diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index 2d0719eeca3ca08960b5ce38bb36095fe6ab248a..9568ab75a5e56b1fbae4121ef4e04d480afe4f49 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -3133,7 +3133,6 @@ static void cldfb_init_proto_and_twiddles_enc( hs->rot_vec_syn_delay_re_fx = NULL; hs->rot_vec_syn_delay_im_fx = NULL; hs->p_filter_sf = (Word16) 17051; - hs->q_scale = norm_s( (Word16) CLDFB80_40_SCALE ); hs->scale = cldfb_scale_2_5ms[4]; hs->p_filter = CLDFB80_40_fx; #endif diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 5619e905d47a82e1763c594e8d50905073b31474..6bcb3ea4bcee71acffee8afd903144ba89f9d740 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -1481,6 +1481,7 @@ enum #define LOW_RATE_HQ_CORE 1 /* Signal use of Low Rate MDCT core */ #define LOW_RATE_HQ_CORE_TRAN 2 /* Signal use of Low Rate MDCT core Tran SWB */ #define NORM_MDCT_FACTOR L_FRAME8k /* Normalize Low Rate MDCT coefficients to this frame size */ +#define SQRT_NORM_MDCT_FACTOR_Q27 (1697734891) /* Normalize Low Rate MDCT coefficients to this frame size */ #define BANDS_MAX ( 4 * 8 ) #define MAX_GQLEVS 32 /* Max fine gain levels */ #define BITS_DE_CMODE 1 diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index 3e8a963cd9823787b22c1fdbc20b13d197c0a3e4..ed75c249b36c8f32c700ac4825c2c202d11ad2c0 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -119,13 +119,13 @@ typedef struct _IVAS_ENC_CHANNEL_AWARE_CONFIG typedef struct _IVAS_ISM_METADATA { #ifdef IVAS_FLOAT_FIXED - Word32 azimuth_fx; - Word32 elevation_fx; - Word16 radius_fx; - Word32 spread_fx; - Word32 gainFactor_fx; - Word32 yaw_fx; - Word32 pitch_fx; + Word32 azimuth_fx; /* Q22 */ + Word32 elevation_fx; /* Q22 */ + Word16 radius_fx; /* Q9 */ + Word32 spread_fx; /* Q22 */ + Word32 gainFactor_fx; /* Q31 */ + Word32 yaw_fx; /* Q22 */ + Word32 pitch_fx; /* Q22 */ #endif float azimuth; float elevation; diff --git a/lib_com/core_com_config.c b/lib_com/core_com_config.c index d7d6b9136c5f6583a216d610903d051e0305cc9d..77f904055bb148de8d127a0a057ae1ad70a8ddef 100644 --- a/lib_com/core_com_config.c +++ b/lib_com/core_com_config.c @@ -808,6 +808,7 @@ float getTcxBandwidth_flt( return tcxBandwidth; } +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * getIgfPresent() * @@ -905,7 +906,7 @@ int16_t getIgfPresent( return igfPresent; } - +#else Word16 getIgfPresent_fx( const Word16 element_mode, /* i : IVAS element mode */ const Word32 total_brate, /* i : total bitrate */ @@ -1009,6 +1010,8 @@ Word16 getIgfPresent_fx( return igfPresent; } +#endif + /*-------------------------------------------------------------------* * getCnaPresent() * @@ -1402,7 +1405,11 @@ void init_tcx_cfg( init_tcx_window_cfg( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, encoderLookahead_enc, encoderLookahead_FB, mdctWindowLength, mdctWindowLengthFB, element_mode ); /* SQ deadzone & memory quantization*/ +#ifndef IVAS_FLOAT_FIXED hTcxCfg->sq_rounding_flt = 0.375f; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ +#else + hTcxCfg->sq_rounding = 12288; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ +#endif /* TCX rate loop */ hTcxCfg->tcxRateLoopOpt = ( tcxonly ) ? 2 : 0; @@ -1453,7 +1460,11 @@ void init_tcx_cfg( } /* Scale TCX for non-active frames to adjust loudness with ACELP*/ +#ifndef IVAS_FLOAT_FIXED hTcxCfg->na_scale_flt = 1.f; +#else + hTcxCfg->na_scale = 32767; +#endif if ( na_scale_bwidth < SWB && !tcxonly ) { @@ -1467,7 +1478,11 @@ void init_tcx_cfg( { i--; } +#ifndef IVAS_FLOAT_FIXED hTcxCfg->na_scale_flt = scaleTcxTable[i].scale_flt; +#else + hTcxCfg->na_scale = scaleTcxTable[i].scale; +#endif break; } } diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index 21ea07dcc60eaab15f77b9f7fac144baecf51d3c..14c9b3c21fad1707950c87023d24b4498a0ea603 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -137,17 +137,28 @@ void initFdCngCom_flt( mhvals_flt( MSSUBFRLEN, &( hFdCngCom->msM_subwin_flt ) ); set_f( hFdCngCom->msPeriodogSum_flt, 0.0f, 2 ); set_f( hFdCngCom->msPsdSum_flt, 0.0f, 2 ); +#ifndef IVAS_FLOAT_FIXED set_f( hFdCngCom->msSlope_flt, 0.0f, 2 ); set_f( hFdCngCom->msQeqInvAv_flt, 0.0f, 2 ); +#else + set16_fx( hFdCngCom->msSlope, 0, 2 ); + set32_fx( hFdCngCom->msQeqInvAv, 0, 2 ); +#endif hFdCngCom->init_old_flt = 0; hFdCngCom->msFrCnt_init_counter = 0; hFdCngCom->msFrCnt_init_thresh = 1; hFdCngCom->offsetflag = 0; hFdCngCom->msFrCnt = MSSUBFRLEN; hFdCngCom->msMinBufferPtr = 0; +#ifndef IVAS_FLOAT_FIXED set_f( hFdCngCom->msAlphaCor_flt, 0.3f, 2 ); hFdCngCom->coherence_flt = 0.5f; +#else + set32_fx( hFdCngCom->msAlphaCor, 644245120l /*0.3f Q31*/, 2 ); + + hFdCngCom->coherence_fx = 16384; /* 0.5 in Q15 */ +#endif return; } @@ -233,6 +244,7 @@ void initPartitions_flt( } +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * compress_range_flt() * @@ -639,6 +651,7 @@ void minimum_statistics_flt( return; } +#endif /*------------------------------------------------------------------- @@ -675,6 +688,7 @@ void apply_scale_flt( } +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * bandcombinepow_flt() * @@ -796,6 +810,7 @@ void scalebands_flt( return; } +#endif /*------------------------------------------------------------------- @@ -859,7 +874,6 @@ void AnalysisSTFT_flt( return; } -#endif /*------------------------------------------------------------------- * SynthesisSTFT_flt() * @@ -946,6 +960,7 @@ void SynthesisSTFT_flt( return; } +#endif #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------- @@ -1332,6 +1347,7 @@ Word16 rand_gauss_fix( } #endif +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * lpc_from_spectrum_flt() * @@ -1352,9 +1368,6 @@ void lpc_from_spectrum_flt( int16_t fftlen = hFdCngCom->fftlen; const float *fftSineTab = hFdCngCom->fftSineTab_flt; float *A = hFdCngCom->A_cng_flt; -#ifdef IVAS_FLOAT_FIXED - Word16 *A_fx = hFdCngCom->A_cng; -#endif /* Power Spectrum */ ptr = fftBuffer; @@ -1408,12 +1421,6 @@ void lpc_from_spectrum_flt( /* LPC */ lev_dur( A, r, M, NULL ); -#ifdef IVAS_FLOAT_FIXED - for ( i = 0; i < M + 1; i++ ) - { - A_fx[i] = float_to_fix16( A[i], Q13 ); - } -#endif return; } @@ -1486,3 +1493,4 @@ void FdCng_exc_flt( return; } +#endif diff --git a/lib_com/fft_fx.c b/lib_com/fft_fx.c index 1126af70ac305c29db608ba67789846657cd936f..27adc56feaa7fbb46c05e11377b5ac0c6dd0be9c 100644 --- a/lib_com/fft_fx.c +++ b/lib_com/fft_fx.c @@ -7116,6 +7116,12 @@ void rfft_fx( s2 = -204; move16(); BREAK; + case 240: + s1 = 136; + move16(); + s2 = -136; + move16(); + BREAK; case 256: s1 = 128; move16(); diff --git a/lib_com/float_to_fix_ops.c b/lib_com/float_to_fix_ops.c index 432bc2d2e2b168fcee1d4a5e45a0830cda7d5c6e..ff8e6fd4f5cae75c5d6412050faf2d0ab9a524bd 100644 --- a/lib_com/float_to_fix_ops.c +++ b/lib_com/float_to_fix_ops.c @@ -29,9 +29,9 @@ Word32 floatToFixed( float f, Word16 Q ) float fixedToFloat( Word32 i, Word16 Q ) { if ( Q < 0 ) - return ( i * (float) ( ( (unsigned) 1 ) << ( -Q ) ) ); + return ( i * (float) ( ( 1LL ) << ( -Q ) ) ); else - return (float) ( i ) / (float) ( (unsigned int) 1 << Q ); + return (float) ( i ) / (float) ( 1LL << Q ); } void floatToFixed_arrL( float *f, Word32 *i, Word16 Q, Word16 l ) { diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 9353570790ea131d84ab75dabd26dec3365c8295..1356d695eccdec5054deb00d227fd83d73bcaa42 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -49,7 +49,7 @@ #define PI_OVER_180_Q22 ( 73204 ) #define _180_OVER_PI ( 180.0f / EVS_PI ) #ifdef IVAS_FLOAT_FIXED -#define _180_OVER_PI_Q25 1922521886 +#define _180_OVER_PI_Q25 1922527338 #define PI_OVER_180_Q25 ( 585635 ) #define _180_IN_Q22 (754974720) #define _360_IN_Q22 (1509949440) @@ -1043,6 +1043,15 @@ typedef enum #define DIRAC_MONO_MIN_THRESH 1e2f #define DIRAC_MONO_FRAME_THRESH 15 /* 30ms */ + +#define DIRAC_MONO_THRESH_SILENCE_FX (Word32)3e4 +#define DIRAC_MONO_NORM_FACTOR_FX (Word64)1e13 +#define DIRAC_MONO_ONE_ON_NORM_FACTOR_FX (Word64)1/1e13 +#define DIRAC_MONO_MAX_THRESH_FX (Word32)1e6 +#define DIRAC_MONO_MIN_THRESH_FX (Word32)1e2 +#define DIRAC_MONO_NORM_FACTOR_M 1220703104 +#define DIRAC_MONO_NORM_FACTOR_E 44 + typedef enum { DIRAC_OPEN, /* initialize to default value */ @@ -1254,7 +1263,7 @@ enum #endif #define BITS_MASA2TOTTAL_DCT0 6 #define STEP_M2T 0.1f -#define STEP_M2T_FX 214748364 +#define STEP_M2T_FX 214748365 #define MASA_HEADER_BITS 2 #define MASA_SUBFRAME_BITS 1 #define MASA_LOWBITRATE_MODE_BITS 1 @@ -1304,6 +1313,7 @@ enum #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*/ #endif @@ -1343,7 +1353,10 @@ enum #define MASA_JBM_RINGBUFFER_FRAMES 3 - +#ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC +#define TOLERANCE_360_Q22 1510033326 /* 360 in Q22 + 0.02 in Q22*/ +#define MINUS_TOLERANCE_360_Q22 -1510033326 /* - (360 in Q22 + 0.02 in Q22) */ +#endif typedef enum { MASA_STEREO_NOT_DEFINED, @@ -1407,9 +1420,9 @@ typedef enum #define MCMASA_LFE_ALPHA 0.67f #define MCMASA_LFE_BETA 0.09f #ifdef IVAS_FLOAT_FIXED -#define MCMASA_LFE_1BIT_THRES_Q31 64424509 /* 0.03f in Q31 */ -#define MCMASA_LFE_ALPHA_Q31 1438814044 /* 0.67f in Q31 */ -#define MCMASA_LFE_BETA_Q31 193273528 /* 0.09f in Q31 */ +#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 */ #endif #define MCMASA_LFE_THETA 1.3f #define MCMASA_LFE_SYNTH_ALPHA 0.95f /* Smoothing coefficient for LFE synthesis */ @@ -1638,6 +1651,13 @@ typedef enum #define LFE_PLC_LENANA LFE_PLC_BUFLEN #define LFE_PLC_FDEL 300 +/*----------------------------------------------------------------------------------* + * 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 */ /*----------------------------------------------------------------------------------* * Amplitude Panning (EFAP, VBAP) constants diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index b775d8ccf134cf6a08f64b4ff5f775aaa77f22f3..01a6d4828d28898d691277a4ee28dc2e8f664802 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -1787,6 +1787,377 @@ void deindex_spherical_component_fx( * *-----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void calculate_hodirac_sector_parameters_fx( + DIRAC_ENC_HANDLE hDirAC, /* i : DirAC handle */ + Word32 RealBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector (L+1)^2 x N_bins, real part */ + Word32 ImagBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector, imaginary part */ + Word16 Qfac, /* i : Q-factor of signal vector */ + const Word32 beta_fx, /* i : forgetting factor for average filtering, Q30 */ + const Word16 *band_grouping, /* i : indices of band groups */ + const Word16 N_bands, /* i : number of bands (groups) */ + const Word16 enc_param_start_band, /* i : first band to process */ + Word32 *azi_fx, /* o : array of sector azimuth angles, flat, Q23 */ + Word32 *ele_fx, /* o : array of sector elevation angles, flat, Q23 */ + Word32 *diff_fx, /* o : array of sector diffuseness values, flat */ + Word16 *diff_exp, /* o : array of sector diffuseness exponents, flat */ + Word32 *ene_fx, /* o : array of sector energy values, flat */ + Word16 *ene_exp /* o : array of sector energy exponents, flat */ +) +{ + Word16 i_sec, i_bin, i_band; + Word32 p_real_fx, p_imag_fx, normI_fx, energy_fx, tmp_diff_fx; + Word16 energy_exp, normI_exp, tmp_diff_exp; + + Word32 sec_I_vec_x_fx[NUM_ANA_SECTORS]; + Word32 sec_I_vec_y_fx[NUM_ANA_SECTORS]; + Word32 sec_I_vec_z_fx[NUM_ANA_SECTORS]; + Word16 sec_I_vec_x_exp[NUM_ANA_SECTORS]; + Word16 sec_I_vec_y_exp[NUM_ANA_SECTORS]; + Word16 sec_I_vec_z_exp[NUM_ANA_SECTORS]; + + FOR( i_sec = 0; i_sec < NUM_ANA_SECTORS; i_sec++ ) + { + Word32 *p_sec_I_vec_x_fx = &sec_I_vec_x_fx[i_sec]; + Word32 *p_sec_I_vec_y_fx = &sec_I_vec_y_fx[i_sec]; + Word32 *p_sec_I_vec_z_fx = &sec_I_vec_z_fx[i_sec]; + Word16 *p_sec_I_vec_x_exp = &sec_I_vec_x_exp[i_sec]; + Word16 *p_sec_I_vec_y_exp = &sec_I_vec_y_exp[i_sec]; + Word16 *p_sec_I_vec_z_exp = &sec_I_vec_z_exp[i_sec]; + + const Word32 *p_c_weights_fx = c_weights_fx; // Q30 + + Word32 *p_ImagBuffer_0_fx = ImagBuffer_fx[0]; + Word32 *p_ImagBuffer_1_fx = ImagBuffer_fx[1]; + Word32 *p_ImagBuffer_2_fx = ImagBuffer_fx[2]; + Word32 *p_ImagBuffer_3_fx = ImagBuffer_fx[3]; + Word32 *p_ImagBuffer_4_fx = ImagBuffer_fx[4]; + Word32 *p_ImagBuffer_5_fx = ImagBuffer_fx[5]; + Word32 *p_ImagBuffer_6_fx = ImagBuffer_fx[6]; + Word32 *p_ImagBuffer_8_fx = ImagBuffer_fx[8]; + + Word32 *p_RealBuffer_0_fx = RealBuffer_fx[0]; + Word32 *p_RealBuffer_1_fx = RealBuffer_fx[1]; + Word32 *p_RealBuffer_2_fx = RealBuffer_fx[2]; + Word32 *p_RealBuffer_3_fx = RealBuffer_fx[3]; + Word32 *p_RealBuffer_4_fx = RealBuffer_fx[4]; + Word32 *p_RealBuffer_5_fx = RealBuffer_fx[5]; + Word32 *p_RealBuffer_6_fx = RealBuffer_fx[6]; + Word32 *p_RealBuffer_8_fx = RealBuffer_fx[8]; + + FOR( i_band = enc_param_start_band; i_band < N_bands; i_band++ ) + { + Word32 *p_azi_fx = &azi_fx[i_sec * N_bands + i_band]; + Word32 *p_ele_fx = &ele_fx[i_sec * N_bands + i_band]; + Word32 *p_ene_fx = &ene_fx[i_sec * N_bands + i_band]; + Word16 *p_ene_exp = &ene_exp[i_sec * N_bands + i_band]; + + Word32 *p_diff_fx = &diff_fx[i_sec * N_bands + i_band]; + Word16 *p_diff_exp = &diff_exp[i_sec * N_bands + i_band]; + Word32 *p_azi_prev_fx = &hDirAC->azi_prev_fx[i_sec * N_bands + i_band]; + Word32 *p_ele_prev_fx = &hDirAC->ele_prev_fx[i_sec * N_bands + i_band]; + + Word32 *p_energy_smth_fx = &hDirAC->energy_smth_fx[i_sec][i_band]; + Word16 *p_energy_smth_exp = &hDirAC->energy_smth_exp[i_sec][i_band]; + Word32 *p_sec_I_vec_smth_x_fx = &hDirAC->sec_I_vec_smth_x_fx[i_sec][i_band]; + Word32 *p_sec_I_vec_smth_y_fx = &hDirAC->sec_I_vec_smth_y_fx[i_sec][i_band]; + Word32 *p_sec_I_vec_smth_z_fx = &hDirAC->sec_I_vec_smth_z_fx[i_sec][i_band]; + Word16 *p_sec_I_vec_smth_x_exp = &hDirAC->sec_I_vec_smth_x_exp[i_sec][i_band]; + Word16 *p_sec_I_vec_smth_y_exp = &hDirAC->sec_I_vec_smth_y_exp[i_sec][i_band]; + Word16 *p_sec_I_vec_smth_z_exp = &hDirAC->sec_I_vec_smth_z_exp[i_sec][i_band]; + *p_sec_I_vec_x_fx = 0; + move32(); + *p_sec_I_vec_x_exp = 0; + move16(); + *p_sec_I_vec_y_fx = 0; + move32(); + *p_sec_I_vec_y_exp = 0; + move16(); + *p_sec_I_vec_z_fx = 0; + move32(); + *p_sec_I_vec_z_exp = 0; + move16(); + energy_fx = 0; + move32(); + energy_exp = 0; + move16(); + + IF( i_sec == 0 ) + { + FOR( i_bin = band_grouping[i_band]; i_bin < band_grouping[i_band + 1]; i_bin++ ) + { + Word32 w_fx = *( p_c_weights_fx++ ); // Q30 + move32(); + Word32 sec_w_imag_fx, sec_x_imag_fx, sec_y_imag_fx, sec_z_imag_fx; + Word32 sec_w_real_fx, sec_x_real_fx, sec_y_real_fx, sec_z_real_fx; + + sec_w_imag_fx = L_add( Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_0_fx ) ), Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_1_fx ) ) ); // Qfac - 2 + sec_x_imag_fx = L_add( Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_3_fx++ ) ), Mpy_32_32( HODIRAC_FAC2, *( p_ImagBuffer_4_fx++ ) ) ); // Qfac - 2 + sec_y_imag_fx = L_sub( L_sub( L_add( Mpy_32_32( HODIRAC_FAC3, *( p_ImagBuffer_0_fx++ ) ), Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_1_fx++ ) ) ), Mpy_32_32( HODIRAC_FAC3, *( p_ImagBuffer_6_fx++ ) ) ), Mpy_32_32( HODIRAC_FAC2, *( p_ImagBuffer_8_fx++ ) ) ); // Qfac - 2 + sec_z_imag_fx = L_add( Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_2_fx++ ) ), Mpy_32_32( HODIRAC_FAC2, *( p_ImagBuffer_5_fx++ ) ) ); // Qfac - 2 + + sec_w_real_fx = L_add( Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_0_fx ) ), Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_1_fx ) ) ); // Qfac - 2 + sec_x_real_fx = L_add( Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_3_fx++ ) ), Mpy_32_32( HODIRAC_FAC2, *( p_RealBuffer_4_fx++ ) ) ); // Qfac - 2 + sec_y_real_fx = L_sub( L_sub( L_add( Mpy_32_32( HODIRAC_FAC3, *( p_RealBuffer_0_fx++ ) ), Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_1_fx++ ) ) ), Mpy_32_32( HODIRAC_FAC3, *( p_RealBuffer_6_fx++ ) ) ), Mpy_32_32( HODIRAC_FAC2, *( p_RealBuffer_8_fx++ ) ) ); // Qfac - 2 + sec_z_real_fx = L_add( Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_2_fx++ ) ), Mpy_32_32( HODIRAC_FAC2, *( p_RealBuffer_5_fx++ ) ) ); // Qfac - 2 + + Word16 p_q; + Word32 tmp_x, tmp_y, tmp_z; + Word16 n, n1, n2; + + p_real_fx = Mpy_32_32( sec_w_real_fx, w_fx ); // ( Qfac - 2 ) + 30 - 31 = Qfac - 3 + p_imag_fx = Mpy_32_32( sec_w_imag_fx, w_fx ); // ( Qfac - 2 ) + 30 - 31 = Qfac - 3 + + n1 = norm_l( p_real_fx ); + n2 = norm_l( p_imag_fx ); + + n = s_min( n1, n2 ); + p_real_fx = L_shl( p_real_fx, n ); + p_imag_fx = L_shl( p_imag_fx, n ); + + p_q = add( sub( Qfac, 3 ), n ); + + Word16 tmp_exp, sec_sum_exp; + tmp_exp = sub( 66, add( p_q, Qfac ) ); // 31 - ( p_q + Qfac - 35 ) + + tmp_x = L_add( L_shr( Mpy_32_32( p_real_fx, sec_x_real_fx ), 2 ), L_shr( Mpy_32_32( p_imag_fx, sec_x_imag_fx ), 2 ) ); // p_q + ( Qfac - 2 ) - 31 - 2 = p_q + Qfac - 35 + tmp_y = L_add( L_shr( Mpy_32_32( p_real_fx, sec_y_real_fx ), 2 ), L_shr( Mpy_32_32( p_imag_fx, sec_y_imag_fx ), 2 ) ); // p_q + ( Qfac - 2 ) - 31 - 2 = p_q + Qfac - 35 + tmp_z = L_add( L_shr( Mpy_32_32( p_real_fx, sec_z_real_fx ), 2 ), L_shr( Mpy_32_32( p_imag_fx, sec_z_imag_fx ), 2 ) ); // p_q + ( Qfac - 2 ) - 31 - 2 = p_q + Qfac - 35 + + *p_sec_I_vec_x_fx = BASOP_Util_Add_Mant32Exp( *p_sec_I_vec_x_fx, *p_sec_I_vec_x_exp, tmp_x, tmp_exp, p_sec_I_vec_x_exp ); + move32(); + *p_sec_I_vec_y_fx = BASOP_Util_Add_Mant32Exp( *p_sec_I_vec_y_fx, *p_sec_I_vec_y_exp, tmp_y, tmp_exp, p_sec_I_vec_y_exp ); + move32(); + *p_sec_I_vec_z_fx = BASOP_Util_Add_Mant32Exp( *p_sec_I_vec_z_fx, *p_sec_I_vec_z_exp, tmp_z, tmp_exp, p_sec_I_vec_z_exp ); + move32(); + + Word32 tmp1; + Word64 tmp2, tmp3, tmp4, sec_sum64; + Word32 tmp5, sec_sum; + tmp_exp = sub( 62, add( p_q, p_q ) ); + + tmp1 = BASOP_Util_Add_Mant32Exp( Mpy_32_32( p_real_fx, p_real_fx ), tmp_exp, Mpy_32_32( p_imag_fx, p_imag_fx ), tmp_exp, &tmp_exp ); + tmp2 = W_add( W_mult0_32_32( sec_x_real_fx, sec_x_real_fx ), W_mult0_32_32( sec_x_imag_fx, sec_x_imag_fx ) ); // 2 * (Qfac - 2) + tmp3 = W_add( W_mult0_32_32( sec_y_real_fx, sec_y_real_fx ), W_mult0_32_32( sec_y_imag_fx, sec_y_imag_fx ) ); // 2 * (Qfac - 2) + tmp4 = W_add( W_mult0_32_32( sec_z_real_fx, sec_z_real_fx ), W_mult0_32_32( sec_z_imag_fx, sec_z_imag_fx ) ); // 2 * (Qfac - 2) + sec_sum64 = W_add( W_add( tmp2, tmp3 ), tmp4 ); // 2 * (Qfac - 2) + n = W_norm( sec_sum64 ); + sec_sum64 = W_shl( sec_sum64, n ); // 2 * (Qfac - 2) + n + sec_sum = W_extract_h( sec_sum64 ); // 2 * (Qfac - 2) + n - 32 = 2 * Qfac + n - 36 + sec_sum_exp = sub( 67, add( shl( Qfac, 1 ), n ) ); + + // divide by 2: + tmp1 = L_shr( tmp1, 1 ); + sec_sum = L_shr( sec_sum, 1 ); + + tmp5 = BASOP_Util_Add_Mant32Exp( tmp1, tmp_exp, sec_sum, sec_sum_exp, &tmp_exp ); + energy_fx = BASOP_Util_Add_Mant32Exp( energy_fx, energy_exp, tmp5, tmp_exp, &energy_exp ); + } + } + ELSE + { + FOR( i_bin = band_grouping[i_band]; i_bin < band_grouping[i_band + 1]; i_bin++ ) + { + Word32 w_fx = *( p_c_weights_fx++ ); // Q30 + move32(); + Word32 sec_w_imag_fx, sec_x_imag_fx, sec_y_imag_fx, sec_z_imag_fx; + Word32 sec_w_real_fx, sec_x_real_fx, sec_y_real_fx, sec_z_real_fx; + + sec_w_imag_fx = L_sub( Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_0_fx ) ), Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_1_fx ) ) ); // Qfac - 2 + sec_x_imag_fx = L_sub( Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_3_fx++ ) ), Mpy_32_32( HODIRAC_FAC2, *( p_ImagBuffer_4_fx++ ) ) ); // Qfac - 2 + sec_y_imag_fx = L_add( L_add( L_add( Mpy_32_32( -HODIRAC_FAC3, *( p_ImagBuffer_0_fx++ ) ), Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_1_fx++ ) ) ), Mpy_32_32( HODIRAC_FAC3, *( p_ImagBuffer_6_fx++ ) ) ), Mpy_32_32( HODIRAC_FAC2, *( p_ImagBuffer_8_fx++ ) ) ); // Qfac - 2 + sec_z_imag_fx = L_sub( Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_2_fx++ ) ), Mpy_32_32( HODIRAC_FAC2, *( p_ImagBuffer_5_fx++ ) ) ); // Qfac - 2 + + sec_w_real_fx = L_sub( Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_0_fx ) ), Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_1_fx ) ) ); // Qfac - 2 + sec_x_real_fx = L_sub( Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_3_fx++ ) ), Mpy_32_32( HODIRAC_FAC2, *( p_RealBuffer_4_fx++ ) ) ); // Qfac - 2 + sec_y_real_fx = L_add( L_add( L_add( Mpy_32_32( -HODIRAC_FAC3, *( p_RealBuffer_0_fx++ ) ), Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_1_fx++ ) ) ), Mpy_32_32( HODIRAC_FAC3, *( p_RealBuffer_6_fx++ ) ) ), Mpy_32_32( HODIRAC_FAC2, *( p_RealBuffer_8_fx++ ) ) ); // Qfac - 2 + sec_z_real_fx = L_sub( Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_2_fx++ ) ), Mpy_32_32( HODIRAC_FAC2, *( p_RealBuffer_5_fx++ ) ) ); // Qfac - 2 + + Word16 p_q; + + p_real_fx = Mpy_32_32( sec_w_real_fx, w_fx ); // ( Qfac - 2 ) + 30 - 31 = Qfac - 3 + p_imag_fx = Mpy_32_32( sec_w_imag_fx, w_fx ); // ( Qfac - 2 ) + 30 - 31 = Qfac - 3 + + Word32 tmp_x, tmp_y, tmp_z; + Word16 n, n1, n2; + + n1 = norm_l( p_real_fx ); + n2 = norm_l( p_imag_fx ); + + n = s_min( n1, n2 ); + + p_real_fx = L_shl( p_real_fx, n ); + p_imag_fx = L_shl( p_imag_fx, n ); + + p_q = add( sub( Qfac, 3 ), n ); + + Word16 tmp_exp, sec_sum_exp; + tmp_exp = sub( 66, add( p_q, Qfac ) ); // 31 - ( p_q + Qfac - 35 ) + + tmp_x = L_add( L_shr( Mpy_32_32( p_real_fx, sec_x_real_fx ), 2 ), L_shr( Mpy_32_32( p_imag_fx, sec_x_imag_fx ), 2 ) ); // p_q + ( Qfac - 2 ) - 31 - 2 = p_q + Qfac - 35 + tmp_y = L_add( L_shr( Mpy_32_32( p_real_fx, sec_y_real_fx ), 2 ), L_shr( Mpy_32_32( p_imag_fx, sec_y_imag_fx ), 2 ) ); // p_q + ( Qfac - 2 ) - 31 - 2 = p_q + Qfac - 35 + tmp_z = L_add( L_shr( Mpy_32_32( p_real_fx, sec_z_real_fx ), 2 ), L_shr( Mpy_32_32( p_imag_fx, sec_z_imag_fx ), 2 ) ); // p_q + ( Qfac - 2 ) - 31 - 2 = p_q + Qfac - 35 + *p_sec_I_vec_x_fx = BASOP_Util_Add_Mant32Exp( *p_sec_I_vec_x_fx, *p_sec_I_vec_x_exp, tmp_x, tmp_exp, p_sec_I_vec_x_exp ); + move32(); + *p_sec_I_vec_y_fx = BASOP_Util_Add_Mant32Exp( *p_sec_I_vec_y_fx, *p_sec_I_vec_y_exp, tmp_y, tmp_exp, p_sec_I_vec_y_exp ); + move32(); + *p_sec_I_vec_z_fx = BASOP_Util_Add_Mant32Exp( *p_sec_I_vec_z_fx, *p_sec_I_vec_z_exp, tmp_z, tmp_exp, p_sec_I_vec_z_exp ); + move32(); + + Word32 tmp1; + Word64 tmp2, tmp3, tmp4, sec_sum64; + Word32 tmp5, sec_sum; + tmp_exp = sub( 62, add( p_q, p_q ) ); + + tmp1 = BASOP_Util_Add_Mant32Exp( Mpy_32_32( p_real_fx, p_real_fx ), tmp_exp, Mpy_32_32( p_imag_fx, p_imag_fx ), tmp_exp, &tmp_exp ); + tmp2 = W_add( W_mult0_32_32( sec_x_real_fx, sec_x_real_fx ), W_mult0_32_32( sec_x_imag_fx, sec_x_imag_fx ) ); // 2 * (Qfac - 2) + tmp3 = W_add( W_mult0_32_32( sec_y_real_fx, sec_y_real_fx ), W_mult0_32_32( sec_y_imag_fx, sec_y_imag_fx ) ); // 2 * (Qfac - 2) + tmp4 = W_add( W_mult0_32_32( sec_z_real_fx, sec_z_real_fx ), W_mult0_32_32( sec_z_imag_fx, sec_z_imag_fx ) ); // 2 * (Qfac - 2) + sec_sum64 = W_add( W_add( tmp2, tmp3 ), tmp4 ); // 2 * (Qfac - 2) + n = W_norm( sec_sum64 ); + sec_sum64 = W_shl( sec_sum64, n ); // 2 * (Qfac - 2) + n + sec_sum = W_extract_h( sec_sum64 ); // 2 * (Qfac - 2) + n - 32 = 2 * Qfac + n - 36 + sec_sum_exp = sub( 67, add( shl( Qfac, 1 ), n ) ); + + // divide by 2: + tmp1 = L_shr( tmp1, 1 ); + sec_sum = L_shr( sec_sum, 1 ); + + tmp5 = BASOP_Util_Add_Mant32Exp( tmp1, tmp_exp, sec_sum, sec_sum_exp, &tmp_exp ); + energy_fx = BASOP_Util_Add_Mant32Exp( energy_fx, energy_exp, tmp5, tmp_exp, &energy_exp ); + } + } + + IF( hDirAC->firstrun_sector_params ) + { + *p_sec_I_vec_smth_x_fx = *p_sec_I_vec_x_fx; + move32(); + *p_sec_I_vec_smth_y_fx = *p_sec_I_vec_y_fx; + move32(); + *p_sec_I_vec_smth_z_fx = *p_sec_I_vec_z_fx; + move32(); + *p_energy_smth_fx = energy_fx; + move32(); + *p_sec_I_vec_smth_x_exp = *p_sec_I_vec_x_exp; + move16(); + *p_sec_I_vec_smth_y_exp = *p_sec_I_vec_y_exp; + move16(); + *p_sec_I_vec_smth_z_exp = *p_sec_I_vec_z_exp; + move16(); + *p_energy_smth_exp = energy_exp; + move16(); + } + ELSE + { + Word32 w_fx = L_sub( ONE_IN_Q30, beta_fx ); // Q30 + + *p_sec_I_vec_smth_x_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( w_fx, *p_sec_I_vec_x_fx ), add( *p_sec_I_vec_x_exp, 1 ), Mpy_32_32( beta_fx, *p_sec_I_vec_smth_x_fx ), add( *p_sec_I_vec_smth_x_exp, 1 ), p_sec_I_vec_smth_x_exp ); + move32(); + *p_sec_I_vec_smth_y_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( w_fx, *p_sec_I_vec_y_fx ), add( *p_sec_I_vec_y_exp, 1 ), Mpy_32_32( beta_fx, *p_sec_I_vec_smth_y_fx ), add( *p_sec_I_vec_smth_y_exp, 1 ), p_sec_I_vec_smth_y_exp ); + move32(); + *p_sec_I_vec_smth_z_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( w_fx, *p_sec_I_vec_z_fx ), add( *p_sec_I_vec_z_exp, 1 ), Mpy_32_32( beta_fx, *p_sec_I_vec_smth_z_fx ), add( *p_sec_I_vec_smth_z_exp, 1 ), p_sec_I_vec_smth_z_exp ); + move32(); + *p_energy_smth_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( w_fx, energy_fx ), add( energy_exp, 1 ), Mpy_32_32( beta_fx, *p_energy_smth_fx ), add( *p_energy_smth_exp, 1 ), p_energy_smth_exp ); + } + + IF( LT_32( energy_fx, EPSILON_FX_SMALL ) ) + { + *p_azi_fx = 0; + move32(); + *p_ele_fx = 0; + move32(); + *p_ene_fx = 0; + move32(); + *p_ene_exp = 0; + move16(); + *p_diff_fx = ONE_IN_Q30; + move32(); + *p_diff_exp = 1; + move16(); + } + ELSE + { + Word32 tmp_x, tmp_y, tmp_z, tmp_xy_hypo, tmp32; + Word16 tmp16, tmp_e; + tmp_x = Mpy_32_32( *p_sec_I_vec_smth_x_fx, *p_sec_I_vec_smth_x_fx ); + tmp_y = Mpy_32_32( *p_sec_I_vec_smth_y_fx, *p_sec_I_vec_smth_y_fx ); + tmp_z = Mpy_32_32( *p_sec_I_vec_smth_z_fx, *p_sec_I_vec_smth_z_fx ); + tmp32 = BASOP_Util_Add_Mant32Exp( tmp_x, shl( *p_sec_I_vec_smth_x_exp, 1 ), tmp_y, shl( *p_sec_I_vec_smth_y_exp, 1 ), &tmp_e ); + normI_fx = BASOP_Util_Add_Mant32Exp( tmp32, tmp_e, tmp_z, shl( *p_sec_I_vec_smth_z_exp, 1 ), &normI_exp ); + normI_fx = Sqrt32( normI_fx, &normI_exp ); + + tmp_xy_hypo = Sqrt32( tmp32, &tmp_e ); // sqrt(x^2 + y^2) + + tmp16 = BASOP_util_atan2( *p_sec_I_vec_smth_y_fx, *p_sec_I_vec_smth_x_fx, sub( *p_sec_I_vec_smth_y_exp, *p_sec_I_vec_smth_x_exp ) ); // Q13 + *p_azi_fx = Mpy_32_32( L_deposit_h( tmp16 ), _180_OVER_PI_Q25 ); // (Q13 + 16) + Q25 - 31 = 54 - 31 = Q23 + tmp16 = BASOP_util_atan2( *p_sec_I_vec_smth_z_fx, tmp_xy_hypo, sub( *p_sec_I_vec_smth_z_exp, tmp_e ) ); // Q13 + *p_ele_fx = Mpy_32_32( L_deposit_h( tmp16 ), _180_OVER_PI_Q25 ); // (Q13 + 16) + Q25 - 31 = 54 - 31 = Q23 + *p_ene_fx = *p_energy_smth_fx; + move32(); + *p_ene_exp = *p_energy_smth_exp; + move16(); + + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( normI_fx, *p_energy_smth_fx, &tmp_e ) ); + tmp_e = add( tmp_e, sub( normI_exp, *p_energy_smth_exp ) ); + tmp32 = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( tmp32 ), tmp_e, &tmp_e ); + *p_diff_fx = tmp32; + move32(); + *p_diff_exp = tmp_e; + move16(); + } + + tmp_diff_fx = *p_diff_fx; + move32(); + tmp_diff_exp = *p_diff_exp; + move16(); + // NOTE: here, assuming abs(tmp_diff) <= 1.0. --> Q30 + tmp_diff_fx = L_shr( tmp_diff_fx, sub( 1, tmp_diff_exp ) ); + tmp_diff_exp = 1; + move16(); + + IF( tmp_diff_fx < 0 ) + { + *p_diff_fx = 0; + move32(); + } + IF( GT_32( tmp_diff_fx, ( ONE_IN_Q30 / 2 ) ) ) + { + IF( hDirAC->firstrun_sector_params ) + { + *p_azi_fx = 0; + move32(); + *p_ele_fx = 0; + move32(); + } + ELSE + { + *p_azi_fx = L_shl( L_add( Mpy_32_32( L_sub( ONE_IN_Q30, tmp_diff_fx ), *p_azi_fx ), Mpy_32_32( L_sub( tmp_diff_fx, ONE_IN_Q30 / 2 ), *p_azi_prev_fx ) ), 1 ); // Q30 + Q23 - 31 = Q22 + move32(); + *p_ele_fx = L_shl( L_add( Mpy_32_32( L_sub( ONE_IN_Q30, tmp_diff_fx ), *p_ele_fx ), Mpy_32_32( L_sub( tmp_diff_fx, ONE_IN_Q30 / 2 ), *p_ele_prev_fx ) ), 1 ); // Q30 + Q23 - 31 = Q22 + move32(); + *p_azi_fx = L_shl( *p_azi_fx, 1 ); // Q22 -> Q23; + move32(); + *p_ele_fx = L_shl( *p_ele_fx, 1 ); // Q22 -> Q23; + move32(); + } + } + ELSE + { + *p_azi_prev_fx = *p_azi_fx; + move32(); + *p_ele_prev_fx = *p_ele_fx; + move32(); + } + } + } + + hDirAC->firstrun_sector_params = 0; + move16(); + + return; +} +#endif + void calculate_hodirac_sector_parameters( DIRAC_ENC_HANDLE hDirAC, /* i : DirAC handle */ float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector (L+1)^2 x N_bins, real part */ diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 1c6a82a99ff789726a253103bc76250c86f96ac6..5da92e9876c433ea565984dd0ce0f5e5e9d10d80 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -48,7 +48,7 @@ /*------------------------------------------------------------------------------------------* * 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 ); static void ivas_get_active_bins( const int16_t **pActive_bins, const int16_t **pActive_bins_abs, const int16_t **pStart_offset, const int16_t **pStart_offset_ab, const int32_t sampling_rate ); static void ivas_get_ld_fb_resp( float **ppIdeal_FRs_re, float **ppIdeal_FRs_im, float **ppNew_FRs_re, float **ppNew_FRs_im, const int16_t *pActive_bins, const int16_t *pStart_offset, const int16_t num_bands, const int16_t delay, const int32_t sampling_rate ); #ifdef IVAS_FLOAT_FIXED @@ -426,6 +426,21 @@ ivas_error ivas_FB_mixer_open( set_f( hFbMixer->prior_mixer[i][j], 0, IVAS_MAX_NUM_BANDS ); } } + + Word32 *pTemp_mem_fx; + if ( ( pTemp_mem_fx = (Word32 *) malloc( sizeof( Word32 ) * fb_cfg->num_out_chans * max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ) * IVAS_MAX_NUM_BANDS ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer" ); + } + for ( i = 0; i < fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < fb_cfg->num_in_chans; j++ ) + { + hFbMixer->prior_mixer_fx[i][j] = pTemp_mem_fx; + pTemp_mem_fx += IVAS_MAX_NUM_BANDS; + set32_fx( hFbMixer->prior_mixer_fx[i][j], 0, IVAS_MAX_NUM_BANDS ); + } + } } if ( !spar_reconfig_flag ) @@ -506,6 +521,12 @@ ivas_error ivas_FB_mixer_open( { return error; } + Word16 index[IVAS_MAX_NUM_FB_BANDS]; + set16_fx( index, 0, IVAS_MAX_NUM_FB_BANDS ); + if ( ( error = ivas_filterbank_setup_fx( hFbMixer, sampling_rate, index ) ) != IVAS_ERR_OK ) + { + return error; + } } *hFbMixer_out = hFbMixer; @@ -714,17 +735,6 @@ ivas_error ivas_FB_mixer_open_fx( FOR( j = start_diff_band_non48k; j < num_bands; j++ ) { -#if 1 // TODO: To be removed later - if ( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] = (float *) malloc( sizeof( float ) * pActive_bins_per_band[j] ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } - - if ( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[1][j] = (float *) malloc( sizeof( float ) * pActive_bins_per_band[j] ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } -#endif IF( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j] = (Word32 *) malloc( sizeof( Word32 ) * pActive_bins_per_band[j] ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); @@ -757,12 +767,6 @@ ivas_error ivas_FB_mixer_open_fx( { return error; } -#if 1 // TODO: To be removed later - if ( ( error = ivas_filterbank_setup( hFbMixer, sampling_rate ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif } *hFbMixer_out = hFbMixer; @@ -1417,7 +1421,162 @@ 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 ) +{ + *out1_re = L_sub_sat( Mpy_32_32( in1_re, in2_re ), Mpy_32_32( in1_im, in2_im ) ); + *out1_im = L_add_sat( Mpy_32_32( in1_re, in2_im ), Mpy_32_32( in2_re, in1_im ) ); +} + +void ivas_fb_mixer_process( + 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 */ + Word32 **ppOut_pcm_fx, /* o : output audio channels */ + Word16 *q_ppOut_pcm_fx, /*ppOut_pcm_fx resultant q*/ + 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 */ +) +{ + ivas_filterbank_t *pFb = hFbMixer->pFb; + Word16 num_bands = pFb->filterbank_num_bands; + move16(); + Word16 i, j, k, ch, hist; + + const Word32 *pFilterbank_bin_to_band_re_fx; + const Word32 *pFilterbank_bin_to_band_im_fx; + Word32 *pMdft_out_fx[2]; + Word32 *pOut_fr_re_fx, *pOut_fr_im_fx; + Word16 q_pOut_fr_fx = 31; + move16(); + Word32 Out_fr_re_fx[L_FRAME48k], Out_fr_im_fx[L_FRAME48k]; + Word32 Mdft_out_0_fx[L_FRAME48k * 2], Mdft_out_1_fx[L_FRAME48k * 2]; + + pOut_fr_re_fx = Out_fr_re_fx; + pOut_fr_im_fx = Out_fr_im_fx; + pMdft_out_fx[0] = Mdft_out_0_fx; + pMdft_out_fx[1] = Mdft_out_1_fx; + + FOR( ch = ( hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + /* Run a loop of 2 to calculate current frame's filterbank output and prev frame's output */ + FOR( hist = 0; hist < 2; hist++ ) + { + set_zero_fx( pOut_fr_re_fx, frame_len ); + set_zero_fx( pOut_fr_im_fx, frame_len ); + q_pOut_fr_fx = 31; + move16(); + FOR( j = 0; j < hFbMixer->fb_cfg->num_in_chans; j++ ) + { + IF( in_out_mixer_map[ch][j] != 0 ) + { + + 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]; + + set_zero_fx( filterbank_mixer_bins_re_fx, frame_len ); + set_zero_fx( filterbank_mixer_bins_im_fx, frame_len ); + + Word16 total_guard = find_guarded_bits_fx( num_bands ); + move16(); + FOR( i = 0; i < num_bands; i++ ) + { + Word16 start_offset = pFb->fb_consts.pFilterbank_bins_start_offset[i]; + move16(); + Word16 num_bins = pFb->fb_consts.pFilterbank_bins_per_band[i]; + move16(); + Word32 mixer_const_fx = hFbMixer->prior_mixer_fx[ch][j][i]; + 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]; + + 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 ) ); + 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 ) ); + 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]; + move32(); + } + Word16 res_q = 0; + move16(); + FOR( k = 0; k < frame_len; k++ ) + { + Word32 temp_out_re_fx, temp_out_im_fx; + Word16 Fb_inFR_com_q = s_min( hFbMixer->q_ppFilterbank_inFR_re_fx[j], hFbMixer->q_ppFilterbank_inFR_im_fx[j] ); + Word32 inp_Fb_inFR_re, inp_Fb_inFR_im; + IF( NE_16( hFbMixer->q_ppFilterbank_inFR_re_fx[j], Fb_inFR_com_q ) ) + { + inp_Fb_inFR_re = L_shr( pFb_inFR_re_fx[k], sub( hFbMixer->q_ppFilterbank_inFR_re_fx[j], Fb_inFR_com_q ) ); + /*common q for real and imag hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ + } + ELSE + { + inp_Fb_inFR_re = pFb_inFR_re_fx[k]; + /*q hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ + move32(); + } + IF( NE_16( hFbMixer->q_ppFilterbank_inFR_im_fx[j], Fb_inFR_com_q ) ) + { + inp_Fb_inFR_im = L_shr( pFb_inFR_im_fx[k], sub( hFbMixer->q_ppFilterbank_inFR_im_fx[j], Fb_inFR_com_q ) ); + /*common q for real and imag hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ + } + ELSE + { + inp_Fb_inFR_im = pFb_inFR_im_fx[k]; + /*q hFbMixer->q_ppFilterbank_inFR_im_fx[j]*/ + move32(); + } + ivas_cmult_fix( filterbank_mixer_bins_re_fx[k], filterbank_mixer_bins_im_fx[k], inp_Fb_inFR_re, + inp_Fb_inFR_im, &temp_out_re_fx, &temp_out_im_fx ); + res_q = sub( add( sub( sub( add( 30, *q_mixer_mat_fx ), 31 ), total_guard ), Fb_inFR_com_q ), 31 ); + move16(); + Word16 q_check = s_min( q_pOut_fr_fx, res_q ); + move16(); + 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 ) ); + move32(); + pOut_fr_im_fx[k] = L_shr( pOut_fr_im_fx[k], sub( q_pOut_fr_fx, q_check ) ); + move32(); + } + IF( 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 ) ); + } + res_q = q_check; + move16(); + pOut_fr_re_fx[k] = L_add_sat( pOut_fr_re_fx[k], temp_out_re_fx ); + move32(); + pOut_fr_im_fx[k] = L_add_sat( pOut_fr_im_fx[k], temp_out_im_fx ); + move32(); + } + q_pOut_fr_fx = res_q; + move16(); + } + } + ivas_imdft_fx( pOut_fr_re_fx, pOut_fr_im_fx, pMdft_out_fx[hist], frame_len ); + } + + ivas_fb_mixer_cross_fading_fx( hFbMixer, ppOut_pcm_fx, pMdft_out_fx[0], pMdft_out_fx[1], ch, frame_len, frame_len ); + q_ppOut_pcm_fx[ch] = q_pOut_fr_fx; + move16(); + } + + return; +} + +#else void ivas_fb_mixer_process( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ float ***mixer_mat, /* i : mixer matrix */ @@ -1432,13 +1591,27 @@ void ivas_fb_mixer_process( const float *pFilterbank_bin_to_band_re; const float *pFilterbank_bin_to_band_im; float *pMdft_out[2], *pOut_fr_re, *pOut_fr_im; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word32 *pMdft_out_fx[2]; + Word32 **ppOut_pcm_fx = (Word32 **) malloc( hFbMixer->fb_cfg->num_out_chans * sizeof( Word32 * ) ); + for ( ch = 0; ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + ppOut_pcm_fx[ch] = (Word32 *) malloc( frame_len * sizeof( Word32 ) ); + } +#endif float Out_fr_re[L_FRAME48k], Out_fr_im[L_FRAME48k]; float Mdft_out_0[L_FRAME48k * 2], Mdft_out_1[L_FRAME48k * 2]; - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word32 Mdft_out_0_fx[L_FRAME48k * 2], Mdft_out_1_fx[L_FRAME48k * 2]; +#endif pOut_fr_re = Out_fr_re; pOut_fr_im = Out_fr_im; pMdft_out[0] = Mdft_out_0; pMdft_out[1] = Mdft_out_1; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + pMdft_out_fx[0] = Mdft_out_0_fx; + pMdft_out_fx[1] = Mdft_out_1_fx; +#endif for ( ch = ( hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) { @@ -1493,14 +1666,32 @@ void ivas_fb_mixer_process( ivas_imdft( pOut_fr_re, pOut_fr_im, pMdft_out[hist], frame_len ); } - +#ifndef IVAS_FLOAT_FIXED ivas_fb_mixer_cross_fading( hFbMixer, ppOut_pcm, pMdft_out[0], pMdft_out[1], ch, frame_len, frame_len ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 q1 = Q_factor_arrL( pMdft_out[0], frame_len * 2 ); + Word16 q2 = Q_factor_arrL( pMdft_out[1], frame_len * 2 ); + Word16 q = s_min( q1, q2 ); + floatToFixed_arrL( pMdft_out[0], pMdft_out_fx[0], q, frame_len * 2 ); + floatToFixed_arrL( pMdft_out[1], pMdft_out_fx[1], q, frame_len * 2 ); +#endif + ivas_fb_mixer_cross_fading_fx( hFbMixer, ppOut_pcm_fx, pMdft_out_fx[0], pMdft_out_fx[1], ch, frame_len, frame_len ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arrL( ppOut_pcm_fx[ch], ppOut_pcm[ch], q, frame_len ); +#endif +#endif } - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( ch = 0; ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + free( ppOut_pcm_fx[ch] ); + } + free( ppOut_pcm_fx ); +#endif return; } - - +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_fb_mixer_get_in_out_mapping() * diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index 458e473aaf848d7093a359a2f0f54cb6e8a2c926..583051b2321b59f4ea863bf7af2953523899fa8e 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -811,15 +811,8 @@ void ivas_ism_reset_metadata_enc( move32(); hIsmMeta->pitch_fx = 0; move32(); - hIsmMeta->radius_fx = 1 << 9; + hIsmMeta->radius_fx = 1 << 9; // Q9 move16(); -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - hIsmMeta->azimuth = 0.0f; - hIsmMeta->elevation = 0.0f; - hIsmMeta->yaw = 0.0f; - hIsmMeta->pitch = 0.0f; - hIsmMeta->radius = 1.0f; -#endif hIsmMeta->ism_metadata_flag = 0; move16(); hIsmMeta->non_diegetic_flag = 0; diff --git a/lib_com/ivas_mdct_imdct_fx.c b/lib_com/ivas_mdct_imdct_fx.c index c25f4fab4bdcba6f02162341aa654d2fec309cc9..37c5251098d3dbd3c4fee6a0006386a71567aa02 100644 --- a/lib_com/ivas_mdct_imdct_fx.c +++ b/lib_com/ivas_mdct_imdct_fx.c @@ -63,9 +63,9 @@ *-----------------------------------------------------------------------------------------*/ void ivas_tda_fx( - const Word32 *pIn, /* i : time domain buffer of size 2*length */ - Word32 *pOut, /* o : time domain buffer of size length */ - const Word16 length /* i : length of time alised signal buffer */ + const Word32 *pIn, /* i : time domain buffer of size 2*length Q10*/ + Word32 *pOut, /* o : time domain buffer of size length Q10 */ + const Word16 length /* i : length of time alised signal buffer Q0*/ ) { Word16 i; @@ -74,9 +74,9 @@ void ivas_tda_fx( FOR( i = 0; i < len_by_2; i++ ) { - pOut[i] = L_sub( pIn[add( len_by_2, i )], pIn[sub( sub( len_by_2, i ), 1 )] ); + pOut[i] = L_sub( pIn[len_by_2 + i], pIn[len_by_2 - i - 1] ); /* Q10*/ move32(); - pOut[add( len_by_2, i )] = L_add( pIn[sub( sub( i_mult( length, 2 ), i ), 1 )], pIn[add( length, i )] ); + pOut[len_by_2 + i] = L_add( pIn[length * 2 - i - 1], pIn[length + i] ); /* Q10*/ move32(); } @@ -91,32 +91,32 @@ void ivas_tda_fx( *-----------------------------------------------------------------------------------------*/ void ivas_dct_windowing_fx( - const Word16 fade_len, - const Word16 full_len, - const Word16 dct_len, - const Word16 zero_pad_len, - const Word32 *pWindow_coeffs, - const Word16 frame_len, - Word32 *pOut_buf, - Word32 *pBuffer_prev, - Word32 *pTemp_lfe ) + const Word16 fade_len, /*Q0*/ + const Word16 full_len, /*Q0*/ + const Word16 dct_len, /*Q0*/ + const Word16 zero_pad_len, /*Q0*/ + const Word32 *pWindow_coeffs, /*Q31*/ + const Word16 frame_len, /*Q0*/ + Word32 *pOut_buf, // Q10 + Word32 *pBuffer_prev, // Q10 + Word32 *pTemp_lfe ) // Q10 { Word16 i; Word16 rem_len; rem_len = 0; move16(); - Copy32( pBuffer_prev, pOut_buf + zero_pad_len, fade_len ); + Copy32( pBuffer_prev, pOut_buf + zero_pad_len, fade_len ); // Q10 - Copy32( pTemp_lfe, ( pOut_buf + add( fade_len, zero_pad_len ) ), dct_len ); + Copy32( pTemp_lfe, ( pOut_buf + add( fade_len, zero_pad_len ) ), dct_len ); // Q10 set32_fx( pOut_buf, 0, zero_pad_len ); - Copy32( ( pOut_buf + sub( full_len, fade_len ) ), pBuffer_prev, fade_len ); + Copy32( ( pOut_buf + sub( full_len, fade_len ) ), pBuffer_prev, fade_len ); // Q10 FOR( i = 0; i < fade_len; i++ ) { - pOut_buf[add( zero_pad_len, i )] = Mult_32_32( pOut_buf[add( zero_pad_len, i )], pWindow_coeffs[i] ); + pOut_buf[zero_pad_len + i] = Mult_32_32( pOut_buf[zero_pad_len + i], pWindow_coeffs[i] ); // Q10 move32(); } @@ -124,7 +124,7 @@ void ivas_dct_windowing_fx( FOR( i = 0; i < rem_len; i++ ) { - pOut_buf[add( add( i_mult( zero_pad_len, 3 ), fade_len ), i )] = Mult_32_32( pOut_buf[add( add( i_mult( zero_pad_len, 3 ), fade_len ), i )], pWindow_coeffs[sub( sub( fade_len, i ), 1 )] ); + pOut_buf[zero_pad_len * 3 + fade_len + i] = Mult_32_32( pOut_buf[zero_pad_len * 3 + fade_len + i], pWindow_coeffs[fade_len - i - 1] ); // Q10 move32(); } @@ -141,9 +141,9 @@ void ivas_dct_windowing_fx( *-----------------------------------------------------------------------------------------*/ void ivas_mdct_fx( - const Word32 *pIn, - Word32 *pOut, - const Word16 length, + const Word32 *pIn, // q_out + Word32 *pOut, // q_out + const Word16 length, // Q0 Word16 *q_out ) { const Word16 *pTwid_re, *pTwid_im; @@ -152,23 +152,23 @@ void ivas_mdct_fx( Word32 ivas_mdct_scaling_gain; len_by_2 = shr( length, 1 ); - ivas_mdct_scaling_gain = ivas_get_mdct_scaling_gain_fx( len_by_2 ); + ivas_mdct_scaling_gain = ivas_get_mdct_scaling_gain_fx( len_by_2 ); // Q46 ivas_get_twid_factors_fx1( length, &pTwid_re, &pTwid_im ); FOR( i = 0; i < len_by_2; i++ ) { - pOut[i] = L_sub( pIn[add( len_by_2, i )], pIn[sub( sub( len_by_2, i ), 1 )] ); + pOut[i] = L_sub( pIn[len_by_2 + i], pIn[len_by_2 - i - 1] ); // q_out move32(); - pOut[add( len_by_2, i )] = L_add( pIn[sub( sub( imult1616( length, 2 ), i ), 1 )], pIn[add( length, i )] ); + pOut[len_by_2 + i] = L_add( pIn[length * 2 - i - 1], pIn[length + i] ); // q_out move32(); } FOR( i = 0; i < len_by_2; i++ ) { - re[i] = L_negate( L_add( Mpy_32_16_1( pOut[2 * i], pTwid_re[i] ), Mpy_32_16_1( pOut[sub( sub( length, 1 ), imult1616( 2, i ) )], pTwid_im[i] ) ) ); + re[i] = L_negate( L_add( Mpy_32_16_1( pOut[2 * i], pTwid_re[i] ), Mpy_32_16_1( pOut[length - 1 - 2 * i], pTwid_im[i] ) ) ); // q_out move32(); - im[i] = L_sub( Mpy_32_16_1( pOut[sub( sub( length, 1 ), imult1616( 2, i ) )], pTwid_re[i] ), Mpy_32_16_1( pOut[2 * i], pTwid_im[i] ) ); + im[i] = L_sub( Mpy_32_16_1( pOut[length - 1 - 2 * i], pTwid_re[i] ), Mpy_32_16_1( pOut[2 * i], pTwid_im[i] ) ); // q_out move32(); } @@ -176,9 +176,9 @@ void ivas_mdct_fx( FOR( i = 0; i < len_by_2; i++ ) { - re[i] = Mult_32_32( re[i], ivas_mdct_scaling_gain ); + re[i] = Mult_32_32( re[i], ivas_mdct_scaling_gain ); // q_out+15 move32(); - im[i] = Mult_32_32( im[i], ivas_mdct_scaling_gain ); + im[i] = Mult_32_32( im[i], ivas_mdct_scaling_gain ); // q_out +15 move32(); } *q_out = add( *q_out, Q15 ); @@ -186,18 +186,18 @@ void ivas_mdct_fx( FOR( i = 0; i < len_by_2; i++ ) { Word32 tmp; - tmp = L_sub( Mpy_32_16_1( re[i], pTwid_re[i] ), Mpy_32_16_1( im[i], pTwid_im[i] ) ); - im[i] = L_add( Mpy_32_16_1( im[i], pTwid_re[i] ), Mpy_32_16_1( re[i], pTwid_im[i] ) ); + tmp = L_sub( Mpy_32_16_1( re[i], pTwid_re[i] ), Mpy_32_16_1( im[i], pTwid_im[i] ) ); // q_out + im[i] = L_add( Mpy_32_16_1( im[i], pTwid_re[i] ), Mpy_32_16_1( re[i], pTwid_im[i] ) ); // q_out move32(); - re[i] = tmp; + re[i] = tmp; // q_out move32(); } FOR( i = 0; i < len_by_2; i++ ) { - pOut[sub( sub( length, imult1616( 2, i ) ), 1 )] = re[i]; + pOut[length - 2 * i - 1] = re[i]; // q_out move32(); - pOut[2 * i] = im[i]; + pOut[2 * i] = im[i]; // q_out move32(); } @@ -212,33 +212,33 @@ void ivas_mdct_fx( *-----------------------------------------------------------------------------------------*/ static void ivas_ifft_cplx( - Word32 *re, - Word32 *im, - const Word16 length ) + Word32 *re, /*Q24*/ + Word32 *im, /*Q24*/ + const Word16 length /*Q0*/ ) { Word16 i; Word32 ivas_imdct_one_by_powergain; - ivas_imdct_one_by_powergain = IVAS_ONE_BY_IMDCT_SCALING_GAIN_Q16; + ivas_imdct_one_by_powergain = IVAS_ONE_BY_IMDCT_SCALING_GAIN_Q16; // Q16 move32(); /*re-arrange inputs to use fft as ifft */ - re[0] = Mult_32_32( re[0], ivas_imdct_one_by_powergain ); + re[0] = Mult_32_32( re[0], ivas_imdct_one_by_powergain ); // Q9 move32(); - im[0] = Mult_32_32( im[0], ivas_imdct_one_by_powergain ); + im[0] = Mult_32_32( im[0], ivas_imdct_one_by_powergain ); // Q9 move32(); - FOR( i = 1; i <= shr( length, 1 ); i++ ) + FOR( i = 1; i <= ( length / 2 ); i++ ) { Word32 tmp; - tmp = Mult_32_32( re[sub( length, i )], ivas_imdct_one_by_powergain ); - re[sub( length, i )] = Mult_32_32( re[i], ivas_imdct_one_by_powergain ); + tmp = Mult_32_32( re[length - i], ivas_imdct_one_by_powergain ); // Q9 + re[length - i] = Mult_32_32( re[i], ivas_imdct_one_by_powergain ); // Q9 move32(); - re[i] = tmp; + re[i] = tmp; //-Q6 move32(); - tmp = Mult_32_32( im[sub( length, i )], ivas_imdct_one_by_powergain ); - im[sub( length, i )] = Mult_32_32( im[i], ivas_imdct_one_by_powergain ); + tmp = Mult_32_32( im[length - i], ivas_imdct_one_by_powergain ); // Q9 + im[length - i] = Mult_32_32( im[i], ivas_imdct_one_by_powergain ); // Q9 move32(); - im[i] = tmp; + im[i] = tmp; // Q9 move32(); } @@ -255,9 +255,9 @@ static void ivas_ifft_cplx( *-----------------------------------------------------------------------------------------*/ void ivas_itda_fx( - const Word32 *re, /* i : time alised signal after IDCT */ + const Word32 *re, /* i : time alised signal after IDCT Q24 */ Word32 *pOut, /* o : time domain buffer of size 2*length */ - const Word16 length /* i : length of time alised signal buffer */ + const Word16 length /* i : length of time alised signal buffer Q0 */ ) { Word16 i; @@ -266,13 +266,13 @@ void ivas_itda_fx( FOR( i = 0; i < len_by_2; i++ ) { - pOut[i] = L_negate( re[sub( sub( len_by_2, i ), 1 )] ); + pOut[i] = L_negate( re[len_by_2 - i - 1] ); /*Q24 */ move32(); - pOut[add( len_by_2, i )] = re[i]; + pOut[add( len_by_2, i )] = re[i]; /*Q24 */ move32(); - pOut[add( length, i )] = re[add( len_by_2, i )]; + pOut[add( length, i )] = re[len_by_2 + i]; /*Q24 */ move32(); - pOut[add( imult1616( 3, len_by_2 ), i )] = re[sub( sub( length, i ), 1 )]; + pOut[3 * len_by_2 + i] = re[length - i - 1]; /*Q24 */ move32(); } @@ -287,9 +287,9 @@ void ivas_itda_fx( *-----------------------------------------------------------------------------------------*/ void ivas_imdct_fx( - const Word32 *pIn, - Word32 *pOut, - const Word16 length, + const Word32 *pIn, // Q24 + Word32 *pOut, // q_out Q9 + const Word16 length /*Q0*/, Word16 *q_out ) { const Word16 *pTwid_re, *pTwid_im; @@ -303,9 +303,9 @@ void ivas_imdct_fx( FOR( i = 0; i < len_by_2; i++ ) { - re[i] = L_add( Mpy_32_16_1( pIn[sub( sub( length, shl( i, 1 ) ), 1 )], pTwid_re[i] ), Mpy_32_16_1( pIn[2 * i], pTwid_im[i] ) ); /*stl_arr_index*/ + re[i] = L_add( Mpy_32_16_1( pIn[length - 2 * i - 1], pTwid_re[i] ), Mpy_32_16_1( pIn[2 * i], pTwid_im[i] ) ); /*stl_arr_index Q24*/ move32(); - im[i] = L_sub( Mpy_32_16_1( pIn[2 * i], pTwid_re[i] ), Mpy_32_16_1( pIn[sub( sub( length, shl( i, 1 ) ), 1 )], pTwid_im[i] ) ); /*stl_arr_index*/ + im[i] = L_sub( Mpy_32_16_1( pIn[2 * i], pTwid_re[i] ), Mpy_32_16_1( pIn[length - 2 * i - 1], pTwid_im[i] ) ); /*stl_arr_index Q24*/ move32(); } @@ -319,30 +319,30 @@ void ivas_imdct_fx( FOR( i = 0; i < len_by_2; i++ ) { Word32 tmp; - tmp = L_add( Mpy_32_16_1( re[i], pTwid_re[i] ), Mpy_32_16_1( im[i], pTwid_im[i] ) ); - im[i] = L_sub( Mpy_32_16_1( im[i], pTwid_re[i] ), Mpy_32_16_1( re[i], pTwid_im[i] ) ); + tmp = L_add( Mpy_32_16_1( re[i], pTwid_re[i] ), Mpy_32_16_1( im[i], pTwid_im[i] ) ); // Q9 + im[i] = L_sub( Mpy_32_16_1( im[i], pTwid_re[i] ), Mpy_32_16_1( re[i], pTwid_im[i] ) ); // Q9 move32(); - re[i] = tmp; + re[i] = tmp; // Q9 move32(); } FOR( i = ( len_by_2 - 1 ); i >= 0; i-- ) { - re[add( shl( i, 1 ), 1 )] = im[sub( sub( len_by_2, 1 ), i )]; + re[2 * i + 1] = im[( len_by_2 - 1 ) - i]; // Q9 move32(); - re[2 * i] = L_negate( re[i] ); + re[2 * i] = L_negate( re[i] ); // Q9 move32(); } FOR( i = 0; i < len_by_2; i++ ) { - pOut[i] = L_negate( re[sub( sub( len_by_2, i ), 1 )] ); + pOut[i] = L_negate( re[len_by_2 - i - 1] ); // Q9 move32(); - pOut[add( len_by_2, i )] = re[i]; + pOut[len_by_2 + i] = re[i]; // Q9 move32(); - pOut[add( length, i )] = re[add( len_by_2, i )]; + pOut[length + i] = re[len_by_2 + i]; // Q9 move32(); - pOut[add( imult1616( 3, len_by_2 ), i )] = re[sub( sub( length, i ), 1 )]; + pOut[3 * len_by_2 + i] = re[length - i - 1]; // Q9 move32(); } @@ -356,29 +356,29 @@ void ivas_imdct_fx( * Sets/Maps the fft twiddle tables based on fft length *-----------------------------------------------------------------------------------------*/ void ivas_get_twid_factors_fx1( - const Word16 length, - const Word16 **pTwid_re, - const Word16 **pTwid_im ) + const Word16 length, // Q0 + const Word16 **pTwid_re, // Q15 + const Word16 **pTwid_im ) // Q15 { IF( EQ_16( length, 480 ) ) { - *pTwid_re = (const Word16 *) &ivas_cos_twiddle_480_fx[0]; - *pTwid_im = (const Word16 *) &ivas_sin_twiddle_480_fx[0]; + *pTwid_re = (const Word16 *) &ivas_cos_twiddle_480_fx[0]; // Q15 + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_480_fx[0]; // Q15 } ELSE IF( EQ_16( length, 320 ) ) { - *pTwid_re = (const Word16 *) &ivas_cos_twiddle_320_fx[0]; - *pTwid_im = (const Word16 *) &ivas_sin_twiddle_320_fx[0]; + *pTwid_re = (const Word16 *) &ivas_cos_twiddle_320_fx[0]; // Q15 + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_320_fx[0]; // Q15 } ELSE IF( EQ_16( length, 160 ) ) { - *pTwid_re = (const Word16 *) &ivas_cos_twiddle_160_fx[0]; - *pTwid_im = (const Word16 *) &ivas_sin_twiddle_160_fx[0]; + *pTwid_re = (const Word16 *) &ivas_cos_twiddle_160_fx[0]; // Q15 + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_160_fx[0]; // Q15 } ELSE IF( EQ_16( length, 80 ) ) { - *pTwid_re = (const Word16 *) &ivas_cos_twiddle_80_fx[0]; - *pTwid_im = (const Word16 *) &ivas_sin_twiddle_80_fx[0]; + *pTwid_re = (const Word16 *) &ivas_cos_twiddle_80_fx[0]; // Q15 + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_80_fx[0]; // Q15 } ELSE { @@ -405,19 +405,19 @@ Word32 ivas_get_mdct_scaling_gain_fx( { case L_FRAME48k >> 2: { - gain = IVAS_MDCT_SCALING_GAIN_48k_Q46; + gain = IVAS_MDCT_SCALING_GAIN_48k_Q46; /*Q46*/ move32(); BREAK; } case L_FRAME32k >> 2: { - gain = IVAS_MDCT_SCALING_GAIN_32k_Q46; + gain = IVAS_MDCT_SCALING_GAIN_32k_Q46; /*Q46*/ move32(); BREAK; } case L_FRAME16k >> 2: { - gain = IVAS_MDCT_SCALING_GAIN_16k_Q46; + gain = IVAS_MDCT_SCALING_GAIN_16k_Q46; /*Q46*/ move32(); BREAK; } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 924a554d664c5808e74ad00dc120a3327a982041..a2aada6a9dddba9deea283321de824eda9e80893 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -70,9 +70,11 @@ void stereo_dmx_evs_enc( ); /*! r: number of channels to be analysed */ +#ifndef IVAS_FLOAT_FIXED int16_t getNumChanAnalysis( Encoder_Struct *st_ivas /* i : IVAS encoder structure */ ); +#endif void copy_encoder_config( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ @@ -693,17 +695,17 @@ void decod_gen_2sbfr( #ifdef IVAS_FLOAT_FIXED void decod_gen_2sbfr_ivas_fx( - Decoder_State *st, /* i/o: decoder static memory */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 *Aq, /* i : LP filter coefficient */ - Word16 *pitch_buf, /* o : floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *gain_buf, /* o : floating pitch gain for each subframe */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : pitch values for primary channel */ + Decoder_State *st, /* i/o: decoder static memory */ + const Word16 sharpFlag, /* i : formant sharpening flag `Q0*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[] /* i : pitch values for primary channel Q6*/ ); #endif @@ -963,9 +965,9 @@ void smooth_dft2td_transition( ); void smooth_dft2td_transition_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx[CPE_CHANNELS], /* i/o: synthesis @external Fs */ - const Word16 output_frame /* i : output frame lenght */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx[CPE_CHANNELS], /* i/o: synthesis @external Fs Q11*/ + const Word16 output_frame /* i : output frame lenght Q0*/ ); /*! r: flag indicating a valid bitrate */ int16_t is_IVAS_bitrate( @@ -1400,7 +1402,7 @@ ivas_error ivas_ism_metadata_enc( const Word16 ism_mode, /* i : ISM mode */ const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Config Handle */ const Word16 ism_extended_metadata_flag, /* i : Extended metadata flag */ - const Word32 lp_noise_CPE, /* i : LP filtered total noise estimation */ + const Word16 lp_noise_CPE, /* i : LP filtered total noise estimation */ const Word16 flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ Word16 *omasa_stereo_sw_cnt, const Word16 ini_frame @@ -1858,9 +1860,9 @@ void stereo_dft_quantize_res_gains( ); #ifdef IVAS_FLOAT_FIXED void stereo_dft_dequantize_itd_fx( - Word16 *ind, - Word32 *out, - const Word32 output_Fs + Word16 *ind, /* Q0 */ + Word32 *out, /* Q15 */ + const Word32 output_Fs /* Q0 */ ); #endif // IVAS_FLOAT_FIXED @@ -1892,9 +1894,9 @@ void stereo_dft_enc_sid_coh( #ifdef IVAS_FLOAT_FIXED void stereo_dft_dec_sid_coh_fx( Decoder_State *st, /* i/o: decoder state structure */ - const Word16 nbands, /* i : number of DFT stereo bands */ - Word16 *coh, /* i/o: coherence */ - Word16 *nb_bits /* i/o: number of bits read */ + const Word16 nbands, /* i : number of DFT stereo bands Q0*/ + Word16 *coh, /* i/o: coherence Q15*/ + Word16 *nb_bits /* i/o: number of bits read Q0*/ ); #endif // IVAS_FLOAT_FIXED @@ -2043,17 +2045,17 @@ void bpf_pitch_coherence( ); #ifdef IVAS_FLOAT_FIXED void stereo_dft_dec_read_BS_fx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word32 element_brate, /* i : element bitrate */ - Word32 *total_brate, /* o : total bitrate */ - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ - const Word16 bwidth, /* i : bandwidth */ - const Word16 output_frame, /* i : output frame length */ - Word32 res_buf[STEREO_DFT_N_8k], /* o : residual buffer */ - Word16 *nb_bits, /* o : number of bits read */ - Word16 *coh, /* i/o: Coherence */ - const Word16 ivas_format /* i : ivas format */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + Word32 *total_brate, /* o : total bitrate Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ + const Word16 bwidth, /* i : bandwidth Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + Word32 res_buf_fx[STEREO_DFT_N_8k], /* o : residual buffer Q0*/ + Word16 *nb_bits, /* o : number of bits read Q0*/ + Word16 *coh_fx, /* i/o: Coherence Q15*/ + const Word16 ivas_format /* i : ivas format Q0*/ ); #endif // IVAS_FLOAT_FIXED @@ -2318,7 +2320,7 @@ int16_t stereo_dft_band_config( const int16_t NFFT, /* i : analysis/synthesis window length */ const int16_t enc_dec /* i : flag to indicate enc vs dec */ ); - +#ifndef IVAS_FLOAT_FIXED void stereo_td_itd( ITD_DATA *hITD, /* i/o: ITD data structure */ float input_mem_itd[CPE_CHANNELS][STEREO_DFT_OVL_MAX], /* o : ITD memory (only used in DFT Stereo) */ @@ -2328,6 +2330,7 @@ void stereo_td_itd( const int16_t input_frame, /* i : input frame length */ float *input_mem[CPE_CHANNELS] /* i/o: input buffer memory */ ); +#endif void stereo_dft_dmx_out_reset( STEREO_DFT_DMX_DATA_HANDLE hStereoDftDmx /* i/o: DFT stereo DMX decoder */ @@ -2537,9 +2540,9 @@ void stereo_tca_dec( ); void stereo_tca_dec_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *synth[CPE_CHANNELS], /* i/o: output synth */ - const Word16 output_frame /* i : length of a frame per channel */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *synth[CPE_CHANNELS], /* i/o: output synth qsynth*/ + const Word16 output_frame /* i : length of a frame per channel Q0*/ ); void stereo_tca_scale_R_channel( @@ -2549,9 +2552,9 @@ void stereo_tca_scale_R_channel( ); void stereo_tca_scale_R_channel_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx, /* i/o: output synthesis, R channel */ - const Word16 output_frame /* i : frame length */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx, /* i/o: output synthesis, R channel q_out*/ + const Word16 output_frame /* i : frame length Q0*/ ); void adjustTargetSignal( @@ -2633,13 +2636,15 @@ int16_t select_stereo_mode( const IVAS_FORMAT ivas_format /* i : IVAS format */ ); +#ifndef IVAS_FLOAT_FIXED void stereo_classifier_init( STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ ); - +#else void stereo_classifier_init_fx( STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ ); +#endif void stereo_classifier_features( STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ @@ -2754,7 +2759,7 @@ void stereo_td_init_dec( void stereo_td_init_dec_fx( STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const Word16 last_element_mode /* i : last element mode */ + const Word16 last_element_mode /* i : last element mode Q0*/ ); void tdm_configure_dec( @@ -2778,15 +2783,15 @@ void tdm_upmix_plain( ); void tdm_upmix_plain_fx( - Word32 Left_fx[], /* o : left channel */ - Word32 Right_fx[], /* o : right channel */ - const Word32 PCh_2_L_fx[], /* i : primary channel */ - const Word32 SCh_2_R_fx[], /* i : secondary channel */ - const Word32 LR_ratio_fx, /* i : mixing ratio */ - const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration */ - const Word16 start_index, /* i : start index */ - const Word16 end_index, /* i : end index */ - const Word16 plus_minus_flag /* i : plus/minus flag */ + Word32 Left_fx[], /* o : left channel Qx*/ + Word32 Right_fx[], /* o : right channel Qx*/ + const Word32 PCh_2_L_fx[], /* i : primary channel Qx*/ + const Word32 SCh_2_R_fx[], /* i : secondary channel Qx*/ + const Word32 LR_ratio_fx, /* i : mixing ratio Q31*/ + const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration Q31*/ + const Word16 start_index, /* i : start index Q0*/ + const Word16 end_index, /* i : end index Q0*/ + const Word16 plus_minus_flag /* i : plus/minus flag Q0*/ ); void stereo_tdm_combine( @@ -2799,12 +2804,12 @@ void stereo_tdm_combine( ); void stereo_tdm_combine_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *PCh_2_L_fx, /* i/o: Primary channel -> output as left channel */ - Word32 *SCh_2_R_fx, /* i/o: Secondary channel -> output as right channel*/ - const Word16 output_frame, /* i : Number of samples */ - const Word16 flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis */ - const Word16 tdm_ratio_idx /* i : TDM ratio index */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *PCh_2_L_fx, /* i/o: Primary channel -> output as left channel Qx*/ + Word32 *SCh_2_R_fx, /* i/o: Secondary channel -> output as right channel Qx*/ + const Word16 output_frame, /* i : Number of samples Q0*/ + const Word16 flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis Q0*/ + const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ ); #ifdef IVAS_FLOAT_FIXED Word16 tdm_lp_comparison_fx( @@ -2888,6 +2893,7 @@ void tdm_bit_alloc( const int16_t tdm_inst_ratio_idx /* i : instantaneous correlation ratio index */ ); +#ifndef IVAS_FLOAT_FIXED void td_stereo_param_updt( const float lsp_old_PCh[], /* i : primary channel old LSPs */ const float lsf_old_PCh[], /* i : primary channel old LSFs */ @@ -2898,6 +2904,7 @@ void td_stereo_param_updt( const int16_t flag_ACELP16k, /* i : ACELP@16kHz flag */ const int16_t tdm_use_IAWB_Ave_lpc /* i : flag to indicate the usage of mean inactive LP coefficients */ ); +#endif void gsc_enc( Encoder_State *st, /* i/o: State structure */ @@ -2952,15 +2959,14 @@ uint16_t get_indice_st( #ifdef IVAS_FLOAT_FIXED void tdm_low_rate_dec_fx( - Decoder_State *st, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain */ - //Word16 *tmp_noise, /* o : long term temporary noise energy */ - Word16 *pitch_buf, /* o : floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - const Word16 *lsf_new /* i : ISFs at the end of the frame */ + Decoder_State *st, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Q_exc*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + const Word16 *lsf_new /* i : ISFs at the end of the frame Q8/100 (2.56x)*/ ); #endif @@ -2998,19 +3004,7 @@ void tdm_SCh_lsf_reuse_fx( const Word16 lsf_wgts_fx[M], /* i : LSF weights */ Word16 *beta_index /* i/o: quantization index */ ); -#endif - - -void tdm_SCh_lsf_reuse_ivas_fx( - const Word16 enc_dec, /* i : encoder/decoder flag */ - const Word32 element_brate, /* i : element bitrate */ - Word16 lsf_new[M], /* i/o: LSFs at the end of the frame */ - Word16 lsp_new[M], /* i/o: LSPs at the end of the frame */ - const Word16 tdm_lsfQ_PCh[M], /* i : primary channel LSFs (log2(2.56)) */ - const Word16 lsf_wgts[M], /* i : LSF weights Q15? */ - Word16 *beta_index /* i/o: quantization index */ -); - +#else void tdm_SCh_lsf_reuse( const int16_t enc_dec, /* i : encoder/decoder flag */ const int32_t element_brate, /* i : element bitrate */ @@ -3020,6 +3014,7 @@ void tdm_SCh_lsf_reuse( const float lsf_wgts[M], /* i : LSF weights */ int16_t *beta_index /* i/o: quantization index */ ); +#endif void first_VQstages( const float *const *cb, @@ -3666,9 +3661,9 @@ void applyDmxMdctStereo( ); void applyDmxMdctStereo_fx( - const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ - Word32 *output_fx[CPE_CHANNELS], /* o : output from core decoder */ - const Word16 output_frame /* i : output frame length */ + const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ + Word32 *output_fx[CPE_CHANNELS], /* o : output from core decoder q_out*/ + const Word16 output_frame /* i : output frame length Q0*/ ); @@ -3773,7 +3768,7 @@ void stereo_cng_compute_PScorr( void stereo_cng_dec_update( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ + const int32_t ivas_total_brate /* i : IVAS total bitrate Q0*/ ); void stereo_cna_update_params( @@ -3784,9 +3779,9 @@ void stereo_cna_update_params( ); void stereo_cna_update_params_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx[CPE_CHANNELS], /* i : Output signal */ - const Word16 output_frame, /* i : Output frame length */ - const Word16 tdm_ratio_idx /* i : TDM ratio index */ + Word32 *output_fx[CPE_CHANNELS], /* i : Output signal OUTPUT_Q*/ + const Word16 output_frame, /* i : Output frame length Q0*/ + const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ ); void dtx_enc_init( Encoder_State *st, /* i : Encoder state handle */ @@ -4108,7 +4103,7 @@ void stereo_switching_enc( #endif void stereo_switching_dec( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ + const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ ); void stereo_td2dft_update( @@ -4121,12 +4116,12 @@ void stereo_td2dft_update( ); void stereo_td2dft_update_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word16 n, /* i : channel number */ - Word32 output_fx[], /* i/o: synthesis @internal Fs */ - Word32 synth_fx[], /* i/o: synthesis @output Fs */ - Word32 hb_synth_fx[], /* i/o: hb synthesis */ - const Word16 output_frame /* i : frame length */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word16 n, /* i : channel number Q0*/ + Word32 output_fx[], /* i/o: synthesis @internal Fs Q11*/ + Word32 synth_fx[], /* i/o: synthesis @output Fs Q11*/ + Word32 hb_synth_fx[], /* i/o: hb synthesis Q11*/ + const Word16 output_frame /* i : frame length Q0*/ ); void stereo_mdct2dft_update( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -4135,9 +4130,9 @@ void stereo_mdct2dft_update( ); void stereo_mdct2dft_update_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 output0_fx[], /* i/o: synthesis @internal Fs, ch0 */ - Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 output0_fx[], /* i/o: synthesis @internal Fs, ch0 Q11*/ + Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 Q11*/ ); /*! r: number of bits written */ #ifdef IVAS_FLOAT_FIXED @@ -4615,6 +4610,13 @@ Word16 quantize_phi_fx( Word32 *phi_hat, /* o : quantized azimuth */ const Word16 n /* i : azimuth codebook size */ ); + +Word16 quantize_phi_enc_fx( + Word32 phi, /* i : azimuth value */ + const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + Word32 *phi_hat, /* o : quantized azimuth */ + const Word16 n /* i : azimuth codebook size */ +); #endif /*! r: decoded elevation value */ float deindex_elevation( @@ -4711,6 +4713,23 @@ int16_t ivas_chan_project_elevation_index( ); #endif +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_param_est_enc( + DIRAC_ENC_HANDLE hDirAC, + IVAS_QDIRECTION *q_direction, + const UWord8 useLowerRes, + Word32 *data_f_fx[], + Word32 **pp_fr_real_fx, + Word32 **pp_fr_imag_fx, + Word16 pp_fr_q, + const Word16 input_frame, + const IVAS_FORMAT ivas_format, + const Word16 hodirac_flag, + const Word16 nchan_fb_in, + Word16 *mono_frame_count, + Word16 *dirac_mono_flag +); +#else void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, @@ -4725,6 +4744,7 @@ void ivas_dirac_param_est_enc( int16_t *mono_frame_count, int16_t *dirac_mono_flag ); +#endif void ivas_sba_config( @@ -5141,6 +5161,26 @@ void ivas_dirac_dec_get_response_fx( Word16 Q_out); #endif + +#ifdef IVAS_FLOAT_FIXED +void calculate_hodirac_sector_parameters_fx( + DIRAC_ENC_HANDLE hDirAC, /* i : DirAC handle */ + Word32 RealBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector (L+1)^2 x N_bins, real part */ + Word32 ImagBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector, imaginary part */ + Word16 Qfac, /* i : Q-factor of signal vector */ + const Word32 beta_fx, /* i : forgetting factor for average filtering, Q30 */ + const Word16 *band_grouping, /* i : indices of band groups */ + const Word16 N_bands, /* i : number of bands (groups) */ + const Word16 enc_param_start_band, /* i : first band to process */ + Word32 *azi_fx, /* o : array of sector azimuth angles, flat Q23 */ + Word32 *ele_fx, /* o : array of sector elevation angles, flat Q23 */ + Word32 *diff_fx, /* o : array of sector diffuseness values, flat */ + Word16 *diff_exp, /* o : array of sector diffuseness exponents, flat */ + Word32 *ene_fx, /* o : array of sector energy values, flat */ + Word16 *ene_exp /* o : array of sector energy exponents, flat */ +); +#endif + void calculate_hodirac_sector_parameters( DIRAC_ENC_HANDLE hDirAC, float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],/* i : signal vector (L+1)^2 x N_bins, real part */ @@ -5446,18 +5486,18 @@ Word16 matrix_product_mant_exp( #ifdef IVAS_FLOAT_FIXED void mat2svdMat_fx( - const Word32 *mat, /* i : matrix as column ordered vector */ - Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* o : matrix as two-dimensional arry */ - const Word16 nRows, /* i : number of rows of the matrix */ - const Word16 mCols, /* i : number of columns of the matrix */ - const Word16 transpose /* i : flag indication transposition */ + const Word32 *mat, /* i : matrix as column ordered vector Qx*/ + Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* o : matrix as two-dimensional arry Qx*/ + const Word16 nRows, /* i : number of rows of the matrix Q0*/ + const Word16 mCols, /* i : number of columns of the matrix Q0*/ + const Word16 transpose /* i : flag indication transposition Q0*/ ); void svdMat2mat_fx( - Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* i : matrix as two-dimensional arry */ - Word32 *mat, /* o : matrix as column ordered vector */ - const Word16 nRows, /* i : number of rows of the matrix */ - const Word16 mCols /* i : number of columns of the matrix */ + Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* i : matrix as two-dimensional arry Qx*/ + Word32 *mat, /* o : matrix as column ordered vector Qx*/ + const Word16 nRows, /* i : number of rows of the matrix Q0*/ + const Word16 mCols /* i : number of columns of the matrix Q0*/ ); #else @@ -5583,14 +5623,14 @@ Word16 computeMixingMatricesResidual_fx( #ifdef IVAS_FLOAT_FIXED /*! r: error or success */ Word16 svd_fx( - Word32 InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) */ + Word32 InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) InputMatrix_e*/ Word16 InputMatrix_e, - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) */ - Word32 singularValues[MAX_OUTPUT_CHANNELS], /* o : singular values vector (S) */ - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) */ + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) Q31*/ + Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* o : singular values vector (S) singularValues_fx_e*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) Q31*/ Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ - const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed */ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ ); #else /*! r: error or success */ @@ -5862,12 +5902,12 @@ void ivas_sba_mix_matrix_determiner( /* AGC */ /*! r: AGC enable flag */ +#ifndef IVAS_FLOAT_FIXED int16_t ivas_agc_enc_get_flag( const int16_t nchan_transport /* i : number of transport channels */ ); - -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_agc_enc_get_flag_fx( +#else +Word16 ivas_agc_enc_get_flag( const Word16 nchan_transport /* i : number of transport channels */ ); #endif @@ -6145,7 +6185,7 @@ ivas_error ivas_sba_dec_render_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *output_fx[], /* o : rendered time signal */ + Word32 *output_fx[], /* o : rendered time signal Q11*/ Word16 out_len/*Store the length of values in each channel*/ ); #endif // IVAS_FLOAT_FIXED @@ -6490,7 +6530,7 @@ void ivas_enc_cov_handler_process_fx( ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ Word32 **ppIn_FR_real, Word32 **ppIn_FR_imag, - Word16 *q_ppIn_FR, + Word16 q_ppIn_FR, Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *q_cov_real[IVAS_SPAR_MAX_CH], Word32 *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -6875,6 +6915,7 @@ void ivas_spar_arith_coeffs_com_init( const Word16 table_idx, const Word16 enc_dec); +#ifndef IVAS_FLOAT_FIXED int16_t ivas_arith_encode_cmplx_cell_array( ivas_arith_t *pArith_re, ivas_arith_t *pArith_re_diff, @@ -6887,6 +6928,7 @@ int16_t ivas_arith_encode_cmplx_cell_array( const int16_t any_diff , const int16_t wc_strat_arith ); +#endif ivas_error ivas_huffman_decode( ivas_huffman_cfg_t *huff_cfg, @@ -7142,9 +7184,11 @@ void ivas_masa_estimate_energy( const int16_t nchan_transport /* i : number of MASA input/transport channels */ ); +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_masa_enc_config( Encoder_Struct* st_ivas /* i/o: IVAS encoder structure */ ); +#endif void ivas_masa_set_elements( const int32_t ivas_total_brate, /* i : codec total bitrate */ @@ -7551,11 +7595,11 @@ void panning_wrap_angles( float *ele_wrapped /* o : wrapped elevation component */ ); #ifdef IVAS_FLOAT_FIXED -void panning_wrap_angles_fixed( - const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ - const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) */ - Word32 *azi_wrapped, /* o : wrapped azimuth component */ - Word32 *ele_wrapped /* o : wrapped elevation component */ +void panning_wrap_angles_fx( + const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q22 */ + const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q22 */ + Word32 *azi_wrapped, /* o : wrapped azimuth component Q22 */ + Word32 *ele_wrapped /* o : wrapped elevation component Q22 */ ); #endif void v_sort_ind( @@ -8055,9 +8099,11 @@ void ivas_omasa_enc_close( OMASA_ENC_HANDLE *hOMasa /* i/o: encoder OMASA handle */ ); +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_omasa_enc_config( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); +#endif // !IVAS_FLOAT_FIXED ivas_error ivas_omasa_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -8109,7 +8155,7 @@ void ivas_set_ism_importance_interformat_fx( const Word16 nchan_transport, /* i : number of transported channels */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ - const Word32 lp_noise_CPE_fx, /* i : LP filtered total noise estimation */ + const Word16 lp_noise_CPE_fx, /* i : LP filtered total noise estimation */ Word16 ism_imp[] /* o : ISM importance flags */ ); #endif @@ -8388,14 +8434,25 @@ void ivas_fb_mixer_get_windowed_fr( const int16_t nchan_fb_in /* i : number of analysis channels */ ); +#ifdef IVAS_FLOAT_FIXED void ivas_fb_mixer_process( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ - float ***mixer_mat, /* i : mixer matrix */ - float **ppOut_pcm, /* o : output audio channels */ + 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*/ const int16_t frame_len, /* i : frame length in samples */ int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ ); - +#else +void ivas_fb_mixer_process( + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + float ***mixer_mat, /* i : mixer matrix */ + float **ppOut_pcm, /* o : output audio channels */ + const int16_t frame_len, /* i : frame length in samples */ + int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ +); +#endif void ivas_fb_mixer_get_in_out_mapping( const IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ @@ -8447,10 +8504,10 @@ void dequantize_sns_fx( Decoder_State **sts ); void inverseMS_fx( - const Word16 L_frame, /* i : frame length */ - Word32 x0[], /* i/o: mid/left channel coefficients */ - Word32 x1[], /* i/o: side/right channel coefficients */ - const Word32 norm_fac /* i : normalization factor */ + const Word16 L_frame, /* i : frame length Q0*/ + Word32 x0[], /* i/o: mid/left channel coefficients Qx*/ + Word32 x1[], /* i/o: side/right channel coefficients Qx*/ + const Word32 norm_fac /* i : normalization factor Q31*/ ); #endif diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index a8d7e76597acb3cfb1b32264f57fed5e1be71c35..a9ca1f48d177cb731a2889049bc3cef0f6f4c017 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -692,6 +692,28 @@ Word16 masa_sq_fx( const Word16 cb_sz /* i : codebook size */ ); +void ivas_compute_spar_params_enc_fx( + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_dm_fv_re, + const Word16 i_ts, + Word32 ***mixer_mat_fx, + Word16 *q_mixer_mat, + const Word16 start_band, + const Word16 end_band, + const Word16 dtx_vad, + const Word16 num_ch, + const Word16 bands_bw, + const Word16 active_w, + const Word16 active_w_vlbr, + ivas_spar_md_com_cfg *hSparCfg, + ivas_spar_md_t *hSparMd, + Word32 *pWscale, + Word16 *q_Wscale, + const Word16 from_dirac, + const Word16 dyn_active_w_flag ); + void ivas_compute_spar_params_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, @@ -1889,16 +1911,16 @@ void ivas_GenShapedWBExcitation_fx( const Word16 uv_flag, /* i : unvoiced flag */ const Word16 igf_flag ); -Word16 ivas_wb_bwe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output[], /* i : suntehsis @ internal Fs */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ - Word16 *Qpost ); +Word16 ivas_wb_bwe_dec_fx( /* o : Q_syn_hb*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ + Word16 *Qpost ); void ivas_param_ism_config_fx( PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i/o: IVAS Param ISM Config Structure */ @@ -1998,6 +2020,20 @@ Word16 set_ACELP_flag_IVAS( const Word16 cng_type /* i : CNG type */ ); +void ivas_calc_c_p_coeffs_enc_fx( + ivas_spar_md_t *pSparMd, + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + const Word16 i_ts, + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 num_ch, + const Word16 num_dmx, + const Word16 band_idx, + const Word16 dtx_vad, + const Word16 compute_p_flag, + const Word16 dyn_active_w_flag ); + void ivas_calc_c_p_coeffs_fx( ivas_spar_md_t *pSparMd, Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -3286,8 +3322,27 @@ void computeReferencePower_enc_fx( const Word16 num_freq_bands, /* i : Number of frequency bands */ const IVAS_FORMAT ivas_format, /* i : ivas_format */ Word16 ref_power_w, /* i : use 0 if hodirac is enabled */ - const Word16 nchan_ana /* i : number of analysis channels */ + const Word16 nchan_ana, /* i : number of analysis channels */ + Word16 inp_q, /* i : q of cld buffers */ + Word16 *ref_q /* i : output q */ ); + +void computeReferencePower_enc_fx_dirac( + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ + Word32 Cldfb_ImagBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal */ + Word16 e_Cldfb, /* i : exponent of Cldfb buffer */ + Word32 *reference_power, /* o : Estimated power */ + Word16 *e_reference, /* o : exponent of reference_power */ + const Word16 enc_param_start_band, /* i : first band to process */ + const Word16 num_freq_bands, /* i : Number of frequency bands */ + const IVAS_FORMAT ivas_format, /* i : ivas_format */ + Word16 ref_power_w, /* i : use 0 if hodirac is enabled */ + const Word16 nchan_ana, /* i : number of analysis channels */ + Word16 *mono_frame_count, /* i/o: Mono Frame Count */ + Word16 *dirac_mono_flag /* i/o: Mono Flag */ +); + void ivas_omasa_enc_fx( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ @@ -3412,4 +3467,61 @@ ivas_error ivas_param_mc_enc_open_fx( ivas_error ivas_param_mc_enc_reconfig_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); + +Word16 ivas_arith_encode_cmplx_cell_array( + ivas_arith_t *pArith_re, + ivas_arith_t *pArith_re_diff, + const Word16 *pDo_diff, + const Word16 nB, + Word16 *pSymbol_re, + Word16 *pSymbol_old_re, + ivas_cell_dim_t *pCell_dims, + BSTR_ENC_HANDLE hMetaData, + const Word16 any_diff, + const Word16 wc_strat_arith ); + +ivas_error stereo_dmx_evs_init_encoder_fx( + STEREO_DMX_EVS_ENC_HANDLE *hStereoDmxEVS_out, /* o : Stereo downmix for EVS encoder handle */ + const Word32 input_Fs /* i : input sampling rate */ +); + +void stereo_dmx_evs_enc_fx( + STEREO_DMX_EVS_ENC_HANDLE hStereoDmxEVS, /* i/o: Stereo downmix for EVS encoder handle */ + const Word32 input_Fs, /* i : input sampling rate */ + Word16 data[CPE_CHANNELS * L_FRAME48k], /* i/o: input signal Q0 */ + const Word16 n_samples, /* i : number of input samples */ + const bool is_binaural /* i : indication that input is binaural audio */ +); + +void stereo_dmx_evs_close_encoder_fx( + STEREO_DMX_EVS_ENC_HANDLE *hStereoDmxEVS /* i/o: Stereo downmix for EVS encoder handle */ +); + +void ivas_omasa_encode_masa_to_total_fx( + Word32 masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* Q30 */ + BSTR_ENC_HANDLE hMetaData, + const Word16 low_bitrate_mode, + const Word16 nbands, + const Word16 nblocks ); +ivas_error ivas_masa_enc_config_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); +ivas_error ivas_omasa_enc_config_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +void ivas_omasa_enc_close_fx( + OMASA_ENC_HANDLE *hOMasa /* i/o: encoder OMASA handle */ +); +ivas_error ivas_omasa_enc_open_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +); + +void ivas_masa_estimate_energy_fx( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ + Word32 *data_fx[], /* i : Input audio channels Q(q_data) */ + const Word16 input_frame, /* i : frame length */ + const Word16 nchan_transport, /* i : number of MASA input/transport channels */ + Word16 q_data /* i : q for data_fx */ +); #endif diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index 3bcec831e87b6d4ee95bb86a0a08d6c5d6df389d..3bb90ec8d7d9488fb8fc3188142b06b3d2544f98 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -177,13 +177,20 @@ ivas_error ivas_qmetadata_allocate_memory( FOR( j = 0; j < nbands; j++ ) { +#ifndef IVAS_FLOAT_FIXED set_zero( hQMetaData->q_direction[dir].band_data[j].elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); -#ifdef IVAS_FLOAT_FIXED - set32_fx( hQMetaData->q_direction[dir].band_data[j].elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); -#endif set_zero( hQMetaData->q_direction[dir].band_data[j].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); -#ifdef IVAS_FLOAT_FIXED +#ifdef MSAN_FIX + set_zero( hQMetaData->q_direction[dir].band_data[j].q_elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); + set_zero( hQMetaData->q_direction[dir].band_data[j].q_azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); +#endif +#else + set32_fx( hQMetaData->q_direction[dir].band_data[j].elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); set32_fx( hQMetaData->q_direction[dir].band_data[j].azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); +#ifdef MSAN_FIX + set32_fx( hQMetaData->q_direction[dir].band_data[j].q_elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); + set32_fx( hQMetaData->q_direction[dir].band_data[j].q_azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); +#endif #endif set_zero( hQMetaData->q_direction[dir].band_data[j].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); #ifdef IVAS_FLOAT_FIXED diff --git a/lib_com/ivas_qspherical_com.c b/lib_com/ivas_qspherical_com.c index ab10cd57c495f9caccd8f639aa4d0dd9a7c88d8f..db931df0f0194ac3017455ff97e44684850cf027 100644 --- a/lib_com/ivas_qspherical_com.c +++ b/lib_com/ivas_qspherical_com.c @@ -495,6 +495,84 @@ ELSE move32(); id_phi = add( id_phi, shr( n, 1 ) ); +return id_phi; +} + +Word16 quantize_phi_enc_fx( + Word32 phi, /* i : azimuth value, Q22 */ + const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + Word32 *phi_hat, /* o : quantized azimuth, Q22 */ + const Word16 n /* i : azimuth codebook size */ +) +{ + Word16 id_phi; + Word32 dd_fx; + Word32 delta_phi_fx; + Word32 inv_delta_phi_fx; + Word32 temp_res; + Word16 temp_e; + + delta_phi_fx = BASOP_Util_Divide3232_Scale_cadence( 360, n, &temp_e ); + delta_phi_fx = L_shl( delta_phi_fx, sub( temp_e, 9 ) ); + inv_delta_phi_fx = BASOP_Util_Divide3232_Scale_cadence( n, 360, &temp_e ); + + IF( EQ_16( n, 1 ) ) + { + *phi_hat = 0; + move32(); + + return 0; + } + + test(); + IF( EQ_16( flag_delta, 1 ) && GT_16( n, 2 ) ) + { + dd_fx = dd_val[n]; + move32(); + } + ELSE + { + dd_fx = 0; + move32(); + } + + temp_res = Mpy_32_32( L_sub( L_sub( phi, DEGREE_180_Q_22 ), dd_fx ), inv_delta_phi_fx ); + temp_res = L_shl( temp_res, temp_e ); + id_phi = round_fx( L_shr( temp_res, Q22 - Q16 ) ); + + assert( L_sub( L_abs( temp_res ), abs( id_phi ) * ONE_IN_Q22 ) <= ONE_IN_Q21 ); + + + IF( add( id_phi, shr( n, 1 ) ) < 0 ) + { + id_phi = add( id_phi, 1 ); + } + + IF( sub( id_phi, shr( n, 1 ) ) >= 0 ) + { + id_phi = negate( shr( n, 1 ) ); + } + + IF( EQ_16( id_phi, negate( add( shr( n, 1 ), ( n % 2 ) ) ) ) ) + { + id_phi = add( id_phi, ( n % 2 ) ); + } + ELSE{ + IF( EQ_16( id_phi, add( shr( n, 1 ), ( n % 2 ) ) ) ){ + IF( n % 2 ){ + id_phi = sub( id_phi, 1 ); +} +ELSE +{ + id_phi = negate( id_phi ); +} +} +} + +*phi_hat = L_add_sat( L_add_sat( ( id_phi * delta_phi_fx ), dd_fx ), DEGREE_180_Q_22 ); +move32(); +id_phi = add( id_phi, shr( n, 1 ) ); + return id_phi; } #endif diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 4b9d3984237cb96c900c7ccfde32eaf50212c571..9f08e3dfe16148821e3f94a9f8c079400b9df52f 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -1041,6 +1041,9 @@ const int16_t DirAC_block_grouping_5ms_MDFT[MAX_PARAM_SPATIAL_SUBFRAMES + 1] = 0, 1, 2, 3, 4 }; +#ifdef IVAS_FLOAT_FIXED +const Word32 c_weights_fx[DIRAC_NO_FB_BANDS_MAX] /* Q30 */ = { 106970960, 1033798336, 1065867776, 1071704704, 1073381888, 1073741824, 1073494016, 1072883072, 1072012032, 1070930560, 1069665600, 1068232640, 1066641792, 1064899968, 1063012224, 1060982464, 1058814144, 1056510016, 1054072832, 1051505280, 1048809664, 1045988480, 1043044160, 1039979072, 1036795776, 1033496576, 1030084096, 1026560960, 1022929600, 1019192512, 1015352576, 1011412416, 1007374720, 1003242112, 999017472, 994703488, 990302976, 985818688, 981253568, 976610304, 971891712, 967100672, 962240064, 957312576, 952321088, 947268224, 942156992, 936990080, 931770048, 926499840, 921182016, 915819200, 910414208, 904969344, 899487488, 893970944, 888422272, 882843840, 877238144, 871607552, 865954432, 860280896, 854589184, 848881728, 843160384, 837427328, 831684672, 825934208, 820178240, 814418240, 808656320, 802894208, 797133568, 791376192, 785623744, 779877568, 774139520, 768410880, 762693184, 756987904, 751296064, 745619328, 739958784, 734315584, 728691008, 723086208, 717502016, 711939712, 706400064, 700884096, 695392768, 689926912, 684487232, 679074688, 673689856, 668333504, 663006464, 657709056, 652442176, 647206144, 642001600, 636828992, 631688896, 626581696, 621507776, 616467520, 611461184, 606489344, 601552064, 596649792, 591782528, 586950784, 582154560, 577394112, 572669696, 567981312, 563329088, 558713152, 554133568, 549590464, 545083840, 540613760, 536180160, 531783104, 527422528, 523098464, 518810784, 514559520, 510344672, 506165856, 502023360, 497916832, 493846304, 489811488, 485812448, 481848832, 477920672, 474027808, 470169952, 466347008, 462558848, 458805152, 455085920, 451400736, 447749600, 444132160, 440548320, 436997792, 433480416, 429995904, 426544032, 423124608, 419737376, 416382144, 413058720, 409766720, 406505984, 403276288, 400077280, 396908768, 393770656, 390662496, 387584064, 384535200, 381515616, 378525024, 375563200, 372629952, 369724864, 366847872, 363998592, 361176672, 358382176, 355614592, 352873760, 350159456, 347471328, 344809216, 342172864, 339562048, 336976384, 334415808, 331879840, 329368576, 326881472, 324418432, 321979104, 319563392, 317170976, 314801664, 312455232, 310131328, 307829856, 305550528, 303293088, 301057440, 298843168, 296650176, 294478304, 292327168, 290196672, 288086432, 285996512, 283926432, 281876224, 279845472, 277834016, 275841792, 273868480, 271913856, 269977792, 268059968, 266160304, 264278672, 262414768, 260568368, 258739360, 256927520, 255132768, 253354752, 251593392, 249848448, 248119936, 246407424, 244710816, 243030080, 241364928, 239715120, 238080672, 236461248, 234856752, 233267088, 231692016, 230131440, 228585136, 227053024, 225534848, 224030544, 222539872, 221062832 }; +#endif const float c_weights[DIRAC_NO_FB_BANDS_MAX] = { 9.962447e-02f, 9.627997e-01f, 9.926667e-01f, 9.981028e-01f, 9.996648e-01f, 1.000000e+00f, 9.997692e-01f, 9.992002e-01f, 9.983890e-01f, 9.973818e-01f, 9.962037e-01f, 9.948692e-01f, 9.933876e-01f, 9.917654e-01f, 9.900073e-01f, 9.881169e-01f, 9.860975e-01f, 9.839516e-01f, 9.816818e-01f, 9.792906e-01f, 9.767801e-01f, 9.741527e-01f, 9.714106e-01f, 9.685560e-01f, 9.655913e-01f, 9.625187e-01f, 9.593406e-01f, 9.560594e-01f, 9.526774e-01f, 9.491970e-01f, 9.456208e-01f, 9.419512e-01f, 9.381908e-01f, 9.343420e-01f, 9.304075e-01f, 9.263898e-01f, 9.222915e-01f, 9.181152e-01f, 9.138636e-01f, 9.095392e-01f, 9.051447e-01f, 9.006827e-01f, 8.961559e-01f, 8.915668e-01f, 8.869181e-01f, 8.822123e-01f, 8.774521e-01f, 8.726400e-01f, 8.677785e-01f, 8.628702e-01f, 8.579176e-01f, 8.529231e-01f, 8.478893e-01f, 8.428184e-01f, 8.377130e-01f, 8.325753e-01f, 8.274077e-01f, 8.222124e-01f, 8.169917e-01f, 8.117478e-01f, 8.064829e-01f, 8.011990e-01f, 7.958982e-01f, 7.905827e-01f, 7.852543e-01f, 7.799150e-01f, 7.745667e-01f, 7.692112e-01f, 7.638505e-01f, 7.584861e-01f, 7.531199e-01f, 7.477535e-01f, 7.423885e-01f, 7.370265e-01f, 7.316691e-01f, 7.263176e-01f, 7.209736e-01f, 7.156384e-01f, 7.103134e-01f, 7.049999e-01f, 6.996990e-01f, 6.944121e-01f, 6.891403e-01f, 6.838847e-01f, 6.786464e-01f, 6.734265e-01f, 6.682258e-01f, 6.630455e-01f, 6.578863e-01f, 6.527492e-01f, 6.476350e-01f, 6.425445e-01f, 6.374784e-01f, 6.324376e-01f, 6.274226e-01f, 6.224341e-01f, 6.174729e-01f, 6.125393e-01f, 6.076341e-01f, 6.027577e-01f, 5.979106e-01f, 5.930932e-01f, 5.883061e-01f, 5.835497e-01f, 5.788242e-01f, 5.741301e-01f, 5.694676e-01f, 5.648372e-01f, 5.602390e-01f, 5.556734e-01f, 5.511404e-01f, 5.466405e-01f, 5.421737e-01f, 5.377402e-01f, 5.333402e-01f, 5.289738e-01f, 5.246411e-01f, 5.203422e-01f, 5.160771e-01f, 5.118460e-01f, 5.076489e-01f, 5.034858e-01f, 4.993567e-01f, 4.952616e-01f, 4.912005e-01f, 4.871734e-01f, 4.831802e-01f, 4.792209e-01f, 4.752955e-01f, 4.714037e-01f, 4.675457e-01f, 4.637212e-01f, 4.599302e-01f, 4.561725e-01f, 4.524481e-01f, 4.487567e-01f, 4.450983e-01f, 4.414728e-01f, 4.378799e-01f, 4.343195e-01f, 4.307915e-01f, 4.272956e-01f, 4.238318e-01f, 4.203997e-01f, 4.169993e-01f, 4.136303e-01f, 4.102926e-01f, 4.069859e-01f, 4.037101e-01f, 4.004649e-01f, 3.972501e-01f, 3.940655e-01f, 3.909109e-01f, 3.877861e-01f, 3.846909e-01f, 3.816250e-01f, 3.785882e-01f, 3.755803e-01f, 3.726010e-01f, 3.696501e-01f, 3.667275e-01f, 3.638328e-01f, 3.609658e-01f, 3.581263e-01f, 3.553141e-01f, 3.525289e-01f, 3.497705e-01f, 3.470387e-01f, 3.443331e-01f, 3.416537e-01f, 3.390001e-01f, 3.363720e-01f, 3.337694e-01f, 3.311919e-01f, 3.286393e-01f, 3.261114e-01f, 3.236079e-01f, 3.211286e-01f, 3.186733e-01f, 3.162418e-01f, 3.138337e-01f, 3.114490e-01f, 3.090872e-01f, 3.067484e-01f, 3.044321e-01f, 3.021382e-01f, 2.998664e-01f, 2.976166e-01f, 2.953885e-01f, 2.931819e-01f, 2.909966e-01f, 2.888323e-01f, 2.866889e-01f, 2.845661e-01f, 2.824637e-01f, 2.803816e-01f, 2.783194e-01f, 2.762770e-01f, 2.742543e-01f, 2.722509e-01f, 2.702667e-01f, 2.683014e-01f, 2.663550e-01f, 2.644271e-01f, 2.625177e-01f, 2.606264e-01f, 2.587531e-01f, 2.568977e-01f, 2.550599e-01f, 2.532395e-01f, 2.514364e-01f, 2.496503e-01f, 2.478811e-01f, 2.461287e-01f, 2.443928e-01f, 2.426732e-01f, 2.409698e-01f, 2.392824e-01f, 2.376109e-01f, 2.359550e-01f, 2.343146e-01f, 2.326895e-01f, 2.310797e-01f, 2.294848e-01f, 2.279047e-01f, 2.263394e-01f, 2.247886e-01f, 2.232521e-01f, 2.217299e-01f, 2.202217e-01f, 2.187274e-01f, 2.172469e-01f, 2.157800e-01f, 2.143266e-01f, 2.128865e-01f, 2.114596e-01f, 2.100457e-01f, 2.086447e-01f, 2.072564e-01f, 2.058808e-01f }; /*----------------------------------------------------------------------* diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index ff79170198cd26371eefe34a31b2b31e798ad93d..6d1648c4e1de524dc08de8f169bccc326fb759d6 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -179,6 +179,9 @@ extern const int16_t DirAC_band_grouping_5[5 + 1]; extern const int16_t DirAC_block_grouping[MAX_PARAM_SPATIAL_SUBFRAMES + 1]; extern const int16_t DirAC_block_grouping_5ms_MDFT[MAX_PARAM_SPATIAL_SUBFRAMES + 1]; +#ifdef IVAS_FLOAT_FIXED +extern const Word32 c_weights_fx[DIRAC_NO_FB_BANDS_MAX]; // Q30 +#endif extern const float c_weights[DIRAC_NO_FB_BANDS_MAX]; extern const float w_nm[NUM_ANA_SECTORS][9]; diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index e7d6600c132fee81f8fa71e5365c7b394855ba5f..269c62d281fbd9149ce1f38fe8cdac4a3c5e6e6f 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -1704,14 +1704,14 @@ const Word16 cb_azi_chan_16fx[] = { 0, 1920, 7040, 8640 }; // Q6 * MASA and ISM (OMASA) combined format ROM tables *----------------------------------------------------------------------------------*/ -const Word32 dct4_fx[4 * 4] = { +const Word32 dct4_fx[4 * 4] = { // Q31 1073741824, 1402951040, 1073741824, 581109056, 1073741824, 581109056, -1073741824, -1402951040, 1073741824, -581109056, -1073741824, 1402951040, 1073741824, -1402951040, 1073741824, -581109056 }; -const Word32 dct5_fx[5 * 5] = { +const Word32 dct5_fx[5 * 5] = { // Q31 960354688, 1291711360, 1098867328, 798219648, 419618304, 960354688, 798219648, -419618304, -1291711360, -1098867328, 960354688, 0, -1358283392, 0, 1358283392, @@ -1719,7 +1719,7 @@ const Word32 dct5_fx[5 * 5] = { 960354688, -1291711360, 1098867328, -798219648, 419618304 }; -const Word32 dct8_fx[8 * 8] = { +const Word32 dct8_fx[8 * 8] = { // Q31 759350208, 1053125952, 991922688, 892708928, 759350208, 596570944, 410813632, 209379648, 759350208, 892708928, 410813632, -209379648, -759350208, -1053125952, -991922688, -596570944, 759350208, 596570944, -410813632, -1053125952, -759350208, 209379648, 991922688, 892708928, @@ -1730,7 +1730,7 @@ const Word32 dct8_fx[8 * 8] = { 759350208, -1053125952, 991922688, -892708928, 759350208, -596570944, 410813632, -209379648 }; -const Word32 dct12_fx[12 * 12] = { +const Word32 dct12_fx[12 * 12] = { // Q31 619978560, 869301376, 846752832, 810030848, 759350208, 695569984, 619978560, 533649696, 438301408, 335436960, 226989024, 114460880, 619978560, 810030848, 619978560, 335436960, 0, -335436960, -619978560, -810030848, -876602816, -810030848, -619978560, -335436960, 619978560, 695569984, 226989024, -335436960, -759350208, -869301376, -619978560, -114460880, 438301408, 810030848, 846752832, 533649696, diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index facff366706fbb0c1b0b67a329e6020327185200..9d21cfbb40c14dd71c027ae5a461837e6e8f4fcd 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -87,6 +87,51 @@ *------------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED +static void ivas_get_pred_coeffs_enc_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_pred_coeffs, + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_dm_fv_re, + const Word16 in_chans, + const Word16 start_band, + const Word16 end_band, + const Word16 active_w, + const Word16 active_w_vlbr, + const Word16 dtx_vad, + const Word16 from_dirac, + const Word16 dyn_active_w_flag, + const Word16 res_ind ); + +static void ivas_get_Wscaling_factor_enc_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 q_pred_coeffs_re, + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 start_band, + const Word16 end_band, + const Word16 dtx_vad, + const Word16 num_ch, + const Word16 *pNum_dmx, + const Word16 bands_bw, + const Word16 active_w, + const Word16 active_w_vlbr, + Word32 *pWscale, + Word16 *q_pWscale, + const Word16 dyn_active_w_flag ); + +static void ivas_calc_post_pred_per_band_enc_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 num_ch, + const Word16 band_idx, + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_postpred_cov_re ); static void ivas_get_pred_coeffs_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -274,7 +319,7 @@ void ivas_spar_config_fx( } ELSE { - *nchan_transport = ivas_get_sba_num_TCs( ivas_total_brate, sba_order ); + *nchan_transport = ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_order ); move16(); } @@ -460,7 +505,6 @@ int16_t ivas_get_sba_num_TCs( return nchan_transport; } - #ifdef IVAS_FLOAT_FIXED Word16 ivas_get_sba_num_TCs_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ @@ -697,10 +741,13 @@ static void ivas_get_pred_coeffs( * Calculation of prediction coefficients *-----------------------------------------------------------------------------------------*/ -static void ivas_get_pred_coeffs_fx( +static void ivas_get_pred_coeffs_enc_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_pred_coeffs, Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_dm_fv_re, const Word16 in_chans, const Word16 start_band, const Word16 end_band, @@ -709,203 +756,166 @@ static void ivas_get_pred_coeffs_fx( const Word16 dtx_vad, const Word16 from_dirac, const Word16 dyn_active_w_flag, - const Word16 res_ind, - Word16 *q_pred_coeffs, - Word16 *q_dm_fv_re ) + const Word16 res_ind ) { - Word16 i, j, k, b, p; + Word16 i, j, k, b; Word32 abs_value; Word32 w_norm_fac; - Word32 one_in_q; - Word32 div_factor[IVAS_MAX_NUM_BANDS]; + Word32 one_in_q, L_tmp; + Word16 q_tmp, e_tmp; + Word64 abs_value64, tmp64; + Word16 q_ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + Word16 div_factor[IVAS_MAX_NUM_BANDS]; + Word16 div_factor_e[IVAS_MAX_NUM_BANDS]; Word16 pred_dim = sub( in_chans, 1 ); - Word16 tmp_shift, prev_tmp_shift, s_div, div_shift; + Word16 tmp_shift, s_div, div_shift; IF( EQ_16( from_dirac, 1 ) ) { - w_norm_fac = ONE_IN_Q29; + w_norm_fac = 1; move32(); } ELSE { - w_norm_fac = 3 * ONE_IN_Q29; + w_norm_fac = 3; move32(); } - tmp_shift = Q30; - move16(); + IF( active_w == 0 ) { - Word32 pPred_temp[IVAS_MAX_NUM_BANDS]; - Word16 q_pred_temp; - prev_tmp_shift = 31; - move16(); + Word64 pPred_temp[IVAS_MAX_NUM_BANDS]; + Word16 q_pPred_temp[IVAS_MAX_NUM_BANDS]; - set32_fx( pPred_temp, 0, IVAS_MAX_NUM_BANDS ); + set64_fx( pPred_temp, 0, IVAS_MAX_NUM_BANDS ); + set16_fx( q_pPred_temp, 31, IVAS_MAX_NUM_BANDS ); FOR( k = start_band; k < end_band; k++ ) { - div_factor[k] = L_max( 1, cov_real[0][0][k] ); - move32(); - tmp_shift = Q30; + div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_max( 1, cov_real[0][0][k] ), &s_div ); move16(); - IF( NE_32( cov_real[0][0][k], ONE_IN_Q30 ) ) + + div_factor_e[k] = sub( add( s_div, q_cov_real[0][0][k] ), 31 ); + move16(); + } + + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( k = start_band; k < end_band; k++ ) { - div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); - move32(); - IF( s_div < 0 ) + tmp64 = W_mult_32_16( cov_real[add( i, 1 )][0][k], div_factor[k] ); + tmp_shift = W_norm( tmp64 ); + IF( tmp64 != 0 ) { - div_shift = add( 15, s_div ); - tmp_shift = Q30; + ppPred_coeffs_re[i][k] = W_extract_h( W_shl( tmp64, tmp_shift ) ); // 1 + q_cov_real[i+1][0][k] + tmp_shift + 15 - div_factor_e[k] - 32 + move32(); + q_ppPred_coeffs_re[i][k] = add( sub( add( q_cov_real[add( i, 1 )][0][k], tmp_shift ), div_factor_e[k] ), 1 + 15 - 32 ); move16(); } ELSE { - div_shift = 15; + ppPred_coeffs_re[i][k] = 0; + move32(); + q_ppPred_coeffs_re[i][k] = 31; move16(); - tmp_shift = sub( Q30, s_div ); } - div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift - move16(); - IF( LT_16( tmp_shift, prev_tmp_shift ) ) + // IVAS_CALCULATE_SQ_ABS_N( ppPred_coeffs_re[i][k], abs_value ); + abs_value = Mpy_32_32( ppPred_coeffs_re[i][k], ppPred_coeffs_re[i][k] ); // Q = 2*q_ppPred_coeffs_re[i][k] - 31 + q_tmp = sub( shl( q_ppPred_coeffs_re[i][k], 1 ), 31 ); + + IF( GE_16( q_tmp, q_pPred_temp[k] ) ) { - FOR( p = start_band; p < k; p++ ) - { - div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); - move32(); - } - prev_tmp_shift = tmp_shift; - move16(); + abs_value = L_shr( abs_value, sub( q_tmp, q_pPred_temp[k] ) ); } - ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) + ELSE { - div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); - move32(); - tmp_shift = prev_tmp_shift; + pPred_temp[k] = W_shr( pPred_temp[k], sub( q_pPred_temp[k], q_tmp ) ); + move64(); + q_pPred_temp[k] = q_tmp; move16(); } - } - } - - FOR( i = 0; i < pred_dim; i++ ) - { - FOR( k = start_band; k < end_band; k++ ) - { - ppPred_coeffs_re[i][k] = Mpy_32_32( cov_real[add( i, 1 )][0][k], div_factor[k] ); // Q30 + temp_shift - 31 => tmp_shift - 1 - move32(); - - // IVAS_CALCULATE_SQ_ABS_N( ppPred_coeffs_re[i][k], abs_value ); - abs_value = Mpy_32_32( ppPred_coeffs_re[i][k], ppPred_coeffs_re[i][k] ); // Q = 2*tmp_shift - 2 - 31 - pPred_temp[k] = L_add( pPred_temp[k], abs_value ); // Q= 2*tmp_shift - 2 - 31 - move32(); + pPred_temp[k] = W_add( pPred_temp[k], abs_value ); // Q = q_pPred_temp[k] + move64(); } } - *q_pred_coeffs = sub( tmp_shift, 1 ); - move16(); FOR( k = start_band; k < end_band; k++ ) { - q_pred_temp = sub( 31, sub( shl( *q_pred_coeffs, 1 ), 31 ) ); - pPred_temp[k] = Sqrt32( pPred_temp[k], &q_pred_temp ); - move32(); + tmp_shift = W_norm( pPred_temp[k] ); + e_tmp = sub( 31, sub( add( q_pPred_temp[k], tmp_shift ), 32 ) ); + L_tmp = Sqrt32( W_extract_h( W_shl( pPred_temp[k], tmp_shift ) ), &e_tmp ); - IF( LT_16( q_pred_temp, 1 ) ) + one_in_q = L_shl_sat( 1, sub( 31, e_tmp ) ); + + IF( LT_32( one_in_q, L_tmp ) ) { - pPred_temp[k] = L_shr( pPred_temp[k], add( abs_s( q_pred_temp ), 1 ) ); // Q30 - move32(); - q_pred_temp = 1; + div_factor[k] = BASOP_Util_Divide3232_Scale( one_in_q, L_tmp, &s_div ); + move16(); + div_factor[k] = shl_sat( div_factor[k], s_div ); // Q = Q15 + move16(); + div_factor_e[k] = 0; move16(); } - ELSE IF( GT_16( q_pred_temp, 1 ) ) + ELSE { - pPred_temp[k] = L_shl( pPred_temp[k], sub( abs_s( q_pred_temp ), 1 ) ); // Q30 - move32(); - q_pred_temp = 1; + div_factor[k] = ONE_IN_Q15 - 1; + move16(); + div_factor_e[k] = 0; move16(); } + } - one_in_q = L_shl( 1, sub( 31, q_pred_temp ) ); - - IF( LT_32( one_in_q, pPred_temp[k] ) ) + tmp_shift = 31; + move16(); + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( k = start_band; k < end_band; k++ ) { - div_factor[k] = pPred_temp[k]; - move32(); - - div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( one_in_q, div_factor[k], &s_div ) ); - move32(); - IF( s_div < 0 ) + IF( NE_16( div_factor[k], ONE_IN_Q15 - 1 ) ) { - div_shift = add( 15, s_div ); - tmp_shift = Q30; - move16(); - } - ELSE - { - div_shift = 15; - move16(); - tmp_shift = sub( Q30, s_div ); + ppPred_coeffs_re[i][k] = Mpy_32_16_1( ppPred_coeffs_re[i][k], div_factor[k] ); // Q = q_ppPred_coeffs_re[i][k] + move32(); } - div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift - move32(); - } - ELSE - { - div_factor[k] = one_in_q; + ppDM_Fv_re[i][k] = 0; move32(); - tmp_shift = sub( 31, q_pred_temp ); - } - IF( LT_16( tmp_shift, prev_tmp_shift ) ) - { - FOR( p = start_band; p < k; p++ ) + IF( ppPred_coeffs_re[i][k] != 0 ) { - div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); - move32(); + tmp_shift = s_min( tmp_shift, add( norm_l( ppPred_coeffs_re[i][k] ), q_ppPred_coeffs_re[i][k] ) ); } - prev_tmp_shift = tmp_shift; - move16(); - } - ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) - { - div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); - move32(); - tmp_shift = prev_tmp_shift; - move16(); } } - FOR( i = 0; i < pred_dim; i++ ) { FOR( k = start_band; k < end_band; k++ ) { - ppPred_coeffs_re[i][k] = Mpy_32_32( ppPred_coeffs_re[i][k], div_factor[k] ); // Q = q_pred_coeffs + tmp_shift -31 - move32(); - ppDM_Fv_re[i][k] = 0; + ppPred_coeffs_re[i][k] = L_shr( ppPred_coeffs_re[i][k], sub( q_ppPred_coeffs_re[i][k], tmp_shift ) ); move32(); } } - *q_pred_coeffs = sub( add( *q_pred_coeffs, tmp_shift ), 31 ); - *q_dm_fv_re = 0; + *q_pred_coeffs = tmp_shift; + move16(); + *q_dm_fv_re = 31; move16(); } ELSE { + Word64 dm_alpha64[IVAS_MAX_NUM_BANDS]; + Word64 real64[IVAS_SPAR_MAX_CH - 1]; + Word64 re, dm_y; + Word16 dm_beta_re_q; + Word16 dm_alpha64_q[IVAS_MAX_NUM_BANDS]; + Word16 dm_v_re_q[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word32 dm_alpha[IVAS_MAX_NUM_BANDS], dm_v_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - Word32 real[IVAS_SPAR_MAX_CH - 1], dm_beta_re = 0, dm_g[IVAS_MAX_NUM_BANDS]; - Word32 dm_f_local, dm_w, dm_y, DM_F[IVAS_MAX_NUM_BANDS]; - Word32 num_f, den_f, passive_g /*, inv_den_f*/; + Word32 dm_g[IVAS_MAX_NUM_BANDS]; + Word16 real64_q[IVAS_SPAR_MAX_CH - 1]; + Word32 dm_f_local, dm_w, DM_F[IVAS_MAX_NUM_BANDS]; + Word16 DM_F_q[IVAS_MAX_NUM_BANDS], dm_g_q[IVAS_MAX_NUM_BANDS]; + Word32 num_f, den_f, passive_g, dm_beta_re /*, inv_den_f*/; Word32 activew_quad_thresh, g_th_sq; Word32 L_tmp1, L_tmp2; - Word16 L_tmp2_q; - Word16 dm_alpha_e, den_f_e, s_dm_f; - prev_tmp_shift = 31; - dm_alpha_e = 0; - Word16 dm_beta_re_e = 0; - move32(); - move16(); - move16(); - move16(); - + Word16 L_tmp1_q, L_tmp2_q; + Word16 den_f_e, s_dm_f; IF( EQ_16( dyn_active_w_flag, 1 ) ) { @@ -920,70 +930,89 @@ static void ivas_get_pred_coeffs_fx( g_th_sq = Mpy_32_32( activew_quad_thresh, activew_quad_thresh ); // Q27 set32_fx( dm_alpha, 0, IVAS_MAX_NUM_BANDS ); + set64_fx( dm_alpha64, 0, IVAS_MAX_NUM_BANDS ); + set16_fx( dm_alpha64_q, 31, IVAS_MAX_NUM_BANDS ); FOR( i = 1; i < in_chans; i++ ) { FOR( k = start_band; k < end_band; k++ ) { // IVAS_CALCULATE_SQ_ABS_N( cov_real[i][0][k], abs_value ); - abs_value = Mpy_32_32( cov_real[i][0][k], cov_real[i][0][k] ); // Q29 - dm_alpha[k] = L_add( dm_alpha[k], abs_value ); // Q29 - move32(); + abs_value64 = W_mult0_32_32( cov_real[i][0][k], cov_real[i][0][k] ); // Q = 2 * q_cov_real[i][0][k] + tmp_shift = W_norm( abs_value64 ); + IF( abs_value64 != 0 ) + { + q_tmp = sub( add( shl( q_cov_real[i][0][k], 1 ), tmp_shift ), 32 ); + } + ELSE + { + q_tmp = 31; + move16(); + } + IF( LT_16( q_tmp, dm_alpha64_q[k] ) ) + { + dm_alpha64[k] = W_add( W_shr( dm_alpha64[k], sub( dm_alpha64_q[k], q_tmp ) ), W_extract_h( W_shl( abs_value64, tmp_shift ) ) ); + move64(); + dm_alpha64_q[k] = q_tmp; + move16(); + } + ELSE + { + tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), dm_alpha64_q[k] ); + IF( LT_16( tmp_shift, 63 ) ) + { + dm_alpha64[k] = W_add( dm_alpha64[k], W_shr( abs_value64, tmp_shift ) ); + move64(); + } + } } } FOR( k = start_band; k < end_band; k++ ) { - dm_alpha_e = 31 - Q29; - dm_alpha[k] = Sqrt32( dm_alpha[k], &dm_alpha_e ); - move32(); - - div_factor[k] = L_max( dm_alpha[k], 1 ); - move32(); - - div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); - move32(); - IF( s_div < 0 ) + tmp_shift = W_norm( dm_alpha64[k] ); + IF( dm_alpha64[k] != 0 ) { - div_shift = add( 15, sub( s_div, dm_alpha_e ) ); - tmp_shift = Q30; - move16(); + e_tmp = sub( 31, sub( add( dm_alpha64_q[k], tmp_shift ), 32 ) ); } ELSE { - div_shift = 15; + e_tmp = 0; move16(); - tmp_shift = sub( Q30, sub( s_div, dm_alpha_e ) ); } - div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift + dm_alpha[k] = Sqrt32( W_extract_h( W_shl( dm_alpha64[k], tmp_shift ) ), &e_tmp ); move32(); + dm_alpha64_q[k] = sub( 31, e_tmp ); + move16(); - IF( LT_16( tmp_shift, prev_tmp_shift ) ) - { - FOR( p = start_band; p < k; p++ ) - { - div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); - move32(); - } - prev_tmp_shift = tmp_shift; - move16(); - } - ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) - { - div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); - move32(); - tmp_shift = prev_tmp_shift; - move16(); - } + div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_max( dm_alpha[k], 1 ), &s_div ); + move16(); + + div_factor_e[k] = sub( add( dm_alpha64_q[k], s_div ), 31 ); + move16(); } FOR( i = 0; i < pred_dim; i++ ) { FOR( k = start_band; k < end_band; k++ ) { - dm_v_re[i][k] = Mpy_32_32( cov_real[i + 1][0][k], div_factor[k] ); // Q30 + Qb - 31 = tmp_shift - 1 - move32(); - } + tmp64 = W_mult_32_16( cov_real[add( i, 1 )][0][k], div_factor[k] ); + tmp_shift = W_norm( tmp64 ); + IF( tmp64 != 0 ) + { + dm_v_re[i][k] = W_extract_h( W_shl( tmp64, tmp_shift ) ); // 1 + q_cov_real[i+1][0][k] + tmp_shift + 15 - div_factor_e[k] - 32 + move32(); + dm_v_re_q[i][k] = add( sub( add( q_cov_real[add( i, 1 )][0][k], tmp_shift ), div_factor_e[k] ), 1 + 15 - 32 ); + move16(); + } + ELSE + { + dm_v_re[i][k] = 0; + move32(); + dm_v_re_q[i][k] = 31; + move16(); + } + } } IF( dtx_vad == 0 ) @@ -1007,60 +1036,121 @@ static void ivas_get_pred_coeffs_fx( FOR( b = start_band; b < end_band; b++ ) { - set32_fx( real, 0, pred_dim ); + set64_fx( real64, 0, pred_dim ); + set16_fx( real64_q, 31, pred_dim ); FOR( j = 0; j < pred_dim; j++ ) { FOR( k = 1; k < in_chans; k++ ) { - Word32 re; - // IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); - re = Mpy_32_32( cov_real[add( j, 1 )][k][b], dm_v_re[sub( k, 1 )][b] ); // Q30 + Q_div_factor - 1 - 31 - real[j] = L_add( real[j], re ); // tmp_shift - 2 - move32(); + re = W_mult0_32_32( cov_real[add( j, 1 )][k][b], dm_v_re[sub( k, 1 )][b] ); + tmp_shift = W_norm( re ); + IF( re != 0 ) + { + q_tmp = sub( add( add( q_cov_real[add( j, 1 )][k][b], dm_v_re_q[sub( k, 1 )][b] ), tmp_shift ), 32 ); + } + ELSE + { + q_tmp = 31; + move16(); + } + + IF( LT_16( q_tmp, real64_q[j] ) ) + { + real64[j] = W_add( W_shr( real64[j], sub( real64_q[j], q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); + move64(); + real64_q[j] = q_tmp; + move16(); + } + ELSE + { + tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), real64_q[j] ); + IF( LT_16( tmp_shift, 63 ) ) + { + real64[j] = W_add( real64[j], W_shr( re, tmp_shift ) ); + move64(); + } + } } } - dm_beta_re = 0; - move32(); + + tmp64 = 0; + move64(); + dm_beta_re_q = 31; + move16(); FOR( k = 0; k < pred_dim; k++ ) { - Word32 re; // IVAS_RMULT_FLOAT( real[k], dm_v_re[k][b], re ); - re = Mpy_32_32( real[k], dm_v_re[k][b] ); // Q = 2*tmp_shift - 3 - 31 - dm_beta_re = L_add( dm_beta_re, re ); // Q = 2*tmp_shift - 3 - 31 + tmp_shift = W_norm( real64[k] ); + re = W_mult0_32_32( W_extract_h( W_shl( real64[k], tmp_shift ) ), dm_v_re[k][b] ); + q_tmp = sub( add( add( real64_q[k], dm_v_re_q[k][b] ), tmp_shift ), 32 ); + tmp_shift = W_norm( re ); + IF( re != 0 ) + { + q_tmp = sub( add( q_tmp, tmp_shift ), 32 ); + } + ELSE + { + q_tmp = 31; + move16(); + } + + IF( LT_16( q_tmp, dm_beta_re_q ) ) + { + tmp64 = W_add( W_shr( tmp64, sub( dm_beta_re_q, q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); + dm_beta_re_q = q_tmp; + move16(); + } + ELSE + { + tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), dm_beta_re_q ); + IF( LT_16( tmp_shift, 63 ) ) + { + tmp64 = W_add( tmp64, W_shr( re, tmp_shift ) ); + } + } + } + tmp_shift = W_norm( tmp64 ); + dm_beta_re = W_extract_h( W_shl( tmp64, tmp_shift ) ); + IF( tmp64 != 0 ) + { + dm_beta_re_q = sub( add( dm_beta_re_q, tmp_shift ), 32 ); + } + ELSE + { + dm_beta_re_q = 31; + move16(); } - dm_beta_re_e = sub( 31, ( sub( sub( shl( tmp_shift, 1 ), 3 ), 31 ) ) ); - dm_w = cov_real[0][0][b]; // Q30 + dm_w = cov_real[0][0][b]; // q_cov_real[0][0][b] move32(); den_f = L_max( dm_w, 1 ); - passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); + passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); // dm_alpha64_q[b] - q_cov_real[0][0][b] + 15 - s_div - div_shift = add( ( sub( 15, ( sub( ( sub( 31, dm_alpha_e ) ), Q30 ) ) ) ), sub( s_div, 1 ) ); - passive_g = L_shl( passive_g, div_shift ); // Q = 29 + div_shift = sub( Q29, add( sub( dm_alpha64_q[b], q_cov_real[0][0][b] ), sub( 15, s_div ) ) ); + passive_g = L_shl_sat( passive_g, div_shift ); // Q = 29 IF( EQ_16( dyn_active_w_flag, 1 ) ) { dm_alpha[b] = 0; move32(); + dm_alpha64_q[b] = 0; + move16(); dm_w = 0; move32(); FOR( i = 0; i < pred_dim; i++ ) { dm_v_re[i][b] = 0; move32(); + dm_v_re_q[i][b] = 31; + move16(); } - IF( NE_16( sub( tmp_shift, 1 ), 31 ) ) - { - dm_v_re[sub( res_ind, 1 )][b] = L_shl( 1, sub( tmp_shift, 1 ) ); - move32(); - } - ELSE - { - dm_v_re[sub( res_ind, 1 )][b] = MAX_32; - move32(); - } + dm_v_re[sub( res_ind, 1 )][b] = MAX_32; + move32(); + dm_v_re_q[i][b] = 31; + move16(); + passive_g = activew_quad_thresh; move32(); } @@ -1070,46 +1160,168 @@ static void ivas_get_pred_coeffs_fx( /*linear activeW*/ dm_y = 0; move32(); + q_tmp = 31; + move16(); FOR( k = 1; k < in_chans; k++ ) { - dm_y = L_add( dm_y, L_shr( cov_real[k][k][b], 2 ) ); // Q28 + IF( GT_16( q_tmp, q_cov_real[k][k][b] ) ) + { + dm_y = W_add( W_shr( dm_y, sub( q_tmp, q_cov_real[k][k][b] ) ), cov_real[k][k][b] ); + q_tmp = q_cov_real[k][k][b]; + move16(); + } + ELSE + { + dm_y = W_add( dm_y, L_shr( cov_real[k][k][b], sub( q_cov_real[k][k][b], q_tmp ) ) ); + } + } + tmp64 = W_mult0_32_32( w_norm_fac, dm_w ); + IF( LT_16( q_tmp, q_cov_real[0][0][b] ) ) + { + tmp64 = W_shr( tmp64, sub( q_cov_real[0][0][b], q_tmp ) ); + } + ELSE + { + q_tmp = q_cov_real[0][0][b]; + move16(); + dm_y = W_shr( dm_y, sub( q_tmp, q_cov_real[0][0][b] ) ); } - den_f = L_max( dm_y, 1 ); // Q28 - den_f = L_max( den_f, Mpy_32_32( w_norm_fac, dm_w ) ); // Q28 - DM_F[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( Mpy_32_32( dm_f_local, dm_alpha[b] ), den_f, &s_div ) ); // Q30 + 31 - dm_alpha_e - 31 + den_f_e - 31 => den_f_e - dm_alpha_e - 1 - move32(); + if ( GT_64( tmp64, dm_y ) ) + { + dm_y = tmp64; + move16(); + } - div_shift = add( ( sub( 15, ( sub( ( sub( 30, dm_alpha_e ) ), 28 ) ) ) ), s_div ); + tmp_shift = W_norm( dm_y ); + IF( dm_y == 0 ) + { + tmp_shift = 32; + move16(); + den_f = W_extract_l( dm_y ); + } + ELSE + { + den_f = W_extract_h( W_shl( dm_y, tmp_shift ) ); // q_tmp + tmp_shift - 32 + } - DM_F[b] = L_shl( DM_F[b], div_shift ); // Q30 - move32(); + den_f = L_max( den_f, 1 ); - DM_F[b] = L_min( ONE_IN_Q30, DM_F[b] ); + DM_F[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( Mpy_32_32( dm_f_local, dm_alpha[b] ), den_f, &s_div ) ); // Q30 + dm_alpha64_q[b] - 31 - q_tmp - tmp_shift + 32 + 15 - s_div move32(); - L_tmp1 = L_add( L_shr( dm_w, 1 ), Mpy_32_32( dm_alpha[b], DM_F[b] ) ); /* Q 29*/ - L_tmp2 = Mpy_32_32( Mpy_32_32( DM_F[b], DM_F[b] ), dm_beta_re ); - L_tmp2_q = add( 29, sub( shl( tmp_shift, 1 ), 65 ) ); // simplified equation for calculating Q of L_tmp2 - L_tmp2 = L_shl( L_tmp2, sub( 29, L_tmp2_q ) ); + DM_F_q[b] = add( sub( sub( dm_alpha64_q[b], add( q_tmp, tmp_shift ) ), s_div ), ( 30 - 31 + 32 + 15 ) ); + move16(); + + IF( LT_32( ONE_IN_Q30, L_shl_sat( DM_F[b], sub( Q30, DM_F_q[b] ) ) ) ) + { + DM_F[b] = ONE_IN_Q31; + move32(); + DM_F_q[b] = Q31; + move16(); + } + + tmp64 = W_mult0_32_32( DM_F[b], DM_F[b] ); + tmp_shift = W_norm( tmp64 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + tmp64 = W_mult0_32_32( W_extract_h( tmp64 ), dm_beta_re ); // 2 * DM_F_q[b] + tmp_shift - 32 + dm_beta_re_q + q_tmp = sub( add( add( shl( DM_F_q[b], 1 ), tmp_shift ), dm_beta_re_q ), 32 ); + tmp_shift = sub( W_norm( tmp64 ), 2 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + L_tmp2 = W_extract_h( tmp64 ); + L_tmp2_q = sub( add( q_tmp, tmp_shift ), 32 ); + + tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], DM_F[b] ), 1 ); + tmp_shift = sub( W_norm( tmp64 ), 2 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + L_tmp1 = W_extract_h( tmp64 ); // DM_F_q[b] + dm_alpha64_q[b] + tmp_shift - 32 + L_tmp1_q = sub( add( add( DM_F_q[b], dm_alpha64_q[b] ), tmp_shift ), 32 ); + + IF( LT_16( L_tmp2_q, L_tmp1_q ) ) + { + L_tmp1 = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); + L_tmp1_q = L_tmp2_q; + move16(); + } + ELSE + { + L_tmp1 = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + } + + tmp_shift = sub( norm_l( dm_w ), 1 ); + L_tmp2 = L_shl( dm_w, tmp_shift ); + L_tmp2_q = add( q_cov_real[0][0][b], tmp_shift ); + + IF( LT_16( L_tmp2_q, L_tmp1_q ) ) + { + den_f = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); + den_f_e = sub( 31, L_tmp2_q ); + } + ELSE + { + den_f = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + den_f_e = sub( 31, L_tmp1_q ); + } - den_f = L_add( L_tmp1, L_tmp2 ); // Q29 den_f = L_max( den_f, 1 ); - den_f_e = 31 - 29; - move16(); - L_tmp2 = Mpy_32_32( DM_F[b], dm_beta_re ); - L_tmp2_q = add( 30, sub( ( sub( shl( tmp_shift, 1 ), 34 ) ), 31 ) ); - L_tmp2 = L_shl( L_tmp2, ( sub( ( sub( 29, dm_alpha_e ) ), L_tmp2_q ) ) ); - L_tmp1 = L_shr( dm_alpha[b], ( sub( ( sub( 31, dm_alpha_e ) ), 29 ) ) ); - L_tmp1 = L_add( L_tmp1, L_tmp2 ); // Q29 + tmp64 = W_mult0_32_32( DM_F[b], dm_beta_re ); + tmp_shift = sub( W_norm( tmp64 ), 1 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + L_tmp2_q = sub( add( add( DM_F_q[b], dm_beta_re_q ), tmp_shift ), 32 ); + L_tmp2 = W_extract_h( tmp64 ); - dm_g[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( L_tmp1, den_f, &s_div ) ); // Q29 + den_f_e - 31 + 15 - s_div - move32(); - div_shift = add( sub( 15, ( sub( 29, sub( 31, den_f_e ) ) ) ), s_div ); - dm_g[b] = L_shl( dm_g[b], div_shift ); // Q30 + tmp_shift = sub( norm_l( dm_alpha[b] ), 1 ); + + IF( LT_16( L_tmp2_q, add( dm_alpha64_q[b], tmp_shift ) ) ) + { + L_tmp1 = L_add( L_shr( dm_alpha[b], sub( dm_alpha64_q[b], L_tmp2_q ) ), L_tmp2 ); + L_tmp1_q = L_tmp2_q; + move16(); + } + ELSE + { + L_tmp1_q = add( dm_alpha64_q[b], tmp_shift ); + L_tmp1 = L_add( L_shl( dm_alpha[b], tmp_shift ), L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + } + + dm_g[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( L_tmp1, den_f, &s_div ) ); // L_tmp1_q - (31 - den_f_e) + (15 - s_div) move32(); + dm_g_q[b] = add( sub( add( L_tmp1_q, den_f_e ), s_div ), 15 - 31 ); + move16(); } ELSE { @@ -1118,67 +1330,590 @@ static void ivas_get_pred_coeffs_fx( Word16 num_f_e; /* quadratic activeW */ + tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], activew_quad_thresh ), 1 ); + tmp_shift = sub( W_norm( tmp64 ), 1 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + L_tmp1 = W_extract_h( tmp64 ); // Q29 + dm_alpha64_q[b] + tmp_shift - 32 + L_tmp1_q = sub( add( add( Q29, dm_alpha64_q[b] ), tmp_shift ), 32 ); - num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, dm_beta_re_e, L_negate( L_shl( Mpy_32_32( dm_alpha[b], activew_quad_thresh ), 1 ) ), add( dm_alpha_e, ( 31 - Q29 ) ), &num_f_e ); + num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, sub( 31, dm_beta_re_q ), L_negate( L_tmp1 ), sub( 31, L_tmp1_q ), &num_f_e ); - sqrt_val = L_shl( Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ), 2 ); /*Q27*/ - val_e = 4; + sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); + val_e = sub( 31, sub( sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ), 2 ) ); // reducing the Q by 2 instead of multiplication by 4 move16(); - - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, 4, Mpy_32_32( dm_beta_re, dm_beta_re ), 2 * dm_beta_re_e, &val_e ); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( L_shl( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ), 2 ) ), add( dm_beta_re_e, 4 + 1 ), &val_e ); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, sub( shl( dm_beta_re_q, 1 ), 31 ) ), &val_e ); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ) ), sub( 31, sub( sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ), 2 ) ), &val_e ); // reducing the Q by 2 instead of multiplication by 4 // val_e = norm_l( sqrt_val ); sqrt_val = Sqrt32( sqrt_val, &val_e ); - IF( val_e < 0 ) - { - sqrt_val = L_shr( sqrt_val, abs_s( val_e ) ); - } - ELSE IF( val_e > 0 ) - { - sqrt_val = L_shl( sqrt_val, abs_s( val_e ) ); - val_e = 0; - move16(); - } - num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, 0, &num_f_e ); - den_f = L_shl( Mpy_32_32( dm_beta_re, g_th_sq ), 1 ); - den_f_e = add( dm_beta_re_e, 4 ); + num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, val_e, &num_f_e ); + + den_f = Mpy_32_32( dm_beta_re, g_th_sq ); + den_f_e = add( add( sub( 31, dm_beta_re_q ), 4 ), 1 ); // adding the exp with 1 instead of multiplication by 2 den_f = L_max( den_f, 1 ); dm_g[b] = activew_quad_thresh; // Q29 move32(); + dm_g_q[b] = Q29; + move16(); DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); move32(); - s_dm_f = add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ); /*Resultant exp for DM_F s_dm_f +( 2 + num_f_e ) - den_f_e*/ - div_shift = sub( s_dm_f, 1 ); - DM_F[b] = L_shl( DM_F[b], div_shift ); // Q30 - move32(); + DM_F_q[b] = sub( 31, add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ) ); + move16(); } } + *q_pred_coeffs = 31; + move16(); + *q_dm_fv_re = 31; + move16(); + FOR( i = 0; i < pred_dim; i++ ) { FOR( b = start_band; b < end_band; b++ ) { - ppPred_coeffs_re[i][b] = Mpy_32_32( dm_v_re[i][b], dm_g[b] ); // Q = tmp_shift - 1 + 30 - 31 + tmp64 = W_mult0_32_32( dm_v_re[i][b], dm_g[b] ); + tmp_shift = W_norm( tmp64 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + ppPred_coeffs_re[i][b] = W_extract_h( tmp64 ); // Q = dm_v_re_q[i][b] + dm_g_q[b] + tmp_shift - 32 move32(); - ppDM_Fv_re[i][b] = Mpy_32_32( dm_v_re[i][b], DM_F[b] ); + q_ppPred_coeffs_re[i][b] = sub( add( add( dm_v_re_q[i][b], dm_g_q[b] ), tmp_shift ), 32 ); + move16(); + + tmp64 = W_mult0_32_32( dm_v_re[i][b], DM_F[b] ); + tmp_shift = W_norm( tmp64 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + ppDM_Fv_re[i][b] = W_extract_h( tmp64 ); // Q = dm_v_re_q[i][b] + DM_F_q[b] + tmp_shift - 32 + move32(); + dm_v_re_q[i][b] = sub( add( add( dm_v_re_q[i][b], DM_F_q[b] ), tmp_shift ), 32 ); + move16(); + + *q_pred_coeffs = s_min( *q_pred_coeffs, q_ppPred_coeffs_re[i][b] ); + move16(); + *q_dm_fv_re = s_min( *q_dm_fv_re, dm_v_re_q[i][b] ); + move16(); + } + } + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( b = start_band; b < end_band; b++ ) + { + ppPred_coeffs_re[i][b] = L_shr( ppPred_coeffs_re[i][b], sub( q_ppPred_coeffs_re[i][b], *q_pred_coeffs ) ); + move32(); + ppDM_Fv_re[i][b] = L_shr( ppDM_Fv_re[i][b], sub( dm_v_re_q[i][b], *q_dm_fv_re ) ); move32(); } } - *q_pred_coeffs = sub( tmp_shift, 2 ); - move16(); - *q_dm_fv_re = sub( tmp_shift, 2 ); - move16(); } return; } -#endif // IVAS_FLOAT_FIXED - -/*-----------------------------------------------------------------------------------------* - * Function ivas_get_Wscaling_factor() - * +static void ivas_get_pred_coeffs_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + const Word16 in_chans, + const Word16 start_band, + const Word16 end_band, + const Word16 active_w, + const Word16 active_w_vlbr, + const Word16 dtx_vad, + const Word16 from_dirac, + const Word16 dyn_active_w_flag, + const Word16 res_ind, + Word16 *q_pred_coeffs, + Word16 *q_dm_fv_re ) +{ + Word16 i, j, k, b, p; + Word32 abs_value; + Word32 w_norm_fac; + Word32 one_in_q; + Word32 div_factor[IVAS_MAX_NUM_BANDS]; + Word16 pred_dim = sub( in_chans, 1 ); + Word16 tmp_shift, prev_tmp_shift, s_div, div_shift; + + IF( EQ_16( from_dirac, 1 ) ) + { + w_norm_fac = ONE_IN_Q29; + move32(); + } + ELSE + { + w_norm_fac = 3 * ONE_IN_Q29; + move32(); + } + tmp_shift = Q30; + move16(); + IF( active_w == 0 ) + { + Word32 pPred_temp[IVAS_MAX_NUM_BANDS]; + Word16 q_pred_temp; + prev_tmp_shift = 31; + move16(); + + set32_fx( pPred_temp, 0, IVAS_MAX_NUM_BANDS ); + FOR( k = start_band; k < end_band; k++ ) + { + div_factor[k] = L_max( 1, cov_real[0][0][k] ); + move32(); + tmp_shift = Q30; + move16(); + IF( NE_32( cov_real[0][0][k], ONE_IN_Q30 ) ) + { + div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); + move32(); + IF( s_div < 0 ) + { + div_shift = add( 15, s_div ); + tmp_shift = Q30; + move16(); + } + ELSE + { + div_shift = 15; + move16(); + tmp_shift = sub( Q30, s_div ); + } + div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift + move16(); + + IF( LT_16( tmp_shift, prev_tmp_shift ) ) + { + FOR( p = start_band; p < k; p++ ) + { + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + move32(); + } + prev_tmp_shift = tmp_shift; + move16(); + } + ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) + { + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + move32(); + tmp_shift = prev_tmp_shift; + move16(); + } + } + } + + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( k = start_band; k < end_band; k++ ) + { + ppPred_coeffs_re[i][k] = Mpy_32_32( cov_real[add( i, 1 )][0][k], div_factor[k] ); // Q30 + temp_shift - 31 => tmp_shift - 1 + move32(); + + // IVAS_CALCULATE_SQ_ABS_N( ppPred_coeffs_re[i][k], abs_value ); + abs_value = Mpy_32_32( ppPred_coeffs_re[i][k], ppPred_coeffs_re[i][k] ); // Q = 2*tmp_shift - 2 - 31 + + pPred_temp[k] = L_add( pPred_temp[k], abs_value ); // Q= 2*tmp_shift - 2 - 31 + move32(); + } + } + *q_pred_coeffs = sub( tmp_shift, 1 ); + move16(); + + FOR( k = start_band; k < end_band; k++ ) + { + q_pred_temp = sub( 31, sub( shl( *q_pred_coeffs, 1 ), 31 ) ); + pPred_temp[k] = Sqrt32( pPred_temp[k], &q_pred_temp ); + move32(); + + IF( LT_16( q_pred_temp, 1 ) ) + { + pPred_temp[k] = L_shr( pPred_temp[k], add( abs_s( q_pred_temp ), 1 ) ); // Q30 + move32(); + q_pred_temp = 1; + move16(); + } + ELSE IF( GT_16( q_pred_temp, 1 ) ) + { + pPred_temp[k] = L_shl( pPred_temp[k], sub( abs_s( q_pred_temp ), 1 ) ); // Q30 + move32(); + q_pred_temp = 1; + move16(); + } + + one_in_q = L_shl( 1, sub( 31, q_pred_temp ) ); + + IF( LT_32( one_in_q, pPred_temp[k] ) ) + { + div_factor[k] = pPred_temp[k]; + move32(); + + div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( one_in_q, div_factor[k], &s_div ) ); + move32(); + IF( s_div < 0 ) + { + div_shift = add( 15, s_div ); + tmp_shift = Q30; + move16(); + } + ELSE + { + div_shift = 15; + move16(); + tmp_shift = sub( Q30, s_div ); + } + div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift + move32(); + } + ELSE + { + div_factor[k] = one_in_q; + move32(); + tmp_shift = sub( 31, q_pred_temp ); + } + + IF( LT_16( tmp_shift, prev_tmp_shift ) ) + { + FOR( p = start_band; p < k; p++ ) + { + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + move32(); + } + prev_tmp_shift = tmp_shift; + move16(); + } + ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) + { + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + move32(); + tmp_shift = prev_tmp_shift; + move16(); + } + } + + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( k = start_band; k < end_band; k++ ) + { + ppPred_coeffs_re[i][k] = Mpy_32_32( ppPred_coeffs_re[i][k], div_factor[k] ); // Q = q_pred_coeffs + tmp_shift -31 + move32(); + ppDM_Fv_re[i][k] = 0; + move32(); + } + } + *q_pred_coeffs = sub( add( *q_pred_coeffs, tmp_shift ), 31 ); + *q_dm_fv_re = 0; + move16(); + } + ELSE + { + Word32 dm_alpha[IVAS_MAX_NUM_BANDS], dm_v_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + Word32 real[IVAS_SPAR_MAX_CH - 1], dm_beta_re = 0, dm_g[IVAS_MAX_NUM_BANDS]; + Word32 dm_f_local, dm_w, dm_y, DM_F[IVAS_MAX_NUM_BANDS]; + Word32 num_f, den_f, passive_g /*, inv_den_f*/; + Word32 activew_quad_thresh, g_th_sq; + Word32 L_tmp1, L_tmp2; + Word16 L_tmp2_q; + Word16 dm_alpha_e, den_f_e, s_dm_f; + prev_tmp_shift = 31; + dm_alpha_e = 0; + Word16 dm_beta_re_e = 0; + move32(); + move16(); + move16(); + move16(); + + + IF( EQ_16( dyn_active_w_flag, 1 ) ) + { + activew_quad_thresh = ONE_IN_Q29; + move32(); + } + ELSE + { + activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29; + move32(); + } + g_th_sq = Mpy_32_32( activew_quad_thresh, activew_quad_thresh ); // Q27 + + set32_fx( dm_alpha, 0, IVAS_MAX_NUM_BANDS ); + + FOR( i = 1; i < in_chans; i++ ) + { + FOR( k = start_band; k < end_band; k++ ) + { + // IVAS_CALCULATE_SQ_ABS_N( cov_real[i][0][k], abs_value ); + abs_value = Mpy_32_32( cov_real[i][0][k], cov_real[i][0][k] ); // Q29 + dm_alpha[k] = L_add( dm_alpha[k], abs_value ); // Q29 + move32(); + } + } + + FOR( k = start_band; k < end_band; k++ ) + { + dm_alpha_e = 31 - Q29; + dm_alpha[k] = Sqrt32( dm_alpha[k], &dm_alpha_e ); + move32(); + + div_factor[k] = L_max( dm_alpha[k], 1 ); + move32(); + + div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); + move32(); + IF( s_div < 0 ) + { + div_shift = add( 15, sub( s_div, dm_alpha_e ) ); + tmp_shift = Q30; + move16(); + } + ELSE + { + div_shift = 15; + move16(); + tmp_shift = sub( Q30, sub( s_div, dm_alpha_e ) ); + } + div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift + move32(); + + IF( LT_16( tmp_shift, prev_tmp_shift ) ) + { + FOR( p = start_band; p < k; p++ ) + { + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + move32(); + } + prev_tmp_shift = tmp_shift; + move16(); + } + ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) + { + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + move32(); + tmp_shift = prev_tmp_shift; + move16(); + } + } + + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( k = start_band; k < end_band; k++ ) + { + dm_v_re[i][k] = Mpy_32_32( cov_real[i + 1][0][k], div_factor[k] ); // Q30 + Qb - 31 = tmp_shift - 1 + move32(); + } + } + + IF( dtx_vad == 0 ) + { + dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; + move32(); + } + ELSE + { + IF( active_w_vlbr ) + { + dm_f_local = IVAS_ACTIVEW_DM_F_VLBR_Q30; + move32(); + } + ELSE + { + dm_f_local = IVAS_ACTIVEW_DM_F_Q30; + move32(); + } + } + + FOR( b = start_band; b < end_band; b++ ) + { + set32_fx( real, 0, pred_dim ); + + FOR( j = 0; j < pred_dim; j++ ) + { + FOR( k = 1; k < in_chans; k++ ) + { + Word32 re; + + // IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); + re = Mpy_32_32( cov_real[add( j, 1 )][k][b], dm_v_re[sub( k, 1 )][b] ); // Q30 + Q_div_factor - 1 - 31 + real[j] = L_add( real[j], re ); // tmp_shift - 2 + move32(); + } + } + dm_beta_re = 0; + move32(); + FOR( k = 0; k < pred_dim; k++ ) + { + Word32 re; + // IVAS_RMULT_FLOAT( real[k], dm_v_re[k][b], re ); + re = Mpy_32_32( real[k], dm_v_re[k][b] ); // Q = 2*tmp_shift - 3 - 31 + dm_beta_re = L_add( dm_beta_re, re ); // Q = 2*tmp_shift - 3 - 31 + } + + dm_beta_re_e = sub( 31, ( sub( sub( shl( tmp_shift, 1 ), 3 ), 31 ) ) ); + dm_w = cov_real[0][0][b]; // Q30 + move32(); + den_f = L_max( dm_w, 1 ); + passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); + + div_shift = add( ( sub( 15, ( sub( ( sub( 31, dm_alpha_e ) ), Q30 ) ) ) ), sub( s_div, 1 ) ); + passive_g = L_shl( passive_g, div_shift ); // Q = 29 + + IF( EQ_16( dyn_active_w_flag, 1 ) ) + { + dm_alpha[b] = 0; + move32(); + dm_w = 0; + move32(); + FOR( i = 0; i < pred_dim; i++ ) + { + dm_v_re[i][b] = 0; + move32(); + } + IF( NE_16( sub( tmp_shift, 1 ), 31 ) ) + { + dm_v_re[sub( res_ind, 1 )][b] = L_shl( 1, sub( tmp_shift, 1 ) ); + move32(); + } + ELSE + { + dm_v_re[sub( res_ind, 1 )][b] = MAX_32; + move32(); + } + passive_g = activew_quad_thresh; + move32(); + } + + IF( LT_32( passive_g, activew_quad_thresh ) ) + { + /*linear activeW*/ + dm_y = 0; + move32(); + + FOR( k = 1; k < in_chans; k++ ) + { + dm_y = L_add( dm_y, L_shr( cov_real[k][k][b], 2 ) ); // Q28 + } + den_f = L_max( dm_y, 1 ); // Q28 + den_f = L_max( den_f, Mpy_32_32( w_norm_fac, dm_w ) ); // Q28 + + DM_F[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( Mpy_32_32( dm_f_local, dm_alpha[b] ), den_f, &s_div ) ); // Q30 + 31 - dm_alpha_e - 31 + den_f_e - 31 => den_f_e - dm_alpha_e - 1 + move32(); + + div_shift = add( ( sub( 15, ( sub( ( sub( 30, dm_alpha_e ) ), 28 ) ) ) ), s_div ); + + DM_F[b] = L_shl( DM_F[b], div_shift ); // Q30 + move32(); + + DM_F[b] = L_min( ONE_IN_Q30, DM_F[b] ); + move32(); + + L_tmp1 = L_add( L_shr( dm_w, 1 ), Mpy_32_32( dm_alpha[b], DM_F[b] ) ); /* Q 29*/ + L_tmp2 = Mpy_32_32( Mpy_32_32( DM_F[b], DM_F[b] ), dm_beta_re ); + L_tmp2_q = add( 29, sub( shl( tmp_shift, 1 ), 65 ) ); // simplified equation for calculating Q of L_tmp2 + L_tmp2 = L_shl( L_tmp2, sub( 29, L_tmp2_q ) ); + + den_f = L_add( L_tmp1, L_tmp2 ); // Q29 + den_f = L_max( den_f, 1 ); + + den_f_e = 31 - 29; + move16(); + L_tmp2 = Mpy_32_32( DM_F[b], dm_beta_re ); + L_tmp2_q = add( 30, sub( ( sub( shl( tmp_shift, 1 ), 34 ) ), 31 ) ); + L_tmp2 = L_shl( L_tmp2, ( sub( ( sub( 29, dm_alpha_e ) ), L_tmp2_q ) ) ); + L_tmp1 = L_shr( dm_alpha[b], ( sub( ( sub( 31, dm_alpha_e ) ), 29 ) ) ); + L_tmp1 = L_add( L_tmp1, L_tmp2 ); // Q29 + + dm_g[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( L_tmp1, den_f, &s_div ) ); // Q29 + den_f_e - 31 + 15 - s_div + move32(); + div_shift = add( sub( 15, ( sub( 29, sub( 31, den_f_e ) ) ) ), s_div ); + dm_g[b] = L_shl( dm_g[b], div_shift ); // Q30 + move32(); + } + ELSE + { + Word32 sqrt_val; + Word16 val_e; + Word16 num_f_e; + + /* quadratic activeW */ + + num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, dm_beta_re_e, L_negate( L_shl( Mpy_32_32( dm_alpha[b], activew_quad_thresh ), 1 ) ), add( dm_alpha_e, ( 31 - Q29 ) ), &num_f_e ); + + sqrt_val = L_shl( Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ), 2 ); /*Q27*/ + val_e = 4; + move16(); + + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, 4, Mpy_32_32( dm_beta_re, dm_beta_re ), 2 * dm_beta_re_e, &val_e ); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( L_shl( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ), 2 ) ), add( dm_beta_re_e, 4 + 1 ), &val_e ); + // val_e = norm_l( sqrt_val ); + sqrt_val = Sqrt32( sqrt_val, &val_e ); + IF( val_e < 0 ) + { + sqrt_val = L_shr( sqrt_val, abs_s( val_e ) ); + } + ELSE IF( val_e > 0 ) + { + sqrt_val = L_shl( sqrt_val, abs_s( val_e ) ); + val_e = 0; + move16(); + } + num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, 0, &num_f_e ); + + den_f = L_shl( Mpy_32_32( dm_beta_re, g_th_sq ), 1 ); + den_f_e = add( dm_beta_re_e, 4 ); + den_f = L_max( den_f, 1 ); + dm_g[b] = activew_quad_thresh; // Q29 + move32(); + DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); + move32(); + s_dm_f = add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ); /*Resultant exp for DM_F s_dm_f +( 2 + num_f_e ) - den_f_e*/ + div_shift = sub( s_dm_f, 1 ); + DM_F[b] = L_shl( DM_F[b], div_shift ); // Q30 + move32(); + } + } + + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( b = start_band; b < end_band; b++ ) + { + ppPred_coeffs_re[i][b] = Mpy_32_32( dm_v_re[i][b], dm_g[b] ); // Q = tmp_shift - 1 + 30 - 31 + move32(); + ppDM_Fv_re[i][b] = Mpy_32_32( dm_v_re[i][b], DM_F[b] ); + move32(); + } + } + *q_pred_coeffs = sub( tmp_shift, 2 ); + move16(); + *q_dm_fv_re = sub( tmp_shift, 2 ); + move16(); + } + + return; +} +#endif // IVAS_FLOAT_FIXED + + +/*-----------------------------------------------------------------------------------------* + * Function ivas_get_Wscaling_factor() + * * Calculation of scaling factor for post predicted W channel *-----------------------------------------------------------------------------------------*/ @@ -1249,6 +1984,118 @@ static void ivas_get_Wscaling_factor( #ifdef IVAS_FLOAT_FIXED +static void ivas_get_Wscaling_factor_enc_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 q_pred_coeffs_re, + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 start_band, + const Word16 end_band, + const Word16 dtx_vad, + const Word16 num_ch, + const Word16 *pNum_dmx, + const Word16 bands_bw, + const Word16 active_w, + const Word16 active_w_vlbr, + Word32 *pWscale, + Word16 *q_pWscale, + const Word16 dyn_active_w_flag ) +{ + Word16 b, ch, q_tmp, q_postpred_cov_re; + Word32 dm_f_local, abs_val; + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + + q_postpred_cov_re = 0; + move16(); + + FOR( ch = 0; ch < IVAS_SPAR_MAX_CH; ch++ ) + { + set32_fx( postpred_cov_re[ch], 0, IVAS_SPAR_MAX_CH ); + } + + IF( dtx_vad == 0 ) + { + dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; // Q31 + move32(); + } + ELSE IF( active_w_vlbr != 0 ) + { + dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX; // Q31 + move32(); + } + ELSE + { + dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_FX; // Q31 + move32(); + } + + FOR( b = start_band; b < end_band; b++ ) + { + pWscale[b] = 1; + move32(); + q_pWscale[b] = 0; + move16(); + + test(); + IF( EQ_16( active_w, 1 ) && ( dyn_active_w_flag == 0 ) ) + { + Word16 guard_bits, q_Gw_sq, q_g_sq, q_min, tmp_exp; + Word32 Gw_sq, g_sq, tmp; + + g_sq = 0; + move32(); + + IF( NE_16( num_ch, pNum_dmx[i_mult( b, bands_bw )] ) ) + { + ivas_calc_post_pred_per_band_enc_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, b, postpred_cov_re, &q_postpred_cov_re ); + } + + Gw_sq = BASOP_Util_Divide3232_Scale( cov_real[0][0][b], L_max( postpred_cov_re[0][0], IVAS_FIX_EPS ), &tmp_exp ); + q_Gw_sq = add( sub( 15, tmp_exp ), sub( q_cov_real[0][0][b], q_postpred_cov_re ) ); + + guard_bits = find_guarded_bits_fx( num_ch ); + + FOR( ch = 0; ch < sub( num_ch, 1 ); ch++ ) + { + abs_val = L_shr( Mpy_32_32( pred_coeffs_re[ch][b], pred_coeffs_re[ch][b] ), guard_bits ); + g_sq = L_add( g_sq, abs_val ); + } + q_g_sq = sub( add( q_pred_coeffs_re, q_pred_coeffs_re ), add( 31, guard_bits ) ); + + tmp = Mpy_32_32( ONE_IN_Q30 /*4 in Q28*/, Mpy_32_32( dm_f_local, g_sq ) ); + q_tmp = sub( q_g_sq, 3 ); + + q_min = s_min( q_Gw_sq, q_tmp ); + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); + tmp = L_add( L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ), tmp ); + + tmp_exp = sub( 31, q_min ); + tmp = Sqrt32( tmp, &tmp_exp ); + q_tmp = sub( 31, tmp_exp ); + + tmp_exp = sub( 31, q_Gw_sq ); + Gw_sq = Sqrt32( Gw_sq, &tmp_exp ); + q_Gw_sq = sub( 31, tmp_exp ); + + q_min = s_min( q_Gw_sq, q_tmp ); + Gw_sq = L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ); + q_Gw_sq = q_min; + move16(); + + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); + + pWscale[b] = L_add( Mpy_32_32( Gw_sq, ONE_IN_Q30 /* 0.5 in Q31*/ ), Mpy_32_32( tmp, ONE_IN_Q30 /* 0.5 in Q31*/ ) ); + move32(); + q_pWscale[b] = q_Gw_sq; + move16(); + } + } + + return; +} + static void ivas_get_Wscaling_factor_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, @@ -1523,7 +2370,7 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p2_re[j][j][b] = L_shl( 1, q_pred_coeffs_re ); + tmp_p2_re[j][j][b] = L_shl_sat( 1, q_pred_coeffs_re ); move32(); max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][j][b] ) ); } @@ -1551,7 +2398,7 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p1_re[j][j][b] = L_shl( 1, q_dm_fv_re ); + tmp_p1_re[j][j][b] = L_shl_sat( 1, q_dm_fv_re ); move32(); max_val = L_max( max_val, L_abs( tmp_p1_re[j][j][b] ) ); } @@ -1723,33 +2570,198 @@ static void ivas_calc_post_pred_per_band( } } - /* num_ch x num_ch mult */ - for ( i = 0; i < num_ch; i++ ) + /* num_ch x num_ch mult */ + for ( i = 0; i < num_ch; i++ ) + { + for ( j = i; j < num_ch; j++ ) + { + for ( k = 0; k < num_ch; k++ ) + { + IVAS_RMULT_FLOAT( mixer_mat[i][k][band_idx], temp_mat[k][j], tmp_re ); + postpred_cov_re[i][j] += tmp_re; + } + } + } + + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < i; j++ ) + { + postpred_cov_re[i][j] = postpred_cov_re[j][i]; + } + } + + return; +} + + +#ifdef IVAS_FLOAT_FIXED + +static void ivas_calc_post_pred_per_band_enc_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 num_ch, + const Word16 band_idx, + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_postpred_cov_re ) +{ + Word16 i, j, k, guard_bits, tmp, q_temp_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], q_tmp_re, q_W_tmp; + Word32 dmx_mat_conj[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 temp_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 max_val; + Word64 tmp_re, W_tmp; + Word16 q_postpred_cov_re_per_value[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; + move32(); + } + } + + FOR( i = 0; i < num_ch; i++ ) + { + set32_fx( temp_mat[i], 0, num_ch ); + set32_fx( postpred_cov_re[i], 0, num_ch ); + } + + max_val = 1; + move32(); + /* num_ch x num_ch mult */ + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + tmp_re = 0; + move64(); + q_tmp_re = 31; + move16(); + FOR( k = 0; k < num_ch; k++ ) + { + W_tmp = W_shr( W_mult0_32_32( cov_real[i][k][band_idx], dmx_mat_conj[k][j] ), q_mixer_mat ); + IF( LT_16( q_cov_real[i][k][band_idx], q_tmp_re ) ) + { + tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_cov_real[i][k][band_idx] ) ), W_tmp ); + q_tmp_re = q_cov_real[i][k][band_idx]; + move16(); + } + ELSE + { + tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_cov_real[i][k][band_idx], q_tmp_re ) ) ); + } + } + IF( tmp_re == 0 ) + { + q_temp_mat[i][j] = 31; + move16(); + temp_mat[i][j] = 0; + move32(); + } + ELSE + { + q_temp_mat[i][j] = q_tmp_re; + move16(); + q_tmp_re = W_norm( tmp_re ); + temp_mat[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); + move32(); + q_temp_mat[i][j] = sub( add( q_temp_mat[i][j], q_tmp_re ), 32 ); + move16(); + } + max_val = L_max( max_val, L_abs( temp_mat[i][j] ) ); + } + } + + guard_bits = find_guarded_bits_fx( num_ch ); + + tmp = norm_l( max_val ); + IF( LT_16( tmp, guard_bits ) ) + { + guard_bits = sub( guard_bits, tmp ); + } + ELSE + { + guard_bits = 0; + move16(); + } + + *q_postpred_cov_re = 31; + move16(); + /* num_ch x num_ch mult */ + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = i; j < num_ch; j++ ) + { + tmp_re = 0; + move64(); + q_tmp_re = 31; + move16(); + FOR( k = 0; k < num_ch; k++ ) + { + W_tmp = W_shr( W_mult0_32_32( mixer_mat[i][k][band_idx], temp_mat[k][j] ), guard_bits ); + q_W_tmp = sub( add( q_temp_mat[k][j], q_mixer_mat ), guard_bits ); + IF( LT_16( q_W_tmp, q_tmp_re ) ) + { + tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_W_tmp ) ), W_tmp ); + q_tmp_re = q_W_tmp; + move16(); + } + ELSE + { + tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_W_tmp, q_tmp_re ) ) ); + } + } + + if ( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) + { + tmp_re = 0; + move64(); + } + + 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 ) ); + 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(); + } + } + + FOR( i = 0; i < num_ch; i++ ) { - for ( j = i; j < num_ch; j++ ) + FOR( j = i; j < num_ch; j++ ) { - for ( k = 0; k < num_ch; k++ ) + IF( postpred_cov_re[i][j] >= 0 ) { - IVAS_RMULT_FLOAT( mixer_mat[i][k][band_idx], temp_mat[k][j], tmp_re ); - postpred_cov_re[i][j] += tmp_re; + postpred_cov_re[i][j] = L_shr( postpred_cov_re[i][j], sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ); + move32(); + } + ELSE + { + postpred_cov_re[i][j] = L_negate( L_shr( L_negate( postpred_cov_re[i][j] ), sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ) ); + move32(); } } } - for ( i = 0; i < num_ch; i++ ) + FOR( i = 0; i < num_ch; i++ ) { - for ( j = 0; j < i; j++ ) + FOR( j = 0; j < i; j++ ) { postpred_cov_re[i][j] = postpred_cov_re[j][i]; + move32(); } } return; } - -#ifdef IVAS_FLOAT_FIXED - static void ivas_calc_post_pred_per_band_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, @@ -1898,166 +2910,672 @@ static void ivas_calc_p_coeffs_per_band( set_zero( recon_uu_re[i], IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); } - for ( i = num_dmx; i < num_ch; i++ ) - { - for ( j = num_dmx; j < num_ch; j++ ) - { - cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; - } - } + for ( i = num_dmx; i < num_ch; i++ ) + { + for ( j = num_dmx; j < num_ch; j++ ) + { + cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; + } + } + + if ( dtx_vad == 1 ) + { + for ( i = 1; i < num_dmx; i++ ) + { + for ( j = 1; j < num_dmx; j++ ) + { + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + } + } + + if ( num_dmx == 2 ) + { + float re1, re2; + + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], cov_dd_re[0][0], re1 ); + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], cov_dd_re[0][0], re2 ); + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1, recon_uu_re[0][0] ); + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re1, recon_uu_re[0][1] ); + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re2, recon_uu_re[1][0] ); + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re2, recon_uu_re[1][1] ); + + for ( i = 0; i < 2; i++ ) + { + for ( j = 0; j < 2; j++ ) + { + cov_uu_re[i][j] -= recon_uu_re[i][j]; + } + } + } + else if ( num_dmx == 3 ) + { + float re1[2], re2; + set_f( re1, 0, 2 ); + + for ( j = 0; j < 2; j++ ) + { + for ( k = 0; k < 2; k++ ) + { + float re; + + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][k], cov_dd_re[k][j], re ); + re1[j] += re; + } + } + + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1[0], re2 ); + recon_uu_re[0][0] = re2; + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][1], re1[1], re2 ); + recon_uu_re[0][0] += re2; + + cov_uu_re[0][0] -= recon_uu_re[0][0]; + } + else if ( num_dmx == 4 ) + { + /* Step 1: Multiply C * cov_dd * C' */ + float re1[3], re; + + for ( i = 0; i < num_ch - num_dmx; i++ ) + { + set_f( re1, 0, 3 ); + for ( m = 0; m < num_dmx - 1; m++ ) + { + for ( k = 0; k < num_dmx - 1; k++ ) + { + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[i][k], cov_dd_re[k][m], re ); + re1[m] += re; + } + } + for ( j = 0; j < num_ch - num_dmx; j++ ) + { + for ( m = 0; m < num_dmx - 1; m++ ) + { + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[j][m], re1[m], re ); + recon_uu_re[i][j] += re; + } + } + } + + /* Step 2: cov_uu - recon_uu */ + for ( i = 0; i < num_ch - num_dmx; i++ ) + { + for ( j = 0; j < num_ch - num_dmx; j++ ) + { + cov_uu_re[i][j] -= recon_uu_re[i][j]; + } + } + } + } + + p_norm_scaling = IVAS_P_NORM_SCALING; + + if ( ( dtx_vad == 0 ) && ( num_dmx == 1 ) ) + { + p_norm_scaling = IVAS_P_NORM_SCALING_DTX; + } + + trace = 0.0f; + + for ( i = num_dmx; i < num_ch; i++ ) + { + float tmp_out; + IVAS_CALCULATE_RABS( cov_uu_re[i - num_dmx][i - num_dmx], tmp_out ); + trace += tmp_out; + } + + factor = max( 1e-20f, postpred_cov_re[0][0] ); + factor = max( factor, ( p_norm_scaling * trace ) ); + factor = 1 / factor; + + /* normalise Hermitian (except for rounding) cov_uu */ + for ( i = num_dmx; i < num_ch; i++ ) + { + for ( j = num_dmx; j < num_ch; j++ ) + { + if ( i == j ) + { + /* force diagonal to be real */ + cov_uu_re[i - num_dmx][j - num_dmx] *= factor; + } + else + { + /* set off-diag elements to zero */ + cov_uu_re[i - num_dmx][j - num_dmx] = 0; + } + } + } + + /* take sqrt of max of diags and zero */ + for ( i = num_dmx; i < num_ch; i++ ) + { + cov_uu_re[i - num_dmx][i - num_dmx] = sqrtf( max( 0.0f, cov_uu_re[i - num_dmx][i - num_dmx] ) ); + /* cov_uu_im[i - num_dmx][i - num_dmx] = 0; */ + } + + /* save into MD struct */ + for ( i = num_dmx; i < num_ch; i++ ) + { + for ( j = num_dmx; j < num_ch; j++ ) + { + if ( i == j ) + { + pSparMd->band_coeffs[b_ts_idx].P_re[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; + } + } + } + } + + return; +} + +#ifdef IVAS_FLOAT_FIXED + +static void ivas_calc_p_coeffs_per_band_enc_fx( + ivas_spar_md_t *pSparMd, + const Word16 i_ts, + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 q_postpred_cov_re, + const Word16 num_ch, + const Word16 dtx_vad, + const Word16 num_dmx, + const Word16 band_idx ) +{ + Word16 i, j, k; + Word16 m; + Word32 factor; + Word32 recon_uu_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS]; + Word16 q_recon_uu_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS]; + Word64 trace, W_tmp; + Word16 q_factor, q_tmp, q_tmp1; + Word32 tmp; + Word32 p_norm_scaling; + Word16 q_cov_uu_re, q_cov_dd_re; + Word32 cov_dd_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; + Word32 cov_uu_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; + Word16 q_cov_uu_re_per_value[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; + Word16 b_ts_idx; + + b_ts_idx = add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) ); + + IF( NE_16( num_dmx, num_ch ) ) + { + set32_fx( pSparMd->band_coeffs[b_ts_idx].P_re_fx, 0, IVAS_SPAR_MAX_CH - 1 ); + pSparMd->band_coeffs[b_ts_idx].q_P_re_fx = 0; + move16(); + FOR( i = 0; i < sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ); i++ ) + { + set32_fx( recon_uu_re[i], 0, sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ) ); + } + + FOR( i = num_dmx; i < num_ch; i++ ) + { + FOR( j = num_dmx; j < num_ch; j++ ) + { + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = postpred_cov_re[i][j]; + move32(); + } + } + q_cov_uu_re = q_postpred_cov_re; + move16(); + + IF( EQ_16( dtx_vad, 1 ) ) + { + FOR( i = 1; i < num_dmx; i++ ) + { + FOR( j = 1; j < num_dmx; j++ ) + { + cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; + move32(); + } + } + q_cov_dd_re = q_postpred_cov_re; + move16(); + + Word16 q_C_re = pSparMd->band_coeffs[b_ts_idx].q_C_re_fx; + move16(); + + IF( EQ_16( num_dmx, 2 ) ) + { + Word32 re1, re2; + + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], cov_dd_re[0][0] ); + q_tmp1 = W_norm( W_tmp ); + re1 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); + q_tmp1 = sub( add( add( q_C_re, q_tmp1 ), q_cov_dd_re ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp1 = 31; + move16(); + } + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], cov_dd_re[0][0] ); + q_tmp = W_norm( W_tmp ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); + q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp = 31; + move16(); + } + + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1 ); + q_recon_uu_re[0][0] = W_norm( W_tmp ); + move16(); + recon_uu_re[0][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][0] ) ); + move32(); + q_recon_uu_re[0][0] = sub( add( add( q_C_re, q_recon_uu_re[0][0] ), q_tmp1 ), 32 ); + move16(); + if ( W_tmp == 0 ) + { + q_recon_uu_re[0][0] = 31; + move16(); + } + + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1 ); + q_recon_uu_re[0][1] = W_norm( W_tmp ); + move16(); + recon_uu_re[0][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][1] ) ); + move32(); + q_recon_uu_re[0][1] = sub( add( add( q_C_re, q_recon_uu_re[0][1] ), q_tmp1 ), 32 ); + move16(); + if ( W_tmp == 0 ) + { + q_recon_uu_re[0][1] = 31; + move16(); + } - if ( dtx_vad == 1 ) - { - for ( i = 1; i < num_dmx; i++ ) - { - for ( j = 1; j < num_dmx; j++ ) + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2 ); + q_recon_uu_re[1][0] = W_norm( W_tmp ); + move16(); + recon_uu_re[1][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][0] ) ); + move32(); + q_recon_uu_re[1][0] = sub( add( add( q_C_re, q_recon_uu_re[1][0] ), q_tmp ), 32 ); + move16(); + if ( W_tmp == 0 ) { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + q_recon_uu_re[1][0] = 31; + move16(); } - } - if ( num_dmx == 2 ) - { - float re1, re2; + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2 ); + q_recon_uu_re[1][1] = W_norm( W_tmp ); + move16(); + recon_uu_re[1][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][1] ) ); + move32(); + q_recon_uu_re[1][1] = sub( add( add( q_C_re, q_recon_uu_re[1][1] ), q_tmp1 ), 32 ); + move16(); + if ( W_tmp == 0 ) + { + q_recon_uu_re[1][1] = 31; + move16(); + } - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], cov_dd_re[0][0], re1 ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], cov_dd_re[0][0], re2 ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1, recon_uu_re[0][0] ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re1, recon_uu_re[0][1] ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re2, recon_uu_re[1][0] ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re2, recon_uu_re[1][1] ); + q_tmp = 31; + move16(); + FOR( i = 0; i < 2; i++ ) + { + FOR( j = 0; j < 2; j++ ) + { + q_tmp = s_min( q_tmp, q_recon_uu_re[i][j] ); + } + } + q_tmp = sub( s_min( q_tmp, q_cov_uu_re ), 1 ); - for ( i = 0; i < 2; i++ ) + FOR( i = 0; i < 2; i++ ) { - for ( j = 0; j < 2; j++ ) + FOR( j = 0; j < 2; j++ ) { - cov_uu_re[i][j] -= recon_uu_re[i][j]; + cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); + move32(); } } + q_cov_uu_re = q_tmp; + move16(); } - else if ( num_dmx == 3 ) + ELSE IF( EQ_16( num_dmx, 3 ) ) { - float re1[2], re2; - set_f( re1, 0, 2 ); + Word32 re1[2], re2; + Word16 q_re1[2]; + set32_fx( re1, 0, 2 ); + set16_fx( q_re1, 31, 2 ); - for ( j = 0; j < 2; j++ ) + FOR( j = 0; j < 2; j++ ) { - for ( k = 0; k < 2; k++ ) + FOR( k = 0; k < 2; k++ ) { - float re; + Word32 re; + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][k], cov_dd_re[k][j] ); + q_tmp = sub( W_norm( W_tmp ), 1 ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp = 31; + move16(); + } - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][k], cov_dd_re[k][j], re ); - re1[j] += re; + IF( LT_16( q_tmp, q_re1[j] ) ) + { + re1[j] = L_shr( re1[j], sub( q_re1[j], q_tmp ) ); + move32(); + q_re1[j] = q_tmp; + move16(); + } + ELSE + { + re = L_shr( re, sub( q_tmp, q_re1[j] ) ); + } + re1[j] = L_add( re1[j], re ); + move32(); } } - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1[0], re2 ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1[0] ); + q_tmp = sub( W_norm( W_tmp ), 1 ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); + q_tmp = sub( add( add( q_C_re, q_tmp ), q_re1[0] ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp = 31; + move16(); + } recon_uu_re[0][0] = re2; - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][1], re1[1], re2 ); - recon_uu_re[0][0] += re2; + move32(); - cov_uu_re[0][0] -= recon_uu_re[0][0]; + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1] ); + q_tmp1 = sub( W_norm( W_tmp ), 1 ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); + q_tmp1 = sub( add( add( q_C_re, q_tmp1 ), q_re1[1] ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp1 = 31; + move16(); + } + + IF( LT_16( q_tmp, q_tmp1 ) ) + { + re2 = L_shr( re2, sub( q_tmp1, q_tmp ) ); + } + ELSE + { + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_tmp1 ) ); + move32(); + q_tmp = q_tmp1; + move16(); + } + + recon_uu_re[0][0] = L_add( recon_uu_re[0][0], re2 ); + move32(); + + IF( LT_16( q_cov_uu_re, q_tmp ) ) + { + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_cov_uu_re ) ); + move32(); + } + ELSE + { + FOR( i = num_dmx; i < num_ch; i++ ) + { + FOR( j = num_dmx; j < num_ch; j++ ) + { + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = L_shr( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], sub( q_cov_uu_re, q_tmp ) ); + move32(); + } + } + q_cov_uu_re = q_tmp; + move16(); + } + + IF( recon_uu_re[0][0] != 0 ) + { + test(); + IF( W_norm( recon_uu_re[0][0] ) == 0 || W_norm( cov_uu_re[0][0] ) == 0 ) + { + FOR( i = num_dmx; i < num_ch; i++ ) + { + FOR( j = num_dmx; j < num_ch; j++ ) + { + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = L_shr( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], 1 ); + move32(); + } + } + q_cov_uu_re = sub( q_cov_uu_re, 1 ); + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], 1 ); + move32(); + } + } + + cov_uu_re[0][0] = L_sub( cov_uu_re[0][0], recon_uu_re[0][0] ); + move32(); } - else if ( num_dmx == 4 ) + ELSE IF( EQ_16( num_dmx, 4 ) ) { /* Step 1: Multiply C * cov_dd * C' */ - float re1[3], re; + Word32 re1[3], re; + Word16 q_re1[3]; - for ( i = 0; i < num_ch - num_dmx; i++ ) + FOR( i = 0; i < num_ch - num_dmx; i++ ) { - set_f( re1, 0, 3 ); - for ( m = 0; m < num_dmx - 1; m++ ) + set32_fx( re1, 0, 3 ); + set16_fx( q_re1, 31, 3 ); + set16_fx( q_recon_uu_re[i], 31, IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); + FOR( m = 0; m < num_dmx - 1; m++ ) { - for ( k = 0; k < num_dmx - 1; k++ ) + FOR( k = 0; k < num_dmx - 1; k++ ) { - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[i][k], cov_dd_re[k][m], re ); - re1[m] += re; + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][k], cov_dd_re[k][m] ); + q_tmp = sub( W_norm( W_tmp ), 2 ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp = 31; + move16(); + } + + IF( LT_16( q_tmp, q_re1[m] ) ) + { + re1[m] = L_shr( re1[m], sub( q_re1[m], q_tmp ) ); + move32(); + q_re1[m] = q_tmp; + move16(); + } + ELSE + { + re = L_shr( re, sub( q_tmp, q_re1[m] ) ); + } + IF( re != 0 ) + { + test(); + IF( W_norm( re ) == 0 || W_norm( re1[m] ) == 0 ) + { + re1[m] = L_shr( re1[m], 1 ); + move32(); + q_re1[m] = sub( q_re1[m], 1 ); + move16(); + re = L_shr( re, 1 ); + } + } + + re1[m] = L_add( re1[m], re ); + move32(); } } - for ( j = 0; j < num_ch - num_dmx; j++ ) + FOR( j = 0; j < num_ch - num_dmx; j++ ) { - for ( m = 0; m < num_dmx - 1; m++ ) + FOR( m = 0; m < num_dmx - 1; m++ ) { - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[j][m], re1[m], re ); - recon_uu_re[i][j] += re; + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[j][m], re1[m] ); + q_tmp = sub( W_norm( W_tmp ), 2 ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + q_tmp = sub( add( add( q_C_re, q_tmp ), q_re1[m] ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp = 31; + move16(); + } + + IF( LT_16( q_tmp, q_recon_uu_re[i][j] ) ) + { + recon_uu_re[i][j] = L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ); + move32(); + q_recon_uu_re[i][j] = q_tmp; + move16(); + } + ELSE + { + re = L_shr( re, sub( q_tmp, q_recon_uu_re[i][j] ) ); + } + IF( re != 0 ) + { + test(); + IF( W_norm( re ) == 0 || W_norm( recon_uu_re[i][j] ) == 0 ) + { + re1[m] = L_shr( re1[m], 1 ); + move32(); + q_recon_uu_re[i][j] = sub( q_recon_uu_re[i][j], 1 ); + move16(); + re = L_shr( re, 1 ); + } + } + recon_uu_re[i][j] = L_add( recon_uu_re[i][j], re ); + move32(); } } } + q_tmp = 31; + move16(); + FOR( i = 0; i < num_ch - num_dmx; i++ ) + { + FOR( j = 0; j < num_ch - num_dmx; j++ ) + { + q_tmp = s_min( q_tmp, q_recon_uu_re[i][j] ); + } + } + q_tmp = sub( s_min( q_tmp, q_cov_uu_re ), 1 ); + /* Step 2: cov_uu - recon_uu */ - for ( i = 0; i < num_ch - num_dmx; i++ ) + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) { - for ( j = 0; j < num_ch - num_dmx; j++ ) + FOR( j = 0; j < num_ch - num_dmx; j++ ) { - cov_uu_re[i][j] -= recon_uu_re[i][j]; + cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); + move32(); } } + q_cov_uu_re = q_tmp; + move16(); } } - p_norm_scaling = IVAS_P_NORM_SCALING; + p_norm_scaling = IVAS_P_NORM_SCALING_FX; + move32(); - if ( ( dtx_vad == 0 ) && ( num_dmx == 1 ) ) + test(); + if ( ( dtx_vad == 0 ) && EQ_16( num_dmx, 1 ) ) { - p_norm_scaling = IVAS_P_NORM_SCALING_DTX; + p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; + move32(); } - trace = 0.0f; + trace = 0; + move64(); - for ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { - float tmp_out; - IVAS_CALCULATE_RABS( cov_uu_re[i - num_dmx][i - num_dmx], tmp_out ); - trace += tmp_out; + trace = W_add( trace, W_deposit32_l( L_abs( cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] ) ) ); } - factor = max( 1e-20f, postpred_cov_re[0][0] ); - factor = max( factor, ( p_norm_scaling * trace ) ); - factor = 1 / factor; + factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); + q_factor = q_postpred_cov_re; + move16(); + IF( trace != 0 ) + { + q_factor = W_norm( trace ); + tmp = Mpy_32_32( p_norm_scaling, W_extract_h( W_shl( trace, q_factor ) ) ); + q_factor = sub( add( q_postpred_cov_re, q_factor ), 32 ); + IF( GT_16( q_factor, q_postpred_cov_re ) ) + { + tmp = L_shr( tmp, sub( q_factor, q_postpred_cov_re ) ); + q_factor = q_postpred_cov_re; + move16(); + } + ELSE + { + factor = L_shr( factor, sub( q_postpred_cov_re, q_factor ) ); + } + factor = L_max( factor, tmp ); + } + + Word16 factor_exp = 0; + move16(); + factor = BASOP_Util_Divide3232_Scale( 1, factor, &factor_exp ); + factor_exp = add( factor_exp, q_factor ); /* normalise Hermitian (except for rounding) cov_uu */ - for ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { - for ( j = num_dmx; j < num_ch; j++ ) + FOR( j = num_dmx; j < num_ch; j++ ) { - if ( i == j ) + IF( EQ_16( i, j ) ) { /* force diagonal to be real */ - cov_uu_re[i - num_dmx][j - num_dmx] *= factor; + W_tmp = W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ); + q_tmp = 32; + move16(); + if ( W_tmp != 0 ) + { + q_tmp = W_norm( W_tmp ); + } + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = W_extract_h( W_shl( W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ), q_tmp ) ); + move32(); + q_cov_uu_re_per_value[sub( i, num_dmx )][sub( j, num_dmx )] = sub( add( add( q_cov_uu_re, sub( 15, factor_exp ) ), q_tmp ), 32 ); + move16(); } - else + ELSE { /* set off-diag elements to zero */ - cov_uu_re[i - num_dmx][j - num_dmx] = 0; + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = 0; + move32(); + q_cov_uu_re_per_value[sub( i, num_dmx )][sub( j, num_dmx )] = 0; + move16(); } } } + Word16 cov_uu_re_exp; + q_tmp = 31; + move16(); /* take sqrt of max of diags and zero */ - for ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { - cov_uu_re[i - num_dmx][i - num_dmx] = sqrtf( max( 0.0f, cov_uu_re[i - num_dmx][i - num_dmx] ) ); - /* cov_uu_im[i - num_dmx][i - num_dmx] = 0; */ + cov_uu_re_exp = sub( 31, q_cov_uu_re_per_value[sub( i, num_dmx )][sub( i, num_dmx )] ); + cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] = Sqrt32( L_max( 0, cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] ), &cov_uu_re_exp ); + move32(); + q_cov_uu_re_per_value[sub( i, num_dmx )][sub( i, num_dmx )] = sub( 31, cov_uu_re_exp ); + move16(); + q_tmp = s_min( q_tmp, q_cov_uu_re_per_value[sub( i, num_dmx )][sub( i, num_dmx )] ); } /* save into MD struct */ - for ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { - for ( j = num_dmx; j < num_ch; j++ ) + FOR( j = num_dmx; j < num_ch; j++ ) { - if ( i == j ) + IF( EQ_16( i, j ) ) { - pSparMd->band_coeffs[b_ts_idx].P_re[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; + pSparMd->band_coeffs[b_ts_idx].P_re_fx[sub( j, num_dmx )] = L_shr( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], sub( q_cov_uu_re_per_value[sub( i, num_dmx )][sub( j, num_dmx )], q_tmp ) ); + move32(); } } } + pSparMd->band_coeffs[b_ts_idx].q_P_re_fx = q_tmp; + move16(); } return; } -#ifdef IVAS_FLOAT_FIXED - static void ivas_calc_p_coeffs_per_band_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, @@ -2078,6 +3596,7 @@ static void ivas_calc_p_coeffs_per_band_fx( Word32 cov_dd_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; Word32 cov_uu_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; Word16 b_ts_idx; + Word16 tmp; b_ts_idx = add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) ); @@ -2231,7 +3750,7 @@ static void ivas_calc_p_coeffs_per_band_fx( Word16 factor_exp = 0; move16(); factor = BASOP_Util_Divide3232_Scale( L_shl( 1, q_postpred_cov_re ), factor, &factor_exp ); - factor = L_shl_sat( factor, factor_exp ); + tmp = sub( 15, factor_exp ); /* normalise Hermitian (except for rounding) cov_uu */ FOR( i = num_dmx; i < num_ch; i++ ) @@ -2241,7 +3760,7 @@ static void ivas_calc_p_coeffs_per_band_fx( IF( EQ_16( i, j ) ) { /* force diagonal to be real */ - cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = W_extract_l( W_shr( W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ), 15 ) ); + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = W_extract_l( W_shr( W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ), tmp ) ); move32(); } ELSE @@ -2282,6 +3801,7 @@ static void ivas_calc_p_coeffs_per_band_fx( return; } + #endif // IVAS_FLOAT_FIXED @@ -2382,6 +3902,156 @@ static void ivas_calc_c_coeffs_per_band( #ifdef IVAS_FLOAT_FIXED +static void ivas_calc_c_coeffs_per_band_enc_fx( + ivas_spar_md_t *pSparMd, + const Word16 i_ts, + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 q_post_pred_cov_re, + const Word16 num_ch, + const Word16 num_dmx, + const Word16 band_idx, + const Word16 dtx_vad ) +{ + Word16 i, j, k; + + /* worst case for cov_ud is actually 12 x 3 */ + Word32 cov_ud_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; + Word32 cov_dd_re[FOA_CHANNELS - 1][FOA_CHANNELS - 1]; + Word32 cov_dd_re_inv[FOA_CHANNELS - 1][FOA_CHANNELS - 1]; + Word16 q_cov_dd_re_inv; + Word32 trace_cov_dd_re, max_val; + Word16 q_tmp; + Word32 abs_trace; + Word16 b_ts_idx; + + b_ts_idx = add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) ); + + IF( dtx_vad == 0 ) + { + set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, imult1616( sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ), sub( IVAS_SPAR_MAX_DMX_CHS, 1 ) ) ); + pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; + move16(); + return; + } + + FOR( i = num_dmx; i < num_ch; i++ ) + { + FOR( j = 1; j < num_dmx; j++ ) + { + cov_ud_re[sub( i, num_dmx )][sub( j, 1 )] = postpred_cov_re[i][j]; + move32(); + } + } + + max_val = 0; + move32(); + + FOR( i = 1; i < num_dmx; i++ ) + { + FOR( j = 1; j < num_dmx; j++ ) + { + IF( EQ_16( i, j ) ) + { + max_val = L_max( max_val, postpred_cov_re[i][j] ); + } + cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; + move32(); + } + } + + trace_cov_dd_re = 0; + move32(); + + FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) + { + trace_cov_dd_re = L_add( trace_cov_dd_re, Mpy_32_32( cov_dd_re[i][i], 10737418 /* 0.005f in Q31*/ ) ); + } + + abs_trace = L_abs( trace_cov_dd_re ); + + IF( LE_32( abs_trace, IVAS_FIX_EPS ) ) + { + /* protection from cases when variance of residual channels is very small */ + set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, imult1616( sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ), sub( IVAS_SPAR_MAX_DMX_CHS, 1 ) ) ); + pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; + move16(); + } + ELSE + { + q_tmp = 1; + move16(); + IF( norm_l( max_val ) > 0 ) + { + q_tmp = 0; + move16(); + } + trace_cov_dd_re = L_shr( trace_cov_dd_re, q_tmp ); + FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) + { + FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) + { + cov_dd_re[i][j] = L_shr( cov_dd_re[i][j], q_tmp ); // q_post_pred_cov_re - q_tmp + move32(); + } + } + + FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) + { + cov_dd_re[i][i] = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); + move32(); + } + test(); + IF( EQ_16( ivas_is_mat_inv_fx( cov_dd_re, q_post_pred_cov_re, sub( num_dmx, 1 ) ), 1 ) && LT_16( num_dmx, FOA_CHANNELS ) ) + { + set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, imult1616( sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ), sub( IVAS_SPAR_MAX_DMX_CHS, 1 ) ) ); + pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; + move16(); + } + ELSE + { + ivas_calc_mat_inv_fx( cov_dd_re, sub( q_post_pred_cov_re, q_tmp ), sub( num_dmx, 1 ), cov_dd_re_inv, &q_cov_dd_re_inv ); + + Word16 tmp; + Word64 W_max_val = 1; + move64(); + Word64 C_re_fx[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; + + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) + { + FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) + { + C_re_fx[i][j] = 0; + move64(); + FOR( k = 0; k < sub( num_dmx, 1 ); k++ ) + { + C_re_fx[i][j] = W_add_nosat( C_re_fx[i][j], W_mult0_32_32( cov_ud_re[i][k], cov_dd_re_inv[k][j] ) ); + move64(); + } + IF( LT_64( W_max_val, W_abs( C_re_fx[i][j] ) ) ) + { + W_max_val = W_abs( C_re_fx[i][j] ); + } + } + } + + tmp = s_max( sub( 32, W_norm( W_max_val ) ), 0 ); + + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) + { + FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) + { + pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][j] = W_extract_l( W_shr( C_re_fx[i][j], tmp ) ); + move32(); + } + } + pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = sub( add( q_cov_dd_re_inv, q_post_pred_cov_re ), tmp ); + move16(); + } + } + + return; +} + static void ivas_calc_c_coeffs_per_band_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, @@ -2570,6 +4240,65 @@ void ivas_calc_c_p_coeffs( #ifdef IVAS_FLOAT_FIXED +void ivas_calc_c_p_coeffs_enc_fx( + ivas_spar_md_t *pSparMd, + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + const Word16 i_ts, + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 num_ch, + const Word16 num_dmx, + const Word16 band_idx, + const Word16 dtx_vad, + const Word16 compute_p_flag, + const Word16 dyn_active_w_flag ) +{ + Word16 i, j, q_postpred_cov_re; + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] = { 0 }; + + IF( NE_16( num_dmx, num_ch ) ) + { + ivas_calc_post_pred_per_band_enc_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, band_idx, postpred_cov_re, &q_postpred_cov_re ); + + IF( NE_16( num_dmx, 1 ) ) + { + ivas_calc_c_coeffs_per_band_enc_fx( pSparMd, i_ts, postpred_cov_re, q_postpred_cov_re, num_ch, num_dmx, band_idx, dtx_vad ); + } + + IF( dyn_active_w_flag ) + { + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) + { + FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) + { + pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[i][j] = 0; + move32(); + } + } + pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_C_re_fx = 0; + move16(); + } + IF( EQ_16( compute_p_flag, 1 ) ) + { + ivas_calc_p_coeffs_per_band_enc_fx( pSparMd, i_ts, postpred_cov_re, q_postpred_cov_re, num_ch, dtx_vad, num_dmx, band_idx ); + } + + IF( dyn_active_w_flag ) + { + FOR( i = num_dmx; i < num_ch; i++ ) + { + pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[sub( i, num_dmx )] = 0; + move32(); + } + pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_P_re_fx = 0; + move16(); + } + } + + return; +} + void ivas_calc_c_p_coeffs_fx( ivas_spar_md_t *pSparMd, Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -3184,6 +4913,85 @@ void ivas_compute_spar_params( } #ifdef IVAS_FLOAT_FIXED + +void ivas_compute_spar_params_enc_fx( + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_dm_fv_re, + const Word16 i_ts, + Word32 ***mixer_mat_fx, + Word16 *q_mixer_mat, + const Word16 start_band, + const Word16 end_band, + const Word16 dtx_vad, + const Word16 num_ch, + const Word16 bands_bw, + const Word16 active_w, + const Word16 active_w_vlbr, + ivas_spar_md_com_cfg *hSparCfg, + ivas_spar_md_t *hSparMd, + Word32 *pWscale, + Word16 *q_Wscale, + const Word16 from_dirac, + const Word16 dyn_active_w_flag ) +{ + Word16 b, i, ndm; + Word16 q_pred_coeffs_re; + Word32 pred_coeffs_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + + ivas_get_pred_coeffs_enc_fx( cov_real_fx, q_cov_real, pred_coeffs_re_fx, &q_pred_coeffs_re, dm_fv_re_fx, q_dm_fv_re, num_ch, start_band, end_band, active_w, active_w_vlbr, dtx_vad, from_dirac, dyn_active_w_flag, hSparMd->res_ind ); + + ivas_create_fullr_dmx_mat_fx( pred_coeffs_re_fx, q_pred_coeffs_re, dm_fv_re_fx, *q_dm_fv_re, mixer_mat_fx, q_mixer_mat, num_ch, start_band, end_band, active_w, hSparCfg ); + + ivas_get_Wscaling_factor_enc_fx( cov_real_fx, q_cov_real, pred_coeffs_re_fx, q_pred_coeffs_re, mixer_mat_fx, *q_mixer_mat, start_band, end_band, dtx_vad, num_ch, hSparCfg->num_dmx_chans_per_band, bands_bw, active_w, active_w_vlbr, pWscale, q_Wscale, dyn_active_w_flag ); + + FOR( b = start_band; b < end_band; b++ ) + { + Word16 tmp_exp, q_tmp, tmp; + IF( pWscale[b] == 0 ) + { + pWscale[b] = 1; + move32(); + q_Wscale[b] = 15; + move16(); + } + + Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale( 1, pWscale[b], &tmp_exp ); + q_tmp = sub( sub( 15, tmp_exp ), q_Wscale[b] ); + + tmp = sub( add( q_pred_coeffs_re, q_tmp ), 15 ); + FOR( i = 0; i < sub( num_ch, 1 ); i++ ) + { + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = Mpy_32_16_1( pred_coeffs_re_fx[i][b], onebyscale_fx ); + move32(); + } + // hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_pred_re_fx = sub(add(q_pred_coeffs, q_tmp), 15); + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_pred_re_fx = tmp; + move16(); + + FOR( i = 0; i < num_ch; i++ ) + { + mixer_mat_fx[0][i][b] = W_extract_l( W_shr( W_mult0_32_32( mixer_mat_fx[0][i][b], pWscale[b] ), q_Wscale[b] ) ); + move32(); + } + } + + FOR( b = start_band; b < end_band; b++ ) + { + ndm = hSparCfg->num_dmx_chans_per_band[imult1616( b, bands_bw )]; + move16(); + + IF( NE_16( ndm, num_ch ) ) + { + ivas_calc_c_p_coeffs_enc_fx( hSparMd, cov_real_fx, q_cov_real, i_ts, mixer_mat_fx, *q_mixer_mat, num_ch, ndm, b, dtx_vad, 1, dyn_active_w_flag ); + } + } + + return; +} + + void ivas_compute_spar_params_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, @@ -3737,7 +5545,8 @@ void ivas_get_spar_md_from_dirac_fx( } - en_ratio_fac_fx = L_sub( ONE_IN_Q31, L_shl_sat( diffuseness_fx[band], 1 ) ); // assuming q of dissusion 30 + en_ratio_fac_fx = L_shl( L_sub( ONE_IN_Q30 - EPSILON_FX /* Guard to prevent overflow if diffuseness_fx is 0 */, diffuseness_fx[band] ), 1 ); // assuming q of dissusion 30 + en_ratio_fac_fx = L_max( en_ratio_fac_fx, 0 ); FOR( i = 0; i < num_ch; i++ ) { @@ -3815,7 +5624,7 @@ void ivas_get_spar_md_from_dirac_fx( } ELSE { - cov_real_dirac_fx[i][j][band] = L_shl_sat( Mpy_32_32( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), response_avg_fx[j] ), 1 ); + cov_real_dirac_fx[i][j][band] = L_shl( Mpy_32_32( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), response_avg_fx[j] ), 1 ); move32(); } } diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 4cb4168dfadba8ecdc1acd48731c606530ab473f..4fde550bdfbfab07fb8557b48e2bf2ba9fafbcbb 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -65,12 +65,13 @@ typedef struct Word16 radius_fx; /* radius value read from the input metadata file */ /* Q9 */ Word32 yaw_fx; /* yaw value read from the input metadata file */ /* Q22 */ Word32 pitch_fx; /* pitch value read from the input metadata file */ /* Q22 */ +#else + float azimuth; /* azimuth value read from the input metadata file */ + float elevation; /* elevation value read from the input metadata file */ + float radius; /* radius value read from the input metadata file */ + float yaw; /* yaw value read from the input metadata file */ + float pitch; /* pitch value read from the input metadata file */ #endif - float azimuth; /* azimuth value read from the input metadata file */ - float elevation; /* elevation value read from the input metadata file */ - float radius; /* radius value read from the input metadata file */ - float yaw; /* yaw value read from the input metadata file */ - float pitch; /* pitch value read from the input metadata file */ int16_t non_diegetic_flag; /* Non-diegetic (non-headtracked) object flag */ @@ -79,11 +80,12 @@ typedef struct int16_t last_radius_idx; /* last frame index of coded radius */ int16_t radius_diff_cnt; /* FEC counter of consecutive differentially radius coded frames */ +#ifndef IVAS_FLOAT_FIXED float last_azimuth; /* MD smoothing in DTX- last Q azimuth value */ float last_elevation; /* MD smoothing in DTX - last Q elevation value */ float last_true_azimuth; /* MD smoothing in DTX- last true Q azimuth value */ float last_true_elevation; /* MD smoothing in DTX- last true Q elevation value */ -#ifdef IVAS_FLOAT_FIXED +#else Word32 last_azimuth_fx; /* MD smoothing in DTX- last Q azimuth value */ /* Q22 */ Word32 last_elevation_fx; /* MD smoothing in DTX - last Q elevation value */ /* Q22 */ Word32 last_true_azimuth_fx; /* MD smoothing in DTX- last true Q azimuth value */ /* Q22 */ @@ -92,9 +94,10 @@ typedef struct int16_t ism_md_fec_cnt_enc; /* counter of continuous frames where MD are not transmitted */ int16_t ism_md_inc_diff_cnt; /* counter of continuous frames where MD are transmitted in inactive segments when MD significantly changes */ - float last_true_radius; /* last true Q radius value */ -#ifdef IVAS_FLOAT_FIXED - Word16 last_true_radius_fx; /* last true Q radius value */ +#ifndef IVAS_FLOAT_FIXED + float last_true_radius; /* last true Q radius value */ +#else + Word16 last_true_radius_fx; /* last true Q radius value */ #endif int16_t ism_imp; /* ISM importance flag */ @@ -103,9 +106,10 @@ typedef struct #ifdef IVAS_FLOAT_FIXED Word32 q_azimuth_old_fx; Word32 q_elevation_old_fx; -#endif +#else float q_azimuth_old; float q_elevation_old; +#endif } ISM_METADATA_FRAME, *ISM_METADATA_HANDLE; @@ -453,15 +457,16 @@ typedef struct ivas_masa_descriptive_meta_struct typedef struct ivas_masa_directional_spatial_meta_struct { +#ifndef IVAS_FLOAT_FIXED float azimuth[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; float elevation[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; float energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; float spread_coherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; -#ifdef IVAS_FLOAT_FIXED - Word32 azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q22 */ - Word32 elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q22 */ - Word32 energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q30 */ - Word16 spread_coherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q15 */ +#else + Word32 azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q22 */ + Word32 elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q22 */ + Word32 energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q30 */ + Word16 spread_coherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q15 */ #endif uint16_t spherical_index[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; @@ -469,14 +474,15 @@ typedef struct ivas_masa_directional_spatial_meta_struct typedef struct ivas_masa_common_spatial_meta_struct { +#ifndef IVAS_FLOAT_FIXED float diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; float surround_coherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; -#ifdef IVAS_FLOAT_FIXED + float remainder_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; +#else Word32 diffuse_to_total_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q30 - Word16 surround_coherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q14 + Word16 surround_coherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q15 Word32 remainder_to_total_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q30 #endif - float remainder_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; } MASA_COMMON_SPATIAL_META; @@ -531,11 +537,12 @@ typedef struct typedef struct ivas_qdirection_band_data_struct { uint16_t spherical_index[MAX_PARAM_SPATIAL_SUBFRAMES]; +#ifndef IVAS_FLOAT_FIXED float azimuth[MAX_PARAM_SPATIAL_SUBFRAMES]; float elevation[MAX_PARAM_SPATIAL_SUBFRAMES]; -#ifdef IVAS_FLOAT_FIXED - Word32 azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ - Word32 elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ +#else + Word32 azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ + Word32 elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ #endif int16_t elevation_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; int16_t azimuth_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; @@ -551,11 +558,12 @@ typedef struct ivas_qdirection_band_data_struct uint16_t energy_ratio_index_mod[MAX_PARAM_SPATIAL_SUBFRAMES]; uint16_t azimuth_index[MAX_PARAM_SPATIAL_SUBFRAMES]; uint16_t elevation_index[MAX_PARAM_SPATIAL_SUBFRAMES]; +#ifndef IVAS_FLOAT_FIXED float q_azimuth[MAX_PARAM_SPATIAL_SUBFRAMES]; float q_elevation[MAX_PARAM_SPATIAL_SUBFRAMES]; -#ifdef IVAS_FLOAT_FIXED - Word32 q_azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ - Word32 q_elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ +#else + Word32 q_azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ + Word32 q_elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ #endif } IVAS_QDIRECTION_BAND_DATA; @@ -611,7 +619,7 @@ typedef struct ivas_masa_qmetadata_frame_struct #ifndef IVAS_FLOAT_FIXED float dir_comp_ratio; #else - Word16 dir_comp_ratio_fx; /* Q15 */ + Word16 dir_comp_ratio_fx; /* Q15 */ #endif uint8_t is_masa_ivas_format; @@ -865,6 +873,7 @@ typedef struct ivas_fb_mixer_state_structure Word16 q_ppFilterbank_inFR_im_fx[IVAS_MAX_FB_MIXER_IN_CH]; Word16 q_ppFilterbank_prior_input_fx[IVAS_MAX_FB_MIXER_IN_CH]; Word32 *prior_mixer_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; + Word16 q_prior_mixer_fx; #endif /* store sin part in const table (no need to store 1s and 0s, no need to do windowing for 1's and 0's as well) */ diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index 995c70ed2148105d11b944643f60ccd837e5c482..4d8f90e9d6f58cc8dd60af07648a3dc3df9f9c9d 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -918,7 +918,7 @@ return; * * copy certain TD stereo parameters from primary channel to secondary channel *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void td_stereo_param_updt( const float lsp_old_PCh[], /* i : primary channel old LSPs */ const float lsf_old_PCh[], /* i : primary channel old LSFs */ @@ -966,8 +966,7 @@ void td_stereo_param_updt( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void td_stereo_param_updt_fx( const Word16 lsp_old_PCh_fx[], /* i : primary channel old LSPs Q15 */ const Word16 lsf_old_PCh_fx[], /* i : primary channel old LSFs Qlog2(2.56) */ @@ -1334,7 +1333,7 @@ static void tdm_SCh_LSF_intra_pred_one_bit_dec_fx( return; } -#endif +#else /*-------------------------------------------------------------------* * tdm_SCh_LSF_intra_pred_one_bit_dec() * @@ -1362,6 +1361,7 @@ static void tdm_SCh_LSF_intra_pred_one_bit_dec( return; } +#endif #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -1425,7 +1425,7 @@ static void tdm_SCh_LSF_intra_pred_one_bit_enc_fx( return; } -#endif +#else /*-------------------------------------------------------------------* * tdm_SCh_LSF_intra_pred_one_bit_enc() * @@ -1474,6 +1474,7 @@ static void tdm_SCh_LSF_intra_pred_one_bit_enc( return; } +#endif #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -1526,8 +1527,7 @@ void tdm_SCh_lsf_reuse_fx( return; } -#endif - +#else /*-------------------------------------------------------------------* * tdm_SCh_lsf_reuse() * @@ -1578,3 +1578,4 @@ void tdm_SCh_lsf_reuse( return; } +#endif diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 76e84cc9a795adfff1bbb73d529aa6730de08b2d..20cce673c507c610971d524c534ab5b2474c9ed7 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -2938,8 +2938,8 @@ static float wrap_azi( } #ifdef IVAS_FLOAT_FIXED /* helper function for panning_wrap_angles */ -static Word32 wrap_azi_fixed( - const Word32 azi_deg ) +static Word32 wrap_azi_fx( + const Word32 azi_deg /* Q22 */ ) { Word32 azi = azi_deg; move32(); @@ -3027,19 +3027,18 @@ void panning_wrap_angles( } #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* - * panning_wrap_angles_fixed() + * panning_wrap_angles_fx() * * Wrap angles for amplitude panning to the range: * azimuth = (-180, 180] * elevation = [-90, 90] * Considers direction changes from large elevation values *-------------------------------------------------------------------*/ -void panning_wrap_angles_fixed( - const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ - const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) */ - Word32 *azi_wrapped, /* o : wrapped azimuth component */ - Word32 *ele_wrapped /* o : wrapped elevation component */ - +void panning_wrap_angles_fx( + const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q22 */ + const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q22 */ + Word32 *azi_wrapped, /* o : wrapped azimuth component Q22 */ + Word32 *ele_wrapped /* o : wrapped elevation component Q22 */ ) { Word32 azi, ele; @@ -3053,7 +3052,7 @@ void panning_wrap_angles_fixed( { *ele_wrapped = ele; move32(); - *azi_wrapped = wrap_azi_fixed( azi ); + *azi_wrapped = wrap_azi_fx( azi ); move32(); return; } @@ -3093,7 +3092,7 @@ void panning_wrap_angles_fixed( ele = L_sub( -ANGLE_180_DEG_Q22, ele ); } } - *azi_wrapped = wrap_azi_fixed( azi ); + *azi_wrapped = wrap_azi_fx( azi ); move32(); *ele_wrapped = ele; move32(); diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index 143821c93806fc7ec2a7ac38f4a7d096a0fa86e8..a28f58851978507ed5541ebfeff8805efdad16b8 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -448,13 +448,13 @@ void E_LPC_f_isp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m ) /* a[i] = 0.5*(f1[i] + f2[i]) */ t0 = L_add( f1[i], f2[i] ); /* f1[i] + f2[i] */ t0 = L_shl( t0, q ); - a[i] = round_fx( t0 ); /* from Q23 to Q12 and * 0.5 */ + a[i] = round_fx_sat( t0 ); /* from Q23 to Q12 and * 0.5 */ move16(); /* a[j] = 0.5*(f1[i] - f2[i]) */ t0 = L_sub( f1[i], f2[i] ); /* f1[i] - f2[i] */ t0 = L_shl( t0, q ); - a[j] = round_fx( t0 ); /* from Q23 to Q12 and * 0.5 */ + a[j] = round_fx_sat( t0 ); /* from Q23 to Q12 and * 0.5 */ move16(); j = sub( j, 1 ); @@ -480,11 +480,11 @@ void E_LPC_f_isp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m ) } WHILE( t0n == 0 || t0p == 0 ); /*in case of overflow, recalculate coefficients*/ - a[nc] = round_fx( t0 ); /* from Q23 to Q12 and * 0.5 */ + a[nc] = round_fx_sat( t0 ); /* from Q23 to Q12 and * 0.5 */ move16(); /* a[m] = isp[m-1] */ t0 = L_mult( a[0], isp[m - 1] ); /* from Q15 to Q12 */ - a[m] = round_fx( t0 ); + a[m] = round_fx_sat( t0 ); move16(); return; diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index 9c490a012a7851a22740fb65a5ac50236adef11f..3cf2b645d93398a0e1cd7de0169d4c62220d5799 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -1709,8 +1709,8 @@ void decimate_2_over_3_allpass_fx( Word16 out, tmp; Word16 mem_fx_11, mem_fx_7, mem_fx_3; Word16 sc, input_fx[960]; - sc = s_min( s_min( sub( Find_Max_Norm16( input, len ), 2 ), sub( Find_Max_Norm16( mem_fx, 12 ), 2 ) ), sub( Find_Max_Norm16( lp_mem_fx, 6 ), 2 ) ); - Scale_sig( lp_mem_fx, 6, sc ); + sc = s_min( s_min( sub( Find_Max_Norm16( input, len ), 2 ), sub( Find_Max_Norm16( mem_fx, 12 ), 2 ) ), sub( Find_Max_Norm16( lp_mem_fx, 3 ), 2 ) ); + Scale_sig( lp_mem_fx, 3, sc ); Copy_Scale_sig( input, input_fx, len, sc ); Scale_sig( mem_fx, 12, sc ); out1 = out1_buff; @@ -1843,7 +1843,7 @@ void decimate_2_over_3_allpass_fx( Scale_sig( mem_fx, 12, negate( sc ) ); Scale_sig( out_fx, loop_len, negate( sc ) ); - Scale_sig( lp_mem_fx, 6, negate( sc ) ); + Scale_sig( lp_mem_fx, 3, negate( sc ) ); return; } diff --git a/lib_com/options.h b/lib_com/options.h index e9a2123d696623cef9d7822b10cbaa150315b830..fce42a1ea932f5deb3517014e37bc09e3ed88716 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -136,6 +136,7 @@ #define NONBE_MDCT_ST_DTX_SKIP_DEWHITENING_OF_NOISE_SHAPES_ON_SID_FRAMES /* FhG: issue 1133: skip de-whitening of bg noise shape after frameloss period if the first good frame is an SID */ #define NONBE_MDCT_ST_PLC_DO_NOT_SCALE_OLD_OUT_IF_FIRST_GOOD_IS_SID /* FhG: issue 1133: in TCX PLC, don't scale hHQ_core->old_out after applying fade to noise in burst frame error */ #define NON_BE_FIX_BASOP_819_THRESHOLD_MASA2TOTAL +#define FIX_903_ZERO_OUT_IMDCT_BUFFERS_FOR_MCT_IGNORE /* FhG: zero out all relevant imdct buffers in MCT decoding of channels with mct_chan_mode == MCT_CHAN_MODE_IGNORE */ /* ##################### End NON-BE switches ########################### */ #define FIX_740_HQ_CORE_OVA // Proposed fix to solve overlap and add issue for HQ_CORE @@ -181,11 +182,19 @@ #define FIX_869_WRONG_UVGAIN_STEP /* VA: Fix wrong decoding of uv gain quantizer for td-stereo*/ #define FIX_871_REMOVE_UNNECESSARY_CONDITION /* VA: remove a condition that is not needed and prevented correct frame classification of the secondary channel of the TD stereo */ + +#define FIX_874_INCREASE_IPD_PRECISION /*VA : Fix issue 874 by increasing ITD precision already when decoding index */ +#define FIX_874_INCREASE_IPD_PRECISION_A /*VA : Fix a possible issue where 2*PI should be used instead of PI (to be confirmed) */ #define FIX_875_SATURATION_DURING_ROUNDING /* VA: fix a possible saturation when rounding */ #define FIX_882_LOW_LEVEL_DISCONTINUITIES /* VA: Fix 882, discontinuities for low level signal by adding a scaling function that uses rounding, this function is more complex than normal one, has to be used only when necessary*/ #define FIX_879_DIFF_CONCEAL_PATH /* FhG: Fix for issue 879 and different concelalment paths that led to crash */ #define FIX_907_MEM_UPDATE_ISSUE /* VA: fix for 907, multiples issues surrounding mem_syn_r and update of mem_syn2 when FS is changing */ #define FIX_918_WRONG_SCALING_ON_MODE_SWITCHING /* VA: Fix wrong scaling of secondary channel when switching from stereo DFT to TD */ +#define FIX_924_IGF_ROUNDFX_SAT +#define FIX_930_JBM_BUFSIZE_MULT /* FhG: Fix 930, Word16 too small for apa_buffer_size */ +#define NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST /* Ericsson: BASOP Issue 943, Float Issue 1208, fix for overflow of sample offset counter for burst error in DFT Stereo PLC. */ +#define FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC /* Nokia: Fixes ivas_decode_masaism_metadata decision logic change due to precision difference; needs corresponding fix in floating point */ +#define FIX_953_WRONG_ENERGY_RATIO_MASA_EXT /* Nok: Fix 953 wrong energy ratio value after shift and cast to Word8 */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_com/prot.h b/lib_com/prot.h index 618057b043483e9db8c91f53230f15afd884a79b..d286851e0f6f60bd819ba3746a94b66c7b6c26ec 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -194,7 +194,12 @@ void set_zero_fx( Word32 *vec, /* o : input vector */ const Word16 lvec /* i : length of the vector */ ); - +#ifdef FIX_930_JBM_BUFSIZE_MULT +void set_zero2_fx( + Word32 *vec, /* o : input vector */ + const Word32 lvec /* i : length of the vector */ +); +#endif void set16_zero_fx( Word16 *vec, /* o : input vector */ const Word16 lvec /* i : length of the vector */ @@ -235,11 +240,13 @@ void mvl2l( const int16_t n /* i : vector size */ ); +#ifndef IVAS_FLOAT_FIXED void AGC_dec( float x[], /* i/o: input/output vector */ float mem[], /* i/o: mem[2] should be init to [0,0] */ const int16_t n /* i : vector size */ ); +#endif /*! r: index of the maximum value in the input vector */ int16_t maximum( @@ -2349,6 +2356,7 @@ void MDCT_selector( const float enerBuffer[] /* i : energy buffer */ ); +#ifndef IVAS_FLOAT_FIXED void MDCT_selector_reset( TCX_ENC_HANDLE hTcxEnc /* i/o: TCX Encoder Handle */ ); @@ -2357,7 +2365,6 @@ void MDCT_classifier_reset( TCX_ENC_HANDLE hTcxEnc /* i/o: TCX Encoder Handle */ ); -#ifndef IVAS_FLOAT_FIXED ivas_error acelp_core_enc( Encoder_State *st, /* i/o: encoder state structure */ const float inp[], /* i : input signal of the current frame */ @@ -2787,13 +2794,13 @@ void GenTransition( void GenTransition_fixed( - TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ - const int32_t output_Fs, /* i : output sampling rate */ - const int16_t element_mode, /* i : element mode */ - const int16_t L_frame, /* i : ACELP frame length */ - const int16_t rf_flag, /* i : RF flag */ - const int32_t total_brate, /* i : total bitrate */ + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ + const Word32 output_Fs, /* i : output sampling rate : Q0 */ + const Word16 element_mode, /* i : element mode : Q0 */ + const Word16 L_frame, /* i : ACELP frame length : Q0 */ + const Word16 rf_flag, /* i : RF flag : Q0 */ + const Word32 total_brate, /* i : total bitrate : Q0 */ const Word16 prev_Qx ); void GenTransition_WB( @@ -2803,9 +2810,9 @@ void GenTransition_WB( ); void GenTransition_WB_fixed( - TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ - const int32_t output_Fs /* i : output sampling rate */ + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ + const Word32 output_Fs /* i : output sampling rate */ ); void td_bwe_dec_init( @@ -4918,11 +4925,13 @@ void dec_acelp_4t64( const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ); +#ifndef IVAS_FLOAT_FIXED uint32_t syn_output( float *synth, /* i/o: float synthesis signal */ const int16_t output_frame, /* i : output frame length */ int16_t *synth_out /* o : integer 16 bits synthesis signal */ ); +#endif void FEC_exc_estim( Decoder_State *st, /* i/o: Decoder static memory */ @@ -9300,6 +9309,7 @@ ivas_error config_acelp1_IVAS( /*! r: ACELP16k flag */ +#ifndef IVAS_FLOAT_FIXED int16_t set_ACELP_flag_IVAS( const int16_t element_mode, /* i : element mode */ const int32_t element_brate, /* i : element bitrate */ @@ -9309,6 +9319,7 @@ int16_t set_ACELP_flag_IVAS( const int16_t bwidth, /* i : audio bandwidth */ const int16_t cng_type /* i : CNG type */ ); +#endif void FEC_clas_estim( const float *syn, @@ -9338,6 +9349,7 @@ void FEC_clas_estim( const int16_t FEC_mode /* i : ACELP FEC mode */ ); +#ifndef IVAS_FLOAT_FIXED void InitTransientDetection( const int16_t nFrameLength, const int16_t nTCXDelay, @@ -9360,6 +9372,7 @@ float GetTCXMaxenergyChange( const int16_t isTCX10, const int16_t nCurrentSubblocks, const int16_t nPrevSubblocks ); +#endif void SetTCXModeInfo( Encoder_State *st, /* i/o: encoder state structure */ @@ -9979,12 +9992,14 @@ float getTcxBandwidth_flt( const int16_t bwidth /* i : audio bandwidth */ ); +#ifndef IVAS_FLOAT_FIXED int16_t getIgfPresent( const int16_t element_mode, /* i : IVAS element mode */ const int32_t total_brate, /* i : total bitrate */ const int16_t bwidth, /* i : audio bandwidth */ const int16_t rf_mode /* i : flag to signal the RF mode */ ); +#endif int16_t getCnaPresent( const int16_t element_mode, /* i : element mode */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index fea8657eb912f754b6953d7bebd71882bf0e1f9f..70d2f94b0f2464703547ec9f06bc516fd1c737b1 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -827,7 +827,7 @@ void compute_poly_product_fx( Word16 *coef, Word32 *p, Word16 order ); void dec_prm_hm_fx( Decoder_State *st, - Word16 *prm_hm, + Word16 *prm_hm, /* Q0 */ const Word16 L_frame ); void msvq_dec( const Word16 *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) (0Q15) */ @@ -5860,17 +5860,17 @@ void td_bwe_dec_init_fx( // lsf_dec_fx.c void lsf_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *lsf_new, /* o : de-quantized LSF vector */ - Word16 *lsp_new, /* o : de-quantized LSP vector */ - Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector */ - const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag */ + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 tc_subfr, /* i : TC subframe index Q0*/ + Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ + Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ + const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ #endif ); @@ -5998,26 +5998,26 @@ Word32 dotp_me_fx( #endif void lsf_end_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 mode2_flag, - const Word16 coder_type_org, /* i : coding type */ - const Word16 bwidth, /* i : i signal bandwidth */ - const Word16 nBits_in, /* i : number of bits used for ISF quantization*/ - Word16 *qlsf, /* o : quantized LSFs in the cosine domain */ - Word16 *lpc_param, - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *nb_indices + Decoder_State *st, /* i/o: decoder state structure */ + Word16 mode2_flag, /* Q0 */ + const Word16 coder_type_org, /* i : coding type Q0*/ + const Word16 bwidth, /* i : input signal bandwidth Q0*/ + const Word16 nBits_in, /* i : number of bits used for ISF quantization Q0*/ + Word16 *qlsf, /* o : quantized LSFs in the cosine domain Qx2.56*/ + Word16 *lpc_param, /* i : LPC parameters Q0*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *nb_indices /* o : number of indices Q0*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const Word16 tdm_lsfQ_PCh[M] + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ #endif ); void lsf_mid_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 lsp_new[], /* i : quantized LSPs from frame endSQ15*/ - Word16 coder_type, /* i : Coder type */ - Word16 lsp_mid[] /* o : quantized LSPs Q15*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 lsp_new[], /* i : quantized LSPs from frame endS Q15*/ + Word16 coder_type, /* i : Coder type Q0*/ + Word16 lsp_mid[] /* o : quantized LSPs Q15*/ ); // cng_dec_fx.c @@ -6358,9 +6358,9 @@ void TonalMDCTConceal_SaveTimeSignal( // decision_matrix_dec_fx.c void decision_matrix_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ - Word16 *sharpFlag, /* o : formant sharpening flag */ - Word16 *hq_core_type, /* o : HQ core type */ - Word16 *core_switching_flag /* o : ACELP->HQ switching frame flag */ + Word16 *sharpFlag, /* o : formant sharpening flag Q0 */ + Word16 *hq_core_type, /* o : HQ core type Q0 */ + Word16 *core_switching_flag /* o : ACELP->HQ switching frame flag Q0 */ ); // hf_synth_fx.c @@ -6372,20 +6372,20 @@ void hf_synth_reset_fx( ); void hf_synth_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az */ - const Word16 *exc, /* i : excitation at 12.8 kHz */ - Word16 *synth, /* i : 12.8kHz synthesis signal */ - Word16 *synth16k, /* o : 16kHz synthesis signal */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc*/ + Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2*/ + Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2*/ const Word16 Q_exc, /* i : excitation scaling */ const Word16 Q_syn2, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ + Word16 *delay_syn_hf, /*i/o: HF synthesis memory Q_syn2*/ Word16 *memExp1, /* o : HF excitation exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ + Word16 *mem_hp_interp, /* i/o: interpol. memory Qx*/ + const Word16 extl, /* i : flag indicating BWE Q0*/ + const Word16 CNG_mode /* i : CNG_mode Q0*/ ); void hf_synth_amr_wb_init_fx( @@ -6400,21 +6400,21 @@ void hf_synth_amr_wb_reset_fx( void hf_synth_amr_wb_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */ ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az : Q12 */ - const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc */ - Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn */ - Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) */ - Word16 *synth_out, /* i/o: output signal at output Fs : Q_out */ - Word16 fmerit, /* i : classify parameter from FEC : Q14 */ - const Word16 *hf_gain, /* i : decoded HF gain */ - const Word16 *voice_factors, /* i : voicing factors : Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer : Q5 */ - const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8 */ - const Word16 *lsf_new, /* i : ISF vector : Q2 */ - const Word16 Q_exc, /* i : exc scaling */ - const Word16 Q_out /* i : Q_syn2-1 */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az : Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc*/ + Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn*/ + Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) Q0*/ + Word16 *synth_out, /* i/o: output signal at output Fs : Q_out*/ + Word16 fmerit, /* i : classify parameter from FEC : Q14*/ + const Word16 *hf_gain, /* i : decoded HF gain Q0*/ + const Word16 *voice_factors, /* i : voicing factors : Q15*/ + const Word16 pitch_buf[], /* i : pitch buffer : Q5*/ + const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8*/ + const Word16 *lsf_new, /* i : ISF vector : Q2*/ + const Word16 Q_exc, /* i : exc scaling */ + const Word16 Q_out /* i : Q_syn2-1 */ ); // dec_post_fx @@ -6518,19 +6518,20 @@ void init_tcx_cfg_fx( // syn_outp_fx.c void syn_output_fx( - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - Word16 *synth, /* i/o: float synthesis signal */ - const Word16 output_frame, /* i : output frame length */ - Word16 *synth_out, /* o : integer 16 bits synthesis signal */ - const Word16 Q_syn2 /* i : Synthesis scaling factor */ + const Word16 codec_mode, /* i : MODE1 or MODE2 */ + Word16 *synth, /* i/o: fixed point synthesis signal Q_syn2 */ + const Word16 output_frame, /* i : output frame length */ + Word16 *synth_out, /* o : integer 16 bits synthesis signal Q_syn2 */ + const Word16 Q_syn2 /* i : Synthesis scaling factor */ ); void unscale_AGC( - const Word16 x[], - const Word16 Qx, - Word16 y[], - Word16 mem[], - const Word16 n ); + const Word16 x[], /* i: 16kHz synthesis Qx */ + const Word16 Qx, /* i: scale factor of x */ + Word16 y[], /* o: output vector Q0 */ + Word16 mem[], /* i/o: mem[2] should be init to [0,0] Q0 */ + const Word16 n /* i: vector size */ +); // bass_psfilter_fx.c void bass_psfilter_init_fx( @@ -6627,60 +6628,60 @@ void PulseResynchronization_fx( // gs_dec_fx.c void decod_audio_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain */ - const Word16 *Aq, /* i : LP filter coefficient */ - Word16 *pitch_buf, /* o : floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new /* i : ISFs at the end of the frame */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : floating pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ , Word16 *gain_buf /*Q14*/ ); void decod_audio_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain */ - const Word16 *Aq, /* i : LP filter coefficient */ - Word16 *pitch_buf, /* o : floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new /* i : ISFs at the end of the frame */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ , Word16 *gain_buf, /*Q14*/ - const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag */ - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag Q0*/ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6*/ ); void gsc_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 coder_type, /* i : coding type */ - Word16 *last_bin, /* i : last bin of bit allocation */ - const Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + Decoder_State *st_fx, /* i/o: State structure */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency Q0*/ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + const Word16 coder_type, /* i : coding type Q0*/ + Word16 *last_bin, /* i : last bin of bit allocation Q0*/ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 Q_exc ); void gsc_dec_ivas_fx( Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 coder_type, /* i : coding type */ - Word16 *last_bin, /* i : last bin of bit allocation */ - const Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency ` Q0*/ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + const Word16 coder_type, /* i : coding type Q0*/ + Word16 *last_bin, /* i : last bin of bit allocation Q0*/ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 *Q_exc ); void GSC_dec_init( @@ -6930,18 +6931,18 @@ void dec_pit_exc_ivas_fx( #ifdef IVAS_FLOAT_FIXED // pit_dec_fx.c -Word32 Mode2_pit_decode( /* o: floating pitch value */ +Word32 Mode2_pit_decode( /* o: pitch value Q16 */ const Word16 coder_type, /* i: coding model */ Word16 i_subfr, /* i: subframe index */ Word16 L_subfr, - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* o: close loop fractional part of the pitch */ - Word16 *T0_res, /* i/o: pitch resolution */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_min_frac, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0_max_frac, /* i/o: higher limit for close-loop search */ + Word16 **pt_indice, /* i/o: quantization indices pointer */ + Word16 *T0, /* i/o: close loop integer pitch Q0 */ + Word16 *T0_frac, /* o: close loop fractional part of the pitch Q0 */ + Word16 *T0_res, /* i/o: pitch resolution Q0 */ + Word16 *T0_min, /* i/o: lower limit for close-loop search Q0 */ + Word16 *T0_min_frac, /* i/o: lower limit for close-loop search Q0 */ + Word16 *T0_max, /* i/o: higher limit for close-loop search Q0 */ + Word16 *T0_max_frac, /* i/o: higher limit for close-loop search Q0 */ Word16 pit_min, Word16 pit_fr1, Word16 pit_fr1b, @@ -6950,9 +6951,9 @@ Word32 Mode2_pit_decode( /* o: floating pitch value Word16 pit_res_max ); void Mode2_abs_pit_dec( - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac, /* o: pitch fraction */ - Word16 *T0_res, /* o: pitch resolution */ + Word16 *T0, /* o: integer pitch lag Q0 */ + Word16 *T0_frac, /* o: pitch fraction Q0 */ + Word16 *T0_res, /* o: pitch resolution Q0 */ Word16 **pt_indice, /* i/o: pointer to Vector of Q indexes */ Word16 pit_min, Word16 pit_fr1, @@ -6960,11 +6961,11 @@ void Mode2_abs_pit_dec( Word16 pit_res_max ); void Mode2_delta_pit_dec( - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac, /* o: pitch fraction */ - Word16 T0_res, /* i: pitch resolution */ - Word16 *T0_min, /* i: delta search min */ - Word16 *T0_min_frac, /* i: delta search min */ + Word16 *T0, /* o: integer pitch lag Q0 */ + Word16 *T0_frac, /* o: pitch fraction Q0 */ + Word16 T0_res, /* i: pitch resolution Q0 */ + Word16 *T0_min, /* i: delta search min Q0 */ + Word16 *T0_min_frac, /* i: delta search min Q0 */ Word16 **pt_indice /* i/o: pointer to Vector of Q indexes */ ); @@ -7001,8 +7002,8 @@ Word16 pit_decode_ivas_fx( /* o : floating p Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ const Word16 L_subfr, /* i : subframe length */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ ); void pit_Q_dec_fx( @@ -7077,33 +7078,32 @@ void limit_T0_voiced( // inov_dec.c void inov_decode_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : core bitrate Q0 */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ + const Word16 L_frame, /* i : length of the frame Q0 */ + const Word16 sharpFlag, /* i : formant sharpening flag Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code /* o : algebraic excitation */ - , - const Word16 L_subfr /* i : subframe length */ + Word16 *code, /* o : algebraic excitation Q12 */ + const Word16 L_subfr /* i : subframe length Q0 */ ); #ifdef IVAS_FLOAT_FIXED void inov_decode_ivas_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ + const Word32 core_brate, /* i : core bitrate Q0 */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ + const Word16 L_frame, /* i : length of the frame Q0 */ + const Word16 sharpFlag, /* i : formant sharpening flag Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code, /* o : algebraic excitation */ - const Word16 L_subfr /* i : subframe length */ + Word16 *code, /* o : algebraic excitation Q12 */ + const Word16 L_subfr /* i : subframe length Q0 */ ); #endif #ifdef IVAS_FLOAT_FIXED @@ -7299,14 +7299,13 @@ void pvq_decode_fx( #ifdef IVAS_FLOAT_FIXED // nelp_dec_fx.c void nelp_decoder_fx( - Decoder_State *st, /* i/o: decoder static memory */ - Word16 *exc_nelp, /* o : adapt. excitation/total exc */ - Word16 *exc, /* o : adapt. excitation exc */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 *exc_nelp, /* o : adapt. excitation/total exc Q0 */ + Word16 *exc, /* o : adapt. excitation exc Q_exc */ Word16 *Q_exc, - Word16 bfi, /* i : frame error rate */ - const Word16 coder_type /* i : coding type */ - , - Word16 *gain_buf /*Q14*/ + Word16 bfi, /* i : frame error rate Q0 */ + const Word16 coder_type, /* i : coding type Q0 */ + Word16 *gain_buf /* Q14 */ ); #endif @@ -7486,6 +7485,12 @@ void generate_masking_noise_mdct_fx( Word32 *mdctBuffer, /* i/o: time-domain s , Word16 L_frame ); +#ifdef IVAS_FLOAT_FIXED +void generate_masking_noise_mdct_ivas_fx( Word32 *mdctBuffer, /* i/o: time-domain signal */ + Word16 *mdctBuffer_e, /* i/o: exponent time-domain signal */ + HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ ); +#endif + // init_dec_fx.c ivas_error init_decoder_fx( Decoder_State *st_fx, /* o: Decoder static variables structure */ @@ -7509,21 +7514,21 @@ void destroy_cldfb_decoder_fx( // swb_bwe_dec_fx.c Word16 WB_BWE_gain_deq_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *WB_fenv ); - + Word16 *WB_fenv /*Q15*/ +); Word16 wb_bwe_dec_fx( #ifdef ADD_IVAS_BWE const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #ifdef ADD_IVAS_BWE const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ Decoder_State *st_fx /* i/o: decoder state structure */ , Word16 *Qpost ); @@ -7537,19 +7542,19 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class const Word16 hqswb_clas /* i : HQ BWE class */ ); -Word16 swb_bwe_dec_fx( +Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/ #ifdef ADD_IVAS_BWE - const Word16 output[], /* i : suntehsis @ internal Fs */ + const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth_fx, /* i : ACELP core synthesis/final synthesis */ - Word16 *hb_synth, /* o : SHB synthesis/final synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #ifdef ADD_IVAS_BWE - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif - const Word16 output_frame /* i : frame length */ - , - Word16 *Qpost ); + const Word16 output_frame /* i : frame length */ + , + Word16 *Qpost ); void fd_bwe_dec_init( Decoder_State *st_fx, /* i/o: decoder state structure */ @@ -7568,11 +7573,11 @@ void hq_core_enc_ivas_fx( // hq_core_dec_fx.c void hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ + Word16 synth[], /* o : output synthesis Q_synth*/ Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag */ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag Q0*/ ); void HQ_core_dec_init_fx( HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ @@ -7618,32 +7623,32 @@ void hq_lr_dec_fx( ); // gq_env_dec_fx.c -Word16 decode_envelope_indices_fx( /* o : Number of bits */ +Word16 decode_envelope_indices_fx( /* o : Number of bits Q0*/ Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : starting band index */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode */ - Word16 *difidx, /* o : Diff indices/encoded diff indices */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core */ + const Word16 start_norm, /* i : starting band index Q0*/ + const Word16 num_sfm, /* i : Number of subbands Q0*/ + const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0*/ + Word16 *difidx, /* o : Diff indices/encoded diff indices Q0*/ + const Word16 flag_HQ2 /* i : indicator of HQ2 core Q0*/ , - const Word16 is_transient /* i : indicator of HQ_TRANSIENT */ + const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0*/ ); void dequantize_norms_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : First SDE encoded norm */ - const Word16 num_sfm, /* i : Number of norms */ - const Word16 is_transient, /* i : Transient flag */ - Word16 *ynrm, /* o : Decoded norm indices */ - Word16 *normqlg2 /* o : Log2 of decoded norms */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 start_norm, /* i : First SDE encoded norm Q0*/ + const Word16 num_sfm, /* i : Number of norms Q0*/ + const Word16 is_transient, /* i : Transient flag Q0*/ + Word16 *ynrm, /* o : Decoded norm indices Q0*/ + Word16 *normqlg2 /* o : Log2 of decoded norms Q0*/ ); #ifdef IVAS_FLOAT_FIXED // hdecnrm_fx.c void hdecnrm_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 numNorms, /* (i) number of norms */ - Word16 *index ); /* (o) indices of quantized norms */ + const Word16 numNorms, /* (i) number of norms Q0*/ + Word16 *index ); /* (o) indices of quantized norms Q0*/ Word16 decode_huff_context_fx( @@ -7653,51 +7658,53 @@ Word16 decode_huff_context_fx( void hdecnrm_context_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, - Word16 *index, - Word16 *n_length ); + const Word16 N, /* Q0 */ + Word16 *index, /* Q0 */ + Word16 *n_length /* Q0 */ +); void hdecnrm_resize_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* (i) number of SFMs */ - Word16 *index /* (o) norm quantization index vector */ + const Word16 N, /* (i) number of SFMs Q0*/ + Word16 *index /* (o) norm quantization index vector Q0*/ ); void huff_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* i : Number of codewords to decode */ - const Word16 buffer_len, /* i : Number of bits to read */ - const Word16 num_lengths, /* i : Number of different huffman codeword lengths */ - const Word16 *thres, /* i : Threshold of first codeword of each length */ - const Word16 *offset, /* i : Offset for first codeword */ - const Word16 *huff_tab, /* i : Huffman table order by codeword lengths */ - Word16 *index /* o : Decoded index */ + const Word16 N, /* i : Number of codewords to decode Q0*/ + const Word16 buffer_len, /* i : Number of bits to read Q0*/ + const Word16 num_lengths, /* i : Number of different huffman codeword lengths Q0*/ + const Word16 *thres, /* i : Threshold of first codeword of each length Q0*/ + const Word16 *offset, /* i : Offset for first codeword Q0*/ + const Word16 *huff_tab, /* i : Huffman table order by codeword lengths Q0*/ + Word16 *index /* o : Decoded index Q0*/ ); void hdecnrm_tran_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* i : number of norms */ - Word16 *index /* o : indices of quantized norms */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 N, /* i : number of norms Q0*/ + Word16 *index /* o : indices of quantized norms Q0*/ ); #endif // tcq_core_dec_fx.c void tcq_core_LR_dec_fx( Decoder_State *st_fx, - Word16 *inp_vector_fx, - const Word16 bit_budget, - const Word16 bands, - const Word16 *band_start, - const Word16 *band_width, - Word32 *Rk_fx, - Word16 *npulses, - Word16 *k_sort, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame, - const Word16 adjustFlag, - const Word16 *is_transient ); + Word16 *inp_vector_fx, /*x5 */ + const Word16 bit_budget, /*Q0 */ + const Word16 BANDS, /*Q0 */ + const Word16 *band_start, /*Q0 */ + const Word16 *band_width, /*Q0 */ + Word32 *Rk_fx, /*Q16*/ + Word16 *npulses, /*Q0 */ + Word16 *k_sort, /*Q0 */ + const Word16 *p2a_flags, /*Q0 */ + const Word16 p2a_bands, /*Q0 */ + const Word16 *last_bitalloc, /*Q0 */ + const Word16 input_frame, /*Q0 */ + const Word16 adjustFlag, /*Q0 */ + const Word16 *is_transient /*Q0 */ +); // FEC_HQ_core_fx.c void HQ_FEC_processing_fx( @@ -7739,11 +7746,11 @@ void time_domain_FEC_HQ_fx( // hq_hr_dec_fx.c void hq_pred_hb_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *ynrm, /* i : norm quantization index vector Q0*/ + const Word16 length, /* i : frame length Q0*/ + const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ); void hq_hr_dec_fx( @@ -7755,7 +7762,7 @@ void hq_hr_dec_fx( Word16 *is_transient, /* o : transient flag Q0 */ Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag */ + const Word16 core_switching_flag /* i : Core switching flag Q1 */ ); // hq_classifier_dec_fx.c @@ -7773,7 +7780,7 @@ void hvq_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 num_bits, /* i : Number of available bits */ const Word32 core_brate, /* i : Core bit-rate */ - const Word16 *ynrm, /* i : Envelope coefficients */ + const Word16 *ynrm, /* i : Envelope coefficients Q0 */ Word16 *R, /* i/o: Bit allocation/updated bit allocation */ Word16 *noise_level, /* o : Noise level in Q15 */ Word16 *peak_idx, /* o : Peak position vector */ @@ -7798,12 +7805,12 @@ Word16 hvq_pvq_bitalloc_fx( // hq_conf_fec_fx.c void hq_configure_bfi_fx( - Word16 *nb_sfm, /* o : Number of sub bands Q0 */ - Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0 */ - Word16 *num_bands_p, /* o : FEC sub bands Q0 */ - const Word16 **sfmsize, /* o : Subband bandwidths */ - const Word16 **sfm_start, /* o : Subband start coefficients */ - const Word16 **sfm_end /* o : Subband end coefficients */ + Word16 *nb_sfm, /* o : Number of sub bands Q0*/ + Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0*/ + Word16 *num_bands_p, /* o : FEC sub bands Q0*/ + const Word16 **sfmsize, /* o : Subband bandwidths Q0*/ + const Word16 **sfm_start, /* o : Subband start coefficients Q0*/ + const Word16 **sfm_end /* o : Subband end coefficients Q0*/ ); // core_switching_dec_fx.c @@ -7970,19 +7977,21 @@ Word16 FEC_pos_dec_fx( // post_dec.h void post_decoder( Decoder_State *st, - Word16 synth_buf[], - Word16 pit_gain[], - Word16 pitch[], - Word16 signal_out[], - Word16 *bpf_noise_buf ); + Word16 synth_buf[], /* Q0 */ + Word16 pit_gain[], /* Q14 */ + Word16 pitch[], /* Q0 */ + Word16 signal_out[], /* Q0 */ + Word16 *bpf_noise_buf /* Q0 */ +); void post_decoder_ivas_fx( Decoder_State *st, - Word16 synth_buf[], - Word16 pit_gain[], - Word16 pitch[], - Word16 signal_out[], - Word16 *bpf_noise_buf ); + Word16 synth_buf[], // Q0 + Word16 pit_gain[], // Q14 + Word16 pitch[], // Q0 + Word16 signal_out[], // Q0 + Word16 *bpf_noise_buf // Q0 +); void cldfb_synth_set_bandsToZero( Decoder_State *st, @@ -8122,24 +8131,24 @@ void music_postfilt_init( // gs_dec_amr_wb.c void improv_amr_wb_gs_fx( - const Word16 clas, /* i : signal frame class */ - const Word16 coder_type, /* i : coder type */ - const Word32 core_brate, /* i : bitrate allocated to the core */ - Word16 *seed_tcx, /* i/o: Seed used for noise generation */ - Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient */ - Word16 *mem_syn2_fx, /* i/o: synthesis memory */ - const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q15 */ - const Word16 locattack, /* i : Flag for a detected attack */ - Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient */ - Word16 *exc2_fx, /* i/o: Decoded complete excitation */ - const Word16 Q_exc2, /* i : Exponent of Exc2 */ - Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory */ - Word16 *syn_fx, /* o: Decoded synthesis to be updated */ - const Word16 Q_syn, /* i : Synthesis scaling Q0 */ - const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer */ - const Word16 Last_ener_fx, /* i : Last energy (Q8) */ - const Word16 rate_switching_reset, /* i : rate switching reset flag */ - const Word16 last_coder_type /* i : Last coder_type */ + const Word16 clas, /* i : signal frame class Q0*/ + const Word16 coder_type, /* i : coder type Q0*/ + const Word32 core_brate, /* i : bitrate allocated to the core Q0*/ + Word16 *seed_tcx, /* i/o: Seed used for noise generation Q0*/ + Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient q_old_Aq*/ + Word16 *mem_syn2_fx, /* i/o: synthesis memory Q_syn*/ + const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q14*/ + const Word16 locattack, /* i : Flag for a detected attack Q0*/ + Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient q_Aq*/ + Word16 *exc2_fx, /* i/o: Decoded complete excitation Q_exc2*/ + const Word16 Q_exc2, /* i : Exponent of Exc2 */ + Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory Q_syn*/ + Word16 *syn_fx, /* o: Decoded synthesis to be updated Q_syn*/ + const Word16 Q_syn, /* i : Synthesis scaling */ + const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer Q6*/ + const Word16 Last_ener_fx, /* i : Last energy (Q8) Q0*/ + const Word16 rate_switching_reset, /* i : rate switching reset flag Q0*/ + const Word16 last_coder_type /* i : Last coder_type Q0*/ #ifdef ADD_IVAS_GS_DEC_IMPR , const Word16 VeryLowRateSTflag /* i : Enable the noise enhancement for very low rate stereo generic mode */ @@ -8162,8 +8171,8 @@ void decod_amr_wb_fx( // rst_dec_fx.c void CNG_reset_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *pitch_buf, /* o : floating pitch for each subframe */ - Word16 *voice_factors /* o : voicing factors */ + Word16 *pitch_buf, /* o : floating pitch for each subframe Q6*/ + Word16 *voice_factors /* o : voicing factors Q15*/ ); // voiced_dec_fx.c @@ -8247,14 +8256,14 @@ void tcxltp_dec_init_fx( const Word32 sr_core ); /* Q0 */ // swb_bwe_dec_hr_fx.c -Word16 swb_bwe_dec_hr_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz */ - const Word16 old_syn_exp, /* i : Exponent of core synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis */ - const Word16 output_frame, /* i : frame length */ - const Word16 unbits, /* i : number of core unused bits */ - const Word16 pitch_buf[] /* i : pitch buffer */ +Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz : Q(15 - exp) */ + const Word16 exp, /* i : Exponent of core synthesis */ + Word16 *hb_synth_fx, /* o : SHB synthesis : Q(15 - hb_synth_fx_exp)*/ + const Word16 output_frame, /* i : frame length */ + const Word16 unbits, /* i : number of core unused bits */ + const Word16 pitch_buf[] /* i : pitch buffer : Q6 */ ); void hr_bwe_dec_init( @@ -8277,13 +8286,12 @@ void swb_hr_noise_fill_fx( #ifdef IVAS_FLOAT_FIXED // stat_noise_uv_dec_fx.c void stat_noise_uv_dec_fx( - Decoder_State *st_fx, /* i/o: Decoder static memory */ - Word16 *lsp_new, /* i : end-frame LSP vector */ - Word16 *lsp_mid, /* i : mid-frame LSP vector */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ - Word16 *exc2 /* i/o: excitation buffer */ - , - const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ + Decoder_State *st_fx, /* i/o: Decoder static memory */ + Word16 *lsp_new, /* i : end-frame LSP vector Q15 */ + Word16 *lsp_mid, /* i : mid-frame LSP vector Q15 */ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q = 14 - norm_s(Aq[0]) */ + Word16 *exc2, /* i/o: excitation buffer, Q = st_fx->Q_exc */ + const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ ); #endif @@ -8510,26 +8518,26 @@ ivas_error decod_ppp_fx( // swb_bwe_dec_lr_fx.c void swb_bwe_dec_lr_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - const Word16 QsL, /* i : Q value of m_core */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Number subbands/Frame */ - Word16 *band_start_fx, /* i : Band Start of each SB */ - Word16 *band_end_fx, /* i : Band end of each SB */ - Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal Indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - Word16 lowlength_fx, /* i : Lowband Length */ - Word16 highlength_fx, /* i : Highband Length */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - Word16 band_width_fx[], /* i : subband bandwidth */ - const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ - Word16 *ni_seed_fx /* i/o: random seed */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 L_m_core[], /* i : lowband synthesis : QsL */ + const Word16 QsL, /* i : Q value of m_core */ + Word32 L_m[], /* o : highband synthesis with lowband zeroed : QsL */ + const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ + Word16 BANDS_fx, /* i : Number subbands/Frame : Q0 */ + Word16 *band_start_fx, /* i : Band Start of each SB : Q0 */ + Word16 *band_end_fx, /* i : Band end of each SB :Q0 */ + Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal Indicator : Q0 */ + const Word16 hqswb_clas_fx, /* i : class information : Q0 */ + Word16 lowlength_fx, /* i : Lowband Length : Q0 */ + Word16 highlength_fx, /* i : Highband Length : Q0 */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands : Q0 */ + Word16 *prev_frm_hfe2, /* i/o: : Q0 */ + Word16 *prev_stab_hfe2, /* i/o: : Q0 */ + Word16 band_width_fx[], /* i : subband bandwidth : Q0 */ + const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ + Word16 *ni_seed_fx /* i/o: random seed : QsL */ ); #ifdef IVAS_FLOAT_FIXED @@ -8614,27 +8622,30 @@ void tcx_hm_decode( ); // lsf_msvq_ma_dec_fx.c -Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ); +Word16 lsf_msvq_ma_decprm( + Decoder_State *st, + Word16 *param_lpc /* Q0 */ +); Word16 lsf_bctcvq_decprm( Decoder_State *st, - Word16 *param_lpc + Word16 *param_lpc /* Q0 */ ); Word16 D_lsf_tcxlpc( - const Word16 indices[], /* (I) VQ indices */ - Word16 xsf_q[], /* (O) quantized xSF */ - Word16 xsf_q_ind[], /* (O) quantized xSF (w/o MA prediction) */ - Word16 narrowband, /* (I) narrowband flag */ - Word16 cdk, /* (I) codebook selector */ - Word16 mem_MA[] /* (I) MA memory */ + const Word16 indices[], /* i : VQ indices Q0*/ + Word16 lsf_q[], /* o : quantized LSF Q1*/ + Word16 lsp_q_ind[], /* o :quantized LSP (w/o MA prediction) Q1*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk, /* i : codebook selector Q0*/ + Word16 mem_MA[] /* i : MA memory Q1*/ ); Word16 dec_lsf_tcxlpc( - Decoder_State *st, /* (I/O) Decoder state */ - Word16 **indices, /* (O) Ptr to VQ indices */ - Word16 narrowband, /* (I) narrowband flag */ - Word16 cdk /* (I) codebook selector */ + Decoder_State *st, /* i/o: Decoder state */ + Word16 **indices, /* o : Ptr to VQ indices Q0*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk /* i : codebook selector Q0*/ ); // lsf_msvq_ma_fx.c @@ -8709,13 +8720,13 @@ void getTCXparam_fx( Decoder_State *st, /* i/o: Decoder State handle */ Decoder_State *st0, /* i : bitstream */ CONTEXT_HM_CONFIG hm_cfg, /* i/o: HM config */ - Word16 param[], /* o : decoded parameters */ - const Word16 bits_common, /* i : number of common bits */ - const Word16 start_bit_pos, /* i : position of the start bit */ - const Word16 *no_param_tns, /* i : number of TNS parameters per subframe */ - Word16 p_param[2], /* o : pointer to parameters for next round of bs reading*/ - Word16 nTnsBitsTCX10[2], - const Word16 pre_past_flag ); + Word16 param[], /* o : decoded parameters Q0 */ + const Word16 bits_common, /* i : number of common bits Q0 */ + const Word16 start_bit_pos, /* i : position of the start bit Q0 */ + const Word16 *no_param_tns, /* i : number of TNS parameters per subframe Q0 */ + Word16 p_param[2], /* o : pointer to parameters for next round of bs reading Q0 */ + Word16 nTnsBitsTCX10[2], /*Q0*/ + const Word16 pre_past_flag /*Q0*/ ); void dec_prm_fx( Word16 *coder_type, Word16 param[], /* (o) : decoded parameters */ @@ -8726,11 +8737,11 @@ void dec_prm_fx( Word16 *bitsRead ); void getLPCparam_fx( - Decoder_State *st, /* i/o: decoder memory state */ - Word16 param_lpc[], /* o : LTP parameters */ - Decoder_State *st0, /* i : bitstream */ - const Word16 ch, /* i : channel */ - const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ + Decoder_State *st, /* i/o: decoder memory state */ + Word16 param_lpc[], /* o : LTP parameters Q0 */ + Decoder_State *st0, /* i : bitstream */ + const Word16 ch, /* i : channel Q0 */ + const Word16 sns_low_br_mode /* i : SNS low-bitrate mode Q0 */ ); // ari_hm_fx.c @@ -9284,39 +9295,40 @@ void tcx_arith_decode_envelope_fx( // tcx_utils_dec_fx.c void tcx_decoder_memory_update( - Word16 *xn_buf, /* i: mdct output buffer */ - Word16 *synthout, /* i/o: synth */ - Word16 *A, /* i: Quantized LPC coefficients */ - Decoder_State *st, - Word8 fb /* i: fullband flag */ + Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer : Q0 */ + Word16 *synthout, /* o: synth : Q0 */ + Word16 *A, /* i: Quantized LPC coefficients : Q12*/ + Decoder_State *st, /* i/o: decoder memory state */ + Word8 fb /* i: fullband flag */ ); Word16 tcx_ari_res_invQ_spec( - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - const Word16 prm[], /* i: bit-stream Q0 */ - Word16 target_bits, /* i: number of bits available Q0 */ - Word16 bits, /* i: number of bits used so far Q0 */ - Word16 deadzone, /* i: quantizer deadzone Q15 */ - const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ + Word32 x_Q[], /* i/o: quantized spectrum Q(31-x_Q_e) */ + Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ + Word16 L_frame, /* i: number of lines Q0 */ + const Word16 prm[], /* i: bitstream Q0 */ + Word16 target_bits, /* i: number of bits available Q0 */ + Word16 bits, /* i: number of bits used so far Q0 */ + Word16 deadzone, /* i: quantizer deadzone Q15 */ + const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ ); Word16 tcx_res_invQ_gain( - Word16 *gain_tcx, + Word16 *gain_tcx, /* i/o : gain_tcx_e*/ Word16 *gain_tcx_e, - Word16 *prm, + Word16 *prm, /*i*/ Word16 resQBits ); Word16 tcx_res_invQ_spec( - Word32 *x, + Word32 *x, /*Q(31 - x_e)*/ Word16 x_e, Word16 L_frame, Word16 *prm, Word16 resQBits, Word16 bits, - Word16 sq_round, - const Word16 lf_deemph_factors[] ); + Word16 sq_round, /*i : sq deadzone Q15*/ + const Word16 lf_deemph_factors[] /*i : LF deemphasis factors Q14*/ +); // er_dec_acelp_fx.c void con_acelp_fx( @@ -9413,15 +9425,15 @@ void fft_cldfb_fx( ); void stereo_dft_dec_analyze_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word32 *input_fx, /* i : input signal */ - Word32 out_DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ - const int16_t chan, /* i : channel number */ - const int16_t input_frame, /* i : input frame size */ - const int16_t output_frame, /* i : output frame size */ - const DFT_STEREO_DEC_ANA_TYPE ana_type, /* i : type of signal to analyse */ - const int16_t k_offset, /* i : offset of DFT */ - const int16_t delay, /* i : delay in samples for input signal */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word32 *input_fx, /* i : input signal q*/ + Word32 out_DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers q_out_DFT*/ + const Word16 chan, /* i : channel number Q0*/ + const Word16 input_frame, /* i : input frame size Q0*/ + const Word16 output_frame, /* i : output frame size Q0*/ + const DFT_STEREO_DEC_ANA_TYPE ana_type, /* i : type of signal to analyse */ + const Word16 k_offset, /* i : offset of DFT Q0*/ + const Word16 delay, /* i : delay in samples FOR input signal Q0*/ Word16 *q, Word16 *q_DFT ); @@ -10368,7 +10380,7 @@ Word16 lin_interp_fx( Word16 ceil_log_2( UWord64 val ); Word32 imax_pos_fx( - const Word32 *y /* i : Input vector for peak interpolation */ + const Word32 *y /* i : Input vector for peak interpolation Qx*/ ); void msvq_enc_ivas_fx( @@ -10454,24 +10466,24 @@ void v_sub32_fx( ); void ivas_swb_tbe_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation */ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ Word16 Q_exc, - const Word16 voice_factors_fx[], /* i : voicing factors */ - const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE */ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis */ - Word16 *pitch_buf_fx, + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis : old_syn_fx */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word16 *pitch_buf_fx, /* i : Q6 */ Word16 *Q_white_exc ); Word16 swb_bwe_dec_fx32( - Decoder_State *st, /* i/o: decoder state structure */ - Word32 output[], /* i : synthesis @internal Fs Q11 */ - Word32 *synth, /* i : ACELP core synthesis/final synthesis Q11 */ - Word32 *hb_synth, /* o : SHB synthesis/final synthesis */ - Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - Word16 output_frame /* i : frame length */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 output_fx[], /* i : synthesis @internal Fs : Q11 */ + Word32 *synth_fx, /* i : ACELP core synthesis/final synthesis : Q11 */ + Word32 *hb_synth_fx, /* o : SHB synthesis/final synthesis : Q_syn_hb */ + Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + Word16 output_frame /* i : frame length */ ); ivas_error acelp_core_dec_ivas_fx( diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index a496c0dd1c065d5fdd27cb99aa133c109c7761b8..9047d8338d8c940c08003b3f33066eda8f061e6c 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -26312,23 +26312,7 @@ const float lsf_q_cb_3b[8] = 0.05307309f, 0.06137543f, 0.07216742f, 0.09013262f }; -const Word16 lsf_q_cb_4b_fx[16] = -{ - 589, 773, 914, 1043, - 1173, 1302, 1430, 1558, - 1698, 1843, 1973, 2103, - 2258, 2470, 2787, 3282 - -}; - -const Word16 lsf_q_cb_3b_fx[8] = -{ - 679, 976, 1245, 1491, - 1739, 2011, 2365, 2953 -}; - const float * const lsf_q_cb[NUM_Q_LSF] = { lsf_q_cb_4b, lsf_q_cb_4b, lsf_q_cb_3b, lsf_q_cb_3b, lsf_q_cb_3b }; -const Word16 * const lsf_q_cb_fx[NUM_Q_LSF] = { lsf_q_cb_4b_fx, lsf_q_cb_4b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx }; const int16_t lsf_q_cb_size[NUM_Q_LSF] = {16, 16, 8, 8, 8}; const int16_t lsf_q_num_bits[NUM_Q_LSF] = { 4, 4, 3, 3, 3 }; @@ -26344,16 +26328,8 @@ const float lsf_grid[4][5] = { 0.14185823f, 0.26648724f, 0.39740108f, 0.55685745f, 0.74688616f }, { 0.15416561f, 0.27238427f, 0.39376780f, 0.59287916f, 0.86613986f } }; -const Word16 lsf_grid_fx[4][5] = -{ - { 5242, 10229, 15516, 21804, 27540, }, - { 5117, 10059, 14949, 20478, 25493, }, - { 4648, 8732, 13022, 18247, 24474, }, - { 5052, 8925, 12903, 19427, 28382, } -}; -const float grid_smoothing[5] = { 0.2f, 0.35f, 0.5f, 0.75f, 0.8f }; -const Word16 grid_smoothing_fx[5] = { 6554, 11469, 16384, 24576, 26214 }; +const float grid_smoothing[5] = { 0.2f, 0.35f, 0.5f, 0.75f, 0.8f }; const float allpass_poles_3_ov_2_flt[9] = { @@ -34696,7 +34672,7 @@ const float PowerCB_NB[64][2] = { 0.95166016f, 1.0351563f, }, }; -const Word16 PowerCB_WB_fx[128] = +const Word16 PowerCB_WB_fx[128] = /* Q11 */ { -3371, -1712, -170, 350, @@ -34764,7 +34740,7 @@ const Word16 PowerCB_WB_fx[128] = 1238, 2446 }; -const Word16 PowerCB_NB_fx[128] = +const Word16 PowerCB_NB_fx[128] = /* Q11 */ { -3349, -2784, -784, 385, diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 3bf5740f56c6118da1038219da3ff53b74e99ee3..993e213b38c80501c98b12914474f7f3bacc1743 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1401,8 +1401,8 @@ extern const Word16 AmpCB2_NB_fx[64 * ( NUM_ERB_NB - 13 )]; extern const float PowerCB_WB[64][2]; extern const float PowerCB_NB[64][2]; -extern const Word16 PowerCB_WB_fx[128]; -extern const Word16 PowerCB_NB_fx[128]; +extern const Word16 PowerCB_WB_fx[128]; // Q11 +extern const Word16 PowerCB_NB_fx[128]; // Q11 extern const float sinc[8][12]; extern const Word16 sinc_fx[8][12]; diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index a1465dc53241eb40588803f02f4b2bfa28a7549a..39b94b3086e6af8425fc3dfb5504bed40f7a65d3 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -6631,3 +6631,56 @@ const Word16 LP_assym_window_16k_fx[L_LP_16k] = { 0x0a40, 0x0a3d, }; + +/* 4-bit/3-bit TD SWB BWE differential LSF scalar quantizer tables */ +/*Q15*/ +const Word16 lsf_q_cb_4b_fx[16] = { + 589, 773, 914, 1043, + 1173, 1302, 1430, 1558, + 1698, 1843, 1973, 2103, + 2258, 2470, 2787, 3282 + +}; + +/*Q15*/ +const Word16 lsf_q_cb_3b_fx[8] = { + 679, 976, 1245, 1491, + 1739, 2011, 2365, 2953 +}; + +const Word16 *const lsf_q_cb_fx[NUM_Q_LSF] = { lsf_q_cb_4b_fx, lsf_q_cb_4b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx }; + +/*Q15*/ +const Word16 lsf_grid_fx[4][5] = { + { + 5242, + 10229, + 15516, + 21804, + 27540, + }, + { + 5117, + 10059, + 14949, + 20478, + 25493, + }, + { + 4648, + 8732, + 13022, + 18247, + 24474, + }, + { + 5052, + 8925, + 12903, + 19427, + 28382, + } +}; + +/*Q15*/ +const Word16 grid_smoothing_fx[5] = { 6554, 11469, 16384, 24576, 26214 }; diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index e1e609a0435d307b410d763acf5093b9d44f5c50..7cc45ae38469ac2a4318673b0ac902201c4a800f 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -54,10 +54,13 @@ struct Decoder_State; typedef struct { +#ifndef IVAS_FLOAT_FIXED float a[MAXLAG_WI]; float b[MAXLAG_WI]; - Word16 a_fx[MAXLAG_WI]; /* Q(DTFS_STRUCTURE.Q) */ - Word16 b_fx[MAXLAG_WI]; /* Q(DTFS_STRUCTURE.Q) */ +#else + Word16 a_fx[MAXLAG_WI]; /* Q(DTFS_STRUCTURE.Q) */ + Word16 b_fx[MAXLAG_WI]; /* Q(DTFS_STRUCTURE.Q) */ +#endif int16_t lag; int16_t nH; int16_t nH_4kHz; @@ -66,10 +69,13 @@ typedef struct Word16 nH_fx; Word16 nH_4kHz_fx; +#ifndef IVAS_FLOAT_FIXED float upper_cut_off_freq_of_interest; float upper_cut_off_freq; - Word16 upper_cut_off_freq_of_interest_fx; - Word16 upper_cut_off_freq_fx; +#else + Word16 upper_cut_off_freq_of_interest_fx; /* Q0 */ + Word16 upper_cut_off_freq_fx; /* Q0 */ +#endif int32_t sampling_rate; Word16 Fs_fx; Word16 Q; @@ -196,12 +202,13 @@ typedef struct TNS_filter_structure int16_t spectrumLength; /* Number of subbands covered by the filter. */ int16_t order; /* Filter order. */ int16_t coefIndex[TNS_MAX_FILTER_ORDER]; /* Quantized filter coefficients. */ - float predictionGain_flt; /* Prediction gain. The ratio of a signal and TNS residual energy. */ - float avgSqrCoef_flt; /* Average squared filter coefficient. */ - /** Prediction gain. The ratio of a signal and TNS residual energy. */ - Word16 predictionGain; /* exponent = PRED_GAIN_E */ - /** Average squared filter coefficient. */ - Word16 avgSqrCoef; /* exponent = 0 */ +#ifndef IVAS_FLOAT_FIXED + float predictionGain_flt; /* Prediction gain. The ratio of a signal and TNS residual energy. */ + float avgSqrCoef_flt; /* Average squared filter coefficient. */ +#else + Word16 predictionGain; /* Prediction gain. The ratio of a signal and TNS residual energy. E(PRED_GAIN_E), Q7 */ + Word16 avgSqrCoef; /* Average squared filter coefficient. E(0), Q15 */ +#endif } STnsFilter; typedef struct /* TNS data describing all active filters. */ @@ -304,8 +311,11 @@ typedef struct TCX_config_structure STnsConfig const *pCurrentTnsConfig; /*Quantization*/ - float sq_rounding_flt; /*set the sq deadzone (no deadzone=0.5f)*/ - Word16 sq_rounding; /*set the sq deadzone (no deadzone=0.5f)*/ +#ifndef IVAS_FLOAT_FIXED + float sq_rounding_flt; /* set the sq deadzone (no deadzone=0.5f) */ +#else + Word16 sq_rounding; /* set the sq deadzone (no deadzone=0.5f) Q15 */ +#endif int16_t tcxRateLoopOpt; /*Bandwidth*/ @@ -319,12 +329,17 @@ typedef struct TCX_config_structure int16_t resq; /* Flag for enabling Residual Quantization */ int16_t coder_type; /* GC,VC,UC */ +#ifndef IVAS_FLOAT_FIXED float na_scale_flt; +#else + Word16 na_scale; /* Q15 */ +#endif +#ifndef IVAS_FLOAT_FIXED float SFM2_flt; - Word16 na_scale; - - Word32 SFM2; +#else + Word32 SFM2; /* Q31 */ +#endif /* Psychoacoustic parameters for LPC in TCX */ PsychoacousticParameters psychParamsTCX10; @@ -372,8 +387,8 @@ typedef struct int32_t bitrateTo; float scale_flt; - Word16 scale; /* EVS implementation */ - Word16 scale_ivas; /* IVAS implementation */ + Word16 scale; /* EVS implementation Q14 */ + Word16 scale_ivas; /* IVAS implementation Q14 */ } SCALE_SETUP; @@ -436,14 +451,17 @@ typedef struct float init_old_flt; Word16 init_old; - int16_t msFrCnt; /* Frame counter */ + int16_t msFrCnt; /* Frame counter */ +#ifndef IVAS_FLOAT_FIXED float msAlphaCor_flt[2]; /* Correction factor (smoothed) */ float msSlope_flt[2]; float msQeqInvAv_flt[2]; - Word32 msAlphaCor[2]; /* Correction factor (smoothed) */ - Word16 msSlope[2]; +#else + Word32 msAlphaCor[2]; /* Correction factor (smoothed) Q31 */ + Word16 msSlope[2]; /* Q14 */ Word32 msQeqInvAv[2]; Word16 msQeqInvAv_exp[2]; +#endif int16_t msMinBufferPtr; float msPsdSum_flt[2]; @@ -519,9 +537,12 @@ typedef struct #endif Word16 likelihood_noisy_speech; - float coherence_flt; /* inter-channel coherence of noise */ - Word16 coherence_fx; /* inter-channel coherence of noise */ /* Q15 */ - int16_t no_side_flag; /* indicates whether the side noise shape should be zeroed-out or not */ +#ifndef IVAS_FLOAT_FIXED + float coherence_flt; /* inter-channel coherence of noise */ +#else + Word16 coherence_fx; /* inter-channel coherence of noise Q15 */ +#endif + int16_t no_side_flag; /* indicates whether the side noise shape should be zeroed-out or not */ } FD_CNG_COM, *HANDLE_FD_CNG_COM; @@ -675,7 +696,7 @@ typedef struct int32_t bitrateTo; float scale_flt; - Word16 scale; + Word16 scale; /* Q15 */ } SCALE_TCX_SETUP; @@ -783,7 +804,6 @@ typedef struct cldfb_filter_bank_struct float scale_flt; /* scaling of frequency domain */ Word16 scale; /* scaling of frequency domain */ /* Q8 */ - Word16 q_scale; } CLDFB_FILTER_BANK, *HANDLE_CLDFB_FILTER_BANK; diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 0025812db446db36ad216c3c9af78c3a79558b5a..d56f1b78492c6673943ec37aac7463f606da4145 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -3005,7 +3005,8 @@ void hq_generic_decoding_fx( { FOR( tmp3_fx = 5120; tmp3_fx > 1024; tmp3_fx -= 512 ) { - L_tmp1 = L_shl( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */ + /* Adding saturation suggested as fix for issue #957 */ + L_tmp1 = L_shl_sat( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */ *pit1_fx-- = L_tmp1; move32(); } diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index f70b82875fb8065c886fedb329f2fdb32100b3d2..edc0a1e7d74da3b7db59b6c28751530987d04982 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -2830,6 +2830,7 @@ void GenShapedSHBExcitation_ivas_fx( Word16 voiceFacEst[NB_SUBFR16k]; Word16 zero_mem[LPC_SHB_ORDER]; Word32 syn_shb_ener_sf[4]; + Word16 syn_shb_ener_sf_q[4]; Word16 tempSHB[80]; Word16 Q_pow1, Q_pow22; @@ -2863,7 +2864,6 @@ void GenShapedSHBExcitation_ivas_fx( #endif set16_fx( zero_mem, 0, LPC_SHB_ORDER ); set16_fx( wht_fil_mem, 0, LPC_WHTN_ORDER ); - FOR( i = 0; i < L_FRAME32k; i = i + 2 ) { exc32k[i] = negate( bwe_exc_extended[i] ); // Q_bwe_exc @@ -3036,7 +3036,11 @@ void GenShapedSHBExcitation_ivas_fx( White_exc16k = exc16k; move16(); - Word16 Q_excTmp2 = sub( add( s_min( getScaleFactor16( excTmp2, L_FRAME16k ), norm_l( *mem_csfilt ) ), *Q_bwe_exc ), 1 ); + Word16 Q_excTmp2 = add( getScaleFactor16( excTmp2, L_FRAME16k ), *Q_bwe_exc ); + IF( *mem_csfilt ) + { + Q_excTmp2 = s_min( Q_excTmp2, sub( add( norm_l( *mem_csfilt ), *Q_bwe_exc ), 1 ) ); + } test(); /* Track the low band envelope */ IF( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT ) @@ -3148,8 +3152,8 @@ void GenShapedSHBExcitation_ivas_fx( tmp = add( *Q_bwe_exc, 1 ); FOR( k = 0; k < L_FRAME16k; k++ ) { - L_tmp4 = L_mult( shr( excNoisyEnv[k], sub( Q_excTmp2, *Q_bwe_exc ) ), White_exc16k[k] ); /* (Q_excTmp2) +5 +1*/ - White_exc16k_32[k] = L_tmp4; /* (Q_excTmp2) +5 +1*/ + L_tmp4 = L_mult( excNoisyEnv[k], White_exc16k[k] ); /* (Q_excTmp2) +5 +1*/ + White_exc16k_32[k] = L_tmp4; /* (Q_excTmp2) +5 +1*/ move32(); L_tmp = L_max( L_tmp, L_abs( White_exc16k_32[k] ) ); } @@ -3166,11 +3170,10 @@ void GenShapedSHBExcitation_ivas_fx( /* pow22=0.00001f */ tmp = sub( shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ), 31 ); pow22 = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(*Q_bwe_exc-NOISE_QADJ) */ - tmp = sub( NOISE_QFAC, 5 ); FOR( k = 0; k < L_FRAME16k; k++ ) { /* White_exc16k[k] *= excNoisyEnv[k]; */ - White_exc16k[k] = mult_r( excNoisyEnv[k], shl( White_exc16k[k], tmp ) ); // Q_excTmp2 + 5 + 1 - 15 ==> Q_excTmp2 - 9 + White_exc16k[k] = mult_r( excNoisyEnv[k], shl( White_exc16k[k], 1 ) ); // Q_excTmp2 + 5 + 1 - 15 ==> Q_excTmp2 - 9 move16(); chk2 = s_or( chk2, White_exc16k[k] ); /* i: excNoisyEnv in (Q_excTmp2) */ @@ -3178,7 +3181,7 @@ void GenShapedSHBExcitation_ivas_fx( /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ) */ /* pow22 += White_exc16k[k] * White_exc16k[k]; */ #ifdef BASOP_NOGLOB - pow22 = L_mac0_sat( pow22, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ + pow22 = L_mac0_sat( pow22, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_excTmp2-NOISE_QADJ)*/ #else pow22 = L_mac0( pow22, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ #endif @@ -3504,6 +3507,7 @@ void GenShapedSHBExcitation_ivas_fx( deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); /* i/o: White_exc16k (Q_bwe_exc-NOISE_QADJ) */ /* i: tbe_demph (Q_bwe_exc-NOISE_QADJ) */ + #if 1 // def ADD_IVAS_TBE_CODE test(); IF( EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) ) @@ -3644,7 +3648,7 @@ void GenShapedSHBExcitation_ivas_fx( tempQ15 = mult_r( SWB_NOISE_MIX_FAC_FX, formant_fac ); /* vf_tmp = voice_factors[i] * (1.0f - vf_tmp); */ vf_tmp = sub( MAX_16, tempQ15 ); - vf_tmp = mult_r( voice_factors[i], vf_tmp ); + vf_tmp = mult( voice_factors[i], vf_tmp ); exp = 0; move16(); @@ -3711,31 +3715,56 @@ void GenShapedSHBExcitation_ivas_fx( set16_fx( zero_mem, 0, LPC_SHB_ORDER ); Syn_filt_s( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, tempSHB, 80, zero_mem, 1 ); + tmp = sub( getScaleFactor16( tempSHB, 80 ), 2 ); + Scale_sig( tempSHB, 80, tmp ); syn_shb_ener_sf[0] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); move32(); + syn_shb_ener_sf_q[0] = add( shl( add( *Q_bwe_exc, tmp ), 1 ), 1 ); + move16(); Syn_filt_s( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, tempSHB, 80, zero_mem, 1 ); + tmp = sub( getScaleFactor16( tempSHB, 80 ), 2 ); + Scale_sig( tempSHB, 80, tmp ); syn_shb_ener_sf[1] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); move32(); + syn_shb_ener_sf_q[1] = add( shl( add( *Q_bwe_exc, tmp ), 1 ), 1 ); + move16(); Syn_filt_s( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, tempSHB, 80, zero_mem, 1 ); + tmp = sub( getScaleFactor16( tempSHB, 80 ), 2 ); + Scale_sig( tempSHB, 80, tmp ); syn_shb_ener_sf[2] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); move32(); + syn_shb_ener_sf_q[2] = add( shl( add( *Q_bwe_exc, tmp ), 1 ), 1 ); + move16(); Syn_filt_s( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, tempSHB, 80, zero_mem, 1 ); + tmp = sub( getScaleFactor16( tempSHB, 80 ), 2 ); + Scale_sig( tempSHB, 80, tmp ); syn_shb_ener_sf[3] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); move32(); + syn_shb_ener_sf_q[3] = add( shl( add( *Q_bwe_exc, tmp ), 1 ), 1 ); + move16(); + + tmp2 = s_min( s_min( syn_shb_ener_sf_q[0], syn_shb_ener_sf_q[1] ), s_min( syn_shb_ener_sf_q[3], syn_shb_ener_sf_q[2] ) ); + syn_shb_ener_sf[0] = L_shl( syn_shb_ener_sf[0], sub( tmp2, syn_shb_ener_sf_q[0] ) ); + move32(); + syn_shb_ener_sf[1] = L_shl( syn_shb_ener_sf[1], sub( tmp2, syn_shb_ener_sf_q[1] ) ); + move32(); + syn_shb_ener_sf[2] = L_shl( syn_shb_ener_sf[2], sub( tmp2, syn_shb_ener_sf_q[2] ) ); + move32(); + syn_shb_ener_sf[3] = L_shl( syn_shb_ener_sf[3], sub( tmp2, syn_shb_ener_sf_q[3] ) ); + move32(); /* i: exc16kWhtnd in Q_bwe_exc */ /* o: tempSHB in Q_bwe_exc */ - /* o: syn_shb_ener_sf in (2*Q_bwe_exc+1) */ + /* o: syn_shb_ener_sf in tmp2 */ IF( LE_32( bitrate, MAX_ACELP_BRATE ) ) { L_tmp = sum32_fx( syn_shb_ener_sf, 4 ); /* find root_a(tempSHB[0]) = root_a_over_b(shb_ener_sf[0]), L_tmp) */ tmp = shl( Q_shb, 1 ); - tmp2 = add( shl( *Q_bwe_exc, 1 ), 1 ); L_tmp2 = root_a_over_b_fx( shb_ener_sf_32, tmp, L_tmp, tmp2, &exp ); /* L_tmp2 in (Q31-exp) */ *Q_bwe_exc = sub( *Q_bwe_exc, exp ); diff --git a/lib_com/tcq_position_arith_fx.c b/lib_com/tcq_position_arith_fx.c index f72017940ab3d22b8ee594db9543cee5d529f8ff..fdac07f5633693e0705bfd7e2ed3aca01c6cba16 100644 --- a/lib_com/tcq_position_arith_fx.c +++ b/lib_com/tcq_position_arith_fx.c @@ -1739,7 +1739,7 @@ Word32 encode_position_ari_fx( /* Estimate TCQ bits */ bits_fx = L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[add( sub( size, nz ), 1 )] ) ); bits_fx = L_add( bits_fx, L_sub( btcq_fx, L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[add( sub( size, nz ), 1 )] ) ) ) ); - bits_fx = L_sub( bits_fx, L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[nz], table_logcum_fx[add( pulses, sub( nz, 1 ) )] ) ) ); + bits_fx = L_sub( bits_fx, L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[nz], table_logcum_fx[pulses - ( nz - 1 )] ) ) ); bits_fx = L_sub( bits_fx, nz ); *est_bits_frame_fx = L_add( *est_bits_frame_fx, bits_fx ); move32(); diff --git a/lib_com/tns_base.c b/lib_com/tns_base.c index e0fd2308244015abb52f232292b8a6bb86a17d66..2f37fb102e1445370d3330ceabeacc91c58f1918 100644 --- a/lib_com/tns_base.c +++ b/lib_com/tns_base.c @@ -1139,10 +1139,8 @@ void ResetTnsData( STnsData *pTnsData ) move16(); pTnsFilter->avgSqrCoef = 0; move16(); - /* TODO: remove float _flt dependencies */ - pTnsFilter->predictionGain_flt = 1.0f; - pTnsFilter->avgSqrCoef_flt = 0; pTnsFilter->filterType = TNS_FILTER_OFF; + move16(); ClearTnsFilterCoefficients( pTnsFilter ); } } diff --git a/lib_com/tns_base_flt.c b/lib_com/tns_base_flt.c index 169dc27e7978da127b0ef409f0d092d8172781f4..ed5d948dc8566dd0f0cb5d59379bc32764ad168a 100644 --- a/lib_com/tns_base_flt.c +++ b/lib_com/tns_base_flt.c @@ -477,6 +477,7 @@ void *SetTnsOnWhite( void *p, const int16_t index, const int16_t value ) // } +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * ResetTnsData() * @@ -517,6 +518,7 @@ void ClearTnsFilterCoefficients_flt( return; } +#endif /** Inverse quantization for reflection coefficients. * diff --git a/lib_com/tools.c b/lib_com/tools.c index 0222d6cc48fb0dcb8a476cda512b765fddb44f7a..072cfa7675260ea29e822eec3f6ee3e5442e5215 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -1101,9 +1101,9 @@ float dotp( /*! r: dot product of x[] and y[] */ Word32 dotp_fixed( - const Word32 x[], /* i : vector x[] */ - const Word32 y[], /* i : vector y[] */ - const Word16 n /* i : vector length */ + const Word32 x[], /* i : vector x[] Qx */ + const Word32 y[], /* i : vector y[] Qy */ + const Word16 n /* i : vector length */ ) { Word16 i; diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 52f8b01afd569fece19b7fbc9509167f4db4bf76..3580e632ea0638c851298082ddb25b1c99700c5b 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -93,6 +93,8 @@ Word16 float_to_fix16( float number, Word16 Q ) return 0; if ( number == 1.0f && Q == Q15 ) return MAX16B; + if ( number == -1.0f && Q == Q15 ) + return MIN16B; assert( fabs( number ) < pow( 2, 15 - Q ) ); Word16 ret = (Word16) ( number * ( (UWord16) 1 << Q ) ); return ret; @@ -4461,7 +4463,23 @@ void set_zero_fx( return; } +#ifdef FIX_930_JBM_BUFSIZE_MULT +void set_zero2_fx( + Word32 *vec, /* o : input vector */ + const Word32 lvec /* i : length of the vector */ +) +{ + Word32 i; + FOR( i = 0; i < lvec; i++ ) + { + *vec++ = 0; + move32(); + } + + return; +} +#endif void set16_zero_fx( Word16 *vec, /* o : input vector */ const Word16 lvec /* i : length of the vector */ diff --git a/lib_com/wi.c b/lib_com/wi.c index 4467606e8b0f58825741588d08dda16f164ec63a..f128a3012d0f6d9d818838d844aac94c6b45a254 100644 --- a/lib_com/wi.c +++ b/lib_com/wi.c @@ -42,6 +42,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ @@ -2293,3 +2294,4 @@ ivas_error WIsyn( return error; } +#endif diff --git a/lib_com/window_ola_fx.c b/lib_com/window_ola_fx.c index 938ee92fb50b18396581e84a36f9e114be54b7bc..7dd0f2a79164d6a5f60be97f2b1c80aedc14a436 100644 --- a/lib_com/window_ola_fx.c +++ b/lib_com/window_ola_fx.c @@ -320,6 +320,7 @@ void window_ola_fx( p3--; p4++; } + Copy_Scale_sig( oldgapsynth, oldgapsynth, L, -( *Q_sig ) ); } ELSE { diff --git a/lib_dec/ACcontextMapping_dec.c b/lib_dec/ACcontextMapping_dec.c index 952303ce872c0a8dc0e816c18bb8238bcc536d4f..470e11e64bbbe940415e30fd4d2ebb2f2a8e2afc 100644 --- a/lib_dec/ACcontextMapping_dec.c +++ b/lib_dec/ACcontextMapping_dec.c @@ -44,6 +44,7 @@ #include "ivas_prot.h" /* Range coder header file */ #include +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * ACcontextMapping_decode2_no_mem_s17_LC_ivas() * @@ -51,7 +52,6 @@ *-------------------------------------------------------------------*/ /*! r: resQBits */ -#ifndef IVAS_FLOAT_FIXED int16_t ACcontextMapping_decode2_no_mem_s17_LC_ivas( Decoder_State *st, /* i/o: decoder state */ int16_t *x, /* o : decoded spectrum */ @@ -319,7 +319,7 @@ int16_t ACcontextMapping_decode2_no_mem_s17_LC_ivas( return resQBits; } -#endif + /*-------------------------------------------------------------------* * RCcontextMapping_decode2_no_mem_s17_LCS() @@ -328,7 +328,7 @@ int16_t ACcontextMapping_decode2_no_mem_s17_LC_ivas( *-------------------------------------------------------------------*/ /*! r: resQBits */ -#ifndef IVAS_FLOAT_FIXED + int16_t RCcontextMapping_decode2_no_mem_s17_LCS( Decoder_State *st, /* i/o: decoder state */ int16_t *x, /* o : decoded spectrum */ diff --git a/lib_dec/ACcontextMapping_dec_fx.c b/lib_dec/ACcontextMapping_dec_fx.c index 89a7e1890f55c31ed324af8bbff5a60afc212bd1..df1ae4cc826cb71172ee53c79936b8317fb5189a 100644 --- a/lib_dec/ACcontextMapping_dec_fx.c +++ b/lib_dec/ACcontextMapping_dec_fx.c @@ -22,7 +22,7 @@ #ifdef IVAS_FLOAT_FIXED Word16 ACcontextMapping_decode2_no_mem_s17_LC( Decoder_State *st, /* i/o: decoder state */ - Word16 *x, /* o: decoded spectrum */ + Word16 *x, /* o: decoded spectrum Q0*/ Word16 nt, /* i: size of spectrum */ Word16 nbbits, /* i: bit budget */ Word16 resQMaxBits, /* i: residual coding maximum bits*/ @@ -40,6 +40,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( Word16 resQBits; Word16 rest_bits, rest_bits_overflow; Word16 tmp = 0; /* initialize just to avoid compiler warning */ + move16(); Word16 nt_half; Word16 c[2], *ctx; Word16 p1, p2; @@ -59,7 +60,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( /* Rate flag */ rateFlag = 0; move16(); - IF( GT_16( nbbits, 400 ) ) + if ( GT_16( nbbits, 400 ) ) { rateFlag = 2 << NBITS_CONTEXT; move16(); @@ -86,7 +87,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( move16(); lastnz = shl( n, 1 ); - + test(); IF( GT_16( lastnz, nt ) || st->BER_detect ) { st->BER_detect = 1; @@ -118,7 +119,6 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( move16(); get_next_coeff = get_next_coeff_mapped; - move16(); } ELSE /* unmapped domain */ { @@ -130,7 +130,6 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( move16(); get_next_coeff = get_next_coeff_unmapped; - move16(); } /* Start Decoding */ @@ -174,10 +173,10 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( La = L_deposit_l( 0 ); Lb = L_deposit_l( 0 ); /* MSBs decoding */ - test(); + FOR( lev = 0; lev < 15 && lsbs_bit_pos > 0; lev++ ) { - test(); + esc_nb = s_min( lev, 3 ); tmp = add( t, Tab_esc_nb[esc_nb] ); assert( tmp >= 0 && tmp < 4096 ); @@ -217,11 +216,11 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( /*lsbs bits sign bits*/ rest_bits = add( rest_bits, shl( lev, 1 ) ); - IF( a > 0 ) + if ( a > 0 ) { rest_bits = add( rest_bits, 1 ); } - IF( b > 0 ) + if ( b > 0 ) { rest_bits = add( rest_bits, 1 ); } @@ -293,12 +292,12 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( } /*Decode signs*/ - IF( hm_cfg ) + if ( hm_cfg ) { tmp = nt; move16(); } - IF( !hm_cfg ) + if ( !hm_cfg ) { tmp = lastnz; move16(); @@ -344,7 +343,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( /*! r: resQBits */ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( Decoder_State *st, /* i/o: decoder state */ - Word16 *x, /* o : decoded spectrum */ + Word16 *x, /* o : decoded spectrum Q0*/ const Word16 nt, /* i : size of spectrum */ const Word16 nbbits, /* i : bit budget */ const Word16 resQMaxBits, /* i : residual coding maximum bits */ @@ -376,7 +375,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( k = 1; move16(); nt_half = shr( nt, 1 ); - WHILE( LT_16( k, nt_half ) ) + WHILE( k < nt_half ) { n = add( n, 1 ); k = shl( k, 1 ); @@ -390,7 +389,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( move16(); lastnz = shl( n, 1 ); - if ( GT_16( lastnz, nt ) ) + IF( GT_16( lastnz, nt ) ) { st->BER_detect = 1; move16(); @@ -463,7 +462,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( t = add( *ctx, rateFlag ); IF( LT_16( nt_half, idx ) ) { - t = add( t, shl( 1, NBITS_CONTEXT ) ); + t = add( t, ( 1 << NBITS_CONTEXT ) ); } esc_nb = 0; @@ -486,7 +485,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( FOR( lev = 0; lev < 15 && lsbs_bit_pos > 0; ++lev ) { esc_nb = s_min( lev, 3 ); - pki = ari_lookup_s17_LC[add( t, Tab_esc_nb[esc_nb] )]; + pki = ari_lookup_s17_LC[t + Tab_esc_nb[esc_nb]]; move16(); r = rc_uni_dec_read_symbol_fastS_fx( &rc_st_dec, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 17, 14 ); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */ /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */ @@ -645,7 +644,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( FOR( lev = 0; lev < 15 && lsbs_bit_pos > 0; ++lev ) { esc_nb = s_min( lev, 3 ); - pki = ari_lookup_s17_LC[add( t, add( shl( ( rateQ ), NBITS_CONTEXT ), Tab_esc_nb[esc_nb] ) )]; + pki = ari_lookup_s17_LC[t + ( ( rateQ << NBITS_CONTEXT ) + Tab_esc_nb[esc_nb] )]; move16(); r = rc_uni_dec_read_symbol_fastS_fx( &rc_st_dec, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 17, 14 ); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */ /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */ diff --git a/lib_dec/FEC.c b/lib_dec/FEC.c index 3f19f35eb7712783a6ea6e7ae50ca90a3d4d5e70..dc36007289920ef9bfaf557139f16ed2f0eb789f 100644 --- a/lib_dec/FEC.c +++ b/lib_dec/FEC.c @@ -43,24 +43,20 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void gain_dec_bfi( float *past_qua_en ); -#endif - -#ifndef IVAS_FLOAT_FIXED static void pulseRes_preCalc( Word16 *cond1, Word16 *cond2, Word32 *cond3, Word16 new_pit, Word16 Tc, Word16 L_frame ); -#endif /*-------------------------------------------------------------------* * FEC_exc_estim() * * Calculation of excitation signal *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void FEC_exc_estim( Decoder_State *st, /* i/o: Decoder static memory */ const int16_t L_frame, /* i : length of the frame */ @@ -482,7 +478,6 @@ void FEC_exc_estim( return; } -#endif /*-------------------------------------------------------------------* @@ -492,7 +487,7 @@ void FEC_exc_estim( * next frame *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void gain_dec_bfi( float *past_qua_en /* i/o: gain quantization memory (4 words) */ ) @@ -522,9 +517,13 @@ static void gain_dec_bfi( return; } -#endif +/*-------------------------------------------------------------------* + * Local function prototypes + *-------------------------------------------------------------------*/ +#endif + #define WMC_TOOL_SKIP /*-------------------------------------------------------------------* * pulseRes_preCalc() diff --git a/lib_dec/FEC_HQ_core.c b/lib_dec/FEC_HQ_core.c index 17fe13469f79f9f2b974cf23dc4365c003f8b7ee..e9695a9efc0c2fa649b8c03af983f748d5a659ce 100644 --- a/lib_dec/FEC_HQ_core.c +++ b/lib_dec/FEC_HQ_core.c @@ -1550,17 +1550,15 @@ void save_synthesis_hq_fec_fx( { case EVS_MONO: post_hq_delay = NS2SA_FX2( st->output_Fs, POST_HQ_DELAY_NS ); - move16(); BREAK; case IVAS_SCE: post_hq_delay = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); - move16(); BREAK; case IVAS_CPE_DFT: + test(); IF( EQ_16( hCPE->nchan_out, 1 ) && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) { post_hq_delay = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); - move16(); } ELSE { @@ -1579,13 +1577,13 @@ void save_synthesis_hq_fec_fx( test(); test(); test(); - IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) + IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) { Copy( st->hTcxDec->synth_history_fx + output_frame, st->hTcxDec->synth_history_fx, add( sub( output_frame, post_hq_delay ), NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ) ); FOR( Word16 i = 0; i < output_frame; i++ ) { #ifdef FIX_856_EXTRACT_L - st->hTcxDec->old_synthFB_fx[sub( add( i, output_frame ), post_hq_delay )] = extract_h( L_shl_sat( output_fx[i], 16 ) ); + st->hTcxDec->old_synthFB_fx[( ( i + output_frame ) - post_hq_delay )] = extract_h( L_shl_sat( output_fx[i], 16 ) ); // Q16 #else st->hTcxDec->old_synthFB_fx[sub( add( i, output_frame ), post_hq_delay )] = extract_l( output_fx[i] ); #endif diff --git a/lib_dec/FEC_HQ_phase_ecu.c b/lib_dec/FEC_HQ_phase_ecu.c index 3ab4ca0ef1219d61f6cb5c8505df8faa9f3ece0c..7a46d308bb0d8a16a11cc81c1ffec0305246bb8f 100644 --- a/lib_dec/FEC_HQ_phase_ecu.c +++ b/lib_dec/FEC_HQ_phase_ecu.c @@ -43,6 +43,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * Local constants *---------------------------------------------------------------------*/ @@ -98,10 +99,8 @@ * Local functions *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static int16_t rand_phase( const int16_t seed, float *sin_F, float *cos_F ); static float imax2_jacobsen_mag( const float *y_re, const float *y_im ); -#endif /*-------------------------------------------------------------------* * mult_rev2() @@ -109,7 +108,7 @@ static float imax2_jacobsen_mag( const float *y_re, const float *y_im ); * Multiplication of two vectors second vector is multiplied in reverse order *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void mult_rev2( const float x1[], /* i : Input vector 1 */ const float x2[], /* i : Input vector 2 */ @@ -126,7 +125,6 @@ static void mult_rev2( return; } -#endif /*-------------------------------------------------------------------* @@ -135,7 +133,6 @@ static void mult_rev2( * Square magnitude of fft spectrum *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void fft_spec2( float x[], /* i/o: Input vector: complex spectrum -> square magnitude spectrum */ const int16_t N /* i : Vector length */ @@ -153,7 +150,7 @@ static void fft_spec2( return; } -#endif + /*------------------------------------------------------------------* * rand_phase() @@ -161,7 +158,6 @@ static void fft_spec2( * randomized phase in form of sin and cos components *------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED /*! r: Updated seed from RNG */ static int16_t rand_phase( const int16_t seed, /* i : RNG seed */ @@ -193,7 +189,7 @@ static int16_t rand_phase( return seed2; } -#endif + /*----------------------------------------------------------------------------- * imax2_jacobsen_mag() @@ -262,7 +258,6 @@ float imax2_jacobsen_mag( return posi; } -#endif /*------------------------------------------------------------------* @@ -271,7 +266,7 @@ float imax2_jacobsen_mag( * Transient analysis *------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void trans_ana( const float *xfp, /* i : Input signal */ float *mag_chg, /* i/o: Magnitude modification */ @@ -453,7 +448,6 @@ static void trans_ana( return; } -#endif /*------------------------------------------------------------------* @@ -462,7 +456,6 @@ static void trans_ana( * Peak-picking algorithm *------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void peakfinder( const float *x0, /* i : vector from which the maxima will be found */ const int16_t len0, /* i : length of input vector */ @@ -659,7 +652,7 @@ void peakfinder( return; } -#endif + /*-------------------------------------------------------------------* * imax_pos() @@ -668,7 +661,6 @@ void peakfinder( *-------------------------------------------------------------------*/ /*! r: interpolated maximum position */ -#ifndef IVAS_FLOAT_FIXED float imax_pos( const float *y /* i : Input vector for peak interpolation */ ) @@ -710,7 +702,7 @@ float imax_pos( return posi + 1.0f; } -#endif + /*-------------------------------------------------------------------* * spec_ana() @@ -718,7 +710,6 @@ float imax_pos( * Spectral analysis *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void spec_ana( const float *prevsynth, /* i : Input signal */ int16_t *plocs, /* o : The indicies of the identified peaks */ @@ -956,7 +947,7 @@ static void spec_ana( return; } -#endif + /*-------------------------------------------------------------------* * subst_spec() @@ -964,7 +955,6 @@ static void spec_ana( * Substitution spectrum calculation *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void subst_spec( const int16_t *plocs, /* i : The indicies of the identified peaks */ const float *plocsi, /* i : Interpolated positions of the identified peaks */ @@ -1278,7 +1268,7 @@ static void subst_spec( return; } -#endif + /*-------------------------------------------------------------------------- * rec_wtda() @@ -1286,7 +1276,6 @@ static void subst_spec( * Windowing and TDA of reconstructed frame *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void rec_wtda( float *X, /* i/o: ECU frame / unwindowed ECU frame */ float *ecu_rec, /* o : Reconstructed frame in tda domain */ @@ -1395,7 +1384,6 @@ static void rec_wtda( return; } -#endif /*-------------------------------------------------------------------------- @@ -1404,7 +1392,6 @@ static void rec_wtda( * Frame reconstruction *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void rec_frame( float *X, /* i/o: FFT spectrum / IFFT of spectrum */ float *ecu_rec, /* o : Reconstructed frame in tda domain */ @@ -1446,7 +1433,6 @@ static void rec_frame( return; } -#endif /*-------------------------------------------------------------------------- @@ -1455,7 +1441,6 @@ static void rec_frame( * FIR downsampling filter *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void fir_dwn( const float x[], /* i : input vector */ const float h[], /* i : impulse response of the FIR filter */ @@ -1508,7 +1493,6 @@ static void fir_dwn( return; } -#endif /*-------------------------------------------------------------------------- @@ -1517,7 +1501,6 @@ static void fir_dwn( * Pitch/correlation analysis and adaptive analysis frame length calculation *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void fec_ecu_pitch( const float *prevsynth, /* i : previous synthesis */ float *prevsynth_LP, /* o : down-sampled synthesis */ @@ -1643,7 +1626,6 @@ static void fec_ecu_pitch( return; } -#endif /*-------------------------------------------------------------------------- @@ -1653,7 +1635,6 @@ static void fec_ecu_pitch( * next power of 2 using linear interpolation. *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void fec_ecu_dft( const float *prevsynth_LP, /* i : Downsampled past synthesis (2*160 samples) */ const int16_t N, /* i : Analysis frame length in 8 kHz (corr. max) */ @@ -1719,7 +1700,6 @@ static void fec_ecu_dft( * fast cosinus generator Amp*cos(2*pi*freq+phi) *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void singenerator( const int16_t L, /* i : size of output */ const float cosfreq, /* i : cosine of 1-sample dephasing at the given frequency */ @@ -1769,7 +1749,6 @@ static void singenerator( return; } -#endif /*-------------------------------------------------------------------------- @@ -1778,7 +1757,6 @@ static void singenerator( * ECU frame sinusoid generation *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void sinusoidal_synthesis( const float *Tfr, /* i : DFT coefficients, real part */ const float *Tfi, /* i : DFT coefficients, imag part */ @@ -1902,7 +1880,6 @@ static void sinusoidal_synthesis( return; } -#endif /*-------------------------------------------------------------------------- * fec_noise_filling() @@ -1915,7 +1892,6 @@ static void sinusoidal_synthesis( * it to be inserted into wtda *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void fec_noise_filling( const float *prevsynth, /* i : Past synthesis buffer (length 2*L) */ float *synthesis, /* i/o: Sinusoidal ECU / Sinusoidal ECU + noise */ @@ -2031,7 +2007,6 @@ static void fec_noise_filling( return; } -#endif /*-------------------------------------------------------------------------- * fec_alg() @@ -2040,7 +2015,6 @@ static void fec_noise_filling( * length *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void fec_alg( const float *prevsynth, /* i : previous synthesis */ const float *prevsynth_LP, /* i : down-sampled synthesis */ @@ -2074,7 +2048,6 @@ static void fec_alg( return; } -#endif /*-------------------------------------------------------------------------- @@ -2083,7 +2056,6 @@ static void fec_alg( * Main routine for HQ phase ECU *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void hq_phase_ecu( const float *prevsynth, /* i : buffer of previously synthesized signal */ float *ecu_rec, /* o : reconstructed frame in tda domain */ @@ -2175,9 +2147,7 @@ static void hq_phase_ecu( return; } -#endif -#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------- * hq_ecu() * diff --git a/lib_dec/FEC_lsf_estim_fx.c b/lib_dec/FEC_lsf_estim_fx.c index 730014f0de6a7a3765cec2cf4ec7b1004cd50e5c..90140911d4ab7d15fe9d5e96ed5534391204c22e 100644 --- a/lib_dec/FEC_lsf_estim_fx.c +++ b/lib_dec/FEC_lsf_estim_fx.c @@ -17,11 +17,11 @@ *-------------------------------------------------------------------*/ void FEC_lsf2lsp_interp( - Decoder_State *st, /* i/o: Decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *Aq, /* o : calculated A(z) for 4 subframes */ - Word16 *lsf, /* o : estimated LSF vector */ - Word16 *lsp /* o : estimated LSP vector */ + Decoder_State *st, /* i/o: Decoder static memory */ + const Word16 L_frame, /* i : length of the frame */ + Word16 *Aq, /* o : calculated A(z) for 4 subframes Q12 */ + Word16 *lsf, /* o : estimated LSF vector Qlog2(2.56)*/ + Word16 *lsp /* o : estimated LSP vector Q15* */ ) { diff --git a/lib_dec/FEC_pitch_estim_fx.c b/lib_dec/FEC_pitch_estim_fx.c index 36fec6a4a69dfa380edb2b5d2f7d450a285f6276..012057a9ddb8c8af6f6a2038876943048be9257c 100644 --- a/lib_dec/FEC_pitch_estim_fx.c +++ b/lib_dec/FEC_pitch_estim_fx.c @@ -41,9 +41,9 @@ void FEC_pitch_estim_fx( const Word16 L_frame, /* i : length of the frame */ const Word16 clas, /* i : current frame classification */ const Word16 last_good, /* i : last good clas information */ - const Word16 pitch_buf[], /* i : Floating pitch for each subframe */ + const Word16 pitch_buf[], /* i : Floating pitch for each subframe Q6 */ const Word32 old_pitch_buf[], /* i : buffer of old subframe pitch values 15Q16 */ - Word16 *bfi_pitch, /* i/o: update of the estimated pitch for FEC */ + Word16 *bfi_pitch, /* i/o: update of the estimated pitch for FEC Q6*/ Word16 *bfi_pitch_frame, /* o : frame length when pitch was updated */ Word16 *upd_cnt /* i/o: update counter */ , diff --git a/lib_dec/LD_music_post_filter.c b/lib_dec/LD_music_post_filter.c index e3817e69f4bb687b3bce4daca2a813c84d789f8d..dfdd586b44ec5714a2c7c3c0f0b1401282d9a28c 100644 --- a/lib_dec/LD_music_post_filter.c +++ b/lib_dec/LD_music_post_filter.c @@ -43,6 +43,7 @@ #include "prot_fx.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ @@ -65,14 +66,11 @@ * Local function prototypes *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void spectrum_mod_dct( float data[], const float lf_E[], float lf_EO[], const float noiseE[], const float minGain, float lp_gbin[], const int16_t music_flag, int16_t min_band, const float MAX_GN, const int16_t max_band ); static void analy_sp_dct( const float dct_in[], float dct_buf[], float *fr_bands, float *lf_E, float *etot ); static void find_enr_dct( const float data[], float band[], float *ptE, float *Etot, const int16_t min_band, const int16_t max_band, float *Bin_E, const float bin_freq ); -#endif -#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------* * LD_music_post_filter() * @@ -360,7 +358,6 @@ void LD_music_post_filter( /* reconstruction of the enhanced synthesis */ mvr2r( DCT_buf, dtc_out, DCT_L_POST ); } -#endif /*---------------------------------------------------------------------------* * spectrum_mod_dct() @@ -368,7 +365,6 @@ void LD_music_post_filter( * spectrum enhancement according to the output of signal_type_clas() *---------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void spectrum_mod_dct( float data[], /* i/o: DCT spectrum */ const float lf_E[], /* i : per bin E for first 46 bins (without DC) */ @@ -523,7 +519,6 @@ static void spectrum_mod_dct( return; } -#endif /*----------------------------------------------------------------------------------* * analy_sp_dct() @@ -531,7 +526,6 @@ static void spectrum_mod_dct( * Spectral analysis of the current synthesized frame *----------------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void analy_sp_dct( const float dct_in[], /* i : input DCT spectrum */ float dct_buf[], /* i : output DCT spectrum */ @@ -558,7 +552,6 @@ static void analy_sp_dct( return; } -#endif /*------------------------------------------------------------------------* * find_enr_dct) @@ -567,7 +560,6 @@ static void analy_sp_dct( * The energy is normalized by the number of frequency bins in a channel *------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void find_enr_dct( const float data[], /* i : fft result, for the format see fft_rel.c */ float band[], /* o : per band energy */ @@ -630,7 +622,6 @@ void find_enr_dct( return; } -#endif /*------------------------------------------------------------------------* * Prep_music_postP() @@ -638,7 +629,6 @@ void find_enr_dct( * Performs the steps needed to do the music post processing *------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void Prep_music_postP( float exc_buffer_in[], /* i/o: excitation buffer */ float dct_buffer_out[], /* o : DCT output buffer */ @@ -701,7 +691,6 @@ void Prep_music_postP( return; } -#endif /*------------------------------------------------------------------------* * Post_music_postP() @@ -710,7 +699,6 @@ void Prep_music_postP( * to retreive the aligned excitation and redo the synthesis *------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void Post_music_postP( float dct_buffer_in[], /* i/o: excitation buffer */ float exc_buffer_out[], /* o : DCT output buffer */ @@ -731,7 +719,6 @@ void Post_music_postP( return; } -#endif /*-------------------------------------------------------------------* @@ -739,7 +726,7 @@ void Post_music_postP( * * Initialize LD music postfilter state structure *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void music_postfilt_init_flt( MUSIC_POSTFILT_HANDLE hMusicPF /* i/o: LD music postfilter handle */ ) diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index e99d8b028886eca4d82bfa94d83dd33c9308d7a2..b9789ab84e0436f67b66106e5cbd4015063bc857 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -39,13 +39,13 @@ ivas_error acelp_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 output[], /* o : synthesis @internal Fs */ - Word16 synth_out[], /* o : synthesis */ + Word16 synth_out[], /* o : synthesis Q_syn2-1*/ Word16 save_hb_synth[], /* o : HB synthesis */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis for SWB BWE */ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation Q0*/ + Word16 *voice_factors, /* o : voicing factors Q15 */ + Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis for SWB BWE Q_syn2-1*/ Word16 sharpFlag, - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ + Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ Word16 *unbits, /* o : number of unused bits */ Word16 *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ @@ -74,7 +74,7 @@ ivas_error acelp_core_dec_fx( Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )] = { 0 }; /*Q12*/ Word16 Es_pred_fx; /*Q8*/ - Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )] = { 0 }; /* excitation buffer */ + Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )] = { 0 }; /* excitation buffer Q_exc*/ Word16 old_exc2_fx[L_FRAME16k + L_EXC_MEM], *exc2_fx; /* total excitation buffer */ Word16 *bwe_exc_fx; Word16 lsf_new_fx[M]; /* LSFs at the end of the frame */ @@ -136,8 +136,11 @@ ivas_error acelp_core_dec_fx( hBWE_FD = st_fx->hBWE_FD; hTcxDec = st_fx->hTcxDec; error = IVAS_ERR_OK; - + move32(); // IF ( EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && EQ_16(nchan_out, 1) && EQ_16(st_fx->idchan, 1) && LE_32(last_element_brate, IVAS_SID_4k4) ) + test(); + test(); + test(); IF( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st_fx->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) { /* In MDCT-Stereo DTX with mono output, we can skip CNG for the second channel, except for the first inactive frame following an active period */ @@ -236,32 +239,35 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); + test(); + test(); IF( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && LE_32( st_fx->last_core_brate, SID_2k40 ) ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && LE_32( st_fx->last_core_brate, SID_2k40 ) ) ) { /* in case of HQ->ACELP switching, do not apply BPF */ st_fx->bpf_off = 1; move16(); /* in case of core switching, reset post-filter memories */ - IF( st_fx->hPFstat != NULL ) + if ( st_fx->hPFstat != NULL ) { st_fx->hPFstat->on = 0; + move16(); } - move16(); + /* reset the GSC pre echo energy threshold in case of switching */ - IF( st_fx->hGSCDec != NULL ) + if ( st_fx->hGSCDec != NULL ) { st_fx->hGSCDec->Last_frame_ener_fx = MAX_32; + move32(); } - move32(); } - if ( st_fx->prev_bfi > 0 ) + IF( st_fx->prev_bfi > 0 ) { /* reset the GSC pre echo energy threshold in case of FEC */ - IF( st_fx->hGSCDec != NULL ) + if ( st_fx->hGSCDec != NULL ) { st_fx->hGSCDec->Last_frame_ener_fx = MAX_32; + move32(); } - move32(); } #ifdef IVAS_CODE #ifdef NON_BE_FIX_807_MASA_DTX_BRSW @@ -277,14 +283,14 @@ ivas_error acelp_core_dec_fx( st_fx->clas_dec = st_fx->last_good; move16(); enr_q_fx = 0; - move16(); + move32(); Es_pred_fx = 0; move16(); tmp_noise_fx = 0; - - Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); - exc_fx = old_exc_fx + L_EXC_MEM_DEC; move16(); + Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); // Q_exc + exc_fx = old_exc_fx + L_EXC_MEM_DEC; + IF( st_fx->hWIDec != NULL ) { Copy( st_fx->hWIDec->old_exc2_fx, old_exc2_fx, L_EXC_MEM ); @@ -296,7 +302,7 @@ ivas_error acelp_core_dec_fx( exc2_fx = old_exc2_fx + L_EXC_MEM; IF( st_fx->hBWE_TD != NULL ) { - Copy( hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); + Copy( hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); // Q_exc bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; } ELSE @@ -304,7 +310,6 @@ ivas_error acelp_core_dec_fx( bwe_exc_fx = NULL; } - move16(); last_pulse_pos = 0; move16(); do_WI_fx = 0; @@ -367,14 +372,14 @@ ivas_error acelp_core_dec_fx( move16(); move16(); } - else + ELSE { tdm_lp_reuse_flag = 0; tdm_low_rate_mode = 0; move16(); move16(); test(); - IF( EQ_16( st_fx->element_mode, IVAS_SCE ) && st_fx->low_rate_mode ) + if ( EQ_16( st_fx->element_mode, IVAS_SCE ) && st_fx->low_rate_mode ) { tdm_low_rate_mode = 1; move16(); @@ -384,16 +389,15 @@ ivas_error acelp_core_dec_fx( p_tdm_Pri_pitch_buf = NULL; #endif move16(); - move16(); } /*----------------------------------------------------------------* * Updates in case of internal sampling rate switching *----------------------------------------------------------------*/ test(); test(); - IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) + IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) && ( st_fx->last_core == ACELP_CORE || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) { - if ( st_fx->hPFstat->on != 0 ) + IF( st_fx->hPFstat->on != 0 ) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; @@ -404,22 +408,23 @@ ivas_error acelp_core_dec_fx( } /* convert quantized LSP vector */ st_fx->rate_switching_reset = lsp_convert_poly_fx( st_fx->lsp_old_fx, st_fx->L_frame, 0 ); + move16(); /* convert old quantized LSF vector */ lsp2lsf_fx( st_fx->lsp_old_fx, st_fx->lsf_old_fx, M, int_fs ); /* FEC - update adaptive LSF mean vector */ - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi0_fx, M ); - Copy( st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, M ); + Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi1_fx, M ); // Qlog2(2.56) + Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi0_fx, M ); // Qlog2(2.56) + Copy( st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, M ); // Qlog2(2.56) /* Reset LPC mem */ IF( EQ_32( st_fx->sr_core, INT_FS_16k ) ) { - Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); + Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); // Qlog2(2.56) } ELSE { - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); + Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); // Qlog2(2.56) } set16_fx( st_fx->mem_MA_fx, 0, M ); #if 1 // def IVAS_CODE @@ -436,7 +441,7 @@ ivas_error acelp_core_dec_fx( #else synth_mem_updt2( st_fx->L_frame, st_fx->last_L_frame, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC ); #endif - Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); + Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); // Q_exc Copy_Scale_sig( st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub( -1, st_fx->Q_syn ) ); /*Q-1*/ Copy( st_fx->mem_syn2_fx, st_fx->mem_syn3_fx, M ); @@ -447,57 +452,63 @@ ivas_error acelp_core_dec_fx( /* update buffer of old subframe pitch values */ IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - move16(); + IF( EQ_16( st_fx->last_L_frame, L_FRAME32k ) ) { /* (float)12800/(float)32000; */ - k = 13107; + k = 13107; // Q15 + move16(); } ELSE IF( EQ_16( st_fx->last_L_frame, 512 ) ) { /* (float)12800/(float)25600; */ - k = 16384; + k = 16384; // Q15 + move16(); } ELSE /* st->last_L_frame == L_FRAME16k */ { /* (float)12800/(float)16000; */ - k = 26214; + k = 26214; // Q15 + move16(); } FOR( i = NB_SUBFR16k - NB_SUBFR; i < NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ); + st_fx->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ); // Q(15+15+1-16) move32(); } FOR( i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ); + st_fx->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ); // Q15 move32(); } } ELSE { - move16(); + IF( EQ_16( st_fx->last_L_frame, L_FRAME32k ) ) { /* (float)16000/(float)32000; */ - k = -16384; + k = -16384; // -0.5 in Q15 + move16(); } ELSE IF( EQ_16( st_fx->last_L_frame, 512 ) ) { /* tmpF = (float)16000/(float)25600; */ - k = -12288; + k = -12288; //-0.375 in Q15 + move16(); } ELSE /* st->last_L_frame == L_FRAME12k8 */ { /* tmpF = (float)16000/(float)12800; */ - k = 8192; + k = 8192; //.25 in Q15 + move16(); } FOR( i = 2 * NB_SUBFR - 1; i >= NB_SUBFR; i-- ) { - st_fx->old_pitch_buf_fx[i + 2] = L_add( st_fx->old_pitch_buf_fx[i], Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ) ); + st_fx->old_pitch_buf_fx[i + 2] = L_add( st_fx->old_pitch_buf_fx[i], Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ) ); // Q15 move32(); } st_fx->old_pitch_buf_fx[NB_SUBFR + 1] = st_fx->old_pitch_buf_fx[NB_SUBFR + 2]; @@ -505,7 +516,7 @@ ivas_error acelp_core_dec_fx( FOR( i = NB_SUBFR - 1; i >= 0; i-- ) { - st_fx->old_pitch_buf_fx[i + 1] = L_add( st_fx->old_pitch_buf_fx[i], Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ) ); + st_fx->old_pitch_buf_fx[i + 1] = L_add( st_fx->old_pitch_buf_fx[i], Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ) ); // Q15 move32(); } st_fx->old_pitch_buf_fx[0] = st_fx->old_pitch_buf_fx[1]; @@ -517,45 +528,53 @@ ivas_error acelp_core_dec_fx( { IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - move16(); + IF( EQ_16( st_fx->bfi_pitch_frame, L_FRAME32k ) ) { /* (float)12800/(float)32000; */ - k = 13107; + k = 13107; // Q15 + move16(); } ELSE IF( EQ_16( st_fx->bfi_pitch_frame, 512 ) ) { /* (float)12800/(float)25600; */ - k = 16384; + k = 16384; // Q15 + move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME16k */ { /* (float)12800/(float)16000; */ - k = 26214; + k = 26214; // Q15 + move16(); } st_fx->bfi_pitch_fx = mult_r( k, st_fx->bfi_pitch_fx ); + move16(); st_fx->bfi_pitch_frame = L_FRAME; move16(); } ELSE { - move16(); + IF( EQ_16( st_fx->bfi_pitch_frame, L_FRAME32k ) ) { /* (float)16000/(float)32000; */ - k = -16384; + k = -16384; //-0.5 in Q15 + move16(); } ELSE IF( EQ_16( st_fx->bfi_pitch_frame, 512 ) ) { /* tmpF = (float)16000/(float)25600; */ - k = -12288; + k = -12288; // -0.375 in Q15 + move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME12k8 */ { /* tmpF = (float)16000/(float)12800; */ - k = 8192; + k = 8192; // .25 in Q15 + move16(); } st_fx->bfi_pitch_fx = add( st_fx->bfi_pitch_fx, mult_r( st_fx->bfi_pitch_fx, k ) ); + move16(); st_fx->bfi_pitch_frame = L_FRAME16k; move16(); } @@ -582,21 +601,28 @@ ivas_error acelp_core_dec_fx( tc_subfr_fx = -1; move16(); - if ( EQ_16( st_fx->coder_type, TRANSITION ) ) + IF( EQ_16( st_fx->coder_type, TRANSITION ) ) { tc_subfr_fx = tc_classif_fx( st_fx, st_fx->L_frame ); - move16(); } #if 1 // def IVAS_CODE /*----------------------------------------------------------------* * Decoding of GSC IVAS mode *----------------------------------------------------------------*/ st_fx->GSC_IVAS_mode = 0; - IF( GT_16( st_fx->element_mode, EVS_MONO ) && st_fx->idchan == 0 && !( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) + move16(); + test(); + test(); + test(); + test(); + IF( ( st_fx->element_mode > EVS_MONO ) && st_fx->idchan == 0 && !( ( st_fx->core_brate == FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) { - IF( EQ_16( st_fx->coder_type, AUDIO ) || ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) + test(); + test(); + IF( EQ_16( st_fx->coder_type, AUDIO ) || ( ( st_fx->coder_type == INACTIVE ) && LE_32( st_fx->total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) { st_fx->GSC_IVAS_mode = get_next_indice( st_fx, 2 ); + move16(); } } #endif @@ -607,7 +633,7 @@ ivas_error acelp_core_dec_fx( IF( st_fx->core_brate == FRAME_NO_DATA || EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* decode CNG parameters */ - IF( EQ_16( st_fx->cng_type, LP_CNG ) ) + IF( st_fx->cng_type == LP_CNG ) { CNG_dec_fx( st_fx, st_fx->last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sid_bw, q_env ); @@ -624,12 +650,13 @@ ivas_error acelp_core_dec_fx( CNG_exc_fx( st_fx->core_brate, st_fx->L_frame, &st_fx->hTdCngDec->Enew_fx, &st_fx->hTdCngDec->cng_seed, exc_fx, exc2_fx, &st_fx->lp_ener_fx, st_fx->last_core_brate, &st_fx->first_CNG, &( st_fx->hTdCngDec->cng_ener_seed ), bwe_exc_fx, allow_cn_step_fx, &st_fx->hTdCngDec->last_allow_cn_step, st_fx->prev_Q_exc, st_fx->Q_exc, st_fx->hTdCngDec->num_ho, q_env, st_fx->hTdCngDec->lp_env_fx, st_fx->hTdCngDec->old_env_fx, st_fx->hTdCngDec->exc_mem_fx, st_fx->hTdCngDec->exc_mem1_fx, sid_bw, &st_fx->hTdCngDec->cng_ener_seed1, exc3_fx, st_fx->Opt_AMR_WB, st_fx->element_mode ); -#if 1 // def IVAS_CODE - Copy( Aq_fx, st_fx->Aq_cng, M + 1 ); +#if 1 // def IVAS_CODE + Copy( Aq_fx, st_fx->Aq_cng, M + 1 ); // Q12 #endif } ELSE { + test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { FdCng_decodeSID_fx( st_fx->hFdCngDec->hFdCngCom, st_fx ); @@ -672,17 +699,18 @@ ivas_error acelp_core_dec_fx( delta_mem_scale = 3; move16(); test(); - if ( LT_32( st_fx->lp_ener_fx, 40 ) && EQ_16( st_fx->cng_type, LP_CNG ) ) /* very low energy frames, less than 0.3125 */ + if ( LT_32( st_fx->lp_ener_fx, 40 ) && ( st_fx->cng_type == LP_CNG ) ) /* very low energy frames, less than 0.3125 */ { delta_mem_scale = 0; move16(); } i = st_fx->Q_exc; + move16(); Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, st_fx->L_frame * HIBND_ACB_L_FAC, 0, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, 0, INACTIVE ); Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, delta_mem_scale, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 0, 0, NULL ); - Copy_Scale_sig( exc2_fx, exc2_fx, st_fx->L_frame, sub( st_fx->Q_exc, i ) ); + Copy_Scale_sig( exc2_fx, exc2_fx, st_fx->L_frame, sub( st_fx->Q_exc, i ) ); // Q_exc /* update past excitation signals for LD music post-filter */ IF( hMusicPF != NULL ) @@ -695,6 +723,7 @@ ivas_error acelp_core_dec_fx( { /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, hMusicPF->filt_lfE_fx[i] ) ); + move16(); } } /* synthesis at 12.8kHz sampling rate */ @@ -712,7 +741,7 @@ ivas_error acelp_core_dec_fx( /* save and delay synthesis to be used by SWB BWE */ - Copy_Scale_sig( syn1_fx, temp_buf_fx, st_fx->L_frame, sub( -1, st_fx->Q_syn ) ); + Copy_Scale_sig( syn1_fx, temp_buf_fx, st_fx->L_frame, sub( -1, st_fx->Q_syn ) ); // Q_syn -> Q(-1) IF( hBWE_FD != NULL ) { save_old_syn_fx( st_fx->L_frame, temp_buf_fx, old_syn_12k8_16k, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); @@ -741,13 +770,13 @@ ivas_error acelp_core_dec_fx( tc_subfr_tmp = tc_subfr_fx; move16(); - IF( LT_16( tc_subfr_tmp, L_SUBFR ) ) + if ( LT_16( tc_subfr_tmp, L_SUBFR ) ) { tc_subfr_tmp = 0; move16(); } - IF( EQ_16( tc_subfr_fx, TC_0_192 ) ) + if ( EQ_16( tc_subfr_fx, TC_0_192 ) ) { nb_bits = -1; move16(); @@ -755,7 +784,7 @@ ivas_error acelp_core_dec_fx( config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, tc_subfr_tmp, 1, &nb_bits, unbits, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); - test(); + test(); test(); IF( EQ_16( st_fx->coder_type, TRANSITION ) && LT_16( tc_subfr_fx, L_SUBFR ) && EQ_16( st_fx->L_frame, L_FRAME ) ) @@ -772,7 +801,7 @@ ivas_error acelp_core_dec_fx( test(); IF( st_fx->hTdCngDec != NULL && ( st_fx->last_core_brate == FRAME_NO_DATA || EQ_32( st_fx->last_core_brate, SID_2k40 ) ) ) { - Copy( st_fx->lspCNG_fx, st_fx->lsp_old_fx, M ); + Copy( st_fx->lspCNG_fx, st_fx->lsp_old_fx, M ); // Q15 lsp2lsf_fx( st_fx->lspCNG_fx, st_fx->lsf_old_fx, M, int_fs ); } @@ -894,7 +923,7 @@ ivas_error acelp_core_dec_fx( /* decode the last glottal pulse position */ T0_tmp = FEC_pos_dec_fx( st_fx, &last_pulse_pos, &enr_q_fx, nb_bits ); - move16(); + test(); test(); @@ -906,10 +935,12 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); + test(); IF( EQ_16( st_fx->clas_dec, SIN_ONSET ) && last_pulse_pos != 0 && EQ_16( st_fx->prev_bfi, 1 ) ) { st_fx->Q_exc = FEC_SinOnset_fx( old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st_fx->L_frame, st_fx->Q_exc ); + move16(); } ELSE IF( ( EQ_16( st_fx->coder_type, GENERIC ) || EQ_16( st_fx->coder_type, VOICED ) ) && last_pulse_pos != 0 && EQ_16( st_fx->old_bfi_cnt, 1 ) && EQ_16( output_frame, L_FRAME16k ) && st_fx->hWIDec != NULL ) { @@ -926,6 +957,8 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); + test(); + test(); IF( st_fx->stab_fac_fx == 0 && st_fx->old_bfi_cnt > 0 && NE_16( st_fx->clas_dec, VOICED_CLAS ) && NE_16( st_fx->clas_dec, ONSET ) && st_fx->relax_prev_lsf_interp == 0 && !( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) ) ) { @@ -945,7 +978,7 @@ ivas_error acelp_core_dec_fx( /*------------------------------------------------------------* * Decode excitation according to coding type *------------------------------------------------------------*/ - test(); + test(); test(); #ifdef ADD_LRTD @@ -971,7 +1004,7 @@ ivas_error acelp_core_dec_fx( IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { /* SC-VBR - NELP frames */ - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0 st_fx->Q_exc = 0; move16(); @@ -985,8 +1018,9 @@ ivas_error acelp_core_dec_fx( } ELSE IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) { - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0 st_fx->Q_exc = 0; + move16(); /* SC-VBR - PPP frames */ IF( NE_32( ( error = decod_ppp_fx( st_fx, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st_fx->bfi, gain_buf, voice_factors, bwe_exc_fx ) ), IVAS_ERR_OK ) ) { @@ -999,7 +1033,7 @@ ivas_error acelp_core_dec_fx( { decod_tran_fx( st_fx, st_fx->L_frame, tc_subfr_fx, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf ); } - ELSE IF( EQ_16( st_fx->coder_type, AUDIO ) || ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) ) ) + ELSE IF( EQ_16( st_fx->coder_type, AUDIO ) || ( ( st_fx->coder_type == INACTIVE ) && LE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) ) ) { decod_audio_fx( st_fx, dct_exc_tmp, Aq_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf #ifdef ADD_LRTD @@ -1041,6 +1075,7 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); + test(); IF( !( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) && NE_16( st_fx->nelp_mode_dec, 1 ) && !( EQ_16( st_fx->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) { stat_noise_uv_dec_fx( st_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag ); @@ -1059,17 +1094,25 @@ ivas_error acelp_core_dec_fx( Copy( hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 ); } test(); - IF( hMusicPF != NULL && ( ( EQ_16( st_fx->coder_type, AUDIO ) && EQ_16( st_fx->GSC_noisy_speech, 0 ) ) || ( GE_16( st_fx->GSC_IVAS_mode, 1 ) && EQ_16( st_fx->L_frame, L_FRAME ) ) ) ) + test(); + test(); + test(); + IF( hMusicPF != NULL && ( ( EQ_16( st_fx->coder_type, AUDIO ) && st_fx->GSC_noisy_speech == 0 ) || ( GE_16( st_fx->GSC_IVAS_mode, 1 ) && EQ_16( st_fx->L_frame, L_FRAME ) ) ) ) { Word16 last_coder_type = st_fx->last_coder_type; - + move16(); + test(); + test(); + test(); if ( ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) || ( GE_16( st_fx->GSC_IVAS_mode, 1 ) && st_fx->GSC_noisy_speech == 0 ) ) { last_coder_type = AUDIO; + move16(); } /* Extrapolation of the last future part, windowing and high resolution DCT transform */ qdct = 0; + move16(); #ifdef _DIFF_FLOAT_FIX_ /* FLoat point using last_core which fits with the inner part of the function */ Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, hMusicPF->filt_lfE_fx, st_fx->last_core, st_fx->element_mode, pitch_buf_fx, hMusicPF->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &qdct ); @@ -1091,7 +1134,7 @@ ivas_error acelp_core_dec_fx( /* Core synthesis at 12.8kHz or 16kHz */ i = 1; move16(); - if ( EQ_16( st_fx->coder_type, INACTIVE ) ) + if ( st_fx->coder_type == INACTIVE ) { i = 0; move16(); @@ -1101,7 +1144,7 @@ ivas_error acelp_core_dec_fx( move16(); test(); test(); - if ( EQ_16( st_fx->coder_type, INACTIVE ) && st_fx->flag_cna && GE_16( round_fx( L_shl( st_fx->lp_noise, 1 ) ), 15 << 7 ) ) + if ( ( st_fx->coder_type == INACTIVE ) && st_fx->flag_cna && GE_16( round_fx( L_shl( st_fx->lp_noise, 1 ) ), 15 << 7 ) ) { k = 1; move16(); @@ -1109,7 +1152,7 @@ ivas_error acelp_core_dec_fx( Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, i, k, temp_buf_fx ); - Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); + Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); // Q_syn syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); IF( hMusicPF != NULL ) @@ -1118,6 +1161,7 @@ ivas_error acelp_core_dec_fx( { /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, hMusicPF->filt_lfE_fx[i] ) ); + move16(); } } } @@ -1155,15 +1199,18 @@ ivas_error acelp_core_dec_fx( move16(); FOR( i = 0; i < st_fx->L_frame; i += L_SUBFR ) { - pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); + pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); // Q0(6+9-15) , (512 = 1.0f in Q9) move16(); - k++; + k = add( k, 1 ); } FEC_scale_syn_fx( st_fx->L_frame, &update_flg, st_fx->clas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, enr_q_fx, st_fx->coder_type, LSF_Q_prediction, &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, st_fx->prev_bfi, st_fx->last_core_brate, exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, avoid_lpc_burst_on_recovery, 0 ); + test(); + test(); + test(); test(); IF( ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && LE_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) { @@ -1201,10 +1248,10 @@ ivas_error acelp_core_dec_fx( FEC_lsf2lsp_interp( st_fx, st_fx->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx ); - IF( st_fx->nelp_mode_dec == 1 ) + IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { /* SC-VBR */ - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0 st_fx->Q_exc = 0; move16(); @@ -1252,6 +1299,7 @@ ivas_error acelp_core_dec_fx( { /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, hMusicPF->filt_lfE_fx[i] ) ); + move16(); } /* Update circular buffer, keep last energy difference unchanged */ FOR( i = 1; i < MAX_LT; i++ ) @@ -1266,7 +1314,7 @@ ivas_error acelp_core_dec_fx( move16(); test(); test(); - if ( EQ_16( st_fx->coder_type, INACTIVE ) && st_fx->flag_cna && GE_16( round_fx( L_shl( st_fx->lp_noise, 1 ) ), 15 << 7 ) ) + if ( ( st_fx->coder_type == INACTIVE ) && st_fx->flag_cna && GE_16( round_fx( L_shl( st_fx->lp_noise, 1 ) ), 15 << 7 ) ) { k = 1; move16(); @@ -1275,9 +1323,10 @@ ivas_error acelp_core_dec_fx( Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, k, temp_buf_fx ); - if ( ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) + test(); + IF( ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) { - Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); + Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); // Q_syn } syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); @@ -1288,20 +1337,22 @@ ivas_error acelp_core_dec_fx( Copy( syn_fx + st_fx->L_frame - L_EXC_MEM, st_fx->hWIDec->old_syn2_fx, L_EXC_MEM ); } st_fx->prev_Q_exc_fr = st_fx->Q_exc; + move16(); st_fx->prev_Q_syn_fr = st_fx->Q_syn; + move16(); Copy( syn_fx + st_fx->L_frame - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - - if ( ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) + test(); + IF( ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) { k = 0; move16(); FOR( i = 0; i < st_fx->L_frame; i += L_SUBFR ) { - pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); + pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); // Q0(6+9-15) , (512 = 1.0f in Q9) move16(); - k++; + k = add( k, 1 ); } /*------------------------------------------------------------* @@ -1328,16 +1379,17 @@ ivas_error acelp_core_dec_fx( /* SC-VBR */ st_fx->hSC_VBR->FadeScale_fx = mult( st_fx->hSC_VBR->FadeScale_fx, 24576 ); /*24576 in Q15*/ + move16(); } IF( hBWE_TD != NULL ) { IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - Copy( Aq_fx + 2 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); + Copy( Aq_fx + 2 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12 } ELSE { - Copy( Aq_fx + 3 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); + Copy( Aq_fx + 3 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12 } } /*--------------------------------------------------------* @@ -1350,9 +1402,9 @@ ivas_error acelp_core_dec_fx( move16(); FOR( i = 0; i < st_fx->L_frame; i += L_SUBFR ) { - pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); + pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); // Q0(6+9-15) , (512 = 1.0f in Q9) move16(); - k++; + k = add( k, 1 ); } IF( EQ_16( st_fx->bwidth, NB ) ) @@ -1371,6 +1423,7 @@ ivas_error acelp_core_dec_fx( ELSE { st_fx->psf_lp_noise_fx = round_fx( L_shl( st_fx->lp_noise, 1 ) ); + move16(); } /*------------------------------------------------------------------* @@ -1386,7 +1439,7 @@ ivas_error acelp_core_dec_fx( /* Update MODE2 memories*/ IF( hTcxDec != NULL ) { - Copy_Scale_sig( syn_fx + st_fx->L_frame / 2, hTcxDec->old_syn_Overl, st_fx->L_frame / 2, sub( -1, st_fx->Q_syn ) ); /*Q-1*/ + Copy_Scale_sig( syn_fx + shr( st_fx->L_frame, 1 ), hTcxDec->old_syn_Overl, shr( st_fx->L_frame, 1 ), sub( -1, st_fx->Q_syn ) ); /*Q-1*/ } Copy_Scale_sig( syn_fx + st_fx->L_frame - M - 1, st_fx->syn, M + 1, sub( 0, st_fx->Q_syn ) ); /*Q0*/ @@ -1399,7 +1452,7 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); - IF( GE_16( st_fx->last_bwidth, WB ) && ( GT_32( st_fx->core_brate, ACELP_24k40 ) || GT_16( st_fx->element_mode, EVS_MONO ) ) && LE_32( st_fx->core_brate, ACELP_32k ) ) + IF( GE_16( st_fx->last_bwidth, WB ) && ( GT_32( st_fx->core_brate, ACELP_24k40 ) || ( st_fx->element_mode > EVS_MONO ) ) && LE_32( st_fx->core_brate, ACELP_32k ) ) { Copy( syn_fx, temp_buf + L_SYN_MEM, L_FRAME16k ); st_fx->hPFstat->on = 1; @@ -1408,7 +1461,7 @@ ivas_error acelp_core_dec_fx( } ELSE IF( GE_16( st_fx->last_bwidth, WB ) ) { - if ( st_fx->hPFstat->on ) + IF( st_fx->hPFstat->on ) { Copy( st_fx->hPFstat->mem_pf_in + L_SYN_MEM - M, temp_buf, M ); Copy( syn_fx, temp_buf + M, L_SUBFR ); @@ -1426,18 +1479,26 @@ ivas_error acelp_core_dec_fx( * Comfort noise addition *----------------------------------------------------------------*/ - test(); - test(); test(); test(); IF( ( st_fx->hFdCngDec != NULL || EQ_16( st_fx->idchan, 1 ) ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || st_fx->flag_cna || ( EQ_16( st_fx->cng_type, FD_CNG ) && LE_32( st_fx->total_brate, ACELP_32k ) ) || ( EQ_16( st_fx->cng_type, LP_CNG ) && LE_32( st_fx->total_brate, SID_2k40 ) ) ) + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || st_fx->flag_cna || ( EQ_16( st_fx->cng_type, FD_CNG ) && LE_32( st_fx->total_brate, ACELP_32k ) ) || ( ( st_fx->cng_type == LP_CNG ) && LE_32( st_fx->total_brate, SID_2k40 ) ) ) { /*VAD only for non inactive frame*/ test(); st_fx->VAD = st_fx->VAD && ( st_fx->coder_type != INACTIVE ); - + move16(); + test(); + test(); + test(); + test(); + test(); IF( st_fx->idchan == 0 && ( st_fx->flag_cna || ( EQ_16( st_fx->cng_type, FD_CNG ) && LE_32( st_fx->total_brate, ACELP_32k ) ) || ( EQ_16( st_fx->cng_type, LP_CNG ) && LE_32( st_fx->total_brate, SID_2k40 ) ) ) ) { @@ -1445,20 +1506,19 @@ ivas_error acelp_core_dec_fx( noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD, syn_fx, st_fx->Q_syn ); st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); + move16(); IF( st_fx->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) { st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); move16(); } } - IF( st_fx->idchan == 0 ) + if ( st_fx->idchan == 0 ) { st_fx->lp_noise = st_fx->hFdCngDec->lp_noise; move32(); } /*Noise estimate*/ - test(); - test(); IF( NE_16( st_fx->element_mode, IVAS_CPE_TD ) /* && !st->cng_ism_flag IVAS_CODE */ ) { #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT @@ -1469,10 +1529,7 @@ ivas_error acelp_core_dec_fx( #endif } /* CNA: Generate additional comfort noise to mask potential coding artefacts */ - test(); - test(); - test(); - test(); + #ifdef IVAS_CODE if ( !st->cna_dirac_flag ) { @@ -1569,11 +1626,15 @@ ivas_error acelp_core_dec_fx( } } #else + test(); + test(); + test(); + test(); IF( st_fx->flag_cna && NE_16( st_fx->coder_type, AUDIO ) ) { generate_masking_noise_fx( syn_fx, st_fx->Q_syn, st_fx->hFdCngDec->hFdCngCom, st_fx->hFdCngDec->hFdCngCom->frameSize, 0 ); } - ELSE IF( st_fx->flag_cna && st_fx->coder_type == AUDIO && st_fx->last_core == ACELP_CORE && st_fx->last_coder_type != AUDIO ) + ELSE IF( st_fx->flag_cna && EQ_16( st_fx->coder_type, AUDIO ) && st_fx->last_core == ACELP_CORE && NE_16( st_fx->last_coder_type, AUDIO ) ) { FOR( i = 0; i < st_fx->hFdCngDec->hFdCngCom->frameSize / 2; i++ ) { @@ -1584,11 +1645,16 @@ ivas_error acelp_core_dec_fx( #endif #ifndef IVAS_CODE - IF( st_fx->flag_cna == 0 && EQ_16( st_fx->L_frame, L_FRAME16k ) && st_fx->last_flag_cna == 1 && ( ( st_fx->last_core == ACELP_CORE && st_fx->last_coder_type != AUDIO ) || st_fx->last_core == AMR_WB_CORE ) ) + test(); + test(); + test(); + test(); + test(); + IF( st_fx->flag_cna == 0 && EQ_16( st_fx->L_frame, L_FRAME16k ) && EQ_16( st_fx->last_flag_cna, 1 ) && ( ( st_fx->last_core == ACELP_CORE && NE_16( st_fx->last_coder_type, AUDIO ) ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) { FOR( i = 0; i < st_fx->L_frame / 2; i++ ) { - syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4], -st_fx->Q_syn ) ); + syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4], negate( st_fx->Q_syn ) ) ); move16(); } } @@ -1614,15 +1680,17 @@ ivas_error acelp_core_dec_fx( resampleCldfb( st_fx->cldfbAna, newCldfbBands, st_fx->L_frame, 0 ); resampleCldfb( st_fx->cldfbBPF, newCldfbBands, st_fx->L_frame, 0 ); - if ( st_fx->ini_frame > 0 ) + IF( st_fx->ini_frame > 0 ) { st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); + move16(); } } #ifdef ADD_LRTD /* analyze pitch coherence for bass post-filter */ bpf_pitch_coherence( st, pitch_buf ); #endif + test(); IF( !( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->bpf_off ) ) { test(); @@ -1680,31 +1748,36 @@ ivas_error acelp_core_dec_fx( { /* set NB mask for upsampling */ st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, 10 ); + move16(); } ELSE IF( NE_16( st_fx->cldfbSyn->bandsToZero, sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ) ) ) { /* in case of BW switching, re-init to default */ st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); + move16(); } /*WB/SWB-FD_CNG*/ scaleFactor.hb_scale = scaleFactor.lb_scale; move16(); - test(); - test(); + test(); IF( !st_fx->cng_sba_flag || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF( ( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) && ( EQ_16( st_fx->cng_type, FD_CNG ) ) && ( LT_16( st_fx->hFdCngDec->hFdCngCom->numCoreBands, st_fx->cldfbSyn->no_channels ) ) ) + test(); + test(); + test(); + IF( ( ( st_fx->core_brate == FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) && ( EQ_16( st_fx->cng_type, FD_CNG ) ) && ( LT_16( st_fx->hFdCngDec->hFdCngCom->numCoreBands, st_fx->cldfbSyn->no_channels ) ) ) { generate_comfort_noise_dec_hf_fx( realBuffer, imagBuffer, &scaleFactor.hb_scale, st_fx ); st_fx->cldfbSyn->bandsToZero = 0; move16(); - if ( LT_16( st_fx->hFdCngDec->hFdCngCom->regularStopBand, st_fx->cldfbSyn->no_channels ) ) + IF( LT_16( st_fx->hFdCngDec->hFdCngCom->regularStopBand, st_fx->cldfbSyn->no_channels ) ) { st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->hFdCngDec->hFdCngCom->regularStopBand ); + move16(); } st_fx->cldfbSyn->lsb = st_fx->cldfbAna->no_channels; move16(); @@ -1832,13 +1905,20 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); + test(); + test(); IF( ( !st_fx->bfi && ( st_fx->prev_bfi ) ) || ( ( EQ_16( st_fx->last_vbr_hw_BWE_disable_dec, 1 ) ) && ( st_fx->vbr_hw_BWE_disable_dec == 0 ) ) || ( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, WB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && !st_fx->tdm_LRTD_flag ) ) { hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); + move32(); set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); } - + test(); + test(); + test(); + test(); + test(); IF( !st_fx->ppp_mode_dec && ( st_fx->idchan == 0 || NE_16( st_fx->element_mode, IVAS_CPE_TD ) || ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && st_fx->tdm_LRTD_flag ) ) ) { non_linearity_fx( bwe_exc_fx, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, st_fx->Q_exc, @@ -1846,9 +1926,10 @@ ivas_error acelp_core_dec_fx( } test(); - IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) + IF( ( st_fx->core_brate == FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) { hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); + move32(); } } /*----------------------------------------------------------------------* @@ -1857,6 +1938,8 @@ ivas_error acelp_core_dec_fx( updt_dec_fx( st_fx, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors, old_bwe_exc_fx, gain_buf ); + test(); + test(); IF( GT_32( st_fx->core_brate, SID_2k40 ) && st_fx->hTdCngDec != NULL && st_fx->hFdCngDec != NULL ) { /* update CNG parameters in active frames */ diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 0827e4504edac78191253baa1ac981639e173e3e..679120dbb2d54c1e741a907b12cd38f86a232cf6 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -55,18 +55,18 @@ static void rescale_fdCngDec( HANDLE_FD_CNG_DEC hFdCngDec, Word16 old_NoiseExp ); ivas_error acelp_core_dec_ivas_fx( Decoder_State *st, /* i/o: decoder state structure */ - Word16 output_fx[], /* o : synthesis @internal Fs */ - Word16 synth_fx16[], /* o : synthesis */ - Word16 save_hb_synth_fx16[], /* o : HB synthesis */ - Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ + Word16 output_fx[], /* o : synthesis @internal Fs Q_syn*/ + Word16 synth_fx16[], /* o : synthesis Q_syn2*/ + Word16 save_hb_synth_fx16[], /* o : HB synthesis Q0*/ + Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation 2*Q_exc*/ + Word16 *voice_factors_fx, /* o : voicing factors Q15*/ + Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE Q_syn2-1*/ const Word16 sharpFlag, /* i : formant sharpening flag */ - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : Word16 pitch for each subframe */ + Word16 pitch_buf_fx[NB_SUBFR16k], /* o : Word16 pitch for each subframe Q6*/ Word16 *unbits, /* o : number of unused bits */ Word16 *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ - STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const Word16 tdm_lspQ_PCh_fx[M], /* i : Q LSPs for primary channel */ + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle Qlog2(2.56)*/ + const Word16 tdm_lspQ_PCh_fx[M], /* i : Q LSPs for primary channel Q15*/ const Word16 tdm_lsfQ_PCh_fx[M], /* i : Q LSFs for primary channel */ const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ const Word16 last_element_mode, /* i : last element mode */ @@ -209,11 +209,11 @@ ivas_error acelp_core_dec_ivas_fx( /* comfort noise generation */ CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, NULL, NULL, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), NULL, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, NULL, st->Opt_AMR_WB, st->element_mode ); - Copy( Aq_fx, st->Aq_cng, M + 1 ); + Copy( Aq_fx, st->Aq_cng, M + 1 ); /*Q12*/ /* update old LSP and LSF vector */ - Copy( lsf_new_fx, st->lsf_old_fx, M ); - Copy( lsp_new_fx, st->lsp_old_fx, M ); + Copy( lsf_new_fx, st->lsf_old_fx, M ); /*Qlog2(2.56)*/ + Copy( lsp_new_fx, st->lsp_old_fx, M ); /*Q15*/ } set16_fx( output_fx, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ @@ -235,9 +235,7 @@ ivas_error acelp_core_dec_ivas_fx( set32_fx( realBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); set32_fx( imagBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); realBuffer_fx[i] = realBufferTmp_fx[i]; - move32(); imagBuffer_fx[i] = imagBufferTmp_fx[i]; - move32(); } /*----------------------------------------------------------------* * Initialization @@ -282,7 +280,7 @@ ivas_error acelp_core_dec_ivas_fx( } test(); - IF( st->hGSCDec != NULL && ( st->prev_bfi > 0 ) ) + if ( st->hGSCDec != NULL && ( st->prev_bfi > 0 ) ) { /* reset the GSC pre echo energy threshold in case of FEC */ st->hGSCDec->Last_frame_ener_fx = MAX_32; @@ -310,7 +308,7 @@ ivas_error acelp_core_dec_ivas_fx( move16(); tmp_noise_fx = 0; move16(); - Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); + Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ exc_fx = old_exc_fx + L_EXC_MEM_DEC; IF( st->hWIDec != NULL ) @@ -325,7 +323,7 @@ ivas_error acelp_core_dec_ivas_fx( IF( st->hBWE_TD != NULL ) { - Copy( st->hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); + Copy( st->hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); /*Q_exc*/ bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; } ELSE @@ -423,8 +421,8 @@ ivas_error acelp_core_dec_ivas_fx( IF( ( st->hPFstat->on != 0 ) ) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; - mem_syn_r_size_old = mult_r( 2048, st->last_L_frame ); - mem_syn_r_size_new = mult_r( 2048, st->L_frame ); + mem_syn_r_size_old = mult_r( 2048, st->last_L_frame ); /* 1.25/20.f = 2048 (Q15)*/ + mem_syn_r_size_new = mult_r( 2048, st->L_frame ); /* 1.25/20.f = 2048 (Q15)*/ lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); } @@ -437,18 +435,18 @@ ivas_error acelp_core_dec_ivas_fx( lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, int_fs ); /* FEC - update adaptive LSF mean vector */ - Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); - Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); - Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); + Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); /*Qlog2(2.56)*/ + Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); /*Qlog2(2.56)*/ + Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); /*Qlog2(2.56)*/ /* Reset LPC mem */ IF( EQ_32( st->sr_core, INT_FS_16k ) ) { - Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); + Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); /*Qlog2(2.56)*/ } ELSE { - Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); + Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); /*Qlog2(2.56)*/ } set16_fx( st->mem_MA_fx, 0, M ); @@ -465,9 +463,9 @@ ivas_error acelp_core_dec_ivas_fx( #else ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec ); #endif - Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); + Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ Copy_Scale_sig( st->mem_syn2_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); /*Q-1*/ - Copy( st->mem_syn2_fx, st->mem_syn3_fx, M ); + Copy( st->mem_syn2_fx, st->mem_syn3_fx, M ); /*Q_syn*/ } /* update buffer of old subframe pitch values */ @@ -477,29 +475,29 @@ ivas_error acelp_core_dec_ivas_fx( { IF( EQ_16( st->last_L_frame, L_FRAME32k ) ) { - tmpF_fx = 13107; + tmpF_fx = 13107; // Q15 move16(); } ELSE IF( EQ_16( st->last_L_frame, 512 ) ) { - tmpF_fx = 16384; + tmpF_fx = 16384; // Q15 move16(); } ELSE /* st->last_L_frame == L_FRAME16k */ { - tmpF_fx = 26214; + tmpF_fx = 26214; // Q15 move16(); } FOR( i = NB_SUBFR16k - NB_SUBFR; i < NB_SUBFR16k; i++ ) { - st->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); + st->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); // Q16 move32(); } FOR( i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++ ) { - st->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); + st->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); // Q16 move32(); } } @@ -509,12 +507,12 @@ ivas_error acelp_core_dec_ivas_fx( move16(); IF( EQ_16( st->last_L_frame, L_FRAME32k ) ) { - tmpF_fx = 16384; + tmpF_fx = 16384; // Q15 move16(); } ELSE IF( EQ_16( st->last_L_frame, 512 ) ) { - tmpF_fx = 20480; + tmpF_fx = 20480; // Q15 move16(); } ELSE /* st->last_L_frame == L_FRAME12k8 */ @@ -526,7 +524,7 @@ ivas_error acelp_core_dec_ivas_fx( } FOR( i = 2 * NB_SUBFR - 1; i >= NB_SUBFR; i-- ) { - st->old_pitch_buf_fx[i + 2] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); + st->old_pitch_buf_fx[i + 2] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); // Q15 move32(); } st->old_pitch_buf_fx[NB_SUBFR + 1] = st->old_pitch_buf_fx[NB_SUBFR + 2]; @@ -534,7 +532,7 @@ ivas_error acelp_core_dec_ivas_fx( FOR( i = NB_SUBFR - 1; i >= 0; i-- ) { - st->old_pitch_buf_fx[i + 1] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); + st->old_pitch_buf_fx[i + 1] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); // Q15 move32(); } st->old_pitch_buf_fx[0] = st->old_pitch_buf_fx[1]; @@ -548,17 +546,17 @@ ivas_error acelp_core_dec_ivas_fx( { IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) ) { - tmpF_fx = 13107; + tmpF_fx = 13107; // Q15 move16(); } ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) ) { - tmpF_fx = 16384; + tmpF_fx = 16384; // Q15 move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME16k */ { - tmpF_fx = 26214; + tmpF_fx = 26214; // Q15 move16(); } st->bfi_pitch_fx = mult_r( st->bfi_pitch_fx, tmpF_fx ); @@ -572,12 +570,12 @@ ivas_error acelp_core_dec_ivas_fx( move16(); IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) ) { - tmpF_fx = 16384; + tmpF_fx = 16384; // Q15 move16(); } ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) ) { - tmpF_fx = 20480; + tmpF_fx = 20480; // Q15 move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME12k8 */ @@ -626,7 +624,7 @@ ivas_error acelp_core_dec_ivas_fx( test(); test(); test(); - IF( GT_16( st->element_mode, EVS_MONO ) && st->idchan == 0 && !( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) + IF( st->element_mode > EVS_MONO && st->idchan == 0 && !( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) { test(); test(); @@ -649,8 +647,8 @@ ivas_error acelp_core_dec_ivas_fx( CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); FOR( Word32 nsf = 0; nsf < NB_SUBFR16k; nsf++ ) { - Scale_sig( Aq_fx + imult3216( nsf, ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[imult3216( nsf, add( M, 1 ) )] ), Q2 ) ); - Aq_fx[imult3216( nsf, M + 1 )] = ONE_IN_Q12; + Scale_sig( Aq_fx + imult3216( nsf, ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[nsf * ( M + 1 )] ), Q2 ) ); + Aq_fx[nsf * ( M + 1 )] = ONE_IN_Q12; move16(); } Copy( Aq_fx, st->Aq_cng, add( M, 1 ) ); @@ -676,7 +674,7 @@ ivas_error acelp_core_dec_ivas_fx( move16(); FdCng_decodeSID_ivas_fx( st ); rescale_fdCngDec( st->hFdCngDec, sub( old_NoiseEstExp, st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ); - Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ), Q2 ) ); + Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ), Q2 ) ); // Qx *sid_bw = 0; move16(); } @@ -703,13 +701,13 @@ ivas_error acelp_core_dec_ivas_fx( ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); Word16 new_sidNoiseEstExp = 31 - Q4; move16(); - Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); - Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); // Q(31-sidNoiseEstExp) + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); // Q(31-sidNoiseEstExp) st->hFdCngDec->hFdCngCom->sidNoiseEstExp = new_sidNoiseEstExp; move16(); Word16 new_cngNoiseLevelExp = 31 - Q4; move16(); - Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - new_cngNoiseLevelExp ); + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, new_cngNoiseLevelExp ) ); // Q(31-cngNoiseLevelExp) st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = new_cngNoiseLevelExp; move16(); @@ -718,7 +716,7 @@ ivas_error acelp_core_dec_ivas_fx( IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) { - Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); // Q(31-cngNoiseLevelExp) st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; move16(); } @@ -728,9 +726,9 @@ ivas_error acelp_core_dec_ivas_fx( { Word32 noise_lvl_highest_fx; - noise_lvl_highest_fx = st->hFdCngDec->hFdCngCom->cngNoiseLevel[sub( sub( st->hFdCngDec->hFdCngCom->stopFFTbin, st->hFdCngDec->hFdCngCom->startBand ), 1 )]; + noise_lvl_highest_fx = st->hFdCngDec->hFdCngCom->cngNoiseLevel[( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ) - 1]; move32(); - FOR( Word16 b = sub( st->hFdCngDec->hFdCngCom->stopFFTbin, st->hFdCngDec->hFdCngCom->startBand ); b < st->hFdCngDec->hFdCngCom->stopBand; b++ ) + FOR( Word16 b = ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); b < st->hFdCngDec->hFdCngCom->stopBand; b++ ) { st->hFdCngDec->hFdCngCom->cngNoiseLevel[b] = noise_lvl_highest_fx; move32(); @@ -747,7 +745,7 @@ ivas_error acelp_core_dec_ivas_fx( Word16 delta_mem_scale = 3; move16(); test(); - if ( LT_32( st->lp_ener_fx, 40 ) && EQ_16( st->cng_type, LP_CNG ) ) /* very low energy frames, less than 0.3125 */ + if ( LT_32( st->lp_ener_fx, 40 ) && st->cng_type == LP_CNG ) /* very low energy frames, less than 0.3125 */ { delta_mem_scale = 0; move16(); @@ -770,7 +768,7 @@ ivas_error acelp_core_dec_ivas_fx( Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale, &st->mem_deemph_fx, NULL, NULL, &st->agc_mem_fx[1], NULL, 0, 0, NULL ); } - Copy_Scale_sig( exc2_fx, exc2_fx, st->L_frame, sub( st->Q_exc, i ) ); + Copy_Scale_sig( exc2_fx, exc2_fx, st->L_frame, sub( st->Q_exc, i ) ); // Q_exc /* update past excitation signals for LD music post-filter */ IF( st->hMusicPF != NULL ) @@ -782,7 +780,7 @@ ivas_error acelp_core_dec_ivas_fx( /* Filter energies update */ FOR( i = 0; i < DCT_L_POST; i++ ) { - st->hMusicPF->filt_lfE_fx[i] = add( 9830, mult_r( 22937, st->hMusicPF->filt_lfE_fx[i] ) ); + st->hMusicPF->filt_lfE_fx[i] = add( 9830, mult_r( 22937, st->hMusicPF->filt_lfE_fx[i] ) ); // Q15, 9830 =.3f in Q15, 22937=.7f in Q15 move16(); } } @@ -801,13 +799,13 @@ ivas_error acelp_core_dec_ivas_fx( CNG_reset_dec_fx( st, pitch_buf_fx, voice_factors_fx ); /* update st->mem_syn1 for ACELP core switching */ - Copy_Scale_sig( st->mem_syn3_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); + Copy_Scale_sig( st->mem_syn3_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); // Q(-1) /* update old synthesis for classification */ Copy( syn1_fx + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); /* save and delay synthesis to be used by SWB BWE */ - Copy_Scale_sig( syn1_fx, temp_buf_fx, st->L_frame, sub( -1, st->Q_syn ) ); + Copy_Scale_sig( syn1_fx, temp_buf_fx, st->L_frame, sub( -1, st->Q_syn ) ); // Q_syn IF( st->hBWE_FD != NULL ) { save_old_syn_fx( st->L_frame, syn1_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); @@ -862,12 +860,12 @@ ivas_error acelp_core_dec_ivas_fx( /*-----------------------------------------------------------------* * After CNG period, use the most up-to-date LSPs *-----------------------------------------------------------------*/ - test(); + test(); test(); IF( st->hTdCngDec != NULL && ( st->last_core_brate == FRAME_NO_DATA || EQ_32( st->last_core_brate, SID_2k40 ) ) ) { - Copy( st->lspCNG_fx, st->lsp_old_fx, M ); + Copy( st->lspCNG_fx, st->lsp_old_fx, M ); /*Q15*/ lsp2lsf_fx( st->lspCNG_fx, st->lsf_old_fx, M, int_fs ); } @@ -947,8 +945,8 @@ ivas_error acelp_core_dec_ivas_fx( FOR( Word32 nsf = 0; nsf < st->nb_subfr; nsf++ ) #endif { - Scale_sig( Aq_fx + imult3216( nsf, ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[imult3216( nsf, M + 1 )] ), Q2 ) ); - Aq_fx[imult3216( nsf, M + 1 )] = ONE_IN_Q12; + Scale_sig( Aq_fx + imult3216( nsf, ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[nsf * ( M + 1 )] ), Q2 ) ); // Q(x-2) + Aq_fx[nsf * ( M + 1 )] = ONE_IN_Q12; move16(); } test(); @@ -957,13 +955,14 @@ ivas_error acelp_core_dec_ivas_fx( /* Prepare ACB memory from last HQ frame */ old_exc_s_fx = st->old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ); tmpF_fx = *old_exc_s_fx; - st->mem_deemph_fx = old_exc_s_fx[sub( st->L_frame, 1 )]; + st->mem_deemph_fx = shl_sat( old_exc_s_fx[st->L_frame - 1], st->Q_syn ); /* Q0 -> Q_syn */ move16(); PREEMPH_FX( old_exc_s_fx, st->preemph_fac, L_FRAME16k, &tmpF_fx ); Copy( old_exc_s_fx + sub( st->L_frame, M ), st->mem_syn2_fx, M ); + Scale_sig( st->mem_syn2_fx, M, st->Q_syn ); /* Q0 -> Q_syn */ Residu3_fx( Aq_fx, old_exc_s_fx, old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, 0 ); #ifdef FIX_737_HQ_ACELP_SWITCH_SCALING_ERROR - Scale_sig( old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, st->Q_exc ); + Scale_sig( old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, st->Q_exc ); /* Q0 -> Q_exc */ #endif } test(); @@ -1061,7 +1060,7 @@ ivas_error acelp_core_dec_ivas_fx( ELSE IF( st->nelp_mode_dec ) { /* SC-VBR - NELP frames */ - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0 st->Q_exc = 0; move16(); /* SC-VBR - NELP frames */ @@ -1076,7 +1075,7 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE IF( st->ppp_mode_dec ) { - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0 st->Q_exc = 0; move16(); /* SC-VBR - PPP frames */ @@ -1091,7 +1090,7 @@ ivas_error acelp_core_dec_ivas_fx( { decod_tran_fx( st, st->L_frame, tc_subfr, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf_fx ); } - ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( EQ_16( st->coder_type, INACTIVE ) && st->inactive_coder_type_flag ) ) + ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( ( st->coder_type == INACTIVE ) && st->inactive_coder_type_flag ) ) { /* AUDIO and INACTIVE frames (coded by GSC technology) */ decod_audio_ivas_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx @@ -1105,7 +1104,7 @@ ivas_error acelp_core_dec_ivas_fx( ELSE { /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ - IF( ( error = decod_gen_voic_ivas_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = decod_gen_voic_ivas_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ), IVAS_ERR_OK ) ) { return error; } @@ -1181,7 +1180,7 @@ ivas_error acelp_core_dec_ivas_fx( LD_music_post_filter_fx( st->hMusicPF, dct_buffer_fx, dct_buffer_fx, st->core_brate, &st->hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct ); /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ - Copy( st->mem_syn2_fx, mem_tmp_fx, M ); + Copy( st->mem_syn2_fx, mem_tmp_fx, M ); /*Q_syn*/ Post_music_postP_fx( dct_buffer_fx, exc2_fx, st->mem_syn2_fx, st->mem_syn2_fx, Aq_fx, psyn_fx, &st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn_clas_estim_fx, 0, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, temp_buf_fx, mem_tmp_fx ); @@ -1191,6 +1190,7 @@ ivas_error acelp_core_dec_ivas_fx( /* Core synthesis at 12.8kHz or 16kHz */ i = 1; move16(); + test(); #ifdef FIX_843_LOW_RATE_BWE if ( st->coder_type == INACTIVE && st->element_mode == EVS_MONO ) #else @@ -1214,7 +1214,7 @@ ivas_error acelp_core_dec_ivas_fx( Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, i, k, temp_buf_fx ); - Copy( st->mem_syn2_fx, mem_tmp_fx, M ); + Copy( st->mem_syn2_fx, mem_tmp_fx, M ); /*Q_syn*/ syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); IF( st->hMusicPF != NULL ) @@ -1256,8 +1256,8 @@ ivas_error acelp_core_dec_ivas_fx( * (smoothing is performed in the excitation domain and signal is resynthesized after) *------------------------------------------------------------*/ - move16(); - Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); + + Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); // Q0 FEC_scale_syn_ivas_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0 ); @@ -1268,7 +1268,7 @@ ivas_error acelp_core_dec_ivas_fx( /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ IF( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && LE_32( st->total_brate, ACELP_7k20 ) ) || EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) { - frame_ener_fx( st->L_frame, st->clas_dec, psyn_fx, pitch_buf_tmp[sub( shr( st->L_frame, 6 ), 1 )], &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); + frame_ener_fx( st->L_frame, st->clas_dec, psyn_fx, pitch_buf_tmp[( ( st->L_frame ) >> 6 ) - 1], &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); } } @@ -1305,14 +1305,14 @@ ivas_error acelp_core_dec_ivas_fx( FOR( Word32 nsf = 0; nsf < st->nb_subfr; nsf++ ) #endif { - Scale_sig( Aq_fx + imult3216( nsf, ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[imult3216( nsf, M + 1 )] ), Q2 ) ); - Aq_fx[imult3216( nsf, M + 1 )] = ONE_IN_Q12; + Scale_sig( Aq_fx + imult3216( nsf, ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[nsf * ( M + 1 )] ), Q2 ) ); // Qx->Q(x-2) + Aq_fx[nsf * ( M + 1 )] = ONE_IN_Q12; move16(); } IF( EQ_16( st->nelp_mode_dec, 1 ) ) { /* SC-VBR */ - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0 st->Q_exc = 0; move16(); @@ -1409,7 +1409,7 @@ ivas_error acelp_core_dec_ivas_fx( test(); IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) { - Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); + Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); // Q0 FEC_scale_syn_ivas_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, @@ -1444,10 +1444,10 @@ ivas_error acelp_core_dec_ivas_fx( * Apply NB postfilter in case of 8kHz output *--------------------------------------------------------*/ test(); - IF( EQ_16( st->last_bwidth, NB ) && st->hPFstat != NULL ) + IF( st->last_bwidth == NB && st->hPFstat != NULL ) { Copy( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k ); - IF( EQ_16( st->bwidth, NB ) ) + IF( st->bwidth == NB ) { st->hPFstat->on = 1; move16(); @@ -1532,7 +1532,9 @@ ivas_error acelp_core_dec_ivas_fx( IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( st->cng_type == LP_CNG && LE_32( st->core_brate, SID_2k40 ) ) ) { /*VAD only for non inactive frame*/ + test(); st->VAD = st->VAD && st->coder_type != INACTIVE; + move16(); test(); test(); test(); @@ -1593,6 +1595,7 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE { + test(); IF( NE_16( st->element_mode, last_element_mode ) && ( st->idchan == 0 ) ) { /* Clear memory for secondary channel CNA */ @@ -1610,12 +1613,19 @@ ivas_error acelp_core_dec_ivas_fx( { set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); } - generate_masking_noise_fx( psyn_fx, st->Q_syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 /*, 0, 0, st->element_mode, hStereoCng, nchan_out*/ ); + Word32 psyn_32_fx[L_FRAME16k]; + Word16 exp; + Copy_Scale_sig_16_32_no_sat( psyn_fx, psyn_32_fx, st->hFdCngDec->hFdCngCom->frameSize, sub( Q6, st->Q_syn ) ); // Q6 + Copy_Scale_sig_16_32_no_sat( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), Q15 ); // Q15 + generate_masking_noise_ivas_fx( psyn_32_fx, &exp, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); + Copy_Scale_sig_32_16( psyn_32_fx, psyn_fx, st->hFdCngDec->hFdCngCom->frameSize, sub( st->Q_syn, exp ) ); // Q = st->Q_syn + Copy_Scale_sig_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), -Q15 ); // Q0 } } } ELSE IF( st->flag_cna && EQ_16( st->coder_type, AUDIO ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) { + test(); IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) { generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); @@ -1624,16 +1634,16 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE { - FOR( i = 0; i < shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ); i++ ) + FOR( i = 0; i < ( st->hFdCngDec->hFdCngCom->frameSize ) / 2; i++ ) { - psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + imult1616( 5, shr( st->hFdCngDec->hFdCngCom->frameSize, 2 ) )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); + psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * ( st->hFdCngDec->hFdCngCom->frameSize / 4 )], st->hFdCngDec->hFdCngCom->fftlenFac ), negate( st->Q_syn ) ) ); move16(); } } } ELSE { - if ( hStereoCng != NULL ) + IF( hStereoCng != NULL ) { hStereoCng->flag_cna_fade = 1; move16(); @@ -1667,9 +1677,9 @@ ivas_error acelp_core_dec_ivas_fx( test(); IF( ( st->flag_cna == 0 ) && EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->last_flag_cna, 1 ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, AMR_WB_CORE ) ) ) { - FOR( i = 0; i < shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ); i++ ) + FOR( i = 0; i < ( st->hFdCngDec->hFdCngCom->frameSize ) / 2; i++ ) { - psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + imult1616( 5, shr( st->hFdCngDec->hFdCngCom->frameSize, 2 ) )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); + psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * ( st->hFdCngDec->hFdCngCom->frameSize / 4 )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); move16(); } } @@ -1713,7 +1723,7 @@ ivas_error acelp_core_dec_ivas_fx( Word32 pitch_buf_fx_q20[12]; - Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4 ); + Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4 ); // Q(x+4) Word16 lim = shr( st->L_frame, 6 ); FOR( Word16 lp = 0; lp < lim; lp++ ) { @@ -1721,7 +1731,7 @@ ivas_error acelp_core_dec_ivas_fx( move32(); } bpf_pitch_coherence_ivas_fx( st, pitch_buf_fx_q20 ); - Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, -Q4 ); + Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, -Q4 ); // Qx test(); IF( !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->bpf_off ) ) @@ -1767,7 +1777,7 @@ ivas_error acelp_core_dec_ivas_fx( Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 #endif Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); // Q11 } #ifdef MSAN_FIX @@ -1817,7 +1827,7 @@ ivas_error acelp_core_dec_ivas_fx( } addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -( sub( q_bpf_error_signal, Q10 ) ) ); // Q10 + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, negate( ( sub( q_bpf_error_signal, Q10 ) ) ) ); // Q10 st->cldfbBPF->Q_cldfb_state = Q10; move16(); /* set output mask for upsampling */ @@ -1888,8 +1898,8 @@ ivas_error acelp_core_dec_ivas_fx( move16(); FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); - scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_imag ); + scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real + scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_imag ); // Q_imag } #ifdef FIX_882_LOW_LEVEL_DISCONTINUITIES scale_sig32_r( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // (Q_real-1) @@ -1898,7 +1908,7 @@ ivas_error acelp_core_dec_ivas_fx( #endif st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); move16(); - Scale_sig32( save_hb_synth_fx, L_FRAME48k, sub( Q_real, 1 ) ); + Scale_sig32( save_hb_synth_fx, L_FRAME48k, sub( Q_real, 1 ) ); // Q_real-1 FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { @@ -1920,7 +1930,7 @@ ivas_error acelp_core_dec_ivas_fx( cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, st->cldfbSynHB ); - Scale_sig32( save_hb_synth_fx, L_FRAME48k, -( sub( Q_real, 1 ) ) ); // Q0 + Scale_sig32( save_hb_synth_fx, L_FRAME48k, negate( ( sub( Q_real, 1 ) ) ) ); // Q0 Scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 st->cldfbSynHB->Q_cldfb_state = Q10; move16(); @@ -1939,7 +1949,7 @@ ivas_error acelp_core_dec_ivas_fx( st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); move16(); cldfbSynthesis_ivas_fx( pRealSave_fx, pImagSave_fx, synth_fx, -1, st->cldfbSyn ); - Scale_sig32( synth_fx, L_FRAME48k, -sub( Q_real, 1 ) ); + Scale_sig32( synth_fx, L_FRAME48k, negate( sub( Q_real, 1 ) ) ); // Q0 Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 st->cldfbSynHB->Q_cldfb_state = Q10; move16(); @@ -1971,8 +1981,8 @@ ivas_error acelp_core_dec_ivas_fx( move16(); FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); - scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); + scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real + scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real } #ifdef FIX_882_LOW_LEVEL_DISCONTINUITIES scale_sig32_r( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1) @@ -1987,7 +1997,7 @@ ivas_error acelp_core_dec_ivas_fx( cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx, -1, st->cldfbSyn ); #ifdef MSAN_FIX - scale_sig32( synth_fx, output_frame, negate( sub( Q_real, 1 ) ) ); + scale_sig32( synth_fx, output_frame, negate( sub( Q_real, 1 ) ) ); // Q0 #else Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); #endif @@ -2001,7 +2011,7 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE { - Word16 nSamples = NS2SA_FX2( st->L_frame * FRAMES_PER_SEC, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */ + Word16 nSamples = NS2SA_FX2( i_mult( st->L_frame, FRAMES_PER_SEC ), FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */ /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */ #ifndef MSAN_FIX @@ -2050,7 +2060,7 @@ ivas_error acelp_core_dec_ivas_fx( addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx + sub( st->L_frame, nSamples ), tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -sub( q_bpf_error_signal, Q10 ) ); // Q10 + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, negate( sub( q_bpf_error_signal, Q10 ) ) ); // Q10 st->cldfbBPF->Q_cldfb_state = Q10; move16(); /* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */ @@ -2078,8 +2088,8 @@ ivas_error acelp_core_dec_ivas_fx( move16(); FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); - scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); + scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real + scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real } #ifdef FIX_882_LOW_LEVEL_DISCONTINUITIES scale_sig32_r( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1) @@ -2093,11 +2103,11 @@ ivas_error acelp_core_dec_ivas_fx( cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), st->cldfbSyn ); #ifdef MSAN_FIX - Scale_sig32( synth_fx, output_frame, -sub( Q_real, 1 ) ); + Scale_sig32( synth_fx, output_frame, negate( sub( Q_real, 1 ) ) ); // Q0 #else Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); #endif - Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); + Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 st->cldfbSyn->Q_cldfb_state = Q10; move16(); IF( st->p_bpf_noise_buf_32 ) @@ -2105,7 +2115,7 @@ ivas_error acelp_core_dec_ivas_fx( Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); // Q11 } set32_fx( synth_fx, 0, output_frame ); @@ -2115,11 +2125,11 @@ ivas_error acelp_core_dec_ivas_fx( #ifndef MSAN_FIX Scale_sig( syn_tmp_fx, L_FRAME16k + L_SUBFR, -st->Q_syn ); #else - Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), -st->Q_syn ); + Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), negate( st->Q_syn ) ); // Q0 #endif IF( st->element_mode > EVS_MONO ) { - Copy( psyn_fx, output_fx, st->L_frame ); + Copy( psyn_fx, output_fx, st->L_frame ); /*Q_syn*/ } st->Q_syn2 = 0; @@ -2136,7 +2146,7 @@ ivas_error acelp_core_dec_ivas_fx( test(); test(); test(); - IF( ( EQ_16( st->L_frame, L_FRAME ) && NE_16( st->bwidth, NB ) && GE_16( output_frame, L_FRAME16k ) && + IF( ( EQ_16( st->L_frame, L_FRAME ) && ( st->bwidth != NB ) && GE_16( output_frame, L_FRAME16k ) && ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type, AUDIO ) ) ) ) ) { #ifndef FIX_774_ENERGY_BURST @@ -2144,7 +2154,7 @@ ivas_error acelp_core_dec_ivas_fx( move16(); #endif #ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); + Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q0 #else Copy_Scale_sig_32_16( synth_fx, synth_fx16, L_FRAME48k, 0 ); #endif @@ -2220,9 +2230,9 @@ ivas_error acelp_core_dec_ivas_fx( test(); IF( !st->ppp_mode_dec && ( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) ) { - Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( st->Q_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); - Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, -( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); + Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( st->Q_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc } test(); if ( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) @@ -2259,10 +2269,10 @@ ivas_error acelp_core_dec_ivas_fx( { IF( save_hb_synth_fx16 ) { - Copy_Scale_sig_32_16( save_hb_synth_fx, save_hb_synth_fx16, L_FRAME48k, 0 ); + Copy_Scale_sig_32_16( save_hb_synth_fx, save_hb_synth_fx16, L_FRAME48k, 0 ); // Q0 } #ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); + Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q_syn2 #else Copy_Scale_sig_32_16( synth_fx, synth_fx16, L_FRAME48k, 0 ); #endif diff --git a/lib_dec/acelp_core_switch_dec.c b/lib_dec/acelp_core_switch_dec.c index a982d8bb4556172171ec9c5c051632aee7896d28..a7a2eb75b78b80f7d625069b83bbc21c503fcadb 100644 --- a/lib_dec/acelp_core_switch_dec.c +++ b/lib_dec/acelp_core_switch_dec.c @@ -40,22 +40,18 @@ #include "rom_com.h" #include "prot.h" #include "wmc_auto.h" - +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ - -#ifndef IVAS_FLOAT_FIXED static void decod_gen_voic_core_switch( Decoder_State *st, const int16_t L_frame, const int16_t sharpFlag, const float *Aq, float *exc, const int32_t core_brate ); -#endif - /*-------------------------------------------------------------------* * acelp_core_switch_dec() * * ACELP core decoder in the first ACELP->HQ switching frame *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + ivas_error acelp_core_switch_dec( Decoder_State *st, /* i/o: decoder state structure */ float *synth_subfr_out, /* o : synthesized ACELP subframe */ diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index 81f58bd2745ec6f1a4be62be3c880b1f089cc351..bedc88438dcb6eb8109fde157cf5c8cbbd1bfce5 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -27,7 +27,7 @@ ivas_error acelp_core_switch_dec_fx( Word16 *tmp_synth_bwe, /* o : synthesized ACELP subframe BWE Q_syn*/ const Word16 output_frame, /* i : input frame length */ const Word16 core_switching_flag, /* i : core switching flag */ - Word16 *mem_synth, /* o : synthesis to overlap */ + Word16 *mem_synth, /* o : synthesis to overlap Q0 */ Word16 *Q_syn ) { Word16 i, delta, L_frame_for_cs, decode_bwe, tmp; @@ -58,9 +58,7 @@ ivas_error acelp_core_switch_dec_fx( set32_fx( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); set32_fx( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); realBuffer[i] = realBufferTmp[i]; - move32(); imagBuffer[i] = imagBufferTmp[i]; - move32(); } /* initializations */ @@ -69,8 +67,8 @@ ivas_error acelp_core_switch_dec_fx( gain = 0; move16(); - Copy( st_fx->old_Aq_12_8_fx, Aq, M + 1 ); - Copy( st_fx->old_Aq_12_8_fx, Aq + ( M + 1 ), M + 1 ); + Copy( st_fx->old_Aq_12_8_fx, Aq, M + 1 ); // Q12 + Copy( st_fx->old_Aq_12_8_fx, Aq + ( M + 1 ), M + 1 ); // Q12 set16_fx( mem_synth, 0, NS2SA( 16000, DELAY_CLDFB_NS ) + 2 ); set16_fx( synth_subfr_out, 0, SWITCH_MAX_GAP ); /* avoid valgrind complaining about uninitialized memory in core_switching_OLA_fx() */ @@ -93,14 +91,15 @@ ivas_error acelp_core_switch_dec_fx( IF( core_switching_flag && EQ_16( st_fx->last_L_frame, st_fx->last_L_frame_ori ) && ( ( ( st_fx->last_core == ACELP_CORE ) ) || ( EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) ) { exc = old_exc + L_EXC_MEM_DEC; - Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); /*scaling of exc from previous frame*/ + Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); /*scaling of exc from previous frame Q_exc*/ IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { cbrate = L_add( st_fx->core_brate, 0 ); - IF( GT_32( cbrate, ACELP_24k40 ) ) + if ( GT_32( cbrate, ACELP_24k40 ) ) { - cbrate = L_add( ACELP_24k40, 0 ); + cbrate = ACELP_24k40; + move32(); } L_frame_for_cs = L_FRAME; @@ -110,11 +109,13 @@ ivas_error acelp_core_switch_dec_fx( { IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - cbrate = L_add( ACELP_8k00, 0 ); + cbrate = ACELP_8k00; + move32(); } ELSE IF( LE_32( st_fx->core_brate, ACELP_14k80 ) ) { - cbrate = L_add( ACELP_14k80, 0 ); + cbrate = ACELP_14k80; + move32(); } ELSE { @@ -141,10 +142,12 @@ ivas_error acelp_core_switch_dec_fx( syn_12k8_fx( 2 * L_SUBFR, Aq, exc, synth_intFreq, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - IF( st_fx->hPFstat->on && ( EQ_16( st_fx->last_bwidth, NB ) ) ) + test(); + IF( st_fx->hPFstat->on && ( st_fx->last_bwidth == NB ) ) { Word16 tmp_noise, pitch_buf_tmp[2]; tmp_noise = 0; + move16(); FOR( i = 0; i < 2; i++ ) { pitch_buf_tmp[i] = L_SUBFR; @@ -166,7 +169,7 @@ ivas_error acelp_core_switch_dec_fx( Copy( syn_fx_tmp + M, synth_intFreq, 2 * L_SUBFR ); test(); - IF( st_fx->hPFstat->on && ( NE_16( st_fx->last_bwidth, NB ) ) ) + IF( st_fx->hPFstat->on && ( st_fx->last_bwidth != NB ) ) { Copy( st_fx->hPFstat->mem_pf_in + L_SYN_MEM - M, bpf_error_signal, M ); Copy( synth_intFreq, bpf_error_signal + M, L_SUBFR ); @@ -177,7 +180,6 @@ ivas_error acelp_core_switch_dec_fx( blend_subfr2_fx( bpf_error_signal + L_SUBFR / 2, synth_intFreq + L_SUBFR / 2, synth_intFreq + L_SUBFR / 2 ); } st_fx->hPFstat->on = 0; - move16(); IF( st_fx->flag_cna ) @@ -235,7 +237,7 @@ ivas_error acelp_core_switch_dec_fx( *Q_syn = 0; move16(); - Copy_Scale_sig( synth_intFreq + sub( NS2SA( i_mult( L_frame_for_cs, 50 ), L_sub( SWITCH_GAP_LENGTH_NS, DELAY_CLDFB_NS ) ), 2 ), mem_synth, add( NS2SA( i_mult( L_frame_for_cs, 50 ), DELAY_CLDFB_NS ), 2 ), negate( st_fx->Q_syn ) ); /* Copy mem with Q0 */ + Copy_Scale_sig( synth_intFreq + sub( NS2SA( i_mult( L_frame_for_cs, 50 ), ( SWITCH_GAP_LENGTH_NS - DELAY_CLDFB_NS ) ), 2 ), mem_synth, add( NS2SA( i_mult( L_frame_for_cs, 50 ), DELAY_CLDFB_NS ), 2 ), negate( st_fx->Q_syn ) ); /* Copy mem with Q0 */ /*----------------------------------------------------------------* * BWE decoding @@ -252,7 +254,7 @@ ivas_error acelp_core_switch_dec_fx( move16(); ind1 = (Word16) get_next_indice_fx( st_fx, NOOFGAINBITS1 ); move16(); - gain = usdequant_fx( ind1, MINVALUEOFFIRSTGAIN_FX, shr( DELTAOFFIRSTGAIN_FX, 3 ) ); /*Q13*/ + gain = usdequant_fx( ind1, MINVALUEOFFIRSTGAIN_FX, DELTAOFFIRSTGAIN_FX >> 3 ); /*Q13*/ decode_bwe = 1; move16(); } @@ -416,7 +418,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( tmp_noise = 0; move16(); - Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); + Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); // Q_exc exc = old_exc + L_EXC_MEM_DEC; IF( st_fx->hWIDec != NULL ) { @@ -429,7 +431,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( exc2 = old_exc2 + L_EXC_MEM; IF( st_fx->hBWE_TD != NULL ) { - Copy( st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); + Copy( st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); // Q_exc bwe_exc = old_bwe_exc + PIT16k_MAX * 2; } ELSE @@ -469,7 +471,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { Word16 gain_buf[NB_SUBFR16k]; - Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); + Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0 st_fx->Q_exc = 0; move16(); /* SC-VBR */ @@ -592,7 +594,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); /* output to Q0 */ - Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) ); + Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) ); // Q0 cldfb_restore_memory( st_fx->cldfbSyn ); @@ -663,7 +665,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( tmp_noise = 0; move16(); - Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); + Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); // Q_exc exc = old_exc + L_EXC_MEM_DEC; IF( st_fx->hWIDec != NULL ) { @@ -716,7 +718,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { Word16 gain_buf[NB_SUBFR16k]; - Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); + Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0 st_fx->Q_exc = 0; move16(); /* SC-VBR */ @@ -771,7 +773,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( Rescale_mem( Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, 0, NULL ); #ifdef FIX_907_MEM_UPDATE_ISSUE - Scale_sig( st_fx->mem_syn_r, L_SYN_MEM, sub( st_fx->Q_syn, Prev_Q_syn_r ) ); + Scale_sig( st_fx->mem_syn_r, L_SYN_MEM, sub( st_fx->Q_syn, Prev_Q_syn_r ) ); // Q_syn #endif Copy( st_fx->mem_syn2_fx, tmp1, M ); syn_12k8_fx( st_fx->L_frame, Aq, exc2, syn, tmp1, 1, Q_exc, st_fx->Q_syn ); @@ -820,12 +822,13 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( Copy( tmp5, hBPF->Track_on_hist, L_TRACK_HIST ); Copy( tmp6, hBPF->vibrato_hist, L_TRACK_HIST ); hBPF->psf_att_fx = tmp7; + move16(); /*----------------------------------------------------------------* * Resamping to the output sampling frequency *----------------------------------------------------------------*/ /* CLDFB analysis of the synthesis at internal sampling rate */ Qtmp = sub( 11, st_fx->Q_syn ); - Copy_Scale_sig_16_32( syn, syn32, L_FRAME16k, Qtmp ); + Copy_Scale_sig_16_32( syn, syn32, L_FRAME16k, Qtmp ); // Q(11) IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbAna ) ), IVAS_ERR_OK ) ) { return error; @@ -842,16 +845,17 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( } /*cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer );*/ - Scale_sig32( st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, 1 ); + Scale_sig32( st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, 1 ); // Q_cldfb_state+1 st_fx->cldfbSyn->Q_cldfb_state = add( st_fx->cldfbSyn->Q_cldfb_state, 1 ); move16(); Copy_Scale_sig_16_32( synth_out, synth32, L_FRAME48k, 5 ); /*11-5-1*/ // cldfbSynthesis_ivas_fx(realBuffer, imagBuffer, synth_out, (int16_t)(st_fx->output_Fs * 0.01f), st_fx->cldfbSyn); cldfbSynthesis_ivas_fx( realBuffer, imagBuffer, synth32, extract_l( Mpy_32_16_1( st_fx->output_Fs, 328 ) ), st_fx->cldfbSyn ); - Scale_sig32( st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, -1 ); + Scale_sig32( st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, -1 ); // Q_cldfb_state-1 st_fx->cldfbSyn->Q_cldfb_state = sub( st_fx->cldfbSyn->Q_cldfb_state, 1 ); - Copy_Scale_sig_32_16( synth32, synth_out, L_FRAME48k, -5 ); + move16(); + Copy_Scale_sig_32_16( synth32, synth_out, L_FRAME48k, -5 ); // 11-5-1 -> 11 // Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) ); @@ -871,19 +875,19 @@ static void decod_gen_voic_core_switch_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 L_frame, /* i : length of the frame */ const Word16 sharpFlag, /* i : flag for formant sharpening */ - const Word16 *Aq, /* i : LP filter coefficient */ - Word16 *exc, /* i/o: adapt. excitation exc */ + const Word16 *Aq, /* i : LP filter coefficient Q_12 */ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc */ const Word32 core_brate, /* i : switching frame bit-rate */ Word16 *Q_exc ) { Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables */ Word16 gain_pit, gain_code16; /* pitch gain */ Word32 gain_code, L_tmp; /* gain/normalized gain of the algebraic excitation */ - Word32 norm_gain_code; /* normalized gain of the algebraic excitation */ - Word16 gain_inov; /* Innovation gain */ - Word16 voice_fac; /* voicing factor */ - Word16 code[L_SUBFR]; /* algebraic codevector */ - Word16 pitch; /* pointer to floating pitch */ + Word32 norm_gain_code; /* normalized gain of the algebraic excitation Q16 */ + Word16 gain_inov; /* Innovation gain Q12 */ + Word16 voice_fac; /* voicing factor Q15*/ + Word16 code[L_SUBFR]; /* algebraic codevector Q9*/ + Word16 pitch; /* pointer to floating pitch Q6*/ Word16 i; /* tmp variables */ Word16 pitch_limit_flag; Word16 *pt1; diff --git a/lib_dec/ari_dec.c b/lib_dec/ari_dec.c index 7d63c3b342f0b7cd331828d23da8317718552fd2..2102356fa1350f155380b7c68958305a3934ee6f 100644 --- a/lib_dec/ari_dec.c +++ b/lib_dec/ari_dec.c @@ -113,15 +113,15 @@ Word16 ari_start_decoding_14bits_prm_ivas_fx( Word16 i; const Word16 *p; - val = L_deposit_l( 0 ); - + val = 0; + move32(); p = ptr + bp; FOR( i = 0; i < cbitsnew; i++ ) { val = L_or( L_shl( val, 1 ), *( p + i ) ); } - s->low = L_deposit_l( 0 ); + s->low = 0; move32(); s->high = ari_q4new; move32(); @@ -189,8 +189,7 @@ Word16 ari_decode_14bits_pow_ivas( move16(); k = sub( k, 1 ); symbol = (UWord16) L_shl( 1, k ); - move16(); - break; + BREAK; } } assert( k < 12 ); /* maximum 2^10-1*/ @@ -220,7 +219,6 @@ Word16 ari_decode_14bits_pow_ivas( highlim = 16384; move16(); move16(); - move16(); } @@ -238,7 +236,6 @@ Word16 ari_decode_14bits_pow_ivas( value = (UWord32) W_sub( value, ari_q2new ); low = L_sub( low, ari_q2new ); high = L_sub( high, ari_q2new ); - move32(); } ELSE { @@ -248,7 +245,6 @@ Word16 ari_decode_14bits_pow_ivas( value = (UWord32) W_sub( value, ari_q1new ); low = L_sub( low, ari_q1new ); high = L_sub( high, ari_q1new ); - move32(); } ELSE { @@ -262,7 +258,6 @@ Word16 ari_decode_14bits_pow_ivas( assert( abs( ptr[bp] ) <= 1 && "AC expects reading binary values!!!" ); value = (UWord32) ( W_shl( value, 1 ) | ptr[bp++] ); - move32(); } test(); @@ -340,6 +335,7 @@ Word16 ari_decode_14bits_sign_ivas( } ELSE { + test(); IF( GE_32( low, ari_q1new ) && LE_32( high, ari_q3new ) ) { value = (UWord32) W_sub( value, ari_q1new ); @@ -348,7 +344,7 @@ Word16 ari_decode_14bits_sign_ivas( } ELSE { - break; + BREAK; } } } diff --git a/lib_dec/arith_coder_dec.c b/lib_dec/arith_coder_dec.c index a4f4d7409304ba16f7b6b1efc5e80f2746b454b4..f41f4f5909cd8a4b6011b0134b2c4597b8303c62 100644 --- a/lib_dec/arith_coder_dec.c +++ b/lib_dec/arith_coder_dec.c @@ -120,11 +120,11 @@ static int16_t tcx_arith_decode( #ifdef IVAS_FLOAT_FIXED static Word16 tcx_arith_decode_ivas_fx( const Word16 L_frame, /* i : number of spectral lines */ - const Word16 envelope[], /* i : scaled envelope (Q15-e) */ + const Word16 envelope[], /* i : scaled envelope (Q15-envelope_e) */ Word16 envelope_e, /* i : scaled envelope exponent (Q0) */ const Word16 target_bits, /* i : target bit budget */ Word16 prm[], /* i : bitstream parameters */ - Word32 q_spectrum[], /* o : scalar quantized spectrum */ + Word32 q_spectrum[], /* o : scalar quantized spectrum (Q31-q_spectrum_e) */ Word16 *q_spectrum_e /* o : spectrum exponent */ ) { @@ -159,13 +159,13 @@ static Word16 tcx_arith_decode_ivas_fx( bp = ari_decode_14bits_sign_ivas( prm, bp, target_bits, &s, &as ); q_spectrum[k] = L_mult( q, sub( 3, shl( s, 1 ) ) ); move32(); - q_spectrum[k] = L_shl( q_spectrum[k], 30 - SPEC_EXP_DEC ); + q_spectrum[k] = L_shl( q_spectrum[k], 30 - SPEC_EXP_DEC ); // Q(31-20) move32(); } ELSE { /* line is zero, no sign needed */ - q_spectrum[k] = L_deposit_l( 0 ); + q_spectrum[k] = 0; move32(); } @@ -297,7 +297,7 @@ void tcx_arith_decode_envelope( #ifdef IVAS_FLOAT_FIXED void tcx_arith_decode_envelope_ivas_fx( Decoder_State *st, /* i/o: coder state */ - Word32 q_spectrum[], /* o : quantised MDCT coefficients */ + Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ Word16 *q_spectrum_e, /* o : MDCT exponent */ const Word16 L_frame, /* i : frame or MDCT length */ Word16 L_spec, /* i : length w/o BW limitation */ @@ -328,7 +328,7 @@ void tcx_arith_decode_envelope_ivas_fx( test(); test(); test(); - IF( GT_16( L_spec, N_MAX_ARI ) || ( EQ_16( st->element_mode, EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) || + IF( GT_16( L_spec, N_MAX_ARI ) || ( ( st->element_mode == EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) || ( EQ_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE / FRAMES_PER_SEC ) ) ) ) || ( GT_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE_CPE / FRAMES_PER_SEC ) ) ) ) || ( target_bits <= 0 ) ) diff --git a/lib_dec/avq_dec.c b/lib_dec/avq_dec.c index b0eef6b2fa04367a1be566bc834d3a98ca510339..8fc098d2d98e9b3b5d99e253b15f66bf1cf1d839 100644 --- a/lib_dec/avq_dec.c +++ b/lib_dec/avq_dec.c @@ -41,12 +41,12 @@ #include "wmc_auto.h" #include +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local prototypes *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void read_cv( Decoder_State *st, uint16_t *I, int16_t *kv, int16_t nq, int16_t *nbits ); -#endif /*-----------------------------------------------------------------* * AVQ_demuxdec() @@ -55,7 +55,6 @@ static void read_cv( Decoder_State *st, uint16_t *I, int16_t *kv, int16_t nq, in * split algebraic vector dequantizer based on RE8 latice. *-----------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void AVQ_demuxdec( Decoder_State *st, /* i/o: decoder state structure */ int16_t xriq[], /* o : decoded subvectors [0..8*Nsv-1]*/ diff --git a/lib_dec/bass_psfilter.c b/lib_dec/bass_psfilter.c index 47ca645bc800f7b3e21c4bc64d4b06c7f365dd7c..9d148712562bfc1ab35be32f8bc92bf3a7db6103 100644 --- a/lib_dec/bass_psfilter.c +++ b/lib_dec/bass_psfilter.c @@ -725,8 +725,8 @@ Word16 res_bpf_adapt_ivas_fx( W_tmp = W_add_nosat( W_tmp, W_mult0_32_32( res_buf[i], res_buf[i] ) ); } - res_hb_nrg = (Word32) W_shr( W_tmp, shl( q_res, 1 ) ); // Q0 - res_hb_nrg = Mpy_32_16_1( res_hb_nrg, bw_inv ); + res_hb_nrg = W_extract_l( W_shr( W_tmp, shl( q_res, 1 ) ) ); // Q0 + res_hb_nrg = Mpy_32_16_1( res_hb_nrg, bw_inv ); // Q0 res_hb_nrg = L_add( Mpy_32_16_1( res_hb_nrg, STEREO_DFT_BPF_ADAPT_ALPHA_FX ), Mpy_32_16_1( hStereoDft->res_hb_nrg_mem_fx, sub( MAX_16, STEREO_DFT_BPF_ADAPT_ALPHA_FX ) ) ); hStereoDft->res_hb_nrg_mem_fx = res_hb_nrg; move32(); @@ -738,7 +738,7 @@ Word16 res_bpf_adapt_ivas_fx( { tmp = L_sub( bpf_error_signal_8k[i], hStereoDft->bpf_error_signal_last_fx ); error_nrg = Madd_32_32( error_nrg, tmp, tmp ); - hStereoDft->bpf_error_signal_last_fx = bpf_error_signal_8k[add( i, ( STEREO_DFT_L_SUBFR_8k - 1 ) )]; + hStereoDft->bpf_error_signal_last_fx = bpf_error_signal_8k[( i + ( STEREO_DFT_L_SUBFR_8k - 1 ) )]; move32(); } error_nrg = L_shl( error_nrg, 1 ); // Q0 @@ -810,7 +810,7 @@ void bpf_pitch_coherence( #ifdef IVAS_FLOAT_FIXED void bpf_pitch_coherence_ivas_fx( Decoder_State *st, /* i/o: decoder state structure */ - const Word32 pitch_buf[] /* i : pitch for every subfr [0,1,2,3] */ + const Word32 pitch_buf[] /* i : pitch for every subfr [0,1,2,3] Q20 */ ) { Word16 nb_subfr; @@ -820,31 +820,31 @@ void bpf_pitch_coherence_ivas_fx( SWITCH( st->L_frame ) { case 80: - scaled_inv_L_frame = 26843545; + scaled_inv_L_frame = 26843545; // 1/80 in Q31 move32(); BREAK; case 160: - scaled_inv_L_frame = 13421773; + scaled_inv_L_frame = 13421773; // 1/160 in Q31 move32(); BREAK; case 256: - scaled_inv_L_frame = 8388608; + scaled_inv_L_frame = 8388608; // 1/256 in Q31 move32(); BREAK; case 320: - scaled_inv_L_frame = 6710886; + scaled_inv_L_frame = 6710886; // 1/320 in Q31 move32(); BREAK; case 512: - scaled_inv_L_frame = 4194304; + scaled_inv_L_frame = 4194304; // 1/512 in Q31 move32(); BREAK; case 640: - scaled_inv_L_frame = 3355443; + scaled_inv_L_frame = 3355443; // 1/640 in Q31 move32(); BREAK; case 960: - scaled_inv_L_frame = 2236962; + scaled_inv_L_frame = 2236962; // 1/80 in Q31 move32(); BREAK; default: @@ -854,27 +854,27 @@ void bpf_pitch_coherence_ivas_fx( nb_subfr = shr( st->L_frame, 6 ); test(); - IF( GT_16( st->clas_dec, UNVOICED_CLAS ) && NE_16( st->element_mode, EVS_MONO ) ) + IF( GT_16( st->clas_dec, UNVOICED_CLAS ) && ( st->element_mode != EVS_MONO ) ) { pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[nb_subfr + 3], st->old_pitch_buf_fx[nb_subfr + 2] ), L_add( st->old_pitch_buf_fx[nb_subfr], st->old_pitch_buf_fx[nb_subfr + 1] ) ) ); pc = Mpy_32_32( pc, scaled_inv_L_frame ); pcn1 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX ); - pcn1 = L_max( L_min( pcn1, 4096 ), 0 ); + pcn1 = L_max( L_min( pcn1, 4096 ), 0 ); // 4096 = 1 in Q12 pc = L_abs( L_sub( L_add( pitch_buf[nb_subfr - 1], pitch_buf[nb_subfr - 2] ), L_add( pitch_buf[1], pitch_buf[0] ) ) ); pc = Mpy_32_32( pc, scaled_inv_L_frame ); pcn2 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX ); - pcn2 = L_max( L_min( pcn2, 4096 ), 0 ); + pcn2 = L_max( L_min( pcn2, 4096 ), 0 ); // 4096 = 1 in Q12 pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[nb_subfr + 3], st->old_pitch_buf_fx[nb_subfr + 2] ), L_add( pitch_buf[1], pitch_buf[0] ) ) ); pc = Mpy_32_32( pc, scaled_inv_L_frame ); pcn3 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX ); - pcn3 = L_max( L_min( pcn3, 4096 ), 0 ); + pcn3 = L_max( L_min( pcn3, 4096 ), 0 ); // 4096 = 1 in Q12 - IF( LT_32( L_add( pcn1, L_add( pcn2, pcn3 ) ), 10240 ) ) + IF( LT_32( L_add( pcn1, L_add( pcn2, pcn3 ) ), 10240 /*2.5f in Q12*/ ) ) { - st->hBPF->psf_att_fx = 13107; - move16(); /*Q15*/ + st->hBPF->psf_att_fx = 13107; //.4 in Q15 + move16(); /*Q15*/ set16_fx( &st->hBPF->Track_on_hist[L_TRACK_HIST - nb_subfr], 1, nb_subfr ); } } diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index 51416a0aebd278b6f9166185dfd05c59b3f085b1..a3c76e23cb99e7a3aa4dbc1ba191eaa0e25f0ed3 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -490,11 +490,15 @@ void open_decoder_LPD_fx( lerp( hHQ_core->old_out_fx, hHQ_core->old_out_LB_fx, st->L_frame, hTcxDec->L_frameTCX ); Copy( hHQ_core->old_out_fx + nz, hTcxDec->syn_Overl_TDACFB, shr( hTcxDec->L_frameTCX, 1 ) ); /* exp(exp_old_out) */ + hTcxDec->Q_syn_Overl_TDACFB = hHQ_core->Q_old_wtda; + move16(); nz = NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS ); move16(); Copy( hHQ_core->old_out_LB_fx + nz, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); /* hHQ_core->q_old_outLB_fx */ hHQ_core->Q_old_wtda_LB = hHQ_core->Q_old_wtda; move16(); + hTcxDec->Q_syn_Overl_TDAC = hHQ_core->Q_old_wtda_LB; + move16(); } #else PMT( "acelp_plc_mdct_transition is missing" ) @@ -1210,11 +1214,15 @@ void acelp_plc_mdct_transition_fx( lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, st->hTcxDec->L_frameTCX ); Copy( st->hHQ_core->old_out_fx + nz, st->hTcxDec->syn_Overl_TDACFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); /* exp_old_out */ + st->hTcxDec->Q_syn_Overl_TDACFB = st->hHQ_core->Q_old_wtda; + move16(); nz = NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS ); Copy( st->hHQ_core->old_out_LB_fx + nz, st->hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); /* exp_old_out */ st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->Q_old_wtda; move16(); + st->hTcxDec->Q_syn_Overl_TDAC = st->hHQ_core->Q_old_wtda_LB; + move16(); } return; diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c index 4a6c372c67367f04a5eaa6fc33b930e889386c9b..47ab012a9d332c717f90105df617394403f8c15c 100644 --- a/lib_dec/core_switching_dec.c +++ b/lib_dec/core_switching_dec.c @@ -78,7 +78,7 @@ ivas_error core_switching_pre_dec_ivas_fx( Word16 i, oldLenClasBuff, newLenClasBuff; ivas_error error; Word16 exp = 25; - + move16(); error = IVAS_ERR_OK; move32(); @@ -86,7 +86,7 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); test(); test(); - IF( EQ_16( st->last_codec_mode, MODE2 ) || ( ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) && GT_16( st->element_mode, EVS_MONO ) ) ) + IF( EQ_16( st->last_codec_mode, MODE2 ) || ( ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) && ( st->element_mode > EVS_MONO ) ) ) { #ifndef FIX_770_DISCONTINUITIES_SW_TCX2ACELP Copy( st->mem_syn2_fx, st->mem_syn1_fx, M ); @@ -113,9 +113,9 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); IF( st->hPFstat != NULL ) { - Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, st->Q_syn ); /* Post_filter mem */ - Scale_sig( st->hPFstat->mem_res2, DECMEM_RES2, st->Q_syn ); /* NB post_filter mem */ - Scale_sig( st->hPFstat->mem_stp, L_SUBFR, st->Q_syn ); /* Post_filter mem */ + Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, st->Q_syn ); /* Post_filter mem ,Q_syn*/ + Scale_sig( st->hPFstat->mem_res2, DECMEM_RES2, st->Q_syn ); /* NB post_filter mem , Q_syn*/ + Scale_sig( st->hPFstat->mem_stp, L_SUBFR, st->Q_syn ); /* Post_filter mem ,Q_syn*/ set16_fx( st->hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* BPF mem*/ } IF( st->hBPF != NULL ) @@ -123,9 +123,10 @@ ivas_error core_switching_pre_dec_ivas_fx( st->hBPF->pst_lp_ener_fx = round_fx( L_shl( Mpy_32_16_1( st->lp_error_ener, 0x6054 ), 2 + 8 ) ); /* convert from 15Q16, log2 -> 7Q8 10*log10 */ st->hBPF->pst_mem_deemp_err_fx = 0; move16(); + move16(); } #endif - st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) ); + st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) ); // Q(23+1-16)->Q8 move16(); /* reset old HB synthesis buffer */ @@ -141,7 +142,7 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( st->hb_prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); test(); - IF( st->hBWE_TD != NULL && NE_16( st->last_core, ACELP_CORE ) ) + IF( st->hBWE_TD != NULL && ( st->last_core != ACELP_CORE ) ) { #ifdef MSAN_FIX st->hBWE_TD->prev_hb_synth_fx_exp = 31; @@ -183,8 +184,8 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX ); st->hHQ_core->last_max_pos_pulse = 0; - move16(); + IF( GT_32( st->output_Fs, 16000 ) ) { set32_fx( st->hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); @@ -196,7 +197,7 @@ ivas_error core_switching_pre_dec_ivas_fx( } /* reset the GSC pre echo energy threshold in case of switching */ - IF( st->hGSCDec != NULL ) + if ( st->hGSCDec != NULL ) { st->hGSCDec->Last_frame_ener_fx = MAX_32; move32(); @@ -205,7 +206,7 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) { - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == EVS_MONO ) { st->last_core = HQ_CORE; move16(); @@ -229,7 +230,7 @@ ivas_error core_switching_pre_dec_ivas_fx( } } - IF( NE_16( st->prev_bfi, 0 ) ) + IF( st->prev_bfi != 0 ) { Word16 delay_comp; @@ -243,11 +244,10 @@ ivas_error core_switching_pre_dec_ivas_fx( } delay_comp = NS2SA( st->output_Fs, DELAY_CLDFB_NS ); - /*TODO To be tested:control not entering the block*/ test(); test(); - IF( !st->last_con_tcx && EQ_16( st->last_core_bfi, ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) + IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) { /*TODO None of the test dtreams are entering this block,hence enabled assert(0)*/ assert( 0 ); @@ -265,12 +265,10 @@ ivas_error core_switching_pre_dec_ivas_fx( set32_fx( imagBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); realBuffer_fx[i] = realBufferTmp_fx[i]; imagBuffer_fx[i] = imagBufferTmp_fx[i]; - move32(); - move32(); } /* CLDFB analysis of the synthesis at internal sampling rate */ - IF( ( error = cldfb_save_memory_ivas_fx( st->cldfbAna ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbAna ) ), IVAS_ERR_OK ) ) { return error; } @@ -279,7 +277,7 @@ ivas_error core_switching_pre_dec_ivas_fx( cldfb_restore_memory_ivas_fx( st->cldfbAna ); /*Assuming Q10*/ /* CLDFB synthesis of the combined signal */ - IF( ( error = cldfb_save_memory_ivas_fx( st->cldfbSyn ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbSyn ) ), IVAS_ERR_OK ) ) { return error; } @@ -292,11 +290,11 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); test(); - IF( !st->last_con_tcx && EQ_16( st->last_core_bfi, ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) + IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) { - lerp( st->hTcxDec->syn_Overl, st->hHQ_core->fer_samples_fx + delay_comp, output_frame / 2, st->last_L_frame / 2 ); + lerp( st->hTcxDec->syn_Overl, st->hHQ_core->fer_samples_fx + delay_comp, shr( output_frame, 1 ), shr( st->last_L_frame, 1 ) ); /*Set to zero the remaining part*/ - set16_fx( st->hHQ_core->fer_samples_fx + delay_comp + output_frame / 2, 0, ( output_frame / 2 ) - delay_comp ); + set16_fx( st->hHQ_core->fer_samples_fx + delay_comp + output_frame / 2, 0, sub( shr( output_frame, 1 ), delay_comp ) ); } } @@ -318,14 +316,14 @@ ivas_error core_switching_pre_dec_ivas_fx( { oldLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->last_L_frame, st->L_frame ) ); newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + move16(); } ELSE { oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + move16(); newLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->L_frame, st->last_L_frame ) ); } - move16(); - move16(); lerp( &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff ); } } @@ -339,7 +337,7 @@ ivas_error core_switching_pre_dec_ivas_fx( within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */ test(); test(); - IF( EQ_16( st->core, ACELP_CORE ) && ( NE_16( st->last_core, ACELP_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) ) ) + IF( ( st->core == ACELP_CORE ) && ( ( st->last_core != ACELP_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) ) ) { st->last_ppp_mode_dec = 0; st->last_nelp_mode_dec = 0; @@ -351,7 +349,7 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); test(); test(); - IF( EQ_16( st->core, ACELP_CORE ) && ( NE_16( st->last_core, ACELP_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) || LE_32( st->last_total_brate, PPP_NELP_2k80 ) ) ) + IF( ( st->core == ACELP_CORE ) && ( ( st->last_core != ACELP_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) || LE_32( st->last_total_brate, PPP_NELP_2k80 ) ) ) { st->act_count = 3; st->uv_count = 0; @@ -370,11 +368,11 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); test(); test(); - IF( ( ( EQ_16( st->core, ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && EQ_16( st->last_core, HQ_CORE ) ) || ( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( nchan_out, 2 ) && - NE_32( st->core_brate, SID_2k40 ) && NE_32( st->core_brate, FRAME_NO_DATA ) && ( EQ_32( last_core_brate_st0, FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) ) ) + IF( ( ( ( st->core == ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && EQ_16( st->last_core, HQ_CORE ) ) || ( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( nchan_out, 2 ) && + NE_32( st->core_brate, SID_2k40 ) && ( st->core_brate != FRAME_NO_DATA ) && ( ( last_core_brate_st0 == FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) ) ) { test(); - IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) + if ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) { st->hPFstat->reset = 1; move16(); @@ -403,7 +401,7 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); test(); test(); - IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && EQ_16( nchan_out, 2 ) && GT_32( st->core_brate, SID_2k40 ) && ( EQ_32( last_core_brate_st0, FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) && st->hTcxDec != NULL ) + IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && EQ_16( nchan_out, 2 ) && GT_32( st->core_brate, SID_2k40 ) && ( ( last_core_brate_st0 == FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) && st->hTcxDec != NULL ) { /* Last frame was Stereo CNG and the synthesis memory is outdated -- reset */ set16_fx( st->hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); @@ -417,7 +415,7 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( st->mem_syn2_fx, 0, M ); } set16_fx( st->mem_syn1_fx, 0, M ); - IF( st->hBWE_TD != NULL ) + if ( st->hBWE_TD != NULL ) { st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move32(); @@ -452,7 +450,9 @@ ivas_error core_switching_pre_dec_ivas_fx( st->lp_gainp_fx = 0; move16(); st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/ - st->lp_gainc_fx = shr( st->lp_gainc_fx, 12 - exp ); /*Q3*/ + move16(); + st->lp_gainc_fx = shr( st->lp_gainc_fx, sub( 12, exp ) ); /*Q3*/ + move16(); st->last_voice_factor_fx = 0; st->Last_GSC_noisy_speech_flag = 0; @@ -467,7 +467,7 @@ ivas_error core_switching_pre_dec_ivas_fx( /* reset TBE memories */ test(); test(); - IF( !st->last_con_tcx && !( ( EQ_16( st->last_core, HQ_CORE ) ) && GT_16( st->element_mode, EVS_MONO ) ) ) + IF( !st->last_con_tcx && !( ( EQ_16( st->last_core, HQ_CORE ) ) && ( st->element_mode > EVS_MONO ) ) ) { set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); } @@ -500,7 +500,7 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); test(); test(); - IF( ( EQ_16( st->core, ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) ) + IF( ( ( st->core == ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) ) { IF( st->hBWE_TD != NULL ) { @@ -525,7 +525,9 @@ ivas_error core_switching_pre_dec_ivas_fx( st->lp_gainp_fx = 0; move16(); st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/ - st->lp_gainc_fx = shr( st->lp_gainc_fx, 12 - exp ); /*Q3*/ + move16(); + st->lp_gainc_fx = shr( st->lp_gainc_fx, sub( 12, exp ) ); /*Q3*/ + move16(); st->last_voice_factor_fx = 0; st->Last_GSC_noisy_speech_flag = 0; @@ -559,7 +561,7 @@ ivas_error core_switching_pre_dec_ivas_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for old_synth_lenFB (32 bit) \n" ) ); } - Copy_Scale_sig_16_32( st->hTcxDec->old_synthFB_fx, old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( Q10, Q_old_synthFB ) ); + Copy_Scale_sig_16_32( st->hTcxDec->old_synthFB_fx, old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( Q10, Q_old_synthFB ) ); // Q10 Copy32( old_synthFB_fx + st->hTcxDec->old_synth_lenFB - offset, st->cldfbAna->cldfb_state_fx, offset ); st->cldfbAna->Q_cldfb_state = Q10; move16(); @@ -572,7 +574,7 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); test(); test(); - IF( EQ_16( st->core, HQ_CORE ) && ( EQ_16( st->last_core, ACELP_CORE ) || EQ_16( st->last_core, AMR_WB_CORE ) || ( ( NE_16( st->element_mode, EVS_MONO ) ) && ( NE_16( st->last_core, HQ_CORE ) ) ) ) ) + IF( EQ_16( st->core, HQ_CORE ) && ( ( st->last_core == ACELP_CORE ) || EQ_16( st->last_core, AMR_WB_CORE ) || ( ( ( st->element_mode != EVS_MONO ) ) && ( NE_16( st->last_core, HQ_CORE ) ) ) ) ) { set32_fx( st->hHQ_core->prev_env_fx, 0, SFM_N_WB ); set32_fx( st->hHQ_core->prev_normq_fx, 0, SFM_N_WB ); @@ -592,13 +594,14 @@ ivas_error core_switching_pre_dec_ivas_fx( set32_fx( st->hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); } - IF( NE_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode != EVS_MONO ) { /* Estimate mem_env_delta to reinit env_stab */ tmp_fx = L_max( 0, L_add( ENV_STAB_EST1_FX, L_add( Mult_32_16( st->stab_fac_smooth_lt_fx, ENV_STAB_EST2_FX ), Mult_32_16( st->log_energy_diff_lt_fx, ENV_STAB_EST3_FX ) ) ) ); /*Q12*/ st->hHQ_core->mem_env_delta = extract_l( L_min( MAX16B, tmp_fx ) ); /* Convert to Q12 and handle saturation */ - + move16(); + test(); IF( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) { set16_fx( st->hHQ_core->old_out_fx, 0, output_frame ); @@ -631,14 +634,15 @@ ivas_error core_switching_pre_dec_ivas_fx( /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */ IF( st->hHQ_core != NULL ) { - st->hHQ_core->pastpre--; - IF( LE_16( st->hHQ_core->pastpre, 0 ) ) + st->hHQ_core->pastpre = sub( st->hHQ_core->pastpre, 1 ); + move16(); + IF( st->hHQ_core->pastpre < 0 ) { reset_preecho_dec_fx( st->hHQ_core ); } } - - IF( EQ_32( st->core_brate, FRAME_NO_DATA ) ) + test(); + IF( st->core_brate == FRAME_NO_DATA ) { st->VAD = 0; st->m_frame_type = ZERO_FRAME; @@ -657,7 +661,7 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); move16(); /*switch on CNA on active frames*/ - IF( EQ_16( st->element_mode, EVS_MONO ) ) /* for IVAS modes, st->flag_cna is set earlier */ + IF( ( st->element_mode == EVS_MONO ) ) /* for IVAS modes, st->flag_cna is set earlier */ { test(); test(); @@ -677,7 +681,7 @@ ivas_error core_switching_pre_dec_ivas_fx( } } - IF( EQ_16( st->core, AMR_WB_CORE ) ) + if ( EQ_16( st->core, AMR_WB_CORE ) ) { st->cng_type = LP_CNG; move16(); @@ -688,18 +692,26 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); test(); test(); - IF( st->hFdCngDec && ( NE_16( st->last_L_frame, st->L_frame ) || NE_16( st->hFdCngDec->hFdCngCom->frameSize, st->L_frame ) || EQ_16( st->ini_frame, 0 ) || NE_16( st->bwidth, st->last_bwidth ) ) ) + IF( st->hFdCngDec && ( NE_16( st->last_L_frame, st->L_frame ) || NE_16( st->hFdCngDec->hFdCngCom->frameSize, st->L_frame ) || ( st->ini_frame == 0 ) || NE_16( st->bwidth, st->last_bwidth ) ) ) { /* || st->last_core == AMR_WB_CORE || st->last_codec_mode == MODE2)){*/ IF( NE_16( st->core, AMR_WB_CORE ) ) { - configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, st->rf_flag == 1 && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate, st->L_frame, st->last_L_frame, st->element_mode ); + test(); + IF( EQ_16( st->rf_flag, 1 ) && EQ_32( st->total_brate, ACELP_13k20 ) ) + { + configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, ACELP_9k60, st->L_frame, st->last_L_frame, st->element_mode ); + } + ELSE + { + configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, st->total_brate, st->L_frame, st->last_L_frame, st->element_mode ); + } } ELSE { configureFdCngDec_ivas_fx( st->hFdCngDec, WB, ACELP_8k00, st->L_frame, st->last_L_frame, st->element_mode ); - IF( st->VAD ) + if ( st->VAD ) { st->hFdCngDec->hFdCngCom->CngBitrate = st->total_brate; move32(); @@ -724,7 +736,7 @@ ivas_error core_switching_pre_dec_ivas_fx( IF( EQ_16( st->L_frame, L_FRAME ) ) { - FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) + FOR( i = 0; i < ( st->L_frame * 2 ); i++ ) { st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], (Word16) 20480 /* 0.6250f in Q15 */ ); move32(); @@ -732,7 +744,7 @@ ivas_error core_switching_pre_dec_ivas_fx( } ELSE { - FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) + FOR( i = 0; i < ( st->L_frame * 2 ); i++ ) { st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( L_shl( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], 1 ), (Word16) 26214 /* 1.6f in Q14 */ ); move32(); @@ -1772,7 +1784,7 @@ void bandwidth_switching_detect_ivas_fx( st_fx->bws_cnt1 = 0; move16(); } - ELSE IF( GT_32( st_fx->total_brate, ACELP_9k60 ) && LT_32( st_fx->last_core_brate, ACELP_9k60 ) && EQ_16( st_fx->bwidth, SWB ) && EQ_16( st_fx->last_bwidth, WB ) && EQ_16( st_fx->last_low_rate_mode, 0 ) ) + ELSE IF( GT_32( st_fx->total_brate, ACELP_9k60 ) && LT_32( st_fx->last_core_brate, ACELP_9k60 ) && EQ_16( st_fx->bwidth, SWB ) && EQ_16( st_fx->last_bwidth, WB ) && ( st_fx->last_low_rate_mode == 0 ) ) { st_fx->bws_cnt1 = add( st_fx->bws_cnt1, 1 ); move16(); @@ -1987,8 +1999,9 @@ void ivas_bw_switching_pre_proc_fx( Flag Overflow = 0; + move32(); - IF( GT_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode > EVS_MONO ) { test(); test(); @@ -1999,33 +2012,36 @@ void ivas_bw_switching_pre_proc_fx( test(); test(); test(); - IF( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) && st->hBWE_FD != NULL && !( LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) && !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) ) + test(); + IF( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) && st->hBWE_FD != NULL && !( LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) && !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) ) { /* Calculate tilt of the ACELP core synthesis - needed in SWB BWE decoding */ Word16 old_syn_12k8_16k_tmp_16fx[L_FRAME16k]; Copy_Scale_sig_32_16( old_syn_12k8_16k_fx, old_syn_12k8_16k_tmp_16fx, st->L_frame, sub( -1, Q ) ); - st->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_tmp_16fx, -1, st->L_frame ), sub( Q, 8 ) ) ); + st->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_tmp_16fx, -1, st->L_frame ), sub( Q, 8 ) ) ); // Q24+(Q-8) - 16 + move16(); } return; } + test(); test(); - test(); - IF( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) + IF( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) { /*----------------------------------------------------------------------* * Calculate tilt of the ACELP core synthesis *----------------------------------------------------------------------*/ st->tilt_wb_fx = ivas_calc_tilt_bwe_fx( old_syn_12k8_16k_fx, Q, st->L_frame ); - + move16(); /*-------------------------------------------------------------------------------* * Calculate frequency energy of 0~3.2kHz and 3.2~6.4kHz the ACELP core synthesis *-------------------------------------------------------------------------------*/ edct_fx( old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, &Q ); Word64 W_tmp = 0; + move64(); Word32 tmp; Word16 shift; FOR( i = 0; i < L_FRAME / 2; i++ ) @@ -2039,8 +2055,9 @@ void ivas_bw_switching_pre_proc_fx( tmp = getSqrtWord32( tmp ); st->enerLL_fx = tmp; + move32(); st->enerLL_fx_Q = shr( sub( add( Q, shift ), 32 ), 1 ); - + move16(); W_tmp = 0; move64(); FOR( ; i < L_FRAME; i++ ) @@ -2055,6 +2072,7 @@ void ivas_bw_switching_pre_proc_fx( st->enerLH_fx = tmp; move32(); st->enerLH_fx_Q = shr( sub( add( Q, shift ), 32 ), 1 ); + move16(); } ELSE { @@ -2090,7 +2108,6 @@ void ivas_bw_switching_pre_proc_fx( ELSE { Word32 tmp, L_tmp = 0; - L_tmp = 0; move32(); FOR( i = 0; i < L_FRAME / 2; i++ ) { @@ -2135,9 +2152,9 @@ void ivas_bw_switching_pre_proc_fx( set16_fx( st->prev_SWB_fenv_fx, 0, SWB_FENV ); } } - ELSE IF( ( ( EQ_16( st->core, ACELP_CORE ) && ( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st->core, st->last_core ) && NE_16( st->extl, st->last_extl ) ) ) && GE_16( st->last_bwidth, SWB ) ) + ELSE IF( ( ( ( st->core == ACELP_CORE ) && ( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st->core, st->last_core ) && NE_16( st->extl, st->last_extl ) ) ) && GE_16( st->last_bwidth, SWB ) ) { - st->attenu_fx = 3277; + st->attenu_fx = 3277; // 0.1f in Q15 move16(); } @@ -2146,7 +2163,7 @@ void ivas_bw_switching_pre_proc_fx( test(); test(); test(); - IF( EQ_16( st->last_core, HQ_CORE ) || ( EQ_16( st->last_core, ACELP_CORE ) && !( EQ_16( st->last_extl, WB_TBE ) || EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) && GT_32( st->core_brate, ACELP_8k00 ) ) ) + if ( EQ_16( st->last_core, HQ_CORE ) || ( ( st->last_core == ACELP_CORE ) && !( EQ_16( st->last_extl, WB_TBE ) || EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) && GT_32( st->core_brate, ACELP_8k00 ) ) ) { st->prev_fractive = 0; move16(); diff --git a/lib_dec/d_gain2p.c b/lib_dec/d_gain2p.c index bd2366c9a5fb008cb98c66f24674da625a7bcb6a..59b87905882fd3373eaff124eba2e743c8cb0a61 100644 --- a/lib_dec/d_gain2p.c +++ b/lib_dec/d_gain2p.c @@ -42,12 +42,13 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* * Mode2_gain_dec_mless_flt * * Decoding of pitch and codebook gains without updating long term energies *-------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void Mode2_gain_dec_mless_flt( const int16_t index, /* i : index of quantizer */ const float code[], /* i : Innovative code vector */ @@ -132,7 +133,6 @@ static void Mode2_gain_dec_mless_flt( return; } -#endif /*---------------------------------------------------------------------* @@ -140,7 +140,7 @@ static void Mode2_gain_dec_mless_flt( * * Decoding of pitch and codebook gains for Unvoiced mode *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void gain_dec_uv( const int16_t index, /* i/o: Quantization index vector */ const float *code, /* i : algebraic code excitation */ @@ -179,15 +179,13 @@ static void gain_dec_uv( return; } -#endif - /*---------------------------------------------------------------------* * gain_dec_gacelp_uv * * Decoding of pitch and codebook gains for Unvoiced mode *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void gain_dec_gacelp_uv( int16_t index, /* i/o: Quantization index vector */ const float *code, /* i : algebraic code excitation */ @@ -239,15 +237,13 @@ void gain_dec_gacelp_uv( return; } -#endif - /*---------------------------------------------------------------------* * decode_acelp_gains * * *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void decode_acelp_gains( const float *code, const int16_t gains_mode, diff --git a/lib_dec/d_gain2p_fx.c b/lib_dec/d_gain2p_fx.c index b93accc7289bda1537e2155faddf442b0f9d5c48..fe916acf3404aae1fc619670f5bad662c023b504 100644 --- a/lib_dec/d_gain2p_fx.c +++ b/lib_dec/d_gain2p_fx.c @@ -17,18 +17,19 @@ * private functions * *********************/ static Word32 calc_gcode0_fx( - Word16 *gcode0, - Word16 *exp_gcode0 ) + Word16 *gcode0, // Q8 + Word16 *exp_gcode0 // Q0 +) { Word32 L_tmp; /*gcode0 = (float)pow(10.0,(gcode0)*0.05);*/ /* predicted gain */ - L_tmp = L_mult( *gcode0, 5443 /*0.166096f Q15*/ ); - *exp_gcode0 = add( 1, extract_l( L_shr( L_tmp, 24 ) ) ); + L_tmp = L_mult( *gcode0, 5443 /*0.166096f Q15*/ ); // Q24 + *exp_gcode0 = add( 1, extract_l( L_shr( L_tmp, 24 ) ) ); // Q0 move16(); - L_tmp = L_lshl( L_tmp, 7 ); - L_tmp = L_and( 0x7FFFFFFF, L_tmp ); + L_tmp = L_lshl( L_tmp, 7 ); // Q31 + L_tmp = L_and( 0x7FFFFFFF, L_tmp ); // 0x7FFFFFFF-> 1 in Q31 L_tmp = Pow2( 30, round_fx( L_tmp ) ); *gcode0 = round_fx( L_tmp ); @@ -81,7 +82,6 @@ static void Mode2_gain_dec_mless_fx( /**gain_inov = 1.0f / (float)sqrt( ( dot_product( code, code, lcode ) + 0.01f ) / lcode);*/ L_tmp = calc_gain_inov( code, lcode, &L_tmp1, &exp_L_tmp1 ); - move16(); #ifdef BASOP_NOGLOB *gain_inov = round_fx_sat( L_shl_sat( L_tmp, 15 - 3 ) ); /* gain_inov in Q12 */ #else @@ -176,9 +176,8 @@ static void gain_dec_uv_fx( *-----------------------------------------------------------------*/ /* *gain_inov = 1.0f / (float)sqrt( ( dot_product( code, code, lcode ) + 0.01f ) / lcode );*/ L_tmp = calc_gain_inov( code, lcode, &L_tmp1, &exp_L_tmp1 ); - move16(); *gain_inov = round_fx( L_shl( L_tmp, 15 - 3 ) ); /* gain_inov in Q12 */ - + move16(); /*-----------------------------------------------------------------* * Decode pitch gain *-----------------------------------------------------------------*/ @@ -192,7 +191,7 @@ static void gain_dec_uv_fx( L_tmp = L_mac( -167197708l /*-0.166096*30.0f Q25*/, shl( index, 16 - 7 ), 10341 /*0.166096f*1.9f Q15*/ ); i = add( 1, extract_l( L_shr( L_tmp, 25 ) ) ); L_tmp = L_lshl( L_tmp, 6 ); - L_tmp = L_and( 0x7FFFFFFF, L_tmp ); + L_tmp = L_and( 0x7FFFFFFF, L_tmp ); // 0x7FFFFFFF ->1 in Q31 L_tmp = Pow2( 30, round_fx( L_tmp ) ); L_tmp = L_shl( L_tmp, sub( i, ( 31 - 16 ) ) ); /* Q16 */ @@ -290,7 +289,7 @@ static void gain_dec_gacelp_uv_fx( * past gains for error concealment *-----------------------------------------------------------------*/ index2 = shr( index, 5 ); - index = s_and( index, 0x1F ); + index = s_and( index, 0x1F ); // 0x1F -> 31 /**gain_code= (float)pow(10.f,(((index*1.25f)-20.f)/20.f))*gcode;*/ @@ -298,10 +297,10 @@ static void gain_dec_gacelp_uv_fx( i = add( 1, extract_l( L_shr( L_tmp, 25 ) ) ); L_tmp = L_lshl( L_tmp, 6 ); - L_tmp = L_and( 0x7FFFFFFF, L_tmp ); + L_tmp = L_and( 0x7FFFFFFF, L_tmp ); // 0x7FFFFFFF-> 1 in Q31 L_tmp = Pow2( 30, round_fx( L_tmp ) ); - L_tmp = L_shl( L_tmp, i - ( 31 - 16 ) ); /* Q16 */ + L_tmp = L_shl( L_tmp, sub( i, ( 31 - 16 ) ) ); /* Q16 */ /* *past_gcode = L_tmp * pred_nrg_frame; */ i = norm_l( L_tmp ); @@ -421,10 +420,10 @@ void d_gain_pred_fx( move16(); } - if ( GT_16( nrg_mode, 2 ) ) + IF( GT_16( nrg_mode, 2 ) ) { - move16(); *Es_pred = extract_l( L_mac( -335544320l /* -20.f Q24*/, indice, 224 /* 1.75f Q7*/ ) ); /*(Q8 - ((Q0*Q7)=Q8))*/ + move16(); } return; diff --git a/lib_dec/dec4t64.c b/lib_dec/dec4t64.c index 9563ac6439efb59a1117b549f7e3e965309e3a01..90e87043645bf69321e19a1b1f878c1b4c61a4ab 100644 --- a/lib_dec/dec4t64.c +++ b/lib_dec/dec4t64.c @@ -41,12 +41,11 @@ #include "ivas_prot.h" #include "rom_com.h" #include "wmc_auto.h" - +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void add_pulses( const int16_t pos[], const int16_t nb_pulse, const int16_t track, float code[] ); static void dec_1p_N1( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] ); static void dec_2p_2N1( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] ); @@ -56,7 +55,6 @@ static void dec_4p_4N( const int32_t index, const int16_t N, const int16_t offse static void dec_5p_5N( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] ); static void dec_6p_6N2( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] ); static void fcb_decode_PI( int32_t code_index, int16_t sector_6p[], const int16_t pulse_num ); -#endif /*----------------------------------------------------------------------------------* * dec_acelp_4t64() @@ -73,7 +71,6 @@ static void fcb_decode_PI( int32_t code_index, int16_t sector_6p[], const int16_ * See cod4t64.c for more details of the algebraic code. *----------------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void dec_acelp_4t64( Decoder_State *st, /* i/o: decoder state structure */ int16_t nbbits, /* i : number of bits per codebook */ @@ -264,7 +261,6 @@ void dec_acelp_4t64( return; } -#endif /*-------------------------------------------------------* * add_pulses() @@ -272,7 +268,6 @@ void dec_acelp_4t64( * Add decoded pulses to the codeword *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void add_pulses( const int16_t pos[], /* i : pulse position */ const int16_t nb_pulse, /* i : nb. of pulses */ @@ -297,14 +292,13 @@ static void add_pulses( return; } -#endif /*-------------------------------------------------------* * dec_1p_N1() * * Decode 1 pulse with N+1 bits *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void dec_1p_N1( const int32_t index, /* i : quantization index */ const int16_t N, /* i : nb. of bits */ @@ -377,8 +371,6 @@ void dec_2p_2N1( return; } -#endif - /*-------------------------------------------------------* * dec_3p_3N1() @@ -386,7 +378,6 @@ void dec_2p_2N1( * Decode 3 pulses with 3*N+1 bits: *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void dec_3p_3N1( const int32_t index, /* i : quantization index */ const int16_t N, /* i : nb. of bits */ @@ -534,14 +525,13 @@ static void dec_5p_5N( return; } -#endif /*-------------------------------------------------------* * dec_6p_6N2() * * Decode 6 pulses with 6*N+2 bits: *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void dec_6p_6N2( const int32_t index, /* i : quantization index */ const int16_t N, /* i : nb. of bits */ @@ -697,7 +687,7 @@ static void fcb_decode_position( return; } -#endif + /*---------------------------------------------------------------------* * fcb_decode_PI() @@ -706,7 +696,7 @@ static void fcb_decode_position( *---------------------------------------------------------------------*/ /*! r: return pulse position number */ -#ifndef IVAS_FLOAT_FIXED + static void fcb_decode_PI( int32_t code_index, /* i : fcb index information */ int16_t sector_6p[], /* o : decoded pulse position */ @@ -746,13 +736,12 @@ static void fcb_decode_PI( return; } -#endif + /*---------------------------------------------------------------------* * Read FCB index * *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void D_ACELP_decode_43bit( uint16_t idxs[], float code[], @@ -788,7 +777,6 @@ void D_ACELP_decode_43bit( return; } -#endif /*-------------------------------------------------------* * dec_1p_N1() @@ -796,7 +784,6 @@ void D_ACELP_decode_43bit( * Decode 1 pulse with N+1 bits *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void dec_1p_N1_L_subfr( const int32_t index, /* i : quantization index */ const int16_t nb_pos, /* i : number of positions */ @@ -820,7 +807,6 @@ static void dec_1p_N1_L_subfr( return; } -#endif /*-------------------------------------------------------* * add_pulses() @@ -828,7 +814,7 @@ static void dec_1p_N1_L_subfr( * Add decoded pulses to the codeword *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void add_pulses_L_subfr( const int16_t nb_pos, /* i : number of positions */ const int16_t pos[], /* i : pulse position */ @@ -854,14 +840,13 @@ static void add_pulses_L_subfr( return; } -#endif /*----------------------------------------------------------------------------------* * dec_acelp_fast() * * fast algebraic codebook decoder *----------------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void dec_acelp_fast( Decoder_State *st, /* i/o: decoder state structure */ const int16_t cdk_index, /* i : codebook index */ diff --git a/lib_dec/dec4t64_fx.c b/lib_dec/dec4t64_fx.c index 517b4f0b2b201d838b10493d0627f10e69a377a3..32774bd8eaba5793e91ef858659b9cad9b45c4d6 100644 --- a/lib_dec/dec4t64_fx.c +++ b/lib_dec/dec4t64_fx.c @@ -244,7 +244,7 @@ static void add_pulses_fx( const Word16 pos[], /* i: pulse position */ const Word16 nb_pulse, /* i: nb. of pulses */ const Word16 track, /* i: no. of the tracks */ - Word16 code[] /* i/o: decoded codevector */ + Word16 code[] /* i/o: decoded codevector Q9*/ ) { @@ -690,17 +690,17 @@ static void fcb_decode_position_fx( FOR( i = 0; i < pos_num - 1; i++ ) { /* k = PI_select_table[16-l][temp] - k ;*/ - k = L_sub( PI_select_table[L_sub( 16, l )][temp], k ); + k = L_sub( PI_select_table[( 16 - l )][temp], k ); - FOR( ; PI_select_table[L_sub( 16, l )][temp] >= k; l += 2 ); + FOR( ; PI_select_table[( 16 - l )][temp] >= k; l += 2 ); - IF( GT_32( k, PI_select_table[L_sub( 17, l )][temp] ) ) + IF( GT_32( k, PI_select_table[( 17 - l )][temp] ) ) { l = L_sub( l, 1 ); } /* k = PI_select_table[17-l][temp--] - k ;*/ - k = L_sub( PI_select_table[L_sub( 17, l )][temp], k ); + k = L_sub( PI_select_table[( 17 - l )][temp], k ); temp = sub( temp, 1 ); pos_vector[i] = extract_l( L_sub( l, 1 ) ); move16(); @@ -1067,7 +1067,7 @@ static void add_pulses_L_subfr_fx( const Word16 pos[], /* i : pulse position */ const Word16 nb_pulse, /* i : nb. of pulses */ const Word16 track, /* i : no. of the tracks */ - Word16 code[] /* i/o: decoded codevector */ + Word16 code[] /* i/o: decoded codevector Q12 */ ) { Word16 i, k; @@ -1095,7 +1095,7 @@ static void add_pulses_L_subfr_fx( void dec_acelp_fast_fx( Decoder_State *st, /* i/o: decoder state structure */ const Word16 cdk_index, /* i : codebook index */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ + Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ const Word16 L_subfr /* i : subframe length */ ) { @@ -1204,19 +1204,19 @@ void dec_acelp_fast_fx( i0 = shl( s_and( shr( index, 7 ), ( NB_POS_FCB_2T_128 - 1 ) ), 1 ); i1 = add( shl( s_and( index, ( NB_POS_FCB_2T_128 - 1 ) ), 1 ), 1 ); - code[i0] = -512; + code[i0] = -512; //-1 in Q9 move16(); IF( EQ_16( s_and( index, 0x2000 ), 0 ) ) { - code[i0] = 512; + code[i0] = 512; // 1 in Q9 move16(); } - code[i1] = -512; + code[i1] = -512; //-1 in Q9 move16(); IF( EQ_16( s_and( index, 0x40 ), 0 ) ) { - code[i1] = 512; + code[i1] = 512; // 1 in Q9 move16(); } } diff --git a/lib_dec/dec_LPD_fx.c b/lib_dec/dec_LPD_fx.c index 7a8abdd83c685d422a2199f29723ac1d671408bb..8e65aaa8ef170697e105f6ce919ed7637082555b 100644 --- a/lib_dec/dec_LPD_fx.c +++ b/lib_dec/dec_LPD_fx.c @@ -27,12 +27,12 @@ void decoder_LPD_fx( Word16 signal_outFB[], /* o : synthesis @output_FS */ Word16 *total_nbbits, /* i/o: number of bits / decoded bits */ Decoder_State *st, /* i/o: decoder memory state pointer */ - Word16 *bpf_noise_buf, /* i/o: BPF noise buffer */ + Word16 *bpf_noise_buf, /* i/o: BPF noise buffer Q0 */ Word16 bfi, /* i : BFI flag */ Word16 *bitsRead, /* o : number of read bits */ Word16 param[], /* o : buffer of parameters */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subfr*/ - Word16 *voice_factors, /* o : voicing factors */ + Word16 *pitch_buf, /* i/o: floating pitch values for each subfr Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ Word16 *ptr_bwe_exc /* o : excitation for SWB TBE */ ) { @@ -171,11 +171,12 @@ void decoder_LPD_fx( move16(); st->flagGuidedAcelp = 0; move16(); - st->nbLostCmpt++; + st->nbLostCmpt = add( st->nbLostCmpt, 1 ); move16(); st->core_brate = st->last_core_brate; move16(); st->core = GetPLCModeDecision_fx( st ); + move16(); } } ELSE @@ -285,7 +286,7 @@ void decoder_LPD_fx( test(); test(); test(); - IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->last_core, ACELP_CORE ) && LT_32( lsp_diff, 52428 ) && GT_32( lsp_diff, 3932 ) && EQ_16( st->next_coder_type, GENERIC ) && !st->prev_use_partial_copy && EQ_16( st->last_coder_type, UNVOICED ) && GE_16( st->rf_frame_type, RF_GENPRED ) ) + IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) && LT_32( lsp_diff, 52428 ) && GT_32( lsp_diff, 3932 ) && EQ_16( st->next_coder_type, GENERIC ) && !st->prev_use_partial_copy && EQ_16( st->last_coder_type, UNVOICED ) && GE_16( st->rf_frame_type, RF_GENPRED ) ) { Copy( &lsp[0], &lsp[M], M ); } @@ -300,7 +301,7 @@ void decoder_LPD_fx( Copy( &lsf[( k + 1 ) * M], &xsfnew_uw[k * M], M ); } } - ELSE IF( ( hTcxDec->enableTcxLpc != 0 && NE_16( st->core, ACELP_CORE ) ) || ( bfi && st->use_partial_copy && EQ_16( st->rf_frame_type, RF_TCXFD ) ) ) + ELSE IF( ( hTcxDec->enableTcxLpc != 0 && ( st->core != ACELP_CORE ) ) || ( bfi && st->use_partial_copy && EQ_16( st->rf_frame_type, RF_TCXFD ) ) ) { Word16 tcx_lpc_cdk; test(); @@ -350,7 +351,7 @@ void decoder_LPD_fx( test(); test(); test(); - IF( EQ_16( st->prev_use_partial_copy, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->core, ACELP_CORE ) && GE_16( st->prev_rf_frame_type, RF_GENPRED ) && EQ_16( st->coder_type, UNVOICED ) ) + IF( EQ_16( st->prev_use_partial_copy, 1 ) && ( st->last_core == ACELP_CORE ) && ( st->core == ACELP_CORE ) && GE_16( st->prev_rf_frame_type, RF_GENPRED ) && EQ_16( st->coder_type, UNVOICED ) ) { test(); IF( st->lpcQuantization && st->acelp_cfg.midLpc ) @@ -376,11 +377,11 @@ void decoder_LPD_fx( FOR( i = 0; i < M; i++ ) { move16(); - st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], 10923 /*1.0f/3.0f Q15*/ ), mult_r( st->lsfoldbfi0_fx[i], 10923 /*1.0f/3.0f Q15*/ ) ), mult_r( xsfnew_uw[add( imult1616( k, M ), i )], 10923 /*1.0f/3.0f Q15*/ ) ); + st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], 10923 /*1.0f/3.0f Q15*/ ), mult_r( st->lsfoldbfi0_fx[i], 10923 /*1.0f/3.0f Q15*/ ) ), mult_r( xsfnew_uw[( k * M ) + i], 10923 /*1.0f/3.0f Q15*/ ) ); move16(); st->lsfoldbfi1_fx[i] = st->lsfoldbfi0_fx[i]; move16(); - st->lsfoldbfi0_fx[i] = xsfnew_uw[add( imult1616( k, M ), i )]; + st->lsfoldbfi0_fx[i] = xsfnew_uw[( k * M ) + i]; } } } @@ -414,20 +415,20 @@ void decoder_LPD_fx( FOR( k = 0; k < st->numlpc; k++ ) { - Copy( &xsfnew_uw[k * M], &lsf[add( k, 1 ) * M], M ); + Copy( &xsfnew_uw[k * M], &lsf[( k + 1 ) * M], M ); IF( st->tcxonly ) { - E_LPC_lsf_lsp_conversion( &lsf[add( k, 1 ) * M], &lsp[add( k, 1 ) * M], M ); + E_LPC_lsf_lsp_conversion( &lsf[( k + 1 ) * M], &lsp[( k + 1 ) * M], M ); E_LPC_lsf_lsp_conversion( st->lsf_q_cng, st->lsp_q_cng, M ); } ELSE { - lsf2lsp_fx( &lsf[add( k, 1 ) * M], &lsp[add( k, 1 ) * M], M, st->sr_core ); + lsf2lsp_fx( &lsf[( k + 1 ) * M], &lsp[( k + 1 ) * M], M, st->sr_core ); lsf2lsp_fx( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core ); } - Copy( &lsp[add( k, 1 ) * M], &xspnew_uw[imult1616( k, M )], M ); + Copy( &lsp[( k + 1 ) * M], &xspnew_uw[( k * M )], M ); } } @@ -448,14 +449,14 @@ void decoder_LPD_fx( IF( st->enablePlcWaveadjust ) { - if ( EQ_16( st->core, ACELP_CORE ) ) + if ( ( st->core == ACELP_CORE ) ) { st->tonality_flag = 0; move16(); } if ( bfi ) { - st->plcInfo.nbLostCmpt++; + st->plcInfo.nbLostCmpt = add( st->plcInfo.nbLostCmpt, 1 ); move16(); } } @@ -485,6 +486,7 @@ void decoder_LPD_fx( IF( bfi == 0 ) { st->stab_fac_fx = lsf_stab_fx( &lsf[M], &lsf[0], 0, st->L_frame ); + move16(); } test(); @@ -537,7 +539,7 @@ void decoder_LPD_fx( test(); test(); test(); - if ( EQ_16( st->clas_dec, UNVOICED_CLAS ) || EQ_16( st->clas_dec, SIN_ONSET ) || EQ_16( st->clas_dec, INACTIVE_CLAS ) || EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, TRANSITION ) ) + if ( ( st->clas_dec == UNVOICED_CLAS ) || EQ_16( st->clas_dec, SIN_ONSET ) || EQ_16( st->clas_dec, INACTIVE_CLAS ) || EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, TRANSITION ) ) { st->relax_prev_lsf_interp = 1; move16(); @@ -565,7 +567,7 @@ void decoder_LPD_fx( } test(); - IF( bfi != 0 && NE_16( st->last_core, ACELP_CORE ) ) + IF( bfi != 0 && ( st->last_core != ACELP_CORE ) ) { /* PLC: [TCX: TD PLC] */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT @@ -616,8 +618,8 @@ void decoder_LPD_fx( { move16(); move16(); - st->mem_pitch_gain[sub( add( 2, ( sub( shl( st->nb_subfr, 1 ), 1 ) ) ), i )] = st->mem_pitch_gain[sub( add( 2, sub( st->nb_subfr, 1 ) ), i )]; - st->mem_pitch_gain[sub( add( 2, sub( st->nb_subfr, 1 ) ), i )] = pit_gain[i]; + st->mem_pitch_gain[2 + ( 2 * st->nb_subfr - 1 ) - i] = st->mem_pitch_gain[( ( 2 + ( st->nb_subfr - 1 ) ) - i )]; + st->mem_pitch_gain[2 + ( st->nb_subfr - 1 ) - i] = pit_gain[i]; } } } @@ -662,10 +664,12 @@ void decoder_LPD_fx( IF( st->tcxonly != 0 ) { st->stab_fac_fx = lsf_stab_fx( &lsf[M], &lsf[0], 0, L_FRAME ); + move16(); } ELSE { st->stab_fac_fx = lsf_stab_fx( &lsf[M], &lsf[0], 0, st->L_frame ); + move16(); } } @@ -724,16 +728,17 @@ void decoder_LPD_fx( /* Stability Factor */ IF( bfi == 0 ) { - st->stab_fac_fx = lsf_stab_fx( &lsf[( add( k, 1 ) ) * M], &lsf[k * M], 0, L_FRAME ); + st->stab_fac_fx = lsf_stab_fx( &lsf[( ( k + 1 ) ) * M], &lsf[k * M], 0, L_FRAME ); + move16(); } - E_LPC_f_lsp_a_conversion( &lsp[( add( k, 1 ) ) * M], Aq, M ); + E_LPC_f_lsp_a_conversion( &lsp[( ( k + 1 ) ) * M], Aq, M ); /* TCX decoder */ IGFDecRestoreTCX10SubFrameData( st->hIGFDec, k ); decoder_tcx_fx( st->hTcxCfg, prm, Aq, Aind, shr( L_frame, 1 ), shr( L_frameTCX, 1 ), - shr( st->hTcxCfg->tcx_coded_lines, 1 ), &synth[shr( imult1616( k, L_frame ), 1 )], &synthFB[shr( imult1616( k, L_frameTCX ), 1 )], st, st->coder_type, bfi, k, st->stab_fac_fx ); + shr( st->hTcxCfg->tcx_coded_lines, 1 ), &synth[k * L_frame / 2], &synthFB[k * L_frameTCX / 2], st, st->coder_type, bfi, k, st->stab_fac_fx ); } } @@ -756,7 +761,7 @@ void decoder_LPD_fx( test(); test(); test(); - IF( ( bfi || st->prev_bfi ) && st->plcInfo.Pitch_fx && ( EQ_16( st->plcInfo.concealment_method, TCX_NONTONAL ) ) ) + IF( ( bfi || st->prev_bfi ) && st->plcInfo.Pitch_fx && ( ( st->plcInfo.concealment_method == TCX_NONTONAL ) ) ) { lerp( synthFB, synth, L_frame, L_frameTCX ); test(); @@ -917,6 +922,7 @@ void decoder_LPD_fx( } /* use latest LPC set */ st->old_enr_LP = Enr_1_Az_fx( Aq + offset, L_SUBFR ); /*Q3*/ + move16(); } @@ -1001,7 +1007,7 @@ void decoder_LPD_fx( { if ( !bfi ) { - st->plcInfo.nbLostCmpt = extract_l( L_deposit_l( 0 ) ); + st->plcInfo.nbLostCmpt = 0; move16(); } diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index 1ba8222ead8d88ae9c8d078afbb9ef9ef8d5b8c8..81f2f14fd323aeafe8cf57fe44f44fd6cc85c6e1 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -22,15 +22,15 @@ void decoder_acelp_fx( Decoder_State *st, Word16 prm[], /* i : parameters */ Word16 A[], /* i : coefficients NxAz[M+1] */ - ACELP_config acelp_cfg, /* i : ACELP config */ + ACELP_config acelp_cfg, /* i : ACELP config Q12 */ Word16 synth[], /* i/o: synth[-2*LFAC..L_DIV] Q0 */ Word16 *pT, /* o : pitch for all subframe Q0 */ Word16 *pgainT, /* o : pitch gain for all subfr 1Q14 */ Word16 stab_fac, /* i : stability of isf */ - Word16 *pitch_buffer, /* o : pitch values for each subfr. */ - Word16 *voice_factors, /* o : voicing factors */ + Word16 *pitch_buffer, /* o : pitch values for each subfr. Q6 */ + Word16 *voice_factors, /* o : voicing factors Q15 */ const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ - Word16 *bwe_exc /* o : excitation for SWB TBE */ + Word16 *bwe_exc /* o : excitation for SWB TBE Q_exc */ ) { Word16 i, j, i_subfr; @@ -46,7 +46,7 @@ void decoder_acelp_fx( Word32 pitch_buf[NB_SUBFR16k]; Word16 dummy_pitch_buf[NB_SUBFR16k]; Word16 gain_inov; - Word16 mem_back[M]; + Word16 mem_back[M]; // Q_mem_back Word16 update_flg; Word16 Q_mem_back; /*Q format of mem_back*/ Word16 h1[L_FRAME_16k / 4 + 1]; @@ -61,9 +61,12 @@ void decoder_acelp_fx( /*Q formats of buffers */ Word16 prev_Q_syn; Word32 gain_code2 = 0; + move32(); Word16 code2[L_SUBFR]; Word16 error = 0; - Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ + move16(); + Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ + move16(); Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation */ Word16 lp_flag; @@ -96,6 +99,8 @@ void decoder_acelp_fx( move16(); move16(); move16(); + move16(); + move16(); gain_pit = 0; gain_code = 0; move16(); @@ -106,7 +111,9 @@ void decoder_acelp_fx( gain_code2 = 0; prev_gain_pit = 0; + move16(); tmp_noise = 0; + move16(); IF( EQ_16( st->nb_subfr, 4 ) ) { @@ -132,14 +139,16 @@ void decoder_acelp_fx( weights[3] = 8738 /*(float)4/15 Q15*/; weights[4] = 10923 /*float)5/15 Q15*/; } - st->Mode2_lp_gainp = L_deposit_l( 0 ); - st->Mode2_lp_gainc = L_deposit_l( 0 ); + st->Mode2_lp_gainp = 0; + move32(); + st->Mode2_lp_gainc = 0; + move32(); avoid_lpc_burst_on_recovery = 0; move16(); test(); test(); - IF( st->last_con_tcx && ( NE_16( st->L_frameTCX_past, st->L_frame ) ) && ( st->last_core != 0 ) ) + if ( st->last_con_tcx && ( NE_16( st->L_frameTCX_past, st->L_frame ) ) && ( st->last_core != 0 ) ) { avoid_lpc_burst_on_recovery = 1; move16(); @@ -152,9 +161,10 @@ void decoder_acelp_fx( /* Reset phase dispersion */ - IF( GT_16( st->last_core_bfi, ACELP_CORE ) ) + IF( st->last_core_bfi > ACELP_CORE ) { - st->dm_fx.prev_gain_code = L_deposit_l( 0 ); + st->dm_fx.prev_gain_code = 0; + move32(); set16_fx( st->dm_fx.prev_gain_pit, 0, 6 ); st->dm_fx.prev_state = 0; move16(); @@ -179,11 +189,11 @@ void decoder_acelp_fx( IF( LT_16( st->old_enr_LP, enr_LP ) ) { ratio = div_s( st->old_enr_LP, enr_LP ); /* Q15 */ - IF( LT_16( ratio, 26215 ) ) + IF( LT_16( ratio, 26215 /*.8f in Q15*/ ) ) { FOR( i = 0; i < L_EXC_MEM_DEC; i++ ) { - st->old_exc_fx[i] = mult_r( st->old_exc_fx[i], ratio ); + st->old_exc_fx[i] = mult_r( st->old_exc_fx[i], ratio ); // Q_exc move16(); } } @@ -203,7 +213,7 @@ void decoder_acelp_fx( exc = exc_buf + L_EXC_MEM_DEC; Copy( st->old_exc_fx, exc_buf, L_EXC_MEM_DEC ); *( exc + st->L_frame ) = 0; - + move16(); /* Init syn buffer */ syn = syn_buf + M; Copy( st->mem_syn2_fx, syn_buf, M ); @@ -212,7 +222,7 @@ void decoder_acelp_fx( * Fast recovery flag *------------------------------------------------------------------------*/ test(); - IF( st->prev_bfi && EQ_16( st->coder_type, VOICED ) ) + if ( st->prev_bfi && EQ_16( st->coder_type, VOICED ) ) { /*Force BPF to be applied fully*/ st->bpf_gain_param = 3; @@ -277,7 +287,7 @@ void decoder_acelp_fx( *-------------------------------------------------------*/ test(); - IF( EQ_16( st->use_partial_copy, 1 ) && st->acelp_cfg.gains_mode[idx] == 0 ) + if ( EQ_16( st->use_partial_copy, 1 ) && st->acelp_cfg.gains_mode[idx] == 0 ) { gain_pit = prev_gain_pit; move16(); @@ -338,7 +348,7 @@ void decoder_acelp_fx( move16(); T0_res = 1; move16(); - pitch_buf[idx] = L_deposit_h( L_SUBFR ); + pitch_buf[idx] = L_deposit_h( L_SUBFR ); // Q16 move32(); } @@ -347,7 +357,7 @@ void decoder_acelp_fx( tbe_celp_exc( st->L_frame, i_subfr, T0, T0_frac, &error, bwe_exc ); } - pitch_buffer[idx] = shl( add( shl( T0, 2 ), T0_frac ), 4 ); + pitch_buffer[idx] = shl( add( shl( T0, 2 ), T0_frac ), 4 ); // Q6 move16(); /*-------------------------------------------------------* @@ -386,7 +396,8 @@ void decoder_acelp_fx( } ELSE { - gain_code2 = L_deposit_l( 0 ); + gain_code2 = 0; + move32(); set16_fx( code2, 0, L_SUBFR ); } @@ -398,14 +409,16 @@ void decoder_acelp_fx( decode_acelp_gains_fx( code, acelp_cfg.gains_mode[idx], Es_pred, &gain_pit, &gain_code, &prm, &( st->past_gpit ), &( st->past_gcode ), &gain_inov, L_SUBFR, code2, &gain_code2 ); } - IF( st->use_partial_copy && st->rf_frame_type == RF_ALLPRED ) + test(); + if ( st->use_partial_copy && EQ_16( st->rf_frame_type, RF_ALLPRED ) ) { st->past_gcode = 0; move32(); } - IF( st->use_partial_copy && st->rf_frame_type == RF_NOPRED ) + test(); + if ( st->use_partial_copy && EQ_16( st->rf_frame_type, RF_NOPRED ) ) { - st->past_gpit = 67; + st->past_gpit = 67; //.004089f in Q14 move32(); } IF( st->igf != 0 ) @@ -449,21 +462,36 @@ void decoder_acelp_fx( * - Find the total excitation. * *-------------------------------------------------------*/ gain_code_tmp = gain_code; + move32(); gain_pit_tmp = gain_pit; - IF( i_subfr == 0 ) + move16(); + if ( i_subfr == 0 ) { gain_code_pre = 0; + move32(); } - IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->last_core, ACELP_CORE ) && ( EQ_16( st->use_partial_copy, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) ) + test(); + test(); + test(); + IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) && ( EQ_16( st->use_partial_copy, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) ) { - IF( i_subfr > 0 && GT_16( gain_pit, 20152 ) && GT_16( st->prev_tilt_code_dec_fx, 6553 ) && EQ_16( st->next_coder_type, VOICED ) && ( EQ_16( st->use_partial_copy, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( i_subfr > 0 && GT_16( gain_pit, 20152 /*1.23 in Q14*/ ) && GT_16( st->prev_tilt_code_dec_fx, 6553 /*1.23 in Q15*/ ) && EQ_16( st->next_coder_type, VOICED ) && ( EQ_16( st->use_partial_copy, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) ) { - gain_pit = mult( gain_pit, sub( 26214, mult( i_subfr, 51 ) ) ); + gain_pit = mult( gain_pit, sub( 26214 /*.8f in Q15*/, mult( i_subfr, 51 /*1.0f/640 in Q15*/ ) ) ); } ELSE IF( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, UNVOICED ) && NE_16( st->next_coder_type, UNVOICED ) && LT_32( gain_code, gain_code_pre ) ) { gain_code = 0; + move32(); } } gain_code_pre = gain_code; @@ -475,17 +503,18 @@ void decoder_acelp_fx( tmp2 = shr( L_SUBFR, 1 ); FOR( j = 0; j < 2; j++ ) { - FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ ) + FOR( i = ( tmp2 - ( L_SUBFR / 2 ) ); i < tmp2; i++ ) { /* code in Q9, gain_pit in Q14, gain_code in Q16; exc Q_new */ Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); Ltmp = L_shl( Ltmp, add( 5, st->Q_exc ) ); Ltmp = L_mac( Ltmp, gain_pit, exc[i + i_subfr] ); #ifdef BASOP_NOGLOB - exc2[add( i, i_subfr )] = round_fx_sat( L_shl_sat( Ltmp, 1 ) ); + exc2[( i + i_subfr )] = round_fx_sat( L_shl_sat( Ltmp, 1 ) ); #else exc2[i + i_subfr] = round_fx( L_shl( Ltmp, 1 ) ); #endif + move16(); Ltmp2 = Mpy_32_16_1( gain_code, code[i] ); Ltmp2 = L_shl( Ltmp2, add( 5, st->Q_exc ) ); Ltmp = L_add( Ltmp, Ltmp2 ); @@ -497,10 +526,11 @@ void decoder_acelp_fx( #endif BASOP_SATURATE_WARNING_ON_EVS #ifdef BASOP_NOGLOB - exc[add( i, i_subfr )] = round_fx_sat( Ltmp ); + exc[( i + i_subfr )] = round_fx_sat( Ltmp ); #else exc[i + i_subfr] = round_fx( Ltmp ); #endif + move16(); } tmp2 = L_SUBFR; move16(); @@ -556,7 +586,7 @@ void decoder_acelp_fx( * - update pitch lag for guided ACELP * *----------------------------------------------------------*/ test(); - IF( st->enableGplc && EQ_16( shr( i_subfr, 6 ), sub( st->nb_subfr, 1 ) ) ) + if ( st->enableGplc && EQ_16( shr( i_subfr, 6 ), sub( st->nb_subfr, 1 ) ) ) { st->T0_4th = T0; move16(); @@ -611,8 +641,10 @@ void decoder_acelp_fx( /* impulse response level = gain introduced by synthesis+deemphasis */ Ltmp = Dot_productSq16HQ( 0, h1, L_SUBFR, &st->last_gain_syn_deemph_e ); st->last_gain_syn_deemph_e = add( st->last_gain_syn_deemph_e, 10 /*scaling of h1[0] and E_UTIL_synthesis * 2*/ ); + move16(); #ifdef BASOP_NOGLOB - st->last_gain_syn_deemph = round_fx_sat( Sqrt32( Ltmp, &st->last_gain_syn_deemph_e ) ); + st->last_gain_syn_deemph = round_fx_sat( Sqrt32( Ltmp, &st->last_gain_syn_deemph_e ) ); // Q(15-last_gain_syn_deemph_e - (16)) + move16(); #else st->last_gain_syn_deemph = round_fx( Sqrt32( Ltmp, &st->last_gain_syn_deemph_e ) ); #endif @@ -660,14 +692,14 @@ void decoder_acelp_fx( move16(); } - Scale_sig( mem_back, M, sub( st->Q_syn, Q_mem_back ) ); + Scale_sig( mem_back, M, sub( st->Q_syn, Q_mem_back ) ); // Q_syn force_scale_syn = 0; move16(); + test(); test(); - test(); - IF( ( EQ_16( st->clas_dec, ONSET ) ) || ( ( GE_16( st->last_good, VOICED_TRANSITION ) ) && ( LT_16( st->last_good, INACTIVE_CLAS ) ) ) ) + if ( ( EQ_16( st->clas_dec, ONSET ) ) || ( ( GE_16( st->last_good, VOICED_TRANSITION ) ) && ( LT_16( st->last_good, INACTIVE_CLAS ) ) ) ) { force_scale_syn = 1; move16(); @@ -704,11 +736,12 @@ void decoder_acelp_fx( FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { Word16 idx = 0; + move16(); IF( i_subfr != 0 ) { idx = idiv1616( i_subfr, L_SUBFR ); } - *pT++ = round_fx( pitch_buf[idx] ); + *pT++ = round_fx( pitch_buf[idx] ); // Q0 } @@ -721,8 +754,10 @@ void decoder_acelp_fx( move16(); hTcxDec->tcxltp_third_last_pitch = hTcxDec->tcxltp_second_last_pitch; + move32(); hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; - st->old_fpitch = pitch_buf[sub( shr( st->L_frame, 6 ), 1 )]; + move32(); + st->old_fpitch = pitch_buf[( ( st->L_frame >> 6 ) - 1 )]; move32(); diff --git a/lib_dec/dec_acelp_fx.c b/lib_dec/dec_acelp_fx.c index 8379eec7e1d761da5eb5c63062326b84cc8f098d..f65ee4bf701a9cd04ba1789c02787f997c642b08 100644 --- a/lib_dec/dec_acelp_fx.c +++ b/lib_dec/dec_acelp_fx.c @@ -24,7 +24,7 @@ static void D_ACELP_decode_arithtrack_fx( Word16 v[], Word32 s, Word16 p, Word16 *---------------------------------------------------------------------*/ void D_ACELP_indexing_fx( - Word16 code[], + Word16 code[], // Q9 PulseConfig config, Word16 num_tracks, Word16 index[], @@ -142,7 +142,7 @@ void D_ACELP_indexing_fx( ELSE { fcb_pulse_track_joint_decode_fx( idxs, wordcnt, index_n, pulsestrack, num_tracks ); - FOR( track = sub( num_tracks, 1 ); track >= 1; track-- ) + FOR( track = ( num_tracks - 1 ); track >= 1; track-- ) { pulses = pulsestrack[track]; move16(); @@ -152,12 +152,13 @@ void D_ACELP_indexing_fx( /* divide by number of possible states: rest is actual state and * the integer part goes to next track */ s = index_n[track]; + move32(); /* decode state to actual pulse positions on track */ D_ACELP_decode_arithtrack_fx( code + track, s, pulses, num_tracks, 16 ); } ELSE /* track is empty */ { - FOR( k = track; k < imult1616( 16, num_tracks ); k += num_tracks ) + FOR( k = track; k < ( 16 * num_tracks ); k += num_tracks ) { code[k] = 0; move16(); @@ -209,12 +210,12 @@ static void D_ACELP_decode_arithtrack_fx( Word16 v[], Word32 s, Word16 p, Word16 FOR( ; p; p-- ) /* one pulse placed, so one less left */ { - IF( LT_32( s, pulsestostates[k][sub( p, 1 )] ) ) + IF( LT_32( s, pulsestostates[k][p - 1] ) ) { BREAK; } - s = L_sub( s, pulsestostates[k][sub( p, 1 )] ); + s = L_sub( s, pulsestostates[k][p - 1] ); IF( v[idx] != 0 ) /* there is a pulse here already = sign is known */ { @@ -271,7 +272,7 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in hi_to_low[4] = 1; move16(); - IF( GE_16( indx_flag, track_num ) ) + if ( GE_16( indx_flag, track_num ) ) { hi_to_low[4] = 9; move16(); @@ -279,7 +280,7 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in hi_to_low[7] = 1; move16(); - IF( GE_16( indx_flag_2, 1 ) ) + if ( GE_16( indx_flag_2, 1 ) ) { hi_to_low[7] = 9; move16(); @@ -289,7 +290,8 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in { IF( GE_16( indx_flag, track_num ) ) { - index = L_deposit_l( 0 ); + index = 0; + move32(); IF( GE_16( indx_flag_2, 1 ) ) { FOR( track = sub( wordcnt, 1 ); track >= 6; track-- ) @@ -320,8 +322,9 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in } ELSE { - index = L_deposit_l( 0 ); - FOR( track = sub( wordcnt, 1 ); track >= 2; track-- ) + index = 0; + move32(); + FOR( track = ( wordcnt - 1 ); track >= 2; track-- ) { index = L_add( L_lshl( index, 16 ), (UWord32) idxs[track] ); } @@ -340,7 +343,7 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in pulse_num1 = pulse_num[track_num1]; move16(); index = L_add( L_lshl( index, hi_to_low[pulse_num1] ), L_lshr( index_n[track_num1], low_len[pulse_num1] ) ); - FOR( track = sub( track_num, 1 ); track > 0; track-- ) + FOR( track = ( track_num - 1 ); track > 0; track-- ) { track_num1 = sub( track, 1 ); pulse_num0 = pulse_num[track_num1]; @@ -361,8 +364,9 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in } ELSE { - index = L_deposit_l( 0 ); - FOR( track = sub( wordcnt, 1 ); track >= 0; track-- ) + index = 0; + move32(); + FOR( track = ( wordcnt - 1 ); track >= 0; track-- ) { index = (UWord32) W_add( UL_lshl( index, 16 ), (UWord32) idxs[track] ); } diff --git a/lib_dec/dec_acelp_tcx_main_fx.c b/lib_dec/dec_acelp_tcx_main_fx.c index ad7117763bc403b7c06164a2ec87687ed92e5c78..9a14aaf7b5d458677d239c422ba54bac72618d08 100644 --- a/lib_dec/dec_acelp_tcx_main_fx.c +++ b/lib_dec/dec_acelp_tcx_main_fx.c @@ -56,7 +56,7 @@ static void decode_frame_type_fx( Decoder_State *st { /* ZERO Frame */ - IF( EQ_32( st->total_brate, FRAME_NO_DATA ) ) + IF( ( st->total_brate == FRAME_NO_DATA ) ) { st->bwidth = st->last_bwidth; move16(); @@ -68,7 +68,8 @@ static void decode_frame_type_fx( Decoder_State *st ELSE IF( EQ_32( st->total_brate, SID_2k40 ) ) { st->cng_type = get_next_indice( st, 1 ); - IF( NE_16( st->cng_type, FD_CNG ) ) + move16(); + if ( NE_16( st->cng_type, FD_CNG ) ) { st->BER_detect = 1; move16(); @@ -83,7 +84,7 @@ static void decode_frame_type_fx( Decoder_State *st frame_len_indicator = get_next_indice( st, 1 ); IF( EQ_16( st->bwidth, NB ) ) { - IF( frame_len_indicator ) + if ( frame_len_indicator ) { st->BER_detect = 1; move16(); @@ -103,7 +104,7 @@ static void decode_frame_type_fx( Decoder_State *st st->L_frame = L_FRAME16k; move16(); test(); - IF( st->last_total_brate == ACELP_16k40 || st->last_total_brate == ACELP_24k40 ) + IF( EQ_32( st->last_total_brate, ACELP_16k40 ) || EQ_32( st->last_total_brate, ACELP_24k40 ) ) { st->total_brate = st->last_total_brate; move32(); @@ -152,12 +153,15 @@ static void decode_frame_type_fx( Decoder_State *st /* Get bandwidth mode */ st->bwidth = get_next_indice( st, FrameSizeConfig[frame_size_index].bandwidth_bits ); + move16(); st->bwidth = add( st->bwidth, FrameSizeConfig[frame_size_index].bandwidth_min ); + move16(); } ELSE { st->bwidth = add( st->bwidth, FrameSizeConfig[frame_size_index].bandwidth_min ); + move16(); } IF( GT_16( st->bwidth, FB ) ) @@ -184,7 +188,7 @@ static void decode_frame_type_fx( Decoder_State *st Word16 dummyBit; dummyBit = (Word8) get_next_indice( st, 1 ); move16(); - IF( dummyBit != 0 ) + if ( dummyBit != 0 ) { st->BER_detect = 1; move16(); @@ -201,7 +205,7 @@ static void decode_frame_type_fx( Decoder_State *st IF( NE_16( st->last_codec_mode, MODE2 ) || !st->BER_detect ) { /* Mode or Rate Change */ - test(); + test(); test(); IF( ( EQ_16( st->m_frame_type, ACTIVE_FRAME ) || EQ_16( st->m_frame_type, SID_FRAME ) ) && ( s_or( s_or( s_or( s_or( (Word16) NE_32( st->total_brate, st->last_total_brate ), (Word16) NE_16( st->bwidth, st->last_bwidth ) ), (Word16) EQ_16( st->last_codec_mode, MODE1 ) ), (Word16) NE_16( st->rf_flag, st->rf_flag_last ) ), st->force_lpd_reset ) ) ) @@ -229,6 +233,7 @@ static void decode_frame_type_fx( Decoder_State *st IF( EQ_16( st->bwidth, NB ) ) { st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); + move16(); } ELSE { @@ -262,7 +267,7 @@ static void decode_frame_type_fx( Decoder_State *st { FOR( n = 0; n < shl( st->L_frame, 1 ); n++ ) { - st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth[n], 20480 ); + st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth[n], 20480 /*1.25f in Q14*/ ); move16(); } } @@ -270,7 +275,7 @@ static void decode_frame_type_fx( Decoder_State *st { FOR( n = 0; n < shl( st->L_frame, 1 ); n++ ) { - st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = mult_r( shl( st->hFdCngDec->hFdCngCom->olapBufferSynth[n], 1 ), 26214 ); + st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = mult_r( shl( st->hFdCngDec->hFdCngCom->olapBufferSynth[n], 1 ), 26214 /* 1/1.25 in Q15*/ ); move16(); } } @@ -301,12 +306,12 @@ static void decode_frame_type_fx( Decoder_State *st Word16 dec_acelp_tcx_frame_fx( Decoder_State *st, /* i/o: decoder state structure */ Word16 *concealWholeFrame, /* i/o: concealment flag */ - Word16 *pcmBuf, /* o : synthesis */ - Word16 *bpf_noise_buf, /* i/o: BPF noise buffer */ - Word16 *pcmbufFB, /* o : synthesis @output_FS */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 pitch_buf[] /* o : floating pitch for each subframe */ + Word16 *pcmBuf, /* o : synthesis Q0 */ + Word16 *bpf_noise_buf, /* i/o: BPF noise buffer Qx */ + Word16 *pcmbufFB, /* o : synthesis @output_FS Qx */ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation Q0 */ + Word16 *voice_factors, /* o : voicing factors Q15 */ + Word16 pitch_buf[] /* o : floating pitch for each subframe Q6 */ #ifdef IVAS_CODE_CNG , STEREO_CNG_DEC_HANDLE hStereoCng /* i : stereo CNG handle */ @@ -352,10 +357,15 @@ Word16 dec_acelp_tcx_frame_fx( { Word16 m_frame_type = st->m_frame_type; + move16(); Word16 bwidth = st->bwidth; + move16(); Word16 cng_type = st->cng_type; + move16(); Word16 L_frame = st->L_frame; + move16(); Word32 total_brate = st->last_total_brate; + move32(); decode_frame_type_fx( st #ifdef IVAS_CODE_CNG @@ -383,7 +393,7 @@ Word16 dec_acelp_tcx_frame_fx( move16(); st->L_frame = L_frame; move16(); - IF( st->ini_frame != 0 ) + if ( st->ini_frame != 0 ) { st->total_brate = total_brate; move32(); @@ -398,7 +408,7 @@ Word16 dec_acelp_tcx_frame_fx( test(); test(); - IF( ( NE_16( st->bwidth, st->last_bwidth ) ) || ( NE_16( st->rf_flag, st->rf_flag_last ) ) || ( NE_32( st->total_brate, st->last_total_brate ) ) ) + if ( ( NE_16( st->bwidth, st->last_bwidth ) ) || ( NE_16( st->rf_flag, st->rf_flag_last ) ) || ( NE_32( st->total_brate, st->last_total_brate ) ) ) { st->force_lpd_reset = 1; move16(); @@ -412,6 +422,7 @@ Word16 dec_acelp_tcx_frame_fx( IF( st->ini_frame == 0 && st->hTcxCfg != NULL ) { st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( SWB ); + move16(); } } ELSE diff --git a/lib_dec/dec_amr_wb_fx.c b/lib_dec/dec_amr_wb_fx.c index ea3fa74f515e7518e6c4f836f22be613fef3dd32..5e047e425cf13cf0adc6fe753097f8cfc8d9b0ef 100644 --- a/lib_dec/dec_amr_wb_fx.c +++ b/lib_dec/dec_amr_wb_fx.c @@ -17,12 +17,12 @@ void decod_amr_wb_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficients */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ + const Word16 *Aq_fx, /* i : LP filter coefficients Q12 */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ + Word16 *exc_fx, /* i/o: adapt. excitation exc Qx */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Qx */ Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ - Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *voice_factors_fx, /* o : voicing factors Q15 */ Word16 *gain_buf /* o : floating pitch gain for each subframe Q14 */ ) { @@ -50,13 +50,14 @@ void decod_amr_wb_fx( p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ - L_Voice_fac_ave = L_deposit_l( 0 ); + L_Voice_fac_ave = 0; + move32(); pitch_limit_flag = 0; move16(); /* always restrained pitch Q range in IO mode */ lp_flag = NORMAL_OPERATION; move16(); /* always restrained pitch Q range in IO mode */ - IF( LT_32( st_fx->core_brate, ACELP_11k60 ) ) + if ( LT_32( st_fx->core_brate, ACELP_11k60 ) ) { lp_flag = LOW_PASS; move16(); /* always restrained pitch Q range in IO mode */ @@ -77,7 +78,6 @@ void decod_amr_wb_fx( 0, NULL #endif ); - move16(); /*--------------------------------------------------------------* * Find the adaptive codebook vector *--------------------------------------------------------------*/ @@ -139,7 +139,7 @@ void decod_amr_wb_fx( /*voice_fac = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac;*/ L_tmp = L_mult( VF_2nd_PARAM_FX, mult_r( voice_fac_fx, voice_fac_fx ) ); L_tmp = L_mac( L_tmp, VF_1st_PARAM_FX, voice_fac_fx ); - voice_fac_fx = mac_r( L_tmp, VF_0th_PARAM_FX, 32767 ); + voice_fac_fx = mac_r( L_tmp, VF_0th_PARAM_FX, 32767 ); // 1.0f in Q15 Word16 idx; idx = 0; @@ -150,17 +150,17 @@ void decod_amr_wb_fx( } /*voice_factors[i_subfr/L_SUBFR] = min( max(0.0f, voice_fac), 1.0f);*/ - voice_factors_fx[idx] = s_min( s_max( 0, voice_fac_fx ), 32767 ); + voice_factors_fx[idx] = s_min( s_max( 0, voice_fac_fx ), 32767 /*1.0f in Q15*/ ); // Q15 move16(); p_Aq_fx += ( M + 1 ); pt_pitch_fx++; - L_Voice_fac_ave = L_mac( L_Voice_fac_ave, 8192, voice_fac_fx ); + L_Voice_fac_ave = L_mac( L_Voice_fac_ave, 8192, voice_fac_fx ); // .25f in Q15 gain_buf[idx] = gain_pit_fx; move16(); } - hAmrwb_IO->lt_voice_fac_fx = round_fx( L_Voice_fac_ave ); + hAmrwb_IO->lt_voice_fac_fx = round_fx( L_Voice_fac_ave ); // Q0 move16(); return; diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index f5fdb1dea51d511a864797333bdc383daba004eb..363c3a2d891499cc1eed6b130308f407f151933d 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -41,34 +41,41 @@ ivas_error decod_gen_voic_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 L_frame, /* i : length of the frame */ const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 *Aq_fx, /* i : LP filter coefficient Q12 */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8 */ const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6 */ + Word16 *voice_factors_fx, /* o : voicing factors Q15 */ + Word16 *exc_fx, /* i/o: adapt. excitation exc Q_exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Q_exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_exc */ Word16 *unbits, /* number of unused bits */ - Word16 *gain_buf ) + Word16 *gain_buf /*Q14*/ +) { Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ Word16 gain_pit_fx = 0; /* pitch gain Q14 */ - Word32 gain_code_fx = 0; /* gain/normalized gain of the algebraic excitation Q16 */ - Word32 norm_gain_code_fx = 0; /* normalized gain of the algebraic excitation Q16 */ - Word16 gain_inov_fx = 0; /* Innovation gain Q12 */ - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ - Word16 voice_fac_fx; /* voicing factor Q15 */ - Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */ + move16(); + Word32 gain_code_fx = 0; /* gain/normalized gain of the algebraic excitation Q16 */ + move32(); + Word32 norm_gain_code_fx = 0; /* normalized gain of the algebraic excitation Q16 */ + move32(); + Word16 gain_inov_fx = 0; /* Innovation gain Q12 */ + move16(); + Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ + Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ + Word16 voice_fac_fx; /* voicing factor Q15 */ + Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */ const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ Word16 i_subfr_fx, i; /* tmp variables */ Word16 error_fx = 0; - Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + move16(); + Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + move16(); Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ Word32 norm_gain_preQ_fx; Word16 pitch_limit_flag_fx; @@ -105,14 +112,8 @@ ivas_error decod_gen_voic_fx( MUSIC_POSTFILT_HANDLE hMusicPF; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); hMusicPF = st_fx->hMusicPF; @@ -142,12 +143,10 @@ ivas_error decod_gen_voic_fx( * ACELP subframe loop *------------------------------------------------------------------*/ - p_Aq_fx = Aq_fx; - move16(); /* pointer to interpolated LPC parameters */ - pt_pitch_fx = pitch_buf_fx; - move16(); /* pointer to the pitch buffer */ + p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ + pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ norm_gain_preQ_fx = 0; - move16(); + move32(); gain_preQ_fx = 0; move16(); set16_fx( code_preQ_fx, 0, L_SUBFR ); @@ -179,7 +178,7 @@ ivas_error decod_gen_voic_fx( *-----------------------------------------------------------------*/ test(); - IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_16( st_fx->coder_type, INACTIVE ) ) + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && ( st_fx->coder_type != INACTIVE ) ) { gain_code_fx = 0; move16(); @@ -209,14 +208,14 @@ ivas_error decod_gen_voic_fx( { gain_dec_mless_fx( st_fx, L_frame, st_fx->coder_type, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } - st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); // Q15 move16(); /*-----------------------------------------------------------------* * Transform domain contribution decoding *-----------------------------------------------------------------*/ test(); - IF( GE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) + IF( GE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) && ( st_fx->coder_type == INACTIVE ) ) { transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); } @@ -266,20 +265,21 @@ ivas_error decod_gen_voic_fx( /* Compute exc2 */ #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); - exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); + L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); // Q_exc+Q14+1+1 + exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc #else L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); exc2_fx[i + i_subfr_fx] = round_fx( L_add( L_tmp, Ltmp1 ) ); #endif - /* code in Q9, gain_pit in Q14 */ - L_tmp = L_mult( gain_code16, code_fx[i] ); + move16(); + /* gain_pit in Q14 */ + L_tmp = L_mult( gain_code16, code_fx[i] ); // Q_exc+Q9+1 #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat( L_tmp, 5 ); - L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); - L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ + L_tmp = L_shl_sat( L_tmp, 5 ); // Q_exc+Q9+1+5 + L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); // Q_exc+Q15 +1 + L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ - exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); + exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc move16(); #else L_tmp = L_shl( L_tmp, 5 ); @@ -316,7 +316,7 @@ ivas_error decod_gen_voic_fx( *----------------------------------------------------------------*/ test(); - IF( GT_32( st_fx->core_brate, ACELP_32k ) || EQ_16( st_fx->coder_type, INACTIVE ) ) + IF( GT_32( st_fx->core_brate, ACELP_32k ) || ( st_fx->coder_type == INACTIVE ) ) { Copy( exc_fx + i_subfr_fx, exc2_fx + i_subfr_fx, L_SUBFR ); } @@ -327,9 +327,8 @@ ivas_error decod_gen_voic_fx( } p_Aq_fx += ( M + 1 ); - move16(); pt_pitch_fx++; - gain_buf[idx] = gain_pit_fx; + gain_buf[idx] = gain_pit_fx; // Q14 move16(); } @@ -371,9 +370,7 @@ ivas_error decod_gen_voic_fx( shft_curr = sub( st_fx->L_frame, rint_pitch ); /*Q0*/ p_exc = exc2_fx + shft_curr; - move16(); p_syn = syn_tmp_fx + shft_curr; - move16(); curr_res_nrg = L_deposit_l( 1 ); curr_spch_nrg = L_deposit_l( 1 ); @@ -394,22 +391,22 @@ ivas_error decod_gen_voic_fx( IF( prev_res_nrg > 0 ) { expa = norm_l( prev_res_nrg ); - fraca = extract_h( L_shl( prev_res_nrg, expa ) ); - expa = sub( 30, expa + ( 2 * st_fx->prev_Q_exc_fr ) ); + fraca = extract_h( L_shl( prev_res_nrg, expa ) ); /* 2*st_fx->prev_Q_exc_fr -16+expa +1*/ + expa = sub( 30, add( expa, ( shl( st_fx->prev_Q_exc_fr, 1 ) ) ) ); expb = norm_l( curr_res_nrg ); #ifdef BASOP_NOGLOB - fracb = round_fx_sat( L_shl_sat( curr_res_nrg, expb ) ); + fracb = round_fx_sat( L_shl_sat( curr_res_nrg, expb ) ); /* 2*st_fx->Q_exc +expb+1 -16*/ #else fracb = round_fx( L_shl( curr_res_nrg, expb ) ); #endif expb = sub( 30, add( expb, shl( st_fx->Q_exc, 1 ) ) ); scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); + fracb = shl( fracb, scale ); // Q(15-expb)+scale expb = sub( expb, scale ); - enratio = div_s( fracb, fraca ); + enratio = div_s( fracb, fraca ); // Q(15-(expb-expa)) exp1 = sub( expb, expa ); Qenratio = sub( 15, exp1 ); } @@ -425,22 +422,22 @@ ivas_error decod_gen_voic_fx( IF( prev_spch_nrg > 0 ) { expa = norm_l( prev_spch_nrg ); - fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); + fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); /* 2*st_fx->prev_Q_syn_fr +expa+1-16*/ expa = sub( 30, add( expa, shl( st_fx->prev_Q_syn_fr, 1 ) ) ); expb = norm_l( curr_spch_nrg ); #ifdef BASOP_NOGLOB - fracb = round_fx_sat( L_shl_sat( curr_spch_nrg, expb ) ); + fracb = round_fx_sat( L_shl_sat( curr_spch_nrg, expb ) ); /* 2*st_fx->Q_syn +expb-16 */ #else fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); #endif expb = sub( 30, add( expb, shl( st_fx->Q_syn, 1 ) ) ); scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); + fracb = shl( fracb, scale ); // Q(15-expb) +scale expb = sub( expb, scale ); - sp_enratio = div_s( fracb, fraca ); + sp_enratio = div_s( fracb, fraca ); // Q(15-(expb-expa)) exp1 = sub( expb, expa ); Qsp_enratio = sub( 15, exp1 ); } @@ -461,7 +458,7 @@ ivas_error decod_gen_voic_fx( LT_16( shl_ro( enratio, sub( 10, Qenratio ), &Overflow ), 15360 ) && /*compare with 15.0 in Q10*/ GT_16( shl_ro( sp_enratio, sub( 15, Qsp_enratio ), &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/ LT_16( st_fx->bfi_pitch_fx, 9600 ) && /*Q6*/ - LT_16( pitch_buf_fx[sub( NB_SUBFR16k, 1 )], 9600 ) ) /*Q6*/ + LT_16( pitch_buf_fx[NB_SUBFR16k - 1], 9600 ) ) /*Q6*/ #else IF( GT_16( shl_r( enratio, 15 - Qenratio ), 8192 ) && /*compare with 0.25 in Q15*/ LT_16( shl_r( enratio, 10 - Qenratio ), 15360 ) && /*compare with 15.0 in Q10*/ @@ -470,12 +467,12 @@ ivas_error decod_gen_voic_fx( pitch_buf_fx[sub( NB_SUBFR16k, 1 )] < 9600 ) /*Q6*/ #endif { - IF( ( error = DTFS_new_fx( &PREVP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = DTFS_new_fx( &PREVP ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = DTFS_new_fx( &CURRP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = DTFS_new_fx( &CURRP ) ), IVAS_ERR_OK ) ) { return error; } @@ -492,14 +489,14 @@ ivas_error decod_gen_voic_fx( ph_offset_fx = 0; move16(); - if ( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ), IVAS_ERR_OK ) ) { return error; } - Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); - Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); + Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc + Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc /* update bwe_exc for SWB-TBE */ FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR ) @@ -551,18 +548,18 @@ ivas_error decod_gen_voic_ivas_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 L_frame, /* i : length of the frame */ const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 *Aq_fx, /* i : LP filter coefficient Q12*/ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8 */ const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors_fx, /* o : voicing factors Q15 */ + Word16 *exc_fx, /* i/o: adapt. excitation exc Q_exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Q_exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_exc */ Word16 *unbits, /* number of unused bits */ Word16 *gain_buf, const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ ) { @@ -624,11 +621,11 @@ ivas_error decod_gen_voic_ivas_fx( gain_preQ_fx = 0; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif move16(); - move16(); - move16(); - move16(); + move32(); + move32(); move16(); move16(); move16(); @@ -661,12 +658,10 @@ ivas_error decod_gen_voic_ivas_fx( * ACELP subframe loop *------------------------------------------------------------------*/ - p_Aq_fx = Aq_fx; - move16(); /* pointer to interpolated LPC parameters */ - pt_pitch_fx = pitch_buf_fx; - move16(); /* pointer to the pitch buffer */ + p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ + pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ norm_gain_preQ_fx = 0; - move16(); + move32(); gain_preQ_fx = 0; move16(); set16_fx( code_preQ_fx, 0, L_SUBFR ); @@ -701,7 +696,7 @@ ivas_error decod_gen_voic_ivas_fx( *-----------------------------------------------------------------*/ test(); - IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_16( st_fx->coder_type, INACTIVE ) ) + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && ( st_fx->coder_type != INACTIVE ) ) { gain_code_fx = 0; move16(); @@ -731,14 +726,14 @@ ivas_error decod_gen_voic_ivas_fx( { gain_dec_mless_fx( st_fx, L_frame, st_fx->coder_type, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } - st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); + st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); // Q15 move16(); /*-----------------------------------------------------------------* * Transform domain contribution decoding *-----------------------------------------------------------------*/ test(); - IF( GE_32( st_fx->total_brate, MAX_GSC_INACTIVE_BRATE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) + IF( GE_32( st_fx->total_brate, MAX_GSC_INACTIVE_BRATE ) && ( st_fx->coder_type == INACTIVE ) ) { transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); } @@ -752,15 +747,31 @@ ivas_error decod_gen_voic_ivas_fx( IF( EQ_16( L_frame, L_FRAME ) ) /* Rescaling for 12.8k core */ { - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC] : NULL, hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + IF( ( bwe_exc_fx != NULL ) ) + { + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + } + ELSE + { + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], NULL, hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + } } ELSE /* Rescaling for 16k core */ { L_tmp_GC = L_max( gain_code_fx, L_shl( gain_preQ_fx, 16 ) ); /* Chose the maximum of gain_code or the prequantizer excitation x4 to keep some room*/ - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[i_subfr_fx * 2] : NULL, hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * 2, L_tmp_GC, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + IF( bwe_exc_fx != NULL ) + { + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * 2], hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * 2, L_tmp_GC, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + } + ELSE + { + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], NULL, hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * 2, L_tmp_GC, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + } } gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/ @@ -793,21 +804,20 @@ ivas_error decod_gen_voic_ivas_fx( /* Compute exc2 */ #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); - exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); - move16(); + exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc #else L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); exc2_fx[i + i_subfr_fx] = round_fx( L_add( L_tmp, Ltmp1 ) ); #endif - - /* code in Q9, gain_pit in Q14 */ - L_tmp = L_mult( gain_code16, code_fx[i] ); + move16(); + /* gain_pit in Q14 */ + L_tmp = L_mult( gain_code16, code_fx[i] ); // Q_exc+Q9+1 #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat( L_tmp, 5 ); - L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); - L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ + L_tmp = L_shl_sat( L_tmp, 5 ); // Q_exc+Q9+1+5 + L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); // Q_exc+16 + L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ - exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); + exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc move16(); #else L_tmp = L_shl( L_tmp, 5 ); @@ -863,7 +873,7 @@ ivas_error decod_gen_voic_ivas_fx( p_Aq_fx += ( M + 1 ); move16(); pt_pitch_fx++; - gain_buf[idx] = gain_pit_fx; + gain_buf[idx] = gain_pit_fx; // Q14 move16(); } @@ -878,11 +888,11 @@ ivas_error decod_gen_voic_ivas_fx( p_exc = st_fx->hWIDec->old_exc2_fx + shft_prev; p_syn = st_fx->hWIDec->old_syn2_fx + shft_prev; - move16(); - move16(); - prev_res_nrg = L_deposit_l( 1 ); - prev_spch_nrg = L_deposit_l( 1 ); + prev_res_nrg = 1; + move32(); + prev_spch_nrg = 1; + move32(); FOR( i = 0; i < rint_bfi_pitch; i++ ) { #ifdef BASOP_NOGLOB @@ -905,12 +915,12 @@ ivas_error decod_gen_voic_ivas_fx( shft_curr = sub( st_fx->L_frame, rint_pitch ); /*Q0*/ p_exc = exc2_fx + shft_curr; - move16(); p_syn = syn_tmp_fx + shft_curr; - move16(); - curr_res_nrg = L_deposit_l( 1 ); - curr_spch_nrg = L_deposit_l( 1 ); + curr_res_nrg = 1; + move32(); + curr_spch_nrg = 1; + move32(); FOR( i = 0; i < rint_pitch; i++ ) { curr_res_nrg = L_mac0( curr_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->Q_exc */ @@ -923,18 +933,18 @@ ivas_error decod_gen_voic_ivas_fx( IF( prev_res_nrg > 0 ) { expa = norm_l( prev_res_nrg ); - fraca = extract_h( L_shl( prev_res_nrg, expa ) ); + fraca = extract_h( L_shl( prev_res_nrg, expa ) ); /* 2*st_fx->prev_Q_exc_fr +expa -16*/ expa = sub( 30, add( expa, shl( st_fx->prev_Q_exc_fr, 1 ) ) ); expb = norm_l( curr_res_nrg ); - fracb = round_fx( L_shl( curr_res_nrg, expb ) ); + fracb = round_fx( L_shl( curr_res_nrg, expb ) ); /* 2*st_fx->prev_Q_exc_fr +expb -16*/ expb = sub( 30, add( expb, shl( st_fx->Q_exc, 1 ) ) ); scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); + fracb = shl( fracb, scale ); // Q(15-expb)+scale expb = sub( expb, scale ); - enratio = div_s( fracb, fraca ); + enratio = div_s( fracb, fraca ); // Q(15-(expb-expa) exp1 = sub( expb, expa ); Qenratio = sub( 15, exp1 ); } @@ -950,18 +960,18 @@ ivas_error decod_gen_voic_ivas_fx( IF( prev_spch_nrg > 0 ) { expa = norm_l( prev_spch_nrg ); - fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); + fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); /* 2*st_fx->prev_Q_syn_fr -16 +expa */ expa = sub( 30, add( expa, shl( st_fx->prev_Q_syn_fr, 1 ) ) ); expb = norm_l( curr_spch_nrg ); - fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); + fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); /* 2*st_fx->Q_syn +expb -16*/ expb = sub( 30, add( expb, shl( st_fx->Q_syn, 1 ) ) ); scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); + fracb = shl( fracb, scale ); // Q(15-expb)+scale expb = sub( expb, scale ); - sp_enratio = div_s( fracb, fraca ); + sp_enratio = div_s( fracb, fraca ); // Q(15-(expb-expa)) exp1 = sub( expb, expa ); Qsp_enratio = sub( 15, exp1 ); } @@ -982,7 +992,7 @@ ivas_error decod_gen_voic_ivas_fx( LT_16( shl_ro( enratio, sub( 10, Qenratio ), &Overflow ), 15360 ) && /*compare with 15.0 in Q10*/ GT_16( shl_ro( sp_enratio, sub( 15, Qsp_enratio ), &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/ LT_16( st_fx->bfi_pitch_fx, 9600 ) && /*Q6*/ - LT_16( pitch_buf_fx[sub( NB_SUBFR16k, 1 )], 9600 ) ) /*Q6*/ + LT_16( pitch_buf_fx[( NB_SUBFR16k - 1 )], 9600 ) ) /*Q6*/ #else IF( GT_16( shl_r( enratio, 15 - Qenratio ), 8192 ) && /*compare with 0.25 in Q15*/ LT_16( shl_r( enratio, 10 - Qenratio ), 15360 ) && /*compare with 15.0 in Q10*/ @@ -991,12 +1001,12 @@ ivas_error decod_gen_voic_ivas_fx( pitch_buf_fx[sub( NB_SUBFR16k, 1 )] < 9600 ) /*Q6*/ #endif { - IF( ( error = DTFS_new_fx( &PREVP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = DTFS_new_fx( &PREVP ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = DTFS_new_fx( &CURRP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = DTFS_new_fx( &CURRP ) ), IVAS_ERR_OK ) ) { return error; } @@ -1013,14 +1023,14 @@ ivas_error decod_gen_voic_ivas_fx( ph_offset_fx = 0; move16(); - IF( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ), IVAS_ERR_OK ) ) { return error; } - Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); - Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); + Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc + Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc /* update bwe_exc for SWB-TBE */ FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR ) diff --git a/lib_dec/dec_higher_acelp_fx.c b/lib_dec/dec_higher_acelp_fx.c index 51a7ab962e2c727c049d1fec85e9571e235c4288..febbaa477949e1d46ec908ceac2c4157536058cb 100644 --- a/lib_dec/dec_higher_acelp_fx.c +++ b/lib_dec/dec_higher_acelp_fx.c @@ -35,6 +35,7 @@ void transf_cdbk_dec_fx( Word16 qdct; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif #ifdef IVAS_CODE Word16 avq_bit_sFlag; @@ -45,7 +46,7 @@ void transf_cdbk_dec_fx( avq_bit_sFlag = 0; move16(); - if ( GT_16( st_fx->element_mode, EVS_MONO ) ) + if ( ( st_fx->element_mode > EVS_MONO ) ) { move16(); avq_bit_sFlag = 1; @@ -55,7 +56,7 @@ void transf_cdbk_dec_fx( * Set bit-allocation *--------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.AVQ_cdk_bits[shr( i_subfr, 6 )]; + nBits = st_fx->acelp_cfg.AVQ_cdk_bits[( i_subfr >> 6 )]; move16(); /* increase # of AVQ allocated bits by unused bits from the previous subframe */ @@ -67,19 +68,19 @@ void transf_cdbk_dec_fx( index = (Word16) get_next_indice_fx( st_fx, G_AVQ_BITS ); - IF( EQ_16( st_fx->coder_type, INACTIVE ) ) + IF( ( st_fx->coder_type == INACTIVE ) ) { IF( GT_32( st_fx->core_brate, 56000 ) ) { - gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12 >> 1 ); + gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12 >> 1 ); // Q12 } ELSE IF( GT_32( st_fx->core_brate, 42000 ) ) { - gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12 >> 1 ); + gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12 >> 1 ); // Q12 } ELSE { - gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12 >> 1 ); + gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12 >> 1 ); // Q12 } L_tmp = Mult_32_16( gain_code, gain16 ); /* Q16 * Q12 - 15 -> Q13*/ @@ -97,17 +98,17 @@ void transf_cdbk_dec_fx( test(); IF( GT_32( st_fx->core_brate, ACELP_24k40 ) && LE_32( st_fx->core_brate, 42000 ) ) { - gain16 = gain_dequant_fx( index, G_AVQ_MIN_32kbps_Q15, G_AVQ_MAX_Q0, G_AVQ_BITS, &exp16 ); + gain16 = gain_dequant_fx( index, G_AVQ_MIN_32kbps_Q15, G_AVQ_MAX_Q0, G_AVQ_BITS, &exp16 ); // Q0 } ELSE { - gain16 = gain_dequant_fx( index, G_AVQ_MIN_Q15, G_AVQ_MAX_Q0, G_AVQ_BITS, &exp16 ); + gain16 = gain_dequant_fx( index, G_AVQ_MIN_Q15, G_AVQ_MAX_Q0, G_AVQ_BITS, &exp16 ); // Q0 } IF( Es_pred < 0 ) { - tmp16 = shr( negate( Es_pred ), 2 ); - L_tmp = L_mult( gain16, tmp16 ); /* Q0*Q8 -> Q9*/ + tmp16 = shr( negate( Es_pred ), 2 ); // Q8 + L_tmp = L_mult( gain16, tmp16 ); /* Q0*Q8 -> Q9*/ } ELSE { @@ -124,7 +125,7 @@ void transf_cdbk_dec_fx( test(); test(); test(); - IF( avq_bit_sFlag && GT_16( nBits, 85 ) && !harm_flag_acelp && ( EQ_16( st_fx->coder_type, GENERIC ) || EQ_16( st_fx->coder_type, TRANSITION ) || EQ_16( st_fx->coder_type, INACTIVE ) ) ) + IF( avq_bit_sFlag && GT_16( nBits, 85 ) && !harm_flag_acelp && ( EQ_16( st_fx->coder_type, GENERIC ) || EQ_16( st_fx->coder_type, TRANSITION ) || ( st_fx->coder_type == INACTIVE ) ) ) { trgtSvPos = 2; avq_bit_sFlag = 2; @@ -139,7 +140,7 @@ void transf_cdbk_dec_fx( #ifdef IVAS_CODE_AVQ AVQ_demuxdec_fx( st_fx, code_preQ, &nBits, 8, nq, avq_bit_sFlag, trgtSvPos ); Word16 q_Code_preQ; - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( ( st_fx->element_mode == EVS_MONO ) ) { q_Code_preQ = Q_AVQ_OUT_DEC; move16(); @@ -172,7 +173,7 @@ void transf_cdbk_dec_fx( test(); test(); - IF( EQ_16( st_fx->coder_type, INACTIVE ) || GT_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) || harm_flag_acelp ) + IF( ( st_fx->coder_type == INACTIVE ) || GT_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) || harm_flag_acelp ) { qdct = 0; move16(); @@ -203,7 +204,7 @@ void transf_cdbk_dec_fx( test(); test(); test(); - IF( st_fx->element_mode > EVS_MONO && NE_16( st_fx->coder_type, INACTIVE ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && !harm_flag_acelp && code_preQ[0] != 0 ) + IF( st_fx->element_mode > EVS_MONO && ( st_fx->coder_type != INACTIVE ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && !harm_flag_acelp && code_preQ[0] != 0 ) { // PMT("Fixed point taking accound of the scaling needs to be done here ") IF( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), 4 ) ) ) @@ -218,7 +219,7 @@ void transf_cdbk_dec_fx( } } - st_fx->last_code_preq = extract_h( code_preQ[L_SUBFR - 1] ); + st_fx->last_code_preq = extract_h( code_preQ[L_SUBFR - 1] ); // q_Code_preQ-16 move16(); #endif PREEMPH_FX( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &st_fx->mem_preemp_preQ_fx ); diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index 3328839ea35ddc5c7bc419323234807e85fef0f0..d04dc1b304ac347d7e8fc81217276cb2705cab0d 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -21,7 +21,7 @@ /*--------------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ /* _ (Word16*) pitch_buf_fx : floating pitch values for each subframe Q6 */ -/* _ (Word16*) code_fx : innovation */ +/* _ (Word16*) code_fx : innovation Q12 */ /*--------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ /* Decoder_State_fx *st_fx : decoder state structure */ @@ -80,6 +80,7 @@ void dec_pit_exc_fx( Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif use_fcb = 0; @@ -269,7 +270,7 @@ void dec_pit_exc_fx( * Find the total excitation *----------------------------------------------------------------------*/ - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )], hGSCDec->last_exc_dct_in_fx, + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[( i_subfr_fx * ( 2 * HIBND_ACB_L_FAC ) ) / 2], hGSCDec->last_exc_dct_in_fx, L_subfr_fx, shr( imult1616( L_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 ), gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type ); gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/ @@ -285,8 +286,8 @@ void dec_pit_exc_fx( FOR( i = 0; i < L_subfr_fx; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[add( i, i_subfr_fx )] ), 1 ); /*Q16+Q_exc*/ - exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ + L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/ + exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ #else L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/ exc_fx[i + i_subfr_fx] = round_fx( L_tmp ); /*Q_exc*/ @@ -300,7 +301,7 @@ void dec_pit_exc_fx( FOR( i = 0; i < L_subfr_fx; i++ ) { - L_tmp = L_mult( gain_pitx2, exc_fx[add( i, i_subfr_fx )] ); /*Q16+Q_exc*/ + L_tmp = L_mult( gain_pitx2, exc_fx[i + i_subfr_fx] ); /*Q16+Q_exc*/ #ifdef BASOP_NOGLOB exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ #else @@ -695,7 +696,7 @@ void dec_pit_exc_ivas_fx( move16(); } #ifdef BASOP_NOGLOB - gain_code_fx = L_mult0( s_max( sub( 32767, shl_o( gain_pit_fx, 1, &Overflow ) ), 16384 ), st_fx->lp_gainc_fx ); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/ + gain_code_fx = L_mult0( s_max( sub( 32767, shl_o( gain_pit_fx, 1, &Overflow ) ), 16384 /*0.5.Q15*/ ), st_fx->lp_gainc_fx ); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/ #else gain_code_fx = L_mult0( s_max( sub( 32767, shl( gain_pit_fx, 1 ) ), 16384 ), st_fx->lp_gainc_fx ); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/ #endif @@ -704,7 +705,7 @@ void dec_pit_exc_ivas_fx( /*----------------------------------------------------------------------* * Find the total excitation *----------------------------------------------------------------------*/ - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )], hGSCDec->last_exc_dct_in_fx, + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[( i_subfr_fx * ( 2 * HIBND_ACB_L_FAC ) ) / 2], hGSCDec->last_exc_dct_in_fx, L_subfr_fx, shr( imult1616( L_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 ), gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type ); gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/ @@ -726,8 +727,8 @@ void dec_pit_exc_ivas_fx( { FOR( i = 0; i < L_subfr_fx; i++ ) { - L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[add( i, i_subfr_fx )] ), 1 ); /*Q16+Q_exc*/ - exc_fx[add( i, i_subfr_fx )] = round_fx( L_tmp ); /*Q_exc*/ + L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/ + exc_fx[i + i_subfr_fx] = round_fx( L_tmp ); /*Q_exc*/ move16(); } } @@ -737,8 +738,8 @@ void dec_pit_exc_ivas_fx( FOR( i = 0; i < L_subfr_fx; i++ ) { - L_tmp = L_mult( gain_pitx2, exc_fx[add( i, i_subfr_fx )] ); /*Q16+Q_exc*/ - exc_fx[add( i, i_subfr_fx )] = round_fx( L_tmp ); /*Q_exc*/ + L_tmp = L_mult( gain_pitx2, exc_fx[i + i_subfr_fx] ); /*Q16+Q_exc*/ + exc_fx[i + i_subfr_fx] = round_fx( L_tmp ); /*Q_exc*/ move16(); } } @@ -859,7 +860,7 @@ void dec_pit_exc_ivas_fx( p_Aq_fx += 4 * ( M + 1 ); /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = gain_pit_fx; + st_fx->lp_gainp_fx = gain_pit_fx; // Q14 move16(); st_fx->lp_gainc_fx = 0; move16(); diff --git a/lib_dec/dec_post_fx.c b/lib_dec/dec_post_fx.c index 977146b346d393691a3f9797cbd2ba37d16231eb..296b5cef746642821361bf104b22235a738bbe9c 100644 --- a/lib_dec/dec_post_fx.c +++ b/lib_dec/dec_post_fx.c @@ -103,7 +103,7 @@ void nb_post_filt_fx( /* update long-term background noise energy during inactive frames */ IF( EQ_16( coder_type, INACTIVE ) ) { - *psf_lp_noise = round_fx( L_mac( L_mult( 31130, *psf_lp_noise ), 26214 /*0.05 Q19*/, shl( tmp_noise, 4 ) ) ); /*Q8*Q15 + Q19*Q4 -> Q8 */ + *psf_lp_noise = round_fx( L_mac( L_mult( 31130 /*0.95.Q15*/, *psf_lp_noise ), 26214 /*0.05 Q19*/, shl( tmp_noise, 4 ) ) ); /*Q8*Q15 + Q19*Q4 -> Q8 */ } } @@ -112,17 +112,17 @@ void nb_post_filt_fx( IF( hPFstat->reset ) { set16_fx( hPFstat->mem_res2, 0, DECMEM_RES2 ); - Copy( &Synth[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); + Copy( &Synth[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); // Qsyn Copy( &Synth[L_frame - L_SYN_MEM], hPFstat->mem_stp, L_SYN_MEM ); - hPFstat->gain_prec = 16384; + hPFstat->gain_prec = 16384; // 1.Q14 move16(); hPFstat->reset = 0; move16(); return; } Pf_in = &pf_in_buffer[M]; - Copy( hPFstat->mem_pf_in + L_SYN_MEM - M, &Pf_in[-M], M ); - Copy( Synth, Pf_in, L_frame ); + Copy( hPFstat->mem_pf_in + L_SYN_MEM - M, &Pf_in[-M], M ); // Qsyn + Copy( Synth, Pf_in, L_frame ); // Qsyn Copy( &Synth[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); /* deactivation of the post filter in case of AUDIO because it causes problems to singing sequences */ IF( EQ_16( coder_type, AUDIO ) ) @@ -137,13 +137,13 @@ void nb_post_filt_fx( /* run the post filter */ - p_Aq = Aq; + p_Aq = Aq; // Q12 move16(); j = 0; move16(); FOR( i = 0; i < L_frame; i += L_SUBFR ) { - T0_first = Pitch_buf[j]; + T0_first = Pitch_buf[j]; // Q6 move16(); Dec_postfilt_fx( hPFstat, T0_first, &Pf_in[i], p_Aq, &Synth[i], Post_G1, Post_G2, Gain_factor, disable_hpf ); @@ -180,26 +180,26 @@ void nb_post_filt_fx( *----------------------------------------------------------------------------*/ static void Dec_postfilt_fx( PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - const Word16 t0, /* i : pitch delay given by coder */ - const Word16 *signal_ptr, /* i : input signal (pointer to current subframe */ - const Word16 *coeff, /* i : LPC coefficients for current subframe */ - Word16 *sig_out, /* o : postfiltered output */ - const Word16 gamma1, /* i : short term postfilt. den. weighting factor */ - const Word16 gamma2, /* i : short term postfilt. num. weighting factor */ + const Word16 t0, /* i : pitch delay given by coder Q6 */ + const Word16 *signal_ptr, /* i : input signal (pointer to current subframe Q0 */ + const Word16 *coeff, /* i : LPC coefficients for current subframe Q12 */ + Word16 *sig_out, /* o : postfiltered output Q15*/ + const Word16 gamma1, /* i : short term postfilt. den. weighting factor Q15*/ + const Word16 gamma2, /* i : short term postfilt. num. weighting factor Q15*/ const Word16 Gain_factor, /* i : Gain Factor (Q15) */ const Word16 disable_hpf ) { /* Local variables and arrays */ - Word16 apond1[M + 1]; /* s.t. denominator coeff. */ - Word16 apond2[LONG_H_ST]; + Word16 apond1[M + 1]; /* s.t. denominator coeff. Q12*/ + Word16 apond2[LONG_H_ST]; // Q12 Word16 sig_ltp[L_SUBFR + 1]; /* H0 output signal */ - Word16 res2[SIZ_RES2]; + Word16 res2[SIZ_RES2]; // Q0 Word16 *sig_ltp_ptr; Word16 *res2_ptr; Word16 *ptr_mem_stp; - Word16 parcor0; + Word16 parcor0; // Q15 /* Init pointers and restore memories */ @@ -259,7 +259,7 @@ static void Dec_postfilt_fx( void formant_post_filt_fx( PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ Word16 *synth_in, /* i : 12k8 synthesis */ - Word16 *Aq, /* i : LP filter coefficient */ + Word16 *Aq, /* i : LP filter coefficient Q12 */ Word16 *synth_out, /* i/o: input signal */ Word16 L_frame, Word32 lp_noise, /* (i) : background noise energy (15Q16) */ @@ -269,7 +269,7 @@ void formant_post_filt_fx( { Word16 i_subfr; Word16 *p_Aq; - Word16 post_G1, post_G2; + Word16 post_G1, post_G2; // Q15 /*default parameter for noisy speech and high bit-rates*/ @@ -351,7 +351,7 @@ void formant_post_filt_fx( } /* Reset post filter */ - if ( hPFstat->reset != 0 ) + IF( hPFstat->reset != 0 ) { post_G1 = MAX16B; move16(); @@ -361,7 +361,7 @@ void formant_post_filt_fx( move16(); Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_stp, L_SYN_MEM ); - hPFstat->gain_prec = 16384; + hPFstat->gain_prec = 16384; // 1.Q14 move16(); Copy( synth_in, synth_out, L_frame ); @@ -373,7 +373,7 @@ void formant_post_filt_fx( Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); move16(); - p_Aq = Aq; + p_Aq = Aq; // Q12 FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) { Dec_formant_postfilt_fx( hPFstat, &synth_in[i_subfr], p_Aq, &synth_out[i_subfr], post_G1, post_G2 ); @@ -385,7 +385,7 @@ void formant_post_filt_fx( void formant_post_filt_ivas_fx( PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ Word16 *synth_in, /* i : 12k8 synthesis */ - Word16 *Aq, /* i : LP filter coefficient */ + Word16 *Aq, /* i : LP filter coefficient Q12 */ Word16 *synth_out, /* i/o: input signal */ Word16 L_frame, Word32 lp_noise, /* (i) : background noise energy (15Q16) */ @@ -477,7 +477,7 @@ void formant_post_filt_ivas_fx( } /* Reset post filter */ - if ( hPFstat->reset != 0 ) + IF( hPFstat->reset != 0 ) { post_G1 = MAX16B; move16(); @@ -487,7 +487,7 @@ void formant_post_filt_ivas_fx( move16(); Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_stp, L_SYN_MEM ); - hPFstat->gain_prec = 16384; + hPFstat->gain_prec = 16384; // 1.Q14 move16(); Copy( synth_in, synth_out, L_frame ); @@ -499,7 +499,7 @@ void formant_post_filt_ivas_fx( Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); move16(); - p_Aq = Aq; + p_Aq = Aq; // Q12 FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) { Dec_formant_postfilt_ivas_fx( hPFstat, &synth_in[i_subfr], p_Aq, &synth_out[i_subfr], post_G1, post_G2 ); @@ -524,19 +524,19 @@ void formant_post_filt_ivas_fx( *----------------------------------------------------------------------------*/ static void Dec_formant_postfilt_fx( PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *signal_ptr, /* i : input signal (pointer to current subframe */ - Word16 *coeff, /* i : LPC coefficients for current subframe */ + Word16 *signal_ptr, /* i : input signal (pointer to current subframe Q14*/ + Word16 *coeff, /* i : LPC coefficients for current subframe Q12 */ Word16 *sig_out, /* o : postfiltered output */ - Word16 gamma1, /* i : short term postfilt. den. weighting factor*/ - Word16 gamma2 /* i : short term postfilt. num. weighting factor*/ + Word16 gamma1, /* i : short term postfilt. den. weighting factor Q15*/ + Word16 gamma2 /* i : short term postfilt. num. weighting factor Q15*/ ) { /* Local variables and arrays */ - Word16 apond1[M + 1]; /* s.t. denominator coeff. */ - Word16 apond2[LONG_H_ST]; - Word16 res2[L_SUBFR]; - Word16 resynth[L_SUBFR + 1]; - Word16 parcor0; + Word16 apond1[M + 1]; /* s.t. denominator coeff. Q12*/ + Word16 apond2[LONG_H_ST]; // Q12 + Word16 res2[L_SUBFR]; // Q14 + Word16 resynth[L_SUBFR + 1]; // Qy + Word16 parcor0; // Q15 Word16 i, max; Word16 scale_down; @@ -545,14 +545,14 @@ static void Dec_formant_postfilt_fx( weight_a_fx( coeff, apond2, gamma2, M ); set16_fx( &apond2[M + 1], 0, LONG_H_ST - ( M + 1 ) ); - max = abs_s( signal_ptr[0] ); + max = abs_s( signal_ptr[0] ); // Q14 FOR( i = 1; i < L_SUBFR; i++ ) { max = s_max( max, abs_s( signal_ptr[i] ) ); } scale_down = 0; move16(); - if ( GT_16( max, 16384 ) ) + if ( GT_16( max, 16384 /*1.Q14*/ ) ) { scale_down = 1; move16(); @@ -604,19 +604,19 @@ static void Dec_formant_postfilt_fx( #ifdef IVAS_FLOAT_FIXED static void Dec_formant_postfilt_ivas_fx( PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *signal_ptr, /* i : input signal (pointer to current subframe */ - Word16 *coeff, /* i : LPC coefficients for current subframe */ + Word16 *signal_ptr, /* i : input signal (pointer to current subframe Q14*/ + Word16 *coeff, /* i : LPC coefficients for current subframe Q12 */ Word16 *sig_out, /* o : postfiltered output */ - Word16 gamma1, /* i : short term postfilt. den. weighting factor*/ - Word16 gamma2 /* i : short term postfilt. num. weighting factor*/ + Word16 gamma1, /* i : short term postfilt. den. weighting factor Q15*/ + Word16 gamma2 /* i : short term postfilt. num. weighting factor Q15*/ ) { /* Local variables and arrays */ - Word16 apond1[M + 1]; /* s.t. denominator coeff. */ - Word16 apond2[LONG_H_ST]; - Word16 res2[L_SUBFR]; - Word16 resynth[L_SUBFR + 1]; - Word16 parcor0; + Word16 apond1[M + 1]; /* s.t. denominator coeff. Q12*/ + Word16 apond2[LONG_H_ST]; // Q12 + Word16 res2[L_SUBFR]; // Q14 + Word16 resynth[L_SUBFR + 1]; // Qy + Word16 parcor0; // Q15 Word16 i, max; Word16 scale_down; @@ -625,14 +625,14 @@ static void Dec_formant_postfilt_ivas_fx( weight_a_fx( coeff, apond2, gamma2, M ); set16_fx( &apond2[M + 1], 0, LONG_H_ST - ( M + 1 ) ); - max = abs_s( signal_ptr[0] ); + max = abs_s( signal_ptr[0] ); // Q14 FOR( i = 1; i < L_SUBFR; i++ ) { max = s_max( max, abs_s( signal_ptr[i] ) ); } scale_down = 0; move16(); - if ( GT_16( max, 16384 ) ) + if ( GT_16( max, 16384 /*1.Q14*/ ) ) { scale_down = 1; move16(); @@ -693,7 +693,7 @@ static void modify_pst_param_fx( Word16 *g1, /* o : Gamma1 used in post filter Q15 */ Word16 *g2, /* o : Gamma1 used in post filter Q15 */ const Word16 coder_type, /* i : Vad information decoded in UV frame */ - Word16 *gain_factor /* o : Gain factor applied in post filtering */ + Word16 *gain_factor /* o : Gain factor applied in post filtering Q15 */ ) { Word16 tmp; @@ -758,9 +758,9 @@ static void modify_pst_param_fx( * Perform harmonic postfilter *----------------------------------------------------------------------------*/ static void pst_ltp_fx( - Word16 t0, /* i : pitch delay given by coder */ - Word16 *ptr_sig_in, /* i : postfilter i filter (residu2) */ - Word16 *ptr_sig_pst0, /* o : harmonic postfilter o */ + Word16 t0, /* i : pitch delay given by coder Q6 */ + Word16 *ptr_sig_in, /* i : postfilter i filter (residu2) Qx */ + Word16 *ptr_sig_pst0, /* o : harmonic postfilter o Qx */ Word16 gain_factor /* i : Gain Factor (Q15) */ ) { @@ -790,8 +790,8 @@ static void pst_ltp_fx( /* i signal justified on 13 bits */ - ptr_sig = ptr_sig_in - DECMEM_RES2; - nb_sh_sig = getScaleFactor16( ptr_sig, add( DECMEM_RES2, L_SUBFR ) ); + ptr_sig = ptr_sig_in - DECMEM_RES2; // Qx + nb_sh_sig = getScaleFactor16( ptr_sig, DECMEM_RES2 + L_SUBFR ); nb_sh_sig = sub( 3, nb_sh_sig ); FOR( i = 0; i < DECMEM_RES2 + L_SUBFR; i++ ) @@ -814,7 +814,7 @@ static void pst_ltp_fx( { IF( phase == 0 ) { - ptr_y_up = ptr_sig_in - ltpdel; + ptr_y_up = ptr_sig_in - ltpdel; // Qx } ELSE { @@ -890,7 +890,7 @@ static void pst_ltp_fx( /* gain_plt += (1.0f-gain_plt) * gain_factor */ /* gain_plt = gain_plt + gain_factor - gain_plt*gain_factor */ #ifdef BASOP_NOGLOB - gain_plt = msu_ro( L_msu( L_deposit_h( gain_plt ), gain_plt, gain_factor ), -32768, gain_factor, &Overflow ); + gain_plt = msu_ro( L_msu( L_deposit_h( gain_plt ), gain_plt, gain_factor ), -32768, gain_factor, &Overflow ); // Q15 #else gain_plt = msu_r( L_msu( L_deposit_h( gain_plt ), gain_plt, gain_factor ), -32768, gain_factor ); #endif @@ -906,12 +906,12 @@ static void pst_ltp_fx( * Computes best (shortest) integer LTP delay + fine search *---------------------------------------------------------------------------*/ static void search_del_fx( - Word16 t0, /* i : pitch delay given by coder */ + Word16 t0, /* i : pitch delay given by coder Q0 */ Word16 *ptr_sig_in, /* i : i signal (with delay line) */ Word16 *ltpdel, /* o : delay = *ltpdel - *phase / f_up */ Word16 *phase, /* o : phase */ - Word16 *num_gltp, /* o : 16 bits numerator of LTP gain */ - Word16 *den_gltp, /* o : 16 bits denominator of LTP gain */ + Word16 *num_gltp, /* o : 16 bits numerator of LTP gain Q(sh_num_gltp) */ + Word16 *den_gltp, /* o : 16 bits denominator of LTP gain Q(sh_den_gltp) */ Word16 *sh_num_gltp, /* o : justification for num_gltp */ Word16 *sh_den_gltp, /* o : justification for den_gltp */ Word16 *y_up, /* o : LT delayed signal if fract. delay */ @@ -933,10 +933,10 @@ static void search_del_fx( Word16 *ptr1, *ptr_y_up; Word16 i, n; - Word16 num, den0, den1; + Word16 num /*Q(sh_num)*/, den0 /*Q(sh_den)*/, den1 /*Q(sh_den)*/; Word16 den_max, num_max; Word32 L_numsq_max; - Word16 ener; + Word16 ener; // Q(sh_ener) Word16 sh_num, sh_den, sh_ener; Word16 i_max, lambda, phi, phi_max, ioff; Word16 temp; @@ -1320,7 +1320,7 @@ static void search_del_fx( } ELSE { - if ( temp > 0 ) + IF( temp > 0 ) { L_temp1 = L_shr( L_temp1, temp ); } @@ -1365,10 +1365,10 @@ static void search_del_fx( * Perform long term postfilter *----------------------------------------------------------------------------*/ static void filt_plt_fx( - Word16 *s_in, /* i : i signal with past */ - Word16 *s_ltp, /* i : filtered signal with gain 1 */ - Word16 *s_out, /* o : signal */ - Word16 gain_plt /* i : filter gain */ + Word16 *s_in, /* i : i signal with past Qx */ + Word16 *s_ltp, /* i : filtered signal with gain 1 Qx*/ + Word16 *s_out, /* o : signal Qx */ + Word16 gain_plt /* i : filter gain Q15 */ ) { @@ -1379,15 +1379,15 @@ static void filt_plt_fx( Word16 gain_plt_1; - gain_plt_1 = sub( 32767, gain_plt ); - gain_plt_1 = add( gain_plt_1, 1 ); /* 2**15 (1 - g) */ + gain_plt_1 = sub( 32767, gain_plt ); // Q15 + gain_plt_1 = add( gain_plt_1, 1 ); /* 2**15 (1 - g) */ FOR( n = 0; n < L_SUBFR; n++ ) { /* s_out(n) = gain_plt x s_in(n) + gain_plt_1 x s_ltp(n) */ - L_acc = L_mult( gain_plt, s_in[n] ); - s_out[n] = mac_r( L_acc, gain_plt_1, s_ltp[n] ); - move16(); /* no overflow */ + L_acc = L_mult( gain_plt, s_in[n] ); // Qx + Q15 + 1 + s_out[n] = mac_r( L_acc, gain_plt_1, s_ltp[n] ); // Qx + move16(); /* no overflow */ } @@ -1406,8 +1406,8 @@ static void compute_ltp_l_fx( Word16 ltpdel, /* i : delay factor */ Word16 phase, /* i : phase factor */ Word16 *y_up, /* i : delayed signal */ - Word16 *num, /* i : numerator of LTP gain */ - Word16 *den, /* i : denominator of LTP gain */ + Word16 *num, /* i : numerator of LTP gain Q(sh_num) */ + Word16 *den, /* i : denominator of LTP gain Q(sh_den) */ Word16 *sh_num, /* i : justification factor of num */ Word16 *sh_den /* i : justification factor of den */ ) @@ -1420,7 +1420,7 @@ static void compute_ltp_l_fx( temp = sub( phase, 1 ); temp = shl( temp, L2_LH2_L ); - ptr_h = tab_hup_l_fx + temp; /* tab_hup_l_fx + LH2_L * (phase-1) */ + ptr_h = tab_hup_l_fx + temp; /* tab_hup_l_fx + LH2_L * (phase-1) */ // Q15 temp = sub( LH_UP_L, ltpdel ); ptr2 = s_in + temp; @@ -1459,6 +1459,7 @@ static void compute_ltp_l_fx( *num = extract_l( L_acc ); *sh_num = temp; move16(); + move16(); } /* Compute den */ @@ -1477,6 +1478,7 @@ static void compute_ltp_l_fx( *den = extract_l( L_acc ); *sh_den = temp; move16(); + move16(); return; @@ -1490,12 +1492,12 @@ static void compute_ltp_l_fx( * and gain2 = num2 * 2** sh_num2 / den2 * 2** sh_den2 *----------------------------------------------------------------------------*/ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain */ - Word16 num1, /* i : numerator of gain1 */ - Word16 den1, /* i : denominator of gain1 */ + Word16 num1, /* i : numerator of gain1 Q(sh_num1) */ + Word16 den1, /* i : denominator of gain1 Q(sh_den1) */ Word16 sh_num1, /* i : just. factor for num1 */ Word16 sh_den1, /* i : just. factor for den1 */ - Word16 num2, /* i : numerator of gain2 */ - Word16 den2, /* i : denominator of gain2 */ + Word16 num2, /* i : numerator of gain2 Q(sh_num2) */ + Word16 den2, /* i : denominator of gain2 Q(sh_den2) */ Word16 sh_num2, /* i : just. factor for num2 */ Word16 sh_den2 /* i : just. factor for den2 */ ) @@ -1506,7 +1508,7 @@ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain Word16 temp1, temp2; - if ( den2 == 0 ) + IF( den2 == 0 ) { return 1; } @@ -1526,11 +1528,11 @@ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain temp2 = add( temp2, sh_den1 ); temp2 = sub( temp2, temp1 ); - if ( temp2 > 0 ) + IF( temp2 > 0 ) { L_temp1 = L_shr( L_temp1, temp2 ); /* temp2 > 0 */ } - if ( temp2 < 0 ) + IF( temp2 < 0 ) { L_temp2 = L_shl( L_temp2, temp2 ); /* temp2 < 0 */ } @@ -1555,10 +1557,10 @@ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain * SUMn (abs (h[n])) and computes parcor0 *---------------------------------------------------------------------------- */ static void calc_st_filt_local_fx( - Word16 *apond2, /* i : coefficients of numerator */ - Word16 *apond1, /* i : coefficients of denominator */ - Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ - Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ + Word16 *apond2, /* i : coefficients of numerator Q12 */ + Word16 *apond1, /* i : coefficients of denominator Q12 */ + Word16 *parcor0, /* o : 1st parcor calcul. on composed filter Q15*/ + Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 Qx */ Word16 *mem_zero /* i : All zero memory */ ) { @@ -1579,20 +1581,20 @@ static void calc_st_filt_local_fx( Calc_rc0_h( h, parcor0 ); /* compute g0 */ - L_g0 = L_mult0( 1, abs_s( h[0] ) ); + L_g0 = L_mult0( 1, abs_s( h[0] ) ); // Q12 FOR( i = 1; i < LONG_H_ST; i++ ) { - L_g0 = L_mac0( L_g0, 1, abs_s( h[i] ) ); + L_g0 = L_mac0( L_g0, 1, abs_s( h[i] ) ); // Q12 } - g0 = extract_h( L_shl( L_g0, 14 ) ); + g0 = extract_h( L_shl( L_g0, 14 ) ); // Q10 /* Scale signal i of 1/A(gamma1) */ - IF( GT_16( g0, 1024 ) ) + IF( GT_16( g0, 1024 ) ) /*1024 = 1.Q10*/ { - temp = div_s( 1024, g0 ); /* temp = 2**15 / gain0 */ + temp = div_s( 1024, g0 ); /* temp => Q15 / gain0 */ /*1024 = 1.Q10*/ FOR( i = 0; i < L_SUBFR; i++ ) { - sig_ltp_ptr[i] = mult_r( sig_ltp_ptr[i], temp ); + sig_ltp_ptr[i] = mult_r( sig_ltp_ptr[i], temp ); // Qx move16(); } } @@ -1603,17 +1605,17 @@ static void calc_st_filt_local_fx( #ifdef IVAS_FLOAT_FIXED static void calc_st_filt_ivas_fx( - Word16 *apond2, /* i : coefficients of numerator */ - Word16 *apond1, /* i : coefficients of denominator */ - Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ - Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ + Word16 *apond2, /* i : coefficients of numerator Q12 */ + Word16 *apond1, /* i : coefficients of denominator Q12 */ + Word16 *parcor0, /* o : 1st parcor calcul. on composed filter Q15 */ + Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 Qx*/ Word16 *mem_zero, /* i : All zero memory */ const Word16 extl /* i : extension layer info */ ) { Word32 L_g0; - Word16 h[LONG_H_ST]; + Word16 h[LONG_H_ST]; // Q12 Word16 g0, temp; Word16 i; @@ -1635,20 +1637,20 @@ static void calc_st_filt_ivas_fx( Calc_rc0_h( h, parcor0 ); /* compute g0 */ - L_g0 = L_mult0( 1, abs_s( h[0] ) ); + L_g0 = L_mult0( 1, abs_s( h[0] ) ); // Q12 FOR( i = 1; i < LONG_H_ST; i++ ) { - L_g0 = L_mac0( L_g0, 1, abs_s( h[i] ) ); + L_g0 = L_mac0( L_g0, 1, abs_s( h[i] ) ); // Q12 } - g0 = extract_h( L_shl( L_g0, 14 ) ); + g0 = extract_h( L_shl( L_g0, 14 ) ); // Q10 /* Scale signal i of 1/A(gamma1) */ - IF( GT_16( g0, 1024 ) ) + IF( GT_16( g0, 1024 ) ) /*1024 = 1.Q10*/ { - temp = div_s( 1024, g0 ); /* temp = 2**15 / gain0 */ + temp = div_s( 1024, g0 ); /* temp => Q15 / gain0 */ /*1024 = 1.Q10*/ FOR( i = 0; i < L_SUBFR; i++ ) { - sig_ltp_ptr[i] = mult_r( sig_ltp_ptr[i], temp ); + sig_ltp_ptr[i] = mult_r( sig_ltp_ptr[i], temp ); // Qx move16(); } } @@ -1685,34 +1687,34 @@ void Filt_mu_fx( IF( parcor0 > 0 ) { - mu = mult_r( parcor0, GAMMA3_PLUS_FX ); + mu = mult_r( parcor0, GAMMA3_PLUS_FX ); // Q15 /* GAMMA3_PLUS_FX < 0.5 */ sh_fact = 14; move16(); /* sh_fact */ fact = (Word16) 0x4000; - move16(); /* 2**sh_fact */ + move16(); /* Q(sh_fact) */ L_fact = (Word32) L_deposit_l( 0x2000 ); /* fact >> 1 */ } ELSE { - mu = mult_r( parcor0, GAMMA3_MINUS_FX ); + mu = mult_r( parcor0, GAMMA3_MINUS_FX ); // Q15 /* GAMMA3_MINUS_FX < 0.9375 */ sh_fact = 11; move16(); /* sh_fact */ fact = (Word16) 0x0800; - move16(); /* 2**sh_fact */ + move16(); /* Q(sh_fact) */ L_fact = (Word32) L_deposit_l( 0x0400 ); /* fact >> 1 */ } temp = sub( 1, abs_s( mu ) ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - mu2 = add_o( 32767, temp, &Overflow ); /* 2**15 (1 - |mu|) */ + mu2 = add_o( 32767, temp, &Overflow ); /* Q15 (1 - |mu|) */ #else mu2 = add( 32767, temp ); /* 2**15 (1 - |mu|) */ #endif BASOP_SATURATE_WARNING_ON_EVS; - ga = div_s( fact, mu2 ); /* 2**sh_fact / (1 - |mu|) */ + ga = div_s( fact, mu2 ); /* Q(sh_fact) / (1 - |mu|) */ ptrs = sig_in; /* points on sig_in(-1) */ @@ -1748,7 +1750,7 @@ void Filt_mu_fx( void Filt_mu_ivas_fx( Word16 *sig_in, /* i : signal (beginning at sample -1) */ Word16 *sig_out, /* o : signal with tilt */ - Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ + Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) Q15 */ Word16 L_subfr, /* i : the length of subframe */ const Word16 extl ) { @@ -1768,58 +1770,58 @@ void Filt_mu_ivas_fx( { IF( parcor0 > 0 ) { - mu = mult_r( parcor0, GAMMA3_PLUS_WB_FX ); + mu = mult_r( parcor0, GAMMA3_PLUS_WB_FX ); // Q15 /* GAMMA3_PLUS_FX < 0.5 */ sh_fact = 14; move16(); /* sh_fact */ fact = (Word16) 0x4000; - move16(); /* 2**sh_fact */ - L_fact = (Word32) L_deposit_l( 0x2000 ); /* fact >> 1 */ + move16(); /* Q(sh_fact) */ + L_fact = L_deposit_l( 0x2000 ); /* fact >> 1 */ } ELSE { - mu = mult_r( parcor0, GAMMA3_MINUS_WB_FX ); + mu = mult_r( parcor0, GAMMA3_MINUS_WB_FX ); // Q15 /* GAMMA3_MINUS_FX < 0.9375 */ sh_fact = 11; move16(); /* sh_fact */ fact = (Word16) 0x0800; - move16(); /* 2**sh_fact */ - L_fact = (Word32) L_deposit_l( 0x0400 ); /* fact >> 1 */ + move16(); /* Q(sh_fact) */ + L_fact = L_deposit_l( 0x0400 ); /* fact >> 1 */ } } ELSE { IF( parcor0 > 0 ) { - mu = mult_r( parcor0, GAMMA3_PLUS_FX ); + mu = mult_r( parcor0, GAMMA3_PLUS_FX ); // Q15 /* GAMMA3_PLUS_FX < 0.5 */ sh_fact = 14; move16(); /* sh_fact */ fact = (Word16) 0x4000; - move16(); /* 2**sh_fact */ - L_fact = (Word32) L_deposit_l( 0x2000 ); /* fact >> 1 */ + move16(); /* Q(sh_fact) */ + L_fact = L_deposit_l( 0x2000 ); /* fact >> 1 */ } ELSE { - mu = mult_r( parcor0, GAMMA3_MINUS_FX ); + mu = mult_r( parcor0, GAMMA3_MINUS_FX ); // Q15 /* GAMMA3_MINUS_FX < 0.9375 */ sh_fact = 11; move16(); /* sh_fact */ fact = (Word16) 0x0800; - move16(); /* 2**sh_fact */ - L_fact = (Word32) L_deposit_l( 0x0400 ); /* fact >> 1 */ + move16(); /* Q(sh_fact) */ + L_fact = L_deposit_l( 0x0400 ); /* fact >> 1 */ } } temp = sub( 1, abs_s( mu ) ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - mu2 = add_o( 32767, temp, &Overflow ); /* 2**15 (1 - |mu|) */ + mu2 = add_o( 32767, temp, &Overflow ); /* Q15 (1 - |mu|) */ #else mu2 = add( 32767, temp ); /* 2**15 (1 - |mu|) */ #endif BASOP_SATURATE_WARNING_ON_EVS; - ga = div_s( fact, mu2 ); /* 2**sh_fact / (1 - |mu|) */ + ga = div_s( fact, mu2 ); /* Q(sh_fact) / (1 - |mu|) */ ptrs = sig_in; /* points on sig_in(-1) */ @@ -1854,9 +1856,9 @@ void Filt_mu_ivas_fx( * gain[n] = AGC_FAC_FX * gain[n-1] + (1 - AGC_FAC_FX) g_in/g_out *---------------------------------------------------------------------------*/ void scale_st_fx( - const Word16 *sig_in, /* i : postfilter i signal */ - Word16 *sig_out, /* i/o: postfilter o signal */ - Word16 *gain_prec, /* i/o: last value of gain for subframe */ + const Word16 *sig_in, /* i : postfilter i signal Qx */ + Word16 *sig_out, /* i/o: postfilter o signal Qx */ + Word16 *gain_prec, /* i/o: last value of gain for subframe Q14*/ Word16 L_subfr ) { Word32 L_acc, L_temp; @@ -1871,11 +1873,11 @@ void scale_st_fx( L_acc = L_deposit_l( 0 ); FOR( i = 0; i < L_subfr; i++ ) { - if ( sig_in[i] > 0 ) + IF( sig_in[i] > 0 ) { L_acc = L_mac0( L_acc, 1, sig_in[i] ); } - if ( sig_in[i] < 0 ) + IF( sig_in[i] < 0 ) { L_acc = L_msu0( L_acc, 1, sig_in[i] ); } @@ -1948,6 +1950,7 @@ void scale_st_fx( L_temp = L_shl( L_temp, 1 ); sig_out[i] = round_fx( L_temp ); #endif + move16(); } *gain_prec = gain; move16(); @@ -1963,26 +1966,26 @@ void scale_st_fx( *---------------------------------------------------------------------------*/ void blend_subfr2_fx( - Word16 *sigIn1, - Word16 *sigIn2, - Word16 *sigOut ) + Word16 *sigIn1, // Qx + Word16 *sigIn2, // Qx + Word16 *sigOut // Qx +) { - Word16 fac1 = 32768 - 512; - Word16 fac2 = 0 + 512; - Word16 step = 1024; + Word16 fac1 = 32768 - 512; // 1.Q15 - ( 1.Q15 / L_SUBFR ); + Word16 fac2 = 0 + 512; // 0.Q15 + ( 1.Q15 / L_SUBFR ); + Word16 step = 1024; // 1.Q15 / ( L_SUBFR / 2 ); Word16 i; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#endif move16(); +#endif move16(); move16(); move16(); FOR( i = 0; i < L_SUBFR / 2; i++ ) { #ifdef BASOP_NOGLOB - sigOut[i] = mac_ro( L_mult_o( fac1, sigIn1[i], &Overflow ), fac2, sigIn2[i], &Overflow ); - move16(); + sigOut[i] = mac_ro( L_mult_o( fac1, sigIn1[i], &Overflow ), fac2, sigIn2[i], &Overflow ); // Qx fac1 = sub_o( fac1, step, &Overflow ); fac2 = add_o( fac2, step, &Overflow ); #else @@ -1990,6 +1993,7 @@ void blend_subfr2_fx( fac1 = sub( fac1, step ); fac2 = add( fac2, step ); #endif + move16(); } return; diff --git a/lib_dec/dec_ppp_fx.c b/lib_dec/dec_ppp_fx.c index d37efa4c7d80b2ca92d6f92813f7b6185644999e..189ecc2b770e5c81aa0f8093c331a980b46f7123 100644 --- a/lib_dec/dec_ppp_fx.c +++ b/lib_dec/dec_ppp_fx.c @@ -70,7 +70,7 @@ ivas_error decod_ppp_fx( /* call voiced decoder at this point */ FOR( k = 0; k < M; k++ ) { - p_Aq_curr_fx[k] = Aq_fx[add( k, ( 3 * ( M + 1 ) ) + 1 )]; + p_Aq_curr_fx[k] = Aq_fx[( k + ( 3 * ( M + 1 ) ) + 1 )]; move16(); /*Q12 */ } diff --git a/lib_dec/dec_prm_fx.c b/lib_dec/dec_prm_fx.c index 7b923ab72ffa094d07d3e6c6534738de29533e2f..194e6bba6930613244790dbf4b517c76a9035928 100644 --- a/lib_dec/dec_prm_fx.c +++ b/lib_dec/dec_prm_fx.c @@ -20,10 +20,10 @@ void getLPCparam_fx( Decoder_State *st, /* i/o: decoder memory state */ - Word16 param_lpc[], /* o : LTP parameters */ + Word16 param_lpc[], /* o : LTP parameters Q0 */ Decoder_State *st0, /* i : bitstream */ - const Word16 ch, /* i : channel */ - const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ + const Word16 ch, /* i : channel Q0 */ + const Word16 sns_low_br_mode /* i : SNS low-bitrate mode Q0 */ ) { IF( st->use_partial_copy == 0 ) @@ -59,9 +59,9 @@ void getLPCparam_fx( { test(); test(); - IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->coder_type, VOICED ) && EQ_16( st->core, ACELP_CORE ) ) + IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->coder_type, VOICED ) && ( st->core == ACELP_CORE ) ) { - assert( EQ_16( st->element_mode, EVS_MONO ) ); + assert( st->element_mode == EVS_MONO ); lsf_bctcvq_decprm( st0, param_lpc ); } ELSE @@ -82,21 +82,21 @@ void getLPCparam_fx( test(); IF( EQ_16( st->rf_frame_type, RF_TCXFD ) ) { - param_lpc[0] = 0; + param_lpc[0] = 0; // Q0 move16(); - param_lpc[1] = get_next_indice_fx( st0, lsf_numbits[0] ); /* VQ 1 */ + param_lpc[1] = get_next_indice_fx( st0, lsf_numbits[0] ); /* VQ 1 */ // Q0 move16(); - param_lpc[2] = get_next_indice_fx( st0, lsf_numbits[1] ); /* VQ 2 */ + param_lpc[2] = get_next_indice_fx( st0, lsf_numbits[1] ); /* VQ 2 */ // Q0 move16(); - param_lpc[3] = get_next_indice_fx( st0, lsf_numbits[2] ); /* VQ 3 */ + param_lpc[3] = get_next_indice_fx( st0, lsf_numbits[2] ); /* VQ 3 */ // Q0 move16(); } ELSE IF( GE_16( st->rf_frame_type, RF_ALLPRED ) && LE_16( st->rf_frame_type, RF_NELP ) ) { /* LSF indices */ - param_lpc[0] = get_next_indice_fx( st0, 8 ); /* VQ 1 */ + param_lpc[0] = get_next_indice_fx( st0, 8 ); /* VQ 1 */ // Q0 move16(); - param_lpc[1] = get_next_indice_fx( st0, 8 ); /* VQ 2 */ + param_lpc[1] = get_next_indice_fx( st0, 8 ); /* VQ 2 */ // Q0 move16(); } } @@ -106,7 +106,7 @@ void getLPCparam_fx( void dec_prm_hm_fx( Decoder_State *st, - Word16 *prm_hm, + Word16 *prm_hm, /* Q0 */ const Word16 L_frame ) { Word16 tmp; @@ -127,7 +127,7 @@ void dec_prm_hm_fx( move16(); /* Flag */ - prm_hm[0] = get_next_indice_fx( st, 1 ); + prm_hm[0] = get_next_indice_fx( st, 1 ); // Q0 move16(); IF( prm_hm[0] != 0 ) @@ -161,13 +161,13 @@ void getTCXparam_fx( Decoder_State *st, /* i/o: Decoder State handle */ Decoder_State *st0, /* i : bitstream */ CONTEXT_HM_CONFIG hm_cfg, /* i/o: HM config */ - Word16 param[], /* o : decoded parameters */ - const Word16 bits_common, /* i : number of common bits */ - const Word16 start_bit_pos, /* i : position of the start bit */ - const Word16 *no_param_tns, /* i : number of TNS parameters per subframe */ - Word16 p_param[2], /* o : pointer to parameters for next round of bs reading*/ - Word16 nTnsBitsTCX10[2], - const Word16 pre_past_flag ) + Word16 param[], /* o : decoded parameters Q0 */ + const Word16 bits_common, /* i : number of common bits Q0 */ + const Word16 start_bit_pos, /* i : position of the start bit Q0 */ + const Word16 *no_param_tns, /* i : number of TNS parameters per subframe Q0 */ + Word16 p_param[2], /* o : pointer to parameters for next round of bs reading Q0 */ + Word16 nTnsBitsTCX10[2], /*Q0*/ + const Word16 pre_past_flag /*Q0*/ ) { Word16 ix, j, k, core, last_core, nSubframes; Word16 lg, lgFB, flag_ctx_hm, hm_size; @@ -243,7 +243,7 @@ void getTCXparam_fx( IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_SHORT, 1 - k ); IGFDecStoreTCX10SubFrameData( st->hIGFDec, k ); - nbits_igf = add( nbits_igf, sub( st0->next_bit_pos, ix ) ); + nbits_igf = add( nbits_igf, sub( st0->next_bit_pos, ix ) ); // Q0 } } /* loop over subframes */ @@ -251,35 +251,35 @@ void getTCXparam_fx( { flag_ctx_hm = 0; move16(); - prm = param + imult1616( k, DEC_NPRM_DIV ); + prm = param + k * DEC_NPRM_DIV; j = 0; move16(); - nbits_tcx = sub( st0->next_bit_pos, start_bit_pos ); + nbits_tcx = sub( st0->next_bit_pos, start_bit_pos ); // Q0 test(); test(); - IF( pre_part && st->enablePlcWaveadjust && EQ_16( k, ( nSubframes - 1 ) ) ) + IF( pre_part && st->enablePlcWaveadjust && EQ_16( k, sub( nSubframes, 1 ) ) ) { - st->tonality_flag = get_next_indice_fx( st0, 1 ); + st->tonality_flag = get_next_indice_fx( st0, 1 ); // Q0 move16(); } IF( post_part ) { /* TCX Gain */ - prm[j] = get_next_indice_fx( st0, NBITS_TCX_GAIN ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st0, NBITS_TCX_GAIN ); // Q0 + j = add( j, 1 ); // Q0 move16(); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j] = get_next_indice_fx( st0, NBITS_NOISE_FILL_LEVEL ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st0, NBITS_NOISE_FILL_LEVEL ); // Q0 + j = add( j, 1 ); // Q0 move16(); } ELSE { - j = add( j, 1 + NOISE_FILL_RANGES ); + j = add( j, 1 + NOISE_FILL_RANGES ); // Q0 } /* LTP data */ @@ -289,24 +289,24 @@ void getTCXparam_fx( test(); IF( ( k == 0 ) && ( hTcxLtpDec->tcxltp || GT_32( st->sr_core, 25600 ) ) ) /* PLC pitch info for HB */ { - prm[j] = get_next_indice_fx( st0, 1 ); + prm[j] = get_next_indice_fx( st0, 1 ); // Q0 move16(); IF( prm[j] ) { - prm[add( j, 1 )] = get_next_indice_fx( st0, 9 ); + prm[add( j, 1 )] = get_next_indice_fx( st0, 9 ); // Q0 move16(); - prm[add( j, 2 )] = get_next_indice_fx( st0, 2 ); + prm[add( j, 2 )] = get_next_indice_fx( st0, 2 ); // Q0 move16(); - tcxltp_prm_0 = prm[j]; + tcxltp_prm_0 = prm[j]; // Q0 move16(); - tcxltp_prm_1 = prm[j + 1]; + tcxltp_prm_1 = prm[j + 1]; // Q0 move16(); - tcxltp_prm_2 = prm[j + 2]; + tcxltp_prm_2 = prm[j + 2]; // Q0 move16(); } - st->BER_detect = st->BER_detect | tcx_ltp_decode_params( &prm[j], &( hTcxLtpDec->tcxltp_pitch_int ), &( hTcxLtpDec->tcxltp_pitch_fr ), &( hTcxLtpDec->tcxltp_gain ), st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ); + st->BER_detect = s_or( st->BER_detect, tcx_ltp_decode_params( &prm[j], &( hTcxLtpDec->tcxltp_pitch_int ), &( hTcxLtpDec->tcxltp_pitch_fr ), &( hTcxLtpDec->tcxltp_gain ), st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ) ); // Q0 move16(); - hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; + hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15 move16(); test(); @@ -316,45 +316,45 @@ void getTCXparam_fx( // To be done at the end Word32 tmp32 = L_shl( L_mult0( st->L_frame, st->pit_res_max ), 1 + kLtpHmFractionalResolution + 1 ); Word16 tmp1 = add( imult1616( hTcxLtpDec->tcxltp_pitch_int, st->pit_res_max ), hTcxLtpDec->tcxltp_pitch_fr ); - hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 ); + hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 ); // Q15 move16(); } ELSE { - hTcxDec->tcx_hm_LtpPitchLag = -1; + hTcxDec->tcx_hm_LtpPitchLag = -1; // Q15 move16(); } - j = add( j, 3 ); + j = add( j, 3 ); // Q0 } ELSE { - prm[j] = tcxltp_prm_0; - j = add( j, 1 ); + prm[j] = tcxltp_prm_0; // Q0 + j = add( j, 1 ); // Q0 move16(); - prm[j] = tcxltp_prm_1; - j = add( j, 1 ); + prm[j] = tcxltp_prm_1; // Q0 + j = add( j, 1 ); // Q0 move16(); - prm[j] = tcxltp_prm_2; - j = add( j, 1 ); + prm[j] = tcxltp_prm_2; // Q0 + j = add( j, 1 ); // Q0 move16(); } } /* TCX spectral data */ - lg = shr( st->L_frame, sub( nSubframes, 1 ) ); - lgFB = shr( st->hTcxCfg->tcx_coded_lines, sub( nSubframes, 1 ) ); + lg = shr( st->L_frame, sub( nSubframes, 1 ) ); // Q0 + lgFB = shr( st->hTcxCfg->tcx_coded_lines, sub( nSubframes, 1 ) ); // Q0 test(); test(); IF( post_part && ( k == 0 ) && EQ_16( st->last_core_from_bs, ACELP_CORE ) ) { /* ACE->TCX transition */ - lg = add( lg, st->hTcxCfg->tcx_offset ); - lgFB = add( lgFB, shr( lgFB, sub( 3, nSubframes ) ) ); + lg = add( lg, st->hTcxCfg->tcx_offset ); // Q0 + lgFB = add( lgFB, shr( lgFB, sub( 3, nSubframes ) ) ); // Q0 - if ( st->hTcxCfg->lfacNext < 0 ) + IF( st->hTcxCfg->lfacNext < 0 ) { - lg = sub( lg, st->hTcxCfg->lfacNext ); + lg = sub( lg, st->hTcxCfg->lfacNext ); // Q0 } } @@ -384,33 +384,41 @@ void getTCXparam_fx( move16(); IF( no_param_tns ) { - ix = get_next_indice_fx( st0, 1 ); /* common_tns_data[] for subframe k */ + ix = get_next_indice_fx( st0, 1 ); /* common_tns_data[] for subframe k */ // Q0 } IF( ix ) { - prm[j] = imult1616( no_param_tns[k], -1 ); /* - signals common TNS and its size */ + prm[j] = imult1616( no_param_tns[k], -1 ); /* - signals common TNS and its size */ // Q0 move16(); - nTnsParams = no_param_tns[k]; + nTnsParams = no_param_tns[k]; // Q0 move16(); } ELSE { ReadTnsData_ivas_fx( st->hTcxCfg->pCurrentTnsConfig, st0, &nTnsBits, prm + j, &nTnsParams ); } - hTcxDec->tnsActive[k] = 0; + hTcxDec->tnsActive[k] = 0; // Q0 move16(); if ( prm[j] != 0 ) { - hTcxDec->tnsActive[k] = nTnsParams; + hTcxDec->tnsActive[k] = nTnsParams; // Q0 move16(); } - if ( nTnsBitsTCX10 != NULL ) + IF( nTnsBitsTCX10 != NULL ) { - nTnsBitsTCX10[k] = add( nTnsBits, ( no_param_tns ? 1 : 0 ) ); - move16(); + IF( no_param_tns ) + { + nTnsBitsTCX10[k] = add( nTnsBits, 1 ); // Q0 + move16(); + } + ELSE + { + nTnsBitsTCX10[k] = add( nTnsBits, 0 ); // Q0 + move16(); + } } - j = add( j, nTnsParams ); + j = add( j, nTnsParams ); // Q0 } IF( post_part ) @@ -418,46 +426,46 @@ void getTCXparam_fx( IF( EQ_16( core, TCX_20_CORE ) ) { // Q-factor of TcxBandwidth is 15 : derived from getTcxBandwidth function - hm_size = mult( st->TcxBandwidth, shl( lg, 1 ) ); + hm_size = mult( st->TcxBandwidth, shl( lg, 1 ) ); // Q0 test(); - IF( hTcxDec->tcx_lpc_shaped_ari && NE_16( st->last_core_from_bs, ACELP_CORE ) ) + IF( hTcxDec->tcx_lpc_shaped_ari && ( st->last_core_from_bs != ACELP_CORE ) ) { dec_prm_hm_fx( st0, &prm[j], hm_size ); } - nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) ); + nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) ); // Q0 } ELSE { - hm_size = mult( st->TcxBandwidth, shl( lgFB, 1 ) ); - nbits_tcx = sub( shr( sub( add( sub( sub( st->bits_frame_core, bits_common ), nbits_igf ), 1 ), k ), 1 ), sub( sub( st0->next_bit_pos, start_bit_pos ), nbits_tcx ) ); + hm_size = mult( st->TcxBandwidth, shl( lgFB, 1 ) ); // Q0 + nbits_tcx = sub( shr( sub( add( sub( sub( st->bits_frame_core, bits_common ), nbits_igf ), 1 ), k ), 1 ), sub( sub( st0->next_bit_pos, start_bit_pos ), nbits_tcx ) ); // Q0 } /*Context HM flag*/ test(); test(); - IF( st->hTcxCfg->ctx_hm && !( EQ_16( st->last_core_from_bs, ACELP_CORE ) && ( k == 0 ) ) ) + IF( st->hTcxCfg->ctx_hm && !( ( st->last_core_from_bs == ACELP_CORE ) && ( k == 0 ) ) ) { - useHarmonicModel = get_next_indice_fx( st0, 1 ); - prm[j] = useHarmonicModel; + useHarmonicModel = get_next_indice_fx( st0, 1 ); // Q0 + prm[j] = useHarmonicModel; // Q0 move16(); - nbits_tcx = sub( nbits_tcx, 1 ); + nbits_tcx = sub( nbits_tcx, 1 ); // Q0 IF( useHarmonicModel ) { ix = DecodeIndex_fx( st0, (Word16) GE_16( hm_size, 256 ), prm + add( j, 1 ) ); - flag_ctx_hm = 1; + flag_ctx_hm = 1; // Q0 move16(); PeriodicityIndex = *( prm + add( j, 1 ) ); - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == EVS_MONO ) { ConfigureContextHm( lgFB, nbits_tcx, PeriodicityIndex, hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg ); } - nbits_tcx = sub( nbits_tcx, ix ); + nbits_tcx = sub( nbits_tcx, ix ); // Q0 } } } - j = add( j, NPRM_CTX_HM ); + j = add( j, NPRM_CTX_HM ); // Q0 /* read IGF payload */ test(); @@ -465,31 +473,39 @@ void getTCXparam_fx( { IF( st->igf ) { - ix = st->next_bit_pos; + ix = st->next_bit_pos; // Q0 move16(); - IGFDecReadLevel( st->hIGFDec, st0, ( EQ_16( st->last_core_from_bs, ACELP_CORE ) ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 ); - IGFDecReadData( st->hIGFDec, st0, ( EQ_16( st->last_core_from_bs, ACELP_CORE ) ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 ); + IF( st->last_core_from_bs == ACELP_CORE ) + { + IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_TRAN, 1 ); + IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_TRAN, 1 ); + } + ELSE + { + IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_NORM, 1 ); + IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_NORM, 1 ); + } - nbits_tcx = sub( nbits_tcx, sub( st0->next_bit_pos, ix ) ); + nbits_tcx = sub( nbits_tcx, sub( st0->next_bit_pos, ix ) ); // Q0 } - nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) ); + nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) ); // Q0 } ELSE IF( p_param != NULL ) { - p_param[k] = j; + p_param[k] = j; // Q0 move16(); } } ELSE { - j = p_param[k]; + j = p_param[k]; // Q0 move16(); - nbits_tcx = st->bits_frame_channel; + nbits_tcx = st->bits_frame_channel; // Q0 move16(); if ( EQ_16( st->core, TCX_10_CORE ) ) { - nbits_tcx = sub( nTnsBitsTCX10[k], NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); + nbits_tcx = sub( nTnsBitsTCX10[k], NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); // Q0 } } @@ -498,36 +514,52 @@ void getTCXparam_fx( test(); IF( hTcxDec->tcx_lpc_shaped_ari && EQ_16( core, TCX_20_CORE ) ) { - prm[j] = nbits_tcx; /* store length of buffer */ - j = add( j, 1 ); + prm[j] = nbits_tcx; /* store length of buffer */ // Q0 + j = add( j, 1 ); // Q0 move16(); prms = &prm[j]; FOR( ix = 0; ix < nbits_tcx; ix++ ) { - prms[ix] = get_next_indice_1_fx( st0 ); + prms[ix] = get_next_indice_1_fx( st0 ); // Q0 } FOR( ix = 0; ix < 32; ix++ ) { - prms[add( ix, nbits_tcx )] = 1; + prms[ix + nbits_tcx] = 1; // Q0 + move16(); } - move16(); - j = add( j, nbits_tcx ); + j = add( j, nbits_tcx ); // Q0 } ELSE { - IF( GT_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode > EVS_MONO ) { IF( useHarmonicModel ) { ConfigureContextHm( lgFB, nbits_tcx, PeriodicityIndex, hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg ); } - hTcxDec->resQBits[k] = RCcontextMapping_decode2_no_mem_s17_LCS_fx( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), flag_ctx_hm ? &hm_cfg : NULL ); - move16(); + IF( flag_ctx_hm ) + { + hTcxDec->resQBits[k] = RCcontextMapping_decode2_no_mem_s17_LCS_fx( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), &hm_cfg ); // Q0 + move16(); + } + ELSE + { + hTcxDec->resQBits[k] = RCcontextMapping_decode2_no_mem_s17_LCS_fx( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), NULL ); // Q0 + move16(); + } } ELSE { - hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), flag_ctx_hm ? &hm_cfg : NULL ); - move16(); + IF( flag_ctx_hm ) + { + hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), &hm_cfg ); // Q0 + move16(); + } + ELSE + { + hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), NULL ); // Q0 + move16(); + } } } } @@ -545,9 +577,9 @@ void getTCXparam_fx( *-----------------------------------------------------------------*/ void dec_prm_fx( Word16 *coder_type, - Word16 param[], /* (o) : decoded parameters */ - Word16 param_lpc[], /* (o) : LPC parameters */ - Word16 *total_nbbits, /* i/o : number of bits / decoded bits */ + Word16 param[], /* (o) : decoded parameters Q0 */ + Word16 param_lpc[], /* (o) : LPC parameters Q0 */ + Word16 *total_nbbits, /* i/o : number of bits / decoded bits Q0 */ Decoder_State *st, Word16 L_frame, Word16 *bitsRead ) @@ -613,17 +645,17 @@ void dec_prm_fx( IF( EQ_16( st->rf_flag, 1 ) ) { /*Inherent adjustment to accommodate the compact packing used in the RF mode*/ - start_bit_pos = sub( st->next_bit_pos, 2 ); + start_bit_pos = sub( st->next_bit_pos, 2 ); // Q0 } ELSE { - start_bit_pos = st->next_bit_pos; + start_bit_pos = st->next_bit_pos; // Q0 move16(); } } /* Framing parameters */ - nb_subfr = st->nb_subfr; + nb_subfr = st->nb_subfr; // Q0 move16(); /* Initialize pointers */ @@ -646,12 +678,12 @@ void dec_prm_fx( /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */ IF( st->tcxonly ) { - st->core = add( get_next_indice_fx( st, 1 ), 1 ); + st->core = add( get_next_indice_fx( st, 1 ), 1 ); // Q0 move16(); - ind = get_next_indice_fx( st, 2 ); + ind = get_next_indice_fx( st, 2 ); // Q0 st->clas_dec = ONSET; move16(); - if ( ind == 0 ) + IF( ind == 0 ) { st->clas_dec = UNVOICED_CLAS; move16(); @@ -683,7 +715,7 @@ void dec_prm_fx( /* 2 bits instead of 3 as TCX is already signaled */ st->core = TCX_20_CORE; move16(); - st->hTcxCfg->coder_type = get_next_indice_fx( st, 2 ); + st->hTcxCfg->coder_type = get_next_indice_fx( st, 2 ); // Q0 move16(); *coder_type = st->hTcxCfg->coder_type; move16(); @@ -694,7 +726,7 @@ void dec_prm_fx( { IF( get_next_indice_1_fx( st ) != 0 ) /* TCX */ { - tmp = get_next_indice_fx( st, 3 ); + tmp = get_next_indice_fx( st, 3 ); // Q0 assert( !( tmp & 4 ) || !"HQ_CORE encountered in dec_prm_fx" ); st->core = TCX_20_CORE; move16(); @@ -707,7 +739,7 @@ void dec_prm_fx( { st->core = ACELP_CORE; move16(); - *coder_type = get_next_indice_fx( st, 2 ); + *coder_type = get_next_indice_fx( st, 2 ); // Q0 move16(); } } @@ -736,7 +768,7 @@ void dec_prm_fx( { st->core = ACELP_CORE; move16(); - *coder_type = get_next_indice_fx( st, 3 ); + *coder_type = get_next_indice_fx( st, 3 ); // Q0 move16(); IF( GE_16( *coder_type, ACELP_MODE_MAX ) ) { @@ -752,22 +784,22 @@ void dec_prm_fx( } test(); - if ( ( st->igf != 0 ) && EQ_16( st->core, ACELP_CORE ) ) + IF( ( st->igf != 0 ) && ( st->core == ACELP_CORE ) ) { - st->bits_frame_core = sub( st->bits_frame_core, get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) ); + st->bits_frame_core = sub( st->bits_frame_core, get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) ); // Q0 move16(); } - if ( EQ_16( st->rf_flag, 1 ) ) + IF( EQ_16( st->rf_flag, 1 ) ) { - st->bits_frame_core = sub( st->bits_frame_core, add( st->rf_target_bits, 1 ) ); /* +1 as flag-bit not considered in rf_target_bits */ + st->bits_frame_core = sub( st->bits_frame_core, add( st->rf_target_bits, 1 ) ); /* +1 as flag-bit not considered in rf_target_bits */ // Q0 move16(); } /* Inactive frame detection on non-DTX mode */ st->VAD = 1; move16(); - if ( EQ_16( *coder_type, INACTIVE ) ) + if ( *coder_type == INACTIVE ) { st->VAD = 0; move16(); @@ -778,7 +810,7 @@ void dec_prm_fx( st->core_ext_mode = *coder_type; move16(); - if ( EQ_16( *coder_type, INACTIVE ) ) + if ( *coder_type == INACTIVE ) { st->core_ext_mode = UNVOICED; move16(); @@ -789,7 +821,7 @@ void dec_prm_fx( move16(); test(); test(); - IF( ( NE_16( st->core, ACELP_CORE ) || st->hTcxCfg->lfacNext > 0 ) && st->use_partial_copy == 0 ) + IF( ( ( st->core != ACELP_CORE ) || st->hTcxCfg->lfacNext > 0 ) && st->use_partial_copy == 0 ) { st->last_core_from_bs = get_next_indice_fx( st, 1 ); move16(); @@ -812,8 +844,8 @@ void dec_prm_fx( IF( EQ_16( st->core, TCX_10_CORE ) ) { st->last_core = TCX_20_CORE; - st->last_core_from_bs = TCX_20_CORE; move16(); + st->last_core_from_bs = TCX_20_CORE; move16(); } } @@ -828,14 +860,14 @@ void dec_prm_fx( Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ - get_next_indice_tmp_fx( st, sub( sub( sub( add( start_bit_pos, num_bits ), st->rf_target_bits ), 3 ), st->next_bit_pos ) ); + get_next_indice_tmp_fx( st, sub( sub( sub( add( start_bit_pos, num_bits ), st->rf_target_bits ), 3 ), st->next_bit_pos ) ); // Q0 } IF( st->use_partial_copy == 0 ) { /* Set the last overlap mode based on the previous and current frame type and coded overlap mode */ test(); - IF( ( EQ_16( st->last_core, ACELP_CORE ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) ) + IF( ( st->last_core == ACELP_CORE ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) ) { st->hTcxCfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; move16(); @@ -853,7 +885,7 @@ void dec_prm_fx( st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode; move16(); test(); - if ( ( NE_16( st->core, TCX_10_CORE ) ) && ( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) + if ( ( NE_16( st->core, TCX_10_CORE ) ) && ( st->hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) ) { st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; move16(); @@ -864,12 +896,12 @@ void dec_prm_fx( st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); - IF( NE_16( st->core, ACELP_CORE ) ) + IF( st->core != ACELP_CORE ) { tmp = 0; move16(); /* if current TCX mode is not 0 (full overlap), read another bit */ - if ( get_next_indice_fx( st, 1 ) ) + IF( get_next_indice_fx( st, 1 ) ) { tmp = add( 2, get_next_indice_fx( st, 1 ) ); } @@ -880,7 +912,7 @@ void dec_prm_fx( test(); test(); test(); - if ( ( EQ_16( st->core, TCX_20_CORE ) ) && ( tmp == 0 ) && ( NE_16( st->last_core, ACELP_CORE ) ) && ( NE_16( st->last_core, AMR_WB_CORE ) ) ) + if ( ( EQ_16( st->core, TCX_20_CORE ) ) && ( tmp == 0 ) && ( st->last_core != ACELP_CORE ) && ( NE_16( st->last_core, AMR_WB_CORE ) ) ) { st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); @@ -897,28 +929,28 @@ void dec_prm_fx( search_range = 8; move16(); - st->flagGuidedAcelp = get_next_indice_fx( st, 1 ); + st->flagGuidedAcelp = get_next_indice_fx( st, 1 ); // Q0 move16(); pitchDiff = 0; move16(); IF( st->flagGuidedAcelp ) { - pitchDiff = get_next_indice_fx( st, bits_per_subfr ); + pitchDiff = get_next_indice_fx( st, bits_per_subfr ); // Q0 move16(); - st->guidedT0 = sub( pitchDiff, search_range ); + st->guidedT0 = sub( pitchDiff, search_range ); // Q0 move16(); } test(); if ( ( pitchDiff == 0 ) && st->flagGuidedAcelp ) { - st->flagGuidedAcelp = 0; + st->flagGuidedAcelp = 0; // Q0 move16(); } } ELSE { - st->flagGuidedAcelp = 0; + st->flagGuidedAcelp = 0; // Q0 move16(); } @@ -926,9 +958,9 @@ void dec_prm_fx( { move16(); st->dec_glr_idx = -1; - if ( EQ_16( st->core, ACELP_CORE ) ) + IF( st->core == ACELP_CORE ) { - st->dec_glr_idx = get_next_indice_fx( st, G_LPC_RECOVERY_BITS ); + st->dec_glr_idx = get_next_indice_fx( st, G_LPC_RECOVERY_BITS ); // Q0 move16(); } } @@ -962,7 +994,7 @@ void dec_prm_fx( /* Decode LPC parameters */ test(); - IF( hTcxDec->enableTcxLpc && NE_16( st->core, ACELP_CORE ) ) + IF( hTcxDec->enableTcxLpc && ( st->core != ACELP_CORE ) ) { Word16 tcx_lpc_cdk; tcx_lpc_cdk = tcxlpc_get_cdk( *coder_type ); @@ -984,7 +1016,7 @@ void dec_prm_fx( { test(); test(); - IF( EQ_32( st->sr_core, 16000 ) && EQ_16( *coder_type, VOICED ) && EQ_16( st->core, ACELP_CORE ) ) + IF( EQ_32( st->sr_core, 16000 ) && EQ_16( *coder_type, VOICED ) && ( st->core == ACELP_CORE ) ) { lsf_bctcvq_decprm( st, param_lpc ); } @@ -1007,26 +1039,26 @@ void dec_prm_fx( test(); IF( EQ_16( st->rf_frame_type, RF_TCXFD ) ) { - param_lpc[0] = 0; + param_lpc[0] = 0; // Q0 move16(); - param_lpc[1] = get_next_indice_fx( st, lsf_numbits[0] ); /* VQ 1 */ + param_lpc[1] = get_next_indice_fx( st, lsf_numbits[0] ); /* VQ 1 */ // Q0 move16(); - param_lpc[2] = get_next_indice_fx( st, lsf_numbits[1] ); /* VQ 2 */ + param_lpc[2] = get_next_indice_fx( st, lsf_numbits[1] ); /* VQ 2 */ // Q0 move16(); - param_lpc[3] = get_next_indice_fx( st, lsf_numbits[2] ); /* VQ 3 */ + param_lpc[3] = get_next_indice_fx( st, lsf_numbits[2] ); /* VQ 3 */ // Q0 move16(); } ELSE IF( GE_16( st->rf_frame_type, RF_ALLPRED ) && LE_16( st->rf_frame_type, RF_NELP ) ) { /* LSF indices */ - param_lpc[0] = get_next_indice_fx( st, 8 ); /* VQ 1 */ + param_lpc[0] = get_next_indice_fx( st, 8 ); /* VQ 1 */ // Q0 move16(); - param_lpc[1] = get_next_indice_fx( st, 8 ); /* VQ 2 */ + param_lpc[1] = get_next_indice_fx( st, 8 ); /* VQ 2 */ // Q0 move16(); } } - st->bits_common = sub( st->next_bit_pos, start_bit_pos ); + st->bits_common = sub( st->next_bit_pos, start_bit_pos ); // Q0 move16(); @@ -1035,7 +1067,7 @@ void dec_prm_fx( *--------------------------------------------------------------------------------*/ test(); test(); - IF( EQ_16( st->core, ACELP_CORE ) && ( st->use_partial_copy == 0 ) ) + IF( ( st->core == ACELP_CORE ) && ( st->use_partial_copy == 0 ) ) { /* Target Bits */ acelp_target_bits = sub( st->bits_frame_core, st->bits_common ); @@ -1053,23 +1085,23 @@ void dec_prm_fx( } /* Adaptive BPF (2 bits)*/ - n = ACELP_BPF_BITS[st->acelp_cfg.bpf_mode]; + n = ACELP_BPF_BITS[st->acelp_cfg.bpf_mode]; // Q0 move16(); - st->bpf_gain_param = shl( st->acelp_cfg.bpf_mode, 1 ); - if ( n != 0 ) + st->bpf_gain_param = shl( st->acelp_cfg.bpf_mode, 1 ); // Q0 + IF( n != 0 ) { - st->bpf_gain_param = get_next_indice_fx( st, n ); + st->bpf_gain_param = get_next_indice_fx( st, n ); // Q0 move16(); } /* Mean energy (2 or 3 bits) */ - n = ACELP_NRG_BITS[st->acelp_cfg.nrg_mode]; + n = ACELP_NRG_BITS[st->acelp_cfg.nrg_mode]; // Q0 move16(); - if ( n != 0 ) + IF( n != 0 ) { - prm[j] = get_next_indice_fx( st, n ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, n ); // Q0 + j = add( j, 1 ); // Q0 move16(); } @@ -1077,63 +1109,63 @@ void dec_prm_fx( FOR( sfr = 0; sfr < nb_subfr; sfr++ ) { /* Pitch lag (4, 5, 6, 8 or 9 bits) */ - n = ACELP_LTP_BITS_SFR[st->acelp_cfg.ltp_mode][sfr]; + n = ACELP_LTP_BITS_SFR[st->acelp_cfg.ltp_mode][sfr]; // Q0 move16(); IF( n != 0 ) { - prm[j] = get_next_indice_fx( st, n ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, n ); // Q0 + j = add( j, 1 ); // Q0 move16(); } /* Adaptive codebook filtering (1 bit) */ IF( EQ_16( st->acelp_cfg.ltf_mode, 2 ) ) { - prm[j] = get_next_indice_fx( st, 1 ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); // Q0 + j = add( j, 1 ); // Q0 move16(); } /* Innovative codebook */ { /* Decode pulse positions. */ - j_old = j; + j_old = j; // Q0 move16(); - wordcnt = shr( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 4 ); - bitcnt = s_and( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 0xF ); + wordcnt = shr( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 4 ); // Q0 + bitcnt = s_and( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 0xF ); // Q0 /* sanity check for testing - not instrumented */ test(); IF( GE_16( st->acelp_cfg.fixed_cdk_index[sfr], ACELP_FIXED_CDK_NB ) || ( st->acelp_cfg.fixed_cdk_index[sfr] < 0 ) ) { - st->acelp_cfg.fixed_cdk_index[sfr] = 0; + st->acelp_cfg.fixed_cdk_index[sfr] = 0; // Q0 move16(); - st->BER_detect = 1; + st->BER_detect = 1; // Q0 move16(); } FOR( ix = 0; ix < wordcnt; ix++ ) { - prm[j] = (Word16) get_next_indice_fx( st, 16 ); - j = add( j, 1 ); + prm[j] = (Word16) get_next_indice_fx( st, 16 ); // Q0 + j = add( j, 1 ); // Q0 move16(); } - if ( bitcnt ) + IF( bitcnt ) { - prm[j] = get_next_indice_fx( st, bitcnt ); + prm[j] = get_next_indice_fx( st, bitcnt ); // Q0 move16(); } - j = add( j_old, 8 ); + j = add( j_old, 8 ); // Q0 } /* Gains (5b, 6b or 7b / subfr) */ - n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; + n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; // Q0 move16(); - prm[j] = get_next_indice_fx( st, n ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, n ); // Q0 + j = add( j, 1 ); // Q0 move16(); } /*end of subfr loop*/ } @@ -1157,43 +1189,44 @@ void dec_prm_fx( IF( EQ_16( st->rf_frame_type, RF_NELP ) ) { /* NELP gain indices */ - st->rf_indx_nelp_iG1 = get_next_indice_fx( st, 5 ); - st->rf_indx_nelp_iG2[0] = get_next_indice_fx( st, 6 ); + st->rf_indx_nelp_iG1 = get_next_indice_fx( st, 5 ); // Q0 move16(); - st->rf_indx_nelp_iG2[1] = get_next_indice_fx( st, 6 ); + st->rf_indx_nelp_iG2[0] = get_next_indice_fx( st, 6 ); // Q0 + move16(); + st->rf_indx_nelp_iG2[1] = get_next_indice_fx( st, 6 ); // Q0 move16(); /* NELP filter selection index */ - st->rf_indx_nelp_fid = get_next_indice_fx( st, 2 ); + st->rf_indx_nelp_fid = get_next_indice_fx( st, 2 ); // Q0 move16(); /* tbe gainFr */ - st->rf_indx_tbeGainFr = get_next_indice_fx( st, 5 ); + st->rf_indx_tbeGainFr = get_next_indice_fx( st, 5 ); // Q0 move16(); } ELSE { /* rf_frame_type ALL_PRED: 4, NO_PRED: 5, GEN_PRED: 6*/ /* ES pred */ - prm[j] = get_next_indice_fx( st, 3 ); + prm[j] = get_next_indice_fx( st, 3 ); // Q0 move16(); - j = add( j, 1 ); + j = add( j, 1 ); // Q0 - ltp_mode = ACELP_LTP_MODE[1][1][st->rf_frame_type]; + ltp_mode = ACELP_LTP_MODE[1][1][st->rf_frame_type]; // Q0 move16(); - gains_mode = ACELP_GAINS_MODE[1][1][st->rf_frame_type]; + gains_mode = ACELP_GAINS_MODE[1][1][st->rf_frame_type]; // Q0 move16(); /* Subframe parameters */ FOR( sfr = 0; sfr < nb_subfr; sfr++ ) { /* Pitch lag (5, or 8 bits) */ - n = ACELP_LTP_BITS_SFR[ltp_mode][sfr]; + n = ACELP_LTP_BITS_SFR[ltp_mode][sfr]; // Q0 move16(); IF( n != 0 ) { - prm[j] = get_next_indice_fx( st, n ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, n ); // Q0 + j = add( j, 1 ); // Q0 move16(); } @@ -1205,24 +1238,24 @@ void dec_prm_fx( { /* NOTE: FCB actual bits need to be backed up as well */ /*n = ACELP_FIXED_CDK_BITS(st->rf_indx_fcb[fec_offset][sfr]) & 15;*/ - prm[j] = get_next_indice_fx( st, 7 ); + prm[j] = get_next_indice_fx( st, 7 ); // Q0 move16(); - j = add( j, 8 ); + j = add( j, 8 ); // Q0 } /* Gains (5b, 6b or 7b / subfr) */ test(); IF( sfr == 0 || EQ_16( sfr, 2 ) ) { - n = ACELP_GAINS_BITS[gains_mode]; + n = ACELP_GAINS_BITS[gains_mode]; // Q0 move16(); - prm[j] = get_next_indice_fx( st, n ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, n ); // Q0 + j = add( j, 1 ); // Q0 move16(); } } - st->rf_indx_tbeGainFr = get_next_indice_fx( st, 2 ); + st->rf_indx_tbeGainFr = get_next_indice_fx( st, 2 ); // Q0 move16(); } } @@ -1238,18 +1271,18 @@ void dec_prm_fx( if ( st->enablePlcWaveadjust ) { - st->tonality_flag = get_next_indice_fx( st, 1 ); + st->tonality_flag = get_next_indice_fx( st, 1 ); // Q0 move16(); } /* TCX Gain = 7 bits */ - prm[j] = get_next_indice_fx( st, 7 ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, 7 ); // Q0 + j = add( j, 1 ); // Q0 move16(); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); // Q0 + j = add( j, 1 ); // Q0 move16(); /* LTP data */ @@ -1258,31 +1291,31 @@ void dec_prm_fx( IF( hTcxLtpDec->tcxltp != 0 || GT_32( st->sr_core, 25600 ) ) { - prm[j] = get_next_indice_fx( st, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); // Q0 move16(); IF( prm[j] ) { - prm[j + 1] = get_next_indice_fx( st, 9 ); + prm[j + 1] = get_next_indice_fx( st, 9 ); // Q0 move16(); - prm[j + 2] = get_next_indice_fx( st, 2 ); + prm[j + 2] = get_next_indice_fx( st, 2 ); // Q0 move16(); } - st->BER_detect = st->BER_detect | - tcx_ltp_decode_params( &prm[j], - &( hTcxLtpDec->tcxltp_pitch_int ), - &( hTcxLtpDec->tcxltp_pitch_fr ), - &( hTcxLtpDec->tcxltp_gain ), - st->pit_min, - st->pit_fr1, - st->pit_fr2, - st->pit_max, - st->pit_res_max ); + st->BER_detect = s_or( st->BER_detect, + tcx_ltp_decode_params( &prm[j], + &( hTcxLtpDec->tcxltp_pitch_int ), + &( hTcxLtpDec->tcxltp_pitch_fr ), + &( hTcxLtpDec->tcxltp_gain ), + st->pit_min, + st->pit_fr1, + st->pit_fr2, + st->pit_max, + st->pit_res_max ) ); - hTcxDec->tcx_hm_LtpPitchLag = -1; + hTcxDec->tcx_hm_LtpPitchLag = -1; // Q15 move16(); - hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; + hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15 move16(); test(); @@ -1290,12 +1323,12 @@ void dec_prm_fx( { Word32 tmp32 = L_shl( L_mult0( st->L_frame, st->pit_res_max ), 1 + kLtpHmFractionalResolution + 1 ); Word16 tmp1 = add( imult1616( hTcxLtpDec->tcxltp_pitch_int, st->pit_res_max ), hTcxLtpDec->tcxltp_pitch_fr ); - hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 ); + hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 ); // Q15 move16(); } } - j = add( j, 3 ); + j = add( j, 3 ); // Q0 /* TCX spectral data */ lg = L_frame; @@ -1303,16 +1336,16 @@ void dec_prm_fx( lgFB = st->hTcxCfg->tcx_coded_lines; move16(); - IF( EQ_16( st->last_core_from_bs, ACELP_CORE ) ) + IF( st->last_core_from_bs == ACELP_CORE ) { /* ACE->TCX transition */ - lg = add( lg, st->hTcxCfg->tcx_offset ); + lg = add( lg, st->hTcxCfg->tcx_offset ); // Q0 if ( st->hTcxCfg->lfacNext < 0 ) { - lg = sub( lg, st->hTcxCfg->lfacNext ); + lg = sub( lg, st->hTcxCfg->lfacNext ); // Q0 } - lgFB = add( lgFB, shr( lgFB, 2 ) ); + lgFB = add( lgFB, shr( lgFB, 2 ) ); // Q0 } /* TNS data */ @@ -1326,7 +1359,7 @@ void dec_prm_fx( SetTnsConfig( st->hTcxCfg, 1, (Word16) EQ_16( st->last_core_from_bs, ACELP_CORE ) ); ReadTnsData( st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm + j, &nTnsParams ); - j = add( j, nTnsParams ); + j = add( j, nTnsParams ); // Q0 } hm_size = shl( mult( st->TcxBandwidth, lg ), 1 ); @@ -1337,18 +1370,18 @@ void dec_prm_fx( } nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) ); - if ( st->enableGplc != 0 ) + IF( st->enableGplc != 0 ) { - nbits_tcx = sub( nbits_tcx, 7 ); + nbits_tcx = sub( nbits_tcx, 7 ); // Q0 } /*Context HM flag*/ test(); - IF( st->hTcxCfg->ctx_hm && NE_16( st->last_core_from_bs, ACELP_CORE ) ) + IF( st->hTcxCfg->ctx_hm && ( st->last_core_from_bs != ACELP_CORE ) ) { - prm[j] = get_next_indice_fx( st, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); // Q0 move16(); - nbits_tcx = sub( nbits_tcx, 1 ); + nbits_tcx = sub( nbits_tcx, 1 ); // Q0 IF( prm[j] ) { @@ -1375,10 +1408,10 @@ void dec_prm_fx( hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg ); - nbits_tcx = sub( nbits_tcx, NumIndexBits ); + nbits_tcx = sub( nbits_tcx, NumIndexBits ); // Q0 } } - j = add( j, NPRM_CTX_HM ); + j = add( j, NPRM_CTX_HM ); // Q0 /* read IGF payload */ IF( st->igf ) @@ -1386,7 +1419,7 @@ void dec_prm_fx( n = st->next_bit_pos; move16(); - IF( EQ_16( st->last_core_from_bs, ACELP_CORE ) ) + IF( st->last_core_from_bs == ACELP_CORE ) { IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 ); IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 ); @@ -1397,22 +1430,22 @@ void dec_prm_fx( IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_NORM, 1 ); } - nbits_tcx = sub( nbits_tcx, sub( st->next_bit_pos, n ) ); + nbits_tcx = sub( nbits_tcx, sub( st->next_bit_pos, n ) ); // Q0 } - nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) ); + nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) ); // Q0 IF( hTcxDec->tcx_lpc_shaped_ari != 0 ) { - prm[j] = nbits_tcx; /* store length of buffer */ - j = add( j, 1 ); + prm[j] = nbits_tcx; /* store length of buffer */ // Q0 + j = add( j, 1 ); // Q0 move16(); prms = &prm[j]; FOR( ix = 0; ix < nbits_tcx; ix++ ) { - prms[ix] = get_next_indice_1_fx( st ); + prms[ix] = get_next_indice_1_fx( st ); // Q0 move16(); } set16_fx( prms + nbits_tcx, 1, 32 ); - j = add( j, nbits_tcx ); + j = add( j, nbits_tcx ); // Q0 } ELSE { @@ -1423,9 +1456,9 @@ void dec_prm_fx( phm_cfg = &hm_cfg; move16(); } - hTcxDec->resQBits[0] = ACcontextMapping_decode2_no_mem_s17_LC( st, prm + j, lgFB, nbits_tcx, NPRM_RESQ * st->hTcxCfg->resq, phm_cfg ); + hTcxDec->resQBits[0] = ACcontextMapping_decode2_no_mem_s17_LC( st, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), phm_cfg ); // Q0 move16(); - j = add( j, lg ); + j = add( j, lg ); // Q0 } } @@ -1434,7 +1467,7 @@ void dec_prm_fx( IF( GE_16( st->rf_frame_type, RF_TCXFD ) && LE_16( st->rf_frame_type, RF_TCXTD2 ) && EQ_16( st->use_partial_copy, 1 ) ) { /* classification */ - ind = get_next_indice_fx( st, 2 ); + ind = get_next_indice_fx( st, 2 ); // Q0 st->clas_dec = ONSET; move16(); @@ -1465,7 +1498,7 @@ void dec_prm_fx( IF( EQ_16( st->rf_frame_type, RF_TCXFD ) ) { /* TCX Gain = 7 bits */ - hTcxDec->old_gaintcx_bfi = get_next_indice_fx( st, 7 ); + hTcxDec->old_gaintcx_bfi = get_next_indice_fx( st, 7 ); // Q0 move16(); } ELSE @@ -1476,19 +1509,19 @@ void dec_prm_fx( test(); IF( EQ_16( st->rf_frame_type, RF_TCXTD2 ) || EQ_16( st->rf_frame_type, RF_TCXTD1 ) ) { - prm_ltp[0] = 1; - move16(); /* LTP active*/ - prm_ltp[1] = get_next_indice_fx( st, 9 ); - prm_ltp[2] = 3; - move16(); /* max ampl. quantizer output (2bits), anyway not used later*/ + prm_ltp[0] = 1; // Q0 + move16(); /* LTP active*/ + prm_ltp[1] = get_next_indice_fx( st, 9 ); // Q0 + prm_ltp[2] = 3; // Q0 + move16(); /* max ampl. quantizer output (2bits), anyway not used later*/ IF( st->prev_bfi == 0 ) { - st->BER_detect = st->BER_detect | - tcx_ltp_decode_params( &prm_ltp[0], &( hTcxLtpDec->tcxltp_pitch_int ), &( hTcxLtpDec->tcxltp_pitch_fr ), &( hTcxLtpDec->tcxltp_gain ), - st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ); + st->BER_detect = s_or( st->BER_detect, + tcx_ltp_decode_params( &prm_ltp[0], &( hTcxLtpDec->tcxltp_pitch_int ), &( hTcxLtpDec->tcxltp_pitch_fr ), &( hTcxLtpDec->tcxltp_gain ), + st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ) ); move16(); - hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; + hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15 move16(); } } @@ -1536,22 +1569,22 @@ void dec_prm_fx( j = 0; move16(); - nbits_tcx = sub( st->next_bit_pos, start_bit_pos ); + nbits_tcx = sub( st->next_bit_pos, start_bit_pos ); // Q0 test(); - if ( st->enablePlcWaveadjust && k ) + IF( st->enablePlcWaveadjust && k ) { - st->tonality_flag = get_next_indice_fx( st, 1 ); + st->tonality_flag = get_next_indice_fx( st, 1 ); // Q0 move16(); } /* TCX Gain = 7 bits */ - prm[j] = get_next_indice_fx( st, 7 ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, 7 ); // Q0 + j = add( j, 1 ); // Q0 move16(); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); // Q0 + j = add( j, 1 ); // Q0 move16(); /* LTP data */ @@ -1559,22 +1592,22 @@ void dec_prm_fx( test(); IF( ( k == 0 ) && ( ( hTcxLtpDec->tcxltp != 0 ) || ( GT_32( st->sr_core, 25600 ) ) ) ) { - prm[j] = get_next_indice_fx( st, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); // Q0 move16(); IF( prm[j] ) { - prm[j + 1] = get_next_indice_fx( st, 9 ); + prm[j + 1] = get_next_indice_fx( st, 9 ); // Q0 move16(); - prm[j + 2] = get_next_indice_fx( st, 2 ); + prm[j + 2] = get_next_indice_fx( st, 2 ); // Q0 move16(); - tcxltp_prm_0 = prm[j]; + tcxltp_prm_0 = prm[j]; // Q0 move16(); - tcxltp_prm_1 = prm[j + 1]; + tcxltp_prm_1 = prm[j + 1]; // Q0 move16(); - tcxltp_prm_2 = prm[j + 2]; + tcxltp_prm_2 = prm[j + 2]; // Q0 move16(); } @@ -1590,32 +1623,32 @@ void dec_prm_fx( st->pit_res_max ) ); move16(); - hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; + hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15 move16(); - hTcxDec->tcx_hm_LtpPitchLag = -1; + hTcxDec->tcx_hm_LtpPitchLag = -1; // Q15 move16(); - j = add( j, 3 ); + j = add( j, 3 ); // Q0 } ELSE { - prm[j] = tcxltp_prm_0; - j = add( j, 1 ); + prm[j] = tcxltp_prm_0; // Q0 + j = add( j, 1 ); // Q0 move16(); - prm[j] = tcxltp_prm_1; - j = add( j, 1 ); + prm[j] = tcxltp_prm_1; // Q0 + j = add( j, 1 ); // Q0 move16(); - prm[j] = tcxltp_prm_2; - j = add( j, 1 ); + prm[j] = tcxltp_prm_2; // Q0 + j = add( j, 1 ); // Q0 move16(); } /* TCX spectral data */ - lg = shr( L_frame, 1 ); - lgFB = shr( st->hTcxCfg->tcx_coded_lines, 1 ); + lg = shr( L_frame, 1 ); // Q0 + lgFB = shr( st->hTcxCfg->tcx_coded_lines, 1 ); // Q0 test(); - IF( k == 0 && EQ_16( st->last_core_from_bs, ACELP_CORE ) ) + IF( k == 0 && ( st->last_core_from_bs == ACELP_CORE ) ) { /* ACE->TCX transition */ lg = add( lg, st->hTcxCfg->tcx_offset ); @@ -1656,31 +1689,31 @@ void dec_prm_fx( hm_size = shl( mult( st->TcxBandwidth, lgFB ), 1 ); /*compute target bits*/ - nbits_tcx = sub( shr( sub( add( sub( sub( st->bits_frame_core, st->bits_common ), nbits_igf ), 1 ), k ), 1 ), sub( sub( st->next_bit_pos, start_bit_pos ), nbits_tcx ) ); + nbits_tcx = sub( shr( sub( add( sub( sub( st->bits_frame_core, st->bits_common ), nbits_igf ), 1 ), k ), 1 ), sub( sub( st->next_bit_pos, start_bit_pos ), nbits_tcx ) ); // Q0 /*Context HM flag*/ test(); test(); - IF( st->hTcxCfg->ctx_hm && !( EQ_16( st->last_core_from_bs, ACELP_CORE ) && ( k == 0 ) ) ) + IF( st->hTcxCfg->ctx_hm && !( ( st->last_core_from_bs == ACELP_CORE ) && ( k == 0 ) ) ) { - prm[j] = get_next_indice_fx( st, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); // Q0 move16(); - nbits_tcx = sub( nbits_tcx, 1 ); + nbits_tcx = sub( nbits_tcx, 1 ); // Q0 move16(); IF( prm[j] ) /* Read PeriodicityIndex */ { - Word16 NumIndexBits = DecodeIndex_fx( st, (Word16) GE_16( hm_size, 256 ), prm + j + 1 ); + Word16 NumIndexBits = DecodeIndex_fx( st, (Word16) GE_16( hm_size, 256 ), prm + j + 1 ); // Q0 flag_ctx_hm = 1; move16(); ConfigureContextHm( lgFB, nbits_tcx, *( prm + j + 1 ), -1, &hm_cfg ); - nbits_tcx = sub( nbits_tcx, NumIndexBits ); + nbits_tcx = sub( nbits_tcx, NumIndexBits ); // Q0 } } - j = add( j, NPRM_CTX_HM ); + j = add( j, NPRM_CTX_HM ); // Q0 phm_cfg = NULL; move16(); if ( flag_ctx_hm ) @@ -1688,9 +1721,9 @@ void dec_prm_fx( phm_cfg = &hm_cfg; move16(); } - hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st, prm + j, lgFB, nbits_tcx, NPRM_RESQ * st->hTcxCfg->resq, phm_cfg ); + hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), phm_cfg ); // Q0 move16(); - j = add( j, lgFB ); + j = add( j, lgFB ); // Q0 } /* k, window index */ } @@ -1701,10 +1734,10 @@ void dec_prm_fx( { st->BER_detect = 1; move16(); - st->next_bit_pos = add( start_bit_pos, sub( *total_nbbits, bitsRead[0] ) ); + st->next_bit_pos = add( start_bit_pos, sub( *total_nbbits, bitsRead[0] ) ); // Q0 move16(); } - bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); + bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); // Q0 move16(); } diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index b952ba542ccec97faa122d6872f1341ffdfcd6ee..3481c797d6f143face290fb748d8d1ebacbdba8f 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -1,3 +1,4 @@ + /****************************************************************************************************** (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, @@ -1559,7 +1560,7 @@ void decoder_tcx_tns_fx( const Word16 L_spec, const Word16 L_frame, const Word16 L_frameTCX, - Word32 x_fx[N_MAX], + Word32 x_fx[N_MAX], // Qx const Word16 fUseTns, /* i : flag that is set if TNS data is present */ STnsData *tnsData, const Word16 bfi, /* i : Bad frame indicator */ @@ -1947,9 +1948,10 @@ void decoder_tcx_imdct_fx( TCX_DEC_HANDLE hTcxDec = st->hTcxDec; TCX_CONFIG_HANDLE hTcxCfg = st->hTcxCfg; Word16 predictionGain_fx; - Word16 A_itf_fx[ITF_MAX_FILTER_ORDER + 1]; + Word16 A_itf_fx[ITF_MAX_FILTER_ORDER + 1]; // q_a_itf Word16 q_a_itf = 15; - Word16 x_e = 31 - q_x; + Word16 x_e = sub( 31, q_x ); + move16(); /*-----------------------------------------------------------------* * Initializations @@ -1963,18 +1965,23 @@ void decoder_tcx_imdct_fx( index = hTcxCfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ move16(); - IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) && NE_16( frame_cnt, 0 ) && EQ_16( bfi, 0 ) && NE_16( st->last_core, ACELP_CORE ) ) + test(); + test(); + test(); + test(); + IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && ( st->tcxonly != 0 ) && ( frame_cnt != 0 ) && ( bfi == 0 ) && ( st->last_core != ACELP_CORE ) ) { /* fix sub-window overlap */ hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode; move16(); } - IF( NE_16( st->igf, 0 ) ) + IF( st->igf != 0 ) { proc = st->hIGFDec->flatteningTrigger; move16(); + test(); IF( proc && fUseTns != 0 ) { proc = 0; @@ -1998,18 +2005,32 @@ void decoder_tcx_imdct_fx( move16(); /* interleave again for ITF */ + test(); IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && st->tcxonly ) { - IF( ( hTcxCfg->fIsTNSAllowed && NE_16( fUseTns, 0 ) && NE_16( bfi, 1 ) ) || GT_16( L_spec, L_frameTCX ) ) + test(); + test(); + test(); + IF( ( hTcxCfg->fIsTNSAllowed && ( fUseTns != 0 ) && NE_16( bfi, 1 ) ) || GT_16( L_spec, L_frameTCX ) ) { L = L_spec; move16(); } - IF( ( EQ_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) || - ( EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) && EQ_16( frame_cnt, 0 ) && EQ_16( index, 0 ) ) ) ) || - ( NE_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) && - NE_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( bfi == 0 ) && ( ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) || + ( ( hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) && ( frame_cnt == 0 ) && ( index == 0 ) ) ) ) || + ( ( bfi != 0 ) && ( ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) && + ( hTcxCfg->tcx_curr_overlap_mode != FULL_OVERLAP ) ) ) ) { isTCX5 = 1; move16(); @@ -2022,7 +2043,7 @@ void decoder_tcx_imdct_fx( { IF( EQ_16( st->hIGFDec->flag_sparse[j - IGF_START_MN], 2 ) ) { - x_itf_fx[j - IGF_START_MN] = x_fx[j]; + x_itf_fx[j - IGF_START_MN] = x_fx[j]; // q_x move32(); x_fx[j] = st->hIGFDec->virtualSpec_fx[j - IGF_START_MN]; move32(); @@ -2035,9 +2056,9 @@ void decoder_tcx_imdct_fx( FOR( j = startLine; j < endLine; j++ ) { - IF( st->hIGFDec->flag_sparse[j - IGF_START_MN] == 2 ) + IF( EQ_16( st->hIGFDec->flag_sparse[j - IGF_START_MN], 2 ) ) { - x_fx[j] = x_itf_fx[j - IGF_START_MN]; + x_fx[j] = x_itf_fx[j - IGF_START_MN]; // q_x move32(); } } @@ -2059,25 +2080,26 @@ void decoder_tcx_imdct_fx( IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { set32_fx( x_tmp_fx, 0, L_FRAME_PLUS ); - Copy32( x_fx, x_tmp_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); - Copy32( x_fx, xn_bufFB_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); + Copy32( x_fx, x_tmp_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); // q_x + Copy32( x_fx, xn_bufFB_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); // q_x } - ELSE IF( EQ_16( st->element_mode, EVS_MONO ) ) + ELSE IF( ( st->element_mode == EVS_MONO ) ) { - Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); + Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x } ELSE { - Copy32( x_fx, x_tmp_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); - Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); + Copy32( x_fx, x_tmp_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x + Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x } - IF( NE_16( st->igf, 0 ) ) + IF( ( st->igf != 0 ) ) { set32_fx( xn_bufFB_fx + st->hIGFDec->infoIGFStartLine, 0, L_frameTCX - st->hIGFDec->infoIGFStartLine ); } - IF( st->element_mode != IVAS_CPE_DFT && !sba_dirac_stereo_flag ) + test(); + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) && !sba_dirac_stereo_flag ) { IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, @@ -2086,18 +2108,22 @@ void decoder_tcx_imdct_fx( } /* Generate additional comfort noise to mask potential coding artefacts */ - IF( NE_16( st->flag_cna, 0 ) && NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( st->cna_dirac_flag, 0 ) ) + test(); + test(); + test(); + IF( ( st->flag_cna != 0 ) && NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) && ( st->cna_dirac_flag == 0 ) ) { - generate_masking_noise_mdct_fx( x_fx, &x_e, st->hFdCngDec->hFdCngCom, L_frame ); + generate_masking_noise_mdct_ivas_fx( x_fx, &x_e, st->hFdCngDec->hFdCngCom ); FOR( Word16 ind = 0; ind < L_frame; ind++ ) { - x_fx[ind] = L_shr( x_fx[ind], sub( 31, add( x_e, q_x ) ) ); + x_fx[ind] = L_shr( x_fx[ind], sub( 31, add( x_e, q_x ) ) ); // q_x } } - IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || NE_16( sba_dirac_stereo_flag, 0 ) ) + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || ( sba_dirac_stereo_flag != 0 ) ) { - Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); + Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); @@ -2105,9 +2131,10 @@ void decoder_tcx_imdct_fx( FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ ) { - xn_bufFB_fx_16[ind] = (Word16) L_shr( xn_bufFB_fx[ind], ( q_x - q_win ) ); + xn_bufFB_fx_16[ind] = extract_l( L_shr( xn_bufFB_fx[ind], sub( q_x, q_win ) ) ); // q_x + move16(); } - IF( NE_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode != EVS_MONO ) { IMDCT_ivas_fx( x_tmp_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, @@ -2121,12 +2148,13 @@ void decoder_tcx_imdct_fx( } FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ ) { - xn_bufFB_fx[ind] = L_shl( xn_bufFB_fx_16[ind], ( q_x - q_win ) ); + xn_bufFB_fx[ind] = L_shl( xn_bufFB_fx_16[ind], sub( q_x, q_win ) ); // Q_x } - IF( EQ_16( bfi, 0 ) ) + IF( ( bfi == 0 ) ) { Word16 res_m, res_e = 0; + move16(); st->second_last_tns_active = st->last_tns_active; move16(); st->last_tns_active = hTcxCfg->fIsTNSAllowed & fUseTns; @@ -2157,20 +2185,20 @@ void decoder_tcx_imdct_fx( } /* Update old_syn_overl */ - IF( EQ_16( hTcxCfg->last_aldo, 0 ) ) + IF( hTcxCfg->last_aldo == 0 ) { - Copy( xn_buf_fx + L_frame, hTcxDec->syn_Overl, overlap ); + Copy( xn_buf_fx + L_frame, hTcxDec->syn_Overl, overlap ); // Q(-2) FOR( Word16 ind = 0; ind < overlapFB; ind++ ) { - hTcxDec->syn_OverlFB[ind] = (Word16) L_shr( xn_bufFB_fx[add( ind, L_frameTCX )], sub( q_x, q_win ) ); + hTcxDec->syn_OverlFB[ind] = (Word16) L_shr( xn_bufFB_fx[( ind + L_frameTCX )], sub( q_x, q_win ) ); // q_x } } /* Output */ - Copy( xn_buf_fx + sub( shr( overlap, 1 ), tcx_offset ), synth_fx, L_frame_glob ); + Copy( xn_buf_fx + sub( shr( overlap, 1 ), tcx_offset ), synth_fx, L_frame_glob ); // Q(-2) FOR( Word16 ind = 0; ind < L_frameTCX_glob; ind++ ) { - synthFB_fx[ind] = (Word16) L_shr( xn_bufFB_fx[add( ind, sub( shr( overlapFB, 1 ), tcx_offsetFB ) )], sub( q_x, q_win ) ); + synthFB_fx[ind] = (Word16) L_shr( xn_bufFB_fx[( ind + ( ( overlapFB >> 1 ) - tcx_offsetFB ) )], sub( q_x, q_win ) ); // q_x } diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 1f0bb5d6a407cb16de77f8d1006ad1c4af7e05f4..35a417a6ce0fa410eec31e05a0c7af18078c47fb 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -1613,9 +1613,9 @@ void decoder_tcx_post_fx( Decoder_State *st_fx, #ifdef IVAS_FLOAT_FIXED void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, - Word16 *synth, - Word16 *synthFB, - Word16 *A, + Word16 *synth, // Qx + Word16 *synthFB, // Qx + Word16 *A, // Q: 14 - norm_s(A[0]) Word16 bfi, Word16 MCT_flag ) { @@ -1684,7 +1684,7 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, { tmp32 = L_shl( tmp32_1 /*Q28*/, -( 28 - 15 ) ); /*16Q15*/ #ifdef BASOP_NOGLOB - synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp32, synthFB[i] ), 16 ) ); + synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp32, synthFB[i] ), 16 ) ); // Qx #else synthFB[i] = round_fx( L_shl( Mpy_32_16_1( tmp32, synthFB[i] ), 16 ) ); #endif @@ -1696,8 +1696,8 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, tmp32_2 /*stepCompensate*/ = L_shl_r( L_deposit_h( hTcxDec->stepCompensate ), sub( hTcxDec->stepCompensate_e, 31 - 28 ) ); /*Q28*/ FOR( i = 0; i < st_fx->L_frame; i++ ) { - tmp32 = L_shl( tmp32_1 /*Q28*/, -( 28 - 15 ) ); /*16Q15*/ - xn_buf[i] = extract_l( Mpy_32_16_1( tmp32, xn_buf[i] ) ); + tmp32 = L_shl( tmp32_1 /*Q28*/, -( 28 - 15 ) ); /*16Q15*/ + xn_buf[i] = extract_l( Mpy_32_16_1( tmp32, xn_buf[i] ) ); // Qx move16(); tmp32_1 = L_sub( tmp32_1, tmp32_2 ); } @@ -1843,7 +1843,7 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, } } - if ( ( EQ_16( st_fx->nbLostCmpt, 1 ) ) ) + IF( ( EQ_16( st_fx->nbLostCmpt, 1 ) ) ) { hTcxDec->conceal_eof_gain32 = ONE_IN_Q30 /*1.0f Q30*/; move32(); @@ -1878,14 +1878,14 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { tmp_shift = conceal_eof_gainFB_e; - synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), tmp_shift ) ); + synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), tmp_shift ) ); // Qx move16(); - conceal_eof_gainFB = BASOP_Util_Add_Mant32Exp( conceal_eof_gainFB, conceal_eof_gainFB_e, L_negate( stepFB ), stepFB_e, &conceal_eof_gainFB_e ); + conceal_eof_gainFB = BASOP_Util_Add_Mant32Exp( conceal_eof_gainFB, conceal_eof_gainFB_e, L_negate( stepFB ), stepFB_e, &conceal_eof_gainFB_e ); // Q: 31 - conceal_eof_gainFB_e } } FOR( i = 0; i < st_fx->L_frame; i++ ) { - xn_buf[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( hTcxDec->conceal_eof_gain32, xn_buf[i] ), hTcxDec->conceal_eof_gain_e ) ); + xn_buf[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( hTcxDec->conceal_eof_gain32, xn_buf[i] ), hTcxDec->conceal_eof_gain_e ) ); // Qx move16(); hTcxDec->conceal_eof_gain32 = BASOP_Util_Add_Mant32Exp( hTcxDec->conceal_eof_gain32, hTcxDec->conceal_eof_gain_e, L_negate( step ), step_e, &hTcxDec->conceal_eof_gain_e ); move32(); @@ -1956,16 +1956,16 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, st_fx->bfi_pitch_frame = st_fx->L_frame; move16(); - st_fx->mem_pitch_gain[add( shl( st_fx->nb_subfr, 1 ), 1 )] = st_fx->mem_pitch_gain[st_fx->nb_subfr + 1]; + st_fx->mem_pitch_gain[st_fx->nb_subfr * 2 + 1] = st_fx->mem_pitch_gain[st_fx->nb_subfr + 1]; // Q14 move16(); - st_fx->mem_pitch_gain[shl( st_fx->nb_subfr, 1 )] = st_fx->mem_pitch_gain[st_fx->nb_subfr]; + st_fx->mem_pitch_gain[st_fx->nb_subfr * 2] = st_fx->mem_pitch_gain[st_fx->nb_subfr]; // Q14 move16(); FOR( i = 0; i < st_fx->nb_subfr; i++ ) { - st_fx->mem_pitch_gain[sub( sub( shl( st_fx->nb_subfr, 1 ), 1 ), i )] = st_fx->mem_pitch_gain[sub( sub( st_fx->nb_subfr, 1 ), i )]; + st_fx->mem_pitch_gain[( st_fx->nb_subfr * 2 - 1 ) - i] = st_fx->mem_pitch_gain[st_fx->nb_subfr - 1 - i]; // Q14 move16(); - st_fx->mem_pitch_gain[sub( sub( st_fx->nb_subfr, 1 ), i )] = shr( hTcxDec->tcxltp_last_gain_unmodified, 1 ); /* Q14 */ + st_fx->mem_pitch_gain[st_fx->nb_subfr - 1 - i] = shr( hTcxDec->tcxltp_last_gain_unmodified, 1 ); /* Q14 */ move16(); } } @@ -2049,7 +2049,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T /* number of zero for ALDO windows*/ tmp32 = L_add( st->sr_core, 0 ); - if ( fullbandScale != 0 ) + IF( fullbandScale != 0 ) { tmp32 = L_add( st->output_Fs, 0 ); } @@ -2057,7 +2057,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T tmp_offset = 0; move16(); - if ( tcx_offset < 0 ) + IF( tcx_offset < 0 ) { tmp_offset = negate( tcx_offset ); } @@ -2258,9 +2258,9 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T L_win ); /* extra folding-out on left side of win, for perfect reconstruction */ - FOR( w = shr( overlap, 1 ); w < overlap; w++ ) + FOR( w = ( overlap / 2 ); w < overlap; w++ ) { - xn_buf[sub( sub( overlap, 1 ), w )] = negate( xn_buf[w] ); + xn_buf[( ( overlap - 1 ) - w )] = negate( xn_buf[w] ); move16(); } @@ -2745,8 +2745,8 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T FOR( ; i < tcx_mdct_window_half_length; i++ ) { #ifdef BASOP_NOGLOB - xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.re ); - xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_OverlFB[i], mult_r_sat( tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.im, tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.im ) ) ); + xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[( ( tcx_mdct_window_half_length - 1 ) - i )].v.re ); + xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_OverlFB[i], mult_r_sat( tcx_mdct_window_half[( ( tcx_mdct_window_half_length - 1 ) - i )].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); #else xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); xn_buf[i + tmp1] = add( xn_buf[i + tmp1], mult_r( hTcxDec->syn_OverlFB[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); @@ -2774,8 +2774,8 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T FOR( ; i < tcx_mdct_window_half_length; i++ ) { #ifdef BASOP_NOGLOB - xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.re ); - xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_Overl[i], mult_r_sat( tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.im, tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.im ) ) ); + xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); + xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_Overl[i], mult_r_sat( tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); #else xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); xn_buf[i + tmp1] = add( xn_buf[i + tmp1], mult_r( hTcxDec->syn_Overl[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); @@ -2836,7 +2836,7 @@ void IMDCT_ivas_fx( exp = 0; move16(); nz = BASOP_Util_Divide3216_Scale( c, L_frameTCX, &exp ); - exp = exp + ( 31 - 15 ); + exp = add( exp, ( 31 - 15 ) ); nz = shr( nz, sub( 15, exp ) ); // Q0 test(); @@ -2852,7 +2852,7 @@ void IMDCT_ivas_fx( fac = Mpy_32_16_1( hTcxDec->conceal_eof_gain32, st->last_concealed_gain_syn_deemph ); // q = 31 - hTcxDec->conceal_eof_gain_e FOR( Word16 ind = 0; ind < overlap; ind++ ) { - old_syn_overl_fx[ind] = extract_l( L_shl_sat( Mpy_32_32( old_syn_overl_fx[ind], fac ), hTcxDec->conceal_eof_gain_e ) ); + old_syn_overl_fx[ind] = extract_l( L_shl_sat( Mpy_32_32( old_syn_overl_fx[ind], fac ), hTcxDec->conceal_eof_gain_e ) ); // Q(-2) move16(); } } @@ -2998,17 +2998,17 @@ void IMDCT_ivas_fx( /* extra folding-out on left side of win, for perfect reconstruction */ IF( GE_16( kernel_type, MDCT_II ) ) { - FOR( w = shr( overlap, 1 ); w < overlap; w++ ) + FOR( w = overlap / 2; w < overlap; w++ ) { - xn_buf_fx[sub( sub( overlap, 1 ), w )] = xn_buf_fx[w]; + xn_buf_fx[overlap - 1 - w] = xn_buf_fx[w]; move16(); } } ELSE { - FOR( w = shr( overlap, 1 ); w < overlap; w++ ) + FOR( w = overlap / 2; w < overlap; w++ ) { - xn_buf_fx[sub( sub( overlap, 1 ), w )] = negate( xn_buf_fx[w] ); + xn_buf_fx[overlap - 1 - w] = negate( xn_buf_fx[w] ); move16(); } } @@ -3068,7 +3068,7 @@ void IMDCT_ivas_fx( FOR( Word16 ind = 0; ind < L_frame; ind++ ) { - tmp_fx_32[ind] = L_shl( Mpy_32_16_1( xn_buf_fx_32[shr( overlap, 1 ) + nz + ind], res_m ), res_e ); + tmp_fx_32[ind] = L_shl( Mpy_32_16_1( xn_buf_fx_32[( overlap / 2 ) + nz + ind], res_m ), res_e ); move32(); } q_tmp_fx_32 = q_xn_buf_fx_32; @@ -3103,7 +3103,7 @@ void IMDCT_ivas_fx( FOR( Word16 ind = 0; ind < L_frame; ind++ ) { - tmp_fx_32[ind] = Mpy_32_16_1( xn_buf_fx_32[shr( overlap, 1 ) + nz + ind], res_m ); + tmp_fx_32[ind] = Mpy_32_16_1( xn_buf_fx_32[( overlap / 2 ) + nz + ind], res_m ); move32(); } q_tmp_fx_32 = sub( q_xn_buf_fx_32, res_e ); @@ -3111,7 +3111,7 @@ void IMDCT_ivas_fx( FOR( Word16 ind = 0; ind < L_frame; ind++ ) { - xn_buf_fx[add( add( ind, shr( overlap, 1 ) ), nz )] = (Word16) L_shr( xn_buf_fx_32[add( add( ind, shr( overlap, 1 ) ), nz )], sub( q_xn_buf_fx_32, q_win ) ); + xn_buf_fx[( ind + ( overlap / 2 ) ) + nz] = (Word16) L_shr( xn_buf_fx_32[( ind + ( overlap / 2 ) ) + nz], sub( q_xn_buf_fx_32, q_win ) ); move16(); } @@ -3135,13 +3135,13 @@ void IMDCT_ivas_fx( IF( tcx_offset < 0 ) { - acelp_mem_len = -tcx_offset; + acelp_mem_len = negate( tcx_offset ); } ELSE { acelp_mem_len = 0; + move16(); } - move16(); IF( EQ_16( kernel_type, MDST_IV ) ) { @@ -3183,7 +3183,7 @@ void IMDCT_ivas_fx( lev_dur_fx( &st->old_Aq_12_8_fx_32[0], &r_fx[0], M, NULL, 28 /*Q(st->q_old_Aq_12_8_fx_32)*/, add( add( shl( q_buf, 1 ), q_r ), 1 ) ); FOR( Word16 ind = 0; ind <= M; ind++ ) { - st->old_Aq_12_8_fx[ind] = (Word16) L_shr( st->old_Aq_12_8_fx_32[ind], 16 ); + st->old_Aq_12_8_fx[ind] = (Word16) L_shr( st->old_Aq_12_8_fx_32[ind], 16 ); // Q28 -> Q12 move16(); } } @@ -3215,9 +3215,9 @@ void IMDCT_ivas_fx( FOR( i = 0; i < sub( overlap, tcx_mdct_window_min_length ); i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )] = add_sat( xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )], old_out_fx[add( i, nz )] ); + xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )], old_out_fx[( i + nz )] ); // Q(-2) #else - xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )] = add( xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )], old_out_fx[add( i, nz )] ); + xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add( xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )], old_out_fx[( i + nz )] ); #endif move16(); } @@ -3232,49 +3232,49 @@ void IMDCT_ivas_fx( FOR( ; i < overlap; i++ ) /* perfectly reconstructing ALDO shortening */ { #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], old_out_fx[add( i, nz )] ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], old_out_fx[( i + nz )] ); // Q(-2) #else - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], old_out_fx[add( i, nz )] ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], old_out_fx[( i + nz )] ); // Q(-2) #endif move16(); } - FOR( i = 0; i < shr( tcx_mdct_window_min_length, 1 ); i++ ) + FOR( i = 0; i < ( tcx_mdct_window_min_length / 2 ); i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )] = add_sat( xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )], mult_r( old_out_fx[add( add( i, nz ), overlap )], tcx_mdct_window_minimum_fx[i].v.re ) ); + xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[i].v.re ) ); // Q(-2) #else - xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )] = add( xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )], mult_r( old_out_fx[add( add( i, nz ), overlap )], tcx_mdct_window_minimum_fx[i].v.re ) ); + xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[i].v.re ) ); #endif move16(); } FOR( ; i < tcx_mdct_window_min_length; i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )] = add_sat( xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )], mult_r( old_out_fx[add( add( i, nz ), overlap )], tcx_mdct_window_minimum_fx[sub( tcx_mdct_window_min_length, add( 1, i ) )].v.im ) ); + xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[( tcx_mdct_window_min_length - ( 1 + i ) )].v.im ) ); // Q(-2) #else - xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )] = add( xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )], mult_r( old_out_fx[add( add( i, nz ), overlap )], tcx_mdct_window_minimum_fx[sub( tcx_mdct_window_min_length, add( 1, i ) )].v.im ) ); + xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[( tcx_mdct_window_min_length - ( 1 + i ) )].v.im ) ); #endif move16(); } } ELSE { - FOR( ; i < sub( overlap, shr( tcx_mdct_window_min_length, 1 ) ); i++ ) + FOR( ; i < ( overlap - ( tcx_mdct_window_min_length / 2 ) ); i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_out_fx[add( i, nz )], tcx_mdct_window_minimum_fx[add( sub( tcx_mdct_window_min_length, overlap ), i )].v.re ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( ( tcx_mdct_window_min_length - overlap ) + i )].v.re ) ); // Q(-2) #else - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_out_fx[add( i, nz )], tcx_mdct_window_minimum_fx[add( sub( tcx_mdct_window_min_length, overlap ), i )].v.re ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( ( tcx_mdct_window_min_length - overlap ) + i )].v.re ) ); #endif move16(); } FOR( ; i < overlap; i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_out_fx[add( i, nz )], tcx_mdct_window_minimum_fx[sub( overlap, add( 1, i ) )].v.im ) ); + xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( overlap - ( 1 + i ) )].v.im ) ); // Q(-2) #else - xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_out_fx[add( i, nz )], tcx_mdct_window_minimum_fx[sub( overlap, add( 1, i ) )].v.im ) ); + xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( overlap - ( 1 + i ) )].v.im ) ); #endif move16(); } @@ -3286,12 +3286,12 @@ void IMDCT_ivas_fx( IF( bfi != 0 ) { - FOR( i = 0; i < shr( tcx_mdct_window_half_length, 1 ); i++ ) + FOR( i = 0; i < ( tcx_mdct_window_half_length / 2 ); i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[i].v.re ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[i].v.re ) ); // Q(-2) #else - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[i].v.re ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[i].v.re ) ); #endif move16(); @@ -3299,9 +3299,9 @@ void IMDCT_ivas_fx( FOR( ; i < tcx_mdct_window_half_length; i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ) ); // Q(-2) #else - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ) ); #endif move16(); } @@ -3310,7 +3310,7 @@ void IMDCT_ivas_fx( { FOR( i = 0; i < overlap; i++ ) { - xn_buf_fx[i] = add_sat( xn_buf_fx[i], old_syn_overl_fx[i] ); + xn_buf_fx[i] = add_sat( xn_buf_fx[i], old_syn_overl_fx[i] ); // Q(-2) move16(); } } @@ -3319,9 +3319,9 @@ void IMDCT_ivas_fx( FOR( i = 0; i < overlap; i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[add( i, shr( overlap, 1 ) )] = add_sat( xn_buf_fx[add( i, shr( overlap, 1 ) )], old_syn_overl_fx[i] ); + xn_buf_fx[( i + ( overlap / 2 ) )] = add_sat( xn_buf_fx[( i + ( overlap / 2 ) )], old_syn_overl_fx[i] ); // Q(-2) #else - xn_buf_fx[add( i, shr( overlap, 1 ) )] = add( xn_buf_fx[add( i, shr( overlap, 1 ) )], old_syn_overl_fx[i] ); + xn_buf_fx[( i + ( overlap / 2 ) )] = add( xn_buf_fx[( i + ( overlap / 2 ) )], old_syn_overl_fx[i] ); #endif move16(); } @@ -3347,7 +3347,7 @@ void IMDCT_ivas_fx( { FOR( i = 0; i < nz; i++ ) { - old_out_fx[add( add( nz, overlap ), i )] = negate( mult_r( xn_buf_fx[sub( L_frame, add( 1, i ) )], tcx_aldo_window_1_fx[sub( nz, add( 1, i ) )] ) ); + old_out_fx[( ( nz + overlap ) + i )] = negate( mult_r( xn_buf_fx[( L_frame - ( 1 + i ) )], tcx_aldo_window_1_fx[( nz - ( 1 + i ) )] ) ); // Q(-2) move16(); } } @@ -3355,7 +3355,7 @@ void IMDCT_ivas_fx( { FOR( i = 0; i < nz; i++ ) { - old_out_fx[add( add( nz, overlap ), i )] = mult_r( xn_buf_fx[sub( L_frame, add( 1, i ) )], tcx_aldo_window_1_fx[sub( nz, add( 1, i ) )] ); + old_out_fx[( ( nz + overlap ) + i )] = mult_r( xn_buf_fx[( L_frame - ( 1 + i ) )], tcx_aldo_window_1_fx[( nz - ( 1 + i ) )] ); // Q(-2) move16(); } } @@ -3378,41 +3378,41 @@ void IMDCT_ivas_fx( { IF( FB_flag != 0 ) { - FOR( i = 0; i < shr( tcx_mdct_window_half_length, 1 ); i++ ) + FOR( i = 0; i < ( tcx_mdct_window_half_length / 2 ); i++ ) { - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[i].v.im ); - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[i].v.re ), tcx_mdct_window_half_fx[i].v.re ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = mult_r( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tcx_mdct_window_half_fx[i].v.im ); // Q(-2) + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[i].v.re ), tcx_mdct_window_half_fx[i].v.re ) ); // Q(-2) move16(); move16(); } FOR( ; i < tcx_mdct_window_half_length; i++ ) { - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.re ); - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ), tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = mult_r( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.re ); // Q(-2) + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ), tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ) ); // Q(-2) move16(); move16(); } } ELSE { - FOR( i = 0; i < shr( tcx_mdct_window_half_length, 1 ); i++ ) + FOR( i = 0; i < ( tcx_mdct_window_half_length / 2 ); i++ ) { - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[i].v.im ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = mult_r( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tcx_mdct_window_half_fx[i].v.im ); #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[i].v.re ), tcx_mdct_window_half_fx[i].v.re ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[i].v.re ), tcx_mdct_window_half_fx[i].v.re ) ); // Q(-2) #else - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[i].v.re ), tcx_mdct_window_half_fx[i].v.re ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[i].v.re ), tcx_mdct_window_half_fx[i].v.re ) ); #endif move16(); move16(); } FOR( ; i < tcx_mdct_window_half_length; i++ ) { - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.re ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = mult_r( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.re ); #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ), tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ), tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ) ); // Q(-2) #else - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ), tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ), tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ) ); #endif move16(); move16(); @@ -3536,7 +3536,16 @@ void init_tcx_info_fx( } ELSE { - IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, ( st->last_core == ACELP_CORE || ( *left_rect && st->bfi ) ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM ); + test(); + test(); + IF( st->last_core == ACELP_CORE || ( *left_rect && st->bfi ) ) + { + IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, IGF_GRID_LB_TRAN ); + } + ELSE + { + IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, IGF_GRID_LB_NORM ); + } } } } @@ -3593,6 +3602,7 @@ void decoder_tcx_IGF_mono_fx( test(); IF( NE_16( L_frame, shr( st->L_frame, 1 ) ) && st->tcxonly ) { + test(); test(); IF( EQ_16( st->last_core, ACELP_CORE ) || ( left_rect && bfi ) ) { @@ -3664,7 +3674,7 @@ void decoder_tcx_IGF_stereo_fx( FOR( sfb = 0; sfb < sfbConf->sfbCnt; sfb++ ) { - set16_fx( &coreMsMask[sfbConf->sfbOffset[sfb]], ms_mask[k][sfb], sfbConf->sfbOffset[sfb + 1] - sfbConf->sfbOffset[sfb] ); + set16_fx( &coreMsMask[sfbConf->sfbOffset[sfb]], ms_mask[k][sfb], sub( sfbConf->sfbOffset[sfb + 1], sfbConf->sfbOffset[sfb] ) ); } test(); @@ -3756,10 +3766,10 @@ void decoder_tcx_IGF_stereo_fx( void decoder_tcx_ivas_fx( Decoder_State *st, Word16 prm[], - Word16 A_fx[], - Word16 Aind[], - Word16 synth_fx[], - Word16 synthFB_fx[], + Word16 A_fx[], // Q: 14 - norm_s(A_fx[0]) + Word16 Aind[], // Q: 14 - norm_s(Aind[0]) + Word16 synth_fx[], // Q_syn + Word16 synthFB_fx[], // Q_syn const Word16 bfi, const Word16 frame_cnt, const Word16 sba_dirac_stereo_flag ) @@ -3842,8 +3852,12 @@ void decoder_tcx_ivas_fx( } /* Scaling down buffers for decoder_tcx_imdct_fx*/ - Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, 1 ); // Scaling to Q_syn - Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, 1 ); // Scaling to Q_syn + Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_Overl_TDACFB ) ); // Scaling to Q_syn + st->hTcxDec->Q_syn_Overl_TDACFB = st->Q_syn; + move16(); + Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_Overl_TDAC ) ); // Scaling to Q_syn + st->hTcxDec->Q_syn_Overl_TDAC = st->Q_syn; + move16(); Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, negate( st->hHQ_core->Q_old_wtda ) ); // Scaling to Q_syn Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, negate( st->hHQ_core->Q_old_wtda_LB ) ); // Scaling to Q_syn st->hHQ_core->Q_old_wtda = 0; @@ -4034,9 +4048,16 @@ void decoder_tcx_invQ_fx( prm_sqQ = prm_target + 1; move16(); - tcx_arith_decode_envelope_ivas_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, ( st->bwidth > WB ) ? 1 : 0 ); + IF( GT_32( st->bwidth, WB ) ) + { + tcx_arith_decode_envelope_ivas_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 1 ); + } + ELSE + { + tcx_arith_decode_envelope_ivas_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 0 ); + } - hTcxDec->resQBits[frame_cnt] = *prm_target - arith_bits; + hTcxDec->resQBits[frame_cnt] = sub( *prm_target, arith_bits ); move16(); /* Noise filling seed */ @@ -4094,7 +4115,7 @@ void decoder_tcx_invQ_fx( move16(); } - FOR( i = start_zeroing; i < max( L_frame, L_frameTCX ); i++ ) + FOR( i = start_zeroing; i < s_max( L_frame, L_frameTCX ); i++ ) { x[i] = 0; move32(); @@ -4167,7 +4188,7 @@ void decoder_tcx_invQ_fx( hTcxDec->old_gaintcx_bfi_e = *gain_tcx_e; move16(); - hTcxDec->cummulative_damping_tcx = MAX16B; + hTcxDec->cummulative_damping_tcx = MAX16B; // 1 in Q15 move16(); } ELSE /* bfi = 1 */ @@ -4207,7 +4228,7 @@ void decoder_tcx_invQ_fx( move16(); } - hTcxDec->damping = ONE_IN_Q14; + hTcxDec->damping = ONE_IN_Q14; // Q14 move16(); } ELSE @@ -4253,7 +4274,7 @@ void decoder_tcx_invQ_fx( gamma = add( mult_r( hTcxDec->cummulative_damping_tcx, sub( gamma1, MAX16B ) ), MAX16B ); } - IF( st->element_mode != IVAS_CPE_MDCT ) + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { weight_a_fx( A, Ap, gamma, M ); lpc2mdct_2( Ap, M, NULL, NULL, gainlpc2, gainlpc2_e, FDNS_NPTS ); @@ -4291,7 +4312,7 @@ void decoder_tcx_invQ_fx( move16(); tmp32 = Sqrt32( tmp32, &st->last_gain_syn_deemph_e ); #ifdef BASOP_NOGLOB - st->last_gain_syn_deemph = round_fx_o( tmp32, &Overflow ); + st->last_gain_syn_deemph = round_fx_o( tmp32, &Overflow ); // Q15 #else last_gain_syn_deemph_fx = round_fx( tmp32 ); #endif @@ -4685,7 +4706,7 @@ void decoder_tcx_noisefilling_fx( } /* get the starting location of the subframe in the frame */ - if ( EQ_16( st->core, TCX_10_CORE ) ) + IF( EQ_16( st->core, TCX_10_CORE ) ) { st->hPlcInfo->subframe = extract_l( L_mult0( frame_cnt, L_frameTCX_glob ) ); move16(); @@ -4900,7 +4921,7 @@ void decoder_tcx_noisefilling_fx( } } - if ( st->igf ) + IF( st->igf ) { *st->hIGFDec->igfData.igfInfo.nfSeed = extract_l( L_add( L_mult0( nf_seed, 31821 ), 13849 ) ); move16(); diff --git a/lib_dec/dec_tran_fx.c b/lib_dec/dec_tran_fx.c index f92ef8904f274e14e1bc40b323df516c32c8f5cc..a9ea119ba5e99585ba43805b0a23cd2b10c1509c 100644 --- a/lib_dec/dec_tran_fx.c +++ b/lib_dec/dec_tran_fx.c @@ -82,24 +82,22 @@ void decod_tran_fx( gain_code_fx = 0; /* Quantized algebraic codeebook gain */ move32(); - norm_gain_code_fx = 0; /* normalized algebraic codeebook gain */ + norm_gain_code_fx = 0; /* normalized algebraic codeebook gain Q16 */ move32(); - gain_pit_fx = 0; /* Quantized pitch gain */ + gain_pit_fx = 0; /* Quantized pitch gain Q14 */ move16(); gain_inov_fx = 0; /* inovation gain */ move16(); - gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + gain_preQ_fx = 0; /* Gain of prequantizer excitation Q2 */ move16(); - gain_preQ_fx = 0; - move16(); - set16_fx( code_preQ_fx, 0, L_SUBFR ); + set16_fx( code_preQ_fx, 0, L_SUBFR ); // Q10 /*----------------------------------------------------------------* * ACELP subframe loop *----------------------------------------------------------------*/ - p_Aq_fx = Aq_fx; - pt_pitch_fx = pitch_buf_fx; + p_Aq_fx = Aq_fx; // Q12 + pt_pitch_fx = pitch_buf_fx; // Q6 Jopt_flag = 0; move16(); norm_gain_preQ_fx = 0; @@ -116,9 +114,9 @@ void decod_tran_fx( IF( i_subfr == 0 && GT_16( st_fx->Q_exc, 2 ) ) { tmp16 = sub( 2, st_fx->Q_exc ); - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, tmp16 ); - Scale_sig( bwe_exc_fx - PIT16k_MAX * 2, PIT16k_MAX * 2, tmp16 ); - Scale_sig( hGSCDec->last_exc_dct_in_fx, L_FRAME, tmp16 ); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, tmp16 ); // Q2 + Scale_sig( bwe_exc_fx - PIT16k_MAX * 2, PIT16k_MAX * 2, tmp16 ); // Q2 + Scale_sig( hGSCDec->last_exc_dct_in_fx, L_FRAME, tmp16 ); // Q2 st_fx->Q_exc = add( st_fx->Q_exc, tmp16 ); move16(); } @@ -213,7 +211,7 @@ void decod_tran_fx( #endif IF( EQ_16( L_frame_fx, L_FRAME ) ) /* Rescaling for 12.8k core */ { - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[shr( imult1616( i_subfr, 2 * HIBND_ACB_L_FAC ), 1 )], hGSCDec->last_exc_dct_in_fx, + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[( ( i_subfr * 2 * HIBND_ACB_L_FAC ) >> 1 )], hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr, st_fx->coder_type ); } ELSE /* Rescaling for 16k core */ @@ -230,7 +228,7 @@ void decod_tran_fx( *-----------------------------------------------------------------*/ IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) { - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( ( st_fx->element_mode == EVS_MONO ) ) { tmp1_fx = add( 15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc ); } @@ -296,9 +294,9 @@ void decod_tran_fx( } p_Aq_fx += ( M + 1 ); pt_pitch_fx++; - st_fx->tilt_code_dec_fx[tmp_idx] = st_fx->tilt_code_fx; + st_fx->tilt_code_dec_fx[tmp_idx] = st_fx->tilt_code_fx; // Q15 move16(); - gain_buf[tmp_idx] = gain_pit_fx; + gain_buf[tmp_idx] = gain_pit_fx; // Q14 move16(); } diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index 7edc512f7951e022f9521473172d20080b03c141..bdddeb791de3b356dfa439a3dc66f51c52439520 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -84,14 +84,14 @@ void decod_unvoiced_fx( Word16 tmp_idx = 0; move16(); - if ( i_subfr_fx != 0 ) + IF( i_subfr_fx != 0 ) { tmp_idx = idiv1616( i_subfr_fx, L_SUBFR ); } voice_factors_fx[tmp_idx] = 0; move16(); - interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )], L_SUBFR ); + interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[( ( i_subfr_fx * 2 * HIBND_ACB_L_FAC ) >> 1 )], L_SUBFR ); p_Aq_fx += ( M + 1 ); pt_pitch_fx++; @@ -217,7 +217,7 @@ void decod_unvoiced_ivas_fx( IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - Rescale_exc( st_fx->hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )] : NULL, st_fx->hGSCDec->last_exc_dct_in_fx, + Rescale_exc( st_fx->hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[( ( i_subfr_fx * 2 * HIBND_ACB_L_FAC ) >> 1 )] : NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, L_max( gain_code2_fx, gain_code_fx ), &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, UNVOICED ); } ELSE @@ -262,7 +262,7 @@ void decod_unvoiced_ivas_fx( } voice_factors_fx[tmp_idx] = 0; move16(); - interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )], L_SUBFR ); + interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[( ( i_subfr_fx * 2 * HIBND_ACB_L_FAC ) >> 1 )], L_SUBFR ); p_Aq_fx += ( M + 1 ); pt_pitch_fx++; diff --git a/lib_dec/decision_matrix_dec_fx.c b/lib_dec/decision_matrix_dec_fx.c index 66c7440b1b6c38e01d813477f2cde203a0cc3da6..5d9beccff03019cb28f7506aad73341eb1101e43 100644 --- a/lib_dec/decision_matrix_dec_fx.c +++ b/lib_dec/decision_matrix_dec_fx.c @@ -20,9 +20,9 @@ #ifdef IVAS_FLOAT_FIXED void decision_matrix_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ - Word16 *sharpFlag, /* o : formant sharpening flag */ - Word16 *hq_core_type, /* o : HQ core type */ - Word16 *core_switching_flag /* o : ACELP->HQ switching frame flag */ + Word16 *sharpFlag, /* o : formant sharpening flag Q0 */ + Word16 *hq_core_type, /* o : HQ core type Q0 */ + Word16 *core_switching_flag /* o : ACELP->HQ switching frame flag Q0 */ ) { Word16 start_idx; @@ -60,24 +60,24 @@ void decision_matrix_dec_fx( ELSE { test(); - IF( EQ_32( st->total_brate, FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) + IF( ( st->total_brate == FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) { st->core = ACELP_CORE; move16(); st->core_brate = st->total_brate; move32(); - IF( NE_32( st->total_brate, FRAME_NO_DATA ) ) + IF( st->total_brate != FRAME_NO_DATA ) { - st->cng_type = get_next_indice_fx( st, 1 ); + st->cng_type = get_next_indice_fx( st, 1 ); // Q0 - IF( EQ_16( st->cng_type, LP_CNG ) ) + IF( st->cng_type == LP_CNG ) { st->L_frame = L_FRAME; move16(); - tmp16 = get_next_indice_fx( st, 1 ); - IF( EQ_16( tmp16, 1 ) ) + tmp16 = get_next_indice_fx( st, 1 ); // Q0 + if ( EQ_16( tmp16, 1 ) ) { st->L_frame = L_FRAME16k; move16(); @@ -85,14 +85,14 @@ void decision_matrix_dec_fx( } ELSE { - st->bwidth = get_next_indice_fx( st, 2 ); + st->bwidth = get_next_indice_fx( st, 2 ); // Q0 - tmp16 = get_next_indice_fx( st, 1 ); + tmp16 = get_next_indice_fx( st, 1 ); // Q0 move16(); st->L_frame = L_FRAME16k; move16(); - IF( tmp16 == 0 ) + if ( tmp16 == 0 ) { st->L_frame = L_FRAME; move16(); @@ -101,7 +101,7 @@ void decision_matrix_dec_fx( } test(); - IF( GE_32( st->output_Fs, 32000 ) && GE_16( st->bwidth, SWB ) ) + if ( GE_32( st->output_Fs, 32000 ) && GE_16( st->bwidth, SWB ) ) { st->extl = SWB_CNG; move16(); @@ -110,7 +110,7 @@ void decision_matrix_dec_fx( test(); test(); test(); - IF( EQ_32( st->total_brate, FRAME_NO_DATA ) && st->prev_bfi && !st->bfi && GT_16( st->L_frame, L_FRAME16k ) ) + if ( ( st->total_brate == FRAME_NO_DATA ) && st->prev_bfi && !st->bfi && GT_16( st->L_frame, L_FRAME16k ) ) { st->L_frame = st->last_CNG_L_frame; move16(); @@ -128,23 +128,27 @@ void decision_matrix_dec_fx( move32(); st->L_frame = L_FRAME; move16(); - st->fscale = sr2fscale_fx( INT_FS_FX ); + st->fscale = sr2fscale_fx( INT_FS_FX ); // Q0 move16(); IF( st->ini_frame == 0 ) { /* avoid switching of internal ACELP Fs in the very first frame */ st->last_L_frame = st->L_frame; + move16(); st->last_core = st->core; + move16(); st->last_core_brate = st->core_brate; + move32(); st->last_extl = st->extl; + move16(); } st->vbr_hw_BWE_disable_dec = 1; move16(); - get_next_indice_fx( st, 1 ); + get_next_indice_fx( st, 1 ); // Q0 - ppp_nelp_mode = get_next_indice_fx( st, 2 ); + ppp_nelp_mode = get_next_indice_fx( st, 2 ); // Q0 /* 0 - PPP_NB, 1 - PPP_WB, 2 - NELP_NB, 3 - NELP_WB */ IF( ppp_nelp_mode == 0 ) @@ -201,11 +205,11 @@ void decision_matrix_dec_fx( ELSE IF( GE_32( st->total_brate, ACELP_24k40 ) && LE_32( st->total_brate, ACELP_64k ) ) { /* read the ACELP/HQ core selection bit */ - temp_core = get_next_indice_fx( st, 1 ); + temp_core = get_next_indice_fx( st, 1 ); // Q0 st->core = HQ_CORE; move16(); - IF( temp_core == 0 ) + if ( temp_core == 0 ) { st->core = ACELP_CORE; move16(); @@ -217,7 +221,7 @@ void decision_matrix_dec_fx( * Read ACELP signaling bits from the bitstream *-----------------------------------------------------------------*/ - IF( EQ_16( st->core, ACELP_CORE ) ) + IF( st->core == ACELP_CORE ) { /* find the section in the ACELP signaling table corresponding to bitrate */ start_idx = 0; @@ -231,7 +235,7 @@ void decision_matrix_dec_fx( move16(); start_idx = 0; move16(); - break; + BREAK; } } @@ -242,7 +246,7 @@ void decision_matrix_dec_fx( nBits = extract_l( acelp_sig_tbl[start_idx] ); start_idx = add( start_idx, 1 ); - start_idx = add( start_idx, get_next_indice_fx( st, nBits ) ); + start_idx = add( start_idx, get_next_indice_fx( st, nBits ) ); // Q0 IF( GE_16( start_idx, MAX_ACELP_SIG ) ) { ind = 0; @@ -257,17 +261,19 @@ void decision_matrix_dec_fx( move32(); /* convert signaling indice into signaling information */ - st->coder_type = extract_l( L_and( ind, 0x7L ) ); + st->coder_type = extract_l( L_and( ind, 0x7L ) ); // Q0 IF( EQ_16( st->coder_type, LR_MDCT ) ) { st->core = HQ_CORE; move16(); - st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7L ) ); + st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7L ) ); // Q0 + move16(); } ELSE { - st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7L ) ); - *sharpFlag = extract_l( L_and( L_shr( ind, 6 ), 0x1L ) ); + st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7L ) ); // Q0 + move16(); + *sharpFlag = extract_l( L_and( L_shr( ind, 6 ), 0x1L ) ); // Q0 move16(); } } @@ -292,11 +298,11 @@ void decision_matrix_dec_fx( IF( ( st->BER_detect ) || ( GE_32( ind, 1 << 7 ) ) || ( LE_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, FB ) ) || - ( GE_32( st->total_brate, ACELP_32k ) && EQ_16( st->bwidth, NB ) ) || - ( GE_32( st->total_brate, ACELP_32k ) && !( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, TRANSITION ) || EQ_16( st->coder_type, INACTIVE ) ) ) || - ( LT_32( st->total_brate, ACELP_13k20 ) && NE_16( st->bwidth, NB ) && EQ_16( st->coder_type, LR_MDCT ) ) || + ( GE_32( st->total_brate, ACELP_32k ) && ( st->bwidth == NB ) ) || + ( GE_32( st->total_brate, ACELP_32k ) && !( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, TRANSITION ) || ( st->coder_type == INACTIVE ) ) ) || + ( LT_32( st->total_brate, ACELP_13k20 ) && ( st->bwidth != NB ) && EQ_16( st->coder_type, LR_MDCT ) ) || ( GE_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->coder_type, UNVOICED ) ) || - ( GE_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->coder_type, AUDIO ) && EQ_16( st->bwidth, NB ) ) ) + ( GE_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->coder_type, AUDIO ) && ( st->bwidth == NB ) ) ) { st->BER_detect = 0; move16(); @@ -413,7 +419,7 @@ void decision_matrix_dec_fx( test(); IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->bwidth, WB ) && LT_32( st->total_brate, ACELP_9k60 ) ) { - IF( st->vbr_hw_BWE_disable_dec == 0 ) + if ( st->vbr_hw_BWE_disable_dec == 0 ) { st->extl = WB_BWE; move16(); @@ -422,7 +428,7 @@ void decision_matrix_dec_fx( ELSE IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->bwidth, WB ) && GE_32( st->total_brate, ACELP_9k60 ) && LE_32( st->total_brate, ACELP_16k40 ) ) { /* read the WB TBE/BWE selection bit */ - tmp16 = get_next_indice_fx( st, 1 ); + tmp16 = get_next_indice_fx( st, 1 ); // Q0 IF( EQ_16( tmp16, 1 ) ) { st->extl = WB_BWE; @@ -444,7 +450,7 @@ void decision_matrix_dec_fx( { st->extl = SWB_BWE_HIGHRATE; move16(); - IF( EQ_16( st->bwidth, FB ) ) + if ( EQ_16( st->bwidth, FB ) ) { st->extl = FB_BWE_HIGHRATE; move16(); @@ -471,7 +477,7 @@ void decision_matrix_dec_fx( move16(); st->extl_brate = SWB_TBE_1k6; move32(); - IF( GE_32( st->total_brate, ACELP_24k40 ) ) + if ( GE_32( st->total_brate, ACELP_24k40 ) ) { st->extl_brate = SWB_TBE_2k8; move32(); @@ -504,6 +510,7 @@ void decision_matrix_dec_fx( /* set core bitrate */ st->core_brate = L_sub( st->total_brate, st->extl_brate ); + move32(); /*-----------------------------------------------------------------* * Read HQ signaling bits from the bitstream @@ -516,11 +523,11 @@ void decision_matrix_dec_fx( IF( NE_16( st->mdct_sw, MODE2 ) ) { /* skip the HQ/TCX core switching flag */ - get_next_indice_tmp_fx( st, 1 ); + get_next_indice_tmp_fx( st, 1 ); // Q0 } /* read ACELP->HQ core switching flag */ - *core_switching_flag = get_next_indice_fx( st, 1 ); + *core_switching_flag = get_next_indice_fx( st, 1 ); // Q0 IF( EQ_16( *core_switching_flag, 1 ) ) { @@ -530,8 +537,8 @@ void decision_matrix_dec_fx( /* read ACELP L_frame info */ st->last_L_frame = L_FRAME16k; move16(); - tmp16 = get_next_indice_fx( st, 1 ); - IF( tmp16 == 0 ) + tmp16 = get_next_indice_fx( st, 1 ); // Q0 + if ( tmp16 == 0 ) { st->last_L_frame = L_FRAME; move16(); @@ -544,7 +551,7 @@ void decision_matrix_dec_fx( /* read/set band-width (needed for different I/O sampling rate support) */ IF( GT_32( st->total_brate, ACELP_16k40 ) ) { - tmp16 = get_next_indice_fx( st, 2 ); + tmp16 = get_next_indice_fx( st, 2 ); // Q0 IF( tmp16 == 0 ) { @@ -574,7 +581,7 @@ void decision_matrix_dec_fx( test(); test(); test(); - IF( ( GE_32( st->total_brate, ACELP_24k40 ) && EQ_16( st->bwidth, NB ) ) || + IF( ( GE_32( st->total_brate, ACELP_24k40 ) && ( st->bwidth == NB ) ) || ( EQ_16( st->core, HQ_CORE ) && LE_32( st->total_brate, LRMDCT_CROSSOVER_POINT ) && EQ_16( st->bwidth, FB ) ) ) { st->bfi = 1; @@ -644,7 +651,7 @@ void decision_matrix_dec_fx( test(); test(); test(); - IF( EQ_32( st->core_brate, FRAME_NO_DATA ) ) + IF( st->core_brate == FRAME_NO_DATA ) { /* prevent "L_frame" changes in CNG segments */ st->L_frame = st->last_L_frame; @@ -670,14 +677,16 @@ void decision_matrix_dec_fx( st->nb_subfr = NB_SUBFR; move16(); - IF( EQ_16( st->L_frame, L_FRAME16k ) ) + if ( EQ_16( st->L_frame, L_FRAME16k ) ) { st->nb_subfr = NB_SUBFR16k; move16(); } #if 1 // def ADD_IVAS_BWE 0> NEEDED for IO with conf_acelp1 st->extl_orig = st->extl; + move16(); st->extl_brate_orig = st->extl_brate; + move32(); #endif test(); IF( EQ_32( st->output_Fs, 8000 ) ) diff --git a/lib_dec/dlpc_avq_fx.c b/lib_dec/dlpc_avq_fx.c index 1f4a7117bcf566457ada2a763a1a38dde77ab563..c38d0b9a377dfe5973d66bf6798950fff80110e0 100644 --- a/lib_dec/dlpc_avq_fx.c +++ b/lib_dec/dlpc_avq_fx.c @@ -48,9 +48,9 @@ Word16 dlpc_avq_fx( move16(); LSF_Q[last + i] = 0; } - vlpc_1st_dec( p_index[0], &LSF_Q[last] ); + vlpc_1st_dec( p_index[0], &LSF_Q[last] ); // LSF_Q[last] -> Q2.56 p_index++; - vlpc_2st_dec( &LSF_Q[last], &p_index[0], 0, sr_core ); + vlpc_2st_dec( &LSF_Q[last], &p_index[0], 0, sr_core ); // Q2.56 nbi = add( 2, add( p_index[0], p_index[1] ) ); p_index += nbi; @@ -70,7 +70,7 @@ Word16 dlpc_avq_fx( move16(); LSF_Q[i] = 0; } - vlpc_1st_dec( p_index[0], &LSF_Q[0] ); + vlpc_1st_dec( p_index[0], &LSF_Q[0] ); ////Q2.56 p_index++; vlpc_2st_dec( &LSF_Q[0], &p_index[0], 0, sr_core ); } @@ -82,7 +82,7 @@ Word16 dlpc_avq_fx( move16(); LSF_Q[i] = LSF_Q[M + i]; } - vlpc_2st_dec( &LSF_Q[0], &p_index[0], 3, sr_core ); + vlpc_2st_dec( &LSF_Q[0], &p_index[0], 3, sr_core ); ////Q2.56 } nbi = add( 2, add( p_index[0], p_index[1] ) ); p_index += nbi; @@ -425,6 +425,7 @@ Word16 decode_lpc_avq_ivas_fx( test(); test(); test(); + test(); IF( NE_16( element_mode, IVAS_CPE_MDCT ) || ( !( sns_low_br_mode && ( ( stereo_mode == 0 ) || EQ_16( stereo_mode, 1 ) ) ) && !( ( q_type == 0 ) && EQ_16( param_lpc[j - 1], -2 ) ) ) ) { /* 2 bits to specify Q2,Q3,Q4,ext */ diff --git a/lib_dec/dlpc_stoch_fx.c b/lib_dec/dlpc_stoch_fx.c index e06a2d51520af76fbc898c14c9f7fa001eec41cc..6583c91de99e8f71c5efafefd99e1fa83764fdd1 100644 --- a/lib_dec/dlpc_stoch_fx.c +++ b/lib_dec/dlpc_stoch_fx.c @@ -15,14 +15,14 @@ void lpc_unquantize_fx( Decoder_State *st, - Word16 *lsf, - Word16 *lsp, + Word16 *lsf, /*x2.56*/ + Word16 *lsp, /*Q15*/ const Word16 m, - Word16 *param_lpc, - Word16 *lspmid, - Word16 *lsfmid, + Word16 *param_lpc, /*Q0*/ + Word16 *lspmid, /*Q15*/ + Word16 *lsfmid, /*x2.56*/ Word16 coder_type, - Word16 *LSF_Q_prediction /* o : LSF prediction mode */ + Word16 *LSF_Q_prediction /* o : LSF prediction mode Q0*/ ) { Word16 nb_indices, k; @@ -31,15 +31,15 @@ void lpc_unquantize_fx( nb_indices = 0; /* to avoid compilation warnings */ move16(); - Copy( st->lsf_old_fx, &lsf[0], m ); - Copy( st->lsp_old_fx, &lsp[0], m ); + Copy( st->lsf_old_fx, &lsf[0], m ); /*x2.56*/ + Copy( st->lsp_old_fx, &lsp[0], m ); /*x2.56*/ IF( st->lpcQuantization == 0 ) { - nb_indices = dlpc_avq_fx( param_lpc, &lsf[m], st->numlpc, st->sr_core ); + nb_indices = dlpc_avq_fx( param_lpc, &lsf[m], st->numlpc, st->sr_core ); /*Q0*/ FOR( k = 0; k < st->numlpc; k++ ) { - E_LPC_lsf_lsp_conversion( &lsf[imult1616( add( k, 1 ), m )], &lsp[imult1616( add( k, 1 ), m )], m ); + E_LPC_lsf_lsp_conversion( &lsf[( ( k + 1 ) * m )], &lsp[( ( k + 1 ) * m )], m ); /*Q15*/ } } ELSE IF( EQ_16( st->lpcQuantization, 1 ) ) @@ -76,7 +76,7 @@ void lpc_unquantize_fx( } } - lsf2lsp_fx( &lsf[m], &lsp[m], M, st->sr_core ); + lsf2lsp_fx( &lsf[m], &lsp[m], M, st->sr_core ); /*Q15*/ } ELSE { @@ -87,7 +87,7 @@ void lpc_unquantize_fx( move16(); FOR( i = nb_indices - 1; i >= 0; i-- ) { - st->seed_acelp = extract_l( L_mac0( L_mac0( 13849, shr( st->seed_acelp, 1 ), 31821 ), param_lpc[i], 31821 ) ); + st->seed_acelp = extract_l( L_mac0( L_mac0( 13849 /*Q0*/, shr( st->seed_acelp, 1 ), 31821 /*Q0*/ ), param_lpc[i], 31821 /*Q0*/ ) ); /*Q0*/ } /* Decoded mid-frame isf */ @@ -96,9 +96,9 @@ void lpc_unquantize_fx( test(); IF( st->lpcQuantization && st->acelp_cfg.midLpc && EQ_16( st->core, ACELP_CORE ) && st->rate_switching_reset == 0 ) { - midlsf_dec( &lsf[0], &lsf[m], param_lpc[nb_indices], lsfmid, coder_type, &( st->mid_lsf_int ), st->prev_bfi, st->safety_net ); - reorder_lsf_fx( lsfmid, LSF_GAP_MID_FX, M, st->sr_core ); - lsf2lsp_fx( lsfmid, lspmid, M, st->sr_core ); + midlsf_dec( &lsf[0], &lsf[m], param_lpc[nb_indices], lsfmid, coder_type, &( st->mid_lsf_int ), st->prev_bfi, st->safety_net ); /*3Q12*/ + reorder_lsf_fx( lsfmid, LSF_GAP_MID_FX, M, st->sr_core ); /*x2.56*/ + lsf2lsp_fx( lsfmid, lspmid, M, st->sr_core ); /*Q15*/ } diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index defb1970a186ce0d5449a89edbbfb15862f861c2..3d2fdee1cbff346020cada7cf88f2c394c118839 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -37,11 +37,11 @@ void con_acelp_fx( Word16 *pgainT, /*mem_syn >rescaling done */ - Word16 *pitch_buffer, - Word16 *voice_factors, - Word16 *bwe_exc ) + const Word16 *Qf_exc, /*mem_syn >rescaling done */ + Word16 *pitch_buffer, /* Q0 */ + Word16 *voice_factors, /* Q6 */ + Word16 *bwe_exc /* Qx */ ) { Word16 i_subfr, i, T0; /*Q0*/ @@ -115,12 +115,12 @@ void con_acelp_fx( *------------------------------------------------------------------------*/ /* set ACELP synthesis memory */ - Copy( st->mem_syn2_fx, mem_syn, M ); + Copy( st->mem_syn2_fx, mem_syn, M ); /* Q_syn */ /* set excitation memory*/ - harmonic_exc_buf = buf + M; - exc = harmonic_exc_buf + L_EXC_MEM_DEC; - Copy( st->old_exc_fx, harmonic_exc_buf, L_EXC_MEM_DEC ); + harmonic_exc_buf = buf + M; /*Qf_exc*/ + exc = harmonic_exc_buf + L_EXC_MEM_DEC; /*Qf_exc*/ + Copy( st->old_exc_fx, harmonic_exc_buf, L_EXC_MEM_DEC ); /*Q_exc*/ exc[st->L_frame] = 0; move16(); @@ -139,7 +139,7 @@ void con_acelp_fx( &st->old_fpitch, &predPitchLag, st->pit_min, st->pit_max, st->mem_pitch_gain, 0, st->plc_use_future_lag, &extrapolationFailed, st->nb_subfr ); - T0 = round_fx( predPitchLag ); + T0 = round_fx( predPitchLag ); /*Q0*/ IF( extrapolationFailed != 0 ) { @@ -160,7 +160,7 @@ void con_acelp_fx( l = shl( L_SUBFR, 1 ); FOR( i = 0; i < l; i++ ) { - exc[i] = exc[sub( i, st->guidedT0 )]; + exc[i] = exc[( i - st->guidedT0 )]; /*Qf_exc*/ move16(); } } @@ -171,11 +171,11 @@ void con_acelp_fx( move16(); } - tmp_tc = st->old_fpitch; - move32(); /* take the previous frame last pitch*/ + tmp_tc = st->old_fpitch; /*15Q16*/ + move32(); /* take the previous frame last pitch*/ if ( nSubframes > 0 ) { - tmp_tc = L_deposit_h( st->guidedT0 ); /* take the transmit pitch*/ + tmp_tc = L_deposit_h( st->guidedT0 ); /* take the transmit pitch*/ /* Q16 */ } /* PLC: [ACELP: Fade-out] @@ -201,7 +201,7 @@ void con_acelp_fx( * Last pitch cycle of the previous frame is repeatedly copied. * *---------------------------------------------------------------*/ - Tc = round_fx( tmp_tc ); + Tc = round_fx( tmp_tc ); /* Q0 */ BASOP_SATURATE_WARNING_OFF_EVS /*if this ever saturates, it doesn't matter*/ #ifdef BASOP_NOGLOB tmp = sub( shl_sat( abs_s( sub( T0, Tc ) ), 6 ), mult( 19661 /*0.15f Q17*/, shl_sat( Tc, 4 ) ) /*Q6*/ ); @@ -221,16 +221,16 @@ void con_acelp_fx( pt_exc = exc; if ( st->enableGplc != 0 ) { - pt_exc = &exc[imult1616( nSubframes, L_SUBFR )]; + pt_exc = &exc[( nSubframes * L_SUBFR )]; /*Qf_exc*/ } - pt1_exc = pt_exc - Tc; + pt1_exc = pt_exc - Tc; /*Qf_exc*/ IF( fUseExtrapolatedPitch != 0 ) { /* Required because later pt1_exc[1] used in filtering points to exc[0]. To make it safe also for GPL pt_exc is used instead of exc */ pt_exc[0] = 0; move16(); - pt_exc = harmonic_exc_buf; + pt_exc = harmonic_exc_buf; /*Qf_exc*/ assert( pt_exc < pt1_exc - 1 ); } @@ -249,10 +249,10 @@ void con_acelp_fx( { /* *pt_exc++ = ( lpFiltAdapt[0] * pt1_exc[-1] + lpFiltAdapt[1] * pt1_exc[0] + lpFiltAdapt[2] * pt1_exc[1]);*/ - tmp_32 = L_mult( lpFiltAdapt[0], pt1_exc[-1] ); - tmp_32 = L_mac( tmp_32, lpFiltAdapt[1], pt1_exc[0] ); - tmp_16 = mac_r( tmp_32, lpFiltAdapt[2], pt1_exc[1] ); - *pt_exc = tmp_16; + tmp_32 = L_mult( lpFiltAdapt[0], pt1_exc[-1] ); /*Q16 + Qf_exc*/ + tmp_32 = L_mac( tmp_32, lpFiltAdapt[1], pt1_exc[0] ); /*Q16 + Qf_exc*/ + tmp_16 = mac_r( tmp_32, lpFiltAdapt[2], pt1_exc[1] ); /*Qf_exc*/ + *pt_exc = tmp_16; /*Qf_exc*/ move16(); pt_exc++; pt1_exc++; @@ -263,20 +263,20 @@ void con_acelp_fx( /* copy the first pitch cycle without low-pass filtering */ FOR( i = 0; i < Tc; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Qf_exc*/ move16(); } } if ( fUseExtrapolatedPitch != 0 ) { - pt1_exc = harmonic_exc_buf; + pt1_exc = harmonic_exc_buf; /*Qf_exc*/ } l = add( st->L_frame, sub( imult1616( L_SUBFR, sub( 1, nSubframes ) ), Tc ) ); FOR( i = 0; i < l; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Qf_exc*/ move16(); } @@ -287,9 +287,9 @@ void con_acelp_fx( IF( nSubframes > 0 ) { - pitch_buf[0] = L_deposit_h( st->guidedT0 ); + pitch_buf[0] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); - pitch_buf[1] = L_deposit_h( st->guidedT0 ); + pitch_buf[1] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); } @@ -301,7 +301,7 @@ void con_acelp_fx( if ( EQ_16( st->nb_subfr, 5 ) ) { /* for guided acelp cases and nSubframes=2, set pitch_buf[4] to avoid memory_access issues in post_decoder() */ - pitch_buf[4] = pitch_buf[3]; + pitch_buf[4] = pitch_buf[3]; /*Q16*/ move32(); } } @@ -315,7 +315,7 @@ void con_acelp_fx( } ELSE { - set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); + set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); /*15Q16*/ } } @@ -323,8 +323,8 @@ void con_acelp_fx( * PLC: [ACELP: adaptive codebook] * PLC: Create the harmonic part needed for the overlap-add. *------------------------------------------------------------*/ - pt_exc = exc + st->L_frame; - pt1_exc = pt_exc - T0; + pt_exc = exc + st->L_frame; /*Qf_exc*/ + pt1_exc = pt_exc - T0; /*Qf_exc*/ if ( T0 == 0 ) { pt1_exc = pt_exc - Tc; @@ -343,11 +343,11 @@ void con_acelp_fx( IF( fUseExtrapolatedPitch != 0 ) { - st->old_fpitch = predPitchLag; + st->old_fpitch = predPitchLag; /*Q16*/ move32(); if ( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_fpitch = L_deposit_h( T0 ); + st->old_fpitch = L_deposit_h( T0 ); /*Q16*/ move32(); } } @@ -371,8 +371,8 @@ void con_acelp_fx( /* mapping: floor(( 0.824[15Q15]-x[15Q0]*0.0733[0Q15] )*4) */ - pc = Mpy_32_16_1( L_shl( pc, 1 ) /*precompensate Q14 from table*/, /*15Q16*/ - T_256DIV_L_Frame[L_shr( L_msu0( 54000, shr( st->L_frame, 5 ), 2402 ), 15 - 2 )] ); + pc = Mpy_32_16_1( L_shl( pc, 1 ) /*precompensate Q14 from table*/, /*15Q16*/ + T_256DIV_L_Frame[L_shr( L_msu0( 54000, shr( st->L_frame, 5 ), 2402 ), 15 - 2 )] ); /*Q16*/ test(); test(); /*test();*/ @@ -421,9 +421,9 @@ void con_acelp_fx( { BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - exc[i] = mult_r( exc[i], shl_sat( gain, 1 ) ); /*overflow is first iteration because gain may be 1 after shift*/ + exc[i] = mult_r( exc[i], shl_sat( gain, 1 ) ); /*overflow is first iteration because gain may be 1 after shift*/ /*Qf_exc*/ #else - exc[i] = mult_r( exc[i], shl( gain, 1 ) ); /*overflow is first iteration because gain may be 1 after shift*/ + exc[i] = mult_r( exc[i], shl( gain, 1 ) ); /*overflow is first iteration because gain may be 1 after shift*/ /*Qf_exc*/ #endif BASOP_SATURATE_WARNING_ON_EVS move16(); @@ -436,9 +436,9 @@ void con_acelp_fx( { BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - exc[i] = mult_r( exc[i], shl_sat( gain, 1 ) ); /*overflow is first iteration because gain may become 1 due to shift*/ + exc[i] = mult_r( exc[i], shl_sat( gain, 1 ) ); /*overflow is first iteration because gain may become 1 due to shift*/ /*Qf_exc*/ #else - exc[i] = mult_r( exc[i], shl( gain, 1 ) ); /*overflow is first iteration because gain may become 1 due to shift*/ + exc[i] = mult_r( exc[i], shl( gain, 1 ) ); /*overflow is first iteration because gain may become 1 due to shift*/ /*Qf_exc*/ #endif BASOP_SATURATE_WARNING_ON_EVS move16(); @@ -449,12 +449,12 @@ void con_acelp_fx( { pT[i] = round_fx( pitch_buf[i] ); /*Q0*/ move16(); - pitch_buffer[i] = round_fx( pitch_buf[i] ); + pitch_buffer[i] = round_fx( pitch_buf[i] ); /*Q0*/ move16(); } /* update old exc without random part*/ - Copy( harmonic_exc_buf + st->L_frame, st->old_exc_fx, L_EXC_MEM_DEC ); + Copy( harmonic_exc_buf + st->L_frame, st->old_exc_fx, L_EXC_MEM_DEC ); /*Qf_exc*/ } ELSE { @@ -468,9 +468,9 @@ void con_acelp_fx( move32(); pgainT[i] = 0; move16(); - pT[i] = L_SUBFR; + pT[i] = L_SUBFR; /*Q0*/ move16(); - pitch_buffer[i] = L_SUBFR; + pitch_buffer[i] = L_SUBFR; /*Q0*/ move16(); } @@ -486,7 +486,7 @@ void con_acelp_fx( * * search for "Scale from randomized buffer to excitation buffer" *-----------------------------------------------------------------*/ - noise_buf = buf; + noise_buf = buf; /*Qf_exc*/ tmpSeed = st->seed_acelp; move16(); l = add( st->L_frame, sub( l_fir_fer, 1 ) ); @@ -516,7 +516,7 @@ void con_acelp_fx( /* PLC: [ACELP: Fade-out] * PLC: retrieve background level */ - tmp2 = shl( div_s( st->L_frame, shl( L_SUBFR, 3 ) ), 3 - 15 ); + tmp2 = shl( div_s( st->L_frame, shl( L_SUBFR, 3 ) ), 3 - 15 ); /*Q0*/ tmp = 32767 /*1.0f Q15*/; @@ -545,11 +545,11 @@ void con_acelp_fx( #ifdef BASOP_NOGLOB ftmp = round_fx_sat( L_shl_sat( gain_32, 1 ) ); /*Q0*/ #else - ftmp = round_fx( L_shl( gain_32, 1 ) ); /*Q0*/ + ftmp = round_fx( L_shl( gain_32, 1 ) ); /*Q0*/ #endif BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - tmp_16 = sub( shl_sat( gainCNG, sub( gainCNG_e, 5 /*Q5*/ ) ), ftmp ); + tmp_16 = sub( shl_sat( gainCNG, sub( gainCNG_e, 5 /*Q5*/ ) ), ftmp ); /*Q0*/ #else tmp_16 = sub( shl( gainCNG, sub( gainCNG_e, 5 /*Q5*/ ) ), ftmp ); #endif @@ -594,7 +594,7 @@ void con_acelp_fx( s2 = sub( s2, 4 - 15 ); /*->Q15*/ s_16 = BASOP_Util_Add_MantExp( tmp_16, s_16, tmp2, s2, &tmp_16 ); - st->Mode2_lp_gainc = L_shl( L_deposit_l( tmp_16 ), add( s_16, 1 ) ); + st->Mode2_lp_gainc = L_shl( L_deposit_l( tmp_16 ), add( s_16, 1 ) ); /*Q16*/ move32(); test(); IF( ( EQ_16( st->last_good, UNVOICED_TRANSITION ) ) && ( EQ_16( coder_type, GENERIC ) ) ) @@ -607,13 +607,13 @@ void con_acelp_fx( highPassFiltering_fx( st->last_good, add( st->L_frame, shr( l_fir_fer, 1 ) ), noise_buf, hp_filt, l_fir_fer ); - pt_exc = noise_buf + shr( l_fir_fer, 1 ); + pt_exc = noise_buf + shr( l_fir_fer, 1 ); /*Qf_exc*/ /*** Find energy normalization factor ***/ /*gain_inov = 1.0f / (float)sqrt( dot_product( pt_exc, pt_exc, st->L_frame ) / st->L_frame );*/ /* normalize energy */ /*<--- FLC*/ - BASOP_SATURATE_WARNING_OFF_EVS /*norm_llQ31 at the end of Dot_productSq16HQ may throw an overflow, but result is okay*/ - tmp_32 = Dot_productSq16HQ( 0, pt_exc, st->L_frame, &s_32 ); + BASOP_SATURATE_WARNING_OFF_EVS /*norm_llQ31 at the end of Dot_productSq16HQ may throw an overflow, but result is okay*/ + tmp_32 = Dot_productSq16HQ( 0, pt_exc, st->L_frame, &s_32 ); /*Q31*/ BASOP_SATURATE_WARNING_ON_EVS s_32 = add( s_32, 31 - 1 ); /*scalingfactor is twice the headroom (at noise insertion onto the buffer), -1 (because of mult) +31 (Result is Q31) +s_32 (output scalingfactor of dot_product)*/ @@ -629,7 +629,7 @@ void con_acelp_fx( { s_gain_inov = s_32; move16(); - tmp_32 = ISqrt32( tmp_32, &s_gain_inov ); + tmp_32 = ISqrt32( tmp_32, &s_gain_inov ); /* Q31 - s_gain_inov */ } ELSE { @@ -640,7 +640,7 @@ void con_acelp_fx( } - gain_inov = round_fx( tmp_32 ); /*Inverse sqrt*/ /* Q15 * 2^s_gain_inov */ + gain_inov = round_fx( tmp_32 ); /*Inverse sqrt*/ /* Q15 * 2^s_gain_inov */ /* Q15 - s_gain_inov */ /* PLC: [ACELP: Fade-out] * PLC: Linearly attenuate the gain through the frame */ @@ -661,12 +661,12 @@ void con_acelp_fx( Word16 tilt_code; /*tilt_code = (float)(0.10f*(1.0f + st->voice_fac));*/ - tilt_code = mac_r( 214748368l /*0.1f Q31*/, 3277 /*0.1f Q15*/, st->voice_fac ); + tilt_code = mac_r( 214748368l /*0.1f Q31*/, 3277 /*0.1f Q15*/, st->voice_fac ); /*Q15*/ gain_inov = mult_r( gain_inov, sub( 32767 /*1.0f Q15*/, tilt_code ) ); /* Q15 * 2^s_gain_inov */ } - pt_exc = noise_buf; + pt_exc = noise_buf; /*Qf_exc*/ /* non-causal ringing of the FIR filter */ @@ -690,9 +690,9 @@ void con_acelp_fx( g_e = norm_s( round_fx( L_shl( Mpy_32_16_1( st->Mode2_lp_gainc, gain_inov ), add( 15, s_gain_inov ) ) ) ); /* norm_s for gain*gain_inov at the end of the following loops */ #endif g_e = s_min( norm_s( gain_16 ), g_e ); - gain_16 = shl( gain_16, g_e ); - gain_32 = L_shl( gain_32, g_e ); - step_32 = L_shl( step_32, g_e ); + gain_16 = shl( gain_16, g_e ); /*Q15 + g_e*/ + gain_32 = L_shl( gain_32, g_e ); /*Q31 + g_e*/ + step_32 = L_shl( step_32, g_e ); /*Q31 + g_e*/ l = shr( l_fir_fer, 1 ); FOR( i = 0; i < l; i++ ) { @@ -711,7 +711,7 @@ void con_acelp_fx( pt_exc++; gain_32 = L_sub( gain_32, step_32 ); - gain_16 = round_fx( gain_32 ); + gain_16 = round_fx( gain_32 ); /*Q15*/ } l = add( shr( st->L_frame, 1 ), shr( l_fir_fer, 1 ) ); @@ -735,36 +735,36 @@ void con_acelp_fx( IF( LT_16( st->last_good, UNVOICED_TRANSITION ) ) { - bufferCopyFx( noise_buf + shr( l_fir_fer, 1 ), exc, add( st->L_frame, shr( st->L_frame, 1 ) ), 0, *Qf_exc, negate( g_e ), 0 ); /*copy between different formats*/ - Copy( harmonic_exc_buf + st->L_frame, st->old_exc_fx, L_EXC_MEM_DEC ); - Copy( exc, exc_unv, add( st->L_frame, shr( st->L_frame, 1 ) ) ); /* Update exc_unv */ + bufferCopyFx( noise_buf + shr( l_fir_fer, 1 ), exc, add( st->L_frame, shr( st->L_frame, 1 ) ), 0, *Qf_exc, negate( g_e ), 0 ); /*copy between different formats*/ /*Qf_exc*/ + Copy( harmonic_exc_buf + st->L_frame, st->old_exc_fx, L_EXC_MEM_DEC ); /*Qf_exc*/ + Copy( exc, exc_unv, add( st->L_frame, shr( st->L_frame, 1 ) ) ); /* Update exc_unv */ /*Qf_exc*/ } ELSE { /* Update exc_unv */ - bufferCopyFx( noise_buf + shr( l_fir_fer, 1 ), exc_unv, add( st->L_frame, shr( st->L_frame, 1 ) ), 0, *Qf_exc, negate( g_e ), 0 ); /*copy between different formats*/ + bufferCopyFx( noise_buf + shr( l_fir_fer, 1 ), exc_unv, add( st->L_frame, shr( st->L_frame, 1 ) ), 0, *Qf_exc, negate( g_e ), 0 ); /*copy between different formats*/ /*Qf_exc*/ } /* Compute total excitation in noisebuffer to save memories */ IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { - Vr_add( exc, exc_unv, noise_buf, add( st->L_frame, 1 ) ); + Vr_add( exc, exc_unv, noise_buf, add( st->L_frame, 1 ) ); /*Qf_exc*/ } ELSE { - noise_buf = exc_unv; + noise_buf = exc_unv; /*Qf_exc*/ } IF( st->hBWE_TD != NULL ) { IF( EQ_16( st->L_frame, L_FRAME ) ) { interp_code_5over2_fx( noise_buf, bwe_exc, st->L_frame ); - set16_fx( voice_factors, st->last_voice_factor_fx, NB_SUBFR ); + set16_fx( voice_factors, st->last_voice_factor_fx, NB_SUBFR ); /* Q6 */ } ELSE { interp_code_4over2_fx( noise_buf, bwe_exc, st->L_frame ); - set16_fx( voice_factors, st->last_voice_factor_fx, NB_SUBFR16k ); + set16_fx( voice_factors, st->last_voice_factor_fx, NB_SUBFR16k ); /* Q6 */ } } /*----------------------------------------------------------* @@ -773,13 +773,13 @@ void con_acelp_fx( /* Init syn buffer */ syn = buf + M; - Copy( st->mem_syn2_fx, buf, M ); + Copy( st->mem_syn2_fx, buf, M ); /*Q_syn*/ IF( EQ_16( st->nbLostCmpt, 1 ) ) { IF( LT_16( st->last_good, UNVOICED_TRANSITION ) ) { - Copy( st->mem_syn2_fx, mem_syn_unv, M ); + Copy( st->mem_syn2_fx, mem_syn_unv, M ); /*Q_syn*/ } ELSE { @@ -788,7 +788,7 @@ void con_acelp_fx( } ELSE { - Copy( st->mem_syn_unv_back, mem_syn_unv, M ); + Copy( st->mem_syn_unv_back, mem_syn_unv, M ); /*Q_syn*/ } /* voiced synth */ @@ -810,11 +810,11 @@ void con_acelp_fx( /* i_subfr / L_SUBFR */ tmp_16 = shr( i_subfr, Q6 ); /* gain_lpc[i_subfr/L_SUBFR] = 1.f/(float)sqrt(dotp( h1, h1, L_SUBFR)); */ - tmp_32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gain_lpc_e[tmp_16] ); + tmp_32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gain_lpc_e[tmp_16] ); /*Q31*/ tmp_32 = L_max( tmp_32, 1 ); gain_lpc_e[tmp_16] = add( gain_lpc_e[tmp_16], shl( scale_h1, 1 ) ); move16(); - gain_lpc[tmp_16] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[tmp_16] ) ); + gain_lpc[tmp_16] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[tmp_16] ) ); /* Q15 - gain_lpc_e[tmp_16] */ move16(); p_A += ( M + 1 ); /* Pointer move */ @@ -826,10 +826,10 @@ void con_acelp_fx( { /* i_subfr / L_SUBFR */ tmp_16 = shr( i_subfr, Q6 ); - g = mult_r( st->last_gain_syn_deemph, gain_lpc[tmp_16] ); + g = mult_r( st->last_gain_syn_deemph, gain_lpc[tmp_16] ); /* Q15 - gain_lpc_e[tmp_16] */ #ifdef BASOP_NOGLOB g_e = add_sat( st->last_gain_syn_deemph_e, gain_lpc_e[tmp_16] ); - g = shl_sat( g, g_e ); + g = shl_sat( g, g_e ); /* Q15 */ #else g_e = add( st->last_gain_syn_deemph_e, gain_lpc_e[tmp_16] ); g = shl( g, g_e ); @@ -838,14 +838,14 @@ void con_acelp_fx( FOR( i = 0; i < L_SUBFR; i++ ) { /* exc[i_subfr + i] *= st->last_gain_syn_deemph*gain_lpc[j]; */ - exc[i_subfr + i] = mult_r( exc[add( i_subfr, i )], g ); + exc[i_subfr + i] = mult_r( exc[( i_subfr + i )], g ); /*Qf_exc*/ move16(); } } l = add( st->L_frame, shr( st->L_frame, 1 ) ); FOR( i = st->L_frame; i < l; i++ ) { - exc[i] = mult_r( exc[i], g ); + exc[i] = mult_r( exc[i], g ); /*Qf_exc*/ move16(); } @@ -866,7 +866,7 @@ void con_acelp_fx( E_UTIL_synthesis( synthScaling, p_A, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1, M ); p_A += ( M + 1 ); } - Copy( mem_syn, mem_syn2, M ); + Copy( mem_syn, mem_syn2, M ); /*Qf_syn + s_16*/ /* synthesize ola*/ E_UTIL_synthesis( synthScaling, p_A - ( M + 1 ), &exc[i_subfr], &syn[i_subfr], shr( st->L_frame, 1 ), mem_syn2, 0, M ); } @@ -875,8 +875,8 @@ void con_acelp_fx( IF( GT_16( st->nbLostCmpt, 5 ) && ( s_16 > 0 ) ) { /*scale back mem_syn, exc and synthesis*/ - Scale_sig( mem_syn, M, negate( s_16 ) ); - Scale_sig( syn, add( shr( st->L_frame, 1 ), st->L_frame ), negate( s_16 ) ); + Scale_sig( mem_syn, M, negate( s_16 ) ); /* Qf_syn */ + Scale_sig( syn, add( shr( st->L_frame, 1 ), st->L_frame ), negate( s_16 ) ); /* Qf_syn */ /*Scale_sig(exc, add(shr(st->L_frame,1),st->L_frame) ,negate(s_16));*/ } @@ -900,11 +900,11 @@ void con_acelp_fx( /* i_subfr / L_SUBFR */ tmp_16 = shr( i_subfr, Q6 ); /* gain_lpc[i_subfr/L_SUBFR] = 1.f/(float)sqrt(dotp( h1, h1, L_SUBFR)); */ - tmp_32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gain_lpc_e[tmp_16] ); + tmp_32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gain_lpc_e[tmp_16] ); /*Q31*/ tmp_32 = L_max( tmp_32, 1 ); gain_lpc_e[tmp_16] = add( gain_lpc_e[tmp_16], shl( scale_h1, 1 ) ); move16(); - gain_lpc[tmp_16] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[tmp_16] ) ); + gain_lpc[tmp_16] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[tmp_16] ) ); /* Q15 - gain_lpc_e[tmp_16] */ move16(); p_A += ( M + 1 ); /* Pointer move */ @@ -916,24 +916,24 @@ void con_acelp_fx( { /* i_subfr / L_SUBFR */ tmp_16 = shr( i_subfr, Q6 ); - g = mult_r( st->last_gain_syn_deemph, gain_lpc[tmp_16] ); + g = mult_r( st->last_gain_syn_deemph, gain_lpc[tmp_16] ); /* Q15 - gain_lpc_e[tmp_16] */ g_e = add( st->last_gain_syn_deemph_e, gain_lpc_e[tmp_16] ); #ifdef BASOP_NOGLOB - g = shl_sat( g, g_e ); + g = shl_sat( g, g_e ); /*Q15*/ #else g = shl( g, g_e ); #endif FOR( i = 0; i < L_SUBFR; i++ ) { /* exc[i_subfr + i] *= st->last_gain_syn_deemph*gain_lpc[j]; */ - exc_unv[add( i_subfr, i )] = mult_r( exc_unv[add( i_subfr, i )], g ); + exc_unv[( i_subfr + i )] = mult_r( exc_unv[add( i_subfr, i )], g ); /*Qf_exc*/ move16(); } } l = add( st->L_frame, shr( st->L_frame, 1 ) ); FOR( i = st->L_frame; i < l; i++ ) { - exc_unv[i] = mult_r( exc_unv[i], g ); + exc_unv[i] = mult_r( exc_unv[i], g ); /*Qf_exc*/ move16(); } @@ -950,18 +950,18 @@ void con_acelp_fx( p_A = st->Aq_cng; /*in case of more than 5 consecutive concealed frames, improve precision of synthesis*/ - memsynPrecission_fx( st->nbLostCmpt, mem_syn_unv, exc_unv, st->L_frame, &s_16 ); + memsynPrecission_fx( st->nbLostCmpt, mem_syn_unv, exc_unv, st->L_frame, &s_16 ); /*Qf_syn + s_16*/ FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { E_UTIL_synthesis( synthScaling, p_A, &exc_unv[i_subfr], &syn_unv[i_subfr], L_SUBFR, mem_syn_unv, 1, M ); p_A += ( M + 1 ); } - Copy( mem_syn_unv, st->mem_syn_unv_back, M ); + Copy( mem_syn_unv, st->mem_syn_unv_back, M ); /*Qf_syn + s_16*/ IF( LT_16( st->last_good, UNVOICED_TRANSITION ) ) { - Copy( mem_syn_unv, mem_syn, M ); + Copy( mem_syn_unv, mem_syn, M ); /*Qf_syn + s_16*/ /* unvoiced for ola */ E_UTIL_synthesis( synthScaling, p_A - ( M + 1 ), &exc_unv[i_subfr], &syn_unv[i_subfr], shr( st->L_frame, 1 ), mem_syn_unv, 0, M ); } @@ -970,18 +970,18 @@ void con_acelp_fx( IF( GT_16( st->nbLostCmpt, 5 ) && ( s_16 > 0 ) ) { /*scale back mem_syn_unv, exc_unv and synthesis*/ - Scale_sig( mem_syn_unv, M, negate( s_16 ) ); + Scale_sig( mem_syn_unv, M, negate( s_16 ) ); /*Qf_syn*/ IF( LT_16( st->last_good, UNVOICED_TRANSITION ) ) { - Scale_sig( mem_syn, M, negate( s_16 ) ); - Scale_sig( syn_unv, add( shr( st->L_frame, 1 ), st->L_frame ), negate( s_16 ) ); + Scale_sig( mem_syn, M, negate( s_16 ) ); /*Qf_syn*/ + Scale_sig( syn_unv, add( shr( st->L_frame, 1 ), st->L_frame ), negate( s_16 ) ); /*Qf_syn*/ } ELSE { - Scale_sig( syn_unv, st->L_frame, negate( s_16 ) ); + Scale_sig( syn_unv, st->L_frame, negate( s_16 ) ); /*Qf_syn*/ } - Scale_sig( st->mem_syn_unv_back, M, negate( s_16 ) ); + Scale_sig( st->mem_syn_unv_back, M, negate( s_16 ) ); /*Qf_syn*/ /*Scale_sig(exc_unv, add(shr(st->L_frame,1),st->L_frame) ,negate(s_16));*/ } @@ -992,7 +992,7 @@ void con_acelp_fx( FOR( i = 0; i < st->L_frame; i++ ) { #ifdef BASOP_NOGLOB - syn[i] = add_sat( syn[i], syn_unv[i] ); + syn[i] = add_sat( syn[i], syn_unv[i] ); /*Qf_syn*/ #else syn[i] = add( syn[i], syn_unv[i] ); #endif @@ -1001,7 +1001,7 @@ void con_acelp_fx( } ELSE { - Copy( syn_unv, syn, add( st->L_frame, shr( st->L_frame, 1 ) ) ); + Copy( syn_unv, syn, add( st->L_frame, shr( st->L_frame, 1 ) ) ); /*Qf_syn*/ } @@ -1072,21 +1072,21 @@ void con_acelp_fx( } /* Update Pitch Lag memory */ - Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); - Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); + Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); /*15Q16*/ + Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); /*15Q16*/ /*updating enr_old parameters*/ frame_ener_fx( st->L_frame, st->last_good, syn, round_fx( tmp_tc ), &( st->enr_old_fx ), 1, 0, 0, 0 ); #ifdef BASOP_NOGLOB - st->enr_old_fx = L_shl_sat( st->enr_old_fx, shl( negate( Qf_syn ), 1 ) ); + st->enr_old_fx = L_shl_sat( st->enr_old_fx, shl( negate( Qf_syn ), 1 ) ); /*Q0*/ #else st->enr_old_fx = L_shl( st->enr_old_fx, shl( negate( Qf_syn ), 1 ) ); #endif move32(); /* update ACELP synthesis memory */ - Copy( mem_syn, st->mem_syn2_fx, M ); - Copy( syn + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); + Copy( mem_syn, st->mem_syn2_fx, M ); /*Qf_syn*/ + Copy( syn + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); /*Qf_syn*/ /*Q_mem_syn_new = Q_mem_syn;*/ /*NOT "+synthScaling", cause mem_syn format is not changed*/ /* Deemphasis and output synth */ @@ -1101,13 +1101,15 @@ void con_acelp_fx( /* save last half frame if next frame is TCX */ bufferCopyFx( syn + st->L_frame, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); - Copy( syn + sub( st->L_frame, M + 1 ), st->syn, 1 + M ); + hTcxDec->Q_syn_Overl_TDAC = add( st->Q_syn, -1 ); + move16(); + Copy( syn + sub( st->L_frame, M + 1 ), st->syn, 1 + M ); /*Qf_syn*/ /* update old_Aq */ - Copy( p_A - ( M + 1 ), st->old_Aq_12_8_fx, M + 1 ); + Copy( p_A - ( M + 1 ), st->old_Aq_12_8_fx, M + 1 ); /*Q12*/ - Copy( syn + st->L_frame, hTcxDec->syn_Overl, shr( st->L_frame, 1 ) ); + Copy( syn + st->L_frame, hTcxDec->syn_Overl, shr( st->L_frame, 1 ) ); /*Qf_syn*/ /* create aliasing and windowing */ @@ -1117,7 +1119,7 @@ void con_acelp_fx( st->hTcxCfg->tcx_curr_overlap_mode = FULL_OVERLAP; move16(); - n = extract_h( L_mult( st->L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); + n = extract_h( L_mult( st->L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); /*Q0*/ hHQ_core->Q_old_wtda_LB = getScaleFactor16( syn + sub( st->L_frame, n ), sub( st->L_frame, n ) ); @@ -1126,15 +1128,15 @@ void con_acelp_fx( bufferCopyFx( syn + sub( st->L_frame, n ), hHQ_core->old_out_LB_fx, sub( st->L_frame, n ), 0, 0, hHQ_core->Q_old_wtda_LB, 0 ); FOR( i = 0; i < W2; i++ ) { - hHQ_core->old_out_LB_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_LB_fx[add( i, n )] ) ); + hHQ_core->old_out_LB_fx[( i + n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_LB_fx[( i + n )] ) ); /* hHQ_core->q_old_outLB_fx */ move16(); } FOR( ; i < W1; i++ ) { - hHQ_core->old_out_LB_fx[i + n] = round_fx( Mpy_32_16_1( L_mult( w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im, w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im ), hHQ_core->old_out_LB_fx[add( i, n )] ) ); + hHQ_core->old_out_LB_fx[i + n] = round_fx( Mpy_32_16_1( L_mult( w[( W2 - ( 1 + ( i - W2 ) ) )].v.im, w[( W2 - ( 1 + ( i - W2 ) ) )].v.im ), hHQ_core->old_out_LB_fx[( i + n )] ) ); /* hHQ_core->q_old_outLB_fx */ move16(); } - set16_fx( &hHQ_core->old_out_LB_fx[add( W1, n )], 0, n ); + set16_fx( &hHQ_core->old_out_LB_fx[( W1 + n )], 0, n ); hHQ_core->Q_old_wtda = hHQ_core->Q_old_wtda_LB; move16(); @@ -1142,43 +1144,45 @@ void con_acelp_fx( FOR( i = 0; i < W2; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[i].v.re ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } FOR( ; i < W1; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[sub( sub( W1, 1 ), i )].v.im ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[( ( W1 - 1 ) - i )].v.im ); /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } FOR( i = 0; i < W2; i++ ) { - hTcxDec->syn_Overl_TDAC[i] = add( buf[i], buf[sub( sub( W1, 1 ), i )] ); /* A-D */ + hTcxDec->syn_Overl_TDAC[i] = add( buf[i], buf[( ( W1 - 1 ) - i )] ); /* A-D */ /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } /*-2*/ FOR( i = 0; i < W2; i++ ) { - hTcxDec->syn_Overl_TDAC[add( W2, i )] = add( buf[add( W2, i )], buf[sub( sub( sub( W1, 1 ), W2 ), i )] ); /* B-C */ + hTcxDec->syn_Overl_TDAC[( W2 + i )] = add( buf[( W2 + i )], buf[( ( ( W1 - 1 ) - W2 ) - i )] ); /* B-C */ /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } FOR( i = 0; i < W2; i++ ) { - hTcxDec->syn_Overl_TDAC[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[i].v.re ); + hTcxDec->syn_Overl_TDAC[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } FOR( ; i < W1; i++ ) { - hTcxDec->syn_Overl_TDAC[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[sub( sub( W1, 1 ), i )].v.im ); + hTcxDec->syn_Overl_TDAC[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[( ( W1 - 1 ) - i )].v.im ); /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } /* update memory for full band */ lerp( hTcxDec->syn_Overl_TDAC, hTcxDec->syn_Overl_TDACFB, shr( hTcxDec->L_frameTCX, 1 ), shr( st->L_frame, 1 ) ); + st->hTcxDec->Q_syn_Overl_TDACFB = st->hTcxDec->Q_syn_Overl_TDAC; + move16(); lerp( hTcxDec->syn_Overl, hTcxDec->syn_OverlFB, shr( hTcxDec->L_frameTCX, 1 ), shr( st->L_frame, 1 ) ); lerp( hHQ_core->old_out_LB_fx, hHQ_core->old_out_fx, hTcxDec->L_frameTCX, st->L_frame ); @@ -1188,7 +1192,7 @@ void con_acelp_fx( lerp( exc, st->hWIDec->old_exc2_fx, L_EXC_MEM, st->L_frame ); lerp( syn, st->hWIDec->old_syn2_fx, L_EXC_MEM, st->L_frame ); } - st->bfi_pitch_fx = shl( round_fx( pitch_buf[sub( st->nb_subfr, 1 )] ), 6 ); + st->bfi_pitch_fx = shl( round_fx( pitch_buf[( st->nb_subfr - 1 )] ), 6 ); /*Q6*/ st->bfi_pitch_frame = st->L_frame; move16(); move16(); @@ -1196,7 +1200,7 @@ void con_acelp_fx( return; } -static void memsynPrecission_fx( Word16 nbLostCmpt, Word16 *mem_syn, Word16 *exc, Word16 len, Word16 *s_16 ) +static void memsynPrecission_fx( Word16 nbLostCmpt, Word16 *mem_syn /*Qx*/, Word16 *exc /*Qx*/, Word16 len, Word16 *s_16 ) { IF( GT_16( nbLostCmpt, 5 ) ) { @@ -1238,8 +1242,8 @@ static void memsynPrecission_fx( Word16 nbLostCmpt, Word16 *mem_syn, Word16 *exc } *s_16 = s_max( sub( s_min( sf_exc, sf_mem_syn ), 5 ), 0 ) /*5 bits of headroom, scaling not smaller than 0*/; move16(); - Scale_sig( mem_syn, M, *s_16 ); - Scale_sig( exc, add( shr( len, 1 ), len ), *s_16 ); + Scale_sig( mem_syn, M, *s_16 ); /*Qx + s_16*/ + Scale_sig( exc, add( shr( len, 1 ), len ), *s_16 ); /*Qx + s_16*/ } } } diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 48299ed3289fc09f5013754dad211dea6dfc6b45..1a1dbce92d5cbd4c6e9f0e5a00f1c0f5ec544c2a 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -14,7 +14,7 @@ /***************************************************** calcGainc calculates st->lp_gainc ******************************************************/ -static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch, Word16 L_subfr, Word32 lp_gainp, Word32 *lp_gainc ) +static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch /*Q16*/, Word16 L_subfr /*Q0*/, Word32 lp_gainp /*Q16*/, Word32 *lp_gainc /*Q16*/ ) { Word32 L_c; Word16 tmp16, tmp16_2, tmp16_3, tmp_e, tmp2_e, tmp_loop, i; @@ -49,7 +49,7 @@ static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch, Word16 L /*st->lp_gainc += ( exc[i-2*L_subfr] - st->Mode2_lp_gainp * exc[i-2*L_subfr-(int)(st->old_fpitch+0.5f)] ) * ( exc[i-2*L_subfr] - st->Mode2_lp_gainp * exc[i-2*L_subfr-(int)(st->old_fpitch+0.5f)] );*/ #ifdef BASOP_NOGLOB - tmp16_3 = sub_o( exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, mult_r( tmp16_2 /*Q15*/, exc[sub( sub( i, shl( L_subfr, 1 ) ), tmp16 )] /*Q1*/ ) /*Q1*/, &Overflow ); + tmp16_3 = sub_o( exc[( i - ( L_subfr * 2 ) )] /*Q1*/, mult_r( tmp16_2 /*Q15*/, exc[( ( i - ( L_subfr * 2 ) ) - tmp16 )] /*Q1*/ ) /*Q1*/, &Overflow ); #else tmp16_3 = sub( exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, mult_r( tmp16_2 /*Q15*/, exc[sub( sub( i, shl( L_subfr, 1 ) ), tmp16 )] /*Q1*/ ) /*Q1*/ ); #endif @@ -61,7 +61,7 @@ static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch, Word16 L Overflow = 0; move16(); #ifdef BASOP_NOGLOB - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Accumulate Carrys*/ + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Accumulate Carrys Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); /*Accumulate Carrys*/ #endif @@ -81,7 +81,7 @@ static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch, Word16 L move32(); } -static void calcGainc2_fx( Word16 *exc, Word16 Q_exc, Word16 L_subfr, Word32 *lp_gainc ) +static void calcGainc2_fx( Word16 *exc, Word16 Q_exc, Word16 L_subfr /*Q0*/, Word32 *lp_gainc /*Q16*/ ) { Word16 i, cnt, tmp16, tmp_e, tmp2_e; Word32 L_c, L_acc, L_tmp; @@ -106,15 +106,15 @@ static void calcGainc2_fx( Word16 *exc, Word16 Q_exc, Word16 L_subfr, Word32 *lp FOR( i = 0; i < cnt; i++ ) { /* *gainc += ( exc[i-2*L_subfr] ) * ( exc[i-2*L_subfr]); */ -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - L_acc = L_macNs_co( L_acc, exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, &Carry, &Overflow ); /*Q3*/ +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ + L_acc = L_macNs_co( L_acc, exc[( i - ( L_subfr * 2 ) )] /*Q1*/, exc[( i - ( L_subfr * 2 ) )] /*Q1*/, &Carry, &Overflow ); /*Q3*/ #else L_acc = L_macNs( L_acc, exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/ ); /*Q3*/ #endif Overflow = 0; move16(); #ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /* Accumulate Carrys */ + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /* Accumulate Carrys Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); /* Accumulate Carrys */ #endif @@ -144,16 +144,16 @@ con_tcx *******************************************************/ void con_tcx_fx( - Decoder_State *st, /* i/o: coder memory state */ - Word16 synth[] /* i/o: synth[] */ /*Q0 */ + Decoder_State *st, /* i/o: coder memory state */ + Word16 synth[] /* i/o: synth[] Q0*/ #ifdef IVAS_CODE_CON_TCX , - const Word16 coh, /* i : coherence of stereo signal */ - Word16 *noise_seed, /* i/o: noise seed for stereo */ - const Word16 only_left /* i : TD-PLC only in left channel */ + const Word16 coh, /* i : coherence of stereo signal Q14*/ + Word16 *noise_seed, /* i/o: noise seed for stereo Q0*/ + const Word16 only_left /* i : TD-PLC only in left channel Q0*/ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT , - const float *A_cng /* i : CNG LP filter coefficients */ + const float *A_cng /* i : CNG LP filter coefficients Q14*/ #endif #endif @@ -211,20 +211,20 @@ void con_tcx_fx( move16(); /* Framing parameters */ - L_frame = hTcxDec->L_frameTCX; + L_frame = hTcxDec->L_frameTCX; /*Q0*/ move16(); /* L_subfr = st->L_frameTCX/st->nb_subfr */ - L_subfr = mult_r( hTcxDec->L_frameTCX, div_s( 1, st->nb_subfr ) ); + L_subfr = mult_r( hTcxDec->L_frameTCX, div_s( 1, st->nb_subfr ) ); /*Q0*/ assert( L_subfr == hTcxDec->L_frameTCX / st->nb_subfr ); move32(); - w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ + w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument Q15*/ W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; move16(); W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 ); W12 = shr( W1, 1 ); /* take the previous frame last pitch */ - Tc = round_fx( st->old_fpitchFB ); + Tc = round_fx( st->old_fpitchFB ); /*Q0*/ set16_fx( buf, 0, OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2 ); /* initialize buf with 0 */ @@ -237,37 +237,37 @@ void con_tcx_fx( FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) { - old_pitch_buf[i] = L_shl( Mpy_32_16_1( st->old_pitch_buf_fx[i], c ), s ); + old_pitch_buf[i] = L_shl( Mpy_32_16_1( st->old_pitch_buf_fx[i], c ), s ); /*Q16*/ move32(); } /* set excitation memory*/ - exc = buf + OLD_EXC_SIZE_DEC; - tmp_deemph = synth[-1]; + exc = buf + OLD_EXC_SIZE_DEC; /*Q_exc*/ + tmp_deemph = synth[-1]; /*Q0*/ move16(); - pre_emph_buf = synth[-1]; + pre_emph_buf = synth[-1]; /*Q0*/ move16(); test(); IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { /* apply pre-emphasis to the signal */ - mem = synth[sub( -( add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), M + M ) ), 1 )]; + mem = synth[( -( ( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )]; /*Q0*/ move16(); - Q_exc = E_UTIL_f_preemph3( &( synth[-add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); + Q_exc = E_UTIL_f_preemph3( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); st->Mode2_lp_gainc = L_deposit_l( 0 ); - st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); + st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); /*Q16*/ - st->Mode2_lp_gainp = L_max( st->Mode2_lp_gainp, 0 ); - st->Mode2_lp_gainp = L_min( st->Mode2_lp_gainp, 65536l /*1.0f Q16*/ ); - st->Mode2_lp_gainp = L_shl( st->Mode2_lp_gainp, 13 ); + st->Mode2_lp_gainp = L_max( st->Mode2_lp_gainp, 0 ); /*Q16*/ + st->Mode2_lp_gainp = L_min( st->Mode2_lp_gainp, 65536l /*1.0f Q16*/ ); /*Q16*/ + st->Mode2_lp_gainp = L_shl( st->Mode2_lp_gainp, 13 ); /*Q29*/ - ana_window = buf; + ana_window = buf; /*Q15*/ ham_cos_window( ana_window, mult( L_frame, 24576 /*0.75f Q15*/ ), shr( L_frame, 2 ) ); /* Autocorrelation */ - autocorr_fx( &( synth[sub( -L_frame, 1 )] ), M, r_h, r_l, &Q_r, L_frame, ana_window, 0, 0 ); + autocorr_fx( &( synth[( -L_frame - 1 )] ), M, r_h, r_l, &Q_r, L_frame, ana_window, 0, 0 ); /* Lag windowing */ lag_wind( r_h, r_l, M, st->output_Fs, LAGW_STRONG ); @@ -276,7 +276,7 @@ void con_tcx_fx( E_LPC_lev_dur( r_h, r_l, A_local, NULL, M, NULL ); /* copy for multiple frame loss */ - Copy( A_local, st->old_Aq_12_8_fx, M + 1 ); + Copy( A_local, st->old_Aq_12_8_fx, M + 1 ); /*Q12*/ /* Residu */ assert( ( 2 * L_subfr + Tc + 1 + M ) <= hTcxDec->old_synth_lenFB ); @@ -284,8 +284,8 @@ void con_tcx_fx( BASOP_SATURATE_WARNING_OFF_EVS /*saturation possible in case of spiky synthesis*/ Residu3_fx( A_local, - &( synth[-add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M )] ), /*Qx = Q0*/ - &( exc[-add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M )] ), /*Qx+1 = Q1*/ + &( synth[-( ( add( ( L_subfr * 2 ), Tc ) + 1 ) + M )] ), /*Qx = Q0*/ + &( exc[-( ( add( ( L_subfr * 2 ), Tc ) + 1 ) + M )] ), /*Qx+1 = Q1*/ add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M ), 1 ); BASOP_SATURATE_WARNING_ON_EVS @@ -293,20 +293,20 @@ void con_tcx_fx( ELSE { /* apply pre-emphasis to the signal */ - mem = synth[sub( -L_frame, 1 )]; + mem = synth[( -L_frame - 1 )]; /*Q0*/ move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); - Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); + Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q12*/ offset = shr( L_frame, 1 ); IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { tmp16 = s_max( sub( Tc, shr( L_frame, 1 ) ), 0 ); - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ } ELSE { - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-shl( L_subfr, 1 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-( L_subfr * 2 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ } } @@ -344,9 +344,9 @@ void con_tcx_fx( tcxltp_pitch_tmp = L_add( L_deposit_h( hTcxLtpDec->tcxltp_pitch_int ), L_shl( L_deposit_l( div_s( hTcxLtpDec->tcxltp_pitch_fr, st->pit_res_max ) ), 1 ) ); /*15Q16*/ scale_tmp = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) ); /*getInvFrameLen()->9Q6*/ tmp_shift = norm_s( scale_tmp ); - predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); + predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); /*Q16*/ - T0 = round_fx( predPitchLag ); + T0 = round_fx( predPitchLag ); /*Q0*/ test(); test(); @@ -372,7 +372,7 @@ void con_tcx_fx( &extrapolationFailed, st->nb_subfr ); - T0 = round_fx( predPitchLag ); + T0 = round_fx( predPitchLag ); /*Q0*/ test(); test(); test(); @@ -386,12 +386,12 @@ void con_tcx_fx( fLowPassFilter = 0; move16(); - pt_exc = exc + offset; - pt1_exc = pt_exc - Tc; + pt_exc = exc + offset; /*Q_exc*/ + pt1_exc = pt_exc - Tc; /*Q_exc*/ if ( fUseExtrapolatedPitch != 0 ) { - pt_exc = buf; + pt_exc = buf; /*Q_exc*/ } test(); IF( LT_16( st->stab_fac_fx, 32767 /*1.f Q15*/ ) && EQ_16( st->nbLostCmpt, 1 ) ) @@ -414,7 +414,7 @@ void con_tcx_fx( 0 /* 0.0000f Q15*/, pt1_exc[2] ), -1442 /*-0.0440f Q15*/, pt1_exc[3] ), 0 /* 0.0000f Q15*/, pt1_exc[4] ), - 174 /* 0.0053f Q15*/, pt1_exc[5] ); + 174 /* 0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ #else *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mult( 174 /* 0.0053f Q15*/, pt1_exc[-5] ), @@ -449,7 +449,7 @@ void con_tcx_fx( 590 /* 0.0180f Q15*/, pt1_exc[2] ), -459 /*-0.0140f Q15*/, pt1_exc[3] ), -121 /*-0.0037f Q15*/, pt1_exc[4] ), - -174 /*-0.0053f Q15*/, pt1_exc[5] ); + -174 /*-0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ #else *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mult( -174 /*-0.0053f Q15*/, pt1_exc[-5] ), @@ -477,7 +477,7 @@ void con_tcx_fx( /* copy the first pitch cycle without low-pass filtering */ FOR( i = 0; i < Tc; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } fLowPassFilter = 1; @@ -486,12 +486,12 @@ void con_tcx_fx( if ( fUseExtrapolatedPitch != 0 ) { - pt1_exc = buf; + pt1_exc = buf; /*Q_exc*/ } tmp16 = add( sub( L_frame, imult1616( fLowPassFilter, Tc ) ), L_subfr ); FOR( i = 0; i < tmp16; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } @@ -512,7 +512,7 @@ void con_tcx_fx( } ELSE { - set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); + set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); /*Q16*/ } IF( EQ_16( st->nbLostCmpt, 1 ) ) @@ -530,14 +530,14 @@ void con_tcx_fx( tmp_loop = shr( L_frame, 1 ); FOR( i = 0; i < tmp_loop; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } } if ( fUseExtrapolatedPitch != 0 ) { - st->old_fpitchFB = predPitchLag; + st->old_fpitchFB = predPitchLag; /*Q16*/ move32(); } st->bpf_gain_param = 0; @@ -599,7 +599,7 @@ void con_tcx_fx( #ifdef BASOP_NOGLOB exc[i] = mult_r( exc[i], round_fx_sat( gain32 ) ) /*Q1*/; move16(); - gain32 = L_sub_sat( gain32, step32 ); + gain32 = L_sub_sat( gain32, step32 ); /*Q31*/ #else exc[i] = mult_r( exc[i], round_fx( gain32 ) ) /*Q1*/; move16(); @@ -608,8 +608,8 @@ void con_tcx_fx( } /* update old exc without random part */ - offset = s_max( sub( round_fx( st->old_fpitchFB ), shr( L_frame, 1 ) ), 0 ); - Copy( exc + sub( L_frame, offset ), hTcxDec->old_excFB_fx, add( shr( L_frame, 1 ), offset ) ); + offset = s_max( sub( round_fx( st->old_fpitchFB ), shr( L_frame, 1 ) ), 0 ); /*Q0*/ + Copy( exc + sub( L_frame, offset ), hTcxDec->old_excFB_fx, add( shr( L_frame, 1 ), offset ) ); /*Q_exc*/ /* copy old_exc as 16kHz for acelp decoding */ IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -617,7 +617,7 @@ void con_tcx_fx( } ELSE { - Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); + Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/ lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; @@ -631,8 +631,8 @@ void con_tcx_fx( { calcGainc2_fx( &exc[0], Q_exc, L_subfr, &( st->Mode2_lp_gainc ) ); } - set32_fx( pitch_buf, L_deposit_h( L_SUBFR ), st->nb_subfr ); - /* PLC: calculate damping factor */ + set32_fx( pitch_buf, L_deposit_h( L_SUBFR ), st->nb_subfr ); /*Q16*/ + /* PLC: calculate damping factor */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT alpha = 1.0f; if ( st->element_mode == IVAS_CPE_MDCT && st->nbLostCmpt >= MDCT_ST_PLC_FADEOUT_START_FRAME ) @@ -699,7 +699,7 @@ void con_tcx_fx( FOR( i = 0; i < tmp_loop; i++ ) { Random( &tmpSeed ); - noise[i] = shr( tmpSeed, noise_e ); + noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/ move16(); } st->seed_acelp = tmpSeed; @@ -709,7 +709,7 @@ void con_tcx_fx( FOR( ; i < tmp_loop; i++ ) { Random( &tmpSeed ); - noise[i] = shr( tmpSeed, noise_e ); + noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/ move16(); } } @@ -733,7 +733,7 @@ void con_tcx_fx( { FOR( i = 0; i < L_FIR_FER2; i++ ) { - hp_filt[i] = h_high3_16[i]; + hp_filt[i] = h_high3_16[i]; /*Q15*/ move16(); } } @@ -741,7 +741,7 @@ void con_tcx_fx( { FOR( i = 0; i < L_FIR_FER2; i++ ) { - hp_filt[i] = h_high3_32[i]; + hp_filt[i] = h_high3_32[i]; /*Q15*/ move16(); } } @@ -762,7 +762,7 @@ void con_tcx_fx( move32(); FOR( j = 11; j > 0; j-- ) { - L_tmp2 = L_mac( L_tmp2, noise[add( i, sub( L_FIR_FER2, j ) )], hp_filt[sub( L_FIR_FER2, j )] ); + L_tmp2 = L_mac( L_tmp2, noise[( i + sub( L_FIR_FER2, j ) )], hp_filt[( L_FIR_FER2 - j )] ); } L_tmp2 = Mpy_32_16_1( L_tmp2, st->cummulative_damping /*Q15*/ ); /*Q0, noise_e*/ noise[i] = mac_r( L_tmp2, gain_tmp, noise[i] ); /*Q15, noise_e*/ @@ -784,7 +784,7 @@ void con_tcx_fx( #else tmp16 = 32767; move16(); - gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); + gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); /*Q5*/ #endif IF( st->tcxonly != 0 ) { @@ -820,10 +820,10 @@ void con_tcx_fx( test(); if ( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) { - gain32 = Mpy_32_16_1( gain32, 22938 /*0.7f Q15*/ ); + gain32 = Mpy_32_16_1( gain32, 22938 /*0.7f Q15*/ ); /*Q16*/ } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - L_tmp = L_shl_sat( gain32, 1 ); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + L_tmp = L_shl_sat( gain32, 1 ); /*Q16*/ #else L_tmp = L_shl( gain32, 1 ); #endif @@ -838,8 +838,8 @@ void con_tcx_fx( L_tmp = Mpy_32_16_1( st->Mode2_lp_gainc, alpha ) /*Q15*/; L_tmp2 = L_mult( sub( 16384 /*1.f Q14*/, alpha ) /*Q14*/, gainCNG /*Q15,gainCNG_e*/ ); /*Q30,gainCNG_e*/ - st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp( L_tmp, 31 - 15, L_tmp2, add( gainCNG_e, 31 - 30 ), &tmp_e ); /*Q31*/ - st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) ); + st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp( L_tmp, 31 - 15, L_tmp2, add( gainCNG_e, 31 - 30 ), &tmp_e ); /*Q31-tmp_e*/ + st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) ); /*Q16*/ move32(); move32(); @@ -864,7 +864,7 @@ void con_tcx_fx( test(); IF( EQ_16( st->last_good, UNVOICED_CLAS ) && NE_16( st->core_ext_mode, UNVOICED ) ) { - gain_inov = mult_r( gain_inov, 26214 /*0.8f Q15*/ ); + gain_inov = mult_r( gain_inov, 26214 /*0.8f Q15*/ ); /*Q30*/ } ELSE IF( !( EQ_16( st->last_good, UNVOICED_CLAS ) || EQ_16( st->last_good, UNVOICED_TRANSITION ) ) ) { @@ -901,7 +901,7 @@ void con_tcx_fx( step32_tmp = L_shl( step32 /*Q25*/, sub( tmp_e, 25 - 16 ) ); /*Q16,-tmp_e*/ FOR( i = 0; i < tmp16; i++ ) /* Actual filtered random part of excitation */ { - *pt_exc = mult_r( *pt_exc, gain_tmp ); + *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/ move16(); pt_exc++; gain32 = L_sub( gain32 /*Q16,-tmp_e*/, step32_tmp ); /*Q16,-tmp_e*/ @@ -910,7 +910,7 @@ void con_tcx_fx( tmp16 = shr( L_frame, 1 ); FOR( i = 0; i < tmp16; i++ ) /* causal ringing of the FIR filter */ { - *pt_exc = mult_r( *pt_exc, gain_tmp ); + *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/ move16(); pt_exc++; } @@ -938,7 +938,7 @@ void con_tcx_fx( ELSE { bufferCopyFx( noise + L_FIR_FER2 / 2, exc, add( L_frame, shr( L_frame, 1 ) ), 0 /*Q_noise*/, noise_e, Q_exc, 0 /*exc_e*/ ); - Copy( exc + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); + Copy( exc + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); /*Q_exc*/ /* copy old_exc as 16kHz for acelp decoding */ IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -946,7 +946,7 @@ void con_tcx_fx( } ELSE { - Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); + Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/ lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; @@ -956,15 +956,15 @@ void con_tcx_fx( /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1*/ /* Update Pitch Lag memory */ - Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); - Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); + Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); /*Q16*/ + Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); /*Q16*/ /*----------------------------------------------------------* * - compute the synthesis speech * *----------------------------------------------------------*/ - syn = buf + M; - Copy( synth - M, buf, M ); + syn = buf + M; /*Q_syn*/ + Copy( synth - M, buf, M ); /*Q_syn*/ new_Q = sub( Q_exc, 3 ); new_Q = s_max( new_Q, -1 ); @@ -977,10 +977,10 @@ void con_tcx_fx( Q_syn = tmp16; move16(); - Copy_Scale_sig( buf, mem_syn, M, exp_scale ); + Copy_Scale_sig( buf, mem_syn, M, exp_scale ); /*Q: tmp16*/ #ifdef BASOP_NOGLOB - tmp_deemph = shl_sat( tmp_deemph, Q_syn ); + tmp_deemph = shl_sat( tmp_deemph, Q_syn ); /*Q_syn*/ #else tmp_deemph = shl( tmp_deemph, Q_syn ); #endif @@ -1031,37 +1031,37 @@ void con_tcx_fx( /*buf[0;M-1] Q0: mem_syn*/ /*buf[M;3/2 L_frame-1] Q-1: syn*/ - n = extract_h( L_mult( L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); + n = extract_h( L_mult( L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); /*q0*/ /* update ACELP synthesis memory */ mem_syn_r_size_old = shr( L_frame, 4 ); /* replace 1.25/20.0 by shr(4) */ /* copy mem_syn as 16kHz */ mem_syn_r_size_new = shr( L_FRAME16k, 4 ); /* replace 1.25/20.0 by shr(4) */ - Copy( syn + sub( L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); + Copy( syn + sub( L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); /*Q_syn*/ lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); + Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /*Q_syn*/ /* Deemphasis and output synth and ZIR */ deemph_fx( syn, st->preemph_fac, add( L_frame, shr( L_frame, 1 ) ), &tmp_deemph ); - bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); + bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); /*Q_syn*/ lerp( syn + sub( L_frame, shr( L_frame, 1 ) ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); - Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); + Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); /*Q_syn*/ FOR( i = 0; i < W12; i++ ) { - hHQ_core->old_out_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[add( i, n )] ) ); + hHQ_core->old_out_fx[( i + n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[( i + n )] ) ); /*Q_syn*/ move16(); } FOR( ; i < W1; i++ ) { - hHQ_core->old_out_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im, w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ), hHQ_core->old_out_fx[add( i, n )] ) ); + hHQ_core->old_out_fx[( i + n )] = round_fx( Mpy_32_16_1( L_mult( w[( ( W12 - 1 ) - ( i - W12 ) )].v.im, w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ), hHQ_core->old_out_fx[( i + n )] ) ); /*Q_syn*/ move16(); } - set16_fx( &hHQ_core->old_out_fx[add( W1, n )], 0, n ); + set16_fx( &hHQ_core->old_out_fx[( W1 + n )], 0, n ); hHQ_core->Q_old_wtda = Q_syn; move16(); @@ -1069,10 +1069,10 @@ void con_tcx_fx( /* As long as there is no synth scaling factor introduced, which is given to the outside, there might occur overflows here */ BASOP_SATURATE_WARNING_OFF_EVS - bufferCopyFx( syn, synth, L_frame, Q_syn, 0, 0, 0 ); + bufferCopyFx( syn, synth, L_frame, Q_syn, 0, 0, 0 ); /*Q_syn*/ BASOP_SATURATE_WARNING_ON_EVS - Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), negate( Q_syn ) ); + Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), negate( Q_syn ) ); /*Q0*/ /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ IF( st->hWIDec != NULL ) @@ -1082,7 +1082,7 @@ void con_tcx_fx( } #ifdef BASOP_NOGLOB - st->bfi_pitch_fx /*Q6*/ = round_fx_sat( L_shl_sat( pitch_buf[sub( st->nb_subfr, 1 )] /*15Q16*/, 6 /*Q6*/ ) ); + st->bfi_pitch_fx /*Q6*/ = round_fx_sat( L_shl_sat( pitch_buf[( st->nb_subfr - 1 )] /*15Q16*/, 6 /*Q6*/ ) ); #else st->bfi_pitch_fx /*Q6*/ = round_fx( L_shl( pitch_buf[sub( st->nb_subfr, 1 )] /*15Q16*/, 6 /*Q6*/ ) ); #endif @@ -1092,15 +1092,17 @@ void con_tcx_fx( /* create aliasing and windowing need for transition to TCX10/5 */ bufferCopyFx( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ), Q_syn, 0, -1, 0 ); + hTcxDec->Q_syn_Overl_TDACFB = add( st->Q_syn, sub( st->Q_syn, -1 ) ); + move16(); FOR( i = 0; i < W12; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( ; i < W1; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } @@ -1108,7 +1110,7 @@ void con_tcx_fx( FOR( i = 0; i < W2; i++ ) { #ifdef BASOP_NOGLOB - hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[sub( sub( W1, 1 ), i )] ); + hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[( ( W1 - 1 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/ #else hTcxDec->syn_Overl_TDACFB[i] = add( buf[i], buf[sub( sub( W1, 1 ), i )] ); #endif @@ -1118,7 +1120,7 @@ void con_tcx_fx( FOR( i = 0; i < W2; i++ ) { #ifdef BASOP_NOGLOB - hTcxDec->syn_Overl_TDACFB[add( W2, i )] = add_sat( buf[add( W2, i )], buf[sub( sub( sub( W1, 1 ), W2 ), i )] ); + hTcxDec->syn_Overl_TDACFB[( W2 + i )] = add_sat( buf[( W2 + i )], buf[( ( ( W1 - 1 ) - W2 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/ #else hTcxDec->syn_Overl_TDACFB[add( W2, i )] = add( buf[add( W2, i )], buf[sub( sub( sub( W1, 1 ), W2 ), i )] ); #endif @@ -1127,25 +1129,27 @@ void con_tcx_fx( FOR( i = 0; i < W12; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); + hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( ; i < W1; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ); + hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } st->hTcxCfg->tcx_curr_overlap_mode = FULL_OVERLAP; move16(); - synth[-1] = pre_emph_buf; + synth[-1] = pre_emph_buf; /*Q0*/ move16(); /* update memory for low band */ - Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); + Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); /*Q_syn*/ lerp( hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); lerp( hTcxDec->syn_Overl_TDACFB, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); + hTcxDec->Q_syn_Overl_TDAC = hTcxDec->Q_syn_Overl_TDACFB; + move16(); lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, L_frame ); st->old_enr_LP = Enr_1_Az_fx( A_local, L_SUBFR ); /*Q3*/ @@ -1159,10 +1163,10 @@ void con_tcx_ivas_fx( Decoder_State *st, /* i/o: coder memory state */ Word16 synth[], /* i/o: synth[] */ /*Q0 */ - const Word16 coh, /* i : coherence of stereo signal */ - Word16 *noise_seed, /* i/o: noise seed for stereo */ - const Word16 only_left, /* i : TD-PLC only in left channel */ - const Word16 *A_cng /* i : CNG LP filter coefficients */ + const Word16 coh, /* i : coherence of stereo signal Q14*/ + Word16 *noise_seed, /* i/o: noise seed for stereo Q0*/ + const Word16 only_left, /* i : TD-PLC only in left channel Q0*/ + const Word16 *A_cng /* i : CNG LP filter coefficients Q14*/ ) { Word16 i, s, c, L_frame, L_subfr, fLowPassFilter, T0; @@ -1220,16 +1224,16 @@ void con_tcx_ivas_fx( L_frame = hTcxDec->L_frameTCX; move16(); /* L_subfr = st->L_frameTCX/st->nb_subfr */ - L_subfr = mult_r( hTcxDec->L_frameTCX, div_s( 1, st->nb_subfr ) ); + L_subfr = mult_r( hTcxDec->L_frameTCX, div_s( 1, st->nb_subfr ) ); /*Q0*/ assert( L_subfr == hTcxDec->L_frameTCX / st->nb_subfr ); - w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ + w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument Q15*/ W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; move16(); W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 ); W12 = shr( W1, 1 ); /* take the previous frame last pitch */ - Tc = round_fx( st->old_fpitchFB ); + Tc = round_fx( st->old_fpitchFB ); /*Q0*/ set16_fx( buf, 0, OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2 ); /* initialize buf with 0 */ @@ -1242,22 +1246,22 @@ void con_tcx_ivas_fx( FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) { - old_pitch_buf[i] = L_shl( Mpy_32_16_1( st->old_pitch_buf_fx[i], c ), s ); + old_pitch_buf[i] = L_shl( Mpy_32_16_1( st->old_pitch_buf_fx[i], c ), s ); /*Q16*/ move32(); } /* set excitation memory*/ exc = buf + OLD_EXC_SIZE_DEC; - tmp_deemph = synth[-1]; + tmp_deemph = synth[-1]; /*Q0*/ move16(); - pre_emph_buf = synth[-1]; + pre_emph_buf = synth[-1]; /*Q0*/ move16(); test(); IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { /* apply pre-emphasis to the signal */ - mem = synth[sub( -add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), M + M ), 1 )]; + mem = synth[( -( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) - 1 )]; /*Q0*/ move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); st->Mode2_lp_gainc = L_deposit_l( 0 ); @@ -1265,18 +1269,18 @@ void con_tcx_ivas_fx( st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); move32(); - st->Mode2_lp_gainp = L_max( st->Mode2_lp_gainp, 0 ); - st->Mode2_lp_gainp = L_min( st->Mode2_lp_gainp, 65536l /*1.0f Q16*/ ); - st->Mode2_lp_gainp = L_shl( st->Mode2_lp_gainp, 13 ); + st->Mode2_lp_gainp = L_max( st->Mode2_lp_gainp, 0 ); /*Q16*/ + st->Mode2_lp_gainp = L_min( st->Mode2_lp_gainp, 65536l /*1.0f Q16*/ ); /*Q16*/ + st->Mode2_lp_gainp = L_shl( st->Mode2_lp_gainp, 13 ); /*Q29*/ move32(); move32(); move32(); - ana_window = buf; + ana_window = buf; /*Q15*/ ham_cos_window( ana_window, mult( L_frame, 24576 /*0.75f Q15*/ ), shr( L_frame, 2 ) ); /* Autocorrelation */ - autocorr_fx( &( synth[sub( -L_frame, 1 )] ), M, r_h, r_l, &Q_r, L_frame, ana_window, 0, 0 ); + autocorr_fx( &( synth[( -L_frame - 1 )] ), M, r_h, r_l, &Q_r, L_frame, ana_window, 0, 0 ); /* Lag windowing */ lag_wind( r_h, r_l, M, st->output_Fs, LAGW_STRONG ); @@ -1285,7 +1289,7 @@ void con_tcx_ivas_fx( E_LPC_lev_dur( r_h, r_l, A_local, NULL, M, NULL ); /* copy for multiple frame loss */ - Copy( A_local, st->old_Aq_12_8_fx, M + 1 ); + Copy( A_local, st->old_Aq_12_8_fx, M + 1 ); /*Q14*/ /* Residu */ assert( ( 2 * L_subfr + Tc + 1 + M ) <= hTcxDec->old_synth_lenFB ); @@ -1302,20 +1306,20 @@ void con_tcx_ivas_fx( ELSE { /* apply pre-emphasis to the signal */ - mem = synth[sub( -L_frame, 1 )]; + mem = synth[( -L_frame - 1 )]; /*Q0*/ move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); - Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); + Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q14*/ offset = shr( L_frame, 1 ); IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { tmp16 = s_max( Tc - shr( L_frame, 1 ), 0 ); - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ } ELSE { - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-shl( L_subfr, 1 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-( L_subfr * 2 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ } } @@ -1354,9 +1358,9 @@ void con_tcx_ivas_fx( scale_tmp = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) ); /*getInvFrameLen()->9Q6*/ tmp_shift = norm_s( scale_tmp ); - predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); + predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); /*Q16*/ - T0 = round_fx( predPitchLag ); + T0 = round_fx( predPitchLag ); /*Q0*/ test(); test(); @@ -1397,12 +1401,12 @@ void con_tcx_ivas_fx( fLowPassFilter = 0; move16(); - pt_exc = exc + offset; - pt1_exc = pt_exc - Tc; + pt_exc = exc + offset; /*Q_exc*/ + pt1_exc = pt_exc - Tc; /*Q_exc*/ if ( fUseExtrapolatedPitch != 0 ) { - pt_exc = buf; + pt_exc = buf; /*Q_exc*/ } test(); IF( LT_16( st->stab_fac_fx, 32767 /*1.f Q15*/ ) && EQ_16( st->nbLostCmpt, 1 ) ) @@ -1424,7 +1428,7 @@ void con_tcx_ivas_fx( 0 /* 0.0000f Q15*/, pt1_exc[2] ), -1442 /*-0.0440f Q15*/, pt1_exc[3] ), 0 /* 0.0000f Q15*/, pt1_exc[4] ), - 174 /* 0.0053f Q15*/, pt1_exc[5] ); + 174 /* 0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ move16(); pt1_exc++; } @@ -1444,7 +1448,7 @@ void con_tcx_ivas_fx( 590 /* 0.0180f Q15*/, pt1_exc[2] ), -459 /*-0.0140f Q15*/, pt1_exc[3] ), -121 /*-0.0037f Q15*/, pt1_exc[4] ), - -174 /*-0.0053f Q15*/, pt1_exc[5] ); + -174 /*-0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ move16(); pt1_exc++; } @@ -1458,7 +1462,7 @@ void con_tcx_ivas_fx( /* copy the first pitch cycle without low-pass filtering */ FOR( i = 0; i < Tc; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } fLowPassFilter = 1; @@ -1472,7 +1476,7 @@ void con_tcx_ivas_fx( tmp16 = add( sub( L_frame, imult1616( fLowPassFilter, Tc ) ), L_subfr ); FOR( i = 0; i < tmp16; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } @@ -1493,7 +1497,7 @@ void con_tcx_ivas_fx( } ELSE { - set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); + set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); /*Q16*/ } IF( EQ_16( st->nbLostCmpt, 1 ) ) @@ -1501,24 +1505,24 @@ void con_tcx_ivas_fx( pt_exc = exc + L_frame; IF( T0 == 0 ) { - pt1_exc = pt_exc - Tc; + pt1_exc = pt_exc - Tc; /*Q_exc*/ } ELSE { - pt1_exc = pt_exc - T0; + pt1_exc = pt_exc - T0; /*Q_exc*/ } tmp_loop = shr( L_frame, 1 ); FOR( i = 0; i < tmp_loop; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } } if ( fUseExtrapolatedPitch != 0 ) { - st->old_fpitchFB = predPitchLag; + st->old_fpitchFB = predPitchLag; /*Q16*/ move32(); } st->bpf_gain_param = 0; @@ -1580,7 +1584,7 @@ void con_tcx_ivas_fx( #ifdef BASOP_NOGLOB exc[i] = mult_r( exc[i], round_fx_sat( gain32 ) ) /*Q1*/; move16(); - gain32 = L_sub_sat( gain32, step32 ); + gain32 = L_sub_sat( gain32, step32 ); /*Q31*/ #else exc[i] = mult_r( exc[i], round_fx( gain32 ) ) /*Q1*/; move16(); @@ -1589,8 +1593,8 @@ void con_tcx_ivas_fx( } /* update old exc without random part */ - offset = s_max( sub( round_fx( st->old_fpitchFB ), shr( L_frame, 1 ) ), 0 ); - Copy( exc + sub( L_frame, offset ), hTcxDec->old_excFB_fx, add( shr( L_frame, 1 ), offset ) ); + offset = s_max( sub( round_fx( st->old_fpitchFB ), shr( L_frame, 1 ) ), 0 ); /*Q0*/ + Copy( exc + sub( L_frame, offset ), hTcxDec->old_excFB_fx, add( shr( L_frame, 1 ), offset ) ); /*Q_exc*/ /* copy old_exc as 16kHz for acelp decoding */ IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -1598,7 +1602,7 @@ void con_tcx_ivas_fx( } ELSE { - Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); + Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/ lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; @@ -1612,8 +1616,8 @@ void con_tcx_ivas_fx( { calcGainc2_fx( &exc[0], Q_exc, L_subfr, &( st->Mode2_lp_gainc ) ); } - set32_fx( pitch_buf, L_deposit_h( L_SUBFR ), st->nb_subfr ); - /* PLC: calculate damping factor */ + set32_fx( pitch_buf, L_deposit_h( L_SUBFR ), st->nb_subfr ); /*Q16*/ + /* PLC: calculate damping factor */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT alpha = 1.0f; if ( st->element_mode == IVAS_CPE_MDCT && st->nbLostCmpt >= MDCT_ST_PLC_FADEOUT_START_FRAME ) @@ -1641,7 +1645,7 @@ void con_tcx_ivas_fx( Word16 e; tmpSeed1 = *noise_seed; - noise = buf; + noise = buf; /*Q15*/ noise_e = 2; move16(); e = 0; @@ -1649,9 +1653,9 @@ void con_tcx_ivas_fx( alpha_coh = 0; move16(); - IF( NE_16( coh, 16384 ) ) + IF( NE_16( coh, 16384 /*1.0f in Q14*/ ) ) { - alpha_coh = Sqrt16( div_s( sub( 16384, coh ), add( 16384, coh ) ), &e ); + alpha_coh = Sqrt16( div_s( sub( 16384 /*1.0f in Q14*/, coh ), add( 16384 /*1.0f in Q14*/, coh ) ), &e ); /* Q15 - e */ } if ( EQ_16( st->idchan, 1 ) ) { @@ -1684,7 +1688,7 @@ void con_tcx_ivas_fx( ELSE #endif /*IVAS_CODE_CON_TCX*/ { - tmpSeed = st->seed_acelp; + tmpSeed = st->seed_acelp; /*Q0*/ move16(); noise = buf; noise_e = 1; /*set exponent of noise to 1*/ @@ -1694,7 +1698,7 @@ void con_tcx_ivas_fx( FOR( i = 0; i < tmp_loop; i++ ) { Random( &tmpSeed ); - noise[i] = shr( tmpSeed, noise_e ); + noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/ move16(); } st->seed_acelp = tmpSeed; @@ -1704,7 +1708,7 @@ void con_tcx_ivas_fx( FOR( ; i < tmp_loop; i++ ) { Random( &tmpSeed ); - noise[i] = shr( tmpSeed, noise_e ); + noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/ move16(); } } @@ -1728,7 +1732,7 @@ void con_tcx_ivas_fx( { FOR( i = 0; i < L_FIR_FER2; i++ ) { - hp_filt[i] = h_high3_16[i]; + hp_filt[i] = h_high3_16[i]; /*Q15*/ move16(); } } @@ -1736,7 +1740,7 @@ void con_tcx_ivas_fx( { FOR( i = 0; i < L_FIR_FER2; i++ ) { - hp_filt[i] = h_high3_32[i]; + hp_filt[i] = h_high3_32[i]; /*Q15*/ move16(); } } @@ -1757,7 +1761,7 @@ void con_tcx_ivas_fx( move32(); FOR( j = 11; j > 0; j-- ) { - L_tmp2 = L_mac( L_tmp2, noise[add( i, sub( L_FIR_FER2, j ) )], hp_filt[sub( L_FIR_FER2, j )] ); + L_tmp2 = L_mac( L_tmp2, noise[( i + ( L_FIR_FER2 - j ) )], hp_filt[sub( L_FIR_FER2, j )] ); } L_tmp2 = Mpy_32_16_1( L_tmp2, st->cummulative_damping /*Q15*/ ); /*Q0, noise_e*/ noise[i] = mac_r( L_tmp2, gain_tmp, noise[i] ); /*Q15, noise_e*/ @@ -1772,11 +1776,11 @@ void con_tcx_ivas_fx( move16(); IF( A_cng != NULL ) { - gainSynthDeemph = shr( getLevelSynDeemph_fx( &( tmp16 ), A_cng, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ), 2 ); + gainSynthDeemph = shr( getLevelSynDeemph_fx( &( tmp16 ), A_cng, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ), 2 ); /*Q13*/ } ELSE { - gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); + gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); /*Q13*/ } #else tmp16 = 32767; @@ -1803,7 +1807,7 @@ void con_tcx_ivas_fx( { // gainCNG *= 1.f - (float)(st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN; L_tmp = L_sub( ONE_IN_Q31, imult3216( 107374182 /* 1 / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN in Q31*/, sub( st->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) ) ); /* Q31 */ - gainCNG = extract_l( Mpy_32_32( gainCNG, L_tmp ) ); + gainCNG = extract_l( Mpy_32_32( gainCNG, L_tmp ) ); /*Q15-gainCNG_e*/ } } #endif @@ -1820,9 +1824,9 @@ void con_tcx_ivas_fx( gain32 = L_add( st->Mode2_lp_gainc, 0 ); /* start-of-the-frame gain - Q16*/ IF( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) { - gain32 = Mpy_32_16_1( gain32, 22938 /*0.7f Q15*/ ); + gain32 = Mpy_32_16_1( gain32, 22938 /*0.7f Q15*/ ); /*Q16*/ } - L_tmp = L_shl( gain32, 1 ); + L_tmp = L_shl( gain32, 1 ); /*Q16*/ IF( GT_32( L_shl( L_deposit_h( gainCNG ), sub( gainCNG_e, 31 - 16 ) /*Q16*/ ), L_tmp ) ) { @@ -1835,8 +1839,8 @@ void con_tcx_ivas_fx( L_tmp = Mpy_32_16_1( st->Mode2_lp_gainc, alpha ) /*Q15*/; L_tmp2 = L_mult( sub( 16384 /*1.f Q14*/, alpha ) /*Q14*/, gainCNG /*Q15,gainCNG_e*/ ); /*Q30,gainCNG_e*/ - st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp( L_tmp, 31 - 15, L_tmp2, add( gainCNG_e, 31 - 30 ), &tmp_e ); /*Q31*/ - st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) ); + st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp( L_tmp, 31 - 15, L_tmp2, add( gainCNG_e, 31 - 30 ), &tmp_e ); /*Q31-tmp_e*/ + st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) ); /*Q16*/ move32(); move32(); @@ -1869,7 +1873,7 @@ void con_tcx_ivas_fx( test(); IF( EQ_16( st->last_good, UNVOICED_CLAS ) && NE_16( st->core_ext_mode, UNVOICED ) ) { - gain_inov = mult_r( gain_inov, 26214 /*0.8f Q15*/ ); + gain_inov = mult_r( gain_inov, 26214 /*0.8f Q15*/ ); /*Q30*/ } ELSE IF( !( EQ_16( st->last_good, UNVOICED_CLAS ) || EQ_16( st->last_good, UNVOICED_TRANSITION ) ) ) { @@ -1903,7 +1907,7 @@ void con_tcx_ivas_fx( step32_tmp = L_shl( step32 /*Q25*/, sub( tmp_e, 25 - 16 ) ); /*Q16,-tmp_e*/ FOR( i = 0; i < tmp16; i++ ) /* Actual filtered random part of excitation */ { - *pt_exc = mult_r( *pt_exc, gain_tmp ); + *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/ move16(); pt_exc++; gain32 = L_sub( gain32 /*Q16,-tmp_e*/, step32_tmp ); /*Q16,-tmp_e*/ @@ -1912,7 +1916,7 @@ void con_tcx_ivas_fx( tmp16 = shr( L_frame, 1 ); FOR( i = 0; i < tmp16; i++ ) /* causal ringing of the FIR filter */ { - *pt_exc = mult_r( *pt_exc, gain_tmp ); + *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/ move16(); pt_exc++; } @@ -1940,7 +1944,7 @@ void con_tcx_ivas_fx( ELSE { bufferCopyFx( noise + L_FIR_FER2 / 2, exc, add( L_frame, shr( L_frame, 1 ) ), 0 /*Q_noise*/, noise_e, Q_exc, 0 /*exc_e*/ ); - Copy( exc + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); + Copy( exc + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); /*Q_exc*/ /* copy old_exc as 16kHz for acelp decoding */ IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -1948,7 +1952,7 @@ void con_tcx_ivas_fx( } ELSE { - Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); + Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/ lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; @@ -1958,15 +1962,15 @@ void con_tcx_ivas_fx( /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1*/ /* Update Pitch Lag memory */ - Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); - Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); + Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); /*Q16*/ + Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); /*Q16*/ /*----------------------------------------------------------* * - compute the synthesis speech * *----------------------------------------------------------*/ - syn = buf + M; - Copy( synth - M, buf, M ); + syn = buf + M; /*Q_syn*/ + Copy( synth - M, buf, M ); /*Q_syn*/ new_Q = sub( Q_exc, 3 ); new_Q = s_max( new_Q, -1 ); @@ -1980,7 +1984,7 @@ void con_tcx_ivas_fx( Q_syn = tmp16; move16(); - Copy_Scale_sig( buf, mem_syn, M, exp_scale ); + Copy_Scale_sig( buf, mem_syn, M, exp_scale ); /* Q: tmp16 */ #ifdef BASOP_NOGLOB tmp_deemph = shl_sat( tmp_deemph, Q_syn ); @@ -1997,11 +2001,11 @@ void con_tcx_ivas_fx( { Word16 alpha_delayed; - alpha_delayed = 16384; + alpha_delayed = 16384; /*1.0f in Q14*/ move16(); IF( GT_16( st->nbLostCmpt, MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE ) ) { - alpha_delayed = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE, st->last_good, st->stab_fac_fx, &( st->Mode2_lp_gainp ), ACELP_CORE ); + alpha_delayed = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE, st->last_good, st->stab_fac_fx, &( st->Mode2_lp_gainp ), ACELP_CORE ); /*Q14*/ } test(); @@ -2009,13 +2013,13 @@ void con_tcx_ivas_fx( { Word16 lsp_local[M], lsp_fade[M], alpha_inv; - alpha_inv = sub( 16384, alpha_delayed ); + alpha_inv = sub( 16384 /*Q.0f in Q14*/, alpha_delayed ); /*Q14*/ E_LPC_a_lsp_conversion( A_local, lsp_local, lsp_local, M ); FOR( i = 0; i < M; i++ ) { - lsp_fade[i] = add( mult_r( alpha_delayed, lsp_local[i] ), mult_r( alpha_inv, st->lspold_cng[i] ) ); + lsp_fade[i] = add( mult_r( alpha_delayed, lsp_local[i] ), mult_r( alpha_inv, st->lspold_cng[i] ) ); /*Q14*/ move16(); } @@ -2039,37 +2043,37 @@ void con_tcx_ivas_fx( /*buf[0;M-1] Q0: mem_syn*/ /*buf[M;3/2 L_frame-1] Q-1: syn*/ - n = extract_h( L_mult( L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); + n = extract_h( L_mult( L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); /*Q0*/ /* update ACELP synthesis memory */ mem_syn_r_size_old = shr( L_frame, 4 ); /* replace 1.25/20.0 by shr(4) */ /* copy mem_syn as 16kHz */ mem_syn_r_size_new = shr( L_FRAME16k, 4 ); /* replace 1.25/20.0 by shr(4) */ - Copy( syn + sub( L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); + Copy( syn + sub( L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); /*Q_syn*/ lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); + Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /*Q_syn*/ /* Deemphasis and output synth and ZIR */ deemph_fx( syn, st->preemph_fac, add( L_frame, shr( L_frame, 1 ) ), &tmp_deemph ); - bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); + bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); /*Q_syn*/ lerp( syn + sub( L_frame, shr( L_frame, 1 ) ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); - Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); + Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); /*Q_syn*/ FOR( i = 0; i < W12; i++ ) { - hHQ_core->old_out_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[add( i, n )] ) ); + hHQ_core->old_out_fx[( i + n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[( i + n )] ) ); /*Q_syn*/ move16(); } FOR( ; i < W1; i++ ) { - hHQ_core->old_out_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im, w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ), hHQ_core->old_out_fx[add( i, n )] ) ); + hHQ_core->old_out_fx[( i + n )] = round_fx( Mpy_32_16_1( L_mult( w[( ( W12 - 1 ) - ( i - W12 ) )].v.im, w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ), hHQ_core->old_out_fx[( i + n )] ) ); /*Q_syn*/ move16(); } - set16_fx( &hHQ_core->old_out_fx[add( W1, n )], 0, n ); + set16_fx( &hHQ_core->old_out_fx[( W1 + n )], 0, n ); hHQ_core->Q_old_wtda = Q_syn; move16(); @@ -2077,10 +2081,10 @@ void con_tcx_ivas_fx( /* As long as there is no synth scaling factor introduced, which is given to the outside, there might occur overflows here */ BASOP_SATURATE_WARNING_OFF_EVS - bufferCopyFx( syn, synth, L_frame, Q_syn, 0, 0, 0 ); + bufferCopyFx( syn, synth, L_frame, Q_syn, 0, 0, 0 ); /*Q_syn*/ BASOP_SATURATE_WARNING_ON_EVS - Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), negate( Q_syn ) ); + Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), negate( Q_syn ) ); /*Q0*/ /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ IF( st->hWIDec != NULL ) @@ -2100,54 +2104,58 @@ void con_tcx_ivas_fx( /* create aliasing and windowing need for transition to TCX10/5 */ bufferCopyFx( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ), Q_syn, 0, -1, 0 ); + hTcxDec->Q_syn_Overl_TDACFB = add( Q_syn, sub( Q_syn, -1 ) ); + move16(); FOR( i = 0; i < W12; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( ; i < W1; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( i = 0; i < W2; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[sub( sub( W1, 1 ), i )] ); + hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[( ( W1 - 1 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( i = 0; i < W2; i++ ) { - hTcxDec->syn_Overl_TDACFB[add( W2, i )] = add_sat( buf[add( W2, i )], buf[sub( sub( sub( W1, 1 ), W2 ), i )] ); + hTcxDec->syn_Overl_TDACFB[( W2 + i )] = add_sat( buf[( W2 + i )], buf[( ( ( W1 - 1 ) - W2 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( i = 0; i < W12; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); + hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( ; i < W1; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ); + hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } st->hTcxCfg->tcx_curr_overlap_mode = FULL_OVERLAP; move16(); - synth[-1] = pre_emph_buf; + synth[-1] = pre_emph_buf; /*Q0*/ move16(); /* update memory for low band */ st->Q_syn = 0; move16(); - Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); + Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); /*Q_syn*/ lerp( hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); lerp( hTcxDec->syn_Overl_TDACFB, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); + hTcxDec->Q_syn_Overl_TDAC = hTcxDec->Q_syn_Overl_TDACFB; + move16(); lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, L_frame ); st->old_enr_LP = Enr_1_Az_fx( A_local, L_SUBFR ); /*Q3*/ diff --git a/lib_dec/er_scale_syn_fx.c b/lib_dec/er_scale_syn_fx.c index 2e5746ccfd530b7eaf6c65008bb1e9f32acd8a4a..509fd071b44840d14cfb1fb70afb28cbf4c0ea9c 100644 --- a/lib_dec/er_scale_syn_fx.c +++ b/lib_dec/er_scale_syn_fx.c @@ -57,8 +57,8 @@ Word16 Damping_fact_fx( /* o : damping factor IF( EQ_16( nbLostCmpt, 1 ) ) { /* If stable, do not decrease the energy, pitch gain = 0 */ - /* * (1.0f - 2.0f*_ALPHA_U_FX) + 2.0f*MODE2_ALPHA_U; */ /* [0.8, 1.0] */ - alpha = add( mult_r( stab_fac, sub( 16384, _ALPHA_U_FX ) ), _ALPHA_U_FX ); + /* * (1.0f - 2.0f*_ALPHA_U_FX) + 2.0f*MODE2_ALPHA_U; */ /* [0.8, 1.0] */ + alpha = add( mult_r( stab_fac, sub( 16384, _ALPHA_U_FX ) ), _ALPHA_U_FX ); /*Q14*/ } ELSE IF( EQ_16( nbLostCmpt, 2 ) ) { @@ -67,7 +67,7 @@ Word16 Damping_fact_fx( /* o : damping factor } ELSE { - alpha = mult_r( _ALPHA_U_FX, 16384 ); /*Q14*/ /* 0.4 go rapidly to CNG gain, pitch gain = 0 */ + alpha = mult_r( _ALPHA_U_FX, 16384 ); /*Q14*/ /* 0.4 go rapidly to CNG gain, pitch gain = 0 Q14*/ } } ELSE IF( EQ_16( last_good, UNVOICED_TRANSITION ) ) @@ -80,12 +80,12 @@ Word16 Damping_fact_fx( /* o : damping factor } ELSE IF( ( ( EQ_16( last_good, VOICED_CLAS ) ) || ( EQ_16( last_good, ONSET ) ) ) && ( LE_16( nbLostCmpt, 3 ) ) ) { - alpha = mult_r( _ALPHA_V_FX, 16384 ); /* constant for the first 3 erased frames */ + alpha = mult_r( _ALPHA_V_FX, 16384 ); /* constant for the first 3 erased frames Q14*/ } IF( GE_16( last_good, VOICED_CLAS ) ) { - lp_tmp = *lp_gainp; + lp_tmp = *lp_gainp; /*Q29*/ move32(); IF( EQ_16( nbLostCmpt, 1 ) ) /* if first erased frame in a block, reset harmonic gain */ @@ -96,7 +96,7 @@ Word16 Damping_fact_fx( /* o : damping factor /*BASOP_Util_Sqrt_MantExp(lp_gainp,&lp_gainp_E);*/ s_gainp = 31 - 29; move16(); - gain32 = Sqrt32( lp_tmp, &s_gainp ); + gain32 = Sqrt32( lp_tmp, &s_gainp ); /*Q31-s_gainp*/ #ifdef BASOP_NOGLOB gain = round_fx_o( L_shl_o( gain32, s_gainp, &Overflow ), &Overflow ); /* Q15*/ @@ -110,7 +110,7 @@ Word16 Damping_fact_fx( /* o : damping factor ELSE IF( EQ_16( nbLostCmpt, 2 ) ) { /*0.6 + 0.35*stab_fac*/ - alpha = mult_r( mac_r( 1288490240l /*0.6f Q31*/, 11469 /*0.35f Q15*/, stab_fac ), round_fx( L_shl( lp_tmp, 1 ) ) ); + alpha = mult_r( mac_r( 1288490240l /*0.6f Q31*/, 11469 /*0.35f Q15*/, stab_fac ), round_fx( L_shl( lp_tmp, 1 ) ) ); /*Q14*/ } ELSE { @@ -118,7 +118,7 @@ Word16 Damping_fact_fx( /* o : damping factor lp_tmp = Mpy_32_16_1( lp_tmp, mac_r( 1503238528l /*0.7f Q31*/, 6554 /*0.2f Q15*/, stab_fac ) ); /*2Q29*/ alpha = round_fx( L_shl( lp_tmp, 1 ) ); /*1Q14*/ } - *lp_gainp = lp_tmp; /*store*/ + *lp_gainp = lp_tmp; /*store Q29*/ move32(); } } diff --git a/lib_dec/er_sync_exc_fx.c b/lib_dec/er_sync_exc_fx.c index 2684768215bc2fc55a325110fc0ae6ef676b207a..ac04d048cf7389db13044db3503453df5dfd3b57 100644 --- a/lib_dec/er_sync_exc_fx.c +++ b/lib_dec/er_sync_exc_fx.c @@ -36,9 +36,9 @@ static Word16 GetMinimumPosition_fx( move16(); #endif - filterLength = s_min( filterLength, length ); - center = shr( filterLength, 1 ); - iMinEnergyPos = center; + filterLength = s_min( filterLength, length ); /*Q0*/ + center = shr( filterLength, 1 ); /*Q0*/ + iMinEnergyPos = center; /*Q0*/ move16(); IF( filterLength > 0 ) @@ -47,22 +47,22 @@ static Word16 GetMinimumPosition_fx( energy = L_deposit_l( 0 ); energy_old = L_deposit_l( 0 ); - cnt = sub( length, filterLength ); + cnt = sub( length, filterLength ); /*Q0*/ tmp_e = 0; move16(); FOR( i = 0; i < cnt; i++ ) { - tmp16 = shr( x[i], tmp_e ); + tmp16 = shr( x[i], tmp_e ); /*Qx*/ #ifdef BASOP_NOGLOB - energy = L_msu_sat( energy_old, tmp16, tmp16 ); + energy = L_msu_sat( energy_old, tmp16, tmp16 ); /*2Qx+1*/ #else energy = L_msu( energy_old, tmp16, tmp16 ); #endif - tmp16 = shr( x[add( i, filterLength )], tmp_e ); - BASOP_SATURATE_WARNING_OFF_EVS /*Saturation will be handled*/ + tmp16 = shr( x[( i + filterLength )], tmp_e ); /*Qx*/ + BASOP_SATURATE_WARNING_OFF_EVS /*Saturation will be handled*/ #ifdef BASOP_NOGLOB - energy = L_mac_sat( energy, tmp16, tmp16 ); + energy = L_mac_sat( energy, tmp16, tmp16 ); /*2Qx+1*/ #else energy = L_mac( energy, tmp16, tmp16 ); #endif @@ -71,7 +71,7 @@ static Word16 GetMinimumPosition_fx( /*if (energy == MAXVAL_WORD32)*/ BASOP_SATURATE_WARNING_OFF_EVS /*saturates if energy < 0*/ #ifdef BASOP_NOGLOB - tmptest = L_sub_o( energy, MAXVAL_WORD32, &Overflow ); + tmptest = L_sub_o( energy, MAXVAL_WORD32, &Overflow ); /*Q31*/ #else tmptest = L_sub( energy, MAXVAL_WORD32 ); #endif @@ -80,15 +80,15 @@ static Word16 GetMinimumPosition_fx( { tmp_e = add( tmp_e, 1 ); energy = L_shr( energy_old, 2 ); - tmp16 = shr( x[i], tmp_e ); - energy = L_msu( energy, tmp16, tmp16 ); - tmp16 = shr( x[add( i, filterLength )], tmp_e ); - energy = L_mac( energy, tmp16, tmp16 ); + tmp16 = shr( x[i], tmp_e ); /*Qx-1*/ + energy = L_msu( energy, tmp16, tmp16 ); /*2Qx-1*/ + tmp16 = shr( x[( i - filterLength )], tmp_e ); + energy = L_mac( energy, tmp16, tmp16 ); /*2Qx-1*/ } IF( energy < 0 ) { - iMinEnergyPos = add( i, center ); + iMinEnergyPos = add( i, center ); /*Q0*/ tmp_e = 0; move16(); energy = 0; @@ -98,7 +98,7 @@ static Word16 GetMinimumPosition_fx( } } - return iMinEnergyPos; + return iMinEnergyPos; /*Q0*/ } /*! @@ -108,7 +108,7 @@ static Word16 GetMinimumPosition_fx( */ static Word16 FindMaxPeak_fx( - Word16 /*float*/ const *x, /* 0; j-- ) { - *pt_dest++ = *pt_src++; + *pt_dest++ = *pt_src++; /*Qx*/ move16(); } /* Add some samples */ - ftmp = negate( mult( *pt_src, 1638 /*.05f Q15*/ ) ); + ftmp = negate( mult( *pt_src, 1638 /*.05f Q15*/ ) ); /*Qx*/ FOR( j = 0; j < points_by_pos[i]; j++ ) { - *pt_dest++ = ftmp; + *pt_dest++ = ftmp; /*Qx*/ move16(); - ftmp = negate( ftmp ); + ftmp = negate( ftmp ); /*Qx*/ } /* Prepare for the next loop iteration */ - last_min_pos = min_pos[i]; + last_min_pos = min_pos[i]; /*Q0*/ move16(); } /* Copy remaining length */ FOR( j = sub( L_frame, add( n_samples_to_add, last_min_pos ) ); j > 0; j-- ) { - *pt_dest++ = *pt_src++; + *pt_dest++ = *pt_src++; /*Qx*/ move16(); } } @@ -192,30 +192,30 @@ static void RemoveSamples_fx( Word16 /*int*/ last_min_pos, i, j; - pt_dest = new_exc + L_frame; - last_min_pos = sub( L_frame, n_samples_to_add ); + pt_dest = new_exc + L_frame; /*Qx*/ + last_min_pos = sub( L_frame, n_samples_to_add ); /*Q0*/ FOR( i = sub( nb_min, 1 ); i >= 0; i-- ) { /* Compute len to copy */ /* Copy section, removing some samples */ - pt_src = old_exc + last_min_pos; + pt_src = old_exc + last_min_pos; /*Qx*/ FOR( j = sub( last_min_pos, add( min_pos[i], points_by_pos[i] ) ); j > 0; j-- ) { - *--pt_dest = *--pt_src; + *--pt_dest = *--pt_src; /*Qx*/ move16(); } /* Prepare for the next loop iteration */ - last_min_pos = min_pos[i]; + last_min_pos = min_pos[i]; /*Q0*/ move16(); } /* Copy remaining length */ - pt_src = old_exc + last_min_pos; + pt_src = old_exc + last_min_pos; /*Qx*/ FOR( j = last_min_pos; j > 0; j-- ) { - *--pt_dest = *--pt_src; + *--pt_dest = *--pt_src; /*Qx*/ move16(); } } @@ -258,7 +258,7 @@ void PulseResynchronization_fx( test(); IF( src_exc != dst_exc && LE_16( nFrameLength, 1200 ) ) { - Copy( src_exc, dst_exc, nFrameLength ); + Copy( src_exc, dst_exc, nFrameLength ); /*Q15*/ } return; } @@ -282,7 +282,7 @@ void PulseResynchronization_fx( tmp16 = shl( tmp16, tmp_e ); /*Q0,-tmp_e*/ /*tmp16=roundedPitchStart*nSubframes*/ tmp_e = sub( 15, tmp_e ); tmp16 = Inv16( tmp16, &tmp_e ); /*Q15,tmp_e*/ /*tmp16=1.0/(roundedPitchStart*nSubframes)*/ - tmp32 = L_sub( pitchEnd, pitchStart ); + tmp32 = L_sub( pitchEnd, pitchStart ); /*Q16*/ tmp2_e = norm_l( tmp32 ); tmp32 = L_shl( tmp32, tmp2_e ); /*Q16,-tmp2_e*/ tmp32 = Mpy_32_16_1( tmp32, tmp16 ); /*Q16,tmp_e-tmp2_e*/ /*tmp32=pitchDelta*freqStart*/ @@ -290,7 +290,7 @@ void PulseResynchronization_fx( tmp16 = imult1616( nFrameLength, add( nSubframes, 1 ) ); /*Q0*/ /*tmp16=nFrameLength*(nSubframes+1)*/ tmp2_e = norm_s( tmp16 ); - tmp16 = shl( tmp16, tmp2_e ); + tmp16 = shl( tmp16, tmp2_e ); /*Q0+tmp2_e*/ tmp32 = Mpy_32_16_1( tmp32, tmp16 ); /*Q1 scaling (tmp_e-tmp2_e-1), -1 because of 0.5f*/ /*tmp32=0.5f*pitchDelta*nFrameLength*(nSubframes+1)*freqStart*/ tmp_e = sub( sub( tmp_e, tmp2_e ), 1 ); /* sum up all the scalings for tmp32 */ @@ -298,7 +298,7 @@ void PulseResynchronization_fx( /*samplesDelta -= nFrameLength*(1.0f-pitchStart*freqStart);*/ tmp2_e = norm_l( pitchStart ); - tmp32_a = L_shl( pitchStart, tmp2_e ); + tmp32_a = L_shl( pitchStart, tmp2_e ); /*Q16+tmp2_e*/ tmp32_a = Mpy_32_16_1( tmp32_a /*Q16,-tmp2_e*/, freqStart /*Q15,freqStart_e*/ ); /*Q16, scaling (freqStart_e-tmp2_e)*/ /*tmp32_a=pitchStart*freqStart*/ tmp16 = norm_l( tmp32_a ); tmp32_a = L_shl( tmp32_a, tmp16 ); @@ -314,7 +314,7 @@ void PulseResynchronization_fx( tmp32_a = L_add( L_shl( 1, sub( 31, tmp3_e ) ), tmp32_a ); /*Q31,tmp3_e*/ /*tmp32_a= 1.0f-pitchStart*freqStart*/ #endif tmp2_e = norm_s( nFrameLength ); - tmp16_a = shl( nFrameLength, tmp2_e ); + tmp16_a = shl( nFrameLength, tmp2_e ); /*Q0+tmp2_e*/ tmp32_a = Mpy_32_16_1( tmp32_a /*Q31,tmp3_e*/, tmp16_a /*Q0,-tmp2_e*/ ); /*Q16,tmp3_e-tmp2_e*/ /*tmp32_a= nFrameLength*(1.0f-pitchStart*freqStart)*/ tmp2_e = add( sub( tmp3_e, tmp2_e ), 15 ); samplesDelta = BASOP_Util_Add_Mant32Exp( tmp32, tmp_e, L_negate( tmp32_a ), tmp2_e, &samplesDelta_e ); /*Q31,samplesDelta_e*/ @@ -346,7 +346,7 @@ void PulseResynchronization_fx( tmp32 = L_shl( tmp32, tmp2_e ); tmp_e = sub( tmp_e, tmp2_e ); /*tmp32 = Q31,tmp_e*/ tmp2_e = norm_l( absPitchDiff ); - tmp32_b = L_shl( absPitchDiff, tmp2_e ); + tmp32_b = L_shl( absPitchDiff, tmp2_e ); /*Q16+tmp2_e*/ tmp_e = sub( tmp_e, tmp2_e ); tmp32 = Mpy_32_16_1( tmp32_b, round_fx( tmp32 ) ); /*Q16,tmp_e*/ /*tmp32 = absPitchDiff*(nFrameLength-samplesDelta)*/ tmp32_a = Mpy_32_16_1( L_abs( samplesDelta ) /*Q31,samplesDelta_e*/, roundedPitchStart /*Q0*/ ); /*Q16,samplesDelta_e*/ /*tmp32_a=fabs(samplesDelta)*roundedPitchStart*/ @@ -412,33 +412,33 @@ void PulseResynchronization_fx( /* Make sure that the number of samples increases */ IF( GT_32( L_deposit_h( roundedCycleDelta ), cycleDelta32 ) ) { - iDeltaSamples[i] = roundedCycleDelta; + iDeltaSamples[i] = roundedCycleDelta; /*Q0*/ move16(); - roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here */ - iDeltaSamples[i - 1] = roundedCycleDelta; + roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here Q0*/ + iDeltaSamples[i - 1] = roundedCycleDelta; /*Q0*/ move16(); } ELSE { - roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here */ - iDeltaSamples[i] = roundedCycleDelta; + roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here Q0*/ + iDeltaSamples[i] = roundedCycleDelta; /*Q0*/ move16(); } /*fractionalLeft = cycleDelta-roundedCycleDelta = cycleDelta-(int)cycleDelta;*/ fractionalLeft = lshr( extract_l( cycleDelta32 ), 1 ); /*Q15*/ /* cycleDelta32 should never be < 0 here */ nSamplesDeltaRemain = sub( nSamplesDeltaRemain, roundedCycleDelta ); } - iDeltaSamples[add( k, 1 )] = s_max( 0, nSamplesDeltaRemain ); + iDeltaSamples[( k + 1 )] = s_max( 0, nSamplesDeltaRemain ); move16(); - maxDeltaSamples = s_max( iDeltaSamples[k], iDeltaSamples[add( k, 1 )] ); /*Q0*/ + maxDeltaSamples = s_max( iDeltaSamples[k], iDeltaSamples[( k + 1 )] ); /*Q0*/ /* Find the location of the minimum energy between the first two pulses */ /*iMinPos1 = T0+GetMinimumPosition_fx(src_exc+T0, min(roundedPitchStart, (nSubframes+1)*nFrameLength/nSubframes-T0), maxDeltaSamples);*/ BASOP_Util_Divide_MantExp( add( nSubframes, 1 ), 15, nSubframes, 15, &tmp16, &tmp_e ); tmp32 = L_mult( nFrameLength /*Q0*/, tmp16 /*Q15,tmp_e*/ ); /*Q16,tmp_e*/ - tmp16 = round_fx( L_shl( tmp32, tmp_e ) ); - tmp16 = sub( tmp16, T0 ); + tmp16 = round_fx( L_shl( tmp32, tmp_e ) ); /*Q0*/ + tmp16 = sub( tmp16, T0 ); /*Q0*/ tmp16 = s_min( roundedPitchStart, tmp16 ); iMinPos1 = GetMinimumPosition_fx( @@ -455,26 +455,26 @@ void PulseResynchronization_fx( IF( GT_16( iMinPos1, add( roundedPitchStart, shr( iDeltaSamples[0], 1 ) ) ) ) { - iMinPos[0] = sub( iMinPos1, sub( roundedPitchStart, shr( iDeltaSamples[0], 1 ) ) ); + iMinPos[0] = sub( iMinPos1, sub( roundedPitchStart, shr( iDeltaSamples[0], 1 ) ) ); /*Q0*/ move16(); } ELSE { - iMinPos[0] = sub( GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ), shr( iDeltaSamples[0], 1 ) ); + iMinPos[0] = sub( GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ), shr( iDeltaSamples[0], 1 ) ); /*Q0*/ move16(); } /* Find the location of the minimum energy between the pulses */ FOR( i = 1; i <= k; i++ ) { - iMinPos[i] = add( iMinPos1, sub( imult1616( sub( i, 1 ), roundedPitchStart ), shr( iDeltaSamples[i], 1 ) ) ); + iMinPos[i] = add( iMinPos1, sub( imult1616( sub( i, 1 ), roundedPitchStart ), shr( iDeltaSamples[i], 1 ) ) ); /*Q0*/ move16(); } /* Find the location of the minimum energy after the last pulse */ - IF( LT_16( add( iMinPos1, add( imult1616( k, roundedPitchStart ), sub( iDeltaSamples[add( k, 1 )], shr( iDeltaSamples[add( k, 1 )], 1 ) ) ) ), sub( nFrameLength, nSamplesDelta ) ) ) + IF( LT_16( add( iMinPos1, add( imult1616( k, roundedPitchStart ), sub( iDeltaSamples[( k + 1 )], shr( iDeltaSamples[( k + 1 )], 1 ) ) ) ), sub( nFrameLength, nSamplesDelta ) ) ) { - iMinPos[add( k, 1 )] = add( iMinPos1, sub( imult1616( k, roundedPitchStart ), shr( iDeltaSamples[add( k, 1 )], 1 ) ) ); + iMinPos[( k + 1 )] = add( iMinPos1, sub( imult1616( k, roundedPitchStart ), shr( iDeltaSamples[( k + 1 )], 1 ) ) ); /*Q0*/ move16(); } ELSE @@ -482,18 +482,18 @@ void PulseResynchronization_fx( /*iMinPos[k+1] = T0+k*roundedPitchStart + GetMinimumPosition_fx(src_exc+T0+k*roundedPitchStart, nFrameLength-nSamplesDelta-(T0+k*roundedPitchStart), iDeltaSamples[k+1]) - iDeltaSamples[k+1]/2; */ - tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[add( k, 1 )] ); + tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[( k + 1 )] ); /*Q0*/ tmp16 = add( add( T0, imult1616( k, roundedPitchStart ) ), tmp16 ); - tmp16 = sub( tmp16, shr( iDeltaSamples[add( k, 1 )], 1 ) ); - iMinPos[add( k, 1 )] = tmp16; + tmp16 = sub( tmp16, shr( iDeltaSamples[( k + 1 )], 1 ) ); + iMinPos[( k + 1 )] = tmp16; move16(); } - IF( GT_16( add( iMinPos[add( k, 1 )], iDeltaSamples[add( k, 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) + IF( GT_16( add( iMinPos[( k + 1 )], iDeltaSamples[( k + 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) { - iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[add( k, 1 )], sub( iDeltaSamples[add( k, 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); + iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[( k + 1 )], sub( iDeltaSamples[( k + 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); /*Q0*/ move16(); - iDeltaSamples[add( k, 1 )] = sub( nFrameLength, add( nSamplesDelta, iMinPos[add( k, 1 )] ) ); + iDeltaSamples[( k + 1 )] = sub( nFrameLength, add( nSamplesDelta, iMinPos[( k + 1 )] ) ); /*Q0*/ move16(); } @@ -505,43 +505,43 @@ void PulseResynchronization_fx( /* Find the location of the minimum energy before the first pulse */ IF( GT_16( iMinPos1, roundedPitchStart ) ) { - iMinPos[0] = sub( iMinPos1, roundedPitchStart ); + iMinPos[0] = sub( iMinPos1, roundedPitchStart ); /*Q0*/ move16(); } ELSE { - iMinPos[0] = GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ); + iMinPos[0] = GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ); /*Q0*/ move16(); } /* Find the location of the minimum energy between the pulses */ FOR( i = 1; i <= k; i++ ) { - iMinPos[i] = iMinPos1; + iMinPos[i] = iMinPos1; /*Q0*/ move16(); - iMinPos1 = add( iMinPos1, roundedPitchStart ); + iMinPos1 = add( iMinPos1, roundedPitchStart ); /*Q0*/ } /* Find the location of the minimum energy after the last pulse */ IF( LT_16( iMinPos1, sub( nFrameLength, nSamplesDelta ) ) ) { - iMinPos[add( k, 1 )] = iMinPos1; + iMinPos[( k + 1 )] = iMinPos1; move16(); } ELSE { - tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[add( k, 1 )] ); + tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[( k + 1 )] ); /*Q0*/ tmp16 = add( add( tmp16, T0 ), imult1616( k, roundedPitchStart ) ); - iMinPos[add( k, 1 )] = tmp16; + iMinPos[( k + 1 )] = tmp16; /*Q0*/ move16(); } - IF( GT_16( add( iMinPos[add( k, 1 )], iDeltaSamples[add( k, 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) + IF( GT_16( add( iMinPos[( k + 1 )], iDeltaSamples[( k + 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) { - iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[add( k, 1 )], sub( iDeltaSamples[add( k, 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); + iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[( k + 1 )], sub( iDeltaSamples[( k + 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); /*Q0*/ move16(); - iDeltaSamples[add( k, 1 )] = sub( sub( nFrameLength, nSamplesDelta ), iMinPos[add( k, 1 )] ); + iDeltaSamples[( k + 1 )] = sub( sub( nFrameLength, nSamplesDelta ), iMinPos[( k + 1 )] ); /*Q0*/ move16(); } /* Add samples at the given positions */ diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index cc6a53cd2a541dc620458b710db8f5ed6b4b278a..c2c766d9e91c64d30e37344ac9b310741712d214 100644 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -61,7 +61,7 @@ void minimumStatistics_fx( #endif { BASOP_SATURATE_WARNING_ON_EVS - currentFrameLevel = PLC_MIN_CNG_LEV; + currentFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/ move16(); currentFrameLevel_e = 0; move16(); @@ -73,13 +73,13 @@ void minimumStatistics_fx( IF( tmp >= 0 ) { /* aOpt = *noiseEstimate / *lastFrameLevel; */ - aOpt = BASOP_Util_Divide1616_Scale( *noiseEstimate, *lastFrameLevel, &aOpt_e ); + aOpt = BASOP_Util_Divide1616_Scale( *noiseEstimate, *lastFrameLevel, &aOpt_e ); /*Q16-aOpt_e*/ aOpt_e = add( aOpt_e, sub( noiseEstimate_e, *lastFrameLevel_e ) ); } ELSE { /* aOpt = *lastFrameLevel / *noiseEstimate; */ - aOpt = BASOP_Util_Divide1616_Scale( *lastFrameLevel, *noiseEstimate, &aOpt_e ); + aOpt = BASOP_Util_Divide1616_Scale( *lastFrameLevel, *noiseEstimate, &aOpt_e ); /*Q16-aOpt_e*/ aOpt_e = add( aOpt_e, sub( *lastFrameLevel_e, noiseEstimate_e ) ); } aOpt = mult_r( aOpt, aOpt ); /* Q15 */ @@ -90,7 +90,7 @@ void minimumStatistics_fx( move16(); } - *lastFrameLevel = currentFrameLevel; + *lastFrameLevel = currentFrameLevel; /*Qx*/ move16(); *lastFrameLevel_e = currentFrameLevel_e; move16(); @@ -100,7 +100,7 @@ void minimumStatistics_fx( move16(); if ( tmp == 0 ) { - tmp = PLC_MIN_STAT_BUFF_SIZE; + tmp = PLC_MIN_STAT_BUFF_SIZE; /*Q0*/ move16(); } /*f = msu_r(L_mult(aOpt, noiseLevelMemory[sub(tmp, 1)]), add(aOpt, 0x8000), currentFrameLevel);*/ @@ -128,7 +128,7 @@ void minimumStatistics_fx( assert( f >= 0 ); /* if current frame min is a new local min, set index to current index */ - p = *noiseLevelIndex; + p = *noiseLevelIndex; /*Q0*/ move16(); tmp2 = BASOP_Util_Add_MantExp( noiseLevelMemory[p], noiseLevelMemory_e[p], negate( f ), *new_noiseEstimate_e, &tmp ); IF( tmp >= 0 ) @@ -137,7 +137,7 @@ void minimumStatistics_fx( /*rescale noiseLevelMemory*/ setnoiseLevelMemory_fx( f, new_noiseEstimate_e, noiseLevelMemory_e, noiseLevelMemory, currLevelIndex ); - p = *currLevelIndex; + p = *currLevelIndex; /*Q0*/ move16(); } ELSE @@ -147,7 +147,7 @@ void minimumStatistics_fx( /* current min is not a new min, so check if min must be re-searched */ IF( NE_16( p, *currLevelIndex ) ) { - f = noiseLevelMemory[p]; /* min is still in memory, so return it */ + f = noiseLevelMemory[p]; /* min is still in memory, so return it Qx*/ move16(); *new_noiseEstimate_e = noiseLevelMemory_e[p]; move16(); @@ -164,7 +164,7 @@ void minimumStatistics_fx( move16(); } } - f = noiseLevelMemory[p]; + f = noiseLevelMemory[p]; /*Qx*/ move16(); *new_noiseEstimate_e = noiseLevelMemory_e[p]; move16(); @@ -172,10 +172,10 @@ void minimumStatistics_fx( } /* update local-minimum-value index and current circular-buffer index */ - *noiseLevelIndex = p; + *noiseLevelIndex = p; /*Q0*/ move16(); p = add( *currLevelIndex, 1 ); - *currLevelIndex = add( *currLevelIndex, 1 ); + *currLevelIndex = add( *currLevelIndex, 1 ); /*Q0*/ move16(); if ( EQ_16( *currLevelIndex, PLC_MIN_STAT_BUFF_SIZE ) ) { @@ -183,7 +183,7 @@ void minimumStatistics_fx( move16(); } - *noiseEstimate = f; + *noiseEstimate = f; /*Qx*/ move16(); } @@ -226,15 +226,15 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ move16(); /*calculate headroom for dotproduct*/ - Hr16 = sub( 15, norm_s( lenLpcExc ) ); + Hr16 = sub( 15, norm_s( lenLpcExc ) ); /*Q0*/ Q_h1 = s_max( sub( Q_h1, Hr16 ), 0 ); /*compensate synthesis scaling with Headroom as much as possible to retain as much precision as possible*/ /*Factor to be multiplied in order to calculate dotproduct with headroom*/ - tmp16 = shr( 32768 / 2, sub( Hr16, 1 ) ); + tmp16 = shr( 32768 / 2, sub( Hr16, 1 ) ); /*Q15*/ /*moved from inside loop, before synthesis*/ - h1Init[0] = mult_r( h1Init[0], tmp16 ); + h1Init[0] = mult_r( h1Init[0], tmp16 ); /*Q15*/ move16(); FOR( loop = 0; loop < numLoops; loop++ ) @@ -242,7 +242,7 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ set16_fx( h1, 0, lenLpcExc ); set16_fx( mem, 0, lpcorder ); - Copy( h1Init, h1, 1 ); + Copy( h1Init, h1, 1 ); /*Q15*/ /*h1 will be scaled down, Q_h1 */ E_UTIL_synthesis( Q_h1, A, h1, h1, lenLpcExc, mem, 0, lpcorder ); deemph_fx( h1, preemph_fac, lenLpcExc, &tmp ); @@ -250,10 +250,10 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ /* gain introduced by synthesis+deemphasis */ /*levelSynDeemphSub = (float)sqrt(dot_product( h1, h1, lenLpcExc));*/ - levelSynDeemphSub = Dot_product12_offs( h1, h1, lenLpcExc, &s16, 0 ); + levelSynDeemphSub = Dot_product12_offs( h1, h1, lenLpcExc, &s16, 0 ); /*Q31 - s16*/ s16 = sub( shl( add( Q_h1, Hr16 ), 1 ), sub( 30, s16 ) ); - levelSynDeemphSub = Sqrt32( levelSynDeemphSub, &s16 ); /*Q31*/ + levelSynDeemphSub = Sqrt32( levelSynDeemphSub, &s16 ); /*Q31 - s16*/ /* mean of the above across all subframes -- moved outta loop*/ /*levelSynDeemph += (1.0/(float)numLoops) * levelSynDeemphSub;*/ @@ -262,14 +262,14 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ if ( GT_16( numLoops, 1 ) ) { - tmp16 = div_s( 1, numLoops ); + tmp16 = div_s( 1, numLoops ); /*Q15*/ } levelSynDeemph = L_add( levelSynDeemph, L_shl( Mpy_32_16_1( levelSynDeemphSub, tmp16 ), sub( s16, 10 ) ) ); /*10Q21*/ } s16 = norm_l( levelSynDeemph ); - levelSynDeemph = L_shl( levelSynDeemph, s16 ); - *Exp = sub( 10, s16 ); /*Set exponent in order to transform returnvalue to Q15*/ + levelSynDeemph = L_shl( levelSynDeemph, s16 ); /*Q31*/ + *Exp = sub( 10, s16 ); /*Set exponent in order to transform returnvalue to Q15*/ move16(); #ifdef BASOP_NOGLOB @@ -281,10 +281,10 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ /* BASOP version: up to date with rev 7422 */ void genPlcFiltBWAdap_fx( - const Word32 sr_core, /* i : core sampling rate */ - Word16 *lpFiltAdapt, /* o : filter coefficients for filtering codebooks in case of flc */ - const Word16 type, /* i : type of filter, either 0 : lowpass or 1 : highpass */ - const Word16 alpha /* i : fade out factor [0 1) used decrease filter tilt */ + const Word32 sr_core, /* i : core sampling rate Q0*/ + Word16 *lpFiltAdapt, /* o : filter coefficients for filtering codebooks in case of flc Q15*/ + const Word16 type, /* i : type of filter, either 0 : lowpass or 1 : highpass Q0*/ + const Word16 alpha /* i : fade out factor [0 1) used decrease filter tilt Q15*/ ) { Word16 a, b, exp; @@ -305,17 +305,17 @@ void genPlcFiltBWAdap_fx( } ELSE { - a = mult_r( 13107 /*0.4000f Q15*/, alpha ); + a = mult_r( 13107 /*0.4000f Q15*/, alpha ); /*Q15*/ exp = 0; move16(); - b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); - b = shr( b, sub( 1, exp ) ); - a = negate( mult_r( a, b ) ); - *lpFiltAdapt++ = a; + b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); /*Q15 - exp*/ + b = shr( b, sub( 1, exp ) ); /*Q15*/ + a = negate( mult_r( a, b ) ); /*Q15*/ + *lpFiltAdapt++ = a; /*Q15*/ move16(); - *lpFiltAdapt++ = b; + *lpFiltAdapt++ = b; /*Q15*/ move16(); - *lpFiltAdapt = a; + *lpFiltAdapt = a; /*Q15*/ move16(); } } @@ -332,17 +332,17 @@ void genPlcFiltBWAdap_fx( } ELSE { - a = mult_r( 9218 /*0.2813f Q15*/, alpha ); + a = mult_r( 9218 /*0.2813f Q15*/, alpha ); /*Q15*/ exp = 0; move16(); - b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); - b = shr( b, sub( 1, exp ) ); - a = negate( mult_r( a, b ) ); - *lpFiltAdapt++ = a; + b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); /*Q15 - exp*/ + b = shr( b, sub( 1, exp ) ); /*Q15*/ + a = negate( mult_r( a, b ) ); /*Q15*/ + *lpFiltAdapt++ = a; /*Q15*/ move16(); - *lpFiltAdapt++ = b; + *lpFiltAdapt++ = b; /*Q15*/ move16(); - *lpFiltAdapt = a; + *lpFiltAdapt = a; /*Q15*/ move16(); } } @@ -355,11 +355,11 @@ void genPlcFiltBWAdap_fx( *-----------------------------------------------------------------*/ /*VERSIONINFO: This port is up to date with trunk rev. 32434*/ void highPassFiltering_fx( - const Word16 last_good, /* i: short last classification type */ - const Word16 L_buffer, /* i: int buffer length */ + const Word16 last_good, /* i: short last classification type Q0*/ + const Word16 L_buffer, /* i: int buffer length Q0*/ Word16 exc2[], /* i/o: Qx unvoiced excitation before the high pass filtering */ const Word16 hp_filt[], /* i: Q15 high pass filter coefficients */ - const Word16 l_fir_fer ) /* i: high pass filter length */ + const Word16 l_fir_fer ) /* i: high pass filter length Q0*/ { Word16 i; /*int*/ @@ -368,7 +368,7 @@ void highPassFiltering_fx( { FOR( i = 0; i < L_buffer; i++ ) { - exc2[i] = round_fx( L_sub( Dot_product( &exc2[i], hp_filt, l_fir_fer ), 1 ) ); + exc2[i] = round_fx( L_sub( Dot_product( &exc2[i], hp_filt, l_fir_fer ), 1 ) ); /*Qx*/ move16(); } } @@ -391,9 +391,9 @@ Word16 GetPLCModeDecision_ivas_fx( IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_pitch_buf_fx[shl( st->nb_subfr, 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( st->nb_subfr * 2 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); - st->old_pitch_buf_fx[add( shl( st->nb_subfr, 1 ), 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( ( st->nb_subfr * 2 ) + 1 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 16384 /*1.f Q14*/; /*Q14*/ move16(); @@ -430,7 +430,7 @@ Word16 GetPLCModeDecision_ivas_fx( move16(); if ( GT_16( st->nbLostCmpt, 1 ) ) { - core = st->last_core_bfi; + core = st->last_core_bfi; /*Q0*/ move16(); } IF( EQ_16( st->nbLostCmpt, 1 ) ) @@ -462,7 +462,7 @@ Word16 GetPLCModeDecision_ivas_fx( pitch = L_deposit_h( 0 ); if ( hTcxDec->tcxltp_last_gain_unmodified > 0 ) { - pitch = L_add( st->old_fpitch, 0 ); + pitch = L_add( st->old_fpitch, 0 ); /*Q16*/ } // TonalMDCTConceal_Detect_ivas_fx(&st->tonalMDCTconceal, pitch, &numIndices // , (st->element_mode == IVAS_CPE_MDCT ? &(st->hTcxCfg->psychParamsTCX20) : st->hTcxCfg->psychParamsCurrent) @@ -503,7 +503,7 @@ Word16 GetPLCModeDecision_ivas_fx( } } } - return core; + return core; /*Q0*/ } #endif @@ -523,9 +523,9 @@ Word16 GetPLCModeDecision_fx( IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_pitch_buf_fx[shl( st->nb_subfr, 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( st->nb_subfr * 2 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); - st->old_pitch_buf_fx[add( shl( st->nb_subfr, 1 ), 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( ( st->nb_subfr * 2 ) + 1 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 16384 /*1.f Q14*/; /*Q14*/ move16(); @@ -594,7 +594,7 @@ Word16 GetPLCModeDecision_fx( pitch = L_deposit_h( 0 ); if ( hTcxDec->tcxltp_last_gain_unmodified > 0 ) { - pitch = L_add( st->old_fpitch, 0 ); + pitch = L_add( st->old_fpitch, 0 ); /*Q16*/ } IF( st->element_mode == EVS_MONO ) { diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 2bfaa4b027c6f79f6c54b8352413fc932db3ac6c..b6ba82895d99f166b6cb430f201c5c2ad9ccd3d9 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -5050,6 +5050,129 @@ void generate_masking_noise_mdct_fx( } } } + +void generate_masking_noise_mdct_ivas_fx( + Word32 *mdctBuffer, /* i/o: time-domain signal */ + Word16 *mdctBuffer_e, /* i/o: exponent time-domain signal */ + HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ ) +{ + Word16 i, sq, cnt; + Word16 cngNoiseLevelExp; + Word32 scale, temp; + Word32 sqrtNoiseLevel; + Word32 maskingNoise[2 * L_FRAME16k]; + Word32 *pMaskingNoise; + Word32 *cngNoiseLevel; + Word16 *seed; + + // PMTE(); /*IVAS CODE need to be added */ + /* pointer initializations */ + cngNoiseLevel = hFdCngCom->cngNoiseLevel; + seed = &( hFdCngCom->seed ); + + /* Compute additional CN level */ + cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; + move16(); + + scale = ONE_IN_Q30; + move32(); + + cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + + /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */ + IF( hFdCngCom->likelihood_noisy_speech > 0 ) + { + FOR( i = 0; i < SIZE_SCALE_TABLE_CN; i++ ) + { + test(); + test(); + IF( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_only[i].bwmode ) && + GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateFrom ) && + LE_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateTo ) ) + { + BREAK; + } + } + + /* Exclude clean speech */ + scale = L_mult( scaleTable_cn_only[i].scale, hFdCngCom->likelihood_noisy_speech ); // Q30 (14 + 15 + 1) + + /* + 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 + */ + IF( hFdCngCom->startBand == 0 ) + { + /* *cngNoiseLevel * scale * 0.5 */ + temp = Mpy_32_32( *cngNoiseLevel, scale ); // exp = cngNoiseLevelExp (cngNoiseLevelExp + Q30(scale) + 1(0.5f) - 31) + sq = cngNoiseLevelExp; + move16(); + + sqrtNoiseLevel = Sqrt32( temp, &sq ); + + rand_gauss_fx( &temp, seed, Q15 ); // Q15 + + maskingNoise[0] = L_shl( Mpy_32_32( temp, sqrtNoiseLevel ), sq ); // Q15 + move32(); + + pMaskingNoise = &maskingNoise[1]; + cngNoiseLevel++; + cnt = sub( cnt, 1 ); + } + ELSE + { + set32_fx( maskingNoise, 0, hFdCngCom->startBand ); + pMaskingNoise = maskingNoise + hFdCngCom->startBand; + } + + FOR( i = 0; i < cnt; i++ ) + { + /* MDCT bins */ + /* *cngNoiseLevel * scale * 0.5 */ + temp = Mpy_32_32( *cngNoiseLevel, scale ); // exp = cngNoiseLevelExp (cngNoiseLevelExp + Q30(scale) + 1(0.5f) - 31) + sq = cngNoiseLevelExp; + move16(); + + sqrtNoiseLevel = Sqrt32( temp, &sq ); + + rand_gauss_fx( &temp, seed, Q15 ); // Q15 + + *pMaskingNoise = L_shl( Mpy_32_32( temp, sqrtNoiseLevel ), sq ); // Q15 + move32(); + + pMaskingNoise++; + cngNoiseLevel++; + } + + /*re-normalization of energy level: M/sqrt(2)*/ + v_multc_fixed( maskingNoise, SQRT_NORM_MDCT_FACTOR_Q27, maskingNoise, hFdCngCom->stopFFTbin ); // Q11 + + scale_sig32( maskingNoise, hFdCngCom->stopFFTbin, sub( 20, *mdctBuffer_e ) ); // exp = *mdctBuffer_e + + /* Add some comfort noise on top of decoded signal */ + v_add_fixed( maskingNoise, mdctBuffer, mdctBuffer, hFdCngCom->stopFFTbin, 1 ); + *mdctBuffer_e = sub( *mdctBuffer_e, 1 ); + move16(); + } + ELSE + { + /* very low level case - just update random seeds */ + IF( hFdCngCom->startBand == 0 ) + { + rand_gauss_fx( &maskingNoise[0], seed, Q15 ); // Q15 + cngNoiseLevel++; + cnt = sub( cnt, 1 ); + } + + FOR( i = 0; i < cnt; i++ ) + { + rand_gauss_fx( &maskingNoise[0], seed, Q15 ); // Q15 + move32(); + } + } + + return; +} #endif #ifdef IVAS_CODE_CNG diff --git a/lib_dec/gaus_dec_fx.c b/lib_dec/gaus_dec_fx.c index a7806e274b81e466b06aebc029f9c57a15aa41a6..5221e14f4f914d7ef26359bce198e0390c8e4801 100644 --- a/lib_dec/gaus_dec_fx.c +++ b/lib_dec/gaus_dec_fx.c @@ -65,7 +65,7 @@ void gaus_dec_fx( L_tmp = Dot_product12( code, code, L_SUBFR, &exp ); exp = sub( exp, 18 /*24*/ + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ L_tmp = Isqrt_lc( L_tmp, &exp ); - *inv_gain_inov = extract_h( L_shl( L_tmp, sub( exp, 3 ) ) ); /* inv_gain_inov in Q12 */ + *inv_gain_inov = extract_h( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /* inv_gain_inov in Q12 */ move16(); nb_bits = st_fx->acelp_cfg.gains_mode[shr( i_subfr, 6 )]; diff --git a/lib_dec/gs_dec_amr_wb_fx.c b/lib_dec/gs_dec_amr_wb_fx.c index d57411ff4104643032be158b07ecce65c2672320..9778acec0357ac79b47e95e6539878855f6b97d1 100644 --- a/lib_dec/gs_dec_amr_wb_fx.c +++ b/lib_dec/gs_dec_amr_wb_fx.c @@ -49,9 +49,9 @@ static void gs_dec_amr_wb_fx( const long core_brate, Word16 *seed_tcx, const Wor *-------------------------------------------------------------------*/ static void NoiseFill_fx( - Word16 *exc_diffQ_fx, /* i/o: Noise per band */ - Word16 *seed_tcx, /* i : Seed for noise */ - const Word16 Mbands_gn, /* i : number of bands */ + Word16 *exc_diffQ_fx, /* i/o: Noise per band Q_out*/ + Word16 *seed_tcx, /* i : Seed for noise Q0*/ + const Word16 Mbands_gn, /* i : number of bands Q0*/ const Word16 Q_out /* i : Q of exc_diffQ_fx[] */ ) { @@ -60,16 +60,16 @@ static void NoiseFill_fx( Word16 fact; CurBin = 0; move16(); - fact = shr( 24576 /*0.75f*/, sub( 15, Q_out ) ); + fact = shr( 24576 /*0.75f in Q15*/, sub( 15, Q_out ) ); /* Q_out */ FOR( i_band = 0; i_band < Mbands_gn; i_band++ ) { EndBin = add( CurBin, crit_bins[i_band] ); FOR( ; CurBin < EndBin; CurBin++ ) { - L_temp = L_mult( Random( seed_tcx ), fact ); - L_temp = L_msu( L_temp, exc_diffQ_fx[CurBin], -32768 ); - exc_diffQ_fx[CurBin] = round_fx( L_temp ); + L_temp = L_mult( Random( seed_tcx ), fact ); /* Q15 + Q_out + 1 */ + L_temp = L_msu( L_temp, exc_diffQ_fx[CurBin], -32768 ); /* Q15 + Q_out + 1*/ + exc_diffQ_fx[CurBin] = round_fx( L_temp ); /* Q_out */ move16(); } } @@ -84,9 +84,9 @@ static void NoiseFill_fx( *-------------------------------------------------------------------*/ static void Ener_per_band_fx( - const Word16 exc_diff_fx[], /* i : target signal */ - const Word16 exc_diff_exp, /* i : Exponent of exc_diff_fx */ - Word32 y_gain4_fx[] /* o : Energy per band to quantize Q16 */ + const Word16 exc_diff_fx[], /* i : target signal exp(exc_diff_exp)*/ + const Word16 exc_diff_exp, /* i : Exponent of exc_diff_fx */ + Word32 y_gain4_fx[] /* o : Energy per band to quantize Q16*/ ) { const Word16 *ptr16; @@ -96,29 +96,29 @@ static void Ener_per_band_fx( exp = shl( exc_diff_exp, 1 ); /* To Get 0.01f in Q of (exc_diff_exp-1)^2 */ - L_epsilon = L_shr( 42949673L, sub( 32 + ENER_FX_Q_GUARD * 2, exp ) ); + L_epsilon = L_shr( 42949673L, sub( 32 + ENER_FX_Q_GUARD * 2, exp ) ); /* Q16 */ ptr16 = exc_diff_fx; FOR( j = 0; j < CRIT_NOIS_BAND; j++ ) { - temp = shr( *ptr16++, ENER_FX_Q_GUARD ); - L_temp = L_mac0( L_epsilon, temp, temp ); + temp = shr( *ptr16++, ENER_FX_Q_GUARD ); /* Q15 - exc_diff_exp + Q1 */ + L_temp = L_mac0( L_epsilon, temp, temp ); /* Q16 */ FOR( i = 1; i < crit_bins[j]; i++ ) { - temp = shr( *ptr16++, ENER_FX_Q_GUARD ); - L_temp = L_mac0( L_temp, temp, temp ); + temp = shr( *ptr16++, ENER_FX_Q_GUARD ); /* Q15 - exc_diff_exp + Q1 */ + L_temp = L_mac0( L_temp, temp, temp ); /* Q16 */ } L_temp2 = L_mult0( 1, 6554 ); /* sqrt of 0.01f in Q16*/ IF( L_temp != 0 ) /* avoid executing sqrt of 0 (because a div_s is used to invert and then call inv_sqrt) */ { L_temp2 = Sqrt_Ratio32( L_temp, exp, 1, 0, &i ); #ifdef BASOP_NOGLOB - L_temp2 = L_shr_sat( L_temp2, sub( 15 - ENER_FX_Q_GUARD, i ) ); + L_temp2 = L_shr_sat( L_temp2, sub( 15 - ENER_FX_Q_GUARD, i ) ); /* Q16 */ #else L_temp2 = L_shr( L_temp2, sub( 15 - ENER_FX_Q_GUARD, i ) ); #endif } - y_gain4_fx[j] = L_temp2; + y_gain4_fx[j] = L_temp2; /* Q16 */ move32(); } @@ -133,9 +133,9 @@ static void Ener_per_band_fx( *-------------------------------------------------------------------*/ static void Apply_gain_fx( - Word16 exc_diffQ_fx[], /* i/o: Quantized excitation */ - Word32 L_Ener_per_bd_iQ[], /* i : Target ener per band */ - Word32 L_Ener_per_bd_yQ[] /* i : Ener per band for norm vector */ + Word16 exc_diffQ_fx[], /* i/o: Quantized excitation Qx*/ + Word32 L_Ener_per_bd_iQ[], /* i : Target ener per band Q16*/ + Word32 L_Ener_per_bd_yQ[] /* i : Ener per band for norm vector Qx*/ , const Word16 Q_out ) { @@ -154,11 +154,11 @@ static void Apply_gain_fx( move16(); FOR( i_band = 0; i_band < CRIT_NOIS_BAND; i_band++ ) { - EndBin = add( CurBin, crit_bins[i_band] ); + EndBin = add( CurBin, crit_bins[i_band] ); /* Q0 */ y_gain_exp = norm_l( L_Ener_per_bd_yQ[i_band] ); exp3 = norm_l( L_Ener_per_bd_iQ[i_band] ); /* use 'exp3' as temporary exponent of 'L_Ener_per_bd_iQ[]' */ #ifdef BASOP_NOGLOB - y_gain_fx = round_fx_sat( Div_flt32_flt32( L_shl_sat( L_Ener_per_bd_iQ[i_band], exp3 ), exp3, L_shl_sat( L_Ener_per_bd_yQ[i_band], y_gain_exp ), y_gain_exp, &y_gain_exp ) ); + y_gain_fx = round_fx_sat( Div_flt32_flt32( L_shl_sat( L_Ener_per_bd_iQ[i_band], exp3 ), exp3, L_shl_sat( L_Ener_per_bd_yQ[i_band], y_gain_exp ), y_gain_exp, &y_gain_exp ) ); /* y_gain_exp - 31 + Q_out */ #else y_gain_fx = round_fx( Div_flt32_flt32( L_shl( L_Ener_per_bd_iQ[i_band], exp3 ), exp3, L_shl( L_Ener_per_bd_yQ[i_band], y_gain_exp ), y_gain_exp, &y_gain_exp ) ); #endif @@ -172,9 +172,9 @@ static void Apply_gain_fx( { FOR( ; CurBin < EndBin; CurBin++ ) { - L_temp = L_mult( exc_diffQ_fx[CurBin], y_gain_fx ); - L_temp = L_shr( L_temp, y_gain_exp ); - exc_diffQ_fx[CurBin] = round_fx( L_temp ); + L_temp = L_mult( exc_diffQ_fx[CurBin], y_gain_fx ); /* Q16 + Q_out + y_gain_exp */ + L_temp = L_shr( L_temp, y_gain_exp ); /* Q_out + 16 */ + exc_diffQ_fx[CurBin] = round_fx( L_temp ); /* Q_out */ move16(); } } @@ -190,29 +190,29 @@ static void Apply_gain_fx( *-------------------------------------------------------------------*/ static void normalize_spec_fx( - Word16 fac_up_fx, /* i : Core bitrate (Q8) */ - Word16 fy_norm_fx[], /* i/o: Frequency quantized parameter (Q8) */ - const Word16 L_frame, /* i : Section lenght */ - const Word16 Q_out /* i : Q of fy_norm_fx[] */ + Word16 fac_up_fx, /* i : Core bitrate (Q8)*/ + Word16 fy_norm_fx[], /* i/o: Frequency quantized parameter (Q8)*/ + const Word16 L_frame, /* i : Section lenght Q0*/ + const Word16 Q_out /* i : Q of fy_norm_fx[] */ ) { Word16 idx, j; Word32 L_temp; Word16 temp, exp; - idx = emaximum_fx( 0 /* Exponent is not Important */, fy_norm_fx, L_frame, &L_temp ); + idx = emaximum_fx( 0 /* Exponent is not Important */, fy_norm_fx, L_frame, &L_temp ); /* Q0 */ exp = sub( Q_out, 8 /*Q8 of Fac Up/down*/ ); - temp = Invert16( abs_s( fy_norm_fx[idx] ), &exp ); - L_temp = L_mult( temp, fac_up_fx ); + temp = Invert16( abs_s( fy_norm_fx[idx] ), &exp ); /* Q15 + exp */ + L_temp = L_mult( temp, fac_up_fx ); /* Q15 + exp + Q8 + 1 */ exp = sub( 15, exp ); #ifdef BASOP_NOGLOB - L_temp = L_shl_sat( L_temp, exp ); + L_temp = L_shl_sat( L_temp, exp ); /* Q24 + Q_out */ #else L_temp = L_shl( L_temp, exp ); #endif FOR( j = 0; j < L_frame; j++ ) { - fy_norm_fx[j] = round_fx( Mult_32_16( L_temp, fy_norm_fx[j] ) ); + fy_norm_fx[j] = round_fx( Mult_32_16( L_temp, fy_norm_fx[j] ) ); /* Q_out */ move16(); } @@ -226,16 +226,16 @@ static void normalize_spec_fx( *-------------------------------------------------------------------*/ static void gs_dec_amr_wb_fx( - const long core_brate, /* i : bitrate allocated to the core */ - Word16 *seed_tcx, /* i/o: seed used for noise generation */ - const Word16 dct_in_fx[], /* i : cdt of residual signal */ + const long core_brate, /* i : bitrate allocated to the core Q0*/ + Word16 *seed_tcx, /* i/o: seed used for noise generation Q0*/ + const Word16 dct_in_fx[], /* i : cdt of residual signal Q_dct_in*/ const Word16 Q_dct_in, /* i : Exponent of dct_in_fx */ - Word16 dct_out_fx[], /* o : dct of pitch only excitation */ + Word16 dct_out_fx[], /* o : dct of pitch only excitation Q_dct_out*/ Word16 Q_dct_out, /* o : Exponent of dct_out_fx */ - const Word16 pitch_fx[], /* i : pitch buffer */ - const Word16 voice_fac, /* i : gain pitch Q15 */ - const Word16 clas, /* i : signal frame class */ - const Word16 coder_type /* i : coder type */ + const Word16 pitch_fx[], /* i : pitch buffer Q6*/ + const Word16 voice_fac, /* i : gain pitch Q15*/ + const Word16 clas, /* i : signal frame class Q0*/ + const Word16 coder_type /* i : coder type Q0*/ #ifdef ADD_IVAS_GS_DEC_IMPR , const Word16 VeryLowRateSTflag /* i : Enable the noise enhancement for very low rate stereo generic mode */ @@ -266,7 +266,7 @@ static void gs_dec_amr_wb_fx( FOR( i = 0; i < CRIT_NOIS_BAND; i++ ) { #ifdef BASOP_NOGLOB - temp = s_max( round_fx_sat( Ener_per_bd_iQ_fx[i] ), temp ); + temp = s_max( round_fx_sat( Ener_per_bd_iQ_fx[i] ), temp ); /* Q0 */ #else temp = s_max( round_fx( Ener_per_bd_iQ_fx[i] ), temp ); #endif @@ -278,7 +278,7 @@ static void gs_dec_amr_wb_fx( { FOR( i = 0; i < CRIT_NOIS_BAND; i++ ) { - Ener_per_bd_iQ_fx[i] = Mult_32_16( Ener_per_bd_iQ_fx[i], crit_bins_corr_fx[i] ); + Ener_per_bd_iQ_fx[i] = Mult_32_16( Ener_per_bd_iQ_fx[i], crit_bins_corr_fx[i] ); /* Q16 */ move32(); } } @@ -287,16 +287,16 @@ static void gs_dec_amr_wb_fx( /*--------------------------------------------------------------------------------------* * Find the lenght of the temporal contribution, with a minimum contribution of 1.2kHz *--------------------------------------------------------------------------------------*/ - temp = s_min( pitch_fx[0], pitch_fx[1] ); - temp = s_min( temp, pitch_fx[2] ); - temp = s_min( temp, pitch_fx[3] ); + temp = s_min( pitch_fx[0], pitch_fx[1] ); /* Q6 */ + temp = s_min( temp, pitch_fx[2] ); /* Q6 */ + temp = s_min( temp, pitch_fx[3] ); /* Q6 */ /* etmp14 = 12800.0f/(temp/16.0f)*8.0f */ exp = 6; /* Pitch in Q6*/ move16(); - temp = Invert16( temp, &exp ); - L_temp = L_mult( temp, 12800 ); - L_temp = L_shl( L_temp, sub( 3, exp ) ); /* *8.0f */ + temp = Invert16( temp, &exp ); /* Q15 */ + L_temp = L_mult( temp, 12800 ); /* Q15 */ + L_temp = L_shl( L_temp, sub( 3, exp ) ); /* *8.0f */ /* Q15 */ #ifdef ADD_IVAS_GS_DEC_IMPR test(); test(); @@ -305,27 +305,27 @@ static void gs_dec_amr_wb_fx( if ( GE_32( core_brate, ACELP_12k65 ) ) #endif { - L_temp = L_shl( L_temp, 1 ); + L_temp = L_shl( L_temp, 1 ); /* Q16 */ } /* (Word16)(etmp14+0.5f) */ - mDiff_len = round_fx( L_temp ); + mDiff_len = round_fx( L_temp ); /* Q0 */ temp = 32767; move16(); L_temp = L_deposit_l( 0 ); FOR( i = 0; i < CRIT_NOIS_BAND; i++ ) { - temp2 = sub( crit_bands_loc_fx[i], mDiff_len ); - temp2 = abs_s( temp2 ); + temp2 = sub( crit_bands_loc_fx[i], mDiff_len ); /* Q0 */ + temp2 = abs_s( temp2 ); /* Q0 */ if ( GT_16( temp, temp2 ) ) { - L_temp = L_msu( L_temp, crit_bins[i], -32768 ); + L_temp = L_msu( L_temp, crit_bins[i], -32768 ); /* Q16 */ } - temp = s_min( temp, temp2 ); + temp = s_min( temp, temp2 ); /* Q0 */ } - mDiff_len = s_max( round_fx( L_temp ), BIN_1k2 ); + mDiff_len = s_max( round_fx( L_temp ), BIN_1k2 ); /* Q0 */ #ifdef ADD_IVAS_GS_DEC_IMPR @@ -334,12 +334,12 @@ static void gs_dec_amr_wb_fx( Copy( dct_in_fx, exc_diffQ, L_FRAME ); /* normalization of the spectrum and noise fill */ - normalize_spec_fx( 1 * 256, exc_diffQ + mDiff_len, L_FRAME - mDiff_len, NORMALIZE_SPECS_Q_OUT ); + normalize_spec_fx( 1 * 256, exc_diffQ + mDiff_len, sub( L_FRAME, mDiff_len ), NORMALIZE_SPECS_Q_OUT ); } ELSE #endif { - Copy( dct_in_fx, exc_diffQ_fx, mDiff_len ); + Copy( dct_in_fx, exc_diffQ_fx, mDiff_len ); /* Q_dct_in */ set16_fx( exc_diffQ_fx + mDiff_len, 0, sub( L_FRAME, mDiff_len ) ); /* normalization of the spectrum and noise fill*/ @@ -356,7 +356,7 @@ static void gs_dec_amr_wb_fx( * Compute tilt factor and amplify HF accordingly *--------------------------------------------------------------------------------------*/ - temp = mult_r( sub( 32767, voice_fac ), 16384 ); /* Q15 */ + temp = mult_r( sub( 32767 /* 1.0 in Q15 */, voice_fac ), 16384 /* 0.5 in Q15 */ ); /* Q15 */ FOR( i = 240; i < L_FRAME; i++ ) { temp2 = msu_r( -7680 * 65536, -17564, shl( i, 6 ) ); /*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */ @@ -374,7 +374,7 @@ static void gs_dec_amr_wb_fx( * Copy to the output vector *--------------------------------------------------------------------------------------*/ - Copy( exc_diffQ_fx, dct_out_fx, L_FRAME ); + Copy( exc_diffQ_fx, dct_out_fx, L_FRAME ); /* Q_dct_out */ return; } @@ -386,24 +386,24 @@ static void gs_dec_amr_wb_fx( * unvoiced and audio signals (used only in AMR-WB IO mode) *-------------------------------------------------------------------*/ void improv_amr_wb_gs_fx( - const Word16 clas, /* i : signal frame class */ - const Word16 coder_type, /* i : coder type */ - const Word32 core_brate, /* i : bitrate allocated to the core */ - Word16 *seed_tcx, /* i/o: Seed used for noise generation */ - Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient */ - Word16 *mem_syn2_fx, /* i/o: synthesis memory */ - const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q14 */ - const Word16 locattack, /* i : Flag for a detected attack */ - Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient */ - Word16 *exc2_fx, /* i/o: Decoded complete excitation */ - const Word16 Q_exc2, /* i : Exponent of Exc2 */ - Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory */ - Word16 *syn_fx, /* o: Decoded synthesis to be updated */ - const Word16 Q_syn, /* i : Synthesis scaling Q0 */ - const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer Q6 */ - const Word16 Last_ener_fx, /* i : Last energy (Q8) */ - const Word16 rate_switching_reset, /* i : rate switching reset flag */ - const Word16 last_coder_type /* i : Last coder_type */ + const Word16 clas, /* i : signal frame class Q0*/ + const Word16 coder_type, /* i : coder type Q0*/ + const Word32 core_brate, /* i : bitrate allocated to the core Q0*/ + Word16 *seed_tcx, /* i/o: Seed used for noise generation Q0*/ + Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient q_old_Aq*/ + Word16 *mem_syn2_fx, /* i/o: synthesis memory Q_syn*/ + const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q14*/ + const Word16 locattack, /* i : Flag for a detected attack Q0*/ + Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient q_Aq*/ + Word16 *exc2_fx, /* i/o: Decoded complete excitation Q_exc2*/ + const Word16 Q_exc2, /* i : Exponent of Exc2 */ + Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory Q_syn*/ + Word16 *syn_fx, /* o: Decoded synthesis to be updated Q_syn*/ + const Word16 Q_syn, /* i : Synthesis scaling */ + const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer Q6*/ + const Word16 Last_ener_fx, /* i : Last energy (Q8) Q0*/ + const Word16 rate_switching_reset, /* i : rate switching reset flag Q0*/ + const Word16 last_coder_type /* i : Last coder_type Q0*/ #ifdef ADD_IVAS_GS_DEC_IMPR , const Word16 VeryLowRateSTflag /* i : Enable the noise enhancement for very low rate stereo generic mode */ @@ -449,7 +449,7 @@ void improv_amr_wb_gs_fx( * generic audio sound * LP filter smoothing for inactive parts *------------------------------------------------------------*/ - *seed_tcx = extract_l( L_mult0( pitch_buf_fx[0], pitch_buf_fx[3] ) ); + *seed_tcx = extract_l( L_mult0( pitch_buf_fx[0], pitch_buf_fx[3] ) ); /* Q0 */ move16(); /* last_coder_type == UNVOICED should be understand as INACTIVE, but it is forced to UNVOICED in update_dec */ test(); @@ -460,36 +460,36 @@ void improv_amr_wb_gs_fx( FOR( i = 0; i < NB_SUBFR; i++ ) { - Copy( Aq_fx, Aq_orig, NB_SUBFR * ( M + 1 ) ); + Copy( Aq_fx, Aq_orig, NB_SUBFR * ( M + 1 ) ); /* q_Aq */ - exp_a = norm_s( Aq_fx[imult1616( i, ( M + 1 ) )] ); - exp_b = norm_s( old_Aq_fx[imult1616( i, ( M + 1 ) )] ); + exp_a = norm_s( Aq_fx[i * ( M + 1 )] ); + exp_b = norm_s( old_Aq_fx[i * ( M + 1 )] ); exp_diff = sub( exp_a, exp_b ); IF( exp_diff > 0 ) { - Scale_sig( &old_Aq_fx[imult1616( i, ( M + 1 ) )], ( M + 1 ), negate( exp_diff ) ); + Scale_sig( &old_Aq_fx[i * ( M + 1 )], ( M + 1 ), negate( exp_diff ) ); /* exp_b */ } ELSE { - Scale_sig( &Aq_fx[imult1616( i, ( M + 1 ) )], ( M + 1 ), exp_diff ); + Scale_sig( &Aq_fx[i * ( M + 1 )], ( M + 1 ), exp_diff ); /* exp_a */ } - FOR( j = imult1616( i, ( M + 1 ) ); j < imult1616( add( i, 1 ), ( M + 1 ) ); j++ ) + FOR( j = i * ( M + 1 ); j < ( i + 1 ) * ( M + 1 ); j++ ) { - Aq_fx[j] = round_fx( L_mac( L_mult( ALP_FX, old_Aq_fx[j] ), MALP_FX, Aq_fx[j] ) ); + Aq_fx[j] = round_fx( L_mac( L_mult( ALP_FX, old_Aq_fx[j] ), MALP_FX, Aq_fx[j] ) ); /* q_Aq */ move16(); } } /* check the smoothed LP filter stability */ - enr_LP_old = Enr_1_Az_fx( old_Aq_fx, L_SUBFR ); + enr_LP_old = Enr_1_Az_fx( old_Aq_fx, L_SUBFR ); /* Q3 */ Overflow = 0; move16(); FOR( i = 0; i < NB_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - enr_LP_new = Enr_1_Az_fx_o( Aq_fx + imult1616( i, ( M + 1 ) ), L_SUBFR, &Overflow ); + enr_LP_new = Enr_1_Az_fx_o( Aq_fx + imult1616( i, ( M + 1 ) ), L_SUBFR, &Overflow ); /* Q3 */ #else enr_LP_new = Enr_1_Az_fx( Aq_fx + i * ( M + 1 ), L_SUBFR ); #endif @@ -497,14 +497,14 @@ void improv_amr_wb_gs_fx( IF( GT_16( shr( enr_LP_new, 7 ), enr_LP_old ) || Overflow ) { /* filter is unstable, do not modify the excitation */ - Copy( Aq_orig, Aq_fx, NB_SUBFR * ( M + 1 ) ); + Copy( Aq_orig, Aq_fx, NB_SUBFR * ( M + 1 ) ); /* q_Aq */ Overflow = 0; move16(); return; } - enr_LP_old = enr_LP_new; + enr_LP_old = enr_LP_new; /* Q3 */ move16(); } } @@ -527,7 +527,7 @@ void improv_amr_wb_gs_fx( * Redo core synthesis at 12k8 Hz with the modified excitation *------------------------------------------------------------*/ - Copy( mem_tmp_fx, mem_syn2_fx, M ); + Copy( mem_tmp_fx, mem_syn2_fx, M ); /* Q_syn */ syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, mem_syn2_fx, 1, Q_exc2, Q_syn ); } diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index 9a10f08621d72d5dae4b93022b2e7da410f6c072..7af4b5c402b5afcd7c512ac4ecae70bc5f8c7841 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -34,14 +34,14 @@ /*==========================================================================*/ void decod_audio_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain */ - const Word16 *Aq, /* i : LP filter coefficient */ - Word16 *pitch_buf, /* o : floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new /* i : ISFs at the end of the frame */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : floating pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ , Word16 *gain_buf /*Q14*/ ) @@ -71,7 +71,7 @@ void decod_audio_fx( move16(); /* decode GSC attack flag (used to reduce possible pre-echo) */ - gsc_attack_flag = (Word16) get_next_indice_fx( st_fx, 1 ); + gsc_attack_flag = (Word16) get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); /* decode GSC SWB speech flag */ @@ -83,7 +83,7 @@ void decod_audio_fx( ( st_fx->element_mode > EVS_MONO && st_fx->total_brate > MIN_BRATE_GSC_NOISY_FLAG && st_fx->bwidth >= SWB && !st_fx->flag_ACELP16k ) ) ) ) #endif { - st_fx->GSC_noisy_speech = (Word16) get_next_indice_fx( st_fx, 1 ); + st_fx->GSC_noisy_speech = (Word16) get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); } @@ -92,9 +92,9 @@ void decod_audio_fx( test(); IF( st_fx->GSC_noisy_speech && LT_16( st_fx->bwidth, SWB ) && st_fx->GSC_IVAS_mode == 0 ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); - st_fx->GSC_noisy_speech = 0; + st_fx->GSC_noisy_speech = 0; /* Q0 */ move16(); } /* set bit-allocation */ @@ -114,11 +114,11 @@ void decod_audio_fx( IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) ) #endif { - nb_subfr = NB_SUBFR; + nb_subfr = NB_SUBFR; /* Q0 */ move16(); hGSCDec->cor_strong_limit = 0; move16(); - hGSCDec->noise_lev = NOISE_LEVEL_SP3; + hGSCDec->noise_lev = NOISE_LEVEL_SP3; /* Q0 */ move16(); #ifdef ADD_LRTD if ( st_fx->GSC_IVAS_mode >= 1 ) @@ -144,12 +144,12 @@ void decod_audio_fx( { IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2 ); + hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2 ); /* Q0 */ move16(); } ELSE { - hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0 ); + hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0 ); /* Q0 */ move16(); } @@ -165,7 +165,7 @@ void decod_audio_fx( else #endif { - hGSCDec->cor_strong_limit = 1; + hGSCDec->cor_strong_limit = 1; /* Q0 */ move16(); nb_subfr = SWNB_SUBFR; move16(); @@ -180,12 +180,12 @@ void decod_audio_fx( nbits = 2; } #endif - nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); + nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */ move16(); IF( s_and( nb_frame_flg, 0x1 ) == 0 ) { - nb_subfr = 2 * SWNB_SUBFR; + nb_subfr = 2 * SWNB_SUBFR; /* Q0 */ move16(); hGSCDec->cor_strong_limit = 0; move16(); @@ -216,29 +216,29 @@ void decod_audio_fx( IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) ) { - nbits = 3; + nbits = 3; /* Q0 */ move16(); test(); if ( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type == INACTIVE ) { - nbits = 1; + nbits = 1; /* Q0 */ move16(); } } ELSE { - nbits = 4; + nbits = 4; /* Q0 */ move16(); } test(); IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type != INACTIVE ) { - pit_band_idx = 1; + pit_band_idx = 1; /* Q0 */ move16(); } ELSE { - pit_band_idx = (Word16) get_next_indice_fx( st_fx, nbits ); + pit_band_idx = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */ move16(); } @@ -246,26 +246,26 @@ void decod_audio_fx( { IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) { - pit_band_idx = 7 + BAND1k2; - move16(); /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */ + pit_band_idx = 7 + BAND1k2; /* Q0 */ + move16(); /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */ } ELSE { - pit_band_idx = add( pit_band_idx, BAND1k2 ); + pit_band_idx = add( pit_band_idx, BAND1k2 ); /* Q0 */ } /* detect bit errors in the bitstream */ IF( GT_16( pit_band_idx, 13 ) ) /* The maximum decodable index is 10 + BAND1k2 (3) = 13 */ { - pit_band_idx = 13; + pit_band_idx = 13; /* Q0 */ move16(); - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } - Diff_len = mfreq_loc_div_25[pit_band_idx]; + Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ move16(); } - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ move16(); @@ -288,7 +288,7 @@ void decod_audio_fx( #endif { Word16 indice; - nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; + nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; /* Q0 */ move16(); if ( st_fx->element_mode > EVS_MONO ) { @@ -296,7 +296,7 @@ void decod_audio_fx( move16(); } - indice = get_next_indice_fx( st_fx, nbits ); + indice = get_next_indice_fx( st_fx, nbits ); /* Q0 */ Es_pred_dec_fx( &Es_pred, indice, nbits, 0 ); } @@ -312,28 +312,28 @@ void decod_audio_fx( IF( LT_16( low_pit, 64 ) ) { - pit_band_idx = 9 + BAND1k2; + pit_band_idx = 9 + BAND1k2; /* Q0 */ move16(); if ( st_fx->bwidth == NB ) { - pit_band_idx = 7 + BAND1k2; + pit_band_idx = 7 + BAND1k2; /* Q0 */ move16(); } } ELSE IF( LT_16( low_pit, 128 ) ) { - pit_band_idx = 5 + BAND1k2; + pit_band_idx = 5 + BAND1k2; /* Q0 */ move16(); } ELSE { - pit_band_idx = 3 + BAND1k2; + pit_band_idx = 3 + BAND1k2; /* Q0 */ move16(); } - Diff_len = mfreq_loc_div_25[pit_band_idx]; + Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ move16(); - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ move16(); } @@ -346,18 +346,18 @@ void decod_audio_fx( * Reset unvaluable part of the adaptive (pitch) excitation contribution *---------------------------------------------------------------*/ - max_len = sub( st_fx->L_frame, Diff_len ); + max_len = sub( st_fx->L_frame, Diff_len ); /* Q0 */ if ( st_fx->bwidth == NB ) { - max_len = sub( 160, Diff_len ); + max_len = sub( 160, Diff_len ); /* Q0 */ } Len = 80; move16(); if ( LT_16( max_len, 80 ) ) { - Len = max_len; + Len = max_len; /* Q0 */ move16(); } @@ -366,7 +366,7 @@ void decod_audio_fx( { FOR( i = 0; i < max_len; i++ ) { - dct_epit[add( i, Diff_len )] = 0; + dct_epit[i + Diff_len] = 0; move16(); } } @@ -374,47 +374,47 @@ void decod_audio_fx( { FOR( i = 0; i < Len; i++ ) { - dct_epit[add( i, Diff_len )] = mult_r( dct_epit[add( i, Diff_len )], sm_table_fx[i] ); + dct_epit[i + Diff_len] = mult_r( dct_epit[i + Diff_len], sm_table_fx[i] ); /* Qx */ move16(); } FOR( ; i < max_len; i++ ) { - dct_epit[add( i, Diff_len )] = 0; + dct_epit[i + Diff_len] = 0; move16(); } } // PMT("in the rare case of 4 subfr, bfi_pitch_fx might be wrong") - st_fx->bfi_pitch_fx = mean_fx( pitch_buf, nb_subfr ); + st_fx->bfi_pitch_fx = mean_fx( pitch_buf, nb_subfr ); /* Q6 */ move16(); - st_fx->bfi_pitch_frame = st_fx->L_frame; + st_fx->bfi_pitch_frame = st_fx->L_frame; /* Q0 */ move16(); - Diff_len = add( Diff_len, 1 ); + Diff_len = add( Diff_len, 1 ); /* Q0 */ st_fx->bpf_off = 0; move16(); } ELSE { /* No adaptive (pitch) excitation contribution */ - st_fx->bpf_off = 1; + st_fx->bpf_off = 1; /* Q0 */ move16(); set16_fx( dct_epit, 0, st_fx->L_frame ); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - set16_fx( pitch_buf, shl( L_SUBFR16k, 6 ), NB_SUBFR16k ); + set16_fx( pitch_buf, L_SUBFR16k * 64, NB_SUBFR16k ); } ELSE { - set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR ); + set16_fx( pitch_buf, L_SUBFR * 64, NB_SUBFR ); } set16_fx( gain_buf, 0, NB_SUBFR16k ); - st_fx->bfi_pitch_fx = shl( L_SUBFR, 6 ); + st_fx->bfi_pitch_fx = L_SUBFR * 64; move16(); - st_fx->bfi_pitch_frame = st_fx->L_frame; + st_fx->bfi_pitch_frame = st_fx->L_frame; /* Q0 */ move16(); st_fx->lp_gainp_fx = 0; move16(); @@ -434,7 +434,7 @@ void decod_audio_fx( /* find the current total number of bits used */ - tmp_nb_bits_tot = st_fx->next_bit_pos; + tmp_nb_bits_tot = st_fx->next_bit_pos; /* Q0 */ move16(); #ifdef IVAS_CODE if ( st_fx->extl_brate_fx_orig > 0 ) @@ -443,7 +443,7 @@ void decod_audio_fx( #endif { /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ - tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); /* Q0 */ } @@ -456,7 +456,7 @@ void decod_audio_fx( if ( st_fx->coder_type == INACTIVE && LE_32( st_fx->core_brate, ACELP_9k60 ) ) #endif { - tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); + tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); /* Q0 */ } #ifdef ADD_LRTD @@ -502,8 +502,8 @@ void decod_audio_fx( * Updates *--------------------------------------------------------------------------------------*/ - Copy( exc, exc2, st_fx->L_frame ); - Copy( exc_wo_nf, exc, st_fx->L_frame ); + Copy( exc, exc2, st_fx->L_frame ); /* Q_exc */ + Copy( exc_wo_nf, exc, st_fx->L_frame ); /* Q_exc */ /*--------------------------------------------------------------------------------------* * Channel aware mode parameters @@ -537,21 +537,21 @@ void decod_audio_fx( /* _ None */ /*==========================================================================*/ void decod_audio_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain */ - const Word16 *Aq, /* i : LP filter coefficient */ - Word16 *pitch_buf, /* o : Word16 pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new /* i : ISFs at the end of the frame */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ , Word16 *gain_buf, /*Q14*/ - const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag */ - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag Q0*/ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6*/ ) { Word16 tmp_nb_bits_tot, pit_band_idx; @@ -579,7 +579,7 @@ void decod_audio_ivas_fx( move16(); /* decode GSC attack flag (used to reduce possible pre-echo) */ - gsc_attack_flag = (Word16) get_next_indice_fx( st_fx, 1 ); + gsc_attack_flag = (Word16) get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); /* decode GSC SWB speech flag */ @@ -597,7 +597,7 @@ void decod_audio_ivas_fx( ( st_fx->element_mode > EVS_MONO && GT_32( st_fx->total_brate, MIN_BRATE_GSC_NOISY_FLAG ) && GE_16( st_fx->bwidth, SWB ) && !st_fx->flag_ACELP16k ) ) ) ) #endif { - st_fx->GSC_noisy_speech = (Word16) get_next_indice_fx( st_fx, 1 ); + st_fx->GSC_noisy_speech = (Word16) get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); } @@ -606,7 +606,7 @@ void decod_audio_ivas_fx( test(); IF( st_fx->GSC_noisy_speech && LT_16( st_fx->bwidth, SWB ) && st_fx->GSC_IVAS_mode == 0 ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); st_fx->GSC_noisy_speech = 0; move16(); @@ -628,11 +628,11 @@ void decod_audio_ivas_fx( IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) ) #endif { - nb_subfr = NB_SUBFR; + nb_subfr = NB_SUBFR; /* Q0 */ move16(); hGSCDec->cor_strong_limit = 0; move16(); - hGSCDec->noise_lev = NOISE_LEVEL_SP3; + hGSCDec->noise_lev = NOISE_LEVEL_SP3; /* Q0 */ move16(); #if 1 // def ADD_LRTD IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) ) @@ -640,20 +640,20 @@ void decod_audio_ivas_fx( test(); if ( LT_32( st_fx->core_brate, GSC_L_RATE_STG ) && LT_32( st_fx->GSC_IVAS_mode, 3 ) ) { - nb_subfr = 2; + nb_subfr = 2; /* Q0 */ move16(); } - hGSCDec->noise_lev = NOISE_LEVEL_SP2; + hGSCDec->noise_lev = NOISE_LEVEL_SP2; /* Q0 */ move16(); IF( EQ_16( st_fx->GSC_IVAS_mode, 3 ) ) /* Music like */ { - hGSCDec->noise_lev = NOISE_LEVEL_SP0; + hGSCDec->noise_lev = NOISE_LEVEL_SP0; /* Q0 */ move16(); } ELSE IF( st_fx->GSC_noisy_speech == 0 ) /* speech like but not noisy */ { - hGSCDec->noise_lev = NOISE_LEVEL_SP3; + hGSCDec->noise_lev = NOISE_LEVEL_SP3; /* Q0 */ move16(); } } @@ -663,12 +663,12 @@ void decod_audio_ivas_fx( { IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2 ); + hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2 ); /* Q0 */ move16(); } ELSE { - hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0 ); + hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0 ); /* Q0 */ move16(); } @@ -682,30 +682,30 @@ void decod_audio_ivas_fx( { hGSCDec->cor_strong_limit = 0; move16(); - nb_subfr = 1; + nb_subfr = 1; /* Q0 */ move16(); } ELSE #endif { - hGSCDec->cor_strong_limit = 1; + hGSCDec->cor_strong_limit = 1; /* Q0 */ move16(); - nb_subfr = SWNB_SUBFR; + nb_subfr = SWNB_SUBFR; /* Q0 */ move16(); IF( GE_32( st_fx->core_brate, ACELP_9k60 ) ) { - nbits = 1; + nbits = 1; /* Q0 */ move16(); #if 1 // def ADD_LRTD test(); if ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) ) { - nbits = 2; + nbits = 2; /* Q0 */ move16(); } #endif - nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); + nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */ move16(); test(); @@ -725,7 +725,7 @@ void decod_audio_ivas_fx( if ( EQ_16( shr( nb_frame_flg, 1 ), 1 ) ) { - nb_subfr = shl( nb_subfr, 1 ); + nb_subfr = shl( nb_subfr, 1 ); /* Q0 */ } #endif } @@ -735,7 +735,7 @@ void decod_audio_ivas_fx( test(); if ( EQ_16( st_fx->L_frame, L_FRAME16k ) && EQ_16( nb_subfr, NB_SUBFR ) ) { - nb_subfr = NB_SUBFR16k; + nb_subfr = NB_SUBFR16k; /* Q0 */ move16(); } #endif @@ -745,29 +745,29 @@ void decod_audio_ivas_fx( IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) ) { - nbits = 3; + nbits = 3; /* Q0 */ move16(); test(); if ( LT_32( st_fx->core_brate, ACELP_9k60 ) && ( st_fx->coder_type == INACTIVE ) ) { - nbits = 1; + nbits = 1; /* Q0 */ move16(); } } ELSE { - nbits = 4; + nbits = 4; /* Q0 */ move16(); } test(); IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type != INACTIVE ) { - pit_band_idx = 1; + pit_band_idx = 1; /* Q0 */ move16(); } ELSE { - pit_band_idx = (Word16) get_next_indice_fx( st_fx, nbits ); + pit_band_idx = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */ move16(); } @@ -775,26 +775,26 @@ void decod_audio_ivas_fx( { IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) { - pit_band_idx = 7 + BAND1k2; - move16(); /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */ + pit_band_idx = 7 + BAND1k2; /* Q0 */ + move16(); /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */ } ELSE { - pit_band_idx = add( pit_band_idx, BAND1k2 ); + pit_band_idx = add( pit_band_idx, BAND1k2 ); /* Q0 */ } /* detect bit errors in the bitstream */ IF( GT_16( pit_band_idx, 13 ) ) /* The maximum decodable index is 10 + BAND1k2 (3) = 13 */ { - pit_band_idx = 13; + pit_band_idx = 13; /* Q0 */ move16(); - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } - Diff_len = mfreq_loc_div_25[pit_band_idx]; + Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ move16(); } - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ move16(); @@ -824,15 +824,15 @@ void decod_audio_ivas_fx( #endif { Word16 indice; - nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; + nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; /* Q0 */ move16(); if ( st_fx->element_mode > EVS_MONO ) { - nbits = 5; + nbits = 5; /* Q0 */ move16(); } - indice = get_next_indice_fx( st_fx, nbits ); + indice = get_next_indice_fx( st_fx, nbits ); /* Q0 */ Es_pred_dec_fx( &Es_pred, indice, nbits, 0 ); } @@ -848,28 +848,28 @@ void decod_audio_ivas_fx( IF( LT_16( low_pit, 64 ) ) { - pit_band_idx = 9 + BAND1k2; + pit_band_idx = 9 + BAND1k2; /* Q0 */ move16(); if ( st_fx->bwidth == NB ) { - pit_band_idx = 7 + BAND1k2; + pit_band_idx = 7 + BAND1k2; /* Q0 */ move16(); } } ELSE IF( LT_16( low_pit, 128 ) ) { - pit_band_idx = 5 + BAND1k2; + pit_band_idx = 5 + BAND1k2; /* Q0 */ move16(); } ELSE { - pit_band_idx = 3 + BAND1k2; + pit_band_idx = 3 + BAND1k2; /* Q0 */ move16(); } - Diff_len = mfreq_loc_div_25[pit_band_idx]; + Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ move16(); - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ move16(); } @@ -882,18 +882,18 @@ void decod_audio_ivas_fx( * Reset unvaluable part of the adaptive (pitch) excitation contribution *---------------------------------------------------------------*/ - max_len = sub( st_fx->L_frame, Diff_len ); + max_len = sub( st_fx->L_frame, Diff_len ); /* Q0 */ if ( st_fx->bwidth == NB ) { - max_len = sub( 160, Diff_len ); + max_len = sub( 160, Diff_len ); /* Q0 */ } Len = 80; move16(); if ( LT_16( max_len, 80 ) ) { - Len = max_len; + Len = max_len; /* Q0 */ move16(); } @@ -902,7 +902,7 @@ void decod_audio_ivas_fx( { FOR( i = 0; i < max_len; i++ ) { - dct_epit[add( i, Diff_len )] = 0; + dct_epit[i + Diff_len] = 0; move16(); } } @@ -910,23 +910,23 @@ void decod_audio_ivas_fx( { FOR( i = 0; i < Len; i++ ) { - dct_epit[add( i, Diff_len )] = mult_r( dct_epit[add( i, Diff_len )], sm_table_fx[i] ); + dct_epit[i + Diff_len] = mult_r( dct_epit[i + Diff_len], sm_table_fx[i] ); /* Qx */ move16(); } FOR( ; i < max_len; i++ ) { - dct_epit[add( i, Diff_len )] = 0; + dct_epit[i + Diff_len] = 0; move16(); } } // PMT("in the rare case of 4 subfr, bfi_pitch_fx might be wrong") - st_fx->bfi_pitch_fx = mean_fx( pitch_buf, nb_subfr ); + st_fx->bfi_pitch_fx = mean_fx( pitch_buf, nb_subfr ); /* Q6 */ move16(); - st_fx->bfi_pitch_frame = st_fx->L_frame; + st_fx->bfi_pitch_frame = st_fx->L_frame; /* Q0 */ move16(); - Diff_len = add( Diff_len, 1 ); + Diff_len = add( Diff_len, 1 ); /* Q0 */ st_fx->bpf_off = 0; move16(); } @@ -939,18 +939,18 @@ void decod_audio_ivas_fx( IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - set16_fx( pitch_buf, shl( L_SUBFR16k, 6 ), NB_SUBFR16k ); + set16_fx( pitch_buf, ( L_SUBFR16k * 64 ), NB_SUBFR16k ); } ELSE { - set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR ); + set16_fx( pitch_buf, L_SUBFR * 64, NB_SUBFR ); } set16_fx( gain_buf, 0, NB_SUBFR16k ); - st_fx->bfi_pitch_fx = shl( L_SUBFR, 6 ); + st_fx->bfi_pitch_fx = L_SUBFR * 64; move16(); - st_fx->bfi_pitch_frame = st_fx->L_frame; + st_fx->bfi_pitch_frame = st_fx->L_frame; /* Q0 */ move16(); st_fx->lp_gainp_fx = 0; move16(); @@ -970,7 +970,7 @@ void decod_audio_ivas_fx( /* find the current total number of bits used */ - tmp_nb_bits_tot = st_fx->next_bit_pos; + tmp_nb_bits_tot = st_fx->next_bit_pos; /* Q0 */ move16(); #if 1 // def IVAS_CODE if ( st_fx->extl_brate_orig > 0 ) @@ -979,7 +979,7 @@ void decod_audio_ivas_fx( #endif { /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ - tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); /* Q0 */ } @@ -991,16 +991,16 @@ void decod_audio_ivas_fx( if ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) ) #endif { - tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); + tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); /* Q0 */ } #if 1 // ydef ADD_LRTD IF( EQ_16( st_fx->idchan, 1 ) ) { - tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); + tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); /* Q0 */ if ( EQ_16( st_fx->tdm_LRTD_flag, 1 ) ) { - tmp_nb_bits_tot = sub( tmp_nb_bits_tot, STEREO_BITS_TCA ); + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, STEREO_BITS_TCA ); /* Q0 */ } } #endif @@ -1012,11 +1012,11 @@ void decod_audio_ivas_fx( Q_exc_old = sub( Q_exc_old, st_fx->Q_exc ); IF( st_fx->hGSCDec ) { - Scale_sig( st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME16k, Q_exc_old ); + Scale_sig( st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME16k, Q_exc_old ); /* Q_exc_old */ } IF( bwe_exc ) { - Scale_sig( bwe_exc - PIT16k_MAX * 2, ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2, Q_exc_old ); + Scale_sig( bwe_exc - PIT16k_MAX * 2, ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2, Q_exc_old ); /* Q_exc_old */ } } /*--------------------------------------------------------------------------------------* @@ -1051,8 +1051,8 @@ void decod_audio_ivas_fx( * Updates *--------------------------------------------------------------------------------------*/ - Copy( exc, exc2, st_fx->L_frame ); - Copy( exc_wo_nf, exc, st_fx->L_frame ); + Copy( exc, exc2, st_fx->L_frame ); /* Q_exc */ + Copy( exc_wo_nf, exc, st_fx->L_frame ); /* Q_exc */ /*--------------------------------------------------------------------------------------* * Channel aware mode parameters @@ -1088,15 +1088,15 @@ void decod_audio_ivas_fx( /*==========================================================================*/ void gsc_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 coder_type, /* i : coding type */ - Word16 *last_bin, /* i : last bin of bit allocation */ - const Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency Q0*/ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + const Word16 coder_type, /* i : coding type Q0*/ + Word16 *last_bin, /* i : last bin of bit allocation Q0*/ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 Q_exc ) { Word16 i, j, bit, nb_subbands, pvq_len; @@ -1127,6 +1127,8 @@ void gsc_dec_fx( Word16 seed_init; GSC_DEC_HANDLE hGSCDec; hGSCDec = st_fx->hGSCDec; + move16(); + move16(); move16(); // for Mbands_gn move16(); // for Qexc_diffQ @@ -1164,8 +1166,8 @@ void gsc_dec_fx( IF( st_fx->bfi || st_fx->BER_detect ) { /* copy old gain */ - Copy( hGSCDec->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); - mean_gain = mult_r( st_fx->lp_gainc_fx, 3277 ); /*Q3*/ + Copy( hGSCDec->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); /* Q_old_gain */ + mean_gain = mult_r( st_fx->lp_gainc_fx, 3277 ); /*Q3*/ FOR( i = 0; i < Mbands_gn; i++ ) { Ener_per_bd_iQ[i] = add( Ener_per_bd_iQ[i], shl( mean_gain, 9 ) ); /*Q12*/ @@ -1202,7 +1204,7 @@ void gsc_dec_fx( mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); #else - mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, st_fx->core_brate, hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); + mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, st_fx->core_brate, hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); /* Q12 */ #endif st_fx->lp_gainc_fx = mult_r( 640, mean_gain ); /*10 in Q6 x Q12 -> lp_gainc in Q3 */ move16(); @@ -1239,13 +1241,13 @@ void gsc_dec_fx( FOR( i = 0; i < st_fx->L_frame; i++ ) { L_tmp = L_shr( L_mult( Random( &hGSCDec->seed_tcx ), 26214 ), 5 ); /*Q10*/ - L_tmp = L_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); - hGSCDec->Last_GSC_spectrum_fx[i] = round_fx( L_tmp ); /*Q10*/ + L_tmp = L_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); /* Q10 */ + hGSCDec->Last_GSC_spectrum_fx[i] = round_fx( L_tmp ); /*Q10*/ move16(); } } - Copy( hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame ); + Copy( hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame ); /* Q10 */ FOR( i = 0; i < st_fx->L_frame; i++ ) { @@ -1271,7 +1273,7 @@ void gsc_dec_fx( #endif { pvq_core_dec_fx( st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); - Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); + Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */ } seed_init = 0; move16(); @@ -1290,34 +1292,34 @@ void gsc_dec_fx( /* Reorder Q bands */ FOR( j = 0; j < nb_subbands; j++ ) { - Copy( concat_out + j * 16, exc_diffQ + max_ener_band[j] * 16, 16 ); + Copy( concat_out + shl( j, 4 ), exc_diffQ + shl( max_ener_band[j], 4 ), 16 ); /* Q_PVQ_OUT */ - *last_bin = s_max( *last_bin, max_ener_band[j] ); + *last_bin = s_max( *last_bin, max_ener_band[j] ); /* Q0 */ move16(); - bitallocation_band[max_ener_band[j]] = 1; + bitallocation_band[max_ener_band[j]] = 1; /* Q0 */ move16(); - seed_init = add( seed_init, inpulses_fx[j] ); + seed_init = add( seed_init, inpulses_fx[j] ); /* Q0 */ } test(); IF( NE_16( st_fx->last_coder_type, AUDIO ) /* First audio frame */ && NE_16( st_fx->last_coder_type, UNVOICED ) ) /* last_coder_type == INACTIVE is overwritten in update_dec to UNVOICED */ { - FOR( j = 0; j < shl( nb_subbands, 4 ); j++ ) + FOR( j = 0; j < nb_subbands * 16; j++ ) { IF( concat_out[j] > 0 ) { - seed_init = extract_l( L_shl( seed_init, 3 ) ); + seed_init = extract_l( L_shl( seed_init, 3 ) ); /* Q0 */ } if ( concat_out[j] < 0 ) { - seed_init = add( seed_init, 3 ); + seed_init = add( seed_init, 3 ); /* Q0 */ move16(); } } - hGSCDec->seed_tcx = seed_init; + hGSCDec->seed_tcx = seed_init; /* Q0 */ move16(); } test(); @@ -1325,18 +1327,18 @@ void gsc_dec_fx( { if ( exc_diffQ[L_FRAME8k - 2] != 0 ) { - bitallocation_exc[0] = 1; + bitallocation_exc[0] = 1; /* Q0 */ move16(); } if ( exc_diffQ[L_FRAME8k - 1] != 0 ) { - bitallocation_exc[1] = 1; + bitallocation_exc[1] = 1; /* Q0 */ move16(); } } - Copy( exc_diffQ, hGSCDec->Last_GSC_spectrum_fx, st_fx->L_frame ); + Copy( exc_diffQ, hGSCDec->Last_GSC_spectrum_fx, st_fx->L_frame ); /* Q_PVQ_OUT */ /*--------------------------------------------------------------------------------------* * Skip adaptive (pitch) contribution frequency band (no noise added over the time contribution) @@ -1413,15 +1415,15 @@ void gsc_dec_fx( /*==========================================================================*/ void gsc_dec_ivas_fx( Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 coder_type, /* i : coding type */ - Word16 *last_bin, /* i : last bin of bit allocation */ - const Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency ` Q0*/ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + const Word16 coder_type, /* i : coding type Q0*/ + Word16 *last_bin, /* i : last bin of bit allocation Q0*/ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 *Q_exc ) { Word16 i, j, bit, nb_subbands, pvq_len; @@ -1470,12 +1472,12 @@ void gsc_dec_ivas_fx( test(); if ( coder_type == INACTIVE && ( EQ_16( st_fx->tdm_LRTD_flag, 1 ) || EQ_16( st_fx->element_mode, IVAS_SCE ) ) && LE_32( st_fx->core_brate, GSC_LRES_GAINQ_LIMIT ) ) { - bit = add( bit, GSC_LRES_NB_NITS ); + bit = add( bit, GSC_LRES_NB_NITS ); /* Q0 */ } if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - Mbands_gn = MBANDS_GN16k; + Mbands_gn = MBANDS_GN16k; /* Q0 */ move16(); } #endif @@ -1489,8 +1491,8 @@ void gsc_dec_ivas_fx( IF( st_fx->bfi || st_fx->BER_detect ) { /* copy old gain */ - Copy( hGSCDec->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); - mean_gain = mult_r( st_fx->lp_gainc_fx, 3277 ); /*Q3*/ + Copy( hGSCDec->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); /* Q_old_gain */ + mean_gain = mult_r( st_fx->lp_gainc_fx, 3277 ); /*Q3*/ FOR( i = 0; i < Mbands_gn; i++ ) { Ener_per_bd_iQ[i] = add( Ener_per_bd_iQ[i], shl( mean_gain, 9 ) ); /*Q12*/ @@ -1512,7 +1514,7 @@ void gsc_dec_ivas_fx( { break; } - i = add( i, 1 ); + i++; } test(); @@ -1521,9 +1523,9 @@ void gsc_dec_ivas_fx( if ( st_fx->element_mode > EVS_MONO && EQ_16( coder_type, AUDIO ) && LE_32( st_fx->core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation is mapped to 8 kb/s instead of 9.6 kb/s in this case */ { - i = sub( i, 1 ); + i--; } - mean_gain = gsc_gaindec_ivas_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); + mean_gain = gsc_gaindec_ivas_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); /* Q3 */ #else mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, st_fx->core_brate, hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); @@ -1563,13 +1565,13 @@ void gsc_dec_ivas_fx( FOR( i = 0; i < st_fx->L_frame; i++ ) { L_tmp = L_shr( L_mult( Random( &hGSCDec->seed_tcx ), 26214 ), 5 ); /*Q10*/ - L_tmp = L_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); - hGSCDec->Last_GSC_spectrum_fx[i] = round_fx( L_tmp ); /*Q10*/ + L_tmp = L_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); /* Q10 */ + hGSCDec->Last_GSC_spectrum_fx[i] = round_fx( L_tmp ); /*Q10*/ move16(); } } - Copy( hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame ); + Copy( hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame ); /* Q10 */ FOR( i = 0; i < st_fx->L_frame; i++ ) { @@ -1595,7 +1597,7 @@ void gsc_dec_ivas_fx( #endif { pvq_core_dec_fx( st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); - Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); + Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */ } seed_init = 0; move16(); @@ -1603,7 +1605,7 @@ void gsc_dec_ivas_fx( #if 1 // def ADD_LRTD max_eq = 0; move16(); - max_eq_val = 32767; + max_eq_val = 32767; /* 1.0f in Q15 */ move16(); test(); @@ -1616,7 +1618,7 @@ void gsc_dec_ivas_fx( Word16 temp_max_eq = add( abs_s( concat_out[j] ), 10 ) /*0.01f in Q10*/; if ( LE_16( temp_max_eq, ONE_IN_Q10 ) ) { - max_eq = max_eq_val; + max_eq = max_eq_val; /* Q15 */ move16(); } ELSE @@ -1624,22 +1626,22 @@ void gsc_dec_ivas_fx( Word16 exp = 5; move16(); max_eq = Inv16( temp_max_eq, &exp ); - max_eq = shl( max_eq, exp ); + max_eq = shl( max_eq, exp ); /* Q15 */ } } #endif /* Reorder Q bands */ FOR( j = 0; j < nb_subbands; j++ ) { - Copy( concat_out + imult1616( j, 16 ), exc_diffQ + imult1616( max_ener_band[j], 16 ), 16 ); + Copy( concat_out + imult1616( j, 16 ), exc_diffQ + imult1616( max_ener_band[j], 16 ), 16 ); /* Q_PVQ_OUT */ - *last_bin = s_max( *last_bin, max_ener_band[j] ); + *last_bin = s_max( *last_bin, max_ener_band[j] ); /* Q0 */ move16(); - bitallocation_band[max_ener_band[j]] = 1; + bitallocation_band[max_ener_band[j]] = 1; /* Q0 */ move16(); - seed_init = add( seed_init, inpulses_fx[j] ); + seed_init = add( seed_init, inpulses_fx[j] ); /* Q0 */ } test(); IF( NE_16( st_fx->last_coder_type, AUDIO ) /* First audio frame */ @@ -1649,19 +1651,19 @@ void gsc_dec_ivas_fx( { IF( concat_out[j] > 0 ) { - seed_init = extract_l( L_shl( seed_init, 3 ) ); + seed_init = extract_l( L_shl( seed_init, 3 ) ); /* Q0 */ } if ( concat_out[j] < 0 ) { #ifdef BASOP_NOGLOB_TMP_715 - seed_init = add_sat( seed_init, 3 ); + seed_init = add_sat( seed_init, 3 ); /* Q0 */ #else seed_init = add( seed_init, 3 ); #endif } } - hGSCDec->seed_tcx = seed_init; + hGSCDec->seed_tcx = seed_init; /* Q0 */ move16(); } test(); @@ -1669,18 +1671,18 @@ void gsc_dec_ivas_fx( { if ( exc_diffQ[L_FRAME8k - 2] != 0 ) { - bitallocation_exc[0] = 1; + bitallocation_exc[0] = 1; /* Q0 */ move16(); } if ( exc_diffQ[L_FRAME8k - 1] != 0 ) { - bitallocation_exc[1] = 1; + bitallocation_exc[1] = 1; /* Q0 */ move16(); } } - Copy( exc_diffQ, hGSCDec->Last_GSC_spectrum_fx, st_fx->L_frame ); + Copy( exc_diffQ, hGSCDec->Last_GSC_spectrum_fx, st_fx->L_frame ); /* Q_PVQ_OUT */ /*--------------------------------------------------------------------------------------* * Skip adaptive (pitch) contribution frequency band (no noise added over the time contribution) @@ -1698,7 +1700,7 @@ void gsc_dec_ivas_fx( { // PMT("GSC FIX point to be done here") // exc_diffQ[i] *= max_eq; - exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); + exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); /* Q_PVQ_OUT */ move16(); } } @@ -1708,7 +1710,7 @@ void gsc_dec_ivas_fx( { // PMT("GSC FIX point to be done here") // exc_diffQ[i] *= max_eq; - exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); + exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); /* Q_PVQ_OUT */ move16(); } } @@ -1744,12 +1746,12 @@ void GSC_dec_init( GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ) { - hGSCDec->seed_tcx = 15687; + hGSCDec->seed_tcx = 15687; /* Q0 */ hGSCDec->cor_strong_limit = 1; move16(); move16(); - hGSCDec->noise_lev = NOISE_LEVEL_SP0; + hGSCDec->noise_lev = NOISE_LEVEL_SP0; /* Q0 */ hGSCDec->Last_GSC_pit_band_idx = 0; move16(); move16(); @@ -1778,7 +1780,7 @@ void GSC_dec_init_ivas_fx( GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ) { - hGSCDec->seed_tcx = 15687; + hGSCDec->seed_tcx = 15687; /* Q0 */ move16(); hGSCDec->cor_strong_limit = 1; move16(); diff --git a/lib_dec/hdecnrm_fx.c b/lib_dec/hdecnrm_fx.c index 9c8b6fa01f05e8adda6fb8a255d279ecb39eb630..291aa87fb7a4e81c1f39e0a48ae1a27e0431632a 100644 --- a/lib_dec/hdecnrm_fx.c +++ b/lib_dec/hdecnrm_fx.c @@ -13,18 +13,18 @@ /* Huffman decoding for indices of quantized norms */ /*--------------------------------------------------------------------------*/ void hdecnrm_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 numNorms, /* i : number of norms */ - Word16 *index ) /* o : indices of quantized norms */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 numNorms, /* i : number of norms Q0*/ + Word16 *index ) /* o : indices of quantized norms Q0*/ { Word16 i, j, k, n, m; Word16 temp; Word16 *pidx; - pidx = index; + pidx = index; /* Q0 */ - m = sub( numNorms, 1 ); + m = sub( numNorms, 1 ); /* Q0 */ FOR( i = 0; i < m; i++ ) { j = (Word16) 0; @@ -34,51 +34,51 @@ void hdecnrm_fx( if ( get_next_indice_1_fx( st_fx ) != 0 ) { - j = (Word16) 1; + j = (Word16) 1; /* Q0 */ move16(); } if ( get_next_indice_1_fx( st_fx ) != 0 ) { - k = (Word16) 1; + k = (Word16) 1; /* Q0 */ move16(); } - n = add( shl( j, 1 ), k ); - j = shl( j, 2 ); - temp = sub( add( 16, n ), j ); + n = add( shl( j, 1 ), k ); /* Q0 */ + j = shl( j, 2 ); /* Q0 */ + temp = sub( add( 16, n ), j ); /* Q0 */ IF( get_next_indice_1_fx( st_fx ) != 0 ) { - temp = add( add( 12, n ), j ); + temp = add( add( 12, n ), j ); /* Q0 */ IF( get_next_indice_1_fx( st_fx ) != 0 ) { j = (Word16) 0; move16(); if ( get_next_indice_1_fx( st_fx ) != 0 ) { - j = 1; + j = 1; /* Q0 */ move16(); } - temp = add( 8, n ); + temp = add( 8, n ); /* Q0 */ if ( j != 0 ) { - temp = add( temp, 12 ); + temp = add( temp, 12 ); /* Q0 */ } IF( get_next_indice_1_fx( st_fx ) != 0 ) { - temp = n; + temp = n; /* Q0 */ move16(); if ( get_next_indice_1_fx( st_fx ) != 0 ) { - temp = add( 4, n ); + temp = add( 4, n ); /* Q0 */ } if ( j != 0 ) { - temp = add( temp, 24 ); + temp = add( temp, 24 ); /* Q0 */ } } } } - *pidx++ = temp; + *pidx++ = temp; /* Q0 */ move16(); } @@ -96,9 +96,10 @@ void hdecnrm_fx( /*--------------------------------------------------------------------------*/ Word16 decode_huff_context_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *hufftab, - Word16 *rbits ) + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *hufftab, /* Q0 */ + Word16 *rbits /* Q0 */ +) { Word16 tmp_l, tmp_h; Word32 hufftab_idx; @@ -106,11 +107,11 @@ Word16 decode_huff_context_fx( hufftab_idx = L_deposit_l( 0 ); WHILE( hufftab[hufftab_idx] > 0 ) { - tmp_h = shr( hufftab[hufftab_idx], 4 ); - tmp_l = sub( hufftab[hufftab_idx], shl( tmp_h, 4 ) ); - *rbits = add( *rbits, tmp_l ); + tmp_h = shr( hufftab[hufftab_idx], 4 ); /* Q0 */ + tmp_l = sub( hufftab[hufftab_idx], shl( tmp_h, 4 ) ); /* Q0 */ + *rbits = add( *rbits, tmp_l ); /* Q0 */ move16(); - hufftab_idx = L_add( hufftab_idx, L_add( L_deposit_l( tmp_h ), get_next_indice_fx( st_fx, tmp_l ) ) ); + hufftab_idx = L_add( hufftab_idx, L_add( L_deposit_l( tmp_h ), get_next_indice_fx( st_fx, tmp_l ) ) ); /* Q0 */ } return negate( hufftab[hufftab_idx] ); } @@ -129,20 +130,21 @@ Word16 decode_huff_context_fx( void hdecnrm_context_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, - Word16 *index, - Word16 *n_length ) + const Word16 N, /* Q0 */ + Word16 *index, /* Q0 */ + Word16 *n_length /* Q0 */ +) { Word16 i, prevj, tmp; - prevj = add( index[0], OFFSET_NORM ); + prevj = add( index[0], OFFSET_NORM ); /* Q0 */ FOR( i = 1; i < N; i++ ) { IF( GT_16( prevj, HTH_NORM ) ) { /* above */ - tmp = decode_huff_context_fx( st_fx, hntable, n_length ); - index[i] = sub( 31, tmp ); + tmp = decode_huff_context_fx( st_fx, hntable, n_length ); /* Q0 */ + index[i] = sub( 31, tmp ); /* Q0 */ move16(); } ELSE @@ -150,17 +152,17 @@ void hdecnrm_context_fx( IF( LT_16( prevj, LTH_NORM ) ) { /* less */ - index[i] = decode_huff_context_fx( st_fx, hntable, n_length ); + index[i] = decode_huff_context_fx( st_fx, hntable, n_length ); /* Q0 */ move16(); } ELSE { /* equal */ - index[i] = decode_huff_context_fx( st_fx, hetable, n_length ); + index[i] = decode_huff_context_fx( st_fx, hetable, n_length ); /* Q0 */ move16(); } } - prevj = index[i]; + prevj = index[i]; /* Q0 */ move16(); } return; @@ -168,17 +170,17 @@ void hdecnrm_context_fx( void hdecnrm_resize_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* (i) number of SFMs */ - Word16 *index /* (o) norm quantization index vector */ + const Word16 N, /* (i) number of SFMs Q0*/ + Word16 *index /* (o) norm quantization index vector Q0*/ ) { Word16 i, j, k, m; Word16 temp; Word16 *pidx; - pidx = index; + pidx = index; /* Q0 */ - m = sub( N, 1 ); + m = sub( N, 1 ); /* Q0 */ move16(); FOR( i = 0; i < m; i++ ) { @@ -191,7 +193,7 @@ void hdecnrm_resize_fx( { IF( get_next_indice_1_fx( st_fx ) != 0 ) { - k = add( k, 1 ); + k = add( k, 1 ); /* Q0 */ move16(); } ELSE @@ -202,31 +204,31 @@ void hdecnrm_resize_fx( IF( EQ_16( k, 11 ) ) { - temp = 25; + temp = 25; /* Q0 */ move16(); } ELSE IF( EQ_16( k, 10 ) ) { - temp = 5; + temp = 5; /* Q0 */ move16(); } ELSE IF( EQ_16( k, 9 ) ) { - temp = 6; + temp = 6; /* Q0 */ move16(); } ELSE{ IF( get_next_indice_1_fx( st_fx ) != 0 ){ - temp = add( 16, k ); + temp = add( 16, k ); /* Q0 */ } ELSE { - temp = sub( 15, k ); + temp = sub( 15, k ); /* Q0 */ move16(); } } -*pidx++ = temp; +*pidx++ = temp; /* Q0 */ move16(); } @@ -241,20 +243,20 @@ return; void huff_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* i : Number of codewords to decode */ - const Word16 buffer_len, /* i : Number of bits to read */ - const Word16 num_lengths, /* i : Number of different huffman codeword lengths */ - const Word16 *thres, /* i : Threshold of first codeword of each length */ - const Word16 *offset, /* i : Offset for first codeword */ - const Word16 *huff_tab, /* i : Huffman table order by codeword lengths */ - Word16 *index /* o : Decoded index */ + const Word16 N, /* i : Number of codewords to decode Q0*/ + const Word16 buffer_len, /* i : Number of bits to read Q0*/ + const Word16 num_lengths, /* i : Number of different huffman codeword lengths Q0*/ + const Word16 *thres, /* i : Threshold of first codeword of each length Q0*/ + const Word16 *offset, /* i : Offset for first codeword Q0*/ + const Word16 *huff_tab, /* i : Huffman table order by codeword lengths Q0*/ + Word16 *index /* o : Decoded index Q0*/ ) { Word16 i, j, k; UWord16 val; Word16 last_bits; - last_bits = buffer_len; + last_bits = buffer_len; /* Q0 */ move16(); val = 0; @@ -263,24 +265,24 @@ void huff_dec_fx( move16(); FOR( i = 0; i < N; i++ ) { - last_bits = sub( buffer_len, j ); - val = (UWord16) L_shl( val, last_bits ); - val = (UWord16) L_and( val, sub( lshl( 1, buffer_len ), 1 ) ); - val = (UWord16) L_or( val, get_next_indice_fx( st_fx, last_bits ) ); + last_bits = sub( buffer_len, j ); /* Q0 */ + val = (UWord16) L_shl( val, last_bits ); /* Q0 */ + val = (UWord16) L_and( val, sub( lshl( 1, buffer_len ), 1 ) ); /* Q0 */ + val = (UWord16) L_or( val, get_next_indice_fx( st_fx, last_bits ) ); /* Q0 */ /* Find codeword length */ - j = sub( num_lengths, 1 ); + j = sub( num_lengths, 1 ); /* Q0 */ WHILE( LT_16( val, thres[j] ) ) { - j = sub( j, 1 ); + j = sub( j, 1 ); /* Q0 */ } - k = lshr( sub( val, thres[j] ), j ); - *index++ = huff_tab[add( offset[j], k )]; + k = lshr( sub( val, thres[j] ), j ); /* Q0 */ + *index++ = huff_tab[offset[j] + k]; /* Q0 */ move16(); } /* Put back unused bits */ - st_fx->next_bit_pos = sub( st_fx->next_bit_pos, j ); + st_fx->next_bit_pos = sub( st_fx->next_bit_pos, j ); /* Q0 */ move16(); return; @@ -293,9 +295,9 @@ void huff_dec_fx( *--------------------------------------------------------------------------*/ void hdecnrm_tran_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* i : number of norms */ - Word16 *index /* o : indices of quantized norms */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 N, /* i : number of norms Q0*/ + Word16 *index /* o : indices of quantized norms Q0*/ ) { Word16 i, j, k, n, m; @@ -303,9 +305,9 @@ void hdecnrm_tran_fx( Word16 *pidx; Word16 l; - pidx = index; + pidx = index; /* Q0 */ - m = sub( N, 1 ); + m = sub( N, 1 ); /* Q0 */ FOR( i = 0; i < m; i++ ) { j = 0; @@ -314,20 +316,20 @@ void hdecnrm_tran_fx( move16(); if ( get_next_indice_1_fx( st_fx ) != 0 ) { - j = 1; + j = 1; /* Q0 */ move16(); } if ( get_next_indice_1_fx( st_fx ) != 0 ) { - k = 1; + k = 1; /* Q0 */ move16(); } /*n = k * 2 + j; */ - n = add( shl( k, 1 ), j ); + n = add( shl( k, 1 ), j ); /* Q0 */ /*l = k * 4; */ - l = shl( k, 2 ); + l = shl( k, 2 ); /* Q0 */ test(); test(); test(); @@ -335,22 +337,22 @@ void hdecnrm_tran_fx( test(); IF( ( j == 0 && k == 0 ) || ( EQ_16( j, 1 ) && k == 0 ) || ( EQ_16( j, 1 ) && EQ_16( k, 1 ) ) ) { - temp = sub( add( 15, l ), n ); + temp = sub( add( 15, l ), n ); /* Q0 */ } ELSE{ IF( get_next_indice_1_fx( st_fx ) != 0 ){ - temp = sub( add( 15, n ), l ); + temp = sub( add( 15, n ), l ); /* Q0 */ } ELSE { - temp = sub( add( 15, l ), n ); + temp = sub( add( 15, l ), n ); /* Q0 */ IF( get_next_indice_1_fx( st_fx ) != 0 ) { FOR( k = 0; k < 3; ) { IF( get_next_indice_1_fx( st_fx ) != 0 ) { - k = add( k, 1 ); + k++; /* Q0 */ } ELSE { @@ -364,22 +366,22 @@ void hdecnrm_tran_fx( temp = sub( temp, 5 ); if ( EQ_16( k, 3 ) ) { - temp = sub( temp, 1 ); + temp = sub( temp, 1 ); /* Q0 */ } } ELSE IF( EQ_16( k, 1 ) ) { - temp = add( temp, 1 ); + temp = add( temp, 1 ); /* Q0 */ } ELSE { - temp = add( temp, 2 ); + temp = add( temp, 2 ); /* Q0 */ IF( get_next_indice_1_fx( st_fx ) != 0 ) { temp = add( temp, 1 ); if ( get_next_indice_1_fx( st_fx ) != 0 ) { - temp = add( temp, 1 ); + temp = add( temp, 1 ); /* Q0 */ } } } @@ -387,7 +389,7 @@ void hdecnrm_tran_fx( } } -*pidx++ = temp; +*pidx++ = temp; /* Q0 */ move16(); } diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index 626796be2bff5f3fa5780d945b94c5a9294f0394..9af04d1f22cb2b4b12ca4e2aec494612ad792dba 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -90,20 +90,20 @@ void hf_synth_reset_fx( *---------------------------------------------------------------------*/ void hf_synth_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az */ - const Word16 *exc, /* i : excitation at 12.8 kHz */ - Word16 *synth, /* i : 12.8kHz synthesis signal */ - Word16 *synth16k, /* o : 16kHz synthesis signal */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc*/ + Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2*/ + Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2*/ const Word16 Q_exc, /* i : excitation scaling */ const Word16 Q_syn2, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ + Word16 *delay_syn_hf, /*i/o: HF synthesis memory Q_syn2*/ Word16 *memExp1, /* o : HF excitation exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ + Word16 *mem_hp_interp, /* i/o: interpol. memory Qx*/ + const Word16 extl, /* i : flag indicating BWE Q0*/ + const Word16 CNG_mode /* i : CNG_mode Q0*/ ) { const Word16 *p_Aq; @@ -112,13 +112,13 @@ void hf_synth_fx( output_subfr = output_frame / NB_SUBFR; move16(); - p_Aq = Aq; + p_Aq = Aq; /* Q12 */ FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) { hf_synthesis_fx( hBWE_zero, core_brate, output_subfr, p_Aq, &exc[i_subfr], Q_exc, &synth[i_subfr], &synth16k[imult3216( (Word32) i_subfr, output_subfr ) / L_SUBFR], Q_syn2, delay_syn_hf, memExp1, mem_hp_interp, extl, CNG_mode ); - p_Aq += ( M + 1 ); + p_Aq += ( M + 1 ); /* Q12 */ } return; @@ -176,19 +176,19 @@ void hf_synth_ivas_fx( static void hf_synthesis_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_subfr, /* i : output sub-frame length */ - const Word16 Aq[], /* i : quantized Az Q12 */ - const Word16 exc[], /* i : excitation at 12.8 kHz Q_exc */ - const Word16 Q_exc, /* i : excitation scaling */ - Word16 synth[], /* i : 12.8kHz synthesis signal Q_syn */ - Word16 synth16k[], /* i/o: 16kHz synthesis signal Q_syn */ - const Word16 Q_syn, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /* i/o: HF synthesis memory Q_syn */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_subfr, /* i : output sub-frame length Q0*/ + const Word16 Aq[], /* i : quantized Az Q12*/ + const Word16 exc[], /* i : excitation at 12.8 kHz Q_exc*/ + const Word16 Q_exc, /* i : excitation scaling */ + Word16 synth[], /* i : 12.8kHz synthesis signal Q_syn*/ + Word16 synth16k[], /* i/o: 16kHz synthesis signal Q_syn*/ + const Word16 Q_syn, /* i : synthesis scaling */ + Word16 *delay_syn_hf, /* i/o: HF synthesis memory Q_syn*/ Word16 *memExp1, /* o : HF excitation scaling exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ + Word16 *mem_hp_interp, /* i/o: interpol. memory Qx*/ + const Word16 extl, /* i : flag indicating BWE Q0*/ + const Word16 CNG_mode /* i : CNG_mode Q0*/ ) { Word16 i; @@ -219,22 +219,22 @@ static void hf_synthesis_fx( *-----------------------------------------------------------------*/ /*ener = sum2_f( exc, L_SUBFR ) + 0.01f*/ - ener = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp2 ) ); + ener = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp2 ) ); /* Q15 */ exp2 = sub( exp2, add( Q_exc, Q_exc ) ); /*tmp = round_fx(Dot_product12(HF_exc, HF_exc, output_subfr, &exp1)); */ L_tmp = Dot_product12( HF_exc, HF_exc, L_SUBFR16k, &exp1 ); - tmp = round_fx( L_tmp ); + tmp = round_fx( L_tmp ); /* Q15 */ /* tmp = (float)(sqrt(ener/tmp)) */ /* scale is -1 if tmp > ener */ - scale = shr( sub( ener, tmp ), 15 ); - tmp = shl( tmp, scale ); + scale = shr( sub( ener, tmp ), 15 ); /* Q0 */ + tmp = shl( tmp, scale ); /* Q15 + scale*/ exp1 = sub( exp1, scale ); - tmp = div_s( tmp, ener ); + tmp = div_s( tmp, ener ); /* Q15 */ exp1 = sub( exp1, exp2 ); - L_tmp = L_deposit_h( tmp ); + L_tmp = L_deposit_h( tmp ); /* Q31 */ L_tmp = Isqrt_lc( L_tmp, &exp1 ); scale = round_fx( L_tmp ); /* Q18 when Q_exc=-1, HF_exc in Q-3 */ @@ -256,11 +256,11 @@ static void hf_synthesis_fx( /* i: synth in Q_syn */ /* o: synth in Q_syn-3 */ - L_tmp = L_mac( 1L, synth[0], synth[0] ); + L_tmp = L_mac( 1L, synth[0], synth[0] ); /* 2*(Q_syn-3)+1 */ FOR( i = 1; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat( L_tmp, synth[i], synth[i] ); + L_tmp = L_mac_sat( L_tmp, synth[i], synth[i] ); /* 2*(Q_syn-3)+1 */ #else L_tmp = L_mac( L_tmp, synth[i], synth[i] ); #endif @@ -269,11 +269,11 @@ static void hf_synthesis_fx( ener = extract_h( L_shl( L_tmp, tmp ) ); /* ener = r[0] */ /*ener in Q = 2*(Q_syn-3)+1 = Q-5 when Q_syn=0*/ - L_tmp = L_mac( 1L, synth[1], synth[0] ); + L_tmp = L_mac( 1L, synth[1], synth[0] ); /* 2*(Q_syn-3)+1 */ FOR( i = 2; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat( L_tmp, synth[i], synth[i - 1] ); + L_tmp = L_mac_sat( L_tmp, synth[i], synth[i - 1] ); /* 2*(Q_syn-3)+1 */ #else L_tmp = L_mac( L_tmp, synth[i], synth[i - 1] ); #endif @@ -287,7 +287,7 @@ static void hf_synthesis_fx( tmp = s_max( 0, tmp ); if ( tmp > 0 ) { - tmp = div_s( tmp, ener ); + tmp = div_s( tmp, ener ); /* Q15 */ } /*-----------------------------------------------------------------* @@ -296,7 +296,7 @@ static void hf_synthesis_fx( /* tmp = 1.0 - fac */ #ifdef BASOP_NOGLOB - tmp = add_o( 1, sub( 32767, tmp ), &Overflow ); + tmp = add_o( 1, sub( 32767 /* 1 in Q15 */, tmp ), &Overflow ); #else tmp = add( 1, sub( 32767, tmp ) ); #endif @@ -306,7 +306,7 @@ static void hf_synthesis_fx( /* emphasize HF noise in CNG */ /*fac *= 2.0f;*/ #ifdef BASOP_NOGLOB - tmp = add_o( tmp, tmp, &Overflow ); + tmp = add_o( tmp, tmp, &Overflow ); /* Q15 */ #else tmp = add( tmp, tmp ); #endif @@ -347,10 +347,10 @@ static void hf_synthesis_fx( /* delay by 5 samples @16kHz to compensate CLDFB resampling delay (20samples) and HP filtering delay (roughly 15 samples) */ delay = NS2SA_FX2( 16000, DELAY_CLDFB_NS ) - 15; - Copy( HF_syn + sub( L_SUBFR16k, delay ), temp_buffer, delay ); - Copy( HF_syn, HF_syn + delay, sub( L_SUBFR16k, delay ) ); - Copy( delay_syn_hf, HF_syn, delay ); - Copy( temp_buffer, delay_syn_hf, delay ); + Copy( HF_syn + sub( L_SUBFR16k, delay ), temp_buffer, delay ); /* Q_syn+exp1 */ + Copy( HF_syn, HF_syn + delay, sub( L_SUBFR16k, delay ) ); /* Q_syn+exp1 */ + Copy( delay_syn_hf, HF_syn, delay ); /* Q_syn */ + Copy( temp_buffer, delay_syn_hf, delay ); /* Q_syn */ /* interpolate the HF synthesis */ IF( EQ_16( output_subfr, L_SUBFR48k ) ) /* 48kHz sampled output */ @@ -360,12 +360,12 @@ static void hf_synthesis_fx( s = s_max( s_min( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, INTERP_3_1_MEM_LEN - 3 ) ), 3 ), sub( Find_Max_Norm16( mem_hp_interp + INTERP_3_1_MEM_LEN - 3, 3 ), 1 ) ), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Q_syn+exp1+s */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); /* Qx + s */ interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp ); - Scale_sig( upsampled_HF_syn, 3 * L_SUBFR16k, -s ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); + Scale_sig( upsampled_HF_syn, 3 * L_SUBFR16k, -s ); /* Q_syn + exp1 + s */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); /* Qx */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Q_syn+exp1 */ } Scale_sig( upsampled_HF_syn, L_SUBFR48k, -1 ); } @@ -374,17 +374,17 @@ static void hf_synthesis_fx( { Word16 s; s = s_max( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP ) ), 2 ), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Q_syn+exp1+s */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); /* Qx + s */ Interpolate_allpass_steep_fx( HF_syn, mem_hp_interp, L_SUBFR16k, upsampled_HF_syn ); - Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); - Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); + Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); /* Q_syn + exp1 */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); /* Qx */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Q_syn+exp1 */ } } ELSE /* 16kHz sampled output */ { - Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); + Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); /* Q_syn */ } Vr_add( synth16k, upsampled_HF_syn, synth16k, output_subfr ); @@ -630,11 +630,11 @@ static void hf_synthesis_ivas_fx( * (gain=4.0) *-------------------------------------------------------------------*/ static void filt_6k_7k_scale_fx( - Word16 signal[], /* i/o: signal */ - Word16 lg, /* i : length of input */ - Word16 mem[], /* i/o: memory (size=30) */ - Word16 fact, /* i : multiply factor */ - Word16 exp /* i : Mem Exponent */ + Word16 signal[], /* i/o: signal Qx*/ + Word16 lg, /* i : length of input Q0*/ + Word16 mem[], /* i/o: memory (size=30) exp*/ + Word16 fact, /* i : multiply factor Q0*/ + Word16 exp /* i : Mem Exponent */ ) { Word16 i, x[L_FRAME48k / NB_SUBFR + ( L_FIR - 1 )]; @@ -647,8 +647,8 @@ static void filt_6k_7k_scale_fx( FOR( i = 0; i < lg; i++ ) { - x[i + L_FIR - 1] = shr( mult( signal[i], fact ), 2 ); - move16(); /* gain of filter = 4 */ + x[i + L_FIR - 1] = shr( mult( signal[i], fact ), 2 ); /* Qx - 2 */ + move16(); /* gain of filter = 4 */ } FOR( i = 0; i < lg; i++ ) { @@ -659,20 +659,20 @@ static void filt_6k_7k_scale_fx( FOR( j = 0; j < 31; j++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_o( L_tmp, x[i + j], fir_6k_7k_fx[j], &Overflow ); + L_tmp = L_mac_o( L_tmp, x[i + j], fir_6k_7k_fx[j], &Overflow ); /* Q16 */ #else L_tmp = L_mac( L_tmp, x[i + j], fir_6k_7k_fx[j] ); #endif } #ifdef BASOP_NOGLOB - signal[i] = round_fx_o( L_tmp, &Overflow ); + signal[i] = round_fx_o( L_tmp, &Overflow ); /* Q0 */ move16(); #else signal[i] = round_fx( L_tmp ); #endif } - Copy( x + lg, mem, L_FIR - 1 ); + Copy( x + lg, mem, L_FIR - 1 ); /* Qx - 2 */ } /*-------------------------------------------------------------------* @@ -694,7 +694,7 @@ void hf_synth_amr_wb_init_fx( hAmrwb_IO->frame_count_fx = 0; move16(); hAmrwb_IO->ne_min_fx = -7680; - move16(); /*Q8*/ + move16(); /*-30.0f in Q8*/ hAmrwb_IO->fmerit_m_sm_fx = 0; move16(); hAmrwb_IO->voice_fac_amr_wb_hf = 0; @@ -702,7 +702,7 @@ void hf_synth_amr_wb_init_fx( hAmrwb_IO->unvoicing_fx = 0; move16(); hAmrwb_IO->unvoicing_sm_fx = 32767; - move16(); /*Q15*/ + move16(); /*1.0f in Q15*/ hAmrwb_IO->unvoicing_flag_fx = 0; move16(); hAmrwb_IO->voicing_flag_fx = 0; @@ -710,7 +710,7 @@ void hf_synth_amr_wb_init_fx( hAmrwb_IO->start_band_old_fx = 160; move16(); hAmrwb_IO->OptCrit_old_fx = 32768; - move32(); /*Q15*/ + move32(); /*1.0f in Q15*/ ; return; } @@ -746,7 +746,7 @@ void hf_synth_amr_wb_reset_fx( hAmrwb_IO->frame_count_fx = 0; move16(); hAmrwb_IO->ne_min_fx = -7680; - move16(); /*Q8*/ + move16(); /*-30.0f in Q8*/ hAmrwb_IO->fmerit_m_sm_fx = 0; move16(); hAmrwb_IO->voice_fac_amr_wb_hf = 0; @@ -754,7 +754,7 @@ void hf_synth_amr_wb_reset_fx( hAmrwb_IO->unvoicing_fx = 0; move16(); hAmrwb_IO->unvoicing_sm_fx = 32767; - move16(); /*Q15*/ + move16(); /*1.0f in Q15*/ hAmrwb_IO->unvoicing_flag_fx = 0; move16(); hAmrwb_IO->voicing_flag_fx = 0; @@ -762,7 +762,7 @@ void hf_synth_amr_wb_reset_fx( hAmrwb_IO->start_band_old_fx = 160; move16(); hAmrwb_IO->OptCrit_old_fx = 32768; - move32(); /*Q15*/ + move32(); /*1.0f in Q15*/ return; } @@ -776,21 +776,21 @@ void hf_synth_amr_wb_reset_fx( void hf_synth_amr_wb_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */ ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az : Q12 */ - const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc */ - Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn */ - Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) */ - Word16 *synth_out, /* i/o: output signal at output Fs : Q_out */ - Word16 fmerit, /* i : classify parameter from FEC : Q14 */ - const Word16 *hf_gain, /* i : decoded HF gain */ - const Word16 *voice_factors, /* i : voicing factors : Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer : Q5 */ - const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8 */ - const Word16 *lsf_new, /* i : ISF vector : Q2 */ - const Word16 Q_exc, /* i : exc scaling */ - const Word16 Q_out /* i : Q_syn2-1 */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az : Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc*/ + Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn*/ + Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) Q0*/ + Word16 *synth_out, /* i/o: output signal at output Fs : Q_out*/ + Word16 fmerit, /* i : classify parameter from FEC : Q14*/ + const Word16 *hf_gain, /* i : decoded HF gain Q0*/ + const Word16 *voice_factors, /* i : voicing factors : Q15*/ + const Word16 pitch_buf[], /* i : pitch buffer : Q5*/ + const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8*/ + const Word16 *lsf_new, /* i : ISF vector : Q2*/ + const Word16 Q_exc, /* i : exc scaling */ + const Word16 Q_out /* i : Q_syn2-1 */ ) { Word16 core_type = 1; @@ -824,11 +824,12 @@ void hf_synth_amr_wb_fx( Word32 exc32[L_FRAME], dct_exc32[L_FRAME], dct_hb32[L_FRAME16k], exc16k32[L_FRAME16k]; Word16 q_tmp; Word16 gamma; + move16(); - Scale_sig( synth, L_FRAME, -3 ); + Scale_sig( synth, L_FRAME, -3 ); /* Q_syn - 3 */ - pt1 = synth + 1; - pt2 = synth; + pt1 = synth + 1; /* Q_syn - 3 */ + pt2 = synth; /* Q_syn - 3 */ pt3 = til; pt4 = til0; FOR( i = 0; i < NB_SUBFR; i++ ) @@ -836,9 +837,9 @@ void hf_synth_amr_wb_fx( enr1 = Dot_product( pt2, pt2, L_SUBFR ); /*2*(Q_syn-3)+1 */ enr2 = Dot_product( pt1, pt2, L_SUBFR - 1 ); /*2*(Q_syn-3)+1 */ - tmp1 = extract_h( enr1 ); + tmp1 = extract_h( enr1 ); /*2*(Q_syn-3) - 15 */ tmp1 = s_max( 1, tmp1 ); - tmp2 = extract_h( enr2 ); + tmp2 = extract_h( enr2 ); /*2*(Q_syn-3) - 15 */ exp = norm_s( tmp1 ); tmp1 = div_s( shl( 1, sub( 14, exp ) ), tmp1 ); /*Q(29-exp-2*(Q_syn-3)-1) */ @@ -852,7 +853,7 @@ void hf_synth_amr_wb_fx( pt2 += L_SUBFR; } - output_subfr = shr( output_frame, 2 ); + output_subfr = shr( output_frame, 2 ); /* Q0 */ if ( NE_16( *amr_io_class, 7 ) ) { @@ -863,8 +864,8 @@ void hf_synth_amr_wb_fx( /* modify LF parameters for excitation weighting or sub-frame gains calculating */ pitch_var_cur = 0; move16(); - pt6 = pitch_buf; - pt7 = pitch_buf + 1; + pt6 = pitch_buf; /* Q5 */ + pt7 = pitch_buf + 1; /* Q5 */ FOR( i = 0; i < 3; i++ ) { tmp1 = abs_s( sub( *pt6++, *pt7++ ) ); /*Q5 */ @@ -874,41 +875,41 @@ void hf_synth_amr_wb_fx( IF( GT_16( hAmrwb_IO->frame_count_fx, FRAME_COUNT_HF_SYNTH ) && *amr_io_class == UNVOICED_CLAS ) { hAmrwb_IO->frame_count_fx = 0; - hAmrwb_IO->ne_min_fx = -7680; + hAmrwb_IO->ne_min_fx = -7680; /* -30.0f in Q8 */ move16(); move16(); /*Q8; */ } ELSE { - hAmrwb_IO->frame_count_fx = s_min( hAmrwb_IO->frame_count_fx, 2 * FRAME_COUNT_HF_SYNTH - 1 ); + hAmrwb_IO->frame_count_fx = s_min( hAmrwb_IO->frame_count_fx, 2 * FRAME_COUNT_HF_SYNTH - 1 ); /* Q0 */ move16(); - hAmrwb_IO->frame_count_fx = add( hAmrwb_IO->frame_count_fx, 1 ); + hAmrwb_IO->frame_count_fx = add( hAmrwb_IO->frame_count_fx, 1 ); /* Q0 */ move16(); - hAmrwb_IO->ne_min_fx = s_min( hAmrwb_IO->ne_min_fx, ng_ener_ST ); + hAmrwb_IO->ne_min_fx = s_min( hAmrwb_IO->ne_min_fx, ng_ener_ST ); /* Q8 */ move16(); } pt6 = voice_factors; - L_tmp = L_mult( *pt6++, 4096 ); + L_tmp = L_mult( *pt6++, 4096 /* 0.25 IN Q14 */ ); /* Q30 */ FOR( i = 1; i < 4; i++ ) { - L_tmp = L_mac( L_tmp, *pt6++, 4096 ); + L_tmp = L_mac( L_tmp, *pt6++, 4096 /* 0.25 IN Q14 */ ); /* Q30 */ } - voice_fac = round_fx( L_tmp ); + voice_fac = round_fx( L_tmp ); /* Q14 */ /*fmerit_w = fmerit > 5734 ? 5734 : (fmerit < 2458 ? 2458 : fmerit); //Q14 */ - fmerit_w = s_min( fmerit, 5734 ); - fmerit_w = s_max( fmerit_w, 2458 ); + fmerit_w = s_min( fmerit, 5734 /* 0.35 IN Q14 */ ); /* Q14 */ + fmerit_w = s_max( fmerit_w, 2458 /* 0.15 IN Q14 */ ); /* Q14 */ if ( EQ_16( core_type, 1 ) ) { - fmerit_w = shr( fmerit_w, 1 ); /*Q14; */ + fmerit_w = shr( fmerit_w, 1 ); /* Q14 */ } #ifdef BASOP_NOGLOB - L_tmp = L_mult( fmerit_w, add_sat( 16384, voice_fac ) ); + L_tmp = L_mult( fmerit_w, add_sat( 16384, voice_fac ) ); /* Q14 */ #else L_tmp = L_mult( fmerit_w, add( 16384, voice_fac ) ); #endif @@ -920,17 +921,17 @@ void hf_synth_amr_wb_fx( move16(); - tmp1 = fmerit; + tmp1 = fmerit; /* Q14 */ move16(); - if ( LT_16( fmerit, 8192 ) ) + if ( LT_16( fmerit, 8192 /* 0.5 in Q14 */ ) ) { - tmp1 = 16384; + tmp1 = 16384; /* 1.0f in Q14 */ move16(); } fmerit_m = negate( add( -32768, tmp1 ) ); hAmrwb_IO->fmerit_m_sm_fx = add( shr( hAmrwb_IO->fmerit_m_sm_fx, 1 ), shr( fmerit_m, 1 ) ); /*Q14 */ move16(); - fmerit_m = hAmrwb_IO->fmerit_m_sm_fx; + fmerit_m = hAmrwb_IO->fmerit_m_sm_fx; /* Q14 */ move16(); pt1 = til; @@ -940,15 +941,15 @@ void hf_synth_amr_wb_fx( tmp = s_and( tmp, *pt1 ); if ( tmp < 0 ) { - *pt1 = 1638; + *pt1 = 1638; /* 0.2 in Q13 */ move16(); } - tmp1 = sub( 8192, *pt1 ); - *pt1 = s_max( 6554, tmp1 ); + tmp1 = sub( 8192 /* 1.0 in Q13 */, *pt1 ); /* Q13 */ + *pt1 = s_max( 6554 /* 0.8 in Q13 */, tmp1 ); /* Q13 */ move16(); - tmp1 = add( hAmrwb_IO->ne_min_fx, 7680 ); /*Q8 */ - tmp1 = mult_r( tmp1, 7340 ); /*Q20 - > 0.007 //Q13 */ + tmp1 = add( hAmrwb_IO->ne_min_fx, 7680 /* 30.0 in Q30 */ ); /*Q8 */ + tmp1 = mult_r( tmp1, 7340 ); /*Q20 - > 0.007 //Q13 */ *pt1 = add( *pt1, tmp1 ); move16(); /*Q13 */ @@ -979,19 +980,19 @@ void hf_synth_amr_wb_fx( q_tmp = Exp16Array( L_FRAME, exc ); qdct = sub( q_tmp, 1 ); - Copy_Scale_sig_16_32( exc, exc32, L_FRAME, qdct ); + Copy_Scale_sig_16_32( exc, exc32, L_FRAME, qdct ); /* Qexc + qdct */ qdct = add( qdct, Q_exc ); edct_fx( exc32, dct_exc32, L_FRAME, &qdct ); q_tmp = Exp32Array( L_FRAME, dct_exc32 ); q_tmp = sub( q_tmp, 16 ); - Copy_Scale_sig_32_16( dct_exc32, dct_exc, L_FRAME, q_tmp ); + Copy_Scale_sig_32_16( dct_exc32, dct_exc, L_FRAME, q_tmp ); /* qdct + qtmp */ qdct = add( qdct, q_tmp ); set16_fx( dct_hb, 0, L_FRAME16k ); - pt1 = &dct_hb[200]; - pt2 = &dct_exc[200]; + pt1 = &dct_hb[200]; /* qdct */ + pt2 = &dct_exc[200]; /* qdct */ FOR( i = 200; i < 240; i++ ) { *pt1++ = *pt2++; @@ -1014,10 +1015,10 @@ void hf_synth_amr_wb_fx( } hb_ener = dot_prod_satcontr( &dct_hb[240], &dct_hb[240], qdct, qdct, &q1, L_SUBFR16k ); - L_tmp = L_shl( L_mult( start_band, 205 ), 14 ); /*Q30 */ - tmp = round_fx( L_tmp ); /*Q14 */ - tmp = sub( 18022, tmp ); /*Q14 */ - fmerit_w = round_fx( L_shl( L_mult( fmerit_w, tmp ), 1 ) ); /*Q: 14+14+1+1-16 = 14 */ + L_tmp = L_shl( L_mult( start_band, 205 /* 0.00625f in Q15 */ ), 14 ); /*Q30 */ + tmp = round_fx( L_tmp ); /*Q14 */ + tmp = sub( 18022 /* 1.1f in Q14 */, tmp ); /*Q14 */ + fmerit_w = round_fx( L_shl( L_mult( fmerit_w, tmp ), 1 ) ); /*Q: 14+14+1+1-16 = 14 */ L_tmp = L_deposit_l( fmerit_w ); /*Q14 */ @@ -1027,15 +1028,15 @@ void hf_synth_amr_wb_fx( alpha = div_s( shl( 1, sub( 14, q2 ) ), tmp ); /*Q(29-q2-8); */ alpha = shl( alpha, sub( q2, 7 ) ); /*Q14 */ - beta = sub( 16384, fmerit_w ); /*Q14 */ + beta = sub( 16384 /* 1.0f in Q14 */, fmerit_w ); /*Q14 */ - L_tmp = L_mult( alpha, 31130 ); /*Q30 */ - gamma = round_fx( L_tmp ); /*Q14 */ - gamma = sub( 17203, gamma ); /*Q14 */ - gamma = s_min( 16384, gamma ); - gamma = s_max( 4915, gamma ); + L_tmp = L_mult( alpha, 31130 /* 0.95f in Q15 */ ); /*Q30 */ + gamma = round_fx( L_tmp ); /*Q14 */ + gamma = sub( 17203 /* 1.05f in Q14 */, gamma ); /*Q14 */ + gamma = s_min( 16384 /* 1.0f in Q14 */, gamma ); /* Q14 */ + gamma = s_max( 4915 /* 0.3f in Q14 */, gamma ); /* Q14 */ - IF( LT_16( beta, 16384 ) ) + IF( LT_16( beta, 16384 /* 1 in Q14 */ ) ) { L_tmp = 1; /*variable for tonal energy*/ move32(); @@ -1045,7 +1046,7 @@ void hf_synth_amr_wb_fx( pt3 = &dct_hb[240]; FOR( i = 0; i < 8; i++ ) { - fn = add( i, 8 ); + fn = add( i, 8 ); /* Q0 */ tmp1 = div_s( 1, fn ); /*Q15 */ tmp = 0; move16(); @@ -1060,11 +1061,11 @@ void hf_synth_amr_wb_fx( } *pt1 = round_fx( L_shl( L_mult( tmp, tmp1 ), 2 ) ); /*qdct */ move16(); - *pt2 = sub( *pt3, *pt1 ); + *pt2 = sub( *pt3, *pt1 ); /* qdct */ move16(); IF( *pt2 > 0 ) { - L_tmp = L_mac0( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); + L_tmp = L_mac0( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); /*2*qdct-2 */ } pt1++; pt2++; @@ -1072,8 +1073,8 @@ void hf_synth_amr_wb_fx( } FOR( ; i < L_SUBFR16k - 8; i++ ) { - fb = sub( i, 7 ); - fn = add( fb, 15 ); + fb = sub( i, 7 ); /* Q0 */ + fn = add( fb, 15 ); /* Q0 */ tmp = 0; move16(); pt4 = &dct_hb[fb + 240]; @@ -1092,7 +1093,7 @@ void hf_synth_amr_wb_fx( IF( *pt2 > 0 ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac0_sat( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); + L_tmp = L_mac0_sat( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); /*2*qdct-2 */ #else L_tmp = L_mac0( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); #endif @@ -1103,11 +1104,11 @@ void hf_synth_amr_wb_fx( } FOR( ; i < L_SUBFR16k; i++ ) { - fb = sub( i, 7 ); + fb = sub( i, 7 ); /* Q0 */ tmp = 0; move16(); - fn = sub( L_SUBFR16k, fb ); - tmp1 = div_s( 1, fn ); /*Q15 */ + fn = sub( L_SUBFR16k, fb ); /* Q0 */ + tmp1 = div_s( 1, fn ); /*Q15 */ pt4 = &dct_hb[fb + 240]; FOR( j = fb; j < L_SUBFR16k; j++ ) { @@ -1172,11 +1173,11 @@ void hf_synth_amr_wb_fx( pt4++; } - ener = dot_prod_satcontr( &dct_hb[240], &dct_hb[240], qdct, qdct, &q2, L_SUBFR16k ); - scale = div_s( shl( 1, 14 ), hb_ener ); /*Q(29-q1) */ - L_tmp = L_mult( ener, scale ); /*30-q1+q2 */ - q2 = sub( q1, q2 ); /*30-q2 */ - scale = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ + ener = dot_prod_satcontr( &dct_hb[240], &dct_hb[240], qdct, qdct, &q2, L_SUBFR16k ); /* q2 */ + scale = div_s( shl( 1, 14 ), hb_ener ); /*Q(29-q1) */ + L_tmp = L_mult( ener, scale ); /*30-q1+q2 */ + q2 = sub( q1, q2 ); /*30-q2 */ + scale = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ #ifdef BASOP_NOGLOB scale = round_fx_sat( L_shl_sat( L_mult( scale, gamma ), 4 ) ); /*Q15 */ #else @@ -1191,23 +1192,23 @@ void hf_synth_amr_wb_fx( IF( EQ_32( core_brate, ACELP_6k60 ) ) { - filt_weight_coeff = 60; + filt_weight_coeff = 60; /* Q0 */ move16(); rev_filt_weight_coeff = 555; move16(); /* 1/(filt_weight_coeff-1) Q15 */ } ELSE IF( EQ_32( core_brate, ACELP_8k85 ) ) { - filt_weight_coeff = 40; + filt_weight_coeff = 40; /* Q0 */ move16(); - rev_filt_weight_coeff = 840; + rev_filt_weight_coeff = 840; /* 1/(filt_weight_coeff-1) Q15 */ move16(); } ELSE { - filt_weight_coeff = 20; + filt_weight_coeff = 20; /* Q0 */ move16(); - rev_filt_weight_coeff = 1725; + rev_filt_weight_coeff = 1725; /* 1/(filt_weight_coeff-1) Q15 */ move16(); } @@ -1223,7 +1224,7 @@ void hf_synth_amr_wb_fx( IF( EQ_32( core_brate, ACELP_23k85 ) ) { pt1 = dct_hb + 240; - tmp = sub( filt_weight_coeff, 80 ); + tmp = sub( filt_weight_coeff, 80 ); /* Q0 */ pt3 = filt_weight + tmp; FOR( i = 240; i < L_FRAME16k; i++ ) { @@ -1252,21 +1253,21 @@ void hf_synth_amr_wb_fx( { tmp = *pt6++; move16(); - *pt1++ = HP_gain_fx[tmp]; + *pt1++ = HP_gain_fx[tmp]; /* Q15 */ move16(); } } ELSE { pt1 = dct_hb + 240; - tmp = sub( filt_weight_coeff, 80 ); + tmp = sub( filt_weight_coeff, 80 ); /* Q0 */ pt3 = filt_weight + tmp; FOR( i = 240; i < L_FRAME16k; i++ ) { *pt1 = mult_r( *pt1, scale ); /*qdct */ IF( GT_16( i, 255 ) ) { - *pt1 = mult_r( 19505, *pt1 ); + *pt1 = mult_r( 19505 /* 0.6 in Q15 */, *pt1 ); move16(); } @@ -1281,25 +1282,25 @@ void hf_synth_amr_wb_fx( pt1 = dct_hb + 200; pt6 = filt_hp_fx; - pt7 = deem_tab_fx; + pt7 = deem_tab_fx; /* Q15 */ FOR( i = 200; i < 256; i++ ) { *pt1 = mult_r( *pt6++, *pt1 ); move16(); /*qdct */ *pt1 = mult_r( *pt7++, *pt1 ); - move16(); + move16(); /* qdct */ pt1++; } } q_tmp = Exp16Array( L_FRAME16k, dct_hb ); qhf = sub( q_tmp, 1 ); - Copy_Scale_sig_16_32( dct_hb, dct_hb32, L_FRAME16k, qhf ); + Copy_Scale_sig_16_32( dct_hb, dct_hb32, L_FRAME16k, qhf ); /* qhf + qdct */ qhf = add( qhf, qdct ); edct_fx( dct_hb32, exc16k32, L_FRAME16k, &qhf ); q_tmp = Exp32Array( L_FRAME16k, exc16k32 ); q_tmp = sub( q_tmp, 16 ); - Copy_Scale_sig_32_16( exc16k32, exc16k, L_FRAME16k, q_tmp ); + Copy_Scale_sig_32_16( exc16k32, exc16k, L_FRAME16k, q_tmp ); /* qhf + qtmp */ qhf = add( qhf, q_tmp ); ener = dot_prod_satcontr( exc, exc, Q_exc, Q_exc, &q1, L_FRAME ); @@ -1383,19 +1384,19 @@ void hf_synth_amr_wb_fx( return; } static void hf_synthesis_amr_wb_fx( - const Word32 core_brate, /* i : core bitrate : Q0 */ - const Word16 output_subfr, /* i : output sub-frame length : Q0 */ - const Word16 Ap[], /* i : quantized Aq : Q12 */ - Word16 exc16k[], /* i : excitation at 16 kHz : Qhf */ - Word16 synth_out[], /* i/o: synthesis signal at output Fs : Qo */ - Word16 *mem_syn_hf, /* i/o: HF synthesis memory : Qo */ - Word16 *delay_syn_hf, /* i/o: HF synthesis memory : Qo */ - Word16 *mem_hp_interp, /* i/o: interpol. memory : Qo */ - Word16 p_r, /* i : sub-frame gain : Q12 */ - Word16 HF_corr_gain, /* i : HF gain index : Q14 */ - Word16 til, /*Q14*/ - Word16 voice_factors, /*Q14*/ - const Word16 exc[], /* i : excitation at 12.8 kHz : Qi */ + const Word32 core_brate, /* i : core bitrate : Q0*/ + const Word16 output_subfr, /* i : output sub-frame length : Q0*/ + const Word16 Ap[], /* i : quantized Aq : Q12*/ + Word16 exc16k[], /* i : excitation at 16 kHz : qhf*/ + Word16 synth_out[], /* i/o: synthesis signal at output Fs : Q_out*/ + Word16 *mem_syn_hf, /* i/o: HF synthesis memory : Q_out*/ + Word16 *delay_syn_hf, /* i/o: HF synthesis memory : Q_out*/ + Word16 *mem_hp_interp, /* i/o: interpol. memory : Q_out*/ + Word16 p_r, /* i : sub-frame gain : Q12*/ + Word16 HF_corr_gain, /* i : HF gain index : Q14*/ + Word16 til, /* Q14 */ + Word16 voice_factors, /* Q14 */ + const Word16 exc[], /* i : excitation at 12.8 kHz : Qexc*/ const Word16 Q_exc, /*exc scaling*/ const Word16 Q_out, /*synth_out scaling*/ Word16 qhf /*exc16k scaling*/ @@ -1412,7 +1413,7 @@ static void hf_synthesis_amr_wb_fx( ener = dot_prod_satcontr( exc, exc, Q_exc, Q_exc, &q1, L_SUBFR ); tmp = dot_prod_satcontr( exc16k, exc16k, qhf, qhf, &q2, L_SUBFR16k ); - L_tmp = L_mult( ener, 6554 ); /*Q(q1+16) */ + L_tmp = L_mult( ener, 6554 /* 0.2 in Q15 */ ); /*Q(q1+16) */ q3 = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, q3 ); /*Q(q1+q3+16) */ ener = extract_h( L_tmp ); /*Q(q1+q3); */ @@ -1463,14 +1464,14 @@ static void hf_synthesis_amr_wb_fx( scale = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ #endif flag = negate( s_and( til, -0x8000 ) ); - if ( GT_16( scale, 4096 ) ) + if ( GT_16( scale, 4096 /* 1.0f in Q12 */ ) ) { flag = 1; move16(); } IF( flag ) { - Copy( exc2385, exc16k, L_SUBFR16k ); + Copy( exc2385, exc16k, L_SUBFR16k ); /* qhf */ } ELSE { @@ -1478,10 +1479,10 @@ static void hf_synthesis_amr_wb_fx( pt2 = exc2385; FOR( i = 0; i < L_SUBFR16k; i++ ) { - tmp = sub( 16348, shl( til, 1 ) ); /*Q14 */ - L_tmp = L_mult( tmp, sub( 26214, shr( voice_factors, 1 ) ) ); /*Q29*/ - tmp = round_fx( L_shr( L_tmp, 1 ) ); /*Q12*/ - tmp = s_min( tmp, 4096 ); + tmp = sub( 16348 /* 1 in Q14 */, shl( til, 1 ) ); /*Q14 */ + L_tmp = L_mult( tmp, sub( 26214 /* 1.6f in Q14 */, shr( voice_factors, 1 ) ) ); /*Q29*/ + tmp = round_fx( L_shr( L_tmp, 1 ) ); /*Q12*/ + tmp = s_min( tmp, 4096 /* 1 in Q12 */ ); tmp = s_max( tmp, scale ); *pt1++ = round_fx( L_shl( L_mult( *pt2++, tmp ), 3 ) ) /*qhf*/; move16(); @@ -1517,31 +1518,31 @@ static void hf_synthesis_amr_wb_fx( s = s_max( s_min( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, INTERP_3_1_MEM_LEN - 3 ) ), 3 ), sub( Find_Max_Norm16( mem_hp_interp + INTERP_3_1_MEM_LEN - 3, 3 ), 1 ) ), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Qout + s */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); /* Qout + s */ interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp ); - Scale_sig( upsampled_HF_syn, L_SUBFR48k, add( -s, -1 ) ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); + Scale_sig( upsampled_HF_syn, L_SUBFR48k, add( -s, -1 ) ); /* Qout - 1 */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); /* Qout */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Qout */ } ELSE IF( EQ_16( output_subfr, L_SUBFR32k ) ) /* 32kHz sampled output */ { Word16 s; s = s_max( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP ) ), 2 ), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Qout + s */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); /* Qout + s */ Interpolate_allpass_steep_fx( HF_syn, mem_hp_interp, L_SUBFR16k, upsampled_HF_syn ); - Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); - Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); + Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); /* Qout */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); /* Qout */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Qout */ } ELSE /* 16kHz sampled output */ { - Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); + Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); /* Qout */ } Vr_add( synth_out, upsampled_HF_syn, synth_out, output_subfr ); @@ -1550,15 +1551,15 @@ static void hf_synthesis_amr_wb_fx( } static Word16 EnhanceClass_fx( - const Word16 qq_fx, - const Word16 pp_fx, - const Word16 tilt0_fx, /* i : spectrum tilt */ - const Word16 tilt_fx, /* i : spectrum tilt */ - const Word16 voice_factor_fx, /* i : voice factor */ - Word16 *voice_fac_fx, /* i/o: smoothed voiced parameter */ - Word16 *unvoicing_fx, /* i/o: unvoiced parameter */ - Word16 *unvoicing_sm_fx, /* i/o: smoothed unvoiced parameter */ - Word16 *unvoicing_flag /* i/o: unvoiced flag */ + const Word16 qq_fx, /* Qx */ + const Word16 pp_fx, /* Qx */ + const Word16 tilt0_fx, /* i : spectrum tilt Q13*/ + const Word16 tilt_fx, /* i : spectrum tilt Q13*/ + const Word16 voice_factor_fx, /* i : voice factor Q15*/ + Word16 *voice_fac_fx, /* i/o: smoothed voiced parameter Q15*/ + Word16 *unvoicing_fx, /* i/o: unvoiced parameter Q15*/ + Word16 *unvoicing_sm_fx, /* i/o: smoothed unvoiced parameter Q15*/ + Word16 *unvoicing_flag /* i/o: unvoiced flag Q0*/ ) { Word16 unvoicing_tmp_fx; @@ -1571,41 +1572,41 @@ static Word16 EnhanceClass_fx( /* Decide (*unvoicing_flag) to allow BWE enhancement when qq>pp */ /**voice_fac_fx = add(mult_r(*voice_fac_fx, 24576), mult_r(voice_factor_fx, 8192)); //Q15 */ - *voice_fac_fx = round_fx( L_mac( L_mult( *voice_fac_fx, 24576 ), voice_factor_fx, 8192 ) ); /*Q15 */ + *voice_fac_fx = round_fx( L_mac( L_mult( *voice_fac_fx, 24576 /* 0.75 in Q15 */ ), voice_factor_fx, 8192 /* 0.25 in Q15 */ ) ); /*Q15 */ move16(); - tmp = mult_r( sub( 8192, tilt0_fx ), 16384 ); /*Q13 */ + tmp = mult_r( sub( 8192 /* 1.0f in Q13 */, tilt0_fx ), 16384 /* 1.0f in Q15 */ ); /*Q13 */ - L_tmp = L_sub( 32768, *voice_fac_fx ); /*Q15 */ + L_tmp = L_sub( 32768 /* 1.0 in Q15 */, *voice_fac_fx ); /*Q15 */ L_tmp = Mult_32_16( L_tmp, tmp ); /*Q13 */ tmp = extract_l( L_tmp ); /*Q13 */ tmp1 = mult_r( tilt_fx, 21845 ); /*Q15->1/1.5 ->Q13+15-15->Q13 */ - tmp1 = s_min( tmp1, 8192 ); + tmp1 = s_min( tmp1, 8192 /* 1.0f in Q13 */ ); L_tmp = L_mult( tmp, tmp1 ); /*Q13+Q13+1 */ unvoicing_tmp_fx = extract_l( L_shr( L_tmp, 12 ) ); /*Q15 */ /**unvoicing_fx = add(mult_r(16384, *unvoicing_fx), mult_r(16384, unvoicing_tmp_fx)); //Q15 */ - *unvoicing_fx = round_fx( L_mac( L_mult( 16384, *unvoicing_fx ), 16384, unvoicing_tmp_fx ) ); /*Q15 */ + *unvoicing_fx = round_fx( L_mac( L_mult( 16384 /* 0.5 in Q15 */, *unvoicing_fx ), 16384 /* 0.5 in Q15 */, unvoicing_tmp_fx ) ); /*Q15 */ move16(); IF( GT_16( *unvoicing_sm_fx, *unvoicing_fx ) ) { /**unvoicing_sm_fx = add(mult_r(29491, *unvoicing_sm_fx), mult_r(3277, *unvoicing_fx)); //Q15 */ - *unvoicing_sm_fx = round_fx( L_mac( L_mult( 29491, *unvoicing_sm_fx ), 3277, *unvoicing_fx ) ); /*Q15 */ + *unvoicing_sm_fx = round_fx( L_mac( L_mult( 29491 /* 0.9 in Q15 */, *unvoicing_sm_fx ), 3277 /* 0.1 in Q15 */, *unvoicing_fx ) ); /*Q15 */ move16(); } ELSE { /**unvoicing_sm_fx = add(mult_r(32440, *unvoicing_sm_fx), mult_r(328, *unvoicing_fx)); //Q15 */ - *unvoicing_sm_fx = round_fx( L_mac( L_mult( 32440, *unvoicing_sm_fx ), 328, *unvoicing_fx ) ); /*Q15 */ + *unvoicing_sm_fx = round_fx( L_mac( L_mult( 32440 /* 0.99 in Q15 */, *unvoicing_sm_fx ), 328 /* 0.01 in Q15 */, *unvoicing_fx ) ); /*Q15 */ move16(); } #ifdef BASOP_NOGLOB - if ( GT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 3277 ) ) + if ( GT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 3277 /* 0.1 in Q15 */ ) ) #else if ( GT_16( sub( *unvoicing_fx, *unvoicing_sm_fx ), 3277 ) ) #endif @@ -1615,7 +1616,7 @@ static Word16 EnhanceClass_fx( } #ifdef BASOP_NOGLOB - if ( LT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 1638 ) ) + if ( LT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 1638 /* 0.05 in Q15 */ ) ) #else if ( LT_16( sub( *unvoicing_fx, *unvoicing_sm_fx ), 1638 ) ) #endif @@ -1629,13 +1630,13 @@ static Word16 EnhanceClass_fx( static void envelope_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, - const Word32 core_brate, /* i : core bitrate */ - const Word16 Aq_dyn_scal[], /* i : de-quant. LPC coefficents, dynamic scaling */ - Word16 Ap[], /* o : extended LPC coefficents, Q12 */ - Word16 *sub_gain, /* o : sub-frame gain, Q12 */ - Word16 tilt0, /* i : spectrum tilt, Q14 */ - Word16 tilt, /* i : spectrum tilt, Q13 */ - Word16 voice_factor /* i : voice factor, Q15 */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 Aq_dyn_scal[], /* i : de-quant. LPC coefficents, dynamic scaling Q12*/ + Word16 Ap[], /* o : extended LPC coefficents, Q12*/ + Word16 *sub_gain, /* o : sub-frame gain, Q12*/ + Word16 tilt0, /* i : spectrum tilt, Q14*/ + Word16 tilt, /* i : spectrum tilt, Q13*/ + Word16 voice_factor /* i : voice factor, Q15*/ ) { @@ -1654,7 +1655,7 @@ static void envelope_fx( /* Aq has dynamic scaling go back to Q12 to make sure there's no overflow while calculating qx,qy*/ shift = sub( norm_s( Aq_dyn_scal[0] ), 2 ); - Copy_Scale_sig( Aq_dyn_scal, Aq, M + 1, shift ); + Copy_Scale_sig( Aq_dyn_scal, Aq, M + 1, shift ); /* Q12 + shift */ /* LPC envelope weighting */ IF( EQ_32( core_brate, ACELP_6k60 ) ) @@ -1670,17 +1671,17 @@ static void envelope_fx( shift = sub( norm_s( Ap[0] ), 2 ); IF( shift != 0 ) { - Scale_sig( Ap, M + 1, shift ); + Scale_sig( Ap, M + 1, shift ); /* Q12 + shift */ } /* LPC envelope level estimate */ L_tmp = 0; move32(); - pt1 = Ap; - pt2 = exp_tab_p_fx; + pt1 = Ap; /* Q12 */ + pt2 = exp_tab_p_fx; /* Q14 */ FOR( i = 0; i <= M; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); /* Q27 */ } q1 = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, q1 ); /*Q(27+q1)*/ @@ -1688,11 +1689,11 @@ static void envelope_fx( L_tmp = L_deposit_l( 0 ); - pt1 = Ap; - pt2 = exp_tab_p_fx + 33; + pt1 = Ap; /* Q12 */ + pt2 = exp_tab_p_fx + 33; /* Q14 */ FOR( i = 0; i <= M; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); /* Q27 */ } q2 = norm_l( L_tmp ); shift = sub( q1, q2 ); @@ -1710,12 +1711,12 @@ static void envelope_fx( py = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/ L_tmp = L_deposit_l( 0 ); - pt2 = Aq; - pt3 = exp_tab_q_fx; + pt2 = Aq; /* Q12 */ + pt3 = exp_tab_q_fx; /* Q14 */ FOR( i = 0; i <= M; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3++ ); + L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3++ ); /* Q27 */ #else L_tmp = L_mac( L_tmp, *pt2++, *pt3++ ); #endif @@ -1725,12 +1726,12 @@ static void envelope_fx( rx = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q2)*/ L_tmp = L_deposit_l( 0 ); - pt2 = Aq; - pt3 = exp_tab_q_fx + 33; + pt2 = Aq; /* Q12 */ + pt3 = exp_tab_q_fx + 33; /* Q14 */ FOR( i = 0; i <= M; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3-- ); + L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3-- ); /* Q14 */ #else L_tmp = L_mac( L_tmp, *pt2++, *pt3-- ); #endif @@ -1765,21 +1766,21 @@ static void envelope_fx( rr = round_fx( Isqrt( L_shr( L_tmp, add( 11, shl( q2, 1 ) ) ) ) ); /*Q10*/ #endif Copy( Aq, As, 3 ); - IF( EQ_16( shr( As[2], 1 ), -2048 ) ) + IF( EQ_16( shr( As[2], 1 ), -2048 /* -1.0f in Q11 */ ) ) { - k2 = -2458; + k2 = -2458; /* -0.6f in Q12 */ move16(); - k1 = 4055; + k1 = 4055; /* 0.99f in Q12 */ move16(); if ( As[1] < 0 ) { - k1 = -k1; + k1 = -k1; /* Q12 */ move16(); } } ELSE { - k1 = add( 2048, shr( As[2], 1 ) ); /*Q11 */ + k1 = add( 2048 /* 1 in Q11 */, shr( As[2], 1 ) ); /*Q11 */ q1 = 11; move16(); q2 = norm_s( k1 ); @@ -1801,28 +1802,28 @@ static void envelope_fx( #endif k2 = As[2]; move16(); /*Q12 */ - if ( GT_16( k2, 2458 ) ) + if ( GT_16( k2, 2458 /* 0.6f in Q12 */ ) ) { - k2 = 2458; + k2 = 2458; /* 0.6f in Q12 */ move16(); } - if ( LT_16( k2, -2458 ) ) + if ( LT_16( k2, -2458 /* -0.6f in Q12 */ ) ) { - k2 = -2458; + k2 = -2458; /* -0.6f in Q12 */ move16(); } - if ( GT_16( k1, 4055 ) ) + if ( GT_16( k1, 4055 /* 0.99f in Q12 */ ) ) { - k1 = 4055; + k1 = 4055; /* 0.99f in Q12 */ move16(); } - if ( LT_16( k1, -4055 ) ) + if ( LT_16( k1, -4055 /* -0.99f in Q12 */ ) ) { - k1 = -4055; + k1 = -4055; /* -0.99f in Q12 */ move16(); } } - As[1] = add( 4096, k2 ); + As[1] = add( 4096 /* 1 in Q12 */, k2 ); move16(); L_tmp = L_mult( As[1], k1 ); /*Q25 */ As[1] = round_fx( L_shl( L_tmp, 3 ) ); /*Q12 */ @@ -1831,11 +1832,11 @@ static void envelope_fx( move16(); /*Q12 */ L_tmp = L_deposit_l( 0 ); - pt1 = As; - pt2 = exp_tab_q_fx; + pt1 = As; /* Q12 */ + pt2 = exp_tab_q_fx; /* Q14 */ FOR( i = 0; i < 3; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); /* Q27 */ } q1 = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, q1 ); /*Q(27+q1)*/ @@ -1843,11 +1844,11 @@ static void envelope_fx( L_tmp = L_deposit_l( 0 ); - pt1 = As; - pt2 = exp_tab_q_fx + 33; + pt1 = As; /* Q12 */ + pt2 = exp_tab_q_fx + 33; /* Q14 */ FOR( i = 0; i < 3; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); /* Q27 */ } q2 = norm_l( L_tmp ); shift = sub( q1, q2 ); @@ -1865,11 +1866,11 @@ static void envelope_fx( qy = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/ - L_tmp = L_mult( qx, qx ); - L_tmp = L_mac( L_tmp, qy, qy ); + L_tmp = L_mult( qx, qx ); /* Q21 + 2q1 */ + L_tmp = L_mac( L_tmp, qy, qy ); /* Q21 + 2q1 */ qq = round_fx( Isqrt( L_shr( L_tmp, add( 11, shl( q1, 1 ) ) ) ) ); /*Q10*/ - Unvoicing_flag = EnhanceClass_fx( rr, pp, tilt0, tilt, voice_factor, &hAmrwb_IO->voice_fac_amr_wb_hf, &hAmrwb_IO->unvoicing_fx, &hAmrwb_IO->unvoicing_sm_fx, &hAmrwb_IO->unvoicing_flag_fx ); + Unvoicing_flag = EnhanceClass_fx( rr, pp, tilt0, tilt, voice_factor, &hAmrwb_IO->voice_fac_amr_wb_hf, &hAmrwb_IO->unvoicing_fx, &hAmrwb_IO->unvoicing_sm_fx, &hAmrwb_IO->unvoicing_flag_fx ); /* Q0 */ alpha = 0; move16(); IF( Unvoicing_flag ) @@ -1886,31 +1887,31 @@ static void envelope_fx( hAmrwb_IO->prev_r_fx = rr; move16(); - L_tmp = L_mult( tilt, sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_mult( tilt, sub( 26214 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_min( L_tmp, 268435456 ); + L_tmp = L_min( L_tmp, 268435456 /* 1 in Q28 */ ); - L_tmp = Mult_32_16( L_tmp, rr ); /*Q23*/ - rr = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ - L_tmp = L_mult( tilt, sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_max( L_tmp, 268435456 ); + L_tmp = Mult_32_16( L_tmp, rr ); /*Q23*/ + rr = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ + L_tmp = L_mult( tilt, sub( 26214 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_max( L_tmp, 268435456 /* 1 in Q28 */ ); L_tmp = Mult_32_16( L_tmp, qq ); /*Q23*/ #ifdef BASOP_NOGLOB qq = round_fx_sat( L_shl_sat( L_tmp, 3 ) ); /*Q10*/ #else qq = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ #endif - rr = s_min( rr, qq ); - rr = s_max( rr, pp ); + rr = s_min( rr, qq ); /* Q10 */ + rr = s_max( rr, pp ); /* Q10 */ } ELSE { test(); - IF( LT_16( rr, 1024 ) && LT_16( ( hAmrwb_IO->prev_r_fx ), 1024 ) ) + IF( LT_16( rr, 1024 /* 1 in Q10 */ ) && LT_16( ( hAmrwb_IO->prev_r_fx ), 1024 /* 1 in Q10 */ ) ) { L_tmp = L_mult( rr, rr ); /*Q21*/ tmp = round_fx( L_shl( L_tmp, 9 ) ); /*Q14*/ - L_tmp = L_sub( 2097152, L_tmp ); /*Q21*/ + L_tmp = L_sub( 2097152 /* 1 in Q21 */, L_tmp ); /*Q21*/ alpha = round_fx( L_shl( L_tmp, 9 ) ); /*Q14*/ L_tmp = L_mult( alpha, ( hAmrwb_IO->prev_r_fx ) ); /*Q25*/ L_tmp = L_mac( L_tmp, tmp, rr ); /*Q25*/ @@ -1924,9 +1925,9 @@ static void envelope_fx( hAmrwb_IO->prev_r_fx = rr; move16(); - L_tmp = L_mult( tilt, sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_mult( tilt, sub( 26214 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_min( L_tmp, 268435456 ); + L_tmp = L_min( L_tmp, 268435456 /* 1 in Q28 */ ); L_tmp = Mult_32_16( L_tmp, qq ); /*Q23*/ est_level1 = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ @@ -1935,8 +1936,8 @@ static void envelope_fx( tmp = s_min( tmp, qq ); rr = s_min( tmp, rr ); - L_tmp = L_mult( abs_s( sub( tilt, 8192 ) ), sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_add( L_tmp, 268435456 ); + L_tmp = L_mult( abs_s( sub( tilt, 8192 /* 1 in Q13 */ ) ), sub( 26214 /* 1.6 in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_add( L_tmp, 268435456 /* 1 in Q28 */ ); L_tmp = Mult_32_16( L_tmp, rr ); /*Q23*/ est_level2 = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ @@ -1949,7 +1950,7 @@ static void envelope_fx( L_tmp = L_mult( rr, tmp ); /*Q(30-q1-10+10) */ #ifdef BASOP_NOGLOB - *sub_gain = s_min( 20480, round_fx_sat( L_shl_sat( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ + *sub_gain = s_min( 20480 /* 5.0f in Q12 */, round_fx_sat( L_shl_sat( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ move16(); #else *sub_gain = s_min( 20480, round_fx( L_shl( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ @@ -1963,15 +1964,15 @@ static void envelope_fx( * adaptively select the start band of bandwidth extension *---------------------------------------------------------------------*/ -void AdaptiveStartBand_fx( - Word16 *start_band, /* o : start point of copied band */ - const Word32 core_rate, /* i : core bitrate */ - const Word16 *lsf_fx, /* i : Q2 lsf frequency */ - const Word16 voicing_fac_fx, /* i : Q14 voicing factors */ - const Word16 clas, /* i : signal class (determined by FEC algorithm)*/ - Word16 *voicing_flag, - Word16 *start_band_old, - Word32 *OptCrit_old_fx /*i/o : Q15 */ +static void AdaptiveStartBand_fx( + Word16 *start_band, /* o : start point of copied band Q0*/ + const Word32 core_rate, /* i : core bitrate Q0*/ + const Word16 *lsf_fx, /* i : lsf frequency Q2*/ + const Word16 voicing_fac_fx, /* i : voicing factors Q14*/ + const Word16 clas, /* i : signal class (determined by FEC algorithm) Q0*/ + Word16 *voicing_flag, /* Q0 */ + Word16 *start_band_old, /* Q0 */ + Word32 *OptCrit_old_fx /*i/o : Q15 */ ) { Word16 i, pos, M2, voicing_flag_old; @@ -1985,19 +1986,19 @@ void AdaptiveStartBand_fx( move32(); // corresponding to initialization of OptCrit_fx /*voicing switching flag : to avoid switching start band frequently in VOICED or AUDIO area*/ - voicing_flag_old = *voicing_flag; + voicing_flag_old = *voicing_flag; /* Q0 */ move16(); test(); test(); test(); - if ( GT_16( voicing_fac_fx, 6554 ) || ( GT_16( voicing_fac_fx, 4915 ) && GE_16( clas, VOICED_CLAS ) ) || EQ_16( clas, AUDIO_CLAS ) ) + if ( GT_16( voicing_fac_fx, 6554 /* 0.4 in Q14 */ ) || ( GT_16( voicing_fac_fx, 4915 /* 0.3 in Q14 */ ) && GE_16( clas, VOICED_CLAS ) ) || EQ_16( clas, AUDIO_CLAS ) ) { - *voicing_flag = 1; + *voicing_flag = 1; /* Q0 */ move16(); } test(); - if ( LT_16( voicing_fac_fx, 3277 ) && LT_16( clas, VOICED_CLAS ) ) + if ( LT_16( voicing_fac_fx, 3277 /* 0.2 in Q14 */ ) && LT_16( clas, VOICED_CLAS ) ) { *voicing_flag = 0; move16(); @@ -2016,14 +2017,14 @@ void AdaptiveStartBand_fx( *pt1++ = sub( *pt2++, *pt3++ ); move16(); /*Q2 */ } - tmp1 = extract_l( Mult_32_16( core_rate, 27046 ) ); /*Q14 */ - L_tmp = L_shr( L_mult0( tmp1, 22370 ), 15 ); /*Q27->1/6000 ->Q26 */ - tmp2 = extract_l( L_tmp ); /*Q26 */ - W_fx = mult_r( tmp1, tmp2 ); /*Q25 */ + tmp1 = extract_l( Mult_32_16( core_rate, 27046 /* 0.00005 in Q29 */ ) ); /*Q14 */ + L_tmp = L_shr( L_mult0( tmp1, 22370 /* 1/6000 in Q27 */ ), 15 ); /*Q27->1/6000 ->Q26 */ + tmp2 = extract_l( L_tmp ); /*Q26 */ + W_fx = mult_r( tmp1, tmp2 ); /*Q25 */ IF( EQ_16( clas, AUDIO_CLAS ) ) { - W_fx = mult_r( W_fx, 24576 ); /*Q25 */ + W_fx = mult_r( W_fx, 24576 /* 0.75 in Q15 */ ); /*Q25 */ } pos = 2; @@ -2050,8 +2051,8 @@ void AdaptiveStartBand_fx( } /*do the procedure for i==2*/ - L_tmp = L_max( L_msu( 171798692, lsf_fx[2], W_fx ), 171799 ); /* Q2.56+25+1 */ - Crit_fx = Mult_32_16( L_tmp, lsf_diff_fx[2] ); /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */ + L_tmp = L_max( L_msu( 171798692 /* 1 in Q2.56+25+1 */, lsf_fx[2], W_fx ), 171799 /* 0.001 in Q2.56+25+1 */ ); /* Q2.56+25+1 */ + Crit_fx = Mult_32_16( L_tmp, lsf_diff_fx[2] ); /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */ OptCrit_fx = L_add( Crit_fx, 0 ); pos = 2; @@ -2062,37 +2063,37 @@ void AdaptiveStartBand_fx( pt1 = &lsf_diff_fx[3]; FOR( i = 3; i < M2; i++ ) { - L_tmp = L_max( L_msu( 171798692, *pt2++, W_fx ), 171799 ); /* Q2.56+25+1 */ + L_tmp = L_max( L_msu( 171798692 /* 1 in Q2.56+25+1 */, *pt2++, W_fx ), 171799 /* 0.001 in Q2.56+25+1 */ ); /* Q2.56+25+1 */ Crit_fx = Mult_32_16( L_tmp, *pt1++ ); /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */ IF( LE_32( Crit_fx, OptCrit_fx ) ) { OptCrit_fx = L_add( Crit_fx, 0 ); /* Q11+2.56+2.56 */ - pos = i; + pos = i; /* Q0 */ move16(); } } - tmp1 = add( mult_r( lsf_fx[pos - 1], 256 ), mult_r( lsf_fx[pos], 256 ) ); - *start_band = s_min( s_max( sub( tmp1, 40 ), 40 ), 160 ); + tmp1 = add( mult_r( lsf_fx[pos - 1], 256 ), mult_r( lsf_fx[pos], 256 ) ); /* Q0 */ + *start_band = s_min( s_max( sub( tmp1, 40 ), 40 ), 160 ); /* Q0 */ move16(); - L_tmp = Mult_32_16( *OptCrit_old_fx, 22938 ); /* Q11+2.56+2.56 */ + L_tmp = Mult_32_16( *OptCrit_old_fx, 22938 /* 0.7 in Q15 */ ); /* Q11+2.56+2.56 */ test(); test(); test(); test(); IF( NE_16( voicing_flag_old, *voicing_flag ) || ( *voicing_flag == 0 && LT_32( OptCrit_fx, *OptCrit_old_fx ) ) || - ( LT_32( OptCrit_fx, L_tmp ) && GT_32( *OptCrit_old_fx, 858993 ) ) ) + ( LT_32( OptCrit_fx, L_tmp ) && GT_32( *OptCrit_old_fx, 858993 /* 64 in Q11+2.56+2.56 */ ) ) ) { - *OptCrit_old_fx = OptCrit_fx; + *OptCrit_old_fx = OptCrit_fx; /* Q15 */ move16(); test(); test(); if ( LT_16( abs_s( sub( ( *start_band ), ( *start_band_old ) ) ), 20 ) && EQ_16( *voicing_flag, 1 ) && EQ_16( voicing_flag_old, 1 ) ) { - *start_band = *start_band_old; + *start_band = *start_band_old; /* Q0 */ move16(); } } @@ -2101,29 +2102,29 @@ void AdaptiveStartBand_fx( test(); if ( LT_32( OptCrit_fx, ( *OptCrit_old_fx ) ) && EQ_16( ( *voicing_flag ), 1 ) ) { - *OptCrit_old_fx = OptCrit_fx; + *OptCrit_old_fx = OptCrit_fx; /* Q15 */ move16(); } - *start_band = *start_band_old; + *start_band = *start_band_old; /* Q0 */ move16(); } IF( EQ_16( clas, AUDIO_CLAS ) ) { - *start_band = s_min( *start_band, 120 ); + *start_band = s_min( *start_band, 120 ); /* Q0 */ move16(); } flag = sub( s_and( *start_band, 0x0001 ), 1 ); IF( flag == 0 ) { - *start_band = sub( *start_band, 1 ); + *start_band = sub( *start_band, 1 ); /* Q0 */ move16(); } } - *start_band_old = *start_band; + *start_band_old = *start_band; /* Q0 */ move16(); return; diff --git a/lib_dec/hq_classifier_dec_fx.c b/lib_dec/hq_classifier_dec_fx.c index ace2e535ceeb365b5bac2e1f9a761456c0ef9ed9..e67d5f663357b91023c64f3242b5672c2b08bb70 100644 --- a/lib_dec/hq_classifier_dec_fx.c +++ b/lib_dec/hq_classifier_dec_fx.c @@ -26,11 +26,11 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits Word16 bits; Word32 max_brate; - max_brate = HQ_32k; + max_brate = HQ_32k; /* Q0 */ move32(); if ( st_fx->element_mode > EVS_MONO ) { - max_brate = HQ_48k; + max_brate = HQ_48k; /* Q0 */ move32(); } test(); @@ -38,21 +38,21 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits test(); IF( ( EQ_16( length, L_SPEC32k ) || EQ_16( length, L_SPEC48k ) ) && LE_32( core_brate, max_brate ) ) { - *hqswb_clas = (Word16) get_next_indice_fx( st_fx, 2 ); + *hqswb_clas = (Word16) get_next_indice_fx( st_fx, 2 ); /* Q0 */ move16(); bits = 2; move16(); } ELSE IF( EQ_16( length, L_SPEC16k_EXT ) || EQ_16( length, L_SPEC48k_EXT ) ) { - *hqswb_clas = HQ_NORMAL; + *hqswb_clas = HQ_NORMAL; /* Q0 */ bits = 0; move16(); move16(); } ELSE { - *hqswb_clas = get_next_indice_fx( st_fx, 1 ); + *hqswb_clas = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); bits = 1; move16(); @@ -62,7 +62,7 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits move16(); if ( EQ_16( *hqswb_clas, HQ_TRANSIENT ) ) { - *is_transient = 1; + *is_transient = 1; /* Q0 */ move16(); } @@ -71,12 +71,12 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits { IF( EQ_16( length, L_SPEC32k ) ) { - *hqswb_clas = HQ_GEN_SWB; + *hqswb_clas = HQ_GEN_SWB; /* Q0 */ move16(); } ELSE IF( EQ_16( length, L_SPEC48k ) ) { - *hqswb_clas = HQ_GEN_FB; + *hqswb_clas = HQ_GEN_FB; /* Q0 */ move16(); } } @@ -97,11 +97,11 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits Word16 bits; Word32 max_brate; - max_brate = HQ_32k; + max_brate = HQ_32k; /* Q0 */ move32(); if ( st_fx->element_mode > EVS_MONO ) { - max_brate = HQ_48k; + max_brate = HQ_48k; /* Q0 */ move32(); } #ifndef SOLVED_COMP_ENC_DEC @@ -116,21 +116,21 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits IF( ( EQ_16( length, L_SPEC32k ) || EQ_16( length, L_SPEC48k ) ) && LE_32( core_brate, max_brate ) ) #endif { - *hqswb_clas = get_next_indice( st_fx, 2 ); + *hqswb_clas = get_next_indice( st_fx, 2 ); /* Q0 */ move16(); bits = 2; move16(); } ELSE IF( EQ_16( length, L_SPEC16k_EXT ) || EQ_16( length, L_SPEC48k_EXT ) ) { - *hqswb_clas = HQ_NORMAL; + *hqswb_clas = HQ_NORMAL; /* Q0 */ bits = 0; move16(); move16(); } ELSE { - *hqswb_clas = get_next_indice( st_fx, 1 ); + *hqswb_clas = get_next_indice( st_fx, 1 ); /* Q0 */ move16(); bits = 1; move16(); @@ -140,7 +140,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits move16(); if ( EQ_16( *hqswb_clas, HQ_TRANSIENT ) ) { - *is_transient = 1; + *is_transient = 1; /* Q0 */ move16(); } @@ -149,7 +149,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits { IF( EQ_16( length, L_SPEC32k ) ) { - *hqswb_clas = HQ_GEN_SWB; + *hqswb_clas = HQ_GEN_SWB; /* Q0 */ move16(); } #ifndef SOLVED_COMP_ENC_DEC @@ -158,7 +158,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits ELSE IF( EQ_16( length, L_SPEC48k ) ) #endif { - *hqswb_clas = HQ_GEN_FB; + *hqswb_clas = HQ_GEN_FB; /* Q0 */ move16(); } } diff --git a/lib_dec/hq_conf_fec_fx.c b/lib_dec/hq_conf_fec_fx.c index dfc19c542dae9ad137e032b0afd4ae1a6cd7ed1f..adcd8307602b62ffa2aa13dfdcf76be9380e2d5a 100644 --- a/lib_dec/hq_conf_fec_fx.c +++ b/lib_dec/hq_conf_fec_fx.c @@ -16,22 +16,22 @@ * Initialization of HQ bands and subframes *--------------------------------------------------------------------------*/ void hq_configure_bfi_fx( - Word16 *nb_sfm, /* o : Number of sub bands Q0 */ - Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0 */ - Word16 *num_bands_p, /* o : FEC sub bands Q0 */ - const Word16 **sfmsize, /* o : Subband bandwidths */ - const Word16 **sfm_start, /* o : Subband start coefficients */ - const Word16 **sfm_end /* o : Subband end coefficients */ + Word16 *nb_sfm, /* o : Number of sub bands Q0*/ + Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0*/ + Word16 *num_bands_p, /* o : FEC sub bands Q0*/ + const Word16 **sfmsize, /* o : Subband bandwidths Q0*/ + const Word16 **sfm_start, /* o : Subband start coefficients Q0*/ + const Word16 **sfm_end /* o : Subband end coefficients Q0*/ ) { - *num_Sb = MAX_SB_NB; + *num_Sb = MAX_SB_NB; /* Q0 */ move16(); - *nb_sfm = SFM_N_NB; + *nb_sfm = SFM_N_NB; /* Q0 */ move16(); - Copy( Num_bands_NB, num_bands_p, *num_Sb ); - *sfmsize = band_len_wb; - *sfm_start = band_start_wb; - *sfm_end = band_end_wb; + Copy( Num_bands_NB, num_bands_p, *num_Sb ); /* Q0 */ + *sfmsize = band_len_wb; /* Q0 */ + *sfm_start = band_start_wb; /* Q0 */ + *sfm_end = band_end_wb; /* Q0 */ move16(); move16(); move16(); diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 9ff88999783a2d5f65e96425ca04f068c5126158..de8d19e32e0914feb2afde82f4aabffc0c68c48c 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -19,11 +19,11 @@ void hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ + Word16 synth[], /* o : output synthesis Q_synth*/ Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag */ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag Q0*/ ) { Word16 num_bits, is_transient, hqswb_clas, inner_frame; @@ -62,15 +62,17 @@ void hq_core_dec_fx( move16(); sfm_start = sfm_end = NULL; num_Sb = nb_sfm = 0; + move16(); + move16(); - st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; + st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; /* Q0 */ move16(); if ( EQ_16( st_fx->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) { - st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); } - st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); /*-------------------------------------------------------------------------- * Find the number of bits for transform-domain coding @@ -114,18 +116,18 @@ void hq_core_dec_fx( } #endif /* subtract signalling bits */ - num_bits = sub( num_bits, st_fx->next_bit_pos ); + num_bits = sub( num_bits, st_fx->next_bit_pos ); /* Q0 */ /* set FEC parameters */ - flag_uv = sub( 1, hHQ_core->HqVoicing ); + flag_uv = sub( 1, hHQ_core->HqVoicing ); /* Q0 */ /* subtract the number of bits for pitch & gain at higher bitrates */ test(); IF( !( core_switching_flag ) && GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = get_next_indice( st_fx, 1 ); + hHQ_core->HqVoicing = get_next_indice( st_fx, 1 ); /* Q0 */ move16(); - num_bits = sub( num_bits, 1 ); + num_bits = sub( num_bits, 1 ); /* Q0 */ } ELSE { @@ -133,7 +135,7 @@ void hq_core_dec_fx( move16(); if ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = 1; + hHQ_core->HqVoicing = 1; /* Q0 */ move16(); } } @@ -145,10 +147,10 @@ void hq_core_dec_fx( } /* set inner frame (== coded bandwidth) length */ - inner_frame = inner_frame_tbl[st_fx->bwidth]; + inner_frame = inner_frame_tbl[st_fx->bwidth]; /* Q0 */ move16(); #ifndef ADD_IVAS_HQ_CODE_L_SPEC - L_spec = inner_frame; + L_spec = inner_frame; /* Q0 */ #endif move16(); @@ -174,7 +176,7 @@ void hq_core_dec_fx( IF( EQ_16( st_fx->bfi, 1 ) ) { - is_transient = hHQ_core->old_is_transient[0]; + is_transient = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) /* Apply phase ecu for WB, SWB and FB */ { @@ -189,22 +191,22 @@ void hq_core_dec_fx( output_frame, sfm_start, sfm_end ); } - hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; + hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; /* Q0 */ move16(); - hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; + hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) { /* keep st->previoussynth updated as in FEC_HQ_pitch_analysis but no LP analysis */ - delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); /* Q0 */ - Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); - Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); + Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); /* Q0 */ + Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); /* Q0 */ flag_uv = 1; move16(); /* disable costly pitch out synthesis in bfi frame */ - hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic */ + hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic Q0*/ set16_fx( hHQ_core->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ } } @@ -222,7 +224,7 @@ void hq_core_dec_fx( /* HQ low rate decoder */ hq_lr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, &is_transient ); - hqswb_clas = is_transient; + hqswb_clas = is_transient; /* Q0 */ move16(); Q_audio = 12; move16(); @@ -251,8 +253,8 @@ void hq_core_dec_fx( } ELSE { - tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ - ener_match = hq_nominal_scaling_inv[tmp]; + tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ + ener_match = hq_nominal_scaling_inv[tmp]; /* Q13 */ move16(); FOR( i = 0; i < inner_frame; i++ ) { @@ -280,7 +282,7 @@ void hq_core_dec_fx( IF( EQ_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) ) { ener_match = 32767; - move16(); /*Q15*/ + move16(); /* 1.0f in Q15 */ } ELSE { @@ -291,11 +293,11 @@ void hq_core_dec_fx( { FOR( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) { - tmp_loop = mult( inner_frame, 8192 ); - FOR( j = mult( inner_frame_tbl[sub( st_fx->bwidth, 1 )], 8192 ); j < tmp_loop; j++ ) + tmp_loop = mult( inner_frame, 8192 /* 0.25 in Q15 */ ); + FOR( j = mult( inner_frame_tbl[st_fx->bwidth - 1], 8192 ); j < tmp_loop; j++ ) { - tmp = i_mult( i, inner_frame ); /*Q0*/ - tmp = mult( tmp, 8192 ); /*Q0*/ + tmp = i_mult( i, inner_frame ); /*Q0*/ + tmp = mult( tmp, 8192 /* 0.25 in Q15 */ ); /*Q0*/ tmp = add( tmp, j ); t_audio_q[tmp] = Mult_32_16( t_audio_q[tmp], ener_match ); move32(); /*Q12*/ @@ -304,7 +306,7 @@ void hq_core_dec_fx( } ELSE { - FOR( i = inner_frame_tbl[sub( st_fx->bwidth, 1 )]; i < inner_frame; i++ ) + FOR( i = inner_frame_tbl[st_fx->bwidth - 1]; i < inner_frame; i++ ) { t_audio_q[i] = Mult_32_16( t_audio_q[i], ener_match ); /*Q12*/ move32(); @@ -315,11 +317,11 @@ void hq_core_dec_fx( /* WB/SWB bandwidth switching */ IF( is_transient ) { - Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); + Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); /* -1Q */ } ELSE { - Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); + Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); /* -1Q */ } @@ -421,7 +423,7 @@ void hq_core_dec_fx( test(); IF( st_fx->bfi == 0 && st_fx->prev_bfi == 0 ) { - Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); /* 15 - exp_old_out - Q_old_wtda */ } ELSE IF( EQ_16( st_fx->prev_bfi, 1 ) ) { @@ -499,7 +501,7 @@ void hq_core_dec_fx( IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && st_fx->plcInfo.concealment_method == TCX_NONTONAL && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) { #ifdef BASOP_NOGLOB - st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); + st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); /* Q14 + Q_synth */ move16(); #else st_fx->plcInfo.recovery_gain = shl( st_fx->plcInfo.recovery_gain, *Q_synth ); @@ -526,7 +528,7 @@ void hq_core_dec_fx( { hHQ_core->oldHqVoicing = 1; move16(); - Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); + Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); /* q_gapsynth */ } ELSE { @@ -548,9 +550,9 @@ void hq_core_dec_fx( IF( EQ_16( output_frame, L_FRAME8k ) ) { - Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); - Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); - Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); + Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); /* q_wtda */ + Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); /* q_old_auOut */ + Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); /* Q0 */ } /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ @@ -558,11 +560,11 @@ void hq_core_dec_fx( { Word16 nbsubfr; /*nbsubfr = extract_l(L_mult0(st_fx->L_frame,FL2WORD16(1/L_SUBFR)));*/ - nbsubfr = 4; + nbsubfr = 4; /* Q0 */ move16(); if ( EQ_16( st_fx->L_frame, 320 ) ) { - nbsubfr = 5; + nbsubfr = 5; /* Q0 */ move16(); } @@ -572,9 +574,9 @@ void hq_core_dec_fx( { set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); } - Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); + Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); /* 15Q16 */ set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); - Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); + Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); /* Q14 */ set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); } #ifdef ADD_IVAS_HQ_CODE @@ -590,12 +592,12 @@ void hq_core_dec_fx( void ivas_hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ + Word16 synth[], /* o : output synthesis Q_synth*/ Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag */ - Word16 output[], + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag Q0*/ + Word16 output[], /* Q_ouput */ Word16 *Q_output ) { Word16 num_bits, is_transient, hqswb_clas, inner_frame; @@ -656,14 +658,14 @@ void ivas_hq_core_dec_fx( hTcxDec = st_fx->hTcxDec; - st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; + st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; /* Q0 */ move16(); if ( EQ_16( st_fx->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) { - st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); } - st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); test(); test(); @@ -678,7 +680,7 @@ void ivas_hq_core_dec_fx( num_bits = extract_l( L_shr( L_tmp, 3 ) ); /*Q0 */ /* Set default spectrum length */ - L_spec = l_spec_tbl[st_fx->bwidth]; + L_spec = l_spec_tbl[st_fx->bwidth]; /* Q0 */ move16(); IF( !st_fx->bfi ) { @@ -686,7 +688,7 @@ void ivas_hq_core_dec_fx( { IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { - L_spec = l_spec_ext_tbl[st_fx->bwidth]; + L_spec = l_spec_ext_tbl[st_fx->bwidth]; /* Q0 */ move16(); } ELSE @@ -706,18 +708,18 @@ void ivas_hq_core_dec_fx( acelp_plc_mdct_transition_fx( st_fx ); } /* subtract signalling bits */ - num_bits = sub( num_bits, st_fx->next_bit_pos ); + num_bits = sub( num_bits, st_fx->next_bit_pos ); /* Q0 */ /* set FEC parameters */ - flag_uv = sub( 1, hHQ_core->HqVoicing ); + flag_uv = sub( 1, hHQ_core->HqVoicing ); /* Q0 */ /* subtract the number of bits for pitch & gain at higher bitrates */ test(); IF( !( core_switching_flag ) && GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = get_next_indice_fx( st_fx, 1 ); + hHQ_core->HqVoicing = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); - num_bits = sub( num_bits, 1 ); + num_bits = sub( num_bits, 1 ); /* Q0 */ } ELSE { @@ -725,7 +727,7 @@ void ivas_hq_core_dec_fx( move16(); if ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = 1; + hHQ_core->HqVoicing = 1; /* Q0 */ move16(); } } @@ -737,7 +739,7 @@ void ivas_hq_core_dec_fx( } /* set inner frame (== coded bandwidth) length */ - inner_frame = inner_frame_tbl[st_fx->bwidth]; + inner_frame = inner_frame_tbl[st_fx->bwidth]; /* Q0 */ move16(); IF( EQ_16( st_fx->bfi, 0 ) ) @@ -746,7 +748,7 @@ void ivas_hq_core_dec_fx( move16(); if ( GE_16( output_frame, L_FRAME16k ) ) { - hHQ_core->ph_ecu_HqVoicing = hHQ_core->HqVoicing; + hHQ_core->ph_ecu_HqVoicing = hHQ_core->HqVoicing; /* Q0 */ move16(); } } @@ -762,7 +764,7 @@ void ivas_hq_core_dec_fx( IF( EQ_16( st_fx->bfi, 1 ) ) { - is_transient = hHQ_core->old_is_transient[0]; + is_transient = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) /* Apply phase ecu for WB, SWB and FB */ { @@ -777,22 +779,22 @@ void ivas_hq_core_dec_fx( output_frame, sfm_start, sfm_end ); } - hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; + hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; /* Q0 */ move16(); - hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; + hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) { /* keep st->previoussynth updated as in FEC_HQ_pitch_analysis but no LP analysis */ - delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); /* Q0 */ - Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); - Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); + Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); /* q_previoussynth */ + Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); /* q_delay_buff */ flag_uv = 1; move16(); /* disable costly pitch out synthesis in bfi frame */ - hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic */ + hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic Q0*/ move16(); set16_fx( hHQ_core->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ } @@ -811,7 +813,7 @@ void ivas_hq_core_dec_fx( /* HQ low rate decoder */ hq_lr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, &is_transient ); - hqswb_clas = is_transient; + hqswb_clas = is_transient; /* Q0 */ move16(); Q_audio = 12; move16(); @@ -843,8 +845,8 @@ void ivas_hq_core_dec_fx( } ELSE { - tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ - ener_match = hq_nominal_scaling_inv[tmp]; + tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ + ener_match = hq_nominal_scaling_inv[tmp]; /* Q13 */ move16(); FOR( i = 0; i < inner_frame; i++ ) { @@ -872,7 +874,7 @@ void ivas_hq_core_dec_fx( IF( EQ_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) ) { ener_match = 32767; - move16(); /*Q15*/ + move16(); /* 1.0f in Q15*/ } ELSE { @@ -883,11 +885,11 @@ void ivas_hq_core_dec_fx( { FOR( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) { - tmp_loop = mult( inner_frame, 8192 ); - FOR( j = mult( inner_frame_tbl[sub( st_fx->bwidth, 1 )], 8192 ); j < tmp_loop; j++ ) + tmp_loop = mult( inner_frame, 8192 /* 0.25 in Q15 */ ); /* Q0 */ + FOR( j = mult( inner_frame_tbl[st_fx->bwidth - 1], 8192 ); j < tmp_loop; j++ ) { - tmp = i_mult( i, inner_frame ); /*Q0*/ - tmp = mult( tmp, 8192 ); /*Q0*/ + tmp = i_mult( i, inner_frame ); /*Q0*/ + tmp = mult( tmp, 8192 /* 0.25 in Q15 */ ); /*Q0*/ tmp = add( tmp, j ); t_audio_q[tmp] = Mult_32_16( t_audio_q[tmp], ener_match ); move32(); /*Q12*/ @@ -896,7 +898,7 @@ void ivas_hq_core_dec_fx( } ELSE { - FOR( i = inner_frame_tbl[sub( st_fx->bwidth, 1 )]; i < inner_frame; i++ ) + FOR( i = inner_frame_tbl[st_fx->bwidth - 1]; i < inner_frame; i++ ) { t_audio_q[i] = Mult_32_16( t_audio_q[i], ener_match ); /*Q12*/ move32(); @@ -907,11 +909,11 @@ void ivas_hq_core_dec_fx( /* WB/SWB bandwidth switching */ IF( is_transient ) { - Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); + Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); /* -1Q */ } ELSE { - Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); + Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); /* -1Q */ } @@ -926,34 +928,34 @@ void ivas_hq_core_dec_fx( { /* Initializations for TCX MDCT framework, to be used for switching frame */ tcx_cfg = st_fx->hTcxCfg; - L_frameTCX_glob = hTcxDec->L_frameTCX; + L_frameTCX_glob = hTcxDec->L_frameTCX; /* Q0 */ move16(); - L_frame_glob = st_fx->L_frame; + L_frame_glob = st_fx->L_frame; /* Q0 */ move16(); - L_spec = hTcxDec->L_frameTCX; + L_spec = hTcxDec->L_frameTCX; /* Q0 */ move16(); - st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); + st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); /* Q0 */ // fscaleFB = sr2fscale( st_fx->output_Fs ); // encoderLookahead = ( L_LOOK_12k8 * st_fx->fscale ) / FSCALE_DENOM; // encoderLookaheadFB = ( L_LOOK_12k8 * fscaleFB ) / FSCALE_DENOM; - mdctWindowLength = getMdctWindowLength( st_fx->fscale ); + mdctWindowLength = getMdctWindowLength( st_fx->fscale ); /* Q0 */ Word16 temp, temp_e; temp = BASOP_Util_Divide3232_Scale( st_fx->output_Fs, st_fx->sr_core, &temp_e ); - mdctWindowLengthFB = extract_l( L_shr( L_mult0( temp, mdctWindowLength ), sub( 15, temp_e ) ) ); + mdctWindowLengthFB = extract_l( L_shr( L_mult0( temp, mdctWindowLength ), sub( 15, temp_e ) ) ); /* Q0 */ IF( core_switching_flag ) { - tcx_cfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; + tcx_cfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; /* Q0 */ move16(); - tcx_cfg->tcx_curr_overlap_mode = FULL_OVERLAP; + tcx_cfg->tcx_curr_overlap_mode = FULL_OVERLAP; /* Q0 */ move16(); } ELSE { - tcx_cfg->tcx_last_overlap_mode = ALDO_WINDOW; + tcx_cfg->tcx_last_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); - tcx_cfg->tcx_curr_overlap_mode = ALDO_WINDOW; + tcx_cfg->tcx_curr_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); - st_fx->last_core = HQ_CORE; /* Needed to decode non-transition frame */ + st_fx->last_core = HQ_CORE; /* Needed to decode non-transition frame Q0*/ move16(); } @@ -961,11 +963,11 @@ void ivas_hq_core_dec_fx( init_tcx_info_fx( st_fx, L_frame_glob, L_frameTCX_glob, 0, st_fx->bfi, &tcx_offset, &tcx_offsetFB, &L_frame, &L_frameTCX, &left_rect, &L_spec ); - overlap = tcx_cfg->tcx_mdct_window_length; + overlap = tcx_cfg->tcx_mdct_window_length; /* Q0 */ move16(); - overlapFB = tcx_cfg->tcx_mdct_window_lengthFB; + overlapFB = tcx_cfg->tcx_mdct_window_lengthFB; /* Q0 */ move16(); - index = tcx_cfg->tcx_last_overlap_mode; + index = tcx_cfg->tcx_last_overlap_mode; /* Q0 */ move16(); #ifndef MSAN_FIX @@ -978,9 +980,9 @@ void ivas_hq_core_dec_fx( left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, 0, st_fx->bfi, hHQ_core->old_out_LB_fx, &hHQ_core->Q_old_wtda_LB, st_fx, 0, acelp_zir ); // values till L_frame same - Scale_sig( wtda_audio_16 + L_frame, overlap, Q1 ); + Scale_sig( wtda_audio_16 + L_frame, overlap, Q1 ); /* q_wtda + 1 */ - Copy( wtda_audio_16 + sub( shr( overlap, 1 ), tcx_offset ), output, L_frame_glob ); + Copy( wtda_audio_16 + sub( shr( overlap, 1 ), tcx_offset ), output, L_frame_glob ); /* q_wtda + 1 */ /* FB synthesis */ temp = BASOP_Util_Divide3232_Scale( L_mult0( FSCALE_DENOM, L_frameTCX_glob ), L_frame_glob, &temp_e ); @@ -988,14 +990,14 @@ void ivas_hq_core_dec_fx( IMDCT_fx( t_audio_q, E_audio, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, wtda_audio_16, tcx_cfg->tcx_aldo_window_1_FB, tcx_cfg->tcx_aldo_window_1_FB_trunc, tcx_cfg->tcx_aldo_window_2_FB, tcx_cfg->tcx_mdct_window_halfFB, tcx_cfg->tcx_mdct_window_minimumFB, tcx_cfg->tcx_mdct_window_transFB, tcx_cfg->tcx_mdct_window_half_lengthFB, tcx_cfg->tcx_mdct_window_min_lengthFB, index, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, 0, st_fx->bfi, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, st_fx, temp, acelp_zir ); - Scale_sig( wtda_audio_16 + L_frameTCX, overlapFB, Q1 ); + Scale_sig( wtda_audio_16 + L_frameTCX, overlapFB, Q1 ); /* q_wtda + 1 */ - Copy( wtda_audio_16 + sub( shr( overlapFB, 1 ), tcx_offsetFB ), synth, L_frameTCX_glob ); + Copy( wtda_audio_16 + sub( shr( overlapFB, 1 ), tcx_offsetFB ), synth, L_frameTCX_glob ); /* q_wtda */ - Copy_Scale_sig_16_32( wtda_audio_16, wtda_audio, 2 * L_FRAME48k, 12 ); + Copy_Scale_sig_16_32( wtda_audio_16, wtda_audio, 2 * L_FRAME48k, 12 ); /* q_wtda + 12 */ IF( !core_switching_flag ) { - st_fx->last_core = ACELP_CORE; /* Restore last core */ + st_fx->last_core = ACELP_CORE; /* Restore last core Q0*/ move16(); } } @@ -1036,9 +1038,9 @@ void ivas_hq_core_dec_fx( tmp = Sqrt16( tmp, &tmp_e ); ener_match = shr( tmp, sub( 2, tmp_e ) ); // Q13 - v_multc_fixed_16( t_audio_q, ener_match, t_audio_q, inner_frame ); // Q + v_multc_fixed_16( t_audio_q, ener_match, t_audio_q, inner_frame ); // Q10 - Scale_sig32( t_audio_q, inner_frame, Q2 ); + Scale_sig32( t_audio_q, inner_frame, Q2 ); // Q10 + Q2 Q_audio = Q_G_audio; move16(); Inverse_Transform( t_audio_q, &Q_audio, wtda_audio_LB, is_transient, st_fx->L_frame, inner_frame, st_fx->element_mode ); @@ -1052,7 +1054,7 @@ void ivas_hq_core_dec_fx( test(); IF( EQ_16( st_fx->bfi, 0 ) && st_fx->prev_bfi == 0 ) { - Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); /* 31 - exp_old_out - Q_old_wtda */ } ELSE IF( EQ_16( st_fx->prev_bfi, 1 ) ) { @@ -1129,7 +1131,7 @@ void ivas_hq_core_dec_fx( IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st_fx->plcInfo.concealment_method, TCX_NONTONAL ) && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) { #ifdef BASOP_NOGLOB - st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); + st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); /* Q15 */ #else st_fx->plcInfo.recovery_gain = shl( st_fx->plcInfo.recovery_gain, *Q_synth ); #endif @@ -1155,7 +1157,7 @@ void ivas_hq_core_dec_fx( { hHQ_core->oldHqVoicing = 1; move16(); - Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); + Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); /* q_gapsynth */ } ELSE { @@ -1177,9 +1179,9 @@ void ivas_hq_core_dec_fx( IF( EQ_16( output_frame, L_FRAME8k ) ) { - Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); - Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); - Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); + Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); /* q_wtda */ + Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); /* Q_old_auOut */ + Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); /* Q0 */ } /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ @@ -1187,10 +1189,10 @@ void ivas_hq_core_dec_fx( { Word16 nbsubfr; /*nbsubfr = extract_l(L_mult0(st_fx->L_frame,FL2WORD16(1/L_SUBFR)));*/ - nbsubfr = 4; + nbsubfr = 4; /* Q0 */ if ( EQ_16( st_fx->L_frame, 320 ) ) { - nbsubfr = 5; + nbsubfr = 5; /* Q0 */ move16(); } @@ -1200,16 +1202,16 @@ void ivas_hq_core_dec_fx( { set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); } - Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); + Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); /* 15Q16 */ set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); - Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); + Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); /* Q14 */ set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); } /* Move LB excitation to old_exc memory in case of switch HQ->ACELP */ IF( st_fx->element_mode > EVS_MONO ) { - Copy_Scale_sig( output, tmp_out, st_fx->L_frame, -( *Q_output ) ); - Copy( tmp_out, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame ); + Copy_Scale_sig( output, tmp_out, st_fx->L_frame, negate( *Q_output ) ); /* Q0 */ + Copy( tmp_out, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame ); /* Q0 */ } return; } @@ -1238,7 +1240,7 @@ void HQ_core_dec_init_fx( move16(); move16(); - hHQ_core->last_hq_core_type = -1; + hHQ_core->last_hq_core_type = -1; /* Q0 */ move16(); set16_fx( hHQ_core->old_is_transient, 0, 3 ); @@ -1251,7 +1253,7 @@ void HQ_core_dec_init_fx( move16(); move16(); move16(); - hHQ_core->energy_lt_fx = 2457600; /*Q13*/ + hHQ_core->energy_lt_fx = 2457600; /*300.0f in Q13*/ hHQ_core->hq_generic_seed = RANDOM_INITSEED; set16_fx( hHQ_core->prev_noise_level_fx, 0, 2 ); hHQ_core->prev_hqswb_clas = HQ_NORMAL; @@ -1281,7 +1283,7 @@ void HQ_core_dec_init_fx( move16(); hHQ_core->prev_stab_hfe2 = 0; move16(); - hHQ_core->prev_ni_ratio_fx = 16384; /*Q15*/ + hHQ_core->prev_ni_ratio_fx = 16384; /*0.5 in Q15*/ move16(); set16_fx( hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); @@ -1309,9 +1311,9 @@ void HQ_core_dec_init_fx( set16_fx( hHQ_core->env_stab_state_p_fx, INV_NUM_ENV_STAB_PLC_STATES, NUM_ENV_STAB_PLC_STATES ); hHQ_core->envstabplc_hocnt = 0; move16(); - set16_fx( hHQ_core->mag_chg_1st_fx, 32767, LGW_MAX ); + set16_fx( hHQ_core->mag_chg_1st_fx, 32767 /* 1.0f in Q15 */, LGW_MAX ); set16_fx( hHQ_core->Xavg_fx, 0, LGW_MAX ); - hHQ_core->beta_mute_fx = BETA_MUTE_FAC_INI; + hHQ_core->beta_mute_fx = BETA_MUTE_FAC_INI; /* Q15 */ hHQ_core->last_fec = 0; hHQ_core->ph_ecu_HqVoicing = 0; hHQ_core->oldHqVoicing = 0; @@ -1343,7 +1345,7 @@ void HQ_nbfec_init_fx( { Word16 i, j; - hHQ_nbfec->prev_last_core = -1; + hHQ_nbfec->prev_last_core = -1; /* Q0 */ hHQ_nbfec->diff_energy_fx = 0; hHQ_nbfec->stat_mode_out = 0; hHQ_nbfec->stat_mode_old = 0; diff --git a/lib_dec/hq_env_dec_fx.c b/lib_dec/hq_env_dec_fx.c index 81385aaaa82855e681dc997247ab1ff12c37fca3..677221f310a35ae66c94efe75a7e99d59ed1f7d9 100644 --- a/lib_dec/hq_env_dec_fx.c +++ b/lib_dec/hq_env_dec_fx.c @@ -14,15 +14,15 @@ * Decode envelope indices *------------------------------------------------------------------------*/ -Word16 decode_envelope_indices_fx( /* o : Number of bits */ +Word16 decode_envelope_indices_fx( /* o : Number of bits Q0*/ Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : starting band index */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode */ - Word16 *difidx, /* o : Diff indices/encoded diff indices */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core */ + const Word16 start_norm, /* i : starting band index Q0*/ + const Word16 num_sfm, /* i : Number of subbands Q0*/ + const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0*/ + Word16 *difidx, /* o : Diff indices/encoded diff indices Q0*/ + const Word16 flag_HQ2 /* i : indicator of HQ2 core Q0*/ , - const Word16 is_transient /* i : indicator of HQ_TRANSIENT */ + const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0*/ ) { Word16 hcode_l; @@ -34,14 +34,14 @@ Word16 decode_envelope_indices_fx( /* o : Number of b test(); IF( EQ_16( flag_HQ2, LOW_RATE_HQ_CORE ) || EQ_16( flag_HQ2, LOW_RATE_HQ_CORE_TRAN ) ) { - LCmode = (Word16) get_next_indice_fx( st_fx, BITS_DE_HMODE ); - difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, BITS_DE_FCOMP ); + LCmode = (Word16) get_next_indice_fx( st_fx, BITS_DE_HMODE ); /* Q0 */ + difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, BITS_DE_FCOMP ); /* Q0 */ move16(); } ELSE { - LCmode = (Word16) get_next_indice_fx( st_fx, 2 ); - difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, NORM0_BITS ); + LCmode = (Word16) get_next_indice_fx( st_fx, 2 ); /* Q0 */ + difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, NORM0_BITS ); /* Q0 */ move16(); } @@ -53,10 +53,10 @@ Word16 decode_envelope_indices_fx( /* o : Number of b IF( EQ_16( LCmode, 1 ) ) { hdecnrm_tran_fx( st_fx, num_sfm, &difidx[start_norm + 1] ); - j = add( start_norm, num_sfm ); + j = add( start_norm, num_sfm ); /* Q0 */ FOR( i = start_norm + 1; i < j; i++ ) { - hcode_l = add( hcode_l, huffsizn_tran[difidx[i]] ); + hcode_l = add( hcode_l, huffsizn_tran[difidx[i]] ); /* Q0 */ } } ELSE @@ -74,68 +74,68 @@ Word16 decode_envelope_indices_fx( /* o : Number of b } ELSE IF( EQ_16( LCmode, 1 ) ) { - startNormPlus1 = add( start_norm, 1 ); + startNormPlus1 = add( start_norm, 1 ); /* Q0 */ hdecnrm_resize_fx( st_fx, num_sfm, &difidx[startNormPlus1] ); - pDifidx = &difidx[startNormPlus1]; + pDifidx = &difidx[startNormPlus1]; /* Q0 */ move16(); - numSfmMinus1 = sub( num_sfm, 1 ); + numSfmMinus1 = sub( num_sfm, 1 ); /* Q0 */ FOR( i = 0; i < numSfmMinus1; i++ ) { j = *pDifidx++; move16(); - hcode_l = add( hcode_l, resize_huffsizn[j] ); + hcode_l = add( hcode_l, resize_huffsizn[j] ); /* Q0 */ } - pDifidx1 = &difidx[startNormPlus1]; + pDifidx1 = &difidx[startNormPlus1]; /* Q0 */ move16(); - numSfmMinus2 = sub( num_sfm, 2 ); + numSfmMinus2 = sub( num_sfm, 2 ); /* Q0 */ FOR( i = 0; i < numSfmMinus2; i++ ) { - pDifidx = pDifidx1++; + pDifidx = pDifidx1++; /* Q0 */ move16(); IF( GT_16( *pDifidx, 17 ) ) { - offset = sub( *pDifidx, 17 ); - offset = s_min( offset, 3 ); - *pDifidx1 = sub( *pDifidx1, offset ); + offset = sub( *pDifidx, 17 ); /* Q0 */ + offset = s_min( offset, 3 ); /* Q0 */ + *pDifidx1 = sub( *pDifidx1, offset ); /* Q0 */ move16(); } ELSE IF( LT_16( *pDifidx, 13 ) ) { - offset = sub( *pDifidx, 13 ); - offset = s_max( offset, -3 ); - *pDifidx1 = sub( *pDifidx1, offset ); + offset = sub( *pDifidx, 13 ); /* Q0 */ + offset = s_max( offset, -3 ); /* Q0 */ + *pDifidx1 = sub( *pDifidx1, offset ); /* Q0 */ move16(); } } } ELSE IF( EQ_16( LCmode, 2 ) ) { - startNormPlus1 = add( start_norm, 1 ); + startNormPlus1 = add( start_norm, 1 ); /* Q0 */ hdecnrm_fx( st_fx, num_sfm, &difidx[start_norm + 1] ); - pDifidx = &difidx[startNormPlus1]; + pDifidx = &difidx[startNormPlus1]; /* Q0 */ move16(); - numSfmMinus1 = sub( num_sfm, 1 ); + numSfmMinus1 = sub( num_sfm, 1 ); /* Q0 */ FOR( i = 0; i < numSfmMinus1; i++ ) { - j = *pDifidx++; + j = *pDifidx++; /* Q0 */ move16(); - hcode_l = add( hcode_l, huffsizn[j] ); + hcode_l = add( hcode_l, huffsizn[j] ); /* Q0 */ } } ELSE { - startNormPlus1 = add( start_norm, 1 ); - numSfmMinus1 = sub( num_sfm, 1 ); - pDifidx = &difidx[startNormPlus1]; + startNormPlus1 = add( start_norm, 1 ); /* Q0 */ + numSfmMinus1 = sub( num_sfm, 1 ); /* Q0 */ + pDifidx = &difidx[startNormPlus1]; /* Q0 */ FOR( i = 0; i < numSfmMinus1; i++ ) { - *pDifidx++ = (Word16) get_next_indice_fx( st_fx, NORMI_BITS ); + *pDifidx++ = (Word16) get_next_indice_fx( st_fx, NORMI_BITS ); /* Q0 */ move16(); } - hcode_l = numnrmibits; + hcode_l = numnrmibits; /* Q0 */ move16(); } } @@ -152,12 +152,12 @@ Word16 decode_envelope_indices_fx( /* o : Number of b *------------------------------------------------------------------------*/ void dequantize_norms_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : First SDE encoded norm */ - const Word16 num_sfm, /* i : Number of norms */ - const Word16 is_transient, /* i : Transient flag */ - Word16 *ynrm, /* o : Decoded norm indices */ - Word16 *normqlg2 /* o : Log2 of decoded norms */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 start_norm, /* i : First SDE encoded norm Q0*/ + const Word16 num_sfm, /* i : Number of norms Q0*/ + const Word16 is_transient, /* i : Transient flag Q0*/ + Word16 *ynrm, /* o : Decoded norm indices Q0*/ + Word16 *normqlg2 /* o : Log2 of decoded norms Q0*/ ) { Word16 i, j; @@ -165,28 +165,28 @@ void dequantize_norms_fx( Word16 *pYnrm, *pNormqlg2; /* First sub-frame */ - i = ynrm[start_norm]; + i = ynrm[start_norm]; /* Q0 */ move16(); - normqlg2[start_norm] = dicnlg2[i]; + normqlg2[start_norm] = dicnlg2[i]; /* Q0 */ move16(); /* Other sub-frames */ IF( is_transient ) { /* Recover quantization indices and quantized norms */ - idxbuf[0] = ynrm[0]; + idxbuf[0] = ynrm[0]; /* Q0 */ move16(); FOR( i = 1; i < num_sfm; i++ ) { - idxbuf[i] = sub( add( ynrm[i], idxbuf[i - 1] ), 15 ); + idxbuf[i] = sub( add( ynrm[i], idxbuf[i - 1] ), 15 ); /* Q0 */ move16(); /* safety check in case of bit errors */ test(); IF( idxbuf[i] < 0 || GT_16( idxbuf[i], 39 ) ) { - idxbuf[i] = 39; + idxbuf[i] = 39; /* Q0 */ move16(); - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } } @@ -195,26 +195,26 @@ void dequantize_norms_fx( } ELSE { - pYnrm = &ynrm[start_norm]; + pYnrm = &ynrm[start_norm]; /* Q0 */ move16(); - pNormqlg2 = &normqlg2[start_norm + 1]; + pNormqlg2 = &normqlg2[start_norm + 1]; /* Q0 */ move16(); FOR( i = 1; i < num_sfm; i++ ) { - j = sub( *pYnrm++, 15 ); + j = sub( *pYnrm++, 15 ); /* Q0 */ move16(); - *pYnrm = add( *pYnrm, j ); + *pYnrm = add( *pYnrm, j ); /* Q0 */ move16(); /* safety check in case of bit errors */ test(); IF( *pYnrm < 0 || GT_16( *pYnrm, 39 ) ) { - *pYnrm = 39; + *pYnrm = 39; /* Q0 */ move16(); - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } - *pNormqlg2++ = dicnlg2[*pYnrm]; + *pNormqlg2++ = dicnlg2[*pYnrm]; /* Q0 */ move16(); } } diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 93b94a5c862c5c25cab3c07590bc22b12af336d4..55600612177614003924f7d80aeea8f0c889242c 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -18,10 +18,10 @@ #ifdef IVAS_FLOAT_FIXED void ivas_hq_pred_hb_bws_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ + const Word16 *ynrm, /* i : norm quantization index vector Q0*/ + const Word16 length, /* i : frame length Q0*/ + const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ) { Word16 i; @@ -41,7 +41,7 @@ void ivas_hq_pred_hb_bws_fx( { L_tmp = L_add( L_tmp, dicn_fx[ynrm[i]] ); /*Q14*/ } - L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); + L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); /* Q1 */ st_fx->prev_ener_shb_fx = extract_l( L_tmp ); /*Q1*/ st_fx->prev_ener_shb_fx = mult( st_fx->prev_ener_shb_fx, 5461 ); /*Q1*/ move16(); @@ -71,11 +71,11 @@ void ivas_hq_pred_hb_bws_fx( } void hq_pred_hb_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *ynrm, /* i : norm quantization index vector Q0*/ + const Word16 length, /* i : frame length Q0*/ + const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ) { Word16 i; @@ -99,7 +99,7 @@ void hq_pred_hb_bws_fx( L_tmp = L_add( L_tmp, dicn_fx[ynrm[i]] ); /*Q14*/ #endif } - L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); + L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); /* Q1 */ st_fx->prev_ener_shb_fx = extract_l( L_tmp ); /*Q1*/ st_fx->prev_ener_shb_fx = mult( st_fx->prev_ener_shb_fx, 5461 ); /*Q1*/ move16(); @@ -153,7 +153,7 @@ void ivas_hq_hr_dec_fx( Word16 *is_transient, /* o : transient flag Q0 */ Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag */ + const Word16 core_switching_flag /* i : Core switching flag Q0 */ ) { Word16 nb_sfm; @@ -211,8 +211,8 @@ void ivas_hq_hr_dec_fx( * Decode classification *------------------------------------------------------------------*/ - bits = ivas_hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); - bits_left = sub( num_bits, bits ); + bits = ivas_hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); /* Q0 */ + bits_left = sub( num_bits, bits ); /* Q0 */ /*------------------------------------------------------------------* * set quantization parameters @@ -231,15 +231,15 @@ void ivas_hq_hr_dec_fx( test(); IF( !*is_transient && NE_16( *hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && LE_32( st_fx->core_brate, HQ_32k ) ) ) { - nf_idx = get_next_indice_fx( st_fx, 2 ); + nf_idx = get_next_indice_fx( st_fx, 2 ); /* Q0 */ } /*------------------------------------------------------------------* * Decode envelope *------------------------------------------------------------------*/ - hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); - bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); + hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); /* Q0 */ + bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); /* Q0 */ dequantize_norms_fx( st_fx, start_norm, num_env_bands, *is_transient, ynrm, normqlg2 ); @@ -249,7 +249,7 @@ void ivas_hq_hr_dec_fx( hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure */ IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_SP_EXC ) ) { - bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class */ + bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class Q0*/ } map_hq_generic_fenv_norm_fx( *hqswb_clas, SWB_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); } @@ -257,8 +257,8 @@ void ivas_hq_hr_dec_fx( env_stab = 0; move16(); - csw_flag1 = s_and( core_switching_flag, (Word16) NE_16( st_fx->element_mode, EVS_MONO ) ); - csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); + csw_flag1 = s_and( core_switching_flag, (Word16) ( st_fx->element_mode != EVS_MONO ) ); /* Q0 */ + csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); /* Q0 */ test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) ) { @@ -267,7 +267,7 @@ void ivas_hq_hr_dec_fx( } ELSE IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); + env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); /* Q15 */ } ELSE { @@ -286,16 +286,16 @@ void ivas_hq_hr_dec_fx( { IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - move16(); /* calculated stability */ - hHQ_core->env_stab_fx = env_stab; + move16(); /* calculated stability */ + hHQ_core->env_stab_fx = env_stab; /* Q15 */ } ELSE { - hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); + hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); /* Q15 */ move16(); } } - hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); + hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767 /* 1.0f in Q15 */, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); /* Q0 */ move16(); /*------------------------------------------------------------------* @@ -309,20 +309,20 @@ void ivas_hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) && st_fx->bws_cnt1 > 0 && LT_32( st_fx->core_brate, HQ_32k ) ) { - tmp = i_mult( st_fx->bws_cnt1, 1638 ); + tmp = i_mult( st_fx->bws_cnt1, 1638 /* 1/20 in Q15 */ ); move16(); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { FOR( n_band = 0; n_band < 4; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ move16(); } } FOR( n_band = 4; n_band < SWB_FENV; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ move16(); } } @@ -330,8 +330,8 @@ void ivas_hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) || EQ_16( *hqswb_clas, HQ_GEN_FB ) ) { - b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); - sum = sub( sum, b_delta_env ); + b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); /* Q0 */ + sum = sub( sum, b_delta_env ); /* Q0 */ } /*------------------------------------------------------------------* @@ -350,10 +350,10 @@ void ivas_hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) || EQ_16( *hqswb_clas, HQ_HARMONIC ) ) { - subband_search_offset = subband_search_offsets_13p2kbps_Har; - wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; + subband_search_offset = subband_search_offsets_13p2kbps_Har; /* Q0 */ + wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; /* Q0 */ move16(); - wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; + wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; /* Q0 */ move16(); IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) ) @@ -407,7 +407,7 @@ void ivas_hq_hr_dec_fx( ivas_hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); /* update */ - hHQ_core->prev_hqswb_clas = *hqswb_clas; + hHQ_core->prev_hqswb_clas = *hqswb_clas; /* Q0 */ move16(); return; @@ -422,7 +422,7 @@ void hq_hr_dec_fx( Word16 *is_transient, /* o : transient flag Q0 */ Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag */ + const Word16 core_switching_flag /* i : Core switching flag Q0 */ ) { Word16 nb_sfm; @@ -500,25 +500,25 @@ void hq_hr_dec_fx( test(); IF( !*is_transient && NE_16( *hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && LE_32( st_fx->core_brate, HQ_32k ) ) ) { - nf_idx = get_next_indice( st_fx, 2 ); + nf_idx = get_next_indice( st_fx, 2 ); /* Q0 */ } /*------------------------------------------------------------------* * Decode envelope *------------------------------------------------------------------*/ - hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); - bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); + hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); /* Q0 */ + bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); /* Q0 */ dequantize_norms_fx( st_fx, start_norm, num_env_bands, *is_transient, ynrm, normqlg2 ); test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) || EQ_16( *hqswb_clas, HQ_GEN_FB ) ) { - hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure */ + hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure Q0*/ if ( EQ_16( hq_generic_exc_clas, HQ_GENERIC_SP_EXC ) ) { - bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class */ + bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class Q0*/ } map_hq_generic_fenv_norm_fx( *hqswb_clas, SWB_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); } @@ -526,8 +526,8 @@ void hq_hr_dec_fx( env_stab = 0; move16(); - csw_flag1 = s_and( core_switching_flag, (Word16) ( st_fx->element_mode != EVS_MONO ) ); - csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); + csw_flag1 = s_and( core_switching_flag, (Word16) ( st_fx->element_mode != EVS_MONO ) ); /* Q0 */ + csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); /* Q0 */ test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) ) { @@ -536,7 +536,7 @@ void hq_hr_dec_fx( } ELSE IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); + env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); /* Q0 */ } ELSE { @@ -556,16 +556,16 @@ void hq_hr_dec_fx( test(); IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - move16(); /* calculated stability */ - hHQ_core->env_stab_fx = env_stab; + move16(); /* calculated stability */ + hHQ_core->env_stab_fx = env_stab; /* Q15 */ } ELSE { - hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); + hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); /* Q15 */ move16(); } } - hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); + hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); /* Q0 */ /*------------------------------------------------------------------* * Bit allocation @@ -578,20 +578,20 @@ void hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) && st_fx->bws_cnt1 > 0 && LT_32( st_fx->core_brate, HQ_32k ) ) { - tmp = i_mult( st_fx->bws_cnt1, 1638 ); + tmp = i_mult( st_fx->bws_cnt1, 1638 /* 1/20 in Q15 */ ); /* Q15 */ move16(); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { FOR( n_band = 0; n_band < 4; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ move16(); } } FOR( n_band = 4; n_band < SWB_FENV; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ move16(); } } @@ -599,8 +599,8 @@ void hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) || EQ_16( *hqswb_clas, HQ_GEN_FB ) ) { - b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); - sum = sub( sum, b_delta_env ); + b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); /* Q0 */ + sum = sub( sum, b_delta_env ); /* Q0 */ } /*------------------------------------------------------------------* @@ -619,10 +619,10 @@ void hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) || EQ_16( *hqswb_clas, HQ_HARMONIC ) ) { - subband_search_offset = subband_search_offsets_13p2kbps_Har; - wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; + subband_search_offset = subband_search_offsets_13p2kbps_Har; /* Q0 */ + wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; /* Q0 */ move16(); - wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; + wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; /* Q0 */ move16(); IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) ) @@ -676,7 +676,7 @@ void hq_hr_dec_fx( hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); /* update */ - hHQ_core->prev_hqswb_clas = *hqswb_clas; + hHQ_core->prev_hqswb_clas = *hqswb_clas; /* Q0 */ move16(); return; diff --git a/lib_dec/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index 887f37d5c93780f7bd18fbdcfd165ffdc5d33160..c51a2fde52c348fdbfd3eda22b214c1ee7e1bb39 100644 --- a/lib_dec/hq_lr_dec_fx.c +++ b/lib_dec/hq_lr_dec_fx.c @@ -36,7 +36,7 @@ static Word16 Calc_inv( Word32 L_tmp, Word16 *exp ) } ELSE { - tmp = 0x7fff; + tmp = 0x7fff; /* 1 in Q15 */ move16(); *exp = 0; move16(); @@ -51,16 +51,16 @@ static Word16 Calc_inv( Word32 L_tmp, Word16 *exp ) *--------------------------------------------------------------------------*/ static void spt_shorten_domain_set_dec_fx( - Decoder_State *st_fx, /* i: encoder state structure */ - const Word16 p2a_flags[], /* i: p2a anlysis information */ - const Word16 new_band_start[], /* i: new band start position */ - const Word16 new_band_end[], /* i: new band end position */ - const Word16 new_band_width[], /* i: new subband band width */ - const Word16 bands, /* i: total number of subbands */ - Word16 band_start[], /* o: band start position */ - Word16 band_end[], /* o: band end position */ - Word16 band_width[], /* o: sub band band width */ - Word16 *bit_budget /* i/o: bit budget */ + Decoder_State *st_fx, /* i: encoder state structure */ + const Word16 p2a_flags[], /* i: p2a anlysis information Q0*/ + const Word16 new_band_start[], /* i: new band start position Q0*/ + const Word16 new_band_end[], /* i: new band end position Q0*/ + const Word16 new_band_width[], /* i: new subband band width Q0*/ + const Word16 bands, /* i: total number of subbands Q0*/ + Word16 band_start[], /* o: band start position Q0*/ + Word16 band_end[], /* o: band end position Q0*/ + Word16 band_width[], /* o: sub band band width Q0*/ + Word16 *bit_budget /* i/o: bit budget Q0*/ ) { Word16 j, k; @@ -68,27 +68,28 @@ static void spt_shorten_domain_set_dec_fx( j = 0; move16(); - FOR( k = sub( bands, SPT_SHORTEN_SBNUM ); k < bands; k++ ) + FOR( k = bands - SPT_SHORTEN_SBNUM; k < bands; k++ ) { spt_shorten_flag[j] = 0; move16(); IF( EQ_16( p2a_flags[k], 1 ) ) { - spt_shorten_flag[j] = get_next_indice_fx( st_fx, 1 ); - *bit_budget = sub( *bit_budget, 1 ); + spt_shorten_flag[j] = get_next_indice_fx( st_fx, 1 ); /* Q0 */ + move16(); + *bit_budget = sub( *bit_budget, 1 ); /* Q0 */ move16(); IF( EQ_16( spt_shorten_flag[j], 1 ) ) { - band_start[k] = new_band_start[j]; + band_start[k] = new_band_start[j]; /* Q0 */ move16(); - band_end[k] = new_band_end[j]; + band_end[k] = new_band_end[j]; /* Q0 */ move16(); - band_width[k] = new_band_width[j]; + band_width[k] = new_band_width[j]; /* Q0 */ move16(); } } - j = add( j, 1 ); + j++; } return; @@ -131,12 +132,12 @@ void hq_lr_dec_fx( Word32 L_qint; /*Word16 Qqint=29;*/ - Word16 eref_fx /*, Qeref=10*/; - Word16 bit_alloc_weight_fx /*, Qbaw=13*/; - Word16 ld_slope_fx /*, Qldslope=15*/; - Word16 p2a_th_fx /*, Qp2ath=11*/; - Word16 pd_thresh_fx /*, Qpdth=15*/; - Word16 ni_coef_fx /*, Qnicoef=14*/; + Word16 eref_fx /* Qeref=10 */; + Word16 bit_alloc_weight_fx /* Qbaw=13 */; + Word16 ld_slope_fx /* Qldslope=15 */; + Word16 p2a_th_fx /* Qp2ath=11 */; + Word16 pd_thresh_fx /* Qpdth=15 */; + Word16 ni_coef_fx /* Qnicoef=14 */; Word32 L_Rk[BANDS_MAX]; Word16 bit_budget_fx; @@ -203,32 +204,32 @@ void hq_lr_dec_fx( test(); IF( EQ_16( st_fx->bwidth, SWB ) && ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) ) { - hqswb_clas_fx = get_next_indice_fx( st_fx, 2 ); - num_bits = sub( num_bits, 2 ); + hqswb_clas_fx = get_next_indice_fx( st_fx, 2 ); /* Q0 */ + num_bits = sub( num_bits, 2 ); /* Q0 */ *is_transient_fx = 0; move16(); if ( EQ_16( hqswb_clas_fx, HQ_TRANSIENT ) ) { - *is_transient_fx = 1; + *is_transient_fx = 1; /* Q0 */ move16(); } } ELSE { /* decode transient flag */ - *is_transient_fx = get_next_indice_fx( st_fx, 1 ); + *is_transient_fx = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); - num_bits = sub( num_bits, 1 ); + num_bits = sub( num_bits, 1 ); /* Q0 */ } /* Configure decoder for different bandwidths, bit rates, etc. */ hq2_core_configure_fx( inner_frame, num_bits, *is_transient_fx, &bands_fx, &length_fx, band_width, band_start, band_end, &L_qint, &eref_fx, &bit_alloc_weight_fx, &gqlevs_fx, &Ngq_fx, &p2a_bands_fx, &p2a_th_fx, &pd_thresh_fx, &ld_slope_fx, &ni_coef_fx, L_bwe_br ); - highlength_fx = band_end[bands_fx - 1]; + highlength_fx = band_end[bands_fx - 1]; /* Q0 */ move16(); - har_bands_fx = bands_fx; + har_bands_fx = bands_fx; /* Q0 */ move16(); test(); @@ -240,11 +241,11 @@ void hq_lr_dec_fx( test(); IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) || EQ_16( hqswb_clas_fx, HQ_HARMONIC ) ) { - num_bits = sub( num_bits, get_usebit_npswb_fx( hqswb_clas_fx ) ); + num_bits = sub( num_bits, get_usebit_npswb_fx( hqswb_clas_fx ) ); /* Q0 */ } if ( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { - flag_spt_fx = 1; + flag_spt_fx = 1; /* Q0 */ move16(); } } @@ -257,26 +258,26 @@ void hq_lr_dec_fx( { j = 0; move16(); - FOR( k = sub( bands_fx, SPT_SHORTEN_SBNUM ); k < bands_fx; k++ ) + FOR( k = bands_fx - SPT_SHORTEN_SBNUM; k < bands_fx; k++ ) { hHQ_core->prev_SWB_peak_pos_fx[j] = 0; move16(); - j = add( j, 1 ); + j++; } } } /* Spectral energy calculation/quantization */ - ebits_fx = band_energy_dequant_fx( st_fx, L_band_energy, bands_fx, L_qint, eref_fx, *is_transient_fx ); + ebits_fx = band_energy_dequant_fx( st_fx, L_band_energy, bands_fx, L_qint, eref_fx, *is_transient_fx ); /* Q0 */ /* simple check: band_energy is too large, Abnormal Situation of bit errors */ FOR( k = 0; k < bands_fx; k++ ) { /* Max: 45.0(737279,Q14) at 32kHz, highest band, Min: -6.600037(-108135,Q14) at 8kHz(NB),8kbps, is_transient (-6.7f(-109772,Q14) is safty-threshold) */ test(); - IF( GT_32( L_band_energy[k], 737279L ) || LT_32( L_band_energy[k], -109772L ) ) + IF( GT_32( L_band_energy[k], 737279L /* 45.0 in Q14 */ ) || LT_32( L_band_energy[k], -109772L /* -6.7 in Q14 */ ) ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); set32_fx( L_yout, 0x0L, inner_frame ); return; @@ -285,9 +286,9 @@ void hq_lr_dec_fx( /* First pass bit budget for TCQ of spectral band information */ exp_norm = norm_s( gqlevs_fx ); - gqbits_fx = sub( 14, exp_norm ); + gqbits_fx = sub( 14, exp_norm ); /* Q0 */ - bit_budget_fx = sub( sub( num_bits, ebits_fx ), round_fx( L_shl( L_mult( Ngq_fx, gqbits_fx ), 15 ) ) ); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; */ + bit_budget_fx = sub( sub( num_bits, ebits_fx ), round_fx( L_shl( L_mult( Ngq_fx, gqbits_fx ), 15 ) ) ); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; Q0*/ pbits_fx = 0; @@ -302,8 +303,8 @@ void hq_lr_dec_fx( } ELSE { - pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); - bit_budget_fx = sub( bit_budget_fx, pbits_fx ); + pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); /* Q0 */ + bit_budget_fx = sub( bit_budget_fx, pbits_fx ); /* Q0 */ IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { @@ -313,8 +314,8 @@ void hq_lr_dec_fx( } ELSE { - pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); - bit_budget_fx = sub( bit_budget_fx, pbits_fx ); + pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); /* Q0 */ + bit_budget_fx = sub( bit_budget_fx, pbits_fx ); /* Q0 */ } IF( EQ_16( flag_spt_fx, 1 ) ) @@ -328,7 +329,7 @@ void hq_lr_dec_fx( /* safety check in case of bit errors */ IF( LT_16( bit_budget_fx, 2 ) ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); set32_fx( L_yout, 0x0, inner_frame ); return; @@ -347,13 +348,13 @@ void hq_lr_dec_fx( Ep_fx[i] = L_shl_sat( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ move32(); #else - Ep_fx[i] = L_shl( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ + Ep_fx[i] = L_shl( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ #endif } FOR( i = 0; i < bands_fx; i++ ) { - L_tmp2 = Ep_fx[i]; + L_tmp2 = Ep_fx[i]; /* Q -6 */ move32(); L_tmp = L_max( 1, L_tmp2 ); exp = norm_l( L_tmp ); @@ -375,7 +376,7 @@ void hq_lr_dec_fx( { exp2 = add( exp2, 1 ); } - tmp = div_s( tmp2, tmp ); + tmp = div_s( tmp2, tmp ); /* Q15 */ L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &exp2 ); /*Q(31-exp2) */ Ep_tmp_fx[i] = L_shr( L_tmp, sub( 15, exp2 ) ); /*Q13 */ @@ -395,20 +396,20 @@ void hq_lr_dec_fx( move16(); FOR( i = 0; i < 2; i++ ) { - last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); + last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); } - lowband = 6; + lowband = 6; /* Q0 */ move16(); - trans_bit_fx = 2; + trans_bit_fx = 2; /* Q0 */ move16(); - bit_budget_fx = sub( bit_budget_fx, trans_bit_fx ); + bit_budget_fx = sub( bit_budget_fx, trans_bit_fx ); /* Q0 */ gama_fx = 27852; move16(); /*Q15 0.85f; */ beta_fx = 17203; move16(); /*Q14 1.05f; */ - set16_fx( &p2a_flags_tmp[sub( bands_fx, trans_bit_fx )], 0, 2 ); + set16_fx( &p2a_flags_tmp[bands_fx - trans_bit_fx], 0, 2 ); IF( EQ_32( st_fx->core_brate, ACELP_13k20 ) ) { @@ -416,7 +417,7 @@ void hq_lr_dec_fx( move16(); /*14 1.25f; */ gama_fx = 31130; move16(); /*0.95f; */ - Copy( &p2a_flags_fx[sub( bands_fx, trans_bit_fx )], &p2a_flags_tmp[sub( bands_fx, trans_bit_fx )], trans_bit_fx ); + Copy( &p2a_flags_fx[bands_fx - trans_bit_fx], &p2a_flags_tmp[bands_fx - trans_bit_fx], trans_bit_fx ); } /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ @@ -429,11 +430,11 @@ void hq_lr_dec_fx( IF( GE_16( i, lowband ) ) { #ifdef BASOP_NOGLOB - Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub_sat( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ + Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub_sat( Ep_tmp_fx[i], Ep_tmp_fx[i - 1] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ + Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[i - 1] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif } ELSE @@ -441,7 +442,7 @@ void hq_lr_dec_fx( #ifdef BASOP_NOGLOB Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ + Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif if ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { @@ -479,7 +480,7 @@ void hq_lr_dec_fx( } ELSE { - FOR( i = sub( bands_fx, trans_bit_fx ); i < bands_fx; i++ ) + FOR( i = bands_fx - trans_bit_fx; i < bands_fx; i++ ) { alpha_fx = 16384; move16(); /*Q14 */ @@ -554,7 +555,7 @@ void hq_lr_dec_fx( move32(); } } - lowband = 3; + lowband = 3; /* Q0 */ move16(); Ep_avrg_fx = L_deposit_l( 0 ); Ep_avrgL_fx = L_deposit_l( 0 ); @@ -605,17 +606,17 @@ void hq_lr_dec_fx( } ELSE IF( *is_transient_fx == 0 && EQ_16( inner_frame, L_FRAME16k ) ) { - bit_budget_fx = sub( bit_budget_fx, 2 ); /* bits in high bands to indicate the last 2 subbands is allocated bits or not */ + bit_budget_fx = sub( bit_budget_fx, 2 ); /* bits in high bands to indicate the last 2 subbands is allocated bits or not Q0*/ FOR( i = 0; i < 2; i++ ) { - last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); + last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); } FOR( i = 0; i < bands_fx; i++ ) { #ifdef BASOP_NOGLOB - Ep_tmp_fx[i] = L_shl_sat( Ep_tmp_fx[i], 2 ); + Ep_tmp_fx[i] = L_shl_sat( Ep_tmp_fx[i], 2 ); /* Q15 */ #else Ep_tmp_fx[i] = L_shl( Ep_tmp_fx[i], 2 ); #endif @@ -623,21 +624,21 @@ void hq_lr_dec_fx( } IF( EQ_32( st_fx->core_brate, ACELP_13k20 ) ) { - lowband = 8; + lowband = 8; /* Q0 */ move16(); - highband = 15; + highband = 15; /* Q0 */ move16(); - bw_low = sub( band_start[highband], band_start[lowband] ); - bw_high = sub( add( band_end[sub( bands_fx, 1 )], 1 ), band_start[highband] ); + bw_low = sub( band_start[highband], band_start[lowband] ); /* Q0 */ + bw_high = sub( add( band_end[bands_fx - 1], 1 ), band_start[highband] ); /* Q0 */ } ELSE { - lowband = 8; + lowband = 8; /* Q0 */ move16(); - highband = 16; + highband = 16; /* Q0 */ move16(); - bw_low = sub( band_start[highband], band_start[lowband] ); - bw_high = sub( add( band_end[sub( bands_fx, 1 )], 1 ), band_start[highband] ); + bw_low = sub( band_start[highband], band_start[lowband] ); /* Q0 */ + bw_high = sub( add( band_end[bands_fx - 1], 1 ), band_start[highband] ); /* Q0 */ } /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ enerL_fx = L_deposit_l( 0 ); @@ -650,11 +651,11 @@ void hq_lr_dec_fx( IF( GE_16( i, lowband ) && add( sub( i, bands_fx ), p2a_bands_fx ) < 0 ) { #ifdef BASOP_NOGLOB - Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ + Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[i - 1] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ + Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[i - 1] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif } @@ -663,7 +664,7 @@ void hq_lr_dec_fx( #ifdef BASOP_NOGLOB enerH_fx = L_add_sat( enerH_fx, L_shl_sat( Ep_fx[i], 2 ) ); /*Q0 */ #else - enerH_fx = L_add( enerH_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ + enerH_fx = L_add( enerH_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ #endif } ELSE IF( GE_16( i, lowband ) ) @@ -671,7 +672,7 @@ void hq_lr_dec_fx( #ifdef BASOP_NOGLOB enerL_fx = L_add_sat( enerL_fx, L_shl_sat( Ep_fx[i], 2 ) ); /*Q0 */ #else - enerL_fx = L_add( enerL_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ + enerL_fx = L_add( enerL_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ #endif } } @@ -685,7 +686,7 @@ void hq_lr_dec_fx( L_tmp = Mult_32_16( L_shl( enerH_fx, i ), shl( bw_low, j ) ); /* i + j -15 */ L_tmp2 = Mult_32_16( L_shl( enerL_fx, i ), shl( bw_high, j ) ); /*i + j -15 */ L_tmp2 = L_sub( L_tmp, L_tmp2 ); - FOR( i = sub( bands_fx, p2a_bands_fx ); i < bands_fx; i++ ) + FOR( i = bands_fx - p2a_bands_fx; i < bands_fx; i++ ) { test(); IF( EQ_16( p2a_flags_fx[i], 1 ) || L_tmp2 > 0 ) @@ -696,7 +697,7 @@ void hq_lr_dec_fx( #ifdef BASOP_NOGLOB tmp1 = extract_h( L_shl_sat( Ep_avrg_fx, 1 ) ); /*Q0 */ #else - tmp1 = extract_h( L_shl( Ep_avrg_fx, 1 ) ); /*Q0 */ + tmp1 = extract_h( L_shl( Ep_avrg_fx, 1 ) ); /*Q0 */ #endif IF( tmp1 != 0 ) { @@ -734,7 +735,7 @@ void hq_lr_dec_fx( IF( add( sub( i, bands_fx ), p2a_bands_fx ) > 0 ) { tmp = sub( bands_fx, p2a_bands_fx ); - IF( EQ_16( last_bitalloc_max_band[sub( i, add( tmp, 1 ) )], 1 ) ) + IF( EQ_16( last_bitalloc_max_band[i - ( tmp + 1 )], 1 ) ) { tmp = sub( tmp, lowband ); L_tmp = Mult_32_16( Ep_tmp_fx[i], tmp ); /*Q(15+0-15 = 0) */ @@ -887,11 +888,11 @@ void hq_lr_dec_fx( spt_shorten_domain_band_restore_fx( bands_fx, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width ); } - Copy32( L_y2, L_y2_org, L_FRAME32k ); + Copy32( L_y2, L_y2_org, L_FRAME32k ); /* Q12 */ /* Inject noise into components having relatively low pulse energy per band */ ni_seed_fx = add( add( add( npulses_fx[0], npulses_fx[1] ), npulses_fx[2] ), npulses_fx[3] ); - Copy32( L_y2, L_y2_ni, band_end[bands_fx - 1] + 1 ); + Copy32( L_y2, L_y2_ni, band_end[bands_fx - 1] + 1 ); /* Q12 */ hq2_noise_inject_fx( L_y2_ni, band_start, band_end, band_width, Ep_fx, L_Rk, npulses_fx, ni_seed_fx, bands_fx, 0, bw_low, bw_high, enerL_fx, enerH_fx, hHQ_core->last_ni_gain_fx, hHQ_core->last_env_fx, &hHQ_core->last_max_pos_pulse, p2a_flags_fx, p2a_bands_fx, @@ -924,16 +925,16 @@ void hq_lr_dec_fx( } } } - Copy32( L_y2_ni, L_y2, lowlength_fx ); + Copy32( L_y2_ni, L_y2, lowlength_fx ); /* Q12 */ } ELSE { - Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* HQ_TRANSIENT */ + Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* HQ_TRANSIENT Q12*/ } } ELSE { - Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* NB, WB */ + Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* NB, WB Q12*/ } test(); @@ -942,7 +943,7 @@ void hq_lr_dec_fx( k1_fx = sub( bands_fx, 2 ); if ( NE_16( *is_transient_fx, 1 ) ) { - k1_fx = sub( bands_fx, 6 ); + k1_fx = sub( bands_fx, 6 ); /* Q1 */ } L_tmp = L_deposit_l( 0 ); FOR( i = k1_fx; i < bands_fx; i++ ) @@ -950,7 +951,7 @@ void hq_lr_dec_fx( tmp = div_s( 1, sub( bands_fx, k1_fx ) ); /*Q15 */ L_tmp = L_add( L_tmp, Mult_32_16( Ep_tmp_fx[i], tmp ) ); /*Q15 */ } - st_fx->prev_ener_shb_fx = extract_l( L_shr( L_tmp, 14 ) ); + st_fx->prev_ener_shb_fx = extract_l( L_shr( L_tmp, 14 ) ); /* Q1 */ move16(); } test(); @@ -972,26 +973,26 @@ void hq_lr_dec_fx( *--------------------------------------------------------------------------------------*/ static Word16 small_symbol_dec_tran_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *qbidx, /* o : output of dequantized differential energy */ - const Word16 bands, /* i : number of bands */ - const Word16 is_transient /* i : transient flag */ + Decoder_State *st_fx, /* i/o: decoder state structure Q0*/ + Word16 *qbidx, /* o : output of dequantized differential energy Q0*/ + const Word16 bands, /* i : number of bands Q0*/ + const Word16 is_transient /* i : transient flag Q0*/ ) { Word16 i, bits; Word16 difidx[BANDS_MAX]; /* Decoding differential energies*/ - bits = decode_envelope_indices_fx( st_fx, 0, bands, 0, difidx, LOW_RATE_HQ_CORE_TRAN, is_transient ); - bits = add( bits, BITS_DE_FCOMP ); + bits = decode_envelope_indices_fx( st_fx, 0, bands, 0, difidx, LOW_RATE_HQ_CORE_TRAN, is_transient ); /* Q0 */ + bits = add( bits, BITS_DE_FCOMP ); /* Q0 */ /* counting 1 bit for band_energy_huff_coding_mode */ - bits = add( bits, BITS_DE_HMODE ); + bits = add( bits, BITS_DE_HMODE ); /* Q0 */ /* converting to original values */ FOR( i = 0; i < bands; i++ ) { - qbidx[i] = sub( difidx[i], LRMDCT_BE_OFFSET ); + qbidx[i] = sub( difidx[i], LRMDCT_BE_OFFSET ); /* Q0 */ move16(); } @@ -1005,41 +1006,41 @@ static Word16 small_symbol_dec_tran_fx( * Huffman decoding of differential energies (MSB and LSB) *--------------------------------------------------------------------------*/ -static Word16 small_symbol_dec_fx( /* o : bits */ +static Word16 small_symbol_dec_fx( /* o : bits Q0*/ Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *qbidx, /* o : output of dequantized differential energy */ - const Word16 bands, /* i : number of bands */ + Word16 *qbidx, /* o : output of dequantized differential energy Q0*/ + const Word16 bands, /* i : number of bands Q0*/ const Word16 is_transient ) { Word16 i, LSB, bits; Word16 difidx[BANDS_MAX]; /* Decoding MSB bits */ - bits = decode_envelope_indices_fx( st_fx, 0, bands, 0, difidx, LOW_RATE_HQ_CORE, is_transient ); - bits = add( bits, BITS_DE_FCOMP ); + bits = decode_envelope_indices_fx( st_fx, 0, bands, 0, difidx, LOW_RATE_HQ_CORE, is_transient ); /* Q0 */ + bits = add( bits, BITS_DE_FCOMP ); /* Q0 */ /* counting 1 bit for band_energy_huff_coding_mode */ - bits = add( bits, BITS_DE_HMODE ); + bits = add( bits, BITS_DE_HMODE ); /* Q0 */ /* Decoding LSB bit packing */ FOR( i = 0; i < bands; ++i ) { - LSB = get_next_indice_fx( st_fx, BITS_DE_LSB ); - difidx[i] = s_or( shl( difidx[i], 1 ), LSB ); + LSB = get_next_indice_fx( st_fx, BITS_DE_LSB ); /* Q0 */ + difidx[i] = s_or( shl( difidx[i], 1 ), LSB ); /* Q0 */ move16(); } /* counting bits for LSB */ - bits = add( bits, bands ); + bits = add( bits, bands ); /* Q0 */ /* converting to original values */ FOR( i = 1; i < bands; ++i ) { - qbidx[i] = sub( difidx[i], DE_OFFSET1 ); + qbidx[i] = sub( difidx[i], DE_OFFSET1 ); /* Q0 */ move16(); } - qbidx[0] = sub( difidx[0], DE_OFFSET0 ); + qbidx[0] = sub( difidx[0], DE_OFFSET0 ); /* Q0 */ move16(); return ( bits ); @@ -1048,18 +1049,19 @@ static Word16 small_symbol_dec_fx( /* o : bits static Word16 decode_huff_8s_fx( Decoder_State *st_fx, - const Word16 *hufftab, - Word16 *rbits ) + const Word16 *hufftab, /* Q0 */ + Word16 *rbits /* Q0 */ +) { Word16 bit; WHILE( *hufftab > 0 ) { - *rbits = add( *rbits, s_and( *hufftab, 0xf ) ); + *rbits = add( *rbits, s_and( *hufftab, 0xf ) ); /* Q0 */ move16(); - bit = get_next_indice_fx( st_fx, s_and( *hufftab, 0xf ) ); + bit = get_next_indice_fx( st_fx, s_and( *hufftab, 0xf ) ); /* Q0 */ move16(); - hufftab += add( shr( *hufftab, 4 ), bit ); + hufftab += add( shr( *hufftab, 4 ), bit ); /* Q0 */ } return negate( *hufftab ); @@ -1067,8 +1069,8 @@ static Word16 decode_huff_8s_fx( static Word16 large_symbol_dec_fx( /* o : bits */ Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *qbidx, /* o : output of dequantized differential energy */ - const Word16 bands /* i : number of bands */ + Word16 *qbidx, /* o : output of dequantized differential energy Q0*/ + const Word16 bands /* i : number of bands Q0*/ ) { Word16 i, bits; @@ -1077,29 +1079,29 @@ static Word16 large_symbol_dec_fx( /* o : bits Word16 pos_outlyer; Word16 ns2mode0, ns2mode1; - cntbits = BITS_DE_8SMODE; + cntbits = BITS_DE_8SMODE; /* Q0 */ move16(); - ns2mode = get_next_indice_fx( st_fx, BITS_DE_8SMODE ); + ns2mode = get_next_indice_fx( st_fx, BITS_DE_8SMODE ); /* Q0 */ IF( ns2mode == 0 ) { - ns2mode0 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N0 ); - ns2mode1 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N1 ); - cntbits = add( cntbits, BITS_DE_8SMODE_N0 + BITS_DE_8SMODE_N1 ); + ns2mode0 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N0 ); /* Q0 */ + ns2mode1 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N1 ); /* Q0 */ + cntbits = add( cntbits, BITS_DE_8SMODE_N0 + BITS_DE_8SMODE_N1 ); /* Q0 */ IF( ns2mode0 == 0 ) { IF( EQ_16( ns2mode1, 1 ) ) { - pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); - cntbits = add( cntbits, BITS_DE_8SPOS ); - qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); /* Q0 */ + cntbits = add( cntbits, BITS_DE_8SPOS ); /* Q0 */ + qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); /* Q0 */ move16(); - cntbits = add( cntbits, BITS_ABS_ENG ); + cntbits = add( cntbits, BITS_ABS_ENG ); /* Q0 */ } ELSE { - pos_outlyer = -1; + pos_outlyer = -1; /* Q0 */ move16(); } @@ -1107,84 +1109,84 @@ static Word16 large_symbol_dec_fx( /* o : bits { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } - FOR( i = add( pos_outlyer, 1 ); i < bands; ++i ) + FOR( i = pos_outlyer + 1; i < bands; ++i ) { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } } ELSE { IF( EQ_16( ns2mode1, 1 ) ) { - pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); - cntbits = add( cntbits, BITS_DE_8SPOS ); - qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); /* Q0 */ + cntbits = add( cntbits, BITS_DE_8SPOS ); /* Q0 */ + qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); /* Q0 */ move16(); - cntbits = add( cntbits, BITS_ABS_ENG ); - qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + cntbits = add( cntbits, BITS_ABS_ENG ); /* Q0 */ + qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); /* Q0 */ move16(); - cntbits = add( cntbits, BITS_ABS_ENG ); + cntbits = add( cntbits, BITS_ABS_ENG ); /* Q0 */ } ELSE { pos_outlyer = 0; move16(); - qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); /* Q0 */ move16(); - cntbits = add( cntbits, BITS_ABS_ENG ); + cntbits = add( cntbits, BITS_ABS_ENG ); /* Q0 */ } FOR( i = 1; i < pos_outlyer; ++i ) { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } FOR( i = pos_outlyer + 1; i < bands; ++i ) { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } } } ELSE { - basic_shift = get_next_indice_fx( st_fx, BITS_MAX_DEPTH ); - cntbits = add( cntbits, BITS_MAX_DEPTH ); + basic_shift = get_next_indice_fx( st_fx, BITS_MAX_DEPTH ); /* Q0 */ + cntbits = add( cntbits, BITS_MAX_DEPTH ); /* Q0 */ FOR( i = 0; i < bands; ++i ) { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - qbidx[i] = shl( qbidx[i], basic_shift ); + qbidx[i] = shl( qbidx[i], basic_shift ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } FOR( i = 0; i < bands; ++i ) { - LSB[0] = get_next_indice_fx( st_fx, basic_shift ); + LSB[0] = get_next_indice_fx( st_fx, basic_shift ); /* Q0 */ move16(); - qbidx[i] = add( qbidx[i], LSB[0] ); + qbidx[i] = add( qbidx[i], LSB[0] ); /* Q0 */ move16(); - cntbits = add( cntbits, basic_shift ); + cntbits = add( cntbits, basic_shift ); /* Q0 */ } } @@ -1199,12 +1201,13 @@ static Word16 large_symbol_dec_fx( /* o : bits *--------------------------------------------------------------------------*/ static Word16 band_energy_dequant_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 L_band_energy[], /* o : Q14 band energy */ - const Word16 bands_fx, - const Word32 L_qint, - const Word16 eref_fx, - const Word16 is_transient_fx ) + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 L_band_energy[], /* o : band energy Q14*/ + const Word16 bands_fx, /* Q0 */ + const Word32 L_qint, /* Q0 */ + const Word16 eref_fx, /* Q0 */ + const Word16 is_transient_fx /* Q0 */ +) { Word16 k; Word16 deng_cmode; @@ -1221,28 +1224,28 @@ static Word16 band_energy_dequant_fx( /* parsing energy difference coding mode */ - deng_cmode = get_next_indice_fx( st_fx, BITS_DE_CMODE ); + deng_cmode = get_next_indice_fx( st_fx, BITS_DE_CMODE ); /* Q0 */ IF( deng_cmode == 0 ) { - deng_bits = large_symbol_dec_fx( st_fx, bq2_fx, bands_fx ); + deng_bits = large_symbol_dec_fx( st_fx, bq2_fx, bands_fx ); /* Q0 */ /* counting 1 bit for deng coding mode */ - deng_bits = add( deng_bits, BITS_DE_CMODE ); + deng_bits = add( deng_bits, BITS_DE_CMODE ); /* Q0 */ } ELSE { IF( is_transient_fx ) { - deng_bits = small_symbol_dec_tran_fx( st_fx, bq2_fx, bands_fx, is_transient_fx ); + deng_bits = small_symbol_dec_tran_fx( st_fx, bq2_fx, bands_fx, is_transient_fx ); /* Q0 */ } ELSE { - deng_bits = small_symbol_dec_fx( st_fx, bq2_fx, bands_fx, is_transient_fx ); + deng_bits = small_symbol_dec_fx( st_fx, bq2_fx, bands_fx, is_transient_fx ); /* Q0 */ } /* counting 1 bit for deng coding mode */ - deng_bits = add( deng_bits, BITS_DE_CMODE ); + deng_bits = add( deng_bits, BITS_DE_CMODE ); /* Q0 */ } exp_normd = norm_l( L_qint ); @@ -1281,10 +1284,10 @@ static Word16 band_energy_dequant_fx( *--------------------------------------------------------------------------*/ static Word16 p2a_threshold_dequant_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *p2a_flags, /* o : tonaly indicator */ - const Word16 bands, /* i : number of subbands */ - const Word16 p2a_bands /* i : number of subbnads for computing tonality */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *p2a_flags, /* o : tonaly indicator Q0*/ + const Word16 bands, /* i : number of subbands Q0*/ + const Word16 p2a_bands /* i : number of subbnads for computing tonality Q0*/ ) { Word16 j, k; @@ -1292,17 +1295,17 @@ static Word16 p2a_threshold_dequant_fx( j = sub( bands, p2a_bands ); FOR( k = 0; k < j; k++ ) { - p2a_flags[k] = 1; + p2a_flags[k] = 1; /* Q0 */ move16(); } j = 0; move16(); - FOR( k = sub( bands, p2a_bands ); k < bands; k++ ) + FOR( k = bands - p2a_bands; k < bands; k++ ) { - p2a_flags[k] = get_next_indice_fx( st_fx, 1 ); + p2a_flags[k] = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); - j = add( j, 1 ); + j++; } return ( j ); @@ -1348,11 +1351,11 @@ static void mdct_spectrum_fine_gain_dec_fx( exp_normn = norm_l( L_qint ); exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( gqlevs ); - delta_fx = div_l( L_shl( L_qint, exp_normn ), shl( gqlevs, exp_normd ) ); - Qdelta = add( sub( exp_normn, exp_normd ), 28 ); /* 29+exp_normn-(exp_normd)-1; */ - L_delta = L_shl( L_deposit_h( delta_fx ), sub( 13, Qdelta ) ); + delta_fx = div_l( L_shl( L_qint, exp_normn ), shl( gqlevs, exp_normd ) ); /* Q15 */ + Qdelta = add( sub( exp_normn, exp_normd ), 28 ); /* 29+exp_normn-(exp_normd)-1; */ + L_delta = L_shl( L_deposit_h( delta_fx ), sub( 13, Qdelta ) ); /* Q18 - Qdelta */ - L_q = L_shr( L_sub( L_delta, L_qint ), 1 ); + L_q = L_shr( L_sub( L_delta, L_qint ), 1 ); /* Q -1*/ FOR( i = 0; i < gqlevs; i++ ) { @@ -1369,9 +1372,9 @@ static void mdct_spectrum_fine_gain_dec_fx( move16(); } - FOR( k = sub( bands, Ngq ); k < bands; k++ ) + FOR( k = bands - Ngq; k < bands; k++ ) { - imin_fx = get_next_indice_fx( st_fx, gqbits ); + imin_fx = get_next_indice_fx( st_fx, gqbits ); /* Q0 */ /*gamma = gain_table[imin]; */ gamma_fx = gain_table_fx[imin_fx]; @@ -1382,12 +1385,12 @@ static void mdct_spectrum_fine_gain_dec_fx( /* This IF statement for keeping same mantissa evenif y2 is plus or minus */ IF( L_y2[i] >= 0x0 ) { - L_y2[i] = L_shl( Mpy_32_16_1( L_y2[i], gamma_fx ), 1 ); + L_y2[i] = L_shl( Mpy_32_16_1( L_y2[i], gamma_fx ), 1 ); /* Q12 */ move32(); } ELSE { - L_y2[i] = L_negate( L_shl( Mpy_32_16_1( L_abs( L_y2[i] ), gamma_fx ), 1 ) ); + L_y2[i] = L_negate( L_shl( Mpy_32_16_1( L_abs( L_y2[i] ), gamma_fx ), 1 ) ); /* Q12 */ move32(); } } diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index dc36524a2c6be726873967248306b805fda294df..463875a1c5cadcff4c4de119bbf8b225dfd842b0 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -38,45 +38,45 @@ static Word16 IGF_getScaleFactor32Cond( /**< ou Word32 tmp32; - x_max = 0; + x_max = 0; // Q31 move32(); - x_min = 0; + x_min = 0; // Q31 move32(); FOR( i = 0; i < len_x; i++ ) { - tmp32 = L_add( x[i], 0 ); /*L_and(x[i], cond[i]);*/ + tmp32 = L_add( x[i], 0 ); /*L_and(x[i], cond[i]);*/ // Q31 - if ( cond[i] == 0 ) + IF( cond[i] == 0 ) { - tmp32 = L_deposit_h( 0 ); + tmp32 = L_deposit_h( 0 ); // Q31 } - if ( tmp32 >= 0 ) + IF( tmp32 >= 0 ) { - x_max = L_max( x_max, tmp32 ); + x_max = L_max( x_max, tmp32 ); // Q31 } - if ( tmp32 < 0 ) + IF( tmp32 < 0 ) { - x_min = L_min( x_min, tmp32 ); + x_min = L_min( x_min, tmp32 ); // Q31 } } - i_max = 0x20; + i_max = 0x20; // Q0 move16(); - i_min = 0x20; + i_min = 0x20; // Q0 move16(); - if ( x_max != 0 ) + IF( x_max != 0 ) { - i_max = norm_l( x_max ); + i_max = norm_l( x_max ); // Q0 } - if ( x_min != 0 ) + IF( x_min != 0 ) { - i_min = norm_l( x_min ); + i_min = norm_l( x_min ); // Q0 } - i = s_and( s_min( i_max, i_min ), 0x1F ); + i = s_and( s_min( i_max, i_min ), 0x1F ); // Q0 return i; } @@ -87,7 +87,7 @@ measures TCX noise static Word16 IGF_replaceTCXNoise_1( /**< out: Q0 | number of noise bands */ const Word32 *in, /**< in: Q31 | MDCT spectrum */ Word16 s_l, /**< in: Q0 | noise headroom */ - const Word16 *TCXNoise, /**< in: | tcx noise indicator vector */ + const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ const Word16 start, /**< in: Q0 | start MDCT subband index */ const Word16 stop, /**< in: Q0 | stop MDCT subband index */ Word32 *totalNoiseNrg /**< out: | measured noise energy */ @@ -107,32 +107,30 @@ static Word16 IGF_replaceTCXNoise_1( /**< ou nE = 0; move32(); - FOR( sb = start; sb < stop; sb++ ) - { - IF( TCXNoise[sb] ) - { - tmp16 = extract_h( L_shl( in[sb], s_l ) ); - } - IF( TCXNoise[sb] ) - { - nE = L_mac( nE, tmp16, tmp16 ); - } - if ( TCXNoise[sb] ) - { - noise = add( noise, 1 ); - } - } + FOR( sb = start; sb < stop; sb++ ){ + IF( TCXNoise[sb] ){ + tmp16 = extract_h( L_shl( in[sb], s_l ) ); // Q31 + s_l +} +IF( TCXNoise[sb] ) +{ + nE = L_mac( nE, tmp16, tmp16 ); // Q31 + s_l +} +IF( TCXNoise[sb] ) +{ + noise = add( noise, 1 ); // Q0 +} +} - *totalNoiseNrg = nE; - move32(); +*totalNoiseNrg = nE; // Q31 + s_l +move32(); - return noise; +return noise; } static Word16 ivas_IGF_replaceTCXNoise_1_fx( /**< out: Q0 | number of noise bands */ const Word32 *in, /**< in: Q31 | MDCT spectrum */ Word16 s_l, /**< in: Q0 | noise headroom */ - const Word16 *TCXNoise, /**< in: | tcx noise indicator vector */ + const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ const Word16 start, /**< in: Q0 | start MDCT subband index */ const Word16 stop, /**< in: Q0 | stop MDCT subband index */ Word32 *totalNoiseNrg, /**< out: | measured noise energy */ @@ -156,15 +154,15 @@ static Word16 ivas_IGF_replaceTCXNoise_1_fx( /**< out: Q { IF( TCXNoise[sb] ) { - tmp16 = extract_h( L_shl( in[sb], s_l ) ); + tmp16 = extract_h( L_shl( in[sb], s_l ) ); // Q31 + s_l } IF( TCXNoise[sb] ) { - nE = W_mac_16_16( nE, tmp16, tmp16 ); + nE = W_mac_16_16( nE, tmp16, tmp16 ); // Q31 + s_l } - if ( TCXNoise[sb] ) + IF( TCXNoise[sb] ) { - noise = add( noise, 1 ); + noise = add( noise, 1 ); // Q0 } } @@ -181,7 +179,7 @@ static Word16 ivas_IGF_replaceTCXNoise_1_fx( /**< out: Q /**********************************************************************/ /* replaces TCX noise **************************************************************************/ -static void IGF_replaceTCXNoise_2( Word32 *in, /**< in/out: | MDCT spectrum */ +static void IGF_replaceTCXNoise_2( Word32 *in, /**< in/out: Q31 | MDCT spectrum */ const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ const Word16 start, /**< in: Q0 | start MDCT subband index */ const Word16 stop, /**< in: Q0 | stop MDCT subband index */ @@ -206,55 +204,55 @@ static void IGF_replaceTCXNoise_2( Word32 *in, /**< in { IF( TCXNoise[sb] ) { - val = Random( nfSeed ); + val = Random( nfSeed ); // Q0 } IF( TCXNoise[sb] ) { - in[sb] = L_deposit_l( val ); + in[sb] = L_deposit_l( val ); // Q0 move32(); } IF( TCXNoise[sb] ) { - val = shr( val, 5 ); + val = shr( val, 5 ); // Q-5 } IF( TCXNoise[sb] ) { - rE = L_mac( rE, val, val ); + rE = L_mac( rE, val, val ); // Q-9 } } - totalNoiseNrg = L_shr( totalNoiseNrg, 1 ); + totalNoiseNrg = L_shr( totalNoiseNrg, 1 ); // Q-9 /* make sure that rE is never 0 */ if ( rE == 0 ) { - rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ + rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ // Q-9 } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ if ( totalNoiseNrg == 0 ) { - rE = L_max( rE, 0x00010000 ); + rE = L_max( rE, 0x00010000 ); // Q-9 } /* make sure that rE is never smaller than totalNoiseNrg */ - L_tmp = L_sub( rE, totalNoiseNrg ); + L_tmp = L_sub( rE, totalNoiseNrg ); // Q-9 if ( L_tmp < 0 ) { - rE = totalNoiseNrg; /* save move32() -> use L_add(x, 0) = x; */ + rE = totalNoiseNrg; /* save move32() -> use L_add(x, 0) = x; */ // Q-9 move32(); } - g = getSqrtWord32( L_mult( divide3232( totalNoiseNrg, rE ), 8192 /*1.0f / 4.0f Q15*/ ) ); - g = shl( g, 1 ); + g = getSqrtWord32( L_mult( divide3232( totalNoiseNrg, rE ), 8192 /*1.0f / 4.0f Q15*/ ) ); // ((Q15 + Q15 + Q1) / 2) -> Q15 + g = shl( g, 1 ); // Q16 FOR( sb = start; sb < stop; sb++ ) { IF( TCXNoise[sb] ) { - in[sb] = L_shr( L_mult( extract_l( in[sb] ), g ), s_l ); + in[sb] = L_shr( L_mult( extract_l( in[sb] ), g ), s_l ); // Q15 + Q16 + Q1 - s_l move32(); } } @@ -293,12 +291,12 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in { IF( TCXNoise[sb] ) { - val = Random( nfSeed ); + val = Random( nfSeed ); // Q0 move16(); - in[sb] = L_deposit_l( val ); + in[sb] = L_deposit_l( val ); // Q0 move32(); - val = shr( val, 5 ); - rE = L_mac( rE, val, val ); + val = shr( val, 5 ); // Q-5 + rE = L_mac( rE, val, val ); // Q-9 n_noise_bands_tile = add( n_noise_bands_tile, 1 ); } } @@ -311,17 +309,17 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in /* make sure that rE is never 0 */ if ( rE == 0 ) { - rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ + rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ // Q31 - totalNoiseNrg_e } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ if ( totalNoiseNrg == 0 ) { - rE = L_max( rE, 0x00010000 ); + rE = L_max( rE, 0x00010000 ); // Q-9 } Word16 tmp, tmp_e; - L_tmp = Mpy_32_16_1( totalNoiseNrg, noise_band_ratio ); + L_tmp = Mpy_32_16_1( totalNoiseNrg, noise_band_ratio ); // Q31 - totalNoiseNrg_e tmp = BASOP_Util_Divide3232_Scale( L_tmp, rE, &tmp_e ); tmp_e = add( tmp_e, sub( totalNoiseNrg_e, 40 ) ); g = Sqrt16( tmp, &tmp_e ); @@ -349,13 +347,13 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in **************************************************************************/ static void IGF_replaceTCXNoise_2_new_ivas_with_var_shift( Word32 *in, /**< in/out: | MDCT spectrum */ Word16 *in_e_arr, /**< in/out: | MDCT spectrum exp */ - const Word16 *TCXNoise, /**< in: | tcx noise indicator vector */ - const Word16 start, /**< in: | start MDCT subband index */ - const Word16 stop, /**< in: | stop MDCT subband index */ + const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ + const Word16 start, /**< in: Q0 | start MDCT subband index */ + const Word16 stop, /**< in: Q0 | stop MDCT subband index */ Word32 totalNoiseNrg, /**< in: | measured noise energy */ Word16 totalNoiseNrg_e, /**< in: | measured noise energy exp */ - const Word16 n_noise_bands, /**< in: | number of noise bands in src */ - Word16 *nfSeed /**< in: | random generator noise seed */ + const Word16 n_noise_bands, /**< in: Q0 | number of noise bands in src */ + Word16 *nfSeed /**< in: Q0 | random generator noise seed */ ) { Word16 sb; @@ -377,14 +375,14 @@ static void IGF_replaceTCXNoise_2_new_ivas_with_var_shift( Word32 *in, { IF( TCXNoise[sb] ) { - val = Random( nfSeed ); + val = Random( nfSeed ); // Q0 move16(); - in[sb] = L_deposit_l( val ); + in[sb] = L_deposit_l( val ); // Q0 move32(); in_e_arr[sb] = 31; move16(); - val = shr( val, 5 ); - rE = L_mac( rE, val, val ); + val = shr( val, 5 ); // Q-5 + rE = L_mac( rE, val, val ); // Q-9 n_noise_bands_tile = add( n_noise_bands_tile, 1 ); } } @@ -397,17 +395,17 @@ static void IGF_replaceTCXNoise_2_new_ivas_with_var_shift( Word32 *in, /* make sure that rE is never 0 */ if ( rE == 0 ) { - rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ + rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ // Q31 - totalNoiseNrg_e } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ if ( totalNoiseNrg == 0 ) { - rE = L_max( rE, 0x00010000 ); + rE = L_max( rE, 0x00010000 ); // Q-9 } Word16 tmp, tmp_e; - L_tmp = Mpy_32_16_1( totalNoiseNrg, noise_band_ratio ); + L_tmp = Mpy_32_16_1( totalNoiseNrg, noise_band_ratio ); // Q31 - totalNoiseNrg_e tmp = BASOP_Util_Divide3232_Scale( L_tmp, rE, &tmp_e ); tmp_e = add( tmp_e, sub( totalNoiseNrg_e, 40 ) ); g = Sqrt16( tmp, &tmp_e ); @@ -441,23 +439,23 @@ static void IGF_decode_whitening_level( Decoder_State *st, Word16 tmp; - tmp = get_next_indice_fx( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); // Q0 if ( tmp == 0 ) { - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_MID; + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_MID; // Q0 move16(); return; } - tmp = get_next_indice_fx( st, 1 ); - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_STRONG; + tmp = get_next_indice_fx( st, 1 ); // Q0 + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_STRONG; // Q0 move16(); if ( tmp == 0 ) { - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; // Q0 move16(); } } @@ -469,7 +467,7 @@ static void IGF_decode_temp_flattening_trigger( Decoder_State *st, IGF_DEC_INSTANCE_HANDLE hInstance /**< in: | instance handle of IGF Deccoder */ ) { - hInstance->flatteningTrigger = get_next_indice_fx( st, 1 ); + hInstance->flatteningTrigger = get_next_indice_fx( st, 1 ); // Q0 move16(); } @@ -520,7 +518,7 @@ static void IGF_convert_exponent_per_idx_to_per_tile( H_IGF_GRID hGrid, FOR( j = start; j < stop; j++ ) { - igfSpec[j] = L_shr( igfSpec[j], sub( max_e, igfSpec_e_per_idx[j] ) ); + igfSpec[j] = L_shr( igfSpec[j], sub( max_e, igfSpec_e_per_idx[j] ) ); // Q31 - max_e move32(); } @@ -593,7 +591,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( i = strt_cpy; i < hGrid->startLine; i++ ) { - abs_sum = L_add( abs_sum, L_abs( src_spec[i] ) ); + abs_sum = L_add( abs_sum, L_abs( src_spec[i] ) ); // Q31 - src_spec_e } /* fill igf_spec with random noise */ @@ -604,7 +602,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { FOR( i = strt_cpy; i < startLine; i++ ) { - igf_spec[tb++] = L_deposit_l( Random( hInfo->nfSeed ) ); /* 31Q0, fill LSBs */ + igf_spec[tb++] = L_deposit_l( Random( hInfo->nfSeed ) ); /* 31Q0, fill LSBs */ // Q0 move32(); } } @@ -612,7 +610,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { FOR( i = strt_cpy; i < startLine; i++ ) { - igf_spec[tb++] = 0; + igf_spec[tb++] = 0; // Q0 move32(); } } @@ -672,7 +670,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { FOR( tb = hGrid->swb_offset[sfb]; tb < hGrid->swb_offset[sfb + 1]; tb++ ) { - igf_spec[tb] = sel_spec[strt_cpy]; + igf_spec[tb] = sel_spec[strt_cpy]; // Q31 - igf_spec_e move32(); strt_cpy = add( strt_cpy, 1 ); } @@ -744,14 +742,14 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in strt_cpy = hGrid->sbWrap[tile_idx]; move16(); - IF( GT_16( element_mode, EVS_MONO ) ) + IF( element_mode > EVS_MONO ) { - tile_width = sub( hGrid->swb_offset[hGrid->sfbWrap[tile_idx + 1]], hGrid->swb_offset[hGrid->sfbWrap[tile_idx]] ); - stop = add( strt_cpy, tile_width ); + tile_width = sub( hGrid->swb_offset[hGrid->sfbWrap[tile_idx + 1]], hGrid->swb_offset[hGrid->sfbWrap[tile_idx]] ); // Q0 + stop = add( strt_cpy, tile_width ); // Q0 } ELSE { - stop = hGrid->startLine; + stop = hGrid->startLine; // Q0 move16(); } @@ -764,18 +762,18 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( i = strt_cpy; i < stop; i++ ) { - abs_sum = L_add_sat( abs_sum, L_abs( src_spec[i] ) ); /* saturation since it just checks if abs_sum is greater than zero*/ + abs_sum = L_add_sat( abs_sum, L_abs( src_spec[i] ) ); /* saturation since it just checks if abs_sum is greater than zero*/ // Q31 - src_spec_e } /* fill igf_spec with random noise */ - tb = hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; + tb = hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; // Q0 move16(); IF( abs_sum != 0 ) { FOR( i = strt_cpy; i < stop; i++ ) { - igf_spec[tb++] = L_deposit_l( Random( hInfo->nfSeed ) ); /* 31Q0, fill LSBs */ + igf_spec[tb++] = L_deposit_l( Random( hInfo->nfSeed ) ); /* 31Q0, fill LSBs */ // Q0 move32(); } } @@ -783,7 +781,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { FOR( i = strt_cpy; i < stop; i++ ) { - igf_spec[tb++] = 0; + igf_spec[tb++] = 0; // Q0 move32(); } } @@ -797,7 +795,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* medium whitening detected */ IF( EQ_16( IGF_WHITENING_MID, hPrivateData->currWhiteningLevel[tile_idx] ) ) { - IF( GT_16( element_mode, EVS_MONO ) ) + IF( element_mode > EVS_MONO ) { IF( n_noise_bands != 0 ) { @@ -879,7 +877,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { FOR( tb = hGrid->swb_offset[sfb]; tb < hGrid->swb_offset[sfb + 1]; tb++ ) { - igf_spec[tb] = sel_spec[strt_cpy]; + igf_spec[tb] = sel_spec[strt_cpy]; // Q31 - igf_spec_e move32(); strt_cpy = add( strt_cpy, 1 ); } @@ -895,9 +893,9 @@ prepare IGF spectrum in stereo static void IGF_prepStereo( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateDataL, /* i : IGF private data handle */ IGF_DEC_PRIVATE_DATA_HANDLE hPrivateDataR, /* i : IGF private data handle */ - const Word16 igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 *TCXNoiseL, /* i : left TCX noise vector */ - const Word16 *TCXNoiseR, /* i : right TCX noise vector */ + const Word16 igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength Q0 */ + const Word16 *TCXNoiseL, /* i : left TCX noise vector Q0 */ + const Word16 *TCXNoiseR, /* i : right TCX noise vector Q0 */ Word32 *igf_specL_fx, /* i/o: prepared left IGF spectrum */ Word16 *igf_specL_e_arr, /* i/o: prepared left IGF spectrum exponents for each index */ Word32 *igf_specR_fx, /* i/o: prepared right IGF spectrum */ @@ -906,7 +904,7 @@ static void IGF_prepStereo( const Word16 src_specL_e, /* i : left source spectrum exp */ const Word32 *src_specR_fx, /* i : right source spectrum */ const Word16 src_specR_e, /* i : right source spectrum exp */ - const Word16 *coreMsMask /* i : line wise ms Mask */ + const Word16 *coreMsMask /* i : line wise ms Mask Q0 */ ) { H_IGF_GRID hGrid; @@ -916,11 +914,15 @@ static void IGF_prepStereo( const Word32 c_fx = SQRT2_OVER_2_FIXED; // Q31 Word16 selectionL = 0; // 0 -> IGF, 1 -> pSpecFlat Word16 selectionR = 0; // 0 -> IGF, 1 -> pSpecFlat + move32(); + move16(); + move16(); hInfoL = &hPrivateDataL->igfInfo; hInfoR = &hPrivateDataR->igfInfo; hGrid = &hPrivateDataL->igfInfo.grid[igfGridIdx]; swb_offset = hGrid->swb_offset; + move16(); FOR( tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++ ) { @@ -938,7 +940,7 @@ static void IGF_prepStereo( FOR( tb = swb_offset[hGrid->sfbWrap[tile_idx]]; tb < swb_offset[hGrid->sfbWrap[tile_idx + 1]]; tb++ ) { - igf_specL_fx[tb] = L_deposit_l( Random( hInfoL->nfSeed ) ); /* 31Q0, fill LSBs */ + igf_specL_fx[tb] = L_deposit_l( Random( hInfoL->nfSeed ) ); /* 31Q0, fill LSBs */ // Q0 move32(); igf_specL_e_arr[tb] = 31; move16(); @@ -1059,8 +1061,8 @@ static void IGF_prepStereo( } ELSE /* MS/DR -> LR */ { - tmpL = Mpy_32_32( selL, c_fx ); - tmpR = Mpy_32_32( selR, c_fx ); + tmpL = Mpy_32_32( selL, c_fx ); // Q31 - selL_e + tmpR = Mpy_32_32( selR, c_fx ); // Q31 - selR_e igf_specL_fx[tb] = BASOP_Util_Add_Mant32Exp( tmpL, selL_e, tmpR, selR_e, &tmp_e ); move32(); igf_specL_e_arr[tb] = tmp_e; @@ -1071,8 +1073,8 @@ static void IGF_prepStereo( { IF( EQ_16( coreMsMask[strt_cpy], 0 ) ) /* LR->MS/DR */ { - tmpL = Mpy_32_32( selL, c_fx ); - tmpR = Mpy_32_32( selR, c_fx ); + tmpL = Mpy_32_32( selL, c_fx ); // Q31 - selL_e + tmpR = Mpy_32_32( selR, c_fx ); // Q31 - selR_e igf_specL_fx[tb] = BASOP_Util_Add_Mant32Exp( tmpL, selL_e, tmpR, selR_e, &tmp_e ); move32(); igf_specL_e_arr[tb] = tmp_e; @@ -1101,7 +1103,7 @@ static void IGF_prepStereo( FOR( tb = swb_offset[hGrid->sfbWrap[tile_idx]]; tb < swb_offset[hGrid->sfbWrap[tile_idx + 1]]; tb++ ) { - igf_specR_fx[tb] = L_deposit_l( Random( hInfoR->nfSeed ) ); /* 31Q0, fill LSBs */ + igf_specR_fx[tb] = L_deposit_l( Random( hInfoR->nfSeed ) ); /* 31Q0, fill LSBs */ // Q0 move32(); igf_specR_e_arr[tb] = 31; move16(); @@ -1225,8 +1227,8 @@ static void IGF_prepStereo( } ELSE /* MS/DR -> LR */ { - tmpL = Mpy_32_32( selL, c_fx ); - tmpR = Mpy_32_32( selR, c_fx ); + tmpL = Mpy_32_32( selL, c_fx ); // Q31 - selL_e + tmpR = Mpy_32_32( selR, c_fx ); // Q31 - selR_e igf_specR_fx[tb] = BASOP_Util_Add_Mant32Exp( tmpL, selL_e, L_negate( tmpR ), selR_e, &tmp_e ); move32(); igf_specR_e_arr[tb] = tmp_e; @@ -1237,8 +1239,8 @@ static void IGF_prepStereo( { IF( EQ_16( coreMsMask[strt_cpy], 0 ) ) /* LR->MS/DR */ { - tmpL = Mpy_32_32( selL, c_fx ); - tmpR = Mpy_32_32( selR, c_fx ); + tmpL = Mpy_32_32( selL, c_fx ); // Q31 - selL_e + tmpR = Mpy_32_32( selR, c_fx ); // Q31 - selR_e igf_specR_fx[tb] = BASOP_Util_Add_Mant32Exp( tmpL, selL_e, L_negate( tmpR ), selR_e, &tmp_e ); move32(); igf_specR_e_arr[tb] = tmp_e; @@ -1493,11 +1495,11 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* initialize variables */ - w0 = 6586; + w0 = 6586; // Q15 move16(); - w1 = 12747; + w1 = 12747; // Q15 move16(); - w2 = 13435; + w2 = 13435; // Q15 move16(); dE = 0; move16(); @@ -1571,8 +1573,8 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { Carry = 0; move16(); -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ - L_tmp = L_add_co( L_tmp, energyTmp[tb], &Carry, &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ + L_tmp = L_add_co( L_tmp, energyTmp[tb], &Carry, &Overflow ); // Q31 - dE_e Overflow = 0; move16(); L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); @@ -1582,7 +1584,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in L_c = L_macNs( L_c, 0, 0 ); #endif } - L_tmp = norm_llQ31( L_c, L_tmp, &shift ); + L_tmp = norm_llQ31( L_c, L_tmp, &shift ); // Q31 /* float: dE = (float)sqrt(dE / 24.f); basop: */ shift = add( sub( shift, 4 ), dE_e ); /* x/24 = (x >> 4) * 1/1.5 */ dE = Sqrt16norm( extract_h( L_tmp ), &shift ); @@ -1610,7 +1612,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize ) { tmp_loop = s_min( add( sfb, hopsize ), stop_sfb ); - FOR( tb = add( sfb, 1 ); tb < tmp_loop; tb++ ) + FOR( tb = sfb + 1; tb < tmp_loop; tb++ ) { sN[sfb] = BASOP_Util_Add_Mant32Exp( sN[sfb], sN_e[sfb], @@ -1642,7 +1644,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in width_e = sub( 15, shift ); /* initial value of width_e is 15, -> width = 15Q0 */ /* float: gn = 0.25f * igf_curr - 4.f; basop: */ - gn = hPrivateData->igf_curr[shr( sfb, 1 )]; + gn = hPrivateData->igf_curr[sfb >> 1]; // Q15 move16(); move16(); gn_e = 13; /* set exponent of igf_curr to 13 = 15 - 2; -> igf_curr = igf_curr * 0.25, virtual division by 4 */ @@ -1875,11 +1877,11 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( tb = 0; tb < hopsize; tb++ ) { /* calculate of the current sfb width */ - width = sub( hGrid->swb_offset[s_min( add( add( sfb, tb ), 1 ), stop_sfb )], /* 15Q0 | width is Q0 */ - hGrid->swb_offset[s_min( add( sfb, tb ), stop_sfb )] ); + width = sub( hGrid->swb_offset[min( sfb + tb + 1, stop_sfb )], /* 15Q0 | width is Q0 */ + hGrid->swb_offset[min( sfb + tb, stop_sfb )] ); - tmp = dS[s_min( add( sfb, tb ), sub( stop_sfb, 1 ) )]; - tmp_e = dS_e[s_min( add( sfb, tb ), sub( stop_sfb, 1 ) )]; + tmp = dS[min( sfb + tb, stop_sfb - 1 )]; + tmp_e = dS_e[min( sfb + tb, stop_sfb - 1 )]; move16(); move16(); @@ -1976,7 +1978,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /*--- check gains /spectrum exponents for possible overflows --- */ /* get tile index */ - if ( LE_16( hGrid->sfbWrap[add( tileIdx, 1 )], sfb ) ) + IF( LE_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) { tileIdx = add( tileIdx, 1 ); } @@ -2026,7 +2028,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( sfb = start_sfb; sfb < stop_sfb; sfb++ ) { /* get tile index */ - if ( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) + IF( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) { tileIdx = add( tileIdx, 1 ); } @@ -2106,7 +2108,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { shift = sub( L_tmp_e, *spectrum_e ); tmp = sub( sub( norm_l( L_tmp ), shift ), 32 ); - if ( tmp < 0 ) + IF( tmp < 0 ) { L_tmp2 = L_shl( L_tmp, shift ); } @@ -2119,7 +2121,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { shift = sub( L_tmp_e, *virtualSpec_e ); tmp = sub( sub( norm_l( L_tmp ), shift ), 32 ); - if ( tmp < 0 ) + IF( tmp < 0 ) { L_tmp2 = L_shl( L_tmp, shift ); } @@ -2209,11 +2211,11 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* initialize variables */ - w0 = 6586; + w0 = 6586; // Q15 move16(); - w1 = 12747; + w1 = 12747; // Q15 move16(); - w2 = 13435; + w2 = 13435; // Q15 move16(); dE = 0; move16(); @@ -2289,8 +2291,8 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { Carry = 0; move16(); -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ - L_tmp = L_add_co( L_tmp, energyTmp[tb], &Carry, &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ + L_tmp = L_add_co( L_tmp, energyTmp[tb], &Carry, &Overflow ); // Q31 - dE_e Overflow = 0; L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); #else @@ -2299,7 +2301,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in L_c = L_macNs( L_c, 0, 0 ); #endif } - L_tmp = norm_llQ31( L_c, L_tmp, &shift ); + L_tmp = norm_llQ31( L_c, L_tmp, &shift ); // Q31 /* float: dE = (float)sqrt(dE / 24.f); basop: */ shift = add( sub( shift, 4 ), dE_e ); /* x/24 = (x >> 4) * 1/1.5 */ dE = Sqrt16norm( extract_h( L_tmp ), &shift ); @@ -2331,7 +2333,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize ) { tmp_loop = s_min( add( sfb, hopsize ), stop_sfb ); - FOR( tb = add( sfb, 1 ); tb < tmp_loop; tb++ ) + FOR( tb = sfb + 1; tb < tmp_loop; tb++ ) { sN[sfb] = BASOP_Util_Add_Mant32Exp( sN[sfb], sN_e[sfb], @@ -2346,9 +2348,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in &pN_e[sfb] ); move32(); sN[tb] = L_deposit_l( 0 ); - move32(); pN[tb] = L_deposit_l( 0 ); - move32(); } } } @@ -2365,7 +2365,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in width_e = sub( 15, shift ); /* initial value of width_e is 15, -> width = 15Q0 */ /* float: gn = 0.25f * igf_curr - 4.f; basop: */ - gn = hPrivateData->igf_curr[shr( sfb, 1 )]; + gn = hPrivateData->igf_curr[sfb >> 1]; // Q15 move16(); move16(); gn_e = 13; /* set exponent of igf_curr to 13 = 15 - 2; -> igf_curr = igf_curr * 0.25, virtual division by 4 */ @@ -2488,7 +2488,11 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* calc square root of L_tmp and store result in dN */ L_tmp = Sqrt32( L_tmp, &L_tmp_e ); +#ifdef FIX_924_IGF_ROUNDFX_SAT + dN[sfb] = round_fx_sat( L_tmp ); +#else dN[sfb] = round_fx( L_tmp ); +#endif move16(); dN_e[sfb] = L_tmp_e; move16(); @@ -2583,11 +2587,11 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( tb = 0; tb < hopsize; tb++ ) { /* calculate of the current sfb width */ - width = sub( hGrid->swb_offset[s_min( add( add( sfb, tb ), 1 ), stop_sfb )], /* 15Q0 | width is Q0 */ - hGrid->swb_offset[s_min( add( sfb, tb ), stop_sfb )] ); + width = sub( hGrid->swb_offset[min( sfb + tb + 1, stop_sfb )], /* 15Q0 | width is Q0 */ + hGrid->swb_offset[min( sfb + tb, stop_sfb )] ); - tmp = dS[s_min( add( sfb, tb ), sub( stop_sfb, 1 ) )]; - tmp_e = dS_e[s_min( add( sfb, tb ), sub( stop_sfb, 1 ) )]; + tmp = dS[min( sfb + tb, stop_sfb - 1 )]; + tmp_e = dS_e[min( sfb + tb, stop_sfb - 1 )]; move16(); move16(); @@ -2792,8 +2796,10 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in move16(); FOR( i = 0; i < hGrid->stopLine; i++ ) { - if ( spectrum[i] != 0 ) + IF( spectrum[i] != 0 ) + { max_e = s_max( max_e, sub( spec_e_arr[i], norm_l( spectrum[i] ) ) ); + } } FOR( i = 0; i < hGrid->stopLine; i++ ) { @@ -2807,8 +2813,10 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in move16(); FOR( i = hGrid->startLine - IGF_START_MN; i < hGrid->stopLine - IGF_START_MN; i++ ) { - if ( virtualSpec[i] ) + IF( virtualSpec[i] ) + { max_e = s_max( max_e, sub( vspec_e_arr[i], norm_l( virtualSpec[i] ) ) ); + } } FOR( i = hGrid->startLine - IGF_START_MN; i < hGrid->stopLine - IGF_START_MN; i++ ) { @@ -2860,9 +2868,9 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in } FOR( j = start; j < stop - level; j++ ) { - tmp_16 = extract_h( L_shl( in[j + level], s_l ) ); // in_e - s_l - ak = L_mac( ak, tmp_16, tmp_16 ); // 2 * (in_e - s_l) - ak_norm = Mpy_32_16_r( ak, 2185 ); + tmp_16 = extract_h( L_shl( in[j + level], s_l ) ); // e: in_e - s_l + ak = L_mac( ak, tmp_16, tmp_16 ); // e: 2 * (in_e - s_l) + ak_norm = Mpy_32_16_r( ak, 2185 /* 1/15 in Q15 */ ); // e: 2 * (in_e - s_l) tmp_16 = sub( 31, norm_l( ak_norm ) ); if ( ak == 0 ) @@ -2873,11 +2881,11 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in tmp_16 = s_min( 14, sub( 15, shr( tmp_16, 1 ) ) ); div = shl( 1, tmp_16 ); - out[j] = Mpy_32_16_1( L_shl( in[j], s_l ), div ); + out[j] = Mpy_32_16_1( L_shl( in[j], s_l ), div ); // e: in_e - s_l move32(); - tmp_16 = extract_h( L_shl( in[j - level], s_l ) ); - ak = L_msu( ak, tmp_16, tmp_16 ); + tmp_16 = extract_h( L_shl( in[j - level], s_l ) ); // e: in_e - s_l + ak = L_msu( ak, tmp_16, tmp_16 ); // e: 2 * (in_e - s_l) } nrm_i = 0; @@ -2885,7 +2893,7 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in FOR( ; j < stop; j++ ) { - ak_norm = Mpy_32_16_r( ak, nrm_tab[nrm_i++] ); + ak_norm = Mpy_32_16_r( ak, nrm_tab[nrm_i++] ); // e: 2 * (in_e - s_l) tmp_16 = sub( 31, norm_l( ak_norm ) ); if ( ak == 0 ) @@ -2903,10 +2911,10 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in move16(); } - out[j] = Mpy_32_16_1( L_shl( in[j], s_l ), div ); + out[j] = Mpy_32_16_1( L_shl( in[j], s_l ), div ); // e: in_e - s_l move32(); - tmp_16 = extract_h( L_shl( in[j - level], s_l ) ); - ak = L_msu( ak, tmp_16, tmp_16 ); + tmp_16 = extract_h( L_shl( in[j - level], s_l ) ); // e: in_e - s_l + ak = L_msu( ak, tmp_16, tmp_16 ); // e: 2 * (in_e - s_l) } } @@ -2919,12 +2927,12 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in static void IGF_getWhiteSpectralData_ivas( const Word32 *in, /* i : MDCT spectrum */ const Word16 in_e, /* i : MDCT spectrum exp */ - Word16 s_l, /* i : getScaleFactor32() of in */ + Word16 s_l, /* i : getScaleFactor32() of in Q0 */ Word32 *out, /* o : whitened spectrum */ Word16 *out_e, /* o : whitened spectrum exp */ - const Word16 start, /* i : start MDCT subband index */ - const Word16 stop, /* i : stop MDCT subband index */ - const Word16 level /* i : whitening strength */ + const Word16 start, /* i : start MDCT subband index Q0 */ + const Word16 stop, /* i : stop MDCT subband index Q0 */ + const Word16 level /* i : whitening strength Q0 */ ) { Word16 i; @@ -2959,8 +2967,8 @@ static void IGF_getWhiteSpectralData_ivas( move32(); FOR( j = i - level; j < i + level + 1; j++ ) { - tmp_16 = extract_h( L_shl( in[j], s_l ) ); - ak = L_mac( ak, tmp_16, tmp_16 ); + tmp_16 = extract_h( L_shl( in[j], s_l ) ); // e: in_e - s_l + ak = L_mac( ak, tmp_16, tmp_16 ); // e: 2 * (in_e - s_l) } ak = L_deposit_h( BASOP_Util_Divide3216_Scale( ak, add( shl( level, 1 ), 1 ), &tmp_e ) ); ak_e = add( tmp_e, sub( shl( sub( in_e, s_l ), 1 ), 15 ) ); // tmp_e + 2 * (in_e - s_l) - 15 @@ -2982,8 +2990,8 @@ static void IGF_getWhiteSpectralData_ivas( FOR( j = i - level; j < stop; j++ ) { - tmp_16 = extract_h( L_shl( in[j], s_l ) ); - ak = L_mac( ak, tmp_16, tmp_16 ); + tmp_16 = extract_h( L_shl( in[j], s_l ) ); // e: in_e - s_l + ak = L_mac( ak, tmp_16, tmp_16 ); // e: 2 * (in_e - s_l) } ak = L_deposit_h( BASOP_Util_Divide3216_Scale( ak, sub( stop, sub( i, level ) ), &tmp_e ) ); ak_e = add( tmp_e, sub( shl( sub( in_e, s_l ), 1 ), 15 ) ); // tmp_e + 2 * (in_e - s_l) - 15 @@ -3000,7 +3008,7 @@ static void IGF_getWhiteSpectralData_ivas( move16(); FOR( i = start; i < stop; i++ ) { - out[i] = L_shr( in[i], *out_e - out_e_arr[i] ); + out[i] = L_shr( in[i], sub( *out_e, out_e_arr[i] ) ); move32(); } @@ -3149,20 +3157,20 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in /* set/reset all values to default = IGF_WHITENING_OFF */ FOR( p = 0; p < IGF_MAX_TILES; p++ ) { - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; // Q0 move16(); } IF( isIndepFrame == 0 ) { - tmp = get_next_indice_fx( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); // Q0 } IF( tmp == 1 ) { FOR( p = 0; p < nT; p++ ) { - hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p]; + hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p]; // Q0 move16(); } } @@ -3177,7 +3185,7 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in } ELSE { - tmp = get_next_indice_fx( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); // Q0 } IF( EQ_16( tmp, 1 ) ) @@ -3191,7 +3199,7 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in { FOR( p = 1; p < nT; p++ ) { - hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0]; + hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0]; // Q0 move16(); } } @@ -3200,7 +3208,7 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in /* save current level for concealment */ FOR( p = 0; p < IGF_MAX_TILES; p++ ) { - hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p]; + hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p]; // Q0 move16(); } @@ -3234,27 +3242,27 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins /* set/reset all values to default = IGF_WHITENING_OFF */ FOR( p = 0; p < IGF_MAX_TILES; p++ ) { - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; // Q0 move16(); } IF( isIndepFrame == 0 ) { - tmp = get_next_indice_fx( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); // Q0 } IF( EQ_16( tmp, 1 ) ) { FOR( p = 0; p < nT; p++ ) { - hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p]; + hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p]; // Q0 move16(); } } ELSE { IGF_decode_whitening_level( st, hPrivateData, 0 ); - tmp = get_next_indice_fx( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); // Q0 IF( EQ_16( tmp, 1 ) ) { FOR( p = 1; p < nT; p++ ) @@ -3266,7 +3274,7 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins { FOR( p = 1; p < nT; p++ ) { - hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0]; + hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0]; // Q0 move16(); } } @@ -3275,7 +3283,7 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins /* save current level for concealment */ FOR( p = 0; p < IGF_MAX_TILES; p++ ) { - hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p]; + hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p]; // Q0 move16(); } @@ -3308,7 +3316,7 @@ void IGFDecReadLevel( /**< ou hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; m_igfSfbStart = hGrid->startSfb; move16(); - IGFAllZero = get_next_indice_fx( st, 1 ); + IGFAllZero = get_next_indice_fx( st, 1 ); // Q0 IF( IGFAllZero == 0 ) { @@ -4249,10 +4257,10 @@ void IGFDecCopyLPCFlatSpectrum_fx( /* pSpectrumFlat_exp has to be multiplied with 1024 = 2^10 go achive proper gain values */ - hPrivateData->pSpecFlat_exp = add( pSpectrumFlat_exp, 10 ); + hPrivateData->pSpecFlat_exp = 30; move16(); - Copy32( pSpectrumFlat, hPrivateData->pSpecFlat, hGrid->startLine ); + Copy_Scale_sig32( pSpectrumFlat, hPrivateData->pSpecFlat, hGrid->startLine, sub( pSpectrumFlat_exp, 20 ) ); // Q11 } } diff --git a/lib_dec/igf_scf_dec_fx.c b/lib_dec/igf_scf_dec_fx.c index e7e4fecb381272626d355c04e309b44794c40e9f..fe670df5652665d8354deb09e7b475c48e6df481 100644 --- a/lib_dec/igf_scf_dec_fx.c +++ b/lib_dec/igf_scf_dec_fx.c @@ -52,7 +52,7 @@ static Word16 quant_ctx_fx( result = s_min( abs_s( ctx ), IGF_CTX_OFFSET ); /* limit the absolute value to IGF_CTX_OFFSET */ - if ( ctx < 0 ) /* add the sign back, if needed */ + IF( ctx < 0 ) /* add the sign back, if needed */ { result = negate( result ); } @@ -90,7 +90,7 @@ static Word16 arith_decode_bits_fx( static Word16 arith_decode_residual_fx( IGFSCFDEC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ Decoder_State *st, /* i/o: pointer to decoder state */ - const UWord16 *cumulativeFrequencyTable, /* i: cumulative frequency table to be used */ + const UWord16 *cumulativeFrequencyTable, /* i: cumulative frequency table to be used Q0 */ Word16 tableOffset /* i: offset used to align the table */ ) { @@ -100,49 +100,49 @@ static Word16 arith_decode_residual_fx( move16(); /* decode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - val = ari_decode_14bits_s27_ext_fx( st, &hPrivateData->acState, cumulativeFrequencyTable ); + val = ari_decode_14bits_s27_ext_fx( st, &hPrivateData->acState, cumulativeFrequencyTable ); // Q0 /* meaning of the values of val: */ /* esc_{0} IGF_MIN_ENC_SEPARATE ... IGF_MAX_ENC_SEPARATE esc_{IGF_SYMBOLS_IN_TABLE - 1} */ test(); IF( ( val != 0 ) && ( NE_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) ) { - x = add( val, -1 + IGF_MIN_ENC_SEPARATE ); /* (val - 1) + IGF_MIN_ENC_SEPARATE */ + x = add( val, -1 + IGF_MIN_ENC_SEPARATE ); /* (val - 1) + IGF_MIN_ENC_SEPARATE */ // Q0 - x = sub( x, tableOffset ); + x = sub( x, tableOffset ); // Q0 return x; } /* decode one of the tails of the distribution */ /* decode extra with 4 bits */ - extra = arith_decode_bits_fx( hPrivateData, st, 4 ); - IF( EQ_16( extra, 15 ) ) /* escape code 15 to indicate extra >= 15 */ + extra = arith_decode_bits_fx( hPrivateData, st, 4 ); // Q0 + IF( EQ_16( extra, 15 ) ) /* escape code 15 to indicate extra >= 15 */ { /* decode addtional extra with 6 bits */ - extra = arith_decode_bits_fx( hPrivateData, st, 6 ); - IF( EQ_16( extra, 63 ) ) /* escape code 63 to indicate extra >= 63 */ + extra = arith_decode_bits_fx( hPrivateData, st, 6 ); // Q0 + IF( EQ_16( extra, 63 ) ) /* escape code 63 to indicate extra >= 63 */ { /* decode safety extra with 7 bits */ - extra = arith_decode_bits_fx( hPrivateData, st, 7 ); + extra = arith_decode_bits_fx( hPrivateData, st, 7 ); // Q0 extra = add( 63, extra ); } - extra = add( 15, extra ); + extra = add( 15, extra ); // Q0 } - if ( val == 0 ) + IF( val == 0 ) { /* escape code 0 to indicate x <= IGF_MIN_ENC_SEPARATE - 1 */ - x = sub( IGF_MIN_ENC_SEPARATE - 1, extra ); + x = sub( IGF_MIN_ENC_SEPARATE - 1, extra ); // Q0 } - if ( EQ_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) + IF( EQ_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) { /* escape code (IGF_SYMBOLS_IN_TABLE - 1) to indicate x >= IGF_MAX_ENC_SEPARATE + 1 */ - x = add( IGF_MAX_ENC_SEPARATE + 1, extra ); + x = add( IGF_MAX_ENC_SEPARATE + 1, extra ); // Q0 } - x = sub( x, tableOffset ); + x = sub( x, tableOffset ); // Q0 return x; } @@ -193,7 +193,7 @@ static void decode_sfe_vector_fx( res = ari_decode_14bits_s27_ext_fx( st, &hPrivateData->acState, (const UWord16 *) hPrivateData->cf_se00 ); pred = arith_decode_bits_fx( hPrivateData, st, 2 ); /* LSBs as 2 bit raw */ - x[f] = add( shl( res, 2 ), pred ); + x[f] = add( shl( res, 2 ), pred ); // Q0 move16(); } ELSE IF( EQ_16( f, 1 ) ) @@ -203,8 +203,8 @@ static void decode_sfe_vector_fx( st, hPrivateData->cf_se01, hPrivateData->cf_off_se01 ); - x[f] = add( x[0], res ); - move16(); /* f - increment is 0, pred = b */ + x[f] = add( x[0], res ); // Q0 + move16(); /* f - increment is 0, pred = b */ } ELSE { @@ -219,8 +219,8 @@ static void decode_sfe_vector_fx( st, hPrivateData->cf_se02 + index1, hPrivateData->cf_off_se02[index2] ); - x[f] = add( x[prev_offset], res ); - move16(); /* pred = b */ + x[f] = add( x[prev_offset], res ); // Q0 + move16(); /* pred = b */ } } ELSE @@ -233,8 +233,8 @@ static void decode_sfe_vector_fx( st, hPrivateData->cf_se10, hPrivateData->cf_off_se10 ); - x[f] = add( prev_x[f], res ); - move16(); /* pred = a */ + x[f] = add( prev_x[f], res ); // Q0 + move16(); /* pred = a */ } ELSE { @@ -257,7 +257,7 @@ static void decode_sfe_vector_fx( st, hPrivateData->cf_se11 + index1, hPrivateData->cf_off_se11[index2] ); - x[f] = add( pred, res ); + x[f] = add( pred, res ); // Q0 move16(); } } @@ -301,7 +301,7 @@ main decoder function void IGFSCFDecoderDecode( IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data or NULL in case there was no instance created */ Decoder_State *st, /* i/o: pointer to decoder state */ - int16_t *sfe, /* o : ptr to an array which will contain the decoded quantized coefficients */ + Word16 *sfe, /* o : ptr to an array which will contain the decoded quantized coefficients */ const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ const Word16 indepFlag /* i : if 1 on input the decoder will be forced to reset, if 0 on input the decoder will be forced to encode without a reset */ diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index 167da45f6b66e7f3c9e424d4d2ad5e3029f112a3..4cdefd6b0dc757140d3ca6be6d7b35057a5efb10 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -86,29 +86,29 @@ ivas_error init_decoder_fx( set16_fx( st_fx->mem_MA_fx, 0, M ); - st_fx->dm_fx.prev_state = 0; - move16(); /* This corresponds to st_fx->dispMem in FLP */ - st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); + st_fx->dm_fx.prev_state = 0; // Q0 + move16(); /* This corresponds to st_fx->dispMem in FLP */ + st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); // Q16 FOR( i = 2; i < 8; i++ ) { - st_fx->dm_fx.prev_gain_pit[i - 2] = 0; + st_fx->dm_fx.prev_gain_pit[i - 2] = 0; // Q14 move16(); } - st_fx->tilt_code_fx = 0; + st_fx->tilt_code_fx = 0; // Q15 move16(); - st_fx->gc_threshold_fx = L_deposit_l( 0 ); + st_fx->gc_threshold_fx = L_deposit_l( 0 ); // Q16 st_fx->last_good = UNVOICED_CLAS; move16(); st_fx->clas_dec = UNVOICED_CLAS; move16(); - st_fx->lp_gainp_fx = 0; + st_fx->lp_gainp_fx = 0; // Q14 move16(); - st_fx->lp_gainc_fx = 0; + st_fx->lp_gainc_fx = 0; // Q3 move16(); - set16_fx( st_fx->old_exc_fx, 0, L_EXC_MEM_DEC ); + set16_fx( st_fx->old_exc_fx, 0, L_EXC_MEM_DEC ); // Q_exc /* AVQ pre-quantizer memory */ st_fx->mem_preemp_preQ_fx = 0; @@ -118,7 +118,7 @@ ivas_error init_decoder_fx( st_fx->use_acelp_preq = 0; move16(); - st_fx->mem_deemph_fx = 0; + st_fx->mem_deemph_fx = 0; // Q_syn move16(); /*-----------------------------------------------------------------* * SWB BWE parameters @@ -178,13 +178,12 @@ ivas_error init_decoder_fx( st_fx->hBWE_FD_HR = NULL; } set16_fx( st_fx->mem_syn1_fx, 0, M ); - move16(); set16_fx( st_fx->mem_syn2_fx, 0, M ); - st_fx->stab_fac_fx = 0; + st_fx->stab_fac_fx = 0; // Q15 move16(); - st_fx->stab_fac_smooth_fx = 0; + st_fx->stab_fac_smooth_fx = 0; // Q15 move16(); - set16_fx( st_fx->agc_mem_fx, 0, 2 ); + set16_fx( st_fx->agc_mem_fx, 0, 2 ); // Q0 set32_fx( st_fx->L_mem_hp_out_fx, 0, 5 ); set16_fx( st_fx->mem_syn3_fx, 0, M ); @@ -197,7 +196,7 @@ ivas_error init_decoder_fx( move16(); st_fx->GSC_noisy_speech = 0; move16(); - st_fx->last_voice_factor_fx = 0; + st_fx->last_voice_factor_fx = 0; // Q6 move16(); set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); @@ -251,30 +250,31 @@ ivas_error init_decoder_fx( } Init_post_filter_fx( st_fx->hPFstat ); - st_fx->psf_lp_noise_fx = 0; + st_fx->psf_lp_noise_fx = 0; // Q8 + move16(); } ELSE { st_fx->hPFstat = NULL; } - st_fx->psf_lp_noise_fx = 0; + st_fx->psf_lp_noise_fx = 0; // Q8 move16(); /* FEC */ st_fx->scaling_flag = 0; move16(); - st_fx->lp_ener_FEC_av = 500000; + st_fx->lp_ener_FEC_av = 500000; // Q0 move32(); - st_fx->lp_ener_FEC_max = 500000; + st_fx->lp_ener_FEC_max = 500000; // Q0 move32(); st_fx->prev_bfi = 0; move16(); - st_fx->lp_ener_FER_fx = 15360; - move16(); /*60 in Q8*/ - st_fx->old_enr_LP = 0; + st_fx->lp_ener_FER_fx = 15360; // Q8 + move16(); /*60 in Q8*/ + st_fx->old_enr_LP = 0; // Q5 move16(); - st_fx->lp_ener_fx = L_deposit_l( 0 ); - st_fx->enr_old_fx = L_deposit_l( 0 ); + st_fx->lp_ener_fx = L_deposit_l( 0 ); // Q6 + st_fx->enr_old_fx = L_deposit_l( 0 ); // Q0 st_fx->bfi_pitch_fx = L_SUBFR_Q6; move16(); st_fx->bfi_pitch_frame = L_SUBFR; @@ -287,8 +287,8 @@ ivas_error init_decoder_fx( FOR( i = 0; i < 2 * NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i] = L_SUBFR << 16; - move32(); /*15Q16*/ + st_fx->old_pitch_buf_fx[i] = L_SUBFR << 16; // Q16 + move32(); /*15Q16*/ } st_fx->upd_cnt = MAX_UPD_CNT; @@ -315,12 +315,12 @@ ivas_error init_decoder_fx( move16(); st_fx->act_count = 3; move16(); - Copy( st_fx->lsp_old_fx, st_fx->lspold_s_fx, M ); + Copy( st_fx->lsp_old_fx, st_fx->lspold_s_fx, M ); // Q15 st_fx->noimix_seed = RANDOM_INITSEED; move16(); - st_fx->min_alpha_fx = 32767; - move16(); /*1; Q15*/ - st_fx->exc_pe_fx = 0; + st_fx->min_alpha_fx = 32767; // Q15 + move16(); /*1; Q15*/ + st_fx->exc_pe_fx = 0; // Q_stat_noise move16(); #ifdef MSAN_FIX st_fx->Q_stat_noise = 31; @@ -370,14 +370,14 @@ ivas_error init_decoder_fx( move16(); /* RXDTX handeler previous frametype flag for G.192 format AMRWB SID_FIRST detection */ st_fx->first_CNG = 0; move16(); - Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); - st_fx->shb_cng_ener_fx = -1541; + Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); // Q15 + st_fx->shb_cng_ener_fx = -1541; // Q8 move16(); - st_fx->wb_cng_ener_fx = -1541; + st_fx->wb_cng_ener_fx = -1541; // Q8 move16(); - st_fx->last_wb_cng_ener_fx = -1541; + st_fx->last_wb_cng_ener_fx = -1541; // Q8 move16(); - st_fx->last_shb_cng_ener_fx = -1541; + st_fx->last_shb_cng_ener_fx = -1541; // Q8 move16(); st_fx->swb_cng_seed = RANDOM_INITSEED; move16(); @@ -388,13 +388,12 @@ ivas_error init_decoder_fx( move32(); st_fx->last_CNG_L_frame = L_FRAME; move16(); - move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - st_fx->lsp_shb_prev_fx[i] = lsp_shb_prev_tbl_fx[i]; + st_fx->lsp_shb_prev_fx[i] = lsp_shb_prev_tbl_fx[i]; // Q15 move16(); - st_fx->lsp_shb_prev_prev_fx[i] = st_fx->lsp_shb_prev_fx[i]; + st_fx->lsp_shb_prev_prev_fx[i] = st_fx->lsp_shb_prev_fx[i]; // Q15 move16(); } @@ -404,12 +403,12 @@ ivas_error init_decoder_fx( move16(); st_fx->trans_cnt_fx = 0; move16(); - st_fx->last_shb_ener_fx = 0; + st_fx->last_shb_ener_fx = 0; // Q8 move16(); /* HF (6-7kHz) BWE */ move16(); - st_fx->Q_stat_noise_ge = GE_SHIFT; + st_fx->Q_stat_noise_ge = GE_SHIFT; // Q of ge_sm_fx move16(); st_fx->cngTDLevel = 0; move16(); @@ -448,15 +447,12 @@ ivas_error init_decoder_fx( ELSE { st_fx->hHQ_nbfec = NULL; - move16(); } } ELSE { st_fx->hHQ_core = NULL; st_fx->hHQ_nbfec = NULL; - move16(); - move16(); } st_fx->Qprev_synth_buffer_fx = 15; move16(); @@ -521,7 +517,7 @@ ivas_error init_decoder_fx( move16(); move16(); - st_fx->tilt_wb_fx = 0; + st_fx->tilt_wb_fx = 0; // Q11 move16(); set16_fx( st_fx->prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); @@ -557,14 +553,14 @@ ivas_error init_decoder_fx( st_fx->hBWE_TD = NULL; } - st_fx->tilt_swb_fx = 0; + st_fx->tilt_swb_fx = 0; // Q24 move16(); - st_fx->tilt_wb_fx = 0; + st_fx->tilt_wb_fx = 0; // Q11 move16(); - st_fx->prev_ener_shb_fx = 0; + st_fx->prev_ener_shb_fx = 0; // Q1 move16(); - st_fx->prev_enerLH_fx = 0; + st_fx->prev_enerLH_fx = 0; // Q1 move16(); st_fx->enerLH_fx = L_deposit_l( 0 ); st_fx->enerLL_fx = L_deposit_l( 0 ); @@ -578,7 +574,7 @@ ivas_error init_decoder_fx( move16(); st_fx->bws_cnt1 = N_NS2W_FRAMES; move16(); - st_fx->attenu_fx = 3277; + st_fx->attenu_fx = 3277; // Q15 move16(); st_fx->last_inner_frame = L_FRAME8k; move16(); @@ -1038,7 +1034,7 @@ ivas_error init_decoder_ivas_fx( FOR( i = 0; i < 2 * NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i] = L_shl( L_SUBFR, 16 ); /*15Q16*/ + st_fx->old_pitch_buf_fx[i] = L_SUBFR << 16; /*15Q16*/ move32(); } @@ -1077,7 +1073,7 @@ ivas_error init_decoder_ivas_fx( st_fx->prev_coder_type = GENERIC; move16(); - st_fx->tilt_wb_fx = 0; + st_fx->tilt_wb_fx = 0; // Q11 move16(); st_fx->last_voice_factor_fx = 0; @@ -1341,11 +1337,11 @@ ivas_error init_decoder_ivas_fx( * WB/SWB bandwidth switching parameters *-----------------------------------------------------------------*/ - st_fx->tilt_swb_fx = 0; + st_fx->tilt_swb_fx = 0; // Q24 move16(); - st_fx->prev_ener_shb_fx = 0; + st_fx->prev_ener_shb_fx = 0; // Q1 move16(); - st_fx->prev_enerLH_fx = 0; + st_fx->prev_enerLH_fx = 0; // Q1 move16(); st_fx->enerLH_fx = L_deposit_l( 0 ); st_fx->enerLL_fx = L_deposit_l( 0 ); @@ -1359,7 +1355,7 @@ ivas_error init_decoder_ivas_fx( move16(); st_fx->bws_cnt1 = N_NS2W_FRAMES; move16(); - st_fx->attenu_fx = 3277; + st_fx->attenu_fx = 3277; // Q15 move16(); st_fx->last_inner_frame = L_FRAME8k; move16(); diff --git a/lib_dec/inov_dec_fx.c b/lib_dec/inov_dec_fx.c index 05f7f98091222f1e847e39586851d1908a21e8dc..96ebf8ec7f78bb96bba377dd983f8c89253786db 100644 --- a/lib_dec/inov_dec_fx.c +++ b/lib_dec/inov_dec_fx.c @@ -41,16 +41,16 @@ void inov_decode_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ + const Word32 core_brate, /* i : core bitrate Q0 */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ + const Word16 L_frame, /* i : length of the frame Q0 */ + const Word16 sharpFlag, /* i : formant sharpening flag Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code, /* o : algebraic excitation */ - const Word16 L_subfr /* i : subframe length */ + Word16 *code, /* o : algebraic excitation Q12 */ + const Word16 L_subfr /* i : subframe length Q0 */ ) { Word16 nBits; @@ -85,7 +85,7 @@ void inov_decode_fx( { IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) { - nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; + nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; // Q0 move16(); IF( EQ_16( nBits, 8 ) ) @@ -110,19 +110,19 @@ void inov_decode_fx( } ELSE { - wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 4 ); + wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 4 ); // Q0 move16(); - bitcnt = s_and( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 15 ); + bitcnt = s_and( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 15 ); // Q0 move16(); // PMT("CONDITION above is missing -> idchan") FOR( i = 0; i < wordcnt; i++ ) { - indexing_indices[i] = extract_l( get_next_indice_fx( st_fx, 16 ) ); + indexing_indices[i] = extract_l( get_next_indice_fx( st_fx, 16 ) ); // Q0 move16(); } IF( bitcnt ) { - indexing_indices[i] = extract_l( get_next_indice_fx( st_fx, bitcnt ) ); + indexing_indices[i] = extract_l( get_next_indice_fx( st_fx, bitcnt ) ); // Q0 move16(); } config = PulseConfTable[st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]]; @@ -136,7 +136,7 @@ void inov_decode_fx( } ELSE { - nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]; + nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]; // Q0 move16(); IF( EQ_16( nBits, 7 ) ) @@ -226,16 +226,16 @@ void inov_decode_fx( void inov_decode_ivas_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ + const Word32 core_brate, /* i : core bitrate Q0 */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ + const Word16 L_frame, /* i : length of the frame Q0 */ + const Word16 sharpFlag, /* i : formant sharpening flag Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code, /* o : algebraic excitation */ - const Word16 L_subfr /* i : subframe length */ + Word16 *code, /* o : algebraic excitation Q12 */ + const Word16 L_subfr /* i : subframe length Q0 */ ) { Word16 nBits; @@ -270,7 +270,8 @@ void inov_decode_ivas_fx( { IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) { - nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; + nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; // Q0 + move16(); IF( EQ_16( nBits, 8 ) ) { @@ -281,7 +282,7 @@ void inov_decode_ivas_fx( dec_acelp_fast_fx( st_fx, nBits, code, L_subfr ); } } - ELSE IF( ( EQ_16( st_fx->idchan, 1 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 7 ) ) || ( EQ_16( st_fx->idchan, 0 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 3 ) ) ) + ELSE IF( ( EQ_16( st_fx->idchan, 1 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 7 ) ) || ( ( st_fx->idchan == 0 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 3 ) ) ) { IF( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0 ) { @@ -294,18 +295,20 @@ void inov_decode_ivas_fx( } ELSE { - wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 4 ); + wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 4 ); // Q0 move16(); - bitcnt = ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ) & 15; + bitcnt = s_and( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 15 ); // Q0 move16(); // PMT("CONDITION above is missing -> idchan") FOR( i = 0; i < wordcnt; i++ ) { - indexing_indices[i] = get_next_indice_fx( st_fx, 16 ); + indexing_indices[i] = get_next_indice_fx( st_fx, 16 ); // Q0 + move16(); } IF( bitcnt ) { - indexing_indices[i] = get_next_indice_fx( st_fx, bitcnt ); + indexing_indices[i] = get_next_indice_fx( st_fx, bitcnt ); // Q0 + move16(); } config = PulseConfTable[st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]]; D_ACELP_indexing_fx( code, config, NB_TRACK_FCB_4T, indexing_indices, &st_fx->BER_detect ); @@ -318,7 +321,7 @@ void inov_decode_ivas_fx( } ELSE { - nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]; + nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]; // Q0 move16(); IF( EQ_16( nBits, 7 ) ) diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 20468f6e54b650fbb8841bcfacff26416200704d..8d44af509f0719c0af55fdc1f8257a827d2c579f 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -59,9 +59,9 @@ ivas_error ivas_core_dec_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ const Word16 n_channels, /* i : number of channels to be decoded */ - Word32 *output_32_fx[], /* o : output synthesis signal */ - Word32 hb_synth_32_fx[][L_FRAME48k], /* o : output HB synthesis signal */ - Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ + Word32 *output_32_fx[], /* o : output synthesis signal Q11*/ + Word32 hb_synth_32_fx[][L_FRAME48k], /* o : output HB synthesis signal Q11*/ + Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers Qx*/ const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ ) { @@ -82,10 +82,10 @@ ivas_error ivas_core_dec_fx( Word16 tmps, incr; Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; - Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; + Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; // Q15 Word16 core_switching_flag[CPE_CHANNELS]; - Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; + Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; // Q6 Word32 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; Word16 unbits[CPE_CHANNELS]; @@ -209,13 +209,13 @@ ivas_error ivas_core_dec_fx( st = sts[n]; IF( st->cldfbAna ) { - scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q10, Q11 ) ); + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, Q10 - Q11 ); // Q10 st->cldfbAna->Q_cldfb_state = Q10; move16(); } IF( st->cldfbSynHB ) { - scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q10, Q11 ) ); + scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, Q10 - Q11 ); // Q10 st->cldfbSynHB->Q_cldfb_state = Q10; move16(); } @@ -268,7 +268,7 @@ ivas_error ivas_core_dec_fx( ELSE { test(); - IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) ) ) /* coder_type for SCh in TD stereo is already read in tdm_configure_dec() */ + if ( !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) ) ) /* coder_type for SCh in TD stereo is already read in tdm_configure_dec() */ { st->coder_type = INACTIVE; move16(); @@ -291,23 +291,24 @@ ivas_error ivas_core_dec_fx( #endif { - conceal_eof_gain32 = L_shr_sat( st->hTcxDec->conceal_eof_gain32, sub( 16, st->hTcxDec->conceal_eof_gain_e ) ); + conceal_eof_gain32 = L_shr_sat( st->hTcxDec->conceal_eof_gain32, sub( 16, st->hTcxDec->conceal_eof_gain_e ) ); // e = 31 - Q , 16 - e => 16 - (31 - Q) => Q - 15, + // shr(16 -e ) = shr(Q -15) => 15 - Q ==> Q15 FOR( i = 0; i < st->hTcxDec->L_frameTCX; i++ ) { - L_tmp = Mpy_32_16_1( conceal_eof_gain32, st->hHQ_core->old_out_fx[i] ); - L_tmp = Mpy_32_16_1( L_tmp, st->last_concealed_gain_syn_deemph ); - L_tmp = L_shl( L_tmp, st->last_concealed_gain_syn_deemph_e ); - st->hHQ_core->old_out_fx[i] = extract_l( L_tmp ); // Q0 + L_tmp = Mpy_32_16_1( conceal_eof_gain32, st->hHQ_core->old_out_fx[i] ); // Q0 (15+1+0 - (15 + 1) + L_tmp = Mpy_32_16_1( L_tmp, st->last_concealed_gain_syn_deemph ); // Q(0+15 - last_concealed_gain_syn_deemph_e -15) + L_tmp = L_shl( L_tmp, st->last_concealed_gain_syn_deemph_e ); // Q0 (-last_concealed_gain_syn_deemph_e +last_concealed_gain_syn_deemph_e) + st->hHQ_core->old_out_fx[i] = extract_l( L_tmp ); // Q0 move16(); } FOR( i = 0; i < st->L_frame; i++ ) { - L_tmp = Mpy_32_16_1( conceal_eof_gain32, st->hHQ_core->old_out_LB_fx[i] ); - L_tmp = Mpy_32_16_1( L_tmp, st->last_concealed_gain_syn_deemph ); - L_tmp = L_shl( L_tmp, st->last_concealed_gain_syn_deemph_e ); - st->hHQ_core->old_out_LB_fx[i] = extract_l( L_tmp ); // Q0 + L_tmp = Mpy_32_16_1( conceal_eof_gain32, st->hHQ_core->old_out_LB_fx[i] ); // Q0 (15+1+0 - (15 + 1) + L_tmp = Mpy_32_16_1( L_tmp, st->last_concealed_gain_syn_deemph ); // Q(0+15 - last_concealed_gain_syn_deemph_e -15) + L_tmp = L_shl( L_tmp, st->last_concealed_gain_syn_deemph_e ); // Q0 (-last_concealed_gain_syn_deemph_e +last_concealed_gain_syn_deemph_e) + st->hHQ_core->old_out_LB_fx[i] = extract_l( L_tmp ); // Q0 move16(); } } @@ -357,9 +358,9 @@ ivas_error ivas_core_dec_fx( Word16 ovl, fade_len; IF( NE_16( sts[0]->L_frame, sts[0]->last_L_frame ) ) { - Copy_Scale_sig_16_32( sts[0]->hHQ_core->old_out_LB_fx, sts[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, sts[0]->hHQ_core->Q_old_wtda_LB ) ); + Copy_Scale_sig_16_32( sts[0]->hHQ_core->old_out_LB_fx, sts[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, sts[0]->hHQ_core->Q_old_wtda_LB ) ); // Q11 L_lerp_fx_q11( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_outLB_fx, sts[0]->L_frame, sts[0]->last_L_frame ); - Copy_Scale_sig_32_16( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( sts[0]->hHQ_core->Q_old_wtda_LB, Q11 ) ); + Copy_Scale_sig_32_16( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( sts[0]->hHQ_core->Q_old_wtda_LB, Q11 ) ); // Q_old_wtda_LB } IF( NE_16( sts[0]->L_frame, L_FRAME16k ) ) { @@ -372,7 +373,7 @@ ivas_error ivas_core_dec_fx( } test(); - IF( hCPE != NULL && hCPE->hStereoCng != NULL ) + if ( hCPE != NULL && hCPE->hStereoCng != NULL ) { hCPE->hStereoCng->flag_cna_fade = 0; move16(); @@ -476,7 +477,7 @@ ivas_error ivas_core_dec_fx( move16(); move16(); - Copy_Scale_sig_16_32( st->previoussynth_fx, st->previoussynth_fx_32, L_FRAME48k, 0 ); + Copy_Scale_sig_16_32( st->previoussynth_fx, st->previoussynth_fx_32, L_FRAME48k, 0 ); // Q0 IF( NE_32( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2 ) ), IVAS_ERR_OK ) ) { @@ -485,7 +486,7 @@ ivas_error ivas_core_dec_fx( flag_sec_CNA = -1; move16(); - IF( hCPE != NULL ) + if ( hCPE != NULL ) { flag_sec_CNA = sts[1]->flag_cna; move16(); @@ -497,7 +498,7 @@ ivas_error ivas_core_dec_fx( * HQ core decoding *---------------------------------------------------------------------*/ - IF( EQ_16( st->core, ACELP_CORE ) ) + IF( st->core == ACELP_CORE ) { /* ACELP core decoder */ Word16 old_syn_12k8_16k_fx_16[L_FRAME16k]; @@ -514,26 +515,26 @@ ivas_error ivas_core_dec_fx( IF( st->cldfbAna ) { - scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, Q11 - Q10 ); // Q11 st->cldfbAna->Q_cldfb_state = Q11; move16(); } IF( st->cldfbBPF ) { - scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub( Q10, Q11 ) ); + scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, Q10 - Q11 ); // Q10 st->cldfbBPF->Q_cldfb_state = Q10; move16(); } IF( st->cldfbSyn ) { - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub( Q10, Q11 ) ); + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, Q10 - Q11 ); // Q10 st->cldfbSyn->Q_cldfb_state = Q10; move16(); } IF( st->hFdCngDec != NULL ) { - Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, add( M, 1 ), sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 3 ) ); + Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, add( M, 1 ), sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 3 ) ); // Qx } IF( hCPE == NULL ) @@ -551,42 +552,41 @@ ivas_error ivas_core_dec_fx( } } - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, st->Q_syn2 ) ); - Scale_sig( output_16_fx[n], L_FRAME48k, negate( st->Q_syn2 ) ); + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, st->Q_syn2 ) ); // Q_syn2->Q11 + Scale_sig( output_16_fx[n], L_FRAME48k, negate( st->Q_syn2 ) ); // Q0 IF( st->cldfbAna ) { - scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q10, Q11 ) ); /* 9 * (Word16)(st->L_frame * FRAMES_PER_SEC * INV_CLDFB_BANDWIDTH + 0.5f) */ + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, Q10 - Q11 ); /* 9 * (Word16)(st->L_frame * FRAMES_PER_SEC * INV_CLDFB_BANDWIDTH + 0.5f) , Q10 */ st->cldfbAna->Q_cldfb_state = Q10; move16(); } IF( st->cldfbBPF ) { - scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub( Q11, Q10 ) ); + scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, Q11 - Q10 ); // Q11 st->cldfbBPF->Q_cldfb_state = Q11; move16(); } IF( st->cldfbSyn ) { - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub( Q11, Q10 ) ); + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, Q11 - Q10 ); // Q11 st->cldfbSyn->Q_cldfb_state = Q11; move16(); } st->prev_Q_syn = st->Q_syn; move16(); - if ( save_hb_synth_32_fx ) + IF( save_hb_synth_32_fx ) { - Copy_Scale_sig_16_32( save_hb_synth_16_fx, save_hb_synth_32_fx, output_frame, Q11 ); + Copy_Scale_sig_16_32( save_hb_synth_16_fx, save_hb_synth_32_fx, output_frame, Q11 ); // Q11 hSCE->q_save_hb_synth_fx = Q11; move16(); } - Copy_Scale_sig_16_32( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], L_FRAME16k, sub( Q11, negate( Q1 ) ) ); + Copy_Scale_sig_16_32( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], L_FRAME16k, Q11 - ( -Q1 ) ); // Q(11 - (-1)) } - Copy_Scale_sig_32_16( st->previoussynth_fx_32, st->previoussynth_fx, L_FRAME48k, 0 ); + Copy_Scale_sig_32_16( st->previoussynth_fx_32, st->previoussynth_fx, L_FRAME48k, 0 ); // Q0 - test(); test(); test(); IF( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -609,10 +609,10 @@ ivas_error ivas_core_dec_fx( move32(); /* TCX decoder */ - Scale_sig( st->hPFstat->mem_stp, L_SUBFR, -Qsyn_temp ); - Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, -Qsyn_temp ); - Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, -st->hHQ_core->Q_old_wtda_LB ); - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, -st->hHQ_core->Q_old_wtda ); + Scale_sig( st->hPFstat->mem_stp, L_SUBFR, -Qsyn_temp ); // Q0 + Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, -Qsyn_temp ); // Q0 + Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, -st->hHQ_core->Q_old_wtda_LB ); // Q0 + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, -st->hHQ_core->Q_old_wtda ); // Q0 st->hHQ_core->Q_old_wtda_LB = 0; move16(); st->hHQ_core->Q_old_wtda = 0; @@ -639,7 +639,7 @@ ivas_error ivas_core_dec_fx( stereo_tcx_core_dec_fx( st, frameMode[n], output_16_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hStereoCng, nchan_out, ivas_format ); st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->Q_old_wtda; move16(); - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 ); + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 ); // Q11 IF( st->hTcxDec ) { @@ -666,13 +666,13 @@ ivas_error ivas_core_dec_fx( ivas_hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_16_fx[n], &Q_output ); - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_output ) ); + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_output ) ); // Q11 #ifdef MSAN_FIX - Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); + Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); // Q0 #else Scale_sig( synth_16_fx[n], L_FRAME48k, negate( Q_synth ) ); #endif - Scale_sig( output_16_fx[n], L_FRAME48k, negate( Q_output ) ); + Scale_sig( output_16_fx[n], L_FRAME48k, negate( Q_output ) ); // Q0 } /*---------------------------------------------------------------------* @@ -682,7 +682,7 @@ ivas_error ivas_core_dec_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && n == 0 ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), negate( Q10 ) ); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), -Q10 ); // Q6 td_stereo_param_updt_fx( st->lsp_old_fx, st->lsf_old_fx, st->old_pitch_buf_16_fx + st->nb_subfr, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, hStereoTD->tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc @@ -692,7 +692,7 @@ ivas_error ivas_core_dec_fx( #endif ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), Q10 ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), Q10 ); // Q16 } } /* n_channels loop */ @@ -714,13 +714,13 @@ ivas_error ivas_core_dec_fx( st = sts[n]; IF( st->cldfbAna ) { - scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, Q11 - Q10 ); // Q11 st->cldfbAna->Q_cldfb_state = Q11; move16(); } IF( st->cldfbSynHB ) { - scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q11, Q10 ) ); + scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, Q11 - Q10 ); // Q11 st->cldfbSynHB->Q_cldfb_state = Q11; move16(); } @@ -744,17 +744,17 @@ ivas_error ivas_core_dec_fx( st->last_gain_syn_deemph = 0; move16(); - IF( st->hHQ_core ) + if ( st->hHQ_core ) { st->hHQ_core->Q_fer_samples = 0; move16(); } #ifdef FIX_778_STEREO_BRATE_SWITCHING - if ( NE_16( st->core, st->last_core ) ) + IF( NE_16( st->core, st->last_core ) ) { IF( st->hTcxDec ) { - Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, negate( st->Q_syn ) ); + Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, negate( st->Q_syn ) ); // Q0 } st->Q_syn = 0; move16(); @@ -764,12 +764,12 @@ ivas_error ivas_core_dec_fx( st->prev_Q_syn = st->Q_syn; move16(); - IF( st->hTcxDec ) + if ( st->hTcxDec ) { st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; move16(); } - IF( st->hTcxDec ) + if ( st->hTcxDec ) { st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; move16(); @@ -870,7 +870,7 @@ ivas_error ivas_core_dec_fx( IF( p_output_mem_fx != NULL ) { p_output_mem_16 = output_mem_16_fx; - Copy_Scale_sig_32_16( p_output_mem_fx, p_output_mem_16, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), negate( Q11 ) ); + Copy_Scale_sig_32_16( p_output_mem_fx, p_output_mem_16, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), -Q11 ); // Q(q_output_mem_fx-11) } ELSE { @@ -878,14 +878,14 @@ ivas_error ivas_core_dec_fx( set16_fx( output_mem_16_fx, 0, NS2SA_FX2( st->output_Fs, 3125000 ) ); } - Scale_sig32( output_32_fx[n], L_FRAME48k, sub( Q4, Q11 ) ); + Scale_sig32( output_32_fx[n], L_FRAME48k, Q4 - Q11 ); // Q4 /*size of synth is choosen as delay comp to start with*/ /*-------------------cldfb-start-------------------------*/ IF( st->cldfbSyn != NULL ) { - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q4, Q11 ) ); + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, Q4 - Q11 ); // Q4 st->cldfbSyn->Q_cldfb_state = Q4; move16(); } @@ -899,7 +899,7 @@ ivas_error ivas_core_dec_fx( test(); test(); test(); - IF( EQ_16( st->last_core, ACELP_CORE ) && ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) && st->hBWE_TD != NULL ) + IF( ( st->last_core == ACELP_CORE ) && ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) && st->hBWE_TD != NULL ) { test(); test(); @@ -915,22 +915,22 @@ ivas_error ivas_core_dec_fx( } /* Memories Scaling */ - Copy_Scale_sig_32_16( st->hBWE_TD->syn_overlap_fx_32, st->hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, sub( st->prev_Q_bwe_syn2, Q11 ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( st->prev_Qx, Q11 ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_shb_fx_32, st->hBWE_TD->state_lsyn_filt_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( st->prev_Qx, Q11 ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->mem_resamp_HB_fx_32, st->hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( st->prev_Qx, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->syn_overlap_fx_32, st->hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, sub( st->prev_Q_bwe_syn2, Q11 ) ); // prev_Q_bwe_syn2 + Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); // prev_Qx + Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, ALLPASSSECTIONS_STEEP * 2, sub( st->prev_Qx, Q11 ) ); // prev_Qx + Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_shb_fx_32, st->hBWE_TD->state_lsyn_filt_shb_fx, ALLPASSSECTIONS_STEEP * 2, sub( st->prev_Qx, Q11 ) ); // prev_Qx + Copy_Scale_sig_32_16( st->hBWE_TD->mem_resamp_HB_fx_32, st->hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( st->prev_Qx, Q11 ) ); // prev_Qx } /* Memories Re-Scaling */ IF( st->hBWE_TD != NULL ) { - Copy_Scale_sig_16_32( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, st->prev_Q_bwe_syn2 ) ); - Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); - Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( Q11, st->prev_Qx ) ); - Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_shb_fx, st->hBWE_TD->state_lsyn_filt_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( Q11, st->prev_Qx ) ); - Copy_Scale_sig_16_32( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->mem_resamp_HB_fx_32, INTERP_3_1_MEM_LEN, sub( Q11, st->prev_Qx ) ); - Copy( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->state_32and48k_WB_upsample_fx, imult1616( 2, ALLPASSSECTIONS_STEEP ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, st->prev_Q_bwe_syn2 ) ); // Q11 + Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); // Q11 + Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, ALLPASSSECTIONS_STEEP * 2, sub( Q11, st->prev_Qx ) ); // Q11 + Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_shb_fx, st->hBWE_TD->state_lsyn_filt_shb_fx_32, ALLPASSSECTIONS_STEEP * 2, sub( Q11, st->prev_Qx ) ); // Q11 + Copy_Scale_sig_16_32( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->mem_resamp_HB_fx_32, INTERP_3_1_MEM_LEN, sub( Q11, st->prev_Qx ) ); // Q11 + Copy( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->state_32and48k_WB_upsample_fx, ( 2 * ALLPASSSECTIONS_STEEP ) ); } /*---------------------------------------------------------------------* * Postprocessing for ACELP/MDCT core switching @@ -942,7 +942,7 @@ ivas_error ivas_core_dec_fx( test(); IF( sba_dirac_stereo_flag && NE_16( st->element_mode, IVAS_CPE_MDCT ) && !( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) ) { - Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); + Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); // q_save_synth_fx } IVAS_FORMAT ivas_format; @@ -977,7 +977,7 @@ ivas_error ivas_core_dec_fx( test(); IF( sba_dirac_stereo_flag && hSCE && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) { - Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); + Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); // q_save_synth_fx } /* if we transition from inactive to active coding in MDCT-Stereo DTX and the output format is mono DMX, we need to sync the upsampled buffer between channels here */ @@ -999,20 +999,20 @@ ivas_error ivas_core_dec_fx( IF( st->hHQ_core == NULL ) { - Copy_Scale_sig_16_32( st->delay_buf_out_fx, st->delay_buf_out32_fx, imult1616( HQ_DELTA_MAX, HQ_DELAY_COMP ), Q11 ); + Copy_Scale_sig_16_32( st->delay_buf_out_fx, st->delay_buf_out32_fx, ( HQ_DELTA_MAX * HQ_DELAY_COMP ), Q11 ); // Q11 } ELSE { - Copy_Scale_sig_16_32( st->delay_buf_out_fx, st->delay_buf_out32_fx, imult1616( HQ_DELTA_MAX, HQ_DELAY_COMP ), sub( Q11, st->hHQ_core->Q_old_postdec ) ); + Copy_Scale_sig_16_32( st->delay_buf_out_fx, st->delay_buf_out32_fx, ( HQ_DELTA_MAX * HQ_DELAY_COMP ), sub( Q11, st->hHQ_core->Q_old_postdec ) ); // Q11 } - Scale_sig32( output_32_fx[n], L_FRAME48k, ( Q11 - Q4 ) ); + Scale_sig32( output_32_fx[n], L_FRAME48k, ( Q11 - Q4 ) ); // Q11 /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ IF( st->cldfbSyn != NULL ) { - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, ( Q11 - Q4 ) ); + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, ( Q11 - Q4 ) ); // Q11 st->cldfbSyn->Q_cldfb_state = Q11; move16(); } @@ -1020,7 +1020,7 @@ ivas_error ivas_core_dec_fx( #ifdef MSAN_FIX IF( Q_synth > 0 ) { - Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); + Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); // Q0 Q_synth = 0; move16(); } @@ -1070,8 +1070,8 @@ ivas_error ivas_core_dec_fx( FD_BWE_DEC_HANDLE hBWE_FD; hBWE_FD = st->hBWE_FD; - Copy_Scale_sig_32_16( output_32_fx[n], output_16_fx[n], L_FRAME48k, sub( Q_input, Q11 ) ); - Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, negate( Q11 ) ); + Copy_Scale_sig_32_16( output_32_fx[n], output_16_fx[n], L_FRAME48k, sub( Q_input, Q11 ) ); // Q_input + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, -( Q11 ) ); // Q0 test(); test(); test(); @@ -1095,17 +1095,17 @@ ivas_error ivas_core_dec_fx( } /* Memories Re-Scaling */ - Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, sub( Q11, Q_hb_synth_fx ) ); - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); - Copy_Scale_sig_16_32( synth_16_fx[n], synth_32_fx[n], L_FRAME48k, sub( Q11, Q_synth_fx ) ); + Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, sub( Q11, Q_hb_synth_fx ) ); // Q11 + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); // Q11 + Copy_Scale_sig_16_32( synth_16_fx[n], synth_32_fx[n], L_FRAME48k, sub( Q11, Q_synth_fx ) ); // Q11 IF( hBWE_FD != NULL ) { - Copy_Scale_sig_16_32( hBWE_FD->L_old_wtda_swb_fx, hBWE_FD->L_old_wtda_swb_fx32, L_FRAME48k, sub( Q11, hBWE_FD->old_wtda_swb_fx_exp ) ); + Copy_Scale_sig_16_32( hBWE_FD->L_old_wtda_swb_fx, hBWE_FD->L_old_wtda_swb_fx32, L_FRAME48k, sub( Q11, hBWE_FD->old_wtda_swb_fx_exp ) ); // Q11 } IF( st->hBWE_TD != NULL ) { - Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); // Q11 } /*---------------------------------------------------------------------* @@ -1136,12 +1136,12 @@ ivas_error ivas_core_dec_fx( move16(); ivas_swb_tbe_dec_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, hb_synth_32_fx[n], pitch_buf_fx[n], &Q_white_exc ); - Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, st->prev_Q_bwe_syn2 ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); + Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, st->prev_Q_bwe_syn2 ) ); // Q11 + Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); // prev_Qx IF( GT_16( Q_white_exc, 31 ) ) { - Scale_sig( tmp_buffer_fx, L_FRAME48k, sub( 31, Q_white_exc ) ); + Scale_sig( tmp_buffer_fx, L_FRAME48k, sub( 31, Q_white_exc ) ); // Q31 Q_white_exc = 31; move16(); } @@ -1157,9 +1157,9 @@ ivas_error ivas_core_dec_fx( /* SWB BWE decoder */ Q_syn_hb = swb_bwe_dec_fx32( st, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], use_cldfb_for_dft, output_frame ); - Scale_sig32( hb_synth_32_fx[n], output_frame, sub( Q11, Q_syn_hb ) ); + Scale_sig32( hb_synth_32_fx[n], output_frame, sub( Q11, Q_syn_hb ) ); // Q11 - Copy_Scale_sig_32_16( st->hBWE_FD->L_old_wtda_swb_fx32, st->hBWE_FD->L_old_wtda_swb_fx, output_frame, sub( hBWE_FD->old_wtda_swb_fx_exp, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_FD->L_old_wtda_swb_fx32, st->hBWE_FD->L_old_wtda_swb_fx, output_frame, sub( hBWE_FD->old_wtda_swb_fx_exp, Q11 ) ); // old_wtda_swb_fx_exp } /*---------------------------------------------------------------------* @@ -1172,7 +1172,7 @@ ivas_error ivas_core_dec_fx( { /*tmp = FRAC_BWE_SMOOTH/output_frame;*/ tmp16 = shr( 410, shr( output_frame, 8 ) ); /* Q15 */ - IF( EQ_16( output_frame, L_FRAME48k ) ) + if ( EQ_16( output_frame, L_FRAME48k ) ) { tmp16 = 68; move16(); @@ -1209,34 +1209,34 @@ ivas_error ivas_core_dec_fx( q = 2; move16(); - Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, negate( ( Q11 ) ) ); + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, -( Q11 ) ); // Q0 #ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, output_frame, negate( add( Q11, q ) ) ); + Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, output_frame, negate( add( Q11, q ) ) ); // Q0 #else Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, L_FRAME48k, negate( add( Q11, q ) ) ); #endif - Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, sub( Q8, st->prev_Q_bwe_syn ) ); + Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, sub( Q8, st->prev_Q_bwe_syn ) ); // Q8 #ifndef FIX_854_HILBERT_SCALING Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, sub( st->prev_Q_bwe_syn2, Q11 ) ); #endif - Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, imult1616( 2, ALLPASSSECTIONS_STEEP ), sub( st->prev_Q_bwe_syn2, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, ( 2 * ALLPASSSECTIONS_STEEP ), sub( st->prev_Q_bwe_syn2, Q11 ) ); // prev_Q_bew_syn2 swb_CNG_dec_ivas_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], negate( q ) ); test(); IF( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) { - Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, ( Q11 ) ); + Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, ( Q11 ) ); // Q11 } #ifndef FIX_826_PRECISION_LOST_AND_COMPL Copy_Scale_sig_16_32( synth_fxl, synth_32_fx[n], L_FRAME48k, ( Q11 + q ) ); #endif - Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, -( Q8 - st->prev_Q_bwe_syn ) ); + Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, negate( sub( Q8, st->prev_Q_bwe_syn ) ) ); // Q0 #ifndef FIX_854_HILBERT_SCALING Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, -( st->prev_Q_bwe_syn2 - Q11 ) ); #endif - Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 2 * ALLPASSSECTIONS_STEEP, -( st->prev_Q_bwe_syn2 - Q11 ) ); + Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 2 * ALLPASSSECTIONS_STEEP, negate( sub( st->prev_Q_bwe_syn2, Q11 ) ) ); } /*-------------------------------------------------------------------* @@ -1249,7 +1249,7 @@ ivas_error ivas_core_dec_fx( q = 11; move16(); - IF( hCPE->hStereoDft != NULL ) + if ( hCPE->hStereoDft != NULL ) { hCPE->hStereoDft->td_gain_fx[0] = 1; move32(); @@ -1269,8 +1269,8 @@ ivas_error ivas_core_dec_fx( test(); IF( ( GT_32( st->core_brate, SID_2k40 ) && ( !( ( ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) || ( ( NE_16( st->core, ACELP_CORE ) || EQ_16( st->extl, -1 ) ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && hCPE->hCoreCoder[0]->tdm_LRTD_flag != 0 ) ) ) ) ) ) ) { - Scale_sig32( hb_synth_32_fx[0], output_frame, sub( Q11, q ) ); - Scale_sig32( hb_synth_32_fx[1], output_frame, sub( Q11, q ) ); + Scale_sig32( hb_synth_32_fx[0], output_frame, sub( Q11, q ) ); // Q11 + Scale_sig32( hb_synth_32_fx[1], output_frame, sub( Q11, q ) ); // Q11 } #else Scale_sig32( hb_synth_32_fx[0], L_FRAME48k, sub( Q11, q ) ); @@ -1349,15 +1349,15 @@ ivas_error ivas_core_dec_fx( test(); test(); IF( !( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) && st->last_core == ACELP_CORE ) && - ( NE_16( st->extl, st->last_extl ) || ( EQ_16( st->extl, st->last_extl ) && s_xor( st->core, st->last_core ) == HQ_CORE ) ) && !( EQ_16( st->extl, SWB_CNG ) && EQ_16( st->last_extl, SWB_TBE ) ) && ( NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && tdm_LRTD_flag ) ) ) + ( NE_16( st->extl, st->last_extl ) || ( EQ_16( st->extl, st->last_extl ) && EQ_16( s_xor( st->core, st->last_core ), HQ_CORE ) ) ) && !( EQ_16( st->extl, SWB_CNG ) && EQ_16( st->last_extl, SWB_TBE ) ) && ( NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && tdm_LRTD_flag ) ) ) { /* switching between BWE and TBE technologies */ - incr = idiv1616( imult1616( L_FRAME, 2 ), add( shl( tmps, 1 ), 1 ) ); + incr = idiv1616( ( L_FRAME * 2 ), add( shl( tmps, 1 ), 1 ) ); tmp16 = 0; move16(); FOR( i = 0; i < tmps; i++ ) { - hb_synth_32_fx[n][i] = Mpy_32_16_1( hb_synth_32_fx[n][i], sin_table256_fx[tmp16] ); + hb_synth_32_fx[n][i] = Mpy_32_16_1( hb_synth_32_fx[n][i], sin_table256_fx[tmp16] ); // Q11 move16(); tmp16 = add( tmp16, incr ); } @@ -1368,19 +1368,19 @@ ivas_error ivas_core_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 = idiv1616( imult1616( L_FRAME, 2 ), add( shl( tmps, 1 ), 1 ) ); + incr = idiv1616( ( L_FRAME * 2 ), add( shl( tmps, 1 ), 1 ) ); tmp16 = 0; move16(); FOR( i = 0; i < tmps; i++ ) { #ifndef FIX_826_PRECISION_LOST_AND_COMPL - tmp_buffer_fx[i] = round_fx( L_add( L_shr( L_mult( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), 1 ), L_shr( L_mult( st->hb_prev_synth_buffer_fx[sub( sub( st->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16] ), 1 ) ) ); + tmp_buffer_fx[i] = round_fx( L_add( L_shr( L_mult( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), 1 ), L_shr( L_mult( st->hb_prev_synth_buffer_fx[st->old_bwe_delay - 1 - i], sin_table256_fx[tmp16] ), 1 ) ) ); move16(); tmp_buffer_fx[i] = shl_sat( tmp_buffer_fx[i], 1 ); move16(); #else - tmp_buffer_fx[i] = round_fx_sat( L_mac_sat( L_mult( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), st->hb_prev_synth_buffer_fx[sub( sub( st->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16] ) ); + tmp_buffer_fx[i] = round_fx_sat( L_mac_sat( L_mult( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), st->hb_prev_synth_buffer_fx[st->old_bwe_delay - 1 - i], sin_table256_fx[tmp16] ) ); // Q0 (0+15-15) move16(); #endif @@ -1396,7 +1396,7 @@ ivas_error ivas_core_dec_fx( move16(); FOR( i = 0; i < st->old_bwe_delay; i++ ) { - tmp_buffer_fx[i] = mult_r( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ); + tmp_buffer_fx[i] = mult_r( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ); // Q0(0+15-15) move16(); tmp16 = add( tmp16, incr ); } @@ -1409,7 +1409,7 @@ ivas_error ivas_core_dec_fx( move16(); FOR( i = 0; i < st->old_bwe_delay; i++ ) { - tmp_buffer_fx[sub( sub( tmps, 1 ), i )] = round_fx( L_mac( L_mult( tmp_buffer_fx[sub( sub( tmps, 1 ), i )], 32767 ), st->hb_prev_synth_buffer_fx[sub( sub( st->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->hb_prev_synth_buffer_fx[st->old_bwe_delay - 1 - i], sin_table256_fx[tmp16 /*i * incr*/] ) ); // 32767-> (1.0f in Q15) -1 move16(); tmp16 = add( tmp16, incr ); } @@ -1425,13 +1425,13 @@ ivas_error ivas_core_dec_fx( /* Delay hb_synth */ Word32 hb_prev_synth_buffer_fx_32[111]; - Copy_Scale_sig_16_32( st->hb_prev_synth_buffer_fx, hb_prev_synth_buffer_fx_32, 111, 11 ); + Copy_Scale_sig_16_32( st->hb_prev_synth_buffer_fx, hb_prev_synth_buffer_fx_32, 111, 11 ); // Q11 delay_signal_fx( hb_synth_32_fx[n], output_frame, hb_prev_synth_buffer_fx_32, tmps ); - Copy_Scale_sig_32_16( hb_prev_synth_buffer_fx_32, st->hb_prev_synth_buffer_fx, 111, negate( 11 ) ); + Copy_Scale_sig_32_16( hb_prev_synth_buffer_fx_32, st->hb_prev_synth_buffer_fx, 111, -( 11 ) ); // Q0 } ELSE { - Copy_Scale_sig_32_16( hb_synth_32_fx[n] + sub( output_frame, tmps ), st->hb_prev_synth_buffer_fx, tmps, negate( Q11 ) ); + Copy_Scale_sig_32_16( hb_synth_32_fx[n] + sub( output_frame, tmps ), st->hb_prev_synth_buffer_fx, tmps, -( Q11 ) ); // Q0 } st->old_bwe_delay = tmps; @@ -1493,7 +1493,7 @@ ivas_error ivas_core_dec_fx( IF( sba_dirac_stereo_flag && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { /* for SBA DirAC stereo output DFT Stereo core switching and updates are done in ivas_sba_dirac_stereo_dec() as hCPE is not available at this point */ - break; + BREAK; } /*----------------------------------------------------------------* @@ -1510,8 +1510,8 @@ ivas_error ivas_core_dec_fx( { IF( hCPE->hCoreCoder[ch_ind]->hHQ_core != NULL ) { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda_LB ) ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda_LB ) ); // Q11 + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda ) ); // Q11 } } } @@ -1522,8 +1522,8 @@ ivas_error ivas_core_dec_fx( { IF( hSCE->hCoreCoder[0]->hHQ_core != NULL ) { - Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hSCE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); - Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_fx, hSCE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hSCE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); // Q11 + Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_fx, hSCE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); // Q11 } } } @@ -1570,8 +1570,8 @@ ivas_error ivas_core_dec_fx( IF( DFT_fx != NULL ) { - Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_DFT[0] ) ); - Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_DFT[1] ) ); + Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_DFT[0] ) ); // q_dft + Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_DFT[1] ) ); // q_dft } test(); @@ -1595,7 +1595,7 @@ ivas_error ivas_core_dec_fx( test(); test(); test(); - IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) + IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) { Word16 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0; move16(); @@ -1604,7 +1604,7 @@ ivas_error ivas_core_dec_fx( move16(); move16(); - Copy_Scale_sig32_16( st->prev_synth_buffer32_fx, st->prev_synth_buffer_fx, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), negate( Q11 ) ); + Copy_Scale_sig32_16( st->prev_synth_buffer32_fx, st->prev_synth_buffer_fx, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -( Q11 ) ); // Q0 st->q_prev_synth_buffer_fx = 0; move16(); @@ -1625,13 +1625,14 @@ ivas_error ivas_core_dec_fx( Copy32( output_32_fx[n], output_fx_loc, output_frame ); - Scale_sig32( output_fx_loc, output_frame, sub( exp_max, Q11 ) ); - Scale_sig( st->delay_buf_out_fx, NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ), exp_max ); - Scale_sig( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), sub( NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ), NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ) ), exp_max ); - Scale_sig( st->prev_synth_buffer_fx, NS2SA_FX2( 48000, L_sub( DELAY_BWE_TOTAL_NS, DELAY_CLDFB_NS ) ), sub( exp_max, st->q_prev_synth_buffer_fx ) ); - Scale_sig( st->hTcxDec->synth_history_fx + output_frame, sub( add( sub( imult1616( 2, output_frame ), NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ), output_frame ), sub( exp_max, 0 ) ); + Scale_sig32( output_fx_loc, output_frame, sub( exp_max, Q11 ) ); // Q(31-exp_max) + Scale_sig( st->delay_buf_out_fx, NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ), exp_max ); // exp_max + Scale_sig( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), sub( NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ), NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ) ), exp_max ); // Q(31-exp_max) + Scale_sig( st->prev_synth_buffer_fx, NS2SA_FX2( 48000, L_sub( DELAY_BWE_TOTAL_NS, DELAY_CLDFB_NS ) ), sub( exp_max, st->q_prev_synth_buffer_fx ) ); // Q(exp_max - prev_synth_buffer_fx) + Scale_sig( st->hTcxDec->synth_history_fx + output_frame, sub( add( sub( imult1616( 2, output_frame ), NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ), output_frame ), sub( exp_max, 0 ) ); // Q(31-exp_max) st->q_prev_synth_buffer_fx = sub( exp_max, st->q_prev_synth_buffer_fx ); + move16(); } /* Save synthesis for HQ FEC */ save_synthesis_hq_fec_fx( st, output_fx_loc, output_frame, hCPE ); @@ -1640,7 +1641,7 @@ ivas_error ivas_core_dec_fx( ivas_updt_dec_common_fx( st, NORMAL_HQ_CORE, -1, output_32_fx[n], Q11 ); - Scale_sig( st->delay_buf_out_fx, NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ), negate( exp_max ) ); + Scale_sig( st->delay_buf_out_fx, NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ), negate( exp_max ) ); // Q0 } /* n_channels loop */ @@ -1649,13 +1650,13 @@ ivas_error ivas_core_dec_fx( st = sts[n]; IF( st->cldfbAna ) { - scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, ( Q11 - Q10 ) ); // Q11 st->cldfbAna->Q_cldfb_state = Q11; move16(); } IF( st->cldfbSynHB ) { - scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q11, Q10 ) ); + scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, ( Q11 - Q10 ) ); // Q11 st->cldfbSynHB->Q_cldfb_state = Q11; move16(); } diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index 66bd6d691ae4cbda8dc037a7baca8591f9796194..8b83d87026c7f1d5f2a0a48e5646235ac340f1f0 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -120,7 +120,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx( destroy_cpe_dec( st_ivas->hCPE[0] ); st_ivas->hCPE[0] = NULL; - if ( st_ivas->hSCE[0] != NULL ) + IF( st_ivas->hSCE[0] != NULL ) { free( st_ivas->hSCE[0]->save_synth_fx ); st_ivas->hSCE[0]->save_synth_fx = NULL; @@ -829,6 +829,7 @@ ivas_error ivas_hp20_dec_reconfig_fx( FOR( i = 0; i < nchan_hp20_old; i++ ) { st_ivas->mem_hp20_out_fx[i] = old_mem_hp20_out_fx[i]; + move32(); old_mem_hp20_out_fx[i] = NULL; } /* create additional hp20 memories */ @@ -859,6 +860,7 @@ ivas_error ivas_hp20_dec_reconfig_fx( FOR( i = 0; i < nchan_hp20; i++ ) { st_ivas->mem_hp20_out_fx[i] = old_mem_hp20_out_fx[i]; + move32(); old_mem_hp20_out_fx[i] = NULL; } /* remove superfluous hp20 memories */ @@ -985,7 +987,7 @@ ivas_error ivas_cldfb_dec_reconfig_fx( numCldfbAnalyses_old = sub( numCldfbAnalyses_old, 1 ); } /* resample CLDFB analysis instances */ - FOR( i = 0; i < min( numCldfbAnalyses, numCldfbAnalyses_old ); i++ ) + FOR( i = 0; i < s_min( numCldfbAnalyses, numCldfbAnalyses_old ); i++ ) { IF( NE_32( L_mult0( extract_l( L_mult0( st_ivas->cldfbAnaDec[i]->no_channels, st_ivas->cldfbAnaDec[i]->no_col ) ), FRAMES_PER_SEC ), hDecoderConfig->output_Fs ) ) { @@ -1044,14 +1046,14 @@ ivas_error ivas_cldfb_dec_reconfig_fx( ivas_spar_get_cldfb_gains_fx( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); FOR( i = 0; i < st_ivas->cldfbAnaDec[0]->cldfb_state_length; i++ ) { - st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i], sub( Q27, Q11 ) ); // Scaling down from 27 to 11 + st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i], ( Q27 - Q11 ) ); // Scaling down from 27 to 11 move32(); } st_ivas->cldfbAnaDec[0]->Q_cldfb_state = Q11; move16(); FOR( i = 0; i < st_ivas->cldfbSynDec[0]->cldfb_state_length; i++ ) { - st_ivas->cldfbSynDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbSynDec[0]->cldfb_state_fx[i], sub( Q21, Q11 ) ); // Scaling down from 21 to 11 + st_ivas->cldfbSynDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbSynDec[0]->cldfb_state_fx[i], ( Q21 - Q11 ) ); // Scaling down from 21 to 11 move32(); } st_ivas->cldfbSynDec[0]->Q_cldfb_state = Q11; diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index 1911b3c4db8ff34976ce943f0250ac9223c2699a..9705b77012b9287a16237762da31f1be91fdaf09 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -64,7 +64,7 @@ static void stereo_mode_combined_format_dec_fx( const Decoder_Struct *st_ivas, C ivas_error ivas_cpe_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 cpe_id, /* i : CPE # identifier */ - Word32 *output[CPE_CHANNELS], /* o : output synthesis signal */ + Word32 *output[CPE_CHANNELS], /* o : output synthesis signal Q11*/ const Word16 output_frame, /* i : output frame length per channel */ const Word16 nb_bits_metadata /* i : number of metadata bits */ #ifndef FIX_826_PRECISION_LOST_AND_COMPL @@ -131,14 +131,14 @@ ivas_error ivas_cpe_dec_fx( test(); IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda ) ); // Q11 } } FOR( Word16 ind1 = 0; ind1 < 2; ind1++ ) { IF( hCPE->hCoreCoder[ind1]->hHQ_core ) { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB ) ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB ) ); // Q11 hCPE->hCoreCoder[ind1]->hHQ_core->q_old_outLB_fx = Q11; move16(); } @@ -151,9 +151,10 @@ ivas_error ivas_cpe_dec_fx( FOR( Word16 ind1 = 0; ind1 < 2; ind1++ ) { + test(); IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda, Q11 ) ); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda, Q11 ) ); // Q_old_wtda } } FOR( Word16 ind1 = 0; ind1 < 2; ind1++ ) @@ -161,7 +162,7 @@ ivas_error ivas_cpe_dec_fx( test(); IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB, Q11 ) ); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB, Q11 ) ); // Q_old_wtda } } @@ -294,17 +295,17 @@ ivas_error ivas_cpe_dec_fx( test(); IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - IF( EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) + IF( ivas_total_brate == FRAME_NO_DATA ) { hCPE->hCoreCoder[n]->core_brate = ivas_total_brate; - move16(); + move32(); hCPE->hCoreCoder[0]->total_brate = ivas_total_brate; - move16(); + move32(); } ELSE { hCPE->hCoreCoder[n]->core_brate = SID_2k40; - move16(); + move32(); } } @@ -369,7 +370,7 @@ ivas_error ivas_cpe_dec_fx( } /* subtract metadata bitbudget */ - sts[0]->total_brate = L_sub( sts[0]->total_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); + sts[0]->total_brate = L_sub( sts[0]->total_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); // Q0 move32(); /* subtract bit-rate for combined format coding */ @@ -519,12 +520,13 @@ ivas_error ivas_cpe_dec_fx( IF( hCPE->hStereoTD != NULL ) { sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->total_brate, n, hCPE->hStereoTD->tdm_LRTD_flag, sts[n]->bwidth, sts[n]->cng_type ); + move16(); } ELSE { sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->total_brate, n, 0, sts[n]->bwidth, sts[n]->cng_type ); + move16(); } - move16(); } FOR( n = 0; n < n_channels; n++ ) @@ -614,7 +616,7 @@ ivas_error ivas_cpe_dec_fx( test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && !( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) ) { - Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX]; + Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX]; // q_dft set32_fx( DFT_fx[0], 0, STEREO_DFT_BUF_MAX ); set32_fx( DFT_fx[1], 0, STEREO_DFT_BUF_MAX ); @@ -657,8 +659,8 @@ ivas_error ivas_cpe_dec_fx( IF( GT_16( shift, hCPE->hStereoDft->q_dft ) ) { - Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); - Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); + Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); // shift + Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); // shift hCPE->hStereoDft->q_dft = shift; move16(); } @@ -679,13 +681,13 @@ ivas_error ivas_cpe_dec_fx( q = Q11; move16(); - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), negate( Q10 ) ); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, ( ( 2 * NB_SUBFR16k ) + 2 ), -( Q10 ) ); // Q16->Q6 stereo_dft_dec_res_fx( hCPE, res_buf_fx, q_res_buf, output[1] ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), 10 ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, ( ( 2 * NB_SUBFR16k ) + 2 ), 10 ); // Q6->Q16 - Scale_sig32( output[1], L_FRAME8k, sub( Q11, Q15 ) ); // Q15 -> Q11 + Scale_sig32( output[1], L_FRAME8k, ( Q11 - Q15 ) ); // Q15 -> Q11 q_out_DFT[0] = q_out_DFT[1] = hCPE->hStereoDft->q_dft; move16(); @@ -693,7 +695,7 @@ ivas_error ivas_cpe_dec_fx( stereo_dft_dec_analyze_fx( hCPE, output[1], DFT_fx, 1, L_FRAME8k, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, &q, q_out_DFT ); - Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_out_DFT[1] ) ); + Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_out_DFT[1] ) ); // q_dft } /* DFT stereo CNG */ @@ -713,7 +715,7 @@ ivas_error ivas_cpe_dec_fx( { hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft; move16(); - FOR( int ii = 0; ii < (int) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ ) + FOR( Word16 ii = 0; ii < (Word16) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ ) { hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft; move16(); @@ -722,11 +724,11 @@ ivas_error ivas_cpe_dec_fx( move16(); } - scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); + scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // q_dft hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft; move16(); stereo_dft_unify_dmx_fx( hCPE->hStereoDft, sts[0], DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng->prev_sid_nodata ); - scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q16, hCPE->hStereoDft->q_res_cod_mem_fx ) ); + scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q16, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // Q16 hCPE->hStereoDft->q_res_cod_mem_fx = Q16; move16(); } @@ -737,7 +739,7 @@ ivas_error ivas_cpe_dec_fx( { hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft; move16(); - FOR( int ii = 0; ii < (int) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ ) + FOR( Word16 ii = 0; ii < (Word16) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ ) { hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft; move16(); @@ -746,20 +748,20 @@ ivas_error ivas_cpe_dec_fx( move16(); } - scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); + scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // q_dft hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft; move16(); } stereo_dft_dec_fx( hCPE->hStereoDft, sts[0], DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng, 0, 0, 0, 0, 0, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); - scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q16, hCPE->hStereoDft->q_res_cod_mem_fx ) ); + scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q16, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // Q16 hCPE->hStereoDft->q_res_cod_mem_fx = Q16; move16(); } FOR( n = 0; n < hCPE->nchan_out; n++ ) { - Scale_sig32( output[n], L_FRAME48k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); - scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + Scale_sig32( output[n], L_FRAME48k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft + scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft hCPE->q_output_mem_fx[n] = hCPE->hStereoDft->q_dft; move16(); } @@ -773,8 +775,8 @@ ivas_error ivas_cpe_dec_fx( // delete below FOR( n = 0; n < hCPE->nchan_out; n++ ) { - Scale_sig32( output[n], L_FRAME48k, sub( Q11, hCPE->hStereoDft->q_dft ) ); - scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + Scale_sig32( output[n], L_FRAME48k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 + scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 hCPE->q_output_mem_fx[n] = Q11; move16(); } @@ -782,7 +784,7 @@ ivas_error ivas_cpe_dec_fx( ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { test(); - IF( NE_16( hCPE->last_element_mode, IVAS_CPE_TD ) && sts[0]->tdm_LRTD_flag ) + if ( NE_16( hCPE->last_element_mode, IVAS_CPE_TD ) && sts[0]->tdm_LRTD_flag ) { hCPE->hStereoTD->tdm_last_ratio_idx = tdm_ratio_idx; move16(); @@ -970,7 +972,7 @@ ivas_error create_cpe_dec( test(); test(); test(); - IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && ( EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) + IF( EQ_16( extract_l( st_ivas->ivas_format ), MASA_ISM_FORMAT ) && ( EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) { cpe_brate = element_brate; move32(); @@ -1079,7 +1081,7 @@ ivas_error create_cpe_dec( FOR( n = 0; n < CPE_CHANNELS; n++ ) { - if ( st_ivas->sba_dirac_stereo_flag && EQ_16( st_ivas->nchan_transport, 1 ) ) + IF( st_ivas->sba_dirac_stereo_flag && EQ_16( st_ivas->nchan_transport, 1 ) ) { /* for SBA DirAC stereo output CPE element is only used for upmix, core coder is found in SCE element used for core decoding */ BREAK; @@ -1102,7 +1104,7 @@ ivas_error create_cpe_dec( st->ivas_format = st_ivas->ivas_format; move32(); - if ( NE_32( ( error = init_decoder_ivas_fx( st, n, st_ivas->mc_mode ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = init_decoder_ivas_fx( st, n, st_ivas->mc_mode ) ), IVAS_ERR_OK ) ) { return error; } @@ -1114,7 +1116,7 @@ ivas_error create_cpe_dec( * DFT stereo initialization *-----------------------------------------------------------------*/ - test(); + test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || ( st_ivas->sba_dirac_stereo_flag && hCPE->cpe_id == 0 ) ) { diff --git a/lib_dec/ivas_decision_matrix_dec.c b/lib_dec/ivas_decision_matrix_dec.c index 0a4e950f60b131f3a16800874e264e9c5f3f3f69..ec8de49005bd26ea995056424d96c2e58695d038 100644 --- a/lib_dec/ivas_decision_matrix_dec.c +++ b/lib_dec/ivas_decision_matrix_dec.c @@ -514,7 +514,7 @@ void ivas_decision_matrix_dec_fx( test(); test(); test(); - IF( ( st->idchan == 0 && ( EQ_32( st->total_brate, FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->total_brate, SID_2k40 ) ) ) + IF( ( st->idchan == 0 && ( ( st->total_brate == FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->total_brate, SID_2k40 ) ) ) { st->core = ACELP_CORE; move16(); @@ -578,7 +578,7 @@ void ivas_decision_matrix_dec_fx( test(); test(); test(); - if ( EQ_32( st->total_brate, FRAME_NO_DATA ) && st->prev_bfi && !st->bfi && GT_16( st->L_frame, L_FRAME16k ) ) + if ( ( st->total_brate == FRAME_NO_DATA ) && st->prev_bfi && !st->bfi && GT_16( st->L_frame, L_FRAME16k ) ) { st->L_frame = st->last_CNG_L_frame; move16(); @@ -654,6 +654,7 @@ void ivas_decision_matrix_dec_fx( { *sharpFlag = 0; move16(); + test(); if ( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) ) { *sharpFlag = 1; @@ -678,6 +679,7 @@ void ivas_decision_matrix_dec_fx( IF( LT_32( element_brate, FRMT_SHP_MIN_BRATE_IVAS ) ) { st->coder_type = get_next_indice_fx( st, 3 ); + move16(); *sharpFlag = 0; move16(); @@ -694,9 +696,10 @@ void ivas_decision_matrix_dec_fx( { /* get coder_type info */ st->coder_type = get_next_indice_fx( st, 3 ); - + move16(); /* get sharpening flag */ *sharpFlag = get_next_indice_fx( st, 1 ); + move16(); } } } @@ -785,7 +788,7 @@ void ivas_decision_matrix_dec_fx( ELSE { st->extl = SWB_TBE; - move32(); + move16(); st->extl_brate = SWB_TBE_1k6; move32(); test(); @@ -878,7 +881,7 @@ void ivas_decision_matrix_dec_fx( test(); test(); test(); - if ( GE_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( st->core, ACELP_CORE ) && ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) + if ( GE_16( st->element_mode, IVAS_CPE_DFT ) && ( st->core == ACELP_CORE ) && ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) { icbwe_brate = L_add( icbwe_brate, STEREO_ICBWE_MSFLAG_BITS * FRAMES_PER_SEC ); } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index a127cd1a4d0a5dbc2b29d10ff335650ab3d451f6..155e03a17b9521a0966e70000514120d3e86b742 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -278,6 +278,7 @@ static ivas_error ivas_dirac_rend_config_fx( IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { st_ivas->nchan_transport = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + move16(); } nchan_transport = st_ivas->nchan_transport; @@ -312,7 +313,7 @@ static ivas_error ivas_dirac_rend_config_fx( Copy32( hDirACRend->hOutSetup.ls_elevation_fx, ls_elevation_fx, nchan_out_woLFE ); } - IF( EQ_16( hDirACRend->hOutSetup.ambisonics_order, negate( (Word16) 1 ) ) ) + IF( EQ_16( hDirACRend->hOutSetup.ambisonics_order, -1 ) ) { hDirACRend->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */ move16(); @@ -340,6 +341,7 @@ static ivas_error ivas_dirac_rend_config_fx( { /* Remove the channel of the separated signal from the output setup of the spatial synthesis */ hDirACRend->hOutSetup.nchan_out_woLFE = sub( hDirACRend->hOutSetup.nchan_out_woLFE, 1 ); + move16(); nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE; move16(); Copy32( &ls_azimuth_fx[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_azimuth_fx[hDirACRend->hOutSetup.separateChannelIndex], sub( nchan_out_woLFE, hDirACRend->hOutSetup.separateChannelIndex ) ); @@ -470,7 +472,9 @@ static ivas_error ivas_dirac_rend_config_fx( /* Directional and diffuses components in SHD */ /* Diffuseness components up to 1st order */ hDirACRend->num_outputs_diff = mult0( ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ), ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ) ); + move16(); hDirACRend->num_outputs_dir = ivas_sba_get_nchan_fx( hDirACRend->hOutSetup.ambisonics_order, 0 ); + move16(); } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) { @@ -893,7 +897,7 @@ static ivas_error ivas_dirac_rend_config_fx( } test(); - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0; move16(); @@ -934,6 +938,7 @@ static ivas_error ivas_dirac_rend_config_fx( } } hDirACRend->proto_frame_f_len = imult1616( 2, imult1616( hDirACRend->num_protos_diff, hSpatParamRendCom->num_freq_bands ) ); + move16(); } if ( EQ_16( flag_config, DIRAC_OPEN ) ) @@ -975,12 +980,13 @@ static ivas_error ivas_dirac_rend_config_fx( set32_fx( hDirACRend->buffer_energy_fx, 0, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); set16_fx( hDirACRend->q_buffer_energy, Q31, DIRAC_NO_COL_AVG_DIFF ); } - ELSE IF( ( EQ_16( flag_config, DIRAC_OPEN ) && EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) && EQ_16( dec_param_estim_old, TRUE ) ) ) ) + ELSE IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == FALSE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( ( hDirAC->hConfig->dec_param_estim == FALSE ) && EQ_16( dec_param_estim_old, TRUE ) ) ) ) { FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { + test(); IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->buffer_intensity_real_fx[i][j] ) { free( hDirACRend->buffer_intensity_real_fx[i][j] ); @@ -1702,7 +1708,7 @@ ivas_error ivas_dirac_dec_config_fx( move16(); test(); test(); - IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && !hodirac_flag ) + if ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && !hodirac_flag ) { sparfoa_flag = 1; move16(); @@ -1829,7 +1835,7 @@ ivas_error ivas_dirac_dec_config_fx( /* This is required to keep BE in rate switching. This probably means that 1TC and 2TC MASA perform differently. */ test(); test(); - IF( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params != NULL && !( st_ivas->ivas_format == MASA_FORMAT && st_ivas->nSCE > 0 ) ) + IF( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params != NULL && !( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && st_ivas->nSCE > 0 ) ) { ivas_dirac_dec_decorr_close_fx( &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params, &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ); // done } @@ -2029,7 +2035,7 @@ ivas_error ivas_dirac_dec_config( * * Close DirAC memories *------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_dirac_dec_close( DIRAC_DEC_HANDLE *hDirAC_out ) { @@ -2055,7 +2061,7 @@ void ivas_dirac_dec_close( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_dirac_dec_close_fx( DIRAC_DEC_HANDLE *hDirAC_out ) { @@ -2112,6 +2118,7 @@ void ivas_dirac_dec_read_BS_fx( move16(); iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); st->next_bit_pos = extract_l( L_sub( quo, 1 ) ); + move16(); if ( last_bit_pos > 0 ) { st->next_bit_pos = last_bit_pos; @@ -2155,7 +2162,7 @@ void ivas_dirac_dec_read_BS_fx( } FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - FOR( j = sub( orig_dirac_bands, 2 ); j >= 0; j-- ) + FOR( j = ( orig_dirac_bands - 2 ); j >= 0; j-- ) { hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0]; move32(); @@ -2239,7 +2246,7 @@ void ivas_dirac_dec_read_BS_fx( } FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - FOR( j = sub( orig_dirac_bands, 2 ); j >= 0; j-- ) + FOR( j = ( orig_dirac_bands - 2 ); j >= 0; j-- ) { hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0]; move32(); @@ -2421,7 +2428,7 @@ void ivas_qmetadata_to_dirac_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ const Word16 hodirac_flag, /* i : flag to indicate HO-DirAC mode */ - Word16 *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ + Word16 *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands Q0*/ ) { Word16 block, band; @@ -2435,16 +2442,20 @@ void ivas_qmetadata_to_dirac_fx( Word16 *band_grouping; Word16 start_band; Word16 nbands = 0; + move16(); Word16 nblocks = 0; + move16(); Word16 qBand_idx; Word16 idx_sec = 0; + move16(); Word16 no_secs = 1; + move16(); q_direction = &( hQMetaData->q_direction[0] ); hSpatParamRendCom->numParametricDirections = hQMetaData->no_directions; move16(); hSpatParamRendCom->numSimultaneousDirections = add( hSpatParamRendCom->numParametricDirections, hSpatParamRendCom->numIsmDirections ); - + move16(); test(); IF( hMasa != NULL && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { @@ -2642,7 +2653,6 @@ void ivas_qmetadata_to_dirac_fx( move16(); tmp_write_idx_band = add( tmp_write_idx_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length; - move16(); } } } @@ -2668,7 +2678,6 @@ void ivas_qmetadata_to_dirac_fx( IF( EQ_32( ivas_format, SBA_FORMAT ) ) { qBand_idx = sub( dirac_to_spar_md_bands[band], start_band ); - move16(); } ELSE { @@ -2740,14 +2749,13 @@ void ivas_qmetadata_to_dirac_fx( Word16 exp_factor = 0; move16(); a = rand_triangular_signed_fx( seed_ptr, &exp_factor ); // q = exp_factor - move16(); + tmp1 = mult( a, dirac_dithering_azi_scale_fx[diff_idx] ); // exp_factor + 5 Word32 tmp1_32 = L_deposit_h( tmp1 ); Word16 final_1_exp; Word32 final_1_32 = BASOP_Util_Add_Mant32Exp( azimuth_fx, 9, tmp1_32, exp_factor + 5, &final_1_exp ); - b_tmp = rand_triangular_signed_fx( seed_ptr, &exp_factor ); // q = exp_factor - move16(); + b_tmp = rand_triangular_signed_fx( seed_ptr, &exp_factor ); // q = exp_factor tmp4 = mult( b_tmp, dirac_dithering_ele_scale_fx[diff_idx] ); // exp_factor + 4 Word32 tmp4_32 = L_deposit_h( tmp4 ); @@ -2758,8 +2766,8 @@ void ivas_qmetadata_to_dirac_fx( final_1_32 = BASOP_Util_Add_Mant32Exp( final_1_32, final_1_exp, ONE_IN_Q30, 0, &final_1_exp ); /*0.5 in q31*/ final_2_32 = BASOP_Util_Add_Mant32Exp( final_2_32, final_2_exp, ONE_IN_Q30, 0, &final_2_exp ); - azi = extract_h( L_shr( final_1_32, 31 - final_1_exp - 16 ) ); - ele = extract_h( L_shr( final_2_32, 31 - final_2_exp - 16 ) ); + azi = extract_h( L_shr( final_1_32, sub( sub( 31, final_1_exp ), 16 ) ) ); + ele = extract_h( L_shr( final_2_32, sub( sub( 31, final_2_exp ), 16 ) ) ); /*addition of one to compensate precision loss*/ if ( azi < 0 ) @@ -2836,7 +2844,7 @@ void ivas_qmetadata_to_dirac_fx( } } tmp_write_idx_param_band = add( tmp_write_idx_param_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length; - move16(); + } /* for ( block =...) */ } /* for ( band = ...) */ @@ -2875,7 +2883,7 @@ void ivas_qmetadata_to_dirac_fx( } /* update buffer write index */ hSpatParamRendCom->dirac_bs_md_write_idx = add( hSpatParamRendCom->dirac_bs_md_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; - + move16(); return; } #else @@ -3296,6 +3304,7 @@ void ivas_dirac_dec_set_md_map( } iDiv_and_mod_32( W_extract_l( W_shl_nosat( tmp_fx, 16 ) ), hSpatParamRendCom->subframe_nbslots[sf_idx], &quo, &rem, 0 ); hSpatParamRendCom->render_to_md_map[sf_idx] = add( round_fx( quo ), hSpatParamRendCom->dirac_read_idx ) % hSpatParamRendCom->dirac_md_buffer_length; + move16(); } set16_fx( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, sub( MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->nb_subframes ) ); @@ -3458,15 +3467,12 @@ void ivas_dirac_dec_set_md_map_fx( norm_num = norm_l( tmp_fx ); num = L_shl( tmp_fx, norm_num ); exp_num = sub( exp_num, norm_num ); - move16(); norm_denom = norm_s( hSpatParamRendCom->subframe_nbslots[sf_idx] ); denom = shl( hSpatParamRendCom->subframe_nbslots[sf_idx], norm_denom ); exp_denom = sub( exp_denom, norm_denom ); - move16(); exp = sub( exp_num, exp_denom ); - move16(); IF( GT_32( num, L_deposit_l( denom ) ) ) { @@ -3478,7 +3484,7 @@ void ivas_dirac_dec_set_md_map_fx( ans_fix_32 = BASOP_Util_Add_Mant32Exp( ans, exp, L_deposit_h( hSpatParamRendCom->dirac_read_idx ), 15 /*31 - 16*/, &exp_final ); ans_fix_16 = round_fx( L_shr( ans_fix_32, sub( sub( Q31, exp_final ), Q16 ) ) ); - hSpatParamRendCom->render_to_md_map[sf_idx] = ans_fix_16 % hSpatParamRendCom->dirac_md_buffer_length; + hSpatParamRendCom->render_to_md_map[sf_idx] = ans_fix_16 % hSpatParamRendCom->dirac_md_buffer_length; // Q0 move16(); } set16_fx( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, sub( MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->nb_subframes ) ); @@ -3500,7 +3506,7 @@ void ivas_dirac_dec_render_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *output_fx[] /* o : rendered time signal */ + Word32 *output_fx[] /* o : rendered time signal Q(6-1)*/ ) { Word16 slots_to_render, first_sf, last_sf, subframe_idx; @@ -3520,7 +3526,7 @@ void ivas_dirac_dec_render_fx( set_zero_fx( output_f_local_fx[ch], nSamplesAsked ); } slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // cL - move16(); + /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ slots_to_render = s_min( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) ); @@ -3537,7 +3543,6 @@ void ivas_dirac_dec_render_fx( { slots_to_render = sub( slots_to_render, hSpatParamRendCom->subframe_nbslots[last_sf] ); last_sf = add( last_sf, 1 ); - move16(); } FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) @@ -3563,7 +3568,7 @@ void ivas_dirac_dec_render_fx( { test(); test(); - IF( !( L_and( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ), ( L_or( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ), EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) ) ) ) + IF( !( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ) && ( ( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ) || EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) ) ) { Copy32( output_f_local_buff_fx[ch], output_fx[ch], *nSamplesRendered ); } @@ -3572,16 +3577,16 @@ void ivas_dirac_dec_render_fx( IF( EQ_16( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->num_slots ) ){ IF( EQ_16( st_ivas->hDirAC->hConfig->dec_param_estim, 1 ) ){ temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_CLDFB_TIMESLOTS ); - hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); + hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); // Q0 } ELSE { temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS ); - hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); + hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); // Q0 } } -*nSamplesAvailableNext = i_mult( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), slot_size ); +*nSamplesAvailableNext = i_mult( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), slot_size ); // Q0 move16(); return; @@ -3677,11 +3682,12 @@ void ivas_dirac_dec_render( *------------------------------------------------------------------------*/ void ivas_dirac_dec_render_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_buf_fx[], /* i/o: synthesized core-coder transport channels/DirAC output */ - const Word16 nchan_transport, /* i : number of transport channels */ - Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], - Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] ) + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output_buf_fx[], /* i/o: synthesized core-coder transport channels/DirAC output Q(6-1)*/ + const Word16 nchan_transport, /* i : number of transport channels */ + Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], /*Q6*/ + Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] /*Q6*/ +) { Word16 i, ch, idx_in, idx_lfe; DIRAC_DEC_HANDLE hDirAC; @@ -3785,15 +3791,16 @@ void ivas_dirac_dec_render_sf_fx( } test(); - IF( L_or( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ), EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) ) + IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) ) { IF( hDirACRend->h_output_synthesis_psd_params.max_band_decorr != 0 ) { DIRAC_OUTPUT_SYNTHESIS_STATE *state = &( hDirACRend->h_output_synthesis_psd_state ); tmp1 = L_norm_arr( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len ); - scale_sig32( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len, tmp1 ); + scale_sig32( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len, tmp1 ); // Q(proto_power_diff_smooth_q + tmp1) state->proto_power_diff_smooth_q = add( state->proto_power_diff_smooth_q, tmp1 ); + move16(); } } @@ -3813,7 +3820,7 @@ void ivas_dirac_dec_render_sf_fx( IF( h_dirac_output_synthesis_params->use_onset_filters && ( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) { tmp1 = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( tmp1, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( tmp1, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); // tmp1 h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = tmp1; move16(); } @@ -3823,18 +3830,20 @@ void ivas_dirac_dec_render_sf_fx( { Word16 shift; shift = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth + shift h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, shift ); - + move16(); shift = L_norm_arr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); + scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth + shift h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, shift ); - + move16(); tmp1 = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth + tmp1 h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, tmp1 ); + move16(); } + test(); test(); IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) @@ -3845,7 +3854,7 @@ void ivas_dirac_dec_render_sf_fx( move16(); } } - ELSE IF( !L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) + ELSE IF( !( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) { Word16 outchannels; idx_lfe = 0; @@ -3877,7 +3886,7 @@ void ivas_dirac_dec_render_sf_fx( FOR( ch = 0; ch < outchannels; ch++ ) { test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { @@ -3890,10 +3899,12 @@ void ivas_dirac_dec_render_sf_fx( { FOR( ch = 0; ch < outchannels; ch++ ) { + test(); test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { + test(); IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled ) { Word16 cldfbSynIdx; @@ -3925,7 +3936,7 @@ void ivas_dirac_dec_render_sf_fx( size_ho = size; move16(); } - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); // Q26 hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26; move16(); @@ -3933,49 +3944,51 @@ void ivas_dirac_dec_render_sf_fx( { Word16 shift; shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, shift ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, shift ); // Q(hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth + shift) hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, shift ); + move16(); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); // Q26 hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26; move16(); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); // Q26 hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = Q26; move16(); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); // Q26 hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = Q26; move16(); } ELSE { Word16 shift; - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); // Q26 hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26; move16(); shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho, shift ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho, shift ); // Q( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev+ shift) hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, shift ); - + move16(); shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, shift ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, shift ); // Q(hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev + shift) hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, shift ); - + move16(); tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); // Q(hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev+ tmp1) hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, tmp1 ); - + move16(); tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q tmp1) hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, tmp1 ); - + move16(); IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 ) { tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, imult1616( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, imult1616( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, imult1616( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q+ tmp1) hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, tmp1 ); + move16(); } } @@ -4001,7 +4014,7 @@ void ivas_dirac_dec_render_sf_fx( subframe_idx = hSpatParamRendCom->subframes_rendered; move16(); - IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) ) { md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; move16(); @@ -4013,7 +4026,7 @@ void ivas_dirac_dec_render_sf_fx( } /* copy parameters into local buffers*/ - IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) ) { Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands ); q_diffuseness_vector = Q30; @@ -4028,7 +4041,7 @@ void ivas_dirac_dec_render_sf_fx( move16(); } - IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { set_zero_fx( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands ); } @@ -4046,7 +4059,7 @@ void ivas_dirac_dec_render_sf_fx( { num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; move16(); - IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) ) { rotateAziEle_DirAC_fx( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat_fx ); } @@ -4055,13 +4068,14 @@ void ivas_dirac_dec_render_sf_fx( ELSE { p_Rmat_fx = 0; + move32(); } - IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) ) { Word16 *masa_band_mapping; /* compute response */ - IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { ivas_dirac_dec_compute_power_factors_fx( hSpatParamRendCom->num_freq_bands, diffuseness_vector_fx, @@ -4089,7 +4103,7 @@ void ivas_dirac_dec_render_sf_fx( surCohRatio_fx[i] = BASOP_Util_Divide3232_Scale( surCohEner_fx, ( L_add( EPSILLON_FX, L_add( dirEne_fx, surCohEner_fx ) ) ), &temp_q ); move32(); - surCohRatio_fx[i] = L_shl( surCohRatio_fx[i], temp_q ); + surCohRatio_fx[i] = L_shl( surCohRatio_fx[i], temp_q ); // Q31 move32(); } } @@ -4114,13 +4128,16 @@ void ivas_dirac_dec_render_sf_fx( &max_exp_direct, &max_exp_diffusion ); hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = sub( Q31, max_exp_direct ); + move16(); hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = sub( Q31, max_exp_diffusion ); + move16(); IF( coherence_flag ) { FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { surCohRatio_fx[i] = L_deposit_l( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); + move32(); } } ELSE @@ -4176,7 +4193,7 @@ void ivas_dirac_dec_render_sf_fx( } test(); - IF( L_and( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ), EQ_16( nchan_transport, 2 ) ) ) + IF( ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( nchan_transport, 2 ) ) ) { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { @@ -4198,7 +4215,7 @@ void ivas_dirac_dec_render_sf_fx( } test(); - IF( L_and( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ), NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) + IF( ( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) { ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( st_ivas, Cldfb_RealBuffer_Temp_fx, Cldfb_ImagBuffer_Temp_fx, &cldfb_buf_q, hSpatParamRendCom->num_freq_bands, subframe_idx ); } @@ -4219,7 +4236,7 @@ void ivas_dirac_dec_render_sf_fx( } test(); test(); - IF( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) + IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) { FOR( ch = 0; ch < nchan_transport; ch++ ) { @@ -4229,7 +4246,7 @@ void ivas_dirac_dec_render_sf_fx( q_cldfb = Q6; move16(); } - ELSE IF( L_and( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ), EQ_16( nchan_transport, 2 ) ) ) + ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( nchan_transport, 2 ) ) ) { FOR( ch = 0; ch < nchan_transport; ch++ ) { @@ -4260,13 +4277,16 @@ void ivas_dirac_dec_render_sf_fx( test(); test(); test(); - IF( EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && !( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && !( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) ) { Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; Word16 Q_input = Q11; move16(); q_temp_cldfb = Q11; move16(); + test(); + test(); + test(); generate_masking_noise_dirac_ivas_fx( st->hFdCngDec->hFdCngCom, st_ivas->cldfbAnaDec[1], st_ivas->hTcBuffer->tc_fx[1], @@ -4274,9 +4294,9 @@ void ivas_dirac_dec_render_sf_fx( Cldfb_ImagBuffer_fx[1][0], index_slot, st->cna_dirac_flag && st->flag_cna, - ( L_or( EQ_32( st->core_brate, FRAME_NO_DATA ), EQ_32( st->core_brate, SID_2k40 ) ) ) && EQ_16( st->cng_type, FD_CNG ) && st->cng_sba_flag, Q_input, &q_temp_cldfb ); - Scale_sig32( Cldfb_RealBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); - Scale_sig32( Cldfb_ImagBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); + ( ( ( st->core_brate == FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) ) && EQ_16( st->cng_type, FD_CNG ) && st->cng_sba_flag, Q_input, &q_temp_cldfb ); + Scale_sig32( Cldfb_RealBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); // Q6 + Scale_sig32( Cldfb_ImagBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); // Q6 } /* LFE synthesis */ @@ -4450,6 +4470,7 @@ void ivas_dirac_dec_render_sf_fx( ELSE { hDirACRend->index_buffer_intensity = add( sub( hDirACRend->index_buffer_intensity, i_mult( idiv1616( hDirACRend->index_buffer_intensity, DIRAC_NO_COL_AVG_DIFF ), DIRAC_NO_COL_AVG_DIFF ) ), 1 ); /* averaging_length = 32 */ + move16(); } index = hDirACRend->index_buffer_intensity; @@ -4494,7 +4515,7 @@ void ivas_dirac_dec_render_sf_fx( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, hDirACRend->num_protos_diff, hDirACRend->proto_index_diff, - &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx[add( imult1616( imult1616( imult1616( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), hDirACRend->num_outputs_diff ), imult1616( imult1616( 2, hSpatParamRendCom->num_freq_bands ), s_min( 4, nchan_transport ) ) )], + &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx[( ( ( slot_idx * 2 ) * hSpatParamRendCom->num_freq_bands ) * hDirACRend->num_outputs_diff ) + ( ( 2 * hSpatParamRendCom->num_freq_bands ) * s_min( 4, nchan_transport ) )], &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, onset_filter_fx, hDirACRend->h_freq_domain_decorr_ap_params, @@ -4508,8 +4529,9 @@ void ivas_dirac_dec_render_sf_fx( ELSE { scale = L_norm_arr( hDirACRend->proto_frame_f_fx, proto_length ); - Scale_sig32( hDirACRend->proto_frame_f_fx, proto_length, scale ); + Scale_sig32( hDirACRend->proto_frame_f_fx, proto_length, scale ); // Q(proto_frame_f_q+scale) hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, scale ); + move16(); ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, hDirACRend->num_protos_diff, @@ -4556,7 +4578,7 @@ void ivas_dirac_dec_render_sf_fx( * output synthesis *-----------------------------------------------------------------*/ test(); - IF( L_or( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ), EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) ) + IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) ) { DIRAC_OUTPUT_SYNTHESIS_STATE *state; Word16 diffuse_start; @@ -4564,13 +4586,13 @@ void ivas_dirac_dec_render_sf_fx( diffuse_start = i_mult( i_mult( slot_idx, 2 ), i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) ); exp = getScaleFactor32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len ); - scale_sig32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len, exp ); + scale_sig32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len, exp ); // hDirACRend->proto_frame_dec_f_q + exp hDirACRend->proto_frame_dec_f_q = add( hDirACRend->proto_frame_dec_f_q, exp ); - + move16(); exp = getScaleFactor32( state->proto_diffuse_buffer_f_fx, diffuse_start ); - scale_sig32( state->proto_diffuse_buffer_f_fx, diffuse_start, exp ); + scale_sig32( state->proto_diffuse_buffer_f_fx, diffuse_start, exp ); // state->proto_diffuse_buffer_f_q + exp state->proto_diffuse_buffer_f_q = add( state->proto_diffuse_buffer_f_q, exp ); - + move16(); /*Compute diffuse prototypes*/ ivas_dirac_dec_compute_diffuse_proto_fx( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx ); } @@ -4589,47 +4611,49 @@ void ivas_dirac_dec_render_sf_fx( test(); test(); - IF( L_and( h_dirac_output_synthesis_params->use_onset_filters, L_and( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ), NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) ) + IF( ( h_dirac_output_synthesis_params->use_onset_filters && ( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) ) { - Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); + Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); // Q31 h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31; move16(); exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_diff_smooth + exp h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp ); + move16(); } test(); - IF( L_and( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ), NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) + IF( ( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) { - scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->direct_power_factor_q ) ); + scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->direct_power_factor_q ) ); // Q31 h_dirac_output_synthesis_state->direct_power_factor_q = Q31; move16(); - scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); + scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); // Q31 h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31; move16(); - scale_sig32( h_dirac_output_synthesis_state->direct_responses_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, h_dirac_output_synthesis_state->direct_responses_q ) ); + scale_sig32( h_dirac_output_synthesis_state->direct_responses_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, h_dirac_output_synthesis_state->direct_responses_q ) ); // Q31 h_dirac_output_synthesis_state->direct_responses_q = Q31; move16(); - scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); + scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); // Q31 h_dirac_output_synthesis_state->direct_responses_square_q = Q31; move16(); exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, exp h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, exp ); - + move16(); exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); + scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth+ exp h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, exp ); - + move16(); exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_diff_smooth+ exp h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp ); + move16(); } test(); @@ -4685,13 +4709,13 @@ void ivas_dirac_dec_render_sf_fx( IF( LT_16( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) ) { - scale_sig32( hSpatParamRendCom->diffuseness_vector_fx[md_idx], hSpatParamRendCom->num_freq_bands, sub( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) ); + scale_sig32( hSpatParamRendCom->diffuseness_vector_fx[md_idx], hSpatParamRendCom->num_freq_bands, sub( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) ); // q_diffuseness_vector hSpatParamRendCom->q_diffuseness_vector = q_diffuseness_vector; move16(); } ELSE { - scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( hSpatParamRendCom->q_diffuseness_vector, q_diffuseness_vector ) ); + scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( hSpatParamRendCom->q_diffuseness_vector, q_diffuseness_vector ) ); // q_diffuseness_vector q_diffuseness_vector = hSpatParamRendCom->q_diffuseness_vector; move16(); } @@ -4702,13 +4726,13 @@ void ivas_dirac_dec_render_sf_fx( { IF( LT_16( q_reference_power_smooth, DirAC_mem.reference_power_q ) ) { - scale_sig32( reference_power_fx, hSpatParamRendCom->num_freq_bands, sub( q_reference_power_smooth, DirAC_mem.reference_power_q ) ); + scale_sig32( reference_power_fx, hSpatParamRendCom->num_freq_bands, sub( q_reference_power_smooth, DirAC_mem.reference_power_q ) ); // q_reference_power_smooth DirAC_mem.reference_power_q = q_reference_power_smooth; move16(); } ELSE { - scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_q, q_reference_power_smooth ) ); + scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_q, q_reference_power_smooth ) ); // reference_power_q q_reference_power_smooth = DirAC_mem.reference_power_q; move16(); } @@ -4728,17 +4752,17 @@ void ivas_dirac_dec_render_sf_fx( { offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, nchan_transport ) ); buff_len = i_mult( 2, i_mult( nchan_transport, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ); - buff_len = 2 * hDirACRend->num_outputs_diff * hSpatParamRendCom->num_freq_bands; - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, q_proto_diffuse_buffer[slot_idx] ) ); + buff_len = i_mult( 2, i_mult( hDirACRend->num_outputs_diff, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, q_proto_diffuse_buffer[slot_idx] ) ); // proto_diffuse_buffer_f_q } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { offset = i_mult( slot_idx, i_mult( 4, hSpatParamRendCom->num_freq_bands ) ); buff_len = i_mult( 4, hSpatParamRendCom->num_freq_bands ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q } ELSE { @@ -4750,7 +4774,7 @@ void ivas_dirac_dec_render_sf_fx( case 4: offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ); buff_len = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q BREAK; case 2: IF( hDirACRend->hOutSetup.is_loudspeaker_setup ) @@ -4763,16 +4787,17 @@ void ivas_dirac_dec_render_sf_fx( offset = i_mult( i_mult( i_mult( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), 2 ); buff_len = i_mult( 4, hSpatParamRendCom->num_freq_bands ); } - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q BREAK; case 1: offset = i_mult( slot_idx, i_mult( 2, hSpatParamRendCom->num_freq_bands ) ); buff_len = i_mult( 2, hSpatParamRendCom->num_freq_bands ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q BREAK; } } q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; + move16(); } ivas_dirac_dec_output_synthesis_get_interpolator_fx( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); @@ -4792,44 +4817,45 @@ void ivas_dirac_dec_render_sf_fx( { IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, Q26 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth ) ); // Q26 hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = Q26; + move16(); } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); // Q26 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size_ho, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size_ho, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); // Q26 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); // Q26 } IF( NE_16( q_diffuseness_vector, Q30 ) ) { - scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q30, q_diffuseness_vector ) ); + scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q30, q_diffuseness_vector ) ); // Q30 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); // Q26 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); // Q26 } ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( Cldfb_RealBuffer_fx, @@ -4852,8 +4878,8 @@ void ivas_dirac_dec_render_sf_fx( { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); - scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); + scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6 + scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6 } } } @@ -4863,8 +4889,8 @@ void ivas_dirac_dec_render_sf_fx( { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); - scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); + scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6 + scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6 } } } @@ -4884,37 +4910,37 @@ void ivas_dirac_dec_render_sf_fx( IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); // Q31 } IF( NE_16( q_diffuseness_vector, Q31 ) ) { - Scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q31, q_diffuseness_vector ) ); + Scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q31, q_diffuseness_vector ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, i_mult( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, i_mult( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q ) ); // Q31 } exp = L_norm_arr( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands ); - scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, exp ); + scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, exp ); // q_reference_power_smooth + exp q_reference_power_smooth = add( q_reference_power_smooth, exp ); IF( LT_16( q_reference_power_smooth, hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx, hSpatParamRendCom->num_freq_bands, sub( q_reference_power_smooth, hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx, hSpatParamRendCom->num_freq_bands, sub( q_reference_power_smooth, hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q ) ); // q_reference_power_smooth hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q = q_reference_power_smooth; move16(); } ELSE { - scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, sub( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, q_reference_power_smooth ) ); + scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, sub( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, q_reference_power_smooth ) ); // reference_power_smooth_prev_q q_reference_power_smooth = hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q; move16(); } @@ -4923,49 +4949,52 @@ void ivas_dirac_dec_render_sf_fx( { IF( LT_16( hDirACRend->masa_stereo_type_detect->q_subtract_power_y, hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) ) { - hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx = L_shr( hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, sub( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ) ); + hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx = L_shr( hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, sub( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ) ); // q_subtract_power_y + move32(); hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth = hDirACRend->masa_stereo_type_detect->q_subtract_power_y; move16(); } ELSE { - hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = L_shr( hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, sub( hDirACRend->masa_stereo_type_detect->q_subtract_power_y, hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) ); + hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = L_shr( hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, sub( hDirACRend->masa_stereo_type_detect->q_subtract_power_y, hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) ); // q_subtract_power_y + move32(); hDirACRend->masa_stereo_type_detect->q_subtract_power_y = hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth; move16(); } } exp = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, proto_power_smooth_len ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, proto_power_smooth_len, exp ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, proto_power_smooth_len, exp ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q + exp) hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, exp ); - + move16(); IF( LT_16( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, i_mult( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, i_mult( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ) ); // proto_power_smooth_q hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q; move16(); } ELSE { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, i_mult( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, i_mult( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q ) ); // proto_power_smooth_prev_q hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q; move16(); } exp = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), exp ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), exp ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q + exp) hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, exp ); + move16(); IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 ) { IF( LT_16( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) ); // proto_power_diff_smooth_q hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q; move16(); } ELSE { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ) ); // proto_power_diff_smooth_prev_q hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q; move16(); } @@ -4973,15 +5002,15 @@ void ivas_dirac_dec_render_sf_fx( IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); // Q26 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); // Q26 } IF( hDirACRend->proto_signal_decorr_on ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q ) ); // proto_direct_buffer_f_q hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; move16(); } @@ -5015,8 +5044,8 @@ void ivas_dirac_dec_render_sf_fx( { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); - scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); + scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); // Q6 + scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); // Q6 } } } @@ -5030,12 +5059,12 @@ void ivas_dirac_dec_render_sf_fx( test(); test(); - IF( L_or( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ), EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) + IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { /* render objects in combined format onto the CICP19 channels for BINAURAL_ROOM_IR */ test(); test(); - IF( L_and( L_and( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ), EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ), EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) + IF( ( ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { Word16 in_ch; FOR( in_ch = 0; in_ch < st_ivas->nchan_ism; in_ch++ ) @@ -5092,7 +5121,7 @@ void ivas_dirac_dec_render_sf_fx( for ( j = 0, j2 = 0; j < nchan_out_woLFE; j++, j2++ ) { test(); - IF( L_and( st_ivas->hIntSetup.num_lfe > 0, ( EQ_16( st_ivas->hIntSetup.index_lfe[lfe_index], j ) ) ) ) + IF( ( st_ivas->hIntSetup.num_lfe > 0 && ( EQ_16( st_ivas->hIntSetup.index_lfe[lfe_index], j ) ) ) ) { IF( LT_16( lfe_index, sub( st_ivas->hIntSetup.num_lfe, 1 ) ) ) { @@ -5109,28 +5138,30 @@ void ivas_dirac_dec_render_sf_fx( prev_gain_fx = st_ivas->hIsmRendererData->prev_gains_fx[i][j]; move32(); test(); - IF( L_or( L_abs( gain_fx ) > 0, L_abs( prev_gain_fx ) > 0 ) ) + IF( ( L_abs( gain_fx ) > 0 || L_abs( prev_gain_fx ) > 0 ) ) { Word32 *tc_re_fx, *tc_im_fx; Word16 *w1_fx, w2_fx; w1_fx = &st_ivas->hIsmRendererData->interpolator_fx[interp_offset]; - tc_re_fx = pppQMfFrame_ts_re_fx[add( nchan_transport, i )][0]; + tc_re_fx = pppQMfFrame_ts_re_fx[nchan_transport + i][0]; move32(); - tc_im_fx = pppQMfFrame_ts_im_fx[add( nchan_transport, i )][0]; + tc_im_fx = pppQMfFrame_ts_im_fx[nchan_transport + i][0]; move32(); FOR( k = 0; k < n_slots_to_render; k++ ) { Word32 g_fx; w2_fx = sub( MAX16B, *w1_fx ); - g_fx = L_add( Mpy_32_16_1( gain_fx, *w1_fx ), Mpy_32_16_1( prev_gain_fx, w2_fx ) ); + g_fx = L_add( Mpy_32_16_1( gain_fx, *w1_fx ), Mpy_32_16_1( prev_gain_fx, w2_fx ) ); // Q15 FOR( l = 0; l < hSpatParamRendCom->num_freq_bands; l++ ) { Word32 tmp; tmp = Mpy_32_32( g_fx, *tc_re_fx ); - Cldfb_RealBuffer_fx[j2][0][add( i_mult( k, hSpatParamRendCom->num_freq_bands ), l )] = L_add( Cldfb_RealBuffer_fx[j2][0][add( i_mult( k, hSpatParamRendCom->num_freq_bands ), l )], tmp ); + Cldfb_RealBuffer_fx[j2][0][k * hSpatParamRendCom->num_freq_bands + l] = L_add( Cldfb_RealBuffer_fx[j2][0][k * hSpatParamRendCom->num_freq_bands + l], tmp ); + move32(); tc_re_fx++; tmp = Mpy_32_32( g_fx, *tc_im_fx ); - Cldfb_ImagBuffer_fx[j2][0][add( i_mult( k, hSpatParamRendCom->num_freq_bands ), l )] = L_add( Cldfb_ImagBuffer_fx[j2][0][add( i_mult( k, hSpatParamRendCom->num_freq_bands ), l )], tmp ); + Cldfb_ImagBuffer_fx[j2][0][k * hSpatParamRendCom->num_freq_bands + l] = L_add( Cldfb_ImagBuffer_fx[j2][0][k * hSpatParamRendCom->num_freq_bands + l], tmp ); + move32(); tc_re_fx++; } w1_fx += hSpatParamRendCom->num_freq_bands; @@ -5159,14 +5190,14 @@ void ivas_dirac_dec_render_sf_fx( Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, &input_q ); - Scale_sig32( Cldfb_RealBuffer_Binaural_fx[0][0], i_mult( BINAURAL_CHANNELS, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, CLDFB_NO_CHANNELS_MAX ) ), sub( Q6, input_q ) ); - Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[0][0], i_mult( BINAURAL_CHANNELS, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, CLDFB_NO_CHANNELS_MAX ) ), sub( Q6, input_q ) ); + Scale_sig32( Cldfb_RealBuffer_Binaural_fx[0][0], i_mult( BINAURAL_CHANNELS, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, CLDFB_NO_CHANNELS_MAX ) ), sub( Q6, input_q ) ); // Q6 + Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[0][0], i_mult( BINAURAL_CHANNELS, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, CLDFB_NO_CHANNELS_MAX ) ), sub( Q6, input_q ) ); // Q6 /* Inverse CLDFB*/ FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) { /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ - Word32 *synth_fx = &output_buf_fx[ch][i_mult( index_slot, hSpatParamRendCom->num_freq_bands )]; + Word32 *synth_fx = &output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands]; Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) @@ -5177,8 +5208,8 @@ void ivas_dirac_dec_render_sf_fx( move32(); } - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( sub( Q6, 1 ), st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); - st_ivas->cldfbSynDec[ch]->Q_cldfb_state = sub( Q6, 1 ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( ( Q6 - 1 ), st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); // Q6-1 + st_ivas->cldfbSynDec[ch]->Q_cldfb_state = ( Q6 - 1 ); move16(); cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, synth_fx, i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), st_ivas->cldfbSynDec[ch] ); @@ -5191,14 +5222,17 @@ void ivas_dirac_dec_render_sf_fx( move16(); IF( GT_16( samplesToProcess, -1 ) ) { - no_col = s_min( no_col, ( add( samplesToProcess, sub( st_ivas->cldfbSynDec[ch]->no_channels, 1 ) ) ) / st_ivas->cldfbSynDec[ch]->no_channels ); + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[ch]->no_channels, 1 ) ), st_ivas->cldfbSynDec[ch]->no_channels, &tmp_e ); + tmp = shr( tmp, 15 - tmp_e ); + no_col = s_min( no_col, tmp ); } Word16 synth_len = imult1616( no_col, no_channels ); - scale_sig32( synth_fx, synth_len, sub( Q11, sub( Q6, 1 ) ) ); + scale_sig32( synth_fx, synth_len, ( Q11 - ( Q6 - 1 ) ) ); // Q11 } } - ELSE IF( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) + ELSE IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) { FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ ) { @@ -5252,9 +5286,10 @@ void ivas_dirac_dec_render_sf_fx( Copy32( &( output_buf_fx[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe_fx, num_samples_subframe ); FOR( ch = 0; ch < outchannels; ch++ ) { + test(); test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { /* Move the LFE channel to the correct place */ Copy32( tmp_lfe_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe ); @@ -5297,9 +5332,10 @@ void ivas_dirac_dec_render_sf_fx( { FOR( ch = 0; ch < outchannels; ch++ ) { + test(); test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { test(); test(); @@ -5307,18 +5343,18 @@ void ivas_dirac_dec_render_sf_fx( { FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) { - RealBuffer_fx[i] = Cldfb_RealBuffer_fx[sub( MAX_OUTPUT_CHANNELS, 1 )][i]; + RealBuffer_fx[i] = Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS - 1][i]; move32(); - ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[sub( MAX_OUTPUT_CHANNELS, 1 )][i]; + ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS - 1][i]; move32(); } Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe ); Word16 samplesToProcess = i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); - Word32 *p_out = &( output_buf_fx[ch][i_mult( index_slot, hSpatParamRendCom->num_freq_bands )] ); - - scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->p_filter_length, sub( sub( Q6, 1 ), st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state ) ); - st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = sub( Q6, 1 ); + Word32 *p_out = &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ); + scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->p_filter_length, sub( ( Q6 - 1 ), st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state ) ); // Q6-1 + st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = ( Q6 - 1 ); + move16(); cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, st_ivas->cldfbSynDec[cldfbSynIdx] ); // Calculating length of output @@ -5328,11 +5364,14 @@ void ivas_dirac_dec_render_sf_fx( move16(); IF( GT_16( samplesToProcess, -1 ) ) { - no_col = s_min( no_col, ( add( samplesToProcess, sub( st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, 1 ) ) ) / st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels ); + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, 1 ) ), st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, &tmp_e ); + tmp = shr( tmp, 15 - tmp_e ); + no_col = s_min( no_col, tmp ); } Word16 synth_len = imult1616( no_col, no_channels ); - scale_sig32( p_out, synth_len, sub( Q11, sub( Q6, 1 ) ) ); + scale_sig32( p_out, synth_len, ( Q11 - ( Q6 - 1 ) ) ); // Q11 } ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && hDirACRend->hOutSetup.separateChannelEnabled ) { @@ -5340,7 +5379,7 @@ void ivas_dirac_dec_render_sf_fx( } ELSE { - set32_fx( &( output_buf_fx[ch][i_mult( index_slot, hSpatParamRendCom->num_freq_bands )] ), 0, imult1616( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) ); + set32_fx( &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), 0, imult1616( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) ); } IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { @@ -5373,13 +5412,16 @@ void ivas_dirac_dec_render_sf_fx( move16(); IF( GT_16( samplesToProcess, -1 ) ) { - no_col = s_min( no_col, ( add( samplesToProcess, sub( st_ivas->cldfbSynDec[idx_in]->no_channels, 1 ) ) ) / st_ivas->cldfbSynDec[idx_in]->no_channels ); + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[idx_in]->no_channels, 1 ) ), st_ivas->cldfbSynDec[idx_in]->no_channels, &tmp_e ); + tmp = shr( tmp, 15 - tmp_e ); + no_col = s_min( no_col, tmp ); } out_len = imult1616( no_col, no_channels ); // Scaling cldfb_state to Q6-1 - scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, sub( sub( Q6, 1 ), st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state ) ); - st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = sub( Q6, 1 ); + scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, sub( ( Q6 - 1 ), st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state ) ); + st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = ( Q6 - 1 ); move16(); cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, st_ivas->cldfbSynDec[idx_in] ); @@ -5394,7 +5436,9 @@ void ivas_dirac_dec_render_sf_fx( } hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); + move16(); hSpatParamRendCom->subframes_rendered = add( hSpatParamRendCom->subframes_rendered, 1 ); + move16(); IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) @@ -5411,7 +5455,7 @@ void ivas_dirac_dec_render_sf_fx( { FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) { - scale_sig32( st_ivas->cldfbSynDec[i]->cldfb_state_fx, st_ivas->cldfbSynDec[i]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[i]->Q_cldfb_state ) ); + scale_sig32( st_ivas->cldfbSynDec[i]->cldfb_state_fx, st_ivas->cldfbSynDec[i]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[i]->Q_cldfb_state ) ); // Q11 st_ivas->cldfbSynDec[i]->Q_cldfb_state = Q11; move16(); } @@ -5451,7 +5495,7 @@ void ivas_dirac_dec_render_sf_fx( FOR( ch = 0; ch < outchannels; ch++ ) { test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { @@ -5464,22 +5508,23 @@ void ivas_dirac_dec_render_sf_fx( { FOR( ch = 0; ch < outchannels; ch++ ) { + test(); test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { test(); IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled ) { Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe ); - scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state ) ); + scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state ) ); // Q11 st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11; move16(); } } ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled == 0 ) || NE_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) ) { - scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state ) ); + scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state ) ); // Q11 st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11; move16(); idx_in = add( idx_in, 1 ); diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov.c index 4af7276724754fc92dc82b50f11bd21476b46a49..4bcfdc3e6d4a85ad28f35a167fab7dd67044f684 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov.c @@ -70,7 +70,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( const Word16 num_param_bands_residual, /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ const Word16 nchan_in, /* i : number of input (transport) channels */ const Word16 nchan_out, /* i : number of output channels */ - const Word32 *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) */ + const Word32 *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) Q(15-proto_matrix_e) */ ) { Word16 idx; @@ -89,7 +89,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } h_dirac_output_synthesis_params->proto_matrix_len = imult1616( nchan_out, nchan_in ); - + move16(); /* cov buffers */ FOR( idx = 0; idx < num_param_bands; idx++ ) { @@ -116,6 +116,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( } set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_fx[idx], imult1616( nchan_out, nchan_in ) ); h_dirac_output_synthesis_state->mixing_matrix_len = i_mult( nchan_out, nchan_in ); + move16(); } FOR( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { @@ -139,6 +140,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( } set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx], imult1616( nchan_out, nchan_out ) ); h_dirac_output_synthesis_state->mixing_matrix_res_len = i_mult( nchan_out, nchan_out ); + move16(); } FOR( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { @@ -194,6 +196,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( FOR( idx = 1; idx <= interp_length; ++idx ) { h_dirac_output_synthesis_params->interpolator_fx[idx - 1] = div_s( idx, interp_length ); + move16(); } Copy32( proto_matrix, h_dirac_output_synthesis_params->proto_matrix_fx, imult1616( nchan_in, nchan_out ) ); h_dirac_output_synthesis_params->proto_matrix_e = 5; @@ -734,13 +737,13 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot( *-------------------------------------------------------------------*/ #ifdef FIX_835_PARAMMC_BUFFER_VALUES void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( - Word32 *RealBuffer_fx, /* i : input channel filter bank samples (real part) */ + Word32 *RealBuffer_fx, /* i : input channel filter bank samples (real part) Q(31- RealBuffer_e)*/ Word16 RealBuffer_e, /* i : exponent input channel filter bank samples (real part)*/ - Word32 *ImagBuffer_fx, /* i : input channel filter bank samples (imaginary part */ + Word32 *ImagBuffer_fx, /* i : input channel filter bank samples (imaginary part Q(ImagBuffer_e)*/ Word16 ImagBuffer_e, /* i : exponent input channel filter bank samples (real part)*/ - Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (real part) */ + Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (real part) Q(31- cx_e)*/ Word16 *cx_e, /* i : exponent for accumulated input covariance (real part) */ - Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (imaginary part) */ + Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (imaginary part) Q(31- cx_imag_e)*/ Word16 *cx_imag_e, /* i : exponent accumulated input covariance (imag part) */ PARAM_MC_DEC_HANDLE hParamMC, /* i : handle to Parametric MC state */ const Word16 param_band, /* i : parameter band */ @@ -777,9 +780,9 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( band = add( brange[0], band_idx ); FOR( ch_idx = 0; ch_idx < nchan_in; ch_idx++ ) { - real_in_buffer_fx[add( band_idx, imult1616( num_bands, ch_idx ) )] = RealBuffer_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; + real_in_buffer_fx[band_idx + num_bands * ch_idx] = RealBuffer_fx[band + hParamMC->num_freq_bands * ch_idx]; move32(); - imag_in_buffer_fx[add( band_idx, imult1616( num_bands, ch_idx ) )] = ImagBuffer_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; + imag_in_buffer_fx[band_idx + num_bands * ch_idx] = ImagBuffer_fx[band + hParamMC->num_freq_bands * ch_idx]; move32(); } } @@ -788,8 +791,8 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( move16(); imag_in_e = ImagBuffer_e; move16(); - shift_real = sub( L_norm_arr( real_in_buffer_fx, imult1616( num_bands, nchan_in ) ), find_guarded_bits_fx( num_bands + 1 ) ); - shift_imag = sub( L_norm_arr( imag_in_buffer_fx, imult1616( num_bands, nchan_in ) ), find_guarded_bits_fx( num_bands + 1 ) ); + shift_real = sub( L_norm_arr( real_in_buffer_fx, imult1616( num_bands, nchan_in ) ), find_guarded_bits_fx( add( num_bands, 1 ) ) ); + shift_imag = sub( L_norm_arr( imag_in_buffer_fx, imult1616( num_bands, nchan_in ) ), find_guarded_bits_fx( add( num_bands, 1 ) ) ); real_in_e = sub( real_in_e, shift_real ); imag_in_e = sub( imag_in_e, shift_imag ); @@ -799,9 +802,9 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( FOR( i = 0; i < num_bands * nchan_in; ++i ) { - real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], sub( output_e, RealBuffer_e ) ); + real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], sub( output_e, RealBuffer_e ) ); // Q(31-output_e) move32(); - imag_in_buffer_fx[i] = L_shr( imag_in_buffer_fx[i], sub( output_e, ImagBuffer_e ) ); + imag_in_buffer_fx[i] = L_shr( imag_in_buffer_fx[i], sub( output_e, ImagBuffer_e ) ); // Q(31-output_e) move32(); } @@ -831,10 +834,10 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( FOR( j = 0; j < PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS; j++ ) { L_tmp = BASOP_Util_Add_Mant32Exp( cx_fx[j], cx_init_e, 0, 0, &tmp1_e ); - cx_fx[j] = L_shr( L_tmp, sub( tmp1, tmp1_e ) ); + cx_fx[j] = L_shr( L_tmp, sub( tmp1, tmp1_e ) ); // Q(31-tmp1) move32(); L_tmp = BASOP_Util_Add_Mant32Exp( cx_imag_fx[j], cx_init_imag_e, 0, 0, &tmp2_e ); - cx_imag_fx[j] = L_shr( L_tmp, sub( tmp2, tmp2_e ) ); + cx_imag_fx[j] = L_shr( L_tmp, sub( tmp2, tmp2_e ) ); // Q(31-tmp2) move32(); } @@ -1095,13 +1098,13 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot( } #else void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( - Word32 *Cldfb_RealBuffer_in_fx, - Word32 *Cldfb_ImagBuffer_in_fx, - Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (real part) */ - Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (imaginary part) */ - Word32 *mixing_matrix_fx[], /* i : parameter band wise mixing matrices (direct part) */ + Word32 *Cldfb_RealBuffer_in_fx, /*Q6*/ + Word32 *Cldfb_ImagBuffer_in_fx, /*Q6*/ + Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (real part) Q6*/ + Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (imaginary part) Q6*/ + Word32 *mixing_matrix_fx[], /* i : parameter band wise mixing matrices (direct part) Q(31-mixing_matrix_e)*/ Word16 *mixing_matrix_e, /* i : parameter band wise mixing matrices (direct part) */ - Word32 *mixing_matrix_res_fx[], /* i : parameter band wise mixing matrices (residual part) */ + Word32 *mixing_matrix_res_fx[], /* i : parameter band wise mixing matrices (residual part) Q(31-mixing_matrix_res_e)*/ Word16 *mixing_matrix_res_e, /* i : parameter band wise mixing matrices (residual part) */ const UWord16 slot_idx_sfr, /* i : time slot index for the current slot within the current subframe */ const UWord16 slot_idx_tot, /* i : time slot index for the current slot within the frame */ @@ -1118,6 +1121,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( Word16 mixing_matrix_smooth_e; Word32 mixing_matrix_res_smooth_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; Word16 mixing_matrix_res_smooth_e = 0; + move16(); Word32 mixing_matrix_buffer_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; Word16 mixing_matrix_buffer_e; Word32 input_f_real_fx[PARAM_MC_MAX_TRANSPORT_CHANS]; @@ -1145,7 +1149,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( move16(); brange[0] = hParamMC->band_grouping[param_band_idx]; move16(); - brange[1] = hParamMC->band_grouping[add( param_band_idx, 1 )]; + brange[1] = hParamMC->band_grouping[( param_band_idx + 1 )]; move16(); if ( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) ) @@ -1191,7 +1195,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( assert( LT_16( band, hParamMC->h_output_synthesis_params.max_band_decorr ) ); FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) { - diff_f_real_fx[ch_idx] = Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band]; // Q6 + diff_f_real_fx[ch_idx] = Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band]; move32(); diff_f_imag_fx[ch_idx] = Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band]; move32(); @@ -1200,17 +1204,17 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( /* apply residual mixing */ matrix_product_mant_exp_fx( mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, nY, nY, 0, diff_f_real_fx, 25, nY, 1, 0, output_f_real_fx, &output_f_real_e ); - scale_sig32( output_f_real_fx, nY, sub( Q6, sub( Q31, output_f_real_e ) ) ); + scale_sig32( output_f_real_fx, nY, sub( Q6, sub( Q31, output_f_real_e ) ) ); // Q6 matrix_product_mant_exp_fx( mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, nY, nY, 0, diff_f_imag_fx, 25, nY, 1, 0, output_f_imag_fx, &output_f_imag_e ); - scale_sig32( output_f_imag_fx, nY, sub( Q6, sub( Q31, output_f_imag_e ) ) ); + scale_sig32( output_f_imag_fx, nY, sub( Q6, sub( Q31, output_f_imag_e ) ) ); // Q6 FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) { Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band] = output_f_real_fx[ch_idx]; // Q6 move32(); - Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band] = output_f_imag_fx[ch_idx]; + Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band] = output_f_imag_fx[ch_idx]; // Q6 move32(); } } @@ -1229,20 +1233,20 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( FOR( ch_idx = 0; ch_idx < nX; ch_idx++ ) { - input_f_real_fx[ch_idx] = Cldfb_RealBuffer_in_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; // Q6 + input_f_real_fx[ch_idx] = Cldfb_RealBuffer_in_fx[ch_idx * hParamMC->num_freq_bands + band]; // Q6 move32(); - input_f_imag_fx[ch_idx] = Cldfb_ImagBuffer_in_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; + input_f_imag_fx[ch_idx] = Cldfb_ImagBuffer_in_fx[ch_idx * hParamMC->num_freq_bands + band]; // Q6 move32(); } /* apply mixing matrix */ matrix_product_mant_exp_fx( mixing_matrix_smooth_fx, mixing_matrix_smooth_e, nY, nX, 0, input_f_real_fx, 25, nX, 1, 0, output_f_real_fx, &output_f_real_e ); - scale_sig32( output_f_real_fx, MAX_CICP_CHANNELS, sub( 6, sub( 31, output_f_real_e ) ) ); + scale_sig32( output_f_real_fx, MAX_CICP_CHANNELS, sub( 6, sub( 31, output_f_real_e ) ) ); // Q6 matrix_product_mant_exp_fx( mixing_matrix_smooth_fx, mixing_matrix_smooth_e, nY, nX, 0, input_f_imag_fx, 25, nX, 1, 0, output_f_imag_fx, &output_f_imag_e ); - scale_sig32( output_f_imag_fx, MAX_CICP_CHANNELS, sub( 6, sub( 31, output_f_imag_e ) ) ); + scale_sig32( output_f_imag_fx, MAX_CICP_CHANNELS, sub( 6, sub( 31, output_f_imag_e ) ) ); // Q6 /* collect output */ FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) @@ -1529,20 +1533,20 @@ int16_t computeMixingMatrices( Word16 computeMixingMatrices_fx( const Word16 num_inputs, /* i : number of input channels */ const Word16 num_outputs, /* i : number of output channels */ - const Word32 *Cx, /* i : input channel covariance matrix */ + const Word32 *Cx, /* i : input channel covariance matrix Q(31-Cx_e) */ Word16 Cx_e, - const Word32 *Cy, /* i : target covariance matrix */ + const Word32 *Cy, /* i : target covariance matrix Q(31-Cy_e) */ Word16 Cy_e, - const Word32 *Q, /* i : prototype matrix (usually a upmix matrix) */ + const Word32 *Q, /* i : prototype matrix (usually a upmix matrix) Q_fx_e */ Word16 Q_fx_e, const Word16 energy_compensation_flag, /* i : flag indicating that the energy compensation should be performed (i.e. no residual mixing matrix will follow) */ const Word32 reg_Sx_fx, /* i : regularization factor for the input channel singular values */ Word16 reg_Sx_e, - const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix */ + const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix Q(31-reg_ghat_e) */ Word16 reg_ghat_e, - Word32 *mixing_matrix_fx, /* o : resulting mixing matrix */ + Word32 *mixing_matrix_fx, /* o : resulting mixing matrix Q(31-mixing_matrix_out_e) */ Word16 *mixing_matrix_out_e, - Word32 *Cr_fx, /* o : residual covariance matrix */ + Word32 *Cr_fx, /* o : residual covariance matrix Q(31-Cr_e) */ Word16 *Cr_e ) { Word16 i, j; @@ -1650,9 +1654,9 @@ Word16 computeMixingMatrices_fx( tmp_e = svd_s_buffer_e[j]; move16(); L_tmp = Sqrt32( svd_s_buffer_fx[j], &tmp_e ); - Ky_fx[add( i, imult1616( j, lengthCy ) )] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); + Ky_fx[i + ( j * lengthCy )] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); // Q(31-tmp_e) move32(); - Ky_fx_e[add( i, imult1616( j, lengthCy ) )] = tmp_e; + Ky_fx_e[i + ( j * lengthCy )] = tmp_e; move16(); } } @@ -1674,9 +1678,9 @@ Word16 computeMixingMatrices_fx( tmp_e = svd_s_buffer_e[j]; move16(); L_tmp = Sqrt32( svd_s_buffer_fx[j], &tmp_e ); - Kx_fx[add( i, imult1616( j, lengthCx ) )] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); + Kx_fx[( i + ( j * lengthCx ) )] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); // Q(31-tmp_e) move32(); - Kx_fx_e[add( i, imult1616( j, lengthCx ) )] = tmp_e; + Kx_fx_e[( i + ( j * lengthCx ) )] = tmp_e; move16(); } } @@ -1686,7 +1690,7 @@ Word16 computeMixingMatrices_fx( { tmp_e = svd_s_buffer_e[i]; move16(); - svd_s_buffer_fx[i] = Sqrt32( svd_s_buffer_fx[i], &tmp_e ); + svd_s_buffer_fx[i] = Sqrt32( svd_s_buffer_fx[i], &tmp_e ); // Q(31-tmp_e) move32(); svd_s_buffer_e[i] = tmp_e; move16(); @@ -1744,9 +1748,9 @@ Word16 computeMixingMatrices_fx( scale = add( scale, sub( Q31, svd_s_buffer_e[i] ) ); FOR( j = 0; j < lengthCx; ++j ) { - Kx_reg_inv_fx[add( i, imult1616( j, lengthCx ) )] = Mpy_32_16_1( svd_u_buffer_fx[j][i], reg_fac_fx ); + Kx_reg_inv_fx[i + j * lengthCx] = Mpy_32_16_1( svd_u_buffer_fx[j][i], reg_fac_fx ); // Q(31-scale) move32(); - Kx_reg_inv_e[add( i, imult1616( j, lengthCx ) )] = scale; + Kx_reg_inv_e[i + j * lengthCx] = scale; move16(); } } @@ -1780,7 +1784,7 @@ Word16 computeMixingMatrices_fx( #endif } #ifdef FIX_827_HIGH_MLD - L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); + L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); // limit_e+ reg_ghat_e limit_fx = L_add( L_tmp, EPSILON_FX ); limit_e = add( limit_e, reg_ghat_e ); #endif @@ -1798,7 +1802,7 @@ Word16 computeMixingMatrices_fx( move16(); } - tmp = BASOP_Util_Divide3232_Scale( Cy_fx[add( i, imult1616( i, lengthCy ) )], Cy_hat_diag_fx[i], &exp ); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[( i + ( i * lengthCy ) )], Cy_hat_diag_fx[i], &exp ); exp = add( exp, sub( Cy_fx_e, Cy_hat_diag_buff_e[i] ) ); L_tmp = Sqrt32( L_deposit_h( tmp ), &exp ); G_hat_fx[i] = L_tmp; @@ -1839,7 +1843,7 @@ Word16 computeMixingMatrices_fx( FOR( i = 0; i < lengthCy * lengthCx; i++ ) { - mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( exp, mat_mult_buffer1_fx_e[i] ) ); + mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( exp, mat_mult_buffer1_fx_e[i] ) ); // Q(31-exp) move32(); } @@ -1919,7 +1923,7 @@ Word16 computeMixingMatrices_fx( FOR( i = 0; i < lengthCy * lengthCx; i++ ) { - mixing_matrix_fx[i] = L_shr( mixing_matrix_fx[i], sub( exp, mixing_matrix_fx_e[i] ) ); + mixing_matrix_fx[i] = L_shr( mixing_matrix_fx[i], sub( exp, mixing_matrix_fx_e[i] ) ); // Q(31-exp) move32(); } @@ -1943,11 +1947,11 @@ Word16 computeMixingMatrices_fx( } /* Avoid Meaningless negative main diagonal elements */ - IF( BASOP_Util_Cmp_Mant32Exp( Cr_fx[add( i, imult1616( i, lengthCy ) )], exp, 0, 0 ) < 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( Cr_fx[i + ( i * lengthCy )], exp, 0, 0 ) < 0 ) { - Cr_fx[add( i, imult1616( i, lengthCy ) )] = 0; + Cr_fx[i + ( i * lengthCy )] = 0; move32(); - Cr_e_arr[add( i, imult1616( i, lengthCy ) )] = 0; + Cr_e_arr[i + ( i * lengthCy )] = 0; move16(); } } @@ -1965,7 +1969,7 @@ Word16 computeMixingMatrices_fx( FOR( i = 0; i < lengthCy * lengthCy; i++ ) { - Cr_fx[i] = L_shr( Cr_fx[i], sub( exp, Cr_e_arr[i] ) ); + Cr_fx[i] = L_shr( Cr_fx[i], sub( exp, Cr_e_arr[i] ) ); // Q(31-exp) move32(); } @@ -1985,7 +1989,7 @@ Word16 computeMixingMatrices_fx( FOR( i = 0; i < lengthCy * lengthCy; i++ ) { - mat_mult_buffer2_fx[i] = L_shr( mat_mult_buffer2_fx[i], sub( exp, mat_mult_buffer2_fx_e[i] ) ); + mat_mult_buffer2_fx[i] = L_shr( mat_mult_buffer2_fx[i], sub( exp, mat_mult_buffer2_fx_e[i] ) ); // Q(31-exp) move32(); } @@ -2005,16 +2009,16 @@ Word16 computeMixingMatrices_fx( { /* Avoid correction for very small energies, main diagonal elements of Cy_tilde_p may be negative */ - IF( BASOP_Util_Cmp_Mant32Exp( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )], mat_mult_buffer2_e, 0, 0 ) < 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( Cy_tilde_p_fx[i + ( i * lengthCy )], mat_mult_buffer2_e, 0, 0 ) < 0 ) { - adj_fx_p[i] = 1073741824; + adj_fx_p[i] = 1073741824; // 1.0f in Q30 move32(); adj_e[i] = 1; move16(); } ELSE { - tmp = BASOP_Util_Divide3232_Scale( Cy_fx[add( i, imult1616( i, lengthCy ) )], L_add( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )], EPSILON_FX ), &exp ); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i + ( i * lengthCy )], L_add( Cy_tilde_p_fx[i + ( i * lengthCy )], EPSILON_FX ), &exp ); exp = add( exp, sub( Cy_fx_e, mat_mult_buffer2_e ) ); L_tmp = L_deposit_h( tmp ); L_tmp = Sqrt32( L_tmp, &exp ); @@ -2026,7 +2030,7 @@ Word16 computeMixingMatrices_fx( IF( BASOP_Util_Cmp_Mant32Exp( adj_fx_p[i], adj_e[i], 1073741824, 3 ) > 0 ) { - adj_fx_p[i] = 1073741824; + adj_fx_p[i] = 1073741824; // 1.0f in Q30 move32(); adj_e[i] = 3; move16(); @@ -2046,7 +2050,7 @@ Word16 computeMixingMatrices_fx( FOR( i = 0; i < lengthCy; i++ ) { - adj_fx[i] = L_shr( adj_fx_p[i], sub( exp, adj_e[i] ) ); + adj_fx[i] = L_shr( adj_fx_p[i], sub( exp, adj_e[i] ) ); // Q(31-exp) move32(); } adj_fx_e = exp; @@ -2054,7 +2058,7 @@ Word16 computeMixingMatrices_fx( diag_matrix_product_fx( adj_fx, adj_fx_e, lengthCy, mixing_matrix_fx, mixing_matrix_e, lengthCy, lengthCx, 0, mat_mult_buffer3_fx, &mat_mult_buffer3_e ); - Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, imult1616( lengthCx, lengthCy ) ); + Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, imult1616( lengthCx, lengthCy ) ); // Q(31-mat_mult_buffer3_e) mixing_matrix_e = mat_mult_buffer3_e; move16(); } @@ -2271,15 +2275,15 @@ int16_t computeMixingMatricesResidual( #else Word16 computeMixingMatricesResidual_fx( const Word32 num_outputs, /* i : number of output channels */ - const Word32 *Cx_fx, /* i : vector containing the diagonal diffuse prototype covariance */ + const Word32 *Cx_fx, /* i : vector containing the diagonal diffuse prototype covariance Q(31-Cx_e) */ const Word16 Cx_e, - const Word32 *Cy_fx, /* i : matrix containing the missing cov (Cr from computeMixingMatrices()) */ + const Word32 *Cy_fx, /* i : matrix containing the missing cov (Cr from computeMixingMatrices()) Q(31-Cy_fx_e) */ const Word16 Cy_fx_e, - const Word32 reg_Sx_fx, /* i : regularization factor for the input channel singular values */ + const Word32 reg_Sx_fx, /* i : regularization factor for the input channel singular values Q(31-reg_Sx_e) */ const Word16 reg_Sx_e, - const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix */ + const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix Q(31-reg_ghat_e) */ const Word16 reg_ghat_e, - Word32 *mixing_matrix_fx, /* o : resulting residual mixing matrix */ + Word32 *mixing_matrix_fx, /* o : resulting residual mixing matrix Q(31-mixing_matrix_ret_e) */ Word16 *mixing_matrix_ret_e ) { Word16 i, j; @@ -2359,7 +2363,7 @@ Word16 computeMixingMatricesResidual_fx( tmp_e = svd_s_buffer_e[j]; move16(); L_tmp = Sqrt32( svd_s_buffer_fx[j], &tmp_e ); - Ky_fx[i + j * lengthCy] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); + Ky_fx[i + j * lengthCy] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); // Q(31-tmp_e) move32(); Ky_fx_e[i + j * lengthCy] = tmp_e; move16(); @@ -2382,6 +2386,7 @@ Word16 computeMixingMatricesResidual_fx( exp = Cx_e; move16(); Kx_fx[i] = Sqrt32( Cx_fx[i], &exp ); + move32(); Kx_fx_e[i] = exp; move16(); } @@ -2405,7 +2410,7 @@ Word16 computeMixingMatricesResidual_fx( } } - L_tmp = Mpy_32_32( limit_fx, reg_Sx_fx ); + L_tmp = Mpy_32_32( limit_fx, reg_Sx_fx ); // limit_e + reg_Sx_e L_tmp = L_add( L_tmp, EPSILLON_FX ); limit_fx = L_tmp; move16(); @@ -2427,10 +2432,11 @@ Word16 computeMixingMatricesResidual_fx( exp = limit_e; move16(); } - tmp = BASOP_Util_Divide3232_Scale( 1073741824, div_tmp, &scale ); + tmp = BASOP_Util_Divide3232_Scale( 1073741824, div_tmp, &scale ); // 1073741824 -> 1.0f in Q30 scale = add( scale, sub( Q1, exp ) ); Kx_reg_inv_fx[i] = L_deposit_h( tmp ); + move32(); Kx_reg_inv_e[i] = scale; move16(); } @@ -2449,7 +2455,7 @@ Word16 computeMixingMatricesResidual_fx( *-----------------------------------------------------------------*/ /* Computing Cy_hat_diag */ - Copy32( Cx_fx, Cy_hat_diag_fx, extract_l( num_outputs ) ); + Copy32( Cx_fx, Cy_hat_diag_fx, extract_l( num_outputs ) ); // Q(31-Cx_e) Cy_hat_diag_e = Cx_e; move16(); @@ -2464,7 +2470,7 @@ Word16 computeMixingMatricesResidual_fx( } } - L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); + L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); // Q(limit_e+reg_ghat_e) limit_fx = L_add( L_tmp, EPSILON_FX ); limit_e = add( limit_e, reg_ghat_e ); @@ -2496,7 +2502,7 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < num_outputs; i++ ) { - L_tmp = Mpy_32_32( Kx_fx[i], G_hat_fx[i] ); + L_tmp = Mpy_32_32( Kx_fx[i], G_hat_fx[i] ); // Q(31-(Kx_fx_e+G_hag_e)) Kx_fx[i] = L_tmp; move32(); Kx_fx_e[i] = add( Kx_fx_e[i], G_hat_e[i] ); @@ -2511,10 +2517,11 @@ Word16 computeMixingMatricesResidual_fx( FOR( j = 0; j < num_outputs; j++ ) { - L_tmp = Mpy_32_32( Ky_fx[add( i, imult1616( j, extract_l( num_outputs ) ) )], fac_fx ); - mat_mult_buffer1_fx[add( i, imult1616( j, extract_l( num_outputs ) ) )] = L_tmp; + L_tmp = Mpy_32_32( Ky_fx[i + j * num_outputs], fac_fx ); // Q(31-(Ky_fx_e+Kx_fx_e)) + mat_mult_buffer1_fx[i + j * num_outputs] = L_tmp; move32(); - mat_mult_buffer1_buff_e[add( i, imult1616( j, extract_l( num_outputs ) ) )] = extract_l( L_add( Ky_fx_e[add( i, imult1616( j, extract_l( num_outputs ) ) )], Kx_fx_e[i] ) ); + mat_mult_buffer1_buff_e[i + j * num_outputs] = extract_l( L_add( Ky_fx_e[i + j * num_outputs], Kx_fx_e[i] ) ); + move16(); } } @@ -2531,7 +2538,7 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < num_outputs * num_outputs; i++ ) { - mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( mat_mult_buffer1_e, mat_mult_buffer1_buff_e[i] ) ); + mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( mat_mult_buffer1_e, mat_mult_buffer1_buff_e[i] ) ); // Q(31-mat_mult_buffer1_e) move32(); } @@ -2572,11 +2579,11 @@ Word16 computeMixingMatricesResidual_fx( FOR( j = 0; j < num_outputs; j++ ) { #ifdef FIX_827_HIGH_MLD - L_tmp = Mpy_32_32( mat_mult_buffer1_fx[add( j, imult1616( i, extract_l( num_outputs ) ) )], fac_fx ); - mixing_matrix_fx[add( j, imult1616( i, extract_l( num_outputs ) ) )] = L_tmp; + L_tmp = Mpy_32_32( mat_mult_buffer1_fx[j + i * num_outputs], fac_fx ); // Q(31-mat_mult_buffer1_e+Kx_reg_inv_e) + mixing_matrix_fx[j + i * num_outputs] = L_tmp; #else - L_tmp = Mpy_32_32( mat_mult_buffer1_fx[add( j, imult1616( j, extract_l( num_outputs ) ) )], fac_fx ); - mixing_matrix_fx[add( j, imult1616( j, extract_l( num_outputs ) ) )] = L_tmp; + L_tmp = Mpy_32_32( mat_mult_buffer1_fx[j + j * num_outputs], fac_fx ); // mat_mult_buffer1_e+Kx_reg_inv_e + mixing_matrix_fx[j + j * num_outputs] = L_tmp; #endif move32(); mixing_matrix_fx_e[j + i * num_outputs] = add( mat_mult_buffer1_buff_e[j + i * num_outputs], Kx_reg_inv_e[i] ); @@ -2608,7 +2615,7 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < num_outputs * num_outputs; i++ ) { - mixing_matrix_fx[i] = L_shr( mixing_matrix_fx[i], sub( exp, mixing_matrix_fx_e[i] ) ); + mixing_matrix_fx[i] = L_shr( mixing_matrix_fx[i], sub( exp, mixing_matrix_fx_e[i] ) ); // Q(31-exp) move32(); } mixing_matrix_e = exp; @@ -2627,7 +2634,7 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < num_outputs * num_outputs; i++ ) { - mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( exp, mat_mult_buffer1_buff_e[i] ) ); + mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( exp, mat_mult_buffer1_buff_e[i] ) ); // Q(31-exp) move32(); } mat_mult_buffer1_e = exp; @@ -2643,14 +2650,15 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < lengthCy; ++i ) { - tmp = BASOP_Util_Divide3232_Scale( Cy_fx[add( i, imult1616( lengthCy, i ) )], L_add( Cy_tilde_fx[i], EPSILON_FX ), &scale ); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i + ( lengthCy * i )], L_add( Cy_tilde_fx[i], EPSILON_FX ), &scale ); scale = add( scale, sub( Cy_fx_e, Cy_tilde_e ) ); adj_fx_p[i] = Sqrt32( L_deposit_h( tmp ), &scale ); + move32(); adj_buff_e[i] = scale; move16(); - IF( BASOP_Util_Cmp_Mant32Exp( adj_fx_p[i], scale, 1073741824, 3 ) > 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( adj_fx_p[i], scale, 1073741824, 3 ) > 0 ) // 1073741824 -> 1.0f in Q30 { - adj_fx_p[i] = 1073741824; + adj_fx_p[i] = 1073741824; // 1.0f in Q30 move32(); adj_buff_e[i] = 3; move16(); @@ -2672,7 +2680,7 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < lengthCy; i++ ) { - adj_fx[i] = L_shr( adj_fx_p[i], sub( adj_e, adj_buff_e[i] ) ); + adj_fx[i] = L_shr( adj_fx_p[i], sub( adj_e, adj_buff_e[i] ) ); // Q(31-adj_e) move32(); } @@ -2698,19 +2706,19 @@ Word16 computeMixingMatricesISM_fx( const Word16 num_inputs, const Word16 num_responses, const Word16 num_outputs, - const Word32 *responses_fx, + const Word32 *responses_fx, /*Q(31-responses_e) */ const Word16 responses_e, - const Word32 *ener_fx, + const Word32 *ener_fx, /*Q(31-ener_e) */ const Word16 ener_e, - const Word32 *Cx_diag_fx, + const Word32 *Cx_diag_fx, /*Q(31-diag_e) */ const Word16 Cx_diag_e, - const Word32 *Cy_diag_fx, + const Word32 *Cy_diag_fx, /*Q(31-diag_e) */ const Word16 Cy_diag_e, const Word16 *Q_16fx, // Q15 const Word16 energy_compensation_flag, - const Word32 reg_Sx_fx, - const Word32 reg_ghat_fx, - Word32 *mixing_matrix_fx, + const Word32 reg_Sx_fx, /*Q0*/ + const Word32 reg_ghat_fx, /*Q0*/ + Word32 *mixing_matrix_fx, /*Q(31-mixing_matrix_e) */ Word16 *mixing_matrix_e ) { Word16 i, out; @@ -2743,7 +2751,7 @@ Word16 computeMixingMatricesISM_fx( push_wmops( "dirac_cov_mix_mat" ); out = EXIT_SUCCESS; - move32(); + move16(); lengthCx = num_inputs; move16(); lengthCy = num_outputs; @@ -2787,13 +2795,13 @@ Word16 computeMixingMatricesISM_fx( } FOR( i = 0; i < lengthCx; i++ ) { - Kx_fx[i] = L_shr_r( Kx_fx[i], sub( Kx_e, temp_e[i] ) ); + Kx_fx[i] = L_shr_r( Kx_fx[i], sub( Kx_e, temp_e[i] ) ); // Q(31-Kx_e) move32(); } /* Regularization of Sx */ maximum_32_fx( Kx_fx, lengthCx, &limit_fx ); - limit_fx = Mpy_32_32( limit_fx, reg_Sx_fx ); + limit_fx = Mpy_32_32( limit_fx, reg_Sx_fx ); // Cy_hat_diag_e + reg_ghat_e FOR( i = 0; i < lengthCx; ++i ) { @@ -2845,7 +2853,7 @@ Word16 computeMixingMatricesISM_fx( } FOR( i = 0; i < lengthCx; i++ ) { - Kx_reg_inv_fx[i] = L_shr_r( Kx_reg_inv_fx[i], sub( Kx_reg_inv_e, temp_e[i] ) ); + Kx_reg_inv_fx[i] = L_shr_r( Kx_reg_inv_fx[i], sub( Kx_reg_inv_e, temp_e[i] ) ); // Q(31- Kx_reg_inv_e) move32(); } @@ -2893,7 +2901,7 @@ Word16 computeMixingMatricesISM_fx( } } - limit_fx = Mpy_32_32( limit_fx, reg_ghat_fx ); + limit_fx = Mpy_32_32( limit_fx, reg_ghat_fx ); // Cy_hat_diag_e + reg_ghat_e /* Computing G_hat */ FOR( i = 0; i < lengthCy; ++i ) @@ -2940,7 +2948,7 @@ Word16 computeMixingMatricesISM_fx( } FOR( i = 0; i < lengthCy; i++ ) { - G_hat_fx[i] = L_shr_r( G_hat_fx[i], sub( G_hat_e, temp_e[i] ) ); + G_hat_fx[i] = L_shr_r( G_hat_fx[i], sub( G_hat_e, temp_e[i] ) ); // Q(31-G_hat_e) move32(); } @@ -3006,7 +3014,7 @@ Word16 computeMixingMatricesISM_fx( FOR( i = 0; i < lengthCy; ++i ) { /* Avoid correction for very small energies, main diagonal elements of Cy_tilde_p may be negative */ - IF( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )] < 0 ) + IF( Cy_tilde_p_fx[( i + ( i * lengthCy ) )] < 0 ) { adj_fx[i] = MAX_32; move32(); @@ -3017,9 +3025,9 @@ Word16 computeMixingMatricesISM_fx( { IF( Cy_diag_fx[i] ) { - IF( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )] ) + IF( Cy_tilde_p_fx[i + ( i * lengthCy )] ) { - adj_fx[i] = BASOP_Util_Divide3232_Scale_cadence( Cy_diag_fx[i], Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )], &temp_e[i] ); + adj_fx[i] = BASOP_Util_Divide3232_Scale_cadence( Cy_diag_fx[i], Cy_tilde_p_fx[i + ( i * lengthCy )], &temp_e[i] ); move32(); temp_e[i] = add( temp_e[i], sub( Cy_diag_e, mat_mult_buffer2_e ) ); move16(); @@ -3061,7 +3069,7 @@ Word16 computeMixingMatricesISM_fx( } FOR( i = 0; i < lengthCy; i++ ) { - adj_fx[i] = L_shr_r( adj_fx[i], sub( adj_e, temp_e[i] ) ); + adj_fx[i] = L_shr_r( adj_fx[i], sub( adj_e, temp_e[i] ) ); // Q(31-adj_e) move32(); } diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index e18d369f46df393119862027b01d9649946e1b9c..9718c710697f78c23c349379cd3fb7f2969afa3c 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -55,7 +55,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( const Word16 nchan_transport_old, /* i : last number of transport channels */ const ISM_MODE last_ism_mode, /* i : last ISM mode */ UWord16 *nSamplesRendered, /* o : number of samples rendered */ - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal Q0*/ ) { ivas_error error; @@ -100,7 +100,13 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( * Allocate, initialize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ - IF( NE_32( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, 0, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ), IVAS_ERR_OK ) ) + /* st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport */ + Word16 tmp, tmp_e; + Word32 tmp_32; + tmp = BASOP_Util_Divide3216_Scale( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, &tmp_e ); + tmp = shr( tmp, sub( 15, tmp_e ) ); + tmp_32 = L_deposit_l( tmp ); + IF( NE_32( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, 0, tmp_32, L_shl( tmp_32, 1 ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -115,7 +121,9 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( /* save old IntSetup, might be needed for JBM flushing...*/ intern_config_old = st_ivas->intern_config; + move32(); hIntSetupOld = st_ivas->hIntSetup; + move32(); tc_granularity_new = 1; move16(); renderer_type_old = st_ivas->renderer_type; @@ -705,7 +713,7 @@ ivas_error ivas_ism_dec_config_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const ISM_MODE last_ism_mode, /* i/o: last ISM mode */ UWord16 *nSamplesRendered, /* o : number of samples flushed when the renderer granularity changes */ - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal Q0*/ ) { Word32 ivas_total_brate; @@ -729,7 +737,7 @@ ivas_error ivas_ism_dec_config_fx( test(); test(); test(); - IF( !st_ivas->bfi && NE_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, FRAME_NO_DATA ) ) + IF( !st_ivas->bfi && NE_32( ivas_total_brate, IVAS_SID_5k2 ) && ( ivas_total_brate != FRAME_NO_DATA ) ) { /* select ISM format mode */ st_ivas->ism_mode = ivas_ism_mode_select( st_ivas->nchan_ism, ivas_total_brate ); @@ -773,7 +781,7 @@ ivas_error ivas_ism_dec_config_fx( { st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; move16(); - IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + if ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { st_ivas->hDecoderConfig->nchan_out = st_ivas->nchan_ism; move16(); diff --git a/lib_dec/ivas_ism_dtx_dec.c b/lib_dec/ivas_ism_dtx_dec.c index d33c88eed8085bc5a6902ba786477221d2ecf692..9f7af820fb1b57de72495bd13ee27a4628a4a1fe 100644 --- a/lib_dec/ivas_ism_dtx_dec.c +++ b/lib_dec/ivas_ism_dtx_dec.c @@ -86,7 +86,7 @@ void ivas_ism_dtx_dec_fx( test(); IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) && !st_ivas->bfi ) { - IF( st_ivas->hParamIsmDec != NULL ) + if ( st_ivas->hParamIsmDec != NULL ) { st_ivas->hParamIsmDec->hParamIsm->flag_noisy_speech = flag_noisy_speech; move16(); @@ -102,8 +102,8 @@ void ivas_ism_dtx_dec_fx( { FOR( ch = 0; ch < nchan_ism; ch++ ) { - st_ivas->hParamIsmDec->azimuth_values_fx[ch] = st_ivas->hIsmMetaData[ch]->azimuth_fx; - st_ivas->hParamIsmDec->elevation_values_fx[ch] = st_ivas->hIsmMetaData[ch]->elevation_fx; + st_ivas->hParamIsmDec->azimuth_values_fx[ch] = st_ivas->hIsmMetaData[ch]->azimuth_fx; // Q22 + st_ivas->hParamIsmDec->elevation_values_fx[ch] = st_ivas->hIsmMetaData[ch]->elevation_fx; // Q22 move32(); move32(); } diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 37c0f6d7baf5cc35971f772d99e6c81ad4ef7376..633459a2a3ec4b489ecc9b6775a5f0372e3bbec4 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -157,7 +157,7 @@ static void ism_metadata_smooth_fx( IF( GT_32( diff_fx, ISM_AZIMUTH_MAX_FX ) ) { diff_fx = L_sub( diff_fx, ( ISM_AZIMUTH_MAX_FX - ISM_AZIMUTH_MIN_FX ) ); - hIsmMetaData->last_azimuth_fx = L_add( hIsmMetaData->last_azimuth_fx, ( ISM_AZIMUTH_MAX_FX - ISM_AZIMUTH_MIN_FX ) ); + hIsmMetaData->last_azimuth_fx = L_add( hIsmMetaData->last_azimuth_fx, ( ISM_AZIMUTH_MAX_FX - ISM_AZIMUTH_MIN_FX ) ); // Q22 move32(); } ELSE IF( LT_32( diff_fx, ISM_AZIMUTH_MIN_FX ) ) @@ -755,8 +755,8 @@ ivas_error ivas_ism_metadata_dec_fx( Word32 element_brate[MAX_NUM_OBJECTS], total_brate[MAX_NUM_OBJECTS]; Word16 ism_extmeta_bitstream; Word16 non_diegetic_flag_global; - Word32 yaw_fx, pitch_fx; - Word16 radius_fx; + Word32 yaw_fx, pitch_fx; // Q22 + Word16 radius_fx; // Q9 Word16 flag_abs_radius; Word16 flag_abs_orientation; Word16 flag_abs_position; @@ -799,7 +799,7 @@ ivas_error ivas_ism_metadata_dec_fx( /* reverse the bitstream for easier reading of indices */ FOR( i = 0; i < s_min( MAX_BITS_ISM_METADATA, last_bit_pos ); i++ ) { - bstr_meta[i] = st0->bit_stream[sub( last_bit_pos, i )]; + bstr_meta[i] = st0->bit_stream[last_bit_pos - i]; move16(); } st0->bit_stream = bstr_meta; @@ -825,7 +825,6 @@ ivas_error ivas_ism_metadata_dec_fx( move16(); ism_mode = ivas_ism_mode_select( nchan_ism, ism_total_brate ); - move16(); } IF( EQ_32( ism_mode, ISM_MODE_PARAM ) ) @@ -954,7 +953,7 @@ ivas_error ivas_ism_metadata_dec_fx( lowrate_metadata_flag[ch] = hIsmMeta[ch]->ism_md_lowrate_flag; move16(); - IF( null_metadata_flag[ch] == 0 ) + if ( null_metadata_flag[ch] == 0 ) { ism_metadata_flag_global = s_or( ism_metadata_flag_global, lowrate_metadata_flag[ch] ); } @@ -1003,7 +1002,7 @@ ivas_error ivas_ism_metadata_dec_fx( test(); test(); test(); - IF( EQ_32( ism_mode, ISM_MODE_DISC ) || EQ_32( ism_mode, ISM_SBA_MODE_DISC ) || EQ_32( ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + if ( EQ_32( ism_mode, ISM_MODE_DISC ) || EQ_32( ism_mode, ISM_SBA_MODE_DISC ) || EQ_32( ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { nb_bits_start = st0->next_bit_pos; move16(); @@ -1039,7 +1038,7 @@ ivas_error ivas_ism_metadata_dec_fx( idx_angle2 = shl( 1, ( ISM_ELEVATION_NBITS - 1 ) ); /* Panning gain dequantization */ - hIsmMetaData->azimuth_fx = ism_dequant_meta_fx( idx_angle1, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, shl( 1, ISM_AZIMUTH_NBITS ) ); + hIsmMetaData->azimuth_fx = ism_dequant_meta_fx( idx_angle1, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, ( 1 << ISM_AZIMUTH_NBITS ) ); hIsmMetaData->elevation_fx = 0; move32(); move32(); @@ -1068,8 +1067,8 @@ ivas_error ivas_ism_metadata_dec_fx( } ELSE /* ISM_MODE_DISC */ { - hIsmMetaData->azimuth_fx = ism_dequant_meta_fx( idx_angle1, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, shl( 1, ISM_AZIMUTH_NBITS ) ); - hIsmMetaData->elevation_fx = ism_dequant_meta_fx( idx_angle2, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, shl( 1, ISM_ELEVATION_NBITS ) ); + hIsmMetaData->azimuth_fx = ism_dequant_meta_fx( idx_angle1, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, ( 1 << ISM_AZIMUTH_NBITS ) ); + hIsmMetaData->elevation_fx = ism_dequant_meta_fx( idx_angle2, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, ( 1 << ISM_ELEVATION_NBITS ) ); move32(); move32(); @@ -1081,8 +1080,8 @@ ivas_error ivas_ism_metadata_dec_fx( move16(); idx_angle2 = hIsmMetaData->orientation_angle.last_angle2_idx; move16(); - yaw_fx = ism_dequant_meta_fx( idx_angle1, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, shl( 1, ISM_AZIMUTH_NBITS ) ); - pitch_fx = ism_dequant_meta_fx( idx_angle2, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, shl( 1, ISM_ELEVATION_NBITS ) ); + yaw_fx = ism_dequant_meta_fx( idx_angle1, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, ( 1 << ISM_AZIMUTH_NBITS ) ); + pitch_fx = ism_dequant_meta_fx( idx_angle2, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, ( 1 << ISM_AZIMUTH_NBITS ) ); idx_radius = decode_radius_fx( st0, &hIsmMetaData->last_radius_idx, &flag_abs_radius ); radius_fx = usdequant_fx( idx_radius, ISM_RADIUS_MIN_Q9, ISM_RADIUS_DELTA_Q8 ); @@ -1130,6 +1129,7 @@ ivas_error ivas_ism_metadata_dec_fx( IF( EQ_32( ism_mode, ISM_MODE_PARAM ) ) { hParamIsm->flag_noisy_speech = get_next_indice_fx( st0, 1 ); + move16(); /* Loop over multiwave to read the object indices from bitstream */ FOR( ch = 0; ch < MAX_PARAM_ISM_WAVE; ch++ ) @@ -1158,7 +1158,11 @@ ivas_error ivas_ism_metadata_dec_fx( total_bits_metadata = sub( st0->next_bit_pos, nb_bits_start ); /* bits per ISM*/ - bits_metadata_ism = extract_l( total_bits_metadata / *nchan_transport ); + + // total_bits_metadata / *nchan_transport + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide1616_Scale( total_bits_metadata, *nchan_transport, &tmp_e ); + bits_metadata_ism = shr( tmp, sub( 15, tmp_e ) ); // Q0 nb_bits_objcod_read = 0; move16(); @@ -1197,9 +1201,9 @@ ivas_error ivas_ism_metadata_dec_fx( { FOR( ch = 0; ch < nchan_ism; ch++ ) { - hParamIsm->azi_index[ch] = add( hParamIsm->azi_index[ch], i_mult2( hParamIsm->last_az_sgn[ch], hParamIsm->last_az_diff[ch] ) ); + hParamIsm->azi_index[ch] = add( hParamIsm->azi_index[ch], i_mult2( hParamIsm->last_az_sgn[ch], hParamIsm->last_az_diff[ch] ) ); // Q0 move16(); - hParamIsm->ele_index[ch] = add( hParamIsm->ele_index[ch], i_mult2( hParamIsm->last_el_sgn[ch], hParamIsm->last_el_diff[ch] ) ); + hParamIsm->ele_index[ch] = add( hParamIsm->ele_index[ch], i_mult2( hParamIsm->last_el_sgn[ch], hParamIsm->last_el_diff[ch] ) ); // Q0 move16(); hIsmMeta[ch]->position_angle.last_angle1_idx = hParamIsm->azi_index[ch]; move16(); @@ -1234,7 +1238,7 @@ ivas_error ivas_ism_metadata_dec_fx( } test(); - IF( EQ_32( ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + if ( EQ_32( ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { ism_metadata_flag_global = 1; move16(); @@ -1261,7 +1265,7 @@ ivas_error ivas_ism_metadata_dec_fx( } } - IF( ( error = ivas_ism_config_fx( ism_total_brate, *nchan_transport, nchan_ism, hIsmMeta, ism_extmeta_bitstream, null_metadata_flag, ism_imp, element_brate, total_brate, nb_bits_metadata, masa_ism_flag ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_config_fx( ism_total_brate, *nchan_transport, nchan_ism, hIsmMeta, ism_extmeta_bitstream, null_metadata_flag, ism_imp, element_brate, total_brate, nb_bits_metadata, masa_ism_flag ) ), IVAS_ERR_OK ) ) { return error; } @@ -1281,8 +1285,8 @@ ivas_error ivas_ism_metadata_dec_fx( test(); test(); test(); - IF( EQ_16( ism_imp[ch], ISM_NO_META ) && ( ( LT_32( total_brate[ch], ACELP_8k00 ) && LT_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) || - ( LE_32( total_brate[ch], ACELP_16k_LOW_LIMIT ) && GE_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) ) ) + if ( ism_imp[ch] == ISM_NO_META && ( ( LT_32( total_brate[ch], ACELP_8k00 ) && LT_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) || + ( LE_32( total_brate[ch], ACELP_16k_LOW_LIMIT ) && GE_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) ) ) { hSCE[ch]->hCoreCoder[0]->low_rate_mode = 1; move16(); @@ -1290,7 +1294,7 @@ ivas_error ivas_ism_metadata_dec_fx( } test(); - IF( NE_32( ism_mode, ISM_MASA_MODE_DISC ) && NE_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + if ( NE_32( ism_mode, ISM_MASA_MODE_DISC ) && NE_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { hSCE[ch]->element_brate = element_brate[ch]; move32(); @@ -1328,7 +1332,7 @@ ivas_error ivas_ism_metadata_dec_fx( /* set bitstream pointers for each ISM */ FOR( ch = 1; ch < *nchan_transport; ch++ ) { - hSCE[ch]->hCoreCoder[0]->bit_stream = hSCE[ch - 1]->hCoreCoder[0]->bit_stream + ( hSCE[ch - 1]->hCoreCoder[0]->total_brate / FRAMES_PER_SEC ); + hSCE[ch]->hCoreCoder[0]->bit_stream = ( hSCE[ch - 1]->hCoreCoder[0]->bit_stream + extract_l( Mpy_32_32( hSCE[ch - 1]->hCoreCoder[0]->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); } /*----------------------------------------------------------------* @@ -1410,7 +1414,7 @@ ivas_error ivas_ism_metadata_dec_create_fx( IF( element_brate_tmp != NULL ) { - IF( ( error = ivas_ism_config_fx( st_ivas->hDecoderConfig->ivas_total_brate, n_ISms, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_config_fx( st_ivas->hDecoderConfig->ivas_total_brate, n_ISms, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -1518,7 +1522,7 @@ static void decode_angle_indices_fx( nbits_diff_angle1 = 1; move16(); - IF( EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) /* negative sign */ + if ( EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) /* negative sign */ { sgn = -1; move16(); @@ -1527,13 +1531,13 @@ static void decode_angle_indices_fx( nbits_diff_angle1 = add( nbits_diff_angle1, 1 ); /* read until the stop bit */ - WHILE( LT_16( nbits_diff_angle1, sub( ISM_AZIMUTH_NBITS, 1 ) ) && EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) + WHILE( nbits_diff_angle1 < ( ISM_AZIMUTH_NBITS - 1 ) && get_next_indice_fx( st0, 1 ) == 1 ) { diff = add( diff, 1 ); nbits_diff_angle1 = add( nbits_diff_angle1, 1 ); } - IF( LT_16( nbits_diff_angle1, sub( ISM_AZIMUTH_NBITS, 1 ) ) ) + if ( LT_16( nbits_diff_angle1, ( ISM_AZIMUTH_NBITS - 1 ) ) ) { /* count stop bit */ nbits_diff_angle1 = add( nbits_diff_angle1, 1 ); @@ -1543,17 +1547,17 @@ static void decode_angle_indices_fx( } /* azimuth/yaw is on a circle - check for diff coding for -180° -> 180° and vice versa changes */ - IF( GT_16( idx_angle1, sub( shl( 1, ISM_AZIMUTH_NBITS ), 1 ) ) ) + IF( GT_16( idx_angle1, ( 1 << ISM_AZIMUTH_NBITS ) - 1 ) ) { - idx_angle1 = sub( idx_angle1, sub( shl( 1, ISM_AZIMUTH_NBITS ), 1 ) ); /* +180° -> -180° */ + idx_angle1 = sub( idx_angle1, ( 1 << ISM_AZIMUTH_NBITS ) - 1 ); /* +180° -> -180° */ } ELSE IF( idx_angle1 < 0 ) { - idx_angle1 = add( idx_angle1, sub( shl( 1, ISM_AZIMUTH_NBITS ), 1 ) ); /* -180° -> +180° */ + idx_angle1 = add( idx_angle1, ( 1 << ISM_AZIMUTH_NBITS ) - 1 ); /* -180° -> +180° */ } /* +180° == -180° */ - IF( EQ_16( idx_angle1, sub( shl( 1, ISM_AZIMUTH_NBITS ), 1 ) ) ) + if ( EQ_16( idx_angle1, ( 1 << ISM_AZIMUTH_NBITS ) - 1 ) ) { idx_angle1 = 0; move16(); @@ -1561,7 +1565,7 @@ static void decode_angle_indices_fx( /* sanity check in case of FER or BER */ test(); - IF( ( idx_angle1 < 0 ) || GT_16( idx_angle1, sub( shl( 1, ISM_AZIMUTH_NBITS ), 1 ) ) ) + if ( ( idx_angle1 < 0 ) || GT_16( idx_angle1, ( 1 << ISM_AZIMUTH_NBITS ) - 1 ) ) { idx_angle1 = angle->last_angle1_idx; move16(); @@ -1596,7 +1600,7 @@ static void decode_angle_indices_fx( nbits_diff_angle2 = 1; move16(); - IF( EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) /* negative sign */ + if ( EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) /* negative sign */ { sgn = -1; move16(); @@ -1605,25 +1609,25 @@ static void decode_angle_indices_fx( nbits_diff_angle2 = add( nbits_diff_angle2, 1 ); /* read until the stop bit */ - WHILE( LT_16( nbits_diff_angle2, ISM_ELEVATION_NBITS ) && EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) + WHILE( ( nbits_diff_angle2 < ISM_ELEVATION_NBITS ) && ( get_next_indice_fx( st0, 1 ) == 1 ) ) { diff = add( diff, 1 ); nbits_diff_angle2 = add( nbits_diff_angle2, 1 ); } - IF( LT_16( nbits_diff_angle2, ISM_ELEVATION_NBITS ) ) + if ( LT_16( nbits_diff_angle2, ISM_ELEVATION_NBITS ) ) { /* count stop bit */ nbits_diff_angle2 = add( nbits_diff_angle2, 1 ); } } - idx_angle2 = add( angle->last_angle2_idx, sgn * diff ); + idx_angle2 = add( angle->last_angle2_idx, i_mult( sgn, diff ) ); } /* sanity check in case of FER or BER */ test(); - IF( ( idx_angle2 < 0 ) || GT_16( idx_angle2, sub( shl( 1, ISM_ELEVATION_NBITS ), 1 ) ) ) + if ( ( idx_angle2 < 0 ) || GT_16( idx_angle2, ( ( 1 << ISM_ELEVATION_NBITS ) - 1 ) ) ) { idx_angle2 = angle->last_angle2_idx; move16(); @@ -1835,7 +1839,7 @@ static Word16 decode_radius_fx( nbits_diff_radius = 1; move16(); - IF( EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) /* negative sign */ + if ( EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) /* negative sign */ { sgn = -1; move16(); @@ -1844,7 +1848,7 @@ static Word16 decode_radius_fx( nbits_diff_radius = add( nbits_diff_radius, 1 ); /* read until the stop bit */ - WHILE( LT_16( nbits_diff_radius, ISM_RADIUS_NBITS ) && EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) + WHILE( ( nbits_diff_radius < ISM_RADIUS_NBITS ) && ( get_next_indice_fx( st0, 1 ) == 1 ) ) { diff = add( diff, 1 ); nbits_diff_radius = add( nbits_diff_radius, 1 ); @@ -1861,7 +1865,7 @@ static Word16 decode_radius_fx( /* sanity check in case of FER or BER */ test(); - IF( ( idx_radius < 0 ) || GT_16( idx_radius, sub( shl( 1, ISM_RADIUS_NBITS ), 1 ) ) ) + if ( ( idx_radius < 0 ) || GT_16( idx_radius, ( 1 << ISM_RADIUS_NBITS ) - 1 ) ) { idx_radius = *last_radius_idx; move16(); @@ -2133,7 +2137,7 @@ void ivas_ism_metadata_sid_dec_fx( Word16 next_bit_pos_orig; UWord16 bstr_meta[IVAS_SID_5k2 / FRAMES_PER_SEC], *bstr_orig; - IF( EQ_32( ism_total_brate, FRAME_NO_DATA ) ) + IF( ism_total_brate == FRAME_NO_DATA ) { ism_metadata_smooth_fx( hIsmMeta, ism_total_brate, nchan_ism ); @@ -2143,7 +2147,7 @@ void ivas_ism_metadata_sid_dec_fx( /* initialization */ st0 = hSCE[0]->hCoreCoder[0]; - last_bit_pos = extract_l( L_sub( ism_total_brate / FRAMES_PER_SEC, L_add( 1, SID_FORMAT_NBITS ) ) ); + last_bit_pos = extract_l( L_sub( Mpy_32_32( ism_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ), L_add( 1, SID_FORMAT_NBITS ) ) ); bstr_orig = st0->bit_stream; next_bit_pos_orig = st0->next_bit_pos; move16(); @@ -2169,7 +2173,7 @@ void ivas_ism_metadata_sid_dec_fx( /* number of objects was already read in ivas_ism_get_dtx_dec() */ /* update the position in the bitstream */ st0->next_bit_pos = add( st0->next_bit_pos, nchan_ism ); - + move16(); /* read SID metadata flag( one per object ) */ FOR( ch = 0; ch < nchan_ism; ch++ ) { @@ -2203,6 +2207,7 @@ void ivas_ism_metadata_sid_dec_fx( { /* read noisy speech flag */ *flag_noisy_speech = get_next_indice_fx( st0, 1 ); + move16(); nBits_sce_id = 1; move16(); } @@ -2212,24 +2217,24 @@ void ivas_ism_metadata_sid_dec_fx( { /* read sce id */ *sce_id_dtx = get_next_indice_fx( st0, nBits_sce_id ); - + move16(); /* decode the coherence */ FOR( ch = 0; ch < nchan_transport; ch++ ) { IF( EQ_16( ch, *sce_id_dtx ) ) { - hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = 32767; + hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = 32767; // 1.0f in Q15 move16(); CONTINUE; } idx = get_next_indice_fx( st0, nBits_coh ); - hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = div_s( idx, sub( ( shl( 1, nBits_coh ) ), 1 ) ); + hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = div_s( idx, sub( ( shl( 1, nBits_coh ) ), 1 ) ); // Q15 move16(); } } - IF( EQ_32( ism_mode, ISM_MODE_PARAM ) ) + if ( EQ_32( ism_mode, ISM_MODE_PARAM ) ) { hSCE[*sce_id_dtx]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = hSCE[!*sce_id_dtx]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx; move16(); @@ -2247,21 +2252,25 @@ void ivas_ism_metadata_sid_dec_fx( /* Azimuth decoding */ idx_azimuth = get_next_indice_fx( st0, nBits_azimuth ); hIsmMetaData->azimuth_fx = ism_dequant_meta_fx( idx_azimuth, ism_azimuth_borders_fx, q_step_fx, q_step_border_fx, 1 << nBits_azimuth ); - + move32(); /* Elevation decoding */ idx_elevation = get_next_indice_fx( st0, nBits_elevation ); hIsmMetaData->elevation_fx = ism_dequant_meta_fx( idx_elevation, ism_elevation_borders_fx, q_step_fx, q_step_border_fx, 1 << nBits_elevation ); - + move32(); /* update last indexes to correspond to active frames coding */ IF( GT_16( nBits_azimuth, ISM_AZIMUTH_NBITS ) ) { hIsmMetaData->position_angle.last_angle1_idx = shr( idx_azimuth, sub( nBits_azimuth, ISM_AZIMUTH_NBITS ) ); + move16(); hIsmMetaData->position_angle.last_angle2_idx = shr( idx_elevation, sub( nBits_elevation, ISM_ELEVATION_NBITS ) ); + move16(); } ELSE { hIsmMetaData->position_angle.last_angle1_idx = shl( idx_azimuth, sub( ISM_AZIMUTH_NBITS, nBits_azimuth ) ); + move16(); hIsmMetaData->position_angle.last_angle2_idx = shl( idx_elevation, sub( ISM_ELEVATION_NBITS, nBits_elevation ) ); + move16(); } /* save for smoothing metadata evolution */ @@ -2274,7 +2283,7 @@ void ivas_ism_metadata_sid_dec_fx( /* take into account padding bits as metadata bits to keep later bitrate checks valid */ Word32 res_dec, res_frac; - iDiv_and_mod_32( sub( IVAS_SID_5k2, SID_2k40 ), FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); + iDiv_and_mod_32( IVAS_SID_5k2 - SID_2k40, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); nb_bits_metadata[*sce_id_dtx] = (Word16) res_dec; move16(); diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 16b818327819f04df311caeb9280800284c5d20f..2c72c6b48c23ef5ab407e3953a1721f56bc6605c 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -67,9 +67,9 @@ static void ivas_param_ism_dec_dequant_DOA_fx( /* Get the azimuth and elevation values */ FOR( i = 0; i < nchan_ism; i++ ) { - hParamIsmDec->azimuth_values_fx[i] = ism_dequant_meta_fx( hParamIsm->azi_index[i], ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); + hParamIsmDec->azimuth_values_fx[i] = ism_dequant_meta_fx( hParamIsm->azi_index[i], ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); // Q22 move16(); - hParamIsmDec->elevation_values_fx[i] = ism_dequant_meta_fx( hParamIsm->ele_index[i], ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_ELEVATION_NBITS ); + hParamIsmDec->elevation_values_fx[i] = ism_dequant_meta_fx( hParamIsm->ele_index[i], ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_ELEVATION_NBITS ); // Q22 move16(); } @@ -113,9 +113,9 @@ static void ivas_param_ism_dec_dequant_powrat_fx( { FOR( slot_idx = 0; slot_idx < hParamIsm->nblocks[band_idx]; slot_idx++ ) { - hParamIsmDec->power_ratios_fx[band_idx][slot_idx][0] = add( shr( imult1616( hParamIsm->power_ratios_idx[band_idx][slot_idx], 4681 /* ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) in Q15 */ ), 1 ), 16384 ); /* Q15 */ + hParamIsmDec->power_ratios_fx[band_idx][slot_idx][0] = add( shr( imult1616( hParamIsm->power_ratios_idx[band_idx][slot_idx], 4681 /* ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) in Q15 */ ), 1 ), 16384 /*.5f in Q15 */ ); /* Q15 */ move16(); - hParamIsmDec->power_ratios_fx[band_idx][slot_idx][1] = sub( 32767, hParamIsmDec->power_ratios_fx[band_idx][slot_idx][0] ); + hParamIsmDec->power_ratios_fx[band_idx][slot_idx][1] = sub( 32767, hParamIsmDec->power_ratios_fx[band_idx][slot_idx][0] ); // Q15 , 32767= (1.0f in Q15) -1 move16(); } } @@ -149,7 +149,8 @@ static void ivas_param_ism_dec_dequant_powrat( #ifdef IVAS_FLOAT_FIXED static void ivas_ism_get_interpolator_fx( const Word16 subframe_nbslots, - Word16 *interpolator ) + Word16 *interpolator /*Q15*/ +) { Word16 interp_idx, q_tmp, tmp; @@ -183,7 +184,8 @@ static void ivas_ism_get_interpolator( static void ivas_ism_get_proto_matrix_fx( IVAS_OUTPUT_SETUP hOutSetup, const Word16 nchan_transport, - Word16 *proto_matrix ) + Word16 *proto_matrix /*Q15*/ +) { Word16 idx; @@ -198,16 +200,16 @@ static void ivas_ism_get_proto_matrix_fx( { IF( hOutSetup.ls_azimuth_fx[idx] > 0 ) { - proto_matrix[idx] = shl_sat( ONE_IN_Q14, 1 ); + proto_matrix[idx] = 32767; /* 1.0f in Q15 */ move16(); - proto_matrix[add( idx, hOutSetup.nchan_out_woLFE )] = 0; + proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0; move16(); } ELSE IF( hOutSetup.ls_azimuth_fx[idx] < 0 ) { proto_matrix[idx] = 0; move16(); - proto_matrix[idx + hOutSetup.nchan_out_woLFE] = shl_sat( ONE_IN_Q14, 1 ); + proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 32767; /* 1.0f in Q15 */ move16(); } ELSE @@ -284,14 +286,14 @@ static void ivas_ism_get_proto_matrix( #ifdef IVAS_FLOAT_FIXED static void ivas_param_ism_collect_slot_fx( PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */ - Word32 *Cldfb_RealBuffer_in_fx, + Word32 *Cldfb_RealBuffer_in_fx, /*Q(31-exp_real)*/ Word16 exp_real, - Word32 *Cldfb_ImagBuffer_in_fx, + Word32 *Cldfb_ImagBuffer_in_fx, /*Q(31-exp_imag)*/ Word16 exp_imag, const Word16 ch, - Word32 ref_power_fx[], + Word32 ref_power_fx[], /*Q(31-exp_ref_power)*/ Word16 *exp_ref_power, - Word32 cx_diag_fx[][PARAM_ISM_MAX_DMX], + Word32 cx_diag_fx[][PARAM_ISM_MAX_DMX], /*Q(31-exp_cx_diag)*/ Word16 *exp_cx_diag ) { Word16 band_idx, bin_idx; @@ -320,9 +322,9 @@ static void ivas_param_ism_collect_slot_fx( tmp_fx = 0; move32(); exp_tmp = 0; - move32(); - Word32 var1 = Mpy_32_32( Cldfb_RealBuffer_in_fx[bin_idx], Cldfb_RealBuffer_in_fx[bin_idx] ); // 2 * exp_real - Word32 var2 = Mpy_32_32( Cldfb_ImagBuffer_in_fx[bin_idx], Cldfb_ImagBuffer_in_fx[bin_idx] ); // 2 * exp_imag + move16(); + Word32 var1 = Mpy_32_32( Cldfb_RealBuffer_in_fx[bin_idx], Cldfb_RealBuffer_in_fx[bin_idx] ); // Q(31-2 * exp_real) + Word32 var2 = Mpy_32_32( Cldfb_ImagBuffer_in_fx[bin_idx], Cldfb_ImagBuffer_in_fx[bin_idx] ); // Q(31-2 * exp_imag) tmp_fx = BASOP_Util_Add_Mant32Exp( tmp_fx, exp_tmp, var1, add( exp_real, exp_real ), &exp_tmp ); tmp_fx = BASOP_Util_Add_Mant32Exp( tmp_fx, exp_tmp, var2, add( exp_imag, exp_imag ), &exp_tmp ); @@ -330,9 +332,9 @@ static void ivas_param_ism_collect_slot_fx( move16(); move16(); cx_diag_fx[bin_idx][ch] = BASOP_Util_Add_Mant32Exp( cx_diag_fx[bin_idx][ch], exp_cx_diag_buf[bin_idx][ch], tmp_fx, exp_tmp, &exp_cx_diag_new ); - move16(); + move32(); ref_power_fx[bin_idx] = BASOP_Util_Add_Mant32Exp( ref_power_fx[bin_idx], exp_ref_power_buf[bin_idx], tmp_fx, exp_tmp, &exp_ref_power_new ); - move16(); + move32(); exp_cx_diag_buf[bin_idx][ch] = exp_cx_diag_new; move16(); exp_ref_power_buf[bin_idx] = exp_ref_power_new; @@ -357,10 +359,10 @@ static void ivas_param_ism_collect_slot_fx( { FOR( j = 0; j < PARAM_ISM_MAX_DMX; j++ ) { - cx_diag_fx[i][j] = L_shr_r( cx_diag_fx[i][j], sub( max_exp_cx_diag, exp_cx_diag_buf[i][j] ) ); - move16(); + cx_diag_fx[i][j] = L_shr_r( cx_diag_fx[i][j], sub( max_exp_cx_diag, exp_cx_diag_buf[i][j] ) ); // Q(31-max_exp_cx_diag) + move32(); } - ref_power_fx[i] = L_shr_r( ref_power_fx[i], sub( max_exp_ref_power, exp_ref_power_buf[i] ) ); + ref_power_fx[i] = L_shr_r( ref_power_fx[i], sub( max_exp_ref_power, exp_ref_power_buf[i] ) ); // Q(31-max_exp_ref_power) move16(); } @@ -407,17 +409,17 @@ static void ivas_param_ism_collect_slot( #ifdef IVAS_FLOAT_FIXED static void ivas_param_ism_compute_mixing_matrix_fx( - const int16_t nchan_ism, /* i : number of ISM channels */ + const Word16 nchan_ism, /* i : number of ISM channels */ PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */ ISM_DTX_DATA_DEC hISMDTX, /* i : ISM DTX handle */ Word32 direct_response_fx[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN], // Q30 const Word16 nchan_transport, const Word16 nchan_out_woLFE, - Word32 cx_diag_fx[][PARAM_ISM_MAX_DMX], + Word32 cx_diag_fx[][PARAM_ISM_MAX_DMX], /*Q(31-cx_diag_e)*/ Word16 cx_diag_e, - Word32 ref_power_fx[], + Word32 ref_power_fx[], /*Q(31-ref_power_e)*/ Word16 ref_power_e, - Word32 mixing_matrix_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], + Word32 mixing_matrix_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], /*Q(31-mixing_matrix_e)*/ Word16 mixing_matrix_e[CLDFB_NO_CHANNELS_MAX] ) { Word16 band_idx, bin_idx; @@ -502,7 +504,7 @@ static void ivas_param_ism_compute_mixing_matrix_fx( move32(); BREAK; case 3: - direct_power_fx[w] = Mpy_32_16_1( ref_power_fx[bin_idx], 24576 ); + direct_power_fx[w] = Mpy_32_16_1( ref_power_fx[bin_idx], 10923 ); // 10923 = 1/3f in Q15 move32(); BREAK; case 4: @@ -513,7 +515,7 @@ static void ivas_param_ism_compute_mixing_matrix_fx( } ELSE { - direct_power_fx[w] = Mpy_32_16_1( ref_power_fx[bin_idx], hParamIsmDec->power_ratios_fx[band_idx][0][w] ); + direct_power_fx[w] = Mpy_32_16_1( ref_power_fx[bin_idx], hParamIsmDec->power_ratios_fx[band_idx][0][w] ); // Q(31-ref_power_e) move32(); } direct_power_e = ref_power_e; @@ -539,7 +541,7 @@ static void ivas_param_ism_compute_mixing_matrix_fx( } FOR( i = 0; i < nchan_out_woLFE; i++ ) { - cy_diag_fx[i] = L_shr_r( cy_diag_fx[i], sub( cy_diag_e, cy_diag_e_arr[i] ) ); + cy_diag_fx[i] = L_shr_r( cy_diag_fx[i], sub( cy_diag_e, cy_diag_e_arr[i] ) ); // cy_diag_e move32(); } @@ -551,7 +553,7 @@ static void ivas_param_ism_compute_mixing_matrix_fx( } FOR( w = 0; w < num_wave; w++ ) { - direct_power_fx[w] = L_shr_r( direct_power_fx[w], sub( direct_power_e, temp_e[w] ) ); + direct_power_fx[w] = L_shr_r( direct_power_fx[w], sub( direct_power_e, temp_e[w] ) ); // diract_power_e move32(); } @@ -665,13 +667,13 @@ static void ivas_param_ism_compute_mixing_matrix( static void ivas_param_ism_render_slot_fx( PARAM_ISM_DEC_HANDLE hParamIsmDec, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, - Word32 *Cldfb_RealBuffer_in_fx[PARAM_ISM_MAX_DMX], - Word32 *Cldfb_ImagBuffer_in_fx[PARAM_ISM_MAX_DMX], - Word32 Cldfb_RealBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], - Word32 Cldfb_ImagBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + Word32 *Cldfb_RealBuffer_in_fx[PARAM_ISM_MAX_DMX], /*Q11 (31-Cldfb_RealBuffer_tc_exp)*/ + Word32 *Cldfb_ImagBuffer_in_fx[PARAM_ISM_MAX_DMX], /*Q11 (31-Cldfb_ImagBuffer_tc_exp)*/ + Word32 Cldfb_RealBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*Q(31-exp_real)*/ + Word32 Cldfb_ImagBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*Q(31-exp_imag)*/ Word16 *exp_real, Word16 *exp_imag, - Word32 mixing_matrix_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], + Word32 mixing_matrix_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], /*Q(31-exp_mixing_matrix_lin_fx)*/ const Word16 interpolator_idx, const Word16 out_slot_idx, const Word16 num_ch_LS, @@ -717,8 +719,8 @@ static void ivas_param_ism_render_slot_fx( Word32 tmp_3 = Mpy_32_32( L_sub( ONE_IN_Q31, tmp_1_fx ), hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old_fx[bin_idx][outchIdx + inchIdx * num_ch_LS] ); // 1 + hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_old mixing_matrix_smooth_fx = BASOP_Util_Add_Mant32Exp( tmp_2, hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_fx[bin_idx], tmp_3, hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_old_fx[bin_idx], &res_exp ); - Word32 tmp_4 = Mpy_32_32( mixing_matrix_smooth_fx, Cldfb_RealBuffer_in_fx[inchIdx][bin_idx] ); // res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp - Word32 tmp_5 = Mpy_32_32( mixing_matrix_smooth_fx, Cldfb_ImagBuffer_in_fx[inchIdx][bin_idx] ); // res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp + Word32 tmp_4 = Mpy_32_32( mixing_matrix_smooth_fx, Cldfb_RealBuffer_in_fx[inchIdx][bin_idx] ); // Q(31-(res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp)) + Word32 tmp_5 = Mpy_32_32( mixing_matrix_smooth_fx, Cldfb_ImagBuffer_in_fx[inchIdx][bin_idx] ); // Q(31-(res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp)) Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx] = BASOP_Util_Add_Mant32Exp( Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx], real_buf_exp, tmp_4, res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp, &real_buf_exp ); @@ -752,9 +754,9 @@ static void ivas_param_ism_render_slot_fx( { FOR( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ ) { - Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx] = L_shr( Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx], sub( max_exp_real, exp_buf_real[outchIdx][out_slot_idx][bin_idx] ) ); + Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx] = L_shr( Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx], sub( max_exp_real, exp_buf_real[outchIdx][out_slot_idx][bin_idx] ) ); // Q(31-(max_exp_real)) move32(); - Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx] = L_shr( Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx], sub( max_exp_imag, exp_buf_imag[outchIdx][out_slot_idx][bin_idx] ) ); + Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx] = L_shr( Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx], sub( max_exp_imag, exp_buf_imag[outchIdx][out_slot_idx][bin_idx] ) ); // Q(31-(max_exp_imag)) move32(); } } @@ -932,7 +934,7 @@ static ivas_error ivas_param_ism_rendering_init( #ifdef IVAS_FLOAT_FIXED static void ivas_param_ism_update_mixing_matrix_fx( PARAM_ISM_DEC_HANDLE hParamIsmDec, - Word32 mixing_matrix_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], + Word32 mixing_matrix_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], /*Q(31-mixing_matrix_exp)*/ Word16 mixing_matrix_exp[CLDFB_NO_CHANNELS_MAX], const Word16 nchan_in, const Word16 nchan_out ) @@ -1107,14 +1109,14 @@ ivas_error ivas_param_ism_dec_open_fx( /* Initialize Param ISM Rendering handle */ IF( st_ivas->hDecoderConfig->Opt_tsm ) { - IF( ( error = ivas_param_ism_rendering_init_fx( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, MAX_JBM_CLDFB_TIMESLOTS, output_config ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_param_ism_rendering_init_fx( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, MAX_JBM_CLDFB_TIMESLOTS, output_config ) ), IVAS_ERR_OK ) ) { return error; } } ELSE { - IF( ( error = ivas_param_ism_rendering_init_fx( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, CLDFB_NO_COL_MAX, output_config ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_param_ism_rendering_init_fx( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, CLDFB_NO_COL_MAX, output_config ) ), IVAS_ERR_OK ) ) { return error; } @@ -1130,7 +1132,7 @@ ivas_error ivas_param_ism_dec_open_fx( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { /* Initialize efap handle */ - IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), hOutSetup.ls_azimuth_fx, hOutSetup.ls_elevation_fx, hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), hOutSetup.ls_azimuth_fx, hOutSetup.ls_elevation_fx, hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) ) { return error; } @@ -1152,12 +1154,12 @@ ivas_error ivas_param_ism_dec_open_fx( test(); IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { - IF( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 1 ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 2 ) ), IVAS_ERR_OK ) ) { return error; } @@ -1870,7 +1872,7 @@ void ivas_ism_dec_digest_tc_fx( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) || EQ_32( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) || - ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) && EQ_16( st_ivas->hDecoderConfig->Opt_Headrotation, 0 ) ) ) + ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) && st_ivas->hDecoderConfig->Opt_Headrotation == 0 ) ) { Word16 i, num_objects; Word32 azimuth_fx, elevation_fx; @@ -1909,7 +1911,7 @@ void ivas_ism_dec_digest_tc_fx( } ELSE { - ivas_jbm_dec_get_adapted_linear_interpolator_fx( (Word16) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ), st_ivas->hTcBuffer->n_samples_available, st_ivas->hIsmRendererData->interpolator_fx ); + ivas_jbm_dec_get_adapted_linear_interpolator_fx( extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), st_ivas->hTcBuffer->n_samples_available, st_ivas->hIsmRendererData->interpolator_fx ); move16(); } @@ -1924,16 +1926,16 @@ void ivas_ism_dec_digest_tc_fx( { Word16 gains_fx[2]; ivas_ism_get_stereo_gains_fx( (Word16) L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, 22 ), (Word16) L_shr( st_ivas->hIsmMetaData[i]->elevation_fx, 22 ), &gains_fx[0], &gains_fx[1] ); - st_ivas->hIsmRendererData->gains_fx[i][0] = L_shr( L_deposit_h( gains_fx[0] ), 1 ); - move16(); - st_ivas->hIsmRendererData->gains_fx[i][1] = L_shr( L_deposit_h( gains_fx[1] ), 1 ); - move16(); + st_ivas->hIsmRendererData->gains_fx[i][0] = L_shr( L_deposit_h( gains_fx[0] ), 1 ); // Q31 -> Q30 + move32(); + st_ivas->hIsmRendererData->gains_fx[i][1] = L_shr( L_deposit_h( gains_fx[1] ), 1 ); // Q31 -> Q30 + move32(); } ELSE { // TODO tmu review when #215 is resolved - azimuth_fx = L_shr( L_add( st_ivas->hIsmMetaData[i]->azimuth_fx, 2097152 ), Q22 ); - elevation_fx = L_shr( L_add( st_ivas->hIsmMetaData[i]->elevation_fx, 2097152 ), Q22 ); + azimuth_fx = L_shr( L_add( st_ivas->hIsmMetaData[i]->azimuth_fx, 2097152 ), Q22 ); // Q0 ,2097152 = .5f in Q22 + elevation_fx = L_shr( L_add( st_ivas->hIsmMetaData[i]->elevation_fx, 2097152 ), Q22 ); // Q0 ,2097152 = .5f in Q22 test(); test(); @@ -1954,8 +1956,8 @@ void ivas_ism_dec_digest_tc_fx( IF( st_ivas->hEFAPdata != NULL ) { - azimuth_fx = L_shl( azimuth_fx, Q22 ); - elevation_fx = L_shl( elevation_fx, Q22 ); + azimuth_fx = L_shl( azimuth_fx, Q22 ); // Q22 + elevation_fx = L_shl( elevation_fx, Q22 ); // Q22 efap_determine_gains_fx( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains_fx[i], azimuth_fx, elevation_fx, EFAP_MODE_EFAP ); } } @@ -1964,8 +1966,8 @@ void ivas_ism_dec_digest_tc_fx( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { /*get HOA gets for direction (ACN/SN3D)*/ - Word16 azi = shr( extract_h( st_ivas->hIsmMetaData[i]->azimuth_fx ), 22 - 16 ); - Word16 ele = shr( extract_h( st_ivas->hIsmMetaData[i]->elevation_fx ), 22 - 16 ); + Word16 azi = shr( extract_h( st_ivas->hIsmMetaData[i]->azimuth_fx ), 22 - 16 ); // Q0 + Word16 ele = shr( extract_h( st_ivas->hIsmMetaData[i]->elevation_fx ), 22 - 16 ); // Q0 ivas_dirac_dec_get_response_fx( azi, ele, st_ivas->hIsmRendererData->gains_fx[i], st_ivas->hIntSetup.ambisonics_order, Q30 ); } } @@ -2078,7 +2080,7 @@ void ivas_ism_dec_digest_tc( void ivas_param_ism_dec_digest_tc_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const UWord16 nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ - Word32 *transport_channels[], /* i : synthesized core-coder transport channels/DirAC output */ + Word32 *transport_channels[], /* i : synthesized core-coder transport channels/DirAC output q_tc_in*/ Word16 q_tc_in ) { Word16 exp_ref_power = 31, exp_cx_diag = 31; @@ -2200,27 +2202,27 @@ void ivas_param_ism_dec_digest_tc_fx( FOR( j = 0; j < nchan_out_woLFE; j++ ) { - IF( GT_32( hParamIsmDec->azimuth_values_fx[j], 0 ) ) + IF( hParamIsmDec->azimuth_values_fx[j] > 0 ) { - hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = 32767; + hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = 32767; // (1.0f in Q15) - 1 move16(); hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = 0; move16(); } ELSE { - IF( LT_32( hParamIsmDec->azimuth_values_fx[j], 0 ) ) + IF( hParamIsmDec->azimuth_values_fx[j] < 0 ) { hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = 0; move16(); - hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = 32767; + hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = 32767; // (1.0f in Q15) - 1 move16(); } ELSE /* == 0.0f */ { - hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = ONE_IN_Q14; + hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = ONE_IN_Q14; // Q15 move16(); - hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = ONE_IN_Q14; + hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = ONE_IN_Q14; // Q15 move16(); } } @@ -2235,7 +2237,7 @@ void ivas_param_ism_dec_digest_tc_fx( { FOR( i = 0; i < 2; i++ ) { - scale_sig32( transport_channels[i], output_frame, sub( q_tc_in, q_tc ) ); + scale_sig32( transport_channels[i], output_frame, sub( q_tc_in, q_tc ) ); // q_tc_in } q_tc = q_tc_in; move16(); @@ -2257,7 +2259,9 @@ void ivas_param_ism_dec_digest_tc_fx( Copy32( RealBuffer_fx, &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); Copy32( ImagBuffer_fx, &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp = sub( 31, q_tc ); + move16(); hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp = sub( 31, q_tc ); + move16(); } Word16 scale_factor_real, scale_factor_imag; Word16 current_idx; @@ -2268,8 +2272,8 @@ void ivas_param_ism_dec_digest_tc_fx( current_idx = add( imult1616( imult1616( slot_idx, hSpatParamRendCom->num_freq_bands ), nchan_transport ), imult1616( ch, hSpatParamRendCom->num_freq_bands ) ); scale_factor_real = getScaleFactor32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands ); scale_factor_imag = getScaleFactor32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands ); - scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, scale_factor_real ); - scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, scale_factor_imag ); + scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, scale_factor_real ); // Q(31-(exp_real_tmp-scale_factor_real)) + scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, scale_factor_imag ); // Q(31-(exp_imag_tmp-scale_factor_imag)) exp_real_tmp = sub( exp_real_tmp, scale_factor_real ); exp_imag_tmp = sub( exp_imag_tmp, scale_factor_imag ); ivas_param_ism_collect_slot_fx( hParamIsmDec, @@ -2282,8 +2286,8 @@ void ivas_param_ism_dec_digest_tc_fx( exp_real_tmp = add( exp_real_tmp, scale_factor_real ); exp_imag_tmp = add( exp_imag_tmp, scale_factor_imag ); - scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, -scale_factor_real ); - scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, -scale_factor_imag ); + scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, -scale_factor_real ); // Q(31-(exp_real_tmp)) + scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, -scale_factor_imag ); // Q(31-(exp_imag_tmp)) } } /* Obtain Mixing Matrix on a frame-level */ @@ -2582,13 +2586,13 @@ void ivas_ism_param_dec_tc_gain_ajust_fx( L_tmp1 = BASOP_Util_Add_Mant32Exp( ch0, ch0_e, ch1, ch1_e, &tmp_e1 ); /*L + R*/ - L_tmp1 = Mpy_32_32( L_tmp1, L_tmp1 ); /*(L + R)*(L + R)*/ + L_tmp1 = Mpy_32_32( L_tmp1, L_tmp1 ); // Q(31-(tmp_e1+tmp_e1 /*(L + R)*(L + R)*/ tmp_e1 = add( tmp_e1, tmp_e1 ); ene_sum_fx = BASOP_Util_Add_Mant32Exp( ene_sum_fx, ene_sum_e, L_tmp1, tmp_e1, &ene_sum_e ); } - IF( NE_32( ene_sum_fx, 0 ) ) + IF( ene_sum_fx != 0 ) { gain_fx = BASOP_Util_Divide3232_Scale( ene_tc_fx, ene_sum_fx, &tmp_e1 ); } @@ -2605,7 +2609,7 @@ void ivas_ism_param_dec_tc_gain_ajust_fx( { /*handling denominator equals to zero*/ gain_fx = 1; move16(); - tmp_e1 = -32767; + tmp_e1 = -32767; //(-1.0f in Q15) + 1 move16(); } } @@ -2617,41 +2621,41 @@ void ivas_ism_param_dec_tc_gain_ajust_fx( IF( GT_16( tmp_e2, tmp_e1 ) ) { - gain_fx = shr( gain_fx, tmp_e2 - tmp_e1 ); + gain_fx = shr( gain_fx, sub( tmp_e2, tmp_e1 ) ); // Q(15-tmp_e2) tmp_e1 = tmp_e2; move16(); } ELSE { - last_gain_fx = shr( last_gain_fx, tmp_e1 - tmp_e2 ); + last_gain_fx = shr( last_gain_fx, sub( tmp_e1, tmp_e2 ) ); // Q(15-tmp_e1) } IF( st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame > 1 ) { /* Smoothing */ - gain_fx = add( mult_r( 24574, gain_fx ), mult_r( 8192, last_gain_fx ) ); + gain_fx = add( mult_r( 24574, gain_fx ), mult_r( 8192, last_gain_fx ) ); // 24574 =.75f in Q15 , 8192=.25f in Q15 /* 10ms ramp */ /* slope between two consecutive gains, 480 samples length */ - invFade = div_s( 1, nFadeLength ); + invFade = div_s( 1, nFadeLength ); // Q15 tmp = 0; move16(); FOR( i = 0; i < ( nFadeLength ); i++ ) { /* tmp2 = ( last_gain_fx + i * grad_fx )*/ - tmp2 = add( mult_r( sub( 32767, tmp ), last_gain_fx ), mult_r( tmp, gain_fx ) ); + tmp2 = add( mult_r( sub( 32767, tmp ), last_gain_fx ), mult_r( tmp, gain_fx ) ); // 32767= 1.0f in Q15, - transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], tmp2 ); + transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], tmp2 ); // Q(Q_tc-tmp_e1) move32(); - transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], tmp2 ); + transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], tmp2 ); // Q(Q_tc-tmp_e1) move32(); tmp = add( tmp, invFade ); } FOR( ; i < nSamples; i++ ) { - transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], gain_fx ); + transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], gain_fx ); // Q(Q_tc-tmp_e1) move32(); - transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], gain_fx ); + transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], gain_fx ); // Q(Q_tc-tmp_e1) move32(); } } @@ -2659,9 +2663,9 @@ void ivas_ism_param_dec_tc_gain_ajust_fx( { FOR( i = 0; i < nSamples; i++ ) { - transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], gain_fx ); + transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], gain_fx ); // Q(Q_tc-tmp_e1) move32(); - transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], gain_fx ); + transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], gain_fx ); // Q(Q_tc-tmp_e1) move32(); } } @@ -2689,15 +2693,15 @@ static void ivas_ism_param_dec_render_sf_fx( const int16_t nchan_transport, const int16_t nchan_out, const int16_t nchan_out_woLFE, - Word32 *output_f_fx[], + Word32 *output_f_fx[], /*Q_output*/ Word16 Q_output[] ) { Word16 ch, slot_idx, i, index_slot; /* CLDFB Output Buffers */ - Word32 Cldfb_RealBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - Word32 Cldfb_ImagBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - Word32 *Cldfb_RealBuffer_in_fx[PARAM_ISM_MAX_DMX]; - Word32 *Cldfb_ImagBuffer_in_fx[PARAM_ISM_MAX_DMX]; + Word32 Cldfb_RealBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; // Q(31-real_exp) + Word32 Cldfb_ImagBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; // Q(31-imag_exp) + Word32 *Cldfb_RealBuffer_in_fx[PARAM_ISM_MAX_DMX]; // Q11 + Word32 *Cldfb_ImagBuffer_in_fx[PARAM_ISM_MAX_DMX]; // Q11 PARAM_ISM_DEC_HANDLE hParamIsmDec; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; Word16 slot_idx_start; @@ -2726,8 +2730,8 @@ static void ivas_ism_param_dec_render_sf_fx( Word16 imag_exp[JBM_CLDFB_SLOTS_IN_SUBFRAME]; FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - index_slot = slot_idx_start + slot_idx; - move16(); + index_slot = add( slot_idx_start, slot_idx ); + FOR( ch = 0; ch < nchan_transport; ch++ ) { @@ -2787,15 +2791,15 @@ static void ivas_ism_param_dec_render_sf_fx( FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) { - Scale_sig32( RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, add( sub( Q_real, 31 ), real_exp[i] ) ); - Scale_sig32( ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, add( sub( Q_real, 31 ), imag_exp[i] ) ); + Scale_sig32( RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, add( sub( Q_real, 31 ), real_exp[i] ) ); // Q_real + Scale_sig32( ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, add( sub( Q_real, 31 ), imag_exp[i] ) ); // Q_real } - Scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( sub( Q_real, 1 ), Q11 ) ); + Scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( sub( Q_real, 1 ), Q11 ) ); // Q_real-1 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = sub( Q_real, 1 ); move16(); - cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, output_f_fx[ch], hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] ); - Scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( Q11, sub( Q_real, 1 ) ) ); + cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, output_f_fx[ch], i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), st_ivas->cldfbSynDec[ch] ); + Scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( Q11, sub( Q_real, 1 ) ) ); // Q11 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; move16(); @@ -2808,13 +2812,12 @@ static void ivas_ism_param_dec_render_sf_fx( Word32 res_dec, res_frac; iDiv_and_mod_32( sub( add( samplesProcessed, st_ivas->cldfbSynDec[ch]->no_channels ), 1 ), st_ivas->cldfbSynDec[ch]->no_channels, &res_dec, &res_frac, 0 ); no_col_cldfb = s_min( no_col_cldfb, extract_l( res_dec ) ); - move16(); } size_cldfb = imult1616( st_ivas->cldfbSynDec[ch]->no_channels, no_col_cldfb ); - Scale_sig32( output_f_fx[ch], size_cldfb, sub( Q11, sub( Q_real, 1 ) ) ); + Scale_sig32( output_f_fx[ch], size_cldfb, sub( Q11, sub( Q_real, 1 ) ) ); // Q11 - Q_output[ch] = sub( Q_real, 1 ); + Q_output[ch] = 11; move16(); idx_in = add( idx_in, 1 ); } @@ -2930,7 +2933,8 @@ void ivas_param_ism_dec_render_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *output_f_fx[] ) + Word32 *output_f_fx[] /*Q11*/ +) { Word16 ch, slots_to_render, first_sf, last_sf, subframe_idx; @@ -2967,7 +2971,7 @@ void ivas_param_ism_dec_render_fx( move16(); } slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); - move16(); + /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ Word32 res_dec, res_frac; iDiv_and_mod_32( nSamplesAsked, slot_size, &res_dec, &res_frac, 0 ); @@ -2995,7 +2999,7 @@ void ivas_param_ism_dec_render_fx( { ivas_ism_param_dec_render_sf_fx( st_ivas, hSetup, nchan_transport, nchan_out, nchan_out_woLFE, output_f_local_fx, Q_output ); - n_samples_sf = hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->slot_size; + n_samples_sf = i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slot_size ); FOR( ch = 0; ch < nchan_out; ch++ ) { output_f_local_fx[ch] += n_samples_sf; @@ -3149,7 +3153,7 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( move32(); test(); - IF( !( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) ) + IF( !( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || ivas_total_brate == FRAME_NO_DATA ) ) { ivas_param_ism_dec_dequant_DOA_fx( hParamIsmDec, st_ivas->nchan_ism ); ivas_param_ism_dec_dequant_powrat_fx( hParamIsmDec ); @@ -3171,9 +3175,9 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( hSpatParamRendCom->numSimultaneousDirections = 1; move16(); - azimuth[0] = (Word16) L_shr( L_add( hParamIsmDec->azimuth_values_fx[0], ONE_IN_Q21 ), 22 ); + azimuth[0] = extract_l( L_shr( L_add( hParamIsmDec->azimuth_values_fx[0], ONE_IN_Q21 ), 22 ) ); // Q0 move16(); - elevation[0] = (Word16) L_shr( L_add( hParamIsmDec->elevation_values_fx[0], ONE_IN_Q21 ), 22 ); + elevation[0] = extract_l( L_shr( L_add( hParamIsmDec->elevation_values_fx[0], ONE_IN_Q21 ), 22 ) ); // Q0 move16(); FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) @@ -3204,15 +3208,15 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1]; move16(); - azimuth[0] = (Word16) L_shr( hParamIsmDec->azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] + ( 1 << 21 ), 22 ); + azimuth[0] = extract_l( L_shr( L_add( hParamIsmDec->azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]], ( 1 << 21 ) ), 22 ) ); // Q0 move16(); - elevation[0] = (Word16) L_shr( hParamIsmDec->elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] + ( 1 << 21 ), 22 ); + elevation[0] = extract_l( L_shr( L_add( hParamIsmDec->elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]], ( 1 << 21 ) ), 22 ) ); // Q0 move16(); power_ratio_fx[0] = hParamIsmDec->power_ratios_fx[band_idx][0][0]; move16(); - azimuth[1] = (Word16) L_shr( hParamIsmDec->azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] + ( 1 << 21 ), 22 ); + azimuth[1] = extract_l( L_shr( L_add( hParamIsmDec->azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]], ( 1 << 21 ) ), 22 ) ); // Q0 move16(); - elevation[1] = (Word16) L_shr( hParamIsmDec->elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] + ( 1 << 21 ), 22 ); + elevation[1] = extract_l( L_shr( L_add( hParamIsmDec->elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]], ( 1 << 21 ) ), 22 ) ); // Q0 move16(); power_ratio_fx[1] = hParamIsmDec->power_ratios_fx[band_idx][0][1]; move16(); @@ -3225,13 +3229,13 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( move16(); hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0]; move16(); - hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx] = L_shl( power_ratio_fx[0], Q15 ); + hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx] = L_shl( power_ratio_fx[0], Q15 ); // Q30 move32(); hSpatParamRendCom->azimuth2[sf_idx][bin_idx] = azimuth[1]; move16(); hSpatParamRendCom->elevation2[sf_idx][bin_idx] = elevation[1]; move16(); - hSpatParamRendCom->energy_ratio2_fx[sf_idx][bin_idx] = L_shl( power_ratio_fx[1], Q15 ); + hSpatParamRendCom->energy_ratio2_fx[sf_idx][bin_idx] = L_shl( power_ratio_fx[1], Q15 ); // Q30 move32(); } } @@ -3255,9 +3259,9 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( { hSpatParamRendCom->numSimultaneousDirections = 1; move16(); - azimuth[0] = (Word16) L_shr( ( hParamIsmDec->azimuth_values_fx[0] + ( 1 << 21 ) ), 22 ); + azimuth[0] = extract_l( L_shr( ( L_add( hParamIsmDec->azimuth_values_fx[0], ( 1 << 21 ) ) ), 22 ) ); // Q0 move16(); - elevation[0] = (Word16) L_shr( hParamIsmDec->elevation_values_fx[0] + ( 1 << 21 ), 22 ); + elevation[0] = extract_l( L_shr( L_add( hParamIsmDec->elevation_values_fx[0], ( 1 << 21 ) ), 22 ) ); // Q0 move16(); FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index b910052d877402f6fa4870dd1187283df861a6ff..68998a30e3c170449f11f17ae7c394c01ba6a14b 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -178,7 +178,7 @@ ivas_error ivas_ism_renderer_open_fx( st_ivas->hIsmRendererData->interpolator_fx[i] = div_s( i, sub( interpolator_length, 1 ) ); move16(); } - st_ivas->hIsmRendererData->interpolator_fx[sub( interpolator_length, 1 )] = 32767; + st_ivas->hIsmRendererData->interpolator_fx[interpolator_length - 1] = 32767; // (1.0f in Q15 )- 1 move16(); return IVAS_ERR_OK; @@ -218,7 +218,7 @@ void ivas_ism_renderer_close( ) { test(); - if ( hIsmRendererData == NULL || *hIsmRendererData == NULL ) + IF( hIsmRendererData == NULL || *hIsmRendererData == NULL ) { return; } @@ -374,7 +374,7 @@ void ivas_ism_render_sf( #else void ivas_ism_render_sf_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_fx[], /* i/o: core-coder transport channels/object output */ + Word32 *output_fx[], /* i/o: core-coder transport channels/object output Q11*/ const Word16 n_samples_to_render /* i : output frame length per channel */ ) { @@ -409,7 +409,7 @@ void ivas_ism_render_sf_fx( { FOR( i = 0; i < num_objects; i++ ) { - p_tc_fx[i] = &st_ivas->hTcBuffer->tc_fx[i][tc_offset]; + p_tc_fx[i] = &st_ivas->hTcBuffer->tc_fx[i][tc_offset]; // Q11 } } ELSE @@ -440,9 +440,7 @@ void ivas_ism_render_sf_fx( test(); IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx], 1 ) ) { - rotateAziEle_fx( (Word16) L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, 22 ), (Word16) L_shr( st_ivas->hIsmMetaData[i]->elevation_fx, 22 ), &azimuth, &elevation, st_ivas->hCombinedOrientationData->Rmat_fx[0], st_ivas->hIntSetup.is_planar_setup ); - move16(); - move16(); + rotateAziEle_fx( extract_l( L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, 22 ) ), extract_l( L_shr( st_ivas->hIsmMetaData[i]->elevation_fx, 22 ) ), &azimuth, &elevation, st_ivas->hCombinedOrientationData->Rmat_fx[0], st_ivas->hIntSetup.is_planar_setup ); IF( st_ivas->hEFAPdata != NULL ) { @@ -480,8 +478,8 @@ void ivas_ism_render_sf_fx( tc_fx = p_tc_fx[i]; FOR( k = 0; k < n_samples_to_render; k++ ) { - g2_fx = sub( 32767, *g1_fx ); - output_fx[j2][k] = L_add( output_fx[j2][k], L_shl( Mpy_32_32( L_add( Mpy_32_16_1( gain_fx, *( g1_fx++ ) ), Mpy_32_16_1( prev_gain_fx, g2_fx ) ), *( tc_fx++ ) ), 1 ) ); + g2_fx = sub( 32767, *g1_fx ); // 32767 = (1.0f in Q15) - 1 + output_fx[j2][k] = L_add( output_fx[j2][k], L_shl( Mpy_32_32( L_add( Mpy_32_16_1( gain_fx, *( g1_fx++ ) ), Mpy_32_16_1( prev_gain_fx, g2_fx ) ), *( tc_fx++ ) ), 1 ) ); // Q11( (30+15+1-16) + 11 -31 +1) move16(); } } @@ -490,7 +488,7 @@ void ivas_ism_render_sf_fx( test(); IF( st_ivas->hCombinedOrientationData != NULL && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] == 1 ) { - st_ivas->hIsmRendererData->prev_gains_fx[i][j] = gain_fx; + st_ivas->hIsmRendererData->prev_gains_fx[i][j] = gain_fx; // Q30 move32(); } } @@ -512,10 +510,10 @@ void ivas_ism_render_sf_fx( #ifdef IVAS_FLOAT_FIXED void ivas_ism_get_stereo_gains_fx( - const Word16 aziDeg, /* i : object azimuth */ - const Word16 eleDeg, /* i : object elevation */ - Word16 *left_gain_fx, /* o : left channel gain */ - Word16 *right_gain_fx /* o : right channel gain */ + const Word16 aziDeg, /* i : object azimuth Q0*/ + const Word16 eleDeg, /* i : object elevation Q0*/ + Word16 *left_gain_fx, /* o : left channel gain Q15*/ + Word16 *right_gain_fx /* o : right channel gain Q15*/ ) { /* Convert azi and ele to an azi value of the cone of confusion */ @@ -525,27 +523,27 @@ void ivas_ism_get_stereo_gains_fx( const Word16 *ptr_sin_az = ivas_sin_az_fx; - WHILE( GT_16( azAddEl, 180 ) ) + WHILE( azAddEl > 180 ) { azAddEl = sub( azAddEl, 360 ); } - WHILE( LT_16( azAddEl, -180 ) ) + WHILE( azAddEl < -180 ) { azAddEl = add( azAddEl, 360 ); } - WHILE( GT_16( azSubEl, 180 ) ) + WHILE( azSubEl > 180 ) { azSubEl = sub( azSubEl, 360 ); } - WHILE( LT_16( azSubEl, -180 ) ) + WHILE( azSubEl < -180 ) { azSubEl = add( azSubEl, 360 ); } Word16 sin_az_cos_el = extract_l( L_shr( L_add( L_deposit_l( ptr_sin_az[azAddEl + 180] ), L_deposit_l( ptr_sin_az[azSubEl + 180] ) ), 1 ) ); IF( GE_16( sin_az_cos_el, SIN_30_DEGREES_Q15 ) ) - { /* Left side */ - gains[0] = (Word16) 0x7fff; + { /* Left side */ + gains[0] = (Word16) 0x7fff; // 1.0f in Q15 move16(); gains[1] = 0; move16(); @@ -554,7 +552,7 @@ void ivas_ism_get_stereo_gains_fx( { /* Right side */ gains[0] = 0; move16(); - gains[1] = (Word16) 0x7fff; + gains[1] = (Word16) 0x7fff; // 1.0f in Q15 move16(); } ELSE /* Tangent panning law */ @@ -984,8 +982,8 @@ void ivas_omasa_separate_object_render_jbm( void ivas_omasa_separate_object_render_jbm_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const UWord16 nSamplesRendered, /* i : number of samples rendered */ - Word32 input_fx_in[][L_FRAME48k], /* i : separated object signal */ - Word32 *output_fx[], /* o : rendered time signal */ + Word32 input_fx_in[][L_FRAME48k], /* i : separated object signal Q11*/ + Word32 *output_fx[], /* o : rendered time signal Q11*/ const Word16 subframes_rendered, /* i : number of subframes rendered */ const Word16 slots_rendered /* i : number of CLDFB slots rendered */ ) @@ -1038,7 +1036,7 @@ void ivas_omasa_separate_object_render_jbm_fx( offsetSamples = i_mult( slots_rendered, hSpatParamRendCom->slot_size ); - FOR( j = 0; j < add( nchan_out_woLFE, num_lfe ); j++ ) + FOR( j = 0; j < nchan_out_woLFE + num_lfe; j++ ) { output_fx_local[j] = output_fx[j]; } @@ -1137,7 +1135,7 @@ void ivas_omasa_separate_object_render_jbm_fx( { IF( hDirACRend->hOutSetup.num_lfe > 0 ) { - j2 = add( j, (Word16) GE_16( j, lfe_index ) ); + j2 = add( j, extract_l( GE_16( j, lfe_index ) ) ); } ELSE { @@ -1152,9 +1150,9 @@ void ivas_omasa_separate_object_render_jbm_fx( { g1_fx = hRendererData->interpolator_fx[k]; move16(); - g2_fx = sub( 32767, g1_fx ); + g2_fx = sub( 32767, g1_fx ); // 32767 = 1.0f in Q15 - output_fx_local[j2][k + offsetSamples] = L_add( output_fx_local[j2][add( k, offsetSamples )], L_add( L_shl( Mpy_32_32( Mpy_32_16_1( input_fx[obj][k + offsetSamples], g1_fx ), gains_fx[j] ), 2 ), L_shl( Mpy_32_32( Mpy_32_16_1( input_fx[obj][add( k, offsetSamples )], g2_fx ), hRendererData->prev_gains_fx[obj][j] ), 2 ) ) ); + output_fx_local[j2][k + offsetSamples] = L_add( output_fx_local[j2][k + offsetSamples], L_add( L_shl( Mpy_32_32( Mpy_32_16_1( input_fx[obj][k + offsetSamples], g1_fx ), gains_fx[j] ), 2 ), L_shl( Mpy_32_32( Mpy_32_16_1( input_fx[obj][k + offsetSamples], g2_fx ), hRendererData->prev_gains_fx[obj][j] ), 2 ) ) ); // Q11( (30+15+1-16) + 11 -31 +1) move32(); } } diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 14101fcd004efde4389387092699a8c4449e3103..106affd0851a4c5e24cbd14dbb40ceb8aacafc4f 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -97,11 +97,12 @@ static Word16 ceil_fx16( Word16 inp, Word16 Q ) #ifdef IVAS_FLOAT_FIXED ivas_error ivas_jbm_dec_tc_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *data_fx ) + Word32 *data_fx /*Q11*/ +) { Word16 n, output_frame, nchan_out, i; Decoder_State *st; /* used for bitstream handling */ - Word32 *p_output_fx[MAX_TRANSPORT_CHANNELS]; /* 'float' buffer for output synthesis */ + Word32 *p_output_fx[MAX_TRANSPORT_CHANNELS]; /* buffer for output synthesis */ Word16 nchan_remapped; Word16 nb_bits_metadata[MAX_SCE + 1]; Word32 output_Fs, ivas_total_brate; @@ -132,6 +133,7 @@ ivas_error ivas_jbm_dec_tc_fx( FOR( n = 0; n < MAX_TRANSPORT_CHANNELS; n++ ) { p_output_fx[n] = st_ivas->p_output_fx[n]; + IF( p_output_fx[n] != NULL ) { set32_fx( p_output_fx[n], 0, L_FRAME48k ); @@ -188,8 +190,8 @@ ivas_error ivas_jbm_dec_tc_fx( IF( NE_16( q_output, Q11 ) ) { - Scale_sig32( p_output_fx[0], L_FRAME48k, sub( Q11, q_output ) ); - Scale_sig32( p_output_fx[1], L_FRAME48k, sub( Q11, q_output ) ); + Scale_sig32( p_output_fx[0], L_FRAME48k, sub( Q11, q_output ) ); // Q11 + Scale_sig32( p_output_fx[1], L_FRAME48k, sub( Q11, q_output ) ); // Q11 } /* HP filtering */ @@ -206,12 +208,12 @@ ivas_error ivas_jbm_dec_tc_fx( s = sub( s, find_guarded_bits_fx( st_ivas->nchan_transport ) ); FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i ) { - Scale_sig32( p_output_fx[i], output_frame, s ); + Scale_sig32( p_output_fx[i], output_frame, s ); // Q(11+s) } ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, output_frame, p_output_fx, p_output_fx ); FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i ) { - Scale_sig32( p_output_fx[i], output_frame, negate( s ) ); + Scale_sig32( p_output_fx[i], output_frame, negate( s ) ); // Q11 } } } @@ -239,7 +241,7 @@ ivas_error ivas_jbm_dec_tc_fx( { shift = sub( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + scale_sig32( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-(cngNoiseLevelExp -shift) ) st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); Q_cngNoiseLevel[ch] = sub( 31, st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); move16(); @@ -298,7 +300,7 @@ ivas_error ivas_jbm_dec_tc_fx( FOR( i = 0; i < st_ivas->nchan_transport; i++ ) { - Scale_sig32( p_output_fx[i], output_frame, 1 ); + Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q } } } @@ -322,7 +324,7 @@ ivas_error ivas_jbm_dec_tc_fx( st = st_ivas->hCPE[0]->hCoreCoder[0]; } - IF( ( error = ivas_masa_decode_fx( st_ivas, st, &nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_decode_fx( st_ivas, st, &nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) { return error; } @@ -334,7 +336,7 @@ ivas_error ivas_jbm_dec_tc_fx( } ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) { - IF( ( error = ivas_spar_dec_fx( st_ivas, nb_bits_metadata ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_dec_fx( st_ivas, nb_bits_metadata ) ), IVAS_ERR_OK ) ) { return error; } @@ -369,7 +371,7 @@ ivas_error ivas_jbm_dec_tc_fx( #ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0], &q_output ) ) != IVAS_ERR_OK ) #else - IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) #endif { return error; @@ -377,8 +379,8 @@ ivas_error ivas_jbm_dec_tc_fx( IF( NE_16( q_output, Q11 ) ) { - Scale_sig32( p_output_fx[0], L_FRAME48k, sub( Q11, q_output ) ); - Scale_sig32( p_output_fx[1], L_FRAME48k, sub( Q11, q_output ) ); + Scale_sig32( p_output_fx[0], L_FRAME48k, sub( Q11, q_output ) ); // Q11 + Scale_sig32( p_output_fx[1], L_FRAME48k, sub( Q11, q_output ) ); // Q11 } } ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) @@ -407,7 +409,7 @@ ivas_error ivas_jbm_dec_tc_fx( { FOR( i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) { - Scale_sig32( p_output_fx[i], output_frame, Q14 - Q11 ); + Scale_sig32( p_output_fx[i], output_frame, Q14 - Q11 ); // Q14 } SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; Word16 nchan_transport; @@ -437,7 +439,7 @@ ivas_error ivas_jbm_dec_tc_fx( } FOR( i = 0; i < 2; i++ ) { - Scale_sig32( p_output_fx[i], L_FRAME48k, s ); + Scale_sig32( p_output_fx[i], L_FRAME48k, s ); // Q(11+s) } hCPE->hStereoDft->q_dft = add( Q11, s ); move16(); @@ -450,16 +452,16 @@ ivas_error ivas_jbm_dec_tc_fx( } q = hCPE->hStereoDft->q_dft; move16(); - scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft FOR( i = 0; i < CPE_CHANNELS; ++i ) { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); - scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft + scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft } IF( hCPE->hCoreCoder[0] != NULL ) { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; move16(); } @@ -484,15 +486,15 @@ ivas_error ivas_jbm_dec_tc_fx( test(); test(); test(); - IF( ( ( st->last_core != ACELP_CORE || ( EQ_16( st->prev_bfi, 1 ) && st->last_core == ACELP_CORE && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */ + IF( ( ( ( st->last_core != ACELP_CORE ) || ( EQ_16( st->prev_bfi, 1 ) && ( st->last_core == ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */ { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft } ELSE IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) /* ACELP -> TCX/HQ */ { IF( !st->tcxonly ) { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft } } } @@ -508,7 +510,7 @@ ivas_error ivas_jbm_dec_tc_fx( test(); IF( ( LE_16( st->last_L_frame, L_FRAME16k ) && LE_16( st->L_frame, L_FRAME16k ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) ) { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft } } } @@ -516,30 +518,30 @@ ivas_error ivas_jbm_dec_tc_fx( #else scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); #endif - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); + scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // q_dft hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft; move16(); } IF( hSCE != NULL ) { - Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mult_32_16( hCPE->hCoreCoder[0]->output_Fs, INV_FRAME_PER_SEC_Q15 ) ), sub( hCPE->hStereoDft->q_dft, hSCE->q_save_hb_synth_fx ) ); + Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mult_32_16( hCPE->hCoreCoder[0]->output_Fs, INV_FRAME_PER_SEC_Q15 ) ), sub( hCPE->hStereoDft->q_dft, hSCE->q_save_hb_synth_fx ) ); // q_dft hSCE->q_save_hb_synth_fx = hCPE->hStereoDft->q_dft; move16(); - Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mult_32_16( hCPE->hCoreCoder[0]->output_Fs, INV_FRAME_PER_SEC_Q15 ) ), sub( hCPE->hStereoDft->q_dft, hSCE->q_save_synth_fx ) ); + Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mult_32_16( hCPE->hCoreCoder[0]->output_Fs, INV_FRAME_PER_SEC_Q15 ) ), sub( hCPE->hStereoDft->q_dft, hSCE->q_save_synth_fx ) ); // q_dft hSCE->q_save_synth_fx = hCPE->hStereoDft->q_dft; move16(); } FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; move16(); } #ifdef MSAN_FIX FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), hCPE->q_prev_synth_fx - 11 ); + Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), hCPE->q_prev_synth_fx - 11 ); // q_prev_synth_fx } #else Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), hCPE->q_prev_synth_fx - 11 ); @@ -554,7 +556,7 @@ ivas_error ivas_jbm_dec_tc_fx( #ifdef MSAN_FIX FOR( int ii = 0; ii < CPE_CHANNELS; ii++ ) { - Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), 11 - hCPE->q_prev_synth_fx ); + Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( 11, hCPE->q_prev_synth_fx ) ); // Q11 } #else Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), 11 - hCPE->q_prev_synth_fx ); @@ -563,14 +565,14 @@ ivas_error ivas_jbm_dec_tc_fx( scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); FOR( i = 0; i < CPE_CHANNELS; ++i ) { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); - scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 + scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 } IF( hCPE->hCoreCoder[0] != NULL ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB - q ); - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda - q ); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB - q ); // Q_old_wtda_LB + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda - q ); // Q_old_wtda_LB } IF( hCPE->hStereoDft != NULL ) { @@ -595,13 +597,13 @@ ivas_error ivas_jbm_dec_tc_fx( test(); IF( ( ( st->last_core != ACELP_CORE || ( EQ_16( st->prev_bfi, 1 ) && st->last_core == ACELP_CORE && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */ { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 } ELSE IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) /* ACELP -> TCX/HQ */ { IF( !st->tcxonly ) { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 } } } @@ -617,21 +619,24 @@ ivas_error ivas_jbm_dec_tc_fx( test(); IF( ( LE_16( st->last_L_frame, L_FRAME16k ) && LE_16( st->L_frame, L_FRAME16k ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) ) { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 } } } } #else - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 #endif - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); + scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // Q11 hCPE->hStereoDft->q_ap_fade_mem_fx = Q11; test(); } + + st_ivas->hSpar->hMdDec->Q_mixer_mat = 30; + move16(); FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 hCPE->q_output_mem_fx[ii] = Q11; move16(); } @@ -641,7 +646,6 @@ ivas_error ivas_jbm_dec_tc_fx( { nchan_remapped = 1; /* Only one channel transported */ move16(); - test(); } /* HP filtering */ @@ -681,13 +685,13 @@ ivas_error ivas_jbm_dec_tc_fx( } FOR( ch = 0; ch < nchan_transport; ch++ ) { - Scale_sig32( p_output_fx[ch], output_frame, Q_p_output ); + Scale_sig32( p_output_fx[ch], output_frame, Q_p_output ); // Q(11+Q_p_output) } ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, p_output_fx, st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames, Q_p_output ); FOR( Word16 c = 0; c < nchan_transport; c++ ) { - Scale_sig32( p_output_fx[c], output_frame, 11 ); + Scale_sig32( p_output_fx[c], output_frame, 11 ); // Q11 } } ELSE IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) ) @@ -699,7 +703,7 @@ ivas_error ivas_jbm_dec_tc_fx( FOR( i = 0; i < size; i++ ) { - Scale_sig32( p_output_fx[i], output_frame, Q14 - Q11 ); + Scale_sig32( p_output_fx[i], output_frame, Q14 - Q11 ); // Q14 } ivas_spar_dec_agc_pca_fx( st_ivas, p_output_fx, output_frame ); @@ -725,7 +729,7 @@ ivas_error ivas_jbm_dec_tc_fx( FOR( i = 0; i < st_ivas->nchan_transport; i++ ) { - Scale_sig32( p_output_fx[i], output_frame, 1 ); + Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q } } } @@ -782,7 +786,7 @@ ivas_error ivas_jbm_dec_tc_fx( } /* MASA metadata decoding */ - IF( ( error = ivas_masa_decode_fx( st_ivas, st_ivas->hCPE[0]->hCoreCoder[0], &nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_decode_fx( st_ivas, st_ivas->hCPE[0]->hCoreCoder[0], &nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) { return error; } @@ -792,7 +796,7 @@ ivas_error ivas_jbm_dec_tc_fx( st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); - IF( ( error = ivas_omasa_ism_metadata_dec_fx( st_ivas, ism_total_brate, &nchan_ism, &nchan_transport_ism, dirac_bs_md_write_idx, &nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_omasa_ism_metadata_dec_fx( st_ivas, ism_total_brate, &nchan_ism, &nchan_transport_ism, dirac_bs_md_write_idx, &nb_bits_metadata[1] ) ), IVAS_ERR_OK ) ) { return error; } @@ -809,7 +813,7 @@ ivas_error ivas_jbm_dec_tc_fx( #ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, p_output_fx, output_frame, nb_bits_metadata[0], &q_output ) ) != IVAS_ERR_OK ) #else - IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, p_output_fx, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) #endif { return error; @@ -846,7 +850,7 @@ ivas_error ivas_jbm_dec_tc_fx( ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { /* sanity check in case of bitrate switching */ - IF( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for combined MASA and ISM format" ); } @@ -862,7 +866,7 @@ ivas_error ivas_jbm_dec_tc_fx( { FOR( n = 0; n < s_max( getNumChanSynthesis( st_ivas ), nchan_transport_ism + st_ivas->nchan_transport ); n++ ) { - Scale_sig32( p_output_fx[n], output_frame, sub( Q11, output_q ) ); + Scale_sig32( p_output_fx[n], output_frame, sub( Q11, output_q ) ); // Q11 } } } @@ -912,7 +916,7 @@ ivas_error ivas_jbm_dec_tc_fx( { set32_fx( p_output_fx[0], 0, L_FRAME48k ); - IF( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ), IVAS_ERR_OK ) ) { return error; } @@ -923,7 +927,7 @@ ivas_error ivas_jbm_dec_tc_fx( #ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] + nb_bits_metadata[1], &q_output ) ) != IVAS_ERR_OK ) #else - IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, add( nb_bits_metadata[0], nb_bits_metadata[1] ) ) ), IVAS_ERR_OK ) ) #endif { return error; @@ -931,13 +935,13 @@ ivas_error ivas_jbm_dec_tc_fx( IF( NE_16( q_output, Q11 ) ) { - Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); - Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); + Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11 + Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11 } } ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) { - IF( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ), IVAS_ERR_OK ) ) { return error; } @@ -947,7 +951,7 @@ ivas_error ivas_jbm_dec_tc_fx( { FOR( i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) { - Scale_sig32( p_output_fx[i + sba_ch_idx], output_frame, Q14 - Q11 ); + Scale_sig32( p_output_fx[i + sba_ch_idx], output_frame, Q14 - Q11 ); // Q14 } SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; Word16 nchan_transport; @@ -974,7 +978,7 @@ ivas_error ivas_jbm_dec_tc_fx( } FOR( i = 0; i < 2; i++ ) { - Scale_sig32( p_output_fx[sba_ch_idx + i], L_FRAME48k, s ); + Scale_sig32( p_output_fx[sba_ch_idx + i], L_FRAME48k, s ); // Q(11+s) } hCPE->hStereoDft->q_dft = add( Q11, s ); move16(); @@ -991,42 +995,42 @@ ivas_error ivas_jbm_dec_tc_fx( scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); FOR( i = 0; i < CPE_CHANNELS; ++i ) { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); - scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft + scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft } IF( hCPE->hCoreCoder[0] != NULL ) { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); // q + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); // q hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; move16(); } IF( hCPE->hStereoDft != NULL ) { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft + scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // q_dft hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft; move16(); } IF( hSCE != NULL ) { - Scale_sig32( &hSCE->save_hb_synth_fx[0], (Word16) ( hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC ), hCPE->hStereoDft->q_dft - hSCE->q_save_hb_synth_fx ); + Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_hb_synth_fx ); // q_dft hSCE->q_save_hb_synth_fx = hCPE->hStereoDft->q_dft; move16(); - Scale_sig32( &hSCE->save_synth_fx[0], (Word16) ( hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC ), hCPE->hStereoDft->q_dft - hSCE->q_save_synth_fx ); + Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_synth_fx ); // q_dft hSCE->q_save_synth_fx = hCPE->hStereoDft->q_dft; move16(); } FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; move16(); } #ifdef MSAN_FIX FOR( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), hCPE->q_prev_synth_fx - 11 ); + Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, 11 ) ); // q_prev_synth_fx #else Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), hCPE->q_prev_synth_fx - 11 ); #endif @@ -1038,35 +1042,35 @@ ivas_error ivas_jbm_dec_tc_fx( #ifdef MSAN_FIX FOR( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( 11, hCPE->q_prev_synth_fx ) ); + Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( 11, hCPE->q_prev_synth_fx ) ); // Q11 #else Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), 11 - hCPE->q_prev_synth_fx ); #endif - scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 FOR( i = 0; i < CPE_CHANNELS; ++i ) { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); - scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 + scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 } IF( hCPE->hCoreCoder[0] != NULL ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB - q ); - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) ); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB, q ) ); // Q_old_wtda_LB + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) ); // Q_old_wtda } IF( hCPE->hStereoDft != NULL ) { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 + scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // Q11 hCPE->hStereoDft->q_ap_fade_mem_fx = Q11; move16(); } FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 hCPE->q_output_mem_fx[ii] = Q11; move16(); } @@ -1097,7 +1101,7 @@ ivas_error ivas_jbm_dec_tc_fx( move16(); FOR( ch = 0; ch < nchan_transport; ch++ ) { - Scale_sig32( p_output_fx[sba_ch_idx + ch], output_frame, sub( Q_p_output, Q11 ) ); + Scale_sig32( p_output_fx[sba_ch_idx + ch], output_frame, sub( Q_p_output, Q11 ) ); // Q_p_output } hSpar->hMdDec->Q_mixer_mat = 31; move16(); @@ -1105,7 +1109,7 @@ ivas_error ivas_jbm_dec_tc_fx( ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, &p_output_fx[sba_ch_idx], st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames, sub( Q_p_output, Q11 ) ); FOR( Word16 c = 0; c < nchan_transport; c++ ) { - Scale_sig32( p_output_fx[sba_ch_idx + c], output_frame, Q11 ); + Scale_sig32( p_output_fx[sba_ch_idx + c], output_frame, Q11 ); // Q11 } } ELSE IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) && st_ivas->sba_dirac_stereo_flag == 0 ) @@ -1118,7 +1122,7 @@ ivas_error ivas_jbm_dec_tc_fx( FOR( i = sba_ch_idx; i < size; i++ ) { - Scale_sig32( p_output_fx[i], output_frame, sub( Q14, Q11 ) ); + Scale_sig32( p_output_fx[i], output_frame, ( Q14 - Q11 ) ); // Q14 } ivas_spar_dec_agc_pca_fx( st_ivas, &p_output_fx[sba_ch_idx], output_frame ); @@ -1133,14 +1137,14 @@ ivas_error ivas_jbm_dec_tc_fx( FOR( i = 0; i < nchan_remapped; i++ ) { - Scale_sig32( p_output_fx[i], output_frame, 1 ); + Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q } } ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { ivas_mono_downmix_render_passive_fx( st_ivas, p_output_fx, output_frame ); - Scale_sig32( p_output_fx[0], L_FRAME48k, Q11 - Q8 ); + Scale_sig32( p_output_fx[0], L_FRAME48k, Q11 - Q8 ); // Q11 /* add W */ FOR( n = 0; n < nchan_out; n++ ) @@ -1167,8 +1171,8 @@ ivas_error ivas_jbm_dec_tc_fx( /* LFE channel decoder */ ivas_lfe_dec_fx( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output_fx[LFE_CHANNEL] ); - Scale_sig32( p_output_fx[LFE_CHANNEL], L_FRAME48k, Q11 - Q9 ); - IF( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, 0 ) ) != IVAS_ERR_OK ) + Scale_sig32( p_output_fx[LFE_CHANNEL], L_FRAME48k, Q11 - Q9 ); // Q11 + IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -1186,7 +1190,7 @@ ivas_error ivas_jbm_dec_tc_fx( test(); IF( NE_32( st_ivas->transport_config, st_ivas->intern_config ) && ( NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) { - IF( ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) >= ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ) ) + IF( GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) ) { ivas_mc2sba_fx( st_ivas->hTransSetup, p_output_fx, p_output_fx, output_frame, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE_FX ); } @@ -1203,12 +1207,12 @@ ivas_error ivas_jbm_dec_tc_fx( s = sub( s, find_guarded_bits_fx( st_ivas->nchan_transport ) ); FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i ) { - Scale_sig32( p_output_fx[i], output_frame, s ); + Scale_sig32( p_output_fx[i], output_frame, s ); // Q(11+s) } ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, output_frame, p_output_fx, p_output_fx ); FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i ) { - Scale_sig32( p_output_fx[i], output_frame, negate( s ) ); + Scale_sig32( p_output_fx[i], output_frame, negate( s ) ); // Q11 } } ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) @@ -1222,7 +1226,7 @@ ivas_error ivas_jbm_dec_tc_fx( /* LFE channel decoder */ ivas_lfe_dec_fx( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output_fx[LFE_CHANNEL] ); - Scale_sig32( p_output_fx[LFE_CHANNEL], L_FRAME48k, Q11 - Q9 ); + Scale_sig32( p_output_fx[LFE_CHANNEL], L_FRAME48k, Q11 - Q9 ); // Q11 ivas_mc_paramupmix_dec_read_BS( st_ivas, st, st_ivas->hMCParamUpmix, &nb_bits_metadata[0] ); @@ -1283,15 +1287,15 @@ ivas_error ivas_jbm_dec_tc_fx( #ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0], &q_output ) ) != IVAS_ERR_OK ) #else - IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) #endif { return error; } IF( NE_16( q_output, Q11 ) ) { - Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); - Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); + Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11 + Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11 } } ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) @@ -1349,15 +1353,15 @@ ivas_error ivas_jbm_dec_tc_fx( #ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0], &q_output ) ) != IVAS_ERR_OK ) #else - IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) #endif { return error; } IF( NE_16( q_output, Q11 ) ) { - Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); - Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); + Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11 + Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11 } /* Identify the index of the separated channel, always LFE_CHANNEL-1 here */ @@ -1368,7 +1372,7 @@ ivas_error ivas_jbm_dec_tc_fx( set32_fx( p_output_fx[n], 0, L_FRAME48k ); - IF( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[n], output_frame, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[n], output_frame, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -1411,15 +1415,15 @@ ivas_error ivas_jbm_dec_tc_fx( #ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0], &q_output ) ) != IVAS_ERR_OK ) #else - IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) #endif { return error; } IF( NE_16( q_output, Q11 ) ) { - Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); - Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); + Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11 + Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11 } } } @@ -1437,7 +1441,7 @@ ivas_error ivas_jbm_dec_tc_fx( } FOR( i = 0; i < 2; i++ ) { - Scale_sig32( p_output_fx[i], L_FRAME48k, s ); + Scale_sig32( p_output_fx[i], L_FRAME48k, s ); // Q(11+s) } hCPE->hStereoDft->q_dft = add( Q11, s ); @@ -1457,21 +1461,21 @@ ivas_error ivas_jbm_dec_tc_fx( scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); FOR( i = 0; i < CPE_CHANNELS; ++i ) { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); - scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft + scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft } IF( hCPE->hCoreCoder[0] != NULL ) { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; move16(); } IF( hCPE->hStereoDft != NULL ) { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft + scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // q_dft hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft; move16(); } @@ -1483,22 +1487,22 @@ ivas_error ivas_jbm_dec_tc_fx( IF( hSCE != NULL ) { - Scale_sig32( &hSCE->save_hb_synth_fx[0], (Word16) ( hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC ), hCPE->hStereoDft->q_dft - hSCE->q_save_hb_synth_fx ); + Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_hb_synth_fx ); // q_dft hSCE->q_save_hb_synth_fx = hCPE->hStereoDft->q_dft; move16(); - Scale_sig32( &hSCE->save_synth_fx[0], (Word16) ( hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC ), hCPE->hStereoDft->q_dft - hSCE->q_save_synth_fx ); + Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_synth_fx ); // q_dft hSCE->q_save_synth_fx = hCPE->hStereoDft->q_dft; move16(); } FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->q_output_mem_fx[ii] ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->q_output_mem_fx[ii] ) ); // q_dft hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; move16(); } #ifdef MSAN_FIX FOR( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, 11 ) ); + Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, 11 ) ); // q_prev_synth_fx #else Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), hCPE->q_prev_synth_fx - 11 ); #endif @@ -1509,7 +1513,7 @@ ivas_error ivas_jbm_dec_tc_fx( } #ifdef MSAN_FIX FOR( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( 11, hCPE->q_prev_synth_fx ) ); + Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( 11, hCPE->q_prev_synth_fx ) ); // Q11 #else Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), 11 - hCPE->q_prev_synth_fx ); #endif // MSAN_FIX @@ -1517,19 +1521,19 @@ ivas_error ivas_jbm_dec_tc_fx( scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); FOR( i = 0; i < CPE_CHANNELS; ++i ) { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); - scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 + scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 } IF( hCPE->hCoreCoder[0] != NULL ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB, q ) ); - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) ); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB, q ) ); // Q_old_wtda_LB + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) ); // Q_old_wtda } IF( hCPE->hStereoDft != NULL ) { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 + scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // Q11 hCPE->hStereoDft->q_ap_fade_mem_fx = Q11; move16(); } @@ -1537,7 +1541,7 @@ ivas_error ivas_jbm_dec_tc_fx( { FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 hCPE->q_output_mem_fx[ii] = Q11; move16(); } @@ -1581,10 +1585,15 @@ ivas_error ivas_jbm_dec_tc_fx( st_ivas->hDecoderConfig->last_ivas_total_brate = ivas_total_brate; move32(); IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) - st_ivas->last_active_ivas_total_brate = st_ivas->last_active_ivas_total_brate; + { + st_ivas->last_active_ivas_total_brate = st_ivas->last_active_ivas_total_brate; + move32(); + } ELSE + { st_ivas->last_active_ivas_total_brate = ivas_total_brate; - move32(); + move32(); + } } test(); @@ -2282,7 +2291,7 @@ void ivas_jbm_dec_feed_tc_to_renderer_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 nSamplesForRendering, /* i : number of TC samples available for rendering */ Word16 *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ - Word32 *data_fx /* i : transport channels */ + Word32 *data_fx /* i : transport channels Q11*/ ) { Word32 data_f_fx[MAX_CLDFB_DIGEST_CHANNELS][MAX_JBM_L_FRAME48k] = { 0 }; /* Word32 buffer for transport channels that will be directly converted with the CLDFB */ @@ -2363,11 +2372,11 @@ void ivas_jbm_dec_feed_tc_to_renderer_fx( IF( st_ivas->hSCE[0] ) { Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); - if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) + IF( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) { shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift) st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); } ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); @@ -2413,7 +2422,7 @@ void ivas_jbm_dec_feed_tc_to_renderer_fx( { shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift) st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); } ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); @@ -2430,7 +2439,7 @@ void ivas_jbm_dec_feed_tc_to_renderer_fx( { shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift) st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); } ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); @@ -2451,7 +2460,7 @@ void ivas_jbm_dec_feed_tc_to_renderer_fx( { shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31- (st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp - shift) st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); move16(); } @@ -2500,24 +2509,24 @@ void ivas_jbm_dec_feed_tc_to_renderer_fx( move16(); } - scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, -1 ); + scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, -1 ); // Q(31-1) st_ivas->hParamMC->proto_matrix_int_e = 1; move16(); ivas_param_mc_dec_digest_tc_fx( st_ivas, (UWord8) n_render_timeslots, (Word32 **) p_data_f_fx, Q11 ); - scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, 1 ); + scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, 1 ); // Q(31-1+1) Word16 shift; FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ ) { shift = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, nchan_transport * nchan_transport ) ); - scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, nchan_transport * nchan_transport ), shift ); + scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, i_mult( nchan_transport, nchan_transport ) ), shift ); // Q(31-cx_old_e+shift) st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], shift ); move16(); shift = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], nchan_out_cov * nchan_out_cov ); - scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], nchan_out_cov * nchan_out_cov, shift ); + scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], i_mult( nchan_out_cov, nchan_out_cov ), shift ); // Q(31-cy_old_e+shift) st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], shift ); move16(); } @@ -2531,7 +2540,7 @@ void ivas_jbm_dec_feed_tc_to_renderer_fx( { shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift) st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); move16(); } @@ -2697,7 +2706,7 @@ ivas_error ivas_jbm_dec_render_fx( const UWord16 nSamplesAsked, /* i : number of samples wanted */ UWord16 *nSamplesRendered, /* o : number of samples rendered */ UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal Q0*/ ) { Word16 n, nchan_out; @@ -2728,7 +2737,7 @@ ivas_error ivas_jbm_dec_render_fx( move16(); output_config = st_ivas->hDecoderConfig->output_config; move32(); - nSamplesAskedLocal = add( (Word16) nSamplesAsked, st_ivas->hTcBuffer->n_samples_discard ); + nSamplesAskedLocal = add( nSamplesAsked, st_ivas->hTcBuffer->n_samples_discard ); move16(); FOR( n = 0; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) @@ -2878,7 +2887,7 @@ ivas_error ivas_jbm_dec_render_fx( Word16 sba_num_chans = imult1616( add( st_ivas->hIntSetup.ambisonics_order, 1 ), add( st_ivas->hIntSetup.ambisonics_order, 1 ) ); FOR( j = 0; j < sba_num_chans; j++ ) { - scale_sig32( p_output_fx[j], *nSamplesRendered, sub( Q11, sub( add( output_q_factor, 29 ), 31 ) ) ); + scale_sig32( p_output_fx[j], *nSamplesRendered, sub( Q11, sub( add( output_q_factor, 29 ), 31 ) ) ); // Q11 } @@ -2908,7 +2917,7 @@ ivas_error ivas_jbm_dec_render_fx( /* Binaural rendering */ IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) { - IF( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) ) { return error; } @@ -2929,15 +2938,15 @@ ivas_error ivas_jbm_dec_render_fx( move16(); FOR( i = 0; i < nchan_in; i++ ) { - scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); + scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q11 } - IF( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, NULL, NULL, st_ivas->hTcBuffer, p_output_fx, p_output_fx, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, NULL, NULL, st_ivas->hTcBuffer, p_output_fx, p_output_fx, *nSamplesRendered, output_Fs ) ), IVAS_ERR_OK ) ) { return error; } FOR( i = 0; i < nchan_out; i++ ) { - scale_sig32( p_output_fx[i], *nSamplesRendered, sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); + scale_sig32( p_output_fx[i], *nSamplesRendered, sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11 } } } @@ -2963,7 +2972,7 @@ ivas_error ivas_jbm_dec_render_fx( { Copy32( st_ivas->hTcBuffer->tc_fx[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output_fx[n], *nSamplesRendered ); } - IF( ( error = ivas_sba_linear_renderer_fx( p_output_fx, *nSamplesRendered, nchan_remapped, 0, output_config, st_ivas->hOutSetup ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_linear_renderer_fx( p_output_fx, *nSamplesRendered, nchan_remapped, 0, output_config, st_ivas->hOutSetup ) ), IVAS_ERR_OK ) ) { return error; } @@ -2975,7 +2984,7 @@ ivas_error ivas_jbm_dec_render_fx( } ELSE { - IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ), IVAS_ERR_OK ) ) { return error; } @@ -2992,7 +3001,7 @@ ivas_error ivas_jbm_dec_render_fx( test(); IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) { - IF( ( error = ivas_omasa_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_omasa_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ) ), IVAS_ERR_OK ) ) { return error; } @@ -3023,7 +3032,7 @@ ivas_error ivas_jbm_dec_render_fx( hSpar->hMdDec->Q_mixer_mat = 30; move16(); - IF( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ), IVAS_ERR_OK ) ) { return error; } @@ -3054,14 +3063,14 @@ ivas_error ivas_jbm_dec_render_fx( } ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { - IF( ( error = ivas_osba_render_sf_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_osba_render_sf_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) ) { return error; } } ELSE IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) /*EXT output = individual objects + HOA3*/ { - IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output_fx[st_ivas->nchan_ism], 960 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output_fx[st_ivas->nchan_ism], 960 ) ), IVAS_ERR_OK ) ) { return error; } @@ -3073,7 +3082,7 @@ ivas_error ivas_jbm_dec_render_fx( } ELSE { - IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ), IVAS_ERR_OK ) ) { return error; } @@ -3085,14 +3094,14 @@ ivas_error ivas_jbm_dec_render_fx( } ELSE { - IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ), IVAS_ERR_OK ) ) { return error; } IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { - FOR( n = sub( st_ivas->hIntSetup.nchan_out_woLFE, 1 ); n >= 0; n-- ) + FOR( n = st_ivas->hIntSetup.nchan_out_woLFE - 1; n >= 0; n-- ) { Copy32( p_output_fx[n], p_output_fx[n + st_ivas->nchan_ism], *nSamplesRendered ); } @@ -3149,10 +3158,10 @@ ivas_error ivas_jbm_dec_render_fx( FOR( i = 0; i < nchan_in; i++ ) { - scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); + scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q11 IF( st_ivas->hDecoderConfig->Opt_tsm ) { - scale_sig32( p_tc_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); + scale_sig32( p_tc_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q11 } } IF( NE_32( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, @@ -3167,7 +3176,7 @@ ivas_error ivas_jbm_dec_render_fx( { FOR( i = 0; i < nchan_in; i++ ) { - scale_sig32( p_tc_fx[i], *nSamplesRendered, -Q2 ); + scale_sig32( p_tc_fx[i], *nSamplesRendered, -Q2 ); // Q(11-2) } } @@ -3175,10 +3184,10 @@ ivas_error ivas_jbm_dec_render_fx( FOR( i = 0; i < nchan_in; i++ ) { - scale_sig32( p_output_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); + scale_sig32( p_output_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11 IF( st_ivas->hDecoderConfig->Opt_tsm ) { - scale_sig32( p_tc_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); + scale_sig32( p_tc_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11 } } } @@ -3279,7 +3288,7 @@ ivas_error ivas_jbm_dec_render_fx( { Word16 tmp; tmp = L_norm_arr( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len ); - scale_sig32( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); + scale_sig32( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); // Q(st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer+ tmp) st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer = add( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer, tmp ); move16(); } @@ -3288,34 +3297,35 @@ ivas_error ivas_jbm_dec_render_fx( { IF( st_ivas->cldfbSynDec[ch] ) { - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q5, Q11 ) ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, ( Q5 - Q11 ) ); // Q5 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5; move16(); } } - Word16 tempp; FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ ) { - tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ) ); - scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ), tempp ); + tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_len ); + scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_len, tempp ); // Q(31-(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx]- tempp)) st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx], tempp ); move16(); IF( LT_16( st_ivas->hParamMC->band_grouping[param_band_idx], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) ) { - tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ) ); - scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ), tempp ); + tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len ); + scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len, tempp ); // Q(31- (st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] - tempp)) st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx], tempp ); move16(); } } + ivas_param_mc_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, channel_active_fx ); + FOR( int ch = 0; ch < nchan_out_cldfb; ch++ ) { IF( st_ivas->cldfbSynDec[ch] ) { - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q11 - Q5 ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q11 - Q5 ); // Q11 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; move16(); } @@ -3368,7 +3378,7 @@ ivas_error ivas_jbm_dec_render_fx( } ELSE IF( EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_5_1 ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) ) ) { - FOR( n = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); n < add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); n++ ) + FOR( n = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; n < ( st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe ); n++ ) { set32_fx( p_output_fx[n], 0, *nSamplesRendered ); } @@ -3933,7 +3943,7 @@ ivas_error ivas_jbm_dec_flush_renderer_fx( const MC_MODE mc_mode_old, /* i : old MC mode */ const ISM_MODE ism_mode_old, /* i : old ISM mode */ UWord16 *nSamplesRendered, /* o : number of samples flushed */ - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal Q0*/ ) { ivas_error error; @@ -3955,7 +3965,11 @@ ivas_error ivas_jbm_dec_flush_renderer_fx( /* get number of possible slots in new granularity */ n_samples_still_available = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_rendered ); - n_slots_still_available = n_samples_still_available / tc_granularity_new; + + // n_slots_still_available = n_samples_still_available / tc_granularity_new; + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide1616_Scale( n_samples_still_available, tc_granularity_new, &tmp_e ); + n_slots_still_available = shr( tmp, sub( 15, tmp_e ) ); *nSamplesRendered = imult1616( n_slots_still_available, tc_granularity_new ); n_samples_to_render = *nSamplesRendered; move16(); @@ -4024,7 +4038,7 @@ ivas_error ivas_jbm_dec_flush_renderer_fx( { /*TODO :To be tested : no stream entering---------------------------------------*/ /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */ - set16_fx( st_ivas->hIsmRendererData->interpolator_fx, 32767, hTcBuffer->n_samples_granularity ); + set16_fx( st_ivas->hIsmRendererData->interpolator_fx, 32767, hTcBuffer->n_samples_granularity ); // 32767=1.0f in Q15 ivas_ism_render_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ); @@ -4126,8 +4140,8 @@ ivas_error ivas_jbm_dec_flush_renderer_fx( Word16 last_dirac_md_idx; UWord16 nSamplesAvailableNext; - last_spar_md_idx = st_ivas->hSpar->render_to_md_map[sub( st_ivas->hSpar->slots_rendered, 1 )]; - last_dirac_md_idx = st_ivas->hSpatParamRendCom->render_to_md_map[sub( st_ivas->hSpatParamRendCom->slots_rendered, 1 )]; + last_spar_md_idx = st_ivas->hSpar->render_to_md_map[st_ivas->hSpar->slots_rendered - 1]; + last_dirac_md_idx = st_ivas->hSpatParamRendCom->render_to_md_map[st_ivas->hSpatParamRendCom->slots_rendered - 1]; move16(); move16(); /* copy from ISM delay buffer to the correct place in tcs */ @@ -4454,13 +4468,13 @@ ivas_error ivas_jbm_dec_set_discard_samples( temp = BASOP_Util_Divide3232_Scale( st_ivas->hDecoderConfig->output_Fs, ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ), &temp_e ); temp = shr( temp, sub( 15, temp_e ) ); nMaxSlotsPerSubframe = BASOP_Util_Divide1616_Scale( temp, st_ivas->hTcBuffer->n_samples_granularity, &temp_e ); - nMaxSlotsPerSubframe = shr( nMaxSlotsPerSubframe, sub( 15, temp_e ) ); - nSlotsInFirstSubframe = sub( nMaxSlotsPerSubframe, st_ivas->hTcBuffer->subframe_nbslots[sub( st_ivas->hTcBuffer->nb_subframes, 1 )] ); + nMaxSlotsPerSubframe = shr( nMaxSlotsPerSubframe, sub( 15, temp_e ) ); // Q0 + nSlotsInFirstSubframe = sub( nMaxSlotsPerSubframe, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] ); IF( nSlotsInFirstSubframe > 0 ) { st_ivas->hTcBuffer->n_samples_discard = imult1616( sub( nMaxSlotsPerSubframe, nSlotsInFirstSubframe ), st_ivas->hTcBuffer->n_samples_granularity ); /* set last subframes number to max to ensure correct continuation */ - st_ivas->hTcBuffer->subframe_nbslots[sub( st_ivas->hTcBuffer->nb_subframes, 1 )] = nMaxSlotsPerSubframe; + st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] = nMaxSlotsPerSubframe; move16(); move16(); } @@ -4530,7 +4544,7 @@ void ivas_jbm_dec_get_adapted_linear_interpolator( void ivas_jbm_dec_get_adapted_linear_interpolator_fx( const Word16 default_interp_length, /* i : default length of the (full-frame) interpolator */ const Word16 interp_length, /* i : length of the interpolator to be created */ - Word16 *interpolator_fx /* o : the interpolator */ + Word16 *interpolator_fx /* o : the interpolator Q15 */ ) { Word16 jbm_segment_len, idx; @@ -4540,7 +4554,7 @@ void ivas_jbm_dec_get_adapted_linear_interpolator_fx( jbm_segment_len = shr( default_interp_length, 1 ); dec_fx = divide1616( 1, default_interp_length ); /*32767 / default_interp_length*/ - interpolator_fx[interp_length - 1] = 32767; + interpolator_fx[interp_length - 1] = 32767; /* (1.0f in Q15) -1 */ move16(); interpolator_fx[interp_length - 2] = add( sub( 32767, dec_fx ), 1 ); // Use 32768 to maintain precision move16(); @@ -4553,7 +4567,7 @@ void ivas_jbm_dec_get_adapted_linear_interpolator_fx( IF( interpolator_fx[idx + 1] > 0 ) { dec_fx = BASOP_Util_Divide1616_Scale( interpolator_fx[idx + 1], add( jbm_segment_len, 1 ), &dec_e ); - dec_fx = shr( dec_fx, sub( 15, dec_e ) ); + dec_fx = shr( dec_fx, sub( 15, dec_e ) ); // Q0 FOR( ; idx >= 0; idx-- ) { interpolator_fx[idx] = sub( interpolator_fx[idx + 1], dec_fx ); @@ -4599,7 +4613,7 @@ void ivas_jbm_dec_get_adapted_subframes( } temp = BASOP_Util_Divide3232_Scale( L_add( nCldfbSlotsLocal, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME - 1 ), PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, &temp_e ); - *nb_subframes = add( *nb_subframes, shr( temp, sub( 15, temp_e ) ) ); + *nb_subframes = add( *nb_subframes, shr( temp, sub( 15, temp_e ) ) ); // Q0 move16(); nSlotsInLastSubframe = nCldfbSlotsLocal % PARAM_MC_MAX_NSLOTS_IN_SUBFRAME; move16(); @@ -4682,10 +4696,10 @@ void ivas_jbm_dec_get_md_map( Word16 temp; jbm_segment_len = shr( default_len, 1 ); - FOR( ( map_idx = sub( len, 1 ), src_idx = sub( default_len, 1 ) ); map_idx >= jbm_segment_len; ( map_idx--, src_idx-- ) ) + FOR( ( map_idx = len - 1, src_idx = default_len - 1 ); map_idx >= jbm_segment_len; ( map_idx--, src_idx-- ) ) { temp = BASOP_Util_Divide1616_Scale( src_idx, subframe_len, &temp_e ); - temp = shr( temp, sub( 15, temp_e ) ); + temp = shr( temp, sub( 15, temp_e ) ); // Q0 src_idx_map = s_max( 0, temp ); map[map_idx] = add( offset, src_idx_map ) % buf_len; move16(); @@ -4701,10 +4715,10 @@ void ivas_jbm_dec_get_md_map( FOR( ; map_idx >= 0; map_idx-- ) { temp = BASOP_Util_Divide1616_Scale( round_fx( src_idx_fx ), subframe_len, &temp_e ); - temp = shr( temp, sub( 15, temp_e ) ); + temp = shr( temp, sub( 15, temp_e ) ); // Q0 src_idx = s_max( 0, temp ); map[map_idx] = add( offset, src_idx ) % buf_len; - src_idx_fx -= dec_fx; + src_idx_fx = L_sub( src_idx_fx, dec_fx ); } } ELSE @@ -4794,8 +4808,8 @@ void ivas_jbm_dec_get_md_map_even_spacing( Word32 temp; Word16 temp_e; temp = BASOP_Util_Divide3232_Scale( L_shl( len, 16 ), subframe_len, &temp_e ); - temp = L_shr( temp, sub( 15, temp_e ) ); - decimal_fx = L_sub( temp, L_shl( sf_length, 16 ) ); + temp = L_shr( temp, sub( 15, temp_e ) ); // Q16 + decimal_fx = L_sub( temp, L_shl( sf_length, 16 ) ); // Q16 decimal_sum_fx = decimal_fx; eps_fx = 65; @@ -5139,13 +5153,14 @@ Word16 ivas_jbm_dec_get_num_tc_channels_fx( } ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - test(); - test(); + + if ( st_ivas->sba_dirac_stereo_flag ) { num_tc = CPE_CHANNELS; move16(); } + test(); test(); if ( ( st_ivas->sba_planar && GE_16( num_tc, 3 ) ) || EQ_16( num_tc, 3 ) ) @@ -5207,9 +5222,9 @@ Word16 ivas_jbm_dec_get_num_tc_channels_fx( test(); test(); test(); - IF( st_ivas->hOutSetup.separateChannelEnabled && ( EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1 ) || - EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || - EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe > 0 ) ) ) + if ( st_ivas->hOutSetup.separateChannelEnabled && ( EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1 ) || + EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || + EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe > 0 ) ) ) { /* LFE is synthesized in TD with the TCs*/ num_tc = add( num_tc, 1 ); @@ -5237,8 +5252,8 @@ static void ivas_jbm_dec_copy_tc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 nSamplesForRendering, /* i : number of samples to digest */ Word16 *nSamplesResidual, /* o : number of samples that will be left for the next frame */ - Word32 *data, /* i : (interleaved) transport channel samples */ - Word32 *tc_digest_f[], /* o : samples that will be directly digested (e.g. by CLDFB) */ + Word32 *data, /* i : (interleaved) transport channel samples data_q*/ + Word32 *tc_digest_f[], /* o : samples that will be directly digested (e.g. by CLDFB) data_q*/ Word16 data_q ) { Word16 ch; @@ -5276,7 +5291,7 @@ static void ivas_jbm_dec_copy_tc( Copy32( hTcBuffer->tc_fx[ch], tc_digest_f[ch], n_samples_still_available ); FOR( m = 0; m < nSamplesForRendering; m++ ) { - tc_digest_f[ch][add( n_samples_still_available, m )] = data[add( imult1616( m, st_ivas->hTcBuffer->nchan_transport_jbm ), ch )]; + tc_digest_f[ch][n_samples_still_available + m] = data[( m * st_ivas->hTcBuffer->nchan_transport_jbm ) + ch]; // data_q move32(); } Copy32( tc_digest_f[ch] + hTcBuffer->n_samples_available, hTcBuffer->tc_fx[ch], *nSamplesResidual ); @@ -5387,7 +5402,7 @@ Word16 ivas_jbm_dec_get_render_granularity( const RENDERER_TYPE rendererType, /* i : renderer type */ const IVAS_FORMAT ivas_format, /* i : ivas format */ const MC_MODE mc_mode, /* i : MC mode */ - const Word32 output_Fs /* i : sampling rate */ + const Word32 output_Fs /* i : sampling rate Q0*/ ) { Word16 render_granularity; @@ -5600,7 +5615,7 @@ ivas_error ivas_jbm_dec_tc_buffer_open_fx( nsamp_to_allocate = 0; move16(); - tmp32 = L_mult0( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, hTcBuffer->n_samples_granularity ); + tmp32 = L_mult0( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, hTcBuffer->n_samples_granularity ); // Q0 tmp = BASOP_Util_Divide3232_Scale( st_ivas->hDecoderConfig->output_Fs, tmp32, &tmp_e ); nMaxSlotsPerSubframe = shr( tmp, sub( 15, tmp_e ) ); // Q0 @@ -5824,7 +5839,7 @@ ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx( { Word16 nMaxSlotsPerSubframeNew; - nMaxSlotsPerSubframeNew = idiv1616( divide3216( st_ivas->hDecoderConfig->output_Fs, ( ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) >> 1 ) ), n_samples_granularity ); + nMaxSlotsPerSubframeNew = idiv1616( divide3216( st_ivas->hDecoderConfig->output_Fs, ( ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) >> 1 ) ), n_samples_granularity ); // Q0 /* if samples were flushed, take that into account here */ test(); IF( LT_16( n_samples_granularity, hTcBuffer->n_samples_granularity ) && hTcBuffer->n_samples_flushed > 0 ) @@ -5980,7 +5995,8 @@ static void ivas_jbm_dec_tc_buffer_playout_fx( Decoder_Struct *st_ivas, const UWord16 nSamplesAsked, UWord16 *nSamplesRendered, - Word32 *output_fx[] ) + Word32 *output_fx[] /*Q11*/ +) { Word16 ch_idx, slot_size, slots_to_render, first_sf, last_sf, tmp, e; @@ -5989,9 +6005,9 @@ static void ivas_jbm_dec_tc_buffer_playout_fx( /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ tmp = BASOP_Util_Divide1616_Scale( nSamplesAsked, slot_size, &e ); - tmp = shr( tmp, sub( 15, e ) ); + tmp = shr( tmp, sub( 15, e ) ); // Q0 slots_to_render = s_min( sub( st_ivas->hTcBuffer->num_slots, st_ivas->hTcBuffer->slots_rendered ), tmp ); - st_ivas->hTcBuffer->slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, slots_to_render ); + st_ivas->hTcBuffer->slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, slots_to_render ); // Q0 *nSamplesRendered = (UWord16) L_mult0( slots_to_render, slot_size ); first_sf = st_ivas->hTcBuffer->subframes_rendered; last_sf = first_sf; @@ -6096,11 +6112,11 @@ void ivas_jbm_dec_td_renderers_adapt_subframes( /* nMaxSlotsPerSubframe = (Word16) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / st_ivas->hTcBuffer->n_samples_granularity; */ tmp = extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, 10737418 /* 1 / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 */ ) ); tmp = BASOP_Util_Divide1616_Scale( tmp, st_ivas->hTcBuffer->n_samples_granularity, &exp ); - nMaxSlotsPerSubframe = shr( tmp, sub( 15, exp ) ); + nMaxSlotsPerSubframe = shr( tmp, sub( 15, exp ) ); // Q0 /* nSlotsAvailable = st_ivas->hTcBuffer->n_samples_available / st_ivas->hTcBuffer->n_samples_granularity; */ tmp = BASOP_Util_Divide1616_Scale( st_ivas->hTcBuffer->n_samples_available, st_ivas->hTcBuffer->n_samples_granularity, &exp ); - nSlotsAvailable = shr( tmp, sub( 15, exp ) ); + nSlotsAvailable = shr( tmp, sub( 15, exp ) ); // Q0 st_ivas->hTcBuffer->num_slots = nSlotsAvailable; move16(); diff --git a/lib_dec/ivas_lfe_plc_fx.c b/lib_dec/ivas_lfe_plc_fx.c index 2b6be58e0db487f43a58fc56dc660ab4fc73b5df..efd158cafcac0a7434f0f687d2665840b004d08a 100644 --- a/lib_dec/ivas_lfe_plc_fx.c +++ b/lib_dec/ivas_lfe_plc_fx.c @@ -795,7 +795,11 @@ static Word16 d_a2rc_fx( exp2 = sub( norm_l( temp1 ), 1 ); temp = Mpy_32_32( L_shl( km_fx, exp1 ), L_shl( temp1, exp2 ) ); temp_q = sub( add( add( km_q_fx, exp1 ), add( temp_q1, exp2 ) ), 31 ); - + if ( temp == 0 ) + { + temp_q = 31; + move16(); + } IF( LT_16( temp_q, temp_q1 ) ) { ff_fx[j] = L_add( L_shr( temp1, sub( temp_q1, temp_q ) ), temp ); @@ -1327,12 +1331,16 @@ void ivas_lfe_tdplc_fx( set16_fx( mem_fx, 0, 2 * LFE_PLC_FDEL / LFE_PLC_DSF ); - Copy_Scale_sig_32_16( prevsynth_fx, prevsynth_16_fx, LFE_PLC_BUFLEN, -16 ); // Q5 = Q21 - Q16 - Copy_Scale_sig_32_16( rec_frame_fx, rec_frame_16_fx, LFE_PLC_RECLEN, 0 ); // Q5 + Copy_Scale_sig_32_16( prevsynth_fx, prevsynth_16_fx, LFE_PLC_BUFLEN, -prevsynth_q_fx ); // Q0 + Copy_Scale_sig_32_16( rec_frame_fx, rec_frame_16_fx, LFE_PLC_RECLEN, -Q5 ); // Q0 + + Word16 Q_new_inp, mem_decim_size, size_modified; + size_modified = modify_Fs_ivas_fx( prevsynth_16_fx + LFE_PLC_BUFLEN - LFE_PLC_FDEL / LFE_PLC_DSF, LFE_PLC_FDEL / LFE_PLC_DSF, LFE_PLC_FS, rec_frame_us_16_fx, 48000, mem_fx, 0, &Q_new_inp, &mem_decim_size ); + Scale_sig( rec_frame_us_16_fx, size_modified, negate( Q_new_inp ) ); /* scaling back to Q0 */ + + size_modified = modify_Fs_ivas_fx( rec_frame_16_fx, LFE_PLC_RECLEN, LFE_PLC_FS, rec_frame_us_16_fx, 48000, mem_fx, 0, &Q_new_inp, &mem_decim_size ); + Scale_sig( rec_frame_us_16_fx, size_modified, negate( Q_new_inp ) ); /* scaling back to Q0 */ - Word16 Q_new_inp, mem_decim_size; // TO be removed - modify_Fs_fx( prevsynth_16_fx + LFE_PLC_BUFLEN - LFE_PLC_FDEL / LFE_PLC_DSF, LFE_PLC_FDEL / LFE_PLC_DSF, LFE_PLC_FS, rec_frame_us_16_fx, 48000, mem_fx, 0, &Q_new_inp, &mem_decim_size ); - modify_Fs_fx( rec_frame_16_fx, LFE_PLC_RECLEN, LFE_PLC_FS, rec_frame_us_16_fx, 48000, mem_fx, 0, &Q_new_inp, &mem_decim_size ); /*samples are generated with 48k sampling rate and then converted to required sampling rate by simple decimation as signal is already bandlimited*/ @@ -1349,7 +1357,7 @@ void ivas_lfe_tdplc_fx( } } - Copy_Scale_sig_16_32( rec_frame_us_16_fx, rec_frame_us_fx, LFE_PLC_RECLEN_48K, 5 ); // Q10 = rec_frame_q + 5 + Copy_Scale_sig_16_32( rec_frame_us_16_fx, rec_frame_us_fx, LFE_PLC_RECLEN_48K, 10 ); // Q10 = rec_frame_q + 5 FOR( i = 0; i < 2; i++ ) { diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index ba1724eee2b8730aae39ad6c614a6389dd57e501..6debcfd575b6f533976909d798185d291781e174 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -590,7 +590,7 @@ ivas_error ivas_masa_decode( ivas_error ivas_masa_decode_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ Decoder_State *st, /* i/o: decoder state structure with bitstream */ - Word16 *nb_bits_read /* o : number of bits read */ + Word16 *nb_bits_read /* o : number of bits read Q0*/ ) { UWord16 byteBuffer; @@ -651,7 +651,7 @@ ivas_error ivas_masa_decode_fx( move16(); /* masa_brate / FRAMES_PER_SEC */ - tmp = extract_l( Mpy_32_32( masa_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + tmp = extract_l( Mpy_32_32( masa_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); // Q0 IF( EQ_32( masa_brate, IVAS_SID_5k2 ) ) { @@ -1102,7 +1102,7 @@ ivas_error ivas_masa_decode_fx( FOR( b = 0; b < st_ivas->hSpatParamRendCom->num_freq_bands; b++ ) { st_ivas->hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = L_sub( st_ivas->hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b], - st_ivas->hMasaIsmData->energy_ratio_ism_fx[i][meta_write_index][b] ); + st_ivas->hMasaIsmData->energy_ratio_ism_fx[i][meta_write_index][b] ); // Q30 move32(); } } @@ -1114,7 +1114,7 @@ ivas_error ivas_masa_decode_fx( FOR( b = 0; b < st_ivas->hSpatParamRendCom->num_freq_bands; b++ ) { - st_ivas->hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = L_max( 0, st_ivas->hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] ); + st_ivas->hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = L_max( 0, st_ivas->hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] ); // Q30 move32(); } } @@ -1992,11 +1992,11 @@ static void replicate_subframes_fx( { hQMetaData->q_direction[dir].band_data[band].spherical_index[sf] = hQMetaData->q_direction[dir].band_data[band].spherical_index[0]; move16(); - hQMetaData->q_direction[dir].band_data[band].azimuth_fx[sf] = hQMetaData->q_direction[dir].band_data[band].azimuth_fx[0]; + hQMetaData->q_direction[dir].band_data[band].azimuth_fx[sf] = hQMetaData->q_direction[dir].band_data[band].azimuth_fx[0]; // Q22 move32(); - hQMetaData->q_direction[dir].band_data[band].elevation_fx[sf] = hQMetaData->q_direction[dir].band_data[band].elevation_fx[0]; + hQMetaData->q_direction[dir].band_data[band].elevation_fx[sf] = hQMetaData->q_direction[dir].band_data[band].elevation_fx[0]; // Q22 move32(); - hQMetaData->q_direction[dir].band_data[band].energy_ratio_fx[sf] = hQMetaData->q_direction[dir].band_data[band].energy_ratio_fx[0]; + hQMetaData->q_direction[dir].band_data[band].energy_ratio_fx[sf] = hQMetaData->q_direction[dir].band_data[band].energy_ratio_fx[0]; // Q30 move32(); if ( hQMetaData->q_direction[dir].coherence_band_data != NULL ) @@ -2097,11 +2097,11 @@ static void restore_lowbitrate_masa_fx( hQMetaData->q_direction[0].band_data[band].spherical_index[sf] = hQMetaData->q_direction[0].band_data[band].spherical_index[0]; move16(); - hQMetaData->q_direction[0].band_data[band].azimuth_fx[sf] = hQMetaData->q_direction[0].band_data[band].azimuth_fx[0]; + hQMetaData->q_direction[0].band_data[band].azimuth_fx[sf] = hQMetaData->q_direction[0].band_data[band].azimuth_fx[0]; // Q22 move32(); - hQMetaData->q_direction[0].band_data[band].elevation_fx[sf] = hQMetaData->q_direction[0].band_data[band].elevation_fx[0]; + hQMetaData->q_direction[0].band_data[band].elevation_fx[sf] = hQMetaData->q_direction[0].band_data[band].elevation_fx[0]; // Q22 move32(); - hQMetaData->q_direction[0].band_data[band].energy_ratio_fx[sf] = hQMetaData->q_direction[0].band_data[band].energy_ratio_fx[0]; + hQMetaData->q_direction[0].band_data[band].energy_ratio_fx[sf] = hQMetaData->q_direction[0].band_data[band].energy_ratio_fx[0]; // Q30 move32(); if ( hQMetaData->q_direction[0].coherence_band_data != NULL ) @@ -2129,11 +2129,11 @@ static void restore_lowbitrate_masa_fx( { hQMetaData->q_direction[0].band_data[band].spherical_index[sf] = hQMetaData->q_direction[0].band_data[0].spherical_index[sf]; move16(); - hQMetaData->q_direction[0].band_data[band].azimuth_fx[sf] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[sf]; + hQMetaData->q_direction[0].band_data[band].azimuth_fx[sf] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[sf]; // Q22 move32(); - hQMetaData->q_direction[0].band_data[band].elevation_fx[sf] = hQMetaData->q_direction[0].band_data[0].elevation_fx[sf]; + hQMetaData->q_direction[0].band_data[band].elevation_fx[sf] = hQMetaData->q_direction[0].band_data[0].elevation_fx[sf]; // Q22 move32(); - hQMetaData->q_direction[0].band_data[band].energy_ratio_fx[sf] = hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[sf]; + hQMetaData->q_direction[0].band_data[band].energy_ratio_fx[sf] = hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[sf]; // Q30 move32(); if ( hQMetaData->q_direction[0].coherence_band_data != NULL ) @@ -2345,13 +2345,13 @@ static ivas_error init_lfe_synth_data_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); } - set32_fx( hMasa->hMasaLfeSynth->lfeSynthRingBuffer_fx, 0, bufferSize ); + set32_fx( hMasa->hMasaLfeSynth->lfeSynthRingBuffer_fx, 0, bufferSize ); // Q11 hMasa->hMasaLfeSynth->ringBufferLoPointer = 0; move16(); hMasa->hMasaLfeSynth->ringBufferHiPointer = shr( bufferSize, 1 ); move16(); - hMasa->hMasaLfeSynth->lowpassSum_fx = 0; + hMasa->hMasaLfeSynth->lowpassSum_fx = 0; // Q11 move16(); hMasa->hMasaLfeSynth->ringBufferSize = bufferSize; move16(); @@ -2364,11 +2364,11 @@ static ivas_error init_lfe_synth_data_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); } - set32_fx( hMasa->hMasaLfeSynth->lfeSynthRingBuffer2_fx, 0, bufferSize ); + set32_fx( hMasa->hMasaLfeSynth->lfeSynthRingBuffer2_fx, 0, bufferSize ); // Q11 hMasa->hMasaLfeSynth->ringBufferLoPointer2 = 0; move16(); - hMasa->hMasaLfeSynth->lowpassSum2_fx = 0; + hMasa->hMasaLfeSynth->lowpassSum2_fx = 0; // Q11 move32(); hMasa->hMasaLfeSynth->ringBufferSize2 = bufferSize; move16(); @@ -2379,7 +2379,7 @@ static ivas_error init_lfe_synth_data_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); } - set32_fx( hMasa->hMasaLfeSynth->delayBuffer_syncLp_fx, 0, bufferSize ); + set32_fx( hMasa->hMasaLfeSynth->delayBuffer_syncLp_fx, 0, bufferSize ); // Q11 hMasa->hMasaLfeSynth->delayBuffer_syncLp_size = bufferSize; move16(); @@ -2389,22 +2389,22 @@ static ivas_error init_lfe_synth_data_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); } - set32_fx( hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_fx, 0, bufferSize ); + set32_fx( hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_fx, 0, bufferSize ); // Q11 hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size = bufferSize; move16(); /* Interpolation between slots */ - hMasa->hMasaLfeSynth->lfeGainPrev_fx = 0; + hMasa->hMasaLfeSynth->lfeGainPrev_fx = 0; // Q15 move16(); - hMasa->hMasaLfeSynth->transportGainPrev_fx = MAX_WORD16; + hMasa->hMasaLfeSynth->transportGainPrev_fx = MAX_WORD16; // Q15 move16(); /* slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); */ - slot_size = extract_l( Mpy_32_32( output_Fs, 2684355 /* 1 / ( FRAMES_PER_SEC * CLDFB_NO_COL_MAX ) */ ) ); + slot_size = extract_l( Mpy_32_32( output_Fs, 2684355 /* 1 / ( FRAMES_PER_SEC * CLDFB_NO_COL_MAX ) in Q31*/ ) ); FOR( i = 0; i < slot_size; i++ ) { - hMasa->hMasaLfeSynth->interpolator_fx[i] = div_s( add( i, 1 ), slot_size ); + hMasa->hMasaLfeSynth->interpolator_fx[i] = div_s( add( i, 1 ), slot_size ); // Q15 move16(); } } @@ -2418,7 +2418,7 @@ static ivas_error init_lfe_synth_data_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); } - set32_fx( hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_fx, 0, bufferSize ); + set32_fx( hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_fx, 0, bufferSize ); // Q11 hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size = bufferSize; move16(); @@ -2634,7 +2634,7 @@ static Word16 decode_lfe_to_total_energy_ratio_fx( lfeBitsRead = add( lfeBitsRead, 3 ); lfeToTotalEnergyRatioIndices[1] = byteBuffer; /* Scalar index */ move16(); - log2LFEaverage_fx = usdequant_fx( lfeToTotalEnergyRatioIndices[1], MCMASA_LFE_QLOW_Q12, MCMASA_LFE_DELTA_Q11 ); + log2LFEaverage_fx = usdequant_fx( lfeToTotalEnergyRatioIndices[1], MCMASA_LFE_QLOW_Q12, MCMASA_LFE_DELTA_Q11 ); // Q12 /* 16.4 kbps sends only scalar gain, above it VQ is used */ IF( GE_32( ivas_total_brate, IVAS_24k4 ) ) @@ -3061,7 +3061,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( // st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; st_ivas->hSCE[sce_id]->element_brate = L_deposit_h( BASOP_Util_Divide3216_Scale( ivas_total_brate, st_ivas->nchan_transport, &tmp_e ) ); - st_ivas->hSCE[sce_id]->element_brate = L_shr( st_ivas->hSCE[sce_id]->element_brate, sub( 15, tmp_e ) ); + st_ivas->hSCE[sce_id]->element_brate = L_shr( st_ivas->hSCE[sce_id]->element_brate, sub( 15, tmp_e ) ); // Q0 move32(); move32(); @@ -3091,7 +3091,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( { // st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; tmp32 = L_deposit_h( BASOP_Util_Divide3216_Scale( ivas_total_brate, st_ivas->nchan_transport, &tmp_e ) ); - tmp32 = L_shr( tmp32, sub( 15, tmp_e ) ); + tmp32 = L_shr( tmp32, sub( 15, tmp_e ) ); // Q0 st_ivas->hCPE[cpe_id]->element_brate = imult3216( tmp32, CPE_CHANNELS ); move32(); @@ -3189,7 +3189,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( IF( st_ivas->hSpar ) { Word16 Q_tmp = getScaleFactor16( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 16 ); - Scale_sig( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 16, Q_tmp - st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q ); + Scale_sig( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 16, Q_tmp - st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q ); // st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q -> Q_tmp st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q = Q_tmp; move16(); } @@ -3437,7 +3437,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( slot_fac_fx = BASOP_Util_Divide3232_Scale( 1, hSpar->subframe_nbslots[subframe], &q_slot_fac ); IF( q_slot_fac < 0 ) { - slot_fac_fx = shr( slot_fac_fx, -1 * q_slot_fac ); + slot_fac_fx = shr( slot_fac_fx, -1 * q_slot_fac ); // Q15 } FOR( slot_idx = 0; slot_idx < hSpar->subframe_nbslots[subframe]; slot_idx++ ) { @@ -3498,7 +3498,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( { FOR( j = 0; j < FOA_CHANNELS; j++ ) { - mixer_mat_sf_bins_real_fx[bin][i][j] = mixer_mat_sf_bands_real_fx[band][i][j]; // 31+q_slot_fac + mixer_mat_sf_bins_real_fx[bin][i][j] = mixer_mat_sf_bands_real_fx[band][i][j]; // 31 move32(); } } @@ -3518,14 +3518,14 @@ void ivas_spar_param_to_masa_param_mapping_fx( { FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - instEne_fx = (Word64) L_shr_sat( inRe_fx[ch][slot][bin], sub( q_cldfb[ch][slot], common_q ) ) * L_shr_sat( inRe_fx[ch][slot][bin], sub( q_cldfb[ch][slot], common_q ) ); - instEne_fx = W_add( instEne_fx, (Word64) L_shr_sat( inIm_fx[ch][slot][bin], sub( q_cldfb[ch][slot], common_q ) ) * L_shr_sat( inIm_fx[ch][slot][bin], sub( q_cldfb[ch][slot], common_q ) ) ); - transportSignalEnergies_64[ch][bin] = W_add( transportSignalEnergies_64[ch][bin], instEne_fx ); + instEne_fx = W_mult0_32_32( L_shr_sat( inRe_fx[ch][slot][bin], sub( q_cldfb[ch][slot], common_q ) ), L_shr_sat( inRe_fx[ch][slot][bin], sub( q_cldfb[ch][slot], common_q ) ) ); // Q(2 * common_q) + instEne_fx = W_add( instEne_fx, W_mult0_32_32( (Word64) L_shr_sat( inIm_fx[ch][slot][bin], sub( q_cldfb[ch][slot], common_q ) ), L_shr_sat( inIm_fx[ch][slot][bin], sub( q_cldfb[ch][slot], common_q ) ) ) ); // Q(2 * common_q) + transportSignalEnergies_64[ch][bin] = W_add( transportSignalEnergies_64[ch][bin], instEne_fx ); // Q(2 * common_q) move64(); move64(); } - transportSignalCrossCorrelation_64[bin] = W_add( transportSignalCrossCorrelation_64[bin], W_mult0_32_32( L_shr_sat( inRe_fx[0][slot][bin], sub( q_cldfb[0][slot], common_q ) ), L_shr_sat( inRe_fx[1][slot][bin], sub( q_cldfb[0][slot], common_q ) ) ) ); - transportSignalCrossCorrelation_64[bin] = W_add( transportSignalCrossCorrelation_64[bin], W_mult0_32_32( L_shr_sat( inIm_fx[0][slot][bin], sub( q_cldfb[0][slot], common_q ) ), L_shr_sat( inIm_fx[1][slot][bin], sub( q_cldfb[0][slot], common_q ) ) ) ); + transportSignalCrossCorrelation_64[bin] = W_add( transportSignalCrossCorrelation_64[bin], W_mult0_32_32( L_shr_sat( inRe_fx[0][slot][bin], sub( q_cldfb[0][slot], common_q ) ), L_shr_sat( inRe_fx[1][slot][bin], sub( q_cldfb[0][slot], common_q ) ) ) ); // Q(2 * common_q) + transportSignalCrossCorrelation_64[bin] = W_add( transportSignalCrossCorrelation_64[bin], W_mult0_32_32( L_shr_sat( inIm_fx[0][slot][bin], sub( q_cldfb[0][slot], common_q ) ), L_shr_sat( inIm_fx[1][slot][bin], sub( q_cldfb[0][slot], common_q ) ) ) ); // Q(2 * common_q) move64(); move64(); } @@ -3536,12 +3536,35 @@ void ivas_spar_param_to_masa_param_mapping_fx( { FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - transportSignalEnergies_max = GT_64( transportSignalEnergies_max, transportSignalEnergies_64[ch][bin] ) ? transportSignalEnergies_max : transportSignalEnergies_64[ch][bin]; + // transportSignalEnergies_max = GT_64( transportSignalEnergies_max, transportSignalEnergies_64[ch][bin] ) ? transportSignalEnergies_max : transportSignalEnergies_64[ch][bin]; + + if ( LE_64( transportSignalEnergies_max, transportSignalEnergies_64[ch][bin] ) ) + { + transportSignalEnergies_max = transportSignalEnergies_64[ch][bin]; // Q(2 * common_q) + move64(); + } + } + + // transportSignalCrossCorrelation_max = GT_64( transportSignalCrossCorrelation_max, transportSignalCrossCorrelation_64[bin] ) ? transportSignalCrossCorrelation_max : transportSignalCrossCorrelation_64[bin]; + + if ( LE_64( transportSignalCrossCorrelation_max, transportSignalCrossCorrelation_64[bin] ) ) + { + transportSignalCrossCorrelation_max = transportSignalCrossCorrelation_64[bin]; // Q(2 * common_q) + move64(); } - transportSignalCrossCorrelation_max = GT_64( transportSignalCrossCorrelation_max, transportSignalCrossCorrelation_64[bin] ) ? transportSignalCrossCorrelation_max : transportSignalCrossCorrelation_64[bin]; } - max_common_val = GT_64( transportSignalEnergies_max, transportSignalCrossCorrelation_max ) ? transportSignalEnergies_max : transportSignalCrossCorrelation_max; + // max_common_val = GT_64( transportSignalEnergies_max, transportSignalCrossCorrelation_max ) ? transportSignalEnergies_max : transportSignalCrossCorrelation_max; + + IF( GT_64( transportSignalEnergies_max, transportSignalCrossCorrelation_max ) ) + { + max_common_val = transportSignalEnergies_max; // Q(2 * common_q) + } + ELSE + { + max_common_val = transportSignalCrossCorrelation_max; // Q(2 * common_q) + } + move64(); IF( max_common_val != 0 ) { @@ -3552,10 +3575,10 @@ void ivas_spar_param_to_masa_param_mapping_fx( { FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - transportSignalEnergies_32[ch][bin] = W_extract_l( transportSignalEnergies_64[ch][bin] ); + transportSignalEnergies_32[ch][bin] = W_extract_l( transportSignalEnergies_64[ch][bin] ); // Q(q_max_common) move32(); } - transportSignalCrossCorrelation_32[bin] = W_extract_l( transportSignalCrossCorrelation_64[bin] ); + transportSignalCrossCorrelation_32[bin] = W_extract_l( transportSignalCrossCorrelation_64[bin] ); // Q(q_max_common) move32(); } q_max_common = shl( common_q, 1 ); @@ -3566,10 +3589,10 @@ void ivas_spar_param_to_masa_param_mapping_fx( { FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - transportSignalEnergies_32[ch][bin] = W_extract_l( W_shr( transportSignalEnergies_64[ch][bin], sub( 32, headroom_left_max_common ) ) ); + transportSignalEnergies_32[ch][bin] = W_extract_l( W_shr( transportSignalEnergies_64[ch][bin], sub( 32, headroom_left_max_common ) ) ); // Q(q_max_common) move32(); } - transportSignalCrossCorrelation_32[bin] = W_extract_l( W_shr( transportSignalCrossCorrelation_64[bin], sub( 32, headroom_left_max_common ) ) ); + transportSignalCrossCorrelation_32[bin] = W_extract_l( W_shr( transportSignalCrossCorrelation_64[bin], sub( 32, headroom_left_max_common ) ) ); // Q(q_max_common) move32(); } q_max_common = sub( shl( common_q, 1 ), sub( 32, headroom_left_max_common ) ); @@ -3581,10 +3604,10 @@ void ivas_spar_param_to_masa_param_mapping_fx( { FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - transportSignalEnergies_32[ch][bin] = 0; + transportSignalEnergies_32[ch][bin] = 0; // Q(q_max_common) move32(); } - transportSignalCrossCorrelation_32[bin] = 0; + transportSignalCrossCorrelation_32[bin] = 0; // Q(q_max_common) move32(); } q_max_common = 31; @@ -3605,7 +3628,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( /* Set the energy of the first transport signal */ IF( EQ_16( nchan_transport, 1 ) ) { - inCovarianceMtx_fx[0][0] = ONE_IN_Q31; /* In case of 1TC, fixed value can be used */ + inCovarianceMtx_fx[0][0] = ONE_IN_Q31; /* In case of 1TC, fixed value can be used, Q(q_inCovarianceMtx)*/ move32(); q_inCovarianceMtx = 31; /* In case of 1TC, fixed value can be used */ move16(); @@ -3642,19 +3665,19 @@ void ivas_spar_param_to_masa_param_mapping_fx( compute_foa_cov_matrix_fx( foaCovarianceMtx_fx, inCovarianceMtx_fx, mixer_mat_sf_bins_real_fx[bin] ); - Iy_fx = foaCovarianceMtx_fx[0][1]; /* Intensity in Y direction */ + Iy_fx = foaCovarianceMtx_fx[0][1]; /* Intensity in Y direction */ // Q(q_inCovarianceMtx) + 2 * Q(31) - 62 move32(); - Iz_fx = foaCovarianceMtx_fx[0][2]; /* Intensity in Z direction */ + Iz_fx = foaCovarianceMtx_fx[0][2]; /* Intensity in Z direction */ // Q(q_inCovarianceMtx) + 2 * Q(31) - 62 move32(); - Ix_fx = foaCovarianceMtx_fx[0][3]; /* Intensity in X direction */ + Ix_fx = foaCovarianceMtx_fx[0][3]; /* Intensity in X direction */ // Q(q_inCovarianceMtx) + 2 * Q(31) - 62 move32(); - Word64 I1 = W_mult0_32_32( Ix_fx, Ix_fx ); - Word64 I2 = W_mult0_32_32( Iy_fx, Iy_fx ); - Word64 I3 = W_mult0_32_32( Iz_fx, Iz_fx ); - Word64 I_res = W_add( W_add( I1, I2 ), I3 ); + Word64 I1 = W_mult0_32_32( Ix_fx, Ix_fx ); // 2 * (Q(q_inCovarianceMtx) + 2 * Q(31) - 62) + Word64 I2 = W_mult0_32_32( Iy_fx, Iy_fx ); // 2 * (Q(q_inCovarianceMtx) + 2 * Q(31) - 62) + Word64 I3 = W_mult0_32_32( Iz_fx, Iz_fx ); // 2 * (Q(q_inCovarianceMtx) + 2 * Q(31) - 62) + Word64 I_res = W_add( W_add( I1, I2 ), I3 ); // 2 * (Q(q_inCovarianceMtx) + 2 * Q(31) - 62) - Word64 E_fx_64 = W_add( W_add( W_add( foaCovarianceMtx_fx[0][0], foaCovarianceMtx_fx[1][1] ), foaCovarianceMtx_fx[2][2] ), foaCovarianceMtx_fx[3][3] ); + Word64 E_fx_64 = W_add( W_add( W_add( foaCovarianceMtx_fx[0][0], foaCovarianceMtx_fx[1][1] ), foaCovarianceMtx_fx[2][2] ), foaCovarianceMtx_fx[3][3] ); // Q(q_inCovarianceMtx) E_fx = L_shr_sat( L_add_sat( L_add_sat( L_add_sat( foaCovarianceMtx_fx[0][0], foaCovarianceMtx_fx[1][1] ), foaCovarianceMtx_fx[2][2] ), foaCovarianceMtx_fx[3][3] ), 1 ); E_fx_64 = W_shr( E_fx_64, 1 ); @@ -3662,7 +3685,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( Word16 q_I_res; IF( LT_16( headroom_left_I_res, 32 ) ) { - I_res = W_shr( I_res, sub( 32, headroom_left_I_res ) ); + I_res = W_shr( I_res, sub( 32, headroom_left_I_res ) ); // q_I_res q_I_res = sub( 31, sub( shl( q_inCovarianceMtx, 1 ), sub( 32, headroom_left_I_res ) ) ); } ELSE @@ -3678,11 +3701,11 @@ void ivas_spar_param_to_masa_param_mapping_fx( } azi_q = 0; move16(); - azi_fx = BASOP_util_atan2( Iy_fx, Ix_fx, azi_q ); /* Azimuth */ + azi_fx = BASOP_util_atan2( Iy_fx, Ix_fx, azi_q ); /* Azimuth Q13*/ - Word64 I_ele_x = W_mult0_32_32( Ix_fx, Ix_fx ); - Word64 I_ele_y = W_mult0_32_32( Iy_fx, Iy_fx ); - Word64 I_ele = W_add( I_ele_x, I_ele_y ); + Word64 I_ele_x = W_mult0_32_32( Ix_fx, Ix_fx ); // Q(ele_q) + Word64 I_ele_y = W_mult0_32_32( Iy_fx, Iy_fx ); // Q(ele_q) + Word64 I_ele = W_add( I_ele_x, I_ele_y ); // Q(ele_q) Word16 headroom_left_I_ele = W_norm( I_ele ); IF( LT_16( headroom_left_I_ele, 32 ) ) { @@ -3696,11 +3719,11 @@ void ivas_spar_param_to_masa_param_mapping_fx( I_ele = Sqrt32( W_extract_l( I_ele ), &ele_q ); IF( ele_q < 0 ) { - I_ele = W_shr( I_ele, negate( ele_q ) ); + I_ele = W_shr( I_ele, negate( ele_q ) ); // Q0 ele_q = 0; move16(); } - ele_fx = BASOP_util_atan2( Iz_fx, W_extract_l( I_ele ), sub( sub( 31, q_inCovarianceMtx ), ele_q ) ); + ele_fx = BASOP_util_atan2( Iz_fx, W_extract_l( I_ele ), sub( sub( 31, q_inCovarianceMtx ), ele_q ) ); // Q13 num_q = sub( 31, q_I_res ); denom_q = q_inCovarianceMtx; @@ -3718,43 +3741,43 @@ void ivas_spar_param_to_masa_param_mapping_fx( move32(); ratio_float_fx = BASOP_Util_Divide3232_Scale( I_fx, E_fx, &res_q ); res_q = sub( res_q, sub( num_q, denom_q ) ); - ratio_fx = L_shl_sat( ratio_float_fx, add( Q15, res_q ) ); + ratio_fx = L_shl_sat( ratio_float_fx, add( Q15, res_q ) ); // Q(15 + res_q) - ratio_fx = L_max( 0, L_min( ratio_fx, ONE_IN_Q30 ) ); + ratio_fx = L_max( 0, L_min( ratio_fx, ONE_IN_Q30 ) ); // Q30 - azi_val = W_mult0_32_32( azi_fx, ONE_BY_PI_OVER_180_Q25 ); + azi_val = W_mult0_32_32( azi_fx, ONE_BY_PI_OVER_180_Q25 ); // Q13 + Q25 IF( azi_val < 0 ) { - azi_val = W_shr( W_neg( azi_val ), 13 + 25 ); + azi_val = W_shr( W_neg( azi_val ), 13 + 25 ); // Q0 azi_val = W_neg( azi_val ); } ELSE { - azi_val = W_shr( azi_val, 13 + 25 ); + azi_val = W_shr( azi_val, 13 + 25 ); // Q0 } - ele_val = W_mult0_32_32( ele_fx, ONE_BY_PI_OVER_180_Q25 ); + ele_val = W_mult0_32_32( ele_fx, ONE_BY_PI_OVER_180_Q25 ); // Q13 + q25 IF( ele_val < 0 ) { - ele_val = W_shr( W_neg( ele_val ), 13 + 25 ); - ele_val = W_neg( ele_val ); + ele_val = W_shr( W_neg( ele_val ), 13 + 25 ); // Q0 + ele_val = W_neg( ele_val ); // Q0 } ELSE { - ele_val = W_shr( ele_val, 13 + 25 ); + ele_val = W_shr( ele_val, 13 + 25 ); // Q0 } - hSpatParamRendCom->azimuth[dirac_write_idx][bin] = (Word16) azi_val; + hSpatParamRendCom->azimuth[dirac_write_idx][bin] = extract_l( W_extract_l( azi_val ) ); // Q0 move16(); - hSpatParamRendCom->elevation[dirac_write_idx][bin] = (Word16) ele_val; + hSpatParamRendCom->elevation[dirac_write_idx][bin] = extract_l( W_extract_l( ele_val ) ); // Q0 move16(); - hSpatParamRendCom->energy_ratio1_fx[dirac_write_idx][bin] = ratio_fx; + hSpatParamRendCom->energy_ratio1_fx[dirac_write_idx][bin] = ratio_fx; // Q30 move32(); - hSpatParamRendCom->diffuseness_vector_fx[dirac_write_idx][bin] = L_sub( ONE_IN_Q30, ratio_fx ); + hSpatParamRendCom->diffuseness_vector_fx[dirac_write_idx][bin] = L_sub( ONE_IN_Q30, ratio_fx ); // Q30 move32(); - hSpatParamRendCom->spreadCoherence_fx[dirac_write_idx][bin] = 0; + hSpatParamRendCom->spreadCoherence_fx[dirac_write_idx][bin] = 0; // Q15 move16(); - hSpatParamRendCom->surroundingCoherence_fx[dirac_write_idx][bin] = 0; + hSpatParamRendCom->surroundingCoherence_fx[dirac_write_idx][bin] = 0; // q15 move16(); /* Determine directional distribution of the indirect audio based on the SPAR mixing matrices (and the transport audio signals when 2 TC) */ @@ -3762,15 +3785,15 @@ void ivas_spar_param_to_masa_param_mapping_fx( { IF( EQ_16( nchan_transport, 1 ) ) { - diffuseGainY_fx = L_abs( mixer_mat_sf_bins_real_fx[bin][1][1] ); - diffuseGainX_fx = L_abs( mixer_mat_sf_bins_real_fx[bin][3][2] ); - diffuseGainZ_fx = L_abs( mixer_mat_sf_bins_real_fx[bin][2][3] ); + diffuseGainY_fx = L_abs( mixer_mat_sf_bins_real_fx[bin][1][1] ); // Q31 + diffuseGainX_fx = L_abs( mixer_mat_sf_bins_real_fx[bin][3][2] ); // Q31 + diffuseGainZ_fx = L_abs( mixer_mat_sf_bins_real_fx[bin][2][3] ); // Q31 } ELSE IF( EQ_16( nchan_transport, 2 ) ) { - diffuseGainY_fx = L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][1][1], transportSignalEnergies_32[1][bin] ) ); - diffuseGainX_fx = L_add_sat( L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][3][2], transportSignalEnergies_32[0][bin] ) ), L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][3][1], transportSignalEnergies_32[1][bin] ) ) ); - diffuseGainZ_fx = L_add_sat( L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][2][3], transportSignalEnergies_32[0][bin] ) ), L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][2][1], transportSignalEnergies_32[1][bin] ) ) ); + diffuseGainY_fx = L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][1][1], transportSignalEnergies_32[1][bin] ) ); // Q(q_max_common) + diffuseGainX_fx = L_add_sat( L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][3][2], transportSignalEnergies_32[0][bin] ) ), L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][3][1], transportSignalEnergies_32[1][bin] ) ) ); // Q(q_max_common) + diffuseGainZ_fx = L_add_sat( L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][2][3], transportSignalEnergies_32[0][bin] ) ), L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][2][1], transportSignalEnergies_32[1][bin] ) ) ); // Q(q_max_common) } ELSE { @@ -3785,7 +3808,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( IF( diffuseGainSum_fx == 0 ) { - hDiffuseDist->diffuseRatioX_fx[bin] = 715827904; + hDiffuseDist->diffuseRatioX_fx[bin] = 715827904; //(1.0f / 3.0f) in Q31 move32(); hDiffuseDist->diffuseRatioY_fx[bin] = 715827904; move32(); @@ -3796,44 +3819,44 @@ void ivas_spar_param_to_masa_param_mapping_fx( { Word16 temp_q = 0; move16(); - Word16 intermediate_results; - intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainX_fx, diffuseGainSum_fx + EPSILON_FX_SMALL, &temp_q ); + Word16 intermediate_results; // temp_q + intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainX_fx, L_add_sat( diffuseGainSum_fx, EPSILON_FX_SMALL ), &temp_q ); // saturating value to less than 1 IF( temp_q <= 0 ) { - intermediate_results = shr( intermediate_results, negate( temp_q ) ); + intermediate_results = shr( intermediate_results, negate( temp_q ) ); // Q15 } ELSE { - intermediate_results = shl_sat( intermediate_results, temp_q ); + intermediate_results = shl_sat( intermediate_results, temp_q ); // Q15 } - hDiffuseDist->diffuseRatioX_fx[bin] = L_deposit_h( intermediate_results ); + hDiffuseDist->diffuseRatioX_fx[bin] = L_deposit_h( intermediate_results ); // Q31 move32(); - intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainY_fx, diffuseGainSum_fx + EPSILON_FX_SMALL, &temp_q ); + intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainY_fx, L_add_sat( diffuseGainSum_fx, EPSILON_FX_SMALL ), &temp_q ); // saturating value to less than 1 IF( temp_q <= 0 ) { - intermediate_results = shr( intermediate_results, negate( temp_q ) ); + intermediate_results = shr( intermediate_results, negate( temp_q ) ); // Q15 } ELSE { - intermediate_results = shl_sat( intermediate_results, temp_q ); + intermediate_results = shl_sat( intermediate_results, temp_q ); // Q15 } - hDiffuseDist->diffuseRatioY_fx[bin] = L_deposit_h( intermediate_results ); + hDiffuseDist->diffuseRatioY_fx[bin] = L_deposit_h( intermediate_results ); // Q31 move32(); - intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainZ_fx, diffuseGainSum_fx + EPSILON_FX_SMALL, &temp_q ); + intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainZ_fx, L_add_sat( diffuseGainSum_fx, EPSILON_FX_SMALL ), &temp_q ); // saturating value to less than 1 IF( temp_q <= 0 ) { - intermediate_results = shr( intermediate_results, negate( temp_q ) ); + intermediate_results = shr( intermediate_results, negate( temp_q ) ); // Q15 } ELSE { - intermediate_results = shl_sat( intermediate_results, temp_q ); + intermediate_results = shl_sat( intermediate_results, temp_q ); // Q15 } - hDiffuseDist->diffuseRatioZ_fx[bin] = L_deposit_h( intermediate_results ); + hDiffuseDist->diffuseRatioZ_fx[bin] = L_deposit_h( intermediate_results ); // Q31 move32(); } } @@ -4068,9 +4091,9 @@ void ivas_spar_param_to_masa_param_mapping( /* Estimate FOA properties: foaCov = mixMtx * inCov * mixMtx' */ #ifdef IVAS_FLOAT_FIXED static void compute_foa_cov_matrix_fx( - Word32 foaCov_fx[FOA_CHANNELS][FOA_CHANNELS], /* o : Estimated FOA covariance matrix */ - Word32 inCov_fx[FOA_CHANNELS][FOA_CHANNELS], /* i : Input covariance matrix */ - Word32 mixMtx_fx[FOA_CHANNELS][FOA_CHANNELS] /* i : Mixing matrix */ + Word32 foaCov_fx[FOA_CHANNELS][FOA_CHANNELS], /* o : Estimated FOA covariance matrix Qx*/ + Word32 inCov_fx[FOA_CHANNELS][FOA_CHANNELS], /* i : Input covariance matrix Qx*/ + Word32 mixMtx_fx[FOA_CHANNELS][FOA_CHANNELS] /* i : Mixing matrix Q31*/ ) { Word32 tmpMtx_fx[FOA_CHANNELS][FOA_CHANNELS]; @@ -4084,7 +4107,7 @@ static void compute_foa_cov_matrix_fx( move32(); FOR( k = 0; k < FOA_CHANNELS; k++ ) { - tmpMtx_fx[i][j] = L_add_sat( tmpMtx_fx[i][j], Mpy_32_32( mixMtx_fx[i][k], inCov_fx[k][j] ) ); + tmpMtx_fx[i][j] = L_add_sat( tmpMtx_fx[i][j], Mpy_32_32( mixMtx_fx[i][k], inCov_fx[k][j] ) ); // Qx move32(); } } @@ -4099,7 +4122,7 @@ static void compute_foa_cov_matrix_fx( move32(); FOR( k = 0; k < FOA_CHANNELS; k++ ) { - foaCov_fx[i][j] = L_add_sat( foaCov_fx[i][j], Mpy_32_32( tmpMtx_fx[i][k], mixMtx_fx[j][k] ) ); + foaCov_fx[i][j] = L_add_sat( foaCov_fx[i][j], Mpy_32_32( tmpMtx_fx[i][k], mixMtx_fx[j][k] ) ); // Qx move32(); } } @@ -4362,7 +4385,7 @@ static void create_masa_ext_out_meta_fx( #endif UWord8 tmp = (UWord8) L_shr( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], Q30 - 8 ); move16(); - extOutMeta->directToTotalRatio[dir][sf][b_new] = tmp; + extOutMeta->directToTotalRatio[dir][sf][b_new] = tmp; // Q8 move16(); } } @@ -4421,9 +4444,16 @@ static void create_masa_ext_out_meta_fx( move16(); FOR( dir = 0; dir < numDirections; dir++ ) { - UWord8 tmp = (UWord8) L_shr( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], Q30 - 8 ); +#ifdef FIX_953_WRONG_ENERGY_RATIO_MASA_EXT + /* todo: not optimal, but less invasive */ + IF( EQ_32( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], ONE_IN_Q30 ) ) + { + hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf]--; + } +#endif + UWord8 tmp = (UWord8) L_shr( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], Q30 - 8 ); // Q8 move16(); - extOutMeta->diffuseToTotalRatio[sf][b_new] = (UWord8) sub( extOutMeta->diffuseToTotalRatio[sf][b_new], tmp ); + extOutMeta->diffuseToTotalRatio[sf][b_new] = (UWord8) sub( extOutMeta->diffuseToTotalRatio[sf][b_new], tmp ); // Q8 move16(); } } @@ -4511,9 +4541,9 @@ static void decode_index_slice( #else static void decode_index_slice_fx( Word16 index, /* i : index to decode */ - Word16 *ratio_idx_ism, /* o : decodec array of integers */ + Word16 *ratio_idx_ism, /* o : decodec array of integers Q0*/ const Word16 nchan_ism, /* i : number of elements in array (objects) */ - const Word16 K /* i : sum of array elements */ + const Word16 K /* i : sum of array elements Q0*/ ) { Word16 i, j, sum, elem; @@ -4561,7 +4591,7 @@ static void decode_index_slice_fx( { elem = idiv1616( j, base[i] ); } - ratio_idx_ism[sub( sub( nchan_ism, i ), 2 )] = elem; + ratio_idx_ism[nchan_ism - i - 2] = elem; move16(); sum = add( sum, elem ); j = sub( j, i_mult( elem, base[i] ) ); @@ -4851,14 +4881,14 @@ static void read_ism_ratio_index( } #else static void read_ism_ratio_index_fx( - Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* o : ISM read ratio indexes */ + Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* o : ISM read ratio indexes Q0*/ const Word16 nchan_ism, /* i : number of objects */ const Word16 numCodingBands, /* i : number of subbands */ const Word16 sf, /* i : index of subframe */ - Word16 ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* i : previous subframe ISM ratio indexes */ + Word16 ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* i : previous subframe ISM ratio indexes Q0*/ UWord16 *bit_stream, /* i : bitstream */ Word16 *next_bit_pos, /* i/o: position in bitstream */ - const Word32 *masa_to_total_energy_ratio_fx, /* i : masa to total ratios */ + const Word32 *masa_to_total_energy_ratio_fx, /* i : masa to total ratios Q30*/ const Word16 idx_sep_obj, /* i : index of separated index, -1 if none */ Word16 *num_zeros /* i/o: number of zero values in first subframe for separated object */ ) @@ -4975,7 +5005,7 @@ static void read_ism_ratio_index_fx( } ratio_ism_idx[b][i] = add( ratio_ism_idx[b][i], ratio_ism_idx_ref[i] ); move16(); - ratio_ism_idx[b][sub( nchan_ism, 1 )] = sub( ratio_ism_idx[b][sub( nchan_ism, 1 )], ratio_ism_idx[b][i] ); + ratio_ism_idx[b][nchan_ism - 1] = sub( ratio_ism_idx[b][nchan_ism - 1], ratio_ism_idx[b][i] ); move16(); } Copy( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism ); @@ -5054,7 +5084,7 @@ static void read_ism_ratio_index_fx( { IF( LT_32( masa_to_total_energy_ratio_fx[b], MASA2TOTAL_THR_Q30 ) ) { - FOR( i = 0; i < sub( nchan_ism, add( 1, shift_one ) ); i++ ) + FOR( i = 0; i < nchan_ism - ( 1 + shift_one ); i++ ) { buf = ivas_qmetadata_DecodeExtendedGR( bit_stream, next_bit_pos, 100, GR_order ); IF( ( buf % 2 ) == 0 ) @@ -5254,8 +5284,8 @@ static void decode_ism_ratios( static void decode_ism_ratios_fx( UWord16 *bit_stream, /* i : bitstream */ Word16 *next_bit_pos, /* i/o: position in bitstream */ - Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : masa_to_total energy ratios */ - Word32 ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* o : ISM ratios */ + Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : masa_to_total energy ratios Q30*/ + Word32 ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* o : ISM ratios Q30*/ const Word16 n_ism, /* i : number of objects */ const Word16 nbands, /* i : number of subbands */ const Word16 numSf, /* i : number of subframes */ @@ -5298,7 +5328,7 @@ static void decode_ism_ratios_fx( { IF( LT_32( masa_to_total_energy_ratio_fx[sf][band], MASA2TOTAL_THR_Q30 ) ) { - tmp32_fx = ratio_ism[sf][band][n_ism - 1]; + tmp32_fx = ratio_ism[sf][band][n_ism - 1]; // Q30 move32(); ratio_ism[sf][band][n_ism - 1] = ratio_ism[sf][band][0]; move32(); @@ -5496,14 +5526,14 @@ static Word16 ivas_decode_masaism_metadata_fx( const Word16 dirac_md_buffer_length ) { Word16 sf, band, dir, nbands, nblocks, obj, i; - Word32 energy_ratio_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + Word32 energy_ratio_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; // Q30 Word16 *band_mapping; Word16 b; Word16 bits_ism[MAX_NUM_OBJECTS], index; UWord16 idx_el, idx_az; - Word32 azimuth, elevation; + Word32 azimuth, elevation; // Q22 Word16 nb_bits_read; - Word32 delta_phi; + Word32 delta_phi; // Q22 Word16 meta_write_index; nb_bits_read = *next_bit_pos; @@ -5545,9 +5575,9 @@ static Word16 ivas_decode_masaism_metadata_fx( /* read if same as previous */ IF( bit_stream[( *next_bit_pos )--] ) { - azimuth = hMasaIsmData->q_azimuth_old_fx[obj]; + azimuth = hMasaIsmData->q_azimuth_old_fx[obj]; // Q22 move32(); - elevation = hMasaIsmData->q_elevation_old_fx[obj]; + elevation = hMasaIsmData->q_elevation_old_fx[obj]; // Q22 move32(); } ELSE @@ -5562,19 +5592,33 @@ static Word16 ivas_decode_masaism_metadata_fx( test(); test(); test(); - // if ( azimuth * hMasaIsmData->q_azimuth_old[obj] > 0 ) + /* if ( azimuth * hMasaIsmData->q_azimuth_old[obj] > 0 ) */ IF( ( ( azimuth > 0 ) && ( hMasaIsmData->q_azimuth_old_fx[obj] > 0 ) ) || ( ( azimuth < 0 ) && ( hMasaIsmData->q_azimuth_old_fx[obj] < 0 ) ) ) { Word16 tmp_e; delta_phi = L_deposit_h( BASOP_Util_Divide1616_Scale( 180, no_phi_masa[bits_ism[obj] - 1][idx_el], &tmp_e ) ); delta_phi = L_shr( delta_phi, sub( 9, tmp_e ) ); /* to maintain Q22 */ + +#ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC + Word32 tmp_32; + Word64 tmp_64; + tmp_32 = L_sub( azimuth, hMasaIsmData->q_azimuth_old_fx[obj] ); + tmp_64 = W_mult_32_16( tmp_32, no_phi_masa[bits_ism[obj] - 1][idx_el] ); + + IF( GT_64( tmp_64, TOLERANCE_360_Q22 ) ) /* >= 360 in Q22 (because there is an additional shift left in W_mult_32_16) + 0.02 in Q22 to counteract for precision loss, */ +#else IF( GT_32( L_sub( azimuth, hMasaIsmData->q_azimuth_old_fx[obj] ), delta_phi ) ) +#endif { azimuth = L_sub( azimuth, delta_phi ); } ELSE { +#ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC + IF( GT_64( MINUS_TOLERANCE_360_Q22, tmp_64 ) ) +#else if ( GT_32( L_sub( hMasaIsmData->q_azimuth_old_fx[obj], azimuth ), delta_phi ) ) +#endif { azimuth = L_add( azimuth, delta_phi ); } @@ -5605,12 +5649,12 @@ static Word16 ivas_decode_masaism_metadata_fx( { meta_write_index = add( dirac_bs_md_write_idx, sf ) % dirac_md_buffer_length; - Word16 int_azi = rint_fx( L_shr( azimuth, Q22 - 16 ) ); - Word16 int_ele = rint_fx( L_shr( elevation, Q22 - 16 ) ); + Word16 int_azi = rint_fx( L_shr( azimuth, Q22 - 16 ) ); // Q0, extra -16 is added as int_azi is W16 and azimuth is W32 + Word16 int_ele = rint_fx( L_shr( elevation, Q22 - 16 ) ); // Q0 - hMasaIsmData->azimuth_ism[obj][meta_write_index] = int_azi; + hMasaIsmData->azimuth_ism[obj][meta_write_index] = int_azi; // Q0 move16(); - hMasaIsmData->elevation_ism[obj][meta_write_index] = int_ele; + hMasaIsmData->elevation_ism[obj][meta_write_index] = int_ele; // Q0 move16(); } } @@ -5671,7 +5715,7 @@ static Word16 rint_fx( /* returns in Q0 */ Word32 num /* num in Q0 */ ) { - Word32 frac_part = L_abs( num ) & 0x0000FFFF; + Word32 frac_part = L_and( L_abs( num ), 0x0000FFFF ); // Q15 Word16 int_part = extract_h( L_abs( num ) ); Word16 res = int_part; move16(); diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index e2d9831546369937efb8eea67c2b03ec27a9b123..b9e9137a1ac2b0159e0b1b64eb202abfd9306910 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -265,8 +265,8 @@ ivas_error ivas_param_mc_dec_open_fx( { st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->hLsSetupCustom->num_spk; move32(); - st_ivas->hIntSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx; - st_ivas->hIntSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx; + st_ivas->hIntSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx; // Q22 + st_ivas->hIntSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx; // Q22 } } ELSE @@ -324,9 +324,9 @@ ivas_error ivas_param_mc_dec_open_fx( // hParamMC->slot_size = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX; Word16 temp_e; Word16 temp = BASOP_Util_Divide3232_Scale( output_Fs, FRAMES_PER_SEC, &temp_e ); - temp = shr( temp, sub( 15, temp_e ) ); + temp = shr( temp, sub( 15, temp_e ) ); // Going back to Q0 temp = BASOP_Util_Divide1616_Scale( temp, CLDFB_NO_COL_MAX, &temp_e ); - temp = shr( temp, sub( 15, temp_e ) ); + temp = shr( temp, sub( 15, temp_e ) ); // Going back to Q0 hParamMC->slot_size = temp; move16(); set16_fx( hParamMC->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); @@ -355,8 +355,8 @@ ivas_error ivas_param_mc_dec_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ) ); - set16_fx( hParamMC->icc_q_fx, 0, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ) ); + set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ) ); // Q8 + set16_fx( hParamMC->icc_q_fx, 0, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ) ); // Q15 param_mc_set_num_synth_bands( output_Fs, hParamMC ); @@ -414,7 +414,7 @@ ivas_error ivas_param_mc_dec_open_fx( FOR( k = 0; k < nchan_out_transport; k++ ) { - Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[L_mult0( k, nchan_out_cov )], nchan_out_cov ); /*Q30*/ + Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov ); /*Q30*/ } /* convert ParamMC parameter bands to SFB */ @@ -454,7 +454,7 @@ ivas_error ivas_param_mc_dec_open_fx( { proto_mtx_norm_fx = ONE_IN_Q26; /*Q26*/ move32(); - FOR( k = 0; k < imult1616( nchan_transport, nchan_out_cov ); k++ ) + FOR( k = 0; k < nchan_transport * nchan_out_cov; k++ ) { proto_mtx_norm_fx = L_max( L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); /*Q.26*/ } @@ -465,7 +465,7 @@ ivas_error ivas_param_mc_dec_open_fx( { FOR( Word16 i = 0; i < nchan_out_cov; i++ ) { - st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mult_32_16( proto_matrix_fx[add( imult1616( k, nchan_out_cov ), i )], extract_l( proto_mtx_norm_fx ) ), 4 ); /*Q.30*/ + st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mult_32_16( proto_matrix_fx[k * nchan_out_cov + i], extract_l( proto_mtx_norm_fx ) ), 4 ); /*Q.30*/ move32(); } } @@ -507,7 +507,7 @@ ivas_error ivas_param_mc_dec_open_fx( hParamMC->h_freq_domain_decorr_ap_params = NULL; hParamMC->h_freq_domain_decorr_ap_state = NULL; - ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); + ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); // Q0 IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff, hParamMC->diff_proto_info->num_protos_diff, DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ), @@ -1034,7 +1034,7 @@ static void ivas_param_mc_get_param_band_mapping( Word16 upper = target_band_grouping[target_band_idx + 1]; Word16 lower = target_band_grouping[target_band_idx]; Word16 source_band_in_target_band_cnt = 0; - Word16 norm_fac_fx = 32767; + Word16 norm_fac_fx = 32767; // 1.Q15 source_band_cnt_total = 0; move16(); move16(); @@ -1221,7 +1221,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( /*-----------------------------------------------------------------* * set input parameters *-----------------------------------------------------------------*/ - hParamMC->num_freq_bands = shr( add( (Word16) Mpy_32_32( output_Fs, INV_CLDFB_BANDWIDTH_Q31 << 1 ), 1 ), 1 ); + hParamMC->num_freq_bands = shr( add( (Word16) Mpy_32_32( output_Fs, INV_CLDFB_BANDWIDTH_Q31 << 1 ), 1 ), 1 ); // Q0 move16(); hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands; move16(); @@ -1267,8 +1267,8 @@ ivas_error ivas_param_mc_dec_reconfig_fx( test(); IF( NE_16( nchan_transport_old, nchan_transport ) || NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) ) { - Word16 *ild_q_old_fx = hParamMC->icld_q_fx; - Word16 *icc_q_old_fx = hParamMC->icc_q_fx; + Word16 *ild_q_old_fx = hParamMC->icld_q_fx; // Q8 + Word16 *icc_q_old_fx = hParamMC->icc_q_fx; // Q15 IF( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( Word16 ) ) ) == NULL ) { @@ -1287,8 +1287,8 @@ ivas_error ivas_param_mc_dec_reconfig_fx( { Word16 new_param_band_idx, param_idx, source_param_idx; Word16 num_param_lfe; - Word16 *p_icc_new_fx = hParamMC->icc_q_fx; - Word16 *p_ild_new_fx = hParamMC->icld_q_fx; + Word16 *p_icc_new_fx = hParamMC->icc_q_fx; // Q15 + Word16 *p_ild_new_fx = hParamMC->icld_q_fx; // Q8 Word16 p_ild_new_e = 23; move16(); Word16 p_ild_new_tmp; @@ -1322,11 +1322,11 @@ ivas_error ivas_param_mc_dec_reconfig_fx( move16(); FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) { - p_ild_new_tmp = extract_h( BASOP_util_Pow2( L_mult0( 10885 /*log2(10)/10*2^15*/, ild_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx] ), 8, &p_ild_new_e ) ); + p_ild_new_tmp = extract_h( BASOP_util_Pow2( L_mult0( 10885 /*log2(10)/10*2^15*/, ild_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx] ), 8, &p_ild_new_e ) ); // 31 - p_ild_new_e - 16 *p_ild_new_fx = add( *p_ild_new_fx, mult( p_ild_new_tmp, parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] ) ); move16(); } - *p_ild_new_fx = extract_l( L_shr( Mpy_32_16_1( L_add( BASOP_Util_Log2( *p_ild_new_fx ), L_add( 16 << Q25, L_shl( p_ild_new_e, 25 ) ) ), 24660 ), 15 ) ); + *p_ild_new_fx = extract_l( L_shr( Mpy_32_16_1( L_add( BASOP_Util_Log2( *p_ild_new_fx ), L_add( 16 << Q25, L_shl( p_ild_new_e, 25 ) ) ), 24660 /*3.Q13*/ ), 15 ) ); // Q8 move16(); p_ild_new_fx++; } @@ -1411,19 +1411,19 @@ ivas_error ivas_param_mc_dec_reconfig_fx( test(); IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { - Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), -4 ); + Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), -4 ); // Q30 -> Q26 matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0, ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0, proto_matrix_fx /*Q26*/ ); - Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), 4 ); + Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), 4 ); // Q26 -> Q30 IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { - proto_mtx_norm_fx = ONE_IN_Q26; + proto_mtx_norm_fx = ONE_IN_Q26; // Q26 move32(); - FOR( k = 0; k < imult1616( nchan_transport, nchan_out_cov ); k++ ) + FOR( k = 0; k < nchan_transport * nchan_out_cov; k++ ) { - proto_mtx_norm_fx = L_max( L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); + proto_mtx_norm_fx = L_max( L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); // Q26 } proto_mtx_norm_fx = divide3232( ONE_IN_Q26, proto_mtx_norm_fx ); /*Q15*/ @@ -1432,7 +1432,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( { FOR( Word16 i = 0; i < nchan_out_cov; i++ ) { - st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mpy_32_16_1( proto_matrix_fx[k * nchan_out_cov + i], (Word16) proto_mtx_norm_fx ), 4 ); + st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mpy_32_16_1( proto_matrix_fx[k * nchan_out_cov + i], (Word16) proto_mtx_norm_fx ), 4 ); // Q26 -> Q30 move32(); } } @@ -1497,7 +1497,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( hParamMC->h_freq_domain_decorr_ap_state = NULL; Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX]; - ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); + ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); // Q0 IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff, hParamMC->diff_proto_info->num_protos_diff, DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ), @@ -1571,14 +1571,14 @@ ivas_error ivas_param_mc_dec_reconfig_fx( FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) { /* Cx */ - v_multc_fixed_16( cov_state_old.cx_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_transport_old, nchan_transport_old ) ); - v_add_fixed_me( tmp_buf_fx, cov_state_old.cx_old_e[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx], imult1616( nchan_transport_old, nchan_transport_old ), 0 ); + v_multc_fixed_16( cov_state_old.cx_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_transport_old, nchan_transport_old ) ); // Q(31 - cov_state_old.cx_old_e) + v_add_fixed_me( tmp_buf_fx, cov_state_old.cx_old_e[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx], imult1616( nchan_transport_old, nchan_transport_old ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx]) /* Cy */ - v_multc_fixed_16( cov_state_old.cy_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_out_cov, nchan_out_cov ) ); - v_add_fixed_me( tmp_buf_fx, cov_state_old.cy_old_e[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); + v_multc_fixed_16( cov_state_old.cy_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_out_cov, nchan_out_cov ) ); // Q(31 - cov_state_old.cy_old_e) + v_add_fixed_me( tmp_buf_fx, cov_state_old.cy_old_e[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx]) /* mixing matrix*/ - v_multc_fixed_16( cov_state_old.mixing_matrix_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_transport_old, nchan_out_cov ) ); - v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], imult1616( nchan_transport_old, nchan_out_cov ), 0 ); + v_multc_fixed_16( cov_state_old.mixing_matrix_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_transport_old, nchan_out_cov ) ); // Q(31 - mixing_matrix_old_exp) + v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], imult1616( nchan_transport_old, nchan_out_cov ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx]) } } FOR( new_param_band_idx = 0; new_param_band_idx < max_param_band_residual; new_param_band_idx++ ) @@ -1586,8 +1586,8 @@ ivas_error ivas_param_mc_dec_reconfig_fx( FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) { /* residual mixing matrix*/ - v_multc_fixed_16( cov_state_old.mixing_matrix_res_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_out_cov, nchan_out_cov ) ); - v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_res_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); + v_multc_fixed_16( cov_state_old.mixing_matrix_res_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_out_cov, nchan_out_cov ) ); // Q(31 - mixing_matrix_res_old_exp) + v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_res_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); // Q(hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx]) } } } @@ -1618,12 +1618,12 @@ ivas_error ivas_param_mc_dec_reconfig_fx( IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL ) { free( hParamMC->Cldfb_RealBuffer_tc_fx ); - hParamMC->Cldfb_RealBuffer_tc_fx = NULL; + hParamMC->Cldfb_RealBuffer_tc_fx = NULL; // Q12 } IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL ) { free( hParamMC->Cldfb_ImagBuffer_tc_fx ); - hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; + hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; // Q12 } n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS; @@ -2257,13 +2257,13 @@ void ivas_param_mc_dec_close_fx( IF( hParamMC->icc_q_fx != NULL ) { free( hParamMC->icc_q_fx ); - hParamMC->icc_q_fx = NULL; + hParamMC->icc_q_fx = NULL; // Q15 } IF( hParamMC->icld_q_fx != NULL ) { free( hParamMC->icld_q_fx ); - hParamMC->icld_q_fx = NULL; + hParamMC->icld_q_fx = NULL; // Q8 } /* diffuse prototype info */ IF( hParamMC->diff_proto_info ) @@ -2963,10 +2963,10 @@ void ivas_param_mc_dec_digest_tc_fx( hParamMC = st_ivas->hParamMC; assert( hParamMC ); Word32 *pCx, *pCx_imag; - Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; - Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; - Word32 cx_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; - Word32 cx_imag_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; + Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_e) + Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_imag_e) + Word32 cx_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_next_band_e) + Word32 cx_imag_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_imag_next_band_e) Word16 cx_buff_e[2][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; Word16 cx_e; @@ -3077,8 +3077,8 @@ void ivas_param_mc_dec_digest_tc_fx( move16(); cldfbAnalysis_ts_fx_fixed_q( &( transport_channels_f_fx[ch][hParamMC->num_freq_bands * slot_idx] ), RealBuffer_fx, ImagBuffer_fx, hParamMC->num_freq_bands, st_ivas->cldfbAnaDec[ch], &qout ); - Copy32( RealBuffer_fx, &hParamMC->Cldfb_RealBuffer_tc_fx[L_add( L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport ), L_mult0( ch, hParamMC->num_freq_bands ) )], hParamMC->num_freq_bands ); - Copy32( ImagBuffer_fx, &hParamMC->Cldfb_ImagBuffer_tc_fx[L_add( L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport ), L_mult0( ch, hParamMC->num_freq_bands ) )], hParamMC->num_freq_bands ); + Copy32( RealBuffer_fx, &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands ); + Copy32( ImagBuffer_fx, &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands ); } hParamMC->Cldfb_ImagBuffer_tc_e = qout; @@ -3096,9 +3096,9 @@ void ivas_param_mc_dec_digest_tc_fx( } IF( is_next_band ) { - ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport )], + ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport], /*hParamMC->Cldfb_RealBuffer_tc_e*/ Q31 - Q6, - &hParamMC->Cldfb_ImagBuffer_tc_fx[L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport )], + &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport], /*hParamMC->Cldfb_ImagBuffer_tc_e*/ Q31 - Q6, cx_next_band_fx, &cx_next_band_e, @@ -3110,9 +3110,9 @@ void ivas_param_mc_dec_digest_tc_fx( } ELSE { - ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport )], + ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport], /*hParamMC->Cldfb_RealBuffer_tc_e*/ Q31 - Q6, - &hParamMC->Cldfb_ImagBuffer_tc_fx[L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport )], + &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport], /*hParamMC->Cldfb_ImagBuffer_tc_e*/ Q31 - Q6, cx_fx, &cx_e, @@ -3151,9 +3151,9 @@ void ivas_param_mc_dec_digest_tc_fx( tmp_cx_imag_e = cx_imag_e; } - FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ ) + FOR( i = 0; i < nchan_transport * nchan_transport; i++ ) { - real_part_fx = pCx[i]; + real_part_fx = pCx[i]; // Q(31 - cx_buff_e) imag_part_fx = pCx_imag[i]; move32(); move32(); @@ -3649,7 +3649,7 @@ void ivas_param_mc_dec_render_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *output_f_fx[], /* o : rendered time signal */ + Word32 *output_f_fx[], /* o : rendered time signal Q11*/ Word16 channel_active_fx[MAX_OUTPUT_CHANNELS] ) { PARAM_MC_DEC_HANDLE hParamMC; @@ -3667,10 +3667,10 @@ void ivas_param_mc_dec_render_fx( Word32 *p_output_f_fx[MAX_OUTPUT_CHANNELS]; FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - p_output_f_fx[i] = output_f_fx[i]; + p_output_f_fx[i] = output_f_fx[i]; // Q11 } /*Decorrelator*/ - Word32 onset_filter_fx[MAX_CICP_CHANNELS * CLDFB_NO_CHANNELS_MAX]; + Word32 onset_filter_fx[MAX_CICP_CHANNELS * CLDFB_NO_CHANNELS_MAX]; // Q31 /* format converter */ Word16 channel_active[MAX_OUTPUT_CHANNELS]; @@ -3860,15 +3860,15 @@ void ivas_param_mc_dec_render_fx( /* copy decorrelated frame directly to output CLDFB buffer, acts also as intermediate */ /* memory FOR the decorrelated signal */ - ivas_param_mc_dec_copy_diffuse_proto( hParamMC, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, nchan_out_cov, slot_idx ); + ivas_param_mc_dec_copy_diffuse_proto( hParamMC, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, nchan_out_cov, slot_idx ); // Returns Cldfb buffers in Q11(tmp_q) FOR( k = 0; k < nchan_out_cov; k++ ) { FOR( Word16 l = 0; l < hParamMC->h_output_synthesis_params.max_band_decorr; l++ ) { - Cldfb_RealBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_RealBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); + Cldfb_RealBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_RealBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); // Q11(tmp_q) -> Q6 move32(); - Cldfb_ImagBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_ImagBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); + Cldfb_ImagBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_ImagBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); // Q11(tmp_q) -> Q6 move32(); } } @@ -3878,8 +3878,8 @@ void ivas_param_mc_dec_render_fx( * output synthesis *-----------------------------------------------------------------*/ ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( - &hParamMC->Cldfb_RealBuffer_tc_fx[L_mult0( imult1616( hParamMC->slots_rendered, nchan_transport ), hParamMC->num_freq_bands )], - &hParamMC->Cldfb_ImagBuffer_tc_fx[L_mult0( imult1616( hParamMC->slots_rendered, nchan_transport ), hParamMC->num_freq_bands )], Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, slot_idx, add( slot_idx, slot_idx_start ), + &hParamMC->Cldfb_RealBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands], + &hParamMC->Cldfb_ImagBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands], Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, slot_idx, add( slot_idx, slot_idx_start ), nchan_transport, nchan_out_cov, hParamMC ); test(); @@ -3897,8 +3897,8 @@ void ivas_param_mc_dec_render_fx( { FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - Scale_sig32( Cldfb_RealBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q_Cldfb_ImagBuffer, Q6 ) ); - Scale_sig32( Cldfb_ImagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q_Cldfb_RealBuffer, Q6 ) ); + Scale_sig32( Cldfb_RealBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q_Cldfb_ImagBuffer, Q6 ) ); // Q1 + Scale_sig32( Cldfb_ImagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q_Cldfb_RealBuffer, Q6 ) ); // Q1 } } ivas_param_mc_mc2sba_cldfb_fx( st_ivas->hTransSetup, hParamMC->hoa_encoder_fx, slot_idx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, nband_synth, GAIN_LFE_FX ); @@ -3906,8 +3906,8 @@ void ivas_param_mc_dec_render_fx( { FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - Scale_sig32( Cldfb_RealBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_Cldfb_ImagBuffer ) ); - Scale_sig32( Cldfb_ImagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_Cldfb_RealBuffer ) ); + Scale_sig32( Cldfb_RealBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_Cldfb_ImagBuffer ) ); // Q6 + Scale_sig32( Cldfb_ImagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_Cldfb_RealBuffer ) ); // Q6 } } } @@ -3994,8 +3994,8 @@ void ivas_param_mc_dec_render_fx( { FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ ) { - Cldfb_RealBuffer_fx[i][j][k] = L_shl( Cldfb_RealBuffer_fx[i][j][k], sub( Q6, input_q ) ); - Cldfb_ImagBuffer_fx[i][j][k] = L_shl( Cldfb_ImagBuffer_fx[i][j][k], sub( Q6, input_q ) ); + Cldfb_RealBuffer_fx[i][j][k] = L_shl( Cldfb_RealBuffer_fx[i][j][k], sub( Q6, input_q ) ); // Q6 + Cldfb_ImagBuffer_fx[i][j][k] = L_shl( Cldfb_ImagBuffer_fx[i][j][k], sub( Q6, input_q ) ); // Q6 } } } @@ -4004,8 +4004,8 @@ void ivas_param_mc_dec_render_fx( { FOR( Word16 idx2 = 0; idx2 < hParamMC->subframe_nbslots[subframe_idx]; idx2++ ) { - Scale_sig32( Cldfb_RealBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); - Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); + Scale_sig32( Cldfb_RealBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); // Q6 + Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); // Q6 } } /* update combined orientation access index */ @@ -4031,26 +4031,26 @@ void ivas_param_mc_dec_render_fx( { IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { - RealBuffer_fx[i] = Cldfb_RealBuffer_Binaural_fx[ch][i]; - ImagBuffer_fx[i] = Cldfb_ImagBuffer_Binaural_fx[ch][i]; + RealBuffer_fx[i] = Cldfb_RealBuffer_Binaural_fx[ch][i]; // Q6 + ImagBuffer_fx[i] = Cldfb_ImagBuffer_Binaural_fx[ch][i]; // Q6 } ELSE { - RealBuffer_fx[i] = Cldfb_RealBuffer_fx[ch][i]; - ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[ch][i]; + RealBuffer_fx[i] = Cldfb_RealBuffer_fx[ch][i]; // Q6 + ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[ch][i]; // Q6 } } Word16 len = add( imult1616( slot_idx_start_cldfb_synth, hParamMC->num_freq_bands ), imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ) ); scale_sig32( output_f_fx[ch], len, 5 - 11 ); - cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][L_mult0( slot_idx_start_cldfb_synth, hParamMC->num_freq_bands )] ), + cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands] ), imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ), st_ivas->cldfbSynDec[ch] ); - scale_sig32( output_f_fx[ch], len, 11 - 5 ); + scale_sig32( output_f_fx[ch], len, 11 - 5 ); // Q11 } ELSE { - set32_fx( &( output_f_fx[ch][L_mult0( slot_idx_start_cldfb_synth, hParamMC->num_freq_bands )] ), 0, imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ) ); + set32_fx( &( output_f_fx[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands] ), 0, imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ) ); } } slot_idx_start = add( slot_idx_start, hParamMC->subframe_nbslots[subframe_idx] ); @@ -4657,13 +4657,13 @@ static void ivas_param_mc_dec_copy_diffuse_proto( FOR( k = 0; k < nY; k++ ) { - p_proto_diff_fx = hParamMC->proto_frame_dec_f_fx + imult1616( shl( k, 1 ), num_freq_bands ); + p_proto_diff_fx = hParamMC->proto_frame_dec_f_fx + imult1616( shl( k, 1 ), num_freq_bands ); // Q11 FOR( l = 0; l < num_freq_bands_diff; l++ ) { - Cldfb_buffer_real_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); + Cldfb_buffer_real_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); // Q11 move32(); - Cldfb_buffer_imag_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); + Cldfb_buffer_imag_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); // Q11 move32(); } } @@ -4752,9 +4752,9 @@ static int16_t ivas_param_mc_bin2dec( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_param_mc_uniform_decoder_fx( - Word16 *seq, /* o : decoded sequence of float values */ + Word16 *seq, /* o : decoded sequence of float values hParamCodingInfo -> Q-quant*/ const Word16 sz_seq, /* i : number of values to decode */ - const Word16 *alphabet, /* i : codebook */ + const Word16 *alphabet, /* i : codebook hParamCodingInfo -> Q-quant*/ const Word16 N, /* i : number of bits per coded index */ UWord16 bit_buffer[PARAM_MC_MAX_BITS] /* i : bit buffer to decode */ ) @@ -4940,7 +4940,7 @@ static void ivas_param_mc_dec_compute_interpolator_fx( IF( bAttackPresent ) { - FOR( idx = 0; idx < shl( attackPos, 1 ); idx++ ) + FOR( idx = 0; idx < attackPos * 2; idx++ ) { interpolator[idx] = 0; move16(); @@ -5047,11 +5047,11 @@ static void remove_lfe_from_cy_fx( ptrCy = cy; ptrCy_out = cy_woLFE; - FOR( lfe_idx1 = 0; lfe_idx1 < add( num_lfe, 1 ); lfe_idx1++ ) + FOR( lfe_idx1 = 0; lfe_idx1 < num_lfe + 1; lfe_idx1++ ) { FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ ) { - FOR( lfe_idx2 = 0; lfe_idx2 < add( num_lfe, 1 ); lfe_idx2++ ) + FOR( lfe_idx2 = 0; lfe_idx2 < num_lfe + 1; lfe_idx2++ ) { FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ ) { @@ -5325,12 +5325,12 @@ static void ivas_param_mc_get_mixing_matrices( static void ivas_param_mc_get_mixing_matrices_fx( PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */ IVAS_OUTPUT_SETUP *hSynthesisOutputSetup, - Word32 Cx_in_fixed[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* i : input covariance for all parameter bands */ + Word32 Cx_in_fixed[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* i : input covariance for all parameter bands Q(31 - Cx_in_e)*/ Word16 Cx_in_e, const Word16 param_band_idx, /* i : parameter band index */ - Word32 *mixing_matrix_fx[], + Word32 *mixing_matrix_fx[], // Q(31 - mixing_matrix_e) Word16 *mixing_matrix_e, - Word32 *mixing_matrix_res_fx[], + Word32 *mixing_matrix_res_fx[], // Q(31 - mixing_matrix_res_e) Word16 *mixing_matrix_res_e, const Word16 nY_intern, /* i : number of channels in the transported format */ const PARAM_MC_SYNTHESIS_CONF synth_config, /* i : Parametric MC synthesis config */ @@ -5352,33 +5352,33 @@ static void ivas_param_mc_get_mixing_matrices_fx( Word32 Cy_full_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; - Word32 Cr_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + Word32 Cr_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cr_e) Word16 Cr_e; - Word32 Cy_diag_fx[MAX_OUTPUT_CHANNELS]; + Word32 Cy_diag_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - Cy_diag_buff_e) Word16 Cy_diag_buff_e[MAX_OUTPUT_CHANNELS]; - Word32 mixing_matrix_local_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; + Word32 mixing_matrix_local_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - mixing_matrix_local_e) Word16 Cy_diag_e = 0, mixing_matrix_local_e = 0; - Word32 Cproto_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + Word32 Cproto_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cproto_e) Word16 Cproto_e; - Word32 *proto_matrix_ptr_fx; - Word32 *Cx_state_fx; + Word32 *proto_matrix_ptr_fx; // Q(31 - proto_matrix_ptr_e) + Word32 *Cx_state_fx; // Q(31 - Cx_state_e) Word32 *Cx_old_state_fx; - Word32 Cy_state_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + Word32 Cy_state_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cy_state_e) Word32 *Cy_old_state_fx; Word16 Cx_state_e; Word16 Cy_state_e; - Word32 mixing_matrix_res_local_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + Word32 mixing_matrix_res_local_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mixing_matrix_res_local_e) Word16 mixing_matrix_res_local_e; Word32 L_tmp; Word16 tmp_e, tmp; Word16 proto_matrix_e = hParamMC->h_output_synthesis_params.proto_matrix_e; move16(); - Word32 proto_matrix_noLFE_fx[PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS]; + Word32 proto_matrix_noLFE_fx[PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS]; // Q(31 - proto_matrix_noLFE_e) - Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mat_mult_buffer1_e) - Word32 Cproto_diag_fx[MAX_CICP_CHANNELS]; + Word32 Cproto_diag_fx[MAX_CICP_CHANNELS]; // Q(31 - Cproto_diag_e) Word16 mat_mult_buffer1_e, proto_matrix_ptr_e, Cproto_diag_e; Word32 *ptrMM_fx; @@ -5392,6 +5392,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( set_zero_fx( Cproto_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); set_zero_fx( mat_mult_buffer1_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); set_zero_fx( proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS ); + set_zero_fx( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS ); #ifdef MSAN_FIX set_zero_fx( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); #endif @@ -5418,7 +5419,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( lfe_indices[lfe_idx1 + 1] = hSynthesisOutputSetup->index_lfe[lfe_idx1]; move16(); } - lfe_indices[add( hSynthesisOutputSetup->num_lfe, 1 )] = nY_cov; + lfe_indices[hSynthesisOutputSetup->num_lfe + 1] = nY_cov; move16(); proto_matrix_ptr_fx = &proto_matrix_noLFE_fx[0]; proto_matrix_ptr_in_fx = &hParamMC->h_output_synthesis_params.proto_matrix_fx[0]; @@ -5429,9 +5430,9 @@ static void ivas_param_mc_get_mixing_matrices_fx( FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ ) { - FOR( lfe_idx1 = 0; lfe_idx1 < add( hSynthesisOutputSetup->num_lfe, 1 ); lfe_idx1++ ) + FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ ) { - FOR( ch_idx2 = add( lfe_indices[lfe_idx1], 1 ); ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ ) + FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ ) { *( proto_matrix_ptr_fx++ ) = *( proto_matrix_ptr_in_fx++ ); move32(); @@ -5489,9 +5490,9 @@ static void ivas_param_mc_get_mixing_matrices_fx( FOR( ch_idx1 = 0; ch_idx1 < nY_intern; ch_idx1++ ) { - IF( BASOP_Util_Cmp_Mant32Exp( Cproto_fx[L_add( ch_idx1, L_mult0( ch_idx1, nY_intern ) )], Cproto_e, 0, 0 ) < 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( Cproto_fx[ch_idx1 + ( ch_idx1 * nY_intern )], Cproto_e, 0, 0 ) < 0 ) { - Cproto_fx[L_add( ch_idx1, L_mult0( ch_idx1, nY_intern ) )] = 0; + Cproto_fx[ch_idx1 + ( ch_idx1 * nY_intern )] = 0; move32(); } } @@ -5539,7 +5540,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = Cy_state_e; move16(); - FOR( i = 0; i < imult1616( nX, nX ); i++ ) + FOR( i = 0; i < nX * nX; i++ ) { if ( Cx_old_state_fx[i] != 0 ) { @@ -5555,7 +5556,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( new_e = 0; move16(); - FOR( i = 0; i < imult1616( nY_cov, nY_cov ); i++ ) + FOR( i = 0; i < nY_cov * nY_cov; i++ ) { if ( Cy_old_state_fx[i] != 0 ) { @@ -5608,19 +5609,35 @@ static void ivas_param_mc_get_mixing_matrices_fx( /* Compute mixing matrix FOR residual */ computeMixingMatricesResidual_fx( nY_band, Cproto_diag_fx, Cproto_diag_e, Cr_fx, Cr_e, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_res_local_fx, &mixing_matrix_res_local_e ); + IF( NE_16( mixing_matrix_res_local_e, mixing_matrix_local_e ) ) + { + tmp = getScaleFactor32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS ); + scale_sig32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS, tmp ); + mixing_matrix_local_e = sub( mixing_matrix_local_e, tmp ); + + tmp = getScaleFactor32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); + scale_sig32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS, tmp ); + mixing_matrix_res_local_e = sub( mixing_matrix_res_local_e, tmp ); + + scale_sig32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS, sub( mixing_matrix_local_e, s_max( mixing_matrix_local_e, mixing_matrix_res_local_e ) ) ); + scale_sig32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS, sub( mixing_matrix_res_local_e, s_max( mixing_matrix_local_e, mixing_matrix_res_local_e ) ) ); + + mixing_matrix_res_local_e = mixing_matrix_local_e = s_max( mixing_matrix_local_e, mixing_matrix_res_local_e ); + move16(); + } IF( remove_lfe ) { set_zero_fx( mixing_matrix_res_fx[param_band_idx], imult1616( nY_cov, nY_cov ) ); ptrMM_fx = mixing_matrix_res_local_fx; ptrMM_out_fx = mixing_matrix_res_fx[param_band_idx]; - FOR( lfe_idx1 = 0; lfe_idx1 < add( hSynthesisOutputSetup->num_lfe, 1 ); lfe_idx1++ ) + FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ ) { - FOR( ch_idx1 = add( lfe_indices[lfe_idx1], 1 ); ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ ) + FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ ) { - FOR( lfe_idx2 = 0; lfe_idx2 < add( hSynthesisOutputSetup->num_lfe, 1 ); lfe_idx2++ ) + FOR( lfe_idx2 = 0; lfe_idx2 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx2++ ) { - FOR( ch_idx2 = add( lfe_indices[lfe_idx2], 1 ); ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ ) + FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ ) { *( ptrMM_out_fx++ ) = *( ptrMM_fx++ ); move32(); @@ -5689,9 +5706,9 @@ static void ivas_param_mc_get_mixing_matrices_fx( ptrMM_out_fx = mixing_matrix_fx[param_band_idx]; FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ ) { - FOR( lfe_idx1 = 0; lfe_idx1 < add( hSynthesisOutputSetup->num_lfe, 1 ); lfe_idx1++ ) + FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ ) { - FOR( ch_idx2 = add( lfe_indices[lfe_idx1], 1 ); ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ ) + FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ ) { *( ptrMM_out_fx++ ) = *( ptrMM_fx++ ); move32(); @@ -6286,7 +6303,7 @@ static void param_mc_update_mixing_matrices_fx( brange[0] = hParamMC->band_grouping[param_band_idx]; move16(); - brange[1] = hParamMC->band_grouping[add( param_band_idx, 1 )]; + brange[1] = hParamMC->band_grouping[param_band_idx + 1]; move16(); Copy32( mixing_matrix[param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], imult1616( nX, nY ) ); @@ -6503,15 +6520,15 @@ static void ivas_param_mc_dequantize_cov_fx( Word16 Cy_buf_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS]; Word16 Cp_buf_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS]; - Word32 Nrqq_fx[MAX_OUTPUT_CHANNELS]; + Word32 Nrqq_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - Nrqq_e) Word16 Nrqq_e[MAX_OUTPUT_CHANNELS]; - Word32 a_fx[MAX_OUTPUT_CHANNELS]; + Word32 a_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - a_e) Word16 a_e[MAX_OUTPUT_CHANNELS]; Word16 k; Word16 l; - Word32 *Cyp_fx; + Word32 *Cyp_fx; // Q(31 - Cyp_e) Word16 *Cyp_e; - Word32 ap_fx; + Word32 ap_fx; // Q(31 - ap_e) Word16 ap_e; #ifndef FIX_901_PARAMMC_DEAD_CODE Word16 param_frame_idx; @@ -6536,7 +6553,7 @@ static void ivas_param_mc_dequantize_cov_fx( FOR( k = 0; k < nY_int; k++ ) { - Word32 ref_ener_fx = 0; + Word32 ref_ener_fx = 0; // Q(31 - ref_ener_e) move32(); Word16 ref_ener_e = 0; move16(); @@ -6547,7 +6564,7 @@ static void ivas_param_mc_dequantize_cov_fx( { ref_channel_idx = h_ild_mapping->ref_channel_idx[k][ref_channel_cnt]; move16(); - ref_ener_fx = BASOP_Util_Add_Mant32Exp( Cx_state_fx[add( ref_channel_idx, imult1616( ref_channel_idx, nX ) )], Cx_state_e, ref_ener_fx, ref_ener_e, &ref_ener_e ); + ref_ener_fx = BASOP_Util_Add_Mant32Exp( Cx_state_fx[ref_channel_idx + ( ref_channel_idx * nX )], Cx_state_e, ref_ener_fx, ref_ener_e, &ref_ener_e ); move32(); } @@ -6566,12 +6583,12 @@ static void ivas_param_mc_dequantize_cov_fx( FOR( k = 0; k < nY_int; k++ ) { // a_fx[k] = 1.f / ( sqrtf( Cproto_fx[k + nY_int * k] ) + EPSILON ); - tmp_e = Cp_buf_e[add( k, imult1616( nY_int, k ) )]; + tmp_e = Cp_buf_e[k + ( nY_int * k )]; move16(); - IF( Cproto_fx[add( k, imult1616( nY_int, k ) )] != 0 ) + IF( Cproto_fx[k + ( nY_int * k )] != 0 ) { - L_tmp = ISqrt32( Cproto_fx[add( k, imult1616( nY_int, k ) )], &tmp_e ); + L_tmp = ISqrt32( Cproto_fx[k + ( nY_int * k )], &tmp_e ); } ELSE { @@ -6587,9 +6604,9 @@ static void ivas_param_mc_dequantize_cov_fx( FOR( l = 0; l < nY_int; l++ ) { - Cy_state_int_fx[add( imult1616( k, nY_int ), l )] = Mpy_32_32( Cproto_fx[add( imult1616( k, nY_int ), l )], a_fx[k] ); + Cy_state_int_fx[( k * nY_int ) + l] = Mpy_32_32( Cproto_fx[( k * nY_int ) + l], a_fx[k] ); move32(); - Cy_state_int_e[add( imult1616( k, nY_int ), l )] = add( Cp_buf_e[add( imult1616( k, nY_int ), l )], a_e[k] ); + Cy_state_int_e[( k * nY_int ) + l] = add( Cp_buf_e[( k * nY_int ) + l], a_e[k] ); move16(); } } @@ -6630,13 +6647,13 @@ static void ivas_param_mc_dequantize_cov_fx( Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping[param_frame_idx][k][1] + nY_int * hParamMC->hMetadataPMC->icc_mapping[param_frame_idx][k][0]] = tmp; move16(); #else - Cy_state_int_fx[add( hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0], imult1616( nY_int, hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] ) )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp ); + Cy_state_int_fx[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp ); move32(); - Cy_state_int_e[add( hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0], imult1616( nY_int, hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] ) )] = tmp; + Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] )] = tmp; move16(); - Cy_state_int_fx[add( hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1], imult1616( nY_int, hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] ) )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp ); + Cy_state_int_fx[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp ); move32(); - Cy_state_int_e[add( hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1], imult1616( nY_int, hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] ) )] = tmp; + Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] )] = tmp; move16(); #endif } @@ -6646,13 +6663,13 @@ static void ivas_param_mc_dequantize_cov_fx( { FOR( k = 0; k < nY_int; k++ ) { - Cy_state_int_fx[add( k, imult1616( 3, nY_int ) )] = ONE_IN_Q31; + Cy_state_int_fx[k + ( 3 * nY_int )] = ONE_IN_Q31; move32(); - Cy_state_int_e[add( k, imult1616( 3, nY_int ) )] = 0; + Cy_state_int_e[k + ( 3 * nY_int )] = 0; move16(); - Cy_state_int_fx[add( 3, imult1616( k, nY_int ) )] = ONE_IN_Q31; + Cy_state_int_fx[3 + ( k * nY_int )] = ONE_IN_Q31; move32(); - Cy_state_int_e[add( 3, imult1616( k, nY_int ) )] = 0; + Cy_state_int_e[3 + ( k * nY_int )] = 0; move16(); } Nrqq_fx[3] = 0; @@ -6672,9 +6689,9 @@ static void ivas_param_mc_dequantize_cov_fx( /* v_multc( Cy_state_int_fx + k * nY_int, a_fx[k], Cy_state_int_fx + k * nY_int, nY_int ) */ FOR( l = 0; l < nY_int; l++ ) { - Cy_state_int_fx[add( imult1616( k, nY_int ), l )] = Mpy_32_32( Cy_state_int_fx[add( imult1616( k, nY_int ), l )], a_fx[k] ); + Cy_state_int_fx[( k * nY_int ) + l] = Mpy_32_32( Cy_state_int_fx[( k * nY_int ) + l], a_fx[k] ); move32(); - Cy_state_int_e[add( imult1616( k, nY_int ), l )] = add( Cy_state_int_e[add( imult1616( k, nY_int ), l )], a_e[k] ); + Cy_state_int_e[( k * nY_int ) + l] = add( Cy_state_int_e[( k * nY_int ) + l], a_e[k] ); move16(); } } @@ -6703,9 +6720,9 @@ static void ivas_param_mc_dequantize_cov_fx( IF( EQ_32( synth_conf, PARAM_MC_SYNTH_LS_CONV_COV ) ) { /* Cy = dmx*Cy*dmx' */ - Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mat_mult_buffer1_e) Word16 mat_mult_buffer1_e[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; - Word32 target_ch_ener_fx[MAX_CICP_CHANNELS]; + Word32 target_ch_ener_fx[MAX_CICP_CHANNELS]; // Q(31 - target_ch_ener_e) Word16 target_ch_ener_e[MAX_CICP_CHANNELS]; Word32 dmx_ch_ener_fx[MAX_CICP_CHANNELS]; @@ -6728,8 +6745,8 @@ static void ivas_param_mc_dequantize_cov_fx( { FOR( l = 0; l < nY_int; l++ ) { - L_tmp = Mpy_32_32( hParamMC->ls_conv_dmx_matrix_fx[add( k, imult1616( l, nY_cov ) )], Nrqq_fx[l] ); - tmp_e = add( ls_conv_dmx_matrix_e[add( k, imult1616( l, nY_cov ) )], Nrqq_e[l] ); + L_tmp = Mpy_32_32( hParamMC->ls_conv_dmx_matrix_fx[k + ( l * nY_cov )], Nrqq_fx[l] ); + tmp_e = add( ls_conv_dmx_matrix_e[k + ( l + nY_cov )], Nrqq_e[l] ); L_tmp = BASOP_Util_Add_Mant32Exp( target_ch_ener_fx[k], target_ch_ener_e[k], L_tmp, tmp_e, &tmp_e ); target_ch_ener_fx[k] = L_tmp; move32(); @@ -6737,12 +6754,12 @@ static void ivas_param_mc_dequantize_cov_fx( move16(); } - dmx_ch_ener_fx[k] = Cy_state_fx[add( k, imult1616( nY_cov, k ) )]; + dmx_ch_ener_fx[k] = Cy_state_fx[k + ( nY_cov * k )]; move32(); IF( dmx_ch_ener_fx[k] < 0 ) { - Cy_state_fx[add( k, imult1616( nY_cov, k ) )] = L_negate( Cy_state_fx[add( k, imult1616( nY_cov, k ) )] ); + Cy_state_fx[k + ( nY_cov * k )] = L_negate( Cy_state_fx[k + ( nY_cov * k )] ); move32(); dmx_ch_ener_fx[k] = L_negate( dmx_ch_ener_fx[k] ); move32(); @@ -6757,7 +6774,7 @@ static void ivas_param_mc_dequantize_cov_fx( } ELSE { - BASOP_Util_Divide_MantExp( extract_h( target_ch_ener_fx[k] ), target_ch_ener_e[k], extract_h( dmx_ch_ener_fx[k] ), Cy_buf_e[add( k, imult1616( nY_cov, k ) )], &tmp, &tmp_e ); + BASOP_Util_Divide_MantExp( extract_h( target_ch_ener_fx[k] ), target_ch_ener_e[k], extract_h( dmx_ch_ener_fx[k] ), Cy_buf_e[k + ( nY_cov * k )], &tmp, &tmp_e ); tmp = Sqrt16( tmp, &tmp_e ); target_ch_ener_fx[k] = L_deposit_h( tmp ); move32(); @@ -6767,9 +6784,9 @@ static void ivas_param_mc_dequantize_cov_fx( FOR( l = 0; l < nY_cov; l++ ) { - Cy_state_fx[add( imult1616( k, nY_cov ), l )] = Mpy_32_32( target_ch_ener_fx[k], Cy_state_fx[add( imult1616( k, nY_cov ), l )] ); + Cy_state_fx[( k * nY_cov ) + l] = Mpy_32_32( target_ch_ener_fx[k], Cy_state_fx[( k * nY_cov ) + l] ); move32(); - Cy_buf_e[add( imult1616( k, nY_cov ), l )] = add( target_ch_ener_e[k], Cy_buf_e[add( imult1616( k, nY_cov ), l )] ); + Cy_buf_e[( k * nY_cov ) + l] = add( target_ch_ener_e[k], Cy_buf_e[( k * nY_cov ) + l] ); move16(); } @@ -6799,13 +6816,13 @@ static void ivas_param_mc_dequantize_cov_fx( /*normalize output matrix to a common exponent*/ tmp = 0; - FOR( k = 0; k < imult1616( nY_int, nY_int ); k++ ) + FOR( k = 0; k < nY_int * nY_int; k++ ) { Cy_state_fx[k] = BASOP_Util_Add_Mant32Exp( Cy_state_fx[k], Cy_buf_e[k], 0, 0, &Cy_buf_e[k] ); move32(); tmp = s_max( tmp, Cy_buf_e[k] ); } - FOR( k = 0; k < imult1616( nY_int, nY_int ); k++ ) + FOR( k = 0; k < nY_int * nY_int; k++ ) { L_tmp = L_shr( Cy_state_fx[k], sub( tmp, Cy_buf_e[k] ) ); Cy_state_fx[k] = L_tmp; @@ -7205,7 +7222,7 @@ static void ivas_param_mc_bs_decode_parameter_values_fx( const Word16 num_lfe_bands, /* i : number of parameter bands with coded LFE */ const Word16 band_step, /* i : parameter band step */ const Word16 num_param_bands, /* i : number of parameter bands to decode */ - Word16 *value_buffer /* o : output buffer for decoded parameter values */ + Word16 *value_buffer /* o : output buffer for decoded parameter values hParamCodingInfo -> Q-quant*/ ) { Word16 range_coding; @@ -7272,7 +7289,7 @@ static void ivas_param_mc_bs_decode_parameter_values_fx( /* dequantize */ FOR( j = 0; j < sz_seq; j++ ) { - dequant_seq_fx[j] = hParamCodingInfo->quantizer_fx[idx[j]]; + dequant_seq_fx[j] = hParamCodingInfo->quantizer_fx[idx[j]]; // hParamCodingInfo -> Q-quant move16(); } } @@ -7290,7 +7307,7 @@ static void ivas_param_mc_bs_decode_parameter_values_fx( { FOR( i = 0; i < num_param_bands; ++i ) { - dequant_ordered_fx[add( j, imult1616( i, map_size ) )] = dequant_seq_fx[k]; + dequant_ordered_fx[j + ( i * map_size )] = dequant_seq_fx[k]; // hParamCodingInfo -> Q-quant move16(); k = add( k, 1 ); } @@ -7300,7 +7317,7 @@ static void ivas_param_mc_bs_decode_parameter_values_fx( { FOR( j = 0; j < n_lfe_idx; j++ ) { - dequant_ordered_fx[add( add( sub( map_size, n_lfe_idx ), j ), imult1616( i, map_size ) )] = dequant_seq_fx[k]; + dequant_ordered_fx[map_size - n_lfe_idx + j + i * map_size] = dequant_seq_fx[k]; // hParamCodingInfo -> Q-quant move16(); k = add( k, 1 ); } @@ -7314,7 +7331,7 @@ static void ivas_param_mc_bs_decode_parameter_values_fx( test(); IF( hMetadataPMC->bAttackPresent || EQ_16( hMetadataPMC->param_frame_idx, hMetadataPMC->coding_band_mapping[k] ) ) { - Copy( dequant_ordered_fx + imult1616( j, map_size ), value_buffer + imult1616( k, map_size ), map_size ); + Copy( dequant_ordered_fx + imult1616( j, map_size ), value_buffer + imult1616( k, map_size ), map_size ); // hParamCodingInfo -> Q-quant j++; } IF( hMetadataPMC->bAttackPresent && k + 1 < hMetadataPMC->nbands_coded ) diff --git a/lib_dec/ivas_mc_paramupmix_dec.c b/lib_dec/ivas_mc_paramupmix_dec.c index 7cbac3f8130a0958e69e1681ae06b3c106a9e945..b0f8d25fec4fb9099794d9b9df3aef6afe4253c0 100644 --- a/lib_dec/ivas_mc_paramupmix_dec.c +++ b/lib_dec/ivas_mc_paramupmix_dec.c @@ -118,8 +118,8 @@ void ivas_mc_paramupmix_dec_read_BS( { FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { - hMCParamUpmix->alphas_fx[i][k] = hMCParamUpmix->alpha_prev_fx[i][k]; - hMCParamUpmix->betas_fx[i][k] = hMCParamUpmix->beta_prev_fx[i][k]; + hMCParamUpmix->alphas_fx[i][k] = hMCParamUpmix->alpha_prev_fx[i][k]; // Q28 + hMCParamUpmix->betas_fx[i][k] = hMCParamUpmix->beta_prev_fx[i][k]; // Q28 move32(); move32(); } @@ -137,9 +137,9 @@ void ivas_mc_paramupmix_dec_read_BS( nb_bits_read_orig = 0; move16(); last_bit_pos = sub( last_bit_pos, nb_bits_read_orig ); /* reverse the bitstream for easier reading of indices */ - FOR( i = 0; i < s_min( MAX_BITS_METADATA, last_bit_pos ); i++ ) + FOR( i = 0; i < min( MAX_BITS_METADATA, last_bit_pos ); i++ ) { - bstr_meta[i] = st_ivas->bit_stream[sub( last_bit_pos, i )]; + bstr_meta[i] = st_ivas->bit_stream[last_bit_pos - i]; move16(); } st0->bit_stream = bstr_meta; @@ -219,8 +219,8 @@ void ivas_mc_paramupmix_dec_render( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ - Word32 *input_fx[], /* i : core-coder transport channels */ - Word32 *output_fx[] /* i/o: synthesized core-coder transport channels */ + Word32 *input_fx[], /* i : core-coder transport channels Qx*/ + Word32 *output_fx[] /* i/o: synthesized core-coder transport channels Qx*/ ) { Word16 slots_to_render, first_sf, last_sf, subframe_idx; @@ -274,7 +274,7 @@ void ivas_mc_paramupmix_dec_render( ivas_mc_paramupmix_dec_sf( st_ivas, output_local_fx ); - FOR( ch = 0; ch < s_min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ) ); ch++ ) + FOR( ch = 0; ch < min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ) ); ch++ ) { output_local_fx[ch] += n_samples_sf; } @@ -495,7 +495,7 @@ static void paramupmix_td_decorr_process_jbm_fx( { Word16 j, k; Word16 offset; - Word32 in_duck_gain[L_FRAME48k], out_duck_gain[L_FRAME48k]; + Word32 in_duck_gain[L_FRAME48k], out_duck_gain[L_FRAME48k]; // Q30 offset = idiv1616( output_frame, 10 ); @@ -515,7 +515,7 @@ static void paramupmix_td_decorr_process_jbm_fx( pp_out_pcm[k][j] = Mpy_32_32( pp_out_pcm[k][j], in_duck_gain[j] ); move16(); } - q_format[k] = sub( q_format[k], Q1 ); + q_format[k] = sub( q_format[k], Q1 ); // q_format-- move16(); } @@ -530,7 +530,7 @@ static void paramupmix_td_decorr_process_jbm_fx( pp_out_pcm[k][j] = Mpy_32_32( pp_out_pcm[k][j], out_duck_gain[j] ); move32(); } - q_format[k] = sub( q_format[k], Q1 ); + q_format[k] = sub( q_format[k], Q1 ); // q_format-- move16(); } } @@ -569,8 +569,8 @@ static void ivas_param_upmix_dec_decorr_subframes( FOR( ch = 0; ch < nchan_internal; ch++ ) { - pPcm_tmp_fx[ch] = st_ivas->hTcBuffer->tc_fx[add( ch, 8 )]; - p_tc_fx[ch] = st_ivas->hTcBuffer->tc_fx[add( ch, 4 )]; + pPcm_tmp_fx[ch] = st_ivas->hTcBuffer->tc_fx[ch + 8]; // Q11 + p_tc_fx[ch] = st_ivas->hTcBuffer->tc_fx[ch + 4]; // Q11 } WHILE( nSamplesLeftForTD ) @@ -590,7 +590,7 @@ static void ivas_param_upmix_dec_decorr_subframes( FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { - Scale_sig32( pPcm_tmp_fx[i], nSamplesToDecorr, sub( Q11, q_format[i] ) ); + Scale_sig32( pPcm_tmp_fx[i], nSamplesToDecorr, sub( Q11, q_format[i] ) ); // Setting Q to changed q in q_format } } FOR( ch = 0; ch < nchan_internal; ch++ ) @@ -613,11 +613,13 @@ static void ivas_param_upmix_dec_decorr_subframes( static void ps_pred_process_sf( MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, DECODER_TC_BUFFER_HANDLE hTcBuffer, - Word32 qmf_mod_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */ - Word32 qmf_mod_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], - Word32 qmf_side_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */ - Word32 qmf_side_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], - Word16 *param_interpol_fx, + Word32 qmf_mod_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + /* in/out */ // Q6 + Word32 qmf_mod_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], // Q6 + Word32 qmf_side_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + /* in/out */ // Q6 + Word32 qmf_side_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], // Q6 + Word16 *param_interpol_fx, // Q15 const Word16 ch, const Word16 slots_rendered ) { @@ -626,69 +628,69 @@ static void ps_pred_process_sf( Word32 alpha_smp_fx, beta_smp_fx; Word32 *alpha1_fx, *alpha2_fx; Word32 *beta1_fx, *beta2_fx; - Word32 *alpha_prev_fx = hMCParamUpmix->alpha_prev_fx[ch]; - Word32 *beta_prev_fx = hMCParamUpmix->beta_prev_fx[ch]; - Word32 *alpha_sf_fx = hMCParamUpmix->alpha_sf_fx[ch]; - Word32 *beta_sf_fx = hMCParamUpmix->beta_sf_fx[ch]; + Word32 *alpha_prev_fx = hMCParamUpmix->alpha_prev_fx[ch]; // Q28 + Word32 *beta_prev_fx = hMCParamUpmix->beta_prev_fx[ch]; // Q28 + Word32 *alpha_sf_fx = hMCParamUpmix->alpha_sf_fx[ch]; // Q28 + Word32 *beta_sf_fx = hMCParamUpmix->beta_sf_fx[ch]; // Q28 Word32 dalpha_fx, dbeta_fx; Word16 ifac_fx; Word32 alpha_start_fx[IVAS_MAX_NUM_BANDS], beta_start_fx[IVAS_MAX_NUM_BANDS]; Word32 res_a, res_b; - Copy32( alpha_sf_fx, alpha_start_fx, IVAS_MAX_NUM_BANDS ); - Copy32( beta_sf_fx, beta_start_fx, IVAS_MAX_NUM_BANDS ); + Copy32( alpha_sf_fx, alpha_start_fx, IVAS_MAX_NUM_BANDS ); // Q28 + Copy32( beta_sf_fx, beta_start_fx, IVAS_MAX_NUM_BANDS ); // Q28 FOR( iqmf = 0; iqmf < CLDFB_NO_CHANNELS_MAX; iqmf++ ) { ipar = qmf_to_par_band[iqmf]; move16(); - alpha1_fx = alpha_prev_fx; + alpha1_fx = alpha_prev_fx; // Q28 move16(); - beta1_fx = beta_prev_fx; + beta1_fx = beta_prev_fx; // Q28 move16(); ismp = 0; move16(); alpha2_fx = hMCParamUpmix->alphas_fx[ch]; beta2_fx = hMCParamUpmix->betas_fx[ch]; - alpha_smp_fx = alpha_start_fx[ipar]; + alpha_smp_fx = alpha_start_fx[ipar]; // Q28 move32(); - beta_smp_fx = beta_start_fx[ipar]; + beta_smp_fx = beta_start_fx[ipar]; // Q28 move32(); FOR( iismp = 0; iismp < hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered]; iismp++ ) { IF( ( slots_rendered == 0 ) && ( iismp == 0 ) ) { - ifac_fx = param_interpol_fx[iismp]; + ifac_fx = param_interpol_fx[iismp]; // Q15 move16(); } ELSE { - ifac_fx = sub( param_interpol_fx[iismp], param_interpol_fx[sub( iismp, 1 )] ); + ifac_fx = sub( param_interpol_fx[iismp], param_interpol_fx[iismp - 1] ); // Q15 } - dalpha_fx = Mpy_32_16_1( L_sub( alpha2_fx[ipar], alpha1_fx[ipar] ), ifac_fx ); + dalpha_fx = Mpy_32_16_1( L_sub( alpha2_fx[ipar], alpha1_fx[ipar] ), ifac_fx ); // Q28 dbeta_fx = Mpy_32_16_1( L_sub( beta2_fx[ipar], beta1_fx[ipar] ), ifac_fx ); alpha_smp_fx = L_add( alpha_smp_fx, dalpha_fx ); beta_smp_fx = L_add( dbeta_fx, beta_smp_fx ); - vmre_fx = qmf_mod_re_fx[ismp][iqmf]; + vmre_fx = qmf_mod_re_fx[ismp][iqmf]; // Q6 move32(); - vmim_fx = qmf_mod_im_fx[ismp][iqmf]; + vmim_fx = qmf_mod_im_fx[ismp][iqmf]; // Q6 move32(); - vsre_fx = qmf_side_re_fx[ismp][iqmf]; + vsre_fx = qmf_side_re_fx[ismp][iqmf]; // Q6 move32(); - vsim_fx = qmf_side_im_fx[ismp][iqmf]; + vsim_fx = qmf_side_im_fx[ismp][iqmf]; // Q6 move32(); - res_a = L_shl_sat( Mpy_32_32( alpha_smp_fx, vmre_fx ), Q31 - Q28 ); - res_b = L_shl_sat( Mpy_32_32( beta_smp_fx, vsre_fx ), Q31 - Q28 ); - qmf_side_re_fx[ismp][iqmf] = L_add_sat( res_a, res_b ); + res_a = L_shl_sat( Mpy_32_32( alpha_smp_fx, vmre_fx ), Q31 - Q28 ); // Q6 + res_b = L_shl_sat( Mpy_32_32( beta_smp_fx, vsre_fx ), Q31 - Q28 ); // Q6 + qmf_side_re_fx[ismp][iqmf] = L_add_sat( res_a, res_b ); // Q6 move32(); - res_a = L_shl_sat( Mpy_32_32( alpha_smp_fx, vmim_fx ), Q31 - Q28 ); - res_b = L_shl_sat( Mpy_32_32( beta_smp_fx, vsim_fx ), Q31 - Q28 ); + res_a = L_shl_sat( Mpy_32_32( alpha_smp_fx, vmim_fx ), Q31 - Q28 ); // Q6 + res_b = L_shl_sat( Mpy_32_32( beta_smp_fx, vsim_fx ), Q31 - Q28 ); // Q6 qmf_side_im_fx[ismp][iqmf] = L_add_sat( res_a, res_b ); move32(); @@ -706,14 +708,14 @@ static void ps_pred_process_sf( static void ivas_mc_paramupmix_dec_sf( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - Word32 *output_fx[MAX_OUTPUT_CHANNELS] /* i/o: synthesized core-coder transport channels */ + Word32 *output_fx[MAX_OUTPUT_CHANNELS] /* i/o: synthesized core-coder transport channels Q11*/ ) { Word16 i, ch, slot_idx, k; Word32 *pPcm_temp_fx[MC_PARAMUPMIX_COMBINATIONS * 2]; /* decorrelated and undecorrelated*/ /*CLDFB*/ - Word32 Cldfb_RealBuffer_fx[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX] = { 0 }; - Word32 Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX] = { 0 }; + Word32 Cldfb_RealBuffer_fx[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX] = { 0 }; // Q6 + Word32 Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX] = { 0 }; // Q6 Word16 noparamupmix_delay, n_samples_rendered; MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix; @@ -734,8 +736,8 @@ static void ivas_mc_paramupmix_dec_sf( FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { - pPcm_temp_fx[2 * i] = output_fx[i + 4]; /* un-decorrelated */ - pPcm_temp_fx[2 * i + 1] = output_fx[i + 8]; /* decorrelated */ + pPcm_temp_fx[2 * i] = output_fx[i + 4]; /* un-decorrelated Q11*/ + pPcm_temp_fx[2 * i + 1] = output_fx[i + 8]; /* decorrelated Q11*/ } /* CLDFB Analysis*/ @@ -746,7 +748,7 @@ static void ivas_mc_paramupmix_dec_sf( { Word16 q_cldfb = 11; move16(); - cldfbAnalysis_ts_fx_fixed_q( &( pPcm_temp_fx[ch][L_mult0( hMCParamUpmix->num_freq_bands, slot_idx )] ), Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][slot_idx], hMCParamUpmix->num_freq_bands, st_ivas->cldfbAnaDec[ch], &q_cldfb ); + cldfbAnalysis_ts_fx_fixed_q( &( pPcm_temp_fx[ch][hMCParamUpmix->num_freq_bands * slot_idx] ), Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][slot_idx], hMCParamUpmix->num_freq_bands, st_ivas->cldfbAnaDec[ch], &q_cldfb ); } } @@ -754,10 +756,10 @@ static void ivas_mc_paramupmix_dec_sf( { ps_pred_process_sf( hMCParamUpmix, st_ivas->hTcBuffer, - Cldfb_RealBuffer_fx[shl( ch, 1 )], /* in/out */ - Cldfb_ImagBuffer_fx[shl( ch, 1 )], - Cldfb_RealBuffer_fx[add( shl( ch, 1 ), 1 )], /* in/out decorr */ - Cldfb_ImagBuffer_fx[add( shl( ch, 1 ), 1 )], + Cldfb_RealBuffer_fx[2 * ch], /* in/out */ + Cldfb_ImagBuffer_fx[2 * ch], + Cldfb_RealBuffer_fx[2 * ch + 1], /* in/out decorr */ + Cldfb_ImagBuffer_fx[2 * ch + 1], &hMCParamUpmix->param_interpolator_fx[st_ivas->hTcBuffer->slots_rendered], ch, st_ivas->hTcBuffer->slots_rendered ); @@ -767,19 +769,19 @@ static void ivas_mc_paramupmix_dec_sf( { FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ ) { - Word32 qlre_fx = Cldfb_RealBuffer_fx[2 * ch][slot_idx][k]; - Word32 qlim_fx = Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k]; - Word32 qrre_fx = Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k]; - Word32 qrim_fx = Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k]; + Word32 qlre_fx = Cldfb_RealBuffer_fx[2 * ch][slot_idx][k]; // Q6 + Word32 qlim_fx = Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k]; // Q6 + Word32 qrre_fx = Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k]; // Q6 + Word32 qrim_fx = Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k]; // Q6 move32(); move32(); move32(); move32(); - Cldfb_RealBuffer_fx[shl( ch, 1 )][slot_idx][k] = L_add_sat( qlre_fx, qrre_fx ); - Cldfb_ImagBuffer_fx[shl( ch, 1 )][slot_idx][k] = L_add_sat( qlim_fx, qrim_fx ); - Cldfb_RealBuffer_fx[add( shl( ch, 1 ), 1 )][slot_idx][k] = L_sub_sat( qlre_fx, qrre_fx ); - Cldfb_ImagBuffer_fx[add( shl( ch, 1 ), 1 )][slot_idx][k] = L_sub_sat( qlim_fx, qrim_fx ); + Cldfb_RealBuffer_fx[2 * ch][slot_idx][k] = L_add_sat( qlre_fx, qrre_fx ); + Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k] = L_add_sat( qlim_fx, qrim_fx ); + Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub_sat( qlre_fx, qrre_fx ); + Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub_sat( qlim_fx, qrim_fx ); move32(); move32(); move32(); @@ -814,7 +816,7 @@ static void ivas_mc_paramupmix_dec_sf( cldfbAnalysis_ts_fx_fixed_q( &( pPcm_temp_fx[ch][L_mult0( hMCParamUpmix->num_freq_bands, slot_idx )] ), Cldfb_RealBuffer_subfr_fx[idx_in][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in][slot_idx], - maxBand, st_ivas->cldfbAnaDec[add( MC_PARAMUPMIX_COMBINATIONS * 2, idx_in )], &q_cldfb ); + maxBand, st_ivas->cldfbAnaDec[2 * MC_PARAMUPMIX_COMBINATIONS + idx_in], &q_cldfb ); } idx_in = add( idx_in, 1 ); } @@ -826,10 +828,10 @@ static void ivas_mc_paramupmix_dec_sf( { FOR( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ ) { - Copy32( Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX ); - Copy32( Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX ); - Copy32( Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); - Copy32( Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); + Copy32( Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX ); // Q6 + Copy32( Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX ); // Q6 + Copy32( Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); // Q6 + Copy32( Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); // Q6 } idx_in = add( idx_in, 2 ); } @@ -858,8 +860,8 @@ static void ivas_mc_paramupmix_dec_sf( { FOR( Word16 idx2 = 0; idx2 < MAX_PARAM_SPATIAL_SUBFRAMES; idx2++ ) { - Scale_sig32( Cldfb_RealBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( 6, input_q ) ); - Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( 6, input_q ) ); + Scale_sig32( Cldfb_RealBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( 6, input_q ) ); // Q6 + Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( 6, input_q ) ); // Q6 } } /* Implement CLDFB synthesis */ @@ -870,20 +872,20 @@ static void ivas_mc_paramupmix_dec_sf( FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ ) { - RealBuffer_fx[slot_idx] = Cldfb_RealBuffer_Binaural_fx[ch][slot_idx]; - ImagBuffer_fx[slot_idx] = Cldfb_ImagBuffer_Binaural_fx[ch][slot_idx]; + RealBuffer_fx[slot_idx] = Cldfb_RealBuffer_Binaural_fx[ch][slot_idx]; // Q6 + ImagBuffer_fx[slot_idx] = Cldfb_ImagBuffer_Binaural_fx[ch][slot_idx]; // Q6 } - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q5 - Q11 ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q5 - Q11 ); // Q11 -> Q5 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5; move16(); - cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_fx[ch][0] ), maxBand * st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], st_ivas->cldfbSynDec[ch] ); - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q11 - Q5 ); + cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_fx[ch][0] ), L_mult0( maxBand, st_ivas->hTcBuffer->subframe_nbslots[subframeIdx] ), st_ivas->cldfbSynDec[ch] ); // output_fx returned in Q5 + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q11 - Q5 ); // Q5 -> Q11 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; move16(); } FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - Scale_sig32( output_fx[ch], imult1616( maxBand, st_ivas->hTcBuffer->subframe_nbslots[subframeIdx] ), 6 ); + Scale_sig32( output_fx[ch], imult1616( maxBand, st_ivas->hTcBuffer->subframe_nbslots[subframeIdx] ), 6 ); // Q5 -> Q11 } } ELSE @@ -901,27 +903,27 @@ static void ivas_mc_paramupmix_dec_sf( /* CLDFB synthesis */ FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ ) { - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q5, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q5, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); // Q11 -> Q5 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5; move16(); FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) { Word32 *ptr_im_fx[1], *ptr_re_fx[1]; - ptr_re_fx[0] = Cldfb_RealBuffer_fx[ch][slot_idx]; - ptr_im_fx[0] = Cldfb_ImagBuffer_fx[ch][slot_idx]; + ptr_re_fx[0] = Cldfb_RealBuffer_fx[ch][slot_idx]; // Q6 + ptr_im_fx[0] = Cldfb_ImagBuffer_fx[ch][slot_idx]; // Q6 cldfbSynthesis_ivas_fx( ptr_re_fx, ptr_im_fx, &( pPcm_temp_fx[ch][L_mult0( hMCParamUpmix->num_freq_bands, slot_idx )] ), hMCParamUpmix->num_freq_bands, st_ivas->cldfbSynDec[ch] ); } - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); // Q6 -> Q11 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; move16(); } // Done to keep entire buffer in q11 FOR( ch = 4; ch < 12; ch++ ) { - Scale_sig32( output_fx[ch], imult1616( hMCParamUpmix->num_freq_bands, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] ), 6 ); + Scale_sig32( output_fx[ch], imult1616( hMCParamUpmix->num_freq_bands, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] ), 6 ); // Q11 } /* adjust delay of other channels */ noparamupmix_delay = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_FB_DEC_DELAY_NS ); @@ -931,7 +933,7 @@ static void ivas_mc_paramupmix_dec_sf( FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) { Word32 tmp_buf_fx[L_SUBFRAME5MS_48k]; - Copy32( &output_fx[ch][sub( n_samples_rendered, noparamupmix_delay )], tmp_buf_fx, noparamupmix_delay ); + Copy32( &output_fx[ch][n_samples_rendered - noparamupmix_delay], tmp_buf_fx, noparamupmix_delay ); Copy32( output_fx[ch], &output_fx[ch][noparamupmix_delay], sub( n_samples_rendered, noparamupmix_delay ) ); Copy32( hMCParamUpmix->pcm_delay_fx[ch], output_fx[ch], noparamupmix_delay ); Copy32( tmp_buf_fx, hMCParamUpmix->pcm_delay_fx[ch], noparamupmix_delay ); @@ -945,7 +947,7 @@ static void ivas_mc_paramupmix_dec_sf( Copy32( &output_fx[ch][0], tmp_buf_fx, n_samples_rendered ); Copy32( hMCParamUpmix->pcm_delay_fx[ch], output_fx[ch], n_samples_rendered ); Copy32( &hMCParamUpmix->pcm_delay_fx[ch][n_samples_rendered], &hMCParamUpmix->pcm_delay_fx[ch][0], sub( noparamupmix_delay, n_samples_rendered ) ); - Copy32( tmp_buf_fx, &hMCParamUpmix->pcm_delay_fx[ch][sub( noparamupmix_delay, n_samples_rendered )], n_samples_rendered ); + Copy32( tmp_buf_fx, &hMCParamUpmix->pcm_delay_fx[ch][noparamupmix_delay - n_samples_rendered], n_samples_rendered ); } } } @@ -1040,7 +1042,7 @@ static void huffman_decode( FOR( iv = 1; iv < IVAS_MAX_NUM_BANDS; iv++ ) { - vq[iv] = L_sub( L_add( huff_read( st, huff_node_table ), vq[sub( iv, 1 )] ), offset ); + vq[iv] = L_sub( L_add( huff_read( st, huff_node_table ), vq[iv - 1] ), offset ); move32(); } @@ -1053,11 +1055,11 @@ static void dequant_alpha( Word32 *v ) { Word16 iv; - const ACPL_QUANT_TABLE_FX *quant_table = &ivas_mc_paramupmix_alpha_quant_table_fx; + const ACPL_QUANT_TABLE_FX *quant_table = &ivas_mc_paramupmix_alpha_quant_table_fx; // Q28 FOR( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ ) { - v[iv] = quant_table->data[vq[iv]]; + v[iv] = quant_table->data[vq[iv]]; // Q28 move32(); } @@ -1075,8 +1077,8 @@ static void dequant_beta( FOR( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ ) { - quant_table = &ivas_mc_paramupmix_beta_quant_table_fx[ivas_param_upmx_mx_qmap[aq[iv]]]; - beta[iv] = quant_table->data[bq[iv]]; + quant_table = &ivas_mc_paramupmix_beta_quant_table_fx[ivas_param_upmx_mx_qmap[aq[iv]]]; // Q28 + beta[iv] = quant_table->data[bq[iv]]; // Q28 move32(); } @@ -1095,12 +1097,12 @@ static void get_ec_data( IF( EQ_32( parType, ALPHA ) ) { - dequant_alpha( parQ, ab ); + dequant_alpha( parQ, ab ); // Qab = Q28 Copy32( parQ, alphaQEnv, (Word16) IVAS_MAX_NUM_BANDS ); } ELSE { - dequant_beta( alphaQEnv, parQ, ab ); + dequant_beta( alphaQEnv, parQ, ab ); // Qab = Q28 } return; diff --git a/lib_dec/ivas_mct_core_dec.c b/lib_dec/ivas_mct_core_dec.c index 3e95cbc5353a2100683feb7c9862c997df330088..8816f03ffc3806f26dd71622fab3f41dc94b1a5b 100644 --- a/lib_dec/ivas_mct_core_dec.c +++ b/lib_dec/ivas_mct_core_dec.c @@ -202,7 +202,7 @@ void ivas_mct_side_bits_fx( } /*read MCT data and calculate frame bits per channel */ - FOR( ch = 0; ch < shr( hMCT->nchan_out_woLFE, 1 ); ch++ ) + FOR( ch = 0; ch < hMCT->nchan_out_woLFE / 2; ch++ ) { initMdctStereoDecData_fx( hMCT->hBlockData[ch]->hStereoMdct, st0->igf, st0->hIGFDec->igfData.igfInfo.grid, hCPE[0]->element_brate, st0->bwidth ); } @@ -292,7 +292,7 @@ void ivas_mct_core_dec( MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ CPE_DEC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE decoder structure */ const Word16 nCPE, /* i : number of CPEs */ - Word32 *signal_out_fx[], + Word32 *signal_out_fx[], // q_x Word16 q_x[MCT_MAX_CHANNELS] ) { Word16 i, k, ch, cpe_id, nChannels; diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index f3221106d3f1dc8df20142aa059183ac44ccefe0..ae5057bc1c5604d32776b115b2a740b3c33e9457 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -292,7 +292,7 @@ ivas_error ivas_mct_dec( #else ivas_error ivas_mct_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_fx[], /* o : output synthesis signal */ + Word32 *output_fx[], /* o : output synthesis signal Q11*/ const Word16 output_frame, /* i : output frame length per channel */ const Word16 nb_bits_metadata /* i : number of metadata bits */ ) @@ -306,18 +306,18 @@ ivas_error ivas_mct_dec_fx( Word16 nTnsBitsTCX10[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; Word16 fUseTns[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; STnsData tnsData[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; - Word16 Aq_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; + Word16 Aq_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; // Q12 Word32 output_lfe_ch_fx[L_FRAME48k]; Word16 q_output = 11; Word16 n, k, i; - Word32 *x_fx[CPE_CHANNELS][NB_DIV]; + Word32 *x_fx[CPE_CHANNELS][NB_DIV]; //(Q(31 - x_e) Word16 x_e[MAX_CICP_CHANNELS][NB_DIV]; Word16 x_len[CPE_CHANNELS][NB_DIV]; set16_fx( x_len[0], 0, NB_DIV ); set16_fx( x_len[1], 0, NB_DIV ); Decoder_State **sts; - Word16 synth_fx[CPE_CHANNELS][L_FRAME_PLUS]; + Word16 synth_fx[CPE_CHANNELS][L_FRAME_PLUS]; //(Q_synth) Word32 ivas_total_brate; ivas_error error; Word16 e_sig[CPE_CHANNELS] = { 15, 15 }; @@ -342,7 +342,7 @@ ivas_error ivas_mct_dec_fx( IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && ( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) ) { /* save LFE channel */ - Copy32( output_fx[LFE_CHANNEL], output_lfe_ch_fx, output_frame ); + Copy32( output_fx[LFE_CHANNEL], output_lfe_ch_fx, output_frame ); // Q11 } IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) && ( st_ivas->bfi == 0 ) ) @@ -406,11 +406,11 @@ ivas_error ivas_mct_dec_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { - x_fx[n][0] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )]; + x_fx[n][0] = output_fx[n + ( cpe_id * CPE_CHANNELS )]; // Q11 x_e[n][0] = 20; move16(); move16(); - x_fx[n][1] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )] + ( L_FRAME48k / 2 ); + x_fx[n][1] = output_fx[n + ( cpe_id * CPE_CHANNELS )] + ( L_FRAME48k / 2 ); // Q11 x_e[n][1] = 20; move16(); move16(); @@ -436,7 +436,7 @@ ivas_error ivas_mct_dec_fx( move16(); FOR( k = 0; k < subFrames; ++k ) { - Scale_sig32( x_fx[ch][k], shr( L_FRAME48k, sub( subFrames, 1 ) ), sub( x_e[ch][k], 20 ) ); + Scale_sig32( x_fx[ch][k], shr( L_FRAME48k, sub( subFrames, 1 ) ), sub( x_e[ch][k], 20 ) ); // Scaling back to Q11 } } @@ -453,13 +453,13 @@ ivas_error ivas_mct_dec_fx( // Scaling output buffer to q_x FOR( i = 0; i < hMCT->nchan_out_woLFE; ++i ) { - Scale_sig32( output_fx[i], L_FRAME48k, sub( q_x[i], Q11 ) ); + Scale_sig32( output_fx[i], L_FRAME48k, sub( q_x[i], Q11 ) ); // Q11 -> Q12 } ivas_mct_core_dec( hMCT, st_ivas->hCPE, nCPE, output_fx, q_x ); // Scaling output buffer back to Q11 FOR( i = 0; i < hMCT->nchan_out_woLFE; ++i ) { - Scale_sig32( output_fx[i], L_FRAME48k, sub( Q11, q_x[i] ) ); + Scale_sig32( output_fx[i], L_FRAME48k, sub( Q11, q_x[i] ) ); // Q12 -> Q11 } @@ -485,9 +485,9 @@ ivas_error ivas_mct_dec_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Copy_Scale_sig_16_32( Aq_fx[cpe_id][n], Aq_fx_32[cpe_id][n], 102, Q16 - Q12 ); - x_fx[n][0] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )]; - x_fx[n][1] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )] + ( L_FRAME48k / 2 ); + Copy_Scale_sig_16_32( Aq_fx[cpe_id][n], Aq_fx_32[cpe_id][n], 102, Q16 - Q12 ); // Q16 + x_fx[n][0] = output_fx[n + ( cpe_id * CPE_CHANNELS )]; // Q11 + x_fx[n][1] = output_fx[n + ( cpe_id * CPE_CHANNELS )] + ( L_FRAME48k / 2 ); // Q11 x_e[n][0] = 20; move16(); move16(); @@ -510,10 +510,10 @@ ivas_error ivas_mct_dec_fx( nSubFrames = NB_DIV; } move16(); - Scale_sig32( x_fx[ind][0], shr( L_FRAME48k, sub( nSubFrames, 1 ) ), sub( x_e[ind][0], 20 ) ); + Scale_sig32( x_fx[ind][0], shr( L_FRAME48k, sub( nSubFrames, 1 ) ), sub( x_e[ind][0], 20 ) ); // Q11 IF( EQ_16( nSubFrames, 2 ) ) { - Scale_sig32( x_fx[ind][1], shr( L_FRAME48k, 1 ), sub( x_e[ind][1], 20 ) ); + Scale_sig32( x_fx[ind][1], shr( L_FRAME48k, 1 ), sub( x_e[ind][1], 20 ) ); // Q11 } } } @@ -533,16 +533,16 @@ ivas_error ivas_mct_dec_fx( { set16_fx( x_all_e[i], 0, NB_DIV ); } - Word32 *x_all_fx[MAX_CICP_CHANNELS][NB_DIV]; + Word32 *x_all_fx[MAX_CICP_CHANNELS][NB_DIV]; //(Q(31 - x_all_e) FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - x_all_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][0] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )]; - x_all_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][1] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )] + ( L_FRAME48k / 2 ); - x_all_e[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][1] = 20; + x_all_fx[n + ( cpe_id * CPE_CHANNELS )][0] = output_fx[n + ( cpe_id * CPE_CHANNELS )]; // Q11 + x_all_fx[n + ( cpe_id * CPE_CHANNELS )][1] = output_fx[n + ( cpe_id * CPE_CHANNELS )] + ( L_FRAME48k / 2 ); // Q11 + x_all_e[n + ( cpe_id * CPE_CHANNELS )][1] = 20; move16(); - x_all_e[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][0] = 20; + x_all_e[n + ( cpe_id * CPE_CHANNELS )][0] = 20; move16(); } } @@ -553,8 +553,8 @@ ivas_error ivas_mct_dec_fx( { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Scale_sig32( x_all_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][0], ( L_FRAME48k / 2 ), sub( x_all_e[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][0], 20 ) ); - Scale_sig32( x_all_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][1], ( L_FRAME48k / 2 ), sub( x_all_e[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][1], 20 ) ); + Scale_sig32( x_all_fx[n + ( cpe_id * CPE_CHANNELS )][0], ( L_FRAME48k / 2 ), sub( x_all_e[n + ( cpe_id * CPE_CHANNELS )][0], 20 ) ); // Q11 + Scale_sig32( x_all_fx[n + ( cpe_id * CPE_CHANNELS )][1], ( L_FRAME48k / 2 ), sub( x_all_e[n + ( cpe_id * CPE_CHANNELS )][1], 20 ) ); // Q11 } } } @@ -566,8 +566,8 @@ ivas_error ivas_mct_dec_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { - x_fx[n][0] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )]; - x_fx[n][1] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )] + ( L_FRAME48k / 2 ); + x_fx[n][0] = output_fx[n + ( cpe_id * CPE_CHANNELS )]; // Q11 + x_fx[n][1] = output_fx[n + ( cpe_id * CPE_CHANNELS )] + ( L_FRAME48k / 2 ); // Q11 } Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, add( M, 1 ), sub( 28, norm_s( sub( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0], 1 ) ) ) ); @@ -579,15 +579,15 @@ ivas_error ivas_mct_dec_fx( hdrm = getScaleFactor16( synth_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX ); IF( hdrm != 0 ) { - sh = s_min( sub( e_sig[0], 15 ), hdrm ); + sh = s_min( sub( e_sig[0], 16 ), hdrm ); Scale_sig( synth_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX, sh ); e_sig[0] = sub( e_sig[0], sh ); move16(); } - + hdrm = getScaleFactor16( synth_fx[1], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX ); IF( hdrm != 0 ) { - sh = s_min( sub( e_sig[1], 15 ), hdrm ); + sh = s_min( sub( e_sig[1], 16 ), hdrm ); Scale_sig( synth_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX, sh ); e_sig[1] = sub( e_sig[1], sh ); move16(); @@ -616,11 +616,11 @@ ivas_error ivas_mct_dec_fx( IF( ( st_ivas->sba_dirac_stereo_flag != 0 ) && ( NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) || GE_16( cpe_id, sub( nCPE, 2 ) ) ) ) { - Copy_Scale_sig_16_32( synth_fx[n], synth_fx_32[n], L_FRAME48k, Q11 - 0 ); + Copy_Scale_sig_16_32( synth_fx[n], synth_fx_32[n], L_FRAME48k, sub( Q11, ( sub( 15, e_sig[n] ) ) ) ); // Q11 Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx, output_frame, sub( Q11, hCPE->hCoreCoder[n]->hHQ_core->Q_old_wtda ) ); ivas_post_proc_fx( NULL, hCPE, n, synth_fx_32[n], NULL, output_frame, 1, Q11 ); #ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], output_frame, 0 - Q11 ); + Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], output_frame, sub( sub( 15, e_sig[n] ), Q11 ) ); // Q0 #else Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], L_FRAME48k, 0 - Q11 ); #endif @@ -630,7 +630,7 @@ ivas_error ivas_mct_dec_fx( Word16 output_mem_fx[L_FRAME48k]; IF( hCPE->output_mem_fx[1] != NULL ) { - Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA( sts[n]->output_Fs, 3125000 ), 0 - Q11 ); + Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA( sts[n]->output_Fs, 3125000 ), -Q11 ); } ELSE { @@ -650,25 +650,25 @@ ivas_error ivas_mct_dec_fx( { dirac_stereo_flag = 0; } - IF( NE_32( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx[n], output_fx[add( shl( cpe_id, 1 /* * CPE_CHANNELS*/ ), n )], output_mem_fx, st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, dirac_stereo_flag, -1, hCPE->last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx[n], output_fx[( cpe_id * CPE_CHANNELS ) + n], output_mem_fx, st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, dirac_stereo_flag, -1, hCPE->last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) { return error; } - Copy_Scale_sig_16_32( synth_fx[n], output_fx[add( shl( cpe_id, 1 /* * CPE_CHANNELS*/ ), n )], output_frame, sub( Q11, Q_synth ) ); + Copy_Scale_sig_16_32( synth_fx[n], output_fx[( cpe_id * CPE_CHANNELS ) + n], output_frame, sub( Q11, Q_synth ) ); // Q11 /* Save synthesis for HQ FEC */ Word32 output_fx_[L_FRAME48k]; - Copy32( output_fx[add( shl( cpe_id, 1 /* * CPE_CHANNELS*/ ), n )], output_fx_, L_FRAME48k ); - Scale_sig32( output_fx_, L_FRAME48k, Q16 - Q11 ); - Copy_Scale_sig32_16( sts[n]->prev_synth_buffer32_fx, sts[n]->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); + Copy32( output_fx[( cpe_id * CPE_CHANNELS ) + n], output_fx_, L_FRAME48k ); // Q11 + Scale_sig32( output_fx_, L_FRAME48k, Q16 - Q11 ); // Q11 -> Q16 + Copy_Scale_sig32_16( sts[n]->prev_synth_buffer32_fx, sts[n]->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); // Q11 -> Q0 sts[n]->q_prev_synth_buffer_fx = 0; move16(); save_synthesis_hq_fec_fx( sts[n], output_fx_, output_frame, hCPE ); /* CoreCoder common updates */ - ivas_updt_dec_common_fx( hCPE->hCoreCoder[n], NORMAL_HQ_CORE, -1, output_fx[add( shl( cpe_id, 1 /* * CPE_CHANNELS*/ ), n )], 11 ); + ivas_updt_dec_common_fx( hCPE->hCoreCoder[n], NORMAL_HQ_CORE, -1, output_fx[( cpe_id * CPE_CHANNELS ) + n], 11 ); } /* n_channels loop */ @@ -676,7 +676,7 @@ ivas_error ivas_mct_dec_fx( { IF( hCPE->hCoreCoder[n] ) { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->delay_buf_out_fx, hCPE->hCoreCoder[n]->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP, Q11 ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->delay_buf_out_fx, hCPE->hCoreCoder[n]->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP, Q11 ); // Q0 -> Q11 } } @@ -697,16 +697,16 @@ ivas_error ivas_mct_dec_fx( Word32 tmp[L_FRAME48k]; /*save center channel output*/ - Copy32( output_fx[sub( hMCT->nchan_out_woLFE, 1 )], tmp, output_frame ); + Copy32( output_fx[hMCT->nchan_out_woLFE - 1], tmp, output_frame ); // Q11 - FOR( n = sub( hMCT->nchan_out_woLFE, 1 ); n >= LFE_CHANNEL; n-- ) + FOR( n = hMCT->nchan_out_woLFE - 1; n >= LFE_CHANNEL; n-- ) { - Copy32( output_fx[sub( n, 1 )], output_fx[add( n, 1 )], output_frame ); + Copy32( output_fx[n - 1], output_fx[n + 1], output_frame ); // Q11 } - Copy32( tmp, output_fx[sub( LFE_CHANNEL, 1 )], output_frame ); + Copy32( tmp, output_fx[LFE_CHANNEL - 1], output_frame ); // Q11 /* save LFE channel */ - Copy32( output_lfe_ch_fx, output_fx[LFE_CHANNEL], output_frame ); + Copy32( output_lfe_ch_fx, output_fx[LFE_CHANNEL], output_frame ); // Q11 } pop_wmops(); @@ -794,7 +794,7 @@ ivas_error create_mct_dec_fx( /* in case we have an uneven number of transport channels, indicate last channel ID as inactive */ if ( hMCT->nchan_out_woLFE % 2 ) { - st_ivas->hCPE[sub( st_ivas->nCPE, 1 )]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; move32(); } @@ -827,7 +827,7 @@ ivas_error create_mct_dec_fx( hMCT->hBlockData[n]->hStereoMdct->reverse_dmx = 0; move16(); move16(); - hMCT->hBlockData[n]->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; + hMCT->hBlockData[n]->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; // Q26 move32(); } FOR( ; n < MCT_MAX_BLOCKS; n++ ) @@ -1442,7 +1442,7 @@ ivas_error ivas_mc_dec_config_fx( { FOR( Word16 i = 0; i < 4; i++ ) { - st_ivas->hRenderConfig->directivity_fx[add( imult1616( i, 3 ), 2 )] = shl_sat( st_ivas->hRenderConfig->directivity_fx[add( imult1616( i, 3 ), 2 )], 9 ); + st_ivas->hRenderConfig->directivity_fx[( i * 3 ) + 2] = shl_sat( st_ivas->hRenderConfig->directivity_fx[( i * 3 ) + 2], 9 ); // Q15 move16(); } } @@ -1454,7 +1454,7 @@ ivas_error ivas_mc_dec_config_fx( { FOR( Word16 i = 0; i < 4; i++ ) { - st_ivas->hRenderConfig->directivity_fx[add( imult1616( i, 3 ), 2 )] = shr( st_ivas->hRenderConfig->directivity_fx[add( imult1616( i, 3 ), 2 )], 9 ); + st_ivas->hRenderConfig->directivity_fx[( i * 3 ) + 2] = shr( st_ivas->hRenderConfig->directivity_fx[( i * 3 ) + 2], 9 ); // Q15 move16(); } } diff --git a/lib_dec/ivas_mct_dec_mct_fx.c b/lib_dec/ivas_mct_dec_mct_fx.c index d6e5b686582b0a9899e0b6faf964b0be72470225..0f9bd98cc2be47af3e46055590cf978cb67d7c52 100644 --- a/lib_dec/ivas_mct_dec_mct_fx.c +++ b/lib_dec/ivas_mct_dec_mct_fx.c @@ -239,7 +239,7 @@ void apply_MCT_dec_fx( Word16 pair; MCT_DEC_BLOCK_DATA_HANDLE hBlock; - FOR( pair = sub( hMCT->currBlockDataCnt, 1 ); pair >= 0; pair-- ) + FOR( pair = hMCT->currBlockDataCnt - 1; pair >= 0; pair-- ) { hBlock = hMCT->hBlockData[pair]; @@ -260,7 +260,7 @@ void apply_MCT_dec_fx( void mctStereoIGF_dec_fx( MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ Decoder_State **stm, /* i/o: decoder state structure */ - Word32 *x[MCT_MAX_CHANNELS][NB_DIV], /* i/o: decoded and dequantized spectrum*/ + Word32 *x[MCT_MAX_CHANNELS][NB_DIV], /* i/o: decoded and dequantized spectrum i:Q12*/ const Word16 bfi /* i : bad frame flag */ ) { @@ -272,7 +272,7 @@ void mctStereoIGF_dec_fx( Word16 L_spec[CPE_CHANNELS]; Word16 L_frame[CPE_CHANNELS]; Word16 L_frameTCX[CPE_CHANNELS]; - Word32 *p_x[CPE_CHANNELS][NB_DIV]; + Word32 *p_x[CPE_CHANNELS][NB_DIV]; // Q(31 - p_x_e) Word16 p_x_e[CPE_CHANNELS][NB_DIV]; Word16 p_x_len[CPE_CHANNELS][NB_DIV]; Word16 singleChEle[MCT_MAX_CHANNELS]; @@ -305,13 +305,13 @@ void mctStereoIGF_dec_fx( move16(); // Using input Q-factor as 12 - set16_fx( p_x_e[0], 31 - Q12, CPE_CHANNELS ); - set16_fx( p_x_e[1], 31 - Q12, CPE_CHANNELS ); + set16_fx( p_x_e[0], 31 - Q12, CPE_CHANNELS ); // Q12 + set16_fx( p_x_e[1], 31 - Q12, CPE_CHANNELS ); // Q12 FOR( k = 0; k < nSubframes; k++ ) { - p_x[0][k] = x[ch1][k]; - p_x[1][k] = x[ch2][k]; + p_x[0][k] = x[ch1][k]; // Q12 + p_x[1][k] = x[ch2][k]; // Q12 test(); IF( NE_16( hMCT->hBlockData[b]->hStereoMdct->IGFStereoMode[k], SMDCT_DUAL_MONO ) || NE_16( hMCT->hBlockData[b]->hStereoMdct->mdct_stereo_mode[k], SMDCT_DUAL_MONO ) ) diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 608fc99874c0536c4f0c58b010d5f99ceebfc399..7201bad8cd2ada10041a2e406ba95e1c2bd40cd0 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -722,7 +722,7 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( FOR( Word16 n = 0; n < nSubframes; ++n ) { - const Word16 is_side = (Word16) L_and( EQ_16( ch, 1 ), EQ_16( param_lpc[0][n], SNS_STEREO_MODE_MS ) ); + const Word16 is_side = extract_l( L_and( EQ_16( ch, 1 ), EQ_16( param_lpc[0][n], SNS_STEREO_MODE_MS ) ) ); const Word16 *bits; Word16 nStages; IF( EQ_16( nSubframes, 1 ) ) @@ -736,6 +736,7 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( nStages = SNS_MSVQ_NSTAGES_TCX10; } move16(); + move16(); IF( is_side ) { /* check for zero-side flag */ @@ -753,6 +754,7 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( { bits = ivas_sns_cdbks_side_tcx10_bits; } + move16(); } FOR( Word16 j = 0; j < nStages; ++j ) @@ -1029,7 +1031,7 @@ void ivas_mdct_core_invQ_fx( Word32 *x[CPE_CHANNELS][NB_DIV], /* i/o: signal buffer */ Word16 x_e[CPE_CHANNELS][NB_DIV], Word16 x_len[CPE_CHANNELS][NB_DIV], - Word16 Aq[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* i : LP coefficients */ + Word16 Aq[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* i : LP coefficients Q12*/ Word16 ms_mask[NB_DIV][MAX_SFB], /* i : M/S mask */ const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */ ) @@ -1044,7 +1046,7 @@ void ivas_mdct_core_invQ_fx( Word16 Aind[CPE_CHANNELS][M + 1]; Word32 sns[CPE_CHANNELS][NB_DIV][M]; /* TCX */ - Word16 xn_buf[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; + Word16 xn_buf[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; // Q14 Word16 tcx_offset[CPE_CHANNELS]; Word16 tcx_offsetFB[CPE_CHANNELS]; Word16 left_rect[CPE_CHANNELS]; @@ -1142,8 +1144,8 @@ void ivas_mdct_core_invQ_fx( stereo_decoder_tcx_fx( hCPE->hStereoMdct, ms_mask, x_0[1], &spectralData_tmp[0], &spectralData_tmp[1], &hCPE->hStereoMdct->mdct_stereo_mode[0], sts[0]->core, sts[1]->core, sts[0]->igf, L_frameTCX[0], L_frameTCX[1], 0, sts[0]->last_core, sts[1]->last_core, 1, &q_r, &q_l ); #ifdef MSAN_FIX - Copy_Scale_sig_32_16( spectralData_tmp[0], sts[0]->hTonalMDCTConc->lastBlockData.spectralData, L_frameTCX[0], -15 ); - Copy_Scale_sig_32_16( spectralData_tmp[1], sts[1]->hTonalMDCTConc->lastBlockData.spectralData, L_frameTCX[1], -15 ); + Copy_Scale_sig_32_16( spectralData_tmp[0], sts[0]->hTonalMDCTConc->lastBlockData.spectralData, L_frameTCX[0], -15 ); // q_l - 15 + Copy_Scale_sig_32_16( spectralData_tmp[1], sts[1]->hTonalMDCTConc->lastBlockData.spectralData, L_frameTCX[1], -15 ); // q_r - 15 #else Copy_Scale_sig_32_16( spectralData_tmp[0], sts[0]->hTonalMDCTConc->lastBlockData.spectralData, L_FRAME_MAX, -15 ); Copy_Scale_sig_32_16( spectralData_tmp[1], sts[1]->hTonalMDCTConc->lastBlockData.spectralData, L_FRAME_MAX, -15 ); @@ -1298,8 +1300,8 @@ void ivas_mdct_core_invQ_fx( } } - Copy( tmp_ms_sig[0], sts[0]->hTonalMDCTConc->lastBlockData.spectralData, L_frameTCX[0] ); - Copy( tmp_ms_sig[1], sts[1]->hTonalMDCTConc->lastBlockData.spectralData, L_frameTCX[0] ); + Copy( tmp_ms_sig[0], sts[0]->hTonalMDCTConc->lastBlockData.spectralData, L_frameTCX[0] ); // Q(15 - tmp_ms_sig_e) + Copy( tmp_ms_sig[1], sts[1]->hTonalMDCTConc->lastBlockData.spectralData, L_frameTCX[0] ); // Q(15 - tmp_ms_sig_e) sts[0]->hTonalMDCTConc->lastBlockData.spectralData_exp = tmp_ms_sig_e[0]; move16(); sts[1]->hTonalMDCTConc->lastBlockData.spectralData_exp = tmp_ms_sig_e[1]; @@ -1860,6 +1862,15 @@ void ivas_mdct_core_reconstruct( { set_f( &synth[k * L_frame[ch]], 0.f, L_frame[ch] ); set_f( &synthFB[k * L_frame[ch]], 0.f, L_frameTCX[ch] ); +#ifdef FIX_903_ZERO_OUT_IMDCT_BUFFERS_FOR_MCT_IGNORE + /* Note: these buffers are not subframe-based, hence no indexing with k */ + set_f( &st->hHQ_core->old_outLB[0], 0.f, L_frame[ch] ); + set_f( &st->hHQ_core->old_out[0], 0.f, L_frameTCX[ch] ); + set_f( &st->hTcxDec->syn_Overl[0], 0.f, L_frame[ch] / 2 ); + set_f( &st->hTcxDec->syn_OverlFB[0], 0.f, L_frameTCX[ch] / 2 ); + set_f( &st->hTcxDec->syn_Overl_TDAC[0], 0.f, L_frame[ch] / 2 ); + set_f( &st->hTcxDec->syn_Overl_TDACFB[0], 0.f, L_frameTCX[ch] / 2 ); +#endif } } @@ -1990,14 +2001,14 @@ void ivas_mdct_core_reconstruct_fx( Word16 q_win = -2; move16(); /* TCX */ - Word16 xn_buf_fx[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; + Word16 xn_buf_fx[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; // Q(-2) Word16 tcx_offset[CPE_CHANNELS]; Word16 tcx_offsetFB[CPE_CHANNELS]; Word16 left_rect[CPE_CHANNELS]; Word16 L_spec[CPE_CHANNELS]; Word16 pitch[CPE_CHANNELS][NB_SUBFR16k]; - Word16 pit_gain_fx[CPE_CHANNELS][NB_SUBFR16k]; + Word16 pit_gain_fx[CPE_CHANNELS][NB_SUBFR16k]; // Q14 Word16 skip_decoding, sf; set16_fx( xn_buf_fx, 0, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX ); @@ -2052,21 +2063,21 @@ void ivas_mdct_core_reconstruct_fx( set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M ); IF( st->core != ACELP_CORE ) { - Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( q_win, sub( -1, st->Q_syn ) ) ); - Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( q_win, sub( -1, st->Q_syn ) ) ); - Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( q_win, sub( -1, st->Q_syn ) ) ); - Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( q_win, st->Q_syn ) ); - Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( q_win, st->Q_syn ) ); - Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( q_win, st->hHQ_core->Q_old_wtda_LB ) ); - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( q_win, st->hHQ_core->Q_old_wtda ) ); + Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( q_win, st->hTcxDec->Q_syn_Overl_TDACFB ) ); // st->hTcxDec->Q_syn_Overl_TDACFB -> q_win + Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( q_win, st->hTcxDec->Q_syn_Overl_TDAC ) ); // st->hTcxDec->Q_syn_Overl_TDAC -> q_win + Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( q_win, sub( -1, st->Q_syn ) ) ); // Q(-1 - st->Q_syn) -> q_win + Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win + Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win + Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( q_win, st->hHQ_core->Q_old_wtda_LB ) ); // Q(st->hHQ_core->Q_old_wtda_LB) -> q_win + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( q_win, st->hHQ_core->Q_old_wtda ) ); // Q(st->hHQ_core->Q_old_wtda) -> q_win #ifdef MSAN_FIX - Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); - Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win + Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win #else Scale_sig( synth_buf_fx, 3136, sub( q_win, q_syn ) ); Scale_sig( synth_bufFB_fx, 3136, sub( q_win, q_syn ) ); #endif - Scale_sig( st->syn, M + 1, sub( q_win, st->Q_syn ) ); + Scale_sig( st->syn, M + 1, sub( q_win, st->Q_syn ) ); // st->Q_syn -> q_win FOR( k = 0; k < nSubframes[ch]; k++ ) { init_tcx_info_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], k, bfi, &tcx_offset[ch], @@ -2079,18 +2090,27 @@ void ivas_mdct_core_reconstruct_fx( IF( ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( st->hTcxDec->kernel_type[k], MDST_IV ) ) || EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, q_win, - MDCT_IV, fUseTns[ch][k], &synth_fx[L_mult0( k, L_frame[ch] )], &synthFB_fx[L_mult0( k, L_frameTCX[ch] )], bfi, k, 0 ); + MDCT_IV, fUseTns[ch][k], &synth_fx[k * L_frame[ch]], &synthFB_fx[k * L_frameTCX[ch]], bfi, k, 0 ); } ELSE { decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, q_win, - st->hTcxDec->kernel_type[k], fUseTns[ch][k], &synth_fx[L_mult0( k, L_frame[ch] )], &synthFB_fx[L_mult0( k, L_frameTCX[ch] )], bfi, k, 0 ); + st->hTcxDec->kernel_type[k], fUseTns[ch][k], &synth_fx[k * L_frame[ch]], &synthFB_fx[k * L_frameTCX[ch]], bfi, k, 0 ); } } ELSE { - set16_fx( &synth_fx[L_mult0( k, L_frame[ch] )], 0, L_frame[ch] ); - set16_fx( &synthFB_fx[L_mult0( k, L_frame[ch] )], 0, L_frameTCX[ch] ); + set16_fx( &synth_fx[k * L_frame[ch]], 0, L_frame[ch] ); + set16_fx( &synthFB_fx[k * L_frame[ch]], 0, L_frameTCX[ch] ); +#ifdef FIX_903_ZERO_OUT_IMDCT_BUFFERS_FOR_MCT_IGNORE + /* Note: these buffers are not subframe-based, hence no indexing with k */ + set16_fx( &st->hHQ_core->old_out_LB_fx[0], 0, L_frame[ch] ); + set16_fx( &st->hHQ_core->old_out_fx[0], 0, L_frameTCX[ch] ); + set16_fx( &st->hTcxDec->syn_Overl[0], 0, shr( L_frame[ch], 1 ) ); + set16_fx( &st->hTcxDec->syn_OverlFB[0], 0, shr( L_frameTCX[ch], 1 ) ); + set16_fx( &st->hTcxDec->syn_Overl_TDAC[0], 0, shr( L_frame[ch], 1 ) ); + set16_fx( &st->hTcxDec->syn_Overl_TDACFB[0], 0, shr( L_frameTCX[ch], 1 ) ); +#endif } } @@ -2115,21 +2135,26 @@ void ivas_mdct_core_reconstruct_fx( { st->Q_syn = add( q_win, sf ); } - Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( sub( -1, st->Q_syn ), q_win ) ); - Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( sub( -1, st->Q_syn ), q_win ) ); - Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( sub( -1, st->Q_syn ), q_win ) ); + + Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( sub( -1, st->Q_syn ), q_win ) ); // q_win -> Q(-1 - st->Q_syn) + st->hTcxDec->Q_syn_Overl_TDACFB = sub( -1, st->Q_syn ); + move16(); + Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( sub( -1, st->Q_syn ), q_win ) ); // q_win -> Q(-1 - st->Q_syn) + st->hTcxDec->Q_syn_Overl_TDAC = sub( -1, st->Q_syn ); + move16(); + Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( sub( -1, st->Q_syn ), q_win ) ); // q_win -> Q(-1 - st->Q_syn) #ifdef MSAN_FIX - Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); - Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // q_win -> q_syn + Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // q_win -> q_syn #else Scale_sig( synth_buf_fx, 3136, sub( q_syn, q_win ) ); Scale_sig( synth_bufFB_fx, 3136, sub( q_syn, q_win ) ); #endif Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); - Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( st->Q_syn, q_win ) ); - Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, q_win ) ); - Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, q_win ) ); - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, q_win ) ); + Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn + Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn + Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn st->hHQ_core->Q_old_wtda = st->Q_syn; move16(); st->hHQ_core->Q_old_wtda_LB = st->Q_syn; @@ -2138,15 +2163,15 @@ void ivas_mdct_core_reconstruct_fx( ELSE /*ACELP core for ACELP-PLC */ { assert( EQ_16( st->bfi, 1 ) ); - Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), negate( q_syn ) ); - Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), negate( q_syn ) ); + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), negate( q_syn ) ); // Q0 + Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), negate( q_syn ) ); // Q0 q_syn = 0; move16(); move16(); /* PLC: [TCX: TD PLC] */ IF( MCT_flag != 0 ) { - con_tcx_ivas_fx( st, &synthFB_fx[0], -16384, NULL, 0, NULL ); + con_tcx_ivas_fx( st, &synthFB_fx[0], -16384, NULL, 0, NULL ); //-1.Q14 = -16384 } ELSE { @@ -2160,14 +2185,14 @@ void ivas_mdct_core_reconstruct_fx( } } - Scale_sig( synthFB_fx, st->hTcxDec->L_frameTCX, q_syn ); + Scale_sig( synthFB_fx, st->hTcxDec->L_frameTCX, q_syn ); // q_syn IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || ( st->hTcxDec->tcxConceal_recalc_exc != 0 ) ) { - Scale_sig( synthFB_fx - add( add( shr( st->hTcxDec->L_frameTCX, 1 ), st->hTcxDec->pit_max_TCX ), 2 * M ), add( add( shr( st->hTcxDec->L_frameTCX, 1 ), st->hTcxDec->pit_max_TCX ), 2 * M ), sub( q_syn, sub( st->Q_exc, 1 ) ) ); + Scale_sig( synthFB_fx - add( add( shr( st->hTcxDec->L_frameTCX, 1 ), st->hTcxDec->pit_max_TCX ), 2 * M ), add( add( shr( st->hTcxDec->L_frameTCX, 1 ), st->hTcxDec->pit_max_TCX ), 2 * M ), sub( q_syn, sub( st->Q_exc, 1 ) ) ); // 2 * q_syn - (st->Q_exc - 1) } ELSE { - Scale_sig( synthFB_fx - st->hTcxDec->L_frameTCX, st->hTcxDec->L_frameTCX, sub( q_syn, sub( st->Q_exc, 1 ) ) ); + Scale_sig( synthFB_fx - st->hTcxDec->L_frameTCX, st->hTcxDec->L_frameTCX, sub( q_syn, sub( st->Q_exc, 1 ) ) ); // 2 * q_syn - (st->Q_exc - 1) } lerp( synthFB_fx, synth_fx, st->L_frame, st->hTcxDec->L_frameTCX ); @@ -2213,7 +2238,7 @@ void ivas_mdct_core_reconstruct_fx( st->hTcxDec->q_synth_history_fx = st->hTcxDec->q_old_synth; move16(); move16(); - Scale_sig( st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( st->Q_syn, q_syn ) ); + Scale_sig( st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( st->Q_syn, q_syn ) ); // st->Q_syn IF( st->hHQ_core != NULL ) { Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + st->hTcxDec->old_synth_lenFB, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); @@ -2228,14 +2253,14 @@ void ivas_mdct_core_reconstruct_fx( Word16 x_fx_16[1200]; IF( st->p_bpf_noise_buf_32 ) { - Copy_Scale_sig_32_16( st->p_bpf_noise_buf_32, st->p_bpf_noise_buf, st->L_frame, -Q11 ); + Copy_Scale_sig_32_16( st->p_bpf_noise_buf_32, st->p_bpf_noise_buf, st->L_frame, -Q11 ); // Q11 -> Q0 } post_decoder_ivas_fx( st, synth_buf_fx, pit_gain_fx[ch], pitch[ch], x_fx_16, st->p_bpf_noise_buf ); IF( st->p_bpf_noise_buf_32 ) { - Copy_Scale_sig_16_32_no_sat( st->p_bpf_noise_buf, st->p_bpf_noise_buf_32, st->L_frame, Q11 ); + Copy_Scale_sig_16_32_no_sat( st->p_bpf_noise_buf, st->p_bpf_noise_buf_32, st->L_frame, Q11 ); // Q0 -> Q11 } IF( signal_outFB_fx[ch] != NULL ) { @@ -2250,7 +2275,7 @@ void ivas_mdct_core_reconstruct_fx( st->last_coder_type = st->coder_type; move16(); - Copy_Scale_sig_16_32( x_fx_16, x_fx[ch][0], st->L_frame, sub( q_x, q_syn ) ); + Copy_Scale_sig_16_32( x_fx_16, x_fx[ch][0], st->L_frame, sub( q_x, q_syn ) ); // q_syn -> Q_x } IF( GT_16( e_sig[0], e_sig[1] ) ) @@ -2307,9 +2332,9 @@ void ivas_mdct_core_reconstruct_fx( L_tmp = Mpy_32_32( W_extract_h( nrgL_fx ), W_extract_h( nrgR_fx ) ); e_tmp = add( e_nrgL, e_nrgR ); L_tmp = ISqrt32( L_tmp, &e_tmp ); - hCPE->hStereoMdct->lastCoh_fx = extract_l( L_shr( Mpy_32_32( L_abs( W_extract_h( xcorr_fx ) ), L_tmp ), sub( 17, add( e_xcorr, e_tmp ) ) ) ); + hCPE->hStereoMdct->lastCoh_fx = extract_l( L_shr( Mpy_32_32( L_abs( W_extract_h( xcorr_fx ) ), L_tmp ), sub( 17, add( e_xcorr, e_tmp ) ) ) ); // Q14 move16(); - hCPE->hStereoMdct->lastCoh_fx = s_min( hCPE->hStereoMdct->lastCoh_fx, 16384 ); + hCPE->hStereoMdct->lastCoh_fx = s_min( hCPE->hStereoMdct->lastCoh_fx, 16384 ); // 1.Q14 = 16384 move16(); } @@ -2448,8 +2473,8 @@ void ivas_mdct_core_tns_ns_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : two entries for each channel in TCX10 */ STnsData tnsData[CPE_CHANNELS][NB_DIV], /* o : TNS parameter */ - Word32 *x_fx[CPE_CHANNELS][NB_DIV], /* o : synthesis @internal_FS */ - Word32 Aq_fx[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* o : LP coefficients */ + Word32 *x_fx[CPE_CHANNELS][NB_DIV], /* o : synthesis @internal_FS Q(31 - x_e)*/ + Word32 Aq_fx[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* o : LP coefficients Q16*/ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ Word16 x_e[CPE_CHANNELS][NB_DIV] ) { @@ -2527,11 +2552,13 @@ void ivas_mdct_core_tns_ns_fx( q_x = sub( 31, x_e[ch][k] ); IF( bfi == 0 ) { - sns_interpolate_scalefactors_fx( sns_int_scf_fx, &Aq_fx[ch][k * M], DEC ); + sns_interpolate_scalefactors_fx( sns_int_scf_fx, &Aq_fx[ch][k * M], DEC ); // Q16 + test(); + test(); IF( ( MCT_flag != 0 ) && st->hTonalMDCTConc != NULL && EQ_16( add( k, 1 ), nSubframes[ch] ) ) { - Word16 scf_fx[FDNS_NPTS], scf_e[FDNS_NPTS]; + Word16 scf_fx[FDNS_NPTS] /*(16 - scf_e)*/, scf_e[FDNS_NPTS]; Word16 q_shift; FOR( Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++ ) { @@ -2548,7 +2575,8 @@ void ivas_mdct_core_tns_ns_fx( { IF( st->hTonalMDCTConc != NULL ) { - IF( ( MCT_flag == 0 ) && LT_16( st->hTcxDec->cummulative_damping_tcx, 32440 ) ) + test(); + IF( ( MCT_flag == 0 ) && LT_16( st->hTcxDec->cummulative_damping_tcx, 32440 ) ) // 0.99.Q15 = 32440 { Word16 *scf_last_m, *scf_last_e; Word32 *scf_bg; @@ -2567,7 +2595,7 @@ void ivas_mdct_core_tns_ns_fx( FOR( Word16 i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) { - sns_int_scf_fx[i] = Madd_32_16( Mpy_32_16_1( L_shl( scf_last_m[i], add( 1, scf_last_e[i] ) ), fade_out ), scf_bg[i], fade_in ); + sns_int_scf_fx[i] = Madd_32_16( Mpy_32_16_1( L_shl( scf_last_m[i], add( 1, scf_last_e[i] ) ), fade_out ), scf_bg[i], fade_in ); // Q16 move32(); } } @@ -2577,7 +2605,7 @@ void ivas_mdct_core_tns_ns_fx( move16(); FOR( Word16 i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) { - sns_int_scf_fx[i] = L_shl( st->hTonalMDCTConc->lastBlockData.scaleFactors[i], add( 1, st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[i] ) ); + sns_int_scf_fx[i] = L_shl( st->hTonalMDCTConc->lastBlockData.scaleFactors[i], add( 1, st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[i] ) ); // Q16 move32(); } } @@ -2611,7 +2639,7 @@ void ivas_mdct_core_tns_ns_fx( // q_sns_int_scf -= 1; FOR( Word16 c = 0; c < FDNS_NPTS; c++ ) { - sns_int_scf_fx[c] = L_shl( sns_int_scf_fx[c], sub( q_sns_int_scf, 16 ) ); + sns_int_scf_fx[c] = L_shl( sns_int_scf_fx[c], sub( q_sns_int_scf, 16 ) ); // Q16 -> q_sns_int_scf move32(); } q_2 = q_x; diff --git a/lib_dec/ivas_mono_dmx_renderer.c b/lib_dec/ivas_mono_dmx_renderer.c index 57a658f4bf717898599f4fe874e8f691141a38e7..b6c8d0273b141a31b3f8287900ba9ca42b4a3707 100644 --- a/lib_dec/ivas_mono_dmx_renderer.c +++ b/lib_dec/ivas_mono_dmx_renderer.c @@ -213,7 +213,7 @@ void ivas_mono_downmix_render_passive( #else void ivas_mono_downmix_render_passive_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_f_fx[], /* i/o: synthesized core-coder transport channels/mono output */ + Word32 *output_f_fx[], /* i/o: synthesized core-coder transport channels/mono output Qin = 11/ Qout = 8*/ const Word16 output_frame /* i : output frame length */ ) { @@ -353,7 +353,7 @@ void ivas_mono_downmix_render_passive_fx( } ELSE { - eq_fx = 16384; + eq_fx = 16384; // 0.5.Q15 move16(); } @@ -415,7 +415,7 @@ void ivas_mono_stereo_downmix_mcmasa( #else void ivas_mono_stereo_downmix_mcmasa_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_f_fx[], /* i/o: synthesized core-coder transport channels/mono or stereo output */ + Word32 *output_f_fx[], /* i/o: synthesized core-coder transport channels/mono or stereo output Q11*/ Word16 output_frame /* i : output frame length per channel */ ) { @@ -429,8 +429,8 @@ void ivas_mono_stereo_downmix_mcmasa_fx( test(); IF( EQ_16( st_ivas->hDecoderConfig->nchan_out, 2 ) && st_ivas->hOutSetup.separateChannelEnabled ) { - v_multc_acc_32_16( output_f_fx[st_ivas->hOutSetup.separateChannelIndex], INV_SQRT2_FX_Q15, output_f_fx[0], output_frame ); - v_multc_acc_32_16( output_f_fx[st_ivas->hOutSetup.separateChannelIndex], INV_SQRT2_FX_Q15, output_f_fx[1], output_frame ); + v_multc_acc_32_16( output_f_fx[st_ivas->hOutSetup.separateChannelIndex], INV_SQRT2_FX_Q15, output_f_fx[0], output_frame ); // Q11 + v_multc_acc_32_16( output_f_fx[st_ivas->hOutSetup.separateChannelIndex], INV_SQRT2_FX_Q15, output_f_fx[1], output_frame ); // Q11 } /* Mono downmix */ ELSE IF( EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 ) ) @@ -438,7 +438,7 @@ void ivas_mono_stereo_downmix_mcmasa_fx( /* Downmix L and R to dmx_tmp */ FOR( i = 0; i < st_ivas->nchan_transport; i++ ) { - v_multc_acc_32_16( output_f_fx[i], INV_SQRT2_FX_Q15, dmx_tmp_fx, output_frame ); + v_multc_acc_32_16( output_f_fx[i], INV_SQRT2_FX_Q15, dmx_tmp_fx, output_frame ); // Q11 } /* Add center channel */ IF( st_ivas->hOutSetup.separateChannelEnabled ) @@ -447,7 +447,7 @@ void ivas_mono_stereo_downmix_mcmasa_fx( } /* Move to output */ - Copy32( dmx_tmp_fx, output_f_fx[0], output_frame ); + Copy32( dmx_tmp_fx, output_f_fx[0], output_frame ); // Q11 } return; @@ -483,13 +483,13 @@ void ivas_apply_non_diegetic_panning( #else void ivas_apply_non_diegetic_panning_fx( Word32 *output_f_fx[], /* i/o: core-coder transport mono channel/stereo output */ - const Word16 non_diegetic_pan_gain_fx, /* i : non-diegetic panning gain */ - const Word16 output_frame /* i : output frame length per channel */ + const Word16 non_diegetic_pan_gain_fx, /* i : non-diegetic panning gain Q15*/ + const Word16 output_frame /* i : output frame length per channel Q11*/ ) { Word16 pan_left_fx, pan_right_fx; - pan_left_fx = add( mult( non_diegetic_pan_gain_fx, 16348 ), 16348 ); + pan_left_fx = add( mult( non_diegetic_pan_gain_fx, 16384 ), 16384 ); // 0.5.Q15 = 16384 pan_right_fx = sub( 32767, pan_left_fx ); v_multc_fixed( output_f_fx[0], L_shl( L_deposit_l( pan_right_fx ), 16 ), output_f_fx[1], output_frame ); diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index ecc44918242a5e43f2389527661f5625ebfedcf2..e304edf6c397680dfe92c86b9f4994ae24991354 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -95,7 +95,7 @@ ivas_error ivas_td_binaural_open( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_td_binaural_renderer_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output[], /* i/o: SCE channels / Binaural synthesis */ + Word32 *output[], /* i/o: SCE channels / Binaural synthesis Q11*/ const Word16 output_frame /* i : output frame length */ ) { @@ -169,9 +169,9 @@ ivas_error ivas_td_binaural_renderer( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_td_binaural_renderer_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis */ - const int16_t n_samples_granularity /* i : granularity of the renderer/buffer */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis Q11*/ + const Word16 n_samples_granularity /* i : granularity of the renderer/buffer */ ) { Word16 first_sf, last_sf, subframe_idx; @@ -245,7 +245,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) { - output_fx_local[ch] = output_fx[ch]; + output_fx_local[ch] = output_fx[ch]; // Q11 } slot_size = st_ivas->hTcBuffer->n_samples_granularity; @@ -342,7 +342,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( scale_sig32( tc_local_fx[i], st_ivas->hReverb->full_block_size, -4 ); // Q11 - 4 = Q7 } - IF( NE_32( ( error = ivas_reverb_process_fx( st_ivas->hReverb, st_ivas->transport_config, 0, tc_local_fx, p_reverb_signal_fx, 0 ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_reverb_process_fx( st_ivas->hReverb, st_ivas->transport_config, 0, tc_local_fx, p_reverb_signal_fx, 0 ) ), IVAS_ERR_OK ) ) // Q(p_reverb_signal_fx) = 11 { return error; } @@ -370,7 +370,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( IF( st_ivas->hRenderConfig != NULL && EQ_32( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { /* add reverb to rendered signals */ - v_add_32( reverb_signal_fx[0], output_fx_local[0], output_fx_local[0], output_frame ); + v_add_32( reverb_signal_fx[0], output_fx_local[0], output_fx_local[0], output_frame ); // Q11 v_add_32( reverb_signal_fx[1], output_fx_local[1], output_fx_local[1], output_frame ); } diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index bb0e65b26f04d0a18e63f9c2b9a5ed643e819dc5..4771a8055dbf15d0c999ee1f8ba99dd976924df6 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -131,16 +131,16 @@ ivas_error ivas_omasa_data_open_fx( { hMasaIsmData->ismPreprocMatrix_fx[ch][ch][bin] = 32767; /* 1.0f in Q15 */ move16(); - hMasaIsmData->ismPreprocMatrix_fx[1 - ch][ch][bin] = 0; + hMasaIsmData->ismPreprocMatrix_fx[1 - ch][ch][bin] = 0; // Q15 move16(); - hMasaIsmData->eneMoveIIR_fx[ch][bin] = 0; + hMasaIsmData->eneMoveIIR_fx[ch][bin] = 0; // Q22 move32(); - hMasaIsmData->enePreserveIIR_fx[ch][bin] = 0; + hMasaIsmData->enePreserveIIR_fx[ch][bin] = 0; // Q22 move32(); } - hMasaIsmData->preprocEneTarget_fx[bin] = 0; + hMasaIsmData->preprocEneTarget_fx[bin] = 0; // Q19 move32(); - hMasaIsmData->preprocEneRealized_fx[bin] = 0; + hMasaIsmData->preprocEneRealized_fx[bin] = 0; // Q19 move32(); } @@ -152,9 +152,9 @@ ivas_error ivas_omasa_data_open_fx( { hMasaIsmData->ism_is_edited[ch] = 0; move16(); - hMasaIsmData->q_elevation_old_fx[ch] = 0; + hMasaIsmData->q_elevation_old_fx[ch] = 0; // Q22 move32(); - hMasaIsmData->q_azimuth_old_fx[ch] = 0; + hMasaIsmData->q_azimuth_old_fx[ch] = 0; // Q22 move32(); } @@ -227,7 +227,7 @@ void ivas_omasa_data_close_fx( { FOR( i = 0; i < ( *hMasaIsmData )->delayBuffer_nchan; i++ ) { - free( ( *hMasaIsmData )->delayBuffer_fx[i] ); + free( ( *hMasaIsmData )->delayBuffer_fx[i] ); // Q11 } free( ( *hMasaIsmData )->delayBuffer_fx ); ( *hMasaIsmData )->delayBuffer_fx = NULL; @@ -253,7 +253,7 @@ ivas_error ivas_omasa_dec_config_fx( UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ Word16 *num_src, Word16 SrcInd[MAX_NUM_TDREND_CHANNELS], - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal Qx*/ ) { Word16 k, sce_id, nSCE_old, nchan_hp20_old, numCldfbAnalyses_old, numCldfbSyntheses_old, n_MD; @@ -362,14 +362,14 @@ ivas_error ivas_omasa_dec_config_fx( FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - ism_total_brate = L_add( ism_total_brate, sep_object_brate[sub( k, 2 )][sub( st_ivas->nSCE, 1 )] ); + ism_total_brate = L_add( ism_total_brate, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); } brate_SCE = 0; move32(); IF( st_ivas->nSCE > 0 ) { - brate_SCE = sep_object_brate[sub( k, 2 )][sub( st_ivas->nSCE, 1 )]; + brate_SCE = sep_object_brate[k - 2][st_ivas->nSCE - 1]; move32(); } brate_CPE = L_sub( ivas_total_brate, ism_total_brate ); @@ -954,7 +954,7 @@ void ivas_set_surplus_brate_dec( tmp = idiv1616( bits_ism, st_ivas->nchan_ism ); } set16_fx( bits_element, tmp, st_ivas->nchan_ism ); - bits_element[sub( st_ivas->nchan_ism, 1 )] = add( bits_element[sub( st_ivas->nchan_ism, 1 )], bits_ism % st_ivas->nchan_ism ); + bits_element[st_ivas->nchan_ism - 1] = add( bits_element[st_ivas->nchan_ism - 1], bits_ism % st_ivas->nchan_ism ); move16(); bitbudget_to_brate( bits_element, element_brate, st_ivas->nchan_ism ); @@ -1136,12 +1136,12 @@ ivas_error ivas_omasa_ism_metadata_dec_fx( { // azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); // elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); - azimuth_ism = extract_l( L_shr_r( L_abs( st_ivas->hIsmMetaData[n]->azimuth_fx ), 22 ) ); + azimuth_ism = extract_l( L_shr_r( L_abs( st_ivas->hIsmMetaData[n]->azimuth_fx /*Q22*/ ), 22 ) ); // Q0 if ( st_ivas->hIsmMetaData[n]->azimuth_fx < 0 ) { azimuth_ism = negate( azimuth_ism ); } - elevation_ism = extract_l( L_shr_r( L_abs( st_ivas->hIsmMetaData[n]->elevation_fx ), 22 ) ); + elevation_ism = extract_l( L_shr_r( L_abs( st_ivas->hIsmMetaData[n]->elevation_fx /*Q22*/ ), 22 ) ); // Q0 if ( st_ivas->hIsmMetaData[n]->elevation_fx < 0 ) { elevation_ism = negate( elevation_ism ); @@ -1243,7 +1243,7 @@ void ivas_omasa_dirac_rend_jbm_fx( UWord16 *nSamplesRendered, /* o : number of samples rendered */ UWord16 *nSamplesAvailable, /* o : number of samples still to render */ const Word16 nchan_transport, /* i : number of transport channels */ - Word32 *output_f[] /* o : rendered time signal */ + Word32 *output_f[] /* o : rendered time signal Q11*/ ) { Word16 subframes_rendered; @@ -1367,15 +1367,15 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm_fx( UWord16 *nSamplesRendered, /* o : number of samples rendered */ UWord16 *nSamplesAvailable, /* o : number of samples still to render */ const Word16 nchan_transport, /* i : number of transport channels */ - Word32 *output_fx[] /* o : rendered time signal */ + Word32 *output_fx[] /* o : rendered time signal Q11*/ ) { Word16 n; - Word16 gain_fx = OMASA_TDREND_MATCHING_GAIN_FX; + Word16 gain_fx = OMASA_TDREND_MATCHING_GAIN_FX; // Q15 move16(); ivas_error error; Word32 *tc_local_fx[MAX_TRANSPORT_CHANNELS]; - Word32 *p_sepobj_fx[MAX_NUM_OBJECTS]; + Word32 *p_sepobj_fx[MAX_NUM_OBJECTS]; // Q11 Word32 data_separated_objects_fx[MAX_NUM_OBJECTS][L_FRAME48k]; move16(); @@ -1393,7 +1393,7 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm_fx( FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { - tc_local_fx[n] = st_ivas->hTcBuffer->tc_fx[n + 2]; + tc_local_fx[n] = st_ivas->hTcBuffer->tc_fx[n + 2]; // Q11 v_multc_fixed_16( tc_local_fx[n], gain_fx, tc_local_fx[n], tcBufferSize ); delay_signal_fx( tc_local_fx[n], tcBufferSize, st_ivas->hMasaIsmData->delayBuffer_fx[n], st_ivas->hMasaIsmData->delayBuffer_size ); @@ -1449,13 +1449,13 @@ void ivas_omasa_rearrange_channels( } #else void ivas_omasa_rearrange_channels_fx( - Word32 *output[], /* o : output synthesis signal */ + Word32 *output[], /* o : output synthesis signal Q11*/ const Word16 nchan_transport_ism, /* o : number of ISM TCs */ const Word16 output_frame /* i : output frame length per channel */ ) { Word16 n; - Word32 tmp_buff[CPE_CHANNELS][L_FRAME48k]; + Word32 tmp_buff[CPE_CHANNELS][L_FRAME48k]; // Q11 Copy32( output[0], tmp_buff[0], output_frame ); Copy32( output[1], tmp_buff[1], output_frame ); diff --git a/lib_dec/ivas_osba_dec.c b/lib_dec/ivas_osba_dec.c index b45bd339cf99a9b918cbbc9d3f3ea49473e5b00b..d5fc88441fce373acf497fb6ce60288110f37e08 100644 --- a/lib_dec/ivas_osba_dec.c +++ b/lib_dec/ivas_osba_dec.c @@ -199,7 +199,7 @@ ivas_error ivas_osba_dirac_td_binaural_jbm_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ - Word32 *output_fx[], /* o : rendered time signal */ + Word32 *output_fx[], /* o : rendered time signal Q11*/ Word16 out_len /*Store the length of values in each channel*/ ) { @@ -232,7 +232,7 @@ ivas_error ivas_osba_dirac_td_binaural_jbm_fx( Word16 i; FOR( i = 0; i < nSamplesAsked; i++ ) { - output_fx[n][i] = L_add( L_shr( output_fx[add( channel_offset, n )][i], 1 ), L_shr( p_sepobj_fx[n][i], 1 ) ); + output_fx[n][i] = L_add( L_shr( output_fx[channel_offset + n][i], 1 ), L_shr( p_sepobj_fx[n][i], 1 ) ); move32(); } } @@ -355,7 +355,7 @@ ivas_error ivas_osba_render_sf_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *p_output[] /* o : rendered time signal */ + Word32 *p_output[] /* o : rendered time signal Q11*/ ) { Word16 n; @@ -370,7 +370,7 @@ ivas_error ivas_osba_render_sf_fx( FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { - v_shr( p_output[n], Q11 - Q11, output_ism[n], nSamplesAsked ); + v_shr( p_output[n], Q11 - Q11, output_ism[n], nSamplesAsked ); // Q11 } IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailableNext, p_output, 960 ) ), IVAS_ERR_OK ) ) diff --git a/lib_dec/ivas_out_setup_conversion.c b/lib_dec/ivas_out_setup_conversion.c index d386b3c85bc3922fe6e3e6f5133f2212df788997..14da4b0fa459b4fbef88d64c7d8fd88c08446dc5 100644 --- a/lib_dec/ivas_out_setup_conversion.c +++ b/lib_dec/ivas_out_setup_conversion.c @@ -72,20 +72,20 @@ #ifdef IVAS_FLOAT_FIXED static void ivas_lssetupconversion_computeEQFactor_fx( - Word32 *outputEnergy, - Word32 *inputEnergy, + Word32 *outputEnergy, // Q0 + Word32 *inputEnergy, // Q0 Word32 *EQ ) { IF( GE_32( L_shr( *outputEnergy, 3 ), Mpy_32_32( LS_OUT_CONV_CLIP_FACTOR_MAX_SQ_Q28, *inputEnergy ) ) ) { - *EQ = L_shl_sat( LS_OUT_CONV_CLIP_FACTOR_MAX_Q29, 1 ); + *EQ = L_shl_sat( LS_OUT_CONV_CLIP_FACTOR_MAX_Q29, 1 ); // Q30 move32(); return; } IF( LE_32( L_shr( *outputEnergy, 3 ), Mpy_32_32( LS_OUT_CONV_CLIP_FACTOR_MIN_SQ_Q28, *inputEnergy ) ) ) { - *EQ = L_shl_sat( LS_OUT_CONV_CLIP_FACTOR_MIN_Q29, 1 ); + *EQ = L_shl_sat( LS_OUT_CONV_CLIP_FACTOR_MIN_Q29, 1 ); // Q30 move32(); return; } @@ -93,7 +93,7 @@ static void ivas_lssetupconversion_computeEQFactor_fx( test(); IF( ( *outputEnergy == 0 ) && ( *inputEnergy == 0 ) ) { - *EQ = ONE_IN_Q30; + *EQ = ONE_IN_Q30; // Q30 move32(); return; } @@ -360,7 +360,7 @@ static void get_custom_ls_conversion_matrix_fx( } ELSE { - hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = tmp_gains[ch_out_woLFE]; + hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = tmp_gains[ch_out_woLFE]; // Q30 move32(); } } @@ -488,12 +488,12 @@ static ivas_error get_ls_conversion_matrix_fx( { IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) { - hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = ls_conversion_cicpX_mono_fx[k][ch_out]; + hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = ls_conversion_cicpX_mono_fx[k][ch_out]; // Q30 move32(); } ELSE { - hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = ls_conversion_cicpX_stereo_fx[k][ch_out]; + hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = ls_conversion_cicpX_stereo_fx[k][ch_out]; // Q30 move32(); } } @@ -520,7 +520,7 @@ static ivas_error get_ls_conversion_matrix_fx( { index = conversion_matrix_fx[k].index; move16(); - value = conversion_matrix_fx[k].value; + value = conversion_matrix_fx[k].value; // Q30 move16(); IF( index != 0 ) @@ -533,8 +533,9 @@ static ivas_error get_ls_conversion_matrix_fx( move16(); } ch_out = index % nchan_out; + move16(); - hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = value; + hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = value; // Q30 move32(); } } @@ -1026,14 +1027,14 @@ void ivas_ls_setup_conversion_fx( Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ const Word16 input_chans, /* i : number of input channels to the renderer */ const Word16 output_frame, /* i : frame length */ - Word32 *input[], /* i : LS input/output synthesis signal */ - Word32 *output[] /* i/o: LS input/output synthesis signal */ + Word32 *input[], /* i : LS input/output synthesis signal Q16*/ + Word32 *output[] /* i/o: LS input/output synthesis signal Q16*/ ) { Word16 chInIdx, chOutIdx, idx; LSSETUP_CONVERSION_HANDLE hLsSetUpConversion; Word32 dmxCoeff, tmpVal; - Word32 output_tmp[MAX_OUTPUT_CHANNELS][L_FRAME48k]; + Word32 output_tmp[MAX_OUTPUT_CHANNELS][L_FRAME48k]; // Q16 push_wmops( "LS_Renderer" ); @@ -1207,8 +1208,8 @@ void ivas_ls_setup_conversion_process_mdct_fx( FOR( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) { - x[chInIdx][0] = output[chInIdx]; - x[chInIdx][1] = output[chInIdx] + L_FRAME48k / 2; + x[chInIdx][0] = output[chInIdx]; // Q(q_output) + x[chInIdx][1] = output[chInIdx] + L_FRAME48k / 2; // Q(q_output) } /* Assign all the declared handles*/ @@ -1250,7 +1251,7 @@ void ivas_ls_setup_conversion_process_mdct_fx( FOR( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) { - dmxCoeff = hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx]; + dmxCoeff = hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx]; // Q30 move32(); test(); @@ -1265,10 +1266,10 @@ void ivas_ls_setup_conversion_process_mdct_fx( /* Convert the signal resolution to TCX20 */ /* initially, set pointers to input; if conversion occurs in (sub)frame, set to convertRes */ - pTmp[0] = x[chInIdx][0]; + pTmp[0] = x[chInIdx][0]; // Q(q_output) sig[0] = pTmp[0]; pTmp[1] = x[chInIdx][1]; - sig[1] = pTmp[1]; + sig[1] = pTmp[1]; // Q(q_output) /* convert (sub)frames to higher frequency resolution */ IF( NE_16( transform_type[chInIdx][0], TCX_20 ) ) @@ -1295,7 +1296,7 @@ void ivas_ls_setup_conversion_process_mdct_fx( move32(); FOR( i = 1; i < frameSize - 1; i++ ) { - mdst[i] = L_sub( sig[0][i + 1], sig[0][i - 1] ); + mdst[i] = L_sub( sig[0][i + 1], sig[0][i - 1] ); // Q(q_output) } FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) @@ -1361,9 +1362,9 @@ void ivas_ls_setup_conversion_process_mdct_fx( move32(); dmxEnergy[bandIdx] = L_add( Mpy_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, dmxEnergy[bandIdx] ), Mpy_32_32( ( ONE_IN_Q31 - LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx] ) ); move32(); - hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx] = targetEnergy[bandIdx]; + hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx] = targetEnergy[bandIdx]; // exp( hLsSetUpConversion->te_prev_exp) (Q0 here) move32(); - hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx] = dmxEnergy[bandIdx]; + hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx] = dmxEnergy[bandIdx]; // exp( hLsSetUpConversion->dmx_prev_exp) (Q0) move32(); hLsSetUpConversion->te_prev_exp = 31; move16(); @@ -1399,7 +1400,7 @@ void ivas_ls_setup_conversion_process_mdct_fx( move16(); /* Compute Eq gains */ - ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy[bandIdx], &dmxEnergy[bandIdx], &eqGain ); + ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy[bandIdx], &dmxEnergy[bandIdx], &eqGain ); // Q(eqGain) = 30 FOR( binIdx = start; binIdx < stop; binIdx++ ) { x[chInIdx][0][binIdx] = Mpy_32_32( L_shl( x[chInIdx][0][binIdx], 1 ), eqGain ); // Q - 1 @@ -1870,15 +1871,16 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( { IF( NE_16( mct_chan_mode[idx], MCT_CHAN_MODE_IGNORE ) ) { - real_in_buffer_fx[add( i, i_mult( num_bands, idx ) )] = L_shr( sig_fx[idx][0][band], sub( max_e, x_e[idx][0] ) ); /*Setting the exponent to max_e*/ - imag_in_buffer_fx[add( i, i_mult( num_bands, idx ) )] = L_shr( mdst_fx[idx][band], sub( max_e, x_e[idx][0] ) ); /*Setting the exponent to max_e*/ + real_in_buffer_fx[i + ( num_bands * idx )] = L_shr( sig_fx[idx][0][band], sub( max_e, x_e[idx][0] ) ); /*Setting the exponent to max_e*/ + imag_in_buffer_fx[i + ( num_bands * idx )] = L_shr( mdst_fx[idx][band], sub( max_e, x_e[idx][0] ) ); /*Setting the exponent to max_e*/ move32(); move32(); } } } Word16 shift = 1; - FOR( i = 0; i < i_mult( num_bands, nchan_transport ); ++i ) + move16(); + FOR( i = 0; i < num_bands * nchan_transport; ++i ) { real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], shift ); move32(); @@ -1898,11 +1900,13 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { DMXEne_fx = 0; + move16(); set_zero_fx( cy_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); set_zero_fx( Nrqq_fx, MAX_OUTPUT_CHANNELS ); set_zero_fx( target_ch_ener_fx, MAX_OUTPUT_CHANNELS ); /* Step 1.2, get target channel energies for the transported format as in ivas_param_mc_get_mono_stereo_mixing_matrices(), Nrqq calculation */ ild_q_fx = hParamMC->icld_q_fx + imult1616( bandIdx, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); + move16(); FOR( chInIdx = 0; chInIdx < nchan_transport_format; chInIdx++ ) { Word32 ref_ener_fx = 0; @@ -1914,7 +1918,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( { ref_channel_idx = hParamMC->hMetadataPMC->ild_mapping_conf->ref_channel_idx[chInIdx][ref_channel_cnt]; move16(); - ref_ener_fx = L_add( ref_ener_fx, cx_fx[bandIdx][add( ref_channel_idx, i_mult( ref_channel_idx, nchan_transport ) )] ); /*Exponent=output_exp*/ + ref_ener_fx = L_add( ref_ener_fx, cx_fx[bandIdx][ref_channel_idx + ( ref_channel_idx * nchan_transport )] ); /*Exponent=output_exp*/ } Word32 temp; temp = BASOP_util_Pow2( L_mult0( ild_q_fx[chInIdx], 2721 /*log2(10)*(2^13)/10*/ ), exp_in, &exp_out ); @@ -1927,17 +1931,17 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( { FOR( i = 0; i < nchan_transport_format; i++ ) { - target_ch_ener_fx[chOutIdx] = L_add( target_ch_ener_fx[chOutIdx], L_shl( Mpy_32_32( Nrqq_fx[i], hParamMC->ls_conv_dmx_matrix_fx[add( chOutIdx, i_mult( i, nchan_out ) )] ), 1 ) ); /*output_exp + 2*/ + target_ch_ener_fx[chOutIdx] = L_add( target_ch_ener_fx[chOutIdx], L_shl( Mpy_32_32( Nrqq_fx[i], hParamMC->ls_conv_dmx_matrix_fx[chOutIdx + ( i * nchan_out )] ), 1 ) ); /*output_exp + 2*/ move32(); } - cy_fx[add( chOutIdx, i_mult( nchan_out, chOutIdx ) )] = target_ch_ener_fx[chOutIdx]; + cy_fx[chOutIdx + ( nchan_out * chOutIdx )] = target_ch_ener_fx[chOutIdx]; move32(); } /* Step 1.4 final target energy for the band would then be the sum over the diagonal of Cy*/ FOR( chOutIdx = 0; chOutIdx < nchan_out; chOutIdx++ ) { - targetEnergy_fx[bandIdx] = L_add( targetEnergy_fx[bandIdx], cy_fx[add( chOutIdx, i_mult( nchan_out, chOutIdx ) )] ); /*exp=output_exp+2*/ + targetEnergy_fx[bandIdx] = L_add( targetEnergy_fx[bandIdx], cy_fx[chOutIdx + ( nchan_out * chOutIdx )] ); /*exp=output_exp+2*/ move32(); } @@ -2066,7 +2070,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( FOR( binIdx = start_tcx5; binIdx < stop_tcx5; binIdx++ ) { - x_fx[chInIdx][subFrameIdx][add( binIdx, shr( frameSize, 2 ) )] = L_shl( Mult_32_32( x_fx[chInIdx][subFrameIdx][add( binIdx, shr( frameSize, 2 ) )], eqGain_fx ), 1 ); + x_fx[chInIdx][subFrameIdx][binIdx + ( frameSize >> 2 )] = L_shl( Mult_32_32( x_fx[chInIdx][subFrameIdx][binIdx + ( frameSize >> 2 )], eqGain_fx ), 1 ); move32(); } } @@ -2416,8 +2420,8 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( void ivas_lssetupconversion_process_param_mc_fx( Decoder_Struct *st_ivas, /* i/o: LS setup conversion renderer handle */ const Word16 num_timeslots, - Word32 Cldfb_RealBuffer_InOut[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i/o: LS signals */ - Word32 Cldfb_ImagBuffer_InOut[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i/o: LS signals */ + Word32 Cldfb_RealBuffer_InOut[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i/o: LS signals Q6*/ + Word32 Cldfb_ImagBuffer_InOut[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i/o: LS signals Q6*/ Word16 channel_active[MAX_CICP_CHANNELS] /* i : bitmap indicating which output channels are active */ ) { @@ -2463,15 +2467,15 @@ void ivas_lssetupconversion_process_param_mc_fx( { FOR( k = 0; k < hLsSetUpConversion->sfbCnt; ++k ) { - Cldfb_RealBuffer_InOut[i][slotIdx][k] = L_shl( Cldfb_RealBuffer_InOut[i][slotIdx][k], q_output ); - Cldfb_ImagBuffer_InOut[i][slotIdx][k] = L_shl( Cldfb_ImagBuffer_InOut[i][slotIdx][k], q_output ); + Cldfb_RealBuffer_InOut[i][slotIdx][k] = L_shl( Cldfb_RealBuffer_InOut[i][slotIdx][k], q_output ); // Q(6 + q_output) + Cldfb_ImagBuffer_InOut[i][slotIdx][k] = L_shl( Cldfb_ImagBuffer_InOut[i][slotIdx][k], q_output ); // Q(6 + q_output) } } /* copy buffers */ FOR( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) { - Copy32( Cldfb_RealBuffer_InOut[chInIdx][slotIdx], Cldfb_RealBuffer_tmp[chInIdx], CLDFB_NO_CHANNELS_MAX ); - Copy32( Cldfb_ImagBuffer_InOut[chInIdx][slotIdx], Cldfb_ImagBuffer_tmp[chInIdx], CLDFB_NO_CHANNELS_MAX ); + Copy32( Cldfb_RealBuffer_InOut[chInIdx][slotIdx], Cldfb_RealBuffer_tmp[chInIdx], CLDFB_NO_CHANNELS_MAX ); // Q(6 + q_output) + Copy32( Cldfb_ImagBuffer_InOut[chInIdx][slotIdx], Cldfb_ImagBuffer_tmp[chInIdx], CLDFB_NO_CHANNELS_MAX ); // Q(6 + q_output) } /* set the buffers to zero */ FOR( chOutIdx = 0; chOutIdx < outChannels; chOutIdx++ ) @@ -2488,7 +2492,7 @@ void ivas_lssetupconversion_process_param_mc_fx( { FOR( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) { - dmxCoeff = hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx]; + dmxCoeff = hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx]; // Q30 move32(); IF( dmxCoeff == 0 ) { @@ -2496,13 +2500,14 @@ void ivas_lssetupconversion_process_param_mc_fx( } ELSE { - channel_active[chOutIdx] |= 1; + channel_active[chOutIdx] = s_or( 1, channel_active[chOutIdx] ); + move16(); FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - tmpDMXSig = Mpy_32_32( L_shl_sat( dmxCoeff, 1 ), Cldfb_RealBuffer_tmp[chInIdx][bandIdx] ); + tmpDMXSig = Mpy_32_32( L_shl_sat( dmxCoeff, 1 ), Cldfb_RealBuffer_tmp[chInIdx][bandIdx] ); // Q(6 + q_output) Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx] = L_add( Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx], tmpDMXSig ); move32(); - targetEnergy[chOutIdx][bandIdx] = L_add( targetEnergy[chOutIdx][bandIdx], Mpy_32_32( tmpDMXSig, tmpDMXSig ) ); + targetEnergy[chOutIdx][bandIdx] = L_add( targetEnergy[chOutIdx][bandIdx], Mpy_32_32( tmpDMXSig, tmpDMXSig ) ); // Q((6 + q_output)*2 - 31) move32(); tmpDMXSig = Mpy_32_32( L_shl_sat( dmxCoeff, 1 ), Cldfb_ImagBuffer_tmp[chInIdx][bandIdx] ); @@ -2522,12 +2527,12 @@ void ivas_lssetupconversion_process_param_mc_fx( { FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - tmpReal = Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx]; + tmpReal = Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx]; // Q(6 + q_output) move32(); - tmpImag = Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx]; + tmpImag = Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx]; // Q(6 + q_output) move32(); - dmxEnergy[chOutIdx][bandIdx] = L_add( Mpy_32_32( tmpReal, tmpReal ), Mpy_32_32( tmpImag, tmpImag ) ); + dmxEnergy[chOutIdx][bandIdx] = L_add( Mpy_32_32( tmpReal, tmpReal ), Mpy_32_32( tmpImag, tmpImag ) ); // Q((6 + q_output)*2 - 31) move32(); } } @@ -2544,9 +2549,9 @@ void ivas_lssetupconversion_process_param_mc_fx( move32(); dmxEnergy[chOutIdx][bandIdx] = L_add( Mpy_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, dmxEnergy[chOutIdx][bandIdx] ), Mpy_32_32( L_sub( ONE_IN_Q31, LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), hLsSetUpConversion->dmxEnergyPrev_fx[chOutIdx][bandIdx] ) ); move32(); - hLsSetUpConversion->targetEnergyPrev_fx[chOutIdx][bandIdx] = targetEnergy[chOutIdx][bandIdx]; + hLsSetUpConversion->targetEnergyPrev_fx[chOutIdx][bandIdx] = targetEnergy[chOutIdx][bandIdx]; // Q0 move32(); - hLsSetUpConversion->dmxEnergyPrev_fx[chOutIdx][bandIdx] = dmxEnergy[chOutIdx][bandIdx]; + hLsSetUpConversion->dmxEnergyPrev_fx[chOutIdx][bandIdx] = dmxEnergy[chOutIdx][bandIdx]; // Q0 move32(); hLsSetUpConversion->te_prev_exp = 31; move16(); @@ -2560,9 +2565,9 @@ void ivas_lssetupconversion_process_param_mc_fx( { FOR( k = 0; k < hLsSetUpConversion->sfbCnt; ++k ) { - Cldfb_RealBuffer_InOut[i][slotIdx][k] = L_shr( Cldfb_RealBuffer_InOut[i][slotIdx][k], q_output ); + Cldfb_RealBuffer_InOut[i][slotIdx][k] = L_shr( Cldfb_RealBuffer_InOut[i][slotIdx][k], q_output ); // Q6 move32(); - Cldfb_ImagBuffer_InOut[i][slotIdx][k] = L_shr( Cldfb_ImagBuffer_InOut[i][slotIdx][k], q_output ); + Cldfb_ImagBuffer_InOut[i][slotIdx][k] = L_shr( Cldfb_ImagBuffer_InOut[i][slotIdx][k], q_output ); // Q6 move32(); } } @@ -2574,7 +2579,7 @@ void ivas_lssetupconversion_process_param_mc_fx( { FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy[chOutIdx][bandIdx], &dmxEnergy[chOutIdx][bandIdx], &EQ ); + ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy[chOutIdx][bandIdx], &dmxEnergy[chOutIdx][bandIdx], &EQ ); // Q(EQ) = Q30 Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx] = Mpy_32_32( L_shl( Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx], 1 ), EQ ); move32(); Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx] = Mpy_32_32( L_shl( Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx], 1 ), EQ ); diff --git a/lib_dec/ivas_pca_dec_fx.c b/lib_dec/ivas_pca_dec_fx.c index 7dd2e334c09251ae4c900102458e07e262057dd4..9765facd6a1a34ffc0aa9ee23f1b2559cefe8f54 100644 --- a/lib_dec/ivas_pca_dec_fx.c +++ b/lib_dec/ivas_pca_dec_fx.c @@ -47,22 +47,24 @@ static Word32 ivas_bitstream_read_int32_fx( Decoder_State *st0, - const Word16 bits ) + const Word16 bits /*Q0*/ +) { Word32 val; /* MSB */ - val = L_shl( get_next_indice_fx( st0, sub( bits, 16 ) ), 16 ); + val = L_shl( get_next_indice_fx( st0, sub( bits, 16 ) ), 16 ); /*Q0*/ /* + LSB */ - val = L_add( val, get_next_indice_fx( st0, 16 ) ); + val = L_add( val, get_next_indice_fx( st0, 16 ) ); /*Q0*/ return val; } static void pca_dec_reset_dquat_fx( - Word16 *ql_fx, - Word16 *qr_fx ) + Word16 *ql_fx, /*Q15*/ + Word16 *qr_fx /*Q15*/ +) { set16_fx( ql_fx, 0, IVAS_PCA_INTERP ); ql_fx[0] = MAX_16; @@ -79,9 +81,9 @@ static void pca_dec_reset_mem_eigvec_fx( { Word16 i; - FOR( i = 0; i < shr( IVAS_PCA_LEN_INTERP_EIG_DEC, 4 ); i++ ) + FOR( i = 0; i < ( IVAS_PCA_LEN_INTERP_EIG_DEC >> 4 ); i++ ) { - eye_matrix_fx( &hPCA->mem_eigVec_interp_fx[i_mult( 16, i )], FOA_CHANNELS, MAX_16 ); + eye_matrix_fx( &hPCA->mem_eigVec_interp_fx[( 16 * i )], FOA_CHANNELS, MAX_16 ); } return; @@ -89,11 +91,12 @@ static void pca_dec_reset_mem_eigvec_fx( static void pca_inv_transform_sub_fx( - Word16 *eigVec, - Word32 *transformed_data[], /* i : input/transformed audio channels */ - const Word16 start, - const Word16 len, - const Word16 n_channels ) + Word16 *eigVec, /*Q15*/ + Word32 *transformed_data[], /* i : input/transformed audio channels Q11*/ + const Word16 start, /*Q0*/ + const Word16 len, /*Q0*/ + const Word16 n_channels /*Q0*/ +) { Word16 i, j, k; Word32 temp, temp2; @@ -103,7 +106,7 @@ static void pca_inv_transform_sub_fx( { FOR( k = 0; k < n_channels; k++ ) { - buffer_data[k] = transformed_data[k][add( j, start )]; + buffer_data[k] = transformed_data[k][( j + start )]; /*Q11*/ move32(); } @@ -113,10 +116,10 @@ static void pca_inv_transform_sub_fx( move32(); FOR( i = 0; i < n_channels; i++ ) { - temp2 = Mpy_32_16_1( buffer_data[i], eigVec[add( k * IVAS_PCA_INTERP, i )] ); + temp2 = Mpy_32_16_1( buffer_data[i], eigVec[( k * IVAS_PCA_INTERP + i )] ); /*Q11*/ temp = L_add( temp, temp2 ); } - transformed_data[k][add( j, start )] = temp; + transformed_data[k][( j + start )] = temp; /*Q11*/ move32(); } } @@ -127,11 +130,12 @@ static void pca_inv_transform_sub_fx( static void pca_dec_inv_transform_fx( PCA_DEC_STATE *hPCA, - Word16 *ql_fx, - Word16 *qr_fx, - const Word16 n_samples, - const Word16 n_channels, - Word32 *decoded_data[] ) + Word16 *ql_fx, /*Q15*/ + Word16 *qr_fx, /*Q15*/ + const Word16 n_samples, /*Q0*/ + const Word16 n_channels, /*Q0*/ + Word32 *decoded_data[] /*Q11*/ +) { Word16 j; Word16 slot_len; @@ -141,12 +145,12 @@ static void pca_dec_inv_transform_fx( pca_interp_preproc_fx( hPCA->prev_ql_fx, hPCA->prev_qr_fx, ql_fx, qr_fx, IVAS_PCA_N_SLOTS, ql_interp_fx, qr_interp_fx ); - slot_len = idiv1616( n_samples, IVAS_PCA_N_SLOTS ); + slot_len = idiv1616( n_samples, IVAS_PCA_N_SLOTS ); /*Q0*/ FOR( j = 0; j < IVAS_PCA_N_SLOTS; j++ ) { /* convert from double quaternion to 4D matrix */ - dquat2mat_fx( &ql_interp_fx[4 * j], &qr_interp_fx[4 * j], &hPCA->mem_eigVec_interp_fx[add( 16 * j, IVAS_PCA_DELAY_CMP * 16 )] ); + dquat2mat_fx( &ql_interp_fx[4 * j], &qr_interp_fx[4 * j], &hPCA->mem_eigVec_interp_fx[( 16 * j + IVAS_PCA_DELAY_CMP * 16 )] ); pca_inv_transform_sub_fx( &hPCA->mem_eigVec_interp_fx[16 * j], decoded_data, slot_len * j, slot_len, n_channels ); } @@ -156,12 +160,13 @@ static void pca_dec_inv_transform_fx( static void pca_dec_update_dquat_fx( PCA_DEC_STATE *hPCA, - const Word16 *ql_fx, - const Word16 *qr_fx ) + const Word16 *ql_fx, /*Q15*/ + const Word16 *qr_fx /*Q15*/ +) { /* update state for next frame */ - Copy( qr_fx, hPCA->prev_qr_fx, IVAS_PCA_INTERP ); - Copy( ql_fx, hPCA->prev_ql_fx, IVAS_PCA_INTERP ); + Copy( qr_fx, hPCA->prev_qr_fx, IVAS_PCA_INTERP ); /*Q15*/ + Copy( ql_fx, hPCA->prev_ql_fx, IVAS_PCA_INTERP ); /*Q15*/ return; } @@ -197,16 +202,16 @@ void ivas_pca_read_bits_fx( PCA_DEC_STATE *hPCA ) { /*first bit in the PCA payload (first bit after 3 header bits) signals bypass/active*/ - hPCA->pca_bypass = get_next_indice_fx( st0, 1 ); + hPCA->pca_bypass = get_next_indice_fx( st0, 1 ); /*Q0*/ move16(); IF( EQ_16( hPCA->pca_bypass, PCA_MODE_INACTIVE ) ) { return; } - hPCA->index[0] = ivas_bitstream_read_int32_fx( st0, IVAS_PCA_QBITS - 1 ); + hPCA->index[0] = ivas_bitstream_read_int32_fx( st0, IVAS_PCA_QBITS - 1 ); /*Q0*/ move32(); - hPCA->index[1] = ivas_bitstream_read_int32_fx( st0, IVAS_PCA_QBITS ); + hPCA->index[1] = ivas_bitstream_read_int32_fx( st0, IVAS_PCA_QBITS ); /*Q0*/ move32(); return; @@ -220,18 +225,18 @@ void ivas_pca_read_bits_fx( void ivas_pca_dec_fx( PCA_DEC_STATE *hPCA, /* i/o: PCA decoder structure */ - const Word16 output_frame, /* i : output frame length */ - const Word16 n_channels, /* i : number of channels */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate */ - const Word16 bfi, /* i : bad frame indicator */ - Word32 *pcm_out_fx[] /* o : output audio channels */ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 n_channels, /* i : number of channels Q0*/ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate Q0*/ + const Word16 bfi, /* i : bad frame indicator Q0*/ + Word32 *pcm_out_fx[] /* o : output audio channels Q11*/ ) { - Word16 ql_fx[IVAS_PCA_INTERP], qr_fx[IVAS_PCA_INTERP]; + Word16 ql_fx[IVAS_PCA_INTERP], qr_fx[IVAS_PCA_INTERP]; /*Q15*/ Word16 pca_bypass; // todo : check if mem_eigVec_interp_fx values are being updated / add loop to update - Copy( &hPCA->mem_eigVec_interp_fx[IVAS_PCA_N_SLOTS * 16], hPCA->mem_eigVec_interp_fx, IVAS_PCA_DELAY_CMP * 16 ); + Copy( &hPCA->mem_eigVec_interp_fx[IVAS_PCA_N_SLOTS * 16], hPCA->mem_eigVec_interp_fx, IVAS_PCA_DELAY_CMP * 16 ); /*Q15*/ /* @@@TODO: check how ivas_total_brate is set if bfi == 1 */ // ToDo: and what happens in DTX where "ivas_total_brate" can be close to zero? @@ -255,12 +260,12 @@ void ivas_pca_dec_fx( } pca_dec_update_dquat_fx( hPCA, ql_fx, qr_fx ); - hPCA->prev_pca_bypass = add( hPCA->prev_pca_bypass, 1 ); + hPCA->prev_pca_bypass = add( hPCA->prev_pca_bypass, 1 ); /*Q0*/ move16(); if ( GT_16( hPCA->prev_pca_bypass, 2 ) ) { - hPCA->prev_pca_bypass = 2; + hPCA->prev_pca_bypass = 2; /*Q0*/ move16(); } @@ -270,12 +275,12 @@ void ivas_pca_dec_fx( IF( bfi == 0 ) { /* set PCA by-pass mode indicator */ - pca_bypass = hPCA->pca_bypass; + pca_bypass = hPCA->pca_bypass; /*Q0*/ move16(); } ELSE { - pca_bypass = hPCA->prev_pca_bypass; + pca_bypass = hPCA->prev_pca_bypass; /*Q0*/ move16(); } @@ -295,9 +300,9 @@ void ivas_pca_dec_fx( pca_dec_update_dquat_fx( hPCA, ql_fx, qr_fx ); - hPCA->prev_pca_bypass = add( hPCA->prev_pca_bypass, 1 ); + hPCA->prev_pca_bypass = add( hPCA->prev_pca_bypass, 1 ); /*Q0*/ move16(); - hPCA->prev_pca_bypass = s_min( hPCA->prev_pca_bypass, 2 ); + hPCA->prev_pca_bypass = s_min( hPCA->prev_pca_bypass, 2 ); /*Q0*/ move16(); return; // exit happens here } @@ -311,8 +316,8 @@ void ivas_pca_dec_fx( { /* freeze */ // todo : check if update of prev_ql_fx is required - Copy( hPCA->prev_ql_fx, ql_fx, IVAS_PCA_INTERP ); - Copy( hPCA->prev_qr_fx, qr_fx, IVAS_PCA_INTERP ); + Copy( hPCA->prev_ql_fx, ql_fx, IVAS_PCA_INTERP ); /*Q15*/ + Copy( hPCA->prev_qr_fx, qr_fx, IVAS_PCA_INTERP ); /*Q15*/ } pca_dec_inv_transform_fx( hPCA, ql_fx, qr_fx, output_frame, n_channels, pcm_out_fx ); diff --git a/lib_dec/ivas_post_proc.c b/lib_dec/ivas_post_proc.c index 912c941932341f59b7d253df63ed2dedf444e24e..b98b5a6b9dcda92d47880eed5a7ba68b6aa094e4 100644 --- a/lib_dec/ivas_post_proc.c +++ b/lib_dec/ivas_post_proc.c @@ -153,11 +153,11 @@ void ivas_post_proc( void ivas_post_proc_fx( SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word16 n, /* i : channel number */ - Word32 synth[], /* i/o: output synthesis signal */ - Word32 *output[CPE_CHANNELS], /* i/o: output synthesis signal */ - const Word16 output_frame, /* i : output frame length */ - const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ + const Word16 n, /* i : channel number Q0*/ + Word32 synth[], /* i/o: output synthesis signal Q11*/ + Word32 *output[CPE_CHANNELS], /* i/o: output synthesis signal output_q*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC Q0*/ Word16 output_q ) { Word16 k; @@ -198,7 +198,7 @@ void ivas_post_proc_fx( ELSE { /* set delay */ - delay_comp = NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ); /*Q0*/ move16(); test(); @@ -207,13 +207,13 @@ void ivas_post_proc_fx( test(); IF( EQ_16( EQ_16( sts[n]->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ), 0 ) && NE_16( sts[n]->element_mode, IVAS_CPE_MDCT ) ) { - Copy32( sts[n]->delay_buf_out32_fx, sts[n]->hTcxDec->FBTCXdelayBuf_32, delay_comp ); + Copy32( sts[n]->delay_buf_out32_fx, sts[n]->hTcxDec->FBTCXdelayBuf_32, delay_comp ); /*Q11*/ } ELSE IF( sba_dirac_stereo_flag && EQ_16( sts[n]->element_mode, IVAS_CPE_MDCT ) ) { - Word16 numZeros = (Word16) ( NS2SA_FX2( output_Fs, N_ZERO_MDCT_NS ) ); + Word16 numZeros = (Word16) ( NS2SA_FX2( output_Fs, N_ZERO_MDCT_NS ) ); /*Q0*/ move16(); - Copy32( sts[n]->hHQ_core->oldOut_fx + numZeros, sts[n]->hTcxDec->FBTCXdelayBuf_32, delay_comp ); + Copy32( sts[n]->hHQ_core->oldOut_fx + numZeros, sts[n]->hTcxDec->FBTCXdelayBuf_32, delay_comp ); /*Q11*/ } tcx_ltp_post32( sts[n], hTcxLtpDec, sts[n]->core, output_frame, add( NS2SA_FX2( output_Fs, ACELP_LOOK_NS ), delay_comp ), synth, sts[n]->hTcxDec->FBTCXdelayBuf_32, output_q ); @@ -224,7 +224,7 @@ void ivas_post_proc_fx( { Word16 pit_res_max_past_tmp; - pit_res_max_past_tmp = sts[0]->pit_res_max_past; + pit_res_max_past_tmp = sts[0]->pit_res_max_past; /*Q0*/ move16(); FOR( k = 0; k < hCPE->nchan_out; k++ ) { @@ -236,16 +236,16 @@ void ivas_post_proc_fx( { hTcxLtpDec = hCPE->hStereoDft->hTcxLtpDec; /* copy LTP side-info of downmix channel also to right channel struct */ - hTcxLtpDec->tcxltp = sts[0]->hTcxLtpDec->tcxltp; + hTcxLtpDec->tcxltp = sts[0]->hTcxLtpDec->tcxltp; /*Q0*/ move16(); - hTcxLtpDec->tcxltp_gain = sts[0]->hTcxLtpDec->tcxltp_gain; + hTcxLtpDec->tcxltp_gain = sts[0]->hTcxLtpDec->tcxltp_gain; /*Q15*/ move16(); - hTcxLtpDec->tcxltp_pitch_int = sts[0]->hTcxLtpDec->tcxltp_pitch_int; + hTcxLtpDec->tcxltp_pitch_int = sts[0]->hTcxLtpDec->tcxltp_pitch_int; /*Q0*/ move16(); - hTcxLtpDec->tcxltp_pitch_fr = sts[0]->hTcxLtpDec->tcxltp_pitch_fr; + hTcxLtpDec->tcxltp_pitch_fr = sts[0]->hTcxLtpDec->tcxltp_pitch_fr; /*Q0*/ move16(); /* revert update of pit_res_max_past to have correct value also in right channel */ - sts[0]->pit_res_max_past = pit_res_max_past_tmp; + sts[0]->pit_res_max_past = pit_res_max_past_tmp; /*Q0*/ move16(); } @@ -277,13 +277,13 @@ void ivas_post_proc_fx( #ifdef IVAS_FLOAT_FIXED void stereo_dft_dec_core_switching_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 output_fx[], /* i/o: synthesis @internal Fs */ - Word32 synth_fx[], /* i/o: synthesis @output Fs */ - Word32 hb_synth_fx[], /* i/o: hb synthesis */ - Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ - const Word16 output_frame, /* i : output frame length */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB FOR DFT Stereo */ - const Word16 sba_dirac_stereo_dtx_flag, /* i : DTX indicator FOR SBA DirAC stereo */ + Word32 output_fx[], /* i/o: synthesis @internal Fs q*/ + Word32 synth_fx[], /* i/o: synthesis @output Fs q*/ + Word32 hb_synth_fx[], /* i/o: hb synthesis q*/ + Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers q_DFT*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB FOR DFT Stereo Q0*/ + const Word16 sba_dirac_stereo_dtx_flag, /* i : DTX indicator FOR SBA DirAC stereo Q0*/ Word16 *q, Word16 *q_DFT ) { @@ -301,31 +301,31 @@ void stereo_dft_dec_core_switching_fx( Word32 synth_tmp_fx[L_FRAME48k]; - st = hCPE->hCoreCoder[0]; /* in DFT stereo, only M channel is decoded by the CoreCoder */ - output_Fs = st->output_Fs; + st = hCPE->hCoreCoder[0]; /* in DFT stereo, only M channel is decoded by the CoreCoder */ + output_Fs = st->output_Fs; /*Q0*/ move32(); - L_frameTCX = st->hTcxDec->L_frameTCX; + L_frameTCX = st->hTcxDec->L_frameTCX; /*Q0*/ move16(); /*TBE*/ - delay_tdbwe = NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ); + delay_tdbwe = NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ); /*Q0*/ move16(); - delay_dft_dec = NS2SA_FX2( output_Fs, STEREO_DFT_DELAY_DEC_BWE_NS ); + delay_dft_dec = NS2SA_FX2( output_Fs, STEREO_DFT_DELAY_DEC_BWE_NS ); /*Q0*/ move16(); - delay_dft_dec_lb = NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT_DELAY_DEC_BWE_NS ); + delay_dft_dec_lb = NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT_DELAY_DEC_BWE_NS ); /*Q0*/ move16(); /* TCX/ACELP/HQ-CORE->TCX */ - tmps = NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ); /*cross-fading size @ FB*/ + tmps = NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ); /*cross-fading size @ FB*/ /*Q0*/ move16(); - delay_comp = NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), DELAY_BWE_TOTAL_NS ); /*cross-fading size @ LB*/ + delay_comp = NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), DELAY_BWE_TOTAL_NS ); /*cross-fading size @ LB*/ /*Q0*/ move16(); calc_inv = W_shl( 1, 31 ); // Memory Tables ////////////////////////////////////////////////////////////////////////////// - Word32 mem_len_inv_tbl[] = { 85899345, 42949672, 28633115, 21474836, 17179869, 14316557 }; - Word32 delay_comp_inv_tbl[] = { 2147483647, 306783378, 153391689, 97612893, 74051160, 58040098, 48806446, 42107522, 36398027, 32537631, 29020049 }; + Word32 mem_len_inv_tbl[] = { 85899345, 42949672, 28633115, 21474836, 17179869, 14316557 }; /*Q31*/ + Word32 delay_comp_inv_tbl[] = { 2147483647, 306783378, 153391689, 97612893, 74051160, 58040098, 48806446, 42107522, 36398027, 32537631, 29020049 }; /*Q31*/ /////////////////////////////////////////////////////////////////////////////////////////////// test(); @@ -338,7 +338,7 @@ void stereo_dft_dec_core_switching_fx( test(); test(); - if ( ( st->prev_bfi != 0 ) && EQ_16( ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ), 0 ) ) + IF( ( st->prev_bfi != 0 ) && EQ_16( ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ), 0 ) ) { /* last_core needed FOR correctly decoding ACELP->TCX/HQ switching frames in ivas_core_dec(). In the following steps the decoder needs to consider IF the core was changed due to a lost frame to apply the correct transition */ @@ -369,7 +369,7 @@ void stereo_dft_dec_core_switching_fx( IF( ( ( ( st->last_core != ACELP_CORE ) || ( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( sba_dirac_stereo_dtx_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */ { /* In case of a TCX to ACELP switch next frame */ - Copy32( &output_fx[st->L_frame - NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); + Copy32( &output_fx[st->L_frame - NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*q*/ /* BPF */ test(); @@ -377,7 +377,7 @@ void stereo_dft_dec_core_switching_fx( IF( st->p_bpf_noise_buf_32 && NE_16( st->core, HQ_CORE ) ) { #ifdef MSAN_FIX - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); /*q*/ #endif stereo_dft_dec_analyze_fx( hCPE, st->p_bpf_noise_buf_32, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 2, 0, q, q_DFT ); } @@ -395,25 +395,25 @@ void stereo_dft_dec_core_switching_fx( test(); IF( LE_32( st->last_core_brate, SID_2k40 ) && LE_16( st->element_mode, IVAS_SCE ) ) { - Word16 mem_len = NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); + Word16 mem_len = NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); /*Q0*/ move16(); - Word32 mem_len_inv = mem_len_inv_tbl[idiv1616( mem_len, 25 )]; + Word32 mem_len_inv = mem_len_inv_tbl[( mem_len / 25 )]; move32(); Word16 qmem_len = norm_l( mem_len ); Word32 mem_len_fx = L_shl( mem_len, qmem_len ); FOR( i = 0; i < mem_len; i++ ) { - hCPE->input_mem_fx[0][i] = Mpy_32_32( hCPE->input_mem_fx[0][i], L_sub( mem_len_fx, L_shl( i, qmem_len ) ) ); + hCPE->input_mem_fx[0][i] = Mpy_32_32( hCPE->input_mem_fx[0][i], L_sub( mem_len_fx, L_shl( i, qmem_len ) ) ); /*Q11 + qmem_len - 31*/ move32(); - hCPE->input_mem_fx[0][i] = L_shl( Mpy_32_32( hCPE->input_mem_fx[0][i], mem_len_inv ), sub( Q31, qmem_len ) ); + hCPE->input_mem_fx[0][i] = L_shl( Mpy_32_32( hCPE->input_mem_fx[0][i], mem_len_inv ), sub( Q31, qmem_len ) ); /*Q11*/ move32(); } /* Update FB input buff with hb synth FOR last delay_tdbwe sampled */ FOR( i = 0; i < delay_tdbwe; i++ ) { - hCPE->input_mem_fx[0][add( sub( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_tdbwe ), i )] = - L_add( hCPE->input_mem_fx[0][NS2SA_FX2( L_add( L_sub( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_tdbwe ), i )], hb_synth_fx[i] ); + hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_tdbwe ) + i )] = + L_add( hCPE->input_mem_fx[0][NS2SA_FX2( L_add( L_sub( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_tdbwe ), i )], hb_synth_fx[i] ); /*Q11*/ move32(); } } @@ -422,21 +422,21 @@ void stereo_dft_dec_core_switching_fx( /* Update FB input buff with hb synth FOR last delay_tdbwe sampled */ FOR( i = 0; i < delay_tdbwe; i++ ) { - hCPE->input_mem_fx[0][add( sub( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_tdbwe ), i )] = hb_synth_fx[i]; + hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_tdbwe ) + i )] = hb_synth_fx[i]; /*Q11*/ move32(); } } /* cross-fading between (delayed) TBE and FB-TCX over 2.3125ms */ - Copy32( synth_fx, synth_tmp_fx, output_frame ); + Copy32( synth_fx, synth_tmp_fx, output_frame ); /*q*/ Word16 qtmps = norm_l( tmps ); Word32 tmps_fx = L_shl( tmps, qtmps ); Word32 tmps_inv = (Word32) ( calc_inv / tmps ); FOR( i = 0; i < tmps; i++ ) { - synth_tmp_fx[i] = L_add( Mpy_32_32( hb_synth_fx[add( i, delay_tdbwe )], L_sub( tmps_fx, L_shl( i, qtmps ) ) ), Mpy_32_32( synth_fx[i], L_shl( i, qtmps ) ) ); + synth_tmp_fx[i] = L_add( Mpy_32_32( hb_synth_fx[( i + delay_tdbwe )], L_sub( tmps_fx, L_shl( i, qtmps ) ) ), Mpy_32_32( synth_fx[i], L_shl( i, qtmps ) ) ); /*q + qtmps - 31*/ move32(); - synth_tmp_fx[i] = L_shl( Mpy_32_32( synth_tmp_fx[i], tmps_inv ), sub( 31, qtmps ) ); + synth_tmp_fx[i] = L_shl( Mpy_32_32( synth_tmp_fx[i], tmps_inv ), sub( 31, qtmps ) ); /*q*/ move32(); } @@ -447,25 +447,25 @@ void stereo_dft_dec_core_switching_fx( { IF( EQ_16( hCPE->hStereoDft->hConfig->res_pred_mode, STEREO_DFT_RESPRED_ESF ) ) { - Copy32( output_fx, tcx_core_buf_fx, L_FRAME16k ); + Copy32( output_fx, tcx_core_buf_fx, L_FRAME16k ); /*q*/ } /* fading-out LB-TCX/ACELP */ Word16 qdelay_comp = norm_l( delay_comp ); - Word32 delay_comp_inv = delay_comp_inv_tbl[idiv1616( delay_comp, 7 )]; + Word32 delay_comp_inv = delay_comp_inv_tbl[( delay_comp / 7 )]; /*Q31*/ move32(); Word32 delay_comp_fx = L_shl( delay_comp, qdelay_comp ); FOR( i = 0; i < delay_comp; i++ ) { - output_fx[i] = Mpy_32_32( output_fx[i], L_sub( delay_comp_fx, L_shl( i, qdelay_comp ) ) ); + output_fx[i] = Mpy_32_32( output_fx[i], L_sub( delay_comp_fx, L_shl( i, qdelay_comp ) ) ); /*q + qdelay_comp - 31*/ move32(); - output_fx[i] = L_shl( Mpy_32_32( output_fx[i], delay_comp_inv ), sub( Q31, qdelay_comp ) ); + output_fx[i] = L_shl( Mpy_32_32( output_fx[i], delay_comp_inv ), sub( Q31, qdelay_comp ) ); /*q*/ move32(); } /* In case of TCX frames, output LB TCX is zeroed out until the end but in case of an TCX->ACELP switch, this memory is needed, hence it is backed up */ /* Unlike the case when DFT32MS is disabled, there is only 1 DFT analysis window, hence in the TCX frame we don't want to do a DFT analysis FOR LB TCX but in a potential ACELP frame, we want the memories of the LB TCX FOR the last OLA samples so that HB analysis can be skipped */ - Copy32( &output_fx[st->L_frame - NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); + Copy32( &output_fx[st->L_frame - NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*q*/ /*zero the rest FOR avoiding adding contribution except the last samples which are not considered in DFT analysis (potentially used in next ACELP frame)*/ IF( GT_32( st->last_core_brate, SID_2k40 ) ) @@ -510,16 +510,16 @@ void stereo_dft_dec_core_switching_fx( IF( sba_dirac_stereo_dtx_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) { Word16 nZeros; - nZeros = (Word16) ( NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ) ); + nZeros = (Word16) ( NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ) ); /*Q0*/ move16(); - delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); /*Q0*/ move16(); - Copy32( &st->hHQ_core->oldOut_fx[sub( nZeros, add( delay_comp, NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ) )], hCPE->input_mem_fx[0], NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); - Copy32( synth_fx, synth_tmp_fx, output_frame ); + Copy32( &st->hHQ_core->oldOut_fx[( nZeros - ( delay_comp + NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ) )], hCPE->input_mem_fx[0], NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*Q11*/ + Copy32( synth_fx, synth_tmp_fx, output_frame ); /*q*/ Word16 mem_len; - mem_len = NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); + mem_len = NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); /*Q0*/ move16(); Word16 qmem_len = norm_l( mem_len ); @@ -528,9 +528,9 @@ void stereo_dft_dec_core_switching_fx( move32(); FOR( i = 0; i < mem_len; i++ ) { - hCPE->input_mem_LB_fx[0][i] = Mpy_32_32( hCPE->input_mem_LB_fx[0][i], L_sub( mem_len_fx, L_shl( i, qmem_len ) ) ); + hCPE->input_mem_LB_fx[0][i] = Mpy_32_32( hCPE->input_mem_LB_fx[0][i], L_sub( mem_len_fx, L_shl( i, qmem_len ) ) ); /*Q11 + qmem_len - 31*/ move32(); - hCPE->input_mem_LB_fx[0][i] = L_shl( Mpy_32_32( hCPE->input_mem_LB_fx[0][i], mem_len_inv ), sub( Q31, qmem_len ) ); + hCPE->input_mem_LB_fx[0][i] = L_shl( Mpy_32_32( hCPE->input_mem_LB_fx[0][i], mem_len_inv ), sub( Q31, qmem_len ) ); /*Q11*/ move32(); } set32_fx( output_fx, 0, st->L_frame ); @@ -541,7 +541,7 @@ void stereo_dft_dec_core_switching_fx( IF( st->p_bpf_noise_buf_32 ) { #ifdef MSAN_FIX - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); /*q*/ #endif stereo_dft_dec_analyze_fx( hCPE, st->p_bpf_noise_buf_32, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0, q, q_DFT ); } @@ -559,11 +559,11 @@ void stereo_dft_dec_core_switching_fx( Word32 delay_dft_dec_lb_inv = (Word32) ( calc_inv / delay_dft_dec_lb ); FOR( i = 0; i < delay_dft_dec_lb; i++ ) { - hCPE->input_mem_LB_fx[0][add( sub( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec_lb ), i )] = - Mpy_32_32( hCPE->input_mem_LB_fx[0][add( sub( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec_lb ), i )], L_shl( i, qdelay_dft_dec_lb ) ); + hCPE->input_mem_LB_fx[0][( ( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )] = + Mpy_32_32( hCPE->input_mem_LB_fx[0][( ( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )], L_shl( i, qdelay_dft_dec_lb ) ); /*Q11 + qdelay_dft_dec_lb -31*/ move32(); - hCPE->input_mem_LB_fx[0][add( sub( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec_lb ), i )] = - L_shl( Mpy_32_32( hCPE->input_mem_LB_fx[0][add( sub( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec_lb ), i )], delay_dft_dec_lb_inv ), sub( Q31, qdelay_dft_dec_lb ) ); + hCPE->input_mem_LB_fx[0][( ( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )] = + L_shl( Mpy_32_32( hCPE->input_mem_LB_fx[0][( ( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )], delay_dft_dec_lb_inv ), sub( Q31, qdelay_dft_dec_lb ) ); /*Q11*/ move32(); } stereo_dft_dec_analyze_fx( hCPE, output_fx, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, q, q_DFT ); @@ -572,13 +572,13 @@ void stereo_dft_dec_core_switching_fx( IF( st->p_bpf_noise_buf_32 ) { #ifdef MSAN_FIX - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); /*q*/ #endif stereo_dft_dec_analyze_fx( hCPE, st->p_bpf_noise_buf_32, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0, q, q_DFT ); } /* Fading-in TD-BWE, Fading-out FB-TCX*/ - Copy32( synth_fx, synth_tmp_fx, output_frame ); + Copy32( synth_fx, synth_tmp_fx, output_frame ); /*q*/ IF( NE_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { Word16 qdelay_dft_dec = norm_l( delay_dft_dec ); @@ -586,20 +586,20 @@ void stereo_dft_dec_core_switching_fx( Word32 delay_dft_dec_fx = L_shl( delay_dft_dec, qdelay_dft_dec ); FOR( i = 0; i < delay_dft_dec; i++ ) /* 1.25 ms of hb_synth fade-in and TCX fade-out */ { - hCPE->input_mem_fx[0][add( sub( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec ), i )] = L_add( - Mpy_32_32( hb_synth_fx[add( sub( delay_tdbwe, delay_dft_dec ), i )], L_shl( i, qdelay_dft_dec ) ), - Mpy_32_32( hCPE->input_mem_fx[0][add( sub( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec ), i )], L_sub( delay_dft_dec_fx, L_shl( i, qdelay_dft_dec ) ) ) ); + hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec ) + i )] = L_add( + Mpy_32_32( hb_synth_fx[( ( delay_tdbwe - delay_dft_dec ) + i )], L_shl( i, qdelay_dft_dec ) ), + Mpy_32_32( hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec ) + i )], L_sub( delay_dft_dec_fx, L_shl( i, qdelay_dft_dec ) ) ) ); /*Q11 + qdelay_dft_dec - 31*/ move32(); - hCPE->input_mem_fx[0][add( sub( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec ), i )] = L_shl( - Mpy_32_32( hCPE->input_mem_fx[0][add( sub( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec ), i )], delay_dft_dec_inv ), - sub( Q31, qdelay_dft_dec ) ); + hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec ) + i )] = L_shl( + Mpy_32_32( hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec ) + i )], delay_dft_dec_inv ), + sub( Q31, qdelay_dft_dec ) ); /*Q11*/ move32(); } FOR( i = 0; i < delay_dft_dec; i++ ) /* 1.25 ms of hb_synth fade out. ICBWE fade in performed in time domain here */ { - synth_tmp_fx[i] = Mpy_32_32( hb_synth_fx[add( sub( delay_tdbwe, delay_dft_dec ), i )], L_sub( delay_dft_dec_fx, L_shl( i, qdelay_dft_dec ) ) ); + synth_tmp_fx[i] = Mpy_32_32( hb_synth_fx[( ( delay_tdbwe - delay_dft_dec ) + i )], L_sub( delay_dft_dec_fx, L_shl( i, qdelay_dft_dec ) ) ); /*q + qdelay_dft_dec - 31*/ move32(); - synth_tmp_fx[i] = L_shl( Mpy_32_32( synth_tmp_fx[i], delay_dft_dec_inv ), sub( Q31, qdelay_dft_dec ) ); + synth_tmp_fx[i] = L_shl( Mpy_32_32( synth_tmp_fx[i], delay_dft_dec_inv ), sub( Q31, qdelay_dft_dec ) ); /*q*/ move32(); } @@ -649,7 +649,7 @@ void stereo_dft_dec_core_switching_fx( IF( st->p_bpf_noise_buf_32 ) { #ifdef MSAN_FIX - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); /*q*/ #endif stereo_dft_dec_analyze_fx( hCPE, st->p_bpf_noise_buf_32, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0, q, q_DFT ); } @@ -680,14 +680,14 @@ void stereo_dft_dec_core_switching_fx( { ap_fade_len = STEREO_DFT_ALLPASS_FADELEN_12k8; move16(); - ap_fade_len_inv = 67108864; + ap_fade_len_inv = 67108864; /*1/32 in Q31*/ move32(); } ELSE { ap_fade_len = STEREO_DFT_ALLPASS_FADELEN_16k; move16(); - ap_fade_len_inv = 53687091; + ap_fade_len_inv = 53687091; /*1/40 in Q31*/ move32(); } @@ -701,10 +701,10 @@ void stereo_dft_dec_core_switching_fx( test(); IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) || ( EQ_16( st->bfi, 1 ) && EQ_16( st->core, ACELP_CORE ) && EQ_16( st->con_tcx, 1 ) ) ) { - Word16 numZeros = (Word16) ( NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS ) ); + Word16 numZeros = (Word16) ( NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS ) ); /*Q0*/ Word32 tmp_fade_fx[max( STEREO_DFT_ALLPASS_FADELEN_12k8, STEREO_DFT_ALLPASS_FADELEN_16k )]; - Copy32( st->hHQ_core->old_outLB_fx + numZeros, hCPE->hStereoDft->ap_fade_mem_fx, ap_fade_len ); + Copy32( st->hHQ_core->old_outLB_fx + numZeros, hCPE->hStereoDft->ap_fade_mem_fx, ap_fade_len ); /*st->hHQ_core->q_old_outLB_fx*/ hCPE->hStereoDft->q_ap_fade_mem_fx = st->hHQ_core->q_old_outLB_fx; move16(); @@ -715,45 +715,45 @@ void stereo_dft_dec_core_switching_fx( test(); IF( EQ_16( st->last_core, ACELP_CORE ) && !( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) && !st->tcxonly ) { - Copy32( tcx_core_buf_fx, pAp_input_fx, st->L_frame ); + Copy32( tcx_core_buf_fx, pAp_input_fx, st->L_frame ); /*q*/ } ELSE { - Copy32( output_fx, pAp_input_fx, st->L_frame ); + Copy32( output_fx, pAp_input_fx, st->L_frame ); /*q*/ } IF( EQ_16( st->last_core, ACELP_CORE ) && EQ_16( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ), 0 ) && !st->tcxonly ) /* ACELP -> TCX/HQ-Core */ { - Copy32( tcx_core_buf_fx, tmp_fade_fx, ap_fade_len ); + Copy32( tcx_core_buf_fx, tmp_fade_fx, ap_fade_len ); /*q*/ FOR( i = 0; i < ap_fade_len; i++ ) { pAp_input_fx[i] = L_add( Mpy_32_32( pAp_input_fx[i], L_shl( i, qap_fade_len ) ), - Mpy_32_32( tmp_fade_fx[i], L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ) ); + Mpy_32_32( tmp_fade_fx[i], L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ) ); /*q + qap_fade_len - 31*/ move32(); - pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); + pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); /*q*/ move32(); } } } ELSE { - Copy32( output_fx, pAp_input_fx, st->L_frame ); - IF( NE_16( st->last_core, ACELP_CORE ) ) /* TCX/HQ-Core -> ACELP */ + Copy32( output_fx, pAp_input_fx, st->L_frame ); /*q*/ + IF( NE_16( st->last_core, ACELP_CORE ) ) /* TCX/HQ-Core -> ACELP */ { Word16 shift = sub( hCPE->hStereoDft->q_ap_fade_mem_fx, q_DFT[0] ); FOR( i = 0; i < ap_fade_len; i++ ) { pAp_input_fx[i] = L_add( Mpy_32_32( pAp_input_fx[i], L_shl( i, qap_fade_len ) ), - Mpy_32_32( L_shr( hCPE->hStereoDft->ap_fade_mem_fx[i], shift ), L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ) ); + Mpy_32_32( L_shr( hCPE->hStereoDft->ap_fade_mem_fx[i], shift ), L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ) ); /*q + qap_fade_len - 31*/ move32(); - pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); + pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); /*q*/ move32(); } } } - predelay = NS2SA_FX2( st->sr_core, DELAY_BWE_TOTAL_NS ); + predelay = NS2SA_FX2( st->sr_core, DELAY_BWE_TOTAL_NS ); /*Q0*/ move16(); /* apply predelay to have same overall filter delay FOR all cases */ @@ -771,9 +771,9 @@ void stereo_dft_dec_core_switching_fx( { FOR( i = 0; i < ap_fade_len; i++ ) { - pAp_input_fx[i] = Mpy_32_32( pAp_input_fx[i], L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ); + pAp_input_fx[i] = Mpy_32_32( pAp_input_fx[i], L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ); /*q + qap_fade_len - 31*/ move32(); - pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); + pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); /*q*/ move32(); } } @@ -785,9 +785,9 @@ void stereo_dft_dec_core_switching_fx( { FOR( i = 0; i < ap_fade_len; i++ ) { - pAp_input_fx[i] = Mpy_32_32( pAp_input_fx[i], L_shl( i, qap_fade_len ) ); + pAp_input_fx[i] = Mpy_32_32( pAp_input_fx[i], L_shl( i, qap_fade_len ) ); /*q + qap_fade_len - 31*/ move32(); - pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); + pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); /*q*/ move32(); } hCPE->hStereoDft->ap_wasTransient = 0; @@ -818,7 +818,7 @@ void stereo_dft_dec_core_switching_fx( test(); IF( !use_cldfb_for_dft || ( ( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) && EQ_16( st->cng_type, LP_CNG ) && EQ_16( st->extl, SWB_CNG ) && EQ_16( hCPE->nchan_out, 1 ) ) ) { - v_add_fx( synth_fx, hb_synth_fx, synth_fx, output_frame ); /* Use one channel TD-BWE FOR ECU analysis buffer */ + v_add_fx( synth_fx, hb_synth_fx, synth_fx, output_frame ); /* Use one channel TD-BWE FOR ECU analysis buffer */ /*q*/ } } diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index ecaf33f00a4c4f3ae645ff5f3261416f4d008d90..9625a39a80e7e402a4759c459a144a418f0bc0d7 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -123,9 +123,9 @@ static int16_t read_coherence_data( uint16_t *bitstream, int16_t *p_bit_pos, IVA /*! r: number of bits read */ Word16 ivas_qmetadata_dec_decode( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: hQMetaData handle */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, /* i/o: bitstream position */ - const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /* i/o: bitstream position Q0*/ + const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode Q0*/ ) { Word16 d, b, m; @@ -192,7 +192,7 @@ Word16 ivas_qmetadata_dec_decode( IF( hQMetaData->coherence_flag ) { /* read if coherence is zero */ - all_coherence_zero = bitstream[( *index )--]; + all_coherence_zero = bitstream[( *index )--]; /*Q0*/ move16(); bits_no_dirs_coh = add( bits_no_dirs_coh, 1 ); } @@ -202,20 +202,20 @@ Word16 ivas_qmetadata_dec_decode( IF( EQ_32( hQMetaData->no_directions, 2 ) ) { /* Read which bands have 2 directions */ - hQMetaData->q_direction[1].cfg.nbands = hQMetaData->numTwoDirBands; + hQMetaData->q_direction[1].cfg.nbands = hQMetaData->numTwoDirBands; /*Q0*/ move16(); set_c( (Word8 *) hQMetaData->twoDirBands, 0, hQMetaData->q_direction[0].cfg.nbands ); d = *index; move16(); - dif_p[0] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); + dif_p[0] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); /*Q0*/ move16(); - p[0] = dif_p[0]; + p[0] = dif_p[0]; /*Q0*/ move16(); hQMetaData->twoDirBands[p[0]] = 1; move16(); FOR( b = 1; b < hQMetaData->numTwoDirBands; b++ ) { - dif_p[b] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); + dif_p[b] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); /*Q0*/ move16(); p[b] = add( add( p[b - 1], dif_p[b] ), 1 ); move16(); @@ -240,7 +240,7 @@ Word16 ivas_qmetadata_dec_decode( { IF( EQ_16( hQMetaData->twoDirBands[b], 1 ) ) { - dfRatio_bits[dir2band] = ivas_get_df_ratio_bits_hodirac( hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] ); + dfRatio_bits[dir2band] = ivas_get_df_ratio_bits_hodirac( hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] ); /*Q0*/ move16(); dir2band = add( dir2band, 1 ); } @@ -260,13 +260,13 @@ Word16 ivas_qmetadata_dec_decode( { IF( EQ_16( hQMetaData->twoDirBands[b], 1 ) ) { - dfRatio_bits[dir2band] = ivas_get_df_ratio_bits( hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] ); + dfRatio_bits[dir2band] = ivas_get_df_ratio_bits( hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] ); /*Q0*/ move16(); dir2band = add( dir2band, 1 ); } } - bits_diff_sum = add( bits_diff_sum, ivas_qmetadata_entropy_decode_df_ratio( bitstream, index, &( hQMetaData->q_direction[1] ), dfRatio_bits ) ); + bits_diff_sum = add( bits_diff_sum, ivas_qmetadata_entropy_decode_df_ratio( bitstream, index, &( hQMetaData->q_direction[1] ), dfRatio_bits ) ); /*Q0*/ } } @@ -286,14 +286,14 @@ Word16 ivas_qmetadata_dec_decode( diffRatio_fx = diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]]; // Q30 move32(); - dfRatio_qsteps = shl( 1, dfRatio_bits[dir2band] ); + dfRatio_qsteps = shl( 1, dfRatio_bits[dir2band] ); /*1 << dfRatio_bits[dir2band]*/ /* already encoded as total and ratios in HO-DirAC */ IF( hodirac_flag ) { dfRatio_fx = usdequant_fx( hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0], 0 /* Q15 */, inv_dfRatio_qsteps[dfRatio_qsteps] ); // Q15 dir1ratio_fx = L_sub( ONE_IN_Q30, diffRatio_fx ); - dir2ratio_fx = L_shl( (Word32) dfRatio_fx, Q15 ); + dir2ratio_fx = L_shl( (Word32) dfRatio_fx, Q15 ); /*Q30*/ } ELSE { @@ -305,17 +305,17 @@ Word16 ivas_qmetadata_dec_decode( /* Requantize the 1 - dirRatio separately for each direction to obtain inverted dirRatio index. These are used in further decoding. */ - hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] = masa_sq_fx( L_sub( ONE_IN_Q30, dir1ratio_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] = masa_sq_fx( L_sub( ONE_IN_Q30, dir1ratio_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); IF( hodirac_flag ) { Word16 tmp_fx; - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0] = usquant_fx( extract_h( dir2ratio_fx ), &tmp_fx, 0, INV_DIRAC_DIFFUSE_LEVELS_Q13, DIRAC_DIFFUSE_LEVELS ); + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0] = usquant_fx( extract_h( dir2ratio_fx ), &tmp_fx, 0, INV_DIRAC_DIFFUSE_LEVELS_Q13, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); } ELSE { - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0] = masa_sq_fx( L_sub( ONE_IN_Q30, dir2ratio_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0] = masa_sq_fx( L_sub( ONE_IN_Q30, dir2ratio_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); } @@ -323,15 +323,15 @@ Word16 ivas_qmetadata_dec_decode( { hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = dir1ratio_fx; // Q30 move32(); - hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); } FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[m] = dir2ratio_fx; + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[m] = dir2ratio_fx; /*Q30*/ move32(); - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[m] = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0]; + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[m] = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0]; /*Q0*/ move16(); } @@ -340,13 +340,13 @@ Word16 ivas_qmetadata_dec_decode( ELSE { /* 1dir band */ - hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]] ); + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]] ); /*Q30*/ move32(); FOR( m = 1; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0]; /*Q30*/ move32(); - hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); } } @@ -357,13 +357,13 @@ Word16 ivas_qmetadata_dec_decode( /* With 1dir band, the decoded index is directly diffuseness and we can decode to direct-to-total ratio with 1 - diff. */ FOR( b = hQMetaData->q_direction[0].cfg.start_band; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]] ); + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]] ); /*Q30*/ move32(); FOR( m = 1; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0]; /*Q30*/ move32(); - hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); } } @@ -384,18 +384,18 @@ Word16 ivas_qmetadata_dec_decode( { Word16 index_dirRatio1Inv, index_dirRatio2Inv, index_dirRatio1Inv_mod, index_dirRatio2Inv_mod; - index_dirRatio1Inv = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + index_dirRatio1Inv = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); - index_dirRatio2Inv = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0]; + index_dirRatio2Inv = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0]; /*Q0*/ move16(); masa_compensate_two_dir_energy_ratio_index_fx( index_dirRatio1Inv, index_dirRatio2Inv, &index_dirRatio1Inv_mod, &index_dirRatio2Inv_mod, hodirac_flag ); FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = index_dirRatio1Inv_mod; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = index_dirRatio1Inv_mod; /*Q0*/ move16(); - hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_direction_masa[index_dirRatio1Inv_mod]; + hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_direction_masa[index_dirRatio1Inv_mod]; /*Q0*/ move16(); bits_dir_raw_pre[0] = add( bits_dir_raw_pre[0], hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] ); move16(); @@ -403,9 +403,9 @@ Word16 ivas_qmetadata_dec_decode( FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index_mod[m] = index_dirRatio2Inv_mod; + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index_mod[m] = index_dirRatio2Inv_mod; /*Q0*/ move16(); - hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[m] = bits_direction_masa[index_dirRatio2Inv_mod]; + hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[m] = bits_direction_masa[index_dirRatio2Inv_mod]; /*Q0*/ move16(); bits_dir_raw_pre[1] = add( bits_dir_raw_pre[1], hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[m] ); move16(); @@ -417,9 +417,9 @@ Word16 ivas_qmetadata_dec_decode( { FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); - hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_direction_masa[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]]; + hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_direction_masa[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]]; /*Q0*/ move16(); bits_dir_raw_pre[0] = add( bits_dir_raw_pre[0], hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] ); move16(); @@ -429,12 +429,12 @@ Word16 ivas_qmetadata_dec_decode( IF( EQ_32( hQMetaData->no_directions, 2 ) ) { - no_TF = add( i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ), i_mult2( hQMetaData->q_direction[1].cfg.nbands, hQMetaData->q_direction[1].cfg.nblocks ) ); - tmp32 = L_sub( L_deposit_h( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), bits_diff_sum ) ), L_mult0( 17612 /* 4.2998046875f in Q12 */, shl( no_TF, 4 ) ) ); + no_TF = add( i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ), i_mult2( hQMetaData->q_direction[1].cfg.nbands, hQMetaData->q_direction[1].cfg.nblocks ) ); /*Q0*/ + tmp32 = L_sub( L_deposit_h( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), bits_diff_sum ) ), L_mult0( 17612 /* 4.2998046875f in Q12 */, shl( no_TF, 4 ) ) ); /*Q16*/ test(); IF( !all_coherence_zero && GE_32( tmp32, L_deposit_h( MASA_MIN_BITS_SURR_COH ) ) ) { - bits_sur_coherence = read_surround_coherence( bitstream, index, hQMetaData ); + bits_sur_coherence = read_surround_coherence( bitstream, index, hQMetaData ); /*Q0*/ } ELSE { @@ -450,16 +450,16 @@ Word16 ivas_qmetadata_dec_decode( } } bits_no_dirs_coh = add( bits_no_dirs_coh, bits_sur_coherence ); - total_bits_1dir = extract_l( L_mult0( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ) ) / no_TF ); + total_bits_1dir = extract_l( L_mult0( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ) ) / no_TF ); /*Q0*/ } ELSE { - no_TF = i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ); - tmp32 = L_sub( L_deposit_h( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), bits_diff_sum ) ), L_mult0( 17612 /* 4.2998046875f in Q12 */, shl( no_TF, 4 ) ) ); + no_TF = i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ); /*Q0*/ + tmp32 = L_sub( L_deposit_h( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), bits_diff_sum ) ), L_mult0( 17612 /* 4.2998046875f in Q12 */, shl( no_TF, 4 ) ) ); /*Q16*/ test(); IF( !all_coherence_zero && GE_32( tmp32, L_deposit_h( MASA_MIN_BITS_SURR_COH ) ) ) { - bits_sur_coherence = read_surround_coherence( bitstream, index, hQMetaData ); + bits_sur_coherence = read_surround_coherence( bitstream, index, hQMetaData ); /*Q0*/ } ELSE { @@ -487,18 +487,18 @@ Word16 ivas_qmetadata_dec_decode( FOR( d = 0; d < hQMetaData->no_directions; d++ ) { q_direction = &hQMetaData->q_direction[d]; - nbands = q_direction->cfg.nbands; + nbands = q_direction->cfg.nbands; /*Q0*/ move16(); - nblocks = q_direction->cfg.nblocks; + nblocks = q_direction->cfg.nblocks; /*Q0*/ move16(); - start_band = q_direction->cfg.start_band; + start_band = q_direction->cfg.start_band; /*Q0*/ move16(); - diffuseness_index_max_ec_frame = diffuseness_index_max_ec_frame_pre[0]; + diffuseness_index_max_ec_frame = diffuseness_index_max_ec_frame_pre[0]; /*Q0*/ move16(); IF( d == 0 ) { - bits_diff = bits_diff_sum; + bits_diff = bits_diff_sum; /*Q0*/ move16(); } ELSE @@ -506,7 +506,7 @@ Word16 ivas_qmetadata_dec_decode( bits_diff = 0; move16(); } - bits_dir_raw = bits_dir_raw_pre[d]; + bits_dir_raw = bits_dir_raw_pre[d]; /*Q0*/ move16(); /* Read coherence, if any */ @@ -515,7 +515,7 @@ Word16 ivas_qmetadata_dec_decode( IF( all_coherence_zero == 0 ) { - bits_coherence = read_coherence_data_fx( bitstream, index, hQMetaData, d, 0 ); + bits_coherence = read_coherence_data_fx( bitstream, index, hQMetaData, d, 0 ); /*Q0*/ } ELSE { @@ -535,7 +535,7 @@ Word16 ivas_qmetadata_dec_decode( } /* Read 2D signaling*/ - q_direction->not_in_2D = bitstream[( *index )--]; + q_direction->not_in_2D = bitstream[( *index )--]; /*Q0*/ move16(); signal_bits = 1; move16(); @@ -566,7 +566,7 @@ Word16 ivas_qmetadata_dec_decode( { bits_dir = 0; move16(); - raw_flag[0] = bitstream[( *index )--]; + raw_flag[0] = bitstream[( *index )--]; /*Q0*/ move16(); bits_dir = add( bits_dir, 1 ); @@ -586,7 +586,7 @@ Word16 ivas_qmetadata_dec_decode( move16(); FOR( b = start_band; b < nbands; b++ ) { - raw_flag[b] = bitstream[( *index )--]; + raw_flag[b] = bitstream[( *index )--]; /*Q0*/ move16(); bits_dir = add( bits_dir, 1 ); } @@ -618,7 +618,7 @@ Word16 ivas_qmetadata_dec_decode( { FOR( j = 0; j < q_direction->cfg.nblocks; j++ ) { - bits_temp[i][j] = q_direction->band_data[i].bits_sph_idx[j]; + bits_temp[i][j] = q_direction->band_data[i].bits_sph_idx[j]; /*Q0*/ move16(); } } @@ -629,7 +629,7 @@ Word16 ivas_qmetadata_dec_decode( { FOR( j = 0; j < q_direction->cfg.nblocks; j++ ) { - q_direction->band_data[i].bits_sph_idx[j] = bits_temp[i][j]; + q_direction->band_data[i].bits_sph_idx[j] = bits_temp[i][j]; /*Q0*/ move16(); } } @@ -653,7 +653,7 @@ Word16 ivas_qmetadata_dec_decode( IF( hQMetaData->is_masa_ivas_format == 0 ) { - reduce_bits = sub( bits_dir_raw, sub( sub( sub( total_bits_1dir, bits_diff ), bits_coherence ), signal_bits ) ); + reduce_bits = sub( bits_dir_raw, sub( sub( sub( total_bits_1dir, bits_diff ), bits_coherence ), signal_bits ) ); /*Q0*/ ind_order[0] = -1; move16(); } @@ -661,7 +661,7 @@ Word16 ivas_qmetadata_dec_decode( { ind_order[0] = 0; move16(); - reduce_bits = s_min( add( i_mult2( nbands, nblocks ), MASA_BIT_REDUCT_PARAM ), sub( bits_dir_raw, sub( sub( sub( total_bits_1dir, bits_diff ), bits_coherence ), signal_bits ) ) ); + reduce_bits = s_min( add( i_mult2( nbands, nblocks ), MASA_BIT_REDUCT_PARAM ), sub( bits_dir_raw, sub( sub( sub( total_bits_1dir, bits_diff ), bits_coherence ), signal_bits ) ) ); /*Q0*/ IF( GT_16( reduce_bits, sub( bits_dir_raw, i_mult2( nbands, nblocks ) ) ) ) { reduce_bits = sub( bits_dir_raw, i_mult2( nbands, nblocks ) ); @@ -670,7 +670,7 @@ Word16 ivas_qmetadata_dec_decode( only_reduce_bits_direction_fx( &dummy, q_direction, reduce_bits, nbands, nblocks, ind_order ); /* Read directions */ - bits_dir = read_directions_fx( q_direction, (UWord8) nbands, (UWord8) nblocks, bitstream, index, ind_order ); + bits_dir = read_directions_fx( q_direction, (UWord8) nbands, (UWord8) nblocks, bitstream, index, ind_order ); /*Q0*/ } IF( bits_coherence > 0 ) @@ -692,7 +692,7 @@ Word16 ivas_qmetadata_dec_decode( } IF( d == 0 ) { - total_bits_1dir = sub( hQMetaData->metadata_max_bits, sub( start_index_0, *index ) ); + total_bits_1dir = sub( hQMetaData->metadata_max_bits, sub( start_index_0, *index ) ); /*Q0*/ } bits_dir_target = add( bits_dir_target, bits_dir_raw ); @@ -747,39 +747,39 @@ Word16 ivas_qmetadata_dec_decode( { IF( EQ_16( hQMetaData->twoDirBands[b], 1 ) ) { - Copy32( hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].band_data[b].azimuth_fx, nblocks ); - Copy32( hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].band_data[b].elevation_fx, nblocks ); - Copy32( hQMetaData->q_direction[1].band_data[d].energy_ratio_fx, hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, nblocks ); + Copy32( hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].band_data[b].azimuth_fx, nblocks ); /*Q22*/ + Copy32( hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].band_data[b].elevation_fx, nblocks ); /*Q22*/ + Copy32( hQMetaData->q_direction[1].band_data[d].energy_ratio_fx, hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, nblocks ); /*Q30*/ IF( LT_32( hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0], 7 ) ) { FOR( m = 0; m < nblocks; m++ ) { - Word32 a1 = hQMetaData->q_direction[1].band_data[b].azimuth_fx[m]; + Word32 a1 = hQMetaData->q_direction[1].band_data[b].azimuth_fx[m]; /*Q22*/ move32(); - a1 = L_shr( hQMetaData->q_direction[1].band_data[b].azimuth_fx[m], 1 ); - Word32 b1 = hQMetaData->q_direction[0].band_data[b].azimuth_fx[m]; + a1 = L_shr( hQMetaData->q_direction[1].band_data[b].azimuth_fx[m], 1 ); /*Q21*/ + Word32 b1 = hQMetaData->q_direction[0].band_data[b].azimuth_fx[m]; /*Q22*/ move32(); - b1 = L_shr( hQMetaData->q_direction[0].band_data[b].azimuth_fx[m], 1 ); - Word32 c = L_shr( DEGREE_180_Q_22, 1 ); + b1 = L_shr( hQMetaData->q_direction[0].band_data[b].azimuth_fx[m], 1 ); /*Q21*/ + Word32 c = L_shr( DEGREE_180_Q_22, 1 ); /*Q21*/ a1 = L_add( a1, L_sub( b1, c ) ); IF( GE_32( a1, L_shr( DEGREE_180_Q_22, 1 ) ) ) { - a1 = L_sub( a1, L_shr( DEGREE_360_Q_22, 1 ) ); + a1 = L_sub( a1, L_shr( DEGREE_360_Q_22, 1 ) ); /*Q21*/ } IF( LT_32( a1, L_shr( -DEGREE_180_Q_22, 1 ) ) ) { - a1 = L_add( a1, L_shr( DEGREE_360_Q_22, 1 ) ); + a1 = L_add( a1, L_shr( DEGREE_360_Q_22, 1 ) ); /*Q21*/ } - hQMetaData->q_direction[1].band_data[b].azimuth_fx[m] = L_shl( a1, 1 ); + hQMetaData->q_direction[1].band_data[b].azimuth_fx[m] = L_shl( a1, 1 ); /*Q22*/ move32(); } } IF( hQMetaData->q_direction[1].coherence_band_data != NULL ) { - mvc2c( hQMetaData->q_direction[1].coherence_band_data[d].spread_coherence, hQMetaData->q_direction[1].coherence_band_data[b].spread_coherence, nblocks ); + mvc2c( hQMetaData->q_direction[1].coherence_band_data[d].spread_coherence, hQMetaData->q_direction[1].coherence_band_data[b].spread_coherence, nblocks ); /*Q0*/ } d = sub( d, 1 ); } @@ -803,12 +803,12 @@ Word16 ivas_qmetadata_dec_decode( { Word32 ratioSum_flt_fx; - ratioSum_flt_fx = L_add( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0], hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[0] ); + ratioSum_flt_fx = L_add( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0], hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[0] ); /*Q30*/ IF( GT_32( ratioSum_flt_fx, ONE_IN_Q30 ) ) { - set32_fx( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx, L_shl( (Word32) divide3232( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0], ratioSum_flt_fx ), 15 ) /* Q30 */, nblocks ); - set32_fx( hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, L_shl( (Word32) divide3232( hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[0], ratioSum_flt_fx ), 15 ) /* Q30 */, nblocks ); + set32_fx( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx, L_shl( (Word32) divide3232( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0], ratioSum_flt_fx ), 15 ) /* Q30 */, nblocks ); /*Q30*/ + set32_fx( hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, L_shl( (Word32) divide3232( hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[0], ratioSum_flt_fx ), 15 ) /* Q30 */, nblocks ); /*Q30*/ } } } @@ -820,12 +820,12 @@ Word16 ivas_qmetadata_dec_decode( IF( GT_16( bits_dir_used, bits_dir_target ) ) { - hQMetaData->dir_comp_ratio_fx = MAX_WORD16; + hQMetaData->dir_comp_ratio_fx = MAX_WORD16; /*Q15*/ move16(); } ELSE { - hQMetaData->dir_comp_ratio_fx = divide3232( bits_dir_used, bits_dir_target ); + hQMetaData->dir_comp_ratio_fx = divide3232( bits_dir_used, bits_dir_target ); /*Q15*/ } return sub( start_index_0, *index ); } @@ -1393,8 +1393,8 @@ int16_t ivas_qmetadata_dec_decode( #ifdef IVAS_FLOAT_FIXED Word16 ivas_qmetadata_dec_decode_hr_384_512( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: hQMetaData handle */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, /* i/o: bitstream position */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /* i/o: bitstream position Q0*/ const SPHERICAL_GRID_DATA *sph_grid16, /* i : spherical grid for deindexing */ const Word16 bits_sph_idx, const Word16 bits_sp_coh, @@ -1440,11 +1440,11 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( /* read number of higher inactive/not encoded bands */ IF( bitstream[( *index )--] ) { - codedBands = sub( sub( MASA_MAXIMUM_CODING_SUBBANDS, ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 1 ) ), 1 ); + codedBands = sub( sub( MASA_MAXIMUM_CODING_SUBBANDS, ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 1 ) ), 1 ); /*Q0*/ } ELSE { - codedBands = MASA_MAXIMUM_CODING_SUBBANDS; + codedBands = MASA_MAXIMUM_CODING_SUBBANDS; /*Q0*/ move16(); } FOR( b = codedBands; b < ncoding_bands_config; b++ ) @@ -1502,10 +1502,10 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( move16(); } } - sf_nbands0 = hQMetaData->q_direction[0].cfg.nbands; + sf_nbands0 = hQMetaData->q_direction[0].cfg.nbands; /*Q0*/ move16(); - hQMetaData->q_direction[0].cfg.nbands = codedBands; + hQMetaData->q_direction[0].cfg.nbands = codedBands; /*Q0*/ move16(); /*Coherence flag decoding*/ @@ -1517,14 +1517,14 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( IF( hQMetaData->coherence_flag ) { /* read if coherence is zero */ - all_coherence_zero = bitstream[( *index )--]; + all_coherence_zero = bitstream[( *index )--]; /*Q0*/ move16(); #ifdef DEBUG_MODE_QMETADATA bits_no_dirs_coh += 1; #endif } - hQMetaData->all_coherence_zero = (UWord8) all_coherence_zero; + hQMetaData->all_coherence_zero = (UWord8) all_coherence_zero; /*Q0*/ IF( EQ_32( hQMetaData->no_directions, 2 ) ) { @@ -1535,19 +1535,19 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( IF( EQ_16( bits_sph_idx, 11 ) && EQ_32( hQMetaData->no_directions, 2 ) ) { /* Read which bands have 2 directions */ - hQMetaData->q_direction[1].cfg.nbands = hQMetaData->numTwoDirBands; + hQMetaData->q_direction[1].cfg.nbands = hQMetaData->numTwoDirBands; /*Q0*/ move16(); - sf_nbands1 = hQMetaData->q_direction[1].cfg.nbands; + sf_nbands1 = hQMetaData->q_direction[1].cfg.nbands; /*Q0*/ move16(); if ( GT_16( hQMetaData->q_direction[1].cfg.nbands, codedBands ) ) { - hQMetaData->q_direction[1].cfg.nbands = codedBands; + hQMetaData->q_direction[1].cfg.nbands = codedBands; /*Q0*/ move16(); } set_c( (Word8 *) hQMetaData->twoDirBands, 0, hQMetaData->q_direction[0].cfg.nbands ); d = *index; move16(); - dif_p[0] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); + dif_p[0] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); /*Q0*/ move16(); p[0] = dif_p[0]; move16(); @@ -1555,7 +1555,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( move16(); FOR( b = 1; b < hQMetaData->q_direction[1].cfg.nbands; b++ ) { - dif_p[b] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); + dif_p[b] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); /*Q0*/ move16(); p[b] = add( add( p[b - 1], dif_p[b] ), 1 ); move16(); @@ -1570,11 +1570,11 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( test(); IF( EQ_16( bits_sph_idx, 16 ) && EQ_32( hQMetaData->no_directions, 2 ) ) { - sf_nbands1 = hQMetaData->q_direction[1].cfg.nbands; + sf_nbands1 = hQMetaData->q_direction[1].cfg.nbands; /*Q0*/ move16(); IF( GT_16( hQMetaData->q_direction[1].cfg.nbands, codedBands ) ) { - hQMetaData->q_direction[1].cfg.nbands = codedBands; + hQMetaData->q_direction[1].cfg.nbands = codedBands; /*Q0*/ move16(); } } @@ -1596,7 +1596,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - W_nrg_ratio[0][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m]] ); + W_nrg_ratio[0][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m]] ); /*Q62*/ move64(); } } @@ -1609,11 +1609,11 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - W_nrg_ratio[1][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]] ); + W_nrg_ratio[1][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]] ); /*Q62*/ move64(); /* Scale energy ratios that sum to over one */ - ratioSum = W_round64_L( W_add( W_nrg_ratio[0][b][m], W_nrg_ratio[1][b][m] ) ); + ratioSum = W_round64_L( W_add( W_nrg_ratio[0][b][m], W_nrg_ratio[1][b][m] ) ); /*Q30*/ IF( GT_32( ratioSum, ONE_IN_Q30 ) ) { @@ -1634,7 +1634,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { IF( EQ_16( hQMetaData->twoDirBands[b], 1 ) ) { - pos_2dir_band[d] = b; + pos_2dir_band[d] = b; /*Q0*/ move16(); d = add( d, 1 ); } @@ -1649,16 +1649,16 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - W_nrg_ratio[1][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]] ); + W_nrg_ratio[1][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]] ); /*Q62*/ move64(); - ratioSum = W_round64_L( W_add( W_nrg_ratio[0][pos_2dir_band[b]][m], W_nrg_ratio[1][b][m] ) ); + ratioSum = W_round64_L( W_add( W_nrg_ratio[0][pos_2dir_band[b]][m], W_nrg_ratio[1][b][m] ) ); /*Q30*/ IF( GT_32( ratioSum, ONE_IN_Q30 ) ) { - W_nrg_ratio[0][pos_2dir_band[b]][m] = W_shl( (Word64) ( W_nrg_ratio[0][pos_2dir_band[b]][m] / ratioSum ), 30 ); + W_nrg_ratio[0][pos_2dir_band[b]][m] = W_shl( (Word64) ( W_nrg_ratio[0][pos_2dir_band[b]][m] / ratioSum ), 30 ); /*Q62*/ move64(); - W_nrg_ratio[1][b][m] = W_shl( (Word64) ( W_nrg_ratio[1][b][m] / ratioSum ), 30 ); + W_nrg_ratio[1][b][m] = W_shl( (Word64) ( W_nrg_ratio[1][b][m] / ratioSum ), 30 ); /*Q62*/ move64(); } } @@ -1672,9 +1672,9 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - hQMetaData->q_direction[1].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]; + hQMetaData->q_direction[1].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]; /*Q0*/ move16(); - hQMetaData->q_direction[1].band_data[b].bits_sph_idx[m] = bits_sph_idx; + hQMetaData->q_direction[1].band_data[b].bits_sph_idx[m] = bits_sph_idx; /*Q0*/ move16(); } } @@ -1684,9 +1684,9 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); - hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_sph_idx; + hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_sph_idx; /*Q0*/ move16(); } } @@ -1766,14 +1766,14 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( IF( EQ_16( hQMetaData->twoDirBands[b], 1 ) ) { - Copy32( hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].band_data[b].azimuth_fx, nblocks ); - Copy32( hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].band_data[b].elevation_fx, nblocks ); - Copy32( hQMetaData->q_direction[1].band_data[d].energy_ratio_fx, hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, nblocks ); + Copy32( hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].band_data[b].azimuth_fx, nblocks ); /*Q22*/ + Copy32( hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].band_data[b].elevation_fx, nblocks ); /*Q22*/ + Copy32( hQMetaData->q_direction[1].band_data[d].energy_ratio_fx, hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, nblocks ); /*Q30*/ Copy64( W_nrg_ratio[1][d], W_nrg_ratio[1][b], nblocks ); IF( hQMetaData->q_direction[1].coherence_band_data != NULL ) { - mvc2c( hQMetaData->q_direction[1].coherence_band_data[d].spread_coherence, hQMetaData->q_direction[1].coherence_band_data[b].spread_coherence, nblocks ); + mvc2c( hQMetaData->q_direction[1].coherence_band_data[d].spread_coherence, hQMetaData->q_direction[1].coherence_band_data[b].spread_coherence, nblocks ); /*Q0*/ } d = sub( d, 1 ); } @@ -1798,12 +1798,12 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { Word32 ratioSum; - ratioSum = W_round64_L( W_add( W_nrg_ratio[0][b][m], W_nrg_ratio[1][b][m] ) ); + ratioSum = W_round64_L( W_add( W_nrg_ratio[0][b][m], W_nrg_ratio[1][b][m] ) ); /*Q30*/ IF( GT_32( ratioSum, ONE_IN_Q30 ) ) { - W_nrg_ratio[0][b][m] = W_shl( (Word64) ( W_nrg_ratio[0][b][m] / ratioSum ), 30 ); + W_nrg_ratio[0][b][m] = W_shl( (Word64) ( W_nrg_ratio[0][b][m] / ratioSum ), 30 ); /*Q62*/ move64(); - W_nrg_ratio[1][b][m] = W_shl( (Word64) ( W_nrg_ratio[1][b][m] / ratioSum ), 30 ); + W_nrg_ratio[1][b][m] = W_shl( (Word64) ( W_nrg_ratio[1][b][m] / ratioSum ), 30 ); /*Q62*/ move64(); } } @@ -1815,7 +1815,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[0][b][m] ); + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[0][b][m] ); /*Q30*/ move32(); } } @@ -1836,7 +1836,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[1][b][m] ); + hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[1][b][m] ); /*Q30*/ move32(); } } @@ -1890,15 +1890,15 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( /* Store status information for renderer use */ hQMetaData->ec_flag = 0; move16(); - hQMetaData->dir_comp_ratio_fx = MAX_WORD16; + hQMetaData->dir_comp_ratio_fx = MAX_WORD16; /*Q15*/ move16(); - hQMetaData->q_direction[0].cfg.nbands = sf_nbands0; + hQMetaData->q_direction[0].cfg.nbands = sf_nbands0; /*Q0*/ move16(); IF( EQ_32( hQMetaData->no_directions, 2 ) ) { - hQMetaData->q_direction[1].cfg.nbands = sf_nbands1; + hQMetaData->q_direction[1].cfg.nbands = sf_nbands1; /*Q0*/ move16(); } @@ -2248,11 +2248,11 @@ int16_t ivas_qmetadata_dec_decode_hr_384_512( #ifdef IVAS_FLOAT_FIXED Word16 ivas_qmetadata_dec_sid_decode( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, /* i/o: bitstream position */ - const Word16 nchan_transport, /* i : number of transport channels */ - Word16 *element_mode, /* o : element mode */ - const Word16 ivas_format /* i : IVAS format */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /* i/o: bitstream position Q0*/ + const Word16 nchan_transport, /* i : number of transport channels Q0*/ + Word16 *element_mode, /* o : element mode Q0*/ + const Word16 ivas_format /* i : IVAS format Q0*/ ) { Word16 b, m, i; @@ -2299,7 +2299,7 @@ Word16 ivas_qmetadata_dec_sid_decode( test(); IF( EQ_16( ivas_format, MASA_FORMAT ) && EQ_16( nchan_transport, 2 ) ) { - b = bitstream[( *index )--]; + b = bitstream[( *index )--]; /*Q0*/ move16(); IF( b ) { @@ -2326,7 +2326,7 @@ Word16 ivas_qmetadata_dec_sid_decode( move16(); } - nblocks = q_direction->cfg.nblocks; /* only 1 block transmitted but up to 4 blocks re-generated */ + nblocks = q_direction->cfg.nblocks; /* only 1 block transmitted but up to 4 blocks re-generated Q0*/ move16(); start_band = 0; /* start from band 0 */ move16(); @@ -2334,7 +2334,7 @@ Word16 ivas_qmetadata_dec_sid_decode( /* Read 2D signaling*/ IF( NE_16( ivas_format, SBA_FORMAT ) ) { - q_direction->not_in_2D = bitstream[( *index )--]; + q_direction->not_in_2D = bitstream[( *index )--]; /*Q0*/ move16(); } ELSE @@ -2350,14 +2350,14 @@ Word16 ivas_qmetadata_dec_sid_decode( /* Decode diffuseness*/ FOR( b = start_band; b < nbands; b++ ) { - diffuseness_index[b] = (UWord16) L_add( ivas_qmetadata_DecodeQuasiUniform( bitstream, index, sub( DIRAC_DIFFUSE_LEVELS, 4 ) ), 4 ); + diffuseness_index[b] = (UWord16) L_add( ivas_qmetadata_DecodeQuasiUniform( bitstream, index, sub( DIRAC_DIFFUSE_LEVELS, 4 ) ), 4 ); /*Q0*/ move16(); - q_direction->band_data[b].energy_ratio_index[0] = diffuseness_index[b]; + q_direction->band_data[b].energy_ratio_index[0] = diffuseness_index[b]; /*Q0*/ move16(); - q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[diffuseness_index[b]]; + q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[diffuseness_index[b]]; /*Q0*/ move16(); - bits_dir = extract_l( L_add( bits_dir, q_direction->band_data[b].bits_sph_idx[0] ) ); - q_direction->band_data[b].azimuth_m_alphabet[0] = no_phi_masa[q_direction->band_data[b].bits_sph_idx[0] - 1][0]; + bits_dir = extract_l( L_add( bits_dir, q_direction->band_data[b].bits_sph_idx[0] ) ); /*Q0*/ + q_direction->band_data[b].azimuth_m_alphabet[0] = no_phi_masa[q_direction->band_data[b].bits_sph_idx[0] - 1][0]; /*Q0*/ move16(); } @@ -2417,7 +2417,7 @@ Word16 ivas_qmetadata_dec_sid_decode( /* Decode diffuseness*/ FOR( b = start_band; b < nbands; b++ ) { - diffuseness_index[b] = (UWord16) L_add( ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS - 4 ), 4 ); + diffuseness_index[b] = (UWord16) L_add( ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS - 4 ), 4 ); /*Q0*/ move16(); q_direction->band_data[b].energy_ratio_index[0] = diffuseness_index[b]; move16(); @@ -2430,11 +2430,11 @@ Word16 ivas_qmetadata_dec_sid_decode( FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[diffuseness_index[b]] ); + q_direction->band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[diffuseness_index[b]] ); /*Q30*/ move32(); FOR( i = 0; i < nblocks; i++ ) { - q_direction->band_data[b].energy_ratio_fx[i] = q_direction->band_data[b].energy_ratio_fx[0]; + q_direction->band_data[b].energy_ratio_fx[i] = q_direction->band_data[b].energy_ratio_fx[0]; /*Q30*/ move32(); } } @@ -2461,11 +2461,11 @@ Word16 ivas_qmetadata_dec_sid_decode( ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( avg_azimuth_fx, avg_elevation_fx, avg_direction_vector_fx ); ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[nblocks - 1], q_direction->band_data[b].elevation_fx[nblocks - 1], direction_vector_fx ); - v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); - v_shr_32( avg_direction_vector_fx, avg_direction_vector_fx, 3, 5 ); + v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); /*Q25*/ + v_shr_32( avg_direction_vector_fx, avg_direction_vector_fx, 3, 5 ); /*Q25*/ FOR( m = 0; m < nblocks - 1; m++ ) { - v_add_32( direction_vector_fx, avg_direction_vector_fx, direction_vector_fx, 3 ); + v_add_32( direction_vector_fx, avg_direction_vector_fx, direction_vector_fx, 3 ); /*Q25*/ ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( direction_vector_fx, sub( 30, 5 ), &q_direction->band_data[b].azimuth_fx[m], &q_direction->band_data[b].elevation_fx[m] ); } ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, sub( 30, 5 ), &q_direction->band_data[b].azimuth_fx[nblocks - 1], &q_direction->band_data[b].elevation_fx[nblocks - 1] ); @@ -2481,14 +2481,14 @@ Word16 ivas_qmetadata_dec_sid_decode( q_direction->band_data[b].azimuth_m_alphabet[0] = shl( 1, extract_l( L_min( 5, q_direction->band_data[b].bits_sph_idx[0] ) ) ); move16(); } - q_direction->band_data[b].azimuth_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, q_direction->band_data[b].azimuth_m_alphabet[0] ); + q_direction->band_data[b].azimuth_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, q_direction->band_data[b].azimuth_m_alphabet[0] ); /*Q0*/ move16(); - q_direction->band_data[b].azimuth_index[0] = add( ivas_qmetadata_dereorder_generic( q_direction->band_data[b].azimuth_index[0] ), shr( q_direction->band_data[b].azimuth_m_alphabet[0], 1 ) ); + q_direction->band_data[b].azimuth_index[0] = add( ivas_qmetadata_dereorder_generic( q_direction->band_data[b].azimuth_index[0] ), shr( q_direction->band_data[b].azimuth_m_alphabet[0], 1 ) ); /*Q0*/ move16(); - temp_result = div_s( ( shl( q_direction->band_data[b].azimuth_index[0], 6 ) ), ( shl( q_direction->band_data[b].azimuth_m_alphabet[0], 6 ) ) ); - temp_result = Mpy_32_16_1( DEGREE_360_Q_22, (Word16) temp_result ); - avg_azimuth_fx = L_sub( temp_result, DEGREE_180_Q_22 ); + temp_result = div_s( ( shl( q_direction->band_data[b].azimuth_index[0], 6 ) ), ( shl( q_direction->band_data[b].azimuth_m_alphabet[0], 6 ) ) ); /*Q15*/ + temp_result = Mpy_32_16_1( DEGREE_360_Q_22, (Word16) temp_result ); /*Q22*/ + avg_azimuth_fx = L_sub( temp_result, DEGREE_180_Q_22 ); /*Q22*/ avg_elevation_fx = 0; move32(); @@ -2496,11 +2496,11 @@ Word16 ivas_qmetadata_dec_sid_decode( ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( avg_azimuth_fx, avg_elevation_fx, avg_direction_vector_fx ); ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[nblocks - 1], q_direction->band_data[b].elevation_fx[nblocks - 1], direction_vector_fx ); - v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); - v_shr_32( avg_direction_vector_fx, avg_direction_vector_fx, 3, 5 ); + v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); /*Q25*/ + v_shr_32( avg_direction_vector_fx, avg_direction_vector_fx, 3, 5 ); /*Q25*/ FOR( m = 0; m < nblocks - 1; m++ ) { - v_add_32( direction_vector_fx, avg_direction_vector_fx, direction_vector_fx, 3 ); + v_add_32( direction_vector_fx, avg_direction_vector_fx, direction_vector_fx, 3 ); /*Q25*/ ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( direction_vector_fx, 30 - 5, &q_direction->band_data[b].azimuth_fx[m], &q_direction->band_data[b].elevation_fx[m] ); } ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, 30 - 5, &q_direction->band_data[b].azimuth_fx[nblocks - 1], &q_direction->band_data[b].elevation_fx[nblocks - 1] ); @@ -2775,9 +2775,9 @@ int16_t ivas_qmetadata_dec_sid_decode( #ifdef IVAS_FLOAT_FIXED static Word16 ivas_diffuseness_huff_ec_decode_fx( - const UWord16 *bitstream, - Word16 *index, - Word16 av ) + const UWord16 *bitstream, /*Q0*/ + Word16 *index, /*Q0*/ + Word16 av /*Q0*/ ) { Word16 val; @@ -2857,10 +2857,10 @@ static int16_t ivas_diffuseness_huff_ec_decode( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_entropy_decode_diffuseness( - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /*Q0*/ IVAS_QDIRECTION *q_direction, - UWord16 *diffuseness_index_max_ec_frame ) + UWord16 *diffuseness_index_max_ec_frame /*Q0*/ ) { Word16 b; UWord16 dif_min; @@ -2883,7 +2883,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( move16(); FOR( b = 0; b < MASA_BITS_ER; b++ ) { - q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); + q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); /*Q0*/ move16(); } *diffuseness_index_max_ec_frame = 5; @@ -2899,21 +2899,21 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( { IF( bitstream[( *index )--] ) /* dif_have_unique_value */ { - dif_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS ); /* dif_unique_value */ + dif_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS ); /* dif_unique_value Q0*/ FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = dif_min; + q_direction->band_data[b].energy_ratio_index[0] = dif_min; /*Q0*/ move16(); } } ELSE /* all diffuseness values are dif_min_value or dif_min_value + 1 */ { - dif_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS - 1 ); /* dif_min_value */ + dif_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS - 1 ); /* dif_min_value Q0*/ FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = (UWord16) L_add( dif_min, bitstream[( *index )--] ); /* dif_bit_offset_values */ + q_direction->band_data[b].energy_ratio_index[0] = (UWord16) L_add( dif_min, bitstream[( *index )--] ); /* dif_bit_offset_values Q0*/ move16(); } } @@ -2927,7 +2927,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( move16(); FOR( b = 0; b < MASA_BITS_ER; b++ ) { - av = add( av, i_mult( (Word16) bitstream[( *index )--], shl( 1, sub( sub( MASA_BITS_ER, 1 ), b ) ) ) ); + av = add( av, i_mult( (Word16) bitstream[( *index )--], shl( 1, sub( sub( MASA_BITS_ER, 1 ), b ) ) ) ); /*Q0*/ } dif_min = DIRAC_DIFFUSE_LEVELS; @@ -2935,7 +2935,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( /* read average removed data (average is added inside)*/ FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = ivas_diffuseness_huff_ec_decode_fx( bitstream, index, av ); + q_direction->band_data[b].energy_ratio_index[0] = ivas_diffuseness_huff_ec_decode_fx( bitstream, index, av ); /*Q0*/ move16(); dif_min = (UWord16) L_min( dif_min, q_direction->band_data[b].energy_ratio_index[0] ); move16(); @@ -2949,7 +2949,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS ); + q_direction->band_data[b].energy_ratio_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); dif_min = (UWord16) L_min( dif_min, q_direction->band_data[b].energy_ratio_index[0] ); move16(); @@ -3072,8 +3072,8 @@ static int16_t ivas_qmetadata_entropy_decode_diffuseness( #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_entropy_decode_diffuseness_hr_512( - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /*Q0*/ IVAS_QDIRECTION *q_direction ) { Word16 b, k; @@ -3099,7 +3099,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness_hr_512( move16(); FOR( b = 0; b < MASA_BITS_ER_HR; b++ ) { - q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( (UWord16) L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); + q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( (UWord16) L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); /*Q0*/ move16(); } @@ -3110,7 +3110,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness_hr_512( { FOR( k = 0; k < nblocks; k++ ) { - q_direction->band_data[b].energy_ratio_index[k] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, HR_MASA_ER_LEVELS ); + q_direction->band_data[b].energy_ratio_index[k] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, HR_MASA_ER_LEVELS ); /*Q0*/ move16(); } } @@ -3167,10 +3167,10 @@ static int16_t ivas_qmetadata_entropy_decode_diffuseness_hr_512( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_entropy_decode_df_ratio( - UWord16 *bitstream, - Word16 *index, + UWord16 *bitstream, /*Q0*/ + Word16 *index, /*Q0*/ IVAS_QDIRECTION *q_direction, - Word16 *dfRatio_bits ) + Word16 *dfRatio_bits /*Q0*/ ) { Word16 b; Word16 bits_raw; @@ -3198,7 +3198,7 @@ static Word16 ivas_qmetadata_entropy_decode_df_ratio( FOR( b = 0; b < dfRatio_bits[0]; b++ ) { // q_direction->band_data[0].energy_ratio_index[0] = ( q_direction->band_data[0].energy_ratio_index[0] << 1 ) + bitstream[( *index )--]; - q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); + q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); /*Q0*/ move16(); } return dfRatio_bits[0]; @@ -3232,7 +3232,7 @@ static Word16 ivas_qmetadata_entropy_decode_df_ratio( ec_mode = 0; move16(); } - max_alphabet_size = shl( 1, max_dfRatio_bits ); + max_alphabet_size = shl( 1, max_dfRatio_bits ); /* 1 << max_dfRatio_bits */ dec_mode = 2; /* Default to raw decoding */ move16(); @@ -3265,27 +3265,27 @@ static Word16 ivas_qmetadata_entropy_decode_df_ratio( { FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, (UWord16) L_shl( 1, dfRatio_bits[b] ) ); + q_direction->band_data[b].energy_ratio_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, (UWord16) L_shl( 1, dfRatio_bits[b] ) ); /*Q0*/ move16(); } } ELSE IF( EQ_16( dec_mode, 1 ) ) /* One value decoding */ { - ratio_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, max_alphabet_size ); /* dif_unique_value */ + ratio_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, max_alphabet_size ); /* dif_unique_value Q0*/ FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = ratio_min; + q_direction->band_data[b].energy_ratio_index[0] = ratio_min; /*Q0*/ move16(); } } ELSE /* Bandwise 1-bit diff decoding */ { - ratio_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, max_alphabet_size - 1 ); /* dif_min_value */ + ratio_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, max_alphabet_size - 1 ); /* dif_min_value Q0*/ FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = (UWord16) L_add( ratio_min, bitstream[( *index )--] ); /* dif_bit_offset_values */ + q_direction->band_data[b].energy_ratio_index[0] = (UWord16) L_add( ratio_min, bitstream[( *index )--] ); /* dif_bit_offset_values Q0*/ move16(); } } @@ -3414,13 +3414,13 @@ static int16_t ivas_qmetadata_entropy_decode_df_ratio( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_entropy_decode_dir_fx( - IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, - const UWord16 diffuseness_index_max_ec_frame, - const Word16 nbands, - const Word16 start_band, - const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding*/ + IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /*Q0*/ + const UWord16 diffuseness_index_max_ec_frame, /*Q0*/ + const Word16 nbands, /*Q0*/ + const Word16 start_band, /*Q0*/ + const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding Q0*/ ) { Word16 b, m; @@ -3458,19 +3458,19 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; + diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; /*Q0*/ move16(); } diff_idx_min = s_min( diff_idx_min, diff_idx ); IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - elev_alph[b] = no_theta_masa[sub( bits_direction_masa[diff_idx], 3 )]; + elev_alph[b] = no_theta_masa[( bits_direction_masa[diff_idx] - 3 )]; /*Q0*/ move16(); } ELSE { - elev_alph[b] = sub( shl( no_theta_masa[sub( bits_direction_masa[diff_idx], 3 )], 1 ), 1 ); + elev_alph[b] = sub( shl( no_theta_masa[( bits_direction_masa[diff_idx] - 3 )], 1 ), 1 ); /*Q0*/ move16(); } @@ -3493,11 +3493,11 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( q_direction->band_data[b].elevation_index[m] = 0; move16(); - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][0]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][0]; /*Q0*/ move16(); - q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, azith_alph[b][m] ); + q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, azith_alph[b][m] ); /*Q0*/ move16(); - q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], 0, 1, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], 0, 1, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -3516,15 +3516,15 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( { IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - avg_elevation_alphabet = no_theta_masa[sub( bits_direction_masa[diff_idx_min], 3 )]; + avg_elevation_alphabet = no_theta_masa[( bits_direction_masa[diff_idx_min] - 3 )]; /*Q0*/ move16(); - avg_elevation_idx = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, avg_elevation_alphabet ); + avg_elevation_idx = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, avg_elevation_alphabet ); /*Q0*/ } ELSE { - avg_elevation_alphabet = sub( shl( no_theta_masa[sub( bits_direction_masa[diff_idx_min], 3 )], 1 ), 1 ); + avg_elevation_alphabet = sub( shl( no_theta_masa[( bits_direction_masa[diff_idx_min] - 3 )], 1 ), 1 ); /*Q0*/ avg_elevation_idx = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, avg_elevation_alphabet ); - avg_elevation_idx = add( ivas_qmetadata_dereorder_generic( avg_elevation_idx ), shr( avg_elevation_alphabet, 1 ) ); + avg_elevation_idx = add( ivas_qmetadata_dereorder_generic( avg_elevation_idx ), shr( avg_elevation_alphabet, 1 ) ); /*Q0*/ } gr_param_elev = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, 4 + 1 ); @@ -3543,27 +3543,27 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; + diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; /*Q0*/ move16(); } IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - avg_elevation_index_projected = ivas_chan_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); + avg_elevation_index_projected = ivas_chan_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); /*Q0*/ } ELSE { - avg_elevation_index_projected = ivas_dirac_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); + avg_elevation_index_projected = ivas_dirac_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); /*Q0*/ /*reorder elevation indexing*/ - tmp_index = sub( avg_elevation_index_projected, shr( elev_alph[b], 1 ) ); + tmp_index = sub( avg_elevation_index_projected, shr( elev_alph[b], 1 ) ); /*Q0*/ IF( tmp_index < 0 ) { - tmp_index = negate( tmp_index * 2 ); + tmp_index = negate( imult1616( tmp_index, 2 ) ); } ELSE IF( tmp_index > 0 ) { - tmp_index = sub( ( tmp_index * 2 ), 1 ); + tmp_index = sub( imult1616( tmp_index, 2 ), 1 ); } avg_elevation_index_projected = tmp_index; move16(); @@ -3571,23 +3571,23 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( FOR( m = 0; m < nblocks; m++ ) { - q_direction->band_data[b].elevation_index[m] = avg_elevation_index_projected; + q_direction->band_data[b].elevation_index[m] = avg_elevation_index_projected; /*Q0*/ move16(); /*deduce aplhabet for azimuth*/ IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][q_direction->band_data[b].elevation_index[m]]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][q_direction->band_data[b].elevation_index[m]]; /*Q0*/ move16(); } ELSE { - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][extract_l( L_shr( L_add( q_direction->band_data[b].elevation_index[m], 1 ), 1 ) )]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][extract_l( L_shr( L_add( q_direction->band_data[b].elevation_index[m], 1 ), 1 ) )]; /*Q0*/ move16(); } /*decode elevation*/ - q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -3606,7 +3606,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; + diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; /*Q0*/ move16(); } @@ -3615,11 +3615,11 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( Word16 tmp_index; IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - avg_elevation_index_projected = ivas_chan_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); - tmp_index = ivas_qmetadata_DecodeExtendedGR( bitstream, index, sub( shl( elev_alph[b], 1 ), 1 ), gr_param_elev ); + avg_elevation_index_projected = ivas_chan_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); /*Q0*/ + tmp_index = ivas_qmetadata_DecodeExtendedGR( bitstream, index, sub( shl( elev_alph[b], 1 ), 1 ), gr_param_elev ); /*Q0*/ IF( s_and( tmp_index, 1 ) ) { - tmp_index = add( avg_elevation_index_projected, shr( add( tmp_index, 1 ), 1 ) ); + tmp_index = add( avg_elevation_index_projected, shr( add( tmp_index, 1 ), 1 ) ); /*Q0*/ } ELSE { @@ -3629,15 +3629,15 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( move16(); /*deduce aplhabet for azimuth*/ - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][q_direction->band_data[b].elevation_index[m]]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][q_direction->band_data[b].elevation_index[m]]; /*Q0*/ move16(); } ELSE { - avg_elevation_index_projected = ivas_dirac_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); + avg_elevation_index_projected = ivas_dirac_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); /*Q0*/ - tmp_index = ivas_qmetadata_DecodeExtendedGR( bitstream, index, elev_alph[b], gr_param_elev ); - tmp_index = ivas_qmetadata_ReorderElevationDecoded( tmp_index, avg_elevation_index_projected, elev_alph[b] ); + tmp_index = ivas_qmetadata_DecodeExtendedGR( bitstream, index, elev_alph[b], gr_param_elev ); /*Q0*/ + tmp_index = ivas_qmetadata_ReorderElevationDecoded( tmp_index, avg_elevation_index_projected, elev_alph[b] ); /*Q0*/ /*reorder elevation indexing*/ tmp_index = sub( tmp_index, elev_alph[b] / 2 ); @@ -3653,12 +3653,12 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( move16(); /*deduce aplhabet for azimuth*/ - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][extract_l( L_shr( L_add( q_direction->band_data[b].elevation_index[m], 1 ), 1 ) )]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][extract_l( L_shr( L_add( q_direction->band_data[b].elevation_index[m], 1 ), 1 ) )]; /*Q0*/ move16(); } /*decode elevation*/ - q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -3678,7 +3678,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; + diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; /*Q0*/ move16(); } @@ -3690,17 +3690,17 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( /*deduce alphabet for azimuth*/ IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][q_direction->band_data[b].elevation_index[m]]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][q_direction->band_data[b].elevation_index[m]]; /*Q0*/ move16(); } ELSE { - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][add( q_direction->band_data[b].elevation_index[m], 1 ) / 2]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][add( q_direction->band_data[b].elevation_index[m], 1 ) / 2]; /*Q0*/ move16(); } /*decode elevation*/ - q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -3708,14 +3708,14 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } /*Azimuth*/ - avg_azimuth_alphabet = no_phi_masa[sub( bits_direction_masa[diff_idx_min], 1 )][0]; /* average azimuth is quantized on the equatorial plane */ + avg_azimuth_alphabet = no_phi_masa[( bits_direction_masa[diff_idx_min] - 1 )][0]; /* average azimuth is quantized on the equatorial plane Q0*/ move16(); - avg_azimuth_index = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, avg_azimuth_alphabet ); - avg_azimuth_index = ivas_qmetadata_dereorder_generic( avg_azimuth_index ); - avg_azimuth_index = add( avg_azimuth_index, shr( avg_azimuth_alphabet, 1 ) ); + avg_azimuth_index = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, avg_azimuth_alphabet ); /*Q0*/ + avg_azimuth_index = ivas_qmetadata_dereorder_generic( avg_azimuth_index ); /*Q0*/ + avg_azimuth_index = add( avg_azimuth_index, shr( avg_azimuth_alphabet, 1 ) ); /*Q0*/ - gr_param_azith = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, 5 + 1 ); - IF( EQ_32( gr_param_azith, 5 ) ) /* all the azimuth distances are zero */ + gr_param_azith = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, 5 + 1 ); /*Q0*/ + IF( EQ_32( gr_param_azith, 5 ) ) /* all the azimuth distances are zero */ { FOR( b = start_band; b < nbands; b++ ) { @@ -3723,7 +3723,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( { FOR( m = 0; m < nblocks; m++ ) { - q_direction->band_data[b].azimuth_index[m] = ivas_dirac_project_azimuth_index( avg_azimuth_index, avg_azimuth_alphabet, azith_alph[b][m] ); + q_direction->band_data[b].azimuth_index[m] = ivas_dirac_project_azimuth_index( avg_azimuth_index, avg_azimuth_alphabet, azith_alph[b][m] ); /*Q0*/ move16(); IF( EQ_16( azith_alph[b][m], 1 ) ) @@ -3733,7 +3733,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->band_data[b].elevation_index[m], 0, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->band_data[b].elevation_index[m], 0, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -3756,15 +3756,15 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( { IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && EQ_16( idx, MASA_LIMIT_IDX_AVG_AZI ) && GT_16( nblocks, 1 ) ) { - use_adapt_avg = bitstream[*index]; + use_adapt_avg = bitstream[*index]; /*Q0*/ move16(); ( *index ) = sub( *index, 1 ); move16(); } - avg_azimuth_index_projected = ivas_dirac_project_azimuth_index( avg_azimuth_index, avg_azimuth_alphabet, azith_alph[b][m] ); - q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, azith_alph[b][m], gr_param_azith ); + avg_azimuth_index_projected = ivas_dirac_project_azimuth_index( avg_azimuth_index, avg_azimuth_alphabet, azith_alph[b][m] ); /*Q0*/ + q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, azith_alph[b][m], gr_param_azith ); /*Q0*/ move16(); - q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_ReorderElevationDecoded( q_direction->band_data[b].azimuth_index[m], avg_azimuth_index_projected, azith_alph[b][m] ); + q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_ReorderElevationDecoded( q_direction->band_data[b].azimuth_index[m], avg_azimuth_index_projected, azith_alph[b][m] ); /*Q0*/ move16(); IF( EQ_16( azith_alph[b][m], 1 ) ) @@ -3774,7 +3774,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->band_data[b].elevation_index[m], 0, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->band_data[b].elevation_index[m], 0, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } @@ -3784,8 +3784,8 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( IF( LT_16( idx, MASA_LIMIT_IDX_AVG_AZI ) ) { ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[m], q_direction->band_data[b].elevation_fx[m], direction_vector_fx ); - v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); - v_add_32( avg_direction_vector_fx, direction_vector_fx, avg_direction_vector_fx, 3 ); + v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); /*Q25*/ + v_add_32( avg_direction_vector_fx, direction_vector_fx, avg_direction_vector_fx, 3 ); /*Q25*/ } ELSE { @@ -3795,16 +3795,16 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( { FOR( Word16 l = 0; l < 3; l++ ) { - avg_direction_vector_fx[l] = L_shr( avg_direction_vector_fx[l], 1 ); + avg_direction_vector_fx[l] = L_shr( avg_direction_vector_fx[l], 1 ); /*0.5f*/ move32(); } } /*compute the average direction per already coded subband */ ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[m], q_direction->band_data[b].elevation_fx[m], direction_vector_fx ); - v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); - v_add_32( avg_direction_vector_fx, direction_vector_fx, avg_direction_vector_fx, 3 ); + v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); /*Q25*/ + v_add_32( avg_direction_vector_fx, direction_vector_fx, avg_direction_vector_fx, 3 ); /*Q25*/ ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, 30 - 5, &avg_azimuth_fx, &avg_elevation_fx ); - avg_azimuth_index = quantize_phi_fx( L_add( avg_azimuth_fx, DEGREE_180_Q_22 ), 0, &avg_azimuth_fx, avg_azimuth_alphabet ); + avg_azimuth_index = quantize_phi_fx( L_add( avg_azimuth_fx, DEGREE_180_Q_22 ), 0, &avg_azimuth_fx, avg_azimuth_alphabet ); /*Q0*/ } } idx = add( idx, 1 ); @@ -4173,11 +4173,11 @@ static int16_t ivas_qmetadata_entropy_decode_dir( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_raw_decode_dir_512_fx( - IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, - const Word16 nbands, - const Word16 start_band, + IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /*Q0*/ + const Word16 nbands, /*Q0*/ + const Word16 start_band, /*Q0*/ const SPHERICAL_GRID_DATA *sph_grid16 /* i : spherical grid for deindexing */ ) { @@ -4265,11 +4265,11 @@ static int16_t ivas_qmetadata_raw_decode_dir_512( #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_raw_decode_dir_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, - const Word16 nbands, - const Word16 start_band, - const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding*/ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /*Q0*/ + const Word16 nbands, /*Q0*/ + const Word16 start_band, /*Q0*/ + const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding Q0*/ ) { Word16 b, m, azith_alph; @@ -4297,7 +4297,7 @@ static Word16 ivas_qmetadata_raw_decode_dir_fx( } ELSE { - diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; + diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; /*Q0*/ move16(); } @@ -4307,11 +4307,11 @@ static Word16 ivas_qmetadata_raw_decode_dir_fx( move32(); q_direction->band_data[b].elevation_index[m] = 0; move16(); - azith_alph = no_phi_masa[bits_direction_masa[diff_idx] - 1][0]; + azith_alph = no_phi_masa[bits_direction_masa[diff_idx] - 1][0]; /*Q0*/ move16(); - q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, azith_alph ); + q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, azith_alph ); /*Q0*/ move16(); - q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], 0, 1, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], 0, 1, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -4384,9 +4384,9 @@ static int16_t ivas_qmetadata_raw_decode_dir( /*! r: Value read from the bitstream */ #ifdef IVAS_FLOAT_FIXED static UWord16 ivas_qmetadata_DecodeQuasiUniform( - const UWord16 *bitstream, /* i : pointer to the bitstream to read */ - Word16 *index, /* i : position in the bitstream to start reading (gets updated with reading) */ - const UWord16 alphabet_size /* i : size of the alphabet, used to calculate the number of bits needed */ + const UWord16 *bitstream, /* i : pointer to the bitstream to read Q0*/ + Word16 *index, /* i : position in the bitstream to start reading (gets updated with reading) Q0*/ + const UWord16 alphabet_size /* i : size of the alphabet, used to calculate the number of bits needed Q0*/ ) { Word16 i, bits; @@ -4400,12 +4400,12 @@ static UWord16 ivas_qmetadata_DecodeQuasiUniform( move16(); FOR( i = 0; i < bits; i++ ) { - value = (UWord16) L_add( (UWord16) L_shl( value, 1 ), bitstream[( *index )--] ); + value = (UWord16) L_add( (UWord16) L_shl( value, 1 ), bitstream[( *index )--] ); /*Q0*/ } IF( GE_32( value, tresh ) ) { - value = (UWord16) L_add( (UWord16) L_sub( (UWord16) L_shl( value, 1 ), tresh ), bitstream[( *index )--] ); + value = (UWord16) L_add( (UWord16) L_sub( (UWord16) L_shl( value, 1 ), tresh ), bitstream[( *index )--] ); /*Q0*/ } return value; @@ -4450,7 +4450,7 @@ static uint16_t ivas_qmetadata_DecodeQuasiUniform( #ifdef IVAS_FLOAT_FIXED Word16 ivas_qmetadata_DecodeExtendedGR( - UWord16 *bitstream, /* i : pointer to the bitstream to read */ + UWord16 *bitstream, /* i : pointer to the bitstream to read Q0*/ Word16 *index, /* i/o: position in the bitstream to start reading (gets updated with reading) */ const Word16 alph_size, /* i : size of the alphabet, used to calculate the number of bits needed */ const Word16 gr_param /* i : GR parameter that indicates the limit for the most significant bits (msb) */ @@ -4460,10 +4460,10 @@ Word16 ivas_qmetadata_DecodeExtendedGR( UWord16 value; Word16 msb, lsb; - msb_size = shr( add( alph_size, sub( shl( 1, gr_param ), 1 ) ), gr_param ); /* ceil division */ + msb_size = shr( add( alph_size, sub( shl( 1, gr_param ), 1 ) ), gr_param ); /* ceil division Q0*/ IF( LE_16( msb_size, 3 ) ) { - value = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, alph_size ); + value = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, alph_size ); /*Q0*/ } ELSE { @@ -4480,7 +4480,7 @@ Word16 ivas_qmetadata_DecodeExtendedGR( IF( EQ_16( msb, sub( msb_size, 1 ) ) ) { - lsb = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, sub( alph_size, shl( sub( msb_size, 1 ), gr_param ) ) ); + lsb = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, sub( alph_size, shl( sub( msb_size, 1 ), gr_param ) ) ); /*Q0*/ } ELSE { @@ -4490,11 +4490,11 @@ Word16 ivas_qmetadata_DecodeExtendedGR( move16(); FOR( i = 0; i < gr_param; i++ ) { - lsb = extract_l( L_add( shl( lsb, 1 ), bitstream[( *index )--] ) ); + lsb = extract_l( L_add( shl( lsb, 1 ), bitstream[( *index )--] ) ); /*Q0*/ } } - value = (UWord16) add( shl( msb, gr_param ), lsb ); + value = (UWord16) add( shl( msb, gr_param ), lsb ); /*Q0*/ } return value; @@ -4555,15 +4555,15 @@ int16_t ivas_qmetadata_DecodeExtendedGR( /*! r: Elevation index as it will be read by the dequantizer */ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_ReorderElevationDecoded( - const Word16 elev_dist, /* i : Distance to the average extracted from the bitstream */ - const Word16 elev_avg, /* i : Average value over time-blocks extracted from the bitstream */ - const Word16 elev_alph /* i : elevation alphabet */ + const Word16 elev_dist, /* i : Distance to the average extracted from the bitstream Q0*/ + const Word16 elev_avg, /* i : Average value over time-blocks extracted from the bitstream Q0*/ + const Word16 elev_alph /* i : elevation alphabet Q0*/ ) { Word16 dist_reorder; Word16 elev_index_reorder; - dist_reorder = ivas_qmetadata_dereorder_generic( elev_dist ); + dist_reorder = ivas_qmetadata_dereorder_generic( elev_dist ); /*Q0*/ elev_index_reorder = add( elev_avg, dist_reorder ); IF( elev_index_reorder < 0 ) @@ -4575,7 +4575,7 @@ static Word16 ivas_qmetadata_ReorderElevationDecoded( elev_index_reorder = sub( elev_index_reorder, elev_alph ); } - return elev_index_reorder; + return elev_index_reorder; /*Q0*/ } #else static int16_t ivas_qmetadata_ReorderElevationDecoded( @@ -4612,11 +4612,11 @@ static int16_t ivas_qmetadata_ReorderElevationDecoded( #ifdef IVAS_FLOAT_FIXED static Word16 read_directions_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ - const UWord8 coding_subbands, /* i : number of directions */ - const UWord8 masa_subframes, /* i : number of tiles */ - UWord16 *bitstream, /* i : bitstream to be read */ - Word16 *pbit_pos, - Word16 *ind_order ) + const UWord8 coding_subbands, /* i : number of directions Q0*/ + const UWord8 masa_subframes, /* i : number of tiles Q0*/ + UWord16 *bitstream, /* i : bitstream to be read Q0*/ + Word16 *pbit_pos, /*Q0*/ + Word16 *ind_order /*Q0*/ ) { Word16 j, k, allowed_bits, last_j, nbits, fixed_rate; Word16 i; @@ -4636,14 +4636,14 @@ static Word16 read_directions_fx( IF( GT_16( coding_subbands, 1 ) ) { - j = ind_order[sub( coding_subbands, 1 )]; + j = ind_order[( coding_subbands - 1 )]; move16(); allowed_bits = 0; move16(); FOR( k = 0; k < masa_subframes; k++ ) { - allowed_bits = extract_l( L_add( allowed_bits, q_direction->band_data[j].bits_sph_idx[k] ) ); + allowed_bits = extract_l( L_add( allowed_bits, q_direction->band_data[j].bits_sph_idx[k] ) ); /*Q0*/ } last_j = sub( j, (Word16) ( allowed_bits == 0 ) ); @@ -4652,7 +4652,7 @@ static Word16 read_directions_fx( { i = ind_order[j]; move16(); - bits_dir0 = (Word16 *) q_direction->band_data[i].bits_sph_idx; + bits_dir0 = (Word16 *) q_direction->band_data[i].bits_sph_idx; /*Q0*/ nbits = 0; move16(); @@ -4701,13 +4701,13 @@ static Word16 read_directions_fx( FOR( k = 0; k < masa_subframes; k++ ) { - q_direction->band_data[i].bits_sph_idx[k] = bits_dir0[k]; + q_direction->band_data[i].bits_sph_idx[k] = bits_dir0[k]; /*Q0*/ move16(); IF( GT_16( bits_dir0[k], 2 ) ) { IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - q_direction->band_data[i].elevation_m_alphabet[k] = no_theta_masa[bits_dir0[k] - 3]; + q_direction->band_data[i].elevation_m_alphabet[k] = no_theta_masa[bits_dir0[k] - 3]; /*Q0*/ move16(); } ELSE @@ -4727,7 +4727,7 @@ static Word16 read_directions_fx( { IF( EQ_32( byteBuffer, 1 ) ) { - nbits = read_common_direction_fx( bitstream, q_direction, i, masa_subframes, allowed_bits, &bit_pos ); + nbits = read_common_direction_fx( bitstream, q_direction, i, masa_subframes, allowed_bits, &bit_pos ); /*Q0*/ } ELSE { @@ -4758,9 +4758,9 @@ static Word16 read_directions_fx( { /* decode elevation */ - nbits = add( nbits, decode_elevation_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); + nbits = add( nbits, decode_elevation_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); /*Q0*/ /* decode azimuth */ - nbits = add( nbits, decode_azimuth_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); + nbits = add( nbits, decode_azimuth_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); /*Q0*/ } } } @@ -4777,7 +4777,7 @@ static Word16 read_directions_fx( } ELSE { - last_j = q_direction->cfg.start_band; + last_j = q_direction->cfg.start_band; /*Q0*/ move16(); } @@ -4786,15 +4786,15 @@ static Word16 read_directions_fx( { i = ind_order[j]; move16(); - bits_dir0 = (Word16 *) q_direction->band_data[i].bits_sph_idx; + bits_dir0 = (Word16 *) q_direction->band_data[i].bits_sph_idx; /*Q0*/ nbits = 0; move16(); - allowed_bits = sum16_fx( bits_dir0, q_direction->cfg.nblocks ); + allowed_bits = sum16_fx( bits_dir0, q_direction->cfg.nblocks ); /*Q0*/ test(); IF( allowed_bits > 0 && EQ_16( masa_subframes, 1 ) ) { - nbits = add( nbits, decode_fixed_rate_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); + nbits = add( nbits, decode_fixed_rate_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); /*Q0*/ } ELSE { @@ -4808,7 +4808,7 @@ static Word16 read_directions_fx( { IF( GT_16( bits_dir0[k], use_vq ) ) { - use_vq = bits_dir0[k]; + use_vq = bits_dir0[k]; /*Q0*/ move16(); max_nb_idx = k; move16(); @@ -4835,7 +4835,7 @@ static Word16 read_directions_fx( test(); IF( EQ_32( byteBuffer, 1 ) || LE_16( use_vq, 1 ) ) { - nbits = read_common_direction_fx( bitstream, q_direction, i, masa_subframes, allowed_bits, &bit_pos ); + nbits = read_common_direction_fx( bitstream, q_direction, i, masa_subframes, allowed_bits, &bit_pos ); /*Q0*/ } ELSE { @@ -4869,7 +4869,7 @@ static Word16 read_directions_fx( } } - nbits = decode_azimuth2D_fx( q_direction, bitstream, coding_subbands, &bit_pos, masa_subframes ); + nbits = decode_azimuth2D_fx( q_direction, bitstream, coding_subbands, &bit_pos, masa_subframes ); /*Q0*/ } nbits = sub( *pbit_pos, bit_pos ); *pbit_pos = bit_pos; @@ -5113,10 +5113,10 @@ static int16_t read_directions( #ifdef IVAS_FLOAT_FIXED static Word16 decode_azimuth_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata structure */ - UWord16 *bitstream, /* i : bitstream to be read */ - Word16 *pbit_pos, /* i/o: current position in bitstream */ - const Word16 idx_subband, /* i : subband index */ - const Word16 masa_subframes /* i : number of tiles */ + UWord16 *bitstream, /* i : bitstream to be read Q0*/ + Word16 *pbit_pos, /* i/o: current position in bitstream Q0*/ + const Word16 idx_subband, /* i : subband index Q0*/ + const Word16 masa_subframes /* i : number of tiles Q0*/ ) { Word16 bit_pos, nbits, k; @@ -5183,18 +5183,18 @@ static Word16 decode_azimuth_fx( { byteBuffer = bitstream[bit_pos--]; move16(); - q_direction->band_data[idx_subband].azimuth_index[k] = byteBuffer; + q_direction->band_data[idx_subband].azimuth_index[k] = byteBuffer; /*Q0*/ move16(); - q_direction->band_data[idx_subband].azimuth_fx[k] = L_shl( L_mult0( q_direction->band_data[idx_subband].azimuth_index[k], -180 ), Q22 ); + q_direction->band_data[idx_subband].azimuth_fx[k] = L_shl( L_mult0( q_direction->band_data[idx_subband].azimuth_index[k], -180 ), Q22 ); /*Q22*/ move32(); } ELSE { - q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], sub( MASA_GR_ORD_AZ, (Word16) EQ_32( q_direction->band_data[idx_subband].bits_sph_idx[k], 2 ) ) ); + q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], sub( MASA_GR_ORD_AZ, (Word16) EQ_32( q_direction->band_data[idx_subband].bits_sph_idx[k], 2 ) ) ); /*Q0*/ move16(); - q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -5203,7 +5203,7 @@ static Word16 decode_azimuth_fx( ELSE { /* read bit to check if min removed encoding */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q22*/ move16(); bit_pos = sub( bit_pos, 1 ); IF( byteBuffer == 0 ) /* regular GR coding5 */ @@ -5220,9 +5220,9 @@ static Word16 decode_azimuth_fx( { IF( GT_16( no_phi_masa[L_sub( q_direction->band_data[idx_subband].bits_sph_idx[k], 1 )][q_direction->band_data[idx_subband].elevation_index[k]], 1 ) ) { - q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], extract_l( L_sub( MASA_GR_ORD_AZ, byteBuffer ) ) ); + q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], extract_l( L_sub( MASA_GR_ORD_AZ, byteBuffer ) ) ); /*Q0*/ move16(); - q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } ELSE @@ -5246,12 +5246,12 @@ static Word16 decode_azimuth_fx( { /* min removed GR coding */ /* read GR_order */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); /* read min index value */ maximum_s( q_direction->band_data[idx_subband].azimuth_m_alphabet, masa_subframes, &max_val ); - min_idx = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, max_val, MASA_GR_ORD_AZ ); + min_idx = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, max_val, MASA_GR_ORD_AZ ); /*Q0*/ FOR( k = 0; k < masa_subframes; k++ ) { @@ -5259,11 +5259,11 @@ static Word16 decode_azimuth_fx( { IF( GT_16( no_phi_masa[q_direction->band_data[idx_subband].bits_sph_idx[k] - 1][q_direction->band_data[idx_subband].elevation_index[k]], 1 ) ) { - q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], extract_l( L_sub( MASA_GR_ORD_AZ - 1, byteBuffer ) ) ); + q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], extract_l( L_sub( MASA_GR_ORD_AZ - 1, byteBuffer ) ) ); /*Q0*/ move16(); - q_direction->band_data[idx_subband].azimuth_index[k] = (UWord16) L_add( q_direction->band_data[idx_subband].azimuth_index[k], min_idx ); + q_direction->band_data[idx_subband].azimuth_index[k] = (UWord16) L_add( q_direction->band_data[idx_subband].azimuth_index[k], min_idx ); /*Q0*/ move16(); - q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } ELSE @@ -5455,10 +5455,10 @@ static int16_t decode_azimuth( #ifdef IVAS_FLOAT_FIXED static Word16 decode_elevation_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata structure */ - UWord16 *bitstream, /* i : input bitstream */ - Word16 *pbit_pos, /* i/o: current position to be read in bitstream*/ - const Word16 j, /* i : subband index */ - const Word16 masa_subframes /* i : number of tiles */ + UWord16 *bitstream, /* i : input bitstream Q0*/ + Word16 *pbit_pos, /* i/o: current position to be read in bitstream Q0*/ + const Word16 j, /* i : subband index Q0*/ + const Word16 masa_subframes /* i : number of tiles Q0*/ ) { Word16 nr_NO_INDEX, nbits; @@ -5485,7 +5485,7 @@ static Word16 decode_elevation_fx( { IF( LE_32( q_direction->band_data[j].bits_sph_idx[k], 2 ) ) { - q_direction->band_data[j].elevation_index[k] = MASA_NO_INDEX; + q_direction->band_data[j].elevation_index[k] = MASA_NO_INDEX; /*Q0*/ move16(); nr_NO_INDEX = add( nr_NO_INDEX, 1 ); q_direction->band_data[j].elevation_fx[k] = 0; @@ -5497,12 +5497,12 @@ static Word16 decode_elevation_fx( { IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - q_direction->band_data[j].elevation_m_alphabet[k] = no_theta_masa[q_direction->band_data[j].bits_sph_idx[k] - 3]; + q_direction->band_data[j].elevation_m_alphabet[k] = no_theta_masa[q_direction->band_data[j].bits_sph_idx[k] - 3]; /*Q0*/ move16(); } ELSE { - q_direction->band_data[j].elevation_m_alphabet[k] = shl( no_theta_masa[q_direction->band_data[j].bits_sph_idx[k] - 3], 1 ) - 1; + q_direction->band_data[j].elevation_m_alphabet[k] = shl( no_theta_masa[q_direction->band_data[j].bits_sph_idx[k] - 3], 1 ) - 1; /*Q0*/ move16(); } } @@ -5523,7 +5523,7 @@ static Word16 decode_elevation_fx( IF( EQ_32( byteBuffer, 1 ) ) /* same value */ { /* read value */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); byteBuffer = (UWord16) L_add( L_shl( byteBuffer, 1 ), bitstream[bit_pos] ); @@ -5536,9 +5536,9 @@ static Word16 decode_elevation_fx( { IF( LT_32( q_direction->band_data[j].elevation_index[k], MASA_NO_INDEX ) ) { - q_direction->band_data[j].elevation_index[k] = same_idx; + q_direction->band_data[j].elevation_index[k] = same_idx; /*Q0*/ move16(); - q_direction->band_data[j].elevation_fx[k] = deindex_elevation_fx( &q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].bits_sph_idx[k], q_direction->cfg.mc_ls_setup ); + q_direction->band_data[j].elevation_fx[k] = deindex_elevation_fx( &q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].bits_sph_idx[k], q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -5546,18 +5546,18 @@ static Word16 decode_elevation_fx( ELSE { /* not same; decode mean removed GR */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ bit_pos = sub( bit_pos, 1 ); move16(); - GR_ord_elevation = extract_l( L_sub( MASA_GR_ORD_EL, byteBuffer ) ); + GR_ord_elevation = extract_l( L_sub( MASA_GR_ORD_EL, byteBuffer ) ); /*Q0*/ FOR( k = 0; k < masa_subframes; k++ ) { IF( LT_32( q_direction->band_data[j].elevation_index[k], MASA_NO_INDEX ) ) { - q_direction->band_data[j].elevation_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[j].elevation_m_alphabet[k], GR_ord_elevation ); + q_direction->band_data[j].elevation_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[j].elevation_m_alphabet[k], GR_ord_elevation ); /*Q0*/ move16(); - q_direction->band_data[j].elevation_fx[k] = deindex_elevation_fx( &q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].bits_sph_idx[k], q_direction->cfg.mc_ls_setup ); + q_direction->band_data[j].elevation_fx[k] = deindex_elevation_fx( &q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].bits_sph_idx[k], q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -5571,9 +5571,9 @@ static Word16 decode_elevation_fx( IF( LT_32( q_direction->band_data[j].elevation_index[k], MASA_NO_INDEX ) && LE_16( no_phi_masa[sub( q_direction->band_data[j].bits_sph_idx[k], 1 )][q_direction->band_data[j].elevation_index[k]], 1 ) ) { - q_direction->band_data[j].azimuth_index[k] = MASA_NO_INDEX; + q_direction->band_data[j].azimuth_index[k] = MASA_NO_INDEX; /*Q0*/ move16(); - q_direction->band_data[j].azimuth_m_alphabet[k] = 1; + q_direction->band_data[j].azimuth_m_alphabet[k] = 1; /*Q0*/ move16(); } ELSE @@ -5582,12 +5582,12 @@ static Word16 decode_elevation_fx( move16(); IF( LT_32( q_direction->band_data[j].elevation_index[k], MASA_NO_INDEX ) ) { - q_direction->band_data[j].azimuth_m_alphabet[k] = no_phi_masa[sub( q_direction->band_data[j].bits_sph_idx[k], 1 )][q_direction->band_data[j].elevation_index[k]]; + q_direction->band_data[j].azimuth_m_alphabet[k] = no_phi_masa[sub( q_direction->band_data[j].bits_sph_idx[k], 1 )][q_direction->band_data[j].elevation_index[k]]; /*Q0*/ move16(); } ELSE { - q_direction->band_data[j].azimuth_m_alphabet[k] = no_phi_masa[sub( q_direction->band_data[j].bits_sph_idx[k], 1 )][0]; + q_direction->band_data[j].azimuth_m_alphabet[k] = no_phi_masa[sub( q_direction->band_data[j].bits_sph_idx[k], 1 )][0]; /*Q0*/ move16(); q_direction->band_data[j].elevation_index[k] = 0; move16(); @@ -5725,10 +5725,10 @@ static int16_t decode_elevation( #ifdef IVAS_FLOAT_FIXED static Word16 decode_fixed_rate_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata */ - const UWord16 *bitstream, /* i : bitstream to be read */ - Word16 *pbit_pos, /* i/o: position in bitstream */ - const Word16 b, /* i : subband index */ - const Word16 nblocks /* i : number of tiles in subband */ + const UWord16 *bitstream, /* i : bitstream to be read Q0*/ + Word16 *pbit_pos, /* i/o: position in bitstream Q0*/ + const Word16 b, /* i : subband index Q0*/ + const Word16 nblocks /* i : number of tiles in subband Q0*/ ) { Word16 nbits, m, i; @@ -5743,13 +5743,13 @@ static Word16 decode_fixed_rate_fx( move16(); FOR( i = 0; i < q_direction->band_data[b].bits_sph_idx[m]; i++ ) { - value = (UWord16) L_add( L_shl( value, 1 ), bitstream[( *pbit_pos )--] ); + value = (UWord16) L_add( L_shl( value, 1 ), bitstream[( *pbit_pos )--] ); /*Q0*/ move16(); } - q_direction->band_data[b].spherical_index[m] = value; + q_direction->band_data[b].spherical_index[m] = value; /*Q0*/ move16(); - nbits = extract_l( L_add( nbits, q_direction->band_data[b].bits_sph_idx[m] ) ); + nbits = extract_l( L_add( nbits, q_direction->band_data[b].bits_sph_idx[m] ) ); /*Q0*/ deindex_spherical_component_fx( q_direction->band_data[b].spherical_index[m], &q_direction->band_data[b].azimuth_fx[m], &q_direction->band_data[b].elevation_fx[m], &q_direction->band_data[b].azimuth_index[m], &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); } @@ -5805,10 +5805,10 @@ static int16_t decode_fixed_rate( #ifdef IVAS_FLOAT_FIXED static Word16 decode_azimuth2D_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata structure */ - UWord16 *bitstream, /* i : bitstream to be read */ - const Word16 coding_subbands, /* i : number of subbands */ - Word16 *pbit_pos, - const Word16 no_frames ) + UWord16 *bitstream, /* i : bitstream to be read Q0*/ + const Word16 coding_subbands, /* i : number of subbands Q0*/ + Word16 *pbit_pos, /*Q0*/ + const Word16 no_frames /*Q0*/ ) { Word16 i, j, k; Word16 allowed_bits, nbits; @@ -5823,7 +5823,7 @@ static Word16 decode_azimuth2D_fx( move16(); FOR( j = 0; j < coding_subbands; j++ ) { - bits_dir0 = (Word16 *) q_direction->band_data[j].bits_sph_idx; + bits_dir0 = (Word16 *) q_direction->band_data[j].bits_sph_idx; /*Q0*/ allowed_bits = sum16_fx( bits_dir0, no_frames ); IF( allowed_bits > 0 ) @@ -5852,7 +5852,7 @@ static Word16 decode_azimuth2D_fx( set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_frames ); FOR( k = 0; k < s_min( allowed_bits, no_frames ); k++ ) { - q_direction->band_data[j].azimuth_fx[k] = L_shl( L_mult0( -180, bitstream[bit_pos] ), Q22 ); + q_direction->band_data[j].azimuth_fx[k] = L_shl( L_mult0( -180, bitstream[bit_pos] ), Q22 ); /*Q22*/ move32(); bit_pos = sub( bit_pos, 1 ); nbits = add( nbits, 1 ); @@ -5860,7 +5860,7 @@ static Word16 decode_azimuth2D_fx( } ELSE { - nbits = add( nbits, read_truncGR_azimuth_fx( bitstream, q_direction, j, no_frames, &bit_pos ) ); + nbits = add( nbits, read_truncGR_azimuth_fx( bitstream, q_direction, j, no_frames, &bit_pos ) ); /*Q0*/ } } ELSE @@ -5871,7 +5871,7 @@ static Word16 decode_azimuth2D_fx( move16(); FOR( i = 0; i < bits_dir0[k]; i++ ) { - Buffer = (UWord16) L_add( L_shl( Buffer, 1 ), bitstream[bit_pos] ); + Buffer = (UWord16) L_add( L_shl( Buffer, 1 ), bitstream[bit_pos] ); /*Q0*/ bit_pos = sub( bit_pos, 1 ); } @@ -5879,15 +5879,15 @@ static Word16 decode_azimuth2D_fx( IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - q_direction->band_data[j].azimuth_fx[k] = L_sub( L_shl( 360, sub( Q22, bits_dir0[k] ) ) * Buffer, L_shl( 180, Q22 ) ); + q_direction->band_data[j].azimuth_fx[k] = L_sub( W_extract_l( W_mult0_32_32( L_shl( 360, sub( Q22, bits_dir0[k] ) ), Buffer ) ), L_shl( 180, Q22 ) ); /*Q22*/ move32(); q_direction->band_data[j].azimuth_fx[k] = companding_azimuth_fx( q_direction->band_data[j].azimuth_fx[k], q_direction->cfg.mc_ls_setup, - (Word16) GT_32( q_direction->band_data[j].elevation_fx[k], L_shl( MC_MASA_THR_ELEVATION, 22 ) ), -1 ); + (Word16) GT_32( q_direction->band_data[j].elevation_fx[k], L_shl( MC_MASA_THR_ELEVATION, 22 ) ), -1 ); /*Q22*/ move32(); } ELSE { - q_direction->band_data[j].azimuth_fx[k] = L_shl( 360, sub( Q22, bits_dir0[k] ) ) * Buffer - L_shl( 180, Q22 ); + q_direction->band_data[j].azimuth_fx[k] = L_sub( W_extract_l( W_mult0_32_32( L_shl( 360, sub( Q22, bits_dir0[k] ) ), Buffer ) ), L_shl( 180, Q22 ) ); /*Q22*/ move32(); } } @@ -6000,8 +6000,8 @@ static int16_t decode_azimuth2D( #ifdef IVAS_FLOAT_FIXED static void set_zero_direction_fx( IVAS_QDIRECTION *q_direction, - const Word16 idx_band, - const Word16 len ) + const Word16 idx_band, /*Q0*/ + const Word16 len /*Q0*/ ) { Word16 k; @@ -6051,11 +6051,11 @@ static void set_zero_direction( #ifdef IVAS_FLOAT_FIXED static Word16 read_truncGR_azimuth_fx( - UWord16 *bitstream, /* i : bitstream to be read */ + UWord16 *bitstream, /* i : bitstream to be read Q0*/ IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata structure */ - const Word16 j, /* i : subband index */ - const Word16 no_subframes, /* i : number of tiles */ - Word16 *pbit_pos /* i/o: position in bitstream */ + const Word16 j, /* i : subband index Q0*/ + const Word16 no_subframes, /* i : number of tiles Q0*/ + Word16 *pbit_pos /* i/o: position in bitstream Q0*/ ) { Word16 i; @@ -6063,7 +6063,7 @@ static Word16 read_truncGR_azimuth_fx( UWord16 idx; Word16 no_symb, allowed_bits; - allowed_bits = sum16_fx( (Word16 *) q_direction->band_data[j].bits_sph_idx, no_subframes ); + allowed_bits = sum16_fx( (Word16 *) q_direction->band_data[j].bits_sph_idx, no_subframes ); /*Q0*/ nbits = 0; move16(); IF( LE_16( allowed_bits, add( no_subframes, 1 ) ) ) @@ -6077,7 +6077,7 @@ static Word16 read_truncGR_azimuth_fx( } ELSE { - q_direction->band_data[j].azimuth_fx[i] = ( -180 * ONE_IN_Q22 ); + q_direction->band_data[j].azimuth_fx[i] = ( -180 * ONE_IN_Q22 ); /*Q22*/ move32(); } nbits = add( nbits, 1 ); @@ -6105,21 +6105,21 @@ static Word16 read_truncGR_azimuth_fx( FOR( i = 0; i < no_subframes; i++ ) { idx = ivas_qmetadata_DecodeExtendedGR( bitstream, pbit_pos, no_symb, 0 ); - q_direction->band_data[j].azimuth_index[i] = idx; + q_direction->band_data[j].azimuth_index[i] = idx; /*Q0*/ move16(); IF( NE_16( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - q_direction->band_data[j].azimuth_fx[i] = cb_azi_chan_fx[(UWord16) L_shr( (UWord16) L_add( idx, 1 ), 1 )]; + q_direction->band_data[j].azimuth_fx[i] = cb_azi_chan_fx[(UWord16) ( (UWord16) ( idx + 1 ) / 2 )]; /*Q22*/ move32(); IF( L_and( idx, 1 ) > 0 ) { - q_direction->band_data[j].azimuth_fx[i] = L_negate( q_direction->band_data[j].azimuth_fx[i] ); + q_direction->band_data[j].azimuth_fx[i] = L_negate( q_direction->band_data[j].azimuth_fx[i] ); /*Q22*/ move32(); } } ELSE { - q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[idx]; + q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[idx]; /*Q22*/ move32(); } } @@ -6207,12 +6207,12 @@ static int16_t read_truncGR_azimuth( /*! r: number of bits read */ #ifdef IVAS_FLOAT_FIXED static Word16 read_common_direction_fx( - UWord16 *bitstream, /* i : bitstream to be read */ + UWord16 *bitstream, /* i : bitstream to be read Q0*/ IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ - const Word16 j, /* i : subband index */ - const Word16 no_subframes, /* i : number of tiles */ - const Word16 bits_total, /* i : number of bits for subband directional data */ - Word16 *pbit_pos /* i/o: position in bitstream */ + const Word16 j, /* i : subband index Q0*/ + const Word16 no_subframes, /* i : number of tiles Q0*/ + const Word16 bits_total, /* i : number of bits for subband directional data Q0*/ + Word16 *pbit_pos /* i/o: position in bitstream Q0*/ ) { Word16 nbits; @@ -6236,10 +6236,10 @@ static Word16 read_common_direction_fx( { FOR( i = 0; i < s_min( no_subframes, bits_total ); i++ ) { - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos--]; /*Q0*/ move16(); /*qdirection->azimuth_index[j][i] = (uint16_t)byteBuffer; */ - q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[byteBuffer]; + q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[byteBuffer]; /*Q22*/ move32(); nbits = add( nbits, 1 ); } @@ -6251,7 +6251,7 @@ static Word16 read_common_direction_fx( } - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); bits_el = 1; @@ -6260,7 +6260,7 @@ static Word16 read_common_direction_fx( /* elevation is already set to 0*/ IF( EQ_32( byteBuffer, 1 ) ) { - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos--]; /*Q0*/ move16(); bits_el = add( bits_el, 1 ); nbits = add( nbits, 1 ); @@ -6268,7 +6268,7 @@ static Word16 read_common_direction_fx( { FOR( i = 0; i < no_subframes; i++ ) { - q_direction->band_data[j].elevation_fx[i] = delta_theta_masa_fx[2]; + q_direction->band_data[j].elevation_fx[i] = delta_theta_masa_fx[2]; /*Q22*/ move32(); } } @@ -6282,7 +6282,7 @@ static Word16 read_common_direction_fx( { FOR( i = 0; i < no_subframes; i++ ) { - q_direction->band_data[j].elevation_fx[i] = L_negate( delta_theta_masa_fx[2] ); + q_direction->band_data[j].elevation_fx[i] = L_negate( delta_theta_masa_fx[2] ); /*Q22*/ move32(); } } @@ -6294,13 +6294,13 @@ static Word16 read_common_direction_fx( nbits = add( nbits, 1 ); IF( byteBuffer == 0 ) { - set32_fx( q_direction->band_data[j].elevation_fx, ( 90 * ONE_IN_Q22 ), no_subframes ); - set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_subframes ); + set32_fx( q_direction->band_data[j].elevation_fx, ( 90 * ONE_IN_Q22 ), no_subframes ); /*Q22*/ + set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_subframes ); /*Q22*/ } ELSE { - set32_fx( q_direction->band_data[j].elevation_fx, ( -90 * ONE_IN_Q22 ), no_subframes ); - set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_subframes ); + set32_fx( q_direction->band_data[j].elevation_fx, ( -90 * ONE_IN_Q22 ), no_subframes ); /*Q22*/ + set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_subframes ); /*Q22*/ } *pbit_pos = bit_pos; move16(); @@ -6310,18 +6310,18 @@ static Word16 read_common_direction_fx( } } - bits_el = sub( sum16_fx( (Word16 *) q_direction->band_data[j].bits_sph_idx, no_subframes ), bits_el ); + bits_el = sub( sum16_fx( (Word16 *) q_direction->band_data[j].bits_sph_idx, no_subframes ), bits_el ); /*Q0*/ IF( LE_16( bits_el, add( no_subframes, 1 ) ) ) { nbits = add( nbits, s_min( no_subframes, bits_el ) ); FOR( i = 0; i < s_min( no_subframes, bits_el ); i++ ) { - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); /*qdirection->azimuth_index[j][i] = (uint16_t) byteBuffer; */ - q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[byteBuffer]; + q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[byteBuffer]; /*Q22*/ move32(); } } @@ -6456,9 +6456,9 @@ static int16_t read_common_direction( #ifdef IVAS_FLOAT_FIXED static void decode_spread_coherence_fx( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: quantized metadata structure */ - Word16 idx_d, /* i : direction index */ - const Word16 no_frames, /* i : number of time subframes */ - const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding */ + Word16 idx_d, /* i : direction index Q0*/ + const Word16 no_frames, /* i : number of time subframes Q0*/ + const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding Q0*/ ) { Word16 i, j; @@ -6486,21 +6486,21 @@ static void decode_spread_coherence_fx( { IF( LE_16( coding_subbands_0, 8 ) ) { - Copy( MASA_grouping_8_to_5, MASA_grouping, 8 ); + Copy( MASA_grouping_8_to_5, MASA_grouping, 8 ); /*Q0*/ } ELSE IF( LE_16( coding_subbands_0, 12 ) ) { - Copy( MASA_grouping_12_to_5, MASA_grouping, 12 ); + Copy( MASA_grouping_12_to_5, MASA_grouping, 12 ); /*Q0*/ } ELSE IF( LE_16( coding_subbands_0, 18 ) ) { - Copy( MASA_grouping_18_to_5, MASA_grouping, 18 ); + Copy( MASA_grouping_18_to_5, MASA_grouping, 18 ); /*Q0*/ } ELSE { IF( LE_16( coding_subbands_0, 24 ) ) { - Copy( MASA_grouping_24_to_5, MASA_grouping, 24 ); + Copy( MASA_grouping_24_to_5, MASA_grouping, 24 ); /*Q0*/ } } } @@ -6528,7 +6528,7 @@ static void decode_spread_coherence_fx( FOR( i = 0; i < coding_subbands; i++ ) { - var_azi_fx = var_32_fx( q_direction->band_data[i].azimuth_fx, no_frames, 22 ); + var_azi_fx = var_32_fx( q_direction->band_data[i].azimuth_fx, no_frames, 22 ); /*Q22*/ IF( hrmasa_flag ) { minimum_s( (Word16 *) ( q_direction->band_data[i].energy_ratio_index ), q_direction->cfg.nblocks, &min_index ); @@ -6536,13 +6536,13 @@ static void decode_spread_coherence_fx( } ELSE { - min_index = q_direction->band_data[i].energy_ratio_index[0]; + min_index = q_direction->band_data[i].energy_ratio_index[0]; /*Q0*/ move16(); } IF( LT_64( var_azi_fx, L_shl( MASA_DELTA_AZI_DCT0, 22 ) ) ) { - idx_sub_cb = i_mult( MASA_NO_CV_COH, min_index ); + idx_sub_cb = i_mult( MASA_NO_CV_COH, min_index ); /*Q0*/ } ELSE { @@ -6555,12 +6555,12 @@ static void decode_spread_coherence_fx( IF( LT_16( coding_subbands, coding_subbands_0 ) ) { assert( EQ_16( idx_d, 1 ) ); - dct_coh_fx[i][1] = coherence_cb1_masa_fx[L_add( L_mult0( MASA_grouping[two_dir_band[i]], MASA_NO_CV_COH1 ), q_direction->coherence_band_data[i].spread_coherence_dct1_index )]; + dct_coh_fx[i][1] = coherence_cb1_masa_fx[( ( MASA_grouping[two_dir_band[i]] * MASA_NO_CV_COH1 ) + q_direction->coherence_band_data[i].spread_coherence_dct1_index )]; /*Q21*/ move32(); } ELSE { - dct_coh_fx[i][1] = coherence_cb1_masa_fx[L_add( L_mult0( MASA_grouping[i], MASA_NO_CV_COH1 ), q_direction->coherence_band_data[i].spread_coherence_dct1_index )]; + dct_coh_fx[i][1] = coherence_cb1_masa_fx[( ( MASA_grouping[i] * MASA_NO_CV_COH1 ) + q_direction->coherence_band_data[i].spread_coherence_dct1_index )]; /*Q21*/ move32(); } @@ -6697,13 +6697,13 @@ static void decode_spread_coherence( /*! r: number of bits read */ #ifdef IVAS_FLOAT_FIXED static ivas_error read_huf( - Word16 *num_bits_read, - const UWord16 *bitstream, /* i : bitstream to be read */ - UWord16 *out, /* o : decoded value */ - const Word16 start_pos, /* i : starting position for reading */ - const Word16 len, /* i : number of codewords */ - const Word16 *huff_code, /* i : Huffman table */ - const Word16 max_len /* i : maximum codeword length */ + Word16 *num_bits_read, /*Q0*/ + const UWord16 *bitstream, /* i : bitstream to be read Q0*/ + UWord16 *out, /* o : decoded value Q0*/ + const Word16 start_pos, /* i : starting position for reading Q0*/ + const Word16 len, /* i : number of codewords Q0*/ + const Word16 *huff_code, /* i : Huffman table Q0*/ + const Word16 max_len /* i : maximum codeword length Q0*/ ) { Word16 done = 0, end_pos; @@ -6720,9 +6720,9 @@ static ivas_error read_huf( move16(); WHILE( !done && LT_16( nbits, max_len ) ) { - ByteBuffer = bitstream[end_pos--]; + ByteBuffer = bitstream[end_pos--]; /*Q0*/ move16(); - val = add( shl( val, 1 ), ByteBuffer & 1 ); + val = add( shl( val, 1 ), ByteBuffer & 1 ); /*Q0*/ nbits = add( nbits, 1 ); FOR( i = 0; i < len; i++ ) { @@ -6791,12 +6791,12 @@ static ivas_error read_huf( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 read_GR_min_removed_data( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ - const Word16 *no_cv_vec, - const Word16 no_data, - Word16 *decoded_idx, - const Word16 no_symb ) + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ + const Word16 *no_cv_vec, /*Q0*/ + const Word16 no_data, /*Q0*/ + Word16 *decoded_idx, /*Q0*/ + const Word16 no_symb /*Q0*/ ) { Word16 j; Word16 bit_pos; @@ -6808,7 +6808,7 @@ static Word16 read_GR_min_removed_data( move16(); /* read GR order */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); nbits = 1; @@ -6817,7 +6817,7 @@ static Word16 read_GR_min_removed_data( /* read min index */ bits_GR = bit_pos; move16(); - min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, no_symb, 0 ); + min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, no_symb, 0 ); /*Q0*/ nbits = add( nbits, sub( bits_GR, bit_pos ) ); /* read GR data */ @@ -6827,7 +6827,7 @@ static Word16 read_GR_min_removed_data( move16(); IF( GT_16( no_cv_vec[j], 1 ) ) { - decoded_idx[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), extract_l( L_and( byteBuffer, 1 ) ) ); + decoded_idx[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), extract_l( L_and( byteBuffer, 1 ) ) ); /*Q0*/ move16(); nbits = add( nbits, sub( bits_GR, bit_pos ) ); } @@ -6914,12 +6914,12 @@ static int16_t read_GR_min_removed_data( #ifdef IVAS_FLOAT_FIXED static Word16 decode_fixed_rate_composed_index_coherence_fx( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ - const Word16 no_bands, - Word16 *no_cv_vec, - UWord16 *decoded_index, - const Word16 no_symb ) + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ + const Word16 no_bands, /*Q0*/ + Word16 *no_cv_vec, /*Q0*/ + UWord16 *decoded_index, /*Q0*/ + const Word16 no_symb /*Q0*/ ) { /* fixed rate */ UWord64 no_cb; @@ -6951,13 +6951,13 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( { IF( GT_16( no_cv_vec[j], no_vals_local ) ) { - no_cv_vec[j] = no_vals_local; + no_cv_vec[j] = no_vals_local; /*Q0*/ move16(); } } } - half_no_bands = shr( no_bands, 1 ); + half_no_bands = shr( no_bands, 1 ); /* no_bands / 2 */ IF( GT_16( sum16_fx( no_cv_vec, no_bands ), MASA_COH_LIMIT_2IDX ) ) { no_cb = 1; @@ -6965,7 +6965,7 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( FOR( j = 0; j < half_no_bands; j++ ) { - no_cb *= no_cv_vec[j]; + no_cb *= no_cv_vec[j]; /*Q0*/ move16(); } no_bits_vec = (Word16) ceil_log_2( no_cb ); @@ -6973,7 +6973,7 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( move64(); FOR( j = half_no_bands; j < no_bands; j++ ) { - no_cb *= no_cv_vec[j]; + no_cb *= no_cv_vec[j]; /*Q0*/ move16(); } no_bits_vec1 = (Word16) ceil_log_2( no_cb ); @@ -6984,7 +6984,7 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( move64(); FOR( j = 0; j < no_bands; j++ ) { - no_cb *= no_cv_vec[j]; + no_cb *= no_cv_vec[j]; /*Q0*/ move16(); } no_bits_vec = (Word16) ceil_log_2( no_cb ); @@ -6997,7 +6997,9 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( move64(); FOR( j = 0; j < no_bits_vec; j++ ) { - idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos--]; + idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); + move64(); } nbits = add( nbits, no_bits_vec ); @@ -7008,7 +7010,9 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( move64(); FOR( j = 0; j < no_bits_vec1; j++ ) { - idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos--]; + idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); + move64(); } nbits = add( nbits, no_bits_vec1 ); decode_combined_index_fx( idx_fr, &no_cv_vec[half_no_bands], &temp_index[half_no_bands], half_no_bands ); @@ -7019,7 +7023,9 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( move64(); FOR( j = 0; j < no_bits_vec; j++ ) { - idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos--]; + idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); + move64(); } nbits = add( nbits, no_bits_vec ); decode_combined_index_fx( idx_fr, no_cv_vec, temp_index, no_bands ); @@ -7027,12 +7033,12 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( FOR( j = 0; j < no_bands; j++ ) { - decoded_index[j] = temp_index[j]; + decoded_index[j] = temp_index[j]; /*Q0*/ move16(); } nbits = sub( *p_bit_pos, bit_pos ); - *p_bit_pos = bit_pos; + *p_bit_pos = bit_pos; /*Q0*/ move16(); return nbits; @@ -7156,11 +7162,11 @@ static int16_t decode_fixed_rate_composed_index_coherence( /*! r: number of bits read */ #ifdef IVAS_FLOAT_FIXED static Word16 read_coherence_data_hr_512_fx( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ IVAS_QMETADATA *hQMetaData, /* i/o: quantized metadata structure */ - const Word16 idx_dir, /* i : direction index */ - const Word16 nbits_coh ) + const Word16 idx_dir, /* i : direction index Q0*/ + const Word16 nbits_coh /*Q0*/ ) { Word16 j, k, i; Word16 nbands, nblocks; @@ -7189,18 +7195,18 @@ static Word16 read_coherence_data_hr_512_fx( move16(); FOR( i = 0; i < nbits_coh; i++ ) { - min_index = add( shl( min_index, 1 ), bitstream[( *p_bit_pos )] ); + min_index = add( shl( min_index, 1 ), bitstream[( *p_bit_pos )] ); /*Q0*/ ( *p_bit_pos ) = sub( ( *p_bit_pos ), 1 ); move16(); } /* read GR param */ - GR_param = bitstream[( *p_bit_pos )]; + GR_param = bitstream[( *p_bit_pos )]; /*Q0*/ move16(); ( *p_bit_pos ) = sub( ( *p_bit_pos ), 1 ); move16(); FOR( j = 0; j < nbands; j++ ) { - decoded_idx = ivas_qmetadata_DecodeExtendedGR( bitstream, p_bit_pos, shl( cb_size, 1 ), GR_param ); + decoded_idx = ivas_qmetadata_DecodeExtendedGR( bitstream, p_bit_pos, shl( cb_size, 1 ), GR_param ); /*Q0*/ IF( EQ_16( s_and( decoded_idx, 1 ), 1 ) ) { decoded_idx = add( shr( add( decoded_idx, 1 ), 1 ), min_index ); @@ -7210,7 +7216,7 @@ static Word16 read_coherence_data_hr_512_fx( decoded_idx = add( negate( shr( decoded_idx, 1 ) ), min_index ); } decoded_idx_fx = L_shl( decoded_idx, 9 ); - hQMetaData->q_direction[idx_dir].coherence_band_data[j].spread_coherence[k] = (UWord8) L_add( Mpy_32_32( decoded_idx_fx, delta_fx ), L_shr( delta_fx, 23 ) ); + hQMetaData->q_direction[idx_dir].coherence_band_data[j].spread_coherence[k] = (UWord8) L_add( Mpy_32_32( decoded_idx_fx, delta_fx ), L_shr( delta_fx, 23 ) ); /*Q0*/ move16(); } } @@ -7221,21 +7227,21 @@ static Word16 read_coherence_data_hr_512_fx( move16(); FOR( i = 0; i < nbits_coh; i++ ) { - min_index = add( shl( min_index, 1 ), bitstream[( *p_bit_pos )] ); + min_index = add( shl( min_index, 1 ), bitstream[( *p_bit_pos )] ); /*Q0*/ ( *p_bit_pos ) = sub( ( *p_bit_pos ), 1 ); move16(); } /* read GR param */ - GR_param = bitstream[( *p_bit_pos )]; + GR_param = bitstream[( *p_bit_pos )]; /*Q0*/ move16(); ( *p_bit_pos ) = sub( ( *p_bit_pos ), 1 ); move16(); FOR( j = 0; j < nbands; j++ ) { - decoded_idx = add( ivas_qmetadata_DecodeExtendedGR( bitstream, p_bit_pos, cb_size - min_index, GR_param ), min_index ); - decoded_idx_fx = L_shl( decoded_idx, 9 ); - hQMetaData->q_direction[idx_dir].coherence_band_data[j].spread_coherence[k] = (UWord8) L_add( Mpy_32_32( decoded_idx_fx, delta_fx ), L_shr( delta_fx, 23 ) ); + decoded_idx = add( ivas_qmetadata_DecodeExtendedGR( bitstream, p_bit_pos, cb_size - min_index, GR_param ), min_index ); /*Q0*/ + decoded_idx_fx = L_shl( decoded_idx, 9 ); /*Q9*/ + hQMetaData->q_direction[idx_dir].coherence_band_data[j].spread_coherence[k] = (UWord8) L_add( Mpy_32_32( decoded_idx_fx, delta_fx ), L_shr( delta_fx, 23 ) ); /*Q0*/ move16(); } } @@ -7328,11 +7334,11 @@ static int16_t read_coherence_data_hr_512( /*! r: number of bits read */ #ifdef IVAS_FLOAT_FIXED static Word16 read_coherence_data_fx( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ IVAS_QMETADATA *hQMetaData, /* i/o: quantized metadata structure */ - const Word16 idx_dir, /* i : direction index */ - const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding*/ + const Word16 idx_dir, /* i : direction index Q0*/ + const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding Q0*/ ) { Word16 j; @@ -7357,7 +7363,7 @@ static Word16 read_coherence_data_fx( coding_subbands = hQMetaData->q_direction[idx_dir].cfg.nbands; move16(); - extra_cv = idiv1616( coding_subbands, MASA_FACTOR_CV_COH ); + extra_cv = idiv1616( coding_subbands, MASA_FACTOR_CV_COH ); /*Q0*/ move16(); q_direction = &( hQMetaData->q_direction[idx_dir] ); bit_pos = *p_bit_pos; @@ -7371,11 +7377,11 @@ static Word16 read_coherence_data_fx( { IF( hrmasa_flag ) { - idx_ER = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], 1 ) ), extra_cv ) ); + idx_ER = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], 1 ) ), extra_cv ) ); /*Q0*/ } ELSE { - idx_ER = extract_l( L_add( L_sub( 7, q_direction->band_data[j].energy_ratio_index_mod[0] ), extra_cv ) ); + idx_ER = extract_l( L_add( L_sub( 7, q_direction->band_data[j].energy_ratio_index_mod[0] ), extra_cv ) ); /*Q0*/ } no_cv_vec[j] = add( idx_ER, 1 ); move16(); @@ -7390,7 +7396,7 @@ static Word16 read_coherence_data_fx( return 0; } - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); nbits = add( nbits, 1 ); @@ -7398,20 +7404,20 @@ static Word16 read_coherence_data_fx( IF( L_and( byteBuffer, 1 ) ) { /* decode GR min removed */ - nbits = add( nbits, read_GR_min_removed_data( bitstream, &bit_pos, no_cv_vec, coding_subbands, decoded_idx, MASA_MAX_NO_CV_SUR_COH + extra_cv ) ); + nbits = add( nbits, read_GR_min_removed_data( bitstream, &bit_pos, no_cv_vec, coding_subbands, decoded_idx, MASA_MAX_NO_CV_SUR_COH + extra_cv ) ); /*Q0*/ FOR( j = 0; j < coding_subbands; j++ ) { IF( GT_16( no_cv_vec[j], 1 ) ) { - num = i_mult( decoded_idx[j], 255 ); + num = i_mult( decoded_idx[j], 255 ); /*Q0*/ move16(); - den = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], hrmasa_flag ) ), coding_subbands / MASA_FACTOR_CV_COH ) ); + den = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], hrmasa_flag ) ), coding_subbands / MASA_FACTOR_CV_COH ) ); /*Q0*/ q_den = norm_s( den ); q_num = sub( norm_s( num ), 1 ); - res = div_s( shl( num, q_num ), shl( den, q_den ) ); + res = div_s( shl( num, q_num ), shl( den, q_den ) ); /*Q15*/ q_res = add( sub( 15, q_den ), q_num ); - res = L_shl( res, sub( 16, q_res ) ); - q_direction->coherence_band_data[j].spread_coherence[0] = (UWord8) ( round_fx( res ) ); + res = L_shl( res, sub( 16, q_res ) ); /*Q16*/ + q_direction->coherence_band_data[j].spread_coherence[0] = (UWord8) ( round_fx( res ) ); /*Q0*/ move16(); } ELSE @@ -7425,20 +7431,20 @@ static Word16 read_coherence_data_fx( { UWord16 decoded_index[MASA_MAXIMUM_CODING_SUBBANDS]; /* decode joint index */ - nbits = add( nbits, decode_fixed_rate_composed_index_coherence_fx( bitstream, &bit_pos, coding_subbands, no_cv_vec, decoded_index, add( MASA_NO_CV_COH, coding_subbands / MASA_FACTOR_CV_COH ) ) ); + nbits = add( nbits, decode_fixed_rate_composed_index_coherence_fx( bitstream, &bit_pos, coding_subbands, no_cv_vec, decoded_index, add( MASA_NO_CV_COH, coding_subbands / MASA_FACTOR_CV_COH ) ) ); /*Q0*/ FOR( j = 0; j < coding_subbands; j++ ) { IF( GT_16( no_cv_vec[j], 1 ) ) { - num = i_mult( decoded_index[j], 255 ); + num = i_mult( decoded_index[j], 255 ); /*Q0*/ move16(); - den = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], hrmasa_flag ) ), coding_subbands / MASA_FACTOR_CV_COH ) ); + den = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], hrmasa_flag ) ), coding_subbands / MASA_FACTOR_CV_COH ) ); /*Q0*/ q_den = norm_s( den ); q_num = sub( norm_s( num ), 1 ); - res = div_s( shl( num, q_num ), shl( den, q_den ) ); + res = div_s( shl( num, q_num ), shl( den, q_den ) ); /*Q15*/ q_res = add( sub( 15, q_den ), q_num ); - res = L_shl( res, sub( 16, q_res ) ); - q_direction->coherence_band_data[j].spread_coherence[0] = (UWord8) ( round_fx( res ) ); + res = L_shl( res, sub( 16, q_res ) ); /*Q16*/ + q_direction->coherence_band_data[j].spread_coherence[0] = (UWord8) ( round_fx( res ) ); /*Q0*/ move16(); } ELSE @@ -7455,14 +7461,14 @@ static Word16 read_coherence_data_fx( { IF( hrmasa_flag ) { - minimum_s( (Word16 *) ( q_direction->band_data[j].energy_ratio_index ), q_direction->cfg.nblocks, &min_index ); - no_cv_vec[j] = len_cb_dct0_masa[shr( min_index, 1 )]; - move16(); /* spread coherence DCT0*/ + minimum_s( (Word16 *) ( q_direction->band_data[j].energy_ratio_index ), q_direction->cfg.nblocks, &min_index ); /*Q0*/ + no_cv_vec[j] = len_cb_dct0_masa[( min_index / 2 )]; /*Q0*/ + move16(); /* spread coherence DCT0*/ } ELSE { - no_cv_vec[j] = len_cb_dct0_masa[q_direction->band_data[j].energy_ratio_index[0]]; - move16(); /* spread coherence DCT0*/ + no_cv_vec[j] = len_cb_dct0_masa[q_direction->band_data[j].energy_ratio_index[0]]; /*Q0*/ + move16(); /* spread coherence DCT0*/ } } @@ -7478,7 +7484,7 @@ static Word16 read_coherence_data_fx( move64(); } - no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); + no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); Q0 no_cb = 1; move64(); @@ -7488,13 +7494,14 @@ static Word16 read_coherence_data_fx( move64(); } - no_bits_vec1 = ceil_log_2( no_cb ); // (int16_t) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); + no_bits_vec1 = ceil_log_2( no_cb ); // (int16_t) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); Q0 dct0_index = 0; move64(); FOR( j = 0; j < no_bits_vec; j++ ) { - dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos--]; + dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); move64(); } @@ -7507,7 +7514,8 @@ static Word16 read_coherence_data_fx( move64(); FOR( j = 0; j < no_bits_vec1; j++ ) { - dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos--]; + dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); move64(); } @@ -7517,7 +7525,7 @@ static Word16 read_coherence_data_fx( FOR( j = 0; j < coding_subbands; j++ ) { - q_direction->coherence_band_data[j].spread_coherence_dct0_index = spr_coh_temp_index[j]; + q_direction->coherence_band_data[j].spread_coherence_dct0_index = spr_coh_temp_index[j]; /*Q0*/ move16(); } } @@ -7535,16 +7543,17 @@ static Word16 read_coherence_data_fx( move64(); } - no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); + no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); Q0 /* read joint index for DCT0 */ - no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); + no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); Q0 dct0_index = 0; move64(); FOR( j = 0; j < no_bits_vec; j++ ) { - dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos--]; + dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); move64(); } @@ -7556,7 +7565,7 @@ static Word16 read_coherence_data_fx( FOR( j = 0; j < coding_subbands; j++ ) { - q_direction->coherence_band_data[j].spread_coherence_dct0_index = spr_coh_temp_index[j]; + q_direction->coherence_band_data[j].spread_coherence_dct0_index = spr_coh_temp_index[j]; /*Q0*/ move16(); } } @@ -7565,7 +7574,7 @@ static Word16 read_coherence_data_fx( FOR( j = 0; j < coding_subbands; j++ ) { bits_GR = bit_pos; - idx_dct1[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, shl( MASA_NO_CV_COH1, 1 ), 0 ); + idx_dct1[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, shl( MASA_NO_CV_COH1, 1 ), 0 ); /*Q0*/ move16(); nbits = add( nbits, sub( bits_GR, bit_pos ) ); } @@ -7581,12 +7590,12 @@ static Word16 read_coherence_data_fx( { IF( L_and( idx_dct1[j], 1 ) ) { - q_direction->coherence_band_data[j].spread_coherence_dct1_index = (UWord16) L_add( L_shr( L_add( idx_dct1[j], 1 ), 1 ), av_index ); + q_direction->coherence_band_data[j].spread_coherence_dct1_index = (UWord16) L_add( L_shr( L_add( idx_dct1[j], 1 ), 1 ), av_index ); /*Q0*/ move16(); } ELSE { - q_direction->coherence_band_data[j].spread_coherence_dct1_index = (UWord16) L_add( L_shr( -idx_dct1[j], 1 ), av_index ); + q_direction->coherence_band_data[j].spread_coherence_dct1_index = (UWord16) L_add( L_shr( L_negate( idx_dct1[j] ), 1 ), av_index ); /*Q0*/ move16(); } } @@ -7996,8 +8005,8 @@ static int16_t read_surround_coherence( } #else static Word16 read_surround_coherence( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ IVAS_QMETADATA *hQMetaData /* i/o: quantized metadata structure */ ) { @@ -8034,16 +8043,16 @@ static Word16 read_surround_coherence( idx = s_max( sub( d, 1 ), 0 ); IF( EQ_16( hQMetaData->twoDirBands[j], 1 ) ) { - error_ratio_surr = L_sub( L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ), q_direction[1].band_data[idx].energy_ratio_fx[0] ); + error_ratio_surr = L_sub( L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ), q_direction[1].band_data[idx].energy_ratio_fx[0] ); /*Q30*/ } ELSE { - error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ); + error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ); /*Q30*/ } } ELSE { - error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ); + error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ); /*Q30*/ } IF( error_ratio_surr <= 0 ) @@ -8052,12 +8061,12 @@ static Word16 read_surround_coherence( move32(); no_cv_vec[j] = 1; move16(); - idx_ER[j] = masa_sq_fx( 0, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + idx_ER[j] = masa_sq_fx( 0, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); } ELSE { - idx_ER[j] = masa_sq_fx( error_ratio_surr, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + idx_ER[j] = masa_sq_fx( error_ratio_surr, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); no_cv_vec[j] = add( idx_cb_sur_coh_masa[idx_ER[j]], 2 ); move16(); @@ -8083,7 +8092,7 @@ static Word16 read_surround_coherence( } /* read how the surround coherence is encoded */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ bit_pos = sub( bit_pos, 1 ); move16(); bits_sur_coherence = add( bits_sur_coherence, 1 ); @@ -8092,14 +8101,14 @@ static Word16 read_surround_coherence( { /* GR decoding */ /* read GR order */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ bit_pos = sub( bit_pos, 1 ); bits_sur_coherence = add( bits_sur_coherence, 1 ); /* read min index */ bits_GR = bit_pos; move16(); - min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, MASA_MAX_NO_CV_SUR_COH, 0 ); + min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, MASA_MAX_NO_CV_SUR_COH, 0 ); /*Q0*/ bits_sur_coherence = add( bits_sur_coherence, sub( bits_GR, bit_pos ) ); /* read GR data */ @@ -8110,7 +8119,7 @@ static Word16 read_surround_coherence( /* decoding for min removed */ IF( GT_16( no_cv_vec[j], 1 ) ) { - idx_sur_coh[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), ( byteBuffer & 1 ) ); + idx_sur_coh[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), ( byteBuffer & 1 ) ); /*Q30*/ move16(); bits_sur_coherence = add( bits_sur_coherence, sub( bits_GR, bit_pos ) ); } @@ -8125,16 +8134,16 @@ static Word16 read_surround_coherence( { IF( GT_16( no_cv_vec[j], 1 ) ) { - hQMetaData->surcoh_band_data[j].sur_coherence_index = add( idx_sur_coh[j], min_index ); + hQMetaData->surcoh_band_data[j].sur_coherence_index = add( idx_sur_coh[j], min_index ); /*Q0*/ move16(); } ELSE { - hQMetaData->surcoh_band_data[j].sur_coherence_index = idx_sur_coh[j]; + hQMetaData->surcoh_band_data[j].sur_coherence_index = idx_sur_coh[j]; /*Q0*/ move16(); } - hQMetaData->surcoh_band_data[j].surround_coherence[0] = sur_coherence_cb_masa[add( shl( idx_cb_sur_coh_masa[idx_ER[j]], 3 ), hQMetaData->surcoh_band_data[j].sur_coherence_index )]; + hQMetaData->surcoh_band_data[j].surround_coherence[0] = sur_coherence_cb_masa[( ( idx_cb_sur_coh_masa[idx_ER[j]] * 8 ) + hQMetaData->surcoh_band_data[j].sur_coherence_index )]; /*Q0*/ move16(); } } @@ -8148,7 +8157,7 @@ static Word16 read_surround_coherence( FOR( j = 0; j < coding_subbands; j++ ) { - hQMetaData->surcoh_band_data[j].sur_coherence_index = sur_coh_temp_index[j]; + hQMetaData->surcoh_band_data[j].sur_coherence_index = sur_coh_temp_index[j]; /*Q0*/ move16(); } @@ -8157,7 +8166,7 @@ static Word16 read_surround_coherence( { IF( GT_16( no_cv_vec[j], 1 ) ) { - hQMetaData->surcoh_band_data[j].surround_coherence[0] = sur_coherence_cb_masa[add( shl( idx_cb_sur_coh_masa[idx_ER[j]], 3 ), hQMetaData->surcoh_band_data[j].sur_coherence_index )]; + hQMetaData->surcoh_band_data[j].surround_coherence[0] = sur_coherence_cb_masa[( ( idx_cb_sur_coh_masa[idx_ER[j]] * 8 ) + hQMetaData->surcoh_band_data[j].sur_coherence_index )]; /*Q0*/ move16(); } ELSE @@ -8172,7 +8181,7 @@ static Word16 read_surround_coherence( { FOR( k = 1; k < MAX_PARAM_SPATIAL_SUBFRAMES; k++ ) { - hQMetaData->surcoh_band_data[j].surround_coherence[k] = hQMetaData->surcoh_band_data[j].surround_coherence[0]; + hQMetaData->surcoh_band_data[j].surround_coherence[k] = hQMetaData->surcoh_band_data[j].surround_coherence[0]; /*Q0*/ move16(); } } @@ -8358,10 +8367,10 @@ static int16_t read_surround_coherence_hr( } #else static Word16 read_surround_coherence_hr_fx( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ IVAS_QMETADATA *hQMetaData, /* i/o: quantized metadata structure */ - Word64 energy_ratio[][MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES] ) + Word64 energy_ratio[][MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES] /*Q62*/ ) { Word16 coding_subbands; Word16 no_cv_vec[MASA_MAXIMUM_CODING_SUBBANDS]; @@ -8393,15 +8402,15 @@ static Word16 read_surround_coherence_hr_fx( error_ratio_surr_fx = ONE_IN_Q62; IF( EQ_32( hQMetaData->no_directions, 2 ) ) { - d = add( d, hQMetaData->twoDirBands[j] ); + d = add( d, hQMetaData->twoDirBands[j] ); /*Q0*/ idx = s_max( sub( d, 1 ), 0 ); error_ratio_surr_fx = W_sub( W_sub( ONE_IN_Q62, energy_ratio[0][j][sf] ), - energy_ratio[1][idx][sf] * hQMetaData->twoDirBands[j] ); + energy_ratio[1][idx][sf] * hQMetaData->twoDirBands[j] ); /*Q62*/ } ELSE { - error_ratio_surr_fx = W_sub( ONE_IN_Q62, energy_ratio[0][j][sf] ); + error_ratio_surr_fx = W_sub( ONE_IN_Q62, energy_ratio[0][j][sf] ); /*Q62*/ } IF( LE_64( error_ratio_surr_fx, ( 461168601842 ) ) ) // 1e-7 in Q62 @@ -8415,8 +8424,10 @@ static Word16 read_surround_coherence_hr_fx( } ELSE { - idx_ER[j] = 7; // masa_sq( error_ratio_surr, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); - no_cv_vec[j] = idx_cb_sur_coh_masa[idx_ER[j]] + 2; + idx_ER[j] = 7; // masa_sq( error_ratio_surr, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); + no_cv_vec[j] = add( idx_cb_sur_coh_masa[idx_ER[j]], 2 ); /*Q0*/ + move16(); + move16(); } } @@ -8438,7 +8449,7 @@ static Word16 read_surround_coherence_hr_fx( ELSE { /* read how the surround coherence is encoded */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); bits_sur_coherence = add( bits_sur_coherence, 1 ); @@ -8447,14 +8458,14 @@ static Word16 read_surround_coherence_hr_fx( { /* GR decoding */ /* read GR order */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); bits_sur_coherence = add( bits_sur_coherence, 1 ); /* read min index */ bits_GR = bit_pos; - min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, MASA_MAX_NO_CV_SUR_COH, 0 ); + min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, MASA_MAX_NO_CV_SUR_COH, 0 ); /*Q0*/ bits_sur_coherence = add( bits_sur_coherence, sub( bits_GR, bit_pos ) ); /* read GR data */ @@ -8465,7 +8476,7 @@ static Word16 read_surround_coherence_hr_fx( /* decoding for min removed */ IF( GT_16( no_cv_vec[j], 1 ) ) { - idx_sur_coh[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), ( byteBuffer & 1 ) ); + idx_sur_coh[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), ( byteBuffer & 1 ) ); /*Q0*/ move16(); bits_sur_coherence = add( bits_sur_coherence, sub( bits_GR, bit_pos ) ); } @@ -8480,14 +8491,14 @@ static Word16 read_surround_coherence_hr_fx( { IF( GT_16( no_cv_vec[j], 1 ) ) { - hQMetaData->surcoh_band_data[j].sur_coherence_index = (UWord16) L_add( (Word32) idx_sur_coh[j], L_deposit_l( min_index ) ); + hQMetaData->surcoh_band_data[j].sur_coherence_index = (UWord16) L_add( (Word32) idx_sur_coh[j], L_deposit_l( min_index ) ); /*Q0*/ move16(); - hQMetaData->surcoh_band_data[j].surround_coherence[sf] = sur_coherence_cb_masa[L_add( L_mult0( idx_cb_sur_coh_masa[idx_ER[j]], MASA_MAX_NO_CV_SUR_COH ), hQMetaData->surcoh_band_data[j].sur_coherence_index )]; + hQMetaData->surcoh_band_data[j].surround_coherence[sf] = sur_coherence_cb_masa[( ( idx_cb_sur_coh_masa[idx_ER[j]] * MASA_MAX_NO_CV_SUR_COH ) + hQMetaData->surcoh_band_data[j].sur_coherence_index )]; move16(); } ELSE { - hQMetaData->surcoh_band_data[j].sur_coherence_index = idx_sur_coh[j]; + hQMetaData->surcoh_band_data[j].sur_coherence_index = idx_sur_coh[j]; /*Q0*/ move16(); hQMetaData->surcoh_band_data[j].surround_coherence[sf] = 0; move16(); @@ -8504,7 +8515,7 @@ static Word16 read_surround_coherence_hr_fx( FOR( j = 0; j < coding_subbands; j++ ) { - hQMetaData->surcoh_band_data[j].sur_coherence_index = sur_coh_temp_index[j]; + hQMetaData->surcoh_band_data[j].sur_coherence_index = sur_coh_temp_index[j]; /*Q0*/ move16(); } @@ -8513,7 +8524,7 @@ static Word16 read_surround_coherence_hr_fx( { IF( GT_16( no_cv_vec[j], 1 ) ) { - hQMetaData->surcoh_band_data[j].surround_coherence[sf] = sur_coherence_cb_masa[L_add( L_mult0( idx_cb_sur_coh_masa[idx_ER[j]], MASA_MAX_NO_CV_SUR_COH ), hQMetaData->surcoh_band_data[j].sur_coherence_index )]; + hQMetaData->surcoh_band_data[j].surround_coherence[sf] = sur_coherence_cb_masa[( ( idx_cb_sur_coh_masa[idx_ER[j]] * MASA_MAX_NO_CV_SUR_COH ) + hQMetaData->surcoh_band_data[j].sur_coherence_index )]; /*Q0*/ move16(); } ELSE @@ -8544,10 +8555,10 @@ static Word16 read_surround_coherence_hr_fx( #ifdef IVAS_FLOAT_FIXED static void decode_combined_index_fx( - UWord64 comb_index, /* i : index to be decoded */ - const Word16 *no_cv_vec, /* i : number of codewords for each element*/ - UWord16 *index, /* o : decoded indexes */ - const Word16 len /* i : number of elements */ + UWord64 comb_index, /* i : index to be decoded Q0*/ + const Word16 *no_cv_vec, /* i : number of codewords for each element Q0*/ + UWord16 *index, /* o : decoded indexes Q0*/ + const Word16 len /* i : number of elements Q0*/ ) { Word16 i; @@ -8603,12 +8614,12 @@ static void decode_combined_index( #ifdef IVAS_FLOAT_FIXED static void read_stream_dct_coeffs_omasa_fx( - Word16 *q_idx, + Word16 *q_idx, /*Q0*/ Word32 *q_dct_data_fx, - const Word16 len_stream, - UWord16 *bit_stream, - Word16 *index, - const Word16 first_line ) + const Word16 len_stream, /*Q0*/ + UWord16 *bit_stream, /*Q0*/ + Word16 *index, /*Q0*/ + const Word16 first_line /*Q0*/ ) { Word16 sign, nbits; Word16 i, j, i_min; @@ -8625,7 +8636,7 @@ static void read_stream_dct_coeffs_omasa_fx( IF( !first_line ) { /* read sign */ - sign = bit_stream[( *index )--]; + sign = bit_stream[( *index )--]; /*Q0*/ move16(); IF( !sign ) { @@ -8639,10 +8650,10 @@ static void read_stream_dct_coeffs_omasa_fx( /* read DCT 0 component */ FOR( i = 0; i < BITS_MASA2TOTTAL_DCT0; i++ ) { - q_idx[0] = add( shl( q_idx[0], 1 ), bit_stream[( *index )--] ); + q_idx[0] = add( shl( q_idx[0], 1 ), bit_stream[( *index )--] ); /*Q0*/ move16(); } - q_idx[0] = i_mult( q_idx[0], sign ); + q_idx[0] = i_mult( q_idx[0], sign ); /*Q0*/ move16(); IF( q_idx[0] != 0 ) @@ -8656,14 +8667,14 @@ static void read_stream_dct_coeffs_omasa_fx( move16(); FOR( i = 0; i < j; i++ ) { - i_min = extract_l( L_add( shl( i_min, 1 ), bit_stream[( *index )--] ) ); + i_min = extract_l( L_add( shl( i_min, 1 ), bit_stream[( *index )--] ) ); /*Q0*/ } nbits = add( nbits, j ); /* read GR orders */ - GR1 = extract_l( L_add( bit_stream[( *index )--], 1 ) ); + GR1 = extract_l( L_add( bit_stream[( *index )--], 1 ) ); /*Q0*/ IF( EQ_16( GR1, 2 ) ) { - GR2 = bit_stream[( *index )--]; + GR2 = bit_stream[( *index )--]; /*Q0*/ move16(); } ELSE @@ -8675,25 +8686,25 @@ static void read_stream_dct_coeffs_omasa_fx( /* read GR data */ FOR( i = 1; i <= i_min; i++ ) { - q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR1 ); + q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR1 ); /*Q0*/ move16(); } - FOR( i = add( i_min, 1 ); i < len_stream; i++ ) + FOR( i = ( i_min + 1 ); i < len_stream; i++ ) { - q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR2 ); + q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR2 ); /*Q0*/ move16(); } } ELSE { /* read GR order (only one) */ - GR1 = bit_stream[( *index )]; + GR1 = bit_stream[( *index )]; /*Q0*/ move16(); ( *index ) = sub( ( *index ), 1 ); move16(); FOR( i = 1; i < len_stream; i++ ) { - q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR1 ); + q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR1 ); /*Q0*/ move16(); } } @@ -8706,12 +8717,12 @@ static void read_stream_dct_coeffs_omasa_fx( { IF( s_and( q_idx[i], 1 ) == 0 ) { - q_dct_data_fx[i] = L_shl( Mpy_32_16_1( step, negate( shl( q_idx[i], 6 ) ) ), 2 ); + q_dct_data_fx[i] = L_shl( Mpy_32_16_1( step, negate( shl( q_idx[i], 6 ) ) ), 2 ); /*Q25*/ move32(); } ELSE { - q_dct_data_fx[i] = L_shl( Mpy_32_16_1( step, shl( q_idx[i] + 1, 6 ) ), 2 ); + q_dct_data_fx[i] = L_shl( Mpy_32_16_1( step, shl( q_idx[i] + 1, 6 ) ), 2 ); /*Q25*/ move32(); } } @@ -8825,11 +8836,11 @@ static void read_stream_dct_coeffs_omasa( #ifdef IVAS_FLOAT_FIXED void ivas_omasa_decode_masa_to_total_fx( - UWord16 *bit_stream, - Word16 *index, - Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], - const Word16 nbands, - const Word16 nblocks ) + UWord16 *bit_stream, /*Q0*/ + Word16 *index, /*Q0*/ + Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /*Q30*/ + const Word16 nbands, /*Q0*/ + const Word16 nblocks /*Q0*/ ) { Word16 i, j, k; Word16 q_idx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; @@ -8852,7 +8863,7 @@ void ivas_omasa_decode_masa_to_total_fx( set16_fx( q_idx, 0, i_mult( nbands, nblocks ) ); FOR( i = 0; i < n_streams; i++ ) { - read_stream_dct_coeffs_omasa_fx( &q_idx[L_mult0( i, len_stream )], &q_dct_data_fx[L_mult0( i, len_stream )], len_stream, bit_stream, index, i == 0 ); + read_stream_dct_coeffs_omasa_fx( &q_idx[( i * len_stream )], &q_dct_data_fx[( i * len_stream )], len_stream, bit_stream, index, i == 0 ); } /* inverse DCT2 transform */ @@ -8860,19 +8871,19 @@ void ivas_omasa_decode_masa_to_total_fx( { case 4: matrix_product_q30_fx( dct4_fx, nblocks, nblocks, 1, q_dct_data_fx, nblocks, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nblocks ); + Copy32( dct_data_tmp_fx, q_dct_data_fx, nblocks ); /*Q25*/ BREAK; case 5: matrix_product_q30_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); + Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q25*/ BREAK; case 8: matrix_product_q30_fx( dct8_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); + Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q25*/ BREAK; case 12: matrix_product_q30_fx( dct12_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); + Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q25*/ BREAK; case 20: matrix_product_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, nblocks, 0, dct_data_tmp_fx ); @@ -8894,7 +8905,7 @@ void ivas_omasa_decode_masa_to_total_fx( { masa_to_total_energy_ratio_fx[i][j] = L_max( 0, q_dct_data_fx[k] ); // Q30 move32(); - masa_to_total_energy_ratio_fx[i][j] = L_min( ONE_IN_Q30, masa_to_total_energy_ratio_fx[i][j] ); + masa_to_total_energy_ratio_fx[i][j] = L_min( ONE_IN_Q30, masa_to_total_energy_ratio_fx[i][j] ); /*Q30*/ move32(); k = add( k, 1 ); } @@ -8906,7 +8917,7 @@ void ivas_omasa_decode_masa_to_total_fx( { FOR( j = 0; j < nbands; j++ ) { - masa_to_total_energy_ratio_fx[i][j] = masa_to_total_energy_ratio_fx[0][j]; + masa_to_total_energy_ratio_fx[i][j] = masa_to_total_energy_ratio_fx[0][j]; /*Q30*/ move32(); } } @@ -8918,7 +8929,7 @@ void ivas_omasa_decode_masa_to_total_fx( { FOR( i = 0; i < nblocks; i++ ) { - masa_to_total_energy_ratio_fx[i][j] = masa_to_total_energy_ratio_fx[i][0]; + masa_to_total_energy_ratio_fx[i][j] = masa_to_total_energy_ratio_fx[i][0]; /*Q30*/ move32(); } } diff --git a/lib_dec/ivas_qspherical_dec.c b/lib_dec/ivas_qspherical_dec.c index 993f01c52fdc9d08d1d95a0ac0a041dee17e595c..3f50f3816c1950d6db32905599bc1ee65121b3c8 100644 --- a/lib_dec/ivas_qspherical_dec.c +++ b/lib_dec/ivas_qspherical_dec.c @@ -103,14 +103,14 @@ float deindex_elevation( #ifdef IVAS_FLOAT_FIXED Word32 deindex_elevation_fx( - UWord16 *id_th, /* i : input index */ - const Word16 no_bits, /* i : number of bits for the spherical grid */ + UWord16 *id_th, /* i : input index Q0*/ + const Word16 no_bits, /* i : number of bits for the spherical grid Q0*/ const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ ) { Word32 theta_hat_fx; Word16 q_id_th = sub( norm_l( *id_th ), 1 ); - Word32 id_th_fx = L_shl( *id_th, q_id_th ); + Word32 id_th_fx = L_shl( *id_th, q_id_th ); /*q_id_th*/ IF( EQ_32( *id_th, MASA_NO_INDEX ) ) { @@ -121,7 +121,7 @@ Word32 deindex_elevation_fx( { IF( NE_32( mc_format, MC_LS_SETUP_INVALID ) ) { - theta_hat_fx = L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[sub( no_bits, 3 )] ), sub( 31, q_id_th ) ); + theta_hat_fx = L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[( no_bits - 3 )] ), sub( 31, q_id_th ) ); /*Q22*/ IF( GT_32( theta_hat_fx, L_shl( 90, Q22 ) ) ) { theta_hat_fx = 90 * ONE_IN_Q22; @@ -133,10 +133,10 @@ Word32 deindex_elevation_fx( IF( L_and( *id_th, 1 ) == 0 ) { /* theta is negative */ - *id_th = (UWord16) L_shr( *id_th, 1 ); + *id_th = (UWord16) L_shr( *id_th, 1 ); /* *id_th / 2 */ /*Q0*/ move16(); - id_th_fx = L_shr( id_th_fx, 1 ); - theta_hat_fx = L_negate( L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[sub( no_bits, 3 )] ), sub( 31, q_id_th ) ) ); + id_th_fx = L_shr( id_th_fx, 1 ); /*q_id_th*/ + theta_hat_fx = L_negate( L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[( no_bits - 3 )] ), sub( 31, q_id_th ) ) ); /*Q22*/ IF( LT_32( theta_hat_fx, -90 * ONE_IN_Q22 ) ) { theta_hat_fx = -90 * ONE_IN_Q22; @@ -145,10 +145,10 @@ Word32 deindex_elevation_fx( } ELSE { - *id_th = (UWord16) L_shr( L_add( *id_th, 1 ), 1 ); + *id_th = (UWord16) L_shr( L_add( *id_th, 1 ), 1 ); /* ( *id_th + 1 ) / 2 */ /*Q0*/ move16(); - id_th_fx = L_shr( L_add( id_th_fx, L_shl( 1, q_id_th ) ), 1 ); - theta_hat_fx = L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[sub( no_bits, 3 )] ), sub( 31, q_id_th ) ); + id_th_fx = L_shr( L_add( id_th_fx, L_shl( 1, q_id_th ) ), 1 ); /*q_id_th*/ + theta_hat_fx = L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[( no_bits - 3 )] ), sub( 31, q_id_th ) ); /*Q22*/ IF( GT_32( theta_hat_fx, 90 * ONE_IN_Q22 ) ) { theta_hat_fx = 90 * ONE_IN_Q22; @@ -158,6 +158,6 @@ Word32 deindex_elevation_fx( } } - return theta_hat_fx; + return theta_hat_fx; /*Q22*/ } #endif diff --git a/lib_dec/ivas_range_uni_dec.c b/lib_dec/ivas_range_uni_dec.c index 380e4da21db0cf3bd7499777ba240de418d796f9..8a82dabd2f0f6f757c27f10b051265b059d558bf 100644 --- a/lib_dec/ivas_range_uni_dec.c +++ b/lib_dec/ivas_range_uni_dec.c @@ -102,8 +102,8 @@ void rc_uni_dec_init( #endif void rc_uni_dec_init_fx( RangeUniDecState *rc_st_dec, /* i/o: RC state handle */ - UWord16 *bit_buffer, /* i : Bit buffer */ - const Word16 max_available_bits /* i : Total maximum bits available */ + UWord16 *bit_buffer, /* i : Bit buffer Q0*/ + const Word16 max_available_bits /* i : Total maximum bits available Q0*/ ) { Word16 i; @@ -111,17 +111,17 @@ void rc_uni_dec_init_fx( rc_st_dec->rc_low = 0; rc_st_dec->rc_range = 0xFFFFFFFF; - rc_st_dec->bit_buffer = bit_buffer; + rc_st_dec->bit_buffer = bit_buffer; /*Q0*/ rc_st_dec->bit_count = 0; /* the renormalization procedure reads at most 32 - 2 extra bits than available */ - rc_st_dec->max_allowable_bit_count = add( max_available_bits, 30 ); + rc_st_dec->max_allowable_bit_count = add( max_available_bits, 30 ); /*Q0*/ rc_st_dec->bit_error_detected = 0; FOR( i = 0; i < 4; i++ ) { // Not adding basops becuase the resultant value greater than Word32 - rc_st_dec->rc_low = ( rc_st_dec->rc_low << 8 ) + rc_uni_dec_read_fx( rc_st_dec ); + rc_st_dec->rc_low = ( rc_st_dec->rc_low << 8 ) + rc_uni_dec_read_fx( rc_st_dec ); /*Q0*/ } return; @@ -211,10 +211,10 @@ uint16_t rc_uni_dec_read_symbol_fastS( #endif UWord16 rc_uni_dec_read_symbol_fastS_fx( RangeUniDecState *rc_st_dec, /* i/o: Decoder State */ - const UWord16 cum_freq_table[], /* i : Cumulative frequency up to symbol */ - const UWord16 sym_freq_table[], /* i : Symbol frequency */ - const UWord16 alphabet_size, /* i : Number of symbols in the alphabet */ - const UWord16 tot_shift /* i : Total frequency as a power of 2 */ + const UWord16 cum_freq_table[], /* i : Cumulative frequency up to symbol Q0*/ + const UWord16 sym_freq_table[], /* i : Symbol frequency Q0*/ + const UWord16 alphabet_size, /* i : Number of symbols in the alphabet Q0*/ + const UWord16 tot_shift /* i : Total frequency as a power of 2 Q0*/ ) { UWord16 sym_begin; @@ -226,11 +226,11 @@ UWord16 rc_uni_dec_read_symbol_fastS_fx( UWord16 step; UWord32 reversed_low; - low = rc_st_dec->rc_low; + low = rc_st_dec->rc_low; /*Q0*/ move32(); - range = rc_st_dec->rc_range; + range = rc_st_dec->rc_range; /*Q0*/ move32(); - range = UL_lshr( range, tot_shift ); + range = UL_lshr( range, tot_shift ); /*range >>= tot_shift*/ /* the cumulative value is val = low / range */ /* the condition val >= level is equivalent with low >= range * level */ @@ -246,7 +246,7 @@ UWord16 rc_uni_dec_read_symbol_fastS_fx( /* will always reach the bitstream error condition branch on the next call */ rc_st_dec->rc_range = 0xFFFFFFFF; move32(); - rc_st_dec->rc_low = rc_st_dec->rc_range; + rc_st_dec->rc_low = rc_st_dec->rc_range; /*Q0*/ move32(); /* the current value and all the following values are very likely incorrect */ @@ -256,28 +256,28 @@ UWord16 rc_uni_dec_read_symbol_fastS_fx( /* do a binary search to find the symbol read */ sym_begin = 0; move16(); - sym_end = alphabet_size; /* the possible values are {sym_begin, .., sym_end - 1} */ + sym_end = alphabet_size; /* the possible values are {sym_begin, .., sym_end - 1} Q0*/ move16(); /* ceil(log2(x)) = 1 + floor(log2(x - 1)), for any x >= 2 */ /* floor(log2(y)) = 31 - norm_ul_float(y) = 30 - norm_l(y), for any 1 <= y <= 2 ^ 31 - 1 */ ceil_log2_alphabet_size = sub( 31, norm_l( UL_subNsD( alphabet_size, 1 ) ) ); /* completely equivalent with 32 - norm_ul_float(alphabet_size - 1), but norm_l is faster */ - reversed_low = UL_subNsD( UL_lshl( range, tot_shift ), low ); + reversed_low = UL_subNsD( UL_lshl( range, tot_shift ), low ); /*( range << tot_shift ) - low*/ /* at most ceil_log2_alphabet_size steps are needed so that sym_end - sym_begin == 1 */ FOR( step = 0; step < ceil_log2_alphabet_size; step++ ) { - sym_middle = shr( add( sym_begin, sym_end ), 1 ); + sym_middle = shr( add( sym_begin, sym_end ), 1 ); /*( sym_begin + sym_end ) >> 1 Q0*/ /* completely equvalent with low >= range * ((1 << tot_shift) - table[sym_middle]) */ IF( range * L_sub( L_shl( 1, tot_shift ), cum_freq_table[sym_middle] ) >= reversed_low ) { - sym_begin = sym_middle; + sym_begin = sym_middle; /*Q0*/ move16(); } ELSE { - sym_end = sym_middle; + sym_end = sym_middle; /*Q0*/ move16(); } } @@ -285,7 +285,7 @@ UWord16 rc_uni_dec_read_symbol_fastS_fx( /* sym_begin contains the symbol read */ /* low was not modified */ - rc_st_dec->rc_range = range; + rc_st_dec->rc_range = range; /*Q0*/ move32(); rc_uni_dec_update_fx( rc_st_dec, cum_freq_table[sym_begin], sym_freq_table[sym_begin] ); @@ -327,26 +327,26 @@ static void rc_uni_dec_update( static void rc_uni_dec_update_fx( RangeUniDecState *rc_st_dec, /* i/o: RC State handle */ - const UWord16 cum_freq, /* i : Cumulative frequency */ - const UWord16 sym_freq /* i : Symbol frequency */ + const UWord16 cum_freq, /* i : Cumulative frequency Q0*/ + const UWord16 sym_freq /* i : Symbol frequency Q0*/ ) { - rc_st_dec->rc_low = UL_subNsD( rc_st_dec->rc_low, UL_Mpy_32_32( cum_freq, rc_st_dec->rc_range ) ); - rc_st_dec->rc_range = UL_Mpy_32_32( rc_st_dec->rc_range, sym_freq ); + rc_st_dec->rc_low = UL_subNsD( rc_st_dec->rc_low, UL_Mpy_32_32( cum_freq, rc_st_dec->rc_range ) ); /*Q0*/ + rc_st_dec->rc_range = UL_Mpy_32_32( rc_st_dec->rc_range, sym_freq ); /*Q0*/ move32(); move32(); /* rc_range was shifted right by up to 16, so at most two renormalizations are needed */ IF( LT_64( rc_st_dec->rc_range, 0x01000000 ) ) { - rc_st_dec->rc_low = UL_addNsD( UL_lshl( rc_st_dec->rc_low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); - rc_st_dec->rc_range = UL_lshl( rc_st_dec->rc_range, 8 ); + rc_st_dec->rc_low = UL_addNsD( UL_lshl( rc_st_dec->rc_low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); /*Q0*/ + rc_st_dec->rc_range = UL_lshl( rc_st_dec->rc_range, 8 ); /*Q0*/ move32(); move32(); IF( LT_64( rc_st_dec->rc_range, 0x01000000 ) ) { - rc_st_dec->rc_low = UL_addNsD( UL_lshl( rc_st_dec->rc_low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); - rc_st_dec->rc_range = UL_lshl( rc_st_dec->rc_range, 8 ); + rc_st_dec->rc_low = UL_addNsD( UL_lshl( rc_st_dec->rc_low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); /*Q0*/ + rc_st_dec->rc_range = UL_lshl( rc_st_dec->rc_range, 8 ); /*Q0*/ move32(); move32(); } @@ -370,12 +370,12 @@ UWord16 rc_uni_dec_read_bit( UWord32 low; /* local copy (1 to 5 uses) */ UWord32 range; /* local copy (3 to 6 uses) */ - low = rc_st_dec->rc_low; + low = rc_st_dec->rc_low; /*Q0*/ move32(); - range = rc_st_dec->rc_range; + range = rc_st_dec->rc_range; /*Q0*/ move32(); - range = UL_lshr( range, 1 ); + range = UL_lshr( range, 1 ); /*range >>= 1*/ /* in case of bitstream errors it is possible that rc_low >= (rc_range << 1) */ val = 0; @@ -383,8 +383,8 @@ UWord16 rc_uni_dec_read_bit( /*basop comment : comparision of unsigned integers hence basops are not used*/ IF( GE_64( low, range ) ) { - val = UL_addNsD( val, 1 ); - low = UL_subNsD( low, range ); + val = UL_addNsD( val, 1 ); /*Q0*/ + low = UL_subNsD( low, range ); /*Q0*/ /* rc_range was already subtracted once from rc_low */ IF( GE_64( low, range ) ) @@ -396,7 +396,7 @@ UWord16 rc_uni_dec_read_bit( /* will always reach the bitstream error condition branch on the next call */ rc_st_dec->rc_range = 0xFFFFFFFF; move32(); - rc_st_dec->rc_low = rc_st_dec->rc_range; + rc_st_dec->rc_low = rc_st_dec->rc_range; /*Q0*/ move32(); /* the current value and all the following values are very likely incorrect */ @@ -408,13 +408,13 @@ UWord16 rc_uni_dec_read_bit( /*basop comment : comparision of unsigned integers hence basops are not used*/ IF( LT_64( range, 0x01000000 ) ) { - low = UL_addNsD( UL_lshl( low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); + low = UL_addNsD( UL_lshl( low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); /*Q0*/ range = UL_lshl( range, 8 ); } - rc_st_dec->rc_low = low; + rc_st_dec->rc_low = low; /*Q0*/ move32(); - rc_st_dec->rc_range = range; + rc_st_dec->rc_range = range; /*Q0*/ move32(); return (UWord16) val; @@ -480,20 +480,20 @@ uint16_t rc_uni_dec_read_bit( #ifdef IVAS_FLOAT_FIXED UWord16 rc_uni_dec_read_bit_prob_fast( RangeUniDecState *rc_st_dec, /* i/o: RC State handle */ - const Word16 freq0, /* i : Frequency for symbol 0 */ - const UWord16 tot_shift /* i : Total frequency as a power of 2 */ + const Word16 freq0, /* i : Frequency for symbol 0 Q0*/ + const UWord16 tot_shift /* i : Total frequency as a power of 2 Q0*/ ) { UWord32 val; UWord32 low; /* local copy (2 to 7 uses) */ UWord32 range; /* local copy (5 to 9 uses) */ - low = rc_st_dec->rc_low; + low = rc_st_dec->rc_low; /*Q0*/ move32(); - range = rc_st_dec->rc_range; + range = rc_st_dec->rc_range; /*Q0*/ move32(); - range = UL_lshr( range, tot_shift ); + range = UL_lshr( range, tot_shift ); /*range >>= tot_shift*/ /* in case of bitstream errors it is possible that low >= (1 << tot_shift) * range */ /*basop comment : unsigned integers are getting compared hence basops are not used*/ @@ -506,7 +506,7 @@ UWord16 rc_uni_dec_read_bit_prob_fast( /* will always reach the bitstream error condition branch on the next call */ rc_st_dec->rc_range = 0xFFFFFFFF; move32(); - rc_st_dec->rc_low = rc_st_dec->rc_range; + rc_st_dec->rc_low = rc_st_dec->rc_range; /*Q0*/ move32(); /* the current value and all the following values are very likely incorrect */ @@ -518,34 +518,34 @@ UWord16 rc_uni_dec_read_bit_prob_fast( /*basop comment : unsigned comparision and multiplication of unsigned and signed hence basops are not used*/ IF( low >= range * freq0 ) { - val = UL_addNsD( val, 1 ); + val = UL_addNsD( val, 1 ); /*Q0*/ - low = UL_subNsD( low, UL_Mpy_32_32( range, freq0 ) ); + low = UL_subNsD( low, UL_Mpy_32_32( range, freq0 ) ); /*Q0*/ /*basop comment : multiplication of two unsigned integers and result is stored in unsigned hence basops are not used*/ - range = UL_Mpy_32_32( range, UL_subNsD( UL_lshl( 1, tot_shift ), freq0 ) ); /* freq1 = (1 << tot_shift) - freq0 */ + range = UL_Mpy_32_32( range, UL_subNsD( UL_lshl( 1, tot_shift ), freq0 ) ); /* freq1 = (1 << tot_shift) - freq0 Q0*/ } ELSE { /* basop comment : multiplication of two unsigned integers and result is stored in unsigned integer hence basops are not used*/ - range = UL_Mpy_32_32( range, freq0 ); + range = UL_Mpy_32_32( range, freq0 ); /*Q0*/ } /* rc_range was shifted right by up to 16, so at most two renormalizations are needed */ /*basop comment : comparision of unsigned integers hence basops are not used*/ IF( LT_64( range, 0x01000000 ) ) { - low = UL_addNsD( UL_lshl( low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); - range = UL_lshl( range, 8 ); + low = UL_addNsD( UL_lshl( low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); /*Q0*/ + range = UL_lshl( range, 8 ); /*range <<= 8*/ IF( LT_64( range, 0x01000000 ) ) { - low = UL_addNsD( UL_lshl( low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); - range = UL_lshl( range, 8 ); + low = UL_addNsD( UL_lshl( low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); /*Q0*/ + range = UL_lshl( range, 8 ); /*range <<= 8*/ } } - rc_st_dec->rc_low = low; + rc_st_dec->rc_low = low; /*Q0*/ move32(); - rc_st_dec->rc_range = range; + rc_st_dec->rc_range = range; /*Q0*/ move32(); return (UWord16) val; @@ -623,7 +623,7 @@ uint16_t rc_uni_dec_read_bit_prob_fast( #ifdef IVAS_FLOAT_FIXED UWord16 rc_uni_dec_read_bits( RangeUniDecState *rc_st_dec, /* i/o: RC State handle */ - const Word16 bits /* i : Number of bits */ + const Word16 bits /* i : Number of bits Q0*/ ) { UWord32 val; @@ -634,18 +634,18 @@ UWord16 rc_uni_dec_read_bits( #ifdef FIX851_RANGE_DEC_PRECISION Word16 exp_temp1; #endif - low = rc_st_dec->rc_low; - range = rc_st_dec->rc_range; + low = rc_st_dec->rc_low; /*Q0*/ + range = rc_st_dec->rc_range; /*Q0*/ move32(); move32(); - range = (UWord32) W_shr( range, bits ); + range = (UWord32) W_shr( range, bits ); /*range >>= bits*/ #ifdef FIX851_RANGE_DEC_PRECISION exp_temp1 = sub( W_norm( low ), 31 + 1 ); - temp1 = (UWord32) W_shl( low, exp_temp1 ); + temp1 = (UWord32) W_shl( low, exp_temp1 ); /*Q : W_norm( low ) - 32*/ norm_range = sub( W_norm( range ), 31 ); - temp2 = (UWord32) W_shl( range, norm_range ); - val = (UWord32) W_shr( UL_div( temp1, temp2 ), sub( add( 32, exp_temp1 ), norm_range ) ); + temp2 = (UWord32) W_shl( range, norm_range ); /*Q : W_norm( range ) - 31*/ + val = (UWord32) W_shr( UL_div( temp1, temp2 ), sub( add( 32, exp_temp1 ), norm_range ) ); /*Q0*/ #else temp1 = (UWord32) W_shr( low, 1 ); norm_range = sub( W_norm( range ), 31 ); @@ -662,7 +662,7 @@ UWord16 rc_uni_dec_read_bits( /* for valid bitstreams, always low < range, therefore setting low = range */ /* will always reach the bitstream error condition branch on the next call */ rc_st_dec->rc_range = 0xFFFFFFFF; - rc_st_dec->rc_low = rc_st_dec->rc_range; + rc_st_dec->rc_low = rc_st_dec->rc_range; /*Q0*/ move32(); move32(); @@ -670,26 +670,26 @@ UWord16 rc_uni_dec_read_bits( return 0; /* return the minimum valid value for the output */ } - low = (UWord32) W_sub( low, W_mult0_32_32( val, range ) ); + low = (UWord32) W_sub( low, W_mult0_32_32( val, range ) ); /*Q0*/ /* rc_range was shifted right by up to 16, so at most two renormalizations are needed */ IF( LT_64( range, 0x01000000 ) ) { - low = (UWord32) W_add( W_shl( low, 8 ), rc_uni_dec_read_fx( rc_st_dec ) ); - range = (UWord32) W_shl( range, 8 ); + low = (UWord32) W_add( W_shl( low, 8 ), rc_uni_dec_read_fx( rc_st_dec ) ); /*Q0*/ + range = (UWord32) W_shl( range, 8 ); /*range <<= 8*/ if ( LT_64( range, 0x01000000 ) ) { - low = (UWord32) W_add( W_shl( low, 8 ), rc_uni_dec_read_fx( rc_st_dec ) ); - range = (UWord32) W_shl( range, 8 ); + low = (UWord32) W_add( W_shl( low, 8 ), rc_uni_dec_read_fx( rc_st_dec ) ); /*Q0*/ + range = (UWord32) W_shl( range, 8 ); /*range <<= 8*/ } } - rc_st_dec->rc_low = low; - rc_st_dec->rc_range = range; + rc_st_dec->rc_low = low; /*Q0*/ + rc_st_dec->rc_range = range; /*Q0*/ move32(); move32(); - return (UWord16) val; + return (UWord16) val; /*Q0*/ } #else uint16_t rc_uni_dec_read_bits( @@ -793,7 +793,7 @@ Word16 rc_uni_dec_virtual_finish_fx( { /* the function is completely equivalent with rc_uni_dec_finish */ // Not adding basop because value of rc_st_dec->rc_range exceeds Word32 - return add( rc_st_dec->bit_count, sub( norm_l( rc_st_dec->rc_range >> 24 ), 53 ) ); + return add( rc_st_dec->bit_count, sub( norm_l( rc_st_dec->rc_range >> 24 ), 53 ) ); /*Q0*/ } #else @@ -850,8 +850,8 @@ static Word16 rc_uni_dec_read_fx( Word16 byte_read; UWord16 *shifted_bit_buffer; - shifted_bit_buffer = rc_st_dec->bit_buffer + rc_st_dec->bit_count; - rc_st_dec->bit_count = add( rc_st_dec->bit_count, 8 ); + shifted_bit_buffer = rc_st_dec->bit_buffer + rc_st_dec->bit_count; /*Q0*/ + rc_st_dec->bit_count = add( rc_st_dec->bit_count, 8 ); /*Q0*/ /* * In case of bitstream errors the number the bits read may be larger than the total @@ -865,7 +865,7 @@ static Word16 rc_uni_dec_read_fx( /* for valid bitstreams, always low < range, therefore setting low = range */ /* will always reach the bitstream error condition branch on the next call */ rc_st_dec->rc_range = 0xFFFFFFFF; - rc_st_dec->rc_low = rc_st_dec->rc_range; + rc_st_dec->rc_low = rc_st_dec->rc_range; /*Q0*/ return 0; /* reading the 8 bits would trigger an out-of-bounds array access */ } @@ -877,5 +877,5 @@ static Word16 rc_uni_dec_read_fx( s_or( shl( shifted_bit_buffer[4], 3 ), s_or( shl( shifted_bit_buffer[5], 2 ), s_or( shl( shifted_bit_buffer[6], 1 ), shifted_bit_buffer[7] ) ) ) ) ) ) ); - return byte_read; + return byte_read; /*Q0*/ } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index a8b1bacadbb9f09b3a7348cdb54051f1baf69913..71c6eeb9e5378be8e44f633f917ff06d36e3358d 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -707,8 +707,8 @@ ivas_error ivas_sba_dec_reconfigure( ivas_error ivas_sba_dec_reconfigure_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - UWord16 *nSamplesFlushed, /* o : number of samples flushed */ - Word16 *data /* o : output synthesis signal */ + UWord16 *nSamplesFlushed, /* o : number of samples flushed Q0*/ + Word16 *data /* o : output synthesis signal Q0*/ ) { Word16 nchan_transport_old, nSCE_old, nCPE_old, nchan_hp20_old; @@ -776,7 +776,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( *nSamplesFlushed = 0; move16(); - granularity_new = st_ivas->hTcBuffer->n_samples_granularity; + granularity_new = st_ivas->hTcBuffer->n_samples_granularity; /*Q0*/ move16(); /* we may need to flush only for binaural and OSBA and TSM */ @@ -821,23 +821,23 @@ ivas_error ivas_sba_dec_reconfigure_fx( } /* determine new granularity */ - granularity_new = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + granularity_new = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /*Q0*/ move16(); /* this will change anyway only with binaural */ test(); IF( EQ_16( renderer_type_new, RENDERER_BINAURAL_FASTCONV ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - granularity_new = i_mult( granularity_new, JBM_CLDFB_SLOTS_IN_SUBFRAME ); + granularity_new = i_mult( granularity_new, JBM_CLDFB_SLOTS_IN_SUBFRAME ); /*Q0*/ } /* flush renderer on granularity change form 5ms to 1.25ms, again only possible for binaural rendering */ IF( LT_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { /* write back info for correct rendering of the flushable samples */ - st_ivas->sba_analysis_order = sba_analysis_order_old_flush; + st_ivas->sba_analysis_order = sba_analysis_order_old_flush; /*Q0*/ move16(); - st_ivas->hDecoderConfig->ivas_total_brate = last_ivas_total_brate; + st_ivas->hDecoderConfig->ivas_total_brate = last_ivas_total_brate; /*Q0*/ move32(); if ( NE_32( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, granularity_new, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, st_ivas->mc_mode, ism_mode_old, nSamplesFlushed, data ) ), IVAS_ERR_OK ) ) @@ -848,7 +848,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( /* restore correct values for the current frame*/ st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order ); move16(); - st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate; + st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate; /*Q0*/ move32(); } ELSE IF( GT_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) @@ -861,10 +861,10 @@ ivas_error ivas_sba_dec_reconfigure_fx( /* make sure the changed number of slots in the last subframe is not lost in the following steps */ IF( st_ivas->hSpatParamRendCom != NULL ) { - st_ivas->hSpatParamRendCom->subframe_nbslots[st_ivas->hSpatParamRendCom->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; + st_ivas->hSpatParamRendCom->subframe_nbslots[st_ivas->hSpatParamRendCom->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; /*Q0*/ move32(); } - st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; + st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; /*Q0*/ move32(); } } @@ -883,7 +883,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( move16(); st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpar->subframes_rendered; move16(); - Copy( st_ivas->hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + Copy( st_ivas->hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); /*Q0*/ } ELSE IF( st_ivas->hSpatParamRendCom != NULL ) { @@ -895,7 +895,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( move16(); st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; move16(); - Copy( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + Copy( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); /*Q0*/ } } @@ -907,7 +907,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( SPAR_DEC_HANDLE hSpar; hSpar = st_ivas->hSpar; - sba_order_internal = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + sba_order_internal = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); /*Q0*/ IF( hSpar != NULL ) { @@ -924,7 +924,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( test(); test(); test(); - IF( NE_16( nchan_transport_old, ivas_get_sba_num_TCs( ivas_total_brate, sba_order_internal ) ) || ( GE_32( last_ivas_total_brate, IVAS_512k ) && LT_32( ivas_total_brate, IVAS_512k ) ) || ( LT_32( last_ivas_total_brate, IVAS_512k ) && GE_32( ivas_total_brate, IVAS_512k ) ) ) + IF( NE_16( nchan_transport_old, ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_order_internal ) ) || ( GE_32( last_ivas_total_brate, IVAS_512k ) && LT_32( ivas_total_brate, IVAS_512k ) ) || ( LT_32( last_ivas_total_brate, IVAS_512k ) && GE_32( ivas_total_brate, IVAS_512k ) ) ) { ivas_spar_dec_close_fx( &( st_ivas->hSpar ), hDecoderConfig->output_Fs, 1 ); @@ -935,7 +935,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( } ELSE IF( LT_32( last_ivas_total_brate, IVAS_24k4 ) && GE_32( ivas_total_brate, IVAS_24k4 ) ) { - num_channels = st_ivas->hSpar->hMdDec->spar_md_cfg.num_umx_chs; + num_channels = st_ivas->hSpar->hMdDec->spar_md_cfg.num_umx_chs; /*Q0*/ move16(); ivas_spar_md_dec_matrix_close_fx( st_ivas->hSpar->hMdDec, num_channels ); @@ -1059,14 +1059,14 @@ ivas_error ivas_sba_dec_reconfigure_fx( { Word16 band_grouping[IVAS_MAX_NUM_BANDS + 1]; - st_ivas->hSpar->enc_param_start_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); + st_ivas->hSpar->enc_param_start_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); /*Q0*/ move16(); IF( ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) ) { st_ivas->hSpar->enc_param_start_band = 0; move16(); - set_c( (Word8 *) st_ivas->hQMetaData->twoDirBands, (Word8) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands ); + set_c( (Word8 *) st_ivas->hQMetaData->twoDirBands, (Word8) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands ); /*Q0*/ st_ivas->hQMetaData->numTwoDirBands = (UWord8) st_ivas->hQMetaData->q_direction[0].cfg.nbands; move16(); } @@ -1174,7 +1174,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( return error; } - st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->nchan_ism, 1 ), 1 ) ); + st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->nchan_ism, 1 ), 1 ) ); /*Q0*/ move16(); } ELSE IF( EQ_16( ism_mode_old, ISM_SBA_MODE_DISC ) && EQ_16( st_ivas->ism_mode, ISM_MODE_NONE ) ) @@ -1193,19 +1193,19 @@ ivas_error ivas_sba_dec_reconfigure_fx( st_ivas->hHrtfTD = NULL; } } - nchan_transport_old = add( nchan_transport_old, st_ivas->nchan_ism ); + nchan_transport_old = add( nchan_transport_old, st_ivas->nchan_ism ); /*Q0*/ st_ivas->ism_mode = ISM_MODE_NONE; move16(); } ELSE IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->nchan_ism, 1 ), 1 ) ); + st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->nchan_ism, 1 ), 1 ) ); /*Q0*/ move16(); nCPE_old = st_ivas->nCPE; move16(); nchan_transport_old = st_ivas->nchan_transport; move16(); - nchan_transport_old = add( nchan_transport_old, st_ivas->nchan_ism ); + nchan_transport_old = add( nchan_transport_old, st_ivas->nchan_ism ); /*Q0*/ } } @@ -1253,8 +1253,8 @@ ivas_error ivas_sba_dec_reconfigure_fx( tc_buffer_mode = TC_BUFFER_MODE_RENDERER; move16(); - tc_nchan_tc = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); - tc_nchan_to_allocate = tc_nchan_tc; + tc_nchan_tc = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); /*Q0*/ + tc_nchan_to_allocate = tc_nchan_tc; /*Q0*/ move16(); test(); test(); @@ -1266,31 +1266,31 @@ ivas_error ivas_sba_dec_reconfigure_fx( test(); IF( ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { - tc_nchan_tc = add( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); - tc_nchan_to_allocate = tc_nchan_tc; + tc_nchan_tc = add( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); /*Q0*/ + tc_nchan_to_allocate = tc_nchan_tc; /*Q0*/ move16(); } ELSE { tc_buffer_mode = TC_BUFFER_MODE_BUFFER; move16(); - tc_nchan_tc = st_ivas->hDecoderConfig->nchan_out; + tc_nchan_tc = st_ivas->hDecoderConfig->nchan_out; /*Q0*/ move16(); - tc_nchan_to_allocate = tc_nchan_tc; + tc_nchan_to_allocate = tc_nchan_tc; /*Q0*/ move16(); } } ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { - tc_nchan_to_allocate = shl( BINAURAL_CHANNELS, 1 ); + tc_nchan_to_allocate = shl( BINAURAL_CHANNELS, 1 ); /*2 * BINAURAL_CHANNELS*/ } ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - tc_nchan_to_allocate = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + tc_nchan_to_allocate = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/ IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - tc_nchan_to_allocate = add( tc_nchan_to_allocate, st_ivas->nchan_ism ); + tc_nchan_to_allocate = add( tc_nchan_to_allocate, st_ivas->nchan_ism ); /*Q0*/ } } ELSE @@ -1321,13 +1321,13 @@ ivas_error ivas_sba_dec_reconfigure_fx( test(); IF( st_ivas->hSpatParamRendCom != NULL && EQ_16( st_ivas->hSpatParamRendCom->slot_size, st_ivas->hTcBuffer->n_samples_granularity ) ) { - Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); /*Q0*/ st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; move16(); st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; move16(); } - Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpar->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpar->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); /*Q0*/ st_ivas->hSpar->nb_subframes = st_ivas->hTcBuffer->nb_subframes; move16(); st_ivas->hSpar->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; @@ -1337,11 +1337,11 @@ ivas_error ivas_sba_dec_reconfigure_fx( test(); IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - Word16 granularityMultiplier = idiv1616( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size ); + Word16 granularityMultiplier = idiv1616( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size ); /*Q0*/ Word16 n; FOR( n = 0; n < MAX_JBM_SUBFRAMES_5MS; n++ ) { - st_ivas->hSpatParamRendCom->subframe_nbslots[n] = i_mult( st_ivas->hTcBuffer->subframe_nbslots[n], granularityMultiplier ); + st_ivas->hSpatParamRendCom->subframe_nbslots[n] = i_mult( st_ivas->hTcBuffer->subframe_nbslots[n], granularityMultiplier ); /*Q0*/ move16(); st_ivas->hSpar->subframe_nbslots[n] = st_ivas->hSpatParamRendCom->subframe_nbslots[n]; move16(); @@ -1352,7 +1352,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( * floating-point output audio buffers *-----------------------------------------------------------------*/ - nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/ if ( NE_32( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) { @@ -1661,8 +1661,8 @@ void ivas_sba_dec_digest_tc( #ifdef IVAS_FLOAT_FIXED void ivas_sba_dec_digest_tc_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const Word16 nCldfbSlots, /* i : number of CLDFB slots */ - const Word16 nSamplesForRendering /* i : number of samples provided */ + const Word16 nCldfbSlots, /* i : number of CLDFB slots Q0*/ + const Word16 nSamplesForRendering /* i : number of samples provided Q0*/ ) { Word16 ch_idx, nchan_transport; @@ -1685,21 +1685,21 @@ void ivas_sba_dec_digest_tc_fx( Word32 *p_tc[2 * BINAURAL_CHANNELS]; /* default_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); */ - default_frame = extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - nSamplesLeftForTD = nSamplesForRendering; + default_frame = extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /*Q0*/ + nSamplesLeftForTD = nSamplesForRendering; /*Q0*/ move16(); FOR( ch_idx = 0; ch_idx < BINAURAL_CHANNELS; ch_idx++ ) { - decorr_signal[ch_idx] = st_ivas->hTcBuffer->tc_fx[add( ch_idx, BINAURAL_CHANNELS )]; + decorr_signal[ch_idx] = st_ivas->hTcBuffer->tc_fx[( ch_idx + BINAURAL_CHANNELS )]; /*Q11*/ move32(); - p_tc[ch_idx] = st_ivas->hTcBuffer->tc_fx[ch_idx]; + p_tc[ch_idx] = st_ivas->hTcBuffer->tc_fx[ch_idx]; /*Q11*/ move32(); } WHILE( nSamplesLeftForTD ) { - Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame ); + Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame ); /*Q0*/ IF( st_ivas->hDiracDecBin->hTdDecorr ) { @@ -1711,12 +1711,12 @@ void ivas_sba_dec_digest_tc_fx( decorr_signal[ch_idx] += nSamplesToDecorr; p_tc[ch_idx] += nSamplesToDecorr; } - nSamplesLeftForTD = sub( nSamplesLeftForTD, nSamplesToDecorr ); + nSamplesLeftForTD = sub( nSamplesLeftForTD, nSamplesToDecorr ); /*Q0*/ } } /* if we have a late CNG generation, do it here */ - nchan_transport = st_ivas->nchan_transport; + nchan_transport = st_ivas->nchan_transport; /*Q0*/ move16(); test(); @@ -1745,7 +1745,7 @@ void ivas_sba_dec_digest_tc_fx( ( ( EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) && ( EQ_16( nchan_transport, 1 ) && NE_16( st_ivas->nchan_transport, 2 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag ) ) ) { Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; - Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 2 ) ); + Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 2 ) ); /*Q12 -> Q13*/ generate_masking_noise_lb_dirac_fx( st->hFdCngDec->hFdCngCom, st_ivas->hTcBuffer->tc_fx[1], nCldfbSlots, st->cna_dirac_flag && st->flag_cna ); } @@ -1763,10 +1763,10 @@ void ivas_sba_dec_digest_tc_fx( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_sba_dec_render_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ - UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ - UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *output_fx[], /* o : rendered time signal */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested Q0*/ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered Q0*/ + UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render Q0*/ + Word32 *output_fx[], /* o : rendered time signal Q11*/ Word16 out_len /*Store the length of values in each channel*/ ) { @@ -1784,38 +1784,38 @@ ivas_error ivas_sba_dec_render_fx( hSpar = st_ivas->hSpar; hSpatParamRendCom = st_ivas->hSpatParamRendCom; nchan_internal = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); - nchan_out = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); + nchan_out = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); /*Q0*/ FOR( ch = 0; ch < nchan_out; ch++ ) { - output_f_local_fx[ch] = output_fx[ch]; + output_f_local_fx[ch] = output_fx[ch]; /*Q11*/ } - slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /*Q0*/ move16(); /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ - slots_to_render = s_min( sub( hSpar->num_slots, hSpar->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) ); - *nSamplesRendered = imult1616( slots_to_render, slot_size ); + slots_to_render = s_min( sub( hSpar->num_slots, hSpar->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) ); /*Q0*/ + *nSamplesRendered = imult1616( slots_to_render, slot_size ); /*Q0*/ move16(); - first_sf = hSpar->subframes_rendered; - last_sf = first_sf; + first_sf = hSpar->subframes_rendered; /*Q0*/ + last_sf = first_sf; /*Q0*/ move16(); move16(); WHILE( slots_to_render > 0 ) { - slots_to_render = sub( slots_to_render, hSpar->subframe_nbslots[last_sf] ); + slots_to_render = sub( slots_to_render, hSpar->subframe_nbslots[last_sf] ); /*Q0*/ last_sf = add( last_sf, 1 ); } FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { - Word16 n_samples_sf = imult1616( slot_size, hSpar->subframe_nbslots[subframe_idx] ); + Word16 n_samples_sf = imult1616( slot_size, hSpar->subframe_nbslots[subframe_idx] ); /*Q0*/ ivas_spar_dec_upmixer_sf_fx( st_ivas, output_f_local_fx, nchan_internal, output_f_local_len ); FOR( ch = 0; ch < nchan_out; ch++ ) { - output_f_local_fx[ch] = output_f_local_fx[ch] + n_samples_sf; + output_f_local_fx[ch] = output_f_local_fx[ch] + n_samples_sf; /*Q11*/ } output_f_local_len = sub( output_f_local_len, n_samples_sf ); @@ -1835,18 +1835,18 @@ ivas_error ivas_sba_dec_render_fx( { IF( EQ_16( st_ivas->hDirAC->hConfig->dec_param_estim, 1 ) ) { - hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_CLDFB_TIMESLOTS ) % hSpatParamRendCom->dirac_md_buffer_length; + hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_CLDFB_TIMESLOTS ) % hSpatParamRendCom->dirac_md_buffer_length; /*Q0*/ move16(); } ELSE { - hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length; + hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length; /*Q0*/ move16(); } move16(); } - *nSamplesAvailableNext = imult1616( sub( hSpar->num_slots, hSpar->slots_rendered ), slot_size ); + *nSamplesAvailableNext = imult1616( sub( hSpar->num_slots, hSpar->slots_rendered ), slot_size ); /*Q0*/ move16(); return IVAS_ERR_OK; diff --git a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c index ae190e4283b43ce9d09d5fc9ca3fa2745ae03763..787646041b15f38d099243603091b2fa8428ce82 100644 --- a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c +++ b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c @@ -143,9 +143,9 @@ void ivas_sba_dirac_stereo_config( *-------------------------------------------------------------------*/ static Word16 ivas_sba_dirac_stereo_band_config( - Word16 *band_limits, /* o : DFT band limits */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word16 NFFT, /* i : analysis/synthesis window length */ + Word16 *band_limits, /* o : DFT band limits Q0*/ + const Word32 output_Fs, /* i : output sampling rate Q0*/ + const Word16 NFFT, /* i : analysis/synthesis window length Q0*/ const Word16 spar_flag /* i : SPAR or DirAC band grouping */ ) { @@ -191,7 +191,7 @@ static Word16 ivas_sba_dirac_stereo_band_config( assert( 0 ); } - bins_per_cldfb_band = idiv1616( NFFT, shl( num_cldfb_bands, 1 ) ); + bins_per_cldfb_band = idiv1616( NFFT, shl( num_cldfb_bands, 1 ) /*( 2 * num_cldfb_bands )*/ ); /*Q0*/ move16(); band_limits[0] = 1; move16(); @@ -199,22 +199,22 @@ static Word16 ivas_sba_dirac_stereo_band_config( { IF( spar_flag ) { - band_limits[i] = i_mult( DirAC_band_grouping_12[i], bins_per_cldfb_band ); + band_limits[i] = i_mult( DirAC_band_grouping_12[i], bins_per_cldfb_band ); /*Q0*/ move16(); } ELSE { - band_limits[i] = i_mult( DirAC_band_grouping_5[i], bins_per_cldfb_band ); + band_limits[i] = i_mult( DirAC_band_grouping_5[i], bins_per_cldfb_band ); /*Q0*/ move16(); } - IF( GE_16( band_limits[i], shr( NFFT, 1 ) ) ) + IF( GE_16( band_limits[i], shr( NFFT, 1 ) /* NFFT / 2 */ ) ) { nbands = i; move16(); BREAK; } } - band_limits[nbands] = shr( NFFT, 1 ); + band_limits[nbands] = shr( NFFT, 1 ); /* NFFT / 2 */ move16(); return nbands; @@ -225,34 +225,34 @@ static Word16 get_panning_tangent_gain( { Word16 tbl_len = sizeof( ivas_sine_panning_tbl_fx ) / sizeof( ivas_sine_panning_tbl_fx[0] ); // Not using BASOP because size can be calculted at compile-time. move16(); - Word16 idx = shr( tbl_len, 1 ); + Word16 idx = shr( tbl_len, 1 ); /*Q0*/ move16(); - const Word16 *ptr_sin = &ivas_sine_panning_tbl_fx[0]; - const Word16 *ptr_tan = &ivas_tan_panning_gain_dirac_tbl_fx[0]; + const Word16 *ptr_sin = &ivas_sine_panning_tbl_fx[0]; /*Q15*/ + const Word16 *ptr_tan = &ivas_tan_panning_gain_dirac_tbl_fx[0]; /*Q15*/ Word16 lim_l = 0; move16(); - Word16 lim_r = tbl_len; + Word16 lim_r = tbl_len; /*Q0*/ move16(); WHILE( 1 ) { - idx = shr( add( lim_l, lim_r ), 1 ); + idx = shr( add( lim_l, lim_r ), 1 ); /*Q0*/ IF( GE_16( idx, tbl_len ) ) { - return ptr_tan[tbl_len - 1]; + return ptr_tan[tbl_len - 1]; /*Q15*/ } ELSE IF( idx <= 0 ) { - return ptr_tan[0]; + return ptr_tan[0]; /*Q15*/ } ELSE IF( LE_16( sinAngleMapped, ptr_sin[idx + 1] ) && GE_16( sinAngleMapped, ptr_sin[idx] ) ) { IF( EQ_16( sinAngleMapped, ptr_sin[idx + 1] ) ) { - return ptr_tan[idx + 1]; + return ptr_tan[idx + 1]; /*Q15*/ } ELSE IF( EQ_16( sinAngleMapped, ptr_sin[idx] ) ) { - return ptr_tan[idx]; + return ptr_tan[idx]; /*Q15*/ } ELSE { @@ -260,70 +260,71 @@ static Word16 get_panning_tangent_gain( move16(); IF( LE_16( sinAngleMapped, mid ) ) { - return ptr_tan[idx]; + return ptr_tan[idx]; /*Q15*/ } ELSE { - return ptr_tan[idx + 1]; + return ptr_tan[idx + 1]; /*Q15*/ } } } ELSE IF( GT_16( sinAngleMapped, ptr_sin[idx] ) ) { - lim_l = add( idx, 1 ); + lim_l = add( idx, 1 ); /*Q0*/ } ELSE IF( LT_16( sinAngleMapped, ptr_sin[idx] ) ) { - lim_r = sub( idx, 1 ); + lim_r = sub( idx, 1 ); /*Q0*/ } } } static Word16 get_panning( - const Word16 aziDeg, - const Word16 eleDeg ) + const Word16 aziDeg, /*Q0*/ + const Word16 eleDeg /*Q0*/ +) { Word16 panning = 0; move16(); - Word16 azAddEl = aziDeg + eleDeg; - move16(); - Word16 azSubEl = aziDeg - eleDeg; - move16(); + Word16 azAddEl = add( aziDeg, eleDeg ); /*Q0*/ + + Word16 azSubEl = sub( aziDeg, eleDeg ); /*Q0*/ + const Word16 *ptr_sin_az = &ivas_sin_az_fx[180]; WHILE( GT_16( azAddEl, 180 ) ) { - azAddEl = sub( azAddEl, 360 ); + azAddEl = sub( azAddEl, 360 ); /*Q0*/ } WHILE( LT_16( azAddEl, negate( 180 ) ) ) { - azAddEl = add( azAddEl, 360 ); + azAddEl = add( azAddEl, 360 ); /*Q0*/ } WHILE( GT_16( azSubEl, 180 ) ) { - azSubEl = sub( azSubEl, 360 ); + azSubEl = sub( azSubEl, 360 ); /*Q0*/ } WHILE( LT_16( azSubEl, negate( 180 ) ) ) { - azSubEl = add( azSubEl, 360 ); + azSubEl = add( azSubEl, 360 ); /*Q0*/ } /*sin(az)cos(el) = 0.5 * (sin(az + el) + sin(az - el)) */ - Word16 sin_az_cos_el = add( shr( ptr_sin_az[azAddEl], 1 ), shr( ptr_sin_az[azSubEl], 1 ) ); + Word16 sin_az_cos_el = add( shr( ptr_sin_az[azAddEl], 1 ), shr( ptr_sin_az[azSubEl], 1 ) ); /*Q15*/ move16(); IF( GE_32( sin_az_cos_el, SIN_30_DEGREES_Q15 ) ) - { /* Left side */ - panning = (Word16) 0x7fff; + { /* Left side */ + panning = (Word16) 0x7fff; /*Q15*/ move16(); } ELSE IF( LE_32( sin_az_cos_el, SIN_NEG_30_DEGREES_Q15 ) ) - { /* Right side */ - panning = (Word16) 0x8000; + { /* Right side */ + panning = (Word16) 0x8000; /*Q15*/ move16(); } ELSE - { /* Tangent panning law */ - panning = get_panning_tangent_gain( sin_az_cos_el ); + { /* Tangent panning law */ + panning = get_panning_tangent_gain( sin_az_cos_el ); /*Q15*/ } - return panning; + return panning; /*Q15*/ } @@ -336,11 +337,11 @@ static Word16 get_panning( static void map_params_dirac_to_stereo( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */ - Word32 synth[], /* i : decoded downmix signal */ - Word32 DFT[STEREO_DFT_BUF_MAX], /* i/o: DFT buffer */ - const UWord8 b_wide_panning, /* i : flag indicating wider panning */ - const Word16 L_frame, /* i : core signal length */ - const Word16 mcmasa, /* i : McMASA flag */ + Word32 synth[], /* i : decoded downmix signal q_synth*/ + Word32 DFT[STEREO_DFT_BUF_MAX], /* i/o: DFT buffer hStereoDft->q_dft*/ + const UWord8 b_wide_panning, /* i : flag indicating wider panning Q0*/ + const Word16 L_frame, /* i : core signal length Q0*/ + const Word16 mcmasa, /* i : McMASA flag Q0*/ const Word16 q_synth ) { Word16 i, b, k; @@ -363,21 +364,21 @@ static void map_params_dirac_to_stereo( Word32 *side_gain, *res_pred_gain; IVAS_QDIRECTION *q_direction; Word16 q_div, q_sqrt; - const Word16 *ptr_sin_az = &ivas_sin_az_fx[180]; - const Word16 *ptr_cos_el = &ivas_sin_az_fx[270]; + const Word16 *ptr_sin_az = &ivas_sin_az_fx[180]; /*Q15*/ + const Word16 *ptr_cos_el = &ivas_sin_az_fx[270]; /*Q15*/ nBlocks = MAX_PARAM_SPATIAL_SUBFRAMES; move16(); - nbands = hStereoDft->nbands; + nbands = hStereoDft->nbands; /*Q15*/ move16(); k_offset = STEREO_DFT_OFFSET; move16(); - side_gain = hStereoDft->side_gain_fx + i_mult( k_offset, STEREO_DFT_BAND_MAX ); - res_pred_gain = hStereoDft->res_pred_gain_fx + i_mult( k_offset, STEREO_DFT_BAND_MAX ); + side_gain = hStereoDft->side_gain_fx + i_mult( k_offset, STEREO_DFT_BAND_MAX ); /*Q31*/ + res_pred_gain = hStereoDft->res_pred_gain_fx + i_mult( k_offset, STEREO_DFT_BAND_MAX ); /*Q31*/ q_direction = &( hQMetaData->q_direction[0] ); /* gain smoothing factor */ - pDFT = DFT; + pDFT = DFT; /*q_dft*/ q_nrg = hStereoDft->q_dft; move16(); FOR( k = 0; k < NB_DIV; k++ ) @@ -391,20 +392,20 @@ static void map_params_dirac_to_stereo( FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { tmp64 = W_add( tmp64, W_add( W_mult0_32_32( pDFT[2 * i], pDFT[2 * i] ), - W_mult0_32_32( pDFT[add( 2 * i, 1 )], pDFT[add( 2 * i, 1 )] ) ) ); + W_mult0_32_32( pDFT[( 2 * i + 1 )], pDFT[( 2 * i + 1 )] ) ) ); /* 2*q_nrg */ move64(); } - subframe_band_nrg[k][b] = W_extract_h( W_shl( tmp64, 1 ) ); + subframe_band_nrg[k][b] = W_extract_h( W_shl( tmp64, 1 ) ); /* 2*q_nrg-31 */ move32(); q_nrg = sub( Q31, sub( shl( hStereoDft->q_dft, 1 ), Q31 ) ); - subframe_band_nrg[k][b] = Sqrt32( subframe_band_nrg[k][b], &q_nrg ); + subframe_band_nrg[k][b] = Sqrt32( subframe_band_nrg[k][b], &q_nrg ); /* Q31 - q_nrg */ move32(); IF( NE_16( sub( Q31, q_nrg ), hStereoDft->q_smooth_buf_fx ) ) { - subframe_band_nrg[k][b] = L_shl( subframe_band_nrg[k][b], sub( hStereoDft->q_smooth_buf_fx, sub( Q31, q_nrg ) ) ); + subframe_band_nrg[k][b] = L_shl( subframe_band_nrg[k][b], sub( hStereoDft->q_smooth_buf_fx, sub( Q31, q_nrg ) ) ); /*hStereoDft->q_smooth_buf_fx*/ move32(); } - hStereoDft->smooth_buf_fx[b][NB_DIV - 1 - k] = subframe_band_nrg[k][b]; + hStereoDft->smooth_buf_fx[b][NB_DIV - 1 - k] = subframe_band_nrg[k][b]; /*hStereoDft->q_smooth_buf_fx*/ move32(); /* calculate short and long energy averages */ @@ -413,17 +414,17 @@ static void map_params_dirac_to_stereo( smooth_long_avg[k][b] = 0; move32(); /* Multiplying and adding avoids overflow */ - FOR( i = sub( sub( NB_DIV, 1 ), k ); i < add( sub( add( SBA_DIRAC_NRG_SMOOTH_SHORT, NB_DIV ), 1 ), k ); i++ ) + FOR( i = ( ( NB_DIV - 1 ) - k ); i < ( ( ( SBA_DIRAC_NRG_SMOOTH_SHORT + NB_DIV ) - 1 ) - k ); i++ ) { - smooth_short_avg[k][b] = Madd_32_16( smooth_short_avg[k][b], hStereoDft->smooth_buf_fx[b][i], (Word16) 0x2AAB ); /* 1/ 3 in Q15*/ + smooth_short_avg[k][b] = Madd_32_16( smooth_short_avg[k][b], hStereoDft->smooth_buf_fx[b][i], (Word16) 0x2AAB ); /* 1/ 3 in Q15*/ /*hStereoDft->q_smooth_buf_fx*/ move32(); - smooth_long_avg[k][b] = Madd_32_16( smooth_long_avg[k][b], hStereoDft->smooth_buf_fx[b][i], (Word16) 0x0CCD ); /* 1/ 10 in Q15*/ + smooth_long_avg[k][b] = Madd_32_16( smooth_long_avg[k][b], hStereoDft->smooth_buf_fx[b][i], (Word16) 0x0CCD ); /* 1/ 10 in Q15*/ /*hStereoDft->q_smooth_buf_fx*/ move32(); } - FOR( i = sub( add( sub( NB_DIV, 1 ), SBA_DIRAC_NRG_SMOOTH_SHORT ), k ); i < sub( sub( add( SBA_DIRAC_NRG_SMOOTH_LONG, NB_DIV ), 1 ), k ); i++ ) + FOR( i = ( ( ( NB_DIV - 1 ) + SBA_DIRAC_NRG_SMOOTH_SHORT ) - k ); i < ( ( ( SBA_DIRAC_NRG_SMOOTH_LONG + NB_DIV ) - 1 ) - k ); i++ ) { - smooth_long_avg[k][b] = Madd_32_16( smooth_long_avg[k][b], hStereoDft->smooth_buf_fx[b][i], (Word16) 0x0CCD ); + smooth_long_avg[k][b] = Madd_32_16( smooth_long_avg[k][b], hStereoDft->smooth_buf_fx[b][i], (Word16) 0x0CCD ); /* 1/ 10 in Q15*/ /*hStereoDft->q_smooth_buf_fx*/ move32(); } @@ -431,16 +432,16 @@ static void map_params_dirac_to_stereo( /* reduce factor for higher short-term energy */ IF( smooth_long_avg[k][b] ) { - hStereoDft->smooth_fac_fx[k][b] = extract_l( s_min( MAX_16, BASOP_Util_Divide3232_Scale( smooth_long_avg[k][b], smooth_short_avg[k][b], &q_div ) ) ); + hStereoDft->smooth_fac_fx[k][b] = extract_l( s_min( MAX_16, BASOP_Util_Divide3232_Scale( smooth_long_avg[k][b], smooth_short_avg[k][b], &q_div ) ) ); /*15 - q_div*/ move32(); IF( GT_16( q_div, norm_s( hStereoDft->smooth_fac_fx[k][b] ) ) ) { - hStereoDft->smooth_fac_fx[k][b] = MAX_16; + hStereoDft->smooth_fac_fx[k][b] = MAX_16; /*Q15*/ move32(); } ELSE { - hStereoDft->smooth_fac_fx[k][b] = shl( hStereoDft->smooth_fac_fx[k][b], q_div ); + hStereoDft->smooth_fac_fx[k][b] = shl( hStereoDft->smooth_fac_fx[k][b], q_div ); /*Q15*/ move32(); q_div = 0; move16(); @@ -453,7 +454,7 @@ static void map_params_dirac_to_stereo( } /* map factor to range [0;1] */ - hStereoDft->smooth_fac_fx[k][b] = s_max( 0, extract_l( L_shr( Mpy_32_16_1( SBA_DIRAC_NRG_SMOOTH_LONG_BY_LONG_SHORT_FX, sub( hStereoDft->smooth_fac_fx[k][b], SBA_DIRAC_NRG_SMOOTH_SHORT_BY_LONG_FX ) ), Q15 ) ) ); + hStereoDft->smooth_fac_fx[k][b] = s_max( 0, extract_l( L_shr( Mpy_32_16_1( SBA_DIRAC_NRG_SMOOTH_LONG_BY_LONG_SHORT_FX, sub( hStereoDft->smooth_fac_fx[k][b], SBA_DIRAC_NRG_SMOOTH_SHORT_BY_LONG_FX ) ), Q15 ) ) ); /*Q15*/ move16(); /* compress factor (higher compression in lowest bands) */ q_sqrt = 0; @@ -461,21 +462,21 @@ static void map_params_dirac_to_stereo( IF( LT_16( b, 2 ) ) { Word16 tmp_val = Sqrt16( hStereoDft->smooth_fac_fx[k][b], &q_sqrt ); - hStereoDft->smooth_fac_fx[k][b] = Sqrt16( tmp_val, &q_sqrt ); + hStereoDft->smooth_fac_fx[k][b] = Sqrt16( tmp_val, &q_sqrt ); /*q_sqrt*/ move16(); } ELSE { - hStereoDft->smooth_fac_fx[k][b] = Sqrt16( hStereoDft->smooth_fac_fx[k][b], &q_sqrt ); + hStereoDft->smooth_fac_fx[k][b] = Sqrt16( hStereoDft->smooth_fac_fx[k][b], &q_sqrt ); /*q_sqrt*/ move16(); } - hStereoDft->smooth_fac_fx[k][b] = shl( hStereoDft->smooth_fac_fx[k][b], q_sqrt ); + hStereoDft->smooth_fac_fx[k][b] = shl( hStereoDft->smooth_fac_fx[k][b], q_sqrt ); /*q_sqrt*/ move16(); /* apply upper bounds depending on band */ - hStereoDft->smooth_fac_fx[0][b] = s_max( hStereoDft->min_smooth_gains_fx[b], s_min( hStereoDft->max_smooth_gains_fx[b], hStereoDft->smooth_fac_fx[0][b] ) ); + hStereoDft->smooth_fac_fx[0][b] = s_max( hStereoDft->min_smooth_gains_fx[b], s_min( hStereoDft->max_smooth_gains_fx[b], hStereoDft->smooth_fac_fx[0][b] ) ); /*Q15*/ move16(); - hStereoDft->smooth_fac_fx[1][b] = s_max( hStereoDft->min_smooth_gains_fx[b], s_min( hStereoDft->max_smooth_gains_fx[b], hStereoDft->smooth_fac_fx[1][b] ) ); + hStereoDft->smooth_fac_fx[1][b] = s_max( hStereoDft->min_smooth_gains_fx[b], s_min( hStereoDft->max_smooth_gains_fx[b], hStereoDft->smooth_fac_fx[1][b] ) ); /*Q15*/ move16(); } pDFT += STEREO_DFT32MS_N_MAX; @@ -485,39 +486,39 @@ static void map_params_dirac_to_stereo( { Word16 q_div1; /* calculate block energies for side gain weighting (combine angles of 2 DirAC blocks to side gain for 1 DFT Stereo subframe; 4 blocks and 2 subframes overall) */ - pSynth = synth; - block_len = idiv1616( L_frame, nBlocks ); + pSynth = synth; /*q_synth*/ + block_len = idiv1616( L_frame, nBlocks ); /*Q0*/ FOR( block = 0; block < nBlocks; block++ ) { block_nrg[block] = 0; move32(); FOR( i = 0; i < block_len; i++ ) { - block_nrg[block] = Madd_32_32( block_nrg[block], pSynth[i], pSynth[i] ); + block_nrg[block] = Madd_32_32( block_nrg[block], pSynth[i], pSynth[i] ); /*2*q_synth-31*/ move32(); } q_nrg = sub( Q31, sub( shl( q_synth, 1 ), Q31 ) ); - block_nrg[block] = Sqrt32( block_nrg[block], &q_nrg ); + block_nrg[block] = Sqrt32( block_nrg[block], &q_nrg ); /*Q31 - q_nrg*/ move32(); IF( NE_16( sub( Q31, q_nrg ), q_synth ) ) { - block_nrg[block] = L_shl( block_nrg[block], sub( q_synth, sub( Q31, q_nrg ) ) ); + block_nrg[block] = L_shl( block_nrg[block], sub( q_synth, sub( Q31, q_nrg ) ) ); /*q_synth*/ move32(); } pSynth += block_len; } - nrg_norm1 = L_add( block_nrg[0], L_add( block_nrg[1], EPSILON_FIX ) ); - nrg_norm2 = L_add( block_nrg[2], L_add( block_nrg[3], EPSILON_FIX ) ); + nrg_norm1 = L_add( block_nrg[0], L_add( block_nrg[1], EPSILON_FIX ) ); /*Q31 - q_nrg*/ + nrg_norm2 = L_add( block_nrg[2], L_add( block_nrg[3], EPSILON_FIX ) ); /*Q31 - q_nrg*/ /* extract DirAC parameters from metadata */ FOR( b = 0; b < nbands; b++ ) { - diffuseness[b] = L_shl( L_sub( ONE_IN_Q30, q_direction->band_data[b].energy_ratio_fx[0] ), 1 ); + diffuseness[b] = L_shl( L_sub( ONE_IN_Q30, q_direction->band_data[b].energy_ratio_fx[0] ), 1 ); /*Q31*/ move32(); IF( hQMetaData->surcoh_band_data != NULL ) { - surrCoh[b] = extract_h( imult3216( (Word32) 0x00808080, hQMetaData->surcoh_band_data[b].surround_coherence[0] ) ); + surrCoh[b] = extract_h( imult3216( (Word32) 0x00808080 /*1/255.0f in Q31*/, hQMetaData->surcoh_band_data[b].surround_coherence[0] ) ); /*Q15*/ move32(); } ELSE @@ -542,7 +543,7 @@ static void map_params_dirac_to_stereo( } IF( q_direction->band_data[b].azimuth_fx[block_metadata] < 0 ) { - q_direction->band_data[b].azimuth_fx[block_metadata] = L_add( (Word32) 0x5A000000, q_direction->band_data[b].azimuth_fx[block_metadata] ); + q_direction->band_data[b].azimuth_fx[block_metadata] = L_add( (Word32) 0x5A000000 /*360.f in Q22*/, q_direction->band_data[b].azimuth_fx[block_metadata] ); /*Q22*/ move16(); } /* @@ -550,9 +551,9 @@ static void map_params_dirac_to_stereo( * Before converting rounding is done. */ - azimuth[block][b] = extract_l( L_shr( L_add( q_direction->band_data[b].azimuth_fx[block_metadata], ONE_IN_Q21 ), Q22 ) ); + azimuth[block][b] = extract_l( L_shr( L_add( q_direction->band_data[b].azimuth_fx[block_metadata], ONE_IN_Q21 ), Q22 ) ); /*Q0*/ move16(); - elevation[block][b] = extract_l( L_shr( L_add( q_direction->band_data[b].elevation_fx[block_metadata], ONE_IN_Q21 ), Q22 ) ); + elevation[block][b] = extract_l( L_shr( L_add( q_direction->band_data[b].elevation_fx[block_metadata], ONE_IN_Q21 ), Q22 ) ); /*Q0*/ move16(); } } @@ -563,7 +564,7 @@ static void map_params_dirac_to_stereo( /* combine angles of first 2 blocks to side gain of first subframe */ side_gain[b] = 0; move32(); - FOR( block = 0; block < shr( nBlocks, 1 ); block++ ) + FOR( block = 0; block < ( nBlocks / 2 ); block++ ) { /* * The floating point version of the code computes @@ -572,23 +573,23 @@ static void map_params_dirac_to_stereo( */ IF( EQ_16( b_wide_panning, 1 ) ) { - Word32 temp = L_mult( BASOP_Util_Divide3232_Scale( block_nrg[block], nrg_norm1, &q_div1 ), get_panning( azimuth[block][b], elevation[block][b] ) ); + Word32 temp = L_mult( BASOP_Util_Divide3232_Scale( block_nrg[block], nrg_norm1, &q_div1 ), get_panning( azimuth[block][b], elevation[block][b] ) ); /*Q31 - q_div1*/ IF( q_div1 ) { - temp = L_shl_sat( temp, q_div1 ); + temp = L_shl_sat( temp, q_div1 ); /*Q31*/ } /* panning between left and ride, saturate at the stereo ls positions (+/- 30deg azi) */ - side_gain[b] = L_add_sat( side_gain[b], temp ); + side_gain[b] = L_add_sat( side_gain[b], temp ); /*Q31*/ move32(); } ELSE { - Word32 temp = L_mult( BASOP_Util_Divide3232_Scale( block_nrg[block], nrg_norm1, &q_div1 ), mult( ptr_sin_az[azimuth[block][b]], ptr_cos_el[elevation[block][b]] ) ); + Word32 temp = L_mult( BASOP_Util_Divide3232_Scale( block_nrg[block], nrg_norm1, &q_div1 ), mult( ptr_sin_az[azimuth[block][b]], ptr_cos_el[elevation[block][b]] ) ); /*Q31 - q_div1*/ IF( q_div1 ) { - temp = L_shl_sat( temp, q_div1 ); + temp = L_shl_sat( temp, q_div1 ); /*Q31*/ } - side_gain[b] = L_add_sat( side_gain[b], temp ); + side_gain[b] = L_add_sat( side_gain[b], temp ); /*Q31*/ move32(); } } @@ -600,47 +601,47 @@ static void map_params_dirac_to_stereo( { IF( EQ_16( b_wide_panning, 1 ) ) { - Word32 temp = L_mult( BASOP_Util_Divide3232_Scale( block_nrg[block], nrg_norm2, &q_div1 ), get_panning( azimuth[block][b], elevation[block][b] ) ); + Word32 temp = L_mult( BASOP_Util_Divide3232_Scale( block_nrg[block], nrg_norm2, &q_div1 ), get_panning( azimuth[block][b], elevation[block][b] ) ); /*Q31 - q_div1*/ IF( q_div1 ) { - temp = L_shl_sat( temp, q_div1 ); + temp = L_shl_sat( temp, q_div1 ); /*Q31*/ } /* panning between left and ride, saturate at the stereo ls positions (+/- 30deg azi) */ - side_gain[b + STEREO_DFT_BAND_MAX] = L_add_sat( side_gain[b + STEREO_DFT_BAND_MAX], temp ); + side_gain[b + STEREO_DFT_BAND_MAX] = L_add_sat( side_gain[b + STEREO_DFT_BAND_MAX], temp ); /*Q31*/ move32(); } ELSE { - Word32 temp = L_mult( BASOP_Util_Divide3232_Scale( block_nrg[block], nrg_norm2, &q_div1 ), mult( ptr_sin_az[azimuth[block][b]], ptr_cos_el[elevation[block][b]] ) ); + Word32 temp = L_mult( BASOP_Util_Divide3232_Scale( block_nrg[block], nrg_norm2, &q_div1 ), mult( ptr_sin_az[azimuth[block][b]], ptr_cos_el[elevation[block][b]] ) ); /*Q31 - q_div1*/ IF( q_div1 ) { - temp = L_shl_sat( temp, q_div1 ); + temp = L_shl_sat( temp, q_div1 ); /*Q31*/ } - side_gain[b + STEREO_DFT_BAND_MAX] = L_add_sat( side_gain[b + STEREO_DFT_BAND_MAX], temp ); + side_gain[b + STEREO_DFT_BAND_MAX] = L_add_sat( side_gain[b + STEREO_DFT_BAND_MAX], temp ); /*Q31*/ move32(); } } q_sqrt = 0; move16(); - side_gain[b] = Mpy_32_32( side_gain[b], Sqrt32( L_sub( MAX_32, diffuseness[b] ), &q_sqrt ) ); + side_gain[b] = Mpy_32_32( side_gain[b], Sqrt32( L_sub( MAX_32, diffuseness[b] ), &q_sqrt ) ); /*Q31 - q_sqrt*/ move32(); IF( q_sqrt ) { - side_gain[b] = L_shl( side_gain[b], q_sqrt ); + side_gain[b] = L_shl( side_gain[b], q_sqrt ); /*Q31*/ q_sqrt = 0; move16(); } - side_gain[b + STEREO_DFT_BAND_MAX] = Mpy_32_32( side_gain[b + STEREO_DFT_BAND_MAX], Sqrt32( L_sub( MAX_32, diffuseness[b] ), &q_sqrt ) ); + side_gain[b + STEREO_DFT_BAND_MAX] = Mpy_32_32( side_gain[b + STEREO_DFT_BAND_MAX], Sqrt32( L_sub( MAX_32, diffuseness[b] ), &q_sqrt ) ); /*Q31 - q_sqrt*/ move32(); IF( q_sqrt ) { - side_gain[b + STEREO_DFT_BAND_MAX] = L_shl( side_gain[b], q_sqrt ); + side_gain[b + STEREO_DFT_BAND_MAX] = L_shl( side_gain[b], q_sqrt ); /*Q31*/ q_sqrt = 0; move16(); } - res_pred_gain[b] = Mpy_32_16_1( diffuseness[b], sub( MAX_16, surrCoh[b] ) ); + res_pred_gain[b] = Mpy_32_16_1( diffuseness[b], sub( MAX_16, surrCoh[b] ) ); /*Q31*/ move32(); - res_pred_gain[b + STEREO_DFT_BAND_MAX] = Mpy_32_16_1( diffuseness[b], sub( MAX_16, surrCoh[b] ) ); + res_pred_gain[b + STEREO_DFT_BAND_MAX] = Mpy_32_16_1( diffuseness[b], sub( MAX_16, surrCoh[b] ) ); /*Q31*/ move32(); } } @@ -664,10 +665,10 @@ static void map_params_dirac_to_stereo( static void ivas_sba_dirac_stereo_compute_td_stefi_nrgs( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word32 hb_synth[L_FRAME48k], /* i : HB signal */ - const Word16 core, /* i : core decision */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 fd_cng_flag, /* i : FD-CNG indicator */ + const Word32 hb_synth[L_FRAME48k], /* i : HB signal q_hb_synth*/ + const Word16 core, /* i : core decision Q0*/ + const Word16 output_frame, /* i : output frame length per channel Q0*/ + const Word16 fd_cng_flag, /* i : FD-CNG indicator Q0*/ const Word16 q_hb_synth ) { Word16 i; @@ -682,10 +683,10 @@ static void ivas_sba_dirac_stereo_compute_td_stefi_nrgs( { FOR( i = 0; i < shr( output_frame, 2 ); i++ ) { - hb_nrg2 = Madd_32_32( hb_nrg2, hb_synth[i], hb_synth[i] ); + hb_nrg2 = Madd_32_32( hb_nrg2, hb_synth[i], hb_synth[i] ); /*2*q_hb_synth-31*/ } - hStereoDft->hb_nrg_subr_fx[0] = hb_nrg2; + hStereoDft->hb_nrg_subr_fx[0] = hb_nrg2; /*2*q_hb_synth-31*/ move32(); hStereoDft->q_hb_nrg_subr = sub( shl( q_hb_synth, 1 ), 31 ); move32(); @@ -696,29 +697,29 @@ static void ivas_sba_dirac_stereo_compute_td_stefi_nrgs( FOR( ; i < output_frame; i++ ) { - hb_nrg2 = Madd_32_32( hb_nrg2, hb_synth[i], hb_synth[i] ); + hb_nrg2 = Madd_32_32( hb_nrg2, hb_synth[i], hb_synth[i] ); /*2*q_hb_synth-31*/ } - hStereoDft->hb_nrg_subr_fx[1] = hb_nrg2; + hStereoDft->hb_nrg_subr_fx[1] = hb_nrg2; /*2*q_hb_synth-31*/ move32(); hb_nrg = L_add( hb_nrg, hb_nrg2 ); IF( EQ_16( hStereoDft->q_hb_stefi_sig_fx, q_hb_synth ) ) { - Copy32( hb_synth, hStereoDft->hb_stefi_sig_fx + hStereoDft->hb_stefi_delay, output_frame ); + Copy32( hb_synth, hStereoDft->hb_stefi_sig_fx + hStereoDft->hb_stefi_delay, output_frame ); /*q_hb_synth*/ } ELSE { IF( GT_16( hStereoDft->q_hb_stefi_sig_fx, q_hb_synth ) ) { - v_shr( hStereoDft->hb_stefi_sig_fx, sub( hStereoDft->q_hb_stefi_sig_fx, q_hb_synth ), hStereoDft->hb_stefi_sig_fx, idiv1616( sizeof( hStereoDft->hb_stefi_sig_fx ), sizeof( hStereoDft->hb_stefi_sig_fx[0] ) ) ); + v_shr( hStereoDft->hb_stefi_sig_fx, sub( hStereoDft->q_hb_stefi_sig_fx, q_hb_synth ), hStereoDft->hb_stefi_sig_fx, idiv1616( sizeof( hStereoDft->hb_stefi_sig_fx ), sizeof( hStereoDft->hb_stefi_sig_fx[0] ) ) ); /*q_hb_synth*/ hStereoDft->q_hb_stefi_sig_fx = q_hb_synth; move16(); - Copy32( hb_synth, hStereoDft->hb_stefi_sig_fx + hStereoDft->hb_stefi_delay, output_frame ); + Copy32( hb_synth, hStereoDft->hb_stefi_sig_fx + hStereoDft->hb_stefi_delay, output_frame ); /*q_hb_synth*/ } ELSE { - v_shr( hb_synth, sub( q_hb_synth, hStereoDft->q_hb_stefi_sig_fx ), hStereoDft->hb_stefi_sig_fx + hStereoDft->hb_stefi_delay, output_frame ); + v_shr( hb_synth, sub( q_hb_synth, hStereoDft->q_hb_stefi_sig_fx ), hStereoDft->hb_stefi_sig_fx + hStereoDft->hb_stefi_delay, output_frame ); /*hStereoDft->q_hb_stefi_sig_fx*/ } } } @@ -732,9 +733,9 @@ static void ivas_sba_dirac_stereo_compute_td_stefi_nrgs( move32(); #endif // MSAN_FIX } - hStereoDft->hb_nrg_subr_fx[0] = hStereoDft->hb_nrg_subr_fx[0]; // imult3216(hStereoDft->hb_nrg_subr_fx[0] , shr(hStereoDft->NFFT, 1)); + hStereoDft->hb_nrg_subr_fx[0] = hStereoDft->hb_nrg_subr_fx[0]; // imult3216(hStereoDft->hb_nrg_subr_fx[0] , shr(hStereoDft->NFFT, 1)); /*hStereoDft->q_hb_nrg_subr*/ move32(); - hStereoDft->hb_nrg_subr_fx[1] = hStereoDft->hb_nrg_subr_fx[1]; // imult3216(hStereoDft->hb_nrg_subr_fx[1] , shr(hStereoDft->NFFT, 1)); + hStereoDft->hb_nrg_subr_fx[1] = hStereoDft->hb_nrg_subr_fx[1]; // imult3216(hStereoDft->hb_nrg_subr_fx[1] , shr(hStereoDft->NFFT, 1)); /*hStereoDft->q_hb_nrg_subr*/ move32(); hStereoDft->hb_nrg_fx[0] = hb_nrg; move32(); @@ -760,7 +761,7 @@ static void ivas_sba_dirac_stereo_compute_td_stefi_nrgs( static void ivas_sba_dirac_stereo_compute_hb_gain( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - Word32 hb_gain[NB_DIV] /* o : side gains for HB signal */ + Word32 hb_gain[NB_DIV] /* o : side gains for HB signal Q31*/ ) { Word16 k_offset; @@ -769,9 +770,9 @@ static void ivas_sba_dirac_stereo_compute_hb_gain( move16(); /* last band covers whole HB range, no averaging needed */ - hb_gain[0] = hStereoDft->side_gain_fx[sub( add( i_mult( k_offset, STEREO_DFT_BAND_MAX ), hStereoDft->nbands ), 1 )]; + hb_gain[0] = hStereoDft->side_gain_fx[( ( ( k_offset * STEREO_DFT_BAND_MAX ) + hStereoDft->nbands ) - 1 )]; /*Q31*/ move32(); - hb_gain[1] = hStereoDft->side_gain_fx[sub( add( i_mult( add( k_offset, 1 ), STEREO_DFT_BAND_MAX ), hStereoDft->nbands ), 1 )]; + hb_gain[1] = hStereoDft->side_gain_fx[( ( ( ( k_offset + 1 ) * STEREO_DFT_BAND_MAX ) + hStereoDft->nbands ) - 1 )]; /*Q31*/ move32(); return; @@ -785,13 +786,13 @@ static void ivas_sba_dirac_stereo_compute_hb_gain( *-------------------------------------------------------------------*/ static void ivas_sba_dirac_stereo_upmix_hb( - Word32 hb_stereo_synth[CPE_CHANNELS][L_FRAME48k], /* i/o: stereo HB synthesis signal */ - Word32 hb_synth[L_FRAME48k], /* i : HB signal */ - Word32 hb_gain[NB_DIV], /* i : side gains for HB signal */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 mcmasa, /* i : McMASA flag */ - const Word16 sba_mono_flag, /* i : flag for mono output */ - const Word16 bwidth, /* i : bandwidth of signal */ + Word32 hb_stereo_synth[CPE_CHANNELS][L_FRAME48k], /* i/o: stereo HB synthesis signal Qx*/ + Word32 hb_synth[L_FRAME48k], /* i : HB signal Qx*/ + Word32 hb_gain[NB_DIV], /* i : side gains for HB signal Q31*/ + const Word16 output_frame, /* i : output frame length per channel Q0*/ + const Word16 mcmasa, /* i : McMASA flag Q0*/ + const Word16 sba_mono_flag, /* i : flag for mono output Q0*/ + const Word16 bwidth, /* i : bandwidth of signal Q0*/ const STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i : Stereo DFT handle for mixing matrix */ ) { @@ -801,11 +802,11 @@ static void ivas_sba_dirac_stereo_upmix_hb( IF( !mcmasa ) { - gain_fac = (Word32) 0x2A3D; /* last matrix element not used for SWB, divide by 3 instead of 4*/ + gain_fac = (Word32) 0x2A3D; /* last matrix element not used for SWB, divide by 3 instead of 4*/ /*Q15*/ move16(); if ( EQ_16( bwidth, FB ) ) { - gain_fac = (Word32) 0x2000; + gain_fac = (Word32) 0x2000; /*Q15*/ move16(); } @@ -813,46 +814,46 @@ static void ivas_sba_dirac_stereo_upmix_hb( { gp = L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][8], gain_fac ), Madd_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][9], gain_fac ), - hStereoDft->mixer_mat_smooth_fx[0][0][10], gain_fac ) ); + hStereoDft->mixer_mat_smooth_fx[0][0][10], gain_fac ) ); /*Q31*/ IF( EQ_16( bwidth, FB ) ) { - gp = Madd_32_16( gp, hStereoDft->mixer_mat_smooth_fx[0][0][11], gain_fac ); + gp = Madd_32_16( gp, hStereoDft->mixer_mat_smooth_fx[0][0][11], gain_fac ); /*Q31*/ } FOR( i = 0; i < shr( output_frame, 1 ); i++ ) { - hb_stereo_synth[0][i] = Mpy_32_32( hb_synth[i], gp ); + hb_stereo_synth[0][i] = Mpy_32_32( hb_synth[i], gp ); /*Qx*/ move32(); } gp = L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][8 + IVAS_MAX_NUM_BANDS], gain_fac ), Madd_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][9 + IVAS_MAX_NUM_BANDS], gain_fac ), - hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS], gain_fac ) ); + hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS], gain_fac ) ); /*Q31*/ IF( EQ_16( bwidth, FB ) ) { - gp = Madd_32_16( gp, hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS], gain_fac ); + gp = Madd_32_16( gp, hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS], gain_fac ); /*Q31*/ } FOR( i = shr( output_frame, 1 ); i < output_frame; i++ ) { - hb_stereo_synth[0][i] = Mpy_32_32( hb_synth[i], gp ); + hb_stereo_synth[0][i] = Mpy_32_32( hb_synth[i], gp ); /*Qx*/ move32(); } } ELSE { /* Accounting for the 0.5 multiplication */ - gain_fac = shr( gain_fac, 1 ); + gain_fac = shr( gain_fac, 1 ); /*Q15*/ gp = L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][8], gain_fac ), L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][0][8], gain_fac ), L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][9], gain_fac ), L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][0][9], gain_fac ), L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][10], gain_fac ), - Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][0][10], gain_fac ) ) ) ) ) ); + Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][0][10], gain_fac ) ) ) ) ) ); /*Q31*/ IF( EQ_32( bwidth, FB ) ) { gp = L_add( gp, Madd_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][11], gain_fac ), - hStereoDft->mixer_mat_smooth_fx[1][0][11], gain_fac ) ); + hStereoDft->mixer_mat_smooth_fx[1][0][11], gain_fac ) ); /*Q31*/ } gm = L_add( Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][8], gain_fac ), @@ -860,18 +861,18 @@ static void ivas_sba_dirac_stereo_upmix_hb( L_add( Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][9], gain_fac ), hStereoDft->mixer_mat_smooth_fx[1][0][9], gain_fac ), Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][10], gain_fac ), - hStereoDft->mixer_mat_smooth_fx[1][0][10], gain_fac ) ) ); + hStereoDft->mixer_mat_smooth_fx[1][0][10], gain_fac ) ) ); /*Q31*/ IF( EQ_32( bwidth, FB ) ) { gm = L_add( gm, Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][11], gain_fac ), - hStereoDft->mixer_mat_smooth_fx[1][0][11], gain_fac ) ); + hStereoDft->mixer_mat_smooth_fx[1][0][11], gain_fac ) ); /*Q31*/ } FOR( i = 0; i < shr( output_frame, 1 ); i++ ) { - hb_stereo_synth[0][i] = Mpy_32_32( hb_synth[i], gp ); + hb_stereo_synth[0][i] = Mpy_32_32( hb_synth[i], gp ); /*Qx*/ move32(); - hb_stereo_synth[1][i] = Mpy_32_32( hb_synth[i], gm ); + hb_stereo_synth[1][i] = Mpy_32_32( hb_synth[i], gm ); /*Qx*/ move32(); } @@ -880,25 +881,25 @@ static void ivas_sba_dirac_stereo_upmix_hb( L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][9 + IVAS_MAX_NUM_BANDS], gain_fac ), L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][0][9 + IVAS_MAX_NUM_BANDS], gain_fac ), Madd_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS], gain_fac ), - hStereoDft->mixer_mat_smooth_fx[1][0][10 + IVAS_MAX_NUM_BANDS], gain_fac ) ) ) ) ); + hStereoDft->mixer_mat_smooth_fx[1][0][10 + IVAS_MAX_NUM_BANDS], gain_fac ) ) ) ) ); /*Q31*/ IF( EQ_32( bwidth, FB ) ) { - gp = L_add( gp, Madd_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS], gain_fac ), hStereoDft->mixer_mat_smooth_fx[1][0][11 + IVAS_MAX_NUM_BANDS], gain_fac ) ); + gp = L_add( gp, Madd_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS], gain_fac ), hStereoDft->mixer_mat_smooth_fx[1][0][11 + IVAS_MAX_NUM_BANDS], gain_fac ) ); /*Q31*/ } gm = L_add( Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][8 + IVAS_MAX_NUM_BANDS], gain_fac ), hStereoDft->mixer_mat_smooth_fx[1][0][8 + IVAS_MAX_NUM_BANDS], gain_fac ), L_add( Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][9 + IVAS_MAX_NUM_BANDS], gain_fac ), hStereoDft->mixer_mat_smooth_fx[1][0][9 + IVAS_MAX_NUM_BANDS], gain_fac ), - Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS], gain_fac ), hStereoDft->mixer_mat_smooth_fx[1][0][10 + IVAS_MAX_NUM_BANDS], gain_fac ) ) ); + Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS], gain_fac ), hStereoDft->mixer_mat_smooth_fx[1][0][10 + IVAS_MAX_NUM_BANDS], gain_fac ) ) ); /*Q31*/ IF( EQ_32( bwidth, FB ) ) { - gm = L_add( gm, Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS], gain_fac ), hStereoDft->mixer_mat_smooth_fx[1][0][11 + IVAS_MAX_NUM_BANDS], gain_fac ) ); + gm = L_add( gm, Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS], gain_fac ), hStereoDft->mixer_mat_smooth_fx[1][0][11 + IVAS_MAX_NUM_BANDS], gain_fac ) ); /*Q31*/ } FOR( i = shr( output_frame, 1 ); i < output_frame; i++ ) { - hb_stereo_synth[0][i] = Mpy_32_32( hb_synth[i], gp ); + hb_stereo_synth[0][i] = Mpy_32_32( hb_synth[i], gp ); /*Qx*/ move32(); - hb_stereo_synth[1][i] = Mpy_32_32( hb_synth[i], gm ); + hb_stereo_synth[1][i] = Mpy_32_32( hb_synth[i], gm ); /*Qx*/ move32(); } } @@ -907,17 +908,17 @@ static void ivas_sba_dirac_stereo_upmix_hb( { FOR( i = 0; i < L_shr( output_frame, 1 ); i++ ) { - hb_stereo_synth[0][i] = L_add( L_shr( hb_synth[i], 1 ), L_shr( Mpy_32_32( hb_gain[0], hb_synth[i] ), 1 ) ); + hb_stereo_synth[0][i] = L_add( L_shr( hb_synth[i], 1 ), L_shr( Mpy_32_32( hb_gain[0], hb_synth[i] ), 1 ) ); /*Qx*/ move32(); - hb_stereo_synth[1][i] = L_sub( L_shr( hb_synth[i], 1 ), L_shr( Mpy_32_32( hb_gain[0], hb_synth[i] ), 1 ) ); + hb_stereo_synth[1][i] = L_sub( L_shr( hb_synth[i], 1 ), L_shr( Mpy_32_32( hb_gain[0], hb_synth[i] ), 1 ) ); /*Qx*/ move32(); } FOR( i = shr( output_frame, 1 ); i < output_frame; i++ ) { - hb_stereo_synth[0][i] = L_add( L_shr( hb_synth[i], 1 ), L_shr( Mpy_32_32( hb_gain[1], hb_synth[i] ), 1 ) ); + hb_stereo_synth[0][i] = L_add( L_shr( hb_synth[i], 1 ), L_shr( Mpy_32_32( hb_gain[1], hb_synth[i] ), 1 ) ); /*Qx*/ move32(); - hb_stereo_synth[1][i] = L_sub( L_shr( hb_synth[i], 1 ), L_shr( Mpy_32_32( hb_gain[1], hb_synth[i] ), 1 ) ); + hb_stereo_synth[1][i] = L_sub( L_shr( hb_synth[i], 1 ), L_shr( Mpy_32_32( hb_gain[1], hb_synth[i] ), 1 ) ); /*Qx*/ move32(); } } @@ -934,9 +935,9 @@ static void ivas_sba_dirac_stereo_upmix_hb( static void ivas_sba_dirac_stereo_apply_td_stefi( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - Word32 *output[CPE_CHANNELS], /* i/o: output synthesis signal */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 spar_flag /* i : SPAR flag */ + Word32 *output[CPE_CHANNELS], /* i/o: output synthesis signal hStereoDft->q_dft*/ + const Word16 output_frame, /* i : output frame length per channel Q0*/ + const Word16 spar_flag /* i : SPAR flag Q0*/ ) { Word16 i; @@ -947,8 +948,8 @@ static void ivas_sba_dirac_stereo_apply_td_stefi( IF( spar_flag ) { - win_dft = hStereoDft->win32ms_fx; - dftOvlLen = hStereoDft->dft32ms_ovl; + win_dft = hStereoDft->win32ms_fx; /*Q15*/ + dftOvlLen = hStereoDft->dft32ms_ovl; /*Q0*/ Word32 g_W_1, g_Y_1; Word32 g_W_2, g_Y_2; @@ -963,7 +964,7 @@ static void ivas_sba_dirac_stereo_apply_td_stefi( L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][3][9], 0x147B ), L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][1][10], 0x147B ), L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][2][10], 0x147B ), - Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][3][10], 0x147B ) ) ) ) ) ) ) ) ); + Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][3][10], 0x147B ) ) ) ) ) ) ) ) ); /*Q31*/ g_Y_1 = L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][1][8], 0x147B ), L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][2][8], 0x147B ), @@ -973,7 +974,7 @@ static void ivas_sba_dirac_stereo_apply_td_stefi( L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][3][9], 0x147B ), L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][1][10], 0x147B ), L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][2][10], 0x147B ), - Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][3][10], 0x147B ) ) ) ) ) ) ) ) ); + Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][3][10], 0x147B ) ) ) ) ) ) ) ) ); /*Q31*/ g_W_2 = L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][1][8 + IVAS_MAX_NUM_BANDS], 0x147B ), L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][2][8 + IVAS_MAX_NUM_BANDS], 0x147B ), @@ -983,7 +984,7 @@ static void ivas_sba_dirac_stereo_apply_td_stefi( L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][3][9 + IVAS_MAX_NUM_BANDS], 0x147B ), L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][1][10 + IVAS_MAX_NUM_BANDS], 0x147B ), L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][2][10 + IVAS_MAX_NUM_BANDS], 0x147B ), - Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][3][10 + IVAS_MAX_NUM_BANDS], 0x147B ) ) ) ) ) ) ) ) ); + Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][3][10 + IVAS_MAX_NUM_BANDS], 0x147B ) ) ) ) ) ) ) ) ); /*Q31*/ g_Y_2 = L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][1][8 + IVAS_MAX_NUM_BANDS], 0x147B ), L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][2][8 + IVAS_MAX_NUM_BANDS], 0x147B ), @@ -993,61 +994,61 @@ static void ivas_sba_dirac_stereo_apply_td_stefi( L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][3][9 + IVAS_MAX_NUM_BANDS], 0x147B ), L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][1][10 + IVAS_MAX_NUM_BANDS], 0x147B ), L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][2][10 + IVAS_MAX_NUM_BANDS], 0x147B ), - Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][3][10 + IVAS_MAX_NUM_BANDS], 0x147B ) ) ) ) ) ) ) ) ); + Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][3][10 + IVAS_MAX_NUM_BANDS], 0x147B ) ) ) ) ) ) ) ) ); /*Q31*/ - g_L = L_sub( L_add( g_W_1, g_W_2 ), L_add( g_Y_1, g_Y_2 ) ); /* 0x147B = 0.16 in Q15 */ - g_R = L_add( L_add( g_W_1, g_W_2 ), L_add( g_Y_1, g_Y_2 ) ); /* 0x147B = 0.16 in Q15 */ + g_L = L_sub( L_add( g_W_1, g_W_2 ), L_add( g_Y_1, g_Y_2 ) ); /* 0x147B = 0.16 in Q15 */ /*Q31*/ + g_R = L_add( L_add( g_W_1, g_W_2 ), L_add( g_Y_1, g_Y_2 ) ); /* 0x147B = 0.16 in Q15 */ /*Q31*/ FOR( i = 0; i < dftOvlLen; i++ ) { - win_in = mult_r( win_dft[STEREO_DFT32MS_STEP * i], win_dft[STEREO_DFT32MS_STEP * i] ); - win_out = sub( MAX_16, win_in ); + win_in = mult_r( win_dft[STEREO_DFT32MS_STEP * i], win_dft[STEREO_DFT32MS_STEP * i] ); /*Q15*/ + win_out = sub( MAX_16, win_in ); /*Q15*/ - stefi_L = L_shr( Mpy_32_32( Madd_32_16( Mpy_32_32( win_out, hStereoDft->g_L_prev_fx ), g_L, win_in ), hStereoDft->hb_stefi_sig_fx[i] ), 1 ); - stefi_R = L_shr( Mpy_32_32( Madd_32_16( Mpy_32_32( win_out, hStereoDft->g_R_prev_fx ), g_R, win_in ), hStereoDft->hb_stefi_sig_fx[i] ), 1 ); + stefi_L = L_shr( Mpy_32_32( Madd_32_16( Mpy_32_32( win_out, hStereoDft->g_L_prev_fx ), g_L, win_in ), hStereoDft->hb_stefi_sig_fx[i] ), 1 ); /*hStereoDft->q_hb_stefi_sig_fx*/ + stefi_R = L_shr( Mpy_32_32( Madd_32_16( Mpy_32_32( win_out, hStereoDft->g_R_prev_fx ), g_R, win_in ), hStereoDft->hb_stefi_sig_fx[i] ), 1 ); /*hStereoDft->q_hb_stefi_sig_fx*/ - output[0][i] = L_add( output[0][i], L_shr( stefi_L, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); + output[0][i] = L_add( output[0][i], L_shr( stefi_L, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); /*hStereoDft->q_dft*/ move32(); - output[1][i] = L_add( output[1][i], L_shr( stefi_R, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); + output[1][i] = L_add( output[1][i], L_shr( stefi_R, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); /*hStereoDft->q_dft*/ move32(); } FOR( i = dftOvlLen; i < output_frame; i++ ) { - stefi_L = L_shr( Mpy_32_32( g_L, hStereoDft->hb_stefi_sig_fx[i] ), 1 ); - stefi_R = L_shr( Mpy_32_32( g_R, hStereoDft->hb_stefi_sig_fx[i] ), 1 ); + stefi_L = L_shr( Mpy_32_32( g_L, hStereoDft->hb_stefi_sig_fx[i] ), 1 ); /*hStereoDft->q_hb_stefi_sig_fx*/ + stefi_R = L_shr( Mpy_32_32( g_R, hStereoDft->hb_stefi_sig_fx[i] ), 1 ); /*hStereoDft->q_hb_stefi_sig_fx*/ - output[0][i] = L_add( output[0][i], L_shr( stefi_L, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); + output[0][i] = L_add( output[0][i], L_shr( stefi_L, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); /*hStereoDft->q_dft*/ move32(); - output[1][i] = L_add( output[1][i], L_shr( stefi_R, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); + output[1][i] = L_add( output[1][i], L_shr( stefi_R, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); /*hStereoDft->q_dft*/ move32(); } - hStereoDft->g_L_prev_fx = g_L; + hStereoDft->g_L_prev_fx = g_L; /*Q31*/ move32(); - hStereoDft->g_R_prev_fx = g_R; + hStereoDft->g_R_prev_fx = g_R; /*Q31*/ move32(); } ELSE IF( L_max( hStereoDft->td_gain_fx[0], hStereoDft->td_gain_fx[1] ) > 0 ) { - win_dft = hStereoDft->win32ms_fx; - dftOvlLen = hStereoDft->dft32ms_ovl; + win_dft = hStereoDft->win32ms_fx; /*Q15*/ + dftOvlLen = hStereoDft->dft32ms_ovl; /*Q0*/ FOR( i = 0; i < dftOvlLen; i++ ) { - win_in = mult( win_dft[STEREO_DFT32MS_STEP * i], win_dft[STEREO_DFT32MS_STEP * i] ); - win_out = sub( MAX_16, win_in ); - tmp = L_shr( Mpy_32_32( Madd_32_16( Mpy_32_16_1( hStereoDft->td_gain_fx[0], win_in ), hStereoDft->td_gain_fx[1], win_out ), hStereoDft->hb_stefi_sig_fx[i] ), 1 ); + win_in = mult( win_dft[STEREO_DFT32MS_STEP * i], win_dft[STEREO_DFT32MS_STEP * i] ); /*Q15*/ + win_out = sub( MAX_16, win_in ); /*Q15*/ + tmp = L_shr( Mpy_32_32( Madd_32_16( Mpy_32_16_1( hStereoDft->td_gain_fx[0], win_in ), hStereoDft->td_gain_fx[1], win_out ), hStereoDft->hb_stefi_sig_fx[i] ), 1 ); /*hStereoDft->q_hb_stefi_sig_fx*/ - output[0][i] = L_add( output[0][i], L_shr( tmp, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); + output[0][i] = L_add( output[0][i], L_shr( tmp, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); /*hStereoDft->q_dft*/ move32(); - output[1][i] = L_sub( output[1][i], L_shr( tmp, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); + output[1][i] = L_sub( output[1][i], L_shr( tmp, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); /*hStereoDft->q_dft*/ move32(); } FOR( i = dftOvlLen; i < output_frame; i++ ) { - tmp = L_shr( Mpy_32_32( hStereoDft->hb_stefi_sig_fx[i], hStereoDft->td_gain_fx[0] ), 1 ); - output[0][i] = L_add( output[0][i], L_shr( tmp, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); + tmp = L_shr( Mpy_32_32( hStereoDft->hb_stefi_sig_fx[i], hStereoDft->td_gain_fx[0] ), 1 ); /*hStereoDft->q_hb_stefi_sig_fx + hStereoDft->q_td_gain - 31*/ + output[0][i] = L_add( output[0][i], L_shr( tmp, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); /*hStereoDft->q_dft + hStereoDft->q_td_gain - 31*/ move32(); - output[1][i] = L_sub( output[1][i], L_shr( tmp, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); + output[1][i] = L_sub( output[1][i], L_shr( tmp, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); /*hStereoDft->q_dft + hStereoDft->q_td_gain - 31*/ move32(); } } @@ -1065,9 +1066,9 @@ static void ivas_sba_dirac_stereo_apply_td_stefi( void ivas_sba_dirac_stereo_smooth_parameters_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD handle for upmixing */ - const Word16 cross_fade_start_offset, /* i : SPAR mixer delay compensation */ - const Word32 output_Fs, /* i : Fs for delay calculation */ - const Word16 num_md_sub_frames /* i : number of subframes in mixing matrix */ + const Word16 cross_fade_start_offset, /* i : SPAR mixer delay compensation Q0*/ + const Word32 output_Fs, /* i : Fs for delay calculation Q0*/ + const Word16 num_md_sub_frames /* i : number of subframes in mixing matrix Q0*/ ) { Word16 i, j, k, i_sf; @@ -1078,10 +1079,10 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( k_offset = STEREO_DFT_OFFSET; move16(); - prev_side_gain = hStereoDft->side_gain_fx; - side_gain = hStereoDft->side_gain_fx + k_offset * STEREO_DFT_BAND_MAX; - prev_res_pred_gain = hStereoDft->res_pred_gain_fx; - res_pred_gain = hStereoDft->res_pred_gain_fx + k_offset * STEREO_DFT_BAND_MAX; + prev_side_gain = hStereoDft->side_gain_fx; /*Q31*/ + side_gain = hStereoDft->side_gain_fx + k_offset * STEREO_DFT_BAND_MAX; /*Q31*/ + prev_res_pred_gain = hStereoDft->res_pred_gain_fx; /*Q31*/ + res_pred_gain = hStereoDft->res_pred_gain_fx + k_offset * STEREO_DFT_BAND_MAX; /*Q31*/ IF( !hMdDec ) { @@ -1090,27 +1091,27 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( { IF( hStereoDft->attackPresent ) { - res_pred_gain[b] = Mpy_32_16_1( res_pred_gain[b], (Word16) 0x6666 ); + res_pred_gain[b] = Mpy_32_16_1( res_pred_gain[b], (Word16) 0x6666 /*0.8f in Q15*/ ); /*Q31*/ move32(); - res_pred_gain[b + STEREO_DFT_BAND_MAX] = Mpy_32_16_1( res_pred_gain[b + STEREO_DFT_BAND_MAX], (Word16) 0x6666 ); + res_pred_gain[b + STEREO_DFT_BAND_MAX] = Mpy_32_16_1( res_pred_gain[b + STEREO_DFT_BAND_MAX], (Word16) 0x6666 /*0.8f in Q15*/ ); /*Q31*/ move32(); } ELSE { side_gain[b] = Madd_32_16( Mpy_32_16_1( prev_side_gain[b], hStereoDft->smooth_fac_fx[0][b] ), - side_gain[b], sub( (Word16) 0x7FFF, hStereoDft->smooth_fac_fx[0][b] ) ); + side_gain[b], sub( (Word16) 0x7FFF /*1.0f in Q15*/, hStereoDft->smooth_fac_fx[0][b] ) ); /*Q31*/ move32(); side_gain[b + STEREO_DFT_BAND_MAX] = Madd_32_16( Mpy_32_16_1( side_gain[b], hStereoDft->smooth_fac_fx[1][b] ), side_gain[b + STEREO_DFT_BAND_MAX], - sub( (Word16) 0x7FFF, hStereoDft->smooth_fac_fx[1][b] ) ); + sub( (Word16) 0x7FFF /*1.0f in Q15*/, hStereoDft->smooth_fac_fx[1][b] ) ); /*Q31*/ move32(); res_pred_gain[b] = Madd_32_16( Mpy_32_16_1( prev_res_pred_gain[b], hStereoDft->smooth_fac_fx[0][b] ), res_pred_gain[b], - sub( (Word16) 0x7FFF, hStereoDft->smooth_fac_fx[0][b] ) ); + sub( (Word16) 0x7FFF /*1.0f in Q15*/, hStereoDft->smooth_fac_fx[0][b] ) ); /*Q31*/ move32(); res_pred_gain[b + STEREO_DFT_BAND_MAX] = Madd_32_16( Mpy_32_16_1( res_pred_gain[b], hStereoDft->smooth_fac_fx[1][b] ), res_pred_gain[b + STEREO_DFT_BAND_MAX], - sub( (Word16) 0x7FFF, hStereoDft->smooth_fac_fx[1][b] ) ); + sub( (Word16) 0x7FFF /*1.0f in Q15*/, hStereoDft->smooth_fac_fx[1][b] ) ); /*Q31*/ move32(); } } @@ -1128,20 +1129,20 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( 64-bit container is needed for storing the result in the previous step. ToDo: Replace the 64-bit division below with appropriate BASOP */ - xfade_delay_subframes = (Word16) ( xfade_start_ns / W_mult_32_32( ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ), output_Fs ) ); + xfade_delay_subframes = (Word16) ( xfade_start_ns / W_mult_32_32( ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ), output_Fs ) ); /*Q0*/ move16(); - i_hist = sub( (Word16) 4, xfade_delay_subframes ); + i_hist = sub( (Word16) 4, xfade_delay_subframes ); /*Q0*/ move16(); FOR( k = 0; k < 2; k++ ) { - FOR( i_sf = shl( k, 1 ); i_sf < shl( add( k, 1 ), 1 ); i_sf++ ) + FOR( i_sf = ( k * 2 ); i_sf < ( k + 1 ) * 2; i_sf++ ) { md_sf = 0; move16(); IF( EQ_16( num_md_sub_frames, MAX_PARAM_SPATIAL_SUBFRAMES ) ) { - md_sf = i_sf; + md_sf = i_sf; /*Q0*/ move16(); } IF( hStereoDft->first_frame ) @@ -1153,12 +1154,12 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( FOR( b = 0; b < hStereoDft->nbands; b++ ) { // The Q format of mixer_mat_fx is Q30 so applying the left shift. - hStereoDft->mixer_mat_smooth_fx[i][j][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->mixer_mat_fx[i][j][b], 1 ); + hStereoDft->mixer_mat_smooth_fx[i][j][( b + ( k * IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->mixer_mat_fx[i][j][b], 1 ); /*Q31*/ move32(); } FOR( ; b < IVAS_MAX_NUM_BANDS; b++ ) { - hStereoDft->mixer_mat_smooth_fx[i][j][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )] = 0; + hStereoDft->mixer_mat_smooth_fx[i][j][( b + ( k * IVAS_MAX_NUM_BANDS ) )] = 0; move32(); } } @@ -1172,22 +1173,22 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( { FOR( b = 0; b < hStereoDft->nbands; b++ ) { - Word16 beta = hStereoDft->smooth_fac_fx[k][b]; + Word16 beta = hStereoDft->smooth_fac_fx[k][b]; /*Q15*/ move16(); // The Q format of mixer_mat_prev_fx is Q30 so applying the left shift. hStereoDft->mixer_mat_smooth_fx[i][j][b + k * IVAS_MAX_NUM_BANDS] = - L_add_sat( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[i][j][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], beta ), - L_shl_sat( Mpy_32_16_1( hMdDec->mixer_mat_prev_fx[i_hist][i][j][b], sub( (Word16) 0x7FFF, beta ) ), Q1 ) ); + L_add_sat( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[i][j][( b + ( k * IVAS_MAX_NUM_BANDS ) )], beta ), + L_shl_sat( Mpy_32_16_1( hMdDec->mixer_mat_prev_fx[i_hist][i][j][b], sub( (Word16) 0x7FFF, beta ) ), Q1 ) ); /*Q31*/ move32(); } } } } - Copy32( hMdDec->mixer_mat_prev_fx[1][0][0], hMdDec->mixer_mat_prev_fx[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hMdDec->mixer_mat_prev_fx[2][0][0], hMdDec->mixer_mat_prev_fx[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hMdDec->mixer_mat_prev_fx[3][0][0], hMdDec->mixer_mat_prev_fx[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hMdDec->mixer_mat_prev_fx[4][0][0], hMdDec->mixer_mat_prev_fx[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + Copy32( hMdDec->mixer_mat_prev_fx[1][0][0], hMdDec->mixer_mat_prev_fx[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); /*hMdDec->Q_mixer_mat*/ + Copy32( hMdDec->mixer_mat_prev_fx[2][0][0], hMdDec->mixer_mat_prev_fx[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); /*hMdDec->Q_mixer_mat*/ + Copy32( hMdDec->mixer_mat_prev_fx[3][0][0], hMdDec->mixer_mat_prev_fx[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); /*hMdDec->Q_mixer_mat*/ + Copy32( hMdDec->mixer_mat_prev_fx[4][0][0], hMdDec->mixer_mat_prev_fx[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); /*hMdDec->Q_mixer_mat*/ FOR( i = 0; i < 2; i++ ) { @@ -1195,7 +1196,7 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( { FOR( b = 0; b < hStereoDft->nbands; b++ ) { - hMdDec->mixer_mat_prev_fx[4][i][j][b] = hMdDec->mixer_mat_fx[i][j][add( b, i_mult( md_sf, IVAS_MAX_NUM_BANDS ) )]; + hMdDec->mixer_mat_prev_fx[4][i][j][b] = hMdDec->mixer_mat_fx[i][j][( b + ( md_sf * IVAS_MAX_NUM_BANDS ) )]; /*hMdDec->Q_mixer_mat*/ move32(); } } @@ -1220,8 +1221,8 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( void ivas_sba_dirac_stereo_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ Word32 *output[CPE_CHANNELS], /* i/o: output synthesis signal */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 mcmasa /* i : McMASA flag */ + const Word16 output_frame, /* i : output frame length per channel Q0*/ + const Word16 mcmasa /* i : McMASA flag Q0*/ ) { Word16 dtx_flag, fd_cng_flag; @@ -1251,14 +1252,14 @@ void ivas_sba_dirac_stereo_dec_fx( move16(); #ifdef MSAN_FIX - Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), negate( sub( Q11, hCPE->hStereoDft->q_dft ) ) ); + Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), negate( sub( Q11, hCPE->hStereoDft->q_dft ) ) ); /*hSCE->q_prev_hb_synth_fx + hCPE->hStereoDft->q_dft - Q11*/ #else Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), -( Q11 - hCPE->hStereoDft->q_dft ) ); #endif IF( hSCE != NULL ) { #ifdef MSAN_FIX - Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), negate( sub( Q11, hCPE->hStereoDft->q_dft ) ) ); + Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), negate( sub( Q11, hCPE->hStereoDft->q_dft ) ) ); /*hSCE->q_prev_hb_synth_fx + hCPE->hStereoDft->q_dft - Q11*/ #else Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), -( Q11 - hCPE->hStereoDft->q_dft ) ); #endif // MSAN_FIX @@ -1276,10 +1277,10 @@ void ivas_sba_dirac_stereo_dec_fx( } ELSE { - dtx_flag = (Word16) LE_32( hSCE->hCoreCoder[0]->core_brate, SID_2k40 ); + dtx_flag = (Word16) LE_32( hSCE->hCoreCoder[0]->core_brate, SID_2k40 ); /*Q0*/ move16(); test(); - fd_cng_flag = ( dtx_flag && EQ_16( hSCE->hCoreCoder[0]->cng_type, FD_CNG ) ); + fd_cng_flag = ( dtx_flag && EQ_16( hSCE->hCoreCoder[0]->cng_type, FD_CNG ) ); /*Q0*/ move16(); } sba_mono_flag = (Word16) EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 ); @@ -1306,14 +1307,14 @@ void ivas_sba_dirac_stereo_dec_fx( ivas_sba_dirac_stereo_compute_td_stefi_nrgs( hStereoDft, hSCE->save_hb_synth_fx, hSCE->hCoreCoder[0]->core, output_frame, fd_cng_flag, hSCE->q_save_synth_fx ); /* do DFT Stereo core switching (including DFT analysis) here as CPE element was not available in SCE decoder */ - Copy32( hSCE->save_synth_fx, tmp_synth, hSCE->hCoreCoder[0]->L_frame ); + Copy32( hSCE->save_synth_fx, tmp_synth, hSCE->hCoreCoder[0]->L_frame ); /*hSCE->q_save_synth_fx*/ stereo_dft_dec_core_switching_fx( hCPE, output[0] /*hSCE->save_output*/, hSCE->save_synth_fx, hSCE->save_hb_synth_fx, DFT, output_frame, 0, dtx_flag, &q, &q_dft[0] ); /* do updates here after skipping this in SCE decoder (needs to be done after core switching) */ ivas_updt_dec_common_fx( hSCE->hCoreCoder[0], NORMAL_HQ_CORE, -1, hSCE->save_synth_fx, q ); q_synth = sub( getScaleFactor32( tmp_synth, hSCE->hCoreCoder[0]->L_frame ), 10 ); - scale_sig32( tmp_synth, hSCE->hCoreCoder[0]->L_frame, q_synth ); + scale_sig32( tmp_synth, hSCE->hCoreCoder[0]->L_frame, q_synth ); /*hSCE->q_save_synth_fx + q_synth*/ q_synth = add( q_synth, hSCE->q_save_synth_fx ); } @@ -1328,7 +1329,7 @@ void ivas_sba_dirac_stereo_dec_fx( IF( ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && !mcmasa ) { - set32_fx( hStereoDft->res_pred_gain_fx, MAX_32, 3 * STEREO_DFT_BAND_MAX ); + set32_fx( hStereoDft->res_pred_gain_fx, MAX_32, 3 * STEREO_DFT_BAND_MAX ); /*Q31*/ } /* DFT Stereo upmix */ @@ -1347,17 +1348,17 @@ void ivas_sba_dirac_stereo_dec_fx( /* output scaling */ IF( !sba_mono_flag ) { - v_shr( output[0], 1, output[0], output_frame ); - v_shr( output[1], 1, output[1], output_frame ); + v_shr( output[0], 1, output[0], output_frame ); /*0.5f*/ + v_shr( output[1], 1, output[1], output_frame ); /*0.5f*/ } /* delay HB synth */ IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { - Copy32( hSCE->save_hb_synth_fx + output_frame - memOffset, tmp_buf, memOffset ); - Copy32( hSCE->save_hb_synth_fx, hSCE->save_hb_synth_fx + memOffset, sub( output_frame, memOffset ) ); - Copy32( hSCE->prev_hb_synth_fx, hSCE->save_hb_synth_fx, memOffset ); - v_shr( tmp_buf, sub( hSCE->q_prev_hb_synth_fx, hSCE->q_save_hb_synth_fx ), hSCE->prev_hb_synth_fx, memOffset ); + Copy32( hSCE->save_hb_synth_fx + output_frame - memOffset, tmp_buf, memOffset ); /*hSCE->q_save_hb_synth_fx*/ + Copy32( hSCE->save_hb_synth_fx, hSCE->save_hb_synth_fx + memOffset, sub( output_frame, memOffset ) ); /*hSCE->q_save_hb_synth_fx*/ + Copy32( hSCE->prev_hb_synth_fx, hSCE->save_hb_synth_fx, memOffset ); /*hSCE->q_prev_hb_synth_fx*/ + v_shr( tmp_buf, sub( hSCE->q_prev_hb_synth_fx, hSCE->q_save_hb_synth_fx ), hSCE->prev_hb_synth_fx, memOffset ); /*hSCE->q_prev_hb_synth_fx*/ } test(); @@ -1373,10 +1374,10 @@ void ivas_sba_dirac_stereo_dec_fx( ivas_sba_dirac_stereo_upmix_hb( hb_synth_stereo, hSCE->save_hb_synth_fx, hb_gain, output_frame, ( ( NE_16( st_ivas->ivas_format, SBA_FORMAT ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) || mcmasa ), sba_mono_flag, hSCE->hCoreCoder[0]->bwidth, hStereoDft ); /* add HB to ACELP core */ - v_add_fx( output[0], hb_synth_stereo[0], output[0], output_frame ); + v_add_fx( output[0], hb_synth_stereo[0], output[0], output_frame ); /*q*/ IF( !sba_mono_flag ) { - v_add_fx( output[1], hb_synth_stereo[1], output[1], output_frame ); + v_add_fx( output[1], hb_synth_stereo[1], output[1], output_frame ); /*q*/ /* apply TD Stereo Filling as is done in ICBWE */ test(); @@ -1392,14 +1393,14 @@ void ivas_sba_dirac_stereo_dec_fx( } #ifdef MSAN_FIX - Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); /*hSCE->q_prev_hb_synth_fx + Q11 - hCPE->hStereoDft->q_dft*/ #else Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), ( Q11 - hCPE->hStereoDft->q_dft ) ); #endif IF( hSCE != NULL ) { #ifdef MSAN_FIX - Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); /*hSCE->q_prev_hb_synth_fx + Q11 - hCPE->hStereoDft->q_dft*/ #else Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), ( Q11 - hCPE->hStereoDft->q_dft ) ); #endif // MSAN_FIX diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal.c index 7379ca1d6cedc65bfd0919f6151b1457b9fcd669..36562cc4db10060cccd10b27afa04a6e85a1201c 100644 --- a/lib_dec/ivas_sba_rendering_internal.c +++ b/lib_dec/ivas_sba_rendering_internal.c @@ -125,10 +125,10 @@ void ivas_sba2mc_cldfb_fixed( IVAS_OUTPUT_SETUP hInSetup, /* i : Format of input layout */ Word32 RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: cldfb real part (Q_real) */ Word32 ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: cldfb imag part (Q_imag) */ - const Word16 nb_channels_out, /* i : nb of output channels */ - const Word16 nb_bands, /* i : nb of CLDFB bands to process */ - const Word16 nb_timeslots, /* i : number of time slots to process */ - const Word32 *hoa_dec_mtx /* i : HOA decoding mtx */ + const Word16 nb_channels_out, /* i : nb of output channels Q0*/ + const Word16 nb_bands, /* i : nb of CLDFB bands to process Q0*/ + const Word16 nb_timeslots, /* i : number of time slots to process Q0*/ + const Word32 *hoa_dec_mtx /* i : HOA decoding mtx Q29*/ ) { Word16 iBlock, iBand, n, m; @@ -138,25 +138,25 @@ void ivas_sba2mc_cldfb_fixed( Word16 nb_channels_in; push_wmops( "ivas_sba2mc_cldfb_fixed" ); - nb_channels_in = hInSetup.nchan_out_woLFE; + nb_channels_in = hInSetup.nchan_out_woLFE; /*Q0*/ move16(); assert( EQ_16( nb_channels_in, 16 ) && EQ_16( nb_channels_out, 11 ) && "ivas_sba2mc_cldfb_fixed; only HOA3 to CICP19 is for now supported!" ); FOR( n = 0; n < nb_channels_out; n++ ) { - set32_fx( realOut_fx[n], 0, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, nb_bands ) ); - set32_fx( imagOut_fx[n], 0, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, nb_bands ) ); + set32_fx( realOut_fx[n], 0, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, nb_bands ) ); /*Q_real*/ + set32_fx( imagOut_fx[n], 0, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, nb_bands ) ); /*Q_imag*/ FOR( m = 0; m < nb_channels_in; m++ ) { - g_fx = hoa_dec_mtx[add( imult1616( SBA_NHARM_HOA3, n ), m )]; // Q29 + g_fx = hoa_dec_mtx[( ( SBA_NHARM_HOA3 * n ) + m )]; // Q29 p_realOut_fx = realOut_fx[n]; p_imagOut_fx = imagOut_fx[n]; FOR( iBlock = 0; iBlock < nb_timeslots; iBlock++ ) { - p_real_fx = RealBuffer[m][iBlock]; - p_imag_fx = ImagBuffer[m][iBlock]; + p_real_fx = RealBuffer[m][iBlock]; /*Q_real*/ + p_imag_fx = ImagBuffer[m][iBlock]; /*Q_imag*/ FOR( iBand = 0; iBand < nb_bands; iBand++ ) { *p_realOut_fx = L_add( *p_realOut_fx, Mpy_32_32( L_shl_sat( g_fx, Q2 ), *( p_real_fx++ ) ) ); // Q_real @@ -172,13 +172,13 @@ void ivas_sba2mc_cldfb_fixed( FOR( n = 0; n < nb_channels_out; n++ ) { - p_realOut_fx = realOut_fx[n]; - p_imagOut_fx = imagOut_fx[n]; + p_realOut_fx = realOut_fx[n]; /*Q_real*/ + p_imagOut_fx = imagOut_fx[n]; /*Q_imag*/ FOR( iBlock = 0; iBlock < nb_timeslots; iBlock++ ) { - p_real_fx = RealBuffer[n][iBlock]; - p_imag_fx = ImagBuffer[n][iBlock]; + p_real_fx = RealBuffer[n][iBlock]; /*Q_real*/ + p_imag_fx = ImagBuffer[n][iBlock]; /*Q_imag*/ FOR( iBand = 0; iBand < nb_bands; iBand++ ) { *( p_real_fx++ ) = *p_realOut_fx++; @@ -205,10 +205,10 @@ void ivas_mc2sba_fx( IVAS_OUTPUT_SETUP hIntSetup, /* i : Format of decoder output */ Word32 *in_buffer_td_fx[], /* i : MC signals (on input) and the HOA3 (on output) */ /*Q*/ - Word32 *buffer_td_fx[], /* i/o: MC signals (on input) and the HOA3 (on output) */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - const Word16 gain_lfe_fx /* i : gain for LFE, 0 = ignore LFE */ + Word32 *buffer_td_fx[], /* i/o: MC signals (on input) and the HOA3 (on output) Q*/ + const Word16 output_frame, /* i : output frame length per channel Q0*/ + const Word16 sba_order, /* i : Ambisonic (SBA) order Q0*/ + const Word16 gain_lfe_fx /* i : gain for LFE, 0 = ignore LFE Q14*/ ) { Word16 i, j, k; @@ -231,7 +231,7 @@ void ivas_mc2sba_fx( idx_in = 0; move16(); move16(); - FOR( i = 0; i < add( hIntSetup.nchan_out_woLFE, hIntSetup.num_lfe ); i++ ) + FOR( i = 0; i < ( hIntSetup.nchan_out_woLFE + hIntSetup.num_lfe ); i++ ) { test(); IF( ( hIntSetup.num_lfe > 0 ) && EQ_16( i, hIntSetup.index_lfe[idx_lfe] ) ) @@ -248,16 +248,16 @@ void ivas_mc2sba_fx( if ( LT_16( idx_lfe, sub( hIntSetup.num_lfe, 1 ) ) ) { - idx_lfe = add( idx_lfe, 1 ); + idx_lfe = add( idx_lfe, 1 ); /*Q0*/ } } ELSE { - azimuth = extract_l( L_shr( hIntSetup.ls_azimuth_fx[idx_in], Q22 ) ); + azimuth = extract_l( L_shr( hIntSetup.ls_azimuth_fx[idx_in], Q22 ) ); /*Q0*/ move16(); - elevation = extract_l( L_shr( hIntSetup.ls_elevation_fx[idx_in], Q22 ) ); + elevation = extract_l( L_shr( hIntSetup.ls_elevation_fx[idx_in], Q22 ) ); /*Q0*/ move16(); - idx_in = add( idx_in, 1 ); + idx_in = add( idx_in, 1 ); /*Q0*/ ivas_dirac_dec_get_response_fx( azimuth, elevation, @@ -279,7 +279,7 @@ void ivas_mc2sba_fx( FOR( j = 0; j < sba_num_chans; j++ ) { - Copy32( buffer_tmp_fx[j], buffer_td_fx[j], output_frame ); + Copy32( buffer_tmp_fx[j], buffer_td_fx[j], output_frame ); /*Q*/ } return; @@ -372,12 +372,12 @@ void ivas_mc2sba( #ifdef IVAS_FLOAT_FIXED void ivas_param_mc_mc2sba_cldfb_fx( IVAS_OUTPUT_SETUP hTransSetup, /* i : transported MC Format */ - Word32 *hoa_encoder_fx, /* i : HOA3 encoder for the transported MC format */ - const Word16 slot_idx, /* i : current slot in the subframe */ - Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) */ - Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) */ - const Word16 nBands, /* i : number of synth CLDFB bands */ - const Word16 gain_lfe_fx /* i : gain applied to LFE */ + Word32 *hoa_encoder_fx, /* i : HOA3 encoder for the transported MC format Q31*/ + const Word16 slot_idx, /* i : current slot in the subframe Q0*/ + Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) Q_Cldfb_RealBuffer*/ + Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) Q_Cldfb_ImagBuffer*/ + const Word16 nBands, /* i : number of synth CLDFB bands Q0*/ + const Word16 gain_lfe_fx /* i : gain applied to LFE Q14*/ ) { Word16 idx_ch, idx_band; @@ -401,7 +401,7 @@ void ivas_param_mc_mc2sba_cldfb_fx( move16(); move16(); - FOR( idx_ch = 0; idx_ch < add( hTransSetup.nchan_out_woLFE, hTransSetup.num_lfe ); idx_ch++ ) + FOR( idx_ch = 0; idx_ch < ( hTransSetup.nchan_out_woLFE + hTransSetup.num_lfe ); idx_ch++ ) { test(); IF( ( hTransSetup.num_lfe > 0 ) && EQ_16( idx_ch, hTransSetup.index_lfe[idx_lfe] ) ) @@ -409,38 +409,38 @@ void ivas_param_mc_mc2sba_cldfb_fx( IF( gain_lfe_fx > 0 ) { /* Add LFE to Omni Channel i.e. W (Just first Band) */ - Cldfb_RealBuffer_tmp_fx[0][0] = L_add_sat( Cldfb_RealBuffer_tmp_fx[0][0], Mult_32_16( L_shl( Cldfb_RealBuffer_fx[idx_ch][slot_idx][0], 1 ), gain_lfe_fx ) ); + Cldfb_RealBuffer_tmp_fx[0][0] = L_add_sat( Cldfb_RealBuffer_tmp_fx[0][0], Mult_32_16( L_shl( Cldfb_RealBuffer_fx[idx_ch][slot_idx][0], 1 ), gain_lfe_fx ) ); /*Q_Cldfb_RealBuffer*/ move32(); - Cldfb_ImagBuffer_tmp_fx[0][0] = L_add_sat( Cldfb_ImagBuffer_tmp_fx[0][0], Mult_32_16( L_shl( Cldfb_ImagBuffer_fx[idx_ch][slot_idx][0], 1 ), gain_lfe_fx ) ); + Cldfb_ImagBuffer_tmp_fx[0][0] = L_add_sat( Cldfb_ImagBuffer_tmp_fx[0][0], Mult_32_16( L_shl( Cldfb_ImagBuffer_fx[idx_ch][slot_idx][0], 1 ), gain_lfe_fx ) ); /*Q_Cldfb_ImagBuffer*/ move32(); } if ( LT_16( idx_lfe, sub( hTransSetup.num_lfe, 1 ) ) ) { - idx_lfe = add( idx_lfe, 1 ); + idx_lfe = add( idx_lfe, 1 ); /*Q0*/ } } ELSE { - gains_fx = hoa_encoder_fx + imult1616( idx_in, sba_num_chans ); /*Pointer addition*/ + gains_fx = hoa_encoder_fx + imult1616( idx_in, sba_num_chans ); /*Pointer addition*/ /*Q31*/ FOR( idx_out = 0; idx_out < sba_num_chans; idx_out++ ) { FOR( idx_band = 0; idx_band < nBands; idx_band++ ) { - Cldfb_RealBuffer_tmp_fx[idx_out][idx_band] = L_add( Cldfb_RealBuffer_tmp_fx[idx_out][idx_band], Mult_32_32( ( *gains_fx ), Cldfb_RealBuffer_fx[idx_ch][slot_idx][idx_band] ) ); + Cldfb_RealBuffer_tmp_fx[idx_out][idx_band] = L_add( Cldfb_RealBuffer_tmp_fx[idx_out][idx_band], Mult_32_32( ( *gains_fx ), Cldfb_RealBuffer_fx[idx_ch][slot_idx][idx_band] ) ); /*Q_Cldfb_RealBuffer*/ move32(); - Cldfb_ImagBuffer_tmp_fx[idx_out][idx_band] = L_add( Cldfb_ImagBuffer_tmp_fx[idx_out][idx_band], Mult_32_32( ( *gains_fx ), Cldfb_ImagBuffer_fx[idx_ch][slot_idx][idx_band] ) ); + Cldfb_ImagBuffer_tmp_fx[idx_out][idx_band] = L_add( Cldfb_ImagBuffer_tmp_fx[idx_out][idx_band], Mult_32_32( ( *gains_fx ), Cldfb_ImagBuffer_fx[idx_ch][slot_idx][idx_band] ) ); /*Q_Cldfb_ImagBuffer*/ move32(); } gains_fx++; } - idx_in = add( idx_in, 1 ); + idx_in = add( idx_in, 1 ); /*Q0*/ } } FOR( idx_ch = 0; idx_ch < sba_num_chans; idx_ch++ ) { - Copy32( Cldfb_RealBuffer_tmp_fx[idx_ch], Cldfb_RealBuffer_fx[idx_ch][slot_idx], nBands ); - Copy32( Cldfb_ImagBuffer_tmp_fx[idx_ch], Cldfb_ImagBuffer_fx[idx_ch][slot_idx], nBands ); + Copy32( Cldfb_RealBuffer_tmp_fx[idx_ch], Cldfb_RealBuffer_fx[idx_ch][slot_idx], nBands ); /*Q_Cldfb_RealBuffer*/ + Copy32( Cldfb_ImagBuffer_tmp_fx[idx_ch], Cldfb_ImagBuffer_fx[idx_ch][slot_idx], nBands ); /*Q_Cldfb_ImagBuffer*/ } return; @@ -527,20 +527,20 @@ void ivas_param_mc_mc2sba_cldfb( /*! r: SBA DirAC stereo flag */ #ifdef IVAS_FLOAT_FIXED Word16 ivas_sba_remapTCs_fx( - Word32 *sba_data_fx[], /* i/o: SBA signals */ + Word32 *sba_data_fx[], /* i/o: SBA signals Q11*/ Decoder_Struct *st_ivas, /* i/o: decoder struct */ - const Word16 output_frame /* i : frame length */ + const Word16 output_frame /* i : frame length Q0*/ ) { Word16 nchan_remapped; - nchan_remapped = st_ivas->nchan_transport; + nchan_remapped = st_ivas->nchan_transport; /*Q0*/ move16(); IF( EQ_16( nchan_remapped, 3 ) ) { - nchan_remapped = add( nchan_remapped, 1 ); + nchan_remapped = add( nchan_remapped, 1 ); /*Q0*/ IF( EQ_16( nchan_remapped, 4 ) ) { - Copy32( sba_data_fx[2], sba_data_fx[3], output_frame ); + Copy32( sba_data_fx[2], sba_data_fx[3], output_frame ); /*Q11*/ } } IF( GT_16( st_ivas->nchan_transport, 3 ) ) @@ -552,11 +552,11 @@ Word16 ivas_sba_remapTCs_fx( /*convert WYXZ downmix to WYZX*/ FOR( i = 0; i < output_frame; i++ ) { - temp_fx = sba_data_fx[2][i]; + temp_fx = sba_data_fx[2][i]; /*Q11*/ move32(); - sba_data_fx[2][i] = sba_data_fx[3][i]; + sba_data_fx[2][i] = sba_data_fx[3][i]; /*Q11*/ move32(); - sba_data_fx[3][i] = temp_fx; + sba_data_fx[3][i] = temp_fx; /*Q11*/ move32(); if ( EQ_16( st_ivas->nchan_transport, 3 ) ) @@ -623,12 +623,12 @@ int16_t ivas_sba_remapTCs( void ivas_ism2sba_sf_fx( Word32 *buffer_in_fx[], /* i : TC buffer */ /*Q_buffer_in*/ - Word32 *buffer_out_fx[], /* o : TD signal buffers */ + Word32 *buffer_out_fx[], /* o : TD signal buffers Q_buffer_in + 29 - 31*/ ISM_RENDERER_HANDLE hIsmRendererData, /* i/o: renderer data */ - const Word16 num_objects, /* i : number of objects */ - const Word16 n_samples_to_render, /* i : output frame length per channel */ - const Word16 offset, /* i : offset for the interpolatr */ - const Word16 sba_order /* i : Ambisonic (SBA) order */ + const Word16 num_objects, /* i : number of objects Q0*/ + const Word16 n_samples_to_render, /* i : output frame length per channel Q0*/ + const Word16 offset, /* i : offset for the interpolatr Q0*/ + const Word16 sba_order /* i : Ambisonic (SBA) order Q0*/ ) { Word16 i, j, k; @@ -640,7 +640,7 @@ void ivas_ism2sba_sf_fx( assert( LE_16( sba_order, 3 ) && "Only order up to 3 is supported!" ); assert( hIsmRendererData != NULL && "hIsmRendererData not allocated!" ); /* Init*/ - sba_num_chans = imult1616( add( sba_order, 1 ), add( sba_order, 1 ) ); + sba_num_chans = imult1616( add( sba_order, 1 ), add( sba_order, 1 ) ); /*Q0*/ FOR( j = 0; j < sba_num_chans; j++ ) { set32_fx( buffer_tmp_fx[j], 0, n_samples_to_render ); @@ -649,17 +649,17 @@ void ivas_ism2sba_sf_fx( { FOR( j = 0; j < sba_num_chans; j++ ) { - g2_fx = hIsmRendererData->interpolator_fx + offset; /*Pointer addition*/ - tc_fx = buffer_in_fx[i] + offset; /*Pointer addition*/ - out_fx = buffer_tmp_fx[j]; - gain_fx = hIsmRendererData->gains_fx[i][j]; + g2_fx = hIsmRendererData->interpolator_fx + offset; /*Pointer addition*/ /*Q15*/ + tc_fx = buffer_in_fx[i] + offset; /*Pointer addition*/ /*Q_buffer_in*/ + out_fx = buffer_tmp_fx[j]; /*Q_buffer_in + 29 - 31*/ + gain_fx = hIsmRendererData->gains_fx[i][j]; /*Q29*/ move32(); - prev_gain_fx = hIsmRendererData->prev_gains_fx[i][j]; + prev_gain_fx = hIsmRendererData->prev_gains_fx[i][j]; /*Q29*/ move32(); #ifdef IVAS_ENH32_CADENCE_CHANGES FOR( k = 0; k < n_samples_to_render; k++ ) { - g1_fx = sub( 32767, *g2_fx ); + g1_fx = sub( 32767, *g2_fx ); /*Q15*/ *( out_fx ) = Madd_32_32( *( out_fx ), Madd_32_16( Mult_32_16( gain_fx, ( *( g2_fx ) ) ), prev_gain_fx, g1_fx ), ( *( tc_fx ) ) ); /*Q_buffer_in + 29 - 31*/ move32(); g2_fx++; @@ -681,7 +681,7 @@ void ivas_ism2sba_sf_fx( } FOR( j = 0; j < sba_num_chans; j++ ) { - Copy32( buffer_tmp_fx[j], buffer_out_fx[j], n_samples_to_render ); + Copy32( buffer_tmp_fx[j], buffer_out_fx[j], n_samples_to_render ); /*Q_buffer_in + 29 - 31*/ } return; } @@ -749,10 +749,10 @@ void ivas_ism2sba_sf( Float to fixed conversion required for:output_f *************************/ ivas_error ivas_sba_linear_renderer_fx( - Word32 *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 nchan_in, /* i : number of input ambisonics channels */ - const Word16 nchan_ism, /* i : number of objects */ + Word32 *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output Q11*/ + const Word16 output_frame, /* i : output frame length per channel Q0*/ + const Word16 nchan_in, /* i : number of input ambisonics channels Q0*/ + const Word16 nchan_ism, /* i : number of objects Q0*/ const AUDIO_CONFIG output_config, /* i : output audio configuration */ const IVAS_OUTPUT_SETUP output_setup /* i : output format setup */ ) @@ -765,7 +765,7 @@ ivas_error ivas_sba_linear_renderer_fx( move32(); /* Number of channels of HOA depends of transport format which is mixed order xH1V*/ - nchan_hoa = nchan_in; + nchan_hoa = nchan_in; /*Q0*/ move16(); IF( EQ_16( nchan_in, 6 ) ) /*2H1V*/ @@ -792,7 +792,7 @@ ivas_error ivas_sba_linear_renderer_fx( case IVAS_AUDIO_CONFIG_EXTERNAL: FOR( i = output_setup.nchan_out_woLFE - 1; i >= nchan_ism; i-- ) { - Copy32( output_f[i - nchan_ism], output_f[i], output_frame ); + Copy32( output_f[i - nchan_ism], output_f[i], output_frame ); /*Q11*/ } FOR( ; i >= 0; i-- ) { @@ -871,11 +871,11 @@ ivas_error ivas_sba_linear_renderer( #ifdef IVAS_FLOAT_FIXED void ivas_sba_mix_matrix_determiner_fx( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - Word32 *output_fx[], /* i/o: transport/output audio channels */ - const Word16 bfi, /* i : BFI flag */ - const Word16 nchan_remapped, /* i : num channels after remapping of TCs */ - const Word16 output_frame, /* i : output frame length */ - const Word16 num_md_sub_frames, /* i : number of subframes in mixing matrix*/ + Word32 *output_fx[], /* i/o: transport/output audio channels Q_output*/ + const Word16 bfi, /* i : BFI flag Q0*/ + const Word16 nchan_remapped, /* i : num channels after remapping of TCs Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 num_md_sub_frames, /* i : number of subframes in mixing matrix Q0*/ const Word16 Q_output /* i : Q of transport/output audio channels */ ) { @@ -888,29 +888,29 @@ void ivas_sba_mix_matrix_determiner_fx( { FOR( i = 0; i < output_frame; i++ ) { - temp_fx = output_fx[ch][i]; + temp_fx = output_fx[ch][i]; /*Q_output*/ move32(); - temp_fx = L_shr( temp_fx + L_shl( 1, Q_p_output - 1 ), Q_p_output ); + temp_fx = L_shr( temp_fx + L_shl( 1, Q_p_output - 1 ), Q_p_output ); /*Q0*/ IF( GT_32( temp_fx, MAX16B ) ) { - temp_fx = MAX16B; + temp_fx = MAX16B; /*Q0*/ move32(); } ELSE IF( LT_32( temp_fx, L_negate( PCM16_TO_FLT_FAC_FX ) ) ) { - temp_fx = L_negate( PCM16_TO_FLT_FAC_FX ); + temp_fx = -( PCM16_TO_FLT_FAC_FX ); /*Q0*/ move32(); } - temp_fx = Mult_32_32( MAX_32 / PCM16_TO_FLT_FAC_FX, L_shl( temp_fx, Q_p_output ) ); - output_fx[ch][i] = temp_fx; + temp_fx = Mult_32_32( MAX_32 / PCM16_TO_FLT_FAC_FX, L_shl( temp_fx, Q_p_output ) ); /*Q_p_output*/ + output_fx[ch][i] = temp_fx; /*Q_p_output*/ move32(); } } /* AGC */ - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; /*Q0*/ move16(); - nchan_out = nchan_transport; + nchan_out = nchan_transport; /*Q0*/ move16(); ivas_agc_dec_process_fx( hSpar->hAgcDec, ( output_fx ), ( output_fx ), nchan_transport, output_frame ); Q_p_output = sub( Q_p_output, 3 ); @@ -923,12 +923,12 @@ void ivas_sba_mix_matrix_determiner_fx( { FOR( i = 0; i < output_frame; i++ ) { - output_fx[ch][i] = Mult_32_32( L_shl_sat( output_fx[ch][i], sub( 15, Q_p_output ) ), L_shl_sat( PCM16_TO_FLT_FAC_FX, 16 ) ); /* Q0 */ + output_fx[ch][i] = Mult_32_32( L_shl_sat( output_fx[ch][i], sub( 15, Q_p_output ) ), 2147483647 /* PCM16_TO_FLT_FAC_FX << 16 */ ); /* Q0 */ } } /* Mixing matrix determiner */ - num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; + num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; /*Q0*/ move16(); ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames ); return; diff --git a/lib_dec/ivas_sce_dec_fx.c b/lib_dec/ivas_sce_dec_fx.c index f38068570436aa6a0b928c8675e9288c1d1f6247..19058c9c9fc2e0ab00858fd872cb75cb698fc647 100644 --- a/lib_dec/ivas_sce_dec_fx.c +++ b/lib_dec/ivas_sce_dec_fx.c @@ -52,10 +52,10 @@ ivas_error ivas_sce_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 sce_id, /* i : SCE # identifier */ - Word32 *output[1], /* o : output synthesis signal */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 nb_bits_metadata /* i : number of metadata bits */ + const Word16 sce_id, /* i : SCE # identifier Q0*/ + Word32 *output[1], /* o : output synthesis signal Q11*/ + const Word16 output_frame, /* i : output frame length per channel Q0*/ + const Word16 nb_bits_metadata /* i : number of metadata bits Q0*/ ) { Word32 outputHB[1][L_FRAME48k]; /*Word32 buffer for output HB synthesis, one channel */ @@ -75,9 +75,9 @@ ivas_error ivas_sce_dec_fx( st->BER_detect = s_or( st->BER_detect, st_ivas->BER_detect ); move16(); - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /*Q0*/ move32(); - last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; + last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; /*Q0*/ move32(); IF( EQ_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) ) @@ -97,7 +97,7 @@ ivas_error ivas_sce_dec_fx( test(); IF( !st_ivas->bfi && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - st->total_brate = L_sub( ivas_total_brate, L_shr( L_mult( nb_bits_metadata, FRAMES_PER_SEC ), 1 ) ); + st->total_brate = L_sub( ivas_total_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); /*Q0*/ move16(); test(); assert( EQ_32( st->total_brate, SID_2k40 ) && "SCE SID must be 2.4kbps!" ); @@ -116,7 +116,7 @@ ivas_error ivas_sce_dec_fx( } ELSE IF( !st_ivas->bfi && NE_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) && LE_32( last_ivas_total_brate, IVAS_SID_5k2 ) ) { - st->total_brate = L_sub( hSCE->element_brate, L_shr( L_mult( nb_bits_metadata, FRAMES_PER_SEC ), 1 ) ); + st->total_brate = L_sub( hSCE->element_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); /*Q0*/ move32(); } @@ -147,13 +147,13 @@ ivas_error ivas_sce_dec_fx( ( LT_32( hSCE->element_brate, MIN_BRATE_FB_ISM ) && st->is_ism_format ) ) { /* WB and SWB are supported */ - st->bwidth = add( get_next_indice_fx( st, 1 ), WB ); + st->bwidth = add( get_next_indice_fx( st, 1 ), WB ); /*Q0*/ move16(); } ELSE { /* WB, SWB and FB are supported */ - st->bwidth = get_next_indice_fx( st, NBITS_BWIDTH ); + st->bwidth = get_next_indice_fx( st, NBITS_BWIDTH ); /*Q0*/ move16(); } } @@ -182,33 +182,33 @@ ivas_error ivas_sce_dec_fx( test(); IF( EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - st->bits_frame_nominal = extract_l( L_sub( Mpy_32_16_1( hSCE->element_brate, INV_FRAME_PER_SEC_Q15 ), ISM_NB_BITS_METADATA_NOMINAL ) ); + st->bits_frame_nominal = extract_l( L_sub( Mpy_32_16_1( hSCE->element_brate, INV_FRAME_PER_SEC_Q15 ), ISM_NB_BITS_METADATA_NOMINAL ) ); /*Q0*/ move16(); } ELSE IF( ( EQ_16( (Word16) st_ivas->mc_mode, MC_MODE_MCMASA ) && GE_32( ivas_total_brate, MCMASA_SEPARATE_BRATE ) ) || ( EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) ) { - st->bits_frame_nominal = extract_l( Mpy_32_16_1( hSCE->element_brate, INV_FRAME_PER_SEC_Q15 ) ); + st->bits_frame_nominal = extract_l( Mpy_32_16_1( hSCE->element_brate, INV_FRAME_PER_SEC_Q15 ) ); /*Q0*/ move16(); } ELSE IF( EQ_16( (Word16) st_ivas->ism_mode, ISM_MODE_NONE ) && EQ_16( (Word16) st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - st->bits_frame_nominal = extract_l( Mpy_32_16_1( st_ivas->hSpar->core_nominal_brate, INV_FRAME_PER_SEC_Q15 ) ); + st->bits_frame_nominal = extract_l( Mpy_32_16_1( st_ivas->hSpar->core_nominal_brate, INV_FRAME_PER_SEC_Q15 ) ); /*Q0*/ move16(); } ELSE { - st->bits_frame_nominal = st_ivas->hQMetaData->bits_frame_nominal; + st->bits_frame_nominal = st_ivas->hQMetaData->bits_frame_nominal; /*Q0*/ move16(); } } ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) ) { - st->bits_frame_nominal = extract_l( Mpy_32_16_1( st_ivas->hSpar->core_nominal_brate, INV_FRAME_PER_SEC_Q15 ) ); + st->bits_frame_nominal = extract_l( Mpy_32_16_1( st_ivas->hSpar->core_nominal_brate, INV_FRAME_PER_SEC_Q15 ) ); /*Q0*/ move16(); } ELSE { - st->bits_frame_nominal = extract_l( L_sub( Mpy_32_16_1( hSCE->element_brate, INV_FRAME_PER_SEC_Q15 ), ISM_NB_BITS_METADATA_NOMINAL ) ); + st->bits_frame_nominal = extract_l( L_sub( Mpy_32_16_1( hSCE->element_brate, INV_FRAME_PER_SEC_Q15 ), ISM_NB_BITS_METADATA_NOMINAL ) ); /*Q0*/ move16(); } @@ -220,7 +220,7 @@ ivas_error ivas_sce_dec_fx( test(); IF( !st_ivas->bfi && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - st->total_brate = L_sub( ivas_total_brate, L_shr( L_mult( nb_bits_metadata, FRAMES_PER_SEC ), 1 ) ); + st->total_brate = L_sub( ivas_total_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); /*Q0*/ if ( EQ_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) && NE_16( st_ivas->hISMDTX.sce_id_dtx, sce_id ) ) { @@ -230,12 +230,12 @@ ivas_error ivas_sce_dec_fx( } ELSE IF( !st_ivas->bfi && EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) { - st->total_brate = ivas_total_brate; + st->total_brate = ivas_total_brate; /*Q0*/ move32(); } ELSE IF( !st_ivas->bfi && NE_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) && NE_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) ) /* note: in ISMs, total_brate[] is set in ivas_ism_config() */ { - st->total_brate = L_sub( hSCE->element_brate, L_shr( L_mult( nb_bits_metadata, FRAMES_PER_SEC ), 1 ) ); + st->total_brate = L_sub( hSCE->element_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); /*Q0*/ move32(); } @@ -257,7 +257,7 @@ ivas_error ivas_sce_dec_fx( } ELSE { - st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 ); + st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 ); /*Q0*/ move16(); } @@ -306,7 +306,7 @@ ivas_error ivas_sce_dec_fx( IF( st_ivas->sba_dirac_stereo_flag && ( GT_32( st->core_brate, SID_2k40 ) || EQ_16( st->cng_type, LP_CNG ) ) ) { /* skip addition of ACELP BWE for now, will be done after upmix */ - Copy32( outputHB[0], hSCE->save_hb_synth_fx, output_frame ); + Copy32( outputHB[0], hSCE->save_hb_synth_fx, output_frame ); /*Q11*/ hSCE->q_save_hb_synth_fx = Q11; move16(); } @@ -314,7 +314,7 @@ ivas_error ivas_sce_dec_fx( { Word32 output_Fs; - output_Fs = st_ivas->hDecoderConfig->output_Fs; + output_Fs = st_ivas->hDecoderConfig->output_Fs; /*Q0*/ move32(); /*----------------------------------------------------------------* @@ -333,17 +333,17 @@ ivas_error ivas_sce_dec_fx( * output LB and HB mix *----------------------------------------------------------------*/ - v_add_fx( output[0], outputHB[0], output[0], output_frame ); + v_add_fx( output[0], outputHB[0], output[0], output_frame ); /*Q11*/ } /*----------------------------------------------------------------* * Common updates *----------------------------------------------------------------*/ - hSCE->last_element_brate = hSCE->element_brate; + hSCE->last_element_brate = hSCE->element_brate; /*Q0*/ move32(); - st_ivas->BER_detect = s_or( st_ivas->BER_detect, st->BER_detect ); + st_ivas->BER_detect = s_or( st_ivas->BER_detect, st->BER_detect ); /*Q0*/ move16(); @@ -360,8 +360,8 @@ ivas_error ivas_sce_dec_fx( ivas_error create_sce_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 sce_id, /* i : SCE # identifier */ - const Word32 element_brate /* i : element bitrate */ + const Word16 sce_id, /* i : SCE # identifier Q0*/ + const Word32 element_brate /* i : element bitrate Q0*/ ) { SCE_DEC_HANDLE hSCE; @@ -371,7 +371,7 @@ ivas_error create_sce_dec( error = IVAS_ERR_OK; move16(); - output_frame = extract_l( Mpy_32_16_1( st_ivas->hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); + output_frame = extract_l( Mpy_32_16_1( st_ivas->hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); /*Q0*/ /*-----------------------------------------------------------------* * Allocate SCE handle @@ -386,9 +386,9 @@ ivas_error create_sce_dec( * Initialization - general parameters *-----------------------------------------------------------------*/ - hSCE->sce_id = sce_id; + hSCE->sce_id = sce_id; /*Q0*/ move16(); - hSCE->element_brate = element_brate; + hSCE->element_brate = element_brate; /*Q0*/ move32(); set32_fx( hSCE->prev_hb_synth_fx, 0, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) ); diff --git a/lib_dec/ivas_sns_dec_fx.c b/lib_dec/ivas_sns_dec_fx.c index d33eb08b7abf3fc441e6aee4c8484567e417ecc4..1863e11ae088df0c76dcd31b009fd382bb68f3de 100644 --- a/lib_dec/ivas_sns_dec_fx.c +++ b/lib_dec/ivas_sns_dec_fx.c @@ -53,7 +53,7 @@ static void sns_1st_dec_fx( const Word16 index, /* i : codebook index */ const Word16 core, const Word16 L_frame, - Word32 *snsq_fx /* i/o: i:prediction o:quantized sns */ + Word32 *snsq_fx /* i/o: i:prediction o:quantized sns Q16*/ ) { Word16 i; @@ -68,20 +68,20 @@ static void sns_1st_dec_fx( SWITCH( L_frame ) { case L_FRAME16k: - means = &sns_1st_means_16k[core - 1][0]; + means = &sns_1st_means_16k[core - 1][0]; /*Q0*/ BREAK; case L_FRAME25_6k: - means = &sns_1st_means_25k6[core - 1][0]; + means = &sns_1st_means_25k6[core - 1][0]; /*Q0*/ BREAK; case L_FRAME32k: - means = &sns_1st_means_32k[core - 1][0]; + means = &sns_1st_means_32k[core - 1][0]; /*Q0*/ BREAK; default: assert( !"illegal frame length in sns_1st_cod" ); } - p_dico = &sns_1st_cdbk[0][core - 1][0] + i_mult( index % 32, ( M / 2 ) ); + p_dico = &sns_1st_cdbk[0][core - 1][0] + i_mult( index % 32, ( M / 2 ) ); /*Q0*/ FOR( i = 0; i < M / 2; i++ ) { @@ -89,11 +89,11 @@ static void sns_1st_dec_fx( move32(); } - p_dico = &sns_1st_cdbk[1][sub( core, 1 )][0] + i_mult( shr( index, 5 ), ( M / 2 ) ); + p_dico = &sns_1st_cdbk[1][sub( core, 1 )][0] + i_mult( shr( index, 5 ), ( M / 2 ) ); /*Q0*/ FOR( i = M / 2; i < M; i++ ) { - snsq_fx[i] = L_add( L_mult( ( *p_dico++ ), cdbk_fix ), L_mult( means[i], means_fix ) ); + snsq_fx[i] = L_add( L_mult( ( *p_dico++ ), cdbk_fix ), L_mult( means[i], means_fix ) ); /*Q16*/ move32(); } @@ -106,14 +106,14 @@ static void sns_1st_dec_fx( *-------------------------------------------------------------------*/ static void sns_2st_dec_fx( - Word32 *snsq_fx, /* i/o: i:1st stage o:1st+2nd stage */ + Word32 *snsq_fx, /* i/o: i:1st stage o:1st+2nd stage q_snsq*/ Word16 *q_snsq, - Word16 *indx /* i : index[] (4 bits per words) */ + Word16 *indx /* i : index[] (4 bits per words) Q0*/ ) { Word16 i; Word16 xq_fx[M]; - Word16 scale_fx = 13107; + Word16 scale_fx = 13107; /*1.0/2.5f in Q15*/ move16(); /* quantize */ AVQ_dec_lpc( indx, xq_fx, 2 ); @@ -129,8 +129,8 @@ static void sns_2st_dec_fx( IF( GE_16( *q_snsq, 16 ) ) { snsq_dIFf = sub( *q_snsq, 16 ); - tmp1 = L_shr( snsq_fx[i], snsq_dIFf ); - snsq_fx[i] = L_add( tmp1, tmp ); + tmp1 = L_shr( snsq_fx[i], snsq_dIFf ); /*Q16*/ + snsq_fx[i] = L_add( tmp1, tmp ); /*Q16*/ move32(); *q_snsq = 16; move16(); @@ -138,8 +138,8 @@ static void sns_2st_dec_fx( ELSE { snsq_dIFf = sub( 16, *q_snsq ); - tmp1 = L_shr( tmp, snsq_dIFf ); - snsq_fx[i] = L_add( snsq_fx[i], tmp1 ); + tmp1 = L_shr( tmp, snsq_dIFf ); /*q_snsq*/ + snsq_fx[i] = L_add( snsq_fx[i], tmp1 ); /*q_snsq*/ move32(); } } @@ -152,18 +152,18 @@ static void sns_2st_dec_fx( *-------------------------------------------------------------------*/ void sns_avq_dec_fx( - Word16 *index, /* i : Quantization indices */ - Word32 SNS_Q[NB_DIV][M], /* o : Quantized SNS vectors */ + Word16 *index, /* i : Quantization indices Q0*/ + Word32 SNS_Q[NB_DIV][M], /* o : Quantized SNS vectors q_snsq*/ Word16 *q_snsq, - const Word16 L_frame, /* i : frame length */ - const Word16 numlpc /* i : Number of sets of lpc */ + const Word16 L_frame, /* i : frame length Q0*/ + const Word16 numlpc /* i : Number of sets of lpc Q0*/ ) { Word16 i, nbi, last; Word16 q_type; /* go from one-based indexing to zero-based indexing */ - last = sub( numlpc, 1 ); + last = sub( numlpc, 1 ); /*Q0*/ index++; @@ -173,13 +173,13 @@ void sns_avq_dec_fx( move16(); sns_2st_dec_fx( SNS_Q[last], q_snsq, index ); - nbi = add( add( 2, index[0] ), index[1] ); + nbi = add( add( 2, index[0] ), index[1] ); /*Q0*/ index += nbi; /* Decode intermediate LPC (512 framing) */ IF( EQ_16( numlpc, 2 ) ) { - q_type = *index++; + q_type = *index++; /*Q0*/ move16(); IF( q_type == 0 ) @@ -193,7 +193,7 @@ void sns_avq_dec_fx( { FOR( i = 0; i < M; i++ ) { - SNS_Q[0][i] = SNS_Q[1][i]; + SNS_Q[0][i] = SNS_Q[1][i]; /*q_snsq*/ move32(); } sns_2st_dec_fx( SNS_Q[0], q_snsq, index ); @@ -210,18 +210,18 @@ void sns_avq_dec_fx( *-------------------------------------------------------------------*/ void sns_avq_dec_stereo_fx( - Word16 *indexl, /* i : Quantization indices (left channel) */ - Word16 *indexr, /* i : Quantization indices (right channe) */ - const Word16 L_frame, /* i : frame length */ - Word32 *SNS_Ql, /* o : Quantized SNS vectors (left channel) */ + Word16 *indexl, /* i : Quantization indices (left channel) Q0*/ + Word16 *indexr, /* i : Quantization indices (right channe) Q0*/ + const Word16 L_frame, /* i : frame length Q0*/ + Word32 *SNS_Ql, /* o : Quantized SNS vectors (left channel) q_l*/ Word16 *q_l, - Word32 *SNS_Qr, /* o : Quantized SNS vectors (right channe) */ + Word32 *SNS_Qr, /* o : Quantized SNS vectors (right channe) q_r*/ Word16 *q_r ) { Word16 i, stereo_mode; Word32 mid_q_fx[M], side_q_fx[M]; - stereo_mode = *indexl++; + stereo_mode = *indexl++; /*Q0*/ move16(); indexr++; @@ -236,7 +236,7 @@ void sns_avq_dec_stereo_fx( IF( EQ_16( stereo_mode, 2 ) ) { /* MS coding */ - tmp1 = *indexl++; + tmp1 = *indexl++; /*Q0*/ move16(); sns_1st_dec_fx( tmp1, TCX_20_CORE, L_frame, mid_q_fx ); q_mid = 16; @@ -291,9 +291,9 @@ void sns_avq_dec_stereo_fx( ELSE { /* LR decoding */ - tmp1 = *indexl++; + tmp1 = *indexl++; /*Q0*/ move16(); - tmp2 = *indexr++; + tmp2 = *indexr++; /*Q0*/ move16(); sns_1st_dec_fx( tmp1, TCX_20_CORE, L_frame, SNS_Ql ); *q_l = 16; @@ -316,8 +316,8 @@ void sns_avq_dec_stereo_fx( *-------------------------------------------------------------------*/ void dequantize_sns_fx( - Word16 indices[CPE_CHANNELS][NPRM_LPC_NEW], - Word32 snsQ_out_fx[CPE_CHANNELS][NB_DIV][M], + Word16 indices[CPE_CHANNELS][NPRM_LPC_NEW], /*Q0*/ + Word32 snsQ_out_fx[CPE_CHANNELS][NB_DIV][M], /*Q16*/ Decoder_State **sts ) { Word16 nSubframes, k, ch; @@ -325,13 +325,13 @@ void dequantize_sns_fx( Word16 zero_side_flag[NB_DIV]; Decoder_State *st; - sns_stereo_mode[0] = indices[0][0]; + sns_stereo_mode[0] = indices[0][0]; /*Q0*/ move16(); - sns_stereo_mode[1] = indices[0][1]; + sns_stereo_mode[1] = indices[0][1]; /*Q0*/ move16(); - zero_side_flag[0] = indices[0][2]; + zero_side_flag[0] = indices[0][2]; /*Q0*/ move16(); - zero_side_flag[1] = indices[0][3]; + zero_side_flag[1] = indices[0][3]; /*Q0*/ move16(); FOR( ch = 0; ch < CPE_CHANNELS; ++ch ) @@ -365,7 +365,7 @@ void dequantize_sns_fx( move16(); } - Word32 *snsQ_fx = snsQ_out_fx[ch][k]; + Word32 *snsQ_fx = snsQ_out_fx[ch][k]; /*Q16*/ IF( is_side ) { @@ -379,13 +379,13 @@ void dequantize_sns_fx( nStages = SNS_MSVQ_NSTAGES_SIDE; move16(); - msvq_dec_fx( side_cdbks_fx, NULL, NULL, nStages, M, M, &indices[ch][add( idxIndices, SNS_STEREO_MODE_OFFSET_INDICES )], 0, NULL, snsQ_fx, NULL, 15 ); // always 15 + msvq_dec_fx( side_cdbks_fx, NULL, NULL, nStages, M, M, &indices[ch][( idxIndices + SNS_STEREO_MODE_OFFSET_INDICES )], 0, NULL, snsQ_fx, NULL, 15 ); // always 15 } ELSE { - msvq_dec_fx( cdbks_fx, NULL, NULL, nStages, M, M, &indices[ch][add( idxIndices, SNS_STEREO_MODE_OFFSET_INDICES )], 0, NULL, snsQ_fx, NULL, 12 ); + msvq_dec_fx( cdbks_fx, NULL, NULL, nStages, M, M, &indices[ch][( idxIndices + SNS_STEREO_MODE_OFFSET_INDICES )], 0, NULL, snsQ_fx, NULL, 12 ); } - idxIndices = add( idxIndices, nStages ); + idxIndices = add( idxIndices, nStages ); /*Q0*/ } } @@ -402,7 +402,7 @@ void dequantize_sns_fx( { IF( EQ_16( sns_stereo_mode[k], SNS_STEREO_MODE_MS ) ) { - inverseMS_fx( M, snsQ_out_fx[0][k], snsQ_out_fx[1][k], ONE_IN_Q31 ); + inverseMS_fx( M, snsQ_out_fx[0][k], snsQ_out_fx[1][k], ONE_IN_Q31 ); /*Q16*/ } } } diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index b8b1e0545e6196a0ba47a18f8c0a585878495be8..6089012bc1831d43d66fcb5887793fd2806e1f09 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -278,7 +278,7 @@ ivas_error ivas_spar_dec_open( #else ivas_error ivas_spar_dec_open_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag Q0*/ ) { SPAR_DEC_HANDLE hSpar; @@ -292,10 +292,10 @@ ivas_error ivas_spar_dec_open_fx( error = IVAS_ERR_OK; move32(); - sba_order_internal = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + sba_order_internal = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); /*Q0*/ move16(); - num_channels_internal = ivas_sba_get_nchan_metadata_fx( sba_order_internal, st_ivas->hDecoderConfig->ivas_total_brate ); + num_channels_internal = ivas_sba_get_nchan_metadata_fx( sba_order_internal, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/ hSpar = st_ivas->hSpar; @@ -308,16 +308,16 @@ ivas_error ivas_spar_dec_open_fx( } } - output_Fs = st_ivas->hDecoderConfig->output_Fs; + output_Fs = st_ivas->hDecoderConfig->output_Fs; /*Q0*/ move32(); IF( GT_16( num_channels_internal, ( SBA_HOA2_ORDER + 1 ) * ( SBA_HOA2_ORDER + 1 ) ) ) { - num_decor_chs = IVAS_HBR_MAX_DECOR_CHS; + num_decor_chs = IVAS_HBR_MAX_DECOR_CHS; /*Q0*/ move16(); } ELSE { - num_decor_chs = sub( num_channels_internal, 1 ); + num_decor_chs = sub( num_channels_internal, 1 ); /*Q0*/ } /* TD decorr. */ @@ -346,7 +346,7 @@ ivas_error ivas_spar_dec_open_fx( move16(); if ( hSpar->hTdDecorr ) { - hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[hSpar->hMdDec->table_idx].td_ducking; + hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[hSpar->hMdDec->table_idx].td_ducking; /*Q0*/ move16(); } @@ -357,9 +357,9 @@ ivas_error ivas_spar_dec_open_fx( { return error; } - fb_cfg->pcm_offset = NS2SA_FX2( output_Fs, DELAY_FB_1_NS + IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ); + fb_cfg->pcm_offset = NS2SA_FX2( output_Fs, DELAY_FB_1_NS + IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ); /*Q0*/ move16(); - fb_cfg->remix_order = remix_order_set[hSpar->hMdDec->spar_md_cfg.remix_unmix_order]; + fb_cfg->remix_order = remix_order_set[hSpar->hMdDec->spar_md_cfg.remix_unmix_order]; /*Q0*/ move16(); /* FB mixer handle */ @@ -440,21 +440,21 @@ ivas_error ivas_spar_dec_open_fx( ivas_output_init( &( st_ivas->hTransSetup ), st_ivas->transport_config ); set16_fx( hSpar->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); - set16_fx( hSpar->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); - hSpar->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; + set16_fx( hSpar->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); /*Q0*/ + hSpar->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; /*Q0*/ move16(); hSpar->subframes_rendered = 0; move16(); hSpar->slots_rendered = 0; move16(); - hSpar->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; + hSpar->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; /*Q0*/ move16(); /* init render timeslot mapping */ set16_fx( hSpar->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); FOR( map_idx = 0; map_idx < DEFAULT_JBM_CLDFB_TIMESLOTS; map_idx++ ) { - hSpar->render_to_md_map[map_idx] = map_idx; + hSpar->render_to_md_map[map_idx] = map_idx; /*Q0*/ move16(); } @@ -468,17 +468,17 @@ ivas_error ivas_spar_dec_open_fx( buffer_mode = TC_BUFFER_MODE_RENDERER; move32(); - nchan_tc = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); - nchan_to_allocate = num_channels_internal; + nchan_tc = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); /*Q0*/ + nchan_to_allocate = num_channels_internal; /*Q0*/ move16(); test(); if ( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - nchan_to_allocate = add( nchan_to_allocate, st_ivas->nchan_ism ); + nchan_to_allocate = add( nchan_to_allocate, st_ivas->nchan_ism ); /*Q0*/ } - granularity = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + granularity = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /*Q0*/ move16(); test(); @@ -490,17 +490,17 @@ ivas_error ivas_spar_dec_open_fx( test(); IF( ( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { - nchan_tc = add( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); - nchan_to_allocate = nchan_tc; + nchan_tc = add( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); /*Q0*/ + nchan_to_allocate = nchan_tc; /*Q0*/ move16(); } ELSE { buffer_mode = TC_BUFFER_MODE_BUFFER; move32(); - nchan_tc = st_ivas->hDecoderConfig->nchan_out; + nchan_tc = st_ivas->hDecoderConfig->nchan_out; /*Q0*/ move16(); - nchan_to_allocate = nchan_tc; + nchan_to_allocate = nchan_tc; /*Q0*/ move16(); } } @@ -518,7 +518,7 @@ ivas_error ivas_spar_dec_open_fx( /* get correct granularity in case of binaural rendering of the discrete objects with the td obj renderer */ Word32 quo, rem; iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &quo, &rem, 0 ); - granularity = extract_l( quo ); + granularity = extract_l( quo ); /*Q0*/ } IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ), IVAS_ERR_OK ) ) @@ -582,8 +582,8 @@ void ivas_spar_dec_close( #else void ivas_spar_dec_close_fx( SPAR_DEC_HANDLE *hSpar, /* i/o: SPAR decoder handle */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ + const Word32 output_Fs, /* i : output sampling rate Q0*/ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag Q0*/ ) { test(); @@ -631,7 +631,7 @@ void ivas_spar_dec_close_fx( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_spar_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ - Word16 *nb_bits_read /* o : number of MD bits read */ + Word16 *nb_bits_read /* o : number of MD bits read Q0*/ ) { DECODER_CONFIG_HANDLE hDecoderConfig; @@ -657,14 +657,14 @@ ivas_error ivas_spar_dec_fx( st0 = st_ivas->hCPE[0]->hCoreCoder[0]; } - bit_stream_orig = st0->bit_stream; - next_bit_pos_orig = st0->next_bit_pos; + bit_stream_orig = st0->bit_stream; /*Q0*/ + next_bit_pos_orig = st0->next_bit_pos; /*Q0*/ move16(); IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { iDiv_and_mod_32( hDecoderConfig->ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); - last_bit_pos = sub( extract_l( L_sub( quo, 1 ) ), nb_bits_read[1] ); + last_bit_pos = sub( extract_l( L_sub( quo, 1 ) ), nb_bits_read[1] ); /*Q0*/ } ELSE { @@ -683,38 +683,38 @@ ivas_error ivas_spar_dec_fx( IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { iDiv_and_mod_32( hDecoderConfig->ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); - last_bit_pos = sub( extract_l( L_sub( quo, 1 ) ), nb_bits_read[1] ); + last_bit_pos = sub( extract_l( L_sub( quo, 1 ) ), nb_bits_read[1] ); /*Q0*/ } ELSE { iDiv_and_mod_32( hDecoderConfig->ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); - last_bit_pos = extract_l( L_sub( quo, 1 ) ); + last_bit_pos = extract_l( L_sub( quo, 1 ) ); /*Q0*/ } test(); if ( !st0->bfi && EQ_32( hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) ) { - last_bit_pos = sub( last_bit_pos, SID_FORMAT_NBITS ); + last_bit_pos = sub( last_bit_pos, SID_FORMAT_NBITS ); /*Q0*/ } - nb_bits_read_orig = *nb_bits_read; + nb_bits_read_orig = *nb_bits_read; /*Q0*/ move16(); - last_bit_pos = sub( last_bit_pos, nb_bits_read_orig ); + last_bit_pos = sub( last_bit_pos, nb_bits_read_orig ); /*Q0*/ /* reverse the bitstream for easier reading of indices */ FOR( i = 0; i < s_min( MAX_BITS_METADATA, last_bit_pos ); i++ ) { - bstr_meta[i] = st_ivas->bit_stream[sub( last_bit_pos, i )]; + bstr_meta[i] = st_ivas->bit_stream[( last_bit_pos - i )]; /*Q0*/ move16(); } - st0->bit_stream = bstr_meta; + st0->bit_stream = bstr_meta; /*Q0*/ st0->next_bit_pos = 0; move16(); - st0->bits_frame = s_min( MAX_BITS_METADATA, add( last_bit_pos, 1 ) ); + st0->bits_frame = s_min( MAX_BITS_METADATA, add( last_bit_pos, 1 ) ); /*Q0*/ move16(); if ( !st0->bfi ) { - st0->total_brate = hDecoderConfig->ivas_total_brate; /* to avoid BER detect */ + st0->total_brate = hDecoderConfig->ivas_total_brate; /* to avoid BER detect */ /*Q0*/ move32(); } @@ -727,21 +727,21 @@ ivas_error ivas_spar_dec_fx( return error; } - *nb_bits_read = add( st0->next_bit_pos, nb_bits_read_orig ); + *nb_bits_read = add( st0->next_bit_pos, nb_bits_read_orig ); /*Q0*/ move16(); - st0->bit_stream = bit_stream_orig; - st0->next_bit_pos = next_bit_pos_orig; + st0->bit_stream = bit_stream_orig; /*Q0*/ + st0->next_bit_pos = next_bit_pos_orig; /*Q0*/ move16(); test(); IF( !st0->bfi && EQ_32( hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) ) { Word16 zero_pad_bits; - *nb_bits_read = add( *nb_bits_read, SID_FORMAT_NBITS ); + *nb_bits_read = add( *nb_bits_read, SID_FORMAT_NBITS ); /*Q0*/ move16(); - zero_pad_bits = sub( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC, *nb_bits_read ); + zero_pad_bits = sub( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC, *nb_bits_read ); /*Q0*/ assert( zero_pad_bits <= 1 ); - *nb_bits_read = add( *nb_bits_read, zero_pad_bits ); + *nb_bits_read = add( *nb_bits_read, zero_pad_bits ); /*Q0*/ move16(); } @@ -853,10 +853,10 @@ ivas_error ivas_spar_dec( #ifdef IVAS_FLOAT_FIXED static Word16 ivas_get_spar_table_idx_from_coded_idx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + const Word16 sba_order, /* i : Ambisonic (SBA) order Q0*/ Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - Word16 *bitlen /* o : number of bits */ + Word16 *bitlen /* o : number of bits Q0*/ ) { Word16 table_idx, ind1[IVAS_SPAR_BR_TABLE_LEN]; @@ -878,12 +878,12 @@ static Word16 ivas_get_spar_table_idx_from_coded_idx( } assert( j > 0 ); - *bitlen = ivas_get_bits_to_encode( sub( j, 1 ) ); + *bitlen = ivas_get_bits_to_encode( sub( j, 1 ) ); /*Q0*/ move16(); - ind2 = get_next_indice_fx( st0, *bitlen ); + ind2 = get_next_indice_fx( st0, *bitlen ); /*Q0*/ - table_idx = ind1[ind2]; + table_idx = ind1[ind2]; /*Q0*/ move16(); return table_idx; @@ -929,17 +929,17 @@ static int16_t ivas_get_spar_table_idx_from_coded_idx( #ifdef IVAS_FLOAT_FIXED static Word16 ivas_parse_spar_header( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + const Word16 sba_order, /* i : Ambisonic (SBA) order Q0*/ Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - Word16 *table_idx ) + Word16 *table_idx /*Q0*/ ) { Word16 bitlen, bwidth; - *table_idx = ivas_get_spar_table_idx_from_coded_idx( ivas_total_brate, sba_order, st0, &bitlen ); + *table_idx = ivas_get_spar_table_idx_from_coded_idx( ivas_total_brate, sba_order, st0, &bitlen ); /*Q0*/ move16(); - bwidth = ivas_spar_br_table_consts[( *table_idx )].bwidth; + bwidth = ivas_spar_br_table_consts[( *table_idx )].bwidth; /*Q0*/ move16(); return bwidth; @@ -966,7 +966,7 @@ static int16_t ivas_parse_spar_header( static Word16 get_random_number_fx( Word16 *seed ) { - return Random( seed ); + return Random( seed ); /*Q15*/ } #else static float get_random_number( @@ -981,12 +981,13 @@ static float get_random_number( #ifdef IVAS_FLOAT_FIXED static Word32 matrix_det_fx( - const Word32 a00, - const Word32 a01, - const Word32 a10, - const Word32 a11 ) + const Word32 a00, /*Q27*/ + const Word32 a01, /*Q27*/ + const Word32 a10, /*Q27*/ + const Word32 a11 /*Q27*/ +) { - return L_sub( Mpy_32_32( a00, a11 ), Mpy_32_32( a01, a10 ) ); + return L_sub( Mpy_32_32( a00, a11 ), Mpy_32_32( a01, a10 ) ); /*Q23*/ } #else static float matrix_det( @@ -1002,8 +1003,8 @@ static float matrix_det( #ifdef IVAS_FLOAT_FIXED static void matrix_inverse_fx( - Word32 in[3][3], - Word32 out[3][3], + Word32 in[3][3], /*Q27*/ + Word32 out[3][3], /*out_q*/ const Word16 size, Word16 *out_q ) { @@ -1016,9 +1017,9 @@ static void matrix_inverse_fx( IF( EQ_16( size, 1 ) ) { - tmp_32 = BASOP_Util_Divide3232_Scale( ONE_IN_Q27, L_max( in[0][0], eps_fx ), &tmp_e ); + tmp_32 = BASOP_Util_Divide3232_Scale( ONE_IN_Q27, L_max( in[0][0], eps_fx ), &tmp_e ); /*Q: 15 - tmp_e*/ shift = norm_l( tmp_32 ); - out[0][0] = L_shl( tmp_32, shift ); + out[0][0] = L_shl( tmp_32, shift ); /*out_q*/ move32(); *out_q = add( shift, sub( Q15, tmp_e ) ); move16(); @@ -1027,20 +1028,20 @@ static void matrix_inverse_fx( } ELSE IF( EQ_16( size, 2 ) ) { - det = matrix_det_fx( in[0][1], in[0][1], in[1][0], in[1][1] ); - tmp_32 = BASOP_Util_Divide3232_Scale( ONE_IN_Q23, L_max( det, eps_fx ), &tmp_e ); + det = matrix_det_fx( in[0][1], in[0][1], in[1][0], in[1][1] ); /*Q23*/ + tmp_32 = BASOP_Util_Divide3232_Scale( ONE_IN_Q23, L_max( det, eps_fx ), &tmp_e ); /*Q: 15 - tmp_e*/ shift = norm_l( tmp_32 ); - fac = L_shl( tmp_32, shift ); + fac = L_shl( tmp_32, shift ); /*q_fac*/ q_fac = add( shift, sub( Q15, tmp_e ) ); - out[0][0] = Mpy_32_32( in[1][1], fac ); + out[0][0] = Mpy_32_32( in[1][1], fac ); /*q_fac - 4*/ move32(); - out[1][0] = Mpy_32_32( in[1][0], L_negate( fac ) ); + out[1][0] = Mpy_32_32( in[1][0], L_negate( fac ) ); /*q_fac - 4*/ move32(); - out[0][1] = Mpy_32_32( in[0][1], L_negate( fac ) ); + out[0][1] = Mpy_32_32( in[0][1], L_negate( fac ) ); /*q_fac - 4*/ move32(); - out[1][1] = Mpy_32_32( in[0][0], fac ); + out[1][1] = Mpy_32_32( in[0][0], fac ); /*q_fac - 4*/ move32(); *out_q = add( Q27, sub( q_fac, 31 ) ); @@ -1049,31 +1050,31 @@ static void matrix_inverse_fx( return; } - det = L_add( L_sub( Mpy_32_32( in[0][0], matrix_det_fx( in[1][1], in[1][2], in[2][1], in[2][2] ) ), Mpy_32_32( in[1][0], matrix_det_fx( in[0][1], in[0][2], in[2][1], in[2][2] ) ) ), Mpy_32_32( in[2][0], matrix_det_fx( in[0][1], in[0][2], in[1][1], in[1][2] ) ) ); - tmp_32 = BASOP_Util_Divide3232_Scale( ONE_IN_Q19, L_max( det, eps_fx ), &tmp_e ); + det = L_add( L_sub( Mpy_32_32( in[0][0], matrix_det_fx( in[1][1], in[1][2], in[2][1], in[2][2] ) ), Mpy_32_32( in[1][0], matrix_det_fx( in[0][1], in[0][2], in[2][1], in[2][2] ) ) ), Mpy_32_32( in[2][0], matrix_det_fx( in[0][1], in[0][2], in[1][1], in[1][2] ) ) ); /*Q19*/ + tmp_32 = BASOP_Util_Divide3232_Scale( ONE_IN_Q19, L_max( det, eps_fx ), &tmp_e ); /*Q: 31 - tmp_e*/ shift = norm_l( tmp_32 ); - fac = L_shl( tmp_32, shift ); + fac = L_shl( tmp_32, shift ); /*q_fac*/ q_fac = add( shift, sub( Q15, tmp_e ) ); - out[0][0] = Mpy_32_32( matrix_det_fx( in[1][1], in[1][2], in[2][1], in[2][2] ), fac ); + out[0][0] = Mpy_32_32( matrix_det_fx( in[1][1], in[1][2], in[2][1], in[2][2] ), fac ); /*q_fac-8*/ move32(); - out[1][0] = Mpy_32_32( matrix_det_fx( in[1][0], in[1][2], in[2][0], in[2][2] ), L_negate( fac ) ); + out[1][0] = Mpy_32_32( matrix_det_fx( in[1][0], in[1][2], in[2][0], in[2][2] ), L_negate( fac ) ); /*q_fac-8*/ move32(); - out[2][0] = Mpy_32_32( matrix_det_fx( in[1][0], in[1][1], in[2][0], in[2][1] ), fac ); + out[2][0] = Mpy_32_32( matrix_det_fx( in[1][0], in[1][1], in[2][0], in[2][1] ), fac ); /*q_fac-8*/ move32(); - out[0][1] = Mpy_32_32( matrix_det_fx( in[0][1], in[0][2], in[2][1], in[2][2] ), L_negate( fac ) ); + out[0][1] = Mpy_32_32( matrix_det_fx( in[0][1], in[0][2], in[2][1], in[2][2] ), L_negate( fac ) ); /*q_fac-8*/ move32(); - out[1][1] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][2], in[2][0], in[2][2] ), fac ); + out[1][1] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][2], in[2][0], in[2][2] ), fac ); /*q_fac-8*/ move32(); - out[2][1] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][1], in[2][0], in[2][1] ), L_negate( fac ) ); + out[2][1] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][1], in[2][0], in[2][1] ), L_negate( fac ) ); /*q_fac-8*/ move32(); - out[0][2] = Mpy_32_32( matrix_det_fx( in[0][1], in[0][2], in[1][1], in[1][2] ), fac ); + out[0][2] = Mpy_32_32( matrix_det_fx( in[0][1], in[0][2], in[1][1], in[1][2] ), fac ); /*q_fac-8*/ move32(); - out[1][2] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][2], in[1][0], in[1][2] ), L_negate( fac ) ); + out[1][2] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][2], in[1][0], in[1][2] ), L_negate( fac ) ); /*q_fac-8*/ move32(); - out[2][2] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][1], in[1][0], in[1][1] ), fac ); + out[2][2] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][1], in[1][0], in[1][1] ), fac ); /*q_fac-8*/ move32(); *out_q = add( Q23, sub( q_fac, 31 ) ); @@ -1164,45 +1165,45 @@ void ivas_spar_get_cldfb_gains_fx( Word16 Q_cf_len_s; Word16 Q_weights; - pt_len = cldfbAnaDec0->p_filter_length; + pt_len = cldfbAnaDec0->p_filter_length; /*Q0*/ move16(); - num_cldfb_bands = cldfbAnaDec0->no_channels; + num_cldfb_bands = cldfbAnaDec0->no_channels; /*Q0*/ move16(); - stride = NS2SA_FX2( output_Fs_fx, DELAY_CLDFB_NS ); - encfb_delay = NS2SA_FX2( output_Fs_fx, IVAS_FB_ENC_DELAY_NS ); - decfb_delay = NS2SA_FX2( output_Fs_fx, IVAS_FB_DEC_DELAY_NS ); + stride = NS2SA_FX2( output_Fs_fx, DELAY_CLDFB_NS ); /*Q0*/ + encfb_delay = NS2SA_FX2( output_Fs_fx, IVAS_FB_ENC_DELAY_NS ); /*Q0*/ + decfb_delay = NS2SA_FX2( output_Fs_fx, IVAS_FB_DEC_DELAY_NS ); /*Q0*/ - cf_start = add( sub( hSpar->hFbMixer->cross_fade_start_offset, encfb_delay ), decfb_delay ); /* time domain after CLDFB synthesis*/ - cf_end = add( sub( hSpar->hFbMixer->cross_fade_end_offset, encfb_delay ), decfb_delay ); + cf_start = add( sub( hSpar->hFbMixer->cross_fade_start_offset, encfb_delay ), decfb_delay ); /* time domain after CLDFB synthesis*/ /*Q0*/ + cf_end = add( sub( hSpar->hFbMixer->cross_fade_end_offset, encfb_delay ), decfb_delay ); /*Q0*/ cf_len = sub( cf_end, cf_start ); - weights_fx = hSpar->hFbMixer->cldfb_cross_fade_fx; - cf_cldfb_start = shr( extract_l( ceil_fixed( sub( divide1616( sub( cf_start, shr( decfb_delay, 1 ) ), shl( stride, 9 ) ), 32 ), 6 ) ), 6 ); - cf_cldfb_end = shr( divide1616( add( sub( cf_start, shr( decfb_delay, 1 ) ), cf_len ), shl( stride, 9 ) ), 6 ); /*q-factor of stride is 9(as max value is 60)*/ - num_cf_slots = add( sub( cf_cldfb_end, cf_cldfb_start ), 1 ); - num_samples = add( imult1616( num_cf_slots, stride ), sub( pt_len, stride ) ); + weights_fx = hSpar->hFbMixer->cldfb_cross_fade_fx; /*hSpar->hFbMixer->cldfb_cross_fade_q*/ + cf_cldfb_start = shr( extract_l( ceil_fixed( sub( divide1616( sub( cf_start, shr( decfb_delay, 1 ) ), shl( stride, 9 ) ), 32 ), 6 ) ), 6 ); /*Q0*/ + cf_cldfb_end = shr( divide1616( add( sub( cf_start, shr( decfb_delay, 1 ) ), cf_len ), shl( stride, 9 ) ), 6 ); /*q-factor of stride is 9(as max value is 60)*/ /*Q0*/ + num_cf_slots = add( sub( cf_cldfb_end, cf_cldfb_start ), 1 ); /*Q0*/ + num_samples = add( imult1616( num_cf_slots, stride ), sub( pt_len, stride ) ); /*Q0*/ seed = RANDOM_INITSEED; move16(); split_band = SPAR_DIRAC_SPLIT_START_BAND; move16(); - pp_ts_im_fx[0] = ts_im_fx; - pp_ts_re_fx[0] = ts_re_fx; + pp_ts_im_fx[0] = ts_im_fx; /*Q22*/ + pp_ts_re_fx[0] = ts_re_fx; /*Q22*/ set32_fx( tgt_fx, 0, ( 3 - 1 ) * CLDFB_NO_CHANNELS_MAX + 10 * CLDFB_NO_CHANNELS_MAX ); - cf_start_s_fx = divide3232( ( sub( cf_start, shr( decfb_delay, 1 ) ) ), output_Fs_fx ); - cf_len_s_fx = divide3232( sub( hSpar->hFbMixer->cross_fade_end_offset, hSpar->hFbMixer->cross_fade_start_offset ), output_Fs_fx ); + cf_start_s_fx = divide3232( ( sub( cf_start, shr( decfb_delay, 1 ) ) ), output_Fs_fx ); /*Q_cf_start_s*/ + cf_len_s_fx = divide3232( sub( hSpar->hFbMixer->cross_fade_end_offset, hSpar->hFbMixer->cross_fade_start_offset ), output_Fs_fx ); /*Q_cf_len_s*/ Q_cf_start_s = sub( norm_s( cf_start_s_fx ), 1 ); Q_cf_len_s = norm_s( cf_len_s_fx ); Q_weights = add( 15, sub( Q_cf_start_s, Q_cf_len_s ) ); FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) { - weights_fx[ts] = divide1616( shl( sub( divide3232( L_mult0( add( shl( ts, 1 ), 1 ), shr( stride, 1 ) ), output_Fs_fx ), cf_start_s_fx ), Q_cf_start_s ), shl( cf_len_s_fx, Q_cf_len_s ) ); + weights_fx[ts] = divide1616( shl( sub( divide3232( L_mult0( add( shl( ts, 1 ), 1 ), shr( stride, 1 ) ), output_Fs_fx ), cf_start_s_fx ), Q_cf_start_s ), shl( cf_len_s_fx, Q_cf_len_s ) ); /*Q_weights*/ move16(); - weights_fx[ts] = s_max( s_min( weights_fx[ts], shl( 1, Q_weights ) ), 0 ); + weights_fx[ts] = s_max( s_min( weights_fx[ts], shl( 1, Q_weights ) ), 0 ); /*Q_weights*/ move16(); } - hSpar->hFbMixer->cldfb_cross_fade_start = cf_cldfb_start; + hSpar->hFbMixer->cldfb_cross_fade_start = cf_cldfb_start; /*Q0*/ move16(); - hSpar->hFbMixer->cldfb_cross_fade_end = cf_cldfb_end; + hSpar->hFbMixer->cldfb_cross_fade_end = cf_cldfb_end; /*Q0*/ move16(); test(); @@ -1215,10 +1216,10 @@ void ivas_spar_get_cldfb_gains_fx( /* optimization*/ /* compute time-domain cross-fade for considered time slots*/ - tmp_idx = sub( cf_start, imult1616( cf_cldfb_start, stride ) ); + tmp_idx = sub( cf_start, imult1616( cf_cldfb_start, stride ) ); /*Q0*/ FOR( sample = 0; sample < cf_len; sample++ ) { - tgt_fx[tmp_idx] = L_deposit_h( hSpar->hFbMixer->pFilterbank_cross_fade_fx[sample] ); + tgt_fx[tmp_idx] = L_deposit_h( hSpar->hFbMixer->pFilterbank_cross_fade_fx[sample] ); /*Q31*/ move32(); tmp_idx = add( tmp_idx, 1 ); /* increasing window function */ @@ -1226,7 +1227,7 @@ void ivas_spar_get_cldfb_gains_fx( FOR( ; tmp_idx < num_samples; tmp_idx++ ) { /* fill up with ones*/ - tgt_fx[tmp_idx] = MAX_32; + tgt_fx[tmp_idx] = MAX_32; /*Q31*/ move32(); } FOR( sample = 0; sample < num_samples; sample++ ) @@ -1241,8 +1242,8 @@ void ivas_spar_get_cldfb_gains_fx( FOR( sample = 0; sample < sub( pt_len, stride ); sample++ ) { /* fill internal CLDFB analysis time buffer with data*/ - Word16 x_fx = get_random_number_fx( &seed ); - cldfbAnaDec0->cldfb_state_fx[sample] = L_shl( x_fx, 12 ); + Word16 x_fx = get_random_number_fx( &seed ); /*Q15*/ + cldfbAnaDec0->cldfb_state_fx[sample] = L_shl( x_fx, 12 ); /*Q27*/ move32(); } Word16 q_cldfb = 27; @@ -1253,8 +1254,8 @@ void ivas_spar_get_cldfb_gains_fx( { FOR( sample = 0; sample < stride; sample++ ) { - Word16 x_fx = get_random_number_fx( &seed ); - ts_inout_fx[sample] = L_shl( x_fx, 12 ); /*Q-27*/ + Word16 x_fx = get_random_number_fx( &seed ); /*Q15*/ + ts_inout_fx[sample] = L_shl( x_fx, 12 ); /*Q27*/ move32(); } @@ -1264,15 +1265,15 @@ void ivas_spar_get_cldfb_gains_fx( FOR( sample = 0; sample < stride; sample++ ) { - T_fx[add( imult1616( slot, stride ), sample )][slot] = ts_inout_fx[sample]; + T_fx[( ( slot * stride ) + sample )][slot] = ts_inout_fx[sample]; /*Q21*/ move32(); } - tmp_idx = sub( pt_len, 1 ); + tmp_idx = sub( pt_len, 1 ); /*Q0*/ FOR( sample = stride; sample < pt_len; sample++ ) { - T_fx[add( imult1616( slot, stride ), sample )][slot] = cldfbSynDec0->cldfb_state_fx[tmp_idx]; + T_fx[( ( slot * stride ) + sample )][slot] = cldfbSynDec0->cldfb_state_fx[tmp_idx]; /*Q21*/ move32(); - tmp_idx = sub( tmp_idx, 1 ); + tmp_idx = sub( tmp_idx, 1 ); /*Q0*/ } } @@ -1297,11 +1298,11 @@ void ivas_spar_get_cldfb_gains_fx( } } - Tt_T_fx[1][0] = Tt_T_fx[0][1]; + Tt_T_fx[1][0] = Tt_T_fx[0][1]; /*Q27*/ move32(); - Tt_T_fx[2][0] = Tt_T_fx[0][2]; + Tt_T_fx[2][0] = Tt_T_fx[0][2]; /*Q27*/ move32(); - Tt_T_fx[2][1] = Tt_T_fx[1][2]; + Tt_T_fx[2][1] = Tt_T_fx[1][2]; /*Q27*/ move32(); FOR( slot_row = 0; slot_row < num_cf_slots; slot_row++ ) { @@ -1309,7 +1310,7 @@ void ivas_spar_get_cldfb_gains_fx( move32(); FOR( sample = 0; sample < num_samples; sample++ ) { - Tt_tgt_fx[slot_row] = L_add( Tt_tgt_fx[slot_row], Mpy_32_32( T_fx[sample][slot_row], tgt_fx[sample] ) ); + Tt_tgt_fx[slot_row] = L_add( Tt_tgt_fx[slot_row], Mpy_32_32( T_fx[sample][slot_row], tgt_fx[sample] ) ); /*Q21*/ move32(); } } @@ -1323,9 +1324,9 @@ void ivas_spar_get_cldfb_gains_fx( move32(); FOR( slot_col = 0; slot_col < num_cf_slots; slot_col++ ) { - tmp = L_add( tmp, Mpy_32_32( Tt_T_inv_fx[slot_row][slot_col], Tt_tgt_fx[slot_col] ) ); + tmp = L_add( tmp, Mpy_32_32( Tt_T_inv_fx[slot_row][slot_col], Tt_tgt_fx[slot_col] ) ); /*output_q-10*/ } - weights_fx[add( cf_cldfb_start, slot_row )] = extract_l( L_shr( L_max( L_min( tmp, L_shl( 1, sub( output_q, 10 ) ) ), 0 ), sub( sub( output_q, 10 ), Q_weights ) ) ); /*Q_weights*/ + weights_fx[( cf_cldfb_start + slot_row )] = extract_l( L_shr( L_max( L_min( tmp, L_shl( 1, sub( output_q, 10 ) ) ), 0 ), sub( sub( output_q, 10 ), Q_weights ) ) ); /*Q_weights*/ move16(); } hSpar->hFbMixer->cldfb_cross_fade_q = Q_weights; @@ -1337,8 +1338,8 @@ void ivas_spar_get_cldfb_gains_fx( return; } Word16 ivas_is_res_channel( - const Word16 ch, /* i : ch index in WYZX ordering */ - const Word16 nchan_transport /* i : number of transport channels (1-4) */ + const Word16 ch, /* i : ch index in WYZX ordering Q0*/ + const Word16 nchan_transport /* i : number of transport channels (1-4) Q0*/ ) { const Word16 rc_map[FOA_CHANNELS][FOA_CHANNELS] = { @@ -1355,7 +1356,7 @@ Word16 ivas_is_res_channel( } assert( nchan_transport <= FOA_CHANNELS ); - return ( rc_map[nchan_transport - 1][ch] ); + return ( rc_map[nchan_transport - 1][ch] ); /*Q0*/ } #else void ivas_spar_get_cldfb_gains( @@ -1596,15 +1597,15 @@ static ivas_error ivas_spar_dec_MD_fx( * Initialization *---------------------------------------------------------------------*/ - sba_order = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); - bfi = st_ivas->bfi; + sba_order = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); /*Q0*/ + bfi = st_ivas->bfi; /*Q0*/ move16(); - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /*Q0*/ move32(); - num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, ivas_total_brate ); - num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, ivas_total_brate ); /*Q0*/ + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); /*Q0*/ - num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; + num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; /*Q0*/ move16(); test(); @@ -1621,17 +1622,17 @@ static ivas_error ivas_spar_dec_MD_fx( } ELSE { - hSpar->hMdDec->spar_md.num_bands = s_min( SPAR_DIRAC_SPLIT_START_BAND, IVAS_MAX_NUM_BANDS ); + hSpar->hMdDec->spar_md.num_bands = s_min( SPAR_DIRAC_SPLIT_START_BAND, IVAS_MAX_NUM_BANDS ); /*Q0*/ move16(); } IF( NE_16( hSpar->hMdDec->table_idx, table_idx ) ) { - hSpar->hMdDec->table_idx = table_idx; + hSpar->hMdDec->table_idx = table_idx; /*Q0*/ move16(); if ( hSpar->hTdDecorr ) { - hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[table_idx].td_ducking; + hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[table_idx].td_ducking; /*Q0*/ move16(); } @@ -1828,10 +1829,11 @@ static ivas_error ivas_spar_dec_MD( static Word16 ivas_spar_get_cldfb_slot_gain_fx( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const Word16 time_slot_idx, - Word16 *time_slot_idx0, - Word16 *time_slot_idx1, - Word16 *weight_lowfreq_fx ) + const Word16 time_slot_idx, /*Q0*/ + Word16 *time_slot_idx0, /*Q0*/ + Word16 *time_slot_idx1, /*Q0*/ + Word16 *weight_lowfreq_fx /*Q15*/ +) { Word16 weight_fx; Word32 encfb_delay_fx, decfb_delay_fx; @@ -1840,40 +1842,40 @@ static Word16 ivas_spar_get_cldfb_slot_gain_fx( Word16 i_hist; Word16 split_band; - *weight_lowfreq_fx = hSpar->hFbMixer->cldfb_cross_fade_fx[time_slot_idx]; + *weight_lowfreq_fx = hSpar->hFbMixer->cldfb_cross_fade_fx[time_slot_idx]; /*Q15*/ move16(); encfb_delay_fx = IVAS_FB_ENC_DELAY_NS; move32(); decfb_delay_fx = IVAS_FB_DEC_DELAY_NS; move32(); - Word32 one_by_outfs = 0; // q15 + Word32 one_by_outfs = 0; // Q15 move32(); SWITCH( hDecoderConfig->output_Fs ) { case 16000: - one_by_outfs = 2048000000; + one_by_outfs = 2048000000; /* 1000000000.0f/(output_Fs) in Q15 */ move32(); BREAK; case 32000: - one_by_outfs = 1024000000; + one_by_outfs = 1024000000; /* 1000000000.0f/(output_Fs) in Q15 */ move32(); BREAK; case 48000: - one_by_outfs = 682666688; + one_by_outfs = 682666688; /* 1000000000.0f/(output_Fs) in Q15 */ move32(); BREAK; default: assert( 0 ); } - Word64 fade_start = W_mult0_32_32( one_by_outfs, hSpar->hFbMixer->cross_fade_start_offset ); + Word64 fade_start = W_mult0_32_32( one_by_outfs, hSpar->hFbMixer->cross_fade_start_offset ); /*Q15*/ move64(); - fade_start = W_shr( fade_start, 15 ); - xfade_start_ns_fx = L_add( L_sub( W_extract_l( fade_start ), encfb_delay_fx ), L_shr( decfb_delay_fx, 1 ) ); - xfade_delay_subframes = extract_l( Mpy_32_32( xfade_start_ns_fx, 429 /* 1 / ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 -> 429 */ ) ); + fade_start = W_shr( fade_start, 15 ); /*Q0*/ + xfade_start_ns_fx = L_add( L_sub( W_extract_l( fade_start ), encfb_delay_fx ), L_shr( decfb_delay_fx, 1 ) ); /*Q0*/ + xfade_delay_subframes = extract_l( Mpy_32_32( xfade_start_ns_fx, 429 /* 1 / ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 -> 429 */ ) ); /*Q0*/ - i_hist = sub( 4, xfade_delay_subframes ); + i_hist = sub( 4, xfade_delay_subframes ); /*Q0*/ split_band = SPAR_DIRAC_SPLIT_START_BAND; move16(); @@ -1890,15 +1892,15 @@ static Word16 ivas_spar_get_cldfb_slot_gain_fx( move16(); BREAK; case 1: - weight_fx = 8191; + weight_fx = 8191; /*0.25f in Q15*/ move16(); BREAK; case 2: - weight_fx = 16383; + weight_fx = 16383; /*0.5f in Q15*/ move16(); BREAK; case 3: - weight_fx = 24575; + weight_fx = 24575; /*0.75f in Q15*/ move16(); BREAK; default: @@ -1912,23 +1914,23 @@ static Word16 ivas_spar_get_cldfb_slot_gain_fx( weight_fx = 0; move16(); } - *time_slot_idx0 = i_hist; + *time_slot_idx0 = i_hist; /*Q0*/ move16(); - *time_slot_idx1 = add( i_hist, 1 ); + *time_slot_idx1 = add( i_hist, 1 ); /*Q0*/ move16(); } ELSE { /* determine cross-fade gain for current frame Parameters*/ - *time_slot_idx0 = hSpar->hFbMixer->cldfb_cross_fade_start; + *time_slot_idx0 = hSpar->hFbMixer->cldfb_cross_fade_start; /*Q0*/ move16(); - *time_slot_idx1 = hSpar->hFbMixer->cldfb_cross_fade_end; + *time_slot_idx1 = hSpar->hFbMixer->cldfb_cross_fade_end; /*Q0*/ move16(); - weight_fx = *weight_lowfreq_fx; + weight_fx = *weight_lowfreq_fx; /*Q15*/ move16(); } - return weight_fx; + return weight_fx; /*Q15*/ } #else @@ -1992,20 +1994,21 @@ static float ivas_spar_get_cldfb_slot_gain( #ifdef IVAS_FLOAT_FIXED void ivas_spar_get_parameters_fx( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const Word16 ts, - const Word16 num_ch_out, - const Word16 num_ch_in, - const Word16 num_spar_bands, - Word32 par_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] ) + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const Word16 ts, /*Q0*/ + const Word16 num_ch_out, /*Q0*/ + const Word16 num_ch_in, /*Q0*/ + const Word16 num_spar_bands, /*Q0*/ + Word32 par_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /*hSpar->hMdDec->Q_mixer_mat*/ +) { Word16 spar_band, out_ch, in_ch; Word16 weight_fx, weight_20ms_fx; Word16 ts0, ts1, split_band; // weight = ivas_spar_get_cldfb_slot_gain(hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms); - weight_fx = ivas_spar_get_cldfb_slot_gain_fx( hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms_fx ); + weight_fx = ivas_spar_get_cldfb_slot_gain_fx( hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms_fx ); /*Q15*/ split_band = SPAR_DIRAC_SPLIT_START_BAND; move16(); @@ -2025,12 +2028,12 @@ void ivas_spar_get_parameters_fx( { par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], sub( MAX_WORD16, weight_fx ) ), - Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx ) ); + Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx ) ); /*hSpar->hMdDec->Q_mixer_mat*/ move32(); } ELSE { - par_mat_fx[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band]; + par_mat_fx[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band]; /*hSpar->hMdDec->Q_mixer_mat*/ move32(); } } @@ -2042,7 +2045,7 @@ void ivas_spar_get_parameters_fx( /* 20ms Transport channel reconstruction with matching encoder/decoder processing */ Word16 prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ move16(); - par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[prev_idx][out_ch][in_ch][spar_band], sub( MAX_WORD16, weight_20ms_fx ) ), Mpy_32_16_1( hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band], weight_20ms_fx ) ); + par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[prev_idx][out_ch][in_ch][spar_band], sub( MAX_WORD16, weight_20ms_fx ) ), Mpy_32_16_1( hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band], weight_20ms_fx ) ); /*hSpar->hMdDec->Q_mixer_mat*/ move32(); } } @@ -2177,12 +2180,13 @@ static void ivas_spar_get_skip_mat( #else static void ivas_spar_get_skip_mat_fx( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - const Word16 num_ch_out, - const Word16 num_ch_in, - const Word16 num_spar_bands, - Word16 skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const Word16 num_md_sub_frames ) + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + const Word16 num_ch_out, /*Q0*/ + const Word16 num_ch_in, /*Q0*/ + const Word16 num_spar_bands, /*Q0*/ + Word16 skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*Q0*/ + const Word16 num_md_sub_frames /*Q0*/ +) { Word16 spar_band, out_ch, in_ch; Word16 i_ts, skip_flag; @@ -2221,7 +2225,7 @@ static void ivas_spar_get_skip_mat_fx( { FOR( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) { - IF( hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][add( spar_band, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] != 0 ) + IF( hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][( spar_band + ( i_ts * IVAS_MAX_NUM_BANDS ) )] != 0 ) { skip_flag = 0; move16(); @@ -2247,15 +2251,15 @@ static void ivas_spar_get_skip_mat_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_spar_calc_smooth_facs_fx( - Word32 *cldfb_in_ts_re_fx[CLDFB_NO_COL_MAX], // i - Word32 *cldfb_in_ts_im_fx[CLDFB_NO_COL_MAX], // i + Word32 *cldfb_in_ts_re_fx[CLDFB_NO_COL_MAX], // i q_cldfb + Word32 *cldfb_in_ts_im_fx[CLDFB_NO_COL_MAX], // i q_cldfb Word16 q_cldfb, - Word16 nbands_spar, - const Word16 nSlots, - const Word16 isFirstSubframe, + Word16 nbands_spar, /*Q0*/ + const Word16 nSlots, /*Q0*/ + const Word16 isFirstSubframe, /*Q0*/ ivas_fb_bin_to_band_data_t *bin2band, - Word16 *smooth_fac_fx, // o - Word32 smooth_buf_fx[IVAS_MAX_NUM_BANDS][2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1] ) // o + Word16 *smooth_fac_fx, // o Q15 + Word32 smooth_buf_fx[IVAS_MAX_NUM_BANDS][2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1] ) // o Q0 { Word16 b, bin, i, ts; Word32 subframe_band_nrg_fx[IVAS_MAX_NUM_BANDS]; @@ -2370,7 +2374,7 @@ static void ivas_spar_calc_smooth_facs_fx( } /* apply upper bounds depending on band */ - smooth_fac_fx[b] = s_max( min_smooth_gains1_fx[b], s_min( max_smooth_gains2_fx[b], smooth_fac_fx[b] ) ); + smooth_fac_fx[b] = s_max( min_smooth_gains1_fx[b], s_min( max_smooth_gains2_fx[b], smooth_fac_fx[b] ) ); /*Q15*/ move16(); } @@ -2382,7 +2386,7 @@ static void ivas_spar_calc_smooth_facs_fx( { FOR( i = 2 * SBA_DIRAC_NRG_SMOOTH_LONG; i > 0; i-- ) { - smooth_buf_fx[b][i] = smooth_buf_fx[b][i - 1]; + smooth_buf_fx[b][i] = smooth_buf_fx[b][i - 1]; /*Q0*/ move32(); } } @@ -2549,8 +2553,8 @@ void ivas_spar_dec_agc_pca( #else void ivas_spar_dec_agc_pca_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - Word32 *output[], /* i/o: input/output audio channels */ - const Word16 output_frame /* i : output frame length */ + Word32 *output[], /* i/o: input/output audio channels Q14*/ + const Word16 output_frame /* i : output frame length Q0*/ ) { Word16 nchan_transport; @@ -2562,7 +2566,7 @@ void ivas_spar_dec_agc_pca_fx( hSpar = st_ivas->hSpar; hDecoderConfig = st_ivas->hDecoderConfig; - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; /*Q0*/ move16(); IF( GE_16( st_ivas->nchan_transport, 3 ) ) @@ -2572,22 +2576,22 @@ void ivas_spar_dec_agc_pca_fx( /*convert WYZX downmix to WYXZ*/ FOR( i = 0; i < output_frame; i++ ) { - temp = output[2][i]; + temp = output[2][i]; /*Q14*/ move32(); - output[2][i] = output[3][i]; + output[2][i] = output[3][i]; /*Q14*/ move32(); - output[3][i] = temp; + output[3][i] = temp; /*Q14*/ move32(); } } IF( hSpar->hMdDec->td_decorr_flag ) { - num_in_ingest = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + num_in_ingest = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/ } ELSE { - num_in_ingest = nchan_transport; + num_in_ingest = nchan_transport; /*Q0*/ move16(); } @@ -2647,7 +2651,7 @@ void ivas_spar_dec_set_render_map( #else void ivas_spar_dec_set_render_map_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 nCldfbTs /* i : number of CLDFB time slots */ + const Word16 nCldfbTs /* i : number of CLDFB time slots Q0*/ ) { SPAR_DEC_HANDLE hSpar; @@ -2655,7 +2659,7 @@ void ivas_spar_dec_set_render_map_fx( hSpar = st_ivas->hSpar; /* adapt subframes */ - hSpar->num_slots = nCldfbTs; + hSpar->num_slots = nCldfbTs; /*Q0*/ move16(); hSpar->slots_rendered = 0; move16(); @@ -2670,9 +2674,9 @@ void ivas_spar_dec_set_render_map_fx( test(); IF( !( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) ) { - st_ivas->hTcBuffer->nb_subframes = hSpar->nb_subframes; + st_ivas->hTcBuffer->nb_subframes = hSpar->nb_subframes; /*Q0*/ move16(); - Copy( hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpar->nb_subframes ); + Copy( hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpar->nb_subframes ); /*Q0*/ } ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, 1, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hSpar->render_to_md_map ); @@ -2710,7 +2714,7 @@ void ivas_spar_dec_set_render_params( #else void ivas_spar_dec_set_render_params_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const Word16 n_cldfb_slots /* i : number of cldfb slots in this frame */ + const Word16 n_cldfb_slots /* i : number of cldfb slots in this frame Q0*/ ) { SPAR_DEC_HANDLE hSpar; @@ -2718,9 +2722,9 @@ void ivas_spar_dec_set_render_params_fx( Word16 num_bands_out; hSpar = st_ivas->hSpar; - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; /*Q0*/ move16(); - num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; + num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; /*Q0*/ move16(); ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); @@ -2819,9 +2823,9 @@ void ivas_spar_dec_digest_tc( #else void ivas_spar_dec_digest_tc_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const Word16 nchan_transport, /* i : number of transport channels */ - const Word16 nCldfbSlots, /* i : number of CLDFB slots */ - const Word16 nSamplesForRendering /* i : number of samples provided */ + const Word16 nchan_transport, /* i : number of transport channels Q0*/ + const Word16 nCldfbSlots, /* i : number of CLDFB slots Q0*/ + const Word16 nSamplesForRendering /* i : number of samples provided Q0*/ ) { SPAR_DEC_HANDLE hSpar; @@ -2846,7 +2850,7 @@ void ivas_spar_dec_digest_tc_fx( { if ( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - ch_sba_idx = st_ivas->nchan_ism; + ch_sba_idx = st_ivas->nchan_ism; /*Q0*/ move16(); } } @@ -2854,20 +2858,20 @@ void ivas_spar_dec_digest_tc_fx( /* TD decorrelator */ Word32 quo, rem; iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &quo, &rem, 0 ); - default_frame = extract_l( quo ); - nSamplesLeftForTD = nSamplesForRendering; + default_frame = extract_l( quo ); /*Q0*/ + nSamplesLeftForTD = nSamplesForRendering; /*Q0*/ move16(); - nchan_internal = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + nchan_internal = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/ FOR( ch = 0; ch < nchan_internal; ch++ ) { - pPcm_tmp[ch] = Pcm_tmp[ch]; - p_tc[ch] = st_ivas->hTcBuffer->tc_fx[add( ch, ch_sba_idx )]; + pPcm_tmp[ch] = Pcm_tmp[ch]; /*Q11*/ + p_tc[ch] = st_ivas->hTcBuffer->tc_fx[( ch + ch_sba_idx )]; /*Q11*/ } WHILE( nSamplesLeftForTD ) { - Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame ); + Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame ); /*Q0*/ IF( hSpar->hTdDecorr ) { @@ -2879,27 +2883,27 @@ void ivas_spar_dec_digest_tc_fx( { FOR( ch = 0; ch < sub( nchan_internal, nchan_transport ); ch++ ) { - Copy32( pPcm_tmp[sub( sub( hSpar->hTdDecorr->num_apd_outputs, 1 ), ch )], p_tc[sub( sub( nchan_internal, 1 ), ch )], nSamplesToDecorr ); + Copy32( pPcm_tmp[( ( hSpar->hTdDecorr->num_apd_outputs - 1 ) - ch )], p_tc[( ( nchan_internal - 1 ) - ch )], nSamplesToDecorr ); /*Q11*/ } } ELSE { FOR( ch = 0; ch < sub( nchan_internal, nchan_transport ); ch++ ) { - set32_fx( p_tc[sub( sub( nchan_internal, 1 ), ch )], 0, nSamplesToDecorr ); + set32_fx( p_tc[( ( nchan_internal - 1 ) - ch )], 0, nSamplesToDecorr ); } FOR( ch = 0; ch < hSpar->hTdDecorr->num_apd_outputs; ch++ ) { - Copy32( pPcm_tmp[sub( sub( hSpar->hTdDecorr->num_apd_outputs, 1 ), ch )], p_tc[sub( sub( nchan_internal, 1 ), ch )], nSamplesToDecorr ); + Copy32( pPcm_tmp[( ( hSpar->hTdDecorr->num_apd_outputs - 1 ) - ch )], p_tc[( ( nchan_internal - 1 ) - ch )], nSamplesToDecorr ); /*Q11*/ } } } FOR( ch = 0; ch < nchan_internal; ch++ ) { - p_tc[ch] = p_tc[ch] + nSamplesToDecorr; + p_tc[ch] = p_tc[ch] + nSamplesToDecorr; /*Q11*/ } - nSamplesLeftForTD = sub( nSamplesLeftForTD, nSamplesToDecorr ); + nSamplesLeftForTD = sub( nSamplesLeftForTD, nSamplesToDecorr ); /*Q0*/ } } @@ -3047,8 +3051,8 @@ void ivas_spar_dec_upmixer( #ifdef IVAS_FLOAT_FIXED void ivas_spar_dec_upmixer_sf_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - Word32 *output_fx[], /* o : output audio channels */ - const Word16 nchan_internal, /* i : number of internal channels */ + Word32 *output_fx[], /* o : output audio channels Q11*/ + const Word16 nchan_internal, /* i : number of internal channels Q0*/ Word16 out_len ) { Word16 cldfb_band, num_cldfb_bands, numch_in, numch_out; @@ -3072,19 +3076,19 @@ void ivas_spar_dec_upmixer_sf_fx( push_wmops( "ivas_spar_dec_upmixer_sf" ); hSpar = st_ivas->hSpar; hDecoderConfig = st_ivas->hDecoderConfig; - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; /*Q0*/ move16(); - num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; + num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; /*Q0*/ move16(); - numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; /*Q0*/ move16(); - numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; /*Q0*/ move16(); - num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); - slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); /*Q0*/ + slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /*Q0*/ move16(); - slot_idx_start = hSpar->slots_rendered; + slot_idx_start = hSpar->slots_rendered; /*Q0*/ move16(); test(); @@ -3097,7 +3101,7 @@ void ivas_spar_dec_upmixer_sf_fx( FOR( i = 0; i < nchan_internal; i++ ) { - p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[add( i, nchan_ism )] + i_mult( slot_idx_start, slot_size ); + p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[( i + nchan_ism )] + i_mult( slot_idx_start, slot_size ); /*Q11*/ } test(); @@ -3106,7 +3110,7 @@ void ivas_spar_dec_upmixer_sf_fx( { FOR( i = 0; i < nchan_ism; i++ ) { - p_tc_fx[add( i, nchan_internal )] = st_ivas->hTcBuffer->tc_fx[i] + i_mult( slot_idx_start, slot_size ); + p_tc_fx[( i + nchan_internal )] = st_ivas->hTcBuffer->tc_fx[i] + i_mult( slot_idx_start, slot_size ); /*Q11*/ } } } @@ -3114,7 +3118,7 @@ void ivas_spar_dec_upmixer_sf_fx( { FOR( i = 0; i < nchan_internal; i++ ) { - p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[i] + i_mult( slot_idx_start, slot_size ); + p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[i] + i_mult( slot_idx_start, slot_size ); /*Q11*/ } } @@ -3125,12 +3129,12 @@ void ivas_spar_dec_upmixer_sf_fx( IF( hSpar->hMdDec->td_decorr_flag ) { - num_in_ingest = nchan_internal; + num_in_ingest = nchan_internal; /*Q0*/ move16(); } ELSE { - num_in_ingest = nchan_transport; + num_in_ingest = nchan_transport; /*Q0*/ move16(); } @@ -3138,7 +3142,7 @@ void ivas_spar_dec_upmixer_sf_fx( * PCA decoder *---------------------------------------------------------------------*/ - hSpar->hFbMixer->fb_cfg->num_in_chans = num_in_ingest; + hSpar->hFbMixer->fb_cfg->num_in_chans = num_in_ingest; /*Q0*/ move16(); @@ -3157,8 +3161,8 @@ void ivas_spar_dec_upmixer_sf_fx( { FOR( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { - cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][i_mult( ts, num_cldfb_bands )]; - cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][add( i_mult( ts, num_cldfb_bands ), ( 4 * num_cldfb_bands ) )]; + cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][( ts * num_cldfb_bands )]; /*Q11*/ + cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][( ( ts * num_cldfb_bands ) + ( 4 * num_cldfb_bands ) )]; /*Q11*/ } } } @@ -3168,8 +3172,8 @@ void ivas_spar_dec_upmixer_sf_fx( { FOR( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { - cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][i_mult( ts, num_cldfb_bands )]; - cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][add( i_mult( ts, num_cldfb_bands ), ( 4 * num_cldfb_bands ) )]; + cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][( ts * num_cldfb_bands )]; /*Q11*/ + cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][( ( ts * num_cldfb_bands ) + ( 4 * num_cldfb_bands ) )]; /*Q11*/ } } } @@ -3178,7 +3182,7 @@ void ivas_spar_dec_upmixer_sf_fx( * CLDFB Processing and Synthesis *---------------------------------------------------------------------*/ - num_spar_bands = hSpar->hFbMixer->pFb->filterbank_num_bands; + num_spar_bands = hSpar->hFbMixer->pFb->filterbank_num_bands; /*Q0*/ move16(); /* apply parameters */ @@ -3196,7 +3200,7 @@ void ivas_spar_dec_upmixer_sf_fx( { Word16 q_cldfb = 11; move16(); - cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][i_mult( ts, num_cldfb_bands )], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch], &q_cldfb ); + cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][( ts * num_cldfb_bands )], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch], &q_cldfb ); } } @@ -3204,13 +3208,13 @@ void ivas_spar_dec_upmixer_sf_fx( test(); IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { - FOR( ; in_ch < add( st_ivas->nchan_ism, numch_in ); in_ch++ ) + FOR( ; in_ch < ( st_ivas->nchan_ism + numch_in ); in_ch++ ) { FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { Word16 q_cldfb = 11; move16(); - cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][i_mult( ts, num_cldfb_bands )], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch], &q_cldfb ); + cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][( ts * num_cldfb_bands )], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch], &q_cldfb ); } } } @@ -3226,9 +3230,9 @@ void ivas_spar_dec_upmixer_sf_fx( } FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { - md_idx = hSpar->render_to_md_map[add( ts, slot_idx_start )]; + md_idx = hSpar->render_to_md_map[( ts + slot_idx_start )]; /*Q0*/ move16(); - Scale_sig( hSpar->hFbMixer->cldfb_cross_fade_fx, CLDFB_NO_COL_MAX, Q15 - st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q ); + Scale_sig( hSpar->hFbMixer->cldfb_cross_fade_fx, CLDFB_NO_COL_MAX, Q15 - st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q ); /*Q15*/ st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q = Q15; move16(); ivas_spar_get_parameters_fx( hSpar, hDecoderConfig, md_idx, numch_out, numch_in, num_spar_bands, mixer_mat_fx ); @@ -3245,7 +3249,7 @@ void ivas_spar_dec_upmixer_sf_fx( { mixer_mat_fx[out_ch][in_ch][spar_band] = Madd_32_16( Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], sub( 32767, hSpar->hMdDec->smooth_fac_fx[spar_band] ) ), hSpar->hMdDec->mixer_mat_prev2_fx[out_ch][in_ch][spar_band], hSpar->hMdDec->smooth_fac_fx[spar_band] ); /*q1*/ move32(); - hSpar->hMdDec->mixer_mat_prev2_fx[out_ch][in_ch][spar_band] = mixer_mat_fx[out_ch][in_ch][spar_band]; + hSpar->hMdDec->mixer_mat_prev2_fx[out_ch][in_ch][spar_band] = mixer_mat_fx[out_ch][in_ch][spar_band]; /*q1*/ move32(); } } @@ -3271,9 +3275,9 @@ void ivas_spar_dec_upmixer_sf_fx( { IF( LT_16( cldfb_band, CLDFB_PAR_WEIGHT_START_BAND ) ) /* tuning parameter, depends on how much SPAR Filters overlap for the CLDFB bands */ { - spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; + spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; /*Q0*/ move16(); - cldfb_par_fx = mixer_mat_fx[out_ch][in_ch][spar_band]; + cldfb_par_fx = mixer_mat_fx[out_ch][in_ch][spar_band]; /*q1*/ move32(); } ELSE @@ -3283,8 +3287,8 @@ void ivas_spar_dec_upmixer_sf_fx( FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ - Word16 tmp = extract_l( L_shr( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 7 ) ); - cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ + Word16 tmp = extract_l( L_shr( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 7 ) ); /*Q15*/ + cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ } } @@ -3307,10 +3311,10 @@ void ivas_spar_dec_upmixer_sf_fx( } test(); - IF( ( EQ_16( ( add( add( slot_idx_start, ts ), 1 ) ), hSpar->num_slots ) ) || ( NE_16( ( shr( md_idx, 2 ) /* md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME */ ), ( hSpar->render_to_md_map[add( add( slot_idx_start, ts ), 1 )] / JBM_CLDFB_SLOTS_IN_SUBFRAME /*It's value is 4*/ ) ) ) ) + IF( ( EQ_16( ( add( add( slot_idx_start, ts ), 1 ) ), hSpar->num_slots ) ) || ( NE_16( ( shr( md_idx, 2 ) /* md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME */ ), ( hSpar->render_to_md_map[( ( slot_idx_start + ts ) + 1 )] / JBM_CLDFB_SLOTS_IN_SUBFRAME /*It's value is 4*/ ) ) ) ) { /* we have crossed an unadapted parameter sf border, update previous mixing matrices */ - Word16 md_sf = shr( md_idx, 2 ) /* md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME */; + Word16 md_sf = shr( md_idx, 2 ) /* md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME */; /*Q0*/ split_band = SPAR_DIRAC_SPLIT_START_BAND; move16(); if ( NE_16( num_md_sub_frames, MAX_PARAM_SPATIAL_SUBFRAMES ) ) @@ -3320,10 +3324,10 @@ void ivas_spar_dec_upmixer_sf_fx( } IF( LT_16( split_band, IVAS_MAX_NUM_BANDS ) ) { - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], hSpar->hMdDec->mixer_mat_prev_fx[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[4][0][0], hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], hSpar->hMdDec->mixer_mat_prev_fx[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); /*hSpar->hMdDec->Q_mixer_mat*/ + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); /*hSpar->hMdDec->Q_mixer_mat*/ + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); /*hSpar->hMdDec->Q_mixer_mat*/ + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[4][0][0], hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); /*hSpar->hMdDec->Q_mixer_mat*/ FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) { @@ -3331,14 +3335,14 @@ void ivas_spar_dec_upmixer_sf_fx( { FOR( b = 0; b < num_spar_bands; b++ ) { - hSpar->hMdDec->mixer_mat_prev_fx[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][add( b, i_mult( md_sf, IVAS_MAX_NUM_BANDS ) )]; + hSpar->hMdDec->mixer_mat_prev_fx[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][( b + ( md_sf * IVAS_MAX_NUM_BANDS ) )]; /*hSpar->hMdDec->Q_mixer_mat*/ move32(); } } } - hSpar->i_subframe = add( hSpar->i_subframe, 1 ); + hSpar->i_subframe = add( hSpar->i_subframe, 1 ); /*Q0*/ move16(); - hSpar->i_subframe = s_min( hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES ); + hSpar->i_subframe = s_min( hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES ); /*Q0*/ move16(); } } @@ -3359,7 +3363,7 @@ void ivas_spar_dec_upmixer_sf_fx( idx_lfe = 0; move16(); - outchannels = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); + outchannels = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); /*Q0*/ FOR( ch = 0; ch < outchannels; ch++ ) { @@ -3383,16 +3387,16 @@ void ivas_spar_dec_upmixer_sf_fx( IF( ( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) || !( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) && !( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { - Scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, -6 ); + Scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, -6 ); /*st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state-6*/ st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = sub( st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state, 6 ); move16(); - Scale_sig32( output_fx[ch], out_len, -6 ); + Scale_sig32( output_fx[ch], out_len, -6 ); /*Q5*/ FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { cldfbSynthesis_ivas_fx( &cldfb_in_ts_re_fx[idx_in][ts], &cldfb_in_ts_im_fx[idx_in][ts], &output_fx[ch][i_mult( ts, num_cldfb_bands )], num_cldfb_bands, st_ivas->cldfbSynDec[idx_in] ); } - Scale_sig32( output_fx[ch], out_len, 6 ); - Scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, 6 ); + Scale_sig32( output_fx[ch], out_len, 6 ); /*Q11*/ + Scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, 6 ); /*st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state+6*/ st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = add( st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state, 6 ); move16(); } @@ -3406,24 +3410,24 @@ void ivas_spar_dec_upmixer_sf_fx( /* CLDFB to time synthesis (overwrite mixer output) */ FOR( out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) { - Scale_sig32( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx, st_ivas->cldfbSynDec[out_ch]->p_filter_length, -6 ); + Scale_sig32( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx, st_ivas->cldfbSynDec[out_ch]->p_filter_length, -6 ); /*st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state-6*/ st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state = sub( st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state, 6 ); move16(); - Scale_sig32( output_fx[out_ch], out_len, -6 ); + Scale_sig32( output_fx[out_ch], out_len, -6 ); /*Q5*/ FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { cldfbSynthesis_ivas_fx( &cldfb_in_ts_re_fx[out_ch][ts], &cldfb_in_ts_im_fx[out_ch][ts], &output_fx[out_ch][i_mult( ts, num_cldfb_bands )], num_cldfb_bands, st_ivas->cldfbSynDec[out_ch] ); } - Scale_sig32( output_fx[out_ch], out_len, 6 ); - Scale_sig32( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx, st_ivas->cldfbSynDec[out_ch]->p_filter_length, 6 ); + Scale_sig32( output_fx[out_ch], out_len, 6 ); /*Q11*/ + Scale_sig32( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx, st_ivas->cldfbSynDec[out_ch]->p_filter_length, 6 ); /*st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state+6*/ st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state = add( st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state, 6 ); move16(); } } - hSpar->slots_rendered = add( hSpar->slots_rendered, hSpar->subframe_nbslots[hSpar->subframes_rendered] ); + hSpar->slots_rendered = add( hSpar->slots_rendered, hSpar->subframe_nbslots[hSpar->subframes_rendered] ); /*Q0*/ move16(); - hSpar->subframes_rendered = add( hSpar->subframes_rendered, 1 ); + hSpar->subframes_rendered = add( hSpar->subframes_rendered, 1 ); /*Q0*/ move16(); pop_wmops(); diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index a2f30844149e6d65ec897968d46765683002fea8..886db765145d8deffd4509ed4bdb31571a221a55 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -261,8 +261,8 @@ ivas_error ivas_spar_md_dec_matrix_open( #else ivas_error ivas_spar_md_dec_matrix_open_fx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 num_channels, /* i : number of internal channels */ - const Word16 num_md_sub_frames /* i : number of MD subframes */ + const Word16 num_channels, /* i : number of internal channels Q0*/ + const Word16 num_md_sub_frames /* i : number of MD subframes Q0*/ ) { Word16 i, j; @@ -437,9 +437,9 @@ ivas_error ivas_spar_md_dec_matrix_open_fx( /*! r: number of MD subframes */ #ifdef IVAS_FLOAT_FIXED Word16 ivas_get_spar_dec_md_num_subframes( - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word32 ivas_last_active_brate /* i : IVAS last active bitrate */ + const Word16 sba_order, /* i : Ambisonic (SBA) order Q0*/ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + const Word32 ivas_last_active_brate /* i : IVAS last active bitrate Q0*/ ) { Word16 num_subframes; @@ -464,7 +464,7 @@ Word16 ivas_get_spar_dec_md_num_subframes( move16(); } - return ( num_subframes ); + return ( num_subframes ); /*Q0*/ } #else int16_t ivas_get_spar_dec_md_num_subframes( @@ -504,10 +504,10 @@ int16_t ivas_get_spar_dec_md_num_subframes( ivas_error ivas_spar_md_dec_open( ivas_spar_md_dec_state_t **hMdDec_out, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const Word16 num_channels, /* i : number of internal channels */ - const Word16 sba_order, /* i : SBA order */ - const Word16 sid_format, /* i : SID format */ - const Word32 last_active_ivas_total_brate /* i : IVAS last active bitrate */ + const Word16 num_channels, /* i : number of internal channels Q0*/ + const Word16 sba_order, /* i : SBA order Q0*/ + const Word16 sid_format, /* i : SID format Q0*/ + const Word32 last_active_ivas_total_brate /* i : IVAS last active bitrate Q0*/ ) { ivas_spar_md_dec_state_t *hMdDec; @@ -522,7 +522,7 @@ ivas_error ivas_spar_md_dec_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD decoder" ); } - num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, hDecoderConfig->ivas_total_brate, last_active_ivas_total_brate ); + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, hDecoderConfig->ivas_total_brate, last_active_ivas_total_brate ); /*Q0*/ IF( NE_32( ( error = ivas_spar_md_dec_matrix_open_fx( hMdDec, num_channels, num_md_sub_frames ) ), IVAS_ERR_OK ) ) { @@ -533,7 +533,7 @@ ivas_error ivas_spar_md_dec_open( { IF( EQ_16( sid_format, SID_SBA_2TC ) ) { - hMdDec->table_idx = ivas_get_spar_table_idx( IVAS_48k, sba_order, SPAR_CONFIG_BW, NULL, NULL ); + hMdDec->table_idx = ivas_get_spar_table_idx( IVAS_48k, sba_order, SPAR_CONFIG_BW, NULL, NULL ); /*Q0*/ move16(); } ELSE @@ -681,7 +681,7 @@ void ivas_spar_md_dec_matrix_close( #else void ivas_spar_md_dec_matrix_close_fx( ivas_spar_md_dec_state_t *hMdDecoder, /* i/o: SPAR MD decoder handle */ - const Word16 num_channels /* i : number of internal channels */ + const Word16 num_channels /* i : number of internal channels Q0*/ ) { Word16 i, j; @@ -814,11 +814,11 @@ void ivas_spar_md_dec_close( return; } -Word32 pFC_8k[IVAS_MAX_NUM_BANDS] = { 33, 100, 166, 233, 300, 366, 433, 566, 866, 1333, 2033, 3233 }; -Word32 pFC_12k[IVAS_MAX_NUM_BANDS] = { 53, 160, 266, 373, 480, 586, 693, 906, 1386, 2133, 3253, 5173 }; -Word32 pFC_16k[IVAS_MAX_NUM_BANDS] = { 66, 200, 333, 466, 600, 733, 866, 1133, 1733, 2666, 4066, 6466 }; -Word32 pFC_32k[IVAS_MAX_NUM_BANDS] = { 133, 400, 666, 933, 1200, 1466, 1733, 2266, 3466, 5333, 8133, 12933 }; -Word32 pFC_48k[IVAS_MAX_NUM_BANDS] = { 199, 600, 1000, 1400, 1800, 2200, 2600, 3400, 5200, 8000, 12200, 19400 }; +Word32 pFC_8k[IVAS_MAX_NUM_BANDS] = { 33, 100, 166, 233, 300, 366, 433, 566, 866, 1333, 2033, 3233 }; /*Q0*/ +Word32 pFC_12k[IVAS_MAX_NUM_BANDS] = { 53, 160, 266, 373, 480, 586, 693, 906, 1386, 2133, 3253, 5173 }; /*Q0*/ +Word32 pFC_16k[IVAS_MAX_NUM_BANDS] = { 66, 200, 333, 466, 600, 733, 866, 1133, 1733, 2666, 4066, 6466 }; /*Q0*/ +Word32 pFC_32k[IVAS_MAX_NUM_BANDS] = { 133, 400, 666, 933, 1200, 1466, 1733, 2266, 3466, 5333, 8133, 12933 }; /*Q0*/ +Word32 pFC_48k[IVAS_MAX_NUM_BANDS] = { 199, 600, 1000, 1400, 1800, 2200, 2600, 3400, 5200, 8000, 12200, 19400 }; /*Q0*/ #ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* @@ -921,8 +921,8 @@ ivas_error ivas_spar_md_dec_init( ivas_error ivas_spar_md_dec_init( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const Word16 num_channels, /* i : number of internal channels */ - const Word16 sba_order /* i : SBA order */ + const Word16 num_channels, /* i : number of internal channels Q0*/ + const Word16 sba_order /* i : SBA order Q0*/ ) { Word16 i, j; @@ -952,23 +952,23 @@ ivas_error ivas_spar_md_dec_init( IF( EQ_32( hDecoderConfig->output_Fs, 8000 ) ) { - pFC_fx = pFC_8k; + pFC_fx = pFC_8k; /*Q0*/ } ELSE IF( EQ_32( hDecoderConfig->output_Fs, 12800 ) ) { - pFC_fx = pFC_12k; + pFC_fx = pFC_12k; /*Q0*/ } ELSE IF( EQ_32( hDecoderConfig->output_Fs, 16000 ) ) { - pFC_fx = pFC_16k; + pFC_fx = pFC_16k; /*Q0*/ } ELSE IF( EQ_32( hDecoderConfig->output_Fs, 32000 ) ) { - pFC_fx = pFC_32k; + pFC_fx = pFC_32k; /*Q0*/ } ELSE IF( EQ_32( hDecoderConfig->output_Fs, 48000 ) ) { - pFC_fx = pFC_48k; + pFC_fx = pFC_48k; /*Q0*/ } ELSE { @@ -988,9 +988,9 @@ ivas_error ivas_spar_md_dec_init( } /* DTX quant init */ - PR_minmax_fx[0] = hMdDec->spar_md_cfg.quant_strat[0].PR.min_fx; + PR_minmax_fx[0] = hMdDec->spar_md_cfg.quant_strat[0].PR.min_fx; /*Q28*/ move32(); - PR_minmax_fx[1] = hMdDec->spar_md_cfg.quant_strat[0].PR.max_fx; + PR_minmax_fx[1] = hMdDec->spar_md_cfg.quant_strat[0].PR.max_fx; /*Q28*/ move32(); ivas_spar_quant_dtx_init_fx( &hMdDec->spar_md, PR_minmax_fx ); @@ -1058,17 +1058,17 @@ ivas_error ivas_spar_md_dec_init( static ivas_error ivas_spar_set_dec_config( ivas_spar_md_dec_state_t *hMdDec, const Word16 nchan_transport, - Word32 *pFC ) + Word32 *pFC /*Q0*/ ) { Word16 i, j, nchan, dmx_ch; FOR( i = 0; i < nchan_transport; i++ ) { - hMdDec->spar_md_cfg.max_freq_per_chan[i] = ivas_spar_br_table_consts[hMdDec->table_idx].fpcs; + hMdDec->spar_md_cfg.max_freq_per_chan[i] = ivas_spar_br_table_consts[hMdDec->table_idx].fpcs; /*Q0*/ move16(); } - nchan = ivas_sba_get_nchan_metadata_fx( ivas_spar_br_table_consts[hMdDec->table_idx].sba_order, ivas_spar_br_table_consts[hMdDec->table_idx].ivas_total_brate ); + nchan = ivas_sba_get_nchan_metadata_fx( ivas_spar_br_table_consts[hMdDec->table_idx].sba_order, ivas_spar_br_table_consts[hMdDec->table_idx].ivas_total_brate ); /*Q0*/ SWITCH( nchan ) { @@ -1090,7 +1090,7 @@ static ivas_error ivas_spar_set_dec_config( BREAK; } - hMdDec->spar_md_cfg.num_umx_chs = nchan; + hMdDec->spar_md_cfg.num_umx_chs = nchan; /*Q0*/ move16(); dmx_ch = 0; @@ -1107,13 +1107,13 @@ static ivas_error ivas_spar_set_dec_config( } } - hMdDec->spar_md_cfg.num_dmx_chans_per_band[i] = hMdDec->spar_md_cfg.nchan_transport; + hMdDec->spar_md_cfg.num_dmx_chans_per_band[i] = hMdDec->spar_md_cfg.nchan_transport; /*Q0*/ move16(); - hMdDec->spar_md_cfg.num_decorr_per_band[i] = sub( nchan, hMdDec->spar_md_cfg.nchan_transport ); + hMdDec->spar_md_cfg.num_decorr_per_band[i] = sub( nchan, hMdDec->spar_md_cfg.nchan_transport ); /*Q0*/ move16(); } - hMdDec->spar_md_cfg.nchan_transport = dmx_ch; + hMdDec->spar_md_cfg.nchan_transport = dmx_ch; /*Q0*/ move16(); return IVAS_ERR_OK; @@ -1248,11 +1248,11 @@ static void ivas_dec_mono_sba_handling_fx( { FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) { - Word32 azimuth_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; + Word32 azimuth_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; /*Q22*/ move32(); - Word32 elevation_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; + Word32 elevation_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; /*Q22*/ move32(); - Word32 energy_ratio_fx = st_ivas->hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[block]; + Word32 energy_ratio_fx = st_ivas->hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[block]; /*Q30*/ move32(); test(); @@ -1290,7 +1290,7 @@ static void ivas_dec_mono_sba_handling_fx( set32_fx( st_ivas->hSpatParamRendCom->energy_ratio2_fx[block], 0, st_ivas->hSpatParamRendCom->num_freq_bands ); } /* Set Diffuseness values to be 1.0 */ - set32_fx( st_ivas->hSpatParamRendCom->diffuseness_vector_fx[block], ONE_IN_Q30, st_ivas->hSpatParamRendCom->num_freq_bands ); + set32_fx( st_ivas->hSpatParamRendCom->diffuseness_vector_fx[block], ONE_IN_Q30, st_ivas->hSpatParamRendCom->num_freq_bands ); /*Q30*/ } } } @@ -1310,8 +1310,8 @@ static void ivas_dec_mono_sba_handling_fx( void ivas_spar_md_dec_process_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 sba_order /* i : Ambisonic (SBA) order */ + const Word16 num_bands_out, /* i : number of output bands Q0*/ + const Word16 sba_order /* i : Ambisonic (SBA) order Q0*/ ) { Word16 j, k, b, bw, dtx_vad, nB, i_ts; @@ -1334,28 +1334,28 @@ void ivas_spar_md_dec_process_fx( move16(); } - num_md_chs = ivas_sba_get_nchan_metadata_fx( sba_order, st_ivas->hDecoderConfig->ivas_total_brate ); + num_md_chs = ivas_sba_get_nchan_metadata_fx( sba_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/ - num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); /*Q0*/ test(); IF( GT_16( hMdDec->spar_md_cfg.nchan_transport, 1 ) && LE_16( hMdDec->spar_md_cfg.nchan_transport, 3 ) ) { hMdDec->spar_md.res_ind = 0; move16(); - dyn_active_w_flag = get_next_indice_fx( st0, 1 ); + dyn_active_w_flag = get_next_indice_fx( st0, 1 ); /*Q0*/ IF( EQ_16( dyn_active_w_flag, 1 ) ) { IF( EQ_16( hMdDec->spar_md_cfg.nchan_transport, 2 ) ) { - hMdDec->spar_md.res_ind = get_next_indice_fx( st0, 1 ); + hMdDec->spar_md.res_ind = get_next_indice_fx( st0, 1 ); /*Q0*/ move16(); - hMdDec->spar_md.res_ind = add( hMdDec->spar_md_cfg.nchan_transport, hMdDec->spar_md.res_ind ); + hMdDec->spar_md.res_ind = add( hMdDec->spar_md_cfg.nchan_transport, hMdDec->spar_md.res_ind ); /*Q0*/ move16(); } ELSE IF( EQ_16( hMdDec->spar_md_cfg.nchan_transport, 3 ) ) { - hMdDec->spar_md.res_ind = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order][hMdDec->spar_md_cfg.nchan_transport]; + hMdDec->spar_md.res_ind = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order][hMdDec->spar_md_cfg.nchan_transport]; /*Q0*/ move16(); } } @@ -1402,7 +1402,7 @@ void ivas_spar_md_dec_process_fx( { FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j] = hMdDec->spar_md.band_coeffs[b].pred_re_fx[j]; + hMdDec->spar_md.band_coeffs[( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j] = hMdDec->spar_md.band_coeffs[b].pred_re_fx[j]; /*Q22*/ move32(); } @@ -1410,14 +1410,14 @@ void ivas_spar_md_dec_process_fx( { FOR( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { - hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b].C_re_fx[j][k]; + hMdDec->spar_md.band_coeffs[( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )].C_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b].C_re_fx[j][k]; /*Q22*/ move32(); } } FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[j] = hMdDec->spar_md.band_coeffs[b].P_re_fx[j]; + hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[j] = hMdDec->spar_md.band_coeffs[b].P_re_fx[j]; /*Q22*/ move32(); } } @@ -1634,9 +1634,9 @@ Word16 ivas_spar_chk_zero_coefs_fx( Word16 ndec, ndm; hMdDec = st_ivas->hSpar->hMdDec; - ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0]; + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0]; /*Q0*/ move16(); - ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; /*Q0*/ move16(); FOR( b = 0; b < min( hMdDec->spar_md.num_bands, SPAR_DIRAC_SPLIT_START_BAND ); b++ ) @@ -1684,8 +1684,8 @@ Word16 ivas_spar_chk_zero_coefs_fx( #ifdef IVAS_FLOAT_FIXED void ivas_spar_smooth_md_dtx_fx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 num_md_sub_frames /* i : number of metadata subframes */ + const Word16 num_bands_out, /* i : number of output bands Q0*/ + const Word16 num_md_sub_frames /* i : number of metadata subframes Q0*/ ) { Word16 j, k, b, dmx_ch; @@ -1734,14 +1734,14 @@ void ivas_spar_smooth_md_dtx_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; + dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; /*Q0*/ move16(); FOR( j = 1; j < FOA_CHANNELS; j++ ) { FOR( k = dmx_ch; k < FOA_CHANNELS; k++ ) { - hMdDec->spar_coeffs.P_re_fx[j][k][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.P_re_fx[j][k][b]; /* Q22 */ + hMdDec->spar_coeffs.P_re_fx[j][k][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.P_re_fx[j][k][b]; /* Q22 */ move32(); } } @@ -1750,7 +1750,7 @@ void ivas_spar_smooth_md_dtx_fx( { FOR( k = 0; k < dmx_ch; k++ ) { - hMdDec->spar_coeffs.C_re_fx[j][k][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.C_re_fx[j][k][b]; /* Q22 */ + hMdDec->spar_coeffs.C_re_fx[j][k][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.C_re_fx[j][k][b]; /* Q22 */ move32(); } } @@ -1843,14 +1843,14 @@ void ivas_spar_smooth_md_dtx( #ifdef IVAS_FLOAT_FIXED void ivas_spar_setup_md_smoothing_fx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 num_md_sub_frames /* i : number of metadata subframes */ + const Word16 num_bands_out, /* i : number of output bands Q0*/ + const Word16 num_md_sub_frames /* i : number of metadata subframes Q0*/ ) { /* copy the coeffs */ Word16 num_channels, i, j, k; - num_channels = hMdDec->spar_md_cfg.num_umx_chs; + num_channels = hMdDec->spar_md_cfg.num_umx_chs; /*Q0*/ move16(); FOR( i = 0; i < num_channels; i++ ) @@ -1981,7 +1981,7 @@ void ivas_spar_update_md_hist_fx( { Word16 num_channels, i, j, k; - num_channels = hMdDec->spar_md_cfg.num_umx_chs; + num_channels = hMdDec->spar_md_cfg.num_umx_chs; /*Q0*/ move16(); FOR( i = 0; i < num_channels; i++ ) @@ -2327,14 +2327,14 @@ static void ivas_get_spar_matrices( static void ivas_get_spar_matrices_fx( ivas_spar_md_dec_state_t *hMdDec, - const Word16 num_bands_out, - const Word16 n_ts, - const Word16 bw, - const Word16 dtx_vad, - const Word16 nB, - const Word16 numch_out, - const Word16 active_w_vlbr, - const Word16 dyn_active_w_flag ) + const Word16 num_bands_out, /*Q0*/ + const Word16 n_ts, /*Q0*/ + const Word16 bw, /*Q0*/ + const Word16 dtx_vad, /*Q0*/ + const Word16 nB, /*Q0*/ + const Word16 numch_out, /*Q0*/ + const Word16 active_w_vlbr, /*Q0*/ + const Word16 dyn_active_w_flag /*Q0*/ ) { Word16 num_bands, dmx_ch, split_band; Word16 i, j, k, m, b, i_ts, active_w; @@ -2359,7 +2359,7 @@ static void ivas_get_spar_matrices_fx( { FOR( b = 0; b < num_bands; b++ ) { - hMdDec->mixer_mat_prev_fx[0][i][j][b] = hMdDec->mixer_mat_fx[i][j][b]; + hMdDec->mixer_mat_prev_fx[0][i][j][b] = hMdDec->mixer_mat_fx[i][j][b]; /*hMdDec->Q_mixer_mat*/ move32(); } } @@ -2397,8 +2397,8 @@ static void ivas_get_spar_matrices_fx( FOR( j = 0; j < numch_out; j++ ) { - set32_fx( &hMdDec->spar_coeffs.C_re_fx[i][j][i_mult( i_ts, IVAS_MAX_NUM_BANDS )], 0, IVAS_MAX_NUM_BANDS ); - set32_fx( &hMdDec->spar_coeffs.P_re_fx[i][j][i_mult( i_ts, IVAS_MAX_NUM_BANDS )], 0, IVAS_MAX_NUM_BANDS ); + set32_fx( &hMdDec->spar_coeffs.C_re_fx[i][j][( i_ts * IVAS_MAX_NUM_BANDS )], 0, IVAS_MAX_NUM_BANDS ); + set32_fx( &hMdDec->spar_coeffs.P_re_fx[i][j][( i_ts * IVAS_MAX_NUM_BANDS )], 0, IVAS_MAX_NUM_BANDS ); } } num_bands = s_min( num_bands, nB ); @@ -2409,7 +2409,7 @@ static void ivas_get_spar_matrices_fx( Word32 tmp_C1_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 tmp_C2_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 tmp_dm_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[i_mult( bw, b )]; + dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[( bw * b )]; /*Q0*/ move16(); FOR( j = 0; j < numch_out; j++ ) @@ -2418,9 +2418,9 @@ static void ivas_get_spar_matrices_fx( set_zero_fx( tmp_C2_re_fx[j], numch_out ); set_zero_fx( tmp_dm_re_fx[j], numch_out ); - tmp_C1_re_fx[j][j] = ONE_IN_Q22; - tmp_C2_re_fx[j][j] = ONE_IN_Q22; - tmp_dm_re_fx[j][j] = ONE_IN_Q22; + tmp_C1_re_fx[j][j] = ONE_IN_Q22; /*Q22*/ + tmp_C2_re_fx[j][j] = ONE_IN_Q22; /*Q22*/ + tmp_dm_re_fx[j][j] = ONE_IN_Q22; /*Q22*/ move32(); move32(); move32(); @@ -2428,7 +2428,7 @@ static void ivas_get_spar_matrices_fx( FOR( j = 1; j < numch_out; j++ ) { - tmp_C1_re_fx[j][0] = hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j - 1]; // Q.22 + tmp_C1_re_fx[j][0] = hMdDec->spar_md.band_coeffs[( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j - 1]; // Q.22 move32(); } @@ -2437,7 +2437,7 @@ static void ivas_get_spar_matrices_fx( FOR( j = 1; j < numch_out; j++ ) { - tmp_C2_re_fx[0][j] = Mpy_32_32( active_w_dm_fac_fx, L_negate( hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j - 1] ) ); // Q31 *Q22=Q22 + tmp_C2_re_fx[0][j] = Mpy_32_32( active_w_dm_fac_fx, L_negate( hMdDec->spar_md.band_coeffs[( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j - 1] ) ); // Q31 *Q22=Q22 move32(); } re_fx = Mpy_32_32( tmp_C2_re_fx[0][1], tmp_C1_re_fx[1][0] ); // Q22 *Q22 =Q13 @@ -2456,22 +2456,22 @@ static void ivas_get_spar_matrices_fx( move32(); } - tmp_dm_re_fx[0][1] = tmp_C2_re_fx[0][1]; + tmp_dm_re_fx[0][1] = tmp_C2_re_fx[0][1]; /*Q22*/ move32(); - tmp_dm_re_fx[0][2] = tmp_C2_re_fx[0][2]; + tmp_dm_re_fx[0][2] = tmp_C2_re_fx[0][2]; /*Q22*/ move32(); - tmp_dm_re_fx[0][3] = tmp_C2_re_fx[0][3]; + tmp_dm_re_fx[0][3] = tmp_C2_re_fx[0][3]; /*Q22*/ move32(); - tmp_dm_re_fx[1][0] = tmp_C1_re_fx[1][0]; + tmp_dm_re_fx[1][0] = tmp_C1_re_fx[1][0]; /*Q22*/ move32(); - tmp_dm_re_fx[2][0] = tmp_C1_re_fx[2][0]; + tmp_dm_re_fx[2][0] = tmp_C1_re_fx[2][0]; /*Q22*/ move32(); - tmp_dm_re_fx[3][0] = tmp_C1_re_fx[3][0]; + tmp_dm_re_fx[3][0] = tmp_C1_re_fx[3][0]; /*Q22*/ move32(); IF( NE_16( hMdDec->spar_md_cfg.remix_unmix_order, 3 ) ) @@ -2506,7 +2506,7 @@ static void ivas_get_spar_matrices_fx( FOR( k = 0; k < dmx_ch; k++ ) { - tmpC_re_fx[k][k] = ONE_IN_Q22; + tmpC_re_fx[k][k] = ONE_IN_Q22; /*Q22*/ move32(); } @@ -2543,9 +2543,9 @@ static void ivas_get_spar_matrices_fx( { FOR( m = 0; m < numch_out; m++ ) { - re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], tmpP_re_fx[m][k] ); // Q30*Q22 - re_fx = L_shl( re_fx, 1 ); - hMdDec->spar_coeffs.P_re_fx[j][k][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_add( hMdDec->spar_coeffs.P_re_fx[j][k][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], re_fx ); + re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], tmpP_re_fx[m][k] ); // Q30*Q22 = Q21 + re_fx = L_shl( re_fx, 1 ); /*Q22*/ + hMdDec->spar_coeffs.P_re_fx[j][k][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_add( hMdDec->spar_coeffs.P_re_fx[j][k][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )], re_fx ); /*Q22*/ move32(); } } @@ -2558,16 +2558,16 @@ static void ivas_get_spar_matrices_fx( { FOR( m = 0; m < numch_out; m++ ) { - re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], tmpC_re_fx[m][k] ); // Q30* Q22 - re_fx = L_shl( re_fx, 1 ); - hMdDec->spar_coeffs.C_re_fx[j][k][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_add( hMdDec->spar_coeffs.C_re_fx[j][k][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], re_fx ); + re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], tmpC_re_fx[m][k] ); // Q30* Q22 = Q21 + re_fx = L_shl( re_fx, 1 ); /*Q22*/ + hMdDec->spar_coeffs.C_re_fx[j][k][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_add( hMdDec->spar_coeffs.C_re_fx[j][k][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )], re_fx ); /*Q22*/ move32(); } } } - hMdDec->spar_coeffs.C_re_fx[0][0][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = - L_max( 0, hMdDec->spar_coeffs.C_re_fx[0][0][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] ); + hMdDec->spar_coeffs.C_re_fx[0][0][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = + L_max( 0, hMdDec->spar_coeffs.C_re_fx[0][0][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] ); /*Q22*/ move32(); } } @@ -2575,7 +2575,7 @@ static void ivas_get_spar_matrices_fx( /* band mixing */ IF( EQ_16( bw, IVAS_RED_BAND_FACT ) ) { - FOR( b = 0; b < num_bands_out; b = add( b, bw ) ) + FOR( b = 0; b < num_bands_out; b = ( b + bw ) ) { dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; move16(); @@ -2583,7 +2583,7 @@ static void ivas_get_spar_matrices_fx( { FOR( k = dmx_ch; k < numch_out; k++ ) { - hMdDec->spar_coeffs.P_re_fx[j][k][add( add( b, 1 ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.P_re_fx[j][k][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )]; + hMdDec->spar_coeffs.P_re_fx[j][k][( ( b + 1 ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.P_re_fx[j][k][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )]; /*Q22*/ move32(); } } @@ -2592,7 +2592,7 @@ static void ivas_get_spar_matrices_fx( { FOR( k = 0; k < dmx_ch; k++ ) { - hMdDec->spar_coeffs.C_re_fx[j][k][add( add( b, 1 ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.C_re_fx[j][k][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )]; + hMdDec->spar_coeffs.C_re_fx[j][k][( ( b + 1 ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.C_re_fx[j][k][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )]; /*Q22*/ move32(); } } @@ -2641,23 +2641,23 @@ static void ivas_mat_col_rearrange( *-----------------------------------------------------------------------------------------*/ static void ivas_mat_col_rearrange_fx( - Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const Word16 order[IVAS_SPAR_MAX_CH], - const Word16 i_ts, - Word32 ***mixer_mat, - const Word16 bands, - const Word16 num_ch ) + Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*Q22*/ + const Word16 order[IVAS_SPAR_MAX_CH], /*Q0*/ + const Word16 i_ts, /*Q0*/ + Word32 ***mixer_mat, /*Q30*/ + const Word16 bands, /*Q0*/ + const Word16 num_ch /*Q0*/ ) { Word16 i, j, idx; FOR( i = 0; i < num_ch; i++ ) { - idx = order[i]; + idx = order[i]; /*Q0*/ move16(); FOR( j = 0; j < num_ch; j++ ) { - mixer_mat[j][i][add( bands, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( in_re[j][idx], Q8 ); + mixer_mat[j][i][( bands + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( in_re[j][idx], Q8 ); /*Q30*/ move32(); } } @@ -2674,10 +2674,10 @@ static void ivas_mat_col_rearrange_fx( #ifdef IVAS_FLOAT_FIXED void ivas_spar_dec_gen_umx_mat_fx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 nchan_transport, /* i : number of transport channels */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 bfi, /* i : bad frame indicator */ - const Word16 num_md_sub_frames ) + const Word16 nchan_transport, /* i : number of transport channels Q0*/ + const Word16 num_bands_out, /* i : number of output bands Q0*/ + const Word16 bfi, /* i : bad frame indicator Q0*/ + const Word16 num_md_sub_frames /*Q0*/ ) { Word16 i, j, b, i_ts, num_out_ch; num_out_ch = hMdDec->spar_md_cfg.num_umx_chs; @@ -2692,7 +2692,7 @@ void ivas_spar_dec_gen_umx_mat_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], Q8 ); + hMdDec->mixer_mat_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], Q8 ); /*Q30*/ move32(); } } @@ -2703,7 +2703,7 @@ void ivas_spar_dec_gen_umx_mat_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.P_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], Q8 ); + hMdDec->mixer_mat_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.P_re_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], Q8 ); /*Q30*/ move32(); } } @@ -2717,7 +2717,7 @@ void ivas_spar_dec_gen_umx_mat_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], Q8 ); + hMdDec->mixer_mat_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], Q8 ); /*Q30*/ move32(); } } @@ -2791,47 +2791,47 @@ void ivas_spar_dec_gen_umx_mat( static void ivas_spar_md_band_upmix( ivas_band_coeffs_t *band_coeffs, - Word16 *nB, - Word16 *bands_bw, - Word16 *valid_bands, - Word16 bw_final, - Word16 ndec, - Word16 ndm ) + Word16 *nB, /*Q0*/ + Word16 *bands_bw, /*Q0*/ + Word16 *valid_bands, /*Q0*/ + Word16 bw_final, /*Q0*/ + Word16 ndec, /*Q0*/ + Word16 ndm /*Q0*/ ) { Word16 i, ii, jj, b, idx, bw_fact; - bw_fact = idiv1616( *bands_bw, bw_final ); + bw_fact = idiv1616( *bands_bw, bw_final ); /*Q0*/ FOR( i = sub( *nB, 1 ); i >= 0; i-- ) { FOR( b = sub( bw_fact, 1 ); b >= 0; b-- ) { - idx = add( i_mult( i, bw_fact ), b ); - FOR( ii = 0; ii < sub( add( ndec, ndm ), 1 ); ii++ ) + idx = add( i_mult( i, bw_fact ), b ); /*Q0*/ + FOR( ii = 0; ii < ( ( ndec + ndm ) - 1 ); ii++ ) { - band_coeffs[idx].pred_re_fx[ii] = band_coeffs[i].pred_re_fx[ii]; + band_coeffs[idx].pred_re_fx[ii] = band_coeffs[i].pred_re_fx[ii]; /*Q22*/ move32(); } FOR( ii = 0; ii < ndec; ii++ ) { FOR( jj = 0; jj < sub( ndm, 1 ); jj++ ) { - band_coeffs[idx].C_re_fx[ii][jj] = band_coeffs[i].C_re_fx[ii][jj]; + band_coeffs[idx].C_re_fx[ii][jj] = band_coeffs[i].C_re_fx[ii][jj]; /*Q22*/ move32(); } } FOR( jj = 0; jj < ndec; jj++ ) { - band_coeffs[idx].P_re_fx[jj] = band_coeffs[i].P_re_fx[jj]; + band_coeffs[idx].P_re_fx[jj] = band_coeffs[i].P_re_fx[jj]; /*Q22*/ move32(); } - valid_bands[idx] = valid_bands[i]; + valid_bands[idx] = valid_bands[i]; /*Q0*/ move16(); } } - *nB = idiv1616( i_mult( ( *nB ), ( *bands_bw ) ), bw_final ); + *nB = idiv1616( i_mult( ( *nB ), ( *bands_bw ) ), bw_final ); /*Q0*/ move16(); - *bands_bw = bw_final; + *bands_bw = bw_final; /*Q0*/ move16(); return; @@ -3081,11 +3081,11 @@ static void ivas_spar_dec_parse_md_bs( static void ivas_spar_dec_parse_md_bs_fx( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st0, - Word16 *nB, - Word16 *bands_bw, - Word16 *dtx_vad, - const Word32 ivas_total_brate, - const Word16 sba_inactive_mode ) + Word16 *nB, /*Q0*/ + Word16 *bands_bw, /*Q0*/ + Word16 *dtx_vad, /*Q0*/ + const Word32 ivas_total_brate, /*Q0*/ + const Word16 sba_inactive_mode /*Q0*/ ) { Word16 i, j, k, num_bands; Word16 ii, jj, ndec, ndm; @@ -3111,7 +3111,7 @@ static void ivas_spar_dec_parse_md_bs_fx( IF( GE_32( ivas_total_brate, BRATE_SPAR_Q_STRAT ) ) { /*only one bit written for quantization strategy to indicate either a fixed quantization strategy or dtx_vad==0 */ - qsi = get_next_indice_fx( st0, 1 ); + qsi = get_next_indice_fx( st0, 1 ); /*Q0*/ if ( EQ_32( qsi, 1 ) ) { *dtx_vad = 0; @@ -3144,14 +3144,14 @@ static void ivas_spar_dec_parse_md_bs_fx( move16(); } - hMdDec->dtx_vad = *dtx_vad; + hMdDec->dtx_vad = *dtx_vad; /*Q0*/ move16(); IF( *dtx_vad == 0 ) { *nB = SPAR_DTX_BANDS; move16(); - *bands_bw = idiv1616( num_bands, *nB ); + *bands_bw = idiv1616( num_bands, *nB ); /*Q0*/ move16(); FOR( i = 0; i < *nB; i++ ) @@ -3183,9 +3183,9 @@ static void ivas_spar_dec_parse_md_bs_fx( IF( NE_16( *bands_bw, 1 ) ) { - ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0]; + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0]; /*Q0*/ move16(); - ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; /*Q0*/ move16(); ivas_spar_md_band_upmix( hMdDec->spar_md.band_coeffs, @@ -3202,7 +3202,7 @@ static void ivas_spar_dec_parse_md_bs_fx( qs = hMdDec->spar_md_cfg.quant_strat[qsi]; - strat = get_next_indice_fx( st0, 3 ); + strat = get_next_indice_fx( st0, 3 ); /*Q0*/ no_ec = 0; move16(); @@ -3211,7 +3211,7 @@ static void ivas_spar_dec_parse_md_bs_fx( { *bands_bw = add( strat, 1 ); move16(); - *nB = idiv1616( num_bands, *bands_bw ); + *nB = idiv1616( num_bands, *bands_bw ); /*Q0*/ move16(); FOR( i = 0; i < *nB; i++ ) { @@ -3225,7 +3225,7 @@ static void ivas_spar_dec_parse_md_bs_fx( { *bands_bw = sub( strat, 1 ); move16(); - *nB = idiv1616( num_bands, *bands_bw ); + *nB = idiv1616( num_bands, *bands_bw ); /*Q0*/ move16(); FOR( i = 0; i < *nB; i++ ) { @@ -3241,14 +3241,14 @@ static void ivas_spar_dec_parse_md_bs_fx( { *bands_bw = 2; move16(); - *nB = idiv1616( num_bands, *bands_bw ); + *nB = idiv1616( num_bands, *bands_bw ); /*Q0*/ move16(); FOR( i = 0; i < *nB; i++ ) { do_diff[i] = 0; move16(); - do_repeat[i] = extract_l( EQ_16( ( strat % 2 ), ( add( i, 1 ) % 2 ) ) ); + do_repeat[i] = extract_l( EQ_16( ( strat % 2 ), ( add( i, 1 ) % 2 ) ) ); /*Q0*/ move16(); } } @@ -3261,7 +3261,7 @@ static void ivas_spar_dec_parse_md_bs_fx( FOR( i = 0; i < *nB; i++ ) { - do_diff[i] = extract_l( NE_16( s_and( add( i, 1 ), 3 ), sub( strat, 4 ) ) ); + do_diff[i] = extract_l( NE_16( s_and( add( i, 1 ), 3 ), sub( strat, 4 ) ) ); /*Q0*/ move16(); do_repeat[i] = 0; move16(); @@ -3285,9 +3285,9 @@ static void ivas_spar_dec_parse_md_bs_fx( FOR( i = 0; i < *nB; i++ ) { - ndec = hMdDec->spar_md_cfg.num_decorr_per_band[i_mult( ( *bands_bw ), i )]; + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[( ( *bands_bw ) * i )]; /*Q0*/ move16(); - ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[i_mult( ( *bands_bw ), i )]; + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[( ( *bands_bw ) * i )]; /*Q0*/ move16(); ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].pred_index_re, qs.PR.q_levels[0], qs.PR.min_fx, qs.PR.max_fx, hMdDec->spar_md.band_coeffs[i].pred_re_fx, sub( add( ndm, ndec ), 1 ) ); @@ -3298,7 +3298,7 @@ static void ivas_spar_dec_parse_md_bs_fx( { FOR( jj = 0; jj < sub( ndm, 1 ); jj++ ) { - quant_fx[j] = hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj]; + quant_fx[j] = hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj]; /*Q22*/ move32(); j = add( j, 1 ); } @@ -3312,7 +3312,7 @@ static void ivas_spar_dec_parse_md_bs_fx( { FOR( jj = 0; jj < sub( ndm, 1 ); jj++ ) { - hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj] = quant_fx[j]; + hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj] = quant_fx[j]; /*Q22*/ move32(); j = add( j, 1 ); } @@ -3321,19 +3321,19 @@ static void ivas_spar_dec_parse_md_bs_fx( ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].decd_index_re, qs.P_r.q_levels[0], qs.P_r.min_fx, qs.P_r.max_fx, hMdDec->spar_md.band_coeffs[i].P_re_fx, sub( add( ndm, ndec ), 1 ) ); /* Store prior coefficient indices */ - FOR( j = 0; j < sub( add( ndm, ndec ), 1 ); j++ ) + FOR( j = 0; j < ( ( ndm + ndec ) - 1 ); j++ ) { - hMdDec->spar_md_prev.band_coeffs_idx[i].pred_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; + hMdDec->spar_md_prev.band_coeffs_idx[i].pred_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; /*Q0*/ move16(); } - FOR( j = 0; j < i_mult( ndec, sub( ndm, 1 ) ); j++ ) + FOR( j = 0; j < ( ndec * ( ndm - 1 ) ); j++ ) { - hMdDec->spar_md_prev.band_coeffs_idx[i].drct_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].drct_index_re[j]; + hMdDec->spar_md_prev.band_coeffs_idx[i].drct_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].drct_index_re[j]; /*Q0*/ move16(); } FOR( j = 0; j < ndec; j++ ) { - hMdDec->spar_md_prev.band_coeffs_idx[i].decd_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j]; + hMdDec->spar_md_prev.band_coeffs_idx[i].decd_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j]; /*Q0*/ move16(); } test(); @@ -3380,13 +3380,13 @@ static void ivas_spar_dec_parse_md_bs_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_decode_arith_bs( ivas_spar_md_dec_state_t *hMdDec, - Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - const UWord16 qsi, - const Word16 nB, - const Word16 bands_bw, - Word16 *pDo_diff, - const Word16 strat, - const Word32 ivas_total_brate ) + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ + const UWord16 qsi, /*Q0*/ + const Word16 nB, /*Q0*/ + const Word16 bands_bw, /*Q0*/ + Word16 *pDo_diff, /*Q0*/ + const Word16 strat, /*Q0*/ + const Word32 ivas_total_brate /*Q0*/ ) { Word16 i, ndm, ndec; Word16 j; @@ -3430,7 +3430,7 @@ static void ivas_decode_arith_bs( } ELSE { - pred_cell_dims[i].dim1 = add( ndm, sub( ndec, 1 ) ); + pred_cell_dims[i].dim1 = add( ndm, sub( ndec, 1 ) ); /*Q0*/ move16(); IF( hMdDec->spar_hoa_md_flag && hMdDec->spar_hoa_dirac2spar_md_flag ) { @@ -3480,7 +3480,7 @@ static void ivas_decode_arith_bs( FOR( j = 0; j < pred_cell_dims[i].dim1; j++ ) { hMdDec->spar_md_prev.band_coeffs_idx_mapped[i].pred_index_re[j] = - hMdDec->spar_md_prev.band_coeffs_idx_mapped[i].pred_index_re[j + ( FOA_CHANNELS - 1 )]; + hMdDec->spar_md_prev.band_coeffs_idx_mapped[i].pred_index_re[j + ( FOA_CHANNELS - 1 )]; /*Q0*/ move16(); } } @@ -3504,7 +3504,7 @@ static void ivas_decode_arith_bs( FOR( j = pred_cell_dims[i].dim1 - 1; j >= 0; j-- ) { hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j + ( FOA_CHANNELS - 1 )] = - hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; + hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; /*Q0*/ move16(); } FOR( j = 0; j < FOA_CHANNELS - 1; j++ ) @@ -3554,8 +3554,8 @@ static void ivas_decode_arith_bs( static void ivas_fill_band_coeffs_idx( ivas_band_coeffs_ind_t *pBands_idx, - const Word16 nB, - Word16 *pSymbol_re, + const Word16 nB, /*Q0*/ + Word16 *pSymbol_re, /*Q0*/ ivas_cell_dim_t *pCell_dims, const ivas_coeffs_type_t coeff_type ) { @@ -3592,8 +3592,8 @@ static void ivas_fill_band_coeffs_idx( IF( NE_16( coeff_type, DECX_COEFF ) ) { - len = imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ); - Copy( pSymbol_re, pPtr_idx, len ); + len = imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ); /*Q0*/ + Copy( pSymbol_re, pPtr_idx, len ); /*Q0*/ pSymbol_re += len; } } @@ -3611,9 +3611,9 @@ static void ivas_fill_band_coeffs_idx( static void ivas_decode_huffman_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - const UWord16 qsi, - const Word16 nB, - const Word16 bands_bw ) + const UWord16 qsi, /*Q0*/ + const Word16 nB, /*Q0*/ + const Word16 bands_bw /*Q0*/ ) { Word16 i, j; Word16 ndm, ndec; @@ -3621,13 +3621,13 @@ static void ivas_decode_huffman_bs( FOR( i = 0; i < nB; i++ ) { - ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[bands_bw * i]; - ndec = hMdDec->spar_md_cfg.num_decorr_per_band[bands_bw * i]; + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[bands_bw * i]; /*Q0*/ + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[bands_bw * i]; /*Q0*/ move16(); move16(); pred_dim = sub( add( ndec, ndm ), 1 ); - drct_dim = imult1616( ndec, sub( ndm, 1 ) ); + drct_dim = imult1616( ndec, sub( ndm, 1 ) ); /*Q0*/ decd_dim = ndec; pred_offset = 0; move16(); @@ -3674,13 +3674,13 @@ static void ivas_decode_huffman_bs( } static void ivas_spar_plc_get_band_age( - const Word16 *valid_bands, - Word16 *base_band_age, - const Word16 num_bands, - Word16 last_valid_band_idx[IVAS_MAX_NUM_BANDS], - Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], - Word16 *all_valid, - Word16 *b_idx ) + const Word16 *valid_bands, /*Q0*/ + Word16 *base_band_age, /*Q0*/ + const Word16 num_bands, /*Q0*/ + Word16 last_valid_band_idx[IVAS_MAX_NUM_BANDS], /*Q0*/ + Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], /*Q0*/ + Word16 *all_valid, /*Q0*/ + Word16 *b_idx /*Q0*/ ) { Word16 b, idx; @@ -3700,7 +3700,7 @@ static void ivas_spar_plc_get_band_age( } ELSE { - base_band_age[b] = add( base_band_age[b], 1 ); /* increment the age of invalid bands */ + base_band_age[b] = add( base_band_age[b], 1 ); /* increment the age of invalid bands */ /*Q0*/ IF( GT_16( base_band_age[b], 3 ) ) { @@ -3751,17 +3751,17 @@ static void ivas_spar_get_plc_interp_weights( #else static void ivas_spar_get_plc_interp_weights_fx( - Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], - Word16 last_valid_band_idx, - Word16 idx, - Word16 b, - Word16 *w, - Word16 *id0, - Word16 *id1 ) + Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], /*Q0*/ + Word16 last_valid_band_idx, /*Q0*/ + Word16 idx, /*Q0*/ + Word16 b, /*Q0*/ + Word16 *w, /*Q15*/ + Word16 *id0, /*Q0*/ + Word16 *id1 /*Q0*/ ) { IF( last_valid_band_idx < 0 ) /* Extrapolation */ { - *id1 = valid_band_idx[0]; + *id1 = valid_band_idx[0]; /*Q0*/ move16(); *id0 = 0; move16(); @@ -3770,18 +3770,18 @@ static void ivas_spar_get_plc_interp_weights_fx( } ELSE IF( EQ_16( last_valid_band_idx, idx ) ) /* Extrapolation */ { - *id1 = valid_band_idx[last_valid_band_idx]; + *id1 = valid_band_idx[last_valid_band_idx]; /*Q0*/ move16(); - *id0 = valid_band_idx[last_valid_band_idx]; + *id0 = valid_band_idx[last_valid_band_idx]; /*Q0*/ move16(); *w = 0; move16(); } ELSE /* Interpolation */ { - *id0 = valid_band_idx[last_valid_band_idx]; + *id0 = valid_band_idx[last_valid_band_idx]; /*Q0*/ move16(); - *id1 = valid_band_idx[last_valid_band_idx + 1]; + *id1 = valid_band_idx[last_valid_band_idx + 1]; /*Q0*/ move16(); IF( sub( b, *id0 ) == 0 ) { @@ -3790,7 +3790,7 @@ static void ivas_spar_get_plc_interp_weights_fx( } ELSE { - *w = divide3232( sub( b, *id0 ), sub( *id1, *id0 ) ); + *w = divide3232( sub( b, *id0 ), sub( *id1, *id0 ) ); /*Q0*/ move16(); } } @@ -3808,11 +3808,11 @@ static void ivas_spar_get_plc_interp_weights_fx( static void ivas_spar_md_fill_invalid_bands_fx( ivas_spar_dec_matrices_t *pSpar_coeffs, ivas_spar_dec_matrices_t *pSpar_coeffs_prev, - const Word16 *valid_bands, - Word16 *base_band_age, - const Word16 num_bands, - const Word16 num_channels, - const Word16 num_md_sub_frames ) + const Word16 *valid_bands, /*Q0*/ + Word16 *base_band_age, /*Q0*/ + const Word16 num_bands, /*Q0*/ + const Word16 num_channels, /*Q0*/ + const Word16 num_md_sub_frames /*Q0*/ ) { Word16 i, j, b, all_valid; Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], idx = -1; @@ -3839,9 +3839,9 @@ static void ivas_spar_md_fill_invalid_bands_fx( { FOR( j = 0; j < num_channels; j++ ) { - pSpar_coeffs->C_re_fx[i][j][b] = L_add( Mpy_32_16_1( pSpar_coeffs->C_re_fx[i][j][id0], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pSpar_coeffs->C_re_fx[i][j][id1], w_fx ) ); + pSpar_coeffs->C_re_fx[i][j][b] = L_add( Mpy_32_16_1( pSpar_coeffs->C_re_fx[i][j][id0], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pSpar_coeffs->C_re_fx[i][j][id1], w_fx ) ); /*Q22*/ move32(); - pSpar_coeffs->P_re_fx[i][j][b] = L_add( Mpy_32_16_1( pSpar_coeffs->P_re_fx[i][j][id0], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pSpar_coeffs->P_re_fx[i][j][id1], w_fx ) ); + pSpar_coeffs->P_re_fx[i][j][b] = L_add( Mpy_32_16_1( pSpar_coeffs->P_re_fx[i][j][id0], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pSpar_coeffs->P_re_fx[i][j][id1], w_fx ) ); /*Q22*/ move32(); } } @@ -3854,9 +3854,9 @@ static void ivas_spar_md_fill_invalid_bands_fx( { FOR( j = 0; j < num_channels; j++ ) { - pSpar_coeffs->C_re_fx[i][j][b] = pSpar_coeffs_prev->C_re_fx[i][j][b]; + pSpar_coeffs->C_re_fx[i][j][b] = pSpar_coeffs_prev->C_re_fx[i][j][b]; /*Q22*/ move32(); - pSpar_coeffs->P_re_fx[i][j][b] = pSpar_coeffs_prev->P_re_fx[i][j][b]; + pSpar_coeffs->P_re_fx[i][j][b] = pSpar_coeffs_prev->P_re_fx[i][j][b]; /*Q22*/ move32(); } } @@ -3872,9 +3872,9 @@ static void ivas_spar_md_fill_invalid_bands_fx( { FOR( i_ts = 1; i_ts < num_md_sub_frames; i_ts++ ) { - pSpar_coeffs->C_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = pSpar_coeffs->C_re_fx[i][j][b]; + pSpar_coeffs->C_re_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = pSpar_coeffs->C_re_fx[i][j][b]; /*Q22*/ move32(); - pSpar_coeffs->P_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = pSpar_coeffs->P_re_fx[i][j][b]; + pSpar_coeffs->P_re_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = pSpar_coeffs->P_re_fx[i][j][b]; /*Q22*/ move32(); } } @@ -3969,10 +3969,10 @@ static void ivas_spar_md_fill_invalid_bands( static void ivas_spar_md_fill_invalid_bandcoeffs( ivas_band_coeffs_t *pBand_coeffs, ivas_band_coeffs_t *pBand_coeffs_prev, - const Word16 *valid_bands, - Word16 *base_band_age, - Word16 *first_valid_frame, - const Word16 num_bands ) + const Word16 *valid_bands, /*Q0*/ + Word16 *base_band_age, /*Q0*/ + Word16 *first_valid_frame, /*Q0*/ + const Word16 num_bands /*Q0*/ ) { Word16 j, k, b, all_valid; Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], idx = -1; @@ -4001,7 +4001,7 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - pBand_coeffs[b].pred_re_fx[j] = L_add( Mpy_32_16_1( pBand_coeffs[id0].pred_re_fx[j], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].pred_re_fx[j], w_fx ) ); + pBand_coeffs[b].pred_re_fx[j] = L_add( Mpy_32_16_1( pBand_coeffs[id0].pred_re_fx[j], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].pred_re_fx[j], w_fx ) ); /*Q22*/ move32(); } @@ -4009,14 +4009,14 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( { FOR( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { - pBand_coeffs[b].C_re_fx[j][k] = L_add( Mpy_32_16_1( pBand_coeffs[id0].C_re_fx[j][k], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].C_re_fx[j][k], w_fx ) ); + pBand_coeffs[b].C_re_fx[j][k] = L_add( Mpy_32_16_1( pBand_coeffs[id0].C_re_fx[j][k], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].C_re_fx[j][k], w_fx ) ); /*Q22*/ move32(); } } FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - pBand_coeffs[b].P_re_fx[j] = L_add( Mpy_32_16_1( pBand_coeffs[id0].P_re_fx[j], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].P_re_fx[j], w_fx ) ); + pBand_coeffs[b].P_re_fx[j] = L_add( Mpy_32_16_1( pBand_coeffs[id0].P_re_fx[j], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].P_re_fx[j], w_fx ) ); /*Q22*/ move32(); } } @@ -4026,7 +4026,7 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( { FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - pBand_coeffs[b].pred_re_fx[j] = pBand_coeffs_prev[b].pred_re_fx[j]; + pBand_coeffs[b].pred_re_fx[j] = pBand_coeffs_prev[b].pred_re_fx[j]; /*Q22*/ move32(); } @@ -4034,14 +4034,14 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( { FOR( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { - pBand_coeffs[b].C_re_fx[j][k] = pBand_coeffs_prev[b].C_re_fx[j][k]; + pBand_coeffs[b].C_re_fx[j][k] = pBand_coeffs_prev[b].C_re_fx[j][k]; /*Q22*/ move32(); } } FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - pBand_coeffs[b].P_re_fx[j] = pBand_coeffs_prev[b].P_re_fx[j]; + pBand_coeffs[b].P_re_fx[j] = pBand_coeffs_prev[b].P_re_fx[j]; /*Q22*/ move32(); } } @@ -4147,13 +4147,13 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( #ifdef IVAS_FLOAT_FIXED static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( ivas_spar_md_dec_state_t *hMdDec, - const Word16 num_bands_out, - const Word16 bfi, - const Word16 num_md_sub_frames ) + const Word16 num_bands_out, /*Q0*/ + const Word16 bfi, /*Q0*/ + const Word16 num_md_sub_frames /*Q0*/ ) { Word16 num_in_ch, num_out_ch, i, j, b; - num_in_ch = hMdDec->spar_md_cfg.num_umx_chs; - num_out_ch = hMdDec->spar_md_cfg.num_umx_chs; + num_in_ch = hMdDec->spar_md_cfg.num_umx_chs; /*Q0*/ + num_out_ch = hMdDec->spar_md_cfg.num_umx_chs; /*Q0*/ move16(); move16(); IF( bfi == 0 ) @@ -4170,7 +4170,7 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( hMdDec->spar_plc_num_lost_frames = add( hMdDec->spar_plc_num_lost_frames, 1 ); move16(); - hMdDec->spar_plc_num_lost_frames = s_min( hMdDec->spar_plc_num_lost_frames, 100 ); /*hMdDec->spar_plc_num_lost_frames is always <=100*/ + hMdDec->spar_plc_num_lost_frames = s_min( hMdDec->spar_plc_num_lost_frames, 100 ); /*hMdDec->spar_plc_num_lost_frames is always <=100*/ /*Q0*/ move16(); IF( GT_16( hMdDec->spar_plc_num_lost_frames, ivas_spar_dec_plc_num_frames_keep ) ) /*if control enters then ivas_spar_dec_plc_num_frames_keep<100 */ @@ -4186,8 +4186,8 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( norm_nff = norm_s( num_fade_frames ); gain_dB = negate( imult1616( s_min( num_fade_frames, ivas_spar_dec_plc_max_num_frames_ramp_down ), ivas_spar_dec_plc_per_frame_ramp_down_gain_dB ) ); /*abs(gain_dB)<99*/ /*Q(gain_dB)=7Q24*/ Word16 exp_gain = 0; - move16(); /*stores exponent for gain_fx*/ - gain_fx = BASOP_util_Pow2( Mult_32_16( imult3216( 13421773 /*=2^28/20*/, gain_dB ), 27213 /*=log2(10)*2^13*/ ), 5, &exp_gain ); + move16(); /*stores exponent for gain_fx*/ + gain_fx = BASOP_util_Pow2( Mult_32_16( imult3216( 13421773 /*=2^28/20*/, gain_dB ), 27213 /*=log2(10)*2^13*/ ), 5, &exp_gain ); /*Q_gain*/ Q_gain = sub( 31, exp_gain ); FOR( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) { @@ -4208,7 +4208,7 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl( Mult_32_32( hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], post_matrix_fx[i] ), sub( Q30, hMdDec->Q_mixer_mat ) ); // Q30 + hMdDec->mixer_mat_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_shl( Mult_32_32( hMdDec->mixer_mat_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], post_matrix_fx[i] ), sub( Q30, hMdDec->Q_mixer_mat ) ); // Q30 move32(); } } @@ -4294,9 +4294,9 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix( #ifdef IVAS_FLOAT_FIXED static void ivas_spar_unquant_dtx_indicies( ivas_spar_md_t *pSpar_md, - const Word16 nB, - const Word16 bw, - Word16 *ndm_per_band ) + const Word16 nB, /*Q0*/ + const Word16 bw, /*Q0*/ + Word16 *ndm_per_band /*Q0*/ ) { Word16 i, b; Word16 q_lvl; @@ -4304,34 +4304,34 @@ static void ivas_spar_unquant_dtx_indicies( Word16 idx; Word32 pr_min_max_fx[2]; - pr_min_max_fx[0] = pSpar_md->min_max_fx[0]; + pr_min_max_fx[0] = pSpar_md->min_max_fx[0]; /*Q28*/ move32(); - pr_min_max_fx[1] = pSpar_md->min_max_fx[1]; + pr_min_max_fx[1] = pSpar_md->min_max_fx[1]; /*Q28*/ move32(); FOR( b = 0; b < nB; b++ ) { FOR( i = 0; i < FOA_CHANNELS - 1; i++ ) { - q_lvl = dtx_pr_real_q_levels[sub( ndm_per_band[i_mult( bw, b )], 1 )][i]; + q_lvl = dtx_pr_real_q_levels[( ndm_per_band[( bw * b )] - 1 )][i]; /*Q0*/ move16(); - idx = pSpar_md->band_coeffs_idx[b].pred_index_re[i]; + idx = pSpar_md->band_coeffs_idx[b].pred_index_re[i]; /*Q0*/ move16(); ivas_deindex_real_index_fx( &idx, q_lvl, pr_min_max_fx[0], pr_min_max_fx[1], &val_fx, 1 ); - pSpar_md->band_coeffs[b].pred_re_fx[i] = val_fx; + pSpar_md->band_coeffs[b].pred_re_fx[i] = val_fx; /*Q22*/ move32(); } - FOR( i = 0; i < sub( FOA_CHANNELS, ndm_per_band[i_mult( bw, b )] ); i++ ) + FOR( i = 0; i < ( FOA_CHANNELS - ndm_per_band[( bw - b )] ); i++ ) { - q_lvl = dtx_pd_real_q_levels[sub( ndm_per_band[i_mult( bw, b )], 1 )][i]; + q_lvl = dtx_pd_real_q_levels[( ndm_per_band[( bw * b )] - 1 )][i]; /*Q0*/ move16(); - idx = pSpar_md->band_coeffs_idx[b].decd_index_re[i]; + idx = pSpar_md->band_coeffs_idx[b].decd_index_re[i]; /*Q0*/ move16(); ivas_deindex_real_index_fx( &idx, q_lvl, dtx_pd_real_min_max_fx[0], dtx_pd_real_min_max_fx[1], &val_fx, 1 ); - pSpar_md->band_coeffs[b].P_re_fx[i] = val_fx; + pSpar_md->band_coeffs[b].P_re_fx[i] = val_fx; /*Q22*/ move32(); } } @@ -4385,11 +4385,11 @@ static void ivas_spar_unquant_dtx_indicies( #ifdef IVAS_FLOAT_FIXED static void ivas_parse_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, - Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - const Word16 bw, - const Word16 num_bands, - Word16 *num_dmx_per_band, - Word16 *num_dec_per_band ) + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ + const Word16 bw, /*Q0*/ + const Word16 num_bands, /*Q0*/ + Word16 *num_dmx_per_band, /*Q0*/ + Word16 *num_dec_per_band /*Q0*/ ) { Word16 i, j, ndec, ndm; Word32 val_fx; @@ -4398,18 +4398,18 @@ static void ivas_parse_parameter_bitstream_dtx( Word16 pr_q_lvls, pr, pd, pd_q_lvls, pr_pd_bits; Word16 zero_pad_bits, sid_bits_len; - sid_bits_len = st0->next_bit_pos; + sid_bits_len = st0->next_bit_pos; /*Q0*/ move16(); - pr_min_max_fx[0] = pSpar_md->min_max_fx[0]; + pr_min_max_fx[0] = pSpar_md->min_max_fx[0]; /*Q28*/ move32(); - pr_min_max_fx[1] = pSpar_md->min_max_fx[1]; + pr_min_max_fx[1] = pSpar_md->min_max_fx[1]; /*Q28*/ move32(); FOR( i = 0; i < num_bands; i++ ) { - ndec = num_dec_per_band[i_mult( bw, i )]; + ndec = num_dec_per_band[( bw * i )]; move16(); - ndm = num_dmx_per_band[i_mult( bw, i )]; + ndm = num_dmx_per_band[( bw * i )]; move16(); FOR( j = 0; j < FOA_CHANNELS - 1; j++ ) @@ -4417,13 +4417,13 @@ static void ivas_parse_parameter_bitstream_dtx( Word16 pr_idx_1, pr_idx_2, pd_idx_1, pd_idx_2; UWord16 value; - pr_idx_1 = pr_pr_idx_pairs[ndm - 1][j][0]; + pr_idx_1 = pr_pr_idx_pairs[ndm - 1][j][0]; /*Q0*/ move16(); - pr_idx_2 = pr_pr_idx_pairs[ndm - 1][j][1]; + pr_idx_2 = pr_pr_idx_pairs[ndm - 1][j][1]; /*Q0*/ move16(); - pd_idx_1 = pr_pd_idx_pairs[ndm - 1][j][0]; + pd_idx_1 = pr_pd_idx_pairs[ndm - 1][j][0]; /*Q0*/ move16(); - pd_idx_2 = pr_pd_idx_pairs[ndm - 1][j][1]; + pd_idx_2 = pr_pd_idx_pairs[ndm - 1][j][1]; /*Q0*/ move16(); test(); @@ -4431,7 +4431,7 @@ static void ivas_parse_parameter_bitstream_dtx( test(); IF( pr_idx_1 != 0 || pd_idx_1 != 0 || pr_idx_2 != 0 || pd_idx_2 != 0 ) { - pr_q_lvls = dtx_pr_real_q_levels[ndm - 1][pd_idx_1 - 1]; + pr_q_lvls = dtx_pr_real_q_levels[ndm - 1][pd_idx_1 - 1]; /*Q0*/ move16(); IF( GT_16( add( j, 1 ), ndec ) ) @@ -4441,17 +4441,17 @@ static void ivas_parse_parameter_bitstream_dtx( } ELSE { - pd_q_lvls = dtx_pd_real_q_levels[ndm - 1][pd_idx_2 - 1]; + pd_q_lvls = dtx_pd_real_q_levels[ndm - 1][pd_idx_2 - 1]; /*Q0*/ move16(); } - pr_pd_bits = ivas_get_bits_to_encode( L_mult0( pd_q_lvls, pr_q_lvls ) ); + pr_pd_bits = ivas_get_bits_to_encode( L_mult0( pd_q_lvls, pr_q_lvls ) ); /*Q0*/ - value = get_next_indice_fx( st0, pr_pd_bits ); + value = get_next_indice_fx( st0, pr_pd_bits ); /*Q0*/ IF( value != 0 ) { - pr = idiv1616( value, pd_q_lvls ); + pr = idiv1616( value, pd_q_lvls ); /*Q0*/ } ELSE { @@ -4459,23 +4459,23 @@ static void ivas_parse_parameter_bitstream_dtx( move16(); } pd = extract_l( L_sub( value, i_mult( pr, pd_q_lvls ) ) ); - val_fx = dtx_pd_real_min_max_fx[0]; + val_fx = dtx_pd_real_min_max_fx[0]; /*Q0*/ move32(); ivas_quantise_real_values_fx( &val_fx, pd_q_lvls, dtx_pd_real_min_max_fx[0], dtx_pd_real_min_max_fx[1], &idx, &val_fx, 1 ); pd = add( pd, idx ); - val_fx = pr_min_max_fx[0]; + val_fx = pr_min_max_fx[0]; /*Q28*/ move32(); ivas_quantise_real_values_fx( &val_fx, pr_q_lvls, pr_min_max_fx[0], pr_min_max_fx[1], &idx, &val_fx, 1 ); pr = add( pr, idx ); if ( LE_16( add( j, 1 ), ndec ) ) { - pSpar_md->band_coeffs_idx[i].decd_index_re[pd_idx_2 - 1] = pd; + pSpar_md->band_coeffs_idx[i].decd_index_re[pd_idx_2 - 1] = pd; /*Q0*/ move16(); } - pSpar_md->band_coeffs_idx[i].pred_index_re[pd_idx_1 - 1] = pr; + pSpar_md->band_coeffs_idx[i].pred_index_re[pd_idx_1 - 1] = pr; /*Q0*/ move16(); } } @@ -4633,12 +4633,12 @@ static ivas_error ivas_deindex_real_index( #else static ivas_error ivas_deindex_real_index_fx( - const Word16 *index, - const Word16 q_levels, - const Word32 min_value, - const Word32 max_value, - Word32 *quant, - const Word16 dim ) + const Word16 *index, /*Q0*/ + const Word16 q_levels, /*Q0*/ + const Word32 min_value, /*Q28*/ + const Word32 max_value, /*Q28*/ + Word32 *quant, /*Q22*/ + const Word16 dim /*Q0*/ ) { Word16 i; Word32 q_step_fx; @@ -4658,7 +4658,7 @@ static ivas_error ivas_deindex_real_index_fx( ELSE { q_step_fx = L_sub( max_value, min_value ); - q_step_fx = Mpy_32_32( q_step_fx, one_by_q_level[q_levels - 1] ); + q_step_fx = Mpy_32_32( q_step_fx, one_by_q_level[q_levels - 1] /*Q31*/ ); /*Q28*/ FOR( i = 0; i < dim; i++ ) { quant[i] = Mpy_32_32( L_shl( index[i], 31 - 6 ), q_step_fx ); //(25+28)-31 = 22 @@ -4949,10 +4949,10 @@ void ivas_spar_to_dirac( #else void ivas_spar_to_dirac_fx( Decoder_Struct *st_ivas, - ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 dtx_vad, /* i : DTX frame flag */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 bw, /* i : band joining factor */ + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle Q0*/ + const Word16 dtx_vad, /* i : DTX frame flag Q0*/ + const Word16 num_bands_out, /* i : number of output bands Q0*/ + const Word16 bw, /* i : band joining factor Q0*/ const Word16 dyn_active_w_flag ) { DIRAC_DEC_HANDLE hDirAC; @@ -4994,17 +4994,17 @@ void ivas_spar_to_dirac_fx( move16(); start_band = 0; move16(); - end_band = idiv1616( s_min( num_bands_out, SPAR_DIRAC_SPLIT_START_BAND ), bw ); + end_band = idiv1616( s_min( num_bands_out, SPAR_DIRAC_SPLIT_START_BAND ), bw ); /*Q0*/ hDirAC = st_ivas->hDirAC; hSpatParamRendCom = st_ivas->hSpatParamRendCom; - dirac_to_spar_md_bands = st_ivas->hSpar->dirac_to_spar_md_bands; + dirac_to_spar_md_bands = st_ivas->hSpar->dirac_to_spar_md_bands; /*Q0*/ move16(); IF( st_ivas->hSpar->enc_param_start_band > 0 ) { - enc_param_start_band = idiv1616( st_ivas->hSpar->enc_param_start_band, bw ); + enc_param_start_band = idiv1616( st_ivas->hSpar->enc_param_start_band, bw ); /*Q0*/ } ELSE { @@ -5044,13 +5044,13 @@ void ivas_spar_to_dirac_fx( Word32 PR_fx[3], Pd_fx[3], dvnorm_fx, g_pred_fx; Word16 q_g_pred; Word16 q_dvnorm; - PR_fx[0] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[2]; + PR_fx[0] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[2]; /*Q22*/ move32(); - PR_fx[1] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[0]; + PR_fx[1] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[0]; /*Q22*/ move32(); - PR_fx[2] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[1]; + PR_fx[2] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[1]; /*Q22*/ move32(); - g_pred_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); + g_pred_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); /*q_g_pred*/ q_g_pred = Q22 + Q22 - Q31; move16(); q_dvnorm = sub( Q31, q_g_pred ); @@ -5058,7 +5058,7 @@ void ivas_spar_to_dirac_fx( move16(); IF( LE_32( g_pred_fx, EPSILON_FIX ) ) { - dvx_fx[band] = ONE_IN_Q22; + dvx_fx[band] = ONE_IN_Q22; /*Q22*/ move32(); dvy_fx[band] = 0; move32(); @@ -5076,8 +5076,8 @@ void ivas_spar_to_dirac_fx( } ELSE { - dvnorm_fx = ISqrt32( g_pred_fx, &q_dvnorm ); - g_pred_fx = Sqrt32( g_pred_fx, &q_g_pred ); + dvnorm_fx = ISqrt32( g_pred_fx, &q_dvnorm ); /*Q31 - q_dvnorm*/ + g_pred_fx = Sqrt32( g_pred_fx, &q_g_pred ); /*Q31 - q_g_pred*/ IF( q_g_pred < 0 ) { g_pred_fx = L_shr( g_pred_fx, negate( q_g_pred ) ); @@ -5085,70 +5085,70 @@ void ivas_spar_to_dirac_fx( move16(); } - dvx_fx[band] = Mpy_32_32( PR_fx[0], dvnorm_fx ); + dvx_fx[band] = Mpy_32_32( PR_fx[0], dvnorm_fx ); /*q_1*/ move32(); - dvy_fx[band] = Mpy_32_32( PR_fx[1], dvnorm_fx ); + dvy_fx[band] = Mpy_32_32( PR_fx[1], dvnorm_fx ); /*q_1*/ move32(); - dvz_fx[band] = Mpy_32_32( PR_fx[2], dvnorm_fx ); + dvz_fx[band] = Mpy_32_32( PR_fx[2], dvnorm_fx ); /*q_1*/ move32(); Word16 q_1 = sub( add( 22, sub( 31, q_dvnorm ) ), 31 ); - Word32 temp = L_add( Mpy_32_32( dvx_fx[band], dvx_fx[band] ), Mpy_32_32( dvy_fx[band], dvy_fx[band] ) ); + Word32 temp = L_add( Mpy_32_32( dvx_fx[band], dvx_fx[band] ), Mpy_32_32( dvy_fx[band], dvy_fx[band] ) ); /*q2*/ Word16 q2 = sub( add( q_1, q_1 ), 31 ); Word16 q_temp = sub( 31, q2 ); radius_fx = Sqrt32( temp, &q_temp ); - Word16 check_azi_fx = BASOP_util_atan2( dvy_fx[band], dvx_fx[band], 0 ); - Word32 check_azi_fx_32 = L_shl( check_azi_fx, 16 ); + Word16 check_azi_fx = BASOP_util_atan2( dvy_fx[band], dvx_fx[band], 0 ); /*Q13*/ + Word32 check_azi_fx_32 = L_shl( check_azi_fx, 16 ); /*Q29*/ Word16 check_azi_fx_res; IF( check_azi_fx_32 < 0 ) { - check_azi_fx_res = negate( divide3232( L_negate( check_azi_fx_32 ), 1686629760 ) ); + check_azi_fx_res = negate( divide3232( L_negate( check_azi_fx_32 ), 1686629760 /*3.145f in Q29*/ ) ); /*Q15*/ } ELSE { - check_azi_fx_res = divide3232( check_azi_fx_32, 1686629760 ); + check_azi_fx_res = divide3232( check_azi_fx_32, 1686629760 /*3.145f in Q29*/ ); /*Q15*/ } - Word32 azi_intermediate = Mpy_32_16_1( DEGREE_180_Q_22, check_azi_fx_res ); - azi_intermediate = L_add( azi_intermediate, ONE_IN_Q21 ); + Word32 azi_intermediate = Mpy_32_16_1( DEGREE_180_Q_22, check_azi_fx_res ); /*Q22*/ + azi_intermediate = L_add( azi_intermediate, ONE_IN_Q21 ); /*Q22*/ Word16 azi_res; IF( azi_intermediate < 0 ) { - azi_res = negate( extract_l( L_shr( L_negate( azi_intermediate ), 22 ) ) ); + azi_res = negate( extract_l( L_shr( L_negate( azi_intermediate ), 22 ) ) ); /*Q0*/ } ELSE { - azi_res = extract_l( L_shr( azi_intermediate, 22 ) ); + azi_res = extract_l( L_shr( azi_intermediate, 22 ) ); /*Q0*/ } - Word16 check_ele_fx = BASOP_util_atan2( dvz_fx[band], radius_fx, sub( add( 9, q_dvnorm ), q_temp ) ); - Word32 check_ele_fx_32 = L_shl( check_ele_fx, 16 ); + Word16 check_ele_fx = BASOP_util_atan2( dvz_fx[band], radius_fx, sub( add( 9, q_dvnorm ), q_temp ) ); /*Q13*/ + Word32 check_ele_fx_32 = L_shl( check_ele_fx, 16 ); /*Q29*/ Word16 check_ele_fx_res; IF( check_azi_fx_32 < 0 ) { - check_ele_fx_res = negate( divide3232( L_negate( check_ele_fx_32 ), 1686629760 ) ); + check_ele_fx_res = negate( divide3232( L_negate( check_ele_fx_32 ), 1686629760 /*3.145f in Q29*/ ) ); /*Q15*/ } ELSE { - check_ele_fx_res = divide3232( check_ele_fx_32, 1686629760 ); + check_ele_fx_res = divide3232( check_ele_fx_32, 1686629760 /*3.145f in Q29*/ ); /*Q15*/ } - Word32 ele_intermediate = Mpy_32_16_1( DEGREE_180_Q_22, check_ele_fx_res ); - ele_intermediate = L_add( ele_intermediate, ONE_IN_Q21 ); + Word32 ele_intermediate = Mpy_32_16_1( DEGREE_180_Q_22, check_ele_fx_res ); /*Q22*/ + ele_intermediate = L_add( ele_intermediate, ONE_IN_Q21 ); /*Q22*/ Word16 ele_res; IF( ele_intermediate < 0 ) { - ele_res = negate( extract_l( L_shr( L_negate( ele_intermediate ), 22 ) ) ); + ele_res = negate( extract_l( L_shr( L_negate( ele_intermediate ), 22 ) ) ); /*Q0*/ } ELSE { - ele_res = extract_l( L_shr( ele_intermediate, 22 ) ); + ele_res = extract_l( L_shr( ele_intermediate, 22 ) ); /*Q0*/ } - azi[band] = s_max( -180, s_min( 180, azi_res ) ); + azi[band] = s_max( -180, s_min( 180, azi_res ) ); /*Q0*/ move16(); - ele[band] = s_max( -90, s_min( 180, ele_res ) ); + ele[band] = s_max( -90, s_min( 180, ele_res ) ); /*Q0*/ move16(); } @@ -5160,19 +5160,19 @@ void ivas_spar_to_dirac_fx( { IF( dtx_vad == 0 ) { - f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; + f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; /*Q31*/ move32(); } ELSE { IF( active_w_vlbr ) { - f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX; + f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX; /*Q31*/ move32(); } ELSE { - f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_FX; + f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_FX; /*Q31*/ move32(); } } @@ -5183,42 +5183,42 @@ void ivas_spar_to_dirac_fx( move32(); } - Word32 temp_result = Mpy_32_32( Mpy_32_32( f_scale_fx, g_pred_fx ), g_pred_fx ); + Word32 temp_result = Mpy_32_32( Mpy_32_32( f_scale_fx, g_pred_fx ), g_pred_fx ); /*Q31 - q_g_pred*/ temp_result = L_sub( L_shr( ONE_IN_Q31, q_g_pred ), temp_result ); - w_en_norm_fx = Mpy_32_32( temp_result, temp_result ); + w_en_norm_fx = Mpy_32_32( temp_result, temp_result ); /*q_w_en_norm_fx*/ q_w_en_norm_fx = add( q_g_pred, q_g_pred ); - Pd_fx[0] = hMdDec->spar_md.band_coeffs[band].P_re_fx[1]; + Pd_fx[0] = hMdDec->spar_md.band_coeffs[band].P_re_fx[1]; /*Q22*/ move32(); - Pd_fx[1] = hMdDec->spar_md.band_coeffs[band].P_re_fx[0]; + Pd_fx[1] = hMdDec->spar_md.band_coeffs[band].P_re_fx[0]; /*Q22*/ move32(); - Pd_fx[2] = hMdDec->spar_md.band_coeffs[band].P_re_fx[2]; + Pd_fx[2] = hMdDec->spar_md.band_coeffs[band].P_re_fx[2]; /*Q22*/ move32(); en_ratio_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); // 22+22-31 = 13 Word32 Pd_temp_res = L_add( L_add( Mpy_32_32( Pd_fx[0], Pd_fx[0] ), Mpy_32_32( Pd_fx[1], Pd_fx[1] ) ), Mpy_32_32( Pd_fx[2], Pd_fx[2] ) ); // q = 22+22-31 = 13 - res_pow_fx = L_add( L_shr( w_en_norm_fx, sub( sub( 31, q_w_en_norm_fx ), 13 ) ), L_add( en_ratio_fx, Pd_temp_res ) ); + res_pow_fx = L_add( L_shr( w_en_norm_fx, sub( sub( 31, q_w_en_norm_fx ), 13 ) ), L_add( en_ratio_fx, Pd_temp_res ) ); /*Q13*/ - res_pow_fx = L_shr( res_pow_fx, 1 ); + res_pow_fx = L_shr( res_pow_fx, 1 ); /*Q13*/ - hMdDec->spar_md.en_ratio_slow_fx[band] = L_add( Mpy_32_32( 1610612736, hMdDec->spar_md.en_ratio_slow_fx[band] ), Mpy_32_32( 536870912, en_ratio_fx ) ); + hMdDec->spar_md.en_ratio_slow_fx[band] = L_add( Mpy_32_32( 1610612736 /*0.75f in Q31*/, hMdDec->spar_md.en_ratio_slow_fx[band] ), Mpy_32_32( 536870912 /*0.25f in Q31*/, en_ratio_fx ) ); /*Q13*/ move32(); - hMdDec->spar_md.ref_pow_slow_fx[band] = L_add( Mpy_32_32( 1610612736, hMdDec->spar_md.ref_pow_slow_fx[band] ), Mpy_32_32( 536870912, res_pow_fx ) ); + hMdDec->spar_md.ref_pow_slow_fx[band] = L_add( Mpy_32_32( 1610612736 /*0.75f in Q31*/, hMdDec->spar_md.ref_pow_slow_fx[band] ), Mpy_32_32( 536870912 /*0.25f in Q31*/, res_pow_fx ) ); /*Q13*/ move32(); en_ratio_q = 31 - 13; move16(); - en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q ); + en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q ); /*Q31 - en_ratio_q*/ IF( en_ratio_q < 0 ) { - en_ratio_fx = L_shr( en_ratio_fx, negate( en_ratio_q ) ); + en_ratio_fx = L_shr( en_ratio_fx, negate( en_ratio_q ) ); /*Q31*/ en_ratio_q = 0; move16(); } - Word32 en_ratio_fx_scaled = L_shr( en_ratio_fx, ( sub( sub( 31, en_ratio_q ), 13 ) ) ); + Word32 en_ratio_fx_scaled = L_shr( en_ratio_fx, ( sub( sub( 31, en_ratio_q ), 13 ) ) ); /*Q13*/ IF( GT_32( en_ratio_fx_scaled, hMdDec->spar_md.ref_pow_slow_fx[band] ) ) { diffuseness_fx[band] = 0; @@ -5226,39 +5226,39 @@ void ivas_spar_to_dirac_fx( } ELSE IF( en_ratio_fx_scaled == 0 ) { - diffuseness_fx[band] = ONE_IN_Q30; + diffuseness_fx[band] = ONE_IN_Q30; /*1.0f in Q30*/ move32(); } ELSE IF( EQ_32( en_ratio_fx_scaled, hMdDec->spar_md.ref_pow_slow_fx[band] ) ) { - diffuseness_fx[band] = ONE_IN_Q30; + diffuseness_fx[band] = ONE_IN_Q30; /*1.0f in Q30*/ move32(); } ELSE { - en_ratio_fx = divide3232( en_ratio_fx_scaled, L_add( hMdDec->spar_md.ref_pow_slow_fx[band], EPSILON_FX ) ); - en_ratio_fx = L_shl( en_ratio_fx, 15 ); + en_ratio_fx = divide3232( en_ratio_fx_scaled, L_add( hMdDec->spar_md.ref_pow_slow_fx[band], EPSILON_FX ) ); /*Q15*/ + en_ratio_fx = L_shl( en_ratio_fx, 15 ); /*Q30*/ diffuseness_fx[band] = L_sub( ONE_IN_Q30, en_ratio_fx ); move32(); } } ELSE { - en_ratio_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); + en_ratio_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); /*Q13*/ - hMdDec->spar_md.en_ratio_slow_fx[band] = L_add( Mpy_32_32( 1610612736, hMdDec->spar_md.en_ratio_slow_fx[band] ), Mpy_32_32( 536870912, en_ratio_fx ) ); + hMdDec->spar_md.en_ratio_slow_fx[band] = L_add( Mpy_32_32( 1610612736 /*0.75f in Q31*/, hMdDec->spar_md.en_ratio_slow_fx[band] ), Mpy_32_32( 536870912 /*0.25f in Q31*/, en_ratio_fx ) ); move32(); en_ratio_q = 31 - 13; move16(); - en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q ); + en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q ); /*Q31 - en_ratio_q*/ IF( en_ratio_q < 0 ) { - en_ratio_fx = L_shr( en_ratio_fx, ( -en_ratio_q ) ); + en_ratio_fx = L_shr( en_ratio_fx, ( -en_ratio_q ) ); /*Q31*/ en_ratio_q = 0; move16(); } - Word32 en_ratio_fx_scaled = L_shr( en_ratio_fx, 1 ); + Word32 en_ratio_fx_scaled = L_shr( en_ratio_fx, 1 ); /*Q30*/ IF( GT_32( en_ratio_fx_scaled, ONE_IN_Q30 ) ) { diffuseness_fx[band] = 0; @@ -5266,7 +5266,7 @@ void ivas_spar_to_dirac_fx( } ELSE { - diffuseness_fx[band] = L_sub( ONE_IN_Q30, en_ratio_fx_scaled ); + diffuseness_fx[band] = L_sub( ONE_IN_Q30, en_ratio_fx_scaled ); /*Q30*/ move32(); } } @@ -5278,60 +5278,60 @@ void ivas_spar_to_dirac_fx( tmp_write_idx_param_band = hDirAC->spar_to_dirac_write_idx; move16(); - en_ratio_fx = L_sub( ONE_IN_Q30, diffuseness_fx[band] ); + en_ratio_fx = L_sub( ONE_IN_Q30, diffuseness_fx[band] ); /*Q30*/ masa_sq_fx( L_sub( ONE_IN_Q30, en_ratio_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); - qmf_band_start = band_grouping[band]; + qmf_band_start = band_grouping[band]; /*Q0*/ move16(); - qmf_band_end = band_grouping[band + 1]; + qmf_band_end = band_grouping[band + 1]; /*Q0*/ move16(); FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { Word16 ts_start, ts_end, ts; - ts_start = DirAC_block_grouping[block]; + ts_start = DirAC_block_grouping[block]; /*Q0*/ move16(); ts_end = DirAC_block_grouping[block + 1]; move16(); - FOR( b = qmf_band_start; b < qmf_band_end; b++ ) + FOR( b = qmf_band_start; b < qmf_band_end; b++ ) /*Q0*/ { - azi_dith = azi[band]; + azi_dith = azi[band]; /*Q0*/ move16(); - ele_dith = ele[band]; + ele_dith = ele[band]; /*Q0*/ move16(); - hSpatParamRendCom->energy_ratio1_fx[block][b] = en_ratio_fx; + hSpatParamRendCom->energy_ratio1_fx[block][b] = en_ratio_fx; /*Q30*/ move32(); - tmp_write_idx_band = tmp_write_idx_param_band; + tmp_write_idx_band = tmp_write_idx_param_band; /*Q0*/ move16(); IF( hDirAC->hConfig->dec_param_estim == FALSE ) { - hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; /*Q0*/ move16(); - hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; /*Q0*/ move16(); - hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; + hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; /*Q30*/ move32(); } ELSE { FOR( ts = ts_start; ts < ts_end; ts++ ) { - hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; /*Q0*/ move16(); - hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; /*Q0*/ move16(); - hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; + hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; /*Q30*/ move32(); - tmp_write_idx_band = add( tmp_write_idx_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length; + tmp_write_idx_band = add( tmp_write_idx_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length; /*Q0*/ move16(); } } @@ -5344,12 +5344,12 @@ void ivas_spar_to_dirac_fx( /* update buffer write index */ IF( hDirAC->hConfig->dec_param_estim == FALSE ) { - hDirAC->spar_to_dirac_write_idx = add( hDirAC->spar_to_dirac_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; + hDirAC->spar_to_dirac_write_idx = add( hDirAC->spar_to_dirac_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; /*Q0*/ move16(); } ELSE { - hDirAC->spar_to_dirac_write_idx = add( hDirAC->spar_to_dirac_write_idx, CLDFB_NO_COL_MAX ) % hSpatParamRendCom->dirac_md_buffer_length; + hDirAC->spar_to_dirac_write_idx = add( hDirAC->spar_to_dirac_write_idx, CLDFB_NO_COL_MAX ) % hSpatParamRendCom->dirac_md_buffer_length; /*Q0*/ move16(); } } @@ -5364,7 +5364,7 @@ void ivas_spar_to_dirac_fx( { Word16 dirac_band_idx; - dirac_band_idx = sub( dirac_to_spar_md_bands[band], enc_param_start_band ); + dirac_band_idx = sub( dirac_to_spar_md_bands[band], enc_param_start_band ); /*Q0*/ num_subframes = MAX_PARAM_SPATIAL_SUBFRAMES; move16(); @@ -5380,17 +5380,17 @@ void ivas_spar_to_dirac_fx( IF( st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] < 0 ) { st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] = - L_add( L_shl( 360, 22 ), st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] ); + L_add( L_shl( 360, 22 ), st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] ); /*Q22*/ move32(); } - azi_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block]; + azi_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block]; /*Q22*/ move32(); - ele_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation_fx[block]; + ele_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation_fx[block]; /*Q22*/ move32(); } - diffuseness_fx[band] = L_sub( ONE_IN_Q30, st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0] ); + diffuseness_fx[band] = L_sub( ONE_IN_Q30, st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0] ); /*Q30*/ move32(); } @@ -5415,7 +5415,7 @@ void ivas_spar_to_dirac_fx( { FOR( band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++ ) { - pred_re_20ms_fx[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[pred_idx]; + pred_re_20ms_fx[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[pred_idx]; /*Q22*/ move32(); } } @@ -5446,12 +5446,12 @@ void ivas_spar_to_dirac_fx( { FOR( i = 0; i < FOA_CHANNELS - 1; i++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ { - hMdDec->spar_md.band_coeffs[add( band, i_mult( block, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[i]; + hMdDec->spar_md.band_coeffs[( band + ( block * IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[i]; /*Q22*/ move32(); } FOR( i = 0; i < FOA_CHANNELS - 1; i++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ { - hMdDec->spar_md.band_coeffs[add( band, i_mult( block, IVAS_MAX_NUM_BANDS ) )].P_re_fx[i] = hMdDec->spar_md.band_coeffs[band].P_re_fx[i]; + hMdDec->spar_md.band_coeffs[( band + ( block * IVAS_MAX_NUM_BANDS ) )].P_re_fx[i] = hMdDec->spar_md.band_coeffs[band].P_re_fx[i]; /*Q22*/ move32(); } } @@ -5468,7 +5468,7 @@ void ivas_spar_to_dirac_fx( IF( ivas_is_res_channel( add( pred_idx, 1 ), hMdDec->spar_md_cfg.nchan_transport ) ) { /* use 20ms coefficients only for residual channels */ - hMdDec->spar_md.band_coeffs[add( band, i_mult( block, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[pred_idx] = pred_re_20ms_fx[band][pred_idx]; + hMdDec->spar_md.band_coeffs[( band + ( block * IVAS_MAX_NUM_BANDS ) )].pred_re_fx[pred_idx] = pred_re_20ms_fx[band][pred_idx]; /*Q22*/ move32(); } } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 4575cf543928342a86540aee792b2d0767bed53b..07d7fd3c5d80952316f11882d816eb4eafc7fc03 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -312,13 +312,13 @@ typedef struct stereo_dft_dec_data_struct #ifdef IVAS_FLOAT_FIXED Word32 smooth_dmx_nrg_fx[STEREO_DFT_BAND_MAX]; /* Q(q_smoothed_nrg) */ Word32 smooth_res_nrg_fx[STEREO_DFT_BAND_MAX]; /* Q(q_smoothed_nrg) */ - Word32 td_gain_fx[STEREO_DFT_CORE_HIST_MAX]; + Word32 td_gain_fx[STEREO_DFT_CORE_HIST_MAX]; /* Q(q_td_gain) */ #endif #ifdef IVAS_FLOAT_FIXED - Word32 hb_stefi_sig_fx[L_FRAME48k + NS2SA( 48000, STEREO_DFT_TD_STEFI_DELAY_NS )]; - Word32 hb_nrg_fx[STEREO_DFT_CORE_HIST_MAX]; - Word32 hb_nrg_subr_fx[STEREO_DFT_NBDIV]; + Word32 hb_stefi_sig_fx[L_FRAME48k + NS2SA( 48000, STEREO_DFT_TD_STEFI_DELAY_NS )]; /* Q(q_hb_stefi_sig_fx) */ + Word32 hb_nrg_fx[STEREO_DFT_CORE_HIST_MAX]; /* Q(q_hb_nrg) */ + Word32 hb_nrg_subr_fx[STEREO_DFT_NBDIV]; /* Q(q_hb_nrg_subr) */ Word16 Q_nrg_subr; Word16 prev_Q_stefi_sig; @@ -700,10 +700,10 @@ typedef struct param_ism_rendering { #ifdef IVAS_FLOAT_FIXED Word16 *proto_matrix_fx; - Word16 *interpolator_fx; /* Q15 */ - Word32 *Cldfb_RealBuffer_tc_fx; + Word16 *interpolator_fx; /* Q15 */ + Word32 *Cldfb_RealBuffer_tc_fx; /* Q31 - Cldfb_RealBuffer_tc_exp */ Word16 Cldfb_RealBuffer_tc_exp; - Word32 *Cldfb_ImagBuffer_tc_fx; + Word32 *Cldfb_ImagBuffer_tc_fx; /* Q31 - Cldfb_ImagBuffer_tc_exp */ Word16 Cldfb_ImagBuffer_tc_exp; Word32 mixing_matrix_lin_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX]; Word16 exp_mixing_matrix_lin_fx[CLDFB_NO_CHANNELS_MAX]; @@ -1263,10 +1263,10 @@ typedef struct ivas_lfe_dec_data_structure typedef struct renderer_struct { #ifdef IVAS_FLOAT_FIXED - Word32 prev_gains_fx[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; - Word16 *interpolator_fx; + Word32 prev_gains_fx[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; /*Q30*/ + Word16 *interpolator_fx; /*Q15*/ Word16 interpolator_len; - Word32 gains_fx[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; + Word32 gains_fx[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; /*Q30*/ #else float prev_gains[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; float *interpolator; @@ -1285,7 +1285,7 @@ typedef struct ivas_binaural_rendering_struct #ifndef IVAS_FLOAT_FIXED float *hoa_dec_mtx; /* pointer to HOA decoder mtx */ #else - Word32 *hoa_dec_mtx; /* pointer to HOA decoder mtx */ + Word32 *hoa_dec_mtx; /* pointer to HOA decoder mtx */ /*Q29*/ #endif int8_t rotInCldfb; /* Flag to enable rotation within bin Renderer in CLDFB*/ int16_t max_band; /* band upto which rendering is performed */ diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index 8177b4567830a3e929e0b2147cd1449bc19a683b..7737a251d1f18a8c1dece2108e2ec370cb02a2f1 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -677,16 +677,16 @@ static void stereo_dft_generate_comfort_noise( *-------------------------------------------------------------------*/ static void stereo_dft_generate_comfort_noise_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT Stereo decoder handle */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ - const Word16 last_element_mode, /* i : last element mode */ - Decoder_State *st, /* i/o: Core coder decoder state */ - Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ - Decoder_State *st1, /* i/o: Core coder decoder state secondary channel */ - const Word16 targetGain, /* i : ICA target gain Q13 */ - const Word16 chan, /* i : channel number */ - const Word16 output_frame, /* i : output frame size */ - Word16 q_dft /* i : Q of DFT */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT Stereo decoder handle */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ + const Word16 last_element_mode, /* i : last element mode Q0*/ + Decoder_State *st, /* i/o: Core coder decoder state */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers q_dft*/ + Decoder_State *st1, /* i/o: Core coder decoder state secondary channel */ + const Word16 targetGain, /* i : ICA target gain Q13*/ + const Word16 chan, /* i : channel number Q0*/ + const Word16 output_frame, /* i : output frame size Q0*/ + Word16 q_dft /* i : Q of DFT */ ) { Word16 i, j, k; @@ -755,17 +755,17 @@ static void stereo_dft_generate_comfort_noise_fx( IF( chan == 0 ) { - pSideGain = hStereoDft->side_gain_fx + STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX; + pSideGain = hStereoDft->side_gain_fx + STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX; /* Q31 */ FOR( b = 0; b < hStereoDft->nbands; b++ ) { IF( hStereoCng->xfade_frame_counter == 0 ) { - hStereoDft->g_state_fx[b] = extract_h( *pSideGain++ ); + hStereoDft->g_state_fx[b] = extract_h( *pSideGain++ ); /* Q15 */ move16(); } ELSE { - hStereoDft->g_state_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, extract_h( *pSideGain++ ) ), mult( A_GFILT_FX, hStereoDft->g_state_fx[b] ) ); + hStereoDft->g_state_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, extract_h( *pSideGain++ ) ), mult( A_GFILT_FX, hStereoDft->g_state_fx[b] ) ); /* Q15 */ move16(); } @@ -774,12 +774,12 @@ static void stereo_dft_generate_comfort_noise_fx( { IF( hStereoCng->first_SID_after_TD ) { - hStereoCng->cm_fx[b] = extract_h( Mpy_32_32( hStereoCng->c_LR_LT_fx, hStereoCng->c_LR_LT_fx ) ); + hStereoCng->cm_fx[b] = extract_h( Mpy_32_32( hStereoCng->c_LR_LT_fx, hStereoCng->c_LR_LT_fx ) ); /* Q15 */ move16(); } ELSE { - hStereoCng->cm_fx[b] = hStereoCng->coh_fx[b]; + hStereoCng->cm_fx[b] = hStereoCng->coh_fx[b]; /* Q15 */ move16(); } } @@ -787,18 +787,18 @@ static void stereo_dft_generate_comfort_noise_fx( { IF( GT_16( hStereoCng->nr_corr_frames, CORR_INIT ) ) { - hStereoCng->cm_fx[b] = extract_h( Mpy_32_32( hStereoCng->c_LR_LT_fx, hStereoCng->c_LR_LT_fx ) ); + hStereoCng->cm_fx[b] = extract_h( Mpy_32_32( hStereoCng->c_LR_LT_fx, hStereoCng->c_LR_LT_fx ) ); /* Q15 */ move16(); } ELSE { - hStereoCng->cm_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), mult( A_GFILT_FX, hStereoCng->cm_fx[b] ) ); + hStereoCng->cm_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), mult( A_GFILT_FX, hStereoCng->cm_fx[b] ) ); /* Q15 */ move16(); } } ELSE { - hStereoCng->cm_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), mult( A_GFILT_FX, hStereoCng->cm_fx[b] ) ); + hStereoCng->cm_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), mult( A_GFILT_FX, hStereoCng->cm_fx[b] ) ); /* Q15 */ move16(); } } @@ -878,25 +878,25 @@ static void stereo_dft_generate_comfort_noise_fx( IF( EQ_16( st->L_frame, L_FRAME ) ) { - pTrigo = hStereoDft->dft_trigo_12k8_fx; + pTrigo = hStereoDft->dft_trigo_12k8_fx; /* Q15 */ trigo_step = STEREO_DFT_TRIGO_SRATE_12k8_STEP * STEREO_DFT_TRIGO_DEC_STEP; move16(); } ELSE { - pTrigo = hStereoDft->dft_trigo_16k_fx; + pTrigo = hStereoDft->dft_trigo_16k_fx; /* Q15 */ trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP * STEREO_DFT_TRIGO_DEC_STEP; move16(); } - FOR( i = 0; i < shr( st->L_frame, 2 ); i++ ) + FOR( i = 0; i < st->L_frame / 4; i++ ) { - trigo_dec[i] = pTrigo[i_mult( i, trigo_step )]; + trigo_dec[i] = pTrigo[i * trigo_step]; /* Q15 */ move16(); - trigo_dec[sub( st->L_frame / 2, i )] = pTrigo[i_mult( i, trigo_step )]; + trigo_dec[st->L_frame / 2 - i] = pTrigo[i * trigo_step]; /* Q15 */ move16(); } - trigo_dec[st->L_frame / 4] = pTrigo[i_mult( st->L_frame / 4, trigo_step )]; + trigo_dec[st->L_frame / 4] = pTrigo[st->L_frame / 4 * trigo_step]; /* Q15 */ move16(); Word16 rshift_cng = sub( find_guarded_bits_fx( st->L_frame ), getScaleFactor32( cngNoiseLevel_upd, st->L_frame ) ); @@ -918,14 +918,14 @@ static void stereo_dft_generate_comfort_noise_fx( // lp_ener_fx will be in Q6 at this point. // So applying appropriate left shift on the denominator. - factor = L_shr( BASOP_Util_Divide3232_Scale_cadence( st->lp_ener_fx, L_shl( st->L_frame, Q6 ), &q_div ), 1 ); /* fixed factor in the loop below */ + factor = L_shr( BASOP_Util_Divide3232_Scale_cadence( st->lp_ener_fx, L_shl( st->L_frame, Q6 ), &q_div ), 1 ); /* fixed factor in the loop below */ /* q_div */ factor = Sqrt32( factor, &q_div ); q_div = add( q_div, 1 ); Word16 q_tmp; - FOR( i = 0; i < sub( shr( st->L_frame, 1 ), 1 ); i++ ) + FOR( i = 0; i < st->L_frame / 2 - 1; i++ ) { - ftmp = Madd_32_32( Mpy_32_32( *ptr1, *ptr1 ), *ptr2, *ptr2 ); + ftmp = Madd_32_32( Mpy_32_32( *ptr1, *ptr1 ), *ptr2, *ptr2 ); /* q_cngNoiseLevel_upd */ assert( ftmp > 0 ); q_sqrt = sub( 62, shl( q_cngNoiseLevel_upd, 1 ) ); IF( ftmp == 0 ) @@ -937,13 +937,13 @@ static void stereo_dft_generate_comfort_noise_fx( tmp = ISqrt32( ftmp, &q_sqrt ); e_norm_temp[i] = sub( 31, add( q_sqrt, q_div ) ); move16(); - *ptr0++ = Mpy_32_32( factor, tmp ); + *ptr0++ = Mpy_32_32( factor, tmp ); /* 2 * q_div + q_sqrt - 31 */ move32(); ptr1 += 2; ptr2 += 2; } - FOR( i = 0; i < sub( shr( st->L_frame, 1 ), 1 ); i++ ) + FOR( i = 0; i < st->L_frame / 2 - 1; i++ ) { q_cngNoiseLevel_upd = s_min( q_cngNoiseLevel_upd, add( e_norm_temp[i], norm_l( cngNoiseLevel_upd[i] ) ) ); } @@ -961,18 +961,18 @@ static void stereo_dft_generate_comfort_noise_fx( IF( NE_16( st->L_frame, L_FRAME16k ) ) { - pTrigo = hStereoDft->dft_trigo_16k_fx; + pTrigo = hStereoDft->dft_trigo_16k_fx; /* Q15 */ trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP * STEREO_DFT_TRIGO_DEC_STEP; move16(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { - trigo_dec[i] = pTrigo[i_mult( i, trigo_step )]; + trigo_dec[i] = pTrigo[i * trigo_step]; /* Q15 */ move16(); - trigo_dec[sub( L_FRAME16k / 2, i )] = pTrigo[i_mult( i, trigo_step )]; + trigo_dec[L_FRAME16k / 2 - i] = pTrigo[i * trigo_step]; /* Q15 */ move16(); } - trigo_dec[L_FRAME16k / 4] = pTrigo[i_mult( L_FRAME16k / 4, trigo_step )]; + trigo_dec[L_FRAME16k / 4] = pTrigo[L_FRAME16k / 4 * trigo_step]; /* Q15 */ move16(); } @@ -983,11 +983,11 @@ static void stereo_dft_generate_comfort_noise_fx( rfft_fx( shb_shape, trigo_dec, L_FRAME16k, -1 ); shift = sub( getScaleFactor32( shb_shape, L_FRAME16k ), 1 ); - scale_sig32( shb_shape, L_FRAME16k, shift ); + scale_sig32( shb_shape, L_FRAME16k, shift ); /* q_shb_shape + shift */ q_shb_shape = add( q_shb_shape, shift ); /* Compute 1/|A| */ - enr = Madd_32_32( Mpy_32_32( shb_shape[0], shb_shape[0] ), shb_shape[1], shb_shape[1] ); + enr = Madd_32_32( Mpy_32_32( shb_shape[0], shb_shape[0] ), shb_shape[1], shb_shape[1] ); /* 62 - 2*q_shb_shape */ q_enr = sub( 62, shl( q_shb_shape, 1 ) ); ptr0 = shb_shape; ptr1 = ptr0 + 2; @@ -996,20 +996,20 @@ static void stereo_dft_generate_comfort_noise_fx( FOR( i = 0; i < L_FRAME16k / 2 - 1; i++ ) { - ftmp = Madd_32_32( Mpy_32_32( *ptr1, *ptr1 ), *ptr2, *ptr2 ); + ftmp = Madd_32_32( Mpy_32_32( *ptr1, *ptr1 ), *ptr2, *ptr2 ); /* 2*q_shape - 31 */ q_tmp = sub( shl( q_shb_shape, 1 ), 31 ); assert( ftmp > 0 ); q_div = 0; move16(); - ftmp = BASOP_Util_Divide3232_Scale_cadence( L_shl( 1, q_tmp ), ftmp, &q_div ); + ftmp = BASOP_Util_Divide3232_Scale_cadence( L_shl( 1, q_tmp ), ftmp, &q_div ); /* q_div */ /* in float: both a = "div"=(1/(x^2+y^2) and sqrt(a) is used and summed up in the same loop. in BASOP: sum up using inv_sqrt( *ptr1 * *ptr1 + *ptr2 * *ptr2 ), in this loop and then sum up enr = sum( *ptr0 * *ptr0 ), in a subsequent MAC loop */ - enr = BASOP_Util_Add_Mant32Exp( enr, q_enr, ftmp, q_div, &q_enr ); - tmp32_1 = Sqrt32( ftmp, &q_div ); + enr = BASOP_Util_Add_Mant32Exp( enr, q_enr, ftmp, q_div, &q_enr ); /* q_enr */ + tmp32_1 = Sqrt32( ftmp, &q_div ); /* q_div */ *ptr0++ = tmp32_1; move32(); e_norm_temp[i] = sub( 31, q_div ); @@ -1026,19 +1026,19 @@ static void stereo_dft_generate_comfort_noise_fx( } FOR( i = 0; i < L_FRAME16k; i++ ) { - shb_shape[i] = L_shl( shb_shape[i], sub( q_shb_shape, e_norm_temp[i] ) ); + shb_shape[i] = L_shl( shb_shape[i], sub( q_shb_shape, e_norm_temp[i] ) ); /* q_shb_shape */ move32(); } } /* Update CNG noise level from MS noise estimation */ - Copy32( st->hFdCngDec->bandNoiseShape, cngNoiseLevel_hist, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); + Copy32( st->hFdCngDec->bandNoiseShape, cngNoiseLevel_hist, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* exp(bandNoiseShape_exp)*/ ptr_cng = cngNoiseLevel_hist; - FOR( i = 0; i < shr( sub( st->last_L_frame, hFdCngCom->startBand ), 1 ); i++ ) + FOR( i = 0; i < ( st->last_L_frame - hFdCngCom->startBand ) / 2; i++ ) { tmp = L_shr( *( cngNoiseLevel_hist + shl( i, 1 ) ), 1 ); move32(); - tmp = L_add( tmp, L_shr( *( cngNoiseLevel_hist + add( shl( i, 1 ), 1 ) ), 1 ) ); + tmp = L_add( tmp, L_shr( *( cngNoiseLevel_hist + add( shl( i, 1 ), 1 ) ), 1 ) ); /* exp(bandNoiseShape_exp)*/ *ptr_cng++ = tmp; move32(); } @@ -1052,11 +1052,11 @@ static void stereo_dft_generate_comfort_noise_fx( ptr_tmp = cngNoiseLevel_upd + hFdCngCom->startBand; Word32 temppp; Word16 shift_g = shr( find_guarded_bits_fx( shr( sub( st->last_L_frame, hFdCngCom->startBand ), 1 ) ), 1 ); - FOR( i = 0; i < shr( sub( st->last_L_frame, hFdCngCom->startBand ), 1 ); i++ ) + FOR( i = 0; i < ( st->last_L_frame - hFdCngCom->startBand ) / 2; i++ ) { - E0 = W_add( E0, *ptr_cng++ ); + E0 = W_add( E0, *ptr_cng++ ); /* exp(bandNoiseShape_exp - E0_e) */ temppp = L_shr( ( *ptr_tmp ), shift_g ); - E1 = W_mac_32_32( E1, temppp, temppp ); + E1 = W_mac_32_32( E1, temppp, temppp ); /* 2*(q_cngNoiseLevel_upd - shift_g) + 1*/ ptr_tmp++; } E0_e = W_norm( E0 ); @@ -1068,20 +1068,20 @@ static void stereo_dft_generate_comfort_noise_fx( IF( BASOP_Util_Cmp_Mant32Exp( W_extract_h( E0 ), E0_e, W_extract_h( E1 ), E1_e ) < 0 ) { - tmp_16 = BASOP_Util_Divide3232_Scale( W_extract_h( E0 ), W_extract_h( E1 ), &q_div ); + tmp_16 = BASOP_Util_Divide3232_Scale( W_extract_h( E0 ), W_extract_h( E1 ), &q_div ); /* q_div + E0_e - E1_e */ q_div = add( q_div, sub( E0_e, E1_e ) ); tmp_16 = Sqrt16( tmp_16, &q_div ); tmp_16 = shl( tmp_16, q_div ); - hStereoCng->xfade_length = sub( MAX_XFADE_FX, extract_l( L_shr( imult3216( MAX_XFADE_FX, tmp_16 ), Q15 ) ) ); + hStereoCng->xfade_length = sub( MAX_XFADE_FX, extract_l( L_shr( imult3216( MAX_XFADE_FX, tmp_16 ), Q15 ) ) ); /* Q0 */ move16(); } ELSE { - tmp_16 = BASOP_Util_Divide3232_Scale( W_extract_h( E1 ), W_extract_h( E0 ), &q_div ); + tmp_16 = BASOP_Util_Divide3232_Scale( W_extract_h( E1 ), W_extract_h( E0 ), &q_div ); /* q_div + E0_e - E1_e */ q_div = add( q_div, sub( E1_e, E0_e ) ); tmp_16 = Sqrt16( tmp_16, &q_div ); tmp_16 = shl( tmp_16, q_div ); - hStereoCng->xfade_length = sub( MAX_XFADE_FX, extract_l( L_shr( imult3216( MAX_XFADE_FX, tmp_16 ), Q15 ) ) ); + hStereoCng->xfade_length = sub( MAX_XFADE_FX, extract_l( L_shr( imult3216( MAX_XFADE_FX, tmp_16 ), Q15 ) ) ); /* Q0 */ move16(); } } @@ -1090,15 +1090,15 @@ static void stereo_dft_generate_comfort_noise_fx( { ptr_cng = cngNoiseLevel_hist + hFdCngCom->startBand; ptr_tmp = cngNoiseLevel_upd + hFdCngCom->startBand; - FOR( i = 0; i < shr( sub( st->last_L_frame, hFdCngCom->startBand ), 1 ); i++ ) + FOR( i = 0; i < ( st->last_L_frame - hFdCngCom->startBand ) / 2; i++ ) { q_sqrt = st->hFdCngDec->bandNoiseShape_exp; move16(); - tmp_16 = BASOP_Util_Divide1616_Scale( hStereoCng->xfade_frame_counter, hStereoCng->xfade_length, &q_div ); + tmp_16 = BASOP_Util_Divide1616_Scale( hStereoCng->xfade_frame_counter, hStereoCng->xfade_length, &q_div ); /* Q0 */ tmp_16 = shl( tmp_16, q_div ); tmp = Sqrt32( *ptr_cng++, &q_sqrt ); tmp = L_shl( tmp, sub( add( q_cngNoiseLevel_upd, q_sqrt ), 31 ) ); - *ptr_tmp = L_add( Mpy_32_16_1( *ptr_tmp, tmp_16 ), Mpy_32_16_1( Mpy_32_16_1( tmp, sub( MAX_16, tmp_16 ) ), hStereoDft->scale_fx ) ); + *ptr_tmp = L_add( Mpy_32_16_1( *ptr_tmp, tmp_16 ), Mpy_32_16_1( Mpy_32_16_1( tmp, sub( MAX_16, tmp_16 ) ), hStereoDft->scale_fx ) ); /* q_cngNoiseLevel_upd + q_div */ move32(); ptr_tmp++; } @@ -1112,7 +1112,7 @@ static void stereo_dft_generate_comfort_noise_fx( ptr_i = ptr_r + 1; scale = shr( output_frame, 1 ); - FOR( i = 0; i < shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); i++ ) + FOR( i = 0; i < ( hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2; i++ ) { /* Real part in FFT bins */ rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft ); @@ -1125,13 +1125,13 @@ static void stereo_dft_generate_comfort_noise_fx( tmp32_1 = L_shl( tmp32_1, q_shift ); q_shift = sub( sub( 46, q_cngNoiseLevel_upd ), q_shift ); - ( *ptr_r ) = L_shl( Mpy_32_32( ( *ptr_r ), tmp32_1 ), q_shift ); + ( *ptr_r ) = L_shl( Mpy_32_32( ( *ptr_r ), tmp32_1 ), q_shift ); /* q_dft */ move32(); ptr_r += 2; /* Imaginary part in FFT bins */ rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); - ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); + ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); /* q_dft */ move32(); ptr_i += 2; ptr_level++; @@ -1163,8 +1163,8 @@ static void stereo_dft_generate_comfort_noise_fx( ptr_shb = shb_shape + ( L_FRAME16k / 2 - 1 ); /* Averaging for Nyquist frequency */ Word16 q1, q2; - tmp32_1 = Mpy_32_16_1( cngNoiseLevel_upd[sub( shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ), 1 )], inv_scale ); - tmp32_2 = *( ptr_shb - 1 ); + tmp32_1 = Mpy_32_16_1( cngNoiseLevel_upd[( hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 - 1], inv_scale ); /* q_cngNoiseLevel_upd + 1 - q_res */ + tmp32_2 = *( ptr_shb - 1 ); /* q_shb_shape */ move32(); q1 = sub( add( q_cngNoiseLevel_upd, 1 ), q_res ); q2 = q_shb_shape; @@ -1174,19 +1174,19 @@ static void stereo_dft_generate_comfort_noise_fx( q_tmp = sub( q_tmp, 1 ); IF( LT_16( sub( Q31, q_tmp ), q_shb_shape ) ) { - scale_sig32( shb_shape, L_FRAME16k, sub( sub( Q31, q_tmp ), q_shb_shape ) ); + scale_sig32( shb_shape, L_FRAME16k, sub( sub( Q31, q_tmp ), q_shb_shape ) ); /* Q31 - q_tmp */ q_shb_shape = sub( Q31, q_tmp ); } - *ptr_shb = L_shl( *ptr_shb, sub( q_shb_shape, sub( Q31, q_tmp ) ) ); + *ptr_shb = L_shl( *ptr_shb, sub( q_shb_shape, sub( Q31, q_tmp ) ) ); /* Q31 - q_tmp */ move32(); // *ptr_shb = 0.5f * ( cngNoiseLevel_upd[( hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 - 1] / scale + *( ptr_shb - 1 ) ); - ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); + ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); /* q_dft */ ptr_i = ptr_r + 1; - FOR( i = 0; i < shr( sub( s_min( output_frame, shl( hFdCngCom->regularStopBand, 4 ) ), hFdCngCom->stopFFTbin ), 1 ); i++ ) + FOR( i = 0; i < ( min( output_frame, hFdCngCom->regularStopBand * 16 ) - hFdCngCom->stopFFTbin ) / 2; i++ ) { /* Real part in FFT bins */ rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft ); @@ -1205,7 +1205,7 @@ static void stereo_dft_generate_comfort_noise_fx( ptr_r += 2; /* Imaginary part in FFT bins */ rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); - ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); + ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); /* q_dft + q_shift */ move32(); ptr_i += 2; ptr_shb--; @@ -1221,13 +1221,13 @@ static void stereo_dft_generate_comfort_noise_fx( tmp32_1 = L_shl( tmp32_1, q_shift ); q_shift = sub( add( Q16, q_div ), q_shift ); - ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); + ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); /* q_dft */ ptr_i = ptr_r + 1; - FOR( i = 0; i < shr( sub( min( output_frame, shl( hFdCngCom->regularStopBand, 4 ) ), hFdCngCom->stopFFTbin ), 1 ); i++ ) + FOR( i = 0; i < ( min( output_frame, hFdCngCom->regularStopBand * 16 ) - hFdCngCom->stopFFTbin ) / 2; i++ ) { - ( *ptr_r ) = L_shl( Mpy_32_32( ( *ptr_r ), tmp32_1 ), q_shift ); + ( *ptr_r ) = L_shl( Mpy_32_32( ( *ptr_r ), tmp32_1 ), q_shift ); /* q_dft + q_shift */ move32(); - ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); + ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); /* q_dft + q_shift */ move32(); ptr_r += 2; ptr_i += 2; @@ -1240,17 +1240,17 @@ static void stereo_dft_generate_comfort_noise_fx( move32(); lp_noise_e = 0; move16(); - ptr_level = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, add( hFdCngCom->startBand, 1 ) ); - ptr_tmp = cngNoiseLevel_upd + sub( shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ), 1 ); + ptr_level = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, add( hFdCngCom->startBand, 1 ) ); /* q_cngNoiseLevel */ + ptr_tmp = cngNoiseLevel_upd + sub( shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ), 1 ); /* q_cngNoiseLevel_upd */ q_tmp = s_max( hFdCngCom->cngNoiseLevelExp, shl( sub( Q31, q_cngNoiseLevel_upd ), 1 ) ); - scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( hFdCngCom->cngNoiseLevelExp, q_tmp ) ); + scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( hFdCngCom->cngNoiseLevelExp, q_tmp ) ); /* q_tmp */ hFdCngCom->cngNoiseLevelExp = q_tmp; move16(); - FOR( i = 0; i < shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); i++ ) + FOR( i = 0; i < ( hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2; i++ ) { - *ptr_level-- = L_shl( Mpy_32_32( *ptr_tmp, *ptr_tmp ), sub( shl( sub( Q31, q_cngNoiseLevel_upd ), 1 ), hFdCngCom->cngNoiseLevelExp ) ); + *ptr_level-- = L_shl( Mpy_32_32( *ptr_tmp, *ptr_tmp ), sub( shl( sub( Q31, q_cngNoiseLevel_upd ), 1 ), hFdCngCom->cngNoiseLevelExp ) ); /* q_cngNoiseLevel */ move32(); ptr_tmp--; *ptr_level = *( ptr_level + 1 ); @@ -1270,9 +1270,9 @@ static void stereo_dft_generate_comfort_noise_fx( /* Fade MS -> SID/MS */ j = 0; move16(); - FOR( k = 0; k < sub( hFdCngCom->nFFTpart, 2 ); k++ ) + FOR( k = 0; k < ( hFdCngCom->nFFTpart - 2 ); k++ ) { - factor = BASOP_Util_Divide3232_Scale_cadence( L_add( hFdCngCom->sidNoiseEstLp[k], DELTA_FX ), L_add( st->hFdCngDec->partNoiseShape[k], DELTA_FX ), &q_div ); + factor = BASOP_Util_Divide3232_Scale_cadence( L_add( hFdCngCom->sidNoiseEstLp[k], DELTA_FX ), L_add( st->hFdCngDec->partNoiseShape[k], DELTA_FX ), &q_div ); /* q_div */ q_div = add( q_div, sub( hFdCngCom->sidNoiseEstExp, st->hFdCngDec->partNoiseShape_exp ) ); IF( q_div < 0 ) { @@ -1280,10 +1280,10 @@ static void stereo_dft_generate_comfort_noise_fx( q_div = 0; move16(); } - factor = L_min( L_add( L_shl( hStereoDft->scale_fx, sub( 16, q_div ) ), W_extract_l( W_mult0_32_32( Mpy_32_16_1( L_sub( factor, L_shl( hStereoDft->scale_fx, sub( 16, q_div ) ) ), ONE_BY_MAX_K ), hStereoCng->xfade_frame_counter ) ) ), factor ); + factor = L_min( L_add( L_shl( hStereoDft->scale_fx, sub( 16, q_div ) ), W_extract_l( W_mult0_32_32( Mpy_32_16_1( L_sub( factor, L_shl( hStereoDft->scale_fx, sub( 16, q_div ) ) ), ONE_BY_MAX_K ), hStereoCng->xfade_frame_counter ) ) ), factor ); /* q_div */ FOR( ; j <= hFdCngCom->part[k]; j++ ) { - hFdCngCom->cngNoiseLevel[j] = L_shl( Mpy_32_32( st->hFdCngDec->bandNoiseShape[j], factor ), q_div ); + hFdCngCom->cngNoiseLevel[j] = L_shl( Mpy_32_32( st->hFdCngDec->bandNoiseShape[j], factor ), q_div ); /* exp(st->hFdCngDec->bandNoiseShape_exp) */ move32(); } } @@ -1296,10 +1296,10 @@ static void stereo_dft_generate_comfort_noise_fx( FOR( k = 0; k < STEREO_DFT_NBDIV; k++ ) { ptr_level = hFdCngCom->cngNoiseLevel; - ptr_r = DFT[chan] + add( hFdCngCom->startBand, i_mult( k, STEREO_DFT32MS_N_MAX ) ); + ptr_r = DFT[chan] + add( hFdCngCom->startBand, i_mult( k, STEREO_DFT32MS_N_MAX ) ); /* qDFT */ ptr_i = ptr_r + 1; q_cngNoiseLevel = sub( Q31, hFdCngCom->cngNoiseLevelExp ); - FOR( i = 0; i < shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); i++ ) + FOR( i = 0; i < ( hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2; i++ ) { /* Real part in FFT bins */ tmp = L_shr( *ptr_level++, 1 ); @@ -1307,19 +1307,19 @@ static void stereo_dft_generate_comfort_noise_fx( rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft ); q_sqrt = sub( Q31, q_cngNoiseLevel ); tmp = Sqrt32( tmp, &q_sqrt ); - *( ptr_r ) = imult3216( Mpy_32_32( *( ptr_r ), tmp ), scale ); + *( ptr_r ) = imult3216( Mpy_32_32( *( ptr_r ), tmp ), scale ); /* qDFT */ move32(); - ( *ptr_r ) = L_shl( ( *ptr_r ), q_sqrt ); + ( *ptr_r ) = L_shl( ( *ptr_r ), q_sqrt ); /* qDFT */ move32(); ptr_r += 2; /* Imaginary part in FFT bins */ rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); - ( *ptr_i ) = L_shl( imult3216( Mpy_32_32( ( *ptr_i ), tmp ), scale ), q_sqrt ); + ( *ptr_i ) = L_shl( imult3216( Mpy_32_32( ( *ptr_i ), tmp ), scale ), q_sqrt ); /* qDFT */ move32(); ptr_i += 2; } ptr_level = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); - ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); + ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); /* qDFT */ ptr_i = ptr_r + 1; FOR( j = hFdCngCom->numCoreBands; j < hFdCngCom->regularStopBand; j++ ) { @@ -1336,7 +1336,7 @@ static void stereo_dft_generate_comfort_noise_fx( ptr_r += 2; /* Imaginary part in FFT bins */ rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); - ( *ptr_i ) = Mpy_32_32( *ptr_i, tmp ); + ( *ptr_i ) = Mpy_32_32( *ptr_i, tmp ); // q_dft + 15 + q_sqrt - 31 ( *ptr_i ) = L_shl_sat( ( *ptr_i ), add( 15, q_sqrt ) ); move32(); ptr_i += 2; @@ -1351,7 +1351,7 @@ static void stereo_dft_generate_comfort_noise_fx( lp_noise_e = 0; move16(); ptr_level = hFdCngCom->cngNoiseLevel; - FOR( i = 0; i < sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); i++ ) + FOR( i = 0; i < hFdCngCom->stopFFTbin - hFdCngCom->startBand; i++ ) { // lp_noise = L_add( lp_noise, *ptr_level++ ); lp_noise = BASOP_Util_Add_Mant32Exp( lp_noise, lp_noise_e, *ptr_level++, hFdCngCom->cngNoiseLevelExp, &lp_noise_e ); @@ -1361,31 +1361,31 @@ static void stereo_dft_generate_comfort_noise_fx( test(); IF( EQ_16( hStereoCng->last_act_element_mode, IVAS_CPE_TD ) && ( chan > 0 ) ) { - Word32 log_lp_noise = L_add( L_shl( lp_noise_e, Q25 ), BASOP_Util_Log2( L_add( lp_noise, DELTA_FX ) ) ); + Word32 log_lp_noise = L_add( L_shl( lp_noise_e, Q25 ), BASOP_Util_Log2( L_add( lp_noise, DELTA_FX ) ) ); /* Q25 */ // log10(x) is computed as log2(x) * log10(2) // log_lp_noise at this stage is in Q25. where as the structure value is in Q23 // Hence the 16-bit constant log10(2) will be stored in Q13 - log_lp_noise = Mpy_32_16_1( log_lp_noise, 2466 /* log10(2) in Q13 */ ); - st1->lp_noise = L_add( Mpy_32_16_1( st1->lp_noise, 29491 /* 0.9f in Q15 */ ), log_lp_noise ); + log_lp_noise = Mpy_32_16_1( log_lp_noise, 2466 /* log10(2) in Q13 */ ); /* Q23 */ + st1->lp_noise = L_add( Mpy_32_16_1( st1->lp_noise, 29491 /* 0.9f in Q15 */ ), log_lp_noise ); /* Q23 */ move32(); } ELSE IF( ( chan == 0 ) ) { Word16 q_lp_noise = 0; // st->hFdCngDec->q_lp_noise; // to be populated appropriately. move16(); - Word32 log_lp_noise = L_add( L_shl( lp_noise_e, Q25 ), BASOP_Util_Log2( L_add( lp_noise, DELTA_FX ) ) ); + Word32 log_lp_noise = L_add( L_shl( lp_noise_e, Q25 ), BASOP_Util_Log2( L_add( lp_noise, DELTA_FX ) ) ); /* Q25 */ // log10(x) is computed as log2(x) * log10(2) // log_lp_noise at this stage is in Q25. where as the structure value is in Q23 // Hence the 16-bit constant log10(2) will be stored in Q13 - log_lp_noise = Mpy_32_16_1( log_lp_noise, 2466 /* log10(2) in Q13 */ ); - st->hFdCngDec->lp_noise = L_add( Mpy_32_16_1( st->hFdCngDec->lp_noise, 29491 /* 0.9f in Q15 */ ), log_lp_noise ); + log_lp_noise = Mpy_32_16_1( log_lp_noise, 2466 /* log10(2) in Q13 */ ); /* Q23 */ + st->hFdCngDec->lp_noise = L_add( Mpy_32_16_1( st->hFdCngDec->lp_noise, 29491 /* 0.9f in Q15 */ ), log_lp_noise ); /* Q23 */ move32(); - st->lp_noise = st->hFdCngDec->lp_noise; + st->lp_noise = st->hFdCngDec->lp_noise; /* Q23 */ move32(); - st->hFdCngDec->hFdCngCom->flag_noisy_speech = extract_l( LT_32( L_shr( L_sub( st->hFdCngDec->lp_speech, st->hFdCngDec->lp_noise ), q_lp_noise ), 28 ) ); + st->hFdCngDec->hFdCngCom->flag_noisy_speech = extract_l( LT_32( L_shr( L_sub( st->hFdCngDec->lp_speech, st->hFdCngDec->lp_noise ), q_lp_noise ), 28 ) ); /* Q0 */ move16(); st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), - imult3216( Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); + imult3216( Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); /* Q31 */ move32(); } @@ -1398,16 +1398,16 @@ static void stereo_dft_generate_comfort_noise_fx( min_q = sub( s_min( add( q_shift_1, sub( Q31, st->hFdCngDec->smoothed_psd_exp ) ), add( q_shift_2, sub( Q31, hFdCngCom->cngNoiseLevelExp ) ) ), 1 /* Guard bit */ ); - scale_sig32( st->hFdCngDec->smoothed_psd_fx, L_FRAME16k, sub( min_q, sub( Q31, st->hFdCngDec->smoothed_psd_exp ) ) ); + scale_sig32( st->hFdCngDec->smoothed_psd_fx, L_FRAME16k, sub( min_q, sub( Q31, st->hFdCngDec->smoothed_psd_exp ) ) ); /* Q31 - st->hFdCngDec->smoothed_psd_exp */ st->hFdCngDec->smoothed_psd_exp = sub( Q31, min_q ); move16(); - scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( min_q, sub( Q31, hFdCngCom->cngNoiseLevelExp ) ) ); + scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( min_q, sub( Q31, hFdCngCom->cngNoiseLevelExp ) ) ); /* Q31 - hFdCngCom->cngNoiseLevelExp */ hFdCngCom->cngNoiseLevelExp = st->hFdCngDec->smoothed_psd_exp; move16(); FOR( i = hFdCngCom->startBand; i < hFdCngCom->stopFFTbin; i++ ) { - ftmp = hFdCngCom->cngNoiseLevel[sub( i, hFdCngCom->startBand )]; + ftmp = hFdCngCom->cngNoiseLevel[i - hFdCngCom->startBand]; move32(); IF( !st->hFdCngDec->first_cna_noise_updated ) { @@ -1423,7 +1423,7 @@ static void stereo_dft_generate_comfort_noise_fx( IF( ( st->hFdCngDec->smoothed_psd_fx[i] > 0 ) && GT_32( Mpy_32_16_1( ftmp, (Word16) 0x3333 ), st->hFdCngDec->smoothed_psd_fx[i] ) ) { /* prevent abrupt upward update steps */ - ftmp = L_add( L_shl( st->hFdCngDec->smoothed_psd_fx[i], 1 ), L_shr( st->hFdCngDec->smoothed_psd_fx[i], 1 ) ); + ftmp = L_add( L_shl( st->hFdCngDec->smoothed_psd_fx[i], 1 ), L_shr( st->hFdCngDec->smoothed_psd_fx[i], 1 ) ); /* st->hFdCngDec->smoothed_psd_exp */ move16(); } ELSE IF( LT_32( ftmp, st->hFdCngDec->smoothed_psd_fx[i] ) ) @@ -1435,7 +1435,7 @@ static void stereo_dft_generate_comfort_noise_fx( } /* smoothing */ - st->hFdCngDec->smoothed_psd_fx[i] = L_add( Mpy_32_16_1( st->hFdCngDec->smoothed_psd_fx[i], alpha ), Mpy_32_16_1( ftmp, sub( MAX_16, alpha ) ) ); + st->hFdCngDec->smoothed_psd_fx[i] = L_add( Mpy_32_16_1( st->hFdCngDec->smoothed_psd_fx[i], alpha ), Mpy_32_16_1( ftmp, sub( MAX_16, alpha ) ) ); /* st->hFdCngDec->smoothed_psd_exp */ move32(); } @@ -1447,15 +1447,15 @@ static void stereo_dft_generate_comfort_noise_fx( IF( max_l ) { q_shift = sub( norm_l( max_l ), 2 ); - scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, q_shift ); + scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, q_shift ); /* st->hFdCngDec->msNoiseEst_exp - q_shift */ st->hFdCngDec->msNoiseEst_exp = sub( st->hFdCngDec->msNoiseEst_exp, q_shift ); move16(); } st->hFdCngDec->first_cna_noise_updated = 1; move16(); - Copy32( st->hFdCngDec->msNoiseEst, st->hFdCngDec->msPeriodog_ST_fx, st->hFdCngDec->nFFTpart_shaping ); + Copy32( st->hFdCngDec->msNoiseEst, st->hFdCngDec->msPeriodog_ST_fx, st->hFdCngDec->nFFTpart_shaping ); /* st->hFdCngDec->msNoiseEst_exp - q_shift */ st->hFdCngDec->msPeriodog_ST_exp = st->hFdCngDec->msNoiseEst_exp; - st->hFdCngDec->ms_last_inactive_bwidth = st->bwidth; + st->hFdCngDec->ms_last_inactive_bwidth = st->bwidth; /* Q0 */ move16(); } @@ -1507,11 +1507,11 @@ void stereo_dtf_cng( } #else void stereo_dtf_cng_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ - const Word16 output_frame, /* i : output frame size */ - Word16 q_dft /* i : Q factor of the DFT data */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers q_dft*/ + const Word16 output_frame, /* i : output frame size Q0*/ + Word16 q_dft /* i : Q factor of the DFT data */ ) { Decoder_State **sts; @@ -1523,7 +1523,7 @@ void stereo_dtf_cng_fx( { IF( LT_16( hCPE->hStereoCng->nr_dft_frames, CM_INIT ) ) { - hCPE->hStereoCng->nr_dft_frames = add( hCPE->hStereoCng->nr_dft_frames, 1 ); + hCPE->hStereoCng->nr_dft_frames = add( hCPE->hStereoCng->nr_dft_frames, 1 ); /* Q0 */ move16(); } @@ -1532,7 +1532,7 @@ void stereo_dtf_cng_fx( test(); IF( LT_16( hCPE->hStereoCng->nr_sid_frames, SID_INIT ) && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - hCPE->hStereoCng->nr_sid_frames = add( hCPE->hStereoCng->nr_sid_frames, 1 ); + hCPE->hStereoCng->nr_sid_frames = add( hCPE->hStereoCng->nr_sid_frames, 1 ); /* Q0 */ move16(); } @@ -1555,8 +1555,8 @@ void stereo_dtf_cng_fx( *-------------------------------------------------------------------*/ void stereo_cng_dec_update( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ ) { IF( GT_32( hCPE->hCoreCoder[0]->core_brate, SID_2k40 ) ) @@ -1572,7 +1572,7 @@ void stereo_cng_dec_update( } IF( LT_16( hCPE->hStereoCng->active_frame_counter, MAX_FRAME_COUNTER ) ) { - hCPE->hStereoCng->active_frame_counter = add( hCPE->hStereoCng->active_frame_counter, 1 ); + hCPE->hStereoCng->active_frame_counter = add( hCPE->hStereoCng->active_frame_counter, 1 ); /* Q0 */ move16(); } } @@ -1582,7 +1582,7 @@ void stereo_cng_dec_update( move16(); IF( LT_16( hCPE->hStereoCng->xfade_frame_counter, MAX_FRAME_COUNTER ) ) { - hCPE->hStereoCng->xfade_frame_counter = add( hCPE->hStereoCng->xfade_frame_counter, 1 ); + hCPE->hStereoCng->xfade_frame_counter = add( hCPE->hStereoCng->xfade_frame_counter, 1 ); /* Q0 */ move16(); } } @@ -1602,7 +1602,7 @@ void stereo_cng_dec_update( } } - hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->active_frame_counter = hCPE->hStereoCng->active_frame_counter; + hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->active_frame_counter = hCPE->hStereoCng->active_frame_counter; /* Q0 */ move16(); return; @@ -1621,8 +1621,8 @@ void stereo_cng_compute_PScorr_fx( Word16 *output_Q, Word32 *c_PS_LT_fx, Word16 Q_c_PS_LT_fx, - const Word16 L_frame_0, /* i : L_frame channel 0 */ - const Word16 L_frame_1 /* i : L_frame channel 1 */ + const Word16 L_frame_0, /* i : L_frame channel 0 Q0*/ + const Word16 L_frame_1 /* i : L_frame channel 1 Q0*/ ) { Word16 i; @@ -1840,10 +1840,10 @@ static void stereo_cng_compute_LRcorr( } #else static void stereo_cng_compute_LRcorr_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ - Word32 *output_fx[CPE_CHANNELS], /* i : Output signal */ - const Word16 output_frame, /* i : Output frame length */ - const Word16 tdm_ratio_idx /* i : TDM ratio index */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ + Word32 *output_fx[CPE_CHANNELS], /* i : Output signal OUTPUT_Q*/ + const Word16 output_frame, /* i : Output frame length Q0*/ + const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ ) { Word16 i; @@ -1874,9 +1874,9 @@ static void stereo_cng_compute_LRcorr_fx( FOR( i = 0; i < output_frame; i++ ) { - enrL_fx = W_add( enrL_fx, W_mult0_32_32( output_fx[0][i], output_fx[0][i] ) ); - enrR_fx = W_add( enrR_fx, W_mult0_32_32( output_fx[1][i], output_fx[1][i] ) ); - dotLR_fx = W_add( dotLR_fx, W_mult0_32_32( output_fx[0][i], output_fx[1][i] ) ); + enrL_fx = W_add( enrL_fx, W_mult0_32_32( output_fx[0][i], output_fx[0][i] ) ); /* 2 * OUTPUT_Q */ + enrR_fx = W_add( enrR_fx, W_mult0_32_32( output_fx[1][i], output_fx[1][i] ) ); /* 2 * OUTPUT_Q */ + dotLR_fx = W_add( dotLR_fx, W_mult0_32_32( output_fx[0][i], output_fx[1][i] ) ); /* 2 * OUTPUT_Q */ } dotLR_fx = W_add( dotLR_fx, EPSILON_FX_SMALL ); if ( dotLR_fx < 0 ) @@ -1917,7 +1917,7 @@ static void stereo_cng_compute_LRcorr_fx( temp_x_inv = ISqrt32( W_extract_l( enrL_fx ), &enrL_inv_q ); temp_y_inv = ISqrt32( W_extract_l( enrR_fx ), &enrR_inv_q ); - energy_xy_fx = Mpy_32_32( temp_x_inv, temp_y_inv ); + energy_xy_fx = Mpy_32_32( temp_x_inv, temp_y_inv ); /* enrL_inv_q + enrR_inv_q - 31 */ res_q = add( enrL_inv_q, enrR_inv_q ); headroom_left_dotLR = W_norm( dotLR_fx ); dotLR_q = OUTPUT_Q * 2; @@ -1935,13 +1935,13 @@ static void stereo_cng_compute_LRcorr_fx( Word16 div_q = 0; move16(); - c_fx = BASOP_Util_Divide3232_Scale( W_extract_l( enrL_fx ), W_extract_l( enrR_fx ), &div_q ); + c_fx = BASOP_Util_Divide3232_Scale( W_extract_l( enrL_fx ), W_extract_l( enrR_fx ), &div_q ); /* div_q */ c_q = add( sub( 15, div_q ), sub( enrR_q, enrL_q ) ); hCPE->hStereoTD->c_LR_LT_fx = L_add( Mpy_32_32( STEREO_TD_PS_CORR_FILT_FX, hCPE->hStereoTD->c_LR_LT_fx ), - Mpy_32_32( L_sub( ONE_IN_Q31, STEREO_TD_PS_CORR_FILT_FX ), L_deposit_h( extract_l( c_LR_fx ) ) ) ); + Mpy_32_32( L_sub( ONE_IN_Q31, STEREO_TD_PS_CORR_FILT_FX ), L_deposit_h( extract_l( c_LR_fx ) ) ) ); /* Q31 */ move32(); - hCPE->hStereoCng->c_LR_LT_fx = hCPE->hStereoTD->c_LR_LT_fx; + hCPE->hStereoCng->c_LR_LT_fx = hCPE->hStereoTD->c_LR_LT_fx; /* Q31 */ move32(); Word16 sqrt_q = sub( 31, c_q ); @@ -1951,8 +1951,8 @@ static void stereo_cng_compute_LRcorr_fx( tmp_fx = Mpy_32_32( tmp_fx, sqrt_res ); Word16 tmp_q = sub( sub( 31, sqrt_q ), 1 ); // *2 handled with q reduction - beta_sqr = Mpy_32_32( beta_fx, beta_fx ); - one_minus_beta_sqr = Mpy_32_32( L_sub( ONE_IN_Q31, beta_fx ), L_sub( ONE_IN_Q31, beta_fx ) ); + beta_sqr = Mpy_32_32( beta_fx, beta_fx ); /* Q31 */ + one_minus_beta_sqr = Mpy_32_32( L_sub( ONE_IN_Q31, beta_fx ), L_sub( ONE_IN_Q31, beta_fx ) ); /* Q31 */ numer_1 = Mpy_32_16_1( one_minus_beta_sqr, extract_l( c_fx ) ); // c_q+31-15 numer_1_q = add( c_q, 31 - 15 ); @@ -1992,8 +1992,8 @@ static void stereo_cng_compute_LRcorr_fx( denom_q = s_min( denom_q, denom_3_q ); - num = L_add( L_add( L_shr( numer_1, sub( numer_1_q, num_q ) ), L_sub( L_shr( numer_2, sub( numer_2_q, num_q ) ), L_shr( numer_3, sub( numer_3_q, num_q ) ) ) ), DELTA_FX ); - denom = L_add( L_add( L_shr( denom_1, sub( denom_1_q, denom_q ) ), L_add( L_shr( denom_2, sub( denom_2_q, denom_q ) ), L_shr( denom_3, sub( denom_3_q, denom_q ) ) ) ), DELTA_FX ); + num = L_add( L_add( L_shr( numer_1, sub( numer_1_q, num_q ) ), L_sub( L_shr( numer_2, sub( numer_2_q, num_q ) ), L_shr( numer_3, sub( numer_3_q, num_q ) ) ) ), DELTA_FX ); /* num_q */ + denom = L_add( L_add( L_shr( denom_1, sub( denom_1_q, denom_q ) ), L_add( L_shr( denom_2, sub( denom_2_q, denom_q ) ), L_shr( denom_3, sub( denom_3_q, denom_q ) ) ) ), DELTA_FX ); /* denom_q */ Word16 q = 0; move16(); sc_fx = BASOP_Util_Divide3232_Scale( num, denom, &q ); @@ -2018,12 +2018,12 @@ static void stereo_cng_compute_LRcorr_fx( move16(); } hCPE->hStereoTD->SP_ratio_LT_fx = L_add_sat( Mpy_32_32( 1932735283, hCPE->hStereoTD->SP_ratio_LT_fx ), - L_shl_sat( Mpy_32_32( 214748364, sqrt_res ), sqrt_q ) ); + L_shl_sat( Mpy_32_32( 214748364, sqrt_res ), sqrt_q ) ); /* sqrt_q */ move32(); IF( LT_16( hCPE->hStereoCng->nr_corr_frames, CM_INIT ) ) { - hCPE->hStereoCng->nr_corr_frames = add( hCPE->hStereoCng->nr_corr_frames, 1 ); + hCPE->hStereoCng->nr_corr_frames = add( hCPE->hStereoCng->nr_corr_frames, 1 ); /* Q0 */ move16(); } @@ -2075,10 +2075,10 @@ static void FindEmEs( #else static void FindEmEs_fx( - const Word32 *ch1_fx, /* i : Left channel */ - const Word32 *ch2_fx, /* i : right channel */ - const Word16 len, /* i : length */ - Word32 *lt_es_em_fx /* i/o: LT energy ratio */ + const Word32 *ch1_fx, /* i : Left channel OUTPUT_Q*/ + const Word32 *ch2_fx, /* i : right channel OUTPUT_Q*/ + const Word16 len, /* i : length Q0*/ + Word32 *lt_es_em_fx /* i/o: LT energy ratio Q24*/ ) { Word16 i; @@ -2098,16 +2098,16 @@ static void FindEmEs_fx( FOR( i = 0; i < len; i++ ) { mono_i_fx = L_add( L_shr( ch1_fx[i], 1 ), L_shr( ch2_fx[i], 1 ) ); - ener_fx = W_add( ener_fx, W_mult0_32_32( mono_i_fx, mono_i_fx ) ); + ener_fx = W_add( ener_fx, W_mult0_32_32( mono_i_fx, mono_i_fx ) ); /* 2 * OUTPUT_Q */ side_i_fx = L_sub( L_shr( ch1_fx[i], 1 ), L_shr( ch2_fx[i], 1 ) ); - ener_side_fx = W_add( ener_side_fx, W_mult0_32_32( side_i_fx, side_i_fx ) ); + ener_side_fx = W_add( ener_side_fx, W_mult0_32_32( side_i_fx, side_i_fx ) ); /* 2 * OUTPUT_Q */ } headroom_left_ener_fx = W_norm( ener_fx ); headroom_left_ener_side_fx = W_norm( ener_side_fx ); IF( LT_16( headroom_left_ener_fx, 32 ) ) { - ener_fx = W_shr( ener_fx, sub( 32, headroom_left_ener_fx ) ); + ener_fx = W_shr( ener_fx, sub( 32, headroom_left_ener_fx ) ); /* 2 * OUTPUT_Q - 32 * headroom_left_ener_fx */ ener_q = sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_ener_fx ) ); } ELSE @@ -2117,7 +2117,7 @@ static void FindEmEs_fx( } IF( LT_16( headroom_left_ener_side_fx, 32 ) ) { - ener_side_fx = W_shr( ener_side_fx, sub( 32, headroom_left_ener_side_fx ) ); + ener_side_fx = W_shr( ener_side_fx, sub( 32, headroom_left_ener_side_fx ) ); /* 2 * OUTPUT_Q - 32 * headroom_left_ener_fx */ ener_side_q = sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_ener_side_fx ) ); } ELSE @@ -2129,7 +2129,7 @@ static void FindEmEs_fx( /**es_em = 10 * ( log10( sqrt( ener_side / len ) ) - log10( sqrt( ener / len ) ) ); */ division_res = BASOP_Util_Divide3232_Scale( W_extract_l( ener_side_fx ), W_extract_l( ener_fx ), &temp_q ); temp_q = sub( temp_q, sub( ener_side_q, ener_q ) ); - square_res = Sqrt32( L_deposit_h( extract_l( division_res ) ), &temp_q ); + square_res = Sqrt32( L_deposit_h( extract_l( division_res ) ), &temp_q ); /* temp_q */ IF( temp_q < 0 ) { square_res = L_shr( square_res, ( -temp_q ) ); @@ -2137,9 +2137,9 @@ static void FindEmEs_fx( move16(); } log_res = BASOP_Util_Log2( square_res ); - es_em_fx = Mpy_32_32( log_res, 1616107501 ); // 25+30 + es_em_fx = Mpy_32_32( log_res, 1616107501 ); // 25+30-31 /* long-term estimate */ - *lt_es_em_fx = L_add( Mpy_32_32( 858993459, *lt_es_em_fx ), Mpy_32_32( 1288490188, es_em_fx ) ); + *lt_es_em_fx = L_add( Mpy_32_32( 858993459, *lt_es_em_fx ), Mpy_32_32( 1288490188, es_em_fx ) ); /* Q24 */ move32(); return; } @@ -2264,10 +2264,10 @@ void stereo_cna_update_params( } #else void stereo_cna_update_params_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx[CPE_CHANNELS], /* i : Output signal */ - const Word16 output_frame, /* i : Output frame length */ - const Word16 tdm_ratio_idx /* i : TDM ratio index */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx[CPE_CHANNELS], /* i : Output signal OUTPUT_Q*/ + const Word16 output_frame, /* i : Output frame length Q0*/ + const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ ) { Word16 i; @@ -2303,7 +2303,7 @@ void stereo_cna_update_params_fx( FindEmEs_fx( output_fx[0], output_fx[1], output_frame, &hCPE->lt_es_em_fx ); - hCPE->hStereoCng->first_SID_after_TD = 1; + hCPE->hStereoCng->first_SID_after_TD = 1; /* Q0 */ move16(); stereo_cng_compute_LRcorr_fx( hCPE, output_fx, output_frame, tdm_ratio_idx ); } @@ -2335,9 +2335,9 @@ void stereo_cna_update_params_fx( { FOR( i = 0; i < output_frame; i++ ) { - enrL_fx = W_add( enrL_fx, W_mult0_32_32( output_fx[0][i], output_fx[0][i] ) ); - enrR_fx = W_add( enrR_fx, W_mult0_32_32( output_fx[1][i], output_fx[1][i] ) ); - dotLR_fx = W_add( dotLR_fx, W_mult0_32_32( output_fx[0][i], output_fx[1][i] ) ); + enrL_fx = W_add( enrL_fx, W_mult0_32_32( output_fx[0][i], output_fx[0][i] ) ); /* 2 * OUTPUT_Q */ + enrR_fx = W_add( enrR_fx, W_mult0_32_32( output_fx[1][i], output_fx[1][i] ) ); /* 2 * OUTPUT_Q */ + dotLR_fx = W_add( dotLR_fx, W_mult0_32_32( output_fx[0][i], output_fx[1][i] ) ); /* 2 * OUTPUT_Q */ } dotLR_fx = W_add( dotLR_fx, EPSILON_FX_SMALL ); if ( dotLR_fx < 0 ) @@ -2351,7 +2351,7 @@ void stereo_cna_update_params_fx( IF( LT_16( headroom_left_x, 32 ) ) { - enrL_fx = W_shr( enrL_fx, sub( 32, headroom_left_x ) ); + enrL_fx = W_shr( enrL_fx, sub( 32, headroom_left_x ) ); /* 2 * OUTPUT_Q - 32 * headroom_left_x */ x_q = sub( 31, sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_x ) ) ); } ELSE @@ -2360,7 +2360,7 @@ void stereo_cna_update_params_fx( } IF( LT_16( headroom_left_y, 32 ) ) { - enrR_fx = W_shr( enrR_fx, sub( 32, headroom_left_y ) ); + enrR_fx = W_shr( enrR_fx, sub( 32, headroom_left_y ) ); /* 2 * OUTPUT_Q - 32 * headroom_left_x */ y_q = sub( 31, sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_y ) ) ); } ELSE @@ -2375,21 +2375,21 @@ void stereo_cna_update_params_fx( temp_x_inv = ISqrt32( W_extract_l( enrL_fx ), &x_inv_q ); temp_y_inv = ISqrt32( W_extract_l( enrR_fx ), &y_inv_q ); - energy_xy_fx = Mpy_32_32( temp_x_inv, temp_y_inv ); + energy_xy_fx = Mpy_32_32( temp_x_inv, temp_y_inv ); /* x_inv_q + y_inv_q */ temp_res_q = add( x_inv_q, y_inv_q ); headroom_left_dotLR_fx = W_norm( dotLR_fx ); dotLR_fx_q = OUTPUT_Q * 2; move16(); IF( LT_16( headroom_left_dotLR_fx, 32 ) ) { - dotLR_fx = W_shr( dotLR_fx, sub( 32, headroom_left_dotLR_fx ) ); + dotLR_fx = W_shr( dotLR_fx, sub( 32, headroom_left_dotLR_fx ) ); /* dotLR_fx_q - (32 * headroom_left_dotLR_fx) */ dotLR_fx_q = sub( dotLR_fx_q, sub( 32, headroom_left_dotLR_fx ) ); } - dotLR_fx = Mpy_32_32( W_extract_l( dotLR_fx ), energy_xy_fx ); + dotLR_fx = Mpy_32_32( W_extract_l( dotLR_fx ), energy_xy_fx ); /* dotLR_fx_q + ((31 - temp_res_q) - 31)) */ dotLR_fx_q = add( dotLR_fx_q, sub( sub( 31, temp_res_q ), 31 ) ); - dotLR_fx = W_deposit32_l( L_shl_sat( W_extract_l( dotLR_fx ), sub( 31, dotLR_fx_q ) ) ); + dotLR_fx = W_deposit32_l( L_shl_sat( W_extract_l( dotLR_fx ), sub( 31, dotLR_fx_q ) ) ); /* Q31 */ /* estimate L/R correlation factor and ILD in time domain */ - c_LR_fx = extract_h( W_extract_l( dotLR_fx ) ); + c_LR_fx = extract_h( W_extract_l( dotLR_fx ) ); /* Q15 */ temp_res_q = 0; move16(); @@ -2401,7 +2401,7 @@ void stereo_cna_update_params_fx( { c_q = 31; move16(); - c_fx = L_shr_sat( c_fx, sub( c_q, 31 ) ); + c_fx = L_shr_sat( c_fx, sub( c_q, 31 ) ); /* Q31 */ one_in_c_q = ONE_IN_Q31; move32(); } @@ -2418,7 +2418,7 @@ void stereo_cna_update_params_fx( move16(); temp_res_q = 0; move16(); - c_ILD_fx = BASOP_Util_Divide3232_Scale( L_shl_sat( num_c_fx, min_headroom_left ), L_shl_sat( denom_c_fx, min_headroom_left ), &temp_res_q ); + c_ILD_fx = BASOP_Util_Divide3232_Scale( L_shl_sat( num_c_fx, min_headroom_left ), L_shl_sat( denom_c_fx, min_headroom_left ), &temp_res_q ); /* temp_res_q */ IF( temp_res_q < 0 ) { c_ILD_fx = L_shr( c_ILD_fx, negate( temp_res_q ) ); @@ -2436,11 +2436,11 @@ void stereo_cna_update_params_fx( ELSE { hFdCngDec->cna_LR_LT_fx = extract_h( L_add_sat( Mpy_32_16_1( STEREO_CNA_LR_CORR_LT_FILT_FX, hFdCngDec->cna_LR_LT_fx ), - Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_CNA_LR_CORR_LT_FILT_FX ), extract_l( c_LR_fx ) ) ) ); + Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_CNA_LR_CORR_LT_FILT_FX ), extract_l( c_LR_fx ) ) ) ); /* Q31 */ move16(); hFdCngDec->cna_ILD_LT_fx = extract_h( L_add_sat( Mpy_32_16_1( STEREO_CNA_ILD_LT_FILT_FX, hFdCngDec->cna_ILD_LT_fx ), - Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_CNA_ILD_LT_FILT_FX ), extract_l( c_ILD_fx ) ) ) ); + Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_CNA_ILD_LT_FILT_FX ), extract_l( c_ILD_fx ) ) ) ); /* Q31 */ move16(); } @@ -2463,19 +2463,19 @@ void stereo_cna_update_params_fx( IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { /* quickly decrease in TD stereo mode */ - hFdCngDec->cna_act_fact_fx = extract_h( Mpy_32_16_1( 1503238553, hFdCngDec->cna_act_fact_fx ) ); + hFdCngDec->cna_act_fact_fx = extract_h( Mpy_32_16_1( 1503238553, hFdCngDec->cna_act_fact_fx ) ); /* Q15 */ move16(); } ELSE IF( GT_32( L_mult0( sts[0]->VAD, MAX_WORD16 ), hFdCngDec->cna_act_fact_fx ) ) // VAD is one bit { /* quickly increase during active frames in DFT stereo mode */ - hFdCngDec->cna_act_fact_fx = extract_h( L_add( Mpy_32_16_1( 1503238553, hFdCngDec->cna_act_fact_fx ), ( 644245094 * sts[0]->VAD ) ) ); + hFdCngDec->cna_act_fact_fx = extract_h( L_add( Mpy_32_16_1( 1503238553, hFdCngDec->cna_act_fact_fx ), ( 644245094 * sts[0]->VAD ) ) ); /* Q15 */ move16(); } ELSE { /* slowly decrease during inactive frames in DFT stereo mode */ - hFdCngDec->cna_act_fact_fx = extract_h( L_add( Mpy_32_16_1( 2040109440, hFdCngDec->cna_act_fact_fx ), ( 107374184 * sts[0]->VAD ) ) ); + hFdCngDec->cna_act_fact_fx = extract_h( L_add( Mpy_32_16_1( 2040109440, hFdCngDec->cna_act_fact_fx ), ( 107374184 * sts[0]->VAD ) ) ); /* Q15 */ move16(); } } @@ -2521,8 +2521,8 @@ void stereo_cng_init_dec( } #else void stereo_cng_init_dec_fx( - STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: stereo CNG decoder structure */ - const Word16 *frameSize /* i : pointer to frameSize of channel 0 to be used for channel 1 */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: stereo CNG decoder structure */ + const Word16 *frameSize /* i : pointer to frameSize of channel 0 to be used for channel 1 Q0*/ ) { hStereoCng->prev_sid_nodata = 0; diff --git a/lib_dec/ivas_stereo_dft_dec.c b/lib_dec/ivas_stereo_dft_dec.c index 4e65044dabe4661b4b7f2fac2df736b199dc4bb4..3d4adac216f7951f58f5211566bcadd6639405a0 100644 --- a/lib_dec/ivas_stereo_dft_dec.c +++ b/lib_dec/ivas_stereo_dft_dec.c @@ -663,14 +663,14 @@ void stereo_dft_dec_destroy( #ifdef IVAS_FLOAT_FIXED void stereo_dft_dec_analyze_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word32 *input_fx, /* i : input signal */ - Word32 out_DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ - const Word16 chan, /* i : channel number */ - const Word16 input_frame, /* i : input frame size */ - const Word16 output_frame, /* i : output frame size */ - const DFT_STEREO_DEC_ANA_TYPE ana_type, /* i : type of signal to analyse */ - const Word16 k_offset, /* i : offset of DFT */ - const Word16 delay, /* i : delay in samples FOR input signal */ + const Word32 *input_fx, /* i : input signal q*/ + Word32 out_DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers q_out_DFT*/ + const Word16 chan, /* i : channel number Q0*/ + const Word16 input_frame, /* i : input frame size Q0*/ + const Word16 output_frame, /* i : output frame size Q0*/ + const DFT_STEREO_DEC_ANA_TYPE ana_type, /* i : type of signal to analyse */ + const Word16 k_offset, /* i : offset of DFT Q0*/ + const Word16 delay, /* i : delay in samples FOR input signal Q0*/ Word16 *q, Word16 *q_out_DFT ) { @@ -704,86 +704,86 @@ void stereo_dft_dec_analyze_fx( IF( EQ_16( input_frame, output_frame ) ) { trigo_fx = hStereoDft->dft_trigo_fx; - trigo_step = i_mult( hStereoDft->dft_trigo_step, STEREO_DFT_TRIGO_DEC_STEP ); - win_right_fx = hStereoDft->win32ms_fx; - win_left_fx = hStereoDft->win32ms_fx; - win2_fx = hStereoDft->win232ms_fx; + trigo_step = i_mult( hStereoDft->dft_trigo_step, STEREO_DFT_TRIGO_DEC_STEP ); /* Q0 */ + win_right_fx = hStereoDft->win32ms_fx; /* Q15 */ + win_left_fx = hStereoDft->win32ms_fx; /* Q15 */ + win2_fx = hStereoDft->win232ms_fx; /* Q15 */ test(); IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_BPF ) ) { assert( ( chan == 0 ) && "DFT stereo: BPF memory only FOR M channel" ); - mem_fx = hCPE->input_mem_BPF_fx[chan]; + mem_fx = hCPE->input_mem_BPF_fx[chan]; /* Q11 */ } ELSE IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB ) || EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB_ADD ) ) { - mem_fx = hCPE->input_mem_LB_fx[chan]; + mem_fx = hCPE->input_mem_LB_fx[chan]; /* Q11 */ } ELSE { - mem_fx = hCPE->input_mem_fx[chan]; + mem_fx = hCPE->input_mem_fx[chan]; /* Q11 */ } } ELSE IF( EQ_16( input_frame, L_FRAME ) ) { - trigo_fx = hStereoDft->dft_trigo_12k8_fx; + trigo_fx = hStereoDft->dft_trigo_12k8_fx; /* Q15 */ trigo_step = STEREO_DFT_TRIGO_SRATE_12k8_STEP * STEREO_DFT_TRIGO_DEC_STEP; move16(); - win_right_fx = hStereoDft->win32ms_12k8_fx; - win_left_fx = hStereoDft->win32ms_12k8_fx; - win2_fx = hStereoDft->win232ms_12k8_fx; + win_right_fx = hStereoDft->win32ms_12k8_fx; /* Q15 */ + win_left_fx = hStereoDft->win32ms_12k8_fx; /* Q15 */ + win2_fx = hStereoDft->win232ms_12k8_fx; /* Q15 */ test(); IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_BPF ) ) { assert( ( chan == 0 ) && "DFT stereo: BPF memory only FOR M channel" ); - mem_fx = hCPE->input_mem_BPF_fx[chan]; + mem_fx = hCPE->input_mem_BPF_fx[chan]; /* Q11 */ } ELSE IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB ) || EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB_ADD ) ) { - mem_fx = hCPE->input_mem_LB_fx[chan]; + mem_fx = hCPE->input_mem_LB_fx[chan]; /* Q11 */ } ELSE { assert( ( chan == 1 ) && "12.8kHz sampling rate only FOR second channel, i.e. residual coding or allpass signal" ); - mem_fx = hCPE->input_mem_fx[chan]; + mem_fx = hCPE->input_mem_fx[chan]; /* Q11 */ } } ELSE IF( EQ_16( input_frame, L_FRAME16k ) ) { - trigo_fx = hStereoDft->dft_trigo_16k_fx; + trigo_fx = hStereoDft->dft_trigo_16k_fx; /* Q15 */ trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP * STEREO_DFT_TRIGO_DEC_STEP; move16(); - win_right_fx = hStereoDft->win32ms_16k_fx; - win_left_fx = hStereoDft->win32ms_16k_fx; - win2_fx = hStereoDft->win232ms_16k_fx; + win_right_fx = hStereoDft->win32ms_16k_fx; /* Q15 */ + win_left_fx = hStereoDft->win32ms_16k_fx; /* Q15 */ + win2_fx = hStereoDft->win232ms_16k_fx; /* Q15 */ test(); IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_BPF ) ) { assert( ( chan == 0 ) && "DFT stereo: BPF memory only FOR M channel" ); - mem_fx = hCPE->input_mem_BPF_fx[chan]; + mem_fx = hCPE->input_mem_BPF_fx[chan]; /* Q11 */ } ELSE IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB ) || EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB_ADD ) ) { - mem_fx = hCPE->input_mem_LB_fx[chan]; + mem_fx = hCPE->input_mem_LB_fx[chan]; /* Q11 */ } ELSE { assert( ( chan == 1 ) && ( hCPE->hStereoDft->hConfig->res_pred_mode == STEREO_DFT_RESPRED_ESF ) && "16kHz sampling rate only FOR second channel with allpass signal" ); - mem_fx = hCPE->input_mem_fx[chan]; + mem_fx = hCPE->input_mem_fx[chan]; /* Q11 */ } } ELSE IF( EQ_16( input_frame, L_FRAME8k ) ) { assert( ( chan == 1 ) && "DFT stereo: 8kHz analysis only FOR residual coding" ); - trigo_fx = hStereoDft->dft_trigo_8k_fx; + trigo_fx = hStereoDft->dft_trigo_8k_fx; /* Q15 */ trigo_step = STEREO_DFT_TRIGO_SRATE_8k_STEP * STEREO_DFT_TRIGO_DEC_STEP; move16(); - win_right_fx = hStereoDft->win32ms_8k_fx; - win_left_fx = hStereoDft->win32ms_8k_fx; - win2_fx = hStereoDft->win232ms_8k_fx; - mem_fx = hCPE->input_mem_fx[chan]; + win_right_fx = hStereoDft->win32ms_8k_fx; /* Q15 */ + win_left_fx = hStereoDft->win32ms_8k_fx; /* Q15 */ + win2_fx = hStereoDft->win232ms_8k_fx; /* Q15 */ + mem_fx = hCPE->input_mem_fx[chan]; /* Q11 */ } ELSE { @@ -797,7 +797,7 @@ void stereo_dft_dec_analyze_fx( win2_fx = NULL; /* to avoid compilation warning */ } - inputFs = L_mult0( input_frame, FRAMES_PER_SEC ); + inputFs = L_mult0( input_frame, FRAMES_PER_SEC ); /* Q0 */ delay_dec = NS2SA_FX2( inputFs, STEREO_DFT32MS_OVL_NS ); move16(); zp = NS2SA_FX2( inputFs, STEREO_DFT32MS_ZP_NS ); @@ -806,7 +806,7 @@ void stereo_dft_dec_analyze_fx( move16(); NFFT = NS2SA_FX2( inputFs, STEREO_DFT32MS_N_NS ); Word16 qfac_fx; - fac_fx = BASOP_Util_Divide3232_Scale_cadence( hStereoDft->NFFT, NFFT, &qfac_fx ); + fac_fx = BASOP_Util_Divide3232_Scale_cadence( hStereoDft->NFFT, NFFT, &qfac_fx ); /* qfac_fx */ qfac_fx = sub( 31, qfac_fx ); ovl2 = NS2SA_FX2( inputFs, STEREO_DFT32MS_OVL2_NS ); move16(); @@ -816,10 +816,10 @@ void stereo_dft_dec_analyze_fx( mem_size = add( delay_dec, delay ); /* Update buffers */ - Copy32( mem_fx, input_buff_fx, mem_size ); - Copy32( input_fx, input_buff_fx + mem_size, input_frame ); - Copy32( input_buff_fx + input_frame, mem_fx, mem_size ); - pInput_buff_fx = input_buff_fx; + Copy32( mem_fx, input_buff_fx, mem_size ); /* Q11 */ + Copy32( input_fx, input_buff_fx + mem_size, input_frame ); /* q */ + Copy32( input_buff_fx + input_frame, mem_fx, mem_size ); /* q */ + pInput_buff_fx = input_buff_fx; /* q */ test(); IF( EQ_16( hCPE->nchan_out, 1 ) && ( hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ) @@ -835,17 +835,17 @@ void stereo_dft_dec_analyze_fx( assert( ( k_offset <= STEREO_DFT_NBDIV ) ); - FOR( i = 0; i < shr( NFFT, 2 ); i++ ) + FOR( i = 0; i < NFFT / 4; i++ ) { - trigo_dec_fx[i] = trigo_fx[i_mult( i, trigo_step )]; + trigo_dec_fx[i] = trigo_fx[i * trigo_step]; move16(); - trigo_dec_fx[sub( NFFT / 2, i )] = trigo_fx[i_mult( i, trigo_step )]; + trigo_dec_fx[NFFT / 2 - i] = trigo_fx[i * trigo_step]; move16(); } - trigo_dec_fx[NFFT / 4] = trigo_fx[i_mult( NFFT / 4, trigo_step )]; + trigo_dec_fx[NFFT / 4] = trigo_fx[NFFT / 4 * trigo_step]; move16(); - FOR( k = 0; k < sub( STEREO_DFT_NBDIV, k_offset ); k++ ) + FOR( k = 0; k < STEREO_DFT_NBDIV - k_offset; k++ ) { set32_fx( DFT_fx, 0, STEREO_DFT32MS_N_MAX ); IF( k == 0 ) @@ -860,24 +860,24 @@ void stereo_dft_dec_analyze_fx( move16(); } - pInput_fx = pInput_buff_fx + offset; - pDFT_out_fx = out_DFT_fx[chan] + i_mult( k, STEREO_DFT32MS_N_MAX ); + pInput_fx = pInput_buff_fx + offset; /* q */ + pDFT_out_fx = out_DFT_fx[chan] + i_mult( k, STEREO_DFT32MS_N_MAX ); /* q_out_DFT */ /*Forwards FFT: L and R*/ /* Zero Padding & Flat Portion */ - Copy32( pInput_fx, DFT_fx + zp, sub( NFFT, i_mult( 2, zp ) ) ); + Copy32( pInput_fx, DFT_fx + zp, sub( NFFT, i_mult( 2, zp ) ) ); /* q */ /* Overlapping portions */ IF( k == 0 ) { FOR( i = 0; i < ovl; i++ ) { - DFT_fx[add( i, zp )] = Mpy_32_16_1( DFT_fx[add( i, zp )], win_left_fx[i_mult( STEREO_DFT32MS_STEP, i )] ); + DFT_fx[i + zp] = Mpy_32_16_1( DFT_fx[i + zp], win_left_fx[STEREO_DFT32MS_STEP * i] ); /* q */ move32(); } FOR( i = 0; i < ovl2; i++ ) { - DFT_fx[sub( sub( sub( NFFT, zp ), 1 ), i )] = Mpy_32_16_1( DFT_fx[sub( sub( sub( NFFT, zp ), 1 ), i )], win2_fx[i] ); + DFT_fx[NFFT - zp - 1 - i] = Mpy_32_16_1( DFT_fx[NFFT - zp - 1 - i], win2_fx[i] ); /* q */ move32(); } } @@ -885,12 +885,12 @@ void stereo_dft_dec_analyze_fx( { FOR( i = 0; i < ovl2; i++ ) { - DFT_fx[add( i, zp )] = Mpy_32_16_1( DFT_fx[add( i, zp )], win2_fx[i] ); + DFT_fx[i + zp] = Mpy_32_16_1( DFT_fx[i + zp], win2_fx[i] ); /* q */ move32(); } FOR( i = 0; i < ovl; i++ ) { - DFT_fx[sub( sub( sub( NFFT, zp ), i ), 1 )] = Mpy_32_16_1( DFT_fx[sub( sub( sub( NFFT, zp ), i ), 1 )], win_right_fx[i_mult( STEREO_DFT32MS_STEP, i )] ); + DFT_fx[NFFT - zp - i - 1] = Mpy_32_16_1( DFT_fx[NFFT - zp - i - 1], win_right_fx[STEREO_DFT32MS_STEP * i] ); /* q */ move32(); } } @@ -902,7 +902,7 @@ void stereo_dft_dec_analyze_fx( FOR( Word16 j = 0; j < NFFT; j++ ) { - DFT_fx[j] = L_shl( DFT_fx[j], q_shift ); + DFT_fx[j] = L_shl( DFT_fx[j], q_shift ); /* q + q_shift*/ move32(); } @@ -913,7 +913,7 @@ void stereo_dft_dec_analyze_fx( q_shift = sub( L_norm_arr( DFT_fx, NFFT ), sub( 31, qfac_fx ) ); FOR( Word16 j = 0; j < NFFT; j++ ) { - DFT_fx[j] = L_shl( DFT_fx[j], q_shift ); + DFT_fx[j] = L_shl( DFT_fx[j], q_shift ); /* q + q_shift */ move32(); } q_DFT = add( q_DFT, q_shift ); @@ -921,7 +921,7 @@ void stereo_dft_dec_analyze_fx( { FOR( Word32 j = 0; j < NFFT; j++ ) { - out_DFT_fx[chan][j] = L_shr( out_DFT_fx[chan][j], sub( q_out_DFT[chan], q_DFT ) ); + out_DFT_fx[chan][j] = L_shr( out_DFT_fx[chan][j], sub( q_out_DFT[chan], q_DFT ) ); /* q_DFT */ move32(); } q_out_DFT[chan] = q_DFT; @@ -931,7 +931,7 @@ void stereo_dft_dec_analyze_fx( { FOR( Word32 j = 0; j < NFFT; j++ ) { - DFT_fx[j] = L_shr( DFT_fx[j], sub( q_DFT, q_out_DFT[chan] ) ); + DFT_fx[j] = L_shr( DFT_fx[j], sub( q_DFT, q_out_DFT[chan] ) ); /* q_DFT */ move32(); } q_DFT = q_out_DFT[chan]; @@ -943,11 +943,11 @@ void stereo_dft_dec_analyze_fx( test(); IF( ( ana_type == DFT_STEREO_DEC_ANA_FB ) || EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB ) || EQ_32( ana_type, DFT_STEREO_DEC_ANA_NOCORE ) ) { - pDFT_out_fx[0] = L_shl( Mpy_32_32( DFT_fx[0], fac_fx ), sub( 31, qfac_fx ) ); /*DC*/ + pDFT_out_fx[0] = L_shl( Mpy_32_32( DFT_fx[0], fac_fx ), sub( 31, qfac_fx ) ); /*DC*/ /* qDFT */ move32(); IF( EQ_16( NFFT, hStereoDft->NFFT ) ) /*Nyquist*/ { - pDFT_out_fx[1] = L_shl( Mpy_32_32( DFT_fx[1], fac_fx ), sub( 31, qfac_fx ) ); + pDFT_out_fx[1] = L_shl( Mpy_32_32( DFT_fx[1], fac_fx ), sub( 31, qfac_fx ) ); /* qDFT */ move32(); } ELSE @@ -957,51 +957,51 @@ void stereo_dft_dec_analyze_fx( } FOR( i = 2; i < NFFT; i++ ) { - pDFT_out_fx[i] = L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), sub( 31, qfac_fx ) ); + pDFT_out_fx[i] = L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), sub( 31, qfac_fx ) ); /* qDFT */ move32(); } FOR( i = NFFT; i < hStereoDft->NFFT; i++ ) { - pDFT_out_fx[i] = 0; + pDFT_out_fx[i] = 0; /* qDFT */ move32(); } } ELSE IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_BPF ) ) { - pDFT_out_fx[0] = L_sub( pDFT_out_fx[0], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[0], fac_fx ), dft_bpf_weights_fx[0] ), sub( 32, qfac_fx ) ) ); + pDFT_out_fx[0] = L_sub( pDFT_out_fx[0], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[0], fac_fx ), dft_bpf_weights_fx[0] ), sub( 32, qfac_fx ) ) ); /* qDFT */ move32(); FOR( i = 1; i < STEREO_DFT_BPF_SIZE; i++ ) { - pDFT_out_fx[2 * i] = L_sub( pDFT_out_fx[2 * i], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[2 * i], fac_fx ), dft_bpf_weights_fx[i] ), sub( 32, qfac_fx ) ) ); + pDFT_out_fx[2 * i] = L_sub( pDFT_out_fx[2 * i], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[2 * i], fac_fx ), dft_bpf_weights_fx[i] ), sub( 32, qfac_fx ) ) ); /* qDFT */ move32(); - pDFT_out_fx[add( 2 * i, 1 )] = L_sub( pDFT_out_fx[add( 2 * i, 1 )], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[add( 2 * i, 1 )], fac_fx ), dft_bpf_weights_fx[i] ), sub( 32, qfac_fx ) ) ); + pDFT_out_fx[2 * i + 1] = L_sub( pDFT_out_fx[2 * i + 1], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[2 * i + 1], fac_fx ), dft_bpf_weights_fx[i] ), sub( 32, qfac_fx ) ) ); /* qDFT */ move32(); } } ELSE IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_HB_ADD ) ) { - NFFT_core = NS2SA_FX2( L_mult0( hCPE->hCoreCoder[0]->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_N_NS ); + NFFT_core = NS2SA_FX2( L_mult0( hCPE->hCoreCoder[0]->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_N_NS ); /* Q0 */ move16(); FOR( i = NFFT_core; i < NFFT; i++ ) { - pDFT_out_fx[i] = L_add( L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), sub( 31, qfac_fx ) ), pDFT_out_fx[i] ); + pDFT_out_fx[i] = L_add( L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), sub( 31, qfac_fx ) ), pDFT_out_fx[i] ); /* qDFT */ move32(); } } ELSE { - pDFT_out_fx[0] = L_add( pDFT_out_fx[0], L_shl( Mpy_32_32( DFT_fx[0], fac_fx ), sub( 31, qfac_fx ) ) ); /*DC*/ + pDFT_out_fx[0] = L_add( pDFT_out_fx[0], L_shl( Mpy_32_32( DFT_fx[0], fac_fx ), sub( 31, qfac_fx ) ) ); /*DC*/ /* qDFT */ move32(); IF( EQ_16( NFFT, hStereoDft->NFFT ) ) /*Nyquist*/ { - pDFT_out_fx[1] = L_add( L_shl( Mpy_32_32( DFT_fx[1], fac_fx ), sub( 31, qfac_fx ) ), pDFT_out_fx[1] ); + pDFT_out_fx[1] = L_add( L_shl( Mpy_32_32( DFT_fx[1], fac_fx ), sub( 31, qfac_fx ) ), pDFT_out_fx[1] ); /* qDFT */ move32(); } FOR( i = 2; i < NFFT; i++ ) { - pDFT_out_fx[i] = L_add( L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), sub( 31, qfac_fx ) ), pDFT_out_fx[i] ); + pDFT_out_fx[i] = L_add( L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), sub( 31, qfac_fx ) ), pDFT_out_fx[i] ); /* qDFT */ move32(); } } diff --git a/lib_dec/ivas_stereo_dft_dec_dmx.c b/lib_dec/ivas_stereo_dft_dec_dmx.c index f1b7055e4a536de275a31390c4f7db84f1c7e428..2613f09d08444294b0ad0a974cd762049515a7f5 100644 --- a/lib_dec/ivas_stereo_dft_dec_dmx.c +++ b/lib_dec/ivas_stereo_dft_dec_dmx.c @@ -72,9 +72,9 @@ void stereo_dft_dmx_out_reset_fx( STEREO_DFT_DMX_DATA_HANDLE hStereoDftDmx /* i/o: DFT stereo DMX decoder */ ) { - hStereoDftDmx->targetGain_fx = ONE_IN_Q29; + hStereoDftDmx->targetGain_fx = ONE_IN_Q29; /* Q29 */ move32(); - hStereoDftDmx->prevTargetGain_fx = ONE_IN_Q29; + hStereoDftDmx->prevTargetGain_fx = ONE_IN_Q29; /* Q29 */ move32(); set32_fx( hStereoDftDmx->memOutHB_fx, 0, NS2SA_FX2( 48000, STEREO_DFT32MS_OVL_NS ) ); @@ -94,11 +94,11 @@ void stereo_dft_dmx_out_reset_fx( #ifdef IVAS_FLOAT_FIXED void stereo_dft_unify_dmx_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ - Decoder_State *st0, /* i/o: decoder state structure */ - Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ - Word32 *input_mem, /* i/o: mem of buffer DFT analysis */ - const Word16 prev_sid_nodata /* i : Previous SID/No data indicator */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ + Decoder_State *st0, /* i/o: decoder state structure */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers hStereoDft->qDFT*/ + Word32 *input_mem, /* i/o: mem of buffer DFT analysis Q11*/ + const Word16 prev_sid_nodata /* i : Previous SID/No data indicator Q0*/ ) { Word16 i, k, b, N_div; @@ -122,11 +122,11 @@ void stereo_dft_unify_dmx_fx( Word16 num_plocs; Word32 plocsi[STEREO_DFT_RES_N_PEAKS_MAX]; - output_frame = extract_l( Mult_32_16( st0->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); + output_frame = extract_l( Mult_32_16( st0->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); /* Q0 */ samp_ratio = BASOP_Util_Divide3232_Scale( st0->sr_core, st0->output_Fs, &q_samp_ratio ); samp_ratio = shr( samp_ratio, sub( Q15 - Q12, q_samp_ratio ) ); - prev_bfi = st0->prev_old_bfi; + prev_bfi = st0->prev_old_bfi; /* Q0 */ move32(); /* Initialization */ @@ -158,7 +158,7 @@ void stereo_dft_unify_dmx_fx( test(); test(); hStereoDft->trans = (Word16) ( ( EQ_16( st0->clas_dec, ONSET ) || EQ_16( st0->clas_dec, SIN_ONSET ) || EQ_16( st0->clas_dec, UNVOICED_CLAS ) || EQ_16( st0->clas_dec, UNVOICED_TRANSITION ) ) || LE_16( st0->stab_fac_fx, (Word16) 0x2000 ) ) || - ( ( EQ_16( st0->core, TCX_20_CORE ) && ( EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) || EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, HALF_OVERLAP ) ) ) || EQ_16( st0->core, TCX_10_CORE ) ); + ( ( EQ_16( st0->core, TCX_20_CORE ) && ( EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) || EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, HALF_OVERLAP ) ) ) || EQ_16( st0->core, TCX_10_CORE ) ); /* Q0 */ move16(); /* Smoothing for the current frame */ @@ -166,15 +166,15 @@ void stereo_dft_unify_dmx_fx( FOR( k = 0; k < N_div; k++ ) { - pDFT_DMX = DFT[0] + i_mult( k, STEREO_DFT32MS_N_MAX ); - pDFT_RES = DFT[1] + i_mult( k, STEREO_DFT32MS_N_MAX ); + pDFT_DMX = DFT[0] + i_mult( k, STEREO_DFT32MS_N_MAX ); /* qDFT */ + pDFT_RES = DFT[1] + i_mult( k, STEREO_DFT32MS_N_MAX ); /* qDFT */ assert( hStereoDft->hConfig->dmx_active ); /*Apply Stereo*/ g = MAX_16; move16(); /* since delay is just 3.125ms, the parameters received are used for the second window */ - pSideGain = hStereoDft->side_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); + pSideGain = hStereoDft->side_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); /* Q31 */ /* Stereo residual PLC */ IF( hStereoDft->res_cod_band_max > 0 ) @@ -183,7 +183,7 @@ void stereo_dft_unify_dmx_fx( { IF( EQ_16( k, 1 ) ) { - Copy32( pDFT_RES, hStereoDft->res_mem_fx, shl( hStereoDft->band_limits[hStereoDft->res_cod_band_max], 1 ) ); + Copy32( pDFT_RES, hStereoDft->res_mem_fx, shl( hStereoDft->band_limits[hStereoDft->res_cod_band_max], 1 ) ); /* qDFT */ hStereoDft->q_res_mem = hStereoDft->q_dft; move16(); hStereoDft->time_offs = 0; @@ -194,7 +194,7 @@ void stereo_dft_unify_dmx_fx( { hStereoDft->nbands = hStereoDft->res_cod_band_max; /* Limit nbands since residual PLC only needs the low frequency range of the stereo filling */ move16(); - pPredGain = hStereoDft->res_pred_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); + pPredGain = hStereoDft->res_pred_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); /* Q31 */ hStereoDft->past_DMX_pos = ( sub( add( hStereoDft->past_DMX_pos, STEREO_DFT_PAST_MAX ), 1 ) ) % STEREO_DFT_PAST_MAX; move16(); stereo_dft_generate_res_pred_fx( hStereoDft, samp_ratio, pDFT_DMX, DFT_PRED_RES, pPredGain, k, DFT[1] + k * STEREO_DFT32MS_N_MAX, &stop, st0->bfi ); @@ -206,7 +206,7 @@ void stereo_dft_unify_dmx_fx( /* Apply active DMX */ - DFT_L[0] = pDFT_DMX[0]; + DFT_L[0] = pDFT_DMX[0]; /* qDFT */ move32(); DFT_R[0] = pDFT_DMX[0]; move32(); @@ -214,23 +214,23 @@ void stereo_dft_unify_dmx_fx( /* upmix residual part */ FOR( b = 0; b < hStereoDft->res_cod_band_max; b++ ) { - g = extract_h( pSideGain[b] ); + g = extract_h( pSideGain[b] ); /* Q15 */ move16(); FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { - tmp = Madd_32_16( pDFT_RES[2 * i], pDFT_DMX[2 * i], g ); + tmp = Madd_32_16( pDFT_RES[2 * i], pDFT_DMX[2 * i], g ); /* qDFT */ - DFT_L[2 * i] = L_add( pDFT_DMX[2 * i], tmp ); + DFT_L[2 * i] = L_add( pDFT_DMX[2 * i], tmp ); /* qDFT */ move32(); - DFT_R[2 * i] = L_sub( pDFT_DMX[2 * i], tmp ); + DFT_R[2 * i] = L_sub( pDFT_DMX[2 * i], tmp ); /* qDFT */ move32(); tmp = Madd_32_16( pDFT_RES[2 * i + 1], pDFT_DMX[2 * i + 1], g ); - DFT_L[2 * i + 1] = L_add( pDFT_DMX[2 * i + 1], tmp ); + DFT_L[2 * i + 1] = L_add( pDFT_DMX[2 * i + 1], tmp ); /* qDFT */ move32(); - DFT_R[2 * i + 1] = L_sub( pDFT_DMX[2 * i + 1], tmp ); + DFT_R[2 * i + 1] = L_sub( pDFT_DMX[2 * i + 1], tmp ); /* qDFT */ move32(); } } @@ -253,11 +253,11 @@ void stereo_dft_unify_dmx_fx( FOR( j = hStereoDft->band_limits[b]; j < hStereoDft->band_limits[b + 1]; j++ ) { - sum_nrg_L = W_add( sum_nrg_L, W_add( W_mult_32_32( DFT_L[2 * j], DFT_L[2 * j] ), W_mult_32_32( DFT_L[add( shl( j, 1 ), 1 )], DFT_L[add( shl( j, 1 ), 1 )] ) ) ); - sum_nrg_R = W_add( sum_nrg_R, W_add( W_mult_32_32( DFT_R[2 * j], DFT_R[2 * j] ), W_mult_32_32( DFT_R[add( shl( j, 1 ), 1 )], DFT_R[add( shl( j, 1 ), 1 )] ) ) ); + sum_nrg_L = W_add( sum_nrg_L, W_add( W_mult_32_32( DFT_L[2 * j], DFT_L[2 * j] ), W_mult_32_32( DFT_L[2 * j + 1], DFT_L[2 * j + 1] ) ) ); /* 2 * q_dft + 1 */ + sum_nrg_R = W_add( sum_nrg_R, W_add( W_mult_32_32( DFT_R[2 * j], DFT_R[2 * j] ), W_mult_32_32( DFT_R[2 * j + 1], DFT_R[2 * j + 1] ) ) ); /* 2 * q_dft + 1 */ - dot_prod_real = W_add( dot_prod_real, W_add( W_mult_32_32( DFT_L[2 * j], DFT_R[2 * j] ), W_mult_32_32( DFT_L[2 * j + 1], DFT_R[add( shl( j, 1 ), 1 )] ) ) ); - dot_prod_img = W_add( dot_prod_img, W_sub( W_mult_32_32( DFT_L[add( shl( j, 1 ), 1 )], DFT_R[2 * j] ), W_mult_32_32( DFT_L[2 * j], DFT_R[add( shl( j, 1 ), 1 )] ) ) ); + dot_prod_real = W_add( dot_prod_real, W_add( W_mult_32_32( DFT_L[2 * j], DFT_R[2 * j] ), W_mult_32_32( DFT_L[2 * j + 1], DFT_R[2 * j + 1] ) ) ); /* 2 * q_dft + 1 */ + dot_prod_img = W_add( dot_prod_img, W_sub( W_mult_32_32( DFT_L[2 * j + 1], DFT_R[2 * j] ), W_mult_32_32( DFT_L[2 * j], DFT_R[2 * j + 1] ) ) ); /* 2 * q_dft + 1 */ } norm_sum_nrg_L = W_norm( sum_nrg_L ); @@ -281,7 +281,7 @@ void stereo_dft_unify_dmx_fx( exp_dot_prod_abs = sub( 31, sub( shl( q_dot_prod_real, 1 ), 31 ) ); exp_sum_nrg_Mid = sub( 31, q_sum_nrg_L ); - sum_nrg_Mid = L_max( 0, L_add( L_add( sum_nrg_L_32, sum_nrg_R_32 ), L_shl( dot_prod_real_32, 1 ) ) ); + sum_nrg_Mid = L_max( 0, L_add( L_add( sum_nrg_L_32, sum_nrg_R_32 ), L_shl( dot_prod_real_32, 1 ) ) ); /* q_sum_nrg_L */ Word32 tmp_nrg_L = Sqrt32( sum_nrg_L_32, &exp_sum_nrg_l ); Word32 tmp_nrg_R = Sqrt32( sum_nrg_R_32, &exp_sum_nrg_R ); @@ -296,7 +296,7 @@ void stereo_dft_unify_dmx_fx( exp_sum_abs = add( exp_sum_abs, 1 ); sum_abs = L_add( L_shr( tmp_nrg_L, sub( exp_sum_abs, exp_sum_nrg_l ) ), L_shr( tmp_nrg_R, sub( exp_sum_abs, exp_sum_nrg_R ) ) ); dot_prod_abs = Sqrt32( L_add( Mpy_32_32( dot_prod_real_32, dot_prod_real_32 ), Mpy_32_32( dot_prod_img_32, dot_prod_img_32 ) ), &exp_dot_prod_abs ); - Word32 num = L_add( L_shr( L_add( sum_nrg_L_32, sum_nrg_R_32 ), 1 ), L_shr( dot_prod_abs, sub( sub( 31, exp_dot_prod_abs ), q_sum_nrg_L ) ) ); + Word32 num = L_add( L_shr( L_add( sum_nrg_L_32, sum_nrg_R_32 ), 1 ), L_shr( dot_prod_abs, sub( sub( 31, exp_dot_prod_abs ), q_sum_nrg_L ) ) ); /* q_sum_nrg_L */ Word16 E_num = sub( 31, q_sum_nrg_L ); Word32 num_sqrt = Sqrt32( num, &E_num ); Word16 exp_wR = exp_sum_abs; @@ -322,7 +322,7 @@ void stereo_dft_unify_dmx_fx( } ELSE { - wR_temp = shr( divide3232( L_shr( num_sqrt, sub( exp_wR, E_num ) ), L_shr( sum_abs, sub( exp_wR, exp_sum_abs ) ) ), 2 ); + wR_temp = shr( divide3232( L_shr( num_sqrt, sub( exp_wR, E_num ) ), L_shr( sum_abs, sub( exp_wR, exp_sum_abs ) ) ), 2 ); /* Q13 */ } Word32 sum_nrg_Mid_sqrt = Sqrt32( sum_nrg_Mid, &exp_sum_nrg_Mid ); @@ -339,12 +339,12 @@ void stereo_dft_unify_dmx_fx( test(); IF( sum_nrg_Mid_sqrt == 0 && sum_abs == 0 ) { - wL_temp = 6364; + wL_temp = 6364; /* Q13 */ move16(); } ELSE IF( sum_nrg_Mid_sqrt == 0 && sum_abs != 0 ) { - wL_temp = 5793; + wL_temp = 5793; /* Q13 */ move16(); } ELSE @@ -365,12 +365,12 @@ void stereo_dft_unify_dmx_fx( move32(); } } - Copy32( pDFT_DMX, DFT[0] + i_mult( k, STEREO_DFT32MS_N_MAX ), hStereoDft->NFFT ); + Copy32( pDFT_DMX, DFT[0] + i_mult( k, STEREO_DFT32MS_N_MAX ), hStereoDft->NFFT ); /* hStereoDft->q_dft */ /* Update DFT_past_DMX, needed for stereo filling used by stereo residual PLC */ - hStereoDft->past_DMX_pos = ( hStereoDft->past_DMX_pos + 1 ) % STEREO_DFT_PAST_MAX; + hStereoDft->past_DMX_pos = ( hStereoDft->past_DMX_pos + 1 ) % STEREO_DFT_PAST_MAX; /* Q0 */ move16(); - Copy32( pDFT_DMX, hStereoDft->DFT_past_DMX_fx[hStereoDft->past_DMX_pos], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ) ); + Copy32( pDFT_DMX, hStereoDft->DFT_past_DMX_fx[hStereoDft->past_DMX_pos], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ) ); /* hStereoDft->q_dft */ hStereoDft->q_DFT_past_DMX_fx[hStereoDft->past_DMX_pos] = hStereoDft->q_dft; move16(); test(); @@ -387,7 +387,7 @@ void stereo_dft_unify_dmx_fx( q_shift1 = sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[idx_k1] ); /*dmx energy memory*/ - hStereoDft->past_dmx_nrg_fx = stereo_dft_dmx_swb_nrg_fx( hStereoDft->DFT_past_DMX_fx[idx_k0], hStereoDft->DFT_past_DMX_fx[idx_k1], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ), q_shift0, q_shift1 ); + hStereoDft->past_dmx_nrg_fx = stereo_dft_dmx_swb_nrg_fx( hStereoDft->DFT_past_DMX_fx[idx_k0], hStereoDft->DFT_past_DMX_fx[idx_k1], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ), q_shift0, q_shift1 ); /* 2 * q_dft */ move32(); } } @@ -665,11 +665,11 @@ void add_HB_to_mono_dmx( } #else void add_HB_to_mono_dmx_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 output[L_FRAME48k], /* i/o: output synthesis */ - Word32 outputHB[L_FRAME48k], /* i : HB synthesis */ - const int16_t last_core, /* i : last core, primary channel */ - const int16_t output_frame /* i : frame length */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 output[L_FRAME48k], /* i/o: output synthesis Qx*/ + Word32 outputHB[L_FRAME48k], /* i : HB synthesis Q11*/ + const Word16 last_core, /* i : last core, primary channel Q0*/ + const Word16 output_frame /* i : frame length Q0*/ ) { Word16 i, j, decoderDelay, icbweOLASize, dftOvlLen, memOffset; @@ -682,10 +682,10 @@ void add_HB_to_mono_dmx_fx( Word32 output_Fs; Word32 *memOutHB_fx, *memTransitionHB_fx; - output_Fs = hCPE->hCoreCoder[0]->output_Fs; + output_Fs = hCPE->hCoreCoder[0]->output_Fs; /* Q0 */ move32(); - memOutHB_fx = hCPE->hStereoDftDmx->memOutHB_fx; - memTransitionHB_fx = hCPE->hStereoDftDmx->memTransitionHB_fx; + memOutHB_fx = hCPE->hStereoDftDmx->memOutHB_fx; /* Q11 */ + memTransitionHB_fx = hCPE->hStereoDftDmx->memTransitionHB_fx; /* Q11 */ memOffset = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); move16(); @@ -729,24 +729,24 @@ void add_HB_to_mono_dmx_fx( } alpha_fx = winSlope_fx; // Q30 move32(); - FOR( ; i < add( decoderDelay, icbweOLASize ); i++ ) + FOR( ; i < decoderDelay + icbweOLASize; i++ ) { - temp_fx[i] = L_shl( Mpy_32_32( temp_fx[i], alpha_fx ), 1 ); + temp_fx[i] = L_shl( Mpy_32_32( temp_fx[i], alpha_fx ), 1 ); // Q30 move32(); - alpha_fx = L_add_sat( alpha_fx, winSlope_fx ); + alpha_fx = L_add_sat( alpha_fx, winSlope_fx ); /* Q30 */ } } ELSE { - Copy32( memOutHB_fx, temp_fx, memOffset ); + Copy32( memOutHB_fx, temp_fx, memOffset ); /* Q11 */ } v_add_32( temp_fx, output, output, output_frame ); - Copy32( outputHB + sub( output_frame, memOffset ), memOutHB_fx, memOffset ); + Copy32( outputHB + sub( output_frame, memOffset ), memOutHB_fx, memOffset ); /* Q11 */ - win_dft_fx = hCPE->hStereoDft->win32ms_fx; - dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; + win_dft_fx = hCPE->hStereoDft->win32ms_fx; /* Q15 */ + dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; /* Q0 */ move16(); /* Preparing buffers in anticipation of an ACELP to TCX switch */ @@ -754,16 +754,16 @@ void add_HB_to_mono_dmx_fx( move16(); FOR( i = 0; i < memOffset; i++ ) { - memTransitionHB_fx[i] = Mpy_32_16_1( memOutHB_fx[i], win_dft_fx[i_mult( STEREO_DFT32MS_STEP, ( sub( dftOvlLen, add( 1, j ) ) ) )] ); + memTransitionHB_fx[i] = Mpy_32_16_1( memOutHB_fx[i], win_dft_fx[STEREO_DFT32MS_STEP * ( dftOvlLen - 1 - j )] ); /* Q11 */ move32(); - j = add( j, 1 ); + j++; } FOR( i = 0; j < dftOvlLen; i++ ) { - memTransitionHB_fx[add( memOffset, i )] = Mpy_32_16_1( outputHB[sub( output_frame, i ) - 1], win_dft_fx[i_mult( STEREO_DFT32MS_STEP, ( sub( dftOvlLen, add( 1, j ) ) ) )] ); + memTransitionHB_fx[memOffset + i] = Mpy_32_16_1( outputHB[output_frame - i - 1], win_dft_fx[STEREO_DFT32MS_STEP * ( dftOvlLen - 1 - j )] ); /* Q11 */ move32(); - j = add( j, 1 ); + j++; } } ELSE diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 87cc8fc2c5ed46753a4d5e515ced74668750874b..71aaec7dfcc375ddb1c60a8d7a5e7088382aaefc 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -285,79 +285,79 @@ void stereo_dft_dec_reset_fx( *-------------------------------------------------------------------------*/ static void stereo_dft_dec_open_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word16 nchan_transport /* i : number of transport channels */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word32 output_Fs, /* i : output sampling rate Q0*/ + const Word16 nchan_transport /* i : number of transport channels Q0*/ ) { /*Sizes*/ // hStereoDft->N = (Word16) ( STEREO_DFT_HOP_MAX * output_Fs / 48000 ); - hStereoDft->N = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT_HOP_MAX ), 44740 ) ); + hStereoDft->N = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT_HOP_MAX ), 44740 /* 1/48000 in Q31 */ ) ); /* Q0 */ move16(); /*Init. DFT sizes*/ - hStereoDft->NFFT = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT32MS_N_MAX ), 44740 ) ); + hStereoDft->NFFT = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT32MS_N_MAX ), 44740 /* 1/48000 in Q31 */ ) ); /* Q0 */ move16(); - hStereoDft->dft_trigo_8k_fx = dft_trigo_32k_fx; - hStereoDft->dft_trigo_12k8_fx = dft_trigo_12k8_fx; - hStereoDft->dft_trigo_16k_fx = dft_trigo_32k_fx; + hStereoDft->dft_trigo_8k_fx = dft_trigo_32k_fx; /* Q15 */ + hStereoDft->dft_trigo_12k8_fx = dft_trigo_12k8_fx; /* Q15 */ + hStereoDft->dft_trigo_16k_fx = dft_trigo_32k_fx; /* Q15 */ - hStereoDft->dft32ms_ovl = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); - hStereoDft->win232ms_8k_fx = dft_win232ms_8k_fx; - hStereoDft->win232ms_12k8_fx = dft_win232ms_12k8_fx; - hStereoDft->win232ms_16k_fx = dft_win232ms_16k_fx; + hStereoDft->dft32ms_ovl = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 /* 1/48000 in Q31 */ ) ); /* Q0 */ + hStereoDft->win232ms_8k_fx = dft_win232ms_8k_fx; /* Q15 */ + hStereoDft->win232ms_12k8_fx = dft_win232ms_12k8_fx; /* Q15 */ + hStereoDft->win232ms_16k_fx = dft_win232ms_16k_fx; /* Q15 */ - hStereoDft->dft32ms_ovl2 = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT32MS_OVL2_MAX ), 44740 ) ); - hStereoDft->win32ms_8k_fx = dft_win232ms_8k_fx + 1; - hStereoDft->win32ms_12k8_fx = dft_win232ms_12k8_fx + 1; - hStereoDft->win32ms_16k_fx = dft_win232ms_16k_fx + 1; + hStereoDft->dft32ms_ovl2 = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT32MS_OVL2_MAX ), 44740 /* 1/48000 in Q31 */ ) ); /* Q0 */ + hStereoDft->win32ms_8k_fx = dft_win232ms_8k_fx + 1; /* Q15 */ + hStereoDft->win32ms_12k8_fx = dft_win232ms_12k8_fx + 1; /* Q15 */ + hStereoDft->win32ms_16k_fx = dft_win232ms_16k_fx + 1; /* Q15 */ IF( EQ_32( output_Fs, 16000 ) ) { - hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; - hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; + hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; /* Q15 */ + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; /* Q0 */ move16(); - hStereoDft->win232ms_fx = dft_win232ms_16k_fx; - hStereoDft->win32ms_fx = dft_win232ms_16k_fx + 1; + hStereoDft->win232ms_fx = dft_win232ms_16k_fx; /* Q15 */ + hStereoDft->win32ms_fx = dft_win232ms_16k_fx + 1; /* Q15 */ } ELSE IF( EQ_32( output_Fs, 32000 ) ) { - hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; - hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; + hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; /* Q15 */ + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; /* Q0 */ move16(); - hStereoDft->win232ms_fx = dft_win232ms_32k_fx; - hStereoDft->win32ms_fx = dft_win232ms_32k_fx + 1; + hStereoDft->win232ms_fx = dft_win232ms_32k_fx; /* Q15 */ + hStereoDft->win32ms_fx = dft_win232ms_32k_fx + 1; /* Q15 */ } ELSE { assert( output_Fs == 48000 ); - hStereoDft->dft_trigo_fx = dft_trigo_48k_fx; - hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; + hStereoDft->dft_trigo_fx = dft_trigo_48k_fx; /* Q15 */ + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; /* Q0 */ move16(); - hStereoDft->win232ms_fx = dft_win232ms_48k_fx; - hStereoDft->win32ms_fx = dft_win232ms_48k_fx + 1; + hStereoDft->win232ms_fx = dft_win232ms_48k_fx; /* Q15 */ + hStereoDft->win32ms_fx = dft_win232ms_48k_fx + 1; /* Q15 */ } - hStereoDft->win_8k_fx = dft_win_8k_fx; + hStereoDft->win_8k_fx = dft_win_8k_fx; /* Q15 */ /*Bands: find the number of bands, Nyquist freq. is not taken into account*/ set16_fx( hStereoDft->band_res, hStereoDft->hConfig->band_res, STEREO_DFT_DEC_DFT_NB ); - hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[0], hStereoDft->NFFT, DEC ); + hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[0], hStereoDft->NFFT, DEC ); /* Q0 */ move16(); - hStereoDft->hb_stefi_delay = NS2SA_FX2( output_Fs, STEREO_DFT_TD_STEFI_DELAY_NS ); + hStereoDft->hb_stefi_delay = NS2SA_FX2( output_Fs, STEREO_DFT_TD_STEFI_DELAY_NS ); /* Q0 */ move16(); IF( GT_16( nchan_transport, 2 ) ) { - hStereoDft->min_smooth_gains_fx = min_smooth_gains2_fx; - hStereoDft->max_smooth_gains_fx = max_smooth_gains2_fx; + hStereoDft->min_smooth_gains_fx = min_smooth_gains2_fx; /* Q15 */ + hStereoDft->max_smooth_gains_fx = max_smooth_gains2_fx; /* Q15 */ } ELSE { - hStereoDft->min_smooth_gains_fx = min_smooth_gains1_fx; - hStereoDft->max_smooth_gains_fx = max_smooth_gains1_fx; + hStereoDft->min_smooth_gains_fx = min_smooth_gains1_fx; /* Q15 */ + hStereoDft->max_smooth_gains_fx = max_smooth_gains1_fx; /* Q15 */ } hStereoDft->q_hb_stefi_sig_fx = Q31; move16(); @@ -378,11 +378,11 @@ static void stereo_dft_dec_open_fx( *------------------------------------------------------------------------*/ ivas_error stereo_dft_dec_create_fx( - STEREO_DFT_DEC_DATA_HANDLE *hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word32 element_brate, /* i : element bitrate */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ - const Word16 nchan_transport /* i : number of transport channels */ + STEREO_DFT_DEC_DATA_HANDLE *hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word32 output_Fs, /* i : output sampling rate Q0*/ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC Q0*/ + const Word16 nchan_transport /* i : number of transport channels Q0*/ ) { STEREO_DFT_DEC_DATA_HANDLE hStereoDft_loc; @@ -443,11 +443,12 @@ ivas_error stereo_dft_dec_create_fx( *-------------------------------------------------------------------------*/ static void stereo_dft_dequantize_res_gains_fx( - Word16 *ind1, - Word16 *ind2, - Word32 *gout, - Word32 *rout, - const Word16 N ) + Word16 *ind1, /* Q0 */ + Word16 *ind2, /* Q0 */ + Word32 *gout, /* Q31 */ + Word32 *rout, /* Q31 */ + const Word16 N /* Q0 */ +) { Word16 i, index; Word16 tmp; @@ -455,9 +456,9 @@ static void stereo_dft_dequantize_res_gains_fx( FOR( i = 0; i < N; i++ ) { /* Ensure the indices are within range -- may go out of range due to frame loss */ - ind1[i] = check_bounds_s( ind1[i], 0, 30 ); + ind1[i] = check_bounds_s( ind1[i], 0, 30 ); /* Q0 */ move16(); - ind2[i] = check_bounds_s( ind2[i], 0, 7 ); + ind2[i] = check_bounds_s( ind2[i], 0, 7 ); /* Q0 */ move16(); IF( LE_16( ind1[i], 15 ) ) { @@ -472,15 +473,15 @@ static void stereo_dft_dequantize_res_gains_fx( // gout[i] = LE_16( ind1[i], 15 ) ? L_negate( dft_res_gains_q_fx[index][0] ) : dft_res_gains_q_fx[index][0]; IF( LE_16( ind1[i], 15 ) ) { - gout[i] = L_negate( dft_res_gains_q_fx[index][0] ); + gout[i] = L_negate( dft_res_gains_q_fx[index][0] ); /* Q31 */ move16(); } ELSE { - gout[i] = dft_res_gains_q_fx[index][0]; + gout[i] = dft_res_gains_q_fx[index][0]; /* Q31 */ move16(); } - rout[i] = dft_res_gains_q_fx[index][1]; + rout[i] = dft_res_gains_q_fx[index][1]; /* Q31 */ move16(); } @@ -494,11 +495,12 @@ static void stereo_dft_dequantize_res_gains_fx( *---------------------------------------------------------------------------*/ static void stereo_dft_dequantize_res_gains_f_fx( - Word32 *ind1, - Word32 *ind2, - Word32 *gout, - Word32 *rout, - const Word16 N ) + Word32 *ind1, /* Q26 */ + Word32 *ind2, /* Q26 */ + Word32 *gout, /* Q31 */ + Word32 *rout, /* Q31 */ + const Word16 N /* Q0 */ +) { Word16 i, i1, j1, sign, ji, ij; Word32 L_tmp; @@ -507,9 +509,9 @@ static void stereo_dft_dequantize_res_gains_f_fx( FOR( i = 0; i < N; i++ ) { /* Ensure the indices are within range -- may go out of range due to frame loss */ - ind1[i] = check_bounds_l( ind1[i], 0, 31 << Q26 ); + ind1[i] = check_bounds_l( ind1[i], 0, 31 << Q26 ); /* Q26 */ move32(); - ind2[i] = check_bounds_l( ind2[i], 0, 7 << Q26 ); + ind2[i] = check_bounds_l( ind2[i], 0, 7 << Q26 ); /* Q26 */ move32(); /* compensate for the offset and extract/remove sign of first index */ @@ -526,49 +528,49 @@ static void stereo_dft_dequantize_res_gains_f_fx( } IF( LT_32( ind1[i], L_shl( 15, Q26 ) ) ) { - L_tmp = L_sub( L_shl( 15, Q26 ), ind1[i] ); + L_tmp = L_sub( L_shl( 15, Q26 ), ind1[i] ); /* Q26 */ } ELSE { - L_tmp = L_sub( ind1[i], L_shl( 15, Q26 ) ); + L_tmp = L_sub( ind1[i], L_shl( 15, Q26 ) ); /* Q26 */ } - i1 = extract_l( L_shr( ( L_tmp ), Q26 ) ); + i1 = extract_l( L_shr( ( L_tmp ), Q26 ) ); /* Q0 */ IF( LT_32( ind1[i], L_shl( 15, Q26 ) ) ) { - L_tmp = L_sub( L_shl( 15, Q26 ), ind1[i] ); + L_tmp = L_sub( L_shl( 15, Q26 ), ind1[i] ); /* Q26 */ } ELSE { - L_tmp = L_sub( ind1[i], L_shl( 15, Q26 ) ); + L_tmp = L_sub( ind1[i], L_shl( 15, Q26 ) ); /* Q26 */ } - fi = L_sub( ( L_tmp ), L_shl( i1, Q26 ) ); + fi = L_sub( ( L_tmp ), L_shl( i1, Q26 ) ); /* Q26 */ move16(); - j1 = extract_l( L_shr( ind2[i], Q26 ) ); - fj = L_sub( ind2[i], L_shl( j1, Q26 ) ); + j1 = extract_l( L_shr( ind2[i], Q26 ) ); /* Q0 */ + fj = L_sub( ind2[i], L_shl( j1, Q26 ) ); /* Q26 */ /* choose base indices for interpolation */ IF( LT_32( fj, ONE_IN_Q25 ) ) { - ji = extract_l( L_min( j1, 7 ) ); + ji = extract_l( L_min( j1, 7 ) ); /* Q0 */ } ELSE { - ji = extract_l( L_min( add( j1, 1 ), 7 ) ); + ji = extract_l( L_min( add( j1, 1 ), 7 ) ); /* Q0 */ } IF( LT_32( fi, ONE_IN_Q25 ) ) { - ij = extract_l( L_min( i1, 15 ) ); + ij = extract_l( L_min( i1, 15 ) ); /* Q0 */ } ELSE { - ij = extract_l( L_min( add( i1, 1 ), 15 ) ); + ij = extract_l( L_min( add( i1, 1 ), 15 ) ); /* Q0 */ } /* interpolate values from table */ IF( LT_16( i1, 15 ) ) { - gout[i] = Madd_32_32( Mpy_32_32( L_sub( MAX_32, L_shl( fi, Q5 ) ), dft_res_gains_q_fx[add( shl( i1, 3 ), ji )][0] ), dft_res_gains_q_fx[add( shl( add( i1, 1 ), 3 ), ji )][0], L_shl( fi, Q5 ) ); + gout[i] = Madd_32_32( Mpy_32_32( L_sub( MAX_32, L_shl( fi, Q5 ) ), dft_res_gains_q_fx[( i1 << 3 ) + ji][0] ), dft_res_gains_q_fx[( ( i1 + 1 ) << 3 ) + ji][0], L_shl( fi, Q5 ) ); /* Q31 */ move32(); IF( EQ_16( sign, -1 ) ) { @@ -578,7 +580,7 @@ static void stereo_dft_dequantize_res_gains_f_fx( } ELSE { - gout[i] = dft_res_gains_q_fx[120 + ji][0]; + gout[i] = dft_res_gains_q_fx[120 + ji][0]; /* Q31 */ move32(); IF( EQ_16( sign, -1 ) ) { @@ -589,12 +591,12 @@ static void stereo_dft_dequantize_res_gains_f_fx( IF( LT_16( j1, 7 ) ) { - rout[i] = Madd_32_32( Mpy_32_32( L_sub( MAX_32, L_shl( fj, Q5 ) ), dft_res_gains_q_fx[add( shl( ij, 3 ), j1 )][1] ), L_shl( fj, Q5 ), dft_res_gains_q_fx[add( add( shl( ij, 3 ), j1 ), 1 )][1] ); + rout[i] = Madd_32_32( Mpy_32_32( L_sub( MAX_32, L_shl( fj, Q5 ) ), dft_res_gains_q_fx[( ij << 3 ) + j1][1] ), L_shl( fj, Q5 ), dft_res_gains_q_fx[( ij << 3 ) + j1 + 1][1] ); /* Q31 */ move32(); } ELSE { - rout[i] = dft_res_gains_q_fx[add( shl( ij, 3 ), 7 )][1]; + rout[i] = dft_res_gains_q_fx[( ij << 3 ) + 7][1]; /* Q31 */ move32(); } } @@ -608,9 +610,9 @@ static void stereo_dft_dequantize_res_gains_f_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_update_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word16 output_frame, /* i : output frame length */ - const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC Q0*/ ) { Word16 b, i, k_offset; @@ -621,30 +623,30 @@ void stereo_dft_dec_update_fx( /* Update parameters */ FOR( i = 0; i < k_offset * STEREO_DFT_BAND_MAX; i++ ) { - hStereoDft->side_gain_fx[i] = hStereoDft->side_gain_fx[STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX + i]; + hStereoDft->side_gain_fx[i] = hStereoDft->side_gain_fx[STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX + i]; /* Q31 */ move32(); - hStereoDft->res_pred_gain_fx[i] = hStereoDft->res_pred_gain_fx[STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX + i]; + hStereoDft->res_pred_gain_fx[i] = hStereoDft->res_pred_gain_fx[STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX + i]; /* Q31 */ move32(); } FOR( i = 0; i < k_offset; i++ ) { - hStereoDft->gipd_fx[i] = hStereoDft->gipd_fx[STEREO_DFT_NBDIV + i]; + hStereoDft->gipd_fx[i] = hStereoDft->gipd_fx[STEREO_DFT_NBDIV + i]; /* Q27 */ move32(); } /* Update configuration memories */ FOR( i = 0; i < k_offset; i++ ) { - hStereoDft->band_res[i] = hStereoDft->band_res[i + STEREO_DFT_NBDIV]; + hStereoDft->band_res[i] = hStereoDft->band_res[i + STEREO_DFT_NBDIV]; /* Q0 */ move16(); - hStereoDft->prm_res[i] = hStereoDft->prm_res[i + STEREO_DFT_NBDIV]; + hStereoDft->prm_res[i] = hStereoDft->prm_res[i + STEREO_DFT_NBDIV]; /* Q0 */ move16(); - hStereoDft->itd_fx[i] = hStereoDft->itd_fx[STEREO_DFT_NBDIV + i]; + hStereoDft->itd_fx[i] = hStereoDft->itd_fx[STEREO_DFT_NBDIV + i]; /* Q15 */ move32(); - hStereoDft->res_cod_mode[i] = hStereoDft->res_cod_mode[i + STEREO_DFT_NBDIV]; + hStereoDft->res_cod_mode[i] = hStereoDft->res_cod_mode[i + STEREO_DFT_NBDIV]; /* Q0 */ move16(); - hStereoDft->res_pred_mode[i] = hStereoDft->res_pred_mode[i + STEREO_DFT_NBDIV]; + hStereoDft->res_pred_mode[i] = hStereoDft->res_pred_mode[i + STEREO_DFT_NBDIV]; /* Q0 */ move16(); } @@ -668,13 +670,13 @@ void stereo_dft_dec_update_fx( FOR( i = STEREO_DFT_CORE_HIST_MAX - 1; i > 0; i-- ) { - hStereoDft->core_hist[i] = hStereoDft->core_hist[i - 1]; + hStereoDft->core_hist[i] = hStereoDft->core_hist[i - 1]; /* Q0 */ move16(); } - Copy32( hStereoDft->hb_stefi_sig_fx + output_frame, hStereoDft->hb_stefi_sig_fx, hStereoDft->hb_stefi_delay ); - Copy32( hStereoDft->hb_nrg_fx, hStereoDft->hb_nrg_fx + 1, STEREO_DFT_CORE_HIST_MAX - 1 ); - Copy32( hStereoDft->td_gain_fx, hStereoDft->td_gain_fx + 1, STEREO_DFT_CORE_HIST_MAX - 1 ); + Copy32( hStereoDft->hb_stefi_sig_fx + output_frame, hStereoDft->hb_stefi_sig_fx, hStereoDft->hb_stefi_delay ); /* Qx */ + Copy32( hStereoDft->hb_nrg_fx, hStereoDft->hb_nrg_fx + 1, STEREO_DFT_CORE_HIST_MAX - 1 ); /* Qx */ + Copy32( hStereoDft->td_gain_fx, hStereoDft->td_gain_fx + 1, STEREO_DFT_CORE_HIST_MAX - 1 ); /* q_td_gain */ #ifdef FIX_826_PRECISION_LOST_AND_COMPL Copy( hStereoDft->q_td_gain, hStereoDft->q_td_gain + 1, STEREO_DFT_CORE_HIST_MAX - 1 ); #else @@ -688,7 +690,7 @@ void stereo_dft_dec_update_fx( { FOR( i = SBA_DIRAC_NRG_SMOOTH_LONG; i > 1; i-- ) { - hStereoDft->smooth_buf_fx[b][i] = hStereoDft->smooth_buf_fx[b][i - 2]; + hStereoDft->smooth_buf_fx[b][i] = hStereoDft->smooth_buf_fx[b][i - 2]; /* q_smooth_buf_fx */ move32(); } } @@ -704,11 +706,11 @@ void stereo_dft_dec_update_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_synthesize_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i : DFT buffers */ - const Word16 chan, /* i : channel number */ - Word32 output[L_FRAME48k], /* o : output synthesis signal */ - const Word16 output_frame /* i : output frame length */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i : DFT buffers qDFT*/ + const Word16 chan, /* i : channel number Q0*/ + Word32 output[L_FRAME48k], /* o : output synthesis signal qDFT*/ + const Word16 output_frame /* i : output frame length Q0*/ ) { Word16 i, k; @@ -716,7 +718,7 @@ void stereo_dft_dec_synthesize_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft; Word32 *p_DFT; const Word16 *win, *win2; - Word16 trigo_dec[( ( STEREO_DFT32MS_N_MAX ) >> 1 ) + 1]; + Word16 trigo_dec[STEREO_DFT32MS_N_MAX / 2 + 1]; Word16 trigo_step; Word16 ovl, zp, NFFT; Word32 outputFs; @@ -734,20 +736,20 @@ void stereo_dft_dec_synthesize_fx( hCPE->lt_es_em_fx = L_shr( hCPE->lt_es_em_fx, 9 ); // Q24 -> Q15 - outputFs = L_mult0( output_frame, FRAMES_PER_SEC ); + outputFs = L_mult0( output_frame, FRAMES_PER_SEC ); /* Q0 */ zp = NS2SA_FX2( outputFs, STEREO_DFT32MS_ZP_NS ); move16(); ovl = NS2SA_FX2( outputFs, STEREO_DFT32MS_OVL_NS ); move16(); - win = hStereoDft->win32ms_fx; + win = hStereoDft->win32ms_fx; /* Q15 */ NFFT = NS2SA_FX2( outputFs, STEREO_DFT32MS_N_NS ); move16(); ovl2 = NS2SA_FX2( outputFs, STEREO_DFT32MS_OVL2_NS ); move16(); flat_portion_end = NS2SA_FX2( outputFs, L_sub( STEREO_DFT32MS_WIN_CENTER_NS, L_shr( STEREO_DFT32MS_OVL2_NS, 1 ) ) ); move16(); - win2 = hStereoDft->win232ms_fx; + win2 = hStereoDft->win232ms_fx; /* Q15 */ p_DFT = DFT[chan]; set32_fx( output, 0, NS2SA_FX2( outputFs, FRAME_SIZE_NS ) ); @@ -758,7 +760,7 @@ void stereo_dft_dec_synthesize_fx( test(); if ( ( chan == 0 && GT_16( hCPE->hCoreCoder[0]->last_coder_type, UNVOICED ) ) || EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) || LT_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { - hCPE->stereo_switching_counter = 10; + hCPE->stereo_switching_counter = 10; /* Q0 */ move16(); } @@ -766,7 +768,7 @@ void stereo_dft_dec_synthesize_fx( { /* Set the level of dispersion */ Word16 tmp = extract_l( L_max( (Word16) 0xF333, L_min( (Word16) 0x3333, hCPE->lt_es_em_fx ) ) ); - hCPE->NbFrameMod = extract_h( L_add( L_mult0( 12, tmp ), 0x0000D99A ) ); /* -0.1: -0.4 ; -0.1 -> 0, 0.4 -> 6*/ + hCPE->NbFrameMod = extract_h( L_add( L_mult0( 12, tmp ), 0x0000D99A ) ); /* -0.1: -0.4 ; -0.1 -> 0, 0.4 -> 6*/ /* Q0 */ move16(); } moffset = s_max( 0, sub( 6, hCPE->NbFrameMod ) ); @@ -775,15 +777,15 @@ void stereo_dft_dec_synthesize_fx( * Synthesis *-----------------------------------------------------------------*/ - trigo_step = i_mult( hStereoDft->dft_trigo_step, STEREO_DFT_TRIGO_DEC_STEP ); - FOR( i = 0; i < shr( NFFT, 2 ); i++ ) + trigo_step = i_mult( hStereoDft->dft_trigo_step, STEREO_DFT_TRIGO_DEC_STEP ); /* Q0 */ + FOR( i = 0; i < NFFT / 4; i++ ) { - trigo_dec[i] = hStereoDft->dft_trigo_fx[i_mult( i, trigo_step )]; + trigo_dec[i] = hStereoDft->dft_trigo_fx[i * trigo_step]; /* Q15 */ move16(); - trigo_dec[sub( shr( NFFT, 1 ), i )] = hStereoDft->dft_trigo_fx[i * trigo_step]; + trigo_dec[NFFT / 2 - i] = hStereoDft->dft_trigo_fx[i * trigo_step]; /* Q15 */ move16(); } - trigo_dec[shr( NFFT, 2 )] = hStereoDft->dft_trigo_fx[shr( NFFT, 2 ) * trigo_step]; + trigo_dec[NFFT / 4] = hStereoDft->dft_trigo_fx[NFFT / 4 * trigo_step]; /* Q15 */ move16(); FOR( k = 0; k < STEREO_DFT_NBDIV; k++ ) @@ -796,17 +798,17 @@ void stereo_dft_dec_synthesize_fx( test(); IF( LE_16( hCPE->stereo_switching_counter, 6 ) && EQ_16( chan, 1 ) && ( GT_32( hCPE->lt_es_em_fx, (Word16) 0xCCCD ) || GT_16( hCPE->NbFrameMod, 4 ) ) ) { - FOR( i = 3; i < sub( sub( NFFT, moffset ), 1 ); i++ ) + FOR( i = 3; i < NFFT - moffset - 1; i++ ) { - p_DFT[i] = L_negate( p_DFT[add( add( i, moffset ), 1 )] ); + p_DFT[i] = L_negate( p_DFT[i + moffset + 1] ); /* q_DFT */ move32(); } } ELSE IF( LT_16( hCPE->stereo_switching_counter, 7 ) && ( GT_32( hCPE->lt_es_em_fx, (Word16) 0x199A ) || GT_16( hCPE->NbFrameMod, 4 ) ) ) { - FOR( i = sub( 16, hCPE->NbFrameMod ); i < sub( NFFT, add( moffset, 1 ) ); i++ ) + FOR( i = 16 - hCPE->NbFrameMod; i < NFFT - moffset - 1; i++ ) { - p_DFT[i - 2] = L_negate( p_DFT[add( add( i, moffset ), 1 )] ); + p_DFT[i - 2] = L_negate( p_DFT[i + moffset + 1] ); /* q_DFT */ move32(); } } @@ -826,19 +828,19 @@ void stereo_dft_dec_synthesize_fx( /* Left OLA - 3.125ms */ FOR( i = 0; i < ovl; i++ ) { - output[add( offset, i )] = Madd_32_16( L_shr( hCPE->output_mem_fx[chan][i], sub( hCPE->q_output_mem_fx[chan], hCPE->hStereoDft->q_dft ) ), p_DFT[add( zp, i )], win[STEREO_DFT32MS_STEP * i] ); + output[offset + i] = Madd_32_16( L_shr( hCPE->output_mem_fx[chan][i], sub( hCPE->q_output_mem_fx[chan], hCPE->hStereoDft->q_dft ) ), p_DFT[zp + i], win[STEREO_DFT32MS_STEP * i] ); /* hCPE->hStereoDft->q_dft */ move32(); } /* Flat Portion */ FOR( i = ovl; i < flat_portion_end; i++ ) { - output[add( offset, i )] = p_DFT[add( zp, i )]; + output[offset + i] = p_DFT[zp + i]; /* hCPE->hStereoDft->q_dft */ move32(); } /* Right OLA */ FOR( i = 0; i < ovl2; i++ ) { - ola_buff[i] = Mpy_32_16_1( p_DFT[add( sub( NFFT, add( zp, ovl2 ) ), i )], win2[sub( sub( ovl2, i ), 1 )] ); + ola_buff[i] = Mpy_32_16_1( p_DFT[NFFT - zp - ovl2 + i], win2[ovl2 - 1 - i] ); /* hCPE->hStereoDft->q_dft */ move32(); } } @@ -850,19 +852,19 @@ void stereo_dft_dec_synthesize_fx( /* Left OLA */ FOR( i = 0; i < ovl2; i++ ) { - output[add( offset, i )] = Madd_32_16( ola_buff[i], p_DFT[add( zp, i )], win2[i] ); + output[offset + i] = Madd_32_16( ola_buff[i], p_DFT[zp + i], win2[i] ); /* hCPE->hStereoDft->q_dft */ move32(); } /* Flat Portion */ - FOR( i = ovl2; i < sub( NFFT, add( shl( zp, 1 ), ovl ) ); i++ ) + FOR( i = ovl2; i < NFFT - 2 * zp - ovl; i++ ) { - output[add( offset, i )] = p_DFT[add( zp, i )]; + output[offset + i] = p_DFT[zp + i]; /* hCPE->hStereoDft->q_dft */ move32(); } /* Right OLA - 3.125ms */ FOR( i = 0; i < ovl; i++ ) { - hCPE->output_mem_fx[chan][i] = Mpy_32_16_1( p_DFT[add( sub( NFFT, add( zp, ovl ) ), i )], win[i_mult( STEREO_DFT32MS_STEP, ( sub( sub( ovl, i ), 1 ) ) )] ); + hCPE->output_mem_fx[chan][i] = Mpy_32_16_1( p_DFT[NFFT - zp - ovl + i], win[STEREO_DFT32MS_STEP * ( ovl - 1 - i )] ); /* hCPE->hStereoDft->q_dft */ move32(); } hCPE->q_output_mem_fx[chan] = hCPE->hStereoDft->q_dft; @@ -886,9 +888,9 @@ void stereo_dft_dec_synthesize_fx( void stereo_dft_dec_smooth_parameters_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word16 prev_sid_nodata, /* i : Previous SID/No data indicator */ - const Word16 active_frame_counter, /* i : Active frame counter */ - const Word32 element_brate /* i : Element bitrate */ + const Word16 prev_sid_nodata, /* i : Previous SID/No data indicator Q0*/ + const Word16 active_frame_counter, /* i : Active frame counter Q0*/ + const Word32 element_brate /* i : Element bitrate Q0*/ ) { Word16 k_offset, k, k2, b, N_div; @@ -898,11 +900,18 @@ void stereo_dft_dec_smooth_parameters_fx( Word32 diff_ipd; Word16 nbands; Word32 max_res_pred_ind; +#ifdef FIX_874_INCREASE_IPD_PRECISION + Word32 PI_round; +#endif N_div = STEREO_DFT_NBDIV; move16(); k_offset = STEREO_DFT_OFFSET; move16(); +#ifdef FIX_874_INCREASE_IPD_PRECISION + PI_round = EVS_PI_FX_Q27 + EPSILLON_FX; /*add error corrections when comparing ipds with exactly a difference of pi*/ + move32(); +#endif test(); IF( hStereoDft->frame_sid_nodata || prev_sid_nodata ) @@ -910,7 +919,7 @@ void stereo_dft_dec_smooth_parameters_fx( k = 1; FOR( b = 0; b < hStereoDft->nbands; b++ ) { - *( hStereoDft->side_gain_fx + add( i_mult( sub( add( k, k_offset ), 1 ), STEREO_DFT_BAND_MAX ), b ) ) = *( hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ) ); + *( hStereoDft->side_gain_fx + add( i_mult( sub( add( k, k_offset ), 1 ), STEREO_DFT_BAND_MAX ), b ) ) = *( hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ) ); /* Q31 */ move32(); } @@ -924,11 +933,15 @@ void stereo_dft_dec_smooth_parameters_fx( #endif { Word16 q_val; - IF( GT_32( L_sub( hStereoDft->gipd_fx[add( k, k_offset )], hStereoDft->ipd_xfade_prev_fx ), EVS_PI_FX_Q27 ) ) + IF( GT_32( L_sub( hStereoDft->gipd_fx[k + k_offset], hStereoDft->ipd_xfade_prev_fx ), EVS_PI_FX_Q27 ) ) { +#ifdef FIX_874_INCREASE_IPD_PRECISION_A + hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[k + k_offset], EVS_PI_FX_Q27 << 1 ); /* Q27 */ +#else hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 ); +#endif move32(); - hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); + hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); /* Q27 */ move32(); q_val = add( q_val, Q9 ); /* Q27 - (Q15 - q_val + (-3))*/ @@ -939,16 +952,20 @@ void stereo_dft_dec_smooth_parameters_fx( } ELSE { - hStereoDft->ipd_xfade_step_fx = L_shl( hStereoDft->ipd_xfade_step_fx, q_val ); + hStereoDft->ipd_xfade_step_fx = L_shl( hStereoDft->ipd_xfade_step_fx, q_val ); /* Q27 */ move32(); } } - ELSE IF( GT_32( L_sub( hStereoDft->ipd_xfade_prev_fx, hStereoDft->gipd_fx[add( k, k_offset )] ), EVS_PI_FX_Q27 ) ) + ELSE IF( GT_32( L_sub( hStereoDft->ipd_xfade_prev_fx, hStereoDft->gipd_fx[k + k_offset] ), EVS_PI_FX_Q27 ) ) { +#ifndef FIX_874_INCREASE_IPD_PRECISION_A hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], L_shl( EVS_PI_FX_Q27, 1 ) ); +#else + hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[k + k_offset], EVS_PI_FX_Q27 << 1 ); /* Q27 */ +#endif move32(); - hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); - q_val = add( q_val, Q9 ); /* Q27 - (Q15 - q_val + (-3))*/ + hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); /* Q27 */ + q_val = add( q_val, Q9 ); /* Q27 - (Q15 - q_val + (-3))*/ move32(); IF( GT_16( q_val, 32 ) ) { @@ -956,13 +973,13 @@ void stereo_dft_dec_smooth_parameters_fx( } ELSE { - hStereoDft->ipd_xfade_step_fx = L_shl( hStereoDft->ipd_xfade_step_fx, q_val ); + hStereoDft->ipd_xfade_step_fx = L_shl( hStereoDft->ipd_xfade_step_fx, q_val ); /* Q27 */ move32(); } } ELSE { - hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[add( k, k_offset )]; + hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[k + k_offset]; /* Q27 */ move32(); hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); q_val = add( q_val, Q9 ); /* Q27 - (Q15 - q_val + (-3))*/ @@ -973,7 +990,7 @@ void stereo_dft_dec_smooth_parameters_fx( } ELSE { - hStereoDft->ipd_xfade_step_fx = L_shl( hStereoDft->ipd_xfade_step_fx, q_val ); + hStereoDft->ipd_xfade_step_fx = L_shl( hStereoDft->ipd_xfade_step_fx, q_val ); /* Q27 */ move32(); } } @@ -984,11 +1001,11 @@ void stereo_dft_dec_smooth_parameters_fx( test(); IF( NE_32( hStereoDft->ipd_xfade_prev_fx, hStereoDft->ipd_xfade_target_fx ) && LT_16( hStereoDft->ipd_xfade_counter, STEREO_DFT_ITD_CNG_XFADE ) && LE_32( hStereoDft->last_active_element_brate, 24400 ) ) { - hStereoDft->gipd_fx[add( k, k_offset )] = L_add( hStereoDft->ipd_xfade_prev_fx, hStereoDft->ipd_xfade_step_fx ); + hStereoDft->gipd_fx[k + k_offset] = L_add( hStereoDft->ipd_xfade_prev_fx, hStereoDft->ipd_xfade_step_fx ); /* Q27 */ move32(); - hStereoDft->ipd_xfade_prev_fx = hStereoDft->gipd_fx[add( k, k_offset )]; + hStereoDft->ipd_xfade_prev_fx = hStereoDft->gipd_fx[k + k_offset]; /* Q27 */ move32(); - hStereoDft->ipd_xfade_counter = add( hStereoDft->ipd_xfade_counter, 1 ); + hStereoDft->ipd_xfade_counter = add( hStereoDft->ipd_xfade_counter, 1 ); /* Q27 */ move16(); } } @@ -997,18 +1014,18 @@ void stereo_dft_dec_smooth_parameters_fx( /* First active frame, "reset" everything if long enough active encoding, only triggered if STEREO_DFT_ITD_CNG_XFADE_RESET = -1 */ IF( GT_16( active_frame_counter, STEREO_DFT_ITD_CNG_XFADE_RESET ) ) { - hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[add( k, k_offset )]; + hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[k + k_offset]; /* Q27 */ move32(); - hStereoDft->ipd_xfade_prev_fx = hStereoDft->gipd_fx[add( k, k_offset )]; + hStereoDft->ipd_xfade_prev_fx = hStereoDft->gipd_fx[k + k_offset]; /* Q27 */ move32(); hStereoDft->ipd_xfade_counter = 0; move16(); } } - FOR( k2 = 1; k2 < hStereoDft->prm_res[add( k, k_offset )]; k2++ ) + FOR( k2 = 1; k2 < hStereoDft->prm_res[k + k_offset]; k2++ ) { - hStereoDft->gipd_fx[sub( add( k, k_offset ), k2 )] = hStereoDft->gipd_fx[add( k, k_offset )]; + hStereoDft->gipd_fx[( k + k_offset ) - k2] = hStereoDft->gipd_fx[k + k_offset]; /* Q27 */ move32(); } @@ -1022,7 +1039,7 @@ void stereo_dft_dec_smooth_parameters_fx( #endif { Word16 q_val; - hStereoDft->itd_xfade_target_fx = hStereoDft->itd_fx[add( k, k_offset )]; + hStereoDft->itd_xfade_target_fx = hStereoDft->itd_fx[k + k_offset]; /* Q15 */ move32(); hStereoDft->itd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->itd_xfade_target_fx, hStereoDft->itd_xfade_prev_fx ), L_shl( sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->itd_xfade_counter ), Q15 ), &q_val ); IF( GT_16( q_val, 16 ) ) @@ -1031,7 +1048,7 @@ void stereo_dft_dec_smooth_parameters_fx( } ELSE { - hStereoDft->itd_xfade_step_fx = L_shl( hStereoDft->itd_xfade_step_fx, q_val ); + hStereoDft->itd_xfade_step_fx = L_shl( hStereoDft->itd_xfade_step_fx, q_val ); /* Q15 */ move32(); } move32(); @@ -1040,11 +1057,11 @@ void stereo_dft_dec_smooth_parameters_fx( /* xfade */ IF( NE_32( hStereoDft->itd_xfade_prev_fx, hStereoDft->itd_xfade_target_fx ) && LT_16( hStereoDft->itd_xfade_counter, STEREO_DFT_ITD_CNG_XFADE ) && LE_32( hStereoDft->last_active_element_brate, 24400 ) ) { - hStereoDft->itd_fx[add( k, k_offset )] = L_add( hStereoDft->itd_xfade_prev_fx, hStereoDft->itd_xfade_step_fx ); + hStereoDft->itd_fx[k + k_offset] = L_add( hStereoDft->itd_xfade_prev_fx, hStereoDft->itd_xfade_step_fx ); /* Q15 */ move32(); - hStereoDft->itd_xfade_prev_fx = hStereoDft->itd_fx[add( k, k_offset )]; + hStereoDft->itd_xfade_prev_fx = hStereoDft->itd_fx[k + k_offset]; /* Q15 */ move32(); - hStereoDft->itd_xfade_counter = add( hStereoDft->itd_xfade_counter, 1 ); + hStereoDft->itd_xfade_counter = add( hStereoDft->itd_xfade_counter, 1 ); /* Q0 */ } } ELSE @@ -1052,20 +1069,20 @@ void stereo_dft_dec_smooth_parameters_fx( /* First active frame, "reset" everything if long enough active encoding, only triggered if STEREO_DFT_ITD_CNG_XFADE_RESET = -1 */ IF( GT_16( active_frame_counter, STEREO_DFT_ITD_CNG_XFADE_RESET ) ) { - hStereoDft->itd_xfade_target_fx = hStereoDft->itd_fx[add( k, k_offset )]; + hStereoDft->itd_xfade_target_fx = hStereoDft->itd_fx[k + k_offset]; /* Q15 */ move32(); - hStereoDft->itd_xfade_prev_fx = hStereoDft->itd_fx[add( k, k_offset )]; + hStereoDft->itd_xfade_prev_fx = hStereoDft->itd_fx[k + k_offset]; /* Q15 */ move32(); - hStereoDft->itd_xfade_counter = 0; + hStereoDft->itd_xfade_counter = 0; /* Q0 */ move32(); } hStereoDft->last_active_element_brate = element_brate; move32(); } - FOR( k2 = 1; k2 < hStereoDft->prm_res[add( k, k_offset )]; k2++ ) + FOR( k2 = 1; k2 < hStereoDft->prm_res[k + k_offset]; k2++ ) { - hStereoDft->itd_fx[sub( add( k, k_offset ), k2 )] = hStereoDft->itd_fx[add( k, k_offset )]; + hStereoDft->itd_fx[( k + k_offset ) - k2] = hStereoDft->itd_fx[k + k_offset]; /* Q15 */ move32(); } @@ -1077,22 +1094,22 @@ void stereo_dft_dec_smooth_parameters_fx( { hStereoDft->itd_xfade_counter = 0; move16(); - hStereoDft->itd_xfade_target_fx = hStereoDft->itd_fx[STEREO_DFT_NBDIV - 1]; + hStereoDft->itd_xfade_target_fx = hStereoDft->itd_fx[STEREO_DFT_NBDIV - 1]; /* Q15 */ move32(); - hStereoDft->itd_xfade_prev_fx = hStereoDft->itd_fx[STEREO_DFT_NBDIV - 1]; + hStereoDft->itd_xfade_prev_fx = hStereoDft->itd_fx[STEREO_DFT_NBDIV - 1]; /* Q15 */ move32(); hStereoDft->ipd_xfade_counter = 0; move16(); - hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[STEREO_DFT_NBDIV - 1]; + hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[STEREO_DFT_NBDIV - 1]; /* Q27 */ move32(); - hStereoDft->ipd_xfade_prev_fx = hStereoDft->gipd_fx[STEREO_DFT_NBDIV - 1]; + hStereoDft->ipd_xfade_prev_fx = hStereoDft->gipd_fx[STEREO_DFT_NBDIV - 1]; /* Q27 */ move32(); } hStereoDft->last_active_element_brate = element_brate; move32(); - FOR( k = sub( hStereoDft->prm_res[k_offset], 1 ); k < N_div; k += hStereoDft->prm_res[add( k, k_offset )] ) + FOR( k = sub( hStereoDft->prm_res[k_offset], 1 ); k < N_div; k += hStereoDft->prm_res[k + k_offset] ) { max_res_pred_ind = 0; move32(); @@ -1106,19 +1123,19 @@ void stereo_dft_dec_smooth_parameters_fx( FOR( b = sub( hStereoDft->nbands_respred, 1 ); b >= nbands; b-- ) { hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = - hStereoDft->res_gains_ind_fx[1][b - STEREO_DFT_RES_PRED_BAND_MIN_RED + hStereoDft->res_pred_band_min + STEREO_DFT_BAND_MAX]; + hStereoDft->res_gains_ind_fx[1][b - STEREO_DFT_RES_PRED_BAND_MIN_RED + hStereoDft->res_pred_band_min + STEREO_DFT_BAND_MAX]; /* Q26 */ move32(); - hStereoDft->res_gains_ind_fx[1][b - STEREO_DFT_RES_PRED_BAND_MIN_RED + hStereoDft->res_pred_band_min + STEREO_DFT_BAND_MAX] = 0; + hStereoDft->res_gains_ind_fx[1][b - STEREO_DFT_RES_PRED_BAND_MIN_RED + hStereoDft->res_pred_band_min + STEREO_DFT_BAND_MAX] = 0; /* Q26 */ move32(); } } /* Get maximal index */ - FOR( b = hStereoDft->res_pred_band_min; b < sub( nbands, STEREO_DFT_RES_PRED_BAND_MIN_CONST ); b++ ) + FOR( b = hStereoDft->res_pred_band_min; b < nbands - STEREO_DFT_RES_PRED_BAND_MIN_CONST; b++ ) { IF( LT_32( max_res_pred_ind, hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] ) ) { - max_res_pred_ind = hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX]; + max_res_pred_ind = hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX]; /* Q26 */ move32(); } } @@ -1127,7 +1144,7 @@ void stereo_dft_dec_smooth_parameters_fx( FOR( ; b < nbands; b++ ) { assert( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] == 0 ); - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = max_res_pred_ind; + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = max_res_pred_ind; /* Q26 */ move32(); } } @@ -1137,12 +1154,12 @@ void stereo_dft_dec_smooth_parameters_fx( Word32 tmp; Word16 tmps1, tmps2; - hStereoDft->res_gains_ind_fx[0][b] = hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX]; + hStereoDft->res_gains_ind_fx[0][b] = hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX]; /* Q26 */ move32(); /*stereo_dft_dequantize_res_gains_f(&hStereoDft->res_gains_ind[0][b], &hStereoDft->res_gains_ind[1][b+STEREO_DFT_BAND_MAX],hStereoDft->side_gain+(k+k_offset)*STEREO_DFT_BAND_MAX+b, hStereoDft->res_pred_gain+(k+k_offset)*STEREO_DFT_BAND_MAX+b, 1);*/ - tmps1 = (Word16) L_shr( hStereoDft->res_gains_ind_fx[0][b], Q26 ); + tmps1 = (Word16) L_shr( hStereoDft->res_gains_ind_fx[0][b], Q26 ); /* Q0 */ move16(); - tmps2 = (Word16) L_shr( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], Q26 ); + tmps2 = (Word16) L_shr( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], Q26 ); /* Q0 */ move16(); stereo_dft_dequantize_res_gains_fx( &tmps1, &tmps2, hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), hStereoDft->res_pred_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), 1 ); @@ -1150,20 +1167,20 @@ void stereo_dft_dec_smooth_parameters_fx( test(); IF( hStereoDft->attackPresent ) { - hStereoDft->res_gains_ind_fx[1][b] = Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], (Word16) 0x6666 ); + hStereoDft->res_gains_ind_fx[1][b] = Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], (Word16) 0x6666 ); /* Q26 */ move32(); } ELSE IF( hStereoDft->trans || ( hStereoDft->res_pred_mode[k] && ( LT_32( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], ONE_IN_Q27 ) ) ) ) /* Assuming Maximum Q of res_gains_ind_fx is Q26 */ { hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], (Word16) 0x4CCD ), - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], (Word16) 0x3333 ); + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], (Word16) 0x3333 ); /* Q26 */ move32(); } ELSE { hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], dft_alpha_s2_fx[b] ), hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], - sub( (Word16) 0x7FFF, dft_alpha_s2_fx[b] ) ); + sub( (Word16) 0x7FFF, dft_alpha_s2_fx[b] ) ); /* Q26 */ move32(); } @@ -1177,25 +1194,25 @@ void stereo_dft_dec_smooth_parameters_fx( test(); IF( hStereoDft->attackPresent ) { - hStereoDft->res_gains_ind_fx[0][b] = hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX]; + hStereoDft->res_gains_ind_fx[0][b] = hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX]; /* Q26 */ move32(); - hStereoDft->res_gains_ind_fx[1][b] = Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], (Word16) 0x6666 ); + hStereoDft->res_gains_ind_fx[1][b] = Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], (Word16) 0x6666 ); /* Q26 */ move32(); } ELSE IF( hStereoDft->trans || ( hStereoDft->res_pred_mode[k] && LT_32( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], ONE_IN_Q27 ) ) ) { - hStereoDft->res_gains_ind_fx[0][b] = hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX]; + hStereoDft->res_gains_ind_fx[0][b] = hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX]; /* Q26 */ move32(); IF( EQ_16( hStereoDft->hConfig->band_res, STEREO_DFT_BAND_RES_LOW ) ) { hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], dft_alpha_w_b2_fx[b] ), - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], sub( (Word16) 0x7FFF, dft_alpha_w_b2_fx[b] ) ); + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], sub( (Word16) 0x7FFF, dft_alpha_w_b2_fx[b] ) ); /* Q26 */ move32(); } ELSE { hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], dft_alpha_w_fx[b] ), - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], sub( (Word16) 0x7FFF, dft_alpha_w_fx[b] ) ); + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], sub( (Word16) 0x7FFF, dft_alpha_w_fx[b] ) ); /* Q26 */ move32(); } } @@ -1205,22 +1222,22 @@ void stereo_dft_dec_smooth_parameters_fx( { hStereoDft->res_gains_ind_fx[0][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[0][b], dft_alpha_s_b2_fx[b] ), hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX], - sub( (Word16) 0x7FFF, dft_alpha_s_b2_fx[b] ) ); + sub( (Word16) 0x7FFF, dft_alpha_s_b2_fx[b] ) ); /* Q26 */ move32(); hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], dft_alpha_s2_b2_fx[b] ), hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], - sub( (Word16) 0x7FFF, dft_alpha_s2_b2_fx[b] ) ); + sub( (Word16) 0x7FFF, dft_alpha_s2_b2_fx[b] ) ); /* Q26 */ move32(); } ELSE { hStereoDft->res_gains_ind_fx[0][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[0][b], dft_alpha_s_fx[b] ), hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX], - sub( (Word16) ( 0x7FFF ), dft_alpha_s_fx[b] ) ); + sub( (Word16) ( 0x7FFF ), dft_alpha_s_fx[b] ) ); /* Q26 */ move32(); hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], dft_alpha_s2_fx[b] ), hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], - sub( (Word16) ( 0x7FFF ), dft_alpha_s2_fx[b] ) ); + sub( (Word16) ( 0x7FFF ), dft_alpha_s2_fx[b] ) ); /* Q26 */ move32(); } } @@ -1233,15 +1250,23 @@ void stereo_dft_dec_smooth_parameters_fx( /* Smoothing of IPDs*/ pgIpd = hStereoDft->gipd_fx + ( add( k, k_offset ) ); - diff_ipd = L_sub( pgIpd[0], pgIpd[-hStereoDft->prm_res[add( k, k_offset )]] ); + diff_ipd = L_sub( pgIpd[0], pgIpd[-hStereoDft->prm_res[k + k_offset]] ); /* Q27 */ +#ifndef FIX_874_INCREASE_IPD_PRECISION IF( LT_32( diff_ipd, -EVS_PI_FX_Q27 ) ) +#else + IF( LT_32( diff_ipd, -PI_round ) ) +#endif { - pgIpd[0] = L_add( pgIpd[0], EVS_2PI_FX_Q27 ); + pgIpd[0] = L_add( pgIpd[0], EVS_2PI_FX_Q27 ); /* Q27 */ move32(); } +#ifndef FIX_874_INCREASE_IPD_PRECISION ELSE IF( GT_32( diff_ipd, EVS_PI_FX_Q27 ) ) +#else + ELSE IF( GT_32( diff_ipd, PI_round ) ) +#endif { - pgIpd[0] = L_sub( pgIpd[0], EVS_2PI_FX_Q27 ); + pgIpd[0] = L_sub( pgIpd[0], EVS_2PI_FX_Q27 ); /* Q27 */ move32(); } @@ -1249,12 +1274,12 @@ void stereo_dft_dec_smooth_parameters_fx( { IF( hStereoDft->wasTransient ) { - pgIpd[0] = L_add( Mpy_32_16_1( pgIpd[0], (Word16) 0x6666 ), Mpy_32_16_1( pgIpd[-hStereoDft->prm_res[add( k, k_offset )]], (Word16) ( 0x199A ) ) ); + pgIpd[0] = L_add( Mpy_32_16_1( pgIpd[0], (Word16) 0x6666 ), Mpy_32_16_1( pgIpd[-hStereoDft->prm_res[k + k_offset]], (Word16) ( 0x199A ) ) ); /* Q27 */ move32(); } ELSE { - pgIpd[0] = L_add( L_shr( pgIpd[0], 1 ), L_shr( pgIpd[-hStereoDft->prm_res[add( k, k_offset )]], 1 ) ); + pgIpd[0] = L_add( L_shr( pgIpd[0], 1 ), L_shr( pgIpd[-hStereoDft->prm_res[k + k_offset]], 1 ) ); /* Q27 */ move32(); } } @@ -1262,21 +1287,21 @@ void stereo_dft_dec_smooth_parameters_fx( IF( !hStereoDft->attackPresent ) { - pSideGain = hStereoDft->side_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); + pSideGain = hStereoDft->side_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); /* Q31 */ FOR( b = 0; b < hStereoDft->res_cod_band_max; b++ ) { pSideGain[b] = Madd_32_16( Mpy_32_16_1( pSideGain[b], dft_res_cod_alpha_fx[b] ), - pSideGain[sub( b, i_mult( hStereoDft->prm_res[add( k, k_offset )], STEREO_DFT_BAND_MAX ) )], - sub( (Word16) 0x7FFF, dft_res_cod_alpha_fx[b] ) ); + pSideGain[b - hStereoDft->prm_res[k + k_offset] * STEREO_DFT_BAND_MAX], + sub( (Word16) 0x7FFF, dft_res_cod_alpha_fx[b] ) ); /* Q31 */ move32(); } } /*Interpolation between DFT slots*/ - FOR( k2 = 1; k2 < hStereoDft->prm_res[add( k, k_offset )]; k2++ ) + FOR( k2 = 1; k2 < hStereoDft->prm_res[k + k_offset]; k2++ ) { - pInterpol = hStereoDft->gipd_fx + sub( add( k, k_offset ), k2 ); - pIpd = hStereoDft->gipd_fx + add( k, k_offset ); + pInterpol = hStereoDft->gipd_fx + sub( add( k, k_offset ), k2 ); /* Q27 */ + pIpd = hStereoDft->gipd_fx + add( k, k_offset ); /* Q27 */ IF( hStereoDft->attackPresent ) { *( pInterpol ) = *( pIpd ); @@ -1284,13 +1309,13 @@ void stereo_dft_dec_smooth_parameters_fx( } ELSE { - *( pInterpol ) = *( hStereoDft->gipd_fx + sub( add( k, k_offset ), hStereoDft->prm_res[add( k, k_offset )] ) ); + *( pInterpol ) = *( hStereoDft->gipd_fx + sub( add( k, k_offset ), hStereoDft->prm_res[k + k_offset] ) ); move32(); } FOR( b = 0; b < hStereoDft->nbands; b++ ) { - *( hStereoDft->res_pred_gain_fx + add( i_mult( sub( add( k, k_offset ), k2 ), STEREO_DFT_BAND_MAX ), b ) ) = *( hStereoDft->res_pred_gain_fx + add( i_mult( sub( add( k, k_offset ), hStereoDft->prm_res[add( k, k_offset )] ), STEREO_DFT_BAND_MAX ), b ) ); + *( hStereoDft->res_pred_gain_fx + add( i_mult( sub( add( k, k_offset ), k2 ), STEREO_DFT_BAND_MAX ), b ) ) = *( hStereoDft->res_pred_gain_fx + add( i_mult( sub( add( k, k_offset ), hStereoDft->prm_res[k + k_offset] ), STEREO_DFT_BAND_MAX ), b ) ); /* Q31 */ move32(); test(); test(); @@ -1298,17 +1323,17 @@ void stereo_dft_dec_smooth_parameters_fx( test(); IF( b < hStereoDft->res_cod_band_max || hStereoDft->attackPresent || hStereoDft->trans || ( hStereoDft->res_pred_mode[k] && LT_32( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], ONE_IN_Q27 ) ) ) { - *( hStereoDft->side_gain_fx + add( i_mult( sub( add( k, k_offset ), k2 ), STEREO_DFT_BAND_MAX ), b ) ) = *( hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ) ); + *( hStereoDft->side_gain_fx + add( i_mult( sub( add( k, k_offset ), k2 ), STEREO_DFT_BAND_MAX ), b ) ) = *( hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ) ); /* Q31 */ move32(); } ELSE { - *( hStereoDft->side_gain_fx + add( i_mult( sub( add( k, k_offset ), k2 ), STEREO_DFT_BAND_MAX ), b ) ) = *( hStereoDft->side_gain_fx + add( i_mult( sub( add( k, k_offset ), hStereoDft->prm_res[add( k, k_offset )] ), STEREO_DFT_BAND_MAX ), b ) ); + *( hStereoDft->side_gain_fx + add( i_mult( sub( add( k, k_offset ), k2 ), STEREO_DFT_BAND_MAX ), b ) ) = *( hStereoDft->side_gain_fx + add( i_mult( sub( add( k, k_offset ), hStereoDft->prm_res[k + k_offset] ), STEREO_DFT_BAND_MAX ), b ) ); /* Q31 */ move32(); } } - hStereoDft->itd_fx[sub( add( k, k_offset ), k2 )] = hStereoDft->itd_fx[add( k, k_offset )]; + hStereoDft->itd_fx[k + k_offset - k2] = hStereoDft->itd_fx[k + k_offset]; /* Q15 */ move32(); } /*end of interpolation*/ } @@ -1323,10 +1348,10 @@ void stereo_dft_dec_smooth_parameters_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_res_fx( - CPE_DEC_HANDLE hCPE, /* i/o: decoder CPE handle */ - Word32 res_buf[STEREO_DFT_N_8k], /* i : residual buffer */ - Word16 q_res, /* i : q fact of residural buffer */ - Word32 *output /* o : output */ + CPE_DEC_HANDLE hCPE, /* i/o: decoder CPE handle */ + Word32 res_buf[STEREO_DFT_N_8k], /* i : residual buffer q_res*/ + Word16 q_res, /* i : q fact of residural buffer */ + Word32 *output /* o : output Q16*/ ) { Word16 i; @@ -1340,6 +1365,7 @@ void stereo_dft_dec_res_fx( prev_bfi = hCPE->hCoreCoder[0]->prev_old_bfi; /* The core decoding is already completed here and the prev_bfi has been updated for the next frame. The prev_old_bfi still holds the prev_bfi for the current frame. */ + /* Q0 */ move16(); /* flush memories when switching residual coding on */ @@ -1364,9 +1390,9 @@ void stereo_dft_dec_res_fx( Word16 q_shift = sub( hCPE->hStereoDft->q_res_cod_mem_fx, Q16 ); FOR( i = 0; i < STEREO_DFT_OVL_8k; i++ ) { - win[i] = extract_h( L_add( hCPE->hStereoDft->res_cod_mem_fx[i], L_shl( L_mult( win[i], hCPE->hStereoDft->win_8k_fx[i] ), q_shift ) ) ); + win[i] = extract_h( L_add( hCPE->hStereoDft->res_cod_mem_fx[i], L_shl( L_mult( win[i], hCPE->hStereoDft->win_8k_fx[i] ), q_shift ) ) ); /* q_res_cod_mem_fx */ move16(); - hCPE->hStereoDft->res_cod_mem_fx[i] = L_mult( win[L_FRAME8k + i], hCPE->hStereoDft->win_8k_fx[STEREO_DFT_OVL_8k - 1 - i] ); + hCPE->hStereoDft->res_cod_mem_fx[i] = L_mult( win[L_FRAME8k + i], hCPE->hStereoDft->win_8k_fx[STEREO_DFT_OVL_8k - 1 - i] ); /* q_res_cod_mem_fx */ move32(); } IF( q_shift != 0 ) @@ -1387,38 +1413,38 @@ void stereo_dft_dec_res_fx( { win[i] = extract_h( Madd_32_16( Mpy_32_16_1( hCPE->hStereoDft->res_cod_mem_fx[i], sub( MAX_16, mult( fac, fac ) ) ), L_mult( hCPE->hStereoDft->win_8k_fx[i], win[i] ), - sub( MAX_16, mult( sub( MAX_16, fac ), sub( MAX_16, fac ) ) ) ) ); + sub( MAX_16, mult( sub( MAX_16, fac ), sub( MAX_16, fac ) ) ) ) ); /* Q0 */ move16(); - hCPE->hStereoDft->res_cod_mem_fx[i] = L_mult( win[L_FRAME8k + i], hCPE->hStereoDft->win_8k_fx[STEREO_DFT_OVL_8k - 1 - i] ); + hCPE->hStereoDft->res_cod_mem_fx[i] = L_mult( win[L_FRAME8k + i], hCPE->hStereoDft->win_8k_fx[STEREO_DFT_OVL_8k - 1 - i] ); /* Q16 */ move32(); fac = add( fac, step ); } } - Copy( win, out_16, L_FRAME8k ); + Copy( win, out_16, L_FRAME8k ); /* Q0 */ IF( hCPE->hCoreCoder[0]->core == ACELP_CORE ) { /* bass post-filter */ bass_psfilter_fx( hCPE->hStereoDft->hBpf, hCPE->hCoreCoder[0]->Opt_AMR_WB, out_16, L_FRAME8k, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx + ( L_FRAME8k / STEREO_DFT_L_SUBFR_8k ), hCPE->hCoreCoder[0]->bpf_off, hCPE->hCoreCoder[0]->stab_fac_fx, &hCPE->hStereoDft->stab_fac_smooth_res_fx, hCPE->hCoreCoder[0]->last_coder_type, 0, bpf_error_signal_8k_16 ); - Copy_Scale_sig_16_32( bpf_error_signal_8k_16, bpf_error_signal_8k, L_FRAME8k, Q15 ); + Copy_Scale_sig_16_32( bpf_error_signal_8k_16, bpf_error_signal_8k, L_FRAME8k, Q15 ); /* Q15 */ res_bpf_flag = res_bpf_adapt_ivas_fx( hCPE->hStereoDft, bpf_error_signal_8k, res_buf, q_res ); IF( prev_bfi ) { /* Ramp up BPF contribution for the first good frame */ - step = (Word16) ( 0x00CD ); // ( 1.0f / L_FRAME8k ); + step = (Word16) ( 0x00CD ); // ( 1.0f / L_FRAME8k ); /* Q15 */ move16(); fac = negate( step ); FOR( i = 0; i < L_FRAME8k; i++ ) { fac = add( fac, step ); - bpf_error_signal_8k[i] = Mpy_32_16_1( bpf_error_signal_8k[i], fac ); + bpf_error_signal_8k[i] = Mpy_32_16_1( bpf_error_signal_8k[i], fac ); /* Q15 */ move32(); } } - Copy_Scale_sig_16_32( out_16, output, L_FRAME8k, 16 ); + Copy_Scale_sig_16_32( out_16, output, L_FRAME8k, 16 ); /* Q16 */ IF( res_bpf_flag ) { v_sub_32( output, bpf_error_signal_8k, output, L_FRAME8k ); @@ -1429,12 +1455,12 @@ void stereo_dft_dec_res_fx( set16_fx( hCPE->hStereoDft->hBpf->pst_old_syn_fx, 0, STEREO_DFT_NBPSF_PIT_MAX_8k ); hCPE->hStereoDft->hBpf->pst_mem_deemp_err_fx = 0; move16(); - Copy_Scale_sig_16_32( out_16, output, L_FRAME8k, 16 ); + Copy_Scale_sig_16_32( out_16, output, L_FRAME8k, 16 ); /* Q16 */ } ELSE { /* This step is needed to ensure output is properly populated with scaled values in all cases*/ - Copy_Scale_sig_16_32( out_16, output, L_FRAME8k, 16 ); + Copy_Scale_sig_16_32( out_16, output, L_FRAME8k, 16 ); /* Q16 */ } return; @@ -1448,18 +1474,18 @@ void stereo_dft_dec_res_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - Decoder_State *st0, /* i/o: decoder state structure */ - Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ - Word32 *input_mem, /* i/o: mem of buffer DFT analysis */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ - const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ - const Word16 sba_mono_flag, /* i : signal mono output for SBA DirAC */ - ivas_spar_md_dec_state_t *hMdDec, /* i : SPAR MD handle for upmixing */ - const Word16 cross_fade_start_offset, /* i : SPAR mixer delay compensation */ - const Word32 output_Fs, /* i : Fs for delay calculation */ - const Word16 nchan_transport, /* i : number of transpor channels */ - const Word16 num_md_sub_frames /* i : number of MD subframes */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + Decoder_State *st0, /* i/o: decoder state structure */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers qDFT*/ + Word32 *input_mem, /* i/o: mem of buffer DFT analysis */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure Q0*/ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC Q0*/ + const Word16 sba_mono_flag, /* i : signal mono output for SBA DirAC Q0*/ + ivas_spar_md_dec_state_t *hMdDec, /* i : SPAR MD handle for upmixing */ + const Word16 cross_fade_start_offset, /* i : SPAR mixer delay compensation Q0*/ + const Word32 output_Fs, /* i : Fs for delay calculation Q0*/ + const Word16 nchan_transport, /* i : number of transpor channels Q0*/ + const Word16 num_md_sub_frames /* i : number of MD subframes Q0*/ ) { Word16 i, k, b, N_div, stop; @@ -1498,7 +1524,7 @@ void stereo_dft_dec_fx( Word16 q_samp_ratio = Q15; move16(); - output_frame = (Word16) Mpy_32_32( L_add( st0->output_Fs, FRAMES_PER_SEC_BY_2 ), ONE_BY_FRAMES_PER_SEC_Q31 ); + output_frame = (Word16) Mpy_32_32( L_add( st0->output_Fs, FRAMES_PER_SEC_BY_2 ), ONE_BY_FRAMES_PER_SEC_Q31 ); /* Q0 */ /*------------------------------------------------------------------* * Initialization @@ -1520,7 +1546,7 @@ void stereo_dft_dec_fx( test(); test(); hStereoDft->trans = (Word16) ( ( EQ_16( st0->clas_dec, ONSET ) || EQ_16( st0->clas_dec, SIN_ONSET ) || EQ_16( st0->clas_dec, UNVOICED_CLAS ) || EQ_16( st0->clas_dec, UNVOICED_TRANSITION ) ) || LE_16( st0->stab_fac_fx, (Word16) 0x2000 ) ) || - ( ( EQ_16( st0->core, TCX_20_CORE ) && ( EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) || EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, HALF_OVERLAP ) ) ) || EQ_16( st0->core, TCX_10_CORE ) ); + ( ( EQ_16( st0->core, TCX_20_CORE ) && ( EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) || EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, HALF_OVERLAP ) ) ) || EQ_16( st0->core, TCX_10_CORE ) ); /* Q0 */ move16(); /* Initialization */ @@ -1535,7 +1561,7 @@ void stereo_dft_dec_fx( test(); IF( LT_16( output_frame, inner_frame_tbl[st0->bwidth] ) && ( sba_dirac_stereo_flag == 0 ) ) { - hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], hStereoDft->NFFT, DEC ); + hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], hStereoDft->NFFT, DEC ); /* Q0 */ } IF( st0->bfi == 0 ) @@ -1555,19 +1581,19 @@ void stereo_dft_dec_fx( move32(); IF( prev_bfi ) { - dmx_nrg = stereo_dft_dmx_swb_nrg_fx( DFT[0], DFT[0] + STEREO_DFT32MS_N_MAX, s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ), 0, 0 ); + dmx_nrg = stereo_dft_dmx_swb_nrg_fx( DFT[0], DFT[0] + STEREO_DFT32MS_N_MAX, s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ), 0, 0 ); /* Q0 */ } FOR( k = 0; k < N_div; k++ ) { - pDFT_DMX = DFT[0] + i_mult( k, STEREO_DFT32MS_N_MAX ); - pDFT_RES = DFT[1] + i_mult( k, STEREO_DFT32MS_N_MAX ); + pDFT_DMX = DFT[0] + i_mult( k, STEREO_DFT32MS_N_MAX ); /* qDFT */ + pDFT_RES = DFT[1] + i_mult( k, STEREO_DFT32MS_N_MAX ); /* qDFT */ pDFT_DMX1 = 0; move16(); IF( GT_16( nchan_transport, 1 ) ) { - pDFT_DMX1 = DFT[1] + i_mult( k, STEREO_DFT32MS_N_MAX ); + pDFT_DMX1 = DFT[1] + i_mult( k, STEREO_DFT32MS_N_MAX ); /* qDFT */ } /*Apply Stereo*/ @@ -1581,22 +1607,22 @@ void stereo_dft_dec_fx( move16(); /* since delay is just 3.125ms, the parameters received are used for the second window */ - pSideGain = hStereoDft->side_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); - pgIpd = hStereoDft->gipd_fx + add( k, k_offset ); - pPredGain = hStereoDft->res_pred_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); + pSideGain = hStereoDft->side_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); /* Q31 */ + pgIpd = hStereoDft->gipd_fx + add( k, k_offset ); /* Q27 */ + pPredGain = hStereoDft->res_pred_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); /* Q31 */ /* Use coarse band partition in inactive frames */ test(); IF( hStereoDft->frame_sid_nodata && !sba_dirac_stereo_flag ) { - NFFT_inner = i_mult( ( STEREO_DFT32MS_N_MAX / L_FRAME48k ), inner_frame_tbl[st0->bwidth] ); + NFFT_inner = i_mult( ( STEREO_DFT32MS_N_MAX / L_FRAME48k ), inner_frame_tbl[st0->bwidth] ); /* Q0 */ hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, 2, NFFT_inner, DEC ); } IF( st0->bfi ) { - hStereoDft->past_DMX_pos = ( hStereoDft->past_DMX_pos + STEREO_DFT_PAST_MAX - 1 ) % STEREO_DFT_PAST_MAX; + hStereoDft->past_DMX_pos = ( sub( add( hStereoDft->past_DMX_pos, STEREO_DFT_PAST_MAX ), 1 ) ) % STEREO_DFT_PAST_MAX; /* Q0 */ } test(); @@ -1611,7 +1637,7 @@ void stereo_dft_dec_fx( { IF( EQ_16( k, 1 ) ) { - Copy32( pDFT_RES, hStereoDft->res_mem_fx, shl( hStereoDft->band_limits[hStereoDft->res_cod_band_max], 1 ) ); + Copy32( pDFT_RES, hStereoDft->res_mem_fx, shl( hStereoDft->band_limits[hStereoDft->res_cod_band_max], 1 ) ); /* qDFT */ hStereoDft->time_offs = 0; move16(); } @@ -1627,16 +1653,16 @@ void stereo_dft_dec_fx( test(); IF( hStereoDft->frame_sid_nodata && !sba_dirac_stereo_flag ) { - DFT_L[0] = pDFT_DMX[0]; + DFT_L[0] = pDFT_DMX[0]; /* qDFT */ move32(); - DFT_R[0] = pDFT_RES[0]; + DFT_R[0] = pDFT_RES[0]; /* qDFT */ move32(); } ELSE { - DFT_L[0] = pDFT_DMX[0]; + DFT_L[0] = pDFT_DMX[0]; /* qDFT */ move32(); - DFT_R[0] = pDFT_DMX[0]; + DFT_R[0] = pDFT_DMX[0]; /* qDFT */ move32(); } @@ -1654,7 +1680,7 @@ void stereo_dft_dec_fx( test(); IF( hStereoDft->frame_sid_nodata && !sba_dirac_stereo_flag ) { - g = hStereoDft->g_state_fx[b]; + g = hStereoDft->g_state_fx[b]; /* Q15 */ move16(); } @@ -1663,11 +1689,11 @@ void stereo_dft_dec_fx( test(); IF( LT_16( hStereoDft->band_limits[b], L_FRAME16k ) && ( hStereoDft->frame_sid_nodata || ( st0->VAD == 0 ) ) ) { - hFdCngDec->cna_nbands = add( b, 1 ); + hFdCngDec->cna_nbands = add( b, 1 ); /* Q0 */ move16(); - hFdCngDec->cna_band_limits[b] = hStereoDft->band_limits[b]; + hFdCngDec->cna_band_limits[b] = hStereoDft->band_limits[b]; /* Q0 */ move16(); - hFdCngDec->cna_g_state_fx[b] = g; + hFdCngDec->cna_g_state_fx[b] = g; /* Q15 */ move16(); } @@ -1692,7 +1718,7 @@ void stereo_dft_dec_fx( { /* Low pass filter coherence */ /* store coherence from inactive frames for later use by the stereo CNA */ - hFdCngDec->cna_cm_fx[b] = hStereoCng->cm_fx[b]; + hFdCngDec->cna_cm_fx[b] = hStereoCng->cm_fx[b]; /* Q15 */ move16(); /* Calculate gamma */ @@ -1702,9 +1728,9 @@ void stereo_dft_dec_fx( Word16 q_loc1, q_loc2; gamma = hStereoCng->cm_fx[b]; move16(); - gamma = BASOP_Util_Divide3232_Scale( gamma, sub( MAX_16, gamma ), &q_loc1 ); + gamma = BASOP_Util_Divide3232_Scale( gamma, sub( MAX_16, gamma ), &q_loc1 ); /* q_loc1 */ l_gamma = L_deposit_l( gamma ); - op1 = L_add( l_gamma, L_shr( L_deposit_l( sub( MAX_16, mult( g, g ) ) ), q_loc1 ) ); + op1 = L_add( l_gamma, L_shr( L_deposit_l( sub( MAX_16, mult( g, g ) ) ), q_loc1 ) ); /* q_loc1 */ q_loc1 = add( Q16, q_loc1 ); q_loc2 = q_loc1; op1 = Sqrt32( op1, &q_loc1 ); @@ -1714,8 +1740,8 @@ void stereo_dft_dec_fx( op2 = L_shl( op2, sub( q_loc2, q_loc1 ) ); q_loc2 = q_loc1; } - gamma = extract_h( L_sub( op1, op2 ) ); - gamma = shl( gamma, q_loc2 ); + gamma = extract_h( L_sub( op1, op2 ) ); /* q_loc1 - 16 */ + gamma = shl( gamma, q_loc2 ); /* 2 * q_loc1 - 16 */ } ELSE { @@ -1726,14 +1752,14 @@ void stereo_dft_dec_fx( FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { /* Create L and R signals with the correct coherence by mixing channel 0 (pDFT_DMX) and channel 1 (pDFT_RES) */ - DFT_L[2 * i] = Madd_32_16( Madd_32_16( pDFT_DMX[2 * i], pDFT_DMX[2 * i], g ), pDFT_RES[2 * i], gamma ); + DFT_L[2 * i] = Madd_32_16( Madd_32_16( pDFT_DMX[2 * i], pDFT_DMX[2 * i], g ), pDFT_RES[2 * i], gamma ); /* qDFT */ move32(); - DFT_R[2 * i] = Msub_32_16( Msub_32_16( pDFT_DMX[2 * i], pDFT_DMX[2 * i], g ), pDFT_RES[2 * i], gamma ); + DFT_R[2 * i] = Msub_32_16( Msub_32_16( pDFT_DMX[2 * i], pDFT_DMX[2 * i], g ), pDFT_RES[2 * i], gamma ); /* qDFT */ move32(); - DFT_L[add( shl( i, 1 ), 1 )] = Madd_32_16( Madd_32_16( pDFT_DMX[add( shl( i, 1 ), 1 )], pDFT_DMX[add( shl( i, 1 ), 1 )], g ), pDFT_RES[add( shl( i, 1 ), 1 )], gamma ); + DFT_L[2 * i + 1] = Madd_32_16( Madd_32_16( pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1], g ), pDFT_RES[2 * i + 1], gamma ); /* qDFt */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = Msub_32_16( Msub_32_16( pDFT_DMX[add( shl( i, 1 ), 1 )], pDFT_DMX[add( shl( i, 1 ), 1 )], g ), pDFT_RES[add( shl( i, 1 ), 1 )], gamma ); + DFT_R[2 * i + 1] = Msub_32_16( Msub_32_16( pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1], g ), pDFT_RES[2 * i + 1], gamma ); /* qDFT */ move32(); } @@ -1742,19 +1768,19 @@ void stereo_dft_dec_fx( Word32 theta = pgIpd[0]; WHILE( GT_32( theta, EVS_2PI_FX_Q27 ) ) { - theta = L_sub( theta, EVS_2PI_FX_Q27 ); + theta = L_sub( theta, EVS_2PI_FX_Q27 ); /* Q27 */ } WHILE( LT_32( theta, -EVS_2PI_FX_Q27 ) ) { - theta = L_add( theta, EVS_2PI_FX_Q27 ); + theta = L_add( theta, EVS_2PI_FX_Q27 ); /* Q27 */ } IF( GT_32( theta, EVS_PI_FX_Q27 ) ) { - theta = L_sub( theta, EVS_2PI_FX_Q27 ); + theta = L_sub( theta, EVS_2PI_FX_Q27 ); /* Q27 */ } ELSE IF( LT_32( theta, -EVS_PI_FX_Q27 ) ) { - theta = L_add( theta, EVS_2PI_FX_Q27 ); + theta = L_add( theta, EVS_2PI_FX_Q27 ); /* Q27 */ } c0 = getCosWord16( (Word16) L_shr( theta, 14 ) ); IF( EQ_16( c0, ONE_IN_Q14 ) ) @@ -1770,10 +1796,10 @@ void stereo_dft_dec_fx( FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { /*rotate L*/ - tmp = Msub_32_16( Mpy_32_16_1( DFT_L[2 * i], c0 ), DFT_L[add( shl( i, 1 ), 1 )], s0 ); - DFT_L[add( shl( i, 1 ), 1 )] = Madd_32_16( Mpy_32_16_1( DFT_L[2 * i], s0 ), DFT_L[add( shl( i, 1 ), 1 )], c0 ); + tmp = Msub_32_16( Mpy_32_16_1( DFT_L[2 * i], c0 ), DFT_L[2 * i + 1], s0 ); /* qDFT */ + DFT_L[2 * i + 1] = Madd_32_16( Mpy_32_16_1( DFT_L[2 * i], s0 ), DFT_L[2 * i + 1], c0 ); /* qDFT */ move32(); - DFT_L[2 * i] = tmp; + DFT_L[2 * i] = tmp; /* qDFT */ move32(); } } @@ -1789,53 +1815,53 @@ void stereo_dft_dec_fx( { i = 0; move16(); - DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); /* qDFT */ move32(); - DFT_L[2 * i] = DFT_W; + DFT_L[2 * i] = DFT_W; /* qDFT */ move32(); DFT_R[2 * i] = 0; move32(); - DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[add( shl( i, 1 ), 1 )] ); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); /* qDFT */ move32(); - DFT_L[add( shl( i, 1 ), 1 )] = DFT_W; + DFT_L[2 * i + 1] = DFT_W; /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = 0; + DFT_R[2 * i + 1] = 0; move32(); } FOR( i = hStereoDft->band_limits[b]; i < s_min( stop, hStereoDft->band_limits[b + 1] ); i++ ) { - DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ), - L_add( hStereoDft->mixer_mat_smooth_fx[0][1][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - L_add( hStereoDft->mixer_mat_smooth_fx[0][2][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - hStereoDft->mixer_mat_smooth_fx[0][3][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )] ) ), - DFT_PRED_RES[2 * i] ); - DFT_L[2 * i] = DFT_W; + DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ), + L_add( hStereoDft->mixer_mat_smooth_fx[0][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[0][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[0][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i] ); /* qDFT */ + DFT_L[2 * i] = DFT_W; /* qDFT */ move32(); DFT_R[2 * i] = 0; move32(); - DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ), - L_add( hStereoDft->mixer_mat_smooth_fx[0][1][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - L_add( hStereoDft->mixer_mat_smooth_fx[0][2][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - hStereoDft->mixer_mat_smooth_fx[0][3][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )] ) ), - DFT_PRED_RES[add( shl( i, 1 ), 1 )] ); - DFT_L[add( shl( i, 1 ), 1 )] = DFT_W; + DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ), + L_add( hStereoDft->mixer_mat_smooth_fx[0][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[0][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[0][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i + 1] ); /* qDFT */ + DFT_L[2 * i + 1] = DFT_W; /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = 0; + DFT_R[2 * i + 1] = 0; move32(); } FOR( ; i < hStereoDft->band_limits[b + 1]; i++ ) { - DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ); - DFT_L[2 * i] = DFT_W; + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); /* qDFT */ + DFT_L[2 * i] = DFT_W; /* qDFT */ move32(); DFT_R[2 * i] = 0; move32(); - DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ); - DFT_L[add( shl( i, 1 ), 1 )] = DFT_W; + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); /* qDFT */ + DFT_L[2 * i + 1] = DFT_W; /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = 0; + DFT_R[2 * i + 1] = 0; move32(); } } @@ -1845,72 +1871,72 @@ void stereo_dft_dec_fx( { i = 0; move16(); - DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ); - DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); /* qDFT */ + DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); /* qDFT */ - DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); + DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ); - DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); /* qDFT */ + DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); /* qDFT */ - DFT_L[2 * i + 1] = L_add( DFT_W, DFT_Y ); + DFT_L[2 * i + 1] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); } FOR( i = hStereoDft->band_limits[b]; i < min( stop, hStereoDft->band_limits[b + 1] ); i++ ) { - DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ), - L_add( hStereoDft->mixer_mat_smooth_fx[0][1][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - L_add( hStereoDft->mixer_mat_smooth_fx[0][2][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - hStereoDft->mixer_mat_smooth_fx[0][3][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )] ) ), - DFT_PRED_RES[2 * i] ); - DFT_Y = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ), - L_add( hStereoDft->mixer_mat_smooth_fx[1][1][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - L_add( hStereoDft->mixer_mat_smooth_fx[1][2][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - hStereoDft->mixer_mat_smooth_fx[1][3][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )] ) ), - DFT_PRED_RES[2 * i] ); - - DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); + DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ), + L_add( hStereoDft->mixer_mat_smooth_fx[0][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[0][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[0][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i] ); /* qDFT */ + DFT_Y = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ), + L_add( hStereoDft->mixer_mat_smooth_fx[1][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[1][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[1][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i] ); /* qDFT */ + + DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ), - L_add( hStereoDft->mixer_mat_smooth_fx[0][1][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - L_add( hStereoDft->mixer_mat_smooth_fx[0][2][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - hStereoDft->mixer_mat_smooth_fx[0][3][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )] ) ), - DFT_PRED_RES[add( shl( i, 1 ), 1 )] ); - DFT_Y = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ), - L_add( hStereoDft->mixer_mat_smooth_fx[1][1][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - L_add( hStereoDft->mixer_mat_smooth_fx[1][2][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - hStereoDft->mixer_mat_smooth_fx[1][3][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )] ) ), - DFT_PRED_RES[add( shl( i, 1 ), 1 )] ); - - DFT_L[add( shl( i, 1 ), 1 )] = L_add( DFT_W, DFT_Y ); + DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ), + L_add( hStereoDft->mixer_mat_smooth_fx[0][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[0][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[0][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i + 1] ); /* qDFT */ + DFT_Y = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ), + L_add( hStereoDft->mixer_mat_smooth_fx[1][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[1][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[1][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i + 1] ); /* qDFT */ + + DFT_L[2 * i + 1] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); } FOR( ; i < hStereoDft->band_limits[b + 1]; i++ ) { - DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ); - DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); /* qDFT */ + DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); /* qDFT */ - DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); + DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ); - DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); /* qDFT */ + DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); /* qDFT */ - DFT_L[add( shl( i, 1 ), 1 )] = L_add( DFT_W, DFT_Y ); + DFT_L[2 * i + 1] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); } } @@ -1922,42 +1948,42 @@ void stereo_dft_dec_fx( i = 0; move32(); - DFT_W = pDFT_DMX[2 * i]; + DFT_W = pDFT_DMX[2 * i]; /* qDFT */ move32(); - DFT_Y = Madd_32_32( pDFT_DMX1[2 * i], hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ); + DFT_Y = Madd_32_32( pDFT_DMX1[2 * i], hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); /* qDFT */ - DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); + DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_W = pDFT_DMX[add( shl( i, 1 ), 1 )]; + DFT_W = pDFT_DMX[2 * i + 1]; /* qDFT */ move32(); - DFT_Y = Madd_32_32( pDFT_DMX1[add( shl( i, 1 ), 1 )], hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ); + DFT_Y = Madd_32_32( pDFT_DMX1[2 * i + 1], hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); /* qDFT */ - DFT_L[add( shl( i, 1 ), 1 )] = L_add( DFT_W, DFT_Y ); + DFT_L[2 * i + 1] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); } FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { - DFT_W = pDFT_DMX[2 * i]; + DFT_W = pDFT_DMX[2 * i]; /* qDFT */ move32(); - DFT_Y = Madd_32_32( pDFT_DMX1[2 * i], hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ); + DFT_Y = Madd_32_32( pDFT_DMX1[2 * i], hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); /* qDFT */ - DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); + DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_W = pDFT_DMX[add( shl( i, 1 ), 1 )]; + DFT_W = pDFT_DMX[2 * i + 1]; /* qDFT */ move32(); - DFT_Y = Madd_32_32( pDFT_DMX1[add( shl( i, 1 ), 1 )], hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ); + DFT_Y = Madd_32_32( pDFT_DMX1[2 * i + 1], hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); /* qDFT */ - DFT_L[add( shl( i, 1 ), 1 )] = L_add( DFT_W, DFT_Y ); + DFT_L[2 * i + 1] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); } } @@ -1968,37 +1994,37 @@ void stereo_dft_dec_fx( } ELSE { - FOR( i = hStereoDft->band_limits[b]; i < s_min( stop, hStereoDft->band_limits[b + 1] ); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < min( stop, hStereoDft->band_limits[b + 1] ); i++ ) { - tmp = L_add( Madd_32_16( pDFT_RES[2 * i], pDFT_DMX[2 * i], g ), DFT_PRED_RES[2 * i] ); + tmp = L_add( Madd_32_16( pDFT_RES[2 * i], pDFT_DMX[2 * i], g ), DFT_PRED_RES[2 * i] ); /* qDFT */ - DFT_L[2 * i] = L_add( pDFT_DMX[2 * i], tmp ); + DFT_L[2 * i] = L_add( pDFT_DMX[2 * i], tmp ); /* qDFT */ move32(); - DFT_R[2 * i] = L_sub( pDFT_DMX[2 * i], tmp ); + DFT_R[2 * i] = L_sub( pDFT_DMX[2 * i], tmp ); /* qDFT */ move32(); - tmp = L_add( Madd_32_16( pDFT_RES[add( shl( i, 1 ), 1 )], pDFT_DMX[add( shl( i, 1 ), 1 )], g ), DFT_PRED_RES[add( shl( i, 1 ), 1 )] ); + tmp = L_add( Madd_32_16( pDFT_RES[2 * i + 1], pDFT_DMX[2 * i + 1], g ), DFT_PRED_RES[2 * i + 1] ); /* qDFT */ - DFT_L[add( shl( i, 1 ), 1 )] = L_add( pDFT_DMX[add( shl( i, 1 ), 1 )], tmp ); + DFT_L[2 * i + 1] = L_add( pDFT_DMX[2 * i + 1], tmp ); /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = L_sub( pDFT_DMX[add( shl( i, 1 ), 1 )], tmp ); + DFT_R[2 * i + 1] = L_sub( pDFT_DMX[2 * i + 1], tmp ); /* qDFT */ move32(); } FOR( ; i < hStereoDft->band_limits[b + 1]; i++ ) { - tmp = Madd_32_16( pDFT_RES[2 * i], pDFT_DMX[2 * i], g ); + tmp = Madd_32_16( pDFT_RES[2 * i], pDFT_DMX[2 * i], g ); /* qDFT */ - DFT_L[2 * i] = L_add( pDFT_DMX[2 * i], tmp ); + DFT_L[2 * i] = L_add( pDFT_DMX[2 * i], tmp ); /* qDFT */ move32(); - DFT_R[2 * i] = L_sub( pDFT_DMX[2 * i], tmp ); + DFT_R[2 * i] = L_sub( pDFT_DMX[2 * i], tmp ); /* qDFT */ move32(); - tmp = Madd_32_16( pDFT_RES[2 * i + 1], pDFT_DMX[2 * i + 1], g ); + tmp = Madd_32_16( pDFT_RES[2 * i + 1], pDFT_DMX[2 * i + 1], g ); /* qDFT */ - DFT_L[add( shl( i, 1 ), 1 )] = L_add( pDFT_DMX[add( shl( i, 1 ), 1 )], tmp ); + DFT_L[2 * i + 1] = L_add( pDFT_DMX[2 * i + 1], tmp ); /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = L_sub( pDFT_DMX[add( shl( i, 1 ), 1 )], tmp ); + DFT_R[2 * i + 1] = L_sub( pDFT_DMX[2 * i + 1], tmp ); /* qDFT */ move32(); } @@ -2009,19 +2035,19 @@ void stereo_dft_dec_fx( move32(); WHILE( GT_32( theta, EVS_2PI_FX_Q27 ) ) { - theta = L_sub( theta, EVS_2PI_FX_Q27 ); + theta = L_sub( theta, EVS_2PI_FX_Q27 ); /* Q27 */ } WHILE( LT_32( theta, -EVS_2PI_FX_Q27 ) ) { - theta = L_add( theta, EVS_2PI_FX_Q27 ); + theta = L_add( theta, EVS_2PI_FX_Q27 ); /* Q27 */ } IF( GT_32( theta, EVS_PI_FX_Q27 ) ) { - theta = L_sub( theta, EVS_2PI_FX_Q27 ); + theta = L_sub( theta, EVS_2PI_FX_Q27 ); /* Q27 */ } ELSE IF( LT_32( theta, -EVS_PI_FX_Q27 ) ) { - theta = L_add( theta, EVS_2PI_FX_Q27 ); + theta = L_add( theta, EVS_2PI_FX_Q27 ); /* Q27 */ } c0 = getCosWord16( (Word16) L_shr( theta, 14 ) ); IF( EQ_16( c0, ONE_IN_Q14 ) ) @@ -2037,10 +2063,10 @@ void stereo_dft_dec_fx( FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { /*rotate L*/ - tmp = Msub_32_16( Mpy_32_16_1( DFT_L[2 * i], c0 ), DFT_L[add( shl( i, 1 ), 1 )], s0 ); - DFT_L[add( shl( i, 1 ), 1 )] = Madd_32_16( Mpy_32_16_1( DFT_L[2 * i], s0 ), DFT_L[add( shl( i, 1 ), 1 )], c0 ); + tmp = Msub_32_16( Mpy_32_16_1( DFT_L[2 * i], c0 ), DFT_L[2 * i + 1], s0 ); /* qDFT */ + DFT_L[2 * i + 1] = Madd_32_16( Mpy_32_16_1( DFT_L[2 * i], s0 ), DFT_L[2 * i + 1], c0 ); /* qDFT */ move32(); - DFT_L[2 * i] = tmp; + DFT_L[2 * i] = tmp; /* qDFT */ move32(); } } @@ -2050,7 +2076,7 @@ void stereo_dft_dec_fx( test(); if ( hStereoDft->frame_sid_nodata || ( st0->VAD == 0 ) ) { - hFdCngDec->cna_band_limits[hFdCngDec->cna_nbands] = hStereoDft->band_limits[hFdCngDec->cna_nbands]; + hFdCngDec->cna_band_limits[hFdCngDec->cna_nbands] = hStereoDft->band_limits[hFdCngDec->cna_nbands]; /* Q0 */ move16(); } @@ -2063,7 +2089,7 @@ void stereo_dft_dec_fx( move16(); } - FOR( i = hStereoDft->band_limits[b]; i < shr( hStereoDft->NFFT, 1 ); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->NFFT / 2; i++ ) { DFT_L[2 * i] = 0; move32(); @@ -2078,13 +2104,13 @@ void stereo_dft_dec_fx( /*Nyquist Freq.*/ IF( EQ_16( hStereoDft->band_limits[b], shr( hStereoDft->NFFT, 1 ) ) ) { - DFT_L[1] = L_add( pDFT_DMX[1], Mpy_32_16_1( pDFT_DMX[1], g ) ); + DFT_L[1] = L_add( pDFT_DMX[1], Mpy_32_16_1( pDFT_DMX[1], g ) ); /* qDFT */ move32(); - DFT_R[1] = L_sub( pDFT_DMX[1], Mpy_32_16_1( pDFT_DMX[1], g ) ); + DFT_R[1] = L_sub( pDFT_DMX[1], Mpy_32_16_1( pDFT_DMX[1], g ) ); /* qDFT */ move32(); - DFT_L[1] = Mpy_32_16_1( DFT_L[1], INV_SQRT2_FX_Q15 ); + DFT_L[1] = Mpy_32_16_1( DFT_L[1], INV_SQRT2_FX_Q15 ); /* qDFT */ move32(); - DFT_R[1] = Mpy_32_16_1( DFT_R[1], INV_SQRT2_FX_Q15 ); + DFT_R[1] = Mpy_32_16_1( DFT_R[1], INV_SQRT2_FX_Q15 ); /* qDFT */ move32(); } ELSE @@ -2103,9 +2129,9 @@ void stereo_dft_dec_fx( /* Dummy upmix-> mono binauralization */ FOR( i = 0; i < hStereoDft->NFFT; i++ ) { - DFT_L[i] = L_add( pDFT_DMX[i], pDFT_RES[i] ); + DFT_L[i] = L_add( pDFT_DMX[i], pDFT_RES[i] ); /* qDFT */ move32(); - DFT_R[i] = L_sub( pDFT_DMX[i], pDFT_RES[i] ); + DFT_R[i] = L_sub( pDFT_DMX[i], pDFT_RES[i] ); /* qDFT */ move32(); } } @@ -2113,7 +2139,7 @@ void stereo_dft_dec_fx( /* Comfort Noise Addition */ IF( st0->flag_cna ) { - ptr_per = &hFdCngDec->smoothed_psd_fx[hFdCngCom->startBand]; + ptr_per = &hFdCngDec->smoothed_psd_fx[hFdCngCom->startBand]; /* hFdCngDec->smoothed_psd_exp */ scale_fact0 = 0; move16(); @@ -2165,16 +2191,16 @@ void stereo_dft_dec_fx( { IF( NE_16( q_loc1, q_loc2 ) ) { - op2 = L_shl( op2, sub( q_loc2, q_loc1 ) ); + op2 = L_shl( op2, sub( q_loc2, q_loc1 ) ); /* qloc2 */ q_loc2 = q_loc1; move16(); } - gamma = extract_h( L_sub( op1, op2 ) ); - gamma = shl( gamma, q_loc2 ); + gamma = extract_h( L_sub( op1, op2 ) ); /* qloc2 - 16 */ + gamma = shl( gamma, q_loc2 ); /* 2 * qloc2 - 16 */ } ELSE { - gamma = extract_h( L_shl( op1, q_loc1 ) ); + gamma = extract_h( L_shl( op1, q_loc1 ) ); /* 2 * qloc2 - 16 */ } } ELSE @@ -2183,7 +2209,7 @@ void stereo_dft_dec_fx( move16(); } - FOR( i = s_max( hFdCngDec->cna_band_limits[b], shr( hFdCngCom->startBand, 1 ) ); i < s_min( hFdCngDec->cna_band_limits[b + 1], ( L_FRAME16k ) >> 1 ); i++ ) + FOR( i = max( hFdCngDec->cna_band_limits[b], ( hFdCngCom->startBand / 2 ) ); i < min( hFdCngDec->cna_band_limits[b + 1], ( L_FRAME16k ) >> 1 ); i++ ) { Word32 l_tmp; lev1 = *ptr_per++; @@ -2196,17 +2222,17 @@ void stereo_dft_dec_fx( IF( ( lev1 > 0 ) && ( lev2 > 0 ) && GT_32( Mpy_32_16_1( L_max( lev1, lev2 ), (Word16) 0x6AAB ), L_min( lev1, lev2 ) ) ) { /* take the minimum of two adjacent frequency bins */ - cna_level = L_min( lev1, lev2 ); + cna_level = L_min( lev1, lev2 ); /* hFdCngDec->smoothed_psd_exp */ } ELSE { /* take the average of two adjacent frequency bins */ - cna_level = L_add( L_shr( lev1, 1 ), L_shr( lev2, 1 ) ); + cna_level = L_add( L_shr( lev1, 1 ), L_shr( lev2, 1 ) ); /* hFdCngDec->smoothed_psd_exp */ } q_cna_level = hFdCngDec->smoothed_psd_exp; move16(); l_tmp = Sqrt32( cna_level, &q_cna_level ); - scale_fact = Mpy_32_32( l_tmp, scale_fact0 ); + scale_fact = Mpy_32_32( l_tmp, scale_fact0 ); /* q_cna_level */ /* scale_fact0 will be in Q15 by the time the above operation is performed so the q of scale_fact represented now by q_cna_level has to be updated @@ -2214,32 +2240,32 @@ void stereo_dft_dec_fx( q_cna_level = sub( Q31, add( q_cna_level, Q16 ) ); /* generate comfort noise from gaussian noise and add to the decoded DFT spectrum */ - N1 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); - N2 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); - l_tmp = L_add( Madd_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); - l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); - DFT_L[2 * i] = L_add( DFT_L[2 * i], l_tmp ); + N1 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); /* q_cna_level */ + N2 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); /* q_cna_level */ + l_tmp = L_add( Madd_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); /* q_cna_level */ + l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); /* q_dft */ + DFT_L[2 * i] = L_add( DFT_L[2 * i], l_tmp ); /* q_dft */ move32(); - l_tmp = L_sub( Msub_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); - l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); - DFT_R[2 * i] = L_add( DFT_R[2 * i], l_tmp ); + l_tmp = L_sub( Msub_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); /* q_cna_level */ + l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); /* q_dft */ + DFT_R[2 * i] = L_add( DFT_R[2 * i], l_tmp ); /* q_dft */ move32(); - N1 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); - N2 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); - l_tmp = L_add( Madd_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); - l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); - DFT_L[2 * i + 1] = L_add( DFT_L[2 * i + 1], l_tmp ); + N1 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); /* q_cna_level */ + N2 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); /* q_cna_level */ + l_tmp = L_add( Madd_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); /* q_cna_level */ + l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); /* q_dft */ + DFT_L[2 * i + 1] = L_add( DFT_L[2 * i + 1], l_tmp ); /* q_dft */ move32(); - l_tmp = L_sub( Msub_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); - l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); - DFT_R[2 * i + 1] = L_add( DFT_R[2 * i + 1], l_tmp ); + l_tmp = L_sub( Msub_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); /* q_cna_level */ + l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); /* q_dft */ + DFT_R[2 * i + 1] = L_add( DFT_R[2 * i + 1], l_tmp ); /* q_dft */ move32(); } } /* update CNA re-scaling factor */ - hFdCngDec->cna_rescale_fact_fx = extract_l( L_shr( L_mult0( (Word16) 0x6666, hFdCngDec->cna_act_fact_fx ), Q15 ) ); + hFdCngDec->cna_rescale_fact_fx = extract_l( L_shr( L_mult0( (Word16) 0x6666, hFdCngDec->cna_act_fact_fx ), Q15 ) ); /* q_cna_act */ move16(); IF( !hFdCngDec->first_cna_noise_updated ) @@ -2250,9 +2276,9 @@ void stereo_dft_dec_fx( } /* Update memories */ - hStereoDft->past_DMX_pos = s_and( ( add( hStereoDft->past_DMX_pos, 1 ) ), ( STEREO_DFT_PAST_MAX - 1 ) ); + hStereoDft->past_DMX_pos = s_and( ( add( hStereoDft->past_DMX_pos, 1 ) ), ( STEREO_DFT_PAST_MAX - 1 ) ); /* Q0 */ move16(); - Copy32( pDFT_DMX, hStereoDft->DFT_past_DMX_fx[hStereoDft->past_DMX_pos], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ) ); + Copy32( pDFT_DMX, hStereoDft->DFT_past_DMX_fx[hStereoDft->past_DMX_pos], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ) ); /* qDFT */ hStereoDft->q_DFT_past_DMX_fx[hStereoDft->past_DMX_pos] = hStereoDft->q_dft; move16(); IF( pPredGain ) @@ -2260,20 +2286,20 @@ void stereo_dft_dec_fx( stereo_dft_adapt_sf_delay_fx( hStereoDft, pPredGain ); } - Copy32( DFT_L, DFT[0] + k * STEREO_DFT32MS_N_MAX, hStereoDft->NFFT ); - Copy32( DFT_R, DFT[1] + k * STEREO_DFT32MS_N_MAX, hStereoDft->NFFT ); + Copy32( DFT_L, DFT[0] + k * STEREO_DFT32MS_N_MAX, hStereoDft->NFFT ); /* qDFT */ + Copy32( DFT_R, DFT[1] + k * STEREO_DFT32MS_N_MAX, hStereoDft->NFFT ); /* qDFT */ } IF( st0->bfi && !prev_bfi ) { Word16 q_shift0; Word16 q_shift1; - idx_k0 = add( hStereoDft->past_DMX_pos, STEREO_DFT_PAST_MAX - 1 ) & ( STEREO_DFT_PAST_MAX - 1 ); + idx_k0 = add( hStereoDft->past_DMX_pos, STEREO_DFT_PAST_MAX - 1 ) & ( STEREO_DFT_PAST_MAX - 1 ); /* Q0 */ idx_k1 = add( idx_k0, 1 ) & ( STEREO_DFT_PAST_MAX - 1 ); q_shift0 = sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[idx_k0] ); q_shift1 = sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[idx_k1] ); /*dmx energy memory*/ - hStereoDft->past_dmx_nrg_fx = stereo_dft_dmx_swb_nrg_fx( hStereoDft->DFT_past_DMX_fx[idx_k0], hStereoDft->DFT_past_DMX_fx[idx_k1], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ), q_shift0, q_shift1 ); + hStereoDft->past_dmx_nrg_fx = stereo_dft_dmx_swb_nrg_fx( hStereoDft->DFT_past_DMX_fx[idx_k0], hStereoDft->DFT_past_DMX_fx[idx_k1], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ), q_shift0, q_shift1 ); /* 2 * q_DFT */ } stereo_dft_compute_td_stefi_params_fx( hStereoDft, samp_ratio ); @@ -2288,8 +2314,8 @@ void stereo_dft_dec_fx( *-------------------------------------------------------------------------*/ static void stereo_dft_compute_td_stefi_params_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word16 samp_ratio /* i : sampling ratio */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word16 samp_ratio /* i : sampling ratio Q13*/ ) { Word16 pdmx_ind; @@ -2307,9 +2333,9 @@ static void stereo_dft_compute_td_stefi_params_fx( Word32 op1; Word16 q_div, q_sqrt; - pdmx_ind = hStereoDft->past_DMX_pos; + pdmx_ind = hStereoDft->past_DMX_pos; /* Q0 */ move16(); - bres = hStereoDft->band_res[1]; + bres = hStereoDft->band_res[1]; /* Q0 */ move16(); test(); @@ -2322,16 +2348,16 @@ static void stereo_dft_compute_td_stefi_params_fx( return; } - bin0 = extract_l( L_shr_r( Mpy_32_16_1( (Word32) hStereoDft->NFFT, samp_ratio ), 1 ) ); + bin0 = extract_l( L_shr_r( Mpy_32_16_1( (Word32) hStereoDft->NFFT, samp_ratio ), 1 ) ); /* Q0 */ bin0 = shl( bin0, Q3 ); - bin0 = s_min( bin0, hStereoDft->band_limits[hStereoDft->nbands] ); - b = hStereoDft->nbands; + bin0 = s_min( bin0, hStereoDft->band_limits[hStereoDft->nbands] ); /* Q0 */ + b = hStereoDft->nbands; /* Q0 */ move16(); WHILE( GT_16( hStereoDft->band_limits[b], bin0 ) ) { - b = sub( b, 1 ); + b--; } - band0 = b; + band0 = b; /* Q0 */ move16(); /* calculate averages over high bands */ @@ -2356,11 +2382,11 @@ static void stereo_dft_compute_td_stefi_params_fx( pred_g = L_add( pred_g, L_shr( Mpy_32_16_1( L_add( L_shr( hStereoDft->res_pred_gain_fx[b + STEREO_DFT_BAND_MAX], 1 ), L_shr( hStereoDft->res_pred_gain_fx[b + 2 * STEREO_DFT_BAND_MAX], 1 ) ), dft_res_pred_weights_fx[bres][b - band0] ), - shift_g ) ); + shift_g ) ); /* Q30 - shift_g */ pred_gain_avg = L_add( pred_gain_avg, L_shr( Mpy_32_16_1( L_add( L_shr( hStereoDft->past_res_pred_gain_fx[STEFI_DELAY_IND( STEREO_DFT_TD_STEFI_SUBFR_DELAY + 2, pdmx_ind )][b], 1 ), L_shr( hStereoDft->past_res_pred_gain_fx[STEFI_DELAY_IND( STEREO_DFT_TD_STEFI_SUBFR_DELAY + 1, pdmx_ind )][b], 1 ) ), dft_res_pred_weights_fx[bres][b - band0] ), - shift_g ) ); + shift_g ) ); /* Q30 - shift_g */ nbands = add( nbands, 1 ); wsum = L_add( wsum, dft_res_pred_weights_fx[bres][b - band0] ); @@ -2378,14 +2404,14 @@ static void stereo_dft_compute_td_stefi_params_fx( move16(); return; } - wsum = L_shl( wsum, sub( Q16, shift_g ) ); - pred_g = BASOP_Util_Divide3232_Scale( pred_g, wsum, &q_div ); + wsum = L_shl( wsum, sub( Q16, shift_g ) ); /* Q31 - shift_g */ + pred_g = BASOP_Util_Divide3232_Scale( pred_g, wsum, &q_div ); /* q_div */ IF( GT_16( sub( 15, q_div ), 15 ) ) { pred_g = L_shl( pred_g, q_div ); } - pred_gain_avg = BASOP_Util_Divide3232_Scale( pred_gain_avg, wsum, &q_div ); + pred_gain_avg = BASOP_Util_Divide3232_Scale( pred_gain_avg, wsum, &q_div ); /* q_div */ IF( GT_16( sub( 15, q_div ), 15 ) ) { pred_gain_avg = L_shl( pred_gain_avg, q_div ); @@ -2401,10 +2427,10 @@ static void stereo_dft_compute_td_stefi_params_fx( nrg_pred_DMX = hStereoDft->hb_nrg_fx[1]; move32(); - op1 = BASOP_Util_Divide3232_Scale( L_add( EPSILON_FIX, nrg_DMX ), L_add( EPSILON_FIX, nrg_pred_DMX ), &q_div ); + op1 = BASOP_Util_Divide3232_Scale( L_add( EPSILON_FIX, nrg_DMX ), L_add( EPSILON_FIX, nrg_pred_DMX ), &q_div ); /* q_div */ q_sqrt = add( Q16, q_div ); op1 = Sqrt32( op1, &q_sqrt ); - g2 = Mpy_32_32( pred_g, op1 ); + g2 = Mpy_32_32( pred_g, op1 ); /* q_div + q_sqrt - 31 */ IF( LT_16( q_sqrt, 0 ) ) { g2 = L_shl( g2, q_sqrt ); @@ -2415,25 +2441,25 @@ static void stereo_dft_compute_td_stefi_params_fx( { IF( LT_32( L_shr( pred_gain_avg, q_sqrt ), g2 ) ) { - g2 = pred_gain_avg; + g2 = pred_gain_avg; /* q_pred_gain_avg */ move32(); } ELSE { g2 = L_min( Mpy_32_16_1( L_shr( pred_gain_avg, q_sqrt ), STEREO_DFT_STEFFI_GAIN_AMP_FX ), Madd_32_16( Mpy_32_16_1( L_shr( pred_gain_avg, q_sqrt ), sub( (Word16) 0x7FFF, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), - g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); - g2 = L_shl( g2, q_sqrt ); + g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); /* q_pred_gain_avg - q_sqrt */ + g2 = L_shl( g2, q_sqrt ); /* q_pred_gain_avg */ } } ELSE { g2 = L_min( Mpy_32_16_1( pred_gain_avg, STEREO_DFT_STEFFI_GAIN_AMP_FX ), Madd_32_16( Mpy_32_16_1( pred_gain_avg, sub( (Word16) 0x7FFF, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), - g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); + g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); /* q_pred_gain_avg */ } - hStereoDft->td_gain_fx[0] = L_deposit_h( (Word16) g2 ); + hStereoDft->td_gain_fx[0] = L_deposit_h( (Word16) g2 ); /* Q16 + q_pred_gain_avg */ hStereoDft->q_td_gain[0] = add( 16, q_pred_gain_avg ); move32(); move16(); @@ -2448,42 +2474,52 @@ static void stereo_dft_compute_td_stefi_params_fx( } static void stereo_dft_dequantize_ipd_fx( - Word16 *ind, - Word32 *out_fx, + Word16 *ind, /* Q0 */ + Word32 *out_fx, /* Q27 */ +#ifndef FIX_874_INCREASE_IPD_PRECISION const Word16 N, - const Word16 bits ) +#endif + const Word16 bits /* Q0 */ +) { - Word16 i; Word16 delta_fx; +#ifndef FIX_874_INCREASE_IPD_PRECISION + Word16 i; Word32 temp_out; +#endif IF( EQ_16( bits, 2 ) ) /* 2-bit phase quantization for the highest frequency band only */ { - delta_fx = ( EVS_PI_FX ) >> 1; + delta_fx = ( EVS_PI_FX ) >> 1; /* Q13 */ move16(); } ELSE IF( EQ_16( bits, 3 ) ) { - delta_fx = ( EVS_PI_FX ) >> 2; + delta_fx = ( EVS_PI_FX ) >> 2; /* Q13 */ move16(); } ELSE IF( EQ_16( bits, 4 ) ) { - delta_fx = ( EVS_PI_FX ) >> 3; + delta_fx = ( EVS_PI_FX ) >> 3; /* Q13 */ move16(); } ELSE { - delta_fx = ( EVS_PI_FX ) >> 2; + delta_fx = ( EVS_PI_FX ) >> 2; /* Q13 */ move16(); assert( 0 ); } +#ifndef FIX_874_INCREASE_IPD_PRECISION FOR( i = 0; i < N; i++ ) { - temp_out = L_sub( L_mult0( ind[i], delta_fx ), ( EVS_PI_FX ) ); - *out_fx = L_shl( temp_out, 14 ); + temp_out = L_sub( L_mult0( ind[i], delta_fx ), ( EVS_PI_FX ) ); /* Q13 */ + *out_fx = L_shl( temp_out, 14 ); /* Q27 */ move32(); } +#else + *out_fx = L_sub( W_sat_l( W_mult_32_16( L_shl( ind[0], 13 ), delta_fx ) ), EVS_PI_FX_Q27 ); + move32(); +#endif return; } @@ -2493,15 +2529,15 @@ static void stereo_dft_dequantize_ipd_fx( * *-------------------------------------------------------------------------*/ void stereo_dft_generate_res_pred_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word16 samp_ratio, /* i : sampling ratio */ - Word32 *pDFT_DMX, /* i : downmix signal */ - Word32 *DFT_PRED_RES, /* o : residual prediction signal */ - Word32 *pPredGain, /* i : residual prediction gains */ - const Word16 k, /* i : subframe index */ - Word32 *ap_filt_DMX, /* i : enhanced stereo filling signal */ - Word16 *stop, /* o : last FD stereo filling bin */ - const Word16 bfi /* i : BFI flag */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word16 samp_ratio, /* i : sampling ratio Q13*/ + Word32 *pDFT_DMX, /* i : downmix signal qDFT*/ + Word32 *DFT_PRED_RES, /* o : residual prediction signal qDFT*/ + Word32 *pPredGain, /* i : residual prediction gains Q31*/ + const Word16 k, /* i : subframe index Q0*/ + Word32 *ap_filt_DMX, /* i : enhanced stereo filling signal qDFT*/ + Word16 *stop, /* o : last FD stereo filling bin Q0*/ + const Word16 bfi /* i : BFI flag Q0*/ ) { /* general variables */ @@ -2538,24 +2574,24 @@ void stereo_dft_generate_res_pred_fx( } ELSE { - alpha = (Word16) ( 0x199A ); + alpha = (Word16) ( 0x199A ); /* Q15 */ move16(); } // gain_limit = 0x7FFF; // 2.0 in Q14 /* residual prediction only used up to 16 kHz (SWB) */ - nbands_respred = s_min( hStereoDft->nbands, STEREO_DFT_RES_PRED_BAND_MAX ); + nbands_respred = s_min( hStereoDft->nbands, STEREO_DFT_RES_PRED_BAND_MAX ); /* Q0 */ /* In ACELP mode the downmix signal is not available in bandwidth extension area. * * Therefore, the downmix energy in the corresponding subbands is estimated. */ - bin0 = (Word16) ( L_shr( L_add( L_mult0( hStereoDft->NFFT, samp_ratio ), ONE_IN_Q12 ), Q12 + 1 ) ); + bin0 = (Word16) ( L_shr( L_add( L_mult0( hStereoDft->NFFT, samp_ratio ), ONE_IN_Q12 ), Q12 + 1 ) ); /* Q0 */ move16(); - bin0 = s_min( bin0, hStereoDft->band_limits[hStereoDft->nbands] ); + bin0 = s_min( bin0, hStereoDft->band_limits[hStereoDft->nbands] ); /* Q0 */ b = hStereoDft->nbands; move16(); WHILE( GE_16( hStereoDft->band_limits[b], bin0 ) ) { - b = sub( b, 1 ); + b--; } band0 = b; move16(); @@ -2563,12 +2599,12 @@ void stereo_dft_generate_res_pred_fx( IF( LT_16( hStereoDft->res_pred_mode[k + STEREO_DFT_OFFSET], STEREO_DFT_RESPRED_ESF ) ) { /* no ESF signal available, use stereo filling over whole spectrum */ - lb_stefi_start_band = s_max( hStereoDft->res_pred_band_min, hStereoDft->res_cod_band_max ); + lb_stefi_start_band = s_max( hStereoDft->res_pred_band_min, hStereoDft->res_cod_band_max ); /* Q0 */ } ELSE { /* ESF signal available, use ESF in lowband, stereo filling in highband */ - lb_stefi_start_band = s_max( band0, hStereoDft->res_cod_band_max ); + lb_stefi_start_band = s_max( band0, hStereoDft->res_cod_band_max ); /* Q0 */ } IF( bfi ) @@ -2591,14 +2627,14 @@ void stereo_dft_generate_res_pred_fx( move64(); /* calculate band energies (low band only in case of ACELP) */ - FOR( i = hStereoDft->band_limits[b]; i < s_min( hStereoDft->band_limits[b + 1], bin0 ); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < min( hStereoDft->band_limits[b + 1], bin0 ); i++ ) { dmx_nrg_64bit = W_add( dmx_nrg_64bit, W_add( W_mult0_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), - W_mult0_32_32( pDFT_DMX[add( shl( i, 1 ), 1 )], pDFT_DMX[add( shl( i, 1 ), 1 )] ) ) ); + W_mult0_32_32( pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ) ) ); /* 2 * q_dft */ rev_nrg_64bit = W_add( rev_nrg_64bit, W_add( W_mult0_32_32( ap_filt_DMX[2 * i], ap_filt_DMX[2 * i] ), - W_mult0_32_32( ap_filt_DMX[add( shl( i, 1 ), 1 )], ap_filt_DMX[add( shl( i, 1 ), 1 )] ) ) ); + W_mult0_32_32( ap_filt_DMX[2 * i + 1], ap_filt_DMX[2 * i + 1] ) ) ); /* 2 * q_dft */ } q_shift = W_norm( dmx_nrg_64bit ); dmx_nrg = W_extract_l( W_shl( dmx_nrg_64bit, sub( q_shift, 32 ) ) ); // 2 * hStereoDft->q_dft + (q_shift - 32) @@ -2609,8 +2645,8 @@ void stereo_dft_generate_res_pred_fx( /* Reach a common Q for dmx_nrg and rev_nrg */ q_com = s_min( dmx_nrg_q, rev_nrg_q ); - dmx_nrg = L_shl( dmx_nrg, sub( q_com, dmx_nrg_q ) ); - rev_nrg = L_shl( rev_nrg, sub( q_com, rev_nrg_q ) ); + dmx_nrg = L_shl( dmx_nrg, sub( q_com, dmx_nrg_q ) ); /* q_com */ + rev_nrg = L_shl( rev_nrg, sub( q_com, rev_nrg_q ) ); /* q_com */ IF( LT_16( hStereoDft->q_smoothed_nrg, q_com ) ) { rev_nrg = L_shr( rev_nrg, shl( sub( q_com, hStereoDft->q_smoothed_nrg ), 1 ) ); @@ -2620,23 +2656,23 @@ void stereo_dft_generate_res_pred_fx( } ELSE IF( GT_16( hStereoDft->q_smoothed_nrg, q_com ) ) { - hStereoDft->smooth_res_nrg_fx[b] = L_shr( hStereoDft->smooth_res_nrg_fx[b], shl( sub( hStereoDft->q_smoothed_nrg, q_com ), 1 ) ); + hStereoDft->smooth_res_nrg_fx[b] = L_shr( hStereoDft->smooth_res_nrg_fx[b], shl( sub( hStereoDft->q_smoothed_nrg, q_com ), 1 ) ); /* hStereoDft->q_smoothed_nrg */ move32(); - hStereoDft->smooth_dmx_nrg_fx[b] = L_shr( hStereoDft->smooth_dmx_nrg_fx[b], shl( sub( hStereoDft->q_smoothed_nrg, q_com ), 1 ) ); + hStereoDft->smooth_dmx_nrg_fx[b] = L_shr( hStereoDft->smooth_dmx_nrg_fx[b], shl( sub( hStereoDft->q_smoothed_nrg, q_com ), 1 ) ); /* hStereoDft->q_smoothed_nrg */ move32(); q_smoothed_nrg_local[b] = q_com; move16(); } /* smoothing */ - hStereoDft->smooth_res_nrg_fx[b] = Madd_32_16( Mpy_32_16_1( hStereoDft->smooth_res_nrg_fx[b], alpha ), rev_nrg, sub( (Word16) ( 0x7FFF ), alpha ) ); + hStereoDft->smooth_res_nrg_fx[b] = Madd_32_16( Mpy_32_16_1( hStereoDft->smooth_res_nrg_fx[b], alpha ), rev_nrg, sub( (Word16) ( 0x7FFF ), alpha ) ); /* hStereoDft->q_smoothed_nrg */ move32(); - hStereoDft->smooth_dmx_nrg_fx[b] = Madd_32_16( Mpy_32_16_1( hStereoDft->smooth_dmx_nrg_fx[b], alpha ), dmx_nrg, sub( (Word16) ( 0x7FFF ), alpha ) ); + hStereoDft->smooth_dmx_nrg_fx[b] = Madd_32_16( Mpy_32_16_1( hStereoDft->smooth_dmx_nrg_fx[b], alpha ), dmx_nrg, sub( (Word16) ( 0x7FFF ), alpha ) ); /* hStereoDft->q_smoothed_nrg */ move32(); /* normalization factor */ IF( hStereoDft->smooth_res_nrg_fx[b] != 0 ) { - norm_fac = BASOP_Util_Divide3232_Scale( hStereoDft->smooth_dmx_nrg_fx[b], hStereoDft->smooth_res_nrg_fx[b], &q_norm_fac ); + norm_fac = BASOP_Util_Divide3232_Scale( hStereoDft->smooth_dmx_nrg_fx[b], hStereoDft->smooth_res_nrg_fx[b], &q_norm_fac ); /* q_norm_fac */ norm_fac = Sqrt16( norm_fac, &q_norm_fac ); IF( norm_fac != 0 ) { @@ -2673,7 +2709,7 @@ void stereo_dft_generate_res_pred_fx( } ELSE { - norm_fac = extract_l( L_shr( L_mult0( norm_fac, lim_norm_fac ), Q15 ) ); + norm_fac = extract_l( L_shr( L_mult0( norm_fac, lim_norm_fac ), Q15 ) ); /* q_norm_fac */ q_norm_fac = add( q_norm_fac, 1 ); test(); IF( q_norm_fac < 0 ) @@ -2700,11 +2736,11 @@ void stereo_dft_generate_res_pred_fx( move16(); } - FOR( i = hStereoDft->band_limits[b]; i < s_min( hStereoDft->band_limits[b + 1], bin0 ); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < min( hStereoDft->band_limits[b + 1], bin0 ); i++ ) { - DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( Mpy_32_16_1( pPredGain[b], norm_fac ), ap_filt_DMX[2 * i] ), q_norm_fac ); + DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( Mpy_32_16_1( pPredGain[b], norm_fac ), ap_filt_DMX[2 * i] ), q_norm_fac ); /* q_dft */ move32(); - DFT_PRED_RES[add( shl( i, 1 ), 1 )] = L_shl( Mpy_32_32( Mpy_32_16_1( pPredGain[b], norm_fac ), ap_filt_DMX[add( shl( i, 1 ), 1 )] ), q_norm_fac ); + DFT_PRED_RES[2 * i + 1] = L_shl( Mpy_32_32( Mpy_32_16_1( pPredGain[b], norm_fac ), ap_filt_DMX[2 * i + 1] ), q_norm_fac ); /* q_dft */ move32(); } } @@ -2718,13 +2754,16 @@ void stereo_dft_generate_res_pred_fx( } FOR( b = 0; b < STEREO_DFT_BAND_MAX; b++ ) { - hStereoDft->smooth_dmx_nrg_fx[b] = L_shl( hStereoDft->smooth_dmx_nrg_fx[b], sub( q_com, q_smoothed_nrg_local[b] ) ); - hStereoDft->smooth_res_nrg_fx[b] = L_shl( hStereoDft->smooth_res_nrg_fx[b], sub( q_com, q_smoothed_nrg_local[b] ) ); + hStereoDft->smooth_dmx_nrg_fx[b] = L_shl( hStereoDft->smooth_dmx_nrg_fx[b], sub( q_com, q_smoothed_nrg_local[b] ) ); /* q_com */ + move32(); + + hStereoDft->smooth_res_nrg_fx[b] = L_shl( hStereoDft->smooth_res_nrg_fx[b], sub( q_com, q_smoothed_nrg_local[b] ) ); /* q_com */ + move32(); } IF( GT_16( q_com, hStereoDft->q_dft ) ) { - scale_sig32( hStereoDft->smooth_dmx_nrg_fx, STEREO_DFT_BAND_MAX, sub( hStereoDft->q_dft, q_com ) ); - scale_sig32( hStereoDft->smooth_res_nrg_fx, STEREO_DFT_BAND_MAX, sub( hStereoDft->q_dft, q_com ) ); + scale_sig32( hStereoDft->smooth_dmx_nrg_fx, STEREO_DFT_BAND_MAX, sub( hStereoDft->q_dft, q_com ) ); /* q_dft */ + scale_sig32( hStereoDft->smooth_res_nrg_fx, STEREO_DFT_BAND_MAX, sub( hStereoDft->q_dft, q_com ) ); /* q_dft */ hStereoDft->q_smoothed_nrg = hStereoDft->q_dft; move16(); } @@ -2737,8 +2776,8 @@ void stereo_dft_generate_res_pred_fx( FOR( b = lb_stefi_start_band; b <= band0; b++ ) { Word16 temp, temp_e; - d_short_ind = add( sub( STEREO_DFT_PAST_MAX, STEREO_DFT_STEFFI_DELAY_SHORT ), b & 1 ); - temp = BASOP_Util_Divide1616_Scale( b, sub( hStereoDft->nbands, 1 ), &temp_e ); /*(float) b / ( hStereoDft->nbands - 1 )*/ + d_short_ind = add( sub( STEREO_DFT_PAST_MAX, STEREO_DFT_STEFFI_DELAY_SHORT ), b & 1 ); /* Q0 */ + temp = BASOP_Util_Divide1616_Scale( b, sub( hStereoDft->nbands, 1 ), &temp_e ); /*(float) b / ( hStereoDft->nbands - 1 )*/ IF( temp_e < 0 ) { temp = shl( temp, temp_e ); @@ -2755,20 +2794,20 @@ void stereo_dft_generate_res_pred_fx( move16(); /* Even number of window sliding (assymmetric OLA) */ - d_short_ind = shl( shr( d_short_ind, 1 ), 1 ); - d_long_ind = shl( shr( d_long_ind, 1 ), 1 ); + d_short_ind = shl( shr( d_short_ind, 1 ), 1 ); /* Q0 */ + d_long_ind = shl( shr( d_long_ind, 1 ), 1 ); /* Q0 */ - d_short = sub( STEREO_DFT_PAST_MAX, d_short_ind ); - d_long = sub( STEREO_DFT_PAST_MAX, d_long_ind ); + d_short = sub( STEREO_DFT_PAST_MAX, d_short_ind ); /* Q0 */ + d_long = sub( STEREO_DFT_PAST_MAX, d_long_ind ); /* Q0 */ - d_short_ind = add( add( d_short_ind, hStereoDft->past_DMX_pos ), 1 ) % STEREO_DFT_PAST_MAX; + d_short_ind = add( add( d_short_ind, hStereoDft->past_DMX_pos ), 1 ) % STEREO_DFT_PAST_MAX; /* Q0 */ move16(); - d_long_ind = add( add( d_long_ind, hStereoDft->past_DMX_pos ), 1 ) % STEREO_DFT_PAST_MAX; + d_long_ind = add( add( d_long_ind, hStereoDft->past_DMX_pos ), 1 ) % STEREO_DFT_PAST_MAX; /* Q0 */ move16(); - g_short = hStereoDft->stefi_short_gain_fx; + g_short = hStereoDft->stefi_short_gain_fx; /* Q15 */ move16(); - g_long = hStereoDft->stefi_long_gain_fx; + g_long = hStereoDft->stefi_long_gain_fx; /* Q15 */ move16(); /* change mixing ratio if long and short delay are the same */ @@ -2812,35 +2851,35 @@ void stereo_dft_generate_res_pred_fx( move32(); dmx_nrg = EPSILON_FIX; move32(); - FOR( i = hStereoDft->band_limits[b]; i < s_min( bin0, hStereoDft->band_limits[b + 1] ); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < min( bin0, hStereoDft->band_limits[b + 1] ); i++ ) { - dmx_nrg = Madd_32_32( Madd_32_32( dmx_nrg, pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[add( shl( i, 1 ), 1 )], pDFT_DMX[add( shl( i, 1 ), 1 )] ); + dmx_nrg = Madd_32_32( Madd_32_32( dmx_nrg, pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ); /* 2 * q_dft - 31 */ - DFT_PRED_RES[2 * i] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i], g_long ), q_shift1 ) ); + DFT_PRED_RES[2 * i] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i], g_long ), q_shift1 ) ); /* q_dft */ move32(); - DFT_PRED_RES[add( shl( i, 1 ), 1 )] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][add( shl( i, 1 ), 1 )], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][add( shl( i, 1 ), 1 )], g_long ), q_shift1 ) ); + DFT_PRED_RES[2 * i + 1] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i + 1], g_long ), q_shift1 ) ); /* q_dft */ move32(); - past_dmx_nrg = Madd_32_32( Madd_32_32( past_dmx_nrg, DFT_PRED_RES[2 * i], DFT_PRED_RES[2 * i] ), DFT_PRED_RES[add( shl( i, 1 ), 1 )], DFT_PRED_RES[add( shl( i, 1 ), 1 )] ); + past_dmx_nrg = Madd_32_32( Madd_32_32( past_dmx_nrg, DFT_PRED_RES[2 * i], DFT_PRED_RES[2 * i] ), DFT_PRED_RES[2 * i + 1], DFT_PRED_RES[2 * i + 1] ); /* q_dft */ } test(); IF( !bfi || GE_16( b, hStereoDft->res_cod_band_max ) ) { Word16 q_div; Word16 op; - op = BASOP_Util_Divide3232_Scale( L_add( 1, dmx_nrg ), L_add( 1, past_dmx_nrg ), &q_div ); + op = BASOP_Util_Divide3232_Scale( L_add( 1, dmx_nrg ), L_add( 1, past_dmx_nrg ), &q_div ); /* q_sqrt */ q_sqrt = q_div; move16(); norm_fac = Sqrt16( op, &q_sqrt ); - g2 = Mpy_32_16_1( pPredGain[b], norm_fac ); + g2 = Mpy_32_16_1( pPredGain[b], norm_fac ); /* Q31 */ IF( LE_32( q_sqrt, norm_l( g2 ) ) ) { g2 = L_shl( g2, q_sqrt ); pred_gain_avg = Madd_32_16( Mpy_32_16_1( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short ), - hStereoDft->past_res_pred_gain_fx[d_long_ind][b], g_long ); + hStereoDft->past_res_pred_gain_fx[d_long_ind][b], g_long ); /* Q31 */ g2 = L_min( Mpy_32_16_1( pred_gain_avg, STEREO_DFT_STEFFI_GAIN_AMP_FX ), Madd_32_16( Mpy_32_16_1( pred_gain_avg, sub( MAX_16, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), - g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); + g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); /* Q31 */ q_sqrt = 0; move16(); } @@ -2849,23 +2888,23 @@ void stereo_dft_generate_res_pred_fx( /* Multiplication with STEREO_DFT_STEFFI_GAIN_AMP_FX is avodided since the float value of this constant is 1.0f */ g2 = Madd_32_16( Mpy_32_16_1( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short ), - hStereoDft->past_res_pred_gain_fx[d_long_ind][b], g_long ); + hStereoDft->past_res_pred_gain_fx[d_long_ind][b], g_long ); /* Q31 */ q_sqrt = 0; move16(); } FOR( i = hStereoDft->band_limits[b]; i < min( bin0, hStereoDft->band_limits[b + 1] ); i++ ) { - DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( g2, DFT_PRED_RES[2 * i] ), q_sqrt ); + DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( g2, DFT_PRED_RES[2 * i] ), q_sqrt ); /* q_dft */ move32(); - DFT_PRED_RES[add( shl( i, 1 ), 1 )] = L_shl( Mpy_32_32( g2, DFT_PRED_RES[add( shl( i, 1 ), 1 )] ), q_sqrt ); + DFT_PRED_RES[2 * i + 1] = L_shl( Mpy_32_32( g2, DFT_PRED_RES[2 * i + 1] ), q_sqrt ); /* q_dft */ move32(); } } } ELSE { - set32_fx( DFT_PRED_RES + shl( hStereoDft->band_limits[b], 1 ), 0, shl( sub( min( bin0, hStereoDft->band_limits[b + 1] ), hStereoDft->band_limits[b] ), 1 ) ); + set32_fx( DFT_PRED_RES + shl( hStereoDft->band_limits[b], 1 ), 0, shl( sub( s_min( bin0, hStereoDft->band_limits[b + 1] ), hStereoDft->band_limits[b] ), 1 ) ); } } } @@ -2886,12 +2925,12 @@ void stereo_dft_generate_res_pred_fx( /* calculate high band energy only */ dmx_nrg = EPSILON_FIX; move32(); - FOR( i = bin0; i < shr( hStereoDft->NFFT, 1 ); i++ ) + FOR( i = bin0; i < hStereoDft->NFFT / 2; i++ ) { - dmx_nrg = L_add( dmx_nrg, Madd_32_32( Mpy_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[add( shl( i, 1 ), 1 )], pDFT_DMX[add( shl( i, 1 ), 1 )] ) ); + dmx_nrg = L_add( dmx_nrg, Madd_32_32( Mpy_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ) ); /* 2 * q_dft - 31 */ } - hStereoDft->hb_nrg_fx[0] = L_add( hStereoDft->hb_nrg_fx[0], div_l( dmx_nrg, shr( hStereoDft->NFFT, 2 ) ) ); + hStereoDft->hb_nrg_fx[0] = L_add( hStereoDft->hb_nrg_fx[0], div_l( dmx_nrg, shr( hStereoDft->NFFT, 2 ) ) ); /* Q15 */ move32(); *stop = bin0; move16(); @@ -2900,22 +2939,22 @@ void stereo_dft_generate_res_pred_fx( { /* TCX/HQ core -> ACELP transition */ /* apply short delay only and blend to long/short gain */ - dmx_nrg = hStereoDft->hb_nrg_subr_fx[k]; + dmx_nrg = hStereoDft->hb_nrg_subr_fx[k]; /* Q15 */ move32(); d_short_ind = STEREO_DFT_PAST_MAX - STEREO_DFT_TD_STEFI_SUBFR_DELAY; move16(); - d_short_ind = s_and( add( d_short_ind, add( hStereoDft->past_DMX_pos, 1 ) ), ( STEREO_DFT_PAST_MAX - 1 ) ); + d_short_ind = s_and( add( d_short_ind, add( hStereoDft->past_DMX_pos, 1 ) ), ( STEREO_DFT_PAST_MAX - 1 ) ); /* Q0 */ /* calculate high band energy of past dmx */ // past_dmx_nrg = EPSILON_FIX; past_dmx_nrg = 0; move32(); - FOR( i = bin0; i < s_min( shr( hStereoDft->NFFT, 1 ), STEREO_DFT32MS_N_32k / 2 ); i++ ) + FOR( i = bin0; i < min( ( hStereoDft->NFFT / 2 ), ( STEREO_DFT32MS_N_32k / 2 ) ); i++ ) { - past_dmx_nrg = L_add( past_dmx_nrg, Madd_32_32( Mpy_32_32( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i] ), hStereoDft->DFT_past_DMX_fx[d_short_ind][add( shl( i, 1 ), 1 )], hStereoDft->DFT_past_DMX_fx[d_short_ind][add( shl( i, 1 ), 1 )] ) ); + past_dmx_nrg = L_add( past_dmx_nrg, Madd_32_32( Mpy_32_32( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i] ), hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1], hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1] ) ); /* 2 * hStereoDft->q_DFT_past_DMX_fx[d_short_ind] - 31 */ } - past_dmx_nrg = L_shl( past_dmx_nrg, shl( sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_short_ind] ), 1 ) ); + past_dmx_nrg = L_shl( past_dmx_nrg, shl( sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_short_ind] ), 1 ) ); /* 2 * hStereoDft->q_dft - 31*/ IF( past_dmx_nrg == 0 ) { past_dmx_nrg = EPSILON_FX; @@ -2941,8 +2980,8 @@ void stereo_dft_generate_res_pred_fx( Word32 op = BASOP_Util_Divide3232_Scale( L_add( EPSILON_FIX, dmx_nrg ), L_add( EPSILON_FIX, past_dmx_nrg ), &q_divide ); q_norm_fac = add( add( Q16, q_divide ), hStereoDft->q_hb_nrg_subr ); op = Sqrt32( op, &q_norm_fac ); - g2 = Mpy_32_32( pPredGain[b], op ); - pred_gain_avg = Mpy_32_16_1( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short ); + g2 = Mpy_32_32( pPredGain[b], op ); /* Q31 */ + pred_gain_avg = Mpy_32_16_1( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short ); /* Q31 */ IF( q_norm_fac < 0 ) { g2 = L_shl( g2, q_norm_fac ); @@ -2960,30 +2999,30 @@ void stereo_dft_generate_res_pred_fx( { g2 = L_min( Mpy_32_16_1( L_shr( pred_gain_avg, q_norm_fac ), STEREO_DFT_STEFFI_GAIN_AMP_FX ), Madd_32_16( Mpy_32_16_1( L_shr( pred_gain_avg, q_norm_fac ), sub( (Word16) 0x7FFF, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), - g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); - g2 = L_shl( g2, q_norm_fac ); + g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); /* Q31 - q_norm_fac */ + g2 = L_shl( g2, q_norm_fac ); /* Q31 */ } } ELSE { g2 = L_min( Mpy_32_16_1( pred_gain_avg, STEREO_DFT_STEFFI_GAIN_AMP_FX ), Madd_32_16( Mpy_32_16_1( pred_gain_avg, sub( (Word16) 0x7FFF, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), - g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); + g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); /* Q31 */ } q_shift = sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_short_ind] ); move16(); - FOR( i = s_max( hStereoDft->band_limits[b], bin0 ); i < s_min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) + FOR( i = max( hStereoDft->band_limits[b], bin0 ); i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) { - DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( g2, hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i] ), q_shift ); + DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( g2, hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i] ), q_shift ); /* q_dft */ move32(); - DFT_PRED_RES[add( shl( i, 1 ), 1 )] = L_shl( Mpy_32_32( g2, hStereoDft->DFT_past_DMX_fx[d_short_ind][add( shl( i, 1 ), 1 )] ), q_shift ); + DFT_PRED_RES[2 * i + 1] = L_shl( Mpy_32_32( g2, hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1] ), q_shift ); /* q_dft */ move32(); } } ELSE { - begin = s_max( hStereoDft->band_limits[b], bin0 ); - end = s_min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); + begin = s_max( hStereoDft->band_limits[b], bin0 ); /* Q0 */ + end = s_min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); /* Q0 */ set32_fx( DFT_PRED_RES + shl( begin, 1 ), 0, shl( sub( end, begin ), 1 ) ); } } @@ -2993,7 +3032,7 @@ void stereo_dft_generate_res_pred_fx( FOR( b = band0; b < nbands_respred; b++ ) { /* TCX/HQ core -> TCX/HQ core: business as usual */ - d_short_ind = add( sub( STEREO_DFT_PAST_MAX, STEREO_DFT_STEFFI_DELAY_SHORT ), b & 1 ); + d_short_ind = add( sub( STEREO_DFT_PAST_MAX, STEREO_DFT_STEFFI_DELAY_SHORT ), b & 1 ); /* Q0 */ Word16 temp, temp_e; temp = BASOP_Util_Divide1616_Scale( b, sub( hStereoDft->nbands, 1 ), &temp_e ); /*(float) b / ( hStereoDft->nbands - 1 )*/ IF( temp_e < 0 ) @@ -3005,31 +3044,31 @@ void stereo_dft_generate_res_pred_fx( temp = shr( temp, 3 ); /*adding 3 as guard bit*/ temp_e = add( temp_e, 3 ); temp = shr( add( imult1616( ( STEREO_DFT_PAST_MAX + 4 - 1 ), temp ), shl( 1, sub( 14, temp_e ) ) ), sub( 15, temp_e ) ); /*( (float) b / ( hStereoDft->nbands - 1 ) ) + 0.5f*/ /*Q0*/ - d_long_ind = sub( s_max( 4, temp ), 4 ); + d_long_ind = sub( s_max( 4, temp ), 4 ); /* Q0 */ /* make sure d_short really corresponds to a shorter or equally long delay than d_long (e.g. not always the case for * STEREO_DFT_STEFFI_DELAY_SHORT=3 and STEREO_DFT_STEFFI_DELAY_LONG=4)*/ - d_short_ind = s_max( d_short_ind, d_long_ind ); + d_short_ind = s_max( d_short_ind, d_long_ind ); /* Q0 */ /* Even number of window sliding (assymmetric OLA) */ - d_short_ind = d_short_ind & (Word16) ( 0xFFFE ); + d_short_ind = d_short_ind & (Word16) ( 0xFFFE ); /* Q0 */ move16(); - d_long_ind = d_long_ind & (Word16) ( 0xFFFE ); + d_long_ind = d_long_ind & (Word16) ( 0xFFFE ); /* Q0 */ move16(); - d_short = sub( STEREO_DFT_PAST_MAX, d_short_ind ); + d_short = sub( STEREO_DFT_PAST_MAX, d_short_ind ); /* Q0 */ move16(); - d_long = sub( STEREO_DFT_PAST_MAX, d_long_ind ); + d_long = sub( STEREO_DFT_PAST_MAX, d_long_ind ); /* Q0 */ move16(); /* Works as long as STEREO_DFT_PAST_MAX is a power of 2*/ - d_short_ind = ( add( d_short_ind, add( hStereoDft->past_DMX_pos, 1 ) ) ) & ( STEREO_DFT_PAST_MAX - 1 ); + d_short_ind = ( add( d_short_ind, add( hStereoDft->past_DMX_pos, 1 ) ) ) & ( STEREO_DFT_PAST_MAX - 1 ); /* Q0 */ move16(); - d_long_ind = ( add( d_long_ind, add( hStereoDft->past_DMX_pos, 1 ) ) ) & ( STEREO_DFT_PAST_MAX - 1 ); + d_long_ind = ( add( d_long_ind, add( hStereoDft->past_DMX_pos, 1 ) ) ) & ( STEREO_DFT_PAST_MAX - 1 ); /* Q0 */ move16(); - g_short = hStereoDft->stefi_short_gain_fx; + g_short = hStereoDft->stefi_short_gain_fx; /* Q15 */ move16(); - g_long = hStereoDft->stefi_long_gain_fx; + g_long = hStereoDft->stefi_long_gain_fx; /* Q15 */ move16(); /* change mixing ratio if long and short delay are the same */ @@ -3086,18 +3125,18 @@ void stereo_dft_generate_res_pred_fx( move32(); dmx_nrg = EPSILON_FIX; move32(); - FOR( i = s_max( hStereoDft->band_limits[b], bin0 ); i < s_min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) + FOR( i = max( hStereoDft->band_limits[b], bin0 ); i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) { - dmx_nrg = L_add( dmx_nrg, Madd_32_32( Mpy_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[add( shl( i, 1 ), 1 )], pDFT_DMX[add( shl( i, 1 ), 1 )] ) ); + dmx_nrg = L_add( dmx_nrg, L_shr( Madd_32_32( Mpy_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ), 1 ) ); /* 2 * q_dft - 31 - 1 */ - DFT_PRED_RES[2 * i] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i], g_long ), q_shift1 ) ); + DFT_PRED_RES[2 * i] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i], g_long ), q_shift1 ) ); /* q_dft */ move32(); - DFT_PRED_RES[add( shl( i, 1 ), 1 )] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][add( shl( i, 1 ), 1 )], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][add( shl( i, 1 ), 1 )], g_long ), q_shift1 ) ); + DFT_PRED_RES[2 * i + 1] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i + 1], g_long ), q_shift1 ) ); /* q_dft */ move32(); - past_dmx_nrg = L_add( past_dmx_nrg, Madd_32_32( Mpy_32_32( DFT_PRED_RES[2 * i], DFT_PRED_RES[2 * i] ), DFT_PRED_RES[2 * i + 1], DFT_PRED_RES[2 * i + 1] ) ); + past_dmx_nrg = L_add( past_dmx_nrg, L_shr( Madd_32_32( Mpy_32_32( DFT_PRED_RES[2 * i], DFT_PRED_RES[2 * i] ), DFT_PRED_RES[2 * i + 1], DFT_PRED_RES[2 * i + 1] ), 1 ) ); /* 2 * q_dft - 31 -1 */ } - op1 = L_deposit_h( BASOP_Util_Divide3232_Scale( ( EPSILON_FIX + dmx_nrg ), ( EPSILON_FIX + past_dmx_nrg ), &q_div ) ); + op1 = L_deposit_h( BASOP_Util_Divide3232_Scale( ( EPSILON_FIX + dmx_nrg ), ( EPSILON_FIX + past_dmx_nrg ), &q_div ) ); /* q_div + 16 */ q_norm_fac = q_div; move16(); op1 = Sqrt32( op1, &q_norm_fac ); @@ -3105,26 +3144,26 @@ void stereo_dft_generate_res_pred_fx( { assert( 0 ); } - norm_fac = extract_h( op1 ); + norm_fac = extract_h( op1 ); /* q_norm_fac - 16 */ q_norm_fac = sub( q_norm_fac, Q16 ); - g2 = Mpy_32_16_1( pPredGain[b], norm_fac ); - pred_gain_avg = Madd_32_16( Mpy_32_16_1( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short ), hStereoDft->past_res_pred_gain_fx[d_long_ind][b], g_long ); + g2 = Mpy_32_16_1( pPredGain[b], norm_fac ); /* Q31 */ + pred_gain_avg = Madd_32_16( Mpy_32_16_1( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short ), hStereoDft->past_res_pred_gain_fx[d_long_ind][b], g_long ); /* Q31 */ g2 = L_min( Mpy_32_16_1( pred_gain_avg, STEREO_DFT_STEFFI_GAIN_AMP_FX ), - Madd_32_16( Mpy_32_16_1( pred_gain_avg, sub( (Word16) ( 0x7FFF ), STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); + Madd_32_16( Mpy_32_16_1( pred_gain_avg, sub( (Word16) ( 0x7FFF ), STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); /* Q31 */ - FOR( i = s_max( hStereoDft->band_limits[b], bin0 ); i < s_min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) + FOR( i = max( hStereoDft->band_limits[b], bin0 ); i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) { - DFT_PRED_RES[2 * i] = Mpy_32_32( g2, DFT_PRED_RES[2 * i] ); + DFT_PRED_RES[2 * i] = Mpy_32_32( g2, DFT_PRED_RES[2 * i] ); /* Q31 */ move32(); - DFT_PRED_RES[add( shl( i, 1 ), 1 )] = Mpy_32_32( g2, DFT_PRED_RES[add( shl( i, 1 ), 1 )] ); + DFT_PRED_RES[2 * i + 1] = Mpy_32_32( g2, DFT_PRED_RES[2 * i + 1] ); /* Q31 */ move32(); } } ELSE { - begin = s_max( hStereoDft->band_limits[b], bin0 ); - end = s_min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); + begin = s_max( hStereoDft->band_limits[b], bin0 ); /* Q0 */ + end = s_min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); /* Q0 */ set32_fx( DFT_PRED_RES + shl( begin, 1 ), 0, shl( sub( end, begin ), 1 ) ); } } @@ -3137,12 +3176,12 @@ void stereo_dft_generate_res_pred_fx( test(); IF( hStereoDft->attackPresent || hStereoDft->wasTransient ) { - hStereoDft->past_res_pred_gain_fx[s_and( add( hStereoDft->past_DMX_pos, 1 ), ( STEREO_DFT_PAST_MAX - 1 ) )][b] = MIN_32; + hStereoDft->past_res_pred_gain_fx[( hStereoDft->past_DMX_pos + 1 ) % STEREO_DFT_PAST_MAX][b] = MIN_32; move32(); } ELSE { - hStereoDft->past_res_pred_gain_fx[s_and( add( hStereoDft->past_DMX_pos, 1 ), ( STEREO_DFT_PAST_MAX - 1 ) )][b] = pPredGain[b]; + hStereoDft->past_res_pred_gain_fx[( hStereoDft->past_DMX_pos + 1 ) % STEREO_DFT_PAST_MAX][b] = pPredGain[b]; move32(); } } @@ -3188,32 +3227,32 @@ static void stereo_dft_adapt_sf_delay_fx( max_pg = pPredGain[b]; move16(); } - sum_pg = L_add( sum_pg, L_shr( pPredGain[b], q_guard ) ); + sum_pg = L_add( sum_pg, L_shr( pPredGain[b], q_guard ) ); /* q_gurad */ } IF( GT_16( q_guard, hStereoDft->q_lt_pred_gain ) ) { - hStereoDft->lt_pred_gain_fx = L_shr( hStereoDft->lt_pred_gain_fx, sub( q_guard, hStereoDft->q_lt_pred_gain ) ); + hStereoDft->lt_pred_gain_fx = L_shr( hStereoDft->lt_pred_gain_fx, sub( q_guard, hStereoDft->q_lt_pred_gain ) ); /* q_guard */ hStereoDft->q_lt_pred_gain = q_guard; move16(); } ELSE { - sum_pg = L_shr( sum_pg, sub( hStereoDft->q_lt_pred_gain, q_guard ) ); + sum_pg = L_shr( sum_pg, sub( hStereoDft->q_lt_pred_gain, q_guard ) ); /* hStereoDft->q_lt_pred_gain */ q_guard = hStereoDft->q_lt_pred_gain; move16(); } IF( sum_pg > 0 ) { /* Calculate mean of the prediction gain */ - hStereoDft->lt_pred_gain_fx = Madd_32_16( Mpy_32_16_1( sum_pg, STEREO_DFT_LT_PREDGAIN_UPD_FX ), hStereoDft->lt_pred_gain_fx, sub( MAX_16, STEREO_DFT_LT_PREDGAIN_UPD_FX ) ); + hStereoDft->lt_pred_gain_fx = Madd_32_16( Mpy_32_16_1( sum_pg, STEREO_DFT_LT_PREDGAIN_UPD_FX ), hStereoDft->lt_pred_gain_fx, sub( MAX_16, STEREO_DFT_LT_PREDGAIN_UPD_FX ) ); /* hStereoDft->q_lt_pred_gain */ /* Calculate the variation of the prediction gain */ - new_variation = L_abs( L_sub( sum_pg, hStereoDft->lt_pred_gain_fx ) ); - hStereoDft->lt_pred_gain_variation_fx = Madd_32_16( Mpy_32_16_1( new_variation, STEREO_DFT_VR_PREDGAIN_UPD_FX ), hStereoDft->lt_pred_gain_variation_fx, sub( MAX_16, STEREO_DFT_VR_PREDGAIN_UPD_FX ) ); + new_variation = L_abs( L_sub( sum_pg, hStereoDft->lt_pred_gain_fx ) ); /* hStereoDft->q_lt_pred_gain */ + hStereoDft->lt_pred_gain_variation_fx = Madd_32_16( Mpy_32_16_1( new_variation, STEREO_DFT_VR_PREDGAIN_UPD_FX ), hStereoDft->lt_pred_gain_variation_fx, sub( MAX_16, STEREO_DFT_VR_PREDGAIN_UPD_FX ) ); /* hStereoDft->q_lt_pred_gain */ } /* Calculate ratio of variation and mean of prediction gain */ - var_mean_ratio = STEREO_DFT_RES_RATIO_LIMIT_FX; + var_mean_ratio = STEREO_DFT_RES_RATIO_LIMIT_FX; /* Q31 */ move16(); IF( hStereoDft->lt_pred_gain_fx > 0 ) @@ -3227,40 +3266,40 @@ static void stereo_dft_adapt_sf_delay_fx( } IF( LT_32( L_shr( STEREO_DFT_RES_RATIO_LIMIT_FX_3_BY_2, q_div ), opr2 ) ) { - var_mean_ratio = STEREO_DFT_RES_RATIO_LIMIT_FX_3_BY_2; + var_mean_ratio = STEREO_DFT_RES_RATIO_LIMIT_FX_3_BY_2; /* Q31 */ move32(); } ELSE { - var_mean_ratio = L_shl( opr2, q_div ); + var_mean_ratio = L_shl( opr2, q_div ); /* Q31 */ } } IF( GT_32( max_pg, STEREO_DFT_STEFFI_PG_THRESHOLD_FX ) ) { /* slow upwards */ - alpha_up = STEREO_DFT_STEFFI_RATIO_UP_HIGH_FX; + alpha_up = STEREO_DFT_STEFFI_RATIO_UP_HIGH_FX; /* Q31 */ move16(); - alpha_down = STEREO_DFT_STEFFI_RATIO_DOWN_HIGH_FX; + alpha_down = STEREO_DFT_STEFFI_RATIO_DOWN_HIGH_FX; /* Q31 */ move16(); } ELSE { /* slow downwards */ - alpha_up = STEREO_DFT_STEFFI_RATIO_UP_LOW_FX; + alpha_up = STEREO_DFT_STEFFI_RATIO_UP_LOW_FX; /* Q31 */ move16(); - alpha_down = STEREO_DFT_STEFFI_RATIO_DOWN_LOW_FX; + alpha_down = STEREO_DFT_STEFFI_RATIO_DOWN_LOW_FX; /* Q31 */ move16(); } IF( GT_16( extract_h( var_mean_ratio ), extract_h( hStereoDft->lt_var_mean_ratio_fx ) ) ) { - hStereoDft->lt_var_mean_ratio_fx = Madd_32_32( Mpy_32_32( var_mean_ratio, alpha_up ), hStereoDft->lt_var_mean_ratio_fx, L_sub( MAX_32, alpha_up ) ); + hStereoDft->lt_var_mean_ratio_fx = Madd_32_32( Mpy_32_32( var_mean_ratio, alpha_up ), hStereoDft->lt_var_mean_ratio_fx, L_sub( MAX_32, alpha_up ) ); /* Q31 */ move32(); } ELSE { - hStereoDft->lt_var_mean_ratio_fx = Madd_32_32( Mpy_32_32( var_mean_ratio, alpha_down ), hStereoDft->lt_var_mean_ratio_fx, L_sub( MAX_32, alpha_down ) ); + hStereoDft->lt_var_mean_ratio_fx = Madd_32_32( Mpy_32_32( var_mean_ratio, alpha_down ), hStereoDft->lt_var_mean_ratio_fx, L_sub( MAX_32, alpha_down ) ); /* Q31 */ move32(); } @@ -3268,7 +3307,7 @@ static void stereo_dft_adapt_sf_delay_fx( variation is relatively high compared to the mean */ IF( GE_16( extract_h( hStereoDft->lt_var_mean_ratio_fx ), extract_h( STEREO_DFT_RES_RATIO_LIMIT_FX ) ) ) { - target_delay = L_shl( STEREO_DFT_STEFFI_DELAY_SHORT, Q15 ); + target_delay = L_shl( STEREO_DFT_STEFFI_DELAY_SHORT, Q15 ); /* Q15 */ move32(); } ELSE @@ -3276,11 +3315,11 @@ static void stereo_dft_adapt_sf_delay_fx( target_delay = L_min( L_shl( STEREO_DFT_STEFFI_DELAY_LONG, Q15 ), L_add( L_shl( STEREO_DFT_STEFFI_DELAY_SHORT, Q15 ), L_mult0( ( STEREO_DFT_STEFFI_DELAY_OFFSET + STEREO_DFT_STEFFI_DELAY_LONG - STEREO_DFT_STEFFI_DELAY_SHORT ), - sub( MAX_16, extract_h( L_shl( Mpy_32_16_1( hStereoDft->lt_var_mean_ratio_fx, ONE_STEREO_DFT_RES_RATIO_LIMIT_Q12 ), Q3 ) ) ) ) ) ); + sub( MAX_16, extract_h( L_shl( Mpy_32_16_1( hStereoDft->lt_var_mean_ratio_fx, ONE_STEREO_DFT_RES_RATIO_LIMIT_Q12 ), Q3 ) ) ) ) ) ); /* Q15 */ } /* Adapt the stereo filling delay by interpolating between two delay taps, one at the shortest delay and one at the longest delay */ - hStereoDft->stefi_short_gain_fx = extract_l( L_shr( L_sub( L_shl( STEREO_DFT_STEFFI_DELAY_LONG, Q15 ), target_delay ), 1 ) ); + hStereoDft->stefi_short_gain_fx = extract_l( L_shr( L_sub( L_shl( STEREO_DFT_STEFFI_DELAY_LONG, Q15 ), target_delay ), 1 ) ); /* Q15 */ q_sqrt = 0; move16(); IF( EQ_16( hStereoDft->stefi_short_gain_fx, MIN_16 ) ) @@ -3294,10 +3333,10 @@ static void stereo_dft_adapt_sf_delay_fx( { op = hStereoDft->stefi_short_gain_fx; move16(); - hStereoDft->stefi_long_gain_fx = Sqrt16( sub( MAX_16, mult( op, op ) ), &q_sqrt ); + hStereoDft->stefi_long_gain_fx = Sqrt16( sub( MAX_16, mult( op, op ) ), &q_sqrt ); /* Q15 */ IF( q_sqrt != 0 ) { - hStereoDft->stefi_long_gain_fx = shl( hStereoDft->stefi_long_gain_fx, q_sqrt ); + hStereoDft->stefi_long_gain_fx = shl( hStereoDft->stefi_long_gain_fx, q_sqrt ); /* Q15 */ } } @@ -3305,9 +3344,9 @@ static void stereo_dft_adapt_sf_delay_fx( } void stereo_dft_dec_sid_coh_fx( Decoder_State *st, /* i/o: decoder state structure */ - const Word16 nbands, /* i : number of DFT stereo bands */ - Word16 *coh_fx, /* i/o: coherence */ - Word16 *nb_bits /* i/o: number of bits read */ + const Word16 nbands, /* i : number of DFT stereo bands Q0*/ + Word16 *coh_fx, /* i/o: coherence Q15*/ + Word16 *nb_bits /* i/o: number of bits read Q0*/ ) { Word16 alpha_fx; @@ -3324,17 +3363,17 @@ void stereo_dft_dec_sid_coh_fx( Word16 bits_tmp; Word16 b; - nr_of_sid_stereo_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; + nr_of_sid_stereo_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; /* Q0 */ move16(); /* If the coherence is not encoded due to lack of bits set alpha to zero which leads to that the coherence */ /* from the previous frame is used. */ - IF( GT_16( sub( sub( nr_of_sid_stereo_bits, *nb_bits ), STEREO_DFT_N_COH_ALPHA_BITS - STEREO_DFT_PRED_NBITS ), 0 ) ) + IF( sub( sub( nr_of_sid_stereo_bits, *nb_bits ), STEREO_DFT_N_COH_ALPHA_BITS - STEREO_DFT_PRED_NBITS ) > 0 ) { /* Read coherence from bitstream */ - coh_pred_index = get_next_indice_fx( st, STEREO_DFT_PRED_NBITS ); /* Read predictor index */ + coh_pred_index = get_next_indice_fx( st, STEREO_DFT_PRED_NBITS ); /* Read predictor index Q0*/ ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_PRED_NBITS ); - alpha_index = get_next_indice_fx( st, STEREO_DFT_N_COH_ALPHA_BITS ); /* Read alpha index */ + alpha_index = get_next_indice_fx( st, STEREO_DFT_N_COH_ALPHA_BITS ); /* Read alpha index Q0*/ ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_N_COH_ALPHA_BITS ); alpha_step = 0; @@ -3343,10 +3382,10 @@ void stereo_dft_dec_sid_coh_fx( { IF( GT_16( sub( nr_of_sid_stereo_bits, *nb_bits ), dft_cng_coh_alpha_start[i] ) ) { - alpha_step = add( i, 1 ); + alpha_step = i + 1; } } - alpha_fx = dft_cng_alpha_bits_fx[alpha_step][alpha_index]; /*Q-15*/ + alpha_fx = dft_cng_alpha_bits_fx[alpha_step][alpha_index]; /* Q15 */ move16(); } ELSE @@ -3358,12 +3397,12 @@ void stereo_dft_dec_sid_coh_fx( FOR( i = *nb_bits; i < nr_of_sid_stereo_bits; i++ ) { get_next_indice_fx( st, 1 ); - ( *nb_bits ) = add( ( *nb_bits ), 1 ); + ( *nb_bits )++; } } - pptr_fx = dft_cng_coh_pred_fx[coh_pred_index]; /*Q-13*/ - pred_fx = 3276; /*Q-13*/ + pptr_fx = dft_cng_coh_pred_fx[coh_pred_index]; /*Q13*/ + pred_fx = 3276; /*Q13*/ move16(); move16(); FOR( b = 0; b < nbands; b++ ) @@ -3380,9 +3419,9 @@ void stereo_dft_dec_sid_coh_fx( /* Read residual index from bitstream */ IF( LT_16( *nb_bits, nr_of_sid_stereo_bits ) ) /* If the bit limit is reached, res_index = 0 is assumed for remaining indices */ { - bits_tmp = read_GR0( &st->bit_stream[st->next_bit_pos], &res_index, 1 ); - *nb_bits = add( *nb_bits, bits_tmp ); - st->next_bit_pos = add( st->next_bit_pos, bits_tmp ); + bits_tmp = read_GR0( &st->bit_stream[st->next_bit_pos], &res_index, 1 ); /* Q0 */ + *nb_bits = add( *nb_bits, bits_tmp ); /* Q0 */ + st->next_bit_pos = add( st->next_bit_pos, bits_tmp ); /* Q0 */ move16(); move16(); } @@ -3393,13 +3432,13 @@ void stereo_dft_dec_sid_coh_fx( } /* Reconstruct */ - res_index = dft_cng_coh_u2i[res_index]; + res_index = dft_cng_coh_u2i[res_index]; /* Q0 */ move16(); - pred_err_fx = shr( usdequant_fx( res_index, -13107 /*Q-15*/, 1638 /*Q-14*/ ), 2 ); - cohBandq_fx[b] = add( pred_fx, pred_err_fx ); /* Store for intra-frame prediction */ + pred_err_fx = shr( usdequant_fx( res_index, -13107 /*Q-15*/, 1638 /*Q-14*/ ), 2 ); /* Q15 */ + cohBandq_fx[b] = add( pred_fx, pred_err_fx ); /* Store for intra-frame prediction */ IF( GT_16( cohBandq_fx[b], 8192 ) ) { - cohBandq_fx[b] = 8192; + cohBandq_fx[b] = 8192; /* Q13 */ move16(); } ELSE IF( cohBandq_fx[b] < 0 ) @@ -3407,7 +3446,7 @@ void stereo_dft_dec_sid_coh_fx( cohBandq_fx[b] = 0; move16(); } - coh_fx[b] = shl_sat( cohBandq_fx[b], 2 ); /* Update memory for next frame */ + coh_fx[b] = shl_sat( cohBandq_fx[b], 2 ); /* Update memory for next frame */ /* Q15 */ move16(); pred_fx = 0; move16(); @@ -3417,29 +3456,30 @@ void stereo_dft_dec_sid_coh_fx( FOR( i = *nb_bits; i < nr_of_sid_stereo_bits; i++ ) { get_next_indice_fx( st, 1 ); - ( *nb_bits ) = add( ( *nb_bits ), 1 ); + ( *nb_bits )++; } return; } void stereo_dft_dequantize_itd_fx( - Word16 *ind, - Word32 *out_fx, - const Word32 output_Fs ) + Word16 *ind, /* Q0 */ + Word32 *out_fx, /* Q15 */ + const Word32 output_Fs /* Q0 */ +) { Word16 itd; Word16 mask; - mask = ( 1 << ( STEREO_DFT_ITD_NBITS - 1 ) ) - 1; + mask = ( 1 << ( STEREO_DFT_ITD_NBITS - 1 ) ) - 1; /* Q0 */ move16(); - itd = s_and( ind[0], mask ) + STEREO_DFT_ITD_MIN; + itd = s_and( ind[0], mask ) + STEREO_DFT_ITD_MIN; /* Q0 */ IF( shr( ind[0], ( STEREO_DFT_ITD_NBITS - 1 ) ) ) { - itd = imult1616( -1, itd ); + itd = imult1616( -1, itd ); /* Q0 */ } assert( ( ABSVAL( itd ) <= STEREO_DFT_ITD_MAX ) && ( ABSVAL( itd ) >= STEREO_DFT_ITD_MIN ) ); /*Convert back @ fs*/ - *out_fx = L_mult( itd, divide3232( output_Fs, STEREO_DFT_ITD_FS << 1 ) ); /*Q-15*/ + *out_fx = L_mult( itd, divide3232( output_Fs, STEREO_DFT_ITD_FS << 1 ) ); /*Q15*/ move32(); return; } @@ -3450,17 +3490,17 @@ void stereo_dft_dequantize_itd_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_read_BS_fx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word32 element_brate, /* i : element bitrate */ - Word32 *total_brate, /* o : total bitrate */ - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ - const Word16 bwidth, /* i : bandwidth */ - const Word16 output_frame, /* i : output frame length */ - Word32 res_buf_fx[STEREO_DFT_N_8k], /* o : residual buffer */ - Word16 *nb_bits, /* o : number of bits read */ - Word16 *coh_fx, /* i/o: Coherence */ - const Word16 ivas_format /* i : ivas format */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + Word32 *total_brate, /* o : total bitrate Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ + const Word16 bwidth, /* i : bandwidth Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + Word32 res_buf_fx[STEREO_DFT_N_8k], /* o : residual buffer Q0*/ + Word16 *nb_bits, /* o : number of bits read Q0*/ + Word16 *coh_fx, /* i/o: Coherence Q15*/ + const Word16 ivas_format /* i : ivas format Q0*/ ) { Word32 sg_tmp_fx[STEREO_DFT_BAND_MAX]; @@ -3485,7 +3525,7 @@ void stereo_dft_dec_read_BS_fx( * Initialization *-----------------------------------------------------------------*/ - k_offset = STEREO_DFT_OFFSET; + k_offset = STEREO_DFT_OFFSET; /* Q0 */ move16(); IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) @@ -3502,7 +3542,7 @@ void stereo_dft_dec_read_BS_fx( hStereoDft->frame_nodata = 0; hStereoDft->frame_sid_nodata = 1; hStereoDft->frame_sid = 1; - *nb_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; + *nb_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; /* Q0 */ } move16(); move16(); @@ -3516,8 +3556,8 @@ void stereo_dft_dec_read_BS_fx( hStereoDft->frame_sid = 0; *nb_bits = 0; *total_brate = 0; - hStereoDft->itd_fx[k = hStereoDft->prm_res[k_offset] - 1 + k_offset] = hStereoDft->itd_xfade_target_fx; - hStereoDft->gipd_fx[hStereoDft->prm_res[k_offset] - 1 + k_offset] = hStereoDft->ipd_xfade_target_fx; + hStereoDft->itd_fx[k = hStereoDft->prm_res[k_offset] - 1 + k_offset] = hStereoDft->itd_xfade_target_fx; /* Q15 */ + hStereoDft->gipd_fx[hStereoDft->prm_res[k_offset] - 1 + k_offset] = hStereoDft->ipd_xfade_target_fx; /* Q27 */ move16(); move16(); @@ -3537,7 +3577,7 @@ void stereo_dft_dec_read_BS_fx( move16(); move16(); - st->total_brate = L_mult0( *nb_bits, FRAMES_PER_SEC ); + st->total_brate = L_mult0( *nb_bits, FRAMES_PER_SEC ); /* Q0 */ } hStereoDft->reverb_flag = 0; @@ -3546,7 +3586,7 @@ void stereo_dft_dec_read_BS_fx( /* reverse the bitstream */ FOR( b = 0; b < *nb_bits; b++ ) { - bit_stream_side[b] = st->bit_stream[-b]; + bit_stream_side[b] = st->bit_stream[-b]; /* Q0 */ move16(); } @@ -3556,12 +3596,12 @@ void stereo_dft_dec_read_BS_fx( bit_stream_side[b] = 0; move16(); } - st->bit_stream = bit_stream_side; + st->bit_stream = bit_stream_side; /* Q0 */ /*init*/ - max_bits = *nb_bits; + max_bits = *nb_bits; /* Q0 */ *nb_bits = 0; - N_div = STEREO_DFT_NBDIV; + N_div = STEREO_DFT_NBDIV; /* Q0 */ move16(); move16(); @@ -3580,7 +3620,7 @@ void stereo_dft_dec_read_BS_fx( } ELSE { - hStereoDft->attackPresent = get_next_indice_fx( st, 1 ); + hStereoDft->attackPresent = get_next_indice_fx( st, 1 ); /* Q0 */ ( *nb_bits ) = add( ( *nb_bits ), 1 ); move16(); move16(); @@ -3590,7 +3630,7 @@ void stereo_dft_dec_read_BS_fx( test(); IF( EQ_16( bwidth, WB ) && hStereoDft->hConfig->ada_wb_res_cod_mode ) { - hStereoDft->res_cod_mode[k_offset] = get_next_indice_fx( st, 1 ); + hStereoDft->res_cod_mode[k_offset] = get_next_indice_fx( st, 1 ); /* Q0 */ move16(); ( *nb_bits ) = add( ( *nb_bits ), 1 ); move16(); @@ -3599,43 +3639,43 @@ void stereo_dft_dec_read_BS_fx( /* read number of bands in the bitstream - depends on the audio bandwidth and not to output_Fs */ IF( hStereoDft->frame_sid ) { - NFFT_inner = imult1616( inner_frame_tbl[bwidth], STEREO_DFT32MS_N_MAX / L_FRAME48k ); + NFFT_inner = imult1616( inner_frame_tbl[bwidth], STEREO_DFT32MS_N_MAX / L_FRAME48k ); /* Q0 */ } ELSE { - NFFT_inner = imult1616( inner_frame_tbl[st->bwidth], STEREO_DFT32MS_N_MAX / L_FRAME48k ); + NFFT_inner = imult1616( inner_frame_tbl[st->bwidth], STEREO_DFT32MS_N_MAX / L_FRAME48k ); /* Q0 */ } /* Use coarse band partition in inactive frames */ IF( hStereoDft->frame_sid ) { - hStereoDft->band_res[k_offset] = STEREO_DFT_BAND_RES_LOW; - hStereoDft->res_cod_mode[k_offset] = STEREO_DFT_RES_COD_OFF; + hStereoDft->band_res[k_offset] = STEREO_DFT_BAND_RES_LOW; /* Q0 */ + hStereoDft->res_cod_mode[k_offset] = STEREO_DFT_RES_COD_OFF; /* Q0 */ move16(); move16(); - hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], s_min( STEREO_DFT32MS_N_MAX, NFFT_inner ), DEC ); + hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], s_min( STEREO_DFT32MS_N_MAX, NFFT_inner ), DEC ); /* Q0 */ IF( hStereoDft->nbands > STEREO_DFT_COH_MAXBAND ) { - hStereoDft->band_limits[STEREO_DFT_COH_MAXBAND] = hStereoDft->band_limits[hStereoDft->nbands]; - hStereoDft->nbands = STEREO_DFT_COH_MAXBAND; + hStereoDft->band_limits[STEREO_DFT_COH_MAXBAND] = hStereoDft->band_limits[hStereoDft->nbands]; /* Q0 */ + hStereoDft->nbands = STEREO_DFT_COH_MAXBAND; /* Q0 */ move16(); move16(); } } ELSE { - hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], NFFT_inner, DEC ); + hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], NFFT_inner, DEC ); /* Q0 */ move16(); } - hStereoDft->res_cod_band_max = dft_band_res_cod[hStereoDft->band_res[k_offset]][hStereoDft->res_cod_mode[k_offset]]; + hStereoDft->res_cod_band_max = dft_band_res_cod[hStereoDft->band_res[k_offset]][hStereoDft->res_cod_mode[k_offset]]; /* Q0 */ move16(); - hStereoDft->res_cod_line_max = (Word16) L_shr( L_add( ( 1 << Q13 ) /*0.5f Q-14*/, L_shl( L_mult0( sub( hStereoDft->band_limits[hStereoDft->res_cod_band_max], 1 ), divide1616( shr( output_frame, 1 ), ( hStereoDft->NFFT ) ) ) /*Q-14*/, 1 ) ), Q14 ); + hStereoDft->res_cod_line_max = (Word16) L_shr( L_add( ( 1 << Q13 ) /*0.5f Q-14*/, L_shl( L_mult0( sub( hStereoDft->band_limits[hStereoDft->res_cod_band_max], 1 ), divide1616( shr( output_frame, 1 ), ( hStereoDft->NFFT ) ) ) /*Q-14*/, 1 ) ), Q14 ); /* Q0 */ move16(); - hStereoDft->res_cod_line_max = shl( shr( hStereoDft->res_cod_line_max, 3 ), 3 ); + hStereoDft->res_cod_line_max = shl( shr( hStereoDft->res_cod_line_max, 3 ), 3 ); /* Q0 */ move16(); - hStereoDft->res_pred_band_min = s_max( STEREO_DFT_RES_PRED_BAND_MIN, hStereoDft->res_cod_band_max ); + hStereoDft->res_pred_band_min = s_max( STEREO_DFT_RES_PRED_BAND_MIN, hStereoDft->res_cod_band_max ); /* Q0 */ move16(); @@ -3674,49 +3714,49 @@ void stereo_dft_dec_read_BS_fx( nb = st->next_bit_pos; move16(); move16(); - n_bits = read_flag_EC_DFT( &st->bit_stream[nb], &hStereoDft->side_gain_flag_1 ); + n_bits = read_flag_EC_DFT( &st->bit_stream[nb], &hStereoDft->side_gain_flag_1 ); /* Q0 */ nb = add( nb, n_bits ); IF( hStereoDft->side_gain_flag_1 == 0 ) { - b = read_BS_adapt_GR_sg( st->bit_stream, nb, ind1, hStereoDft->nbands, &hStereoDft->side_gain_flag_2, dft_maps_sg ); - n_bits = add( n_bits, b ); + b = read_BS_adapt_GR_sg( st->bit_stream, nb, ind1, hStereoDft->nbands, &hStereoDft->side_gain_flag_2, dft_maps_sg ); /* Q0 */ + n_bits = add( n_bits, b ); /* Q0 */ } ELSE { IF( EQ_16( hStereoDft->side_gain_flag_1, 2 ) ) /* differential */ { - b = read_BS_GR( st->bit_stream, nb, ind1, hStereoDft->nbands, &hStereoDft->side_gain_flag_2 ); - n_bits = add( n_bits, b ); + b = read_BS_GR( st->bit_stream, nb, ind1, hStereoDft->nbands, &hStereoDft->side_gain_flag_2 ); /* Q0 */ + n_bits = add( n_bits, b ); /* Q0 */ FOR( b = 0; b < hStereoDft->nbands; b++ ) { - ind1[b] = add( ind1[b], hStereoDft->side_gain_index_previous[b] ); + ind1[b] = add( ind1[b], hStereoDft->side_gain_index_previous[b] ); /* Q0 */ } } ELSE { FOR( b = 0; b < hStereoDft->nbands; b++ ) { - ind1[b] = get_value( &st->bit_stream[nb], STEREO_DFT_SIDEGAIN_NBITS ); - nb = add( nb, STEREO_DFT_SIDEGAIN_NBITS ); - n_bits = add( n_bits, STEREO_DFT_SIDEGAIN_NBITS ); + ind1[b] = get_value( &st->bit_stream[nb], STEREO_DFT_SIDEGAIN_NBITS ); /* Q0 */ + nb = add( nb, STEREO_DFT_SIDEGAIN_NBITS ); /* Q0 */ + n_bits = add( n_bits, STEREO_DFT_SIDEGAIN_NBITS ); /* Q0 */ } } } FOR( b = 0; b < hStereoDft->nbands; b++ ) { - hStereoDft->side_gain_index_previous[b] = ind1[b]; + hStereoDft->side_gain_index_previous[b] = ind1[b]; /* Q0 */ move16(); #ifdef FIX_860_FER_CRASH - hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX] = L_shl_sat( ind1[b], 26 ); + hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX] = L_shl_sat( ind1[b], 26 ); /* Q26 */ #else hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX] = L_shl( ind1[b], 26 ); #endif move32(); } - st->next_bit_pos = add( st->next_bit_pos, n_bits ); + st->next_bit_pos = add( st->next_bit_pos, n_bits ); /* Q0 */ ( *nb_bits ) = add( ( *nb_bits ), n_bits ); move16(); move16(); @@ -3728,34 +3768,34 @@ void stereo_dft_dec_read_BS_fx( IF( !hStereoDft->frame_sid_nodata ) { - itd_mode = get_next_indice_fx( st, STEREO_DFT_ITD_MODE_NBITS ); - ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_ITD_MODE_NBITS ); /*ITD mode flag: 1bit*/ + itd_mode = get_next_indice_fx( st, STEREO_DFT_ITD_MODE_NBITS ); /* Q0 */ + ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_ITD_MODE_NBITS ); /*ITD mode flag: 1bit Q0*/ move16(); hStereoDft->itd_fx[k + k_offset] = 0; move32(); IF( itd_mode ) { - ( *nb_bits ) = add( ( *nb_bits ), read_itd( st, &I ) ); + ( *nb_bits ) = add( ( *nb_bits ), read_itd( st, &I ) ); /* Q0 */ move16(); stereo_dft_dequantize_itd_fx( &I, hStereoDft->itd_fx + add( k, k_offset ), st->output_Fs ); } } ELSE IF( LE_16( *nb_bits, ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - STEREO_DFT_ITD_MODE_NBITS - STEREO_DFT_SID_ITD_NBITS - 1 - SID_FORMAT_NBITS ) ) ) { - itd_mode = get_next_indice_fx( st, STEREO_DFT_ITD_MODE_NBITS ); - ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_ITD_MODE_NBITS ); /*ITD mode flag: 1bit*/ + itd_mode = get_next_indice_fx( st, STEREO_DFT_ITD_MODE_NBITS ); /* Q0 */ + ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_ITD_MODE_NBITS ); /*ITD mode flag: 1bit*/ move16(); - hStereoDft->itd_fx[add( k, k_offset )] = 0; + hStereoDft->itd_fx[k + k_offset] = 0; /* Q0 */ move32(); IF( itd_mode ) { - sign_flag = get_next_indice_fx( st, 1 ); - I = get_next_indice_fx( st, STEREO_DFT_SID_ITD_NBITS ); - ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_SID_ITD_NBITS + 1 ); + sign_flag = get_next_indice_fx( st, 1 ); /* Q0 */ + I = get_next_indice_fx( st, STEREO_DFT_SID_ITD_NBITS ); /* Q0 */ + ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_SID_ITD_NBITS + 1 ); /* Q0 */ move16(); - I = shl( I, STEREO_DFT_SID_ITD_FAC ); - I = add( I, shl( sign_flag, 8 ) ); + I = shl( I, STEREO_DFT_SID_ITD_FAC ); /* Q0 */ + I = add( I, shl( sign_flag, 8 ) ); /* Q0 */ stereo_dft_dequantize_itd_fx( &I, hStereoDft->itd_fx + add( k, k_offset ), st->output_Fs ); } } @@ -3766,49 +3806,57 @@ void stereo_dft_dec_read_BS_fx( n_bits = 0; move16(); - nb = st->next_bit_pos; + nb = st->next_bit_pos; /* Q0 */ move16(); IF( !hStereoDft->frame_sid_nodata ) { /* Active frame */ - hStereoDft->no_ipd_flag = st->bit_stream[nb]; + hStereoDft->no_ipd_flag = st->bit_stream[nb]; /* Q0 */ move16(); - nb = add( nb, 1 ); - n_bits = add( n_bits, 1 ); + nb = add( nb, 1 ); /* Q0 */ + n_bits = add( n_bits, 1 ); /* Q0 */ IF( hStereoDft->no_ipd_flag == 0 ) { - ind1_ipd[0] = get_value( &st->bit_stream[nb], STEREO_DFT_GIPD_NBITS ); + ind1_ipd[0] = get_value( &st->bit_stream[nb], STEREO_DFT_GIPD_NBITS ); /* Q0 */ move16(); - nb = add( nb, STEREO_DFT_GIPD_NBITS ); - n_bits = add( n_bits, STEREO_DFT_GIPD_NBITS ); + nb = add( nb, STEREO_DFT_GIPD_NBITS ); /* Q0 */ + n_bits = add( n_bits, STEREO_DFT_GIPD_NBITS ); /* Q0 */ +#ifndef FIX_874_INCREASE_IPD_PRECISION stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), 1, STEREO_DFT_GIPD_NBITS ); +#else + stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), STEREO_DFT_GIPD_NBITS ); +#endif } } ELSE IF( LE_16( *nb_bits, ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - STEREO_DFT_FLAG_BITS - STEREO_DFT_SID_GIPD_NBITS - SID_FORMAT_NBITS ) ) ) { /* SID frame, only read IPD only if enough bits left in bitstream */ - hStereoDft->no_ipd_flag = st->bit_stream[nb]; + hStereoDft->no_ipd_flag = st->bit_stream[nb]; /* Q0 */ move16(); - nb = add( nb, 1 ); - n_bits = add( n_bits, 1 ); + nb = add( nb, 1 ); /* Q0 */ + n_bits = add( n_bits, 1 ); /* Q0 */ IF( hStereoDft->no_ipd_flag == 0 ) { - ind1_ipd[0] = get_value( &st->bit_stream[nb], STEREO_DFT_SID_GIPD_NBITS ); + ind1_ipd[0] = get_value( &st->bit_stream[nb], STEREO_DFT_SID_GIPD_NBITS ); /* Q0 */ move16(); - nb = add( nb, STEREO_DFT_SID_GIPD_NBITS ); - n_bits = add( n_bits, STEREO_DFT_SID_GIPD_NBITS ); + nb = add( nb, STEREO_DFT_SID_GIPD_NBITS ); /* Q0 */ + n_bits = add( n_bits, STEREO_DFT_SID_GIPD_NBITS ); /* Q0 */ +#ifndef FIX_874_INCREASE_IPD_PRECISION stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), 1, STEREO_DFT_SID_GIPD_NBITS ); +#else + stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), STEREO_DFT_SID_GIPD_NBITS ); +#endif } } ELSE { - hStereoDft->no_ipd_flag = 1; + hStereoDft->no_ipd_flag = 1; /* Q0 */ move16(); } - st->next_bit_pos = add( st->next_bit_pos, n_bits ); - ( *nb_bits ) = add( ( *nb_bits ), n_bits ); + st->next_bit_pos = add( st->next_bit_pos, n_bits ); /* Q0 */ + ( *nb_bits ) = add( ( *nb_bits ), n_bits ); /* Q0 */ move16(); move16(); @@ -3818,7 +3866,7 @@ void stereo_dft_dec_read_BS_fx( /* Residual prediction */ /* Switch it off if ITD detected */ n_bits = 0; - nb = st->next_bit_pos; + nb = st->next_bit_pos; /* Q0 */ move16(); move16(); @@ -3826,49 +3874,49 @@ void stereo_dft_dec_read_BS_fx( IF( !hStereoDft->frame_sid_nodata ) { test(); - IF( hStereoDft->res_pred_mode[add( k, k_offset )] && hStereoDft->attackPresent == 0 ) + IF( hStereoDft->res_pred_mode[k + k_offset] && hStereoDft->attackPresent == 0 ) { - nbands = s_min( hStereoDft->nbands, STEREO_DFT_RES_PRED_BAND_MAX ); + nbands = s_min( hStereoDft->nbands, STEREO_DFT_RES_PRED_BAND_MAX ); /* Q0 */ hStereoDft->reverb_flag = 0; - hStereoDft->nbands_respred = nbands; + hStereoDft->nbands_respred = nbands; /* Q0 */ move16(); move16(); /* Read bit for adaptive SF (WB/SWB & FB) */ IF( EQ_16( hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) { - hStereoDft->reverb_flag = get_next_indice_fx( st, STEREO_DFT_REVERB_MODE_NBITS ); - ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_REVERB_MODE_NBITS ); + hStereoDft->reverb_flag = get_next_indice_fx( st, STEREO_DFT_REVERB_MODE_NBITS ); /* Q0 */ + ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_REVERB_MODE_NBITS ); /* Q0 */ move16(); move16(); - nb = add( nb, STEREO_DFT_REVERB_MODE_NBITS ); + nb = add( nb, STEREO_DFT_REVERB_MODE_NBITS ); /* Q0 */ IF( hStereoDft->reverb_flag ) { - nbands = sub( nbands, STEREO_DFT_RES_PRED_BAND_MIN_CONST ); + nbands = sub( nbands, STEREO_DFT_RES_PRED_BAND_MIN_CONST ); /* Q0 */ } } /* get coding type */ - b = read_flag_EC_DFT( &st->bit_stream[nb], &hStereoDft->res_pred_flag_0 ); - nb = add( nb, b ); - n_bits = add( n_bits, b ); + b = read_flag_EC_DFT( &st->bit_stream[nb], &hStereoDft->res_pred_flag_0 ); /* Q0 */ + nb = add( nb, b ); /* Q0 */ + n_bits = add( n_bits, b ); /* Q0 */ IF( hStereoDft->res_pred_flag_0 == 0 ) { - b = read_BS_adapt_GR_rpg( st->bit_stream, nb, ind1_pred, hStereoDft->res_pred_band_min, nbands, &hStereoDft->res_pred_flag_1 ); - n_bits = add( n_bits, b ); + b = read_BS_adapt_GR_rpg( st->bit_stream, nb, ind1_pred, hStereoDft->res_pred_band_min, nbands, &hStereoDft->res_pred_flag_1 ); /* Q0 */ + n_bits = add( n_bits, b ); /* Q0 */ } ELSE { IF( EQ_16( hStereoDft->res_pred_flag_0, 2 ) ) { - b = read_BS_GR( st->bit_stream, nb, &ind1_pred[hStereoDft->res_pred_band_min], nbands - hStereoDft->res_pred_band_min, &hStereoDft->res_pred_flag_1 ); + b = read_BS_GR( st->bit_stream, nb, &ind1_pred[hStereoDft->res_pred_band_min], nbands - hStereoDft->res_pred_band_min, &hStereoDft->res_pred_flag_1 ); /* Q0 */ - n_bits = add( n_bits, b ); + n_bits = add( n_bits, b ); /* Q0 */ FOR( b = hStereoDft->res_pred_band_min; b < nbands; b++ ) { - ind1_pred[b] = add( ind1_pred[b], hStereoDft->res_pred_index_previous[b] ); + ind1_pred[b] = add( ind1_pred[b], hStereoDft->res_pred_index_previous[b] ); /* Q0 */ move16(); } } @@ -3876,10 +3924,10 @@ void stereo_dft_dec_read_BS_fx( { FOR( b = hStereoDft->res_pred_band_min; b < nbands; b++ ) { - ind1_pred[b] = get_value( &st->bit_stream[nb], STEREO_DFT_RES_GAINS_BITS ); + ind1_pred[b] = get_value( &st->bit_stream[nb], STEREO_DFT_RES_GAINS_BITS ); /* Q0 */ move16(); - nb = add( nb, STEREO_DFT_RES_GAINS_BITS ); - n_bits = add( n_bits, STEREO_DFT_RES_GAINS_BITS ); + nb = add( nb, STEREO_DFT_RES_GAINS_BITS ); /* Q0 */ + n_bits = add( n_bits, STEREO_DFT_RES_GAINS_BITS ); /* Q0 */ } } } @@ -3889,21 +3937,21 @@ void stereo_dft_dec_read_BS_fx( I = 0; move16(); stereo_dft_dequantize_res_gains_fx( ind1 + b, &I, hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), hStereoDft->res_pred_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), 1 ); - hStereoDft->res_pred_index_previous[b] = I; + hStereoDft->res_pred_index_previous[b] = I; /* Q0 */ move16(); - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = 0; + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = 0; /* Q26 */ move32(); } FOR( b = hStereoDft->res_pred_band_min; b < nbands; b++ ) { - I = ind1_pred[b]; + I = ind1_pred[b]; /* Q0 */ move16(); stereo_dft_dequantize_res_gains_fx( ind1 + b, &I, hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), hStereoDft->res_pred_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), 1 ); - hStereoDft->res_pred_index_previous[b] = I; + hStereoDft->res_pred_index_previous[b] = I; /* Q0 */ move16(); #ifdef FIX_860_FER_CRASH - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = L_shl_sat( I, 26 ); + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = L_shl_sat( I, 26 ); /* Q26 */ #else hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = L_shl( I, 26 ); #endif @@ -3916,9 +3964,9 @@ void stereo_dft_dec_read_BS_fx( move16(); stereo_dft_dequantize_res_gains_fx( ind1 + b, &I, hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), hStereoDft->res_pred_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), 1 ); move16(); - hStereoDft->res_pred_index_previous[b] = I; + hStereoDft->res_pred_index_previous[b] = I; /* Q0 */ move16(); - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = 0; + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = 0; /* Q26 */ move32(); } } @@ -3929,10 +3977,10 @@ void stereo_dft_dec_read_BS_fx( I = 0; move16(); stereo_dft_dequantize_res_gains_fx( ind1 + b, &I, hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), hStereoDft->res_pred_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), 1 ); - hStereoDft->res_pred_index_previous[b] = I; + hStereoDft->res_pred_index_previous[b] = I; /* Q0 */ move16(); #ifdef FIX_860_FER_CRASH - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = L_shl_sat( I, 26 ); + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = L_shl_sat( I, 26 ); /* Q26 */ #else hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = L_shl( I, 26 ); #endif @@ -3940,8 +3988,8 @@ void stereo_dft_dec_read_BS_fx( } } - st->next_bit_pos = add( st->next_bit_pos, n_bits ); - ( *nb_bits ) = add( ( *nb_bits ), n_bits ); + st->next_bit_pos = add( st->next_bit_pos, n_bits ); /* Q0 */ + ( *nb_bits ) = add( ( *nb_bits ), n_bits ); /* Q0 */ move16(); move16(); } @@ -3974,12 +4022,12 @@ void stereo_dft_dec_read_BS_fx( IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { // hStereoDft->recovery_flg = stereo_dft_sg_recovery( hStereoDft ); - hStereoDft->recovery_flg = stereo_dft_sg_recovery_fx( hStereoDft ); + hStereoDft->recovery_flg = stereo_dft_sg_recovery_fx( hStereoDft ); /* Q0 */ IF( hStereoDft->recovery_flg ) { - Copy32( sg_tmp_fx, hStereoDft->side_gain_fx + 2 * STEREO_DFT_BAND_MAX, STEREO_DFT_BAND_MAX ); - Copy32( res_pred_gain_tmp_fx, hStereoDft->res_pred_gain_fx + 2 * STEREO_DFT_BAND_MAX, STEREO_DFT_BAND_MAX ); + Copy32( sg_tmp_fx, hStereoDft->side_gain_fx + 2 * STEREO_DFT_BAND_MAX, STEREO_DFT_BAND_MAX ); /* Q31 */ + Copy32( res_pred_gain_tmp_fx, hStereoDft->res_pred_gain_fx + 2 * STEREO_DFT_BAND_MAX, STEREO_DFT_BAND_MAX ); /* Q31 */ } } @@ -3993,8 +4041,8 @@ void stereo_dft_dec_read_BS_fx( { Word16 dec[STEREO_DFT_N_MAX_RES]; - I = get_next_indice_fx( st, STEREO_DFT_RES_GLOBAL_GAIN_BITS ); - ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_RES_GLOBAL_GAIN_BITS ); + I = get_next_indice_fx( st, STEREO_DFT_RES_GLOBAL_GAIN_BITS ); /* Q0 */ + ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_RES_GLOBAL_GAIN_BITS ); /* Q0 */ move16(); move16(); @@ -4005,24 +4053,24 @@ void stereo_dft_dec_read_BS_fx( rc_uni_dec_init_fx( &range_uni_dec_state, bit_stream_side + *nb_bits, max_bits - *nb_bits ); - hStereoDft->res_global_gain_fx = ECSQ_dequantize_gain_fx( I ); + hStereoDft->res_global_gain_fx = ECSQ_dequantize_gain_fx( I ); /* Q15 */ move32(); #ifdef DEBUGGING dbgwrite_txt( (const float *) ( &hStereoDft->res_global_gain_fx ), 1, "fixed_res_global_gain.txt", NULL ); #endif - ecsq_inst.config_index = sub( shl( hStereoDft->res_cod_mode[k_offset], 1 ), 1 ); + ecsq_inst.config_index = sub( shl( hStereoDft->res_cod_mode[k_offset], 1 ), 1 ); /* Q0 */ move16(); ECSQ_decode( &ecsq_inst, hStereoDft->res_cod_line_max, dec ); - n_bits = rc_uni_dec_virtual_finish_fx( &range_uni_dec_state ); + n_bits = rc_uni_dec_virtual_finish_fx( &range_uni_dec_state ); /* Q0 */ set_zero_fx( res_buf_fx, STEREO_DFT_N_8k ); FOR( Word16 c = 0; c < hStereoDft->res_cod_line_max; c++ ) { - dec[c] = shl_sat( dec[c], 8 ); + dec[c] = shl_sat( dec[c], 8 ); /* Q0 */ move16(); } @@ -4042,7 +4090,7 @@ void stereo_dft_dec_read_BS_fx( set_zero_fx( res_buf_fx, STEREO_DFT_N_8k ); } - ( *nb_bits ) = add( ( *nb_bits ), n_bits ); + ( *nb_bits ) = add( ( *nb_bits ), n_bits ); /* Q0 */ pop_wmops(); } @@ -4056,11 +4104,11 @@ void stereo_dft_dec_read_BS_fx( test(); IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_16( ivas_format, MASA_FORMAT ) ) { - *nb_bits = (Word16) Mult_32_16( L_sub( element_brate, SID_2k40 ), INV_FRAME_PER_SEC_Q15 ); /* => hCPE->hCoreCoder[0]->total_brate = SID_2k40; */ + *nb_bits = (Word16) Mult_32_16( L_sub( element_brate, SID_2k40 ), INV_FRAME_PER_SEC_Q15 ); /* => hCPE->hCoreCoder[0]->total_brate = SID_2k40; Q0*/ move16(); } { - *total_brate = L_sub( element_brate, L_mult0( *nb_bits, FRAMES_PER_SEC ) ); + *total_brate = L_sub( element_brate, L_mult0( *nb_bits, FRAMES_PER_SEC ) ); /* Q0 */ move32(); } return; diff --git a/lib_dec/ivas_stereo_dft_plc_fx.c b/lib_dec/ivas_stereo_dft_plc_fx.c index de5dae9ecb6c0d8fc9ba80fd3ab24bfbc5aded2c..a8bb5a6e66248ae378a071d2b2f46bc917bfcd76 100644 --- a/lib_dec/ivas_stereo_dft_plc_fx.c +++ b/lib_dec/ivas_stereo_dft_plc_fx.c @@ -62,17 +62,17 @@ * ---------------------------------------------------------------*/ void stereo_dft_res_ecu_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ - Word32 *pDFT_RES, /* i/o: residual signal */ - Word32 *const DFT_PRED_RES, /* i/o: residual prediction signal */ - const Word16 k, /* i : Subframe index */ - const Word16 output_frame, /* i : Output frame length */ - const Word16 prev_bfi, /* i : Previous BFI */ - const Word32 dmx_nrg, /* i : Down-mix energy */ - Word16 *num_plocs, /* i/o: Number of peak locations */ - Word16 *plocs, /* i/o: Peak locations (bin) */ - Word32 *plocsi, /* i/o: Peak locations (fractional) */ - Word32 *input_mem /* o : Residual DFT buffer input mem */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ + Word32 *pDFT_RES, /* i/o: residual signal hStereoDft->q_dft*/ + Word32 *const DFT_PRED_RES, /* i/o: residual prediction signal hStereoDft->q_dft*/ + const Word16 k, /* i : Subframe index Q0*/ + const Word16 output_frame, /* i : Output frame length Q0*/ + const Word16 prev_bfi, /* i : Previous BFI Q0*/ + const Word32 dmx_nrg, /* i : Down-mix energy Qx*/ + Word16 *num_plocs, /* i/o: Number of peak locations Q0*/ + Word16 *plocs, /* i/o: Peak locations (bin) Q0*/ + Word32 *plocsi, /* i/o: Peak locations (fractional) Qx*/ + Word32 *input_mem /* o : Residual DFT buffer input mem Q11*/ ) { Word32 res_buf[L_FRAME8k] = { 0 }; @@ -83,10 +83,13 @@ void stereo_dft_res_ecu_fx( Word16 trigo_dec[STEREO_DFT32MS_N_8k / 2 + 1]; Word16 trigo_step; Word16 q_fac; +#ifdef NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST + Word16 time_offs; +#endif set32_fx( pDFT_RES, 0, L_FRAME8k ); - L_res = hStereoDft->band_limits[hStereoDft->res_cod_band_max]; + L_res = hStereoDft->band_limits[hStereoDft->res_cod_band_max]; /* Q0 */ move16(); stereo_dft_res_subst_spec_fx( hStereoDft, pDFT_RES, DFT_PRED_RES, hStereoDft->time_offs, L_res, L_FRAME8k, k, num_plocs, plocs, plocsi, k == 0 ); @@ -103,35 +106,40 @@ void stereo_dft_res_ecu_fx( IF( hStereoDft->core_hist[0] == ACELP_CORE ) { - fac = extract_l( L_shr( L_mult0( fac, 0x2000 ), 15 ) ); + fac = extract_l( L_shr( L_mult0( fac, 0x2000 ), 15 ) ); /* Q15 */ } - trigo_step = STEREO_DFT_TRIGO_SRATE_8k_STEP * STEREO_DFT_TRIGO_DEC_STEP; + trigo_step = STEREO_DFT_TRIGO_SRATE_8k_STEP * STEREO_DFT_TRIGO_DEC_STEP; /* Q0 */ move16(); FOR( i = 0; i < STEREO_DFT32MS_N_8k / 4; i++ ) { - trigo_dec[i] = hStereoDft->dft_trigo_8k_fx[i_mult( i, trigo_step )]; + trigo_dec[i] = hStereoDft->dft_trigo_8k_fx[i * trigo_step]; /* Q15 */ move16(); - trigo_dec[STEREO_DFT32MS_N_8k / 2 - i] = hStereoDft->dft_trigo_8k_fx[i_mult( i, trigo_step )]; + trigo_dec[STEREO_DFT32MS_N_8k / 2 - i] = hStereoDft->dft_trigo_8k_fx[i * trigo_step]; /* Q15 */ move16(); } - trigo_dec[STEREO_DFT32MS_N_8k / 4] = hStereoDft->dft_trigo_8k_fx[i_mult( STEREO_DFT32MS_N_8k / 4, trigo_step )]; + trigo_dec[STEREO_DFT32MS_N_8k / 4] = hStereoDft->dft_trigo_8k_fx[STEREO_DFT32MS_N_8k / 4 * trigo_step]; /* Q15 */ move16(); /* estimation of res_cod_mem (ola part in imdct residual signal) and input_mem (memory for buffer in DFT analysis)*/ IF( k == 0 ) { - Copy32( pDFT_RES, res_buf, L_FRAME8k ); + Copy32( pDFT_RES, res_buf, L_FRAME8k ); /* hStereoDft->q_dft */ +#ifdef NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST + time_offs = add_sat( hStereoDft->time_offs, output_frame ); + stereo_dft_res_subst_spec_fx( hStereoDft, res_buf, DFT_PRED_RES, time_offs, L_res, L_FRAME8k, k, num_plocs, plocs, plocsi, FALSE ); +#else stereo_dft_res_subst_spec_fx( hStereoDft, res_buf, DFT_PRED_RES, hStereoDft->time_offs + output_frame, L_res, L_FRAME8k, k, num_plocs, plocs, plocsi, FALSE ); +#endif rfft_fx( res_buf, trigo_dec, L_FRAME8k, +1 ); - v_multc_fixed_16( res_buf, fac, res_buf, L_FRAME8k ); - Copy32( res_buf + ( OFFSET8k - ZP8k ), &hStereoDft->res_cod_mem_fx[0], STEREO_DFT_OVL_8k ); + v_multc_fixed_16( res_buf, fac, res_buf, L_FRAME8k ); /* hStereoDft->q_dft */ + Copy32( res_buf + ( OFFSET8k - ZP8k ), &hStereoDft->res_cod_mem_fx[0], STEREO_DFT_OVL_8k ); /* hStereoDft->q_dft */ hStereoDft->q_res_cod_mem_fx = hStereoDft->q_dft; move16(); - Copy32( res_buf + ZP8k, input_mem, NS2SA( 8000, STEREO_DFT32MS_OVL_NS ) ); /* Store memory for cross-fade to next frame, in case of good frame */ + Copy32( res_buf + ZP8k, input_mem, NS2SA( 8000, STEREO_DFT32MS_OVL_NS ) ); /* Store memory for cross-fade to next frame, in case of good frame */ /* hStereoDft->q_dft */ hStereoDft->q_ip_mem = hStereoDft->q_dft; move16(); } @@ -141,13 +149,13 @@ void stereo_dft_res_ecu_fx( Word16 q_shift = sub( 8, scale_fac ); move16(); // Copy32( pDFT_RES, res_buf, L_FRAME8k ); - v_shr_32( pDFT_RES, res_buf, L_FRAME8k, q_shift ); + v_shr_32( pDFT_RES, res_buf, L_FRAME8k, q_shift ); /* hStereoDft->q_dft - q_shift */ rfft_fx( res_buf, trigo_dec, L_FRAME8k, +1 ); - v_shr_32( res_buf, res_buf, L_FRAME8k, negate( q_shift ) ); + v_shr_32( res_buf, res_buf, L_FRAME8k, negate( q_shift ) ); /* hStereoDft->q_dft */ - v_multc_fixed( res_buf, fac, res_buf, L_FRAME8k ); + v_multc_fixed( res_buf, fac, res_buf, L_FRAME8k ); /* hStereoDft->q_dft */ /* Cross-fade memory */ fac = 0; @@ -156,13 +164,17 @@ void stereo_dft_res_ecu_fx( move16(); FOR( i = 0; i < NS2SA( 8000, STEREO_DFT32MS_OVL_NS ); i++ ) { - input_mem[i] = Madd_32_16( Mpy_32_16_1( res_buf[i + L_FRAME8k - NS2SA( 8000, STEREO_DFT32MS_OVL_NS ) - ZP8k], sub( MAX_16, fac ) ), input_mem[i], fac ); + input_mem[i] = Madd_32_16( Mpy_32_16_1( res_buf[i + L_FRAME8k - NS2SA( 8000, STEREO_DFT32MS_OVL_NS ) - ZP8k], sub( MAX_16, fac ) ), input_mem[i], fac ); /* hStereoDft->q_dft */ move32(); fac = add( fac, step ); } /*in case of burst error*/ - hStereoDft->time_offs = add( hStereoDft->time_offs, L_FRAME8k ); +#ifdef NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST + hStereoDft->time_offs = add_sat( hStereoDft->time_offs, L_FRAME8k ); /* Q0 */ +#else + hStereoDft->time_offs = add( hStereoDft->time_offs, L_FRAME8k ); /* Q0 */ +#endif move16(); } @@ -184,22 +196,22 @@ void stereo_dft_res_ecu_fx( /*! r: interpolated maximum position */ Word32 imax_pos_fx( - const Word32 *y /* i : Input vector for peak interpolation */ + const Word32 *y /* i : Input vector for peak interpolation Qx*/ ) { Word32 posi, y1, y2, y3, y3_y1, y2i; Word32 ftmp_den1, ftmp_den2; Word16 q_div_2i, q_div_posi; /* Seek the extrema of the parabola P(x) defined by 3 consecutive points so that P([-1 0 1]) = [y1 y2 y3] */ - y1 = y[0]; + y1 = y[0]; /* Qx */ move32(); - y2 = y[1]; + y2 = y[1]; /* Qx */ move32(); - y3 = y[2]; + y3 = y[2]; /* Qx */ move32(); - y3_y1 = L_sub( y3, y1 ); - ftmp_den1 = L_sub( L_add( y1, y3 ), L_shl( y2, 1 ) ); - ftmp_den2 = L_shl( L_sub( L_sub( L_shl( y2, 1 ), y1 ), y3 ), 1 ); + y3_y1 = L_sub( y3, y1 ); /* Qx */ + ftmp_den1 = L_sub( L_add( y1, y3 ), L_shl( y2, 1 ) ); /* Qx */ + ftmp_den2 = L_shl( L_sub( L_sub( L_shl( y2, 1 ), y1 ), y3 ), 1 ); /* Qx */ test(); IF( ( ftmp_den2 == 0 ) || ( ftmp_den1 == 0 ) ) @@ -207,20 +219,20 @@ Word32 imax_pos_fx( return ( 0 ); /* early exit with left-most value */ } - y2i = Mpy_32_16_1( Mpy_32_16_1( y3_y1, BASOP_Util_Divide3232_Scale( y3_y1, ftmp_den1, &q_div_2i ) ), (Word16) ( 0xF000 ) ); + y2i = Mpy_32_16_1( Mpy_32_16_1( y3_y1, BASOP_Util_Divide3232_Scale( y3_y1, ftmp_den1, &q_div_2i ) ), (Word16) ( 0xF000 ) ); /* q_div_2i */ IF( q_div_2i < 0 ) { y2i = L_shl( y2i, q_div_2i ); q_div_2i = 0; move16(); - y2i = L_add( y2i, y2 ); + y2i = L_add( y2i, y2 ); /* Qx */ } ELSE { - y2i = L_add( y2i, L_shr( y2, q_div_2i ) ); + y2i = L_add( y2i, L_shr( y2, q_div_2i ) ); /* q_div_2i */ } /* their corresponding normalized locations */ - posi = BASOP_Util_Divide3232_Scale( y3_y1, ( ftmp_den2 ), &q_div_posi ); + posi = BASOP_Util_Divide3232_Scale( y3_y1, ( ftmp_den2 ), &q_div_posi ); /* q_div_posi */ IF( ( q_div_posi != 0 ) ) { posi = L_shl( posi, q_div_posi ); @@ -234,12 +246,12 @@ Word32 imax_pos_fx( // posi = GT_32( y3, y1 ) ? ONE_IN_Q15 : MIN_16; IF( GT_32( y3, y1 ) ) { - posi = ONE_IN_Q15; + posi = ONE_IN_Q15; /* Q15 */ move32(); } ELSE { - posi = MIN_16; + posi = MIN_16; /* Q15 */ move32(); } } @@ -250,19 +262,19 @@ Word32 imax_pos_fx( // posi = GT_32( y1, y3 ) ? MIN_16 : ONE_IN_Q15; IF( GT_32( y1, y3 ) ) { - posi = MIN_16; + posi = MIN_16; /* Q15 */ move32(); } ELSE { - posi = ONE_IN_Q15; + posi = ONE_IN_Q15; /* Q15 */ move32(); } move16(); } ELSE IF( GE_32( L_shr( y3, q_div_2i ), y2i ) ) { - posi = ONE_IN_Q15; + posi = ONE_IN_Q15; /* Q15 */ move16(); } } @@ -271,12 +283,12 @@ Word32 imax_pos_fx( } static void ivas_peakfinder_fx( - const Word32 *x0, /* i : vector from which the maxima will be found */ - const Word16 len0, /* i : length of input vector */ - Word16 *plocs, /* o : the indicies of the identified peaks in x0 */ - Word16 *cInd, /* o : number of identified peaks */ - const Word32 sel, /* i : The amount above surrounding data for a peak to be identified */ - const Word16 endpoints /* i : Flag to include endpoints in peak search */ + const Word32 *x0, /* i : vector from which the maxima will be found Qx*/ + const Word16 len0, /* i : length of input vector Q0*/ + Word16 *plocs, /* o : the indicies of the identified peaks in x0 Q0*/ + Word16 *cInd, /* o : number of identified peaks Q0*/ + const Word32 sel, /* i : The amount above surrounding data for a peak to be identified Q0*/ + const Word16 endpoints /* i : Flag to include endpoints in peak search Q0*/ ) { Word32 minMag, tempMag, leftMin; @@ -292,7 +304,7 @@ static void ivas_peakfinder_fx( v_sub_32( x0 + 1, x0, dx0, sub( len0, 1 ) ); /* This is so we find the first of repeated values */ - FOR( i = 0; i < sub( len0, 1 ); i++ ) + FOR( i = 0; i < len0 - 1; i++ ) { IF( dx0[i] == 0 ) { @@ -308,29 +320,29 @@ static void ivas_peakfinder_fx( IF( endpoints ) { - x[k] = x0[0]; + x[k] = x0[0]; /* Qx */ move32(); ind[k] = 0; move16(); k = add( k, 1 ); } - FOR( i = 1; i < sub( len0, 1 ); i++ ) + FOR( i = 1; i < len0 - 1; i++ ) { IF( L_xor( dx0[i - 1], dx0[i] ) < 0 ) { - ind[k] = i; + ind[k] = i; /* Q0 */ move16(); - x[k++] = x0[i]; + x[k++] = x0[i]; /* Qx */ move32(); } } IF( endpoints ) { - ind[k] = sub( len0, 1 ); + ind[k] = sub( len0, 1 ); /* Q0 */ move16(); - x[k] = x0[sub( len0, 1 )]; + x[k] = x0[len0 - 1]; /* Qx */ move32(); k = add( k, 1 ); } @@ -344,11 +356,11 @@ static void ivas_peakfinder_fx( IF( GT_16( len, 2 ) || ( !endpoints && ( len > 0 ) ) ) { /* Set initial parameters for loop */ - tempMag = minMag; + tempMag = minMag; /* Q0 */ move32(); foundPeak = 0; move16(); - leftMin = minMag; + leftMin = minMag; /* Q0 */ move32(); IF( endpoints ) @@ -364,9 +376,9 @@ static void ivas_peakfinder_fx( move16(); IF( GE_32( x[1], x[2] ) ) /* x[1] is not extremum -> overwrite with x[0] */ { - x[1] = x[0]; + x[1] = x[0]; /* Qx */ move32(); - ind[1] = ind[0]; + ind[1] = ind[0]; /* Q0 */ move16(); ind++; len--; @@ -378,9 +390,9 @@ static void ivas_peakfinder_fx( move16(); IF( LT_32( x[1], x[2] ) ) /* x[1] is not extremum -> overwrite with x[0] */ { - x[1] = x[0]; + x[1] = x[0]; /* Qx */ move32(); - ind[1] = ind[0]; + ind[1] = ind[0]; /* Q0 */ move16(); ind++; len--; @@ -412,7 +424,7 @@ static void ivas_peakfinder_fx( than the last or the left min was small enough to reset.*/ IF( foundPeak ) { - tempMag = minMag; + tempMag = minMag; /* Q0 */ move32(); foundPeak = 0; move16(); @@ -429,13 +441,13 @@ static void ivas_peakfinder_fx( test(); IF( GT_32( x[ii], tempMag ) && GT_32( x[ii], L_add( leftMin, sel ) ) ) { - tempLoc = ii; + tempLoc = ii; /* Q0 */ move16(); - tempMag = x[ii]; + tempMag = x[ii]; /* Q0 */ move32(); } - ii = add( ii, 1 ); /* Move onto the valley */ + ii++; /* Move onto the valley */ /* Come down at least sel from peak */ test(); @@ -443,18 +455,18 @@ static void ivas_peakfinder_fx( { foundPeak = 1; /* We have found a peak */ move16(); - leftMin = x[ii]; + leftMin = x[ii]; /* Qx */ move32(); - peakLoc[*cInd] = tempLoc; /* Add peak to index */ + peakLoc[*cInd] = tempLoc; /* Add peak to index Q0*/ move16(); - peakMag[*cInd] = tempMag; + peakMag[*cInd] = tempMag; /* Q0 */ move32(); ( *cInd ) = add( *( cInd ), 1 ); move16(); } ELSE IF( LT_32( x[ii], leftMin ) ) /* New left minimum */ { - leftMin = x[ii]; + leftMin = x[ii]; /* Qx */ move32(); } } @@ -464,17 +476,17 @@ static void ivas_peakfinder_fx( test(); IF( GT_32( x[len - 1], tempMag ) && GT_32( x[len - 1], L_add( leftMin, sel ) ) ) { - peakLoc[*cInd] = sub( len, 1 ); + peakLoc[*cInd] = sub( len, 1 ); /* Q0 */ move16(); - peakMag[*cInd] = x[len - 1]; + peakMag[*cInd] = x[len - 1]; /* Q0 */ move32(); ( *cInd )++; } ELSE IF( !foundPeak && GT_32( tempMag, minMag ) ) /* Check if we still need to add the last point */ { - peakLoc[*cInd] = tempLoc; + peakLoc[*cInd] = tempLoc; /* Q0 */ move16(); - peakMag[*cInd] = tempMag; + peakMag[*cInd] = tempMag; /* Q0 */ move32(); ( *cInd ) = add( *( cInd ), 1 ); move16(); @@ -483,7 +495,7 @@ static void ivas_peakfinder_fx( /* Create output */ FOR( i = 0; i < *cInd; i++ ) { - plocs[i] = ind[peakLoc[i]]; + plocs[i] = ind[peakLoc[i]]; /* Q0 */ move16(); } } @@ -508,7 +520,7 @@ static void ivas_peakfinder_fx( move32(); IF( GT_32( peakMag[0], L_add( minMag, sel ) ) ) { - plocs[0] = ind[xInd]; + plocs[0] = ind[xInd]; /* Q0 */ move16(); *cInd = 1; move16(); @@ -538,17 +550,17 @@ static void ivas_peakfinder_fx( * ---------------------------------------------------------------*/ void stereo_dft_res_subst_spec_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ - Word32 *pDFT_RES, /* i/o: residual signal */ - const Word32 *const DFT_PRED_RES, /* i : residual prediction signal */ - const Word16 time_offs, /* i : Time offset for phase adjustment*/ - const Word16 L_res, /* i : bandwidth of residual signal */ - const Word16 L_ana, /* i : Length of FFT analysis */ - const Word16 k, /* i : Subframe index */ - Word16 *num_plocs, /* i/o: Number of peak locations */ - Word16 *plocs, /* i/o: Peak locations (bin) */ - Word32 *plocsi, /* i/o: Peak locations (fractional) */ - const Word16 analysis_flag /* i : Flag for running peak analysis */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ + Word32 *pDFT_RES, /* i/o: residual signal qDFT*/ + const Word32 *const DFT_PRED_RES, /* i : residual prediction signal qDFT*/ + const Word16 time_offs, /* i : Time offset for phase adjustment Q0*/ + const Word16 L_res, /* i : bandwidth of residual signal Q0*/ + const Word16 L_ana, /* i : Length of FFT analysis Q0*/ + const Word16 k, /* i : Subframe index Q0*/ + Word16 *num_plocs, /* i/o: Number of peak locations Q0*/ + Word16 *plocs, /* i/o: Peak locations (bin) Q0*/ + Word32 *plocsi, /* i/o: Peak locations (fractional) Qx*/ + const Word16 analysis_flag /* i : Flag for running peak analysis Q0*/ ) { Word16 i, idx; @@ -568,8 +580,8 @@ void stereo_dft_res_subst_spec_fx( Word16 cos_F, sin_F; /* initialization */ - Copy32( DFT_PRED_RES, pDFT_RES, 2 * L_res ); - p_mem = hStereoDft->res_mem_fx; + Copy32( DFT_PRED_RES, pDFT_RES, 2 * L_res ); /* qDFT */ + p_mem = hStereoDft->res_mem_fx; /* q_res_mem */ Np = 1; move16(); @@ -577,20 +589,20 @@ void stereo_dft_res_subst_spec_fx( { Word16 q_res = sub( getScaleFactor32( p_mem, shl( L_res, 1 ) ), 2 ); /* Perform spectral analysis on 2nd subframe of last good frame */ - abs_res[0] = L_shr( Mpy_32_32( L_shl( p_mem[0], q_res ), L_shl( p_mem[0], q_res ) ), 1 ); /* DC */ + abs_res[0] = L_shr( Mpy_32_32( L_shl( p_mem[0], q_res ), L_shl( p_mem[0], q_res ) ), 1 ); /* DC */ /* 2 * q_res - 31 */ move32(); FOR( i = 1; i < L_res; i++ ) { Word32 r = L_shl( p_mem[2 * i], q_res ); - Word32 l = L_shl( p_mem[add( shl( i, 1 ), 1 )], q_res ); - abs_res[i] = Madd_32_32( Mpy_32_32( r, r ), l, l ); + Word32 l = L_shl( p_mem[2 * i + 1], q_res ); + abs_res[i] = Madd_32_32( Mpy_32_32( r, r ), l, l ); /* 2 * q_res - 31 */ move32(); } /* Find maxima */ maximum_l( abs_res, L_res, &Xmax ); minimum_l( abs_res, L_res, &Xmin ); - sel = Mpy_32_16_1( L_sub( Xmax, Xmin ), (Word16) ( 0x03D7 ) ); + sel = Mpy_32_16_1( L_sub( Xmax, Xmin ), (Word16) ( 0x03D7 ) /* Q15 */ ); /* 2 * q_res - 31 */ ivas_peakfinder_fx( abs_res, L_res, plocs, num_plocs, sel, FALSE ); /* Refine peaks */ @@ -598,17 +610,17 @@ void stereo_dft_res_subst_spec_fx( { IF( plocs[i] == 0 ) { - plocsi[i] = L_add( L_deposit_h( plocs[i] ), L_shl( imax_pos_fx( &abs_res[plocs[i]] ), Q1 ) ); + plocsi[i] = L_add( L_deposit_h( plocs[i] ), L_shl( imax_pos_fx( &abs_res[plocs[i]] ), Q1 ) ); /* Q16 */ move32(); } ELSE IF( EQ_16( plocs[i], L_res ) ) { - plocsi[i] = L_add( L_deposit_h( sub( plocs[i], 2 ) ), L_shl( imax_pos_fx( &abs_res[plocs[i] - 2] ), Q1 ) ); + plocsi[i] = L_add( L_deposit_h( sub( plocs[i], 2 ) ), L_shl( imax_pos_fx( &abs_res[plocs[i] - 2] ), Q1 ) ); /* Q16 */ move32(); } ELSE { - plocsi[i] = L_add( L_deposit_h( sub( plocs[i], 1 ) ), L_shl( imax_pos_fx( &abs_res[plocs[i] - 1] ), Q1 ) ); + plocsi[i] = L_add( L_deposit_h( sub( plocs[i], 1 ) ), L_shl( imax_pos_fx( &abs_res[plocs[i] - 1] ), Q1 ) ); /* Q16 */ move16(); } } @@ -618,30 +630,30 @@ void stereo_dft_res_subst_spec_fx( FOR( i = 1; i < L_res; i++ ) { s1 = sign_l( pDFT_RES[2 * i] ); - s2 = sign_l( pDFT_RES[add( shl( i, 1 ), 1 )] ); - abs1 = L_abs( pDFT_RES[2 * i] ); - abs2 = L_abs( pDFT_RES[add( shl( i, 1 ), 1 )] ); - abs3 = L_abs( p_mem[2 * i] ); - abs4 = L_abs( p_mem[add( shl( i, 1 ), 1 )] ); + s2 = sign_l( pDFT_RES[2 * i + 1] ); + abs1 = L_abs( pDFT_RES[2 * i] ); /* qDFt */ + abs2 = L_abs( pDFT_RES[2 * i + 1] ); /* qDFT */ + abs3 = L_abs( p_mem[2 * i] ); /* q_res_mem */ + abs4 = L_abs( p_mem[2 * i + 1] ); /* q_res_mem*/ // fac = MAX_16; - move16(); + /* Low-complex phase matching that brings the angle within pi/4 of the target angle */ test(); test(); test(); IF( ( GT_32( abs1, abs2 ) && LT_32( abs3, abs4 ) ) || ( LE_32( abs1, abs2 ) && GE_32( abs3, abs4 ) ) ) { - pDFT_RES[2 * i] = Mpy_32_32( s1, abs4 ); + pDFT_RES[2 * i] = Mpy_32_32( s1, abs4 ); /* q_res - 31 */ move32(); - pDFT_RES[add( shl( i, 1 ), 1 )] = Mpy_32_32( s2, abs3 ); + pDFT_RES[2 * i + 1] = Mpy_32_32( s2, abs3 ); /* q_res - 31 */ move32(); } ELSE { - pDFT_RES[2 * i] = Mpy_32_32( s1, abs3 ); + pDFT_RES[2 * i] = Mpy_32_32( s1, abs3 ); /* q_res - 31 */ move32(); - pDFT_RES[add( shl( i, 1 ), 1 )] = Mpy_32_32( s2, abs4 ); + pDFT_RES[2 * i + 1] = Mpy_32_32( s2, abs4 ); /* q_res - 31 */ move32(); } } @@ -662,18 +674,18 @@ void stereo_dft_res_subst_spec_fx( op = L_negate( L_shl( phase, 1 ) ); // Q13 corr_phase = L_add( L_add( STEREO_DFT_PLC_STEP21, L_ana ), time_offs ); // Q0 q_shift = norm_l( corr_phase ); - corr_phase = Mpy_32_32( L_shl( corr_phase, q_shift ), plocsi[i] ); + corr_phase = Mpy_32_32( L_shl( corr_phase, q_shift ), plocsi[i] ); // q_shift + Q16 - 31 corr_phase = L_deposit_l( BASOP_Util_Divide3232_Scale( corr_phase, L_ana, &q_div ) ); - corr_phase = L_shl( corr_phase, sub( q_div, sub( q_shift, Q15 ) ) ); - corr_phase = L_negate( L_shl( Mpy_32_16_1( corr_phase, EVS_PI_FX ), Q1 ) ); - corr_phase = L_add( op, corr_phase ); + corr_phase = L_shl( corr_phase, sub( q_div, sub( q_shift, Q15 ) ) ); /* q_div */ + corr_phase = L_negate( L_shl( Mpy_32_16_1( corr_phase, EVS_PI_FX ), Q1 ) ); /* Q13 */ + corr_phase = L_add( op, corr_phase ); /* Q13 */ WHILE( LT_32( corr_phase, -EVS_PI_FX ) ) { - corr_phase = L_add( L_add( corr_phase, EVS_PI_FX ), EVS_PI_FX ); + corr_phase = L_add( L_add( corr_phase, EVS_PI_FX ), EVS_PI_FX ); /* Q13 */ } WHILE( GT_32( corr_phase, EVS_PI_FX ) ) { - corr_phase = L_sub( L_sub( corr_phase, EVS_PI_FX ), EVS_PI_FX ); + corr_phase = L_sub( L_sub( corr_phase, EVS_PI_FX ), EVS_PI_FX ); /* Q13 */ } conj_sign = MIN_32; move32(); @@ -681,21 +693,21 @@ void stereo_dft_res_subst_spec_fx( ELSE { /* corr_phase = PI2 * ( L_ana + time_offs ) * ( plocsi[i] / L_ana ); */ - Word32 op = L_add( L_ana, time_offs ); + Word32 op = L_add( L_ana, time_offs ); /* Q0 */ Word16 q_div; - op = Mpy_32_32( L_shl( op, Q15 ), plocsi[i] ); + op = Mpy_32_32( L_shl( op, Q15 ), plocsi[i] ); /* Q0 */ corr_phase = BASOP_Util_Divide3232_Scale( op, L_ana, &q_div ); - corr_phase = extract_l( L_and( L_shl( corr_phase, q_div ), MAX_16 ) ); + corr_phase = extract_l( L_and( L_shl( corr_phase, q_div ), MAX_16 ) ); /* Q13 */ /* For 2nd subframe, do regular phase shift */ /* Multiplying only with EVS_PI_Fx and taking care of 2 in shift */ - corr_phase = ( L_shr( L_mult0( extract_l( corr_phase ), EVS_PI_FX ), Q14 /* Q13 + Q1*/ ) ); + corr_phase = ( L_shr( L_mult0( extract_l( corr_phase ), EVS_PI_FX ), Q14 /* Q13 + Q1*/ ) ); /* Q13 */ WHILE( LT_32( corr_phase, -EVS_PI_FX ) ) { - corr_phase = L_add( L_add( corr_phase, EVS_PI_FX ), EVS_PI_FX ); + corr_phase = L_add( L_add( corr_phase, EVS_PI_FX ), EVS_PI_FX ); /* Q13 */ } WHILE( GT_32( corr_phase, EVS_PI_FX ) ) { - corr_phase = L_sub( L_sub( corr_phase, EVS_PI_FX ), EVS_PI_FX ); + corr_phase = L_sub( L_sub( corr_phase, EVS_PI_FX ), EVS_PI_FX ); /* Q13 */ } conj_sign = MAX_32; move32(); @@ -707,11 +719,11 @@ void stereo_dft_res_subst_spec_fx( idx = s_max( 0, sub( plocs[i], Np ) ); /* Iterate over plocs[i]-1:plocs[i]+1, considering the edges of the spectrum */ WHILE( ( idx < add( add( plocs[i], Np ), 1 ) ) && LT_16( idx, L_res ) ) { - pDFT_RES[2 * idx] = Msub_32_16( Mpy_32_16_1( p_mem[2 * idx], cos_F ), p_mem[add( shl( idx, 1 ), 1 )], sin_F ); + pDFT_RES[2 * idx] = Msub_32_16( Mpy_32_16_1( p_mem[2 * idx], cos_F ), p_mem[2 * idx + 1], sin_F ); /* q_res - 1 */ move32(); - pDFT_RES[add( shl( idx, 1 ), 1 )] = Mpy_32_32( conj_sign, Madd_32_16( Mpy_32_16_1( p_mem[2 * idx], sin_F ), p_mem[add( shl( idx, 1 ), 1 )], cos_F ) ); + pDFT_RES[2 * idx + 1] = Mpy_32_32( conj_sign, Madd_32_16( Mpy_32_16_1( p_mem[2 * idx], sin_F ), p_mem[2 * idx + 1], cos_F ) ); /* q_res - 1 */ move32(); - idx = add( idx, 1 ); + idx++; } } return; @@ -725,11 +737,11 @@ void stereo_dft_res_subst_spec_fx( * ---------------------------------------------------------------*/ void stereo_dft_res_ecu_burst_att_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ - Word32 *pDFT_RES, /* i/o: residual signal /att. residual */ - const Word32 dmx_nrg, /* i : dmx energy of current frame */ - const Word16 L_res, /* i : Bandwidth of residual */ - const Word16 L_ana /* i : Length of FFT analysis */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ + Word32 *pDFT_RES, /* i/o: residual signal /att. residual qDFT*/ + const Word32 dmx_nrg, /* i : dmx energy of current frame Qx*/ + const Word16 L_res, /* i : Bandwidth of residual Q0*/ + const Word16 L_ana /* i : Length of FFT analysis Q0*/ ) { Word32 fac; @@ -744,11 +756,11 @@ void stereo_dft_res_ecu_burst_att_fx( /* attenuation of residual; follow attenuation of DMX */ IF( hStereoDft->core_hist[0] == ACELP_CORE ) { - fac = Mpy_32_16_1( Sqrt32( L_deposit_h( BASOP_Util_Divide3232_Scale( dmx_nrg, hStereoDft->past_dmx_nrg_fx, &q_fac ) ), &exponent ), (Word16) ( 0x0CCD ) ); + fac = Mpy_32_16_1( Sqrt32( L_deposit_h( BASOP_Util_Divide3232_Scale( dmx_nrg, hStereoDft->past_dmx_nrg_fx, &q_fac ) ), &exponent ), (Word16) ( 0x0CCD ) ); /* Q0 */ } ELSE { - fac = L_sub( MAX_32, L_deposit_h( BASOP_Util_Divide3232_Scale( sub( hStereoDft->time_offs, L_ana ), add( hStereoDft->time_offs, L_ana ), &q_fac ) ) ); + fac = L_sub( MAX_32, L_deposit_h( BASOP_Util_Divide3232_Scale( sub( hStereoDft->time_offs, L_ana ), add( hStereoDft->time_offs, L_ana ), &q_fac ) ) ); /* Q0 */ } v_multc_fixed( pDFT_RES, fac, pDFT_RES, shl( L_res, 1 ) ); @@ -764,9 +776,9 @@ void stereo_dft_res_ecu_burst_att_fx( /*! r: total energy of downmix with maximum swb bandwidth max */ Word32 stereo_dft_dmx_swb_nrg_fx( - const Word32 *dmx_k0, /* i : first subframe spectrum */ - const Word32 *dmx_k1, /* i : second subframe spectrum */ - const int16_t frame_length, /* i : frame lanegth */ + const Word32 *dmx_k0, /* i : first subframe spectrum q0*/ + const Word32 *dmx_k1, /* i : second subframe spectrum q1*/ + const Word16 frame_length, /* i : frame lanegth Q0*/ const Word16 q0, const Word16 q1 ) { @@ -778,20 +790,20 @@ Word32 stereo_dft_dmx_swb_nrg_fx( test(); IF( q0 == 0 && q1 == 0 ) { - FOR( i = 0; i < shr( frame_length, 1 ); i++ ) + FOR( i = 0; i < frame_length / 2; i++ ) { dmx_nrg = L_add( dmx_nrg, - L_add( Madd_32_32( Mpy_32_32( dmx_k0[shl( i, 1 )], dmx_k0[shl( i, 1 )] ), dmx_k0[add( shl( i, 1 ), 1 )], dmx_k0[add( shl( i, 1 ), 1 )] ), - Madd_32_32( Mpy_32_32( dmx_k1[shl( i, 1 )], dmx_k1[shl( i, 1 )] ), dmx_k1[add( shl( i, 1 ), 1 )], dmx_k1[add( shl( i, 1 ), 1 )] ) ) ); + L_add( Madd_32_32( Mpy_32_32( dmx_k0[2 * i], dmx_k0[2 * i] ), dmx_k0[2 * i + 1], dmx_k0[2 * i + 1] ), + Madd_32_32( Mpy_32_32( dmx_k1[2 * i], dmx_k1[2 * i] ), dmx_k1[2 * i + 1], dmx_k1[2 * i + 1] ) ) ); /* Q0 */ } } ELSE { - FOR( i = 0; i < shr( frame_length, 1 ); i++ ) + FOR( i = 0; i < frame_length / 2; i++ ) { dmx_nrg = L_add( dmx_nrg, - L_add( L_shl( Madd_32_32( Mpy_32_32( dmx_k0[shl( i, 1 )], dmx_k0[shl( i, 1 )] ), dmx_k0[add( shl( i, 1 ), 1 )], dmx_k0[add( shl( i, 1 ), 1 )] ), q0 ), - L_shl( Madd_32_32( Mpy_32_32( dmx_k1[shl( i, 1 )], dmx_k1[shl( i, 1 )] ), dmx_k1[add( shl( i, 1 ), 1 )], dmx_k1[add( shl( i, 1 ), 1 )] ), q1 ) ) ); + L_add( L_shl( Madd_32_32( Mpy_32_32( dmx_k0[2 * i], dmx_k0[2 * i] ), dmx_k0[2 * i + 1], dmx_k0[2 * i + 1] ), q0 ), + L_shl( Madd_32_32( Mpy_32_32( dmx_k1[2 * i], dmx_k1[2 * i] ), dmx_k1[2 * i + 1], dmx_k1[2 * i + 1] ), q1 ) ) ); /*3*q0 - 31*/ } } @@ -813,32 +825,36 @@ Word16 stereo_dft_sg_recovery_fx( Word32 *pSideGain; Word32 sg_m; Word16 beta; + Word16 exp_sg_m; test(); IF( !hStereoDft->sg_mem_corrupt ) { pSideGain = hStereoDft->side_gain_fx + 2 * STEREO_DFT_BAND_MAX; - beta = (Word16) ( 0x3666 ); + beta = (Word16) ( 0x3666 ); /* Q15 */ move16(); sg_m = EPSILON_FIX; move32(); FOR( b = 0; b < hStereoDft->nbands; b++ ) { - sg_m = L_add_sat( sg_m, L_shr( pSideGain[b], 5 ) ); + sg_m = L_add_sat( sg_m, L_shr( pSideGain[b], 5 ) ); /* Q26 */ } - sg_m /= hStereoDft->nbands; - sg_m = L_shl_sat( sg_m, 5 ); + sg_m = L_deposit_l( BASOP_Util_Divide3216_Scale( sg_m, hStereoDft->nbands, &exp_sg_m ) ); + exp_sg_m = add( exp_sg_m, -10 ); // exp_sg_m - (31 - Q26) - (15 - Q0) + + sg_m = L_shl_sat( sg_m, sub( 31, sub( 15, exp_sg_m ) ) ); /* Q31 */ + test(); IF( LT_32( sg_m, (Word32) 0x4CCCCCCD ) && GT_32( sg_m, (Word32) ( 0xB3333333 ) ) ) { - hStereoDft->sg_mean_fx = 0; + hStereoDft->sg_mean_fx = 0; /* Q13 */ move32(); } ELSE { - hStereoDft->sg_mean_fx = Madd_32_16( Mpy_32_16_1( sg_m, beta ), hStereoDft->sg_mean_fx, sub( MAX_16, beta ) ); /* LP filter delta_sg to obtain side gain stability measure */ + hStereoDft->sg_mean_fx = Madd_32_16( Mpy_32_16_1( sg_m, beta ), hStereoDft->sg_mean_fx, sub( MAX_16, beta ) ); /* LP filter delta_sg to obtain side gain stability measure */ /* Q31 */ move32(); } } diff --git a/lib_dec/ivas_stereo_eclvq_dec.c b/lib_dec/ivas_stereo_eclvq_dec.c index 82ca7123fa81465aa630ffc364634e248f2472eb..cd26f5539c7da80134903e8418a3f3d63cb354a6 100644 --- a/lib_dec/ivas_stereo_eclvq_dec.c +++ b/lib_dec/ivas_stereo_eclvq_dec.c @@ -91,16 +91,16 @@ static Word16 arith_decode_elias_mod( n_bits = 0; move16(); - bit = rc_uni_dec_read_bit( rc_st_dec ); + bit = rc_uni_dec_read_bit( rc_st_dec ); /* Q0 */ WHILE( bit == 0 ) { - bit = rc_uni_dec_read_bit( rc_st_dec ); - n_bits = add( n_bits, 1 ); + bit = rc_uni_dec_read_bit( rc_st_dec ); /* Q0 */ + n_bits = add( n_bits, 1 ); /* Q0 */ IF( EQ_16( n_bits, 17 ) ) { /* bitstream error encountered */ - rc_st_dec->bit_error_detected = 1; + rc_st_dec->bit_error_detected = 1; /* Q0 */ move16(); return 0; } @@ -149,18 +149,19 @@ static int16_t arith_decode_prob_escape( #else static Word16 arith_decode_prob_escape( RangeUniDecState *rc_st_dec, - const UWord16 cum_freq_table[], /* i : Cumulative frequency up to symbol */ - const UWord16 sym_freq_table[], /* i : Symbol frequency */ - const Word16 table_size ) + const UWord16 cum_freq_table[], /* i : Cumulative frequency up to symbol Q0*/ + const UWord16 sym_freq_table[], /* i : Symbol frequency Q0*/ + const Word16 table_size /* Q0 */ +) { Word16 symbol; - symbol = rc_uni_dec_read_symbol_fastS_fx( rc_st_dec, cum_freq_table, sym_freq_table, table_size, ECSQ_PROB_BITS ); + symbol = rc_uni_dec_read_symbol_fastS_fx( rc_st_dec, cum_freq_table, sym_freq_table, table_size, ECSQ_PROB_BITS ); /* Q0 */ IF( EQ_16( symbol, sub( table_size, 1 ) ) ) /* escape symbol */ { /* decode the additional value using a modified Elias integer code */ - symbol = add( symbol, arith_decode_elias_mod( rc_st_dec ) ); + symbol = add( symbol, arith_decode_elias_mod( rc_st_dec ) ); /* Q0 */ } return symbol; @@ -281,8 +282,9 @@ void ECSQ_decode( #else void ECSQ_decode( ECSQ_instance *ecsq_inst, - const Word16 N, - Word16 *output ) + const Word16 N, /* Q0 */ + Word16 *output /* Q0 */ +) { Word16 i, idx, segment, segment_count, seg_start, seg_stop; const UWord16 *tab_vals_cum_freq; @@ -296,40 +298,40 @@ void ECSQ_decode( rc_st_dec = (RangeUniDecState *) ecsq_inst->ac_handle; - segment_count = shr( sub( add( N, ECSQ_SEGMENT_SIZE ), 1 ), 3 ); + segment_count = shr( sub( add( N, ECSQ_SEGMENT_SIZE ), 1 ), 3 ); /* Q0 */ FOR( segment = 0; segment < segment_count; ++segment ) { - seg_start = shl( segment, 3 ); - seg_stop = sub( s_min( add( seg_start, ECSQ_SEGMENT_SIZE ), N ), 1 ); + seg_start = shl( segment, 3 ); /* Q0 */ + seg_stop = sub( s_min( add( seg_start, ECSQ_SEGMENT_SIZE ), N ), 1 ); /* Q0 */ - param_zb = rc_uni_dec_read_symbol_fastS_fx( rc_st_dec, cum_freq_ECSQ_tab_param[ecsq_inst->config_index], sym_freq_ECSQ_tab_param[ecsq_inst->config_index], ECSQ_PARAM_COUNT, ECSQ_PROB_BITS ); - shift = s_max( 0, sub( param_zb, 3 ) ); /* first nonzero shift of 1 is used for param 3 */ + param_zb = rc_uni_dec_read_symbol_fastS_fx( rc_st_dec, cum_freq_ECSQ_tab_param[ecsq_inst->config_index], sym_freq_ECSQ_tab_param[ecsq_inst->config_index], ECSQ_PARAM_COUNT, ECSQ_PROB_BITS ); /* Q0 */ + shift = s_max( 0, sub( param_zb, 3 ) ); /* first nonzero shift of 1 is used for param 3 */ /* Q0 */ IF( param_zb != 0 ) /* not the ECSQ_ALL_ZERO_PARAM param */ { - tab_vals_cum_freq = cum_freq_ECSQ_tab_vals[sub( param_zb, 1 )]; - tab_vals_sym_freq = sym_freq_ECSQ_tab_vals[sub( param_zb, 1 )]; - idx = s_min( shift, 4 ); - tab_abs_lsbs_cum_freq = cum_freq_ECSQ_tab_abs_lsbs[idx]; - tab_abs_lsbs_sym_freq = sym_freq_ECSQ_tab_abs_lsbs[idx]; + tab_vals_cum_freq = cum_freq_ECSQ_tab_vals[param_zb - 1]; /* Q0 */ + tab_vals_sym_freq = sym_freq_ECSQ_tab_vals[param_zb - 1]; /* Q0 */ + idx = s_min( shift, 4 ); /* Q0 */ + tab_abs_lsbs_cum_freq = cum_freq_ECSQ_tab_abs_lsbs[idx]; /* Q0 */ + tab_abs_lsbs_sym_freq = sym_freq_ECSQ_tab_abs_lsbs[idx]; /* Q0 */ FOR( i = seg_start; i <= seg_stop; ++i ) { - sym = arith_decode_prob_escape( rc_st_dec, tab_vals_cum_freq, tab_vals_sym_freq, ECSQ_TAB_VALS_SIZE ); + sym = arith_decode_prob_escape( rc_st_dec, tab_vals_cum_freq, tab_vals_sym_freq, ECSQ_TAB_VALS_SIZE ); /* Q0 */ IF( shift != 0 ) { test(); IF( ( sym > 0 ) || ( GT_16( shift, 4 ) ) ) { - lsbs = rc_uni_dec_read_bits( rc_st_dec, shift ); + lsbs = rc_uni_dec_read_bits( rc_st_dec, shift ); /* Q0 */ } ELSE /* (sym == 0) && (shift <= 4) */ { - lsbs = rc_uni_dec_read_symbol_fastS_fx( rc_st_dec, tab_abs_lsbs_cum_freq, tab_abs_lsbs_sym_freq, shl( 1, shift ), ECSQ_PROB_BITS ); + lsbs = rc_uni_dec_read_symbol_fastS_fx( rc_st_dec, tab_abs_lsbs_cum_freq, tab_abs_lsbs_sym_freq, shl( 1, shift ), ECSQ_PROB_BITS ); /* Q0 */ } - sym = s_or( shl( sym, shift ), lsbs ); + sym = s_or( shl( sym, shift ), lsbs ); /* Q0 */ } IF( sym != 0 ) @@ -337,39 +339,39 @@ void ECSQ_decode( /* map the sign bit to +1 or -1 and then multiply */ IF( rc_uni_dec_read_bit( rc_st_dec ) ) { - sym = negate( sym ); + sym = negate( sym ); /* Q0 */ } } - output[i] = sym; + output[i] = sym; /* Q0 */ move16(); } } ELSE { - nonzero = rc_uni_dec_read_bits( rc_st_dec, 2 ); + nonzero = rc_uni_dec_read_bits( rc_st_dec, 2 ); /* Q0 */ - left1 = nonzero; + left1 = nonzero; /* Q0 */ move16(); - left0 = sub( add( sub( seg_stop, seg_start ), 1 ), nonzero ); + left0 = sub( add( sub( seg_stop, seg_start ), 1 ), nonzero ); /* Q0 */ FOR( i = seg_start; i <= seg_stop; ++i ) { IF( left1 == 0 ) { - sym = 0; + sym = 0; /* Q0 */ move16(); } ELSE IF( left0 == 0 ) { - sym = 1; + sym = 1; /* Q0 */ move16(); } ELSE { - count0 = left0 * ECSQ_tab_inverse[left0 + left1]; /* left0 * round(ECSQ_PROB_TOTAL / (left0 + left1)) */ - sym = rc_uni_dec_read_bit_prob_fast( rc_st_dec, count0, ECSQ_PROB_BITS ); + count0 = left0 * ECSQ_tab_inverse[left0 + left1]; /* left0 * round(ECSQ_PROB_TOTAL / (left0 + left1)) Q0*/ + sym = rc_uni_dec_read_bit_prob_fast( rc_st_dec, count0, ECSQ_PROB_BITS ); /* Q0 */ } IF( sym != 0 ) @@ -377,13 +379,13 @@ void ECSQ_decode( /* map the sign bit to +1 or -1 and then multiply */ IF( rc_uni_dec_read_bit( rc_st_dec ) ) { - sym = negate( sym ); + sym = negate( sym ); /* Q0 */ } - left1 = sub( left1, 1 ); + left1 = sub( left1, 1 ); /* Q0 */ } ELSE { - left0 = sub( left0, 1 ); + left0 = sub( left0, 1 ); /* Q0 */ } output[i] = sym; diff --git a/lib_dec/ivas_stereo_esf_dec.c b/lib_dec/ivas_stereo_esf_dec.c index 6233f9e253aeb1865659b259b8303630f638c828..1ad65585966d68e1d92e206e358985ee18cb9e49 100644 --- a/lib_dec/ivas_stereo_esf_dec.c +++ b/lib_dec/ivas_stereo_esf_dec.c @@ -70,21 +70,22 @@ void init_basic_allpass( #else void init_basic_allpass_fx( basic_allpass_t *ap, - const Word32 *gains_fx, - const Word16 *delays ) + const Word32 *gains_fx, /* Q31 */ + const Word16 *delays /* Q15 */ +) { Word16 i, j; FOR( i = 0; i < 3; i++ ) { - ap->delays[i] = delays[i]; + ap->delays[i] = delays[i]; /* Q0 */ move16(); - ap->gains_fx[i] = gains_fx[i]; + ap->gains_fx[i] = gains_fx[i]; /* Q31 */ move32(); FOR( j = 0; j < STEREO_DFT_ALLPASS_BUFFERLEN; j++ ) { - ap->buffer_fx[i][j] = 0; + ap->buffer_fx[i][j] = 0; /* q_buffer_fx */ move32(); } ap->q_buffer_fx = 0; @@ -158,9 +159,9 @@ void filter_with_allpass( } #else void filter_with_allpass_fx( - const Word32 *sig, - Word32 *out, - const Word16 len, + const Word32 *sig, /* q_shift */ + Word32 *out, /* q_shift */ + const Word16 len, /* Q0 */ basic_allpass_t *ap, Word16 q_shift ) { @@ -182,36 +183,36 @@ void filter_with_allpass_fx( pos = ap->pos; move16(); - g1_fx = ap->gains_fx[0]; + g1_fx = ap->gains_fx[0]; /* Q31 */ move32(); - g2_fx = ap->gains_fx[1]; + g2_fx = ap->gains_fx[1]; /* Q31 */ move32(); - g3_fx = ap->gains_fx[2]; + g3_fx = ap->gains_fx[2]; /* Q31 */ move32(); - d1 = ap->delays[0]; + d1 = ap->delays[0]; /* Q0 */ move16(); - d2 = ap->delays[1]; + d2 = ap->delays[1]; /* Q0 */ move16(); - d3 = ap->delays[2]; + d3 = ap->delays[2]; /* Q0 */ move16(); - D1_fx = ap->buffer_fx[0]; + D1_fx = ap->buffer_fx[0]; /* q_buffer_fx */ move32(); - D2_fx = ap->buffer_fx[1]; + D2_fx = ap->buffer_fx[1]; /* q_buffer_fx */ move32(); - D3_fx = ap->buffer_fx[2]; + D3_fx = ap->buffer_fx[2]; /* q_buffer_fx */ move32(); IF( NE_16( q_shift, ap->q_buffer_fx ) ) { FOR( k = 0; k < (Word16) ( sizeof( ap->buffer_fx[0] ) / sizeof( ap->buffer_fx[0][0] ) ); k++ ) { - D1_fx[k] = L_shr( D1_fx[k], sub( ap->q_buffer_fx, q_shift ) ); + D1_fx[k] = L_shr( D1_fx[k], sub( ap->q_buffer_fx, q_shift ) ); /* q_shift */ move32(); - D2_fx[k] = L_shr( D2_fx[k], sub( ap->q_buffer_fx, q_shift ) ); + D2_fx[k] = L_shr( D2_fx[k], sub( ap->q_buffer_fx, q_shift ) ); /* q_shift */ move32(); - D3_fx[k] = L_shr( D3_fx[k], sub( ap->q_buffer_fx, q_shift ) ); + D3_fx[k] = L_shr( D3_fx[k], sub( ap->q_buffer_fx, q_shift ) ); /* q_shift */ move32(); } ap->q_buffer_fx = q_shift; @@ -238,19 +239,19 @@ void filter_with_allpass_fx( move32(); } - P1_fx = L_sub_sat( sig[k], Mpy_32_32( g3_fx, D3_fx[pos] ) ); - P2_fx = L_sub_sat( P1_fx, Mpy_32_32( g1_fx, D1_fx[pos] ) ); - P3_fx = L_add_sat( D1_fx[pos], L_sub( Mpy_32_32( g1_fx, P2_fx ), Mpy_32_32( g2_fx, D2_fx[pos] ) ) ); - P4_fx = L_add_sat( D2_fx[pos], Mpy_32_32( g2_fx, P3_fx ) ); - P5_fx = L_add_sat( D3_fx[pos], Mpy_32_32( g3_fx, P1_fx ) ); - out[k] = P5_fx; /* could overwrite sig */ + P1_fx = L_sub_sat( sig[k], Mpy_32_32( g3_fx, D3_fx[pos] ) ); /* q_shift */ + P2_fx = L_sub_sat( P1_fx, Mpy_32_32( g1_fx, D1_fx[pos] ) ); /* q_shift */ + P3_fx = L_add_sat( D1_fx[pos], L_sub( Mpy_32_32( g1_fx, P2_fx ), Mpy_32_32( g2_fx, D2_fx[pos] ) ) ); /* q_shift */ + P4_fx = L_add_sat( D2_fx[pos], Mpy_32_32( g2_fx, P3_fx ) ); /* q_shift */ + P5_fx = L_add_sat( D3_fx[pos], Mpy_32_32( g3_fx, P1_fx ) ); /* q_shift */ + out[k] = P5_fx; /* could overwrite sig */ move32(); - D1_fx[( pos + d1 ) & mask] = P2_fx; + D1_fx[( pos + d1 ) & mask] = P2_fx; /* q_shift */ move32(); - D2_fx[( pos + d2 ) & mask] = P3_fx; + D2_fx[( pos + d2 ) & mask] = P3_fx; /* q_shift */ move32(); - D3_fx[( pos + d3 ) & mask] = P4_fx; + D3_fx[( pos + d3 ) & mask] = P4_fx; /* q_shift */ move32(); pos = s_and( add( pos, 1 ), mask ); @@ -259,19 +260,19 @@ void filter_with_allpass_fx( FOR( k = mask + 1; k < len; k++ ) { - P1_fx = L_sub( sig[k], Mpy_32_32( g3_fx, D3_fx[pos] ) ); - P2_fx = L_sub( P1_fx, Mpy_32_32( g1_fx, D1_fx[pos] ) ); - P3_fx = L_add( D1_fx[pos], L_sub( Mpy_32_32( g1_fx, P2_fx ), Mpy_32_32( g2_fx, D2_fx[pos] ) ) ); - P4_fx = L_add( D2_fx[pos], Mpy_32_32( g2_fx, P3_fx ) ); - P5_fx = L_add( D3_fx[pos], Mpy_32_32( g3_fx, P1_fx ) ); - out[k] = P5_fx; /* could overwrite sig */ + P1_fx = L_sub( sig[k], Mpy_32_32( g3_fx, D3_fx[pos] ) ); /* q_shift */ + P2_fx = L_sub( P1_fx, Mpy_32_32( g1_fx, D1_fx[pos] ) ); /* q_shift */ + P3_fx = L_add( D1_fx[pos], L_sub( Mpy_32_32( g1_fx, P2_fx ), Mpy_32_32( g2_fx, D2_fx[pos] ) ) ); /* q_shift */ + P4_fx = L_add( D2_fx[pos], Mpy_32_32( g2_fx, P3_fx ) ); /* q_shift */ + P5_fx = L_add( D3_fx[pos], Mpy_32_32( g3_fx, P1_fx ) ); /* q_shift */ + out[k] = P5_fx; /* could overwrite sig */ move32(); - D1_fx[( pos + d1 ) & mask] = P2_fx; + D1_fx[( pos + d1 ) & mask] = P2_fx; /* q_shift */ move32(); - D2_fx[( pos + d2 ) & mask] = P3_fx; + D2_fx[( pos + d2 ) & mask] = P3_fx; /* q_shift */ move32(); - D3_fx[( pos + d3 ) & mask] = P4_fx; + D3_fx[( pos + d3 ) & mask] = P4_fx; /* q_shift */ move32(); pos = s_and( add( pos, 1 ), mask ); diff --git a/lib_dec/ivas_stereo_ica_dec.c b/lib_dec/ivas_stereo_ica_dec.c index 892df2868417a94640c82961b4376f2ca95dc586..94e17583e295e84f57630158af55dd05697f3387 100644 --- a/lib_dec/ivas_stereo_ica_dec.c +++ b/lib_dec/ivas_stereo_ica_dec.c @@ -56,9 +56,9 @@ #ifdef IVAS_FLOAT_FIXED void stereo_tca_dec_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *synth_fx[CPE_CHANNELS], /* i/o: output synth */ - const Word16 output_frame /* i : length of a frame per channel */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *synth_fx[CPE_CHANNELS], /* i/o: output synth qsynth*/ + const Word16 output_frame /* i : length of a frame per channel Q0*/ ) { /* Buffers, input Left and right channels @ input_Fs*/ @@ -77,10 +77,11 @@ void stereo_tca_dec_fx( Word16 bothChannelShift; Word32 output_Fs; STEREO_TCA_DEC_HANDLE hStereoTCA; + Word16 exp_ds; hStereoTCA = hCPE->hStereoTCA; - output_Fs = hCPE->hCoreCoder[0]->output_Fs; + output_Fs = hCPE->hCoreCoder[0]->output_Fs; /* Q0 */ move32(); test(); @@ -90,12 +91,12 @@ void stereo_tca_dec_fx( { IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - hCPE->hStereoDftDmx->targetGain_fx = ONE_IN_Q29; + hCPE->hStereoDftDmx->targetGain_fx = ONE_IN_Q29; /* Q29 */ move32(); } /* save the target gain for next frame */ - hCPE->hStereoDftDmx->prevTargetGain_fx = hCPE->hStereoDftDmx->targetGain_fx; + hCPE->hStereoDftDmx->prevTargetGain_fx = hCPE->hStereoDftDmx->targetGain_fx; /* Q29 */ move32(); } @@ -107,25 +108,27 @@ void stereo_tca_dec_fx( } /* populate L/R memories into current buffers */ - Copy32( hStereoTCA->memChanL_fx, bufChanL_fx, L_DEC_MEM_LEN_ICA ); - Copy32( hStereoTCA->memChanR_fx, bufChanR_fx, L_DEC_MEM_LEN_ICA ); + Copy32( hStereoTCA->memChanL_fx, bufChanL_fx, L_DEC_MEM_LEN_ICA ); /* memChan_q */ + Copy32( hStereoTCA->memChanR_fx, bufChanR_fx, L_DEC_MEM_LEN_ICA ); /* memChan_q */ /* pointers to the current frame */ - ptrChanL_fx = bufChanL_fx + L_DEC_MEM_LEN_ICA; - ptrChanR_fx = bufChanR_fx + L_DEC_MEM_LEN_ICA; + ptrChanL_fx = bufChanL_fx + L_DEC_MEM_LEN_ICA; /* memChan_q */ + ptrChanR_fx = bufChanR_fx + L_DEC_MEM_LEN_ICA; /* memChan_q */ /* copy interleaved stereo data to two channels, e.g., L, R */ - Copy32( synth_fx[0], ptrChanL_fx, output_frame ); - Copy32( synth_fx[1], ptrChanR_fx, output_frame ); + Copy32( synth_fx[0], ptrChanL_fx, output_frame ); /* qsynth */ + Copy32( synth_fx[1], ptrChanR_fx, output_frame ); /* qsynth */ /* back up the L/R target synth for next frame */ - Copy32( bufChanL_fx + output_frame, hStereoTCA->memChanL_fx, L_DEC_MEM_LEN_ICA ); - Copy32( bufChanR_fx + output_frame, hStereoTCA->memChanR_fx, L_DEC_MEM_LEN_ICA ); + Copy32( bufChanL_fx + output_frame, hStereoTCA->memChanL_fx, L_DEC_MEM_LEN_ICA ); /* memChan_q */ + Copy32( bufChanR_fx + output_frame, hStereoTCA->memChanR_fx, L_DEC_MEM_LEN_ICA ); /* memChan_q */ /* TCA parameter de-quantize */ - dsFactor = extract_l( output_Fs / 8000 ); - tempMax = NS2SA( output_Fs, L_NCSHIFT_NS ); - hStereoTCA->corrLagStats = s_min( hStereoTCA->indx_ica_NCShift * dsFactor, tempMax ); + dsFactor = BASOP_Util_Divide3232_Scale( output_Fs, 8000, &exp_ds ); + dsFactor = shr( dsFactor, sub( 15, exp_ds ) ); /* Q0 */ + + tempMax = NS2SA( output_Fs, L_NCSHIFT_NS ); /* Q0 */ + hStereoTCA->corrLagStats = s_min( hStereoTCA->indx_ica_NCShift * dsFactor, tempMax ); /* Q0 */ bothChannelShift = 0; move16(); @@ -134,22 +137,22 @@ void stereo_tca_dec_fx( { hStereoTCA->corrLagStats = 0; move16(); - hStereoTCA->refChanIndx = L_CH_INDX; + hStereoTCA->refChanIndx = L_CH_INDX; /* Q0 */ move16(); - hStereoTCA->targetGain_fx = ONE_IN_Q29; + hStereoTCA->targetGain_fx = ONE_IN_Q29; /* Q29 */ move16(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - hStereoTCA->corrLagStats = extract_l( L_shr( L_abs( hCPE->hStereoDft->itd_fx[1] ), Q15 ) ); + hStereoTCA->corrLagStats = extract_l( L_shr( L_abs( hCPE->hStereoDft->itd_fx[1] ), Q15 ) ); /* Q0 */ IF( hCPE->hStereoDft->itd_fx[1] >= 0 ) { - hStereoTCA->refChanIndx = ( L_CH_INDX ); + hStereoTCA->refChanIndx = ( L_CH_INDX ); /* Q0 */ } ELSE { - hStereoTCA->refChanIndx = ( R_CH_INDX ); + hStereoTCA->refChanIndx = ( R_CH_INDX ); /* Q0 */ } move16(); move16(); @@ -160,15 +163,15 @@ void stereo_tca_dec_fx( itd = hCPE->hStereoMdct->itd_fx; move32(); - hStereoTCA->corrLagStats = extract_l( L_shr( L_abs( itd ), Q15 ) ); + hStereoTCA->corrLagStats = extract_l( L_shr( L_abs( itd ), Q15 ) ); /* Q0 */ IF( GE_32( itd, 0 ) ) { - hStereoTCA->refChanIndx = ( L_CH_INDX ); + hStereoTCA->refChanIndx = ( L_CH_INDX ); /* Q0 */ } ELSE { - hStereoTCA->refChanIndx = ( R_CH_INDX ); + hStereoTCA->refChanIndx = ( R_CH_INDX ); /* Q0 */ } move16(); } @@ -181,8 +184,8 @@ void stereo_tca_dec_fx( } } - prevNCShift = abs_s( hStereoTCA->prevCorrLagStats ); - currentNCShift = abs_s( hStereoTCA->corrLagStats ); + prevNCShift = abs_s( hStereoTCA->prevCorrLagStats ); /* Q0 */ + currentNCShift = abs_s( hStereoTCA->corrLagStats ); /* Q0 */ test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) ) @@ -201,24 +204,24 @@ void stereo_tca_dec_fx( IF( currentNCShift != 0 ) { - currentNCShift = add( mult( 19660 /* 0.6 in Q15 */, prevNCShift ), mult( 13106 /* 0.4 in Q15 */, currentNCShift ) ); + currentNCShift = add( mult( 19660 /* 0.6 in Q15 */, prevNCShift ), mult( 13106 /* 0.4 in Q15 */, currentNCShift ) ); /* Q0 */ } - prevNCShift = hStereoTCA->interp_dec_prevNCShift; + prevNCShift = hStereoTCA->interp_dec_prevNCShift; /* Q0 */ move16(); - hStereoTCA->interp_dec_prevNCShift = currentNCShift; + hStereoTCA->interp_dec_prevNCShift = currentNCShift; /* Q0 */ move16(); } ELSE { - hStereoTCA->interp_dec_prevNCShift = currentNCShift; + hStereoTCA->interp_dec_prevNCShift = currentNCShift; /* Q0 */ move16(); hStereoTCA->interp_dec_switch_to_zero_diff = 0; move16(); } - ref_fx = ptrChanL_fx; - target_fx = ptrChanR_fx; + ref_fx = ptrChanL_fx; /* qsynth */ + target_fx = ptrChanR_fx; /* qsynth */ target_idx = R_CH_INDX; move16(); /* identify target signal to adjust for shift variations */ @@ -226,22 +229,22 @@ void stereo_tca_dec_fx( test(); IF( ( ( prevNCShift == 0 ) && EQ_16( hStereoTCA->refChanIndx, R_CH_INDX ) ) || EQ_16( hStereoTCA->prevRefChanIndx, R_CH_INDX ) ) { - ref_fx = ptrChanR_fx; - target_fx = ptrChanL_fx; + ref_fx = ptrChanR_fx; /* qsynth */ + target_fx = ptrChanL_fx; /* qsynth */ target_idx = L_CH_INDX; move16(); } IF( EQ_16( bothChannelShift, 1 ) ) { - ref_fx = ptrChanL_fx; - target_fx = ptrChanR_fx; + ref_fx = ptrChanL_fx; /* qsynth */ + target_fx = ptrChanR_fx; /* qsynth */ target_idx = R_CH_INDX; move16(); IF( EQ_16( hStereoTCA->refChanIndx, R_CH_INDX ) ) { - ref_fx = ptrChanR_fx; - target_fx = ptrChanL_fx; + ref_fx = ptrChanR_fx; /* qsynth */ + target_fx = ptrChanL_fx; /* qsynth */ target_idx = L_CH_INDX; move16(); } @@ -257,14 +260,14 @@ void stereo_tca_dec_fx( move16(); IF( GT_32( output_Fs, 16000 ) ) { - l_shift_adapt = L_SHIFT_ADAPT_MAX; + l_shift_adapt = L_SHIFT_ADAPT_MAX; /* Q0 */ move16(); } test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { - l_shift_adapt = shr( l_shift_adapt, 1 ); + l_shift_adapt = shr( l_shift_adapt, 1 ); /* Q0 */ } test(); @@ -287,9 +290,9 @@ void stereo_tca_dec_fx( } /* temporal channel adjustment */ - Copy32( target_fx - currentNCShift, synth_fx[target_idx], output_frame ); + Copy32( target_fx - currentNCShift, synth_fx[target_idx], output_frame ); /* qsynth */ - Copy32( ref_fx, synth_fx[!target_idx], output_frame ); + Copy32( ref_fx, synth_fx[!target_idx], output_frame ); /* qsynth */ /* Scale the Right channel with the gain */ stereo_tca_scale_R_channel_fx( hCPE, synth_fx[1], output_frame ); @@ -299,15 +302,15 @@ void stereo_tca_dec_fx( *-----------------------------------------------------------------*/ /* save the reference channel index for next frame */ - hStereoTCA->prevRefChanIndx = hStereoTCA->refChanIndx; + hStereoTCA->prevRefChanIndx = hStereoTCA->refChanIndx; /* Q0 */ move16(); /* save the corr lag stats for next frame */ - hStereoTCA->prevCorrLagStats = hStereoTCA->corrLagStats; + hStereoTCA->prevCorrLagStats = hStereoTCA->corrLagStats; /* Q0 */ move16(); /* save the target gain for next frame */ - hStereoTCA->prevTargetGain_fx = hStereoTCA->targetGain_fx; + hStereoTCA->prevTargetGain_fx = hStereoTCA->targetGain_fx; /* qsynth */ move32(); return; } @@ -591,9 +594,9 @@ void stereo_tca_scale_R_channel( #else #define MAX_TARGET_GAIN_Q29 1904890240 void stereo_tca_scale_R_channel_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx, /* i/o: output synthesis, R channel */ - const Word16 output_frame /* i : frame length */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx, /* i/o: output synthesis, R channel q_out*/ + const Word16 output_frame /* i : frame length Q0*/ ) { STEREO_TCA_DEC_HANDLE hStereoTCA; @@ -604,7 +607,7 @@ void stereo_tca_scale_R_channel_fx( move16(); hStereoTCA = hCPE->hStereoTCA; - output_Fs = hCPE->hCoreCoder[0]->output_Fs; + output_Fs = hCPE->hCoreCoder[0]->output_Fs; /* Q0 */ move32(); test(); @@ -613,14 +616,14 @@ void stereo_tca_scale_R_channel_fx( return; } /* Scale the Right channel with the gain */ - l_ica_ovl = NS2SA( output_Fs, STEREO_L_TCA_OVLP_NS ); + l_ica_ovl = NS2SA( output_Fs, STEREO_L_TCA_OVLP_NS ); /* Q0 */ move16(); test(); IF( EQ_16( hCPE->nchan_out, 1 ) ) { /* in mono DMX, the scaling is done before synchro_synthesis() */ - flat_old = NS2SA( output_Fs, ACELP_LOOK_NS + IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); + flat_old = NS2SA( output_Fs, ACELP_LOOK_NS + IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); /* Q0 */ move16(); test(); @@ -630,23 +633,23 @@ void stereo_tca_scale_R_channel_fx( // to be deleted next MR // hCPE->hStereoDftDmx->prevTargetGain *= 2.0f; // hCPE->hStereoDftDmx->prevTargetGain = min( hCPE->hStereoDftDmx->prevTargetGain, powf( 10, ( ( 1 << STEREO_BITS_TCA_GD ) - 1 ) * STEREO_TCA_GDSTEP + STEREO_TCA_GDMIN ) ); - local_value = W_shl( hCPE->hStereoDftDmx->prevTargetGain_fx, 1 ); - hCPE->hStereoDftDmx->prevTargetGain_fx = (Word32) min( local_value, MAX_TARGET_GAIN_Q29 ); - hCPE->hStereoDftDmx->targetGain_fx = ONE_IN_Q29; + local_value = W_shl( hCPE->hStereoDftDmx->prevTargetGain_fx, 1 ); /* Q29 */ + hCPE->hStereoDftDmx->prevTargetGain_fx = (Word32) min( local_value, MAX_TARGET_GAIN_Q29 ); /* Q29 */ + hCPE->hStereoDftDmx->targetGain_fx = ONE_IN_Q29; /* Q29 */ move32(); - flat_old = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); + flat_old = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); /* Q0 */ move16(); } } ELSE IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - flat_old = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); + flat_old = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); /* Q0 */ move16(); } ELSE { - flat_old = NS2SA( output_Fs, ACELP_LOOK_NS + IVAS_DEC_DELAY_NS ); + flat_old = NS2SA( output_Fs, ACELP_LOOK_NS + IVAS_DEC_DELAY_NS ); /* Q0 */ move16(); } @@ -654,30 +657,30 @@ void stereo_tca_scale_R_channel_fx( { IF( EQ_32( hCPE->hStereoDftDmx->targetGain_fx, ONE_IN_Q29 ) ) { - tempF1_fx = ONE_IN_Q27; + tempF1_fx = ONE_IN_Q27; /* Q27 */ move32(); } ELSE { - Word16 temp_a = (Word16) L_shr( hCPE->hStereoDftDmx->targetGain_fx, (Word16) 16 ); + Word16 temp_a = (Word16) L_shr( hCPE->hStereoDftDmx->targetGain_fx, (Word16) 16 ); /* Q13 */ Word16 temp_a_q = 2; move16(); - tempF1_fx = Inv16( temp_a, &temp_a_q ); - tempF1_fx = L_shl( tempF1_fx, sub( ( 31 - 4 ), sub( 15, temp_a_q ) ) ); + tempF1_fx = Inv16( temp_a, &temp_a_q ); /* Q13 */ + tempF1_fx = L_shl( tempF1_fx, sub( ( 31 - 4 ), sub( 15, temp_a_q ) ) ); /* Q27 */ } IF( EQ_32( hCPE->hStereoDftDmx->prevTargetGain_fx, ONE_IN_Q29 ) ) { - tempF_fx = ONE_IN_Q27; + tempF_fx = ONE_IN_Q27; /* Q27 */ move32(); } ELSE { - Word16 temp_b = (Word16) L_shr( hCPE->hStereoDftDmx->prevTargetGain_fx, 16 ); + Word16 temp_b = (Word16) L_shr( hCPE->hStereoDftDmx->prevTargetGain_fx, 16 ); /* Q13 */ Word16 temp_b_q = 2; move16(); - tempF_fx = Inv16( temp_b, &temp_b_q ); - tempF_fx = L_shl( tempF_fx, sub( ( 31 - 4 ), sub( 15, temp_b_q ) ) ); + tempF_fx = Inv16( temp_b, &temp_b_q ); /* Q13 */ + tempF_fx = L_shl( tempF_fx, sub( ( 31 - 4 ), sub( 15, temp_b_q ) ) ); /* Q27 */ } } ELSE @@ -685,45 +688,45 @@ void stereo_tca_scale_R_channel_fx( IF( EQ_32( hStereoTCA->targetGain_fx, ONE_IN_Q29 ) ) { - tempF1_fx = ONE_IN_Q27; + tempF1_fx = ONE_IN_Q27; /* Q27 */ move32(); } ELSE { - Word16 temp_a = (Word16) L_shr( hStereoTCA->targetGain_fx, (Word16) 16 ); + Word16 temp_a = (Word16) L_shr( hStereoTCA->targetGain_fx, (Word16) 16 ); /* Q13 */ Word16 temp_a_q = 2; move16(); - tempF1_fx = Inv16( temp_a, &temp_a_q ); - tempF1_fx = L_shl( tempF1_fx, sub( ( 31 - 4 ), sub( 15, temp_a_q ) ) ); + tempF1_fx = Inv16( temp_a, &temp_a_q ); /* Q13 */ + tempF1_fx = L_shl( tempF1_fx, sub( ( 31 - 4 ), sub( 15, temp_a_q ) ) ); /* Q27 */ } IF( EQ_32( hStereoTCA->prevTargetGain_fx, ONE_IN_Q29 ) ) { - tempF_fx = ONE_IN_Q27; + tempF_fx = ONE_IN_Q27; /* Q27 */ move32(); } ELSE { - Word16 temp_b = (Word16) L_shr( hStereoTCA->prevTargetGain_fx, (Word16) 16 ); + Word16 temp_b = (Word16) L_shr( hStereoTCA->prevTargetGain_fx, (Word16) 16 ); /* Q13 */ Word16 temp_b_q = 2; move16(); - tempF_fx = Inv16( temp_b, &temp_b_q ); - tempF_fx = L_shl( tempF_fx, sub( ( 31 - 4 ), sub( 15, temp_b_q ) ) ); + tempF_fx = Inv16( temp_b, &temp_b_q ); /* Q13 */ + tempF_fx = L_shl( tempF_fx, sub( ( 31 - 4 ), sub( 15, temp_b_q ) ) ); /* Q27 */ } } SWITCH( output_Fs ) { case 16000: - winSlope_fx = 26843546; + winSlope_fx = 26843546; // 0.0125 in Q31 move32(); BREAK; case 32000: - winSlope_fx = 13421773; + winSlope_fx = 13421773; // 0.00625 in Q30 move32(); BREAK; case 48000: - winSlope_fx = 8947849; + winSlope_fx = 8947849; // 0.00416 in Q30 move32(); BREAK; } @@ -732,7 +735,7 @@ void stereo_tca_scale_R_channel_fx( { FOR( i_fx = 0; i_fx < flat_old; i_fx++ ) { - output_fx[i_fx] = output_fx[i_fx]; + output_fx[i_fx] = output_fx[i_fx]; /* q_out */ move32(); } } @@ -740,7 +743,7 @@ void stereo_tca_scale_R_channel_fx( { FOR( i_fx = 0; i_fx < flat_old; i_fx++ ) { - output_fx[i_fx] = L_shl_sat( Mpy_32_32( output_fx[i_fx], tempF_fx ), 4 ); + output_fx[i_fx] = L_shl_sat( Mpy_32_32( output_fx[i_fx], tempF_fx ), 4 ); /* q_out */ move32(); } } @@ -750,11 +753,11 @@ void stereo_tca_scale_R_channel_fx( { FOR( j = 0; i_fx < flat_old + l_ica_ovl; ( i_fx++, j++ ) ) { - Word32 slope_gain_decend = L_sub( ONE_IN_Q31, j * winSlope_fx ); - Word32 slope_gain_ascend = ( j * winSlope_fx ); - Word32 left_res = Mpy_32_32( slope_gain_decend, output_fx[i_fx] ); - Word32 right_res = Mpy_32_32( slope_gain_ascend, output_fx[i_fx] ); - output_fx[i_fx] = L_add( left_res, right_res ); + Word32 slope_gain_decend = L_sub( ONE_IN_Q31, imult3216( winSlope_fx, j ) ); /* Q31 */ + Word32 slope_gain_ascend = imult3216( winSlope_fx, j ); /* Q31 */ + Word32 left_res = Mpy_32_32( slope_gain_decend, output_fx[i_fx] ); /* q_out */ + Word32 right_res = Mpy_32_32( slope_gain_ascend, output_fx[i_fx] ); /* q_out */ + output_fx[i_fx] = L_add( left_res, right_res ); /* q_out */ move32(); } } @@ -762,11 +765,11 @@ void stereo_tca_scale_R_channel_fx( { FOR( j = 0; i_fx < flat_old + l_ica_ovl; ( i_fx++, j++ ) ) { - Word32 slope_gain_decend = L_sub( ONE_IN_Q31, j * winSlope_fx ); - Word32 slope_gain_ascend = imult3216( winSlope_fx, j ); - Word32 left_res = Mpy_32_32( slope_gain_decend, output_fx[i_fx] ); - Word32 right_res = Mpy_32_32( slope_gain_ascend, output_fx[i_fx] ); - output_fx[i_fx] = L_add_sat( L_shl_sat( Mpy_32_32( tempF_fx, left_res ), 4 ), L_shl_sat( Mpy_32_32( right_res, tempF1_fx ), 4 ) ); + Word32 slope_gain_decend = L_sub( ONE_IN_Q31, imult3216( winSlope_fx, j ) ); /* Q31 */ + Word32 slope_gain_ascend = imult3216( winSlope_fx, j ); /* Q31 */ + Word32 left_res = Mpy_32_32( slope_gain_decend, output_fx[i_fx] ); /* q_out */ + Word32 right_res = Mpy_32_32( slope_gain_ascend, output_fx[i_fx] ); /* q_out */ + output_fx[i_fx] = L_add_sat( L_shl_sat( Mpy_32_32( tempF_fx, left_res ), 4 ), L_shl_sat( Mpy_32_32( right_res, tempF1_fx ), 4 ) ); /* q_out */ move32(); } } @@ -775,7 +778,7 @@ void stereo_tca_scale_R_channel_fx( { FOR( ; i_fx < output_frame; i_fx++ ) { - output_fx[i_fx] = output_fx[i_fx]; + output_fx[i_fx] = output_fx[i_fx]; /* q_out */ move32(); } } @@ -783,7 +786,7 @@ void stereo_tca_scale_R_channel_fx( { FOR( ; i_fx < output_frame; i_fx++ ) { - output_fx[i_fx] = L_shl_sat( Mpy_32_32( output_fx[i_fx], tempF1_fx ), 4 ); + output_fx[i_fx] = L_shl_sat( Mpy_32_32( output_fx[i_fx], tempF1_fx ), 4 ); /* q_out */ move32(); } } @@ -812,9 +815,9 @@ void stereo_tca_init_dec_fx( move16(); hStereoTCA->indx_ica_gD = 0; move16(); - hStereoTCA->targetGain_fx = ONE_IN_Q29; + hStereoTCA->targetGain_fx = ONE_IN_Q29; /* Q29 */ move32(); - hStereoTCA->prevTargetGain_fx = ONE_IN_Q29; + hStereoTCA->prevTargetGain_fx = ONE_IN_Q29; /* Q29 */ move32(); hStereoTCA->corrLagStats = 0; diff --git a/lib_dec/ivas_stereo_icbwe_dec.c b/lib_dec/ivas_stereo_icbwe_dec.c index 5540db7a3f81abc948f062e50c9f106c273719f9..32751a338a44f28d609cbc125b6d4c221b84feac 100644 --- a/lib_dec/ivas_stereo_icbwe_dec.c +++ b/lib_dec/ivas_stereo_icbwe_dec.c @@ -530,8 +530,8 @@ void stereo_icBWE_dec( } #else static Word16 FindScale( - Word32 *buff, - Word16 len, + Word32 *buff, /* Q_buff */ + Word16 len, /* Q0 */ Word16 Q_buff, Word16 Q_prev ) { @@ -553,16 +553,16 @@ static Word16 FindScale( void stereo_icBWE_dec_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *synthRef_fx, /* i/o: Reference channel HB synthesis at output Fs Q11 */ - Word32 *synth_fx, /* o : Non reference channel HB synthesis at output Fs Q11 */ - const Word16 *fb_synth_ref_fx, /* i : ref. high-band synthesis 16-20 kHz fb_synth_ref_fx */ - const Word16 *voice_factors_fx, /* i : voicing factors Q15 */ - const Word16 output_frame, /* i : frame length */ - Word16 *Q_syn /* i : Q of synth and synthRef buffers */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *synthRef_fx, /* i/o: Reference channel HB synthesis at output Fs Q11 */ + Word32 *synth_fx, /* o : Non reference channel HB synthesis at output Fs Q11 */ + const Word16 *fb_synth_ref_fx, /* i : ref. high-band synthesis 16-20 kHz Q_white_exc*/ + const Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 output_frame, /* i : frame length Q0 */ + Word16 *Q_syn /* i : Q of synth and synthRef buffers */ #ifdef FIX_839_FB_CONTENT_SOMETIME_MISSING , - const Word16 Q_white_exc /* i : Q of fb_synth_ref_fx */ + const Word16 Q_white_exc /* i : Q of fb_synth_ref_fx */ #endif ) { @@ -606,7 +606,7 @@ void stereo_icBWE_dec_fx( test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && GT_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) { - hCPE->hStereoDft->core_hist[0] = st->core; + hCPE->hStereoDft->core_hist[0] = st->core; /* Q0 */ move16(); return; @@ -658,20 +658,20 @@ void stereo_icBWE_dec_fx( move64(); tmp = shl_sat( 1, synthRef_shift ); #endif - FOR( i = 0; i < shr( output_frame, 1 ); i++ ) + FOR( i = 0; i < output_frame / 2; i++ ) { // needed to be adjusted for q #ifndef FIX_826_PRECISION_LOST_AND_COMPL L_tmp = L_shl( synthRef_fx[i], synthRef_shift ); hb_nrg2_fx = L_add( hb_nrg2_fx, Mpy_32_32( L_tmp, L_tmp ) ); // 2*(Qx + SynthRef_shift) - 31 #else - L_tmp = Mpy_32_16_1( synthRef_fx[i], tmp ); - W_tmp = W_mac_32_32( W_tmp, L_tmp, L_tmp ); + L_tmp = Mpy_32_16_1( synthRef_fx[i], tmp ); /* Qsyn + SynthRef_shift - 15 */ + W_tmp = W_mac_32_32( W_tmp, L_tmp, L_tmp ); /* 2 * (Qsyn + SynthRef_shift) - 29 */ #endif } #ifdef FIX_826_PRECISION_LOST_AND_COMPL - hb_nrg_fx = W_round48_L( W_tmp ); - hCPE->hStereoDft->hb_nrg_subr_fx[0] = hb_nrg_fx; + hb_nrg_fx = W_round48_L( W_tmp ); /* 2 * (Qsyn + SynthRef_shift) - 45 */ + hCPE->hStereoDft->hb_nrg_subr_fx[0] = hb_nrg_fx; /* 2 * (Qsyn + SynthRef_shift) - 45 */ move32(); hStereoDft->q_hb_nrg_subr = sub( shl( add( *Q_syn, synthRef_shift ), 1 ), 45 ); move16(); @@ -679,12 +679,12 @@ void stereo_icBWE_dec_fx( move64(); FOR( ; i < output_frame; i++ ) { - L_tmp = Mpy_32_16_1( synthRef_fx[i], tmp ); - W_tmp = W_mac_32_32( W_tmp, L_tmp, L_tmp ); + L_tmp = Mpy_32_16_1( synthRef_fx[i], tmp ); /* Qsyn + SynthRef_shift - 15 */ + W_tmp = W_mac_32_32( W_tmp, L_tmp, L_tmp ); /* 2 * (Qsyn + SynthRef_shift) - 45 */ } - hCPE->hStereoDft->hb_nrg_subr_fx[1] = W_round48_L( W_tmp ); // 2*(Qx + SynthRef_shift) - 45 - hb_nrg_fx = L_add( hCPE->hStereoDft->hb_nrg_subr_fx[0], hCPE->hStereoDft->hb_nrg_subr_fx[1] ); + hCPE->hStereoDft->hb_nrg_subr_fx[1] = W_round48_L( W_tmp ); // 2 * (Qsyn + SynthRef_shift) - 45 + hb_nrg_fx = L_add( hCPE->hStereoDft->hb_nrg_subr_fx[0], hCPE->hStereoDft->hb_nrg_subr_fx[1] ); // 2 * (Qsyn + SynthRef_shift) - 45 #else hCPE->hStereoDft->hb_nrg_subr_fx[0] = hb_nrg2_fx; move32(); @@ -705,7 +705,7 @@ void stereo_icBWE_dec_fx( #endif - Copy32( synthRef_fx, hCPE->hStereoDft->hb_stefi_sig_fx + hCPE->hStereoDft->hb_stefi_delay, output_frame ); + Copy32( synthRef_fx, hCPE->hStereoDft->hb_stefi_sig_fx + hCPE->hStereoDft->hb_stefi_delay, output_frame ); /* Qsynth */ #ifndef FIX_826_PRECISION_LOST_AND_COMPL Scale_sig32( hCPE->hStereoDft->hb_stefi_sig_fx + hCPE->hStereoDft->hb_stefi_delay, output_frame, -5 ); #endif @@ -720,9 +720,9 @@ void stereo_icBWE_dec_fx( move32(); #endif // MSAN_FIX } - hCPE->hStereoDft->hb_nrg_subr_fx[0] = ( Mpy_32_16_1( hCPE->hStereoDft->hb_nrg_subr_fx[0], shl( hCPE->hStereoDft->NFFT / 2, 6 ) ) ); // 2 * (Qx + SynthRef_shift) - 40 // 2 * (Qx + SynthRef_shift) - 31 - 15 + hCPE->hStereoDft->hb_nrg_subr_fx[0] = ( Mpy_32_16_1( hCPE->hStereoDft->hb_nrg_subr_fx[0], shl( shr( hCPE->hStereoDft->NFFT, 1 ), 6 ) ) ); // 2 * (Qsynth + SynthRef_shift) - 40 // 2 * (Qx + SynthRef_shift) - 31 - 15 move32(); - hCPE->hStereoDft->hb_nrg_subr_fx[1] = ( Mpy_32_16_1( hCPE->hStereoDft->hb_nrg_subr_fx[1], shl( hCPE->hStereoDft->NFFT / 2, 6 ) ) ); // 2 * (Qx + SynthRef_shift) - 40 + hCPE->hStereoDft->hb_nrg_subr_fx[1] = ( Mpy_32_16_1( hCPE->hStereoDft->hb_nrg_subr_fx[1], shl( shr( hCPE->hStereoDft->NFFT, 1 ), 6 ) ) ); // 2 * (Qsynth + SynthRef_shift) - 40 move32(); #ifndef FIX_826_PRECISION_LOST_AND_COMPL hCPE->hStereoDft->q_hb_nrg_subr = sub( shl( ( *Q_syn + synthRef_shift ), 1 ), 40 ); @@ -750,7 +750,7 @@ void stereo_icBWE_dec_fx( } ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && LE_32( st->core_brate, SID_2k40 ) ) { - Copy32( synthRef_fx, synth_fx, output_frame ); + Copy32( synthRef_fx, synth_fx, output_frame ); /* Qsynth */ return; } @@ -767,9 +767,9 @@ void stereo_icBWE_dec_fx( { hStereoICBWE->prevSpecMapping_fx = 0; move16(); - hStereoICBWE->prevgsMapping_fx = 16384; + hStereoICBWE->prevgsMapping_fx = 16384; /* 1.f in Q14 */ move16(); - hStereoICBWE->icbweM2Ref_prev_fx = 16384; + hStereoICBWE->icbweM2Ref_prev_fx = 16384; /* 1.f in Q14 */ move16(); } @@ -782,9 +782,9 @@ void stereo_icBWE_dec_fx( { hStereoICBWE->prevSpecMapping_fx = 0; move16(); - hStereoICBWE->prevgsMapping_fx = 16384; + hStereoICBWE->prevgsMapping_fx = 16384; /* 1.f in Q14 */ move16(); - hStereoICBWE->icbweM2Ref_prev_fx = 16384; + hStereoICBWE->icbweM2Ref_prev_fx = 16384; /* 1.f in Q14 */ move16(); } ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) @@ -797,12 +797,12 @@ void stereo_icBWE_dec_fx( prevgsMapping_fx = hStereoICBWE->prevgsMapping_fx; move16(); temp1_fx = shr( extract_h( hStereoDft->side_gain_fx[2 * STEREO_DFT_BAND_MAX + hStereoDft->nbands - 1] ), 1 ); - icbweM2Ref_fx = add( 16384, temp1_fx ); - gsMapping_fx = sub( 16384, temp1_fx ); + icbweM2Ref_fx = add( 16384 /*1.f in Q14*/, temp1_fx ); /* Q14 */ + gsMapping_fx = sub( 16384 /*1.f in Q14*/, temp1_fx ); /* Q14 */ - winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); //(int16_t)((SHB_OVERLAP_LEN * st->output_Fs) / 16000); - winSlope_fx = div_s( 1, winLen_fx ); - alpha_fx = winSlope_fx; + winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); //(int16_t)((SHB_OVERLAP_LEN * st->output_Fs) / 16000); Q0 + winSlope_fx = div_s( 1, winLen_fx ); /* Q15 */ + alpha_fx = winSlope_fx; /* Q15 */ move16(); FOR( i = 0; i < winLen_fx; i++ ) { @@ -823,29 +823,29 @@ void stereo_icBWE_dec_fx( } #else /*synthRef[i] *= ( alpha * ( icbweM2Ref ) + ( 1.0f - alpha ) * ( hStereoICBWE->icbweM2Ref_prev ) );*/ - temp1_fx = sub( 32767, alpha_fx ); + temp1_fx = sub( 32767, alpha_fx ); /* 1.f in Q15 */ L_tmp = L_mult( alpha_fx, icbweM2Ref_fx ); // Q15 + Q14 + 1 - L_tmp = L_mac( L_tmp, temp1_fx, hStereoICBWE->icbweM2Ref_prev_fx ); // Q15 + Q14 +1 ; - synthRef_fx[i] = L_shl( Mpy_32_32( synthRef_fx[i], L_tmp ), 1 ); + L_tmp = L_mac( L_tmp, temp1_fx, hStereoICBWE->icbweM2Ref_prev_fx ); // Q15 + Q14 + 1 + synthRef_fx[i] = L_shl( Mpy_32_32( synthRef_fx[i], L_tmp ), 1 ); // Qsynth move32(); /*synth[i] *= ( alpha * ( gsMapping ) + ( 1.0f - alpha ) * ( prevgsMapping ) );*/ - L_tmp = L_mult( alpha_fx, gsMapping_fx ); - L_tmp = L_mac( L_tmp, temp1_fx, prevgsMapping_fx ); - synth_fx[i] = L_shl( Mpy_32_32( synth_fx[i], L_tmp ), 1 ); + L_tmp = L_mult( alpha_fx, gsMapping_fx ); // Q15 + Q14 + 1 + L_tmp = L_mac( L_tmp, temp1_fx, prevgsMapping_fx ); // Q15 + Q14 +1 + synth_fx[i] = L_shl( Mpy_32_32( synth_fx[i], L_tmp ), 1 ); // Qsynth move32(); - alpha_fx = add_sat( alpha_fx, winSlope_fx ); + alpha_fx = add_sat( alpha_fx, winSlope_fx ); /* Q15 */ #endif } FOR( ; i < NS2SA( st->output_Fs, FRAME_SIZE_NS ); i++ ) { - synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); + synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); // Qsyth - 1 move32(); - synth_fx[i] = Mpy_32_16_1( synth_fx[i], gsMapping_fx ); + synth_fx[i] = Mpy_32_16_1( synth_fx[i], gsMapping_fx ); // Qsynth - 1 move32(); } - hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; + hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; // Q14 move16(); - hStereoICBWE->prevgsMapping_fx = gsMapping_fx; + hStereoICBWE->prevgsMapping_fx = gsMapping_fx; // Q14 move16(); *Q_syn = sub( *Q_syn, 1 ); @@ -860,7 +860,7 @@ void stereo_icBWE_dec_fx( hStereoICBWE->refChanIndx_bwe = get_next_indice_fx( st, STEREO_ICBWE_REFBITS ); IF( EQ_16( st->flag_ACELP16k, 1 ) ) { - spIndx = get_next_indice_fx( st, STEREO_ICBWE_SPBITS ); + spIndx = get_next_indice_fx( st, STEREO_ICBWE_SPBITS ); /* Q0 */ } ELSE { @@ -869,33 +869,33 @@ void stereo_icBWE_dec_fx( } IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - gsIndx = get_next_indice_fx( st, STEREO_ICBWE_GSBITS ); + gsIndx = get_next_indice_fx( st, STEREO_ICBWE_GSBITS ); /* Q0 */ } ELSE { - gsIndx = get_next_indice_fx( st, STEREO_ICBWE_GSBITS_DFT ); + gsIndx = get_next_indice_fx( st, STEREO_ICBWE_GSBITS_DFT ); /* Q0 */ } /* Store indices in case of frame loss */ - hStereoICBWE->prev_spIndx = spIndx; + hStereoICBWE->prev_spIndx = spIndx; /* Q0 */ move16(); - hStereoICBWE->prev_gsIndx = gsIndx; + hStereoICBWE->prev_gsIndx = gsIndx; /* Q0 */ move16(); } ELSE /*bfi*/ { /* Retrieve last decoded indices */ - spIndx = hStereoICBWE->prev_spIndx; + spIndx = hStereoICBWE->prev_spIndx; /* Q0 */ move16(); - gsIndx = hStereoICBWE->prev_gsIndx; + gsIndx = hStereoICBWE->prev_gsIndx; /* Q0 */ move16(); - hStereoICBWE->refChanIndx_bwe = hStereoICBWE->prev_refChanIndx_bwe; + hStereoICBWE->refChanIndx_bwe = hStereoICBWE->prev_refChanIndx_bwe; /* Q0 */ move16(); } /* IC-BWE parameter de-quant */ /* sp Mapping */ - hStereoICBWE->prevSpecMapping_fx = usdequant_fx( spIndx, -19661, 3277 ); // Q15 + hStereoICBWE->prevSpecMapping_fx = usdequant_fx( spIndx, -19661 /* -0.6 in Q15 */, 3277 /* 0.2 in Q14 */ ); // Q15 /* gs Mapping */ prevgsMapping_fx = hStereoICBWE->prevgsMapping_fx; // Q14 @@ -903,12 +903,12 @@ void stereo_icBWE_dec_fx( IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - hStereoICBWE->prevgsMapping_fx = pow_10_icbwe_gsMapping_tbl_fx[gsIndx]; + hStereoICBWE->prevgsMapping_fx = pow_10_icbwe_gsMapping_tbl_fx[gsIndx]; /* Q14 */ move16(); } ELSE { - hStereoICBWE->prevgsMapping_fx = pow_10_icbwe_gsMappingDFT_tbl_fx[gsIndx]; + hStereoICBWE->prevgsMapping_fx = pow_10_icbwe_gsMappingDFT_tbl_fx[gsIndx]; /* Q14 */ move16(); } @@ -927,17 +927,17 @@ void stereo_icBWE_dec_fx( IF( hCPE->hStereoDftDmx != NULL ) { test(); - IF( LT_32( hCPE->hStereoDftDmx->targetGain_fx, 268435456 ) || GT_32( hCPE->hStereoDftDmx->targetGain_fx, 1073741824 ) ) + IF( LT_32( hCPE->hStereoDftDmx->targetGain_fx, 268435456 /* 0.5 in Q29 */ ) || GT_32( hCPE->hStereoDftDmx->targetGain_fx, 1073741824 /* 2.0 in Q29 */ ) ) { - v_multc_fixed_16_16( voice_factors_fx, 16384, nlMixFac_fx, NB_SUBFR16k ); + v_multc_fixed_16_16( voice_factors_fx, 16384 /* 0.5 in Q15 */, nlMixFac_fx, NB_SUBFR16k ); } } ELSE { test(); - IF( LT_32( hCPE->hStereoTCA->targetGain_fx, 268435456 ) || GT_32( hCPE->hStereoTCA->targetGain_fx, 1073741824 ) ) + IF( LT_32( hCPE->hStereoTCA->targetGain_fx, 268435456 /* 0.5 in Q29 */ ) || GT_32( hCPE->hStereoTCA->targetGain_fx, 1073741824 /* 2.0 in Q29 */ ) ) { - v_multc_fixed_16_16( voice_factors_fx, 16384, nlMixFac_fx, NB_SUBFR16k ); + v_multc_fixed_16_16( voice_factors_fx, 16384 /* 0.5 in Q15 */, nlMixFac_fx, NB_SUBFR16k ); } } @@ -960,7 +960,7 @@ void stereo_icBWE_dec_fx( { temp1_fx = 0; move16(); - temp2_fx = 32767; + temp2_fx = 32767; /* 1.0f in Q15 */ move16(); } ELSE @@ -974,7 +974,7 @@ void stereo_icBWE_dec_fx( } tmp = 0; move16(); - temp2_fx = Sqrt16( sub( 32767, nlMixFac_fx[i] ), &tmp ); + temp2_fx = Sqrt16( sub( 32767 /* 1.0f in Q15 */, nlMixFac_fx[i] ), &tmp ); IF( LT_16( tmp, 0 ) ) { temp2_fx = shl( temp2_fx, tmp ); @@ -1009,13 +1009,13 @@ void stereo_icBWE_dec_fx( Q_syn_shb = sub( Q_syn_shb, 3 ); // gaurded bits - Scale_sig32( hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, sub( Q_syn_shb, 12 ) ); - Scale_sig32( excSHB_nonref_fx, L_FRAME16k, sub( Q_syn_shb, Q_icBWE ) ); - Scale_sig32( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, LPC_SHB_ORDER, sub( Q_syn_shb, hStereoICBWE->prev_Q_lpc_shbsynth_nonref ) ); - Scale_sig32( hStereoICBWE->mem_syn_shb_nonref_fx, L_SHB_LAHEAD, sub( Q_syn_shb, hStereoICBWE->prev_Q_syn_shb_nonref ) ); + Scale_sig32( hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, sub( Q_syn_shb, 12 ) ); // Q_syn_shb + Scale_sig32( excSHB_nonref_fx, L_FRAME16k, sub( Q_syn_shb, Q_icBWE ) ); // Q_syn_shb + Scale_sig32( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, LPC_SHB_ORDER, sub( Q_syn_shb, hStereoICBWE->prev_Q_lpc_shbsynth_nonref ) ); // Q_syn_shb + Scale_sig32( hStereoICBWE->mem_syn_shb_nonref_fx, L_SHB_LAHEAD, sub( Q_syn_shb, hStereoICBWE->prev_Q_syn_shb_nonref ) ); // Q_syn_shb - Copy32( hStereoICBWE->mem_syn_shb_nonref_fx, shb_synth_nonref_fx, L_SHB_LAHEAD ); + Copy32( hStereoICBWE->mem_syn_shb_nonref_fx, shb_synth_nonref_fx, L_SHB_LAHEAD ); // Q_syn_shb E_UTIL_synthesis_fx( 0, hStereoICBWE->lpSHBRef_fx, excSHB_nonref_fx, shb_synth_nonref_fx + L_SHB_LAHEAD, L_FRAME16k, hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 1, LPC_SHB_ORDER ); @@ -1032,13 +1032,13 @@ void stereo_icBWE_dec_fx( move32(); FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) { - L_tmp = L_shl( shb_synth_nonref_fx[i], shift_prev_pow ); - prev_pow_fx = L_add( prev_pow_fx, Mpy_32_32( L_tmp, L_tmp ) ); + L_tmp = L_shl( shb_synth_nonref_fx[i], shift_prev_pow ); // Qsyn_shb + shift_prev_pow + prev_pow_fx = L_add( prev_pow_fx, Mpy_32_32( L_tmp, L_tmp ) ); /* 2 * ( Qsyn_shb + shift_prev_pow ) - 31 */ } FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) { - L_tmp = L_shl( shb_synth_nonref_fx[L_SHB_LAHEAD + 10 + i], shift_prev_pow ); - curr_pow_fx = L_add( curr_pow_fx, Mpy_32_32( L_tmp, L_tmp ) ); + L_tmp = L_shl( shb_synth_nonref_fx[L_SHB_LAHEAD + 10 + i], shift_prev_pow ); // Qsyn_shb + shift_prev_pow + curr_pow_fx = L_add( curr_pow_fx, Mpy_32_32( L_tmp, L_tmp ) ); /* 2 * ( Qsyn_shb + shift_prev_pow ) - 31 */ } IF( prev_pow_fx == 0 ) @@ -1057,42 +1057,42 @@ void stereo_icBWE_dec_fx( } IF( e_scale_fx < 0 ) { - scale_fx = shl( scale_fx, e_scale_fx ); + scale_fx = shl( scale_fx, e_scale_fx ); /* exp(e_scale_fx) */ e_scale_fx = 0; move16(); } FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - shb_synth_nonref_fx[i] = Mpy_32_16_1( shb_synth_nonref_fx[i], scale_fx ); + shb_synth_nonref_fx[i] = Mpy_32_16_1( shb_synth_nonref_fx[i], scale_fx ); // Qsyn_shb move32(); } - tmp = 3276; + tmp = 3276; /* 0.1 in Q15 */ move16(); FOR( ; i < L_SHB_LAHEAD + 10; i++ ) { IF( EQ_16( e_scale_fx, 0 ) ) { - temp1_fx = 32767; + temp1_fx = 32767; /* 1.0f in Q15 */ move16(); } ELSE { - temp1_fx = shl( 1, sub( 15, e_scale_fx ) ); + temp1_fx = shl( 1, sub( 15, e_scale_fx ) ); /* 15 - e_scale_fx */ move16(); } - L_tmp = L_mult0( tmp, temp1_fx ); - L_tmp = L_mac0( L_tmp, sub( 32767, tmp ), scale_fx ); - shb_synth_nonref_fx[i] = Mpy_32_16_1( shb_synth_nonref_fx[i], shl( round_fx( L_tmp ), 1 ) ); + L_tmp = L_mult0( tmp, temp1_fx ); /* Q15 + Q15 - e_scale_fx */ + L_tmp = L_mac0( L_tmp, sub( 32767 /* 1.0f in Q15 */, tmp ), scale_fx ); /* Q15 + Q15 - e_scale_fx */ + shb_synth_nonref_fx[i] = Mpy_32_16_1( shb_synth_nonref_fx[i], shl( round_fx( L_tmp ), 1 ) ); // Q_syn_shb - e_scale_fx move32(); - IF( LT_16( tmp, 29492 ) ) + IF( LT_16( tmp, 29492 /* 0.9f in Q15 */ ) ) { - tmp = add( tmp, 3276 ); + tmp = add( tmp, 3276 /* 0.1f in Q15 */ ); } } /* spec and gs adjustment */ Q_syn_shb = sub( Q_syn_shb, e_scale_fx ); - Scale_sig32( shb_synth_nonref_fx + L_SHB_LAHEAD + 10, L_FRAME16k - 10, -e_scale_fx ); + Scale_sig32( shb_synth_nonref_fx + L_SHB_LAHEAD + 10, L_FRAME16k - 10, -e_scale_fx ); /* Q_syn_shb */ tmp = 31; move16(); @@ -1108,8 +1108,8 @@ void stereo_icBWE_dec_fx( tmp = sub( tmp, 9 ); - Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, tmp - Q_syn_shb ); - hStereoICBWE->memShbSpecMapping_fx = L_shl( hStereoICBWE->memShbSpecMapping_fx, sub( tmp, hStereoICBWE->prev_Q_memshbspec ) ); + Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, sub( tmp, Q_syn_shb ) ); /* tmp */ + hStereoICBWE->memShbSpecMapping_fx = L_shl( hStereoICBWE->memShbSpecMapping_fx, sub( tmp, hStereoICBWE->prev_Q_memshbspec ) ); /* tmp */ hStereoICBWE->prev_Q_memshbspec = tmp; move16(); @@ -1119,7 +1119,7 @@ void stereo_icBWE_dec_fx( deemph_fx_32( 0, shb_synth_nonref_fx + L_SHB_LAHEAD, specMapping_fx, L_FRAME16k, &( hStereoICBWE->memShbSpecMapping_fx ) ); hStereoICBWE->prev_Q_memshbspec = Q_syn_shb; move16(); - Copy32( shb_synth_nonref_fx + L_FRAME16k, hStereoICBWE->mem_syn_shb_nonref_fx, L_SHB_LAHEAD ); + Copy32( shb_synth_nonref_fx + L_FRAME16k, hStereoICBWE->mem_syn_shb_nonref_fx, L_SHB_LAHEAD ); /* Q_syn_shb */ hStereoICBWE->prev_Q_syn_shb_nonref = Q_syn_shb; move16(); @@ -1130,10 +1130,10 @@ void stereo_icBWE_dec_fx( tmp = sub( tmp, 3 ); - Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, tmp - Q_syn_shb ); - Scale_sig32( hStereoICBWE->mem_syn_shb_ola_nonref_fx, L_SHB_LAHEAD, tmp - hStereoICBWE->prev_Q_syn_shb_ola_nonref ); + Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, sub( tmp, Q_syn_shb ) ); /* tmp */ + Scale_sig32( hStereoICBWE->mem_syn_shb_ola_nonref_fx, L_SHB_LAHEAD, sub( tmp, hStereoICBWE->prev_Q_syn_shb_ola_nonref ) ); /* tmp */ - ScaleShapedSHB_32( SHB_OVERLAP_LEN, shb_synth_nonref_fx, hStereoICBWE->mem_syn_shb_ola_nonref_fx, hStereoICBWE->gshapeRef_fx, ( Mpy_32_16_1( L_shl( hStereoICBWE->gFrameRef_fx, 1 ), mult_r( gsMapping_fx, 29492 ) ) ), window_shb_fx, subwin_shb_fx, &tmp, &temp1_fx ); + ScaleShapedSHB_32( SHB_OVERLAP_LEN, shb_synth_nonref_fx, hStereoICBWE->mem_syn_shb_ola_nonref_fx, hStereoICBWE->gshapeRef_fx, ( Mpy_32_16_1( L_shl( hStereoICBWE->gFrameRef_fx, 1 ), mult_r( gsMapping_fx, 29492 /* 0.9 in Q15 */ ) ) ), window_shb_fx, subwin_shb_fx, &tmp, &temp1_fx ); hStereoICBWE->prev_Q_syn_shb_ola_nonref = tmp; move16(); @@ -1155,9 +1155,9 @@ void stereo_icBWE_dec_fx( tmp = sub( tmp, 3 ); - Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, sub( tmp, Q_syn_shb ) ); - Scale_sig32( hStereoICBWE->memShbHilbert_nonref_fx, HILBERT_MEM_SIZE, sub( tmp, hStereoICBWE->prev_Q_hilb ) ); - Scale_sig32( hStereoICBWE->memShbInterp_nonref_fx, 2 * ALLPASSSECTIONS_STEEP + 1, sub( tmp, hStereoICBWE->prev_Q_interp ) ); + Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, sub( tmp, Q_syn_shb ) ); /* tmp */ + Scale_sig32( hStereoICBWE->memShbHilbert_nonref_fx, HILBERT_MEM_SIZE, sub( tmp, hStereoICBWE->prev_Q_hilb ) ); /* tmp */ + Scale_sig32( hStereoICBWE->memShbInterp_nonref_fx, 2 * ALLPASSSECTIONS_STEEP + 1, sub( tmp, hStereoICBWE->prev_Q_interp ) ); /* tmp */ hStereoICBWE->prev_Q_hilb = tmp; move16(); @@ -1171,43 +1171,43 @@ void stereo_icBWE_dec_fx( } ELSE { - Copy32( synthRef_fx, synth_fx, output_frame ); + Copy32( synthRef_fx, synth_fx, output_frame ); /* Q_syn */ - winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); - winSlope_fx = div_s( 1, winLen_fx ); - alpha_fx = winSlope_fx; + winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); /* Q0 */ + winSlope_fx = div_s( 1, winLen_fx ); /* Q15 */ + alpha_fx = winSlope_fx; /* Q15 */ move16(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - ratio_L_fx = 16384; + ratio_L_fx = 16384; /* 0.5 in Q15 */ move16(); } ELSE { - ratio_L_fx = extract_h( tdm_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx] ); + ratio_L_fx = extract_h( tdm_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx] ); /* Q15 */ move16(); } - icbweM2Ref_fx = gsMapping_fx; + icbweM2Ref_fx = gsMapping_fx; /* Q14 */ move16(); IF( hStereoICBWE->refChanIndx_bwe == L_CH_INDX ) { - IF( GE_16( ratio_L_fx, 3276 ) ) + IF( GE_16( ratio_L_fx, 3276 /* 0.1 in Q15 */ ) ) { - tmp = mult_r( sub( 32767, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15 - tmp = mult_r( tmp, gsMapping_fx ); // Q14 - tmp = mult_r( tmp, gsMapping_fx ); // Q13 - IF( LT_16( tmp, 4096 ) ) + tmp = mult_r( sub( 32767 /* 1.0 in Q15 */, ratio_L_fx ), sub( 32767 /* 1.0 in Q15 */, ratio_L_fx ) ); // Q15 + tmp = mult_r( tmp, gsMapping_fx ); // Q14 + tmp = mult_r( tmp, gsMapping_fx ); // Q13 + IF( LT_16( tmp, 4096 /* 0.5 in Q13*/ ) ) { temp1_fx = 0; move16(); temp2_fx = 0; move16(); - tmp = shl( tmp, 2 ); - icbweM2Ref_fx = Sqrt16( sub( 16384, tmp ), &temp1_fx ); + tmp = shl( tmp, 2 ); /* Q13 + Q2 */ + icbweM2Ref_fx = Sqrt16( sub( 16384 /* 0.5 in Q15 */, tmp ), &temp1_fx ); icbweM2Ref_fx = BASOP_Util_Divide1616_Scale( icbweM2Ref_fx, ratio_L_fx, &temp2_fx ); #ifdef FIX_860_FER_CRASH icbweM2Ref_fx = shl_sat( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14 @@ -1224,7 +1224,7 @@ void stereo_icBWE_dec_fx( } ELSE { - IF( LE_16( ratio_L_fx, 29490 ) ) + IF( LE_16( ratio_L_fx, 29490 /* 0.9 in Q15*/ ) ) { #ifdef FIX_TMP_714 tmp = mult_r( ratio_L_fx, ratio_L_fx ); // Q15 @@ -1233,14 +1233,14 @@ void stereo_icBWE_dec_fx( #endif tmp = mult_r( tmp, gsMapping_fx ); // Q14 tmp = mult_r( tmp, gsMapping_fx ); // Q13 - IF( LT_16( tmp, 4096 ) ) + IF( LT_16( tmp, 4096 /* 0.5 in Q13*/ ) ) { temp1_fx = 0; move16(); temp2_fx = 0; move16(); tmp = shl( tmp, 2 ); - icbweM2Ref_fx = Sqrt16( sub( 16384, tmp ), &temp1_fx ); + icbweM2Ref_fx = Sqrt16( sub( 16384 /* 0.5 in Q15 */, tmp ), &temp1_fx ); icbweM2Ref_fx = BASOP_Util_Divide1616_Scale( icbweM2Ref_fx, sub( 32767, ratio_L_fx ), &temp2_fx ); #ifdef FIX_860_FER_CRASH icbweM2Ref_fx = shl_sat( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14 @@ -1260,29 +1260,29 @@ void stereo_icBWE_dec_fx( FOR( i = 0; i < winLen_fx; i++ ) { - L_tmp = L_mult0( alpha_fx, icbweM2Ref_fx ); - L_tmp = L_mac0( L_tmp, sub( 32767, alpha_fx ), hStereoICBWE->icbweM2Ref_prev_fx ); - tmp = shl( round_fx( L_tmp ), 1 ); - synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], tmp ); + L_tmp = L_mult0( alpha_fx, icbweM2Ref_fx ); /* Q29 */ + L_tmp = L_mac0( L_tmp, sub( 32767 /* 1.0 in Q15*/, alpha_fx ), hStereoICBWE->icbweM2Ref_prev_fx ); /* Q29 */ + tmp = shl( round_fx( L_tmp ), 1 ); /* Q14 */ + synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], tmp ); /* Qsyn - 1*/ move32(); - L_tmp = L_mult0( alpha_fx, gsMapping_fx ); - L_tmp = L_mac0( L_tmp, sub( 32767, alpha_fx ), prevgsMapping_fx ); - tmp = shl( round_fx( L_tmp ), 1 ); - synth_fx[i] = Mpy_32_16_1( synth_fx[i], tmp ); + L_tmp = L_mult0( alpha_fx, gsMapping_fx ); /* Q29 */ + L_tmp = L_mac0( L_tmp, sub( 32767 /* 1.0 in Q15*/, alpha_fx ), prevgsMapping_fx ); /* Q29 */ + tmp = shl( round_fx( L_tmp ), 1 ); /* Q14 */ + synth_fx[i] = Mpy_32_16_1( synth_fx[i], tmp ); /* Qsyn - 1 */ move32(); - IF( LE_16( alpha_fx, sub( 32767, winSlope_fx ) ) ) + IF( LE_16( alpha_fx, sub( 32767 /* 1.0 in Q15*/, winSlope_fx ) ) ) { - alpha_fx = add( alpha_fx, winSlope_fx ); + alpha_fx = add( alpha_fx, winSlope_fx ); /* Q15 */ } } FOR( ; i < NS2SA( st->output_Fs, FRAME_SIZE_NS ); i++ ) { - synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); + synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); /* Qsyn - 1 */ move32(); - synth_fx[i] = Mpy_32_16_1( synth_fx[i], gsMapping_fx ); + synth_fx[i] = Mpy_32_16_1( synth_fx[i], gsMapping_fx ); /* Qsyn - 1 */ move32(); } - hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; + hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; /* Q14 */ move16(); ic_bwe_dec_reset_fx( hStereoICBWE ); @@ -1298,7 +1298,7 @@ void stereo_icBWE_dec_fx( /* resample to output FS */ - IF( EQ_32( st->output_Fs, 48000 ) ) + IF( EQ_32( st->output_Fs, 48000 /* Q0 */ ) ) { tmp = 31; move16(); @@ -1306,17 +1306,17 @@ void stereo_icBWE_dec_fx( tmp = FindScale( hStereoICBWE->memShb_fsout_nonref_fx, INTERP_3_2_MEM_LEN, hStereoICBWE->prev_Q_fsout, tmp ); tmp = sub( tmp, 4 ); - Scale_sig32( error_fx, L_FRAME32k, sub( tmp, Q_syn_shb ) ); - Scale_sig32( hStereoICBWE->memShb_fsout_nonref_fx, INTERP_3_2_MEM_LEN, sub( tmp, hStereoICBWE->prev_Q_fsout ) ); + Scale_sig32( error_fx, L_FRAME32k, sub( tmp, Q_syn_shb ) ); /* tmp */ + Scale_sig32( hStereoICBWE->memShb_fsout_nonref_fx, INTERP_3_2_MEM_LEN, sub( tmp, hStereoICBWE->prev_Q_fsout ) ); /* tmp */ interpolate_3_over_2_allpass_32( error_fx, L_FRAME32k, synth_fx, hStereoICBWE->memShb_fsout_nonref_fx ); hStereoICBWE->prev_Q_fsout = tmp; move16(); } - ELSE IF( EQ_32( st->output_Fs, 32000 ) ) + ELSE IF( EQ_32( st->output_Fs, 32000 /* Q0 */ ) ) { - Copy32( error_fx, synth_fx, L_FRAME32k ); + Copy32( error_fx, synth_fx, L_FRAME32k ); /* tmp */ } - ELSE IF( EQ_32( st->output_Fs, 16000 ) ) + ELSE IF( EQ_32( st->output_Fs, 16000 /* Q0 */ ) ) { tmp = 31; move16(); @@ -1324,8 +1324,8 @@ void stereo_icBWE_dec_fx( tmp = FindScale( hStereoICBWE->memShb_fsout_nonref_fx, INTERP_3_2_MEM_LEN, hStereoICBWE->prev_Q_fsout, tmp ); tmp = sub( tmp, 4 ); - Scale_sig32( error_fx, L_FRAME32k, sub( tmp, Q_syn_shb ) ); - Scale_sig32( hStereoICBWE->memShb_fsout_nonref_fx, INTERP_3_2_MEM_LEN, sub( tmp, hStereoICBWE->prev_Q_fsout ) ); + Scale_sig32( error_fx, L_FRAME32k, sub( tmp, Q_syn_shb ) ); /* tmp */ + Scale_sig32( hStereoICBWE->memShb_fsout_nonref_fx, INTERP_3_2_MEM_LEN, sub( tmp, hStereoICBWE->prev_Q_fsout ) ); /* tmp */ Decimate_allpass_steep_fx32( error_fx, hStereoICBWE->memShb_fsout_nonref_fx, L_FRAME32k, synth_fx ); hStereoICBWE->prev_Q_fsout = tmp; move16(); @@ -1333,23 +1333,23 @@ void stereo_icBWE_dec_fx( #ifndef MSAN_FIX Scale_sig32( synth_fx, L_FRAME48k, sub( *Q_syn, add( 1, tmp ) ) ); #else - Scale_sig32( synth_fx, output_frame, sub( *Q_syn, add( 1, tmp ) ) ); + Scale_sig32( synth_fx, output_frame, sub( *Q_syn, add( 1, tmp ) ) ); /* Qsyn - 1 */ #endif *Q_syn = sub( *Q_syn, 1 ); test(); - IF( EQ_16( st->extl, FB_TBE ) && EQ_32( st->output_Fs, 48000 ) ) + IF( EQ_16( st->extl, FB_TBE ) && EQ_32( st->output_Fs, 48000 /* Q0*/ ) ) { // v_add( fb_synth_nonref_fx, synth_fx, synth_fx, L_FRAME48k, 0 ); #ifdef FIX_839_FB_CONTENT_SOMETIME_MISSING - tmp = shl_sat( 1, sub( Q11 + 15, Q_white_exc ) ); + tmp = shl_sat( 1, sub( Q11 + 15, Q_white_exc ) ); /* 29 - Q_white_exc */ IF( tmp != 0 ) { FOR( i = 0; i < L_FRAME48k; i++ ) { - synth_fx[i] = L_mac( synth_fx[i], fb_synth_nonref_fx[i], tmp ); + synth_fx[i] = L_mac( synth_fx[i], fb_synth_nonref_fx[i], tmp ); /* Q_syn */ } } #else @@ -1365,12 +1365,12 @@ void stereo_icBWE_dec_fx( IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - ratio_L_fx = 16384; + ratio_L_fx = 16384; /* 1.0 in Q15 */ move16(); } ELSE { - ratio_L_fx = extract_h( tdm_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx] ); + ratio_L_fx = extract_h( tdm_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx] ); /* Q15 */ move16(); } @@ -1378,19 +1378,19 @@ void stereo_icBWE_dec_fx( move16(); IF( hStereoICBWE->refChanIndx_bwe == L_CH_INDX ) { - IF( GE_16( ratio_L_fx, 3276 ) ) + IF( GE_16( ratio_L_fx, 3276 /* 0.1 in Q15*/ ) ) { - tmp = mult_r( sub( 32767, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15 - tmp = mult_r( tmp, gsMapping_fx ); // Q14 - tmp = mult_r( tmp, gsMapping_fx ); // Q13 - IF( LT_16( tmp, 4096 ) ) + tmp = mult_r( sub( 32767 /* 1.0 in Q15*/, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15 + tmp = mult_r( tmp, gsMapping_fx ); // Q14 + tmp = mult_r( tmp, gsMapping_fx ); // Q13 + IF( LT_16( tmp, 4096 /* 0.5 in Q13*/ ) ) { temp1_fx = 0; move16(); temp2_fx = 0; move16(); tmp = shl( tmp, 2 ); - icbweM2Ref_fx = Sqrt16( sub( 16384, tmp ), &temp1_fx ); + icbweM2Ref_fx = Sqrt16( sub( 16384 /* 0.5 in Q15*/, tmp ), &temp1_fx ); icbweM2Ref_fx = BASOP_Util_Divide1616_Scale( icbweM2Ref_fx, ratio_L_fx, &temp2_fx ); icbweM2Ref_fx = shl_sat( icbweM2Ref_fx, add( temp1_fx, sub( temp2_fx, 1 ) ) ); // Q14 } @@ -1403,7 +1403,7 @@ void stereo_icBWE_dec_fx( } ELSE { - IF( LE_16( ratio_L_fx, 29490 ) ) + IF( LE_16( ratio_L_fx, 29490 /* 0.9 in Q15*/ ) ) { #ifdef FIX_TMP_714 tmp = mult_r( ratio_L_fx, ratio_L_fx ); // Q15 @@ -1412,14 +1412,14 @@ void stereo_icBWE_dec_fx( #endif tmp = mult_r( tmp, gsMapping_fx ); // Q14 tmp = mult_r( tmp, gsMapping_fx ); // Q13 - IF( LT_16( tmp, 4096 ) ) + IF( LT_16( tmp, 4096 /* 0.5 in Q13*/ ) ) { temp1_fx = 0; move16(); temp2_fx = 0; move16(); tmp = shl( tmp, 2 ); - icbweM2Ref_fx = Sqrt16( sub( 16384, tmp ), &temp1_fx ); + icbweM2Ref_fx = Sqrt16( sub( 16384 /* 0.5 in Q15*/, tmp ), &temp1_fx ); icbweM2Ref_fx = BASOP_Util_Divide1616_Scale( icbweM2Ref_fx, sub( 32767, ratio_L_fx ), &temp2_fx ); icbweM2Ref_fx = shl_sat( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14 } @@ -1431,32 +1431,32 @@ void stereo_icBWE_dec_fx( } } - icbweM2Ref_fx = s_max( gsMapping_fx, icbweM2Ref_fx ); + icbweM2Ref_fx = s_max( gsMapping_fx, icbweM2Ref_fx ); /* Q14 */ - winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); - winSlope_fx = div_s( 1, winLen_fx ); - alpha_fx = winSlope_fx; + winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); /* Q0 */ + winSlope_fx = div_s( 1, winLen_fx ); /* Q15 */ + alpha_fx = winSlope_fx; /* Q15 */ move16(); FOR( i = 0; i < winLen_fx; i++ ) { - L_tmp = L_mult0( alpha_fx, icbweM2Ref_fx ); - L_tmp = L_mac0( L_tmp, sub( 32767, alpha_fx ), hStereoICBWE->icbweM2Ref_prev_fx ); - tmp = shl( round_fx( L_tmp ), 1 ); - synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], tmp ); + L_tmp = L_mult0( alpha_fx, icbweM2Ref_fx ); /* Q29 */ + L_tmp = L_mac0( L_tmp, sub( 32767 /* 1.0 in Q15*/, alpha_fx ), hStereoICBWE->icbweM2Ref_prev_fx ); /* Q29 */ + tmp = shl( round_fx( L_tmp ), 1 ); /* Q14 */ + synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], tmp ); /* Qsyn - 1 */ move32(); - IF( LE_16( alpha_fx, sub( 32767, winSlope_fx ) ) ) + IF( LE_16( alpha_fx, sub( 32767 /* 1.0 in Q15*/, winSlope_fx ) ) ) { - alpha_fx = add( alpha_fx, winSlope_fx ); + alpha_fx = add( alpha_fx, winSlope_fx ); /* Q15 */ } } FOR( ; i < NS2SA( st->output_Fs, FRAME_SIZE_NS ); i++ ) { - synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); + synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); /* Qsyn - 1 */ move32(); } - hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; + hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; /* Q14 */ move16(); return; @@ -1753,11 +1753,11 @@ void stereo_icBWE_decproc( #else void stereo_icBWE_decproc_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output[CPE_CHANNELS], /* i/o: output synthesis */ - Word32 outputHB[CPE_CHANNELS][L_FRAME48k], /* i : HB synthesis */ - const Word16 last_core, /* i : last core, primary channel */ - const Word16 last_bwidth, /* i : last bandwidth */ - const Word16 output_frame /* i : frame length */ + Word32 *output[CPE_CHANNELS], /* i/o: output synthesis Q11*/ + Word32 outputHB[CPE_CHANNELS][L_FRAME48k], /* i : HB synthesis Q11*/ + const Word16 last_core, /* i : last core, primary channel Q0*/ + const Word16 last_bwidth, /* i : last bandwidth Q0*/ + const Word16 output_frame /* i : frame length Q0*/ #ifndef FIX_826_PRECISION_LOST_AND_COMPL , Word16 q_output /* i : Q-fac of output */ @@ -1816,14 +1816,14 @@ void stereo_icBWE_decproc_fx( * IC-BWE processing * -------------------------------------------------------------------*/ - core = hCPE->hCoreCoder[0]->core; + core = hCPE->hCoreCoder[0]->core; /* Q0 */ move16(); - extl_brate = hCPE->hCoreCoder[0]->extl_brate; + extl_brate = hCPE->hCoreCoder[0]->extl_brate; /* Q0 */ move32(); - output_Fs = hCPE->hCoreCoder[0]->output_Fs; + output_Fs = hCPE->hCoreCoder[0]->output_Fs; /* Q0 */ move32(); - memOffset = NS2SA( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); + memOffset = NS2SA( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); /* Q0 */ /* LRTD stereo mode - 2xBWEs used */ test(); @@ -1832,10 +1832,10 @@ void stereo_icBWE_decproc_fx( /* delay HB synth */ FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Copy32( outputHB[n] + output_frame - memOffset, temp0_fx, memOffset ); - Copy32( outputHB[n], outputHB[n] + memOffset, output_frame - memOffset ); - Copy32( hCPE->prev_hb_synth_fx[n], outputHB[n], memOffset ); - Copy32( temp0_fx, hCPE->prev_hb_synth_fx[n], memOffset ); + Copy32( outputHB[n] + output_frame - memOffset, temp0_fx, memOffset ); /* Q11 */ + Copy32( outputHB[n], outputHB[n] + memOffset, output_frame - memOffset ); /* Q11 */ + Copy32( hCPE->prev_hb_synth_fx[n], outputHB[n], memOffset ); /* Q11 */ + Copy32( temp0_fx, hCPE->prev_hb_synth_fx[n], memOffset ); /* Q11 */ } IF( EQ_16( hCPE->nchan_out, 1 ) ) @@ -1844,7 +1844,7 @@ void stereo_icBWE_decproc_fx( FOR( i = 0; i < output_frame; i++ ) { #ifdef FIX_826_PRECISION_LOST_AND_COMPL - outputHB[0][i] = W_extract_l( W_shr( W_mac_32_16( W_mult_32_16( outputHB[0][i], 16384 ), outputHB[1][i], 16384 ), Q16 ) ); + outputHB[0][i] = W_extract_l( W_shr( W_mac_32_16( W_mult_32_16( outputHB[0][i], 16384 ), outputHB[1][i], 16384 ), Q16 ) ); /* Q11 */ #else outputHB[0][i] = L_shr( ( outputHB[0][i] + outputHB[1][i] ), 1 ); #endif @@ -1904,15 +1904,15 @@ void stereo_icBWE_decproc_fx( { #if defined FIX_826_PRECISION_LOST_AND_COMPL case 15: - winSlope_fx = 2185; + winSlope_fx = 2185; /* 0.06 in Q15 */ move32(); BREAK; case 30: - winSlope_fx = 1092; + winSlope_fx = 1092; /* 0.03 in Q15 */ move32(); BREAK; case 45: - winSlope_fx = 728; + winSlope_fx = 728; /* 0.02 in Q15 */ move32(); BREAK; #else @@ -1944,8 +1944,8 @@ void stereo_icBWE_decproc_fx( FOR( i = 0; i < memOffset; i++ ) { #if defined FIX_826_PRECISION_LOST_AND_COMPL - alpha_fx = add_sat( alpha_fx, winSlope_fx ); - outputHB[refChanIndx_bwe][i] = W_round48_L( W_mult_32_16( outputHB[refChanIndx_bwe][i] /* Q11 + Q15 + 1 - 16 = Q11)*/, winSlope_fx ) ); // + alpha_fx = add_sat( alpha_fx, winSlope_fx ); /* Q15 */ + outputHB[refChanIndx_bwe][i] = W_round48_L( W_mult_32_16( outputHB[refChanIndx_bwe][i] /* Q11 + Q15 + 1 - 16 = Q11)*/, winSlope_fx ) ); // Q11 #else Word32 mul_win = Mpy_32_16_1( winSlope_fx, ( i + 1 ) ); // Q30 + Q0 - 15 = Q15 mul_win = L_shl( mul_win, 15 ); // Q30 @@ -1955,16 +1955,16 @@ void stereo_icBWE_decproc_fx( } } /* Resampled LB and HB offset */ - Copy32( outputHB[refChanIndx_bwe], temp0_fx + memOffset, sub( output_frame, memOffset ) ); - Copy32( outputHB[!refChanIndx_bwe], temp1_fx + memOffset, sub( output_frame, memOffset ) ); + Copy32( outputHB[refChanIndx_bwe], temp0_fx + memOffset, sub( output_frame, memOffset ) ); /* Q11 */ + Copy32( outputHB[!refChanIndx_bwe], temp1_fx + memOffset, sub( output_frame, memOffset ) ); /* Q11 */ - decoderDelay = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); + decoderDelay = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); /* Q0 */ test(); IF( last_core != ACELP_CORE && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { /* hb_synth of mid band is faded out in the 1.25 ms prior to DFT analysis and the icbwe is faded in time domain */ - icbweOLASize = NS2SA( output_Fs, STEREO_DFT_DELAY_DEC_BWE_NS ); + icbweOLASize = NS2SA( output_Fs, STEREO_DFT_DELAY_DEC_BWE_NS ); /* Q0 */ FOR( i = 0; i < decoderDelay; i++ ) { @@ -1979,15 +1979,15 @@ void stereo_icBWE_decproc_fx( { #if defined FIX_826_PRECISION_LOST_AND_COMPL case 60: - winSlope_fx = 546; + winSlope_fx = 546; /* 0.0166 in Q15 */ move16(); BREAK; case 40: - winSlope_fx = 819; + winSlope_fx = 819; /* 0.025 in Q15 */ move16(); BREAK; case 20: - winSlope_fx = 1638; + winSlope_fx = 1638; /* 0.05 in Q15 */ move16(); BREAK; default: @@ -2009,16 +2009,16 @@ void stereo_icBWE_decproc_fx( BREAK; #endif } - alpha_fx = winSlope_fx; // Q30 + alpha_fx = winSlope_fx; // Q15 move32(); FOR( ; i < add( decoderDelay, icbweOLASize ); i++ ) { #if defined FIX_826_PRECISION_LOST_AND_COMPL temp0_fx[i] = W_round48_L( W_mult_32_16( temp0_fx[i], alpha_fx ) ); // Q11 move32(); - temp1_fx[i] = W_round48_L( W_mult_32_16( temp1_fx[i], alpha_fx ) ); + temp1_fx[i] = W_round48_L( W_mult_32_16( temp1_fx[i], alpha_fx ) ); // Q11 move32(); - alpha_fx = add_sat( alpha_fx, winSlope_fx ); + alpha_fx = add_sat( alpha_fx, winSlope_fx ); // Q15 #else temp0_fx[i] = L_shl_sat( Mpy_32_32( temp0_fx[i], alpha_fx ), 1 ); // Q11 move32(); @@ -2038,15 +2038,15 @@ void stereo_icBWE_decproc_fx( { #if defined FIX_826_PRECISION_LOST_AND_COMPL case 15: - winSlope_fx = 2185; + winSlope_fx = 2185; /* 0.06 in Q15 */ move16(); BREAK; case 30: - winSlope_fx = 1092; + winSlope_fx = 1092; /* 0.03 in Q15 */ move16(); BREAK; case 45: - winSlope_fx = 728; + winSlope_fx = 728; /* 0.022 in Q15 */ move16(); BREAK; #else @@ -2087,18 +2087,18 @@ void stereo_icBWE_decproc_fx( temp1_fx[i] = L_add( L_shl( Mpy_32_32( Mpy_32_16_1( winSlope_fx, ( i + 1 ) ), hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i] ), 16 ), L_shl( Mpy_32_32( Mpy_32_16_1( winSlope_fx, ( 1 - ( i + 1 ) ) ), hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i] ), 16 ) ); #else - Incr = add_sat( Incr, winSlope_fx ); - Decr = sub( Decr, winSlope_fx ); - temp0_fx[i] = W_round48_L( W_mac_32_16( W_mult_32_16( hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i], Incr ), hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i], Decr ) ); - temp1_fx[i] = W_round48_L( W_mac_32_16( W_mult_32_16( hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i], Incr ), hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i], Decr ) ); + Incr = add_sat( Incr, winSlope_fx ); /* Q15 */ + Decr = sub( Decr, winSlope_fx ); /* Q15 */ + temp0_fx[i] = W_round48_L( W_mac_32_16( W_mult_32_16( hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i], Incr ), hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i], Decr ) ); /* Q11 */ + temp1_fx[i] = W_round48_L( W_mac_32_16( W_mult_32_16( hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i], Incr ), hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i], Decr ) ); /* Q11 */ #endif move32(); } } ELSE { - Copy32( hStereoICBWE->memOutHB_fx[refChanIndx_bwe], temp0_fx, memOffset ); - Copy32( hStereoICBWE->memOutHB_fx[!refChanIndx_bwe], temp1_fx, memOffset ); + Copy32( hStereoICBWE->memOutHB_fx[refChanIndx_bwe], temp0_fx, memOffset ); /* Q11 */ + Copy32( hStereoICBWE->memOutHB_fx[!refChanIndx_bwe], temp1_fx, memOffset ); /* Q11 */ } } @@ -2117,9 +2117,9 @@ void stereo_icBWE_decproc_fx( move32(); output[0][i] = L_add( output[0][i], temp0_fx[i] ); #else - W_tmp = W_mult_32_16( output[0][i], 32767 ); - W_tmp = W_mac_32_16( W_tmp, temp0_fx[i], 16384 ); - output[0][i] = W_round48_L( W_mac_32_16( W_tmp, temp1_fx[i], 16384 ) ); + W_tmp = W_mult_32_16( output[0][i], 32767 /* 1.0 in Q15*/ ); /* Q11 */ + W_tmp = W_mac_32_16( W_tmp, temp0_fx[i], 16384 /* 0.5 in Q15*/ ); /* Q11*/ + output[0][i] = W_round48_L( W_mac_32_16( W_tmp, temp1_fx[i], 16384 /* 0.5 in Q15*/ ) ); /* Q11 */ move32(); #endif @@ -2132,14 +2132,14 @@ void stereo_icBWE_decproc_fx( v_add_32( temp1_fx, output[1], output[1], output_frame ); } - Copy32( outputHB[0] + output_frame - memOffset, hStereoICBWE->memOutHB_fx[0], memOffset ); - Copy32( outputHB[1] + output_frame - memOffset, hStereoICBWE->memOutHB_fx[1], memOffset ); + Copy32( outputHB[0] + output_frame - memOffset, hStereoICBWE->memOutHB_fx[0], memOffset ); /* Q11*/ + Copy32( outputHB[1] + output_frame - memOffset, hStereoICBWE->memOutHB_fx[1], memOffset ); /* Q11 */ IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { /*win_dft = hCPE->hStereoDft->win32ms;*/ - win_dft_fx = hCPE->hStereoDft->win32ms_fx; - dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; + win_dft_fx = hCPE->hStereoDft->win32ms_fx; /* Q15 */ + dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; /* Q0 */ move16(); /* Preparing buffers in anticipation of an ACELP to TCX switch */ @@ -2161,9 +2161,9 @@ void stereo_icBWE_decproc_fx( j = add( j, 1 ); #else Word16 tmp_mul = i_mult( STEREO_DFT32MS_STEP, j ); - hStereoICBWE->memTransitionHB_fx[0][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[0][i], win_dft_fx[tmp_mul] ); + hStereoICBWE->memTransitionHB_fx[0][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[0][i], win_dft_fx[tmp_mul] ); /* Q11 */ move32(); - hStereoICBWE->memTransitionHB_fx[1][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[1][i], win_dft_fx[tmp_mul] ); + hStereoICBWE->memTransitionHB_fx[1][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[1][i], win_dft_fx[tmp_mul] ); /* Q11 */ move32(); j = sub( j, 1 ); #endif @@ -2177,9 +2177,9 @@ void stereo_icBWE_decproc_fx( { #if !defined FIX_826_PRECISION_LOST_AND_COMPL || defined FIX_833_CORRECTION_to_826 Word16 tmp_mul = mult0( STEREO_DFT32MS_STEP, ( sub( dftOvlLen, add( 1, j ) ) ) ); - hStereoICBWE->memTransitionHB_fx[0][memOffset + i] = Mpy_32_16_1( outputHB[0][output_frame - i - 1], win_dft_fx[tmp_mul] ); + hStereoICBWE->memTransitionHB_fx[0][memOffset + i] = Mpy_32_16_1( outputHB[0][output_frame - i - 1], win_dft_fx[tmp_mul] ); /* Q11 */ move32(); - hStereoICBWE->memTransitionHB_fx[1][memOffset + i] = Mpy_32_16_1( outputHB[1][output_frame - i - 1], win_dft_fx[tmp_mul] ); + hStereoICBWE->memTransitionHB_fx[1][memOffset + i] = Mpy_32_16_1( outputHB[1][output_frame - i - 1], win_dft_fx[tmp_mul] ); /* Q11 */ move32(); j = add( j, 1 ); #else @@ -2250,8 +2250,8 @@ void stereo_icBWE_decproc_fx( #else Word32 win_in_fx, win_out_fx, tmp_fx, gain0_fx, gain1_fx; #endif - win_dft_fx = hCPE->hStereoDft->win32ms_fx; - dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; + win_dft_fx = hCPE->hStereoDft->win32ms_fx; /* Q15 */ + dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; /* Q0 */ move16(); // Scale_sig32(hCPE->hStereoDft->td_gain_fx, STEREO_DFT_CORE_HIST_MAX, -12); @@ -2265,22 +2265,22 @@ void stereo_icBWE_decproc_fx( /* hCPE->hStereoDft->q_hb_stefi_sig_fx is always 31 here */ /* tmp = ( win_in * hCPE->hStereoDft->td_gain[0] + win_out * hCPE->hStereoDft->td_gain[1] ) * hCPE->hStereoDft->hb_stefi_sig[i]; */ - W_tmp = W_mult_32_32( hCPE->hStereoDft->td_gain_fx[0], win_in_fx ); + W_tmp = W_mult_32_32( hCPE->hStereoDft->td_gain_fx[0], win_in_fx ); /* q_td_gain + Q31 + 1 */ if ( hCPE->hStereoDft->q_td_gain[0] != 0 ) { - W_tmp = W_shl( W_tmp, sub( 31, hCPE->hStereoDft->q_td_gain[0] ) ); + W_tmp = W_shl( W_tmp, sub( 31, hCPE->hStereoDft->q_td_gain[0] ) ); /* Q63 */ } - W_tmp1 = W_mult_32_32( hCPE->hStereoDft->td_gain_fx[1], win_out_fx ); + W_tmp1 = W_mult_32_32( hCPE->hStereoDft->td_gain_fx[1], win_out_fx ); /* q_td_gain + Q31 + 1 */ if ( hCPE->hStereoDft->q_td_gain[1] != 0 ) { - W_tmp1 = W_shl( W_tmp1, sub( 31, hCPE->hStereoDft->q_td_gain[1] ) ); + W_tmp1 = W_shl( W_tmp1, sub( 31, hCPE->hStereoDft->q_td_gain[1] ) ); /* Q63 */ } - tmp_fx = W_extract_h( W_add_nosat( W_tmp, W_tmp1 ) ); - tmp_fx = W_extract_h( W_mult_32_32( tmp_fx, hCPE->hStereoDft->hb_stefi_sig_fx[i] ) ); + tmp_fx = W_extract_h( W_add_nosat( W_tmp, W_tmp1 ) ); /* Q31 */ + tmp_fx = W_extract_h( W_mult_32_32( tmp_fx, hCPE->hStereoDft->hb_stefi_sig_fx[i] ) ); /* Q11 */ - output[0][i] = L_add_sat( output[0][i], tmp_fx ); + output[0][i] = L_add_sat( output[0][i], tmp_fx ); /* Q11 */ move32(); - output[1][i] = L_sub_sat( output[1][i], tmp_fx ); + output[1][i] = L_sub_sat( output[1][i], tmp_fx ); /* Q11 */ move32(); #else win_in_fx = L_mult( win_dft_fx[mult0( STEREO_DFT32MS_STEP, i )], win_dft_fx[mult0( STEREO_DFT32MS_STEP, i )] ); /* Q31 */ @@ -2315,9 +2315,9 @@ void stereo_icBWE_decproc_fx( tmp_fx = (Word32) W_shr( ( (Word64) hCPE->hStereoDft->td_gain_fx[0] * hCPE->hStereoDft->hb_stefi_sig_fx[i] ), sub( add( (Word16) hCPE->hStereoDft->q_td_gain[0], hCPE->hStereoDft->q_hb_stefi_sig_fx ), q_output ) ); /* Q --> q_output */ #endif #endif - output[0][i] = L_add_sat( output[0][i], tmp_fx ); + output[0][i] = L_add_sat( output[0][i], tmp_fx ); /* Q11 */ move32(); - output[1][i] = L_sub_sat( output[1][i], tmp_fx ); + output[1][i] = L_sub_sat( output[1][i], tmp_fx ); /* Q11 */ move32(); } } @@ -2385,9 +2385,9 @@ void stereo_icBWE_init_dec_fx( /* inter-channel BWE spectral shape adj. */ hStereoICBWE->prevSpecMapping_fx = 0; move16(); - hStereoICBWE->prevgsMapping_fx = 16384; + hStereoICBWE->prevgsMapping_fx = 16384; /* 1.0 in Q14 */ move16(); - hStereoICBWE->icbweM2Ref_prev_fx = 16384; + hStereoICBWE->icbweM2Ref_prev_fx = 16384; /* 1.0 in Q14 */ move16(); hStereoICBWE->prev_spIndx = 0; diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 22ad71a41e268a141291455889e7d30bebfa7b5b..6731b8b0d24484154bd1fcf6fb6d00d3c178116d 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -56,7 +56,7 @@ * Local function prototypes *-------------------------------------------------------------------------*/ -static void apply_dmx_weights_fx( CPE_DEC_HANDLE hCPE, Word32 *x[CPE_CHANNELS][NB_DIV], int16_t transform_type_left[NB_DIV], int16_t transform_type_right[NB_DIV] ); +static void apply_dmx_weights_fx( CPE_DEC_HANDLE hCPE, Word32 *x[CPE_CHANNELS][NB_DIV], Word16 transform_type_left[NB_DIV], Word16 transform_type_right[NB_DIV] ); static void run_min_stats_fx( Decoder_State **sts, Word32 *x[CPE_CHANNELS][NB_DIV], Word16 x_e[CPE_CHANNELS][NB_DIV] ); @@ -69,10 +69,10 @@ static void run_min_stats_fx( Decoder_State **sts, Word32 *x[CPE_CHANNELS][NB_DI *-------------------------------------------------------------------*/ void convert_coeffs_to_higher_res_fx( - const Word32 *in1, /* i : first subframe input */ - const Word32 *in2, /* i : second subframe input */ - Word32 *out, /* o : converted output */ - const Word16 len /* i : length of subframes */ + const Word32 *in1, /* i : first subframe input Qx*/ + const Word32 *in2, /* i : second subframe input Qx*/ + Word32 *out, /* o : converted output Qx*/ + const Word16 len /* i : length of subframes Q0*/ ) { Word16 i; @@ -82,17 +82,17 @@ void convert_coeffs_to_higher_res_fx( { FOR( i = 0; i < len; i += 2 ) { - tmp1 = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); - tmp2 = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); - out[2 * i] = tmp1; + tmp1 = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); /* Qx */ + tmp2 = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); /* Qx */ + out[2 * i] = tmp1; /* Qx */ move32(); - out[2 * i + 1] = tmp2; + out[2 * i + 1] = tmp2; /* Qx */ move32(); - tmp1 = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); - tmp2 = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); - out[2 * i + 2] = tmp1; + tmp1 = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); /* Qx */ + tmp2 = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); /* Qx */ + out[2 * i + 2] = tmp1; /* Qx */ move32(); - out[2 * i + 3] = tmp2; + out[2 * i + 3] = tmp2; /* Qx */ move32(); } } @@ -100,13 +100,13 @@ void convert_coeffs_to_higher_res_fx( { FOR( i = 0; i < len; i += 2 ) { - out[2 * i] = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); + out[2 * i] = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); /* Qx */ move32(); - out[2 * i + 1] = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); + out[2 * i + 1] = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); /* Qx */ move32(); - out[2 * i + 2] = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i + 1], in1[i + 1] ) ) ); + out[2 * i + 2] = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i + 1], in1[i + 1] ) ) ); /* Qx */ move32(); - out[2 * i + 3] = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i + 1], in1[i + 1] ) ) ); + out[2 * i + 3] = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i + 1], in1[i + 1] ) ) ); /* Qx */ move32(); } } @@ -122,8 +122,8 @@ void convert_coeffs_to_higher_res_fx( *-------------------------------------------------------------------*/ static void stereo_mdct_dec_stereo_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word16 ms_mask[2][MAX_SFB] /* o : bandwise MS mask */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word16 ms_mask[2][MAX_SFB] /* o : bandwise MS mask Q0*/ ) { Word16 availableBits; @@ -134,16 +134,16 @@ static void stereo_mdct_dec_stereo_fx( parse_stereo_from_bitstream( hCPE->hStereoMdct, hCPE->hCoreCoder, 0, hCPE->hStereoMdct->isSBAStereoMode, hCPE->hCoreCoder[0], ms_mask ); /*Split available bits between channels */ - availableBits = sub( sub( sub( add( sts[0]->bits_frame_channel, sts[1]->bits_frame_channel ), sts[0]->next_bit_pos ), i_mult( sts[0]->core, ( NF_GAIN_BITS + SMDCT_MINIMUM_ARITH_BITS ) ) ), i_mult( sts[1]->core, ( NF_GAIN_BITS + SMDCT_MINIMUM_ARITH_BITS ) ) ); + availableBits = sub( sub( sub( add( sts[0]->bits_frame_channel, sts[1]->bits_frame_channel ), sts[0]->next_bit_pos ), i_mult( sts[0]->core, ( NF_GAIN_BITS + SMDCT_MINIMUM_ARITH_BITS ) ) ), i_mult( sts[1]->core, ( NF_GAIN_BITS + SMDCT_MINIMUM_ARITH_BITS ) ) ); /* Q0 */ splitAvailableBits_fx( availableBits, hCPE->hStereoMdct->split_ratio, hCPE->hStereoMdct->isSBAStereoMode, &sts[0]->bits_frame_channel, &sts[1]->bits_frame_channel ); - sts[0]->bits_frame_channel = add( sts[0]->bits_frame_channel, i_mult( sts[0]->core, SMDCT_MINIMUM_ARITH_BITS ) ); + sts[0]->bits_frame_channel = add( sts[0]->bits_frame_channel, i_mult( sts[0]->core, SMDCT_MINIMUM_ARITH_BITS ) ); /* Q0 */ move16(); - sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, i_mult( sts[1]->core, SMDCT_MINIMUM_ARITH_BITS ) ); + sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, i_mult( sts[1]->core, SMDCT_MINIMUM_ARITH_BITS ) ); /* Q0 */ move16(); - sts[1]->bit_stream = &sts[0]->bit_stream[add( add( sts[0]->next_bit_pos, sts[0]->bits_frame_channel ), i_mult( sts[0]->core, NF_GAIN_BITS ) )]; + sts[1]->bit_stream = &sts[0]->bit_stream[sts[0]->next_bit_pos + sts[0]->bits_frame_channel + sts[0]->core * NF_GAIN_BITS]; /* Q0 */ return; } @@ -158,8 +158,8 @@ static void stereo_mdct_dec_stereo_fx( void stereo_mdct_core_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *signal_out_fx[CPE_CHANNELS], /* o : synthesis @internal_FS */ - Word16 signal_outFB_fx[CPE_CHANNELS][L_FRAME48k], /* o : synthesis @output_FS */ + Word32 *signal_out_fx[CPE_CHANNELS], /* o : synthesis @internal_FS Q11*/ + Word16 signal_outFB_fx[CPE_CHANNELS][L_FRAME48k], /* o : synthesis @output_FS exp(e_sigFB)*/ Word16 e_sigFB[CPE_CHANNELS] /* o : exponent of synthesis @output_FS */ ) { @@ -213,8 +213,8 @@ void stereo_mdct_core_dec_fx( sts = hCPE->hCoreCoder; st = NULL; - nChannels = CPE_CHANNELS; - bfi = sts[0]->bfi; + nChannels = CPE_CHANNELS; /* Q0 */ + bfi = sts[0]->bfi; /* Q0 */ move16(); FOR( ch = 0; ch < nChannels; ch++ ) @@ -245,7 +245,7 @@ void stereo_mdct_core_dec_fx( set16_fx( ms_mask[1], 0, MAX_SFB ); initMdctStereoDecData_fx( hCPE->hStereoMdct, sts[0]->igf, sts[0]->hIGFDec->igfData.igfInfo.grid, hCPE->element_brate, sts[0]->bwidth ); - hCPE->hStereoMdct->isSBAStereoMode = ( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && EQ_16( st_ivas->nchan_transport, 2 ) ); + hCPE->hStereoMdct->isSBAStereoMode = ( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && EQ_16( st_ivas->nchan_transport, 2 ) ); /* Q0 */ move16(); IF( bfi == 0 ) @@ -265,25 +265,25 @@ void stereo_mdct_core_dec_fx( } ELSE { - Copy( hCPE->hStereoMdct->prev_ms_mask[0], ms_mask[0], MAX_SFB ); - Copy( hCPE->hStereoMdct->prev_ms_mask[1], ms_mask[1], MAX_SFB ); + Copy( hCPE->hStereoMdct->prev_ms_mask[0], ms_mask[0], MAX_SFB ); /* Q0 */ + Copy( hCPE->hStereoMdct->prev_ms_mask[1], ms_mask[1], MAX_SFB ); /* Q0 */ test(); test(); IF( NE_16( sts[0]->core, TCX_10_CORE ) && NE_16( sts[1]->core, TCX_10_CORE ) ) { - hCPE->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO; + hCPE->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO; /* Q0 */ move16(); - hCPE->hStereoMdct->IGFStereoMode[1] = SMDCT_DUAL_MONO; + hCPE->hStereoMdct->IGFStereoMode[1] = SMDCT_DUAL_MONO; /* Q0 */ move16(); } ELSE IF( EQ_16( sts[0]->core, TCX_10_CORE ) && EQ_16( sts[1]->core, TCX_10_CORE ) ) { - hCPE->hStereoMdct->global_ild[0] = hCPE->hStereoMdct->global_ild[1]; + hCPE->hStereoMdct->global_ild[0] = hCPE->hStereoMdct->global_ild[1]; /* Q0 */ move16(); - hCPE->hStereoMdct->mdct_stereo_mode[0] = hCPE->hStereoMdct->mdct_stereo_mode[1]; + hCPE->hStereoMdct->mdct_stereo_mode[0] = hCPE->hStereoMdct->mdct_stereo_mode[1]; /* Q0 */ move16(); - hCPE->hStereoMdct->IGFStereoMode[0] = hCPE->hStereoMdct->IGFStereoMode[1]; + hCPE->hStereoMdct->IGFStereoMode[0] = hCPE->hStereoMdct->IGFStereoMode[1]; /* Q0 */ move16(); } } @@ -309,19 +309,19 @@ void stereo_mdct_core_dec_fx( // Word16 subFrames = ( hCPE->hCoreCoder[ch]->core == TCX_10_CORE ) ? NB_DIV : 1; IF( ( hCPE->hCoreCoder[ch]->core == TCX_10_CORE ) ) { - subFrames = NB_DIV; + subFrames = NB_DIV; /* Q0 */ } ELSE { - subFrames = 1; + subFrames = 1; /* Q0 */ } move16(); FOR( k = 0; k < subFrames; ++k ) { - Scale_sig32( x_fx[ch][k], x_len[ch][k], sub( x_e[ch][k], 20 ) ); + Scale_sig32( x_fx[ch][k], x_len[ch][k], sub( x_e[ch][k], 20 ) ); /* exp(20) */ x_e[ch][k] = 20; move16(); - Scale_sig32( x_0_fx[ch][k], x_len[ch][k], sub( x_0_e[ch][k], 20 ) ); + Scale_sig32( x_0_fx[ch][k], x_len[ch][k], sub( x_0_e[ch][k], 20 ) ); /* exp(20) */ x_0_e[ch][k] = 20; move16(); } @@ -329,12 +329,12 @@ void stereo_mdct_core_dec_fx( FOR( ch = 0; ch < nChannels; ch++ ) { - nSubframes[ch] = EQ_16( sts[ch]->core, TCX_10_CORE ) ? NB_DIV : 1; + nSubframes[ch] = EQ_16( sts[ch]->core, TCX_10_CORE ) ? NB_DIV : 1; /* Q0 */ move16(); FOR( k = 0; k < nSubframes[ch]; k++ ) { - L_spec[ch] = idiv1616( sts[ch]->hTcxCfg->tcx_coded_lines, nSubframes[ch] ); + L_spec[ch] = idiv1616( sts[ch]->hTcxCfg->tcx_coded_lines, nSubframes[ch] ); /* Q0 */ move16(); init_tcx_info_fx( sts[ch], sts[ch]->L_frame / nSubframes[ch], sts[ch]->hTcxDec->L_frameTCX / nSubframes[ch], k, bfi, &tcx_offset[ch], &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] ); @@ -358,7 +358,7 @@ void stereo_mdct_core_dec_fx( { /* mono or dual mono IGF decoding */ decoder_tcx_IGF_mono_fx( st, x_fx[ch][k], &x_e[ch][k], &x_len[ch][k], L_frame[ch], left_rect[ch], bfi, k ); - Scale_sig32( x_fx[ch][k], x_len[ch][k], sub( x_e[ch][k], 20 ) ); + Scale_sig32( x_fx[ch][k], x_len[ch][k], sub( x_e[ch][k], 20 ) ); /* exp(20) */ x_e[ch][k] = 20; move16(); } @@ -379,8 +379,8 @@ void stereo_mdct_core_dec_fx( /* stereo IGF decoding */ decoder_tcx_IGF_stereo_fx( sts, hCPE->hStereoMdct, ms_mask, x_fx, x_e, x_len, L_frame[0], left_rect[0], k, bfi, 0 /* MCT_flag */ ); - Scale_sig32( x_fx[0][k], x_len[0][k], sub( x_e[0][k], 20 ) ); - Scale_sig32( x_fx[1][k], x_len[1][k], sub( x_e[1][k], 20 ) ); + Scale_sig32( x_fx[0][k], x_len[0][k], sub( x_e[0][k], 20 ) ); /* exp(20) */ + Scale_sig32( x_fx[1][k], x_len[1][k], sub( x_e[1][k], 20 ) ); /* exp(20) */ x_e[0][k] = 20; x_e[1][k] = 20; move16(); @@ -393,7 +393,7 @@ void stereo_mdct_core_dec_fx( st = sts[ch]; /* mono or dual mono IGF decoding */ decoder_tcx_IGF_mono_fx( st, x_fx[ch][k], &x_e[ch][k], &x_len[ch][k], L_frame[ch], left_rect[ch], bfi, k ); - Scale_sig32( x_fx[ch][k], x_len[ch][k], sub( x_e[ch][k], 20 ) ); + Scale_sig32( x_fx[ch][k], x_len[ch][k], sub( x_e[ch][k], 20 ) ); /* exp(20) */ x_e[ch][k] = 20; move16(); } @@ -404,7 +404,7 @@ void stereo_mdct_core_dec_fx( FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { - Copy_Scale_sig_16_32( Aq_fx[ch], Aq_fx_32[ch], ( NB_SUBFR16k + 1 ) * ( M + 1 ), sub( Q16, Q12 ) ); + Copy_Scale_sig_16_32( Aq_fx[ch], Aq_fx_32[ch], ( NB_SUBFR16k + 1 ) * ( M + 1 ), sub( Q16, Q12 ) ); /* Q16 */ } /*--------------------------------------------------------------------------------* @@ -439,15 +439,15 @@ void stereo_mdct_core_dec_fx( move16(); } Word16 s = getScaleFactor32( x_fx[ch][k], L_frameTCX[ch] ); - Scale_sig32( x_fx[ch][k], L_frameTCX[ch], s ); + Scale_sig32( x_fx[ch][k], L_frameTCX[ch], s ); /* exp(x_e + 31 - s) */ TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx[ch][k], sub( x_e[ch][k], s ), L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); - Scale_sig32( x_fx[ch][k], L_frameTCX[ch], negate( s ) ); + Scale_sig32( x_fx[ch][k], L_frameTCX[ch], negate( s ) ); /* exp(x_e) */ } } IF( ( st->hTcxDec->tcxltp_last_gain_unmodified > 0 ) ) { - L_tmp = st->old_fpitch; + L_tmp = st->old_fpitch; /* 15Q16 */ } ELSE { @@ -459,8 +459,8 @@ void stereo_mdct_core_dec_fx( TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX[ch], L_tmp, bfi, bfi && st->tonal_mdct_plc_active ); } - Copy( ms_mask[0], hCPE->hStereoMdct->prev_ms_mask[0], MAX_SFB ); - Copy( ms_mask[1], hCPE->hStereoMdct->prev_ms_mask[1], MAX_SFB ); + Copy( ms_mask[0], hCPE->hStereoMdct->prev_ms_mask[0], MAX_SFB ); /* Q0 */ + Copy( ms_mask[1], hCPE->hStereoMdct->prev_ms_mask[1], MAX_SFB ); /* Q0 */ } test(); @@ -490,12 +490,12 @@ void stereo_mdct_core_dec_fx( nSubFrames = NB_DIV; } move16(); - Scale_sig32( x_fx[ind][0], shr( L_FRAME_MAX, sub( nSubFrames, 1 ) ), sub( x_e[ind][0], 20 ) ); + Scale_sig32( x_fx[ind][0], shr( L_FRAME_MAX, sub( nSubFrames, 1 ) ), sub( x_e[ind][0], 20 ) ); /* exp(20) */ x_e[ind][0] = 20; move16(); IF( EQ_16( nSubFrames, 2 ) ) { - Scale_sig32( x_fx[ind][1], shr( L_FRAME_MAX, 1 ), sub( x_e[ind][1], 20 ) ); + Scale_sig32( x_fx[ind][1], shr( L_FRAME_MAX, 1 ), sub( x_e[ind][1], 20 ) ); /* exp(20) */ x_e[ind][1] = 20; move16(); } @@ -531,34 +531,34 @@ void stereo_mdct_core_dec_fx( s = sub( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); move16(); } - scale_sig32( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, s ); + scale_sig32( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, s ); /* s */ sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, s ); } test(); IF( sts[ch]->hFdCngDec && sts[ch]->hFdCngDec->hFdCngCom ) { - sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); + sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); /* 16 - q_likelihood_noisy_speech */ } test(); test(); IF( sts[ch]->igf != 0 && sts[ch]->hIGFDec && sts[ch]->hIGFDec->virtualSpec_fx ) { - Scale_sig32( sts[ch]->hIGFDec->virtualSpec_fx + sub( sts[ch]->hIGFDec->infoIGFStartLine, IGF_START_MN ), s_min( sub( sts[ch]->hIGFDec->infoIGFStopLine, sts[ch]->hIGFDec->infoIGFStartLine ), 856 ), sub( sts[ch]->hIGFDec->virtualSpec_e, x_e[ch][0] ) ); + Scale_sig32( sts[ch]->hIGFDec->virtualSpec_fx + sub( sts[ch]->hIGFDec->infoIGFStartLine, IGF_START_MN ), s_min( sub( sts[ch]->hIGFDec->infoIGFStopLine, sts[ch]->hIGFDec->infoIGFStartLine ), 856 ), sub( sts[ch]->hIGFDec->virtualSpec_e, x_e[ch][0] ) ); /* x_e */ sts[ch]->hIGFDec->virtualSpec_e = x_e[ch][0]; move16(); } } - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, M + 1, ( 28 - norm_s( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0] - 1 ) ) ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, M + 1, ( 28 - norm_s( hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0] - 1 ) ) ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, M + 1, ( 28 - norm_s( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0] - 1 ) ) ); /* Q28 */ + Copy_Scale_sig_16_32( hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, M + 1, ( 28 - norm_s( hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0] - 1 ) ) ); /* Q28 */ ivas_mdct_core_reconstruct_fx( hCPE, x_fx, signal_outFB_tmp_fx, fUseTns, 0, Q11, e_sigFB ); - Copy32( signal_out_tmp_fx[0], signal_out_fx[0], L_FRAME48k ); - Copy32( signal_out_tmp_fx[1], signal_out_fx[1], L_FRAME48k ); + Copy32( signal_out_tmp_fx[0], signal_out_fx[0], L_FRAME48k ); /* Q11 */ + Copy32( signal_out_tmp_fx[1], signal_out_fx[1], L_FRAME48k ); /* Q11 */ - Copy( signal_outFB_tmp_fx[0], signal_outFB_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX ); - Copy( signal_outFB_tmp_fx[1], signal_outFB_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX ); + Copy( signal_outFB_tmp_fx[0], signal_outFB_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX ); /* exp(e_sigFB) */ + Copy( signal_outFB_tmp_fx[1], signal_outFB_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX ); /* exp(e_sigFB) */ pop_wmops(); return; @@ -573,9 +573,9 @@ void stereo_mdct_core_dec_fx( static void apply_dmx_weights_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *x[CPE_CHANNELS][NB_DIV], /* i/o: MDCT Spectrum */ - Word16 transform_type_left[NB_DIV], /* i : indicate TCX5 for left ch */ - Word16 transform_type_right[NB_DIV] /* i : indicate TCX5 for right ch */ + Word32 *x[CPE_CHANNELS][NB_DIV], /* i/o: MDCT Spectrum Q11*/ + Word16 transform_type_left[NB_DIV], /* i : indicate TCX5 for left ch Q0*/ + Word16 transform_type_right[NB_DIV] /* i : indicate TCX5 for right ch Q0*/ ) { Word16 b, k, l, i, ch; @@ -589,18 +589,18 @@ static void apply_dmx_weights_fx( Word32 convertRes[CPE_CHANNELS][L_FRAME48k]; Word32 *sig[CPE_CHANNELS][NB_DIV], *pTmp[CPE_CHANNELS][NB_DIV]; - nChannels = CPE_CHANNELS; + nChannels = CPE_CHANNELS; /* Q0 */ move16(); - frameSize = hCPE->hStereoMdct->stbParamsTCX20.sfbOffset[hCPE->hStereoMdct->stbParamsTCX20.sfbCnt]; + frameSize = hCPE->hStereoMdct->stbParamsTCX20.sfbOffset[hCPE->hStereoMdct->stbParamsTCX20.sfbCnt]; /* Q0 */ move16(); - transform_type[0][0] = transform_type_left[0]; + transform_type[0][0] = transform_type_left[0]; /* Q0 */ move16(); - transform_type[0][1] = transform_type_left[1]; + transform_type[0][1] = transform_type_left[1]; /* Q0 */ move16(); - transform_type[1][0] = transform_type_right[0]; + transform_type[1][0] = transform_type_right[0]; /* Q0 */ move16(); - transform_type[1][1] = transform_type_right[1]; + transform_type[1][1] = transform_type_right[1]; /* Q0 */ move16(); /* set overall frequency resolution of (sub)frame to maximum of (sub)frame, requires conversion if both channels are not the same */ @@ -610,7 +610,7 @@ static void apply_dmx_weights_fx( { /* use TCX20 band config for TCX20 in both channels and mixed frames */ sfbConf = &hCPE->hStereoMdct->stbParamsTCX20; - nsub = nsub2[0] = nsub2[1] = 1; /* overall TCX 20 */ + nsub = nsub2[0] = nsub2[1] = 1; /* overall TCX 20 Q0*/ move16(); move16(); move16(); @@ -621,34 +621,34 @@ static void apply_dmx_weights_fx( { /* use TCX10 band config only if none of the channels is TCX20 */ sfbConf = &hCPE->hStereoMdct->stbParamsTCX10; - nsub = 2; + nsub = 2; /* Q0 */ move16(); /* set resolution per subframe, subdivide again if subframe is TCX5 in both channels */ // nsub2[0] = ( transform_type[0][0] == TCX_5 && transform_type[1][0] == TCX_5 ) ? 2 : 1; test(); IF( EQ_16( transform_type[0][0], TCX_5 ) && EQ_16( transform_type[1][0], TCX_5 ) ) { - nsub2[0] = 2; + nsub2[0] = 2; /* Q0 */ move16(); } ELSE { - nsub2[0] = 1; + nsub2[0] = 1; /* Q0 */ move16(); } // nsub2[1] = ( transform_type[0][1] == TCX_5 && transform_type[1][1] == TCX_5 ) ? 2 : 1; test(); IF( EQ_16( transform_type[0][1], TCX_5 ) && EQ_16( transform_type[1][1], TCX_5 ) ) { - nsub2[1] = 2; + nsub2[1] = 2; /* Q0 */ move16(); } ELSE { - nsub2[1] = 1; + nsub2[1] = 1; /* Q0 */ move16(); } - tcx_10_only = 1; + tcx_10_only = 1; /* Q0 */ move16(); } @@ -656,26 +656,26 @@ static void apply_dmx_weights_fx( // numCoeffs[0] = ( nsub2[0] == 1 ) ? sfbConf->sfbOffset[sfbConf->sfbCnt] : sfbConf->sfbOffset[sfbConf->sfbCnt] / 2; IF( EQ_16( nsub2[0], 1 ) ) { - numCoeffs[0] = sfbConf->sfbOffset[sfbConf->sfbCnt]; + numCoeffs[0] = sfbConf->sfbOffset[sfbConf->sfbCnt]; /* Q0 */ } ELSE { - numCoeffs[0] = shr( sfbConf->sfbOffset[sfbConf->sfbCnt], 1 ); + numCoeffs[0] = shr( sfbConf->sfbOffset[sfbConf->sfbCnt], 1 ); /* Q0 */ } // numCoeffs[1] = ( nsub2[1] == 1 ) ? sfbConf->sfbOffset[sfbConf->sfbCnt] : sfbConf->sfbOffset[sfbConf->sfbCnt] / 2; IF( EQ_16( nsub2[1], 1 ) ) { - numCoeffs[1] = sfbConf->sfbOffset[sfbConf->sfbCnt]; + numCoeffs[1] = sfbConf->sfbOffset[sfbConf->sfbCnt]; /* Q0 */ } ELSE { - numCoeffs[1] = shr( sfbConf->sfbOffset[sfbConf->sfbCnt], 1 ); + numCoeffs[1] = shr( sfbConf->sfbOffset[sfbConf->sfbCnt], 1 ); /* Q0 */ } /* initially, set pointers to input; if conversion occurs in (sub)frame, set to convertRes */ - sig[0][0] = pTmp[0][0] = x[0][0]; - sig[0][1] = pTmp[0][1] = x[0][1]; - sig[1][0] = pTmp[1][0] = x[1][0]; - sig[1][1] = pTmp[1][1] = x[1][1]; + sig[0][0] = pTmp[0][0] = x[0][0]; /* Q11 */ + sig[0][1] = pTmp[0][1] = x[0][1]; /* Q11 */ + sig[1][0] = pTmp[1][0] = x[1][0]; /* Q11 */ + sig[1][1] = pTmp[1][1] = x[1][1]; /* Q11 */ /* convert (sub)frames to higher frequency resolution */ FOR( ch = 0; ch < nChannels; ch++ ) @@ -686,7 +686,7 @@ static void apply_dmx_weights_fx( IF( EQ_16( transform_type[ch][k], TCX_5 ) && EQ_16( nsub2[k], 1 ) ) { /* subframe is TCX5, but TCX10 or TCX20 in other channel -> convert channel with TCX5 to TCX10 resolution */ - pTmp[ch][k] = sig[ch][k] = convertRes[ch] + i_mult( k, shr( frameSize, 1 ) ); + pTmp[ch][k] = sig[ch][k] = convertRes[ch] + i_mult( k, shr( frameSize, 1 ) ); /* Q11 */ convert_coeffs_to_higher_res_fx( x[ch][k], x[ch][k] + shr( frameSize, 2 ), pTmp[ch][k], shr( frameSize, 2 ) ); } } @@ -695,7 +695,7 @@ static void apply_dmx_weights_fx( IF( NE_16( transform_type[ch][0], TCX_20 ) && EQ_16( nsub, 1 ) ) { /* TCX20 and TCX10 in same frame -> convert channel with TCX10 to TCX20 resolution */ - sig[ch][0] = convertRes[ch]; + sig[ch][0] = convertRes[ch]; /* Q11 */ convert_coeffs_to_higher_res_fx( pTmp[ch][0], pTmp[ch][1], sig[ch][0], shr( frameSize, 1 ) ); } } @@ -708,12 +708,12 @@ static void apply_dmx_weights_fx( FOR( l = 0; l < nsub2[k]; l++ ) { // mdst[ch][k][l * numCoeffs[k]] = mdst[ch][k][( l + 1 ) * numCoeffs[k] - 1] = 0.f; - mdst[ch][k][i_mult( l, numCoeffs[k] )] = mdst[ch][k][sub( i_mult( add( l, 1 ), numCoeffs[k] ), 1 )] = 0; + mdst[ch][k][l * numCoeffs[k]] = mdst[ch][k][( l + 1 ) * numCoeffs[k] - 1] = 0; /* Q11 */ move32(); move32(); FOR( i = l * numCoeffs[k] + 1; i < ( l + 1 ) * numCoeffs[k] - 1; i++ ) { - mdst[ch][k][i] = L_sub( sig[ch][k][i + 1], sig[ch][k][i - 1] ); + mdst[ch][k][i] = L_sub( sig[ch][k][i + 1], sig[ch][k][i - 1] ); /* Q11 */ move32(); } } @@ -748,10 +748,10 @@ static void apply_dmx_weights_fx( } ELSE { - val_div = idiv1616( sfbConf->sfbOffset[b], nsub2[k] ); + val_div = idiv1616( sfbConf->sfbOffset[b], nsub2[k] ); /* Q0 */ move16(); } - start = add( i_mult( l, numCoeffs[k] ), val_div ); + start = add( i_mult( l, numCoeffs[k] ), val_div ); /* Q0 */ IF( sfbConf->sfbOffset[b + 1] == 0 ) { @@ -760,19 +760,19 @@ static void apply_dmx_weights_fx( } ELSE { - val_div = idiv1616( sfbConf->sfbOffset[b + 1], nsub2[k] ); + val_div = idiv1616( sfbConf->sfbOffset[b + 1], nsub2[k] ); /* Q0 */ move16(); } - stop = add( i_mult( l, numCoeffs[k] ), val_div ); + stop = add( i_mult( l, numCoeffs[k] ), val_div ); /* Q0 */ /* compute band energies and cross correlation */ FOR( i = start; i < stop; i++ ) { - sum_nrg_L = W_add( sum_nrg_L, W_add( W_mult_32_32( sig[0][k][i], sig[0][k][i] ), W_mult_32_32( mdst[0][k][i], mdst[0][k][i] ) ) ); - sum_nrg_R = W_add( sum_nrg_R, W_add( W_mult_32_32( sig[1][k][i], sig[1][k][i] ), W_mult_32_32( mdst[1][k][i], mdst[1][k][i] ) ) ); - dot_prod_real = W_add( dot_prod_real, W_add( W_mult_32_32( sig[0][k][i], sig[1][k][i] ), W_mult_32_32( mdst[0][k][i], mdst[1][k][i] ) ) ); - dot_prod_imag = W_add( dot_prod_imag, W_sub( W_mult_32_32( mdst[0][k][i], sig[1][k][i] ), W_mult_32_32( sig[0][k][i], mdst[1][k][i] ) ) ); + sum_nrg_L = W_add( sum_nrg_L, W_add( W_mult_32_32( sig[0][k][i], sig[0][k][i] ), W_mult_32_32( mdst[0][k][i], mdst[0][k][i] ) ) ); /* Q23 */ + sum_nrg_R = W_add( sum_nrg_R, W_add( W_mult_32_32( sig[1][k][i], sig[1][k][i] ), W_mult_32_32( mdst[1][k][i], mdst[1][k][i] ) ) ); /* Q23 */ + dot_prod_real = W_add( dot_prod_real, W_add( W_mult_32_32( sig[0][k][i], sig[1][k][i] ), W_mult_32_32( mdst[0][k][i], mdst[1][k][i] ) ) ); /* Q23 */ + dot_prod_imag = W_add( dot_prod_imag, W_sub( W_mult_32_32( mdst[0][k][i], sig[1][k][i] ), W_mult_32_32( sig[0][k][i], mdst[1][k][i] ) ) ); /* Q23 */ } Word16 norm_sum_nrg_L = Q31; @@ -803,10 +803,10 @@ static void apply_dmx_weights_fx( Word16 guard_bit = find_guarded_bits_fx( 4 ); Word16 min_norm = sub( s_min( s_min( s_min( norm_sum_nrg_L, norm_sum_nrg_R ), norm_dot_prod_real ), norm_dot_prod_imag ), guard_bit ); - Word32 sum_nrg_L_32 = W_extract_h( W_shl( sum_nrg_L, min_norm ) ); - Word32 sum_nrg_R_32 = W_extract_h( W_shl( sum_nrg_R, min_norm ) ); - Word32 dot_prod_real_32 = W_extract_h( W_shl( dot_prod_real, min_norm ) ); - Word32 dot_prod_imag_32 = W_extract_h( W_shl( dot_prod_imag, min_norm ) ); + Word32 sum_nrg_L_32 = W_extract_h( W_shl( sum_nrg_L, min_norm ) ); /* Q23 + min_norm - 32 */ + Word32 sum_nrg_R_32 = W_extract_h( W_shl( sum_nrg_R, min_norm ) ); /* Q23 + min_norm - 32 */ + Word32 dot_prod_real_32 = W_extract_h( W_shl( dot_prod_real, min_norm ) ); /* Q23 + min_norm - 32 */ + Word32 dot_prod_imag_32 = W_extract_h( W_shl( dot_prod_imag, min_norm ) ); /* Q23 + min_norm - 32 */ Word16 q_sum_nrg_L = sub( add( 23, min_norm ), 32 ); Word16 q_sum_nrg_R = sub( add( 23, min_norm ), 32 ); @@ -816,7 +816,7 @@ static void apply_dmx_weights_fx( Word16 E_sum_nrg_R = sub( 31, q_sum_nrg_R ); Word16 E_dot_prod_abs = sub( 31, sub( shl( q_dot_prod_real, 1 ), 31 ) ); Word16 E_sum_nrg_Mid = sub( 31, q_sum_nrg_L ); - sum_nrg_Mid = L_max( 0, L_add( L_add( sum_nrg_L_32, sum_nrg_R_32 ), L_shl( dot_prod_real_32, 1 ) ) ); + sum_nrg_Mid = L_max( 0, L_add( L_add( sum_nrg_L_32, sum_nrg_R_32 ), L_shl( dot_prod_real_32, 1 ) ) ); /* Q23 + min_norm - 32 */ Word32 tmp_nrg_L = Sqrt32( sum_nrg_L_32, &E_sum_nrg_l ); Word32 tmp_nrg_R = Sqrt32( sum_nrg_R_32, &E_sum_nrg_R ); Word16 max_e_sum_abs = E_sum_nrg_l; @@ -827,9 +827,9 @@ static void apply_dmx_weights_fx( move16(); } max_e_sum_abs = add( max_e_sum_abs, 1 ); - sum_abs = L_add( L_shr( tmp_nrg_L, max_e_sum_abs - E_sum_nrg_l ), L_shr( tmp_nrg_R, max_e_sum_abs - E_sum_nrg_R ) ); - dot_prod_abs = Sqrt32( L_add( Mpy_32_32( dot_prod_real_32, dot_prod_real_32 ), Mpy_32_32( dot_prod_imag_32, dot_prod_imag_32 ) ), &E_dot_prod_abs ); - Word32 num = L_add( L_shr( L_add( sum_nrg_L_32, sum_nrg_R_32 ), 1 ), L_shr( dot_prod_abs, ( 31 - E_dot_prod_abs ) - q_sum_nrg_L ) ); + sum_abs = L_add( L_shr( tmp_nrg_L, max_e_sum_abs - E_sum_nrg_l ), L_shr( tmp_nrg_R, max_e_sum_abs - E_sum_nrg_R ) ); /* E_sum_nrg_R */ + dot_prod_abs = Sqrt32( L_add( Mpy_32_32( dot_prod_real_32, dot_prod_real_32 ), Mpy_32_32( dot_prod_imag_32, dot_prod_imag_32 ) ), &E_dot_prod_abs ); /* E_dot_prod_abs */ + Word32 num = L_add( L_shr( L_add( sum_nrg_L_32, sum_nrg_R_32 ), 1 ), L_shr( dot_prod_abs, ( 31 - E_dot_prod_abs ) - q_sum_nrg_L ) ); /* 31 - q_sum_nrg_L */ Word16 E_num = sub( 31, q_sum_nrg_L ); Word32 num_sqrt = Sqrt32( num, &E_num ); @@ -855,7 +855,7 @@ static void apply_dmx_weights_fx( } ELSE { - full_w_up = shr( divide3232( L_shr( num_sqrt, sub( e_full_w, E_num ) ), L_shr( sum_abs, sub( e_full_w, max_e_sum_abs ) ) ), 2 ); + full_w_up = shr( divide3232( L_shr( num_sqrt, sub( e_full_w, E_num ) ), L_shr( sum_abs, sub( e_full_w, max_e_sum_abs ) ) ), 2 ); // Q13 } Word32 sum_nrg_Mid_sqrt = Sqrt32( sum_nrg_Mid, &E_sum_nrg_Mid ); @@ -872,7 +872,7 @@ static void apply_dmx_weights_fx( test(); IF( sum_nrg_Mid_sqrt == 0 && sum_abs == 0 ) { - full_w_down = 16384; + full_w_down = 16384; /* 1.0f in Q14 */ move16(); } ELSE IF( sum_nrg_Mid_sqrt == 0 && sum_abs != 0 ) @@ -882,21 +882,21 @@ static void apply_dmx_weights_fx( } ELSE { - full_w_down = shr( divide3232( L_shr( sum_nrg_Mid_sqrt, sub( e_full_down, E_sum_nrg_Mid ) ), L_shr( sum_abs, sub( e_full_down, max_e_sum_abs ) ) ), 1 ); + full_w_down = shr( divide3232( L_shr( sum_nrg_Mid_sqrt, sub( e_full_down, E_sum_nrg_Mid ) ), L_shr( sum_abs, sub( e_full_down, max_e_sum_abs ) ) ), 1 ); /* Q14 */ } IF( hCPE->hStereoMdct->reverse_dmx == 0 ) { - w[1][add( 2 * k, l )] = full_w_up; + w[1][2 * k + l] = full_w_up; /* Q13 */ move16(); - w[0][add( 2 * k, l )] = add( w[1][add( 2 * k, l )], mult( 23170 /*sqrt(2.0f in Q14)*/, sub( 16384 /* 1.0f in Q14 */, full_w_down ) ) ); + w[0][2 * k + l] = add( w[1][2 * k + l], mult( 23170 /*sqrt(2.0f in Q14)*/, sub( 16384 /* 1.0f in Q14 */, full_w_down ) ) ); /* Q13 */ move16(); } ELSE { - w[0][add( 2 * k, l )] = full_w_up; + w[0][2 * k + l] = full_w_up; /* Q13 */ move16(); - w[1][add( 2 * k, l )] = add( w[0][add( 2 * k, l )], mult( 23170 /*sqrt(2.0f in Q14)*/, sub( 16384 /* 1.0f in Q14 */, full_w_down ) ) ); + w[1][2 * k + l] = add( w[0][2 * k + l], mult( 23170 /*sqrt(2.0f in Q14)*/, sub( 16384 /* 1.0f in Q14 */, full_w_down ) ) ); /* Q13 */ move16(); } } @@ -909,20 +909,20 @@ static void apply_dmx_weights_fx( { FOR( i = sfbConf->sfbOffset[b]; i < sfbConf->sfbOffset[b + 1]; i++ ) { - x[ch][0][i] = L_shl( Mpy_32_16_1( x[ch][0][i], w[ch][0] ), 2 ); + x[ch][0][i] = L_shl( Mpy_32_16_1( x[ch][0][i], w[ch][0] ), 2 ); /* Q11 */ move32(); } } ELSE { - start = sfbConf->sfbOffset[b]; + start = sfbConf->sfbOffset[b]; /* Q0 */ move16(); - stop = sfbConf->sfbOffset[b + 1]; + stop = sfbConf->sfbOffset[b + 1]; /* Q0 */ move16(); IF( !tcx_10_only ) /* TCX20 band config is used */ { - start = shr( start, 1 ); - stop = shr( stop, 1 ); + start = shr( start, 1 ); /* Q0 */ + stop = shr( stop, 1 ); /* Q0 */ } FOR( k = 0; k < NB_DIV; k++ ) @@ -935,7 +935,7 @@ static void apply_dmx_weights_fx( } ELSE { - w_idx = shl( k, 1 ); + w_idx = shl( k, 1 ); /* Q0 */ move16(); } @@ -943,30 +943,30 @@ static void apply_dmx_weights_fx( { FOR( i = start; i < stop; i++ ) { - x[ch][k][i] = L_shl( Mpy_32_16_1( x[ch][k][i], w[ch][w_idx] ), 2 ); + x[ch][k][i] = L_shl( Mpy_32_16_1( x[ch][k][i], w[ch][w_idx] ), 2 ); /* Q11 */ move32(); } } ELSE /* TCX_5 */ { - start_tcx5 = stop_tcx5; + start_tcx5 = stop_tcx5; /* Q0 */ move16(); - stop_tcx5 = shr( add( stop, 1 ), 1 ); + stop_tcx5 = shr( add( stop, 1 ), 1 ); /* Q0 */ FOR( i = start_tcx5; i < stop_tcx5; i++ ) { - x[ch][k][i] = L_shl( Mpy_32_16_1( x[ch][k][i], w[ch][w_idx] ), 2 ); + x[ch][k][i] = L_shl( Mpy_32_16_1( x[ch][k][i], w[ch][w_idx] ), 2 ); /* Q11 */ move32(); } IF( EQ_16( nsub2[k], 2 ) ) { - w_idx = add( w_idx, 1 ); + w_idx = add( w_idx, 1 ); /* Q0 */ } FOR( i = start_tcx5; i < stop_tcx5; i++ ) { - x[ch][k][add( i, shr( frameSize, 2 ) )] = L_shl( Mpy_32_16_1( x[ch][k][add( i, shr( frameSize, 2 ) )], w[ch][w_idx] ), 2 ); + x[ch][k][i + ( frameSize >> 2 )] = L_shl( Mpy_32_16_1( x[ch][k][i + ( frameSize >> 2 )], w[ch][w_idx] ), 2 ); /* Q11 */ move32(); } } @@ -988,7 +988,7 @@ static void apply_dmx_weights_fx( static void run_min_stats_fx( Decoder_State **sts, - Word32 *x[CPE_CHANNELS][NB_DIV], /* i/o: MDCT Spectrum */ + Word32 *x[CPE_CHANNELS][NB_DIV], /* i/o: MDCT Spectrum exp(x_e)*/ Word16 x_e[CPE_CHANNELS][NB_DIV] ) { Word16 ch, will_estimate_noise_on_channel[CPE_CHANNELS], save_VAD[CPE_CHANNELS]; @@ -1000,16 +1000,16 @@ static void run_min_stats_fx( /* Check if the minimum statistics would run on the respective channels. They are run on inactive TCX20 channels */ test(); test(); - will_estimate_noise_on_channel[0] = EQ_16( sts[0]->core, TCX_20_CORE ) && !sts[0]->VAD; - will_estimate_noise_on_channel[1] = EQ_16( sts[1]->core, TCX_20_CORE ) && !sts[1]->VAD; + will_estimate_noise_on_channel[0] = EQ_16( sts[0]->core, TCX_20_CORE ) && !sts[0]->VAD; /* Q0 */ + will_estimate_noise_on_channel[1] = EQ_16( sts[1]->core, TCX_20_CORE ) && !sts[1]->VAD; /* Q0 */ test(); test(); move16(); move16(); - save_VAD[0] = sts[0]->VAD; + save_VAD[0] = sts[0]->VAD; /* Q0 */ move16(); - save_VAD[1] = sts[1]->VAD; + save_VAD[1] = sts[1]->VAD; /* Q0 */ move16(); /* The first loop calculates the power spectra needed in the minimum statistics (MS) noise estimation. This is only needed if the MS @@ -1030,13 +1030,13 @@ static void run_min_stats_fx( otherwise, use other channel's signal */ IF( will_estimate_noise_on_channel[ch] ) { - spec_in = &x[ch][0][0]; + spec_in = &x[ch][0][0]; /* exp(x_e) */ spec_e = x_e[ch][0]; move16(); } ELSE { - spec_in = &x[( ch + 1 ) % 2][0][0]; + spec_in = &x[( ch + 1 ) % 2][0][0]; /* exp(x_e) */ spec_e = x_e[( ch + 1 ) % 2][0]; move16(); /* patch VAD to zero so that estimation runs, will later be restored */ @@ -1062,15 +1062,15 @@ static void run_min_stats_fx( power_spec_e = sub( add( 4, shl( spec_e, 1 ) ), tmp16 ); } - Copy_Scale_sig32_16( power_spec, power_spec_16, L_FRAME16k, 0 ); + Copy_Scale_sig32_16( power_spec, power_spec_16, L_FRAME16k, 0 ); /* exp(power_spec_e) */ noisy_speech_detection_fx( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, power_spec_16, sub( 15, power_spec_e ) ); - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), Mpy_32_32( st->hFdCngDec->hFdCngCom->flag_noisy_speech, Q31_0_01 ) ); - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), Mpy_32_32( st->hFdCngDec->hFdCngCom->flag_noisy_speech, Q31_0_01 ) ); /* q_likelihood_noisy_speech */ + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); /* q_likelihood_noisy_speech - 16 */ move32(); move32(); - st->lp_noise = st->hFdCngDec->lp_noise; + st->lp_noise = st->hFdCngDec->lp_noise; /* Q9.23 */ move32(); } @@ -1092,7 +1092,7 @@ static void run_min_stats_fx( } /* restore VAD (see above) */ - st->VAD = save_VAD[ch]; + st->VAD = save_VAD[ch]; /* Q0 */ move16(); } diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec.c b/lib_dec/ivas_stereo_mdct_stereo_dec.c index d0fefa50cde9f2193e637b69e24f96184366a800..b83432db3feb3a2ef1edeb2c1136b5f57cb57882 100644 --- a/lib_dec/ivas_stereo_mdct_stereo_dec.c +++ b/lib_dec/ivas_stereo_mdct_stereo_dec.c @@ -346,12 +346,12 @@ void stereo_decoder_tcx( *-------------------------------------------------------------------*/ void parse_stereo_from_bitstream( - STEREO_MDCT_DEC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo decoder structure */ - Decoder_State **sts, /* i/o: decoder state structure */ - const Word16 mct_on, /* i : flag mct block (1) or stereo (0)*/ - const Word16 isSBAStereoMode, /* i : flag core coding for SBA */ - Decoder_State *st0, /* i/o: decoder state structure for Bstr*/ - Word16 ms_mask[NB_DIV][MAX_SFB] /* o : bandwise MS mask */ + STEREO_MDCT_DEC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo decoder structure */ + Decoder_State **sts, /* i/o: decoder state structure */ + const Word16 mct_on, /* i : flag mct block (1) or stereo (0) Q0*/ + const Word16 isSBAStereoMode, /* i : flag core coding for SBA Q0*/ + Decoder_State *st0, /* i/o: decoder state structure for Bstr */ + Word16 ms_mask[NB_DIV][MAX_SFB] /* o : bandwise MS mask Q0*/ ) { Word16 i, k, nSubframes, mdct_stereo_mode; @@ -363,12 +363,12 @@ void parse_stereo_from_bitstream( test(); IF( ( EQ_16( sts[0]->core, TCX_10_CORE ) || ( NE_16( sts[0]->core, sts[1]->core ) ) ) ) { - nSubframes = NB_DIV; + nSubframes = NB_DIV; /* Q0 */ move16(); } ELSE { - nSubframes = 1; + nSubframes = 1; /* Q0 */ move16(); } move16(); @@ -390,8 +390,8 @@ void parse_stereo_from_bitstream( { Word16 I; - hStereoMdct->itd_mode = extract_l( get_next_indice_fx( st0, STEREO_DFT_ITD_MODE_NBITS ) ); - /*(*nb_bits) += STEREO_DFT_ITD_MODE_NBITS;*/ /*ITD mode flag: 1bit*/ + hStereoMdct->itd_mode = extract_l( get_next_indice_fx( st0, STEREO_DFT_ITD_MODE_NBITS ) ); /* Q0 */ + /*(*nb_bits) += STEREO_DFT_ITD_MODE_NBITS;*/ /*ITD mode flag: 1bit*/ hStereoMdct->itd_fx = 0; move32(); @@ -404,23 +404,23 @@ void parse_stereo_from_bitstream( FOR( k = 0; k < nSubframes; k++ ) { - mdct_stereo_mode = extract_l( get_next_indice_fx( st0, 1 ) ); + mdct_stereo_mode = extract_l( get_next_indice_fx( st0, 1 ) ); /* Q0 */ IF( mdct_stereo_mode ) { - mdct_stereo_mode = add( 1, extract_l( get_next_indice_fx( st0, 1 ) ) ); + mdct_stereo_mode = add( 1, extract_l( get_next_indice_fx( st0, 1 ) ) ); /* Q0 */ } SWITCH( mdct_stereo_mode ) { case 0: - hStereoMdct->mdct_stereo_mode[k] = SMDCT_DUAL_MONO; + hStereoMdct->mdct_stereo_mode[k] = SMDCT_DUAL_MONO; /* Q0 */ move16(); BREAK; case 1: - hStereoMdct->mdct_stereo_mode[k] = SMDCT_MS_FULL; + hStereoMdct->mdct_stereo_mode[k] = SMDCT_MS_FULL; /* Q0 */ move16(); BREAK; case 2: - hStereoMdct->mdct_stereo_mode[k] = SMDCT_BW_MS; + hStereoMdct->mdct_stereo_mode[k] = SMDCT_BW_MS; /* Q0 */ move16(); BREAK; default: @@ -432,13 +432,13 @@ void parse_stereo_from_bitstream( test(); IF( EQ_16( sts[0]->core, sts[1]->core ) || k == 0 ) { - hStereoMdct->global_ild[k] = extract_l( get_next_indice_fx( st0, SMDCT_GLOBAL_ILD_BITS ) ); + hStereoMdct->global_ild[k] = extract_l( get_next_indice_fx( st0, SMDCT_GLOBAL_ILD_BITS ) ); /* Q0 */ move16(); assert( ( GT_16( hStereoMdct->global_ild[k], 0 ) ) && ( LT_16( hStereoMdct->global_ild[k], SMDCT_ILD_RANGE ) ) ); } ELSE { - hStereoMdct->global_ild[1] = hStereoMdct->global_ild[0]; + hStereoMdct->global_ild[1] = hStereoMdct->global_ild[0]; /* Q0 */ move16(); } } @@ -457,7 +457,7 @@ void parse_stereo_from_bitstream( { FOR( i = 0; i < sfbConf->nBandsStereoCore; i++ ) { - ms_mask[k][i] = extract_l( get_next_indice_fx( st0, 1 ) ); + ms_mask[k][i] = extract_l( get_next_indice_fx( st0, 1 ) ); /* Q0 */ move16(); } } @@ -467,21 +467,21 @@ void parse_stereo_from_bitstream( mdct_stereo_mode = extract_l( get_next_indice_fx( st0, 1 ) ); IF( mdct_stereo_mode ) { - mdct_stereo_mode = add( 1, extract_l( get_next_indice_fx( st0, 1 ) ) ); + mdct_stereo_mode = add( 1, extract_l( get_next_indice_fx( st0, 1 ) ) ); /* Q0 */ } SWITCH( mdct_stereo_mode ) { case 0: - hStereoMdct->IGFStereoMode[k] = SMDCT_DUAL_MONO; + hStereoMdct->IGFStereoMode[k] = SMDCT_DUAL_MONO; /* Q0 */ move16(); BREAK; case 1: - hStereoMdct->IGFStereoMode[k] = SMDCT_MS_FULL; + hStereoMdct->IGFStereoMode[k] = SMDCT_MS_FULL; /* Q0 */ move16(); BREAK; case 2: - hStereoMdct->IGFStereoMode[k] = SMDCT_BW_MS; + hStereoMdct->IGFStereoMode[k] = SMDCT_BW_MS; /* Q0 */ move16(); BREAK; default: @@ -502,14 +502,14 @@ void parse_stereo_from_bitstream( { FOR( i = sfbConf->nBandsStereoCore; i < sfbConf->sfbCnt; i++ ) { - ms_mask[k][i] = extract_l( get_next_indice_fx( st0, 1 ) ); + ms_mask[k][i] = extract_l( get_next_indice_fx( st0, 1 ) ); /* Q0 */ move16(); } } } ELSE { - hStereoMdct->IGFStereoMode[k] = SMDCT_DUAL_MONO; + hStereoMdct->IGFStereoMode[k] = SMDCT_DUAL_MONO; /* Q0 */ move16(); } } @@ -517,9 +517,9 @@ void parse_stereo_from_bitstream( IF( !mct_on ) { - hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE; /* Equal bits to both channels */ + hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE; /* Equal bits to both channels Q0*/ move16(); - hStereoMdct->split_ratio = extract_l( get_next_indice_fx( st0, SMDCT_NBBITS_SPLIT_RATIO ) ); + hStereoMdct->split_ratio = extract_l( get_next_indice_fx( st0, SMDCT_NBBITS_SPLIT_RATIO ) ); /* Q0 */ assert( GT_16( hStereoMdct->split_ratio, 0 ) ); } @@ -535,11 +535,11 @@ void parse_stereo_from_bitstream( * Band-wise M/S stereo processing *-------------------------------------------------------------------*/ static void inverseBwMS_fx( - const Word16 startLine, /* i : start line of sfb */ - const Word16 stopLine, /* i : stop line of sfb */ - Word32 x0[], /* i/o: mid/left channel coefficients */ - Word32 x1[], /* i/o: side/right channel coefficients */ - const Word32 norm_fac /* i : normalization factor */ + const Word16 startLine, /* i : start line of sfb Q0*/ + const Word16 stopLine, /* i : stop line of sfb Q0*/ + Word32 x0[], /* i/o: mid/left channel coefficients Qx*/ + Word32 x1[], /* i/o: side/right channel coefficients Qx*/ + const Word32 norm_fac /* i : normalization factor Q31*/ ) { Word16 j; @@ -549,9 +549,9 @@ static void inverseBwMS_fx( { tmpValue = x0[j]; move32(); - x0[j] = Mpy_32_32( L_add( x0[j], x1[j] ), norm_fac ); + x0[j] = Mpy_32_32( L_add( x0[j], x1[j] ), norm_fac ); /* Qx */ move32(); - x1[j] = Mpy_32_32( L_sub_sat( tmpValue, x1[j] ), norm_fac ); + x1[j] = Mpy_32_32( L_sub_sat( tmpValue, x1[j] ), norm_fac ); /* Qx */ move32(); } @@ -565,10 +565,10 @@ static void inverseBwMS_fx( * M/S stereo processing *-------------------------------------------------------------------*/ void inverseMS_fx( - const Word16 L_frame, /* i : frame length */ - Word32 x0[], /* i/o: mid/left channel coefficients */ - Word32 x1[], /* i/o: side/right channel coefficients */ - const Word32 norm_fac /* i : normalization factor */ + const Word16 L_frame, /* i : frame length Q0*/ + Word32 x0[], /* i/o: mid/left channel coefficients Qx*/ + Word32 x1[], /* i/o: side/right channel coefficients Qx*/ + const Word32 norm_fac /* i : normalization factor Q31*/ ) { inverseBwMS_fx( 0, L_frame, x0, x1, norm_fac ); @@ -584,20 +584,20 @@ void inverseMS_fx( *-------------------------------------------------------------------*/ void stereo_decoder_tcx_fx( STEREO_MDCT_DEC_DATA *hStereoMdct, /* i/o: MDCT stereo decoder structure */ - Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ - Word32 *spec_r_0[NB_DIV], /* i/o: spectrum right channel */ - Word32 *spec_l[], /* i/o: spectrum left channel [NB_DIV][N] */ - Word32 *spec_r[], /* i/o: spectrum right channel [NB_DIV][N] */ - const Word16 mdct_stereo_mode[], /* i : stereo mode (FB/band wise MS, dual mono */ - const Word16 core_l, /* i : core for left channel (TCX20/TCX10) */ - const Word16 core_r, /* i : core for right channel (TCX20/TCX10) */ - const Word16 igf, /* i : flag for IGF activity */ - const Word16 L_frameTCX_l, /* i : TCX frame length of left channel */ - const Word16 L_frameTCX_r, /* i : TCX frame length of right channel */ - const Word16 mct_on, /* i : flag mct block (1) or stereo (0) */ - const Word16 last_core_l, /* i : last core for left channel */ - const Word16 last_core_r, /* i : last core for right channel */ - const Word16 tmp_plc_upmix, /* i : indicates temp upmix for PLC decision */ + Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask Q0*/ + Word32 *spec_r_0[NB_DIV], /* i/o: spectrum right channel Qx*/ + Word32 *spec_l[], /* i/o: spectrum left channel [NB_DIV][N] Qx*/ + Word32 *spec_r[], /* i/o: spectrum right channel [NB_DIV][N] Qx*/ + const Word16 mdct_stereo_mode[], /* i : stereo mode (FB/band wise MS, dual mono Q0*/ + const Word16 core_l, /* i : core for left channel (TCX20/TCX10) Q0*/ + const Word16 core_r, /* i : core for right channel (TCX20/TCX10) Q0*/ + const Word16 igf, /* i : flag for IGF activity Q0*/ + const Word16 L_frameTCX_l, /* i : TCX frame length of left channel Q0*/ + const Word16 L_frameTCX_r, /* i : TCX frame length of right channel Q0*/ + const Word16 mct_on, /* i : flag mct block (1) or stereo (0) Q0*/ + const Word16 last_core_l, /* i : last core for left channel Q0*/ + const Word16 last_core_r, /* i : last core for right channel Q0*/ + const Word16 tmp_plc_upmix, /* i : indicates temp upmix for PLC decision Q0*/ Word16 *q_x_ch2, Word16 *q_x_ch1 ) { @@ -612,7 +612,7 @@ void stereo_decoder_tcx_fx( test(); if ( ( LE_16( core_l, TCX_20_CORE ) && LE_16( core_r, TCX_20_CORE ) ) || tmp_plc_upmix ) { - nSubframes = 1; + nSubframes = 1; /* Q0 */ move16(); } @@ -640,7 +640,7 @@ void stereo_decoder_tcx_fx( { IF( EQ_32( spec_r_0[k][i], 0 ) ) { - spec_r[k][i] = Mpy_32_32( spec_r[k][i], NF_RED_FAC_FIXED ); + spec_r[k][i] = Mpy_32_32( spec_r[k][i], NF_RED_FAC_FIXED ); /* Qx */ move32(); } } @@ -660,7 +660,7 @@ void stereo_decoder_tcx_fx( { IF( EQ_32( spec_r_0[k][i], 0 ) ) { - spec_r[k][i] = Mpy_32_32( spec_r[k][i], NF_RED_FAC_FIXED ); + spec_r[k][i] = Mpy_32_32( spec_r[k][i], NF_RED_FAC_FIXED ); /* Qx */ move32(); } } @@ -681,7 +681,7 @@ void stereo_decoder_tcx_fx( { IF( EQ_32( spec_r_0[k][i], 0 ) ) { - spec_r[k][i] = Mpy_32_32( spec_r[k][i], NF_RED_FAC_FIXED ); + spec_r[k][i] = Mpy_32_32( spec_r[k][i], NF_RED_FAC_FIXED ); /* Qx */ move32(); } } @@ -701,7 +701,7 @@ void stereo_decoder_tcx_fx( { IF( EQ_32( spec_r_0[k][i], 0 ) ) { - spec_r[k][i] = Mpy_32_32( spec_r[k][i], NF_RED_FAC_FIXED ); + spec_r[k][i] = Mpy_32_32( spec_r[k][i], NF_RED_FAC_FIXED ); /* Qx */ move32(); } } @@ -725,12 +725,12 @@ void stereo_decoder_tcx_fx( /* set flag to reverse dmx computation in case of right-side panning, only relevant for mono output */ IF( GT_32( hStereoMdct->smooth_ratio_fx, ONE_POINT_3_FIXED ) ) { - hStereoMdct->reverse_dmx = 1; + hStereoMdct->reverse_dmx = 1; /* Q0 */ move16(); } ELSE IF( LT_32( hStereoMdct->smooth_ratio_fx, POINT_9_FIXED ) ) { - hStereoMdct->reverse_dmx = 0; + hStereoMdct->reverse_dmx = 0; /* Q0 */ move16(); } @@ -763,19 +763,19 @@ void stereo_decoder_tcx_fx( IF( ( GT_32( nrgRatio, ONE_IN_Q26 ) ) && ( LT_16( k, tmp1 ) ) ) { shift = norm_l( nrgRatio ); - nrgRatio = L_shl( nrgRatio, shift ); - v_multc_fixed( spec_r[k], nrgRatio, spec_r[k], L_frameTCX_r ); - Scale_sig32( spec_r[k], L_frameTCX_r, sub( 5, shift ) ); + nrgRatio = L_shl( nrgRatio, shift ); /* Q26 + shift */ + v_multc_fixed( spec_r[k], nrgRatio, spec_r[k], L_frameTCX_r ); /* spec_r will be in Qx + shift - Q5 */ + Scale_sig32( spec_r[k], L_frameTCX_r, sub( 5, shift ) ); /* Qx */ *q_x_ch2 = *q_x_ch2; move16(); } ELSE IF( ( LT_32( nrgRatio, ONE_IN_Q26 ) ) && ( LT_16( k, tmp2 ) ) ) { tmp = BASOP_Util_Divide3232_Scale( ONE_IN_Q26, nrgRatio, &tmp_e ); - inv_nrgRatio = L_deposit_h( tmp ); + inv_nrgRatio = L_deposit_h( tmp ); /* Q31 - tmp_e */ shift = sub( 5, tmp_e ); - v_multc_fixed( spec_l[k], inv_nrgRatio, spec_l[k], L_frameTCX_l ); - Scale_sig32( spec_l[k], L_frameTCX_l, sub( 5, shift ) ); + v_multc_fixed( spec_l[k], inv_nrgRatio, spec_l[k], L_frameTCX_l ); /* spec_r will be in Qx - tmp_e */ + Scale_sig32( spec_l[k], L_frameTCX_l, sub( 5, shift ) ); /* Qx */ *q_x_ch1 = *q_x_ch1; move16(); } @@ -844,11 +844,11 @@ void inverseMS( #ifdef IVAS_FLOAT_FIXED void initMdctStereoDecData_fx( - STEREO_MDCT_DEC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ - const Word16 igf, /* i : flag indicating IGF activity */ - const H_IGF_GRID igfGrid, /* i : IGF grid configuration */ - const Word32 element_brate, /* i : element bitrate */ - const Word16 bwidth /* i : audio bandwidth */ + STEREO_MDCT_DEC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ + const Word16 igf, /* i : flag indicating IGF activity Q0*/ + const H_IGF_GRID igfGrid, /* i : IGF grid configuration Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word16 bwidth /* i : audio bandwidth Q0*/ ) { Word16 tcx_coded_lines; @@ -873,17 +873,17 @@ void initMdctStereoDecData_fx( } ELSE { - hStereoMdct->stbParamsTCX20.sfbIgfStart = -1; + hStereoMdct->stbParamsTCX20.sfbIgfStart = -1; /* Q0 */ move16(); - hStereoMdct->stbParamsTCX10.sfbIgfStart = -1; + hStereoMdct->stbParamsTCX10.sfbIgfStart = -1; /* Q0 */ move16(); - hStereoMdct->stbParamsTCX20afterACELP.sfbIgfStart = -1; + hStereoMdct->stbParamsTCX20afterACELP.sfbIgfStart = -1; /* Q0 */ move16(); - hStereoMdct->stbParamsTCX10.nBandsStereoCore = hStereoMdct->stbParamsTCX10.sfbCnt; + hStereoMdct->stbParamsTCX10.nBandsStereoCore = hStereoMdct->stbParamsTCX10.sfbCnt; /* Q0 */ move16(); - hStereoMdct->stbParamsTCX20.nBandsStereoCore = hStereoMdct->stbParamsTCX20.sfbCnt; + hStereoMdct->stbParamsTCX20.nBandsStereoCore = hStereoMdct->stbParamsTCX20.sfbCnt; /* Q0 */ move16(); - hStereoMdct->stbParamsTCX20afterACELP.nBandsStereoCore = hStereoMdct->stbParamsTCX20afterACELP.sfbCnt; + hStereoMdct->stbParamsTCX20afterACELP.nBandsStereoCore = hStereoMdct->stbParamsTCX20afterACELP.sfbCnt; /* Q0 */ move16(); } @@ -971,7 +971,7 @@ ivas_error initMdctStereoDtxData_fx( test(); IF( EQ_16( ch, 1 ) && st->cng_sba_flag ) { - st->hFdCngDec->hFdCngCom->seed = add( st->hFdCngDec->hFdCngCom->seed, 3 ); + st->hFdCngDec->hFdCngCom->seed = add( st->hFdCngDec->hFdCngCom->seed, 3 ); /* Q0 */ move16(); } } @@ -1068,8 +1068,8 @@ ivas_error initMdctStereoDtxData( #ifdef IVAS_FLOAT_FIXED void synchonize_channels_mdct_sid_fx( - Decoder_State *sts[CPE_CHANNELS], /* i/o: decoder state structure */ - const Word16 n /* i : channel number */ + Decoder_State *sts[CPE_CHANNELS], /* i/o: decoder state structure */ + const Word16 n /* i : channel number Q0*/ ) { Decoder_State *st; @@ -1162,7 +1162,13 @@ void synchonize_channels_mdct_sid( // helper function static void update_exp( Word16 *a_exp, Word16 *b_exp, Word16 *buff_a, Word16 *buff_b, Word16 legth ); -static void update_exp( Word16 *a_exp, Word16 *b_exp, Word16 *buff_a, Word16 *buff_b, Word16 legth ) +static void update_exp( + Word16 *a_exp, + Word16 *b_exp, + Word16 *buff_a, /* exp(a_exp) */ + Word16 *buff_b, /* exp(b_exp) */ + Word16 legth /* Q0 */ +) { Word16 diff = 0; move16(); @@ -1171,7 +1177,7 @@ static void update_exp( Word16 *a_exp, Word16 *b_exp, Word16 *buff_a, Word16 *bu diff = sub( *a_exp, *b_exp ); FOR( Word16 j = 0; j < legth; j++ ) { - buff_b[j] = shr( buff_b[j], diff ); + buff_b[j] = shr( buff_b[j], diff ); /* exp(a_exp) */ move16(); } *b_exp = *a_exp; @@ -1183,7 +1189,7 @@ static void update_exp( Word16 *a_exp, Word16 *b_exp, Word16 *buff_a, Word16 *bu FOR( Word16 j = 0; j < legth; j++ ) { - buff_a[j] = shr( buff_a[j], diff ); + buff_a[j] = shr( buff_a[j], diff ); /* exp(b_exp)*/ move16(); } *a_exp = *b_exp; @@ -1191,7 +1197,10 @@ static void update_exp( Word16 *a_exp, Word16 *b_exp, Word16 *buff_a, Word16 *bu } return; } -static Word16 norm_arr( Word16 *arr, Word32 size ) +static Word16 norm_arr( + Word16 *arr, + Word32 size /* Q0 */ +) { Word16 q = 15; move16(); @@ -1203,11 +1212,11 @@ static Word16 norm_arr( Word16 *arr, Word32 size ) return q; } void updateBuffersForDmxMdctStereo_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ - const Word16 output_frame, /* i : output frame length */ - Word32 output0_fx[], - Word32 output1_fx[], - Word16 synth_fx[CPE_CHANNELS][L_FRAME48k] /* i/o: decoder synthesis */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ + const Word16 output_frame, /* i : output frame length Q0*/ + Word32 output0_fx[], /* Qx */ + Word32 output1_fx[], /* Qx */ + Word16 synth_fx[CPE_CHANNELS][L_FRAME48k] /* i/o: decoder synthesis qsynth*/ ) { Word16 delay_buf_out_len, tcxltp_mem_in_len, delta, i; @@ -1236,7 +1245,7 @@ void updateBuffersForDmxMdctStereo_fx( diff_sidNoiseEst = sub( exp_sidNoiseEst0, exp_sidNoiseEst1 ); FOR( Word32 j = 0; j < NPART; j++ ) { - sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[j] = L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[j], diff_sidNoiseEst ); + sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[j] = L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[j], diff_sidNoiseEst ); /* exp(exp_sidNoiseEst0) */ move16(); } exp_sidNoiseEst1 = exp_sidNoiseEst0; @@ -1247,7 +1256,7 @@ void updateBuffersForDmxMdctStereo_fx( diff_sidNoiseEst = sub( exp_sidNoiseEst1, exp_sidNoiseEst0 ); FOR( Word32 j = 0; j < NPART; j++ ) { - sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[j] = L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[j], diff_sidNoiseEst ); + sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[j] = L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[j], diff_sidNoiseEst ); /* exp( exp_sidNoiseEst1) */ move16(); } exp_sidNoiseEst0 = exp_sidNoiseEst1; @@ -1262,7 +1271,7 @@ void updateBuffersForDmxMdctStereo_fx( IF( EQ_32( hCPE->element_brate, IVAS_SID_5k2 ) && GT_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) { /* in the first SID frame after an active frame, create mid noise shape here, in SID frames that follow inactive frames, it is done directly in the SID decoding since the mid shape is being used in CNG then */ - FOR( int16_t p = 0; p < sts[0]->hFdCngDec->hFdCngCom->npart; p++ ) + FOR( Word16 p = 0; p < sts[0]->hFdCngDec->hFdCngCom->npart; p++ ) { Var1 = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ) ); // exp_sidNoiseEst0 - 1 sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = Mpy_32_32( ONE_IN_Q30, Var1 ); // 31 - exp_sidNoiseEst0 - 1 + 31 - 31 @@ -1291,8 +1300,8 @@ void updateBuffersForDmxMdctStereo_fx( move16(); } - delay_buf_out_len = i_mult( delta, HQ_DELAY_COMP ); - tcxltp_mem_in_len = NS2SA_FX2( sts[0]->output_Fs, TCXLTP_DELAY_NS ); + delay_buf_out_len = i_mult( delta, HQ_DELAY_COMP ); /* Q0 */ + tcxltp_mem_in_len = NS2SA_FX2( sts[0]->output_Fs, TCXLTP_DELAY_NS ); /* Q0 */ move16(); assert( delay_buf_out_len > tcxltp_mem_in_len ); @@ -1303,11 +1312,11 @@ void updateBuffersForDmxMdctStereo_fx( move16(); move16(); - Copy_Scale_sig_32_16( &sts[0]->hTcxLtpDec->tcxltp_mem_in_32[0], &sts[0]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, -11 ); - Copy_Scale_sig_32_16( &sts[1]->hTcxLtpDec->tcxltp_mem_in_32[0], &sts[1]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, -11 ); + Copy_Scale_sig_32_16( &sts[0]->hTcxLtpDec->tcxltp_mem_in_32[0], &sts[0]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, -11 ); // Q0 + Copy_Scale_sig_32_16( &sts[1]->hTcxLtpDec->tcxltp_mem_in_32[0], &sts[1]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, -11 ); // Q0 - Copy_Scale_sig_32_16( &sts[0]->hTcxLtpDec->tcxltp_mem_out_32[0], &sts[0]->hTcxLtpDec->tcxltp_mem_out[0], L_FRAME48k, -11 ); - Copy_Scale_sig_32_16( &sts[1]->hTcxLtpDec->tcxltp_mem_out_32[0], &sts[1]->hTcxLtpDec->tcxltp_mem_out[0], L_FRAME48k, -11 ); + Copy_Scale_sig_32_16( &sts[0]->hTcxLtpDec->tcxltp_mem_out_32[0], &sts[0]->hTcxLtpDec->tcxltp_mem_out[0], L_FRAME48k, -11 ); // Q0 + Copy_Scale_sig_32_16( &sts[1]->hTcxLtpDec->tcxltp_mem_out_32[0], &sts[1]->hTcxLtpDec->tcxltp_mem_out[0], L_FRAME48k, -11 ); // Q0 sts[0]->hTcxLtpDec->exp_tcxltp_mem_in = sub( 15, norm_arr( sts[0]->hTcxLtpDec->tcxltp_mem_in, TCXLTP_MAX_DELAY ) ); move16(); @@ -1320,11 +1329,11 @@ void updateBuffersForDmxMdctStereo_fx( move16(); - Scale_sig( &sts[0]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_in ) ); - Scale_sig( &sts[1]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, sub( 15, sts[1]->hTcxLtpDec->exp_tcxltp_mem_in ) ); + Scale_sig( &sts[0]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_in ) ); // (15 - sts[0]->hTcxLtpDec->exp_tcxltp_mem_in) + Scale_sig( &sts[1]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, sub( 15, sts[1]->hTcxLtpDec->exp_tcxltp_mem_in ) ); // (15 - sts[0]->hTcxLtpDec->exp_tcxltp_mem_in) - Scale_sig( &sts[0]->hTcxLtpDec->tcxltp_mem_out[0], TCXLTP_MAX_DELAY, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_out ) ); - Scale_sig( &sts[1]->hTcxLtpDec->tcxltp_mem_out[0], TCXLTP_MAX_DELAY, sub( 15, sts[1]->hTcxLtpDec->exp_tcxltp_mem_out ) ); + Scale_sig( &sts[0]->hTcxLtpDec->tcxltp_mem_out[0], TCXLTP_MAX_DELAY, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_out ) ); // (15 - sts[0]->hTcxLtpDec->exp_tcxltp_mem_out) + Scale_sig( &sts[1]->hTcxLtpDec->tcxltp_mem_out[0], TCXLTP_MAX_DELAY, sub( 15, sts[1]->hTcxLtpDec->exp_tcxltp_mem_out ) ); // (15 - sts[0]->hTcxLtpDec->exp_tcxltp_mem_in) update_exp( &sts[0]->hTcxLtpDec->exp_tcxltp_mem_in, &sts[1]->hTcxLtpDec->exp_tcxltp_mem_in, @@ -1339,46 +1348,46 @@ void updateBuffersForDmxMdctStereo_fx( FOR( i = 0; i < tcxltp_mem_in_len; i++ ) { sum_tcx_ltp = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_in[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_in[i], 1 ) ); // exp_tcxltp_mem_in + 1 - sts[0]->hTcxLtpDec->tcxltp_mem_in[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp ); // 14 - exp_tcxltp_mem_in - 1 + sts[0]->hTcxLtpDec->tcxltp_mem_in[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp ); // exp_tcxltp_mem_in + 1 move16(); - sum_delay_buf = add( sts[0]->delay_buf_out_fx[i], sts[1]->delay_buf_out_fx[i] ); - sts[0]->delay_buf_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_delay_buf ); // exp_delay_buf_sum + sum_delay_buf = add( sts[0]->delay_buf_out_fx[i], sts[1]->delay_buf_out_fx[i] ); /* Q0 */ + sts[0]->delay_buf_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_delay_buf ); // Q0 move16(); - sum_old_out = add( shr( sts[0]->hHQ_core->old_out_fx[i], 1 ), shr( sts[1]->hHQ_core->old_out_fx[i], 1 ) ); - sts[0]->hHQ_core->old_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_old_out ); // exp_old_out_sum + sum_old_out = add( shr( sts[0]->hHQ_core->old_out_fx[i], 1 ), shr( sts[1]->hHQ_core->old_out_fx[i], 1 ) ); // exp_old_out + 1 + sts[0]->hHQ_core->old_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_old_out ); // exp_old_out + 1 move16(); - sum_tcx_ltp_out = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_out[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_out[i], 1 ) ); - sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp_out ); // exp_tcs_ltp_out_sm + sum_tcx_ltp_out = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_out[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_out[i], 1 ) ); // exp_tcxltp_mem_out + 1 + sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp_out ); // exp_tcxltp_mem_out + 1 move16(); } FOR( ; i < delay_buf_out_len; i++ ) { - sum_delay_buf = add( sts[0]->delay_buf_out_fx[i], sts[1]->delay_buf_out_fx[i] ); - sts[0]->delay_buf_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_delay_buf ); // exp_delay_buf_sum + sum_delay_buf = add( sts[0]->delay_buf_out_fx[i], sts[1]->delay_buf_out_fx[i] ); // Q0 + sts[0]->delay_buf_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_delay_buf ); // Q0 move16(); - sum_old_out = add( shr( sts[0]->hHQ_core->old_out_fx[i], 1 ), shr( sts[1]->hHQ_core->old_out_fx[i], 1 ) ); - sts[0]->hHQ_core->old_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_old_out ); + sum_old_out = add( shr( sts[0]->hHQ_core->old_out_fx[i], 1 ), shr( sts[1]->hHQ_core->old_out_fx[i], 1 ) ); /* exp_old_out + 1 */ + sts[0]->hHQ_core->old_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_old_out ); /* exp_old_out + 1 */ move16(); - sum_tcx_ltp_out = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_out[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_out[i], 1 ) ); - sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp_out ); // exp_tcs_ltp_out_sm + sum_tcx_ltp_out = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_out[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_out[i], 1 ) ); // exp_tcxltp_mem_out + 1 + sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp_out ); // exp_tcxltp_mem_out + 1 move16(); } FOR( ; i < output_frame; i++ ) { - sum_old_out = add( shr( sts[0]->hHQ_core->old_out_fx[i], 1 ), shr( sts[1]->hHQ_core->old_out_fx[i], 1 ) ); - sts[0]->hHQ_core->old_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_old_out ); // exp_old_out_sum + sum_old_out = add( shr( sts[0]->hHQ_core->old_out_fx[i], 1 ), shr( sts[1]->hHQ_core->old_out_fx[i], 1 ) ); // exp_old_out + 1 + sts[0]->hHQ_core->old_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_old_out ); // exp_old_out + 1 move16(); - sum_tcx_ltp_out = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_out[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_out[i], 1 ) ); - sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp_out ); // 15 + exp_tcs_ltp_out_sm - 15 + sum_tcx_ltp_out = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_out[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_out[i], 1 ) ); // exp_tcxltp_mem_out + 1 + sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp_out ); // exp_tcxltp_mem_out + 1 move16(); } sts[0]->hTcxLtpDec->exp_tcxltp_mem_in = add( sts[0]->hTcxLtpDec->exp_tcxltp_mem_in, 1 ); @@ -1388,8 +1397,8 @@ void updateBuffersForDmxMdctStereo_fx( sts[0]->hTcxLtpDec->exp_tcxltp_mem_out = add( sts[0]->hTcxLtpDec->exp_tcxltp_mem_out, 1 ); move16(); - Copy_Scale_sig_16_32( &sts[0]->hTcxLtpDec->tcxltp_mem_in[0], &sts[0]->hTcxLtpDec->tcxltp_mem_in_32[0], TCXLTP_MAX_DELAY, sub( 11, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_in ) ) ); - Copy_Scale_sig_16_32( &sts[0]->hTcxLtpDec->tcxltp_mem_out[0], &sts[0]->hTcxLtpDec->tcxltp_mem_out_32[0], TCXLTP_MAX_DELAY, sub( 11, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_out ) ) ); + Copy_Scale_sig_16_32( &sts[0]->hTcxLtpDec->tcxltp_mem_in[0], &sts[0]->hTcxLtpDec->tcxltp_mem_in_32[0], TCXLTP_MAX_DELAY, sub( 11, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_in ) ) ); // Q11 + Copy_Scale_sig_16_32( &sts[0]->hTcxLtpDec->tcxltp_mem_out[0], &sts[0]->hTcxLtpDec->tcxltp_mem_out_32[0], TCXLTP_MAX_DELAY, sub( 11, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_out ) ) ); // Q11 } return; @@ -1533,20 +1542,20 @@ void applyDmxMdctStereo( } #else void applyDmxMdctStereo_fx( - const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ - Word32 *output_fx[CPE_CHANNELS], /* i/o: core decoder output */ - const Word16 output_frame /* i : output frame length */ + const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ + Word32 *output_fx[CPE_CHANNELS], /* i/o: core decoder output q_out*/ + const Word16 output_frame /* i : output frame length Q0*/ ) { Word16 crossfade_len, i; Word16 dmx_len; Word32 fade_fx, step_fx; - step_fx = ONE_IN_Q31; + step_fx = ONE_IN_Q31; /* Q31 */ move32(); - fade_fx = ONE_IN_Q31; + fade_fx = ONE_IN_Q31; /* Q31 */ move32(); - dmx_len = output_frame; + dmx_len = output_frame; /* Q0 */ move16(); test(); @@ -1558,15 +1567,15 @@ void applyDmxMdctStereo_fx( SWITCH( hCPE->hCoreCoder[0]->output_Fs ) { case 48000: - step_fx = 22369622; + step_fx = 22369622; /* 0.0104 in Q31 */ move32(); BREAK; case 32000: - step_fx = 33554432; + step_fx = 33554432; /* 0.0156 in Q31 */ move32(); BREAK; case 16000: - step_fx = 67108864; + step_fx = 67108864; /* 0.0312 in Q31 */ move32(); BREAK; default: @@ -1577,43 +1586,43 @@ void applyDmxMdctStereo_fx( /* for first inactive CNG frame after active decoding we have to do a fade-OUT FROM the passive DMX */ ELSE IF( LE_32( hCPE->element_brate, IVAS_SID_5k2 ) && GT_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) { - crossfade_len = shr( output_frame, 2 ); + crossfade_len = shr( output_frame, 2 ); /* Q0 */ SWITCH( output_frame ) { case 960: - step_fx = -8947849; + step_fx = -8947849; /* -0.0041 in Q31 */ move32(); BREAK; case 640: - step_fx = -13421773; + step_fx = -13421773; /* -0.00625 in Q31 */ move32(); BREAK; case 320: - step_fx = -26843546; + step_fx = -26843546; /* -0.0125 in Q31 */ move32(); BREAK; } fade_fx = 0; move32(); - dmx_len = crossfade_len; + dmx_len = crossfade_len; /* Q0 */ move16(); } ELSE IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && LE_32( hCPE->last_element_brate, IVAS_32k ) ) { - crossfade_len = NS2SA( hCPE->hCoreCoder[0]->output_Fs, DELAY_CLDFB_NS ); + crossfade_len = NS2SA( hCPE->hCoreCoder[0]->output_Fs, DELAY_CLDFB_NS ); /* Q0 */ move16(); SWITCH( hCPE->hCoreCoder[0]->output_Fs ) { case 48000: - step_fx = 35791396; + step_fx = 35791396; /* 0.0166 in Q31 */ move32(); BREAK; case 32000: - step_fx = 53687092; + step_fx = 53687092; /* 0.025 in Q31 */ move32(); BREAK; case 16000: - step_fx = 107374184; + step_fx = 107374184; /* 0.05 in Q31 */ move32(); BREAK; default: @@ -1630,17 +1639,17 @@ void applyDmxMdctStereo_fx( /* apply crossfade */ FOR( i = 0; i < crossfade_len; i++ ) { - Word32 temp_1 = Mpy_32_32( output_fx[0][i], fade_fx ); - Word32 temp_2 = Mpy_32_32( L_add_sat( output_fx[0][i], output_fx[1][i] ), Mpy_32_32( INV_SQRT2_FX, L_sub_sat( ONE_IN_Q31, fade_fx ) ) ); - output_fx[0][i] = L_add( temp_1, temp_2 ); + Word32 temp_1 = Mpy_32_32( output_fx[0][i], fade_fx ); /* q_out */ + Word32 temp_2 = Mpy_32_32( L_add_sat( output_fx[0][i], output_fx[1][i] ), Mpy_32_32( INV_SQRT2_FX, L_sub_sat( ONE_IN_Q31, fade_fx ) ) ); /* q_out */ + output_fx[0][i] = L_add( temp_1, temp_2 ); /* q_out */ move32(); - fade_fx = L_sub_sat( fade_fx, step_fx ); + fade_fx = L_sub_sat( fade_fx, step_fx ); /* Q31 */ } /* apply passive downmix on all-active-frame part */ FOR( ; i < dmx_len; i++ ) { - output_fx[0][i] = Mpy_32_32( L_add_sat( output_fx[0][i], output_fx[1][i] ), INV_SQRT2_FX ); + output_fx[0][i] = Mpy_32_32( L_add_sat( output_fx[0][i], output_fx[1][i] ), INV_SQRT2_FX ); /* q_out */ move32(); } diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index 3accfa8b64545c88978861b3400ed6733fde41c4..5f15ccba8f09d4c4953a308b52dd30badbe16034 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -559,31 +559,31 @@ static void cpy_tcx_ltp_data( } #else static void cpy_tcx_ltp_data_fx( - TCX_LTP_DEC_HANDLE hTcxLtpDecOld, /* i : TCX-LTP structure to copy from */ - TCX_LTP_DEC_HANDLE hTcxLtpDecNew, /* o : TCX-LTP structure to copy to */ - const Word32 output_Fs /* i : output sampling rate */ + TCX_LTP_DEC_HANDLE hTcxLtpDecOld, /* i : TCX-LTP structure to copy from */ + TCX_LTP_DEC_HANDLE hTcxLtpDecNew, /* o : TCX-LTP structure to copy to */ + const Word32 output_Fs /* i : output sampling rate Q0*/ ) { Word16 sz; - hTcxLtpDecNew->tcxltp_pitch_int_post_prev = hTcxLtpDecOld->tcxltp_pitch_int_post_prev; + hTcxLtpDecNew->tcxltp_pitch_int_post_prev = hTcxLtpDecOld->tcxltp_pitch_int_post_prev; /* Q0 */ move16(); - hTcxLtpDecNew->tcxltp_pitch_fr_post_prev = hTcxLtpDecOld->tcxltp_pitch_fr_post_prev; + hTcxLtpDecNew->tcxltp_pitch_fr_post_prev = hTcxLtpDecOld->tcxltp_pitch_fr_post_prev; /* Q0 */ move16(); - hTcxLtpDecNew->tcxltp_gain_post_prev = hTcxLtpDecOld->tcxltp_gain_post_prev; + hTcxLtpDecNew->tcxltp_gain_post_prev = hTcxLtpDecOld->tcxltp_gain_post_prev; /* Qx */ move16(); - hTcxLtpDecNew->tcxltp_filt_idx_prev = hTcxLtpDecOld->tcxltp_filt_idx_prev; + hTcxLtpDecNew->tcxltp_filt_idx_prev = hTcxLtpDecOld->tcxltp_filt_idx_prev; /* Q0 */ move16(); /* (int16_t) ( ( TCXLTP_MAX_DELAY * output_Fs ) / 48000 ) */ - sz = extract_l( Mpy_32_32_r( TCXLTP_MAX_DELAY * output_Fs, 44739 /* 1 / 48000 in Q31 */ ) ); - Copy( hTcxLtpDecOld->tcxltp_mem_in, hTcxLtpDecNew->tcxltp_mem_in, sz ); // TODO: One of these will be removed later - Copy32( hTcxLtpDecOld->tcxltp_mem_in_32, hTcxLtpDecNew->tcxltp_mem_in_32, sz ); - hTcxLtpDecNew->exp_tcxltp_mem_in = hTcxLtpDecOld->exp_tcxltp_mem_in; + sz = extract_l( Mpy_32_32_r( TCXLTP_MAX_DELAY * output_Fs, 44739 /* 1 / 48000 in Q31 */ ) ); /* Q0 */ + Copy( hTcxLtpDecOld->tcxltp_mem_in, hTcxLtpDecNew->tcxltp_mem_in, sz ); // TODO: One of these will be removed later /* exp(exp_tcxltp_mem_in) */ + Copy32( hTcxLtpDecOld->tcxltp_mem_in_32, hTcxLtpDecNew->tcxltp_mem_in_32, sz ); /* exp(exp_tcxltp_mem_in) */ + hTcxLtpDecNew->exp_tcxltp_mem_in = hTcxLtpDecOld->exp_tcxltp_mem_in; /* exp(exp_tcxltp_mem_in) */ move16(); /* (int16_t) ( ( L_FRAME48k * output_Fs ) / 48000 ) */ - sz = extract_l( Mpy_32_32_r( L_FRAME48k * output_Fs, 44739 /* 1 / 48000 in Q31 */ ) ); - Copy( hTcxLtpDecOld->tcxltp_mem_out, hTcxLtpDecNew->tcxltp_mem_out, sz ); // TODO: One of these will be removed later - Copy32( hTcxLtpDecOld->tcxltp_mem_out_32, hTcxLtpDecNew->tcxltp_mem_out_32, sz ); - hTcxLtpDecNew->exp_tcxltp_mem_out = hTcxLtpDecOld->exp_tcxltp_mem_out; + sz = extract_l( Mpy_32_32_r( L_FRAME48k * output_Fs, 44739 /* 1 / 48000 in Q31 */ ) ); /* Q0 */ + Copy( hTcxLtpDecOld->tcxltp_mem_out, hTcxLtpDecNew->tcxltp_mem_out, sz ); // TODO: One of these will be removed later /* exp(exp_tcxltp_mem_in) */ + Copy32( hTcxLtpDecOld->tcxltp_mem_out_32, hTcxLtpDecNew->tcxltp_mem_out_32, sz ); /* exp(exp_tcxltp_mem_in) */ + hTcxLtpDecNew->exp_tcxltp_mem_out = hTcxLtpDecOld->exp_tcxltp_mem_out; /* exp(exp_tcxltp_mem_in) */ move16(); return; @@ -1256,13 +1256,13 @@ ivas_error stereo_memory_dec( } #else ivas_error stereo_memory_dec_fx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - CPE_DEC_HANDLE hCPE, /* i : CPE decoder structure */ - const Word16 nb_bits_metadata, /* i : number of metadata bits */ - const Word32 output_Fs, /* i : output sampling rate */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const MC_MODE mc_mode, /* i : MC mode */ - const Word16 nchan_transport /* i : number of transport channels*/ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + CPE_DEC_HANDLE hCPE, /* i : CPE decoder structure */ + const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ + const Word32 output_Fs, /* i : output sampling rate Q0*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const MC_MODE mc_mode, /* i : MC mode */ + const Word16 nchan_transport /* i : number of transport channels Q0*/ ) { DEC_CORE_HANDLE st; @@ -1276,9 +1276,9 @@ ivas_error stereo_memory_dec_fx( assert( GE_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && "Switching from SCE to CPE is not a valid configuration!" ); - hCPE->hCoreCoder[0]->element_mode = hCPE->element_mode; + hCPE->hCoreCoder[0]->element_mode = hCPE->element_mode; /* Q0 */ move16(); - hCPE->hCoreCoder[1]->element_mode = hCPE->element_mode; + hCPE->hCoreCoder[1]->element_mode = hCPE->element_mode; /* Q0 */ move16(); /*--------------------------------------------------------------* @@ -1290,7 +1290,7 @@ ivas_error stereo_memory_dec_fx( test(); IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) ) { - delay_comp_DFT = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); + delay_comp_DFT = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); /* Q0 */ move16(); /* redressing of the DFT OLA part */ @@ -1298,8 +1298,8 @@ ivas_error stereo_memory_dec_fx( { FOR( i = delay_comp_DFT; i < hCPE->hStereoDft->dft32ms_ovl; i++ ) { - div_m = BASOP_Util_Divide3216_Scale( hCPE->output_mem_fx[n][sub( i, delay_comp_DFT )], hCPE->hStereoDft->win32ms_fx[i_mult( STEREO_DFT32MS_STEP, ( sub( add( sub( hCPE->hStereoDft->dft32ms_ovl, 1 ), delay_comp_DFT ), i ) ) )], &div_e ); - hCPE->output_mem_fx[n][sub( i, delay_comp_DFT )] = L_shl( div_m, add( div_e, 16 ) ); + div_m = BASOP_Util_Divide3216_Scale( hCPE->output_mem_fx[n][i - delay_comp_DFT], hCPE->hStereoDft->win32ms_fx[STEREO_DFT32MS_STEP * ( hCPE->hStereoDft->dft32ms_ovl - 1 + delay_comp_DFT - i )], &div_e ); + hCPE->output_mem_fx[n][i - delay_comp_DFT] = L_shl( div_m, add( div_e, 16 ) ); /* div_e + Q16 */ move32(); // hCPE->output_mem_fx[n][sub(i, delay_comp_DFT)] = hCPE->hStereoDft->win32ms_fx[i_mult(STEREO_DFT32MS_STEP, ( sub(add(sub(hCPE->hStereoDft->dft32ms_ovl, 1), delay_comp_DFT), i) ))]; } @@ -1307,18 +1307,18 @@ ivas_error stereo_memory_dec_fx( IF( hCPE->hCoreCoder[0]->last_core != ACELP_CORE ) { - Copy32( hCPE->hStereoDft->buff_LBTCX_mem_fx, hCPE->input_mem_LB_fx[0], NS2SA( i_mult( hCPE->hCoreCoder[0]->last_L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); + Copy32( hCPE->hStereoDft->buff_LBTCX_mem_fx, hCPE->input_mem_LB_fx[0], NS2SA( i_mult( hCPE->hCoreCoder[0]->last_L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /* Q11 */ } } test(); IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - v_add_32( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[1]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) ); - v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, 16384 /* 0.5 in Q15 */, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) ); + v_add_32( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[1]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) ); /* exp(exp_old_out) */ + v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, 16384 /* 0.5 in Q15 */, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) ); /* exp(exp_old_out) */ - v_add_32( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[1]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k ); - v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, 16384, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k ); + v_add_32( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[1]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k ); /* q_old_outLB_fx */ + v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, 16384 /* 0.5 in Q15 */, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k ); /* exp(exp_old_out) */ } /*--------------------------------------------------------------* @@ -1362,7 +1362,7 @@ ivas_error stereo_memory_dec_fx( } /* memory update - needed in TD stereo, TCX/HQ frame -> DFT stereo, ACELP frame switching */ - Copy32( hCPE->input_mem_LB_fx[0], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( s_min( i_mult( hCPE->hCoreCoder[0]->last_L_frame, FRAMES_PER_SEC ), 16000 ), STEREO_DFT32MS_OVL_NS ) ); + Copy32( hCPE->input_mem_LB_fx[0], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( s_min( i_mult( hCPE->hCoreCoder[0]->last_L_frame, FRAMES_PER_SEC ), 16000 ), STEREO_DFT32MS_OVL_NS ) ); /* Q11 */ /* allocate ICBWE structure */ IF( hCPE->hStereoICBWE == NULL ) @@ -1466,11 +1466,11 @@ ivas_error stereo_memory_dec_fx( { /* re-use an existing buffer for MDCT->TD stereo switching */ Word16 nZeros, len; - nZeros = extract_l( NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ) ); + nZeros = extract_l( NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ) ); /* Q0 */ move16(); - len = NS2SA_FX2( st->output_Fs, 3000000 ); + len = NS2SA_FX2( st->output_Fs, 3000000 ); /* Q0 */ move16(); - Copy32( st->hHQ_core->oldOut_fx + nZeros, hCPE->output_mem_fx[1], len ); + Copy32( st->hHQ_core->oldOut_fx + nZeros, hCPE->output_mem_fx[1], len ); /* exp(exp_old_out) */ } /* deallocated HQ-core for second channel */ @@ -1588,7 +1588,7 @@ ivas_error stereo_memory_dec_fx( IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) ) { - Copy32( hCPE->hStereoTD->TCX_old_syn_Overl_fx, tmpF_buff, L_FRAME16k / 2 ); + Copy32( hCPE->hStereoTD->TCX_old_syn_Overl_fx, tmpF_buff, L_FRAME16k / 2 ); /* Q11 */ } IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) @@ -1631,7 +1631,7 @@ ivas_error stereo_memory_dec_fx( FOR( i = 0; i < CPE_CHANNELS; i++ ) { st = hCPE->hCoreCoder[i]; - st->element_mode = hCPE->element_mode; + st->element_mode = hCPE->element_mode; /* Q0 */ move16(); /* deallocate core-decoder substructures */ @@ -1672,7 +1672,7 @@ ivas_error stereo_memory_dec_fx( if ( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { - st->last_core = ACELP_CORE; /* needed to set-up TCX core in SetTCXModeInfo() */ + st->last_core = ACELP_CORE; /* needed to set-up TCX core in SetTCXModeInfo() Q0*/ move16(); } @@ -1696,7 +1696,7 @@ ivas_error stereo_memory_dec_fx( IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) ) { - Copy32( tmpF_buff, st->hTcxDec->old_syn_Overl_32, L_FRAME16k / 2 ); + Copy32( tmpF_buff, st->hTcxDec->old_syn_Overl_32, L_FRAME16k / 2 ); /* Q11 */ Copy_Scale_sig32_16( st->hTcxDec->old_syn_Overl_32, st->hTcxDec->old_syn_Overl, L_FRAME16k / 2, add( st->Q_syn, 5 ) ); //(st->Qsyn - (11 - 16)) } #ifdef FIX_844_Q_SYN_INIT @@ -1705,8 +1705,8 @@ ivas_error stereo_memory_dec_fx( #endif set16_fx( st->hTcxDec->FBTCXdelayBuf, 0, 111 ); set32_fx( st->hTcxDec->FBTCXdelayBuf_32, 0, 111 ); - st->hTcxDec->old_synthFB_fx = st->hTcxDec->synth_history_fx + NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ); - st->hTcxDec->prev_good_synth_fx = st->hTcxDec->old_synthFB_fx + NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ); + st->hTcxDec->old_synthFB_fx = st->hTcxDec->synth_history_fx + NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ); /* q_synth_history_fx */ + st->hTcxDec->prev_good_synth_fx = st->hTcxDec->old_synthFB_fx + NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ); /* q_synth_history_fx */ /* allocate and initialize MDCT stereo structure */ IF( ( hCPE->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) @@ -1715,7 +1715,7 @@ ivas_error stereo_memory_dec_fx( } IF( EQ_16( ivas_format, STEREO_FORMAT ) && hCPE->element_brate <= MAX_MDCT_ITD_BRATE ) { - hCPE->hStereoMdct->use_itd = 1; + hCPE->hStereoMdct->use_itd = 1; /* Q0 */ move16(); } ELSE @@ -1725,7 +1725,7 @@ ivas_error stereo_memory_dec_fx( } hCPE->hStereoMdct->reverse_dmx = 0; move16(); - hCPE->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; + hCPE->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; /* Q26 */ move32(); } } @@ -1741,14 +1741,14 @@ ivas_error stereo_memory_dec_fx( st = hCPE->hCoreCoder[1]; IF( hCPE->brate_surplus < 0 ) { - tmp16 = extract_l( L_negate( Mpy_32_32( L_abs( hCPE->brate_surplus ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); + tmp16 = extract_l( L_negate( Mpy_32_32( L_abs( hCPE->brate_surplus ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); /* Q0 */ } ELSE { - tmp16 = extract_l( Mpy_32_32( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + tmp16 = extract_l( Mpy_32_32( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* Q0 */ } - hCPE->hStereoTD->tdm_LRTD_flag = get_indice_st( hCPE->hCoreCoder[0], L_add( hCPE->element_brate, hCPE->brate_surplus ), ( sub( add( sub( extract_l( Mpy_32_16_1( hCPE->element_brate, INV_FRAME_PER_SEC_Q15 ) ), nb_bits_metadata ), tmp16 ), ( TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS + TDM_LP_REUSE_BITS + TDM_LR_CONTENT_BITS ) ) ), TDM_LR_CONTENT_BITS ); + hCPE->hStereoTD->tdm_LRTD_flag = get_indice_st( hCPE->hCoreCoder[0], L_add( hCPE->element_brate, hCPE->brate_surplus ), ( sub( add( sub( extract_l( Mpy_32_16_1( hCPE->element_brate, INV_FRAME_PER_SEC_Q15 ) ), nb_bits_metadata ), tmp16 ), ( TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS + TDM_LP_REUSE_BITS + TDM_LR_CONTENT_BITS ) ) ), TDM_LR_CONTENT_BITS ); /* Q0 */ move16(); IF( hCPE->hStereoTD->tdm_LRTD_flag != 0 ) @@ -2381,11 +2381,11 @@ void synchro_synthesis( } #else void synchro_synthesis_fx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx[CPE_CHANNELS], /* i/o: output synthesis signal */ - const Word16 output_frame, /* i : Number of samples */ - const Word16 sba_dirac_stereo_flag, /* i : signal stereo output FOR SBA DirAC */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx[CPE_CHANNELS], /* i/o: output synthesis signal Q11*/ + const Word16 output_frame, /* i : Number of samples Q0*/ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output FOR SBA DirAC Q0*/ Word16 output_fx_q ) { Word16 n, delay_comp_TD, delay_comp_DFT; @@ -2406,7 +2406,7 @@ void synchro_synthesis_fx( Word16 nChannels; sts = hCPE->hCoreCoder; - output_Fs = sts[0]->output_Fs; + output_Fs = sts[0]->output_Fs; /* Q0 */ use_cldfb_for_last_dft = 0; move16(); @@ -2419,7 +2419,7 @@ void synchro_synthesis_fx( if ( ( NE_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && LE_32( hCPE->last_element_brate, IVAS_24k4 ) ) /* note: this is to mimic the DFT stereo condition "hCPE->hStereoDft->hConfig->res_cod_mode == 0" in last frame */ || ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) ) { - use_cldfb_for_last_dft = 1; + use_cldfb_for_last_dft = 1; /* Q0 */ move16(); } @@ -2435,12 +2435,12 @@ void synchro_synthesis_fx( test(); IF( GE_32( hCPE->last_element_brate, IVAS_32k ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) { - dft_mono_brate_switch = -1; /* switch from residual coding mode or MDCT Stereo */ + dft_mono_brate_switch = -1; /* switch from residual coding mode or MDCT Stereo Q0*/ move16(); } ELSE IF( LE_32( hCPE->last_element_brate, IVAS_24k4 ) && GT_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) { - dft_mono_brate_switch = 1; /* switch to residual coding mode*/ + dft_mono_brate_switch = 1; /* switch to residual coding mode Q0*/ move16(); } } @@ -2457,14 +2457,14 @@ void synchro_synthesis_fx( } /* set delays */ - delay_comp_DFT = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); + delay_comp_DFT = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); /* Q0 */ move16(); - delay_comp_TD = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); + delay_comp_TD = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); /* Q0 */ move16(); - delay_diff = sub( delay_comp_TD, delay_comp_DFT ); + delay_diff = sub( delay_comp_TD, delay_comp_DFT ); /* Q0 */ - dft32ms_ovl = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); - delay_cldfb = NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ); + dft32ms_ovl = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); /* Q0 */ + delay_cldfb = NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ); /* Q0 */ move16(); /* initialize pointers */ @@ -2473,7 +2473,7 @@ void synchro_synthesis_fx( { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - p_output_mem_fx[n] = hCPE->output_mem_fx[n]; + p_output_mem_fx[n] = hCPE->output_mem_fx[n]; /* Q11 */ } } @@ -2489,13 +2489,13 @@ void synchro_synthesis_fx( { FOR( i = delay_comp_DFT; i < delay_comp_TD; i++ ) { - sts[0]->prev_synth_buffer32_fx[i] = p_output_mem_fx[0][sub( i, delay_comp_DFT )]; + sts[0]->prev_synth_buffer32_fx[i] = p_output_mem_fx[0][i - delay_comp_DFT]; /* Q11 */ move32(); } FOR( i = delay_comp_TD; i < add( delay_comp_TD, delay_cldfb ); i++ ) { - tmp_out_fx[0][sub( i, delay_comp_TD )] = p_output_mem_fx[0][sub( i, delay_comp_DFT )]; + tmp_out_fx[0][i - delay_comp_TD] = p_output_mem_fx[0][i - delay_comp_DFT]; /* Q11 */ move32(); } } @@ -2505,8 +2505,8 @@ void synchro_synthesis_fx( { FOR( Word32 ind = 0; ind < delay_comp_DFT; ind++ ) { - Word32 temp = L_add( sts[0]->prev_synth_buffer32_fx[ind], sts[1]->prev_synth_buffer32_fx[ind] ); - sts[0]->prev_synth_buffer32_fx[ind] = Mpy_32_32( temp, INV_SQRT2_FX ); + Word32 temp = L_add( sts[0]->prev_synth_buffer32_fx[ind], sts[1]->prev_synth_buffer32_fx[ind] ); /* Q11 */ + sts[0]->prev_synth_buffer32_fx[ind] = Mpy_32_32( temp, INV_SQRT2_FX ); /* Q11 */ move32(); } } @@ -2514,7 +2514,7 @@ void synchro_synthesis_fx( IF( use_cldfb_for_last_dft ) { /* delay CLDFB-based mono output (<= 24.4 kbps) to be aligned with DFT-based mono output (32 kbps), needed to avoid discontinuities with TCX-LTP. */ - Copy32( sts[0]->prev_synth_buffer32_fx + delay_comp_DFT, hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); + Copy32( sts[0]->prev_synth_buffer32_fx + delay_comp_DFT, hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); /* Q11 */ delay_signal_fx( output_fx[0], output_frame, hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); } @@ -2542,7 +2542,7 @@ void synchro_synthesis_fx( } IF( use_cldfb_for_last_dft ) { - Copy32( hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32, sts[0]->prev_synth_buffer32_fx + delay_comp_DFT, delay_diff ); + Copy32( hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32, sts[0]->prev_synth_buffer32_fx + delay_comp_DFT, delay_diff ); /* Q11 */ } /* handling of TD->DFT switching */ @@ -2559,15 +2559,15 @@ void synchro_synthesis_fx( SWITCH( output_Fs ) { case 16000: - inv_fade_len_fx = 71582792; + inv_fade_len_fx = 71582792; /* Q31 */ move32(); BREAK; case 32000: - inv_fade_len_fx = 35791396; + inv_fade_len_fx = 35791396; /* Q31 */ move32(); BREAK; case 48000: - inv_fade_len_fx = 23860930; + inv_fade_len_fx = 23860930; /* Q31 */ move32(); BREAK; default: @@ -2577,12 +2577,12 @@ void synchro_synthesis_fx( /* cross-fading between TD synchro memory and the DFT output */ IF( sba_dirac_stereo_flag ) { - pPrev_synth_fx = hCPE->prev_synth_fx[n]; + pPrev_synth_fx = hCPE->prev_synth_fx[n]; /* Q11 */ move32(); } ELSE { - pPrev_synth_fx = sts[n]->prev_synth_buffer32_fx; + pPrev_synth_fx = sts[n]->prev_synth_buffer32_fx; /* Q11 */ move32(); } @@ -2590,12 +2590,12 @@ void synchro_synthesis_fx( { FOR( i = delay_comp_DFT; i < delay_comp_TD; i++ ) { - Word64 res1 = W_mult0_32_32( pPrev_synth_fx[i], ( sub( delay_comp_TD, i ) ) ); - Word64 res2 = W_mult0_32_32( output_fx[n][i], ( sub( i, delay_comp_DFT ) ) ); - Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); - res = res * inv_fade_len_fx; + Word64 res1 = W_mult0_32_32( pPrev_synth_fx[i], ( sub( delay_comp_TD, i ) ) ); /* Q11 */ + Word64 res2 = W_mult0_32_32( output_fx[n][i], ( sub( i, delay_comp_DFT ) ) ); /* Q11 */ + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); /* Q11 - 6 */ + res = res * inv_fade_len_fx; /* Q11 + 31 - 6 */ move64(); - output_fx[n][i] = W_extract_l( W_shr( res, 31 - 6 ) ); + output_fx[n][i] = W_extract_l( W_shr( res, 31 - 6 ) ); /* Q11 */ move32(); // change 6 to less number to get better precision } @@ -2611,21 +2611,21 @@ void synchro_synthesis_fx( SWITCH( output_Fs ) { case 16000: - inv_fade_len_1_fx = 71582792; + inv_fade_len_1_fx = 71582792; /* Q31 */ move32(); - inv_fade_len_2_fx = 107374184; + inv_fade_len_2_fx = 107374184; /* Q31 */ move32(); BREAK; case 32000: - inv_fade_len_1_fx = 35791396; + inv_fade_len_1_fx = 35791396; /* Q31 */ move32(); - inv_fade_len_2_fx = 53687092; + inv_fade_len_2_fx = 53687092; /* Q31 */ move32(); BREAK; case 48000: - inv_fade_len_1_fx = 23860930; + inv_fade_len_1_fx = 23860930; /* Q31 */ move32(); - inv_fade_len_2_fx = 35791396; + inv_fade_len_2_fx = 35791396; /* Q31 */ move32(); BREAK; default: @@ -2633,23 +2633,23 @@ void synchro_synthesis_fx( } FOR( i = 0; i < delay_diff; i++ ) { - Word64 res1 = W_mult0_32_32( output_fx[0][add( i, delay_comp_DFT )], ( sub( delay_diff, i ) ) ); - Word64 res2 = W_mult0_32_32( p_output_mem_fx[0][i], i ); - Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); - res = res * inv_fade_len_1_fx; + Word64 res1 = W_mult0_32_32( output_fx[0][i + delay_comp_DFT], ( sub( delay_diff, i ) ) ); /* Q11 */ + Word64 res2 = W_mult0_32_32( p_output_mem_fx[0][i], i ); /* Q11 */ + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); /* Q11 - 6 */ + res = res * inv_fade_len_1_fx; /* Q11 + 31 - 6 */ move64(); - output_fx[0][add( i, delay_comp_DFT )] = W_extract_l( W_shr( res, 31 - 6 ) ); + output_fx[0][i + delay_comp_DFT] = W_extract_l( W_shr( res, 31 - 6 ) ); /* Q11 */ move32(); } FOR( i = 0; i < delay_cldfb; i++ ) { - Word64 res1 = W_mult0_32_32( tmp_out_fx[0][i], ( sub( delay_cldfb, i ) ) ); - Word64 res2 = W_mult0_32_32( output_fx[0][add( i, delay_comp_TD )], i ); - Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); - res = res * inv_fade_len_2_fx; + Word64 res1 = W_mult0_32_32( tmp_out_fx[0][i], ( sub( delay_cldfb, i ) ) ); /* Q11 */ + Word64 res2 = W_mult0_32_32( output_fx[0][i + delay_comp_TD], i ); /* Q11 */ + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); /* Q11 - 6 */ + res = res * inv_fade_len_2_fx; /* Q11 + 31 - 6 */ move64(); - output_fx[0][add( i, delay_comp_TD )] = W_extract_l( W_shr( res, 31 - 6 ) ); + output_fx[0][i + delay_comp_TD] = W_extract_l( W_shr( res, 31 - 6 ) ); /* Q11 */ move32(); } } @@ -2678,13 +2678,13 @@ void synchro_synthesis_fx( { FOR( i = delay_comp_DFT; i < delay_comp_TD; i++ ) { - sts[n]->prev_synth_buffer32_fx[i] = p_output_mem_fx[n][sub( i, delay_comp_DFT )]; + sts[n]->prev_synth_buffer32_fx[i] = p_output_mem_fx[n][i - delay_comp_DFT]; /* Q11 */ move32(); } FOR( i = delay_comp_TD; i < add( delay_comp_TD, delay_cldfb ); i++ ) { - tmp_out_fx[n][sub( i, delay_comp_TD )] = p_output_mem_fx[n][sub( i, delay_comp_DFT )]; + tmp_out_fx[n][i - delay_comp_TD] = p_output_mem_fx[n][i - delay_comp_DFT]; /* Q11 */ move32(); } } @@ -2695,9 +2695,9 @@ void synchro_synthesis_fx( test(); IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { - Copy32( sts[0]->prev_synth_buffer32_fx, sts[1]->prev_synth_buffer32_fx, delay_comp_TD ); - Copy32( tmp_out_fx[0], tmp_out_fx[1], delay_cldfb ); - Copy32( p_output_mem_fx[0], p_output_mem_fx[1], delay_diff ); + Copy32( sts[0]->prev_synth_buffer32_fx, sts[1]->prev_synth_buffer32_fx, delay_comp_TD ); /* Q11 */ + Copy32( tmp_out_fx[0], tmp_out_fx[1], delay_cldfb ); /* Q11 */ + Copy32( p_output_mem_fx[0], p_output_mem_fx[1], delay_diff ); /* Q11 */ } /*----------------------------------------------------------------* @@ -2721,7 +2721,7 @@ void synchro_synthesis_fx( /* use TCX synchro memory (perfect signal is available) */ FOR( i = delay_diff; i < dft32ms_ovl; i++ ) { - tmp_out_TD_fx[n][i] = sts[n]->delay_buf_out32_fx[sub( i, delay_diff )]; + tmp_out_TD_fx[n][i] = sts[n]->delay_buf_out32_fx[i - delay_diff]; /* Q11 */ move32(); } } @@ -2734,7 +2734,7 @@ void synchro_synthesis_fx( } ELSE { - Copy32( tmp_out_TD_fx[0], tmp_out_TD2_fx[0], dft32ms_ovl ); + Copy32( tmp_out_TD_fx[0], tmp_out_TD2_fx[0], dft32ms_ovl ); /* Q11 */ } FOR( n = 0; n < hCPE->nchan_out; n++ ) @@ -2744,15 +2744,15 @@ void synchro_synthesis_fx( SWITCH( output_Fs ) { case 16000: - tmpF_fx = 71582792; + tmpF_fx = 71582792; /* 0.033 in Q31 */ move32(); BREAK; case 32000: - tmpF_fx = 35791396; + tmpF_fx = 35791396; /* 0.016 in Q31 */ move32(); BREAK; case 48000: - tmpF_fx = 23860930; + tmpF_fx = 23860930; /* 0.011 in Q31 */ move32(); BREAK; default: @@ -2762,12 +2762,12 @@ void synchro_synthesis_fx( FOR( i = 0; i < delay_diff; i++ ) { - Word64 res1 = W_mult0_32_32( output_fx[n][add( add( sub( output_frame, dft32ms_ovl ), delay_cldfb ), i )], ( sub( delay_diff, i ) ) ); - Word64 res2 = W_mult0_32_32( tmp_out_TD2_fx[n][i], i ); - Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); - res = res * tmpF_fx; + Word64 res1 = W_mult0_32_32( output_fx[n][output_frame - dft32ms_ovl + delay_cldfb + i], ( sub( delay_diff, i ) ) ); /* Q11 */ + Word64 res2 = W_mult0_32_32( tmp_out_TD2_fx[n][i], i ); /* Q11 */ + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); /* Q11 - Q6 */ + res = res * tmpF_fx; /* Q11 + Q31 - Q6 */ move64(); - p_output_mem_fx[n][i] = W_extract_l( W_shr( res, 31 - 6 ) ); + p_output_mem_fx[n][i] = W_extract_l( W_shr( res, 31 - 6 ) ); /* Q11 */ } } ELSE /* TCX core */ @@ -2775,7 +2775,7 @@ void synchro_synthesis_fx( /* reconstruct the 3.125 - 1.25 ms OLA part */ FOR( i = 0; i < delay_diff; i++ ) { - p_output_mem_fx[n][i] = output_fx[n][output_frame - dft32ms_ovl + delay_cldfb + i]; + p_output_mem_fx[n][i] = output_fx[n][output_frame - dft32ms_ovl + delay_cldfb + i]; /* Q11 */ move32(); } } @@ -2783,7 +2783,7 @@ void synchro_synthesis_fx( /* reconstruct the last 1.25 ms part of OLA window */ FOR( i = delay_diff; i < dft32ms_ovl; i++ ) { - p_output_mem_fx[n][i] = tmp_out_TD2_fx[n][i]; + p_output_mem_fx[n][i] = tmp_out_TD2_fx[n][i]; /* Q11 */ move32(); } } @@ -2801,20 +2801,20 @@ void synchro_synthesis_fx( { Word32 step_fx = 0; move32(); - tmpF_fx = ONE_IN_Q31; + tmpF_fx = ONE_IN_Q31; /* Q31 */ move32(); SWITCH( output_Fs ) { case 16000: - step_fx = 33554432; + step_fx = 33554432; /* 0.0156 in Q31 */ move32(); BREAK; case 32000: - step_fx = 16777216; + step_fx = 16777216; /* 0.0078 in Q31 */ move32(); BREAK; case 48000: - step_fx = 11184811; + step_fx = 11184811; /* 0.0052 in Q31 */ move32(); BREAK; default: @@ -2823,9 +2823,9 @@ void synchro_synthesis_fx( /* FOR the first switching frame from DFT to TD, downmix memory too */ FOR( n = 0; n < delay_comp_TD; n++ ) { - sts[0]->prev_synth_buffer32_fx[n] = Mpy_32_32( sts[0]->prev_synth_buffer32_fx[n], tmpF_fx ); + sts[0]->prev_synth_buffer32_fx[n] = Mpy_32_32( sts[0]->prev_synth_buffer32_fx[n], tmpF_fx ); /* Q11 */ move32(); - tmpF_fx = L_sub_sat( tmpF_fx, step_fx ); + tmpF_fx = L_sub_sat( tmpF_fx, step_fx ); /* Q31 */ } } @@ -2834,30 +2834,30 @@ void synchro_synthesis_fx( test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) && !is_DTXrate( hCPE->element_brate ) && is_DTXrate( hCPE->last_element_brate ) ) { - Copy32( sts[0]->prev_synth_buffer32_fx, sts[1]->prev_synth_buffer32_fx, delay_comp_TD ); + Copy32( sts[0]->prev_synth_buffer32_fx, sts[1]->prev_synth_buffer32_fx, delay_comp_TD ); /* Q11 */ } // nChannels = ( hCPE->element_mode == IVAS_CPE_MDCT ) ? 2 : hCPE->nchan_out; IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { - nChannels = 2; + nChannels = 2; /* Q0 */ move16(); } ELSE { - nChannels = hCPE->nchan_out; + nChannels = hCPE->nchan_out; /* Q0 */ move16(); } FOR( n = 0; n < nChannels; n++ ) { IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { - Copy32( sts[n]->prev_synth_buffer32_fx + delay_comp_DFT, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); - delay_signal_fx( output_fx[n], output_frame, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); + Copy32( sts[n]->prev_synth_buffer32_fx + delay_comp_DFT, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); /* Q11 */ + delay_signal_fx( output_fx[n], output_frame, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); /* Q11 */ ivas_post_proc_fx( NULL, hCPE, n, output_fx[n], output_fx, output_frame, 0, output_fx_q ); delay_signal_fx( output_fx[n], output_frame, sts[n]->prev_synth_buffer32_fx, delay_comp_DFT ); - Copy32( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, sts[n]->prev_synth_buffer32_fx + delay_comp_DFT, delay_diff ); + Copy32( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, sts[n]->prev_synth_buffer32_fx + delay_comp_DFT, delay_diff ); /* Q11 */ } ELSE { @@ -2877,15 +2877,15 @@ void synchro_synthesis_fx( SWITCH( output_Fs ) { case 16000: - tmpF_fx = 107374184; + tmpF_fx = 107374184; /* 0.05 in Q31 */ move32(); BREAK; case 32000: - tmpF_fx = 53687092; + tmpF_fx = 53687092; /* 0.025 in Q31 */ move32(); BREAK; case 48000: - tmpF_fx = 35791396; + tmpF_fx = 35791396; /* 0.016 in Q31 */ move32(); BREAK; default: @@ -2893,7 +2893,7 @@ void synchro_synthesis_fx( } FOR( i = 0; i < delay_cldfb; i++ ) { - tmp_out_fx[n][i] = W_extract_l( W_mult0_32_32( Mpy_32_32( tmp_out_fx[n][i], tmpF_fx ), ( sub( delay_cldfb, i ) ) ) ); + tmp_out_fx[n][i] = W_extract_l( W_mult0_32_32( Mpy_32_32( tmp_out_fx[n][i], tmpF_fx ), ( sub( delay_cldfb, i ) ) ) ); /* Q11 */ move32(); } } @@ -2907,15 +2907,15 @@ void synchro_synthesis_fx( SWITCH( output_Fs ) { case 16000: - tmpF_fx = 71582792; + tmpF_fx = 71582792; /* Q31 */ move32(); BREAK; case 32000: - tmpF_fx = 35791396; + tmpF_fx = 35791396; /* Q31 */ move32(); BREAK; case 48000: - tmpF_fx = 23860930; + tmpF_fx = 23860930; /* Q31 */ move32(); BREAK; default: @@ -2924,27 +2924,27 @@ void synchro_synthesis_fx( FOR( i = 0; i < delay_diff; i++ ) { - Word64 res1 = W_mult0_32_32( output_fx[n][i + delay_comp_DFT], ( sub( delay_diff, i ) ) ); - Word64 res2 = W_mult0_32_32( p_output_mem_fx[n][i], i ); - Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); - res = res * tmpF_fx; + Word64 res1 = W_mult0_32_32( output_fx[n][i + delay_comp_DFT], ( sub( delay_diff, i ) ) ); /* Q11 */ + Word64 res2 = W_mult0_32_32( p_output_mem_fx[n][i], i ); /* Q11 */ + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); /* Q11 - Q6 */ + res = res * tmpF_fx; /* Q11 + Q31 - Q6 */ move64(); - output_fx[n][add( i, delay_comp_DFT )] = W_extract_l( W_shr( res, 31 - 6 ) ); + output_fx[n][i + delay_comp_DFT] = W_extract_l( W_shr( res, 31 - 6 ) ); /* Q11 */ move32(); } } SWITCH( output_Fs ) { case 16000: - tmpF_fx = 107374184; + tmpF_fx = 107374184; /* Q31 */ move32(); BREAK; case 32000: - tmpF_fx = 53687092; + tmpF_fx = 53687092; /* Q31 */ move32(); BREAK; case 48000: - tmpF_fx = 35791396; + tmpF_fx = 35791396; /* Q31 */ move32(); BREAK; default: @@ -2952,12 +2952,12 @@ void synchro_synthesis_fx( } FOR( i = 0; i < delay_cldfb; i++ ) { - Word64 res1 = W_mult0_32_32( tmp_out_fx[n][i], ( sub( delay_cldfb, i ) ) ); - Word64 res2 = W_mult0_32_32( output_fx[n][add( i, delay_comp_TD )], i ); - Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); - res = res * tmpF_fx; + Word64 res1 = W_mult0_32_32( tmp_out_fx[n][i], ( sub( delay_cldfb, i ) ) ); /* Q11 */ + Word64 res2 = W_mult0_32_32( output_fx[n][i + delay_comp_TD], i ); /* Q11 */ + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); /* Q11 - Q6 */ + res = res * tmpF_fx; /* Q11 + Q31 - Q6 */ move64(); - output_fx[n][add( i, delay_comp_TD )] = W_extract_l( W_shr( res, 31 - 6 ) ); + output_fx[n][i + delay_comp_TD] = W_extract_l( W_shr( res, 31 - 6 ) ); /* Q11 */ move32(); } } @@ -3010,8 +3010,8 @@ Word32 side_gain_table[32 + 1] = { -ONE_IN_Q31, -2040109440, -1932735232, -18253 322122496, 429496832, 536870912, 644245248, 751619328, 858993408, 966367744, 1073741824, 1181116160, 1288490240 }; void stereo_switching_dec( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ ) { Word16 i, n; @@ -3028,11 +3028,11 @@ void stereo_switching_dec( /* prevent CPE mode switching in the first received frame */ IF( sts[0]->ini_frame == 0 ) { - hCPE->last_element_mode = hCPE->element_mode; + hCPE->last_element_mode = hCPE->element_mode; /* Q0 */ move16(); - hCPE->stereo_switching_counter = 10; + hCPE->stereo_switching_counter = 10; /* Q0 */ move16(); - hCPE->NbFrameMod = 7; + hCPE->NbFrameMod = 7; /* Q0 */ move16(); hCPE->lt_es_em_fx = 0; move16(); @@ -3040,8 +3040,8 @@ void stereo_switching_dec( IF( EQ_16( hCPE->element_mode, hCPE->last_element_mode ) ) { - hCPE->stereo_switching_counter = add( hCPE->stereo_switching_counter, 1 ); - hCPE->stereo_switching_counter = s_min( 10, hCPE->stereo_switching_counter ); + hCPE->stereo_switching_counter = add( hCPE->stereo_switching_counter, 1 ); /* Q0 */ + hCPE->stereo_switching_counter = s_min( 10, hCPE->stereo_switching_counter ); /* Q0 */ } ELSE { @@ -3054,7 +3054,7 @@ void stereo_switching_dec( test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && GE_32( hCPE->element_brate, IVAS_32k ) && LE_32( hCPE->last_element_brate, IVAS_24k4 ) ) { - dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) + dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ set32_fx( hCPE->output_mem_fx[0], 0, dft32ms_ovl ); } test(); @@ -3062,13 +3062,13 @@ void stereo_switching_dec( IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && NE_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && hCPE->hCoreCoder[0]->ini_frame > 0 ) { /* windowing the OLA memory */ - dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) + dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ FOR( n = 0; n < CPE_CHANNELS; n++ ) { IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { /* copy memories from previous MDCT Stereo frame to output_mem */ - Copy32( hCPE->input_mem_fx[n], hCPE->output_mem_fx[n], dft32ms_ovl ); + Copy32( hCPE->input_mem_fx[n], hCPE->output_mem_fx[n], dft32ms_ovl ); /* Q11 */ } test(); @@ -3078,7 +3078,7 @@ void stereo_switching_dec( { FOR( i = 0; i < dft32ms_ovl; i++ ) { - hCPE->output_mem_fx[n][i] = Mpy_32_16_1( hCPE->output_mem_fx[n][i], hCPE->hStereoDft->win32ms_fx[i_mult( STEREO_DFT32MS_STEP, ( sub( sub( dft32ms_ovl, 1 ), i ) ) )] ); + hCPE->output_mem_fx[n][i] = Mpy_32_16_1( hCPE->output_mem_fx[n][i], hCPE->hStereoDft->win32ms_fx[STEREO_DFT32MS_STEP * ( dft32ms_ovl - 1 - i )] ); /* q_output_mem_fx */ move32(); } } @@ -3086,32 +3086,32 @@ void stereo_switching_dec( { IF( EQ_32( hCPE->hStereoTCA->prevTargetGain_fx, ONE_IN_Q29 ) ) { - tmpF_fx = ONE_IN_Q27; + tmpF_fx = ONE_IN_Q27; /* Q27 */ move32(); } ELSE { - Word16 temp_b = extract_l( L_shr( hCPE->hStereoTCA->prevTargetGain_fx, 16 ) ); + Word16 temp_b = extract_l( L_shr( hCPE->hStereoTCA->prevTargetGain_fx, 16 ) ); /* Q13 */ Word16 temp_b_q = 2; move16(); tmpF_fx = Inv16( temp_b, &temp_b_q ); - tmpF_fx = L_shl( tmpF_fx, sub( ( 31 - 4 ), sub( 15, temp_b_q ) ) ); + tmpF_fx = L_shl( tmpF_fx, sub( sub( 31, 4 ), sub( 15, temp_b_q ) ) ); /* Q27 */ } FOR( i = 0; i < dft32ms_ovl; i++ ) { - Word32 temp_result = Mpy_32_16_1( tmpF_fx, hCPE->hStereoDft->win32ms_fx[i_mult( STEREO_DFT32MS_STEP, sub( dft32ms_ovl, 1 + i ) )] ); - hCPE->output_mem_fx[n][i] = L_shl_sat( Mpy_32_32( hCPE->output_mem_fx[n][i], temp_result ), 4 ); + Word32 temp_result = Mpy_32_16_1( tmpF_fx, hCPE->hStereoDft->win32ms_fx[STEREO_DFT32MS_STEP * ( dft32ms_ovl - 1 - i )] ); /* Q27 */ + hCPE->output_mem_fx[n][i] = L_shl_sat( Mpy_32_32( hCPE->output_mem_fx[n][i], temp_result ), 4 ); /* q_output_mem_fx */ } FOR( i = 0; i < delay_comp_TD; i++ ) { Word64 temp_result; - temp_result = W_mult0_32_32( hCPE->hCoreCoder[1]->prev_synth_buffer32_fx[i], tmpF_fx ); - hCPE->hCoreCoder[1]->prev_synth_buffer32_fx[i] = W_sat_l( W_shr( temp_result, 27 ) ); + temp_result = W_mult0_32_32( hCPE->hCoreCoder[1]->prev_synth_buffer32_fx[i], tmpF_fx ); /* q_prev_synth + Q27 */ + hCPE->hCoreCoder[1]->prev_synth_buffer32_fx[i] = W_sat_l( W_shr( temp_result, 27 ) ); /* q_prev_synth */ move32(); } FOR( i = 0; i < L_DEC_MEM_LEN_ICA; i++ ) { - hCPE->hStereoTCA->memChanR_fx[i] = L_shl_sat( Mpy_32_32( hCPE->hStereoTCA->memChanR_fx[i], tmpF_fx ), 4 ); + hCPE->hStereoTCA->memChanR_fx[i] = L_shl_sat( Mpy_32_32( hCPE->hStereoTCA->memChanR_fx[i], tmpF_fx ), 4 ); /* q_mem_chanR */ move32(); } } @@ -3122,15 +3122,15 @@ void stereo_switching_dec( /* create passive downmix of MDCT Stereo memories FOR DFT input memory */ FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) { - Word32 result_int = L_add_sat( hCPE->input_mem_LB_fx[0][ind], hCPE->input_mem_LB_fx[1][ind] ); - hCPE->input_mem_LB_fx[0][ind] = L_shr( result_int, 1 ); + Word32 result_int = L_add_sat( hCPE->input_mem_LB_fx[0][ind], hCPE->input_mem_LB_fx[1][ind] ); /* Q11 */ + hCPE->input_mem_LB_fx[0][ind] = L_shr( result_int, 1 ); /* Q11 */ move32(); } FOR( Word32 ind = 0; ind < dft32ms_ovl; ind++ ) { - Word32 result_int = L_add_sat( hCPE->input_mem_fx[0][ind], hCPE->input_mem_fx[1][ind] ); - hCPE->input_mem_fx[0][ind] = L_shr( result_int, 1 ); + Word32 result_int = L_add_sat( hCPE->input_mem_fx[0][ind], hCPE->input_mem_fx[1][ind] ); /* Q11 */ + hCPE->input_mem_fx[0][ind] = L_shr( result_int, 1 ); /* Q11 */ move32(); } @@ -3138,8 +3138,8 @@ void stereo_switching_dec( { FOR( Word32 ind = 0; ind < dft32ms_ovl; ind++ ) { - Word32 result_int = L_add_sat( hCPE->output_mem_fx[0][ind], hCPE->output_mem_fx[1][ind] ); - hCPE->output_mem_fx[0][ind] = Mpy_32_32( result_int, INV_SQRT_2_Q31 ); + Word32 result_int = L_add_sat( hCPE->output_mem_fx[0][ind], hCPE->output_mem_fx[1][ind] ); /* q_output_mem_fx */ + hCPE->output_mem_fx[0][ind] = Mpy_32_32( result_int, INV_SQRT_2_Q31 ); /* q_output_mem_fx */ move32(); } } @@ -3152,7 +3152,7 @@ void stereo_switching_dec( move32(); if ( hCPE->hStereoTCA != NULL ) { - tmpF_fx = side_gain_table[hCPE->hStereoTCA->indx_ica_gD]; + tmpF_fx = side_gain_table[hCPE->hStereoTCA->indx_ica_gD]; /* Q31 */ move32(); } set32_fx( hCPE->hStereoDft->side_gain_fx + STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX, tmpF_fx, STEREO_DFT_BAND_MAX ); @@ -3170,7 +3170,7 @@ void stereo_switching_dec( test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && NE_16( hCPE->last_element_mode, IVAS_CPE_TD ) && hCPE->hCoreCoder[0]->ini_frame > 0 ) { - hCPE->hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; + hCPE->hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; /* Q0 */ move16(); hCPE->hStereoTD->tdm_last_SM_flag = 0; move16(); @@ -3180,7 +3180,7 @@ void stereo_switching_dec( /* First frame after DFT frame AND the content is uncorrelated or xtalk -> the primary channel is forced to left */ if ( EQ_16( hCPE->hStereoTD->tdm_LRTD_flag, 1 ) ) { - hCPE->hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; + hCPE->hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; /* Q0 */ move16(); } } @@ -3214,7 +3214,7 @@ void stereo_switching_dec( set16_fx( sts[0]->mem_syn3_fx, 0, M ); set16_fx( sts[0]->mem_syn_r, 0, L_SYN_MEM ); - sts[1]->last_L_frame = sts[0]->last_L_frame; + sts[1]->last_L_frame = sts[0]->last_L_frame; /* Q0 */ move16(); @@ -3225,13 +3225,13 @@ void stereo_switching_dec( sts[1]->last_extl = -1; move16(); - sts[1]->prev_bfi = sts[0]->prev_bfi; + sts[1]->prev_bfi = sts[0]->prev_bfi; /* Q0 */ move16(); // fix need to do correctly set32_fx( sts[1]->old_pitch_buf_fx, L_deposit_h( L_SUBFR ), 2 * NB_SUBFR16k ); - sts[1]->old_fpitchFB = L_deposit_h( 2 * L_SUBFR ); + sts[1]->old_fpitchFB = L_deposit_h( 2 * L_SUBFR ); /* 15Q16 */ move32(); /* reset CLDFB memories */ @@ -3254,13 +3254,13 @@ void stereo_switching_dec( set16_fx( sts[1]->mem_syn3_fx, 0, M ); set16_fx( sts[1]->mem_syn_r, 0, L_SYN_MEM ); - sts[1]->last_L_frame = sts[0]->last_L_frame; + sts[1]->last_L_frame = sts[0]->last_L_frame; /* Q0 */ move16(); #ifndef FIX_918_WRONG_SCALING_ON_MODE_SWITCHING Copy_Scale_sig( sts[0]->old_exc_fx, sts[1]->old_exc_fx, L_EXC_MEM_DEC, sub( sts[1]->Q_exc, sts[0]->Q_exc ) ); #else /* Should not force sts[1]->Q_exc on the data of st[0], instead it better to just reuse the current scaling of st[0]*/ - Copy( sts[0]->old_exc_fx, sts[1]->old_exc_fx, L_EXC_MEM_DEC ); + Copy( sts[0]->old_exc_fx, sts[1]->old_exc_fx, L_EXC_MEM_DEC ); /* Q_exc */ sts[1]->Q_exc = sts[0]->Q_exc; move16(); sts[1]->Q_exc_cng = sts[0]->Q_exc_cng; @@ -3292,27 +3292,27 @@ void stereo_switching_dec( move16(); #endif - Copy( sts[0]->lsf_old_fx, sts[1]->lsf_old_fx, M ); - Copy( sts[0]->lsp_old_fx, sts[1]->lsp_old_fx, M ); + Copy( sts[0]->lsf_old_fx, sts[1]->lsf_old_fx, M ); /* Q2.56 */ + Copy( sts[0]->lsp_old_fx, sts[1]->lsp_old_fx, M ); /* Q15 */ IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { - sts[1]->last_core = sts[0]->last_core; + sts[1]->last_core = sts[0]->last_core; /* Q0 */ move16(); - sts[1]->last_coder_type = sts[0]->last_coder_type; + sts[1]->last_coder_type = sts[0]->last_coder_type; /* Q0 */ move16(); // 32bit buffer - Copy32( sts[0]->hHQ_core->oldOut_fx, sts[1]->hHQ_core->oldOut_fx, L_FRAME48k ); - Copy32( sts[0]->delay_buf_out32_fx, sts[1]->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP ); - Copy32( sts[0]->hTcxDec->old_syn_Overl_32, sts[1]->hTcxDec->old_syn_Overl_32, 256 ); + Copy32( sts[0]->hHQ_core->oldOut_fx, sts[1]->hHQ_core->oldOut_fx, L_FRAME48k ); /* exp(exp_old_out) */ + Copy32( sts[0]->delay_buf_out32_fx, sts[1]->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP ); /* Q11 */ + Copy32( sts[0]->hTcxDec->old_syn_Overl_32, sts[1]->hTcxDec->old_syn_Overl_32, 256 ); /* Q_old_syn_Overl*/ // 16 bit buffer - Copy( sts[0]->hHQ_core->old_out_fx, sts[1]->hHQ_core->old_out_fx, L_FRAME48k ); + Copy( sts[0]->hHQ_core->old_out_fx, sts[1]->hHQ_core->old_out_fx, L_FRAME48k ); /* exp(exp_old_out) */ sts[1]->hHQ_core->Q_old_wtda = sts[0]->hHQ_core->Q_old_wtda; move16(); - Copy( sts[0]->delay_buf_out_fx, sts[1]->delay_buf_out_fx, HQ_DELTA_MAX * HQ_DELAY_COMP ); - Copy( sts[0]->hTcxDec->old_syn_Overl, sts[1]->hTcxDec->old_syn_Overl, 256 ); + Copy( sts[0]->delay_buf_out_fx, sts[1]->delay_buf_out_fx, HQ_DELTA_MAX * HQ_DELAY_COMP ); /* Q0 */ + Copy( sts[0]->hTcxDec->old_syn_Overl, sts[1]->hTcxDec->old_syn_Overl, 256 ); /* Q_old_syn_Overl*/ } } ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) @@ -3324,23 +3324,23 @@ void stereo_switching_dec( /* TD/DFT -> MDCT stereo switching (there is no TCX in the TD stereo secondary channel, or DFT stereo) */ IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && NE_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { - sts[1]->hTcxCfg->last_aldo = sts[0]->hTcxCfg->last_aldo; + sts[1]->hTcxCfg->last_aldo = sts[0]->hTcxCfg->last_aldo; /* Q0 */ move16(); - sts[1]->hTcxCfg->tcx_curr_overlap_mode = sts[0]->hTcxCfg->tcx_curr_overlap_mode; + sts[1]->hTcxCfg->tcx_curr_overlap_mode = sts[0]->hTcxCfg->tcx_curr_overlap_mode; /* Q0 */ move16(); - sts[1]->fscale = sts[0]->fscale; + sts[1]->fscale = sts[0]->fscale; /* Q0 */ move16(); - sts[1]->hTcxCfg->tcx_mdct_window_length = sts[0]->hTcxCfg->tcx_mdct_window_length; + sts[1]->hTcxCfg->tcx_mdct_window_length = sts[0]->hTcxCfg->tcx_mdct_window_length; /* Q0 */ move16(); - sts[1]->pit_res_max = sts[0]->pit_res_max; + sts[1]->pit_res_max = sts[0]->pit_res_max; /* Q0 */ move16(); - sts[1]->pit_res_max_past = sts[0]->pit_res_max_past; + sts[1]->pit_res_max_past = sts[0]->pit_res_max_past; /* Q0 */ move16(); - sts[1]->hTcxDec->L_frameTCX = sts[0]->hTcxDec->L_frameTCX; + sts[1]->hTcxDec->L_frameTCX = sts[0]->hTcxDec->L_frameTCX; /* Q0 */ move16(); - sts[1]->hTcxDec->conceal_eof_gain = sts[0]->hTcxDec->conceal_eof_gain; + sts[1]->hTcxDec->conceal_eof_gain = sts[0]->hTcxDec->conceal_eof_gain; /* Q14 */ move16(); - sts[1]->hTcxDec->conceal_eof_gain32 = sts[0]->hTcxDec->conceal_eof_gain32; + sts[1]->hTcxDec->conceal_eof_gain32 = sts[0]->hTcxDec->conceal_eof_gain32; /* sts[0]->hTcxDec->conceal_eof_gain_e */ move32(); sts[1]->hTcxDec->conceal_eof_gain_e = sts[0]->hTcxDec->conceal_eof_gain_e; move16(); @@ -3685,12 +3685,12 @@ void stereo_td2dft_update( } #else void stereo_td2dft_update_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word16 n, /* i : channel number */ - Word32 output_fx[], /* i/o: synthesis @internal Fs */ - Word32 synth_fx[], /* i/o: synthesis @output Fs */ - Word32 hb_synth_fx[], /* i/o: hb synthesis */ - const Word16 output_frame /* i : frame length */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word16 n, /* i : channel number Q0*/ + Word32 output_fx[], /* i/o: synthesis @internal Fs Q11*/ + Word32 synth_fx[], /* i/o: synthesis @output Fs Q11*/ + Word32 hb_synth_fx[], /* i/o: hb synthesis Q11*/ + const Word16 output_frame /* i : frame length Q0*/ ) { Word16 ovl, ovl_TCX, dft32ms_ovl, hq_delay_comp; @@ -3705,11 +3705,11 @@ void stereo_td2dft_update_fx( /* initialization */ sts = hCPE->hCoreCoder; - ovl = NS2SA_FX2( i_mult( sts[n]->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); + ovl = NS2SA_FX2( i_mult( sts[n]->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); /* Q0 */ move16(); - dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) + dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ move16(); - hq_delay_comp = NS2SA_FX2( sts[0]->output_Fs, DELAY_CLDFB_NS ); + hq_delay_comp = NS2SA_FX2( sts[0]->output_Fs, DELAY_CLDFB_NS ); /* Q0 */ move16(); test(); @@ -3721,12 +3721,12 @@ void stereo_td2dft_update_fx( IF( n == 0 ) { /* update DFT analysis overlap memory @internal_fs: core synthesis */ - Copy32( output_fx + sts[n]->L_frame - ovl, hCPE->input_mem_LB_fx[n], ovl ); + Copy32( output_fx + sts[n]->L_frame - ovl, hCPE->input_mem_LB_fx[n], ovl ); /* Q11 */ /* update DFT analysis overlap memory @internal_fs: BPF */ IF( sts[n]->p_bpf_noise_buf_32 ) { - Copy32( sts[n]->p_bpf_noise_buf_32 + sub( sts[n]->L_frame, ovl ), hCPE->input_mem_BPF_fx[n], ovl ); + Copy32( sts[n]->p_bpf_noise_buf_32 + sub( sts[n]->L_frame, ovl ), hCPE->input_mem_BPF_fx[n], ovl ); /* Q11 */ } @@ -3735,33 +3735,33 @@ void stereo_td2dft_update_fx( test(); IF( NE_16( sts[n]->extl, -1 ) || ( sts[n]->bws_cnt > 0 && sts[n]->core == ACELP_CORE ) ) { - Copy32( hb_synth_fx + sub( output_frame, dft32ms_ovl ), hCPE->input_mem_fx[n], dft32ms_ovl ); + Copy32( hb_synth_fx + sub( output_frame, dft32ms_ovl ), hCPE->input_mem_fx[n], dft32ms_ovl ); /* Q11 */ } } ELSE { /* update DFT analysis overlap memory @internal_fs: core synthesis, secondary channel */ - Copy32( output_fx + sub( sts[n]->L_frame, ovl ), hCPE->input_mem_LB_fx[n], ovl ); + Copy32( output_fx + sub( sts[n]->L_frame, ovl ), hCPE->input_mem_LB_fx[n], ovl ); /* Q11 */ } } ELSE /* TCX core */ { /* LB-TCX synthesis */ - Copy32( output_fx + sub( sts[n]->L_frame, ovl ), hCPE->input_mem_LB_fx[n], ovl ); + Copy32( output_fx + sub( sts[n]->L_frame, ovl ), hCPE->input_mem_LB_fx[n], ovl ); /* Q11 */ /* BPF */ IF( n == 0 && sts[n]->p_bpf_noise_buf_32 ) { - Copy32( sts[n]->p_bpf_noise_buf_32 + sub( sts[n]->L_frame, ovl ), hCPE->input_mem_BPF_fx[n], ovl ); + Copy32( sts[n]->p_bpf_noise_buf_32 + sub( sts[n]->L_frame, ovl ), hCPE->input_mem_BPF_fx[n], ovl ); /* Q11 */ } /* TCX synthesis (it was already delayed in TD stereo in core_switching_post_dec()) */ IF( sts[n]->hTcxDec != NULL ) { - ovl_TCX = NS2SA_FX2( sts[n]->hTcxDec->L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); + ovl_TCX = NS2SA_FX2( sts[n]->hTcxDec->L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); /* Q0 */ move16(); - Copy32( synth_fx + sts[n]->hTcxDec->L_frameTCX + hq_delay_comp - ovl_TCX, hCPE->input_mem_fx[n], ovl_TCX - hq_delay_comp ); - Copy32( sts[n]->delay_buf_out32_fx, hCPE->input_mem_fx[n] + ovl_TCX - hq_delay_comp, hq_delay_comp ); + Copy32( synth_fx + sts[n]->hTcxDec->L_frameTCX + hq_delay_comp - ovl_TCX, hCPE->input_mem_fx[n], sub( ovl_TCX, hq_delay_comp ) ); /* Q11 */ + Copy32( sts[n]->delay_buf_out32_fx, hCPE->input_mem_fx[n] + ovl_TCX - hq_delay_comp, hq_delay_comp ); /* Q11 */ } } } @@ -3776,21 +3776,21 @@ void stereo_td2dft_update_fx( /* TCX synthesis (it was already delayed in TD stereo in core_switching_post_dec()) */ IF( sts[n]->hTcxDec != NULL ) { - ovl_TCX = NS2SA_FX2( sts[n]->hTcxDec->L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); + ovl_TCX = NS2SA_FX2( sts[n]->hTcxDec->L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); /* Q0 */ move16(); - Copy32( synth_fx + add( sts[n]->hTcxDec->L_frameTCX, sub( hq_delay_comp, ovl_TCX ) ), hCPE->input_mem_fx[n], sub( ovl_TCX, hq_delay_comp ) ); - Copy32( sts[n]->delay_buf_out32_fx, hCPE->input_mem_fx[n] + sub( ovl_TCX, hq_delay_comp ), hq_delay_comp ); + Copy32( synth_fx + add( sts[n]->hTcxDec->L_frameTCX, sub( hq_delay_comp, ovl_TCX ) ), hCPE->input_mem_fx[n], sub( ovl_TCX, hq_delay_comp ) ); /* Q11 */ + Copy32( sts[n]->delay_buf_out32_fx, hCPE->input_mem_fx[n] + sub( ovl_TCX, hq_delay_comp ), hq_delay_comp ); /* Q11 */ } IF( EQ_16( n, 1 ) ) { - nsLB = NS2SA_FX2( L_mult0( sts[n]->L_frame, FRAMES_PER_SEC ), N_ZERO_MDCT_NS ); + nsLB = NS2SA_FX2( L_mult0( sts[n]->L_frame, FRAMES_PER_SEC ), N_ZERO_MDCT_NS ); /* Q0 */ move16(); - ns = NS2SA_FX2( sts[n]->output_Fs, N_ZERO_MDCT_NS ); + ns = NS2SA_FX2( sts[n]->output_Fs, N_ZERO_MDCT_NS ); /* Q0 */ move16(); - old_outLB_len = extract_l( Mpy_32_32( ( L_mult0( STEREO_MDCT2DFT_FADE_LEN_48k * FRAMES_PER_SEC, i_mult( 3, sts[0]->L_frame ) ) ), 44740 ) ); + old_outLB_len = extract_l( Mpy_32_32( ( L_mult0( STEREO_MDCT2DFT_FADE_LEN_48k * FRAMES_PER_SEC, i_mult( 3, sts[0]->L_frame ) ) ), 44740 ) ); /* Q0 */ move16(); - old_out_len = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_MDCT2DFT_FADE_LEN_48k ), 44740 ) ); + old_out_len = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_MDCT2DFT_FADE_LEN_48k ), 44740 ) ); /* Q0 */ move16(); /* update buffers used for fading when switching to DFT Stereo */ @@ -3802,17 +3802,17 @@ void stereo_td2dft_update_fx( FOR( Word32 i = 0; i < old_outLB_len; i++ ) #endif { - hCPE->old_outLB_mdct_fx[i] = L_shr( hCPE->old_outLB_mdct_fx[i], 1 ); + hCPE->old_outLB_mdct_fx[i] = L_shr( hCPE->old_outLB_mdct_fx[i], 1 ); /* Q11 */ move32(); } - v_add_fx( sts[0]->hHQ_core->oldOut_fx + ns, sts[1]->hHQ_core->oldOut_fx + ns, hCPE->old_out_mdct_fx, old_out_len ); + v_add_fx( sts[0]->hHQ_core->oldOut_fx + ns, sts[1]->hHQ_core->oldOut_fx + ns, hCPE->old_out_mdct_fx, old_out_len ); /* exp(exp_old_out) */ #ifndef MSAN_FIX for ( int i = 0; i < STEREO_MDCT2DFT_FADE_LEN_48k; i++ ) #else FOR( Word32 i = 0; i < old_out_len; i++ ) #endif { - hCPE->old_out_mdct_fx[i] = L_shr( hCPE->old_out_mdct_fx[i], 1 ); + hCPE->old_out_mdct_fx[i] = L_shr( hCPE->old_out_mdct_fx[i], 1 ); /* q_old_out_mdct */ move32(); } } @@ -3828,7 +3828,7 @@ void stereo_td2dft_update_fx( test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) && sts[n]->hTcxDec == NULL ) { - Copy32( output_fx + shr( sts[n]->L_frame, 1 ), hCPE->hStereoTD->TCX_old_syn_Overl_fx, shr( sts[n]->L_frame, 1 ) ); + Copy32( output_fx + shr( sts[n]->L_frame, 1 ), hCPE->hStereoTD->TCX_old_syn_Overl_fx, shr( sts[n]->L_frame, 1 ) ); /* Q11*/ } return; @@ -3878,8 +3878,8 @@ void stereo_mdct2dft_update( #else void stereo_mdct2dft_update_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 output0_fx[], /* i/o: synthesis @internal Fs, ch0 */ - Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 */ + Word32 output0_fx[], /* i/o: synthesis @internal Fs, ch0 Q11*/ + Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 Q11*/ ) { Word16 i; @@ -3894,20 +3894,20 @@ void stereo_mdct2dft_update_fx( st = hCPE->hCoreCoder[0]; - fade_len = extract_l( Mpy_32_32( imult3216( st->output_Fs, STEREO_MDCT2DFT_FADE_LEN_48k ), 44740 ) ); // 1/48000 = 44740 (Q31) - fade_len_LB = extract_l( Mpy_32_32( imult3216( 3 * STEREO_MDCT2DFT_FADE_LEN_48k * FRAMES_PER_SEC, st->L_frame ), 44740 ) ); // 1/48000 = 44740 (Q31) + fade_len = extract_l( Mpy_32_32( imult3216( st->output_Fs, STEREO_MDCT2DFT_FADE_LEN_48k ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ + fade_len_LB = extract_l( Mpy_32_32( imult3216( 3 * STEREO_MDCT2DFT_FADE_LEN_48k * FRAMES_PER_SEC, st->L_frame ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ SWITCH( st->output_Fs ) { case 16000: - tmpF_fx = 53687092; + tmpF_fx = 53687092; /* Q31 */ move32(); BREAK; case 32000: - tmpF_fx = 26843546; + tmpF_fx = 26843546; /* Q31 */ move32(); BREAK; case 48000: - tmpF_fx = 17895698; + tmpF_fx = 17895698; /* Q31 */ move32(); BREAK; } @@ -3916,49 +3916,49 @@ void stereo_mdct2dft_update_fx( Word32 descen_gain; IF( EQ_16( i, 0 ) ) { - descen_gain = ONE_IN_Q31; + descen_gain = ONE_IN_Q31; /* Q31 */ move32(); } ELSE { - descen_gain = W_extract_l( W_mult0_32_32( ( sub( fade_len, i ) ), tmpF_fx ) ); + descen_gain = W_extract_l( W_mult0_32_32( ( sub( fade_len, i ) ), tmpF_fx ) ); /* Q31 */ } - Word32 temp_a = Mpy_32_32( hCPE->old_out_mdct_fx[i], descen_gain ); - Word32 ascend_gain = W_extract_l( W_mult0_32_32( i, tmpF_fx ) ); - Word32 temp_b = Mpy_32_32( synth0_fx[i], ascend_gain ); - synth0_fx[i] = L_add_sat( temp_a, temp_b ); + Word32 temp_a = Mpy_32_32( hCPE->old_out_mdct_fx[i], descen_gain ); /* Q11 */ + Word32 ascend_gain = W_extract_l( W_mult0_32_32( i, tmpF_fx ) ); /* Q31 */ + Word32 temp_b = Mpy_32_32( synth0_fx[i], ascend_gain ); /* Q11 */ + synth0_fx[i] = L_add_sat( temp_a, temp_b ); /* Q11 */ move32(); } SWITCH( st->L_frame ) { case 80: - tmpF_fx = 71582792; + tmpF_fx = 71582792; /* Q31 */ move32(); BREAK; case 160: - tmpF_fx = 35791396; + tmpF_fx = 35791396; /* Q31 */ move32(); BREAK; case 256: - tmpF_fx = 22369622; + tmpF_fx = 22369622; /* Q31 */ move32(); BREAK; case 320: - tmpF_fx = 17895698; + tmpF_fx = 17895698; /* Q31 */ move32(); BREAK; case 512: - tmpF_fx = 11184811; + tmpF_fx = 11184811; /* Q31 */ move32(); BREAK; case 640: - tmpF_fx = 8947849; + tmpF_fx = 8947849; /* Q31 */ move32(); BREAK; case 960: - tmpF_fx = 5965232; + tmpF_fx = 5965232; /* Q31 */ move32(); BREAK; default: @@ -3969,17 +3969,17 @@ void stereo_mdct2dft_update_fx( Word32 descen_gain; IF( i == 0 ) { - descen_gain = ONE_IN_Q31; + descen_gain = ONE_IN_Q31; /* Q31 */ move32(); } ELSE { - descen_gain = W_extract_l( W_mult0_32_32( sub( fade_len_LB, i ), tmpF_fx ) ); + descen_gain = W_extract_l( W_mult0_32_32( sub( fade_len_LB, i ), tmpF_fx ) ); /* Q31 */ } - Word32 temp_a = Mpy_32_32( hCPE->old_outLB_mdct_fx[i], descen_gain ); - Word32 ascend_gain = W_extract_l( W_mult0_32_32( i, tmpF_fx ) ); - Word32 temp_b = Mpy_32_32( output0_fx[i], ascend_gain ); - output0_fx[i] = L_add_sat( temp_a, temp_b ); + Word32 temp_a = Mpy_32_32( hCPE->old_outLB_mdct_fx[i], descen_gain ); /* Q11 */ + Word32 ascend_gain = W_extract_l( W_mult0_32_32( i, tmpF_fx ) ); /* Q31 */ + Word32 temp_b = Mpy_32_32( output0_fx[i], ascend_gain ); /* Q11 */ + output0_fx[i] = L_add_sat( temp_a, temp_b ); /* Q11 */ } return; @@ -4025,11 +4025,12 @@ static float ncross_corr_self( } #else static Word32 ncross_corr_self_fx( - Word32 *signal_fx, - const Word16 x, - const Word16 y, - const Word16 corr_len, - const Word16 subsampling ) + Word32 *signal_fx, /* Q11*/ + const Word16 x, /* Q0 */ + const Word16 y, /* Q0 */ + const Word16 corr_len, /* Q0 */ + const Word16 subsampling /* Q0 */ +) { Word64 c_c_fx; Word32 c_c_fx_return; @@ -4048,20 +4049,20 @@ static Word32 ncross_corr_self_fx( move64(); energy_y_fx = 0; move64(); - signal_a_fx = &signal_fx[x]; - signal_b_fx = &signal_fx[y]; + signal_a_fx = &signal_fx[x]; /* Q11 */ + signal_b_fx = &signal_fx[y]; /* Q11 */ FOR( j = 0; j < corr_len; j += subsampling ) { - c_c_fx = W_add( c_c_fx, W_mult0_32_32( ( signal_a_fx[j] ), ( signal_b_fx[j] ) ) ); - energy_x_fx = W_add( energy_x_fx, W_mult0_32_32( ( signal_a_fx[j] ), ( signal_a_fx[j] ) ) ); - energy_y_fx = W_add( energy_y_fx, W_mult0_32_32( ( signal_b_fx[j] ), ( signal_b_fx[j] ) ) ); + c_c_fx = W_add( c_c_fx, W_mult0_32_32( ( signal_a_fx[j] ), ( signal_b_fx[j] ) ) ); /* 2 * Q11 */ + energy_x_fx = W_add( energy_x_fx, W_mult0_32_32( ( signal_a_fx[j] ), ( signal_a_fx[j] ) ) ); /* 2 * Q11 */ + energy_y_fx = W_add( energy_y_fx, W_mult0_32_32( ( signal_b_fx[j] ), ( signal_b_fx[j] ) ) ); /* 2 * Q11 */ } headroom_left_x = W_norm( energy_x_fx ); headroom_left_y = W_norm( energy_y_fx ); IF( LT_16( headroom_left_x, 32 ) ) { - energy_x_fx = W_shr( energy_x_fx, sub( 32, headroom_left_x ) ); + energy_x_fx = W_shr( energy_x_fx, sub( 32, headroom_left_x ) ); /* 2 * Q11 - (32 -headroom_left_x) */ x_q = sub( 31, ( sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_x ) ) ) ); } ELSE @@ -4070,7 +4071,7 @@ static Word32 ncross_corr_self_fx( } IF( LT_16( headroom_left_y, 32 ) ) { - energy_y_fx = W_shr( energy_y_fx, sub( 32, headroom_left_y ) ); + energy_y_fx = W_shr( energy_y_fx, sub( 32, headroom_left_y ) ); /* 2 * Q11 - (32 -headroom_left_y) */ y_q = sub( 31, ( sub( ( 2 * OUTPUT_Q ), ( sub( 32, headroom_left_y ) ) ) ) ); } ELSE @@ -4086,7 +4087,7 @@ static Word32 ncross_corr_self_fx( temp_x = Sqrt32( W_extract_l( energy_x_fx ), &x_q ); IF( x_q < 0 ) { - temp_x = L_shr( temp_x, i_mult( -1, x_q ) ); + temp_x = L_shr( temp_x, i_mult( -1, x_q ) ); /* Q0 */ x_q = 0; move16(); } @@ -4094,41 +4095,41 @@ static Word32 ncross_corr_self_fx( temp_y = Sqrt32( W_extract_l( energy_y_fx ), &y_q ); IF( y_q < 0 ) { - temp_y = L_shr( temp_y, i_mult( -1, y_q ) ); + temp_y = L_shr( temp_y, i_mult( -1, y_q ) ); /* Q0 */ y_q = 0; move16(); } - energy_xy_fx = Mpy_32_32( temp_x, temp_y ); + energy_xy_fx = Mpy_32_32( temp_x, temp_y ); /* x_q + y_q - 31 */ res_q = add( y_q, x_q ); IF( ( energy_xy_fx < L_shr( ONE_IN_Q31, res_q ) ) || energy_xy_fx == 0 ) { energy_xy_fx = ONE_IN_Q31; /* conceal silent frames */ res_q = 0; - c_c_fx = W_shl( c_c_fx, 31 - ( 2 * OUTPUT_Q ) ); + c_c_fx = W_shl( c_c_fx, 31 - ( 2 * OUTPUT_Q ) ); /* Q31 */ } ELSE { Word32 temp_x_inv = ISqrt32( W_extract_l( energy_x_fx ), &x_inv_q ); Word32 temp_y_inv = ISqrt32( W_extract_l( energy_y_fx ), &y_inv_q ); Word16 headroom_left_c_c; - energy_xy_fx = Mpy_32_32( temp_x_inv, temp_y_inv ); + energy_xy_fx = Mpy_32_32( temp_x_inv, temp_y_inv ); /* exp(x_inv_q + y_inv_q) */ res_q = add( x_inv_q, y_inv_q ); headroom_left_c_c = W_norm( c_c_fx ); c_c_fx_q = OUTPUT_Q * 2; move16(); IF( LT_16( headroom_left_c_c, 32 ) ) { - c_c_fx = W_shr( c_c_fx, extract_l( sub( 32, headroom_left_c_c ) ) ); + c_c_fx = W_shr( c_c_fx, extract_l( sub( 32, headroom_left_c_c ) ) ); /* c_c_fx_q - (32 - headroom_left_c_c) */ c_c_fx_q = sub( c_c_fx_q, sub( 32, headroom_left_c_c ) ); } - c_c_fx = W_deposit32_l( Mpy_32_32( W_extract_l( c_c_fx ), W_extract_l( energy_xy_fx ) ) ); + c_c_fx = W_deposit32_l( Mpy_32_32( W_extract_l( c_c_fx ), W_extract_l( energy_xy_fx ) ) ); /* c_c_fx_q + (31 - res_q) - 31 */ c_c_fx_q = add( c_c_fx_q, sub( sub( 31, res_q ), 31 ) ); - c_c_fx = W_extract_l( W_shl_sat_l( c_c_fx, extract_l( sub( 31, c_c_fx_q ) ) ) ); + c_c_fx = W_extract_l( W_shl_sat_l( c_c_fx, extract_l( sub( 31, c_c_fx_q ) ) ) ); /* Q31 */ } - c_c_fx_return = W_extract_l( c_c_fx ); + c_c_fx_return = W_extract_l( c_c_fx ); /* Q31 */ move32(); return c_c_fx_return; } @@ -4290,9 +4291,9 @@ void smooth_dft2td_transition( } #else void smooth_dft2td_transition_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx[CPE_CHANNELS], /* i/o: synthesis @external Fs */ - const Word16 output_frame /* i : output frame lenght */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx[CPE_CHANNELS], /* i/o: synthesis @external Fs Q11*/ + const Word16 output_frame /* i : output frame lenght Q0*/ ) { @@ -4318,106 +4319,106 @@ void smooth_dft2td_transition_fx( IF( ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && ( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) && ( EQ_16( sts[0]->clas_dec, VOICED_CLAS ) && LT_16( sts[0]->coder_type, TRANSITION ) && GT_16( sts[0]->coder_type, UNVOICED ) && GT_16( sts[0]->last_coder_type, UNVOICED ) && GT_16( sts[1]->coder_type, UNVOICED ) ) ) ) { /* length of OVA */ - ilen = shr( output_frame, 1 ); + ilen = shr( output_frame, 1 ); /* Q0 */ /* correlation length */ - corr_len = idiv1616( output_frame, 20 ); + corr_len = idiv1616( output_frame, 20 ); /* Q0 */ subsampl = 4; FOR( ch = 0; ch < hCPE->nchan_out; ch++ ) { /* core to external sampling frequency ratio */ Word16 q = norm_l( output_frame ); - Word32 check = BASOP_Util_Divide3232_Scale( output_frame, sts[ch]->L_frame, &q ); - fac_fs_fx = imult3216( check, shl( 1, add( 26 - 15, q ) ) ); + Word32 check = BASOP_Util_Divide3232_Scale( output_frame, sts[ch]->L_frame, &q ); /* q */ + fac_fs_fx = imult3216( check, shl( 1, add( 26 - 15, q ) ) ); /* Q11 */ /* Find minimum and maximum pitch*/ - ipit_min = add( minimum_32_fx( sts[ch]->old_pitch_buf_fx + 4, 4, &flen_fx ), 4 ); - ipit_max = add( maximum_32_fx( sts[ch]->old_pitch_buf_fx + 4, 4, &flen_fx ), 4 ); - ipit_min = (Word16) L_shr( L_add( Mpy_32_32( sts[ch]->old_pitch_buf_fx[ipit_min], fac_fs_fx ), ONE_IN_Q10 ), 11 ); - ipit_max = (Word16) L_shr( L_add( Mpy_32_32( sts[ch]->old_pitch_buf_fx[ipit_max], fac_fs_fx ), ONE_IN_Q10 ), 11 ); + ipit_min = add( minimum_32_fx( sts[ch]->old_pitch_buf_fx + 4, 4, &flen_fx ), 4 ); /* Q0 */ + ipit_max = add( maximum_32_fx( sts[ch]->old_pitch_buf_fx + 4, 4, &flen_fx ), 4 ); /* Q0 */ + ipit_min = (Word16) L_shr( L_add( Mpy_32_32( sts[ch]->old_pitch_buf_fx[ipit_min], fac_fs_fx ), ONE_IN_Q10 ), 11 ); /* Q0 */ + ipit_max = (Word16) L_shr( L_add( Mpy_32_32( sts[ch]->old_pitch_buf_fx[ipit_max], fac_fs_fx ), ONE_IN_Q10 ), 11 ); /* Q0 */ IF( GT_16( add( ipit_max, corr_len ), ilen ) ) /*ensure the search is performed on the available memory*/ { CONTINUE; } - lsearch = add( sub( ipit_max, ipit_min ), corr_len ); - lsearch = s_min( lsearch, shr( output_frame, 2 ) ); + lsearch = add( sub( ipit_max, ipit_min ), corr_len ); /* Q0 */ + lsearch = s_min( lsearch, shr( output_frame, 2 ) ); /* Q0 */ /* ptr init for search of the best correlation in the past frame */ - ptE_fx = hCPE->prev_synth_chs_fx[ch] + sub( output_frame, add( ipit_max, corr_len ) ); + ptE_fx = hCPE->prev_synth_chs_fx[ch] + sub( output_frame, add( ipit_max, corr_len ) ); /* Q11 */ idiff = 0; move16(); - fmaxcorr_fx = -ONE_IN_Q31; + fmaxcorr_fx = -ONE_IN_Q31; /* Q31 */ move32(); FOR( i = 0; i < lsearch; i++ ) { - ftmp_corr_fx = ncross_corr_self_fx( ptE_fx, i, ipit_max, corr_len, subsampl ); + ftmp_corr_fx = ncross_corr_self_fx( ptE_fx, i, ipit_max, corr_len, subsampl ); /* Q31 */ IF( GT_32( ftmp_corr_fx, fmaxcorr_fx ) ) { - idiff = i; + idiff = i; /* Q0 */ move16(); } - fmaxcorr_fx = L_max( fmaxcorr_fx, ftmp_corr_fx ); + fmaxcorr_fx = L_max( fmaxcorr_fx, ftmp_corr_fx ); /* Q11 */ } - ipit = sub( ipit_max, idiff ); + ipit = sub( ipit_max, idiff ); /* Q0 */ - ptO_fx = tmp_out_fx + output_frame; + ptO_fx = tmp_out_fx + output_frame; /* Q11 */ /* If the correlation is too low, don't use the prediction */ IF( LT_32( fmaxcorr_fx, DFT2TD_CORR_THRESH_FX ) ) { - Copy32( &output_fx[ch][0], ptO_fx, ilen ); + Copy32( &output_fx[ch][0], ptO_fx, ilen ); /* Q11 */ } ELSE { - Copy32( hCPE->prev_synth_chs_fx[ch], tmp_out_fx, output_frame ); - pt1_fx = tmp_out_fx + output_frame - ipit; + Copy32( hCPE->prev_synth_chs_fx[ch], tmp_out_fx, output_frame ); /* Q11 */ + pt1_fx = tmp_out_fx + output_frame - ipit; /* Q11 */ FOR( i = 0; i < ilen; i++ ) { - ptO_fx[i] = pt1_fx[i]; + ptO_fx[i] = pt1_fx[i]; /* Q11 */ move32(); } } /* Set buffer for the reserved buffer of the current frame */ - ptO2_fx = tmp_out2_fx + sub( output_frame, ilen ); + ptO2_fx = tmp_out2_fx + sub( output_frame, ilen ); /* Q11 */ set32_fx( tmp_out2_fx + sub( output_frame, ilen ), 0, ilen ); FOR( i = 0; i < output_frame; i++ ) { - tmp_out2_fx[i] = output_fx[ch][sub( output_frame, ( 1 + i ) )]; + tmp_out2_fx[i] = output_fx[ch][output_frame - 1 - i]; /* Q11 */ move32(); } /* ptr init for search of the best correlation of the current frame */ - ptE_fx = ptO2_fx - ( ipit_max + corr_len ); + ptE_fx = ptO2_fx - ( ipit_max + corr_len ); /* Q11 */ idiff = 0; move16(); - fmaxcorr_fx = -ONE_IN_Q31; + fmaxcorr_fx = -ONE_IN_Q31; /* Q31 */ move32(); FOR( i = 0; i < lsearch; i++ ) { - ftmp_corr_fx = ncross_corr_self_fx( ptE_fx, i, ipit_max, corr_len, subsampl ); + ftmp_corr_fx = ncross_corr_self_fx( ptE_fx, i, ipit_max, corr_len, subsampl ); /* Q31 */ IF( GT_32( ftmp_corr_fx, fmaxcorr_fx ) ) { - idiff = i; + idiff = i; /* Q0 */ move16(); } - fmaxcorr_fx = L_max( fmaxcorr_fx, ftmp_corr_fx ); + fmaxcorr_fx = L_max( fmaxcorr_fx, ftmp_corr_fx ); /* Q31 */ } - ipit = sub( ipit_max, idiff ); + ipit = sub( ipit_max, idiff ); /* Q0 */ /* If the correlation is too low, don't use the prediction */ IF( GT_32( fmaxcorr_fx, DFT2TD_CORR_THRESH_FX ) ) { - pt1_fx = tmp_out2_fx + sub( output_frame, add( ilen, ipit ) ); + pt1_fx = tmp_out2_fx + sub( output_frame, add( ilen, ipit ) ); /* Q11 */ FOR( i = 0; i < ilen; i++ ) { - ptO2_fx[i] = pt1_fx[i]; + ptO2_fx[i] = pt1_fx[i]; /* Q11 */ move32(); } } @@ -4426,15 +4427,15 @@ void smooth_dft2td_transition_fx( SWITCH( ilen ) { case 160: - flen_fx = 13421772; + flen_fx = 13421772; /* Q31 */ move32(); BREAK; case 320: - flen_fx = 6710886; + flen_fx = 6710886; /* Q31 */ move32(); BREAK; case 480: - flen_fx = 4473924; + flen_fx = 4473924; /* Q31 */ move32(); BREAK; default: @@ -4443,26 +4444,26 @@ void smooth_dft2td_transition_fx( } FOR( i = 0; i < 4; i++ ) { - Word64 temp_a = W_shr( W_add( W_mult0_32_32( sub( 4, i ), output_fx[ch][i] ), W_mult0_32_32( i, ptO_fx[i] ) ), 2 ) * ( ilen - i ); + Word64 temp_a = W_shr( W_add( W_mult0_32_32( sub( 4, i ), output_fx[ch][i] ), W_mult0_32_32( i, ptO_fx[i] ) ), 2 ) * ( ilen - i ); /* Q11 */ move64(); - Word64 temp_b = W_mult0_32_32( tmp_out2_fx[sub( output_frame, add( 1, i ) )], i ); - output_fx[ch][i] = W_extract_l( W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ) ); + Word64 temp_b = W_mult0_32_32( tmp_out2_fx[output_frame - 1 - i], i ); /* Q11 */ + output_fx[ch][i] = W_extract_l( W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ) ); /* Q11 */ move32(); } - FOR( ; i < sub( ilen, 4 ); i++ ) + FOR( ; i < ilen - 4; i++ ) { - Word64 temp_a = W_mult0_32_32( ptO_fx[i], sub( ilen, i ) ); - Word64 temp_b = W_mult0_32_32( tmp_out2_fx[sub( output_frame, add( 1, i ) )], i ); - output_fx[ch][i] = W_extract_l( W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ) ); + Word64 temp_a = W_mult0_32_32( ptO_fx[i], sub( ilen, i ) ); /* Q11 */ + Word64 temp_b = W_mult0_32_32( tmp_out2_fx[output_frame - 1 - i], i ); /* Q11 */ + output_fx[ch][i] = W_extract_l( W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ) ); /* Q11 */ move32(); } j = 0; move16(); FOR( ; i < ilen; i++ ) { - Word64 temp_a = (Word64) ptO_fx[i] * ( ilen - i ); - Word64 temp_b = W_shr( ( W_add( W_mult0_32_32( sub( 4, j ), tmp_out2_fx[sub( output_frame, add( 1, i ) )] ), W_mult0_32_32( j, output_fx[ch][i] ) ) * i ), 2 ); - output_fx[ch][i] = W_extract_l( W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ) ); + Word64 temp_a = W_mult0_32_32( ptO_fx[i], sub( ilen, i ) ); /* Q11 */ + Word64 temp_b = W_shr( ( W_add( W_mult0_32_32( sub( 4, j ), tmp_out2_fx[output_frame - 1 - i] ), W_mult0_32_32( j, output_fx[ch][i] ) ) * i ), 2 ); /* Q11 */ + output_fx[ch][i] = W_extract_l( W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ) ); /* Q11 */ move32(); j = add( j, 1 ); } @@ -4473,7 +4474,7 @@ void smooth_dft2td_transition_fx( /* Updates */ FOR( ch = 0; ch < hCPE->nchan_out; ch++ ) { - Copy32( output_fx[ch], hCPE->prev_synth_chs_fx[ch], output_frame ); + Copy32( output_fx[ch], hCPE->prev_synth_chs_fx[ch], output_frame ); /* Q11 */ } } diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index 55b793bda35bcd3ad29e1eb553fe879067435129..966f0d650edf17dcfb42cc7418fb2134cd9c4c96 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -83,28 +83,28 @@ void stereo_td_init_dec( #ifdef IVAS_FLOAT_FIXED void stereo_td_init_dec_fx( - STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const int16_t last_element_mode /* i : last element mode */ + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ + const Word16 last_element_mode /* i : last element mode Q0*/ ) { hStereoTD->tdm_SM_flag = 0; move16(); hStereoTD->tdm_last_SM_flag = 0; move16(); - hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; /* Q0 */ move16(); hStereoTD->tdm_prev_last_SM_flag = 0; move16(); hStereoTD->tdm_LRTD_flag = 0; move16(); // hStereoTD->prevSP_ratio = 0.5f; - hStereoTD->prevSP_ratio_fx = ONE_IN_Q14; //.5 + hStereoTD->prevSP_ratio_fx = ONE_IN_Q14; //.5 /* Q15 */ move16(); // hStereoTD->SP_ratio_LT = 0.0f; hStereoTD->SP_ratio_LT_fx = 0; move32(); // hStereoTD->c_LR_LT = 0.5f; - hStereoTD->c_LR_LT_fx = ONE_IN_Q30; //.5 + hStereoTD->c_LR_LT_fx = ONE_IN_Q30; //.5 /* Q31 */ move32(); hStereoTD->flag_skip_DMX = 0; @@ -112,9 +112,9 @@ void stereo_td_init_dec_fx( IF( EQ_16( last_element_mode, IVAS_CPE_MDCT ) ) { - hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; + hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; /* Q0 */ move16(); - hStereoTD->tdm_LRTD_flag = 1; + hStereoTD->tdm_LRTD_flag = 1; /* Q0 */ move16(); } @@ -138,11 +138,11 @@ Word32 power_table[32 + 1] = { 2137321728 }; // Q29 void tdm_configure_dec_fx( - const Word16 ivas_format, /* i : IVAS format */ - const Word16 ism_mode, /* i : ISM mode in combined format */ - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word16 *tdm_ratio_idx, /* o : ratio index */ - const Word16 nb_bits_metadata /* i : number of metadata bits */ + const Word16 ivas_format, /* i : IVAS format Q0*/ + const Word16 ism_mode, /* i : ISM mode in combined format Q0*/ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word16 *tdm_ratio_idx, /* o : ratio index Q0*/ + const Word16 nb_bits_metadata /* i : number of metadata bits Q0*/ ) { STEREO_TD_DEC_DATA_HANDLE hStereoTD; @@ -156,72 +156,72 @@ void tdm_configure_dec_fx( hStereoTD = hCPE->hStereoTD; sts = hCPE->hCoreCoder; - element_brate_adapt = L_add( hCPE->element_brate, hCPE->brate_surplus ); + element_brate_adapt = L_add( hCPE->element_brate, hCPE->brate_surplus ); /* Q0 */ IF( hCPE->brate_surplus < 0 ) { - temp = extract_l( L_negate( Mpy_32_32( L_abs( hCPE->brate_surplus ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); + temp = extract_l( L_negate( Mpy_32_32( L_abs( hCPE->brate_surplus ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); /* Q0 */ } ELSE { - temp = extract_l( Mpy_32_32( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + temp = extract_l( Mpy_32_32( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* Q0 */ } - bstr_last_pos = add( sub( div_l( hCPE->element_brate, FRAMES_PER_SEC / 2 ), nb_bits_metadata ), temp ); + bstr_last_pos = add( sub( div_l( hCPE->element_brate, FRAMES_PER_SEC / 2 ), nb_bits_metadata ), temp ); /* Q0 */ /*----------------------------------------------------------------* * Decode CoreCoder signaling *----------------------------------------------------------------*/ /* temporarily decode PCh signaling */ - bits_offset = sts[0]->next_bit_pos; + bits_offset = sts[0]->next_bit_pos; /* Q0 */ move16(); - core = get_indice_st( sts[0], hCPE->element_brate, bits_offset, 1 ); - bits_offset = add( bits_offset, 1 ); + core = get_indice_st( sts[0], hCPE->element_brate, bits_offset, 1 ); /* Q0 */ + bits_offset = add( bits_offset, 1 ); /* Q0 */ IF( core == ACELP_CORE && LT_32( hCPE->element_brate, IVAS_24k4 ) ) { - mod_ct = get_indice_st( sts[0], hCPE->element_brate, bits_offset, 3 ); + mod_ct = get_indice_st( sts[0], hCPE->element_brate, bits_offset, 3 ); /* Q0 */ /* Only transition mode is important to decoder, otherwise mod_ct is set to AUDIO only to easy debugging IF needed */ if ( NE_16( mod_ct, TRANSITION ) ) { - mod_ct = AUDIO; + mod_ct = AUDIO; /* Q0 */ move16(); } } ELSE /* core != ACELP_CORE */ { - mod_ct = AUDIO; /* coder_type == VOICED || coder_type == GENERIC */ + mod_ct = AUDIO; /* coder_type == VOICED || coder_type == GENERIC */ /* Q0 */ move16(); } /* Get few parameters needed to decode the bitrate allocated to each channel */ /* Get the coder_type of the secondary channel (last parameter on 2 bits) */ - sts[1]->coder_type = get_indice_st( sts[0], element_brate_adapt, sub( bstr_last_pos, TDM_SECONDARY_SIGNALLING ), TDM_SECONDARY_SIGNALLING ); + sts[1]->coder_type = get_indice_st( sts[0], element_brate_adapt, sub( bstr_last_pos, TDM_SECONDARY_SIGNALLING ), TDM_SECONDARY_SIGNALLING ); /* Q0 */ move16(); /* Get the LRTD config flag: 1 = LRTD configuration, favor closer bitrate per channel; 0 = Pri/Sec configuration, bitrates linked wrt. the mono */ - tdm_tmp_SM_LRTD_flag = s_and( sts[1]->coder_type, 0x1 ); - sts[1]->coder_type = shr( sts[1]->coder_type, 1 ); + tdm_tmp_SM_LRTD_flag = s_and( sts[1]->coder_type, 0x1 ); /* Q0 */ + sts[1]->coder_type = shr( sts[1]->coder_type, 1 ); /* Q0 */ move16(); hStereoTD->tdm_Pitch_reuse_flag = 0; move16(); IF( EQ_16( sts[1]->coder_type, 2 ) ) { - sts[1]->coder_type = GENERIC; + sts[1]->coder_type = GENERIC; /* Q0 */ move16(); } ELSE IF( EQ_16( sts[1]->coder_type, 3 ) ) { - sts[1]->coder_type = AUDIO; + sts[1]->coder_type = AUDIO; /* Q0 */ move16(); IF( LE_32( hCPE->element_brate, IVAS_24k4 ) ) { - hStereoTD->tdm_Pitch_reuse_flag = 1; + hStereoTD->tdm_Pitch_reuse_flag = 1; /* Q0 */ move16(); - sts[1]->coder_type = GENERIC; + sts[1]->coder_type = GENERIC; /* Q0 */ move16(); } } @@ -231,7 +231,7 @@ void tdm_configure_dec_fx( *----------------------------------------------------------------*/ /* Get the correlation ratio */ - *tdm_ratio_idx = get_indice_st( sts[0], element_brate_adapt, ( sub( bstr_last_pos, ( TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS ) ) ), TDM_RATIO_BITS ); + *tdm_ratio_idx = get_indice_st( sts[0], element_brate_adapt, ( sub( bstr_last_pos, ( TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS ) ) ), TDM_RATIO_BITS ); /* Q0 */ move16(); hStereoTD->tdm_use_IAWB_Ave_lpc = 0; @@ -239,43 +239,43 @@ void tdm_configure_dec_fx( IF( sts[1]->coder_type == INACTIVE ) { /* Get the flag on the LPC reusage type (primary channel of ave LPC */ - hStereoTD->tdm_use_IAWB_Ave_lpc = get_indice_st( sts[0], element_brate_adapt, sub( bstr_last_pos, TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS + TDM_LP_REUSE_BITS ), TDM_LP_REUSE_BITS ); + hStereoTD->tdm_use_IAWB_Ave_lpc = get_indice_st( sts[0], element_brate_adapt, sub( bstr_last_pos, TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS + TDM_LP_REUSE_BITS ), TDM_LP_REUSE_BITS ); /* Q0 */ move16(); - hStereoTD->tdm_lp_reuse_flag = 1; + hStereoTD->tdm_lp_reuse_flag = 1; /* Q0 */ move16(); } ELSE { /* Get the flag on the LPC reusage */ - hStereoTD->tdm_lp_reuse_flag = get_indice_st( sts[0], element_brate_adapt, sub( bstr_last_pos, TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS + TDM_LP_REUSE_BITS ), TDM_LP_REUSE_BITS ); + hStereoTD->tdm_lp_reuse_flag = get_indice_st( sts[0], element_brate_adapt, sub( bstr_last_pos, TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS + TDM_LP_REUSE_BITS ), TDM_LP_REUSE_BITS ); /* Q0 */ move16(); } - sts[0]->tdm_LRTD_flag = hStereoTD->tdm_LRTD_flag; /* the flag was already read in function stereo_memory_dec() */ + sts[0]->tdm_LRTD_flag = hStereoTD->tdm_LRTD_flag; /* the flag was already read in function stereo_memory_dec() Q0*/ move16(); - sts[1]->tdm_LRTD_flag = hStereoTD->tdm_LRTD_flag; + sts[1]->tdm_LRTD_flag = hStereoTD->tdm_LRTD_flag; /* Q0 */ move16(); - tdm_inst_ratio_idx = *tdm_ratio_idx; + tdm_inst_ratio_idx = *tdm_ratio_idx; /* Q0 */ move16(); /* update past tdm_SM_flag */ - hStereoTD->tdm_prev_last_SM_flag = hStereoTD->tdm_last_SM_flag; + hStereoTD->tdm_prev_last_SM_flag = hStereoTD->tdm_last_SM_flag; /* Q0 */ move16(); - hStereoTD->tdm_last_SM_flag = hStereoTD->tdm_SM_flag; + hStereoTD->tdm_last_SM_flag = hStereoTD->tdm_SM_flag; /* Q0 */ move16(); - idx_LRTD_pri_side = -1; + idx_LRTD_pri_side = -1; /* Q0 */ move16(); IF( EQ_16( hStereoTD->tdm_LRTD_flag, 1 ) ) { - idx_LRTD_pri_side = tdm_tmp_SM_LRTD_flag; + idx_LRTD_pri_side = tdm_tmp_SM_LRTD_flag; /* Q0 */ move16(); hStereoTD->tdm_SM_flag = 0; move16(); IF( tdm_inst_ratio_idx == TDM_NQ ) { - hStereoTD->flag_skip_DMX = 1; + hStereoTD->flag_skip_DMX = 1; /* Q0 */ move16(); } ELSE @@ -284,17 +284,17 @@ void tdm_configure_dec_fx( move16(); } /* Set primary channel */ - *tdm_ratio_idx = LRTD_STEREO_RIGHT_IS_PRIM; + *tdm_ratio_idx = LRTD_STEREO_RIGHT_IS_PRIM; /* Q0 */ move16(); if ( EQ_16( idx_LRTD_pri_side, 1 ) ) { - *tdm_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; + *tdm_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; /* Q0 */ move16(); } } ELSE { - hStereoTD->tdm_SM_flag = tdm_tmp_SM_LRTD_flag; + hStereoTD->tdm_SM_flag = tdm_tmp_SM_LRTD_flag; /* Q0 */ move16(); if ( EQ_16( hCPE->nchan_out, 1 ) ) { @@ -308,7 +308,7 @@ void tdm_configure_dec_fx( test(); IF( sts[1]->coder_type == INACTIVE && ( GE_16( *tdm_ratio_idx, 29 ) || LE_16( *tdm_ratio_idx, 1 ) ) ) { - hStereoTD->tdm_lp_reuse_flag = hStereoTD->tdm_use_IAWB_Ave_lpc; + hStereoTD->tdm_lp_reuse_flag = hStereoTD->tdm_use_IAWB_Ave_lpc; /* Q0 */ move16(); hStereoTD->tdm_use_IAWB_Ave_lpc = 0; move16(); @@ -326,43 +326,43 @@ void tdm_configure_dec_fx( { tmpS = get_indice_st( sts[0], element_brate_adapt, add( sub( bstr_last_pos, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ), STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS ), STEREO_BITS_TCA_GD ); } - hCPE->hStereoDftDmx->targetGain_fx = power_table[tmpS]; + hCPE->hStereoDftDmx->targetGain_fx = power_table[tmpS]; /* Q29 */ move32(); } ELSE { IF( hStereoTD->tdm_LRTD_flag == 0 ) { - hCPE->hStereoTCA->refChanIndx = get_indice_st( sts[0], element_brate_adapt, sub( bstr_last_pos, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ), STEREO_BITS_TCA_CHAN ); + hCPE->hStereoTCA->refChanIndx = get_indice_st( sts[0], element_brate_adapt, sub( bstr_last_pos, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ), STEREO_BITS_TCA_CHAN ); /* Q0 */ move16(); - hCPE->hStereoTCA->indx_ica_NCShift = get_indice_st( sts[0], element_brate_adapt, add( sub( bstr_last_pos, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ), STEREO_BITS_TCA_CHAN ), STEREO_BITS_TCA_CORRSTATS ); + hCPE->hStereoTCA->indx_ica_NCShift = get_indice_st( sts[0], element_brate_adapt, add( sub( bstr_last_pos, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ), STEREO_BITS_TCA_CHAN ), STEREO_BITS_TCA_CORRSTATS ); /* Q0 */ move16(); - hCPE->hStereoTCA->indx_ica_gD = get_indice_st( sts[0], element_brate_adapt, add( sub( bstr_last_pos, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ), STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS ), STEREO_BITS_TCA_GD ); + hCPE->hStereoTCA->indx_ica_gD = get_indice_st( sts[0], element_brate_adapt, add( sub( bstr_last_pos, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ), STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS ), STEREO_BITS_TCA_GD ); /* Q0 */ move16(); } ELSE { - hCPE->hStereoTCA->refChanIndx = L_CH_INDX; + hCPE->hStereoTCA->refChanIndx = L_CH_INDX; /* Q0 */ move16(); - hCPE->hStereoTCA->indx_ica_NCShift = 0; + hCPE->hStereoTCA->indx_ica_NCShift = 0; /* Q0 */ move16(); - hCPE->hStereoTCA->indx_ica_gD = 20; + hCPE->hStereoTCA->indx_ica_gD = 20; /* Q0 */ move16(); } - hCPE->hStereoTCA->targetGain_fx = power_table[hCPE->hStereoTCA->indx_ica_gD]; + hCPE->hStereoTCA->targetGain_fx = power_table[hCPE->hStereoTCA->indx_ica_gD]; /* Q29 */ move32(); } /* set the BW of the secondary channel */ IF( hStereoTD->tdm_LRTD_flag && GE_16( sts[1]->bits_frame_channel, IVAS_16k4 / FRAMES_PER_SEC ) ) { /* set BW of the secondary channel in LRTD stereo mode as the BW of the primary channel at higher bitrates */ - sts[1]->bwidth = sts[0]->bwidth; + sts[1]->bwidth = sts[0]->bwidth; /* Q0 */ move16(); } ELSE { /* limit BW of the secondary channel in LRTD mode to WB for low bitrates */ - sts[1]->bwidth = WB; + sts[1]->bwidth = WB; /* Q0 */ move16(); } @@ -608,15 +608,15 @@ void tdm_upmix_plain( return; } void tdm_upmix_plain_fx( - Word32 Left_fx[], /* o : left channel */ - Word32 Right_fx[], /* o : right channel */ - const Word32 PCh_2_L_fx[], /* i : primary channel */ - const Word32 SCh_2_R_fx[], /* i : secondary channel */ - const Word32 LR_ratio_fx, /* i : mixing ratio */ - const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration */ - const Word16 start_index, /* i : start index */ - const Word16 end_index, /* i : end index */ - const Word16 plus_minus_flag /* i : plus/minus flag */ + Word32 Left_fx[], /* o : left channel Qx*/ + Word32 Right_fx[], /* o : right channel Qx*/ + const Word32 PCh_2_L_fx[], /* i : primary channel Qx*/ + const Word32 SCh_2_R_fx[], /* i : secondary channel Qx*/ + const Word32 LR_ratio_fx, /* i : mixing ratio Q31*/ + const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration Q31*/ + const Word16 start_index, /* i : start index Q0*/ + const Word16 end_index, /* i : end index Q0*/ + const Word16 plus_minus_flag /* i : plus/minus flag Q0*/ ) { Word16 i; @@ -625,11 +625,11 @@ void tdm_upmix_plain_fx( { FOR( i = start_index; i < end_index; i++ ) { - Word32 temp_left = L_add( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ); - Left_fx[i] = L_shl_sat( Mpy_32_32( temp_left, inv_den_LR_ratio_fx ), 1 ); + Word32 temp_left = L_add( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ); /* Qx */ + Left_fx[i] = L_shl_sat( Mpy_32_32( temp_left, inv_den_LR_ratio_fx ), 1 ); /* Qx + 1 */ move32(); - Word32 temp_right = L_add( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), L_negate( LR_ratio_fx ) ), PCh_2_L_fx[i] ); - Right_fx[i] = L_shl_sat( Mpy_32_32( temp_right, inv_den_LR_ratio_fx ), 1 ); + Word32 temp_right = L_add( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), L_negate( LR_ratio_fx ) ), PCh_2_L_fx[i] ); /* Qx */ + Right_fx[i] = L_shl_sat( Mpy_32_32( temp_right, inv_den_LR_ratio_fx ), 1 ); /* Qx + 1 */ move32(); } } @@ -637,11 +637,11 @@ void tdm_upmix_plain_fx( { FOR( i = start_index; i < end_index; i++ ) { - Word32 temp_left = L_sub( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ); - Left_fx[i] = L_shl_sat( Mpy_32_32( temp_left, inv_den_LR_ratio_fx ), 1 ); + Word32 temp_left = L_sub( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ); /* Qx */ + Left_fx[i] = L_shl_sat( Mpy_32_32( temp_left, inv_den_LR_ratio_fx ), 1 ); /* Qx + 1 */ move32(); - Word32 temp_right = L_sub( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), PCh_2_L_fx[i] ); - Right_fx[i] = L_shl_sat( Mpy_32_32( temp_right, inv_den_LR_ratio_fx ), 1 ); + Word32 temp_right = L_sub( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), PCh_2_L_fx[i] ); /* Qx */ + Right_fx[i] = L_shl_sat( Mpy_32_32( temp_right, inv_den_LR_ratio_fx ), 1 ); /* Qx + 1 */ move32(); } } @@ -727,7 +727,7 @@ static void tdm_upmix_fade( } #endif - +// Q31 Word32 inv_time[960 + 1] = { 0, 2147483647, 1073741824, 715827904, 536870912, 429496736, 357913952, 306783392, 268435456, 238609296, 214748368, 195225792, 178956976, 165191056, 153391696, 143165584, @@ -853,102 +853,102 @@ Word32 inv_time[960 + 1] = { }; #ifdef IVAS_FLOAT_FIXED static void tdm_upmix_fade_fx( - Word32 Left_fx[], /* o : left channel */ - Word32 Right_fx[], /* o : right channel */ - const Word32 PCh_2_L_fx[], /* i : primary channel */ - const Word32 SCh_2_R_fx[], /* i : secondary channel */ - const Word32 LR_ratio_mem_fx, /* i : last mixing ratio */ - const Word32 inv_den_LR_ratio_mem_fx, /* i : last inverse mixing ration */ - const Word32 LR_ratio_fx, /* i : mixing ratio */ - const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration */ - const Word16 start_index, /* i : start index */ - const Word16 end_index, /* i : end index */ - const Word16 fading_type /* i : fading type */ + Word32 Left_fx[], /* o : left channel Qx*/ + Word32 Right_fx[], /* o : right channel Qx*/ + const Word32 PCh_2_L_fx[], /* i : primary channel Qx*/ + const Word32 SCh_2_R_fx[], /* i : secondary channel Qx*/ + const Word32 LR_ratio_mem_fx, /* i : last mixing ratio Q31*/ + const Word32 inv_den_LR_ratio_mem_fx, /* i : last inverse mixing ration Q31*/ + const Word32 LR_ratio_fx, /* i : mixing ratio Q31*/ + const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration Q31*/ + const Word16 start_index, /* i : start index Q0*/ + const Word16 end_index, /* i : end index Q0*/ + const Word16 fading_type /* i : fading type Q0*/ ) { Word16 i; Word32 step_fx, step2_fx, fade_in_fx, fade_out_fx; step_fx = inv_time[end_index - start_index]; - fade_out_fx = ONE_IN_Q31; + fade_out_fx = ONE_IN_Q31; /* Q31 */ move32(); fade_in_fx = 0; move32(); - fade_out_fx = Mpy_32_32( fade_out_fx, inv_den_LR_ratio_mem_fx ); - fade_in_fx = Mpy_32_32( fade_in_fx, inv_den_LR_ratio_fx ); - step2_fx = Mpy_32_32( step_fx, inv_den_LR_ratio_fx ); - step_fx = Mpy_32_32( step_fx, inv_den_LR_ratio_mem_fx ); + fade_out_fx = Mpy_32_32( fade_out_fx, inv_den_LR_ratio_mem_fx ); /* Q31 */ + fade_in_fx = Mpy_32_32( fade_in_fx, inv_den_LR_ratio_fx ); /* Q31 */ + step2_fx = Mpy_32_32( step_fx, inv_den_LR_ratio_fx ); /* Q31 */ + step_fx = Mpy_32_32( step_fx, inv_den_LR_ratio_mem_fx ); /* Q31 */ IF( fading_type == 0 ) /* Switching from YX scheme to SM scheme */ { FOR( i = start_index; i < end_index; i++ ) { - Word32 temp_left1 = Mpy_32_32( L_add( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), SCh_2_R_fx[i] ), fade_out_fx ); - Word32 temp_left2 = Mpy_32_32( L_sub( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ), fade_in_fx ); - Left_fx[i] = L_shl_sat( L_add( temp_left1, temp_left2 ), 1 ); + Word32 temp_left1 = Mpy_32_32( L_add( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), SCh_2_R_fx[i] ), fade_out_fx ); /* Qx */ + Word32 temp_left2 = Mpy_32_32( L_sub( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ), fade_in_fx ); /* Qx */ + Left_fx[i] = L_shl_sat( L_add( temp_left1, temp_left2 ), 1 ); /* Qx + 1 */ move32(); - Word32 temp_right1 = Mpy_32_32( L_add( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), L_negate( LR_ratio_mem_fx ) ), PCh_2_L_fx[i] ), fade_out_fx ); - Word32 temp_right2 = Mpy_32_32( L_sub( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), PCh_2_L_fx[i] ), fade_in_fx ); - Right_fx[i] = L_shl_sat( L_add( temp_right1, temp_right2 ), 1 ); + Word32 temp_right1 = Mpy_32_32( L_add( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), L_negate( LR_ratio_mem_fx ) ), PCh_2_L_fx[i] ), fade_out_fx ); /* Qx */ + Word32 temp_right2 = Mpy_32_32( L_sub( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), PCh_2_L_fx[i] ), fade_in_fx ); /* Qx */ + Right_fx[i] = L_shl_sat( L_add( temp_right1, temp_right2 ), 1 ); /* Qx + 1 */ move32(); - fade_in_fx = L_add( fade_in_fx, step2_fx ); - fade_out_fx = L_sub( fade_out_fx, step_fx ); + fade_in_fx = L_add( fade_in_fx, step2_fx ); /* Q31 */ + fade_out_fx = L_sub( fade_out_fx, step_fx ); /* Q31 */ } } ELSE IF( EQ_16( fading_type, 1 ) ) /* SM scheme */ { FOR( i = start_index; i < end_index; i++ ) { - Word32 temp_left1 = Mpy_32_32( L_sub( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), SCh_2_R_fx[i] ), fade_out_fx ); - Word32 temp_left2 = Mpy_32_32( L_sub( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ), fade_in_fx ); - Left_fx[i] = L_shl_sat( L_add( temp_left1, temp_left2 ), 1 ); + Word32 temp_left1 = Mpy_32_32( L_sub( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), SCh_2_R_fx[i] ), fade_out_fx ); /* Qx */ + Word32 temp_left2 = Mpy_32_32( L_sub( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ), fade_in_fx ); /* Qx */ + Left_fx[i] = L_shl_sat( L_add( temp_left1, temp_left2 ), 1 ); /* Qx + 1 */ move32(); - Word32 temp_right1 = Mpy_32_32( L_sub( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), PCh_2_L_fx[i] ), fade_out_fx ); - Word32 temp_right2 = Mpy_32_32( L_sub( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), PCh_2_L_fx[i] ), fade_in_fx ); - Right_fx[i] = L_shl_sat( L_add( temp_right1, temp_right2 ), 1 ); + Word32 temp_right1 = Mpy_32_32( L_sub( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), PCh_2_L_fx[i] ), fade_out_fx ); /* Qx */ + Word32 temp_right2 = Mpy_32_32( L_sub( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), PCh_2_L_fx[i] ), fade_in_fx ); /* Qx */ + Right_fx[i] = L_shl_sat( L_add( temp_right1, temp_right2 ), 1 ); /* Qx + 1 */ move32(); - fade_in_fx = L_add( fade_in_fx, step2_fx ); - fade_out_fx = L_sub( fade_out_fx, step_fx ); + fade_in_fx = L_add( fade_in_fx, step2_fx ); /* Q31 */ + fade_out_fx = L_sub( fade_out_fx, step_fx ); /* Q31 */ } } ELSE IF( EQ_16( fading_type, 2 ) ) /* Switching from SM scheme to YX scheme */ { FOR( i = start_index; i < end_index; i++ ) { - Word32 temp_left1 = Mpy_32_32( L_sub( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), SCh_2_R_fx[i] ), fade_out_fx ); - Word32 temp_left2 = Mpy_32_32( L_add( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ), fade_in_fx ); - Left_fx[i] = L_shl_sat( L_add( temp_left1, temp_left2 ), 1 ); + Word32 temp_left1 = Mpy_32_32( L_sub( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), SCh_2_R_fx[i] ), fade_out_fx ); /* Qx */ + Word32 temp_left2 = Mpy_32_32( L_add( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ), fade_in_fx ); /* Qx */ + Left_fx[i] = L_shl_sat( L_add( temp_left1, temp_left2 ), 1 ); /* Qx + 1 */ move32(); - Word32 temp_right1 = Mpy_32_32( L_sub( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), PCh_2_L_fx[i] ), fade_out_fx ); - Word32 temp_right2 = Mpy_32_32( L_add( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), L_negate( LR_ratio_fx ) ), PCh_2_L_fx[i] ), fade_in_fx ); - Right_fx[i] = L_shl_sat( L_add( temp_right1, temp_right2 ), 1 ); + Word32 temp_right1 = Mpy_32_32( L_sub( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), PCh_2_L_fx[i] ), fade_out_fx ); /* Qx */ + Word32 temp_right2 = Mpy_32_32( L_add( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), L_negate( LR_ratio_fx ) ), PCh_2_L_fx[i] ), fade_in_fx ); /* Qx */ + Right_fx[i] = L_shl_sat( L_add( temp_right1, temp_right2 ), 1 ); /* Qx + 1 */ move32(); - fade_in_fx = L_add( fade_in_fx, step2_fx ); - fade_out_fx = L_sub( fade_out_fx, step_fx ); + fade_in_fx = L_add( fade_in_fx, step2_fx ); /* Q31 */ + fade_out_fx = L_sub( fade_out_fx, step_fx ); /* Q31 */ } } ELSE IF( EQ_16( fading_type, 3 ) ) /* YX scheme */ { FOR( i = start_index; i < end_index; i++ ) { - Word32 temp_left1 = Mpy_32_32( L_add( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), SCh_2_R_fx[i] ), fade_out_fx ); - Word32 temp_left2 = Mpy_32_32( L_add( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ), fade_in_fx ); - Left_fx[i] = L_shl_sat( L_add( temp_left1, temp_left2 ), 1 ); + Word32 temp_left1 = Mpy_32_32( L_add( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), SCh_2_R_fx[i] ), fade_out_fx ); /* Qx */ + Word32 temp_left2 = Mpy_32_32( L_add( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ), fade_in_fx ); /* Qx */ + Left_fx[i] = L_shl_sat( L_add( temp_left1, temp_left2 ), 1 ); /* Qx + 1 */ move32(); - Word32 temp_right1 = Mpy_32_32( L_add( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), L_negate( LR_ratio_mem_fx ) ), PCh_2_L_fx[i] ), fade_out_fx ); - Word32 temp_right2 = Mpy_32_32( L_add( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), L_negate( LR_ratio_fx ) ), PCh_2_L_fx[i] ), fade_in_fx ); - Right_fx[i] = L_shl_sat( L_add( temp_right1, temp_right2 ), 1 ); + Word32 temp_right1 = Mpy_32_32( L_add( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), L_negate( LR_ratio_mem_fx ) ), PCh_2_L_fx[i] ), fade_out_fx ); /* Qx */ + Word32 temp_right2 = Mpy_32_32( L_add( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), L_negate( LR_ratio_fx ) ), PCh_2_L_fx[i] ), fade_in_fx ); /* Qx */ + Right_fx[i] = L_shl_sat( L_add( temp_right1, temp_right2 ), 1 ); /* Qx + 1 */ move32(); - fade_in_fx = L_add( fade_in_fx, step2_fx ); - fade_out_fx = L_sub( fade_out_fx, step_fx ); + fade_in_fx = L_add( fade_in_fx, step2_fx ); /* Q31 */ + fade_out_fx = L_sub( fade_out_fx, step_fx ); /* Q31 */ } } @@ -1125,11 +1125,11 @@ void stereo_tdm_combine( #else void stereo_tdm_combine_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *PCh_2_L_fx, /* i/o: Primary channel -> output as left channel */ - Word32 *SCh_2_R_fx, /* i/o: Secondary channel -> output as right channel*/ - const Word16 output_frame, /* i : Number of samples */ - const Word16 flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis */ - const Word16 tdm_ratio_idx /* i : TDM ratio index */ + Word32 *PCh_2_L_fx, /* i/o: Primary channel -> output as left channel Qx*/ + Word32 *SCh_2_R_fx, /* i/o: Secondary channel -> output as right channel Qx*/ + const Word16 output_frame, /* i : Number of samples Q0*/ + const Word16 flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis Q0*/ + const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ ) { Word16 i; @@ -1142,33 +1142,33 @@ void stereo_tdm_combine_fx( Word16 tdm_last_ratio_idx = hCPE->hStereoTD->tdm_last_ratio_idx; move16(); - output_Fs = hCPE->hCoreCoder[0]->output_Fs; + output_Fs = hCPE->hCoreCoder[0]->output_Fs; /* Q0 */ move32(); - tdm_n_OVA = NS2SA( output_Fs, TDM_L_NOVA_NS ); + tdm_n_OVA = NS2SA( output_Fs, TDM_L_NOVA_NS ); /* Q0 */ move16(); IF( flag_HB ) { - upmixing_delay = NS2SA( output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ); + upmixing_delay = NS2SA( output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ); /* Q0 */ move16(); } ELSE { - upmixing_delay = NS2SA( output_Fs, ACELP_LOOK_NS + DELAY_CLDFB_NS ); + upmixing_delay = NS2SA( output_Fs, ACELP_LOOK_NS + DELAY_CLDFB_NS ); /* Q0 */ move16(); } - LR_ratio_fx = tdm_ratio_tabl_fx[tdm_ratio_idx]; + LR_ratio_fx = tdm_ratio_tabl_fx[tdm_ratio_idx]; /* Q31 */ move32(); - LR_ratio_mem_fx = tdm_ratio_tabl_fx[tdm_last_ratio_idx]; + LR_ratio_mem_fx = tdm_ratio_tabl_fx[tdm_last_ratio_idx]; /* Q31 */ move32(); IF( hCPE->hStereoTD->flag_skip_DMX ) { stereo_tdm_coder_type = 10; /* no DMX */ move16(); - Copy32( PCh_2_L_fx, Left_fx, output_frame ); - Copy32( SCh_2_R_fx, Right_fx, output_frame ); + Copy32( PCh_2_L_fx, Left_fx, output_frame ); /* Qx */ + Copy32( SCh_2_R_fx, Right_fx, output_frame ); /* Qx */ } ELSE IF( EQ_16( hCPE->hStereoTD->tdm_last_SM_flag, 1 ) ) { @@ -1179,7 +1179,7 @@ void stereo_tdm_combine_fx( } ELSE { - stereo_tdm_coder_type = 1; /* mode 2 : SM scheme*/ + stereo_tdm_coder_type = 1; /* mode 2 : SM scheme Q0*/ move16(); } } @@ -1262,9 +1262,9 @@ void stereo_tdm_combine_fx( } FOR( i = 0; i < output_frame; i++ ) { - PCh_2_L_fx[i] = Left_fx[i]; + PCh_2_L_fx[i] = Left_fx[i]; /* Qx */ move32(); - SCh_2_R_fx[i] = Right_fx[i]; + SCh_2_R_fx[i] = Right_fx[i]; /* Qx */ move32(); } @@ -1275,12 +1275,12 @@ void stereo_tdm_combine_fx( IF( hCPE->hStereoDftDmx != NULL ) { - fac_fx = ONE_IN_Q29; + fac_fx = ONE_IN_Q29; /* Q29 */ move32(); } ELSE { - fac_fx = hCPE->hStereoTCA->targetGain_fx; + fac_fx = hCPE->hStereoTCA->targetGain_fx; /* Q29 */ move32(); } @@ -1292,29 +1292,29 @@ void stereo_tdm_combine_fx( SWITCH( output_Fs ) { case ( 16000 ): - step = 15339168; + step = 15339168; /* Q31 */ move32(); BREAK; case ( 32000 ): - step = 7669584; + step = 7669584; /* Q31 */ move32(); BREAK; case ( 48000 ): - step = 5113056; + step = 5113056; /* Q31 */ move32(); BREAK; default: assert( 0 ); BREAK; } - incr_fx = Mpy_32_32( L_sub( ONE_IN_Q29, fac_fx ), step ); + incr_fx = Mpy_32_32( L_sub( ONE_IN_Q29, fac_fx ), step ); /* Q29 */ FOR( i = 0; i < NS2SA( output_Fs, ACELP_LOOK_NS ); i++ ) { - PCh_2_L_fx[i] = L_shl_sat( Mpy_32_32( PCh_2_L_fx[i], fac_fx ), 2 ); + PCh_2_L_fx[i] = L_shl_sat( Mpy_32_32( PCh_2_L_fx[i], fac_fx ), 2 ); /* Qx */ move32(); - fac_fx = L_add( incr_fx, fac_fx ); + fac_fx = L_add( incr_fx, fac_fx ); /* Q29 */ } } } diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index e33ad58e320a79f8a4959b13be4d341b875ae496..e0c210a2f5d38e0e9930c6ebb6b6c76d2ccae470 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -92,62 +92,67 @@ static void flushToZeroArray( float arr[MAX_OUTPUT_CHANNELS], const int16_t leng static void flushToZeroMat( float mat[][MAX_OUTPUT_CHANNELS], const int16_t m, const int16_t n ); #else static void HouseholderReduction_fx( - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], - Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], - Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_Left_e) */ + Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* exp(singularValues_fx_e) */ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_Left_e) */ + Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* exp(secDiag_fx_e) */ Word16 singularVectors_Left_e, Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], Word16 *secDiag_fx_e, - const int16_t nChannelsL, - const int16_t nChannelsC, - Word32 *eps_x_fx, + const Word16 nChannelsL, /* Q0 */ + const Word16 nChannelsC, /* Q0 */ + Word32 *eps_x_fx, /* exp(eps_x_fx_e) */ Word16 *eps_x_fx_e ); static void biDiagonalReductionLeft_fx( - Word32 singularVectors[][MAX_OUTPUT_CHANNELS], - Word32 singularValues[MAX_OUTPUT_CHANNELS], - Word32 secDiag[MAX_OUTPUT_CHANNELS], + Word32 singularVectors[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) */ + Word32 singularValues[MAX_OUTPUT_CHANNELS], /* exp(singularValues_e) */ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* exp(secDiag_e) */ Word16 *singularVectors_e, Word16 singularValues_e[MAX_OUTPUT_CHANNELS], Word16 *secDiag_e, - const Word16 nChannelsL, - const Word16 nChannelsC, - const Word16 currChannel, - Word32 *sig_x, + const Word16 nChannelsL, /* Q0 */ + const Word16 nChannelsC, /* Q0 */ + const Word16 currChannel, /* Q0 */ + Word32 *sig_x, /* exp(sig_x_e) */ Word16 *sig_x_e, - Word32 *g ); // Q31 + Word32 *g /* Q31 */ +); static void biDiagonalReductionRight_fx( - Word32 singularVectors[][MAX_OUTPUT_CHANNELS], - Word32 secDiag[MAX_OUTPUT_CHANNELS], + Word32 singularVectors[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) */ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* exp(secDiag_e) */ Word16 *singularVectors_e, Word16 *secDiag_e, - const Word16 nChannelsL, - const Word16 nChannelsC, - const Word16 currChannel, - Word32 *sig_x, + const Word16 nChannelsL, /* Q0 */ + const Word16 nChannelsC, /* Q0 */ + const Word16 currChannel, /* Q0 */ + Word32 *sig_x, /* exp(sig_x_e) */ Word16 *sig_x_e, - Word32 *g ); // Q31 + Word32 *g /* Q31 */ +); // Q31 static void singularVectorsAccumulationLeft_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], // Q31 output - Word32 singularValues[MAX_OUTPUT_CHANNELS], + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) as Input, Q31 as output */ + Word32 singularValues[MAX_OUTPUT_CHANNELS], /* exp(singularValues_e) */ Word16 singularVectors_e, Word16 singularValues_e[MAX_OUTPUT_CHANNELS], - const Word16 nChannelsL, - const Word16 nChannelsC ); + const Word16 nChannelsL, /* Q0 */ + const Word16 nChannelsC /* Q0 */ +); static void singularVectorsAccumulationRight_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], // Q31 output - Word32 secDiag[MAX_OUTPUT_CHANNELS], + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* Q31 */ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* Q31 */ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* exp(secDiag_e) */ Word16 singularVectors_e, Word16 secDiag_e, - const Word16 nChannelsC ); + const Word16 nChannelsC /* Q0 */ +); static Word32 maxWithSign_fx( - const Word32 a ); + const Word32 a /* Qx */ +); #if 0 static void flushToZeroArray_fx( @@ -161,54 +166,55 @@ static void flushToZeroMat_fx( #endif static Word16 BidagonalDiagonalisation_fx( - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31 */ - Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31 */ - Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* i/o: */ - Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ - Word16 *secDiag_fx_e, /* i/o: */ - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ - const Word16 nChannelsC, /* i : number of columns in the matrix to be decomposed */ - const Word32 eps_x, /* i : */ - const Word16 eps_x_e /* i : */ + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31*/ + Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_fx_e*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31*/ + Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_fx_e*/ + Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ + Word16 *secDiag_fx_e, /* i/o: */ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC, /* i : number of columns in the matrix to be decomposed Q0*/ + const Word32 eps_x, /* i : eps_x_e*/ + const Word16 eps_x_e /* i : */ ); static void ApplyRotation_fx( Word32 singularVector[][MAX_OUTPUT_CHANNELS], - const Word32 c, + const Word32 c, /* exp(c_e)*/ const Word16 c_e, - const Word32 s, + const Word32 s, /* exp(s_e) */ const Word16 s_e, - Word32 x11, + Word32 x11, /* exp(x11_e) */ Word16 x11_e, - Word32 x12, + Word32 x12, /* exp(x12_e) */ Word16 x12_e, - Word32 *d, + Word32 *d, /* exp(d_e) */ Word16 *d_e, - Word32 *g, + Word32 *g, /* exp(g_e) */ Word16 *g_e, - const Word16 currentIndex1, - const Word16 currentIndex2, - const Word16 nChannels ); + const Word16 currentIndex1, /* Q0 */ + const Word16 currentIndex2, /* Q0 */ + const Word16 nChannels /* Q0 */ +); static Word32 GivensRotation_fx( - const Word32 x, + const Word32 x, /* exp(x_e) */ const Word16 x_e, - const Word32 z, + const Word32 z, /* exp(z_e) */ const Word16 z_e, Word16 *out_e ); static void ApplyQRTransform_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31 */ - Word32 singularValues[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31 */ - Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: */ + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31*/ + Word32 singularValues[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_e*/ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31*/ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_e*/ Word16 singularValues_e[MAX_OUTPUT_CHANNELS], Word16 secDiag_e[MAX_OUTPUT_CHANNELS], - const Word16 startIndex, /* i : */ - const Word16 currentIndex, /* i : */ - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ - const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed */ + const Word16 startIndex, /* i : Q0*/ + const Word16 currentIndex, /* i : Q0*/ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ ); #endif @@ -220,11 +226,11 @@ static void ApplyQRTransform_fx( *-------------------------------------------------------------------------*/ void mat2svdMat_fx( - const Word32 *mat, /* i : matrix as column ordered vector */ - Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* o : matrix as two-dimensional arry */ - const Word16 nRows, /* i : number of rows of the matrix */ - const Word16 mCols, /* i : number of columns of the matrix */ - const Word16 transpose /* i : flag indication transposition */ + const Word32 *mat, /* i : matrix as column ordered vector Qx*/ + Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* o : matrix as two-dimensional arry Qx*/ + const Word16 nRows, /* i : number of rows of the matrix Q0*/ + const Word16 mCols, /* i : number of columns of the matrix Q0*/ + const Word16 transpose /* i : flag indication transposition Q0*/ ) { Word16 i, j; @@ -235,11 +241,11 @@ void mat2svdMat_fx( { FOR( j = 0; j < nRows; j++ ) { - svdMat[i][j] = mat[add( j, i_mult( nRows, i ) )]; + svdMat[i][j] = mat[j + ( nRows * i )]; /* Qx */ move32(); } - set_zero_fx( &svdMat[i][mCols], MAX_OUTPUT_CHANNELS - nRows ); + set_zero_fx( &svdMat[i][mCols], sub( MAX_OUTPUT_CHANNELS, nRows ) ); } FOR( ; i < MAX_OUTPUT_CHANNELS; i++ ) @@ -253,11 +259,11 @@ void mat2svdMat_fx( { FOR( j = 0; j < mCols; j++ ) { - svdMat[i][j] = mat[add( i, i_mult( nRows, j ) )]; + svdMat[i][j] = mat[i + ( nRows * j )]; /* Qx */ move32(); } - set_zero_fx( &svdMat[i][mCols], MAX_OUTPUT_CHANNELS - mCols ); + set_zero_fx( &svdMat[i][mCols], sub( MAX_OUTPUT_CHANNELS, mCols ) ); } FOR( ; i < MAX_OUTPUT_CHANNELS; i++ ) @@ -277,10 +283,10 @@ void mat2svdMat_fx( *---------------------------------------------------------------------*/ void svdMat2mat_fx( - Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* i : matrix as two-dimensional arry */ - Word32 *mat, /* o : matrix as column ordered vector */ - const Word16 nRows, /* i : number of rows of the matrix */ - const Word16 mCols /* i : number of columns of the matrix */ + Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* i : matrix as two-dimensional arry Qx*/ + Word32 *mat, /* o : matrix as column ordered vector Qx*/ + const Word16 nRows, /* i : number of rows of the matrix Q0*/ + const Word16 mCols /* i : number of columns of the matrix Q0*/ ) { Word16 i, j; @@ -289,7 +295,7 @@ void svdMat2mat_fx( { FOR( j = 0; j < mCols; j++ ) { - mat[add( i, i_mult( nRows, j ) )] = svdMat[i][j]; + mat[i + ( nRows * j )] = svdMat[i][j]; /* Qx */ move32(); } } @@ -391,14 +397,14 @@ void svdMat2mat( #ifdef IVAS_FLOAT_FIXED /*! r: error or success */ Word16 svd_fx( - Word32 InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) */ + Word32 InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) InputMatrix_e*/ Word16 InputMatrix_e, - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) (Q31) */ - Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* o : singular values vector (S) */ - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) (Q31) */ + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) Q31*/ + Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* o : singular values vector (S) singularValues_fx_e*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) Q31*/ Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ - const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed */ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ ) { Word16 iCh, jCh; @@ -422,7 +428,7 @@ Word16 svd_fx( { FOR( jCh = 0; jCh < nChannelsC; jCh++ ) { - singularVectors_Left_fx[iCh][jCh] = InputMatrix[iCh][jCh]; + singularVectors_Left_fx[iCh][jCh] = InputMatrix[iCh][jCh]; /* Q31 */ move32(); } } @@ -438,26 +444,26 @@ Word16 svd_fx( // flushToZeroMat(singularVectors_Right, nChannelsC, nChannelsC); /* BidagonalDiagonalisation */ - errorMessage = BidagonalDiagonalisation_fx( singularVectors_Left_fx, singularValues_fx, singularVectors_Right_fx, secDiag_fx, singularValues_fx_e, &secDiag_fx_e, nChannelsL, nChannelsC, eps_x_fx, eps_x_fx_e ); + errorMessage = BidagonalDiagonalisation_fx( singularVectors_Left_fx, singularValues_fx, singularVectors_Right_fx, secDiag_fx, singularValues_fx_e, &secDiag_fx_e, nChannelsL, nChannelsC, eps_x_fx, eps_x_fx_e ); /* Q0 */ /* Sort the singular values descending order */ - lengthSingularValues = s_min( nChannelsL, nChannelsC ); + lengthSingularValues = s_min( nChannelsL, nChannelsC ); /* Q0 */ DO { condition = 0; move16(); - FOR( iCh = 0; iCh < sub( lengthSingularValues, 1 ); iCh++ ) + FOR( iCh = 0; iCh < lengthSingularValues - 1; iCh++ ) { IF( BASOP_Util_Cmp_Mant32Exp( singularValues_fx[iCh], singularValues_fx_e[iCh], singularValues_fx[iCh + 1], singularValues_fx_e[iCh + 1] ) < 0 ) { condition = 1; move16(); - temp_fx = singularValues_fx[iCh]; + temp_fx = singularValues_fx[iCh]; /* singularValues_fx_e */ move32(); - singularValues_fx[iCh] = singularValues_fx[iCh + 1]; + singularValues_fx[iCh] = singularValues_fx[iCh + 1]; /* singularValues_fx_e */ move32(); - singularValues_fx[iCh + 1] = temp_fx; + singularValues_fx[iCh + 1] = temp_fx; /* singularValues_fx_e */ move32(); temp_fx_e = singularValues_fx_e[iCh]; move16(); @@ -468,21 +474,21 @@ Word16 svd_fx( FOR( jCh = 0; jCh < nChannelsL; ++jCh ) { - temp_fx = singularVectors_Left_fx[jCh][iCh]; + temp_fx = singularVectors_Left_fx[jCh][iCh]; /* Q31 */ move32(); - singularVectors_Left_fx[jCh][iCh] = singularVectors_Left_fx[jCh][iCh + 1]; + singularVectors_Left_fx[jCh][iCh] = singularVectors_Left_fx[jCh][iCh + 1]; /* Q31 */ move32(); - singularVectors_Left_fx[jCh][iCh + 1] = temp_fx; + singularVectors_Left_fx[jCh][iCh + 1] = temp_fx; /* Q31 */ move32(); } FOR( jCh = 0; jCh < nChannelsC; ++jCh ) { - temp_fx = singularVectors_Right_fx[jCh][iCh]; + temp_fx = singularVectors_Right_fx[jCh][iCh]; /* Q31 */ move32(); - singularVectors_Right_fx[jCh][iCh] = singularVectors_Right_fx[jCh][iCh + 1]; + singularVectors_Right_fx[jCh][iCh] = singularVectors_Right_fx[jCh][iCh + 1]; /* Q31 */ move32(); - singularVectors_Right_fx[jCh][iCh + 1] = temp_fx; + singularVectors_Right_fx[jCh][iCh + 1] = temp_fx; /* Q31 */ move32(); } } @@ -585,16 +591,16 @@ int16_t svd( #ifdef IVAS_FLOAT_FIXED static Word16 BidagonalDiagonalisation_fx( - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31 */ - Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31 */ - Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* i/o: */ - Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ - Word16 *secDiag_fx_e, /* i/o: */ - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ - const Word16 nChannelsC, /* i : number of columns in the matrix to be decomposed */ - const Word32 eps_x, /* i : */ - const Word16 eps_x_e /* i : */ + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31*/ + Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_fx_e*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31*/ + Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_fx_e*/ + Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ + Word16 *secDiag_fx_e, /* i/o: */ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC, /* i : number of columns in the matrix to be decomposed Q0*/ + const Word32 eps_x, /* i : eps_x_e*/ + const Word16 eps_x_e /* i : */ ) { Word16 kCh, nCh, iCh, jCh, split; @@ -621,18 +627,18 @@ static Word16 BidagonalDiagonalisation_fx( move16(); iteration = 0; move16(); - split = iCh - 1; + split = iCh - 1; /* Q0 */ move16(); WHILE( EQ_16( convergence, 0 ) ) { - iteration = add( iteration, 1 ); - found_split = 1; + iteration = add( iteration, 1 ); /* Q0 */ + found_split = 1; /* Q0 */ move16(); FOR( jCh = iCh; jCh >= 0; jCh-- ) { - split = sub( jCh, 1 ); + split = sub( jCh, 1 ); /* Q0 */ IF( LE_16( BASOP_Util_Cmp_Mant32Exp( L_abs( secDiag_fx[jCh] ), secDiag_new_e[jCh], Mpy_32_32( CONVERGENCE_FACTOR_FX, eps_x ), eps_x_e ), 0 ) ) /* is secDiag[ch] vanishing compared to eps_x */ { found_split = 0; @@ -648,7 +654,7 @@ static Word16 BidagonalDiagonalisation_fx( // convergence = ( jCh == iCh ) ? 1 : 0; IF( EQ_16( jCh, iCh ) ) { - convergence = 1; + convergence = 1; /* Q0 */ move16(); } ELSE @@ -670,19 +676,19 @@ static Word16 BidagonalDiagonalisation_fx( FOR( kCh = jCh; kCh <= iCh; kCh++ ) { - g = Mpy_32_32( s, secDiag_fx[kCh] ); + g = Mpy_32_32( s, secDiag_fx[kCh] ); /* exp(s_e + secDiag_new_e) */ g_e = add( s_e, secDiag_new_e[kCh] ); - secDiag_fx[kCh] = Mpy_32_32( c, secDiag_fx[kCh] ); + secDiag_fx[kCh] = Mpy_32_32( c, secDiag_fx[kCh] ); /* exp(c_e + secDiag_new_e) */ secDiag_new_e[kCh] = add( c_e, secDiag_new_e[kCh] ); IF( LE_16( BASOP_Util_Cmp_Mant32Exp( L_abs( g ), g_e, Mpy_32_32( CONVERGENCE_FACTOR_FX, eps_x ), eps_x_e ), 0 ) ) /* is singularValues[split] vanishing compared to eps_x */ { BREAK; } - c = singularValues_fx[kCh]; + c = singularValues_fx[kCh]; /* exp(singularValues_new_e) */ c_e = singularValues_new_e[kCh]; - singularValues_fx[kCh] = GivensRotation_fx( g, g_e, singularValues_fx[kCh], singularValues_new_e[kCh], &singularValues_new_e[kCh] ); - c = BASOP_Util_Divide3232_Scale_cadence( c, maxWithSign_fx( singularValues_fx[kCh] ), &temp_exp ); + singularValues_fx[kCh] = GivensRotation_fx( g, g_e, singularValues_fx[kCh], singularValues_new_e[kCh], &singularValues_new_e[kCh] ); /* exp(singularValues_new_e) */ + c = BASOP_Util_Divide3232_Scale_cadence( c, maxWithSign_fx( singularValues_fx[kCh] ), &temp_exp ); /* exp(temp_exp + (c_e - singularValues_new_e)) */ c_e = add( temp_exp, sub( c_e, singularValues_new_e[kCh] ) ); IF( c_e > 0 ) { @@ -690,7 +696,7 @@ static Word16 BidagonalDiagonalisation_fx( c_e = 0; move16(); } - s = BASOP_Util_Divide3232_Scale_cadence( -g, maxWithSign_fx( singularValues_fx[kCh] ), &temp_exp ); + s = BASOP_Util_Divide3232_Scale_cadence( -g, maxWithSign_fx( singularValues_fx[kCh] ), &temp_exp ); /* exp(temp_exp + (g_e - singularValues_new_e))*/ s_e = add( temp_exp, sub( g_e, singularValues_new_e[kCh] ) ); IF( s_e > 0 ) { @@ -766,7 +772,7 @@ static Word16 BidagonalDiagonalisation_fx( move16(); FOR( iCh = 0; iCh < nChannelsC; iCh++ ) { - secDiag_fx[iCh] = L_shr_r( secDiag_fx[iCh], sub( *secDiag_fx_e, secDiag_new_e[iCh] ) ); + secDiag_fx[iCh] = L_shr_r( secDiag_fx[iCh], sub( *secDiag_fx_e, secDiag_new_e[iCh] ) ); /* exp(secDiag_fx_e) */ move32(); } @@ -887,16 +893,16 @@ static int16_t BidagonalDiagonalisation( #ifdef IVAS_FLOAT_FIXED static void ApplyQRTransform_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31 */ - Word32 singularValues[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31 */ - Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: */ + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31*/ + Word32 singularValues[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_e*/ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31*/ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_e*/ Word16 singularValues_e[MAX_OUTPUT_CHANNELS], Word16 secDiag_e[MAX_OUTPUT_CHANNELS], - const Word16 startIndex, /* i : */ - const Word16 currentIndex, /* i : */ - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ - const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed */ + const Word16 startIndex, /* i : Q0*/ + const Word16 currentIndex, /* i : Q0*/ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ ) { Word16 ch, split; @@ -929,42 +935,42 @@ static void ApplyQRTransform_fx( Word16 s_e = 0; move16(); - x_kk = singularValues[currentIndex]; + x_kk = singularValues[currentIndex]; /* exp(singularValues_e) */ move32(); x_kk_e = singularValues_e[currentIndex]; move16(); - x_ii = singularValues[startIndex]; + x_ii = singularValues[startIndex]; /* exp(singularValues_e) */ move32(); x_ii_e = singularValues_e[startIndex]; move16(); - split = sub( currentIndex, 1 ); + split = sub( currentIndex, 1 ); /* Q0 */ move16(); - x_split = singularValues[split]; + x_split = singularValues[split]; /* exp(singularValues_e) */ move32(); x_split_e = singularValues_e[split]; move16(); - g = secDiag[split]; + g = secDiag[split]; /* exp(secDiag_e) */ move32(); g_e = secDiag_e[split]; move16(); - r = secDiag[currentIndex]; + r = secDiag[currentIndex]; /* exp(secDiag_e) */ move32(); r_e = secDiag_e[currentIndex]; move16(); // d = (x_split + x_kk) * (x_split - x_kk) + (g + r) * (g - r); - L_temp1 = BASOP_Util_Add_Mant32Exp( x_split, x_split_e, x_kk, x_kk_e, &L_temp1_e ); - L_temp2 = BASOP_Util_Add_Mant32Exp( x_split, x_split_e, L_negate( x_kk ), x_kk_e, &L_temp2_e ); - L_temp3 = BASOP_Util_Add_Mant32Exp( g, g_e, r, r_e, &L_temp3_e ); - L_temp4 = BASOP_Util_Add_Mant32Exp( g, g_e, L_negate( r ), r_e, &L_temp4_e ); - d = BASOP_Util_Add_Mant32Exp( Mpy_32_32( L_temp1, L_temp2 ), add( L_temp1_e, L_temp2_e ), Mpy_32_32( L_temp3, L_temp4 ), add( L_temp3_e, L_temp4_e ), &d_e ); + L_temp1 = BASOP_Util_Add_Mant32Exp( x_split, x_split_e, x_kk, x_kk_e, &L_temp1_e ); /* exp(L_temp1_e) */ + L_temp2 = BASOP_Util_Add_Mant32Exp( x_split, x_split_e, L_negate( x_kk ), x_kk_e, &L_temp2_e ); /* exp(L_temp2_e) */ + L_temp3 = BASOP_Util_Add_Mant32Exp( g, g_e, r, r_e, &L_temp3_e ); /* exp(L_temp3_e) */ + L_temp4 = BASOP_Util_Add_Mant32Exp( g, g_e, L_negate( r ), r_e, &L_temp4_e ); /* exp(L_temp4_e) */ + d = BASOP_Util_Add_Mant32Exp( Mpy_32_32( L_temp1, L_temp2 ), add( L_temp1_e, L_temp2_e ), Mpy_32_32( L_temp3, L_temp4 ), add( L_temp3_e, L_temp4_e ), &d_e ); /* exp(d_e) */ // d /= maxWithSign((r + r) * x_split); - L_temp1 = BASOP_Util_Add_Mant32Exp( r, r_e, r, r_e, &L_temp1_e ); - L_temp1 = maxWithSign_fx( Mpy_32_32( L_temp1, x_split ) ); + L_temp1 = BASOP_Util_Add_Mant32Exp( r, r_e, r, r_e, &L_temp1_e ); /* exp(L_temp1_e) */ + L_temp1 = maxWithSign_fx( Mpy_32_32( L_temp1, x_split ) ); /* exp(L_temp1_e + x_split_e) */ L_temp1_e = add( L_temp1_e, x_split_e ); - d = BASOP_Util_Divide3232_Scale_cadence( d, L_temp1, &temp_exp ); + d = BASOP_Util_Divide3232_Scale_cadence( d, L_temp1, &temp_exp ); /* temp_exp + d_e - L_temp1_e */ d_e = add( temp_exp, sub( d_e, L_temp1_e ) ); g = GivensRotation_fx( MAX_32, 0, d, d_e, &g_e ); @@ -981,29 +987,29 @@ static void ApplyQRTransform_fx( } L_temp1_e = g_e; move16(); - L_temp2 = maxWithSign_fx( BASOP_Util_Add_Mant32Exp( d, d_e, L_temp1, L_temp1_e, &L_temp2_e ) ); - mu = BASOP_Util_Divide3232_Scale_cadence( x_split, L_temp2, &mu_e ); + L_temp2 = maxWithSign_fx( BASOP_Util_Add_Mant32Exp( d, d_e, L_temp1, L_temp1_e, &L_temp2_e ) ); /* exp(L_temp2_e) */ + mu = BASOP_Util_Divide3232_Scale_cadence( x_split, L_temp2, &mu_e ); /* exp(mu_e + (x-plit_e - L_temp2_e)) */ mu_e = add( mu_e, sub( x_split_e, L_temp2_e ) ); - mu = BASOP_Util_Add_Mant32Exp( mu, mu_e, L_negate( r ), r_e, &mu_e ); + mu = BASOP_Util_Add_Mant32Exp( mu, mu_e, L_negate( r ), r_e, &mu_e ); /* exp(mu_e) */ // d = ((x_ii + x_kk) * (x_ii - x_kk) + r * mu) / maxWithSign(x_ii); - L_temp1 = BASOP_Util_Add_Mant32Exp( x_ii, x_ii_e, x_kk, x_kk_e, &L_temp1_e ); - L_temp2 = BASOP_Util_Add_Mant32Exp( x_ii, x_ii_e, L_negate( x_kk ), x_kk_e, &L_temp2_e ); - d = BASOP_Util_Add_Mant32Exp( Mpy_32_32( L_temp1, L_temp2 ), add( L_temp1_e, L_temp2_e ), Mpy_32_32( r, mu ), add( r_e, mu_e ), &d_e ); - d = BASOP_Util_Divide3232_Scale_cadence( d, maxWithSign_fx( x_ii ), &temp_exp ); + L_temp1 = BASOP_Util_Add_Mant32Exp( x_ii, x_ii_e, x_kk, x_kk_e, &L_temp1_e ); /* exp(L_temp1_e) */ + L_temp2 = BASOP_Util_Add_Mant32Exp( x_ii, x_ii_e, L_negate( x_kk ), x_kk_e, &L_temp2_e ); /* exp(L_temp2_e) */ + d = BASOP_Util_Add_Mant32Exp( Mpy_32_32( L_temp1, L_temp2 ), add( L_temp1_e, L_temp2_e ), Mpy_32_32( r, mu ), add( r_e, mu_e ), &d_e ); /* exp(d_e) */ + d = BASOP_Util_Divide3232_Scale_cadence( d, maxWithSign_fx( x_ii ), &temp_exp ); /* exp(temp_exp + (d_e - x_ii_e) */ d_e = add( temp_exp, sub( d_e, x_ii_e ) ); /*QR transformation*/ FOR( ch = startIndex; ch <= split; ch++ ) { - r = Mpy_32_32( s, secDiag[ch + 1] ); + r = Mpy_32_32( s, secDiag[ch + 1] ); /* exp(s_e + secDiag_e) */ r_e = add( s_e, secDiag_e[ch + 1] ); - g = Mpy_32_32( c, secDiag[ch + 1] ); + g = Mpy_32_32( c, secDiag[ch + 1] ); /* exp(c_e + secDiag_e) */ g_e = add( c_e, secDiag_e[ch + 1] ); - secDiag[ch] = GivensRotation_fx( d, d_e, r, r_e, &secDiag_e[ch] ); + secDiag[ch] = GivensRotation_fx( d, d_e, r, r_e, &secDiag_e[ch] ); /* exp(secDiag_e) */ move32(); - c = BASOP_Util_Divide3232_Scale_cadence( d, maxWithSign_fx( secDiag[ch] ), &c_e ); + c = BASOP_Util_Divide3232_Scale_cadence( d, maxWithSign_fx( secDiag[ch] ), &c_e ); /* exp(c_e + (d_e + secDiag_e)) */ c_e = add( c_e, sub( d_e, secDiag_e[ch] ) ); IF( c_e > 0 ) { @@ -1011,7 +1017,7 @@ static void ApplyQRTransform_fx( c_e = 0; move16(); } - s = BASOP_Util_Divide3232_Scale_cadence( r, maxWithSign_fx( secDiag[ch] ), &s_e ); + s = BASOP_Util_Divide3232_Scale_cadence( r, maxWithSign_fx( secDiag[ch] ), &s_e ); /* exp(s_e + (r_e - sec_Diag_e))*/ s_e = add( s_e, sub( r_e, secDiag_e[ch] ) ); IF( s_e > 0 ) { @@ -1020,12 +1026,12 @@ static void ApplyQRTransform_fx( move16(); } - r = Mpy_32_32( s, singularValues[ch + 1] ); + r = Mpy_32_32( s, singularValues[ch + 1] ); /* exp(r_e + secDiag_e) */ r_e = add( s_e, singularValues_e[ch + 1] ); - x_split = Mpy_32_32( c, singularValues[ch + 1] ); + x_split = Mpy_32_32( c, singularValues[ch + 1] ); /* exp(c_e + secDiag_e) */ x_split_e = add( c_e, singularValues_e[ch + 1] ); - aux = g; + aux = g; /* exp(g_e) */ move32(); aux_e = g_e; move16(); @@ -1033,14 +1039,14 @@ static void ApplyQRTransform_fx( // ApplyRotation(singularVectors_Right, c, s, x_ii, aux, &d, &g, ch + 1, ch, nChannelsC); ApplyRotation_fx( singularVectors_Right, c, c_e, s, s_e, x_ii, x_ii_e, aux, aux_e, &d, &d_e, &g, &g_e, ch + 1, ch, nChannelsC ); - singularValues[ch] = GivensRotation_fx( d, d_e, r, r_e, &singularValues_e[ch] ); + singularValues[ch] = GivensRotation_fx( d, d_e, r, r_e, &singularValues_e[ch] ); /* exp(singularValues_e) */ move32(); IF( GT_32( L_abs( singularValues[ch] ), Mpy_32_32( CONVERGENCE_FACTOR_FX, L_abs( singularValues[ch] ) ) ) ) { - aux = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q30, singularValues[ch], &aux_e ); + aux = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q30, singularValues[ch], &aux_e ); /* exp(aux_e + (1 - singularValues_e)) */ aux_e = add( aux_e, sub( 1, singularValues_e[ch] ) ); - c = Mpy_32_32( d, aux ); + c = Mpy_32_32( d, aux ); /* exp(d_e + aux_e) */ c_e = add( d_e, aux_e ); IF( c_e > 0 ) { @@ -1049,7 +1055,7 @@ static void ApplyQRTransform_fx( move16(); } - s = Mpy_32_32( r, aux ); + s = Mpy_32_32( r, aux ); /* exp(r_e + aux_e) */ s_e = add( r_e, aux_e ); IF( s_e > 0 ) { @@ -1065,11 +1071,11 @@ static void ApplyQRTransform_fx( secDiag[startIndex] = 0; move32(); - secDiag[currentIndex] = d; + secDiag[currentIndex] = d; /* exp(d_e) */ move32(); secDiag_e[currentIndex] = d_e; move16(); - singularValues[currentIndex] = x_ii; + singularValues[currentIndex] = x_ii; /* exp(x_ii_e) */ move32(); singularValues_e[currentIndex] = x_ii_e; move16(); @@ -1151,28 +1157,29 @@ static void ApplyQRTransform( #ifdef IVAS_FLOAT_FIXED static void ApplyRotation_fx( Word32 singularVector[][MAX_OUTPUT_CHANNELS], - const Word32 c, + const Word32 c, /* exp(c_e)*/ const Word16 c_e, - const Word32 s, + const Word32 s, /* exp(s_e) */ const Word16 s_e, - Word32 x11, + Word32 x11, /* exp(x11_e) */ Word16 x11_e, - Word32 x12, + Word32 x12, /* exp(x12_e) */ Word16 x12_e, - Word32 *d, + Word32 *d, /* exp(d_e) */ Word16 *d_e, - Word32 *g, + Word32 *g, /* exp(g_e) */ Word16 *g_e, - const Word16 currentIndex1, - const Word16 currentIndex2, - const Word16 nChannels ) + const Word16 currentIndex1, /* Q0 */ + const Word16 currentIndex2, /* Q0 */ + const Word16 nChannels /* Q0 */ +) { Word16 ch; Word16 temp_exp; - *d = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x11 ), add( c_e, x11_e ), Mpy_32_32( s, x12 ), add( s_e, x12_e ), d_e ); + *d = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x11 ), add( c_e, x11_e ), Mpy_32_32( s, x12 ), add( s_e, x12_e ), d_e ); /* exp(d_e) */ move32(); - *g = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x12 ), add( c_e, x12_e ), Mpy_32_32( L_negate( s ), x11 ), add( s_e, x11_e ), g_e ); + *g = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x12 ), add( c_e, x12_e ), Mpy_32_32( L_negate( s ), x11 ), add( s_e, x11_e ), g_e ); /* exp(g_e) */ move32(); FOR( ch = 0; ch < nChannels; ch++ ) @@ -1181,13 +1188,13 @@ static void ApplyRotation_fx( move32(); x12 = singularVector[ch][currentIndex1]; move32(); - singularVector[ch][currentIndex2] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x11 ), c_e, Mpy_32_32( s, x12 ), s_e, &temp_exp ); + singularVector[ch][currentIndex2] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x11 ), c_e, Mpy_32_32( s, x12 ), s_e, &temp_exp ); /* exp(temp_exp) */ move32(); - singularVector[ch][currentIndex2] = L_shl_sat( singularVector[ch][currentIndex2], temp_exp ); + singularVector[ch][currentIndex2] = L_shl_sat( singularVector[ch][currentIndex2], temp_exp ); /* exp(temp_exp) */ move32(); - singularVector[ch][currentIndex1] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x12 ), c_e, Mpy_32_32( L_negate( s ), x11 ), s_e, &temp_exp ); + singularVector[ch][currentIndex1] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x12 ), c_e, Mpy_32_32( L_negate( s ), x11 ), s_e, &temp_exp ); /* exp(temp_exp) */ move32(); - singularVector[ch][currentIndex1] = L_shl_sat( singularVector[ch][currentIndex1], temp_exp ); + singularVector[ch][currentIndex1] = L_shl_sat( singularVector[ch][currentIndex1], temp_exp ); /* exp(temp_exp) */ move32(); } @@ -1231,16 +1238,16 @@ static void ApplyRotation( #ifdef IVAS_FLOAT_FIXED static void HouseholderReduction_fx( - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], - Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], - Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_Left_e) */ + Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* exp(singularValues_fx_e) */ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_Left_e) */ + Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* exp(secDiag_fx_e) */ Word16 singularVectors_Left_e, Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], Word16 *secDiag_fx_e, - const Word16 nChannelsL, - const Word16 nChannelsC, - Word32 *eps_x_fx, + const Word16 nChannelsL, /* Q0 */ + const Word16 nChannelsC, /* Q0 */ + Word32 *eps_x_fx, /* exp(eps_x_fx_e) */ Word16 *eps_x_fx_e ) { Word16 nCh; @@ -1258,10 +1265,10 @@ static void HouseholderReduction_fx( biDiagonalReductionRight_fx( singularVectors_Left_fx, secDiag_fx, &singularVectors_Left_e, secDiag_fx_e, nChannelsL, nChannelsC, nCh, &sig_x_fx, &sig_x_fx_e, &g_fx ); Word16 L_temp_e; - Word32 L_temp = BASOP_Util_Add_Mant32Exp( L_abs( singularValues_fx[nCh] ), singularValues_fx_e[nCh], L_abs( secDiag_fx[nCh] ), *secDiag_fx_e, &L_temp_e ); + Word32 L_temp = BASOP_Util_Add_Mant32Exp( L_abs( singularValues_fx[nCh] ), singularValues_fx_e[nCh], L_abs( secDiag_fx[nCh] ), *secDiag_fx_e, &L_temp_e ); /* exp(L_temp_e) */ IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( L_temp, L_temp_e, *eps_x_fx, *eps_x_fx_e ), 1 ) ) { - *eps_x_fx = L_temp; + *eps_x_fx = L_temp; /* exp(L_temp_e) */ move32(); *eps_x_fx_e = L_temp_e; move32(); @@ -1312,18 +1319,19 @@ static void HouseholderReduction( #ifdef IVAS_FLOAT_FIXED static void biDiagonalReductionLeft_fx( - Word32 singularVectors[][MAX_OUTPUT_CHANNELS], - Word32 singularValues[MAX_OUTPUT_CHANNELS], - Word32 secDiag[MAX_OUTPUT_CHANNELS], + Word32 singularVectors[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) */ + Word32 singularValues[MAX_OUTPUT_CHANNELS], /* exp(singularValues_e) */ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* exp(secDiag_e) */ Word16 *singularVectors_e, Word16 singularValues_e[MAX_OUTPUT_CHANNELS], Word16 *secDiag_e, - const Word16 nChannelsL, - const Word16 nChannelsC, - const Word16 currChannel, - Word32 *sig_x, + const Word16 nChannelsL, /* Q0 */ + const Word16 nChannelsC, /* Q0 */ + const Word16 currChannel, /* Q0 */ + Word32 *sig_x, /* exp(sig_x_e) */ Word16 *sig_x_e, - Word32 *g ) // Q31 + Word32 *g /* Q31 */ +) { Word16 iCh, jCh, idx; Word32 norm_x, f, r; @@ -1337,14 +1345,14 @@ static void biDiagonalReductionLeft_fx( set16_fx( sing_exp2[jCh], *singularVectors_e, MAX_OUTPUT_CHANNELS ); } - secDiag[currChannel] = Mpy_32_32( *sig_x, *g ); + secDiag[currChannel] = Mpy_32_32( *sig_x, *g ); /* exp(sig_x_e) */ move32(); // rescaling block IF( GT_16( *sig_x_e, *secDiag_e ) ) { FOR( Word16 i = 0; i < MAX_OUTPUT_CHANNELS; i++ ){ IF( NE_16( i, currChannel ) ){ - secDiag[i] = L_shl( secDiag[i], sub( *secDiag_e, *sig_x_e ) ); + secDiag[i] = L_shl( secDiag[i], sub( *secDiag_e, *sig_x_e ) ); /* sig_x_e */ move32(); } } @@ -1353,7 +1361,7 @@ move16(); } ELSE IF( LT_16( *sig_x_e, *secDiag_e ) ) { - secDiag[currChannel] = L_shr_r( secDiag[currChannel], sub( *secDiag_e, *sig_x_e ) ); + secDiag[currChannel] = L_shr_r( secDiag[currChannel], sub( *secDiag_e, *sig_x_e ) ); /* exp(secDiag_e) */ move32(); } @@ -1370,7 +1378,7 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { - ( *sig_x ) = BASOP_Util_Add_Mant32Exp( *sig_x, *sig_x_e, L_abs( singularVectors[jCh][currChannel] ), *singularVectors_e, sig_x_e ); + ( *sig_x ) = BASOP_Util_Add_Mant32Exp( *sig_x, *sig_x_e, L_abs( singularVectors[jCh][currChannel] ), *singularVectors_e, sig_x_e ); /* exp(sig_x_e) */ } IF( ( *sig_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ @@ -1381,11 +1389,11 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ move16(); FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { - singularVectors[jCh][currChannel] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[jCh][currChannel], maxWithSign_fx( *sig_x ), &sing_exp[jCh] ); + singularVectors[jCh][currChannel] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[jCh][currChannel], maxWithSign_fx( *sig_x ), &sing_exp[jCh] ); /* exp(sing_exp + (singularVectors_e - sig_x_e) */ move32(); sing_exp[jCh] = add( sing_exp[jCh], sub( *singularVectors_e, *sig_x_e ) ); move16(); - norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[jCh][currChannel], singularVectors[jCh][currChannel] ), shl( sing_exp[jCh], 1 ), &norm_x_e ); + norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[jCh][currChannel], singularVectors[jCh][currChannel] ), shl( sing_exp[jCh], 1 ), &norm_x_e ); /* exp(norm_x_e) */ } IF( GT_16( norm_x_e, 0 ) ) { @@ -1410,9 +1418,9 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ move32(); } - r = BASOP_Util_Add_Mant32Exp( Mpy_32_32( ( *g ), singularVectors[currChannel][idx] ), sing_exp[currChannel], -norm_x, norm_x_e, &r_e ); + r = BASOP_Util_Add_Mant32Exp( Mpy_32_32( ( *g ), singularVectors[currChannel][idx] ), sing_exp[currChannel], -norm_x, norm_x_e, &r_e ); /* exp(r_e) */ #ifdef FIX_827_HIGH_MLD - singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp( singularVectors[currChannel][idx], sing_exp[currChannel], -( *g ), 0, &sing_exp[currChannel] ); + singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp( singularVectors[currChannel][idx], sing_exp[currChannel], -( *g ), 0, &sing_exp[currChannel] ); /* sing_exp */ #else singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp( singularVectors[currChannel][idx], sing_exp[idx], -( *g ), 0, &sing_exp[currChannel] ); #endif @@ -1426,15 +1434,15 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ move16(); FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { - norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[jCh][currChannel], singularVectors[jCh][iCh] ), add( sing_exp[jCh], *singularVectors_e ), &norm_x_e ); + norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[jCh][currChannel], singularVectors[jCh][iCh] ), add( sing_exp[jCh], *singularVectors_e ), &norm_x_e ); /* exp(norm_x_e) */ } - f = BASOP_Util_Divide3232_Scale_cadence( norm_x, maxWithSign_fx( r ), &f_e ); + f = BASOP_Util_Divide3232_Scale_cadence( norm_x, maxWithSign_fx( r ), &f_e ); /* f_e + (norm_x_e - r_e) */ f_e = add( f_e, sub( norm_x_e, r_e ) ); FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { - singularVectors[jCh][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors[jCh][iCh], *singularVectors_e, Mpy_32_32( f, singularVectors[jCh][currChannel] ), add( f_e, sing_exp[jCh] ), &sing_exp2[jCh][iCh] ); + singularVectors[jCh][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors[jCh][iCh], *singularVectors_e, Mpy_32_32( f, singularVectors[jCh][currChannel] ), add( f_e, sing_exp[jCh] ), &sing_exp2[jCh][iCh] ); /* exp( sing_exp2) */ move32(); } } @@ -1442,7 +1450,7 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { - singularVectors[jCh][currChannel] = Mpy_32_32( singularVectors[jCh][currChannel], ( *sig_x ) ); + singularVectors[jCh][currChannel] = Mpy_32_32( singularVectors[jCh][currChannel], ( *sig_x ) ); /* sing_exp + sig_x_e */ move32(); sing_exp2[jCh][currChannel] = add( sing_exp[jCh], *sig_x_e ); move16(); @@ -1463,7 +1471,7 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ { FOR( jCh = 0; jCh < nChannelsL; jCh++ ) { - singularVectors[jCh][iCh] = L_shr_r( singularVectors[jCh][iCh], sub( exp_max, sing_exp2[jCh][iCh] ) ); + singularVectors[jCh][iCh] = L_shr_r( singularVectors[jCh][iCh], sub( exp_max, sing_exp2[jCh][iCh] ) ); /* exp(exp_max) */ move32(); } } @@ -1472,7 +1480,7 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ } // rescaling block - singularValues[currChannel] = Mpy_32_32( ( *sig_x ), ( *g ) ); + singularValues[currChannel] = Mpy_32_32( ( *sig_x ), ( *g ) ); /* sig_x_e */ move32(); singularValues_e[currChannel] = *sig_x_e; move16(); @@ -1561,16 +1569,17 @@ static void biDiagonalReductionLeft( #ifdef IVAS_FLOAT_FIXED static void biDiagonalReductionRight_fx( - Word32 singularVectors[][MAX_OUTPUT_CHANNELS], - Word32 secDiag[MAX_OUTPUT_CHANNELS], + Word32 singularVectors[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) */ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* exp(secDiag_e) */ Word16 *singularVectors_e, Word16 *secDiag_e, - const Word16 nChannelsL, - const Word16 nChannelsC, - const Word16 currChannel, - Word32 *sig_x, + const Word16 nChannelsL, /* Q0 */ + const Word16 nChannelsC, /* Q0 */ + const Word16 currChannel, /* Q0 */ + Word32 *sig_x, /* exp(sig_x_e) */ Word16 *sig_x_e, - Word32 *g ) + Word32 *g /* Q31 */ +) { Word16 iCh, jCh, idx; Word32 norm_x, r; @@ -1594,11 +1603,11 @@ static void biDiagonalReductionRight_fx( IF( LT_16( currChannel, nChannelsL ) && NE_16( currChannel, sub( nChannelsC, 1 ) ) ) /* i <=m && i !=n */ { - idx = add( currChannel, 1 ); + idx = add( currChannel, 1 ); /* Q0 */ FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { - ( *sig_x ) = BASOP_Util_Add_Mant32Exp( *sig_x, *sig_x_e, L_abs( singularVectors[currChannel][jCh] ), *singularVectors_e, sig_x_e ); + ( *sig_x ) = BASOP_Util_Add_Mant32Exp( *sig_x, *sig_x_e, L_abs( singularVectors[currChannel][jCh] ), *singularVectors_e, sig_x_e ); /* exp(sig_x_e) */ } IF( ( *sig_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ @@ -1610,11 +1619,11 @@ static void biDiagonalReductionRight_fx( FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /*nChannelsC */ { - singularVectors[currChannel][jCh] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[currChannel][jCh], maxWithSign_fx( *sig_x ), &sing_exp[jCh] ); + singularVectors[currChannel][jCh] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[currChannel][jCh], maxWithSign_fx( *sig_x ), &sing_exp[jCh] ); /* exp(sing_exp + (singularVectors_e - sig_x_e)) */ move32(); sing_exp[jCh] = add( sing_exp[jCh], sub( *singularVectors_e, *sig_x_e ) ); move16(); - norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[currChannel][jCh], singularVectors[currChannel][jCh] ), shl( sing_exp[jCh], 1 ), &norm_x_e ); + norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[currChannel][jCh], singularVectors[currChannel][jCh] ), shl( sing_exp[jCh], 1 ), &norm_x_e ); /* exp(norm_x_e) */ } IF( GT_16( norm_x_e, 0 ) ) { @@ -1629,22 +1638,22 @@ static void biDiagonalReductionRight_fx( L_temp = L_shl_r( L_temp, L_temp_e ); // Q31 IF( singularVectors[currChannel][idx] >= 0 ) { - ( *g ) = L_negate( L_temp ); + ( *g ) = L_negate( L_temp ); /* exp(L_temp_e) */ move32(); } ELSE { - ( *g ) = L_negate( L_negate( L_temp ) ); + ( *g ) = L_negate( L_negate( L_temp ) ); /* exp(L_temp_e) */ move32(); } - r = BASOP_Util_Add_Mant32Exp( Mpy_32_32( ( *g ), singularVectors[currChannel][idx] ), sing_exp[idx], -norm_x, norm_x_e, &r_e ); - singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp( singularVectors[currChannel][idx], sing_exp[idx], -( *g ), 0, &sing_exp[idx] ); + r = BASOP_Util_Add_Mant32Exp( Mpy_32_32( ( *g ), singularVectors[currChannel][idx] ), sing_exp[idx], -norm_x, norm_x_e, &r_e ); /* exp(r_e) */ + singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp( singularVectors[currChannel][idx], sing_exp[idx], -( *g ), 0, &sing_exp[idx] ); /* exp(sing_exp) */ move32(); FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { - secDiag[jCh] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[currChannel][jCh], maxWithSign_fx( r ), &secDiag_exp[jCh] ); + secDiag[jCh] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[currChannel][jCh], maxWithSign_fx( r ), &secDiag_exp[jCh] ); /* exp(secDiag_exp + (sing_exp - r_e) */ move32(); secDiag_exp[jCh] = add( secDiag_exp[jCh], sub( sing_exp[jCh], r_e ) ); move32(); @@ -1658,19 +1667,19 @@ static void biDiagonalReductionRight_fx( move16(); FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { - norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[iCh][jCh], singularVectors[currChannel][jCh] ), add( *singularVectors_e, sing_exp[jCh] ), &norm_x_e ); + norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[iCh][jCh], singularVectors[currChannel][jCh] ), add( *singularVectors_e, sing_exp[jCh] ), &norm_x_e ); /* exp(norm_x_e) */ } FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { - singularVectors[iCh][jCh] = BASOP_Util_Add_Mant32Exp( singularVectors[iCh][jCh], *singularVectors_e, Mpy_32_32( norm_x, secDiag[jCh] ), add( norm_x_e, secDiag_exp[jCh] ), &sing_exp2[iCh][jCh] ); + singularVectors[iCh][jCh] = BASOP_Util_Add_Mant32Exp( singularVectors[iCh][jCh], *singularVectors_e, Mpy_32_32( norm_x, secDiag[jCh] ), add( norm_x_e, secDiag_exp[jCh] ), &sing_exp2[iCh][jCh] ); /* exp(sing_exp2) */ move32(); } } FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { - singularVectors[currChannel][jCh] = Mpy_32_32( singularVectors[currChannel][jCh], ( *sig_x ) ); + singularVectors[currChannel][jCh] = Mpy_32_32( singularVectors[currChannel][jCh], ( *sig_x ) ); /* exp(sing_exp + sig_x_e) */ move32(); sing_exp2[currChannel][jCh] = add( sing_exp[jCh], *sig_x_e ); move16(); @@ -1685,7 +1694,7 @@ static void biDiagonalReductionRight_fx( } FOR( jCh = 0; jCh < nChannelsC; jCh++ ) { - secDiag[jCh] = L_shr_r( secDiag[jCh], sub( exp_max, secDiag_exp[jCh] ) ); + secDiag[jCh] = L_shr_r( secDiag[jCh], sub( exp_max, secDiag_exp[jCh] ) ); /* exp(exp_max) */ move32(); } @@ -1704,7 +1713,7 @@ static void biDiagonalReductionRight_fx( { FOR( jCh = 0; jCh < nChannelsC; jCh++ ) { - singularVectors[iCh][jCh] = L_shr_r( singularVectors[iCh][jCh], sub( exp_max, sing_exp2[iCh][jCh] ) ); + singularVectors[iCh][jCh] = L_shr_r( singularVectors[iCh][jCh], sub( exp_max, sing_exp2[iCh][jCh] ) ); /* exp(exp_max) */ move32(); } } @@ -1792,12 +1801,13 @@ static void biDiagonalReductionRight( #ifdef IVAS_FLOAT_FIXED static void singularVectorsAccumulationLeft_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], // Q31 output - Word32 singularValues[MAX_OUTPUT_CHANNELS], + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) as Input, Q31 as output */ + Word32 singularValues[MAX_OUTPUT_CHANNELS], /* exp(singularValues_e) */ Word16 singularVectors_e, Word16 singularValues_e[MAX_OUTPUT_CHANNELS], - const Word16 nChannelsL, - const Word16 nChannelsC ) + const Word16 nChannelsL, /* Q0 */ + const Word16 nChannelsC /* Q0 */ +) { Word16 nCh, iCh, k; Word16 nChannels; @@ -1810,11 +1820,11 @@ static void singularVectorsAccumulationLeft_fx( } /* Processing */ - nChannels = min( nChannelsL, nChannelsC ); /* min(nChannelsL,ChannelsC) */ + nChannels = s_min( nChannelsL, nChannelsC ); /* min(nChannelsL,ChannelsC) Q0*/ // FILE *fp = fopen("t_ii_out.txt","a"); FOR( nCh = nChannels - 1; nCh >= 0; nCh-- ) /* min(nChannelsL,ChannelsC) */ { - t_ii = singularValues[nCh]; + t_ii = singularValues[nCh]; /* exp(singularValues_e) */ move32(); t_ii_e = singularValues_e[nCh]; move16(); @@ -1827,7 +1837,7 @@ static void singularVectorsAccumulationLeft_fx( IF( t_ii ) /*if (fabsf(t_ii) > EPSILON *fabsf(t_ii)) {*/ { - t_ii = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q30, maxWithSign_fx( t_ii ), &temp_exp ); + t_ii = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q30, maxWithSign_fx( t_ii ), &temp_exp ); /* exp(1 + (temp_exp + tii_e)) */ t_ii_e = add( 1, sub( temp_exp, t_ii_e ) ); // fprintf( fp, "%e\n", me2f( t_ii, t_ii_e ) ); FOR( iCh = nCh + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC */ @@ -1838,21 +1848,21 @@ static void singularVectorsAccumulationLeft_fx( move16(); FOR( k = nCh + 1; k < nChannelsL; k++ ) /* nChannelsL */ { - norm_y = BASOP_Util_Add_Mant32Exp( norm_y, norm_y_e, Mpy_32_32( singularVectors_Left[k][nCh], singularVectors_Left[k][iCh] ), add( sing_exp2[k][nCh], sing_exp2[k][iCh] ), &norm_y_e ); + norm_y = BASOP_Util_Add_Mant32Exp( norm_y, norm_y_e, Mpy_32_32( singularVectors_Left[k][nCh], singularVectors_Left[k][iCh] ), add( sing_exp2[k][nCh], sing_exp2[k][iCh] ), &norm_y_e ); /* exp(norm_y_e) */ } t_jj = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( t_ii, norm_y ), maxWithSign_fx( singularVectors_Left[nCh][nCh] ), &temp_exp ); // t_ii_e+norm_y_e-*singularVectors_e, t_jj_e = add( temp_exp, sub( add( t_ii_e, norm_y_e ), sing_exp2[nCh][nCh] ) ); FOR( k = nCh; k < nChannelsL; k++ ) /* nChannelsL */ { - singularVectors_Left[k][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors_Left[k][iCh], sing_exp2[k][iCh], Mpy_32_32( t_jj, singularVectors_Left[k][nCh] ), add( t_jj_e, sing_exp2[k][nCh] ), &sing_exp2[k][iCh] ); + singularVectors_Left[k][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors_Left[k][iCh], sing_exp2[k][iCh], Mpy_32_32( t_jj, singularVectors_Left[k][nCh] ), add( t_jj_e, sing_exp2[k][nCh] ), &sing_exp2[k][iCh] ); /* exp(sing_exp2) */ move32(); } } FOR( iCh = nCh; iCh < nChannelsL; iCh++ ) /* nChannelsL */ { - singularVectors_Left[iCh][nCh] = Mpy_32_32( singularVectors_Left[iCh][nCh], t_ii ); + singularVectors_Left[iCh][nCh] = Mpy_32_32( singularVectors_Left[iCh][nCh], t_ii ); /* exp(sing_exp2 + t_ii_e) */ move32(); sing_exp2[iCh][nCh] = add( sing_exp2[iCh][nCh], t_ii_e ); move16(); @@ -1867,7 +1877,7 @@ static void singularVectorsAccumulationLeft_fx( } } - singularVectors_Left[nCh][nCh] = BASOP_Util_Add_Mant32Exp( singularVectors_Left[nCh][nCh], sing_exp2[nCh][nCh], ONE_IN_Q30, 1, &sing_exp2[nCh][nCh] ); + singularVectors_Left[nCh][nCh] = BASOP_Util_Add_Mant32Exp( singularVectors_Left[nCh][nCh], sing_exp2[nCh][nCh], ONE_IN_Q30, 1, &sing_exp2[nCh][nCh] ); /* exp(sing_exp2) */ move32(); } // fclose(fp); @@ -1875,7 +1885,7 @@ static void singularVectorsAccumulationLeft_fx( { FOR( iCh = 0; iCh < nChannelsC; iCh++ ) { - singularVectors_Left[nCh][iCh] = L_shl_sat( singularVectors_Left[nCh][iCh], sing_exp2[nCh][iCh] ); + singularVectors_Left[nCh][iCh] = L_shl_sat( singularVectors_Left[nCh][iCh], sing_exp2[nCh][iCh] ); /* Q31 */ move32(); } } @@ -1953,12 +1963,13 @@ static void singularVectorsAccumulationLeft( #ifdef IVAS_FLOAT_FIXED static void singularVectorsAccumulationRight_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], // Q31 - Word32 secDiag[MAX_OUTPUT_CHANNELS], + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* Q31 */ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* Q31 */ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* exp(secDiag_e) */ Word16 singularVectors_e, Word16 secDiag_e, - const Word16 nChannelsC ) + const Word16 nChannelsC /* Q0 */ +) { Word16 nCh, iCh, k; Word16 nChannels; @@ -1966,10 +1977,10 @@ static void singularVectorsAccumulationRight_fx( Word16 norm_y_e, temp_exp1, sing_right_exp[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS] = { 0 }; /* Processing */ - nChannels = nChannelsC; /* nChannelsC */ + nChannels = nChannelsC; /* nChannelsC Q0*/ /* avoid compiler warning */ - t_ii = secDiag[nChannels - 1]; + t_ii = secDiag[nChannels - 1]; /* exp(secDiag_e) */ move32(); FOR( nCh = nChannels - 1; nCh >= 0; nCh-- ) /* nChannelsC, min(nChannelsLmnChannelsC) otherwise */ @@ -1982,8 +1993,8 @@ static void singularVectorsAccumulationRight_fx( FOR( iCh = nCh + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC*/ { - ratio_float = BASOP_Util_Divide3232_Scale_cadence( singularVectors_Left[nCh][iCh], maxWithSign_fx( singularVectors_Left[nCh][nCh + 1] ), &temp_exp1 ); - singularVectors_Right[iCh][nCh] = BASOP_Util_Divide3232_Scale_cadence( ratio_float, maxWithSign_fx( t_ii ), &sing_right_exp[iCh][nCh] ); + ratio_float = BASOP_Util_Divide3232_Scale_cadence( singularVectors_Left[nCh][iCh], maxWithSign_fx( singularVectors_Left[nCh][nCh + 1] ), &temp_exp1 ); /* exp(temp_exp1) */ + singularVectors_Right[iCh][nCh] = BASOP_Util_Divide3232_Scale_cadence( ratio_float, maxWithSign_fx( t_ii ), &sing_right_exp[iCh][nCh] ); /* exp(sing_right_exp + (temp_exp1 - secDiag_e) */ move32(); sing_right_exp[iCh][nCh] = add( sing_right_exp[iCh][nCh], sub( temp_exp1, secDiag_e ) ); move16(); @@ -1999,14 +2010,14 @@ static void singularVectorsAccumulationRight_fx( FOR( k = nCh + 1; k < nChannelsC; k++ ) /* nChannelsC */ { - norm_y = BASOP_Util_Add_Mant32Exp( norm_y, norm_y_e, Mpy_32_32( singularVectors_Left[nCh][k], singularVectors_Right[k][iCh] ), add( singularVectors_e, sing_right_exp[k][iCh] ), &norm_y_e ); + norm_y = BASOP_Util_Add_Mant32Exp( norm_y, norm_y_e, Mpy_32_32( singularVectors_Left[nCh][k], singularVectors_Right[k][iCh] ), add( singularVectors_e, sing_right_exp[k][iCh] ), &norm_y_e ); /* exp(norm_y_e) */ } FOR( k = nCh + 1; k < nChannelsC; k++ ) /* nChannelsC */ { - singularVectors_Right[k][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors_Right[k][iCh], sing_right_exp[k][iCh], Mpy_32_32( norm_y, singularVectors_Right[k][nCh] ), add( norm_y_e, sing_right_exp[k][nCh] ), &sing_right_exp[k][iCh] ); + singularVectors_Right[k][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors_Right[k][iCh], sing_right_exp[k][iCh], Mpy_32_32( norm_y, singularVectors_Right[k][nCh] ), add( norm_y_e, sing_right_exp[k][nCh] ), &sing_right_exp[k][iCh] ); /* exp(sing_right_exp) */ move32(); - singularVectors_Right[k][iCh] = L_shl_sat( singularVectors_Right[k][iCh], sing_right_exp[k][iCh] ); + singularVectors_Right[k][iCh] = L_shl_sat( singularVectors_Right[k][iCh], sing_right_exp[k][iCh] ); /* Q31 */ move32(); sing_right_exp[k][iCh] = 0; move16(); @@ -2023,7 +2034,7 @@ static void singularVectorsAccumulationRight_fx( } singularVectors_Right[nCh][nCh] = MAX_32; move32(); - t_ii = secDiag[nCh]; + t_ii = secDiag[nCh]; /* exp(secDiag_e) */ move32(); } return; @@ -2096,9 +2107,9 @@ static void singularVectorsAccumulationRight( #ifdef IVAS_FLOAT_FIXED static Word32 GivensRotation_fx( - const Word32 x, + const Word32 x, /* exp(x_e) */ const Word16 x_e, - const Word32 z, + const Word32 z, /* exp(z_e) */ const Word16 z_e, Word16 *out_e ) { @@ -2123,11 +2134,11 @@ static Word32 GivensRotation_fx( } ELSE { - cotan = BASOP_Util_Divide3232_Scale_cadence( z_abs, x_abs, &temp_exp ); + cotan = BASOP_Util_Divide3232_Scale_cadence( z_abs, x_abs, &temp_exp ); /* exp(temp_exp + (z_e - x_e) */ temp_exp = add( temp_exp, sub( z_e, x_e ) ); - L_temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, Mpy_32_32( cotan, cotan ), 2 * temp_exp, &temp_exp ); + L_temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, Mpy_32_32( cotan, cotan ), 2 * temp_exp, &temp_exp ); /* exp(temp_exp) */ L_temp = Sqrt32( L_temp, &temp_exp ); - r = Mpy_32_32( x_abs, L_temp ); + r = Mpy_32_32( x_abs, L_temp ); /* exp(x_e + temp_exp) */ *out_e = add( x_e, temp_exp ); } } @@ -2140,11 +2151,11 @@ static Word32 GivensRotation_fx( } ELSE { - tan = BASOP_Util_Divide3232_Scale_cadence( x_abs, z_abs, &temp_exp ); + tan = BASOP_Util_Divide3232_Scale_cadence( x_abs, z_abs, &temp_exp ); /* exp(temp_exp + (x_e - z_e) */ temp_exp = add( temp_exp, sub( x_e, z_e ) ); - L_temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, Mpy_32_32( tan, tan ), shl( temp_exp, 1 ), &temp_exp ); + L_temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, Mpy_32_32( tan, tan ), shl( temp_exp, 1 ), &temp_exp ); /* exp(temp_exp) */ L_temp = Sqrt32( L_temp, &temp_exp ); - r = Mpy_32_32( z_abs, L_temp ); + r = Mpy_32_32( z_abs, L_temp ); /* exp(z_e + temp_exp) */ *out_e = add( z_e, temp_exp ); } } @@ -2201,7 +2212,8 @@ static float GivensRotation( #ifdef IVAS_FLOAT_FIXED static Word32 maxWithSign_fx( - const Word32 a ) + const Word32 a /* Qx */ +) { IF( GT_32( L_abs( a ), SVD_MINIMUM_VALUE_FX ) ) { diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index d0bed2c21df63a0c56ad97251c782a76158b6852..4ac7c32a8909c6b4ebf152f91cff043ca9ea59b3 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -65,9 +65,9 @@ static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( Decoder_State *st, const *-------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void stereo_tcx_init_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ - const Word16 last_element_mode /* i : element mode of previous frame */ + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 last_element_mode /* i : element mode of previous frame Q0*/ ) { TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; @@ -75,20 +75,20 @@ void stereo_tcx_init_dec_fx( st->rate_switching_init = 0; move16(); - st->m_frame_type = ACTIVE_FRAME; + st->m_frame_type = ACTIVE_FRAME; /* Q0 */ move16(); - st->core_brate = st->total_brate; + st->core_brate = st->total_brate; /* Q0 */ move32(); /*sampling rate*/ - st->sr_core = getCoreSamplerateMode2( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); + st->sr_core = getCoreSamplerateMode2( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); /* Q0 */ move32(); - st->fscale = sr2fscale_fx( st->sr_core ); + st->fscale = sr2fscale_fx( st->sr_core ); /* Q0 */ move16(); /*frame size*/ - st->L_frame = extract_l( Mult_32_16( st->sr_core, INV_FRAME_PER_SEC_Q15 ) ); - hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); + st->L_frame = extract_l( Mult_32_16( st->sr_core, INV_FRAME_PER_SEC_Q15 ) ); /* Q0 */ + hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); /* Q0 */ move16(); move16(); @@ -98,47 +98,47 @@ void stereo_tcx_init_dec_fx( test(); IF( ( EQ_16( st->L_frame, L_FRAME16k ) && LE_32( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), MAX_ACELP_BRATE ) ) || ( st->tcxonly && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, INT_FS_16k ) ) ) ) { - st->nb_subfr = NB_SUBFR16k; + st->nb_subfr = NB_SUBFR16k; /* Q0 */ move16(); } ELSE { - st->nb_subfr = NB_SUBFR; + st->nb_subfr = NB_SUBFR; /* Q0 */ move16(); } move16(); /*TCX tools*/ - st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->rf_flag ); + st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->rf_flag ); /* Q0 */ move16(); - st->hTcxCfg->resq = getResq( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ) ); + st->hTcxCfg->resq = getResq( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ) ); /* Q0 */ move16(); - hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->rf_flag, st->element_mode ); + hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->rf_flag, st->element_mode ); /* Q0 */ move16(); - st->igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->bwidth, st->rf_flag ); + st->igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->bwidth, st->rf_flag ); /* Q0 */ move16(); IF( st->element_mode != EVS_MONO ) { - st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->igf, st->element_mode ); + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->igf, st->element_mode ); /* Q0 */ move16(); } IF( hTcxLtpDec != NULL ) { - hTcxLtpDec->tcxltp = getTcxLtp( st->sr_core ); + hTcxLtpDec->tcxltp = getTcxLtp( st->sr_core ); /* Q0 */ move16(); } IF( EQ_16( st->element_mode, IVAS_SCE ) ) { - st->tcxonly = getTcxonly_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), MCT_flag, st->is_ism_format ); + st->tcxonly = getTcxonly_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), MCT_flag, st->is_ism_format ); /* Q0 */ move16(); /* LPC quantization */ test(); IF( LE_32( st->sr_core, INT_FS_16k ) && st->tcxonly == 0 ) { - st->lpcQuantization = 1; + st->lpcQuantization = 1; /* Q0 */ move16(); } ELSE @@ -150,12 +150,12 @@ void stereo_tcx_init_dec_fx( IF( st->tcxonly == 0 ) { - st->numlpc = 1; + st->numlpc = 1; /* Q0 */ move16(); } ELSE { - st->numlpc = 2; + st->numlpc = 2; /* Q0 */ move16(); } move16(); @@ -284,18 +284,18 @@ void stereo_tcx_init_dec( *-------------------------------------------------------------------*/ void stereo_tcx_core_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const FRAME_MODE frameMode, /* i : Decoder frame mode */ - Word16 *signal_out_fx, /* o : synthesis @internal_Fs, Q0 */ - Word16 *signal_outFB_fx, /* o : synthesis @output_Fs, Q0 */ - Word16 pitch_buf_fx[], /* o : Word16 pitch for each subframe, Q6 */ - const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ - STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const Word16 last_element_mode, /* i : last element mode */ - const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ - const Word16 nchan_out, /* i : number of output channels */ - const IVAS_FORMAT ivas_format /* i : IVAS format */ + Decoder_State *st, /* i/o: decoder state structure */ + const FRAME_MODE frameMode, /* i : Decoder frame mode */ + Word16 *signal_out_fx, /* o : synthesis @internal_Fs, Q0*/ + Word16 *signal_outFB_fx, /* o : synthesis @output_Fs, Q0*/ + Word16 pitch_buf_fx[], /* o : Word16 pitch for each subframe, Q6*/ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC Q0*/ + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ + const Word16 last_element_mode, /* i : last element mode Q0*/ + const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel Q0*/ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ + const Word16 nchan_out, /* i : number of output channels Q0*/ + const IVAS_FORMAT ivas_format /* i : IVAS format */ ) { Word16 i, k; @@ -357,10 +357,10 @@ void stereo_tcx_core_dec_fx( *--------------------------------------------------------------------------------*/ iDiv_and_mod_32( st->total_brate, FRAMES_PER_SEC, &L_tmp, &mod, 0 ); - total_nbbits = extract_l( L_tmp ); + total_nbbits = extract_l( L_tmp ); /* Q0 */ bitsRead = 0; move16(); - LSF_Q_prediction = -1; /* to avoid compilation warnings */ + LSF_Q_prediction = -1; /* to avoid compilation warnings Q0*/ move16(); IF( frameMode == FRAMEMODE_NORMAL ) @@ -375,7 +375,7 @@ void stereo_tcx_core_dec_fx( { st->m_decodeMode = DEC_CONCEALMENT_EXT; move32(); - bfi = 1; + bfi = 1; /* Q0 */ move16(); } /* for bass postfilter */ @@ -394,8 +394,8 @@ void stereo_tcx_core_dec_fx( /* Initialize pointers */ synth_fx = synth_buf_fx + hTcxDec->old_synth_len; synthFB_fx = synth_bufFB_fx + hTcxDec->old_synth_lenFB; - Copy_Scale_sig( hTcxDec->old_synth, synth_buf_fx, hTcxDec->old_synth_len, negate( st->Q_syn ) ); - Copy( hTcxDec->old_synthFB_fx, synth_bufFB_fx, hTcxDec->old_synth_lenFB ); + Copy_Scale_sig( hTcxDec->old_synth, synth_buf_fx, hTcxDec->old_synth_len, negate( st->Q_syn ) ); /* q_old_synth - st->Q_syn */ + Copy( hTcxDec->old_synthFB_fx, synth_bufFB_fx, hTcxDec->old_synth_lenFB ); /* q_old_synthFB */ set16_fx( synth_fx, 0, L_FRAME_PLUS + M ); set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M ); @@ -405,7 +405,7 @@ void stereo_tcx_core_dec_fx( IF( !bfi ) { - st->second_last_core = st->last_core; + st->second_last_core = st->last_core; /* Q0 */ move16(); move16(); @@ -421,7 +421,7 @@ void stereo_tcx_core_dec_fx( /* PLC: [Common: mode decision] * PLC: Decide which Concealment to use. Update pitch lags if needed */ - st->core = GetPLCModeDecision_ivas_fx( st ); + st->core = GetPLCModeDecision_ivas_fx( st ); /* Q0 */ move16(); } @@ -442,24 +442,24 @@ void stereo_tcx_core_dec_fx( test(); IF( bfi && st->use_partial_copy && EQ_16( st->rf_frame_type, RF_TCXFD ) ) { - tcx_lpc_cdk = tcxlpc_get_cdk( GENERIC ); + tcx_lpc_cdk = tcxlpc_get_cdk( GENERIC ); /* Q0 */ move16(); } ELSE { - tcx_lpc_cdk = tcxlpc_get_cdk( st->coder_type ); + tcx_lpc_cdk = tcxlpc_get_cdk( st->coder_type ); /* Q0 */ move16(); } - Copy( st->lsf_old_fx, &lsf_fx[0], M ); - Copy( st->lsp_old_fx, &lsp_fx[0], M ); + Copy( st->lsf_old_fx, &lsf_fx[0], M ); /* Q2.56 */ + Copy( st->lsp_old_fx, &lsp_fx[0], M ); /* Q15 */ D_lsf_tcxlpc( param_lpc, &lsf_fx[M], lspind, st->narrowBand, tcx_lpc_cdk, st->mem_MA_fx ); lsf2lsp_fx( &lsf_fx[M], &lsp_fx[M], M, st->sr_core ); lsf_update_memory( st->narrowBand, &lsf_fx[M], st->mem_MA_fx, st->mem_MA_fx, M ); - Copy( &lsf_fx[M], st->mem_AR_fx, M ); + Copy( &lsf_fx[M], st->mem_AR_fx, M ); /* Q2.56 */ hTcxDec->envWeighted = 1; move16(); @@ -470,8 +470,8 @@ void stereo_tcx_core_dec_fx( { IF( hTcxDec->envWeighted ) { - Copy( st->lspold_uw, st->lsp_old_fx, M ); - Copy( st->lsfold_uw, st->lsf_old_fx, M ); + Copy( st->lspold_uw, st->lsp_old_fx, M ); /* Q15 */ + Copy( st->lsfold_uw, st->lsf_old_fx, M ); /* Q2.56 */ hTcxDec->envWeighted = 0; move16(); } @@ -480,8 +480,8 @@ void stereo_tcx_core_dec_fx( FOR( k = 0; k < st->numlpc; ++k ) { - Copy( &lsp_fx[imult1616( add( k, 1 ), M )], &lspnew_uw_fx[k * M], M ); /*basop not used for k * M as M is a multiple of 2*/ - Copy( &lsf_fx[imult1616( add( k, 1 ), M )], &lsfnew_uw_fx[k * M], M ); + Copy( &lsp_fx[( k + 1 ) * M], &lspnew_uw_fx[k * M], M ); /*basop not used for k * M as M is a multiple of 2 Q15*/ + Copy( &lsf_fx[( k + 1 ) * M], &lsfnew_uw_fx[k * M], M ); /* Q2.56 */ } } @@ -490,11 +490,11 @@ void stereo_tcx_core_dec_fx( { FOR( i = 0; i < M; i++ ) { - st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], ONE_BY_THREE_Q15 ), mult_r( st->lsfoldbfi0_fx[i], ONE_BY_THREE_Q15 ) ), mult_r( lsfnew_uw_fx[add( i_mult( k, M ), i )], ONE_BY_THREE_Q15 ) ); + st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], ONE_BY_THREE_Q15 ), mult_r( st->lsfoldbfi0_fx[i], ONE_BY_THREE_Q15 ) ), mult_r( lsfnew_uw_fx[k * M + i], ONE_BY_THREE_Q15 ) ); /* Q2.56 */ move16(); - st->lsfoldbfi1_fx[i] = st->lsfoldbfi0_fx[i]; + st->lsfoldbfi1_fx[i] = st->lsfoldbfi0_fx[i]; /* Q2.56 */ move16(); - st->lsfoldbfi0_fx[i] = lsfnew_uw_fx[add( i_mult( k, M ), i )]; + st->lsfoldbfi0_fx[i] = lsfnew_uw_fx[( k * M ) + i]; /* Q2.56 */ move16(); } } @@ -519,28 +519,28 @@ void stereo_tcx_core_dec_fx( IF( EQ_16( st->nbLostCmpt, 1 ) ) { - Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); - Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); + Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); /* Q2.56 */ + Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); /* Q15 */ } - lsfBase = PlcGetLsfBase( st->lpcQuantization, st->narrowBand, st->sr_core ); + lsfBase = PlcGetLsfBase( st->lpcQuantization, st->narrowBand, st->sr_core ); /* Q2.56 */ dlpc_bfi( st->L_frame, lsfnew_uw_fx, st->lsfold_uw, st->last_good, st->nbLostCmpt, st->mem_MA_fx, st->mem_AR_fx, &( st->stab_fac_fx ), st->lsf_adaptive_mean_fx, st->numlpc, st->lsf_cng, (Word8) st->plcBackgroundNoiseUpdated, st->lsf_q_cng, st->old_lsf_q_cng, lsfBase, (Word8) st->tcxonly ); hTcxDec->envWeighted = 0; move16(); - Copy( st->lspold_uw, lsp_fx, M ); - Copy( st->lsfold_uw, lsf_fx, M ); + Copy( st->lspold_uw, lsp_fx, M ); /* Q15 */ + Copy( st->lsfold_uw, lsf_fx, M ); /* Q2.56 */ FOR( k = 0; k < st->numlpc; k++ ) { - Copy( &lsfnew_uw_fx[k * M], &lsf_fx[imult1616( add( k, 1 ), M )], M ); + Copy( &lsfnew_uw_fx[k * M], &lsf_fx[( k + 1 ) * M], M ); /* Q2.56 */ - lsf2lsp_fx( &lsf_fx[imult1616( add( k, 1 ), M )], &lsp_fx[imult1616( add( k, 1 ), M )], M, st->sr_core ); - lsf2lsp_fx( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core ); + lsf2lsp_fx( &lsf_fx[( k + 1 ) * M], &lsp_fx[( k + 1 ) * M], M, st->sr_core ); /* Q2.56 */ + lsf2lsp_fx( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core ); /* Q2.56 */ - Copy( &lsp_fx[imult1616( add( k, 1 ), M )], &lspnew_uw_fx[k * M], M ); + Copy( &lsp_fx[( k + 1 ) * M], &lspnew_uw_fx[k * M], M ); /* Q2.56 */ } } @@ -550,19 +550,19 @@ void stereo_tcx_core_dec_fx( IF( st->rate_switching_reset ) { - Copy( &( lsf_fx[M] ), &( lsf_fx[0] ), M ); - Copy( &( lsp_fx[M] ), &( lsp_fx[0] ), M ); - Copy( &( lsf_fx[M] ), st->lsf_old_fx, M ); - Copy( &( lsp_fx[M] ), st->lsp_old_fx, M ); - Copy( &( lsf_fx[M] ), lsfmid_fx, M ); - Copy( &( lsp_fx[M] ), lspmid_fx, M ); + Copy( &( lsf_fx[M] ), &( lsf_fx[0] ), M ); /* Q2.56 */ + Copy( &( lsp_fx[M] ), &( lsp_fx[0] ), M ); /* Q15 */ + Copy( &( lsf_fx[M] ), st->lsf_old_fx, M ); /* Q2.56 */ + Copy( &( lsp_fx[M] ), st->lsp_old_fx, M ); /* Q2.56 */ + Copy( &( lsf_fx[M] ), lsfmid_fx, M ); /* Q2.56 */ + Copy( &( lsp_fx[M] ), lspmid_fx, M ); /* Q15 */ E_LPC_f_lsp_a_conversion( st->lsp_old_fx, st->old_Aq_12_8_fx, M ); } test(); if ( st->enablePlcWaveadjust && bfi ) { - st->hPlcInfo->nbLostCmpt = add( st->hPlcInfo->nbLostCmpt, 1 ); + st->hPlcInfo->nbLostCmpt = add( st->hPlcInfo->nbLostCmpt, 1 ); /* Q0 */ move16(); } @@ -586,11 +586,11 @@ void stereo_tcx_core_dec_fx( test(); IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { - Copy_Scale_sig( &synthFB_fx[negate( add( add( shr( st->hTcxDec->L_frameTCX, 1 ), hTcxDec->pit_max_TCX ), 2 * M ) )], &synthFB_fx[negate( add( add( shr( st->hTcxDec->L_frameTCX, 1 ), hTcxDec->pit_max_TCX ), 2 * M ) )], add( add( shr( st->hTcxDec->L_frameTCX, 1 ), hTcxDec->pit_max_TCX ), 2 * M ), negate( sub( st->Q_exc, 1 ) ) ); + Copy_Scale_sig( &synthFB_fx[-( ( st->hTcxDec->L_frameTCX / 2 ) + hTcxDec->pit_max_TCX + 2 * M )], &synthFB_fx[-( ( st->hTcxDec->L_frameTCX / 2 ) + hTcxDec->pit_max_TCX + 2 * M )], add( add( shr( st->hTcxDec->L_frameTCX, 1 ), hTcxDec->pit_max_TCX ), 2 * M ), negate( sub( st->Q_exc, 1 ) ) ); /* q_old_synthFB + Q_exc - 1 */ } ELSE { - Copy_Scale_sig( &synthFB_fx[negate( st->hTcxDec->L_frameTCX )], &synthFB_fx[negate( st->hTcxDec->L_frameTCX )], st->hTcxDec->L_frameTCX, negate( sub( st->Q_exc, 1 ) ) ); + Copy_Scale_sig( &synthFB_fx[-( st->hTcxDec->L_frameTCX )], &synthFB_fx[-( st->hTcxDec->L_frameTCX )], st->hTcxDec->L_frameTCX, negate( sub( st->Q_exc, 1 ) ) ); /* q_old_synthFB + Q_exc - 1 */ } lerp( synthFB_fx, synth_fx, st->L_frame, hTcxDec->L_frameTCX ); @@ -604,7 +604,7 @@ void stereo_tcx_core_dec_fx( test(); IF( st->narrowBand || EQ_32( st->sr_core, INT_FS_12k8 ) || EQ_32( st->sr_core, INT_FS_16k ) ) { - Copy( Aq_fx, st->mem_Aq, i_mult( st->nb_subfr, ( M + 1 ) ) ); + Copy( Aq_fx, st->mem_Aq, i_mult( st->nb_subfr, ( M + 1 ) ) ); /* Q12 */ } /* PLC: [TCX: Tonal Concealment] */ @@ -620,14 +620,14 @@ void stereo_tcx_core_dec_fx( *--------------------------------------------------------------------------------*/ /* Set pointer to parameters */ - prm = param; + prm = param; /* Q0 */ IF( EQ_16( st->core, TCX_20_CORE ) ) { /* Stability Factor */ IF( !bfi ) { - st->stab_fac_fx = lsf_stab_fx( &lsf_fx[M], &lsf_fx[0], 0, st->L_frame ); + st->stab_fac_fx = lsf_stab_fx( &lsf_fx[M], &lsf_fx[0], 0, st->L_frame ); /* Q15 */ move16(); } @@ -645,7 +645,7 @@ void stereo_tcx_core_dec_fx( /* diffuse LPC power on rate switching*/ RecLpcSpecPowDiffuseLc( &lsp_fx[M], &lsp_fx[0], &lsf_fx[M], st, 0 ); int_lsp_fx( st->L_frame, &lsp_fx[0], &lsp_fx[M], Aq_fx, M, interpol_frac_fx, 0 ); - Copy( &lsf_fx[M], lsfnew_uw_fx, M ); + Copy( &lsf_fx[M], lsfnew_uw_fx, M ); /* Q2.56 */ } ELSE { @@ -678,22 +678,22 @@ void stereo_tcx_core_dec_fx( FOR( k = 0; k < 2; k++ ) { /* Set pointer to parameters */ - prm = param + imult1616( k, DEC_NPRM_DIV ); + prm = param + imult1616( k, DEC_NPRM_DIV ); /* Q0 */ /* Stability Factor */ IF( !bfi ) { - st->stab_fac_fx = lsf_stab_fx( &lsf_fx[imult1616( add( k, 1 ), M )], &lsf_fx[k * M], 0, st->L_frame ); + st->stab_fac_fx = lsf_stab_fx( &lsf_fx[( k + 1 ) * M], &lsf_fx[k * M], 0, st->L_frame ); /* Q15 */ move16(); } - E_LPC_f_lsp_a_conversion( &lsp_fx[imult1616( add( k, 1 ), M )], Aq_fx, M ); + E_LPC_f_lsp_a_conversion( &lsp_fx[( k + 1 ) * M], Aq_fx, M ); { IGFDecRestoreTCX10SubFrameData_fx( st->hIGFDec, k ); } /* TCX decoder */ - decoder_tcx_ivas_fx( st, prm, Aq_fx, Aind, &synth_fx[imult1616( k, shr( st->L_frame, 1 ) )], &synthFB_fx[imult1616( k, shr( hTcxDec->L_frameTCX, 1 ) )], bfi, k, sba_dirac_stereo_flag ); + decoder_tcx_ivas_fx( st, prm, Aq_fx, Aind, &synth_fx[k * st->L_frame / 2], &synthFB_fx[k * ( hTcxDec->L_frameTCX / 2 )], bfi, k, sba_dirac_stereo_flag ); } } @@ -743,7 +743,7 @@ void stereo_tcx_core_dec_fx( IF( st->narrowBand || EQ_32( st->sr_core, INT_FS_12k8 ) || EQ_32( st->sr_core, INT_FS_16k ) ) { int_lsp_fx( st->L_frame, st->lspold_uw, lspnew_uw_fx, Aq_fx, M, interpol_frac_fx, 0 ); - Copy( Aq_fx, st->mem_Aq, i_mult( st->nb_subfr, ( M + 1 ) ) ); + Copy( Aq_fx, st->mem_Aq, i_mult( st->nb_subfr, ( M + 1 ) ) ); /* Q12 */ } } } @@ -764,9 +764,9 @@ void stereo_tcx_core_dec_fx( set16_fx( pitch_C, shl( round_fx( st->old_fpitch ), Q6 ), 4 ); /* note: codec_mode is forced to MODE2, since FEC_clas_estim() considers only TCX being in Mode2*/ - Word16 prev_codec_mode = st->codec_mode; + Word16 prev_codec_mode = st->codec_mode; /* Q0 */ move16(); - st->codec_mode = MODE2; + st->codec_mode = MODE2; /* Q0 */ move16(); IF( st->tcxonly ) { @@ -784,7 +784,7 @@ void stereo_tcx_core_dec_fx( FEC_clas_estim_fx( st, 0, st->L_frame, &st->clas_dec, st->core_ext_mode, pitch_C, synth_fx, &st->lp_ener_FER_fx, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, hTcxLtpDec->tcxltp ? hTcxDec->tcxltp_last_gain_unmodified : MIN_16, CLASSIFIER_TCX, bfi, st->last_core_brate, -1 ); #endif } - st->codec_mode = prev_codec_mode; + st->codec_mode = prev_codec_mode; /* Q0 */ move16(); } } @@ -818,23 +818,23 @@ void stereo_tcx_core_dec_fx( } /* Update past buffers */ - Copy_Scale_sig( synth_buf_fx + st->L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len, 0 ); - Copy( hTcxDec->old_synthFB_fx + sub( hTcxDec->L_frameTCX, NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ), hTcxDec->synth_history_fx, NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ); - Copy( synth_bufFB_fx + hTcxDec->L_frameTCX, hTcxDec->old_synthFB_fx, hTcxDec->old_synth_lenFB ); - Copy( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + hTcxDec->old_synth_lenFB, NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + Copy_Scale_sig( synth_buf_fx + st->L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len, 0 ); /* q_old_synth - st->Q_syn */ + Copy( hTcxDec->old_synthFB_fx + sub( hTcxDec->L_frameTCX, NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ), hTcxDec->synth_history_fx, NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ); /* q_old_synthFB */ + Copy( synth_bufFB_fx + hTcxDec->L_frameTCX, hTcxDec->old_synthFB_fx, hTcxDec->old_synth_lenFB ); /* q_old_synthFB */ + Copy( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + hTcxDec->old_synth_lenFB, NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); /* exp(exp_old_out) */ Copy( &lspnew_uw_fx[imult1616( sub( st->numlpc, 1 ), M )], st->lspold_uw, M ); Copy( &lsfnew_uw_fx[imult1616( sub( st->numlpc, 1 ), M )], st->lsfold_uw, M ); IF( EQ_16( bfi, 1 ) ) { - Copy( st->lspold_uw, st->lsp_old_fx, M ); /* for recovery */ - Copy( st->lsfold_uw, st->lsf_old_fx, M ); /* for recovery */ + Copy( st->lspold_uw, st->lsp_old_fx, M ); /* for recovery Q15*/ + Copy( st->lsfold_uw, st->lsf_old_fx, M ); /* for recovery Q15*/ } ELSE { - Copy( &lsp_fx[i_mult( st->numlpc, M )], st->lsp_old_fx, M ); - Copy( &lsf_fx[i_mult( st->numlpc, M )], st->lsf_old_fx, M ); + Copy( &lsp_fx[( st->numlpc ) * M], st->lsp_old_fx, M ); /* Q15 */ + Copy( &lsf_fx[( st->numlpc ) * M], st->lsf_old_fx, M ); /* Q2.56 */ } Copy( st->lsp_q_cng, st->old_lsp_q_cng, M ); Copy( st->lsf_q_cng, st->old_lsf_q_cng, M ); @@ -851,7 +851,7 @@ void stereo_tcx_core_dec_fx( Word16 buf[L_LP], res[L_FRAME], A[M + 1], r_h[M + 1], r_l[M + 1], tmp, lsptmp[M], q_r; assert( EQ_16( st->L_frame, L_FRAME ) ); - Copy( synth_fx + L_FRAME - L_LP, buf, L_LP ); + Copy( synth_fx + L_FRAME - L_LP, buf, L_LP ); /* q_old_synth - st->Q_syn */ tmp = synth_fx[L_FRAME - L_LP - 1]; move16(); E_UTIL_f_preemph2( 0, buf, st->preemph_fac, L_LP, &tmp ); @@ -879,7 +879,7 @@ void stereo_tcx_core_dec_fx( } ELSE { - st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1; + st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1; /* Q0 */ move16(); } } @@ -904,11 +904,11 @@ void stereo_tcx_core_dec_fx( IF( st->p_bpf_noise_buf_32 ) #endif // MSAN_FIX { - Copy_Scale_sig_16_32_no_sat( st->p_bpf_noise_buf, st->p_bpf_noise_buf_32, st->L_frame, Q11 ); + Copy_Scale_sig_16_32_no_sat( st->p_bpf_noise_buf, st->p_bpf_noise_buf_32, st->L_frame, Q11 ); /* q_p_bpf + Q11 */ } IF( signal_outFB_fx ) { - Copy( synthFB_fx, signal_outFB_fx, hTcxDec->L_frameTCX ); + Copy( synthFB_fx, signal_outFB_fx, hTcxDec->L_frameTCX ); /* q_old_synthFB */ } IF( !bfi ) @@ -941,7 +941,7 @@ void stereo_tcx_core_dec_fx( /* updates */ st->last_voice_factor_fx = 0; move16(); - st->last_coder_type = st->coder_type; + st->last_coder_type = st->coder_type; /* Q0 */ move16(); /* -------------------------------------------------------------- * @@ -956,9 +956,9 @@ void stereo_tcx_core_dec_fx( noisy_speech_detection_fx( st->hFdCngDec, st->VAD && EQ_16( st->m_frame_type, ACTIVE_FRAME ), signal_out_fx, 0 ); st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), - imult3216( Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); - st->lp_noise = st->hFdCngDec->lp_noise; + imult3216( Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); /* Q31 */ + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); /* Q15 */ + st->lp_noise = st->hFdCngDec->lp_noise; /* Q9.23 */ move32(); move32(); move16(); @@ -996,8 +996,13 @@ void stereo_tcx_core_dec_fx( } ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { - // generate_masking_noise( signal_out, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); - generate_masking_noise_fx( signal_out_fx, 0, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 ); + Word32 signal_out_32_fx[L_FRAME48k]; + Word16 exp; + Copy_Scale_sig_16_32_no_sat( signal_out_fx, signal_out_32_fx, st->hFdCngDec->hFdCngCom->frameSize, Q6 ); + Copy_Scale_sig_16_32_no_sat( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), Q15 ); + generate_masking_noise_ivas_fx( signal_out_32_fx, &exp, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); + Copy_Scale_sig_32_16( signal_out_32_fx, signal_out_fx, st->hFdCngDec->hFdCngCom->frameSize, negate( exp ) ); // Q0 + Copy_Scale_sig_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), -Q15 ); // Q0 } } @@ -1765,9 +1770,9 @@ static void stereo_tcx_dec_mode_switch_reconf( #endif #ifdef IVAS_FLOAT_FIXED static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ - const Word16 last_element_mode, /* i : element mode of previous frame */ + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 last_element_mode, /* i : element mode of previous frame Q0*/ Word16 *Q_syn_Overl_TDAC, Word16 *Q_fer_samples, Word16 *Q_syn_Overl, @@ -1779,7 +1784,7 @@ static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( { Word16 frame_size_index; - st->rate_switching_init = 1; + st->rate_switching_init = 1; /* Q0 */ move16(); /* Identify frame type - TCX Reconfiguration */ @@ -1808,12 +1813,12 @@ static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( return; } static void dec_prm_tcx_ivas_fx( - Decoder_State *st, /* i/o: decoder memory state */ - Word16 param[], /* o : decoded parameters */ - Word16 param_lpc[], /* o : LPC parameters */ - Word16 *total_nbbits, /* i/o: number of bits / decoded bits */ - const Word16 last_element_mode, /* i : last element mode */ - Word16 *bitsRead /* o : number of read bits */ + Decoder_State *st, /* i/o: decoder memory state */ + Word16 param[], /* o : decoded parameters Q0*/ + Word16 param_lpc[], /* o : LPC parameters Q0*/ + Word16 *total_nbbits, /* i/o: number of bits / decoded bits Q0*/ + const Word16 last_element_mode, /* i : last element mode Q0*/ + Word16 *bitsRead /* o : number of read bits Q0*/ ) { Word16 start_bit_pos, bits_common; @@ -1830,14 +1835,14 @@ static void dec_prm_tcx_ivas_fx( IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { // The value of 1/ FRAMES_PER_SEC shifted left by 19 because taking Q as 15 led to precision loss - st->bits_frame_core = extract_l( L_sub( L_shr( Mpy_32_16_1( st->total_brate, 10486 ), 4 ), st->next_bit_pos ) ); + st->bits_frame_core = extract_l( L_sub( L_shr( Mpy_32_16_1( st->total_brate, 10486 ), 4 ), st->next_bit_pos ) ); /* Q0 */ move16(); } - start_bit_pos = st->next_bit_pos; + start_bit_pos = st->next_bit_pos; /* Q0 */ move16(); /* Init LTP data */ - st->hTcxDec->tcx_hm_LtpPitchLag = -1; + st->hTcxDec->tcx_hm_LtpPitchLag = -1; /* Q0 */ move16(); st->hTcxLtpDec->tcxltp_gain = 0; move16(); @@ -1853,7 +1858,7 @@ static void dec_prm_tcx_ivas_fx( test(); IF( !st->use_partial_copy && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - st->last_core_from_bs = get_next_indice_fx( st, 1 ); /* Store decoder memory of last_core */ + st->last_core_from_bs = get_next_indice_fx( st, 1 ); /* Store decoder memory of last_core Q0*/ move16(); test(); @@ -1862,7 +1867,7 @@ static void dec_prm_tcx_ivas_fx( /* A mismatch between the memory and the last_core from the bitstream indicates a frame was lost. If prev_bfi is not set the frame loss occured during CNG and the prev_bfi needs to be set. */ - st->prev_bfi = 1; + st->prev_bfi = 1; /* Q0 */ move16(); } @@ -1885,13 +1890,13 @@ static void dec_prm_tcx_ivas_fx( &st->hHQ_core->Q_old_wtda_LB, &Q_old_Aq_12_8 ); } - st->last_core = st->last_core_from_bs; + st->last_core = st->last_core_from_bs; /* Q0 */ move16(); /*for TCX 10 force last_core to be TCX since ACELP as previous core is forbidden*/ if ( EQ_16( st->core, TCX_10_CORE ) ) { - st->last_core = TCX_20_CORE; + st->last_core = TCX_20_CORE; /* Q0 */ move16(); } } @@ -1937,11 +1942,11 @@ static void dec_prm_tcx_ivas_fx( { st->BER_detect = 1; move16(); - st->next_bit_pos = add( start_bit_pos, sub( *total_nbbits, bitsRead[0] ) ); + st->next_bit_pos = add( start_bit_pos, sub( *total_nbbits, bitsRead[0] ) ); /* Q0 */ move16(); } - bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); + bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); /* Q0 */ move16(); } diff --git a/lib_dec/ivas_td_low_rate_dec.c b/lib_dec/ivas_td_low_rate_dec.c index 132a7d7434de65740d93d756fa4c1a272f484c04..03f85a5d6a155f604223a6a4542fda0479c4b16a 100644 --- a/lib_dec/ivas_td_low_rate_dec.c +++ b/lib_dec/ivas_td_low_rate_dec.c @@ -219,14 +219,14 @@ void tdm_low_rate_dec( #endif #ifdef IVAS_FLOAT_FIXED void tdm_low_rate_dec_fx( - Decoder_State *st, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain Q_exc */ - Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6 */ - Word16 *voice_factors, /* o : voicing factors Q15 */ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc */ - const Word16 *lsf_new /* i : ISFs at the end of the frame Q8/100 (2.56x) */ + Decoder_State *st, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Q_exc*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + const Word16 *lsf_new /* i : ISFs at the end of the frame Q8/100 (2.56x)*/ ) { Word16 tmp_nb_bits_tot, pit_band_idx; @@ -249,11 +249,11 @@ void tdm_low_rate_dec_fx( move16(); st->GSC_noisy_speech = 1; move16(); - hGSCDec->noise_lev = 14; + hGSCDec->noise_lev = 14; /* Q0 */ move16(); - pit_band_idx = 10 + BAND1k2; - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; + pit_band_idx = 10 + BAND1k2; /* Q0 */ + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ move16(); move16(); @@ -265,9 +265,9 @@ void tdm_low_rate_dec_fx( st->bpf_off = 1; move16(); - st->bfi_pitch_fx = mean_fx( pitch_buf, 4 ); + st->bfi_pitch_fx = mean_fx( pitch_buf, 4 ); /* Q6 */ move16(); - st->bfi_pitch_frame = L_FRAME; + st->bfi_pitch_frame = L_FRAME; /* Q0 */ move16(); Diff_len = L_FRAME / 2; move16(); @@ -285,24 +285,24 @@ void tdm_low_rate_dec_fx( *--------------------------------------------------------------------------------------*/ /* find the current total number of bits used */ - tmp_nb_bits_tot = st->next_bit_pos; + tmp_nb_bits_tot = st->next_bit_pos; /* Q0 */ move16(); move16(); if ( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); + tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); /* Q0 */ } if ( EQ_16( st->tdm_LRTD_flag, 1 ) ) { - tmp_nb_bits_tot = sub( tmp_nb_bits_tot, STEREO_BITS_TCA ); + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, STEREO_BITS_TCA ); /* Q0 */ } if ( st->extl_brate_orig > 0 ) { /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ - tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); /* Q0 */ } gsc_dec_ivas_fx( st, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st->coder_type, &last_bin, lsf_new, exc_wo_nf_fx, &st->Q_exc ); @@ -348,8 +348,8 @@ void tdm_low_rate_dec_fx( * Updates *--------------------------------------------------------------------------------------*/ - Copy( exc, exc2, L_FRAME ); - Copy( exc_wo_nf_fx, exc, L_FRAME ); + Copy( exc, exc2, L_FRAME ); /* Q_exc */ + Copy( exc_wo_nf_fx, exc, L_FRAME ); /* Q_exc */ /*--------------------------------------------------------------------------------------* * Channel aware mode parameters @@ -507,16 +507,16 @@ void decod_gen_2sbfr( void decod_gen_2sbfr_ivas_fx( Decoder_State *st, /* i/o: decoder static memory */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 *Aq, /* i : LP filter coefficient Q12 */ - Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6 */ - Word16 *voice_factors, /* o : voicing factors Q15 */ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc */ - Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14 */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : pitch values for primary channel Q6 */ + const Word16 sharpFlag, /* i : formant sharpening flag `Q0*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[] /* i : pitch values for primary channel Q6*/ ) { Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables */ @@ -560,8 +560,8 @@ void decod_gen_2sbfr_ivas_fx( * ACELP subframe loop *------------------------------------------------------------------*/ - p_Aq = Aq; /* pointer to interpolated LPC parameters */ - pt_pitch = pitch_buf; /* pointer to the pitch buffer */ + p_Aq = Aq; /* pointer to interpolated LPC parameters Q12*/ + pt_pitch = pitch_buf; /* pointer to the pitch buffer Q6*/ FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += 2 * L_SUBFR ) { @@ -569,7 +569,7 @@ void decod_gen_2sbfr_ivas_fx( * Decode pitch lag *----------------------------------------------------------------------*/ - *pt_pitch = pit_decode_ivas_fx( st, st->core_brate, 0, L_frame, i_subfr, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, 2 * L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + *pt_pitch = pit_decode_ivas_fx( st, st->core_brate, 0, L_frame, i_subfr, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, 2 * L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); /* Q6 */ test(); test(); @@ -602,19 +602,19 @@ void decod_gen_2sbfr_ivas_fx( *--------------------------------------------------------------*/ gain_dec_lbr_ivas_fx( st, GENERIC, i_subfr, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, gc_mem, gp_mem, 2 * L_SUBFR ); - st->tilt_code_fx = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, st->Q_exc, 2 * L_SUBFR, 0 ); + st->tilt_code_fx = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, st->Q_exc, 2 * L_SUBFR, 0 ); /* Q15 */ move16(); /* update LP filtered gains for the case of frame erasures */ lp_gain_updt_ivas_fx( i_subfr, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); - lp_gain_updt_ivas_fx( i_subfr + L_SUBFR, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); + lp_gain_updt_ivas_fx( add( i_subfr, L_SUBFR ), gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); /*----------------------------------------------------------------------* * Find the total excitation *----------------------------------------------------------------------*/ #ifdef FIX_734_MISSING_SUBFR_LOW_RATE_ACELP /* Don't need the if/else as here L_frame==L_FRAME all the time */ - Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], ( bwe_exc != NULL ) ? &bwe_exc[imult1616( i_subfr, HIBND_ACB_L_FAC )] : NULL, st->hGSCDec->last_exc_dct_in_fx, + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], ( bwe_exc != NULL ) ? &bwe_exc[i_subfr * HIBND_ACB_L_FAC] : NULL, st->hGSCDec->last_exc_dct_in_fx, 2 * L_SUBFR, 2 * L_SUBFR * HIBND_ACB_L_FAC, gain_code, &( st->Q_exc ), st->Q_subfr, exc2, i_subfr, st->coder_type ); #else @@ -646,7 +646,7 @@ void decod_gen_2sbfr_ivas_fx( // prep_tbe_exc_fx(L_frame, /*L_SUBFR,*/ i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, Q_exc, T0, T0_frac, GENERIC, st->core_brate/*, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag*/); prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, st->Q_exc, T0, T0_frac, GENERIC, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); #endif - voice_factors[add( shr( i_subfr, 6 ) /*i_subfr / L_SUBFR*/, 1 )] = voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/]; + voice_factors[i_subfr / L_SUBFR + 1] = voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/]; /* Q15 */ move16(); /*----------------------------------------------------------------* @@ -666,25 +666,25 @@ void decod_gen_2sbfr_ivas_fx( // enhancer_fx(MODE1, st->core_brate, -1, 0, GENERIC, L_frame, voice_fac, st->stab_fac, norm_gain_code, gain_inov, &st->gc_threshold, code + L_SUBFR, exc2 + i_subfr + L_SUBFR, gain_pit, st->dispMem); enhancer_fx( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code + L_SUBFR, exc2 + L_SUBFR, gain_pit, &st->dm_fx, st->Q_exc ); #endif - p_Aq += 2 * ( M + 1 ); + p_Aq += 2 * ( M + 1 ); /* Q12 */ pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); + *pt_pitch = *( pt_pitch - 1 ); /* Q6 */ move16(); pt_pitch++; - gain_buf[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/] = gain_pit; + gain_buf[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/] = gain_pit; /* Q14 */ move16(); - gain_buf[shr( add( i_subfr, L_SUBFR ), 6 ) /*(i_subfr+L_SUBFR) / L_SUBFR*/] = gain_pit; + gain_buf[( i_subfr + L_SUBFR ) / L_SUBFR /*(i_subfr+L_SUBFR) / L_SUBFR*/] = gain_pit; /* Q14 */ move16(); - st->tilt_code_dec_fx[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/] = st->tilt_code_fx; + st->tilt_code_dec_fx[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/] = st->tilt_code_fx; /* Q15 */ move16(); - st->tilt_code_dec_fx[shr( add( i_subfr, L_SUBFR ), 6 ) /*( i_subfr + L_SUBFR ) / L_SUBFR*/] = st->tilt_code_fx; + st->tilt_code_dec_fx[( i_subfr + L_SUBFR ) / L_SUBFR /*( i_subfr + L_SUBFR ) / L_SUBFR*/] = st->tilt_code_fx; /* Q15 */ move16(); } /* SC-VBR */ - st->prev_gain_pit_dec_fx = gain_pit; + st->prev_gain_pit_dec_fx = gain_pit; /* Q14 */ move16(); return; diff --git a/lib_dec/jbm_jb4sb.c b/lib_dec/jbm_jb4sb.c index 32c52ba3b29b3e04d2e6b2385acabd14b7c7e453..44d6abe4ba1c9eea19e2651b904d9769824e6924 100644 --- a/lib_dec/jbm_jb4sb.c +++ b/lib_dec/jbm_jb4sb.c @@ -240,7 +240,7 @@ ivas_error JB4_Create( move32(); /* internal configuration values - do not change!!! */ h->timeScale = 0; - move32(); + move16(); h->frameDuration = 0; move32(); @@ -789,7 +789,7 @@ static Word16 JB4_adaptPlayout( *maxScaling = 0; move32(); stretchTime = false; - + move16(); /* switch type of current playout (first one, active, DTX) */ IF( !h->firstDataUnitPopped ) { diff --git a/lib_dec/lead_deindexing_fx.c b/lib_dec/lead_deindexing_fx.c index 068d60bb1d60d979f1a5e9f3eacb51b75ee76256..4c13ee3925cadf38788674a21ea2ff2f3cbcf320 100644 --- a/lib_dec/lead_deindexing_fx.c +++ b/lib_dec/lead_deindexing_fx.c @@ -277,7 +277,7 @@ static void fcb_decode_pos_fx( FOR( i = 0; i < tmp_loop; i++ ) { select_table23 = select_table22[temp1]; - select_table24 = &select_table23[sub( pulse_num, l )]; + select_table24 = &select_table23[pulse_num - l]; k = sub( *select_table24, k ); WHILE( LE_16( k, *select_table24 ) ) @@ -286,7 +286,7 @@ static void fcb_decode_pos_fx( select_table24--; } - k = sub( select_table23[sub( temp2, l )], k ); + k = sub( select_table23[temp2 - l], k ); pos_vector[i] = sub( l, 1 ); move16(); temp1 = sub( temp1, 1 ); diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 93604547bfe678f75723ead0a3df02b2b8a8f876..e44092fb60ae1f11095e92ec3a8d29da991da1af 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -430,7 +430,7 @@ ivas_error IVAS_DEC_Configure( const IVAS_HEAD_ORIENT_TRK_T orientation_tracking, /* i : head orientation tracking type */ const Word16 renderConfigEnabled, /* i : enable Renderer config. file for binaural output */ const Word16 Opt_non_diegetic_pan, /* i : diegetic or not */ - const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain */ + const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain Q15 */ const Word16 Opt_dpid_on, /* i : enable directivity pattern option */ const UWord16 acousticEnvironmentId, /* i : Acoustic environment ID */ const Word16 delayCompensationEnabled /* i : enable delay compensation */ @@ -455,7 +455,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( ivas_error IVAS_DEC_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 nSamplesAsked, /* i : number of samples wanted by the caller */ - Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */ Word16 *nOutSamples, /* o : number of samples per channel written to output buffer */ bool *needNewFrame /* o : indication that the decoder needs a new frame */ ); @@ -527,14 +527,14 @@ ivas_error IVAS_DEC_VoIP_SetScale( ivas_error IVAS_DEC_TSM_SetQuality( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const Word16 quality /* i : target TSM quality */ + const Word16 quality /* i : target TSM quality Q14 */ ); /*! r: error code */ ivas_error IVAS_DEC_VoIP_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ UWord16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ - Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */ const UWord32 systemTimestamp_ms /* i : current system timestamp */ #ifdef SUPPORT_JBM_TRACEFILE , JbmTraceFileWriterFn jbmWriterFn, @@ -545,7 +545,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( ivas_error IVAS_DEC_Flush( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ - Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */ Word16 *nSamplesFlushed /* o : number of samples flushed */ ); @@ -571,12 +571,12 @@ ivas_error IVAS_DEC_GetRenderFramesize( ivas_error IVAS_DEC_GetRenderFramesizeSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *render_framesize /* o : render framesize in samples */ + Word16 *render_framesize /* o : render framesize in samples Q0 */ ); ivas_error IVAS_DEC_GetReferencesUpdateFrequency( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *update_frequency /* o : update frequency */ + Word16 *update_frequency /* o : update frequency Q0 */ ); ivas_error IVAS_DEC_GetNumOrientationSubframes( @@ -586,7 +586,7 @@ ivas_error IVAS_DEC_GetNumOrientationSubframes( ivas_error IVAS_DEC_GetRenderFramesizeMs( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - UWord32 *render_framesize /* o : render framesize in samples */ + UWord32 *render_framesize /* o : render framesize in samples Q0 */ ); @@ -678,7 +678,7 @@ ivas_error IVAS_DEC_HasDecodedFirstGoodFrame( /*! r: error code */ ivas_error IVAS_DEC_GetPcmFrameSize( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word32 *pcmFrameSize /* o : total size of the PCM output frame. This takes into account the number of output channels */ + Word32 *pcmFrameSize /* o : total size of the PCM output frame. This takes into account the number of output channels Q0 */ ); /*! r: true if decoder has no data in VoIP jitter buffer */ @@ -689,8 +689,8 @@ bool IVAS_DEC_VoIP_IsEmpty( ivas_error IVAS_DEC_VoIP_Get_CA_offset( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *optimum_offset, - Word16 *FEC_hi + Word16 *optimum_offset, //Q0 + Word16 *FEC_hi //Q0 ); #ifdef SUPPORT_JBM_TRACEFILE diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index d59ddcfc4808ec981334870a65b6a8d5f67d1992..9d1fb571c731311a5e3889bb0a0f3e7ee9cdd4b0 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -295,7 +295,7 @@ static void init_decoder_config( hDecoderConfig->Opt_RendConfigCustom = 0; hDecoderConfig->orientation_tracking = IVAS_HEAD_ORIENT_TRK_NONE; hDecoderConfig->Opt_non_diegetic_pan = 0; - hDecoderConfig->non_diegetic_pan_gain_fx = 0; + hDecoderConfig->non_diegetic_pan_gain_fx = 0; // Q15 hDecoderConfig->Opt_tsm = 0; hDecoderConfig->Opt_delay_comp = 0; hDecoderConfig->Opt_ExternalOrientation = 0; @@ -418,7 +418,7 @@ ivas_error IVAS_DEC_Configure( const IVAS_HEAD_ORIENT_TRK_T orientation_tracking, /* i : head orientation tracking type */ const Word16 renderConfigEnabled, /* i : enable Renderer config. file for binaural output */ const Word16 Opt_non_diegetic_pan, /* i : diegetic or not */ - const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain */ + const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain Q15 */ const Word16 Opt_dpid_on, /* i : enable directivity pattern option */ const UWord16 acousticEnvironmentId, /* i : Acoustic environment ID */ const Word16 delayCompensationEnabled /* i : enable delay compensation */ @@ -489,7 +489,7 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig->Opt_HRTF_binary = hrtfReaderEnabled; hDecoderConfig->Opt_RendConfigCustom = renderConfigEnabled; hDecoderConfig->Opt_non_diegetic_pan = Opt_non_diegetic_pan; - hDecoderConfig->non_diegetic_pan_gain_fx = non_diegetic_pan_gain_fx; + hDecoderConfig->non_diegetic_pan_gain_fx = non_diegetic_pan_gain_fx; // Q15 hDecoderConfig->Opt_delay_comp = delayCompensationEnabled; hDecoderConfig->Opt_ExternalOrientation = enableExternalOrientation; hDecoderConfig->Opt_dpid_on = Opt_dpid_on; @@ -571,11 +571,11 @@ Word16 get_render_frame_size_ms( } ELSE IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) ) { - return shl( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ), 1 ); + return ( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ) << 1 ); } ELSE IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) ) { - return shl( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ), 2 ); + return ( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ) << 2 ); } return 0; } @@ -637,7 +637,7 @@ ivas_error IVAS_DEC_GetRenderFramesize( ivas_error IVAS_DEC_GetRenderFramesizeSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *render_framesize /* o : render framesize in samples */ + Word16 *render_framesize /* o : render framesize in samples Q0 */ ) { Word16 tmp; @@ -679,7 +679,7 @@ ivas_error IVAS_DEC_GetRenderFramesizeSamples( ivas_error IVAS_DEC_GetRenderFramesizeMs( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - UWord32 *render_framesize /* o : render framesize in samples */ + UWord32 *render_framesize /* o : render framesize in samples Q0 */ ) { test(); @@ -703,7 +703,7 @@ ivas_error IVAS_DEC_GetRenderFramesizeMs( ivas_error IVAS_DEC_GetReferencesUpdateFrequency( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *update_frequency /* o : update frequency */ + Word16 *update_frequency /* o : update frequency Q0 */ ) { test(); @@ -937,7 +937,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) && hIvasDec->hVoIP != NULL && hIvasDec->hVoIP->hCurrentDataUnit != NULL && - NE_16( (Word16) hIvasDec->hVoIP->hCurrentDataUnit->partial_frame, 0 ) ) + ( (Word16) hIvasDec->hVoIP->hCurrentDataUnit->partial_frame != 0 ) ) { DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0]; st->codec_mode = MODE2; @@ -969,7 +969,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( ivas_error IVAS_DEC_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 nSamplesAsked, /* i : number of samples wanted by the caller */ - Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */ Word16 *nOutSamples, /* o : number of samples per channel written to output buffer */ bool *needNewFrame /* o :indication that the decoder needs a new frame */ ) @@ -1090,37 +1090,37 @@ ivas_error IVAS_DEC_GetSamples( Word16 tmp_apaExecBuffer[APA_BUF]; IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { - for ( int i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { - tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q11 ) ); + tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q11 ) ); // Q0 } IF( apa_exec_fx( hIvasDec->hTimeScaler, tmp_apaExecBuffer, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, tmp_apaExecBuffer, &nTimeScalerOutSamples ) != 0 ) { return IVAS_ERR_UNKNOWN; } - for ( int i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { - hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q11 ); + hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q11 ); // Q11 } } ELSE { - for ( int i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { - tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q12 ) ); + tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q12 ) ); // Q(-1) } IF( apa_exec_ivas_fx( hIvasDec->hTimeScaler, tmp_apaExecBuffer, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, tmp_apaExecBuffer, &nTimeScalerOutSamples ) != 0 ) { return IVAS_ERR_UNKNOWN; } - for ( int i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { - hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q12 ); + hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q12 ); // Q11 } } assert( LE_32( (Word32) nTimeScalerOutSamples, APA_BUF ) ); - nSamplesTcsScaled = idiv1616( extract_l( nTimeScalerOutSamples ), nTransportChannels ); + nSamplesTcsScaled = idiv1616U( extract_l( nTimeScalerOutSamples ), nTransportChannels ); } ELSE { @@ -1189,7 +1189,7 @@ static ivas_error IVAS_DEC_Setup( UWord8 *nTransportChannels, /* o : number of decoded transport PCM channels */ UWord8 *nOutChannels, /* o : number of decoded out channels (PCM or CLDFB) */ UWord16 *nSamplesRendered, /* o : number of samples flushed from the last frame */ - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal Q0 */ ) { ivas_error error; @@ -1258,7 +1258,7 @@ static ivas_error IVAS_DEC_Setup( test(); test(); test(); - IF( is_DTXrate( ivas_total_brate ) == 0 && st_ivas->ivas_format == MASA_ISM_FORMAT && GT_16( st_ivas->ini_frame, 0 ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) && st_ivas->ini_active_frame == 0 ) + IF( is_DTXrate( ivas_total_brate ) == 0 && EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && GT_16( st_ivas->ini_frame, 0 ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) && st_ivas->ini_active_frame == 0 ) { IF( st_ivas->hSpar ) { @@ -1317,7 +1317,7 @@ static ivas_error IVAS_DEC_Setup( test(); test(); test(); - IF( is_DTXrate( ivas_total_brate ) == 0 && st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ini_frame > 0 && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) && st_ivas->ini_active_frame == 0 ) + IF( is_DTXrate( ivas_total_brate ) == 0 && EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && st_ivas->ini_frame > 0 && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) && st_ivas->ini_active_frame == 0 ) { IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { @@ -1363,7 +1363,7 @@ static ivas_error IVAS_DEC_Setup( static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word32 *pcmBuf_fx, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word32 *pcmBuf_fx, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q11 */ Word16 *nOutSamples /* o : number of samples per channel written to output buffer */ ) { @@ -1403,7 +1403,7 @@ static ivas_error IVAS_DEC_GetTcSamples( FOR( n = 0; n < ivas_get_nchan_buffers_dec_ivas_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ ) { set32_fx( st_ivas->p_output_fx[n], 0, L_FRAME48k ); - st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; + st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; // Q11 } } @@ -1463,13 +1463,13 @@ static ivas_error IVAS_DEC_GetTcSamples( /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ IF( sts[n]->cldfbAna != NULL ) { - scale_sig32( sts[n]->cldfbAna->cldfb_state_fx, sts[n]->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); + scale_sig32( sts[n]->cldfbAna->cldfb_state_fx, sts[n]->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); // Q11 sts[n]->cldfbAna->Q_cldfb_state = Q11; move16(); } IF( sts[n]->cldfbSyn != NULL ) { - scale_sig32( sts[n]->cldfbSyn->cldfb_state_fx, sts[n]->cldfbSyn->cldfb_size, sub( Q11, Q4 ) ); + scale_sig32( sts[n]->cldfbSyn->cldfb_state_fx, sts[n]->cldfbSyn->cldfb_size, sub( Q11, Q4 ) ); // Q11 sts[n]->cldfbSyn->Q_cldfb_state = Q11; move16(); } @@ -1498,7 +1498,7 @@ static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 nSamplesForRendering, /* i : number of TC samples wanted from the renderer */ Word16 *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call */ - Word32 *pcmBuf /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word32 *pcmBuf /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q11*/ ) { Decoder_Struct *st_ivas; @@ -1529,7 +1529,8 @@ static ivas_error IVAS_DEC_GetRenderedSamples( const UWord16 nSamplesForRendering, /* i : number of TC samples wanted from the renderer */ UWord16 *nSamplesRendered, /* o : number of samples rendered */ UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the renerer pipeline */ - Word16 *pcmBuf ) + Word16 *pcmBuf // Q0 +) { Decoder_Struct *st_ivas; ivas_error error; @@ -1768,23 +1769,23 @@ ivas_error IVAS_DEC_GetObjectMetadata( IF( hIsmMeta == NULL || zero_flag ) { - metadata->azimuth_fx = 0; - metadata->elevation_fx = 0; - metadata->radius_fx = 512; - metadata->yaw_fx = 0; - metadata->pitch_fx = 0; - metadata->spread_fx = 0; - metadata->gainFactor_fx = ONE_IN_Q31; + metadata->azimuth_fx = 0; // Q22 + metadata->elevation_fx = 0; // Q22 + metadata->radius_fx = 512; // Q9 + metadata->yaw_fx = 0; // Q22 + metadata->pitch_fx = 0; // Q22 + metadata->spread_fx = 0; // Q22 + metadata->gainFactor_fx = ONE_IN_Q31; // Q31 metadata->non_diegetic_flag = 0; } ELSE { - metadata->azimuth_fx = hIsmMeta->azimuth_fx; - metadata->elevation_fx = hIsmMeta->elevation_fx; - metadata->radius_fx = hIsmMeta->radius_fx; - metadata->yaw_fx = hIsmMeta->yaw_fx; - metadata->pitch_fx = hIsmMeta->pitch_fx; - metadata->spread_fx = 0; + metadata->azimuth_fx = hIsmMeta->azimuth_fx; // Q22 + metadata->elevation_fx = hIsmMeta->elevation_fx; // Q22 + metadata->radius_fx = hIsmMeta->radius_fx; // Q9 + metadata->yaw_fx = hIsmMeta->yaw_fx; // Q22 + metadata->pitch_fx = hIsmMeta->pitch_fx; // Q22 + metadata->spread_fx = 0; // Q22 metadata->gainFactor_fx = ONE_IN_Q31; metadata->non_diegetic_flag = hIsmMeta->non_diegetic_flag; } @@ -1940,18 +1941,18 @@ ivas_error IVAS_DEC_FeedHeadTrackData( Word32 updateRate_fx = 1677721600; // value is 200 in Q23 move32(); - orientation.w_fx = L_shl( orientation.w_fx, sub( Q29, orientation.q_fact ) ); - orientation.x_fx = L_shl( orientation.x_fx, sub( Q29, orientation.q_fact ) ); - orientation.y_fx = L_shl( orientation.y_fx, sub( Q29, orientation.q_fact ) ); - orientation.z_fx = L_shl( orientation.z_fx, sub( Q29, orientation.q_fact ) ); - hHeadTrackData->OrientationTracker->refRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); - hHeadTrackData->OrientationTracker->refRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); - hHeadTrackData->OrientationTracker->refRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); - hHeadTrackData->OrientationTracker->refRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); - hHeadTrackData->OrientationTracker->absAvgRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); - hHeadTrackData->OrientationTracker->absAvgRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); - hHeadTrackData->OrientationTracker->absAvgRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); - hHeadTrackData->OrientationTracker->absAvgRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); + orientation.w_fx = L_shl( orientation.w_fx, sub( Q29, orientation.q_fact ) ); // Q29 + orientation.x_fx = L_shl( orientation.x_fx, sub( Q29, orientation.q_fact ) ); // Q29 + orientation.y_fx = L_shl( orientation.y_fx, sub( Q29, orientation.q_fact ) ); // Q29 + orientation.z_fx = L_shl( orientation.z_fx, sub( Q29, orientation.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->refRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->refRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->refRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->refRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->absAvgRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->absAvgRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->absAvgRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->absAvgRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29 orientation.q_fact = Q29; hHeadTrackData->OrientationTracker->refRot.q_fact = Q29; @@ -2004,10 +2005,10 @@ ivas_error IVAS_DEC_FeedRefRotData( pOtr = hIvasDec->st_ivas->hHeadTrackData->OrientationTracker; - pOtr->refRot.w_fx = rotation.w_fx; - pOtr->refRot.x_fx = rotation.x_fx; - pOtr->refRot.z_fx = rotation.z_fx; - pOtr->refRot.y_fx = rotation.y_fx; + pOtr->refRot.w_fx = rotation.w_fx; // rotation.q_fact + pOtr->refRot.x_fx = rotation.x_fx; // rotation.q_fact + pOtr->refRot.z_fx = rotation.z_fx; // rotation.q_fact + pOtr->refRot.y_fx = rotation.y_fx; // rotation.q_fact pOtr->refRot.q_fact = rotation.q_fact; move32(); @@ -2140,15 +2141,16 @@ ivas_error IVAS_DEC_FeedCustomLsData( hLsSetupCustom->num_spk = hLsCustomData.num_spk; move16(); - Copy32( hLsCustomData.azimuth_fx, hLsSetupCustom->ls_azimuth_fx, hLsCustomData.num_spk ); - Copy32( hLsCustomData.elevation_fx, hLsSetupCustom->ls_elevation_fx, hLsCustomData.num_spk ); + Copy32( hLsCustomData.azimuth_fx, hLsSetupCustom->ls_azimuth_fx, hLsCustomData.num_spk ); // Q22 + Copy32( hLsCustomData.elevation_fx, hLsSetupCustom->ls_elevation_fx, hLsCustomData.num_spk ); // Q22 /* Set planar flag */ is_planar = 1; move16(); FOR( i = 0; i < hLsCustomData.num_spk; i++ ) { - IF( is_planar && hLsSetupCustom->ls_elevation_fx[i] != 0 ) + test(); + if ( is_planar && hLsSetupCustom->ls_elevation_fx[i] != 0 ) { is_planar = 0; move16(); @@ -2282,9 +2284,9 @@ static ivas_error copyRendererConfigStruct( hRCout->roomAcoustics.acousticPreDelay_fx = hRCin->roomAcoustics.acousticPreDelay_fx; hRCout->roomAcoustics.inputPreDelay_fx = hRCin->roomAcoustics.inputPreDelay_fx; - Copy32( hRCin->roomAcoustics.pFc_input_fx, hRCout->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); - Copy32( hRCin->roomAcoustics.pAcoustic_rt60_fx, hRCout->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); - Copy32( hRCin->roomAcoustics.pAcoustic_dsr_fx, hRCout->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); + Copy32( hRCin->roomAcoustics.pFc_input_fx, hRCout->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); // Q16 + Copy32( hRCin->roomAcoustics.pAcoustic_rt60_fx, hRCout->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26 + Copy32( hRCin->roomAcoustics.pAcoustic_dsr_fx, hRCout->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); // Q30 Copy( hRCin->directivity_fx, hRCout->directivity_fx, 3 * MAX_NUM_OBJECTS ); hRCout->roomAcoustics.use_er = hRCin->roomAcoustics.use_er; hRCout->roomAcoustics.lowComplexity = hRCin->roomAcoustics.lowComplexity; @@ -2382,9 +2384,9 @@ ivas_error IVAS_DEC_FeedRenderConfig( move32(); } - Copy32( renderConfig.roomAcoustics.pFc_input_fx, hRenderConfig->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); - Copy32( renderConfig.roomAcoustics.pAcoustic_rt60_fx, hRenderConfig->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); - Copy32( renderConfig.roomAcoustics.pAcoustic_dsr_fx, hRenderConfig->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); + Copy32( renderConfig.roomAcoustics.pFc_input_fx, hRenderConfig->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); // Q16 + Copy32( renderConfig.roomAcoustics.pAcoustic_rt60_fx, hRenderConfig->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26 + Copy32( renderConfig.roomAcoustics.pAcoustic_dsr_fx, hRenderConfig->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); // Q30 Copy( renderConfig.directivity_fx, hRenderConfig->directivity_fx, 3 * MAX_NUM_OBJECTS ); @@ -2444,7 +2446,7 @@ ivas_error IVAS_DEC_GetDelay( nSamples[1] = NS2SA_FX2( hDecoderConfig->output_Fs, get_delay_fx( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0] ) ); move16(); - nSamples[2] = (Word16) W_round64_L( W_mult0_32_32( L_shl( st_ivas->binaural_latency_ns, 1 ), out_fs_fx ) ); + nSamples[2] = extract_l( W_round64_L( W_mult0_32_32( L_shl( st_ivas->binaural_latency_ns, 1 ), out_fs_fx ) ) ); move16(); nSamples[0] = add( nSamples[1], nSamples[2] ); move16(); @@ -2496,7 +2498,7 @@ ivas_error IVAS_DEC_HasDecodedFirstGoodFrame( ivas_error IVAS_DEC_GetPcmFrameSize( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word32 *pcmFrameSize /* o : total size of the PCM output frame. This takes into account the number of output channels */ + Word32 *pcmFrameSize /* o : total size of the PCM output frame. This takes into account the number of output channels Q0 */ ) { test(); @@ -2572,7 +2574,7 @@ static void bsCompactToSerial( const UWord8 *compact, UWord16 *serial, UWord16 n /* Add 4 padding bytes required by core coder */ FOR( i = 0; i < 4 * 8; ++i ) { - serial[L_add( num_bits, (Word32) i )] = 0; + serial[( num_bits + i )] = 0; move16(); } #undef WMC_TOOL_SKIP @@ -2696,7 +2698,7 @@ ivas_error IVAS_DEC_VoIP_SetScale( error = IVAS_ERR_OK; move32(); - IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm, false ) ) + IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm == false ) { return IVAS_ERR_TSM_NOT_ENABLED; } @@ -2719,7 +2721,7 @@ ivas_error IVAS_DEC_VoIP_SetScale( ivas_error IVAS_DEC_TSM_SetQuality( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const Word16 quality /* i : target TSM quality */ + const Word16 quality /* i : target TSM quality Q14 */ ) { ivas_error error; @@ -2727,13 +2729,14 @@ ivas_error IVAS_DEC_TSM_SetQuality( error = IVAS_ERR_OK; move32(); - IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm, false ) ) + IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm == false ) { return IVAS_ERR_TSM_NOT_ENABLED; } ELSE { - hIvasDec->tsm_quality = quality; + hIvasDec->tsm_quality = quality; // Q14 + move16(); } return error; @@ -2749,7 +2752,7 @@ ivas_error IVAS_DEC_TSM_SetQuality( ivas_error IVAS_DEC_VoIP_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ UWord16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ - Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */ const UWord32 systemTimestamp_ms /* i : current system timestamp */ #ifdef SUPPORT_JBM_TRACEFILE , @@ -2804,7 +2807,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( extBufferedSamples = add( nSamplesRendered, nSamplesBuffered ); Word16 exp; extBufferedTime_ms = BASOP_Util_Divide3232_Scale( imult3216( extBufferedSamples, 1000 ), hDecoderConfig->output_Fs, &exp ); - extBufferedTime_ms = (UWord32) W_shr( extBufferedTime_ms, 15 - exp ); + extBufferedTime_ms = (UWord32) W_shr( extBufferedTime_ms, sub( 15, exp ) ); // Q0 dataUnit = NULL; /* pop one access unit from the jitter buffer */ @@ -2959,7 +2962,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( ivas_error IVAS_DEC_Flush( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ - Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */ Word16 *nSamplesFlushed /* o : number of samples flushed */ ) { @@ -3462,8 +3465,9 @@ void IVAS_DEC_PrintDisclaimer( void ) static ivas_error evs_dec_main_fx( Decoder_Struct *st_ivas, const Word16 nOutSamples, - Word32 *Buf_fx, - Word16 *pcmBuf ) + Word32 *Buf_fx, // Q11 + Word16 *pcmBuf // Q0 +) { DEC_CORE_HANDLE *hCoreCoder; Word16 mixer_left_fx, mixer_right_fx; @@ -3477,13 +3481,13 @@ static ivas_error evs_dec_main_fx( hCoreCoder[0]->total_num_bits = st_ivas->num_bits; move16(); move32(); - hCoreCoder[0]->output_frame_fx = extract_l( Mult_32_16( hCoreCoder[0]->output_Fs, 0x0290 ) ); + hCoreCoder[0]->output_frame_fx = extract_l( Mult_32_16( hCoreCoder[0]->output_Fs, 0x0290 /*Q0*/ ) ); // Q0 move16(); mdct_switching_dec( hCoreCoder[0] ); FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; ch++ ) { - p_output_fx[ch] = st_ivas->p_output_fx[ch]; + p_output_fx[ch] = st_ivas->p_output_fx[ch]; // Q0 } /* run the main EVS decoding routine */ @@ -3538,7 +3542,7 @@ static ivas_error evs_dec_main_fx( move16(); IF( EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) { - mixer_left_fx = add( shr( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, Q1 ), ONE_IN_Q14 ); + mixer_left_fx = add( shr( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, Q1 ), ONE_IN_Q14 ); // Q14 mixer_right_fx = sub( MAX16B, mixer_left_fx ); v_multc_fixed_16( p_output_fx[0], mixer_right_fx, p_output_fx[1], nOutSamples ); /* Q11 */ @@ -3706,12 +3710,20 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( } } +#ifdef FIX_930_JBM_BUFSIZE_MULT + IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * L_mult0( apa_buffer_size, (Word16) nTransportChannels ) ) ) == NULL ) +#else IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * imult1616( apa_buffer_size, (Word16) nTransportChannels ) ) ) == NULL ) +#endif { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); } +#ifdef FIX_930_JBM_BUFSIZE_MULT + set_zero2_fx( hIvasDec->apaExecBuffer_fx, L_mult0( apa_buffer_size, (Word16) nTransportChannels ) ); +#else set_zero_fx( hIvasDec->apaExecBuffer_fx, imult1616( apa_buffer_size, (Word16) nTransportChannels ) ); +#endif } } ELSE @@ -3733,11 +3745,19 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( set_zero( hIvasDec->apaExecBuffer, apa_buffer_size * nTransportChannels ); #else free( hIvasDec->apaExecBuffer_fx ); +#ifdef FIX_930_JBM_BUFSIZE_MULT + IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * L_mult0( apa_buffer_size, (Word16) nTransportChannels ) ) ) == NULL ) +#else IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * imult1616( apa_buffer_size, (Word16) nTransportChannels ) ) ) == NULL ) +#endif { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); } +#ifdef FIX_930_JBM_BUFSIZE_MULT + set_zero2_fx( hIvasDec->apaExecBuffer_fx, L_mult0( apa_buffer_size, (Word16) nTransportChannels ) ); +#else set_zero_fx( hIvasDec->apaExecBuffer_fx, imult1616( apa_buffer_size, (Word16) nTransportChannels ) ); +#endif #endif } /* realloc apa_exe_buffer */ diff --git a/lib_dec/lp_exc_d_fx.c b/lib_dec/lp_exc_d_fx.c index e0bcb2c609e4b5d5d936e2b237c43a6370eba472..cb94c47f7c6da95863e461c46d82ea62ed3bc4a0 100644 --- a/lib_dec/lp_exc_d_fx.c +++ b/lib_dec/lp_exc_d_fx.c @@ -57,7 +57,7 @@ void lp_filt_exc_dec_fx( lp_flag = (Word16) get_next_indice_fx( st_fx, 1 ); } } - IF( EQ_16( lp_flag, LOW_PASS ) ) + IF( lp_flag == LOW_PASS ) { /* pointer positioning to avoid doing it inside the loop */ test(); @@ -76,9 +76,9 @@ void lp_filt_exc_dec_fx( FOR( i = 0; i < L_subfr; i++ ) { - L_tmp = L_mult( fac_n, exc[add( sub( i, 1 ), i_subfr )] ); - L_tmp = L_mac( L_tmp, fac_m, exc[add( i /*+ 0 */, i_subfr )] ); - code[i] = mac_r( L_tmp, fac_n, exc[add( add( i, 1 ), i_subfr )] ); + L_tmp = L_mult( fac_n, exc[( ( i - 1 ) + i_subfr )] ); + L_tmp = L_mac( L_tmp, fac_m, exc[( i /*+ 0 */ + i_subfr )] ); + code[i] = mac_r( L_tmp, fac_n, exc[( ( i + 1 ) + i_subfr )] ); move16(); } diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index 5d7313b21e8021ccb69c35273b0c3198c1178585..a81e22f2580dc9fe84fd72eb2775cae3095c0f64 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -29,32 +29,32 @@ static void dqlsf_CNG_fx( Decoder_State *st_fx, Word16 *lsf_q ); ----------------------------------------------------------------------------------------*/ static void dqlsf_CNG_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *lsf_q /* o : decoded LSFs */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *lsf_q /* o : decoded LSFs Q9*/ ) { Word16 indice[4]; Word16 ber_flag; - indice[0] = (Word16) get_next_indice_fx( st_fx, 4 ); + indice[0] = (Word16) get_next_indice_fx( st_fx, 4 ); /* Q0 */ move16(); - indice[1] = (Word16) get_next_indice_fx( st_fx, LEN_INDICE ); + indice[1] = (Word16) get_next_indice_fx( st_fx, LEN_INDICE ); /* Q0 */ move16(); - indice[2] = (Word16) get_next_indice_fx( st_fx, LSF_BITS_CNG - 4 - LEN_INDICE ); + indice[2] = (Word16) get_next_indice_fx( st_fx, LSF_BITS_CNG - 4 - LEN_INDICE ); /* Q0 */ move16(); /* deindex_lvq_cng decoder does not need to know the sampling rate, the sampling rate data is embedded inside the LSF coefficients */ IF( st_fx->element_mode == EVS_MONO ) { ber_flag = - deindex_lvq_cng_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4, &st_fx->offset_scale1_fx[0][0], &st_fx->offset_scale2_fx[0][0], &st_fx->no_scales_fx[0][0] ); + deindex_lvq_cng_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4, &st_fx->offset_scale1_fx[0][0], &st_fx->offset_scale2_fx[0][0], &st_fx->no_scales_fx[0][0] ); /* Q0 */ } ELSE { ber_flag = - deindex_lvq_cng_ivas_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4 ); + deindex_lvq_cng_ivas_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4 ); /* Q0 */ } - st_fx->BER_detect = s_or( ber_flag, st_fx->BER_detect ); + st_fx->BER_detect = s_or( ber_flag, st_fx->BER_detect ); /* Q0 */ move16(); /* The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF coefficient (last coefficient). @@ -67,7 +67,7 @@ static void dqlsf_CNG_fx( test(); IF( ( ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) && ( LE_16( lsf_q[M - 1], WB_LIMIT_LSF_FX ) ) ) || ( ( LT_16( st_fx->L_frame, L_FRAME16k ) ) && ( GT_16( lsf_q[M - 1], WB_LIMIT_LSF_FX ) ) ) ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } @@ -102,17 +102,17 @@ static void dqlsf_CNG_fx( /* _ None */ /*===========================================================================*/ void lsf_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *lsf_new, /* o : de-quantized LSF vector */ - Word16 *lsp_new, /* o : de-quantized LSP vector */ - Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector */ - const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag */ + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 tc_subfr, /* i : TC subframe index Q0*/ + Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ + Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ + const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ #endif ) { @@ -132,13 +132,13 @@ void lsf_dec_fx( coder_type = st_fx->coder_type; if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) { - coder_type = INACTIVE; + coder_type = INACTIVE; /* Q0 */ move16(); } test(); if ( EQ_16( coder_type, AUDIO ) && st_fx->GSC_IVAS_mode > 0 ) { - coder_type = GENERIC; + coder_type = GENERIC; /* Q0 */ move16(); } no_param_lpc = 0; @@ -149,7 +149,7 @@ void lsf_dec_fx( /* Find the number of bits for LSF quantization */ IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { - nBits = LSF_BITS_CNG; + nBits = LSF_BITS_CNG; /* Q0 */ move16(); } ELSE @@ -157,25 +157,25 @@ void lsf_dec_fx( test(); IF( st_fx->nelp_mode_dec == 0 && st_fx->ppp_mode_dec == 0 ) { - nBits = st_fx->acelp_cfg.lsf_bits; + nBits = st_fx->acelp_cfg.lsf_bits; /* Q0 */ move16(); } ELSE IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { IF( EQ_16( coder_type, UNVOICED ) ) { - nBits = 30; + nBits = 30; /* Q0 */ move16(); if ( st_fx->bwidth == NB ) { - nBits = 32; + nBits = 32; /* Q0 */ move16(); } } } ELSE IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) { - nBits = 26; + nBits = 26; /* Q0 */ move16(); } } @@ -197,10 +197,10 @@ void lsf_dec_fx( { st_fx->seed_acelp = 0; move16(); - FOR( i = sub( no_param_lpc, 1 ); i >= 0; i-- ) + FOR( i = no_param_lpc - 1; i >= 0; i-- ) { /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ - st_fx->seed_acelp = extract_l( L_add( imult3216( 31821L, add( shr( ( st_fx->seed_acelp ), 1 ), param_lpc[i] ) ), 13849L ) ); + st_fx->seed_acelp = extract_l( L_add( imult3216( 31821L /* Q0 */, add( shr( ( st_fx->seed_acelp ), 1 ), param_lpc[i] ) ), 13849L /* Q0 */ ) ); /* Q0 */ move16(); // PMTE() /*IVAS_CODE to be completed */ } @@ -240,7 +240,7 @@ void lsf_dec_fx( FOR( i = 1; i < M; i++ ) { - st_fx->lsf_old_fx[i] = add( st_fx->lsf_old_fx[i - 1], lsf_diff ); + st_fx->lsf_old_fx[i] = add( st_fx->lsf_old_fx[i - 1], lsf_diff ); /* Q2.56 */ move16(); } lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, st_fx->sr_core ); @@ -252,8 +252,8 @@ void lsf_dec_fx( IF( st_fx->rate_switching_reset ) { /*extrapolation in case of unstable LSF convert*/ - Copy( lsp_new, st_fx->lsp_old_fx, M ); - Copy( lsf_new, st_fx->lsf_old_fx, M ); + Copy( lsp_new, st_fx->lsp_old_fx, M ); /* Q15 */ + Copy( lsf_new, st_fx->lsf_old_fx, M ); /* Q2.56 */ } { /* Mid-frame LSF decoding */ @@ -267,10 +267,10 @@ void lsf_dec_fx( { /* check, if LSP interpolation can be relaxed */ E_LPC_f_lsp_a_conversion( st_fx->lsp_old_fx, tmp_old, M ); - enr_old = Enr_1_Az_fx( tmp_old, 2 * L_SUBFR ); + enr_old = Enr_1_Az_fx( tmp_old, 2 * L_SUBFR ); /* Q3 */ E_LPC_f_lsp_a_conversion( lsp_new, tmp_new, M ); - enr_new = Enr_1_Az_fx( tmp_new, 2 * L_SUBFR ); + enr_new = Enr_1_Az_fx( tmp_new, 2 * L_SUBFR ); /* Q3 */ IF( LT_16( enr_new, mult_r( 9830 /*0.3 Q15*/, enr_old ) ) ) { @@ -293,8 +293,8 @@ void lsf_dec_fx( IF( EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->core == ACELP_CORE ) { /* update old LSPs/LSFs in case of HQ->ACELP core switching */ - Copy( lsp_mid, st_fx->lsp_old_fx, M ); - lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); + Copy( lsp_mid, st_fx->lsp_old_fx, M ); /* Q15 */ + lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */ } test(); IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( coder_type, UNVOICED ) ) @@ -302,9 +302,9 @@ void lsf_dec_fx( // PMT("To be verified") IF( EQ_16( st_fx->active_cnt, 1 ) ) { - Copy( lsp_mid, st_fx->lsp_old_fx, M ); - lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); - Copy( lsp_new, lsp_mid, M ); + Copy( lsp_mid, st_fx->lsp_old_fx, M ); /* Q15 */ + lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */ + Copy( lsp_new, lsp_mid, M ); /* Q15 */ } /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ @@ -326,7 +326,7 @@ void lsf_dec_fx( } ELSE { - st_fx->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); + st_fx->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); /* Q15 */ move16(); } @@ -369,18 +369,18 @@ void lsf_dec_fx( /*========================================================================*/ void lsf_end_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 mode2_flag, - const Word16 coder_type_org, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 nBits_in, /* i : number of bits used for ISF quantization*/ - Word16 *qlsf, /* o : quantized LSFs in the cosine domain */ - Word16 *lpc_param, /* i : LPC parameters */ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *nb_indices /* o : number of indices */ + Decoder_State *st, /* i/o: decoder state structure */ + Word16 mode2_flag, /* Q0 */ + const Word16 coder_type_org, /* i : coding type Q0*/ + const Word16 bwidth, /* i : input signal bandwidth Q0*/ + const Word16 nBits_in, /* i : number of bits used for ISF quantization Q0*/ + Word16 *qlsf, /* o : quantized LSFs in the cosine domain Qx2.56*/ + Word16 *lpc_param, /* i : LPC parameters Q0*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *nb_indices /* o : number of indices Q0*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ #endif ) { @@ -409,9 +409,9 @@ void lsf_end_dec_fx( #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE Word16 pred3[M]; #endif - flag_1bit_gran = (Word16) GT_16( st->element_mode, EVS_MONO ); + flag_1bit_gran = (Word16) ( st->element_mode > EVS_MONO ); /* Q0 */ - nBits = nBits_in; + nBits = nBits_in; /* Q0 */ *nb_indices = 0; move16(); move16(); @@ -427,18 +427,18 @@ void lsf_end_dec_fx( #endif { /* this bit is used only for primary channel or mono */ - coder_type = (Word16) get_next_indice_fx( st, 1 ); - coder_type = add( coder_type, 2 ); + coder_type = (Word16) get_next_indice_fx( st, 1 ); /* Q0 */ + coder_type = add( coder_type, 2 ); /* Q0 */ test(); test(); if ( EQ_16( coder_type, GENERIC ) || ( EQ_16( coder_type, VOICED ) && EQ_16( flag_1bit_gran, 1 ) ) ) { - nBits = sub( nBits, 1 ); + nBits = sub( nBits, 1 ); /* Q0 */ } } ELSE { - coder_type = coder_type_org; + coder_type = coder_type_org; /* Q0 */ move16(); } @@ -475,16 +475,16 @@ void lsf_end_dec_fx( { /* if secondary channel predmode is set to be > 2 */ /*predmode += 3;*/ - predmode = add( predmode, 3 ); + predmode = add( predmode, 3 ); /* Q0 */ } #endif - p_lpc_param = lpc_param; + p_lpc_param = lpc_param; /* Q0 */ move16(); IF( predmode == 0 ) { - safety_net = 1; + safety_net = 1; /* Q0 */ move16(); } ELSE IF( predmode == 1 ) @@ -499,18 +499,18 @@ void lsf_end_dec_fx( IF( EQ_16( mode2_flag, 1 ) || EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) { /* read from param_lpc */ - safety_net = p_lpc_param[0]; + safety_net = p_lpc_param[0]; /* Q0 */ move16(); p_lpc_param++; - *nb_indices = add( *nb_indices, 1 ); + *nb_indices = add( *nb_indices, 1 ); /* Q0 */ } ELSE { - safety_net = (Word16) get_next_indice_fx( st, 1 ); + safety_net = (Word16) get_next_indice_fx( st, 1 ); /* Q0 */ } } - st->safety_net = safety_net; + st->safety_net = safety_net; /* Q0 */ move16(); /*--------------------------------------------------------------------------* @@ -523,9 +523,9 @@ void lsf_end_dec_fx( { /* use same AR prediction bit allocation for intra and inter modes*/ lsf_allocate_fx( sub( nBits, 1 ), mode_lvq, 9, &stages0, &stages1, levels0, levels1, bits0, bits1 ); - stages0 = stages1; - Copy( levels1, levels0, stages0 ); - Copy( bits1, bits0, stages0 ); + stages0 = stages1; /* Q0 */ + Copy( levels1, levels0, stages0 ); /* Q0 */ + Copy( bits1, bits0, stages0 ); /* Q0 */ } #endif @@ -538,24 +538,24 @@ void lsf_end_dec_fx( test(); IF( EQ_16( st->codec_mode, MODE2 ) || EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) { - *nb_indices = 10; + *nb_indices = 10; /* Q0 */ move16(); - TCQIdx[0] = safety_net; + TCQIdx[0] = safety_net; /* Q0 */ move16(); FOR( i = 1; i < *nb_indices; i++ ) { - TCQIdx[i] = *p_lpc_param++; + TCQIdx[i] = *p_lpc_param++; /* Q0 */ move16(); } } ELSE { - Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; - TCQIdx[0] = safety_net; + Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; /* Q0 */ + TCQIdx[0] = safety_net; /* Q0 */ move16(); FOR( i = 0; i < M / 2 + 3; i++ ) { - TCQIdx[i + 1] = get_next_indice_fx( st, Bit_alloc1[i] ); + TCQIdx[i + 1] = get_next_indice_fx( st, Bit_alloc1[i] ); /* Q0 */ move16(); } } @@ -564,20 +564,20 @@ void lsf_end_dec_fx( { IF( safety_net ) { - stages = stages0; + stages = stages0; /* Q0 */ move16(); - levels = levels0; + levels = levels0; /* Q0 */ move16(); - bits = bits0; + bits = bits0; /* Q0 */ move16(); } ELSE { - stages = stages1; + stages = stages1; /* Q0 */ move16(); - levels = levels1; + levels = levels1; /* Q0 */ move16(); - bits = bits1; + bits = bits1; /* Q0 */ move16(); } test(); @@ -586,19 +586,19 @@ void lsf_end_dec_fx( { FOR( i = 0; i < sub( stages, 1 ); i++ ) { - num_bits = bits[i]; + num_bits = bits[i]; /* Q0 */ move16(); - lindice[i + 1] = *p_lpc_param++; + lindice[i + 1] = *p_lpc_param++; /* Q0 */ move16(); } - cumleft = levels[stages - 1]; + cumleft = levels[stages - 1]; /* Q0 */ move16(); WHILE( cumleft > 0 ) { IF( GT_16( cumleft, LEN_INDICE ) ) { - cumleft = sub( cumleft, LEN_INDICE ); + cumleft = sub( cumleft, LEN_INDICE ); /* Q0 */ } ELSE { @@ -606,43 +606,43 @@ void lsf_end_dec_fx( move16(); } - lindice[i + 1] = *p_lpc_param++; + lindice[i + 1] = *p_lpc_param++; /* Q0 */ move16(); - i = add( i, 1 ); + i++; } - *nb_indices = add( *nb_indices, i ); + *nb_indices = add( *nb_indices, i ); /* Q0 */ move16(); } ELSE { FOR( i = 0; i < stages - 1; i++ ) { - num_bits = bits[i]; + num_bits = bits[i]; /* Q0 */ move16(); - lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); + lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); /* Q0 */ move16(); } - cumleft = levels[sub( stages, 1 )]; + cumleft = levels[stages - 1]; /* Q0 */ WHILE( cumleft > 0 ) { IF( GT_16( cumleft, LEN_INDICE ) ) { - cumleft = sub( cumleft, LEN_INDICE ); - num_bits = LEN_INDICE; + cumleft = sub( cumleft, LEN_INDICE ); /* Q0 */ + num_bits = LEN_INDICE; /* Q0 */ move16(); } ELSE { - num_bits = (Word16) cumleft; + num_bits = (Word16) cumleft; /* Q0 */ move16(); cumleft = 0; move16(); } - lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); + lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); /* Q0 */ move16(); - i = add( i, 1 ); + i++; } } } @@ -650,7 +650,7 @@ void lsf_end_dec_fx( { FOR( i = 0; i < M; i++ ) { - st->mem_AR_fx[i] = ModeMeans_fx[mode_lvq][i]; + st->mem_AR_fx[i] = ModeMeans_fx[mode_lvq][i]; /* Q2.56 */ move16(); } st->reset_mem_AR = 0; @@ -661,7 +661,7 @@ void lsf_end_dec_fx( * De-quantize LSF vector *------------------------------------------------------------------------------------------*/ - *LSF_Q_prediction = SAFETY_NET; + *LSF_Q_prediction = SAFETY_NET; /* Q0 */ move16(); /* VOICED_WB@16kHz */ test(); @@ -669,14 +669,14 @@ void lsf_end_dec_fx( IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, VOICED ) && flag_1bit_gran == 0 ) { /* BC-TCVQ decoder */ - safety_net = qlsf_ARSN_tcvq_Dec_16k_fx( qlsf, TCQIdx, sub( nBits, 1 ) ); + safety_net = qlsf_ARSN_tcvq_Dec_16k_fx( qlsf, TCQIdx, sub( nBits, 1 ) ); /* Q0 */ /* Update mem_MA */ - Copy( qlsf, st->mem_MA_fx, M ); + Copy( qlsf, st->mem_MA_fx, M ); /* Q2.56 */ IF( safety_net ) { - Copy( ModeMeans_fx[mode_lvq], pred0, M ); + Copy( ModeMeans_fx[mode_lvq], pred0, M ); /* Q2.56 */ } ELSE { @@ -685,7 +685,7 @@ void lsf_end_dec_fx( pred0[i] = add( ModeMeans_fx[mode_lvq][i], mult( Predictors_fx[mode_lvq_p][i], ( sub( st->mem_AR_fx[i], ModeMeans_fx[mode_lvq][i] ) ) ) ); /* Q(x2.56)*/ move16(); } - *LSF_Q_prediction = AUTO_REGRESSIVE; + *LSF_Q_prediction = AUTO_REGRESSIVE; /* Q0 */ move16(); } Vr_add( qlsf, pred0, qlsf, M ); @@ -694,11 +694,11 @@ void lsf_end_dec_fx( { /* Safety-net */ - Copy( ModeMeans_fx[mode_lvq], pred0, M ); + Copy( ModeMeans_fx[mode_lvq], pred0, M ); /* Q2.56 */ /* for mem_MA update */ FOR( i = 0; i < M; i++ ) { - pred1[i] = add( pred0[i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); + pred1[i] = add( pred0[i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); /* Q2.56 */ move16(); } #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE @@ -719,7 +719,7 @@ void lsf_end_dec_fx( /* intra mode*/ st->BER_detect = s_or( st->BER_detect, - vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages0, M, 9, levels0[stages0 - 1] ) ); + vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages0, M, 9, levels0[stages0 - 1] ) ); /* Q0 */ move16(); Vr_add( qlsf, pred3, qlsf, M ); @@ -730,15 +730,15 @@ void lsf_end_dec_fx( { IF( st->element_mode != EVS_MONO ) { - ber_flag = vq_dec_lvq_ivas_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1] ); + ber_flag = vq_dec_lvq_ivas_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1] ); /* Q0 */ } ELSE { ber_flag = vq_dec_lvq_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1], &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); /* Q0 */ } - st->BER_detect = s_or( st->BER_detect, ber_flag ); + st->BER_detect = s_or( st->BER_detect, ber_flag ); /* Q0 */ move16(); Vr_add( qlsf, pred0, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); @@ -757,15 +757,15 @@ void lsf_end_dec_fx( #endif IF( st->element_mode != EVS_MONO ) { - ber_flag = vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); + ber_flag = vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); /* Q0 */ } ELSE { ber_flag = vq_dec_lvq_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1], &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); /* Q0 */ } - st->BER_detect = s_or( st->BER_detect, ber_flag ); + st->BER_detect = s_or( st->BER_detect, ber_flag ); /* Q0 */ move16(); #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE test(); @@ -774,9 +774,9 @@ void lsf_end_dec_fx( IF( EQ_16( predmode, 1 ) ) /* MA only */ #endif { - Copy( qlsf, st->mem_MA_fx, M ); - Vr_add( qlsf, pred1, qlsf, M ); - *LSF_Q_prediction = MOVING_AVERAGE; + Copy( qlsf, st->mem_MA_fx, M ); /* Q2.56 */ + Vr_add( qlsf, pred1, qlsf, M ); /* Q2.56 */ + *LSF_Q_prediction = MOVING_AVERAGE; /* Q0 */ move16(); } ELSE @@ -784,12 +784,12 @@ void lsf_end_dec_fx( /* AR */ FOR( i = 0; i < M; i++ ) { - pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); + pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); /* Q2.56 */ move16(); } Vr_add( qlsf, pred2, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); - *LSF_Q_prediction = AUTO_REGRESSIVE; + *LSF_Q_prediction = AUTO_REGRESSIVE; /* Q0 */ move16(); } } @@ -807,9 +807,9 @@ void lsf_end_dec_fx( /* Verify stability */ reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); /* Update predictor memory */ - Copy( qlsf, st->mem_AR_fx, M ); + Copy( qlsf, st->mem_AR_fx, M ); /* Q2.56 */ - st->mode_lvq = mode_lvq; + st->mode_lvq = mode_lvq; /* Q0 */ move16(); @@ -839,10 +839,10 @@ void lsf_end_dec_fx( /* _ None */ /*========================================================================*/ void lsf_mid_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 lsp_new[], /* i : quantized LSPs from frame endSQ15*/ - Word16 coder_type, /* i : Coder type */ - Word16 lsp_mid[] /* o : quantized LSPs Q15*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 lsp_new[], /* i : quantized LSPs from frame endS Q15*/ + Word16 coder_type, /* i : Coder type Q0*/ + Word16 lsp_mid[] /* o : quantized LSPs Q15*/ ) { Word16 j, idx; @@ -862,19 +862,19 @@ void lsf_mid_dec_fx( /* Codebook selection */ IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) { - nb_bits = 1; + nb_bits = 1; /* Q0 */ move16(); - ratio = &tbl_mid_voi_wb_1b_fx[0]; + ratio = &tbl_mid_voi_wb_1b_fx[0]; /* Q13 */ } ELSE IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { - nb_bits = 4; + nb_bits = 4; /* Q0 */ move16(); - ratio = &tbl_mid_unv_wb_4b_fx[0]; + ratio = &tbl_mid_unv_wb_4b_fx[0]; /* Q13 */ } ELSE { - nb_bits = st_fx->acelp_cfg.mid_lsf_bits; + nb_bits = st_fx->acelp_cfg.mid_lsf_bits; /* Q0 */ move16(); /* codebook selection */ @@ -885,24 +885,24 @@ void lsf_mid_dec_fx( { case 5: { - ratio = tbl_mid_voi_wb_5b_fx; + ratio = tbl_mid_voi_wb_5b_fx; /* Q13 */ BREAK; } case 4: { - ratio = tbl_mid_voi_wb_4b_fx; + ratio = tbl_mid_voi_wb_4b_fx; /* Q13 */ BREAK; } case 1: { - ratio = tbl_mid_voi_wb_1b_fx; + ratio = tbl_mid_voi_wb_1b_fx; /* Q13 */ break; } } } - ELSE IF( coder_type == UNVOICED ) + ELSE IF( EQ_16( coder_type, UNVOICED ) ) { - ratio = tbl_mid_unv_wb_5b_fx; + ratio = tbl_mid_unv_wb_5b_fx; /* Q13 */ } ELSE { @@ -911,17 +911,17 @@ void lsf_mid_dec_fx( { case 5: { - ratio = tbl_mid_gen_wb_5b_fx; + ratio = tbl_mid_gen_wb_5b_fx; /* Q13 */ BREAK; } case 4: { - ratio = tbl_mid_gen_wb_4b_fx; + ratio = tbl_mid_gen_wb_4b_fx; /* Q13 */ break; } case 2: { - ratio = tbl_mid_gen_wb_2b_fx; + ratio = tbl_mid_gen_wb_2b_fx; /* Q13 */ BREAK; } } @@ -929,7 +929,7 @@ void lsf_mid_dec_fx( } /* Retrieve mid-frame LSF index */ - idx = (Word16) get_next_indice_fx( st_fx, nb_bits ); + idx = (Word16) get_next_indice_fx( st_fx, nb_bits ); /* Q0 */ /* Calculation of mid-LSF vector */ FOR( j = 0; j < M; j++ ) @@ -947,7 +947,7 @@ void lsf_mid_dec_fx( { IF( LT_16( qlsf[j], qlsf[j - 1] ) ) { - bad_spacing = 1; + bad_spacing = 1; /* Q0 */ move16(); BREAK; } @@ -970,7 +970,7 @@ void lsf_mid_dec_fx( test(); IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) { - qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); /* Q2.56 */ move16(); } } @@ -984,7 +984,7 @@ void lsf_mid_dec_fx( test(); IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) { - qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); /* Q2.56 */ move16(); } } @@ -993,7 +993,7 @@ void lsf_mid_dec_fx( if ( st_fx->prev_bfi ) { /* continue redoing mid-LSF interpolation with 0.4 in order not to propagate the error */ - st_fx->mid_lsf_int = 1; + st_fx->mid_lsf_int = 1; /* Q0 */ move16(); } diff --git a/lib_dec/lsf_msvq_ma_dec_fx.c b/lib_dec/lsf_msvq_ma_dec_fx.c index 167f71d4d2ee096874aa572599816eac7b15332b..f57aee0e12caea0ae2b73f4408334d8d8b6f4975 100644 --- a/lib_dec/lsf_msvq_ma_dec_fx.c +++ b/lib_dec/lsf_msvq_ma_dec_fx.c @@ -26,7 +26,10 @@ * *---------------------------------------------------------------------*/ -Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) +Word16 lsf_msvq_ma_decprm( + Decoder_State *st, + Word16 *param_lpc /* Q0 */ +) { Word16 i, nbits_lpc, tmp; Word16 bits_midlpc; @@ -34,7 +37,7 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) levels0[MAX_VQ_STAGES], levels1[MAX_VQ_STAGES], *bits; Word16 predmode, mode_lvq, mode_lvq_p, safety_net; - bits_midlpc = 5; + bits_midlpc = 5; /* Q0 */ move16(); test(); @@ -63,54 +66,54 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) IF( EQ_16( predmode, 2 ) ) { /* there is choice between SN and AR prediction */ - safety_net = get_next_indice_fx( st, 1 ); + safety_net = get_next_indice_fx( st, 1 ); /* Q0 */ IF( EQ_16( safety_net, 1 ) ) { - stages = stages0; + stages = stages0; /* Q0 */ move16(); - bits = bits0; + bits = bits0; /* Q0 */ move16(); } ELSE { - stages = stages1; + stages = stages1; /* Q0 */ move16(); - bits = bits1; + bits = bits1; /* Q0 */ move16(); } - *param_lpc = safety_net; + *param_lpc = safety_net; /* Q0 */ move16(); param_lpc++; - nbits_lpc++; + nbits_lpc = add( nbits_lpc, 1 ); } ELSE { - stages = stages1; + stages = stages1; /* Q0 */ move16(); - bits = bits1; + bits = bits1; /* Q0 */ move16(); } - tmp = sub( stages, 1 ); + tmp = sub( stages, 1 ); /* Q0 */ FOR( i = 0; i < tmp; i++ ) { - *param_lpc = get_next_indice_fx( st, bits[i] ); + *param_lpc = get_next_indice_fx( st, bits[i] ); /* Q0 */ move16(); param_lpc++; - nbits_lpc = add( nbits_lpc, bits[i] ); + nbits_lpc = add( nbits_lpc, bits[i] ); /* Q0 */ } - *param_lpc = get_next_indice_fx( st, LEN_INDICE ); + *param_lpc = get_next_indice_fx( st, LEN_INDICE ); /* Q0 */ move16(); param_lpc++; - nbits_lpc = add( nbits_lpc, LEN_INDICE ); + nbits_lpc = add( nbits_lpc, LEN_INDICE ); /* Q0 */ - *param_lpc = get_next_indice_fx( st, sub( bits[i], LEN_INDICE ) ); + *param_lpc = get_next_indice_fx( st, sub( bits[i], LEN_INDICE ) ); /* Q0 */ move16(); param_lpc++; - nbits_lpc = add( nbits_lpc, sub( bits[i], LEN_INDICE ) ); + nbits_lpc = add( nbits_lpc, sub( bits[i], LEN_INDICE ) ); /* Q0 */ test(); @@ -118,9 +121,9 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) IF( NE_16( st->coder_type, VOICED ) && st->core == 0 && st->acelp_cfg.midLpc ) { - *param_lpc = get_next_indice_fx( st, bits_midlpc ); + *param_lpc = get_next_indice_fx( st, bits_midlpc ); /* Q0 */ move16(); - nbits_lpc = add( nbits_lpc, bits_midlpc ); + nbits_lpc = add( nbits_lpc, bits_midlpc ); /* Q0 */ } return nbits_lpc; @@ -129,15 +132,16 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) Word16 lsf_bctcvq_decprm( Decoder_State *st, - Word16 *param_lpc ) + Word16 *param_lpc /* Q0 */ +) { Word16 i, nbits_lpc; Word16 num_par; const Word16 *bits1; - num_par = 10; + num_par = 10; /* Q0 */ move16(); - bits1 = BC_TCVQ_BIT_ALLOC_40B; + bits1 = BC_TCVQ_BIT_ALLOC_40B; /* Q0 */ nbits_lpc = 0; move16(); @@ -145,10 +149,10 @@ Word16 lsf_bctcvq_decprm( FOR( i = 0; i < num_par; i++ ) { - *param_lpc = get_next_indice_fx( st, bits1[i] ); + *param_lpc = get_next_indice_fx( st, bits1[i] ); /* Q0 */ move16(); param_lpc++; - nbits_lpc = add( nbits_lpc, bits1[i] ); + nbits_lpc = add( nbits_lpc, bits1[i] ); /* Q0 */ } return nbits_lpc; @@ -156,12 +160,12 @@ Word16 lsf_bctcvq_decprm( /* Returns: number of indices */ Word16 D_lsf_tcxlpc( - const Word16 indices[], /* i : VQ indices */ - Word16 lsf_q[], /* o : quantized LSF */ - Word16 lsp_q_ind[], /* o :quantized LSP (w/o MA prediction) */ - Word16 narrowband, /* i : narrowband flag */ - Word16 cdk, /* i : codebook selector */ - Word16 mem_MA[] /* i : MA memory */ + const Word16 indices[], /* i : VQ indices Q0*/ + Word16 lsf_q[], /* o : quantized LSF Q1*/ + Word16 lsp_q_ind[], /* o :quantized LSP (w/o MA prediction) Q1*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk, /* i : codebook selector Q0*/ + Word16 mem_MA[] /* i : MA memory Q1*/ ) { Word16 i; @@ -171,7 +175,7 @@ Word16 D_lsf_tcxlpc( const Word16 *means; Word16 lsf_rem_q_ind[M]; - NumIndices = 1; + NumIndices = 1; /* Q0 */ move16(); msvq_dec( @@ -187,7 +191,7 @@ Word16 D_lsf_tcxlpc( #endif lsf_q ); - NumIndices = add( NumIndices, TCXLPC_NUMSTAGES ); + NumIndices = add( NumIndices, TCXLPC_NUMSTAGES ); /* Q0 */ FOR( i = 0; i < M; ++i ) { @@ -209,32 +213,32 @@ Word16 D_lsf_tcxlpc( 0, NULL, #endif lsf_rem_q_ind ); - NumIndices = add( NumIndices, TCXLPC_IND_NUMSTAGES ); + NumIndices = add( NumIndices, TCXLPC_IND_NUMSTAGES ); /* Q0 */ /* Add to MA-removed vector */ FOR( i = 0; i < M; ++i ) { - lsf_q_ind[i] = add( lsf_q_ind[i], lsf_rem_q_ind[i] ); + lsf_q_ind[i] = add( lsf_q_ind[i], lsf_rem_q_ind[i] ); /* Q1 */ move16(); } } /* Inter-frame prediction */ move16(); - means = lsf_means[narrowband]; + means = lsf_means[narrowband]; /* Q1 */ FOR( i = 0; i < M; ++i ) { - pred[i] = add( means[i], mult_r( MU_MA_FX, mem_MA[i] ) ); + pred[i] = add( means[i], mult_r( MU_MA_FX, mem_MA[i] ) ); /* Q1 */ move16(); } /* Add prediction */ FOR( i = 0; i < M; ++i ) { - lsf_q[i] = add( lsf_q[i], pred[i] ); + lsf_q[i] = add( lsf_q[i], pred[i] ); /* Q1 */ move16(); - lsf_q_ind[i] = add( lsf_q_ind[i], means[i] ); + lsf_q_ind[i] = add( lsf_q_ind[i], means[i] ); /* Q1 */ move16(); } @@ -251,26 +255,26 @@ Word16 D_lsf_tcxlpc( /* Returns: number of bits read */ Word16 dec_lsf_tcxlpc( - Decoder_State *st, /* i/o: Decoder state */ - Word16 **indices, /* o : Ptr to VQ indices */ - Word16 narrowband, /* i : narrowband flag */ - Word16 cdk /* i : codebook selector */ + Decoder_State *st, /* i/o: Decoder state */ + Word16 **indices, /* o : Ptr to VQ indices Q0*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk /* i : codebook selector Q0*/ ) { Word16 i, start_bit_pos; Word16 lsf_q_ind[M]; Word16 *flag; - flag = *indices; /* Save pointer */ + flag = *indices; /* Save pointer Q0*/ *flag = 0; move16(); /* Set flag to disabled */ ++*indices; - start_bit_pos = st->next_bit_pos; + start_bit_pos = st->next_bit_pos; /* Q0 */ move16(); FOR( i = 0; i < TCXLPC_NUMSTAGES; ++i ) { - **indices = get_next_indice_fx( st, lsf_numbits[i] ); + **indices = get_next_indice_fx( st, lsf_numbits[i] ); /* Q0 */ ++*indices; move16(); } @@ -290,13 +294,13 @@ Word16 dec_lsf_tcxlpc( lsf_q_ind ); /* Update flag */ - *flag = lsf_ind_is_active( lsf_q_ind, lsf_means[narrowband], narrowband, cdk ); + *flag = lsf_ind_is_active( lsf_q_ind, lsf_means[narrowband], narrowband, cdk ); /* Q0 */ move16(); IF( *flag ) { FOR( i = 0; i < TCXLPC_IND_NUMSTAGES; ++i ) { - **indices = get_next_indice_fx( st, lsf_ind_numbits[i] ); + **indices = get_next_indice_fx( st, lsf_ind_numbits[i] ); /* Q0 */ ++*indices; move16(); } diff --git a/lib_dec/nelp_dec_fx.c b/lib_dec/nelp_dec_fx.c index 1f103223ea5585b608d2562b916278e3b657c094..a1e2bbf39736aa426620c83c93ab4207142089b2 100644 --- a/lib_dec/nelp_dec_fx.c +++ b/lib_dec/nelp_dec_fx.c @@ -86,7 +86,15 @@ static void normalize_arr( Word16 *arr, Word16 *qf, Word16 size, Word16 hdr ) /* _ None */ /*===================================================================*/ -void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word16 *Q_exc, Word16 bfi, const Word16 coder_type, Word16 *gain_buf ) +void nelp_decoder_fx( + Decoder_State *st_fx, + Word16 *exc_nelp, /* Q0 */ + Word16 *exc, /* Q_exc */ + Word16 *Q_exc, + Word16 bfi, /* Q0 */ + const Word16 coder_type, /* Q0 */ + Word16 *gain_buf /* Q14 */ +) { Word16 i, fid = 0; move16(); @@ -126,7 +134,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 { IF( NE_16( st_fx->last_nelp_mode_dec, 1 ) ) { - BP1_ORDER = 7; + BP1_ORDER = 7; /* Q0 */ move16(); set32_fx( hSC_VBR->bp1_filt_mem_nb_dec_fx, 0, BP1_ORDER * 2 ); @@ -134,7 +142,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 } ELSE IF( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) ) { - BP1_ORDER = 4; + BP1_ORDER = 4; /* Q0 */ move16(); IF( NE_16( st_fx->last_nelp_mode_dec, 1 ) ) { @@ -154,21 +162,21 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 test(); IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) && EQ_16( st_fx->use_partial_copy, 1 ) ) { - iG1 = st_fx->rf_indx_nelp_iG1; + iG1 = st_fx->rf_indx_nelp_iG1; /* Q0 */ move16(); - iG2[0] = st_fx->rf_indx_nelp_iG2[0]; + iG2[0] = st_fx->rf_indx_nelp_iG2[0]; /* Q0 */ move16(); - iG2[1] = st_fx->rf_indx_nelp_iG2[1]; + iG2[1] = st_fx->rf_indx_nelp_iG2[1]; /* Q0 */ move16(); } ELSE { /* Do Unvoiced/NELP Decoding */ - iG1 = (Word16) get_next_indice_fx( st_fx, 5 ); + iG1 = (Word16) get_next_indice_fx( st_fx, 5 ); /* Q0 */ move16(); - iG2[0] = (Word16) get_next_indice_fx( st_fx, 6 ); + iG2[0] = (Word16) get_next_indice_fx( st_fx, 6 ); /* Q0 */ move16(); - iG2[1] = (Word16) get_next_indice_fx( st_fx, 6 ); + iG2[1] = (Word16) get_next_indice_fx( st_fx, 6 ); /* Q0 */ move16(); } @@ -179,12 +187,12 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 test(); IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) && EQ_16( st_fx->use_partial_copy, 1 ) ) { - fid = st_fx->rf_indx_nelp_fid; + fid = st_fx->rf_indx_nelp_fid; /* Q0 */ move16(); } ELSE { - fid = (Word16) get_next_indice_fx( st_fx, 2 ); + fid = (Word16) get_next_indice_fx( st_fx, 2 ); /* Q0 */ move16(); } } @@ -202,7 +210,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 max_exc_sqr = L_deposit_l( 0 ); FOR( i = 0; i < L_SUBFR; i++ ) { - max_exc_sqr = L_max( max_exc_sqr, exc_sqr[i] ); + max_exc_sqr = L_max( max_exc_sqr, exc_sqr[i] ); /*2*Q_exc */ } IF( max_exc_sqr != 0 ) { @@ -231,7 +239,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 n = norm_l( Gain ); frac = round_fx( L_shl( Gain, n ) ); n = sub( add( n, 24 ), 30 ); - frac = div_s( 16384, frac ); + frac = div_s( 16384, frac ); /* Q15 */ Gain = Isqrt_lc( L_deposit_h( frac ), &n ); /*Q(31-n-exp) */ tmp = round_fx( L_shl( Gain, sub( add( n, exp ), 15 ) ) ); /*Q0 */ } @@ -272,7 +280,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 test(); IF( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) ) { - BP1_ORDER = 4; + BP1_ORDER = 4; /* Q0 */ move16(); Scale_sig( hSC_VBR->bp1_filt_mem_wb_dec_fx, shl( BP1_ORDER, 1 ), qGain ); /* bring filter prev memory from Q0 to qGain */ pz_filter_sp_fx( bp1_num_coef_wb_fx, bp1_den_coef_wb_fx, ptr, ptr_tmp, hSC_VBR->bp1_filt_mem_wb_dec_fx, @@ -280,18 +288,18 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 Scale_sig( hSC_VBR->bp1_filt_mem_wb_dec_fx, shl( BP1_ORDER, 1 ), negate( qGain ) ); /* bring filter prev memory from qGain to Q0 */ Scale_sig( ptr_tmp, L_FRAME, -qGain ); /* bring nelp_exc to Q0 */ - Copy( ptr_tmp, ptr, L_FRAME ); + Copy( ptr_tmp, ptr, L_FRAME ); /* Q0 */ } test(); IF( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, NB ) ) ) { - BP1_ORDER = 7; + BP1_ORDER = 7; /* Q0 */ move16(); FOR( i = 0; i < L_FRAME; i++ ) { - max_val = s_max( ptr[i], max_val ); + max_val = s_max( ptr[i], max_val ); /* Q0 */ } tmp = shl( BP1_ORDER, 1 ); FOR( i = 0; i < tmp; i++ ) @@ -306,13 +314,13 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 IF( norm_val > 0 ) { - Scale_sig32( hSC_VBR->bp1_filt_mem_nb_dec_fx, shl( BP1_ORDER, 1 ), norm_val ); - Scale_sig( ptr, L_FRAME, norm_val ); + Scale_sig32( hSC_VBR->bp1_filt_mem_nb_dec_fx, shl( BP1_ORDER, 1 ), norm_val ); /* norm_val */ + Scale_sig( ptr, L_FRAME, norm_val ); /* norm_val + Q_exc */ *Q_exc = add( norm_val, *Q_exc ); move16(); } - BP1_ORDER = 7; + BP1_ORDER = 7; /* Q0 */ move16(); pz_filter_dp_fx( bp1_num_coef_nb_fx_order7, bp1_den_coef_nb_fx_order7, ptr, ptr_tmp, hSC_VBR->bp1_filt_mem_nb_dec_fx, BP1_ORDER, BP1_ORDER, L_FRAME, ( sub( 16, BP1_COEF_NB_QF_ORDER7 ) ) ); diff --git a/lib_dec/peak_vq_dec_fx.c b/lib_dec/peak_vq_dec_fx.c index d3fa428b2c9799f9f5d64d9d6548afc6a33ca8f4..9a3251836ff9bec4b218a74dd57a65803dba70a6 100644 --- a/lib_dec/peak_vq_dec_fx.c +++ b/lib_dec/peak_vq_dec_fx.c @@ -28,7 +28,7 @@ void hvq_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 num_bits, /* i : Number of available bits */ const Word32 core_brate, /* i : Core bit-rate */ - const Word16 *ynrm, /* i : Envelope coefficients */ + const Word16 *ynrm, /* i : Envelope coefficients Q0 */ Word16 *R, /* i/o: Bit allocation/updated bit allocation */ Word16 *noise_level, /* o : Noise level in Q15 */ Word16 *peak_idx, /* o : Peak position vector */ @@ -68,7 +68,7 @@ static void peak_vq_dec_fx( Word32 *coefs_out, /* o : Output coefficient vector Q12 */ const Word32 core_brate, /* i : Core bitrate */ const Word16 num_bits, /* i : Number of bits for HVQ */ - const Word16 *ynrm, /* i : Envelope coefficients */ + const Word16 *ynrm, /* i : Envelope coefficients Q0 */ Word16 *R, /* i/o: Bit allocation/updated bit allocation */ Word16 *vq_peak_idx, /* o : Peak position vector */ Word16 *Npeaks, /* o : Number of peaks */ @@ -241,8 +241,8 @@ static void peak_vq_dec_fx( move16(); } - peak_gains_fx[i] = dicn_pg_fx[pgain_difidx[i]]; - move32(); /* Q12 move16(); */ + peak_gains_fx[i] = dicn_pg_fx[pgain_difidx[i]]; // Q12 + move32(); if ( res_vec[vq_peak_idx[i]] < 0 ) { peak_gains_fx[i] = L_negate( peak_gains_fx[i] ); @@ -256,12 +256,12 @@ static void peak_vq_dec_fx( move16(); FOR( i = 0; i < vq_peaks; i++ ) { - peak_gains_fx[i] = L_shl( peak_gains_fx[i], 2 ); - move32(); /* Q12 */ + peak_gains_fx[i] = L_shl( peak_gains_fx[i], 2 ); // Q12 -> Q14 + move32(); /* Use floating point operation to deal with wide dynamic range. * 32-bit mantissa is used here. It should be even more accurate than * the floating-point reference code with 24-bit mantissa! */ - tmp = L_shl( dicn_pg_fx[pgain_difidx[i]], 2 ); + tmp = L_shl( dicn_pg_fx[pgain_difidx[i]], 2 ); // Q14 expPeakGains = norm_l( tmp ); manPeakGains = L_shl( tmp, expPeakGains ); Mpy_32_32_ss( manPeakGains, manPeakGains, &manPkEnrg, &lsb ); /* peak_gains square */ @@ -478,7 +478,7 @@ static Word16 hvq_dec_pos_fx( mode = get_next_indice_fx( st_fx, 1 ); num_bits = add( num_bits, 1 ); - IF( EQ_16( mode, HVQ_CP_DELTA ) ) + IF( ( mode == HVQ_CP_DELTA ) ) { huff_dec_fx( st_fx, num_peaks, HVQ_CP_HUFF_MAX_CODE, HVQ_CP_HUFF_NUM_LEN, hvq_cp_huff_thres, hvq_cp_huff_offset, hvq_cp_huff_tab, delta ); @@ -490,7 +490,7 @@ static Word16 hvq_dec_pos_fx( peak_idx[0] = sub( delta[0], HVQ_CP_HUFF_OFFSET ); move16(); /* safety check in case of bit errors */ - IF( peak_idx[0] < 2 ) + IF( LT_16( peak_idx[0], 2 ) ) { peak_idx[0] = 2; move16(); @@ -541,10 +541,10 @@ static Word16 hvq_dec_pos_fx( j = 0; move16(); /* safety check in case of bit errors */ - test(); FOR( i = 0; i < length && j < num_peaks; i++ ) { - if ( EQ_16( pos_vec[i], 1 ) ) + test(); + IF( EQ_16( pos_vec[i], 1 ) ) { pos_vec[i] = i_mult2( pos_vec[i], sign_vec[j++] ); move16(); @@ -605,7 +605,8 @@ static Word16 sparse_dec_pos_fx( move16(); } tmp = i_mult2( j, HVQ_CP_L1_LEN ); - FOR( i = sub( s_min( i_mult2( add( j, 1 ), HVQ_CP_L1_LEN ), length ), 1 ); i >= tmp; i-- ) + FOR( i = ( s_min( ( j + 1 ) * HVQ_CP_L1_LEN, length ) - 1 ); + i >= tmp; i-- ) { out[i] = s_and( val, 1 ); move16(); diff --git a/lib_dec/pit_dec_fx.c b/lib_dec/pit_dec_fx.c index a68cba5a88523e6b095d13e6b9af25bd922efcd3..a2b5a7618ea50c66bdd5aea5a420ac6b1adc4bc1 100644 --- a/lib_dec/pit_dec_fx.c +++ b/lib_dec/pit_dec_fx.c @@ -17,18 +17,18 @@ * Decode pitch lag *----------------------------------------------------------*/ -Word32 Mode2_pit_decode( /* o: floating pitch value */ +Word32 Mode2_pit_decode( /* o: pitch value Q16 */ const Word16 coder_type, /* i: coding model */ Word16 i_subfr, /* i: subframe index */ Word16 L_subfr, - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* o: close loop fractional part of the pitch */ - Word16 *T0_res, /* i/o: pitch resolution */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_min_frac, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0_max_frac, /* i/o: higher limit for close-loop search */ + Word16 **pt_indice, /* i/o: quantization indices pointer */ + Word16 *T0, /* i/o: close loop integer pitch Q0 */ + Word16 *T0_frac, /* o: close loop fractional part of the pitch Q0 */ + Word16 *T0_res, /* i/o: pitch resolution Q0 */ + Word16 *T0_min, /* i/o: lower limit for close-loop search Q0 */ + Word16 *T0_min_frac, /* i/o: lower limit for close-loop search Q0 */ + Word16 *T0_max, /* i/o: higher limit for close-loop search Q0 */ + Word16 *T0_max_frac, /* i/o: higher limit for close-loop search Q0 */ Word16 pit_min, Word16 pit_fr1, Word16 pit_fr1b, @@ -156,8 +156,8 @@ Word32 Mode2_pit_decode( /* o: floating pitch value *-------------------------------------------------------*/ assert( *T0_res > 0 || *T0_res <= 6 ); - /*pitch = (float)(*T0) + (float)(*T0_frac)/(float)(*T0_res);*/ /* save subframe pitch values */ - pitch = L_mac( L_deposit_h( *T0 ), *T0_frac, inv_T0_res[*T0_res] ); + /*pitch = (float)(*T0) + (float)(*T0_frac)/(float)(*T0_res);*/ /* save subframe pitch values */ + pitch = L_mac( L_deposit_h( *T0 ), *T0_frac, inv_T0_res[*T0_res] ); // Q16 return pitch; @@ -171,9 +171,9 @@ Word32 Mode2_pit_decode( /* o: floating pitch value *---------------------------------------------------------------------*/ void Mode2_abs_pit_dec( - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac, /* o: pitch fraction */ - Word16 *T0_res, /* o: pitch resolution */ + Word16 *T0, /* o: integer pitch lag Q0 */ + Word16 *T0_frac, /* o: pitch fraction Q0 */ + Word16 *T0_res, /* o: pitch resolution Q0 */ Word16 **pt_indice, /* i/o: pointer to Vector of Q indexes */ Word16 pit_min, Word16 pit_fr1, @@ -197,14 +197,14 @@ void Mode2_abs_pit_dec( res = pit_res_max; move16(); - if ( EQ_16( pit_res_max, 6 ) ) + IF( EQ_16( pit_res_max, 6 ) ) { res = shr( res, 1 ); } *T0 = mult( index, inv_T0_res[res] ); move16(); - if ( EQ_16( pit_res_max, 6 ) ) + IF( EQ_16( pit_res_max, 6 ) ) { *T0 = shr( *T0, 1 ); move16(); @@ -250,11 +250,11 @@ void Mode2_abs_pit_dec( * Decode delta pitch *---------------------------------------------------------------------*/ void Mode2_delta_pit_dec( - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac, /* o: pitch fraction */ - Word16 T0_res, /* i: pitch resolution */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_min_frac, /* i: delta search min */ + Word16 *T0, /* o: integer pitch lag Q0 */ + Word16 *T0_frac, /* o: pitch fraction Q0 */ + Word16 T0_res, /* i: pitch resolution Q0 */ + Word16 *T0_min, /* i/o: delta search min Q0 */ + Word16 *T0_min_frac, /* i: delta search min Q0 */ Word16 **pt_indice /* i/o: pointer to Vector of Q indexes */ ) { @@ -277,7 +277,7 @@ void Mode2_delta_pit_dec( *T0 = mult( add( index, *T0_min_frac ), inv_T0_res[res] ); move16(); - if ( EQ_16( T0_res, 6 ) ) + IF( EQ_16( T0_res, 6 ) ) { *T0 = shr( *T0, 1 ); move16(); @@ -614,12 +614,12 @@ Word16 pit_decode_ivas_fx( /* o : floating p Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ const Word16 L_subfr, /* i : subframe length */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ ) { Word16 pitch; /*Q2*/ - Word16 pitch_index, nBits, pit_flag; + Word16 pitch_index, nBits, pit_flag, tmp; pitch_index = 0; move16(); @@ -683,7 +683,8 @@ Word16 pit_decode_ivas_fx( /* o : floating p /* find the number of bits */ IF( i_subfr ) { - nBits = st_fx->acelp_cfg.pitch_bits[idiv1616( i_subfr, L_subfr )]; + tmp = idiv1616( i_subfr, L_subfr ); + nBits = st_fx->acelp_cfg.pitch_bits[tmp]; } ELSE { @@ -762,7 +763,7 @@ Word16 pit_decode_ivas_fx( /* o : floating p move16(); move16(); pit_tmp1 = tdm_Pri_pitch_buf[isubfridx]; /*tdm_Pri_pitch_buf in Q6 ->pit_tmp1 and 2 in Q6 too */ - pit_tmp2 = tdm_Pri_pitch_buf[shr( add( i_subfr, 1 ), 6 )]; + pit_tmp2 = tdm_Pri_pitch_buf[( i_subfr + 1 ) / L_SUBFR]; /*loc_T0 = (int16_t)(0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]);*/ loc_T0 = mac_r( L_mult( 16384, pit_tmp1 ), 16384, pit_tmp2 ); /*loc_frac = (int16_t)(((0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]) - loc_T0) * 4.0f);*/ @@ -771,6 +772,7 @@ Word16 pit_decode_ivas_fx( /* o : floating p { /*loc_T0 = (int16_t)tdm_Pri_pitch_buf[i_subfr / L_SUBFR];*/ loc_T0 = tdm_Pri_pitch_buf[isubfridx]; /*Q6*/ + move16(); /*loc_frac = (int16_t)((tdm_Pri_pitch_buf[i_subfr / L_SUBFR] - loc_T0) * 4.0f);*/ } loc_frac = shr( sub( loc_T0, shl( shr( loc_T0, 6 ), 6 ) ), 4 ); /* Final result in Q 2*/ @@ -1004,7 +1006,7 @@ void pit16k_Q_dec_fx( *T0 = add( PIT16k_FR2_EXTEND_10b, shr( index, 1 ) ); move16(); *T0_frac = sub( index, shl( sub( *T0, PIT16k_FR2_EXTEND_10b ), 1 ) ); - ( *T0_frac ) = shl( *T0_frac, 1 ); + ( *T0_frac ) = shl( *T0_frac, 1 ); //( *T0_frac ) *= 2; move16(); } } diff --git a/lib_dec/pitch_extr_fx.c b/lib_dec/pitch_extr_fx.c index 4831d087c2692bb2928192bef446ea10428fa129..f1e69ae68e302bc87374cdd0da0948a9a79d5801 100644 --- a/lib_dec/pitch_extr_fx.c +++ b/lib_dec/pitch_extr_fx.c @@ -16,11 +16,11 @@ * ------------------- Q15 * PIT_MAX x Fact *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED #define PIT_MAX_DIV_8k( num, fact ) ( -( num * 32768 ) / ( PIT_MAX_12k8 * fact ) ) #define PIT_MAX_DIV_12k8( num, fact ) ( -( num * 32768 ) / ( PIT_MAX_12k8 * fact ) ) #define PIT_MAX_DIV_16k( num, fact ) ( -( num * 32768 ) / ( PIT_MAX_16k * fact ) ) - +#endif /*-----------------------------------------------------------------* * Pitch prediction for frame erasure using linear fitting * @@ -76,7 +76,7 @@ void pitch_pred_linear_fit( { FOR( i = 0; i < 2 * NB_SUBFR + 2; i++ ) { - mem_lag[i] = old_pitch_buf[2 * NB_SUBFR + 1 - i]; + mem_lag[i] = old_pitch_buf[2 * NB_SUBFR + 1 - i]; // Q16 move32(); } } @@ -84,7 +84,7 @@ void pitch_pred_linear_fit( { FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) { - mem_lag[i] = old_pitch_buf[2 * NB_SUBFR16k + 1 - i]; + mem_lag[i] = old_pitch_buf[2 * NB_SUBFR16k + 1 - i]; // Q16 move32(); } } diff --git a/lib_dec/post_dec_fx.c b/lib_dec/post_dec_fx.c index bf9e51a87c2b781be74b4ea922546b2ebcc8a0de..f37a86ea12572ea99e6fe3c7a774007f4109698d 100644 --- a/lib_dec/post_dec_fx.c +++ b/lib_dec/post_dec_fx.c @@ -23,11 +23,12 @@ static void bass_pf_1sf_delay( Word16 *syn, Word16 *T_sf, Word16 *gainT_sf, Word void post_decoder( Decoder_State *st, - Word16 synth_buf[], - Word16 pit_gain[], - Word16 pitch[], - Word16 signal_out[], - Word16 *bpf_noise_buf ) + Word16 synth_buf[], /* Q0 */ + Word16 pit_gain[], /* Q14 */ + Word16 pitch[], /* Q0 */ + Word16 signal_out[], /* Q0 */ + Word16 *bpf_noise_buf /* Q0 */ +) { Word16 L_frame, nb_subfr; Word16 *synth, *synth2; @@ -81,7 +82,7 @@ void post_decoder( ELSE { /*Formant enhancement*/ - IF( EQ_16( st->last_bwidth, NB ) ) + IF( ( st->last_bwidth == NB ) ) { Copy( synth, synth2_pe, L_frame ); tmp = synth[-1]; @@ -106,7 +107,7 @@ void post_decoder( st->hPFstat->reset = 1; move16(); } - IF( EQ_16( st->bwidth, NB ) ) + IF( ( st->bwidth == NB ) ) { st->hPFstat->on = 1; move16(); @@ -174,11 +175,12 @@ void post_decoder( void post_decoder_ivas_fx( Decoder_State *st, - Word16 synth_buf[], - Word16 pit_gain[], - Word16 pitch[], - Word16 signal_out[], - Word16 *bpf_noise_buf ) + Word16 synth_buf[], // Q0 + Word16 pit_gain[], // Q14 + Word16 pitch[], // Q0 + Word16 signal_out[], // Q0 + Word16 *bpf_noise_buf // Q0 +) { Word16 L_frame, nb_subfr; Word16 *synth, *synth2; @@ -268,7 +270,7 @@ void post_decoder_ivas_fx( st->hPFstat->reset = 1; move16(); } - IF( EQ_16( st->bwidth, NB ) ) + IF( ( st->bwidth == NB ) ) { st->hPFstat->on = 1; move16(); @@ -406,12 +408,12 @@ static void bass_pf_1sf_delay( Word64 nrg64 = W_deposit32_l( nrg ); FOR( i = 0; i < lg; i++ ) { - tmp32 = L_mult( syn[sub( add( i, i_subfr ), T )], 0x4000 ); - tmp32 = L_mac( tmp32, syn[add( add( i, i_subfr ), T )], 0x4000 ); + tmp32 = L_mult( syn[( i + i_subfr ) - T], 0x4000 ); + tmp32 = L_mac( tmp32, syn[( i + i_subfr ) + T], 0x4000 ); tmp16 = round_fx( L_shl( tmp32, s1 ) ); /* Q0+s1 */ - tmp64 = W_mac0_16_16( tmp64, shl( syn[add( i, i_subfr )], s1 ), tmp16 ); /* Q0+2*s1 */ - nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ + tmp64 = W_mac0_16_16( tmp64, shl( syn[i + i_subfr], s1 ), tmp16 ); /* Q0+2*s1 */ + nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ } tmp = W_sat_l( tmp64 ); nrg = W_sat_l( nrg64 ); @@ -426,9 +428,9 @@ static void bass_pf_1sf_delay( Word64 nrg64 = W_deposit32_l( nrg ); FOR( i = lg; i < l_subfr; i++ ) { - tmp16 = shl( syn[sub( add( i, i_subfr ), T )], s1 ); /* Q0+s1 */ - tmp64 = W_mac0_16_16( tmp64, shl( syn[add( i, i_subfr )], s1 ), tmp16 ); /* Q0+2*s1 */ - nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ + tmp16 = shl( syn[( i + i_subfr ) - T], s1 ); /* Q0+s1 */ + tmp64 = W_mac0_16_16( tmp64, shl( syn[i + i_subfr], s1 ), tmp16 ); /* Q0+2*s1 */ + nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ } tmp = W_sat_l( tmp64 ); nrg = W_sat_l( nrg64 ); @@ -468,10 +470,10 @@ static void bass_pf_1sf_delay( Word64 ener2_64 = W_deposit32_l( ener2 ); FOR( i = 0; i < lg; i++ ) { - tmp32 = L_msu0( 0, gain, syn[sub( add( i, i_subfr ), T )] ); - tmp32 = L_msu0( tmp32, gain, syn[add( add( i, i_subfr ), T )] ); + tmp32 = L_msu0( 0, gain, syn[( i + i_subfr ) - T] ); + tmp32 = L_msu0( tmp32, gain, syn[( i + i_subfr ) + T] ); #ifdef BASOP_NOGLOB - tmp16 = mac_r_sat( tmp32, gain, syn[add( i, i_subfr )] ); /* Q0 */ + tmp16 = mac_r_sat( tmp32, gain, syn[i + i_subfr] ); /* Q0 */ #else tmp16 = mac_r( tmp32, gain, syn[i + i_subfr] ); /* Q0 */ #endif @@ -498,8 +500,8 @@ static void bass_pf_1sf_delay( FOR( i = lg; i < l_subfr; i++ ) { #ifdef BASOP_NOGLOB - tmp32 = L_mult0( gain, syn[add( i, i_subfr )] ); - tmp32 = L_msu0_sat( tmp32, gain, syn[sub( add( i, i_subfr ), T )] ); /* Q0 */ + tmp32 = L_mult0( gain, syn[i + i_subfr] ); + tmp32 = L_msu0_sat( tmp32, gain, syn[( i + i_subfr ) - T] ); /* Q0 */ tmp16 = round_fx_sat( tmp32 ); lp_error = Mpy_32_16_1( lp_error, 29491 /*0.9f Q15*/ ); @@ -582,11 +584,11 @@ static void bass_pf_1sf_delay( { FOR( i = 0; i < lg; i++ ) { - tmp32 = L_msu0( 0, tmp16, syn[sub( add( i, i_subfr ), T )] ); + tmp32 = L_msu0( 0, tmp16, syn[( i + i_subfr ) - T] ); #ifdef BASOP_NOGLOB - tmp32 = L_msu0_sat( tmp32, tmp16, syn[add( add( i, i_subfr ), T )] ); - tmp32 = L_mac_sat( tmp32, tmp16, syn[add( i, i_subfr )] ); - bpf_noise_buf[add( i, i_subfr )] = round_fx_sat( tmp32 ); /* Q0 */ + tmp32 = L_msu0_sat( tmp32, tmp16, syn[( i + i_subfr ) + T] ); + tmp32 = L_mac_sat( tmp32, tmp16, syn[i + i_subfr] ); + bpf_noise_buf[i + i_subfr] = round_fx_sat( tmp32 ); /* Q0 */ move16(); #else tmp32 = L_msu0( tmp32, tmp16, syn[i + i_subfr + T] ); @@ -600,10 +602,10 @@ static void bass_pf_1sf_delay( { FOR( i = lg; i < l_subfr; i++ ) { - tmp32 = L_mult0( tmp16, syn[add( i, i_subfr )] ); + tmp32 = L_mult0( tmp16, syn[i + i_subfr] ); #ifdef BASOP_NOGLOB - tmp32 = L_msu0_sat( tmp32, tmp16, syn[sub( add( i, i_subfr ), T )] ); - bpf_noise_buf[add( i, i_subfr )] = round_fx_sat( tmp32 ); /* Q0 */ + tmp32 = L_msu0_sat( tmp32, tmp16, syn[i + i_subfr - T] ); + bpf_noise_buf[i + i_subfr] = round_fx_sat( tmp32 ); /* Q0 */ move16(); #else tmp32 = L_msu0( tmp32, tmp16, syn[i + i_subfr - T] ); @@ -686,7 +688,7 @@ void cldfb_synth_set_bandsToZero( move16(); } - FOR( i = 0; i < sub( st->cldfbSyn->no_channels, st->cldfbSyn->bandsToZero ); i++ ) + FOR( i = 0; i < ( st->cldfbSyn->no_channels - st->cldfbSyn->bandsToZero ); i++ ) { nrgQ31 = 0; move32(); @@ -746,7 +748,7 @@ void cldfb_synth_set_bandsToZero( move16(); } - FOR( i = 0; i < sub( WBcnt, 1 ); i++ ) + FOR( i = 0; i < ( WBcnt - 1 ); i++ ) { st->flag_buffer[i] = st->flag_buffer[i + 1]; move16(); @@ -789,7 +791,8 @@ void cldfb_synth_set_bandsToZero( { test(); test(); - IF( ( st->perc_bwddec >= perc_detect || ( st->perc_bwddec >= perc_miss && st->last_flag_filter_NB ) ) && ( sum16_fx( st->flag_buffer, WBcnt ) != 0 ) ) /*decision hysterysis*/ + test(); + IF( ( GE_16( st->perc_bwddec, perc_detect ) || ( GE_16( st->perc_bwddec, perc_miss ) && st->last_flag_filter_NB ) ) && ( sum16_fx( st->flag_buffer, WBcnt ) != 0 ) ) /*decision hysterysis*/ { st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); move16(); diff --git a/lib_dec/ppp_dec_fx.c b/lib_dec/ppp_dec_fx.c index 88cc99e2cf3daf46dc1786cd9c3e8d03c05a2677..437927d7cce8ab4e361ab8782506e33cdec3cc89 100644 --- a/lib_dec/ppp_dec_fx.c +++ b/lib_dec/ppp_dec_fx.c @@ -60,12 +60,12 @@ static void DTFS_dequant_cw_fx( IF( EQ_16( num_erb_fx, NUM_ERB_NB ) ) { - PowerCB_fx = PowerCB_NB_fx; + PowerCB_fx = PowerCB_NB_fx; // Q11 move16(); } ELSE IF( EQ_16( num_erb_fx, NUM_ERB_WB ) ) { - PowerCB_fx = PowerCB_WB_fx; + PowerCB_fx = PowerCB_WB_fx; // Q11 move16(); } @@ -75,11 +75,11 @@ static void DTFS_dequant_cw_fx( curr_erb_fx[0] = mult_r( curr_erb_fx[1], 9830 ); /* 0.3 inQ15 leaves curr_erb in Q13 */ move16(); - curr_erb_fx[sub( num_erb_fx, 2 )] = mult_r( curr_erb_fx[sub( num_erb_fx, 3 )], 9830 ); /* Q13 */ + curr_erb_fx[num_erb_fx - 2] = mult_r( curr_erb_fx[num_erb_fx - 3], 9830 ); /* Q13 */ move16(); - curr_erb_fx[sub( num_erb_fx, 1 )] = 0; + curr_erb_fx[num_erb_fx - 1] = 0; move16(); erb_slot_fx( X_fx->lag_fx, slot_fx, mfreq_fx, num_erb_fx ); @@ -101,9 +101,13 @@ static void DTFS_dequant_cw_fx( /* This logic adjusts difference between Q formats of both bands */ IF( n < 0 ) - rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); + { + rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); + } ELSE IF( n > 0 ) + { rshiftHarmBand_fx( X_fx, 0, 2828, sub( Qh, Ql ) ); + } DTFS_to_erb_fx( *X_fx, lasterbD_fx ); @@ -203,9 +207,13 @@ static void DTFS_dequant_cw_fx( IF( n < 0 ) - rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); + { + rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); + } ELSE IF( n > 0 ) + { rshiftHarmBand_fx( X_fx, 0, 2828, sub( Qh, Ql ) ); + } } /*===================================================================*/ /* FUNCTION : void ppp_quarter_decoder_fx () */ diff --git a/lib_dec/pvq_core_dec_fx.c b/lib_dec/pvq_core_dec_fx.c index 530c2c5b937a7c1bab95cd616a760aa861c49c54..121c472fe9277a632081a444755329168956f6f9 100644 --- a/lib_dec/pvq_core_dec_fx.c +++ b/lib_dec/pvq_core_dec_fx.c @@ -25,7 +25,7 @@ static void pvq_decode_band_fx( PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ Word16 *pulse_vector, /* i/o: decoded integer shape vector */ Word16 *npulses, /* i/o: number of pulses */ - Word16 *coefs_quant, /* i/o: decoded coefficients buffer */ + Word16 *coefs_quant, /* i/o: decoded coefficients buffer Qx */ const Word16 sfmsize, /* i : band length */ const Word16 band_bits, /* i : assigned bit budget */ Word16 *bits_left, /* i/o: number of bits / bits remaining */ @@ -112,14 +112,14 @@ static void pvq_decode_band_fx( void pvq_decode_frame_fx( Decoder_State *st_fx, - Word16 *coefs_quant, /* o : quantized coefficients */ + Word16 *coefs_quant, /* o : quantized coefficients Qx */ Word16 *npulses, /* o : number of pulses per band */ Word16 *pulse_vector, /* o : non-normalized pulse shapes */ const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ const Word16 *sfmsize, /* i : band sizes */ const Word16 nb_sfm, /* i : total number of bands */ - const Word16 *R, /* i : bitallocation per band */ + const Word16 *R, /* i : bitallocation per band Q3 */ const Word16 pvq_bits, /* i : number of bits avaiable */ const Word16 core /* i : core */ ) @@ -134,6 +134,7 @@ void pvq_decode_frame_fx( Word16 strict_bits; PVQ_DEC_DATA pvq_dec; PVQ_DEC_HANDLE hPVQ = &pvq_dec; + move16(); rc_dec_init_fx( st_fx, hPVQ, pvq_bits ); @@ -174,8 +175,8 @@ void pvq_decode_frame_fx( move16(); IF( R[is] > 0 ) { - bandBitsAdjustment_fx( hPVQ->rc_num_bits, hPVQ->rc_range, bits, bands_to_code, bands_to_code - coded_bands, sfmsize[is], R[is], bit_pool, /* inputs */ - &band_bits, &bits_left, &bit_pool ); /* outputs */ + bandBitsAdjustment_fx( hPVQ->rc_num_bits, hPVQ->rc_range, bits, bands_to_code, sub( bands_to_code, coded_bands ), sfmsize[is], R[is], bit_pool, /* inputs */ + &band_bits, &bits_left, &bit_pool ); /* outputs */ pvq_decode_band_fx( st_fx, hPVQ, &pulse_vector[sfm_start[is]], &npulses[is], &coefs_quant[sfm_start[is]], sfmsize[is], band_bits, @@ -209,7 +210,7 @@ Word16 ivas_pvq_core_dec_fx( const Word16 *sfm_start, const Word16 *sfm_end, const Word16 *sfmsize, - Word16 coefs_quant[], /* o : output MDCT */ + Word16 coefs_quant[], /* o : output MDCT, Q_coefs */ Word16 *Q_coefs, Word16 bits_tot, Word16 nb_sfm, @@ -227,16 +228,16 @@ Word16 ivas_pvq_core_dec_fx( Word16 gain_bits_array[NB_SFM]; Word16 fg_pred[NB_SFM_MAX]; - IF( st_fx->hHQ_core != NULL ) + if ( st_fx->hHQ_core != NULL ) { st_fx->hHQ_core->ber_occured_in_pvq = 0; move16(); } - R_upd = shl( bits_tot, 3 ); + R_upd = shl( bits_tot, 3 ); // Q0 -> Q3 ivas_assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); - pvq_bits = shr( R_upd, 3 ); + pvq_bits = shr( R_upd, 3 ); // Q3 -> Q0 pvq_decode_frame_fx( st_fx, coefs_quant, npulses, pulse_vector, sfm_start, sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); @@ -245,7 +246,7 @@ Word16 ivas_pvq_core_dec_fx( { FOR( i = 0; i < nb_sfm; i++ ) { - IF( LE_16( npulses[i], 0 ) ) + IF( ( npulses[i] <= 0 ) ) { Rs[i] = 0; move16(); /* Update Rs in case no pulses were assigned */ @@ -257,7 +258,7 @@ Word16 ivas_pvq_core_dec_fx( { ord[i] = i; move16(); - IF( LE_16( npulses[i], 0 ) ) + if ( ( npulses[i] <= 0 ) ) { R[i] = 0; move16(); /* Update in case no pulses were assigned */ @@ -272,7 +273,7 @@ Word16 ivas_pvq_core_dec_fx( fine_gain_dec_fx( st_fx, ord, nb_sfm, gain_bits_array, fg_pred ); IF( st_fx->hHQ_core != NULL ) { - IF( NE_16( st_fx->hHQ_core->ber_occured_in_pvq, 0 ) ) + IF( ( st_fx->hHQ_core->ber_occured_in_pvq != 0 ) ) { set16_fx( fg_pred, 1, nb_sfm ); /* low complex ECU action in case of detetected BER in PVQ decoding */ } @@ -307,16 +308,16 @@ Word16 pvq_core_dec_fx( Word16 gain_bits_array[NB_SFM]; Word16 fg_pred[NB_SFM_MAX]; - IF( st_fx->hHQ_core != NULL ) + if ( st_fx->hHQ_core != NULL ) { st_fx->hHQ_core->ber_occured_in_pvq = 0; move16(); } - R_upd = shl( bits_tot, 3 ); + R_upd = shl( bits_tot, 3 ); // Q0 -> Q3 assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); - pvq_bits = shr( R_upd, 3 ); + pvq_bits = shr( R_upd, 3 ); // Q3 -> Q0 pvq_decode_frame_fx( st_fx, coefs_quant, npulses, pulse_vector, sfm_start, sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); @@ -375,7 +376,7 @@ void decode_energies_fx( Word16 *dim_part, Word16 *bits_part, Word16 *g_part, /* Q15 */ - short qband, + Word16 qband, Word16 *bits_left, Word16 dim, const Word16 strict_bits ) @@ -485,12 +486,13 @@ static void densitySymbolIndexDecode_fx( { /* odd density exit */ *index_phi = -1; + move16(); return; } sym_freq = L_deposit_l( 1 ); - angle = atan2_fx( SQRT_DIM_fx[opp_sz], SQRT_DIM_fx[near_sz] ); + angle = atan2_fx( SQRT_DIM_fx[opp_sz], SQRT_DIM_fx[near_sz] ); // Q13 #ifdef BASOP_NOGLOB angle = shl_o( angle, 1, &Overflow ); #else @@ -526,7 +528,7 @@ static void densitySymbolIndexDecode_fx( Mpy_32_16_ss( acc, density_c, &acc, &lsb ); acc = L_or( L_shl( acc, 16 ), L_and( lsb, 0xffffL ) ); /* Concatenate acc and lsb forming 48 bits; upshift 16 bits; keep 32 MSB. */ acc = L_shr( acc, 1 ); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ - tot = L_add( L_add( acc, (Word32) density ), 1L ); + tot = L_add( L_add( acc, L_deposit_l( density ) ), 1L ); dec_freq = rc_decode_fx( &st_fx->BER_detect, hPVQ, tot ); @@ -577,7 +579,7 @@ static void densitySymbolIndexDecode_fx( tmp1 = L_mult0( tmp2, tmp2 ); tmp1 = L_add( tmp1, acc ); tmp2 = getSqrtWord32( tmp1 ); /* floor */ - if ( L_msu0( tmp1, tmp2, tmp2 ) != 0 ) + IF( L_msu0( tmp1, tmp2, tmp2 ) != 0 ) { tmp2 = add( tmp2, 1 ); /* convert to ceil */ } diff --git a/lib_dec/pvq_decode_fx.c b/lib_dec/pvq_decode_fx.c index ca8c8ed0af65172c38536177abebcdceb42d0226..5c97d867987613b58b8964eea8025f66fb0a327f 100644 --- a/lib_dec/pvq_decode_fx.c +++ b/lib_dec/pvq_decode_fx.c @@ -46,6 +46,8 @@ void pvq_decode_fx( { entry.lead_sign_ind = (Word16) rc_dec_bits_fx( st_fx, hPVQ, 1 ); entry.index = rc_dec_uniform_fx( st_fx, hPVQ, entry.size ); + move16(); + move32(); IF( st_fx->hHQ_core != NULL ) { @@ -66,6 +68,8 @@ void pvq_decode_fx( { entry.lead_sign_ind = (Word16) rc_dec_bits_fx( st_fx, hPVQ, 1 ); /* always a single sign bit */ entry.index = L_deposit_l( 0 ); + move16(); + move32(); } mpvq_decode_vec_fx( &entry, h_mem, y ); diff --git a/lib_dec/range_dec_fx.c b/lib_dec/range_dec_fx.c index e53e5cc58f97560ea2a3db5bfc6f7792fb7f0033..d92e0d1d9070812f88451d73a58d336e9750ff73 100644 --- a/lib_dec/range_dec_fx.c +++ b/lib_dec/range_dec_fx.c @@ -23,23 +23,26 @@ static Word16 rc_dec_read_fx( Decoder_State *st_fx, PVQ_DEC_HANDLE hPVQ ); void rc_dec_init_fx( Decoder_State *st_fx, /* i/o: Decoder State */ PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - Word16 tot_bits /* i : Total bit budget */ + Word16 tot_bits /* i : Total bit budget Q0 */ ) { Word16 i; hPVQ->rc_low = L_deposit_l( 0 ); + move32(); hPVQ->rc_range = 0xffffffff; move32(); hPVQ->rc_num_bits = 0; move16(); hPVQ->rc_offset = add( tot_bits, st_fx->next_bit_pos ); + move16(); hPVQ->rc_end = hPVQ->rc_offset; move16(); FOR( i = 0; i < 4; i++ ) { hPVQ->rc_low = UL_addNsD( UL_lshl( hPVQ->rc_low, 8 ), UL_deposit_l( rc_dec_read_fx( st_fx, hPVQ ) ) ); + move32(); } } @@ -52,7 +55,7 @@ void rc_dec_init_fx( UWord32 rc_decode_fx( /* o : Decoded cumulative frequency */ Word16 *BER_detect, /* o : Bit error detection flag */ PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - UWord32 tot /* i : Total cumulative frequency */ + UWord32 tot /* i : Total cumulative frequency Q0 */ ) { UWord32 inv, lsb, val, UL_tmp1, UL_tmp2; @@ -62,6 +65,7 @@ UWord32 rc_decode_fx( /* o : Decoded cumulative frequency inv = UL_inverse( tot, &exp ); Mpy_32_32_uu( hPVQ->rc_range, inv, &( hPVQ->rc_help ), &lsb ); /*0+exp-32*/ hPVQ->rc_help = UL_lshr( hPVQ->rc_help, sub( exp, 32 ) ); + move32(); exp_den = norm_ul( hPVQ->rc_help ); UL_tmp2 = UL_lshl( hPVQ->rc_help, exp_den ); @@ -76,7 +80,7 @@ UWord32 rc_decode_fx( /* o : Decoded cumulative frequency UL_tmp2 = UL_Mpy_32_32( UL_addNsD( val, 1 ), hPVQ->rc_help ); UL_tmp1 = UL_subNsD( hPVQ->rc_low, UL_tmp1 ); UL_tmp2 = UL_subNsD( hPVQ->rc_low, UL_tmp2 ); - if ( UL_tmp2 < UL_tmp1 ) + IF( LT_64( UL_tmp2, UL_tmp1 ) ) { val = UL_addNsD( val, 1 ); } @@ -108,13 +112,18 @@ void rc_dec_update_fx( { hPVQ->rc_low = UL_subNsD( hPVQ->rc_low, UL_Mpy_32_32( cum_freq, hPVQ->rc_help ) ); /*0+0*/ hPVQ->rc_range = UL_Mpy_32_32( hPVQ->rc_help, sym_freq ); + move32(); + move32(); - WHILE( hPVQ->rc_range < 1 << 24 ) + WHILE( LT_64( hPVQ->rc_range, 1 << 24 ) ) { L_sub( 0, 0 ); /* For comparision in while*/ hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, 8 ); hPVQ->rc_low = UL_addNsD( UL_lshl( hPVQ->rc_low, 8 ), UL_deposit_l( rc_dec_read_fx( st_fx, hPVQ ) ) ); hPVQ->rc_range = UL_lshl( hPVQ->rc_range, 8 ); + move16(); + move32(); + move32(); } } @@ -133,17 +142,21 @@ Word32 rc_dec_bits_fx( /* i : Decoded value */ Word32 value; hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); + move16(); IF( GT_16( bits, 16 ) ) { hPVQ->rc_offset = sub( hPVQ->rc_offset, sub( bits, 16 ) ); + move16(); value = UL_lshl( UL_deposit_l( get_indice( st_fx, hPVQ->rc_offset, sub( bits, 16 ) ) ), 16 ); hPVQ->rc_offset = sub( hPVQ->rc_offset, 16 ); + move16(); value = UL_or( value, UL_deposit_l( get_indice( st_fx, hPVQ->rc_offset, 16 ) ) ); } ELSE { hPVQ->rc_offset = sub( hPVQ->rc_offset, bits ); + move16(); value = UL_deposit_l( get_indice( st_fx, hPVQ->rc_offset, bits ) ); } @@ -164,7 +177,7 @@ UWord32 rc_dec_uniform_fx( /* i : Decoded value */ { UWord32 value; Word16 n; - n = sub( 32, norm_ul( tot - 1 ) ); + n = sub( 32, norm_ul( UL_subNsD( tot, 1 ) ) ); IF( LE_16( n, 8 ) ) { @@ -195,6 +208,7 @@ void rc_dec_finish_fx( ) { st_fx->next_bit_pos = hPVQ->rc_end; + move16(); } /*-------------------------------------------------------------------* diff --git a/lib_dec/rom_dec.c b/lib_dec/rom_dec.c index 8ae4a74627f843a113dc8f54e1e7bb55213d3518..a317678a4e16ab2b2dbcfa3c37eb541d2ee40fae 100644 --- a/lib_dec/rom_dec.c +++ b/lib_dec/rom_dec.c @@ -49,11 +49,11 @@ #ifndef IVAS_FLOAT_FIXED const float h_low[5] = { -0.0125f, 0.1090f, 0.7813f, 0.1090f, -0.0125f }; #endif -const Word16 h_low_fx[5] = +const Word16 h_low_fx[5] = /* Q15 */ { -410, 3572, 25602, 3572, -410 }; -const Word16 inv_sqi[15] = +const Word16 inv_sqi[15] = /* Q15 */ { 8192, /* 1/4 */ 3641, /* 1/9 */ @@ -74,7 +74,7 @@ const Word16 inv_sqi[15] = /*-------------------------------------------------------------------* * index square used in fec_adapt_codebook *-------------------------------------------------------------------*/ -const Word16 sqi[15] = +const Word16 sqi[15] = /* Q0 */ { 4, /* 2 */ 9, /* 3 */ @@ -129,19 +129,19 @@ const float lsf_tab[LPC_SHB_ORDER] = 0.31293656f, 0.34594478f, 0.38072862f, 0.410051247f, 0.44525622f }; #endif -const Word16 lsf_tab_fx[LPC_SHB_ORDER] = +const Word16 lsf_tab_fx[LPC_SHB_ORDER] = /* Q15 */ { 2315, 3920, 5546, 6759, 7978, 10254, 11336, 12476, 13437, 14590 }; -const Word16 POW_ATT_TABLE0[OFF_FRAMES_LIMIT + 1] = +const Word16 POW_ATT_TABLE0[OFF_FRAMES_LIMIT + 1] = /* Q15 */ { 32767, 31293, 29885, 28540, 27255, 26029, 24857, 23738, 22670, 21650, 20675, 19745, 18856, 18007, 17197, 16423, 8211, 4106, 2053, 1026, 513, 257, 128, 64, 32, 16, 8, 4, 2, 1, 0 }; -const Word16 POW_ATT_TABLE1[OFF_FRAMES_LIMIT + 1] = +const Word16 POW_ATT_TABLE1[OFF_FRAMES_LIMIT + 1] = /* Q15 */ { 32767, 31656, 30581, 29543, 28540, 27571, 26635, 25731, 24857, 24013, 23198, 22410, 21650, 20915, 20205, 19519, 9759, 4880, 2440, 1220, @@ -150,7 +150,7 @@ const Word16 POW_ATT_TABLE1[OFF_FRAMES_LIMIT + 1] = /* frequency group start bins for transient analysis */ /* 125 375 750 1250 2000 4000 8000 16000 24000 */ const Word16 gw[LGW_MAX] = { 1, 3, 6, 10, 16, 32, 64, 128, 192 }; -const Word16 gw_fx[LGW_MAX] = { 1, 3, 6, 10, 16, 32, 64, 128, 192 }; /* frequency group start bins for transient analysis */ +const Word16 gw_fx[LGW_MAX] = { 1, 3, 6, 10, 16, 32, 64, 128, 192 }; /* Q0 frequency group start bins for transient analysis */ const Word16 gw_len_inv_fx[LGW_MAX - 1] = /* Q15 */ { @@ -226,7 +226,7 @@ const float w_hamm16k_2[L_TRANA16k/2] = }; #endif -const Word16 w_hamm48k_2_fx[L_TRANA48k / 2] = +const Word16 w_hamm48k_2_fx[L_TRANA48k / 2] = /* Q15 */ { 2621, 2623, 2630, 2640, 2654, 2672, 2694, 2721, 2751, 2785, 2824, 2866, 2913, 2963, 3017, 3076, @@ -254,7 +254,7 @@ const Word16 w_hamm48k_2_fx[L_TRANA48k / 2] = 32654, 32682, 32707, 32727, 32743, 32755, 32763, 32767 }; -const Word16 w_hamm32k_2_fx[L_TRANA32k / 2] = +const Word16 w_hamm32k_2_fx[L_TRANA32k / 2] = /* Q15 */ { 2621, 2626, 2640, 2663, 2695, 2736, 2786, 2845, 2913, 2991, 3077, 3172, 3276, 3388, 3509, 3639, @@ -274,7 +274,7 @@ const Word16 w_hamm32k_2_fx[L_TRANA32k / 2] = 32511, 32575, 32630, 32675, 32712, 32739, 32758, 32767 }; -const Word16 w_hamm16k_2_fx[L_TRANA16k / 2] = +const Word16 w_hamm16k_2_fx[L_TRANA16k / 2] = /* Q15 */ { 2621, 2640, 2695, 2787, 2916, 3080, 3281, 3516, 3787, 4091, 4429, 4799, 5201, 5633, 6095, 6585, @@ -285,7 +285,7 @@ const Word16 w_hamm16k_2_fx[L_TRANA16k / 2] = 28549, 29053, 29529, 29976, 30393, 30780, 31134, 31455, 31742, 31995, 32213, 32396, 32543, 32653, 32727, 32763 }; - +#ifndef IVAS_FLOAT_FIXED const float w_hamm_sana48k_2[L_PROT_HAMM_LEN2_48k] = { 0.080000000000000f, 0.080027462973758f, 0.080109848615839f, 0.080247147089046f, 0.080439341999361f, 0.080686410397899f, 0.080988322783646f, 0.081345043106986f, @@ -325,7 +325,8 @@ const float w_hamm_sana48k_2[L_PROT_HAMM_LEN2_48k] = 0.993417713086533f, 0.994237922201026f, 0.995003893384487f, 0.995715535176712f, 0.996372762604660f, 0.996975497192592f, 0.997523666971448f, 0.998017206487434f, 0.998456056809844f, 0.998840165538090f, 0.999169486807964f, 0.999443981297112f, 0.999663616229731f, 0.999828365380479f, 0.999938209077610f, 0.999993134205322f }; -const Word16 w_hamm_sana48k_2_fx[288] = +#endif +const Word16 w_hamm_sana48k_2_fx[288] = /* Q15 */ { 2621, 2622, 2625, 2630, 2636, 2644, 2654, 2666, 2679, 2694, 2711, 2730, 2751, 2773, 2797, 2823, @@ -364,6 +365,7 @@ const Word16 w_hamm_sana48k_2_fx[288] = 32552, 32579, 32604, 32628, 32649, 32669, 32687, 32703, 32717, 32730, 32741, 32750, 32757, 32762, 32766, 32767 }; +#ifndef IVAS_FLOAT_FIXED const float w_hamm_sana32k_2[L_PROT_HAMM_LEN2_32k] = { 0.080000000000000f, 0.080061898522781f, 0.080247577432747f, 0.080556986759243f, 0.080990043232791f, 0.081546630307495f, 0.082226598192408f, 0.083029763891845f, @@ -391,7 +393,7 @@ const float w_hamm_sana32k_2[L_PROT_HAMM_LEN2_32k] = 0.985208504353495f, 0.987046796215483f, 0.988764777050081f, 0.990361984507393f, 0.991837988740540f, 0.993192392521341f, 0.994424831347216f, 0.995534973539285f, 0.996522520331626f, 0.997387205951684f, 0.998128797691797f, 0.998747095971820f, 0.999241934392838f, 0.999613179781951f, 0.999860732228111f, 0.999984525109009f }; - +#endif const Word16 w_hamm_sana32k_2_fx[L_PROT_HAMM_LEN2_32k] = /* Q15 */ { 2621, 2623, 2630, 2640, 2654, 2672, 2694, 2721, @@ -419,7 +421,7 @@ const Word16 w_hamm_sana32k_2_fx[L_PROT_HAMM_LEN2_32k] = /* Q15 */ 32283, 32344, 32400, 32452, 32501, 32545, 32585, 32622, 32654, 32682, 32707, 32727, 32743, 32755, 32763, 32767 }; - +#ifndef IVAS_FLOAT_FIXED const float w_hamm_sana16k_2[L_PROT_HAMM_LEN2_16k] = { 0.080000000000000f, 0.080248875229243f, 0.080995231617495f, 0.082238261557724f, 0.083976620009229f, 0.086208425953062f, 0.088931264427414f, 0.092142189140766f, @@ -435,7 +437,7 @@ const float w_hamm_sana16k_2[L_PROT_HAMM_LEN2_16k] = 0.941486723514159f, 0.948653981707932f, 0.955379049234843f, 0.961654649126531f, 0.967473990768381f, 0.972830777247415f, 0.977719212165966f, 0.982134005913770f, 0.986070381391670f, 0.989524079180756f, 0.992491362151336f, 0.994969019506760f, 0.996954370257714f, 0.998445266123226f, 0.999440093855253f, 0.999937776984316f }; - +#endif const Word16 w_hamm_sana16k_2_fx[L_PROT_HAMM_LEN2_16k] = /* Q15 */ { 2621, 2630, 2654, 2695, 2752, 2825, 2914, 3019, @@ -471,8 +473,10 @@ const Word16 inv_tbl_2n_minus1[] = { -1, -1, /* Bits = 0 and 1 are not used */ /* er_dec_tcx.c */ +#ifndef IVAS_FLOAT_FIXED const float h_high3_32_flt[L_FIR_FER2] = {-0.0517f, -0.0587f, -0.0820f, -0.1024f, -0.1164f, 0.8786f, -0.1164f, -0.1024f, -0.0820f, -0.0587f, -0.0517f}; const float h_high3_16_flt[L_FIR_FER2] = { 0.f, -0.0205f, -0.0651f, -0.1256f, -0.1792f, 0.8028f, -0.1792f, -0.1256f, -0.0651f, -0.0205f, 0.f }; +#endif const Word16 h_high3_32[L_FIR_FER2] = { -1694/*-0.0517f Q15*/, -1923/*-0.0587f Q15*/, -2687/*-0.0820f Q15*/, -3355/*-0.1024f Q15*/, -3814/*-0.1164f Q15*/, 28790/*0.8786f Q15*/, -3814/*-0.1164f Q15*/, -3355/*-0.1024f Q15*/, -2687/*-0.0820f Q15*/, -1923/*-0.0587f Q15*/, -1694/*-0.0517f Q15*/ }; const Word16 h_high3_16[L_FIR_FER2] = { 0/* 0.f Q15*/, -672/*-0.0205f Q15*/, -2133/*-0.0651f Q15*/, -4116/*-0.1256f Q15*/, -5872/*-0.1792f Q15*/, 26306/*0.8028f Q15*/, -5872/*-0.1792f Q15*/, -4116/*-0.1256f Q15*/, -2133/*-0.0651f Q15*/, -672/*-0.0205f Q15*/, 0/* 0.f Q15*/ }; const Word16 T_256DIV_L_Frame[] = diff --git a/lib_dec/rom_dec.h b/lib_dec/rom_dec.h index 908a7f289e41f59aa2ae6181b16b26af68120283..44f45905e7ce7ae55313de1d2ca1d6ed94de07af 100644 --- a/lib_dec/rom_dec.h +++ b/lib_dec/rom_dec.h @@ -44,52 +44,55 @@ #ifndef IVAS_FLOAT_FIXED extern const float h_low[]; /* LP filter for filtering periodic part of excitation in artificial onset construction after FEC */ #endif -extern const Word16 h_low_fx[5]; -extern const Word16 inv_sqi[15]; -extern const Word16 sqi[15]; -extern const int16_t mult_avq_tab[]; -extern const int16_t shift_avq_tab[]; - -extern const int16_t hntable[55]; -extern const int16_t hetable[57]; -extern const int16_t hestable[15]; +extern const Word16 h_low_fx[5]; // Q15 +extern const Word16 inv_sqi[15]; // Q15 +extern const Word16 sqi[15]; // Q0 +extern const Word16 mult_avq_tab[]; // Q0 +extern const Word16 shift_avq_tab[]; // Q0 + +extern const Word16 hntable[55]; +extern const Word16 hetable[57]; +extern const Word16 hestable[15]; #ifndef IVAS_FLOAT_FIXED extern const float lsf_tab[LPC_SHB_ORDER]; #endif -extern const Word16 lsf_tab_fx[LPC_SHB_ORDER]; +extern const Word16 lsf_tab_fx[LPC_SHB_ORDER]; // Q15 -extern const Word16 POW_ATT_TABLE0[]; -extern const Word16 POW_ATT_TABLE1[]; -extern const int16_t gw[LGW_MAX]; -extern const Word16 gw_fx[LGW_MAX]; -extern const Word16 gw_len_inv_fx[LGW_MAX - 1]; +extern const Word16 POW_ATT_TABLE0[]; // Q15 +extern const Word16 POW_ATT_TABLE1[]; // Q15 +extern const Word16 gw[LGW_MAX]; // Q0 +extern const Word16 gw_fx[LGW_MAX]; // Q0 +extern const Word16 gw_len_inv_fx[LGW_MAX - 1]; // Q15 extern const Word16 GR_POW_HEADROOM[]; -extern const int16_t ivas_gwlpr[LGW_MAX]; +extern const Word16 ivas_gwlpr[LGW_MAX]; #ifndef IVAS_FLOAT_FIXED extern const float w_hamm48k_2[L_TRANA48k / 2]; extern const float w_hamm32k_2[L_TRANA32k / 2]; extern const float w_hamm16k_2[L_TRANA16k / 2]; #endif -extern const Word16 w_hamm48k_2_fx[]; -extern const Word16 w_hamm32k_2_fx[]; -extern const Word16 w_hamm16k_2_fx[]; - +extern const Word16 w_hamm48k_2_fx[]; // Q15 +extern const Word16 w_hamm32k_2_fx[]; // Q15 +extern const Word16 w_hamm16k_2_fx[]; // Q15 +#ifndef IVAS_FLOAT_FIXED extern const float w_hamm_sana32k_2[L_PROT_HAMM_LEN2_32k]; extern const float w_hamm_sana16k_2[L_PROT_HAMM_LEN2_16k]; extern const float w_hamm_sana48k_2[L_PROT_HAMM_LEN2_48k]; +#endif extern const Word16 swb_hr_inv_frm_len[4]; /* in Q19 */ extern const Word16 inv_tbl_2n_minus1[]; -extern const Word16 w_hamm_sana48k_2_fx[]; -extern const Word16 w_hamm_sana32k_2_fx[]; -extern const Word16 w_hamm_sana16k_2_fx[]; +extern const Word16 w_hamm_sana48k_2_fx[]; // Q15 +extern const Word16 w_hamm_sana32k_2_fx[]; // Q15 +extern const Word16 w_hamm_sana16k_2_fx[]; // Q15 +#ifndef IVAS_FLOAT_FIXED extern const float h_high3_32_flt[L_FIR_FER2]; extern const float h_high3_16_flt[L_FIR_FER2]; -extern const Word16 h_high3_32[L_FIR_FER2]; -extern const Word16 h_high3_16[L_FIR_FER2]; -extern const Word16 T_256DIV_L_Frame[]; +#endif +extern const Word16 h_high3_32[L_FIR_FER2]; // Q15 +extern const Word16 h_high3_16[L_FIR_FER2]; // Q15 +extern const Word16 T_256DIV_L_Frame[]; // Q0 -extern const Word16 pcmdsp_window_hann_960[960]; -extern const Word16 pcmdsp_window_hann_640[640]; +extern const Word16 pcmdsp_window_hann_960[960]; // Q15 +extern const Word16 pcmdsp_window_hann_640[640]; // Q15 #endif diff --git a/lib_dec/rst_dec_fx.c b/lib_dec/rst_dec_fx.c index f348b56bcf9b68dad25b26c6daa2ec2c5a1b1cdb..4a43c7fd35bba3dd77e62de9b95e44bb9c8f066b 100644 --- a/lib_dec/rst_dec_fx.c +++ b/lib_dec/rst_dec_fx.c @@ -16,9 +16,9 @@ *----------------------------------------------------------------------------------*/ void CNG_reset_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *pitch_buf, /* o : floating pitch for each subframe */ - Word16 *voice_factors /* o : voicing factors */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *pitch_buf, /* o : floating pitch for each subframe Q6 */ + Word16 *voice_factors /* o : voicing factors Q15 */ ) { Word16 tmp, exp; @@ -44,12 +44,12 @@ void CNG_reset_dec_fx( move16(); /* LP-filtered pitch gain set to 0 */ - st_fx->lp_gainp_fx = 0; + st_fx->lp_gainp_fx = 0; // Q14 move16(); /* convert CNG energy into CNG gain for ACELP FEC */ /* st->lp_gainc = sqrt( st->lp_ener ); */ - st_fx->lp_gainc_fx = 0; + st_fx->lp_gainc_fx = 0; // Q3 move16(); IF( st_fx->lp_ener_fx != 0 ) diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index b6d153746284057284761583ac8f194e9f65fd4d..cc6f7c5be3454fe41bd5d713f5998bfc154b9768 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -130,8 +130,8 @@ typedef struct #endif Word32 msCurrentMinSubWindow[NPART_SHAPING]; - int16_t msLocalMinFlag[NPART_SHAPING]; - int16_t msNewMinFlag[NPART_SHAPING]; + Word16 msLocalMinFlag[NPART_SHAPING]; + Word16 msNewMinFlag[NPART_SHAPING]; #ifndef IVAS_FLOAT_FIXED float msPsdFirstMoment_float[NPART_SHAPING]; #endif @@ -159,10 +159,10 @@ typedef struct #endif Word16 msLogNoiseEst[NPART_SHAPING]; - int16_t npart_shaping; /* Number of partitions */ - int16_t nFFTpart_shaping; /* Number of hybrid spectral partitions */ - int16_t part_shaping[NPART_SHAPING]; /* Partition upper boundaries (band indices starting from 0) */ - int16_t midband_shaping[NPART_SHAPING]; /* Central band of each partition */ + Word16 npart_shaping; /* Number of partitions */ + Word16 nFFTpart_shaping; /* Number of hybrid spectral partitions */ + Word16 part_shaping[NPART_SHAPING]; /* Partition upper boundaries (band indices starting from 0) */ + Word16 midband_shaping[NPART_SHAPING]; /* Central band of each partition */ Word16 psize_shaping[NPART_SHAPING]; /* Partition sizes */ @@ -194,8 +194,8 @@ typedef struct #endif Word32 msPeriodog_ST_fx[NPART_SHAPING]; /* stereo CNA - short-term periodogram */ Word16 msPeriodog_ST_exp; /* exponent of stereo CNA - short-term periodogram */ - int16_t ms_last_inactive_bwidth; /* stereo CNA - bandwidth from the last inactive frame */ - int16_t ms_cnt_bw_up; /* stereo CNA - downward counter of frames since the last NB->WB switch */ + Word16 ms_last_inactive_bwidth; /* stereo CNA - bandwidth from the last inactive frame */ + Word16 ms_cnt_bw_up; /* stereo CNA - downward counter of frames since the last NB->WB switch */ #ifndef IVAS_FLOAT_FIXED float cna_LR_LT; /* stereo CNA - long-term L/R correlation factor calculated on stereo upmix */ #endif @@ -208,20 +208,20 @@ typedef struct float cna_g_state[STEREO_DFT_BAND_MAX]; /* stereo CNA - side gains from the last inactive frame */ float cna_cm[STEREO_DFT_BAND_MAX]; /* stereo CNA - coherence from the last inactive frame */ #endif - int16_t first_cna_noise_updated; /* stereo CNA - flag indicating that comfort noise has been properly initialized during warmup */ - int16_t first_cna_noise_update_cnt; /* stereo CNA - counter of CN initialization frames */ - int16_t cna_nbands; /* stereo CNA - number of frequency bands used by the CNA in DFT stereo mode */ + Word16 first_cna_noise_updated; /* stereo CNA - flag indicating that comfort noise has been properly initialized during warmup */ + Word16 first_cna_noise_update_cnt; /* stereo CNA - counter of CN initialization frames */ + Word16 cna_nbands; /* stereo CNA - number of frequency bands used by the CNA in DFT stereo mode */ - int16_t cna_band_limits[STEREO_DFT_BAND_MAX + 1]; /* stereo CNA - band limits used by the CNA in DFT stereo mode */ + Word16 cna_band_limits[STEREO_DFT_BAND_MAX + 1]; /* stereo CNA - band limits used by the CNA in DFT stereo mode */ #ifndef IVAS_FLOAT_FIXED float cna_act_fact; /* stereo CNA - long-term signal activity factor (0-1) */ #endif #ifndef IVAS_FLOAT_FIXED float cna_rescale_fact; /* stereo CNA - CN energy re-scaling factor to maintain decoded energy */ #endif - int16_t cna_seed; /* stereo CNA - seed for random CN generator */ + Word16 cna_seed; /* stereo CNA - seed for random CN generator */ - int16_t flag_dtx_mode; + Word16 flag_dtx_mode; #ifndef IVAS_FLOAT_FIXED float lp_speech_float; #endif @@ -239,7 +239,7 @@ typedef struct #endif Word16 msPeriodogBuf[MSBUFLEN * NPART_SHAPING]; - int16_t msPeriodogBufPtr; + Word16 msPeriodogBufPtr; Word32 smoothed_psd_fx[L_FRAME16k]; /* stereo CNA - periodogram smoothed with IIR filter */ #ifdef IVAS_FLOAT_FIXED @@ -258,17 +258,17 @@ typedef struct typedef struct { - int16_t L_frameTCX; + Word16 L_frameTCX; Word16 FrameSize; - int16_t Pitch; + Word16 Pitch; Word16 Pitch_fx; - int16_t T_bfi; + Word16 T_bfi; Word8 T_bfi_fx; - int16_t Transient[MAX_POST_LEN]; - int16_t TCX_Tonality[DEC_STATE_LEN]; + Word16 Transient[MAX_POST_LEN]; + Word16 TCX_Tonality[DEC_STATE_LEN]; #ifndef IVAS_FLOAT_FIXED float outx_new_n1; #endif @@ -300,7 +300,7 @@ typedef struct #endif Word32 ener_fx; - int16_t zp; + Word16 zp; Word16 zp_fx; #ifndef IVAS_FLOAT_FIXED float recovery_gain_float; @@ -311,14 +311,14 @@ typedef struct #endif Word16 step_concealgain_fx; - int16_t concealment_method; + Word16 concealment_method; - int16_t subframe; + Word16 subframe; Word16 subframe_fx; - int16_t nbLostCmpt; + Word16 nbLostCmpt; - int16_t seed; + Word16 seed; } T_PLCInfo, *T_PLCInfo_HANDLE; @@ -329,8 +329,8 @@ typedef struct typedef struct { - uint16_t nSamples; - uint16_t nSamplesCore; + UWord16 nSamples; + UWord16 nSamplesCore; Float32 *spectralData_float; Word16 *spectralData; @@ -345,17 +345,17 @@ typedef struct Word16 scaleFactors_max_e; Word16 gain_tcx_exp; - int16_t blockIsValid; - int16_t blockIsConcealed; - int16_t tonalConcealmentActive; + Word16 blockIsValid; + Word16 blockIsConcealed; + Word16 tonalConcealmentActive; } blockData; typedef struct { - uint16_t numIndexes; - uint16_t indexOfTonalPeak[MAX_NUMBER_OF_IDX]; - uint16_t lowerIndex[MAX_NUMBER_OF_IDX]; - uint16_t upperIndex[MAX_NUMBER_OF_IDX]; + UWord16 numIndexes; + UWord16 indexOfTonalPeak[MAX_NUMBER_OF_IDX]; + UWord16 lowerIndex[MAX_NUMBER_OF_IDX]; + UWord16 upperIndex[MAX_NUMBER_OF_IDX]; Word16 phaseDiff[MAX_NUMBER_OF_IDX]; // Q12 /* This one can be stored with 16 bits in range 0..2*PI */ @@ -371,10 +371,10 @@ typedef struct tonalmdctconceal { TCX_config *tcx_cfg; void *pMDSTData; - int16_t nSamples; - int16_t nSamplesCore; - int16_t nNonZeroSamples; - int16_t nScaleFactors; + Word16 nSamples; + Word16 nSamplesCore; + Word16 nNonZeroSamples; + Word16 nScaleFactors; #ifndef IVAS_FLOAT_FIXED float lastPitchLag_float; @@ -452,20 +452,20 @@ typedef struct tonalmdctconceal typedef struct { - int16_t bitsRead; /* after a call bitsRead contains the number of bits consumed by the decoder */ - int16_t prev[64]; /* no more than 64 SCFs for the IGF energy envelope of one block */ - int16_t scfCountLongBlock[IGF_NOF_GRIDS]; - int16_t t; - int32_t bitrate; - const uint16_t *cf_se00; - const uint16_t *cf_se01; - int16_t cf_off_se01; - const uint16_t *cf_se02; - const int16_t *cf_off_se02; - const uint16_t *cf_se10; - int16_t cf_off_se10; - const uint16_t *cf_se11; - const int16_t *cf_off_se11; + Word16 bitsRead; /* after a call bitsRead contains the number of bits consumed by the decoder */ + Word16 prev[64]; /* no more than 64 SCFs for the IGF energy envelope of one block */ + Word16 scfCountLongBlock[IGF_NOF_GRIDS]; + Word16 t; + Word32 bitrate; + const UWord16 *cf_se00; + const UWord16 *cf_se01; + Word16 cf_off_se01; + const UWord16 *cf_se02; + const Word16 *cf_off_se02; + const UWord16 *cf_se10; + Word16 cf_off_se10; + const UWord16 *cf_se11; + const Word16 *cf_off_se11; Tastat acState; } IGFSCFDEC_INSTANCE, *IGFSCFDEC_INSTANCE_HANDLE; @@ -488,11 +488,11 @@ typedef struct igfdec_private_data_struct Word16 igf_pN_e[IGF_MAX_SFB]; - int16_t igf_curr[IGF_MAX_SFB]; /* current igf energies */ - int16_t igf_prev[IGF_MAX_SFB]; /* needed for concealment or indepflag==0 */ - int16_t igf_curr_subframe[IGF_MAX_SUBFRAMES][IGF_TRANS_FAK][IGF_MAX_SFB]; /* current igf energies per subframe*/ - int16_t igf_prev_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_SFB]; /* needed for concealment or indepflag==0 */ - int16_t igf_flatteningTrigger_subframe[IGF_MAX_SUBFRAMES]; + Word16 igf_curr[IGF_MAX_SFB]; /* current igf energies */ + Word16 igf_prev[IGF_MAX_SFB]; /* needed for concealment or indepflag==0 */ + Word16 igf_curr_subframe[IGF_MAX_SUBFRAMES][IGF_TRANS_FAK][IGF_MAX_SFB]; /* current igf energies per subframe*/ + Word16 igf_prev_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_SFB]; /* needed for concealment or indepflag==0 */ + Word16 igf_flatteningTrigger_subframe[IGF_MAX_SUBFRAMES]; /* spectral whitening: */ #ifndef IVAS_FLOAT_FIXED @@ -503,19 +503,19 @@ typedef struct igfdec_private_data_struct Word32 pSpecFlatBuf_fx[IGF_START_MX]; /* Q31 | MDCT spectrum before LPC shaping */ Word16 pSpecFlat_exp; - int16_t restrict_hopsize; + Word16 restrict_hopsize; - int16_t currWhiteningLevel[IGF_MAX_TILES]; - int16_t prevWhiteningLevel[IGF_MAX_TILES]; /* needed for concealment */ - int16_t currWhiteningLevel_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_TILES]; - int16_t prevWhiteningLevel_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_TILES]; /* needed for concealment */ + Word16 currWhiteningLevel[IGF_MAX_TILES]; + Word16 prevWhiteningLevel[IGF_MAX_TILES]; /* needed for concealment */ + Word16 currWhiteningLevel_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_TILES]; + Word16 prevWhiteningLevel_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_TILES]; /* needed for concealment */ #ifndef IVAS_FLOAT_FIXED float totalNoiseNrg_float; #endif Word32 totalNoiseNrg; Word16 totalNoiseNrg_exp; - int16_t n_noise_bands; + Word16 n_noise_bands; Word16 headroom_TCX_noise_white; Word16 headroom_TCX_noise; @@ -524,29 +524,29 @@ typedef struct igfdec_private_data_struct #endif Word32 totalNoiseNrg_off; Word16 totalNoiseNrg_off_exp; - int16_t n_noise_bands_off; + Word16 n_noise_bands_off; /* IGF SCF decoding: */ IGFSCFDEC_INSTANCE hArithSCFdec; /* concealment: */ - int16_t frameLossCounter; + Word16 frameLossCounter; } IGFDEC_PRIVATE_DATA, *IGF_DEC_PRIVATE_DATA_HANDLE; typedef struct igfdec_instance_struct { - int16_t isIGFActive; - int16_t infoIGFAllZero; - int16_t infoIGFStopLine; - int16_t infoIGFStartLine; - int16_t infoIGFStopFreq; - int16_t infoIGFStartFreq; + Word16 isIGFActive; + Word16 infoIGFAllZero; + Word16 infoIGFStopLine; + Word16 infoIGFStartLine; + Word16 infoIGFStopFreq; + Word16 infoIGFStartFreq; Word16 *infoTCXNoise_ptr; Word16 infoTCXNoise_evs[IGF_START_MX]; - int16_t *flag_sparse; - int16_t flag_sparseBuf[N_MAX_TCX - IGF_START_MN]; + Word16 *flag_sparse; + Word16 flag_sparseBuf[N_MAX_TCX - IGF_START_MN]; #ifndef IVAS_FLOAT_FIXED float *virtualSpec_float; // needed in MCT path float virtualSpecBuf[N_MAX_TCX - IGF_START_MN]; @@ -555,7 +555,7 @@ typedef struct igfdec_instance_struct Word32 virtualSpec[N_MAX_TCX - IGF_START_MN]; /* Q31 | buffer for temp flattening */ Word16 virtualSpec_e; /* | exponent of virtualSpec */ - int16_t flatteningTrigger; + Word16 flatteningTrigger; IGFDEC_PRIVATE_DATA igfData; } IGFDEC_INSTANCE, *IGF_DEC_INSTANCE_HANDLE; @@ -589,14 +589,14 @@ typedef struct tec_dec_structure typedef struct tcx_ltp_dec_structure { /* TCX-LTP */ - int16_t tcxltp; + Word16 tcxltp; #ifndef IVAS_FLOAT_FIXED float tcxltp_gain_float; #endif Word16 tcxltp_gain; /* Q15 */ - int16_t tcxltp_pitch_int; - int16_t tcxltp_pitch_fr; + Word16 tcxltp_pitch_int; + Word16 tcxltp_pitch_fr; #ifndef IVAS_FLOAT_FIXED float tcxltp_mem_in_float[TCXLTP_MAX_DELAY]; #endif @@ -615,15 +615,15 @@ typedef struct tcx_ltp_dec_structure #endif - int16_t tcxltp_pitch_int_post_prev; - int16_t tcxltp_pitch_fr_post_prev; + Word16 tcxltp_pitch_int_post_prev; + Word16 tcxltp_pitch_fr_post_prev; #ifndef IVAS_FLOAT_FIXED float tcxltp_gain_post_prev_float; #endif // #ifndef IVAS_FLOAT_FIXED Word16 tcxltp_gain_post_prev; - int16_t tcxltp_filt_idx_prev; + Word16 tcxltp_filt_idx_prev; } TCX_LTP_DEC_DATA, *TCX_LTP_DEC_HANDLE; @@ -634,8 +634,8 @@ typedef struct tcx_ltp_dec_structure typedef struct tcx_dec_structure { - int16_t enableTcxLpc; /* global toggle for the TCX LPC quantizer */ - int16_t envWeighted; /* are is{p,f}_old[] weighted or not? */ + Word16 enableTcxLpc; /* global toggle for the TCX LPC quantizer */ + Word16 envWeighted; /* are is{p,f}_old[] weighted or not? */ /* tonal PLC */ #ifndef IVAS_FLOAT_FIXED @@ -650,20 +650,20 @@ typedef struct tcx_dec_structure #endif Word16 tcxltp_last_gain_unmodified; /* Q15 */ - int16_t tcx_hm_LtpPitchLag; - int16_t tcx_lpc_shaped_ari; + Word16 tcx_hm_LtpPitchLag; + Word16 tcx_lpc_shaped_ari; - int16_t pit_min_TCX; - int16_t pit_max_TCX; + Word16 pit_min_TCX; + Word16 pit_max_TCX; - int16_t L_frameTCX; + Word16 L_frameTCX; #ifndef IVAS_FLOAT_FIXED float old_excFB[L_FRAME48k]; /* old excitation FB */ #endif Word16 old_excFB_fx[L_FRAME48k]; /* old excitation FB */ - int16_t old_synth_len; - int16_t old_synth_lenFB; + Word16 old_synth_len; + Word16 old_synth_lenFB; #ifndef IVAS_FLOAT_FIXED float old_synth_float[OLD_SYNTH_INTERNAL_DEC]; /* synthesis memory */ #endif @@ -716,25 +716,25 @@ typedef struct tcx_dec_structure /*TCX resisual Q*/ - int16_t resQBits[NB_DIV]; /* number of bits read for the residual Quantization in TCX*/ + Word16 resQBits[NB_DIV]; /* number of bits read for the residual Quantization in TCX*/ /* PLC */ - int16_t noise_filling_index[NB_DIV]; /* PLC - last decoded noise filling index */ - int16_t tnsActive[NB_DIV]; + Word16 noise_filling_index[NB_DIV]; /* PLC - last decoded noise filling index */ + Word16 tnsActive[NB_DIV]; #ifndef IVAS_FLOAT_FIXED float ltpGainMemory[N_LTP_GAIN_MEMS]; /* for smoothing noiseTransWidth */ #endif Word16 ltpGainMemory_fx[N_LTP_GAIN_MEMS]; /* Q15 */ - uint16_t kernel_type[2]; /* transform kernel type in each subframe (MDCT or MDST) */ + UWord16 kernel_type[2]; /* transform kernel type in each subframe (MDCT or MDST) */ - int16_t prev_widow_left_rect; + Word16 prev_widow_left_rect; /* state variables for the minimum statistics used for PLC */ #ifndef IVAS_FLOAT_FIXED float CngLevelBackgroundTrace_bfi; /* PLC - long term gain estimate for background level, used for PLC fade out */ float NoiseLevelMemory_bfi[PLC_MIN_STAT_BUFF_SIZE]; #endif - int16_t NoiseLevelIndex_bfi; - int16_t CurrLevelIndex_bfi; + Word16 NoiseLevelIndex_bfi; + Word16 CurrLevelIndex_bfi; Word16 conCngLevelBackgroundTrace; /* Q15 long term gain estimate for background level, used for PLC fade out */ Word16 conCngLevelBackgroundTrace_e; @@ -774,11 +774,11 @@ typedef struct tcx_dec_structure #endif Word16 stepCompensate, stepCompensate_e; - int16_t tcxConceal_recalc_exc; + Word16 tcxConceal_recalc_exc; #ifndef IVAS_FLOAT_FIXED float cummulative_damping_tcx_float; #endif - Word16 cummulative_damping_tcx; + Word16 cummulative_damping_tcx; // Q15 } TCX_DEC_DATA, *TCX_DEC_HANDLE; @@ -790,18 +790,18 @@ typedef struct tcx_dec_structure typedef struct gsc_dec_structure { - int16_t seed_tcx; /* AC mode (GSC) - seed for noise fill */ + Word16 seed_tcx; /* AC mode (GSC) - seed for noise fill */ - int16_t cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ - // Word16 cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ + Word16 cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ + // Word16 cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ #ifndef IVAS_FLOAT_FIXED float old_y_gain[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ #endif Word16 old_y_gain_fx[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ - int16_t noise_lev; /* AC mode (GSC) - noise level */ - // Word16 noise_lev; /* AC mode (GSC) - noise level Q0*/ + Word16 noise_lev; /* AC mode (GSC) - noise level */ + // Word16 noise_lev; /* AC mode (GSC) - noise level Q0*/ #ifndef IVAS_FLOAT_FIXED float lt_ener_per_band[MBANDS_GN16k]; @@ -818,8 +818,8 @@ typedef struct gsc_dec_structure #endif Word16 Last_GSC_spectrum_fx[L_FRAME16k]; /* AC mode (GSC) - Last good GSC spectrum */ - int16_t Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index */ - // Word16 Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index Q0*/ + Word16 Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index */ + // Word16 Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index Q0*/ #ifndef IVAS_FLOAT_FIXED float last_exc_dct_in[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ @@ -831,8 +831,8 @@ typedef struct gsc_dec_structure #endif Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ - int16_t last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ - // Word16 last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ + Word16 last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ + // Word16 last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ } GSC_DEC_DATA, *GSC_DEC_HANDLE; @@ -869,11 +869,11 @@ typedef struct ld_music_postfilt_structure #endif Word16 LDm_mem_etot_fx; /* LD music post-filter - total energy memory */ - int16_t LDm_last_music_flag; /* LD music post-filter - last music flag */ + Word16 LDm_last_music_flag; /* LD music post-filter - last music flag */ - int16_t LDm_nb_thr_1; /* LD music post-filter - number of consecutive frames of level 1 */ + Word16 LDm_nb_thr_1; /* LD music post-filter - number of consecutive frames of level 1 */ - int16_t LDm_nb_thr_3; + Word16 LDm_nb_thr_3; #ifndef IVAS_FLOAT_FIXED float dct_post_old_exc[DCT_L_POST - OFFSET2]; @@ -914,7 +914,7 @@ typedef struct ld_music_postfilt_structure #endif Word16 filt_lfE_fx[DCT_L_POST]; - int16_t last_nonfull_music; + Word16 last_nonfull_music; Word16 Old_ener_Q; /* Old energy scaling factor */ @@ -942,10 +942,10 @@ typedef struct bass_postfilt_structure #endif Word16 pst_lp_ener_fx; /* Bass post-filter - long-term energy Q8*/ - int16_t Track_on_hist[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ + Word16 Track_on_hist[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ - int16_t vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ - // Word16 vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ + Word16 vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ + // Word16 vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ #ifndef IVAS_FLOAT_FIXED float psf_att; /* Bass post-filter - post filter attenuation factor */ #endif @@ -964,27 +964,27 @@ typedef struct bass_postfilt_structure typedef struct td_cng_dec_structure { - int16_t cng_seed; /* DTX/CNG - seed for white noise random generator */ - // Word16 cng_seed; /*CNG and DTX - seed for white noise random generator*/ + Word16 cng_seed; /* DTX/CNG - seed for white noise random generator */ + // Word16 cng_seed; /*CNG and DTX - seed for white noise random generator*/ #ifndef IVAS_FLOAT_FIXED float Enew; /* DTX/CNG - decoded residual energy */ #endif Word32 Enew_fx; /* CNG and DTX - decoded residual energy Q6*/ - int16_t old_enr_index; /* DTX/CNG - index of last encoded CNG energy */ + Word16 old_enr_index; /* DTX/CNG - index of last encoded CNG energy */ - int16_t cng_ener_seed; /* DTX/CNG - seed for random generator for variation of excitation energy */ + Word16 cng_ener_seed; /* DTX/CNG - seed for random generator for variation of excitation energy */ - int16_t cng_ener_seed1; + Word16 cng_ener_seed1; - int16_t last_allow_cn_step; + Word16 last_allow_cn_step; - int16_t ho_hist_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + Word16 ho_hist_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - int16_t ho_hist_ptr; /* DTX/CNG - pointer for averaging buffers */ + Word16 ho_hist_ptr; /* DTX/CNG - pointer for averaging buffers */ - int32_t ho_sid_bw; /* DTX/CNG - SID bandwidth flags */ - // Word32 ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ + Word32 ho_sid_bw; /* DTX/CNG - SID bandwidth flags */ + // Word32 ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ #ifndef IVAS_FLOAT_FIXED float ho_lsp_hist[HO_HIST_SIZE * M]; /* DTX/CNG - old LSP buffer for averaging */ #endif @@ -999,12 +999,12 @@ typedef struct td_cng_dec_structure Word32 ho_env_hist_fx[HO_HIST_SIZE * NUM_ENV_CNG]; - int16_t act_cnt; /* DTX/CNG - counter of active frames */ + Word16 act_cnt; /* DTX/CNG - counter of active frames */ - int16_t ho_circ_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + Word16 ho_circ_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - int16_t ho_circ_ptr; /* DTX/CNG - pointer for averaging buffers */ - // Word16 ho_circ_ptr; /* CNG and DTX - pointer for averaging buffers */ + Word16 ho_circ_ptr; /* DTX/CNG - pointer for averaging buffers */ + // Word16 ho_circ_ptr; /* CNG and DTX - pointer for averaging buffers */ #ifndef IVAS_FLOAT_FIXED float ho_lsp_circ[HO_HIST_SIZE * M]; /* DTX/CNG - old LSP buffer for averaging */ @@ -1020,14 +1020,14 @@ typedef struct td_cng_dec_structure Word32 ho_env_circ_fx[HO_HIST_SIZE * NUM_ENV_CNG]; - int16_t num_ho; /* DTX/CNG - number of selected hangover frames */ + Word16 num_ho; /* DTX/CNG - number of selected hangover frames */ - int16_t ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ - // Word16 ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ + Word16 ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ + // Word16 ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ - int16_t act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ - // Word16 act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ + Word16 act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ + // Word16 act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ #ifndef IVAS_FLOAT_FIXED float old_env[20]; #endif @@ -1063,13 +1063,13 @@ typedef struct td_cng_dec_structure float last_wb_cng_ener; float last_shb_cng_ener; #endif - int16_t swb_cng_seed; + Word16 swb_cng_seed; #ifndef IVAS_FLOAT_FIXED float lsp_shb_prev_prev[LPC_SHB_ORDER]; float lsp_shb_prev[LPC_SHB_ORDER]; #endif - int16_t shb_dtx_count; - int16_t trans_cnt; + Word16 shb_dtx_count; + Word16 trans_cnt; #ifdef IVAS_FLOAT_FIXED Word16 interpol_3_2_cng_dec_fx[INTERP_3_2_MEM_LEN]; @@ -1083,7 +1083,7 @@ typedef struct td_cng_dec_structure Word16 lsp_shb_prev_prev_fx[LPC_SHB_ORDER]; // Q(14) #endif - int16_t burst_cnt; + Word16 burst_cnt; #ifndef IVAS_FLOAT_FIXED float last_shb_ener; #endif @@ -1103,7 +1103,7 @@ typedef struct td_cng_dec_structure typedef struct sc_vbr_dec_structure { - int16_t firstTime_voiceddec; + Word16 firstTime_voiceddec; /* DTFS variables */ #ifndef IVAS_FLOAT_FIXED @@ -1115,11 +1115,11 @@ typedef struct sc_vbr_dec_structure #endif Word16 dtfs_dec_b_fx[MAXLAG_WI]; /*Variable Q format in dtfs_dec_Q*/ - int16_t dtfs_dec_lag; + Word16 dtfs_dec_lag; - int16_t dtfs_dec_nH; + Word16 dtfs_dec_nH; - int16_t dtfs_dec_nH_4kHz; + Word16 dtfs_dec_nH_4kHz; #ifndef IVAS_FLOAT_FIXED float dtfs_dec_upper_cut_off_freq_of_interest; @@ -1172,7 +1172,7 @@ typedef struct sc_vbr_dec_structure Word16 shape3_filt_mem_dec_fx[10]; /* qfm currently Q0*/ - int16_t nelp_dec_seed; + Word16 nelp_dec_seed; Word16 FadeScale_fx; /*Q15*/ @@ -1185,24 +1185,24 @@ typedef struct sc_vbr_dec_structure typedef struct hq_nbfec_structure { - int16_t prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ - // Word16 prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ + Word16 prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ + // Word16 prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ #ifndef IVAS_FLOAT_FIXED float diff_energy; #endif Word16 diff_energy_fx; - int16_t stat_mode_out; + Word16 stat_mode_out; - int16_t stat_mode_old; + Word16 stat_mode_old; - int16_t phase_mat_flag; + Word16 phase_mat_flag; - int16_t phase_mat_next; + Word16 phase_mat_next; - int16_t old_Min_ind; + Word16 old_Min_ind; #ifndef IVAS_FLOAT_FIXED float old_auOut_2fr[L_FRAME8k * 2]; @@ -1232,16 +1232,16 @@ typedef struct hq_nbfec_structure /*Word16 old_hqswb_clas;*/ /* only used in inactive code, where it might probably be replaced by old_hqswb_clas_fx */ - int16_t HQ_FEC_seed; + Word16 HQ_FEC_seed; #ifndef IVAS_FLOAT_FIXED float energy_MA_Curr[2]; #endif Word16 energy_MA_Curr_fx[2]; - int16_t prev_sign_switch[HQ_FEC_SIGN_SFM]; + Word16 prev_sign_switch[HQ_FEC_SIGN_SFM]; - int16_t prev_sign_switch_2[HQ_FEC_SIGN_SFM]; + Word16 prev_sign_switch_2[HQ_FEC_SIGN_SFM]; #ifndef IVAS_FLOAT_FIXED float old_coeffs[L_FRAME8k]; /* HQ core - old coefficients (for FEC) */ @@ -1288,7 +1288,7 @@ typedef struct hq_dec_structure Word16 Q_old_wtda; Word16 Q_old_postdec; /*scaling of the output of core_switching_post_dec_fx() */ - int16_t last_hq_core_type; + Word16 last_hq_core_type; Word16 old_is_transient[3]; /* HQ core - previous transient flag (for FEC) */ @@ -1317,7 +1317,7 @@ typedef struct hq_dec_structure #ifndef IVAS_FLOAT_FIXED float prev_coeff_out[L_HQ_WB_BWE]; /* the highest coefficients of last frame */ #endif - int16_t prev_SWB_peak_pos[SPT_SHORTEN_SBNUM]; + Word16 prev_SWB_peak_pos[SPT_SHORTEN_SBNUM]; Word32 prev_coeff_out_fx[L_HQ_WB_BWE]; /* Q12 */ /* the coefficients of last frame */ Word16 prev_SWB_peak_pos_fx[SPT_SHORTEN_SBNUM]; @@ -1386,9 +1386,9 @@ typedef struct hq_dec_structure #endif Word16 wmold_hb_fx; /* Q15 */ - int16_t prevflag; + Word16 prevflag; - int16_t pastpre; + Word16 pastpre; Word16 prev_frm_hfe2; @@ -1477,9 +1477,9 @@ typedef struct hq_dec_structure Word16 ph_ecu_active; /* Set if Phase ECU was used in last bad frame */ - int16_t ni_seed_forfec; + Word16 ni_seed_forfec; - int16_t ber_occured_in_pvq; /* flag for BER detection from PVQ routines */ + Word16 ber_occured_in_pvq; /* flag for BER detection from PVQ routines */ } HQ_DEC_DATA, *HQ_DEC_HANDLE; @@ -1491,7 +1491,7 @@ typedef struct hq_dec_structure typedef struct zero_bwe_dec_structure { - int16_t seed2; /* HF (6-7kHz) BWE - seed for random signal generator */ + Word16 seed2; /* HF (6-7kHz) BWE - seed for random signal generator */ #ifndef IVAS_FLOAT_FIXED float mem_hp400[4]; /* HF (6-7kHz) BWE - hp400 filter memory */ @@ -1575,7 +1575,7 @@ typedef struct td_bwe_dec_structure #endif Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ - int16_t bwe_seed[2]; + Word16 bwe_seed[2]; #ifndef IVAS_FLOAT_FIXED float bwe_non_lin_prev_scale; @@ -1649,7 +1649,7 @@ typedef struct td_bwe_dec_structure #endif Word16 prev_mix_factor_fx; /* mixing factor in the previous frame */ - int16_t syn_dm_phase; + Word16 syn_dm_phase; #ifndef IVAS_FLOAT_FIXED float fbbwe_hpf_mem[4][4]; @@ -1758,27 +1758,27 @@ typedef struct td_bwe_dec_structure /* quantized data */ - int16_t lsf_idx[NUM_Q_LSF]; + Word16 lsf_idx[NUM_Q_LSF]; - int16_t m_idx; + Word16 m_idx; - int16_t grid_idx; + Word16 grid_idx; - int16_t idxSubGains; + Word16 idxSubGains; - int16_t idxFrameGain; + Word16 idxFrameGain; - int16_t idx_shb_fr_gain; + Word16 idx_shb_fr_gain; - int16_t idx_res_gs[NB_SUBFR16k]; + Word16 idx_res_gs[NB_SUBFR16k]; - int16_t idx_mixFac; + Word16 idx_mixFac; - int16_t lsf_WB; + Word16 lsf_WB; - int16_t gFrame_WB; + Word16 gFrame_WB; - int16_t idxGain; + Word16 idxGain; #ifndef IVAS_FLOAT_FIXED float old_core_synth[L_FRAME16k]; @@ -1838,7 +1838,7 @@ typedef struct fd_bwe_dec_structure #endif Word16 mem_deemph_old_syn_fx; - int16_t prev_mode; + Word16 prev_mode; #ifndef IVAS_FLOAT_FIXED float prev_SWB_fenv[SWB_FENV]; @@ -1854,13 +1854,13 @@ typedef struct fd_bwe_dec_structure #endif Word32 prev_Energy_wb_fx; - int16_t prev_L_swb_norm; + Word16 prev_L_swb_norm; - int16_t Seed; + Word16 Seed; Word16 memExp1; - int16_t prev_frica_flag; + Word16 prev_frica_flag; #ifndef IVAS_FLOAT_FIXED float mem_imdct[L_FRAME48k]; @@ -1879,7 +1879,7 @@ typedef struct fd_bwe_dec_structure #endif Word16 prev_weight_fx; - int16_t prev_flag; + Word16 prev_flag; #ifndef IVAS_FLOAT_FIXED float last_wb_bwe_ener; @@ -1899,7 +1899,7 @@ typedef struct fd_bwe_dec_structure typedef struct hr_swb_bwe_dec_structure { - int16_t bwe_highrate_seed; + Word16 bwe_highrate_seed; Word16 bwe_highrate_seed_fx; #ifndef IVAS_FLOAT_FIXED @@ -1909,7 +1909,7 @@ typedef struct hr_swb_bwe_dec_structure Word16 t_audio_prev_fx_exp[NUM_TIME_SWITCHING_BLOCKS]; - int16_t old_is_transient_hr_bwe; + Word16 old_is_transient_hr_bwe; Word16 old_is_transient_hr_bwe_fx; #ifndef IVAS_FLOAT_FIXED @@ -1929,12 +1929,12 @@ typedef struct hr_swb_bwe_dec_structure typedef struct pvq_dec_structure { - uint32_t rc_low; - uint32_t rc_range; - uint32_t rc_help; - int16_t rc_num_bits; - int16_t rc_offset; - int16_t rc_end; + UWord32 rc_low; + UWord32 rc_range; + UWord32 rc_help; + Word16 rc_num_bits; + Word16 rc_offset; + Word16 rc_end; } PVQ_DEC_DATA, *PVQ_DEC_HANDLE; @@ -1960,7 +1960,7 @@ typedef struct amrwb_io_dec_structure #endif Word16 fmerit_w_sm_fx; /* HF BWE - fmerit parameter memory */ - int16_t frame_count; /* HF BWE - frame count */ + Word16 frame_count; /* HF BWE - frame count */ Word16 frame_count_fx; /* HF BWE - frame count */ #ifndef IVAS_FLOAT_FIXED float ne_min; /* HF BWE - minimum Noise gate - short-term energy */ @@ -1987,13 +1987,13 @@ typedef struct amrwb_io_dec_structure #endif Word16 unvoicing_sm_fx; /* HF BWE - smoothed unvoiced parameter */ - int16_t unvoicing_flag; /* HF BWE - unvoiced flag */ + Word16 unvoicing_flag; /* HF BWE - unvoiced flag */ Word16 unvoicing_flag_fx; /* HF BWE - unvoiced flag */ - int16_t voicing_flag; /* HF BWE - voiced flag */ + Word16 voicing_flag; /* HF BWE - voiced flag */ Word16 voicing_flag_fx; /* HF BWE - voiced flag */ - int16_t start_band_old; /* HF BWE - previous start point for copying frequency band */ + Word16 start_band_old; /* HF BWE - previous start point for copying frequency band */ Word16 start_band_old_fx; /* HF BWE - previous start point for copying frequency band */ #ifndef IVAS_FLOAT_FIXED float OptCrit_old; /* HF BWE - previous criterion value for deciding the start point */ @@ -2001,7 +2001,7 @@ typedef struct amrwb_io_dec_structure Word32 OptCrit_old_fx; /* HF BWE - previous criterion value for deciding the start point */ /* Improvement of unvoiced and audio signals in AMR-WB IO mode */ - int16_t UV_cnt; /* number of consecutives frames classified as UV */ + Word16 UV_cnt; /* number of consecutives frames classified as UV */ Word16 UV_cnt_fx; /* number of consecutives frames classified as UV */ #ifndef IVAS_FLOAT_FIXED float LT_UV_cnt; /* long-term consecutives frames classified as UV */ @@ -2051,75 +2051,75 @@ typedef struct Decoder_State * Common parameters *----------------------------------------------------------------------------------*/ - int16_t idchan; /* channel ID (audio channel number) */ - int16_t element_mode; /* element mode */ - int32_t element_brate; /* element bitrate */ - int16_t codec_mode; /* Mode 1 or 2 */ - int16_t mdct_sw_enable; /* MDCT switching enable flag */ - int16_t mdct_sw; /* MDCT switching indicator */ - int16_t last_codec_mode; /* last used codec mode */ + Word16 idchan; /* channel ID (audio channel number) */ + Word16 element_mode; /* element mode */ + Word32 element_brate; /* element bitrate */ + Word16 codec_mode; /* Mode 1 or 2 */ + Word16 mdct_sw_enable; /* MDCT switching enable flag */ + Word16 mdct_sw; /* MDCT switching indicator */ + Word16 last_codec_mode; /* last used codec mode */ - uint16_t *bit_stream; /* pointer to bitstream buffer */ + UWord16 *bit_stream; /* pointer to bitstream buffer */ - int16_t next_bit_pos; /* position of the next bit to be read from the bitstream */ + Word16 next_bit_pos; /* position of the next bit to be read from the bitstream */ Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */ Word16 sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */ Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */ Word16 total_num_bits; /* == st->total_brate / 50 */ - int16_t BER_detect; /* flag to signal detected bit error in the bitstream */ + Word16 BER_detect; /* flag to signal detected bit error in the bitstream */ - int32_t output_Fs; /* output sampling rate */ + Word32 output_Fs; /* output sampling rate */ Word16 output_frame_fx; /* Output frame length Q0*/ - int32_t total_brate; /* total bitrate in kbps of the codec */ + Word32 total_brate; /* total bitrate in kbps of the codec */ - int32_t last_total_brate; /* last total bitrate in kbps of the codec */ - // Word32 last_total_brate_fx; /* last total bitrate in kbps of the codec Q0*/ + Word32 last_total_brate; /* last total bitrate in kbps of the codec */ + // Word32 last_total_brate_fx; /* last total bitrate in kbps of the codec Q0*/ - int32_t last_total_brate_ber; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */ + Word32 last_total_brate_ber; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */ - int16_t bits_frame_nominal; /* avg bits per frame on active frame */ - int32_t last_bits_frame_nominal; /* last avg bits per frame on active frame */ - int16_t flag_ACELP16k; /* flag indicating use of ACELP core at 16kHz internal sampling rate */ - int16_t bits_frame_channel; /* bits frame channel */ - int16_t side_bits_frame_channel; /* bits frame channel */ + Word16 bits_frame_nominal; /* avg bits per frame on active frame */ + Word32 last_bits_frame_nominal; /* last avg bits per frame on active frame */ + Word16 flag_ACELP16k; /* flag indicating use of ACELP core at 16kHz internal sampling rate */ + Word16 bits_frame_channel; /* bits frame channel */ + Word16 side_bits_frame_channel; /* bits frame channel */ - int16_t core; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ + Word16 core; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ - int16_t coder_type; /* coder type */ - int16_t transform_type[2]; /* TCX20/10/5 mode in each subframe */ + Word16 coder_type; /* coder type */ + Word16 transform_type[2]; /* TCX20/10/5 mode in each subframe */ - int32_t core_brate; /* core bitrate */ + Word32 core_brate; /* core bitrate */ - int32_t last_core_brate; /* previous frame core bitrate */ + Word32 last_core_brate; /* previous frame core bitrate */ - int16_t extl; /* extension layer */ + Word16 extl; /* extension layer */ - int16_t extl_orig; /* extension layer */ + Word16 extl_orig; /* extension layer */ - int16_t last_extl; /* previous extension layer */ + Word16 last_extl; /* previous extension layer */ - int32_t extl_brate; /* extension layer bitrate */ + Word32 extl_brate; /* extension layer bitrate */ - int32_t extl_brate_orig; /* extension layer bitrate */ + Word32 extl_brate_orig; /* extension layer bitrate */ - int16_t L_frame; /* ACELP core internal frame length */ + Word16 L_frame; /* ACELP core internal frame length */ - int16_t bwidth; /* encoded signal bandwidth */ + Word16 bwidth; /* encoded signal bandwidth */ - int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + Word16 Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ Word16 Opt_VOIP_fx; /* flag indicating VOIP mode with JBM */ - int16_t ini_frame; /* initialization frames counter */ + Word16 ini_frame; /* initialization frames counter */ - int16_t prev_coder_type; /* coding type of last frame */ - int16_t low_rate_mode; /* low-rate mode flag */ - int16_t last_low_rate_mode; /* previous frame low-rate mode flag */ - int16_t inactive_coder_type_flag; /* inactive coder type flag (0 = AVQ / 1 = GSC) */ + Word16 prev_coder_type; /* coding type of last frame */ + Word16 low_rate_mode; /* low-rate mode flag */ + Word16 last_low_rate_mode; /* previous frame low-rate mode flag */ + Word16 inactive_coder_type_flag; /* inactive coder type flag (0 = AVQ / 1 = GSC) */ Word16 CNG_fx; /* RXDTX handler: CNG=1, nonCNG=0 */ Word16 prev_ft_speech_fx; /* RXDTX handler: previous frametype flag for G.192 format AMRWB SID_FIRST detection */ @@ -2167,13 +2167,13 @@ typedef struct Decoder_State Word16 stab_fac_smooth_fx; /* low-pass filtered stability factor Q15*/ - int16_t last_coder_type; /* previous coder type */ + Word16 last_coder_type; /* previous coder type */ Word16 agc_mem_fx[2]; /* memory of AGC for saturation control Q0*/ - int16_t mid_lsf_int; + Word16 mid_lsf_int; - int16_t safety_net; + Word16 safety_net; #ifndef IVAS_FLOAT_FIXED float stab_fac; /* LSF stability factor */ @@ -2198,11 +2198,11 @@ typedef struct Decoder_State Word32 L_mem_hp_out_fx[5]; /* hp filter memory for synthesis */ - int16_t GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ + Word16 GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ - int16_t GSC_IVAS_mode; /* AC mode (GSC) - GSC IVAS mode */ + Word16 GSC_IVAS_mode; /* AC mode (GSC) - GSC IVAS mode */ - int16_t Last_GSC_noisy_speech_flag; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */ + Word16 Last_GSC_noisy_speech_flag; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */ GSC_DEC_HANDLE hGSCDec; @@ -2217,17 +2217,17 @@ typedef struct Decoder_State ZERO_BWE_DEC_HANDLE hBWE_zero; /* HF (6-7kHz) BWE */ - int16_t unv_cnt; /* Stationary noise UV modification - unvoiced frame counter */ + Word16 unv_cnt; /* Stationary noise UV modification - unvoiced frame counter */ - int16_t uv_count; /* Stationary noise UV modification - unvoiced counter */ + Word16 uv_count; /* Stationary noise UV modification - unvoiced counter */ - int16_t act_count; /* Stationary noise UV modification - activation counter */ + Word16 act_count; /* Stationary noise UV modification - activation counter */ Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain Q(GE_SHIFT)*/ Word16 lspold_s_fx[M]; /* Stationary noise UV modification - old LSP vector Q15*/ - int16_t noimix_seed; /* Stationary noise UV modification - mixture seed */ + Word16 noimix_seed; /* Stationary noise UV modification - mixture seed */ Word16 min_alpha_fx; /* Stationary noise UV modification - minimum alpha Q15*/ @@ -2244,21 +2244,21 @@ typedef struct Decoder_State Word16 Q_stat_noise_ge; /* Q of ge_sm_fx */ - int16_t bfi; /* FEC - bad frame indicator */ + Word16 bfi; /* FEC - bad frame indicator */ - int16_t prev_bfi; /* FEC - previous bad frame indicator */ + Word16 prev_bfi; /* FEC - previous bad frame indicator */ - int16_t prev_old_bfi; /* FEC - previous old bad frame indicator */ + Word16 prev_old_bfi; /* FEC - previous old bad frame indicator */ - int16_t seed; /* FEC - seed for random generator for excitation */ - // Word16 seed_fx; /* FEC - seed for random generator for excitation Q0*/ + Word16 seed; /* FEC - seed for random generator for excitation */ + // Word16 seed_fx; /* FEC - seed for random generator for excitation Q0*/ #ifndef IVAS_FLOAT_FIXED float lp_ener_bfi; /* FEC - long-term active-signal average energy */ float lp_ener; /* FEC - low-pass filtered energy */ #endif - int16_t last_good; /* FEC - clas of last good received */ + Word16 last_good; /* FEC - clas of last good received */ Word16 lp_gainp_fx; /* FEC - low-pass filtered pitch gain Q14 */ @@ -2277,14 +2277,14 @@ typedef struct Decoder_State #endif // #ifndef IVAS_FLOAT_FIXED Word16 bfi_pitch_fx; /* FEC - pitch for FEC */ - int16_t bfi_pitch_frame; /* FEC - frame length when pitch for FEC is saved */ + Word16 bfi_pitch_frame; /* FEC - frame length when pitch for FEC is saved */ Word16 old_pitch_buf_16_fx[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values Q6 */ Word32 old_pitch_buf_fx[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values 15Q16 */ - int16_t upd_cnt; /* FEC - counter of frames since last update */ + Word16 upd_cnt; /* FEC - counter of frames since last update */ - int16_t scaling_flag; /* FEC - flag to indicate energy control of syn */ + Word16 scaling_flag; /* FEC - flag to indicate energy control of syn */ Word32 lp_ener_FEC_av; /* FEC - averaged voiced signal energy Q0 */ @@ -2292,8 +2292,8 @@ typedef struct Decoder_State Word16 old_enr_LP; /* FEC - LP filter gain Q5*/ - int16_t prev_nbLostCmpt; /* FEC - compt for number of consecutive lost frame at the previous frame*/ - int16_t mode_lvq; /* FEC - index for LSF mean vector*/ + Word16 prev_nbLostCmpt; /* FEC - compt for number of consecutive lost frame at the previous frame*/ + Word16 mode_lvq; /* FEC - index for LSF mean vector*/ #ifndef IVAS_FLOAT_FIXED float old_enr_LP_float; /* FEC - LP filter gain */ @@ -2310,21 +2310,21 @@ typedef struct Decoder_State Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC (Qx2.56)*/ - int16_t decision_hyst; /* FEC - hysteresis of the music/speech decision */ + Word16 decision_hyst; /* FEC - hysteresis of the music/speech decision */ Word16 lp_ener_FER_fx; /* FEC - long-term active-signal average energy Q8*/ WI_DEC_HANDLE hWIDec; - int16_t relax_prev_lsf_interp; + Word16 relax_prev_lsf_interp; #ifndef IVAS_FLOAT_FIXED float mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ #endif // #ifndef IVAS_FLOAT_FIXED Word16 mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ - int16_t bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ + Word16 bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ BPF_DEC_HANDLE hBPF; /* Bass post-filter handle */ @@ -2337,8 +2337,8 @@ typedef struct Decoder_State HANDLE_CLDFB_FILTER_BANK cldfbSynHB; /* high band synthesis filter bank needed in SBA2Stereo DTX handling */ - int16_t last_active_bandsToZero_bwdec; - int16_t last_flag_filter_NB; + Word16 last_active_bandsToZero_bwdec; + Word16 last_flag_filter_NB; #ifndef IVAS_FLOAT_FIXED float perc_bwddec_float; @@ -2347,23 +2347,23 @@ typedef struct Decoder_State #endif // 0 Word16 perc_bwddec; /*Q14*/ - int16_t active_frame_cnt_bwddec; - int16_t flag_buffer[20]; - int16_t total_frame_cnt_bwddec; + Word16 active_frame_cnt_bwddec; + Word16 flag_buffer[20]; + Word16 total_frame_cnt_bwddec; Word32 avg_nrg_LT; Word16 Ng_ener_ST_fx; /* Noise gate - short-term energy Q8*/ - int16_t last_L_frame; /* ACELP@16kHz - last value of st->L_frame */ + Word16 last_L_frame; /* ACELP@16kHz - last value of st->L_frame */ Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */ - int16_t last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ + Word16 last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ - int16_t last_code_preq; /* ACELP@16kHz - last coefficient of the pre-quantizer contribution */ + Word16 last_code_preq; /* ACELP@16kHz - last coefficient of the pre-quantizer contribution */ - int16_t use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ + Word16 use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ /* NB and formant post-filter */ @@ -2380,35 +2380,35 @@ typedef struct Decoder_State Word16 last_voice_factor_fx; /* Q6*/ - int16_t old_bfi_cnt; /* HQ core - # of bfi until previous frame(for FEC) */ + Word16 old_bfi_cnt; /* HQ core - # of bfi until previous frame(for FEC) */ /*----------------------------------------------------------------------------------* * DTX and TD CNG parameters *----------------------------------------------------------------------------------*/ - int16_t first_CNG; /* DTX/CNG - first CNG frame flag */ + Word16 first_CNG; /* DTX/CNG - first CNG frame flag */ - int16_t cng_type; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */ + Word16 cng_type; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */ - int16_t last_vad; + Word16 last_vad; - int32_t last_active_brate; /* DTX/CNG - last active frame bitrate used for CNG_mode control */ + Word32 last_active_brate; /* DTX/CNG - last active frame bitrate used for CNG_mode control */ - int16_t last_CNG_L_frame; /* DTX/CNG - last CNG frame length */ - // Word16 last_CNG_L_frame_fx; /* DTX/CNG - last CNG frame length */ + Word16 last_CNG_L_frame; /* DTX/CNG - last CNG frame length */ + // Word16 last_CNG_L_frame_fx; /* DTX/CNG - last CNG frame length */ - int16_t CNG_mode; /* DTX/CNG - mode for DTX configuration */ - // Word16 CNG_mode_fx; /* DTX/CNG - mode for DTX configuration */ + Word16 CNG_mode; /* DTX/CNG - mode for DTX configuration */ + // Word16 CNG_mode_fx; /* DTX/CNG - mode for DTX configuration */ #ifndef IVAS_FLOAT_FIXED float lspCNG[M]; /* DTX/CNG - LP filtered ISPs */ #endif // #ifndef IVAS_FLOAT_FIXED Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered ISPs Q15*/ - int16_t active_cnt; + Word16 active_cnt; TD_CNG_DEC_HANDLE hTdCngDec; - int16_t masa_sid_format; + Word16 masa_sid_format; /*----------------------------------------------------------------------------------* * AMR-WB IO mode parameters @@ -2422,13 +2422,13 @@ typedef struct Decoder_State SC_VBR_DEC_HANDLE hSC_VBR; - int16_t last_ppp_mode_dec; + Word16 last_ppp_mode_dec; - int16_t ppp_mode_dec; + Word16 ppp_mode_dec; - int16_t last_nelp_mode_dec; + Word16 last_nelp_mode_dec; - int16_t nelp_mode_dec; + Word16 nelp_mode_dec; Word16 prev_gain_pit_dec_fx; /*Q14*/ @@ -2440,9 +2440,9 @@ typedef struct Decoder_State Word16 prev_tilt_code_dec_fx; /*Q15*/ - int16_t vbr_hw_BWE_disable_dec; + Word16 vbr_hw_BWE_disable_dec; - int16_t last_vbr_hw_BWE_disable_dec; + Word16 last_vbr_hw_BWE_disable_dec; /*----------------------------------------------------------------------------------* * channel-aware mode @@ -2450,21 +2450,21 @@ typedef struct Decoder_State Word16 tilt_code_dec_fx[NB_SUBFR16k]; - int16_t rf_frame_type; - int16_t use_partial_copy; - int16_t prev_use_partial_copy; - int16_t rf_flag; - int16_t rf_flag_last; + Word16 rf_frame_type; + Word16 use_partial_copy; + Word16 prev_use_partial_copy; + Word16 rf_flag; + Word16 rf_flag_last; - int16_t rf_fec_offset; - int16_t next_coder_type; - int16_t prev_rf_frame_type; - int16_t rf_target_bits; + Word16 rf_fec_offset; + Word16 next_coder_type; + Word16 prev_rf_frame_type; + Word16 rf_target_bits; - int16_t rf_indx_nelp_fid; - int16_t rf_indx_nelp_iG1; - int16_t rf_indx_nelp_iG2[2]; - int16_t rf_indx_tbeGainFr; + Word16 rf_indx_nelp_fid; + Word16 rf_indx_nelp_iG1; + Word16 rf_indx_nelp_iG2[2]; + Word16 rf_indx_tbeGainFr; /*----------------------------------------------------------------------------------* * HR SWB BWE parameters @@ -2479,12 +2479,12 @@ typedef struct Decoder_State HQ_DEC_HANDLE hHQ_core; - int16_t last_core; + Word16 last_core; - int16_t last_core_from_bs; /* last frame core as coded in TCX bitstream */ - // Word16 last_core_bs_fx; + Word16 last_core_from_bs; /* last frame core as coded in TCX bitstream */ + // Word16 last_core_bs_fx; - int16_t last_L_frame_ori; + Word16 last_L_frame_ori; Word16 previoussynth_fx[L_FRAME48k]; Word32 previoussynth_fx_32[L_FRAME48k]; @@ -2518,14 +2518,14 @@ typedef struct Decoder_State TD_BWE_DEC_HANDLE hBWE_TD; - int16_t old_bwe_delay; + Word16 old_bwe_delay; Word16 hb_prev_synth_buffer_fx[NS2SA( 48000, DELAY_BWE_TOTAL_NS )]; /* WB/SWB bandwidth switching */ - Word16 tilt_wb_fx; + Word16 tilt_wb_fx; // Q11 - Word16 tilt_swb_fx; + Word16 tilt_swb_fx; // Q24 #ifndef IVAS_FLOAT_FIXED float hb_prev_synth_buffer[NS2SA( 48000, DELAY_BWE_TOTAL_NS )]; @@ -2538,25 +2538,25 @@ typedef struct Decoder_State float enerLH; float enerLL; #endif - Word16 prev_ener_shb_fx; + Word16 prev_ener_shb_fx; // Q1 Word32 enerLH_fx; Word16 enerLH_fx_Q; - Word32 prev_enerLH_fx; + Word32 prev_enerLH_fx; // Q1 Word32 enerLL_fx; Word16 enerLL_fx_Q; - Word32 prev_enerLL_fx; + Word32 prev_enerLL_fx; // Q1 - int16_t prev_fractive; + Word16 prev_fractive; - int16_t prev_bws_cnt; + Word16 prev_bws_cnt; - int16_t bws_cnt; + Word16 bws_cnt; - int16_t bws_cnt1; + Word16 bws_cnt1; #ifndef IVAS_FLOAT_FIXED float attenu1; @@ -2564,9 +2564,9 @@ typedef struct Decoder_State #endif // #ifndef IVAS_FLOAT_FIXED Word16 attenu_fx; - int16_t last_inner_frame; + Word16 last_inner_frame; - int16_t last_bwidth; + Word16 last_bwidth; Word16 t_audio_q_fx[L_FRAME]; @@ -2654,19 +2654,19 @@ typedef struct Decoder_State * Mode 2 *----------------------------------------------------------------------------------*/ - int16_t force_lpd_reset; + Word16 force_lpd_reset; ACELP_config acelp_cfg; /* ACELP configuration set for each frame */ ACELP_config acelp_cfg_rf; /* ACELP configuration for RF frame */ TCX_CONFIG_HANDLE hTcxCfg; /* TCX config */ - int16_t bits_frame; /* bit per frame overall */ - int16_t bits_frame_core; /* bit per frame for the core */ - int16_t narrowBand; + Word16 bits_frame; /* bit per frame overall */ + Word16 bits_frame_core; /* bit per frame for the core */ + Word16 narrowBand; Word16 bits_common; /* read bits from header and LPC*/ - int16_t last_is_cng; + Word16 last_is_cng; #ifndef IVAS_FLOAT_FIXED float *acelp_zir; @@ -2676,16 +2676,16 @@ typedef struct Decoder_State #endif Word16 syn[M + 1]; - int16_t bpf_gain_param; /* bass post-filter gain factor parameter (0->noBpf)*/ + Word16 bpf_gain_param; /* bass post-filter gain factor parameter (0->noBpf)*/ - int16_t L_frame_past; - int16_t L_frameTCX_past; + Word16 L_frame_past; + Word16 L_frameTCX_past; Word16 lsfold_uw[M]; /* old lsf (unweighted) */ Word16 lspold_uw[M]; /* old lsp (unweighted) */ - int16_t seed_tcx_plc; /* seed memory (for random function in TCX PLC) */ + Word16 seed_tcx_plc; /* seed memory (for random function in TCX PLC) */ #ifndef IVAS_FLOAT_FIXED float lsfold_uw_float[M]; /* old lsf (unweighted) */ @@ -2720,7 +2720,7 @@ typedef struct Decoder_State Word16 mem_syn_unv_back[M]; /* filter memory for unvoiced synth */ - int16_t plcBackgroundNoiseUpdated; /* flag: Is background noise estimate updated? */ + Word16 plcBackgroundNoiseUpdated; /* flag: Is background noise estimate updated? */ #ifndef IVAS_FLOAT_FIXED float mem_syn_unv_back_float[M]; /* filter memory for unvoiced synth */ @@ -2737,19 +2737,19 @@ typedef struct Decoder_State /* variables for framing */ - int16_t nb_subfr; + Word16 nb_subfr; - int16_t fscale; - int16_t fscale_old; - int32_t sr_core; + Word16 fscale; + Word16 fscale_old; + Word32 sr_core; - int16_t pit_min; - int16_t pit_fr1; - int16_t pit_fr1b; - int16_t pit_fr2; - int16_t pit_max; - int16_t pit_res_max; - int16_t pit_res_max_past; + Word16 pit_min; + Word16 pit_fr1; + Word16 pit_fr1b; + Word16 pit_fr2; + Word16 pit_max; + Word16 pit_res_max; + Word16 pit_res_max_past; /*Preemphasis factor*/ Word16 preemph_fac; /*0Q15*/ @@ -2771,14 +2771,14 @@ typedef struct Decoder_State Word16 mem_Aq[( NB_SUBFR16k ) * ( M + 1 )]; /* Q12 */ /* Error concealment */ - int16_t last_core_bfi; /* PLC - mode in previous frame */ - int16_t nbLostCmpt; /* PLC - compt for number of consecutive lost frame */ + Word16 last_core_bfi; /* PLC - mode in previous frame */ + Word16 nbLostCmpt; /* PLC - compt for number of consecutive lost frame */ Word32 old_fpitch; /* last pitch of previous frame */ /*15Q16*/ Word32 old_fpitchFB; /* PLC - last pitch of previous FB frame (depends on output sr) */ /*15Q16*/ - int16_t clas_dec; /* PLC - frame class at the decoder */ + Word16 clas_dec; /* PLC - frame class at the decoder */ #ifndef IVAS_FLOAT_FIXED float old_fpitch_float; /* PLC - last pitch of previous frame (as transmitted) */ @@ -2790,7 +2790,7 @@ typedef struct Decoder_State #endif // #ifndef IVAS_FLOAT_FIXED Word16 mem_pitch_gain[2 * NB_SUBFR16k + 2]; /* Pitch gain memory Q14 */ - int16_t plc_use_future_lag; /* PLC - flag indicating if info (pitch lag / pitch gain) about future frame is usable */ + Word16 plc_use_future_lag; /* PLC - flag indicating if info (pitch lag / pitch gain) about future frame is usable */ Word32 Mode2_lp_gainc; /* 15Q16 low passed code gain used for concealment*/ Word32 Mode2_lp_gainp; /* 15Q16 low passed pitch gain used for concealment*/ @@ -2803,16 +2803,16 @@ typedef struct Decoder_State Word16 prev_widow_left_rect; - int16_t reset_mem_AR; + Word16 reset_mem_AR; Word16 classifier_Q_mem_syn; /*scalingfactor of mem_syn_clas_estim_fx in MODE2 */ - int16_t rate_switching_init; + Word16 rate_switching_init; /* LPC quantization */ - int16_t lpcQuantization; - int16_t numlpc; + Word16 lpcQuantization; + Word16 numlpc; /* Bandwidth */ #ifndef IVAS_FLOAT_FIXED @@ -2825,17 +2825,17 @@ typedef struct Decoder_State #endif // #ifndef IVAS_FLOAT_FIXED Word16 voice_fac; - int16_t tcxonly; + Word16 tcxonly; - int16_t last_ctx_hm_enabled; + Word16 last_ctx_hm_enabled; struct tonalmdctconceal tonalMDCTconceal; TonalMDCTConcealPtr hTonalMDCTConc; - int16_t tonal_mdct_plc_active; - int16_t last_tns_active; - int16_t second_last_tns_active; - int16_t second_last_core; + Word16 tonal_mdct_plc_active; + Word16 last_tns_active; + Word16 second_last_tns_active; + Word16 second_last_core; /* parameters for switching */ #ifndef IVAS_FLOAT_FIXED @@ -2843,7 +2843,7 @@ typedef struct Decoder_State #endif // #ifndef IVAS_FLOAT_FIXED Word16 mem_syn_r[L_SYN_MEM]; /*LPC synthesis memory needed for rate switching*/ - int16_t rate_switching_reset; + Word16 rate_switching_reset; Word16 bpf_noise_buf[L_FRAME_16k]; Word32 bpf_noise_buf_32[L_FRAME_16k]; @@ -2854,44 +2854,44 @@ typedef struct Decoder_State Word16 *p_bpf_noise_buf; Word32 *p_bpf_noise_buf_32; - int16_t enableGplc; - int16_t flagGuidedAcelp; - int16_t T0_4th; - int16_t guidedT0; + Word16 enableGplc; + Word16 flagGuidedAcelp; + Word16 T0_4th; + Word16 guidedT0; - int16_t enablePlcWaveadjust; - int16_t tonality_flag; + Word16 enablePlcWaveadjust; + Word16 tonality_flag; T_PLCInfo_HANDLE hPlcInfo; T_PLCInfo plcInfo; - int16_t VAD; - int16_t flag_cna; - int16_t last_flag_cna; + Word16 VAD; + Word16 flag_cna; + Word16 last_flag_cna; #ifndef IVAS_FLOAT_FIXED float lp_noise_float; #endif // #ifndef IVAS_FLOAT_FIXED Word32 lp_noise; - int16_t seed_acelp; - int16_t core_ext_mode; /*GC,VC,UC,TC: core extended mode used for PLC or Acelp-external modules.*/ + Word16 seed_acelp; + Word16 core_ext_mode; /*GC,VC,UC,TC: core extended mode used for PLC or Acelp-external modules.*/ - int16_t dec_glr; - int16_t dec_glr_idx; + Word16 dec_glr; + Word16 dec_glr_idx; DEC_MODE m_decodeMode; - uint8_t m_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ - uint8_t m_old_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ + UWord8 m_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ + UWord8 m_old_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ - int16_t old_ppp_mode; + Word16 old_ppp_mode; - int16_t con_tcx; - int16_t last_con_tcx; + Word16 con_tcx; + Word16 last_con_tcx; Word16 prev_Q_exc_fr; Word16 prev_Q_syn_fr; - int16_t writeFECoffset; + Word16 writeFECoffset; /*----------------------------------------------------------------------------------* * Frequency-domain-based CNG @@ -2904,7 +2904,7 @@ typedef struct Decoder_State *----------------------------------------------------------------------------------*/ IGF_DEC_INSTANCE_HANDLE hIGFDec; - int16_t igf; + Word16 igf; CLDFB_SCALE_FACTOR scaleFactor; @@ -2912,9 +2912,9 @@ typedef struct Decoder_State * TEC *----------------------------------------------------------------------------------*/ - int16_t tec_tfa; - int16_t tec_flag; - int16_t tfa_flag; + Word16 tec_tfa; + Word16 tec_flag; + Word16 tfa_flag; TEC_DEC_HANDLE hTECDec; #if 0 //not needed above structure has same variable @@ -2924,16 +2924,16 @@ typedef struct Decoder_State * IVAS parameters *----------------------------------------------------------------------------------*/ - int16_t tdm_LRTD_flag; /* LRTD stereo mode flag */ - int16_t cna_dirac_flag; /* CNA in DirAC flag */ - int16_t cng_sba_flag; /* CNG in SBA flag */ + Word16 tdm_LRTD_flag; /* LRTD stereo mode flag */ + Word16 cna_dirac_flag; /* CNA in DirAC flag */ + Word16 cng_sba_flag; /* CNG in SBA flag */ /* MCT Channel mode indication: LFE, ignore channel? */ // note_ : one extra value in evs ivas macro code MCT_CHAN_MODE mct_chan_mode; - int16_t cng_ism_flag; /* CNG in ISM format flag */ - int16_t is_ism_format; /* Indication whether the codec operates in ISM format */ + Word16 cng_ism_flag; /* CNG in ISM format flag */ + Word16 is_ism_format; /* Indication whether the codec operates in ISM format */ Word16 last_element_mode; /* element mode */ // Word16 coder_type; /* low-rate mode flag */ diff --git a/lib_dec/stat_noise_uv_dec_fx.c b/lib_dec/stat_noise_uv_dec_fx.c index c1749a536ef2aaf1b6e2a3748b0e3d1c51765cac..6c7705cfc5ea90d5afc414b4165f796604f9c48b 100644 --- a/lib_dec/stat_noise_uv_dec_fx.c +++ b/lib_dec/stat_noise_uv_dec_fx.c @@ -13,12 +13,12 @@ * Modifies excitation signal in UC mode when the noise is stationary *---------------------------------------------------------*/ void stat_noise_uv_dec_fx( - Decoder_State *st_fx, /* i/o: Decoder static memory */ - Word16 *lsp_new, /* i : end-frame LSP vector */ - Word16 *lsp_mid, /* i : mid-frame LSP vector */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ - Word16 *exc2, /* i/o: excitation buffer */ - const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ + Decoder_State *st_fx, /* i/o: Decoder static memory */ + Word16 *lsp_new, /* i : end-frame LSP vector Q15 */ + Word16 *lsp_mid, /* i : mid-frame LSP vector Q15 */ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q = 14 - norm_s(Aq[0]) */ + Word16 *exc2, /* i/o: excitation buffer, Q = st_fx->Q_exc */ + const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ ) { Word16 noisiness = 0, i; diff --git a/lib_dec/swb_bwe_dec.c b/lib_dec/swb_bwe_dec.c index a1f18d2daa2126bfdb951bd138fa9a5ba38ce7ab..34bb10fc8c9bcd607981e98196dda086c6e992fe 100644 --- a/lib_dec/swb_bwe_dec.c +++ b/lib_dec/swb_bwe_dec.c @@ -218,9 +218,9 @@ static int16_t para_pred_bws( #endif #ifdef IVAS_FLOAT_FIXED static Word16 para_pred_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *signal_wb_fx, /* i : wideband frequency signal */ - Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *signal_wb_fx, /* i : wideband frequency signal Q_syn */ + Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope Q1 */ Word16 Q_syn ) { Word16 i, j, k; @@ -242,7 +242,7 @@ static Word16 para_pred_bws_fx( k = 0; move16(); - input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; + input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; /*Q_syn*/ FOR( i = 0; i < 7; i++ ) { peak_fx = 0; @@ -251,9 +251,9 @@ static Word16 para_pred_bws_fx( move16(); FOR( j = 0; j < SHARP_WIDTH; j++ ) { - mag_fx = abs_s( *input_hi_fx ); - peak_fx = s_max( peak_fx, mag_fx ); - mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); + mag_fx = abs_s( *input_hi_fx ); /*Q_syn*/ + peak_fx = s_max( peak_fx, mag_fx ); /*Q_syn*/ + mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); /*Q_syn*/ move32(); input_hi_fx++; } @@ -275,7 +275,7 @@ static Word16 para_pred_bws_fx( } IF( tmp > 0 ) { - L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ), 18432 ), peak_fx, 4544 ); + L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ) /*Q_syn + 10*/, 18432 /*4.5f Q12*/ ), peak_fx /*Q_syn*/, 4544 /*35.5 (SHARP_WIDTH + 3.5f)Q7*/ ); if ( L_tmp < 0 ) { k = add( k, 1 ); @@ -287,11 +287,11 @@ static Word16 para_pred_bws_fx( avrg2_fx = L_deposit_l( 0 ); FOR( i = 1; i < 4; i++ ) { - avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); - avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); + avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); /*Q_syn*/ + avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); /*Q_syn*/ } - avrg1_fx = Mult_32_16( avrg1_fx, 10923 ); - avrg2_fx = Mult_32_16( avrg2_fx, 10923 ); /* 1/3 -> Q15 -> 10923 */ + avrg1_fx = Mult_32_16( avrg1_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ + avrg2_fx = Mult_32_16( avrg2_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ min_fx = L_add( 2147483647, 0 ); /*2^31 */ peak_32_fx = L_deposit_l( 0 ); @@ -303,7 +303,7 @@ static Word16 para_pred_bws_fx( IF( LT_16( exp, 16 ) ) { tmp_den = extract_l( L_shr( mean_fx[i], sub( 16, exp ) ) ); /*Qsyn - 16 + exp */ - tmp_num = extract_l( L_shr( avrg2_fx, sub( 15, exp ) ) ); /*//Qsyn - 16 + exp */ + tmp_num = extract_l( L_shr( avrg2_fx, sub( 15, exp ) ) ); /*Qsyn - 16 + exp */ } ELSE { @@ -315,16 +315,16 @@ static Word16 para_pred_bws_fx( tmp = i_mult( tmp_num, tmp_den ); /*Q15 */ - mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); + mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); /*Q_syn + Q15 - 15*/ move32(); } min_fx = L_min( min_fx, mean_fx[i] ); peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); } - IF( GT_16( st_fx->tilt_wb_fx, 16384 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 16384 /*8 in Q11*/ ) ) { - IF( GT_16( st_fx->tilt_wb_fx, 30720 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 30720 /*15.0f in Q11*/ ) ) { min_fx = peak_32_fx; move32(); @@ -410,21 +410,21 @@ static Word16 para_pred_bws_fx( FOR( i = 0; i < SWB_FENV; i++ ) { test(); - IF( NE_16( st_fx->prev_coder_type, coder_type ) && GT_16( mult_r( SWB_fenv_fx[i], 16384 ), st_fx->prev_SWB_fenv_fx[i] ) ) + IF( NE_16( st_fx->prev_coder_type, coder_type ) && GT_16( mult_r( SWB_fenv_fx[i], 16384 /*1/2.0f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i] ) ) { - SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 3277 ), st_fx->prev_SWB_fenv_fx[i], 29491 ) ); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 3277 /*0.1f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i], 29491 /*0.9f in Q15*/ ) ); move16(); } ELSE { - SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], st_fx->attenu_fx ), st_fx->prev_SWB_fenv_fx[i], sub( 32767, st_fx->attenu_fx ) ) ); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], st_fx->attenu_fx ), st_fx->prev_SWB_fenv_fx[i], sub( 32767 /*1.0f in Q15*/, st_fx->attenu_fx ) ) ); move16(); } } - IF( LT_16( st_fx->attenu_fx, 29491 ) ) + IF( LT_16( st_fx->attenu_fx, 29491 /*0.9f in Q15*/ ) ) { - st_fx->attenu_fx = add( st_fx->attenu_fx, 1638 ); + st_fx->attenu_fx = add( st_fx->attenu_fx, 1638 /*0.05f in Q15*/ ); move16(); } } @@ -439,7 +439,7 @@ static Word16 para_pred_bws_fx( { FOR( i = 0; i < SWB_FENV; i++ ) { - if ( GT_16( mult_r( SWB_fenv_fx[i], 16384 ), st_fx->prev_SWB_fenv_fx[i] ) ) + if ( GT_16( mult_r( SWB_fenv_fx[i], 16384 /*0.5f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i] ) ) { SWB_fenv_fx[i] = st_fx->prev_SWB_fenv_fx[i]; move16(); @@ -449,10 +449,10 @@ static Word16 para_pred_bws_fx( FOR( i = 0; i < SWB_FENV; i++ ) { - SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 ), st_fx->prev_SWB_fenv_fx[i], 3277 ) ); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 /*0.9f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i], 3277 /*0.1f in Q15*/ ) ); move16(); } - st_fx->attenu_fx = 3277; + st_fx->attenu_fx = 3277; /*Q15*/ move16(); } @@ -1031,12 +1031,12 @@ void swb_bwe_dec_flt( #ifdef IVAS_FLOAT_FIXED Word16 swb_bwe_dec_fx32( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 output_fx[], /* i : synthesis @internal Fs Q11 */ - Word32 *synth_fx, /* i : ACELP core synthesis/final synthesis Q11 */ - Word32 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - Word16 output_frame /* i : frame length */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 output_fx[], /* i : synthesis @internal Fs : Q11 */ + Word32 *synth_fx, /* i : ACELP core synthesis/final synthesis : Q11 */ + Word32 *hb_synth_fx, /* o : SHB synthesis/final synthesis : Q_syn_hb */ + Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + Word16 output_frame /* i : frame length */ ) { Word16 L; @@ -1285,7 +1285,7 @@ Word16 swb_bwe_dec_fx32( { FOR( i = 0; i < SWB_TENV; i++ ) { - SWB_tenv_tmp_fx[i] = L_mult0( SWB_tenv_fx[i], 26214 ); + SWB_tenv_tmp_fx[i] = L_mult0( SWB_tenv_fx[i] /*Q0*/, 26214 /*0.8f Q15*/ ); // Q15 move32(); } @@ -1351,7 +1351,7 @@ Word16 swb_bwe_dec_fx32( FOR( i = 0; i < output_frame; i++ ) { - hb_synth_fx[i] = L_deposit_l( hb_synth_fx16[i] ); + hb_synth_fx[i] = L_deposit_l( hb_synth_fx16[i] ); // Q_syn_hb move32(); } @@ -1400,7 +1400,7 @@ void fd_bwe_dec_init_fx( ) { set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); - set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) ); hBWE_FD->prev_mode = NORMAL; move16(); hBWE_FD->prev_Energy_fx = 0; @@ -1420,7 +1420,6 @@ void fd_bwe_dec_init_fx( move16(); hBWE_FD->prev_Energy_wb_fx = 0; move32(); - hBWE_FD->mem_deemph_old_syn_fx = 0; move16(); diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index 765458a90a9f76db61b11812ca0590152c810b99..6e9fd80dc897310069043a29b4fce7dde2007787 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -21,9 +21,9 @@ * predict SWB parameters for bandwidth switching *-------------------------------------------------------------------*/ static Word16 para_pred_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *signal_wb_fx, /* i : wideband frequency signal */ - Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *signal_wb_fx, /* i : wideband frequency signal Q_syn*/ + Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope Q1 */ Word16 Q_syn ) { Word16 i, j, k; @@ -45,7 +45,7 @@ static Word16 para_pred_bws_fx( k = 0; move16(); - input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; + input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; /*Q_syn*/ FOR( i = 0; i < 7; i++ ) { peak_fx = 0; @@ -54,13 +54,13 @@ static Word16 para_pred_bws_fx( move16(); FOR( j = 0; j < SHARP_WIDTH; j++ ) { - mag_fx = abs_s( *input_hi_fx ); - peak_fx = s_max( peak_fx, mag_fx ); + mag_fx = abs_s( *input_hi_fx ); /*Q_syn*/ + peak_fx = s_max( peak_fx, mag_fx ); /*Q_syn*/ /*IF (sub(mag_fx, peak_fx) > 0) */ /*{ */ /* peak_fx = mag_fx; */ /*} */ - mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); + mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); /*Q_syn*/ move32(); input_hi_fx++; } @@ -82,7 +82,7 @@ static Word16 para_pred_bws_fx( } IF( tmp > 0 ) { - L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ), 18432 ), peak_fx, 4544 ); + L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ) /*Q_syn + 10*/, 18432 /*4.5f Q12*/ ), peak_fx /*Q_syn*/, 4544 /*35.5 (SHARP_WIDTH + 3.5f)Q7*/ ); if ( L_tmp < 0 ) { k = add( k, 1 ); @@ -94,11 +94,11 @@ static Word16 para_pred_bws_fx( avrg2_fx = L_deposit_l( 0 ); FOR( i = 1; i < 4; i++ ) { - avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); - avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); + avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); /*Q_syn*/ + avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); /*Q_syn*/ } - avrg1_fx = Mult_32_16( avrg1_fx, 10923 ); - avrg2_fx = Mult_32_16( avrg2_fx, 10923 ); /* 1/3 -> Q15 -> 10923 */ + avrg1_fx = Mult_32_16( avrg1_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ + avrg2_fx = Mult_32_16( avrg2_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ min_fx = L_add( 2147483647, 0 ); /*2^31 */ peak_32_fx = L_deposit_l( 0 ); @@ -122,11 +122,11 @@ static Word16 para_pred_bws_fx( tmp = i_mult( tmp_num, tmp_den ); /*Q15 */ - mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); + mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); // Q_syn + Q15 - 15 move32(); } min_fx = L_min( min_fx, mean_fx[i] ); - peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); + peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); /*Q_syn*/ /*IF(L_sub(mean_fx[i], min_fx) < 0) */ /*{ */ /* min_fx = mean_fx[i]; */ @@ -137,9 +137,9 @@ static Word16 para_pred_bws_fx( /*} */ } - IF( GT_16( st_fx->tilt_wb_fx, 16384 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 16384 /*8 in Q11*/ ) ) { - IF( GT_16( st_fx->tilt_wb_fx, 30720 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 30720 /*15.0f in Q11*/ ) ) { min_fx = peak_32_fx; move32(); @@ -147,7 +147,7 @@ static Word16 para_pred_bws_fx( ELSE { tmp = extract_l( L_shr( L_mult0( st_fx->tilt_wb_fx, 17476 ), 14 ) ); /*Q15 */ - min_fx = Mult_32_16( peak_32_fx, tmp ); + min_fx = Mult_32_16( peak_32_fx, tmp ); /*Q_syn + Q15 - 15*/ } } @@ -272,7 +272,7 @@ static Word16 para_pred_bws_fx( SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 ), st_fx->prev_SWB_fenv_fx[i], 3277 ) ); move16(); } - st_fx->attenu_fx = 3277; + st_fx->attenu_fx = 3277; /*Q15*/ move16(); } @@ -309,7 +309,8 @@ static Word16 para_pred_bws_fx( *-------------------------------------------------------------------*/ Word16 WB_BWE_gain_deq_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *WB_fenv ) + Word16 *WB_fenv /* o : Q15 */ +) { Word16 mode; Word16 index, index2; @@ -320,25 +321,25 @@ Word16 WB_BWE_gain_deq_fx( mode = add( extract_l( get_next_indice_fx( st_fx, 1 ) ), 2 ); index2 = shl( index, 1 ); - L_tmp = L_shr( F_2_5_fx[index2], 1 ); - L_tmp = L_shl( L_tmp, 6 ); + L_tmp = L_shr( F_2_5_fx[index2] /*Q10*/, 1 ); + L_tmp = L_shl( L_tmp, 6 ); /*Q15*/ frac = L_Extract_lc( L_tmp, &exp ); tmp = extract_l( Pow2( 14, frac ) ); exp = sub( exp, 14 ); - WB_fenv[0] = shl( tmp, add( exp, 3 ) ); + WB_fenv[0] = shl( tmp, add( exp, 3 ) ); // Q15 move16(); - L_tmp = L_shr( F_2_5_fx[index2 + 1], 1 ); - L_tmp = L_shl( L_tmp, 6 ); + L_tmp = L_shr( F_2_5_fx[index2 + 1] /*Q10*/, 1 ); + L_tmp = L_shl( L_tmp, 6 ); /*Q15*/ frac = L_Extract_lc( L_tmp, &exp ); tmp = extract_l( Pow2( 14, frac ) ); exp = sub( exp, 14 ); - WB_fenv[1] = shl( tmp, add( exp, 3 ) ); + WB_fenv[1] = shl( tmp, add( exp, 3 ) ); // Q15 move16(); return ( mode ); @@ -349,16 +350,16 @@ Word16 WB_BWE_gain_deq_fx( * * WB BWE decoder (only for 16kHz signals) *-------------------------------------------------------------------*/ -Word16 ivas_wb_bwe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output[], /* i : suntehsis @ internal Fs */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ - Word16 *Qpost ) +Word16 ivas_wb_bwe_dec_fx( /* o : Q_syn_hb */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ + Word16 *Qpost ) { Word16 mode; Word16 WB_fenv_fx[SWB_FENV]; @@ -449,7 +450,7 @@ Word16 ivas_wb_bwe_dec_fx( { /* de-quantization */ mode = WB_BWE_gain_deq_fx( st_fx, WB_fenv_fx ); - st_fx->last_wb_bwe_ener_fx = extract_l( Mpy_32_16_r( L_add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 ) ); + st_fx->last_wb_bwe_ener_fx = extract_l( Mpy_32_16_r( L_add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 /*0.5f in Q15*/ ) ); move16(); } ELSE @@ -536,15 +537,15 @@ Word16 wb_bwe_dec_fx( #ifdef ADD_IVAS_BWE const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #ifdef ADD_IVAS_BWE - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif - const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ - Decoder_State *st_fx /* i/o: decoder state structure */ + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ + Decoder_State *st_fx /* i/o: decoder state structure */ , Word16 *Qpost ) { @@ -706,12 +707,12 @@ Word16 wb_bwe_dec_fx( * Decoding of SWB parameters *-------------------------------------------------------------------*/ Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 core, /* i : core */ - Word16 *SWB_tenv, /* o : Q0, time-domain BWE envelope */ - Word16 *SWB_fenv, /* o : Q1, frequency-domain BWE envelope */ - const Word16 hr_flag, /* i : high rate flag */ - const Word16 hqswb_clas /* i : HQ BWE class */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 core, /* i : core : Q0 */ + Word16 *SWB_tenv, /* o : time-domain BWE envelope : Q0 */ + Word16 *SWB_fenv, /* o : frequency-domain BWE envelope : Q1 */ + const Word16 hr_flag, /* i : high rate flag : Q0 */ + const Word16 hqswb_clas /* i : HQ BWE class : Q0 */ ) { Word16 index, mode, n_band; @@ -759,7 +760,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class FOR( n_band = 0; n_band < DIM_TR1; n_band++ ) { /*Env_TR_Cdbk1_fx[ indice[0]*DIM_TR1+n_band]*/ - quant_tmp[2 * n_band] = Env_TR_Cdbk1_fx[add( tmp, n_band )]; /*Q8 */ + quant_tmp[2 * n_band] = Env_TR_Cdbk1_fx[tmp + n_band]; /*Q8 */ move16(); } @@ -848,8 +849,8 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class move16(); } - Copy( &EnvCdbk11_fx[i_mult2( indice[0], DIM11 )], quant_tmp, DIM11 ); - Copy( &EnvCdbk1st_fx[i_mult2( indice[1], DIM1ST )], quant_tmp2, DIM1ST ); + Copy( &EnvCdbk11_fx[indice[0] * DIM11], quant_tmp, DIM11 ); + Copy( &EnvCdbk1st_fx[indice[1] * DIM1ST], quant_tmp2, DIM1ST ); Copy( &EnvCdbk2nd_fx[indice[2] * DIM2ND], quant_tmp2 + DIM1ST, DIM2ND ); FOR( n_band = 0; n_band < ( DIM11 - 1 ); n_band++ ) @@ -867,13 +868,13 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class SWB_fenv[11] = quant_tmp[6]; move16(); - Copy( &EnvCdbk3rd_fx[i_mult( indice[3], DIM3RD )], quant_tmp2, DIM3RD ); - Copy( &EnvCdbk3rd_fx[i_mult( indice[4], DIM3RD )], quant_tmp2 + DIM3RD, DIM3RD ); + Copy( &EnvCdbk3rd_fx[indice[3] * DIM3RD], quant_tmp2, DIM3RD ); + Copy( &EnvCdbk3rd_fx[indice[4] * DIM3RD], quant_tmp2 + DIM3RD, DIM3RD ); FOR( n_band = 0; n_band < 5; n_band++ ) { #ifdef BASOP_NOGLOB - SWB_fenv[add( n_band * 2, 1 )] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); + SWB_fenv[n_band * 2 + 1] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); #else SWB_fenv[add( shl( n_band, 1 ), 1 )] = add( shr( add( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); #endif @@ -896,7 +897,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class FOR( n_band = 0; n_band < DIM12 - 1; n_band++ ) { #ifdef BASOP_NOGLOB - SWB_fenv[add( n_band * 2, 1 )] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); + SWB_fenv[n_band * 2 + 1] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); #else SWB_fenv[add( shl( n_band, 1 ), 1 )] = add( shr( add( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); #endif @@ -929,11 +930,11 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class IF( EQ_16( hqswb_clas, HQ_GEN_FB ) ) { - Copy( &EnvCdbkFB_fx[i_mult2( indice[5], DIM_FB )], &SWB_fenv[nenv], DIM_FB ); /*Q7 */ + Copy( &EnvCdbkFB_fx[indice[5] * DIM_FB], &SWB_fenv[nenv], DIM_FB ); /*Q7 */ FOR( n_band = 0; n_band < DIM_FB; n_band++ ) { - tmp = add( SWB_fenv[add( n_band, nenv )], Mean_env_fb_fx[n_band] ); + tmp = add( SWB_fenv[n_band + nenv], Mean_env_fb_fx[n_band] ); L_tmp = L_mult( tmp, 21771 ); /* 0.166096 in Q17 -> Q25 */ L_tmp = L_shr( L_tmp, 9 ); /* From Q25 to Q16 */ frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ @@ -942,7 +943,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ exp = sub( exp, 13 ); - SWB_fenv[add( n_band, nenv )] = shl( tmp, add( exp, 1 ) ); + SWB_fenv[n_band + nenv] = shl( tmp, add( exp, 1 ) ); move16(); } } @@ -958,19 +959,19 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class * * SWB BWE decoder *-------------------------------------------------------------------*/ -Word16 swb_bwe_dec_fx( +Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/ #ifdef ADD_IVAS_BWE - const Word16 output[], /* i : suntehsis @ internal Fs */ + const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #ifdef ADD_IVAS_BWE - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif - const Word16 output_frame /* i : frame length */ - , - Word16 *Qpost ) + const Word16 output_frame /* i : frame length */ + , + Word16 *Qpost ) { Word16 i, l_subfr; Word16 mode; @@ -1280,7 +1281,7 @@ void fd_bwe_dec_init( { hBWE_FD->old_wtda_wb_fx_exp = 0; move16(); - set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) ); set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); hBWE_FD->old_wtda_swb_fx_exp = 0; move16(); diff --git a/lib_dec/swb_bwe_dec_hr_fx.c b/lib_dec/swb_bwe_dec_hr_fx.c index 51880fe619ec660fd521a1451d6b0647223105db..8b238e46c47df7bee365af5e5de0bb1e5f6ee7f6 100644 --- a/lib_dec/swb_bwe_dec_hr_fx.c +++ b/lib_dec/swb_bwe_dec_hr_fx.c @@ -26,6 +26,7 @@ two functions would be less efficient (Performance Wise) since the function here doesn't use 'Log2_norm_lc' at all versus gain_dequant_fx() which does. */ +#ifdef IVAS_FLOAT_FIXED static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) */ Word16 index, /* i: quantization index */ const Word16 min, /* i: value of lower limit (Q13) */ @@ -40,9 +41,9 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) L_mini = 0; /* no complexity counted, just to remove warning */ L_fact = 0; /* no complexity counted, just to remove warning */ - move32(); move32(); + IF( EQ_16( min, G_AVQ_MIN_FX ) ) { L_mini = MAKE_PSEUDO_FLT( 26214, 15 ); /* 0.8 in Q15 */ @@ -83,7 +84,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) /* c_mult = (float) ((levels-1)/(log10(max)-c_min));*/ /* gain = (float)pow( 10.0, (((float)index)/c_mult) + c_min );*/ - L_temp = L_mult0( extract_h( L_fact ), inv_tbl_2n_minus1[bits] ); + L_temp = L_mult0( extract_h( L_fact ), inv_tbl_2n_minus1[bits] ); // Q12 + Qx exp1 = norm_s( index ); index = shl( index, exp1 ); /* inv_tbl has variable Q, with Q0 being at [2]*/ @@ -100,7 +101,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) exp1 = sub( 30 - 16 - 15, p2_int ); exp1 = add( exp1, extract_l( L_mini ) ); - gain = round_fx( L_temp ); + gain = round_fx( L_temp ); // exp1 L_temp = L_mult( gain, extract_h( L_mini ) ); exp2 = norm_l( L_temp ); @@ -109,7 +110,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) gain = round_fx( L_temp ); exp1 = add( exp1, exp2 ); - *exp = exp1; + *exp = exp1; // gain_e move16(); return gain; @@ -122,7 +123,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) *-------------------------------------------------------------------*/ static Word16 TD_Postprocess( /* o : gain in Q15 */ - Word16 hb_synth_fx[], /* i/o: high-band synthesis */ + Word16 hb_synth_fx[], /* i/o: high-band synthesis Q(15 - hb_synth_fx_exp) */ const Word16 hb_synth_fx_exp, /* i : Q of high-band synthesis */ const Word16 input_frame, /* i : frame length */ const Word16 last_extl /* i : last extension layer */ @@ -251,14 +252,14 @@ static Word16 TD_Postprocess( /* o : gain in Q15 * HR SWB BWE decoder *-------------------------------------------------------------------*/ -Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz */ - const Word16 exp, /* i : Exponent of core synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis */ - const Word16 output_frame, /* i : frame length */ - const Word16 unbits, /* i : number of core unused bits */ - const Word16 pitch_buf[] /* i : pitch buffer */ +Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz : Q(15 - exp) */ + const Word16 exp, /* i : Exponent of core synthesis */ + Word16 *hb_synth_fx, /* o : SHB synthesis : Q(15 - hb_synth_fx_exp)*/ + const Word16 output_frame, /* i : frame length */ + const Word16 unbits, /* i : number of core unused bits */ + const Word16 pitch_buf[] /* i : pitch buffer : Q6 */ ) { Word16 i, j, k, nBits, nBits_total, nBits_block, Nsv, Nsv2, width_noncoded; @@ -413,9 +414,9 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB temp4 = add( temp4, t_audio_exp ); FOR( i = 0; i < tmpS; i++ ) { - L_temp = L_mult( alpha, hBWE_FD_HR->t_audio_prev_fx[add( i, ind1 )] ); + L_temp = L_mult( alpha, hBWE_FD_HR->t_audio_prev_fx[i + ind1] ); L_temp = L_shr( L_temp, temp4 ); - t_audio32[add( pos, i )] = L_temp; + t_audio32[pos + i] = L_temp; move32(); } ind1 = add( ind1, tmpS ); @@ -590,17 +591,17 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB IF( EQ_16( ind1, 1 ) ) { - en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT1_FX_Q16 ) ); + en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT1_FX_Q16 ) ); // Q9 } IF( EQ_16( ind1, 2 ) ) { - en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT2_FX_Q16 ) ); + en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT2_FX_Q16 ) ); // Q9 } IF( EQ_16( ind1, 3 ) ) { - en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT3_FX_Q16 ) ); + en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT3_FX_Q16 ) ); // Q9 } } @@ -621,7 +622,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB move16(); FOR( i = 0; i < i_mult( Nsv, WIDTH_BAND ); i++ ) { - t_audio[add( temp, i )] = shl( x_norm[i], t_audio_exp ); + t_audio[temp + i] = shl( x_norm[i], t_audio_exp ); move16(); } @@ -656,7 +657,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* reconstruct 14-16(20) kHz spectrum */ FOR( j = 0; j < tmpS; j++ ) { - *ptr32++ = L_shr( t_audio32[add( pos, j )], 1 ); + *ptr32++ = L_shr( t_audio32[pos + j], 1 ); move32(); } @@ -678,8 +679,8 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB temp2 = add( NUM_TRANS_END_FREQ_COEF_EFF, temp ); j = sub( tmpS, width_noncoded ); - ptr16 = &t_audio[add( temp2, j )]; - ptr32 = &t_audio32[add( temp2, j )]; + ptr16 = &t_audio[temp2 + j]; + ptr32 = &t_audio32[temp2 + j]; /* envelope denormalization of 14.4-16(20) kHz spectrum */ FOR( ; j < tmpS; j++ ) { @@ -763,7 +764,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB FOR( i = 0; i < j; i++ ) { - t_audio[add( temp, i )] = mult_r( t_audio[add( temp, i )], temp2 ); + t_audio[temp + i] = mult_r( t_audio[temp + i], temp2 ); move16(); } } @@ -787,18 +788,18 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB ind2 = (Word16) get_next_indice_fx( st_fx, NBITS_ENVELOPE_BWE_HR2 ); temp = shl( ind1, 1 ); - en_band[0] = swb_hr_env_code1_fx[temp]; + en_band[0] = swb_hr_env_code1_fx[temp]; // Q9 move16(); - en_band[1] = swb_hr_env_code1_fx[temp + 1]; + en_band[1] = swb_hr_env_code1_fx[temp + 1]; // Q9 move16(); temp = shl( ind2, 1 ); - en_band[2] = swb_hr_env_code2_fx[temp]; + en_band[2] = swb_hr_env_code2_fx[temp]; // Q9 move16(); - en_band[3] = swb_hr_env_code2_fx[temp + 1]; + en_band[3] = swb_hr_env_code2_fx[temp + 1]; // Q9 move16(); /*env = add(add(shr(en_band[0], 2), shr(en_band[1], 2)), add(shr(en_band[2], 2), shr(en_band[3], 2)));*/ - env = mac_r( L_mac( L_mac( L_mult( en_band[0], 8192 ), en_band[1], 8192 ), en_band[2], 8192 ), en_band[3], 8192 ); + env = mac_r( L_mac( L_mac( L_mult( en_band[0] /*Q9*/, 8192 /*0.25 in Q15*/ ) /*Q23*/, en_band[1], 8192 ), en_band[2], 8192 ), en_band[3], 8192 ); // Q23 /*---------------------------------------------------------------------* * choose sub-bands to be dequantized @@ -846,19 +847,19 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB if ( EQ_16( ind1, 1 ) ) { /* en_noncoded = BWE_HR_NONTRANS_EN_LIMIT1*(0.5*min_env) ==> 0.25*min_env */ - en_noncoded = mult_r( min_env, BWE_HR_NONTRANS_EN_LIMIT2_FX_Q15 / 2 ); + en_noncoded = mult_r( min_env, BWE_HR_NONTRANS_EN_LIMIT2_FX_Q15 / 2 ); // Q9 } IF( EQ_16( ind1, 2 ) ) { /* en_noncoded = 2.0*BWE_HR_NONTRANS_EN_LIMIT2*(0.5*min_env) ==> 1.2*min_env */ - en_noncoded = round_fx( L_shl( L_mult( BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14, min_env ), 1 ) ); + en_noncoded = round_fx( L_shl( L_mult( BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14, min_env ), 1 ) ); // Q9 } if ( EQ_16( ind1, 3 ) ) { /* en_noncoded = 2.0*BWE_HR_NONTRANS_EN_LIMIT3*(0.5*min_env) ==> 0.8*min_env */ - en_noncoded = mult_r( BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15, min_env ); + en_noncoded = mult_r( BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15, min_env ); // Q9 } } @@ -954,7 +955,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB { L_temp = L_mult( gain2_fx, *ptr16++ ); L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ - t_audio_tmp[add( temp, j )] = round_fx( L_temp ); + t_audio_tmp[temp + j] = round_fx( L_temp ); } /* 'nq[i] = add(nq[i], nq2[incr])' replaced by 'nq[i] = nq2[incr]' because 'nq[i] == 0' */ nq[i] = nq2[incr]; @@ -978,9 +979,9 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB FOR( j = 0; j < WIDTH_BAND; j++ ) { L_temp = L_mult( gain2_fx, *ptr16++ ); - L_temp = L_msu( L_temp, t_audio_tmp[add( temp, j )], temp3 ); /* go to -Q't_audio' */ - L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ - t_audio_tmp[add( temp, j )] = round_fx( L_temp ); + L_temp = L_msu( L_temp, t_audio_tmp[temp + j], temp3 ); /* go to -Q't_audio' */ + L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ + t_audio_tmp[temp + j] = round_fx( L_temp ); } nq[i] = add( nq[i], nq2[incr] ); move16(); @@ -1043,7 +1044,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB { nq[j] = nq[i]; move16(); - j = j - 1; + j = sub( j, 1 ); } Copy( nq + ind2, nq + ind1, add( WIDTH_BAND, pos ) ); @@ -1271,7 +1272,8 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* Apply global gain */ if ( LE_16( nBits_total, NBITS_THRESH_BWE_HR ) ) { - gain_fx = mult_r( 27853, gain_fx ); /* 0.85 */ + gain_fx = mult_r( 27853, gain_fx ); /* 0.85 in exp_0 */ + // gain_e } ptr32 = &t_audio32[NUM_NONTRANS_START_FREQ_COEF]; @@ -1336,12 +1338,12 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB } ELSE { - st_fx->prev_ener_shb_fx = extract_h( L_shr( L_mult0( gain_fx, env ), 7 ) ); + st_fx->prev_ener_shb_fx = extract_h( L_shr( L_mult0( gain_fx, env ) /*gain_e + (31 - Q23)*/, 7 ) ); /*gain_e + 15*/ move16(); } FOR( i = 0; i < SWB_FENV; i++ ) { - st_fx->prev_SWB_fenv_fx[i] = st_fx->prev_ener_shb_fx; + st_fx->prev_SWB_fenv_fx[i] = st_fx->prev_ener_shb_fx; /*gain_e + 15*/ move16(); } @@ -1512,7 +1514,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB } } - hBWE_FD_HR->L_mem_EnergyLT_fx = L_EnergyLT; + hBWE_FD_HR->L_mem_EnergyLT_fx = L_EnergyLT; // exp_temp4 move32(); hBWE_FD_HR->mem_EnergyLT_fx_exp = temp4; move16(); @@ -1558,7 +1560,6 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB * * Initialize HR BWE state structure at the decoder *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED void hr_bwe_dec_init( HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */ ) @@ -1567,32 +1568,14 @@ void hr_bwe_dec_init( set16_fx( hBWE_FD_HR->t_audio_prev_fx_exp, 0, NUM_TIME_SWITCHING_BLOCKS ); /* one exp per switching block */ hBWE_FD_HR->old_is_transient_hr_bwe_fx = 0; move16(); - hBWE_FD_HR->bwe_highrate_seed_fx = 12345; + hBWE_FD_HR->bwe_highrate_seed_fx = 12345; /*0.75f in Q14*/ move16(); - hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h( 16384 ); + hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h( 16384 ); /*1.0f in Q30*/ move32(); hBWE_FD_HR->mem_EnergyLT_fx_exp = 40; move16(); /* set to a high exponent */ return; } -#else -void hr_bwe_dec_init( - HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */ -) -{ - set16_fx( hBWE_FD_HR->t_audio_prev_fx, 0, 2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_START_FREQ_COEF ); - set16_fx( hBWE_FD_HR->t_audio_prev_fx_exp, 0, NUM_TIME_SWITCHING_BLOCKS ); /* one exp per switching block */ - hBWE_FD_HR->old_is_transient_hr_bwe_fx = 0; - move16(); - hBWE_FD_HR->bwe_highrate_seed_fx = 12345; - move16(); - - hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h( 16384 ); - hBWE_FD_HR->mem_EnergyLT_fx_exp = 40; - move16(); /* set to a high exponent */ - - return; -} #endif diff --git a/lib_dec/swb_bwe_dec_lr_fx.c b/lib_dec/swb_bwe_dec_lr_fx.c index f2aa60a59f60d746c259952292162e17deef0529..b9bb176217997e0b0bc91b6697770dfbbe6177a8 100644 --- a/lib_dec/swb_bwe_dec_lr_fx.c +++ b/lib_dec/swb_bwe_dec_lr_fx.c @@ -15,12 +15,12 @@ *-------------------------------------------------------------------*/ static void DecodeSWBGenericParameters_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *lagIndices_fx, /* o : lowband index for each subband */ - const Word16 nBands_search_fx, /* i : number of subbnads for SSearch */ - const Word16 BANDS_fx, /* i : total number of subbands per frame */ - const Word16 *p2a_flags_fx, /* i : HF tonal flag */ - const Word16 hq_swb_clas_fx /* i : mode of operation HQ_NORMAL or HQ_HARMONIC */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *lagIndices_fx, /* o : lowband index for each subband :Q0 */ + const Word16 nBands_search_fx, /* i : number of subbnads for SSearch :Q0 */ + const Word16 BANDS_fx, /* i : total number of subbands per frame :Q0 */ + const Word16 *p2a_flags_fx, /* i : HF tonal flag :Q0 */ + const Word16 hq_swb_clas_fx /* i : mode of operation HQ_NORMAL or HQ_HARMONIC :Q0 */ ) { Word16 sb; @@ -35,16 +35,15 @@ static void DecodeSWBGenericParameters_fx( } ELSE { - IF( p2a_flags_fx[add( sub( BANDS_fx, NB_SWB_SUBBANDS ), sb )] == 0 ) + IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + sb] == 0 ) { lagIndices_fx[sb] = (Word16) get_next_indice_fx( st_fx, bits_lagIndices_modeNormal[sb] ); - move16(); } ELSE { lagIndices_fx[sb] = 0; - move16(); } + move16(); } } @@ -61,32 +60,32 @@ static void DecodeSWBGenericParameters_fx( *-------------------------------------------------------------------*/ static void DecodeSWBSubbands_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - HQ_DEC_HANDLE hHQ_core, /* i/o: HQ decoder handle */ - Word32 *L_spectra, /* i/o: MDCT domain spectrum */ - Word16 QsL, /* i : Q value of spectra */ - const Word16 fLenLow_fx, /* i : lowband length */ - const Word16 fLenHigh_fx, /* i : highband length */ - const Word16 nBands_fx, /* i : number of subbands */ - const Word16 *sbWidth_fx, /* i : subband lengths */ - const Word16 *subband_offsets_fx, /* i : subband offsets */ - Word16 *lagIndices_fx, /* i : lowband index for each subband */ - Word16 *lagGains_fx, /* i : first gain for each subband */ - Word16 *QlagGains, /* i : Q value of lagGains */ - Word16 BANDS_fx, /* i : number subbands per frame */ - Word16 *band_start_fx, /* i : band start of each SB */ - Word16 *band_end_fx, /* i : band end of each SB */ - Word32 *L_band_energy, /* i : band energy of each SB */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - const Word16 har_bands_fx, /* i : number of LF harmonic bands */ - const Word16 *subband_search_offset_fx, /* i : Number of harmonic LF bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - Word16 band_width_fx[], /* i : subband band widths */ - const Word32 L_spectra_ni[], /* i/o: core coder with sparseness filled */ - Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + HQ_DEC_HANDLE hHQ_core, /* i/o: HQ decoder handle */ + Word32 *L_spectra, /* i/o: MDCT domain spectrum : QsL */ + Word16 QsL, /* i : Q value of spectra */ + const Word16 fLenLow_fx, /* i : lowband length : Q0 */ + const Word16 fLenHigh_fx, /* i : highband length : Q0 */ + const Word16 nBands_fx, /* i : number of subbands : Q0 */ + const Word16 *sbWidth_fx, /* i : subband lengths : Q0 */ + const Word16 *subband_offsets_fx, /* i : subband offsets : Q0 */ + Word16 *lagIndices_fx, /* i : lowband index for each subband : Q0 */ + Word16 *lagGains_fx, /* i : first gain for each subband QlagGains*/ + Word16 *QlagGains, /* i : Q value of lagGains */ + Word16 BANDS_fx, /* i : number subbands per frame : Q0 */ + Word16 *band_start_fx, /* i : band start of each SB : Q0 */ + Word16 *band_end_fx, /* i : band end of each SB : Q0 */ + Word32 *L_band_energy, /* i : band energy of each SB : Q0 */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal indicator : Q0 */ + const Word16 hqswb_clas_fx, /* i : class information : Q0 */ + const Word16 har_bands_fx, /* i : number of LF harmonic bands : Q0 */ + const Word16 *subband_search_offset_fx, /* i : Number of harmonic LF bands : Q0 */ + Word16 *prev_frm_hfe2, /* i/o: : Q0 */ + Word16 *prev_stab_hfe2, /* i/o: : Q0 */ + Word16 band_width_fx[], /* i : subband band widths : Q0 */ + const Word32 L_spectra_ni[], /* i/o: core coder with sparseness filled : QsL */ + Word16 *ni_seed_fx /* i/o: random seed for search buffer NI : Q0 */ ) { Word16 i, k; @@ -179,7 +178,7 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_xSynth_har[sub( i, fLenLow_fx )]; + L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; move32(); /* QsL */ } } @@ -192,7 +191,7 @@ static void DecodeSWBSubbands_fx( convert_lagIndices_pls2smp_fx( lagIndices_fx, nBands_fx, lagIndices_real_fx, sspectra_fx, sbWidth_fx, fLenLow_fx ); FOR( k = 0; k < nBands_fx; k++ ) { - if ( EQ_16( p2a_flags_fx[add( BANDS_fx - NB_SWB_SUBBANDS, k )], 1 ) ) + if ( EQ_16( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k], 1 ) ) { lagIndices_real_fx[k] = 0; move16(); @@ -200,12 +199,12 @@ static void DecodeSWBSubbands_fx( } GetlagGains_fx( sspectra_ni_fx, Qss, - &L_band_energy[sub( BANDS_fx, NB_SWB_SUBBANDS )], Qbe, + &L_band_energy[BANDS_fx - NB_SWB_SUBBANDS], Qbe, nBands_fx, sbWidth_fx, lagIndices_real_fx, fLenLow_fx, lagGains_fx, QlagGains ); FOR( k = 0; k < nBands_fx; k++ ) { - IF( EQ_16( p2a_flags_fx[add( BANDS_fx - NB_SWB_SUBBANDS, k )], 1 ) ) + IF( EQ_16( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k], 1 ) ) { lagGains_fx[k] = 0; move16(); @@ -214,7 +213,7 @@ static void DecodeSWBSubbands_fx( } ELSE { - lagGains_fx[k] = mult_r( lagGains_fx[k], 29491 ); /* lagGains[k]*0.9f; */ + lagGains_fx[k] = mult_r( lagGains_fx[k], 29491 /*0.9f in Q15*/ ); /* lagGains[k]*0.9f; */ move16(); } } @@ -223,7 +222,7 @@ static void DecodeSWBSubbands_fx( { L_th_g[k] = 0; move32(); - IF( p2a_flags_fx[add( BANDS_fx - NB_SWB_SUBBANDS, k )] == 0 ) + IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k] == 0 ) { L_th_g[k] = L_shl( L_mult( lagGains_fx[k], ss_min_fx ), sub( QsL, add( add( QlagGains[k], Qss ), 1 ) ) ); /* QlagGain+Qss -> Qs */ move32(); @@ -244,7 +243,7 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_xSynth_har[sub( i, fLenLow_fx )]; + L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; move32(); /* QsL */ } } @@ -252,7 +251,7 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_spectra_ni[i]; + L_spectra[i] = L_spectra_ni[i]; /* QsL */ move32(); } } @@ -268,26 +267,26 @@ static void DecodeSWBSubbands_fx( * Main decoding routine of SWB BWE for the LR MDCT core *-------------------------------------------------------------------*/ void swb_bwe_dec_lr_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - const Word16 QsL, /* i : Q value of m_core */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Number subbands/Frame */ - Word16 *band_start_fx, /* i : Band Start of each SB */ - Word16 *band_end_fx, /* i : Band end of each SB */ - Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal Indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - Word16 lowlength_fx, /* i : Lowband Length */ - Word16 highlength_fx, /* i : Highband Length */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - Word16 band_width_fx[], /* i : subband bandwidth */ - const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ - Word16 *ni_seed_fx /* i/o: random seed */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 L_m_core[], /* i : lowband synthesis : QsL */ + const Word16 QsL, /* i : Q value of m_core */ + Word32 L_m[], /* o : highband synthesis with lowband zeroed : QsL */ + const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ + Word16 BANDS_fx, /* i : Number subbands/Frame : Q0 */ + Word16 *band_start_fx, /* i : Band Start of each SB : Q0 */ + Word16 *band_end_fx, /* i : Band end of each SB :Q0 */ + Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal Indicator : Q0 */ + const Word16 hqswb_clas_fx, /* i : class information : Q0 */ + Word16 lowlength_fx, /* i : Lowband Length : Q0 */ + Word16 highlength_fx, /* i : Highband Length : Q0 */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands : Q0 */ + Word16 *prev_frm_hfe2, /* i/o: : Q0 */ + Word16 *prev_stab_hfe2, /* i/o: : Q0 */ + Word16 band_width_fx[], /* i : subband bandwidth : Q0 */ + const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ + Word16 *ni_seed_fx /* i/o: random seed : QsL */ ) { Word16 k; diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index c519d51b1231798c1a39ff6741476c972c718006..3c788e784ae4870a75f83246e112d787d06f5a57 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -466,10 +466,10 @@ void wb_tbe_dec( } #else static void calc_tilt_bwe_fx_loc( - const Word32 *sp_fx, /* i : input signal */ - Word32 *tilt_fx, /* o : signal tilt */ - Word16 *tilt_fx_q, /* o : signal tilt */ - const Word16 N /* i : signal length */ + const Word32 *sp_fx, /* i : input signal : Q11 */ + Word32 *tilt_fx, /* o : signal tilt : tilt_fx_q */ + Word16 *tilt_fx_q, /* o : signal tilt */ + const Word16 N /* i : signal length : Q0 */ ) { Word16 i; @@ -479,14 +479,14 @@ static void calc_tilt_bwe_fx_loc( move64(); FOR( i = 0; i < N; i++ ) { - r0_fx = W_add( r0_fx, W_shr( W_mult_32_32( sp_fx[i], sp_fx[i] ), 1 ) ); + r0_fx = W_add( r0_fx, W_shr( W_mult_32_32( sp_fx[i], sp_fx[i] ), 1 ) ); /*Q11*2 - 1*/ } - r1_fx = W_deposit32_l( abs( L_sub( sp_fx[1], sp_fx[0] ) ) ); + r1_fx = W_deposit32_l( abs( L_sub( sp_fx[1], sp_fx[0] ) ) ); /*Q11*/ FOR( i = 2; i < N; i++ ) { - IF( W_mult_32_32( L_sub( sp_fx[i], sp_fx[i - 1] ), L_sub( sp_fx[i - 1], sp_fx[i - 2] ) ) < 0 ) + IF( W_mult_32_32( L_sub( sp_fx[i], sp_fx[i - 1] ) /*Q11*/, L_sub( sp_fx[i - 1], sp_fx[i - 2] ) /*Q11*/ ) /*Q11 * 2 - 1*/ < 0 ) { - r1_fx = W_add( r1_fx, W_deposit32_l( abs( L_sub( sp_fx[i], sp_fx[i - 1] ) ) ) ); + r1_fx = W_add( r1_fx, W_deposit32_l( abs( L_sub( sp_fx[i], sp_fx[i - 1] ) ) ) ); /*Q11*/ } } Word16 headroom_left_r0 = W_norm( r0_fx ); @@ -494,7 +494,6 @@ static void calc_tilt_bwe_fx_loc( Word16 r0_q = 0, r1_q = 0; move16(); move16(); - // Word16 r0_bits_occ = 0, r1_bits_occ = 0; IF( LT_16( headroom_left_r0, 32 ) ) { r0_fx = W_shr( r0_fx, sub( 32, headroom_left_r0 ) ); @@ -553,7 +552,8 @@ static void calc_tilt_bwe_fx_loc( *-------------------------------------------------------------------*/ static void rescale_genSHB_mem_dec( Decoder_State *st_fx, - Word16 sf ) + Word16 sf /*Q0*/ +) { Word16 i; TD_BWE_DEC_HANDLE hBWE_TD; @@ -598,8 +598,8 @@ static void rescale_genSHB_mem_dec( static void gradientGainShape( Decoder_State *st_fx, - Word16 *GainShape_fx, - Word32 *GainFrame_fx ) + Word16 *GainShape_fx, /*Q15*/ + Word32 *GainFrame_fx /* Q18 */ ) { Word16 i, j, tmp; Word16 GainShapeTemp[NUM_SHB_SUBFR / 4]; @@ -617,7 +617,7 @@ static void gradientGainShape( move16(); /* Q14 */ GainGrad1[j] = sub( shr( st_fx->GainShape_Delay[j + 5], 1 ), shr( st_fx->GainShape_Delay[j + 4], 1 ) ); move16(); /* Q14 */ - GainGradFEC[j + 1] = add( mult_r( GainGrad0[j], 13107 ), mult_r( GainGrad1[j], 19660 ) ); + GainGradFEC[j + 1] = add( mult_r( GainGrad0[j], 13107 /*0.4f in Q15*/ ), mult_r( GainGrad1[j], 19660 /*0.6f in Q15*/ ) ); move16(); /* Q14 */ } @@ -628,14 +628,14 @@ static void gradientGainShape( IF( ( ( GT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( GT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) || ( ( LT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( LT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) ) { - GainGradFEC[0] = add( mult_r( GainGrad1[1], 3277 ), mult_r( GainGrad1[2], 29490 ) ); + GainGradFEC[0] = add( mult_r( GainGrad1[1], 3277 /*0.1f in Q15*/ ), mult_r( GainGrad1[2], 29490 /*0.9f in Q15*/ ) ); move16(); /* Q14 */ } ELSE { - GainGradFEC[0] = add( mult_r( GainGrad1[0], 6553 ), mult_r( GainGrad1[1], 9830 ) ); + GainGradFEC[0] = add( mult_r( GainGrad1[0], 6553 /*0.2f in Q15*/ ), mult_r( GainGrad1[1], 9830 /*0.3f in Q15*/ ) ); move16(); - GainGradFEC[0] = add( GainGradFEC[0], mult_r( GainGrad1[2], 16384 ) ); + GainGradFEC[0] = add( GainGradFEC[0], mult_r( GainGrad1[2], 16384 /*0.5f in Q15*/ ) ); move16(); /* Q14 */ } @@ -649,7 +649,7 @@ static void gradientGainShape( } ELSE IF( GainGradFEC[0] > 0 ) { - GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), mult_r( GainGradFEC[0], 16384 ) ); + GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), mult_r( GainGradFEC[0], 16384 /*0.5f in Q15*/ ) ); move16(); /* Q14 */ } ELSE @@ -668,7 +668,7 @@ static void gradientGainShape( { FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { - GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 26214 ) ); + GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 26214 /*0.8f in Q15*/ ) ); move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); move16(); @@ -681,7 +681,7 @@ static void gradientGainShape( { FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { - GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 6553 ) ); + GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 6553 /*0.2f in Q15*/ ) ); move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); move16(); /* Q14 */ @@ -709,17 +709,17 @@ static void gradientGainShape( { FOR( j = 0; j < 4; j++ ) { - tmp = mult_r( GainShapeTemp[i], 19660 ); /* GainShapeTemp[i]*0.6 */ + tmp = mult_r( GainShapeTemp[i], 19660 /*0.6f Q15*/ ); /* GainShapeTemp[i]*0.6 */ IF( GT_16( 8192, tmp ) ) { - GainShape_fx[add( i * 4, j )] = shl( tmp, 2 ); - move16(); /* (GainShapeTemp[i]*0.6)>>1 */ + GainShape_fx[i * 4 + j] = shl( tmp, 2 ); /*Q15*/ + move16(); /* (GainShapeTemp[i]*0.6)>>1 */ } ELSE { - GainShape_fx[add( i * 4, j )] = 32767; - move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ + GainShape_fx[i * 4 + j] = 32767; /*Q15*/ + move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ } } } @@ -734,17 +734,17 @@ static void gradientGainShape( { IF( LT_16( GainShapeTemp[i], 16384 ) ) { - GainShape_fx[add( i * 4, j )] = shl( GainShapeTemp[i], 1 ); + GainShape_fx[i * 4 + j] = shl( GainShapeTemp[i], 1 ); /*Q15*/ move16(); } ELSE { - GainShape_fx[add( i * 4, j )] = 32767; + GainShape_fx[i * 4 + j] = 32767; // 1.0f in Q15 move16(); } } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 /*0.95f in Q15*/ ); /*Q15*/ move16(); } ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) @@ -753,11 +753,11 @@ static void gradientGainShape( { FOR( j = 0; j < 4; j++ ) { - GainShape_fx[add( i * 4, j )] = GainShapeTemp[i]; + GainShape_fx[i * 4 + j] = GainShapeTemp[i]; /*Q15*/ move16(); } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 /*0.5f in Q15*/ ); /*Q15*/ move16(); } ELSE @@ -768,17 +768,17 @@ static void gradientGainShape( { IF( LT_16( GainShapeTemp[i], 16384 ) ) { - GainShape_fx[add( i * 4, j )] = shl( GainShapeTemp[i], 1 ); + GainShape_fx[i * 4 + j] = shl( GainShapeTemp[i], 1 ); /*Q15*/ move16(); } ELSE { - GainShape_fx[add( i * 4, j )] = 32767; + GainShape_fx[i * 4 + j] = 32767; /*Q15*/ move16(); } } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 /*0.85f in Q15*/ ); /*Q15*/ move16(); } @@ -1012,15 +1012,15 @@ void find_max_mem_dec_m3( * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module *-------------------------------------------------------------------*/ void ivas_swb_tbe_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation */ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ Word16 Q_exc, - const Word16 voice_factors_fx[], /* i : voicing factors */ - const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE */ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis */ - Word16 *pitch_buf_fx, + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis : old_syn_fx */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word16 *pitch_buf_fx, /* i : Q6 */ Word16 *Q_white_exc ) { Word16 i, j, cnt, n; @@ -1136,7 +1136,7 @@ void ivas_swb_tbe_dec_fx( /* WB/SWB bandwidth switching */ test(); test(); - IF( ( GT_16( st->tilt_wb_fx, 10240 ) && ( st->clas_dec == UNVOICED_CLAS ) ) || GT_16( st->tilt_wb_fx, 20480 ) ) + IF( ( GT_16( st->tilt_wb_fx, 10240 /*5 in Q11*/ ) && ( EQ_16( st->clas_dec, UNVOICED_CLAS ) ) ) || GT_16( st->tilt_wb_fx, 20480 /*10 in Q11*/ ) ) { test(); test(); @@ -1155,21 +1155,20 @@ void ivas_swb_tbe_dec_fx( ) { is_fractive = 0; - move16(); } ELSE { is_fractive = 1; - move16(); } + move16(); } /* WB/SWB bandwidth switching */ IF( st->bws_cnt > 0 ) { - f_fx = 1489; /*Q15*/ + f_fx = 1489; /*1.0f / 22.0f in Q15*/ move16(); - inc_fx = 1489; /*Q15*/ + inc_fx = 1489; /*1.0f / 22.0f in Q15*/ move16(); IF( EQ_16( is_fractive, 1 ) ) @@ -1180,9 +1179,9 @@ void ivas_swb_tbe_dec_fx( { FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/ move16(); - f_fx = add( f_fx, inc_fx ); + f_fx = add( f_fx, inc_fx ); /*Q15*/ } } test(); @@ -1194,13 +1193,13 @@ void ivas_swb_tbe_dec_fx( test(); IF( ( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) && !( ( L_sub( L_shr( st->prev_enerLH_fx, 1 ), st->enerLH_fx ) < 0 ) && L_sub( st->prev_enerLH_fx, ( L_shr( st->enerLH_fx, 1 ) > 0 ) ) ) ) || st->last_core != ACELP_CORE || ( ( st->last_core == ACELP_CORE ) && GT_32( abs( L_sub( st->last_core_brate, st->core_brate ) ), 3600 ) ) || EQ_16( s_xor( is_fractive, st->prev_fractive ), 1 ) ) { - set16_fx( GainShape_fx, 11587, NUM_SHB_SUBFR ); + set16_fx( GainShape_fx, 11587, NUM_SHB_SUBFR ); /*0.3536f in Q15*/ } ELSE { - if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) + if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) /*0.3536f in Q15*/ { - hBWE_TD->prev_GainShape_fx = 11587; + hBWE_TD->prev_GainShape_fx = 11587; /*0.3536f in Q15*/ move16(); } set16_fx( GainShape_fx, hBWE_TD->prev_GainShape_fx, NUM_SHB_SUBFR ); @@ -1220,7 +1219,7 @@ void ivas_swb_tbe_dec_fx( move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/ move16(); f_fx = add( f_fx, inc_fx ); } @@ -1240,9 +1239,9 @@ void ivas_swb_tbe_dec_fx( move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/ move16(); - f_fx = add( f_fx, inc_fx ); + f_fx = add( f_fx, inc_fx ); /*Q15*/ } } Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb_fx, LPC_SHB_ORDER ); @@ -1267,7 +1266,7 @@ void ivas_swb_tbe_dec_fx( test(); IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) && !st->prev_use_partial_copy && EQ_16( st->prev_coder_type, UNVOICED ) && NE_32( GainFrame_fx, hBWE_TD->GainFrame_prevfrm_fx ) && NE_16( st->next_coder_type, GENERIC ) && EQ_16( st->last_extl, SWB_TBE ) ) { - GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame_fx, 6553 ) ); + GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame_fx, 6553 /*0.2f in Q15*/ ) ); } } ELSE @@ -1323,13 +1322,14 @@ void ivas_swb_tbe_dec_fx( IF( EQ_16( st->last_extl, SWB_TBE ) ) { GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp_fx ), Mult_32_16( GainFrame_fx, sub( 32767, temp_fx ) ) ); + /*Q18*/ } IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) ) { - if ( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, VOICED ) && EQ_16( st->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame_fx, 2097152 ) && LT_32( GainFrame_fx, 3059606 ) ) + if ( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, VOICED ) && EQ_16( st->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame_fx, 2097152 /*8.0f in Q18*/ ) && LT_32( GainFrame_fx, 3059606 /*11.67f in Q18*/ ) ) { - GainFrame_fx = Mult_32_16( GainFrame_fx, 9830 ); + GainFrame_fx = Mult_32_16( GainFrame_fx, 9830 /*0.3f in Q15*/ ); // Q18 } } } @@ -1360,7 +1360,7 @@ void ivas_swb_tbe_dec_fx( { FOR( j = 0; j < 4; j++ ) { - GainShape_fx[add( i * 4, j )] = mult_r( st->cummulative_damping, st->GainShape_Delay[4 + i] ); + GainShape_fx[i * 4 + j] = mult_r( st->cummulative_damping, st->GainShape_Delay[4 + i] ); move16(); } } @@ -1464,7 +1464,7 @@ void ivas_swb_tbe_dec_fx( Copy( &st->GainShape_Delay[4], &st->GainShape_Delay[0], NUM_SHB_SUBFR / 4 ); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - st->GainShape_Delay[i + 4] = GainShape_fx[i * 4]; + st->GainShape_Delay[i + 4] = GainShape_fx[i * 4]; /*Q15*/ move16(); } @@ -1862,8 +1862,8 @@ void ivas_swb_tbe_dec_fx( FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation_fx[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ move16(); } IF( exp < 0 ) @@ -1883,8 +1883,8 @@ void ivas_swb_tbe_dec_fx( #endif temp_fx = sub( 32767 /*1.0f Q15*/, temp_fx ); Lscale = L_add( Mult_32_16( Lscale, temp_fx ), L_tmp1 ); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation_fx[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ move16(); } } @@ -2140,9 +2140,9 @@ void ivas_swb_tbe_dec_fx( IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) && ( ( EQ_16( st->codec_mode, MODE1 ) && GT_32( st->enerLL_fx, st->prev_enerLL_fx ) && GT_32( st->enerLH_fx, st->prev_enerLH_fx ) ) || EQ_16( st->codec_mode, MODE2 ) ) ) { test(); - IF( GT_16( tilt_swb_fec_fx, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) + IF( GT_16( tilt_swb_fec_fx, 20480 /*10.0f in Q11*/ ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 /*10.0f in Q11*/ ) ) { - GainFrame_fx = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame_fx, 6554 ) ), L_shl( Mult_32_16( GainFrame_fx, 16384 ), 3 ) ); /*Q18*/ + GainFrame_fx = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame_fx, 6554 /*0.2f in Q15*/ ) ), L_shl( Mult_32_16( GainFrame_fx, 16384 /*4.0f in Q12*/ ), 3 ) ); /*Q18*/ } ELSE { @@ -2154,11 +2154,11 @@ void ivas_swb_tbe_dec_fx( test(); IF( GT_16( tilt_swb_fec_fx, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) { - GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame_fx, 16384 ) ); + GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 /*0.5f in Q15*/ ), Mult_32_16( GainFrame_fx, 16384 /*0.5f in Q15*/ ) ); /* Q18 */ } ELSE { - GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame_fx, 26214 ) ); + GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 /*0.2f in Q15*/ ), Mult_32_16( GainFrame_fx, 26214 /*0.8f in Q15*/ ) ); /* Q18 */ } } } @@ -2446,7 +2446,7 @@ void ivas_swb_tbe_dec_fx( { GainShape_fx[2 * j] = mult_r( GainShape_fx[2 * j], scale_fx ); move16(); - GainShape_fx[add( 2 * j, 1 )] = mult_r( GainShape_fx[add( 2 * j, 1 )], scale_fx ); + GainShape_fx[2 * j + 1] = mult_r( GainShape_fx[2 * j + 1], scale_fx ); move16(); FOR( i = 0; i < L_FRAME16k / 8; i++ ) { @@ -2573,7 +2573,7 @@ void ivas_swb_tbe_dec_fx( move16(); FOR( i = 0; i < 40; i++ ) { - shaped_shb_excitation_fx[add( i, j * 40 )] = shl( mult_r( shaped_shb_excitation_fx[add( i, j * 40 )], scale_fx ), 3 ); + shaped_shb_excitation_fx[i + j * L_FRAME16k / 8] = shl( mult_r( shaped_shb_excitation_fx[i + j * L_FRAME16k / 8], scale_fx ), 3 ); move16(); /* Q_bwe_exc +12+3 -15 =Q_bwe_exc*/ } @@ -2772,7 +2772,7 @@ void ivas_swb_tbe_dec_fx( if ( !st->bfi ) { - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*1.0f in Q15*/ move16(); } } @@ -2784,7 +2784,7 @@ void ivas_swb_tbe_dec_fx( move32(); /*Q18*/ hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec_fx; move16(); - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*1.0f in Q15*/ move16(); } } @@ -4565,12 +4565,12 @@ void GenTransition( #ifdef IVAS_FLOAT_FIXED void GenTransition_fixed( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word16 element_mode, /* i : element mode */ - const Word16 L_frame, /* i : ACELP frame length */ - const Word16 rf_flag, /* i : RF flag */ - const Word32 total_brate, /* i : total bitrate */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ + const Word32 output_Fs, /* i : output sampling rate : Q0 */ + const Word16 element_mode, /* i : element mode : Q0 */ + const Word16 L_frame, /* i : ACELP frame length : Q0 */ + const Word16 rf_flag, /* i : RF flag : Q0 */ + const Word32 total_brate, /* i : total bitrate : Q0 */ const Word16 prev_Qx ) { Word16 i, length; @@ -4578,7 +4578,7 @@ void GenTransition_fixed( Word32 syn_overlap_32k_fx[2 * SHB_OVERLAP_LEN]; /* set targeted length of transition signal */ - length = i_mult( 2, NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ) ); + length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) ); /* upsample overlap snippet */ Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, SHB_OVERLAP_LEN, syn_overlap_32k_fx ); @@ -4599,13 +4599,12 @@ void GenTransition_fixed( IF( i % 2 == 0 ) { syn_overlap_32k_fx[i] = L_negate( syn_overlap_32k_fx[i] ); - move32(); } ELSE { syn_overlap_32k_fx[i] = syn_overlap_32k_fx[i]; - move32(); } + move32(); } } @@ -4697,7 +4696,7 @@ void GenTransition_WB( #ifdef IVAS_FLOAT_FIXED void GenTransition_WB_fixed( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ const Word32 output_Fs /* i : output sampling rate */ ) { @@ -4706,7 +4705,7 @@ void GenTransition_WB_fixed( Word32 upsampled_synth_fx[L_FRAME48k]; /* set targeted length of transition signal */ - length = i_mult( 2, NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ) ); + length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) ); /* upsample overlap snippet */ Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->state_lsyn_filt_shb_fx_32, SHB_OVERLAP_LEN / 2, speech_buf_16k1_fx ); diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 1701bfdbf4bff9344243d9cae7d8869e6c63e424..cb3ae52a8f466df02fc8eb9c40328586f5512f8b 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -633,11 +633,11 @@ void ResetSHBbuffer_Dec_fx( Decoder_State *st_fx /* i/o: SHB encoder structure * /*==========================================================================*/ void ivas_wb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ + const Word16 coder_type, /* i : coding type Q0 */ Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ const Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - Word16 *synth, /* o : WB synthesis/final synthesis */ + const Word16 voice_factors[], /* i : voicing factors Q15 */ + Word16 *synth, /* o : WB synthesis/final synthesis Q_synth */ Word16 *Q_synth ) { Word16 i; @@ -716,7 +716,7 @@ void ivas_wb_tbe_dec_fx( IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && EQ_16( st_fx->last_extl, WB_TBE ) ) { /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); + GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx /*Q18*/, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame /*Q18*/, 6553 /*0.2f in Q15*/ ) /*Q18+Q15 - 15*/ ); /*Q18*/ } } ELSE @@ -782,7 +782,7 @@ void ivas_wb_tbe_dec_fx( test(); IF( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && LT_16( st_fx->prev_tilt_code_dec_fx, 1497 ) && GT_16( st_fx->prev_tilt_code_dec_fx, 200 ) ) { - GainFrame = Mult_32_16( GainFrame, 9830 ); + GainFrame = Mult_32_16( GainFrame, 9830 /*0.3f in Q15*/ ); /*Q18*/ } } } @@ -806,12 +806,12 @@ void ivas_wb_tbe_dec_fx( } set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27853 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27853 /*0.85f in Q15*/ ); /*Q15*/ move16(); IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { - GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /*Q18*/ + GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx /*Q18*/, hBWE_TD->GainAttn_fx /*Q15*/ ); /*Q15+Q18-15*/ } ELSE { @@ -835,7 +835,7 @@ void ivas_wb_tbe_dec_fx( lpc_wb[i] = negate( lpc_wb[i] ); move16(); } - lpc_wb[0] = 4096; + lpc_wb[0] = 4096; /*1.0f in Q12*/ move16(); } ELSE @@ -852,7 +852,7 @@ void ivas_wb_tbe_dec_fx( lpc_wb[i] = negate( lpc_wb[i] ); move16(); } - lpc_wb[0] = 4096; + lpc_wb[0] = 4096; /*1.0f in Q12*/ move16(); } @@ -955,7 +955,11 @@ void ivas_wb_tbe_dec_fx( #endif FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { +#ifdef BASOP_NOGLOB + curr_pow = L_mac0_sat( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ +#else curr_pow = L_mac0( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ +#endif } if ( GT_16( voice_factors[0], 24576 ) ) @@ -972,7 +976,7 @@ void ivas_wb_tbe_dec_fx( #ifdef BASOP_NOGLOB shaped_wb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ #else - shaped_wb_excitation[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ + shaped_wb_excitation[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ #endif move16(); } @@ -1014,7 +1018,7 @@ void ivas_wb_tbe_dec_fx( shaped_wb_excitation_frac[i] = shl_o( shaped_wb_excitation[i], n, &Overflow ); /*Q14*/ move16(); #else - shaped_wb_excitation_frac[i] = shl( shaped_wb_excitation[i], n ); /*Q14*/ + shaped_wb_excitation_frac[i] = shl( shaped_wb_excitation[i], n ); /*Q14*/ move16(); #endif } @@ -1183,7 +1187,7 @@ void ivas_wb_tbe_dec_fx( FOR( i = 0; i < L_FRAME16k; i++ ) { - synth[i] = mult_r( error[i], 21299 ); + synth[i] = mult_r( error[i], 21299 /*0.65f in Q15*/ ); move16(); } @@ -1226,8 +1230,12 @@ void ivas_wb_tbe_dec_fx( #endif exp = sub( add( exp, 22 ), 30 ); tmp = div_s( 16384, tmp ); - L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ + L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ +#ifdef BASOP_NOGLOB + st_fx->last_wb_bwe_ener_fx = round_fx_sat( L_shl_sat( L_tmp, add( exp, sub( n, 12 ) ) ) ); /* Q3 */ +#else st_fx->last_wb_bwe_ener_fx = round_fx( L_shl( L_tmp, add( exp, sub( n, 12 ) ) ) ); /* Q3 */ +#endif move16(); } @@ -1368,11 +1376,11 @@ void wb_tbe_dec_fx( move16(); FOR( i = 1; i < LPC_SHB_ORDER_LBR_WB; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = add( hBWE_TD->lsp_prevfrm_fx[i - i], 3277 /*0.1f Q15*/ ); + hBWE_TD->lsp_prevfrm_fx[i] = add( hBWE_TD->lsp_prevfrm_fx[i - i], 3277 /*0.1f Q15*/ ); /*Q15*/ move16(); } } - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) ) @@ -1389,7 +1397,7 @@ void wb_tbe_dec_fx( IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && EQ_16( st_fx->last_extl, WB_TBE ) ) { /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); + GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); /*Q18*/ } } ELSE @@ -1455,7 +1463,7 @@ void wb_tbe_dec_fx( test(); IF( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && LT_16( st_fx->prev_tilt_code_dec_fx, 1497 ) && GT_16( st_fx->prev_tilt_code_dec_fx, 200 ) ) { - GainFrame = Mult_32_16( GainFrame, 9830 ); + GainFrame = Mult_32_16( GainFrame, 9830 ); /*Q18*/ } } } @@ -1470,11 +1478,11 @@ void wb_tbe_dec_fx( { IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ } ELSE { - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_WB ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_WB ); /*Q15*/ } set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); @@ -1963,18 +1971,18 @@ void wb_tbe_dec_fx( /* Update previous frame parameters for FEC */ IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { - Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_LBR_WB ); + Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ } ELSE { - Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_WB ); + Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_WB ); /*Q15*/ } hBWE_TD->GainFrame_prevfrm_fx = GainFrame; /* Q18 */ move32(); IF( !st_fx->bfi ) { - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); } @@ -3734,7 +3742,7 @@ void swb_tbe_dec_fx( if ( !st_fx->bfi ) { - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); } } @@ -3746,7 +3754,7 @@ void swb_tbe_dec_fx( move16(); /*Q18*/ hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; move16(); - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); } } @@ -3962,7 +3970,7 @@ static void gradientGainShape( static void Dequant_lower_LSF_fx( const Word16 lsf_idx[], /* i : LSF indices */ - Word16 lsf_q[] /* o : Quantized LSFs */ + Word16 lsf_q[] /* o : Quantized LSFs Q15*/ ) { Word16 i; @@ -3971,7 +3979,7 @@ static void Dequant_lower_LSF_fx( move16(); FOR( i = 1; i < NUM_Q_LSF; i++ ) { - lsf_q[i] = add( lsf_q_cb_fx[i][lsf_idx[i]], lsf_q[i - 1] ); + lsf_q[i] = add( lsf_q_cb_fx[i][lsf_idx[i]], lsf_q[i - 1] ); /*Q15*/ move16(); } @@ -3985,9 +3993,10 @@ static void Dequant_lower_LSF_fx( *-------------------------------------------------------------------*/ static void Map_higher_LSF_fx( - Word16 lsf_q[], /* i/o : Quantized lower LSFs */ - const Word16 m, /* i : Mirroring point */ - const Word16 grid_in[] /* i : Input LSF smoohthing grid */ ) + Word16 lsf_q[], /* i/o : Quantized lower LSFs Q15*/ + const Word16 m, /* i : Mirroring point Q15*/ + const Word16 grid_in[] /* i : Input LSF smoohthing grid Q15*/ +) { Word16 lsf_map[NUM_MAP_LSF]; Word16 grid[NUM_MAP_LSF]; @@ -3999,42 +4008,42 @@ static void Map_higher_LSF_fx( FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_map[i] = sub( shl( m, 1 ), lsf_q[NUM_MAP_LSF - 1 - i] ); + lsf_map[i] = sub( shl( m, 1 ), lsf_q[NUM_MAP_LSF - 1 - i] ); /*Q15*/ move16(); } IF( GT_16( m, MAX_LSF_FX_BY_2 ) ) { - offset = lsf_map[0]; + offset = lsf_map[0]; /*Q15*/ move16(); scale = div_s( sub( MAX_LSF_FX, m ), m ); FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_map[i] = add( mult_r( sub( lsf_map[i], offset ), scale ), offset ); + lsf_map[i] = add( mult_r( sub( lsf_map[i], offset ), scale ), offset ); /*Q15*/ move16(); } } - last_q_lsf = lsf_q[NUM_Q_LSF - 1]; + last_q_lsf = lsf_q[NUM_Q_LSF - 1]; /*Q15*/ move16(); scale = sub( MAX_LSF_FX, last_q_lsf ); FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - grid[i] = add( mult_r( grid_in[i], scale ), last_q_lsf ); + grid[i] = add( mult_r( grid_in[i], scale ), last_q_lsf ); /*Q15*/ move16(); } FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_smooth[i] = sub( mult_r( grid_smoothing_fx[i], grid[i] ), - mult_r( lsf_map[i], add( grid_smoothing_fx[i], -32768 /*-1.0f Q15*/ ) ) ); + lsf_smooth[i] = sub( mult_r( grid_smoothing_fx[i], grid[i] ) /*Q15*/, + mult_r( lsf_map[i], add( grid_smoothing_fx[i], -32768 /*-1.0f Q15*/ /*Q15*/ ) ) ); /*Q15*/ move16(); } FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; + lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; /*Q15*/ move16(); } @@ -4043,40 +4052,41 @@ static void Map_higher_LSF_fx( static void Dequant_mirror_point_fx( - const Word16 lsf_q[], /* i/o : Quantized lower LSFs */ - const Word16 m_idx, - /* i : Mirror point index */ Word16 *m /* i : Mirroring point */ ) + const Word16 lsf_q[], /* i/o : Quantized lower LSFs Q15*/ + const Word16 m_idx, /* i : Mirror point index Q0 */ + Word16 *m /* i : Mirroring point Q15*/ +) { - *m = add( mirror_point_q_cb_fx[m_idx], lsf_q[NUM_Q_LSF - 1] ); + *m = add( mirror_point_q_cb_fx[m_idx], lsf_q[NUM_Q_LSF - 1] ); /*Q15*/ move16(); return; } Word16 dotp_loc( - const Word16 x[], /* i : vector x[] */ - const Word32 y[], /* i : vector y[] */ + const Word16 x[], /* i : vector x[] Qx */ + const Word32 y[], /* i : vector y[] Qy */ const Word16 n /* i : vector length */ ) { Word16 i; Word32 suma; Word16 guarded_bits = find_guarded_bits_fx( n ); - suma = L_shr( Mpy_32_16_1( y[0], x[0] ), guarded_bits ); + suma = L_shr( Mpy_32_16_1( y[0], x[0] ), guarded_bits ); /*Qx + Qy - guarded_bits*/ FOR( i = 1; i < n; i++ ) { - suma = L_add( suma, L_shr( Mpy_32_16_1( y[i], x[i] ), guarded_bits ) ); + suma = L_add( suma, L_shr( Mpy_32_16_1( y[i], x[i] ), guarded_bits ) ); /*Qx + Qy - guarded_bits*/ } - suma = L_shl_sat( suma, guarded_bits ); + suma = L_shl_sat( suma, guarded_bits ); /*Qx + Qy*/ - return extract_h( suma ); + return extract_h( suma ); /*Qx + Qy - 16*/ } void ivas_dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, - const Word16 extl, /* i : extension layer */ - Word32 extl_brate, /* i : extensiuon layer bitrate */ - Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ + const Word16 extl, /* i : extension layer */ + Word32 extl_brate, /* i : extensiuon layer bitrate */ + Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ Word16 *Q_subgain, /* o : SHB subframe gains from de-quantization Q15*/ Word32 *Q_framegrain, /* o : SHB frame gain from de-quantization Q18*/ Word16 *uv_flag, /* o : unvoiced flag*/ @@ -4273,13 +4283,10 @@ void ivas_dequantizeSHBparams_fx_9_1( *Q_mixFactors = 0; move16(); } - //*Q_mixFactors = 0; set16_fx( Q_shb_res_gshape, 0, 5 ); } /* LSFs */ - - test(); test(); test(); @@ -4319,13 +4326,13 @@ void ivas_dequantizeSHBparams_fx_9_1( set16_fx( lsf_q, 0, LPC_SHB_ORDER ); /* VQ part */ - num_bits_lvq = config_LSF_BWE[i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 )]; + num_bits_lvq = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3]; Idx = get_next_indice_fx( st_fx, num_bits_lvq ); v_add_16( lsf_q, cb_stage + i_mult( Idx, 6 ), lsf_q, 6 ); /* MSLVQ part */ - num_bits_lvq = sub( sub( nbits, num_bits_lvq ), config_LSF_BWE[add( i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 ), 2 )] ); - predictor_bits = config_LSF_BWE[add( i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 ), 2 )]; + num_bits_lvq = sub( sub( nbits, num_bits_lvq ), config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2] ); + predictor_bits = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2]; Idx_pred = 0; move16(); @@ -4356,9 +4363,9 @@ void ivas_dequantizeSHBparams_fx_9_1( ELSE { Idx_pred = (Word16) get_next_indice_fx( st_fx, 1 ); - lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[i_mult( 2 * ( LATTICE_DIM + 1 ), Idx_pred )], LATTICE_DIM ); + lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred], LATTICE_DIM ); move16(); - lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[add( i_mult( 2 * ( LATTICE_DIM + 1 ), Idx_pred ), LATTICE_DIM + 1 )], LATTICE_DIM ); + lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred + LATTICE_DIM + 1], LATTICE_DIM ); move16(); } @@ -4533,15 +4540,15 @@ void ivas_dequantizeSHBparams_fx_9_1( static void dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, - const Word16 extl, /* i : extension layer */ - Word32 extl_brate, /* i : extensiuon layer bitrate */ - Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ + const Word16 extl, /* i : extension layer */ + Word32 extl_brate, /* i : extensiuon layer bitrate */ + Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ Word16 *Q_subgain, /* o : SHB subframe gains from de-quantization Q15*/ Word32 *Q_framegrain, /* o : SHB frame gain from de-quantization Q18*/ Word16 *uv_flag, /* o : unvoiced flag*/ - Word32 *Q_shb_ener_sf, /* o : Q15 */ - Word16 *Q_shb_res_gshape, /* o : Q14 */ - Word16 *Q_mixFactors /* o : Q15 */ + Word32 *Q_shb_ener_sf, /* o : Q15*/ + Word16 *Q_shb_res_gshape, /* o : Q14*/ + Word16 *Q_mixFactors /* o : Q15*/ ) { Word16 i, j, idxLSF, idxSubGain, idxFrameGain; @@ -4833,10 +4840,10 @@ static void dequantizeSHBparams_fx_9_1( * FB TBE decoder, 14(resp. 15.5) - 20 kHz band decoding module *-------------------------------------------------------------------*/ void fb_tbe_dec_fx( - Decoder_State *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ + Decoder_State *st, /* i/o: encoder state structure */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, - Word16 *hb_synth, /* o : high-band synthesis */ + Word16 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ Word16 hb_synth_exp ) { @@ -4895,11 +4902,11 @@ void fb_tbe_dec_fx( void fb_tbe_dec_ivas_fx( Decoder_State *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, - Word32 *hb_synth, /* o : high-band synthesis */ + Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ Word16 hb_synth_exp, - Word16 *fb_synth_ref, + Word16 *fb_synth_ref, /*Q_fb_synth_ref*/ Word16 Q_fb_synth_ref, Word16 output_frame ) @@ -4970,7 +4977,7 @@ void fb_tbe_dec_ivas_fx( FOR( i = 0; i < L_FRAME48k; i++ ) { // hb_synth[i] = L_add( hb_synth[i], L_deposit_l(fb_synth[i])); - hb_synth[i] = L_add( hb_synth[i], L_shl( fb_synth[i], Q11 ) ); + hb_synth[i] = L_add( hb_synth[i], L_shl( fb_synth[i], Q11 ) ); // hb_synth_exp move16(); } return; @@ -5091,12 +5098,12 @@ void tbe_read_bitstream_fx( * switching from TBE to IGF *---------------------------------------------------------------------*/ void GenTransition_fx( - const Word16 *input, /* i : gain shape overlap buffer */ - const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ - Word16 length, /* i : targeted length of transition signal */ - Word16 *output, /* o : synthesized transitions signal */ - Word32 Hilbert_Mem[], /* i/o: memory */ - Word16 state_lsyn_filt_shb_local[], /* i/o: memory */ + const Word16 *input, /* i : gain shape overlap buffer Q11 */ + const Word16 *old_hb_synth, /* i : synthesized HB from previous frame Q(15 - hb_synth_fx_exp)*/ + Word16 length, /* i : targeted length of transition signal */ + Word16 *output, /* o : synthesized transitions signal st_fx->prev_Q_bwe_syn2 */ + Word32 Hilbert_Mem[], /* i/o: memory st_fx->prev_Q_bwe_syn2 */ + Word16 state_lsyn_filt_shb_local[], /* i/o: memory st_fx->prev_Q_bwe_syn2*/ Word16 mem_resamp_HB_32k[], /* i/o: memory */ Word16 *syn_dm_phase, Word32 target_fs, @@ -5438,7 +5445,7 @@ void td_bwe_dec_init_fx( const Word32 output_Fs /* i : output sampling rate */ ) { - int16_t i; + Word16 i; /* init. SHB buffers */; InitSWBdecBuffer_fx( st_fx ); @@ -5461,7 +5468,7 @@ void td_bwe_dec_init_fx( hBWE_TD->tilt_mem_fx = 0; move16(); - set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384 /*0.5f in Q15*/, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para_fx = 0; move16(); set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); @@ -5495,10 +5502,8 @@ void td_bwe_dec_init_fx( hBWE_TD->fb_tbe_demph_fx = 0; move16(); - set16_fx( hBWE_TD->old_hb_synth_fx, 0, L_FRAME48k ); - hBWE_TD->prev_ener_fx = L_deposit_l( 0 ); move32(); diff --git a/lib_dec/syn_outp.c b/lib_dec/syn_outp.c index 65e36bc6140499ac75a045bf239e1071a1bfe8b8..31cd8b1097de1d0bec426403c54d66414d6da5bf 100644 --- a/lib_dec/syn_outp.c +++ b/lib_dec/syn_outp.c @@ -47,7 +47,7 @@ * Output synthesis signal with compensation for saturation * returns number of clipped samples *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED /*! r: number of clipped samples */ uint32_t syn_output( float *synth, /* i/o: float synthesis signal */ @@ -133,3 +133,4 @@ void AGC_dec( return; } +#endif diff --git a/lib_dec/syn_outp_fx.c b/lib_dec/syn_outp_fx.c index 7d51c4341255eaf617b714d616ebc14dce0aa542..0d84c0c883b139f7621dc12c99e44cd722007ba5 100644 --- a/lib_dec/syn_outp_fx.c +++ b/lib_dec/syn_outp_fx.c @@ -15,11 +15,11 @@ *-------------------------------------------------------------------*/ void syn_output_fx( - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - Word16 *synth, /* i/o: fixed point synthesis signal */ - const Word16 output_frame, /* i : output frame length */ - Word16 *synth_out, /* o : integer 16 bits synthesis signal */ - const Word16 Q_syn2 /* i : Synthesis scaling factor */ + const Word16 codec_mode, /* i : MODE1 or MODE2 Q0 */ + Word16 *synth, /* i/o: fixed point synthesis signal Q_syn2 */ + const Word16 output_frame, /* i : output frame length Q0 */ + Word16 *synth_out, /* o : integer 16 bits synthesis signal Q_syn2 */ + const Word16 Q_syn2 /* i : Synthesis scaling factor */ ) { Word16 i, tmp; @@ -66,7 +66,7 @@ void unscale_AGC( const Word16 x[], /* i: 16kHz synthesis Qx */ const Word16 Qx, /* i: scale factor of x */ Word16 y[], /* o: output vector Q0 */ - Word16 mem[], /* i/o: mem[2] should be init to [0,0] */ + Word16 mem[], /* i/o: mem[2] should be init to [0,0] Q0 */ const Word16 n /* i: vector size */ ) { @@ -97,16 +97,16 @@ void unscale_AGC( move16(); IF( GT_16( max_val, tmp ) ) { - frame_fac = sub( 16384, div_s( shr( tmp, 1 ), max_val ) ); /* frame fac in Q15 */ + frame_fac = sub( 16384 /*0.5f in Q15*/, div_s( shr( tmp, 1 ), max_val ) ); /* frame fac in Q15 */ } /*----------------------------------------------------------------* * AGC *----------------------------------------------------------------*/ /* update AGC factor (slowly) */ - fac = mac_r( L_mult( 32440, mem[0] ), 328, frame_fac ); + fac = mac_r( L_mult( 32440 /*0.99f in Q15*/, mem[0] ) /*Q14*/, 328 /*0.01f in Q15*/, frame_fac /*Q15*/ ); - L_tmp = L_mult( x[0], 16384 ); + L_tmp = L_mult( x[0], 16384 /*1.0f in Q14*/ ); // Q13 L_tmp = L_msu0( L_tmp, fac, x[0] ); L_tmp = L_msu( L_tmp, fac, mem[1] ); L_tmp = L_shr( L_tmp, -1 ); /* saturation can occur here */ diff --git a/lib_dec/tcq_core_dec_fx.c b/lib_dec/tcq_core_dec_fx.c index 41c83c71ec499a4ff961d2e13eea60e633f7f26d..0432f02a589658605300076dcb71e50b76ed3543 100644 --- a/lib_dec/tcq_core_dec_fx.c +++ b/lib_dec/tcq_core_dec_fx.c @@ -16,20 +16,21 @@ #ifdef IVAS_FLOAT_FIXED void tcq_core_LR_dec_fx( Decoder_State *st_fx, - Word16 *inp_vector_fx, /* x5 */ - const Word16 bit_budget, - const Word16 BANDS, - const Word16 *band_start, - const Word16 *band_width, - Word32 *Rk_fx, /* Q16 */ - Word16 *npulses, - Word16 *k_sort, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame, - const Word16 adjustFlag, - const Word16 *is_transient ) + Word16 *inp_vector_fx, /*Qx */ + const Word16 bit_budget, /*Q0 */ + const Word16 BANDS, /*Q0 */ + const Word16 *band_start, /*Q0 */ + const Word16 *band_width, /*Q0 */ + Word32 *Rk_fx, /*Q16*/ + Word16 *npulses, /*Q0 */ + Word16 *k_sort, /*Q0 */ + const Word16 *p2a_flags, /*Q0 */ + const Word16 p2a_bands, /*Q0 */ + const Word16 *last_bitalloc, /*Q0 */ + const Word16 input_frame, /*Q0 */ + const Word16 adjustFlag, /*Q0 */ + const Word16 *is_transient /*Q0 */ +) { Word16 i, j, k; Word32 Rk_sort_fx[NB_SFM]; @@ -141,7 +142,7 @@ void tcq_core_LR_dec_fx( { IF( Rk_fx[j] > 0 ) { - Rk_fx[j] = L_sub( Rk_fx[j], ar_div( bsub_fx, nzb ) ); + Rk_fx[j] = L_sub( Rk_fx[j], ar_div( bsub_fx, nzb ) ); /*Q16*/ move32(); IF( Rk_fx[j] < 0 ) { @@ -201,7 +202,7 @@ void tcq_core_LR_dec_fx( IF( LE_16( input_frame, L_FRAME16k ) && ( adjustFlag == 0 ) && ( *is_transient == 0 ) ) { surplus_fx = -131072; - move32(); /*16 */ + move32(); /*2 in Q16 */ bit_allocation_second_fx( Rk_fx, Rk_sort_fx, BANDS, band_width, k_sort, k_num, p2a_flags, p2a_bands, last_bitalloc, input_frame ); @@ -244,7 +245,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } IF( surplus_fx != 0 ) @@ -266,7 +267,7 @@ void tcq_core_LR_dec_fx( decode_mangitude_tcq_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, nz, &positions_fx[band_start[k_sort[k]]], &inp_vector_fx[band_start[k_sort[k]]], &surplus_fx ); decode_signs_fx( pardec_fx, band_width[k_sort[k]], &inp_vector_fx[band_start[k_sort[k]]] ); } - nzbands--; + nzbands = sub( nzbands, 1 ); move16(); } ELSE IF( ( Rk_fx[k_sort[k]] > 0 ) && EQ_16( USQ_TCQ[k_sort[k]], 1 ) ) @@ -282,7 +283,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } IF( surplus_fx != 0 ) @@ -302,7 +303,7 @@ void tcq_core_LR_dec_fx( decode_magnitude_usq_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, nz, &positions_fx[band_start[k_sort[k]]], &inp_vector_fx[band_start[k_sort[k]]] ); decode_signs_fx( pardec_fx, band_width[k_sort[k]], &inp_vector_fx[band_start[k_sort[k]]] ); } - nzbands--; + nzbands = sub( nzbands, 1 ); move16(); } ELSE @@ -311,7 +312,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } } @@ -403,7 +404,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } } @@ -436,7 +437,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } } diff --git a/lib_dec/tcx_utils_dec_fx.c b/lib_dec/tcx_utils_dec_fx.c index e4b56eca9964566be04279a94992cefa24b82378..1c7bee57be3dd1a64b67569233d49e06c3924dbf 100644 --- a/lib_dec/tcx_utils_dec_fx.c +++ b/lib_dec/tcx_utils_dec_fx.c @@ -20,11 +20,11 @@ * *--------------------------------------------------------------*/ void tcx_decoder_memory_update( - Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer */ - Word16 *synthout, /* o: synth */ - Word16 *A, /* i: Quantized LPC coefficients */ - Decoder_State *st, /* i/o: decoder memory state */ - Word8 fb /* i: fullband flag */ + Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer : Q0 */ + Word16 *synthout, /* o: synth : Q0 */ + Word16 *A, /* i: Quantized LPC coefficients : Q12*/ + Decoder_State *st, /* i/o: decoder memory state */ + Word8 fb /* i: fullband flag */ ) { Word16 tmp; @@ -35,7 +35,7 @@ void tcx_decoder_memory_update( L_frame_glob = st->L_frame; move16(); - preemph = st->preemph_fac; + preemph = st->preemph_fac; // Q15 move16(); /* Output synth */ @@ -105,7 +105,7 @@ void tcx_decoder_memory_update( Residu3_fx( A, synth, st->old_exc_fx + sub( L_EXC_MEM_DEC, L_frame_glob ), L_frame_glob, 1 ); } /* Update old_Aq */ - Copy( A, st->old_Aq_12_8_fx, M + 1 ); + Copy( A, st->old_Aq_12_8_fx /*Q12*/, M + 1 ); #ifdef FIX_778_STEREO_BRATE_SWITCHING } #endif @@ -116,27 +116,22 @@ void tcx_decoder_memory_update( /* Returns: number of bits used (including "bits") */ Word16 tcx_ari_res_invQ_spec( - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - const Word16 prm[], /* i: bitstream Q0 */ - Word16 target_bits, /* i: number of bits available Q0 */ - Word16 bits, /* i: number of bits used so far Q0 */ - Word16 deadzone, /* i: quantizer deadzone Q15 */ - const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ + Word32 x_Q[], /* i/o: quantized spectrum Q(31-x_Q_e) */ + Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ + Word16 L_frame, /* i: number of lines Q0 */ + const Word16 prm[], /* i: bitstream Q0 */ + Word16 target_bits, /* i: number of bits available Q0 */ + Word16 bits, /* i: number of bits used so far Q0 */ + Word16 deadzone, /* i: quantizer deadzone Q15 */ + const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ ) { - Word16 i, j, num_zeros; - Word16 zeros[L_FRAME_PLUS]; - Word16 fac_p, sign; + Word16 i, j, num_zeros, zeros[L_FRAME_PLUS], fac_p, sign, s; Word32 L_tmp; - Word16 s; - /* Limit the number of residual bits */ target_bits = s_min( target_bits, NPRM_RESQ ); - /* Requantize the spectrum line-by-line */ /* fac_m = deadzone * 0.5f; */ num_zeros = 0; @@ -157,7 +152,7 @@ Word16 tcx_ari_res_invQ_spec( sign = negate( sign ); /* x_Q[i] += sign*(prm[bits++] * 0.5f - fac_m); */ - x_Q[i] = L_sub( x_Q[i], L_shr( L_mult( sign, add( deadzone, lshl( prm[bits], 15 ) ) ), x_Q_e ) ); + x_Q[i] = L_sub( x_Q[i], L_shr( L_mult( sign, add( deadzone, lshl( prm[bits], 15 ) ) ), x_Q_e ) ); // x_Q_e move32(); bits = add( bits, 1 ); } @@ -196,7 +191,6 @@ Word16 tcx_ari_res_invQ_spec( bits = add( bits, 1 ); } - return bits; } /*--------------------------------------------------------------- @@ -205,14 +199,13 @@ Word16 tcx_ari_res_invQ_spec( * *--------------------------------------------------------------*/ Word16 tcx_res_invQ_gain( - Word16 *gain_tcx, + Word16 *gain_tcx, /* i/o : gain_tcx_e*/ Word16 *gain_tcx_e, - Word16 *prm, - Word16 resQBits ) + Word16 *prm, /*i : Q0 */ + Word16 resQBits /*i : Q0 */ +) { - Word16 bits; - Word16 gain, tmp1, tmp2; - + Word16 bits, gain, tmp1, tmp2; gain = *gain_tcx; move16(); @@ -255,14 +248,14 @@ Word16 tcx_res_invQ_gain( * *--------------------------------------------------------------*/ Word16 tcx_res_invQ_spec( - Word32 *x, + Word32 *x, /*Q(31 - x_e)*/ Word16 x_e, Word16 L_frame, Word16 *prm, Word16 resQBits, Word16 bits, - Word16 sq_round, - const Word16 lf_deemph_factors[] ) + Word16 sq_round, /*i : sq deadzone Q15*/ + const Word16 lf_deemph_factors[] /*i : LF deemphasis factors Q14*/ ) { Word16 i; Word16 fac_m, fac_p; @@ -275,9 +268,9 @@ Word16 tcx_res_invQ_spec( /* Requantize the spectrum line-by-line */ fac_m = shr( sq_round, 1 ); - fac_p = sub( 0x4000, fac_m ); + fac_p = sub( 0x4000 /*0.5f Q15*/, fac_m ); // Q15 - lf_deemph_factor = 0x4000; + lf_deemph_factor = 0x4000; /*0.5f Q15*/ move16(); s = sub( x_e, 1 ); @@ -290,11 +283,11 @@ Word16 tcx_res_invQ_spec( test(); test(); - IF( ( x[i] != 0 ) && ( ( lf_deemph_factors == NULL ) || ( GT_16( lf_deemph_factors[i], 0x2000 ) ) ) ) + IF( ( x[i] != 0 ) && ( ( lf_deemph_factors == NULL ) || ( GT_16( lf_deemph_factors[i], 0x2000 /*0.5f in Q14*/ ) ) ) ) { if ( lf_deemph_factors != NULL ) { - lf_deemph_factor = lf_deemph_factors[i]; + lf_deemph_factor = lf_deemph_factors[i]; // Q14 move16(); } @@ -306,13 +299,13 @@ Word16 tcx_res_invQ_spec( move32(); if ( x[i] > 0 ) - tmp = L_mult( fac_m, lf_deemph_factor ); + tmp = L_mult( fac_m, lf_deemph_factor ); // Q14+Q15-1 = Q28 if ( x[i] < 0 ) - tmp = L_mult( fac_p, lf_deemph_factor ); + tmp = L_mult( fac_p, lf_deemph_factor ); // Q14+Q15-1 = Q28 assert( tmp != 0 ); - x[i] = L_sub( x[i], L_shr( tmp, s ) ); + x[i] = L_sub( x[i], L_shr( tmp, s ) ); // Q(31 - x_e) move32(); } ELSE @@ -323,13 +316,13 @@ Word16 tcx_res_invQ_spec( move32(); if ( x[i] > 0 ) - tmp = L_mult( fac_p, lf_deemph_factor ); + tmp = L_mult( fac_p, lf_deemph_factor ); // Q14+Q15-1 = Q28 if ( x[i] < 0 ) - tmp = L_mult( fac_m, lf_deemph_factor ); + tmp = L_mult( fac_m, lf_deemph_factor ); // Q14+Q15-1 = Q28 assert( tmp != 0 ); - x[i] = L_add( x[i], L_shr( tmp, s ) ); + x[i] = L_add( x[i], L_shr( tmp, s ) ); // Q(31 - x_e) move32(); } bits = add( bits, 1 ); @@ -354,11 +347,11 @@ Word16 tcx_res_invQ_spec( { bits = add( bits, 1 ); - tmp = L_mult( 21627 /*1.32f Q14*/, fac_p ); + tmp = L_mult( 21627 /*1.32f Q14*/, fac_p /*Q15*/ ); // Q28 if ( prm[bits] == 0 ) tmp = L_negate( tmp ); - x[i] = L_shr( tmp, s ); + x[i] = L_shr( tmp, s ); // Q(31 - x_e) move32(); } bits = add( bits, 1 ); @@ -367,7 +360,7 @@ Word16 tcx_res_invQ_spec( } ELSE { - c = sub( 21627 /*0.66f Q15*/, mult_r( sq_round, 21627 /*0.66f Q15*/ ) ); + c = sub( 21627 /*0.66f Q15*/, mult_r( sq_round, 21627 /*0.66f Q15*/ ) ); // Q15 FOR( i = 0; i < L_frame; i++ ) { @@ -383,11 +376,11 @@ Word16 tcx_res_invQ_spec( { bits = add( bits, 1 ); - tmp = L_mult( c, lf_deemph_factors[i] ); + tmp = L_mult( c, lf_deemph_factors[i] ); // Q28 if ( prm[bits] == 0 ) tmp = L_negate( tmp ); - x[i] = L_shr( tmp, s ); + x[i] = L_shr( tmp, s ); // Q(31 - x_e) move32(); } bits = add( bits, 1 ); diff --git a/lib_dec/tns_base_dec_fx.c b/lib_dec/tns_base_dec_fx.c index 4f44dab85d8aa15568f0f1303f286ffe342f39f3..4a68a49c22d5597c4efbdb5fe7bd2fc89b47cef5 100644 --- a/lib_dec/tns_base_dec_fx.c +++ b/lib_dec/tns_base_dec_fx.c @@ -35,9 +35,10 @@ Word16 ReadTnsData( STnsConfig const *pTnsConfig, Decoder_State *st, - Word16 *pnBits, - Word16 *stream, - Word16 *pnSize ) + Word16 *pnBits, /*Q0*/ + Word16 *stream, /*Q0*/ + Word16 *pnSize /*Q0*/ +) { Word16 start_bit_pos; @@ -97,13 +98,13 @@ Word16 ReadTnsData_ivas_fx( STnsConfig const *pTnsConfig, Decoder_State *st, - Word16 *pnBits, - Word16 *stream, - Word16 *pnSize ) + Word16 *pnBits, /*Q0*/ + Word16 *stream, /*Q0*/ + Word16 *pnSize /*Q0*/ +) { Word16 start_bit_pos; - move16(); start_bit_pos = st->next_bit_pos; @@ -143,7 +144,6 @@ ReadTnsData_ivas_fx( move16(); *pnBits = sub( st->next_bit_pos, start_bit_pos ); - #ifdef IVAS_CODE return; #else @@ -159,8 +159,8 @@ ReadTnsData_ivas_fx( Word16 DecodeTnsData( STnsConfig const *pTnsConfig, - Word16 const *stream, - Word16 *pnSize, + Word16 const *stream, /*Q0*/ + Word16 *pnSize, /*Q0*/ STnsData *pTnsData ) { Word16 result; @@ -215,8 +215,8 @@ Word16 DecodeTnsData( Word16 DecodeTnsData_ivas_fx( STnsConfig const *pTnsConfig, - Word16 const *stream, - Word16 *pnSize, + Word16 const *stream, /*Q0*/ + Word16 *pnSize, /*Q0*/ STnsData *pTnsData ) { Word16 result; diff --git a/lib_dec/tonalMDCTconcealment.c b/lib_dec/tonalMDCTconcealment.c index f27836c0ef383c1cd9a275c75f4ed80fc15d5ba3..9bb02702582cf53e33835a29e6b4e2d1fd0ed0e9 100644 --- a/lib_dec/tonalMDCTconcealment.c +++ b/lib_dec/tonalMDCTconcealment.c @@ -960,15 +960,15 @@ void TonalMDCTConceal_SaveTimeSignal_ivas( #ifdef IVAS_FLOAT_FIXED void TonalMdctConceal_create_concealment_noise_ivas_fx( - Word32 concealment_noise[L_FRAME48k], + Word32 concealment_noise[L_FRAME48k], // Q31-concealment_noise_exp Word16 *concealment_noise_exp, CPE_DEC_HANDLE hCPE, - const Word16 L_frameTCX, - const Word16 L_frame, - const Word16 idchan, - const Word16 subframe_idx, - const Word16 core, - const Word16 crossfade_gain, + const Word16 L_frameTCX, // Q0 + const Word16 L_frame, // Q0 + const Word16 idchan, // Q0 + const Word16 subframe_idx, // Q0 + const Word16 core, // Q0 + const Word16 crossfade_gain, // Q15 const TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode ) { STEREO_MDCT_DEC_DATA_HANDLE hStereoMdct; @@ -1027,10 +1027,10 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( /* first lost frame is handled separately */ IF( !hTonalMDCTConc->lastBlockData.blockIsConcealed ) { - *rnd = add( 1977, idchan ); + *rnd = add( 1977, idchan ); // Q0 move16(); /* will be set twice when looping over two channels, but does not matter */ - *rnd_c = 1979; + *rnd_c = 1979; // Q0 move16(); } @@ -1042,7 +1042,7 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( { *rnd = own_random( rnd ); move16(); - concealment_noise[i] = *rnd; + concealment_noise[i] = *rnd; // Q31-concealment_noise_exp move32(); } *concealment_noise_exp = 31; @@ -1052,7 +1052,7 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( return; } - save_rnd_c = *rnd_c; + save_rnd_c = *rnd_c; // Q0 move16(); c_e = 1; @@ -1067,13 +1067,13 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( { IF( LT_16( c_e, c_inv_e ) ) { - c = shr( c, sub( c_inv_e, c_e ) ); + c = shr( c, sub( c_inv_e, c_e ) ); // Q0 c_e = c_inv_e; move16(); } ELSE { - c_inv = shr( c_inv, sub( c_e, c_inv_e ) ); + c_inv = shr( c_inv, sub( c_e, c_inv_e ) ); // Q0 } } @@ -1105,7 +1105,7 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( { noise_shape_buffer_e[i] = hFdCngCom->cngNoiseLevelExp; move16(); - noise_shape_buffer[i] = Sqrt32( *( cngNoiseLevelPtr ), &noise_shape_buffer_e[i] ); + noise_shape_buffer[i] = Sqrt32( *( cngNoiseLevelPtr ), &noise_shape_buffer_e[i] ); // Q31-noise_shape_buffer_e[i] move32(); noise_shape_buffer_common_exp = s_max( noise_shape_buffer_e[i], noise_shape_buffer_common_exp ); } @@ -1115,33 +1115,33 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( IF( NE_16( noise_shape_buffer_common_exp, noise_shape_buffer_e[i] ) ) { - noise_shape_buffer[i] = L_shr( noise_shape_buffer[i], sub( noise_shape_buffer_common_exp, noise_shape_buffer_e[i] ) ); + noise_shape_buffer[i] = L_shr( noise_shape_buffer[i], sub( noise_shape_buffer_common_exp, noise_shape_buffer_e[i] ) ); // Q31- (noise_shape_buffer_common_exp-noise_shape_buffer_e[i]) move32(); } } - last_scf = Sqrt32( *( cngNoiseLevelPtr - inc ), &last_scf_e ); + last_scf = Sqrt32( *( cngNoiseLevelPtr - inc ), &last_scf_e ); // Q31-last_scf_e IF( LT_16( noise_shape_buffer_common_exp, last_scf_e ) ) { - Scale_sig32( noise_shape_buffer, stop_idx, sub( noise_shape_buffer_common_exp, last_scf_e ) ); + Scale_sig32( noise_shape_buffer, stop_idx, sub( noise_shape_buffer_common_exp, last_scf_e ) ); // Q31- (noise_shape_buffer_common_exp-last_scf_e) noise_shape_buffer_common_exp = last_scf_e; move16(); } ELSE { - last_scf = L_shl( last_scf, sub( last_scf_e, noise_shape_buffer_common_exp ) ); + last_scf = L_shl( last_scf, sub( last_scf_e, noise_shape_buffer_common_exp ) ); // Q31-(last_scf_e-noise_shape_buffer_common_exp) } FOR( ; i < max_noise_line; i++ ) { - noise_shape_buffer[i] = last_scf; + noise_shape_buffer[i] = last_scf; // Q31 - noise_shape_buffer_common_exp move32(); } /* fill the noise vector */ - hTonalMDCTConc->curr_noise_nrg = MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG_Q31; + hTonalMDCTConc->curr_noise_nrg = MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG_Q31; // Q31 move32(); hTonalMDCTConc->curr_noise_nrg_exp = 0; move16(); @@ -1160,17 +1160,17 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( FOR( i = 0; i < max_noise_line; i++ ) { - *rnd = own_random( rnd ); + *rnd = own_random( rnd ); // Q0 *rnd_c = own_random( rnd_c ); move16(); move16(); - concealment_noise[i] = Mpy_32_32( L_add( L_shr( L_mult( c_inv, *rnd ), 1 ), L_shr( L_mult( c, *rnd_c ), 1 ) ), noise_shape_buffer[i] ); + concealment_noise[i] = Mpy_32_32( L_add( L_shr( L_mult( c_inv, *rnd ), 1 ), L_shr( L_mult( c, *rnd_c ), 1 ) ), noise_shape_buffer[i] ); // Q31 - *concealment_noise_exp move32(); IF( concealment_noise[i] != 0 ) { - hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); + hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); // Q31-temp_e } hTonalMDCTConc->curr_noise_nrg_exp = temp_e; move16(); @@ -1181,8 +1181,8 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( /* current channel is TCX10 and the other is TCX20 -> generate noise for "half-length" spectrum, but "increment" mid seed twice, to have the same seed in mid as the other (TCX20) channel for next frame */ FOR( i = 0; i < max_noise_line; i++ ) { - *rnd = own_random( rnd ); - *rnd_c = own_random( rnd_c ); + *rnd = own_random( rnd ); // Q0 + *rnd_c = own_random( rnd_c ); // Q0 move16(); move16(); @@ -1190,7 +1190,7 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( move32(); IF( concealment_noise[i] != 0 ) { - hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); + hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); // Q31-temp_e } hTonalMDCTConc->curr_noise_nrg_exp = temp_e; move16(); @@ -1521,11 +1521,11 @@ void TonalMdctConceal_whiten_noise_shape_ivas_fx( sns_interpolate_scalefactors_fx( scfs_int, scf, ENC ); sns_interpolate_scalefactors_fx( scfs_bg, scf, DEC ); - scfs_for_shaping = &scfs_int[0]; + scfs_for_shaping = &scfs_int[0]; // Q16 } ELSE /* whitening_mode == ON_FIRST_GOOD_FRAME */ { - scfs_for_shaping = &scfs_bg[0]; + scfs_for_shaping = &scfs_bg[0]; // Q16 } IF( sum32_sat( scfs_for_shaping, FDNS_NPTS ) > 0 ) @@ -1537,7 +1537,7 @@ void TonalMdctConceal_whiten_noise_shape_ivas_fx( { FOR( i = 0; i < sub( stop_idx, start_idx ); i++ ) { - hFdCngCom->cngNoiseLevel[i] = L_shr( whitenend_noise_shape[start_idx + i], sub( add( q_wns, hFdCngCom->cngNoiseLevelExp ), 30 ) ); + hFdCngCom->cngNoiseLevel[i] = L_shr( whitenend_noise_shape[start_idx + i], sub( add( q_wns, hFdCngCom->cngNoiseLevelExp ), 30 ) ); //(q_wns + 1) move32(); } } diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 93e2f24cc737086744f535ca95494e0a3b3315b9..adb73de03f5632537f670393de390379e98fc496 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -118,8 +118,8 @@ ivas_error TonalMDCTConceal_Init( move16(); move16(); /* just the second half of the second last pcm output is needed */ - hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, shr( imult1616( 3, ( s_min( L_FRAME_MAX, nSamples ) ) ), 1 ) )]; - hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, s_min( L_FRAME_MAX, nSamples ) )]; + hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - ( 3 * ( min( L_FRAME_MAX, nSamples ) ) / 2 )]; + hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - min( L_FRAME_MAX, nSamples )]; /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */ assert( sizeof( *hTonalMDCTConc->pTCI ) <= ( hTonalMDCTConc->lastPcmOut - hTonalMDCTConc->timeDataBuffer ) * sizeof( hTonalMDCTConc->timeDataBuffer[0] ) ); @@ -231,8 +231,8 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( move16(); move16(); /* just the second half of the second last pcm output is needed */ - hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, imult1616( 3, shr( s_min( L_FRAME_MAX, nSamples ), 1 ) ) )]; - hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, s_min( L_FRAME_MAX, nSamples ) )]; + hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - ( 3 * min( L_FRAME_MAX, nSamples ) / 2 )]; + hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - min( L_FRAME_MAX, nSamples )]; /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */ assert( sizeof( *hTonalMDCTConc->pTCI ) <= ( hTonalMDCTConc->lastPcmOut - hTonalMDCTConc->timeDataBuffer ) * sizeof( hTonalMDCTConc->timeDataBuffer[0] ) ); @@ -240,11 +240,11 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( } void TonalMDCTConceal_SaveFreqSignal( TonalMDCTConcealPtr hTonalMDCTConc, - const Word32 *mdctSpectrum, + const Word32 *mdctSpectrum, // Q31-mdctSpectrum_exp const Word16 mdctSpectrum_exp, - Word16 nNewSamples, - Word16 nNewSamplesCore, - const Word16 *scaleFactors, + Word16 nNewSamples, // Q0 + Word16 nNewSamplesCore, // Q0 + const Word16 *scaleFactors, // Q31-scaleFactors_exp const Word16 *scaleFactors_exp, const Word16 gain_tcx_exp #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT @@ -375,7 +375,7 @@ void TonalMDCTConceal_SaveFreqSignal( FOR( i = 0; i < nNewSamples; i++ ) { - hTonalMDCTConc->lastBlockData.spectralData[i] = extract_h( L_shl( mdctSpectrum[i], s ) ); + hTonalMDCTConc->lastBlockData.spectralData[i] = extract_h( L_shl( mdctSpectrum[i], s ) ); // Q31-(mdctSpectrum_exp-s) move16(); } hTonalMDCTConc->lastBlockData.spectralData_exp = sub( mdctSpectrum_exp, s ); @@ -390,14 +390,14 @@ void TonalMDCTConceal_SaveFreqSignal( void TonalMDCTConceal_SaveFreqSignal_ivas_fx( TonalMDCTConcealPtr hTonalMDCTConc, - const Word32 *mdctSpectrum, - const Word16 mdctSpectrum_exp, - const Word16 nNewSamples, - const Word16 nNewSamplesCore, - const Word16 *scaleFactors, - const Word16 *scaleFactors_exp, - const Word16 gain_tcx_exp, - const Word16 infoIGFStartLine ) + const Word32 *mdctSpectrum, // Q31-mdctSpectrum_exp + const Word16 mdctSpectrum_exp, // Q0 + const Word16 nNewSamples, // Q0 + const Word16 nNewSamplesCore, // Q0 + const Word16 *scaleFactors, // Q15 - *scaleFactors_exp + const Word16 *scaleFactors_exp, // Q0 + const Word16 gain_tcx_exp, // Q0 + const Word16 infoIGFStartLine ) // Q0 { Word16 *temp; Word16 nOldSamples, temp_exp, s, i, max_exp; @@ -496,7 +496,7 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( { Word16 tmp = extract_h( mdctSpectrum[i] ); hTonalMDCTConc->last_block_nrg = L_add( hTonalMDCTConc->last_block_nrg, - L_shr( L_mult0( tmp, tmp ), 16 ) ); + L_shr( L_mult0( tmp, tmp ), 16 ) ); // Q31-last_block_nrg_exp move32(); } hTonalMDCTConc->last_block_nrg_exp = sub( 31, sub( shl( sub( 15, mdctSpectrum_exp ), 1 ), 16 ) ); @@ -526,7 +526,7 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( tmp = 1; move16(); } - hTonalMDCTConc->lastBlockData.spectralData[i] = extract_h( L_shl( mdctSpectrum[i], s ) ); + hTonalMDCTConc->lastBlockData.spectralData[i] = extract_h( L_shl( mdctSpectrum[i], s ) ); // 31 - mdctSpectrum_exp +s -16 = 15-(mdctSpectrum_exp -s) move16(); test(); @@ -549,9 +549,9 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState( TonalMDCTConcealPtr hTonalMDCTConc, - Word16 nNewSamples, - Word32 pitchLag, - Word16 badBlock, + Word16 nNewSamples, // Q0 + Word32 pitchLag, // Qx + Word16 badBlock, // Q0 Word8 tonalConcealmentActive ) { Word8 newBlockIsValid; @@ -596,8 +596,8 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState( TonalMDCTConcealPtr hTonalM } static void FindPhases( /* o: currenc phase [-pi;pi] 2Q13 */ TonalMDCTConcealPtr const hTonalMDCTConc, /* i: pointer to internal structure */ - Word32 secondLastMDCT[], /* i: MDST spectrum data */ - Word32 secondLastMDST[], /* i: MDCT spectrum data */ + Word32 secondLastMDCT[], /* i: MDST spectrum data Qx +31 -diff_exp */ + Word32 secondLastMDST[], /* i: MDCT spectrum data Qx */ Word16 diff_exp ) /* i: exp_MDST - exp_MDCT */ { Word16 i; @@ -614,7 +614,7 @@ static void FindPhases( /* o: currenc /* in contrast to the float code, the parameter secondLastMDST[l] needs not to be negated - due to a different implementation of the MDST */ - *pCurrentPhase++ = BASOP_util_atan2( secondLastMDST[l], secondLastMDCT[l], diff_exp ); + *pCurrentPhase++ = BASOP_util_atan2( secondLastMDST[l], secondLastMDCT[l], diff_exp ); // Q13 move16(); } } @@ -630,7 +630,7 @@ static void FindPhases( /* o: currenc static void FindPhaseDifferences( /* o: Phase difference [-pi;pi] 2Q13*/ TonalMDCTConcealPtr const hTonalMDCTConc, /* i: Pointer to internal structure */ - Word32 powerSpectrum[] ) /* i: Power spectrum data */ + Word32 powerSpectrum[] ) /* i: Power spectrum data Qx */ { Word16 i, k; Word16 *phaseDiff; @@ -684,7 +684,7 @@ static void FindPhaseDifferences( /* o phaseDiff[i] = (float)atan(a) * (bandwidth/2.0f);*/ /*max divi=44.8 & sf=6*/ divi = BASOP_Util_Divide3232_uu_1616_Scale( powerSpectrum[k - 1], powerSpectrum[k + 1], &sf ); - Q = BASOP_Util_fPow( L_deposit_h( divi ), sf, G, 0, &sf ); + Q = BASOP_Util_fPow( L_deposit_h( divi ), sf, G, 0, &sf ); // Q31-sf L_tmp = Mpy_32_16_1( Q, s ); sfn = sub( sf, 2 ); @@ -743,11 +743,11 @@ static void FindPhaseDifferences( /* o #ifdef IVAS_FLOAT_FIXED static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( TonalMDCTConcealPtr const hTonalMDCTConc, - Word32 secondLastMDST[], + Word32 secondLastMDST[], // Q31 - secondLastMDST_exp Word16 secondLastMDST_exp, - Word32 secondLastMDCT[], + Word32 secondLastMDCT[], // Q31 - secondLastMDCT_exp Word16 secondLastMDCT_exp, - Word32 const pitchLag, + Word32 const pitchLag, /*15Q16*/ const PsychoacousticParameters *psychParamsCurrent, Word16 element_mode ) { @@ -823,14 +823,14 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( /*sqrtFLOAT(powerSpectrum, powerSpectrum, nSamples);*/ old_exp = powerSpectrum_exp; move16(); - powerSpectrum_exp = mult_r( sub( powerSpectrum_exp, 2 ), 1 << 14 ); /*remove 2 bits of headroom from CalcPowerSpec*/ + powerSpectrum_exp = mult_r( sub( powerSpectrum_exp, 2 ), ( 1 << 14 ) ); /*remove 2 bits of headroom from CalcPowerSpec*/ FOR( i = 0; i < nSamples; i++ ) { tmp_exp = old_exp; move16(); powerSpectrum[i] = Sqrt32( powerSpectrum[i], &tmp_exp ); move32(); - powerSpectrum[i] = L_shr( powerSpectrum[i], sub( powerSpectrum_exp, tmp_exp ) ); + powerSpectrum[i] = L_shr( powerSpectrum[i], sub( powerSpectrum_exp, tmp_exp ) ); // Q31-(powerSpectrum_exp-tmp_exp) move32(); } @@ -838,7 +838,7 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( { invScaleFactors_exp[i] = hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]; move16(); - invScaleFactors[i] = Inv16( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i] ); + invScaleFactors[i] = Inv16( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i] ); // Q31-invScaleFactors_exp[i] move16(); } @@ -868,19 +868,19 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( } IF( LT_16( old_power_spectrum_q, power_spectrum_q ) ) { - Scale_sig32( powerSpectrum, length, sub( old_power_spectrum_q, power_spectrum_q ) ); + Scale_sig32( powerSpectrum, length, sub( old_power_spectrum_q, power_spectrum_q ) ); // Q(old_power_spectrum_q-power_spectrum_q) } ELSE { - Scale_sig32( powerSpectrum + length, sub( nSamples, length ), sub( power_spectrum_q, old_power_spectrum_q ) ); + Scale_sig32( powerSpectrum + length, sub( nSamples, length ), sub( power_spectrum_q, old_power_spectrum_q ) ); // Q(power_spectrum_q - old_power_spectrum_q) powerSpectrum_exp = sub( 31, power_spectrum_q ); } - Scale_sig32( powerSpectrum, nSamples, -3 ); /*Adding guard bits*/ + Scale_sig32( powerSpectrum, nSamples, -3 ); /*Adding guard bits*/ // Q(31 - powerSpectrum_exp )-3 powerSpectrum_exp = add( powerSpectrum_exp, 3 ); FOR( i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++ ) { #ifdef BASOP_NOGLOB - powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[nBands - 1] ), invScaleFactors_exp[nBands - 1] ); + powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[nBands - 1] ), invScaleFactors_exp[nBands - 1] ); // Q(31 - powerSpectrum_exp) #else powerSpectrum[i] = L_shl( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[nBands - 1] ), invScaleFactors_exp[nBands - 1] ); #endif @@ -895,7 +895,7 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( FOR( i = 0; i < nSamples; i++ ) { #ifdef BASOP_NOGLOB - hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx_o( powerSpectrum[i], &Overflow ); + hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx_o( powerSpectrum[i], &Overflow ); // Q31 - powerSpectrum_exp #else hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx( powerSpectrum[i] ); #endif @@ -910,11 +910,11 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( static void CalcPowerSpecAndDetectTonalComponents( TonalMDCTConcealPtr const hTonalMDCTConc, - Word32 secondLastMDST[], + Word32 secondLastMDST[], // Q31-secondLastMDST_exp Word16 secondLastMDST_exp, - Word32 secondLastMDCT[], + Word32 secondLastMDCT[], // Q31-secondLastMDCT_exp Word16 secondLastMDCT_exp, - Word32 const pitchLag, + Word32 const pitchLag, /*15Q16*/ Word16 element_mode #ifdef IVAS_CODE_MDCT_GSHAPE , @@ -995,8 +995,8 @@ static void CalcPowerSpecAndDetectTonalComponents( { tmp_exp = old_exp; move16(); - powerSpectrum[i] = Sqrt32( powerSpectrum[i], &tmp_exp ); - powerSpectrum[i] = L_shr( powerSpectrum[i], sub( powerSpectrum_exp, tmp_exp ) ); + powerSpectrum[i] = Sqrt32( powerSpectrum[i], &tmp_exp ); // Q31- tmp_exp + powerSpectrum[i] = L_shr( powerSpectrum[i], sub( powerSpectrum_exp, tmp_exp ) ); // Q31- tmp_exp move32(); } @@ -1005,7 +1005,7 @@ static void CalcPowerSpecAndDetectTonalComponents( move16(); move16(); invScaleFactors_exp[i] = hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]; - invScaleFactors[i] = Inv16( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i] ); + invScaleFactors[i] = Inv16( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i] ); // Q31 - invScaleFactors_exp[i] } @@ -1027,7 +1027,7 @@ static void CalcPowerSpecAndDetectTonalComponents( FOR( i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++ ) { #ifdef BASOP_NOGLOB - powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[FDNS_NPTS - 1] ), invScaleFactors_exp[FDNS_NPTS - 1] ); + powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[FDNS_NPTS - 1] ), invScaleFactors_exp[FDNS_NPTS - 1] ); // powerSpectrum_exp+ 2*invScaleFactors_exp -15 #else powerSpectrum[i] = L_shl( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[FDNS_NPTS - 1] ), invScaleFactors_exp[FDNS_NPTS - 1] ); #endif @@ -1038,7 +1038,7 @@ static void CalcPowerSpecAndDetectTonalComponents( FOR( i = 0; i < nSamples; i++ ) { #ifdef BASOP_NOGLOB - hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx_o( powerSpectrum[i], &Overflow ); + hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx_o( powerSpectrum[i], &Overflow ); // Q31-powerSpectrum_exp #else hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx( powerSpectrum[i] ); #endif @@ -1055,8 +1055,8 @@ static void CalcPowerSpecAndDetectTonalComponents( static void CalcMDXT( const TonalMDCTConcealPtr hTonalMDCTConc, const Word16 type, - const Word16 *timeSignal, - Word32 *mdxtOutput, + const Word16 *timeSignal, // Qx + Word32 *mdxtOutput, // Q31-mdxtOutput_e Word16 *mdxtOutput_e ) { Word16 windowedTimeSignal[L_FRAME_PLUS + 2 * L_MDCT_OVLP_MAX]; @@ -1082,7 +1082,7 @@ static void CalcMDXT( void TonalMDCTConceal_Detect( const TonalMDCTConcealPtr hTonalMDCTConc, - const Word32 pitchLag, + const Word32 pitchLag, /*15Q16*/ Word16 *numIndices, Word16 element_mode #ifdef IVAS_CODE_MDCT_GSHAPE @@ -1184,8 +1184,8 @@ void TonalMDCTConceal_Detect( /* multFLOAT(powerSpectrum, powerSpectrum, powerSpectrum, nSamples); */ FOR( i = 0; i < nSamples; i++ ) { - Word32 const t = L_shl( powerSpectrum[i], powerSpectrum_exp ); - powerSpectrum[i] = Mpy_32_32( t, t ); + Word32 const t = L_shl( powerSpectrum[i], powerSpectrum_exp ); // Q(31-secondLastMDST_exp+powerSpectrum_exp) + powerSpectrum[i] = Mpy_32_32( t, t ); // Q2*(31-secondLastMDST_exp+powerSpectrum_exp) -31 move32(); } @@ -1225,7 +1225,7 @@ void TonalMDCTConceal_Detect( #ifdef IVAS_FLOAT_FIXED void TonalMDCTConceal_Detect_ivas_fx( const TonalMDCTConcealPtr hTonalMDCTConc, - const Word32 pitchLag, + const Word32 pitchLag, /*15Q16*/ Word16 *numIndices, const PsychoacousticParameters *psychParamsCurrent, Word16 element_mode ) @@ -1283,7 +1283,7 @@ void TonalMDCTConceal_Detect_ivas_fx( nSamples = hTonalMDCTConc->nNonZeroSamples; move16(); - s = getScaleFactor32( secondLastMDST, nSamples ); + s = sub( getScaleFactor32( secondLastMDST, nSamples ), 1 ); FOR( i = 0; i < nSamples; i++ ) { @@ -1292,7 +1292,7 @@ void TonalMDCTConceal_Detect_ivas_fx( } secondLastMDST_exp = sub( secondLastMDST_exp, s ); move16(); - s = getScaleFactor32( secondLastMDCT, nSamples ); + s = sub( getScaleFactor32( secondLastMDCT, nSamples ), 1 ); FOR( i = 0; i < nSamples; i++ ) { @@ -1328,8 +1328,8 @@ void TonalMDCTConceal_Detect_ivas_fx( /* multFLOAT(powerSpectrum, powerSpectrum, powerSpectrum, nSamples); */ FOR( i = 0; i < nSamples; i++ ) { - Word32 const t = L_shl( powerSpectrum[i], powerSpectrum_exp ); - powerSpectrum[i] = Mpy_32_32( t, t ); + Word32 const t = L_shl( powerSpectrum[i], powerSpectrum_exp ); // Q(31-secondLastMDST_exp+powerSpectrum_exp) + powerSpectrum[i] = Mpy_32_32( t, t ); // Q(31-secondLastMDST_exp+powerSpectrum_exp) move32(); } } @@ -1345,8 +1345,8 @@ void TonalMDCTConceal_Detect_ivas_fx( FOR( i = 0; i < nSamples; i++ ) { - Word32 const t = L_shl( powerSpectrum[i], -3 ); - powerSpectrum[i] = Mpy_32_32( t, t ); + Word32 const t = L_shl( powerSpectrum[i], -3 ); // Q31 - powerSpectrum_exp -3 + powerSpectrum[i] = Mpy_32_32( t, t ); // 2*(Q31 - powerSpectrum_exp -3)-31 move32(); } } @@ -1387,17 +1387,17 @@ void TonalMDCTConceal_Detect_ivas_fx( void TonalMDCTConceal_InsertNoise_ivas_fx( const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32 *mdctSpectrum, + Word32 *mdctSpectrum, // Q31-mdctSpectrum_exp Word16 *mdctSpectrum_exp, const Word16 tonalConcealmentActive, - Word16 *pSeed, /*IN/OUT*/ - const Word16 tiltCompFactor, - const Word16 crossfadeGain_const, - const Word32 concealment_noise[L_FRAME48k], + Word16 *pSeed, /*IN/OUT*/ + const Word16 tiltCompFactor, // Q15 + const Word16 crossfadeGain_const, // Q15 + const Word32 concealment_noise[L_FRAME48k], // Q31-concealment_noise_e const Word16 concealment_noise_e, - const Word32 cngLevelBackgroundTrace_bfi, + const Word32 cngLevelBackgroundTrace_bfi, // Q31-cngLevelBackgroundTrace_bfi_e const Word16 cngLevelBackgroundTrace_bfi_e, - const Word16 crossOverFreq ) + const Word16 crossOverFreq ) // Q0 { Word16 i, l, ld, fac; Word16 rnd; @@ -1438,11 +1438,11 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( move32(); inv_exp = 15; move16(); - inv_samples = Inv16( hTonalMDCTConc->lastBlockData.nSamples, &inv_exp ); - tiltFactor = round_fx( BASOP_Util_fPow( L_max( L_tmp, L_deposit_h( tiltCompFactor ) ), 0, L_deposit_h( inv_samples ), inv_exp, &exp ) ); - BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ + inv_samples = Inv16( hTonalMDCTConc->lastBlockData.nSamples, &inv_exp ); // Q31-inv_exp + tiltFactor = round_fx( BASOP_Util_fPow( L_max( L_tmp, L_deposit_h( tiltCompFactor ) ), 0, L_deposit_h( inv_samples ), inv_exp, &exp ) ); // Q15 - exp + BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ #ifdef BASOP_NOGLOB - tiltFactor = shl_sat( tiltFactor, exp ); + tiltFactor = shl_sat( tiltFactor, exp ); // Q15 #else tiltFactor = shl( tiltFactor, exp ); #endif @@ -1474,19 +1474,19 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( concealment_noise[i] > 0 ) { - mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), 16 ); + mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), 16 ); // Q31-spectralData_exp move32(); } ELSE { - mdctSpectrum[i] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), 16 ) ); + mdctSpectrum[i] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), 16 ) ); // Q31-spectralData_exp move32(); } } FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); // Q31-spectralData_exp move32(); } @@ -1508,14 +1508,14 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( num = L_shl( cngLevelBackgroundTrace_bfi, ld ); exp_num = sub( exp_num, ld ); ld = norm_l( hTonalMDCTConc->curr_noise_nrg ); - den = L_shl( hTonalMDCTConc->curr_noise_nrg, ld ); + den = L_shl( hTonalMDCTConc->curr_noise_nrg, ld ); // Q31- curr_noise_nrg_exp + ld exp_den = sub( exp_den, ld ); exp = sub( exp_num, exp_den ); IF( GT_32( num, den ) ) { - num = L_shr( num, 1 ); + num = L_shr( num, 1 ); // Q31-exp -1 exp = add( exp, 1 ); } #ifdef BASOP_NOGLOB @@ -1533,13 +1533,13 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( exp > 0 ) { - g = shr( g, exp ); + g = shr( g, exp ); // Q15-exp *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; move16(); } ELSE { - crossfadeGain = shl( crossfadeGain, exp ); + crossfadeGain = shl( crossfadeGain, exp ); // Q15 - e_crossfadeGain + exp e_crossfadeGain = sub( e_crossfadeGain, exp ); *mdctSpectrum_exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, exp ); move16(); @@ -1568,25 +1568,25 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( FOR( i = 0; i < crossOverFreq; i++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; // Q15 - spectralData_exp move16(); - Word32 y = concealment_noise[i]; + Word32 y = concealment_noise[i]; // Q31-concealment_noise_e move32(); IF( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-concealment_noise_e- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp IF( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[i] = L_shl( L_tmp2, exp ); + mdctSpectrum[i] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); - hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[i], mdctSpectrum[i] ) ); + hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[i], mdctSpectrum[i] ) ); // Q31- faded_signal_nrg_exp move32(); } FOR( i = crossOverFreq; i < hTonalMDCTConc->lastBlockData.nSamples; i++ ) @@ -1621,11 +1621,11 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; move16(); - Word32 y = concealment_noise[l]; + Word32 y = concealment_noise[l]; // concealment_noise_e move32(); - last_block_nrg_correct = L_add( last_block_nrg_correct, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // exp = 2 * x_exp + ld - y = L_negate( Mpy_32_32( y, y ) ); - hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, y, 2 * concealment_noise_e, &hTonalMDCTConc->curr_noise_nrg_exp ); + last_block_nrg_correct = L_add( last_block_nrg_correct, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // exp = 2 * x_exp + ld + y = L_negate( Mpy_32_32( y, y ) ); // Q31-2* concealment_noise_e + hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, y, 2 * concealment_noise_e, &hTonalMDCTConc->curr_noise_nrg_exp ); // Q31- hTonalMDCTConc->curr_noise_nrg_exp move32(); } } @@ -1639,12 +1639,12 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( GT_32( concealment_noise[l], 0 ) ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } ELSE { - mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); + mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } } @@ -1654,12 +1654,12 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( concealment_noise[l] > 0 ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } ELSE { - mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); + mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } } @@ -1669,19 +1669,19 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( concealment_noise[l] > 0 ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } ELSE { - mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); + mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } } FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } @@ -1700,17 +1700,17 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( move16(); ld = norm_l( cngLevelBackgroundTrace_bfi ); - num = L_shl( cngLevelBackgroundTrace_bfi, ld ); + num = L_shl( cngLevelBackgroundTrace_bfi, ld ); // Q15 - exp_num + ld exp_num = sub( exp_num, ld ); ld = norm_l( hTonalMDCTConc->curr_noise_nrg ); - den = L_shl( hTonalMDCTConc->curr_noise_nrg, ld ); + den = L_shl( hTonalMDCTConc->curr_noise_nrg, ld ); // Q15 - exp_den + ld exp_den = sub( exp_den, ld ); exp = sub( exp_num, exp_den ); IF( GT_32( num, den ) ) { - num = L_shr( num, 1 ); + num = L_shr( num, 1 ); // Q31- exp -1 exp = add( exp, 1 ); } tmp = div_l( num, round_fx( den ) ); @@ -1725,13 +1725,13 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( GT_16( exp, 0 ) ) { - g = shr( g, exp ); + g = shr( g, exp ); // Q15- exp *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; move16(); } ELSE { - crossfadeGain = shl( crossfadeGain, exp ); + crossfadeGain = shl( crossfadeGain, exp ); // Q15 - e_crossfadeGain e_crossfadeGain = sub( e_crossfadeGain, exp ); *mdctSpectrum_exp = add( e_crossfadeGain, hTonalMDCTConc->lastBlockData.spectralData_exp ); move16(); @@ -1760,25 +1760,25 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 y = concealment_noise[l]; + Word32 y = concealment_noise[l]; // Q31-concealment_noise_e move32(); IF( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-concealment_noise_e- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp IF( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); - hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); + hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); // Q31 - 2*mdctSpectrum_exp move32(); } @@ -1786,41 +1786,41 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 y = concealment_noise[l]; + Word32 y = concealment_noise[l]; // Q31-concealment_noise_e move32(); L_tmp = Mpy_32_16_1( y, g ); - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp IF( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); - hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); + hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); // Q31- 2*mdctSpectrum_exp } } FOR( l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 y = concealment_noise[l]; + Word32 y = concealment_noise[l]; // Q31-concealment_noise_e move32(); - L_tmp = Mpy_32_16_1( y, g ); - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-concealment_noise_e- spectralData_exp + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp IF( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); - hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); + hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); // Q31- 2*mdctSpectrum_exp move32(); } @@ -1845,26 +1845,26 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( Word16 num_exp, den_exp; Word32 num, den; - num = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->last_block_nrg, hTonalMDCTConc->last_block_nrg_exp, L_negate( last_block_nrg_correct ), last_block_nrg_correct_e, &num_exp ); + num = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->last_block_nrg, hTonalMDCTConc->last_block_nrg_exp, L_negate( last_block_nrg_correct ), last_block_nrg_correct_e, &num_exp ); // Q31-num_exp - den = hTonalMDCTConc->faded_signal_nrg; + den = hTonalMDCTConc->faded_signal_nrg; // Q31 - hTonalMDCTConc->faded_signal_nrg_exp move32(); den_exp = hTonalMDCTConc->faded_signal_nrg_exp; move16(); ld = norm_l( num ); - num = L_shl( num, ld ); + num = L_shl( num, ld ); // Q31-num_exp + ld num_exp = sub( num_exp, ld ); ld = norm_l( den ); - den = L_shl( den, ld ); + den = L_shl( den, ld ); // Q31-den_exp + ld den_exp = sub( den_exp, ld ); exp = sub( num_exp, den_exp ); IF( GT_32( num, den ) ) { - num = L_shr( num, 1 ); + num = L_shr( num, 1 ); // Q31- exp -1 exp = add( exp, 1 ); } tmp = div_l( num, round_fx( den ) ); @@ -1872,7 +1872,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( FOR( i = 0; i < crossOverFreq; i++ ) { - mdctSpectrum[i] = Mpy_32_16_1( mdctSpectrum[i], tmp ); + mdctSpectrum[i] = Mpy_32_16_1( mdctSpectrum[i], tmp ); // Q31-(*mdctSpectrum_exp+exp) move32(); } *mdctSpectrum_exp = add( *mdctSpectrum_exp, exp ); @@ -1914,20 +1914,20 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( IF( nrgWhiteNoise > 0 ) { ld = norm_l( nrgNoiseInLastFrame ); - nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); + nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); // Q31- exp_last + ld exp_last = sub( exp_last, ld ); ld = norm_l( nrgWhiteNoise ); - nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); + nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); // Q31 - exp_noise + ld exp_noise = sub( exp_noise, ld ); exp = sub( exp_last, exp_noise ); IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) { - nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); + nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); // Q31-exp -1 exp = add( exp, 1 ); } - tmp = div_l( nrgNoiseInLastFrame, round_fx( nrgWhiteNoise ) ); + tmp = div_l( nrgNoiseInLastFrame, round_fx( nrgWhiteNoise ) ); // Q15 tmp = Sqrt16( tmp, &exp ); g = mult_r( g, tmp ); // exponent of g = exp @@ -1937,13 +1937,13 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( IF( exp > 0 ) { - g = shr( g, exp ); + g = shr( g, exp ); // Q15 - exp *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; move16(); } ELSE { - crossfadeGain = shl( crossfadeGain, exp ); + crossfadeGain = shl( crossfadeGain, exp ); // Q15-e_crossfadeGain+ exp e_crossfadeGain = sub( e_crossfadeGain, exp ); *mdctSpectrum_exp = add( e_crossfadeGain, hTonalMDCTConc->lastBlockData.spectralData_exp ); move16(); @@ -1964,29 +1964,29 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( } FOR( i = 0; i < crossOverFreq; i++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[i]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[i]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[i]; + Word32 const y = mdctSpectrum[i]; // Q31-mdctSpectrum_exp move32(); IF( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp IF( GT_32( y, 0 ) ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[i] = L_shl( L_tmp2, exp ); + mdctSpectrum[i] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } } exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, sub( *mdctSpectrum_exp, 16 ) ); FOR( i = crossOverFreq; i < hTonalMDCTConc->lastBlockData.nSamples; i++ ) { - mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), exp ); + mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), exp ); // Q15 - spectralData_exp + exp move32(); } } @@ -2002,12 +2002,12 @@ ELSE fac = shr( -32768, ld ); FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); // 15Q16 + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 + y = L_mult( tilt, rnd ); // 15Q16 nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - x_exp - ld) + Q(15 - x_exp) - 15 = Q(31 - x_exp * 2 - ld) x = round_fx( y ); // 15Q16 -> Q15 @@ -2036,12 +2036,12 @@ ELSE } FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 + y = L_mult( tilt, rnd ); // 15Q16 nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - hTonalMDCTConc->lastBlockData.spectralData_exp * 2 - ld) x = round_fx( y ); // Q15 @@ -2067,20 +2067,20 @@ ELSE FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 + y = L_mult( tilt, rnd ); // 15Q16 - nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); - x = round_fx( y ); - nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); + nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - hTonalMDCTConc->lastBlockData.spectralData_exp * 2 - ld) + x = round_fx( y ); // Q15 + nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(1 - ld) mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); - tilt = mult_r( tilt, tiltFactor ); + tilt = mult_r( tilt, tiltFactor ); // Q15 } IF( EQ_32( nrgNoiseInLastFrame, 0 ) ) @@ -2095,17 +2095,17 @@ ELSE exp_noise = add( ld, shl( 15, 1 ) ); ld = norm_l( nrgNoiseInLastFrame ); - nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); + nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); // Q31-exp_last+ld exp_last = sub( exp_last, ld ); ld = norm_l( nrgWhiteNoise ); - nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); + nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); // Q31 - exp_noise + ld exp_noise = sub( exp_noise, ld ); exp = sub( exp_last, exp_noise ); IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) { - nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); + nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); // Q31 - Qexp -1 exp = add( exp, 1 ); } tmp = div_l( nrgNoiseInLastFrame, extract_h( nrgWhiteNoise ) ); @@ -2117,7 +2117,7 @@ ELSE exp = sub( ld, exp ); IF( exp > 0 ) { - g = shr( g, exp ); + g = shr( g, exp ); // Q15 - exp *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; move16(); } @@ -2144,22 +2144,22 @@ ELSE FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); - IF( GT_16( g, 0 ) ) + IF( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); - IF( GT_32( y, 0 ) ) + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + IF( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } @@ -2167,22 +2167,22 @@ ELSE { FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); - IF( GT_16( g, 0 ) ) + IF( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); - IF( GT_32( y, 0 ) ) + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + IF( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } } @@ -2202,29 +2202,29 @@ ELSE FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); IF( GT_16( g, 0 ) ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp IF( GT_32( y, 0 ) ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } } exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, sub( *mdctSpectrum_exp, 16 ) ); FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), exp ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), exp ); // Q15 - spectralData_exp move32(); } } @@ -2241,12 +2241,12 @@ return; void TonalMDCTConceal_InsertNoise( const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32 *mdctSpectrum, /*OUT*/ + Word32 *mdctSpectrum, // Q31- *mdctSpectrum_exp /*OUT*/ Word16 *mdctSpectrum_exp, /*OUT*/ const Word16 tonalConcealmentActive, - Word16 *pSeed, /*IN/OUT*/ - const Word16 tiltCompFactor, - Word16 crossfadeGain, + Word16 *pSeed, /*IN/OUT*/ + const Word16 tiltCompFactor, // Q15 + Word16 crossfadeGain, // Q15 #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT const Word16concealment_noise[L_FRAME48k], const float cngLevelBackgroundTrace_bfi, @@ -2488,7 +2488,7 @@ void TonalMDCTConceal_InsertNoise( tiltFactor = round_fx( BASOP_Util_fPow( L_max( L_tmp, L_deposit_h( tiltCompFactor ) ), 0, L_deposit_h( inv_samples ), inv_exp, &exp ) ); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ #ifdef BASOP_NOGLOB - tiltFactor = shl_sat( tiltFactor, exp ); + tiltFactor = shl_sat( tiltFactor, exp ); // Q15- 2*exp #else tiltFactor = shl( tiltFactor, exp ); #endif @@ -2510,20 +2510,20 @@ void TonalMDCTConceal_InsertNoise( FOR( i = 0; i < crossOverFreq; i++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 + y = L_mult( tilt, rnd ); /* 15Q16 */ - nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); - x = round_fx( y ); - nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); + nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - hTonalMDCTConc->lastBlockData.spectralData_exp * 2 - ld) + x = round_fx( y ); // Q15 + nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(1 - ld) mdctSpectrum[i] = y; /* 15Q16 */ move32(); - tilt = mult_r( tilt, tiltFactor ); + tilt = mult_r( tilt, tiltFactor ); // Q15 } IF( nrgNoiseInLastFrame == 0 ) @@ -2540,17 +2540,17 @@ void TonalMDCTConceal_InsertNoise( IF( nrgWhiteNoise > 0 ) { ld = norm_l( nrgNoiseInLastFrame ); - nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); + nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); // Q31-exp_last + ld exp_last = sub( exp_last, ld ); ld = norm_l( nrgWhiteNoise ); - nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); + nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); // Q31-exp_noise + ld exp_noise = sub( exp_noise, ld ); exp = sub( exp_last, exp_noise ); IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) { - nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); + nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); // Q31- exp - 1 exp = add( exp, 1 ); } tmp = div_l( nrgNoiseInLastFrame, round_fx( nrgWhiteNoise ) ); @@ -2591,27 +2591,27 @@ void TonalMDCTConceal_InsertNoise( { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[i]; move16(); - Word32 const y = mdctSpectrum[i]; + Word32 const y = mdctSpectrum[i]; // Q31-mdctSpectrum_exp move32(); if ( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp if ( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[i] = L_shl( L_tmp2, exp ); + mdctSpectrum[i] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } } exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, sub( *mdctSpectrum_exp, 16 ) ); FOR( i = crossOverFreq; i < hTonalMDCTConc->lastBlockData.nSamples; i++ ) { - mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), exp ); + mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), exp ); // Q15 - spectralData_exp + exp move32(); } } @@ -2630,20 +2630,20 @@ void TonalMDCTConceal_InsertNoise( fac = shr( -32768, ld ); FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 + y = L_mult( tilt, rnd ); // 15Q16 - nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); - x = round_fx( y ); - nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); + nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - hTonalMDCTConc->lastBlockData.spectralData_exp * 2 - ld) + x = round_fx( y ); // Q15 + nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(1-ld) mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); - tilt = mult_r( tilt, tiltFactor ); + tilt = mult_r( tilt, tiltFactor ); // Q15 } FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) @@ -2661,27 +2661,27 @@ void TonalMDCTConceal_InsertNoise( FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 + y = L_mult( tilt, rnd ); // 15Q16 - nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); - x = round_fx( y ); - nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); + nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - hTonalMDCTConc->lastBlockData.spectralData_exp * 2 - ld) + x = round_fx( y ); // Q15 + nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(1-ld) mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); - tilt = mult_r( tilt, tiltFactor ); + tilt = mult_r( tilt, tiltFactor ); // Q15 } } tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, L_deposit_h( (UWord16) L_add( L_sub( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1] ), 1 ) ), 15, &exp ) ); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ #ifdef BASOP_NOGLOB - tmp = shl_sat( tmp, exp ); + tmp = shl_sat( tmp, exp ); // Q15 - 2*exp #else tmp = shl( tmp, exp ); #endif @@ -2690,20 +2690,20 @@ void TonalMDCTConceal_InsertNoise( FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 + y = L_mult( tilt, rnd ); // 15Q16 - nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); - x = round_fx( y ); - nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); + nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - hTonalMDCTConc->lastBlockData.spectralData_exp * 2 - ld) + x = round_fx( y ); // Q15 + nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(1-ld) mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); - tilt = mult_r( tilt, tiltFactor ); + tilt = mult_r( tilt, tiltFactor ); // Q15 } IF( nrgNoiseInLastFrame == 0 ) @@ -2718,17 +2718,17 @@ void TonalMDCTConceal_InsertNoise( exp_noise = add( ld, shl( 15, 1 ) ); ld = norm_l( nrgNoiseInLastFrame ); - nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); + nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); // Q31 - exp_last + ld exp_last = sub( exp_last, ld ); ld = norm_l( nrgWhiteNoise ); - nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); + nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); // Q31 - exp_last + ld exp_noise = sub( exp_noise, ld ); exp = sub( exp_last, exp_noise ); IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) { - nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); + nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); // Q31 - exp -1 exp = add( exp, 1 ); } tmp = div_l( nrgNoiseInLastFrame, round_fx( nrgWhiteNoise ) ); @@ -2766,22 +2766,22 @@ void TonalMDCTConceal_InsertNoise( FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); if ( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp if ( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } @@ -2789,22 +2789,22 @@ void TonalMDCTConceal_InsertNoise( { FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); if ( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp if ( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } } @@ -2824,29 +2824,29 @@ void TonalMDCTConceal_InsertNoise( FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); if ( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp if ( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } } exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, sub( *mdctSpectrum_exp, 16 ) ); FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), exp ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), exp ); // Q15 - spectralData_exp + exp move32(); } } @@ -2860,7 +2860,7 @@ void TonalMDCTConceal_InsertNoise( void TonalMDCTConceal_Apply( const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32 *mdctSpectrum, /*IN/OUT*/ + Word32 *mdctSpectrum, // Q31-*mdctSpectrum_exp /*IN/OUT*/ Word16 *mdctSpectrum_exp /*IN */ #ifdef IVAS_CODE_MDCT_GSHAPE , @@ -2964,7 +2964,7 @@ void TonalMDCTConceal_Apply( #ifdef IVAS_FLOAT_FIXED void TonalMDCTConceal_Apply_ivas_fx( TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32 *mdctSpectrum, /*IN/OUT*/ + Word32 *mdctSpectrum, // Q31-*mdctSpectrum_exp /*IN/OUT*/ Word16 mdctSpectrum_exp[L_FRAME_MAX], /*IN */ const PsychoacousticParameters *psychParamsCurrent ) @@ -2990,7 +2990,7 @@ void TonalMDCTConceal_Apply_ivas_fx( /* Creating 32-bit scaleFactors with common exponent. */ FOR( i = 0; i < FDNS_NPTS; i++ ) { - scaleFactors[i] = L_shr( L_deposit_h( hTonalMDCTConc->secondLastBlockData.scaleFactors[i] ), sub( hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ) ); + scaleFactors[i] = L_shr( L_deposit_h( hTonalMDCTConc->secondLastBlockData.scaleFactors[i] ), sub( hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ) ); // Q31- scaleFactors_max_e+scaleFactors_exp[i] move32(); } @@ -3004,7 +3004,7 @@ void TonalMDCTConceal_Apply_ivas_fx( FOR( i = 0; i < nSamples; i++ ) { - powerSpectrum[i] = L_deposit_h( tmp_secondLastPowerSpectrum[i] ); + powerSpectrum[i] = L_deposit_h( tmp_secondLastPowerSpectrum[i] ); // Q31 - secondLastPowerSpectrum_exp move16(); } powerSpectrum_exp = tmp_secondLastPowerSpectrum_exp; @@ -3030,7 +3030,7 @@ void TonalMDCTConceal_Apply_ivas_fx( q_ps = sub( q_ps, 1 ); FOR( Word16 c = 0; c < hTonalMDCTConc->nSamplesCore; c++ ) { - powerSpectrum[c] = L_shr( powerSpectrum[c], 1 ); + powerSpectrum[c] = L_shr( powerSpectrum[c], 1 ); // q_ps -1 move32(); } @@ -3038,7 +3038,7 @@ void TonalMDCTConceal_Apply_ivas_fx( q_sf = sub( q_sf, 1 ); FOR( Word16 c = 0; c < FDNS_NPTS; c++ ) { - scaleFactors[c] = L_shr( scaleFactors[c], 1 ); + scaleFactors[c] = L_shr( scaleFactors[c], 1 ); // q_sf - 1 move32(); } @@ -3057,7 +3057,7 @@ void TonalMDCTConceal_Apply_ivas_fx( FOR( Word16 c = hTonalMDCTConc->nSamplesCore; c < nSamples; c++ ) { - powerSpectrum[c] = Mpy_32_16_1( powerSpectrum[c], hTonalMDCTConc->secondLastBlockData.scaleFactors[nBands - 1] ); + powerSpectrum[c] = Mpy_32_16_1( powerSpectrum[c], hTonalMDCTConc->secondLastBlockData.scaleFactors[nBands - 1] ); // Q31 -(exp_right + scaleFactors_exp[]) move32(); } exp_right = add( exp_right, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[nBands - 1] ); @@ -3071,12 +3071,12 @@ void TonalMDCTConceal_Apply_ivas_fx( test(); IF( GE_16( c, hTonalMDCTConc->nSamplesCore ) && LT_16( c, nSamples ) && GT_16( max_e, exp_right ) ) { - powerSpectrum[c] = L_shr( powerSpectrum[c], sub( max_e, exp_right ) ); + powerSpectrum[c] = L_shr( powerSpectrum[c], sub( max_e, exp_right ) ); // Q31-max_e move32(); } ELSE IF( ( LT_16( c, hTonalMDCTConc->nSamplesCore ) || GT_16( c, nSamples ) ) && GT_16( max_e, exp_left ) ) { - powerSpectrum[c] = L_shr( powerSpectrum[c], sub( max_e, exp_left ) ); + powerSpectrum[c] = L_shr( powerSpectrum[c], sub( max_e, exp_left ) ); // Q31-max_e move32(); } } @@ -3146,7 +3146,7 @@ void TonalMDCTConceal_Apply_ivas_fx( void TonalMDCTConceal_SaveTimeSignal( TonalMDCTConcealPtr hTonalMDCTConc, - Word16 *timeSignal, + Word16 *timeSignal, // Qx Word16 nNewSamples ) @@ -3164,13 +3164,13 @@ void TonalMDCTConceal_SaveTimeSignal( return; } static void CalcPowerSpec( - const Word32 *mdctSpec, /* i: MDCT spectrum Q31,mdctSpec_exp */ + const Word32 *mdctSpec, /* i: MDCT spectrum Q31-mdctSpec_exp */ const Word16 mdctSpec_exp, /* i: exponent of MDCT spectrum */ - const Word32 *mdstSpec, /* i: MDST spectrum Q31,mdstSpec_exp */ + const Word32 *mdstSpec, /* i: MDST spectrum Q31-mdstSpec_exp */ const Word16 mdstSpec_exp, /* i: exponent of MDST spectrum */ const Word16 nSamples, /* i: frame size */ const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins Q0 */ - Word32 *powerSpec, /* o: power spectrum */ + Word32 *powerSpec, /* o: power spectrum Q31- powerSpec_exp */ Word16 *powerSpec_exp ) /* o: exponent of power spectrum */ { Word16 k, s1, s2, tmp; diff --git a/lib_dec/transition_dec_fx.c b/lib_dec/transition_dec_fx.c index 73342e64cbf6fae43e4e861709d9b7ec5705a6f1..ab6a76cacf9a870317e7e4528937128e37a9df34 100644 --- a/lib_dec/transition_dec_fx.c +++ b/lib_dec/transition_dec_fx.c @@ -37,19 +37,19 @@ static void tc_dec_fx( Decoder_State *st_fx, const Word16 L_frame, Word16 exc[], void transition_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 *Jopt_flag, /* i : joint optimization flag */ - Word16 *exc, /* o : excitation signal */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - Word16 **pt_pitch, /* o : floating pitch values */ - Word16 *position, /* i/o: first glottal impulse position in frame */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ + const Word16 L_frame, /* i : length of the frame Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ + const Word16 tc_subfr, /* i : TC subframe index Q0 */ + Word16 *Jopt_flag, /* i : joint optimization flag Q0*/ + Word16 *exc, /* o : excitation signal Q0 */ + Word16 *T0, /* o : close loop integer pitch Q0 */ + Word16 *T0_frac, /* o : close loop fractional part of the pitch Q0*/ + Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 Q0 */ + Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 Q0 */ + Word16 **pt_pitch, /* o : floating pitch values Q6 */ + Word16 *position, /* i/o: first glottal impulse position in frame Q0*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc */ Word16 *Q_exc /*i/o : scaling of excitation */ ) { @@ -110,8 +110,8 @@ void transition_dec_fx( /* glottal shape codebook contribution construction */ tc_dec_fx( st_fx, L_frame, exc, T0, T0_frac, i_subfr, tc_subfr, position, bwe_exc, Q_exc ); - **pt_pitch = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); - move16(); /* save subframe pitch values Q6 */ + **pt_pitch = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); // Q6 + move16(); /* save subframe pitch values Q6 */ *Jopt_flag = 1; move16(); @@ -620,14 +620,14 @@ void transition_dec_fx( static void tc_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 L_frame, /* i : length of the frame */ - Word16 exc[], /* o : glottal codebook contribution */ - Word16 *T0, /* o : close-loop pitch period */ - Word16 *T0_frac, /* o : close-loop pitch period - fractional part */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 *position, /* o : first glottal impulse position in frame */ - Word16 bwe_exc[], /* o : excitation for SWB TBE */ + const Word16 L_frame, /* i : length of the frame Q0*/ + Word16 exc[], /* o : glottal codebook contribution Q0*/ + Word16 *T0, /* o : close-loop pitch period Q0 */ + Word16 *T0_frac, /* o : close-loop pitch period - fractional part Q0 */ + const Word16 i_subfr, /* i : subframe index Q0*/ + const Word16 tc_subfr, /* i : TC subframe index Q0 */ + Word16 *position, /* o : first glottal impulse position in frame Q0*/ + Word16 bwe_exc[], /* o : excitation for SWB TBE Q_exc */ Word16 *Q_exc /*i/o : scaling of excitation */ ) { @@ -829,9 +829,9 @@ return; * TC subframe classification decoding *-------------------------------------------------------------------*/ -Word16 tc_classif_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 L_frame /* i : length of the frame */ +Word16 tc_classif_fx( /*o: Q0*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 L_frame /* i : length of the frame Q0 */ ) { Word16 tc_subfr, indice; diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 4c8df08998c6a0dccbf44138b33fe5c6642ad9d4..d21bde643519cc50e71a1cc135f844207764cdbb 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -17,14 +17,14 @@ *-------------------------------------------------------------------*/ void updt_dec_fx( Decoder_State *st_fx, /* i/o: state structure */ - const Word16 *old_exc_fx, /* i : buffer of excitation */ - const Word16 *pitch_buf_fx, /* i : fixed point pitch values for each subframe */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - const Word16 *Aq, /* i : A(z) quantized for all subframes */ - const Word16 *lsf_new_fx, /* i : current frame LSF vector */ - const Word16 *lsp_new_fx, /* i : current frame LSP vector */ - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 *old_bwe_exc_fx, /* i : buffer of excitation */ + const Word16 *old_exc_fx, /* i : buffer of excitation Q_exc */ + const Word16 *pitch_buf_fx, /* i : fixed point pitch values for each subframe Q6*/ + const Word16 Es_pred, /* i : predicited scaled innovation energy Q8*/ + const Word16 *Aq, /* i : A(z) quantized for all subframes Q12 */ + const Word16 *lsf_new_fx, /* i : current frame LSF vector Qlog2(2.56)*/ + const Word16 *lsp_new_fx, /* i : current frame LSP vector Q15*/ + const Word16 voice_factors[], /* i : voicing factors Q15*/ + const Word16 *old_bwe_exc_fx, /* i : buffer of excitation Q_syn*/ const Word16 *gain_buf /* i : fixed point pitch gain for each subframe Q14*/ ) { @@ -85,7 +85,7 @@ void updt_dec_fx( /* overwrite previous coding type to help FEC */ st_fx->last_coder_type = UNVOICED; move16(); - st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR - 1]; + st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR - 1]; // Q15 move16(); } @@ -131,32 +131,32 @@ void updt_dec_fx( Copy32( &st_fx->old_pitch_buf_fx[len], st_fx->old_pitch_buf_fx, len ); FOR( i = 0; i < len; i++ ) { - st_fx->old_pitch_buf_fx[len + i] = L_mult0( pitch_buf_fx[i], 1 << 10 ); + st_fx->old_pitch_buf_fx[len + i] = L_mult0( pitch_buf_fx[i], 1 << 10 ); /* 15Q16 */ move32(); } Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[add( st_fx->L_frame / L_SUBFR, 2 )], st_fx->L_frame / L_SUBFR ); IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - st_fx->mem_pitch_gain[2] = gain_buf[3]; + st_fx->mem_pitch_gain[2] = gain_buf[3]; // Q14 move16(); - st_fx->mem_pitch_gain[3] = gain_buf[2]; + st_fx->mem_pitch_gain[3] = gain_buf[2]; // Q14 move16(); - st_fx->mem_pitch_gain[4] = gain_buf[1]; + st_fx->mem_pitch_gain[4] = gain_buf[1]; // Q14 move16(); - st_fx->mem_pitch_gain[5] = gain_buf[0]; + st_fx->mem_pitch_gain[5] = gain_buf[0]; // Q14 move16(); } ELSE { - st_fx->mem_pitch_gain[2] = gain_buf[4]; + st_fx->mem_pitch_gain[2] = gain_buf[4]; // Q14 move16(); - st_fx->mem_pitch_gain[3] = gain_buf[3]; + st_fx->mem_pitch_gain[3] = gain_buf[3]; // Q14 move16(); - st_fx->mem_pitch_gain[4] = gain_buf[2]; + st_fx->mem_pitch_gain[4] = gain_buf[2]; // Q14 move16(); - st_fx->mem_pitch_gain[5] = gain_buf[1]; + st_fx->mem_pitch_gain[5] = gain_buf[1]; // Q14 move16(); - st_fx->mem_pitch_gain[6] = gain_buf[0]; + st_fx->mem_pitch_gain[6] = gain_buf[0]; // Q14 move16(); } @@ -268,7 +268,7 @@ void updt_IO_switch_dec_fx( fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx ); } hBWE_FD->prev_Energy_wb_fx = L_deposit_l( 0 ); - hBWE_FD->prev_weight_fx = 6554; + hBWE_FD->prev_weight_fx = 6554; /*0.2 in Q15*/ move16(); } @@ -294,7 +294,7 @@ void updt_IO_switch_dec_fx( /* reset the unvoiced/audio signal improvement memories */ if ( st_fx->hGSCDec != NULL ) { - st_fx->hGSCDec->seed_tcx = 15687; + st_fx->hGSCDec->seed_tcx = 15687; // Q0 move16(); } st_fx->hAmrwb_IO->UV_cnt_fx = 30; @@ -396,22 +396,22 @@ void updt_IO_switch_dec_fx( void updt_bw_switching_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *synth, /* i : fixed point synthesis signal */ + const Word16 *synth, /* i : fixed point synthesis signal Qpost */ const Word16 Qpost ) { test(); IF( EQ_32( st_fx->output_Fs, 32000 ) && EQ_16( st_fx->bwidth, SWB ) ) { #ifdef BASOP_NOGLOB - st_fx->tilt_swb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ), 3 ) ); + st_fx->tilt_swb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ), 3 ) ); // Q27 - 16 = Q11 #else st_fx->tilt_swb_fx = round_fx( L_shl( calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ), 3 ) ); #endif } - st_fx->prev_enerLH_fx = st_fx->enerLH_fx; + st_fx->prev_enerLH_fx = st_fx->enerLH_fx; // enerLH_fx_Q move32(); - st_fx->prev_enerLL_fx = st_fx->enerLL_fx; + st_fx->prev_enerLL_fx = st_fx->enerLL_fx; // enerLL_fx_Q move32(); st_fx->last_bwidth = st_fx->bwidth; move32(); @@ -453,7 +453,7 @@ void updt_dec_common_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 hq_core_type_fx, /* i : HQ core type */ const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ - const Word16 *synth, /* i : decoded synthesis */ + const Word16 *synth, /* i : decoded synthesis Qpostd */ const Word16 Qpostd /* i : Synthesis Q value */ ) @@ -771,7 +771,7 @@ void updt_dec_common_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_updt_bw_switching_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 *synth, /* i : fixed point synthesis signal */ + const Word32 *synth, /* i : fixed point synthesis signal Qpost */ const Word16 Qpost ) { test(); @@ -784,9 +784,9 @@ static void ivas_updt_bw_switching_fx( #endif } - st_fx->prev_enerLH_fx = st_fx->enerLH_fx; + st_fx->prev_enerLH_fx = st_fx->enerLH_fx; // enerLH_fx_Q move32(); - st_fx->prev_enerLL_fx = st_fx->enerLL_fx; + st_fx->prev_enerLL_fx = st_fx->enerLL_fx; // enerLL_fx_Q move32(); st_fx->last_bwidth = st_fx->bwidth; move32(); @@ -818,13 +818,13 @@ static void ivas_updt_bw_switching_fx( return; } -static Word32 sum_32_32_fx( const Word32 *x, Word16 length ) +static Word32 sum_32_32_fx( const Word32 *x, Word16 length ) // Qx { Word64 sum = 0; Word16 i; FOR( i = 0; i < length; i++ ) { - sum = W_add( sum, W_mult_32_32( x[i], x[i] ) ); + sum = W_add( sum, W_mult_32_32( x[i], x[i] ) ); // 2*Qx -1 } return W_round64_L( sum ); } @@ -833,7 +833,7 @@ void ivas_updt_dec_common_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 hq_core_type_fx, /* i : HQ core type */ const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ - const Word32 *synth, /* i : decoded synthesis Q(Qpostd) */ + const Word32 *synth, /* i : decoded synthesis Qpostd */ const Word16 Qpostd /* i : Synthesis Q value */ ) @@ -996,22 +996,22 @@ void ivas_updt_dec_common_fx( Word16 q_div = sub( Q31, shl( Qpostd, 1 ) ); Word16 output_frame = NS2SA_FX2( st_fx->output_Fs, FRAME_SIZE_NS ); move16(); - Word32 sum_val = sum_32_32_fx( synth, output_frame ); + Word32 sum_val = sum_32_32_fx( synth, output_frame ); // 2*Q_syn -1 Word32 div_val = BASOP_Util_Divide3232_Scale( sum_val, output_frame, &q_div ); Word32 log_energy = L_add( L_shl( L_deposit_l( add( q_div, sub( Q31, shl( Qpostd, 1 ) ) ) ), Q15 ), - L_shr( BASOP_Util_Log2( L_shl( L_add( div_val, EPSILON_FX ), Q16 ) ), Q10 ) ); - Word32 log_energy_diff = L_abs( L_sub( st_fx->log_energy_old_fx, log_energy ) ); - st_fx->log_energy_old_fx = log_energy; + L_shr( BASOP_Util_Log2( L_shl( L_add( div_val, EPSILON_FX ), Q16 ) ), Q10 ) ); // Q15 + Word32 log_energy_diff = L_abs( L_sub( st_fx->log_energy_old_fx, log_energy ) ); // Q15 + st_fx->log_energy_old_fx = log_energy; // Q15 move32(); - st_fx->log_energy_diff_lt_fx = Madd_32_16( Mpy_32_16_1( log_energy_diff, ENV_SMOOTH_FAC_FX ), st_fx->log_energy_diff_lt_fx, sub( MAX_16, ENV_SMOOTH_FAC_FX ) ); + st_fx->log_energy_diff_lt_fx = Madd_32_16( Mpy_32_16_1( log_energy_diff, ENV_SMOOTH_FAC_FX ), st_fx->log_energy_diff_lt_fx, sub( MAX_16, ENV_SMOOTH_FAC_FX ) ); // Q15 IF( EQ_16( st_fx->core, HQ_CORE ) ) { - st_fx->stab_fac_fx = extract_l( L_min( MAX_16, L_add( L_shr( STAB_FAC_EST1_FX, Q15 ), Madd_32_32( Mpy_32_16_1( STAB_FAC_EST2_FX, st_fx->hHQ_core->mem_env_delta ), STAB_FAC_EST3_FX, st_fx->log_energy_diff_lt_fx ) ) ) ); - st_fx->stab_fac_fx = s_max( 0, st_fx->stab_fac_fx ); + st_fx->stab_fac_fx = extract_l( L_min( MAX_16, L_add( L_shr( STAB_FAC_EST1_FX, Q15 ), Madd_32_32( Mpy_32_16_1( STAB_FAC_EST2_FX, st_fx->hHQ_core->mem_env_delta ), STAB_FAC_EST3_FX, st_fx->log_energy_diff_lt_fx ) ) ) ); // Q15 + st_fx->stab_fac_fx = s_max( 0, st_fx->stab_fac_fx ); // Q15 } st_fx->stab_fac_smooth_lt_fx = extract_h( L_add( L_mult( ENV_SMOOTH_FAC_FX, st_fx->stab_fac_fx ), - L_mult( sub( MAX_16, ENV_SMOOTH_FAC_FX ), st_fx->stab_fac_smooth_lt_fx ) ) ); + L_mult( sub( MAX_16, ENV_SMOOTH_FAC_FX ), st_fx->stab_fac_smooth_lt_fx ) ) ); // Q15 } #endif @@ -1209,9 +1209,10 @@ void ivas_updt_dec_common_fx( void update_decoder_LPD_cng( Decoder_State *st, Word16 coder_type, - Word16 *timeDomainBuffer, - Word16 *A, - Word16 *bpf_noise_buf ) + Word16 *timeDomainBuffer, /*QtimeDomainBuffer*/ + Word16 *A, /*Q12*/ + Word16 *bpf_noise_buf /*Qbpf_noise_buf*/ +) { Word16 i; Word16 lsp[M], lsf[M]; diff --git a/lib_dec/vlpc_1st_dec_fx.c b/lib_dec/vlpc_1st_dec_fx.c index ad2c3fc2cf423d14615050ab18ee208902c26ddd..cd79792c207981ca9af2b22a3c8cb62802b7f69e 100644 --- a/lib_dec/vlpc_1st_dec_fx.c +++ b/lib_dec/vlpc_1st_dec_fx.c @@ -11,17 +11,17 @@ #ifdef IVAS_FLOAT_FIXED void vlpc_1st_dec( Word16 index, /* input: codebook index */ - Word16 *lsfq ) /* i/o: i:prediction o:quantized lsf */ + Word16 *lsfq ) /* i/o: i:prediction o:quantized lsf 14Q1*1.28 */ { Word16 i; const Word16 *p_dico; assert( index < 256 ); - p_dico = &dico_lsf_abs_8b[index * M]; + p_dico = &dico_lsf_abs_8b[index * M]; /*14Q1*1.28*/ FOR( i = 0; i < M; i++ ) { - lsfq[i] = add( lsfq[i], *p_dico ); + lsfq[i] = add( lsfq[i], *p_dico ); /*14Q1*1.28*/ move16(); p_dico++; } diff --git a/lib_dec/vlpc_2st_dec_fx.c b/lib_dec/vlpc_2st_dec_fx.c index 6aacd0974d56211f85e72446a2d189fb64c885d6..74b53369ca3a7d236bb510d88982bc95d4fd62f6 100644 --- a/lib_dec/vlpc_2st_dec_fx.c +++ b/lib_dec/vlpc_2st_dec_fx.c @@ -12,7 +12,7 @@ #ifdef IVAS_FLOAT_FIXED void vlpc_2st_dec( - Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ + Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage 14Q1*1.28*/ Word16 *indx, /* i : index[] (4 bits per words) */ Word16 mode, /* i : 0=abs, >0=rel */ Word32 sr_core /* i : internal sampling rate */ diff --git a/lib_dec/voiced_dec_fx.c b/lib_dec/voiced_dec_fx.c index 761f904ea572818cd3969a69e599cf800b4607f7..c9ef8b473a87a2c18f28f45025541e6acc21f6c0 100644 --- a/lib_dec/voiced_dec_fx.c +++ b/lib_dec/voiced_dec_fx.c @@ -43,11 +43,11 @@ /*===================================================================*/ ivas_error ppp_voiced_decoder_fx( Decoder_State *st_fx, /* i/o: state structure */ - Word16 *out_fx, /* o : residual signal */ - const Word16 *lpc2_fx, /* i : current frame LPC */ - Word16 *exc_fx, /* i : previous frame excitation */ - Word16 *pitch, /* o : fixed point pitch values for each subframe */ - Word16 bfi /* i : Frame error rate */ + Word16 *out_fx, /* o : residual signal Q0*/ + const Word16 *lpc2_fx, /* i : current frame LPC Q12*/ + Word16 *exc_fx, /* i : previous frame excitation Q0*/ + Word16 *pitch, /* o : fixed point pitch values for each subframe Q6*/ + Word16 bfi /* i : Frame error rate Q0*/ ) { Word16 k, delta_lag_D = 0, temp, Ql, Qh, diff; @@ -258,7 +258,7 @@ ivas_error ppp_voiced_decoder_fx( Ltemp = DTFS_setEngyHarm_fx( 2828, upper_cut_off_freq_of_interest, 2828, upper_cut_off_freq, 1, 0, &Qh, TMPDTFS_FX ); - Ltemp = log10_fx( Ltemp ); + Ltemp = log10_fx( Ltemp ); // Q23 #ifdef BASOP_NOGLOB Ltemp = L_add_sat( L_sub_sat( Ltemp, Ltemp_q ), logLag ); /* Ltemp=10*log10(lag*eng), Q23 */ hSC_VBR->lastHgainD_fx = round_fx_sat( L_shl_sat( (Word32) Mpy_32_16( extract_h( Ltemp ), extract_l( Ltemp ), 0x6666 ), 1 ) ); /* Q11 */ diff --git a/lib_dec/waveadjust_fec_dec_fx.c b/lib_dec/waveadjust_fec_dec_fx.c index b090b22e5ff2df4015fe63c4f713baaf89e3f34b..070447cd4582f4dfe69bb0788ba9b8c07bd380ee 100644 --- a/lib_dec/waveadjust_fec_dec_fx.c +++ b/lib_dec/waveadjust_fec_dec_fx.c @@ -19,12 +19,12 @@ Word16 get_voicing_x( Word16 *s_LP, Word16 pitch, Word32 covMax, Word16 maxConv_ Word32 con_Log10( Word32 i_s32Val, Word16 i_s16Q ); Word16 Spl_GetScalingSquare_x( const Word16 *in_vector, const Word16 in_vector_length, Word16 times ); -Word16 vadmin( Word16 a, Word16 b ) +Word16 vadmin( Word16 a, Word16 b ) /*i/o: Qx */ { return s_min( a, b ); } -void set_state( Word16 *state, Word16 num, Word16 N ) +void set_state( Word16 *state, Word16 num, Word16 N ) /*i/o: Qx */ { Word16 i, tmp; @@ -38,7 +38,7 @@ void set_state( Word16 *state, Word16 num, Word16 N ) move16(); } -void concealment_update_x( Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 *invkoef, Word16 *invkoef_scale, void *_plcInfo ) +void concealment_update_x( Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 *invkoef /*Qinvkoef_scale*/, Word16 *invkoef_scale, void *_plcInfo ) { T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; Word32 *data_reci2 = plcInfo->data_reci2_fx; @@ -99,46 +99,46 @@ void concealment_update_x( Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 return; } -static Word16 zero_pass_w32_x( const Word16 *s, const Word16 N ) +static Word16 zero_pass_w32_x( const Word16 *s, const Word16 N ) /* i: Qx*/ /* o: 2*Qx-31*/ { Word16 i; Word32 temp, zp = L_deposit_l( 0 ); FOR( i = 1; i < N; i++ ) { - temp = L_mac0( -1L, s[i], s[i - 1] ); - zp = L_sub( zp, L_shr( temp, 31 ) ); + temp = L_mac0( -1L, s[i], s[i - 1] ); // 2*Qx + zp = L_sub( zp, L_shr( temp, 31 ) ); // 2*Qx-31 } return extract_l( zp ); } -Word16 Sqrt_x_fast( Word32 value ) +Word16 Sqrt_x_fast( Word32 value /*Qvalue*/ ) /*o : Q11-(2*norm+1)*/ { Word16 norm; Word16 result, index; norm = sub( 23, norm_l( value ) ); index = extract_l( L_shr_r( value, add( norm, s_and( norm, 1 ) ) ) ); - result = shr( sqrt_table_pitch_search[index], sub( 11, shr( add( norm, 1 ), 1 ) ) ); + result = shr( sqrt_table_pitch_search[index], sub( 11, shr( add( norm, 1 ), 1 ) ) ); // Q11-(2*norm+1) return result; } -Word32 dot_w32_accuracy_x( Word16 *s1, Word16 *s2, Word16 nbits, Word16 N ) +Word32 dot_w32_accuracy_x( Word16 *s1 /*Qs1*/, Word16 *s2 /*Qs2*/, Word16 nbits, Word16 N ) { Word16 i; Word32 eng = L_deposit_l( 0 ), temp; FOR( i = 0; i < N; i++ ) { - temp = L_mult0( s1[i], s2[i] ); - eng = L_add( eng, L_shr( temp, nbits ) ); + temp = L_mult0( s1[i], s2[i] ); /*Qs1+ Qs2*/ + eng = L_add( eng, L_shr( temp, nbits ) ); /*Qs1+ Qs2-nbits*/ } return eng; } -Word16 int_div_s_x( Word16 a, Word16 b ) +Word16 int_div_s_x( Word16 a, Word16 b ) /*i/o : Q0*/ { Word16 result = 0; Word16 norm, left = 0, i; @@ -170,7 +170,7 @@ Word16 int_div_s_x( Word16 a, Word16 b ) return result; } -Word16 GetW32Norm_x( Word32 *s, Word16 N ) +Word16 GetW32Norm_x( Word32 *s, Word16 N ) /*i : Qx, o: Q0*/ { Word32 smax = L_deposit_l( 0 ); Word16 smax_norm, i; @@ -185,7 +185,7 @@ Word16 GetW32Norm_x( Word32 *s, Word16 N ) return smax_norm; } -Word16 harmo_x( Word32 *X, Word16 Framesize, Word16 pitch ) +Word16 harmo_x( Word32 *X, Word16 Framesize, Word16 pitch ) /*i : Qx, o: Q15*/ { Word16 h, k, result = 0; Word32 ener = L_deposit_l( 0 ), ener_harmo = L_deposit_l( 0 ); @@ -229,7 +229,7 @@ Word16 harmo_x( Word32 *X, Word16 Framesize, Word16 pitch ) return result; } -static Word16 get_low_freq_eng_rate_x( Word32 *mdct_data, +static Word16 get_low_freq_eng_rate_x( Word32 *mdct_data, /*i: Qx*/ /*o: Q0*/ Word16 curr_mode, Word16 N ) { @@ -276,7 +276,7 @@ static Word16 get_low_freq_eng_rate_x( Word32 *mdct_data, return ( L_sub( low_eng, smax ) <= 0 ); } -void LpFilter2_x( Word16 *x, Word16 *y, Word16 N ) +void LpFilter2_x( Word16 *x, Word16 *y, Word16 N ) /*i/o : Qx*/ { Word16 i; Word16 smax, norm; @@ -305,7 +305,7 @@ void LpFilter2_x( Word16 *x, Word16 *y, Word16 N ) } } -void sig_tilt_x( Word16 *s, Word16 FrameSize, Word32 *enr1, Word32 *enr2 ) +void sig_tilt_x( Word16 *s /*Qx*/, Word16 FrameSize, Word32 *enr1 /*2*Qx-nbits*/, Word32 *enr2 /*2*Qx-nbits*/ ) { Word16 subFrameSize, shIFt; Word16 *p1, *p2; @@ -323,7 +323,7 @@ void sig_tilt_x( Word16 *s, Word16 FrameSize, Word32 *enr1, Word32 *enr2 ) move32(); } -void get_maxConv_and_pitch_x( Word16 *s_LP, Word16 s, Word16 e, Word16 N, Word32 *maxConv, Word16 *maxConv_bits, Word16 *pitch ) +void get_maxConv_and_pitch_x( Word16 *s_LP /*Qx*/, Word16 s /*Q0*/, Word16 e /*Q0*/, Word16 N, Word32 *maxConv /*2*Qx-nbits*/, Word16 *maxConv_bits, Word16 *pitch /*Q0*/ ) { Word16 t, cov_size, size = N; Word32 tmp_sigma = L_deposit_l( 0 ), cov_max_sigma = L_deposit_l( 0 ); @@ -399,7 +399,7 @@ void get_maxConv_and_pitch_x( Word16 *s_LP, Word16 s, Word16 e, Word16 N, Word32 move16(); } -Word16 get_voicing_x( Word16 *s_LP, Word16 pitch, Word32 covMax, Word16 maxConv_bits, Word16 Framesize ) +Word16 get_voicing_x( Word16 *s_LP /*Qx*/, Word16 pitch /*Q0*/, Word32 covMax /*2*Qx-nbits*/, Word16 maxConv_bits, Word16 Framesize ) /*o : Q15*/ { Word32 eng1 = L_deposit_l( 0 ), eng2 = L_deposit_l( 0 ); Word16 voicing, norm; @@ -447,7 +447,7 @@ Word16 get_voicing_x( Word16 *s_LP, Word16 pitch, Word32 covMax, Word16 maxConv_ } } -void pitch_modify_x( Word16 *s_LP, Word16 *voicing, Word16 *pitch, Word16 FrameSize ) +void pitch_modify_x( Word16 *s_LP /*Qx*/, Word16 *voicing /*Q15*/, Word16 *pitch /*Q0*/, Word16 FrameSize ) { Word32 eng1, eng2, eng3; Word16 shIFt = shr( *pitch, 1 ); @@ -513,7 +513,7 @@ void pitch_modify_x( Word16 *s_LP, Word16 *voicing, Word16 *pitch, Word16 FrameS } } -Word16 Is_Periodic_x( Word32 *mdct_data, Word16 cov_max, Word16 zp, Word32 ener, Word32 ener_mean, Word16 pitch, Word16 Framesize ) +Word16 Is_Periodic_x( Word32 *mdct_data /*Qx*/, Word16 cov_max /*Q15*/, Word16 zp, Word32 ener /*Q8*/, Word32 ener_mean /*Q8*/, Word16 pitch /*Q0*/, Word16 Framesize ) /*o: Q0*/ { Word16 flag = 0; Word16 harm; @@ -561,7 +561,7 @@ Word16 Is_Periodic_x( Word32 *mdct_data, Word16 cov_max, Word16 zp, Word32 ener, return flag; } -Word16 get_conv_relation_x( Word16 *s_LP, Word16 shIFt, Word16 N ) +Word16 get_conv_relation_x( Word16 *s_LP /*Qx*/, Word16 shIFt, Word16 N ) /*o :Q0*/ { Word32 eng1, eng2, eng3; Word16 eng1_w, eng2_w; @@ -607,14 +607,14 @@ Word16 get_conv_relation_x( Word16 *s_LP, Word16 shIFt, Word16 N ) return tmp; } -static Word16 pitch_search_fx( Word16 *s, /* lastPcmOut */ - Word16 *outx_new, +static Word16 pitch_search_fx( Word16 *s /*Qs*/, /* lastPcmOut */ + Word16 *outx_new /*Qoutx_new*/, Word16 Framesize, - Word16 *voicing, - Word16 zp, - Word32 ener, - Word32 ener_mean, - Word32 *mdct_data, + Word16 *voicing /*Q15*/, + Word16 zp, /*Q0*/ + Word32 ener /*Q8*/, + Word32 ener_mean /*Q8*/, + Word32 *mdct_data /*Qmdct*/, Word16 curr_mode ) { Word16 pitch = 0; @@ -901,14 +901,14 @@ void concealment_init_ivas_fx( #endif // IVAS_FLOAT_FIXED static Word16 own_random_fix( /* o : output random value */ - Word16 *seed /* i/o: random seed */ + Word16 *seed /* i/o: random seed Q0 */ ) { *seed = extract_l( L_mac0( 13849L, *seed, 31821 ) ); return ( *seed ); } -void concealment_decode_fix( Word16 curr_mode, Word32 *invkoef, Word16 *invkoef_scale, void *_plcInfo ) +void concealment_decode_fix( Word16 curr_mode, Word32 *invkoef /*Qinvkoef_scale*/, Word16 *invkoef_scale, void *_plcInfo ) { T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; Word16 i; @@ -940,7 +940,7 @@ void concealment_decode_fix( Word16 curr_mode, Word32 *invkoef, Word16 *invkoef_ } -Word16 Spl_GetScalingSquare_x( const Word16 *in_vector, const Word16 in_vector_length, Word16 times ) +Word16 Spl_GetScalingSquare_x( const Word16 *in_vector /*Qin_vector*/, const Word16 in_vector_length, Word16 times ) /*o : Q0*/ { Word16 nbits = sub( 15, norm_s( times ) ) /*Spl_GetSizeInBits_x(times)*/; Word16 i; @@ -973,7 +973,7 @@ Word16 Spl_GetScalingSquare_x( const Word16 *in_vector, const Word16 in_vector_l } -Word32 Spl_Energy_x( const Word16 *vector, const Word16 vector_length, Word16 *scale_factor ) +Word32 Spl_Energy_x( const Word16 *vector /*Qvector*/, const Word16 vector_length, Word16 *scale_factor ) { Word32 en = L_deposit_l( 0 ); Word32 i; @@ -990,7 +990,7 @@ Word32 Spl_Energy_x( const Word16 *vector, const Word16 vector_length, Word16 *s return en; } -void Log10OfEnergy_x( const Word16 *s, Word32 *enerlogval, const Word16 len ) +void Log10OfEnergy_x( const Word16 *s /* Qs */, Word32 *enerlogval /* Q8 */, const Word16 len ) { Word32 energy = L_deposit_l( 0 ), tmp2 = L_deposit_l( 0 ); Word16 shfts = 0; @@ -1013,7 +1013,7 @@ void Log10OfEnergy_x( const Word16 *s, Word32 *enerlogval, const Word16 len ) } } -static Word32 fnLog2( Word32 L_Input ) +static Word32 fnLog2( Word32 L_Input /*QL_Input*/ ) /*o :Q26*/ { Word16 swC0 = -0x2b2a, swC1 = 0x7fc5, swC2 = -0x54d0; @@ -1067,7 +1067,7 @@ static Word32 fnLog2( Word32 L_Input ) return ( LwIn ); } -static Word32 fnLog10( Word32 L_Input ) +static Word32 fnLog10( Word32 L_Input /*QL_Input*/ ) /*o :Q26*/ { Word16 Scale = 9864; /* 0.30103 = log10(2) */ @@ -1088,7 +1088,7 @@ static Word32 fnLog10( Word32 L_Input ) return ( LwIn ); } -Word32 con_Log10( Word32 i_s32Val, Word16 i_s16Q ) +Word32 con_Log10( Word32 i_s32Val /*Qi_s32Val*/, Word16 i_s16Q /*Q0*/ ) /*o; Q26*/ { Word32 s32Out; Word32 s32Correct; /* corrected (31-q)*log10(2) */ @@ -1111,7 +1111,7 @@ Word32 con_Log10( Word32 i_s32Val, Word16 i_s16Q ) return s32Out; } -void concealment_update2_x( const Word16 *outx_new, void *_plcInfo, const Word16 FrameSize ) +void concealment_update2_x( const Word16 *outx_new /*Qoutx_new*/, void *_plcInfo, const Word16 FrameSize ) { T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; @@ -1129,7 +1129,7 @@ void concealment_update2_x( const Word16 *outx_new, void *_plcInfo, const Word16 return; } -static Word16 array_max_indx_fx( Word16 *s, Word16 N ) +static Word16 array_max_indx_fx( Word16 *s /*Qs*/, Word16 N ) { Word16 i, indx = 0; move16(); @@ -1145,7 +1145,7 @@ static Word16 array_max_indx_fx( Word16 *s, Word16 N ) } Word16 ffr_getSfWord16( /* o: measured headroom in range [0..15], 0 IF all x[i] == 0 */ - Word16 *x, /* i: array containing 16-bit data */ + Word16 *x, /* i: array containing 16-bit data Qx*/ Word16 len_x ) /* i: length of the array to scan */ { Word16 i, i_min, i_max; @@ -1189,7 +1189,7 @@ Word16 ffr_getSfWord16( /* o: measured headroom in range [0..15], return i; } -static Word16 OverlapAdd_fx( Word16 *pitch125_data, Word16 *sbuf, Word16 n, Word16 pitch, Word16 Framesize ) +static Word16 OverlapAdd_fx( Word16 *pitch125_data /*Qx*/, Word16 *sbuf /*Qx*/, Word16 n, Word16 pitch /*Q0*/, Word16 Framesize ) { Word16 n1, n2, s, s16MaxCoefNorm, s16MaxCoefNorm2, tmp16; Word16 i; @@ -1236,12 +1236,12 @@ static Word16 OverlapAdd_fx( Word16 *pitch125_data, Word16 *sbuf, Word16 n, Word return pitch; } -static void add_noise( Word16 *const sbuf, - Word16 *const outx_new_n1, - Word16 const *const noise_seg, +static void add_noise( Word16 *const sbuf, /*Qsbuf*/ + Word16 *const outx_new_n1, /*Q0*/ + Word16 const *const noise_seg, /*Q0*/ Word16 const Len, - Word16 *const gain, - Word16 const *const gain_n, + Word16 *const gain, /*Q15*/ + Word16 const *const gain_n, /*Q15*/ Word8 const firstFrame ) { Word16 i; @@ -1283,18 +1283,18 @@ static void add_noise( Word16 *const sbuf, return; } -static Word16 waveform_adj_fix( Word16 *overlapbuf, - Word16 *outdata2, - Word16 *outx_new, - Word16 *data_noise, - Word16 *outx_new_n1, - Word16 *nsapp_gain, - Word16 *nsapp_gain_n, +static Word16 waveform_adj_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ + Word16 *outdata2, /*Qoutdata2*/ + Word16 *outx_new, /*Qoutx_new*/ + Word16 *data_noise, /*Qoutx_new*/ + Word16 *outx_new_n1, /*Q0*/ + Word16 *nsapp_gain, /*Q15*/ + Word16 *nsapp_gain_n, /*Q15*/ Word16 Framesize, Word8 T_bfi, - Word16 voicing, + Word16 voicing, /*Q15*/ Word16 curr_mode, - Word16 pitch ) + Word16 pitch /*Q0*/ ) { Word16 i, zp1, zp2, Framesizediv2, s16MaxCoefNorm; Word16 sbuf[L_FRAME_MAX]; @@ -1429,15 +1429,15 @@ static Word16 waveform_adj_fix( Word16 *overlapbuf, return pitch; } -void waveform_adj2_fix( Word16 *overlapbuf, - Word16 *outx_new, - Word16 *data_noise, - Word16 *outx_new_n1, - Word16 *nsapp_gain, - Word16 *nsapp_gain_n, - Word16 *recovery_gain, - Word16 step_concealgain, - Word16 pitch, +void waveform_adj2_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ + Word16 *outx_new, /*Qoutx_new*/ + Word16 *data_noise, /*Qoutx_new*/ + Word16 *outx_new_n1, /*Q0*/ + Word16 *nsapp_gain, /*Q15*/ + Word16 *nsapp_gain_n, /*Q15*/ + Word16 *recovery_gain, /*Q14*/ + Word16 step_concealgain, /*Q15*/ + Word16 pitch, /*Q0*/ Word16 Framesize, Word16 delay, Word16 bfi_cnt, @@ -1612,7 +1612,7 @@ void waveform_adj2_fix( Word16 *overlapbuf, return; } -void concealment_signal_tuning_fx( Word16 bfi, Word16 curr_mode, Word16 *outx_new_fx, void *_plcInfo, Word16 nbLostCmpt, Word16 pre_bfi, Word16 *OverlapBuf_fx, Word16 past_core_mode, Word16 *outdata2_fx, Decoder_State *st ) +void concealment_signal_tuning_fx( Word16 bfi, Word16 curr_mode, Word16 *outx_new_fx /*Qoutx_new_fx*/, void *_plcInfo, Word16 nbLostCmpt, Word16 pre_bfi, Word16 *OverlapBuf_fx /*QOverlapBuf_fx*/, Word16 past_core_mode, Word16 *outdata2_fx /*Qoutdata2_fx*/, Decoder_State *st ) { T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; Word16 FrameSize = plcInfo->FrameSize; diff --git a/lib_enc/FEC_enc.c b/lib_enc/FEC_enc.c index fe61b552d52fbf9c35c2988c78e592f14ca22322..d011b596198cbfc9e8805b990abc8f30dd2a811e 100644 --- a/lib_enc/FEC_enc.c +++ b/lib_enc/FEC_enc.c @@ -217,7 +217,7 @@ void FEC_encode_ivas_fx( return; } -#endif +#else void FEC_encode( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP */ @@ -350,7 +350,9 @@ void FEC_encode( return; } +#endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * FEC_lsf_estim_enc() * @@ -438,3 +440,4 @@ void FEC_lsf_estim_enc( return; } +#endif diff --git a/lib_enc/SNR_calc.c b/lib_enc/SNR_calc.c index 7e9f297aa13ff0ea1c29a52855b044f7038fd92e..0f8376c5233ee74135547774affdd5bb44fcb93f 100644 --- a/lib_enc/SNR_calc.c +++ b/lib_enc/SNR_calc.c @@ -42,6 +42,7 @@ #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * SNR_calc() * @@ -259,3 +260,4 @@ void calc_lf_snr( return; } +#endif diff --git a/lib_enc/SNR_calc_fx.c b/lib_enc/SNR_calc_fx.c index 674467cf4f6b249b5805f5a9865f11aeea324d88..320a68d255f539a42d1f543642c5abcd85a10863 100644 --- a/lib_enc/SNR_calc_fx.c +++ b/lib_enc/SNR_calc_fx.c @@ -72,15 +72,15 @@ void calc_lf_snr_fx( * *-------------------------------------------------------------------*/ void calc_lt_snr_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word32 *lt_snr_org_fp, /* o : original long time SNR*/ - Word32 *lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy*/ - Word32 fg_energy, /* i : foreground energy sum */ - Word16 fg_energy_count, /* i : amount of the foreground energy frame */ - Word32 bg_energy, /* i : background energy sum */ - Word16 bg_energy_count, /* i : amount of the background energy frame */ - Word16 bw_index, /* i : band width index*/ - Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32 *lt_snr_org_fp, /* o : original long time SNR*/ + Word32 *lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy*/ + Word32 fg_energy, /* i : foreground energy sum */ + Word16 fg_energy_count, /* i : amount of the foreground energy frame */ + Word32 bg_energy, /* i : background energy sum */ + Word16 bg_energy_count, /* i : amount of the background energy frame */ + Word16 bw_index, /* i : band width index*/ + Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0*/ ) { Word16 tmp_lt_noise_sp_center; @@ -229,12 +229,12 @@ void calc_snr_flux_fx( * *-------------------------------------------------------------------*/ void snr_calc( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - const Word16 sacle_sbpower, /* i : the Scaling of sbpower*/ - Word32 *snr, /* o : frequency domain SNR */ - Word32 *tsnr, /* o : time domain SNR */ - const Word32 frame_energy, /* i : current frame energy */ - const Word32 bwidth /* i : audio band width*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + const Word16 sacle_sbpower, /* i : the Scaling of sbpower*/ + Word32 *snr, /* o : frequency domain SNR */ + Word32 *tsnr, /* o : time domain SNR */ + const Word32 frame_energy, /* i : current frame energy */ + const Word32 bwidth /* i : audio band width*/ ) { Word32 i; diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 5e967443d40601a0d5cde2b5ed3dd76680095f15..a814ff029aadd8406387f08c45a1bffe6362a578 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -168,7 +168,9 @@ ivas_error acelp_core_enc( // Word16 next_force_sf_bck_fx; Word32 q_env_fx[NUM_ENV_CNG]; // Word16 coder_type; - +#ifdef MSAN_FIX + set32_fx( q_env_fx, 0, NUM_ENV_CNG ); +#endif Word16 exc3_fx[L_FRAME16k]; Word16 syn1_fx[L_FRAME16k]; Word16 *tdm_Pri_pitch_buf_fx; @@ -230,7 +232,6 @@ ivas_error acelp_core_enc( floatToFixed_arr( &inp[-M - 1], &inp_fx[-M - 1], Q_new, L_FRAME16k + M + 1 ); floatToFixed_arrL( st->Bin_E_old, st->Bin_E_old_fx, Q_new + Q_SCALE - 2, 128 ); floatToFixed_arrL( st->Bin_E, st->Bin_E_fx, Q_new + Q_SCALE - 2, 256 ); - st->stab_fac_fx = float_to_fix16( st->stab_fac, Q15 ); IF( hStereoTD ) { floatToFixed_arr( hStereoTD->tdm_Pri_pitch_buf, hStereoTD->tdm_Pri_pitch_buf_fx, Q6, 4 ); @@ -337,7 +338,11 @@ ivas_error acelp_core_enc( move16(); /* channel-aware mode */ +#ifndef IVAS_FLOAT_FIXED reset_rf_indices( st->hRF, st->L_frame, &st->rf_target_bits_write ); +#else + reset_rf_indices_fx( st ); +#endif /* VBR modes */ IF( st->Opt_SC_VBR ) @@ -499,25 +504,13 @@ ivas_error acelp_core_enc( floatToFixed_arr( Aq, Aq_fx, NB_SUBFR16k * ( M + 1 ), Q12 ); q_inp = Q_factor_arr( inp, st->L_frame ); floatToFixed_arr( inp, inp_fx, q_inp, st->L_frame ); - st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 ); floatToFixed_arr( lsp_mid, lsp_mid_fx, Q15, M ); floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); - floatToFixed_arr( st->hTdCngEnc->ho_lsp_hist, st->hTdCngEnc->ho_lsp_hist_fx, Q15, HO_HIST_SIZE * M ); floatToFixed_arr( st->hTdCngEnc->ho_lsp_circ, st->hTdCngEnc->ho_lsp_circ_fx, Q15, HO_HIST_SIZE * M ); floatToFixed_arr( st->hTdCngEnc->ho_lsp_circ2, st->hTdCngEnc->ho_lsp_circ2_fx, Q15, HO_HIST_SIZE * M ); - floatToFixed_arrL( st->hTdCngEnc->ho_ener_hist, st->hTdCngEnc->ho_ener_hist_fx, Q6, HO_HIST_SIZE ); floatToFixed_arrL( st->hTdCngEnc->ho_ener_circ, st->hTdCngEnc->ho_ener_circ_fx, Q6, HO_HIST_SIZE ); - floatToFixed_arr( st->hTdCngEnc->cng_ener_hist, st->hTdCngEnc->cng_ener_hist_fx, Q8, DTX_HIST_SIZE ); - floatToFixed_arr( st->hDtxEnc->lspCNG, st->hDtxEnc->lspCNG_fx, Q15, M ); - floatToFixed_arrL( st->hTdCngEnc->cng_res_env, st->hTdCngEnc->cng_res_env_fx, Q6, NUM_ENV_CNG * HO_HIST_SIZE ); - floatToFixed_arr( st->hTdCngEnc->cng_lsp_hist, st->hTdCngEnc->cng_lsp_hist_fx, Q15, DTX_HIST_SIZE * M ); - floatToFixed_arrL( st->hTdCngEnc->lp_env, st->hTdCngEnc->lp_env_fx, Q6, NUM_ENV_CNG ); - floatToFixed_arrL( st->hTdCngEnc->ho_env_hist, st->hTdCngEnc->ho_env_hist_fx, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); floatToFixed_arr( st->hTdCngEnc->exc_mem2, st->hTdCngEnc->exc_mem2_fx, q_inp, 30 ); - st->hTdCngEnc->lp_ener_fx = float_to_fix( st->hTdCngEnc->lp_ener, Q6 ); - st->hTdCngEnc->Enew_fx = float_to_fix( st->hTdCngEnc->Enew, Q6 ); - st->hTdCngEnc->lp_sp_enr_fx = float_to_fix16( st->hTdCngEnc->lp_sp_enr, Q8 ); for ( i = 0; i < M; i++ ) { lsf_new_fx[i] = (Word16) ( lsf_new[i] * 2.56f ); @@ -531,23 +524,11 @@ ivas_error acelp_core_enc( fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); fixedToFloat_arrL32( q_env_fx, q_env, Q6, NUM_ENV_CNG ); fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); - fixedToFloat_arr( st->hDtxEnc->lspCNG_fx, st->hDtxEnc->lspCNG, Q15, M ); fixedToFloat_arr( st->hTdCngEnc->ho_lsp_circ_fx, st->hTdCngEnc->ho_lsp_circ, Q15, HO_HIST_SIZE * M ); fixedToFloat_arr( st->hTdCngEnc->ho_lsp_circ2_fx, st->hTdCngEnc->ho_lsp_circ2, Q15, HO_HIST_SIZE * M ); - fixedToFloat_arr( st->hTdCngEnc->ho_lsp_hist_fx, st->hTdCngEnc->ho_lsp_hist, Q15, HO_HIST_SIZE * M ); fixedToFloat_arrL( st->hTdCngEnc->ho_env_circ_fx, st->hTdCngEnc->ho_env_circ, Q6, 160 ); - fixedToFloat_arrL( st->hTdCngEnc->cng_res_env_fx, st->hTdCngEnc->cng_res_env, Q6, NUM_ENV_CNG * HO_HIST_SIZE ); - fixedToFloat_arr( st->hTdCngEnc->cng_ener_hist_fx, st->hTdCngEnc->cng_ener_hist, Q8, DTX_HIST_SIZE ); - fixedToFloat_arrL( st->hTdCngEnc->ho_ener_hist_fx, st->hTdCngEnc->ho_ener_hist, Q6, HO_HIST_SIZE ); fixedToFloat_arrL( st->hTdCngEnc->ho_ener_circ_fx, st->hTdCngEnc->ho_ener_circ, Q6, HO_HIST_SIZE ); - fixedToFloat_arr( st->hTdCngEnc->cng_lsp_hist_fx, st->hTdCngEnc->cng_lsp_hist, Q15, DTX_HIST_SIZE * M ); - fixedToFloat_arrL( st->hTdCngEnc->lp_env_fx, st->hTdCngEnc->lp_env, Q6, NUM_ENV_CNG ); - fixedToFloat_arrL( st->hTdCngEnc->ho_env_hist_fx, st->hTdCngEnc->ho_env_hist, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); fixedToFloat_arr( st->hTdCngEnc->exc_mem2_fx, st->hTdCngEnc->exc_mem2, q_inp, 30 ); - st->hTdCngEnc->lp_sp_enr = fix16_to_float( st->hTdCngEnc->lp_sp_enr_fx, Q8 ); - st->hTdCngEnc->lp_ener = fix_to_float( st->hTdCngEnc->lp_ener_fx, Q6 ); - st->hTdCngEnc->Enew = fix_to_float( st->hTdCngEnc->Enew_fx, Q6 ); - st->hTdCngEnc->CNG_att = fix16_to_float( st->hTdCngEnc->CNG_att_fx, Q7 ); for ( i = 0; i < M; i++ ) { lsf_new[i] = ( (float) lsf_new_fx[i] / 2.56f ); @@ -562,11 +543,7 @@ ivas_error acelp_core_enc( #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->hTdCngEnc->Enew_fx = float_to_fix( st->hTdCngEnc->Enew, Q6 ); - st->hTdCngEnc->lp_ener_fx = float_to_fix( st->hTdCngEnc->lp_ener, Q6 ); floatToFixed_arr32( q_env, q_env_fx, Q6, NUM_ENV_CNG ); - floatToFixed_arr32( st->hTdCngEnc->lp_env, st->hTdCngEnc->lp_env_fx, Q6, NUM_ENV_CNG ); - floatToFixed_arr32( st->hTdCngEnc->old_env, st->hTdCngEnc->old_env_fx, Q6, NUM_ENV_CNG ); // Word16 Q_exc_l = Q_factor_arr( st->hTdCngEnc->exc_mem, 24 ); // Word16 Q_exc1_l = Q_factor_arr( st->hTdCngEnc->exc_mem1, 30 ); // Q_exc_l = min( Q_exc_l, Q_exc1_l ); @@ -583,11 +560,7 @@ ivas_error acelp_core_enc( q_env_fx, st->hTdCngEnc->lp_env_fx, st->hTdCngEnc->old_env_fx, st->hTdCngEnc->exc_mem_fx, st->hTdCngEnc->exc_mem1_fx, &sid_bw, &st->hTdCngEnc->cng_ener_seed1, exc3_fx, st->Opt_AMR_WB, EVS_MONO ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->hTdCngEnc->Enew = fixedToFloat( st->hTdCngEnc->Enew_fx, Q6 ); - st->hTdCngEnc->lp_ener = fixedToFloat( st->hTdCngEnc->lp_ener_fx, Q6 ); fixedToFloat_arrL( q_env_fx, q_env, Q6, NUM_ENV_CNG ); - fixedToFloat_arrL( st->hTdCngEnc->lp_env_fx, st->hTdCngEnc->lp_env, Q6, NUM_ENV_CNG ); - fixedToFloat_arrL( st->hTdCngEnc->old_env_fx, st->hTdCngEnc->old_env, Q6, NUM_ENV_CNG ); fixedToFloat_arr( exc_fx, exc, Q_new, st->L_frame ); fixedToFloat_arr( exc2_fx, exc2, Q_new, st->L_frame ); fixedToFloat_arr( exc3_fx, exc3, Q_new, st->L_frame ); @@ -616,10 +589,6 @@ ivas_error acelp_core_enc( Word16 Q_cngNoise = Q_factor_arrL( st->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, FFTCLDFBLEN ); floatToFixed_arrL( st->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, st->hFdCngEnc->hFdCngCom->cngNoiseLevel, Q_cngNoise, FFTCLDFBLEN ); st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp = sub( 31, Q_cngNoise ); - IF( st->hTdCngEnc != NULL ) - { - st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 ); - } st->preemph_fac = float_to_fix16( st->preemph_fac_flt, Q15 ); #endif // generate_comfort_noise_enc( st ); @@ -637,7 +606,6 @@ ivas_error acelp_core_enc( // Word16 Q_exc_cng_l = Q_factor_arr( st->hFdCngEnc->hFdCngCom->exc_cng_flt, st->L_frame ); floatToFixed_arr( st->hFdCngEnc->hFdCngCom->exc_cng_flt, st->hFdCngEnc->hFdCngCom->exc_cng, Q_new, st->L_frame ); floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); - floatToFixed_arr( st->hDtxEnc->lspCNG, st->hDtxEnc->lspCNG_fx, Q15, M ); #endif // FdCng_exc_flt( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG, Aq, lsp_new, lsf_new, exc, exc2, bwe_exc ); FdCng_exc( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old_fx, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); @@ -649,7 +617,6 @@ ivas_error acelp_core_enc( lsf_new[i] = ( (float) lsf_new_fx[i] / 2.56f ); } - fixedToFloat_arr( st->hDtxEnc->lspCNG_fx, st->hDtxEnc->lspCNG, Q15, M ); fixedToFloat_arr( exc_fx, exc, Q_new, st->L_frame ); fixedToFloat_arr( exc2_fx, exc2, Q_new, st->L_frame ); IF( st->hBWE_TD != NULL ) @@ -666,7 +633,6 @@ ivas_error acelp_core_enc( { Word16 enr, enr_index; #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 ); // Word16 Q_exc_l = Q_factor_arr( exc, st->L_frame ); floatToFixed_arr( exc, exc_fx, Q_new, st->L_frame ); #endif @@ -703,14 +669,14 @@ ivas_error acelp_core_enc( Q_syn_l = Q_factor_arr( hLPDmem->mem_syn3_flt, M ); floatToFixed_arr( hLPDmem->mem_syn3_flt, hLPDmem->mem_syn3, Q_syn_l, M ); - floatToFixed_arr( Aq, Aq_fx, NB_SUBFR16k * ( M + 1 ), Q12 ); + floatToFixed_arr( Aq, Aq_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); #endif /* synthesis at 12.8kHz sampling rate */ syn_12k8_fx( st->L_frame, Aq_fx, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, Q_exc_l, Q_syn_l ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( Aq_fx, Aq, NB_SUBFR16k * ( M + 1 ), Q12 ); - fixedToFloat_arr( exc3_fx, exc, st->L_frame, Q_exc_l ); + fixedToFloat_arr( Aq_fx, Aq, Q12, NB_SUBFR16k * ( M + 1 ) ); + fixedToFloat_arr( exc3_fx, exc, Q_exc_l, st->L_frame ); fixedToFloat_arr( hLPDmem->mem_syn3, hLPDmem->mem_syn3_flt, Q_syn_l, M ); fixedToFloat_arr( syn1_fx, syn1, Q_syn_l, st->L_frame ); #endif @@ -793,10 +759,6 @@ ivas_error acelp_core_enc( } } - IF( st->hDtxEnc ) - { - floatToFixed_arr( st->hDtxEnc->lspCNG, st->hDtxEnc->lspCNG_fx, Q15, M ); - } for ( i = 0; i < M; i++ ) { st->lsf_old_fx[i] = (Word16) ( st->lsf_old[i] * 2.56f ); @@ -816,8 +778,6 @@ ivas_error acelp_core_enc( st->clip_var_fx[3] = float_to_fix16( st->clip_var[3], 0 ); st->clip_var_fx[4] = float_to_fix16( st->clip_var[4], Q14 ); st->clip_var_fx[5] = float_to_fix16( st->clip_var[5], Q14 ); - - st->streaklimit_fx = (Word16) floatToFixed( st->streaklimit, Q15 ); FOR( Word16 idx = 0; idx < M; idx++ ) { st->lsf_adaptive_mean_fx[idx] = (Word16) ( st->lsf_adaptive_mean[idx] * 2.56f ); @@ -847,8 +807,6 @@ ivas_error acelp_core_enc( st->hGSCEnc->last_ener_fx = (Word16) st->hGSCEnc->last_ener; IF( st->hLPDmem ) st->hLPDmem->tilt_code = float_to_fix16( st->hLPDmem->tilt_code_flt, Q15 ); - IF( st->hTdCngEnc ) - st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 ); #endif /*-----------------------------------------------------------------* * Configure ACELP bit allocation @@ -1075,7 +1033,6 @@ ivas_error acelp_core_enc( // So each chunk might have a different Q which is predicted by 1st element. fixedToFloat_arr( &Aq_fx[i * ( M + 1 )], &Aq[i * ( M + 1 )], 14 - norm_s( Aq_fx[i * ( M + 1 )] ), ( M + 1 ) ); } - st->stab_fac = fixedToFloat( st->stab_fac_fx, Q15 ); fixedToFloat_arr( old_exc_fx, old_exc_flt, Q15 - hLPDmem->e_old_exc, st->L_frame ); me2f_buf_16( &hLPDmem->old_exc[-M - 1], hLPDmem->e_old_exc, &hLPDmem->old_exc_flt[-M - 1], L_EXC_MEM + M + 1 ); fixedToFloat_arr( old_bwe_exc_fx, old_bwe_exc, Q_old_bwe_exc, 1380 ); @@ -1305,7 +1262,11 @@ ivas_error acelp_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // conv params from float to fix Q_exc2 = Q_factor_arr( exc2, L_FRAME ); +#ifndef MSAN_FIX floatToFixed_arr( exc2, exc2_fx, Q_exc2, L_FRAME16k ); +#else + floatToFixed_arr( exc2, exc2_fx, Q_exc2, L_FRAME ); +#endif floatToFixed_arr( Aq, Aq_fx, 12, NB_SUBFR16k * ( M + 1 ) ); floatToFixed_arr( st->lspold_s, st->lspold_s_fx, 15, 16 ); st->min_alpha_fx = float_to_fix16( st->min_alpha, 15 ); @@ -1341,9 +1302,19 @@ ivas_error acelp_core_enc( *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS + +#ifndef MSAN_FIX Word16 q_syn = Q_factor_arr( syn, L_FRAME16k ); +#else + Word16 q_syn = Q_factor_arr( syn, L_FRAME ); +#endif q_syn = min( q_syn, Q_factor_arr( res, L_FRAME16k ) ); + +#ifndef MSAN_FIX floatToFixed_arr16( syn, syn_fx, q_syn, L_FRAME16k ); +#else + floatToFixed_arr16( syn, syn_fx, q_syn, L_FRAME ); +#endif floatToFixed_arr( pitch_buf, pitch_buf_fx, Q6, NB_SUBFR16k ); // Saturation Conversion used as last values have garbage values even in float floatToFixed_arr16( res, res_fx, q_syn, L_FRAME16k ); #endif @@ -1496,7 +1467,6 @@ ivas_error acelp_core_enc( floatToFixed_arr16( exc, exc_fx, q_exc, L_EXC - L_EXC_MEM ); floatToFixed_arr16( st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_exc2_buf, q_exc, HO_HIST_SIZE * L_FFT ); - floatToFixed_arr32( st->hTdCngEnc->ho_ener_circ, st->hTdCngEnc->ho_ener_circ_fx, Q6, HO_HIST_SIZE ); floatToFixed_arr32( st->hTdCngEnc->ho_env_circ, st->hTdCngEnc->ho_env_circ_fx, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); floatToFixed_arr16( st->hTdCngEnc->ho_lsp_circ, st->hTdCngEnc->ho_lsp_circ_fx, Q15, HO_HIST_SIZE * M ); diff --git a/lib_enc/analy_lp_fx.c b/lib_enc/analy_lp_fx.c index 314f7a9c2ffe687d944c448f70dcbeb1dd4f1589..cd88567133ec7587abadd295c6dc015754303886 100644 --- a/lib_enc/analy_lp_fx.c +++ b/lib_enc/analy_lp_fx.c @@ -23,6 +23,108 @@ * - find interpolated LSPs and convert back to A(z) for all subframes * - update LSPs for the next frame *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void analy_lp_ivas_fx( + const Word16 speech[], /* i :(Q_new) pointer to the speech frame */ + const Word16 L_frame, /* i :(q0) length of the frame */ + const Word16 L_look, /* i :(q0) look-ahead */ + Word32 *ener, /* o :(Q_r) residual energy from Levinson-Durbin */ + Word16 A[], /* o :(q14) A(z) filter coefficients */ + Word16 epsP_h[], /* o :(high part of epsP(Q_r)) LP analysis residual energies for each iteration */ + Word16 epsP_l[], /* o :(low part of epsP(Q_r)) LP analysis residual energies for each iteration */ + Word16 lsp_new[], /* o :(q15) current frame LSPs */ + Word16 lsp_mid[], /* o :(q15) current mid-frame LSPs */ + Word16 lsp_old[], /* i/o:(q15) previous frame unquantized LSPs */ + const Word16 Top[2], /* i :(q0) open loop pitch lag */ + const Word16 Tnc[2], /* i :(q15) open loop pitch gain */ + const Word32 Core_sr, /* i :(q0) Internal core sampling rate */ + const Word16 sec_chan_low_rate, /* i :(q0) flag to signal second channel */ + Word16 Q_new, /*i: stores Q for speech*/ + Word16 *Q_r /*stores q for ener*/ ) +{ + Word16 r_h[M + 1]; /* Autocorrelations of windowed speech MSB */ + Word16 r_l[M + 1]; /* Autocorrelations of windowed speech LSB */ + Word32 LepsP[M + 1]; + Word16 i, i_subfr, wind_length = 0; + Word16 *lsp; + const Word16 *wind = NULL; + const Word16 *pt; + Word16 half_frame; + move16(); /* wind_length*/ + + IF( EQ_16( L_frame, L_FRAME ) ) + { + wind_length = L_LP; + move16(); + wind = Assym_window_W16fx; /*q15*/ + } + ELSE /* L_frame == L_FRAME16k */ + { + wind_length = L_LP_16k; + move16(); + wind = assym_window_16k_fx; /*q15*/ + } + lsp = lsp_mid; + half_frame = shr( L_frame, 1 ); + + FOR( i_subfr = 0; i_subfr <= 1; i_subfr++ ) + { + pt = speech + sub( add( half_frame, L_look ), wind_length ); + half_frame = shl( half_frame, 1 ); + + /* Autocorrelations */ + autocorr_fx( pt, M, r_h, r_l, &Q_r[1 - i_subfr], wind_length, wind, 0, 0 ); + + /*if ( r[0] < 100.0f && no_thr == 0 )*/ + /*r[0] = 100.0f*/ + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( L_Comp( r_h[0], r_l[0] ) /* Q_r[1 - i_subfr]*/, sub( 31, add( Q_r[1 - i_subfr], shl( Q_new, 1 ) ) ), 100 /*q0*/, 31 ), -1 ) ) + { + /*Q_min stores min of 24 and the actual Q for r*/ + Word16 Q_min = s_min( add( Q_r[1 - i_subfr], shl( Q_new, 1 ) ), 24 ); /* comparing q with 24 because exponent of 100 is 7 so max q should be 24*/ + L_Extract( L_shl( 100, Q_min ), &r_h[0], &r_l[0] ); /*extracting high and low components of r[0]*/ + FOR( i = 1; i < 17; i++ ) + { + L_Extract( L_shr( L_Comp( r_h[i], r_l[i] ), sub( add( Q_r[1 - i_subfr], shl( Q_new, 1 ) ), Q_min ) ), &r_h[i], &r_l[i] ); /*scaling all the values to q24*/ + } + Q_r[1 - i_subfr] = sub( Q_min, shl( Q_new, 1 ) ); /*updating the q (subtracting shl( Q_new, 1 ) as in later part it is being added-> to maintain q24 )*/ + move16(); + } + + /* Lag windowing */ + adapt_lag_wind( r_h, r_l, M, Top[i_subfr], Tnc[i_subfr], Core_sr ); + + /* Levinson-Durbin */ + E_LPC_lev_dur( r_h, r_l, A, LepsP, M, NULL ); + FOR( i = 0; i <= M; i++ ) + { + L_Extract( LepsP[i], &epsP_h[i], &epsP_l[i] ); + } + /*Q_r[... might not be needed from external...*/ + Q_r[1 - i_subfr] = add( Q_r[1 - i_subfr], shl( Q_new, 1 ) ); + move16(); + + /* Conversion of A(z) to LSPs */ + E_LPC_a_lsp_conversion( A, lsp, lsp_old, M ); + + lsp = lsp_new; + } + IF( EQ_16( sec_chan_low_rate, 1 ) ) + { + /* LSP interpolation */ + int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, -2 ); + } + ELSE + { + /* LSP interpolation */ + int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0 ); + } + Copy( lsp_new, lsp_old, M ); + *ener = L_Comp( epsP_h[M], epsP_l[M] ); + move32(); + + return; +} +#endif // IVAS_FLOAT_FIXED void analy_lp_fx( const Word16 speech[], /* i : pointer to the speech frame */ diff --git a/lib_enc/bw_detect.c b/lib_enc/bw_detect.c index 473f7d82a8a1709b162286cb60d63e4e54103bcb..3d1cc6e09976d824611a320806c32df0a088ad00 100644 --- a/lib_enc/bw_detect.c +++ b/lib_enc/bw_detect.c @@ -63,6 +63,7 @@ #define CLDFB_ENER_OFFSET 1.6f +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * bw_detect() * @@ -726,3 +727,4 @@ int16_t set_bw_mct( return bw_changed; } +#endif diff --git a/lib_enc/bw_detect_fx.c b/lib_enc/bw_detect_fx.c index 2d69854e5d28443861d599cb842ea2718c3fef91..f572f4be37c41448fc990d70d53adac98cefa0e8 100644 --- a/lib_enc/bw_detect_fx.c +++ b/lib_enc/bw_detect_fx.c @@ -1037,7 +1037,7 @@ void set_bw_fx( move16(); } } -#ifdef IVAS_CODE_BWD +//#ifdef IVAS_CODE_BWD /*-------------------------------------------------------------------* * set_bw_stereo() @@ -1045,38 +1045,46 @@ void set_bw_fx( * Set encoded bandwidth for stereo (CPE) channels *-------------------------------------------------------------------*/ -void set_bw_stereo( +void set_bw_stereo_fx( CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structures */ ) { Encoder_State **sts = hCPE->hCoreCoder; - if ( hCPE->element_brate > BWD_MAX_BRATE_WIDER_BW_MDCT ) + IF( GT_32( hCPE->element_brate, BWD_MAX_BRATE_WIDER_BW_MDCT ) ) { sts[0]->bwidth = sts[0]->max_bwidth; + move16(); sts[1]->bwidth = sts[1]->max_bwidth; + move16(); } - else if ( hCPE->element_mode == IVAS_CPE_MDCT ) + ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { /* ensure that both CPE channels have the same audio band-width */ - if ( sts[0]->input_bwidth == sts[1]->input_bwidth ) + IF( EQ_16( sts[0]->input_bwidth, sts[1]->input_bwidth ) ) { sts[0]->bwidth = sts[0]->input_bwidth; + move16(); sts[1]->bwidth = sts[0]->input_bwidth; + move16(); } - else + ELSE { - sts[0]->bwidth = max( sts[0]->input_bwidth, sts[1]->input_bwidth ); - sts[1]->bwidth = max( sts[0]->input_bwidth, sts[1]->input_bwidth ); + sts[0]->bwidth = s_max( sts[0]->input_bwidth, sts[1]->input_bwidth ); + move16(); + sts[1]->bwidth = s_max( sts[0]->input_bwidth, sts[1]->input_bwidth ); + move16(); } } - sts[0]->bwidth = max( sts[0]->bwidth, WB ); - sts[1]->bwidth = max( sts[1]->bwidth, WB ); + sts[0]->bwidth = s_max( sts[0]->bwidth, WB ); + move16(); + sts[1]->bwidth = s_max( sts[1]->bwidth, WB ); + move16(); return; } -#endif +//#endif /*-------------------------------------------------------------------* * set_bw_mct() * diff --git a/lib_enc/cng_enc.c b/lib_enc/cng_enc.c index 571fc35494de65cb9b181485c4a7ee75a0ef34a5..2c1fbc63902d1e16367ce8c01aaa8919d905f270 100644 --- a/lib_enc/cng_enc.c +++ b/lib_enc/cng_enc.c @@ -1504,6 +1504,7 @@ static Word16 shb_DTX_ivas_fx( } #endif +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * calculate_hangover_attenuation_gain() * @@ -1548,3 +1549,4 @@ void calculate_hangover_attenuation_gain( return; } +#endif diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index efa0e0d4c06c5213554cb068d28dd8850da8e43b..262d8d42450121b684c6518631aad5ca1e5c35a7 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -98,7 +98,12 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * /* Configure ACELP */ + +#ifndef MSAN_FIX hLPDmem->nbits = BITS_ALLOC_config_acelp( target_bits, st->coder_type, acelp_cfg, st->narrowBand, st->nb_subfr ); +#else + BITS_ALLOC_config_acelp( target_bits, st->coder_type, acelp_cfg, st->narrowBand, st->nb_subfr ); +#endif /* Init Framing parameters */ move16(); diff --git a/lib_enc/cod_tcx.c b/lib_enc/cod_tcx.c index 4508bfb64bc3b1c81ca9091215c86bf6a56265f0..502b22aed1d5a98afe714df4163c5dadba1253b0 100644 --- a/lib_enc/cod_tcx.c +++ b/lib_enc/cod_tcx.c @@ -309,11 +309,29 @@ void TNSAnalysisStereo_fx( IF( sts[0]->hTcxEnc->tnsData[k].nFilters > 0 || sts[1]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || LT_16( meanLtpGain_fx, 19660 /* 0.6 in Q15*/ ) ) { ++sts[0]->hTcxEnc->tnsData[k].nFilters; - pFilter[0]->filterType = TNS_FILTER_ON; - move16(); + /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here, + this may result in crash later. Changing the filter type here so the order is taken here in further section */ + IF( pFilter[0]->order != 0 ) + { + pFilter[0]->filterType = TNS_FILTER_ON; + move16(); + } + ELSE + { + pFilter[0]->filterType = TNS_FILTER_ON_ZERO; + move16(); + } ++sts[1]->hTcxEnc->tnsData[k].nFilters; - pFilter[1]->filterType = TNS_FILTER_ON; - move16(); + IF( pFilter[1]->order != 0 ) + { + pFilter[1]->filterType = TNS_FILTER_ON; + move16(); + } + ELSE + { + pFilter[1]->filterType = TNS_FILTER_ON_ZERO; + move16(); + } } ELSE { @@ -323,11 +341,29 @@ void TNSAnalysisStereo_fx( IF( GE_16( maxEnergyChange_fx, pTnsParameters[0]->minEnergyChange ) ) { ++sts[0]->hTcxEnc->tnsData[k].nFilters; - pFilter[0]->filterType = TNS_FILTER_ON; - move16(); + /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here, + this may result in crash later. Changing the filter type here so the order is taken here in further section */ + IF( pFilter[0]->order != 0 ) + { + pFilter[0]->filterType = TNS_FILTER_ON; + move16(); + } + ELSE + { + pFilter[0]->filterType = TNS_FILTER_ON_ZERO; + move16(); + } ++sts[1]->hTcxEnc->tnsData[k].nFilters; - pFilter[1]->filterType = TNS_FILTER_ON; - move16(); + IF( pFilter[1]->order != 0 ) + { + pFilter[1]->filterType = TNS_FILTER_ON; + move16(); + } + ELSE + { + pFilter[1]->filterType = TNS_FILTER_ON_ZERO; + move16(); + } } ELSE { @@ -540,8 +576,18 @@ void TNSAnalysisStereo_fx( IF( sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || LT_16( sts[ch]->hTcxEnc->tcxltp_gain, 19660 ) ) { ++sts[ch]->hTcxEnc->tnsData[k].nFilters; - pFilter->filterType = TNS_FILTER_ON; - move16(); + /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here, + this may result in crash later. Changing the filter type here so the order is taken here in further section */ + IF( pFilter->order != 0 ) + { + pFilter->filterType = TNS_FILTER_ON; + move16(); + } + ELSE + { + pFilter->filterType = TNS_FILTER_ON_ZERO; + move16(); + } } ELSE { @@ -550,13 +596,24 @@ void TNSAnalysisStereo_fx( IF( GE_16( maxEnergyChange_fx, pTnsParameters->minEnergyChange ) ) { ++sts[ch]->hTcxEnc->tnsData[k].nFilters; - pFilter->filterType = TNS_FILTER_ON; + /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here, + this may result in crash later. Changing the filter type here so the order is taken here in further section */ + IF( pFilter->order != 0 ) + { + pFilter->filterType = TNS_FILTER_ON; + move16(); + } + ELSE + { + pFilter->filterType = TNS_FILTER_ON_ZERO; + move16(); + } } ELSE { pFilter->filterType = TNS_FILTER_OFF; + move16(); } - move16(); } } ELSE IF( sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 ) /* If a previous filter is turned on */ @@ -752,7 +809,7 @@ void TNSAnalysisStereo_fx( } return; } -#endif +#else void TNSAnalysisStereo( Encoder_State **sts, /* i : encoder state handle */ float *mdst_spectrum[CPE_CHANNELS][NB_DIV], /* o : MDST spectrum */ @@ -1213,7 +1270,9 @@ void TNSAnalysisStereo( return; } +#endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * TNSAnalysis() * @@ -1298,7 +1357,6 @@ void TNSAnalysis( } -#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * ShapeSpectrum() * @@ -1475,7 +1533,6 @@ void ShapeSpectrum( return; } -#endif /*-------------------------------------------------------------------* @@ -1506,7 +1563,6 @@ static int16_t GetTransWidth( } -#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------* * EstimateTCXNoiseLevel() * @@ -1566,7 +1622,6 @@ static void EstimateTCXNoiseLevel( return; } -#endif /*-----------------------------------------------------------* @@ -1662,7 +1717,6 @@ void EstimateStereoTCXNoiseLevel( } -#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------* * DecideTonalSideInfo() * @@ -2799,7 +2853,6 @@ void coder_tcx( return; } -#endif /*-------------------------------------------------------------------* * coder_tcx_post() @@ -2827,3 +2880,4 @@ void coder_tcx_post( return; } +#endif diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index e449b2420f5dbaef56632161f91ecc9af430191e..86be7be4ec749b98b8959d677bc4c6542a3cf76b 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -4394,7 +4394,9 @@ void coder_tcx_fx( Word16 winMDST[N_MAX + L_MDCT_OVLP_MAX]; Word16 *pWinMDST; Word16 left_overlap_mode, right_overlap_mode; +#ifndef MSAN_FIX LPD_state_HANDLE hLPDmem = st->hLPDmem; +#endif TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; left_overlap = right_overlap = -1; @@ -4560,7 +4562,9 @@ void coder_tcx_fx( st, hm_cfg ); +#ifndef MSAN_FIX hLPDmem->nbits = add( hLPDmem->nbits, add( tnsBits, ltpBits ) ); +#endif } diff --git a/lib_enc/comvad_decision.c b/lib_enc/comvad_decision.c index d5d81c6917d6ebf3192bdfaa1a64767603f5c58e..5eb7aeda6e53a3d5c2db7e814598df0a2c6567fe 100644 --- a/lib_enc/comvad_decision.c +++ b/lib_enc/comvad_decision.c @@ -41,6 +41,7 @@ #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * local function prototypes *-------------------------------------------------------------------*/ @@ -873,3 +874,4 @@ static int16_t comvad_hangover( return speech_flag; } +#endif diff --git a/lib_enc/comvad_decision_fx.c b/lib_enc/comvad_decision_fx.c index 98816e768d91e0666a6fade90f54a9201054fa04..505e18326fb3483811fef7a6904da7b22a9d68b4 100644 --- a/lib_enc/comvad_decision_fx.c +++ b/lib_enc/comvad_decision_fx.c @@ -394,7 +394,7 @@ static Word16 comvad_hangover( Word16 comvad_decision_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ const Word32 l_snr, /* i : long time frequency domain*/ const Word32 lt_snr_org, /* i : original long time SNR*/ const Word32 lt_snr, /* i : long time SNR calculated by fg_energy and bg_energy*/ diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index 77b055e3231c27841e491221b6c5e7e658f4235d..fc2bef83c9ef14538877ac9b9dcb0713fdf86174 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -80,65 +80,6 @@ void init_coder_ace_plus_ivas_fx( Word16 L_frame_old; /*keep old frame size for switching */ Word16 L_subfr; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( hTcxEnc != NULL ) - { - hTcxEnc->L_frameTCX = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); /* 0x0290 is 1/FRAMES_PER_SEC in Q15*/ - move16(); - - IF( st->ini_frame == 0 ) - { - set_zero( hTcxEnc->Txnq_flt, L_FRAME32k / 2 + 64 ); - hTcxEnc->acelp_zir_flt = hTcxEnc->Txnq_flt + L_FRAME / 2; - hTcxEnc->tcx_target_bits_fac_flt = 1.0f; - } - } - - IF( st->hBWE_TD != NULL ) - { - set_zero( st->hBWE_TD->cur_sub_Aq, M + 1 ); - } - - st->currEnergyHF = 0; - - IF( ( NE_16( st->last_L_frame, st->L_frame ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) || ( EQ_16( st->last_core, HQ_CORE ) ) ) - { - set_f( st->mem_MA, 0.0f, M ); - mvr2r( GEWB_Ave, st->mem_AR, M ); - } - - /* Initialize TCX */ - IF( hTcxEnc != NULL ) - { - st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_flt, Q15 ); - } - - /* Initialize Signal Buffers */ - f2me_buf_16( st->buf_speech_enc_flt, st->buf_speech_enc, &st->exp_buf_speech_enc, st->L_frame ); - f2me_buf_16( st->old_wsp, st->old_wsp_fx, &st->exp_old_wsp, L_WSP_MEM ); - f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, L_INP_MEM ); - f2me_buf_16( st->old_inp_16k, st->old_inp_16k_fx, &st->exp_old_inp_16k, L_INP_MEM ); - f2me_buf_16( st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, &st->exp_old_inp_16k, L_WSP_MEM ); - - /* Initialize ACELP */ - if ( st->lspold_enc != NULL ) - { - floatToFixed_arr16( st->lspold_enc, &st->lspold_enc_fx[0], Q15, M ); - } - if ( st->lsp_old1 != NULL ) - { - floatToFixed_arr16( st->lsp_old1, &st->lsp_old1_fx[0], Q15, M ); - } - if ( st->lsp_old != NULL ) - { - floatToFixed_arr16( st->lsp_old, &st->lsp_old_fx[0], Q15, M ); - } - - /* Adaptive BPF */ - set_zero( st->mem_bpf, 2 * L_FILT16k ); - set_zero( st->mem_error_bpf, 2 * L_FILT16k ); -#endif - /* Bitrate */ st->tcxonly = getTcxonly_ivas_fx( st->element_mode, st->total_brate, MCT_flag, st->is_ism_format ); move16(); @@ -261,9 +202,6 @@ void init_coder_ace_plus_ivas_fx( test(); IF( st->igf && st->hIGFEnc != NULL ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IGFEncSetMode( st->hIGFEnc, st->total_brate, st->bwidth, st->element_mode, st->rf_mode ); -#endif IGFEncSetMode_ivas_fx( st->hIGFEnc, st->total_brate, st->bwidth, st->element_mode, st->rf_mode ); } ELSE IF( st->hIGFEnc != NULL ) @@ -275,11 +213,9 @@ void init_coder_ace_plus_ivas_fx( } /* Initialize Core Signal Analysis Module */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - init_core_sig_ana( st ); -#endif init_core_sig_ana_ivas_fx( st ); + /* Initialize TCX */ IF( hTcxEnc != NULL ) { @@ -295,9 +231,6 @@ void init_coder_ace_plus_ivas_fx( init_sig_buffers( st, L_frame_old, L_subfr, st->total_brate, last_total_brate ); #endif /* Initialize ACELP */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - init_acelp( st, L_frame_old, st->total_brate, last_total_brate ); -#endif init_acelp_ivas_fx( st, L_frame_old, 0 ); @@ -349,9 +282,6 @@ void init_coder_ace_plus_ivas_fx( move16(); /* Initialize ACELP/TCX Modes */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - init_modes( st, last_total_brate ); -#endif init_modes_ivas_fx( st, last_total_brate ); /* Adaptive BPF */ @@ -424,7 +354,11 @@ void init_coder_ace_plus( { set_zero( hTcxEnc->Txnq_flt, L_FRAME32k / 2 + 64 ); hTcxEnc->acelp_zir_flt = hTcxEnc->Txnq_flt + L_FRAME / 2; +#ifndef IVAS_FLOAT_FIXED hTcxEnc->tcx_target_bits_fac_flt = 1.0f; +#else + hTcxEnc->tcx_target_bits_fac = ONE_IN_Q14; +#endif #ifdef IVAS_FLOAT_FIXED set16_fx( hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 ); @@ -452,6 +386,11 @@ void init_coder_ace_plus( st->acelpFramesCount = 0; #ifndef IVAS_FLOAT_FIXED st->prevTempFlatness = 1.0f; +#endif +#ifdef IVAS_FLOAT_FIXED +#ifdef MSAN_FIX + st->prevTempFlatness_fx = 128; // Q7 +#endif #endif } @@ -783,11 +722,19 @@ static void init_tcx( hTcxEnc->spectrum[0] = hTcxEnc->spectrum_long; hTcxEnc->spectrum[1] = hTcxEnc->spectrum_long + N_TCX10_MAX; + #ifdef IVAS_FLOAT_FIXED hTcxEnc->spectrum_fx[0] = hTcxEnc->spectrum_long_fx; hTcxEnc->spectrum_fx[1] = hTcxEnc->spectrum_long_fx + N_TCX10_MAX; + st->preemph_fac_flt = fix16_to_float( st->preemph_fac, Q15 ); #endif +#ifdef MSAN_FIX + set_zero( hTcxEnc->spectrum[0], N_TCX10_MAX ); + set_zero( hTcxEnc->spectrum[1], N_TCX10_MAX ); + set_zero_fx( hTcxEnc->spectrum_fx[0], N_TCX10_MAX ); + set_zero_fx( hTcxEnc->spectrum_fx[1], N_TCX10_MAX ); +#endif init_tcx_cfg( st->hTcxCfg, total_brate, st->sr_core, st->input_Fs, st->L_frame, st->bwidth, hTcxEnc->L_frameTCX, st->fscale, st->encoderLookahead_enc, st->encoderLookahead_FB, st->preemph_fac_flt, st->tcxonly, st->rf_mode, st->igf, @@ -801,12 +748,24 @@ static void init_tcx( #endif /* Init TCX target bits correction factor */ +#ifndef IVAS_FLOAT_FIXED hTcxEnc->tcx_target_bits_fac_flt = 1.0f; +#else + hTcxEnc->tcx_target_bits_fac = ONE_IN_Q14; +#endif hTcxEnc->measuredBwRatio_flt = 1.0f; +#ifndef IVAS_FLOAT_FIXED hTcxEnc->noiseTiltFactor_flt = 0.5625f; +#else + hTcxEnc->noiseTiltFactor = 9216; /*0.5625f in 1Q14*/ +#endif hTcxEnc->noiseLevelMemory_cnt = 0; +#ifndef IVAS_FLOAT_FIXED set_f( hTcxEnc->ltpGainMemory, 0.0f, N_LTP_GAIN_MEMS ); +#else + set16_fx( hTcxEnc->ltpGainMemory_fx, 0, N_LTP_GAIN_MEMS ); +#endif set_c( hTcxEnc->memQuantZeros, 0, L_FRAME_PLUS ); /* TCX-LTP */ @@ -816,10 +775,18 @@ static void init_tcx( { hTcxEnc->tcxltp_pitch_int_past = st->L_frame; hTcxEnc->tcxltp_pitch_fr_past = 0; +#ifndef IVAS_FLOAT_FIXED hTcxEnc->tcxltp_gain_past_flt = 0.f; +#else + hTcxEnc->tcxltp_gain_past = 0; +#endif hTcxEnc->tcxltp_norm_corr_past_flt = 0.f; hTcxEnc->tcxltp_norm_corr_mem_flt = 0.f; +#ifndef IVAS_FLOAT_FIXED hTcxEnc->kernel_switch_corr_past_flt = 0.f; +#else + hTcxEnc->kernel_switch_corr_past = 0; +#endif hTcxEnc->kernel_symmetry_past = 0; /* MDCT_IV & 1 */ hTcxEnc->enc_ste_pre_corr_past = 0; hTcxEnc->tfm_mem = 0.75f; @@ -1621,7 +1588,8 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh move16(); set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); move16(); - + hLPDmem->e_old_exc = 0; + move16(); /*Resamp others memories*/ /*Size of LPC syn memory*/ /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */ diff --git a/lib_enc/core_enc_reconf.c b/lib_enc/core_enc_reconf.c index bb66aa946a79266d10c2cedf81e640f151e2be64..b02d0c4385529931ec45dc8d93cf38047302913f 100644 --- a/lib_enc/core_enc_reconf.c +++ b/lib_enc/core_enc_reconf.c @@ -133,7 +133,11 @@ void core_coder_reconfig( /*Scale TCX for non-active frames to adjust loudness with ACELP*/ if ( st->hTcxCfg != NULL ) { +#ifndef IVAS_FLOAT_FIXED st->hTcxCfg->na_scale_flt = 1.f; +#else + st->hTcxCfg->na_scale = 32767; +#endif if ( bwidth < SWB && !( st->tcxonly ) ) { for ( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ ) @@ -146,7 +150,11 @@ void core_coder_reconfig( { i--; } +#ifndef IVAS_FLOAT_FIXED st->hTcxCfg->na_scale_flt = scaleTcxTable[i].scale_flt; +#else + st->hTcxCfg->na_scale = scaleTcxTable[i].scale; +#endif break; } } diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 4b11e2b8d69397362307d4898a1cd80b84e144c2..f6c196b42e76db806fdbfb49e438fc8da9a1e796 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -200,7 +200,76 @@ void core_coder_mode_switch_ivas_fx( { st->igf = getIgfPresent_fx( st->element_mode, st->total_brate, st->bwidth, st->rf_mode ); move16(); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + IF( hTcxEnc != NULL ) + { + hTcxEnc->L_frameTCX = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); /* 0x0290 is 1/FRAMES_PER_SEC in Q15*/ + move16(); + + IF( st->ini_frame == 0 ) + { + set_zero( hTcxEnc->Txnq_flt, L_FRAME32k / 2 + 64 ); + hTcxEnc->acelp_zir_flt = hTcxEnc->Txnq_flt + L_FRAME / 2; + } + } + + IF( st->hBWE_TD != NULL ) + { + set_zero( st->hBWE_TD->cur_sub_Aq, M + 1 ); + } + + st->currEnergyHF = 0; + + IF( ( NE_16( st->last_L_frame, st->L_frame ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) || ( EQ_16( st->last_core, HQ_CORE ) ) ) + { + set_f( st->mem_MA, 0.0f, M ); + mvr2r( GEWB_Ave, st->mem_AR, M ); + } + + /* Initialize TCX */ + IF( hTcxEnc != NULL ) + { + st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_flt, Q15 ); + } + + /* Initialize Signal Buffers */ + f2me_buf_16( st->buf_speech_enc_flt, st->buf_speech_enc, &st->exp_buf_speech_enc, st->L_frame ); + f2me_buf_16( st->old_wsp, st->old_wsp_fx, &st->exp_old_wsp, L_WSP_MEM ); + f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, L_INP_MEM ); + f2me_buf_16( st->old_inp_16k, st->old_inp_16k_fx, &st->exp_old_inp_16k, L_INP_MEM ); + f2me_buf_16( st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, &st->exp_old_inp_16k, L_WSP_MEM ); + + /* Initialize ACELP */ + if ( st->lspold_enc != NULL ) + { + floatToFixed_arr16( st->lspold_enc, &st->lspold_enc_fx[0], Q15, M ); + } + if ( st->lsp_old1 != NULL ) + { + floatToFixed_arr16( st->lsp_old1, &st->lsp_old1_fx[0], Q15, M ); + } + if ( st->lsp_old != NULL ) + { + floatToFixed_arr16( st->lsp_old, &st->lsp_old_fx[0], Q15, M ); + } + + /* Adaptive BPF */ + set_zero( st->mem_bpf, 2 * L_FILT16k ); + set_zero( st->mem_error_bpf, 2 * L_FILT16k ); +#endif init_coder_ace_plus_ivas_fx( st, last_total_brate, MCT_flag ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + st->preemph_fac_flt = fix16_to_float( st->preemph_fac, Q15 ); + IF( st->hLPDmem != NULL ) + { + 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 } test(); diff --git a/lib_enc/core_enc_updt.c b/lib_enc/core_enc_updt.c index a388365f601d0c3da953e481684d19d62fca94e9..4c525bd6dae00994f29794a202cc1404e3df7d5f 100644 --- a/lib_enc/core_enc_updt.c +++ b/lib_enc/core_enc_updt.c @@ -50,6 +50,7 @@ * Common updates of buffers *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void core_encode_update( Encoder_State *st /* i/o: Encoder state structure */ ) @@ -105,9 +106,7 @@ void core_encode_update( return; } - - -#ifdef IVAS_FLOAT_FIXED +#else void core_encode_update_ivas_fx( Encoder_State *st /* i/o: Encoder state structure */ ) diff --git a/lib_enc/dtx.c b/lib_enc/dtx.c index a466e10a958a73990133266fe7f2f7e5ee732dfb..896d58b4be1c70b8c6ba352a389c3b3209dc0028 100644 --- a/lib_enc/dtx.c +++ b/lib_enc/dtx.c @@ -43,6 +43,9 @@ #include "ivas_prot.h" #include "rom_com.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif /*-------------------------------------------------------------------* * Local constants @@ -541,7 +544,6 @@ static void update_SID_cnt( return; } -#endif /*-------------------------------------------------------------------* @@ -748,6 +750,7 @@ void dtx_hangover_control( return; } +#endif /*-------------------------------------------------------------------* @@ -766,25 +769,51 @@ void td_cng_enc_init( hTdCngEnc->cng_seed = RANDOM_INITSEED; hTdCngEnc->cng_ener_seed = RANDOM_INITSEED; hTdCngEnc->cng_ener_seed1 = RANDOM_INITSEED; +#ifndef IVAS_FLOAT_FIXED hTdCngEnc->lp_ener = 0.0f; +#else + hTdCngEnc->lp_ener_fx = 0; +#endif hTdCngEnc->old_enr_index = -1; +#ifndef IVAS_FLOAT_FIXED hTdCngEnc->Enew = 0.0f; hTdCngEnc->lp_sp_enr = 0.0f; +#else + hTdCngEnc->Enew_fx = 0; + + hTdCngEnc->lp_sp_enr_fx = 0; +#endif + hTdCngEnc->last_allow_cn_step = 0; +#ifndef IVAS_FLOAT_FIXED hTdCngEnc->CNG_att = 0.0f; +#else + hTdCngEnc->CNG_att_fx = 0; +#endif if ( Opt_DTX_ON ) { hTdCngEnc->cng_hist_ptr = -1; +#ifndef IVAS_FLOAT_FIXED set_f( hTdCngEnc->cng_lsp_hist, 0, DTX_HIST_SIZE * M ); set_f( hTdCngEnc->cng_ener_hist, 0, DTX_HIST_SIZE ); +#else + set16_fx( hTdCngEnc->cng_lsp_hist_fx, 0, DTX_HIST_SIZE * M ); + set16_fx( hTdCngEnc->cng_ener_hist_fx, 0, DTX_HIST_SIZE ); +#endif hTdCngEnc->ho_hist_ptr = -1; hTdCngEnc->ho_sid_bw = 0; +#ifndef IVAS_FLOAT_FIXED set_f( hTdCngEnc->ho_lsp_hist, 0, HO_HIST_SIZE * M ); set_f( hTdCngEnc->ho_ener_hist, 0, HO_HIST_SIZE ); set_f( hTdCngEnc->ho_env_hist, 0, HO_HIST_SIZE * NUM_ENV_CNG ); +#else + set16_fx( hTdCngEnc->ho_lsp_hist_fx, 0, HO_HIST_SIZE * M ); + set32_fx( hTdCngEnc->ho_ener_hist_fx, 0, HO_HIST_SIZE ); + set32_fx( hTdCngEnc->ho_env_hist_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG ); +#endif hTdCngEnc->ho_hist_size = 0; hTdCngEnc->act_cnt = 0; } @@ -802,21 +831,37 @@ void td_cng_enc_init( hTdCngEnc->cng_buf_cnt = 0; +#ifndef IVAS_FLOAT_FIXED set_f( hTdCngEnc->lp_env, 0.0f, 20 ); set_f( hTdCngEnc->cng_res_env, 0.0f, 20 * 8 ); +#else + set32_fx( hTdCngEnc->lp_env_fx, 0, 20 ); + set32_fx( hTdCngEnc->cng_res_env_fx, 0, 20 * 8 ); +#endif set_f( hTdCngEnc->exc_mem, 0.0f, 24 ); set_f( hTdCngEnc->exc_mem1, 0.0f, 30 ); set_f( hTdCngEnc->exc_mem2, 0.0f, 30 ); +#ifndef IVAS_FLOAT_FIXED set_f( hTdCngEnc->old_env, 0.0f, NUM_ENV_CNG ); +#else + set32_fx( hTdCngEnc->old_env_fx, 0, NUM_ENV_CNG ); +#endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float fixed conversions set_f( hTdCngEnc->cng_exc2_buf_flt, 0.0f, HO_HIST_SIZE * L_FFT ); #endif /* SWB CNG/DTX */ +#ifndef IVAS_FLOAT_FIXED hTdCngEnc->last_wb_cng_ener = -6.02f; hTdCngEnc->last_shb_cng_ener = -6.02f; hTdCngEnc->mov_wb_cng_ener = -6.02f; hTdCngEnc->mov_shb_cng_ener = -6.02f; +#else + hTdCngEnc->last_wb_cng_ener_fx = -1541; + hTdCngEnc->last_shb_cng_ener_fx = -1541; + hTdCngEnc->mov_wb_cng_ener_fx = -1541; + hTdCngEnc->mov_shb_cng_ener_fx = -1541; +#endif hTdCngEnc->shb_cng_ini_cnt = 1; hTdCngEnc->shb_NO_DATA_cnt = 0; hTdCngEnc->last_SID_bwidth = min( max_bwidth, SWB ); @@ -894,6 +939,7 @@ void td_cng_enc_init( } #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * dtx_enc_init() * @@ -916,17 +962,10 @@ void dtx_enc_init( mvr2r( st->lsp_old1, hDtxEnc->lspCNG, M ); hDtxEnc->VarDTX_cnt_voiced = 0; hDtxEnc->VarDTX_cnt_noise = 0; -#ifndef IVAS_FLOAT_FIXED hDtxEnc->lt_ener_voiced = 0.0f; hDtxEnc->lt_ener_noise = 0.0f; hDtxEnc->frame_ener = 0.0f; hDtxEnc->lt_ener_last_SID = 0.0f; -#else - hDtxEnc->lt_ener_voiced_fx = 0; - hDtxEnc->lt_ener_noise_fx = 0; - hDtxEnc->frame_ener_fx = 0; - hDtxEnc->lt_ener_last_SID_fx = 0; -#endif hDtxEnc->last_CNG_L_frame = L_FRAME; hDtxEnc->var_SID_rate_flag = var_SID_rate_flag; hDtxEnc->last_active_brate = ACELP_7k20; @@ -948,3 +987,4 @@ void dtx_enc_init( return; } +#endif diff --git a/lib_enc/dtx_fx.c b/lib_enc/dtx_fx.c index 843b3731826005f0302032f804d803eb12ccef52..445f25b675e8f62c920fa0eca9533699983ac016 100644 --- a/lib_enc/dtx_fx.c +++ b/lib_enc/dtx_fx.c @@ -1691,19 +1691,19 @@ void dtx_enc_init_fx( hDtxEnc->VarDTX_cnt_noise = 0; move16(); hDtxEnc->lt_ener_voiced_fx = 0; - move16(); + move32(); hDtxEnc->lt_ener_noise_fx = 0; - move16(); + move32(); hDtxEnc->frame_ener_fx = 0; - move16(); + move32(); hDtxEnc->lt_ener_last_SID_fx = 0; - move16(); + move32(); hDtxEnc->last_CNG_L_frame = L_FRAME; move16(); hDtxEnc->var_SID_rate_flag = var_SID_rate_flag; move16(); hDtxEnc->last_active_brate = ACELP_7k20; - move16(); + move32(); hDtxEnc->cng_cnt = 0; move16(); @@ -1711,8 +1711,8 @@ void dtx_enc_init_fx( { hDtxEnc->interval_SID = 12; move16(); - move16(); hDtxEnc->cng_hist_size = DTX_HIST_SIZE; + move16(); } ELSE { diff --git a/lib_enc/enc_gen_voic_rf.c b/lib_enc/enc_gen_voic_rf.c index ed0867eb236769b053573ff888dde7ea8765c6dc..549a16dedef8311cfe6caca57182fa5596843d89 100644 --- a/lib_enc/enc_gen_voic_rf.c +++ b/lib_enc/enc_gen_voic_rf.c @@ -42,6 +42,7 @@ #include "wmc_auto.h" #include "prot_fx.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * reset_rf_indices() * @@ -107,7 +108,6 @@ void reset_rf_indices( } -#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * coder_acelp_rf() * diff --git a/lib_enc/energy.c b/lib_enc/energy.c index 84fedfbfaee4c365f6aca1e2dc4f5f9cf05d7658..77c28484fb3519fa64a782a4a28c236bae7161f1 100644 --- a/lib_enc/energy.c +++ b/lib_enc/energy.c @@ -41,6 +41,7 @@ #include "rom_enc.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * background_update() * @@ -285,3 +286,4 @@ void est_energy( return; } +#endif diff --git a/lib_enc/energy_fx.c b/lib_enc/energy_fx.c index 4bd16df2e21b8f85a1bf87ca66e6e568b0ef80fd..054245a6d288b432c1c5b5107d52f713ce9ed4d6 100644 --- a/lib_enc/energy_fx.c +++ b/lib_enc/energy_fx.c @@ -212,11 +212,11 @@ static void update_sb_bg_energy( * *-------------------------------------------------------------------*/ void background_update_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 scale, /* i : the scaling of frame energy*/ - Word32 frame_energy, /* i : current frame energy*/ - Word32 update_flag, /* i : update flag*/ - Word16 music_backgound_f, /* i : background music flag*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 scale, /* i : the scaling of frame energy*/ + Word32 frame_energy, /* i : current frame energy*/ + Word32 update_flag, /* i : update flag*/ + Word16 music_backgound_f, /* i : background music flag*/ Word32 snr ) { Word32 tmp; diff --git a/lib_enc/ext_sig_ana.c b/lib_enc/ext_sig_ana.c index e7688dfbaef1ece0033ed624d3d4ff2a3d31f678..33c3201b0aff379e049862561df6aaf387dc51da 100644 --- a/lib_enc/ext_sig_ana.c +++ b/lib_enc/ext_sig_ana.c @@ -133,8 +133,6 @@ void core_signal_analysis_high_bitrate( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( st->element_mode == IVAS_CPE_DFT ) { - floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, Q7, NSUBBLOCKS + MAX_TD_DELAY ); - hTcxEnc->tcxltp_gain_past = float_to_fix16( hTcxEnc->tcxltp_gain_past_flt, Q15 ); hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); q_fac = Q_factor_arr( st->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); floatToFixed_arr( st->buf_wspeech_enc_flt, buf_wspeech_enc_fx, q_fac, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); @@ -150,8 +148,6 @@ void core_signal_analysis_high_bitrate( } else if ( st->element_mode != IVAS_CPE_MDCT ) { - floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, Q7, NSUBBLOCKS + MAX_TD_DELAY ); - hTcxEnc->tcxltp_gain_past = float_to_fix16( hTcxEnc->tcxltp_gain_past_flt, Q15 ); hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); q_fac = Q_factor_arr( st->buf_speech_enc_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); floatToFixed_arr( st->buf_speech_enc_flt, buf_speech_enc_fx, q_fac, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); @@ -174,15 +170,11 @@ void core_signal_analysis_high_bitrate( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( st->element_mode == IVAS_CPE_DFT ) { - hTcxEnc->tcxltp_gain_past_flt = fix16_to_float( hTcxEnc->tcxltp_gain_past, Q15 ); - hTcxEnc->tcxltp_gain_flt = fix16_to_float( hTcxEnc->tcxltp_gain, Q15 ); hTcxEnc->tcxltp_norm_corr_past_flt = fix16_to_float( hTcxEnc->tcxltp_norm_corr_past, Q15 ); fixedToFloat_arr( buf_wspeech_enc_fx, st->buf_wspeech_enc_flt, q_fac, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); } else if ( st->element_mode != IVAS_CPE_MDCT ) { - hTcxEnc->tcxltp_gain_past_flt = fix16_to_float( hTcxEnc->tcxltp_gain_past, Q15 ); - hTcxEnc->tcxltp_gain_flt = fix16_to_float( hTcxEnc->tcxltp_gain, Q15 ); hTcxEnc->tcxltp_norm_corr_past_flt = fix16_to_float( hTcxEnc->tcxltp_norm_corr_past, Q15 ); fixedToFloat_arr( buf_speech_ltp_fx, st->hTcxEnc->buf_speech_ltp_flt, q_fac, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); } @@ -485,34 +477,14 @@ void core_signal_analysis_high_bitrate( // -1 = -32768 , Q=15 , ltp_gain // spectrum_fx[]=fixed( (float)spectrum[]) , Q=q_factor_spectrum floatToFixed_arrL( hTcxEnc->spectrum_long, hTcxEnc->spectrum_long_fx, q_factor_spectrum, N_MAX ); - - // subblockNrg=(fix)((float)subblockNrg_flt) - floatToFixed_arrL( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg, 7, 24 ); - - // subblockNrgChange=(fix)((float)subblockNrgChange_flt) - floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, 7, 24 ); #endif test(); TNSAnalysis_ivas_fx( st->hTcxCfg, L_frameTCX, st->hTcxCfg->tcx_coded_lines, transform_type[frameno], ( frameno == 0 ) && ( st->last_core == ACELP_CORE ), hTcxEnc->spectrum_fx[frameno], st->hTranDet, -32768, &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns[frameno], NULL ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( st->hTcxCfg->fIsTNSAllowed ) { // conv params to float - // avgSqrCoef_flt = float(avgSqrCoef, Q 15) - hTcxEnc->tnsData[frameno].filter[0].avgSqrCoef_flt = fix16_to_float( hTcxEnc->tnsData[frameno].filter[0].avgSqrCoef, 15 ); - hTcxEnc->tnsData[frameno].filter[1].avgSqrCoef_flt = fix16_to_float( hTcxEnc->tnsData[frameno].filter[1].avgSqrCoef, 15 ); - - // avgSqrCoef_flt = float(avgSqrCoef, Q 15) - hTcxEnc->tnsData[frameno].filter[0].predictionGain_flt = fix16_to_float( hTcxEnc->tnsData[frameno].filter[0].predictionGain, 7 ); - hTcxEnc->tnsData[frameno].filter[1].predictionGain_flt = fix16_to_float( hTcxEnc->tnsData[frameno].filter[1].predictionGain, 7 ); - // spectrum[]=float( (fix)spectrum_fx[]) , Q=q_factor_spectrum fixedToFloat_arrL( hTcxEnc->spectrum_long_fx, hTcxEnc->spectrum_long, q_factor_spectrum, N_MAX ); - - // subblockNrg_flt=(float)((fixed)subblockNrg) - fixedToFloat_arrL( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg_flt, 7, 24 ); - - // subblockNrgChange_flt=(float)((fixed)subblockNrgChange) - fixedToFloat_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, 7, 24 ); } #endif #endif @@ -575,63 +547,6 @@ void core_signal_analysis_high_bitrate( } IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData = &st->hIGFEnc->igfData; - if ( st->hTdCngEnc != NULL ) - { - st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 ); - } - - 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 ); - } - } #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 @@ -664,11 +579,6 @@ void core_signal_analysis_high_bitrate( hPrivateData->igfPastSFM[i][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[i][j], 13 ); } } - - if ( st->hTdCngEnc != NULL ) - { - st->hTdCngEnc->CNG_att = fix16_to_float( st->hTdCngEnc->CNG_att_fx, Q7 ); - } #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/fd_cng_enc.c b/lib_enc/fd_cng_enc.c index 2a7e7cd5adeab26877a7ab6bc40d4ead9b60aefa..00b2aef908f37c8441a4aa2df2441d51408d1628 100644 --- a/lib_enc/fd_cng_enc.c +++ b/lib_enc/fd_cng_enc.c @@ -541,6 +541,7 @@ void perform_noise_estimation_enc_ivas_fx( return; } +#ifndef IVAS_FLOAT_FIXED void perform_noise_estimation_enc( float *band_energies, /* i : energy in critical bands without minimum noise floor E_MIN*/ float *enerBuffer, /* i : energy buffer */ @@ -671,6 +672,7 @@ void AdjustFirstSID( return; } +#endif /*-------------------------------------------------------------------* * FdCng_encodeSID() @@ -1068,6 +1070,7 @@ void FdCng_encodeSID( } #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * generate_comfort_noise_enc() * @@ -1276,6 +1279,7 @@ float cng_energy( return ( enr ); } +#endif /*-------------------------------------------------------------------* @@ -1560,7 +1564,6 @@ void FdCngEncodeMDCTStereoSID_fx( f2me_buf( hCPE->hCoreCoder[1]->hFdCngEnc->msNoiseEst, hCPE->hCoreCoder[1]->hFdCngEnc->msNoiseEst_fx, &hCPE->hCoreCoder[1]->hFdCngEnc->msNoiseEst_fx_exp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); f2me_buf( hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); f2me_buf( hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); - hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->coherence_fx = float_to_fix16( hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->coherence_flt, Q15 ); #endif is_inp_ms = 0; @@ -2450,8 +2453,6 @@ void FdCngEncodeDiracMDCTStereoSID_fx( me2f_buf( sts[1]->hFdCngEnc->hFdCngCom->sidNoiseEst, sts[1]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, sts[1]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, sts[1]->hFdCngEnc->npartDec ); sts[0]->preemph_fac_flt = fixedToFloat( sts[0]->preemph_fac, Q15 ); sts[1]->preemph_fac_flt = fixedToFloat( sts[1]->preemph_fac, Q15 ); - sts[0]->hFdCngEnc->hFdCngCom->coherence_flt = fixedToFloat( sts[0]->hFdCngEnc->hFdCngCom->coherence_fx, Q15 ); - sts[1]->hFdCngEnc->hFdCngCom->coherence_flt = fixedToFloat( sts[1]->hFdCngEnc->hFdCngCom->coherence_fx, Q15 ); #endif return; diff --git a/lib_enc/find_uv.c b/lib_enc/find_uv.c index 4a4e7f4f239da71a7a8ca21addb694b181983aa6..f51a259bca4a2bb20f754f15d9821b1f0325f76e 100644 --- a/lib_enc/find_uv.c +++ b/lib_enc/find_uv.c @@ -562,7 +562,6 @@ Word16 find_uv_ivas_fx( /* o : coding typ test(); #ifdef BASOP_NOGLOB if ( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22774, mean_voi3_offset ) ) ) && /* normalized correlation low */ - ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 ) ) && /* normalized correlation low on look-ahead - onset detection */ ( LT_32( ee[0], 397 ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ ( LT_32( ee[1], 397 ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ diff --git a/lib_enc/frame_spec_dif_cor_rate_fx.c b/lib_enc/frame_spec_dif_cor_rate_fx.c index c7fa5eb1cab5d0ca8b4c15038cb232529d6ffc05..117ced6baf87ef4209f4d88104b659e4b4c84856 100644 --- a/lib_enc/frame_spec_dif_cor_rate_fx.c +++ b/lib_enc/frame_spec_dif_cor_rate_fx.c @@ -20,10 +20,10 @@ * *-------------------------------------------------------------------*/ void frame_spec_dif_cor_rate_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word32 *spec_amp, /* i : spectral amplitude*/ - Word16 sacle, /* i : the scaling of spec_amp*/ - Word16 f_tonality_rate[3] /* o : tonality rate*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32 *spec_amp, /* i : spectral amplitude*/ + Word16 sacle, /* i : the scaling of spec_amp*/ + Word16 f_tonality_rate[3] /* o : tonality rate*/ ) { diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index 4acf05384a5be334a797d10739b11ef43609ab16..a2ec04bbaf5eb6a05c81ac7c33e74d5e991101ba 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -410,6 +410,7 @@ static Word16 IGF_getTilt_fx( } #endif #endif +#ifndef IVAS_FLOAT_FIXED static float IGF_getTilt( const float *powerSpectrum, /* i : energies */ const int16_t start, /* i : start subband index */ @@ -445,6 +446,7 @@ static float IGF_getTilt( return slope; } +#endif /*-------------------------------------------------------------------* * IGF_getTNR() @@ -681,6 +683,7 @@ static float IGF_getSFM_ivas( * envelope estimation *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void IGF_CalculateEnvelope( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ const float *pMDCTSpectrum, /* i : MDCT spectrum */ @@ -909,8 +912,7 @@ static void IGF_CalculateEnvelope( return; } - -#ifdef IVAS_FLOAT_FIXED +#else static void IGF_CalculateEnvelope_ivas_fx( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ Word32 *pMDCTSpectrum_fx, /* i : MDCT spectrum */ @@ -3883,8 +3885,14 @@ void IGFEncSetMode_ivas_fx( set16_fx( hPrivateData->prevSFM_IIR, 0, IGF_MAX_TILES ); set16_fx( hPrivateData->dampingFactorSmoothing, 2, IGF_MAX_SFB ); set16_fx( hPrivateData->prevSFM_FIR_SFB_SB_fx, 0, IGF_MAX_SFB ); + set16_fx( hPrivateData->prevSFB_FIR_TB_e, 15, IGF_MAX_SFB ); + set16_fx( hPrivateData->prevSFB_FIR_SB_e, 15, IGF_MAX_SFB ); set16_fx( hPrivateData->prevSFM_IIR_SFB_SB_fx, 0, IGF_MAX_SFB ); + set16_fx( hPrivateData->prevSFB_IIR_SB_e, 15, IGF_MAX_SFB ); set16_fx( hPrivateData->prevSFM_FIR_SFB_TB_fx, 0, IGF_MAX_SFB ); + set16_fx( hPrivateData->prevSFB_IIR_TB_e, 15, IGF_MAX_SFB ); + set16_fx( hPrivateData->sfb_tb_e, 15, IGF_MAX_SFB ); + set16_fx( hPrivateData->sfb_sb_e, 15, IGF_MAX_SFB ); set16_fx( hPrivateData->prevSFM_IIR_SFB_TB_fx, 0, IGF_MAX_SFB ); set16_fx( hPrivateData->prevDampingFactor_IIR_fx, -( ONE_IN_Q15 ), IGF_MAX_SFB ); set16_fx( hPrivateData->prevDampingFactor_IIR_e, 0, IGF_MAX_SFB ); @@ -4154,6 +4162,7 @@ int16_t IGFEncWriteConcatenatedBitstream( * * apply the IGF encoder, main encoder interface *-------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED void IGFEncApplyMono_ivas_fx( Encoder_State *st, /* i : Encoder state */ @@ -4227,8 +4236,7 @@ void IGFEncApplyMono_ivas_fx( IGF_ErodeSpectrum( &highPassEner_exp, st->hIGFEnc, pMDCTSpectrum_fx, pPowerSpectrumParameter_fx, e_ps, igfGridIdx ); } -#endif - +#else void IGFEncApplyMono( Encoder_State *st, /* i : Encoder state */ const int16_t igfGridIdx, /* i : IGF grid index */ @@ -4266,6 +4274,7 @@ void IGFEncApplyMono( return; } +#endif /*-------------------------------------------------------------------* diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 0e63098c69230f976e9a51489fc5800c860984c5..6e051302fccb3adb06398d4e04d332cd59f9c6b5 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -151,7 +151,11 @@ ivas_error init_encoder( st->next_force_safety_net = 0; st->pstreaklen = 0; +#ifndef IVAS_FLOAT_FIXED st->streaklimit = 1.0f; +#else + st->streaklimit_fx = 32767; +#endif set_f( st->mem_MA, 0, M ); init_gp_clip( st->clip_var ); @@ -231,9 +235,9 @@ ivas_error init_encoder( mvr2r( st->lsp_old, st->lsp_old16k, M ); mvr2r( st->lsp_old, st->lspold_enc, M ); +#ifndef IVAS_FLOAT_FIXED st->stab_fac = 0.0f; - -#ifdef IVAS_FLOAT_FIXED +#else st->stab_fac_fx = 0; move16(); #endif @@ -457,7 +461,11 @@ ivas_error init_encoder( #ifndef IVAS_FLOAT_FIXED wb_vad_init( st->hVAD ); #else +#ifndef MSAN_FIX wb_vad_init_fx( st->hVAD ); +#else + wb_vad_init_ivas_fx( st->hVAD ); +#endif #endif } else @@ -474,7 +482,11 @@ ivas_error init_encoder( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB VAD\n" ) ); } +#ifndef IVAS_FLOAT_FIXED vad_init( st->hVAD_CLDFB ); +#else + vad_init_fx( st->hVAD_CLDFB ); +#endif } else { @@ -511,9 +523,15 @@ ivas_error init_encoder( * WB, SWB and FB bandwidth detector *-----------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED st->lt_mean_NB = 0; st->lt_mean_WB = 0; st->lt_mean_SWB = 0; +#else + st->lt_mean_NB_fx = 0; + st->lt_mean_WB_fx = 0; + st->lt_mean_SWB_fx = 0; +#endif st->count_WB = BWD_COUNT_MAX; st->count_SWB = BWD_COUNT_MAX; st->count_FB = BWD_COUNT_MAX; @@ -529,8 +547,9 @@ ivas_error init_encoder( *-----------------------------------------------------------------*/ st->lp_speech = 45.0f; /* Initialize the long-term active speech level in dB */ +#ifndef IVAS_FLOAT_FIXED st->lp_noise = 0.0f; -#ifdef IVAS_FLOAT_FIXED +#else st->lp_noise_fx = 0; #endif st->flag_noisy_speech_snr = 0; @@ -549,8 +568,12 @@ ivas_error init_encoder( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n" ) ); } +#ifndef IVAS_FLOAT_FIXED dtx_enc_init( st, var_SID_rate_flag, interval_SID ); -#ifdef IVAS_FLOAT_FIXED +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr( st->lsp_old1, st->lsp_old1_fx, Q15, M ); +#endif dtx_enc_init_fx( st, var_SID_rate_flag, interval_SID ); #endif } @@ -826,7 +849,11 @@ ivas_error init_encoder( } /* initialize RF indice buffers */ +#ifndef IVAS_FLOAT_FIXED reset_rf_indices( st->hRF, st->L_frame, &st->rf_target_bits_write ); +#else + reset_rf_indices_fx( st ); +#endif } else { @@ -863,6 +890,7 @@ ivas_error init_encoder( } #ifdef MSAN_FIX set_f( st->hTcxEnc->spectrum_long, 0, N_MAX ); + set32_fx( st->hTcxEnc->spectrum_long_fx, 0, N_MAX ); #endif // MSAN_FIX /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ @@ -874,15 +902,23 @@ ivas_error init_encoder( st->hTcxEnc->spectrum[0] = st->hTcxEnc->spectrum_long; st->hTcxEnc->spectrum[1] = st->hTcxEnc->spectrum_long + N_TCX10_MAX; +#ifdef MSAN_FIX + set32_fx( st->hTcxEnc->spectrum_fx[0], 0, N_TCX10_MAX ); + set32_fx( st->hTcxEnc->spectrum_fx[1], 0, N_TCX10_MAX ); +#endif set_f( st->hTcxEnc->old_out, 0, L_FRAME32k ); /* MDCT selector */ +#ifndef IVAS_FLOAT_FIXED MDCT_selector_reset( st->hTcxEnc ); +#else + MDCT_selector_reset_fx( st->hTcxEnc ); +#endif /* MDCT classifier */ +#ifndef IVAS_FLOAT_FIXED MDCT_classifier_reset( st->hTcxEnc ); - -#ifdef IVAS_FLOAT_FIXED +#else MDCT_classifier_reset_fx( st->hTcxEnc ); #endif @@ -936,7 +972,11 @@ ivas_error init_encoder( if ( st->codec_mode == MODE2 || st->element_mode > EVS_MONO ) { +#ifndef IVAS_FLOAT_FIXED st->igf = getIgfPresent( st->element_mode, igf_brate, st->max_bwidth, st->rf_mode ); +#else + st->igf = getIgfPresent_fx( st->element_mode, igf_brate, st->max_bwidth, st->rf_mode ); +#endif } else { @@ -1022,6 +1062,16 @@ ivas_error init_encoder( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } +#ifdef IVAS_FLOAT_FIXED + IF( GT_16( st->element_mode, EVS_MONO ) ) + { + InitTransientDetection_ivas_fx( shl( div_l( st->input_Fs, FRAMES_PER_SEC ), 1 ), 0, st->hTranDet, 1 ); + } + ELSE + { + 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 if ( st->element_mode > EVS_MONO ) { @@ -1031,6 +1081,7 @@ ivas_error init_encoder( { InitTransientDetection( (int16_t) ( st->input_Fs / FRAMES_PER_SEC ), NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); } +#endif /*-----------------------------------------------------------------* * IVAS parameters @@ -1185,7 +1236,6 @@ ivas_error init_encoder_ivas_fx( mvr2r( GEWB_Ave, st->lsf_adaptive_mean, M ); init_gp_clip( st->clip_var ); set_zero( st->mem_MA, M ); - st->streaklimit = 1.0f; pitch_ol_init( #ifndef IVAS_FLOAT_FIXED &st->old_thres, @@ -1244,7 +1294,6 @@ ivas_error init_encoder_ivas_fx( mvr2r( st->lsp_old1, st->lsp_old, M ); mvr2r( st->lsp_old, st->lsp_old16k, M ); mvr2r( st->lsp_old, st->lspold_enc, M ); - st->stab_fac = 0.0f; set_f( st->old_enr_ssf, 0.0f, 2 * NB_SSF ); st->mem_preemph_DFT = 0.0f; set_f( st->inp_12k8_mem_stereo_sw, 0, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); @@ -1259,11 +1308,7 @@ ivas_error init_encoder_ivas_fx( st->diff_sm = 0; st->energy_sm = 0; set_f( st->voicing, 0.0f, 3 ); - st->lt_mean_NB = 0; - st->lt_mean_WB = 0; - st->lt_mean_SWB = 0; st->lp_speech = 45.0f; /* Initialize the long-term active speech level in dB */ - st->lp_noise = 0.0f; st->active_cnt = 0; st->currEnergyLookAhead = 6.1e-5f; #ifndef IVAS_FLOAT_FIXED @@ -1603,15 +1648,16 @@ ivas_error init_encoder_ivas_fx( /* CLDFB-based VAD */ IF( st->element_mode == EVS_MONO ) { - IF( ( st->hVAD_CLDFB = (VAD_CLDFB_HANDLE) malloc( sizeof( T_CldfbVadState ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB VAD\n" ) ); - } + /* This is done to as in EVS T_CldfbVadState structure is present in Encoder State */ + /* + if ( ( st->hVAD_CLDFB = (VAD_CLDFB_HANDLE) malloc( sizeof( T_CldfbVadState ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB VAD\n" ) ); + } + */ + st->hVAD_CLDFB = &st->vad_st; - vad_init_ivas_fx( st->hVAD_CLDFB ); -#if 1 - vad_init( st->hVAD_CLDFB ); -#endif + vad_init_fx( st->hVAD_CLDFB ); } ELSE { @@ -1703,10 +1749,10 @@ ivas_error init_encoder_ivas_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n" ) ); } - dtx_enc_init_fx( st, var_SID_rate_flag, interval_SID ); -#if 1 - dtx_enc_init( st, var_SID_rate_flag, interval_SID ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr( st->lsp_old1, st->lsp_old1_fx, Q15, M ); #endif + dtx_enc_init_fx( st, var_SID_rate_flag, interval_SID ); } ELSE { @@ -2017,9 +2063,6 @@ ivas_error init_encoder_ivas_fx( /* initialize RF indice buffers */ reset_rf_indices_fx( st ); -#if 1 - reset_rf_indices( st->hRF, st->L_frame, &st->rf_target_bits_write ); -#endif } ELSE { @@ -2073,10 +2116,6 @@ ivas_error init_encoder_ivas_fx( /* MDCT classifier */ MDCT_classifier_reset_fx( st->hTcxEnc ); -#if 1 - MDCT_selector_reset( st->hTcxEnc ); - MDCT_classifier_reset( st->hTcxEnc ); -#endif IF( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) { @@ -2188,9 +2227,77 @@ ivas_error init_encoder_ivas_fx( set16_fx( st->totalNoise_increase_hist_fx, 0, TOTALNOISE_HIST_SIZE ); st->totalNoise_increase_len = 0; move16(); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; + IF( hTcxEnc != NULL ) + { + hTcxEnc->L_frameTCX = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); /* 0x0290 is 1/FRAMES_PER_SEC in Q15*/ + move16(); - init_coder_ace_plus_ivas_fx( st, st->last_total_brate, 0 ); + IF( st->ini_frame == 0 ) + { + set_zero( hTcxEnc->Txnq_flt, L_FRAME32k / 2 + 64 ); + hTcxEnc->acelp_zir_flt = hTcxEnc->Txnq_flt + L_FRAME / 2; + } + } + IF( st->hBWE_TD != NULL ) + { + set_zero( st->hBWE_TD->cur_sub_Aq, M + 1 ); + } + + st->currEnergyHF = 0; + + IF( ( NE_16( st->last_L_frame, st->L_frame ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) || ( EQ_16( st->last_core, HQ_CORE ) ) ) + { + set_f( st->mem_MA, 0.0f, M ); + mvr2r( GEWB_Ave, st->mem_AR, M ); + } + + /* Initialize TCX */ + IF( hTcxEnc != NULL ) + { + st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_flt, Q15 ); + } + + /* Initialize Signal Buffers */ + f2me_buf_16( st->buf_speech_enc_flt, st->buf_speech_enc, &st->exp_buf_speech_enc, st->L_frame ); + f2me_buf_16( st->old_wsp, st->old_wsp_fx, &st->exp_old_wsp, L_WSP_MEM ); + f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, L_INP_MEM ); + f2me_buf_16( st->old_inp_16k, st->old_inp_16k_fx, &st->exp_old_inp_16k, L_INP_MEM ); + f2me_buf_16( st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, &st->exp_old_inp_16k, L_WSP_MEM ); + + /* Initialize ACELP */ + if ( st->lspold_enc != NULL ) + { + floatToFixed_arr16( st->lspold_enc, &st->lspold_enc_fx[0], Q15, M ); + } + if ( st->lsp_old1 != NULL ) + { + floatToFixed_arr16( st->lsp_old1, &st->lsp_old1_fx[0], Q15, M ); + } + if ( st->lsp_old != NULL ) + { + floatToFixed_arr16( st->lsp_old, &st->lsp_old_fx[0], Q15, M ); + } + + /* Adaptive BPF */ + set_zero( st->mem_bpf, 2 * L_FILT16k ); + set_zero( st->mem_error_bpf, 2 * L_FILT16k ); +#endif + init_coder_ace_plus_ivas_fx( st, st->last_total_brate, 0 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + st->preemph_fac_flt = fix16_to_float( st->preemph_fac, Q15 ); + IF( st->hLPDmem != NULL ) + { + 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 *-----------------------------------------------------------------*/ @@ -2238,16 +2345,16 @@ ivas_error init_encoder_ivas_fx( Word16 frame_length = BASOP_Util_Divide3232_Scale( st->input_Fs, FRAMES_PER_SEC, &temp ); frame_length = shr( frame_length, sub( 15, temp ) ); +#ifdef IVAS_FLOAT_FIXED IF( GT_16( st->element_mode, EVS_MONO ) ) { InitTransientDetection_ivas_fx( frame_length, 0, st->hTranDet, 1 ); } ELSE { - InitTransientDetection_ivas_fx( frame_length, NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); + InitTransientDetection_ivas_fx( frame_length, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); } - -#if 1 +#else if ( GT_16( st->element_mode, EVS_MONO ) ) { InitTransientDetection( frame_length, 0, st->hTranDet, 1 ); diff --git a/lib_enc/ivas_agc_enc.c b/lib_enc/ivas_agc_enc.c index 2e4c17c8396836b3beaf0616d97286f3778c5769..cd20bc222863af811fb1abcec8b2477a9c382e6a 100644 --- a/lib_enc/ivas_agc_enc.c +++ b/lib_enc/ivas_agc_enc.c @@ -214,6 +214,7 @@ Word32 pow32_fx( Word16 inp, Word16 indx ) *-----------------------------------------------------------------------------------------*/ /*! r: AGC enable flag */ +#ifndef IVAS_FLOAT_FIXED Word16 ivas_agc_enc_get_flag( const Word16 nchan_transport /* i : number of transport channels */ ) @@ -226,9 +227,8 @@ Word16 ivas_agc_enc_get_flag( return agc_flag; } - -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_agc_enc_get_flag_fx( +#else +Word16 ivas_agc_enc_get_flag( const Word16 nchan_transport /* i : number of transport channels */ ) { @@ -249,6 +249,7 @@ Word16 ivas_agc_enc_get_flag_fx( * AGC encoder initialization *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void ivas_agc_enc_init( ivas_agc_enc_state_t *hAgcEnc, const int16_t input_frame, @@ -289,8 +290,7 @@ static void ivas_agc_enc_init( return; } - -#ifdef IVAS_FLOAT_FIXED +#else static void ivas_agc_enc_init_fx( ivas_agc_enc_state_t *hAgcEnc, const Word16 input_frame, @@ -343,6 +343,7 @@ static void ivas_agc_enc_init_fx( * Allocate and initialize SPAR AGC encoder handle *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_spar_agc_enc_open( ivas_agc_enc_state_t **hAgcEnc, /* i/o: SPAR AGC encoder handle */ const int32_t input_Fs, /* i : input sampling rate */ @@ -381,8 +382,7 @@ ivas_error ivas_spar_agc_enc_open( return IVAS_ERR_OK; } - -#ifdef IVAS_FLOAT_FIXED +#else ivas_error ivas_spar_agc_enc_open_fx( ivas_agc_enc_state_t **hAgcEnc, /* i/o: SPAR AGC encoder handle */ const Word32 input_Fs, /* i : input sampling rate */ @@ -392,7 +392,7 @@ ivas_error ivas_spar_agc_enc_open_fx( ivas_agc_enc_state_t *hAgc; Word16 input_frame, delay; - if ( ( hAgc = (ivas_agc_enc_state_t *) malloc( sizeof( ivas_agc_enc_state_t ) ) ) == NULL ) + IF( ( hAgc = (ivas_agc_enc_state_t *) malloc( sizeof( ivas_agc_enc_state_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR AGC encoder" ); } @@ -400,17 +400,17 @@ ivas_error ivas_spar_agc_enc_open_fx( input_frame = (Word16) Mpy_32_16_1( input_Fs, INV_FRAME_PER_SEC_Q15 ); delay = NS2SA_FX2( input_Fs, ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) ); - if ( ( hAgc->agc_com.winFunc_fx = (Word16 *) malloc( sizeof( Word16 ) * ( input_frame - delay ) ) ) == NULL ) + IF( ( hAgc->agc_com.winFunc_fx = (Word16 *) malloc( sizeof( Word16 ) * ( input_frame - delay ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR AGC encoder" ); } - if ( ( hAgc->gain_state = (ivas_agc_enc_chan_state_t *) malloc( sizeof( ivas_agc_enc_chan_state_t ) * nchan_inp ) ) == NULL ) + IF( ( hAgc->gain_state = (ivas_agc_enc_chan_state_t *) malloc( sizeof( ivas_agc_enc_chan_state_t ) * nchan_inp ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR AGC encoder" ); } - if ( ( hAgc->gain_data = (ivas_agc_chan_data_t *) malloc( sizeof( ivas_agc_chan_data_t ) * nchan_inp ) ) == NULL ) + IF( ( hAgc->gain_data = (ivas_agc_chan_data_t *) malloc( sizeof( ivas_agc_chan_data_t ) * nchan_inp ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR AGC encoder" ); } diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index b578a8eeffacb38549253eb9fdb8b595fb3b12ff..20ac14fb6dc9f5bdd0a363e2a3d415aad736ea7a 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -114,8 +114,8 @@ ivas_error ivas_core_enc( Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; /* 2 * Q_new */ Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; /* Q15 */ Word16 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; /* ACELP core synthesis at 12.8kHz or 16kHz to be used by the SWB BWE */ - Word16 *new_swb_speech_fx1; - Word16 new_swb_speech_buffer_fx1[L_FRAME48k + STEREO_DFT_OVL_MAX]; + Word16 *new_swb_speech_fx_16; + Word16 new_swb_speech_buffer_fx_16[L_FRAME48k + STEREO_DFT_OVL_MAX]; #endif int16_t Voicing_flag[CPE_CHANNELS]; #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float fixed conversions @@ -140,6 +140,16 @@ ivas_error ivas_core_enc( Word16 i; #endif + set32_fx( new_swb_speech_buffer_fx, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); + set16_fx( new_swb_speech_buffer_fx_16, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); + +#ifdef MSAN_FIX + FOR( i = 0; i < CPE_CHANNELS; i++ ) + { + set_zero( bwe_exc_extended[i], L_FRAME32k + NL_BUFF_OFFSET ); + } +#endif + push_wmops( "ivas_core_enc" ); error = IVAS_ERR_OK; @@ -230,11 +240,6 @@ ivas_error ivas_core_enc( st->hTcxEnc->tcxltp_norm_corr_past = (Word16) floatToFixed( st->hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); } - IF( st->hTranDet ) - { - floatToFixed_arr( st->hTranDet->subblockEnergies.subblockNrgChange_flt, st->hTranDet->subblockEnergies.subblockNrgChange, Q15 - NRG_CHANGE_E, NSUBBLOCKS + MAX_TD_DELAY ); - } - f2me( cor_map_sum[n], &cor_map_sum_fx, &exp_cor_map_sum ); q_fft_buff = Q_factor_arrL( fft_buff[n], ( 2 * L_FFT ) ); @@ -264,14 +269,6 @@ ivas_error ivas_core_enc( e_enerBuffer += tmp_shift; // Shifting the exponent of energyBuffer with the tmp_shift floatToFixed_arrL( st->Bin_E_old, st->Bin_E_old_fx, Q_factor_arrL( st->Bin_E_old, 129 ), 129 ); - if ( st->element_mode != IVAS_SCE && !st->low_rate_mode && !( st->total_brate > MAX_ACELP_BRATE ) && st->element_mode != IVAS_CPE_MDCT && st->coder_type != INACTIVE && st->sp_aud_decision1 != 0 && st->sp_aud_decision2 != 0 && st->sp_aud_decision1 != 1 && st->sp_aud_decision2 != 0 && !( st->element_mode == IVAS_CPE_TD || st->sp_aud_decision0 == 0 ) ) - { - if ( st->hTcxEnc != NULL ) - { - st->hTcxEnc->clas_sec_old_fx = float_to_fix16( st->hTcxEnc->clas_sec_old_flt, Q13 ); - } - } - /*setTcxmode*/ IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { @@ -323,20 +320,6 @@ ivas_error ivas_core_enc( st->hTcxEnc->tfm_mem = fixedToFloat_32( st->hTcxEnc->tfm_mem_fx, Q31 ); st->hTcxEnc->tcxltp_norm_corr_past_flt = fixedToFloat_16( st->hTcxEnc->tcxltp_norm_corr_past, Q15 ); } - - IF( st->hTranDet ) - { - fixedToFloat_arr( st->hTranDet->subblockEnergies.subblockNrgChange, st->hTranDet->subblockEnergies.subblockNrgChange_flt, Q15 - NRG_CHANGE_E, NSUBBLOCKS + MAX_TD_DELAY ); - } - - /*decison matrix*/ - if ( st->element_mode != IVAS_SCE && !st->low_rate_mode && !( st->total_brate > MAX_ACELP_BRATE ) && st->element_mode != IVAS_CPE_MDCT && st->coder_type != INACTIVE && st->sp_aud_decision1 != 0 && st->sp_aud_decision2 != 0 && st->sp_aud_decision1 != 1 && st->sp_aud_decision2 != 0 && !( st->element_mode == IVAS_CPE_TD || st->sp_aud_decision0 == 0 ) ) - { - if ( st->hTcxEnc != NULL ) - { - st->hTcxEnc->clas_sec_old_flt = fix16_to_float( st->hTcxEnc->clas_sec_old_fx, Q13 ); - } - } #endif if ( st->element_mode == IVAS_CPE_MDCT || st->element_mode == IVAS_SCE ) @@ -465,7 +448,6 @@ ivas_error ivas_core_enc( // floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); // floatToFixed_arr( lsp_mid, lsp_mid_fx, Q15, M ); - st->hTcxEnc->noiseTiltFactor = float_to_fix16( st->hTcxEnc->noiseTiltFactor_flt, Q15 ); st->hTcxCfg->preemph_fac = float_to_fix16( st->hTcxCfg->preemph_fac_flt, Q15 ); { @@ -476,14 +458,7 @@ ivas_error ivas_core_enc( st->clip_var_fx[4] = float_to_fix16( st->clip_var[4], Q14 ); st->clip_var_fx[5] = float_to_fix16( st->clip_var[5], Q14 ); } - st->hTcxEnc->tcx_target_bits_fac = float_to_fix16( st->hTcxEnc->tcx_target_bits_fac_flt, Q14 ); - st->hTcxCfg->sq_rounding = float_to_fix16( st->hTcxCfg->sq_rounding_flt, Q15 ); st->hTcxEnc->measuredBwRatio = float_to_fix16( st->hTcxEnc->measuredBwRatio_flt, Q14 ); - st->hTcxCfg->na_scale = float_to_fix16( st->hTcxCfg->na_scale_flt, Q15 ); - if ( st->hTdCngEnc != NULL ) - { - st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 ); - } floatToFixed_arr( st->hTcxEnc->Txnq_flt, st->hTcxEnc->Txnq, -1, L_FRAME32k / 2 + 64 ); st->hTcxEnc->Q_old_out = Q_factor_arr( st->hTcxEnc->old_out, L_FRAME32k ) - 1; @@ -494,7 +469,6 @@ ivas_error ivas_core_enc( floatToFixed_arrL( st->hTdCngEnc->ho_ener_circ, st->hTdCngEnc->ho_ener_circ_fx, Q6, HO_HIST_SIZE ); floatToFixed_arr( st->hTdCngEnc->ho_lsp_circ, st->hTdCngEnc->ho_lsp_circ_fx, Q15, HO_HIST_SIZE * M ); floatToFixed_arrL( st->hTdCngEnc->ho_env_circ, st->hTdCngEnc->ho_env_circ_fx, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); - st->hTdCngEnc->lp_ener_fx = float_to_fix( st->hTdCngEnc->lp_ener, Q6 ); // floatToFixed_arr( st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_exc2_buf, Q_exc, HO_HIST_SIZE * L_FFT ); } @@ -520,7 +494,6 @@ ivas_error ivas_core_enc( st->hTcxEnc->measuredBwRatio_flt = fix16_to_float( st->hTcxEnc->measuredBwRatio, Q14 ); - st->streaklimit = fix16_to_float( st->streaklimit_fx, Q15 ); fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); { st->clip_var[0] = (float) st->clip_var_fx[0] / 2.56f; @@ -538,17 +511,11 @@ ivas_error ivas_core_enc( st->mem_AR[j] = (float) st->mem_AR_fx[j] / 2.56f; st->mem_MA[j] = (float) st->mem_MA_fx[j] / 2.56f; } - if ( st->enablePlcWaveadjust ) - { - st->hTcxCfg->SFM2_flt = fix_to_float( st->hTcxCfg->SFM2, Q31 ); - } for ( int k = 0; k < 2; k++ ) { fixedToFloat_arrL( st->hTcxEnc->spectrum_fx[k], st->hTcxEnc->spectrum[k], 31 - st->hTcxEnc->spectrum_e[k], 720 ); } fixedToFloat_arr( st->hTcxEnc->Txnq, st->hTcxEnc->Txnq_flt, -1, L_FRAME32k / 2 + 64 ); - st->hTcxEnc->noiseTiltFactor_flt = fix16_to_float( st->hTcxEnc->noiseTiltFactor, Q15 ); - st->hTcxEnc->tcx_target_bits_fac_flt = me2f_16( st->hTcxEnc->tcx_target_bits_fac, Q15 - Q14 ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS #else /* TCX core encoder */ @@ -942,7 +909,7 @@ ivas_error ivas_core_enc( new_swb_speech = new_swb_speech_buffer + STEREO_DFT_OVL_MAX; #ifdef IVAS_FLOAT_FIXED new_swb_speech_fx = new_swb_speech_buffer_fx + STEREO_DFT_OVL_MAX; - new_swb_speech_fx1 = new_swb_speech_buffer_fx1 + STEREO_DFT_OVL_MAX; + new_swb_speech_fx_16 = new_swb_speech_buffer_fx_16 + STEREO_DFT_OVL_MAX; #endif if ( !st->Opt_SC_VBR && input_Fs >= 32000 && st->hBWE_TD != NULL ) @@ -952,7 +919,7 @@ ivas_error ivas_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 new_swb_speech_16_fx[L_FRAME48k] = { 0 }; + // Word16 new_swb_speech_16_fx[L_FRAME48k] = { 0 }; Word16 use_shb32 = 0; Word16 q_realImagBuffer = Q_factor_arrL( (float *) &realBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); q_realImagBuffer = s_min( q_realImagBuffer, Q_factor_arrL( (float *) &imagBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ) ); @@ -999,7 +966,7 @@ ivas_error ivas_core_enc( } #endif #endif - swb_pre_proc_ivas_fx( st, new_swb_speech_16_fx, new_swb_speech_fx, shb_speech_fx, shb_speech_fx_32, &use_shb32, realBuffer_fx, imagBuffer_fx, q_realImagBuffer, hCPE ); + swb_pre_proc_ivas_fx( st, new_swb_speech_fx_16, new_swb_speech_fx, shb_speech_fx, shb_speech_fx_32, &use_shb32, realBuffer_fx, imagBuffer_fx, q_realImagBuffer, hCPE ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( (Word16 *) &st->hBWE_TD->old_speech_shb_fx[0], (float *) &st->hBWE_TD->old_speech_shb[0], 0, L_LOOK_16k + L_SUBFR16k ); fixedToFloat_arr( (Word16 *) &st->hBWE_FD->old_fdbwe_speech_fx[0], (float *) &st->hBWE_FD->old_fdbwe_speech[0], 0, L_FRAME48k ); @@ -1009,7 +976,7 @@ ivas_error ivas_core_enc( st->hBWE_FD->old_input[ii] = (Word16) st->hBWE_FD->old_input_fx[ii]; } fixedToFloat_arrL32( (Word32 *) &st->cldfbSynTd->cldfb_state_fx[0], (float *) &st->cldfbSynTd->cldfb_state[0], q_realImagBuffer, st->cldfbSynTd->p_filter_length ); - fixedToFloat_arr( new_swb_speech_16_fx, new_swb_speech, 0, L_FRAME48k ); + fixedToFloat_arr( new_swb_speech_fx_16, new_swb_speech, 0, L_FRAME48k ); if ( use_shb32 == 0 ) { fixedToFloat_arr( shb_speech_fx, shb_speech, 0, L_FRAME16k ); @@ -1134,9 +1101,11 @@ ivas_error ivas_core_enc( fb_tbe_enc( st, st->input, fb_exc ); #else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS +#ifndef MSAN_FIX Q_fb_exc = Q_factor_arr( fb_exc, L_FRAME16k ); floatToFixed_arr( fb_exc, fb_exc_fx, Q_fb_exc, L_FRAME16k ); - // Q_input is being calculated inside already +#endif + // Q_input is being calculated inside already Word16 Q_input = 0; floatToFixed_arr( st->input_buff, st->input_buff_fx, Q_input, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); Word16 len_old_input_fhb_fx = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2; @@ -1189,7 +1158,7 @@ ivas_error ivas_core_enc( for ( int ii = 0; ii < L_FRAME48k + STEREO_DFT_OVL_MAX; ii++ ) { - new_swb_speech_buffer_fx1[ii] = (Word16) new_swb_speech_buffer[ii]; + new_swb_speech_buffer_fx_16[ii] = (Word16) new_swb_speech_buffer[ii]; } for ( int ii = 0; ii < NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ); ii++ ) { @@ -1197,7 +1166,7 @@ ivas_error ivas_core_enc( } #endif /* SWB(FB) BWE encoder */ - swb_bwe_enc_ivas_fx( st, last_element_mode, old_inp_12k8_fx, old_inp_16k_fx, old_syn_12k8_16k_fx[n], new_swb_speech_fx1, shb_speech_fx, q_shb_speech_fx, q_val ); + swb_bwe_enc_ivas_fx( st, last_element_mode, old_inp_12k8_fx, old_inp_16k_fx, old_syn_12k8_16k_fx[n], new_swb_speech_fx_16, shb_speech_fx, q_shb_speech_fx, q_val ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( st->hBWE_FD != NULL ) { @@ -1340,12 +1309,15 @@ ivas_error ivas_core_enc( f2me_buf_16( hCPE->hStereoICBWE->shbSynthRef, hCPE->hStereoICBWE->shbSynthRef_fx, &hCPE->hStereoICBWE->shbSynthRef_e, L_LOOK_16k ); // shb_speech_ref_e f2me( hCPE->hStereoICBWE->icbweRefEner, &hCPE->hStereoICBWE->icbweRefEner_fx, &hCPE->hStereoICBWE->icbweRefEner_e ); - scale_factor = Q_factor_arrL( hCPE->hStereoICBWE->lpSHBRef, LPC_SHB_ORDER + 1 ) - 1; scale_factor = s_min( scale_factor, Q_factor_arrL( hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref, LPC_SHB_ORDER ) ); - floatToFixed_arr32( hCPE->hStereoICBWE->lpSHBRef, hCPE->hStereoICBWE->lpSHBRef_fx, scale_factor, LPC_SHB_ORDER + 1 ); floatToFixed_arr32( hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref, hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref_fx, scale_factor, LPC_SHB_ORDER ); +#ifdef MSAN_FIX + f2me_buf( hCPE->hStereoICBWE->lpSHBRef, hCPE->hStereoICBWE->lpSHBRef_fx, &hCPE->hStereoICBWE->lpSHBRef_e, LPC_SHB_ORDER + 1 ); +#else + scale_factor = Q_factor_arrL( hCPE->hStereoICBWE->lpSHBRef, LPC_SHB_ORDER + 1 ) - 1; + floatToFixed_arr32( hCPE->hStereoICBWE->lpSHBRef, hCPE->hStereoICBWE->lpSHBRef_fx, scale_factor, LPC_SHB_ORDER + 1 ); hCPE->hStereoICBWE->lpSHBRef_e = 31 - scale_factor; - +#endif #endif stereo_icBWE_enc_ivas_fx( hCPE, shb_speech_fx32, 31 - q_shb_speech_fx32, new_swb_speech_buffer_fx, 31 - q_new_swb_speech_buffer, voice_factors_fx32[0] ); @@ -1457,17 +1429,9 @@ ivas_error ivas_core_enc( mvr2r( GEWB_Ave, st->mem_AR, M ); } - IF( st->hTcxEnc != NULL ) - { - IF( st->element_mode != IVAS_CPE_MDCT ) - { - st->hTcxEnc->kernel_switch_corr_past_flt = 0.f; - } - } - IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) { - st->hTcxEnc->tcxltp_norm_corr_mem_flt = fixedToFloat( st->hTcxEnc->tcxltp_norm_corr_mem, 31 ); + st->hTcxEnc->tcxltp_norm_corr_mem_flt = fixedToFloat( st->hTcxEnc->tcxltp_norm_corr_mem, 15 ); } IF( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->mdct_sw, MODE2 ) ) @@ -1481,17 +1445,6 @@ ivas_error ivas_core_enc( st->preemph_fac_flt = PREEMPH_FAC_16k_FLT; } } - - IF( st->Opt_DTX_ON && st->hTdCngEnc != NULL ) - { - IF( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->hDtxEnc->first_CNG, 1 ) ) - { - IF( ( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && GE_16( st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) ) - { - st->hTdCngEnc->CNG_att = fix16_to_float( st->hTdCngEnc->CNG_att_fx, Q7 ); - } - } - } #endif #else updt_enc_common( st ); diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 598a5094b57c0b12f210a840266d095f4bb148df..7902d1cf85ab2da31b884acd9956b5df6de0217e 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -1138,7 +1138,9 @@ ivas_error ivas_compute_core_buffers( Word16 inp16k_out_buf_fx[2][L_FRAME16k]; Word16 **inp16k_out_fx = (Word16 **) inp16k_out_buf_fx; Word16 new_inp_resamp16k_out_fx[L_FRAME16k]; - +#ifdef MSAN_FIX + set16_fx( new_inp_resamp16k_fx, 0, L_FRAME16k ); +#endif signal_in_32fx = st->input32_fx; signal_in_fx = st->input_fx; @@ -1159,7 +1161,9 @@ ivas_error ivas_compute_core_buffers( floatToFixed_arr16( old_inp_16k, old_inp_16k_fx, Q_old_inp_16k, L_INP ); floatToFixed_arr16( signal_in, signal_in_fx, Q_old_inp_16k, 960 ); +#ifndef MSAN_FIX floatToFixed_arr16( new_inp_resamp16k, new_inp_resamp16k_fx, Q_old_inp_16k, L_FRAME16k ); +#endif floatToFixed_arr16( st->old_inp_16k, st->old_inp_16k_fx, Q_old_inp_16k, L_INP_MEM ); floatToFixed_arr16( st->mem_decim16k, st->mem_decim16k_fx, Q_old_inp_16k, 2 * L_FILT_MAX ); @@ -1839,7 +1843,7 @@ ivas_error ivas_compute_core_buffers( Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); } - analy_lp_fx( inp_16k_fx, L_FRAME16k, L_look, &ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, 0, Q_old_inp_16k, Q_r ); + analy_lp_ivas_fx( inp_16k_fx, L_FRAME16k, L_look, &ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, 0, Q_old_inp_16k, Q_r ); /*--------------------------------------------------------------* * Compute Weighted Input diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 00bfb09530718d84a95c97d605620f4542dc6988..b84e822620f97926f3842a4812b3fe0f4e772d7c 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -1091,7 +1091,19 @@ ivas_error pre_proc_front_ivas_fx( Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; +#ifdef MSAN_FIX + for ( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ ) + { + set32_fx( realBuffer_fx[k], 0, CLDFB_NO_CHANNELS_MAX ); + } +#endif Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; +#ifdef MSAN_FIX + for ( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ ) + { + set32_fx( imagBuffer_fx[k], 0, CLDFB_NO_CHANNELS_MAX ); + } +#endif Word16 sf_energySum[CLDFB_NO_CHANNELS_MAX]; Word16 max_e; @@ -1605,7 +1617,6 @@ ivas_error pre_proc_front_ivas_fx( /*float to fix conversions for wb_vad_ivas_fx*/ Word16 Q_new = Q_factor_arr( fr_bands, 40 ) + 3; floatToFixed_arrL( fr_bands, fr_bands_fx, Q_new + QSCALE, 40 ); - st->lp_noise_fx = float_to_fix16( st->lp_noise, 8 ); st->lp_speech_fx = float_to_fix16( st->lp_speech, 8 ); floatToFixed_arrL( st->hNoiseEst->bckr, st->hNoiseEst->bckr_fx, Q_new + QSCALE, 20 ); floatToFixed_arrL( st->hNoiseEst->enrO, st->hNoiseEst->enrO_fx, Q_new + QSCALE, 20 ); @@ -1616,9 +1627,6 @@ ivas_error pre_proc_front_ivas_fx( if ( st->cldfbAnaEnc ) st->cldfbAnaEnc->scale = (Word16) ( st->cldfbAnaEnc->scale_flt * ( 1 << 8 ) ); - st->lt_mean_NB_fx = (Word16) st->lt_mean_NB * ( 1 << 11 ); - st->lt_mean_WB_fx = (Word16) st->lt_mean_WB * ( 1 << 11 ); - st->lt_mean_SWB_fx = (Word16) st->lt_mean_SWB * ( 1 << 11 ); Word16 Q_bands0 = 0, Q_bands1 = 0; IF( lr_vad_enabled && st->idchan == 0 ) @@ -1786,10 +1794,6 @@ ivas_error pre_proc_front_ivas_fx( st->hNoiseEst->sign_dyn_lp = fixedToFloat( st->hNoiseEst->sign_dyn_lp_fx, 8 ); st->flag_noisy_speech_snr = (Word16) st->flag_noisy_speech_snr_fx; - st->lt_mean_NB = (float) st->lt_mean_NB_fx / ( 1 << 11 ); - st->lt_mean_WB = (float) st->lt_mean_WB_fx / ( 1 << 11 ); - st->lt_mean_SWB = (float) st->lt_mean_SWB_fx / ( 1 << 11 ); - /*fixed to float for noise_est_down*/ fixedToFloat_arrL( st->hNoiseEst->bckr_fx, st->hNoiseEst->bckr, Q_new + QSCALE, NB_BANDS ); fixedToFloat_arrL( tmpN_fx, tmpN, Q_new + QSCALE, 20 ); @@ -1862,11 +1866,17 @@ ivas_error pre_proc_front_ivas_fx( Word16 q_band_energies_LR = Q_factor_arrL( band_energies_LR, 2 * NB_BANDS ); band_energies_LR_fx_exp = 31 - q_band_energies_LR; floatToFixed_arrL( band_energies_LR, band_energies_LR_fx, ( 31 - band_energies_LR_fx_exp ), 2 * NB_BANDS ); - +#ifdef MSAN_FIX + Word16 q_enerBuffer = Q_factor_arrL( enerBuffer, st->cldfbAnaEnc->no_channels ); +#else Word16 q_enerBuffer = Q_factor_arrL( enerBuffer, CLDFB_NO_CHANNELS_MAX ); +#endif enerBuffer_fx_exp = 31 - q_enerBuffer; +#ifdef MSAN_FIX + floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), st->cldfbAnaEnc->no_channels ); +#else floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), CLDFB_NO_CHANNELS_MAX ); - +#endif Word16 normmsPeriodog = Q_factor_arrL( st->hFdCngEnc->msPeriodog, NPART ); st->hFdCngEnc->msPeriodog_fx_exp = 31 - normmsPeriodog; st->hFdCngEnc->msPeriodog_fx_exp_cldfb = 31 - normmsPeriodog; @@ -1877,7 +1887,11 @@ ivas_error pre_proc_front_ivas_fx( Word16 normmsNoiseEst = Q_factor_arrL( st->hFdCngEnc->msNoiseEst, NPART ); st->hFdCngEnc->msNoiseEst_fx_exp = 31 - normmsNoiseEst; floatToFixed_arrL( st->hFdCngEnc->msNoiseEst, st->hFdCngEnc->msNoiseEst_fx, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); +#ifdef MSAN_FIX + floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, st->hFdCngEnc->hFdCngCom->nCLDFBpart ); +#else floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, NPARTCLDFB ); +#endif #endif perform_noise_estimation_enc_ivas_fx( band_energies_LR_fx, band_energies_LR_fx_exp, enerBuffer_fx_loc, enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -1896,12 +1910,17 @@ ivas_error pre_proc_front_ivas_fx( Word16 q_band_energies = Q_factor_arrL( band_energies, 2 * NB_BANDS ); band_energies_fx_exp = 31 - q_band_energies; floatToFixed_arrL( band_energies, band_energies_fx, ( 31 - band_energies_fx_exp ), 2 * NB_BANDS ); - - +#ifdef MSAN_FIX + Word16 q_enerBuffer = Q_factor_arrL( enerBuffer, st->cldfbAnaEnc->no_channels ); +#else Word16 q_enerBuffer = Q_factor_arrL( enerBuffer, CLDFB_NO_CHANNELS_MAX ); +#endif enerBuffer_fx_exp = 31 - q_enerBuffer; +#ifdef MSAN_FIX + floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), st->cldfbAnaEnc->no_channels ); +#else floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), CLDFB_NO_CHANNELS_MAX ); - +#endif Word16 normmsPeriodog = Q_factor_arrL( st->hFdCngEnc->msPeriodog, NPART ); st->hFdCngEnc->msPeriodog_fx_exp = 31 - normmsPeriodog; st->hFdCngEnc->msPeriodog_fx_exp_cldfb = 31 - normmsPeriodog; @@ -1912,8 +1931,11 @@ ivas_error pre_proc_front_ivas_fx( Word16 normmsNoiseEst = Q_factor_arrL( st->hFdCngEnc->msNoiseEst, NPART ); st->hFdCngEnc->msNoiseEst_fx_exp = 31 - normmsNoiseEst; floatToFixed_arrL( st->hFdCngEnc->msNoiseEst, st->hFdCngEnc->msNoiseEst_fx, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); +#ifdef MSAN_FIX + floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, st->hFdCngEnc->hFdCngCom->nCLDFBpart ); +#else floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, NPARTCLDFB ); - +#endif Word16 normmsperiodog = Q_factor_arrL( st->hFdCngEnc->hFdCngCom->periodog_flt, PERIODOGLEN ); st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog = 31 - normmsperiodog; // floatToFixed_arrL( st->hFdCngEnc->hFdCngCom->periodog_flt, st->hFdCngEnc->hFdCngCom->periodog, 31 - st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog, PERIODOGLEN); @@ -1954,7 +1976,6 @@ ivas_error pre_proc_front_ivas_fx( Word16 Q_inp_12k8 = Q_factor_arr( inp_12k8, L_FRAME ); floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_inp_12k8, L_FRAME ); // Q_lp_noise = Q_factor( st->lp_noise ); - st->lp_noise_fx = float_to_fix16( st->lp_noise, Q8 ); #endif dtx_ivas_fx( st, ivas_total_brate, *vad_flag_dtx, inp_12k8_fx, Q_inp_12k8 ); #endif @@ -2071,8 +2092,8 @@ ivas_error pre_proc_front_ivas_fx( move16(); } - analy_lp_fx( inp_12k8_loc_fx, L_FRAME, L_look, &ener_fx, A_loc_fx, epsP_h_loc, epsP_l_loc, lsp_new_loc_fx, lsp_mid_loc_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, - INT_FS_12k8, i, Q_new_loc, Q_r ); + analy_lp_ivas_fx( inp_12k8_loc_fx, L_FRAME, L_look, &ener_fx, A_loc_fx, epsP_h_loc, epsP_l_loc, lsp_new_loc_fx, lsp_mid_loc_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, + INT_FS_12k8, i, Q_new_loc, Q_r ); lsp2lsf_fx( lsp_new_loc_fx, lsf_new_16_loc_fx, M, INT_FS_12k8 ); @@ -2107,6 +2128,9 @@ ivas_error pre_proc_front_ivas_fx( } stab_fac = (float) ( (float) stab_fac_fx / 32767.0f ); + + free( old_inp_12k8_loc_fx ); + #endif if ( element_mode == IVAS_CPE_TD && st->idchan == 1 ) { @@ -2358,7 +2382,6 @@ ivas_error pre_proc_front_ivas_fx( } } - st->lp_noise_fx = float_to_fix16( st->lp_noise, Q8 ); st->hNoiseEst->Etot_last_fx = float_to_fix16( st->hNoiseEst->Etot_last, Q8 ); floatToFixed_arr32( st->old_enr_ssf, st->old_enr_ssf_fx, 0, 2 * NB_SSF ); @@ -2677,14 +2700,12 @@ ivas_error pre_proc_front_ivas_fx( Etot_fx = float_to_fix( Etot, 8 ); Etot16_fx = extract_l( Etot_fx ); st->lp_speech_fx = float_to_fix16( st->lp_speech, 8 ); - st->lp_noise_fx = float_to_fix16( st->lp_noise, 8 ); st->hNoiseEst->Etot_last_fx = float_to_fix16( st->hNoiseEst->Etot_last, 8 ); #endif ivas_long_enr_fx( st, Etot16_fx, localVAD_HE_SAD, high_lpn_flag, NULL, 1, NULL, NULL ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // conv params from fix to float st->lp_speech = fix16_to_float( st->lp_speech_fx, 8 ); - st->lp_noise = fix16_to_float( st->lp_noise_fx, 8 ); st->hNoiseEst->Etot_last = fix16_to_float( st->hNoiseEst->Etot_last_fx, 8 ); #endif #endif @@ -2916,30 +2937,29 @@ ivas_error pre_proc_front_ivas_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS IF( EQ_16( element_mode, IVAS_SCE ) ) { - Word16 q1 = Q_factor_arr( st->hTranDet->subblockEnergies.subblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY ); - Word16 q2 = Q_factor_arr( st->hTranDet->subblockEnergies.accSubblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY + 1 ); - - st->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg = float_to_fix16( st->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg_flt, Q15 ); - floatToFixed_arrL( st->hTranDet->subblockEnergies.subblockNrg_flt, st->hTranDet->subblockEnergies.subblockNrg, q1, NSUBBLOCKS + MAX_TD_DELAY ); - floatToFixed_arrL( st->hTranDet->subblockEnergies.accSubblockNrg_flt, st->hTranDet->subblockEnergies.accSubblockNrg, q2, NSUBBLOCKS + MAX_TD_DELAY + 1 ); - st->hTranDet->subblockEnergies.subblockNrg_e = 31 - q1; - st->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - q2; + Word16 q1 = Q7; + Word16 q2 = Q7; + st->hTranDet->subblockEnergies.subblockNrg_e = sub( 31, q1 ); + st->hTranDet->subblockEnergies.accSubblockNrg_e = sub( 31, q2 ); + move16(); + move16(); + move16(); + move16(); } ELSE IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { FOR( i = 0; i < CPE_CHANNELS; i++ ) { - Word16 q1 = Q_factor_arr( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY ); - Word16 q2 = Q_factor_arr( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY + 1 ); - - hCPE->hCoreCoder[i]->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg = float_to_fix16( hCPE->hCoreCoder[i]->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg_flt, Q15 ); - floatToFixed_arrL( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_flt, hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg, q1, NSUBBLOCKS + MAX_TD_DELAY ); - floatToFixed_arrL( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_flt, hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg, q2, NSUBBLOCKS + MAX_TD_DELAY + 1 ); - hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_e = 31 - q1; - hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - q2; + Word16 q1 = Q7; + Word16 q2 = Q7; + hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_e = sub( 31, q1 ); + hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_e = sub( 31, q2 ); + move16(); + move16(); + move16(); + move16(); } } - #endif IF( EQ_16( element_mode, IVAS_SCE ) ) { @@ -2961,24 +2981,6 @@ ivas_error pre_proc_front_ivas_fx( } } } - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( EQ_16( element_mode, IVAS_SCE ) ) - { - fixedToFloat_arrL( st->hTranDet->subblockEnergies.subblockNrg, st->hTranDet->subblockEnergies.subblockNrg_flt, ( 31 - st->hTranDet->subblockEnergies.subblockNrg_e ), NSUBBLOCKS + MAX_TD_DELAY ); - fixedToFloat_arrL( st->hTranDet->subblockEnergies.accSubblockNrg, st->hTranDet->subblockEnergies.accSubblockNrg_flt, ( 31 - st->hTranDet->subblockEnergies.accSubblockNrg_e ), NSUBBLOCKS + MAX_TD_DELAY + 1 ); - st->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg_flt = fix16_to_float( st->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg, Q15 ); - } - ELSE IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) - { - FOR( i = 0; i < CPE_CHANNELS; i++ ) - { - fixedToFloat_arrL( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg, hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_flt, ( 31 - hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_e ), NSUBBLOCKS + MAX_TD_DELAY ); - fixedToFloat_arrL( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg, hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_flt, ( 31 - hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_e ), NSUBBLOCKS + MAX_TD_DELAY + 1 ); - hCPE->hCoreCoder[i]->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg_flt = fix16_to_float( hCPE->hCoreCoder[i]->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg, Q15 ); - } - } -#endif #else if ( element_mode == IVAS_SCE ) { @@ -3023,7 +3025,6 @@ ivas_error pre_proc_front_ivas_fx( st->old_corr_fx = float_to_fix16( st->old_corr, Q15 ); floatToFixed_arrL( st->hSpMusClas->finc_prev, st->hSpMusClas->finc_prev_fx, 2 * Q_new, ATT_NSEG ); st->hSpMusClas->lt_finc_fx = floatToFixed( st->hSpMusClas->lt_finc, 2 * Q_new ); - st->lp_noise_fx = float_to_fix16( st->lp_noise, Q8 ); st->hSpMusClas->mold_corr_fx = float_to_fix16( st->hSpMusClas->mold_corr, Q15 ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index bb0125e113549e58994edf965d2feaaeb5542abd..9fb4736f18ba015607c1dfbdf89f572f8a940b5d 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -986,10 +986,18 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; move32(); st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hCPE[0]->element_brate, 42949673 ) ) /* 1/50 in Q31*/; // ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); +#ifndef IVAS_FLOAT_FIXED st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, L_mult0( st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal, FRAMES_PER_SEC ), st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); +#else + st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent_fx( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, + L_mult0( st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal, FRAMES_PER_SEC ), + st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, + st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); +#endif + move16(); IF( ( error = IGF_Reconfig( &st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc, st_ivas->hCPE[0]->hCoreCoder[n]->igf, 1, st_ivas->hCPE[0]->element_brate, st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index c48f9bf7fc5959a3c98ad936e2fdee406b0280d9..7f79fdbc2d4bac902fde2ed5b451152933cf4ace 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -173,6 +173,12 @@ ivas_error ivas_cpe_enc( set16_fx( voicing_fr_fx[0], 0, NB_SUBFR ); set16_fx( voicing_fr_fx[1], 0, NB_SUBFR ); +#ifdef MSAN_FIX + FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) + { + set_zero( fft_buff[i], 2 * L_FFT ); + } +#endif /*------------------------------------------------------------------* * CPE initialization - core coder *-----------------------------------------------------------------*/ @@ -234,11 +240,13 @@ ivas_error ivas_cpe_enc( move16(); Word16 front_create_flag = 0; move16(); +#ifdef MSAN_FIX + set_f( band_energies_LR, 0, 2 * NB_BANDS ); +#endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( n = 0; n < CPE_CHANNELS; n++ ) { sts[n]->lp_speech_fx = (Word16) floatToFixed( sts[n]->lp_speech, Q8 ); - sts[n]->lp_noise_fx = (Word16) floatToFixed( sts[n]->lp_noise, Q8 ); sts[n]->flag_noisy_speech_snr_fx = (Word8) sts[n]->flag_noisy_speech_snr; Q_buffer[n] = 15; move16(); @@ -466,57 +474,13 @@ ivas_error ivas_cpe_enc( { #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - sts[n]->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( sts[n]->hTranDet->subblockEnergies.firState1_flt, -1 ); - sts[n]->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( sts[n]->hTranDet->subblockEnergies.firState2_flt, -1 ); - - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - sts[n]->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( sts[n]->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); - } - - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - sts[n]->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( sts[n]->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); - sts[n]->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( sts[n]->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); - } - - - FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - sts[n]->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( sts[n]->hTranDet->delayBuffer.buffer_flt[i], -1 ); - } - - sts[n]->hTranDet->transientDetector.attackRatioThreshold = (Word16) floatToFixed( sts[n]->hTranDet->transientDetector.attackRatioThreshold_flt, 11 ); - floatToFixed_arr16( sts[n]->input, sts[n]->input_fx, -1, input_frame ); - - sts[n]->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( sts[n]->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); - #endif - RunTransientDetection_ivas_fx( sts[n]->input_fx, input_frame, sts[n]->hTranDet ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - sts[n]->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) sts[n]->hTranDet->subblockEnergies.firState1, -1 ); - sts[n]->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) sts[n]->hTranDet->subblockEnergies.firState2, -1 ); - - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - sts[n]->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( sts[n]->hTranDet->subblockEnergies.subblockNrg[i], 7 ); - sts[n]->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) sts[n]->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); - } - - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - sts[n]->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( sts[n]->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); - } - - FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - sts[n]->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) sts[n]->hTranDet->delayBuffer.buffer[i], -1 ); - } -#endif + sts[n]->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; + sts[n]->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; + move16(); + move16(); #else RunTransientDetection( sts[n]->input, input_frame, sts[n]->hTranDet ); #endif @@ -524,9 +488,6 @@ ivas_error ivas_cpe_enc( #ifndef IVAS_FLOAT_FIXED currFlatness[n] = GetTCXAvgTemporalFlatnessMeasure( sts[n]->hTranDet, NSUBBLOCKS, 0 ); #else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( sts[n]->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, sts[n]->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, 7, NSUBBLOCKS + MAX_TD_DELAY ); -#endif currFlatness_fx[n] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( sts[n]->hTranDet, NSUBBLOCKS, 0 ); move16(); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -702,7 +663,6 @@ ivas_error ivas_cpe_enc( floatToFixed_arr( &hCPE->hStereoDft->input_mem_itd[i][0], &hCPE->hStereoDft->input_mem_itd_fx[i][0], hCPE->hStereoDft->q_input_mem_itd[i], STEREO_DFT_OVL_MAX ); #endif // MSAN_FIX } - floatToFixed_arrL( hCPE->hStereoDft->hItd->itd, hCPE->hStereoDft->hItd->itd_fx, 16, STEREO_DFT_ENC_DFT_NB ); #ifndef MSAN_FIX hCPE->hStereoClassif->xtalk_score_fx = floatToFixed( hCPE->hStereoClassif->xtalk_score, 31 ); #endif // !MSAN_FIX @@ -848,8 +808,6 @@ ivas_error ivas_cpe_enc( floatToFixed_arr( sts[i]->old_input_signal, sts[i]->old_input_signal_fx, sts[i]->q_inp, 1965 ); floatToFixed_arr( &hCPE->input_mem[i][0], &hCPE->input_mem_fx[i][0], hCPE->q_input_mem[i], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); } - floatToFixed_arrL( hCPE->hStereoMdct->hItd->itd, hCPE->hStereoMdct->hItd->itd_fx, 16, STEREO_DFT_ENC_DFT_NB ); - floatToFixed_arrL( hCPE->hStereoMdct->hItd->deltaItd, hCPE->hStereoMdct->hItd->deltaItd_fx, 16, STEREO_DFT_ENC_DFT_NB ); floatToFixed_arr( hCPE->hCoreCoder[0]->voicing, hCPE->hCoreCoder[0]->voicing_fx, 15, 3 ); if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) { @@ -861,7 +819,6 @@ ivas_error ivas_cpe_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( hCPE->hStereoMdct != NULL && hCPE->hStereoMdct->hItd != NULL ) { - fixedToFloat_arrL( hCPE->hStereoMdct->hItd->itd_fx, hCPE->hStereoMdct->hItd->itd, 16, STEREO_DFT_ENC_DFT_NB ); FOR( int16_t i = 0; i < CPE_CHANNELS; i++ ) { fixedToFloat_arr( &hCPE->input_mem_fx[i][0], &hCPE->input_mem[i][0], hCPE->q_input_mem[i], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); @@ -934,8 +891,6 @@ ivas_error ivas_cpe_enc( fixedToFloat_arr( &hCPE->input_mem_fx[i][0], &hCPE->input_mem[i][0], hCPE->q_input_mem[i], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); me2f_buf( hCPE->hStereoDft->DFT_fx[i], hCPE->hStereoDft->DFT_fx_e[i], hCPE->hStereoDft->DFT[i], STEREO_DFT_N_MAX_ENC ); } - fixedToFloat_arrL( hCPE->hStereoDft->hItd->itd_fx, hCPE->hStereoDft->hItd->itd, 16, STEREO_DFT_ENC_DFT_NB ); - /*local fix2flt*/ for ( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) @@ -1067,10 +1022,6 @@ ivas_error ivas_cpe_enc( fft_exp = max_e; #endif stereoFdCngCoherence_fx( sts, hCPE->last_element_mode, fft_buff_fx, fft_exp ); - -#ifdef IVAS_FLOAT_FIXED - sts[0]->hFdCngEnc->hFdCngCom->coherence_flt = fixedToFloat( sts[0]->hFdCngEnc->hFdCngCom->coherence_fx, Q15 ); -#endif #else stereoFdCngCoherence( sts, hCPE->last_element_mode, fft_buff ); #endif @@ -1123,7 +1074,11 @@ ivas_error ivas_cpe_enc( if ( hCPE->element_mode == IVAS_CPE_MDCT && st_ivas->hMCT == NULL ) { /* set coded BW for MDCT stereo */ +#ifndef IVAS_FLOAT_FIXED set_bw_stereo( hCPE ); +#else + set_bw_stereo_fx( hCPE ); +#endif /* reconfiguration of MDCT stereo */ if ( sts[0]->bwidth != sts[0]->last_bwidth || ( ( hCPE->last_element_brate != hCPE->element_brate || hCPE->last_element_mode != hCPE->element_mode ) && sts[0]->bwidth != sts[0]->max_bwidth ) ) @@ -2328,8 +2283,9 @@ ivas_error create_cpe_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo classifier structure\n" ) ); } +#ifndef IVAS_FLOAT_FIXED stereo_classifier_init( hCPE->hStereoClassif ); -#ifdef IVAS_FLOAT_FIXED +#else stereo_classifier_init_fx( hCPE->hStereoClassif ); #endif @@ -2356,7 +2312,11 @@ ivas_error create_cpe_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) ); } +#ifdef IVAS_FLOAT_FIXED + copy_encoder_config_fx( st_ivas, st, 1 ); +#else copy_encoder_config( st_ivas, st, 1 ); +#endif st->total_brate = hCPE->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; @@ -2610,9 +2570,10 @@ ivas_error create_cpe_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo classifier structure\n" ) ); } - stereo_classifier_init_fx( hCPE->hStereoClassif ); -#if 1 // TODO: To be removed later +#ifndef IVAS_FLOAT_FIXED stereo_classifier_init( hCPE->hStereoClassif ); +#else + stereo_classifier_init_fx( hCPE->hStereoClassif ); #endif /*-----------------------------------------------------------------* diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 3206e7ea9e697f23c496f397d03a727ec14c220e..beeec44b71dea5d55fc93eb0c80d8f4ff36ca5c8 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -46,9 +46,17 @@ /*------------------------------------------------------------------------- * Local function prototypes *------------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED +static void computeIntensityVector_enc_fx( + const DIRAC_ENC_HANDLE hDirAC, + Word32 Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], + Word32 Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], + const Word16 enc_param_start_band, /* i : first band to process */ + const Word16 num_frequency_bands, + Word32 intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS] ); +#else static void computeIntensityVector_enc( DIRAC_ENC_HANDLE hDirAC, float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], const int16_t enc_param_start_band, const int16_t num_frequency_bands, float intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS] ); - +#endif /*------------------------------------------------------------------------- * ivas_dirac_enc_open() @@ -130,6 +138,21 @@ ivas_error ivas_dirac_enc_open( } set_f( hDirAC->direction_vector_m[i][j], 0.0f, DIRAC_MAX_NBANDS ); } +#ifdef IVAS_FLOAT_FIXED + IF( ( hDirAC->direction_vector_m_fx[i] = (Word32 **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + if ( ( hDirAC->direction_vector_m_fx[i][j] = (Word32 *) malloc( DIRAC_MAX_NBANDS * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set32_fx( hDirAC->direction_vector_m_fx[i][j], 0, DIRAC_MAX_NBANDS ); + } +#endif } hDirAC->no_col_avg_diff = (int16_t) ( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); @@ -154,6 +177,29 @@ ivas_error ivas_dirac_enc_open( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } set_f( hDirAC->buffer_energy, 0.0f, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); +#ifdef IVAS_FLOAT_FIXED + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + IF( ( hDirAC->buffer_intensity_real_fx[i] = (Word32 **) malloc( hDirAC->no_col_avg_diff * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + IF( ( hDirAC->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( DIRAC_MAX_NBANDS * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set32_fx( hDirAC->buffer_intensity_real_fx[i][j], 0, DIRAC_MAX_NBANDS ); + } + } + + IF( ( hDirAC->buffer_energy_fx = (Word32 *) malloc( DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set32_fx( hDirAC->buffer_energy_fx, 0, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); +#endif if ( st_ivas->hQMetaData->useLowerRes ) { @@ -395,6 +441,10 @@ void ivas_dirac_enc_close( { free( hDirAC->direction_vector_m[i][j] ); hDirAC->direction_vector_m[i][j] = NULL; +#ifdef IVAS_FLOAT_FIXED + free( hDirAC->direction_vector_m_fx[i][j] ); + hDirAC->direction_vector_m_fx[i][j] = NULL; +#endif } for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) @@ -409,8 +459,26 @@ void ivas_dirac_enc_close( free( hDirAC->buffer_intensity_real[i] ); hDirAC->buffer_intensity_real[i] = NULL; +#ifdef IVAS_FLOAT_FIXED + FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + IF( hDirAC->buffer_intensity_real_fx[i][j] != 0 ) + { + free( hDirAC->buffer_intensity_real_fx[i][j] ); + hDirAC->buffer_intensity_real_fx[i][j] = NULL; + } + } + + free( hDirAC->buffer_intensity_real_fx[i] ); + hDirAC->buffer_intensity_real_fx[i] = NULL; +#endif + free( hDirAC->direction_vector_m[i] ); hDirAC->direction_vector_m[i] = NULL; +#ifdef IVAS_FLOAT_FIXED + free( hDirAC->direction_vector_m_fx[i] ); + hDirAC->direction_vector_m_fx[i] = NULL; +#endif } free( hDirAC->buffer_energy ); @@ -453,27 +521,208 @@ ivas_error ivas_dirac_enc( int16_t orig_dirac_bands; float dir[3], avg_dir[3]; #ifdef IVAS_FLOAT_FIXED - Word32 dir_fx[3] /*, avg_dir_fx[3]*/; + Word32 dir_fx[3], avg_dir_fx[3]; #endif float energySum, vecLen; int16_t i, j, b, i_ts; ivas_error error; push_wmops( "ivas_dirac_enc" ); - ivas_dirac_param_est_enc( hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f, ppIn_FR_real, ppIn_FR_imag, input_frame, ivas_format, hodirac_flag, hodirac_flag ? HOA2_CHANNELS : FOA_CHANNELS, &( hDirAC->mono_frame_count ), &( hQMetaData->dirac_mono_flag ) ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + /*---------------------------------------------- float to fixed ----------------------------------------------*/ - if ( hQMetaData->q_direction->cfg.nbands > 0 ) + set16_fx( (Word16 *) hDirAC->buffer_energy_q, 0, DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); + set16_fx( (Word16 *) hDirAC->buffer_intensity_real_q, 0, DIRAC_NUM_DIMS * DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); + Word16 block_m_idx; + Word16 band_m_idx; + Word16 nchan_fb_in = hodirac_flag ? HOA2_CHANNELS : FOA_CHANNELS; + Word16 nblocks = hQMetaData->useLowerRes ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; + + /* Find Q-factor */ + Word16 pcm_q; + Word16 pp_fr_q; + float max_val = 0; + for ( i = 0; i < nchan_fb_in; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + max_val = max( max_val, (float) fabs( data_f[i][j] ) ); + } + } + pcm_q = Q_factor_L( max_val ); + + max_val = 0; + for ( i = 0; i < nchan_fb_in; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + max_val = max( max_val, (float) fabs( ppIn_FR_real[i][j] ) ); + max_val = max( max_val, (float) fabs( ppIn_FR_imag[i][j] ) ); + } + } + pp_fr_q = Q_factor_L( max_val ); + + Word32 fr_real_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; + Word32 fr_imag_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; + Word32 data_f_buf[DIRAC_MAX_ANA_CHANS][L_FRAME48k]; + Word32 *pp_fr_real_fx[DIRAC_MAX_ANA_CHANS]; + Word32 *pp_fr_imag_fx[DIRAC_MAX_ANA_CHANS]; + Word32 *data_f_fx[DIRAC_MAX_ANA_CHANS]; + for ( i = 0; i < nchan_fb_in; i++ ) + { + data_f_fx[i] = data_f_buf[i]; + pp_fr_real_fx[i] = fr_real_fx[i]; + pp_fr_imag_fx[i] = fr_imag_fx[i]; + for ( j = 0; j < input_frame; j++ ) + { + data_f_fx[i][j] = float_to_fix( data_f[i][j], pcm_q ); + pp_fr_real_fx[i][j] = float_to_fix( ppIn_FR_real[i][j], pp_fr_q ); + pp_fr_imag_fx[i][j] = float_to_fix( ppIn_FR_imag[i][j], pp_fr_q ); + } + } + + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + for ( int k = 0; k < hDirAC->hConfig->nbands; k++ ) + { + Word16 tmp; + f2me( hDirAC->buffer_intensity_real[i][j][k], &hDirAC->buffer_intensity_real_fx[i][j][k], &tmp ); + hDirAC->buffer_intensity_real_q[i][j][k] = 31 - tmp; + } + } + } + for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + Word16 tmp; + f2me( hDirAC->buffer_energy[i + j * hDirAC->hConfig->nbands], &hDirAC->buffer_energy_fx[i + j * hDirAC->hConfig->nbands], &tmp ); + hDirAC->buffer_energy_q[i + j * hDirAC->hConfig->nbands] = 31 - tmp; + } + } + + for ( i = 0; i < NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS; i++ ) + { + hDirAC->azi_prev_fx[i] = float_to_fix( hDirAC->azi_prev[i], Q23 ); + hDirAC->ele_prev_fx[i] = float_to_fix( hDirAC->ele_prev[i], Q23 ); + } + for ( i = 0; i < NUM_ANA_SECTORS; i++ ) + { + for ( j = 0; j < IVAS_MAX_NUM_BANDS; j++ ) + { + f2me( hDirAC->sec_I_vec_smth_x[i][j], &hDirAC->sec_I_vec_smth_x_fx[i][j], &hDirAC->sec_I_vec_smth_x_exp[i][j] ); + f2me( hDirAC->sec_I_vec_smth_y[i][j], &hDirAC->sec_I_vec_smth_y_fx[i][j], &hDirAC->sec_I_vec_smth_y_exp[i][j] ); + f2me( hDirAC->sec_I_vec_smth_z[i][j], &hDirAC->sec_I_vec_smth_z_fx[i][j], &hDirAC->sec_I_vec_smth_z_exp[i][j] ); + } + } +#endif + ivas_dirac_param_est_enc( hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f_fx, pp_fr_real_fx, pp_fr_imag_fx, pp_fr_q, input_frame, ivas_format, hodirac_flag, nchan_fb_in, &( hDirAC->mono_frame_count ), &( hQMetaData->dirac_mono_flag ) ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + /*---------------------------------------------- fixed to float ----------------------------------------------*/ + for ( block_m_idx = 0; block_m_idx < nblocks; block_m_idx++ ) + { + for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + { + if ( hodirac_flag ) + { + hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx], Q30 ); + } + else + { + hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); + hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); + hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); + } + } + } + const int N_bands = hDirAC->hConfig->nbands; + for ( int i_sec = 0; i_sec < NUM_ANA_SECTORS; i_sec++ ) + { + for ( int i_band = 0; i_band < IVAS_MAX_NUM_BANDS; i_band++ ) + { + hDirAC->sec_I_vec_smth_x[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_x_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_x_exp[i_sec][i_band] ); + hDirAC->sec_I_vec_smth_y[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_y_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_y_exp[i_sec][i_band] ); + hDirAC->sec_I_vec_smth_z[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_z_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_z_exp[i_sec][i_band] ); + hDirAC->azi_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->azi_prev_fx[i_sec * N_bands + i_band], Q23 ); + hDirAC->ele_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->ele_prev_fx[i_sec * N_bands + i_band], Q23 ); + } + for ( int i_band = hDirAC->hConfig->enc_param_start_band; i_band < N_bands; i_band++ ) + { + hDirAC->energy_smth[i_sec][i_band] = me2f( hDirAC->energy_smth_fx[i_sec][i_band], hDirAC->energy_smth_exp[i_sec][i_band] ); + } + } + for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + { + hDirAC->diffuseness_m[band_m_idx] = me2f( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx] ); + me2f_buf( hQMetaData->q_direction->band_data[band_m_idx].energy_ratio_fx, 1, hQMetaData->q_direction->band_data[band_m_idx].energy_ratio, hQMetaData->q_direction->cfg.nblocks ); + } + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + for ( int k = 0; k < N_bands; k++ ) + { + hDirAC->buffer_intensity_real[i][j][k] = me2f( hDirAC->buffer_intensity_real_fx[i][j][k], 31 - hDirAC->buffer_intensity_real_q[i][j][k] ); + } + } + } + for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + hDirAC->buffer_energy[i + j * hDirAC->hConfig->nbands] = me2f( hDirAC->buffer_energy_fx[i + j * hDirAC->hConfig->nbands], 31 - hDirAC->buffer_energy_q[i + j * hDirAC->hConfig->nbands] ); + } + } +#endif + + + IF( hQMetaData->q_direction->cfg.nbands > 0 ) { orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands; - if ( dtx_vad == 1 ) + IF( EQ_16( dtx_vad, 1 ) ) { /* WB 4TC mode bit : disable for now*/ push_next_indice( hMetaData, 0, 1 ); /* Set Energy Ratio to 0.0 if the mono flag is set, before the metadata is encoded */ - if ( hQMetaData->dirac_mono_flag ) + IF( hQMetaData->dirac_mono_flag ) { +#ifdef IVAS_FLOAT_FIXED + IF( EQ_16( dtx_vad, 1 ) ) + { + FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + { + FOR( i_ts = 0; i_ts < hQMetaData->q_direction[0].cfg.nblocks; i_ts++ ) + { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; +#endif + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[i_ts] = 0; + hQMetaData->q_direction[0].band_data[b].azimuth_fx[i_ts] = 0; + hQMetaData->q_direction[0].band_data[b].elevation_fx[i_ts] = 0; + } + } + } + ELSE + { + FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + { + FOR( i_ts = 0; i_ts < 1; i_ts++ ) + { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; +#endif + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[i_ts] = 0; + hQMetaData->q_direction[0].band_data[b].azimuth_fx[i_ts] = 0; + hQMetaData->q_direction[0].band_data[b].elevation_fx[i_ts] = 0; + } + } + } + +#else for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) { for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) @@ -483,6 +732,7 @@ ivas_error ivas_dirac_enc( hQMetaData->q_direction[0].band_data[b].elevation[i_ts] = 0.0f; } } +#endif } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -491,14 +741,14 @@ ivas_error ivas_dirac_enc( for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].azimuth, hQMetaData->q_direction[i].band_data[j].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].elevation, hQMetaData->q_direction[i].band_data[j].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); +#ifndef MSAN_FIX floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth, hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation, hQMetaData->q_direction[i].band_data[j].q_elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); +#endif } } #endif - if ( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, hodirac_flag ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, hodirac_flag ) ) != IVAS_ERR_OK ) { return error; } @@ -508,17 +758,14 @@ ivas_error ivas_dirac_enc( for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, hQMetaData->q_direction[i].band_data[j].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - /*fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].azimuth_fx, hQMetaData->q_direction[i].band_data[j].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].elevation_fx, hQMetaData->q_direction[i].band_data[j].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES );*/ - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, hQMetaData->q_direction[i].band_data[j].q_azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation_fx, hQMetaData->q_direction[i].band_data[j].q_elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); } } #endif } - else + ELSE { hQMetaData->q_direction[0].cfg.nbands = DIRAC_DTX_BANDS; + move16(); /* compute directions */ for ( i = 0; i < hQMetaData->q_direction[0].cfg.nblocks; i++ ) @@ -531,11 +778,6 @@ ivas_error ivas_dirac_enc( for ( j = 0; j < orig_dirac_bands - 1; j++ ) { #ifdef IVAS_FLOAT_FIXED - /*==========================================flt-2-fix======================================================*/ - hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = floatToFixed( hQMetaData->q_direction[0].band_data[j].azimuth[i], Q22 ); - hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = floatToFixed( hQMetaData->q_direction[0].band_data[j].elevation[i], Q22 ); - /*==========================================flt-2-fix======================================================*/ - ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( hQMetaData->q_direction[0].band_data[j].azimuth_fx[i], hQMetaData->q_direction[0].band_data[j].elevation_fx[i], &dir_fx[0] ); /*==========================================fix-2-flt======================================================*/ @@ -554,7 +796,7 @@ ivas_error ivas_dirac_enc( energySum += hDirAC->buffer_energy[i * orig_dirac_bands + j]; } -#ifdef IVAS_FLOAT_FIXED_ +#ifdef IVAS_FLOAT_FIXED /*==========================================flt-2-fix======================================================*/ Word16 q_dir_e = 0; f2me_buf( avg_dir, avg_dir_fx, &q_dir_e, 3 ); @@ -562,18 +804,18 @@ ivas_error ivas_dirac_enc( /*==========================================flt-2-fix======================================================*/ ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( &avg_dir_fx[0], Q30, &hQMetaData->q_direction[0].band_data[0].azimuth_fx[i], &hQMetaData->q_direction[0].band_data[0].elevation_fx[i] ); - - /*==========================================fix-2-flt======================================================*/ - hQMetaData->q_direction[0].band_data[0].azimuth[i] = fixedToFloat( hQMetaData->q_direction[0].band_data[0].azimuth_fx[i], Q22 ); - hQMetaData->q_direction[0].band_data[0].elevation[i] = fixedToFloat( hQMetaData->q_direction[0].band_data[0].elevation_fx[i], Q22 ); - /*==========================================fix-2-flt======================================================*/ #else ivas_qmetadata_direction_vector_to_azimuth_elevation( &avg_dir[0], &hQMetaData->q_direction[0].band_data[0].azimuth[i], &hQMetaData->q_direction[0].band_data[0].elevation[i] ); #endif hQMetaData->q_direction[0].band_data[0].energy_ratio[i] = sqrtf( dotp( avg_dir, avg_dir, 3 ) ) / ( energySum + EPSILON ); +#ifdef IVAS_FLOAT_FIXED + hQMetaData->q_direction[0].band_data[1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i]; + hQMetaData->q_direction[0].band_data[1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i]; +#else hQMetaData->q_direction[0].band_data[1].azimuth[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i]; hQMetaData->q_direction[0].band_data[1].elevation[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i]; +#endif hQMetaData->q_direction[0].band_data[1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i]; } @@ -582,64 +824,61 @@ ivas_error ivas_dirac_enc( /* encode SID parameters */ #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IVAS_QDIRECTION *q_direction; - q_direction = &( hQMetaData->q_direction[0] ); - - FOR( b = 0; b < q_direction->cfg.nbands; b++ ) - { - FOR( int m = 0; m < q_direction->cfg.nblocks; m++ ) - { - q_direction->band_data[b].azimuth_fx[m] = floatToFixed( q_direction->band_data[b].azimuth[m], Q22 ); - q_direction->band_data[b].elevation_fx[m] = floatToFixed( q_direction->band_data[b].elevation[m], Q22 ); - } - } -#endif ivas_qmetadata_enc_sid_encode_fx( hMetaData, hQMetaData, -1, SBA_FORMAT ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( b = 0; b < q_direction->cfg.nbands; b++ ) - { - q_direction->band_data[b].q_azimuth[0] = fixedToFloat( q_direction->band_data[b].q_azimuth_fx[0], Q22 ); - q_direction->band_data[b].q_elevation[0] = fixedToFloat( q_direction->band_data[b].q_elevation_fx[0], Q22 ); - } -#endif #else ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, -1, SBA_FORMAT ); #endif } - for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) { - for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) + FOR( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) { +#ifdef IVAS_FLOAT_FIXED + hQMetaData->q_direction->band_data[b].azimuth_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_azimuth_fx[i_ts]; + hQMetaData->q_direction->band_data[b].elevation_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_elevation_fx[i_ts]; +#else hQMetaData->q_direction->band_data[b].azimuth[i_ts] = hQMetaData->q_direction->band_data[b].q_azimuth[i_ts]; hQMetaData->q_direction->band_data[b].elevation[i_ts] = hQMetaData->q_direction->band_data[b].q_elevation[i_ts]; +#endif hQMetaData->q_direction[0].band_data[b].energy_ratio[0] = 1.0f - diffuseness_reconstructions[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]]; } } - if ( dtx_vad == 0 ) + IF( dtx_vad == 0 ) { - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { +#ifdef IVAS_FLOAT_FIXED + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0]; + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[1].elevation_fx[0]; +#else hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0]; hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i] = hQMetaData->q_direction[0].band_data[1].elevation[0]; +#endif hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio[0]; } - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - for ( j = orig_dirac_bands - 2; j >= 0; j-- ) + FOR( j = orig_dirac_bands - 2; j >= 0; j-- ) { +#ifdef IVAS_FLOAT_FIXED + hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0]; + hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = hQMetaData->q_direction[0].band_data[0].elevation_fx[0]; +#else hQMetaData->q_direction[0].band_data[j].azimuth[i] = hQMetaData->q_direction[0].band_data[0].azimuth[0]; hQMetaData->q_direction[0].band_data[j].elevation[i] = hQMetaData->q_direction[0].band_data[0].elevation[0]; +#endif hQMetaData->q_direction[0].band_data[j].energy_ratio[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio[0]; } } hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; + move16(); } } + pop_wmops(); return IVAS_ERR_OK; @@ -779,74 +1018,261 @@ ivas_error ivas_dirac_enc( * *-------------------------------------------------------------------------*/ -static int16_t ivas_dirac_get_mono_flag( - const int16_t *band_grouping, /* i : Band grouping for estimation */ - float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ - float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal */ - const int16_t nchan_ana, /* i : number of analysis channels */ - int16_t *mono_frame_count ) /* i/o: current number of mono frames count */ +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_dirac_get_mono_flag_fx( + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ + Word32 Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal */ + Word16 e_Cldfb, /* i : Exponent of cldfb buffer */ + const Word16 nchan_ana, /* i : number of analysis channels */ + Word16 *mono_frame_count ) /* i/o: current number of mono frames count */ { - int16_t brange[2]; - int16_t i, j, ch_idx; - float other_ch_band_power; - float W_band_power; - int16_t any_mc_band = 0; - int16_t any_mono_band = 0; - int16_t local_mono_flag = 0; - float W_band_power_norm; - float threshold = 0; + Word16 brange[2]; + Word16 i, j, ch_idx; + Word32 other_ch_band_power; + Word32 W_band_power; + Word16 any_mc_band = 0; + Word16 any_mono_band = 0; + Word16 local_mono_flag = 0; + Word32 W_band_power_norm; + Word32 threshold = 0; + Word16 W_band_power_e = 0; + Word16 other_ch_band_power_e = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + move32(); /* Banded Power Calculations */ - for ( i = 0; i < DIRAC_MAX_NBANDS; i++ ) + FOR( i = 0; i < DIRAC_MAX_NBANDS; i++ ) { W_band_power = 0; other_ch_band_power = 0; + move32(); + move32(); brange[0] = band_grouping[i]; brange[1] = band_grouping[i + 1]; + move16(); + move16(); + + Word64 acc = 0, acc1 = 0; + move64(); + move64(); + + Word16 shift1 = 0; + Word16 shift2 = 0; + move16(); + move16(); /* Loop over the W channel bins to calculate the power in the band */ - for ( j = brange[0]; j < brange[1]; j++ ) + FOR( j = brange[0]; j < brange[1]; j++ ) { - W_band_power += ( Cldfb_RealBuffer[0][j] * Cldfb_RealBuffer[0][j] ) + ( Cldfb_ImagBuffer[0][j] * Cldfb_ImagBuffer[0][j] ); + acc = W_mac_32_32( acc, Cldfb_RealBuffer[0][j], Cldfb_RealBuffer[0][j] ); + acc = W_mac_32_32( acc, Cldfb_ImagBuffer[0][j], Cldfb_ImagBuffer[0][j] ); + shift1 = W_norm( acc ); + W_band_power = W_extract_h( W_shl( acc, shift1 ) ); + W_band_power_e = sub( imult1616( (Word16) 2, e_Cldfb ), shift1 ); } /* Loop over the other channels and bins to calculate the power in the band */ - for ( ch_idx = 1; ch_idx < nchan_ana; ch_idx++ ) + FOR( ch_idx = 1; ch_idx < nchan_ana; ch_idx++ ) { /* abs()^2 */ - for ( j = brange[0]; j < brange[1]; j++ ) + FOR( j = brange[0]; j < brange[1]; j++ ) { - other_ch_band_power += ( Cldfb_RealBuffer[ch_idx][j] * Cldfb_RealBuffer[ch_idx][j] ) + ( Cldfb_ImagBuffer[ch_idx][j] * Cldfb_ImagBuffer[ch_idx][j] ); + acc1 = W_mac_32_32( acc1, Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ); + acc1 = W_mac_32_32( acc1, Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ); + shift2 = W_norm( acc1 ); + other_ch_band_power = W_extract_h( W_shl( acc1, shift2 ) ); + other_ch_band_power_e = sub( imult1616( (Word16) 2, e_Cldfb ), shift2 ); } } - if ( other_ch_band_power < EPSILON ) + IF( BASOP_Util_Cmp_Mant32Exp( other_ch_band_power, other_ch_band_power_e, EPSILON_FX_M, EPSILON_FX_E ) < 0 ) { - if ( W_band_power > DIRAC_MONO_THRESH_SILENCE ) + if ( BASOP_Util_Cmp_Mant32Exp( W_band_power, W_band_power_e, DIRAC_MONO_THRESH_SILENCE_FX, 31 ) > 0 ) { any_mono_band = 1; + move16(); } } - else + ELSE { - if ( ( W_band_power > DIRAC_MONO_THRESH_SILENCE ) || ( other_ch_band_power > DIRAC_MONO_THRESH_SILENCE ) ) + test(); + IF( ( BASOP_Util_Cmp_Mant32Exp( W_band_power, W_band_power_e, DIRAC_MONO_THRESH_SILENCE_FX, 31 ) > 0 ) || ( BASOP_Util_Cmp_Mant32Exp( other_ch_band_power, other_ch_band_power_e, DIRAC_MONO_THRESH_SILENCE_FX, 31 ) > 0 ) ) { - W_band_power_norm = min( W_band_power, DIRAC_MONO_NORM_FACTOR ) * DIRAC_MONO_ONE_ON_NORM_FACTOR; - threshold = max( W_band_power_norm * DIRAC_MONO_MAX_THRESH, DIRAC_MONO_MIN_THRESH ); - if ( W_band_power / other_ch_band_power > threshold ) + Word16 tmp_div_e = 0; + move16(); + Word16 tmp_div = BASOP_Util_Divide3232_Scale( W_band_power, DIRAC_MONO_NORM_FACTOR_M, &tmp_div_e ); + tmp_div_e = add( tmp_div_e, sub( W_band_power_e, DIRAC_MONO_NORM_FACTOR_E ) ); + Word16 W_band_power_norm_e = 0; + move16(); + Word16 flag = BASOP_Util_Cmp_Mant32Exp( tmp_div, tmp_div_e, ONE_IN_Q14, 1 ); + IF( EQ_16( flag, 1 ) ) + { + W_band_power_norm = 1; + move16(); + W_band_power_norm_e = 31; + move16(); + } + ELSE + { + W_band_power_norm = L_deposit_h( tmp_div ); + W_band_power_norm_e = tmp_div_e; + move16(); + } + Word32 tmp_2 = Mpy_32_32( W_band_power_norm, DIRAC_MONO_MAX_THRESH_FX ); // W_band_power_norm_e+31 + Word32 tmp_3 = W_extract_h( W_shl( DIRAC_MONO_MIN_THRESH_FX, sub( 31, add( W_band_power_norm_e, 31 ) ) ) ); + tmp_3 = DIRAC_MONO_MIN_THRESH_FX; // exp31 + move32(); + Word16 flag2 = BASOP_Util_Cmp_Mant32Exp( tmp_2, add( W_band_power_norm_e, 31 ), tmp_3, 31 ); + + Word16 threshold_e = 0; + move16(); + IF( EQ_16( flag2, 1 ) ) + { + threshold = tmp_2; + move32(); + threshold_e = add( W_band_power_norm_e, 31 ); + } + ELSE + { + threshold = DIRAC_MONO_MIN_THRESH_FX; + threshold_e = 31; + move32(); + move16(); + } + + IF( BASOP_Util_Cmp_Mant32Exp( divide3232( W_band_power, other_ch_band_power ), 31, threshold, threshold_e ) == 0 ) { any_mono_band = 1; + move16(); } - else + ELSE { any_mc_band = 1; + move16(); } } } } /* If any band contains multi-channel content it's not mono */ - if ( any_mc_band ) + IF( any_mc_band ) + { + local_mono_flag = 0; + move16(); + } + ELSE + { + /* If any band contains mono content the frame is mono. */ + if ( any_mono_band ) + { + local_mono_flag = 1; + move16(); + } + } + + /* Hysteresis - only after DIRAC_MONO_FRAME_THRESH frames on mono will the actual mono flag be set */ + IF( local_mono_flag ) + { + IF( LT_16( *mono_frame_count, DIRAC_MONO_FRAME_THRESH ) ) + { + *mono_frame_count = add( *mono_frame_count, 1 ); + move16(); + } + } + ELSE + { + /* Instantaneously disable actual mono flag if multi-channel content is observed */ + if ( any_mc_band ) + { + *mono_frame_count = 0; + move16(); + } + } + + /* Final check if there has been mono for DIRAC_MONO_FRAME_THRESH number of frames than the content is declared mono */ + IF( EQ_16( *mono_frame_count, DIRAC_MONO_FRAME_THRESH ) ) + { + return 1; + } + ELSE + { + return 0; + } +} + +static int16_t ivas_dirac_get_mono_flag( + const int16_t *band_grouping, /* i : Band grouping for estimation */ + float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ + float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal */ + const int16_t nchan_ana, /* i : number of analysis channels */ + int16_t *mono_frame_count ) /* i/o: current number of mono frames count */ +{ + int16_t brange[2]; + int16_t i, j, ch_idx; + float other_ch_band_power; + float W_band_power; + int16_t any_mc_band = 0; + int16_t any_mono_band = 0; + int16_t local_mono_flag = 0; + float W_band_power_norm; + float threshold = 0; + + /* Banded Power Calculations */ + for ( i = 0; i < DIRAC_MAX_NBANDS; i++ ) + { + W_band_power = 0; + other_ch_band_power = 0; + + brange[0] = band_grouping[i]; + brange[1] = band_grouping[i + 1]; + + /* Loop over the W channel bins to calculate the power in the band */ + for ( j = brange[0]; j < brange[1]; j++ ) + { + W_band_power += ( Cldfb_RealBuffer[0][j] * Cldfb_RealBuffer[0][j] ) + ( Cldfb_ImagBuffer[0][j] * Cldfb_ImagBuffer[0][j] ); + } + + /* Loop over the other channels and bins to calculate the power in the band */ + for ( ch_idx = 1; ch_idx < nchan_ana; ch_idx++ ) + { + /* abs()^2 */ + for ( j = brange[0]; j < brange[1]; j++ ) + { + other_ch_band_power += ( Cldfb_RealBuffer[ch_idx][j] * Cldfb_RealBuffer[ch_idx][j] ) + ( Cldfb_ImagBuffer[ch_idx][j] * Cldfb_ImagBuffer[ch_idx][j] ); + } + } + if ( other_ch_band_power < EPSILON ) + { + if ( W_band_power > DIRAC_MONO_THRESH_SILENCE ) + { + any_mono_band = 1; + } + } + else + { + if ( ( W_band_power > DIRAC_MONO_THRESH_SILENCE ) || ( other_ch_band_power > DIRAC_MONO_THRESH_SILENCE ) ) + { + W_band_power_norm = min( W_band_power, DIRAC_MONO_NORM_FACTOR ) * DIRAC_MONO_ONE_ON_NORM_FACTOR; + threshold = max( W_band_power_norm * DIRAC_MONO_MAX_THRESH, DIRAC_MONO_MIN_THRESH ); + if ( W_band_power / other_ch_band_power > threshold ) + { + any_mono_band = 1; + } + else + { + any_mc_band = 1; + } + } + } + } + + /* If any band contains multi-channel content it's not mono */ + if ( any_mc_band ) { local_mono_flag = 0; } @@ -886,7 +1312,7 @@ static int16_t ivas_dirac_get_mono_flag( return 0; } } - +#endif /*------------------------------------------------------------------------- * computeReferencePower_enc() @@ -959,6 +1385,114 @@ void computeReferencePower_enc( * * *-------------------------------------------------------------------------*/ + +void computeReferencePower_enc_fx_dirac( + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ + Word32 Cldfb_ImagBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal */ + Word16 e_Cldfb, /* i : exponent of Cldfb buffer */ + Word32 *reference_power, /* o : Estimated power */ + Word16 *e_reference, /* o : exponent of reference_power */ + const Word16 enc_param_start_band, /* i : first band to process */ + const Word16 num_freq_bands, /* i : Number of frequency bands */ + const IVAS_FORMAT ivas_format, /* i : ivas_format */ + Word16 ref_power_w, /* i : use 0 if hodirac is enabled */ + const Word16 nchan_ana, /* i : number of analysis channels */ + Word16 *mono_frame_count, /* i/o: Mono Frame Count */ + Word16 *dirac_mono_flag /* i/o: Mono Flag */ +) +{ + Word16 brange[2]; + Word16 ch_idx, i, j; + Word64 reference_power_temp[DIRAC_MAX_NBANDS]; + Word64 reference_power_W[DIRAC_MAX_NBANDS]; + Word16 e_reference_W = 0, e_reference_temp = 0; + Word16 min_norm; + move16(); + move16(); + + IF( dirac_mono_flag != NULL ) + { + *dirac_mono_flag = ivas_dirac_get_mono_flag_fx( band_grouping, Cldfb_RealBuffer, Cldfb_ImagBuffer, e_Cldfb, nchan_ana, mono_frame_count ); + move16(); + } + + FOR( i = 0; i < num_freq_bands; i++ ) + { + brange[0] = band_grouping[i + enc_param_start_band]; + brange[1] = band_grouping[i + enc_param_start_band + 1]; + move16(); + move16(); + + reference_power_temp[i] = 0; + move64(); + + reference_power_W[i] = 0; + move64(); + + FOR( j = brange[0]; j < brange[1]; j++ ) + { + reference_power_W[i] = W_mac_32_32( reference_power_W[i], Cldfb_RealBuffer[0][j], Cldfb_RealBuffer[0][j] ); + reference_power_W[i] = W_mac_32_32( reference_power_W[i], Cldfb_ImagBuffer[0][j], Cldfb_ImagBuffer[0][j] ); + move64(); + move64(); + + e_reference_W = imult1616( (Word16) 2, e_Cldfb ); + } + reference_power_temp[i] = W_add( reference_power_temp[i], reference_power_W[i] ); + move64(); + + FOR( ch_idx = 1; ch_idx < nchan_ana; ch_idx++ ) + { + /* abs()^2 */ + FOR( j = brange[0]; j < brange[1]; j++ ) + { + reference_power_temp[i] = W_mac_32_32( reference_power_temp[i], Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ); + reference_power_temp[i] = W_mac_32_32( reference_power_temp[i], Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ); + move64(); + move64(); + + e_reference_temp = imult1616( (Word16) 2, e_Cldfb ); + } + } + } + + FOR( i = 0; i < num_freq_bands; i++ ) + { + reference_power_temp[i] = W_shr( reference_power_temp[i], 1 ); + move64(); + } + + test(); + IF( EQ_16( ivas_format, SBA_FORMAT ) && EQ_16( ref_power_w, 1 ) ) + { + FOR( i = 0; i < num_freq_bands; i++ ) + { + IF( BASOP_Util_Cmp_Mant32Exp( W_extract_h( reference_power_temp[i] ), e_reference_temp, W_extract_h( reference_power_W[i] ), e_reference_W ) < 0 ) + { + reference_power_temp[i] = reference_power_W[i]; + move64(); + } + } + } + + min_norm = W_norm( reference_power_temp[0] ); + FOR( i = 0; i < num_freq_bands; i++ ) + { + min_norm = s_min( min_norm, W_norm( reference_power_temp[i] ) ); // Finding minimum norm for the right shifting of entire buffer + } + + FOR( i = 0; i < num_freq_bands; i++ ) + { + reference_power[i] = W_extract_h( W_shl( reference_power_temp[i], min_norm ) ); // Right shift with min_norm and extract high bits + move32(); + } + *e_reference = sub( e_reference_temp, min_norm ); + move16(); + + return; +} + void computeReferencePower_enc_fx( const Word16 *band_grouping, /* i : Band grouping for estimation */ Word32 Cldfb_RealBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ @@ -968,12 +1502,18 @@ void computeReferencePower_enc_fx( const Word16 num_freq_bands, /* i : Number of frequency bands */ const IVAS_FORMAT ivas_format, /* i : ivas_format */ Word16 ref_power_w, /* i : use 0 if hodirac is enabled */ - const Word16 nchan_ana /* i : number of analysis channels */ + const Word16 nchan_ana, /* i : number of analysis channels */ + Word16 inp_q, /* i : q of cld buffers */ + Word16 *ref_exp /* i : output q */ ) { Word16 brange[2]; Word16 ch_idx, i, j; - Word32 reference_power_W[DIRAC_MAX_NBANDS]; + Word16 ref_Q = 63; + move16(); + + Word64 reference_power_tmp[DIRAC_MAX_NBANDS]; + Word64 reference_power_W[DIRAC_MAX_NBANDS]; FOR( i = 0; i < num_freq_bands; i++ ) { brange[0] = band_grouping[i + enc_param_start_band]; @@ -983,35 +1523,60 @@ void computeReferencePower_enc_fx( reference_power[i] = 0; move32(); reference_power_W[i] = 0; - move32(); + move64(); + reference_power_tmp[i] = 0; + move64(); FOR( j = brange[0]; j < brange[1]; j++ ) { - reference_power_W[i] = L_add( reference_power_W[i], L_add( Mpy_32_32( Cldfb_RealBuffer[0][j], Cldfb_RealBuffer[0][j] ), Mpy_32_32( Cldfb_ImagBuffer[0][j], Cldfb_ImagBuffer[0][j] ) ) ); - move32(); + // 2*inp_q + 1 + reference_power_W[i] = W_add( reference_power_W[i], W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[0][j], Cldfb_RealBuffer[0][j] ), Cldfb_ImagBuffer[0][j], Cldfb_ImagBuffer[0][j] ) ); + move64(); } - reference_power[i] = L_add( reference_power[i], reference_power_W[i] ); // 2*inp_q -31 - move32(); + reference_power_tmp[i] = W_add( reference_power_tmp[i], reference_power_W[i] ); // 2*inp_q + 1 + move64(); FOR( ch_idx = 1; ch_idx < nchan_ana; ch_idx++ ) { /* abs()^2 */ FOR( j = brange[0]; j < brange[1]; j++ ) { - reference_power[i] = L_add( reference_power[i], L_add( Mpy_32_32( Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ), Mpy_32_32( Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ) ) ); - move32(); + reference_power_tmp[i] = W_add( reference_power_tmp[i], W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ), Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ) ); + move64(); } - // 2*inp_q - 31 + // 2*inp_q + 1 } } - v_multc_fixed( reference_power, ONE_IN_Q30, reference_power, num_freq_bands ); + FOR( i = 0; i < num_freq_bands; i++ ) + { + reference_power_tmp[i] = W_shr( reference_power_tmp[i], 1 ); // 2*inp_q + 1 + move64(); + } + test(); IF( EQ_16( ivas_format, SBA_FORMAT ) && EQ_16( ref_power_w, 1 ) ) { FOR( i = 0; i < num_freq_bands; i++ ) { - reference_power[i] = max( reference_power[i], reference_power_W[i] ); - move32(); + IF( LT_64( reference_power_tmp[i], reference_power_W[i] ) ) + { + reference_power_tmp[i] = reference_power_W[i]; + move64(); + } } } + FOR( i = 0; i < num_freq_bands; i++ ) + { + ref_Q = s_min( ref_Q, W_norm( reference_power_tmp[i] ) ); + } + FOR( i = 0; i < num_freq_bands; i++ ) + { + reference_power_tmp[i] = W_shl( reference_power_tmp[i], ref_Q ); // 2*inp_q + 1 + ref_Q + move64(); + reference_power[i] = W_extract_h( reference_power_tmp[i] ); // 2*inp_q + ref_Q - 31 + move32(); + } + + *ref_exp = sub( Q31, ( sub( add( shl( inp_q, Q1 ), ref_Q ), Q31 ) ) ); + move16(); return; } #endif @@ -1026,9 +1591,10 @@ void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, const UWord8 useLowerRes, - float *data_f[], - float **pp_fr_real, - float **pp_fr_imag, + Word32 *data_f_fx[], + Word32 **pp_fr_real_fx, + Word32 **pp_fr_imag_fx, + Word16 pp_fr_q, const Word16 input_frame, const IVAS_FORMAT ivas_format, const Word16 hodirac_flag, @@ -1036,108 +1602,52 @@ void ivas_dirac_param_est_enc( Word16 *mono_frame_count, Word16 *dirac_mono_flag ) { -#ifdef IVAS_FLOAT_FIXED - Word32 *data_f_fx[DIRAC_MAX_ANA_CHANS]; - Word32 **pp_fr_real_fx; - Word32 **pp_fr_imag_fx; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* Assign memory */ - Word16 nblocks = useLowerRes ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - hDirAC->direction_vector_m_fx[0] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); - hDirAC->direction_vector_m_fx[1] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); - hDirAC->direction_vector_m_fx[2] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); - for ( int block_m_idx = 0; block_m_idx < nblocks; block_m_idx++ ) - { - hDirAC->direction_vector_m_fx[0][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); - hDirAC->direction_vector_m_fx[1][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); - hDirAC->direction_vector_m_fx[2][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); - } - - /* Find Q-factor */ - Word16 pcm_q; - Word16 pp_fr_q; - float max_val = 0; - for ( int i = 0; i < nchan_fb_in; i++ ) - { - for ( int j = 0; j < input_frame; j++ ) - { - max_val = max( max_val, (float) fabs( data_f[i][j] ) ); - } - } - pcm_q = Q_factor_L( max_val ); - - max_val = 0; - for ( int i = 0; i < nchan_fb_in; i++ ) - { - for ( int j = 0; j < input_frame; j++ ) - { - max_val = max( max_val, (float) fabs( pp_fr_real[i][j] ) ); - max_val = max( max_val, (float) fabs( pp_fr_imag[i][j] ) ); - } - } - pp_fr_q = Q_factor_L( max_val ); - - /* Float to fixed */ - pp_fr_real_fx = (Word32 **) calloc( nchan_fb_in, sizeof( Word32 * ) ); - pp_fr_imag_fx = (Word32 **) calloc( nchan_fb_in, sizeof( Word32 * ) ); - for ( int i = 0; i < nchan_fb_in; i++ ) - { - data_f_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); - pp_fr_real_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); - pp_fr_imag_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); - for ( int j = 0; j < input_frame; j++ ) - { - data_f_fx[i][j] = float_to_fix( data_f[i][j], pcm_q ); - pp_fr_real_fx[i][j] = float_to_fix( pp_fr_real[i][j], pp_fr_q ); - pp_fr_imag_fx[i][j] = float_to_fix( pp_fr_imag[i][j], pp_fr_q ); - } - } -#endif - - Word16 i, d, ts, index, l_ts, num_freq_bands; + Word16 i, j, k, d, ts, index, l_ts, num_freq_bands; Word16 band_m_idx, block_m_idx; - float dir_v[DIRAC_NUM_DIMS]; -#ifdef IVAS_FLOAT_FIXED_ Word32 dir_v_fx[DIRAC_NUM_DIMS]; -#endif - float *pcm_in[DIRAC_MAX_ANA_CHANS]; - float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; - float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; - float *p_Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS]; - float *p_Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS]; Word32 *pcm_in_fx[DIRAC_MAX_ANA_CHANS]; Word32 Cldfb_RealBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; Word32 Cldfb_ImagBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; Word32 *p_Cldfb_RealBuffer_fx[DIRAC_MAX_ANA_CHANS]; Word32 *p_Cldfb_ImagBuffer_fx[DIRAC_MAX_ANA_CHANS]; Word16 cldfb_q; - float intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - float direction_vector[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - float diffuseness_vector[DIRAC_MAX_NBANDS]; - float renormalization_factor[DIRAC_MAX_NBANDS]; - float renormalization_factor_diff[DIRAC_MAX_NBANDS]; + Word32 intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; + Word16 intensity_real_q; + Word32 direction_vector_fx[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; + Word16 direction_vector_q; + Word32 diffuseness_vector_fx[DIRAC_MAX_NBANDS]; + Word16 diffuseness_vector_q; Word32 renormalization_factor_fx[DIRAC_MAX_NBANDS]; + Word16 renormalization_factor_exp; Word32 renormalization_factor_diff_fx[DIRAC_MAX_NBANDS]; - float norm_tmp; + Word16 renormalization_factor_diff_exp[DIRAC_MAX_NBANDS]; + Word32 norm_tmp_fx; + Word16 norm_tmp_exp; Word16 mrange[2]; Word16 num_blocks; - float reference_power[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; Word32 reference_power_fx[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; Word16 reference_power_exp; - float azi_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ele_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float diff_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ene_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 azi_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 ele_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 diff_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; + Word16 diff_secs_exp[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 ene_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; + Word16 ene_secs_exp[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; push_wmops( "dirac_enc_param_est" ); num_freq_bands = hDirAC->hConfig->nbands; move16(); /* Initialization */ + cldfb_q = 0; + move16(); + intensity_real_q = 0; + move16(); + direction_vector_q = 0; + move16(); + diffuseness_vector_q = 0; + move16(); + l_ts = idiv1616( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES ); IF( useLowerRes ) { @@ -1156,149 +1666,48 @@ void ivas_dirac_param_est_enc( /* Need to initialize renormalization_factors, direction_m and diffuseness_m */ set_zero_fx( hDirAC->diffuseness_m_fx, hDirAC->hConfig->nbands ); + set16_zero_fx( hDirAC->diffuseness_m_exp, hDirAC->hConfig->nbands ); set_zero_fx( renormalization_factor_diff_fx, hDirAC->hConfig->nbands ); + set16_zero_fx( renormalization_factor_diff_exp, hDirAC->hConfig->nbands ); + reference_power_exp = 0; + move16(); set_zero_fx( azi_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); set_zero_fx( ele_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); set_zero_fx( diff_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); + set16_zero_fx( diff_secs_exp, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); set_zero_fx( ene_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); + set16_zero_fx( ene_secs_exp, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); /* Copy current frame to memory for delay compensation */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* assign memory */ - for ( i = 0; i < nchan_fb_in; i++ ) - { - pcm_in[i] = data_f[i]; - p_Cldfb_RealBuffer[i] = &Cldfb_RealBuffer[i][0]; - p_Cldfb_ImagBuffer[i] = &Cldfb_ImagBuffer[i][0]; - } -#endif FOR( i = 0; i < nchan_fb_in; i++ ) { pcm_in_fx[i] = data_f_fx[i]; p_Cldfb_RealBuffer_fx[i] = &Cldfb_RealBuffer_fx[i][0]; p_Cldfb_ImagBuffer_fx[i] = &Cldfb_ImagBuffer_fx[i][0]; } -#if 1 - /* using void temporarily to avoid null */ - (void) p_Cldfb_RealBuffer_fx; - (void) p_Cldfb_ImagBuffer_fx; - (void) p_Cldfb_RealBuffer; - (void) p_Cldfb_ImagBuffer; - (void) pcm_in_fx; - (void) pcm_in; -#endif - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* Fixed to float */ - fixedToFloat_arrL( azi_secs_fx, azi_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - fixedToFloat_arrL( ele_secs_fx, ele_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - fixedToFloat_arrL( diff_secs_fx, diff_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - fixedToFloat_arrL( ene_secs_fx, ene_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - - fixedToFloat_arrL( hDirAC->diffuseness_m_fx, hDirAC->diffuseness_m, 0, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( renormalization_factor_diff_fx, renormalization_factor_diff, 0, hDirAC->hConfig->nbands ); -#endif - -#else - int16_t i, d, ts, index, l_ts, num_freq_bands; - int16_t band_m_idx, block_m_idx; - float dir_v[DIRAC_NUM_DIMS]; - float *pcm_in[DIRAC_MAX_ANA_CHANS]; - float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; - float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; - float *p_Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS]; - float *p_Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS]; - float intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - float direction_vector[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - float diffuseness_vector[DIRAC_MAX_NBANDS]; - float renormalization_factor[DIRAC_MAX_NBANDS]; - float renormalization_factor_diff[DIRAC_MAX_NBANDS]; - float norm_tmp; - int16_t mrange[2]; - int16_t num_blocks; - float reference_power[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; - float azi_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ele_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float diff_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ene_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - - push_wmops( "dirac_enc_param_est" ); - num_freq_bands = hDirAC->hConfig->nbands; - - /* Initialization */ - l_ts = input_frame / MAX_PARAM_SPATIAL_SUBFRAMES; - if ( useLowerRes ) - { - q_direction->cfg.nblocks = 1; - num_blocks = 1; - } - else - { - q_direction->cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES; - num_blocks = MAX_PARAM_SPATIAL_SUBFRAMES; - } - - /* Need to initialize renormalization_factors, direction_m and diffuseness_m */ - for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) - { - renormalization_factor_diff[i] = 0; - hDirAC->diffuseness_m[i] = 0; - } - - set_zero( azi_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - set_zero( ele_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - set_zero( diff_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - set_zero( ene_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - - /* Copy current frame to memory for delay compensation */ - for ( i = 0; i < nchan_fb_in; i++ ) - { - pcm_in[i] = data_f[i]; - p_Cldfb_RealBuffer[i] = &Cldfb_RealBuffer[i][0]; - p_Cldfb_ImagBuffer[i] = &Cldfb_ImagBuffer[i][0]; - } -#endif /* ifdef IVAS_FLOAT_FIXED */ /* do processing over all CLDFB time slots */ - for ( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) + FOR( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) { -#ifdef IVAS_FLOAT_FIXED mrange[0] = hDirAC->block_grouping[block_m_idx]; move16(); - mrange[1] = hDirAC->block_grouping[add( block_m_idx, 1 )]; - move16(); - - set32_fx( renormalization_factor_fx, EPSILON_FX, hDirAC->hConfig->nbands ); - set_zero_fx( hDirAC->direction_vector_m_fx[0][block_m_idx], hDirAC->hConfig->nbands ); - set_zero_fx( hDirAC->direction_vector_m_fx[1][block_m_idx], hDirAC->hConfig->nbands ); - set_zero_fx( hDirAC->direction_vector_m_fx[2][block_m_idx], hDirAC->hConfig->nbands ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - set_f( renormalization_factor, EPSILON, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( hDirAC->direction_vector_m_fx[0][block_m_idx], hDirAC->direction_vector_m[0][block_m_idx], 0, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( hDirAC->direction_vector_m_fx[1][block_m_idx], hDirAC->direction_vector_m[1][block_m_idx], 0, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( hDirAC->direction_vector_m_fx[2][block_m_idx], hDirAC->direction_vector_m[2][block_m_idx], 0, hDirAC->hConfig->nbands ); -#endif - -#else - mrange[0] = hDirAC->block_grouping[block_m_idx]; - mrange[1] = hDirAC->block_grouping[block_m_idx + 1]; + mrange[1] = hDirAC->block_grouping[add( block_m_idx, 1 )]; + move16(); - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) - { - renormalization_factor[band_m_idx] = EPSILON; - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = 0; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = 0; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = 0; - } -#endif + set32_fx( renormalization_factor_fx, EPSILON_FX, hDirAC->hConfig->nbands ); + renormalization_factor_exp = 0; + move16(); + set_zero_fx( hDirAC->direction_vector_m_fx[0][block_m_idx], hDirAC->hConfig->nbands ); + set_zero_fx( hDirAC->direction_vector_m_fx[1][block_m_idx], hDirAC->hConfig->nbands ); + set_zero_fx( hDirAC->direction_vector_m_fx[2][block_m_idx], hDirAC->hConfig->nbands ); + hDirAC->direction_vector_m_exp[block_m_idx] = 0; + move16(); - for ( ts = mrange[0]; ts < mrange[1]; ts++ ) + FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) { - if ( hDirAC->hFbMixer ) + IF( hDirAC->hFbMixer ) { -#ifdef IVAS_FLOAT_FIXED ivas_fb_mixer_get_windowed_fr_fx( hDirAC->hFbMixer, pcm_in_fx, p_Cldfb_RealBuffer_fx, p_Cldfb_ImagBuffer_fx, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans, 0 ); ivas_fb_mixer_update_prior_input_fx( hDirAC->hFbMixer, pcm_in_fx, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); @@ -1307,25 +1716,9 @@ void ivas_dirac_param_est_enc( { pcm_in_fx[i] += l_ts; } -#else - ivas_fb_mixer_get_windowed_fr( hDirAC->hFbMixer, pcm_in, p_Cldfb_RealBuffer, p_Cldfb_ImagBuffer, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); - - ivas_fb_mixer_update_prior_input( hDirAC->hFbMixer, pcm_in, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); - - for ( i = 0; i < nchan_fb_in; i++ ) - { - pcm_in[i] += l_ts; - } -#endif } - else + ELSE { -#ifdef IVAS_FLOAT_FIXED - for ( i = 0; i < nchan_fb_in; i++ ) - { - mvr2r( &pp_fr_real[i][ts * l_ts], Cldfb_RealBuffer[i], l_ts ); - mvr2r( &pp_fr_imag[i][ts * l_ts], Cldfb_ImagBuffer[i], l_ts ); - } FOR( i = 0; i < nchan_fb_in; i++ ) { Copy32( &pp_fr_real_fx[i][imult1616( ts, l_ts )], Cldfb_RealBuffer_fx[i], l_ts ); @@ -1333,276 +1726,318 @@ void ivas_dirac_param_est_enc( } cldfb_q = pp_fr_q; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < nchan_fb_in; i++ ) - { - fixedToFloat_arrL( Cldfb_ImagBuffer_fx[i], Cldfb_ImagBuffer[i], cldfb_q, l_ts ); - fixedToFloat_arrL( Cldfb_RealBuffer_fx[i], Cldfb_RealBuffer[i], cldfb_q, l_ts ); - } -#endif -#else - for ( i = 0; i < nchan_fb_in; i++ ) - { - mvr2r( &pp_fr_real[i][ts * l_ts], Cldfb_RealBuffer[i], l_ts ); - mvr2r( &pp_fr_imag[i][ts * l_ts], Cldfb_ImagBuffer[i], l_ts ); - } -#endif } - computeReferencePower_enc( + Word16 ref_power_w = 1; + move16(); + IF( hodirac_flag ) + { + ref_power_w = 0; + move16(); + } + + computeReferencePower_enc_fx_dirac( hDirAC->band_grouping, - Cldfb_RealBuffer, - Cldfb_ImagBuffer, - reference_power[ts], + Cldfb_RealBuffer_fx, + Cldfb_ImagBuffer_fx, + sub( 31, cldfb_q ), + reference_power_fx[ts], + &reference_power_exp, hDirAC->hConfig->enc_param_start_band, num_freq_bands, ivas_format, - hodirac_flag ? 0 : 1, + ref_power_w, FOA_CHANNELS, mono_frame_count, dirac_mono_flag ); - computeIntensityVector_enc( + computeIntensityVector_enc_fx( hDirAC, - Cldfb_RealBuffer, - Cldfb_ImagBuffer, + Cldfb_RealBuffer_fx, + Cldfb_ImagBuffer_fx, hDirAC->hConfig->enc_param_start_band, num_freq_bands, - intensity_real ); + intensity_real_fx ); - if ( !hodirac_flag ) + intensity_real_q = sub( shl( cldfb_q, 1 ), 31 ); // 2 * Q_Cldfb + 1 - 32; + + IF( !hodirac_flag ) { - computeDirectionVectors( - intensity_real[0], - intensity_real[1], - intensity_real[2], + computeDirectionVectors_fixed( + intensity_real_fx[0], + intensity_real_fx[1], + intensity_real_fx[2], hDirAC->hConfig->enc_param_start_band, num_freq_bands, - direction_vector[0], - direction_vector[1], - direction_vector[2] ); - } + direction_vector_fx[0], + direction_vector_fx[1], + direction_vector_fx[2], + sub( 31, intensity_real_q ) ); -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS -#define MAX_NUM_INDEX_INTENSITY ( 10 ) /* NOTE: arbitrary value. need to check exact max value of "index"*/ - Word32 buffer_intensity_real_fx[DIRAC_NUM_DIMS][MAX_NUM_INDEX_INTENSITY][DIRAC_MAX_NBANDS]; - Word32 buffer_energy_fx[MAX_NUM_INDEX_INTENSITY * DIRAC_MAX_NBANDS]; - Word32 intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - max_val = 0; - Word32 tmp32; - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - float tmpf; - maximumAbs( intensity_real[i], num_freq_bands, &tmpf ); - max_val = fmaxf( max_val, tmpf ); - } - Word16 intensity_real_exp; - f2me( max_val, &tmp32, &intensity_real_exp ); - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - for ( int j = 0; j < num_freq_bands; j++ ) - { - intensity_real_fx[i][j] = (Word32) ( intensity_real[i][j] * powf( 2, 31.f - intensity_real_exp ) ); - } + direction_vector_q = Q30; + move16(); } - f2me_buf( reference_power[ts], reference_power_fx[ts], &reference_power_exp, num_freq_bands ); -#endif + /* fill buffers of length "averaging_length" time slots for intensity and energy */ hDirAC->index_buffer_intensity = add( ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ), 1 ); /* averaging_length = 32 */ move16(); index = hDirAC->index_buffer_intensity; move16(); - assert( index <= MAX_NUM_INDEX_INTENSITY ); FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { /* only real part needed */ - Copy32( intensity_real_fx[i], &( buffer_intensity_real_fx[i][sub( index, 1 )][0] ), num_freq_bands ); + Copy32( intensity_real_fx[i], &( hDirAC->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); + set16_fx( &hDirAC->buffer_intensity_real_q[i][index - 1][0], intensity_real_q, num_freq_bands ); } - Copy32( reference_power_fx[ts], &( buffer_energy_fx[imult1616( sub( index, 1 ), num_freq_bands )] ), num_freq_bands ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Copy32( reference_power_fx[ts], &( hDirAC->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); + set16_fx( &hDirAC->buffer_energy_q[( index - 1 ) * num_freq_bands], sub( 31, reference_power_exp ), num_freq_bands ); + + Word16 buffer_intensity_real_single_q; + buffer_intensity_real_single_q = hDirAC->buffer_intensity_real_q[0][0][0]; + move16(); FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - me2f_buf( &buffer_intensity_real_fx[i][index - 1][0], intensity_real_exp, &hDirAC->buffer_intensity_real[i][index - 1][0], num_freq_bands ); + FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + FOR( k = 0; k < num_freq_bands; k++ ) + { + buffer_intensity_real_single_q = s_min( buffer_intensity_real_single_q, hDirAC->buffer_intensity_real_q[i][j][k] ); + } + } } - me2f_buf( &buffer_energy_fx[( index - 1 ) * num_freq_bands], reference_power_exp, &hDirAC->buffer_energy[( index - 1 ) * num_freq_bands], num_freq_bands ); -#endif -#else - /* fill buffers of length "averaging_length" time slots for intensity and energy */ - hDirAC->index_buffer_intensity = ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ) + 1; /* averaging_length = 32 */ - index = hDirAC->index_buffer_intensity; - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - /* only real part needed */ - mvr2r( intensity_real[i], &( hDirAC->buffer_intensity_real[i][index - 1][0] ), num_freq_bands ); + FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + FOR( k = 0; k < num_freq_bands; k++ ) + { + hDirAC->buffer_intensity_real_fx[i][j][k] = L_shl( hDirAC->buffer_intensity_real_fx[i][j][k], sub( buffer_intensity_real_single_q, hDirAC->buffer_intensity_real_q[i][j][k] ) ); + move32(); + hDirAC->buffer_intensity_real_q[i][j][k] = buffer_intensity_real_single_q; + move16(); + } + } } - mvr2r( reference_power[ts], &( hDirAC->buffer_energy[( index - 1 ) * num_freq_bands] ), num_freq_bands ); -#endif - computeDiffuseness_mdft( hDirAC->buffer_intensity_real, hDirAC->buffer_energy, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector ); + Word16 buffer_energy_single_q; + Word16 buffer_len; + buffer_len = imult1616( DIRAC_MAX_NBANDS, hDirAC->no_col_avg_diff ); + minimum_fx( hDirAC->buffer_energy_q, buffer_len, &buffer_energy_single_q ); + FOR( i = 0; i < buffer_len; i++ ) + { + hDirAC->buffer_energy_fx[i] = L_shl( hDirAC->buffer_energy_fx[i], sub( buffer_energy_single_q, hDirAC->buffer_energy_q[i] ) ); + move32(); + hDirAC->buffer_energy_q[i] = buffer_energy_single_q; + move16(); + } - if ( hodirac_flag ) + Word16 tmp_q_buffer_for_intensity[DIRAC_MAX_NBANDS * DIRAC_NO_COL_AVG_DIFF]; + Word16 tmp_q_buffer_for_energy[DIRAC_MAX_NBANDS * DIRAC_NO_COL_AVG_DIFF]; + + set16_fx( tmp_q_buffer_for_intensity, buffer_intensity_real_single_q, buffer_len ); + set16_fx( tmp_q_buffer_for_energy, buffer_energy_single_q, buffer_len ); + + computeDiffuseness_mdft_fx( hDirAC->buffer_intensity_real_fx, hDirAC->buffer_energy_fx, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector_fx, tmp_q_buffer_for_intensity, tmp_q_buffer_for_energy, &diffuseness_vector_q ); + + IF( hodirac_flag ) { - calculate_hodirac_sector_parameters( + calculate_hodirac_sector_parameters_fx( hDirAC, - Cldfb_RealBuffer, - Cldfb_ImagBuffer, - 0.20f, + Cldfb_RealBuffer_fx, + Cldfb_ImagBuffer_fx, + cldfb_q, + HODIRAC_BETA, hDirAC->band_grouping, hDirAC->hConfig->nbands, hDirAC->hConfig->enc_param_start_band, - azi_secs, - ele_secs, - diff_secs, - ene_secs ); + azi_secs_fx, + ele_secs_fx, + diff_secs_fx, + diff_secs_exp, + ene_secs_fx, + ene_secs_exp ); } - if ( hodirac_flag ) + const Word16 gbits = 4; // 4 guard bits + move16(); + IF( hodirac_flag ) { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - hDirAC->diffuseness_m[band_m_idx] += reference_power[ts][band_m_idx] * diffuseness_vector[band_m_idx]; - renormalization_factor_diff[band_m_idx] += reference_power[ts][band_m_idx]; + Word32 tmp_diff = L_shr( diffuseness_vector_fx[band_m_idx], sub( diffuseness_vector_q, 30 ) ); // diffueseness_vector_q -> Q30 + hDirAC->diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx], + Mpy_32_32( reference_power_fx[ts][band_m_idx], tmp_diff ), add( reference_power_exp, 1 ), &hDirAC->diffuseness_m_exp[band_m_idx] ); + move32(); + renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_exp[band_m_idx], reference_power_fx[ts][band_m_idx], reference_power_exp, &renormalization_factor_diff_exp[band_m_idx] ); + move32(); } } - else + ELSE { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - norm_tmp = reference_power[ts][band_m_idx] * ( 1 - diffuseness_vector[band_m_idx] ); - - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] += norm_tmp * direction_vector[0][band_m_idx]; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] += norm_tmp * direction_vector[1][band_m_idx]; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] += norm_tmp * direction_vector[2][band_m_idx]; - renormalization_factor[band_m_idx] += norm_tmp; - - hDirAC->diffuseness_m[band_m_idx] += reference_power[ts][band_m_idx] * diffuseness_vector[band_m_idx]; - renormalization_factor_diff[band_m_idx] += reference_power[ts][band_m_idx]; + Word32 tmp_diff = L_shr( diffuseness_vector_fx[band_m_idx], sub( diffuseness_vector_q, 30 ) ); // diffueseness_vector_q -> Q30 + norm_tmp_fx = Mpy_32_32( reference_power_fx[ts][band_m_idx], L_sub( ONE_IN_Q30, tmp_diff ) ); + + hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ), gbits ) ); + move32(); + hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ), gbits ) ); + move32(); + hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ), gbits ) ); + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], L_shr( norm_tmp_fx, gbits ) ); + move32(); + hDirAC->diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx], + Mpy_32_32( reference_power_fx[ts][band_m_idx], tmp_diff ), add( reference_power_exp, 1 ), &hDirAC->diffuseness_m_exp[band_m_idx] ); + move32(); + renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_exp[band_m_idx], + reference_power_fx[ts][band_m_idx], reference_power_exp, &renormalization_factor_diff_exp[band_m_idx] ); + move32(); } + norm_tmp_exp = add( reference_power_exp, 1 ); + hDirAC->direction_vector_m_exp[block_m_idx] = add( norm_tmp_exp, add( sub( 31, direction_vector_q ), gbits ) ); + move32(); + renormalization_factor_exp = add( norm_tmp_exp, gbits ); } } - if ( !hodirac_flag ) + IF( !hodirac_flag ) { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - renormalization_factor[band_m_idx] = EPSILON; - for ( d = 0; d < DIRAC_NUM_DIMS; d++ ) - { - renormalization_factor[band_m_idx] += ( hDirAC->direction_vector_m[d][block_m_idx][band_m_idx] * hDirAC->direction_vector_m[d][block_m_idx][band_m_idx] ); - } - renormalization_factor[band_m_idx] = sqrtf( renormalization_factor[band_m_idx] ); + renormalization_factor_fx[band_m_idx] = EPSILON_FX; + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] ) ); + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] ) ); + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] ) ); + move32(); + renormalization_factor_exp = shl( hDirAC->direction_vector_m_exp[block_m_idx], 1 ); // 2 * direction_vector_m_exp + renormalization_factor_fx[band_m_idx] = Sqrt32( renormalization_factor_fx[band_m_idx], &renormalization_factor_exp ); + move32(); - if ( renormalization_factor[band_m_idx] > EPSILON ) + IF( GT_32( renormalization_factor_fx[band_m_idx], EPSILON_FX ) ) { - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; + Word16 tmp_e; + Word32 tmp32; + + tmp32 = hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx]; + move32(); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); + hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 + move32(); + + tmp32 = hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx]; + move32(); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); + hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 + move32(); + + tmp32 = hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx]; + move32(); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); + hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 + move32(); } - else + ELSE { - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = 1; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = 0; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = 0; + hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = ONE_IN_Q30; + move32(); + hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = 0; + move32(); + hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = 0; + move32(); } + hDirAC->direction_vector_m_exp[block_m_idx] = 1; + move16(); /* save the elevation and azimuth values to be used later by the ivas_dirac_QuantizeParameters function */ - for ( d = 0; d < DIRAC_NUM_DIMS; d++ ) + FOR( d = 0; d < DIRAC_NUM_DIMS; d++ ) { - dir_v[d] = hDirAC->direction_vector_m[d][block_m_idx][band_m_idx]; + dir_v_fx[d] = hDirAC->direction_vector_m_fx[d][block_m_idx][band_m_idx]; // Q30 + move32(); } -#ifdef IVAS_FLOAT_FIXED_ - /*==========================================flt-2-fix======================================================*/ - Word16 q_dir_e = 0; - f2me_buf( dir_v, dir_v_fx, &q_dir_e, 3 ); Scale_sig32( dir_v_fx, 3, -1 ); - /*==========================================flt-2-fix======================================================*/ - ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( dir_v_fx, - Q31 - q_dir_e, + Q30, &q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], &q_direction->band_data[band_m_idx].elevation_fx[block_m_idx] ); - - /*==========================================fix-2-flt======================================================*/ - q_direction->band_data[band_m_idx].azimuth[block_m_idx] = fixedToFloat( q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); - q_direction->band_data[band_m_idx].elevation[block_m_idx] = fixedToFloat( q_direction->band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); - /*==========================================fix-2-flt======================================================*/ -#else - ivas_qmetadata_direction_vector_to_azimuth_elevation( - dir_v, - &q_direction->band_data[band_m_idx].azimuth[block_m_idx], - &q_direction->band_data[band_m_idx].elevation[block_m_idx] ); -#endif } } /* Sectors */ - if ( hodirac_flag ) + IF( hodirac_flag ) { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - q_direction->band_data[band_m_idx].azimuth[block_m_idx] = azi_secs[band_m_idx]; - q_direction->band_data[band_m_idx].elevation[block_m_idx] = ele_secs[band_m_idx]; - // q_direction->band_data[band_m_idx].energy_ratio[block_m_idx] = 1.f - diffuseness_vector[band_m_idx]; // set later + q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx] = L_shr( azi_secs_fx[band_m_idx], 1 ); // Q23 -> Q22 + move32(); + q_direction->band_data[band_m_idx].elevation_fx[block_m_idx] = L_shr( ele_secs_fx[band_m_idx], 1 ); // Q23 -> Q22 + move32(); - q_direction[1].band_data[band_m_idx].azimuth[block_m_idx] = azi_secs[num_freq_bands + band_m_idx]; - q_direction[1].band_data[band_m_idx].elevation[block_m_idx] = ele_secs[num_freq_bands + band_m_idx]; - q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] = ( 1.f - diff_secs[band_m_idx] ) / ( ( 1.f - diff_secs[band_m_idx] ) + ( 1.f - diff_secs[num_freq_bands + band_m_idx] ) + EPSILON ); - } - } - } + q_direction[1].band_data[band_m_idx].azimuth_fx[block_m_idx] = L_shr( azi_secs_fx[num_freq_bands + band_m_idx], 1 ); // Q23 -> Q22 + move32(); + q_direction[1].band_data[band_m_idx].elevation_fx[block_m_idx] = L_shr( ele_secs_fx[num_freq_bands + band_m_idx], 1 ); // Q23 -> Q22 + move32(); + Word32 x = L_sub( ONE_IN_Q30, L_shr( diff_secs_fx[band_m_idx], sub( 1, diff_secs_exp[band_m_idx] ) ) ); + Word32 y = L_sub( ONE_IN_Q30, L_shr( diff_secs_fx[num_freq_bands + band_m_idx], sub( 1, diff_secs_exp[num_freq_bands + band_m_idx] ) ) ); -#ifdef IVAS_FLOAT_FIXED - for ( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) - { - free( hDirAC->direction_vector_m_fx[0][block_m_idx] ); - free( hDirAC->direction_vector_m_fx[1][block_m_idx] ); - free( hDirAC->direction_vector_m_fx[2][block_m_idx] ); + Word16 tmp16 = extract_h( L_add( x, y ) ); + Word32 tmp32; + IF( tmp16 == 0 ) + { + tmp32 = L_deposit_h( div_l( x, EPSILON_FX ) ); + } + ELSE + { + tmp32 = L_deposit_h( div_l( x, tmp16 ) ); + } + tmp32 = L_shr( tmp32, 1 ); // Q31 -> Q30 + } + } } - free( hDirAC->direction_vector_m_fx[0] ); - free( hDirAC->direction_vector_m_fx[1] ); - free( hDirAC->direction_vector_m_fx[2] ); -#endif /* Diffuseness */ - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - if ( renormalization_factor_diff[band_m_idx] > EPSILON ) + IF( GT_32( renormalization_factor_diff_fx[band_m_idx], EPSILON_FX ) ) { - hDirAC->diffuseness_m[band_m_idx] /= renormalization_factor_diff[band_m_idx]; + Word16 tmp_e; + hDirAC->diffuseness_m_fx[band_m_idx] = L_deposit_h( BASOP_Util_Divide3232_Scale( hDirAC->diffuseness_m_fx[band_m_idx], renormalization_factor_diff_fx[band_m_idx], &tmp_e ) ); + move32(); + tmp_e = add( tmp_e, sub( hDirAC->diffuseness_m_exp[band_m_idx], renormalization_factor_diff_exp[band_m_idx] ) ); + hDirAC->diffuseness_m_fx[band_m_idx] = L_shr( hDirAC->diffuseness_m_fx[band_m_idx], sub( 1, tmp_e ) ); // to Q30 + move32(); } - else + ELSE { - hDirAC->diffuseness_m[band_m_idx] = 0.f; + hDirAC->diffuseness_m_fx[band_m_idx] = 0; + move32(); } + hDirAC->diffuseness_m_exp[band_m_idx] = 1; + move16(); /* set coherence to zero and convert diffuseness to energy ratio*/ - set_f( q_direction->band_data[band_m_idx].energy_ratio, 1.f - hDirAC->diffuseness_m[band_m_idx], q_direction->cfg.nblocks ); + set32_fx( q_direction->band_data[band_m_idx].energy_ratio_fx, L_sub( ONE_IN_Q30, hDirAC->diffuseness_m_fx[band_m_idx] ), q_direction->cfg.nblocks ); - for ( block_m_idx = 0; block_m_idx < q_direction->cfg.nblocks; block_m_idx++ ) + FOR( block_m_idx = 0; block_m_idx < q_direction->cfg.nblocks; block_m_idx++ ) { - if ( q_direction->coherence_band_data != NULL ) + IF( q_direction->coherence_band_data != NULL ) { q_direction->coherence_band_data[band_m_idx].spread_coherence[block_m_idx] = 0; + move16(); } } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < nchan_fb_in; i++ ) - { - free( data_f_fx[i] ); - free( pp_fr_real_fx[i] ); - free( pp_fr_imag_fx[i] ); - } - free( pp_fr_real_fx ); - free( pp_fr_imag_fx ); -#endif - pop_wmops(); return; } @@ -1891,7 +2326,62 @@ void ivas_dirac_param_est_enc( * * *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void computeIntensityVector_enc_fx( + const DIRAC_ENC_HANDLE hDirAC, + Word32 Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], + Word32 Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], + const Word16 enc_param_start_band, /* i : first band to process */ + const Word16 num_frequency_bands, + Word32 intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS] ) +{ + /* Reminder + * X = a + ib; Y = c + id + * X*Y = ac - bd + i(ad +bc) + */ + Word16 i, j; + Word32 real, img; + Word16 brange[2]; + + FOR( i = 0; i < num_frequency_bands; i++ ) + { + brange[0] = hDirAC->band_grouping[i + enc_param_start_band]; + move16(); + brange[1] = hDirAC->band_grouping[i + enc_param_start_band + 1]; + move16(); + + intensity_real[0][i] = 0; + move32(); + intensity_real[1][i] = 0; + move32(); + intensity_real[2][i] = 0; + move32(); + Word64 tmp_1 = 0, tmp_2 = 0, tmp_3 = 0; + move64(); + move64(); + move64(); + + FOR( j = brange[0]; j < brange[1]; j++ ) + { + real = Cldfb_RealBuffer[0][j]; + move32(); + img = Cldfb_ImagBuffer[0][j]; + move32(); + /* Intensity is XYZ order, audio is WYZX order. */ + tmp_1 = W_add( tmp_1, W_add( W_mult_32_32( Cldfb_RealBuffer[3][j], real ), W_mult_32_32( Cldfb_ImagBuffer[3][j], img ) ) ); + tmp_2 = W_add( tmp_2, W_add( W_mult_32_32( Cldfb_RealBuffer[1][j], real ), W_mult_32_32( Cldfb_ImagBuffer[1][j], img ) ) ); + tmp_3 = W_add( tmp_3, W_add( W_mult_32_32( Cldfb_RealBuffer[2][j], real ), W_mult_32_32( Cldfb_ImagBuffer[2][j], img ) ) ); + } + + intensity_real[0][i] = W_extract_h( tmp_1 ); // output Q= 2* input_q + 1 - 32 + intensity_real[1][i] = W_extract_h( tmp_2 ); // output Q= 2* input_q + 1 - 32 + intensity_real[2][i] = W_extract_h( tmp_3 ); // output Q= 2* input_q + 1 - 32 + } + + return; +} +#else static void computeIntensityVector_enc( DIRAC_ENC_HANDLE hDirAC, float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ @@ -1929,7 +2419,7 @@ static void computeIntensityVector_enc( return; } - +#endif /*------------------------------------------------------------------------- * computeDiffuseness_mdft() diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index cb2965b62f1bf99fca24d84532e0f9f5d273b2d5..c417361764ecbec4797d8a01b36ed274b89f3336 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -803,8 +803,6 @@ ivas_error ivas_enc( } for ( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) { - st_ivas->hIsmMetaData[i]->azimuth_fx = floatToFixed( st_ivas->hIsmMetaData[i]->azimuth, Q22 ); - st_ivas->hIsmMetaData[i]->elevation_fx = floatToFixed( st_ivas->hIsmMetaData[i]->elevation, Q22 ); floatToFixed_arr32( st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input[i], st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input_fx[i], Q14, st_ivas->hParamIsm->hFbMixer->fb_cfg->prior_input_length ); st_ivas->hParamIsm->last_cardioid_left_fx[i] = float_to_fix16( st_ivas->hParamIsm->last_cardioid_left[i], Q14 ); } @@ -824,7 +822,6 @@ ivas_error ivas_enc( } for ( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) { - st_ivas->hIsmMetaData[i]->azimuth_fx = floatToFixed( st_ivas->hIsmMetaData[i]->azimuth, Q22 ); fixedToFloat_arrL32( st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input_fx[i], st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input[i], Q14, st_ivas->hParamIsm->hFbMixer->fb_cfg->prior_input_length ); st_ivas->hParamIsm->last_cardioid_left[i] = fixedToFloat_16( st_ivas->hParamIsm->last_cardioid_left_fx[i], Q14 ); } @@ -866,12 +863,50 @@ ivas_error ivas_enc( if ( st_ivas->hQMetaData != NULL && ivas_format == MASA_FORMAT ) { +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < st_ivas->nchan_transport; i++ ) + { + floatToFixed_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); + } +#endif + + ivas_masa_estimate_energy_fx( st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, st_ivas->q_data_fx ); /* energy-estimation uses TF-resolution: 4x24 */ + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < st_ivas->nchan_transport; i++ ) + { + fixedToFloat_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); + } +#endif +#else ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ +#endif +#ifdef IVAS_FLOAT_FIXED + if ( ( error = ivas_masa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + if ( st_ivas->hQMetaData->q_direction ) + { + for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + if ( st_ivas->hQMetaData->no_directions == 2 ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } + } +#endif // IVAS_FLOAT_FIXED_CONVERSIONS +#else if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#endif // IVAS_FLOAT_FIXED if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) @@ -920,25 +955,70 @@ ivas_error ivas_enc( float *data_separated_object; Word32 *data_separated_object_fx; - int16_t idx_separated_object; - int16_t flag_omasa_ener_brate; + Word16 idx_separated_object; + Word16 flag_omasa_ener_brate; flag_omasa_ener_brate = 0; + move16(); /* Stereo transport is used also with monoMASA, duplicate mono if monoMASA */ + IF( EQ_16( sub( st_ivas->hEncoderConfig->nchan_inp, hEncoderConfig->nchan_ism ), 1 ) ) + { + v_multc_fixed( data_fx[hEncoderConfig->nchan_ism], L_deposit_h( INV_SQRT2_FX_Q15 ) /* Q31 */, data_fx[hEncoderConfig->nchan_ism], input_frame ); + Copy32( data_fx[hEncoderConfig->nchan_ism], data_fx[hEncoderConfig->nchan_ism + 1], input_frame ); + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( ( st_ivas->hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism ) == 1 ) { v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); } +#endif +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < st_ivas->nchan_transport; i++ ) + { + floatToFixed_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); + } +#endif + /* Estimate TF-tile energy for the input MASA stream */ + ivas_masa_estimate_energy_fx( st_ivas->hMasa, &( data_fx[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport, st_ivas->q_data_fx ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < st_ivas->nchan_transport; i++ ) + { + fixedToFloat_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); + } +#endif +#else /* Estimate TF-tile energy for the input MASA stream */ ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); +#endif +#ifdef IVAS_FLOAT_FIXED + if ( ( error = ivas_omasa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + if ( st_ivas->hQMetaData->q_direction ) + { + for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + if ( st_ivas->hQMetaData->no_directions == 2 ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } + } +#endif // IVAS_FLOAT_FIXED_CONVERSIONS +#else if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#endif // IVAS_FLOAT_FIXED set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); idx_separated_object = 0; @@ -952,50 +1032,9 @@ ivas_error ivas_enc( /* Estimate MASA parameters for the objects */ #ifdef IVAS_FLOAT_FIXED_CONVERSIONS OMASA_ENC_HANDLE hOMasa = st_ivas->hOMasa; - MASA_ENCODER_HANDLE hMasa = st_ivas->hMasa; int16_t j; int16_t nchan_transport = st_ivas->nchan_transport; int16_t nchan_ism = hEncoderConfig->nchan_ism; - Word16 block_m_idx, band_m_idx; - for ( i = 0; i < 3; i++ ) - { - for ( j = 0; j < 32; j++ ) - { - for ( int k = 0; k < MASA_FREQUENCY_BANDS; k++ ) - { - hOMasa->buffer_intensity_real_fx[i][j][k] = floatToFixed( hOMasa->buffer_intensity_real[i][j][k], hOMasa->buffer_intensity_real_q[j] ); - } - } - } - for ( i = 0; i < DIRAC_NO_COL_AVG_DIFF; i++ ) - { - for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hOMasa->buffer_energy_fx[i * MASA_FREQUENCY_BANDS + j] = floatToFixed( hOMasa->buffer_energy[i * MASA_FREQUENCY_BANDS + j], hOMasa->buffer_energy_q[i] ); - } - } - for ( i = 0; i < nchan_ism; i++ ) - { - hOMasa->chnlToFoaMtx_fx[0][i] = float_to_fix( hOMasa->chnlToFoaMtx[0][i], 31 ); /*q31*/ - hOMasa->chnlToFoaMtx_fx[1][i] = float_to_fix( hOMasa->chnlToFoaMtx[1][i], 31 ); /*q31*/ - hOMasa->chnlToFoaMtx_fx[2][i] = float_to_fix( hOMasa->chnlToFoaMtx[2][i], 31 ); /*q31*/ - hOMasa->chnlToFoaMtx_fx[3][i] = float_to_fix( hOMasa->chnlToFoaMtx[3][i], 31 ); /*q31*/ - } - for ( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) - { - for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) - { - hMasa->data.hOmasaData->energy_ism_fx[block_m_idx][band_m_idx] = floatToFixed( hMasa->data.hOmasaData->energy_ism[block_m_idx][band_m_idx], 31 - hMasa->data.hOmasaData->energy_ism_fx_e[block_m_idx][band_m_idx] ); - hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = floatToFixed( hOMasa->direction_vector_m[0][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[0][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ - hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = floatToFixed( hOMasa->direction_vector_m[1][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[1][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ - hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = floatToFixed( hOMasa->direction_vector_m[2][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[2][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ - } - } - for ( i = 0; i < nchan_ism; i++ ) - { - st_ivas->hIsmMetaData[i]->azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[i]->azimuth, Q22 ); - st_ivas->hIsmMetaData[i]->elevation_fx = float_to_fix( st_ivas->hIsmMetaData[i]->elevation, Q22 ); - } int16_t norm_data_in = MAX16B; for ( j = 0; j < nchan_ism + nchan_transport; j++ ) { @@ -1013,131 +1052,21 @@ ivas_error ivas_enc( st_ivas->q_data_fx = st_ivas->q_data_fx + norm_data_in; for ( i = 0; i < nchan_ism; i++ ) { - floatToFixed_arr32( hOMasa->cldfbAnaEnc[i]->cldfb_state, hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); - } - for ( i = 0; i < nchan_ism; i++ ) - { - for ( j = 0; j < nchan_transport; j++ ) - { - hOMasa->prev_object_dm_gains_fx[i][j] = float_to_fix16( hOMasa->prev_object_dm_gains[i][j], 15 ); - } - } - for ( i = 0; i < input_frame; i++ ) - { - hOMasa->interpolator_fx[i] = float_to_fix16( hOMasa->interpolator[i], 15 ); - } - // int16_t numSf = hMasa->config.joinedSubframes == TRUE ? 1 : 4; - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( hMasa->data.energy[i][j], &hMasa->data.energy_fx[i][j], &hMasa->data.energy_e[i][j] ); - for ( int k = 0; k < hMasa->config.numberOfDirections; k++ ) - { - hMasa->masaMetadata.directional_meta[k].energy_ratio_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[k].energy_ratio[i][j], 30 ); - hMasa->masaMetadata.directional_meta[k].azimuth_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[k].azimuth[i][j], 22 ); - hMasa->masaMetadata.directional_meta[k].elevation_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[k].elevation[i][j], 22 ); - hMasa->masaMetadata.directional_meta[k].spread_coherence_fx[i][j] = float_to_fix16( hMasa->masaMetadata.directional_meta[k].spread_coherence[i][j], 15 ); - } - hMasa->masaMetadata.common_meta.surround_coherence_fx[i][j] = float_to_fix16( hMasa->masaMetadata.common_meta.surround_coherence[i][j], 15 ); - hMasa->masaMetadata.common_meta.diffuse_to_total_ratio_fx[i][j] = float_to_fix( hMasa->masaMetadata.common_meta.diffuse_to_total_ratio[i][j], 30 ); - } - } - for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) - { - hMasa->data.importanceWeight_fx[i] = floatToFixed( hMasa->data.importanceWeight[i], Q30 ); + floatToFixed_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state, hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); } - f2me_buf( hOMasa->broadband_energy_sm, hOMasa->broadband_energy_sm_fx, &hOMasa->broadband_energy_sm_e, nchan_ism + nchan_transport ); - f2me_buf( hOMasa->broadband_energy_prev, hOMasa->broadband_energy_prev_fx, &hOMasa->broadband_energy_prev_e, nchan_ism + nchan_transport ); - floatToFixed_arr16( hOMasa->fade_out_gain, hOMasa->fade_out_gain_fx, 15, input_frame ); - floatToFixed_arr16( hOMasa->fade_in_gain, hOMasa->fade_in_gain_fx, 15, input_frame ); #endif ivas_omasa_enc_fx( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_fx, st_ivas->q_data_fx, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object_fx, &idx_separated_object ); -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - for ( i = 0; i < 3; i++ ) - { - for ( j = 0; j < 32; j++ ) - { - for ( int k = 0; k < MASA_FREQUENCY_BANDS; k++ ) - { - hOMasa->buffer_intensity_real[i][j][k] = fixedToFloat( hOMasa->buffer_intensity_real_fx[i][j][k], hOMasa->buffer_intensity_real_q[j] ); - } - } - } - for ( i = 0; i < DIRAC_NO_COL_AVG_DIFF; i++ ) - { - for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hOMasa->buffer_energy[i * MASA_FREQUENCY_BANDS + j] = me2f( hOMasa->buffer_energy_fx[i * MASA_FREQUENCY_BANDS + j], 31 - hOMasa->buffer_energy_q[i] ); - } - } - for ( i = 0; i < nchan_ism; i++ ) - { - hOMasa->chnlToFoaMtx[0][i] = fixedToFloat( hOMasa->chnlToFoaMtx_fx[0][i], 31 ); /*q31*/ - hOMasa->chnlToFoaMtx[1][i] = fixedToFloat( hOMasa->chnlToFoaMtx_fx[1][i], 31 ); /*q31*/ - hOMasa->chnlToFoaMtx[2][i] = fixedToFloat( hOMasa->chnlToFoaMtx_fx[2][i], 31 ); /*q31*/ - hOMasa->chnlToFoaMtx[3][i] = fixedToFloat( hOMasa->chnlToFoaMtx_fx[3][i], 31 ); /*q31*/ - } - for ( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) - { - for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) - { - hMasa->data.hOmasaData->energy_ism[block_m_idx][band_m_idx] = me2f( hMasa->data.hOmasaData->energy_ism_fx[block_m_idx][band_m_idx], hMasa->data.hOmasaData->energy_ism_fx_e[block_m_idx][band_m_idx] ); - hOMasa->direction_vector_m[0][block_m_idx][band_m_idx] = fixedToFloat( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[0][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ - hOMasa->direction_vector_m[1][block_m_idx][band_m_idx] = fixedToFloat( hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[1][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ - hOMasa->direction_vector_m[2][block_m_idx][band_m_idx] = fixedToFloat( hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[2][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ - } - } - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hMasa->data.energy[i][j] = me2f( hMasa->data.energy_fx[i][j], hMasa->data.energy_e[i][j] ); - for ( int k = 0; k < hMasa->config.numberOfDirections; k++ ) - { - hMasa->masaMetadata.directional_meta[k].energy_ratio[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[k].energy_ratio_fx[i][j], 30 ); - hMasa->masaMetadata.directional_meta[k].azimuth[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[k].azimuth_fx[i][j], 22 ); - hMasa->masaMetadata.directional_meta[k].elevation[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[k].elevation_fx[i][j], 22 ); - hMasa->masaMetadata.directional_meta[k].spread_coherence[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[k].spread_coherence_fx[i][j], 15 ); - } - hMasa->masaMetadata.common_meta.surround_coherence[i][j] = fix_to_float( hMasa->masaMetadata.common_meta.surround_coherence_fx[i][j], 15 ); - hMasa->masaMetadata.common_meta.diffuse_to_total_ratio[i][j] = fix_to_float( hMasa->masaMetadata.common_meta.diffuse_to_total_ratio_fx[i][j], 30 ); - } - } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < nchan_ism; i++ ) { fixedToFloat_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); } - for ( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) - { - for ( i = 0; i < hOMasa->nbands; i++ ) - { - for ( int k = 0; k < nchan_ism; k++ ) - { - hMasa->data.hOmasaData->energy_ratio_ism[block_m_idx][i][k] = me2f( hMasa->data.hOmasaData->energy_ratio_ism_fx[block_m_idx][i][k], 1 ); - } - } - } for ( i = 0; i < nchan_ism + nchan_transport; i++ ) { fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); } - for ( i = 0; i < nchan_ism; i++ ) - { - st_ivas->hIsmMetaData[i]->azimuth = fixedToFloat( st_ivas->hIsmMetaData[i]->azimuth_fx, Q22 ); - st_ivas->hIsmMetaData[i]->elevation = fixedToFloat( st_ivas->hIsmMetaData[i]->elevation_fx, Q22 ); - } - for ( i = 0; i < nchan_ism; i++ ) - { - for ( j = 0; j < nchan_transport; j++ ) - { - hOMasa->prev_object_dm_gains[i][j] = fixedToFloat( hOMasa->prev_object_dm_gains_fx[i][j], 15 ); - } - } fixedToFloat_arrL( data_separated_object_fx, data_separated_object, st_ivas->q_data_fx, input_frame ); - me2f_buf( hOMasa->broadband_energy_sm_fx, hOMasa->broadband_energy_sm_e, hOMasa->broadband_energy_sm, nchan_ism + nchan_transport ); - me2f_buf( hOMasa->broadband_energy_prev_fx, hOMasa->broadband_energy_prev_e, hOMasa->broadband_energy_prev, nchan_ism + nchan_transport ); -#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED +#endif // IVAS_FLOAT_FIXED_CONVERSIONS } /* Encode ISMs transport channels */ @@ -1251,7 +1180,7 @@ ivas_error ivas_enc( n = hEncoderConfig->nchan_ism; hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -256 /* -1.0f in Q8 */, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) { return error; } @@ -1439,10 +1368,6 @@ ivas_error ivas_enc( #endif ivas_mcmasa_enc_fx( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, nchan_inp, q_data ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - st_ivas->hMasa->data.lfeToTotalEnergyRatio[i] = st_ivas->hMasa->data.lfeToTotalEnergyRatio_fx[i] / (float) ( 1 << ( Q15 - st_ivas->hMasa->data.lfeToTotalEnergyRatio_e[i] ) ); - } for ( i = 0; i < nchan_inp; i++ ) { fixedToFloat_arrL( data_fx[i], data_f[i], q_data, input_frame ); @@ -1454,8 +1379,6 @@ ivas_error ivas_enc( { FOR( jj = 0; jj < nBlocks; jj++ ) { - st_ivas->hQMetaData->q_direction[0].band_data[ii].azimuth[jj] = fixedToFloat( st_ivas->hQMetaData->q_direction[0].band_data[ii].azimuth_fx[jj], Q22 ); - st_ivas->hQMetaData->q_direction[0].band_data[ii].elevation[jj] = fixedToFloat( st_ivas->hQMetaData->q_direction[0].band_data[ii].elevation_fx[jj], Q22 ); st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio[jj] = fixedToFloat( st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio_fx[jj], Q31 ); } } diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index f2ee3a9d6c0cb2cf2df99b8c5f3d29d50c67478e..7c5223b42ecd3b3b8b4fe7f5c363f81436abe0a3 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -60,7 +60,7 @@ *------------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static void ivas_band_cov_fx( Word32 **ppIn_FR_real, Word32 **ppIn_FR_imag, Word16 *q_In_FR, const Word16 num_chans, const Word16 num_bins, Word16 stride, Word32 **pFb_bin_to_band, const Word16 *pFb_start_bin_per_band, const Word16 *pFb_active_bins_per_band, const Word16 start_band, const Word16 end_band, Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *q_cov_real[IVAS_SPAR_MAX_CH], const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH] ); +static void ivas_band_cov_fx( Word32 **ppIn_FR_real, Word32 **ppIn_FR_imag, Word16 q_In_FR, const Word16 num_chans, const Word16 num_bins, Word16 stride, Word32 **pFb_bin_to_band, const Word16 *pFb_start_bin_per_band, const Word16 *pFb_active_bins_per_band, const Word16 start_band, const Word16 end_band, Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *q_cov_real[IVAS_SPAR_MAX_CH], const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH] ); #else static void ivas_band_cov( float **ppIn_FR_real, float **ppIn_FR_imag, const int16_t num_chans, const int16_t num_bins, int16_t stride, float **pFb_bin_to_band, const int16_t *pFb_start_bin_per_band, const int16_t *pFb_active_bins_per_band, const int16_t start_band, const int16_t end_band, float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] ); #endif @@ -547,7 +547,7 @@ void ivas_enc_cov_handler_process_fx( ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ Word32 **ppIn_FR_real, Word32 **ppIn_FR_imag, - Word16 *q_ppIn_FR, + Word16 q_ppIn_FR, Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *q_cov_real[IVAS_SPAR_MAX_CH], Word32 *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -819,7 +819,7 @@ void ivas_enc_cov_handler_process( static void ivas_band_cov_fx( Word32 **ppIn_FR_real, Word32 **ppIn_FR_imag, - Word16 *q_In_FR, + Word16 q_In_FR, const Word16 num_chans, const Word16 num_bins, Word16 stride, @@ -905,7 +905,7 @@ static void ivas_band_cov_fx( cov_real_64bit[i][j][k] = temp * (Word64) ( num_blocks ); // (q_In_FR[i1] + q_In_FR[j1] + (q_shift - 10) - guard_bits move64(); } - q_cov_real[i][j] = add( add( q_In_FR[i1], q_In_FR[j1] ), sub( q_shift, Q10 ) ); + q_cov_real[i][j] = add( add( q_In_FR, q_In_FR ), sub( q_shift, Q10 ) ); move16(); } } diff --git a/lib_enc/ivas_entropy_coder.c b/lib_enc/ivas_entropy_coder.c index 900f0bb49b0850738f755240febb8c93c0f38e41..d296a4f01c5a3e1c2178d74ad98549011981814f 100644 --- a/lib_enc/ivas_entropy_coder.c +++ b/lib_enc/ivas_entropy_coder.c @@ -401,9 +401,10 @@ static Word16 arith_encode_cell_array_diff( Word16 arith_result; total_symbol_len = 0; + move16(); FOR( i = 0; i < nB; i++ ) { - total_symbol_len += ( pCell_dims[i].dim1 * pCell_dims[i].dim2 ); + total_symbol_len = add( total_symbol_len, ( imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ) ) ); } assert( LE_16( total_symbol_len, ( IVAS_MAX_INPUT_LEN ) ) ); @@ -451,35 +452,50 @@ Word16 ivas_arith_encode_cmplx_cell_array( Word16 arith_result; idx1 = 0; + move16(); IF( EQ_16( any_diff, 1 ) ) { idx = 0; total_len = 0; + move16(); + move16(); FOR( i = 0; i < nB; i++ ) { - len = ( pCell_dims[i].dim1 * pCell_dims[i].dim2 ); + len = ( imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ) ); + move16(); IF( NE_16( pDo_diff[i], 0 ) ) { FOR( j = 0; j < len; j++ ) { input_old[idx] = pSymbol_old_re[total_len + j]; input_new[idx++] = pSymbol_re[total_len + j]; + move16(); + move16(); } cell_dim_diff[i].dim1 = pCell_dims[i].dim1; cell_dim_diff[i].dim2 = pCell_dims[i].dim2; cell_dim[i].dim1 = 0; cell_dim[i].dim2 = 0; + move16(); + move16(); + move16(); + move16(); } ELSE { FOR( j = 0; j < len; j++ ) { input[idx1++] = pSymbol_re[total_len + j]; + move16(); } cell_dim_diff[i].dim1 = 0; cell_dim_diff[i].dim2 = 0; cell_dim[i].dim1 = pCell_dims[i].dim1; cell_dim[i].dim2 = pCell_dims[i].dim2; + move16(); + move16(); + move16(); + move16(); } total_len = add( total_len, len ); } @@ -491,6 +507,7 @@ Word16 ivas_arith_encode_cmplx_cell_array( } arith_result = arith_encode_cell_array_diff( cell_dim_diff, hMetaData, nB, pArith_re_diff, input_old, input_new, wc_strat_arith ); + move16(); IF( LT_16( arith_result, 0 ) ) { return -1; diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index d2cada5f9e90db83c8d0197d6151475956d0320a..61e8f6e62c1288611e6622d63a47d230ee3903b8 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -885,11 +885,12 @@ ivas_error front_vad_spar( hFrontVad->hNoiseEst->Etot_lp_32fx = (Word32) ( hFrontVad->hNoiseEst->Etot_lp * 16777216.0 ); hFrontVad->hNoiseEst->sign_dyn_lp_32fx = (Word32) ( hFrontVad->hNoiseEst->sign_dyn_lp * 16777216.0 ); st->lp_speech_fx = (Word16) floatToFixed( st->lp_speech, Q8 ); - st->lp_noise_fx = (Word16) floatToFixed( st->lp_noise, Q8 ); floatToFixed_arrL( hFrontVad->hNoiseEst->bckr, hFrontVad->hNoiseEst->bckr_fx, Q_new_old + QSCALE + 2, 20 ); floatToFixed_arrL( hFrontVad->hNoiseEst->enrO, hFrontVad->hNoiseEst->enrO_fx, Q_new_old + QSCALE + 2, 20 ); st->flag_noisy_speech_snr_fx = (Word8) st->flag_noisy_speech_snr; +#ifndef MSAN_FIX floatToFixed_arrL( &band_energies[0], &band_energies_fx[0], Q_new_old + QSCALE + 2, 40 ); +#endif #endif if ( ( error = front_vad_fx( NULL, st, hEncoderConfig, &hFrontVad, 0 /* MCT_flag */, input_frame, vad_flag_dtx, fr_bands_fx, Etot_fx, lf_E_fx, localVAD_HE_SAD, vad_hover_flag, band_energies_fx, &PS_fx[0], &st->lgBin_E_fx[0], Q_inp, &Q_buffer, Q_add, &front_create_flag ) ) != IVAS_ERR_OK ) { @@ -964,7 +965,6 @@ ivas_error front_vad_spar( Q_inp_12k8 = Q_factor_arr( inp_12k8, 3 * L_FRAME / 2 ); floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_inp_12k8, 3 * L_FRAME / 2 ); // Q_lp_noise = Q_factor( st->lp_noise ); - st->lp_noise_fx = float_to_fix16( st->lp_noise, Q8 ); dtx_ivas_fx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8_fx, Q_inp_12k8 ); #else dtx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8 ); @@ -984,7 +984,7 @@ ivas_error front_vad_spar( floatToFixed_arr( alw_voicing, alw_voicing_fx, Q15, 2 ); Q_inp_12k8 = Q9; // Q_factor_arr( inp_12k8 - 90, 3 * L_FRAME / 2 + 90 ); floatToFixed_arr( inp_12k8 - 90, inp_12k8_fx - 90, Q_inp_12k8, 3 * L_FRAME / 2 + 90 ); - analy_lp_fx( inp_12k8_fx, L_FRAME, L_LOOK_12k8, &res_energy_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, 0 /* <-- sec_chan_low_rate */, Q_inp_12k8, Q_r ); + analy_lp_ivas_fx( inp_12k8_fx, L_FRAME, L_LOOK_12k8, &res_energy_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, 0 /* <-- sec_chan_low_rate */, Q_inp_12k8, Q_r ); for ( Word16 i = 0; i <= M; i++ ) { epsP_fx[i] = L_Comp( epsP_h[i], epsP_l[i] ); @@ -1034,7 +1034,9 @@ ivas_error front_vad_spar( floatToFixed_arr( wsp, wsp_fx, Q8, 368 ); floatToFixed_arr( st->old_wsp2, st->old_wsp2_fx, Q8, 115 ); floatToFixed_arr( st->mem_decim2, st->mem_decim2_fx, Q8, 3 ); - // st->old_corr_fx = (Word16)floatToFixed( st->old_corr, Q15 ); +#ifdef MSAN_FIX + st->old_corr_fx = (Word16) floatToFixed( st->old_corr, Q15 ); +#endif corr_shift_fx = (Word16) floatToFixed( corr_shift, Q15 ); // st->old_thres_fx = (Word16) floatToFixed( st->old_thres, Q15 ); relE_fx = (Word16) floatToFixed( relE, Q8 ); diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 3dc5c4cd1d60fed98c012d0b2469cd65e7e4c79d..b40665a98926ed263027aba0a3b1478388d7bfd2 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -373,6 +373,7 @@ void ivas_write_format_sid_fx( *-------------------------------------------------------------------*/ /*! r: number of channels to be analysed */ +#ifndef IVAS_FLOAT_FIXED int16_t getNumChanAnalysis( Encoder_Struct *st_ivas /* i : IVAS encoder structure */ ) @@ -407,8 +408,7 @@ int16_t getNumChanAnalysis( return n; } - -#ifdef IVAS_FLOAT_FIXED +#else Word16 getNumChanAnalysis_fx( Encoder_Struct *st_ivas /* i : IVAS encoder structure */ ) @@ -492,6 +492,12 @@ void copy_encoder_config( return; } #ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * copy_encoder_config_fx() + * + * Copy configuration structrue to the state structrure + *-------------------------------------------------------------------*/ + void copy_encoder_config_fx( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ Encoder_State *st_fx, /* o : encoder state structure */ @@ -775,10 +781,17 @@ ivas_error ivas_init_encoder( /* prepare stereo downmix for EVS */ if ( hEncoderConfig->stereo_dmx_evs == 1 ) { +#ifndef IVAS_FLOAT_FIXED if ( ( error = stereo_dmx_evs_init_encoder( &( st_ivas->hStereoDmxEVS ), input_Fs ) ) != IVAS_ERR_OK ) { return error; } +#else + if ( ( error = stereo_dmx_evs_init_encoder_fx( &( st_ivas->hStereoDmxEVS ), input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif } } else if ( ivas_format == STEREO_FORMAT ) @@ -943,10 +956,17 @@ ivas_error ivas_init_encoder( if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { +#ifdef IVAS_FLOAT_FIXED + if ( ( error = ivas_omasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_omasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#endif // IVAS_FLOAT_FIXED } if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) @@ -1179,13 +1199,30 @@ ivas_error ivas_init_encoder( } #ifndef IVAS_FLOAT_FIXED if ( ( error = ivas_mcmasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } #else if ( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) -#endif { return error; } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + if ( st_ivas->hQMetaData->q_direction != NULL ) + { + for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + if ( st_ivas->hQMetaData->no_directions == 2 ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } + } +#endif + +#endif // IVAS_FLOAT_FIXED_CONVERSIONS #ifndef IVAS_FLOAT_FIXED ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); #else @@ -1217,7 +1254,11 @@ ivas_error ivas_init_encoder( *-----------------------------------------------------------------*/ /* set number of input channels used for analysis/coding */ +#ifndef IVAS_FLOAT_FIXED n = getNumChanAnalysis( st_ivas ); +#else + n = getNumChanAnalysis_fx( st_ivas ); +#endif if ( n > 0 ) { @@ -1417,9 +1458,9 @@ ivas_error ivas_init_encoder_fx( } /* prepare stereo downmix for EVS */ - IF( hEncoderConfig->stereo_dmx_evs == 1 ) + IF( EQ_16( hEncoderConfig->stereo_dmx_evs, 1 ) ) { - IF( ( error = stereo_dmx_evs_init_encoder( &( st_ivas->hStereoDmxEVS ), input_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = stereo_dmx_evs_init_encoder_fx( &( st_ivas->hStereoDmxEVS ), input_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -1587,7 +1628,7 @@ ivas_error ivas_init_encoder_fx( if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { - if ( ( error = ivas_omasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_omasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1820,13 +1861,30 @@ ivas_error ivas_init_encoder_fx( #ifndef IVAS_FLOAT_FIXED if ( ( error = ivas_mcmasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } #else if ( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) -#endif { return error; } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + if ( st_ivas->hQMetaData->q_direction != NULL ) + { + for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + if ( st_ivas->hQMetaData->no_directions == 2 ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } + } +#endif + +#endif // IVAS_FLOAT_FIXED_CONVERSIONS #ifndef IVAS_FLOAT_FIXED ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); #else @@ -1965,7 +2023,8 @@ void destroy_core_enc( IF( hCoreCoder->hVAD_CLDFB != NULL ) { - free( hCoreCoder->hVAD_CLDFB ); + /* This is not required as we are not allocating memory dynamically */ + // free( hCoreCoder->hVAD_CLDFB ); hCoreCoder->hVAD_CLDFB = NULL; } @@ -2175,13 +2234,17 @@ void ivas_destroy_enc( #endif /* OMASA handle */ - ivas_omasa_enc_close( &( st_ivas->hOMasa ) ); + ivas_omasa_enc_close_fx( &( st_ivas->hOMasa ) ); /* OSBA handle */ ivas_osba_enc_close_fx( &( st_ivas->hOSba ) ); /* Stereo downmix for EVS encoder handle */ +#ifdef IVAS_FLOAT_FIXED + stereo_dmx_evs_close_encoder_fx( &( st_ivas->hStereoDmxEVS ) ); +#else stereo_dmx_evs_close_encoder( &( st_ivas->hStereoDmxEVS ) ); +#endif /* Encoder configuration handle */ if ( st_ivas->hEncoderConfig != NULL ) diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 177d52e38c4737f82aefba96787ea7853a9b3007..78eb1974d9b479b025605be095b7e8d089cd9177 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -557,68 +557,21 @@ ivas_error ivas_ism_enc( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( st->hTranDet->subblockEnergies.firState1_flt, -1 ); - st->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( st->hTranDet->subblockEnergies.firState2_flt, -1 ); - - FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - st->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( st->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); - } - - FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - st->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( st->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); - st->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( st->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); - } - - - FOR( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - st->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( st->hTranDet->delayBuffer.buffer_flt[i], 7 ); - } - - st->hTranDet->transientDetector.attackRatioThreshold = (Word16) floatToFixed( st->hTranDet->transientDetector.attackRatioThreshold_flt, 11 ); - floatToFixed_arr16( st->input, st->input_fx, -1, input_frame ); - st->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( st->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); - #endif - RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - st->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.firState1, -1 ); - st->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.firState2, -1 ); - - FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - st->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( st->hTranDet->subblockEnergies.subblockNrg[i], 7 ); - st->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); - } - - FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - st->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( st->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); - } - - FOR( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - st->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) st->hTranDet->delayBuffer.buffer[i], -1 ); - } -#endif + st->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; + st->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; + move16(); + move16(); #else RunTransientDetection( st->input, input_frame, st->hTranDet ); #endif #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 e_tmp; - f2me_buf_16( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, &e_tmp, 24 ); -#endif currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - currFlatness[0] = me2f_16( currFlatness_fx[0], e_tmp ); + currFlatness[0] = me2f_16( currFlatness_fx[0], 15 - Q7 ); #endif #else currFlatness[0] = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS, 0 ); @@ -664,29 +617,10 @@ ivas_error ivas_ism_enc( *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( st_ivas->hIsmMetaData != NULL ) - { - FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) - { - st_ivas->hIsmMetaData[ch]->azimuth_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); - st_ivas->hIsmMetaData[ch]->elevation_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); - st_ivas->hIsmMetaData[ch]->yaw_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->yaw, Q22 ); - st_ivas->hIsmMetaData[ch]->pitch_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->pitch, Q22 ); - st_ivas->hIsmMetaData[ch]->radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->radius, Q9 ); - st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_azimuth, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_elevation, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->last_true_radius, Q9 ); - } - } if ( st_ivas->hISMDTX ) { floatToFixed_arr16( st_ivas->hISMDTX->coh, st_ivas->hISMDTX->coh_fx, Q15, st_ivas->nchan_transport ); } - for ( int ch = 0; ch < st_ivas->nchan_transport; ch++ ) - { - IF( st_ivas->hSCE[ch] ) - st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise_fx = float_to_fix16( st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise, Q8 ); /*Q8*/ - } /* compute the dominant sce_id using long term energy */ for ( int j = 0; j < st_ivas->nchan_transport; j++ ) @@ -697,11 +631,6 @@ ivas_error ivas_ism_enc( IF( st_ivas->hISMDTX ) f2me_buf( &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc[0][0], &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_fx[0][0], &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_e, st_ivas->nchan_transport * PARAM_ISM_HYS_BUF_SIZE ); - IF( st_ivas->hMasa != NULL ) - { - st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = floatToFixed( st_ivas->hMasa->data.hOmasaData->lp_noise_CPE, Q8 ); - } - FOR( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ ) { relE_fx[sce_id][0] = float_to_fix16( relE[sce_id][0], Q8 ); @@ -739,7 +668,7 @@ ivas_error ivas_ism_enc( } ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { - IF( NE_32( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, L_negate( ONE_IN_Q8 ), 0, NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -256 /* -1.0f in Q8 */, 0, NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ), IVAS_ERR_OK ) ) { return error; } @@ -905,17 +834,6 @@ ivas_error ivas_ism_enc( pop_wmops(); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( st_ivas->hIsmMetaData != NULL ) - { - FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) - { - st_ivas->hIsmMetaData[ch]->last_true_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_elevation_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_radius = fix16_to_float( st_ivas->hIsmMetaData[ch]->last_true_radius_fx, Q9 ); - st_ivas->hIsmMetaData[ch]->last_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_azimuth_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->last_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_elevation_fx, Q22 ); - } - } IF( st_ivas->hISMDTX ) { me2f_buf( &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_fx[0][0], st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_e, &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc[0][0], st_ivas->nchan_transport * PARAM_ISM_HYS_BUF_SIZE ); diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index fdd17fa68c988b853ac2608da1eb4cd492e919ef..982b355503449e91162491a6dde37d1701ee910a 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -282,8 +282,8 @@ ivas_error ivas_ism_metadata_enc( const Word16 ism_mode, /* i : ISM mode */ const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Enc Handle */ const Word16 ism_extended_metadata_flag, /* i : Extended metadata flag */ - const Word32 lp_noise_CPE_fx, - const Word16 flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ + const Word16 lp_noise_CPE_fx, /* i : Q8 */ + const Word16 flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ Word16 *omasa_stereo_sw_cnt, const Word16 ini_frame ) { @@ -1622,11 +1622,6 @@ ivas_error ivas_ism_metadata_enc_create( move16(); st_ivas->hIsmMetaData[ch]->q_elevation_old_fx = 0; move16(); - /*===============fix-to-flt====================*/ - st_ivas->hIsmMetaData[ch]->q_azimuth_old = fix_to_float( st_ivas->hIsmMetaData[ch]->q_azimuth_old_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->q_elevation_old = fix_to_float( st_ivas->hIsmMetaData[ch]->q_elevation_old_fx, Q22 ); - /*===============fix-to-flt====================*/ - #ifdef IVAS_FLOAT_FIXED ivas_ism_reset_metadata_enc( st_ivas->hIsmMetaData[ch] ); @@ -1644,15 +1639,6 @@ ivas_error ivas_ism_metadata_enc_create( st_ivas->hIsmMetaData[ch]->ism_md_fec_cnt_enc = 0; st_ivas->hIsmMetaData[ch]->ism_md_inc_diff_cnt = ISM_MD_INC_DIFF_CNT_MAX; st_ivas->hIsmMetaData[ch]->last_true_radius_fx = ONE_IN_Q9; - - /*===============fix-to-flt====================*/ - st_ivas->hIsmMetaData[ch]->last_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_azimuth_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->last_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_elevation_fx, Q22 ); - - st_ivas->hIsmMetaData[ch]->last_true_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_elevation_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_radius = fix16_to_float( st_ivas->hIsmMetaData[ch]->last_true_radius_fx, Q9 ); - /*===============fix-to-flt====================*/ } IF( EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index a7eb2b719b423fcb99b4b5c6b3c53f4eeeacf59c..5438bc9217d3bf530bcd55814e72b392425856df 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -41,6 +41,7 @@ #include "prot.h" #ifdef IVAS_FLOAT_FIXED #include "prot_fx.h" +#include "prot_fx_enc.h" #include "ivas_prot_fx.h" #endif #ifdef IVAS_FLOAT_FIXED @@ -68,7 +69,16 @@ static void find_n_largest( const float *input, int16_t *largestIndices, const i static void move_metadata_to_qmetadata( const MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMeta ); #endif +#ifdef IVAS_FLOAT_FIXED +static void detect_metadata_composition_fx( + const MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder data */ + UWord8 *joinedSubframes, /* o : Result of subframe composition */ + UWord8 *coherencePresent, /* o : Result of coherence presence */ + UWord8 *isTwoDir /* o : Result of two direction check */ +); +#else static void detect_metadata_composition( const MASA_ENCODER_HANDLE hMasa, uint8_t *joinedSubframes, uint8_t *coherencePresent, uint8_t *isTwoDir ); +#endif #ifdef IVAS_FLOAT_FIXED static void compensate_energy_ratios_fx( MASA_ENCODER_HANDLE hMasa ); @@ -78,18 +88,28 @@ static void compensate_energy_ratios( MASA_ENCODER_HANDLE hMasa ); #ifdef IVAS_FLOAT_FIXED static Word16 encode_lfe_to_total_energy_ratio_fx( MASA_ENCODER_HANDLE hMasa, BSTR_ENC_HANDLE hMetaData, const Word32 ivas_total_brate ); + +static void ivas_encode_masaism_metadata_fx( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, ISM_METADATA_HANDLE hIsmMeta[], const Word16 nchan_ism, const Word16 low_bitrate_mode, const Word16 omasa_nbands, const Word16 omasa_nblocks, const Word16 idx_separated_object, const Word16 ism_imp ); + +static void reduce_metadata_further_fx( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); #else static int16_t encode_lfe_to_total_energy_ratio( MASA_ENCODER_HANDLE hMasa, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate ); -#endif static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, ISM_METADATA_HANDLE hIsmMeta[], const int16_t nchan_ism, const int16_t low_bitrate_mode, const int16_t omasa_nbands, const int16_t omasa_nblocks, const int16_t idx_separated_object, const int16_t ism_imp ); -#ifndef IVAS_FLOAT_FIXED + static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); -#else -static void reduce_metadata_further_fx( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); #endif +#ifdef IVAS_FLOAT_FIXED +static void average_masa_metadata_fx( + MASA_METADATA_FRAME *hMeta, + Word32 energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + Word16 energy_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + const SPHERICAL_GRID_DATA *Sph_Grid16, + const UWord8 useSphGrid ); +#else static void average_masa_metadata( MASA_METADATA_FRAME *masaMetadata, float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], const SPHERICAL_GRID_DATA *sphGrid, const uint8_t useSphGrid ); +#endif // IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED static void copy_masa_metadata_subframe_fx( @@ -115,8 +135,9 @@ static UWord8 are_masa_subframes_similar_fx( const MASA_METADATA_HANDLE frame2, /* i : MASA metadata frame 2 */ const UWord8 sf2_idx /* i : index of the subframe of frame2 to inspect */ ); -#endif +#else static uint8_t are_masa_subframes_similar( const MASA_METADATA_HANDLE frame1, const uint8_t sf1_idx, const MASA_METADATA_HANDLE frame2, const uint8_t sf2_idx ); +#endif #ifdef IVAS_FLOAT_FIXED static void detect_framing_async_fx( @@ -229,20 +250,32 @@ ivas_error ivas_masa_enc_open( hMasa->data.onset_detector_2 = 0.0f; #endif - set_zero( hMasa->data.lfeToTotalEnergyRatio, MAX_PARAM_SPATIAL_SUBFRAMES ); +#ifdef IVAS_FLOAT_FIXED set32_fx( hMasa->data.lfeToTotalEnergyRatio_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); set16_fx( hMasa->data.lfeToTotalEnergyRatio_e, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = 0; + move32(); +#else + set_zero( hMasa->data.lfeToTotalEnergyRatio, MAX_PARAM_SPATIAL_SUBFRAMES ); hMasa->data.prevq_lfeToTotalEnergyRatio = 0.0f; +#endif hMasa->data.prevq_lfeIndex = 0; hMasa->data.sync_state.prev_sim_stop = 0; hMasa->data.sync_state.prev_offset = 0; hMasa->data.sync_state.frame_mode = MASA_FRAME_4SF; +#ifdef IVAS_FLOAT_FIXED + set_zero_fx( hMasa->data.dir_align_state.previous_azi_dir1_fx, MASA_FREQUENCY_BANDS ); + set_zero_fx( hMasa->data.dir_align_state.previous_ele_dir1_fx, MASA_FREQUENCY_BANDS ); + set_zero_fx( hMasa->data.dir_align_state.previous_azi_dir2_fx, MASA_FREQUENCY_BANDS ); + set_zero_fx( hMasa->data.dir_align_state.previous_ele_dir2_fx, MASA_FREQUENCY_BANDS ); +#else set_zero( hMasa->data.dir_align_state.previous_azi_dir1, MASA_FREQUENCY_BANDS ); set_zero( hMasa->data.dir_align_state.previous_ele_dir1, MASA_FREQUENCY_BANDS ); set_zero( hMasa->data.dir_align_state.previous_azi_dir2, MASA_FREQUENCY_BANDS ); set_zero( hMasa->data.dir_align_state.previous_ele_dir2, MASA_FREQUENCY_BANDS ); +#endif if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { @@ -252,19 +285,34 @@ ivas_error ivas_masa_enc_open( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data encoder\n" ) ); } +#ifdef IVAS_FLOAT_FIXED + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + set32_fx( hOmasaData->masa_to_total_energy_ratio_fx[i], 0, MASA_FREQUENCY_BANDS ); + } +#else for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { set_f( hOmasaData->masa_to_total_energy_ratio[i], 0, MASA_FREQUENCY_BANDS ); } +#endif +#ifndef IVAS_FLOAT_FIXED hOmasaData->lp_noise_CPE = -1; +#else + hOmasaData->lp_noise_CPE_fx = -256; /* -1 in Q8 */ +#endif hOmasaData->omasa_stereo_sw_cnt = OMASA_STEREO_SW_CNT_MAX; #ifdef IVAS_FLOAT_FIXED - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - set_zero( hOmasaData->energy_ism[i], MASA_FREQUENCY_BANDS ); set_zero_fx( hOmasaData->energy_ism_fx[i], MASA_FREQUENCY_BANDS ); set16_fx( hOmasaData->energy_ism_fx_e[i], 0, MASA_FREQUENCY_BANDS ); } +#else + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + set_zero( hOmasaData->energy_ism[i], MASA_FREQUENCY_BANDS ); + } #endif hMasa->data.hOmasaData = hOmasaData; @@ -326,572 +374,371 @@ ivas_error ivas_masa_encode( MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ - int16_t *nb_bits_metadata, /* o : number of metadata bits written */ - const int16_t nchan_transport, /* i : number of MASA input/transport channels */ + Word16 *nb_bits_metadata, /* o : number of metadata bits written */ + const Word16 nchan_transport, /* i : number of MASA input/transport channels */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - const int16_t Opt_DTX_ON, /* i : DTX on flag */ - const int16_t element_mode, /* i : element mode */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 Opt_DTX_ON, /* i : DTX on flag */ + const Word16 element_mode, /* i : element mode */ const ISM_MODE ism_mode, /* i : ISM format mode */ - const int16_t nchan_ism, /* i : number of ISM channels */ + const Word16 nchan_ism, /* i : number of ISM channels */ ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ - const int16_t idx_separated_object, /* i : index of the separated object */ + const Word16 idx_separated_object, /* i : index of the separated object */ OMASA_ENC_HANDLE hOMasa, /* i : OMASA encoder handle */ - const int16_t ism_imp, /* i : importance of separated object */ - const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ + const Word16 ism_imp, /* i : importance of separated object */ + const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ ) { MASA_DIRECTIONAL_SPATIAL_META *h_orig_metadata; - int16_t i, j; - int16_t masa_sid_descriptor; - int16_t low_bitrate_mode; - int32_t masa_total_brate; + Word16 i, j, s; + Word16 masa_sid_descriptor; + Word16 low_bitrate_mode; + Word32 masa_total_brate; ivas_error error; - Word16 guard_bits; + Word16 guard_bits, tmp; + + guard_bits = find_guarded_bits_fx( 24 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < hQMetaData->no_directions; i++ ) + { + for ( j = hQMetaData->q_direction[i].cfg.start_band; j < hQMetaData->q_direction[i].cfg.nbands; ++j ) + { + floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } +#endif masa_sid_descriptor = -1; h_orig_metadata = NULL; low_bitrate_mode = 0; + move16(); + move16(); - if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) + test(); + IF( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { /* Create the MASA SID descriptor for the metadata and CPE mode, in order to have the SID frame self-contained. */ - if ( Opt_DTX_ON && hQMetaData != NULL ) + test(); + IF( Opt_DTX_ON && hQMetaData != NULL ) { - if ( nchan_transport == 2 ) /* this is MASA format in CPE only */ + IF( EQ_16( nchan_transport, 2 ) ) /* this is MASA format in CPE only */ { masa_sid_descriptor = 0; /* for IVAS_CPE_DFT */ - if ( element_mode == IVAS_CPE_MDCT ) + move16(); + if ( EQ_16( element_mode, IVAS_CPE_MDCT ) ) { masa_sid_descriptor = 1; + move16(); } } } /* Validate and compensate ratios as necessary */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 sf, dir; - MASA_METADATA_HANDLE hMeta = &( hMasa->masaMetadata ); - Word16 numDirs = hMeta->descriptive_meta.numberOfDirections + 1; - FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) - { - floatToFixed_arrL32( hMeta->common_meta.remainder_to_total_ratio[sf], hMeta->common_meta.remainder_to_total_ratio_fx[sf], Q30, MASA_FREQUENCY_BANDS ); - FOR( dir = 0; dir < numDirs; dir++ ) - { - floatToFixed_arrL32( hMeta->directional_meta[dir].energy_ratio[sf], hMeta->directional_meta[dir].energy_ratio_fx[sf], Q30, MASA_FREQUENCY_BANDS ); - } - floatToFixed_arrL32( hMeta->common_meta.diffuse_to_total_ratio[sf], hMeta->common_meta.diffuse_to_total_ratio_fx[sf], Q30, MASA_FREQUENCY_BANDS ); - } -#endif compensate_energy_ratios_fx( hMasa ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) - { - FOR( dir = 0; dir < numDirs; dir++ ) - { - fixedToFloat_arrL32( hMeta->directional_meta[dir].energy_ratio_fx[sf], hMeta->directional_meta[dir].energy_ratio[sf], Q30, MASA_FREQUENCY_BANDS ); - } - fixedToFloat_arrL32( hMeta->common_meta.diffuse_to_total_ratio_fx[sf], hMeta->common_meta.diffuse_to_total_ratio[sf], Q30, MASA_FREQUENCY_BANDS ); - } -#endif -#else - compensate_energy_ratios( hMasa ); -#endif - if ( Opt_DTX_ON ) + IF( Opt_DTX_ON ) { - if ( ( h_orig_metadata = (MASA_DIRECTIONAL_SPATIAL_META *) malloc( MASA_MAXIMUM_DIRECTIONS * sizeof( MASA_DIRECTIONAL_SPATIAL_META ) ) ) == NULL ) + IF( ( h_orig_metadata = (MASA_DIRECTIONAL_SPATIAL_META *) malloc( MASA_MAXIMUM_DIRECTIONS * sizeof( MASA_DIRECTIONAL_SPATIAL_META ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA encoder\n" ) ); } - for ( i = 0; i < MASA_MAXIMUM_DIRECTIONS; i++ ) + FOR( i = 0; i < MASA_MAXIMUM_DIRECTIONS; i++ ) { - for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - mvr2r( hMasa->masaMetadata.directional_meta[i].azimuth[j], h_orig_metadata[i].azimuth[j], MASA_FREQUENCY_BANDS ); - mvr2r( hMasa->masaMetadata.directional_meta[i].elevation[j], h_orig_metadata[i].elevation[j], MASA_FREQUENCY_BANDS ); - mvr2r( hMasa->masaMetadata.directional_meta[i].energy_ratio[j], h_orig_metadata[i].energy_ratio[j], MASA_FREQUENCY_BANDS ); - mvs2s( (int16_t *) ( hMasa->masaMetadata.directional_meta[i].spherical_index[j] ), (int16_t *) ( h_orig_metadata[i].spherical_index[j] ), MASA_FREQUENCY_BANDS ); + Copy32( hMasa->masaMetadata.directional_meta[i].azimuth_fx[j], h_orig_metadata[i].azimuth_fx[j], MASA_FREQUENCY_BANDS ); + Copy32( hMasa->masaMetadata.directional_meta[i].elevation_fx[j], h_orig_metadata[i].elevation_fx[j], MASA_FREQUENCY_BANDS ); + Copy32( hMasa->masaMetadata.directional_meta[i].energy_ratio_fx[j], h_orig_metadata[i].energy_ratio_fx[j], MASA_FREQUENCY_BANDS ); + Copy( (Word16 *) ( hMasa->masaMetadata.directional_meta[i].spherical_index[j] ), (Word16 *) ( h_orig_metadata[i].spherical_index[j] ), MASA_FREQUENCY_BANDS ); } } } - if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && ivas_total_brate >= IVAS_384k ) + test(); + test(); + if ( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) ) && GE_32( ivas_total_brate, IVAS_384k ) ) { hMasa->config.mergeRatiosOverSubframes = 0; + move16(); } /* Combine frequency bands and sub-frames */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - hMasa->data.q_energy = Q31; - guard_bits = find_guarded_bits_fx( 9 ); - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - hMasa->data.q_energy = s_min( hMasa->data.q_energy, L_get_q_buf1( hMasa->data.energy[i], MASA_FREQUENCY_BANDS ) ); - } - hMasa->data.q_energy -= guard_bits; - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - floatToFixed_arrL32( hMasa->data.energy[i], hMasa->data.energy_fx[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); - } - if ( hMasa->config.numCodingBands <= MAX_REDUCED_NBANDS ) - { - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - floatToFixed_arrL32( hMeta->directional_meta[i].azimuth[j], hMeta->directional_meta[i].azimuth_fx[j], Q22, MASA_FREQUENCY_BANDS ); - floatToFixed_arrL32( hMeta->directional_meta[i].elevation[j], hMeta->directional_meta[i].elevation_fx[j], Q22, MASA_FREQUENCY_BANDS ); - floatToFixed_arrL32( hMeta->directional_meta[i].energy_ratio[j], hMeta->directional_meta[i].energy_ratio_fx[j], Q30, MASA_FREQUENCY_BANDS ); - } - } - if ( hMasa->config.useCoherence && hMasa->config.coherencePresent ) - { - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - floatToFixed_arr( hMeta->directional_meta[i].spread_coherence[j], hMeta->directional_meta[i].spread_coherence_fx[j], Q15, MASA_FREQUENCY_BANDS ); - if ( i == 0 ) - { - floatToFixed_arr( hMeta->common_meta.surround_coherence[j], hMeta->common_meta.surround_coherence_fx[j], Q15, MASA_FREQUENCY_BANDS ); - } - } - } - } - } - if ( hMasa->config.mergeRatiosOverSubframes ) - { - if ( hMasa->config.useCoherence && hMasa->config.coherencePresent ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - floatToFixed_arr( hMeta->common_meta.surround_coherence[j], hMeta->common_meta.surround_coherence_fx[j], Q15, MASA_FREQUENCY_BANDS ); - } - } - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - floatToFixed_arrL32( hMeta->directional_meta[i].energy_ratio[j], hMeta->directional_meta[i].energy_ratio_fx[j], Q30, MASA_FREQUENCY_BANDS ); - } - } - } -#endif combine_freqbands_and_subframes_fx( hMasa ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - fixedToFloat_arrL32( hMasa->data.energy_fx[i], hMasa->data.energy[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); - } - if ( hMasa->config.numCodingBands <= MAX_REDUCED_NBANDS ) - { - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - fixedToFloat_arrL32( hMeta->directional_meta[i].azimuth_fx[j], hMeta->directional_meta[i].azimuth[j], Q22, MASA_FREQUENCY_BANDS ); - fixedToFloat_arrL32( hMeta->directional_meta[i].elevation_fx[j], hMeta->directional_meta[i].elevation[j], Q22, MASA_FREQUENCY_BANDS ); - fixedToFloat_arrL32( hMeta->directional_meta[i].energy_ratio_fx[j], hMeta->directional_meta[i].energy_ratio[j], Q30, MASA_FREQUENCY_BANDS ); - } - } - if ( hMasa->config.useCoherence && hMasa->config.coherencePresent ) - { - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - fixedToFloat_arr( hMeta->directional_meta[i].spread_coherence_fx[j], hMeta->directional_meta[i].spread_coherence[j], Q15, MASA_FREQUENCY_BANDS ); - if ( i == 0 ) - { - fixedToFloat_arr( hMeta->common_meta.surround_coherence_fx[j], hMeta->common_meta.surround_coherence[j], Q15, MASA_FREQUENCY_BANDS ); - } - } - } - } - } - if ( hMasa->config.mergeRatiosOverSubframes ) + } + + /* aligning the exponents of energy_fx */ + s = 0; + move16(); + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + maximum_s( hMasa->data.energy_e[i], MASA_FREQUENCY_BANDS, &tmp ); + s = s_max( s, tmp ); + } + s = add( s, guard_bits ); + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - if ( hMasa->config.useCoherence && hMasa->config.coherencePresent ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - fixedToFloat_arr( hMeta->common_meta.surround_coherence_fx[j], hMeta->common_meta.surround_coherence[j], Q15, MASA_FREQUENCY_BANDS ); - } - } - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - fixedToFloat_arrL32( hMeta->directional_meta[i].energy_ratio_fx[j], hMeta->directional_meta[i].energy_ratio[j], Q30, MASA_FREQUENCY_BANDS ); - } - } + hMasa->data.energy_fx[i][j] = L_shr( hMasa->data.energy_fx[i][j], sub( s, hMasa->data.energy_e[i][j] ) ); + hMasa->data.energy_e[i][j] = s; + move32(); + move16(); } -#endif -#else - combine_freqbands_and_subframes( hMasa ); -#endif } + hMasa->data.q_energy = sub( 31, s ); + move16(); - if ( hMasa->config.numberOfDirections == 2 && hMasa->config.numTwoDirBands < hMasa->config.numCodingBands && ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) ) + test(); + test(); + test(); + IF( EQ_16( hMasa->config.numberOfDirections, 2 ) && LT_16( hMasa->config.numTwoDirBands, hMasa->config.numCodingBands ) && ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) ) ) { - if ( ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE && ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) || ( ivas_format != MASA_ISM_FORMAT ) ) + test(); + test(); + test(); + IF( ( EQ_32( ivas_format, MASA_ISM_FORMAT ) && NE_32( ism_mode, ISM_MODE_NONE ) && NE_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) || NE_32( ivas_format, MASA_ISM_FORMAT ) ) { /* Combine directions */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 numCodingBands = hMasa->config.numCodingBands; - Word16 numDirections = hMasa->config.numberOfDirections; - Word16 numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - Word16 computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; - MASA_METADATA_HANDLE hMeta; - hMeta = &( hMasa->masaMetadata ); - for ( i = 0; i < numDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) - { - for ( int k = 0; k < hMasa->config.numCodingBands; k++ ) - { - hMeta->directional_meta[i].energy_ratio_fx[j][k] = floatToFixed( hMeta->directional_meta[i].energy_ratio[j][k], Q30 ); - hMeta->directional_meta[i].azimuth_fx[j][k] = floatToFixed( hMeta->directional_meta[i].azimuth[j][k], Q22 ); - hMeta->directional_meta[i].elevation_fx[j][k] = floatToFixed( hMeta->directional_meta[i].elevation[j][k], Q22 ); - } - } - } - /* Combine directions on the remaining bands */ - for ( i = 0; i < hMasa->config.numCodingBands; i++ ) - { - for ( j = 0; j < numSf; j++ ) - { - hMeta->directional_meta[0].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[0].spread_coherence[j][i], Q15 ); - hMeta->directional_meta[1].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[1].spread_coherence[j][i], Q15 ); - hMeta->common_meta.surround_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->common_meta.surround_coherence[j][i], Q15 ); - } - } - - /* Estimate the importance of having two directions instead of one */ - for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) - { - hMasa->data.importanceWeight_fx[i] = floatToFixed( hMasa->data.importanceWeight[i], Q30 ); - } -#endif - ivas_masa_combine_directions_fx( hMasa ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < numCodingBands; i++ ) - { - if ( hMasa->data.twoDirBands[i] == 0 ) - { - for ( j = 0; j < numSf; j++ ) - { - hMeta->directional_meta[0].azimuth[j][i] = fixedToFloat( hMeta->directional_meta[0].azimuth_fx[j][i], Q22 ); - hMeta->directional_meta[0].elevation[j][i] = fixedToFloat( hMeta->directional_meta[0].elevation_fx[j][i], Q22 ); - if ( computeCoherence ) - { - hMeta->directional_meta[0].spread_coherence[j][i] = fixedToFloat( hMeta->directional_meta[0].spread_coherence_fx[j][i], Q15 ); - hMeta->common_meta.surround_coherence[j][i] = fixedToFloat( hMeta->common_meta.surround_coherence_fx[j][i], Q15 ); - } - hMeta->directional_meta[0].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[0].energy_ratio_fx[j][i], Q30 ); - hMeta->directional_meta[1].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[1].energy_ratio_fx[j][i], Q30 ); - } - } - } -#endif -#else - ivas_masa_combine_directions( hMasa ); -#endif } /* If we joined all bands, then metadata is now one directional. */ - if ( hMasa->config.numTwoDirBands == 0 ) + IF( hMasa->config.numTwoDirBands == 0 ) { hMasa->config.numberOfDirections = 1; hMasa->masaMetadata.descriptive_meta.numberOfDirections = 0; hQMetaData->no_directions = 1; + move16(); + move16(); + move16(); } } /* Reset qmetadata bit budget */ hQMetaData->metadata_max_bits = hMasa->config.max_metadata_bits; - if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) + move16(); + test(); + IF( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { - if ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE ) + test(); + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && NE_32( ism_mode, ISM_MODE_NONE ) ) { /* write the number of objects in ISM_MASA format*/ - push_next_indice( hMetaData, nchan_ism - 1, NO_BITS_MASA_ISM_NO_OBJ ); - hQMetaData->metadata_max_bits -= NO_BITS_MASA_ISM_NO_OBJ; + push_next_indice( hMetaData, sub( nchan_ism, 1 ), NO_BITS_MASA_ISM_NO_OBJ ); + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, NO_BITS_MASA_ISM_NO_OBJ ); + move16(); /* write index of separated object if needed */ - if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ && nchan_ism > 1 ) + test(); + IF( EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) && GT_16( nchan_ism, 1 ) ) { push_next_indice( hMetaData, idx_separated_object, NO_BITS_MASA_ISM_NO_OBJ ); - hQMetaData->metadata_max_bits -= NO_BITS_MASA_ISM_NO_OBJ; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, NO_BITS_MASA_ISM_NO_OBJ ); + move16(); } /* write ISM importance flag (one per object) */ - if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + IF( EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { push_next_indice( hMetaData, hIsmMetaData[0]->ism_imp, ISM_METADATA_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_FLAG_BITS ); + move16(); } - else if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + ELSE IF( EQ_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - if ( hIsmMetaData[0]->ism_md_null_flag ) + IF( hIsmMetaData[0]->ism_md_null_flag ) { /* signal NULL metadata frame */ push_next_indice( hMetaData, 1, ISM_METADATA_MD_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_MD_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_MD_FLAG_BITS ); + move16(); /* write the ISM class to ISM_NO_META and again the true ISM class */ push_next_indice( hMetaData, ISM_NO_META, ISM_METADATA_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_FLAG_BITS ); + move16(); push_next_indice( hMetaData, hIsmMetaData[0]->ism_imp, ISM_METADATA_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_FLAG_BITS ); + move16(); } - else + ELSE { push_next_indice( hMetaData, hIsmMetaData[0]->ism_imp, ISM_METADATA_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_FLAG_BITS ); + move16(); - if ( hIsmMetaData[0]->ism_imp == ISM_NO_META ) + IF( EQ_16( hIsmMetaData[0]->ism_imp, ISM_NO_META ) ) { /* signal low-rate ISM_NO_META frame */ push_next_indice( hMetaData, 0, ISM_METADATA_MD_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_MD_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_MD_FLAG_BITS ); + move16(); /* signal presence of MD in low-rate ISM_NO_META frame */ push_next_indice( hMetaData, hIsmMetaData[0]->ism_md_lowrate_flag, ISM_METADATA_INACTIVE_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_INACTIVE_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_INACTIVE_FLAG_BITS ); + move16(); } } } - else if ( ism_mode == ISM_MASA_MODE_DISC ) + ELSE IF( EQ_32( ism_mode, ISM_MASA_MODE_DISC ) ) { - for ( i = 0; i < nchan_ism; i++ ) + FOR( i = 0; i < nchan_ism; i++ ) { - if ( hIsmMetaData[i]->ism_md_null_flag ) + IF( hIsmMetaData[i]->ism_md_null_flag ) { /* signal NULL metadata frame */ push_next_indice( hMetaData, 1, ISM_METADATA_MD_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_MD_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_MD_FLAG_BITS ); + move16(); /* write the ISM class to ISM_NO_META and again the true ISM class */ push_next_indice( hMetaData, ISM_NO_META, ISM_METADATA_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_FLAG_BITS ); + move16(); push_next_indice( hMetaData, hIsmMetaData[i]->ism_imp, ISM_METADATA_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_FLAG_BITS ); + move16(); } - else + ELSE { push_next_indice( hMetaData, hIsmMetaData[i]->ism_imp, ISM_METADATA_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_FLAG_BITS ); + move16(); - if ( hIsmMetaData[i]->ism_imp == ISM_NO_META ) + IF( EQ_16( hIsmMetaData[i]->ism_imp, ISM_NO_META ) ) { /* signal low-rate ISM_NO_META frame */ push_next_indice( hMetaData, 0, ISM_METADATA_MD_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_MD_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_MD_FLAG_BITS ); + move16(); /* signal presence of MD in low-rate ISM_NO_META frame */ push_next_indice( hMetaData, hIsmMetaData[i]->ism_md_lowrate_flag, ISM_METADATA_INACTIVE_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_INACTIVE_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_INACTIVE_FLAG_BITS ); + move16(); } } } - - if ( ivas_total_brate == IVAS_128k && nchan_ism >= 3 ) + test(); + IF( EQ_32( ivas_total_brate, IVAS_128k ) && GE_16( nchan_ism, 3 ) ) { push_next_indice( hMetaData, flag_omasa_ener_brate, 1 ); - hQMetaData->metadata_max_bits -= 1; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, 1 ); + move16(); } } } - else + ELSE { /* write the number of MASA transport channels */ - push_next_indice( hMetaData, nchan_transport - 1, MASA_TRANSP_BITS ); - hQMetaData->metadata_max_bits -= MASA_TRANSP_BITS; + push_next_indice( hMetaData, sub( nchan_transport, 1 ), MASA_TRANSP_BITS ); + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, MASA_TRANSP_BITS ); + move16(); } - if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MODE_NONE ) + test(); + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MODE_NONE ) ) { /* signal MASA_ISM_FORMAT to decoder */ push_next_indice( hMetaData, 1, 1 ); /* write reserved bit */ push_next_indice( hMetaData, 0, MASA_HEADER_BITS - 1 ); - hQMetaData->metadata_max_bits -= MASA_HEADER_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, MASA_HEADER_BITS ); + move16(); } - else + ELSE { /* the MASA_ISM_FORMAT is not signalled here */ /* write reserved bits */ push_next_indice( hMetaData, 0, MASA_HEADER_BITS ); - hQMetaData->metadata_max_bits -= MASA_HEADER_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, MASA_HEADER_BITS ); + move16(); } /* write number of directions */ - push_next_indice( hMetaData, hQMetaData->no_directions - 1, 1 ); - hQMetaData->metadata_max_bits -= 1; + push_next_indice( hMetaData, sub( hQMetaData->no_directions, 1 ), 1 ); + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, 1 ); + move16(); /* write subframe mode */ - push_next_indice( hMetaData, hQMetaData->q_direction[0].cfg.nblocks == 1 ? 1 : 0, MASA_SUBFRAME_BITS ); - hQMetaData->metadata_max_bits -= MASA_SUBFRAME_BITS; - } - - if ( ivas_format == MC_FORMAT ) - { - int16_t lfeBitsWritten; -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + IF( EQ_16( hQMetaData->q_direction[0].cfg.nblocks, 1 ) ) { - f2me( hMasa->data.lfeToTotalEnergyRatio[i], &hMasa->data.lfeToTotalEnergyRatio_fx[i], &hMasa->data.lfeToTotalEnergyRatio_e[i] ); + push_next_indice( hMetaData, 1, MASA_SUBFRAME_BITS ); } - hMasa->data.prevq_lfeToTotalEnergyRatio_fx = floatToFixed( hMasa->data.prevq_lfeToTotalEnergyRatio, Q31 ); -#endif - lfeBitsWritten = encode_lfe_to_total_energy_ratio_fx( hMasa, hMetaData, ivas_total_brate ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hMasa->data.prevq_lfeToTotalEnergyRatio = fixedToFloat( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, Q31 ); -#endif -#else - lfeBitsWritten = encode_lfe_to_total_energy_ratio( hMasa, hMetaData, ivas_total_brate ); -#endif - hQMetaData->metadata_max_bits -= lfeBitsWritten; + ELSE + { + push_next_indice( hMetaData, 0, MASA_SUBFRAME_BITS ); + } + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, MASA_SUBFRAME_BITS ); + move16(); } -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // Word16 numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - hMasa->data.q_energy = Q31; - guard_bits = find_guarded_bits_fx( 9 ); - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - hMasa->data.q_energy = s_min( hMasa->data.q_energy, L_get_q_buf1( hMasa->data.energy[i], MASA_FREQUENCY_BANDS ) ); - } - hMasa->data.q_energy -= guard_bits; - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - floatToFixed_arrL32( hMasa->data.energy[i], hMasa->data.energy_fx[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); - } - for ( int16_t d = 0; d < hQMetaData->no_directions; d++ ) + + IF( EQ_32( ivas_format, MC_FORMAT ) ) { - for ( i = hQMetaData->q_direction[d].cfg.start_band; i < hQMetaData->q_direction[d].cfg.nbands; i++ ) - { - for ( j = 0; j < hQMetaData->q_direction[d].cfg.nblocks; j++ ) - { - hQMetaData->q_direction[d].band_data[i].elevation_fx[j] = float_to_fix( hQMetaData->q_direction[d].band_data[i].elevation[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].azimuth_fx[j] = float_to_fix( hQMetaData->q_direction[d].band_data[i].azimuth[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].energy_ratio_fx[j] = floatToFixed( hQMetaData->q_direction[d].band_data[i].energy_ratio[j], Q30 ); - } - } + Word16 lfeBitsWritten; + + lfeBitsWritten = encode_lfe_to_total_energy_ratio_fx( hMasa, hMetaData, ivas_total_brate ); + + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, lfeBitsWritten ); + move16(); } -#endif + /* Move data from encoder to qmetadata */ test(); IF( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { move_metadata_to_qmetadata_fx( hMasa, hQMetaData ); } -#else - /* Move data from encoder to qmetadata */ - if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) - { - move_metadata_to_qmetadata( hMasa, hQMetaData ); - } -#endif -#ifdef IVAS_FLOAT_FIXED test(); - IF( hMasa->config.max_metadata_bits < MINIMUM_BIT_BUDGET_NORMAL_META && !hMasa->config.joinedSubframes ) + IF( LT_16( hMasa->config.max_metadata_bits, MINIMUM_BIT_BUDGET_NORMAL_META ) && !hMasa->config.joinedSubframes ) { reduce_metadata_further_fx( hMasa, hQMetaData, ivas_format ); low_bitrate_mode = (Word16) LE_32( ivas_total_brate, 32000 ); /* Write low bitrate mode. 1 signals that we have merged through time, 0 signals merge through frequency. */ - push_next_indice( hMetaData, hQMetaData->q_direction[0].cfg.nblocks == 1 ? 1 : 0, MASA_LOWBITRATE_MODE_BITS ); - hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, MASA_LOWBITRATE_MODE_BITS ); - } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - fixedToFloat_arrL32( hMasa->data.energy_fx[i], hMasa->data.energy[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); - } - for ( int16_t d = 0; d < hQMetaData->no_directions; d++ ) - { - for ( i = hQMetaData->q_direction[d].cfg.start_band; i < hQMetaData->q_direction[d].cfg.nbands; i++ ) + IF( EQ_16( hQMetaData->q_direction[0].cfg.nblocks, 1 ) ) { - for ( j = 0; j < hQMetaData->q_direction[d].cfg.nblocks; j++ ) - { - hQMetaData->q_direction[d].band_data[i].elevation[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].elevation_fx[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].azimuth[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].azimuth_fx[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].energy_ratio[j] = fixedToFloat( hQMetaData->q_direction[d].band_data[i].energy_ratio_fx[j], Q30 ); - } + push_next_indice( hMetaData, 1, MASA_LOWBITRATE_MODE_BITS ); } + ELSE + { + push_next_indice( hMetaData, 0, MASA_LOWBITRATE_MODE_BITS ); + } + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, MASA_LOWBITRATE_MODE_BITS ); + move16(); } -#endif -#else - if ( hMasa->config.max_metadata_bits < MINIMUM_BIT_BUDGET_NORMAL_META && !hMasa->config.joinedSubframes ) - { - reduce_metadata_further( hMasa, hQMetaData, ivas_format ); - - low_bitrate_mode = ( ivas_total_brate <= 32000 ); - /* Write low bitrate mode. 1 signals that we have merged through time, 0 signals merge through frequency. */ - push_next_indice( hMetaData, hQMetaData->q_direction[0].cfg.nblocks == 1 ? 1 : 0, MASA_LOWBITRATE_MODE_BITS ); - hQMetaData->metadata_max_bits -= MASA_LOWBITRATE_MODE_BITS; - } -#endif /* Encode MASA+ISM metadata */ - if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + test(); + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { /* encode MASA/ISM energy ratios */ - ivas_encode_masaism_metadata( hMasa, hQMetaData, hMetaData, hIsmMetaData, nchan_ism, low_bitrate_mode, hOMasa->nCodingBands, hOMasa->nSubframes, idx_separated_object, ism_imp ); + ivas_encode_masaism_metadata_fx( hMasa, hQMetaData, hMetaData, hIsmMetaData, nchan_ism, low_bitrate_mode, hOMasa->nCodingBands, hOMasa->nSubframes, idx_separated_object, ism_imp ); } - else + ELSE { - if ( ivas_format == MASA_ISM_FORMAT ) + if ( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { - hMasa->data.hOmasaData->masa_to_total_energy_ratio[0][0] = -1; /* signals NOT to adjust the energy ratios */ + hMasa->data.hOmasaData->masa_to_total_energy_ratio_fx[0][0] = -ONE_IN_Q30; /* signals NOT to adjust the energy ratios */ + move32(); } } /* Encode metadata */ masa_total_brate = ivas_total_brate; -#ifndef IVAS_FLOAT_FIXED - if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_DISC ) - { - masa_total_brate = calculate_cpe_brate_MASA_ISM( ism_mode, ivas_total_brate, nchan_ism ); - } -#else + move32(); test(); IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MASA_MODE_DISC ) ) { masa_total_brate = calculate_cpe_brate_MASA_ISM_fx( ism_mode, ivas_total_brate, nchan_ism ); } -#endif IF( GE_32( masa_total_brate, IVAS_384k ) ) { -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int16_t d = 0; d < hQMetaData->no_directions; d++ ) - { - for ( i = hQMetaData->q_direction[d].cfg.start_band; i < hQMetaData->q_direction[d].cfg.nbands; i++ ) - { - for ( j = 0; j < hQMetaData->q_direction[d].cfg.nblocks; j++ ) - { - hQMetaData->q_direction[d].band_data[i].elevation_fx[j] = float_to_fix( hQMetaData->q_direction[d].band_data[i].elevation[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].azimuth_fx[j] = float_to_fix( hQMetaData->q_direction[d].band_data[i].azimuth[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].energy_ratio_fx[j] = floatToFixed( hQMetaData->q_direction[d].band_data[i].energy_ratio[j], Q30 ); - } - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS IF( GE_32( masa_total_brate, IVAS_512k ) ) { IF( NE_32( ( error = ivas_qmetadata_enc_encode_hr_384_512_fx( hMetaData, hQMetaData, 16, 4 ) ), IVAS_ERR_OK ) ) @@ -906,110 +753,13 @@ ivas_error ivas_masa_encode( return error; } } - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int16_t d = 0; d < hQMetaData->no_directions; d++ ) - { - for ( i = hQMetaData->q_direction[d].cfg.start_band; i < hQMetaData->q_direction[d].cfg.nbands; i++ ) - { - for ( j = 0; j < hQMetaData->q_direction[d].cfg.nblocks; j++ ) - { - hQMetaData->q_direction[d].band_data[i].elevation[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].elevation_fx[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].azimuth[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].azimuth_fx[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].energy_ratio[j] = fixedToFloat( hQMetaData->q_direction[d].band_data[i].energy_ratio_fx[j], Q30 ); - } - } - } - if ( masa_total_brate >= IVAS_512k ) - { - for ( int16_t d = 0; d < hQMetaData->no_directions; d++ ) - { - for ( i = hQMetaData->q_direction[d].cfg.start_band; i < hQMetaData->q_direction[d].cfg.nbands; i++ ) - { - for ( j = 0; j < hQMetaData->q_direction[d].cfg.nblocks; j++ ) - { - hQMetaData->q_direction[d].band_data[i].q_elevation[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].q_elevation_fx[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].q_azimuth[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].q_azimuth_fx[j], Q22 ); - } - } - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS - -#else - if ( masa_total_brate >= IVAS_512k ) - { - if ( ( error = ivas_qmetadata_enc_encode_hr_384_512( hMetaData, hQMetaData, 16, 4 ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else - { - if ( ( error = ivas_qmetadata_enc_encode_hr_384_512( hMetaData, hQMetaData, 11, 3 ) ) != IVAS_ERR_OK ) - { - return error; - } - } -#endif } - else + ELSE { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < hQMetaData->no_directions; i++ ) - { - for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) - { - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].azimuth, hQMetaData->q_direction[i].band_data[j].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].elevation, hQMetaData->q_direction[i].band_data[j].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth, hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation, hQMetaData->q_direction[i].band_data[j].q_elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } -#endif - if ( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, 0 ) ), IVAS_ERR_OK ) ) { return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < hQMetaData->no_directions; i++ ) - { - for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) - { - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, hQMetaData->q_direction[i].band_data[j].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - /*fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].azimuth_fx, hQMetaData->q_direction[i].band_data[j].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].elevation_fx, hQMetaData->q_direction[i].band_data[j].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES );*/ - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, hQMetaData->q_direction[i].band_data[j].q_azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation_fx, hQMetaData->q_direction[i].band_data[j].q_elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } -#endif - } - -#ifndef IVAS_FLOAT_FIXED - if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) - { - /* Modify spatial metadata based on the MASA-to-total energy ratios */ - ivas_omasa_modify_masa_energy_ratios( hQMetaData, hMasa->data.hOmasaData->masa_to_total_energy_ratio ); - } -#else - Word16 b, d; - - IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) - { - for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) - { - for ( d = 0; d < hQMetaData->no_directions; d++ ) - { - floatToFixed_arr32( hQMetaData->q_direction[d].band_data[b].energy_ratio, hQMetaData->q_direction[d].band_data[b].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - - for ( b = 0; b < MAX_PARAM_SPATIAL_SUBFRAMES; ++b ) - { - floatToFixed_arr32( hMasa->data.hOmasaData->masa_to_total_energy_ratio[b], hMasa->data.hOmasaData->masa_to_total_energy_ratio_fx[b], Q30, MASA_MAXIMUM_CODING_SUBBANDS ); - } } test(); @@ -1019,293 +769,80 @@ ivas_error ivas_masa_encode( ivas_omasa_modify_masa_energy_ratios_fx( hQMetaData, hMasa->data.hOmasaData->masa_to_total_energy_ratio_fx ); } - IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) - { - for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) - { - for ( d = 0; d < hQMetaData->no_directions; d++ ) - { - fixedToFloat_arrL( hQMetaData->q_direction[d].band_data[b].energy_ratio_fx, hQMetaData->q_direction[d].band_data[b].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - } -#endif - *nb_bits_metadata = hMetaData->nb_bits_tot; + move16(); - if ( ivas_format == MASA_FORMAT && Opt_DTX_ON ) + test(); + IF( EQ_32( ivas_format, MASA_FORMAT ) && Opt_DTX_ON ) { /* save old values */ - uint8_t numCodingBands = hMasa->config.numCodingBands; - uint8_t numTwoDirBands = hMasa->config.numTwoDirBands; - int16_t nbands = hQMetaData->q_direction[0].cfg.nbands; - uint8_t numberOfDirections = hMasa->config.numberOfDirections; - uint8_t numberOfDirectionsMeta = hMasa->masaMetadata.descriptive_meta.numberOfDirections; - uint16_t numberOfDirectionsQMetaData = hQMetaData->no_directions; + UWord8 numCodingBands = hMasa->config.numCodingBands; + UWord8 numTwoDirBands = hMasa->config.numTwoDirBands; + Word16 nbands = hQMetaData->q_direction[0].cfg.nbands; + UWord8 numberOfDirections = hMasa->config.numberOfDirections; + UWord8 numberOfDirectionsMeta = hMasa->masaMetadata.descriptive_meta.numberOfDirections; + UWord16 numberOfDirectionsQMetaData = hQMetaData->no_directions; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); - if ( !( hMasa->config.numberOfDirections == 1 && hQMetaData->q_direction->cfg.nbands == 5 ) ) + test(); + IF( !( EQ_16( hMasa->config.numberOfDirections, 1 ) && EQ_16( hQMetaData->q_direction->cfg.nbands, 5 ) ) ) { - for ( i = 0; i < MASA_MAXIMUM_DIRECTIONS; i++ ) + FOR( i = 0; i < MASA_MAXIMUM_DIRECTIONS; i++ ) { - for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - mvr2r( h_orig_metadata[i].azimuth[j], hMasa->masaMetadata.directional_meta[i].azimuth[j], MASA_FREQUENCY_BANDS ); - mvr2r( h_orig_metadata[i].elevation[j], hMasa->masaMetadata.directional_meta[i].elevation[j], MASA_FREQUENCY_BANDS ); - mvr2r( h_orig_metadata[i].energy_ratio[j], hMasa->masaMetadata.directional_meta[i].energy_ratio[j], MASA_FREQUENCY_BANDS ); + Copy32( h_orig_metadata[i].azimuth_fx[j], hMasa->masaMetadata.directional_meta[i].azimuth_fx[j], MASA_FREQUENCY_BANDS ); + Copy32( h_orig_metadata[i].elevation_fx[j], hMasa->masaMetadata.directional_meta[i].elevation_fx[j], MASA_FREQUENCY_BANDS ); + Copy32( h_orig_metadata[i].energy_ratio_fx[j], hMasa->masaMetadata.directional_meta[i].energy_ratio_fx[j], MASA_FREQUENCY_BANDS ); } } /* Force to have 5 bands and 1 direction */ hMasa->config.numCodingBands = 5; hMasa->config.numTwoDirBands = 0; -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - MASA_METADATA_HANDLE hMeta = &( hMasa->masaMetadata ); - Word16 numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - hMasa->data.q_energy = Q31; - guard_bits = find_guarded_bits_fx( 9 ); - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - hMasa->data.q_energy = s_min( hMasa->data.q_energy, L_get_q_buf1( hMasa->data.energy[i], MASA_FREQUENCY_BANDS ) ); - } - hMasa->data.q_energy -= guard_bits; - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - floatToFixed_arrL32( hMasa->data.energy[i], hMasa->data.energy_fx[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); - } - if ( hMasa->config.numCodingBands <= MAX_REDUCED_NBANDS ) - { - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - floatToFixed_arrL32( hMeta->directional_meta[i].azimuth[j], hMeta->directional_meta[i].azimuth_fx[j], Q22, MASA_FREQUENCY_BANDS ); - floatToFixed_arrL32( hMeta->directional_meta[i].elevation[j], hMeta->directional_meta[i].elevation_fx[j], Q22, MASA_FREQUENCY_BANDS ); - floatToFixed_arrL32( hMeta->directional_meta[i].energy_ratio[j], hMeta->directional_meta[i].energy_ratio_fx[j], Q30, MASA_FREQUENCY_BANDS ); - } - } - if ( hMasa->config.useCoherence && hMasa->config.coherencePresent ) - { - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - floatToFixed_arr( hMeta->directional_meta[i].spread_coherence[j], hMeta->directional_meta[i].spread_coherence_fx[j], Q15, MASA_FREQUENCY_BANDS ); - if ( i == 0 ) - { - floatToFixed_arr( hMeta->common_meta.surround_coherence[j], hMeta->common_meta.surround_coherence_fx[j], Q15, MASA_FREQUENCY_BANDS ); - } - } - } - } - } - if ( hMasa->config.mergeRatiosOverSubframes ) - { - if ( hMasa->config.useCoherence && hMasa->config.coherencePresent ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - floatToFixed_arr( hMeta->common_meta.surround_coherence[j], hMeta->common_meta.surround_coherence_fx[j], Q15, MASA_FREQUENCY_BANDS ); - } - } - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - floatToFixed_arrL32( hMeta->directional_meta[i].energy_ratio[j], hMeta->directional_meta[i].energy_ratio_fx[j], Q30, MASA_FREQUENCY_BANDS ); - } - } - } -#endif + move16(); + move16(); + combine_freqbands_and_subframes_fx( hMasa ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - fixedToFloat_arrL32( hMasa->data.energy_fx[i], hMasa->data.energy[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); - } - if ( hMasa->config.numCodingBands <= MAX_REDUCED_NBANDS ) - { - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - fixedToFloat_arrL32( hMeta->directional_meta[i].azimuth_fx[j], hMeta->directional_meta[i].azimuth[j], Q22, MASA_FREQUENCY_BANDS ); - fixedToFloat_arrL32( hMeta->directional_meta[i].elevation_fx[j], hMeta->directional_meta[i].elevation[j], Q22, MASA_FREQUENCY_BANDS ); - fixedToFloat_arrL32( hMeta->directional_meta[i].energy_ratio_fx[j], hMeta->directional_meta[i].energy_ratio[j], Q30, MASA_FREQUENCY_BANDS ); - } - } - if ( hMasa->config.useCoherence && hMasa->config.coherencePresent ) - { - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - fixedToFloat_arr( hMeta->directional_meta[i].spread_coherence_fx[j], hMeta->directional_meta[i].spread_coherence[j], Q15, MASA_FREQUENCY_BANDS ); - if ( i == 0 ) - { - fixedToFloat_arr( hMeta->common_meta.surround_coherence_fx[j], hMeta->common_meta.surround_coherence[j], Q15, MASA_FREQUENCY_BANDS ); - } - } - } - } - } - if ( hMasa->config.mergeRatiosOverSubframes ) - { - if ( hMasa->config.useCoherence && hMasa->config.coherencePresent ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - fixedToFloat_arr( hMeta->common_meta.surround_coherence_fx[j], hMeta->common_meta.surround_coherence[j], Q15, MASA_FREQUENCY_BANDS ); - } - } - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - fixedToFloat_arrL32( hMeta->directional_meta[i].energy_ratio_fx[j], hMeta->directional_meta[i].energy_ratio[j], Q30, MASA_FREQUENCY_BANDS ); - } - } - } -#endif -#else - combine_freqbands_and_subframes( hMasa ); -#endif + hQMetaData->q_direction[0].cfg.nbands = 5; + move16(); - if ( hMasa->config.numberOfDirections == 2 && hMasa->config.numTwoDirBands < hMasa->config.numCodingBands ) + test(); + IF( EQ_16( hMasa->config.numberOfDirections, 2 ) && LT_16( hMasa->config.numTwoDirBands, hMasa->config.numCodingBands ) ) { /* Combine directions */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - numCodingBands = hMasa->config.numCodingBands; - Word16 numDirections = hMasa->config.numberOfDirections; - numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - Word16 computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; - hMeta = &( hMasa->masaMetadata ); - for ( i = 0; i < numDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) - { - for ( int k = 0; k < hMasa->config.numCodingBands; k++ ) - { - hMeta->directional_meta[i].energy_ratio_fx[j][k] = floatToFixed( hMeta->directional_meta[i].energy_ratio[j][k], Q30 ); - hMeta->directional_meta[i].azimuth_fx[j][k] = floatToFixed( hMeta->directional_meta[i].azimuth[j][k], Q22 ); - hMeta->directional_meta[i].elevation_fx[j][k] = floatToFixed( hMeta->directional_meta[i].elevation[j][k], Q22 ); - } - } - } - /* Combine directions on the remaining bands */ - for ( i = 0; i < hMasa->config.numCodingBands; i++ ) - { - for ( j = 0; j < numSf; j++ ) - { - hMeta->directional_meta[0].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[0].spread_coherence[j][i], Q15 ); - hMeta->directional_meta[1].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[1].spread_coherence[j][i], Q15 ); - hMeta->common_meta.surround_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->common_meta.surround_coherence[j][i], Q15 ); - } - } - - /* Estimate the importance of having two directions instead of one */ - for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) - { - hMasa->data.importanceWeight_fx[i] = floatToFixed( hMasa->data.importanceWeight[i], Q30 ); - } -#endif ivas_masa_combine_directions_fx( hMasa ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < numCodingBands; i++ ) - { - if ( hMasa->data.twoDirBands[i] == 0 ) - { - for ( j = 0; j < numSf; j++ ) - { - hMeta->directional_meta[0].azimuth[j][i] = fixedToFloat( hMeta->directional_meta[0].azimuth_fx[j][i], Q22 ); - hMeta->directional_meta[0].elevation[j][i] = fixedToFloat( hMeta->directional_meta[0].elevation_fx[j][i], Q22 ); - if ( computeCoherence ) - { - hMeta->directional_meta[0].spread_coherence[j][i] = fixedToFloat( hMeta->directional_meta[0].spread_coherence_fx[j][i], Q15 ); - hMeta->common_meta.surround_coherence[j][i] = fixedToFloat( hMeta->common_meta.surround_coherence_fx[j][i], Q15 ); - } - hMeta->directional_meta[0].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[0].energy_ratio_fx[j][i], Q30 ); - hMeta->directional_meta[1].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[1].energy_ratio_fx[j][i], Q30 ); - } - } - } -#endif -#else - ivas_masa_combine_directions( hMasa ); -#endif - /* If we joined all bands, then metadata is now one directional. */ - if ( hMasa->config.numTwoDirBands == 0 ) + IF( hMasa->config.numTwoDirBands == 0 ) { hMasa->config.numberOfDirections = 1; hMasa->masaMetadata.descriptive_meta.numberOfDirections = 0; hQMetaData->no_directions = 1; + move16(); + move16(); + move16(); } } -#ifdef IVAS_FLOAT_FIXED move_metadata_to_qmetadata_fx( hMasa, hQMetaData ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( d = 0; d < hQMetaData->no_directions; d++ ) - { - for ( i = hQMetaData->q_direction[d].cfg.start_band; i < hQMetaData->q_direction[d].cfg.nbands; i++ ) - { - for ( j = 0; j < hQMetaData->q_direction[d].cfg.nblocks; j++ ) - { - hQMetaData->q_direction[d].band_data[i].elevation[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].elevation_fx[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].azimuth[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].azimuth_fx[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].energy_ratio[j] = fixedToFloat( hQMetaData->q_direction[d].band_data[i].energy_ratio_fx[j], Q30 ); - } - } - } -#endif -#else - move_metadata_to_qmetadata( hMasa, hQMetaData ); -#endif - FOR( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { -#ifdef IVAS_FLOAT_FIXED - /*=====================================flt-2-fix============================================*/ - hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] = floatToFixed( hQMetaData->q_direction[0].band_data[j].energy_ratio[0], Q30 ); - /*=====================================flt-2-fix============================================*/ - hQMetaData->q_direction[0].band_data[j].energy_ratio_index[0] = masa_sq_fx( L_sub( ONE_IN_Q30, hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); -#else - hQMetaData->q_direction[0].band_data[j].energy_ratio_index[0] = masa_sq( 1.0f - hQMetaData->q_direction[0].band_data[j].energy_ratio[0], diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); -#endif + move32(); } } free( h_orig_metadata ); -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IVAS_QDIRECTION *q_direction; - q_direction = &( hQMetaData->q_direction[0] ); - FOR( b = 0; b < q_direction->cfg.nbands; b++ ) - { - FOR( int m = 0; m < q_direction->cfg.nblocks; m++ ) - { - q_direction->band_data[b].azimuth_fx[m] = floatToFixed( q_direction->band_data[b].azimuth[m], Q22 ); - q_direction->band_data[b].elevation_fx[m] = floatToFixed( q_direction->band_data[b].elevation[m], Q22 ); - } - } -#endif + ivas_qmetadata_enc_sid_encode_fx( hMetaData, hQMetaData, masa_sid_descriptor, ivas_format ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( b = 0; b < q_direction->cfg.nbands; b++ ) - { - q_direction->band_data[b].q_azimuth[0] = fixedToFloat( q_direction->band_data[b].q_azimuth_fx[0], Q22 ); - q_direction->band_data[b].q_elevation[0] = fixedToFloat( q_direction->band_data[b].q_elevation_fx[0], Q22 ); - } -#endif -#else - ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, masa_sid_descriptor, ivas_format ); -#endif /* restore old values */ hMasa->config.numCodingBands = numCodingBands; @@ -1314,7 +851,23 @@ ivas_error ivas_masa_encode( hMasa->config.numberOfDirections = numberOfDirections; hMasa->masaMetadata.descriptive_meta.numberOfDirections = numberOfDirectionsMeta; hQMetaData->no_directions = numberOfDirectionsQMetaData; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + } + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < hQMetaData->no_directions; i++ ) + { + for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) + { + fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, hQMetaData->q_direction[i].band_data[j].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } } +#endif return IVAS_ERR_OK; } @@ -1683,8 +1236,113 @@ ivas_error ivas_masa_encode( return IVAS_ERR_OK; } #endif +#ifdef IVAS_FLOAT_FIXED +/*-----------------------------------------------------------------------* + * ivas_masa_estimate_energy_fx() + * + * + *-----------------------------------------------------------------------*/ + +void ivas_masa_estimate_energy_fx( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ + Word32 *data_fx[], /* i : Input audio channels Q(q_data) */ + const Word16 input_frame, /* i : frame length */ + const Word16 nchan_transport, /* i : number of MASA input/transport channels */ + Word16 q_data /* i : q for data_fx */ +) +{ + Word32 Input_RealBuffer[MASA_MAX_TRANSPORT_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word32 Input_ImagBuffer[MASA_MAX_TRANSPORT_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word16 block_m_idx, band_m_idx; + Word16 mrange[2], brange[2]; + Word16 i, j, ts, l_ts, maxBin; + Word64 energy_fx_temp[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 scale = 63; + move16(); + Word16 q_buf; + maxBin = extract_l( Mpy_32_32( 134217728 /*CLDFB_NO_CHANNELS_MAX / L_FRAME48k in Q31*/, input_frame ) ); + l_ts = idiv1616( input_frame, CLDFB_NO_COL_MAX ); + + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + energy_fx_temp[i][j] = 0; + move64(); + } + } + + FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + { + mrange[0] = hMasa->config.block_grouping[block_m_idx]; + move16(); + mrange[1] = hMasa->config.block_grouping[block_m_idx + 1]; + move16(); + set_zero_fx( hMasa->data.energy_fx[block_m_idx], MASA_FREQUENCY_BANDS ); + set16_fx( hMasa->data.energy_e[block_m_idx], 0, MASA_FREQUENCY_BANDS ); + + FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) + { + FOR( i = 0; i < nchan_transport; i++ ) + { + q_buf = q_data; + move16(); + cldfbAnalysis_ts_fx_fixed_q( &( data_fx[i][l_ts * ts] ), Input_RealBuffer[i], Input_ImagBuffer[i], l_ts, hMasa->data.cldfbAnaEnc[i], &q_buf ); // (q_data - 5) for Input_RealBuffer[i], Input_ImagBuffer[i] + } + + FOR( band_m_idx = 0; band_m_idx < MASA_FREQUENCY_BANDS; band_m_idx++ ) + { + brange[0] = hMasa->config.band_grouping[band_m_idx]; + move16(); + brange[1] = hMasa->config.band_grouping[band_m_idx + 1]; + move16(); + + FOR( i = 0; i < nchan_transport; i++ ) + { + IF( GT_16( brange[0], maxBin ) ) + { + hMasa->data.energy_fx[block_m_idx][band_m_idx] = 0; + move32(); + CONTINUE; + } + ELSE IF( GE_16( brange[1], maxBin ) ) + { + brange[1] = maxBin; + move16(); + } + + FOR( j = brange[0]; j < brange[1]; j++ ) + { + energy_fx_temp[block_m_idx][band_m_idx] = W_add( energy_fx_temp[block_m_idx][band_m_idx], W_mac_32_32( W_mult_32_32( Input_RealBuffer[i][j], Input_RealBuffer[i][j] ), Input_ImagBuffer[i][j], Input_ImagBuffer[i][j] ) ); // Q: 2 * (q_data - 5) + 1 for energy_fx_temp + move64(); + } + IF( energy_fx_temp[block_m_idx][band_m_idx] != 0 ) + { + scale = s_min( scale, W_norm( energy_fx_temp[block_m_idx][band_m_idx] ) ); // scale calculates minimum shift can be done across a buffer + } + } + } + } + } + FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + { + FOR( band_m_idx = 0; band_m_idx < MASA_FREQUENCY_BANDS; band_m_idx++ ) + { + energy_fx_temp[block_m_idx][band_m_idx] = W_shl( energy_fx_temp[block_m_idx][band_m_idx], scale ); // Q: 2 * (q_data - 5) + 1 + scale + move64(); + hMasa->data.energy_fx[block_m_idx][band_m_idx] = W_extract_h( energy_fx_temp[block_m_idx][band_m_idx] ); // Q: 2 * (q_data - 5) + 1 + scale - 32 + move32(); + hMasa->data.energy_e[block_m_idx][band_m_idx] = sub( 31, add( add( imult1616( 2, q_data ), scale ), 1 - 10 - 32 ) ); + move16(); + } + } + hMasa->data.q_energy = add( add( imult1616( 2, q_data ), scale ), 1 - 10 - 32 ); + move16(); + return; +} +#else /*-----------------------------------------------------------------------* * ivas_masa_estimate_energy() * @@ -1750,6 +1408,7 @@ void ivas_masa_estimate_energy( return; } +#endif /*-----------------------------------------------------------------------* @@ -1758,1234 +1417,1113 @@ void ivas_masa_estimate_energy( * Frame-by-frame configuration of MASA encoder *-----------------------------------------------------------------------*/ -ivas_error ivas_masa_enc_config( +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_masa_enc_config_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { - int16_t i; + Word16 i; MASA_ENCODER_HANDLE hMasa; IVAS_QMETADATA_HANDLE hQMetaData; IVAS_FORMAT ivas_format; - uint8_t joinedSubframes; - uint8_t coherencePresent; - uint8_t isActualTwoDir; /* Flag to tell that when there are two directions present in metadata, they both contain meaningful information. */ - int32_t ivas_total_brate; - uint8_t maxBand; - int16_t maxBin, sf; + UWord8 joinedSubframes; + UWord8 coherencePresent; + UWord8 isActualTwoDir; /* Flag to tell that when there are two directions present in metadata, they both contain meaningful information. */ + Word32 ivas_total_brate; + UWord8 maxBand; + Word16 maxBin, sf; ivas_error error; - int32_t ism_total_brate; - int32_t masa_total_brate; + Word32 ism_total_brate; + Word32 masa_total_brate; error = IVAS_ERR_OK; + move16(); hMasa = st_ivas->hMasa; hQMetaData = st_ivas->hQMetaData; ivas_format = st_ivas->hEncoderConfig->ivas_format; ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + move16(); + move32(); ism_total_brate = 0; - if ( ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) + move32(); + test(); + test(); + test(); + test(); + IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) && st_ivas->nSCE > 0 && ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) { - for ( i = 0; i < st_ivas->nSCE; i++ ) + FOR( i = 0; i < st_ivas->nSCE; i++ ) { - ism_total_brate += st_ivas->hSCE[i]->element_brate; + ism_total_brate = L_add( ism_total_brate, st_ivas->hSCE[i]->element_brate ); } } -#ifndef IVAS_FLOAT_FIXED - ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, hQMetaData, &st_ivas->hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, ivas_format, st_ivas->ism_mode, ism_total_brate ); -#else ivas_masa_set_elements_fx( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, hQMetaData, &st_ivas->hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, ivas_format, st_ivas->ism_mode, ism_total_brate ); -#endif hQMetaData->is_masa_ivas_format = 1; + move16(); - if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) + test(); + test(); + IF( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - floatToFixed_arr32( hMasa->data.dir_align_state.previous_ele_dir1, hMasa->data.dir_align_state.previous_ele_dir1_fx, Q22, MASA_FREQUENCY_BANDS ); - floatToFixed_arr32( hMasa->data.dir_align_state.previous_ele_dir2, hMasa->data.dir_align_state.previous_ele_dir2_fx, Q22, MASA_FREQUENCY_BANDS ); - floatToFixed_arr32( hMasa->data.dir_align_state.previous_azi_dir1, hMasa->data.dir_align_state.previous_azi_dir1_fx, Q22, MASA_FREQUENCY_BANDS ); - floatToFixed_arr32( hMasa->data.dir_align_state.previous_azi_dir2, hMasa->data.dir_align_state.previous_azi_dir2_fx, Q22, MASA_FREQUENCY_BANDS ); - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + masa_metadata_direction_alignment_fx( hMasa ); + + detect_framing_async_fx( hMasa ); /* detect the offset, set 1sf/4sf mode based on this. potentially also shift the metadata using a history buffer */ + test(); + IF( EQ_16( hMasa->data.sync_state.frame_mode, MASA_FRAME_1SF ) && hMasa->data.sync_state.prev_offset != 0 ) { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + /* average over sub-frames */ + IF( EQ_32( ivas_total_brate, IVAS_512k ) ) + { + average_masa_metadata_fx( &( hMasa->masaMetadata ), hMasa->data.energy_fx, hMasa->data.energy_e, &( hMasa->data.Sph_Grid16 ), TRUE ); + } + ELSE { - hMasa->masaMetadata.directional_meta[0].azimuth_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[0].azimuth[i][j], Q22 ); - hMasa->masaMetadata.directional_meta[0].elevation_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[0].elevation[i][j], Q22 ); - hMasa->masaMetadata.directional_meta[0].energy_ratio_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[0].energy_ratio[i][j], Q30 ); - hMasa->masaMetadata.directional_meta[0].spread_coherence_fx[i][j] = float_to_fix16( hMasa->masaMetadata.directional_meta[0].spread_coherence[i][j], Q15 ); - hMasa->masaMetadata.directional_meta[1].azimuth_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[1].azimuth[i][j], Q22 ); - hMasa->masaMetadata.directional_meta[1].elevation_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[1].elevation[i][j], Q22 ); - hMasa->masaMetadata.directional_meta[1].energy_ratio_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[1].energy_ratio[i][j], Q30 ); - hMasa->masaMetadata.directional_meta[1].spread_coherence_fx[i][j] = float_to_fix16( hMasa->masaMetadata.directional_meta[1].spread_coherence[i][j], Q15 ); + average_masa_metadata_fx( &( hMasa->masaMetadata ), hMasa->data.energy_fx, hMasa->data.energy_e, &( hMasa->data.Sph_Grid16 ), FALSE ); } } -#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED - masa_metadata_direction_alignment_fx( hMasa ); -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - fixedToFloat_arrL( hMasa->data.dir_align_state.previous_ele_dir1_fx, hMasa->data.dir_align_state.previous_ele_dir1, Q22, MASA_FREQUENCY_BANDS ); - fixedToFloat_arrL( hMasa->data.dir_align_state.previous_ele_dir2_fx, hMasa->data.dir_align_state.previous_ele_dir2, Q22, MASA_FREQUENCY_BANDS ); - fixedToFloat_arrL( hMasa->data.dir_align_state.previous_azi_dir1_fx, hMasa->data.dir_align_state.previous_azi_dir1, Q22, MASA_FREQUENCY_BANDS ); - fixedToFloat_arrL( hMasa->data.dir_align_state.previous_azi_dir2_fx, hMasa->data.dir_align_state.previous_ele_dir2, Q22, MASA_FREQUENCY_BANDS ); - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hMasa->masaMetadata.directional_meta[0].azimuth[i][j] = fixedToFloat( hMasa->masaMetadata.directional_meta[0].azimuth_fx[i][j], Q22 ); - hMasa->masaMetadata.directional_meta[0].elevation[i][j] = fixedToFloat( hMasa->masaMetadata.directional_meta[0].elevation_fx[i][j], Q22 ); - hMasa->masaMetadata.directional_meta[0].energy_ratio[i][j] = fixedToFloat( hMasa->masaMetadata.directional_meta[0].energy_ratio_fx[i][j], Q30 ); - hMasa->masaMetadata.directional_meta[0].spread_coherence[i][j] = fixedToFloat( hMasa->masaMetadata.directional_meta[0].spread_coherence_fx[i][j], Q15 ); - hMasa->masaMetadata.directional_meta[1].azimuth[i][j] = fixedToFloat( hMasa->masaMetadata.directional_meta[1].azimuth_fx[i][j], Q22 ); - hMasa->masaMetadata.directional_meta[1].elevation[i][j] = fixedToFloat( hMasa->masaMetadata.directional_meta[1].elevation_fx[i][j], Q22 ); - hMasa->masaMetadata.directional_meta[1].energy_ratio[i][j] = fixedToFloat( hMasa->masaMetadata.directional_meta[1].energy_ratio_fx[i][j], Q30 ); - hMasa->masaMetadata.directional_meta[1].spread_coherence[i][j] = fixedToFloat( hMasa->masaMetadata.directional_meta[1].spread_coherence_fx[i][j], Q15 ); - } - } -#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - MASA_METADATA_HANDLE current_meta = &( hMasa->masaMetadata ); - MASA_METADATA_HANDLE previous_meta = &( hMasa->data.sync_state.previous_metadata ); - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) - { - current_meta->directional_meta[k].azimuth_fx[i][j] = float_to_fix( current_meta->directional_meta[k].azimuth[i][j], Q22 ); - current_meta->directional_meta[k].elevation_fx[i][j] = float_to_fix( current_meta->directional_meta[k].elevation[i][j], Q22 ); - current_meta->directional_meta[k].energy_ratio_fx[i][j] = float_to_fix( current_meta->directional_meta[k].energy_ratio[i][j], Q30 ); - current_meta->directional_meta[k].spread_coherence_fx[i][j] = float_to_fix16( current_meta->directional_meta[k].spread_coherence[i][j], Q15 ); - previous_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].azimuth[i][j], Q22 ); - previous_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].elevation[i][j], Q22 ); - previous_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].energy_ratio[i][j], Q30 ); - previous_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); - } - current_meta->common_meta.surround_coherence_fx[i][j] = float_to_fix16( current_meta->common_meta.surround_coherence[i][j], Q15 ); - current_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = float_to_fix( current_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); - current_meta->common_meta.remainder_to_total_ratio_fx[i][j] = float_to_fix( current_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); - previous_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->common_meta.surround_coherence[i][j], Q15 ) ); - previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); - previous_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS - detect_framing_async_fx( hMasa ); /* detect the offset, set 1sf/4sf mode based on this. potentially also shift the metadata using a history buffer */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) - { - current_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( current_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); - current_meta->directional_meta[k].elevation[i][j] = fixedToFloat( current_meta->directional_meta[k].elevation_fx[i][j], Q22 ); - current_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( current_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); - current_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( current_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); - previous_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( previous_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); - previous_meta->directional_meta[k].elevation[i][j] = fixedToFloat( previous_meta->directional_meta[k].elevation_fx[i][j], Q22 ); - previous_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( previous_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); - previous_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( previous_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); - } - current_meta->common_meta.surround_coherence[i][j] = fixedToFloat( current_meta->common_meta.surround_coherence_fx[i][j], Q15 ); - current_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); - current_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); - previous_meta->common_meta.surround_coherence[i][j] = fixedToFloat( previous_meta->common_meta.surround_coherence_fx[i][j], Q15 ); - previous_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); - previous_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS - if ( hMasa->data.sync_state.frame_mode == MASA_FRAME_1SF && hMasa->data.sync_state.prev_offset != 0 ) - { - /* average over sub-frames */ - average_masa_metadata( &( hMasa->masaMetadata ), hMasa->data.energy, &( hMasa->data.Sph_Grid16 ), ivas_total_brate == IVAS_512k ? TRUE : FALSE ); - } /* Inspect metadata for parameter changes that affect coding. */ - detect_metadata_composition( hMasa, &joinedSubframes, &coherencePresent, &isActualTwoDir ); + detect_metadata_composition_fx( hMasa, &joinedSubframes, &coherencePresent, &isActualTwoDir ); + hMasa->config.joinedSubframes = joinedSubframes; hMasa->config.coherencePresent = coherencePresent; - hMasa->config.numberOfDirections = ( hMasa->masaMetadata.descriptive_meta.numberOfDirections + 1 ) == 2 && isActualTwoDir ? 2 : 1; + move16(); + move16(); + test(); + IF( EQ_16( add( hMasa->masaMetadata.descriptive_meta.numberOfDirections, 1 ), 2 ) && isActualTwoDir ) + { + hMasa->config.numberOfDirections = 2; + } + ELSE + { + hMasa->config.numberOfDirections = 1; + } + move16(); } - else if ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) + ELSE IF( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { /* For McMASA, these are set only once as this function is called only once. */ hMasa->config.joinedSubframes = 0; hMasa->config.numberOfDirections = 1; + move16(); + move16(); } -#ifndef IVAS_FLOAT_FIXED - if ( ivas_format == MASA_ISM_FORMAT ) - { - ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); - } - else - { - ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, ivas_total_brate, st_ivas->nchan_transport, ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); - } -#else IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { ivas_masa_set_coding_config_fx( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); } ELSE { - ivas_masa_set_coding_config_fx( &( hMasa->config ), hMasa->data.band_mapping, ivas_total_brate, st_ivas->nchan_transport, ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); + test(); + ivas_masa_set_coding_config_fx( &( hMasa->config ), hMasa->data.band_mapping, ivas_total_brate, st_ivas->nchan_transport, ( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) ); } -#endif /* Setup importance weights for two-direction band selection. */ - if ( hMasa->config.numberOfDirections == 2 ) + IF( EQ_16( hMasa->config.numberOfDirections, 2 ) ) { - set_f( hMasa->data.importanceWeight, 1.0f, hMasa->config.numCodingBands ); + set32_fx( hMasa->data.importanceWeight_fx, ONE_IN_Q30 /*1.0f Q30*/, hMasa->config.numCodingBands ); - if ( hMasa->config.numCodingBands == 5 ) + IF( EQ_16( hMasa->config.numCodingBands, 5 ) ) { - hMasa->data.importanceWeight[4] = 0.7f; + hMasa->data.importanceWeight_fx[4] = 751619277 /*0.7f q30*/; + move32(); } - else if ( hMasa->config.numCodingBands == 8 ) + ELSE IF( EQ_16( hMasa->config.numCodingBands, 8 ) ) { - hMasa->data.importanceWeight[7] = 0.7f; + hMasa->data.importanceWeight_fx[7] = 751619277 /*0.7f q30*/; + move32(); } - else if ( hMasa->config.numCodingBands == 10 ) + ELSE IF( EQ_16( hMasa->config.numCodingBands, 10 ) ) { - hMasa->data.importanceWeight[8] = 0.7f; - hMasa->data.importanceWeight[9] = 0.1f; + hMasa->data.importanceWeight_fx[8] = 751619277 /*0.7f q30*/; + hMasa->data.importanceWeight_fx[9] = 107374182 /*0.1f q30*/; + move32(); + move32(); } - else if ( hMasa->config.numCodingBands == 12 ) + ELSE IF( EQ_16( hMasa->config.numCodingBands, 12 ) ) { - hMasa->data.importanceWeight[10] = 0.7f; - hMasa->data.importanceWeight[11] = 0.1f; + hMasa->data.importanceWeight_fx[10] = 751619277 /*0.7f q30*/; + hMasa->data.importanceWeight_fx[11] = 107374182 /*0.1f q30*/; + move32(); + move32(); } - else if ( hMasa->config.numCodingBands == 18 ) + ELSE IF( EQ_16( hMasa->config.numCodingBands, 18 ) ) { - hMasa->data.importanceWeight[14] = 0.8f; - hMasa->data.importanceWeight[15] = 0.5f; - hMasa->data.importanceWeight[16] = 0.2f; - hMasa->data.importanceWeight[17] = 0.0f; + hMasa->data.importanceWeight_fx[14] = 858993459 /*0.8f q30*/; + hMasa->data.importanceWeight_fx[15] = 536870912 /*0.5f q30*/; + hMasa->data.importanceWeight_fx[16] = 214748365 /*0.2f q30*/; + hMasa->data.importanceWeight_fx[17] = 0 /*0 q30*/; + move32(); + move32(); + move32(); + move32(); } - else if ( hMasa->config.numCodingBands == 24 ) + ELSE IF( EQ_16( hMasa->config.numCodingBands, 24 ) ) { - hMasa->data.importanceWeight[20] = 0.8f; - hMasa->data.importanceWeight[21] = 0.5f; - hMasa->data.importanceWeight[22] = 0.2f; - hMasa->data.importanceWeight[23] = 0.0f; + hMasa->data.importanceWeight_fx[20] = 858993459 /*0.8f q30*/; + hMasa->data.importanceWeight_fx[21] = 536870912 /*0.5f q30*/; + hMasa->data.importanceWeight_fx[22] = 214748365 /*0.2f q30*/; + hMasa->data.importanceWeight_fx[23] = 0 /*0 q30*/; + move32(); + move32(); + move32(); + move32(); } - if ( hMasa->config.numTwoDirBands == hMasa->config.numCodingBands ) + IF( EQ_16( hMasa->config.numTwoDirBands, hMasa->config.numCodingBands ) ) { - set_c( (int8_t *) hMasa->data.twoDirBands, 1, hMasa->config.numCodingBands ); + set8_fx( (Word8 *) hMasa->data.twoDirBands, 1, hMasa->config.numCodingBands ); } } - else + ELSE { - set_c( (int8_t *) hMasa->data.twoDirBands, 0, hMasa->config.numCodingBands ); + set8_fx( (Word8 *) hMasa->data.twoDirBands, 0, hMasa->config.numCodingBands ); } /* Set qmeta to correct values */ - if ( ( error = ivas_qmetadata_allocate_memory( hQMetaData, hMasa->config.numCodingBands, hMasa->config.numberOfDirections == 2 && hMasa->config.numTwoDirBands != 0 ? 2 : 1, hMasa->config.useCoherence ) ) != IVAS_ERR_OK ) + test(); + IF( EQ_16( hMasa->config.numberOfDirections, 2 ) && hMasa->config.numTwoDirBands != 0 ) { - return error; + IF( ( error = ivas_qmetadata_allocate_memory( hQMetaData, hMasa->config.numCodingBands, 2, hMasa->config.useCoherence ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE + { + IF( ( error = ivas_qmetadata_allocate_memory( hQMetaData, hMasa->config.numCodingBands, 1, hMasa->config.useCoherence ) ) != IVAS_ERR_OK ) + { + return error; + } } - for ( i = 0; i < hQMetaData->no_directions; i++ ) + FOR( i = 0; i < hQMetaData->no_directions; i++ ) { hQMetaData->q_direction[i].cfg.nbands = hMasa->config.numCodingBands; - hQMetaData->q_direction[i].cfg.nblocks = hMasa->config.joinedSubframes == TRUE ? 1 : 4; + move16(); + IF( EQ_16( hMasa->config.joinedSubframes, TRUE ) ) + { + hQMetaData->q_direction[i].cfg.nblocks = 1; + } + ELSE + { + hQMetaData->q_direction[i].cfg.nblocks = 4; + } + move16(); - if ( ivas_format == MC_FORMAT ) + IF( EQ_16( ivas_format, MC_FORMAT ) ) { hQMetaData->q_direction[i].cfg.mc_ls_setup = st_ivas->hEncoderConfig->mc_input_setup; + move16(); } - else + ELSE { /* Just to be sure that this default value is maintained */ hQMetaData->q_direction[i].cfg.mc_ls_setup = MC_LS_SETUP_INVALID; + move16(); } } hQMetaData->all_coherence_zero = !hMasa->config.coherencePresent; + move16(); ivas_set_qmetadata_maxbit_req( hQMetaData, ivas_format ); /* Find maximum band usable */ - maxBin = (int16_t) ( st_ivas->hEncoderConfig->input_Fs * INV_CLDFB_BANDWIDTH ); + maxBin = extract_l( Mpy_32_32( st_ivas->hEncoderConfig->input_Fs /*q0*/, INV_CLDFB_BANDWIDTH_Q31 /*Q31*/ ) ); /*q0+q31-q31->q0*/ maxBand = 0; - while ( maxBand <= MASA_FREQUENCY_BANDS && MASA_band_grouping_24[maxBand] <= maxBin ) + move16(); + WHILE( LE_16( maxBand, MASA_FREQUENCY_BANDS ) && LE_16( MASA_band_grouping_24[maxBand], maxBin ) ) { - maxBand++; + test(); + maxBand = (UWord8) add( maxBand, 1 ); + move16(); /*because typecasting word16 to uword8*/ } - maxBand--; + maxBand = (UWord8) sub( maxBand, 1 ); + move16(); /*because typecasting word16 to uword8*/ st_ivas->hQMetaData->q_direction->cfg.inactiveBands = 0; masa_total_brate = ivas_total_brate; -#ifndef IVAS_FLOAT_FIXED - if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) - { - masa_total_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->hEncoderConfig->nchan_ism ); - } -#else + move16(); + move32(); test(); IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - masa_total_brate = calculate_cpe_brate_MASA_ISM_fx( st_ivas->ism_mode, ivas_total_brate, st_ivas->hEncoderConfig->nchan_ism ); + masa_total_brate = calculate_cpe_brate_MASA_ISM_fx( st_ivas->ism_mode, ivas_total_brate, st_ivas->hEncoderConfig->nchan_ism ); /*q0*/ } -#endif - if ( masa_total_brate >= IVAS_384k && ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) ) + test(); + test(); + IF( GE_32( masa_total_brate, IVAS_384k ) && ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) ) { - int16_t continueLoop; + Word16 continueLoop; continueLoop = 1; - while ( maxBand > 5 && continueLoop ) + move16(); + WHILE( GT_16( maxBand, 5 ) && continueLoop ) { - for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + test(); + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - if ( hMasa->data.energy[sf][maxBand - 1] > 100000 ) + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( hMasa->data.energy_fx[sf][maxBand - 1], hMasa->data.energy_e[sf][maxBand - 1], 100000 /*q0*/, 31 ), 1 ) ) { continueLoop = 0; - break; + move16(); + BREAK; } } - if ( continueLoop ) + IF( continueLoop ) { - maxBand--; + maxBand = (UWord8) sub( maxBand, 1 ); + move16(); /*because typecasting word16 to uword8*/ } } - if ( maxBand < MASA_MAXIMUM_CODING_SUBBANDS ) + IF( LT_16( maxBand, MASA_MAXIMUM_CODING_SUBBANDS ) ) { - st_ivas->hQMetaData->q_direction->cfg.inactiveBands = MASA_MAXIMUM_CODING_SUBBANDS - maxBand; + st_ivas->hQMetaData->q_direction->cfg.inactiveBands = (UWord8) sub( MASA_MAXIMUM_CODING_SUBBANDS, maxBand ); + move16(); /*because typecasting word16 to uword8*/ } - else + ELSE { st_ivas->hQMetaData->q_direction->cfg.inactiveBands = 0; + move16(); } } -#ifndef IVAS_FLOAT_FIXED - masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, masa_total_brate >= IVAS_384k, NULL ); -#else - Word16 numBands48k = hMasa->config.numCodingBands, band; - - for ( band = 0; band < numBands48k; band++ ) - { - floatToFixed_arrL( hQMetaData->q_direction[0].band_data[band].azimuth, hQMetaData->q_direction[0].band_data[band].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[0].band_data[band].elevation, hQMetaData->q_direction[0].band_data[band].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[0].band_data[band].energy_ratio, hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - if ( hQMetaData->no_directions == 2 ) - { - floatToFixed_arrL( hQMetaData->q_direction[1].band_data[band].azimuth, hQMetaData->q_direction[1].band_data[band].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[1].band_data[band].elevation, hQMetaData->q_direction[1].band_data[band].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[1].band_data[band].energy_ratio, hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - masa_sample_rate_band_correction_fx( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, masa_total_brate >= IVAS_384k, NULL ); + masa_sample_rate_band_correction_fx( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, (UWord8) GE_32( masa_total_brate, IVAS_384k ), NULL ); - for ( band = 0; band < numBands48k; band++ ) - { - fixedToFloat_arrL( hQMetaData->q_direction[0].band_data[band].azimuth_fx, hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[0].band_data[band].elevation_fx, hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - if ( hQMetaData->no_directions == 2 ) - { - fixedToFloat_arrL( hQMetaData->q_direction[1].band_data[band].azimuth_fx, hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[1].band_data[band].elevation_fx, hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } -#endif - if ( hMasa->config.numTwoDirBands >= hMasa->config.numCodingBands ) + IF( GE_16( hMasa->config.numTwoDirBands, hMasa->config.numCodingBands ) ) { hMasa->config.numTwoDirBands = hMasa->config.numCodingBands; - set_c( (int8_t *) hMasa->data.twoDirBands, 1, hMasa->config.numCodingBands ); + move16(); + set8_fx( (Word8 *) hMasa->data.twoDirBands, 1, hMasa->config.numCodingBands ); } + test(); + test(); + test(); + test(); /* Transmit stereo signals using a mono downmix at lowest bitrates */ - if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && st_ivas->nCPE == 1 && st_ivas->hCPE[0]->hStereoDft != NULL && st_ivas->hCPE[0]->hStereoDft->hConfig != NULL ) + IF( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && EQ_16( st_ivas->nCPE, 1 ) && st_ivas->hCPE[0]->hStereoDft != NULL && st_ivas->hCPE[0]->hStereoDft->hConfig != NULL ) { - st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = ( ivas_total_brate - ism_total_brate < MASA_STEREO_MIN_BITRATE ) ? 1 : 0; + IF( LT_32( L_sub( ivas_total_brate, ism_total_brate ), MASA_STEREO_MIN_BITRATE ) ) + { + st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = 1; + } + ELSE + { + st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = 0; + } + move16(); } - if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) + test(); + test(); + test(); + IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) && ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) { - if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT || st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX ) + test(); + IF( EQ_16( st_ivas->hCPE[0]->element_mode, IVAS_CPE_DFT ) || LT_16( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt, OMASA_STEREO_SW_CNT_MAX ) ) { - st_ivas->hMasa->data.hOmasaData->lp_noise_CPE = st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise; + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise_fx; /*Q8*/ } - else + ELSE { - st_ivas->hMasa->data.hOmasaData->lp_noise_CPE = ( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise + st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise ) / CPE_CHANNELS; + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = shr( add( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise_fx, st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise_fx ), 1 ); /*Q8*/ } + move16(); } - return error; } - -/*-----------------------------------------------------------------------* - * ivas_masa_surrcoh_signicant() - * - * Determine if surrounding coherence is significant in this frame and should be encoded - *-----------------------------------------------------------------------*/ -UWord8 ivas_masa_surrcoh_signicant_fx( - Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence */ - Word32 diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio */ - const Word16 nSubFrames, /* i : Number of sub frames */ - const Word16 nBands /* i : Number of frequency bands */ /* i : dynamic (min q for surroundingCoherence and diffuse_to_total_ratio) */ +#else +ivas_error ivas_masa_enc_config( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { - Word32 significanceMeasure1, significanceMeasure2, significanceMeasure; - Word32 surrCohToTotal, surrCohToTotalSum, surrCohToTotalTimesDiffSum, diffSum; - Word32 sf, band; - Word16 surrCohToTotalSum_e, surrCohToTotalTimesDiffSum_e, diffSum_e; - - // input buffers Q=31 - Word32 surrCohSignificanceCoef = 858993459; //( 0.4 * ( 1 << q ) ) 0.4 scaled to Q=31 - move32(); - Word32 threshold = 214748365; //( 0.1 * ( 1 << q ) ) 0.1 scaled to Q=31 - move32(); - FOR( sf = 0; sf < nSubFrames; sf++ ) - { - surrCohToTotalSum = 0; - move32(); - surrCohToTotalSum_e = 0; - move16(); - surrCohToTotalTimesDiffSum = 0; - move32(); - surrCohToTotalTimesDiffSum_e = 0; - move16(); - diffSum = 0; - move32(); - diffSum_e = 0; - move16(); + int16_t i; + MASA_ENCODER_HANDLE hMasa; + IVAS_QMETADATA_HANDLE hQMetaData; + IVAS_FORMAT ivas_format; + uint8_t joinedSubframes; + uint8_t coherencePresent; + uint8_t isActualTwoDir; /* Flag to tell that when there are two directions present in metadata, they both contain meaningful information. */ + int32_t ivas_total_brate; + uint8_t maxBand; + int16_t maxBin, sf; + ivas_error error; + int32_t ism_total_brate; + int32_t masa_total_brate; - FOR( band = 0; band < nBands; band++ ) - { - surrCohToTotal = Mpy_32_32( diffuse_to_total_ratio[sf][band], surroundingCoherence[sf][band] ); // 2Q -> Q - surrCohToTotalSum = BASOP_Util_Add_Mant32Exp( surrCohToTotalSum, surrCohToTotalSum_e, surrCohToTotal, 0, &surrCohToTotalSum_e ); - surrCohToTotalTimesDiffSum = BASOP_Util_Add_Mant32Exp( surrCohToTotalTimesDiffSum, surrCohToTotalTimesDiffSum_e, Mpy_32_32( (Word32) diffuse_to_total_ratio[sf][band], surrCohToTotal ), 0, &surrCohToTotalTimesDiffSum_e ); // Q2 -> Q - diffSum = BASOP_Util_Add_Mant32Exp( diffSum, diffSum_e, diffuse_to_total_ratio[sf][band], 0, &diffSum_e ); // Q - } + error = IVAS_ERR_OK; - Word16 significanceMeasure1_e, significanceMeasure2_e; - Word16 significanceMeasure_e; - significanceMeasure1 = L_deposit_h( BASOP_Util_Divide3216_Scale( surrCohToTotalSum, nBands, &significanceMeasure1_e ) ); // e1 exponent - significanceMeasure1_e = add( significanceMeasure1_e, sub( surrCohToTotalSum_e, 15 ) ); - significanceMeasure2 = L_deposit_h( BASOP_Util_Divide3232_Scale( Mpy_32_32( surrCohSignificanceCoef, surrCohToTotalTimesDiffSum ), L_add( diffSum, EPSILON_FX ), &significanceMeasure2_e ) ); // e2 exponent - significanceMeasure2_e = add( significanceMeasure2_e, sub( surrCohToTotalTimesDiffSum_e, diffSum_e ) ); + hMasa = st_ivas->hMasa; + hQMetaData = st_ivas->hQMetaData; + ivas_format = st_ivas->hEncoderConfig->ivas_format; + ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; - IF( BASOP_Util_Cmp_Mant32Exp( significanceMeasure1, significanceMeasure1_e, significanceMeasure2, significanceMeasure2_e ) > 0 ) - { - significanceMeasure = significanceMeasure1; - move32(); - significanceMeasure_e = significanceMeasure1_e; - move16(); - } - ELSE - { - significanceMeasure = significanceMeasure2; - move32(); - significanceMeasure_e = significanceMeasure2_e; - move16(); - } - IF( BASOP_Util_Cmp_Mant32Exp( significanceMeasure, significanceMeasure_e, threshold, 0 ) > 0 ) // Q31 Comparision + ism_total_brate = 0; + if ( ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) + { + for ( i = 0; i < st_ivas->nSCE; i++ ) { - return 1; + ism_total_brate += st_ivas->hSCE[i]->element_brate; } } - return 0; -} - -/*-----------------------------------------------------------------------* - * ivas_masa_surrcoh_signicant() - * - * Determine if surrounding coherence is significant in this frame and should be encoded - *-----------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED + ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, hQMetaData, &st_ivas->hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, ivas_format, st_ivas->ism_mode, ism_total_brate ); +#else + ivas_masa_set_elements_fx( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, hQMetaData, &st_ivas->hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, ivas_format, st_ivas->ism_mode, ism_total_brate ); +#endif -uint8_t ivas_masa_surrcoh_signicant( - float surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence */ - float diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio */ - const int16_t nSubFrames, /* i : Number of sub frames */ - const int16_t nBands /* i : Number of frequency bands */ -) -{ - float significanceMeasure1, significanceMeasure2, significanceMeasure; - float surrCohToTotal, surrCohToTotalSum, surrCohToTotalTimesDiffSum, diffSum; - int16_t sf, band; - float surrCohSignificanceCoef = 0.4f; - float threshold = 0.1f; + hQMetaData->is_masa_ivas_format = 1; - for ( sf = 0; sf < nSubFrames; sf++ ) + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) { - surrCohToTotalSum = 0.0f; - surrCohToTotalTimesDiffSum = 0.0f; - diffSum = 0.0f; - for ( band = 0; band < nBands; band++ ) +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + floatToFixed_arr32( hMasa->data.dir_align_state.previous_ele_dir1, hMasa->data.dir_align_state.previous_ele_dir1_fx, Q22, MASA_FREQUENCY_BANDS ); + floatToFixed_arr32( hMasa->data.dir_align_state.previous_ele_dir2, hMasa->data.dir_align_state.previous_ele_dir2_fx, Q22, MASA_FREQUENCY_BANDS ); + floatToFixed_arr32( hMasa->data.dir_align_state.previous_azi_dir1, hMasa->data.dir_align_state.previous_azi_dir1_fx, Q22, MASA_FREQUENCY_BANDS ); + floatToFixed_arr32( hMasa->data.dir_align_state.previous_azi_dir2, hMasa->data.dir_align_state.previous_azi_dir2_fx, Q22, MASA_FREQUENCY_BANDS ); +#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED + masa_metadata_direction_alignment_fx( hMasa ); +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + fixedToFloat_arrL( hMasa->data.dir_align_state.previous_ele_dir1_fx, hMasa->data.dir_align_state.previous_ele_dir1, Q22, MASA_FREQUENCY_BANDS ); + fixedToFloat_arrL( hMasa->data.dir_align_state.previous_ele_dir2_fx, hMasa->data.dir_align_state.previous_ele_dir2, Q22, MASA_FREQUENCY_BANDS ); + fixedToFloat_arrL( hMasa->data.dir_align_state.previous_azi_dir1_fx, hMasa->data.dir_align_state.previous_azi_dir1, Q22, MASA_FREQUENCY_BANDS ); + fixedToFloat_arrL( hMasa->data.dir_align_state.previous_azi_dir2_fx, hMasa->data.dir_align_state.previous_ele_dir2, Q22, MASA_FREQUENCY_BANDS ); +#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - surrCohToTotal = diffuse_to_total_ratio[sf][band] * surroundingCoherence[sf][band]; - surrCohToTotalSum += surrCohToTotal; - surrCohToTotalTimesDiffSum += diffuse_to_total_ratio[sf][band] * surrCohToTotal; - diffSum += diffuse_to_total_ratio[sf][band]; + for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + f2me( hMasa->data.energy[i][j], &hMasa->data.energy_fx[i][j], &hMasa->data.energy_e[i][j] ); + } } - significanceMeasure1 = surrCohToTotalSum / (float) nBands; - significanceMeasure2 = surrCohSignificanceCoef * surrCohToTotalTimesDiffSum / ( diffSum + EPSILON ); - significanceMeasure = max( significanceMeasure1, significanceMeasure2 ); - - if ( significanceMeasure > threshold ) +#endif // IVAS_FLOAT_FIXED_CONVERSIONS + detect_framing_async_fx( hMasa ); /* detect the offset, set 1sf/4sf mode based on this. potentially also shift the metadata using a history buffer */ + if ( hMasa->data.sync_state.frame_mode == MASA_FRAME_1SF && hMasa->data.sync_state.prev_offset != 0 ) { - return 1; /* Surrounding coherence was significant in at least one subframe */ + /* average over sub-frames */ + average_masa_metadata_fx( &( hMasa->masaMetadata ), hMasa->data.energy_fx, hMasa->data.energy_e, &( hMasa->data.Sph_Grid16 ), ivas_total_brate == IVAS_512k ? TRUE : FALSE ); } - } - - return 0; /* Surrounding coherence was not significant in any subframe */ -} -/*-----------------------------------------------------------------------* - * Local functions - *-----------------------------------------------------------------------*/ + /* Inspect metadata for parameter changes that affect coding. */ + detect_metadata_composition_fx( hMasa, &joinedSubframes, &coherencePresent, &isActualTwoDir ); -#ifdef IVAS_FLOAT_FIXED -static void combine_freqbands_and_subframes_fx( - MASA_ENCODER_HANDLE hMasa ) -{ - Word16 i, j, k, m; - Word16 aziRad, eleRad; - Word32 x[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 y[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 z[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 vecLen; - Word16 vecLen_e; - Word32 xSum, ySum, zSum; - Word64 xSum_sq, ySum_sq, zSum_sq; - Word32 energySum; - Word32 spreadCohSum; - Word32 surrCohSum; - Word32 energyRatioSum; - Word16 surrCohTemp; - Word32 energyRatioTemp; - Word32 energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word16 brange[2]; - UWord8 numCodingBands; - UWord8 numSf; - UWord8 numDirections; - MASA_METADATA_HANDLE hMeta; - UWord8 mergeRatiosOverSubframes; - UWord8 computeCoherence; - Word16 exp_diff; - Word32 L_tmp; - Word16 guard_bits; - Word64 W_tmp; - Word16 q_shift; + hMasa->config.joinedSubframes = joinedSubframes; + hMasa->config.coherencePresent = coherencePresent; + hMasa->config.numberOfDirections = ( hMasa->masaMetadata.descriptive_meta.numberOfDirections + 1 ) == 2 && isActualTwoDir ? 2 : 1; + } + else if ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) + { + /* For McMASA, these are set only once as this function is called only once. */ + hMasa->config.joinedSubframes = 0; + hMasa->config.numberOfDirections = 1; + } - numCodingBands = hMasa->config.numCodingBands; - move16(); - numDirections = hMasa->config.numberOfDirections; - move16(); - IF( EQ_16( hMasa->config.joinedSubframes, TRUE ) ) +#ifndef IVAS_FLOAT_FIXED + if ( ivas_format == MASA_ISM_FORMAT ) { - numSf = 1; - move16(); + ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); } - ELSE + else { - numSf = MAX_PARAM_SPATIAL_SUBFRAMES; - move16(); + ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, ivas_total_brate, st_ivas->nchan_transport, ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); } - hMeta = &( hMasa->masaMetadata ); - - mergeRatiosOverSubframes = hMasa->config.mergeRatiosOverSubframes; - move16(); - test(); - IF( hMasa->config.useCoherence && hMasa->config.coherencePresent ) +#else + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { - computeCoherence = 1; - move16(); + ivas_masa_set_coding_config_fx( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); } ELSE { - computeCoherence = 0; - move16(); + ivas_masa_set_coding_config_fx( &( hMasa->config ), hMasa->data.band_mapping, ivas_total_brate, st_ivas->nchan_transport, ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); } - - /* If metadata subframes are joined then we need all energy to be in the first subframe for combining. - * This optimizes following computations a bit. - * Note: If energy is used elsewhere, then this can cause problems and local energy should be used. */ - IF( EQ_16( numSf, 1 ) ) +#endif +#ifdef IVAS_FLOAT_FIXED + /* Setup importance weights for two-direction band selection. */ + IF( EQ_16( hMasa->config.numberOfDirections, 2 ) ) { - FOR( j = 1; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + set32_fx( hMasa->data.importanceWeight_fx, ONE_IN_Q30, hMasa->config.numCodingBands ); + + IF( EQ_16( hMasa->config.numCodingBands, 5 ) ) { - FOR( k = 0; k < MASA_FREQUENCY_BANDS; k++ ) - { - hMasa->data.energy_fx[0][k] = L_add( hMasa->data.energy_fx[0][k], hMasa->data.energy_fx[j][k] ); // hMasa->data.q_energy - move32(); - } + hMasa->data.importanceWeight_fx[4] = 751619277; // 0.7f in Q30 + move32(); } - } - - IF( LE_16( numCodingBands, MAX_REDUCED_NBANDS ) ) - { - /* reduce metadata *frequency* resolution. time resolution is not touched */ - FOR( i = 0; i < numDirections; i++ ) + ELSE IF( EQ_16( hMasa->config.numCodingBands, 8 ) ) { - FOR( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - FOR( k = 0; k < MASA_FREQUENCY_BANDS; k++ ) - { - aziRad = extract_l( L_shl( Mpy_32_32( hMeta->directional_meta[i].azimuth_fx[j][k], PI_OVER_180_FX ), Q13 - Q22 ) ); // ((Q22, Q31) -> Q22) >> Q9 -> Q13 - eleRad = extract_l( L_shl( Mpy_32_32( hMeta->directional_meta[i].elevation_fx[j][k], PI_OVER_180_FX ), Q13 - Q22 ) ); // ((Q22, Q31) -> Q22) >> Q9 -> Q13 - vecLen = Mpy_32_32( hMeta->directional_meta[i].energy_ratio_fx[j][k], hMasa->data.energy_fx[j][k] ); // (Q30, hMasa->data.q_energy) -> hMasa->data.q_energy - Q1 - - x[i][j][k] = Mpy_32_32( L_mult( getCosWord16( aziRad ), getCosWord16( eleRad ) ), vecLen ); // (Q29, hMasa->data.q_energy - Q1) -> hMasa->data.q_energy - Q3 - move32(); - y[i][j][k] = Mpy_32_32( L_mult0( getSinWord16( aziRad ), getCosWord16( eleRad ) ), vecLen ); // (Q29, hMasa->data.q_energy - Q1) -> hMasa->data.q_energy - Q3 - move32(); - z[i][j][k] = Mpy_32_32( L_mult0( getSinWord16( eleRad ), ONE_IN_Q14 ), vecLen ); // (Q29, hMasa->data.q_energy - Q1) -> hMasa->data.q_energy - Q3 - move32(); - } - } + hMasa->data.importanceWeight_fx[7] = 751619277; // 0.7f in Q30 + move32(); } - - FOR( i = 0; i < numDirections; i++ ) + ELSE IF( EQ_16( hMasa->config.numCodingBands, 10 ) ) { - FOR( j = 0; j < numSf; j++ ) - { - FOR( k = 0; k < numCodingBands; k++ ) - { - brange[0] = hMasa->data.band_mapping[k]; - move16(); - brange[1] = hMasa->data.band_mapping[k + 1]; - move16(); - - xSum = 0; - ySum = 0; - zSum = 0; - energySum = 0; - spreadCohSum = 0; - move32(); - move32(); - move32(); - move32(); - move32(); - - FOR( m = brange[0]; m < brange[1]; m++ ) - { - xSum = L_add( xSum, x[i][j][m] ); // hMasa->data.q_energy - Q3 - ySum = L_add( ySum, y[i][j][m] ); // hMasa->data.q_energy - Q3 - zSum = L_add( zSum, z[i][j][m] ); // hMasa->data.q_energy - Q3 - energySum = L_add( energySum, hMasa->data.energy_fx[j][m] ); // hMasa->data.q_energy - } - - aziRad = BASOP_util_atan2( ySum, xSum, 0 ); // Q13 - xSum_sq = W_mult0_32_32( xSum, xSum ); // 2 * hMasa->data.q_energy - Q6 - ySum_sq = W_mult0_32_32( ySum, ySum ); // 2 * hMasa->data.q_energy - Q6 - zSum_sq = W_mult0_32_32( zSum, zSum ); // 2 * hMasa->data.q_energy - Q6 - W_tmp = W_add( xSum_sq, ySum_sq ); // 2 * hMasa->data.q_energy - Q6 - q_shift = W_norm( W_tmp ); - L_tmp = W_extract_h( W_shl( W_tmp, q_shift ) ); // 2 * hMasa->data.q_energy - Q6 + (q_shift -32) - exp_diff = sub( Q31, add( sub( imult1616( 2, hMasa->data.q_energy ), Q6 ), sub( q_shift, 32 ) ) ); - L_tmp = Sqrt32( L_tmp, &exp_diff ); - eleRad = BASOP_util_atan2( zSum, L_tmp, sub( sub( 34, hMasa->data.q_energy ), exp_diff ) ); // Q13 + hMasa->data.importanceWeight_fx[8] = 751619277; // 0.7f in Q30 + hMasa->data.importanceWeight_fx[9] = 107374182; // 0.1f in Q30 + move32(); + move32(); + } + ELSE IF( EQ_16( hMasa->config.numCodingBands, 12 ) ) + { + hMasa->data.importanceWeight_fx[10] = 751619277; // 0.7f in Q30 + hMasa->data.importanceWeight_fx[11] = 107374182; // 0.1f in Q30 + move32(); + move32(); + } + ELSE IF( EQ_16( hMasa->config.numCodingBands, 18 ) ) + { + hMasa->data.importanceWeight_fx[14] = 858993459; // 0.8f in Q30 + hMasa->data.importanceWeight_fx[15] = 536870912; // 0.5f in Q30 + hMasa->data.importanceWeight_fx[16] = 214748365; // 0.2f in Q30 + hMasa->data.importanceWeight_fx[17] = 0; + move32(); + move32(); + move32(); + move32(); + } + ELSE IF( EQ_16( hMasa->config.numCodingBands, 24 ) ) + { + hMasa->data.importanceWeight_fx[20] = 858993459; // 0.8f in Q30 + hMasa->data.importanceWeight_fx[21] = 536870912; // 0.5f in Q30 + hMasa->data.importanceWeight_fx[22] = 214748365; // 0.2f in Q30 + hMasa->data.importanceWeight_fx[23] = 0; + move32(); + move32(); + move32(); + move32(); + } - hMeta->directional_meta[i].azimuth_fx[j][k] = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, aziRad ), Q1 ); // ((Q25, Q13) -> Q23) >> Q1 -> Q22 - move32(); - hMeta->directional_meta[i].elevation_fx[j][k] = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, eleRad ), Q1 ); // ((Q25, Q13) -> Q23) >> Q1 -> Q22 - move32(); + IF( EQ_16( hMasa->config.numTwoDirBands, hMasa->config.numCodingBands ) ) + { + set8_fx( (Word8 *) hMasa->data.twoDirBands, 1, hMasa->config.numCodingBands ); + } + } + ELSE + { + set8_fx( (Word8 *) hMasa->data.twoDirBands, 0, hMasa->config.numCodingBands ); + } +#else + /* Setup importance weights for two-direction band selection. */ + if ( hMasa->config.numberOfDirections == 2 ) + { + set_f( hMasa->data.importanceWeight, 1.0f, hMasa->config.numCodingBands ); - W_tmp = W_add( xSum_sq, ySum_sq ); // 2 * hMasa->data.q_energy - Q6 - W_tmp = W_add( W_tmp, zSum_sq ); // 2 * hMasa->data.q_energy - Q6 - q_shift = W_norm( W_tmp ); - vecLen = W_extract_h( W_shl( W_tmp, q_shift ) ); // 2 * hMasa->data.q_energy - Q6 + (q_shift -32) - exp_diff = sub( Q31, add( sub( imult1616( 2, hMasa->data.q_energy ), Q6 ), sub( q_shift, 32 ) ) ); - vecLen = Sqrt32( vecLen, &exp_diff ); - vecLen_e = exp_diff; - move16(); + if ( hMasa->config.numCodingBands == 5 ) + { + hMasa->data.importanceWeight[4] = 0.7f; + } + else if ( hMasa->config.numCodingBands == 8 ) + { + hMasa->data.importanceWeight[7] = 0.7f; + } + else if ( hMasa->config.numCodingBands == 10 ) + { + hMasa->data.importanceWeight[8] = 0.7f; + hMasa->data.importanceWeight[9] = 0.1f; + } + else if ( hMasa->config.numCodingBands == 12 ) + { + hMasa->data.importanceWeight[10] = 0.7f; + hMasa->data.importanceWeight[11] = 0.1f; + } + else if ( hMasa->config.numCodingBands == 18 ) + { + hMasa->data.importanceWeight[14] = 0.8f; + hMasa->data.importanceWeight[15] = 0.5f; + hMasa->data.importanceWeight[16] = 0.2f; + hMasa->data.importanceWeight[17] = 0.0f; + } + else if ( hMasa->config.numCodingBands == 24 ) + { + hMasa->data.importanceWeight[20] = 0.8f; + hMasa->data.importanceWeight[21] = 0.5f; + hMasa->data.importanceWeight[22] = 0.2f; + hMasa->data.importanceWeight[23] = 0.0f; + } - hMeta->directional_meta[i].energy_ratio_fx[j][k] = - BASOP_Util_Divide3232_Scale_cadence( vecLen, L_add( energySum, EPSILON_FX ), &exp_diff ); - move32(); - exp_diff = add( exp_diff, sub( vecLen_e, sub( Q31, hMasa->data.q_energy ) ) ); - hMeta->directional_meta[i].energy_ratio_fx[j][k] = - L_shl( hMeta->directional_meta[i].energy_ratio_fx[j][k], sub( exp_diff, Q1 ) ); // (Q31 - exp_diff ) -> Q30 - move32(); + if ( hMasa->config.numTwoDirBands == hMasa->config.numCodingBands ) + { + set_c( (int8_t *) hMasa->data.twoDirBands, 1, hMasa->config.numCodingBands ); + } + } + else + { + set_c( (int8_t *) hMasa->data.twoDirBands, 0, hMasa->config.numCodingBands ); + } +#endif - IF( computeCoherence ) - { - FOR( m = brange[0]; m < brange[1]; m++ ) - { - spreadCohSum = L_add( spreadCohSum, Mpy_32_16_1( hMasa->data.energy_fx[j][m], hMeta->directional_meta[i].spread_coherence_fx[j][m] ) ); // hMasa->data.q_energy - } - hMeta->directional_meta[i].spread_coherence_fx[j][k] = BASOP_Util_Divide3232_Scale( spreadCohSum, L_add( energySum, EPSILON_FX ), &exp_diff ); - move16(); - hMeta->directional_meta[i].spread_coherence_fx[j][k] = shl( hMeta->directional_meta[i].spread_coherence_fx[j][k], exp_diff ); // Q15 - move16(); + /* Set qmeta to correct values */ + if ( ( error = ivas_qmetadata_allocate_memory( hQMetaData, hMasa->config.numCodingBands, hMasa->config.numberOfDirections == 2 && hMasa->config.numTwoDirBands != 0 ? 2 : 1, hMasa->config.useCoherence ) ) != IVAS_ERR_OK ) + { + return error; + } - IF( i == 0 ) - { - surrCohSum = 0; - move32(); - FOR( m = brange[0]; m < brange[1]; m++ ) - { - surrCohSum = L_add( surrCohSum, Mpy_32_16_1( hMasa->data.energy_fx[j][m], hMeta->common_meta.surround_coherence_fx[j][m] ) ); // hMasa->data.q_energy - } - hMeta->common_meta.surround_coherence_fx[j][k] = BASOP_Util_Divide3232_Scale( surrCohSum, L_add( energySum, EPSILON_FX ), &exp_diff ); - move16(); - hMeta->common_meta.surround_coherence_fx[j][k] = shl( hMeta->common_meta.surround_coherence_fx[j][k], exp_diff ); // Q15 - move16(); - } - } + for ( i = 0; i < hQMetaData->no_directions; i++ ) + { + hQMetaData->q_direction[i].cfg.nbands = hMasa->config.numCodingBands; + hQMetaData->q_direction[i].cfg.nblocks = hMasa->config.joinedSubframes == TRUE ? 1 : 4; - if ( i == 0 ) - { - energy[j][k] = energySum; // hMasa->data.q_energy - move32(); - } - } - } + if ( ivas_format == MC_FORMAT ) + { + hQMetaData->q_direction[i].cfg.mc_ls_setup = st_ivas->hEncoderConfig->mc_input_setup; } - } - ELSE IF( mergeRatiosOverSubframes ) /* keep frequency resolution */ - { - FOR( j = 0; j < numSf; j++ ) + else { - FOR( k = 0; k < numCodingBands; k++ ) - { - energy[j][k] = hMasa->data.energy_fx[j][k]; // hMasa->data.q_energy - move32(); - } + /* Just to be sure that this default value is maintained */ + hQMetaData->q_direction[i].cfg.mc_ls_setup = MC_LS_SETUP_INVALID; } } - IF( mergeRatiosOverSubframes ) + hQMetaData->all_coherence_zero = !hMasa->config.coherencePresent; + + ivas_set_qmetadata_maxbit_req( hQMetaData, ivas_format ); + + /* Find maximum band usable */ + maxBin = (int16_t) ( st_ivas->hEncoderConfig->input_Fs * INV_CLDFB_BANDWIDTH ); + maxBand = 0; + while ( maxBand <= MASA_FREQUENCY_BANDS && MASA_band_grouping_24[maxBand] <= maxBin ) { - FOR( k = 0; k < numCodingBands; k++ ) - { - guard_bits = 0; - move16(); - energySum = 0; - move32(); - FOR( j = 0; j < numSf; j++ ) - { - energySum = L_add( energySum, L_shr( energy[j][k], guard_bits ) ); // hMasa->data.q_energy - guard_bits - } + maxBand++; + } + maxBand--; - IF( computeCoherence ) + st_ivas->hQMetaData->q_direction->cfg.inactiveBands = 0; + masa_total_brate = ivas_total_brate; +#ifndef IVAS_FLOAT_FIXED + if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + masa_total_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->hEncoderConfig->nchan_ism ); + } +#else + test(); + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + masa_total_brate = calculate_cpe_brate_MASA_ISM_fx( st_ivas->ism_mode, ivas_total_brate, st_ivas->hEncoderConfig->nchan_ism ); + } +#endif + if ( masa_total_brate >= IVAS_384k && ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) ) + { + int16_t continueLoop; + continueLoop = 1; + while ( maxBand > 5 && continueLoop ) + { + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - surrCohSum = 0; - move32(); - FOR( j = 0; j < numSf; j++ ) - { - surrCohSum = L_add( surrCohSum, Mpy_32_16_1( L_shr( energy[j][k], guard_bits ), hMeta->common_meta.surround_coherence_fx[j][k] ) ); // hMasa->data.q_energy - guard_bits - } - surrCohTemp = BASOP_Util_Divide3232_Scale( surrCohSum, L_add( energySum, EPSILON_FX ), &exp_diff ); - surrCohTemp = shl( surrCohTemp, exp_diff ); // Q15 - - FOR( j = 0; j < numSf; j++ ) + if ( hMasa->data.energy[sf][maxBand - 1] > 100000 ) { - hMeta->common_meta.surround_coherence_fx[j][k] = surrCohTemp; // Q15 - move16(); + continueLoop = 0; + break; } } - - FOR( i = 0; i < numDirections; i++ ) + if ( continueLoop ) { - energyRatioSum = 0; - move32(); - FOR( j = 0; j < numSf; j++ ) - { - energyRatioSum = L_add( energyRatioSum, Mpy_32_32( L_shr( energy[j][k], guard_bits ), hMeta->directional_meta[i].energy_ratio_fx[j][k] ) ); // hMasa->data.q_energy - guard_bits - Q1 - } - energyRatioTemp = BASOP_Util_Divide3232_Scale_cadence( energyRatioSum, L_add( energySum, EPSILON_FX ), &exp_diff ); - energyRatioTemp = L_shl( energyRatioTemp, exp_diff ); // (exp_diff + ((hMasa->data.q_energy - guard_bits) - (hMasa->data.q_energy - guard_bits - Q1))) -> Q30 - - FOR( j = 0; j < numSf; j++ ) - { - hMeta->directional_meta[i].energy_ratio_fx[j][k] = energyRatioTemp; // Q30 - move32(); - } + maxBand--; } } + + if ( maxBand < MASA_MAXIMUM_CODING_SUBBANDS ) + { + st_ivas->hQMetaData->q_direction->cfg.inactiveBands = MASA_MAXIMUM_CODING_SUBBANDS - maxBand; + } + else + { + st_ivas->hQMetaData->q_direction->cfg.inactiveBands = 0; + } } - return; -} +#ifndef IVAS_FLOAT_FIXED + masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, masa_total_brate >= IVAS_384k, NULL ); #else -static void combine_freqbands_and_subframes( - MASA_ENCODER_HANDLE hMasa ) -{ - int16_t i, j, k, m; - float aziRad, eleRad; - float x[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - float y[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - float z[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - float vecLen; - float xSum, ySum, zSum; - float energySum; - float spreadCohSum; - float surrCohSum; - float energyRatioSum; - float surrCohTemp; - float energyRatioTemp; - float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - int16_t brange[2]; - uint8_t numCodingBands; - uint8_t numSf; - uint8_t numDirections; - MASA_METADATA_HANDLE hMeta; - uint8_t mergeRatiosOverSubframes; - uint8_t computeCoherence; + Word16 numBands48k = hMasa->config.numCodingBands, band; - numCodingBands = hMasa->config.numCodingBands; - numDirections = hMasa->config.numberOfDirections; - numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - hMeta = &( hMasa->masaMetadata ); - - mergeRatiosOverSubframes = hMasa->config.mergeRatiosOverSubframes; - computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; - - /* If metadata subframes are joined then we need all energy to be in the first subframe for combining. - * This optimizes following computations a bit. - * Note: If energy is used elsewhere, then this can cause problems and local energy should be used. */ - if ( numSf == 1 ) + for ( band = 0; band < numBands48k; band++ ) { - for ( j = 1; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + floatToFixed_arrL( hQMetaData->q_direction[0].band_data[band].azimuth, hQMetaData->q_direction[0].band_data[band].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + floatToFixed_arrL( hQMetaData->q_direction[0].band_data[band].elevation, hQMetaData->q_direction[0].band_data[band].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + floatToFixed_arrL( hQMetaData->q_direction[0].band_data[band].energy_ratio, hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + if ( hQMetaData->no_directions == 2 ) { - for ( k = 0; k < MASA_FREQUENCY_BANDS; k++ ) - { - hMasa->data.energy[0][k] += hMasa->data.energy[j][k]; - } + floatToFixed_arrL( hQMetaData->q_direction[1].band_data[band].azimuth, hQMetaData->q_direction[1].band_data[band].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + floatToFixed_arrL( hQMetaData->q_direction[1].band_data[band].elevation, hQMetaData->q_direction[1].band_data[band].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + floatToFixed_arrL( hQMetaData->q_direction[1].band_data[band].energy_ratio, hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } - if ( numCodingBands <= MAX_REDUCED_NBANDS ) + masa_sample_rate_band_correction_fx( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, masa_total_brate >= IVAS_384k, NULL ); + + for ( band = 0; band < numBands48k; band++ ) { - /* reduce metadata *frequency* resolution. time resolution is not touched */ - for ( i = 0; i < numDirections; i++ ) + fixedToFloat_arrL( hQMetaData->q_direction[0].band_data[band].azimuth_fx, hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( hQMetaData->q_direction[0].band_data[band].elevation_fx, hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + if ( hQMetaData->no_directions == 2 ) { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - for ( k = 0; k < MASA_FREQUENCY_BANDS; k++ ) - { - aziRad = hMeta->directional_meta[i].azimuth[j][k] / 180.0f * EVS_PI; - eleRad = hMeta->directional_meta[i].elevation[j][k] / 180.0f * EVS_PI; - vecLen = hMeta->directional_meta[i].energy_ratio[j][k] * hMasa->data.energy[j][k]; - - x[i][j][k] = cosf( aziRad ) * cosf( eleRad ) * vecLen; - y[i][j][k] = sinf( aziRad ) * cosf( eleRad ) * vecLen; - z[i][j][k] = sinf( eleRad ) * vecLen; - } - } + fixedToFloat_arrL( hQMetaData->q_direction[1].band_data[band].azimuth_fx, hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( hQMetaData->q_direction[1].band_data[band].elevation_fx, hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } + } +#endif - for ( i = 0; i < numDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) - { - for ( k = 0; k < numCodingBands; k++ ) - { - brange[0] = hMasa->data.band_mapping[k]; - brange[1] = hMasa->data.band_mapping[k + 1]; - - xSum = 0.0f; - ySum = 0.0f; - zSum = 0.0f; - energySum = 0.0f; - spreadCohSum = 0.0f; - - for ( m = brange[0]; m < brange[1]; m++ ) - { - xSum += x[i][j][m]; - ySum += y[i][j][m]; - zSum += z[i][j][m]; - energySum += hMasa->data.energy[j][m]; - } - - aziRad = atan2f( ySum, xSum ); - eleRad = atan2f( zSum, sqrtf( xSum * xSum + ySum * ySum ) ); - - hMeta->directional_meta[i].azimuth[j][k] = aziRad / EVS_PI * 180.0f; - hMeta->directional_meta[i].elevation[j][k] = eleRad / EVS_PI * 180.0f; - - vecLen = sqrtf( xSum * xSum + ySum * ySum + zSum * zSum ); - hMeta->directional_meta[i].energy_ratio[j][k] = vecLen / ( energySum + EPSILON ); - - if ( computeCoherence ) - { - for ( m = brange[0]; m < brange[1]; m++ ) - { - spreadCohSum += hMeta->directional_meta[i].spread_coherence[j][m] * hMasa->data.energy[j][m]; - } - hMeta->directional_meta[i].spread_coherence[j][k] = spreadCohSum / ( energySum + EPSILON ); - - if ( i == 0 ) - { - surrCohSum = 0.0f; - for ( m = brange[0]; m < brange[1]; m++ ) - { - surrCohSum += hMeta->common_meta.surround_coherence[j][m] * hMasa->data.energy[j][m]; - } - hMeta->common_meta.surround_coherence[j][k] = surrCohSum / ( energySum + EPSILON ); - } - } + if ( hMasa->config.numTwoDirBands >= hMasa->config.numCodingBands ) + { + hMasa->config.numTwoDirBands = hMasa->config.numCodingBands; + set_c( (int8_t *) hMasa->data.twoDirBands, 1, hMasa->config.numCodingBands ); + } - if ( i == 0 ) - { - energy[j][k] = energySum; - } - } - } - } + /* Transmit stereo signals using a mono downmix at lowest bitrates */ + if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && st_ivas->nCPE == 1 && st_ivas->hCPE[0]->hStereoDft != NULL && st_ivas->hCPE[0]->hStereoDft->hConfig != NULL ) + { + st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = ( ivas_total_brate - ism_total_brate < MASA_STEREO_MIN_BITRATE ) ? 1 : 0; } - else if ( mergeRatiosOverSubframes ) /* keep frequency resolution */ + + if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) { - for ( j = 0; j < numSf; j++ ) + if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT || st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX ) { - for ( k = 0; k < numCodingBands; k++ ) - { - energy[j][k] = hMasa->data.energy[j][k]; - } +#ifndef IVAS_FLOAT_FIXED + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE = st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise; +#else + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise_fx; +#endif + } + else + { +#ifndef IVAS_FLOAT_FIXED + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE = ( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise + st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise ) / CPE_CHANNELS; +#else + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = shr( add( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise_fx, st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise_fx ), 1 ); +#endif } } - if ( mergeRatiosOverSubframes ) - { - for ( k = 0; k < numCodingBands; k++ ) - { - energySum = 0.0f; - for ( j = 0; j < numSf; j++ ) - { - energySum += energy[j][k]; - } + return error; +} +#endif // IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED +/*-----------------------------------------------------------------------* + * ivas_masa_surrcoh_signicant() + * + * Determine if surrounding coherence is significant in this frame and should be encoded + *-----------------------------------------------------------------------*/ +UWord8 ivas_masa_surrcoh_signicant_fx( + Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence */ + Word32 diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio */ + const Word16 nSubFrames, /* i : Number of sub frames */ + const Word16 nBands /* i : Number of frequency bands */ /* i : dynamic (min q for surroundingCoherence and diffuse_to_total_ratio) */ +) +{ + Word32 significanceMeasure1, significanceMeasure2, significanceMeasure; + Word32 surrCohToTotal, surrCohToTotalSum, surrCohToTotalTimesDiffSum, diffSum; + Word32 sf, band; + Word16 surrCohToTotalSum_e, surrCohToTotalTimesDiffSum_e, diffSum_e; - if ( computeCoherence ) - { - surrCohSum = 0.0f; - for ( j = 0; j < numSf; j++ ) - { - surrCohSum += energy[j][k] * hMeta->common_meta.surround_coherence[j][k]; - } - surrCohTemp = surrCohSum / ( energySum + EPSILON ); + // input buffers Q=31 + Word32 surrCohSignificanceCoef = 858993459; //( 0.4 * ( 1 << q ) ) 0.4 scaled to Q=31 + move32(); + Word32 threshold = 214748365; //( 0.1 * ( 1 << q ) ) 0.1 scaled to Q=31 + move32(); + FOR( sf = 0; sf < nSubFrames; sf++ ) + { + surrCohToTotalSum = 0; + move32(); + surrCohToTotalSum_e = 0; + move16(); + surrCohToTotalTimesDiffSum = 0; + move32(); + surrCohToTotalTimesDiffSum_e = 0; + move16(); + diffSum = 0; + move32(); + diffSum_e = 0; + move16(); - for ( j = 0; j < numSf; j++ ) - { - hMeta->common_meta.surround_coherence[j][k] = surrCohTemp; - } - } + FOR( band = 0; band < nBands; band++ ) + { + surrCohToTotal = Mpy_32_32( diffuse_to_total_ratio[sf][band], surroundingCoherence[sf][band] ); // 2Q -> Q + surrCohToTotalSum = BASOP_Util_Add_Mant32Exp( surrCohToTotalSum, surrCohToTotalSum_e, surrCohToTotal, 0, &surrCohToTotalSum_e ); + surrCohToTotalTimesDiffSum = BASOP_Util_Add_Mant32Exp( surrCohToTotalTimesDiffSum, surrCohToTotalTimesDiffSum_e, Mpy_32_32( (Word32) diffuse_to_total_ratio[sf][band], surrCohToTotal ), 0, &surrCohToTotalTimesDiffSum_e ); // Q2 -> Q + diffSum = BASOP_Util_Add_Mant32Exp( diffSum, diffSum_e, diffuse_to_total_ratio[sf][band], 0, &diffSum_e ); // Q + } - for ( i = 0; i < numDirections; i++ ) - { - energyRatioSum = 0.0f; - for ( j = 0; j < numSf; j++ ) - { - energyRatioSum += energy[j][k] * hMeta->directional_meta[i].energy_ratio[j][k]; - } - energyRatioTemp = energyRatioSum / ( energySum + EPSILON ); + Word16 significanceMeasure1_e, significanceMeasure2_e; + Word16 significanceMeasure_e; + significanceMeasure1 = L_deposit_h( BASOP_Util_Divide3216_Scale( surrCohToTotalSum, nBands, &significanceMeasure1_e ) ); // e1 exponent + significanceMeasure1_e = add( significanceMeasure1_e, sub( surrCohToTotalSum_e, 15 ) ); + significanceMeasure2 = L_deposit_h( BASOP_Util_Divide3232_Scale( Mpy_32_32( surrCohSignificanceCoef, surrCohToTotalTimesDiffSum ), L_add( diffSum, EPSILON_FX ), &significanceMeasure2_e ) ); // e2 exponent + significanceMeasure2_e = add( significanceMeasure2_e, sub( surrCohToTotalTimesDiffSum_e, diffSum_e ) ); - for ( j = 0; j < numSf; j++ ) - { - hMeta->directional_meta[i].energy_ratio[j][k] = energyRatioTemp; - } - } + IF( BASOP_Util_Cmp_Mant32Exp( significanceMeasure1, significanceMeasure1_e, significanceMeasure2, significanceMeasure2_e ) > 0 ) + { + significanceMeasure = significanceMeasure1; + move32(); + significanceMeasure_e = significanceMeasure1_e; + move16(); + } + ELSE + { + significanceMeasure = significanceMeasure2; + move32(); + significanceMeasure_e = significanceMeasure2_e; + move16(); + } + IF( BASOP_Util_Cmp_Mant32Exp( significanceMeasure, significanceMeasure_e, threshold, 0 ) > 0 ) // Q31 Comparision + { + return 1; } } - return; + return 0; } -#endif - - -/*-------------------------------------------------------------------* - * ivas_masa_combine_directions() - * +#else +/*-----------------------------------------------------------------------* + * ivas_masa_surrcoh_signicant() * - *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -void ivas_masa_combine_directions_fx( - MASA_ENCODER_HANDLE hMasa ) -{ - Word16 i, j, k; + * Determine if surrounding coherence is significant in this frame and should be encoded + *-----------------------------------------------------------------------*/ + +uint8_t ivas_masa_surrcoh_signicant( + float surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence */ + float diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio */ + const int16_t nSubFrames, /* i : Number of sub frames */ + const int16_t nBands /* i : Number of frequency bands */ +) +{ + float significanceMeasure1, significanceMeasure2, significanceMeasure; + float surrCohToTotal, surrCohToTotalSum, surrCohToTotalTimesDiffSum, diffSum; + int16_t sf, band; + float surrCohSignificanceCoef = 0.4f; + float threshold = 0.1f; + + for ( sf = 0; sf < nSubFrames; sf++ ) + { + surrCohToTotalSum = 0.0f; + surrCohToTotalTimesDiffSum = 0.0f; + diffSum = 0.0f; + for ( band = 0; band < nBands; band++ ) + { + surrCohToTotal = diffuse_to_total_ratio[sf][band] * surroundingCoherence[sf][band]; + surrCohToTotalSum += surrCohToTotal; + surrCohToTotalTimesDiffSum += diffuse_to_total_ratio[sf][band] * surrCohToTotal; + diffSum += diffuse_to_total_ratio[sf][band]; + } + significanceMeasure1 = surrCohToTotalSum / (float) nBands; + significanceMeasure2 = surrCohSignificanceCoef * surrCohToTotalTimesDiffSum / ( diffSum + EPSILON ); + significanceMeasure = max( significanceMeasure1, significanceMeasure2 ); + + if ( significanceMeasure > threshold ) + { + return 1; /* Surrounding coherence was significant in at least one subframe */ + } + } + + return 0; /* Surrounding coherence was not significant in any subframe */ +} +#endif + +/*-----------------------------------------------------------------------* + * Local functions + *-----------------------------------------------------------------------*/ + +#ifdef IVAS_FLOAT_FIXED +static void combine_freqbands_and_subframes_fx( + MASA_ENCODER_HANDLE hMasa ) +{ + Word16 i, j, k, m; + Word16 aziRad, eleRad; + Word32 x[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 y[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 z[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 vecLen; + Word16 vecLen_e; + Word32 xSum, ySum, zSum; + Word16 xSum_e, ySum_e, zSum_e, common_e; + Word64 xSum_sq, ySum_sq, zSum_sq; + Word32 energySum; + Word16 energySum_e; + Word32 spreadCohSum; + Word16 spreadCohSum_e; + Word32 surrCohSum; + Word16 surrCohSum_e; + Word32 energyRatioSum; + Word16 energyRatioSum_e; + Word16 surrCohTemp; + Word32 energyRatioTemp; + Word32 energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 energy_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 brange[2]; UWord8 numCodingBands; UWord8 numSf; UWord8 numDirections; - UWord8 computeCoherence; MASA_METADATA_HANDLE hMeta; - - Word16 aziRad_fx; - Word16 eleRad_fx; - Word32 x_fx[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 y_fx[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 z_fx[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 vecLen_fx; - Word32 xSum_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 ySum_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 zSum_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 sumVecLen_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word16 exp_sumVecLen_buff[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], exp_sumVecLen = MIN16B_FLT_FX; - move16(); - Word32 tempImportance_fx; - Word16 exp_tmp_importance = 0; - move16(); - Word32 importance_fx[MASA_FREQUENCY_BANDS]; - Word16 exp_importance_buff[MASA_FREQUENCY_BANDS], exp_importance = MIN16B_FLT_FX; - move16(); - Word16 indicesOfLargest[MASA_FREQUENCY_BANDS]; - - Word32 ratioSum_fx; - Word32 ambience1dir_fx; - Word32 ambience2dir_fx; - Word32 ambienceIncrease_fx; - Word32 origSurrCohEne_fx; - Word32 newSurrCohEne_fx; + UWord8 mergeRatiosOverSubframes; + UWord8 computeCoherence; + Word16 exp_diff; + Word32 L_tmp; + Word64 W_tmp; + Word16 q_shift; numCodingBands = hMasa->config.numCodingBands; - numDirections = hMasa->config.numberOfDirections; move16(); + numDirections = hMasa->config.numberOfDirections; move16(); - IF( EQ_16( hMasa->config.joinedSubframes, TRUE ) ) { numSf = 1; + move16(); } ELSE { numSf = MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); } - move16(); hMeta = &( hMasa->masaMetadata ); - computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; - move16(); - Word16 azi_cos = 0, azi_sine = 0, ele_cos = 0, ele_sine = 0; - move16(); - move16(); - move16(); + mergeRatiosOverSubframes = hMasa->config.mergeRatiosOverSubframes; move16(); - FOR( i = 0; i < numDirections; i++ ) + test(); + IF( hMasa->config.useCoherence && hMasa->config.coherencePresent ) { - FOR( j = 0; j < numSf; j++ ) + computeCoherence = 1; + move16(); + } + ELSE + { + computeCoherence = 0; + move16(); + } + + /* If metadata subframes are joined then we need all energy to be in the first subframe for combining. + * This optimizes following computations a bit. + * Note: If energy is used elsewhere, then this can cause problems and local energy should be used. */ + IF( EQ_16( numSf, 1 ) ) + { + FOR( j = 1; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - FOR( k = 0; k < numCodingBands; k++ ) + FOR( k = 0; k < MASA_FREQUENCY_BANDS; k++ ) { - aziRad_fx = extract_l( L_shr( Mpy_32_32( hMeta->directional_meta[i].azimuth_fx[j][k], PI_OVER_180_Q25 ), 3 ) ); // (Q22 + Q25 - 31) - 3 = Q13 - azi_cos = getCosWord16( aziRad_fx ); // Q14 - azi_sine = getSinWord16( aziRad_fx ); // Q15 - - eleRad_fx = extract_l( L_shr( Mpy_32_32( hMeta->directional_meta[i].elevation_fx[j][k], PI_OVER_180_Q25 ), 3 ) ); // (Q22 + Q25 - 31) - 3 = Q13 - ele_sine = getSinWord16( eleRad_fx ); // Q15 - ele_cos = getCosWord16( eleRad_fx ); // Q14 - - vecLen_fx = hMeta->directional_meta[i].energy_ratio_fx[j][k]; - move32(); - - x_fx[i][j][k] = L_mult0( azi_cos, ele_cos ); // Q14+Q14 - x_fx[i][j][k] = Mpy_32_32( x_fx[i][j][k], vecLen_fx ); // Q28+Q30-31 - y_fx[i][j][k] = L_mult0( azi_sine, ele_cos ); // Q15+Q14 - y_fx[i][j][k] = Mpy_32_32( y_fx[i][j][k], vecLen_fx ); // Q29+Q30-31 - z_fx[i][j][k] = Mpy_32_32( L_deposit_h( ele_sine ), vecLen_fx ); // Q16+Q15+Q30 - 31 - move32(); - move32(); - move32(); - move32(); + hMasa->data.energy_fx[0][k] = BASOP_Util_Add_Mant32Exp( hMasa->data.energy_fx[0][k], hMasa->data.energy_e[0][k], hMasa->data.energy_fx[j][k], hMasa->data.energy_e[j][k], &hMasa->data.energy_e[0][k] ); // 31-hMasa->data.energy_e[0][k] move32(); } } } - /* Compute sum vector */ - FOR( j = 0; j < numSf; j++ ) + IF( LE_16( numCodingBands, MAX_REDUCED_NBANDS ) ) { - FOR( k = 0; k < numCodingBands; k++ ) + /* reduce metadata *frequency* resolution. time resolution is not touched */ + FOR( i = 0; i < numDirections; i++ ) { - xSum_fx[j][k] = L_add( x_fx[0][j][k], x_fx[1][j][k] ); // Q27 - ySum_fx[j][k] = L_add( y_fx[0][j][k], y_fx[1][j][k] ); // Q28 - zSum_fx[j][k] = L_add( z_fx[0][j][k], z_fx[1][j][k] ); // Q30 - move32(); - move32(); - move32(); - - Word32 var1 = Mpy_32_32( xSum_fx[j][k], xSum_fx[j][k] ); // Q27 + Q27 - 31 //Q23 - Word32 var2 = Mpy_32_32( ySum_fx[j][k], ySum_fx[j][k] ); // Q28 + Q28 - 31 //Q25 - Word32 var3 = Mpy_32_32( zSum_fx[j][k], zSum_fx[j][k] ); // Q30 + Q30 - 31 //Q29 - Word32 var4 = L_add( L_add( var1, L_shr( var2, 2 ) ), L_shr( var3, 6 ) ); // Q23 - Word16 exp_var4 = 31 - Q23; - move16(); - - Word16 exp_var5 = exp_var4; - move16(); - Word32 var5 = 0; - move32(); - - IF( var4 != 0 ) + FOR( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ { - var5 = Sqrt32( var4, &exp_var5 ); + FOR( k = 0; k < MASA_FREQUENCY_BANDS; k++ ) + { + aziRad = extract_l( L_shl( Mpy_32_32( hMeta->directional_meta[i].azimuth_fx[j][k], PI_OVER_180_FX ), Q13 - Q22 ) ); // ((Q22, Q31) -> Q22) >> Q9 -> Q13 + eleRad = extract_l( L_shl( Mpy_32_32( hMeta->directional_meta[i].elevation_fx[j][k], PI_OVER_180_FX ), Q13 - Q22 ) ); // ((Q22, Q31) -> Q22) >> Q9 -> Q13 + vecLen = Mpy_32_32( hMeta->directional_meta[i].energy_ratio_fx[j][k], hMasa->data.energy_fx[j][k] ); // (Q30, 31-hMasa->data.energy_e[j][k]) -> (31-hMasa->data.energy_e[j][k]) - Q1 + + x[i][j][k] = Mpy_32_32( L_mult( getCosWord16( aziRad ), getCosWord16( eleRad ) ), vecLen ); // (Q29, (31-hMasa->data.energy_e[j][k]) - Q1) -> (31-hMasa->data.energy_e[j][k]) - Q3 + move32(); + y[i][j][k] = Mpy_32_32( L_mult0( getSinWord16( aziRad ), getCosWord16( eleRad ) ), vecLen ); // (Q29, (31-hMasa->data.energy_e[j][k]) - Q1) -> (31-hMasa->data.energy_e[j][k]) - Q3 + move32(); + z[i][j][k] = Mpy_32_32( L_mult0( getSinWord16( eleRad ), ONE_IN_Q14 ), vecLen ); // (Q29, (31-hMasa->data.energy_e[j][k]) - Q1) -> (31-hMasa->data.energy_e[j][k]) - Q3 + move32(); + } } - sumVecLen_fx[j][k] = var5; - move32(); - exp_sumVecLen_buff[j][k] = exp_var5; - move16(); } - } - /*make commen exp for sumVecLen_fx buffer*/ - FOR( j = 0; j < numSf; j++ ) - { - FOR( k = 0; k < numCodingBands; k++ ) + FOR( i = 0; i < numDirections; i++ ) { - exp_sumVecLen = s_max( exp_sumVecLen_buff[j][k], exp_sumVecLen ); - } - } + FOR( j = 0; j < numSf; j++ ) + { + FOR( k = 0; k < numCodingBands; k++ ) + { + brange[0] = hMasa->data.band_mapping[k]; + move16(); + brange[1] = hMasa->data.band_mapping[k + 1]; + move16(); - FOR( j = 0; j < numSf; j++ ) - { - FOR( k = 0; k < numCodingBands; k++ ) - { - sumVecLen_fx[j][k] = L_shr( sumVecLen_fx[j][k], sub( exp_sumVecLen, exp_sumVecLen_buff[j][k] ) ); - move32(); - } - } + xSum = 0; + ySum = 0; + zSum = 0; + energySum = 0; + spreadCohSum = 0; + xSum_e = 0; + ySum_e = 0; + zSum_e = 0; + energySum_e = 0; + spreadCohSum_e = 0; + move32(); + move32(); + move32(); + move32(); + move32(); + move16(); + move16(); + move16(); + move16(); + move16(); - /* Estimate the importance of having two directions instead of one */ - FOR( i = 0; i < numCodingBands; i++ ) - { - importance_fx[i] = 0; - move32(); - FOR( j = 0; j < numSf; j++ ) - { - tempImportance_fx = L_add( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[1].energy_ratio_fx[j][i] ); - exp_tmp_importance = 0; - move16(); - tempImportance_fx = BASOP_Util_Add_Mant32Exp( tempImportance_fx, 31 - Q30, L_negate( sumVecLen_fx[j][i] ), exp_sumVecLen, &exp_tmp_importance ); - importance_fx[i] = BASOP_Util_Add_Mant32Exp( importance_fx[i], exp_importance_buff[i], tempImportance_fx, exp_tmp_importance, &exp_importance_buff[i] ); - move32(); - } + FOR( m = brange[0]; m < brange[1]; m++ ) + { + xSum = BASOP_Util_Add_Mant32Exp( xSum, xSum_e, x[i][j][m], add( hMasa->data.energy_e[j][m], 3 ), &xSum_e ); // xSum_e + ySum = BASOP_Util_Add_Mant32Exp( ySum, ySum_e, y[i][j][m], add( hMasa->data.energy_e[j][m], 3 ), &ySum_e ); // ySum_e + zSum = BASOP_Util_Add_Mant32Exp( zSum, zSum_e, z[i][j][m], add( hMasa->data.energy_e[j][m], 3 ), &zSum_e ); // zSum_e + energySum = BASOP_Util_Add_Mant32Exp( energySum, energySum_e, hMasa->data.energy_fx[j][m], hMasa->data.energy_e[j][m], &energySum_e ); // energySum_e + } + common_e = add( s_max( xSum_e, s_max( ySum_e, zSum_e ) ), 2 ); /*2 is guard bit for addition operations*/ + xSum = L_shr( xSum, sub( common_e, xSum_e ) ); /*common_e*/ + ySum = L_shr( ySum, sub( common_e, ySum_e ) ); /*common_e*/ + zSum = L_shr( zSum, sub( common_e, zSum_e ) ); /*common_e*/ + aziRad = BASOP_util_atan2( ySum, xSum, 0 ); // Q13 + xSum_sq = W_mult0_32_32( xSum, xSum ); // 2 * (31-common_e) + ySum_sq = W_mult0_32_32( ySum, ySum ); // 2 * (31-common_e) + zSum_sq = W_mult0_32_32( zSum, zSum ); // 2 * (31-common_e) + W_tmp = W_add( xSum_sq, ySum_sq ); // 2 * (31-common_e) + q_shift = W_norm( W_tmp ); + L_tmp = W_extract_h( W_shl( W_tmp, q_shift ) ); // 2 * (31-common_e) + (q_shift -32) + exp_diff = sub( Q31, add( imult1616( 2, sub( 31, common_e ) ), sub( q_shift, 32 ) ) ); + L_tmp = Sqrt32( L_tmp, &exp_diff ); + eleRad = BASOP_util_atan2( zSum, L_tmp, sub( common_e, exp_diff ) ); // Q13 - if ( numSf != 1 ) - { - importance_fx[i] = L_shr( importance_fx[i], 2 ); - move32(); - } - importance_fx[i] = Mpy_32_32( importance_fx[i], hMasa->data.importanceWeight_fx[i] ); - move32(); - exp_importance_buff[i] = add( exp_importance_buff[i], 1 ); - move16(); - } + hMeta->directional_meta[i].azimuth_fx[j][k] = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, aziRad ), Q1 ); // ((Q25, Q13) -> Q23) >> Q1 -> Q22 + move32(); + hMeta->directional_meta[i].elevation_fx[j][k] = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, eleRad ), Q1 ); // ((Q25, Q13) -> Q23) >> Q1 -> Q22 + move32(); - /*make commen exp for importance_fx buffer*/ - FOR( i = 0; i < numCodingBands; i++ ) - { - exp_importance = s_max( exp_importance_buff[i], exp_importance ); - } - FOR( i = 0; i < numCodingBands; i++ ) - { - importance_fx[i] = L_shr( importance_fx[i], sub( exp_importance, exp_importance_buff[i] ) ); - move32(); - } + W_tmp = W_add( xSum_sq, ySum_sq ); // 2 * (31-common_e) + W_tmp = W_add( W_tmp, zSum_sq ); // 2 * (31-common_e) + q_shift = W_norm( W_tmp ); + vecLen = W_extract_h( W_shl( W_tmp, q_shift ) ); // 2 * (31-common_e) + (q_shift -32) + exp_diff = sub( Q31, add( imult1616( 2, sub( 31, common_e ) ), sub( q_shift, 32 ) ) ); + vecLen = Sqrt32( vecLen, &exp_diff ); + vecLen_e = exp_diff; + move16(); - /* Determine bands where to use two directions */ - find_n_largest_fx( importance_fx, exp_importance, indicesOfLargest, numCodingBands, hMasa->config.numTwoDirBands ); + hMeta->directional_meta[i].energy_ratio_fx[j][k] = + BASOP_Util_Divide3232_Scale_cadence( vecLen, L_add( energySum, EPSILON_FX ), &exp_diff ); /*exp_diff+vecLen_e-energySum_e*/ + move32(); + exp_diff = add( exp_diff, sub( vecLen_e, energySum_e ) ); + hMeta->directional_meta[i].energy_ratio_fx[j][k] = + L_shl( hMeta->directional_meta[i].energy_ratio_fx[j][k], sub( exp_diff, Q1 ) ); // (Q31 - exp_diff ) -> Q30 + move32(); - FOR( i = 0; i < numCodingBands; i++ ) - { - hMasa->data.twoDirBands[i] = 0; - move16(); - } + IF( computeCoherence ) + { + FOR( m = brange[0]; m < brange[1]; m++ ) + { + spreadCohSum = BASOP_Util_Add_Mant32Exp( spreadCohSum, spreadCohSum_e, Mpy_32_16_1( hMasa->data.energy_fx[j][m], hMeta->directional_meta[i].spread_coherence_fx[j][m] ), hMasa->data.energy_e[j][m], &spreadCohSum_e ); // 31-spreadCohSum_e + } + hMeta->directional_meta[i].spread_coherence_fx[j][k] = BASOP_Util_Divide3232_Scale( spreadCohSum, L_add( energySum, EPSILON_FX ), &exp_diff ); /*exp_diff+spreadCohSum_e-energySum_e*/ + exp_diff = add( exp_diff, sub( spreadCohSum_e, energySum_e ) ); + move16(); + hMeta->directional_meta[i].spread_coherence_fx[j][k] = shl( hMeta->directional_meta[i].spread_coherence_fx[j][k], exp_diff ); // Q15 + move16(); - FOR( i = 0; i < hMasa->config.numTwoDirBands; i++ ) + IF( i == 0 ) + { + surrCohSum = 0; + surrCohSum_e = 0; + move32(); + move16(); + FOR( m = brange[0]; m < brange[1]; m++ ) + { + surrCohSum = BASOP_Util_Add_Mant32Exp( surrCohSum, surrCohSum_e, Mpy_32_16_1( hMasa->data.energy_fx[j][m], hMeta->common_meta.surround_coherence_fx[j][m] ), hMasa->data.energy_e[j][m], &surrCohSum_e ); // 31-surrCohSum_e + } + hMeta->common_meta.surround_coherence_fx[j][k] = BASOP_Util_Divide3232_Scale( surrCohSum, L_add( energySum, EPSILON_FX ), &exp_diff ); /*exp_diff+surrCohSum_e-energySum_e*/ + move16(); + exp_diff = add( exp_diff, sub( surrCohSum_e, energySum_e ) ); + hMeta->common_meta.surround_coherence_fx[j][k] = shl( hMeta->common_meta.surround_coherence_fx[j][k], exp_diff ); // Q15 + move16(); + } + } + + if ( i == 0 ) + { + energy[j][k] = energySum; // 31-energySum_e + energy_e[j][k] = energySum_e; + move32(); + move16(); + } + } + } + } + } + ELSE IF( mergeRatiosOverSubframes ) /* keep frequency resolution */ { - hMasa->data.twoDirBands[indicesOfLargest[i]] = 1; - move16(); + FOR( j = 0; j < numSf; j++ ) + { + FOR( k = 0; k < numCodingBands; k++ ) + { + energy[j][k] = hMasa->data.energy_fx[j][k]; // 31-hMasa->data.energy_e[j][k] + energy_e[j][k] = hMasa->data.energy_e[j][k]; + move32(); + move16(); + } + } } - /* Combine directions on the remaining bands */ - FOR( i = 0; i < numCodingBands; i++ ) + IF( mergeRatiosOverSubframes ) { - IF( hMasa->data.twoDirBands[i] == 0 ) + FOR( k = 0; k < numCodingBands; k++ ) { + energySum = 0; + move32(); + energySum_e = 0; + move16(); FOR( j = 0; j < numSf; j++ ) { - aziRad_fx = BASOP_util_atan2( ySum_fx[j][i], xSum_fx[j][i], Q27 - Q28 ); // Q13 - Word32 tmp1 = Mpy_32_32( xSum_fx[j][i], xSum_fx[j][i] ); // Q27+Q27-31 //Q23 - Word32 tmp2 = Mpy_32_32( ySum_fx[j][i], ySum_fx[j][i] ); // Q28+Q28-31 //Q25 - Word32 tmp3 = L_add( tmp1, L_shr( tmp2, 2 ) ); // Q23 - Word16 exp_tmp3 = 31 - Q23; - move16(); - Word32 tmp4 = Sqrt32( tmp3, &exp_tmp3 ); - eleRad_fx = BASOP_util_atan2( zSum_fx[j][i], tmp4, sub( sub( 31, Q30 ), exp_tmp3 ) ); - - Word16 exp_tmp5 = 0; - move16(); - Word16 tmp5 = BASOP_Util_Divide1616_Scale( aziRad_fx, EVS_PI_FX, &exp_tmp5 ); - Word16 Q_tmp6 = 0; - move16(); - Word32 tmp6 = L_mult( tmp5, 23040 /*180.0f in Q7*/ ); - Q_tmp6 = sub( 31, add( exp_tmp5, 8 ) ); + energySum = BASOP_Util_Add_Mant32Exp( energySum, energySum_e, energy[j][k], energy_e[j][k], &energySum_e ); // 31-energySum_e + } - Word16 exp_tmp7 = 0; - move16(); - Word16 tmp7 = BASOP_Util_Divide1616_Scale( eleRad_fx, EVS_PI_FX, &exp_tmp7 ); - Word16 Q_tmp8 = 0; + IF( computeCoherence ) + { + surrCohSum = 0; + surrCohSum_e = 0; + move32(); move16(); - Word32 tmp8 = L_mult( tmp7, 23040 /*180.0f in Q7*/ ); - Q_tmp8 = sub( 31, add( exp_tmp7, 8 ) ); - - Scale_sig32( &tmp6, 1, Q22 - Q_tmp6 ); - Scale_sig32( &tmp8, 1, Q22 - Q_tmp8 ); + FOR( j = 0; j < numSf; j++ ) + { + surrCohSum = BASOP_Util_Add_Mant32Exp( surrCohSum, surrCohSum_e, Mpy_32_16_1( energy[j][k], hMeta->common_meta.surround_coherence_fx[j][k] ), energy_e[j][k], &surrCohSum_e ); // 31-surrCohSum_e + } + surrCohTemp = BASOP_Util_Divide3232_Scale( surrCohSum, L_add( energySum, EPSILON_FX ), &exp_diff ); + exp_diff = add( exp_diff, sub( surrCohSum_e, energySum_e ) ); + surrCohTemp = shl( surrCohTemp, exp_diff ); // Q15 - hMeta->directional_meta[0].azimuth_fx[j][i] = tmp6; // Q22 - hMeta->directional_meta[0].elevation_fx[j][i] = tmp8; // Q22 - move32(); - move32(); - ratioSum_fx = L_add( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[1].energy_ratio_fx[j][i] ); // Q30 - IF( computeCoherence ) + FOR( j = 0; j < numSf; j++ ) { - Word32 var1 = Mpy_32_16_1( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[0].spread_coherence_fx[j][i] ); - Word32 var2 = Mpy_32_16_1( hMeta->directional_meta[1].energy_ratio_fx[j][i], hMeta->directional_meta[1].spread_coherence_fx[j][i] ); - Word32 var3 = L_add( var1, var2 ); // Q30 - Word16 exp_var4 = 0; - move16(); - Word32 var4 = BASOP_Util_Add_Mant32Exp( ratioSum_fx, 31 - Q30, EPSILON_FX_M, EPSILON_FX_E, &exp_var4 ); - Word16 exp_var5 = 0; - move16(); - Word16 var5 = BASOP_Util_Divide3232_Scale( var3, var4, &exp_var5 ); - exp_var5 = add( exp_var5, ( sub( sub( 31, Q30 ), exp_var4 ) ) ); - Scale_sig( &var5, 1, sub( Q15, sub( 15, exp_var5 ) ) ); - hMeta->directional_meta[0].spread_coherence_fx[j][i] = var5; // Q15 + hMeta->common_meta.surround_coherence_fx[j][k] = surrCohTemp; // Q15 move16(); } + } - ambience2dir_fx = L_sub( ONE_IN_Q30, ratioSum_fx ); // Q30 - Word32 ambience2dir_fx_by_2 = L_shr( ambience2dir_fx, 1 ); - Word32 var_a = L_add( L_add( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[1].energy_ratio_fx[j][i] ), ambience2dir_fx_by_2 ); // Q30 - Word16 exp_var_b = 0; - move16(); - Word16 var_b = BASOP_Util_Divide3232_Scale( sumVecLen_fx[j][i], var_a, &exp_var_b ); - exp_var_b = add( exp_var_b, sub( exp_sumVecLen, 1 ) ); - Word32 var_b_32 = L_deposit_h( var_b ); - hMeta->directional_meta[0].energy_ratio_fx[j][i] = L_shr( var_b_32, 1 - exp_var_b ); // Q30 - hMeta->directional_meta[1].energy_ratio_fx[j][i] = 0; // Q30 - move16(); + FOR( i = 0; i < numDirections; i++ ) + { + energyRatioSum = 0; + energyRatioSum_e = 0; + move32(); move16(); - - IF( computeCoherence ) + FOR( j = 0; j < numSf; j++ ) { - ambience1dir_fx = L_sub( ONE_IN_Q30, hMeta->directional_meta[0].energy_ratio_fx[j][i] ); // Q30 - ambienceIncrease_fx = L_max( L_sub( ambience1dir_fx, ambience2dir_fx ), 0 ); // Q30 - origSurrCohEne_fx = Mpy_32_16_1( ambience2dir_fx /*Q30*/, hMeta->common_meta.surround_coherence_fx[j][i] /*Q15*/ ); // Q30 - newSurrCohEne_fx = Mpy_32_16_1( ambienceIncrease_fx /*Q30*/, hMeta->directional_meta[0].spread_coherence_fx[j][i] /*Q15*/ ); // Q30 + energyRatioSum = BASOP_Util_Add_Mant32Exp( energyRatioSum, energyRatioSum_e, Mpy_32_32( energy[j][k], hMeta->directional_meta[i].energy_ratio_fx[j][k] ), add( energy_e[j][k], 1 ), &energyRatioSum_e ); // 31-energyRatioSum_e + } + energyRatioTemp = BASOP_Util_Divide3232_Scale_cadence( energyRatioSum, L_add( energySum, EPSILON_FX ), &exp_diff ); + exp_diff = add( exp_diff, sub( energyRatioSum_e, energySum_e ) ); + energyRatioTemp = L_shl( energyRatioTemp, sub( exp_diff, 1 ) ); // Q30 - Word16 exp_y = 0, exp_z = 0; - move16(); - move16(); - Word32 x = L_add( origSurrCohEne_fx, newSurrCohEne_fx ); // Q30 - Word32 y = BASOP_Util_Add_Mant32Exp( ambience1dir_fx, 1, EPSILON_FX_M, EPSILON_FX_E, &exp_y ); - Word16 z = BASOP_Util_Divide3232_Scale( x, y, &exp_z ); - exp_z = add( exp_z, ( sub( 31 - Q30, exp_y ) ) ); - z = shl_sat( z, exp_z ); // Q15 - hMeta->common_meta.surround_coherence_fx[j][i] = s_min( MAX16B, z ); - move16(); + FOR( j = 0; j < numSf; j++ ) + { + hMeta->directional_meta[i].energy_ratio_fx[j][k] = energyRatioTemp; // Q30 + move32(); } } } @@ -2994,131 +2532,180 @@ void ivas_masa_combine_directions_fx( return; } #else -void ivas_masa_combine_directions( +static void combine_freqbands_and_subframes( MASA_ENCODER_HANDLE hMasa ) { - int16_t i, j, k; - uint8_t numCodingBands; - uint8_t numSf; - uint8_t numDirections; - uint8_t computeCoherence; - MASA_METADATA_HANDLE hMeta; - - float aziRad; - float eleRad; + int16_t i, j, k, m; + float aziRad, eleRad; float x[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; float y[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; float z[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; float vecLen; - float xSum[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - float ySum[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - float zSum[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - float sumVecLen[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - float tempImportance; - float importance[MASA_FREQUENCY_BANDS]; - int16_t indicesOfLargest[MASA_FREQUENCY_BANDS]; - - float ambience1dir; - float ambience2dir; - float ambienceIncrease; - float ratioSum; - float origSurrCohEne; - float newSurrCohEne; + float xSum, ySum, zSum; + float energySum; + float spreadCohSum; + float surrCohSum; + float energyRatioSum; + float surrCohTemp; + float energyRatioTemp; + float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + int16_t brange[2]; + uint8_t numCodingBands; + uint8_t numSf; + uint8_t numDirections; + MASA_METADATA_HANDLE hMeta; + uint8_t mergeRatiosOverSubframes; + uint8_t computeCoherence; numCodingBands = hMasa->config.numCodingBands; numDirections = hMasa->config.numberOfDirections; numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - hMeta = &( hMasa->masaMetadata ); + mergeRatiosOverSubframes = hMasa->config.mergeRatiosOverSubframes; computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; - for ( i = 0; i < numDirections; i++ ) + /* If metadata subframes are joined then we need all energy to be in the first subframe for combining. + * This optimizes following computations a bit. + * Note: If energy is used elsewhere, then this can cause problems and local energy should be used. */ + if ( numSf == 1 ) { - for ( j = 0; j < numSf; j++ ) + for ( j = 1; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - for ( k = 0; k < numCodingBands; k++ ) + for ( k = 0; k < MASA_FREQUENCY_BANDS; k++ ) { - aziRad = hMeta->directional_meta[i].azimuth[j][k] / 180.0f * EVS_PI; - eleRad = hMeta->directional_meta[i].elevation[j][k] / 180.0f * EVS_PI; - vecLen = hMeta->directional_meta[i].energy_ratio[j][k]; - - x[i][j][k] = cosf( aziRad ) * cosf( eleRad ) * vecLen; - y[i][j][k] = sinf( aziRad ) * cosf( eleRad ) * vecLen; - z[i][j][k] = sinf( eleRad ) * vecLen; + hMasa->data.energy[0][k] += hMasa->data.energy[j][k]; } } } - /* Compute sum vector */ - for ( j = 0; j < numSf; j++ ) + if ( numCodingBands <= MAX_REDUCED_NBANDS ) { - for ( k = 0; k < numCodingBands; k++ ) + /* reduce metadata *frequency* resolution. time resolution is not touched */ + for ( i = 0; i < numDirections; i++ ) { - xSum[j][k] = x[0][j][k] + x[1][j][k]; - ySum[j][k] = y[0][j][k] + y[1][j][k]; - zSum[j][k] = z[0][j][k] + z[1][j][k]; - sumVecLen[j][k] = sqrtf( xSum[j][k] * xSum[j][k] + ySum[j][k] * ySum[j][k] + zSum[j][k] * zSum[j][k] ); - } - } + for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ + { + for ( k = 0; k < MASA_FREQUENCY_BANDS; k++ ) + { + aziRad = hMeta->directional_meta[i].azimuth[j][k] / 180.0f * EVS_PI; + eleRad = hMeta->directional_meta[i].elevation[j][k] / 180.0f * EVS_PI; + vecLen = hMeta->directional_meta[i].energy_ratio[j][k] * hMasa->data.energy[j][k]; - /* Estimate the importance of having two directions instead of one */ - for ( i = 0; i < numCodingBands; i++ ) - { - importance[i] = 0.0f; - for ( j = 0; j < numSf; j++ ) - { - tempImportance = hMeta->directional_meta[0].energy_ratio[j][i] + hMeta->directional_meta[1].energy_ratio[j][i] - sumVecLen[j][i]; - importance[i] += tempImportance; + x[i][j][k] = cosf( aziRad ) * cosf( eleRad ) * vecLen; + y[i][j][k] = sinf( aziRad ) * cosf( eleRad ) * vecLen; + z[i][j][k] = sinf( eleRad ) * vecLen; + } + } } - importance[i] /= (float) numSf; - importance[i] *= hMasa->data.importanceWeight[i]; - } - /* Determine bands where to use two directions */ - find_n_largest( importance, indicesOfLargest, numCodingBands, hMasa->config.numTwoDirBands ); + for ( i = 0; i < numDirections; i++ ) + { + for ( j = 0; j < numSf; j++ ) + { + for ( k = 0; k < numCodingBands; k++ ) + { + brange[0] = hMasa->data.band_mapping[k]; + brange[1] = hMasa->data.band_mapping[k + 1]; - for ( i = 0; i < numCodingBands; i++ ) - { - hMasa->data.twoDirBands[i] = 0; - } + xSum = 0.0f; + ySum = 0.0f; + zSum = 0.0f; + energySum = 0.0f; + spreadCohSum = 0.0f; - for ( i = 0; i < hMasa->config.numTwoDirBands; i++ ) + for ( m = brange[0]; m < brange[1]; m++ ) + { + xSum += x[i][j][m]; + ySum += y[i][j][m]; + zSum += z[i][j][m]; + energySum += hMasa->data.energy[j][m]; + } + + aziRad = atan2f( ySum, xSum ); + eleRad = atan2f( zSum, sqrtf( xSum * xSum + ySum * ySum ) ); + + hMeta->directional_meta[i].azimuth[j][k] = aziRad / EVS_PI * 180.0f; + hMeta->directional_meta[i].elevation[j][k] = eleRad / EVS_PI * 180.0f; + + vecLen = sqrtf( xSum * xSum + ySum * ySum + zSum * zSum ); + hMeta->directional_meta[i].energy_ratio[j][k] = vecLen / ( energySum + EPSILON ); + + if ( computeCoherence ) + { + for ( m = brange[0]; m < brange[1]; m++ ) + { + spreadCohSum += hMeta->directional_meta[i].spread_coherence[j][m] * hMasa->data.energy[j][m]; + } + hMeta->directional_meta[i].spread_coherence[j][k] = spreadCohSum / ( energySum + EPSILON ); + + if ( i == 0 ) + { + surrCohSum = 0.0f; + for ( m = brange[0]; m < brange[1]; m++ ) + { + surrCohSum += hMeta->common_meta.surround_coherence[j][m] * hMasa->data.energy[j][m]; + } + hMeta->common_meta.surround_coherence[j][k] = surrCohSum / ( energySum + EPSILON ); + } + } + + if ( i == 0 ) + { + energy[j][k] = energySum; + } + } + } + } + } + else if ( mergeRatiosOverSubframes ) /* keep frequency resolution */ { - hMasa->data.twoDirBands[indicesOfLargest[i]] = 1; + for ( j = 0; j < numSf; j++ ) + { + for ( k = 0; k < numCodingBands; k++ ) + { + energy[j][k] = hMasa->data.energy[j][k]; + } + } } - /* Combine directions on the remaining bands */ - for ( i = 0; i < numCodingBands; i++ ) + if ( mergeRatiosOverSubframes ) { - if ( hMasa->data.twoDirBands[i] == 0 ) + for ( k = 0; k < numCodingBands; k++ ) { + energySum = 0.0f; for ( j = 0; j < numSf; j++ ) { - aziRad = atan2f( ySum[j][i], xSum[j][i] ); - eleRad = atan2f( zSum[j][i], sqrtf( xSum[j][i] * xSum[j][i] + ySum[j][i] * ySum[j][i] ) ); + energySum += energy[j][k]; + } - hMeta->directional_meta[0].azimuth[j][i] = aziRad / EVS_PI * 180.0f; - hMeta->directional_meta[0].elevation[j][i] = eleRad / EVS_PI * 180.0f; + if ( computeCoherence ) + { + surrCohSum = 0.0f; + for ( j = 0; j < numSf; j++ ) + { + surrCohSum += energy[j][k] * hMeta->common_meta.surround_coherence[j][k]; + } + surrCohTemp = surrCohSum / ( energySum + EPSILON ); - ratioSum = hMeta->directional_meta[0].energy_ratio[j][i] + hMeta->directional_meta[1].energy_ratio[j][i]; - if ( computeCoherence ) + for ( j = 0; j < numSf; j++ ) { - hMeta->directional_meta[0].spread_coherence[j][i] = - ( hMeta->directional_meta[0].spread_coherence[j][i] * hMeta->directional_meta[0].energy_ratio[j][i] + hMeta->directional_meta[1].spread_coherence[j][i] * hMeta->directional_meta[1].energy_ratio[j][i] ) / ( ratioSum + EPSILON ); + hMeta->common_meta.surround_coherence[j][k] = surrCohTemp; } + } - ambience2dir = 1.0f - ratioSum; - hMeta->directional_meta[0].energy_ratio[j][i] = sumVecLen[j][i] / ( hMeta->directional_meta[0].energy_ratio[j][i] + hMeta->directional_meta[1].energy_ratio[j][i] + ambience2dir / 2.0f ); - hMeta->directional_meta[1].energy_ratio[j][i] = 0.0f; - if ( computeCoherence ) + for ( i = 0; i < numDirections; i++ ) + { + energyRatioSum = 0.0f; + for ( j = 0; j < numSf; j++ ) { - ambience1dir = 1.0f - hMeta->directional_meta[0].energy_ratio[j][i]; - ambienceIncrease = max( ambience1dir - ambience2dir, 0.0f ); + energyRatioSum += energy[j][k] * hMeta->directional_meta[i].energy_ratio[j][k]; + } + energyRatioTemp = energyRatioSum / ( energySum + EPSILON ); - origSurrCohEne = ambience2dir * hMeta->common_meta.surround_coherence[j][i]; - newSurrCohEne = ambienceIncrease * hMeta->directional_meta[0].spread_coherence[j][i]; - hMeta->common_meta.surround_coherence[j][i] = min( 1.0f, ( origSurrCohEne + newSurrCohEne ) / ( ambience1dir + EPSILON ) ); + for ( j = 0; j < numSf; j++ ) + { + hMeta->directional_meta[i].energy_ratio[j][k] = energyRatioTemp; } } } @@ -3128,494 +2715,520 @@ void ivas_masa_combine_directions( } #endif + +/*-------------------------------------------------------------------* + * ivas_masa_combine_directions() + * + * + *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static void find_n_largest_fx( - const Word32 *input_fx, - Word16 exp_input, - Word16 *largestIndices, - const Word16 numElements, - const Word16 numLargest ) +void ivas_masa_combine_directions_fx( + MASA_ENCODER_HANDLE hMasa ) { - Word16 i, j; - Word32 largestValue; - Word16 largestIndex; - Word32 values[MASA_FREQUENCY_BANDS]; + Word16 i, j, k; + UWord8 numCodingBands; + UWord8 numSf; + UWord8 numDirections; + UWord8 computeCoherence; + MASA_METADATA_HANDLE hMeta; - FOR( j = 0; j < numElements; j++ ) + Word16 aziRad_fx; + Word16 eleRad_fx; + Word32 x_fx[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 y_fx[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 z_fx[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 vecLen_fx; + Word32 xSum_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 ySum_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 zSum_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 sumVecLen_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 exp_sumVecLen_buff[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], exp_sumVecLen = MIN16B_FLT_FX; + move16(); + Word32 tempImportance_fx; + Word16 exp_tmp_importance = 0; + move16(); + Word32 importance_fx[MASA_FREQUENCY_BANDS]; + Word16 exp_importance_buff[MASA_FREQUENCY_BANDS], exp_importance = MIN16B_FLT_FX; + move16(); + Word16 indicesOfLargest[MASA_FREQUENCY_BANDS]; + + Word32 ratioSum_fx; + Word32 ambience1dir_fx; + Word32 ambience2dir_fx; + Word32 ambienceIncrease_fx; + Word32 origSurrCohEne_fx; + Word32 newSurrCohEne_fx; + + numCodingBands = hMasa->config.numCodingBands; + numDirections = hMasa->config.numberOfDirections; + move16(); + move16(); + + IF( EQ_16( hMasa->config.joinedSubframes, TRUE ) ) { - values[j] = input_fx[j]; - move32(); + numSf = 1; + } + ELSE + { + numSf = MAX_PARAM_SPATIAL_SUBFRAMES; } + move16(); + hMeta = &( hMasa->masaMetadata ); - FOR( i = 0; i < numLargest; i++ ) + computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; + move16(); + Word16 azi_cos = 0, azi_sine = 0, ele_cos = 0, ele_sine = 0; + move16(); + move16(); + move16(); + move16(); + FOR( i = 0; i < numDirections; i++ ) { - largestValue = values[0]; - move32(); - largestIndex = 0; - move16(); - FOR( j = 1; j < numElements; j++ ) + FOR( j = 0; j < numSf; j++ ) { - IF( GT_32( values[j], largestValue ) ) + FOR( k = 0; k < numCodingBands; k++ ) { - largestValue = values[j]; - largestIndex = j; + aziRad_fx = extract_l( L_shr( Mpy_32_32( hMeta->directional_meta[i].azimuth_fx[j][k], PI_OVER_180_Q25 ), 3 ) ); // (Q22 + Q25 - 31) - 3 = Q13 + azi_cos = getCosWord16( aziRad_fx ); // Q14 + azi_sine = getSinWord16( aziRad_fx ); // Q15 + + eleRad_fx = extract_l( L_shr( Mpy_32_32( hMeta->directional_meta[i].elevation_fx[j][k], PI_OVER_180_Q25 ), 3 ) ); // (Q22 + Q25 - 31) - 3 = Q13 + ele_sine = getSinWord16( eleRad_fx ); // Q15 + ele_cos = getCosWord16( eleRad_fx ); // Q14 + + vecLen_fx = hMeta->directional_meta[i].energy_ratio_fx[j][k]; + move32(); + + x_fx[i][j][k] = L_mult0( azi_cos, ele_cos ); // Q14+Q14 + x_fx[i][j][k] = Mpy_32_32( x_fx[i][j][k], vecLen_fx ); // Q28+Q30-31 + y_fx[i][j][k] = L_mult0( azi_sine, ele_cos ); // Q15+Q14 + y_fx[i][j][k] = Mpy_32_32( y_fx[i][j][k], vecLen_fx ); // Q29+Q30-31 + z_fx[i][j][k] = Mpy_32_32( L_deposit_h( ele_sine ), vecLen_fx ); // Q16+Q15+Q30 - 31 + move32(); + move32(); + move32(); + move32(); move32(); - move16(); } } - largestIndices[i] = largestIndex; - move16(); - IF( exp_input != 0 ) - { - values[largestIndex] = L_negate( 1 << ( sub( 31, exp_input ) ) ); - move32(); - } - ELSE + } + + /* Compute sum vector */ + FOR( j = 0; j < numSf; j++ ) + { + FOR( k = 0; k < numCodingBands; k++ ) { - values[largestIndex] = 1 << ( sub( 31, exp_input ) ); + xSum_fx[j][k] = L_add( x_fx[0][j][k], x_fx[1][j][k] ); // Q27 + ySum_fx[j][k] = L_add( y_fx[0][j][k], y_fx[1][j][k] ); // Q28 + zSum_fx[j][k] = L_add( z_fx[0][j][k], z_fx[1][j][k] ); // Q30 + move32(); + move32(); move32(); - } - } - return; -} -#else -static void find_n_largest( - const float *input, - int16_t *largestIndices, - const int16_t numElements, - const int16_t numLargest ) -{ - int16_t i, j; - float largestValue; - int16_t largestIndex; - float values[MASA_FREQUENCY_BANDS]; + Word32 var1 = Mpy_32_32( xSum_fx[j][k], xSum_fx[j][k] ); // Q27 + Q27 - 31 //Q23 + Word32 var2 = Mpy_32_32( ySum_fx[j][k], ySum_fx[j][k] ); // Q28 + Q28 - 31 //Q25 + Word32 var3 = Mpy_32_32( zSum_fx[j][k], zSum_fx[j][k] ); // Q30 + Q30 - 31 //Q29 + Word32 var4 = L_add( L_add( var1, L_shr( var2, 2 ) ), L_shr( var3, 6 ) ); // Q23 + Word16 exp_var4 = 31 - Q23; + move16(); - for ( j = 0; j < numElements; j++ ) - { - values[j] = input[j]; - } + Word16 exp_var5 = exp_var4; + move16(); + Word32 var5 = 0; + move32(); - for ( i = 0; i < numLargest; i++ ) - { - largestValue = values[0]; - largestIndex = 0; - for ( j = 1; j < numElements; j++ ) - { - if ( values[j] > largestValue ) + IF( var4 != 0 ) { - largestValue = values[j]; - largestIndex = j; + var5 = Sqrt32( var4, &exp_var5 ); } + sumVecLen_fx[j][k] = var5; + move32(); + exp_sumVecLen_buff[j][k] = exp_var5; + move16(); } - largestIndices[i] = largestIndex; - values[largestIndex] = -1.0f; } - return; -} -#endif - -#ifndef IVAS_FLOAT_FIXED -static void move_metadata_to_qmetadata( - const MASA_ENCODER_HANDLE hMasa, - IVAS_QMETADATA_HANDLE hQMeta ) -{ - int16_t dir, sf, band; - uint8_t numCodingBands; - uint8_t numDirections; - uint8_t numSf; - MASA_METADATA_HANDLE hMeta; - - numCodingBands = hMasa->config.numCodingBands; - numDirections = hMasa->config.numberOfDirections; - numSf = hMasa->config.joinedSubframes == TRUE ? 1 : 4; - hMeta = &( hMasa->masaMetadata ); - - for ( dir = 0; dir < numDirections; dir++ ) + /*make commen exp for sumVecLen_fx buffer*/ + FOR( j = 0; j < numSf; j++ ) { - for ( sf = 0; sf < numSf; sf++ ) + FOR( k = 0; k < numCodingBands; k++ ) { - for ( band = 0; band < numCodingBands; band++ ) - { - hQMeta->q_direction[dir].band_data[band].azimuth[sf] = hMeta->directional_meta[dir].azimuth[sf][band]; - hQMeta->q_direction[dir].band_data[band].elevation[sf] = hMeta->directional_meta[dir].elevation[sf][band]; - hQMeta->q_direction[dir].band_data[band].energy_ratio[sf] = hMeta->directional_meta[dir].energy_ratio[sf][band]; - hQMeta->q_direction[dir].band_data[band].spherical_index[sf] = hMeta->directional_meta[dir].spherical_index[sf][band]; - if ( hQMeta->q_direction[dir].coherence_band_data != NULL ) - { - hQMeta->q_direction[dir].coherence_band_data[band].spread_coherence[sf] = (uint8_t) roundf( hMeta->directional_meta[dir].spread_coherence[sf][band] * UINT8_MAX ); - } - } + exp_sumVecLen = s_max( exp_sumVecLen_buff[j][k], exp_sumVecLen ); } } - for ( sf = 0; sf < numSf; sf++ ) + FOR( j = 0; j < numSf; j++ ) { - for ( band = 0; band < numCodingBands; band++ ) + FOR( k = 0; k < numCodingBands; k++ ) { - if ( hQMeta->surcoh_band_data != NULL ) - { - hQMeta->surcoh_band_data[band].surround_coherence[sf] = (uint8_t) roundf( hMeta->common_meta.surround_coherence[sf][band] * UINT8_MAX ); - } + sumVecLen_fx[j][k] = L_shr( sumVecLen_fx[j][k], sub( exp_sumVecLen, exp_sumVecLen_buff[j][k] ) ); + move32(); } } - if ( numDirections > 1 ) + /* Estimate the importance of having two directions instead of one */ + FOR( i = 0; i < numCodingBands; i++ ) { - for ( band = 0; band < numCodingBands; band++ ) + importance_fx[i] = 0; + move32(); + FOR( j = 0; j < numSf; j++ ) { - hQMeta->twoDirBands[band] = hMasa->data.twoDirBands[band]; + tempImportance_fx = L_add( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[1].energy_ratio_fx[j][i] ); + exp_tmp_importance = 0; + move16(); + tempImportance_fx = BASOP_Util_Add_Mant32Exp( tempImportance_fx, 31 - Q30, L_negate( sumVecLen_fx[j][i] ), exp_sumVecLen, &exp_tmp_importance ); + importance_fx[i] = BASOP_Util_Add_Mant32Exp( importance_fx[i], exp_importance_buff[i], tempImportance_fx, exp_tmp_importance, &exp_importance_buff[i] ); + move32(); } - hQMeta->numTwoDirBands = hMasa->config.numTwoDirBands; - } - /* Copy spread coherence for DCT-based coding */ - if ( numSf == 1 && hMasa->config.useCoherence ) - { - for ( dir = 0; dir < numDirections; dir++ ) + if ( numSf != 1 ) { - for ( sf = 1; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) - { - for ( band = 0; band < numCodingBands; band++ ) - { - hQMeta->q_direction[dir].coherence_band_data[band].spread_coherence[sf] = hQMeta->q_direction[dir].coherence_band_data[band].spread_coherence[0]; - } - } + importance_fx[i] = L_shr( importance_fx[i], 2 ); + move32(); } + importance_fx[i] = Mpy_32_32( importance_fx[i], hMasa->data.importanceWeight_fx[i] ); + move32(); + exp_importance_buff[i] = add( exp_importance_buff[i], 1 ); + move16(); } - return; -} -#else -static void move_metadata_to_qmetadata_fx( - const MASA_ENCODER_HANDLE hMasa, - IVAS_QMETADATA_HANDLE hQMeta ) -{ - Word16 dir, sf, band; - UWord8 numCodingBands; - UWord8 numDirections; - UWord8 numSf; - MASA_METADATA_HANDLE hMeta; - - numCodingBands = hMasa->config.numCodingBands; - numDirections = hMasa->config.numberOfDirections; - move16(); - move16(); - move16(); - numSf = 4; - if ( EQ_16( hMasa->config.joinedSubframes, TRUE ) ) + /*make commen exp for importance_fx buffer*/ + FOR( i = 0; i < numCodingBands; i++ ) { - numSf = 1; - move16(); + exp_importance = s_max( exp_importance_buff[i], exp_importance ); } - hMeta = &( hMasa->masaMetadata ); - - FOR( dir = 0; dir < numDirections; dir++ ) + FOR( i = 0; i < numCodingBands; i++ ) { - FOR( sf = 0; sf < numSf; sf++ ) - { - FOR( band = 0; band < numCodingBands; band++ ) - { - hQMeta->q_direction[dir].band_data[band].azimuth_fx[sf] = hMeta->directional_meta[dir].azimuth_fx[sf][band]; - hQMeta->q_direction[dir].band_data[band].elevation_fx[sf] = hMeta->directional_meta[dir].elevation_fx[sf][band]; - hQMeta->q_direction[dir].band_data[band].energy_ratio_fx[sf] = hMeta->directional_meta[dir].energy_ratio_fx[sf][band]; - hQMeta->q_direction[dir].band_data[band].spherical_index[sf] = hMeta->directional_meta[dir].spherical_index[sf][band]; - move32(); - move32(); - move32(); - move16(); - - IF( hQMeta->q_direction[dir].coherence_band_data != NULL ) - { - hQMeta->q_direction[dir].coherence_band_data[band].spread_coherence[sf] = (UWord8) mult_r( hMeta->directional_meta[dir].spread_coherence_fx[sf][band], UINT8_MAX ); - move16(); - } - } - } + importance_fx[i] = L_shr( importance_fx[i], sub( exp_importance, exp_importance_buff[i] ) ); + move32(); } - FOR( sf = 0; sf < numSf; sf++ ) + /* Determine bands where to use two directions */ + find_n_largest_fx( importance_fx, exp_importance, indicesOfLargest, numCodingBands, hMasa->config.numTwoDirBands ); + + FOR( i = 0; i < numCodingBands; i++ ) { - FOR( band = 0; band < numCodingBands; band++ ) - { - IF( hQMeta->surcoh_band_data != NULL ) - { - hQMeta->surcoh_band_data[band].surround_coherence[sf] = (UWord8) mult_r( hMeta->common_meta.surround_coherence_fx[sf][band], UINT8_MAX ); - move16(); - } - } + hMasa->data.twoDirBands[i] = 0; + move16(); } - IF( GT_16( numDirections, 1 ) ) + FOR( i = 0; i < hMasa->config.numTwoDirBands; i++ ) { - FOR( band = 0; band < numCodingBands; band++ ) - { - hQMeta->twoDirBands[band] = hMasa->data.twoDirBands[band]; - move16(); - } - hQMeta->numTwoDirBands = hMasa->config.numTwoDirBands; + hMasa->data.twoDirBands[indicesOfLargest[i]] = 1; move16(); } - /* Copy spread coherence for DCT-based coding */ - test(); - IF( EQ_16( numSf, 1 ) && hMasa->config.useCoherence ) + /* Combine directions on the remaining bands */ + FOR( i = 0; i < numCodingBands; i++ ) { - FOR( dir = 0; dir < numDirections; dir++ ) + IF( hMasa->data.twoDirBands[i] == 0 ) { - FOR( sf = 1; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + FOR( j = 0; j < numSf; j++ ) { - FOR( band = 0; band < numCodingBands; band++ ) - { - hQMeta->q_direction[dir].coherence_band_data[band].spread_coherence[sf] = hQMeta->q_direction[dir].coherence_band_data[band].spread_coherence[0]; - move16(); - } - } - } - } - - return; -} -#endif + aziRad_fx = BASOP_util_atan2( ySum_fx[j][i], xSum_fx[j][i], Q27 - Q28 ); // Q13 + Word32 tmp1 = Mpy_32_32( xSum_fx[j][i], xSum_fx[j][i] ); // Q27+Q27-31 //Q23 + Word32 tmp2 = Mpy_32_32( ySum_fx[j][i], ySum_fx[j][i] ); // Q28+Q28-31 //Q25 + Word32 tmp3 = L_add( tmp1, L_shr( tmp2, 2 ) ); // Q23 + Word16 exp_tmp3 = 31 - Q23; + move16(); + Word32 tmp4 = Sqrt32( tmp3, &exp_tmp3 ); + eleRad_fx = BASOP_util_atan2( zSum_fx[j][i], tmp4, sub( sub( 31, Q30 ), exp_tmp3 ) ); + Word16 exp_tmp5 = 0; + move16(); + Word16 tmp5 = BASOP_Util_Divide1616_Scale( aziRad_fx, EVS_PI_FX, &exp_tmp5 ); + Word16 Q_tmp6 = 0; + move16(); + Word32 tmp6 = L_mult( tmp5, 23040 /*180.0f in Q7*/ ); + Q_tmp6 = sub( 31, add( exp_tmp5, 8 ) ); -/* This function studies parametric MASA metadata to provide information for codec configuration */ -static void detect_metadata_composition( - const MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder data */ - uint8_t *joinedSubframes, /* o : Result of subframe composition */ - uint8_t *coherencePresent, /* o : Result of coherence presence */ - uint8_t *isTwoDir /* o : Result of two direction check */ -) -{ - MASA_METADATA_FRAME *hMeta; - int8_t sf, band, dir, numDir; - int16_t nSubFrames; - uint8_t dirValid[2] = { FALSE, FALSE }; - uint8_t cohPresent = FALSE; - uint8_t sfDiffer = FALSE; - uint8_t sfSimilar; + Word16 exp_tmp7 = 0; + move16(); + Word16 tmp7 = BASOP_Util_Divide1616_Scale( eleRad_fx, EVS_PI_FX, &exp_tmp7 ); + Word16 Q_tmp8 = 0; + move16(); + Word32 tmp8 = L_mult( tmp7, 23040 /*180.0f in Q7*/ ); + Q_tmp8 = sub( 31, add( exp_tmp7, 8 ) ); - hMeta = &( hMasa->masaMetadata ); - numDir = hMeta->descriptive_meta.numberOfDirections + 1; + Scale_sig32( &tmp6, 1, Q22 - Q_tmp6 ); + Scale_sig32( &tmp8, 1, Q22 - Q_tmp8 ); - *isTwoDir = FALSE; + hMeta->directional_meta[0].azimuth_fx[j][i] = tmp6; // Q22 + hMeta->directional_meta[0].elevation_fx[j][i] = tmp8; // Q22 + move32(); + move32(); + ratioSum_fx = L_add( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[1].energy_ratio_fx[j][i] ); // Q30 + IF( computeCoherence ) + { + Word32 var1 = Mpy_32_16_1( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[0].spread_coherence_fx[j][i] ); + Word32 var2 = Mpy_32_16_1( hMeta->directional_meta[1].energy_ratio_fx[j][i], hMeta->directional_meta[1].spread_coherence_fx[j][i] ); + Word32 var3 = L_add( var1, var2 ); // Q30 + Word16 exp_var4 = 0; + move16(); + Word32 var4 = BASOP_Util_Add_Mant32Exp( ratioSum_fx, 31 - Q30, EPSILON_FX_M, EPSILON_FX_E, &exp_var4 ); + Word16 exp_var5 = 0; + move16(); + Word16 var5 = BASOP_Util_Divide3232_Scale( var3, var4, &exp_var5 ); + exp_var5 = add( exp_var5, ( sub( sub( 31, Q30 ), exp_var4 ) ) ); + Scale_sig( &var5, 1, sub( Q15, sub( 15, exp_var5 ) ) ); + hMeta->directional_meta[0].spread_coherence_fx[j][i] = var5; // Q15 + move16(); + } - /* First check for valid two directions */ - if ( numDir == 1 ) - { - dirValid[0] = TRUE; - } - else - { - /* Default assumption */ - *isTwoDir = TRUE; + ambience2dir_fx = L_sub( ONE_IN_Q30, ratioSum_fx ); // Q30 + Word32 ambience2dir_fx_by_2 = L_shr( ambience2dir_fx, 1 ); + Word32 var_a = L_add( L_add( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[1].energy_ratio_fx[j][i] ), ambience2dir_fx_by_2 ); // Q30 + Word16 exp_var_b = 0; + move16(); + Word16 var_b = BASOP_Util_Divide3232_Scale( sumVecLen_fx[j][i], var_a, &exp_var_b ); + exp_var_b = add( exp_var_b, sub( exp_sumVecLen, 1 ) ); + Word32 var_b_32 = L_deposit_h( var_b ); + hMeta->directional_meta[0].energy_ratio_fx[j][i] = L_shr( var_b_32, 1 - exp_var_b ); // Q30 + hMeta->directional_meta[1].energy_ratio_fx[j][i] = 0; // Q30 + move16(); + move16(); - /* Check for direct-to-total ratio values */ - for ( dir = 0; dir < numDir; dir++ ) - { - sf = 0; - while ( !dirValid[dir] && sf < MAX_PARAM_SPATIAL_SUBFRAMES ) - { - band = 0; - while ( !dirValid[dir] && band < MASA_FREQUENCY_BANDS ) + IF( computeCoherence ) { - if ( hMeta->directional_meta[dir].energy_ratio[sf][band] >= MASA_RATIO_THRESHOLD ) - { - dirValid[dir] = TRUE; - } - band++; + ambience1dir_fx = L_sub( ONE_IN_Q30, hMeta->directional_meta[0].energy_ratio_fx[j][i] ); // Q30 + ambienceIncrease_fx = L_max( L_sub( ambience1dir_fx, ambience2dir_fx ), 0 ); // Q30 + origSurrCohEne_fx = Mpy_32_16_1( ambience2dir_fx /*Q30*/, hMeta->common_meta.surround_coherence_fx[j][i] /*Q15*/ ); // Q30 + newSurrCohEne_fx = Mpy_32_16_1( ambienceIncrease_fx /*Q30*/, hMeta->directional_meta[0].spread_coherence_fx[j][i] /*Q15*/ ); // Q30 + + Word16 exp_y = 0, exp_z = 0; + move16(); + move16(); + Word32 x = L_add( origSurrCohEne_fx, newSurrCohEne_fx ); // Q30 + Word32 y = BASOP_Util_Add_Mant32Exp( ambience1dir_fx, 1, EPSILON_FX_M, EPSILON_FX_E, &exp_y ); + Word16 z = BASOP_Util_Divide3232_Scale( x, y, &exp_z ); + exp_z = add( exp_z, ( sub( 31 - Q30, exp_y ) ) ); + z = shl_sat( z, exp_z ); // Q15 + hMeta->common_meta.surround_coherence_fx[j][i] = s_min( MAX16B, z ); + move16(); } - sf++; } } + } - if ( dirValid[1] == FALSE ) - { - /* This handles also case where both are false. Then we just use first dir metadata. */ - *isTwoDir = FALSE; - } - else if ( dirValid[0] == FALSE && dirValid[1] == TRUE ) + return; +} +#else +void ivas_masa_combine_directions( + MASA_ENCODER_HANDLE hMasa ) +{ + int16_t i, j, k; + uint8_t numCodingBands; + uint8_t numSf; + uint8_t numDirections; + uint8_t computeCoherence; + MASA_METADATA_HANDLE hMeta; + + float aziRad; + float eleRad; + float x[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + float y[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + float z[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + float vecLen; + float xSum[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + float ySum[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + float zSum[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + float sumVecLen[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + float tempImportance; + float importance[MASA_FREQUENCY_BANDS]; + int16_t indicesOfLargest[MASA_FREQUENCY_BANDS]; + + float ambience1dir; + float ambience2dir; + float ambienceIncrease; + float ratioSum; + float origSurrCohEne; + float newSurrCohEne; + + numCodingBands = hMasa->config.numCodingBands; + numDirections = hMasa->config.numberOfDirections; + numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; + + hMeta = &( hMasa->masaMetadata ); + + computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; + + for ( i = 0; i < numDirections; i++ ) + { + for ( j = 0; j < numSf; j++ ) { - *isTwoDir = FALSE; - /* Copy data to first direction */ - for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + for ( k = 0; k < numCodingBands; k++ ) { - for ( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) - { - hMeta->directional_meta[0].azimuth[sf][band] = hMeta->directional_meta[1].azimuth[sf][band]; - hMeta->directional_meta[0].elevation[sf][band] = hMeta->directional_meta[1].elevation[sf][band]; - hMeta->directional_meta[0].energy_ratio[sf][band] = hMeta->directional_meta[1].energy_ratio[sf][band]; - hMeta->directional_meta[0].spread_coherence[sf][band] = hMeta->directional_meta[1].spread_coherence[sf][band]; - } + aziRad = hMeta->directional_meta[i].azimuth[j][k] / 180.0f * EVS_PI; + eleRad = hMeta->directional_meta[i].elevation[j][k] / 180.0f * EVS_PI; + vecLen = hMeta->directional_meta[i].energy_ratio[j][k]; + + x[i][j][k] = cosf( aziRad ) * cosf( eleRad ) * vecLen; + y[i][j][k] = sinf( aziRad ) * cosf( eleRad ) * vecLen; + z[i][j][k] = sinf( eleRad ) * vecLen; } } + } - if ( *isTwoDir == FALSE ) + /* Compute sum vector */ + for ( j = 0; j < numSf; j++ ) + { + for ( k = 0; k < numCodingBands; k++ ) { - /* Further checks will be done with just one direction */ - numDir = 1; + xSum[j][k] = x[0][j][k] + x[1][j][k]; + ySum[j][k] = y[0][j][k] + y[1][j][k]; + zSum[j][k] = z[0][j][k] + z[1][j][k]; + sumVecLen[j][k] = sqrtf( xSum[j][k] * xSum[j][k] + ySum[j][k] * ySum[j][k] + zSum[j][k] * zSum[j][k] ); } } - /* Check if data over subframes is identical. Check is done by comparing to first subframe. */ - sfSimilar = TRUE; - sf = 1; - while ( ( sfSimilar == TRUE ) && ( sf < MAX_PARAM_SPATIAL_SUBFRAMES ) ) + /* Estimate the importance of having two directions instead of one */ + for ( i = 0; i < numCodingBands; i++ ) { - sfSimilar = are_masa_subframes_similar( hMeta, 0, hMeta, sf ); - sf++; + importance[i] = 0.0f; + for ( j = 0; j < numSf; j++ ) + { + tempImportance = hMeta->directional_meta[0].energy_ratio[j][i] + hMeta->directional_meta[1].energy_ratio[j][i] - sumVecLen[j][i]; + importance[i] += tempImportance; + } + importance[i] /= (float) numSf; + importance[i] *= hMasa->data.importanceWeight[i]; } - sfDiffer = sfSimilar == TRUE ? FALSE : TRUE; - /* Further checks can be done with just one subframe if they are identical */ - nSubFrames = sfDiffer == TRUE ? MAX_PARAM_SPATIAL_SUBFRAMES : 1; + /* Determine bands where to use two directions */ + find_n_largest( importance, indicesOfLargest, numCodingBands, hMasa->config.numTwoDirBands ); - /* Check spread coherence */ - dir = 0; - while ( cohPresent == FALSE && dir < numDir ) + for ( i = 0; i < numCodingBands; i++ ) { - sf = 0; - while ( cohPresent == FALSE && sf < nSubFrames ) + hMasa->data.twoDirBands[i] = 0; + } + + for ( i = 0; i < hMasa->config.numTwoDirBands; i++ ) + { + hMasa->data.twoDirBands[indicesOfLargest[i]] = 1; + } + + /* Combine directions on the remaining bands */ + for ( i = 0; i < numCodingBands; i++ ) + { + if ( hMasa->data.twoDirBands[i] == 0 ) { - band = 0; - while ( cohPresent == FALSE && band < MASA_FREQUENCY_BANDS ) + for ( j = 0; j < numSf; j++ ) { - /* Check coherences for presence of coherence */ - if ( hMeta->directional_meta[dir].spread_coherence[sf][band] >= MASA_COHERENCE_THRESHOLD ) + aziRad = atan2f( ySum[j][i], xSum[j][i] ); + eleRad = atan2f( zSum[j][i], sqrtf( xSum[j][i] * xSum[j][i] + ySum[j][i] * ySum[j][i] ) ); + + hMeta->directional_meta[0].azimuth[j][i] = aziRad / EVS_PI * 180.0f; + hMeta->directional_meta[0].elevation[j][i] = eleRad / EVS_PI * 180.0f; + + ratioSum = hMeta->directional_meta[0].energy_ratio[j][i] + hMeta->directional_meta[1].energy_ratio[j][i]; + if ( computeCoherence ) { - cohPresent = TRUE; + hMeta->directional_meta[0].spread_coherence[j][i] = + ( hMeta->directional_meta[0].spread_coherence[j][i] * hMeta->directional_meta[0].energy_ratio[j][i] + hMeta->directional_meta[1].spread_coherence[j][i] * hMeta->directional_meta[1].energy_ratio[j][i] ) / ( ratioSum + EPSILON ); + } + + ambience2dir = 1.0f - ratioSum; + hMeta->directional_meta[0].energy_ratio[j][i] = sumVecLen[j][i] / ( hMeta->directional_meta[0].energy_ratio[j][i] + hMeta->directional_meta[1].energy_ratio[j][i] + ambience2dir / 2.0f ); + hMeta->directional_meta[1].energy_ratio[j][i] = 0.0f; + if ( computeCoherence ) + { + ambience1dir = 1.0f - hMeta->directional_meta[0].energy_ratio[j][i]; + ambienceIncrease = max( ambience1dir - ambience2dir, 0.0f ); + + origSurrCohEne = ambience2dir * hMeta->common_meta.surround_coherence[j][i]; + newSurrCohEne = ambienceIncrease * hMeta->directional_meta[0].spread_coherence[j][i]; + hMeta->common_meta.surround_coherence[j][i] = min( 1.0f, ( origSurrCohEne + newSurrCohEne ) / ( ambience1dir + EPSILON ) ); } - band++; } - sf++; } - dir++; } - /* Check surround coherence separately if we do not have already knowledge of coherence */ - if ( cohPresent == FALSE ) - { - cohPresent = ivas_masa_surrcoh_signicant( hMeta->common_meta.surround_coherence, hMeta->common_meta.diffuse_to_total_ratio, nSubFrames, MASA_FREQUENCY_BANDS ); - } + return; +} +#endif - /* Set output flags */ - *joinedSubframes = sfDiffer == TRUE ? FALSE : TRUE; - *coherencePresent = cohPresent; - - return; -} - - -/* Check and compensate energy ratios. This function verifies that energy ratios follow the principle of summing to one. - * In addition, it implements simple remainder-to-total handling where remainder energy is proportionally added to other - * ratios. */ #ifdef IVAS_FLOAT_FIXED -static void compensate_energy_ratios_fx( - MASA_ENCODER_HANDLE hMasa ) +static void find_n_largest_fx( + const Word32 *input_fx, + Word16 exp_input, + Word16 *largestIndices, + const Word16 numElements, + const Word16 numLargest ) { - Word16 sf, band, dir; - Word32 ratioSum; - MASA_METADATA_HANDLE hMeta; - UWord8 numDirs; + Word16 i, j; + Word32 largestValue; + Word16 largestIndex; + Word32 values[MASA_FREQUENCY_BANDS]; - hMeta = &( hMasa->masaMetadata ); - numDirs = (UWord8) add( hMeta->descriptive_meta.numberOfDirections, 1 ); + FOR( j = 0; j < numElements; j++ ) + { + values[j] = input_fx[j]; + move32(); + } - FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + FOR( i = 0; i < numLargest; i++ ) { - FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + largestValue = values[0]; + move32(); + largestIndex = 0; + move16(); + FOR( j = 1; j < numElements; j++ ) { - /* Remainder is always set to zero and energy removal is compensated in following steps - * to other ratios. */ - hMeta->common_meta.remainder_to_total_ratio_fx[sf][band] = 0; // Q30 - move32(); - - ratioSum = 0; - move32(); - FOR( dir = 0; dir < numDirs; dir++ ) - { - ratioSum = L_add( ratioSum, hMeta->directional_meta[dir].energy_ratio_fx[sf][band] ); // Q30 - } - ratioSum = L_add( ratioSum, hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] ); // Q30 - - IF( ratioSum == 0 ) - { - FOR( dir = 0; dir < numDirs; dir++ ) - { - hMeta->directional_meta[dir].energy_ratio_fx[sf][band] = 0; // Q30 - move32(); - } - hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = ONE_IN_Q30; // Q30 - move32(); - } - // ELSE IF( NE_32( ratioSum, ONE_IN_Q30 ) ) - ELSE /* Removing the check against 1 works well!!! */ + IF( GT_32( values[j], largestValue ) ) { - Word16 exp_diff; - FOR( dir = 0; dir < numDirs; dir++ ) - { - hMeta->directional_meta[dir].energy_ratio_fx[sf][band] = - BASOP_Util_Divide3232_Scale_cadence( hMeta->directional_meta[dir].energy_ratio_fx[sf][band], ratioSum, &exp_diff ); - move32(); - hMeta->directional_meta[dir].energy_ratio_fx[sf][band] = L_shl( hMeta->directional_meta[dir].energy_ratio_fx[sf][band], sub( exp_diff, Q1 ) ); // Q30 - move32(); - } - hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = - BASOP_Util_Divide3232_Scale_cadence( hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], ratioSum, &exp_diff ); - move32(); - hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_shl( hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], sub( exp_diff, Q1 ) ); // Q30 + largestValue = values[j]; + largestIndex = j; move32(); + move16(); } } + largestIndices[i] = largestIndex; + move16(); + IF( exp_input != 0 ) + { + values[largestIndex] = L_negate( 1 << ( sub( 31, exp_input ) ) ); + move32(); + } + ELSE + { + values[largestIndex] = 1 << ( sub( 31, exp_input ) ); + move32(); + } } return; } #else -static void compensate_energy_ratios( - MASA_ENCODER_HANDLE hMasa ) +static void find_n_largest( + const float *input, + int16_t *largestIndices, + const int16_t numElements, + const int16_t numLargest ) { - int16_t sf, band, dir; - float ratioSum; - MASA_METADATA_HANDLE hMeta; - uint8_t numDirs; + int16_t i, j; + float largestValue; + int16_t largestIndex; + float values[MASA_FREQUENCY_BANDS]; - hMeta = &( hMasa->masaMetadata ); - numDirs = hMeta->descriptive_meta.numberOfDirections + 1; + for ( j = 0; j < numElements; j++ ) + { + values[j] = input[j]; + } - for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + for ( i = 0; i < numLargest; i++ ) { - for ( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + largestValue = values[0]; + largestIndex = 0; + for ( j = 1; j < numElements; j++ ) { - /* Remainder is always set to zero and energy removal is compensated in following steps - * to other ratios. */ - hMeta->common_meta.remainder_to_total_ratio[sf][band] = 0.0f; - - ratioSum = 0; - for ( dir = 0; dir < numDirs; dir++ ) - { - ratioSum += hMeta->directional_meta[dir].energy_ratio[sf][band]; - } - ratioSum += hMeta->common_meta.diffuse_to_total_ratio[sf][band]; - - if ( ratioSum == 0.0f ) - { - for ( dir = 0; dir < numDirs; dir++ ) - { - hMeta->directional_meta[dir].energy_ratio[sf][band] = 0.0f; - } - hMeta->common_meta.diffuse_to_total_ratio[sf][band] = 1.0f; - } - else if ( ratioSum != 1.0f ) + if ( values[j] > largestValue ) { - for ( dir = 0; dir < numDirs; dir++ ) - { - hMeta->directional_meta[dir].energy_ratio[sf][band] /= ratioSum; - } - hMeta->common_meta.diffuse_to_total_ratio[sf][band] /= ratioSum; + largestValue = values[j]; + largestIndex = j; } } + largestIndices[i] = largestIndex; + values[largestIndex] = -1.0f; } return; @@ -3623,3683 +3236,5368 @@ static void compensate_energy_ratios( #endif #ifndef IVAS_FLOAT_FIXED -/* If the bit budget is very low, reduce metadata further to either 1 subframe and 5 bands, or 1 band and 4 subframes, based on which works better */ -static void reduce_metadata_further( - MASA_ENCODER_HANDLE hMasa, - IVAS_QMETADATA_HANDLE hqmetadata, - const IVAS_FORMAT ivas_format ) +static void move_metadata_to_qmetadata( + const MASA_ENCODER_HANDLE hMasa, + IVAS_QMETADATA_HANDLE hQMeta ) { - int16_t sf; - int16_t band; - int16_t selectedBand; - float energy[MAX_PARAM_SPATIAL_SUBFRAMES][LOWBITRATE_NUM_BANDS]; - float totalEnergySum; + int16_t dir, sf, band; uint8_t numCodingBands; - uint8_t computeCoherence; - float onset_filter; - float bandEnergy; - uint8_t mergeOverFreqBands; - float meanRatio; + uint8_t numDirections; + uint8_t numSf; + MASA_METADATA_HANDLE hMeta; numCodingBands = hMasa->config.numCodingBands; - computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; - - /* Set default values */ - selectedBand = 0; - mergeOverFreqBands = 0; + numDirections = hMasa->config.numberOfDirections; + numSf = hMasa->config.joinedSubframes == TRUE ? 1 : 4; + hMeta = &( hMasa->masaMetadata ); - /* Get energy for the input data in 4-subframe, 5-band format */ - totalEnergySum = 0.0f; - if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) /* Energy data is in 4-subframe, 24-band format */ + for ( dir = 0; dir < numDirections; dir++ ) { - for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + for ( sf = 0; sf < numSf; sf++ ) { - int16_t brange[2]; - float eneSum; - int16_t m; - for ( band = 0; band < numCodingBands; band++ ) { - brange[0] = hMasa->data.band_mapping[band]; - brange[1] = hMasa->data.band_mapping[band + 1]; - - eneSum = 0.0f; - for ( m = brange[0]; m < brange[1]; m++ ) + hQMeta->q_direction[dir].band_data[band].azimuth[sf] = hMeta->directional_meta[dir].azimuth[sf][band]; + hQMeta->q_direction[dir].band_data[band].elevation[sf] = hMeta->directional_meta[dir].elevation[sf][band]; + hQMeta->q_direction[dir].band_data[band].energy_ratio[sf] = hMeta->directional_meta[dir].energy_ratio[sf][band]; + hQMeta->q_direction[dir].band_data[band].spherical_index[sf] = hMeta->directional_meta[dir].spherical_index[sf][band]; + if ( hQMeta->q_direction[dir].coherence_band_data != NULL ) { - eneSum += hMasa->data.energy[sf][m]; + hQMeta->q_direction[dir].coherence_band_data[band].spread_coherence[sf] = (uint8_t) roundf( hMeta->directional_meta[dir].spread_coherence[sf][band] * UINT8_MAX ); } - energy[sf][band] = eneSum; - totalEnergySum += eneSum; } } } - else /* Energy data is already in 4-subframe, 5-band format */ + + for ( sf = 0; sf < numSf; sf++ ) { - for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + for ( band = 0; band < numCodingBands; band++ ) { - for ( band = 0; band < numCodingBands; band++ ) + if ( hQMeta->surcoh_band_data != NULL ) { - energy[sf][band] = hMasa->data.energy[sf][band]; - totalEnergySum += energy[sf][band]; + hQMeta->surcoh_band_data[band].surround_coherence[sf] = (uint8_t) roundf( hMeta->common_meta.surround_coherence[sf][band] * UINT8_MAX ); } } } - /* Determine onsets */ - hMasa->data.onset_detector_1 = hMasa->data.onset_detector_1 * LOWBITRATE_ONSET_ALPHA; - hMasa->data.onset_detector_1 = max( hMasa->data.onset_detector_1, totalEnergySum ); - - hMasa->data.onset_detector_2 = LOWBITRATE_ONSET_BETA * hMasa->data.onset_detector_2 + ( 1.0f - LOWBITRATE_ONSET_BETA ) * hMasa->data.onset_detector_1; - hMasa->data.onset_detector_2 = LOWBITRATE_ONSET_GAIN * min( hMasa->data.onset_detector_1, hMasa->data.onset_detector_2 ); - - onset_filter = min( max( hMasa->data.onset_detector_2 / ( hMasa->data.onset_detector_1 + EPSILON ), 0.0f ), 1.0f ); - - /* If we have onset, continue checking if we should reduce in frequency instead of time. */ - if ( onset_filter < 0.99f ) + if ( numDirections > 1 ) { - /* Determine one frequency band to use to represent all frequency bands */ - for ( band = numCodingBands - 1; band >= 0; band-- ) + for ( band = 0; band < numCodingBands; band++ ) { - float threshold; - float bandRatio; - - threshold = totalEnergySum / ( MAX_PARAM_SPATIAL_SUBFRAMES * LOWBITRATE_NUM_BANDS ) * 0.5f; /* Average energy multiplied with energy ratio of 0.5f */ - bandRatio = hqmetadata->q_direction[0].band_data[band].energy_ratio[0]; + hQMeta->twoDirBands[band] = hMasa->data.twoDirBands[band]; + } + hQMeta->numTwoDirBands = hMasa->config.numTwoDirBands; + } - bandEnergy = 0.0f; - for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + /* Copy spread coherence for DCT-based coding */ + if ( numSf == 1 && hMasa->config.useCoherence ) + { + for ( dir = 0; dir < numDirections; dir++ ) + { + for ( sf = 1; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - bandEnergy += energy[sf][band]; + for ( band = 0; band < numCodingBands; band++ ) + { + hQMeta->q_direction[dir].coherence_band_data[band].spread_coherence[sf] = hQMeta->q_direction[dir].coherence_band_data[band].spread_coherence[0]; + } } + } + } - if ( bandEnergy / MAX_PARAM_SPATIAL_SUBFRAMES * bandRatio > threshold ) + return; +} +#else +static void move_metadata_to_qmetadata_fx( + const MASA_ENCODER_HANDLE hMasa, + IVAS_QMETADATA_HANDLE hQMeta ) +{ + Word16 dir, sf, band; + UWord8 numCodingBands; + UWord8 numDirections; + UWord8 numSf; + MASA_METADATA_HANDLE hMeta; + + numCodingBands = hMasa->config.numCodingBands; + numDirections = hMasa->config.numberOfDirections; + move16(); + move16(); + move16(); + numSf = 4; + if ( EQ_16( hMasa->config.joinedSubframes, TRUE ) ) + { + numSf = 1; + move16(); + } + hMeta = &( hMasa->masaMetadata ); + + FOR( dir = 0; dir < numDirections; dir++ ) + { + FOR( sf = 0; sf < numSf; sf++ ) + { + FOR( band = 0; band < numCodingBands; band++ ) { - selectedBand = band; - break; + hQMeta->q_direction[dir].band_data[band].azimuth_fx[sf] = hMeta->directional_meta[dir].azimuth_fx[sf][band]; + hQMeta->q_direction[dir].band_data[band].elevation_fx[sf] = hMeta->directional_meta[dir].elevation_fx[sf][band]; + hQMeta->q_direction[dir].band_data[band].energy_ratio_fx[sf] = hMeta->directional_meta[dir].energy_ratio_fx[sf][band]; + hQMeta->q_direction[dir].band_data[band].spherical_index[sf] = hMeta->directional_meta[dir].spherical_index[sf][band]; + move32(); + move32(); + move32(); + move16(); + + IF( hQMeta->q_direction[dir].coherence_band_data != NULL ) + { + hQMeta->q_direction[dir].coherence_band_data[band].spread_coherence[sf] = (UWord8) mult_r( hMeta->directional_meta[dir].spread_coherence_fx[sf][band], UINT8_MAX ); + move16(); + } } } + } - /* Determine if to merge over frequency instead of time */ - meanRatio = 0.0f; - for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + FOR( sf = 0; sf < numSf; sf++ ) + { + FOR( band = 0; band < numCodingBands; band++ ) { - for ( band = 0; band < numCodingBands; band++ ) + IF( hQMeta->surcoh_band_data != NULL ) { - meanRatio += hqmetadata->q_direction[0].band_data[band].energy_ratio[sf] * energy[sf][band]; + hQMeta->surcoh_band_data[band].surround_coherence[sf] = (UWord8) mult_r( hMeta->common_meta.surround_coherence_fx[sf][band], UINT8_MAX ); + move16(); } } - meanRatio /= ( totalEnergySum + EPSILON ); + } - /* If the ratio of the selected band is larger than the average ratio of all bands and if there is an onset, merge over frequency bands. - * Otherwise, merge over subframes. */ - if ( hqmetadata->q_direction[0].band_data[selectedBand].energy_ratio[0] > meanRatio ) - { - mergeOverFreqBands = 1; - } - else + IF( GT_16( numDirections, 1 ) ) + { + FOR( band = 0; band < numCodingBands; band++ ) { - mergeOverFreqBands = 0; + hQMeta->twoDirBands[band] = hMasa->data.twoDirBands[band]; + move16(); } - } - else - { - mergeOverFreqBands = 0; + hQMeta->numTwoDirBands = hMasa->config.numTwoDirBands; + move16(); } - /* Merge values over subframes or frequency bands, depending on which one is less important */ - if ( !mergeOverFreqBands ) /* Merge values over subframes */ + /* Copy spread coherence for DCT-based coding */ + test(); + IF( EQ_16( numSf, 1 ) && hMasa->config.useCoherence ) { - float xSum, ySum, zSum; - float bandSumEnergy; - float aziRad, eleRad; - float x, y, z; - float veclen; - - for ( band = 0; band < numCodingBands; band++ ) + FOR( dir = 0; dir < numDirections; dir++ ) { - xSum = 0.0f; - ySum = 0.0f; - zSum = 0.0f; - bandSumEnergy = 0.0f; - - for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + FOR( sf = 1; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - aziRad = hqmetadata->q_direction[0].band_data[band].azimuth[sf] / 180.0f * EVS_PI; - eleRad = hqmetadata->q_direction[0].band_data[band].elevation[sf] / 180.0f * EVS_PI; - veclen = hqmetadata->q_direction[0].band_data[band].energy_ratio[sf] * energy[sf][band]; + FOR( band = 0; band < numCodingBands; band++ ) + { + hQMeta->q_direction[dir].coherence_band_data[band].spread_coherence[sf] = hQMeta->q_direction[dir].coherence_band_data[band].spread_coherence[0]; + move16(); + } + } + } + } - x = cosf( aziRad ) * cosf( eleRad ) * veclen; - y = sinf( aziRad ) * cosf( eleRad ) * veclen; - z = sinf( eleRad ) * veclen; + return; +} +#endif - xSum += x; - ySum += y; - zSum += z; - bandSumEnergy += energy[sf][band]; - } +/* This function studies parametric MASA metadata to provide information for codec configuration */ +#ifdef IVAS_FLOAT_FIXED +static void detect_metadata_composition_fx( + const MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder data */ + UWord8 *joinedSubframes, /* o : Result of subframe composition */ + UWord8 *coherencePresent, /* o : Result of coherence presence */ + UWord8 *isTwoDir /* o : Result of two direction check */ +) +{ + MASA_METADATA_FRAME *hMeta; + Word8 sf, band, dir, numDir; + Word16 nSubFrames; + UWord8 dirValid[2] = { FALSE, FALSE }; + UWord8 cohPresent = FALSE; + UWord8 sfDiffer = FALSE; + UWord8 sfSimilar; + move16(); /*dirValid[0]*/ + move16(); /*dirValid[1]*/ + move16(); /*cohPresent*/ + move16(); /*sfDiffer*/ - aziRad = atan2f( ySum, xSum ); - eleRad = atan2f( zSum, sqrtf( xSum * xSum + ySum * ySum ) ); + hMeta = &( hMasa->masaMetadata ); + numDir = (Word8) add( hMeta->descriptive_meta.numberOfDirections, 1 ); + move16(); - hqmetadata->q_direction[0].band_data[band].azimuth[0] = aziRad / EVS_PI * 180.0f; - hqmetadata->q_direction[0].band_data[band].elevation[0] = eleRad / EVS_PI * 180.0f; + *isTwoDir = FALSE; + move16(); - /* Energy ratio is already merged through time */ + /* First check for valid two directions */ + IF( EQ_16( numDir, 1 ) ) + { + dirValid[0] = TRUE; + move16(); + } + ELSE + { + /* Default assumption */ + *isTwoDir = TRUE; + move16(); - if ( computeCoherence && hqmetadata->q_direction[0].coherence_band_data != NULL ) + /* Check for direct-to-total ratio values */ + FOR( dir = 0; dir < numDir; dir++ ) + { + sf = 0; + move16(); + WHILE( !dirValid[dir] && LT_16( sf, MAX_PARAM_SPATIAL_SUBFRAMES ) ) { - float spreadCoh; - float spreadCohSum = 0.0f; - for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) - { - spreadCoh = (float) hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf] / 255.0f; - spreadCohSum += spreadCoh * energy[sf][band]; - } - hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[0] = (uint8_t) roundf( spreadCohSum / ( bandSumEnergy + EPSILON ) * 255.0f ); - - /* Copy spread coherence to the rest of subframes for the coherence coding algorithm. */ - for ( sf = 1; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + test(); + band = 0; + move16(); + WHILE( !dirValid[dir] && LT_16( band, MASA_FREQUENCY_BANDS ) ) { - for ( band = 0; band < numCodingBands; band++ ) + test(); + IF( GE_32( hMeta->directional_meta[dir].energy_ratio_fx[sf][band] /*q30*/, MASA_RATIO_THRESHOLD_FX >> 1 /*q30*/ ) ) { - hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[0]; + dirValid[dir] = TRUE; + move16(); } + band = (Word8) add( band, 1 ); } - - /* Surround coherence is already merged through time */ + sf = (Word8) add( sf, 1 ); } } - hqmetadata->q_direction->cfg.nblocks = 1; - hMasa->config.joinedSubframes = 1; - } - else /* Merge values over frequency bands */ - { - /* Use the selected frequency band to represent all data */ - for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + test(); + IF( dirValid[1] == FALSE ) { - hqmetadata->q_direction[0].band_data[0].azimuth[sf] = hqmetadata->q_direction[0].band_data[selectedBand].azimuth[sf]; - hqmetadata->q_direction[0].band_data[0].elevation[sf] = hqmetadata->q_direction[0].band_data[selectedBand].elevation[sf]; - hqmetadata->q_direction[0].band_data[0].energy_ratio[sf] = hqmetadata->q_direction[0].band_data[selectedBand].energy_ratio[sf]; - if ( hqmetadata->q_direction[0].coherence_band_data != NULL ) - { - hqmetadata->q_direction[0].coherence_band_data[0].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[selectedBand].spread_coherence[sf]; - } - if ( hqmetadata->surcoh_band_data != NULL ) - { - hqmetadata->surcoh_band_data[0].surround_coherence[sf] = hqmetadata->surcoh_band_data[selectedBand].surround_coherence[sf]; - } + /* This handles also case where both are false. Then we just use first dir metadata. */ + *isTwoDir = FALSE; + move16(); } - - /* Copy coherence to rest of bands for the coherence coding algorithm. */ - for ( band = 1; band < numCodingBands; band++ ) + ELSE IF( dirValid[0] == FALSE && EQ_16( dirValid[1], TRUE ) ) { - if ( hqmetadata->q_direction[0].coherence_band_data != NULL ) - { - for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) - { - hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[0].spread_coherence[sf]; - } - } - if ( hqmetadata->q_direction[0].coherence_band_data != NULL ) + *isTwoDir = FALSE; + move16(); + /* Copy data to first direction */ + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) { - hqmetadata->surcoh_band_data[band].surround_coherence[sf] = hqmetadata->surcoh_band_data[0].surround_coherence[sf]; + hMeta->directional_meta[0].azimuth_fx[sf][band] = hMeta->directional_meta[1].azimuth_fx[sf][band]; /*q22*/ + hMeta->directional_meta[0].elevation_fx[sf][band] = hMeta->directional_meta[1].elevation_fx[sf][band]; /*q22*/ + hMeta->directional_meta[0].energy_ratio_fx[sf][band] = hMeta->directional_meta[1].energy_ratio_fx[sf][band]; /*q30*/ + hMeta->directional_meta[0].spread_coherence_fx[sf][band] = hMeta->directional_meta[1].spread_coherence_fx[sf][band]; /*q15*/ + move32(); + move16(); + move16(); + move16(); } } } - hqmetadata->q_direction[0].cfg.nbands = 1; + IF( *isTwoDir == FALSE ) + { + /* Further checks will be done with just one direction */ + numDir = 1; + move16(); + } } - return; -} -#else -/* If the bit budget is very low, reduce metadata further to either 1 subframe and 5 bands, or 1 band and 4 subframes, based on which works better */ -static void reduce_metadata_further_fx( - MASA_ENCODER_HANDLE hMasa, - IVAS_QMETADATA_HANDLE hqmetadata, - const IVAS_FORMAT ivas_format ) -{ - Word16 sf; - Word16 band; - Word16 selectedBand; - Word32 energy[MAX_PARAM_SPATIAL_SUBFRAMES][LOWBITRATE_NUM_BANDS]; - Word32 totalEnergySum; - UWord8 numCodingBands; - UWord8 computeCoherence; - Word32 onset_filter; - Word16 onset_filter_e, exp; - Word32 bandEnergy; - UWord8 mergeOverFreqBands; - Word32 meanRatio; - Word16 tmp; - - numCodingBands = hMasa->config.numCodingBands; - test(); - computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; - move16(); + /* Check if data over subframes is identical. Check is done by comparing to first subframe. */ + sfSimilar = TRUE; + sf = 1; move16(); - - /* Set default values */ - selectedBand = 0; - mergeOverFreqBands = 0; move16(); + WHILE( EQ_16( sfSimilar, TRUE ) && LT_16( sf, MAX_PARAM_SPATIAL_SUBFRAMES ) ) + { + test(); + sfSimilar = are_masa_subframes_similar_fx( hMeta, 0, hMeta, sf ); + sf = (Word8) add( sf, 1 ); + move16(); + } + IF( sfSimilar == TRUE ) + sfDiffer = FALSE; + ELSE + sfDiffer = TRUE; move16(); - /* Get energy for the input data in 4-subframe, 5-band format */ - totalEnergySum = 0; - move32(); - test(); - IF( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) ) /* Energy data is in 4-subframe, 24-band format */ + /* Further checks can be done with just one subframe if they are identical */ + IF( EQ_16( sfDiffer, TRUE ) ) + nSubFrames = MAX_PARAM_SPATIAL_SUBFRAMES; + ELSE + nSubFrames = 1; + move16(); + + /* Check spread coherence */ + dir = 0; + move16(); + WHILE( cohPresent == FALSE && LT_16( dir, numDir ) ) { - FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + test(); + sf = 0; + move16(); + WHILE( cohPresent == FALSE && LT_16( sf, nSubFrames ) ) { - Word16 brange[2]; - Word32 eneSum; - Word16 m; - - FOR( band = 0; band < numCodingBands; band++ ) + test(); + band = 0; + move16(); + WHILE( cohPresent == FALSE /*has value zero*/ && LT_16( band, MASA_FREQUENCY_BANDS ) ) { - brange[0] = hMasa->data.band_mapping[band]; - brange[1] = hMasa->data.band_mapping[band + 1]; - move16(); - move16(); - - eneSum = 0; - move32(); - FOR( m = brange[0]; m < brange[1]; m++ ) + test(); + /* Check coherences for presence of coherence */ + IF( GT_16( hMeta->directional_meta[dir].spread_coherence_fx[sf][band] /*Q15*/, MASA_COHERENCE_THRESHOLD_FX >> 16 ) ) /*Q15*/ { - eneSum = L_add( eneSum, hMasa->data.energy_fx[sf][m] ); // hMasa->data.q_energy + cohPresent = TRUE; + move16(); } - energy[sf][band] = eneSum; // hMasa->data.q_energy - move32(); - totalEnergySum = L_add( totalEnergySum, eneSum ); // hMasa->data.q_energy + band = (Word8) add( band, 1 ); + move16(); } + sf = (Word8) add( sf, 1 ); + move16(); } + dir = (Word8) add( dir, 1 ); + move16(); } - ELSE /* Energy data is already in 4-subframe, 5-band format */ + + /* Check surround coherence separately if we do not have already knowledge of coherence */ + IF( cohPresent == FALSE ) { - FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + Word32 surround_coherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 diffuse_to_total_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 i, j; + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - FOR( band = 0; band < numCodingBands; band++ ) + FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - energy[sf][band] = hMasa->data.energy_fx[sf][band]; // hMasa->data.q_energy - move32(); - totalEnergySum = L_add( totalEnergySum, energy[sf][band] ); // hMasa->data.q_energy + surround_coherence_fx[i][j] = L_deposit_h( hMeta->common_meta.surround_coherence_fx[i][j] ); /*q31*/ + diffuse_to_total_ratio_fx[i][j] = L_shl_sat( hMeta->common_meta.diffuse_to_total_ratio_fx[i][j], 1 ); /*q31*/ } } + cohPresent = ivas_masa_surrcoh_signicant_fx( surround_coherence_fx, diffuse_to_total_ratio_fx, nSubFrames, MASA_FREQUENCY_BANDS ); } - /* Determine onsets */ - hMasa->data.onset_detector_1_fx = Mpy_32_32( hMasa->data.onset_detector_1_fx, LOWBITRATE_ONSET_ALPHA_Q31 ); - move32(); - - tmp = hMasa->data.q_onset_detector; - move16(); - IF( BASOP_Util_Cmp_Mant32Exp( hMasa->data.onset_detector_1_fx, sub( 31, hMasa->data.q_onset_detector ), totalEnergySum, sub( 31, hMasa->data.q_energy ) ) < 0 ) - { - hMasa->data.onset_detector_1_fx = totalEnergySum; // hMasa->data.q_energy - hMasa->data.q_onset_detector = hMasa->data.q_energy; - move32(); - move16(); - } - IF( LT_16( tmp, hMasa->data.q_onset_detector ) ) + /* Set output flags */ + IF( EQ_16( sfDiffer, TRUE ) ) { - hMasa->data.onset_detector_1_fx = L_shr( hMasa->data.onset_detector_1_fx, sub( hMasa->data.q_onset_detector, tmp ) ); // tmp - hMasa->data.onset_detector_2_fx = L_add( Mpy_32_32( LOWBITRATE_ONSET_BETA_Q31, hMasa->data.onset_detector_2_fx ), Mpy_32_32( ( ONE_IN_Q31 - LOWBITRATE_ONSET_BETA_Q31 ), hMasa->data.onset_detector_1_fx ) ); // tmp - hMasa->data.q_onset_detector = tmp; - move32(); - move32(); - move16(); + *joinedSubframes = FALSE; } ELSE { - hMasa->data.onset_detector_2_fx = L_add( L_shr( Mpy_32_32( LOWBITRATE_ONSET_BETA_Q31, hMasa->data.onset_detector_2_fx ), sub( tmp, hMasa->data.q_onset_detector ) ), Mpy_32_32( ( ONE_IN_Q31 - LOWBITRATE_ONSET_BETA_Q31 ), hMasa->data.onset_detector_1_fx ) ); // hMasa->data.q_onset_detector - move32(); + *joinedSubframes = TRUE; } - hMasa->data.onset_detector_2_fx = L_shl( Mpy_32_32( LOWBITRATE_ONSET_GAIN_Q30, L_min( hMasa->data.onset_detector_1_fx, hMasa->data.onset_detector_2_fx ) ), 1 ); // hMasa->data.q_onset_detector - move32(); + move16(); + *coherencePresent = cohPresent; + move16(); - IF( hMasa->data.onset_detector_1_fx != 0 ) - { - onset_filter = L_max( BASOP_Util_Divide3232_Scale_cadence( hMasa->data.onset_detector_2_fx, hMasa->data.onset_detector_1_fx, &onset_filter_e ), 0 ); + return; +} +#else +static void detect_metadata_composition( + const MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder data */ + uint8_t *joinedSubframes, /* o : Result of subframe composition */ + uint8_t *coherencePresent, /* o : Result of coherence presence */ + uint8_t *isTwoDir /* o : Result of two direction check */ +) +{ + MASA_METADATA_FRAME *hMeta; + int8_t sf, band, dir, numDir; + int16_t nSubFrames; + uint8_t dirValid[2] = { FALSE, FALSE }; + uint8_t cohPresent = FALSE; + uint8_t sfDiffer = FALSE; + uint8_t sfSimilar; - IF( BASOP_Util_Cmp_Mant32Exp( onset_filter, onset_filter_e, ONE_IN_Q31, 0 ) > 0 ) - { - onset_filter = ONE_IN_Q31; - onset_filter_e = 0; - move32(); - move16(); - } - } - ELSE + hMeta = &( hMasa->masaMetadata ); + numDir = hMeta->descriptive_meta.numberOfDirections + 1; + + *isTwoDir = FALSE; + + /* First check for valid two directions */ + if ( numDir == 1 ) { - onset_filter = ONE_IN_Q31; - onset_filter_e = 0; - move32(); - move16(); + dirValid[0] = TRUE; } - /* If we have onset, continue checking if we should reduce in frequency instead of time. */ - IF( BASOP_Util_Cmp_Mant32Exp( onset_filter, onset_filter_e, 2126008812 /* 0.99f in Q31 */, 0 ) < 0 ) + else { - /* Determine one frequency band to use to represent all frequency bands */ - FOR( band = numCodingBands - 1; band >= 0; band-- ) - { - Word32 threshold; - Word32 bandRatio; - - // threshold = totalEnergySum / ( MAX_PARAM_SPATIAL_SUBFRAMES * LOWBITRATE_NUM_BANDS ) * 0.5f; /* Average energy multiplied with energy ratio of 0.5f */ - threshold = BASOP_Util_Divide3232_Scale_cadence( totalEnergySum, ( MAX_PARAM_SPATIAL_SUBFRAMES * LOWBITRATE_NUM_BANDS ) * 2, &exp ); /* Average energy multiplied with energy ratio of 0.5f */ - exp = add( exp, sub( sub( 31, hMasa->data.q_energy ), 31 ) ); - bandRatio = hqmetadata->q_direction[0].band_data[band].energy_ratio_fx[0]; // Q30 - move32(); - - bandEnergy = 0; - move32(); - FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) - { - bandEnergy = L_add( bandEnergy, energy[sf][band] ); - } - - IF( BASOP_Util_Cmp_Mant32Exp( Mpy_32_32( L_shr( bandEnergy, 2 ), bandRatio ), sub( 31 + 1, hMasa->data.q_energy ), threshold, exp ) > 0 ) - { - selectedBand = band; - move16(); - BREAK; - } - } + /* Default assumption */ + *isTwoDir = TRUE; - /* Determine if to merge over frequency instead of time */ - meanRatio = 0; - move32(); - FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + /* Check for direct-to-total ratio values */ + for ( dir = 0; dir < numDir; dir++ ) { - FOR( band = 0; band < numCodingBands; band++ ) + sf = 0; + while ( !dirValid[dir] && sf < MAX_PARAM_SPATIAL_SUBFRAMES ) { - meanRatio = L_add( meanRatio, Mpy_32_32( hqmetadata->q_direction[0].band_data[band].energy_ratio_fx[sf], energy[sf][band] ) ); // hMasa->data.q_energy - 1 + band = 0; + while ( !dirValid[dir] && band < MASA_FREQUENCY_BANDS ) + { + if ( hMeta->directional_meta[dir].energy_ratio[sf][band] >= MASA_RATIO_THRESHOLD ) + { + dirValid[dir] = TRUE; + } + band++; + } + sf++; } } - IF( totalEnergySum != 0 ) + + if ( dirValid[1] == FALSE ) { - meanRatio = BASOP_Util_Divide3232_Scale_cadence( meanRatio, totalEnergySum, &exp ); - exp = add( exp, 1 ); // 31 - (hMasa->data.q_energy - 1) - 31 - hMasa->data.q_energy => 1 + /* This handles also case where both are false. Then we just use first dir metadata. */ + *isTwoDir = FALSE; } - ELSE + else if ( dirValid[0] == FALSE && dirValid[1] == TRUE ) { - meanRatio = MAX_32; - exp = 31; - move32(); - move16(); + *isTwoDir = FALSE; + /* Copy data to first direction */ + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + for ( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + { + hMeta->directional_meta[0].azimuth[sf][band] = hMeta->directional_meta[1].azimuth[sf][band]; + hMeta->directional_meta[0].elevation[sf][band] = hMeta->directional_meta[1].elevation[sf][band]; + hMeta->directional_meta[0].energy_ratio[sf][band] = hMeta->directional_meta[1].energy_ratio[sf][band]; + hMeta->directional_meta[0].spread_coherence[sf][band] = hMeta->directional_meta[1].spread_coherence[sf][band]; + } + } } - /* If the ratio of the selected band is larger than the average ratio of all bands and if there is an onset, merge over frequency bands. - * Otherwise, merge over subframes. */ - IF( BASOP_Util_Cmp_Mant32Exp( hqmetadata->q_direction[0].band_data[selectedBand].energy_ratio_fx[0], 1, meanRatio, exp ) > 0 ) - { - mergeOverFreqBands = 1; - move16(); - } - ELSE + if ( *isTwoDir == FALSE ) { - mergeOverFreqBands = 0; - move16(); + /* Further checks will be done with just one direction */ + numDir = 1; } } - ELSE + + /* Check if data over subframes is identical. Check is done by comparing to first subframe. */ + sfSimilar = TRUE; + sf = 1; + while ( ( sfSimilar == TRUE ) && ( sf < MAX_PARAM_SPATIAL_SUBFRAMES ) ) { - mergeOverFreqBands = 0; - move16(); + sfSimilar = are_masa_subframes_similar( hMeta, 0, hMeta, sf ); + sf++; } + sfDiffer = sfSimilar == TRUE ? FALSE : TRUE; - /* Merge values over subframes or frequency bands, depending on which one is less important */ - IF( !mergeOverFreqBands ) /* Merge values over subframes */ - { - Word32 xSum, ySum, zSum; - Word64 W_xSum_sq, W_ySum_sq, W_tmp; - Word32 bandSumEnergy; - Word16 aziRad, eleRad, q_shift, exp_diff; - Word32 x, y, z; - Word32 veclen, L_tmp; + /* Further checks can be done with just one subframe if they are identical */ + nSubFrames = sfDiffer == TRUE ? MAX_PARAM_SPATIAL_SUBFRAMES : 1; - FOR( band = 0; band < numCodingBands; band++ ) + /* Check spread coherence */ + dir = 0; + while ( cohPresent == FALSE && dir < numDir ) + { + sf = 0; + while ( cohPresent == FALSE && sf < nSubFrames ) { - xSum = 0; - ySum = 0; - zSum = 0; - bandSumEnergy = 0; - move32(); - move32(); - move32(); - move32(); - - FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + band = 0; + while ( cohPresent == FALSE && band < MASA_FREQUENCY_BANDS ) { - aziRad = extract_l( Mpy_32_32( hqmetadata->q_direction[0].band_data[band].azimuth_fx[sf], PI_OVER_180_Q22 ) ); - eleRad = extract_l( Mpy_32_32( hqmetadata->q_direction[0].band_data[band].elevation_fx[sf], PI_OVER_180_Q22 ) ); - veclen = Mpy_32_32( hqmetadata->q_direction[0].band_data[band].energy_ratio_fx[sf], energy[sf][band] ); // hMasa->data.q_energy - 1 - - x = Mpy_32_32( L_mult( getCosWord16( aziRad ), getCosWord16( eleRad ) ), veclen ); // (Q29, hMasa->data.q_energy - Q1) -> hMasa->data.q_energy - Q3 - move32(); - y = Mpy_32_32( L_mult0( getSinWord16( aziRad ), getCosWord16( eleRad ) ), veclen ); // (Q29, hMasa->data.q_energy - Q1) -> hMasa->data.q_energy - Q3 - move32(); - z = Mpy_32_32( L_mult0( getSinWord16( eleRad ), ONE_IN_Q14 ), veclen ); // (Q29, hMasa->data.q_energy - Q1) -> hMasa->data.q_energy - Q3 - move32(); - - xSum = L_add( xSum, x ); - ySum = L_add( ySum, y ); - zSum = L_add( zSum, z ); - - bandSumEnergy = L_add( bandSumEnergy, energy[sf][band] ); + /* Check coherences for presence of coherence */ + if ( hMeta->directional_meta[dir].spread_coherence[sf][band] >= MASA_COHERENCE_THRESHOLD ) + { + cohPresent = TRUE; + } + band++; } + sf++; + } + dir++; + } - aziRad = BASOP_util_atan2( ySum, xSum, 0 ); // Q13 - W_xSum_sq = W_mult0_32_32( xSum, xSum ); // 2 * hMasa->data.q_energy - Q6 - W_ySum_sq = W_mult0_32_32( ySum, ySum ); // 2 * hMasa->data.q_energy - Q6 - W_tmp = W_add( W_xSum_sq, W_ySum_sq ); // 2 * hMasa->data.q_energy - Q6 - q_shift = W_norm( W_tmp ); - L_tmp = W_extract_h( W_shl( W_tmp, q_shift ) ); // 2 * hMasa->data.q_energy - Q6 + (q_shift -32) - exp_diff = sub( Q31, add( sub( imult1616( 2, hMasa->data.q_energy ), Q6 ), sub( q_shift, 32 ) ) ); - L_tmp = Sqrt32( L_tmp, &exp_diff ); - eleRad = BASOP_util_atan2( zSum, L_tmp, sub( sub( 34, hMasa->data.q_energy ), exp_diff ) ); // Q13 + /* Check surround coherence separately if we do not have already knowledge of coherence */ + if ( cohPresent == FALSE ) + { + cohPresent = ivas_masa_surrcoh_signicant( hMeta->common_meta.surround_coherence, hMeta->common_meta.diffuse_to_total_ratio, nSubFrames, MASA_FREQUENCY_BANDS ); + } - hqmetadata->q_direction[0].band_data[band].azimuth_fx[0] = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, aziRad ), Q1 ); // ((Q25, Q13) -> Q23) >> Q1 -> Q22 - hqmetadata->q_direction[0].band_data[band].elevation_fx[0] = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, eleRad ), Q1 ); // ((Q25, Q13) -> Q23) >> Q1 -> Q22 + /* Set output flags */ + *joinedSubframes = sfDiffer == TRUE ? FALSE : TRUE; + *coherencePresent = cohPresent; - /* Energy ratio is already merged through time */ - test(); - IF( computeCoherence && hqmetadata->q_direction[0].coherence_band_data != NULL ) - { - Word16 spreadCoh; - Word32 spreadCohSum = 0; - move32(); - FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) - { - spreadCoh = div_s( (Word16) hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf], 255 ); // Q15 - spreadCohSum = L_add( spreadCohSum, Mpy_32_16_1( energy[sf][band], spreadCoh ) ); - } - // hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[0] = (uint8_t) roundf( spreadCohSum / ( bandSumEnergy + EPSILON ) * 255.0f ); - tmp = BASOP_Util_Divide3232_Scale( spreadCohSum, bandSumEnergy, &exp ); - tmp = mult_r( tmp, 32640 /* 255 in Q7 */ ); // 15 - exp + 7 - 15 => 7 - exp - hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[0] = (UWord8) shr( tmp, sub( 7, exp ) ); // Q0 - move16(); + return; +} +#endif // IVAS_FLOAT_FIXED - /* Copy spread coherence to the rest of subframes for the coherence coding algorithm. */ - FOR( sf = 1; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) - { - FOR( band = 0; band < numCodingBands; band++ ) - { - hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[0]; - move16(); - } - } - /* Surround coherence is already merged through time */ - } - } +/* Check and compensate energy ratios. This function verifies that energy ratios follow the principle of summing to one. + * In addition, it implements simple remainder-to-total handling where remainder energy is proportionally added to other + * ratios. */ +#ifdef IVAS_FLOAT_FIXED +static void compensate_energy_ratios_fx( + MASA_ENCODER_HANDLE hMasa ) +{ + Word16 sf, band, dir; + Word32 ratioSum; + MASA_METADATA_HANDLE hMeta; + UWord8 numDirs; - hqmetadata->q_direction->cfg.nblocks = 1; - hMasa->config.joinedSubframes = 1; - move16(); - move16(); - } - ELSE /* Merge values over frequency bands */ + hMeta = &( hMasa->masaMetadata ); + numDirs = (UWord8) add( hMeta->descriptive_meta.numberOfDirections, 1 ); + + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - /* Use the selected frequency band to represent all data */ - FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) { - hqmetadata->q_direction[0].band_data[0].azimuth_fx[sf] = hqmetadata->q_direction[0].band_data[selectedBand].azimuth_fx[sf]; - hqmetadata->q_direction[0].band_data[0].elevation_fx[sf] = hqmetadata->q_direction[0].band_data[selectedBand].elevation_fx[sf]; - hqmetadata->q_direction[0].band_data[0].energy_ratio_fx[sf] = hqmetadata->q_direction[0].band_data[selectedBand].energy_ratio_fx[sf]; - move32(); + /* Remainder is always set to zero and energy removal is compensated in following steps + * to other ratios. */ + hMeta->common_meta.remainder_to_total_ratio_fx[sf][band] = 0; // Q30 move32(); + + ratioSum = 0; move32(); - if ( hqmetadata->q_direction[0].coherence_band_data != NULL ) - { - hqmetadata->q_direction[0].coherence_band_data[0].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[selectedBand].spread_coherence[sf]; - move16(); - } - if ( hqmetadata->surcoh_band_data != NULL ) + FOR( dir = 0; dir < numDirs; dir++ ) { - hqmetadata->surcoh_band_data[0].surround_coherence[sf] = hqmetadata->surcoh_band_data[selectedBand].surround_coherence[sf]; - move16(); + ratioSum = L_add( ratioSum, hMeta->directional_meta[dir].energy_ratio_fx[sf][band] ); // Q30 } - } + ratioSum = L_add( ratioSum, hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] ); // Q30 - /* Copy coherence to rest of bands for the coherence coding algorithm. */ - FOR( band = 1; band < numCodingBands; band++ ) - { - IF( hqmetadata->q_direction[0].coherence_band_data != NULL ) + IF( ratioSum == 0 ) { - FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + FOR( dir = 0; dir < numDirs; dir++ ) { - hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[0].spread_coherence[sf]; - move16(); + hMeta->directional_meta[dir].energy_ratio_fx[sf][band] = 0; // Q30 + move32(); } + hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = ONE_IN_Q30; // Q30 + move32(); } - IF( hqmetadata->q_direction[0].coherence_band_data != NULL ) + // ELSE IF( NE_32( ratioSum, ONE_IN_Q30 ) ) + ELSE /* Removing the check against 1 works well!!! */ { - FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + Word16 exp_diff; + FOR( dir = 0; dir < numDirs; dir++ ) { - hqmetadata->surcoh_band_data[band].surround_coherence[sf] = hqmetadata->surcoh_band_data[0].surround_coherence[sf]; - move16(); + hMeta->directional_meta[dir].energy_ratio_fx[sf][band] = + BASOP_Util_Divide3232_Scale_cadence( hMeta->directional_meta[dir].energy_ratio_fx[sf][band], ratioSum, &exp_diff ); + move32(); + hMeta->directional_meta[dir].energy_ratio_fx[sf][band] = L_shl( hMeta->directional_meta[dir].energy_ratio_fx[sf][band], sub( exp_diff, Q1 ) ); // Q30 + move32(); } + hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = + BASOP_Util_Divide3232_Scale_cadence( hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], ratioSum, &exp_diff ); + move32(); + hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_shl( hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], sub( exp_diff, Q1 ) ); // Q30 + move32(); } } - - hqmetadata->q_direction[0].cfg.nbands = 1; - move16(); } return; } -#endif - - -#ifdef IVAS_FLOAT_FIXED -static Word16 encode_lfe_to_total_energy_ratio_fx( - MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ - BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ -) +#else +static void compensate_energy_ratios( + MASA_ENCODER_HANDLE hMasa ) { - Word16 i; - Word16 xq; - Word16 VQLevels; - Word32 maxLFESubFrameEner; - Word16 maxLFESubFrameEner_e; - Word32 log2LFEaverage; - Word32 log2LFEratio[4]; - Word32 xqv[4]; - Word32 linearLFEaverage; - Word16 linearLFEaverage_e; - Word16 lfeToTotalEnergyRatioIndices[3]; - Word16 lfeAdaptiveVQBits; - Word16 lfeBitsWritten; - Word32 maxVal; - Word16 maxVal_e; + int16_t sf, band, dir; + float ratioSum; + MASA_METADATA_HANDLE hMeta; + uint8_t numDirs; - VQLevels = 0; - move16(); - lfeAdaptiveVQBits = 0; - move16(); + hMeta = &( hMasa->masaMetadata ); + numDirs = hMeta->descriptive_meta.numberOfDirections + 1; - /* Determine maximum amount of LFE energy in any subframe */ - maxLFESubFrameEner = 0; - move32(); - maxLFESubFrameEner_e = 0; - move16(); - FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - IF( BASOP_Util_Cmp_Mant32Exp( hMasa->data.lfeToTotalEnergyRatio_fx[i], hMasa->data.lfeToTotalEnergyRatio_e[i], maxLFESubFrameEner, maxLFESubFrameEner_e ) > 0 ) + for ( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) { - maxLFESubFrameEner = hMasa->data.lfeToTotalEnergyRatio_fx[i]; - move32(); - maxLFESubFrameEner_e = hMasa->data.lfeToTotalEnergyRatio_e[i]; - move16(); - } - } - - /* Set default values for the indices */ - FOR( i = 0; i < 3; i++ ) - { - lfeToTotalEnergyRatioIndices[i] = 0; - move16(); - } + /* Remainder is always set to zero and energy removal is compensated in following steps + * to other ratios. */ + hMeta->common_meta.remainder_to_total_ratio[sf][band] = 0.0f; - /* Check if there is enough energy in any subframe. If not, send only 1 bit (0) and abort. */ - /* If there is enough LFE energy at least in one subframe, quantize it. */ - IF( BASOP_Util_Cmp_Mant32Exp( maxLFESubFrameEner, maxLFESubFrameEner_e, 10737418 /* 0.005f in Q31 */, 0 ) > 0 ) - { - /* Convert energy to log2 domain, and clamp it to reasonable values */ - log2LFEaverage = 0; // Q25 - move32(); - FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - // log2LFEratio[i] = log2f( max( 0.001f, hMasa->data.lfeToTotalEnergyRatio[i] ) ); - maxVal = 2147484 /* 0.001f in Q31 */; - move32(); - maxVal_e = 0; - move16(); - IF( BASOP_Util_Cmp_Mant32Exp( hMasa->data.lfeToTotalEnergyRatio_fx[i], hMasa->data.lfeToTotalEnergyRatio_e[i], maxVal, maxVal_e ) > 0 ) + ratioSum = 0; + for ( dir = 0; dir < numDirs; dir++ ) { - maxVal = hMasa->data.lfeToTotalEnergyRatio_fx[i]; - move32(); - maxVal_e = hMasa->data.lfeToTotalEnergyRatio_e[i]; - move16(); + ratioSum += hMeta->directional_meta[dir].energy_ratio[sf][band]; } - log2LFEratio[i] = L_add( BASOP_Util_Log2( maxVal ), L_shl( maxVal_e, Q25 ) ); // Q25 - move32(); - IF( GT_32( log2LFEratio[i], ONE_IN_Q25 ) ) /* Corresponds to linear value 2.0f */ + ratioSum += hMeta->common_meta.diffuse_to_total_ratio[sf][band]; + + if ( ratioSum == 0.0f ) { - log2LFEratio[i] = ONE_IN_Q25; // Q25 - move32(); + for ( dir = 0; dir < numDirs; dir++ ) + { + hMeta->directional_meta[dir].energy_ratio[sf][band] = 0.0f; + } + hMeta->common_meta.diffuse_to_total_ratio[sf][band] = 1.0f; } - ELSE IF( LT_32( log2LFEratio[i], -301989888 /* -9.0f in Q25 */ ) ) + else if ( ratioSum != 1.0f ) { - log2LFEratio[i] = -301989888 /* -9.0f in Q25 */; // Q25 - move32(); + for ( dir = 0; dir < numDirs; dir++ ) + { + hMeta->directional_meta[dir].energy_ratio[sf][band] /= ratioSum; + } + hMeta->common_meta.diffuse_to_total_ratio[sf][band] /= ratioSum; } - log2LFEaverage = L_add( log2LFEaverage, Mpy_32_32( 536870912 /* 0.25f in Q31 */, log2LFEratio[i] ) ); // Q25 } + } - IF( EQ_32( ivas_total_brate, IVAS_13k2 ) ) - { - /* Calculate adaptive 1-bit LFE quantizer index */ - // linearLFEaverage = exp2f( log2LFEaverage ); /* Convert back to linear domain */ - linearLFEaverage = BASOP_util_Pow2( log2LFEaverage, Q31 - Q25, &linearLFEaverage_e ); /* Convert back to linear domain */ - linearLFEaverage = L_shl( linearLFEaverage, linearLFEaverage_e ); // Q31 - test(); - IF( GT_32( linearLFEaverage, MCMASA_LFE_1BIT_THRES_Q31 ) && - GT_32( linearLFEaverage, L_add( L_add( MCMASA_LFE_BETA_Q31 >> Q1, L_shr( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, Q1 ) ), - L_shr( Mpy_32_32( MCMASA_LFE_ALPHA_Q31, hMasa->data.prevq_lfeToTotalEnergyRatio_fx ), Q1 ) ) ) ) - { - lfeToTotalEnergyRatioIndices[0] = 1; - move16(); - IF( EQ_16( hMasa->data.prevq_lfeIndex, 1 ) ) - { - hMasa->data.prevq_lfeToTotalEnergyRatio_fx = L_add( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, 251255587 /* MCMASA_LFE_THETA * MCMASA_LFE_BETA in Q31 */ ); /* larger "bump-up" to LFE-to-total energy ratio */ // Q31 - move32(); - } - ELSE - { - hMasa->data.prevq_lfeToTotalEnergyRatio_fx = L_add( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, MCMASA_LFE_BETA_Q31 ); /* default "bump-up" to LFE-to-total energy ratio */ // Q31 - move32(); - } - } - ELSE - { - hMasa->data.prevq_lfeToTotalEnergyRatio_fx = Mpy_32_32( MCMASA_LFE_ALPHA_Q31, hMasa->data.prevq_lfeToTotalEnergyRatio_fx ); /* exponential decay */ // Q31 - move32(); - } + return; +} +#endif - if ( GT_32( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, ONE_IN_Q31 ) ) - { - hMasa->data.prevq_lfeToTotalEnergyRatio_fx = ONE_IN_Q31; - move32(); - } - hMasa->data.prevq_lfeIndex = lfeToTotalEnergyRatioIndices[0]; /* Update to previous frame's index memories */ - move16(); - } - ELSE /* Bitrate >= 16.4 kbps */ +#ifndef IVAS_FLOAT_FIXED +/* If the bit budget is very low, reduce metadata further to either 1 subframe and 5 bands, or 1 band and 4 subframes, based on which works better */ +static void reduce_metadata_further( + MASA_ENCODER_HANDLE hMasa, + IVAS_QMETADATA_HANDLE hqmetadata, + const IVAS_FORMAT ivas_format ) +{ + int16_t sf; + int16_t band; + int16_t selectedBand; + float energy[MAX_PARAM_SPATIAL_SUBFRAMES][LOWBITRATE_NUM_BANDS]; + float totalEnergySum; + uint8_t numCodingBands; + uint8_t computeCoherence; + float onset_filter; + float bandEnergy; + uint8_t mergeOverFreqBands; + float meanRatio; + + numCodingBands = hMasa->config.numCodingBands; + computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; + + /* Set default values */ + selectedBand = 0; + mergeOverFreqBands = 0; + + /* Get energy for the input data in 4-subframe, 5-band format */ + totalEnergySum = 0.0f; + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) /* Energy data is in 4-subframe, 24-band format */ + { + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - /* Do 1st stage scalar quantization */ - lfeToTotalEnergyRatioIndices[0] = 1; - move16(); - lfeToTotalEnergyRatioIndices[1] = usquant_fx( extract_l( L_shr( log2LFEaverage, Q13 ) ), &xq, MCMASA_LFE_QLOW_Q12, MCMASA_LFE_DELTA_Q11, 8 ); - move16(); + int16_t brange[2]; + float eneSum; + int16_t m; - IF( GE_32( ivas_total_brate, IVAS_24k4 ) ) /* Vector quantization is applied if bitrate >= 24.4 kbps */ + for ( band = 0; band < numCodingBands; band++ ) { - /* Remove scalar value from the vector*/ - FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - log2LFEratio[i] = L_sub( log2LFEratio[i], L_shl( xq, Q13 ) ); // Q25 - move32(); - } - - /* Vector quantize residual with energy adaptive bit allocation */ - SWITCH( lfeToTotalEnergyRatioIndices[1] ) - { - case 0: - case 1: - VQLevels = 0; - move16(); - lfeAdaptiveVQBits = 0; - move16(); - BREAK; - case 2: - VQLevels = 2; - move16(); - lfeAdaptiveVQBits = 1; - move16(); - BREAK; - case 3: - VQLevels = 4; - move16(); - lfeAdaptiveVQBits = 2; - move16(); - BREAK; - case 4: - VQLevels = 8; - move16(); - lfeAdaptiveVQBits = 3; - move16(); - BREAK; - default: - VQLevels = 16; - move16(); - lfeAdaptiveVQBits = 4; - move16(); - } + brange[0] = hMasa->data.band_mapping[band]; + brange[1] = hMasa->data.band_mapping[band + 1]; - IF( VQLevels > 0 ) + eneSum = 0.0f; + for ( m = brange[0]; m < brange[1]; m++ ) { - lfeToTotalEnergyRatioIndices[2] = vquant_ivas_fx( log2LFEratio, 0, xqv, McMASA_LFEGain_vectors_fx_q25, 4, VQLevels ); - move16(); + eneSum += hMasa->data.energy[sf][m]; } + energy[sf][band] = eneSum; + totalEnergySum += eneSum; } } } - - /* Write first LFE bit */ - lfeBitsWritten = 0; - move16(); - push_next_indice( hMetaData, lfeToTotalEnergyRatioIndices[0], 1 ); - lfeBitsWritten = add( lfeBitsWritten, 1 ); - - test(); - IF( EQ_16( lfeToTotalEnergyRatioIndices[0], 1 ) && GE_32( ivas_total_brate, IVAS_16k4 ) ) + else /* Energy data is already in 4-subframe, 5-band format */ { - /* If bitrate >= 16.4kbit/s, send 1-bit on/off + 3-bit scalar */ - push_next_indice( hMetaData, lfeToTotalEnergyRatioIndices[1], 3 ); - lfeBitsWritten = add( lfeBitsWritten, 3 ); - - /* If bitrate >= 24.4kbit/s, use adaptive 1 + (3.. 7) bit quantizer */ - IF( GE_32( ivas_total_brate, IVAS_24k4 ) ) + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - /* Vector quantize residual with energy adaptive bit allocation */ - IF( lfeAdaptiveVQBits > 0 ) + for ( band = 0; band < numCodingBands; band++ ) { - push_next_indice( hMetaData, lfeToTotalEnergyRatioIndices[2], lfeAdaptiveVQBits ); - lfeBitsWritten = add( lfeBitsWritten, lfeAdaptiveVQBits ); + energy[sf][band] = hMasa->data.energy[sf][band]; + totalEnergySum += energy[sf][band]; } } } - return lfeBitsWritten; -} -#else -static int16_t encode_lfe_to_total_energy_ratio( - MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ - BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ -) -{ - int16_t i; - float xq; - int16_t VQLevels; - float maxLFESubFrameEner; - float log2LFEaverage; - float log2LFEratio[4]; - float xqv[4]; - float linearLFEaverage; - int16_t lfeToTotalEnergyRatioIndices[3]; - int16_t lfeAdaptiveVQBits; - int16_t lfeBitsWritten; + /* Determine onsets */ + hMasa->data.onset_detector_1 = hMasa->data.onset_detector_1 * LOWBITRATE_ONSET_ALPHA; + hMasa->data.onset_detector_1 = max( hMasa->data.onset_detector_1, totalEnergySum ); - VQLevels = 0; - lfeAdaptiveVQBits = 0; + hMasa->data.onset_detector_2 = LOWBITRATE_ONSET_BETA * hMasa->data.onset_detector_2 + ( 1.0f - LOWBITRATE_ONSET_BETA ) * hMasa->data.onset_detector_1; + hMasa->data.onset_detector_2 = LOWBITRATE_ONSET_GAIN * min( hMasa->data.onset_detector_1, hMasa->data.onset_detector_2 ); - /* Determine maximum amount of LFE energy in any subframe */ - maxLFESubFrameEner = 0.0f; - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + onset_filter = min( max( hMasa->data.onset_detector_2 / ( hMasa->data.onset_detector_1 + EPSILON ), 0.0f ), 1.0f ); + + /* If we have onset, continue checking if we should reduce in frequency instead of time. */ + if ( onset_filter < 0.99f ) { - if ( hMasa->data.lfeToTotalEnergyRatio[i] > maxLFESubFrameEner ) + /* Determine one frequency band to use to represent all frequency bands */ + for ( band = numCodingBands - 1; band >= 0; band-- ) { - maxLFESubFrameEner = hMasa->data.lfeToTotalEnergyRatio[i]; - } - } + float threshold; + float bandRatio; - /* Set default values for the indices */ - for ( i = 0; i < 3; i++ ) - { - lfeToTotalEnergyRatioIndices[i] = 0; - } + threshold = totalEnergySum / ( MAX_PARAM_SPATIAL_SUBFRAMES * LOWBITRATE_NUM_BANDS ) * 0.5f; /* Average energy multiplied with energy ratio of 0.5f */ + bandRatio = hqmetadata->q_direction[0].band_data[band].energy_ratio[0]; - /* Check if there is enough energy in any subframe. If not, send only 1 bit (0) and abort. */ - /* If there is enough LFE energy at least in one subframe, quantize it. */ - if ( maxLFESubFrameEner > 0.005f ) - { - /* Convert energy to log2 domain, and clamp it to reasonable values */ - log2LFEaverage = 0.0f; - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - log2LFEratio[i] = log2f( max( 0.001f, hMasa->data.lfeToTotalEnergyRatio[i] ) ); - if ( log2LFEratio[i] > 1.0f ) /* Corresponds to linear value 2.0f */ + bandEnergy = 0.0f; + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - log2LFEratio[i] = 1.0f; + bandEnergy += energy[sf][band]; } - else if ( log2LFEratio[i] < -9.0f ) + + if ( bandEnergy / MAX_PARAM_SPATIAL_SUBFRAMES * bandRatio > threshold ) { - log2LFEratio[i] = -9.0f; + selectedBand = band; + break; } - log2LFEaverage += 0.25f * log2LFEratio[i]; } - if ( ivas_total_brate == IVAS_13k2 ) + /* Determine if to merge over frequency instead of time */ + meanRatio = 0.0f; + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - /* Calculate adaptive 1-bit LFE quantizer index */ - linearLFEaverage = exp2f( log2LFEaverage ); /* Convert back to linear domain */ - if ( ( linearLFEaverage > MCMASA_LFE_1BIT_THRES ) && ( linearLFEaverage > ( 0.5f * ( MCMASA_LFE_BETA + hMasa->data.prevq_lfeToTotalEnergyRatio ) + 0.5f * ( MCMASA_LFE_ALPHA * hMasa->data.prevq_lfeToTotalEnergyRatio ) ) ) ) - { - lfeToTotalEnergyRatioIndices[0] = 1; - if ( hMasa->data.prevq_lfeIndex == 1 ) - { - hMasa->data.prevq_lfeToTotalEnergyRatio = hMasa->data.prevq_lfeToTotalEnergyRatio + MCMASA_LFE_THETA * MCMASA_LFE_BETA; /* larger "bump-up" to LFE-to-total energy ratio */ - } - else - { - hMasa->data.prevq_lfeToTotalEnergyRatio = hMasa->data.prevq_lfeToTotalEnergyRatio + MCMASA_LFE_BETA; /* default "bump-up" to LFE-to-total energy ratio */ - } - } - else + for ( band = 0; band < numCodingBands; band++ ) { - hMasa->data.prevq_lfeToTotalEnergyRatio = MCMASA_LFE_ALPHA * hMasa->data.prevq_lfeToTotalEnergyRatio; /* exponential decay */ + meanRatio += hqmetadata->q_direction[0].band_data[band].energy_ratio[sf] * energy[sf][band]; } + } + meanRatio /= ( totalEnergySum + EPSILON ); - if ( hMasa->data.prevq_lfeToTotalEnergyRatio > 1.0f ) - { - hMasa->data.prevq_lfeToTotalEnergyRatio = 1.0f; - } - hMasa->data.prevq_lfeIndex = lfeToTotalEnergyRatioIndices[0]; /* Update to previous frame's index memories */ + /* If the ratio of the selected band is larger than the average ratio of all bands and if there is an onset, merge over frequency bands. + * Otherwise, merge over subframes. */ + if ( hqmetadata->q_direction[0].band_data[selectedBand].energy_ratio[0] > meanRatio ) + { + mergeOverFreqBands = 1; } - else /* Bitrate >= 16.4 kbps */ + else { - /* Do 1st stage scalar quantization */ - lfeToTotalEnergyRatioIndices[0] = 1; - lfeToTotalEnergyRatioIndices[1] = usquant( log2LFEaverage, &xq, MCMASA_LFE_QLOW, MCMASA_LFE_DELTA, 8 ); - - if ( ivas_total_brate >= IVAS_24k4 ) /* Vector quantization is applied if bitrate >= 24.4 kbps */ - { - /* Remove scalar value from the vector*/ - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - log2LFEratio[i] -= xq; - } - - /* Vector quantize residual with energy adaptive bit allocation */ - switch ( lfeToTotalEnergyRatioIndices[1] ) - { - case 0: - case 1: - VQLevels = 0; - lfeAdaptiveVQBits = 0; - break; - case 2: - VQLevels = 2; - lfeAdaptiveVQBits = 1; - break; - case 3: - VQLevels = 4; - lfeAdaptiveVQBits = 2; - break; - case 4: - VQLevels = 8; - lfeAdaptiveVQBits = 3; - break; - default: - VQLevels = 16; - lfeAdaptiveVQBits = 4; - } - - if ( VQLevels > 0 ) - { - lfeToTotalEnergyRatioIndices[2] = vquant( log2LFEratio, 0, xqv, McMASA_LFEGain_vectors, 4, VQLevels ); - } - } + mergeOverFreqBands = 0; } } + else + { + mergeOverFreqBands = 0; + } - /* Write first LFE bit */ - lfeBitsWritten = 0; - push_next_indice( hMetaData, lfeToTotalEnergyRatioIndices[0], 1 ); - lfeBitsWritten += 1; - - if ( lfeToTotalEnergyRatioIndices[0] == 1 && ivas_total_brate >= IVAS_16k4 ) + /* Merge values over subframes or frequency bands, depending on which one is less important */ + if ( !mergeOverFreqBands ) /* Merge values over subframes */ { - /* If bitrate >= 16.4kbit/s, send 1-bit on/off + 3-bit scalar */ - push_next_indice( hMetaData, lfeToTotalEnergyRatioIndices[1], 3 ); - lfeBitsWritten += 3; + float xSum, ySum, zSum; + float bandSumEnergy; + float aziRad, eleRad; + float x, y, z; + float veclen; - /* If bitrate >= 24.4kbit/s, use adaptive 1 + (3.. 7) bit quantizer */ - if ( ivas_total_brate >= IVAS_24k4 ) + for ( band = 0; band < numCodingBands; band++ ) { - /* Vector quantize residual with energy adaptive bit allocation */ - if ( lfeAdaptiveVQBits > 0 ) + xSum = 0.0f; + ySum = 0.0f; + zSum = 0.0f; + bandSumEnergy = 0.0f; + + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - push_next_indice( hMetaData, lfeToTotalEnergyRatioIndices[2], lfeAdaptiveVQBits ); - lfeBitsWritten += lfeAdaptiveVQBits; + aziRad = hqmetadata->q_direction[0].band_data[band].azimuth[sf] / 180.0f * EVS_PI; + eleRad = hqmetadata->q_direction[0].band_data[band].elevation[sf] / 180.0f * EVS_PI; + veclen = hqmetadata->q_direction[0].band_data[band].energy_ratio[sf] * energy[sf][band]; + + x = cosf( aziRad ) * cosf( eleRad ) * veclen; + y = sinf( aziRad ) * cosf( eleRad ) * veclen; + z = sinf( eleRad ) * veclen; + + xSum += x; + ySum += y; + zSum += z; + + bandSumEnergy += energy[sf][band]; } - } - } - return lfeBitsWritten; -} -#endif + aziRad = atan2f( ySum, xSum ); + eleRad = atan2f( zSum, sqrtf( xSum * xSum + ySum * ySum ) ); + hqmetadata->q_direction[0].band_data[band].azimuth[0] = aziRad / EVS_PI * 180.0f; + hqmetadata->q_direction[0].band_data[band].elevation[0] = eleRad / EVS_PI * 180.0f; -/*-------------------------------------------------------------------* - * ivas_masa_enc_reconfigure() - * - * Reconfigure IVAS MASA encoder - *-------------------------------------------------------------------*/ + /* Energy ratio is already merged through time */ -void ivas_masa_enc_reconfigure( - Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ -) -{ - int16_t n, tmp; - int16_t sce_id, cpe_id; - int32_t ivas_total_brate; - int32_t ism_total_brate; + if ( computeCoherence && hqmetadata->q_direction[0].coherence_band_data != NULL ) + { + float spreadCoh; + float spreadCohSum = 0.0f; + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + spreadCoh = (float) hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf] / 255.0f; + spreadCohSum += spreadCoh * energy[sf][band]; + } + hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[0] = (uint8_t) roundf( spreadCohSum / ( bandSumEnergy + EPSILON ) * 255.0f ); - ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + /* Copy spread coherence to the rest of subframes for the coherence coding algorithm. */ + for ( sf = 1; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + for ( band = 0; band < numCodingBands; band++ ) + { + hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[0]; + } + } - ism_total_brate = 0; - if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) - { - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) - { - ism_total_brate += st_ivas->hSCE[sce_id]->element_brate; + /* Surround coherence is already merged through time */ + } } - } - if ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) + hqmetadata->q_direction->cfg.nblocks = 1; + hMasa->config.joinedSubframes = 1; + } + else /* Merge values over frequency bands */ { - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) - { - copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); - st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } - - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + /* Use the selected frequency band to represent all data */ + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; - - /* prepare bitstream buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) + hqmetadata->q_direction[0].band_data[0].azimuth[sf] = hqmetadata->q_direction[0].band_data[selectedBand].azimuth[sf]; + hqmetadata->q_direction[0].band_data[0].elevation[sf] = hqmetadata->q_direction[0].band_data[selectedBand].elevation[sf]; + hqmetadata->q_direction[0].band_data[0].energy_ratio[sf] = hqmetadata->q_direction[0].band_data[selectedBand].energy_ratio[sf]; + if ( hqmetadata->q_direction[0].coherence_band_data != NULL ) { - copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + hqmetadata->q_direction[0].coherence_band_data[0].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[selectedBand].spread_coherence[sf]; + } + if ( hqmetadata->surcoh_band_data != NULL ) + { + hqmetadata->surcoh_band_data[0].surround_coherence[sf] = hqmetadata->surcoh_band_data[selectedBand].surround_coherence[sf]; } + } - if ( ivas_total_brate - ism_total_brate < MIN_BRATE_MDCT_STEREO ) + /* Copy coherence to rest of bands for the coherence coding algorithm. */ + for ( band = 1; band < numCodingBands; band++ ) + { + if ( hqmetadata->q_direction[0].coherence_band_data != NULL ) { - st_ivas->hCPE[cpe_id]->element_mode = IVAS_CPE_DFT; + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[0].spread_coherence[sf]; + } } - else + if ( hqmetadata->q_direction[0].coherence_band_data != NULL ) { - st_ivas->hCPE[cpe_id]->element_mode = IVAS_CPE_MDCT; + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + hqmetadata->surcoh_band_data[band].surround_coherence[sf] = hqmetadata->surcoh_band_data[0].surround_coherence[sf]; + } } } -#ifndef IVAS_FLOAT_FIXED - ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp, st_ivas->hEncoderConfig->ivas_format, st_ivas->ism_mode, ism_total_brate ); -#else - ivas_masa_set_elements_fx( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp, st_ivas->hEncoderConfig->ivas_format, st_ivas->ism_mode, ism_total_brate ); -#endif + hqmetadata->q_direction[0].cfg.nbands = 1; } return; } - - -/*-------------------------------------------------------------------* - * average_masa_metadata() - * - * Average MASA metadata frame subframe contents: applies aggregation over time - *-------------------------------------------------------------------*/ - -static void average_masa_metadata( - MASA_METADATA_FRAME *hMeta, - float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], - const SPHERICAL_GRID_DATA *Sph_Grid16, - const uint8_t useSphGrid ) +#else +/* If the bit budget is very low, reduce metadata further to either 1 subframe and 5 bands, or 1 band and 4 subframes, based on which works better */ +static void reduce_metadata_further_fx( + MASA_ENCODER_HANDLE hMasa, + IVAS_QMETADATA_HANDLE hqmetadata, + const IVAS_FORMAT ivas_format ) { - int16_t i, j, k; - float azi_rad, ele_rad; - uint8_t numDirections; + Word16 sf; + Word16 band; + Word16 selectedBand; + Word32 energy[MAX_PARAM_SPATIAL_SUBFRAMES][LOWBITRATE_NUM_BANDS]; + Word64 W_tmp; + Word32 totalEnergySum; + UWord8 numCodingBands; + UWord8 computeCoherence; + Word32 onset_filter; + Word16 onset_filter_e, exp; + Word32 bandEnergy; + UWord8 mergeOverFreqBands; + Word32 meanRatio; + Word16 tmp, tmp2; - /* use the nominal values without data-adaptivity */ - numDirections = hMeta->descriptive_meta.numberOfDirections + 1; + numCodingBands = hMasa->config.numCodingBands; + test(); + computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; + move16(); + move16(); - /* azi/ele/nrg into vectors for each sub-frame and band */ - for ( i = 0; i < numDirections; i++ ) + /* Set default values */ + selectedBand = 0; + mergeOverFreqBands = 0; + move16(); + move16(); + + /* Get energy for the input data in 4-subframe, 5-band format */ + W_tmp = 0; + move64(); + test(); + IF( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) ) /* Energy data is in 4-subframe, 24-band format */ { - for ( k = 0; k < MASA_FREQUENCY_BANDS; k++ ) + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - float x_sum, y_sum, z_sum, energy_sum, vec_len, spread_coh_sum, surr_coh_sum; + Word16 brange[2]; + Word32 eneSum; + Word16 m; - x_sum = 0.0f; - y_sum = 0.0f; - z_sum = 0.0f; - energy_sum = 0.0f; - spread_coh_sum = 0.0f; - surr_coh_sum = 0.0f; - for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) - { - azi_rad = hMeta->directional_meta[i].azimuth[j][k] / 180.0f * EVS_PI; - ele_rad = hMeta->directional_meta[i].elevation[j][k] / 180.0f * EVS_PI; - vec_len = hMeta->directional_meta[i].energy_ratio[j][k] * energy[j][k]; - - /* energy-weighted sum over subframes */ - x_sum += cosf( azi_rad ) * cosf( ele_rad ) * vec_len; - y_sum += sinf( azi_rad ) * cosf( ele_rad ) * vec_len; - z_sum += sinf( ele_rad ) * vec_len; - - energy_sum += energy[j][k]; - - spread_coh_sum += hMeta->directional_meta[i].spread_coherence[j][k] * energy[j][k]; - if ( i == 0 ) - { - /* this is in common metadata and not in each direction */ - surr_coh_sum += hMeta->common_meta.surround_coherence[j][k] * energy[j][k]; - } - } - - /* the data from the combined sub-frames is written into the first sub-frame band */ - j = 0; - hMeta->directional_meta[i].azimuth[j][k] = atan2f( y_sum, x_sum ) / EVS_PI * 180.0f; - hMeta->directional_meta[i].elevation[j][k] = atan2f( z_sum, sqrtf( x_sum * x_sum + y_sum * y_sum ) ) / EVS_PI * 180.0f; - if ( useSphGrid == TRUE ) - { -#ifndef IVAS_FLOAT_FIXED - hMeta->directional_meta[i].spherical_index[j][k] = index_theta_phi_16( &( hMeta->directional_meta[i].elevation[j][k] ), - &( hMeta->directional_meta[i].azimuth[j][k] ), Sph_Grid16 ); -#else - hMeta->directional_meta[i].elevation_fx[j][k] = floatToFixed( hMeta->directional_meta[i].elevation[j][k], Q22 ); - hMeta->directional_meta[i].azimuth_fx[j][k] = floatToFixed( hMeta->directional_meta[i].azimuth[j][k], Q22 ); - - hMeta->directional_meta[i].spherical_index[j][k] = index_theta_phi_16_fx( &( hMeta->directional_meta[i].elevation_fx[j][k] ), - &( hMeta->directional_meta[i].azimuth_fx[j][k] ), Sph_Grid16 ); - - hMeta->directional_meta[i].elevation[j][k] = fixedToFloat( hMeta->directional_meta[i].elevation_fx[j][k], Q22 ); - hMeta->directional_meta[i].azimuth[j][k] = fixedToFloat( hMeta->directional_meta[i].azimuth_fx[j][k], Q22 ); -#endif - } - vec_len = sqrtf( x_sum * x_sum + y_sum * y_sum + z_sum * z_sum ); - hMeta->directional_meta[i].energy_ratio[j][k] = vec_len / ( energy_sum + EPSILON ); - - hMeta->directional_meta[i].spread_coherence[j][k] = spread_coh_sum / ( energy_sum + EPSILON ); - if ( i == 0 ) + FOR( band = 0; band < numCodingBands; band++ ) { - hMeta->common_meta.surround_coherence[j][k] = surr_coh_sum / ( energy_sum + EPSILON ); - } + brange[0] = hMasa->data.band_mapping[band]; + brange[1] = hMasa->data.band_mapping[band + 1]; + move16(); + move16(); - /* copy the same value to all subframes */ - for ( j = 1; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) - { - hMeta->directional_meta[i].azimuth[j][k] = hMeta->directional_meta[i].azimuth[0][k]; - hMeta->directional_meta[i].elevation[j][k] = hMeta->directional_meta[i].elevation[0][k]; - hMeta->directional_meta[i].energy_ratio[j][k] = hMeta->directional_meta[i].energy_ratio[0][k]; - hMeta->directional_meta[i].spread_coherence[j][k] = hMeta->directional_meta[i].spread_coherence[0][k]; - if ( i == 0 ) + eneSum = 0; + move32(); + FOR( m = brange[0]; m < brange[1]; m++ ) { - hMeta->common_meta.surround_coherence[j][k] = hMeta->common_meta.surround_coherence[0][k]; + eneSum = L_add( eneSum, hMasa->data.energy_fx[sf][m] ); // hMasa->data.q_energy } + energy[sf][band] = eneSum; // hMasa->data.q_energy + move32(); + W_tmp = W_add( W_tmp, eneSum ); // hMasa->data.q_energy } } } - - for ( k = 0; k < MASA_FREQUENCY_BANDS; k++ ) + ELSE /* Energy data is already in 4-subframe, 5-band format */ { - for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - if ( numDirections == 2 ) - { - hMeta->common_meta.diffuse_to_total_ratio[j][k] = max( 0.0f, 1.0f - hMeta->directional_meta[1].energy_ratio[j][k] - hMeta->directional_meta[0].energy_ratio[j][k] ); - } - else + FOR( band = 0; band < numCodingBands; band++ ) { - hMeta->common_meta.diffuse_to_total_ratio[j][k] = max( 0.0f, 1.0f - hMeta->directional_meta[0].energy_ratio[j][k] ); + energy[sf][band] = hMasa->data.energy_fx[sf][band]; // hMasa->data.q_energy + move32(); + W_tmp = W_add( W_tmp, energy[sf][band] ); // hMasa->data.q_energy } - hMeta->common_meta.remainder_to_total_ratio[j][k] = 0.0f; } } - return; -} - - -/*-------------------------------------------------------------------* - * copy_masa_metadata_subframe() - * - * Copy MASA metadata frame subframe contents - *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -static void copy_masa_metadata_subframe_fx( - const MASA_METADATA_HANDLE hMetaFrom, /* i : MASA frame metdata to be copied */ - const UWord8 sfFrom, /* i : subframe index of the copy source */ - MASA_METADATA_HANDLE hMetaTo, /* o : MASA frame metadata copy destination */ - const UWord8 sfTo /* i : subframe index of the copy target */ -) -{ - UWord8 dir; - - /* directional metadata */ - FOR( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ ) - { - Copy32( hMetaFrom->directional_meta[dir].azimuth_fx[sfFrom], hMetaTo->directional_meta[dir].azimuth_fx[sfTo], MASA_FREQUENCY_BANDS ); - Copy32( hMetaFrom->directional_meta[dir].elevation_fx[sfFrom], hMetaTo->directional_meta[dir].elevation_fx[sfTo], MASA_FREQUENCY_BANDS ); - Copy32( hMetaFrom->directional_meta[dir].energy_ratio_fx[sfFrom], hMetaTo->directional_meta[dir].energy_ratio_fx[sfTo], MASA_FREQUENCY_BANDS ); - Copy( hMetaFrom->directional_meta[dir].spread_coherence_fx[sfFrom], hMetaTo->directional_meta[dir].spread_coherence_fx[sfTo], MASA_FREQUENCY_BANDS ); - } - - /* common metadata */ - Copy32( hMetaFrom->common_meta.diffuse_to_total_ratio_fx[sfFrom], hMetaTo->common_meta.diffuse_to_total_ratio_fx[sfTo], MASA_FREQUENCY_BANDS ); - Copy( hMetaFrom->common_meta.surround_coherence_fx[sfFrom], hMetaTo->common_meta.surround_coherence_fx[sfTo], MASA_FREQUENCY_BANDS ); - Copy32( hMetaFrom->common_meta.remainder_to_total_ratio_fx[sfFrom], hMetaTo->common_meta.remainder_to_total_ratio_fx[sfTo], MASA_FREQUENCY_BANDS ); + tmp2 = W_norm( W_tmp ); + tmp2 = s_min( 32, tmp2 ); + totalEnergySum = W_extract_h( W_shl( W_tmp, tmp2 ) ); + tmp2 = sub( tmp2, 32 ); - return; -} -#else -static void copy_masa_metadata_subframe( - const MASA_METADATA_HANDLE hMetaFrom, /* i : MASA frame metdata to be copied */ - const uint8_t sfFrom, /* i : subframe index of the copy source */ - MASA_METADATA_HANDLE hMetaTo, /* o : MASA frame metadata copy destination */ - const uint8_t sfTo /* i : subframe index of the copy target */ -) -{ - uint8_t dir; + /* Determine onsets */ + hMasa->data.onset_detector_1_fx = Mpy_32_32( hMasa->data.onset_detector_1_fx, LOWBITRATE_ONSET_ALPHA_Q31 ); + move32(); - /* directional metadata */ - for ( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ ) + tmp = hMasa->data.q_onset_detector; + move16(); + IF( BASOP_Util_Cmp_Mant32Exp( hMasa->data.onset_detector_1_fx, sub( 31, hMasa->data.q_onset_detector ), totalEnergySum, sub( 31, hMasa->data.q_energy ) ) < 0 ) { - mvr2r( hMetaFrom->directional_meta[dir].azimuth[sfFrom], hMetaTo->directional_meta[dir].azimuth[sfTo], MASA_FREQUENCY_BANDS ); - mvr2r( hMetaFrom->directional_meta[dir].elevation[sfFrom], hMetaTo->directional_meta[dir].elevation[sfTo], MASA_FREQUENCY_BANDS ); - mvr2r( hMetaFrom->directional_meta[dir].energy_ratio[sfFrom], hMetaTo->directional_meta[dir].energy_ratio[sfTo], MASA_FREQUENCY_BANDS ); - mvr2r( hMetaFrom->directional_meta[dir].spread_coherence[sfFrom], hMetaTo->directional_meta[dir].spread_coherence[sfTo], MASA_FREQUENCY_BANDS ); + hMasa->data.onset_detector_1_fx = totalEnergySum; // hMasa->data.q_energy + hMasa->data.q_onset_detector = add( hMasa->data.q_energy, tmp2 ); + move32(); + move16(); } - - /* common metadata */ - mvr2r( hMetaFrom->common_meta.diffuse_to_total_ratio[sfFrom], hMetaTo->common_meta.diffuse_to_total_ratio[sfTo], MASA_FREQUENCY_BANDS ); - mvr2r( hMetaFrom->common_meta.surround_coherence[sfFrom], hMetaTo->common_meta.surround_coherence[sfTo], MASA_FREQUENCY_BANDS ); - mvr2r( hMetaFrom->common_meta.remainder_to_total_ratio[sfFrom], hMetaTo->common_meta.remainder_to_total_ratio[sfTo], MASA_FREQUENCY_BANDS ); - - return; -} -#endif // IVAS_FLOAT_FIXED - -/*-------------------------------------------------------------------* - * copy_masa_metadata() - * - * Copy MASA metada frame contents - *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -static void copy_masa_metadata_fx( - const MASA_METADATA_HANDLE hMetaFrom, /* i : MASA frame metadata to be copied */ - MASA_METADATA_HANDLE hMetaTo /* o : MASA frame metadata copy destination */ -) -{ - UWord8 sf, byte_idx; - - /* descriptive metadata */ - FOR( byte_idx = 0; byte_idx < 8; byte_idx++ ) + IF( LT_16( tmp, hMasa->data.q_onset_detector ) ) { - hMetaTo->descriptive_meta.formatDescriptor[byte_idx] = hMetaFrom->descriptive_meta.formatDescriptor[byte_idx]; + hMasa->data.onset_detector_1_fx = L_shr( hMasa->data.onset_detector_1_fx, sub( hMasa->data.q_onset_detector, tmp ) ); // tmp + hMasa->data.onset_detector_2_fx = L_add( Mpy_32_32( LOWBITRATE_ONSET_BETA_Q31, hMasa->data.onset_detector_2_fx ), Mpy_32_32( ( ONE_IN_Q31 - LOWBITRATE_ONSET_BETA_Q31 ), hMasa->data.onset_detector_1_fx ) ); // tmp + hMasa->data.q_onset_detector = tmp; + move32(); + move32(); move16(); } - - hMetaTo->descriptive_meta.numberOfDirections = hMetaFrom->descriptive_meta.numberOfDirections; - hMetaTo->descriptive_meta.numberOfChannels = hMetaFrom->descriptive_meta.numberOfChannels; - hMetaTo->descriptive_meta.sourceFormat = hMetaFrom->descriptive_meta.sourceFormat; - hMetaTo->descriptive_meta.transportDefinition = hMetaFrom->descriptive_meta.transportDefinition; - hMetaTo->descriptive_meta.channelAngle = hMetaFrom->descriptive_meta.channelAngle; - hMetaTo->descriptive_meta.channelDistance = hMetaFrom->descriptive_meta.channelDistance; - hMetaTo->descriptive_meta.channelLayout = hMetaFrom->descriptive_meta.channelLayout; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - - /* directional and common metadata */ - FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + ELSE { - copy_masa_metadata_subframe_fx( hMetaFrom, sf, hMetaTo, sf ); + hMasa->data.onset_detector_2_fx = L_add( L_shr( Mpy_32_32( LOWBITRATE_ONSET_BETA_Q31, hMasa->data.onset_detector_2_fx ), sub( tmp, hMasa->data.q_onset_detector ) ), Mpy_32_32( ( ONE_IN_Q31 - LOWBITRATE_ONSET_BETA_Q31 ), hMasa->data.onset_detector_1_fx ) ); // hMasa->data.q_onset_detector + move32(); } + hMasa->data.onset_detector_2_fx = L_shl( Mpy_32_32( LOWBITRATE_ONSET_GAIN_Q30, L_min( hMasa->data.onset_detector_1_fx, hMasa->data.onset_detector_2_fx ) ), 1 ); // hMasa->data.q_onset_detector + move32(); - return; -} -#else -static void copy_masa_metadata( - const MASA_METADATA_HANDLE hMetaFrom, /* i : MASA frame metadata to be copied */ - MASA_METADATA_HANDLE hMetaTo /* o : MASA frame metadata copy destination */ -) -{ - uint8_t sf, byte_idx; - - /* descriptive metadata */ - for ( byte_idx = 0; byte_idx < 8; byte_idx++ ) + IF( hMasa->data.onset_detector_1_fx != 0 ) { - hMetaTo->descriptive_meta.formatDescriptor[byte_idx] = hMetaFrom->descriptive_meta.formatDescriptor[byte_idx]; - } - - hMetaTo->descriptive_meta.numberOfDirections = hMetaFrom->descriptive_meta.numberOfDirections; - hMetaTo->descriptive_meta.numberOfChannels = hMetaFrom->descriptive_meta.numberOfChannels; - hMetaTo->descriptive_meta.sourceFormat = hMetaFrom->descriptive_meta.sourceFormat; - hMetaTo->descriptive_meta.transportDefinition = hMetaFrom->descriptive_meta.transportDefinition; - hMetaTo->descriptive_meta.channelAngle = hMetaFrom->descriptive_meta.channelAngle; - hMetaTo->descriptive_meta.channelDistance = hMetaFrom->descriptive_meta.channelDistance; - hMetaTo->descriptive_meta.channelLayout = hMetaFrom->descriptive_meta.channelLayout; + onset_filter = L_max( BASOP_Util_Divide3232_Scale_cadence( hMasa->data.onset_detector_2_fx, hMasa->data.onset_detector_1_fx, &onset_filter_e ), 0 ); - /* directional and common metadata */ - for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + IF( BASOP_Util_Cmp_Mant32Exp( onset_filter, onset_filter_e, ONE_IN_Q31, 0 ) > 0 ) + { + onset_filter = ONE_IN_Q31; + onset_filter_e = 0; + move32(); + move16(); + } + } + ELSE { - copy_masa_metadata_subframe( hMetaFrom, sf, hMetaTo, sf ); + onset_filter = ONE_IN_Q31; + onset_filter_e = 0; + move32(); + move16(); } + /* If we have onset, continue checking if we should reduce in frequency instead of time. */ + IF( BASOP_Util_Cmp_Mant32Exp( onset_filter, onset_filter_e, 2126008812 /* 0.99f in Q31 */, 0 ) < 0 ) + { + /* Determine one frequency band to use to represent all frequency bands */ + FOR( band = numCodingBands - 1; band >= 0; band-- ) + { + Word32 threshold; + Word32 bandRatio; - return; -} -#endif + // threshold = totalEnergySum / ( MAX_PARAM_SPATIAL_SUBFRAMES * LOWBITRATE_NUM_BANDS ) * 0.5f; /* Average energy multiplied with energy ratio of 0.5f */ + threshold = BASOP_Util_Divide3232_Scale_cadence( totalEnergySum, ( MAX_PARAM_SPATIAL_SUBFRAMES * LOWBITRATE_NUM_BANDS ) * 2, &exp ); /* Average energy multiplied with energy ratio of 0.5f */ + exp = add( exp, sub( sub( 31, add( hMasa->data.q_energy, tmp2 ) ), 31 ) ); + bandRatio = hqmetadata->q_direction[0].band_data[band].energy_ratio_fx[0]; // Q30 + move32(); -/*-------------------------------------------------------------------* - * are_masa_subframes_similar() - * - * Compare the similarity of MASA metadata in two sub-frames - *-------------------------------------------------------------------*/ - -/* r: similarity decision */ -#ifdef IVAS_FLOAT_FIXED -static UWord8 are_masa_subframes_similar_fx( - const MASA_METADATA_HANDLE frame1, /* i : MASA metadata frame 1 */ - const UWord8 sf1_idx, /* i : index of the subframe of frame1 to inspect */ - const MASA_METADATA_HANDLE frame2, /* i : MASA metadata frame 2 */ - const UWord8 sf2_idx /* i : index of the subframe of frame2 to inspect */ -) -{ - UWord8 num_dir; - UWord8 dir; - UWord8 band_idx; - UWord8 sf_differ; - - num_dir = frame1->descriptive_meta.numberOfDirections; - dir = 0; - band_idx = 0; - sf_differ = FALSE; - move16(); - move16(); - move16(); - move16(); - - IF( NE_16( num_dir, frame2->descriptive_meta.numberOfDirections ) ) - { - sf_differ = TRUE; - move16(); - } - ELSE - { - /* check per-direction metadata */ - dir = 0; - band_idx = 0; - move16(); - move16(); - - WHILE( EQ_16( sf_differ, FALSE ) && LE_16( dir, num_dir ) ) - { - test(); - band_idx = 0; - move16(); - WHILE( EQ_16( sf_differ, FALSE ) && LT_16( band_idx, MASA_FREQUENCY_BANDS ) ) + bandEnergy = 0; + move32(); + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - test(); - Word32 azi_dif_fx; - azi_dif_fx = L_abs( L_sub( frame1->directional_meta[dir].azimuth_fx[sf1_idx][band_idx], frame2->directional_meta[dir].azimuth_fx[sf2_idx][band_idx] ) ); - IF( GT_32( azi_dif_fx, 180 << Q22 ) ) - azi_dif_fx = L_sub( 360 << Q22, azi_dif_fx ); - - IF( GT_32( azi_dif_fx, ONE_IN_Q21 /*0.5 in Q22*/ ) ) - { - sf_differ = TRUE; - move16(); - BREAK; - } - - IF( GT_32( L_abs( L_sub( frame1->directional_meta[dir].elevation_fx[sf1_idx][band_idx], frame2->directional_meta[dir].elevation_fx[sf2_idx][band_idx] ) ), MASA_ANGLE_TOLERANCE_FX ) ) - { - sf_differ = TRUE; - move16(); - BREAK; - } - - IF( GT_32( L_abs( L_sub( frame1->directional_meta[dir].energy_ratio_fx[sf1_idx][band_idx], frame2->directional_meta[dir].energy_ratio_fx[sf2_idx][band_idx] ) ), MASA_RATIO_TOLERANCE_FX ) ) - { - sf_differ = TRUE; - move16(); - BREAK; - } - - IF( GT_32( L_abs( L_sub( frame1->directional_meta[dir].spread_coherence_fx[sf1_idx][band_idx], frame2->directional_meta[dir].spread_coherence_fx[sf2_idx][band_idx] ) ), MASA_COHERENCE_TOLERANCE_FX ) ) - { - sf_differ = TRUE; - move16(); - BREAK; - } + bandEnergy = L_add( bandEnergy, energy[sf][band] ); + } - band_idx = (UWord8) add( band_idx, 1 ); + IF( BASOP_Util_Cmp_Mant32Exp( Mpy_32_32( L_shr( bandEnergy, 2 ), bandRatio ), sub( 31 + 1, hMasa->data.q_energy ), threshold, exp ) > 0 ) + { + selectedBand = band; move16(); + BREAK; } - dir = (UWord8) add( dir, 1 ); - move16(); } - /* check the common metadata */ - WHILE( EQ_16( sf_differ, FALSE ) && LT_16( band_idx, MASA_FREQUENCY_BANDS ) ) + /* Determine if to merge over frequency instead of time */ + meanRatio = 0; + move32(); + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - test(); - IF( GT_32( L_abs( L_sub( frame1->common_meta.surround_coherence_fx[sf1_idx][band_idx], frame2->common_meta.surround_coherence_fx[sf2_idx][band_idx] ) ), MASA_COHERENCE_TOLERANCE_FX ) ) + FOR( band = 0; band < numCodingBands; band++ ) { - sf_differ = TRUE; - move16(); - BREAK; + meanRatio = L_add( meanRatio, Mpy_32_32( hqmetadata->q_direction[0].band_data[band].energy_ratio_fx[sf], energy[sf][band] ) ); // hMasa->data.q_energy - 1 } - - band_idx = (UWord8) add( band_idx, 1 ); + } + IF( totalEnergySum != 0 ) + { + meanRatio = BASOP_Util_Divide3232_Scale_cadence( meanRatio, totalEnergySum, &exp ); + exp = add( add( exp, 1 ), tmp2 ); // 31 - (hMasa->data.q_energy - 1) - 31 - hMasa->data.q_energy - tmp2 => 1 + tmp2 + } + ELSE + { + meanRatio = MAX_32; + exp = 31; + move32(); move16(); } - } - IF( sf_differ ) - { - return FALSE; + /* If the ratio of the selected band is larger than the average ratio of all bands and if there is an onset, merge over frequency bands. + * Otherwise, merge over subframes. */ + IF( BASOP_Util_Cmp_Mant32Exp( hqmetadata->q_direction[0].band_data[selectedBand].energy_ratio_fx[0], 1, meanRatio, exp ) > 0 ) + { + mergeOverFreqBands = 1; + move16(); + } + ELSE + { + mergeOverFreqBands = 0; + move16(); + } } ELSE { - return TRUE; + mergeOverFreqBands = 0; + move16(); } -} -#endif -static uint8_t are_masa_subframes_similar( - const MASA_METADATA_HANDLE frame1, /* i : MASA metadata frame 1 */ - const uint8_t sf1_idx, /* i : index of the subframe of frame1 to inspect */ - const MASA_METADATA_HANDLE frame2, /* i : MASA metadata frame 2 */ - const uint8_t sf2_idx /* i : index of the subframe of frame2 to inspect */ -) -{ - uint8_t num_dir; - uint8_t dir; - uint8_t band_idx; - uint8_t sf_differ; - - num_dir = frame1->descriptive_meta.numberOfDirections; - dir = 0; - band_idx = 0; - sf_differ = FALSE; - if ( num_dir != frame2->descriptive_meta.numberOfDirections ) - { - sf_differ = TRUE; - } - else + /* Merge values over subframes or frequency bands, depending on which one is less important */ + IF( !mergeOverFreqBands ) /* Merge values over subframes */ { - /* check per-direction metadata */ - dir = 0; - band_idx = 0; + Word32 xSum, ySum, zSum; + Word64 W_xSum_sq, W_ySum_sq; + Word32 bandSumEnergy; + Word16 aziRad, eleRad, q_shift, exp_diff; + Word32 x, y, z; + Word32 veclen, L_tmp; - while ( ( sf_differ == FALSE ) && ( dir <= num_dir ) ) + FOR( band = 0; band < numCodingBands; band++ ) { - band_idx = 0; - while ( ( sf_differ == FALSE ) && ( band_idx < MASA_FREQUENCY_BANDS ) ) + xSum = 0; + ySum = 0; + zSum = 0; + bandSumEnergy = 0; + move32(); + move32(); + move32(); + move32(); + + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - float azi_dif; - azi_dif = fabsf( frame1->directional_meta[dir].azimuth[sf1_idx][band_idx] - frame2->directional_meta[dir].azimuth[sf2_idx][band_idx] ); - azi_dif = azi_dif > 180.0f ? 360.0f - azi_dif : azi_dif; + aziRad = extract_l( Mpy_32_32( hqmetadata->q_direction[0].band_data[band].azimuth_fx[sf], PI_OVER_180_Q22 ) ); + eleRad = extract_l( Mpy_32_32( hqmetadata->q_direction[0].band_data[band].elevation_fx[sf], PI_OVER_180_Q22 ) ); + veclen = Mpy_32_32( hqmetadata->q_direction[0].band_data[band].energy_ratio_fx[sf], energy[sf][band] ); // hMasa->data.q_energy - 1 - if ( azi_dif > MASA_ANGLE_TOLERANCE ) - { - sf_differ = TRUE; - break; - } + x = Mpy_32_32( L_mult( getCosWord16( aziRad ), getCosWord16( eleRad ) ), veclen ); // (Q29, hMasa->data.q_energy - Q1) -> hMasa->data.q_energy - Q3 + move32(); + y = Mpy_32_32( L_mult0( getSinWord16( aziRad ), getCosWord16( eleRad ) ), veclen ); // (Q29, hMasa->data.q_energy - Q1) -> hMasa->data.q_energy - Q3 + move32(); + z = Mpy_32_32( L_mult0( getSinWord16( eleRad ), ONE_IN_Q14 ), veclen ); // (Q29, hMasa->data.q_energy - Q1) -> hMasa->data.q_energy - Q3 + move32(); - if ( fabsf( frame1->directional_meta[dir].elevation[sf1_idx][band_idx] - frame2->directional_meta[dir].elevation[sf2_idx][band_idx] ) > MASA_ANGLE_TOLERANCE ) - { - sf_differ = TRUE; - break; - } + xSum = L_add( xSum, x ); + ySum = L_add( ySum, y ); + zSum = L_add( zSum, z ); - if ( fabsf( frame1->directional_meta[dir].energy_ratio[sf1_idx][band_idx] - frame2->directional_meta[dir].energy_ratio[sf2_idx][band_idx] ) > MASA_RATIO_TOLERANCE ) + bandSumEnergy = L_add( bandSumEnergy, energy[sf][band] ); + } + + aziRad = BASOP_util_atan2( ySum, xSum, 0 ); // Q13 + W_xSum_sq = W_mult0_32_32( xSum, xSum ); // 2 * hMasa->data.q_energy - Q6 + W_ySum_sq = W_mult0_32_32( ySum, ySum ); // 2 * hMasa->data.q_energy - Q6 + W_tmp = W_add( W_xSum_sq, W_ySum_sq ); // 2 * hMasa->data.q_energy - Q6 + q_shift = W_norm( W_tmp ); + L_tmp = W_extract_h( W_shl( W_tmp, q_shift ) ); // 2 * hMasa->data.q_energy - Q6 + (q_shift -32) + exp_diff = sub( Q31, add( sub( imult1616( 2, hMasa->data.q_energy ), Q6 ), sub( q_shift, 32 ) ) ); + L_tmp = Sqrt32( L_tmp, &exp_diff ); + eleRad = BASOP_util_atan2( zSum, L_tmp, sub( sub( 34, hMasa->data.q_energy ), exp_diff ) ); // Q13 + + hqmetadata->q_direction[0].band_data[band].azimuth_fx[0] = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, aziRad ), Q1 ); // ((Q25, Q13) -> Q23) >> Q1 -> Q22 + hqmetadata->q_direction[0].band_data[band].elevation_fx[0] = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, eleRad ), Q1 ); // ((Q25, Q13) -> Q23) >> Q1 -> Q22 + + /* Energy ratio is already merged through time */ + test(); + IF( computeCoherence && hqmetadata->q_direction[0].coherence_band_data != NULL ) + { + Word16 spreadCoh; + Word32 spreadCohSum = 0; + move32(); + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - sf_differ = TRUE; - break; + spreadCoh = div_s( (Word16) hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf], 255 ); // Q15 + spreadCohSum = L_add( spreadCohSum, Mpy_32_16_1( energy[sf][band], spreadCoh ) ); } + // hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[0] = (uint8_t) roundf( spreadCohSum / ( bandSumEnergy + EPSILON ) * 255.0f ); + tmp = BASOP_Util_Divide3232_Scale( spreadCohSum, bandSumEnergy, &exp ); + tmp = mult_r( tmp, 32640 /* 255 in Q7 */ ); // 15 - exp + 7 - 15 => 7 - exp + hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[0] = (UWord8) shr( tmp, sub( 7, exp ) ); // Q0 + move16(); - if ( fabsf( frame1->directional_meta[dir].spread_coherence[sf1_idx][band_idx] - frame2->directional_meta[dir].spread_coherence[sf2_idx][band_idx] ) > MASA_COHERENCE_TOLERANCE ) + /* Copy spread coherence to the rest of subframes for the coherence coding algorithm. */ + FOR( sf = 1; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - sf_differ = TRUE; - break; + FOR( band = 0; band < numCodingBands; band++ ) + { + hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[0]; + move16(); + } } - band_idx++; + /* Surround coherence is already merged through time */ } - dir++; } - /* check the common metadata */ - while ( ( sf_differ == FALSE ) && ( band_idx < MASA_FREQUENCY_BANDS ) ) + hqmetadata->q_direction->cfg.nblocks = 1; + hMasa->config.joinedSubframes = 1; + move16(); + move16(); + } + ELSE /* Merge values over frequency bands */ + { + /* Use the selected frequency band to represent all data */ + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - if ( fabsf( frame1->common_meta.surround_coherence[sf1_idx][band_idx] - frame2->common_meta.surround_coherence[sf2_idx][band_idx] ) > MASA_COHERENCE_TOLERANCE ) + hqmetadata->q_direction[0].band_data[0].azimuth_fx[sf] = hqmetadata->q_direction[0].band_data[selectedBand].azimuth_fx[sf]; + hqmetadata->q_direction[0].band_data[0].elevation_fx[sf] = hqmetadata->q_direction[0].band_data[selectedBand].elevation_fx[sf]; + hqmetadata->q_direction[0].band_data[0].energy_ratio_fx[sf] = hqmetadata->q_direction[0].band_data[selectedBand].energy_ratio_fx[sf]; + move32(); + move32(); + move32(); + if ( hqmetadata->q_direction[0].coherence_band_data != NULL ) { - sf_differ = TRUE; - break; + hqmetadata->q_direction[0].coherence_band_data[0].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[selectedBand].spread_coherence[sf]; + move16(); + } + if ( hqmetadata->surcoh_band_data != NULL ) + { + hqmetadata->surcoh_band_data[0].surround_coherence[sf] = hqmetadata->surcoh_band_data[selectedBand].surround_coherence[sf]; + move16(); } + } - band_idx++; + /* Copy coherence to rest of bands for the coherence coding algorithm. */ + FOR( band = 1; band < numCodingBands; band++ ) + { + IF( hqmetadata->q_direction[0].coherence_band_data != NULL ) + { + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[0].spread_coherence[sf]; + move16(); + } + } + IF( hqmetadata->q_direction[0].coherence_band_data != NULL ) + { + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + hqmetadata->surcoh_band_data[band].surround_coherence[sf] = hqmetadata->surcoh_band_data[0].surround_coherence[sf]; + move16(); + } + } } - } - if ( sf_differ ) - { - return FALSE; - } - else - { - return TRUE; + hqmetadata->q_direction[0].cfg.nbands = 1; + move16(); } + + return; } +#endif + -/*-------------------------------------------------------------------* - * detect_framing_async() - * - * Compare the similarity of MASA metadata in two sub-frames - * Analysis result is stored in hMasa->data.sync_state, and - * potentially hMasa->masaMetadata is modified - *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static void detect_framing_async_fx( - MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder structure */ +static Word16 encode_lfe_to_total_energy_ratio_fx( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ ) { - MASA_METADATA_HANDLE current_meta; - MASA_METADATA_HANDLE previous_meta; - MASA_SYNC_HANDLE sync_state; - MASA_FRAME_MODE frame_mode; - UWord8 n_sim_start, n_sim_stop, sf_idx; - UWord8 found_offset; + Word16 i; + Word16 xq; + Word16 VQLevels; + Word32 maxLFESubFrameEner; + Word16 maxLFESubFrameEner_e; + Word32 log2LFEaverage; + Word32 log2LFEratio[4]; + Word32 xqv[4]; + Word32 linearLFEaverage; + Word16 linearLFEaverage_e; + Word16 lfeToTotalEnergyRatioIndices[3]; + Word16 lfeAdaptiveVQBits; + Word16 lfeBitsWritten; + Word32 maxVal; + Word16 maxVal_e; - current_meta = &( hMasa->masaMetadata ); /* metadata from current frame */ - sync_state = &( hMasa->data.sync_state ); /* synchronization structure */ - previous_meta = &( sync_state->previous_metadata ); + VQLevels = 0; + move16(); + lfeAdaptiveVQBits = 0; + move16(); - /* check current frame, how many are similar from the start and from the end */ - n_sim_start = 1; + /* Determine maximum amount of LFE energy in any subframe */ + maxLFESubFrameEner = 0; + move32(); + maxLFESubFrameEner_e = 0; move16(); - FOR( sf_idx = n_sim_start; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - IF( EQ_16( are_masa_subframes_similar_fx( current_meta, 0, current_meta, sf_idx ), TRUE ) ) + IF( BASOP_Util_Cmp_Mant32Exp( hMasa->data.lfeToTotalEnergyRatio_fx[i], hMasa->data.lfeToTotalEnergyRatio_e[i], maxLFESubFrameEner, maxLFESubFrameEner_e ) > 0 ) { - n_sim_start = (UWord8) add( sf_idx, 1 ); + maxLFESubFrameEner = hMasa->data.lfeToTotalEnergyRatio_fx[i]; + move32(); + maxLFESubFrameEner_e = hMasa->data.lfeToTotalEnergyRatio_e[i]; move16(); } - ELSE - { - BREAK; - } } - /* number of similar sub-frames starting from the end of the frame */ - IF( EQ_16( n_sim_start, MAX_PARAM_SPATIAL_SUBFRAMES ) ) /* shortcut */ + /* Set default values for the indices */ + FOR( i = 0; i < 3; i++ ) { - n_sim_stop = n_sim_start; + lfeToTotalEnergyRatioIndices[i] = 0; move16(); } - ELSE + + /* Check if there is enough energy in any subframe. If not, send only 1 bit (0) and abort. */ + /* If there is enough LFE energy at least in one subframe, quantize it. */ + IF( BASOP_Util_Cmp_Mant32Exp( maxLFESubFrameEner, maxLFESubFrameEner_e, 10737418 /* 0.005f in Q31 */, 0 ) > 0 ) { - n_sim_stop = 1; - move16(); - FOR( sf_idx = 2; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + /* Convert energy to log2 domain, and clamp it to reasonable values */ + log2LFEaverage = 0; // Q25 + move32(); + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - /* we need to check only the two middle sub-frames, as all being the same would have taken the shortcut above */ - IF( EQ_16( are_masa_subframes_similar_fx( current_meta, MAX_PARAM_SPATIAL_SUBFRAMES - 1, current_meta, (UWord8) sub( MAX_PARAM_SPATIAL_SUBFRAMES, sf_idx ) ), TRUE ) ) + // log2LFEratio[i] = log2f( max( 0.001f, hMasa->data.lfeToTotalEnergyRatio[i] ) ); + maxVal = 2147484 /* 0.001f in Q31 */; + move32(); + maxVal_e = 0; + move16(); + IF( BASOP_Util_Cmp_Mant32Exp( hMasa->data.lfeToTotalEnergyRatio_fx[i], hMasa->data.lfeToTotalEnergyRatio_e[i], maxVal, maxVal_e ) > 0 ) { - n_sim_stop = sf_idx; + maxVal = hMasa->data.lfeToTotalEnergyRatio_fx[i]; + move32(); + maxVal_e = hMasa->data.lfeToTotalEnergyRatio_e[i]; move16(); } - ELSE + log2LFEratio[i] = L_add( BASOP_Util_Log2( maxVal ), L_shl( maxVal_e, Q25 ) ); // Q25 + move32(); + IF( GT_32( log2LFEratio[i], ONE_IN_Q25 ) ) /* Corresponds to linear value 2.0f */ { - BREAK; + log2LFEratio[i] = ONE_IN_Q25; // Q25 + move32(); + } + ELSE IF( LT_32( log2LFEratio[i], -301989888 /* -9.0f in Q25 */ ) ) + { + log2LFEratio[i] = -301989888 /* -9.0f in Q25 */; // Q25 + move32(); } + log2LFEaverage = L_add( log2LFEaverage, Mpy_32_32( 536870912 /* 0.25f in Q31 */, log2LFEratio[i] ) ); // Q25 } - } - - frame_mode = MASA_FRAME_4SF; /* default mode: 4sf */ - move16(); - IF( GT_16( sync_state->prev_offset, MAX_PARAM_SPATIAL_SUBFRAMES - 2 ) ) - { - /* earlier offset was large => reset the offset */ - found_offset = 0; - } - ELSE - { - /* keep previous offset unless something else is found. alternatively, we could reset always */ - found_offset = sync_state->prev_offset; - } - move16(); - test(); - test(); - IF( EQ_16( n_sim_start, MAX_PARAM_SPATIAL_SUBFRAMES ) && EQ_16( n_sim_stop, MAX_PARAM_SPATIAL_SUBFRAMES ) ) - { - /* full frame consists of similar sub-frames */ - frame_mode = MASA_FRAME_1SF; - move16(); - test(); - IF( ( sync_state->prev_sim_stop != 0 ) && EQ_16( are_masa_subframes_similar_fx( current_meta, 0, previous_meta, MAX_PARAM_SPATIAL_SUBFRAMES - 1 ), TRUE ) ) + IF( EQ_32( ivas_total_brate, IVAS_13k2 ) ) { - /* > 4 sub-frames of similar data */ - IF( LT_16( sync_state->prev_sim_stop, 3 ) ) + /* Calculate adaptive 1-bit LFE quantizer index */ + // linearLFEaverage = exp2f( log2LFEaverage ); /* Convert back to linear domain */ + linearLFEaverage = BASOP_util_Pow2( log2LFEaverage, Q31 - Q25, &linearLFEaverage_e ); /* Convert back to linear domain */ + linearLFEaverage = L_shl_sat( linearLFEaverage, sub( linearLFEaverage_e, Q1 ) ); // Q30 + test(); + IF( GT_32( linearLFEaverage, MCMASA_LFE_1BIT_THRES_Q30 ) && + GT_32( linearLFEaverage, L_add( L_add( MCMASA_LFE_BETA_Q30 >> Q1, L_shr( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, Q2 ) ), + L_shr( Mpy_32_32( MCMASA_LFE_ALPHA_Q30, hMasa->data.prevq_lfeToTotalEnergyRatio_fx ), Q1 ) ) ) ) { - /* can nicely align the framing with the earlier data and a small offset */ - found_offset = sync_state->prev_sim_stop; + lfeToTotalEnergyRatioIndices[0] = 1; + move16(); + IF( EQ_16( hMasa->data.prevq_lfeIndex, 1 ) ) + { + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = L_add( L_shr( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, Q1 ), 125627793 /* MCMASA_LFE_THETA * MCMASA_LFE_BETA in Q30 */ ); /* larger "bump-up" to LFE-to-total energy ratio */ // Q30 + move32(); + } + ELSE + { + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = L_add( L_shr( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, Q1 ), MCMASA_LFE_BETA_Q30 ); /* default "bump-up" to LFE-to-total energy ratio */ // Q30 + move32(); + } } ELSE { - /* too many similar sub-frames to determine the offset accurately => keep earlier value */ - found_offset = sync_state->prev_offset; + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = Mpy_32_32( MCMASA_LFE_ALPHA_Q30, hMasa->data.prevq_lfeToTotalEnergyRatio_fx ); /* exponential decay */ // Q30 + move32(); } - move16(); - } - ELSE - { - /* earlier window was different => reset the offset */ - found_offset = 0; - move16(); - } - } - ELSE IF( EQ_16( n_sim_stop, 3 ) ) - { - /* first sub-frame different that the rest 3 - => make a risky guess that the future sf would be the same too and we're in an offset case */ - frame_mode = MASA_FRAME_1SF; - found_offset = 3; - move16(); - move16(); - } - ELSE IF( ( sync_state->prev_sim_stop > 0 ) && EQ_16( are_masa_subframes_similar_fx( current_meta, 0, previous_meta, MAX_PARAM_SPATIAL_SUBFRAMES - 1 ), TRUE ) ) - { - /* seeing data similar to past */ - test(); - IF( GT_16( n_sim_start, 1 ) && ( GE_16( add( n_sim_start, sync_state->prev_sim_stop ), MAX_PARAM_SPATIAL_SUBFRAMES ) ) ) - { - /* with the past, would have at least one long frame similar subframes */ - frame_mode = MASA_FRAME_1SF; - move16(); - IF( sync_state->prev_offset == 0 ) + IF( GE_32( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, ONE_IN_Q30 ) ) { - found_offset = (UWord8) s_min( 2, sync_state->prev_sim_stop ); + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = ONE_IN_Q31; // Q31 + move32(); } ELSE { - found_offset = sync_state->prev_offset; - move16(); + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = L_shl( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, Q1 ); // Q31 + move32(); } + hMasa->data.prevq_lfeIndex = lfeToTotalEnergyRatioIndices[0]; /* Update to previous frame's index memories */ + move16(); } - } - - /* keep the original contents of the frame, but then perform interpolation later */ - /* just copy current frame to storage */ - copy_masa_metadata_fx( current_meta, previous_meta ); + ELSE /* Bitrate >= 16.4 kbps */ + { + /* Do 1st stage scalar quantization */ + lfeToTotalEnergyRatioIndices[0] = 1; + move16(); + lfeToTotalEnergyRatioIndices[1] = usquant_fx( extract_l( L_shr( log2LFEaverage, Q13 ) ), &xq, MCMASA_LFE_QLOW_Q12, MCMASA_LFE_DELTA_Q11, 8 ); + move16(); - sync_state->prev_sim_stop = n_sim_stop; - sync_state->prev_offset = found_offset; - sync_state->frame_mode = frame_mode; - move16(); - move16(); + IF( GE_32( ivas_total_brate, IVAS_24k4 ) ) /* Vector quantization is applied if bitrate >= 24.4 kbps */ + { + /* Remove scalar value from the vector*/ + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + log2LFEratio[i] = L_sub( log2LFEratio[i], L_shl( xq, Q13 ) ); // Q25 + move32(); + } + + /* Vector quantize residual with energy adaptive bit allocation */ + SWITCH( lfeToTotalEnergyRatioIndices[1] ) + { + case 0: + case 1: + VQLevels = 0; + move16(); + lfeAdaptiveVQBits = 0; + move16(); + BREAK; + case 2: + VQLevels = 2; + move16(); + lfeAdaptiveVQBits = 1; + move16(); + BREAK; + case 3: + VQLevels = 4; + move16(); + lfeAdaptiveVQBits = 2; + move16(); + BREAK; + case 4: + VQLevels = 8; + move16(); + lfeAdaptiveVQBits = 3; + move16(); + BREAK; + default: + VQLevels = 16; + move16(); + lfeAdaptiveVQBits = 4; + move16(); + } + + IF( VQLevels > 0 ) + { + lfeToTotalEnergyRatioIndices[2] = vquant_ivas_fx( log2LFEratio, 0, xqv, McMASA_LFEGain_vectors_fx_q25, 4, VQLevels ); + move16(); + } + } + } + } + + /* Write first LFE bit */ + lfeBitsWritten = 0; move16(); + push_next_indice( hMetaData, lfeToTotalEnergyRatioIndices[0], 1 ); + lfeBitsWritten = add( lfeBitsWritten, 1 ); - return; + test(); + IF( EQ_16( lfeToTotalEnergyRatioIndices[0], 1 ) && GE_32( ivas_total_brate, IVAS_16k4 ) ) + { + /* If bitrate >= 16.4kbit/s, send 1-bit on/off + 3-bit scalar */ + push_next_indice( hMetaData, lfeToTotalEnergyRatioIndices[1], 3 ); + lfeBitsWritten = add( lfeBitsWritten, 3 ); + + /* If bitrate >= 24.4kbit/s, use adaptive 1 + (3.. 7) bit quantizer */ + IF( GE_32( ivas_total_brate, IVAS_24k4 ) ) + { + /* Vector quantize residual with energy adaptive bit allocation */ + IF( lfeAdaptiveVQBits > 0 ) + { + push_next_indice( hMetaData, lfeToTotalEnergyRatioIndices[2], lfeAdaptiveVQBits ); + lfeBitsWritten = add( lfeBitsWritten, lfeAdaptiveVQBits ); + } + } + } + + return lfeBitsWritten; } #else -static void detect_framing_async( - MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder structure */ +static int16_t encode_lfe_to_total_energy_ratio( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + const int32_t ivas_total_brate /* i : IVAS total bitrate */ ) { - MASA_METADATA_HANDLE current_meta; - MASA_METADATA_HANDLE previous_meta; - MASA_SYNC_HANDLE sync_state; - MASA_FRAME_MODE frame_mode; - uint8_t n_sim_start, n_sim_stop, sf_idx; - uint8_t found_offset; + int16_t i; + float xq; + int16_t VQLevels; + float maxLFESubFrameEner; + float log2LFEaverage; + float log2LFEratio[4]; + float xqv[4]; + float linearLFEaverage; + int16_t lfeToTotalEnergyRatioIndices[3]; + int16_t lfeAdaptiveVQBits; + int16_t lfeBitsWritten; - current_meta = &( hMasa->masaMetadata ); /* metadata from current frame */ - sync_state = &( hMasa->data.sync_state ); /* synchronization structure */ - previous_meta = &( sync_state->previous_metadata ); + VQLevels = 0; + lfeAdaptiveVQBits = 0; - /* check current frame, how many are similar from the start and from the end */ - n_sim_start = 1; - for ( sf_idx = n_sim_start; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + /* Determine maximum amount of LFE energy in any subframe */ + maxLFESubFrameEner = 0.0f; + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - if ( are_masa_subframes_similar( current_meta, 0, current_meta, sf_idx ) == TRUE ) - { - n_sim_start = sf_idx + 1; - } - else + if ( hMasa->data.lfeToTotalEnergyRatio[i] > maxLFESubFrameEner ) { - break; + maxLFESubFrameEner = hMasa->data.lfeToTotalEnergyRatio[i]; } } - /* number of similar sub-frames starting from the end of the frame */ - if ( n_sim_start == MAX_PARAM_SPATIAL_SUBFRAMES ) /* shortcut */ + /* Set default values for the indices */ + for ( i = 0; i < 3; i++ ) { - n_sim_stop = n_sim_start; + lfeToTotalEnergyRatioIndices[i] = 0; } - else + + /* Check if there is enough energy in any subframe. If not, send only 1 bit (0) and abort. */ + /* If there is enough LFE energy at least in one subframe, quantize it. */ + if ( maxLFESubFrameEner > 0.005f ) { - n_sim_stop = 1; - for ( sf_idx = 2; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + /* Convert energy to log2 domain, and clamp it to reasonable values */ + log2LFEaverage = 0.0f; + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - /* we need to check only the two middle sub-frames, as all being the same would have taken the shortcut above */ - if ( are_masa_subframes_similar( current_meta, MAX_PARAM_SPATIAL_SUBFRAMES - 1, current_meta, MAX_PARAM_SPATIAL_SUBFRAMES - sf_idx ) == TRUE ) + log2LFEratio[i] = log2f( max( 0.001f, hMasa->data.lfeToTotalEnergyRatio[i] ) ); + if ( log2LFEratio[i] > 1.0f ) /* Corresponds to linear value 2.0f */ { - n_sim_stop = sf_idx; + log2LFEratio[i] = 1.0f; } - else + else if ( log2LFEratio[i] < -9.0f ) { - break; + log2LFEratio[i] = -9.0f; } + log2LFEaverage += 0.25f * log2LFEratio[i]; } - } - - frame_mode = MASA_FRAME_4SF; /* default mode: 4sf */ - if ( sync_state->prev_offset > MAX_PARAM_SPATIAL_SUBFRAMES - 2 ) - { - /* earlier offset was large => reset the offset */ - found_offset = 0; - } - else - { - /* keep previous offset unless something else is found. alternatively, we could reset always */ - found_offset = sync_state->prev_offset; - } - if ( ( n_sim_start == MAX_PARAM_SPATIAL_SUBFRAMES ) && ( n_sim_stop == MAX_PARAM_SPATIAL_SUBFRAMES ) ) - { - /* full frame consists of similar sub-frames */ - frame_mode = MASA_FRAME_1SF; - if ( ( sync_state->prev_sim_stop != 0 ) && ( are_masa_subframes_similar( current_meta, 0, previous_meta, MAX_PARAM_SPATIAL_SUBFRAMES - 1 ) == TRUE ) ) + if ( ivas_total_brate == IVAS_13k2 ) { - /* > 4 sub-frames of similar data */ - if ( sync_state->prev_sim_stop < 3 ) + /* Calculate adaptive 1-bit LFE quantizer index */ + linearLFEaverage = exp2f( log2LFEaverage ); /* Convert back to linear domain */ + if ( ( linearLFEaverage > MCMASA_LFE_1BIT_THRES ) && ( linearLFEaverage > ( 0.5f * ( MCMASA_LFE_BETA + hMasa->data.prevq_lfeToTotalEnergyRatio ) + 0.5f * ( MCMASA_LFE_ALPHA * hMasa->data.prevq_lfeToTotalEnergyRatio ) ) ) ) { - /* can nicely align the framing with the earlier data and a small offset */ - found_offset = sync_state->prev_sim_stop; + lfeToTotalEnergyRatioIndices[0] = 1; + if ( hMasa->data.prevq_lfeIndex == 1 ) + { + hMasa->data.prevq_lfeToTotalEnergyRatio = hMasa->data.prevq_lfeToTotalEnergyRatio + MCMASA_LFE_THETA * MCMASA_LFE_BETA; /* larger "bump-up" to LFE-to-total energy ratio */ + } + else + { + hMasa->data.prevq_lfeToTotalEnergyRatio = hMasa->data.prevq_lfeToTotalEnergyRatio + MCMASA_LFE_BETA; /* default "bump-up" to LFE-to-total energy ratio */ + } } else { - /* too many similar sub-frames to determine the offset accurately => keep earlier value */ - found_offset = sync_state->prev_offset; + hMasa->data.prevq_lfeToTotalEnergyRatio = MCMASA_LFE_ALPHA * hMasa->data.prevq_lfeToTotalEnergyRatio; /* exponential decay */ } - } - else - { - /* earlier window was different => reset the offset */ - found_offset = 0; - } - } - else if ( n_sim_stop == 3 ) - { - /* first sub-frame different that the rest 3 - => make a risky guess that the future sf would be the same too and we're in an offset case */ - frame_mode = MASA_FRAME_1SF; - found_offset = 3; - } - else if ( ( sync_state->prev_sim_stop > 0 ) && ( are_masa_subframes_similar( current_meta, 0, previous_meta, MAX_PARAM_SPATIAL_SUBFRAMES - 1 ) == TRUE ) ) - { - /* seeing data similar to past */ - if ( ( n_sim_start > 1 ) && ( n_sim_start + sync_state->prev_sim_stop >= MAX_PARAM_SPATIAL_SUBFRAMES ) ) - { - /* with the past, would have at least one long frame similar subframes */ - frame_mode = MASA_FRAME_1SF; - if ( sync_state->prev_offset == 0 ) - { - found_offset = min( 2, sync_state->prev_sim_stop ); - } - else + if ( hMasa->data.prevq_lfeToTotalEnergyRatio > 1.0f ) { - found_offset = sync_state->prev_offset; + hMasa->data.prevq_lfeToTotalEnergyRatio = 1.0f; } + hMasa->data.prevq_lfeIndex = lfeToTotalEnergyRatioIndices[0]; /* Update to previous frame's index memories */ } - } - - /* keep the original contents of the frame, but then perform interpolation later */ - /* just copy current frame to storage */ - copy_masa_metadata( current_meta, previous_meta ); - - sync_state->prev_sim_stop = n_sim_stop; - sync_state->prev_offset = found_offset; - sync_state->frame_mode = frame_mode; + else /* Bitrate >= 16.4 kbps */ + { + /* Do 1st stage scalar quantization */ + lfeToTotalEnergyRatioIndices[0] = 1; + lfeToTotalEnergyRatioIndices[1] = usquant( log2LFEaverage, &xq, MCMASA_LFE_QLOW, MCMASA_LFE_DELTA, 8 ); - return; -} -#endif // IVAS_FLOAT_FIXED + if ( ivas_total_brate >= IVAS_24k4 ) /* Vector quantization is applied if bitrate >= 24.4 kbps */ + { + /* Remove scalar value from the vector*/ + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + log2LFEratio[i] -= xq; + } -/*-------------------------------------------------------------------* - * masa_metadata_direction_alignment() - * - * In 2dir MASA metadata, determine the ordering of the directional - * fields such that the azi/ele change across time is minimized. - *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -static void masa_metadata_direction_alignment_fx( - MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder handle */ -) -{ - UWord8 band, n_dirs; + /* Vector quantize residual with energy adaptive bit allocation */ + switch ( lfeToTotalEnergyRatioIndices[1] ) + { + case 0: + case 1: + VQLevels = 0; + lfeAdaptiveVQBits = 0; + break; + case 2: + VQLevels = 2; + lfeAdaptiveVQBits = 1; + break; + case 3: + VQLevels = 4; + lfeAdaptiveVQBits = 2; + break; + case 4: + VQLevels = 8; + lfeAdaptiveVQBits = 3; + break; + default: + VQLevels = 16; + lfeAdaptiveVQBits = 4; + } + + if ( VQLevels > 0 ) + { + lfeToTotalEnergyRatioIndices[2] = vquant( log2LFEratio, 0, xqv, McMASA_LFEGain_vectors, 4, VQLevels ); + } + } + } + } + + /* Write first LFE bit */ + lfeBitsWritten = 0; + push_next_indice( hMetaData, lfeToTotalEnergyRatioIndices[0], 1 ); + lfeBitsWritten += 1; + + if ( lfeToTotalEnergyRatioIndices[0] == 1 && ivas_total_brate >= IVAS_16k4 ) + { + /* If bitrate >= 16.4kbit/s, send 1-bit on/off + 3-bit scalar */ + push_next_indice( hMetaData, lfeToTotalEnergyRatioIndices[1], 3 ); + lfeBitsWritten += 3; + + /* If bitrate >= 24.4kbit/s, use adaptive 1 + (3.. 7) bit quantizer */ + if ( ivas_total_brate >= IVAS_24k4 ) + { + /* Vector quantize residual with energy adaptive bit allocation */ + if ( lfeAdaptiveVQBits > 0 ) + { + push_next_indice( hMetaData, lfeToTotalEnergyRatioIndices[2], lfeAdaptiveVQBits ); + lfeBitsWritten += lfeAdaptiveVQBits; + } + } + } + + return lfeBitsWritten; +} +#endif + + +/*-------------------------------------------------------------------* + * ivas_masa_enc_reconfigure() + * + * Reconfigure IVAS MASA encoder + *-------------------------------------------------------------------*/ + +void ivas_masa_enc_reconfigure( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + int16_t n, tmp; + int16_t sce_id, cpe_id; + int32_t ivas_total_brate; + int32_t ism_total_brate; + + ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + + ism_total_brate = 0; + if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) + { + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + ism_total_brate += st_ivas->hSCE[sce_id]->element_brate; + } + } + + if ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) + { + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { +#ifdef IVAS_FLOAT_FIXED + copy_encoder_config_fx( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); +#else + copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); +#endif + st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; + st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + } + + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; + + /* prepare bitstream buffers */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { +#ifdef IVAS_FLOAT_FIXED + copy_encoder_config_fx( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); +#else + copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); +#endif + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + } + + if ( ivas_total_brate - ism_total_brate < MIN_BRATE_MDCT_STEREO ) + { + st_ivas->hCPE[cpe_id]->element_mode = IVAS_CPE_DFT; + } + else + { + st_ivas->hCPE[cpe_id]->element_mode = IVAS_CPE_MDCT; + } + } + +#ifndef IVAS_FLOAT_FIXED + ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp, st_ivas->hEncoderConfig->ivas_format, st_ivas->ism_mode, ism_total_brate ); +#else + ivas_masa_set_elements_fx( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp, st_ivas->hEncoderConfig->ivas_format, st_ivas->ism_mode, ism_total_brate ); +#endif + } + + return; +} + + +/*-------------------------------------------------------------------* + * average_masa_metadata() + * + * Average MASA metadata frame subframe contents: applies aggregation over time + *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void average_masa_metadata_fx( + MASA_METADATA_FRAME *hMeta, + Word32 energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /*i*/ + Word16 energy_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /*i:stores exponent values for energy_e*/ + const SPHERICAL_GRID_DATA *Sph_Grid16, + const UWord8 useSphGrid ) +{ + Word16 i, j, k; + Word16 azi_rad_fx, ele_rad_fx; + UWord8 numDirections; + + /* use the nominal values without data-adaptivity */ + numDirections = (UWord8) add( hMeta->descriptive_meta.numberOfDirections, 1 ); + move16(); + + /* azi/ele/nrg into vectors for each sub-frame and band */ + FOR( i = 0; i < numDirections; i++ ) + { + FOR( k = 0; k < MASA_FREQUENCY_BANDS; k++ ) + { + Word32 x_sum_fx, y_sum_fx, z_sum_fx, energy_sum_fx, vec_len_fx, spread_coh_sum_fx, surr_coh_sum_fx, temp1, temp2; + Word16 vec_len_e, x_sum_e, y_sum_e, z_sum_e, energy_sum_e, spread_coh_sum_e, surr_coh_sum_e, temp1_e, temp2_e; + x_sum_fx = 0; + y_sum_fx = 0; + z_sum_fx = 0; + energy_sum_fx = 0; + spread_coh_sum_fx = 0; + surr_coh_sum_fx = 0; + x_sum_e = 0; /*exponent for x_sum_fx*/ + y_sum_e = 0; /*exponent for y_sum_fx*/ + z_sum_e = 0; /*exponent for z_sum_fx*/ + energy_sum_e = 0; /*exponent for energy_sum_fx*/ + spread_coh_sum_e = 0; /*exponent for spread_coh_sum_fx*/ + surr_coh_sum_e = 0; /*exponent for surr_coh_sum_fx*/ + temp1 = 0; /* to store temporary computations*/ + temp2 = 0; /* to store temporary computations*/ + temp1_e = 0; /*to store temporary exponents*/ + temp2_e = 0; /*to store temporary exponents*/ + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + azi_rad_fx = extract_l( Mpy_32_32( hMeta->directional_meta[i].azimuth_fx[j][k], 2670177 /*1/(2*pi) in Q24*/ ) ); /*=angle *(1/2pi) brings the azi_rad_fx in -32767 to 32767 in q15 (this argument is further passed in cos and sin functions)*/ /*22+24-31=15*/ + ele_rad_fx = extract_l( Mpy_32_32( hMeta->directional_meta[i].elevation_fx[j][k], 2670177 /*1/(2*pi) in Q24*/ ) ); /*=angle *(1/2pi) brings the azi_rad_fx in -32767 to 32767 in q15 (this argument is further passed in cos and sin functions)*/ /*22+24-31=15*/ + vec_len_fx = extract_l( Mpy_32_32( hMeta->directional_meta[i].energy_ratio_fx[j][k] /*q30*/, energy[j][k] ) ); /*exponent=energy_e+1*/ + vec_len_e = add( energy_e[j][k], 1 ); + + /* energy-weighted sum over subframes */ + x_sum_fx = BASOP_Util_Add_Mant32Exp( x_sum_fx, x_sum_e, Mpy_32_32( L_mult( getCosWord16R2( azi_rad_fx ), getCosWord16R2( ele_rad_fx ) ) /*q31*/, vec_len_fx ), vec_len_e, &x_sum_e ); /*x_sum_e*/ + y_sum_fx = BASOP_Util_Add_Mant32Exp( y_sum_fx, y_sum_e, Mpy_32_32( L_mult( getSineWord16R2( azi_rad_fx ), getCosWord16R2( ele_rad_fx ) ) /*q31*/, vec_len_fx ), vec_len_e, &y_sum_e ); /*y_sum_e*/ + z_sum_fx = BASOP_Util_Add_Mant32Exp( z_sum_fx, z_sum_e, Mpy_32_16_1( vec_len_fx, getSineWord16R2( ele_rad_fx ) /*q15*/ ), vec_len_e, &z_sum_e ); /*z_sum_e*/ + + energy_sum_fx = BASOP_Util_Add_Mant32Exp( energy_sum_fx, energy_sum_e, energy[j][k], energy_e[j][k], &energy_sum_e ); /*energy_sum_e*/ + + spread_coh_sum_fx = BASOP_Util_Add_Mant32Exp( spread_coh_sum_fx, spread_coh_sum_e, Mpy_32_16_1( energy[j][k], hMeta->directional_meta[i].spread_coherence_fx[j][k] ), energy_e[j][k], &spread_coh_sum_e ); /*spread_coh_sum_e*/ + IF( i == 0 ) + { + /* this is in common metadata and not in each direction */ + surr_coh_sum_fx = BASOP_Util_Add_Mant32Exp( surr_coh_sum_fx, surr_coh_sum_e, Mpy_32_16_1( energy[j][k], hMeta->common_meta.surround_coherence_fx[j][k] ), energy_e[j][k], &surr_coh_sum_e ); /*surr_coh_sum_e*/ + } + } + + /* the data from the combined sub-frames is written into the first sub-frame band */ + j = 0; + move16(); + hMeta->directional_meta[i].azimuth_fx[j][k] = Mpy_32_16_1( 961263669 /*(1/ EVS_PI * 180.0f) in Q24*/, BASOP_util_atan2( y_sum_fx, x_sum_fx, sub( y_sum_e, x_sum_e ) ) /*q13*/ ); /*24+13-15=22*/ + move32(); + temp1 = BASOP_Util_Add_Mant32Exp( Mpy_32_32( x_sum_fx, x_sum_fx ), shl( x_sum_e, 1 ), Mpy_32_32( y_sum_fx, y_sum_fx ), shl( y_sum_e, 1 ), &temp1_e ); /*temp1_e*/ + temp2_e = temp1_e; + temp2 = Sqrt32( temp1, &temp2_e ); /*temp2_e*/ + hMeta->directional_meta[i].elevation_fx[j][k] = Mpy_32_16_1( 961263669 /*(1/ EVS_PI * 180.0f) in Q24*/, BASOP_util_atan2( z_sum_fx, temp2, sub( z_sum_e, temp2_e ) ) /*q13*/ ); /*24+13-15=22*/ + move32(); + IF( EQ_16( useSphGrid, TRUE ) ) + { + + hMeta->directional_meta[i].spherical_index[j][k] = index_theta_phi_16_fx( &( hMeta->directional_meta[i].elevation_fx[j][k] ), + &( hMeta->directional_meta[i].azimuth_fx[j][k] ), Sph_Grid16 ); + move16(); + } + vec_len_fx = BASOP_Util_Add_Mant32Exp( temp1, temp1_e, Mpy_32_32( z_sum_fx, z_sum_fx ), shl( z_sum_e, 1 ), &vec_len_e ); /*vec_len_e*/ /*x_sum * x_sum + y_sum * y_sum + z_sum * z_sum*/ + vec_len_fx = Sqrt32( vec_len_fx, &vec_len_e ); /*vec_len_e*/ + hMeta->directional_meta[i].energy_ratio_fx[j][k] = BASOP_Util_Divide3232_Scale( vec_len_fx, L_add( energy_sum_fx, EPSILON_FX ), &temp2_e ); /*temp2_e*/ + move32(); + temp2_e = add( temp2_e, sub( vec_len_e, energy_sum_e ) ); + hMeta->directional_meta[i].energy_ratio_fx[j][k] = L_shl( hMeta->directional_meta[i].energy_ratio_fx[j][k], add( temp2_e, 15 ) ); /*changing q from 15-temp2_e to q30*/ + move32(); + hMeta->directional_meta[i].spread_coherence_fx[j][k] = BASOP_Util_Divide3232_Scale( spread_coh_sum_fx, L_add( energy_sum_fx, EPSILON_FX ), &temp2_e ); + move16(); + temp2_e = add( temp2_e, sub( spread_coh_sum_e, energy_sum_e ) ); + hMeta->directional_meta[i].spread_coherence_fx[j][k] = shl( hMeta->directional_meta[i].spread_coherence_fx[j][k], temp2_e ); /*changing q from 15-temp2_e to q15*/ + move16(); + IF( i == 0 ) + { + hMeta->common_meta.surround_coherence_fx[j][k] = BASOP_Util_Divide3232_Scale( surr_coh_sum_fx, L_add( energy_sum_fx, EPSILON_FX ), &temp2_e ); + move16(); + temp2_e = add( temp2_e, sub( surr_coh_sum_e, energy_sum_e ) ); + hMeta->common_meta.surround_coherence_fx[j][k] = shl( hMeta->common_meta.surround_coherence_fx[j][k], temp2_e ); /*changing q from 15-temp2_e to q15*/ + move16(); + } + + /* copy the same value to all subframes */ + FOR( j = 1; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + hMeta->directional_meta[i].azimuth_fx[j][k] = hMeta->directional_meta[i].azimuth_fx[0][k]; /*q22*/ + hMeta->directional_meta[i].elevation_fx[j][k] = hMeta->directional_meta[i].elevation_fx[0][k]; /*q22*/ + hMeta->directional_meta[i].energy_ratio_fx[j][k] = hMeta->directional_meta[i].energy_ratio_fx[0][k]; /*q30*/ + hMeta->directional_meta[i].spread_coherence_fx[j][k] = hMeta->directional_meta[i].spread_coherence_fx[0][k]; /*q15*/ + move32(); + move32(); + move32(); + move16(); + IF( i == 0 ) + { + hMeta->common_meta.surround_coherence_fx[j][k] = hMeta->common_meta.surround_coherence_fx[0][k]; /*q15*/ + move16(); + } + } + } + } + + FOR( k = 0; k < MASA_FREQUENCY_BANDS; k++ ) + { + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + IF( EQ_16( numDirections, 2 ) ) + { + hMeta->common_meta.diffuse_to_total_ratio_fx[j][k] = L_max( 0, L_sub( L_sub( ONE_IN_Q30, hMeta->directional_meta[1].energy_ratio_fx[j][k] ), hMeta->directional_meta[0].energy_ratio_fx[j][k] ) ); /*q30*/ + } + ELSE + { + hMeta->common_meta.diffuse_to_total_ratio_fx[j][k] = L_max( 0, L_sub( ONE_IN_Q30, hMeta->directional_meta[0].energy_ratio_fx[j][k] ) ); /*q30*/ + } + move32(); + hMeta->common_meta.remainder_to_total_ratio_fx[j][k] = 0; /*q30*/ + move32(); + } + } + + return; +} +#else + +static void average_masa_metadata( + MASA_METADATA_FRAME *hMeta, + float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + const SPHERICAL_GRID_DATA *Sph_Grid16, + const uint8_t useSphGrid ) +{ + int16_t i, j, k; + float azi_rad, ele_rad; + uint8_t numDirections; + + /* use the nominal values without data-adaptivity */ + numDirections = hMeta->descriptive_meta.numberOfDirections + 1; + + /* azi/ele/nrg into vectors for each sub-frame and band */ + for ( i = 0; i < numDirections; i++ ) + { + for ( k = 0; k < MASA_FREQUENCY_BANDS; k++ ) + { + float x_sum, y_sum, z_sum, energy_sum, vec_len, spread_coh_sum, surr_coh_sum; + + x_sum = 0.0f; + y_sum = 0.0f; + z_sum = 0.0f; + energy_sum = 0.0f; + spread_coh_sum = 0.0f; + surr_coh_sum = 0.0f; + for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + azi_rad = hMeta->directional_meta[i].azimuth[j][k] / 180.0f * EVS_PI; + ele_rad = hMeta->directional_meta[i].elevation[j][k] / 180.0f * EVS_PI; + vec_len = hMeta->directional_meta[i].energy_ratio[j][k] * energy[j][k]; + + /* energy-weighted sum over subframes */ + x_sum += cosf( azi_rad ) * cosf( ele_rad ) * vec_len; + y_sum += sinf( azi_rad ) * cosf( ele_rad ) * vec_len; + z_sum += sinf( ele_rad ) * vec_len; + + energy_sum += energy[j][k]; + + spread_coh_sum += hMeta->directional_meta[i].spread_coherence[j][k] * energy[j][k]; + if ( i == 0 ) + { + /* this is in common metadata and not in each direction */ + surr_coh_sum += hMeta->common_meta.surround_coherence[j][k] * energy[j][k]; + } + } + + /* the data from the combined sub-frames is written into the first sub-frame band */ + j = 0; + hMeta->directional_meta[i].azimuth[j][k] = atan2f( y_sum, x_sum ) / EVS_PI * 180.0f; + hMeta->directional_meta[i].elevation[j][k] = atan2f( z_sum, sqrtf( x_sum * x_sum + y_sum * y_sum ) ) / EVS_PI * 180.0f; + if ( useSphGrid == TRUE ) + { +#ifndef IVAS_FLOAT_FIXED + hMeta->directional_meta[i].spherical_index[j][k] = index_theta_phi_16( &( hMeta->directional_meta[i].elevation[j][k] ), + &( hMeta->directional_meta[i].azimuth[j][k] ), Sph_Grid16 ); +#else + hMeta->directional_meta[i].elevation_fx[j][k] = floatToFixed( hMeta->directional_meta[i].elevation[j][k], Q22 ); + hMeta->directional_meta[i].azimuth_fx[j][k] = floatToFixed( hMeta->directional_meta[i].azimuth[j][k], Q22 ); + + hMeta->directional_meta[i].spherical_index[j][k] = index_theta_phi_16_fx( &( hMeta->directional_meta[i].elevation_fx[j][k] ), + &( hMeta->directional_meta[i].azimuth_fx[j][k] ), Sph_Grid16 ); + + hMeta->directional_meta[i].elevation[j][k] = fixedToFloat( hMeta->directional_meta[i].elevation_fx[j][k], Q22 ); + hMeta->directional_meta[i].azimuth[j][k] = fixedToFloat( hMeta->directional_meta[i].azimuth_fx[j][k], Q22 ); +#endif + } + vec_len = sqrtf( x_sum * x_sum + y_sum * y_sum + z_sum * z_sum ); + hMeta->directional_meta[i].energy_ratio[j][k] = vec_len / ( energy_sum + EPSILON ); + + hMeta->directional_meta[i].spread_coherence[j][k] = spread_coh_sum / ( energy_sum + EPSILON ); + if ( i == 0 ) + { + hMeta->common_meta.surround_coherence[j][k] = surr_coh_sum / ( energy_sum + EPSILON ); + } + + /* copy the same value to all subframes */ + for ( j = 1; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + hMeta->directional_meta[i].azimuth[j][k] = hMeta->directional_meta[i].azimuth[0][k]; + hMeta->directional_meta[i].elevation[j][k] = hMeta->directional_meta[i].elevation[0][k]; + hMeta->directional_meta[i].energy_ratio[j][k] = hMeta->directional_meta[i].energy_ratio[0][k]; + hMeta->directional_meta[i].spread_coherence[j][k] = hMeta->directional_meta[i].spread_coherence[0][k]; + if ( i == 0 ) + { + hMeta->common_meta.surround_coherence[j][k] = hMeta->common_meta.surround_coherence[0][k]; + } + } + } + } + + for ( k = 0; k < MASA_FREQUENCY_BANDS; k++ ) + { + for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + if ( numDirections == 2 ) + { + hMeta->common_meta.diffuse_to_total_ratio[j][k] = max( 0.0f, 1.0f - hMeta->directional_meta[1].energy_ratio[j][k] - hMeta->directional_meta[0].energy_ratio[j][k] ); + } + else + { + hMeta->common_meta.diffuse_to_total_ratio[j][k] = max( 0.0f, 1.0f - hMeta->directional_meta[0].energy_ratio[j][k] ); + } + hMeta->common_meta.remainder_to_total_ratio[j][k] = 0.0f; + } + } + + return; +} +#endif // IVAS_FLOAT_FIXED + + +/*-------------------------------------------------------------------* + * copy_masa_metadata_subframe() + * + * Copy MASA metadata frame subframe contents + *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void copy_masa_metadata_subframe_fx( + const MASA_METADATA_HANDLE hMetaFrom, /* i : MASA frame metdata to be copied */ + const UWord8 sfFrom, /* i : subframe index of the copy source */ + MASA_METADATA_HANDLE hMetaTo, /* o : MASA frame metadata copy destination */ + const UWord8 sfTo /* i : subframe index of the copy target */ +) +{ + UWord8 dir; + + /* directional metadata */ + FOR( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ ) + { + Copy32( hMetaFrom->directional_meta[dir].azimuth_fx[sfFrom], hMetaTo->directional_meta[dir].azimuth_fx[sfTo], MASA_FREQUENCY_BANDS ); + Copy32( hMetaFrom->directional_meta[dir].elevation_fx[sfFrom], hMetaTo->directional_meta[dir].elevation_fx[sfTo], MASA_FREQUENCY_BANDS ); + Copy32( hMetaFrom->directional_meta[dir].energy_ratio_fx[sfFrom], hMetaTo->directional_meta[dir].energy_ratio_fx[sfTo], MASA_FREQUENCY_BANDS ); + Copy( hMetaFrom->directional_meta[dir].spread_coherence_fx[sfFrom], hMetaTo->directional_meta[dir].spread_coherence_fx[sfTo], MASA_FREQUENCY_BANDS ); + } + + /* common metadata */ + Copy32( hMetaFrom->common_meta.diffuse_to_total_ratio_fx[sfFrom], hMetaTo->common_meta.diffuse_to_total_ratio_fx[sfTo], MASA_FREQUENCY_BANDS ); + Copy( hMetaFrom->common_meta.surround_coherence_fx[sfFrom], hMetaTo->common_meta.surround_coherence_fx[sfTo], MASA_FREQUENCY_BANDS ); + Copy32( hMetaFrom->common_meta.remainder_to_total_ratio_fx[sfFrom], hMetaTo->common_meta.remainder_to_total_ratio_fx[sfTo], MASA_FREQUENCY_BANDS ); + + return; +} +#else +static void copy_masa_metadata_subframe( + const MASA_METADATA_HANDLE hMetaFrom, /* i : MASA frame metdata to be copied */ + const uint8_t sfFrom, /* i : subframe index of the copy source */ + MASA_METADATA_HANDLE hMetaTo, /* o : MASA frame metadata copy destination */ + const uint8_t sfTo /* i : subframe index of the copy target */ +) +{ + uint8_t dir; + + /* directional metadata */ + for ( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ ) + { + mvr2r( hMetaFrom->directional_meta[dir].azimuth[sfFrom], hMetaTo->directional_meta[dir].azimuth[sfTo], MASA_FREQUENCY_BANDS ); + mvr2r( hMetaFrom->directional_meta[dir].elevation[sfFrom], hMetaTo->directional_meta[dir].elevation[sfTo], MASA_FREQUENCY_BANDS ); + mvr2r( hMetaFrom->directional_meta[dir].energy_ratio[sfFrom], hMetaTo->directional_meta[dir].energy_ratio[sfTo], MASA_FREQUENCY_BANDS ); + mvr2r( hMetaFrom->directional_meta[dir].spread_coherence[sfFrom], hMetaTo->directional_meta[dir].spread_coherence[sfTo], MASA_FREQUENCY_BANDS ); + } + + /* common metadata */ + mvr2r( hMetaFrom->common_meta.diffuse_to_total_ratio[sfFrom], hMetaTo->common_meta.diffuse_to_total_ratio[sfTo], MASA_FREQUENCY_BANDS ); + mvr2r( hMetaFrom->common_meta.surround_coherence[sfFrom], hMetaTo->common_meta.surround_coherence[sfTo], MASA_FREQUENCY_BANDS ); + mvr2r( hMetaFrom->common_meta.remainder_to_total_ratio[sfFrom], hMetaTo->common_meta.remainder_to_total_ratio[sfTo], MASA_FREQUENCY_BANDS ); + + return; +} +#endif // IVAS_FLOAT_FIXED + +/*-------------------------------------------------------------------* + * copy_masa_metadata() + * + * Copy MASA metada frame contents + *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void copy_masa_metadata_fx( + const MASA_METADATA_HANDLE hMetaFrom, /* i : MASA frame metadata to be copied */ + MASA_METADATA_HANDLE hMetaTo /* o : MASA frame metadata copy destination */ +) +{ + UWord8 sf, byte_idx; + + /* descriptive metadata */ + FOR( byte_idx = 0; byte_idx < 8; byte_idx++ ) + { + hMetaTo->descriptive_meta.formatDescriptor[byte_idx] = hMetaFrom->descriptive_meta.formatDescriptor[byte_idx]; + move16(); + } + + hMetaTo->descriptive_meta.numberOfDirections = hMetaFrom->descriptive_meta.numberOfDirections; + hMetaTo->descriptive_meta.numberOfChannels = hMetaFrom->descriptive_meta.numberOfChannels; + hMetaTo->descriptive_meta.sourceFormat = hMetaFrom->descriptive_meta.sourceFormat; + hMetaTo->descriptive_meta.transportDefinition = hMetaFrom->descriptive_meta.transportDefinition; + hMetaTo->descriptive_meta.channelAngle = hMetaFrom->descriptive_meta.channelAngle; + hMetaTo->descriptive_meta.channelDistance = hMetaFrom->descriptive_meta.channelDistance; + hMetaTo->descriptive_meta.channelLayout = hMetaFrom->descriptive_meta.channelLayout; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + + /* directional and common metadata */ + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + copy_masa_metadata_subframe_fx( hMetaFrom, sf, hMetaTo, sf ); + } + + return; +} +#else +static void copy_masa_metadata( + const MASA_METADATA_HANDLE hMetaFrom, /* i : MASA frame metadata to be copied */ + MASA_METADATA_HANDLE hMetaTo /* o : MASA frame metadata copy destination */ +) +{ + uint8_t sf, byte_idx; + + /* descriptive metadata */ + for ( byte_idx = 0; byte_idx < 8; byte_idx++ ) + { + hMetaTo->descriptive_meta.formatDescriptor[byte_idx] = hMetaFrom->descriptive_meta.formatDescriptor[byte_idx]; + } + + hMetaTo->descriptive_meta.numberOfDirections = hMetaFrom->descriptive_meta.numberOfDirections; + hMetaTo->descriptive_meta.numberOfChannels = hMetaFrom->descriptive_meta.numberOfChannels; + hMetaTo->descriptive_meta.sourceFormat = hMetaFrom->descriptive_meta.sourceFormat; + hMetaTo->descriptive_meta.transportDefinition = hMetaFrom->descriptive_meta.transportDefinition; + hMetaTo->descriptive_meta.channelAngle = hMetaFrom->descriptive_meta.channelAngle; + hMetaTo->descriptive_meta.channelDistance = hMetaFrom->descriptive_meta.channelDistance; + hMetaTo->descriptive_meta.channelLayout = hMetaFrom->descriptive_meta.channelLayout; + + /* directional and common metadata */ + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + copy_masa_metadata_subframe( hMetaFrom, sf, hMetaTo, sf ); + } + + return; +} +#endif + +/*-------------------------------------------------------------------* + * are_masa_subframes_similar() + * + * Compare the similarity of MASA metadata in two sub-frames + *-------------------------------------------------------------------*/ + +/* r: similarity decision */ +#ifdef IVAS_FLOAT_FIXED +static UWord8 are_masa_subframes_similar_fx( + const MASA_METADATA_HANDLE frame1, /* i : MASA metadata frame 1 */ + const UWord8 sf1_idx, /* i : index of the subframe of frame1 to inspect */ + const MASA_METADATA_HANDLE frame2, /* i : MASA metadata frame 2 */ + const UWord8 sf2_idx /* i : index of the subframe of frame2 to inspect */ +) +{ + UWord8 num_dir; + UWord8 dir; + UWord8 band_idx; + UWord8 sf_differ; + + num_dir = frame1->descriptive_meta.numberOfDirections; + dir = 0; + band_idx = 0; + sf_differ = FALSE; + move16(); + move16(); + move16(); + move16(); + + IF( NE_16( num_dir, frame2->descriptive_meta.numberOfDirections ) ) + { + sf_differ = TRUE; + move16(); + } + ELSE + { + /* check per-direction metadata */ + dir = 0; + band_idx = 0; + move16(); + move16(); + + WHILE( EQ_16( sf_differ, FALSE ) && LE_16( dir, num_dir ) ) + { + test(); + band_idx = 0; + move16(); + WHILE( EQ_16( sf_differ, FALSE ) && LT_16( band_idx, MASA_FREQUENCY_BANDS ) ) + { + test(); + Word32 azi_dif_fx; + azi_dif_fx = L_abs( L_sub( frame1->directional_meta[dir].azimuth_fx[sf1_idx][band_idx], frame2->directional_meta[dir].azimuth_fx[sf2_idx][band_idx] ) ); + IF( GT_32( azi_dif_fx, 180 << Q22 ) ) + azi_dif_fx = L_sub( 360 << Q22, azi_dif_fx ); + + IF( GT_32( azi_dif_fx, ONE_IN_Q21 /*0.5 in Q22*/ ) ) + { + sf_differ = TRUE; + move16(); + BREAK; + } + + IF( GT_32( L_abs( L_sub( frame1->directional_meta[dir].elevation_fx[sf1_idx][band_idx], frame2->directional_meta[dir].elevation_fx[sf2_idx][band_idx] ) ), MASA_ANGLE_TOLERANCE_FX ) ) + { + sf_differ = TRUE; + move16(); + BREAK; + } + + IF( GT_32( L_abs( L_sub( frame1->directional_meta[dir].energy_ratio_fx[sf1_idx][band_idx], frame2->directional_meta[dir].energy_ratio_fx[sf2_idx][band_idx] ) ), MASA_RATIO_TOLERANCE_FX ) ) + { + sf_differ = TRUE; + move16(); + BREAK; + } + + IF( GT_32( L_abs( L_sub( frame1->directional_meta[dir].spread_coherence_fx[sf1_idx][band_idx], frame2->directional_meta[dir].spread_coherence_fx[sf2_idx][band_idx] ) ), MASA_COHERENCE_TOLERANCE_FX ) ) + { + sf_differ = TRUE; + move16(); + BREAK; + } + + band_idx = (UWord8) add( band_idx, 1 ); + move16(); + } + dir = (UWord8) add( dir, 1 ); + move16(); + } + + /* check the common metadata */ + WHILE( EQ_16( sf_differ, FALSE ) && LT_16( band_idx, MASA_FREQUENCY_BANDS ) ) + { + test(); + IF( GT_32( L_abs( L_sub( frame1->common_meta.surround_coherence_fx[sf1_idx][band_idx], frame2->common_meta.surround_coherence_fx[sf2_idx][band_idx] ) ), MASA_COHERENCE_TOLERANCE_FX ) ) + { + sf_differ = TRUE; + move16(); + BREAK; + } + + band_idx = (UWord8) add( band_idx, 1 ); + move16(); + } + } + + IF( sf_differ ) + { + return FALSE; + } + ELSE + { + return TRUE; + } +} +#else +static uint8_t are_masa_subframes_similar( + const MASA_METADATA_HANDLE frame1, /* i : MASA metadata frame 1 */ + const uint8_t sf1_idx, /* i : index of the subframe of frame1 to inspect */ + const MASA_METADATA_HANDLE frame2, /* i : MASA metadata frame 2 */ + const uint8_t sf2_idx /* i : index of the subframe of frame2 to inspect */ +) +{ + uint8_t num_dir; + uint8_t dir; + uint8_t band_idx; + uint8_t sf_differ; + + num_dir = frame1->descriptive_meta.numberOfDirections; + dir = 0; + band_idx = 0; + sf_differ = FALSE; + + if ( num_dir != frame2->descriptive_meta.numberOfDirections ) + { + sf_differ = TRUE; + } + else + { + /* check per-direction metadata */ + dir = 0; + band_idx = 0; + + while ( ( sf_differ == FALSE ) && ( dir <= num_dir ) ) + { + band_idx = 0; + while ( ( sf_differ == FALSE ) && ( band_idx < MASA_FREQUENCY_BANDS ) ) + { + float azi_dif; + azi_dif = fabsf( frame1->directional_meta[dir].azimuth[sf1_idx][band_idx] - frame2->directional_meta[dir].azimuth[sf2_idx][band_idx] ); + azi_dif = azi_dif > 180.0f ? 360.0f - azi_dif : azi_dif; + + if ( azi_dif > MASA_ANGLE_TOLERANCE ) + { + sf_differ = TRUE; + break; + } + + if ( fabsf( frame1->directional_meta[dir].elevation[sf1_idx][band_idx] - frame2->directional_meta[dir].elevation[sf2_idx][band_idx] ) > MASA_ANGLE_TOLERANCE ) + { + sf_differ = TRUE; + break; + } + + if ( fabsf( frame1->directional_meta[dir].energy_ratio[sf1_idx][band_idx] - frame2->directional_meta[dir].energy_ratio[sf2_idx][band_idx] ) > MASA_RATIO_TOLERANCE ) + { + sf_differ = TRUE; + break; + } + + if ( fabsf( frame1->directional_meta[dir].spread_coherence[sf1_idx][band_idx] - frame2->directional_meta[dir].spread_coherence[sf2_idx][band_idx] ) > MASA_COHERENCE_TOLERANCE ) + { + sf_differ = TRUE; + break; + } + + band_idx++; + } + dir++; + } + + /* check the common metadata */ + while ( ( sf_differ == FALSE ) && ( band_idx < MASA_FREQUENCY_BANDS ) ) + { + if ( fabsf( frame1->common_meta.surround_coherence[sf1_idx][band_idx] - frame2->common_meta.surround_coherence[sf2_idx][band_idx] ) > MASA_COHERENCE_TOLERANCE ) + { + sf_differ = TRUE; + break; + } + + band_idx++; + } + } + + if ( sf_differ ) + { + return FALSE; + } + else + { + return TRUE; + } +} +#endif + +/*-------------------------------------------------------------------* + * detect_framing_async() + * + * Compare the similarity of MASA metadata in two sub-frames + * Analysis result is stored in hMasa->data.sync_state, and + * potentially hMasa->masaMetadata is modified + *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void detect_framing_async_fx( + MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder structure */ +) +{ + MASA_METADATA_HANDLE current_meta; + MASA_METADATA_HANDLE previous_meta; + MASA_SYNC_HANDLE sync_state; + MASA_FRAME_MODE frame_mode; + UWord8 n_sim_start, n_sim_stop, sf_idx; + UWord8 found_offset; + + current_meta = &( hMasa->masaMetadata ); /* metadata from current frame */ + sync_state = &( hMasa->data.sync_state ); /* synchronization structure */ + previous_meta = &( sync_state->previous_metadata ); + + /* check current frame, how many are similar from the start and from the end */ + n_sim_start = 1; + move16(); + FOR( sf_idx = n_sim_start; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + { + IF( EQ_16( are_masa_subframes_similar_fx( current_meta, 0, current_meta, sf_idx ), TRUE ) ) + { + n_sim_start = (UWord8) add( sf_idx, 1 ); + move16(); + } + ELSE + { + BREAK; + } + } + + /* number of similar sub-frames starting from the end of the frame */ + IF( EQ_16( n_sim_start, MAX_PARAM_SPATIAL_SUBFRAMES ) ) /* shortcut */ + { + n_sim_stop = n_sim_start; + move16(); + } + ELSE + { + n_sim_stop = 1; + move16(); + FOR( sf_idx = 2; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + { + /* we need to check only the two middle sub-frames, as all being the same would have taken the shortcut above */ + IF( EQ_16( are_masa_subframes_similar_fx( current_meta, MAX_PARAM_SPATIAL_SUBFRAMES - 1, current_meta, (UWord8) sub( MAX_PARAM_SPATIAL_SUBFRAMES, sf_idx ) ), TRUE ) ) + { + n_sim_stop = sf_idx; + move16(); + } + ELSE + { + BREAK; + } + } + } + + frame_mode = MASA_FRAME_4SF; /* default mode: 4sf */ + move16(); + IF( GT_16( sync_state->prev_offset, MAX_PARAM_SPATIAL_SUBFRAMES - 2 ) ) + { + /* earlier offset was large => reset the offset */ + found_offset = 0; + } + ELSE + { + /* keep previous offset unless something else is found. alternatively, we could reset always */ + found_offset = sync_state->prev_offset; + } + move16(); + + test(); + test(); + IF( EQ_16( n_sim_start, MAX_PARAM_SPATIAL_SUBFRAMES ) && EQ_16( n_sim_stop, MAX_PARAM_SPATIAL_SUBFRAMES ) ) + { + /* full frame consists of similar sub-frames */ + frame_mode = MASA_FRAME_1SF; + move16(); + test(); + IF( ( sync_state->prev_sim_stop != 0 ) && EQ_16( are_masa_subframes_similar_fx( current_meta, 0, previous_meta, MAX_PARAM_SPATIAL_SUBFRAMES - 1 ), TRUE ) ) + { + /* > 4 sub-frames of similar data */ + IF( LT_16( sync_state->prev_sim_stop, 3 ) ) + { + /* can nicely align the framing with the earlier data and a small offset */ + found_offset = sync_state->prev_sim_stop; + } + ELSE + { + /* too many similar sub-frames to determine the offset accurately => keep earlier value */ + found_offset = sync_state->prev_offset; + } + move16(); + } + ELSE + { + /* earlier window was different => reset the offset */ + found_offset = 0; + move16(); + } + } + ELSE IF( EQ_16( n_sim_stop, 3 ) ) + { + /* first sub-frame different that the rest 3 + => make a risky guess that the future sf would be the same too and we're in an offset case */ + frame_mode = MASA_FRAME_1SF; + found_offset = 3; + move16(); + move16(); + } + ELSE IF( ( sync_state->prev_sim_stop > 0 ) && EQ_16( are_masa_subframes_similar_fx( current_meta, 0, previous_meta, MAX_PARAM_SPATIAL_SUBFRAMES - 1 ), TRUE ) ) + { + /* seeing data similar to past */ + test(); + IF( GT_16( n_sim_start, 1 ) && ( GE_16( add( n_sim_start, sync_state->prev_sim_stop ), MAX_PARAM_SPATIAL_SUBFRAMES ) ) ) + { + /* with the past, would have at least one long frame similar subframes */ + frame_mode = MASA_FRAME_1SF; + move16(); + + IF( sync_state->prev_offset == 0 ) + { + found_offset = (UWord8) s_min( 2, sync_state->prev_sim_stop ); + } + ELSE + { + found_offset = sync_state->prev_offset; + move16(); + } + } + } + + /* keep the original contents of the frame, but then perform interpolation later */ + /* just copy current frame to storage */ + copy_masa_metadata_fx( current_meta, previous_meta ); + + sync_state->prev_sim_stop = n_sim_stop; + sync_state->prev_offset = found_offset; + sync_state->frame_mode = frame_mode; + move16(); + move16(); + move16(); + + return; +} +#else +static void detect_framing_async( + MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder structure */ +) +{ + MASA_METADATA_HANDLE current_meta; + MASA_METADATA_HANDLE previous_meta; + MASA_SYNC_HANDLE sync_state; + MASA_FRAME_MODE frame_mode; + uint8_t n_sim_start, n_sim_stop, sf_idx; + uint8_t found_offset; + + current_meta = &( hMasa->masaMetadata ); /* metadata from current frame */ + sync_state = &( hMasa->data.sync_state ); /* synchronization structure */ + previous_meta = &( sync_state->previous_metadata ); + + /* check current frame, how many are similar from the start and from the end */ + n_sim_start = 1; + for ( sf_idx = n_sim_start; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + { + if ( are_masa_subframes_similar( current_meta, 0, current_meta, sf_idx ) == TRUE ) + { + n_sim_start = sf_idx + 1; + } + else + { + break; + } + } + + /* number of similar sub-frames starting from the end of the frame */ + if ( n_sim_start == MAX_PARAM_SPATIAL_SUBFRAMES ) /* shortcut */ + { + n_sim_stop = n_sim_start; + } + else + { + n_sim_stop = 1; + for ( sf_idx = 2; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + { + /* we need to check only the two middle sub-frames, as all being the same would have taken the shortcut above */ + if ( are_masa_subframes_similar( current_meta, MAX_PARAM_SPATIAL_SUBFRAMES - 1, current_meta, MAX_PARAM_SPATIAL_SUBFRAMES - sf_idx ) == TRUE ) + { + n_sim_stop = sf_idx; + } + else + { + break; + } + } + } + + frame_mode = MASA_FRAME_4SF; /* default mode: 4sf */ + if ( sync_state->prev_offset > MAX_PARAM_SPATIAL_SUBFRAMES - 2 ) + { + /* earlier offset was large => reset the offset */ + found_offset = 0; + } + else + { + /* keep previous offset unless something else is found. alternatively, we could reset always */ + found_offset = sync_state->prev_offset; + } + + if ( ( n_sim_start == MAX_PARAM_SPATIAL_SUBFRAMES ) && ( n_sim_stop == MAX_PARAM_SPATIAL_SUBFRAMES ) ) + { + /* full frame consists of similar sub-frames */ + frame_mode = MASA_FRAME_1SF; + if ( ( sync_state->prev_sim_stop != 0 ) && ( are_masa_subframes_similar( current_meta, 0, previous_meta, MAX_PARAM_SPATIAL_SUBFRAMES - 1 ) == TRUE ) ) + { + /* > 4 sub-frames of similar data */ + if ( sync_state->prev_sim_stop < 3 ) + { + /* can nicely align the framing with the earlier data and a small offset */ + found_offset = sync_state->prev_sim_stop; + } + else + { + /* too many similar sub-frames to determine the offset accurately => keep earlier value */ + found_offset = sync_state->prev_offset; + } + } + else + { + /* earlier window was different => reset the offset */ + found_offset = 0; + } + } + else if ( n_sim_stop == 3 ) + { + /* first sub-frame different that the rest 3 + => make a risky guess that the future sf would be the same too and we're in an offset case */ + frame_mode = MASA_FRAME_1SF; + found_offset = 3; + } + else if ( ( sync_state->prev_sim_stop > 0 ) && ( are_masa_subframes_similar( current_meta, 0, previous_meta, MAX_PARAM_SPATIAL_SUBFRAMES - 1 ) == TRUE ) ) + { + /* seeing data similar to past */ + if ( ( n_sim_start > 1 ) && ( n_sim_start + sync_state->prev_sim_stop >= MAX_PARAM_SPATIAL_SUBFRAMES ) ) + { + /* with the past, would have at least one long frame similar subframes */ + frame_mode = MASA_FRAME_1SF; + + if ( sync_state->prev_offset == 0 ) + { + found_offset = min( 2, sync_state->prev_sim_stop ); + } + else + { + found_offset = sync_state->prev_offset; + } + } + } + + /* keep the original contents of the frame, but then perform interpolation later */ + /* just copy current frame to storage */ + copy_masa_metadata( current_meta, previous_meta ); + + sync_state->prev_sim_stop = n_sim_stop; + sync_state->prev_offset = found_offset; + sync_state->frame_mode = frame_mode; + + return; +} +#endif // IVAS_FLOAT_FIXED + +/*-------------------------------------------------------------------* + * masa_metadata_direction_alignment() + * + * In 2dir MASA metadata, determine the ordering of the directional + * fields such that the azi/ele change across time is minimized. + *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void masa_metadata_direction_alignment_fx( + MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder handle */ +) +{ + UWord8 band, n_dirs; + MASA_DIR_ALIGN_HANDLE hAlignState; + MASA_METADATA_HANDLE hMeta; + hAlignState = &( hMasa->data.dir_align_state ); + hMeta = &( hMasa->masaMetadata ); + + n_dirs = (UWord8) add( hMeta->descriptive_meta.numberOfDirections, 1 ); /* 1-based */ + move16(); + FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + { + UWord8 sf; + Word16 diff_swap_fx; + Word16 diff_no_swap_fx; + + /* trade 2*(cos+sin) against storing the values between frames */ + Word16 prev_ele_dir1_sin_fx, prev_ele_dir2_sin_fx; + Word16 prev_ele_dir1_cos_fx, prev_ele_dir2_cos_fx; + + prev_ele_dir1_sin_fx = getSineWord16R2( extract_l( Mpy_32_32( hAlignState->previous_ele_dir1_fx[band], 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + prev_ele_dir2_sin_fx = getSineWord16R2( extract_l( Mpy_32_32( hAlignState->previous_ele_dir2_fx[band], 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + + prev_ele_dir1_cos_fx = getCosWord16R2( extract_l( Mpy_32_32( hAlignState->previous_ele_dir1_fx[band], 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + prev_ele_dir2_cos_fx = getCosWord16R2( extract_l( Mpy_32_32( hAlignState->previous_ele_dir2_fx[band], 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + Word32 azi_rad1_fx, ele_rad1_fx; + Word32 azi_rad2_fx, ele_rad2_fx; + Word16 cos_ele1_fx, cos_ele2_fx; + Word16 sin_ele1_fx, sin_ele2_fx; + Word16 temp1; + Word32 temp2; + Word16 temp1_e; + + + azi_rad1_fx = Mpy_32_16_1( hMeta->directional_meta[0].azimuth_fx[sf][band], 572 /*PI_OVER_180 q15*/ ); /*q22*/ + ele_rad1_fx = Mpy_32_16_1( hMeta->directional_meta[0].elevation_fx[sf][band], 572 /*PI_OVER_180 q15*/ ); /*q22*/ + + IF( GT_16( n_dirs, 1 ) ) + { + azi_rad2_fx = Mpy_32_16_1( hMeta->directional_meta[1].azimuth_fx[sf][band], 572 /*PI_OVER_180 q15*/ ); /*q22*/ + ele_rad2_fx = Mpy_32_16_1( hMeta->directional_meta[1].elevation_fx[sf][band], 572 /*PI_OVER_180 q15*/ ); /*q22*/ + + test(); + test(); + test(); + test(); + test(); + test(); + /* quick checks to detect constant data and earlier flip */ + IF( LT_32( L_abs( L_sub( azi_rad1_fx, hAlignState->previous_azi_dir1_fx[band] ) ), EPSILON_FX ) && + LT_32( L_abs( L_sub( azi_rad2_fx, hAlignState->previous_azi_dir2_fx[band] ) ), EPSILON_FX ) && + LT_32( L_abs( L_sub( ele_rad1_fx, hAlignState->previous_ele_dir1_fx[band] ) ), EPSILON_FX ) && + LT_32( L_abs( L_sub( ele_rad2_fx, hAlignState->previous_ele_dir2_fx[band] ) ), EPSILON_FX ) ) + { + diff_swap_fx = ONE_IN_Q13; /*1 q13*/ + diff_no_swap_fx = 0; + /* cached values that will be used for the short-cuts and over-written by the real computations, if done */ + sin_ele1_fx = prev_ele_dir1_sin_fx; /*q15*/ + sin_ele2_fx = prev_ele_dir2_sin_fx; /*q15*/ + cos_ele1_fx = prev_ele_dir1_cos_fx; /*q15*/ + cos_ele2_fx = prev_ele_dir2_cos_fx; /*q15*/ + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + } + ELSE IF( LT_32( L_abs( L_sub( azi_rad1_fx, hAlignState->previous_azi_dir2_fx[band] ) ), EPSILON_FX ) && + LT_32( L_abs( L_sub( azi_rad2_fx, hAlignState->previous_azi_dir1_fx[band] ) ), EPSILON_FX ) && + LT_32( L_abs( L_sub( ele_rad1_fx, hAlignState->previous_ele_dir2_fx[band] ) ), EPSILON_FX ) && + LT_32( L_abs( L_sub( ele_rad2_fx, hAlignState->previous_ele_dir1_fx[band] ) ), EPSILON_FX ) ) + { + diff_swap_fx = 0; + diff_no_swap_fx = ONE_IN_Q13; /*1.0 q13*/ + /* cached values that will be used for the short-cuts and over-written by the real computations, if done */ + sin_ele1_fx = prev_ele_dir2_sin_fx; /*q15*/ + sin_ele2_fx = prev_ele_dir1_sin_fx; /*q15*/ + cos_ele1_fx = prev_ele_dir2_cos_fx; /*q15*/ + cos_ele2_fx = prev_ele_dir1_cos_fx; /*q15*/ + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + } + ELSE + { + /* angular distance of the two vectors */ + /* pre-compute values for re-use */ + sin_ele1_fx = getSineWord16R2( extract_l( Mpy_32_32( ele_rad1_fx, 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + sin_ele2_fx = getSineWord16R2( extract_l( Mpy_32_32( ele_rad2_fx, 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + + cos_ele1_fx = getCosWord16R2( extract_l( Mpy_32_32( ele_rad1_fx, 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + cos_ele2_fx = getCosWord16R2( extract_l( Mpy_32_32( ele_rad2_fx, 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + + temp1 = getCosWord16R2( extract_l( Mpy_32_32( L_sub( azi_rad1_fx, hAlignState->previous_azi_dir1_fx[band] ), 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + temp1 = mult( mult( temp1, cos_ele1_fx ) /*q31*/, prev_ele_dir1_cos_fx /*q15*/ ); /*q15*/ + temp1 = add_sat( mult( sin_ele1_fx, prev_ele_dir1_sin_fx ), temp1 ); /*q15*/ + temp1_e = 1; /*stores expoenent for square root operation*/ + move16(); + temp2 = Sqrt32( L_sub( ONE_IN_Q30, L_mult0( temp1, temp1 ) ), &temp1_e ); /*31-temp1_e*/ + temp1 = BASOP_util_atan2( temp2, abs_s( temp1 ), sub( temp1_e, 16 ) ); /*q13*/ + diff_no_swap_fx = temp1; /*q13*/ + + temp1 = getCosWord16R2( extract_l( Mpy_32_32( L_sub( azi_rad2_fx, hAlignState->previous_azi_dir2_fx[band] ), 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + temp1 = mult( mult( temp1, cos_ele2_fx ) /*q31*/, prev_ele_dir2_cos_fx /*q15*/ ); /*q15*/ + temp1 = add_sat( mult( sin_ele2_fx, prev_ele_dir2_sin_fx ), temp1 ); /*q15*/ + temp1_e = 1; /*stores expoenent for square root operation*/ + move16(); + temp2 = Sqrt32( L_sub( ONE_IN_Q30, L_mult0( temp1, temp1 ) ), &temp1_e ); /*31-temp1_e*/ + temp1 = BASOP_util_atan2( temp2, abs_s( temp1 ), sub( temp1_e, 16 ) ); /*q13*/ + diff_no_swap_fx = add( diff_no_swap_fx, temp1 ); /*q13*/ + + temp1 = getCosWord16R2( extract_l( Mpy_32_32( L_sub( azi_rad1_fx, hAlignState->previous_azi_dir2_fx[band] ), 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + temp1 = mult( mult( temp1, cos_ele1_fx ) /*q31*/, prev_ele_dir2_cos_fx /*q15*/ ); /*q15*/ + temp1 = add_sat( mult( sin_ele1_fx, prev_ele_dir2_sin_fx ), temp1 ); /*q15*/ + temp1_e = 1; /*stores expoenent for square root operation*/ + move16(); + temp2 = Sqrt32( L_sub( ONE_IN_Q30, L_mult0( temp1, temp1 ) ), &temp1_e ); /*31-temp1_e*/ + temp1 = BASOP_util_atan2( temp2, abs_s( temp1 ), sub( temp1_e, 16 ) ); /*q13*/ + diff_swap_fx = temp1; /*q13*/ + + temp1 = getCosWord16R2( extract_l( Mpy_32_32( L_sub( azi_rad2_fx, hAlignState->previous_azi_dir1_fx[band] ), 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + temp1 = mult( mult( temp1, cos_ele2_fx ) /*q31*/, prev_ele_dir1_cos_fx /*q15*/ ); /*q15*/ + temp1 = add_sat( mult( sin_ele2_fx, prev_ele_dir1_sin_fx ), temp1 ); /*q15*/ + temp1_e = 1; /*stores expoenent for square root operation*/ + move16(); + temp2 = Sqrt32( L_sub( ONE_IN_Q30, L_mult0( temp1, temp1 ) ), &temp1_e ); /*31-temp1_e*/ + temp1 = BASOP_util_atan2( temp2, abs_s( temp1 ), sub( temp1_e, 16 ) ); /*q13*/ + diff_swap_fx = add( diff_swap_fx, temp1 ); /*q13*/ + } + } + ELSE + { + /* 1dir */ + sin_ele1_fx = getSineWord16R2( extract_l( Mpy_32_32( ele_rad1_fx, 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + cos_ele1_fx = getCosWord16R2( extract_l( Mpy_32_32( ele_rad1_fx, 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + + azi_rad2_fx = 0; + ele_rad2_fx = 0; + move32(); + move32(); + + sin_ele2_fx = 0; /* sin(0) */ + cos_ele2_fx = MAX_16; /* cos(0) in Q15*/ + move16(); + move16(); + + diff_swap_fx = ONE_IN_Q13; /*1.0 in Q13*/ + diff_no_swap_fx = 0; + move16(); + move16(); + } + + test(); + IF( GT_16( n_dirs, 1 ) && GT_16( diff_no_swap_fx, diff_swap_fx ) ) + { + /* swap the metadata of the two directions in this TF-tile */ + Word32 tmp_val; + Word16 tmp_val_16; + UWord16 tmp_int_val; + tmp_val = hMeta->directional_meta[0].azimuth_fx[sf][band]; /*q22*/ + hMeta->directional_meta[0].azimuth_fx[sf][band] = hMeta->directional_meta[1].azimuth_fx[sf][band]; /*q22*/ + hMeta->directional_meta[1].azimuth_fx[sf][band] = tmp_val; /*q22*/ + move32(); + move32(); + move32(); + + tmp_val = hMeta->directional_meta[0].elevation_fx[sf][band]; /*q22*/ + hMeta->directional_meta[0].elevation_fx[sf][band] = hMeta->directional_meta[1].elevation_fx[sf][band]; /*q22*/ + hMeta->directional_meta[1].elevation_fx[sf][band] = tmp_val; /*q22*/ + move32(); + move32(); + move32(); + + tmp_int_val = hMeta->directional_meta[0].spherical_index[sf][band]; /*q0*/ + hMeta->directional_meta[0].spherical_index[sf][band] = hMeta->directional_meta[1].spherical_index[sf][band]; /*q0*/ + hMeta->directional_meta[1].spherical_index[sf][band] = tmp_int_val; /*q0*/ + move32(); + move32(); + move32(); + + tmp_val = hMeta->directional_meta[0].energy_ratio_fx[sf][band]; /*q30*/ + hMeta->directional_meta[0].energy_ratio_fx[sf][band] = hMeta->directional_meta[1].energy_ratio_fx[sf][band]; /*q30*/ + hMeta->directional_meta[1].energy_ratio_fx[sf][band] = tmp_val; /*q30*/ + move32(); + move32(); + move32(); + + tmp_val_16 = hMeta->directional_meta[0].spread_coherence_fx[sf][band]; /*q15*/ + hMeta->directional_meta[0].spread_coherence_fx[sf][band] = hMeta->directional_meta[1].spread_coherence_fx[sf][band]; /*q15*/ + hMeta->directional_meta[1].spread_coherence_fx[sf][band] = tmp_val_16; /*q15*/ + move16(); + move16(); + move16(); + + hAlignState->previous_azi_dir1_fx[band] = azi_rad2_fx; /*q22*/ + hAlignState->previous_ele_dir1_fx[band] = ele_rad2_fx; /*q22*/ + move32(); + move32(); + + hAlignState->previous_azi_dir2_fx[band] = azi_rad1_fx; /*q22*/ + hAlignState->previous_ele_dir2_fx[band] = ele_rad1_fx; /*q22*/ + move32(); + move32(); + + prev_ele_dir1_cos_fx = cos_ele2_fx; /*q15*/ + prev_ele_dir1_sin_fx = sin_ele2_fx; /*q15*/ + move16(); + move16(); + + prev_ele_dir2_cos_fx = cos_ele1_fx; /*q15*/ + prev_ele_dir2_sin_fx = sin_ele1_fx; /*q15*/ + move16(); + move16(); + } + ELSE + { + hAlignState->previous_azi_dir1_fx[band] = azi_rad1_fx; /*q22*/ + hAlignState->previous_ele_dir1_fx[band] = ele_rad1_fx; /*q22*/ + move32(); + move32(); + + hAlignState->previous_azi_dir2_fx[band] = azi_rad2_fx; /*q22*/ + hAlignState->previous_ele_dir2_fx[band] = ele_rad2_fx; /*q22*/ + move32(); + move32(); + + prev_ele_dir1_cos_fx = cos_ele1_fx; /*q15*/ + prev_ele_dir1_sin_fx = sin_ele1_fx; /*q15*/ + move16(); + move16(); + + prev_ele_dir2_cos_fx = cos_ele2_fx; /*q15*/ + prev_ele_dir2_sin_fx = sin_ele2_fx; /*q15*/ + move16(); + move16(); + } + } /* sf */ + } /* band */ + + return; +} +#else +static void masa_metadata_direction_alignment( + MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder handle */ +) +{ + uint8_t band, n_dirs; MASA_DIR_ALIGN_HANDLE hAlignState; MASA_METADATA_HANDLE hMeta; - hAlignState = &( hMasa->data.dir_align_state ); + + hAlignState = &( hMasa->data.dir_align_state ); + hMeta = &( hMasa->masaMetadata ); + + n_dirs = hMeta->descriptive_meta.numberOfDirections + 1; /* 1-based */ + for ( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + { + uint8_t sf; + float diff_swap, diff_no_swap; + + /* trade 2*(cos+sin) against storing the values between frames */ + float prev_ele_dir1_sin, prev_ele_dir2_sin; + float prev_ele_dir1_cos, prev_ele_dir2_cos; + + prev_ele_dir1_sin = sinf( hAlignState->previous_ele_dir1[band] ); + prev_ele_dir2_sin = sinf( hAlignState->previous_ele_dir2[band] ); + + prev_ele_dir1_cos = cosf( hAlignState->previous_ele_dir1[band] ); + prev_ele_dir2_cos = cosf( hAlignState->previous_ele_dir2[band] ); + + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + float azi_rad1, ele_rad1; + float azi_rad2, ele_rad2; + float cos_ele1, cos_ele2; + float sin_ele1, sin_ele2; + + azi_rad1 = hMeta->directional_meta[0].azimuth[sf][band] * PI_OVER_180; + ele_rad1 = hMeta->directional_meta[0].elevation[sf][band] * PI_OVER_180; + + if ( n_dirs > 1 ) + { + azi_rad2 = hMeta->directional_meta[1].azimuth[sf][band] * PI_OVER_180; + ele_rad2 = hMeta->directional_meta[1].elevation[sf][band] * PI_OVER_180; + + /* quick checks to detect constant data and earlier flip */ + if ( fabsf( azi_rad1 - hAlignState->previous_azi_dir1[band] ) < EPSILON && + fabsf( azi_rad2 - hAlignState->previous_azi_dir2[band] ) < EPSILON && + fabsf( ele_rad1 - hAlignState->previous_ele_dir1[band] ) < EPSILON && + fabsf( ele_rad2 - hAlignState->previous_ele_dir2[band] ) < EPSILON ) + { + diff_swap = 1.0f; + diff_no_swap = 0.0f; + /* cached values that will be used for the short-cuts and over-written by the real computations, if done */ + sin_ele1 = prev_ele_dir1_sin; + sin_ele2 = prev_ele_dir2_sin; + cos_ele1 = prev_ele_dir1_cos; + cos_ele2 = prev_ele_dir2_cos; + } + else if ( fabsf( azi_rad1 - hAlignState->previous_azi_dir2[band] ) < EPSILON && + fabsf( azi_rad2 - hAlignState->previous_azi_dir1[band] ) < EPSILON && + fabsf( ele_rad1 - hAlignState->previous_ele_dir2[band] ) < EPSILON && + fabsf( ele_rad2 - hAlignState->previous_ele_dir1[band] ) < EPSILON ) + { + diff_swap = 0.0f; + diff_no_swap = 1.0f; + /* cached values that will be used for the short-cuts and over-written by the real computations, if done */ + sin_ele1 = prev_ele_dir2_sin; + sin_ele2 = prev_ele_dir1_sin; + cos_ele1 = prev_ele_dir2_cos; + cos_ele2 = prev_ele_dir1_cos; + } + else + { + /* angular distance of the two vectors */ + /* pre-compute values for re-use */ + sin_ele1 = sinf( ele_rad1 ); + sin_ele2 = sinf( ele_rad2 ); + + cos_ele1 = cosf( ele_rad1 ); + cos_ele2 = cosf( ele_rad2 ); + + diff_no_swap = acosf( cos_ele1 * prev_ele_dir1_cos * cosf( azi_rad1 - hAlignState->previous_azi_dir1[band] ) + sin_ele1 * prev_ele_dir1_sin ) + + acosf( cos_ele2 * prev_ele_dir2_cos * cosf( azi_rad2 - hAlignState->previous_azi_dir2[band] ) + sin_ele2 * prev_ele_dir2_sin ); + + diff_swap = acosf( cos_ele1 * prev_ele_dir2_cos * cosf( azi_rad1 - hAlignState->previous_azi_dir2[band] ) + sin_ele1 * prev_ele_dir2_sin ) + + acosf( cos_ele2 * prev_ele_dir1_cos * cosf( azi_rad2 - hAlignState->previous_azi_dir1[band] ) + sin_ele2 * prev_ele_dir1_sin ); + } + } + else + { + /* 1dir */ + sin_ele1 = sinf( ele_rad1 ); + cos_ele1 = cosf( ele_rad1 ); + + azi_rad2 = 0.0f; + ele_rad2 = 0.0f; + + sin_ele2 = 0.0f; /* sin(0) */ + cos_ele2 = 1.0f; /* cos(0) */ + + diff_swap = 1.0f; + diff_no_swap = 0.0f; + } + + if ( n_dirs > 1 && diff_no_swap > diff_swap ) + { + /* swap the metadata of the two directions in this TF-tile */ + float tmp_val; + uint16_t tmp_int_val; + tmp_val = hMeta->directional_meta[0].azimuth[sf][band]; + hMeta->directional_meta[0].azimuth[sf][band] = hMeta->directional_meta[1].azimuth[sf][band]; + hMeta->directional_meta[1].azimuth[sf][band] = tmp_val; + + tmp_val = hMeta->directional_meta[0].elevation[sf][band]; + hMeta->directional_meta[0].elevation[sf][band] = hMeta->directional_meta[1].elevation[sf][band]; + hMeta->directional_meta[1].elevation[sf][band] = tmp_val; + tmp_int_val = hMeta->directional_meta[0].spherical_index[sf][band]; + hMeta->directional_meta[0].spherical_index[sf][band] = hMeta->directional_meta[1].spherical_index[sf][band]; + hMeta->directional_meta[1].spherical_index[sf][band] = tmp_int_val; + tmp_val = hMeta->directional_meta[0].energy_ratio[sf][band]; + hMeta->directional_meta[0].energy_ratio[sf][band] = hMeta->directional_meta[1].energy_ratio[sf][band]; + hMeta->directional_meta[1].energy_ratio[sf][band] = tmp_val; + + tmp_val = hMeta->directional_meta[0].spread_coherence[sf][band]; + hMeta->directional_meta[0].spread_coherence[sf][band] = hMeta->directional_meta[1].spread_coherence[sf][band]; + hMeta->directional_meta[1].spread_coherence[sf][band] = tmp_val; + + hAlignState->previous_azi_dir1[band] = azi_rad2; + hAlignState->previous_ele_dir1[band] = ele_rad2; + + hAlignState->previous_azi_dir2[band] = azi_rad1; + hAlignState->previous_ele_dir2[band] = ele_rad1; + + prev_ele_dir1_cos = cos_ele2; + prev_ele_dir1_sin = sin_ele2; + + prev_ele_dir2_cos = cos_ele1; + prev_ele_dir2_sin = sin_ele1; + } + else + { + hAlignState->previous_azi_dir1[band] = azi_rad1; + hAlignState->previous_ele_dir1[band] = ele_rad1; + + hAlignState->previous_azi_dir2[band] = azi_rad2; + hAlignState->previous_ele_dir2[band] = ele_rad2; + + prev_ele_dir1_cos = cos_ele1; + prev_ele_dir1_sin = sin_ele1; + + prev_ele_dir2_cos = cos_ele2; + prev_ele_dir2_sin = sin_ele2; + } + } /* sf */ + } /* band */ + + return; +} +#endif + +/*-------------------------------------------------------------------* + * ivas_merge_masa_metadata() + * + * + *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_merge_masa_metadata_fx( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA enc handle. source for MASA metadata and combined metadata will be here */ + OMASA_SPATIAL_META_HANDLE hOMasaMeta /* i : ISM-object metadata to be merged with the MASA metadata */ +) +{ + Word16 sf, band; + UWord8 numCodingBands; + UWord8 numDirections; + UWord8 numSf; + MASA_METADATA_HANDLE hMeta; + Word16 energyTimesRatioMASA_e[2]; + Word16 total_diff_nrg_e; + Word16 energyMerged_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 energyTimesRatioISM_fx; /*energyTimesRatioISM_e*/ + Word16 energyTimesRatioISM_e; + Word32 energyTimesRatioMASA_fx[2]; /*energyTimesRatioMASA_e*/ + Word32 total_diff_nrg_fx; + Word32 eneBand_fx; /*eneBand_e*/ + Word16 eneBand_e; + Word32 energyMerged_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /*energyMerged_e*/ + Word32 temp1 /*temp1_e*/, temp2 /*temp2_e*/; + Word16 temp1_e, temp2_e; + + numCodingBands = hMasa->config.numCodingBands; + numDirections = hMasa->config.numberOfDirections; + IF( EQ_16( hMasa->config.joinedSubframes, TRUE ) ) + { + numSf = 1; + } + ELSE + { + numSf = 4; + } + move16(); + move16(); + move16(); hMeta = &( hMasa->masaMetadata ); - n_dirs = (UWord8) add( hMeta->descriptive_meta.numberOfDirections, 1 ); /* 1-based */ - move16(); - FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + FOR( sf = 0; sf < numSf; sf++ ) + { + FOR( band = 0; band < numCodingBands; band++ ) + { + Word16 merge_dest; + Word32 dir_sum_fx; /*dir_sum_e*/ + Word16 dir_sum_e; + UWord8 band_n_dirs; + test(); + test(); + IF( EQ_16( numDirections, 1 ) || ( EQ_16( numDirections, 2 ) && hMasa->data.twoDirBands[band] == 0 ) ) + { + band_n_dirs = 1; + } + ELSE + { + band_n_dirs = 2; + } + move16(); + + /* Compute energies */ + eneBand_fx = hMasa->data.energy_fx[sf][band]; + eneBand_e = hMasa->data.energy_e[sf][band]; + move32(); + move16(); + energyMerged_fx[sf][band] = BASOP_Util_Add_Mant32Exp( eneBand_fx, eneBand_e, hMasa->data.hOmasaData->energy_ism_fx[sf][band], hMasa->data.hOmasaData->energy_ism_fx_e[sf][band], &energyMerged_e[sf][band] ); + move32(); + + /* Compute weights */ + energyTimesRatioMASA_fx[0] = Mpy_32_32( eneBand_fx, hMeta->directional_meta[0].energy_ratio_fx[sf][band] ); + energyTimesRatioMASA_e[0] = add( eneBand_e, 1 ); + move32(); + move16(); + IF( EQ_16( band_n_dirs, 2 ) ) + { + energyTimesRatioMASA_fx[1] = Mpy_32_32( eneBand_fx, hMeta->directional_meta[1].energy_ratio_fx[sf][band] ); + energyTimesRatioMASA_e[1] = add( eneBand_e, 1 ); + } + ELSE + { + energyTimesRatioMASA_fx[1] = 0; + energyTimesRatioMASA_e[1] = 0; + } + move32(); + move16(); + + /* target is original MASA diffuseness */ + total_diff_nrg_fx = Mpy_32_32( eneBand_fx, hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] ); + total_diff_nrg_e = add( eneBand_e, 1 ); + + /* criterion is mean of ISM ratio and new ratio */ + temp1 = BASOP_Util_Add_Mant32Exp( L_add( EPSILON_FX, eneBand_fx ), eneBand_e, hMasa->data.hOmasaData->energy_ism_fx[sf][band], hMasa->data.hOmasaData->energy_ism_fx_e[sf][band], &temp1_e ); /* EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band]*/ + temp2 = L_deposit_h( BASOP_Util_Divide3232_Scale( total_diff_nrg_fx, temp1, &temp2_e ) ); /*temp2_e*/ /*total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] )*/ + temp2_e = add( temp2_e, sub( total_diff_nrg_e, temp1_e ) ); + IF( temp2_e < 0 ) + { + temp2 = L_shl( temp2, temp2_e ); + temp2_e = 0; + move16(); + } + temp2 = L_sub( L_shl_sat( 1, sub( 31, temp2_e ) ), temp2 ); /*( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] ) )*/ + temp2 = BASOP_Util_Add_Mant32Exp( hOMasaMeta->directional_meta[0].energy_ratio_fx[sf][band], 1, temp2, temp2_e, &temp2_e ); /*( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] ) )*/ + energyTimesRatioISM_fx = Mpy_32_32( L_shr( temp2, 1 ), hMasa->data.hOmasaData->energy_ism_fx[sf][band] ); /*energyTimesRatioISM_e*/ + energyTimesRatioISM_e = add( temp2_e, hMasa->data.hOmasaData->energy_ism_fx_e[sf][band] ); + /*energyTimesRatioISM = ( hOMasaMeta->directional_meta[0].energy_ratio[sf][band] + ( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] ) ) ) / 2.0f * hMasa->data.hOmasaData->energy_ism[sf][band];*/ + + /* Determine combined metadata based on the weights */ + merge_dest = -1; + move16(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( band_n_dirs, 1 ) && EQ_16( BASOP_Util_Cmp_Mant32Exp( energyTimesRatioMASA_fx[0], energyTimesRatioMASA_e[0], energyTimesRatioISM_fx, energyTimesRatioISM_e ), -1 ) ) || + ( EQ_16( band_n_dirs, 2 ) && EQ_16( BASOP_Util_Cmp_Mant32Exp( energyTimesRatioMASA_fx[0], energyTimesRatioMASA_e[0], energyTimesRatioMASA_fx[1], energyTimesRatioMASA_e[1] ), -1 ) && EQ_16( BASOP_Util_Cmp_Mant32Exp( energyTimesRatioMASA_fx[0], energyTimesRatioMASA_e[0], energyTimesRatioISM_fx, energyTimesRatioISM_e ), -1 ) ) ) + { + /* 1dir and ISM the most energetic, or 2dir and ISM the more energetic than MASA1 */ + merge_dest = 0; + } + ELSE IF( EQ_16( band_n_dirs, 2 ) && NE_16( BASOP_Util_Cmp_Mant32Exp( energyTimesRatioMASA_fx[1], energyTimesRatioMASA_e[1], energyTimesRatioMASA_fx[0], energyTimesRatioMASA_e[0] ), 1 ) && EQ_16( BASOP_Util_Cmp_Mant32Exp( energyTimesRatioMASA_fx[1], energyTimesRatioMASA_e[1], energyTimesRatioISM_fx, energyTimesRatioISM_e ), -1 ) ) + { + /* 2dir and ISM the most energetic and MASA2 the least energetic */ + merge_dest = 1; + } + move16(); + + IF( merge_dest >= 0 ) /* replace one MASA with ISM */ + { + hMeta->directional_meta[merge_dest].azimuth_fx[sf][band] = hOMasaMeta->directional_meta[0].azimuth_fx[sf][band]; /*q22*/ + hMeta->directional_meta[merge_dest].elevation_fx[sf][band] = hOMasaMeta->directional_meta[0].elevation_fx[sf][band]; /*q22*/ + move32(); + move32(); + /* limit with the earlier direct-energy ratio */ + dir_sum_fx = temp2; /* new dir ratio */ + dir_sum_e = temp2_e; + move32(); + move16(); + /*dir_sum = 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] )*/ + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( dir_sum_fx, dir_sum_e, hOMasaMeta->directional_meta[0].energy_ratio_fx[sf][band], 1 ), -1 ) ) + { + hMeta->directional_meta[merge_dest].energy_ratio_fx[sf][band] = L_shl( dir_sum_fx, sub( dir_sum_e, 1 ) ); /*scaling to Q30*/ + } + ELSE + { + hMeta->directional_meta[merge_dest].energy_ratio_fx[sf][band] = hOMasaMeta->directional_meta[0].energy_ratio_fx[sf][band]; /*q30*/ + } + /* clip with original ISM dir */ + hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_sub( ONE_IN_Q30, hMeta->directional_meta[merge_dest].energy_ratio_fx[sf][band] ); /*q30*/ + move32(); + move32(); /*hMeta->directional_meta[merge_dest].energy_ratio_fx*/ + + IF( hMasa->config.useCoherence ) + { + hMeta->directional_meta[merge_dest].spread_coherence_fx[sf][band] = hOMasaMeta->directional_meta[0].spread_coherence_fx[sf][band]; /*q15*/ + hMeta->common_meta.surround_coherence_fx[sf][band] = hOMasaMeta->common_meta.surround_coherence_fx[sf][band]; /*q15*/ + move16(); + move16(); + } + + /* recompute direct energy ratios to match the diffuse ratio */ + Word32 direct_quota_fx, direct_scaler_fx; + Word16 direct_scaler_e; + direct_quota_fx = L_sub( ONE_IN_Q30, hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] ); + IF( EQ_16( band_n_dirs, 1 ) ) + { + hMeta->directional_meta[0].energy_ratio_fx[sf][band] = direct_quota_fx; /*q30*/ + move32(); + } + ELSE + { + dir_sum_fx = L_add( hMeta->directional_meta[0].energy_ratio_fx[sf][band], hMeta->directional_meta[1].energy_ratio_fx[sf][band] ); /*q30*/ + direct_scaler_fx = BASOP_Util_Divide3232_Scale( direct_quota_fx, L_add( EPSILON_FX, dir_sum_fx ), &direct_scaler_e ); + direct_scaler_fx = L_shl( direct_scaler_fx, direct_scaler_e ); /*q31*/ + direct_scaler_e = 0; + move16(); + hMeta->directional_meta[0].energy_ratio_fx[sf][band] = Mpy_32_32( direct_scaler_fx, hMeta->directional_meta[0].energy_ratio_fx[sf][band] ); /*q30*/ + hMeta->directional_meta[1].energy_ratio_fx[sf][band] = Mpy_32_32( direct_scaler_fx, hMeta->directional_meta[0].energy_ratio_fx[sf][band] ); /*q30*/ + move32(); + move32(); + } + } + } + } + + FOR( sf = 0; sf < numSf; sf++ ) { - UWord8 sf; - Word16 diff_swap_fx; - Word16 diff_no_swap_fx; + FOR( band = 0; band < numCodingBands; band++ ) + { + hMasa->data.energy_fx[sf][band] = energyMerged_fx[sf][band]; + hMasa->data.energy_e[sf][band] = energyMerged_e[sf][band]; + move32(); + move16(); + } + } - /* trade 2*(cos+sin) against storing the values between frames */ - Word16 prev_ele_dir1_sin_fx, prev_ele_dir2_sin_fx; - Word16 prev_ele_dir1_cos_fx, prev_ele_dir2_cos_fx; + return; +} +#else - prev_ele_dir1_sin_fx = getSineWord16R2( extract_l( Mpy_32_32( hAlignState->previous_ele_dir1_fx[band], 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ - prev_ele_dir2_sin_fx = getSineWord16R2( extract_l( Mpy_32_32( hAlignState->previous_ele_dir2_fx[band], 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ +void ivas_merge_masa_metadata( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA enc handle. source for MASA metadata and combined metadata will be here */ + OMASA_SPATIAL_META_HANDLE hOMasaMeta /* i : ISM-object metadata to be merged with the MASA metadata */ +) +{ + int16_t sf, band; + uint8_t numCodingBands; + uint8_t numDirections; + uint8_t numSf; + MASA_METADATA_HANDLE hMeta; + float energyTimesRatioISM; + float energyTimesRatioMASA[2]; + float total_diff_nrg; + float eneBand; + float energyMerged[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - prev_ele_dir1_cos_fx = getCosWord16R2( extract_l( Mpy_32_32( hAlignState->previous_ele_dir1_fx[band], 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ - prev_ele_dir2_cos_fx = getCosWord16R2( extract_l( Mpy_32_32( hAlignState->previous_ele_dir2_fx[band], 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + numCodingBands = hMasa->config.numCodingBands; + numDirections = hMasa->config.numberOfDirections; + numSf = hMasa->config.joinedSubframes == TRUE ? 1 : 4; + hMeta = &( hMasa->masaMetadata ); - FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + for ( sf = 0; sf < numSf; sf++ ) + { + for ( band = 0; band < numCodingBands; band++ ) { - Word32 azi_rad1_fx, ele_rad1_fx; - Word32 azi_rad2_fx, ele_rad2_fx; - Word16 cos_ele1_fx, cos_ele2_fx; - Word16 sin_ele1_fx, sin_ele2_fx; - Word16 temp1; - Word32 temp2; - Word16 temp1_e; + int16_t merge_dest; + float dir_sum; + uint8_t band_n_dirs; + if ( numDirections == 1 || ( numDirections == 2 && hMasa->data.twoDirBands[band] == 0 ) ) + { + band_n_dirs = 1; + } + else + { + band_n_dirs = 2; + } + /* Compute energies */ + eneBand = hMasa->data.energy[sf][band]; + energyMerged[sf][band] = eneBand + hMasa->data.hOmasaData->energy_ism[sf][band]; - azi_rad1_fx = Mpy_32_16_1( hMeta->directional_meta[0].azimuth_fx[sf][band], 572 /*PI_OVER_180 q15*/ ); /*q22*/ - ele_rad1_fx = Mpy_32_16_1( hMeta->directional_meta[0].elevation_fx[sf][band], 572 /*PI_OVER_180 q15*/ ); /*q22*/ + /* Compute weights */ + energyTimesRatioMASA[0] = eneBand * hMeta->directional_meta[0].energy_ratio[sf][band]; + if ( band_n_dirs == 2 ) + { + energyTimesRatioMASA[1] = eneBand * hMeta->directional_meta[1].energy_ratio[sf][band]; + } + else + { + energyTimesRatioMASA[1] = 0.0f; + } - IF( GT_16( n_dirs, 1 ) ) + /* target is original MASA diffuseness */ + total_diff_nrg = eneBand * hMeta->common_meta.diffuse_to_total_ratio[sf][band]; + + /* criterion is mean of ISM ratio and new ratio */ + energyTimesRatioISM = ( hOMasaMeta->directional_meta[0].energy_ratio[sf][band] + ( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] ) ) ) / 2.0f * hMasa->data.hOmasaData->energy_ism[sf][band]; + + /* Determine combined metadata based on the weights */ + merge_dest = -1; + if ( ( band_n_dirs == 1 && energyTimesRatioMASA[0] < energyTimesRatioISM ) || + ( band_n_dirs == 2 && energyTimesRatioMASA[0] < energyTimesRatioMASA[1] && energyTimesRatioMASA[0] < energyTimesRatioISM ) ) { - azi_rad2_fx = Mpy_32_16_1( hMeta->directional_meta[1].azimuth_fx[sf][band], 572 /*PI_OVER_180 q15*/ ); /*q22*/ - ele_rad2_fx = Mpy_32_16_1( hMeta->directional_meta[1].elevation_fx[sf][band], 572 /*PI_OVER_180 q15*/ ); /*q22*/ + /* 1dir and ISM the most energetic, or 2dir and ISM the more energetic than MASA1 */ + merge_dest = 0; + } + else if ( band_n_dirs == 2 && energyTimesRatioMASA[1] <= energyTimesRatioMASA[0] && energyTimesRatioMASA[1] < energyTimesRatioISM ) + { + /* 2dir and ISM the most energetic and MASA2 the least energetic */ + merge_dest = 1; + } - test(); - test(); - test(); - test(); - test(); - test(); - /* quick checks to detect constant data and earlier flip */ - IF( LT_32( L_abs( L_sub( azi_rad1_fx, hAlignState->previous_azi_dir1_fx[band] ) ), EPSILON_FX ) && - LT_32( L_abs( L_sub( azi_rad2_fx, hAlignState->previous_azi_dir2_fx[band] ) ), EPSILON_FX ) && - LT_32( L_abs( L_sub( ele_rad1_fx, hAlignState->previous_ele_dir1_fx[band] ) ), EPSILON_FX ) && - LT_32( L_abs( L_sub( ele_rad2_fx, hAlignState->previous_ele_dir2_fx[band] ) ), EPSILON_FX ) ) + if ( merge_dest >= 0 ) /* replace one MASA with ISM */ + { + hMeta->directional_meta[merge_dest].azimuth[sf][band] = hOMasaMeta->directional_meta[0].azimuth[sf][band]; + hMeta->directional_meta[merge_dest].elevation[sf][band] = hOMasaMeta->directional_meta[0].elevation[sf][band]; + /* limit with the earlier direct-energy ratio */ + dir_sum = 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] ); /* new dir ratio */ + hMeta->directional_meta[merge_dest].energy_ratio[sf][band] = min( dir_sum, hOMasaMeta->directional_meta[0].energy_ratio[sf][band] ); /* clip with original ISM dir */ + hMeta->common_meta.diffuse_to_total_ratio[sf][band] = 1.0f - hMeta->directional_meta[merge_dest].energy_ratio[sf][band]; + + if ( hMasa->config.useCoherence ) { - diff_swap_fx = ONE_IN_Q13; /*1 q13*/ - diff_no_swap_fx = 0; - /* cached values that will be used for the short-cuts and over-written by the real computations, if done */ - sin_ele1_fx = prev_ele_dir1_sin_fx; /*q15*/ - sin_ele2_fx = prev_ele_dir2_sin_fx; /*q15*/ - cos_ele1_fx = prev_ele_dir1_cos_fx; /*q15*/ - cos_ele2_fx = prev_ele_dir2_cos_fx; /*q15*/ - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); + hMeta->directional_meta[merge_dest].spread_coherence[sf][band] = hOMasaMeta->directional_meta[0].spread_coherence[sf][band]; + hMeta->common_meta.surround_coherence[sf][band] = hOMasaMeta->common_meta.surround_coherence[sf][band]; } - ELSE IF( LT_32( L_abs( L_sub( azi_rad1_fx, hAlignState->previous_azi_dir2_fx[band] ) ), EPSILON_FX ) && - LT_32( L_abs( L_sub( azi_rad2_fx, hAlignState->previous_azi_dir1_fx[band] ) ), EPSILON_FX ) && - LT_32( L_abs( L_sub( ele_rad1_fx, hAlignState->previous_ele_dir2_fx[band] ) ), EPSILON_FX ) && - LT_32( L_abs( L_sub( ele_rad2_fx, hAlignState->previous_ele_dir1_fx[band] ) ), EPSILON_FX ) ) + + /* recompute direct energy ratios to match the diffuse ratio */ + float direct_quota, direct_scaler; + direct_quota = 1.0f - hMeta->common_meta.diffuse_to_total_ratio[sf][band]; + if ( band_n_dirs == 1 ) { - diff_swap_fx = 0; - diff_no_swap_fx = ONE_IN_Q13; /*1.0 q13*/ - /* cached values that will be used for the short-cuts and over-written by the real computations, if done */ - sin_ele1_fx = prev_ele_dir2_sin_fx; /*q15*/ - sin_ele2_fx = prev_ele_dir1_sin_fx; /*q15*/ - cos_ele1_fx = prev_ele_dir2_cos_fx; /*q15*/ - cos_ele2_fx = prev_ele_dir1_cos_fx; /*q15*/ - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); + hMeta->directional_meta[0].energy_ratio[sf][band] = direct_quota; } - ELSE + else { - /* angular distance of the two vectors */ - /* pre-compute values for re-use */ - sin_ele1_fx = getSineWord16R2( extract_l( Mpy_32_32( ele_rad1_fx, 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ - sin_ele2_fx = getSineWord16R2( extract_l( Mpy_32_32( ele_rad2_fx, 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + dir_sum = hMeta->directional_meta[0].energy_ratio[sf][band] + hMeta->directional_meta[1].energy_ratio[sf][band]; + direct_scaler = direct_quota / ( EPSILON + dir_sum ); + hMeta->directional_meta[0].energy_ratio[sf][band] *= direct_scaler; + hMeta->directional_meta[1].energy_ratio[sf][band] *= direct_scaler; + } + } + } + } - cos_ele1_fx = getCosWord16R2( extract_l( Mpy_32_32( ele_rad1_fx, 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ - cos_ele2_fx = getCosWord16R2( extract_l( Mpy_32_32( ele_rad2_fx, 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + for ( sf = 0; sf < numSf; sf++ ) + { + for ( band = 0; band < numCodingBands; band++ ) + { + hMasa->data.energy[sf][band] = energyMerged[sf][band]; + } + } - temp1 = getCosWord16R2( extract_l( Mpy_32_32( L_sub( azi_rad1_fx, hAlignState->previous_azi_dir1_fx[band] ), 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ - temp1 = mult( mult( temp1, cos_ele1_fx ) /*q31*/, prev_ele_dir1_cos_fx /*q15*/ ); /*q15*/ - temp1 = add_sat( mult( sin_ele1_fx, prev_ele_dir1_sin_fx ), temp1 ); /*q15*/ - temp1_e = 1; /*stores expoenent for square root operation*/ - move16(); - temp2 = Sqrt32( L_sub( ONE_IN_Q30, L_mult0( temp1, temp1 ) ), &temp1_e ); /*31-temp1_e*/ - temp1 = BASOP_util_atan2( temp2, abs_s( temp1 ), sub( temp1_e, 16 ) ); /*q13*/ - diff_no_swap_fx = temp1; /*q13*/ + return; +} +#endif +#ifdef IVAS_FLOAT_FIXED +static void quantize_ratio_ism_vector_ivas_fx( + const Word16 *ratio_ism, /* ratio_ism_e */ + Word16 ratio_ism_e, + Word16 *idx, /* Q0 */ + const Word16 nchan_ism, + const Word32 masa_to_total_energy_ratio, + const Word16 idx_sep_object ) +{ + Word16 i, j, best_i, best_i2; + Word16 dist, div, tmp, dist2, best_dist, temp, temp_e, tmp_e, idx_e, best_dist_e, dist_e, dist2_e; + Word16 part_idx_sum, max_sum_idx; + Word16 ratio_ism_loc[MAX_NUM_OBJECTS]; + Word16 no_ism_loc; - temp1 = getCosWord16R2( extract_l( Mpy_32_32( L_sub( azi_rad2_fx, hAlignState->previous_azi_dir2_fx[band] ), 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ - temp1 = mult( mult( temp1, cos_ele2_fx ) /*q31*/, prev_ele_dir2_cos_fx /*q15*/ ); /*q15*/ - temp1 = add_sat( mult( sin_ele2_fx, prev_ele_dir2_sin_fx ), temp1 ); /*q15*/ - temp1_e = 1; /*stores expoenent for square root operation*/ - move16(); - temp2 = Sqrt32( L_sub( ONE_IN_Q30, L_mult0( temp1, temp1 ) ), &temp1_e ); /*31-temp1_e*/ - temp1 = BASOP_util_atan2( temp2, abs_s( temp1 ), sub( temp1_e, 16 ) ); /*q13*/ - diff_no_swap_fx = add( diff_no_swap_fx, temp1 ); /*q13*/ + max_sum_idx = sub( shl( 1, PARAM_ISM_POW_RATIO_NBITS ), 1 ); - temp1 = getCosWord16R2( extract_l( Mpy_32_32( L_sub( azi_rad1_fx, hAlignState->previous_azi_dir2_fx[band] ), 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ - temp1 = mult( mult( temp1, cos_ele1_fx ) /*q31*/, prev_ele_dir2_cos_fx /*q15*/ ); /*q15*/ - temp1 = add_sat( mult( sin_ele1_fx, prev_ele_dir2_sin_fx ), temp1 ); /*q15*/ - temp1_e = 1; /*stores expoenent for square root operation*/ - move16(); - temp2 = Sqrt32( L_sub( ONE_IN_Q30, L_mult0( temp1, temp1 ) ), &temp1_e ); /*31-temp1_e*/ - temp1 = BASOP_util_atan2( temp2, abs_s( temp1 ), sub( temp1_e, 16 ) ); /*q13*/ - diff_swap_fx = temp1; /*q13*/ + test(); + IF( GT_16( idx_sep_object, -1 ) ) + { + temp = BASOP_Util_Divide1616_Scale( 1, max_sum_idx, &temp_e ); + BASOP_Util_Add_MantExp( ratio_ism[idx_sep_object], ratio_ism_e, negate( temp ), temp_e, &tmp ); - temp1 = getCosWord16R2( extract_l( Mpy_32_32( L_sub( azi_rad2_fx, hAlignState->previous_azi_dir1_fx[band] ), 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ - temp1 = mult( mult( temp1, cos_ele2_fx ) /*q31*/, prev_ele_dir1_cos_fx /*q15*/ ); /*q15*/ - temp1 = add_sat( mult( sin_ele2_fx, prev_ele_dir1_sin_fx ), temp1 ); /*q15*/ - temp1_e = 1; /*stores expoenent for square root operation*/ - move16(); - temp2 = Sqrt32( L_sub( ONE_IN_Q30, L_mult0( temp1, temp1 ) ), &temp1_e ); /*31-temp1_e*/ - temp1 = BASOP_util_atan2( temp2, abs_s( temp1 ), sub( temp1_e, 16 ) ); /*q13*/ - diff_swap_fx = add( diff_swap_fx, temp1 ); /*q13*/ - } - } - ELSE - { - /* 1dir */ - sin_ele1_fx = getSineWord16R2( extract_l( Mpy_32_32( ele_rad1_fx, 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ - cos_ele1_fx = getCosWord16R2( extract_l( Mpy_32_32( ele_rad1_fx, 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ + test(); + IF( tmp < 0 ) + { + /* take it out from quantize function */ + Copy( ratio_ism, ratio_ism_loc, idx_sep_object ); + Copy( &ratio_ism[idx_sep_object + 1], &ratio_ism_loc[idx_sep_object], nchan_ism - idx_sep_object - 1 ); + no_ism_loc = sub( nchan_ism, 1 ); + } + ELSE + { + no_ism_loc = nchan_ism; + move16(); + Copy( ratio_ism, ratio_ism_loc, nchan_ism ); + } + } + ELSE + { + no_ism_loc = nchan_ism; + move16(); + Copy( ratio_ism, ratio_ism_loc, nchan_ism ); + } - azi_rad2_fx = 0; - ele_rad2_fx = 0; - move32(); - move32(); + test(); + IF( GT_16( nchan_ism, 1 ) ) + { + test(); + IF( GE_32( masa_to_total_energy_ratio, MASA2TOTAL_THR_Q30 ) ) + { + distribute_evenly_ism_fx( idx, max_sum_idx, nchan_ism ); + } + ELSE + { + test(); + IF( GT_16( no_ism_loc, 1 ) ) + { - sin_ele2_fx = 0; /* sin(0) */ - cos_ele2_fx = MAX_16; /* cos(0) in Q15*/ + dist = 0; + dist_e = 0; + div = div_s( 1, max_sum_idx ); // Q15 move16(); move16(); - diff_swap_fx = ONE_IN_Q13; /*1.0 in Q13*/ - diff_no_swap_fx = 0; - move16(); + part_idx_sum = 0; move16(); - } - - test(); - IF( GT_16( n_dirs, 1 ) && GT_16( diff_no_swap_fx, diff_swap_fx ) ) - { - /* swap the metadata of the two directions in this TF-tile */ - Word32 tmp_val; - Word16 tmp_val_16; - UWord16 tmp_int_val; - tmp_val = hMeta->directional_meta[0].azimuth_fx[sf][band]; /*q22*/ - hMeta->directional_meta[0].azimuth_fx[sf][band] = hMeta->directional_meta[1].azimuth_fx[sf][band]; /*q22*/ - hMeta->directional_meta[1].azimuth_fx[sf][band] = tmp_val; /*q22*/ - move32(); - move32(); - move32(); - - tmp_val = hMeta->directional_meta[0].elevation_fx[sf][band]; /*q22*/ - hMeta->directional_meta[0].elevation_fx[sf][band] = hMeta->directional_meta[1].elevation_fx[sf][band]; /*q22*/ - hMeta->directional_meta[1].elevation_fx[sf][band] = tmp_val; /*q22*/ - move32(); - move32(); - move32(); - tmp_int_val = hMeta->directional_meta[0].spherical_index[sf][band]; /*q0*/ - hMeta->directional_meta[0].spherical_index[sf][band] = hMeta->directional_meta[1].spherical_index[sf][band]; /*q0*/ - hMeta->directional_meta[1].spherical_index[sf][band] = tmp_int_val; /*q0*/ - move32(); - move32(); - move32(); + FOR( i = 0; i < no_ism_loc; i++ ) + { + idx[i] = mult( ratio_ism_loc[i], max_sum_idx ); // exponent : ratio_ism_e + 15 + move16(); + idx[i] = shl( idx[i], sub( add( ratio_ism_e, 15 ), 15 ) ); // Q0 + move16(); + part_idx_sum = add( part_idx_sum, idx[i] ); - tmp_val = hMeta->directional_meta[0].energy_ratio_fx[sf][band]; /*q30*/ - hMeta->directional_meta[0].energy_ratio_fx[sf][band] = hMeta->directional_meta[1].energy_ratio_fx[sf][band]; /*q30*/ - hMeta->directional_meta[1].energy_ratio_fx[sf][band] = tmp_val; /*q30*/ - move32(); - move32(); - move32(); + tmp_e = BASOP_Util_Add_MantExp( ratio_ism_loc[i], ratio_ism_e, negate( imult1616( idx[i], div ) ), 0, &tmp ); // tmp_e + dist_e = BASOP_Util_Add_MantExp( dist, dist_e, mult( tmp, tmp ), add( tmp_e, tmp_e ), &dist ); // dist_e + } - tmp_val_16 = hMeta->directional_meta[0].spread_coherence_fx[sf][band]; /*q15*/ - hMeta->directional_meta[0].spread_coherence_fx[sf][band] = hMeta->directional_meta[1].spread_coherence_fx[sf][band]; /*q15*/ - hMeta->directional_meta[1].spread_coherence_fx[sf][band] = tmp_val_16; /*q15*/ + best_dist = dist; + best_dist_e = dist_e; + best_i2 = -1; move16(); move16(); move16(); - hAlignState->previous_azi_dir1_fx[band] = azi_rad2_fx; /*q22*/ - hAlignState->previous_ele_dir1_fx[band] = ele_rad2_fx; /*q22*/ - move32(); - move32(); + WHILE( LT_16( part_idx_sum, max_sum_idx ) ) + { + best_i = -1; + move16(); + /* check which index to increase by 1 for a possible improvement */ - hAlignState->previous_azi_dir2_fx[band] = azi_rad1_fx; /*q22*/ - hAlignState->previous_ele_dir2_fx[band] = ele_rad1_fx; /*q22*/ - move32(); - move32(); + FOR( i = 0; i < no_ism_loc; i++ ) + { + idx[i] = add( idx[i], 1 ); + move16(); + dist2 = 0; + dist2_e = 0; + move16(); + move16(); - prev_ele_dir1_cos_fx = cos_ele2_fx; /*q15*/ - prev_ele_dir1_sin_fx = sin_ele2_fx; /*q15*/ - move16(); - move16(); + FOR( j = 0; j < no_ism_loc; j++ ) + { + Word32 temp1 = L_mult( idx[i], div ); // Q : 15 + 0 + 1 + Word16 temp1_n = norm_l( temp1 ); + Word16 temp1_16 = extract_h( L_shl( temp1, temp1_n ) ); // Q : Q + temp1_n - 16 + tmp_e = BASOP_Util_Add_MantExp( ratio_ism_loc[i], ratio_ism_e, negate( temp1_16 ), sub( 15, temp1_n ), &tmp ); // tmp_e + dist2_e = BASOP_Util_Add_MantExp( dist2, dist2_e, mult_sat( tmp, tmp ), add( tmp_e, tmp_e ), &dist2 ); // dist_e + } - prev_ele_dir2_cos_fx = cos_ele1_fx; /*q15*/ - prev_ele_dir2_sin_fx = sin_ele1_fx; /*q15*/ - move16(); - move16(); + BASOP_Util_Add_MantExp( dist2, dist2_e, negate( best_dist ), best_dist_e, &tmp ); + test(); + IF( tmp < 0 ) + { + best_i2 = best_i; + best_i = i; + best_dist = dist2; + best_dist_e = dist2_e; + move16(); + move16(); + move16(); + move16(); + } + idx[i] = sub( idx[i], 1 ); + move16(); + } + + test(); + IF( GT_16( best_i, -1 ) ) + { + idx[best_i] = add( idx[best_i], 1 ); + move16(); + part_idx_sum = add( part_idx_sum, 1 ); + } + ELSE + { + test(); + IF( GT_16( best_i2, -1 ) ) + { + idx[best_i2] = add( idx[best_i2], 1 ); + move16(); + part_idx_sum = add( part_idx_sum, 1 ); + } + ELSE + { + idx[no_ism_loc - 1] = add( idx[no_ism_loc - 1], sub( max_sum_idx, part_idx_sum ) ); + move16(); + part_idx_sum = max_sum_idx; + move16(); + } + } + } + assert( sum_s( idx, no_ism_loc ) == max_sum_idx ); } ELSE { - hAlignState->previous_azi_dir1_fx[band] = azi_rad1_fx; /*q22*/ - hAlignState->previous_ele_dir1_fx[band] = ele_rad1_fx; /*q22*/ - move32(); - move32(); - - hAlignState->previous_azi_dir2_fx[band] = azi_rad2_fx; /*q22*/ - hAlignState->previous_ele_dir2_fx[band] = ele_rad2_fx; /*q22*/ - move32(); - move32(); - - prev_ele_dir1_cos_fx = cos_ele1_fx; /*q15*/ - prev_ele_dir1_sin_fx = sin_ele1_fx; /*q15*/ - move16(); + idx[0] = max_sum_idx; move16(); + } - prev_ele_dir2_cos_fx = cos_ele2_fx; /*q15*/ - prev_ele_dir2_sin_fx = sin_ele2_fx; /*q15*/ - move16(); + test(); + IF( LT_16( no_ism_loc, nchan_ism ) ) + { + /* insert back the ratio of the separated object */ + FOR( i = nchan_ism - 1; i > idx_sep_object; i-- ) + { + idx[i] = idx[i - 1]; + move16(); + } + idx[idx_sep_object] = 0; move16(); } - } /* sf */ - } /* band */ + } + } + ELSE + { + // idx[0] = (int16_t) ( ( ratio_ism[0] ) * ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) + 0.5f ); + tmp = imult1616( ratio_ism[0], sub( shl( 1, PARAM_ISM_POW_RATIO_NBITS ), 1 ) ); // tmp_e + tmp_e = ratio_ism_e; + move16(); + idx_e = BASOP_Util_Add_MantExp( tmp, tmp_e, 16384 /* 0.5 in Q15 */, 0, &idx[0] ); // idx_e + idx[0] = shl( idx[0], sub( idx_e, 15 ) ); // Q0 + move16(); + } return; } #else -static void masa_metadata_direction_alignment( - MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder handle */ -) + +static void quantize_ratio_ism_vector( + const float *ratio_ism, + int16_t *idx, + const int16_t nchan_ism, + const float masa_to_total_energy_ratio, + const int16_t idx_sep_object ) { - uint8_t band, n_dirs; - MASA_DIR_ALIGN_HANDLE hAlignState; - MASA_METADATA_HANDLE hMeta; + int16_t i, j, best_i, best_i2; + float dist, div, tmp, dist2, best_dist; + int16_t part_idx_sum, max_sum_idx; + float ratio_ism_loc[MAX_NUM_OBJECTS]; + int16_t no_ism_loc; - hAlignState = &( hMasa->data.dir_align_state ); - hMeta = &( hMasa->masaMetadata ); + max_sum_idx = ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1; - n_dirs = hMeta->descriptive_meta.numberOfDirections + 1; /* 1-based */ - for ( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + if ( idx_sep_object > -1 ) { - uint8_t sf; - float diff_swap, diff_no_swap; - - /* trade 2*(cos+sin) against storing the values between frames */ - float prev_ele_dir1_sin, prev_ele_dir2_sin; - float prev_ele_dir1_cos, prev_ele_dir2_cos; - - prev_ele_dir1_sin = sinf( hAlignState->previous_ele_dir1[band] ); - prev_ele_dir2_sin = sinf( hAlignState->previous_ele_dir2[band] ); - - prev_ele_dir1_cos = cosf( hAlignState->previous_ele_dir1[band] ); - prev_ele_dir2_cos = cosf( hAlignState->previous_ele_dir2[band] ); + if ( ratio_ism[idx_sep_object] < 1.0f / (float) ( max_sum_idx ) ) + { + /* take it out from quantize function */ + mvr2r( ratio_ism, ratio_ism_loc, idx_sep_object ); + mvr2r( &ratio_ism[idx_sep_object + 1], &ratio_ism_loc[idx_sep_object], nchan_ism - idx_sep_object - 1 ); + no_ism_loc = nchan_ism - 1; + } + else + { + no_ism_loc = nchan_ism; + mvr2r( ratio_ism, ratio_ism_loc, nchan_ism ); + } + } + else + { + no_ism_loc = nchan_ism; + mvr2r( ratio_ism, ratio_ism_loc, nchan_ism ); + } - for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + if ( nchan_ism > 1 ) + { + if ( masa_to_total_energy_ratio >= MASA2TOTAL_THR ) { - float azi_rad1, ele_rad1; - float azi_rad2, ele_rad2; - float cos_ele1, cos_ele2; - float sin_ele1, sin_ele2; +#ifndef IVAS_FLOAT_FIXED + distribute_evenly_ism( idx, max_sum_idx, nchan_ism ); +#else + distribute_evenly_ism_fx( idx, max_sum_idx, nchan_ism ); +#endif + } + else + { + if ( no_ism_loc > 1 ) + { - azi_rad1 = hMeta->directional_meta[0].azimuth[sf][band] * PI_OVER_180; - ele_rad1 = hMeta->directional_meta[0].elevation[sf][band] * PI_OVER_180; + dist = 0.0f; + div = 1.0f / (float) ( max_sum_idx ); - if ( n_dirs > 1 ) - { - azi_rad2 = hMeta->directional_meta[1].azimuth[sf][band] * PI_OVER_180; - ele_rad2 = hMeta->directional_meta[1].elevation[sf][band] * PI_OVER_180; + part_idx_sum = 0; - /* quick checks to detect constant data and earlier flip */ - if ( fabsf( azi_rad1 - hAlignState->previous_azi_dir1[band] ) < EPSILON && - fabsf( azi_rad2 - hAlignState->previous_azi_dir2[band] ) < EPSILON && - fabsf( ele_rad1 - hAlignState->previous_ele_dir1[band] ) < EPSILON && - fabsf( ele_rad2 - hAlignState->previous_ele_dir2[band] ) < EPSILON ) - { - diff_swap = 1.0f; - diff_no_swap = 0.0f; - /* cached values that will be used for the short-cuts and over-written by the real computations, if done */ - sin_ele1 = prev_ele_dir1_sin; - sin_ele2 = prev_ele_dir2_sin; - cos_ele1 = prev_ele_dir1_cos; - cos_ele2 = prev_ele_dir2_cos; - } - else if ( fabsf( azi_rad1 - hAlignState->previous_azi_dir2[band] ) < EPSILON && - fabsf( azi_rad2 - hAlignState->previous_azi_dir1[band] ) < EPSILON && - fabsf( ele_rad1 - hAlignState->previous_ele_dir2[band] ) < EPSILON && - fabsf( ele_rad2 - hAlignState->previous_ele_dir1[band] ) < EPSILON ) + for ( i = 0; i < no_ism_loc; i++ ) { - diff_swap = 0.0f; - diff_no_swap = 1.0f; - /* cached values that will be used for the short-cuts and over-written by the real computations, if done */ - sin_ele1 = prev_ele_dir2_sin; - sin_ele2 = prev_ele_dir1_sin; - cos_ele1 = prev_ele_dir2_cos; - cos_ele2 = prev_ele_dir1_cos; + idx[i] = (int16_t) ( ( ratio_ism_loc[i] ) * ( max_sum_idx ) ); + part_idx_sum += idx[i]; + + tmp = ( ratio_ism_loc[i] - ( idx[i] * div ) ); + dist += ( tmp * tmp ); } - else + + best_dist = dist; + best_i2 = -1; + while ( part_idx_sum < max_sum_idx ) { - /* angular distance of the two vectors */ - /* pre-compute values for re-use */ - sin_ele1 = sinf( ele_rad1 ); - sin_ele2 = sinf( ele_rad2 ); + best_i = -1; + /* check which index to increase by 1 for a possible improvement */ - cos_ele1 = cosf( ele_rad1 ); - cos_ele2 = cosf( ele_rad2 ); + for ( i = 0; i < no_ism_loc; i++ ) + { + idx[i]++; + dist2 = 0.0f; - diff_no_swap = acosf( cos_ele1 * prev_ele_dir1_cos * cosf( azi_rad1 - hAlignState->previous_azi_dir1[band] ) + sin_ele1 * prev_ele_dir1_sin ) + - acosf( cos_ele2 * prev_ele_dir2_cos * cosf( azi_rad2 - hAlignState->previous_azi_dir2[band] ) + sin_ele2 * prev_ele_dir2_sin ); + for ( j = 0; j < no_ism_loc; j++ ) + { + tmp = ( ratio_ism_loc[i] - ( idx[i] * div ) ); + dist2 += ( tmp * tmp ); + } - diff_swap = acosf( cos_ele1 * prev_ele_dir2_cos * cosf( azi_rad1 - hAlignState->previous_azi_dir2[band] ) + sin_ele1 * prev_ele_dir2_sin ) + - acosf( cos_ele2 * prev_ele_dir1_cos * cosf( azi_rad2 - hAlignState->previous_azi_dir1[band] ) + sin_ele2 * prev_ele_dir1_sin ); + if ( dist2 < best_dist ) + { + best_i2 = best_i; + best_i = i; + best_dist = dist2; + } + idx[i]--; + } + if ( best_i > -1 ) + { + idx[best_i]++; + part_idx_sum++; + } + else + { + if ( best_i2 > -1 ) + { + idx[best_i2]++; + part_idx_sum++; + } + else + { + idx[no_ism_loc - 1] += max_sum_idx - part_idx_sum; + part_idx_sum = max_sum_idx; + } + } } + assert( sum_s( idx, no_ism_loc ) == max_sum_idx ); } else { - /* 1dir */ - sin_ele1 = sinf( ele_rad1 ); - cos_ele1 = cosf( ele_rad1 ); - - azi_rad2 = 0.0f; - ele_rad2 = 0.0f; - - sin_ele2 = 0.0f; /* sin(0) */ - cos_ele2 = 1.0f; /* cos(0) */ - - diff_swap = 1.0f; - diff_no_swap = 0.0f; + idx[0] = max_sum_idx; } - if ( n_dirs > 1 && diff_no_swap > diff_swap ) + if ( no_ism_loc < nchan_ism ) { - /* swap the metadata of the two directions in this TF-tile */ - float tmp_val; - uint16_t tmp_int_val; - tmp_val = hMeta->directional_meta[0].azimuth[sf][band]; - hMeta->directional_meta[0].azimuth[sf][band] = hMeta->directional_meta[1].azimuth[sf][band]; - hMeta->directional_meta[1].azimuth[sf][band] = tmp_val; - - tmp_val = hMeta->directional_meta[0].elevation[sf][band]; - hMeta->directional_meta[0].elevation[sf][band] = hMeta->directional_meta[1].elevation[sf][band]; - hMeta->directional_meta[1].elevation[sf][band] = tmp_val; - tmp_int_val = hMeta->directional_meta[0].spherical_index[sf][band]; - hMeta->directional_meta[0].spherical_index[sf][band] = hMeta->directional_meta[1].spherical_index[sf][band]; - hMeta->directional_meta[1].spherical_index[sf][band] = tmp_int_val; - tmp_val = hMeta->directional_meta[0].energy_ratio[sf][band]; - hMeta->directional_meta[0].energy_ratio[sf][band] = hMeta->directional_meta[1].energy_ratio[sf][band]; - hMeta->directional_meta[1].energy_ratio[sf][band] = tmp_val; - - tmp_val = hMeta->directional_meta[0].spread_coherence[sf][band]; - hMeta->directional_meta[0].spread_coherence[sf][band] = hMeta->directional_meta[1].spread_coherence[sf][band]; - hMeta->directional_meta[1].spread_coherence[sf][band] = tmp_val; - - hAlignState->previous_azi_dir1[band] = azi_rad2; - hAlignState->previous_ele_dir1[band] = ele_rad2; - - hAlignState->previous_azi_dir2[band] = azi_rad1; - hAlignState->previous_ele_dir2[band] = ele_rad1; - - prev_ele_dir1_cos = cos_ele2; - prev_ele_dir1_sin = sin_ele2; - - prev_ele_dir2_cos = cos_ele1; - prev_ele_dir2_sin = sin_ele1; + /* insert back the ratio of the separated object */ + for ( i = nchan_ism - 1; i > idx_sep_object; i-- ) + { + idx[i] = idx[i - 1]; + } + idx[idx_sep_object] = 0; } - else - { - hAlignState->previous_azi_dir1[band] = azi_rad1; - hAlignState->previous_ele_dir1[band] = ele_rad1; + } + } + else + { + idx[0] = (int16_t) ( ( ratio_ism[0] ) * ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) + 0.5f ); + } - hAlignState->previous_azi_dir2[band] = azi_rad2; - hAlignState->previous_ele_dir2[band] = ele_rad2; + return; +} +#endif +#ifndef IVAS_FLOAT_FIXED +static int16_t index_slice_enum( + const int16_t *ratio_ism_idx, + const int16_t nchan_ism ) +{ + int16_t i; + int16_t x, index; + int16_t base; - prev_ele_dir1_cos = cos_ele1; - prev_ele_dir1_sin = sin_ele1; + if ( nchan_ism == 2 ) + { + index = ratio_ism_idx[0]; + } + else + { + x = ratio_ism_idx[nchan_ism - 2]; + base = 10; + for ( i = nchan_ism - 3; i >= 0; i-- ) + { + x += ratio_ism_idx[i] * base; + base *= 10; + } - prev_ele_dir2_cos = cos_ele2; - prev_ele_dir2_sin = sin_ele2; + index = 0; + i = 0; + while ( i <= x ) + { +#ifndef IVAS_FLOAT_FIXED + if ( valid_ratio_index( i, 7, nchan_ism - 1 ) ) +#else + IF( valid_ratio_index_fx( i, 7, nchan_ism - 1 ) ) +#endif + { + index++; } - } /* sf */ - } /* band */ + i++; + } + index--; + } - return; + return index; } -#endif - -/*-------------------------------------------------------------------* - * ivas_merge_masa_metadata() - * - * - *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -void ivas_merge_masa_metadata_fx( - MASA_ENCODER_HANDLE hMasa, /* i/o: MASA enc handle. source for MASA metadata and combined metadata will be here */ - OMASA_SPATIAL_META_HANDLE hOMasaMeta /* i : ISM-object metadata to be merged with the MASA metadata */ -) +#else +static Word16 index_slice_enum_fx( + const Word16 *ratio_ism_idx, + const Word16 nchan_ism ) { - Word16 sf, band; - UWord8 numCodingBands; - UWord8 numDirections; - UWord8 numSf; - MASA_METADATA_HANDLE hMeta; - Word16 energyTimesRatioMASA_e[2]; - Word16 total_diff_nrg_e; - Word16 energyMerged_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 energyTimesRatioISM_fx; /*energyTimesRatioISM_e*/ - Word16 energyTimesRatioISM_e; - Word32 energyTimesRatioMASA_fx[2]; /*energyTimesRatioMASA_e*/ - Word32 total_diff_nrg_fx; - Word32 eneBand_fx; /*eneBand_e*/ - Word16 eneBand_e; - Word32 energyMerged_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /*energyMerged_e*/ - Word32 temp1 /*temp1_e*/, temp2 /*temp2_e*/; - Word16 temp1_e, temp2_e; + Word16 i; + Word16 x, index; + Word16 base; - numCodingBands = hMasa->config.numCodingBands; - numDirections = hMasa->config.numberOfDirections; - IF( EQ_16( hMasa->config.joinedSubframes, TRUE ) ) + IF( EQ_16( nchan_ism, 2 ) ) { - numSf = 1; + index = ratio_ism_idx[0]; + move16(); } ELSE { - numSf = 4; - } - move16(); - move16(); - move16(); - hMeta = &( hMasa->masaMetadata ); - - FOR( sf = 0; sf < numSf; sf++ ) - { - FOR( band = 0; band < numCodingBands; band++ ) + x = ratio_ism_idx[nchan_ism - 2]; + base = 10; + move16(); + move16(); + FOR( i = nchan_ism - 3; i >= 0; i-- ) { - Word16 merge_dest; - Word32 dir_sum_fx; /*dir_sum_e*/ - Word16 dir_sum_e; - UWord8 band_n_dirs; - test(); - test(); - IF( EQ_16( numDirections, 1 ) || ( EQ_16( numDirections, 2 ) && hMasa->data.twoDirBands[band] == 0 ) ) - { - band_n_dirs = 1; - } - ELSE - { - band_n_dirs = 2; - } - move16(); - - /* Compute energies */ - eneBand_fx = hMasa->data.energy_fx[sf][band]; - eneBand_e = hMasa->data.energy_e[sf][band]; - move32(); - move16(); - energyMerged_fx[sf][band] = BASOP_Util_Add_Mant32Exp( eneBand_fx, eneBand_e, hMasa->data.hOmasaData->energy_ism_fx[sf][band], hMasa->data.hOmasaData->energy_ism_fx_e[sf][band], &energyMerged_e[sf][band] ); - move32(); + x = add( x, imult1616( ratio_ism_idx[i], base ) ); + base = imult1616( base, 10 ); + } - /* Compute weights */ - energyTimesRatioMASA_fx[0] = Mpy_32_32( eneBand_fx, hMeta->directional_meta[0].energy_ratio_fx[sf][band] ); - energyTimesRatioMASA_e[0] = add( eneBand_e, 1 ); - move32(); - move16(); - IF( EQ_16( band_n_dirs, 2 ) ) - { - energyTimesRatioMASA_fx[1] = Mpy_32_32( eneBand_fx, hMeta->directional_meta[1].energy_ratio_fx[sf][band] ); - energyTimesRatioMASA_e[1] = add( eneBand_e, 1 ); - } - ELSE + index = 0; + i = 0; + move16(); + move16(); + WHILE( LE_16( i, x ) ) + { + IF( valid_ratio_index_fx( i, 7, nchan_ism - 1 ) ) { - energyTimesRatioMASA_fx[1] = 0; - energyTimesRatioMASA_e[1] = 0; + index = add( index, 1 ); } - move32(); - move16(); + i = add( i, 1 ); + } + index = sub( index, 1 ); + } - /* target is original MASA diffuseness */ - total_diff_nrg_fx = Mpy_32_32( eneBand_fx, hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] ); - total_diff_nrg_e = add( eneBand_e, 1 ); + return index; +} +#endif - /* criterion is mean of ISM ratio and new ratio */ - temp1 = BASOP_Util_Add_Mant32Exp( L_add( EPSILON_FX, eneBand_fx ), eneBand_e, hMasa->data.hOmasaData->energy_ism_fx[sf][band], hMasa->data.hOmasaData->energy_ism_fx_e[sf][band], &temp1_e ); /* EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band]*/ - temp2 = L_deposit_h( BASOP_Util_Divide3232_Scale( total_diff_nrg_fx, temp1, &temp2_e ) ); /*temp2_e*/ /*total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] )*/ - temp2_e = add( temp2_e, sub( total_diff_nrg_e, temp1_e ) ); - IF( temp2_e < 0 ) - { - temp2 = L_shl( temp2, temp2_e ); - temp2_e = 0; - move16(); - } - temp2 = L_sub( L_shl_sat( 1, sub( 31, temp2_e ) ), temp2 ); /*( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] ) )*/ - temp2 = BASOP_Util_Add_Mant32Exp( hOMasaMeta->directional_meta[0].energy_ratio_fx[sf][band], 1, temp2, temp2_e, &temp2_e ); /*( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] ) )*/ - energyTimesRatioISM_fx = Mpy_32_32( L_shr( temp2, 1 ), hMasa->data.hOmasaData->energy_ism_fx[sf][band] ); /*energyTimesRatioISM_e*/ - energyTimesRatioISM_e = add( temp2_e, hMasa->data.hOmasaData->energy_ism_fx_e[sf][band] ); - /*energyTimesRatioISM = ( hOMasaMeta->directional_meta[0].energy_ratio[sf][band] + ( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] ) ) ) / 2.0f * hMasa->data.hOmasaData->energy_ism[sf][band];*/ +#ifndef IVAS_FLOAT_FIXED +static void transform_difference_index( + const int16_t *diff_idx, + int16_t *idx, + const int16_t len ) +{ + int16_t i; + for ( i = 0; i < len; i++ ) + { + if ( diff_idx[i] <= 0 ) + { + idx[i] = -2 * diff_idx[i]; + } + else + { + idx[i] = 2 * diff_idx[i] - 1; + } + } - /* Determine combined metadata based on the weights */ - merge_dest = -1; + return; +} +#else +static void transform_difference_index_ivas_fx( + const Word16 *diff_idx, + Word16 *idx, + const Word16 len ) +{ + Word16 i; + FOR( i = 0; i < len; i++ ) + { + IF( diff_idx[i] <= 0 ) + { + idx[i] = negate( shl( diff_idx[i], 1 ) ); move16(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( EQ_16( band_n_dirs, 1 ) && EQ_16( BASOP_Util_Cmp_Mant32Exp( energyTimesRatioMASA_fx[0], energyTimesRatioMASA_e[0], energyTimesRatioISM_fx, energyTimesRatioISM_e ), -1 ) ) || - ( EQ_16( band_n_dirs, 2 ) && EQ_16( BASOP_Util_Cmp_Mant32Exp( energyTimesRatioMASA_fx[0], energyTimesRatioMASA_e[0], energyTimesRatioMASA_fx[1], energyTimesRatioMASA_e[1] ), -1 ) && EQ_16( BASOP_Util_Cmp_Mant32Exp( energyTimesRatioMASA_fx[0], energyTimesRatioMASA_e[0], energyTimesRatioISM_fx, energyTimesRatioISM_e ), -1 ) ) ) - { - /* 1dir and ISM the most energetic, or 2dir and ISM the more energetic than MASA1 */ - merge_dest = 0; - } - ELSE IF( EQ_16( band_n_dirs, 2 ) && NE_16( BASOP_Util_Cmp_Mant32Exp( energyTimesRatioMASA_fx[1], energyTimesRatioMASA_e[1], energyTimesRatioMASA_fx[0], energyTimesRatioMASA_e[0] ), 1 ) && EQ_16( BASOP_Util_Cmp_Mant32Exp( energyTimesRatioMASA_fx[1], energyTimesRatioMASA_e[1], energyTimesRatioISM_fx, energyTimesRatioISM_e ), -1 ) ) - { - /* 2dir and ISM the most energetic and MASA2 the least energetic */ - merge_dest = 1; - } + } + ELSE + { + idx[i] = sub( shl( diff_idx[i], 1 ), 1 ); move16(); - - IF( merge_dest >= 0 ) /* replace one MASA with ISM */ - { - hMeta->directional_meta[merge_dest].azimuth_fx[sf][band] = hOMasaMeta->directional_meta[0].azimuth_fx[sf][band]; /*q22*/ - hMeta->directional_meta[merge_dest].elevation_fx[sf][band] = hOMasaMeta->directional_meta[0].elevation_fx[sf][band]; /*q22*/ - move32(); - move32(); - /* limit with the earlier direct-energy ratio */ - dir_sum_fx = temp2; /* new dir ratio */ - dir_sum_e = temp2_e; - move32(); - move16(); - /*dir_sum = 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] )*/ - hMeta->directional_meta[merge_dest].energy_ratio_fx[sf][band] = L_min( L_shl( dir_sum_fx, sub( dir_sum_e, 1 ) ), hOMasaMeta->directional_meta[0].energy_ratio_fx[sf][band] ); /* clip with original ISM dir */ /*q30*/ - hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_sub( ONE_IN_Q30, hMeta->directional_meta[merge_dest].energy_ratio_fx[sf][band] ); /*q30*/ - move32(); - move32(); - - IF( hMasa->config.useCoherence ) - { - hMeta->directional_meta[merge_dest].spread_coherence_fx[sf][band] = hOMasaMeta->directional_meta[0].spread_coherence_fx[sf][band]; /*q15*/ - hMeta->common_meta.surround_coherence_fx[sf][band] = hOMasaMeta->common_meta.surround_coherence_fx[sf][band]; /*q15*/ - move16(); - move16(); - } - - /* recompute direct energy ratios to match the diffuse ratio */ - Word32 direct_quota_fx, direct_scaler_fx; - Word16 direct_scaler_e; - direct_quota_fx = L_sub( ONE_IN_Q30, hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] ); - IF( EQ_16( band_n_dirs, 1 ) ) - { - hMeta->directional_meta[0].energy_ratio_fx[sf][band] = direct_quota_fx; /*q30*/ - move32(); - } - ELSE - { - dir_sum_fx = L_add( hMeta->directional_meta[0].energy_ratio_fx[sf][band], hMeta->directional_meta[1].energy_ratio_fx[sf][band] ); /*q30*/ - direct_scaler_fx = BASOP_Util_Divide3232_Scale( direct_quota_fx, L_add( EPSILON_FX, dir_sum_fx ), &direct_scaler_e ); - direct_scaler_fx = L_shl( direct_scaler_fx, direct_scaler_e ); /*q31*/ - direct_scaler_e = 0; - move16(); - hMeta->directional_meta[0].energy_ratio_fx[sf][band] = Mpy_32_32( direct_scaler_fx, hMeta->directional_meta[0].energy_ratio_fx[sf][band] ); /*q30*/ - hMeta->directional_meta[1].energy_ratio_fx[sf][band] = Mpy_32_32( direct_scaler_fx, hMeta->directional_meta[0].energy_ratio_fx[sf][band] ); /*q30*/ - move32(); - move32(); - } - } } } - FOR( sf = 0; sf < numSf; sf++ ) + return; +} +#endif +#ifndef IVAS_FLOAT_FIXED +static void transform_index_and_GR_encode( + int16_t *diff_idx, /* i : differenc eindex to encode */ + const int16_t len, /* i : input length */ + const int16_t GR_order, /* i : GR order */ + BSTR_ENC_HANDLE hMetaData /* i/o: metadata bitstream handle */ +) +{ + int16_t i; + int16_t idx[IVAS_MAX_NUM_OBJECTS]; + + /* transform difference index into positive */ + transform_difference_index( diff_idx, idx, len ); + + /* GR encoding */ + for ( i = 0; i < len; i++ ) { - FOR( band = 0; band < numCodingBands; band++ ) - { - hMasa->data.energy_fx[sf][band] = energyMerged_fx[sf][band]; - hMasa->data.energy_e[sf][band] = energyMerged_e[sf][band]; - move32(); - move16(); - } + ivas_qmetadata_encode_extended_gr( hMetaData, idx[i], 100, GR_order ); } return; } -#endif // IVAS_FLOAT_FIXED - -void ivas_merge_masa_metadata( - MASA_ENCODER_HANDLE hMasa, /* i/o: MASA enc handle. source for MASA metadata and combined metadata will be here */ - OMASA_SPATIAL_META_HANDLE hOMasaMeta /* i : ISM-object metadata to be merged with the MASA metadata */ +#else +static void transform_index_and_GR_encode_ivas_fx( + Word16 *diff_idx, /* i : differenc eindex to encode */ + const Word16 len, /* i : input length */ + const Word16 GR_order, /* i : GR order */ + BSTR_ENC_HANDLE hMetaData /* i/o: metadata bitstream handle */ ) { - int16_t sf, band; - uint8_t numCodingBands; - uint8_t numDirections; - uint8_t numSf; - MASA_METADATA_HANDLE hMeta; - float energyTimesRatioISM; - float energyTimesRatioMASA[2]; - float total_diff_nrg; - float eneBand; - float energyMerged[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 i; + Word16 idx[IVAS_MAX_NUM_OBJECTS]; - numCodingBands = hMasa->config.numCodingBands; - numDirections = hMasa->config.numberOfDirections; - numSf = hMasa->config.joinedSubframes == TRUE ? 1 : 4; - hMeta = &( hMasa->masaMetadata ); + /* transform difference index into positive */ + transform_difference_index_ivas_fx( diff_idx, idx, len ); - for ( sf = 0; sf < numSf; sf++ ) + /* GR encoding */ + FOR( i = 0; i < len; i++ ) { - for ( band = 0; band < numCodingBands; band++ ) - { - int16_t merge_dest; - float dir_sum; - uint8_t band_n_dirs; - if ( numDirections == 1 || ( numDirections == 2 && hMasa->data.twoDirBands[band] == 0 ) ) - { - band_n_dirs = 1; - } - else - { - band_n_dirs = 2; - } - - /* Compute energies */ - eneBand = hMasa->data.energy[sf][band]; - energyMerged[sf][band] = eneBand + hMasa->data.hOmasaData->energy_ism[sf][band]; + ivas_qmetadata_encode_extended_gr( hMetaData, idx[i], 100, GR_order ); + } - /* Compute weights */ - energyTimesRatioMASA[0] = eneBand * hMeta->directional_meta[0].energy_ratio[sf][band]; - if ( band_n_dirs == 2 ) - { - energyTimesRatioMASA[1] = eneBand * hMeta->directional_meta[1].energy_ratio[sf][band]; - } - else - { - energyTimesRatioMASA[1] = 0.0f; - } + return; +} +#endif +#ifdef IVAS_FLOAT_FIXED +static Word16 try_differential_fx( + const Word16 numCodingBands, + const Word32 *masa_to_total_energy_ratio, /* Q30 */ + Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + const Word16 nchan_ism, + const Word16 bits_index, + Word16 *p_b_signif ) +{ + Word16 b, i; + Word16 nbits0; + Word16 b_signif; + Word16 ratio_ism_idx_ref[MAX_NUM_OBJECTS]; + Word16 diff_idx[MAX_NUM_OBJECTS]; - /* target is original MASA diffuseness */ - total_diff_nrg = eneBand * hMeta->common_meta.diffuse_to_total_ratio[sf][band]; + b_signif = 0; + move16(); + WHILE( LT_16( b_signif, numCodingBands ) && GE_32( masa_to_total_energy_ratio[b_signif], MASA2TOTAL_THR_Q30 ) ) + { + test(); + b_signif = add( b_signif, 1 ); + } - /* criterion is mean of ISM ratio and new ratio */ - energyTimesRatioISM = ( hOMasaMeta->directional_meta[0].energy_ratio[sf][band] + ( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] ) ) ) / 2.0f * hMasa->data.hOmasaData->energy_ism[sf][band]; + nbits0 = 0; + move16(); - /* Determine combined metadata based on the weights */ - merge_dest = -1; - if ( ( band_n_dirs == 1 && energyTimesRatioMASA[0] < energyTimesRatioISM ) || - ( band_n_dirs == 2 && energyTimesRatioMASA[0] < energyTimesRatioMASA[1] && energyTimesRatioMASA[0] < energyTimesRatioISM ) ) - { - /* 1dir and ISM the most energetic, or 2dir and ISM the more energetic than MASA1 */ - merge_dest = 0; - } - else if ( band_n_dirs == 2 && energyTimesRatioMASA[1] <= energyTimesRatioMASA[0] && energyTimesRatioMASA[1] < energyTimesRatioISM ) - { - /* 2dir and ISM the most energetic and MASA2 the least energetic */ - merge_dest = 1; - } + IF( LT_16( b_signif, numCodingBands ) ) + { + nbits0 = bits_index; + move16(); + Copy( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism ); - if ( merge_dest >= 0 ) /* replace one MASA with ISM */ + FOR( b = b_signif + 1; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio[b], MASA2TOTAL_THR_Q30 ) ) { - hMeta->directional_meta[merge_dest].azimuth[sf][band] = hOMasaMeta->directional_meta[0].azimuth[sf][band]; - hMeta->directional_meta[merge_dest].elevation[sf][band] = hOMasaMeta->directional_meta[0].elevation[sf][band]; - /* limit with the earlier direct-energy ratio */ - dir_sum = 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] ); /* new dir ratio */ - hMeta->directional_meta[merge_dest].energy_ratio[sf][band] = min( dir_sum, hOMasaMeta->directional_meta[0].energy_ratio[sf][band] ); /* clip with original ISM dir */ - hMeta->common_meta.diffuse_to_total_ratio[sf][band] = 1.0f - hMeta->directional_meta[merge_dest].energy_ratio[sf][band]; + v_sub_s16_fx( ratio_ism_idx[b], ratio_ism_idx_ref, diff_idx, nchan_ism ); + Copy( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism ); - if ( hMasa->config.useCoherence ) - { - hMeta->directional_meta[merge_dest].spread_coherence[sf][band] = hOMasaMeta->directional_meta[0].spread_coherence[sf][band]; - hMeta->common_meta.surround_coherence[sf][band] = hOMasaMeta->common_meta.surround_coherence[sf][band]; - } + /* transform difference index into positive */ + transform_difference_index_ivas_fx( diff_idx, diff_idx, sub( nchan_ism, 1 ) ); - /* recompute direct energy ratios to match the diffuse ratio */ - float direct_quota, direct_scaler; - direct_quota = 1.0f - hMeta->common_meta.diffuse_to_total_ratio[sf][band]; - if ( band_n_dirs == 1 ) - { - hMeta->directional_meta[0].energy_ratio[sf][band] = direct_quota; - } - else + /* GR encoding */ + FOR( i = 0; i < nchan_ism - 1; i++ ) { - dir_sum = hMeta->directional_meta[0].energy_ratio[sf][band] + hMeta->directional_meta[1].energy_ratio[sf][band]; - direct_scaler = direct_quota / ( EPSILON + dir_sum ); - hMeta->directional_meta[0].energy_ratio[sf][band] *= direct_scaler; - hMeta->directional_meta[1].energy_ratio[sf][band] *= direct_scaler; + nbits0 = add( nbits0, ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ) ); } } } } + *p_b_signif = b_signif; + move16(); - for ( sf = 0; sf < numSf; sf++ ) - { - for ( band = 0; band < numCodingBands; band++ ) - { - hMasa->data.energy[sf][band] = energyMerged[sf][band]; - } - } - - return; + return nbits0; } - -#ifdef IVAS_FLOAT_FIXED -static void quantize_ratio_ism_vector_ivas_fx( - const Word16 *ratio_ism, /* ratio_ism_e */ - Word16 ratio_ism_e, - Word16 *idx, /* Q0 */ - const Word16 nchan_ism, - const Word32 masa_to_total_energy_ratio, - const Word16 idx_sep_object ) +#else +static int16_t try_differential( + const int16_t numCodingBands, + const float *masa_to_total_energy_ratio, + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + const int16_t nchan_ism, + const int16_t bits_index, + int16_t *p_b_signif ) { - Word16 i, j, best_i, best_i2; - Word16 dist, div, tmp, dist2, best_dist, temp, temp_e, tmp_e, idx_e, best_dist_e, dist_e, dist2_e; - Word16 part_idx_sum, max_sum_idx; - Word16 ratio_ism_loc[MAX_NUM_OBJECTS]; - Word16 no_ism_loc; + int16_t b, i; + int16_t nbits0; + int16_t b_signif; + int16_t ratio_ism_idx_ref[MAX_NUM_OBJECTS]; + int16_t diff_idx[MAX_NUM_OBJECTS]; - max_sum_idx = sub( shl( 1, PARAM_ISM_POW_RATIO_NBITS ), 1 ); + b_signif = 0; + while ( ( b_signif < numCodingBands ) && ( masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR ) ) + { + b_signif++; + } - test(); - IF( GT_16( idx_sep_object, -1 ) ) + nbits0 = 0; + + if ( b_signif < numCodingBands ) { - temp = BASOP_Util_Divide1616_Scale( 1, max_sum_idx, &temp_e ); - BASOP_Util_Add_MantExp( ratio_ism[idx_sep_object], ratio_ism_e, negate( temp ), temp_e, &tmp ); + nbits0 = bits_index; + mvs2s( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism ); - test(); - IF( tmp < 0 ) - { - /* take it out from quantize function */ - Copy( ratio_ism, ratio_ism_loc, idx_sep_object ); - Copy( &ratio_ism[idx_sep_object + 1], &ratio_ism_loc[idx_sep_object], nchan_ism - idx_sep_object - 1 ); - no_ism_loc = sub( nchan_ism, 1 ); - } - ELSE + for ( b = b_signif + 1; b < numCodingBands; b++ ) { - no_ism_loc = nchan_ism; - move16(); - Copy( ratio_ism, ratio_ism_loc, nchan_ism ); + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + v_sub_s( ratio_ism_idx[b], ratio_ism_idx_ref, diff_idx, nchan_ism ); + mvs2s( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism ); + + /* transform difference index into positive */ + transform_difference_index( diff_idx, diff_idx, nchan_ism - 1 ); + + /* GR encoding */ + for ( i = 0; i < nchan_ism - 1; i++ ) + { + nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); + } + } } } - ELSE - { - no_ism_loc = nchan_ism; - move16(); - Copy( ratio_ism, ratio_ism_loc, nchan_ism ); - } + *p_b_signif = b_signif; - test(); - IF( GT_16( nchan_ism, 1 ) ) - { - test(); - IF( GE_32( masa_to_total_energy_ratio, MASA2TOTAL_THR_Q30 ) ) - { - distribute_evenly_ism_fx( idx, max_sum_idx, nchan_ism ); - } - ELSE - { - test(); - IF( GT_16( no_ism_loc, 1 ) ) - { + return nbits0; +} +#endif + +#ifndef IVAS_FLOAT_FIXED +static void differential_coding_first_subframe( + BSTR_ENC_HANDLE hMetaData, + const float *masa_to_total_energy_ratio, + const int16_t b_signif, + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + const int16_t nchan_ism, + const int16_t numCodingBands, + const int16_t bits_index ) +{ + int16_t index, b; + int16_t ratio_ism_idx_ref[MAX_NUM_OBJECTS]; + int16_t diff_idx[MAX_NUM_OBJECTS]; - dist = 0; - dist_e = 0; - div = div_s( 1, max_sum_idx ); // Q15 - move16(); - move16(); + /* differential encoding*/ + push_next_indice( hMetaData, 0, 1 ); - part_idx_sum = 0; - move16(); + if ( b_signif < numCodingBands ) + { + index = index_slice_enum( ratio_ism_idx[b_signif], nchan_ism ); + push_next_indice( hMetaData, index, bits_index ); - FOR( i = 0; i < no_ism_loc; i++ ) - { - idx[i] = mult( ratio_ism_loc[i], max_sum_idx ); // exponent : ratio_ism_e + 15 - move16(); - idx[i] = shl( idx[i], sub( add( ratio_ism_e, 15 ), 15 ) ); // Q0 - move16(); - part_idx_sum = add( part_idx_sum, idx[i] ); + mvs2s( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism ); - tmp_e = BASOP_Util_Add_MantExp( ratio_ism_loc[i], ratio_ism_e, negate( imult1616( idx[i], div ) ), 0, &tmp ); // tmp_e - dist_e = BASOP_Util_Add_MantExp( dist, dist_e, mult( tmp, tmp ), add( tmp_e, tmp_e ), &dist ); // dist_e - } + for ( b = b_signif + 1; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + v_sub_s( ratio_ism_idx[b], ratio_ism_idx_ref, diff_idx, nchan_ism ); + mvs2s( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism ); - best_dist = dist; - best_dist_e = dist_e; - best_i2 = -1; - move16(); - move16(); - move16(); + /* transform difference index into positive */ + transform_index_and_GR_encode( diff_idx, nchan_ism - 1, 0, hMetaData ); + } + } + } - WHILE( LT_16( part_idx_sum, max_sum_idx ) ) - { - best_i = -1; - move16(); - /* check which index to increase by 1 for a possible improvement */ + return; +} +#else +static void differential_coding_first_subframe_ivas_fx( + BSTR_ENC_HANDLE hMetaData, + const Word32 *masa_to_total_energy_ratio, // Q30 + const Word16 b_signif, + Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + const Word16 nchan_ism, + const Word16 numCodingBands, + const Word16 bits_index ) +{ + Word16 index, b; + Word16 ratio_ism_idx_ref[MAX_NUM_OBJECTS]; + Word16 diff_idx[MAX_NUM_OBJECTS]; - FOR( i = 0; i < no_ism_loc; i++ ) - { - idx[i] = add( idx[i], 1 ); - move16(); - dist2 = 0; - dist2_e = 0; - move16(); - move16(); + /* differential encoding*/ + push_next_indice( hMetaData, 0, 1 ); - FOR( j = 0; j < no_ism_loc; j++ ) - { - Word32 temp1 = L_mult( idx[i], div ); // Q : 15 + 0 + 1 - Word16 temp1_n = norm_l( temp1 ); - Word16 temp1_16 = extract_h( L_shl( temp1, temp1_n ) ); // Q : Q + temp1_n - 16 - tmp_e = BASOP_Util_Add_MantExp( ratio_ism_loc[i], ratio_ism_e, negate( temp1_16 ), sub( 15, temp1_n ), &tmp ); // tmp_e - dist2_e = BASOP_Util_Add_MantExp( dist2, dist2_e, mult_sat( tmp, tmp ), add( tmp_e, tmp_e ), &dist2 ); // dist_e - } + IF( LT_16( b_signif, numCodingBands ) ) + { + index = index_slice_enum_fx( ratio_ism_idx[b_signif], nchan_ism ); + push_next_indice( hMetaData, index, bits_index ); - BASOP_Util_Add_MantExp( dist2, dist2_e, negate( best_dist ), best_dist_e, &tmp ); - test(); - IF( tmp < 0 ) - { - best_i2 = best_i; - best_i = i; - best_dist = dist2; - best_dist_e = dist2_e; - move16(); - move16(); - move16(); - move16(); - } - idx[i] = sub( idx[i], 1 ); - move16(); - } + Copy( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism ); - test(); - IF( GT_16( best_i, -1 ) ) - { - idx[best_i] = add( idx[best_i], 1 ); - move16(); - part_idx_sum = add( part_idx_sum, 1 ); - } - ELSE - { - test(); - IF( GT_16( best_i2, -1 ) ) - { - idx[best_i2] = add( idx[best_i2], 1 ); - move16(); - part_idx_sum = add( part_idx_sum, 1 ); - } - ELSE - { - idx[no_ism_loc - 1] = add( idx[no_ism_loc - 1], sub( max_sum_idx, part_idx_sum ) ); - move16(); - part_idx_sum = max_sum_idx; - move16(); - } - } - } - assert( sum_s( idx, no_ism_loc ) == max_sum_idx ); - } - ELSE + FOR( b = b_signif + 1; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio[b], MASA2TOTAL_THR_Q30 ) ) { - idx[0] = max_sum_idx; - move16(); - } + v_sub_s16_fx( ratio_ism_idx[b], ratio_ism_idx_ref, diff_idx, nchan_ism ); + Copy( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism ); - test(); - IF( LT_16( no_ism_loc, nchan_ism ) ) - { - /* insert back the ratio of the separated object */ - FOR( i = nchan_ism - 1; i > idx_sep_object; i-- ) - { - idx[i] = idx[i - 1]; - move16(); - } - idx[idx_sep_object] = 0; - move16(); + /* transform difference index into positive */ + transform_index_and_GR_encode_ivas_fx( diff_idx, sub( nchan_ism, 1 ), 0, hMetaData ); } } } - ELSE + + return; +} +#endif +#ifndef IVAS_FLOAT_FIXED +static void independent_coding_ratio_ism_idx( + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* i : ISM ratios */ + const float *masa_to_total_energy_ratio, /* i : MASA to total ratios */ + const int16_t nchan_ism, /* i : number of objects */ + const int16_t numCodingBands, /* i : number of subbands */ + const int16_t bits_index, /* i : number of bits per index */ + BSTR_ENC_HANDLE hMetaData /* i/o: metadata bitstream handle */ +) +{ + int16_t b, index; + + for ( b = 0; b < numCodingBands; b++ ) { - // idx[0] = (int16_t) ( ( ratio_ism[0] ) * ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) + 0.5f ); - tmp = imult1616( ratio_ism[0], sub( shl( 1, PARAM_ISM_POW_RATIO_NBITS ), 1 ) ); // tmp_e - tmp_e = ratio_ism_e; - move16(); - idx_e = BASOP_Util_Add_MantExp( tmp, tmp_e, 16384 /* 0.5 in Q15 */, 0, &idx[0] ); // idx_e - idx[0] = shl( idx[0], sub( idx_e, 15 ) ); // Q0 - move16(); + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + index = index_slice_enum( ratio_ism_idx[b], nchan_ism ); + push_next_indice( hMetaData, index, bits_index ); + } } return; } #else - -static void quantize_ratio_ism_vector( - const float *ratio_ism, - int16_t *idx, - const int16_t nchan_ism, - const float masa_to_total_energy_ratio, - const int16_t idx_sep_object ) +static void independent_coding_ratio_ism_idx_fx( + Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* i : ISM ratios */ + const Word32 *masa_to_total_energy_ratio, /* i : MASA to total ratios, Q30 */ + const Word16 nchan_ism, /* i : number of objects */ + const Word16 numCodingBands, /* i : number of subbands */ + const Word16 bits_index, /* i : number of bits per index */ + BSTR_ENC_HANDLE hMetaData /* i/o: metadata bitstream handle */ +) { - int16_t i, j, best_i, best_i2; - float dist, div, tmp, dist2, best_dist; - int16_t part_idx_sum, max_sum_idx; - float ratio_ism_loc[MAX_NUM_OBJECTS]; - int16_t no_ism_loc; - - max_sum_idx = ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1; + Word16 b, index; - if ( idx_sep_object > -1 ) + FOR( b = 0; b < numCodingBands; b++ ) { - if ( ratio_ism[idx_sep_object] < 1.0f / (float) ( max_sum_idx ) ) - { - /* take it out from quantize function */ - mvr2r( ratio_ism, ratio_ism_loc, idx_sep_object ); - mvr2r( &ratio_ism[idx_sep_object + 1], &ratio_ism_loc[idx_sep_object], nchan_ism - idx_sep_object - 1 ); - no_ism_loc = nchan_ism - 1; - } - else + IF( LT_32( masa_to_total_energy_ratio[b], MASA2TOTAL_THR_Q30 ) ) { - no_ism_loc = nchan_ism; - mvr2r( ratio_ism, ratio_ism_loc, nchan_ism ); + index = index_slice_enum_fx( ratio_ism_idx[b], nchan_ism ); + push_next_indice( hMetaData, index, bits_index ); } } - else + + return; +} +#endif + +#ifndef IVAS_FLOAT_FIXED +static void remove_sep_obj( + int16_t *diff_idx, /* i/o: array of difference of indexes */ + const int16_t nchan_ism, /* i : number of objects */ + const int16_t idx_sep_obj /* i : index of separated object, to be taken out of array */ +) +{ + int16_t i; + + for ( i = idx_sep_obj; i < nchan_ism - 1; i++ ) { - no_ism_loc = nchan_ism; - mvr2r( ratio_ism, ratio_ism_loc, nchan_ism ); + diff_idx[i] = diff_idx[i + 1]; + } + + return; +} +#else +static void remove_sep_obj_fx( + Word16 *diff_idx, /* i/o: array of difference of indexes */ + const Word16 nchan_ism, /* i : number of objects */ + const Word16 idx_sep_obj /* i : index of separated object, to be taken out of array */ +) +{ + Word16 i; + + FOR( i = idx_sep_obj; i < nchan_ism - 1; i++ ) + { + diff_idx[i] = diff_idx[i + 1]; + move16(); } - if ( nchan_ism > 1 ) - { - if ( masa_to_total_energy_ratio >= MASA2TOTAL_THR ) - { -#ifndef IVAS_FLOAT_FIXED - distribute_evenly_ism( idx, max_sum_idx, nchan_ism ); -#else - distribute_evenly_ism_fx( idx, max_sum_idx, nchan_ism ); -#endif - } - else - { - if ( no_ism_loc > 1 ) - { + return; +} +#endif + +#ifndef IVAS_FLOAT_FIXED +static void estimate_bits_subband_ism_ratio( + const int16_t *ratio_ism_idx, + const int16_t *ratio_ism_idx_ref, /* ( i/o ) */ + const int16_t nchan_ism, + const int16_t shift_one, + const int16_t idx_sep_obj, + int16_t *p_nbits0, + int16_t *p_nbits1 ) +{ + int16_t diff_idx[MAX_NUM_OBJECTS]; + int16_t nbits0, nbits1; + int16_t i; + + nbits0 = 0; + nbits1 = 0; - dist = 0.0f; - div = 1.0f / (float) ( max_sum_idx ); + /* take difference with respect to previous subframe */ + v_sub_s( ratio_ism_idx, ratio_ism_idx_ref, diff_idx, nchan_ism ); - part_idx_sum = 0; + if ( shift_one ) + { + remove_sep_obj( diff_idx, nchan_ism, idx_sep_obj ); + } - for ( i = 0; i < no_ism_loc; i++ ) - { - idx[i] = (int16_t) ( ( ratio_ism_loc[i] ) * ( max_sum_idx ) ); - part_idx_sum += idx[i]; + /* transform difference index into positive */ + transform_difference_index( diff_idx, diff_idx, nchan_ism - 1 - shift_one ); - tmp = ( ratio_ism_loc[i] - ( idx[i] * div ) ); - dist += ( tmp * tmp ); - } + /* GR encoding */ + for ( i = 0; i < nchan_ism - 1 - shift_one; i++ ) + { + nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); + nbits1 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ); + } - best_dist = dist; - best_i2 = -1; - while ( part_idx_sum < max_sum_idx ) - { - best_i = -1; - /* check which index to increase by 1 for a possible improvement */ + *p_nbits0 = nbits0; + *p_nbits1 = nbits1; - for ( i = 0; i < no_ism_loc; i++ ) - { - idx[i]++; - dist2 = 0.0f; + return; +} +#else +static void estimate_bits_subband_ism_ratio_fx( + const Word16 *ratio_ism_idx, + const Word16 *ratio_ism_idx_ref, /* ( i/o ) */ + const Word16 nchan_ism, + const Word16 shift_one, + const Word16 idx_sep_obj, + Word16 *p_nbits0, + Word16 *p_nbits1 ) +{ + Word16 diff_idx[MAX_NUM_OBJECTS]; + Word16 nbits0, nbits1; + Word16 i; - for ( j = 0; j < no_ism_loc; j++ ) - { - tmp = ( ratio_ism_loc[i] - ( idx[i] * div ) ); - dist2 += ( tmp * tmp ); - } + nbits0 = 0; + nbits1 = 0; + move16(); + move16(); - if ( dist2 < best_dist ) - { - best_i2 = best_i; - best_i = i; - best_dist = dist2; - } - idx[i]--; - } - if ( best_i > -1 ) - { - idx[best_i]++; - part_idx_sum++; - } - else - { - if ( best_i2 > -1 ) - { - idx[best_i2]++; - part_idx_sum++; - } - else - { - idx[no_ism_loc - 1] += max_sum_idx - part_idx_sum; - part_idx_sum = max_sum_idx; - } - } - } - assert( sum_s( idx, no_ism_loc ) == max_sum_idx ); - } - else - { - idx[0] = max_sum_idx; - } + /* take difference with respect to previous subframe */ + v_sub_s16_fx( ratio_ism_idx, ratio_ism_idx_ref, diff_idx, nchan_ism ); - if ( no_ism_loc < nchan_ism ) - { - /* insert back the ratio of the separated object */ - for ( i = nchan_ism - 1; i > idx_sep_object; i-- ) - { - idx[i] = idx[i - 1]; - } - idx[idx_sep_object] = 0; - } - } + IF( shift_one ) + { + remove_sep_obj_fx( diff_idx, nchan_ism, idx_sep_obj ); } - else + + /* transform difference index into positive */ + transform_difference_index_ivas_fx( diff_idx, diff_idx, sub( sub( nchan_ism, 1 ), shift_one ) ); + + /* GR encoding */ + FOR( i = 0; i < nchan_ism - 1 - shift_one; i++ ) { - idx[0] = (int16_t) ( ( ratio_ism[0] ) * ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) + 0.5f ); + nbits0 = add( nbits0, ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ) ); + nbits1 = add( nbits1, ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ) ); } + *p_nbits0 = nbits0; + *p_nbits1 = nbits1; + move16(); + move16(); + return; } #endif -static int16_t index_slice_enum( - const int16_t *ratio_ism_idx, - const int16_t nchan_ism ) +#ifndef IVAS_FLOAT_FIXED +static int16_t encode_ratio_ism_subframe( + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + const int16_t nchan_ism, + const uint8_t numCodingBands, + const int16_t sf, + int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + BSTR_ENC_HANDLE hMetaData, + // const float *masa_to_total_energy_ratio, + float *masa_to_total_energy_ratio, + const int16_t shift_one, + const int16_t idx_separated_obj ) { - int16_t i; - int16_t x, index; - int16_t base; + int16_t b, b_signif; + int16_t diff_idx[MAX_NUM_OBJECTS]; + int16_t nbits, nbits0, nbits1, GR_order, GR_order_sb; + int16_t differential_subframe; + int16_t ratio_ism_idx_ref[MAX_NUM_OBJECTS]; + int16_t bits_index; + int16_t nbits00, nbits11; + int16_t idx_sep_obj_local; - if ( nchan_ism == 2 ) - { - index = ratio_ism_idx[0]; - } - else + idx_sep_obj_local = idx_separated_obj; + if ( idx_separated_obj > -1 ) { - x = ratio_ism_idx[nchan_ism - 2]; - base = 10; - for ( i = nchan_ism - 3; i >= 0; i-- ) + if ( idx_separated_obj == nchan_ism - 1 ) { - x += ratio_ism_idx[i] * base; - base *= 10; + idx_sep_obj_local = 0; } + } + nbits = 0; + nbits0 = 0; + nbits1 = 0; - index = 0; - i = 0; - while ( i <= x ) - { + differential_subframe = 1; /* the differences are taken with respect to previous subframe */ + + /* first subframe */ + bits_index = 0; + if ( sf == 0 ) + { #ifndef IVAS_FLOAT_FIXED - if ( valid_ratio_index( i, 7, nchan_ism - 1 ) ) + bits_index = bits_index_ism_ratio( nchan_ism ); #else - IF( valid_ratio_index_fx( i, 7, nchan_ism - 1 ) ) + bits_index = bits_index_ism_ratio_fx( nchan_ism ); #endif + + nbits = 0; + for ( b = 0; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) { - index++; + nbits += bits_index; } - i++; } - index--; - } - - return index; -} + nbits0 = try_differential( numCodingBands, masa_to_total_energy_ratio, ratio_ism_idx, nchan_ism, bits_index, &b_signif ); -static void transform_difference_index( - const int16_t *diff_idx, - int16_t *idx, - const int16_t len ) -{ - int16_t i; - for ( i = 0; i < len; i++ ) - { - if ( diff_idx[i] <= 0 ) + if ( nbits <= nbits0 && nbits > 0 ) { - idx[i] = -2 * diff_idx[i]; + /* independent encoding */ + push_next_indice( hMetaData, 1, 1 ); + independent_coding_ratio_ism_idx( ratio_ism_idx, masa_to_total_energy_ratio, nchan_ism, numCodingBands, bits_index, hMetaData ); + nbits = nbits + 1; } else { - idx[i] = 2 * diff_idx[i] - 1; + if ( nbits > 0 ) + { +#ifndef IVAS_FLOAT_FIXED + differential_coding_first_subframe( hMetaData, masa_to_total_energy_ratio, b_signif, ratio_ism_idx, nchan_ism, numCodingBands, bits_index ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word32 masa_to_total_energy_ratio_fx[MASA_FREQUENCY_BANDS]; + floatToFixed_arrL( masa_to_total_energy_ratio, masa_to_total_energy_ratio_fx, 30, MASA_FREQUENCY_BANDS ); +#endif + differential_coding_first_subframe_ivas_fx( hMetaData, masa_to_total_energy_ratio_fx, b_signif, ratio_ism_idx, nchan_ism, numCodingBands, bits_index ); +#endif + nbits = nbits0 + 1; + } } } + else + { + /* not first subframe */ + if ( shift_one == 1 && nchan_ism == 2 ) + { + nbits = 0; + } + else + { + nbits0 = 0; + nbits1 = 0; - return; -} + for ( b = 0; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + estimate_bits_subband_ism_ratio( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], nchan_ism, shift_one, idx_sep_obj_local, &nbits00, &nbits11 ); + nbits0 += nbits00; + nbits1 += nbits11; + } + } + if ( nbits0 < nbits1 ) + { + GR_order = 0; + nbits = nbits0; + } + else + { + GR_order = 1; + nbits = nbits1; + } -static void transform_difference_index_ivas_fx( - const Word16 *diff_idx, - Word16 *idx, - const Word16 len ) -{ - Word16 i; - FOR( i = 0; i < len; i++ ) - { - IF( diff_idx[i] <= 0 ) - { - idx[i] = negate( shl( diff_idx[i], 1 ) ); - move16(); - } - ELSE - { - idx[i] = sub( shl( diff_idx[i], 1 ), 1 ); - move16(); - } - } + if ( numCodingBands > 1 ) + { + /* try the difference from subband to subband; first subband is compared to previous subframe first subband*/ + /* take difference with respect to previous subframe only for first subband */ + nbits0 = 0; + nbits1 = 0; + b_signif = 0; + while ( ( b_signif < numCodingBands ) && ( masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR ) ) + { + b_signif++; + } - return; -} + if ( b_signif < numCodingBands ) + { + estimate_bits_subband_ism_ratio( ratio_ism_idx[b_signif], ratio_ism_idx_prev_sf[b_signif], nchan_ism, shift_one, idx_sep_obj_local, &nbits0, &nbits1 ); + mvs2s( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism ); -static void transform_index_and_GR_encode( - int16_t *diff_idx, /* i : differenc eindex to encode */ - const int16_t len, /* i : input length */ - const int16_t GR_order, /* i : GR order */ - BSTR_ENC_HANDLE hMetaData /* i/o: metadata bitstream handle */ -) -{ - int16_t i; - int16_t idx[IVAS_MAX_NUM_OBJECTS]; + for ( b = b_signif + 1; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + estimate_bits_subband_ism_ratio( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism, shift_one, idx_sep_obj_local, &nbits00, &nbits11 ); + nbits0 += nbits00; + nbits1 += nbits11; + mvs2s( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism ); + } + } - /* transform difference index into positive */ - transform_difference_index( diff_idx, idx, len ); + if ( nbits0 < nbits1 ) + { + GR_order_sb = 0; + } + else + { + GR_order_sb = 1; + nbits0 = nbits1; + } - /* GR encoding */ - for ( i = 0; i < len; i++ ) - { - ivas_qmetadata_encode_extended_gr( hMetaData, idx[i], 100, GR_order ); - } + if ( nbits0 < nbits ) + { + differential_subframe = 0; + nbits = nbits0; + GR_order = GR_order_sb; + } - return; -} + if ( nbits > 0 ) + { + /* write prediction type */ + push_next_indice( hMetaData, differential_subframe, 1 ); + /* write GR order */ + push_next_indice( hMetaData, GR_order, 1 ); + nbits++; /* for the prediction type */ + nbits++; /* for GR_order */ -static void transform_index_and_GR_encode_ivas_fx( - Word16 *diff_idx, /* i : differenc eindex to encode */ - const Word16 len, /* i : input length */ - const Word16 GR_order, /* i : GR order */ - BSTR_ENC_HANDLE hMetaData /* i/o: metadata bitstream handle */ -) -{ - Word16 i; - Word16 idx[IVAS_MAX_NUM_OBJECTS]; + /* write data */ + if ( differential_subframe ) + { + for ( b = 0; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + /* take difference with respect to previous subframe */ + v_sub_s( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], diff_idx, nchan_ism ); - /* transform difference index into positive */ - transform_difference_index_ivas_fx( diff_idx, idx, len ); + if ( shift_one ) + { + remove_sep_obj( diff_idx, nchan_ism, idx_sep_obj_local ); + } - /* GR encoding */ - FOR( i = 0; i < len; i++ ) - { - ivas_qmetadata_encode_extended_gr( hMetaData, idx[i], 100, GR_order ); - } + transform_index_and_GR_encode( diff_idx, nchan_ism - 1 - shift_one, GR_order, hMetaData ); + } + } + } + else + { + v_sub_s( ratio_ism_idx[b_signif], ratio_ism_idx_prev_sf[b_signif], diff_idx, nchan_ism ); - return; -} + if ( shift_one ) + { + remove_sep_obj( diff_idx, nchan_ism, idx_sep_obj_local ); + } + transform_index_and_GR_encode( diff_idx, nchan_ism - 1 - shift_one, GR_order, hMetaData ); -static int16_t try_differential( - const int16_t numCodingBands, - const float *masa_to_total_energy_ratio, - int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], - const int16_t nchan_ism, - const int16_t bits_index, - int16_t *p_b_signif ) -{ - int16_t b, i; - int16_t nbits0; - int16_t b_signif; - int16_t ratio_ism_idx_ref[MAX_NUM_OBJECTS]; - int16_t diff_idx[MAX_NUM_OBJECTS]; + mvs2s( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism - shift_one ); - b_signif = 0; - while ( ( b_signif < numCodingBands ) && ( masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR ) ) - { - b_signif++; - } + for ( b = b_signif + 1; b < numCodingBands; b++ ) + { + /* take difference with respect to previous subband */ + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + v_sub_s( ratio_ism_idx[b], ratio_ism_idx_ref, diff_idx, nchan_ism ); - nbits0 = 0; + if ( shift_one ) + { + remove_sep_obj( diff_idx, nchan_ism, idx_sep_obj_local ); + } - if ( b_signif < numCodingBands ) - { - nbits0 = bits_index; - mvs2s( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism ); + transform_index_and_GR_encode( diff_idx, nchan_ism - 1 - shift_one, GR_order, hMetaData ); - for ( b = b_signif + 1; b < numCodingBands; b++ ) - { - if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + mvs2s( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism - shift_one ); + } + } + } + } + } + } + else { - v_sub_s( ratio_ism_idx[b], ratio_ism_idx_ref, diff_idx, nchan_ism ); - mvs2s( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism ); - - /* transform difference index into positive */ - transform_difference_index( diff_idx, diff_idx, nchan_ism - 1 ); + /* only differential wrt previous subframe is possible */ + /* write the differential to subframe case and no bit to signal the difference type */ - /* GR encoding */ - for ( i = 0; i < nchan_ism - 1; i++ ) + if ( nbits > 0 ) { - nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); + /* write GR order */ + push_next_indice( hMetaData, GR_order, 1 ); + nbits++; /* for GR_order */ + /* write data */ + /* only one subband */ + if ( masa_to_total_energy_ratio[0] < MASA2TOTAL_THR ) + { + /* take difference with respect to previous subframe */ + v_sub_s( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, nchan_ism ); + + if ( shift_one ) + { + remove_sep_obj( diff_idx, nchan_ism, idx_sep_obj_local ); + } + + transform_index_and_GR_encode( diff_idx, nchan_ism - 1 - shift_one, GR_order, hMetaData ); + } } } } } - *p_b_signif = b_signif; - return nbits0; + return nbits; } - -#ifndef IVAS_FLOAT_FIXED -static void differential_coding_first_subframe( +#else +static Word16 encode_ratio_ism_subframe_fx( + Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + const Word16 nchan_ism, + const UWord8 numCodingBands, + const Word16 sf, + Word16 ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], BSTR_ENC_HANDLE hMetaData, - const float *masa_to_total_energy_ratio, - const int16_t b_signif, - int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], - const int16_t nchan_ism, - const int16_t numCodingBands, - const int16_t bits_index ) + const Word32 *masa_to_total_energy_ratio, /* Q30 */ + const Word16 shift_one, + const Word16 idx_separated_obj ) { - int16_t index, b; - int16_t ratio_ism_idx_ref[MAX_NUM_OBJECTS]; - int16_t diff_idx[MAX_NUM_OBJECTS]; + Word16 b, b_signif; + Word16 diff_idx[MAX_NUM_OBJECTS]; + Word16 nbits, nbits0, nbits1, GR_order, GR_order_sb; + Word16 differential_subframe; + Word16 ratio_ism_idx_ref[MAX_NUM_OBJECTS]; + Word16 bits_index; + Word16 nbits00, nbits11; + Word16 idx_sep_obj_local; - /* differential encoding*/ - push_next_indice( hMetaData, 0, 1 ); + idx_sep_obj_local = idx_separated_obj; + move16(); + IF( GT_16( idx_separated_obj, -1 ) ) + { + if ( EQ_16( idx_separated_obj, sub( nchan_ism, 1 ) ) ) + { + idx_sep_obj_local = 0; + move16(); + } + } + nbits = 0; + nbits0 = 0; + nbits1 = 0; + move16(); + move16(); + move16(); - if ( b_signif < numCodingBands ) + differential_subframe = 1; /* the differences are taken with respect to previous subframe */ + move16(); + + /* first subframe */ + bits_index = 0; + move16(); + IF( sf == 0 ) { - index = index_slice_enum( ratio_ism_idx[b_signif], nchan_ism ); - push_next_indice( hMetaData, index, bits_index ); + bits_index = bits_index_ism_ratio_fx( nchan_ism ); + + nbits = 0; + move16(); + FOR( b = 0; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio[b], MASA2TOTAL_THR_Q30 ) ) + { + nbits = add( nbits, bits_index ); + } + } - mvs2s( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism ); + nbits0 = try_differential_fx( numCodingBands, masa_to_total_energy_ratio, ratio_ism_idx, nchan_ism, bits_index, &b_signif ); - for ( b = b_signif + 1; b < numCodingBands; b++ ) + test(); + IF( LE_16( nbits, nbits0 ) && nbits > 0 ) { - if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + /* independent encoding */ + push_next_indice( hMetaData, 1, 1 ); + independent_coding_ratio_ism_idx_fx( ratio_ism_idx, masa_to_total_energy_ratio, nchan_ism, numCodingBands, bits_index, hMetaData ); + nbits = add( nbits, 1 ); + } + ELSE + { + IF( nbits > 0 ) { - v_sub_s( ratio_ism_idx[b], ratio_ism_idx_ref, diff_idx, nchan_ism ); - mvs2s( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism ); + differential_coding_first_subframe_ivas_fx( hMetaData, masa_to_total_energy_ratio, b_signif, ratio_ism_idx, nchan_ism, numCodingBands, bits_index ); - /* transform difference index into positive */ - transform_index_and_GR_encode( diff_idx, nchan_ism - 1, 0, hMetaData ); + nbits = add( nbits0, 1 ); } } } + ELSE + { + /* not first subframe */ + test(); + IF( EQ_16( shift_one, 1 ) && EQ_16( nchan_ism, 2 ) ) + { + nbits = 0; + move16(); + } + ELSE + { + nbits0 = 0; + nbits1 = 0; + move16(); + move16(); - return; -} -#else -static void differential_coding_first_subframe_ivas_fx( - BSTR_ENC_HANDLE hMetaData, - const Word32 *masa_to_total_energy_ratio, // Q30 - const Word16 b_signif, - Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], - const Word16 nchan_ism, - const Word16 numCodingBands, - const Word16 bits_index ) -{ - Word16 index, b; - Word16 ratio_ism_idx_ref[MAX_NUM_OBJECTS]; - Word16 diff_idx[MAX_NUM_OBJECTS]; + FOR( b = 0; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio[b], MASA2TOTAL_THR_Q30 ) ) + { + estimate_bits_subband_ism_ratio_fx( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], nchan_ism, shift_one, idx_sep_obj_local, &nbits00, &nbits11 ); + nbits0 = add( nbits0, nbits00 ); + nbits1 = add( nbits1, nbits11 ); + } + } + IF( LT_16( nbits0, nbits1 ) ) + { + GR_order = 0; + nbits = nbits0; + move16(); + move16(); + } + ELSE + { + GR_order = 1; + nbits = nbits1; + move16(); + move16(); + } - /* differential encoding*/ - push_next_indice( hMetaData, 0, 1 ); + IF( GT_16( numCodingBands, 1 ) ) + { + /* try the difference from subband to subband; first subband is compared to previous subframe first subband*/ + /* take difference with respect to previous subframe only for first subband */ + nbits0 = 0; + nbits1 = 0; + b_signif = 0; + move16(); + move16(); + move16(); + WHILE( LT_16( b_signif, numCodingBands ) && GE_32( masa_to_total_energy_ratio[b_signif], MASA2TOTAL_THR_Q30 ) ) + { + test(); + b_signif = add( b_signif, 1 ); + } - IF( LT_16( b_signif, numCodingBands ) ) - { - index = index_slice_enum( ratio_ism_idx[b_signif], nchan_ism ); - push_next_indice( hMetaData, index, bits_index ); + IF( LT_16( b_signif, numCodingBands ) ) + { + estimate_bits_subband_ism_ratio_fx( ratio_ism_idx[b_signif], ratio_ism_idx_prev_sf[b_signif], nchan_ism, shift_one, idx_sep_obj_local, &nbits0, &nbits1 ); - Copy( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism ); + Copy( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism ); - FOR( b = b_signif + 1; b < numCodingBands; b++ ) - { - IF( LT_32( masa_to_total_energy_ratio[b], MASA2TOTAL_THR_Q30 ) ) - { - v_sub_s16_fx( ratio_ism_idx[b], ratio_ism_idx_ref, diff_idx, nchan_ism ); - Copy( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism ); + FOR( b = b_signif + 1; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio[b], MASA2TOTAL_THR_Q30 ) ) + { + estimate_bits_subband_ism_ratio_fx( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism, shift_one, idx_sep_obj_local, &nbits00, &nbits11 ); + nbits0 = add( nbits0, nbits00 ); + nbits1 = add( nbits1, nbits11 ); + Copy( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism ); + } + } - /* transform difference index into positive */ - transform_index_and_GR_encode_ivas_fx( diff_idx, sub( nchan_ism, 1 ), 0, hMetaData ); - } - } - } + IF( LT_16( nbits0, nbits1 ) ) + { + GR_order_sb = 0; + move16(); + } + ELSE + { + GR_order_sb = 1; + nbits0 = nbits1; + move16(); + move16(); + } - return; -} -#endif + IF( LT_16( nbits0, nbits ) ) + { + differential_subframe = 0; + nbits = nbits0; + GR_order = GR_order_sb; + move16(); + move16(); + move16(); + } -static void independent_coding_ratio_ism_idx( - int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* i : ISM ratios */ - const float *masa_to_total_energy_ratio, /* i : MASA to total ratios */ - const int16_t nchan_ism, /* i : number of objects */ - const int16_t numCodingBands, /* i : number of subbands */ - const int16_t bits_index, /* i : number of bits per index */ - BSTR_ENC_HANDLE hMetaData /* i/o: metadata bitstream handle */ -) -{ - int16_t b, index; + IF( nbits > 0 ) + { + /* write prediction type */ + push_next_indice( hMetaData, differential_subframe, 1 ); + /* write GR order */ + push_next_indice( hMetaData, GR_order, 1 ); + nbits = add( nbits, 1 ); /* for the prediction type */ + nbits = add( nbits, 1 ); /* for GR_order */ - for ( b = 0; b < numCodingBands; b++ ) - { - if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) - { - index = index_slice_enum( ratio_ism_idx[b], nchan_ism ); - push_next_indice( hMetaData, index, bits_index ); - } - } + /* write data */ + IF( differential_subframe ) + { + FOR( b = 0; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio[b], MASA2TOTAL_THR_Q30 ) ) + { + /* take difference with respect to previous subframe */ + v_sub_s16_fx( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], diff_idx, nchan_ism ); - return; -} + IF( shift_one ) + { + remove_sep_obj_fx( diff_idx, nchan_ism, idx_sep_obj_local ); + } + transform_index_and_GR_encode_ivas_fx( diff_idx, sub( sub( nchan_ism, 1 ), shift_one ), GR_order, hMetaData ); + } + } + } + ELSE + { + v_sub_s16_fx( ratio_ism_idx[b_signif], ratio_ism_idx_prev_sf[b_signif], diff_idx, nchan_ism ); -static void remove_sep_obj( - int16_t *diff_idx, /* i/o: array of difference of indexes */ - const int16_t nchan_ism, /* i : number of objects */ - const int16_t idx_sep_obj /* i : index of separated object, to be taken out of array */ -) -{ - int16_t i; + IF( shift_one ) + { + remove_sep_obj_fx( diff_idx, nchan_ism, idx_sep_obj_local ); + } - for ( i = idx_sep_obj; i < nchan_ism - 1; i++ ) - { - diff_idx[i] = diff_idx[i + 1]; - } + transform_index_and_GR_encode_ivas_fx( diff_idx, sub( sub( nchan_ism, 1 ), shift_one ), GR_order, hMetaData ); - return; -} + Copy( ratio_ism_idx[b_signif], ratio_ism_idx_ref, sub( nchan_ism, shift_one ) ); + FOR( b = b_signif + 1; b < numCodingBands; b++ ) + { + /* take difference with respect to previous subband */ + IF( LT_32( masa_to_total_energy_ratio[b], MASA2TOTAL_THR_Q30 ) ) + { + v_sub_s16_fx( ratio_ism_idx[b], ratio_ism_idx_ref, diff_idx, nchan_ism ); -static void estimate_bits_subband_ism_ratio( - const int16_t *ratio_ism_idx, - const int16_t *ratio_ism_idx_ref, /* ( i/o ) */ - const int16_t nchan_ism, - const int16_t shift_one, - const int16_t idx_sep_obj, - int16_t *p_nbits0, - int16_t *p_nbits1 ) -{ - int16_t diff_idx[MAX_NUM_OBJECTS]; - int16_t nbits0, nbits1; - int16_t i; + IF( shift_one ) + { + remove_sep_obj_fx( diff_idx, nchan_ism, idx_sep_obj_local ); + } - nbits0 = 0; - nbits1 = 0; + transform_index_and_GR_encode_ivas_fx( diff_idx, sub( sub( nchan_ism, 1 ), shift_one ), GR_order, hMetaData ); - /* take difference with respect to previous subframe */ - v_sub_s( ratio_ism_idx, ratio_ism_idx_ref, diff_idx, nchan_ism ); + Copy( ratio_ism_idx[b], ratio_ism_idx_ref, sub( nchan_ism, shift_one ) ); + } + } + } + } + } + } + ELSE + { + /* only differential wrt previous subframe is possible */ + /* write the differential to subframe case and no bit to signal the difference type */ - if ( shift_one ) - { - remove_sep_obj( diff_idx, nchan_ism, idx_sep_obj ); + IF( nbits > 0 ) + { + /* write GR order */ + push_next_indice( hMetaData, GR_order, 1 ); + nbits = add( nbits, 1 ); /* for GR_order */ + /* write data */ + /* only one subband */ + IF( LT_32( masa_to_total_energy_ratio[0], MASA2TOTAL_THR_Q30 ) ) + { + /* take difference with respect to previous subframe */ + v_sub_s16_fx( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, nchan_ism ); + + IF( shift_one ) + { + remove_sep_obj_fx( diff_idx, nchan_ism, idx_sep_obj_local ); + } + + transform_index_and_GR_encode_ivas_fx( diff_idx, sub( sub( nchan_ism, 1 ), shift_one ), GR_order, hMetaData ); + } + } + } + } } - /* transform difference index into positive */ - transform_difference_index( diff_idx, diff_idx, nchan_ism - 1 - shift_one ); + return nbits; +} +#endif +#ifndef IVAS_FLOAT_FIXED +static void ivas_encode_masaism_metadata( + MASA_ENCODER_HANDLE hMasa, + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + const int16_t nchan_ism, /* i : number of ISM channels */ + const int16_t low_bitrate_mode, /* i : is low bitrate more? 1/0 */ + const int16_t omasa_nbands, + const int16_t omasa_nblocks, + const int16_t idx_separated_object, + const int16_t ism_imp ) +{ + int16_t sf, band; + uint8_t numCodingBands; + uint8_t numSf; + int16_t brange[2]; + float eneBand; + int16_t bin; + int16_t obj; + int16_t bits_ism[MAX_NUM_OBJECTS]; + uint16_t idx_sph; + float theta_q, phi_q; + uint16_t index_theta, index_phi; + float ratio_ism[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + float step; + int16_t inv_step; + float energy_ism, energy_ism_ind[MAX_NUM_OBJECTS]; + int16_t tmp, rotate; + int16_t n_ism_tmp, i; + OMASA_ENCODER_DATA_HANDLE hOmasaData = hMasa->data.hOmasaData; + int16_t nbands_work; - /* GR encoding */ - for ( i = 0; i < nchan_ism - 1 - shift_one; i++ ) + /* use the values from hQMetaData */ + numCodingBands = (uint8_t) hQMetaData->q_direction->cfg.nbands; + numSf = (int8_t) hQMetaData->q_direction->cfg.nblocks; + nbands_work = min( numCodingBands, omasa_nbands ); + if ( numCodingBands == 1 ) { - nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); - nbits1 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ); - } - - *p_nbits0 = nbits0; - *p_nbits1 = nbits1; - - return; -} + for ( sf = 0; sf < numSf; sf++ ) + { + if ( sum_f( hOmasaData->energy_ism[sf], omasa_nbands ) == 0.0f ) + { + hOmasaData->masa_to_total_energy_ratio[sf][0] = 1.0f; + } + else + { + brange[0] = hMasa->data.band_mapping[0]; + brange[1] = hMasa->data.band_mapping[omasa_nbands]; + eneBand = 0.0f; + for ( bin = brange[0]; bin < brange[1]; bin++ ) + { + eneBand += hMasa->data.energy[sf][bin]; + } + energy_ism = 0.0f; + for ( obj = 0; obj < nchan_ism; obj++ ) + { + energy_ism_ind[obj] = 0.0f; + } -static int16_t encode_ratio_ism_subframe( - int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], - const int16_t nchan_ism, - const uint8_t numCodingBands, - const int16_t sf, - int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], - BSTR_ENC_HANDLE hMetaData, - // const float *masa_to_total_energy_ratio, - float *masa_to_total_energy_ratio, - const int16_t shift_one, - const int16_t idx_separated_obj ) -{ - int16_t b, b_signif; - int16_t diff_idx[MAX_NUM_OBJECTS]; - int16_t nbits, nbits0, nbits1, GR_order, GR_order_sb; - int16_t differential_subframe; - int16_t ratio_ism_idx_ref[MAX_NUM_OBJECTS]; - int16_t bits_index; - int16_t nbits00, nbits11; - int16_t idx_sep_obj_local; + for ( band = 0; band < omasa_nbands; band++ ) + { + energy_ism += hOmasaData->energy_ism[sf][band]; + for ( obj = 0; obj < nchan_ism; obj++ ) + { + energy_ism_ind[obj] += hOmasaData->energy_ism[sf][band] * hOmasaData->energy_ratio_ism[sf][band][obj]; + } + } - idx_sep_obj_local = idx_separated_obj; - if ( idx_separated_obj > -1 ) - { - if ( idx_separated_obj == nchan_ism - 1 ) - { - idx_sep_obj_local = 0; + for ( obj = 0; obj < nchan_ism; obj++ ) + { + hOmasaData->energy_ratio_ism[sf][0][obj] = energy_ism_ind[obj] / energy_ism; + } + hOmasaData->masa_to_total_energy_ratio[sf][0] = eneBand / ( eneBand + energy_ism + EPSILON ); + } } } - nbits = 0; - nbits0 = 0; - nbits1 = 0; - - differential_subframe = 1; /* the differences are taken with respect to previous subframe */ - - /* first subframe */ - bits_index = 0; - if ( sf == 0 ) + else if ( numSf == 1 ) { -#ifndef IVAS_FLOAT_FIXED - bits_index = bits_index_ism_ratio( nchan_ism ); -#else - bits_index = bits_index_ism_ratio_fx( nchan_ism ); -#endif - - nbits = 0; - for ( b = 0; b < numCodingBands; b++ ) + for ( band = 0; band < nbands_work; band++ ) { - if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + energy_ism = 0.0f; /* ISM energy for current subband */ + for ( obj = 0; obj < nchan_ism; obj++ ) { - nbits += bits_index; + energy_ism_ind[obj] = 0.0f; + } + for ( sf = 0; sf < omasa_nblocks; sf++ ) + { + energy_ism += hOmasaData->energy_ism[sf][band]; + for ( obj = 0; obj < nchan_ism; obj++ ) + { + energy_ism_ind[obj] += hOmasaData->energy_ism[sf][band] * hOmasaData->energy_ratio_ism[sf][band][obj]; + } } - } - nbits0 = try_differential( numCodingBands, masa_to_total_energy_ratio, ratio_ism_idx, nchan_ism, bits_index, &b_signif ); + if ( energy_ism == 0.0f ) + { + hOmasaData->masa_to_total_energy_ratio[0][band] = 1.0f; + } + else + { + for ( obj = 0; obj < nchan_ism; obj++ ) + { + hOmasaData->energy_ratio_ism[0][band][obj] = energy_ism_ind[obj] / energy_ism; + } + brange[0] = hMasa->data.band_mapping[band]; + brange[1] = hMasa->data.band_mapping[band + 1]; - if ( nbits <= nbits0 && nbits > 0 ) - { - /* independent encoding */ - push_next_indice( hMetaData, 1, 1 ); - independent_coding_ratio_ism_idx( ratio_ism_idx, masa_to_total_energy_ratio, nchan_ism, numCodingBands, bits_index, hMetaData ); - nbits = nbits + 1; + eneBand = 0.0f; + for ( sf = 0; sf < omasa_nblocks; sf++ ) + { + for ( bin = brange[0]; bin < brange[1]; bin++ ) + { + eneBand += hMasa->data.energy[sf][bin]; + } + } + hOmasaData->masa_to_total_energy_ratio[0][band] = eneBand / ( eneBand + energy_ism + EPSILON ); + } } - else + for ( band = nbands_work; band < numCodingBands; band++ ) { - if ( nbits > 0 ) + hOmasaData->masa_to_total_energy_ratio[0][band] = 1.0f; + + for ( obj = 0; obj < nchan_ism; obj++ ) { -#ifndef IVAS_FLOAT_FIXED - differential_coding_first_subframe( hMetaData, masa_to_total_energy_ratio, b_signif, ratio_ism_idx, nchan_ism, numCodingBands, bits_index ); -#else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word32 masa_to_total_energy_ratio_fx[MASA_FREQUENCY_BANDS]; - floatToFixed_arrL( masa_to_total_energy_ratio, masa_to_total_energy_ratio_fx, 30, MASA_FREQUENCY_BANDS ); -#endif - differential_coding_first_subframe_ivas_fx( hMetaData, masa_to_total_energy_ratio_fx, b_signif, ratio_ism_idx, nchan_ism, numCodingBands, bits_index ); -#endif - nbits = nbits0 + 1; + hOmasaData->energy_ratio_ism[0][band][obj] = hOmasaData->energy_ratio_ism[0][nbands_work - 1][obj]; } } } else { - /* not first subframe */ - if ( shift_one == 1 && nchan_ism == 2 ) - { - nbits = 0; - } - else + for ( sf = 0; sf < numSf; sf++ ) { - nbits0 = 0; - nbits1 = 0; - - for ( b = 0; b < numCodingBands; b++ ) + for ( band = 0; band < nbands_work; band++ ) { - if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + if ( hOmasaData->energy_ism[sf][band] == 0.0f ) { - estimate_bits_subband_ism_ratio( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], nchan_ism, shift_one, idx_sep_obj_local, &nbits00, &nbits11 ); - nbits0 += nbits00; - nbits1 += nbits11; + hOmasaData->masa_to_total_energy_ratio[sf][band] = 1.0f; + } + else + { + brange[0] = hMasa->data.band_mapping[band]; + brange[1] = hMasa->data.band_mapping[band + 1]; + + eneBand = 0.0f; + for ( bin = brange[0]; bin < brange[1]; bin++ ) + { + eneBand += hMasa->data.energy[sf][bin]; + } + hOmasaData->masa_to_total_energy_ratio[sf][band] = eneBand / ( eneBand + hOmasaData->energy_ism[sf][band] + EPSILON ); } } - if ( nbits0 < nbits1 ) - { - GR_order = 0; - nbits = nbits0; - } - else + for ( band = nbands_work; band < numCodingBands; band++ ) { - GR_order = 1; - nbits = nbits1; + hOmasaData->masa_to_total_energy_ratio[sf][band] = 1.0f; + + for ( obj = 0; obj < nchan_ism; obj++ ) + { + hOmasaData->energy_ratio_ism[sf][band][obj] = hOmasaData->energy_ratio_ism[sf][nbands_work - 1][obj]; + } } + } + } - if ( numCodingBands > 1 ) + ivas_omasa_encode_masa_to_total( hOmasaData->masa_to_total_energy_ratio, hMetaData, low_bitrate_mode, numCodingBands, numSf ); + + /* quantize ism_ratios */ + if ( nchan_ism > 1 ) + { + inv_step = ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ); + step = 1.0f / inv_step; + + rotate = 0; + n_ism_tmp = 0; + + for ( sf = 0; sf < numSf; sf++ ) + { + for ( band = 0; band < numCodingBands; band++ ) { - /* try the difference from subband to subband; first subband is compared to previous subframe first subband*/ - /* take difference with respect to previous subframe only for first subband */ - nbits0 = 0; - nbits1 = 0; - b_signif = 0; - while ( ( b_signif < numCodingBands ) && ( masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR ) ) + for ( obj = 0; obj < nchan_ism; obj++ ) { - b_signif++; + assert( ( hOmasaData->energy_ratio_ism[sf][band][obj] >= 0 ) && ( hOmasaData->energy_ratio_ism[sf][band][obj] <= 1 ) ); + ratio_ism[band][obj] = hOmasaData->energy_ratio_ism[sf][band][obj]; } - if ( b_signif < numCodingBands ) + /* Quantize ISM ratios */ +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 ratio_ism_fx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + + Word16 ratio_ism_fx_q = Q_factor_arr( ratio_ism[band], nchan_ism ); + + floatToFixed_arr( ratio_ism[band], ratio_ism_fx[band], ratio_ism_fx_q, nchan_ism ); + + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + floatToFixed_arrL( hOmasaData->masa_to_total_energy_ratio[i], hOmasaData->masa_to_total_energy_ratio_fx[i], Q30, MASA_FREQUENCY_BANDS ); + } +#endif + quantize_ratio_ism_vector_ivas_fx( ratio_ism_fx[band], sub( Q15, ratio_ism_fx_q ), ratio_ism_idx[band], nchan_ism, hOmasaData->masa_to_total_energy_ratio_fx[sf][band], idx_separated_object ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( ratio_ism_fx[band], ratio_ism[band], ratio_ism_fx_q, nchan_ism ); + + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + fixedToFloat_arrL( hOmasaData->masa_to_total_energy_ratio_fx[i], hOmasaData->masa_to_total_energy_ratio[i], Q30, MASA_FREQUENCY_BANDS ); + } +#endif +#else + quantize_ratio_ism_vector( ratio_ism[band], ratio_ism_idx[band], nchan_ism, hOmasaData->masa_to_total_energy_ratio[sf][band], idx_separated_object ); +#endif + if ( n_ism_tmp == numCodingBands && ratio_ism_idx[band][idx_separated_object] != 0 && hOmasaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) { - estimate_bits_subband_ism_ratio( ratio_ism_idx[b_signif], ratio_ism_idx_prev_sf[b_signif], nchan_ism, shift_one, idx_sep_obj_local, &nbits0, &nbits1 ); - - mvs2s( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism ); - - for ( b = b_signif + 1; b < numCodingBands; b++ ) + i = 0; + while ( ratio_ism_idx[band][idx_separated_object] > 0 ) { - if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + if ( i != idx_separated_object ) { - estimate_bits_subband_ism_ratio( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism, shift_one, idx_sep_obj_local, &nbits00, &nbits11 ); - nbits0 += nbits00; - nbits1 += nbits11; - mvs2s( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism ); + ratio_ism_idx[band][i]++; + ratio_ism_idx[band][idx_separated_object]--; + } + i++; + if ( i == nchan_ism ) + { + i = 0; } } + } - if ( nbits0 < nbits1 ) - { - GR_order_sb = 0; - } - else - { - GR_order_sb = 1; - nbits0 = nbits1; - } + /* reconstructed values */ +#ifndef IVAS_FLOAT_FIXED + reconstruct_ism_ratios( ratio_ism_idx[band], nchan_ism, step, hMasa->data.hOmasaData->q_energy_ratio_ism[sf][band] ); +#else + Word16 step_fx = float_to_fix16( step, Q15 ); - if ( nbits0 < nbits ) - { - differential_subframe = 0; - nbits = nbits0; - GR_order = GR_order_sb; - } + reconstruct_ism_ratios_fx( ratio_ism_idx[band], nchan_ism, step_fx, hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band] ); - if ( nbits > 0 ) - { - /* write prediction type */ - push_next_indice( hMetaData, differential_subframe, 1 ); - /* write GR order */ - push_next_indice( hMetaData, GR_order, 1 ); - nbits++; /* for the prediction type */ - nbits++; /* for GR_order */ + fixedToFloat_arrL( hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band], hMasa->data.hOmasaData->q_energy_ratio_ism[sf][band], Q30, nchan_ism ); +#endif + } - /* write data */ - if ( differential_subframe ) + if ( ( nchan_ism > 2 ) && ( idx_separated_object == nchan_ism - 1 ) ) + { + /* rotate components */ + rotate = 1; + for ( band = 0; band < numCodingBands; band++ ) + { + if ( hOmasaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) + { + tmp = ratio_ism_idx[band][nchan_ism - 1]; + ratio_ism_idx[band][nchan_ism - 1] = ratio_ism_idx[band][0]; + ratio_ism_idx[band][0] = tmp; + if ( sf == 0 && tmp == 0 ) { - for ( b = 0; b < numCodingBands; b++ ) - { - if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) - { - /* take difference with respect to previous subframe */ - v_sub_s( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], diff_idx, nchan_ism ); - - if ( shift_one ) - { - remove_sep_obj( diff_idx, nchan_ism, idx_sep_obj_local ); - } + n_ism_tmp += 1; + } - transform_index_and_GR_encode( diff_idx, nchan_ism - 1 - shift_one, GR_order, hMetaData ); - } - } + if ( n_ism_tmp == numCodingBands ) + { + assert( tmp == 0 ); } - else + } + } + } + else + { + if ( idx_separated_object > -1 ) + { + for ( band = 0; band < numCodingBands; band++ ) + { + if ( hOmasaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) { - v_sub_s( ratio_ism_idx[b_signif], ratio_ism_idx_prev_sf[b_signif], diff_idx, nchan_ism ); - - if ( shift_one ) - { - remove_sep_obj( diff_idx, nchan_ism, idx_sep_obj_local ); - } - - transform_index_and_GR_encode( diff_idx, nchan_ism - 1 - shift_one, GR_order, hMetaData ); - - mvs2s( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism - shift_one ); - - for ( b = b_signif + 1; b < numCodingBands; b++ ) + if ( ratio_ism_idx[band][idx_separated_object] == 0 && sf == 0 ) { - /* take difference with respect to previous subband */ - if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) - { - v_sub_s( ratio_ism_idx[b], ratio_ism_idx_ref, diff_idx, nchan_ism ); - - if ( shift_one ) - { - remove_sep_obj( diff_idx, nchan_ism, idx_sep_obj_local ); - } - - transform_index_and_GR_encode( diff_idx, nchan_ism - 1 - shift_one, GR_order, hMetaData ); - - mvs2s( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism - shift_one ); - } + n_ism_tmp++; } } } } } + + /* encode data for current subframe */ + if ( sf > 0 && n_ism_tmp == numCodingBands ) + { + encode_ratio_ism_subframe( ratio_ism_idx, nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hOmasaData->masa_to_total_energy_ratio[sf], 1, idx_separated_object ); + } else { - /* only differential wrt previous subframe is possible */ - /* write the differential to subframe case and no bit to signal the difference type */ + encode_ratio_ism_subframe( ratio_ism_idx, nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hOmasaData->masa_to_total_energy_ratio[sf], 0, idx_separated_object ); + } - if ( nbits > 0 ) + /* calculate quantized ISM ratios */ + /* save previous subframe indexes */ + for ( band = 0; band < numCodingBands; band++ ) + { + mvs2s( ratio_ism_idx[band], ratio_ism_idx_prev_sf[band], nchan_ism ); + } + + if ( rotate ) + { + for ( band = 0; band < numCodingBands; band++ ) { - /* write GR order */ - push_next_indice( hMetaData, GR_order, 1 ); - nbits++; /* for GR_order */ - /* write data */ - /* only one subband */ - if ( masa_to_total_energy_ratio[0] < MASA2TOTAL_THR ) + if ( hOmasaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) { - /* take difference with respect to previous subframe */ - v_sub_s( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, nchan_ism ); - - if ( shift_one ) - { - remove_sep_obj( diff_idx, nchan_ism, idx_sep_obj_local ); - } - - transform_index_and_GR_encode( diff_idx, nchan_ism - 1 - shift_one, GR_order, hMetaData ); + tmp = ratio_ism_idx[band][nchan_ism - 1]; + ratio_ism_idx[band][nchan_ism - 1] = ratio_ism_idx[band][0]; + ratio_ism_idx[band][0] = tmp; } } } } } - return nbits; -} +#ifndef IVAS_FLOAT_FIXED + calculate_nbits_meta( nchan_ism, hOmasaData->q_energy_ratio_ism, hOmasaData->masa_to_total_energy_ratio, numSf, numCodingBands, bits_ism, idx_separated_object, ism_imp ); +#else + FOR( sf = 0; sf < numSf; ++sf ) + { + FOR( band = 0; band < numCodingBands; ++band ) + { + floatToFixed_arr32( hOmasaData->q_energy_ratio_ism[sf][band], hOmasaData->q_energy_ratio_ism_fx[sf][band], Q30, nchan_ism ); + hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = floatToFixed_32( hOmasaData->masa_to_total_energy_ratio[sf][band], Q30 ); + } + } + calculate_nbits_meta_fx( nchan_ism, hOmasaData->q_energy_ratio_ism_fx, hOmasaData->masa_to_total_energy_ratio_fx, numSf, numCodingBands, bits_ism, idx_separated_object, ism_imp ); +#endif -static void ivas_encode_masaism_metadata( + /* quantize directions */ + for ( obj = 0; obj < nchan_ism; obj++ ) + { + if ( bits_ism[obj] < 8 ) + { + /* check is same as previous */ + if ( ( fabs( hIsmMeta[obj]->elevation - hIsmMeta[obj]->q_elevation_old ) < 0.01f ) && ( fabs( hIsmMeta[obj]->azimuth - hIsmMeta[obj]->q_azimuth_old ) < 0.01f ) ) + { + push_next_indice( hMetaData, 1, 1 ); + /* the old stays the same */ + } + else + { + push_next_indice( hMetaData, 0, 1 ); + idx_sph = quantize_direction( hIsmMeta[obj]->elevation, hIsmMeta[obj]->azimuth, bits_ism[obj], &theta_q, &phi_q, &index_theta, &index_phi, MC_LS_SETUP_INVALID ); + push_next_indice( hMetaData, idx_sph, bits_ism[obj] ); + hIsmMeta[obj]->q_elevation_old = hIsmMeta[obj]->elevation; + hIsmMeta[obj]->q_azimuth_old = hIsmMeta[obj]->azimuth; + } + } + else + { + idx_sph = quantize_direction( hIsmMeta[obj]->elevation, hIsmMeta[obj]->azimuth, bits_ism[obj], &theta_q, &phi_q, &index_theta, &index_phi, MC_LS_SETUP_INVALID ); + push_next_indice( hMetaData, idx_sph, bits_ism[obj] ); + hIsmMeta[obj]->q_elevation_old = hIsmMeta[obj]->elevation; + hIsmMeta[obj]->q_azimuth_old = hIsmMeta[obj]->azimuth; + } + } + + return; +} +#else +static void ivas_encode_masaism_metadata_fx( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - const int16_t nchan_ism, /* i : number of ISM channels */ - const int16_t low_bitrate_mode, /* i : is low bitrate more? 1/0 */ - const int16_t omasa_nbands, - const int16_t omasa_nblocks, - const int16_t idx_separated_object, - const int16_t ism_imp ) + const Word16 nchan_ism, /* i : number of ISM channels */ + const Word16 low_bitrate_mode, /* i : is low bitrate more? 1/0 */ + const Word16 omasa_nbands, + const Word16 omasa_nblocks, + const Word16 idx_separated_object, + const Word16 ism_imp ) { - int16_t sf, band; - uint8_t numCodingBands; - uint8_t numSf; - int16_t brange[2]; - float eneBand; - int16_t bin; - int16_t obj; - int16_t bits_ism[MAX_NUM_OBJECTS]; - uint16_t idx_sph; - float theta_q, phi_q; - uint16_t index_theta, index_phi; - float ratio_ism[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; - int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; - float step; - int16_t inv_step; - float energy_ism, energy_ism_ind[MAX_NUM_OBJECTS]; - int16_t tmp, rotate; - int16_t n_ism_tmp, i; + Word16 sf, band; + UWord8 numCodingBands; + UWord8 numSf; + Word16 brange[2]; + Word32 eneBand; + Word16 bin; + Word16 obj; + Word16 bits_ism[MAX_NUM_OBJECTS]; + UWord16 idx_sph; + Word32 theta_q, phi_q; + UWord16 index_theta, index_phi; + Word16 ratio_ism_fx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + Word16 step; + Word32 energy_ism, energy_ism_ind[MAX_NUM_OBJECTS]; + Word16 tmp, rotate, energy_ism_e, energy_ism_ind_e[MAX_NUM_OBJECTS]; + Word16 n_ism_tmp, i; OMASA_ENCODER_DATA_HANDLE hOmasaData = hMasa->data.hOmasaData; - int16_t nbands_work; + Word16 nbands_work; + Word32 L_tmp; + Word16 L_tmp_e; /* use the values from hQMetaData */ - numCodingBands = (uint8_t) hQMetaData->q_direction->cfg.nbands; - numSf = (int8_t) hQMetaData->q_direction->cfg.nblocks; - nbands_work = min( numCodingBands, omasa_nbands ); - if ( numCodingBands == 1 ) + numCodingBands = (UWord8) hQMetaData->q_direction->cfg.nbands; + numSf = (Word8) hQMetaData->q_direction->cfg.nblocks; + nbands_work = s_min( numCodingBands, omasa_nbands ); + move16(); + move16(); + IF( EQ_16( numCodingBands, 1 ) ) { - for ( sf = 0; sf < numSf; sf++ ) + FOR( sf = 0; sf < numSf; sf++ ) { - if ( sum_f( hOmasaData->energy_ism[sf], omasa_nbands ) == 0.0f ) + L_tmp = 0; + L_tmp_e = 0; + move32(); + move16(); + FOR( i = 0; i < omasa_nbands; i++ ) { - hOmasaData->masa_to_total_energy_ratio[sf][0] = 1.0f; + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, hOmasaData->energy_ism_fx[sf][i], hOmasaData->energy_ism_fx_e[sf][i], &L_tmp_e ); } - else + /* if ( sum_f( hOmasaData->energy_ism[sf], omasa_nbands ) == 0.0f ) */ + IF( L_tmp == 0 ) + { + hOmasaData->masa_to_total_energy_ratio_fx[sf][0] = ONE_IN_Q30; // 1.0f in Q30 + move32(); + } + ELSE { brange[0] = hMasa->data.band_mapping[0]; brange[1] = hMasa->data.band_mapping[omasa_nbands]; - eneBand = 0.0f; - for ( bin = brange[0]; bin < brange[1]; bin++ ) + eneBand = 0; + move16(); + move16(); + move32(); + FOR( bin = brange[0]; bin < brange[1]; bin++ ) { - eneBand += hMasa->data.energy[sf][bin]; + eneBand = L_add( eneBand, hMasa->data.energy_fx[sf][bin] ); // hMasa->data.q_energy } - energy_ism = 0.0f; - for ( obj = 0; obj < nchan_ism; obj++ ) + energy_ism = 0; + energy_ism_e = 0; + move32(); + move16(); + FOR( obj = 0; obj < nchan_ism; obj++ ) { - energy_ism_ind[obj] = 0.0f; + energy_ism_ind[obj] = 0; + energy_ism_ind_e[obj] = 0; + move32(); + move16(); } - for ( band = 0; band < omasa_nbands; band++ ) + FOR( band = 0; band < omasa_nbands; band++ ) { - energy_ism += hOmasaData->energy_ism[sf][band]; - for ( obj = 0; obj < nchan_ism; obj++ ) + energy_ism = BASOP_Util_Add_Mant32Exp( energy_ism, energy_ism_e, hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ism_fx_e[sf][band], &energy_ism_e ); + FOR( obj = 0; obj < nchan_ism; obj++ ) { - energy_ism_ind[obj] += hOmasaData->energy_ism[sf][band] * hOmasaData->energy_ratio_ism[sf][band][obj]; + L_tmp = Mpy_32_32( hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ratio_ism_fx[sf][band][obj] ); // Q = (31 - hOmasaData->energy_ism_fx_e[sf][band]) + Q30 - 31 + L_tmp_e = sub( 30, hOmasaData->energy_ism_fx_e[sf][band] ); + energy_ism_ind[obj] = BASOP_Util_Add_Mant32Exp( energy_ism_ind[obj], energy_ism_ind_e[obj], L_tmp, L_tmp_e, &energy_ism_ind_e[obj] ); + move32(); } } - for ( obj = 0; obj < nchan_ism; obj++ ) + FOR( obj = 0; obj < nchan_ism; obj++ ) { - hOmasaData->energy_ratio_ism[sf][0][obj] = energy_ism_ind[obj] / energy_ism; + hOmasaData->energy_ratio_ism_fx[sf][0][obj] = BASOP_Util_Divide3232_Scale_cadence( energy_ism_ind[obj], energy_ism, &L_tmp_e ); + move32(); + L_tmp_e = add( L_tmp_e, sub( energy_ism_ind_e[obj], energy_ism_e ) ); + /* Scaling to Q30 */ + hOmasaData->energy_ratio_ism_fx[sf][0][obj] = L_shl( hOmasaData->energy_ratio_ism_fx[sf][0][obj], sub( L_tmp_e, 1 ) ); // Q30 + move32(); + } + + L_tmp = BASOP_Util_Add_Mant32Exp( eneBand, sub( 31, hMasa->data.q_energy ), energy_ism, energy_ism_e, &L_tmp_e ); + IF( L_tmp != 0 ) + { + hOmasaData->masa_to_total_energy_ratio_fx[sf][0] = BASOP_Util_Divide3232_Scale_cadence( eneBand, L_tmp, &tmp ); + move32(); + tmp = add( tmp, sub( sub( 31, hMasa->data.q_energy ), L_tmp_e ) ); + /* Scaling to Q30 */ + hOmasaData->masa_to_total_energy_ratio_fx[sf][0] = L_shl( hOmasaData->masa_to_total_energy_ratio_fx[sf][0], sub( tmp, 1 ) ); // Q30 + move32(); + } + ELSE + { + hOmasaData->masa_to_total_energy_ratio_fx[sf][0] = MAX_32; + move32(); } - hOmasaData->masa_to_total_energy_ratio[sf][0] = eneBand / ( eneBand + energy_ism + EPSILON ); } } } - else if ( numSf == 1 ) + ELSE IF( EQ_16( numSf, 1 ) ) { - for ( band = 0; band < nbands_work; band++ ) + FOR( band = 0; band < nbands_work; band++ ) { - energy_ism = 0.0f; /* ISM energy for current subband */ - for ( obj = 0; obj < nchan_ism; obj++ ) + energy_ism = 0; /* ISM energy for current subband */ + energy_ism_e = 0; /* ISM energy for current subband */ + move32(); + move16(); + FOR( obj = 0; obj < nchan_ism; obj++ ) { - energy_ism_ind[obj] = 0.0f; + energy_ism_ind[obj] = 0; + energy_ism_ind_e[obj] = 0; + move32(); + move16(); } - for ( sf = 0; sf < omasa_nblocks; sf++ ) + FOR( sf = 0; sf < omasa_nblocks; sf++ ) { - energy_ism += hOmasaData->energy_ism[sf][band]; - for ( obj = 0; obj < nchan_ism; obj++ ) + energy_ism = BASOP_Util_Add_Mant32Exp( energy_ism, energy_ism_e, hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ism_fx_e[sf][band], &energy_ism_e ); + FOR( obj = 0; obj < nchan_ism; obj++ ) { - energy_ism_ind[obj] += hOmasaData->energy_ism[sf][band] * hOmasaData->energy_ratio_ism[sf][band][obj]; + L_tmp = Mpy_32_32( hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ratio_ism_fx[sf][band][obj] ); // Q = (31 - hOmasaData->energy_ism_fx_e[sf][band]) + Q30 - 31 + L_tmp_e = add( 1, hOmasaData->energy_ism_fx_e[sf][band] ); + energy_ism_ind[obj] = BASOP_Util_Add_Mant32Exp( energy_ism_ind[obj], energy_ism_ind_e[obj], L_tmp, L_tmp_e, &energy_ism_ind_e[obj] ); + move32(); } } - if ( energy_ism == 0.0f ) + IF( energy_ism == 0 ) { - hOmasaData->masa_to_total_energy_ratio[0][band] = 1.0f; + hOmasaData->masa_to_total_energy_ratio_fx[0][band] = ONE_IN_Q30; // 1.0f in Q30 + move32(); } - else + ELSE { - for ( obj = 0; obj < nchan_ism; obj++ ) + FOR( obj = 0; obj < nchan_ism; obj++ ) { - hOmasaData->energy_ratio_ism[0][band][obj] = energy_ism_ind[obj] / energy_ism; + hOmasaData->energy_ratio_ism_fx[0][band][obj] = BASOP_Util_Divide3232_Scale_cadence( energy_ism_ind[obj], energy_ism, &L_tmp_e ); + move32(); + L_tmp_e = add( L_tmp_e, sub( energy_ism_ind_e[obj], energy_ism_e ) ); + /* Scaling to Q30 */ + hOmasaData->energy_ratio_ism_fx[0][band][obj] = L_shl( hOmasaData->energy_ratio_ism_fx[0][band][obj], sub( L_tmp_e, 1 ) ); // Q30 + move32(); } brange[0] = hMasa->data.band_mapping[band]; brange[1] = hMasa->data.band_mapping[band + 1]; + move16(); + move16(); - eneBand = 0.0f; - for ( sf = 0; sf < omasa_nblocks; sf++ ) + eneBand = 0; + move32(); + FOR( sf = 0; sf < omasa_nblocks; sf++ ) { - for ( bin = brange[0]; bin < brange[1]; bin++ ) + FOR( bin = brange[0]; bin < brange[1]; bin++ ) { - eneBand += hMasa->data.energy[sf][bin]; + eneBand = L_add( eneBand, hMasa->data.energy_fx[sf][bin] ); // hMasa->data.q_energy } } - hOmasaData->masa_to_total_energy_ratio[0][band] = eneBand / ( eneBand + energy_ism + EPSILON ); + + L_tmp = BASOP_Util_Add_Mant32Exp( eneBand, sub( 31, hMasa->data.q_energy ), energy_ism, energy_ism_e, &L_tmp_e ); + IF( L_tmp != 0 ) + { + hOmasaData->masa_to_total_energy_ratio_fx[0][band] = BASOP_Util_Divide3232_Scale_cadence( eneBand, L_tmp, &tmp ); + move32(); + tmp = add( tmp, sub( sub( 31, hMasa->data.q_energy ), L_tmp_e ) ); + /* Scaling to Q30 */ + hOmasaData->masa_to_total_energy_ratio_fx[0][band] = L_shl( hOmasaData->masa_to_total_energy_ratio_fx[0][band], sub( tmp, 1 ) ); // Q30 + move32(); + } + ELSE + { + hOmasaData->masa_to_total_energy_ratio_fx[0][band] = MAX_32; + move32(); + } } } - for ( band = nbands_work; band < numCodingBands; band++ ) + FOR( band = nbands_work; band < numCodingBands; band++ ) { - hOmasaData->masa_to_total_energy_ratio[0][band] = 1.0f; + hOmasaData->masa_to_total_energy_ratio_fx[0][band] = ONE_IN_Q30; + move32(); - for ( obj = 0; obj < nchan_ism; obj++ ) + FOR( obj = 0; obj < nchan_ism; obj++ ) { - hOmasaData->energy_ratio_ism[0][band][obj] = hOmasaData->energy_ratio_ism[0][nbands_work - 1][obj]; + hOmasaData->energy_ratio_ism_fx[0][band][obj] = hOmasaData->energy_ratio_ism_fx[0][nbands_work - 1][obj]; + move32(); } } } - else + ELSE { - for ( sf = 0; sf < numSf; sf++ ) + FOR( sf = 0; sf < numSf; sf++ ) { - for ( band = 0; band < nbands_work; band++ ) + FOR( band = 0; band < nbands_work; band++ ) { - if ( hOmasaData->energy_ism[sf][band] == 0.0f ) + IF( hOmasaData->energy_ism_fx[sf][band] == 0 ) { - hOmasaData->masa_to_total_energy_ratio[sf][band] = 1.0f; + hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = ONE_IN_Q30; + move32(); } - else + ELSE { brange[0] = hMasa->data.band_mapping[band]; brange[1] = hMasa->data.band_mapping[band + 1]; + move16(); + move16(); - eneBand = 0.0f; - for ( bin = brange[0]; bin < brange[1]; bin++ ) + eneBand = 0; + move32(); + FOR( bin = brange[0]; bin < brange[1]; bin++ ) { - eneBand += hMasa->data.energy[sf][bin]; + eneBand = L_add( eneBand, hMasa->data.energy_fx[sf][bin] ); // hMasa->data.q_energy + } + + L_tmp = BASOP_Util_Add_Mant32Exp( eneBand, sub( 31, hMasa->data.q_energy ), hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ism_fx_e[sf][band], &L_tmp_e ); + IF( L_tmp != 0 ) + { + hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = BASOP_Util_Divide3232_Scale_cadence( eneBand, L_tmp, &tmp ); + move32(); + tmp = add( tmp, sub( sub( 31, hMasa->data.q_energy ), L_tmp_e ) ); + /* Scaling to Q30 */ + hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = L_shl( hOmasaData->masa_to_total_energy_ratio_fx[sf][band], sub( tmp, 1 ) ); // Q30 + move32(); + } + ELSE + { + hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = MAX_32; + move32(); } - hOmasaData->masa_to_total_energy_ratio[sf][band] = eneBand / ( eneBand + hOmasaData->energy_ism[sf][band] + EPSILON ); } } - for ( band = nbands_work; band < numCodingBands; band++ ) + FOR( band = nbands_work; band < numCodingBands; band++ ) { - hOmasaData->masa_to_total_energy_ratio[sf][band] = 1.0f; + hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = ONE_IN_Q30; + move32(); - for ( obj = 0; obj < nchan_ism; obj++ ) + FOR( obj = 0; obj < nchan_ism; obj++ ) { - hOmasaData->energy_ratio_ism[sf][band][obj] = hOmasaData->energy_ratio_ism[sf][nbands_work - 1][obj]; + hOmasaData->energy_ratio_ism_fx[sf][band][obj] = hOmasaData->energy_ratio_ism_fx[sf][nbands_work - 1][obj]; + move32(); } } } } - ivas_omasa_encode_masa_to_total( hOmasaData->masa_to_total_energy_ratio, hMetaData, low_bitrate_mode, numCodingBands, numSf ); + + ivas_omasa_encode_masa_to_total_fx( hOmasaData->masa_to_total_energy_ratio_fx, hMetaData, low_bitrate_mode, numCodingBands, numSf ); /* quantize ism_ratios */ - if ( nchan_ism > 1 ) + IF( GT_16( nchan_ism, 1 ) ) { - inv_step = ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ); - step = 1.0f / inv_step; + /* inv_step = ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ); * + * step = 1.0f / inv_step; */ + step = 4681; // 1.f / ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) => 1.f / 7 in Q15 + move16(); rotate = 0; n_ism_tmp = 0; + move16(); + move16(); - for ( sf = 0; sf < numSf; sf++ ) + FOR( sf = 0; sf < numSf; sf++ ) { - for ( band = 0; band < numCodingBands; band++ ) + FOR( band = 0; band < numCodingBands; band++ ) { - for ( obj = 0; obj < nchan_ism; obj++ ) + FOR( obj = 0; obj < nchan_ism; obj++ ) { - assert( ( hOmasaData->energy_ratio_ism[sf][band][obj] >= 0 ) && ( hOmasaData->energy_ratio_ism[sf][band][obj] <= 1 ) ); - ratio_ism[band][obj] = hOmasaData->energy_ratio_ism[sf][band][obj]; + assert( ( hOmasaData->energy_ratio_ism_fx[sf][band][obj] >= 0 ) && ( hOmasaData->energy_ratio_ism_fx[sf][band][obj] <= ONE_IN_Q30 ) ); + ratio_ism_fx[band][obj] = extract_h( hOmasaData->energy_ratio_ism_fx[sf][band][obj] ); // Q14 + move16(); } /* Quantize ISM ratios */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 ratio_ism_fx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; - - Word16 ratio_ism_fx_q = Q_factor_arr( ratio_ism[band], nchan_ism ); - - floatToFixed_arr( ratio_ism[band], ratio_ism_fx[band], ratio_ism_fx_q, nchan_ism ); - - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - floatToFixed_arrL( hOmasaData->masa_to_total_energy_ratio[i], hOmasaData->masa_to_total_energy_ratio_fx[i], Q30, MASA_FREQUENCY_BANDS ); - } -#endif - quantize_ratio_ism_vector_ivas_fx( ratio_ism_fx[band], sub( Q15, ratio_ism_fx_q ), ratio_ism_idx[band], nchan_ism, hOmasaData->masa_to_total_energy_ratio_fx[sf][band], idx_separated_object ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( ratio_ism_fx[band], ratio_ism[band], ratio_ism_fx_q, nchan_ism ); + quantize_ratio_ism_vector_ivas_fx( ratio_ism_fx[band], 1 /* Q14 */, ratio_ism_idx[band], nchan_ism, hOmasaData->masa_to_total_energy_ratio_fx[sf][band], idx_separated_object ); - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - fixedToFloat_arrL( hOmasaData->masa_to_total_energy_ratio_fx[i], hOmasaData->masa_to_total_energy_ratio[i], Q30, MASA_FREQUENCY_BANDS ); - } -#endif -#else - quantize_ratio_ism_vector( ratio_ism[band], ratio_ism_idx[band], nchan_ism, hOmasaData->masa_to_total_energy_ratio[sf][band], idx_separated_object ); -#endif - if ( n_ism_tmp == numCodingBands && ratio_ism_idx[band][idx_separated_object] != 0 && hOmasaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) + test(); + test(); + IF( EQ_16( n_ism_tmp, numCodingBands ) && ratio_ism_idx[band][idx_separated_object] != 0 && LT_32( hOmasaData->masa_to_total_energy_ratio_fx[sf][band], MASA2TOTAL_THR_Q30 ) ) { i = 0; - while ( ratio_ism_idx[band][idx_separated_object] > 0 ) + move16(); + WHILE( ratio_ism_idx[band][idx_separated_object] > 0 ) { - if ( i != idx_separated_object ) + IF( NE_16( i, idx_separated_object ) ) { - ratio_ism_idx[band][i]++; - ratio_ism_idx[band][idx_separated_object]--; + ratio_ism_idx[band][i] = add( ratio_ism_idx[band][i], 1 ); + ratio_ism_idx[band][idx_separated_object] = sub( ratio_ism_idx[band][idx_separated_object], 1 ); + move16(); + move16(); } - i++; - if ( i == nchan_ism ) + i = add( i, 1 ); + if ( EQ_16( i, nchan_ism ) ) { i = 0; + move16(); } } } /* reconstructed values */ -#ifndef IVAS_FLOAT_FIXED - reconstruct_ism_ratios( ratio_ism_idx[band], nchan_ism, step, hMasa->data.hOmasaData->q_energy_ratio_ism[sf][band] ); -#else - Word16 step_fx = float_to_fix16( step, Q15 ); - - reconstruct_ism_ratios_fx( ratio_ism_idx[band], nchan_ism, step_fx, hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band] ); - - fixedToFloat_arrL( hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band], hMasa->data.hOmasaData->q_energy_ratio_ism[sf][band], Q30, nchan_ism ); -#endif + reconstruct_ism_ratios_fx( ratio_ism_idx[band], nchan_ism, step, hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band] ); } - - if ( ( nchan_ism > 2 ) && ( idx_separated_object == nchan_ism - 1 ) ) + test(); + IF( GT_16( nchan_ism, 2 ) && EQ_16( idx_separated_object, sub( nchan_ism, 1 ) ) ) { /* rotate components */ rotate = 1; - for ( band = 0; band < numCodingBands; band++ ) + move16(); + FOR( band = 0; band < numCodingBands; band++ ) { - if ( hOmasaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) + IF( LT_32( hOmasaData->masa_to_total_energy_ratio_fx[sf][band], MASA2TOTAL_THR_Q30 ) ) { tmp = ratio_ism_idx[band][nchan_ism - 1]; ratio_ism_idx[band][nchan_ism - 1] = ratio_ism_idx[band][0]; ratio_ism_idx[band][0] = tmp; - if ( sf == 0 && tmp == 0 ) + move16(); + move16(); + move16(); + test(); + IF( sf == 0 && tmp == 0 ) { - n_ism_tmp += 1; + n_ism_tmp = add( n_ism_tmp, 1 ); } - if ( n_ism_tmp == numCodingBands ) + if ( EQ_16( n_ism_tmp, numCodingBands ) ) { assert( tmp == 0 ); } } } } - else + ELSE { - if ( idx_separated_object > -1 ) + IF( GT_16( idx_separated_object, -1 ) ) { - for ( band = 0; band < numCodingBands; band++ ) + FOR( band = 0; band < numCodingBands; band++ ) { - if ( hOmasaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) + IF( LT_32( hOmasaData->masa_to_total_energy_ratio_fx[sf][band], MASA2TOTAL_THR_Q30 ) ) { - if ( ratio_ism_idx[band][idx_separated_object] == 0 && sf == 0 ) + test(); + IF( ratio_ism_idx[band][idx_separated_object] == 0 && sf == 0 ) { - n_ism_tmp++; + n_ism_tmp = add( n_ism_tmp, 1 ); } } } @@ -7307,84 +8605,80 @@ static void ivas_encode_masaism_metadata( } /* encode data for current subframe */ - if ( sf > 0 && n_ism_tmp == numCodingBands ) + test(); + IF( sf > 0 && EQ_16( n_ism_tmp, numCodingBands ) ) { - encode_ratio_ism_subframe( ratio_ism_idx, nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hOmasaData->masa_to_total_energy_ratio[sf], 1, idx_separated_object ); + encode_ratio_ism_subframe_fx( ratio_ism_idx, nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hOmasaData->masa_to_total_energy_ratio_fx[sf], 1, idx_separated_object ); } - else + ELSE { - encode_ratio_ism_subframe( ratio_ism_idx, nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hOmasaData->masa_to_total_energy_ratio[sf], 0, idx_separated_object ); + encode_ratio_ism_subframe_fx( ratio_ism_idx, nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hOmasaData->masa_to_total_energy_ratio_fx[sf], 0, idx_separated_object ); } /* calculate quantized ISM ratios */ /* save previous subframe indexes */ - for ( band = 0; band < numCodingBands; band++ ) + FOR( band = 0; band < numCodingBands; band++ ) { - mvs2s( ratio_ism_idx[band], ratio_ism_idx_prev_sf[band], nchan_ism ); + Copy( ratio_ism_idx[band], ratio_ism_idx_prev_sf[band], nchan_ism ); } - if ( rotate ) + IF( rotate ) { - for ( band = 0; band < numCodingBands; band++ ) + FOR( band = 0; band < numCodingBands; band++ ) { - if ( hOmasaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) + IF( LT_32( hOmasaData->masa_to_total_energy_ratio_fx[sf][band], MASA2TOTAL_THR_Q30 ) ) { tmp = ratio_ism_idx[band][nchan_ism - 1]; ratio_ism_idx[band][nchan_ism - 1] = ratio_ism_idx[band][0]; ratio_ism_idx[band][0] = tmp; + move16(); + move16(); + move16(); } } } } } -#ifndef IVAS_FLOAT_FIXED - calculate_nbits_meta( nchan_ism, hOmasaData->q_energy_ratio_ism, hOmasaData->masa_to_total_energy_ratio, numSf, numCodingBands, bits_ism, idx_separated_object, ism_imp ); -#else - FOR( sf = 0; sf < numSf; ++sf ) - { - FOR( band = 0; band < numCodingBands; ++band ) - { - floatToFixed_arr32( hOmasaData->q_energy_ratio_ism[sf][band], hOmasaData->q_energy_ratio_ism_fx[sf][band], Q30, nchan_ism ); - hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = floatToFixed_32( hOmasaData->masa_to_total_energy_ratio[sf][band], Q30 ); - } - } - calculate_nbits_meta_fx( nchan_ism, hOmasaData->q_energy_ratio_ism_fx, hOmasaData->masa_to_total_energy_ratio_fx, numSf, numCodingBands, bits_ism, idx_separated_object, ism_imp ); -#endif /* quantize directions */ - for ( obj = 0; obj < nchan_ism; obj++ ) + FOR( obj = 0; obj < nchan_ism; obj++ ) { - if ( bits_ism[obj] < 8 ) + IF( LT_16( bits_ism[obj], 8 ) ) { /* check is same as previous */ - if ( ( fabs( hIsmMeta[obj]->elevation - hIsmMeta[obj]->q_elevation_old ) < 0.01f ) && ( fabs( hIsmMeta[obj]->azimuth - hIsmMeta[obj]->q_azimuth_old ) < 0.01f ) ) + test(); + IF( LT_32( L_abs( L_sub( hIsmMeta[obj]->elevation_fx, hIsmMeta[obj]->q_elevation_old_fx ) ), 41943 /* 0.01f in Q22 */ ) && LT_32( L_abs( L_sub( hIsmMeta[obj]->azimuth_fx, hIsmMeta[obj]->q_azimuth_old_fx ) ), 41943 /* 0.01f in Q22 */ ) ) { push_next_indice( hMetaData, 1, 1 ); /* the old stays the same */ } - else + ELSE { push_next_indice( hMetaData, 0, 1 ); - idx_sph = quantize_direction( hIsmMeta[obj]->elevation, hIsmMeta[obj]->azimuth, bits_ism[obj], &theta_q, &phi_q, &index_theta, &index_phi, MC_LS_SETUP_INVALID ); + idx_sph = quantize_direction_fx( hIsmMeta[obj]->elevation_fx, hIsmMeta[obj]->azimuth_fx, bits_ism[obj], &theta_q, &phi_q, &index_theta, &index_phi, MC_LS_SETUP_INVALID ); push_next_indice( hMetaData, idx_sph, bits_ism[obj] ); - hIsmMeta[obj]->q_elevation_old = hIsmMeta[obj]->elevation; - hIsmMeta[obj]->q_azimuth_old = hIsmMeta[obj]->azimuth; + hIsmMeta[obj]->q_elevation_old_fx = hIsmMeta[obj]->elevation_fx; + hIsmMeta[obj]->q_azimuth_old_fx = hIsmMeta[obj]->azimuth_fx; + move32(); + move32(); } } - else + ELSE { - idx_sph = quantize_direction( hIsmMeta[obj]->elevation, hIsmMeta[obj]->azimuth, bits_ism[obj], &theta_q, &phi_q, &index_theta, &index_phi, MC_LS_SETUP_INVALID ); + idx_sph = quantize_direction_fx( hIsmMeta[obj]->elevation_fx, hIsmMeta[obj]->azimuth_fx, bits_ism[obj], &theta_q, &phi_q, &index_theta, &index_phi, MC_LS_SETUP_INVALID ); push_next_indice( hMetaData, idx_sph, bits_ism[obj] ); - hIsmMeta[obj]->q_elevation_old = hIsmMeta[obj]->elevation; - hIsmMeta[obj]->q_azimuth_old = hIsmMeta[obj]->azimuth; + hIsmMeta[obj]->q_elevation_old_fx = hIsmMeta[obj]->elevation_fx; + hIsmMeta[obj]->q_azimuth_old_fx = hIsmMeta[obj]->azimuth_fx; + move32(); + move32(); } } return; } - +#endif /*-------------------------------------------------------------------* * ivas_merge_masa_transports() @@ -7412,7 +8706,7 @@ void ivas_merge_masa_transports_fx( return; } -#endif // IVAS_FLOAT_FIXED +#else void ivas_merge_masa_transports( float data_in_f1[][L_FRAME48k], @@ -7433,3 +8727,4 @@ void ivas_merge_masa_transports( return; } +#endif diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index a6316ea3dbea53badcb67496eebc8ff63961a099..0245324503de56a59431b5633141b885b9e05053 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -829,31 +829,11 @@ void ivas_param_mc_enc_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { - Word16 cpe_idx = ch / 2; - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt, -1 ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt, -1 ); - - for ( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); - } - - for ( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); - } - - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_e = 31 - 7; - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - 7; - - for ( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i], 7 ); - } - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold = float_to_fix16( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold_flt, Q15 - ATTACKTHRESHOLD_E ); - - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); + Word16 cpe_idx = shr( ch, 1 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; + move16(); + move16(); } #endif @@ -907,7 +887,11 @@ void ivas_param_mc_enc_fx( { Word16 cpe_idx = shr( ch, 1 ); +#ifndef MSAN_FIX Copy_Scale_sig_32_16( data_dmx_fx[ch], data_dmx_fx16[ch], -Q1 - Q11, input_frame ); // Q11 -> Q(-1) +#else + Copy_Scale_sig_32_16( data_dmx_fx[ch], data_dmx_fx16[ch], input_frame, -Q1 - Q11 ); // Q11 -> Q(-1) +#endif RunTransientDetection_ivas_fx( data_dmx_fx16[ch], input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); ivas_param_mc_transient_detection_fx( hParamMC, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet, &bAttackPresent[ch], &attackIdx[ch] ); @@ -1014,35 +998,26 @@ void ivas_param_mc_enc_fx( hParamMC->hMetadataPMC.last_coded_bwidth = hParamMC->hMetadataPMC.coded_bwidth; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) + FOR( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { - Word16 cpe_idx = ch / 2; - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1, -1 ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2, -1 ); - - for ( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) + Word16 cpe_idx = shr( ch, 1 ); + FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i], 7 ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); - } - - for ( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; + move16(); } - - for ( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i], -1 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; + move16(); } } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < hParamMC->hFbMixer->fb_cfg->num_in_chans; i++ ) { fixedToFloat_arrL( hParamMC->hFbMixer->ppFilterbank_prior_input_fx[i], hParamMC->hFbMixer->ppFilterbank_prior_input[i], Q11, input_frame / PARAM_MC_MDFT_NO_SLOTS ); } - #endif pop_wmops(); diff --git a/lib_enc/ivas_mc_paramupmix_enc.c b/lib_enc/ivas_mc_paramupmix_enc.c index ddb275e08e089e79849f0721ecbbf10564846071..7e4902855613a5683f132c32d5b963c7f8276011 100644 --- a/lib_enc/ivas_mc_paramupmix_enc.c +++ b/lib_enc/ivas_mc_paramupmix_enc.c @@ -1442,7 +1442,7 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( Word16 *q_cov_real[IVAS_SPAR_MAX_CH]; Word16 *q_cov_dtx_real[IVAS_SPAR_MAX_CH]; Word32 *pp_in_fr_real_fx[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH], *pp_in_fr_imag_fx[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; - Word16 q_ppIn_FR[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; + Word16 q_ppIn_FR; Word32 rxy_fx, ryy_fx; Word32 rxx_fx; @@ -1588,7 +1588,7 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( set_s( q_cov_dtx_real[i], Q31, MC_PARAMUPMIX_NCH ); } - set_s( q_ppIn_FR, sub( Q14, gb ), MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH ); + q_ppIn_FR = sub( Q14, gb ); ivas_enc_cov_handler_process_fx( hMCParamUpmix->hCovEnc[b], pp_in_fr_real_fx, pp_in_fr_imag_fx, q_ppIn_FR, cov_real_fx, q_cov_real, cov_dtx_real_fx, q_cov_dtx_real, hMCParamUpmix->hFbMixer->pFb, 0, hMCParamUpmix->hFbMixer->pFb->filterbank_num_bands, MC_PARAMUPMIX_NCH, 0 /*dtx_vad*/, transient_det[b], HOA_md_ind, NULL, NULL, NULL, 0, 0 ); FOR( i = 0; i < MC_PARAMUPMIX_NCH; i++ ) diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 00f8197c451e41dd248a0fc08c90842883842aa4..57de41384b2714a085012d682b01a8903b4a39a3 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -220,7 +220,7 @@ ivas_error ivas_mcmasa_enc_open_fx( } /* With McMASA, we config MASA encoder only in init as we know the input and there are no frame-by-frame changes currently. */ - IF( NE_32( ( error = ivas_masa_enc_config( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_masa_enc_config_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1696,6 +1696,20 @@ void ivas_mcmasa_param_est_enc_fx( p_Chnl_ImagBuffer_fx[i] = &Chnl_ImagBuffer_fx[i][0]; } + /* initialising energy_fx */ + FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + { + FOR( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) + { + hMasa->data.energy_fx[block_m_idx][i] = 0; + move32(); + hMasa->data.energy_e[block_m_idx][i] = 31; + move16(); + } + } + hMasa->data.q_energy = 0; + move16(); + /* do processing over all CLDFB time slots */ FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) { @@ -1767,25 +1781,11 @@ void ivas_mcmasa_param_est_enc_fx( } /* Store energies for guiding metadata encoding */ - hMasa->data.energy_fx[block_m_idx][i] = 0; - move32(); - hMasa->data.energy_e[block_m_idx][i] = 31; - move16(); FOR( j = 0; j < numAnalysisChannels; j++ ) { move32(); hMasa->data.energy_fx[block_m_idx][i] = BASOP_Util_Add_Mant32Exp( hMasa->data.energy_fx[block_m_idx][i], hMasa->data.energy_e[block_m_idx][i], COVls[i].xr_fx[j][j], COVls[i].xr_e[j][j], &hMasa->data.energy_e[block_m_idx][i] ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( hMasa->data.energy_e[block_m_idx][i] < 31 ) - { - hMasa->data.energy[block_m_idx][i] = hMasa->data.energy_fx[block_m_idx][i] / (float) ( 1 << ( 31 - hMasa->data.energy_e[block_m_idx][i] ) ); - } - ELSE - { - hMasa->data.energy[block_m_idx][i] = hMasa->data.energy_fx[block_m_idx][i] * (float) ( 1 << ( hMasa->data.energy_e[block_m_idx][i] - 31 ) ); - } -#endif } IF( !hMcMasa->separateChannelEnabled ) @@ -1901,7 +1901,7 @@ void ivas_mcmasa_param_est_enc_fx( 0, num_freq_bands, intensity_even_real_fx ); - + Word16 ref_e = 0; computeReferencePower_enc_fx( hMcMasa->band_grouping, FoaEven_RealBuffer_fx, FoaEven_ImagBuffer_fx, @@ -1910,7 +1910,7 @@ void ivas_mcmasa_param_est_enc_fx( num_freq_bands, MC_FORMAT, 0, - FOA_CHANNELS ); + FOA_CHANNELS, inp_q, &ref_e ); /* Fill buffers of length "averaging_length" time slots for intensity and energy */ hMcMasa->index_buffer_intensity = ( hMcMasa->index_buffer_intensity % hMcMasa->no_col_avg_diff ) + 1; /* averaging_length = 32 */ @@ -1925,7 +1925,7 @@ void ivas_mcmasa_param_est_enc_fx( hMcMasa->buffer_intensity_real_q[index - 1] = sub( shl( inp_q, 1 ), 31 ); move16(); Copy32( reference_power_fx[ts], &( hMcMasa->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); - hMcMasa->buffer_energy_q[index - 1] = sub( shl( inp_q, 1 ), 31 ); + hMcMasa->buffer_energy_q[index - 1] = sub( Q31, ref_e ); move16(); computeDiffuseness_mdft_fx( hMcMasa->buffer_intensity_real_fx, hMcMasa->buffer_energy_fx, num_freq_bands, hMcMasa->no_col_avg_diff, diffuseness_vector_fx, hMcMasa->buffer_intensity_real_q, hMcMasa->buffer_energy_q, out_exp ); @@ -1942,12 +1942,12 @@ void ivas_mcmasa_param_est_enc_fx( FOR( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) { - norm_tmp_fx = Mult_32_32( reference_power_fx[ts][band_m_idx], L_sub( ONE_IN_Q31, diffuseness_vector_fx[band_m_idx] ) ); /*2q-31*/ - hMcMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], hMcMasa->direction_vector_e[0][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ), sub( 31, sub( shl( inp_q, 1 ), 32 ) ), &hMcMasa->direction_vector_e[0][block_m_idx][band_m_idx] ); + norm_tmp_fx = Mult_32_32( reference_power_fx[ts][band_m_idx], L_sub( ONE_IN_Q31, diffuseness_vector_fx[band_m_idx] ) ); /*31-ref_e*/ + hMcMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], hMcMasa->direction_vector_e[0][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ), add( 1, ref_e ), &hMcMasa->direction_vector_e[0][block_m_idx][band_m_idx] ); move32(); - hMcMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx], hMcMasa->direction_vector_e[1][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ), sub( 31, sub( shl( inp_q, 1 ), 32 ) ), &hMcMasa->direction_vector_e[1][block_m_idx][band_m_idx] ); + hMcMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx], hMcMasa->direction_vector_e[1][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ), add( 1, ref_e ), &hMcMasa->direction_vector_e[1][block_m_idx][band_m_idx] ); move32(); - hMcMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx], hMcMasa->direction_vector_e[2][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ), sub( 31, sub( shl( inp_q, 1 ), 32 ) ), &hMcMasa->direction_vector_e[2][block_m_idx][band_m_idx] ); + hMcMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx], hMcMasa->direction_vector_e[2][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ), add( 1, ref_e ), &hMcMasa->direction_vector_e[2][block_m_idx][band_m_idx] ); move32(); IF( hMcMasa->combineRatios ) { @@ -3497,10 +3497,11 @@ static void computeVerticalDiffuseness_fx( /* Compute Diffuseness */ FOR( i = 0; i < num_freq_bands; ++i ) { - Word16 tmp_e1, tmp_e2; + Word16 tmp_e1, tmp_e2, tmp1; tmp = BASOP_Util_Divide3232_Scale( intensity_slow_abs[i], L_add( energy_slow[i], EPSILON_FX_SMALL ), &tmp_e1 ); tmp_e1 = add( tmp_e1, sub( intensity_slow_e[i], energy_slow_e[i] ) ); - tmp = BASOP_Util_Divide3232_Scale( L_sub( tmp, L_shr( VERTICAL_ENERGY_RATIO_OFFSET_FX, tmp_e1 ) ), L_sub( ONE_IN_Q15, VERTICAL_ENERGY_RATIO_OFFSET_FX ), &tmp_e2 ); /* Tuned to avoid effect due to ambience of vertically un-even setups */ + tmp_e1 = BASOP_Util_Add_MantExp( (Word16) tmp, tmp_e1, -VERTICAL_ENERGY_RATIO_OFFSET_FX, 0, &tmp1 ); + tmp = BASOP_Util_Divide3232_Scale( (Word32) tmp1, ONE_IN_Q15 - VERTICAL_ENERGY_RATIO_OFFSET_FX, &tmp_e2 ); /* Tuned to avoid effect due to ambience of vertically un-even setups */ tmp_e2 = add( tmp_e2, tmp_e1 ); tmp = L_sub( L_shl( 1, sub( 15, tmp_e2 ) ), tmp ); IF( tmp < 0 ) diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 4c3ce7706b545a6aee1bfa132bccfefd49997f57..aaa3dd26024f0768c03457a1c90f1f775e911ab8 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -42,6 +42,7 @@ #ifdef IVAS_FLOAT_FIXED #include "prot_fx.h" #include "ivas_prot_fx.h" +#include "prot_fx_enc.h" #include "rom_com.h" #endif @@ -438,6 +439,7 @@ ivas_error ivas_mct_enc( hMCT->p_orig_spectrum_long[cpe_id][n] = orig_spectrum_long[cpe_id][n]; #ifdef MSAN_FIX set_zero( mdst_spectrum_long[cpe_id][n], L_FRAME48k ); + set_zero( orig_spectrum_long[cpe_id][n], L_FRAME48k ); #endif #endif set32_fx( orig_spectrum_long_fx[cpe_id][n], 0, L_FRAME48k ); @@ -615,15 +617,6 @@ ivas_error ivas_mct_enc( } } } - - FOR( Word16 pair = hMCT->currBlockDataCnt - 1; pair >= 0; pair-- ) - { - IF( hMCT->hBlockData[pair]->hStereoMdct->hItd ) - { - hMCT->hBlockData[pair]->hStereoMdct->hItd->itd_fx[1] = float_to_fix( hMCT->hBlockData[pair]->hStereoMdct->hItd->itd[1], Q23 ); - } - } - #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Encoder_State *sts_tmp[MCT_MAX_CHANNELS]; Encoder_State *st; @@ -652,92 +645,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; - H_IGF_GRID hGrid; - Word16 igfGridIdx; - IF( st->last_core == ACELP_CORE && EQ_16( st->core, TCX_20_CORE ) ) - { - igfGridIdx = IGF_GRID_LB_TRAN; - } - ELSE IF( EQ_16( st->core, TCX_20_CORE ) ) - { - igfGridIdx = IGF_GRID_LB_NORM; - } - ELSE - { - /* It is short block */ - igfGridIdx = IGF_GRID_LB_SHORT; - } - hPrivateData = &hIGFEnc[ch]->igfData; - hGrid = &hPrivateData->igfInfo.grid[(Word16) igfGridIdx]; - if ( hIGFEnc[ch] ) - { - hIGFEnc[ch]->tns_predictionGain = float_to_fix16( hIGFEnc[ch]->tns_predictionGain_flt, Q23 ); - } - - 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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( int k = 0; k < IGF_MAX_TILES; k++ ) - { - hPrivateData->prevSFM_FIR[k] = float_to_fix( hPrivateData->prevSFM_FIR_flt[k], 16 ); /*15Q16*/ - hPrivateData->prevSFM_IIR[k] = float_to_fix16( hPrivateData->prevSFM_IIR_flt[k], 13 ); /*2Q13*/ - FOR( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) - { - hPrivateData->igfPastSFM_fx[k][j] = float_to_fix16( hPrivateData->igfPastSFM[k][j], 13 ); - } - } - floatToFixed_arr16( &hGrid->whiteningThreshold_flt[0][0], &hGrid->whiteningThreshold[0][0], Q13, 2 * IGF_MAX_TILES ); - } - - if ( st->hTdCngEnc != NULL ) - { - st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 ); - } } #endif #endif // 1 @@ -800,11 +707,6 @@ ivas_error ivas_mct_enc( } } } - - if ( st->hTdCngEnc != NULL ) - { - st->hTdCngEnc->CNG_att = fix16_to_float( st->hTdCngEnc->CNG_att_fx, Q7 ); - } if ( st->hIGFEnc ) { st->hIGFEnc->tns_predictionGain_flt = fix16_to_float( st->hIGFEnc->tns_predictionGain, Q23 ); @@ -828,19 +730,9 @@ ivas_error ivas_mct_enc( { sts = hCPE->hCoreCoder; st = sts[ch]; - TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; st->hTcxCfg->bandwidth = float_to_fix16( st->hTcxCfg->bandwidth_flt, Q15 ); st->hTcxCfg->preemph_fac = float_to_fix16( st->hTcxCfg->preemph_fac_flt, Q15 ); - st->hTcxEnc->tcx_target_bits_fac = float_to_fix16( st->hTcxEnc->tcx_target_bits_fac_flt, Q14 ); - st->hTcxCfg->sq_rounding = float_to_fix16( st->hTcxCfg->sq_rounding_flt, Q15 ); - if ( st->hTdCngEnc != NULL ) - { - st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 ); - } - floatToFixed_arr( hTcxEnc->ltpGainMemory, hTcxEnc->ltpGainMemory_fx, Q15, N_LTP_GAIN_MEMS ); st->hTcxEnc->measuredBwRatio = float_to_fix16( st->hTcxEnc->measuredBwRatio_flt, Q14 ); - st->hTcxEnc->noiseTiltFactor = float_to_fix16( st->hTcxEnc->noiseTiltFactor_flt, Q15 ); - st->hTcxEnc->tcxltp_gain = (Word16) ( st->hTcxEnc->tcxltp_gain_flt * ( 1 << Q15 ) ); } #endif ivas_mdct_quant_coder_fx( hCPE, hMCT->tnsBits[cpe_id], hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], 1 ); @@ -850,7 +742,6 @@ ivas_error ivas_mct_enc( { sts = hCPE->hCoreCoder; st = sts[ch]; - st->hTcxEnc->tcx_target_bits_fac_flt = me2f_16( st->hTcxEnc->tcx_target_bits_fac, Q15 - Q14 ); } #endif /* update input samples buffer (as done in ivas_cpe_enc() for other than MCT coding) */ @@ -894,17 +785,9 @@ ivas_error ivas_mct_enc( mvr2r( GEWB_Ave, st->mem_AR, M ); } - IF( st->hTcxEnc != NULL ) - { - IF( st->element_mode != IVAS_CPE_MDCT ) - { - st->hTcxEnc->kernel_switch_corr_past_flt = 0.f; - } - } - IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) { - st->hTcxEnc->tcxltp_norm_corr_mem_flt = fixedToFloat( st->hTcxEnc->tcxltp_norm_corr_mem, 31 ); + st->hTcxEnc->tcxltp_norm_corr_mem_flt = fixedToFloat( st->hTcxEnc->tcxltp_norm_corr_mem, 15 ); } IF( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->mdct_sw, MODE2 ) ) @@ -918,17 +801,6 @@ ivas_error ivas_mct_enc( st->preemph_fac_flt = PREEMPH_FAC_16k_FLT; } } - - IF( st->Opt_DTX_ON && st->hTdCngEnc != NULL ) - { - IF( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->hDtxEnc->first_CNG, 1 ) ) - { - IF( ( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && GE_16( st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) ) - { - st->hTdCngEnc->CNG_att = fix16_to_float( st->hTdCngEnc->CNG_att_fx, Q7 ); - } - } - } #endif #else updt_enc_common( hCPE->hCoreCoder[n] ); @@ -1109,7 +981,7 @@ ivas_error create_mct_enc( } ELSE IF( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) { - hMCT->nchan_out_woLFE = ivas_get_sba_num_TCs( ivas_total_brate, st_ivas->sba_analysis_order ); + hMCT->nchan_out_woLFE = ivas_get_sba_num_TCs_fx( ivas_total_brate, st_ivas->sba_analysis_order ); move16(); test(); @@ -1900,24 +1772,56 @@ static ivas_error ivas_mc_enc_reconfig( } #ifdef IVAS_FLOAT_FIXED if ( NE_32( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + { + return error; + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + if ( st_ivas->hQMetaData->q_direction != NULL ) + { + for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + if ( st_ivas->hQMetaData->no_directions == 2 ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } + } +#endif // IVAS_FLOAT_FIXED_CONVERSIONS #else if ( ( error = ivas_mcmasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) -#endif { return error; } +#endif } else { /* reconfigure McMASA instance */ #ifdef IVAS_FLOAT_FIXED if ( NE_32( ( error = ivas_mcmasa_enc_reconfig_fx( st_ivas ) ), IVAS_ERR_OK ) ) + { + return error; + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + if ( st_ivas->hQMetaData->q_direction != NULL ) + { + for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + if ( st_ivas->hQMetaData->no_directions == 2 ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } + } +#endif // IVAS_FLOAT_FIXED_CONVERSIONS #else if ( ( error = ivas_mcmasa_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) -#endif { return error; } +#endif } #ifdef IVAS_FLOAT_FIXED @@ -1983,7 +1887,11 @@ static ivas_error ivas_mc_enc_reconfig( 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 ) @@ -1993,9 +1901,11 @@ static ivas_error ivas_mc_enc_reconfig( 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 /* set last core to TCX20 */ st->last_core = TCX_20_CORE; } diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index bbf7639f25c3c4ff8d63f21d73180189d7d6f6bf..f8787ab7d50621a7f1c371a1caab6f420a9d1fda 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -1661,6 +1661,14 @@ void ivas_mdct_core_whitening_enc( push_wmops( "mdct_core_whitening" ); +#ifdef MSAN_FIX + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + set_zero( A_q[ch][0], M + 1 ); + set_zero( A_q[ch][1], M + 1 ); + } +#endif + /*--------------------------------------------------------------* * Initialization *---------------------------------------------------------------*/ @@ -1703,6 +1711,9 @@ void ivas_mdct_core_whitening_enc( mdst_spectrum_fx[ch][1] = mdst_spectrum_long_fx[ch] + N_TCX10_MAX; set_f( scf[ch][0], 0.0, M ); set_f( scf[ch][1], 0.0, M ); +#ifdef MSAN_FIX + set_f( temp_buffer, 0.0, 15 * L_FRAME48k / 8 ); +#endif #endif } @@ -1732,10 +1743,6 @@ void ivas_mdct_core_whitening_enc( st->prevEnergyHF_fx = floatToFixed_32( st->prevEnergyHF, q_com ); st->currEnergyHF_fx = floatToFixed_32( st->currEnergyHF, q_com ); st->currEnergyHF_e_fx = sub( Q31, q_com ); - IF( st->hTranDet ) - { - floatToFixed_arr( st->hTranDet->subblockEnergies.subblockNrgChange_flt, st->hTranDet->subblockEnergies.subblockNrgChange, Q15 - NRG_CHANGE_E, NSUBBLOCKS + MAX_TD_DELAY ); - } IF( st->hTcxEnc ) { st->hTcxEnc->tfm_mem_fx = floatToFixed_32( st->hTcxEnc->tfm_mem, Q31 ); @@ -1776,8 +1783,6 @@ void ivas_mdct_core_whitening_enc( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, 7, NSUBBLOCKS + MAX_TD_DELAY ); - hTcxEnc->tcxltp_gain_past = float_to_fix16( hTcxEnc->tcxltp_gain_past_flt, Q15 ); hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); q_fac = Q_factor_arr( old_wsp[ch], L_WSP ); floatToFixed_arr( old_wsp[ch], old_wsp_fx[ch], q_fac, L_WSP ); @@ -1786,8 +1791,6 @@ void ivas_mdct_core_whitening_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( old_wsp_fx[ch], old_wsp[ch], q_fac, L_WSP ); - hTcxEnc->tcxltp_gain_past_flt = fix16_to_float( hTcxEnc->tcxltp_gain_past, Q15 ); - hTcxEnc->tcxltp_gain_flt = fix16_to_float( hTcxEnc->tcxltp_gain, Q15 ); hTcxEnc->tcxltp_norm_corr_past_flt = fix16_to_float( hTcxEnc->tcxltp_norm_corr_past, Q15 ); #endif #else @@ -1913,8 +1916,6 @@ void ivas_mdct_core_whitening_enc( if ( st->element_mode == IVAS_CPE_DFT ) { - floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, Q7, NSUBBLOCKS + MAX_TD_DELAY ); - hTcxEnc->tcxltp_gain_past = float_to_fix16( hTcxEnc->tcxltp_gain_past_flt, Q15 ); hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); q_fac = Q_factor_arr( st->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); floatToFixed_arr( st->buf_wspeech_enc_flt, st->buf_wspeech_enc, q_fac, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); @@ -1922,8 +1923,6 @@ void ivas_mdct_core_whitening_enc( } else if ( st->element_mode != IVAS_CPE_MDCT ) { - floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, Q7, NSUBBLOCKS + MAX_TD_DELAY ); - hTcxEnc->tcxltp_gain_past = float_to_fix16( hTcxEnc->tcxltp_gain_past_flt, Q15 ); hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); q_fac = Q_factor_arr( st->buf_speech_enc_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); floatToFixed_arr( st->buf_speech_enc_flt, st->buf_speech_enc, q_fac, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); @@ -1932,9 +1931,6 @@ void ivas_mdct_core_whitening_enc( st->hTcxEnc->exp_buf_speech_ltp = 15 - q_fac; } - floatToFixed_arrL( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg, 7, 24 ); - floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, 7, 24 ); - IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) && st->igf ) { if ( st->hIGFEnc ) @@ -1943,10 +1939,6 @@ void ivas_mdct_core_whitening_enc( } IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData = &st->hIGFEnc->igfData; - if ( st->hTdCngEnc != NULL ) - { - st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 ); - } float max_sb = 0; float max_tb = 0; @@ -2050,11 +2042,6 @@ void ivas_mdct_core_whitening_enc( hPrivateData->igfPastSFM[i][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[i][j], 13 ); } } - - if ( st->hTdCngEnc != NULL ) - { - st->hTdCngEnc->CNG_att = fix16_to_float( st->hTdCngEnc->CNG_att_fx, Q7 ); - } } IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -2062,47 +2049,20 @@ void ivas_mdct_core_whitening_enc( IF( st->hTcxEnc->fUseTns[0] || st->hTcxEnc->fUseTns[1] ) { if ( st->hTcxCfg->fIsTNSAllowed ) - { // conv params to float - // avgSqrCoef_flt = float(avgSqrCoef, Q 15) - hTcxEnc->tnsData[0].filter[0].avgSqrCoef_flt = fix16_to_float( hTcxEnc->tnsData[0].filter[0].avgSqrCoef, 15 ); - hTcxEnc->tnsData[0].filter[1].avgSqrCoef_flt = fix16_to_float( hTcxEnc->tnsData[0].filter[1].avgSqrCoef, 15 ); - IF( hTcxEnc->tcxMode != TCX_20 ) - { - hTcxEnc->tnsData[1].filter[0].avgSqrCoef_flt = fix16_to_float( hTcxEnc->tnsData[1].filter[0].avgSqrCoef, 15 ); - hTcxEnc->tnsData[1].filter[1].avgSqrCoef_flt = fix16_to_float( hTcxEnc->tnsData[1].filter[1].avgSqrCoef, 15 ); - } - - // avgSqrCoef_flt = float(avgSqrCoef, Q 15) - hTcxEnc->tnsData[0].filter[0].predictionGain_flt = fix16_to_float( hTcxEnc->tnsData[0].filter[0].predictionGain, 7 ); - hTcxEnc->tnsData[0].filter[1].predictionGain_flt = fix16_to_float( hTcxEnc->tnsData[0].filter[1].predictionGain, 7 ); - IF( hTcxEnc->tcxMode != TCX_20 ) - { - hTcxEnc->tnsData[1].filter[0].predictionGain_flt = fix16_to_float( hTcxEnc->tnsData[1].filter[0].predictionGain, 7 ); - hTcxEnc->tnsData[1].filter[1].predictionGain_flt = fix16_to_float( hTcxEnc->tnsData[1].filter[1].predictionGain, 7 ); - } - // spectrum[]=float( (fix)spectrum_fx[]) , Q=q_factor_spectrum - // fixedToFloat_arrL( hTcxEnc->spectrum_long_fx, hTcxEnc->spectrum_long, q_factor_spectrum, N_MAX ); - - // subblockNrg_flt=(float)((fixed)subblockNrg) - fixedToFloat_arrL( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg_flt, 7, 24 ); - - // subblockNrgChange_flt=(float)((fixed)subblockNrgChange) - fixedToFloat_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, 7, 24 ); + { + st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg_e = 31 - Q7; + move16(); } } } if ( st->element_mode == IVAS_CPE_DFT ) { - hTcxEnc->tcxltp_gain_past_flt = fix16_to_float( hTcxEnc->tcxltp_gain_past, Q15 ); - hTcxEnc->tcxltp_gain_flt = fix16_to_float( hTcxEnc->tcxltp_gain, Q15 ); hTcxEnc->tcxltp_norm_corr_past_flt = fix16_to_float( hTcxEnc->tcxltp_norm_corr_past, Q15 ); fixedToFloat_arr( st->buf_wspeech_enc, st->buf_wspeech_enc_flt, q_fac, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); } else if ( st->element_mode != IVAS_CPE_MDCT ) { - hTcxEnc->tcxltp_gain_past_flt = fix16_to_float( hTcxEnc->tcxltp_gain_past, Q15 ); - hTcxEnc->tcxltp_gain_flt = fix16_to_float( hTcxEnc->tcxltp_gain, Q15 ); hTcxEnc->tcxltp_norm_corr_past_flt = fix16_to_float( hTcxEnc->tcxltp_norm_corr_past, Q15 ); fixedToFloat_arr( st->hTcxEnc->buf_speech_ltp, st->hTcxEnc->buf_speech_ltp_flt, q_fac, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); } @@ -2168,9 +2128,14 @@ void ivas_mdct_core_whitening_enc( bw_detect( st, NULL, st->hTcxEnc->spectrum[n], NULL, MC_FORMAT /*just cannot be ISM_FORMAT*/, mct_on ); #else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS +#ifdef MSAN_FIX + q_spectrum = Q_factor_arr( st->hTcxEnc->spectrum[n], st->hTcxEnc->L_frameTCX / ( n + 1 ) ); + floatToFixed_arr( st->hTcxEnc->spectrum[n], spect_fx[n], q_spectrum, st->hTcxEnc->L_frameTCX / ( n + 1 ) ); +#else Word16 l_frame = (int16_t) ( st->input_Fs / FRAMES_PER_SEC ); q_spectrum = Q_factor_arr( st->hTcxEnc->spectrum[n], l_frame ); floatToFixed_arr( st->hTcxEnc->spectrum[n], spect_fx[n], q_spectrum, l_frame ); +#endif #endif bw_detect_fx( st, NULL, spect_fx[n], NULL, NULL, MC_FORMAT /*just cannot be ISM_FORMAT*/, mct_on ); #endif @@ -2186,7 +2151,11 @@ void ivas_mdct_core_whitening_enc( #endif if ( st->last_core == ACELP_CORE ) /* reset past kernel info */ { +#ifndef IVAS_FLOAT_FIXED st->hTcxEnc->kernel_switch_corr_past_flt = 0.f; +#else + st->hTcxEnc->kernel_switch_corr_past = 0; +#endif st->hTcxEnc->kernel_symmetry_past = 0; } } @@ -2240,15 +2209,10 @@ void ivas_mdct_core_whitening_enc( floatToFixed_arrL32( hTcxEnc1->spectrum[n], hTcxEnc1->spectrum_fx[n], q_com, hTcxEnc1->L_frameTCX / nSubframes ); floatToFixed_arrL32( mdst_spectrum[0][n], mdst_spectrum_fx[0][n], q_com, hTcxEnc0->L_frameTCX / nSubframes ); floatToFixed_arrL32( mdst_spectrum[1][n], mdst_spectrum_fx[1][n], q_com, hTcxEnc1->L_frameTCX / nSubframes ); - - hTcxEnc0->kernel_switch_corr_past = float_to_fix16( hTcxEnc0->kernel_switch_corr_past_flt, Q15 ); #endif const Word16 switchKernel = /* these 4 transform types can be applied: 0 = MDCT-IV, 1 = MDST-II, 2 = MDCT-II, 3 = MDST-IV */ kernel_switch_detect_fx( hTcxEnc0->spectrum_fx[n], hTcxEnc1->spectrum_fx[n], mdst_spectrum_fx[0][n], mdst_spectrum_fx[1][n], q_com, nSampCore / nSubframes, L_subframeTCX / nSubframes, hTcxEnc0->transform_type[n], &hTcxEnc0->kernel_switch_corr_past, ( totalRate * L_subframe ) / nSubframes ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hTcxEnc0->kernel_switch_corr_past_flt = fix16_to_float( hTcxEnc0->kernel_switch_corr_past, Q15 ); -#endif #else const int16_t switchKernel = /* these 4 transform types can be applied: 0 = MDCT-IV, 1 = MDST-II, 2 = MDCT-II, 3 = MDST-IV */ kernel_switch_detect( hTcxEnc0->spectrum[n], hTcxEnc1->spectrum[n], mdst_spectrum[0][n], mdst_spectrum[1][n], nSampCore / nSubframes, @@ -2267,7 +2231,11 @@ void ivas_mdct_core_whitening_enc( } else { +#ifdef IVAS_FLOAT_FIXED + hTcxEnc0->kernel_switch_corr_past = 0; /* don't update the kernel switching state, postpone it to when data is available */ +#else hTcxEnc0->kernel_switch_corr_past_flt = 0.f; /* don't update the kernel switching state, postpone it to when data is available */ +#endif hTcxEnc0->kernel_type[n] = ( hTcxEnc0->kernel_symmetry_past ? 3 : 0 ); hTcxEnc1->kernel_type[n] = ( hTcxEnc1->kernel_symmetry_past ? 3 : 0 ); } @@ -2469,7 +2437,11 @@ void ivas_mdct_core_whitening_enc( else { sts[0]->hTcxEnc->enc_ste_pre_corr_past = 0; +#ifdef IVAS_FLOAT_FIXED + sts[0]->hTcxEnc->kernel_switch_corr_past = 0; +#else sts[0]->hTcxEnc->kernel_switch_corr_past_flt = 0.f; +#endif for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { @@ -2563,8 +2535,6 @@ void ivas_mdct_core_whitening_enc( q_temp[ch][k] = L_get_q_buf1( mdst_spectrum[ch][k], st->hTcxEnc->L_frameTCX / nSubframes ); floatToFixed_arrL32( mdst_spectrum[ch][k], mdst_spectrum_fx[ch][k], q_temp[ch][k], st->hTcxEnc->L_frameTCX / nSubframes ); } - - hTcxEnc->tcxltp_gain = (Word16) ( hTcxEnc->tcxltp_gain_flt * ( 1 << Q15 ) ); } #endif @@ -2581,7 +2551,6 @@ void ivas_mdct_core_whitening_enc( fixedToFloat_arrL32( st->hTcxEnc->spectrum_fx[k], st->hTcxEnc->spectrum[k], ( Q31 - st->hTcxEnc->spectrum_e[k] ), st->hTcxEnc->L_frameTCX / nSubframes ); fixedToFloat_arrL32( mdst_spectrum_fx[ch][k], mdst_spectrum[ch][k], q_temp[ch][k], st->hTcxEnc->L_frameTCX / nSubframes ); } - sts[ch]->hTcxEnc->tcxltp_gain_flt = fix16_to_float( sts[ch]->hTcxEnc->tcxltp_gain, Q15 ); } #endif #else @@ -2801,7 +2770,6 @@ void ivas_mdct_core_whitening_enc( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 A_q_fx[CPE_CHANNELS][NB_DIV][M + 1]; - st->hTcxEnc->noiseTiltFactor = float_to_fix16( st->hTcxEnc->noiseTiltFactor_flt, Q15 ); st->hTcxEnc->spectrum_e[n] = 31 - ( Q_factor_arrL( st->hTcxEnc->spectrum[n], tcx_subframe_coded_lines ) - 4 ); floatToFixed_arrL( st->hTcxEnc->spectrum[n], st->hTcxEnc->spectrum_fx[n], 31 - st->hTcxEnc->spectrum_e[n], tcx_subframe_coded_lines ); floatToFixed_arrL( scf_q[ch][n], scf_q_fx[ch][n], Q16, M ); @@ -2813,11 +2781,6 @@ void ivas_mdct_core_whitening_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL( st->hTcxEnc->spectrum_fx[n], st->hTcxEnc->spectrum[n], 31 - st->hTcxEnc->spectrum_e[n], tcx_subframe_coded_lines ); - if ( st->enablePlcWaveadjust ) - { - st->hTcxCfg->SFM2_flt = fix_to_float( st->hTcxCfg->SFM2, Q31 ); - } - #endif #else ShapeSpectrum( st->hTcxCfg, A_q[ch][n], NULL, L_subframe, tcx_subframe_coded_lines, st->hTcxEnc->spectrum[n], st->hTcxEnc->fUseTns[n], st, scf_q[ch][n] ); @@ -2879,8 +2842,6 @@ void ivas_mdct_core_whitening_enc( q_temp[ch][k] = L_get_q_buf1( mdst_spectrum[ch][k], st->hTcxEnc->L_frameTCX / nSubframes ); floatToFixed_arrL32( mdst_spectrum[ch][k], mdst_spectrum_fx[ch][k], q_temp[ch][k], st->hTcxEnc->L_frameTCX / nSubframes ); } - - hTcxEnc->tcxltp_gain = (Word16) ( hTcxEnc->tcxltp_gain_flt * ( 1 << Q15 ) ); } #endif @@ -2897,7 +2858,6 @@ void ivas_mdct_core_whitening_enc( fixedToFloat_arrL32( st->hTcxEnc->spectrum_fx[k], st->hTcxEnc->spectrum[k], ( Q31 - st->hTcxEnc->spectrum_e[k] ), st->hTcxEnc->L_frameTCX / nSubframes ); fixedToFloat_arrL32( mdst_spectrum_fx[ch][k], mdst_spectrum[ch][k], q_temp[ch][k], st->hTcxEnc->L_frameTCX / nSubframes ); } - sts[ch]->hTcxEnc->tcxltp_gain_flt = fix16_to_float( sts[ch]->hTcxEnc->tcxltp_gain, Q15 ); } #endif #else @@ -2931,7 +2891,6 @@ void ivas_mdct_core_whitening_enc( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 A_q_fx[CPE_CHANNELS][NB_DIV][M + 1]; - st->hTcxEnc->noiseTiltFactor = float_to_fix16( st->hTcxEnc->noiseTiltFactor_flt, Q15 ); floatToFixed_arr( A_q[ch][n], A_q_fx[ch][n], Q12, M + 1 ); mdst_spectrum_e[ch][n] = 31 - ( Q_factor_arrL( mdst_spectrum[ch][n], tcx_subframe_coded_lines ) - 2 ); floatToFixed_arrL( mdst_spectrum[ch][n], mdst_spectrum_fx[ch][n], 31 - mdst_spectrum_e[ch][n], tcx_subframe_coded_lines ); @@ -2944,11 +2903,6 @@ void ivas_mdct_core_whitening_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL( mdst_spectrum_fx[ch][n], mdst_spectrum[ch][n], 31 - mdst_spectrum_e[ch][n], tcx_subframe_coded_lines ); - if ( st->enablePlcWaveadjust ) - { - st->hTcxCfg->SFM2_flt = fix_to_float( st->hTcxCfg->SFM2, Q31 ); - } - #endif #else ShapeSpectrum( st->hTcxCfg, A_q[ch][n], NULL, L_subframe, tcx_subframe_coded_lines, mdst_spectrum[ch][n], st->hTcxEnc->fUseTns[n], st, scf_q[ch][n] ); diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 77f3d318408843ee4a9410326b297592045e489e..0265b1339fa5dc24c096903e4a7ce672dc179d6d 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -121,6 +121,117 @@ static void computeReferencePower_omasa_ivas_fx( const Word16 *band_grouping, Wo * Allocate and initialize OMASA handle *--------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_omasa_enc_open_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +) +{ + Word16 i, j; + OMASA_ENC_HANDLE hOMasa; + Word16 numAnalysisChannels; + Word16 input_frame; + ivas_error error; + + error = IVAS_ERR_OK; + move16(); + + assert( st_ivas->hMasa != NULL && "MASA encoder handle is not present" ); + + IF( ( hOMasa = (OMASA_ENC_HANDLE) malloc( sizeof( OMASA_ENC_STATE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA encoder\n" ) ); + } + + numAnalysisChannels = st_ivas->hEncoderConfig->nchan_ism; + move16(); + + /* open/initialize CLDFB */ + hOMasa->num_Cldfb_instances = numAnalysisChannels; + move16(); + FOR( i = 0; i < hOMasa->num_Cldfb_instances; i++ ) + { + IF( ( error = openCldfb_ivas_enc( &( hOMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, st_ivas->hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + set_zero_fx( &hOMasa->chnlToFoaMtx_fx[0][0], DIRAC_MAX_ANA_CHANS * MCMASA_MAX_ANA_CHANS ); + + /* intensity 3-dim */ + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + hOMasa->direction_vector_m_fx[i] = (Word32 **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word32 * ) ); + + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + IF( ( hOMasa->direction_vector_m_fx[i][j] = (Word32 *) malloc( MASA_FREQUENCY_BANDS * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data\n" ) ); + } + set_zero_fx( hOMasa->direction_vector_m_fx[i][j], MASA_FREQUENCY_BANDS ); + } + hOMasa->direction_vector_e[i] = (Word16 **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word16 * ) ); + + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + IF( ( hOMasa->direction_vector_e[i][j] = (Word16 *) malloc( MASA_FREQUENCY_BANDS * sizeof( Word16 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data\n" ) ); + } + set16_fx( hOMasa->direction_vector_e[i][j], 0, MASA_FREQUENCY_BANDS ); + } + } + + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + { + IF( ( hOMasa->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( MASA_FREQUENCY_BANDS * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data\n" ) ); + } + set_zero_fx( hOMasa->buffer_intensity_real_fx[i][j], MASA_FREQUENCY_BANDS ); + } + } + set16_fx( hOMasa->buffer_intensity_real_q, 31, DIRAC_NO_COL_AVG_DIFF ); + set_zero_fx( hOMasa->buffer_energy_fx, DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS ); + set16_fx( hOMasa->buffer_energy_q, 31, DIRAC_NO_COL_AVG_DIFF ); + + FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) + { + set16_fx( hOMasa->prev_object_dm_gains_fx[i], INV_SQRT_2_Q15, MASA_MAX_TRANSPORT_CHANNELS ); /*q15*/ + } + set_zero_fx( hOMasa->broadband_energy_sm_fx, MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS ); + hOMasa->broadband_energy_sm_e = 0; + move16(); + set_zero_fx( hOMasa->broadband_energy_prev_fx, MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS ); + hOMasa->broadband_energy_prev_e = 0; + move16(); + + hOMasa->prev_selected_object = 0; + hOMasa->changing_object = 0; + move16(); + move16(); + + input_frame = extract_l( Mult_32_16( st_ivas->hEncoderConfig->input_Fs /*q0*/, INV_FRAME_PER_SEC_Q15 /*q15*/ ) ); /*Q0+Q15-Q15->Q0*/ + FOR( i = 0; i < input_frame; i++ ) + { + hOMasa->interpolator_fx[i] = divide1616( i, input_frame ); /*q15*/ + hOMasa->fade_out_gain_fx[i] = add( 16384 /*0.5 in q15*/, shr( getCosWord16R2( mult( hOMasa->interpolator_fx[i], 32767 / 2 ) /*15+15-15=>15*/ ), 1 ) /*q15*/ ); /*(angle in degrees=((float)i/(float)input_frame *pi)*180/pi)/360*32767 =>(float)i/(float)input_frame )*32767/2*/ /*q15*/ + hOMasa->fade_in_gain_fx[i] = sub( 32767 /*1.0 in Q15*/, hOMasa->fade_out_gain_fx[i] ); /*q15*/ + move16(); + move16(); + move16(); + } + + hOMasa->index_buffer_intensity = 0; + move16(); + + st_ivas->hOMasa = hOMasa; + + return error; +} +#else ivas_error ivas_omasa_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ) @@ -248,7 +359,7 @@ ivas_error ivas_omasa_enc_open( return error; } - +#endif /*--------------------------------------------------------------------------* * ivas_omasa_enc_close() @@ -256,6 +367,50 @@ ivas_error ivas_omasa_enc_open( * Close OMASA handle *--------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED + +void ivas_omasa_enc_close_fx( + OMASA_ENC_HANDLE *hOMasa /* i/o: encoder OMASA handle */ +) +{ + Word16 i, j; + + test(); + IF( hOMasa == NULL || *hOMasa == NULL ) + { + return; + } + + FOR( i = 0; i < ( *hOMasa )->num_Cldfb_instances; i++ ) + { + deleteCldfb_ivas( &( ( *hOMasa )->cldfbAnaEnc[i] ) ); + } + + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + free( ( *hOMasa )->direction_vector_m_fx[i][j] ); + ( *hOMasa )->direction_vector_m_fx[i][j] = NULL; + free( ( *hOMasa )->direction_vector_e[i][j] ); + ( *hOMasa )->direction_vector_e[i][j] = NULL; + } + + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + { + free( ( *hOMasa )->buffer_intensity_real_fx[i][j] ); + ( *hOMasa )->buffer_intensity_real_fx[i][j] = NULL; + } + free( ( *hOMasa )->direction_vector_m_fx[i] ); + ( *hOMasa )->direction_vector_m_fx[i] = NULL; + } + + free( *hOMasa ); + ( *hOMasa ) = NULL; + + return; +} +#else void ivas_omasa_enc_close( OMASA_ENC_HANDLE *hOMasa /* i/o: encoder OMASA handle */ ) @@ -308,13 +463,141 @@ void ivas_omasa_enc_close( return; } - +#endif /*--------------------------------------------------------------------------* * ivas_omasa_enc_config() * * oMASA encoder configuration *--------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_omasa_enc_config_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + Word16 k, sce_id, nSCE_old; + Word32 ivas_total_brate, ism_total_brate; + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; + + hEncoderConfig = st_ivas->hEncoderConfig; + ivas_total_brate = hEncoderConfig->ivas_total_brate; + nSCE_old = st_ivas->nSCE; + move16(); + move32(); /*hEncoderConfig->ivas_total_brate*/ + + st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, hEncoderConfig->nchan_ism ); + move16(); + st_ivas->nchan_transport = 2; + move16(); + + /* reconfiguration in case of bitrate switching */ + IF( NE_32( hEncoderConfig->last_ivas_total_brate, ivas_total_brate ) ) + { + ivas_set_omasa_TC_fx( st_ivas->ism_mode, hEncoderConfig->nchan_ism, &st_ivas->nSCE, &st_ivas->nCPE ); + + k = 0; + move16(); + WHILE( LT_16( k, SIZE_IVAS_BRATE_TBL ) && NE_32( ivas_total_brate, ivas_brate_tbl[k] ) ) + { + test(); + k = add( k, 1 ); + } + + ism_total_brate = 0; + move32(); + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + ism_total_brate = L_add( ism_total_brate, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); + } + + IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + { + IF( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, 1, NULL, 0, NULL, NULL, NULL, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + IF( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->nSCE, NULL, 0, NULL, NULL, NULL, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* reconfigure core-coders for ISMs */ + IF( st_ivas->nSCE > 0 ) + { + IF( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, 1, 2, sep_object_brate[k - 2][st_ivas->nSCE - 1], L_sub( ivas_total_brate, ism_total_brate ), MC_MODE_NONE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE + { + IF( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, 1, 2, 0, L_sub( ivas_total_brate, ism_total_brate ), MC_MODE_NONE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* re-write IVAS format signalling - actual 'ism_mode' was not known before */ + IF( st_ivas->nSCE > 0 ) + { + reset_indices_enc( st_ivas->hSCE[0]->hCoreCoder[0]->hBstr, st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot ); + } + ELSE + { + reset_indices_enc( st_ivas->hCPE[0]->hCoreCoder[0]->hBstr, st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_bits_tot ); + } + + ivas_write_format_fx( st_ivas ); + + test(); + test(); + IF( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && st_ivas->hOMasa == NULL ) + { + IF( ( error = ivas_omasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && st_ivas->hOMasa != NULL ) + { + ivas_omasa_enc_close_fx( &( st_ivas->hOMasa ) ); + st_ivas->hOMasa = NULL; + } + + st_ivas->hCPE[0]->element_brate = L_sub( ivas_total_brate, ism_total_brate ); + move32(); + + IF( GE_32( L_sub( ivas_total_brate, ism_total_brate ), MIN_BRATE_MDCT_STEREO ) ) + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + ELSE + { + hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + } + move16(); + } + + /* Configure MASA encoder based on frame parameters */ + IF( ( error = ivas_masa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + IF( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + /* Configure oMASA analysis based on MASA config */ + ivas_omasa_set_config_fx( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hEncoderConfig->input_Fs, st_ivas->ism_mode ); + } + + return IVAS_ERR_OK; +} +#else ivas_error ivas_omasa_enc_config( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ @@ -438,6 +721,7 @@ ivas_error ivas_omasa_enc_config( return IVAS_ERR_OK; } +#endif // IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* @@ -1098,14 +1382,15 @@ void ivas_omasa_enc( * * Set the importance of particular ISM streams in combined-format coding *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED void ivas_set_ism_importance_interformat_fx( - const Word32 ism_total_brate, /* i/o: ISms total bitrate */ - const Word16 nchan_transport, /* i : number of transported channels */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ - const Word32 lp_noise_CPE_fx, /* i : LP filtered total noise estimation Q8*/ - Word16 ism_imp[] /* o : ISM importance flags */ + const Word32 ism_total_brate, /* i/o: ISms total bitrate */ + const Word16 nchan_transport, /* i : number of transported channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + const Word16 lp_noise_CPE_fx, /* i : LP filtered total noise estimation Q8 */ + Word16 ism_imp[] /* o : ISM importance flags */ ) { Encoder_State *st; @@ -1120,7 +1405,7 @@ void ivas_set_ism_importance_interformat_fx( IF( active_flag == 0 ) { - if ( GT_32( st->lp_noise_fx, 3840 /*15 in Q8*/ ) || LT_32( L_sub( lp_noise_CPE_fx, st->lp_noise_fx ), 7680 /*30*/ ) ) + if ( GT_16( st->lp_noise_fx, 3840 /* 15 in Q8 */ ) || LT_16( sub( lp_noise_CPE_fx, st->lp_noise_fx ), 7680 /* 30 in Q8 */ ) ) { active_flag = 1; move16(); @@ -1169,8 +1454,7 @@ void ivas_set_ism_importance_interformat_fx( return; } -#endif - +#else void ivas_set_ism_importance_interformat( const int32_t ism_total_brate, /* i/o: ISms total bitrate */ const int16_t nchan_transport, /* i : number of transported channels */ @@ -1229,6 +1513,7 @@ void ivas_set_ism_importance_interformat( return; } +#endif /*--------------------------------------------------------------------------* * ivas_set_surplus_brate_enc() @@ -1504,6 +1789,11 @@ static void ivas_omasa_param_est_enc_fx( set_zero_fx( diffuseness_m_fx, hOMasa->nbands ); set16_fx( renormalization_factor_diff_e, 0, hOMasa->nbands ); set16_fx( diffuseness_e, 0, hOMasa->nbands ); + FOR( i = 0; i < nchan_ism; i++ ) + { + set_zero_fx( Chnl_RealBuffer_fx[i], 60 ); + set_zero_fx( Chnl_ImagBuffer_fx[i], 60 ); + } /* Compute ISM to FOA matrices */ FOR( i = 0; i < nchan_ism; i++ ) { @@ -1583,7 +1873,7 @@ static void ivas_omasa_param_est_enc_fx( { FOR( j = brange[0]; j < brange[1]; j++ ) { - temp = Mpy_32_32( Chnl_RealBuffer_fx[k][j], Chnl_RealBuffer_fx[k][j] ), Mpy_32_32( Chnl_ImagBuffer_fx[k][j], Chnl_ImagBuffer_fx[k][j] ); + temp = L_add( Mpy_32_32( Chnl_RealBuffer_fx[k][j], Chnl_RealBuffer_fx[k][j] ), Mpy_32_32( Chnl_ImagBuffer_fx[k][j], Chnl_ImagBuffer_fx[k][j] ) ); temp_e = sub( 62, shl( q, 1 ) ); hOmasaData->energy_ism_fx[block_m_idx][i] = BASOP_Util_Add_Mant32Exp( hOmasaData->energy_ism_fx[block_m_idx][i], hOmasaData->energy_ism_fx_e[block_m_idx][i], temp, temp_e, &hOmasaData->energy_ism_fx_e[block_m_idx][i] ); /*2q-31*/ move32(); @@ -1670,7 +1960,7 @@ static void ivas_omasa_param_est_enc_fx( move32(); move32(); - diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( diffuseness_m_fx[band_m_idx], diffuseness_e[band_m_idx], Mpy_32_32( reference_power_fx[ts][band_m_idx], diffuseness_vector_fx[band_m_idx] ), ref_exp + 1, &diffuseness_e[band_m_idx] ); /*(30-ref_exp)*/ + diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( diffuseness_m_fx[band_m_idx], diffuseness_e[band_m_idx], W_extract_l( W_shr( W_mult0_32_32( reference_power_fx[ts][band_m_idx], diffuseness_vector_fx[band_m_idx] ), 30 ) ), ref_exp, &diffuseness_e[band_m_idx] ); /*(30-ref_exp)*/ renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_e[band_m_idx], reference_power_fx[ts][band_m_idx], ref_exp, &renormalization_factor_diff_e[band_m_idx] ); move32(); move32(); @@ -1711,7 +2001,7 @@ static void ivas_omasa_param_est_enc_fx( { IF( GT_32( BASOP_Util_Log10( renormalization_factor_diff_fx[band_m_idx], ref_exp ), -( 15 << 25 ) ) ) { - diffuseness_m_fx[band_m_idx] = BASOP_Util_Divide3232_Scale( diffuseness_m_fx[band_m_idx], renormalization_factor_diff_fx[band_m_idx], &temp_e ); + diffuseness_m_fx[band_m_idx] = BASOP_Util_Divide3232_Scale( diffuseness_m_fx[band_m_idx], L_add( renormalization_factor_diff_fx[band_m_idx], EPSILON_FX ), &temp_e ); temp_e = add( temp_e, sub( diffuseness_e[band_m_idx], renormalization_factor_diff_e[band_m_idx] ) ); } ELSE diff --git a/lib_enc/ivas_pca_enc.c b/lib_enc/ivas_pca_enc.c index 726df7c99b62d7377a9f42e7f45d804fa023681c..17cd24ba34b7bcf6648612be3b93b2dfcbac02a7 100644 --- a/lib_enc/ivas_pca_enc.c +++ b/lib_enc/ivas_pca_enc.c @@ -460,17 +460,28 @@ static void sort4_D_eigVec_fx( * * Initialize PCA encoder *------------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void ivas_pca_enc_init( PCA_ENC_STATE *hPCA /* i/o: PCA encoder structure */ ) { hPCA->prev_bypass_decision = PCA_MODE_INACTIVE; + move32(); pca_enc_reset( hPCA ); return; } +#else +void ivas_pca_enc_init( + PCA_ENC_STATE *hPCA /* i/o: PCA encoder structure */ +) +{ + hPCA->prev_bypass_decision = PCA_MODE_INACTIVE; + pca_enc_reset( hPCA ); + return; +} +#endif /*------------------------------------------------------------------------- * ivas_pca_enc() diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index bfc3155c85f7097757459a6d540f6cd8cda325df..bde299111f08be40d607c4988cf5646ba9a88a89 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -306,6 +306,12 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512( IVAS_QMETADAT static int16_t ivas_qmetadata_quantize_coherence_hr_512( IVAS_QMETADATA *hQMetaData, const int16_t idx_d, const int16_t all_coherence_zero, BSTR_ENC_HANDLE hMetaData, const int16_t bits_coh ); static int16_t encode_surround_coherence_hr( IVAS_QMETADATA *hQMetaData, BSTR_ENC_HANDLE hMetaData ); + +static int16_t write_stream_dct_coeffs_omasa( int16_t *q_idx, const int16_t len_stream, BSTR_ENC_HANDLE hMetaData, const int16_t first_line, const int16_t low_bitrate_mode ); + +static int16_t find_optimal_GR_order( const int16_t *q_idx, const int16_t len, int16_t *GR ); + +static int16_t find_optimal_GR_orders( const int16_t *q_idx, const int16_t len, const int16_t len_max_GR1, int16_t *GR1, int16_t *GR2, int16_t *i_min ); #else static Word16 ivas_qmetadata_quantize_coherence_hr_512_fx( IVAS_QMETADATA *hQMetaData, const Word16 idx_d, const Word16 all_coherence_zero, BSTR_ENC_HANDLE hMetaData, const Word16 bits_coh ); @@ -314,13 +320,13 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512_fx( IVAS_QMETA static Word16 calc_var_azi_fx( const IVAS_QDIRECTION *q_direction, const Word16 diffuseness_index_max_ec_frame, const Word32 avg_azimuth, Word32 *avg_azimuth_out ); static Word16 encode_surround_coherence_hr_fx( IVAS_QMETADATA *hQMetaData, BSTR_ENC_HANDLE hMetaData ); -#endif -static int16_t write_stream_dct_coeffs_omasa( int16_t *q_idx, const int16_t len_stream, BSTR_ENC_HANDLE hMetaData, const int16_t first_line, const int16_t low_bitrate_mode ); +static Word16 write_stream_dct_coeffs_omasa_fx( Word16 *q_idx, const Word16 len_stream, BSTR_ENC_HANDLE hMetaData, const Word16 first_line, const Word16 low_bitrate_mode ); -static int16_t find_optimal_GR_order( const int16_t *q_idx, const int16_t len, int16_t *GR ); +static Word16 find_optimal_GR_order_fx( const Word16 *q_idx, const Word16 len, Word16 *GR ); -static int16_t find_optimal_GR_orders( const int16_t *q_idx, const int16_t len, const int16_t len_max_GR1, int16_t *GR1, int16_t *GR2, int16_t *i_min ); +static Word16 find_optimal_GR_orders_fx( const Word16 *q_idx, const Word16 len, const Word16 len_max_GR1, Word16 *GR1, Word16 *GR2, Word16 *i_min ); +#endif /*-----------------------------------------------------------------------* @@ -349,7 +355,6 @@ ivas_error ivas_qmetadata_enc_encode_fx( Word16 nbands, nblocks, start_band; Word16 ndirections, d; Word32 azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - float azimuth_orig_flt[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], elevation_orig_flt[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; Word16 all_coherence_zero; Word16 bit_pos_0, total_bits_1dir, bits_no_dirs_coh; Word16 bits_signaling[QMETADATA_MAX_NO_DIRECTIONS]; @@ -436,7 +441,7 @@ ivas_error ivas_qmetadata_enc_encode_fx( bits_diff_sum = 0; move16(); - // TODO + bits_diff[0] = ivas_qmetadata_entropy_encode_diffuseness_fx( hMetaData, &( hQMetaData->q_direction[0] ), &diffuseness_index_max_ec_frame_pre[0] ); move16(); bits_diff_sum = add( bits_diff_sum, bits_diff[0] ); @@ -585,7 +590,6 @@ ivas_error ivas_qmetadata_enc_encode_fx( q_direction->not_in_2D = 0; move16(); /* Quantize directions*/ - // TODO : Remove azimuth_orig_flt and elevation_orig_flt once full fixed point quantize_direction_frame2D_fx( q_direction, azimuth_orig, elevation_orig ); } ELSE @@ -709,19 +713,6 @@ ivas_error ivas_qmetadata_enc_encode_fx( extra_bits = sub( hQMetaData->metadata_max_bits, sub( hMetaData->nb_bits_tot, bit_pos_0 ) ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) - { - fixedToFloat_arrL( hQMetaData->q_direction[d].band_data[j].azimuth_fx, hQMetaData->q_direction[d].band_data[j].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[d].band_data[j].elevation_fx, hQMetaData->q_direction[d].band_data[j].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - for ( i = start_band; i < nbands; i++ ) - { - fixedToFloat_arrL( azimuth_orig[i], azimuth_orig_flt[i], Q22, nblocks ); - fixedToFloat_arrL( elevation_orig[i], elevation_orig_flt[i], Q22, nblocks ); - } -#endif - /* Requantized directions */ IF( LE_16( add( total_bits_1dir, bits_surround_coh ), hQMetaData->qmetadata_max_bit_req ) && GT_16( add( add( add( bits_dir[d], bits_diff[d] ), bits_coherence[d] ), bits_signaling[d] ), total_bits_1dir ) ) { @@ -747,59 +738,48 @@ ivas_error ivas_qmetadata_enc_encode_fx( IF( hQMetaData->is_masa_ivas_format == 0 ) { - reduce_bits = bits_dir_raw - ( total_bits_1dir - bits_diff[d] - bits_coherence[d] - bits_signaling[d] ); + reduce_bits = sub( bits_dir_raw, sub( sub( sub( total_bits_1dir, bits_diff[d] ), bits_coherence[d] ), bits_signaling[d] ) ); ind_order[0] = -1; + move16(); } ELSE { ind_order[0] = 0; - reduce_bits = min( nbands * nblocks + MASA_BIT_REDUCT_PARAM, bits_dir_raw - ( total_bits_1dir - bits_diff[d] - bits_coherence[d] - bits_signaling[d] ) ); + move16(); + reduce_bits = s_min( add( imult1616( nbands, nblocks ), MASA_BIT_REDUCT_PARAM ), sub( bits_dir_raw, sub( sub( sub( total_bits_1dir, bits_diff[d] ), bits_coherence[d] ), bits_signaling[d] ) ) ); - IF( GT_16( reduce_bits, ( bits_dir_raw - nbands * nblocks ) ) ) + IF( GT_16( reduce_bits, sub( bits_dir_raw, imult1616( nbands, nblocks ) ) ) ) { - reduce_bits = bits_dir_raw - nbands * nblocks; + reduce_bits = sub( bits_dir_raw, imult1616( nbands, nblocks ) ); } } only_reduce_bits_direction_fx( &extra_bits, q_direction, reduce_bits, nbands, nblocks, ind_order ); bits_dir[d] = hMetaData->nb_bits_tot; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - for ( int j = 0; j < MASA_MAXIMUM_CODING_SUBBANDS; j++ ) - { - floatToFixed_arrL32( elevation_orig_flt[j], elevation_orig[j], Q22, 4 ); - floatToFixed_arrL32( azimuth_orig_flt[j], azimuth_orig[j], Q22, 4 ); - } + move16(); - for ( int k = q_direction->cfg.start_band; k < q_direction->cfg.nbands; k++ ) - { - floatToFixed_arrL32( q_direction->band_data[k].elevation, q_direction->band_data[k].elevation_fx, Q22, 4 ); - floatToFixed_arrL32( q_direction->band_data[k].azimuth, q_direction->band_data[k].azimuth_fx, Q22, 4 ); - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS requantize_direction_EC_3_fx( &extra_bits, q_direction, nbands, hMetaData, elevation_orig, azimuth_orig, ind_order ); - bits_dir[d] = hMetaData->nb_bits_tot - bits_dir[d]; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int k = q_direction->cfg.start_band; k < q_direction->cfg.nbands; k++ ) - { - fixedToFloat_arrL32( q_direction->band_data[k].elevation_fx, q_direction->band_data[k].elevation, Q22, 4 ); - fixedToFloat_arrL32( q_direction->band_data[k].azimuth_fx, q_direction->band_data[k].azimuth, Q22, 4 ); - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS + bits_dir[d] = sub( hMetaData->nb_bits_tot, bits_dir[d] ); + move16(); } /* finalize writing coherence */ + test(); + test(); IF( GT_16( bits_coherence[d], 0 ) && EQ_16( all_coherence_zero, 0 ) && GT_16( nblocks, 1 ) ) { bit_pos_start = hMetaData->nb_bits_tot; hMetaData->nb_bits_tot = bit_pos_start_coh; ivas_qmetadata_quantize_coherence_fx( hQMetaData, d, all_coherence_zero, hMetaData, 1, &indice_coherence, 0 ); hMetaData->nb_bits_tot = bit_pos_start; + move16(); + move16(); + move16(); } - IF( EQ_16( d, 0 ) ) + IF( d == 0 ) { - total_bits_1dir = hQMetaData->metadata_max_bits - ( hMetaData->nb_bits_tot - bit_pos_0 ); + total_bits_1dir = sub( hQMetaData->metadata_max_bits, sub( hMetaData->nb_bits_tot, bit_pos_0 ) ); } /* Save quantized DOAs */ @@ -810,13 +790,6 @@ ivas_error ivas_qmetadata_enc_encode_fx( } /* Copy original DOAs back to q_direction*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = start_band; i < nbands; i++ ) - { - floatToFixed_arrL( azimuth_orig_flt[i], azimuth_orig[i], Q22, nblocks ); - floatToFixed_arrL( elevation_orig_flt[i], elevation_orig[i], Q22, nblocks ); - } -#endif FOR( i = start_band; i < nbands; i++ ) { Copy32( azimuth_orig[i], q_direction->band_data[i].azimuth_fx, nblocks ); @@ -1221,7 +1194,7 @@ ivas_error ivas_qmetadata_enc_encode( * * Main function for quantizing and coding Spatial Metadata at HRs *-----------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_qmetadata_enc_encode_hr_384_512( BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ IVAS_QMETADATA *hQMetaData, /* i/o: metadata handle */ @@ -1460,7 +1433,7 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512( return error; } -#ifdef IVAS_FLOAT_FIXED +#else ivas_error ivas_qmetadata_enc_encode_hr_384_512_fx( BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ IVAS_QMETADATA *hQMetaData, /* i/o: metadata handle */ @@ -2258,7 +2231,7 @@ Word16 quantize_direction2D_fx( } ELSE { - id_phi = quantize_phi_fx( L_add( phi, 180 << Q22 ), 0, phi_q, no_cw ); + id_phi = quantize_phi_enc_fx( L_add( phi, 180 << Q22 ), 0, phi_q, no_cw ); } *phi_q = L_sub( *phi_q, 180 << Q22 ); move32(); @@ -4284,7 +4257,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( } } - avg_azimuth_index = (UWord16) ( quantize_phi_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); + avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); /* Elevation only if not 2D */ IF( q_direction->not_in_2D > 0 ) @@ -4427,7 +4400,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( { use_adapt_avg = calc_var_azi_fx( q_direction, diffuseness_index_max_ec_frame, L_sub( avg_azimuth, 180 << Q22 ), &avg_azimuth ); // 180.Q22 - avg_azimuth_index = (UWord16) ( quantize_phi_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); + avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); } avg_azimuth_index_initial = avg_azimuth_index; /* avg_azimuth_index;*/ move16(); @@ -4505,7 +4478,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( v_add_fixed( avg_direction_vector, direction_vector, avg_direction_vector, 3, 0 ); ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector, Q22, &avg_azimuth, &avg_elevation ); - avg_azimuth_index_upd = quantize_phi_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ); + avg_azimuth_index_upd = quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ); } idx = add( idx, 1 ); } @@ -5799,7 +5772,7 @@ static Word16 truncGR0_fx( FOR( i = 0; i < len; i++ ) { - data_idx[i] = quantize_phi_fx( L_add( data_fx[i], DEGREE_180_Q_22 ), 0, &data_hat_fx[i], 8 ); + data_idx[i] = quantize_phi_enc_fx( L_add( data_fx[i], DEGREE_180_Q_22 ), 0, &data_hat_fx[i], 8 ); move16(); data_hat_fx[i] = L_sub( data_hat_fx[i], DEGREE_180_Q_22 ); move32(); @@ -5823,7 +5796,7 @@ static Word16 truncGR0_fx( { bits = sub( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[indx[i]], 8, 0 ) ); // data_idx[indx[i]] = quantize_phi( data[indx[i]] + 180, 0, &data_hat[indx[i]], 4 ); - data_idx[indx[i]] = quantize_phi_fx( L_add( data_fx[indx[i]], DEGREE_180_Q_22 ), 0, &data_hat_fx[indx[i]], 4 ); + data_idx[indx[i]] = quantize_phi_enc_fx( L_add( data_fx[indx[i]], DEGREE_180_Q_22 ), 0, &data_hat_fx[indx[i]], 4 ); move16(); // data_hat[indx[i]] -= 180; data_hat_fx[indx[i]] = L_sub( data_hat_fx[indx[i]], DEGREE_180_Q_22 ); @@ -11223,7 +11196,7 @@ static void transform_azimuth_dir2( return; } #endif - +#ifndef IVAS_FLOAT_FIXED static int16_t divide_GR_orders( const int16_t *q_idx, const int16_t GR1, @@ -11498,13 +11471,331 @@ static int16_t write_stream_dct_coeffs_omasa( return nb_bits; } +#else +static Word16 divide_GR_orders_fx( + const Word16 *q_idx, + const Word16 GR1, + const Word16 GR2, + const Word16 len, + const Word16 len_max_GR1, + Word16 *i_min ) +{ + Word16 nb_GR_min; + Word16 i, j, nb_GR; + nb_GR_min = 1000; + *i_min = -1; + move16(); + move16(); + FOR( i = 0; i < s_min( len_max_GR1, len ); i++ ) + { + nb_GR = 0; + move16(); + + FOR( j = 0; j <= i; j++ ) + { + nb_GR = add( nb_GR, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR1 ) ); + } + FOR( j = i + 1; j < len; j++ ) + { + nb_GR = add( nb_GR, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ) ); + } + + IF( LT_16( nb_GR, nb_GR_min ) ) + { + nb_GR_min = nb_GR; + *i_min = add( i, 1 ); + move16(); + move16(); + } + } + + return nb_GR_min; +} + + +static Word16 find_optimal_GR_order_fx( + const Word16 *q_idx, + const Word16 len, + Word16 *GR ) +{ + Word16 nb_GR_0, nb_GR_1; + Word16 i; + /* find optimum length of the part encoded with GR2 */ + nb_GR_0 = 0; + nb_GR_1 = 0; + move16(); + move16(); + FOR( i = 0; i < len; i++ ) + { + nb_GR_0 = add( nb_GR_0, ivas_qmetadata_encode_extended_gr_length( q_idx[i], 100, 0 ) ); + nb_GR_1 = add( nb_GR_1, ivas_qmetadata_encode_extended_gr_length( q_idx[i], 100, 1 ) ); + } + + IF( LT_16( nb_GR_0, nb_GR_1 ) ) + { + *GR = 0; + move16(); + return nb_GR_0; + } + ELSE + { + *GR = 1; + move16(); + + return nb_GR_1; + } +} + + +static Word16 find_optimal_GR_orders_fx( + const Word16 *q_idx, + const Word16 len, + const Word16 len_max_GR1, + Word16 *GR1, + Word16 *GR2, + Word16 *i_min ) +{ + Word16 nb_GR_20, nb_GR_21, nb_GR_10, nb_GR_min; + Word16 i_min_20, i_min_21, i_min_10; + /* find optimum length of the part encoded with GR2 */ + nb_GR_20 = divide_GR_orders_fx( q_idx, 2, 0, len, len_max_GR1, &i_min_20 ); + nb_GR_21 = divide_GR_orders_fx( q_idx, 2, 1, len, len_max_GR1, &i_min_21 ); + nb_GR_10 = divide_GR_orders_fx( q_idx, 1, 0, len, len_max_GR1, &i_min_10 ); + + test(); + IF( LT_16( nb_GR_20, nb_GR_21 ) && LT_16( nb_GR_20, nb_GR_10 ) ) + { + *GR1 = 2; + *GR2 = 0; + nb_GR_min = nb_GR_20; + *i_min = i_min_20; + move16(); + move16(); + move16(); + move16(); + } + ELSE + { + test(); + IF( LT_16( nb_GR_21, nb_GR_20 ) && LT_16( nb_GR_21, nb_GR_10 ) ) + { + *GR1 = 2; + *GR2 = 1; + nb_GR_min = nb_GR_21; + *i_min = i_min_21; + move16(); + move16(); + move16(); + move16(); + } + ELSE + { + *GR1 = 1; + *GR2 = 0; + nb_GR_min = nb_GR_10; + *i_min = i_min_10; + move16(); + move16(); + move16(); + move16(); + } + } + + return nb_GR_min; +} + + +static Word16 write_stream_dct_coeffs_omasa_fx( + Word16 *q_idx, /* i : array of indexes to be written */ + const Word16 len_stream, /* i : array length */ + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream */ + const Word16 first_line, /* i : is first line of the matrix? 1/0 */ + const Word16 low_bitrate_mode /* i : is low bitrate mode? if yes, limit the number of bits written */ +) +{ + Word16 nb_bits = 0, bits_pos; + UWord16 nb_GR_min; + Word16 i, j; + Word16 changed, update_needed; + move16(); + Word16 GR1, GR2, i_min; + Word16 max_bits; + + bits_pos = hMetaData->nb_bits_tot; + move16(); + IF( EQ_16( low_bitrate_mode, 1 ) ) + { + max_bits = 50; + move16(); + } + ELSE + { + max_bits = 1000; + move16(); + } + + /* write DCT 0 component */ + /* write sign only if not the very first DCT coeff */ + IF( first_line == 0 ) + { + IF( q_idx[0] > 0 ) + { + push_next_indice( hMetaData, 1, 1 ); + push_next_indice( hMetaData, q_idx[0], BITS_MASA2TOTTAL_DCT0 ); + } + ELSE + { + push_next_indice( hMetaData, 0, 1 ); + push_next_indice( hMetaData, negate( q_idx[0] ), BITS_MASA2TOTTAL_DCT0 ); + } + nb_bits = add( nb_bits, BITS_MASA2TOTTAL_DCT0 + 1 ); + } + ELSE + { + push_next_indice( hMetaData, q_idx[0], BITS_MASA2TOTTAL_DCT0 ); + nb_bits = add( nb_bits, BITS_MASA2TOTTAL_DCT0 ); + } + + IF( q_idx[0] != 0 ) + { + i_min = 1; + GR2 = 0; + move16(); + move16(); + IF( GE_16( len_stream, 8 ) ) + { + nb_GR_min = find_optimal_GR_orders_fx( &q_idx[1], sub( len_stream, 1 ), 15, &GR1, &GR2, &i_min ); + } + ELSE + { + nb_GR_min = find_optimal_GR_order_fx( &q_idx[1], sub( len_stream, 1 ), &GR1 ); + } + + assert( nb_GR_min < 1000 ); + changed = 1; + update_needed = 0; + move16(); + move16(); + WHILE( GE_16( len_stream, 8 ) && GT_16( nb_GR_min, max_bits ) && GE_16( changed, 1 ) ) + { + test(); + test(); + update_needed = 1; + changed = 0; + move16(); + move16(); + FOR( j = len_stream - 1; j > 6; j-- ) + { + IF( GE_16( q_idx[j], 2 ) ) + { + + IF( GT_16( j, i_min ) ) + { + changed = 1; + move16(); + nb_GR_min = sub( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ) ); + q_idx[j] = sub( q_idx[j], 2 ); + move16(); + nb_GR_min = add( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ) ); + } + ELSE + { + changed = 1; + move16(); + nb_GR_min = sub( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR1 ) ); + q_idx[j] = sub( q_idx[j], 2 ); + move16(); + nb_GR_min = add( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, 0 ) ); + } + } + ELSE IF( EQ_16( q_idx[j], 1 ) ) + { + IF( GT_16( j, i_min ) ) + { + changed = 1; + move16(); + nb_GR_min = sub( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ) ); + q_idx[j] = sub( q_idx[j], 1 ); + move16(); + + nb_GR_min = add( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ) ); + } + ELSE + { + changed = 1; + move16(); + nb_GR_min = sub( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR1 ) ); + q_idx[j] = sub( q_idx[j], 1 ); + move16(); + nb_GR_min = add( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, 0 ) ); + } + } + IF( LT_16( nb_GR_min, max_bits ) ) + { + BREAK; + } + } + } + + IF( EQ_16( update_needed, 1 ) ) + { + /* re-calculate */ + /* find optimum length of the part encoded with GR2 */ + nb_GR_min = find_optimal_GR_orders_fx( &q_idx[1], sub( len_stream, 1 ), 15, &GR1, &GR2, &i_min ); + } + + IF( GE_16( len_stream, 8 ) ) + { + /* write number of indexes encoded with GR2 on 4 bits */ + push_next_indice( hMetaData, i_min, 4 ); + nb_bits = add( nb_bits, 4 ); + /* write GR orders */ + push_next_indice( hMetaData, sub( GR1, 1 ), 1 ); + nb_bits = add( nb_bits, 1 ); + IF( EQ_16( GR1, 2 ) ) + { + push_next_indice( hMetaData, GR2, 1 ); + nb_bits = add( nb_bits, 1 ); + } + + /* write GR data */ + FOR( i = 1; i <= i_min; i++ ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, GR1 ); + } + + FOR( i = i_min + 1; i < len_stream; i++ ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, GR2 ); + } + } + ELSE + { + /* len_stream <= 8 */ + /* write GR order */ + push_next_indice( hMetaData, GR1, 1 ); + nb_bits = add( nb_bits, 1 ); + FOR( i = 1; i < len_stream; i++ ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, GR1 ); + } + } + + nb_bits = add( nb_bits, nb_GR_min ); + + assert( nb_bits == ( hMetaData->nb_bits_tot - bits_pos ) ); + } + + return nb_bits; +} +#endif /*------------------------------------------------------------------------- * ivas_omasa_encode_masa_to_total() * *------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_omasa_encode_masa_to_total( float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], BSTR_ENC_HANDLE hMetaData, @@ -11686,3 +11977,228 @@ void ivas_omasa_encode_masa_to_total( return; } +#else +void ivas_omasa_encode_masa_to_total_fx( + Word32 masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* Q30 */ + BSTR_ENC_HANDLE hMetaData, + const Word16 low_bitrate_mode, + const Word16 nbands, + const Word16 nblocks ) +{ + Word16 i, j, k; + Word32 data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; // Q30 + Word32 q_dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + Word32 step = STEP_M2T_FX; + Word16 q_idx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + Word32 dct_data_tmp[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + Word32 dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + Word16 dct_data_e = 0, dct_data_tmp_e, q_dct_data_e; + Word16 bits_pos, nb_bits; + Word16 n_streams, len_stream, tmp_e; + Word32 L_tmp; + move32(); + move16(); + + set32_fx( q_dct_data, 0, MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS ); + bits_pos = hMetaData->nb_bits_tot; + k = 0; + move16(); + move16(); + FOR( i = 0; i < nbands; i++ ) + { + FOR( j = 0; j < nblocks; j++ ) + { + data[k] = masa_to_total_energy_ratio[j][i]; + move32(); + k = add( k, 1 ); + } + } + + /* DCT2 transform */ + n_streams = 1; + move16(); + len_stream = imult1616( nbands, nblocks ); + SWITCH( len_stream ) + { + case 4: + matrix_product_mant_exp_fx( dct4_fx, 0 /* Q31 */, nblocks, nblocks, 0, data, 1 /* Q30*/, 1, nblocks, 1, dct_data, &dct_data_e ); + n_streams = 1; + len_stream = 4; + move16(); + BREAK; + case 5: + matrix_product_mant_exp_fx( dct5_fx, 0 /* Q31 */, nbands, nbands, 0, data, 1 /* Q30 */, 1, nbands, 1, dct_data, &dct_data_e ); + n_streams = 1; + len_stream = nbands; + move16(); + move16(); + BREAK; + case 8: + matrix_product_mant_exp_fx( dct8_fx, 0 /* Q31 */, nbands, nbands, 0, data, 1 /* Q30 */, 1, nbands, 1, dct_data, &dct_data_e ); + n_streams = 1; + len_stream = nbands; + move16(); + BREAK; + case 12: + matrix_product_mant_exp_fx( dct12_fx, 0 /* Q31 */, nbands, nbands, 0, data, 1 /* Q30 */, 1, nbands, 1, dct_data, &dct_data_e ); + n_streams = 1; + len_stream = nbands; + move16(); + move16(); + BREAK; + case 20: + matrix_product_mant_exp_fx( dct5_fx, 0 /* Q31 */, nbands, nbands, 0, data, 1 /* Q30 */, nblocks, nbands, 1, dct_data_tmp, &dct_data_e ); + matrix_product_mant_exp_fx( dct_data_tmp, dct_data_e, nbands, nblocks, 0, dct4_fx, 0 /* Q31 */, nblocks, nblocks, 1, dct_data, &dct_data_e ); + n_streams = 1; + len_stream = imult1616( nbands, nblocks ); + move16(); + move16(); + BREAK; + case 32: + matrix_product_mant_exp_fx( dct8_fx, 0 /* Q31 */, nbands, nbands, 0, data, 1 /* Q30 */, nblocks, nbands, 1, dct_data_tmp, &dct_data_e ); + matrix_product_mant_exp_fx( dct_data_tmp, dct_data_e, nbands, nblocks, 0, dct4_fx, 0 /* Q31 */, nblocks, nblocks, 1, dct_data, &dct_data_e ); + n_streams = nblocks; + len_stream = nbands; + move16(); + move16(); + BREAK; + default: + printf( "Incorrect number of coefficients for OMASA.\n" ); + BREAK; + } + + FOR( k = 0; k < n_streams; k++ ) + { + j = imult1616( k, len_stream ); + /* quantize with fixed common step */ + L_tmp = BASOP_Util_Divide3232_Scale_cadence( dct_data[j], step, &tmp_e ); + tmp_e = add( tmp_e, dct_data_e ); + q_idx[j] = rint_new_fx( L_shr( L_tmp, sub( 15, tmp_e ) ) /* Q16 */ ); // Q0 + move16(); + + IF( GT_16( q_idx[j], ( ( 1 << BITS_MASA2TOTTAL_DCT0 ) - 1 ) ) ) /* limit DCT0 to BITS_MASA2TOTTAL_DCT0 bit representation */ + { + q_idx[j] = ( ( 1 << BITS_MASA2TOTTAL_DCT0 ) - 1 ); + move16(); + } + + q_dct_data[j] = Mpy_32_16_1( step, shl( q_idx[j], 9 ) /* Q9 */ ); // Q25 + move16(); + + IF( q_idx[j] == 0 ) + { + set16_fx( &q_idx[j], 0, len_stream ); + set32_fx( &q_dct_data[j], 0, len_stream ); + } + ELSE + { + FOR( i = 1; i < len_stream; i++ ) + { + L_tmp = BASOP_Util_Divide3232_Scale_cadence( dct_data[j + i], step, &tmp_e ); + tmp_e = add( tmp_e, dct_data_e ); + q_idx[j + i] = rint_new_fx( L_shr( L_tmp, sub( 15, tmp_e ) ) ); + move16(); + q_dct_data[j + i] = Mpy_32_16_1( step, shl( q_idx[j + i], 9 ) /* Q9 */ ); // Q25 + move32(); + IF( q_idx[j + i] <= 0 ) + { + q_idx[j + i] = imult1616( -2, q_idx[j + i] ); + move16(); + } + ELSE + { + q_idx[j + i] = sub( imult1616( 2, q_idx[j + i] ), 1 ); + move16(); + } + } + } + } + + /* write data */ + nb_bits = 0; + move16(); + FOR( i = 0; i < n_streams; i++ ) + { + nb_bits = add( nb_bits, write_stream_dct_coeffs_omasa_fx( &q_idx[i * len_stream], len_stream, hMetaData, ( i == 0 ), low_bitrate_mode ) ); + } + + /* reconstruct masa2total */ + q_dct_data[0] = Mpy_32_16_1( step, shl( q_idx[0], 9 ) /* Q9 */ ); // Q25 + move32(); + FOR( i = 1; i < len_stream; i++ ) + { + IF( ( q_idx[i] % 2 ) == 0 ) + { + q_dct_data[i] = L_negate( Mpy_32_16_1( step, shl( q_idx[i], 8 ) /* Q9 */ ) ); // Q25 + move32(); + } + ELSE + { + q_dct_data[i] = Mpy_32_16_1( step, shl( add( q_idx[i], 1 ), 8 ) /* Q9 */ ); // Q25 + move32(); + } + } + + q_dct_data_e = 6; // Q25 + move16(); + /* inverse DCT2 transform */ + SWITCH( len_stream ) + { + case 4: + matrix_product_mant_exp_fx( dct4_fx, 0 /* Q31 */, nblocks, nblocks, 1, q_dct_data, q_dct_data_e, nblocks, 1, 0, dct_data_tmp, &dct_data_tmp_e ); + Copy32( dct_data_tmp, q_dct_data, nblocks ); + q_dct_data_e = dct_data_tmp_e; + move16(); + BREAK; + case 5: + matrix_product_mant_exp_fx( dct5_fx, 0 /* Q31 */, nbands, nbands, 1, q_dct_data, q_dct_data_e, nbands, 1, 0, dct_data_tmp, &dct_data_tmp_e ); + Copy32( dct_data_tmp, q_dct_data, nbands ); + q_dct_data_e = dct_data_tmp_e; + move16(); + BREAK; + case 8: + matrix_product_mant_exp_fx( dct8_fx, 0 /* Q31 */, nbands, nbands, 1, q_dct_data, q_dct_data_e, nbands, 1, 0, dct_data_tmp, &dct_data_tmp_e ); + Copy32( dct_data_tmp, q_dct_data, nbands ); + q_dct_data_e = dct_data_tmp_e; + move16(); + BREAK; + case 12: + matrix_product_mant_exp_fx( dct12_fx, 0 /* Q31 */, nbands, nbands, 1, q_dct_data, q_dct_data_e, nbands, 1, 0, dct_data_tmp, &dct_data_tmp_e ); + Copy32( dct_data_tmp, q_dct_data, nbands ); + q_dct_data_e = dct_data_tmp_e; + move16(); + BREAK; + case 20: + matrix_product_mant_exp_fx( dct5_fx, 0 /* Q31 */, nbands, nbands, 1, q_dct_data, q_dct_data_e, nbands, nblocks, 0, dct_data_tmp, &dct_data_tmp_e ); + matrix_product_mant_exp_fx( dct_data_tmp, dct_data_tmp_e, nbands, nblocks, 0, dct4_fx, 0 /* Q31 */, nblocks, nblocks, 0, q_dct_data, &q_dct_data_e ); /* reuse of variable*/ + BREAK; + case 32: + matrix_product_mant_exp_fx( dct8_fx, 0 /* Q31 */, nbands, nbands, 1, q_dct_data, q_dct_data_e, nbands, nblocks, 0, dct_data_tmp, &dct_data_tmp_e ); + matrix_product_mant_exp_fx( dct_data_tmp, dct_data_tmp_e, nbands, nblocks, 0, dct4_fx, 0 /* Q31 */, nblocks, nblocks, 0, q_dct_data, &q_dct_data_e ); + BREAK; + default: + printf( "Incorrect number of coefficients for OMASA.\n" ); + BREAK; + } + + scale_sig32( q_dct_data, MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS, sub( Q30, sub( 31, q_dct_data_e ) ) ); // Scaling to Q30 + + k = 0; + move16(); + FOR( i = 0; i < nblocks; i++ ) + { + FOR( j = 0; j < nbands; j++ ) + { + masa_to_total_energy_ratio[i][j] = L_max( 0, q_dct_data[k] ); + masa_to_total_energy_ratio[i][j] = L_min( ONE_IN_Q30, masa_to_total_energy_ratio[i][j] ); + move32(); + move32(); + k = add( k, 1 ); + } + } + assert( nb_bits == ( hMetaData->nb_bits_tot - bits_pos ) ); + + + return; +} +#endif diff --git a/lib_enc/ivas_qspherical_enc.c b/lib_enc/ivas_qspherical_enc.c index 879cccf6a8dc3d48f30f7496abeac24e38eba7bd..d2804108a7661c2d3c8180adb8f98a4021fa4e80 100644 --- a/lib_enc/ivas_qspherical_enc.c +++ b/lib_enc/ivas_qspherical_enc.c @@ -66,7 +66,7 @@ static Word16 direction_distance_cp_fx( Word32 theta, Word32 theta_hat, Word32 t * * *----------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void quantize_direction_frame( IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ float azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], @@ -166,7 +166,7 @@ void quantize_direction_frame( return; } -#ifdef IVAS_FLOAT_FIXED +#else void quantize_direction_frame_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ Word32 azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], /* o : Q22 */ @@ -812,7 +812,7 @@ UWord16 quantize_direction_fx( } ELSE { - id_phi = quantize_phi_fx( L_add( phi, DEGREE_180_Q_22 ), 0, &phi_hat, no_phi_masa[no_bits - 1][0] ); + id_phi = quantize_phi_enc_fx( L_add( phi, DEGREE_180_Q_22 ), 0, &phi_hat, no_phi_masa[no_bits - 1][0] ); idx_sph = id_phi; *phi_q = L_sub( phi_hat, DEGREE_180_Q_22 ); id_phi_remap = ivas_qmetadata_reorder_generic( sub( id_phi, shr( no_phi_masa[no_bits - 1][0], 1 ) ) ); @@ -1055,7 +1055,20 @@ static Word16 direction_distance_cp_fx( // Q14 // d = st * st1 + ct * ( sqrtf( 1 - st1 * st1 ) ) * cosf( ( phi - phi_hat ) * PI_OVER_180 ); /*( phi - phi_hat ) * PI_OVER_180 */ - tmp_phi = extract_l( Mpy_32_32( L_sub( phi, phi_hat ), PI_OVER_180_Q22 ) ); // (Q22 + Q22 - 31) = Q13 + IF( GT_32( L_sub( phi, phi_hat ), _180_IN_Q22 ) ) + { + // cos(360 - theta) = cos(theta) + tmp_phi = extract_l( Mpy_32_32( L_sub( _360_IN_Q22, L_sub( phi, phi_hat ) ), PI_OVER_180_Q22 ) ); // (Q22 + Q22 - 31) = Q13 + } + ELSE IF( LT_32( L_sub( phi, phi_hat ), -_180_IN_Q22 ) ) + { + // cos(360 + theta) = cos(theta) + tmp_phi = extract_l( Mpy_32_32( L_add( _360_IN_Q22, L_sub( phi, phi_hat ) ), PI_OVER_180_Q22 ) ); // (Q22 + Q22 - 31) = Q13 + } + ELSE + { + tmp_phi = extract_l( Mpy_32_32( L_sub( phi, phi_hat ), PI_OVER_180_Q22 ) ); // (Q22 + Q22 - 31) = Q13 + } tmp_e = 0; move16(); @@ -1067,13 +1080,26 @@ static Word16 direction_distance_cp_fx( // Q14 tmp = add_sat( tmp, shr( mult( st, st1 ), 1 ) /* Q14 */ ); // Q14 - d = tmp; // Q15 + d = tmp; // Q14 move16(); // *d1 = st * st2 + ct * ( sqrtf( 1 - st2 * st2 ) ) * cosf( ( phi - phi_hat1 ) * PI_OVER_180 ); /*( phi - phi_hat1 ) * PI_OVER_180 */ - tmp_phi = extract_l( Mpy_32_32( L_sub( phi, phi_hat1 ), PI_OVER_180_Q22 ) ); // (Q22 + Q22 - 31) = Q13 + IF( GT_32( L_sub( phi, phi_hat1 ), _180_IN_Q22 ) ) + { + // cos(360 - theta) = cos(theta) + tmp_phi = extract_l( Mpy_32_32( L_sub( _360_IN_Q22, L_sub( phi, phi_hat1 ) ), PI_OVER_180_Q22 ) ); // (Q22 + Q22 - 31) = Q13 + } + ELSE IF( LT_32( L_sub( phi, phi_hat1 ), -_180_IN_Q22 ) ) + { + // cos(360 + theta) = cos(theta) + tmp_phi = extract_l( Mpy_32_32( L_add( _360_IN_Q22, L_sub( phi, phi_hat1 ) ), PI_OVER_180_Q22 ) ); // (Q22 + Q22 - 31) = Q13 + } + ELSE + { + tmp_phi = extract_l( Mpy_32_32( L_sub( phi, phi_hat1 ), PI_OVER_180_Q22 ) ); // (Q22 + Q22 - 31) = Q13 + } tmp_e = 0; move16(); @@ -1313,7 +1339,7 @@ static Word32 quantize_theta_phi_fx( // Q22 } ELSE { - id_ph = quantize_phi_fx( phi, s_and( id_th, 1 ), phi_hat, no_phi_loc[id_th] ); + id_ph = quantize_phi_enc_fx( phi, s_and( id_th, 1 ), phi_hat, no_phi_loc[id_th] ); } } ELSE @@ -1336,7 +1362,7 @@ static Word32 quantize_theta_phi_fx( // Q22 theta_hat1 = theta_cb[id_th1]; move32(); - id_ph1 = quantize_phi_fx( phi, s_and( id_th1, 1 ), &phi_hat1, no_phi_loc[id_th1] ); + id_ph1 = quantize_phi_enc_fx( phi, s_and( id_th1, 1 ), &phi_hat1, no_phi_loc[id_th1] ); d_fx = direction_distance_cp_fx( abs_theta, theta_hat, theta_hat1, phi, *phi_hat, phi_hat1, &d1_fx ); @@ -1363,7 +1389,7 @@ static Word32 quantize_theta_phi_fx( // Q22 } ELSE { - id_ph = quantize_phi_fx( phi, s_and( id_th, 1 ), phi_hat, no_phi_loc[id_th] ); + id_ph = quantize_phi_enc_fx( phi, s_and( id_th, 1 ), phi_hat, no_phi_loc[id_th] ); } } diff --git a/lib_enc/ivas_rom_enc.c b/lib_enc/ivas_rom_enc.c index 7a83d7227b11944ef701d203fe7276a3258f59e1..1b222e5ed64d7ab2af9f717b1739bb78f3bf9368 100644 --- a/lib_enc/ivas_rom_enc.c +++ b/lib_enc/ivas_rom_enc.c @@ -996,13 +996,29 @@ const Word32 ari_bit_estimate_s17_LC_fx[RANGE_N_CONTEXT][RANGE_N_SYMBOLS] = // Q /*----------------------------------------------------------------------------------* * Stereo downmix to EVS ROM tables *----------------------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED +// Q31 +const Word32 Stereo_dmx_s_wnd_coef_16k_fx[L_FRAME16k >> 4] = { + 3309988, 29667578, 81733728, 158226416, 257262128, 376402368, 512713184, 662838656, 823081792, 989497088, + 1157986560, 1324401920, 1484645120, 1634770560, 1771081600, 1890221568, 1989257344, 2065750016, 2117816064, 2144173568 +}; +#endif const float Stereo_dmx_s_wnd_coef_16k[L_FRAME16k >> 4] = { 0.00154133327f, 0.0138150426f, 0.0380602330f, 0.0736799166f, 0.119797014f, 0.175276011f, 0.238750681f, 0.308658302f, 0.383277327f, 0.460770488f, 0.539229512f, 0.616722703f, 0.691341758f, 0.761249363f, 0.824724138f, 0.880203009f, 0.926320136f, 0.961939812f, 0.986184955f, 0.998458624f, }; +#ifdef IVAS_FLOAT_FIXED +// Q31 +const Word32 Stereo_dmx_s_wnd_coef_32k_fx[L_FRAME32k >> 4] = { + 827816, 7442688, 20631648, 40313376, 66366540, 98630536, 136906352, 180958112, 230514208, 285269056, + 344885056, 408994752, 477202848, 549088896, 624209472, 702101440, 782284928, 864265344, 947537088, 1031587008, + 1115896832, 1199946752, 1283218432, 1365198592, 1445382400, 1523274368, 1598395136, 1670280960, 1738488832, 1802598528, + 1862214528, 1916969472, 1966525568, 2010577280, 2048853120, 2081117056, 2107170304, 2126851968, 2140040960, 2146655872 +}; +#endif + const float Stereo_dmx_s_wnd_coef_32k[L_FRAME32k >> 4] = { 0.000385481922f, 0.00346577191f, 0.00960735977f, 0.0187723786f, 0.0309043285f, 0.0459284224f, 0.0637519881f, 0.0842651874f, 0.107341543f, 0.132838756f, 0.160599619f, 0.190453023f, 0.222214893f, 0.255689442f, 0.290670186f, 0.326941460f, 0.364279807f, 0.402454913f, 0.441231340f, 0.480370134f, @@ -1010,6 +1026,18 @@ const float Stereo_dmx_s_wnd_coef_32k[L_FRAME32k >> 4] = { 0.867161214f, 0.892658472f, 0.915734828f, 0.936248004f, 0.954071581f, 0.969095647f, 0.981227636f, 0.990392625f, 0.996534228f, 0.999614537f }; +#ifdef IVAS_FLOAT_FIXED +// Q31 +const Word32 Stereo_dmx_s_wnd_coef_48k_fx[L_FRAME48k >> 4] = { + 367944, 3309988, 9186011, 17979908, 29667578, 44216976, 61588232, 81733728, 104598264, 130119136, + 158226416, 188843056, 221885136, 257262128, 294876992, 334626720, 376402368, 420089216, 465567840, 512713184, + 561396544, 611484032, 662838656, 715319488, 768782656, 823081792, 878067904, 933590528, 989497088, 1045634688, + 1101849216, 1157986560, 1213893504, 1269415808, 1324401920, 1378700928, 1432164224, 1484645120, 1535999488, 1586087424, + 1634770560, 1681915904, 1727394560, 1771081600, 1812856960, 1852606720, 1890221568, 1925598592, 1958640640, 1989257344, + 2017364480, 2042885504, 2065750016, 2085895424, 2103266688, 2117816064, 2129503616, 2138297728, 2144173568, 2147115776 +}; +#endif + const float Stereo_dmx_s_wnd_coef_48k[L_FRAME48k >> 4] = { 0.000171337553f, 0.00154133327f, 0.00427756971f, 0.00837254710f, 0.0138150426f, 0.0205901340f, 0.0286792554f, 0.0380602330f, 0.0487073623f, 0.0605914444f, 0.0736799166f, 0.0879369006f, 0.103323318f, 0.119797014f, 0.137312800f, 0.155822709f, 0.175276011f, 0.195619285f, 0.216796920f, 0.238750681f, @@ -1019,6 +1047,76 @@ const float Stereo_dmx_s_wnd_coef_48k[L_FRAME48k >> 4] = { 0.939408541f, 0.951292694f, 0.961939812f, 0.971320748f, 0.979409873f, 0.986184955f, 0.991627395f, 0.995722473f, 0.998458624f, 0.999828696f }; +#ifdef IVAS_FLOAT_FIXED +// Q31 +const Word32 Stereo_dmx_wnd_coef_32k_fx[L_FRAME32k] = { + 5270712, 15812011, 26352928, 36893212, 47432604, 57970856, 68507712, 79042912, 89576208, 100107344, + 110636080, 121162136, 131685288, 142205264, 152721792, 163234656, 173743584, 184248336, 194748624, 205244240, + 215734896, 226220368, 236700384, 247174704, 257643072, 268105216, 278560896, 289009856, 299451872, 309886688, + 320314016, 330733632, 341145280, 351548704, 361943648, 372329888, 382707168, 393075200, 403433728, 413782592, + 424121472, 434450112, 444768288, 455075776, 465372256, 475657600, 485931392, 496193568, 506443680, 516681632, + 526907168, 537120000, 547319872, 557506560, 567679744, 577839360, 587984960, 598116544, 608233536, 618336000, + 628423488, 638495872, 648552832, 658594240, 668619712, 678629120, 688622144, 698598592, 708558080, 718500736, + 728425856, 738333568, 748223424, 758095296, 767948864, 777783936, 787600256, 797397632, 807175744, 816934464, + 826673472, 836392512, 846091520, 855770048, 865427968, 875065024, 884681024, 894275712, 903848768, 913400128, + 922929536, 932436608, 941921216, 951383168, 960822208, 970237952, 979630528, 988999360, 998344512, 1007665344, + 1016962112, 1026234368, 1035481728, 1044704256, 1053901632, 1063073728, 1072219968, 1081340416, 1090434944, 1099503104, + 1108544768, 1117559808, 1126547840, 1135508736, 1144442240, 1153348224, 1162226432, 1171076480, 1179898496, 1188691968, + 1197456896, 1206192896, 1214899840, 1223577472, 1232225792, 1240844288, 1249432832, 1257991296, 1266519552, 1275017216, + 1283484160, 1291920128, 1300325120, 1308698624, 1317040640, 1325350912, 1333629440, 1341875584, 1350089472, 1358270848, + 1366419456, 1374535168, 1382617728, 1390667008, 1398682752, 1406664832, 1414612992, 1422527104, 1430406912, 1438252288, + 1446062848, 1453838720, 1461579520, 1469285120, 1476955264, 1484589952, 1492188800, 1499751552, 1507278336, 1514768768, + 1522222720, 1529639808, 1537020288, 1544363520, 1551669760, 1558938496, 1566169600, 1573363200, 1580518656, 1587636096, + 1594715264, 1601756032, 1608758144, 1615721600, 1622646016, 1629531520, 1636377472, 1643184128, 1649951360, 1656678656, + 1663366016, 1670013440, 1676620544, 1683187072, 1689713280, 1696198656, 1702643328, 1709046784, 1715409152, 1721730176, + 1728009600, 1734247424, 1740443520, 1746597760, 1752709888, 1758779776, 1764807168, 1770792064, 1776734336, 1782633728, + 1788490240, 1794303744, 1800073984, 1805800704, 1811483904, 1817123584, 1822719360, 1828271360, 1833779328, 1839243008, + 1844662400, 1850037248, 1855367552, 1860653312, 1865894016, 1871089920, 1876240768, 1881346304, 1886406400, 1891421184, + 1896390400, 1901313920, 1906191616, 1911023360, 1915809152, 1920548480, 1925241856, 1929888768, 1934489088, 1939042944, + 1943549952, 1948010112, 1952423424, 1956789504, 1961108736, 1965380608, 1969604992, 1973782016, 1977911424, 1981993216, + 1986027264, 1990013440, 1993951616, 1997841920, 2001683840, 2005477760, 2009223168, 2012920192, 2016568832, 2020168704, + 2023720064, 2027222656, 2030676352, 2034081024, 2037436800, 2040743424, 2044000896, 2047209088, 2050368128, 2053477504, + 2056537472, 2059548032, 2062508928, 2065420032, 2068281344, 2071092864, 2073854464, 2076566144, 2079227776, 2081839360, + 2084400768, 2086911872, 2089372672, 2091783168, 2094143232, 2096452864, 2098711936, 2100920576, 2103078528, 2105185792, + 2107242240, 2109248000, 2111202944, 2113107072, 2114960128, 2116762368, 2118513536, 2120213632, 2121862656, 2123460608, + 2125007360, 2126502912, 2127947264, 2129340288, 2130681984, 2131972352, 2133211392, 2134398976, 2135535104, 2136619904, + 2137653120, 2138634880, 2139565056, 2140443648, 2141270784, 2142046208, 2142770048, 2143442304, 2144062976, 2144631808, + 2145149056, 2145614592, 2146028544, 2146390656, 2146701056, 2146959744, 2147166720, 2147321984, 2147425408, 2147477120, + 2147477120, 2147425408, 2147321984, 2147166720, 2146959744, 2146701056, 2146390656, 2146028416, 2145614592, 2145149056, + 2144631808, 2144062848, 2143442304, 2142770048, 2142046208, 2141270784, 2140443648, 2139565056, 2138634880, 2137653120, + 2136619904, 2135535104, 2134398976, 2133211392, 2131972352, 2130681984, 2129340288, 2127947136, 2126502912, 2125007360, + 2123460608, 2121862656, 2120213632, 2118513536, 2116762368, 2114960128, 2113107072, 2111202944, 2109248000, 2107242240, + 2105185792, 2103078400, 2100920576, 2098711936, 2096452864, 2094143232, 2091783040, 2089372672, 2086911872, 2084400640, + 2081839232, 2079227776, 2076566144, 2073854464, 2071092864, 2068281216, 2065419904, 2062508800, 2059547904, 2056537472, + 2053477376, 2050368000, 2047209216, 2044000896, 2040743424, 2037436800, 2034081024, 2030676224, 2027222528, 2023720064, + 2020168704, 2016568704, 2012920064, 2009223040, 2005477632, 2001683840, 1997841792, 1993951616, 1990013440, 1986027136, + 1981993216, 1977911424, 1973781888, 1969604864, 1965380352, 1961108608, 1956789504, 1952423168, 1948010112, 1943549824, + 1939042944, 1934489088, 1929888640, 1925241728, 1920548480, 1915809024, 1911023360, 1906191488, 1901313792, 1896390144, + 1891421184, 1886406272, 1881346304, 1876240640, 1871089792, 1865893888, 1860653312, 1855367552, 1850037120, 1844662144, + 1839242752, 1833779200, 1828271232, 1822719232, 1817123328, 1811483648, 1805800576, 1800073984, 1794303744, 1788490240, + 1782633728, 1776734208, 1770792064, 1764807040, 1758779520, 1752709632, 1746597504, 1740443520, 1734247424, 1728009472, + 1721730176, 1715409024, 1709046656, 1702643328, 1696198656, 1689713152, 1683186944, 1676620160, 1670013312, 1663365888, + 1656678400, 1649950976, 1643183872, 1636377472, 1629531520, 1622646144, 1615721600, 1608758016, 1601755776, 1594715264, + 1587635968, 1580518528, 1573362816, 1566169344, 1558938368, 1551669632, 1544363392, 1537020288, 1529639808, 1522222464, + 1514768896, 1507278336, 1499751552, 1492188544, 1484589568, 1476955264, 1469284992, 1461579392, 1453838464, 1446062464, + 1438252160, 1430407040, 1422527104, 1414612992, 1406664704, 1398682496, 1390667008, 1382617728, 1374535040, 1366419200, + 1358270464, 1350089344, 1341875456, 1333629056, 1325350656, 1317040640, 1308698496, 1300325248, 1291920256, 1283484032, + 1275016960, 1266519296, 1257991296, 1249432704, 1240844032, 1232225408, 1223577088, 1214899712, 1206192640, 1197456896, + 1188691968, 1179898368, 1171076224, 1162226432, 1153348096, 1144442112, 1135508480, 1126547456, 1117559680, 1108544640, + 1099502848, 1090434560, 1081339904, 1072219776, 1063073792, 1053901696, 1044704256, 1035481600, 1026233984, 1016962112, + 1007665280, 998344192, 988999040, 979630080, 970237888, 960821952, 951382784, 941921216, 932436480, 922929280, + 913400256, 903848768, 894275520, 884680768, 875064640, 865427904, 855769856, 846091200, 836392128, 826672960, + 816934272, 807175936, 797397696, 787600192, 777783744, 767948544, 758095296, 748223360, 738333376, 728425536, + 718500224, 708558080, 698598336, 688621760, 678629120, 668619584, 658593984, 648552960, 638495872, 628423360, + 618335744, 608233152, 598116480, 587984896, 577839104, 567679360, 557505984, 547319680, 537120192, 526907232, + 516681600, 506443520, 496193216, 485931456, 475657504, 465372096, 455075456, 444767840, 434450048, 424121248, + 413782240, 403433280, 393075072, 382706912, 372330016, 361943648, 351548576, 341145024, 330733248, 320314016, + 309886560, 299451616, 289009472, 278560384, 268105072, 257642784, 247174800, 236700368, 226220208, 215734608, + 205244320, 194748592, 184248144, 173743280, 163234208, 152721728, 142205056, 131684952, 121161680, 110635488, + 100107136, 89576376, 79042944, 68507608, 57970624, 47432244, 36893228, 26352814, 15811765, 5270335 +}; +#endif + const float Stereo_dmx_wnd_coef_32k[L_FRAME32k] = { 0.00245436677f, 0.00736304140f, 0.0122715384f, 0.0171797406f, 0.0220875274f, 0.0269947834f, 0.0319013894f, 0.0368072242f, 0.0417121723f, 0.0466161147f, 0.0515189394f, 0.0564205162f, 0.0613207407f, 0.0662194863f, 0.0711166263f, 0.0760120600f, 0.0809056610f, 0.0857973173f, 0.0906868950f, 0.0955742970f, @@ -1086,6 +1184,108 @@ const float Stereo_dmx_wnd_coef_32k[L_FRAME32k] = { 0.0466160178f, 0.0417122506f, 0.0368072391f, 0.0319013409f, 0.0269946754f, 0.0220873598f, 0.0171797480f, 0.0122714853f, 0.00736292684f, 0.00245419098f }; +#ifdef IVAS_FLOAT_FIXED +// Q31 +const Word32 Stereo_dmx_wnd_coef_48k_fx[L_FRAME48k] = { + 3513810, 10541394, 17568864, 24596146, 31623164, 38649844, 45676112, 52701888, 59727100, 66751676, + 73775536, 80798600, 87820800, 94842072, 101862312, 108881464, 115899464, 122916208, 129931632, 136945680, + 143958256, 150969296, 157978704, 164986432, 171992400, 178996496, 185998688, 192998912, 199997040, 206993040, + 213986832, 220978320, 227967424, 234954096, 241938272, 248919856, 255898752, 262874928, 269848288, 276818720, + 283786272, 290750720, 297712032, 304670240, 311625088, 318576672, 325524800, 332469472, 339410592, 346348000, + 353281792, 360211744, 367137888, 374060064, 380978240, 387892320, 394802240, 401708000, 408609408, 415506464, + 422399040, 429287072, 436170560, 443049344, 449923392, 456792640, 463656992, 470516320, 477370656, 484219904, + 491063936, 497902752, 504736192, 511564224, 518386784, 525203776, 532015168, 538820864, 545620800, 552414848, + 559203008, 565985152, 572761280, 579531264, 586295040, 593052544, 599803648, 606548416, 613286592, 620018304, + 626743296, 633461632, 640173120, 646877760, 653575488, 660266176, 666949888, 673626432, 680295744, 686957760, + 693612416, 700259712, 706899392, 713531584, 720156160, 726772928, 733381888, 739983104, 746576384, 753161600, + 759738816, 766307904, 772868736, 779421312, 785965568, 792501376, 799028608, 805547392, 812057536, 818558976, + 825051648, 831535488, 838010496, 844476416, 850933312, 857381184, 863819712, 870249152, 876669120, 883079808, + 889481024, 895872704, 902254784, 908627200, 914989888, 921342848, 927685888, 934018944, 940342016, 946655104, + 952957888, 959250560, 965532992, 971805056, 978066688, 984317888, 990558592, 996788544, 1003007936, 1009216576, + 1015414336, 1021601280, 1027777280, 1033942336, 1040096192, 1046238976, 1052370624, 1058490752, 1064599808, 1070697344, + 1076783488, 1082857984, 1088920960, 1094972288, 1101011840, 1107039616, 1113055616, 1119059712, 1125051776, 1131031680, + 1136999424, 1142955264, 1148898688, 1154829824, 1160748544, 1166654976, 1172548736, 1178430080, 1184298752, 1190154880, + 1195998080, 1201828480, 1207646080, 1213450624, 1219242368, 1225020928, 1230786432, 1236538752, 1242277760, 1248003584, + 1253715840, 1259414784, 1265100160, 1270772224, 1276430464, 1282075136, 1287706112, 1293323136, 1298926336, 1304515840, + 1310091136, 1315652608, 1321199872, 1326733056, 1332251776, 1337756416, 1343246848, 1348722688, 1354184192, 1359631232, + 1365063680, 1370481408, 1375884544, 1381272960, 1386646656, 1392005376, 1397349120, 1402678144, 1407991808, 1413290624, + 1418574336, 1423842816, 1429095936, 1434333952, 1439556480, 1444763520, 1449955200, 1455131264, 1460291840, 1465436672, + 1470566016, 1475679488, 1480777088, 1485858816, 1490924800, 1495974656, 1501008640, 1506026368, 1511028224, 1516013568, + 1520982784, 1525935872, 1530872448, 1535792768, 1540696576, 1545584000, 1550454656, 1555308800, 1560146304, 1564967168, + 1569771136, 1574558336, 1579328768, 1584082048, 1588818560, 1593538048, 1598240512, 1602925696, 1607593856, 1612244736, + 1616878336, 1621494656, 1626093568, 1630675200, 1635239296, 1639785856, 1644314752, 1648826240, 1653319936, 1657795968, + 1662254208, 1666694784, 1671117440, 1675522048, 1679908864, 1684277632, 1688628480, 1692961024, 1697275648, 1701571968, + 1705850112, 1710109952, 1714351616, 1718574848, 1722779648, 1726966016, 1731133824, 1735283072, 1739413760, 1743525888, + 1747619328, 1751694080, 1755750016, 1759787264, 1763805440, 1767804928, 1771785472, 1775746944, 1779689472, 1783612800, + 1787517312, 1791402368, 1795268352, 1799115136, 1802942720, 1806750976, 1810539776, 1814309376, 1818059264, 1821789824, + 1825500928, 1829192448, 1832864384, 1836516608, 1840149248, 1843762176, 1847355392, 1850928768, 1854482432, 1858016000, + 1861529856, 1865023744, 1868497536, 1871951488, 1875385344, 1878799104, 1882192640, 1885566208, 1888919552, 1892252672, + 1895565312, 1898857856, 1902130048, 1905381760, 1908613248, 1911824256, 1915014784, 1918184576, 1921334016, 1924462848, + 1927571072, 1930658688, 1933725568, 1936771840, 1939797248, 1942801920, 1945785856, 1948748928, 1951691136, 1954612480, + 1957512832, 1960392192, 1963250560, 1966087808, 1968904192, 1971699328, 1974473472, 1977226496, 1979958272, 1982668800, + 1985358208, 1988026368, 1990673152, 1993298560, 1995902720, 1998485632, 2001046912, 2003586688, 2006105216, 2008602240, + 2011077632, 2013531648, 2015964032, 2018374912, 2020764032, 2023131520, 2025477504, 2027801728, 2030104064, 2032384768, + 2034643840, 2036880896, 2039096192, 2041289728, 2043461504, 2045611136, 2047739008, 2049844992, 2051928960, 2053991040, + 2056030976, 2058049024, 2060044928, 2062018816, 2063970560, 2065900288, 2067807872, 2069693312, 2071556608, 2073397760, + 2075216640, 2077013248, 2078787712, 2080539776, 2082269696, 2083977344, 2085662592, 2087325440, 2088966016, 2090584192, + 2092179968, 2093753344, 2095304320, 2096832896, 2098338944, 2099822592, 2101283712, 2102722432, 2104138496, 2105532032, + 2106903040, 2108251520, 2109577344, 2110880640, 2112161408, 2113419392, 2114654848, 2115867648, 2117057792, 2118225152, + 2119369984, 2120492032, 2121591424, 2122668032, 2123721984, 2124753152, 2125761536, 2126747136, 2127710080, 2128650112, + 2129567360, 2130461952, 2131333632, 2132182400, 2133008384, 2133811584, 2134591872, 2135349376, 2136083968, 2136795648, + 2137484544, 2138150400, 2138793472, 2139413632, 2140010880, 2140585088, 2141136512, 2141664896, 2142170496, 2142653056, + 2143112704, 2143549312, 2143963008, 2144353792, 2144721664, 2145066496, 2145388288, 2145687168, 2145963136, 2146216064, + 2146445952, 2146652928, 2146836864, 2146997888, 2147135872, 2147250816, 2147342848, 2147411840, 2147457792, 2147480832, + 2147480832, 2147457792, 2147411840, 2147342848, 2147250816, 2147135872, 2146997888, 2146836864, 2146652928, 2146445952, + 2146216064, 2145963136, 2145687168, 2145388288, 2145066496, 2144721664, 2144353792, 2143963008, 2143549312, 2143112704, + 2142653056, 2142170496, 2141664896, 2141136512, 2140585088, 2140010752, 2139413632, 2138793472, 2138150400, 2137484416, + 2136795648, 2136083968, 2135349376, 2134591872, 2133811584, 2133008384, 2132182400, 2131333504, 2130461824, 2129567360, + 2128650112, 2127710080, 2126747136, 2125761536, 2124753152, 2123721984, 2122668032, 2121591424, 2120492032, 2119369984, + 2118225152, 2117057664, 2115867648, 2114654848, 2113419392, 2112161280, 2110880640, 2109577344, 2108251520, 2106903040, + 2105532032, 2104138368, 2102722304, 2101283712, 2099822592, 2098338944, 2096832896, 2095304448, 2093753344, 2092179968, + 2090584192, 2088966016, 2087325440, 2085662464, 2083977216, 2082269696, 2080539776, 2078787584, 2077013248, 2075216512, + 2073397632, 2071556608, 2069693312, 2067807872, 2065900288, 2063970688, 2062018816, 2060044928, 2058048896, 2056030976, + 2053990912, 2051928832, 2049844864, 2047739008, 2045611136, 2043461376, 2041289728, 2039096192, 2036880896, 2034643712, + 2032384768, 2030104064, 2027801472, 2025477376, 2023131520, 2020763904, 2018374784, 2015963904, 2013531648, 2011077760, + 2008602240, 2006105216, 2003586816, 2001046784, 1998485376, 1995902720, 1993298560, 1990673024, 1988026240, 1985358208, + 1982668800, 1979958144, 1977226496, 1974473472, 1971699328, 1968904064, 1966087936, 1963250432, 1960392064, 1957512576, + 1954612352, 1951691008, 1948748800, 1945785728, 1942801792, 1939797248, 1936771712, 1933725568, 1930658560, 1927571200, + 1924462848, 1921334016, 1918184576, 1915014528, 1911824000, 1908612992, 1905381888, 1902130048, 1898857728, 1895565312, + 1892252672, 1888919552, 1885566208, 1882192640, 1878798976, 1875385216, 1871951360, 1868497664, 1865023744, 1861529728, + 1858015872, 1854482176, 1850928512, 1847355392, 1843762176, 1840149248, 1836516480, 1832864128, 1829192448, 1825500928, + 1821789824, 1818059136, 1814309376, 1810539904, 1806750976, 1802942720, 1799115136, 1795268352, 1791402240, 1787517312, + 1783612928, 1779689472, 1775746816, 1771785344, 1767804800, 1763805312, 1759786880, 1755750016, 1751693952, 1747619200, + 1743525760, 1739413632, 1735282816, 1731133440, 1726965888, 1722779392, 1718574592, 1714351360, 1710110080, 1705850112, + 1701571840, 1697275776, 1692961152, 1688628480, 1684277632, 1679908864, 1675521920, 1671117184, 1666694528, 1662254336, + 1657795968, 1653319936, 1648826112, 1644314624, 1639785600, 1635238912, 1630675200, 1626093568, 1621494528, 1616878208, + 1612244480, 1607593472, 1602925312, 1598240000, 1593537920, 1588818432, 1584082176, 1579328640, 1574558336, 1569771008, + 1564966912, 1560146432, 1555308800, 1550454656, 1545583872, 1540696448, 1535792640, 1530872320, 1525935872, 1520982912, + 1516013568, 1511027968, 1506026240, 1501008256, 1495974400, 1490924416, 1485858816, 1480776960, 1475679232, 1470565632, + 1465436416, 1460291456, 1455130880, 1449955456, 1444763648, 1439556480, 1434333952, 1429095936, 1423842688, 1418574080, + 1413290752, 1407991936, 1402678016, 1397349120, 1392005120, 1386646400, 1381272704, 1375884288, 1370481408, 1365063552, + 1359631104, 1354184064, 1348722432, 1343246464, 1337756032, 1332251776, 1326732800, 1321199616, 1315652224, 1310090880, + 1304515328, 1298926336, 1293323392, 1287706240, 1282075264, 1276430592, 1270772224, 1265100160, 1259414656, 1253715584, + 1248003584, 1242277760, 1236538624, 1230786304, 1225020800, 1219242112, 1213450368, 1207646080, 1201828480, 1195997952, + 1190154624, 1184298496, 1178429696, 1172548352, 1166654464, 1160748416, 1154829568, 1148898304, 1142954880, 1136999552, + 1131031552, 1125051520, 1119059840, 1113055744, 1107039744, 1101011840, 1094972160, 1088920832, 1082857728, 1076783616, + 1070697408, 1064599744, 1058490688, 1052370304, 1046238656, 1040095808, 1033941824, 1027777216, 1021601152, 1015414144, + 1009216256, 1003007552, 996788096, 990558016, 984317760, 978066496, 971805184, 965533056, 959250560, 952957824, + 946654848, 940342208, 934019072, 927685888, 921342784, 914989824, 908627008, 902254528, 895872384, 889481088, + 883079808, 876669056, 870248896, 863819456, 857380736, 850932864, 844476352, 838010304, 831535296, 825051392, + 818558592, 812057088, 805546880, 799028032, 792501568, 785965696, 779421376, 772868736, 766307776, 759738624, + 753161344, 746576512, 739983168, 733381888, 726772800, 720155904, 713531264, 706899008, 700259712, 693612352, + 686957632, 680295552, 673626112, 666949504, 660265792, 653574976, 646877632, 640172864, 633461248, 626742912, + 620017792, 613286080, 606548224, 599803904, 593052672, 586295104, 579531264, 572761216, 565985024, 559202752, + 552414976, 545620864, 538820864, 532015072, 525203584, 518386496, 511563840, 504735712, 497902688, 491063808, + 484219680, 477370368, 470515968, 463656512, 456792064, 449923264, 443049120, 436170240, 429286688, 422399040, + 415506368, 408609248, 401708256, 394802432, 387892416, 380978240, 374059968, 367137696, 360211488, 353281440, + 346348096, 339410560, 332469376, 325524608, 318576384, 311624736, 304669760, 297712032, 290750592, 283786048, + 276818464, 269847904, 262874464, 255898208, 248919216, 241938064, 234953808, 227967552, 220978336, 213986752, + 206992896, 199996800, 192999088, 185998800, 178996512, 171992304, 164986256, 157978448, 150968944, 143958336, + 136945664, 129931544, 122916024, 115899184, 108881112, 101861864, 94841528, 87820688, 80798400, 73775248, + 66751300, 59726636, 52701336, 45675472, 38649628, 31623374, 24596266, 17568896, 10541338, 3513666 +}; +#endif + const float Stereo_dmx_wnd_coef_48k[L_FRAME48k] = { 0.00163624552f, 0.00490871910f, 0.00818113983f, 0.0114534730f, 0.0147256833f, 0.0179977361f, 0.0212695971f, 0.0245412290f, 0.0278125983f, 0.0310836714f, 0.0343544111f, 0.0376247801f, 0.0408947468f, 0.0441642813f, 0.0474333353f, 0.0507018827f, 0.0539698936f, 0.0572373196f, 0.0605041310f, 0.0637703016f, diff --git a/lib_enc/ivas_rom_enc.h b/lib_enc/ivas_rom_enc.h index 0a77df02ffb0570dbe77e103fa5722084b399551..34c3e2562e1f7ab1fbdeed83027ab9095fe2223c 100644 --- a/lib_enc/ivas_rom_enc.h +++ b/lib_enc/ivas_rom_enc.h @@ -169,12 +169,16 @@ extern const uint16_t ECSQ_tab_vals[ECSQ_PARAM_COUNT - 1][1 + ECSQ_TAB_VALS_SIZE * Stereo downmix to EVS ROM tables *----------------------------------------------------------------------------------*/ +extern const Word32 Stereo_dmx_s_wnd_coef_16k_fx[L_FRAME16k >> 4]; extern const float Stereo_dmx_s_wnd_coef_16k[L_FRAME16k >> 4]; +extern const Word32 Stereo_dmx_s_wnd_coef_32k_fx[L_FRAME32k >> 4]; extern const float Stereo_dmx_s_wnd_coef_32k[L_FRAME32k >> 4]; +extern const Word32 Stereo_dmx_s_wnd_coef_48k_fx[L_FRAME48k >> 4]; extern const float Stereo_dmx_s_wnd_coef_48k[L_FRAME48k >> 4]; +extern const Word32 Stereo_dmx_wnd_coef_32k_fx[L_FRAME32k]; extern const float Stereo_dmx_wnd_coef_32k[L_FRAME32k]; +extern const Word32 Stereo_dmx_wnd_coef_48k_fx[L_FRAME48k]; extern const float Stereo_dmx_wnd_coef_48k[L_FRAME48k]; - /*----------------------------------------------------------------------------------* * ParamUpmix ROM tables *----------------------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index e27f432be931b17d289e7f15a470936e471a7476..b6e5fbaf6798e7fb550a4341cb0fc6d11dc9a5b9 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -146,62 +146,24 @@ ivas_error ivas_sce_enc( { #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( st->hTranDet->subblockEnergies.firState1_flt, -1 ); - st->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( st->hTranDet->subblockEnergies.firState2_flt, -1 ); - - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - st->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( st->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); - } - - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - st->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( st->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); - st->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( st->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); - } - - - FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - st->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( st->hTranDet->delayBuffer.buffer_flt[i], -1 ); - } - - st->hTranDet->transientDetector.attackRatioThreshold = (Word16) floatToFixed( st->hTranDet->transientDetector.attackRatioThreshold_flt, 11 ); - floatToFixed_arr16( st->input, st->input_fx, -1, input_frame ); - - st->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( st->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); - #endif - RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - st->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.firState1, -1 ); - st->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.firState2, -1 ); - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - st->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( st->hTranDet->subblockEnergies.subblockNrg[i], 7 ); - st->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); - } - - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - st->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( st->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); - } - - FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - st->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) st->hTranDet->delayBuffer.buffer[i], -1 ); - } -#endif + st->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; + st->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; + move16(); + move16(); #else RunTransientDetection( st->input, input_frame, st->hTranDet ); #endif } +#ifdef IVAS_FLOAT_FIXED + Word16 tmp = GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); + currFlatness[0] = me2f_16( tmp, 15 - Q7 ); +#else currFlatness[0] = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS, 0 ); +#endif /*----------------------------------------------------------------* * Configuration of core encoder diff --git a/lib_enc/ivas_sns_enc.c b/lib_enc/ivas_sns_enc.c index 5419544c20573f898df401f6091a84890110fce8..bab1cbde47b10c85bd827c0150f470987adc242a 100644 --- a/lib_enc/ivas_sns_enc.c +++ b/lib_enc/ivas_sns_enc.c @@ -816,7 +816,7 @@ Word16 quantize_sns_fx( Word16 *zero_side_flag, /* Q0 */ Word16 *sns_stereo_mode ) /* Q0 */ { - Word16 nSubframes, k, ch, i; + Word16 nSubframes = 0, k, ch, i; Word16 nbits, idxIndices; Encoder_State *st; @@ -1017,15 +1017,24 @@ Word16 quantize_sns_fx( /* Re-Scaling Buffers*/ *sns_e = sns_e_tmp[0][0]; move16(); + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { *sns_e = s_max( *sns_e, sns_e_tmp[ch][0] ); *sns_e = s_max( *sns_e, sns_e_tmp[ch][1] ); } + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { +#ifdef MSAN_FIX + FOR( k = 0; k < nSubframes; k++ ) + { + scale_sig32( snsQ_out_fx[ch][k], M, sub( sns_e_tmp[ch][k], *sns_e ) ); + } +#else scale_sig32( snsQ_out_fx[ch][0], M, sub( sns_e_tmp[ch][0], *sns_e ) ); scale_sig32( snsQ_out_fx[ch][1], M, sub( sns_e_tmp[ch][1], *sns_e ) ); +#endif } /* get back to L/F representation */ test(); diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 3e9f1e2ed9399a21132d3ce59cb68f6f7ca1192e..d7857435a2946b31be99980e39ddd8f18b2fb5df 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -177,7 +177,7 @@ ivas_error ivas_spar_enc_open( /* AGC handle */ #ifdef IVAS_FLOAT_FIXED - hSpar->AGC_Enable = ivas_agc_enc_get_flag_fx( nchan_transport ); + hSpar->AGC_Enable = ivas_agc_enc_get_flag( nchan_transport ); #else hSpar->AGC_Enable = ivas_agc_enc_get_flag( nchan_transport ); #endif @@ -295,6 +295,7 @@ ivas_error ivas_spar_enc_open_fx( hEncoderConfig = st_ivas->hEncoderConfig; error = IVAS_ERR_OK; + move32(); hSpar = st_ivas->hSpar; IF( !spar_reconfig_flag ) @@ -307,24 +308,30 @@ ivas_error ivas_spar_enc_open_fx( } hSpar->spar_reconfig_flag = 0; + move16(); input_Fs = hEncoderConfig->input_Fs; + move32(); sba_order_internal = extract_l( L_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ) ); nchan_inp = ivas_sba_get_nchan_metadata_fx( sba_order_internal, hEncoderConfig->ivas_total_brate ); assert( nchan_inp <= hEncoderConfig->nchan_inp ); ivas_total_brate = hEncoderConfig->ivas_total_brate; - + move32(); nchan_fb_in = 0; + move16(); IF( EQ_16( st_ivas->sba_analysis_order, 1 ) ) { nchan_fb_in = FOA_CHANNELS; + move16(); } ELSE IF( EQ_16( st_ivas->sba_analysis_order, 2 ) ) { nchan_fb_in = 9; + move16(); } ELSE IF( EQ_16( st_ivas->sba_analysis_order, 3 ) ) { nchan_fb_in = 11; + move16(); } ELSE { @@ -343,6 +350,7 @@ ivas_error ivas_spar_enc_open_fx( /* set FB config. */ active_w_mixing = ivas_spar_br_table_consts[table_idx].active_w; + move16(); IF( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, nchan_inp, nchan_transport, active_w_mixing, input_Fs, nchan_fb_in ) ) != IVAS_ERR_OK ) { return error; @@ -350,24 +358,16 @@ ivas_error ivas_spar_enc_open_fx( fb_cfg->remix_order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; /* FB mixer handle */ - IF( ( error = ivas_FB_mixer_open( &( hSpar->hFbMixer ), input_Fs, fb_cfg, spar_reconfig_flag ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_FB_mixer_open_fx( &( hSpar->hFbMixer ), input_Fs, fb_cfg, spar_reconfig_flag ) ) != IVAS_ERR_OK ) { return error; } /* Covariance handle */ -#ifdef IVAS_FLOAT_FIXED IF( NE_32( ( error = ivas_spar_covar_enc_open_fx( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, COV_SMOOTH_SPAR, hEncoderConfig->ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } -#else - IF( ( error = ivas_spar_covar_enc_open( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, COV_SMOOTH_SPAR, hEncoderConfig->ivas_total_brate ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif - IF( !spar_reconfig_flag ) { /* Transient Detector handle */ @@ -379,14 +379,14 @@ ivas_error ivas_spar_enc_open_fx( /* initialization */ hSpar->hMdEnc->table_idx = -1; - + move16(); /* AGC handle */ hSpar->AGC_Enable = ivas_agc_enc_get_flag( nchan_transport ); - + move16(); hSpar->hAgcEnc = NULL; IF( hSpar->AGC_Enable ) { - IF( ( error = ivas_spar_agc_enc_open( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_agc_enc_open_fx( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) { return error; } @@ -405,16 +405,12 @@ ivas_error ivas_spar_enc_open_fx( /* initialization */ hSpar->hMdEnc->table_idx = -1; - + move16(); /*-----------------------------------------------------------------* * Configuration - set SPAR high-level parameters *-----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED - ivas_spar_config_fx( hEncoderConfig->ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); -#else - ivas_spar_config( hEncoderConfig->ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); -#endif + ivas_spar_config_fx( hEncoderConfig->ivas_total_brate, s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { @@ -424,7 +420,7 @@ ivas_error ivas_spar_enc_open_fx( { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } - + move16(); /*-----------------------------------------------------------------* * Allocate and initialize Front-VAD handle *-----------------------------------------------------------------*/ @@ -432,9 +428,11 @@ ivas_error ivas_spar_enc_open_fx( IF( !spar_reconfig_flag ) { hSpar->front_vad_flag = 0; + move16(); hSpar->front_vad_dtx_flag = 0; + move16(); hSpar->force_front_vad = 0; - + move16(); IF( hEncoderConfig->Opt_DTX_ON ) { IF( ( error = front_vad_create_fx( &( hSpar->hFrontVad ), hEncoderConfig ) ) != IVAS_ERR_OK ) @@ -451,7 +449,8 @@ ivas_error ivas_spar_enc_open_fx( hSpar->hCoreCoderVAD->total_brate = hEncoderConfig->ivas_total_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ hSpar->hCoreCoderVAD->mct_chan_mode = MCT_CHAN_MODE_IGNORE; - + move32(); + move32(); IF( ( error = init_encoder_ivas_fx( hSpar->hCoreCoderVAD, st_ivas, 0, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 1, st_ivas->ism_mode, hSpar->hCoreCoderVAD->total_brate ) ) != IVAS_ERR_OK ) { return error; @@ -645,17 +644,18 @@ static ivas_error ivas_spar_cov_md_process( SPAR_ENC_HANDLE hSpar, const IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, - const int16_t nchan_inp, - const int16_t sba_order, - float *ppIn_FR_real[IVAS_SPAR_MAX_CH], - float *ppIn_FR_imag[IVAS_SPAR_MAX_CH], - const int16_t transient_det[2], - const int16_t dtx_vad, - const int16_t nchan_transport, - int16_t *dyn_active_w_flag ) + const Word16 nchan_inp, + const Word16 sba_order, + Word32 *ppIn_FR_real_fx[IVAS_SPAR_MAX_CH], + Word32 *ppIn_FR_imag_fx[IVAS_SPAR_MAX_CH], + const Word16 transient_det[2], + const Word16 dtx_vad, + const Word16 nchan_transport, + Word16 *dyn_active_w_flag, + Word16 q_ppIn_FR ) { - int16_t i, j, i_ts, b, table_idx; - int16_t active_w_vlbr; + Word16 i, j, i_ts, b, table_idx; + Word16 active_w_vlbr; /* note: the actual dimensions of matrixes correspond to num_channels = ivas_sba_get_nchan_metadata( sba_order, ivas_total_brate ); */ float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; @@ -668,34 +668,42 @@ static ivas_error ivas_spar_cov_md_process( Word16 *q_cov_dtx_real[IVAS_SPAR_MAX_CH]; Word32 cov_real_buf_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; Word32 cov_dtx_real_buf_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - Word32 *ppIn_FR_real_fx[IVAS_SPAR_MAX_CH], *ppIn_FR_imag_fx[IVAS_SPAR_MAX_CH]; - Word16 q_ppIn_FR[IVAS_SPAR_MAX_CH]; - Word16 input_frame; - Word16 nchan_fb_in; #endif ivas_error error; error = IVAS_ERR_OK; + move32(); - active_w_vlbr = ( hEncoderConfig->ivas_total_brate < IVAS_24k4 ) ? 1 : 0; + IF( LT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) ) + { + active_w_vlbr = 1; + move16(); + } + ELSE + { + active_w_vlbr = 0; + move16(); + } /*-----------------------------------------------------------------------------------------* * Set SPAR bitrates *-----------------------------------------------------------------------------------------*/ - table_idx = ivas_get_spar_table_idx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); + table_idx = ivas_get_spar_table_idx_fx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); - if ( hSpar->hMdEnc->table_idx != table_idx ) + IF( NE_16( hSpar->hMdEnc->table_idx, table_idx ) ) { hSpar->hMdEnc->table_idx = table_idx; - if ( hEncoderConfig->ivas_total_brate != hEncoderConfig->last_ivas_total_brate && !hSpar->spar_reconfig_flag ) + move16(); + test(); + IF( NE_32( hEncoderConfig->ivas_total_brate, hEncoderConfig->last_ivas_total_brate ) && !hSpar->spar_reconfig_flag ) { - if ( ( error = ivas_spar_md_enc_init( hSpar->hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_md_enc_init( hSpar->hMdEnc, hEncoderConfig, sba_order ) ), IVAS_ERR_OK ) ) { return error; } } - else + ELSE { ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND, hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, hSpar->AGC_Enable ); } @@ -747,44 +755,10 @@ static ivas_error ivas_spar_cov_md_process( } #endif -#ifdef IVAS_FLOAT_FIXED - input_frame = extract_l( Mpy_32_32( hEncoderConfig->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - nchan_fb_in = hSpar->hFbMixer->fb_cfg->nchan_fb_in; - move16(); - - FOR( i = 0; i < nchan_fb_in; i++ ) - { - IF( ( ppIn_FR_real_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * input_frame ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR encoder Fixed" ); - } - set_zero_fx( ppIn_FR_real_fx[i], input_frame ); - IF( ( ppIn_FR_imag_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * input_frame ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR encoder Fixed" ); - } - set_zero_fx( ppIn_FR_imag_fx[i], input_frame ); - } - set_s( q_ppIn_FR, Q31, nchan_fb_in ); - - FOR( i = 0; i < nchan_fb_in; i++ ) - { - q_ppIn_FR[i] = L_get_q_buf1( ppIn_FR_real[i], input_frame ); - q_ppIn_FR[i] = min( q_ppIn_FR[i], L_get_q_buf1( ppIn_FR_imag[i], input_frame ) ); - floatToFixed_arrL( ppIn_FR_real[i], ppIn_FR_real_fx[i], q_ppIn_FR[i], input_frame ); - floatToFixed_arrL( ppIn_FR_imag[i], ppIn_FR_imag_fx[i], q_ppIn_FR[i], input_frame ); - } -#endif - -#ifdef IVAS_FLOAT_FIXED ivas_enc_cov_handler_process_fx( hSpar->hCovEnc, ppIn_FR_real_fx, ppIn_FR_imag_fx, q_ppIn_FR, cov_real_fx, q_cov_real, cov_dtx_real_fx, q_cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands, nchan_inp, dtx_vad, transient_det, hSpar->hMdEnc->HOA_md_ind, &hSpar->hMdEnc->spar_md.res_ind, remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order], dyn_active_w_flag, nchan_transport, 1 ); -#else - ivas_enc_cov_handler_process( hSpar->hCovEnc, ppIn_FR_real, ppIn_FR_imag, cov_real, cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands, nchan_inp, dtx_vad, transient_det, hSpar->hMdEnc->HOA_md_ind, - &hSpar->hMdEnc->spar_md.res_ind, remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order], dyn_active_w_flag, nchan_transport, 1 ); -#endif -#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS FOR( i = 0; i < nchan_inp; i++ ) { FOR( j = 0; j < nchan_inp; j++ ) @@ -801,29 +775,30 @@ static ivas_error ivas_spar_cov_md_process( free( q_cov_dtx_real[i] ); q_cov_dtx_real[i] = NULL; } - // Note: No need to convert ppIn_FR_real_fx and ppIn_FR_imag_fx back to float as they are not used after ivas_spar_cov_md_process() - - FOR( i = 0; i < nchan_fb_in; i++ ) - { - free( ppIn_FR_real_fx[i] ); - ppIn_FR_real_fx[i] = NULL; - free( ppIn_FR_imag_fx[i] ); - ppIn_FR_imag_fx[i] = NULL; - } #endif - - if ( nchan_transport > 1 && nchan_transport <= ( FOA_CHANNELS - 1 ) ) + test(); + IF( GT_16( nchan_transport, 1 ) && LE_16( nchan_transport, ( FOA_CHANNELS - 1 ) ) ) { push_next_indice( hMetaData, *dyn_active_w_flag, 1 ); - if ( ( *dyn_active_w_flag == 1 ) && ( nchan_transport == 2 ) ) + test(); + IF( EQ_16( *dyn_active_w_flag, 1 ) && EQ_16( nchan_transport, 2 ) ) + { + push_next_indice( hMetaData, sub( hSpar->hMdEnc->spar_md.res_ind, nchan_transport ), 1 ); + } + IF( EQ_16( *dyn_active_w_flag, 1 ) ) { - push_next_indice( hMetaData, hSpar->hMdEnc->spar_md.res_ind - nchan_transport, 1 ); + hSpar->front_vad_flag = 1; + move16(); + } + ELSE + { + hSpar->front_vad_flag = hSpar->front_vad_flag; + move16(); } - hSpar->front_vad_flag = ( *dyn_active_w_flag == 1 ) ? 1 : hSpar->front_vad_flag; } - else + ELSE { - if ( nchan_transport == FOA_CHANNELS ) + IF( EQ_16( nchan_transport, FOA_CHANNELS ) ) { push_next_indice( hMetaData, 0, 1 ); } @@ -833,83 +808,90 @@ static ivas_error ivas_spar_cov_md_process( * MetaData encoder *-----------------------------------------------------------------------------------------*/ - if ( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) + IF( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) { -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ) ) != IVAS_ERR_OK ) -#endif + IF( NE_32( ( error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ) ), IVAS_ERR_OK ) ) { return error; } } - if ( hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag ) + IF( hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag ) { - float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - float diffuseness[IVAS_MAX_NUM_BANDS]; - float Wscale_d[IVAS_MAX_NUM_BANDS]; -#ifdef IVAS_FLOAT_FIXED Word16 order; Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS]; Word32 Wscale_d_fx[IVAS_MAX_NUM_BANDS]; -#endif - int16_t d_start_band, d_end_band; - int16_t dirac_band_idx; + Word16 d_start_band, d_end_band; + Word16 dirac_band_idx; d_start_band = hSpar->enc_param_start_band; + move16(); d_end_band = IVAS_MAX_NUM_BANDS; + move16(); - for ( b = d_start_band; b < d_end_band; b++ ) + FOR( b = d_start_band; b < d_end_band; b++ ) { - dirac_band_idx = hSpar->dirac_to_spar_md_bands[b] - d_start_band; - for ( i_ts = 0; i_ts < hQMetaData->q_direction->cfg.nblocks; i_ts++ ) + dirac_band_idx = sub( hSpar->dirac_to_spar_md_bands[b], d_start_band ); + FOR( i_ts = 0; i_ts < hQMetaData->q_direction->cfg.nblocks; i_ts++ ) { - azi_dirac[b][i_ts] = hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[i_ts]; - ele_dirac[b][i_ts] = hQMetaData->q_direction->band_data[dirac_band_idx].elevation[i_ts]; + azi_dirac_fx[b][i_ts] = hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[i_ts]; + move32(); + ele_dirac_fx[b][i_ts] = hQMetaData->q_direction->band_data[dirac_band_idx].elevation_fx[i_ts]; + move32(); } - diffuseness[b] = 1.0f - hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0]; + diffuseness_fx[b] = L_sub( ONE_IN_Q30, hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0] ); + move32(); } - - if ( d_start_band >= 6 && dtx_vad == 1 ) + test(); + IF( GE_16( d_start_band, 6 ) && EQ_16( dtx_vad, 1 ) ) { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS mvr2r( hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_quant_re, hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_re, IVAS_SPAR_MAX_CH - 1 ); +#endif + Copy32( hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_quant_re_fx, hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_re_fx, IVAS_SPAR_MAX_CH - 1 ); } - for ( b = d_start_band; b < d_end_band; b++ ) + FOR( b = d_start_band; b < d_end_band; b++ ) { - Wscale_d[b] = 1.0f; - for ( i = 1; i < nchan_inp; i++ ) + Word16 tmp_e, Wscale_d_e = 0; + move16(); + Wscale_d_fx[b] = ONE_IN_Q31; + move32(); + FOR( i = 1; i < nchan_inp; i++ ) { - Wscale_d[b] += cov_real[i][i][b] / max( EPSILON, cov_real[0][0][b] ); + Word32 tmp = 0; + move32(); + tmp_e = 0; + move16(); + IF( cov_real_fx[0][0][b] != 0 ) + { + tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( cov_real_fx[i][i][b], cov_real_fx[0][0][b], &tmp_e ) ); + tmp_e = add( tmp_e, sub( sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[i][i][b] ), sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[0][0][b] ) ) ); + } + Wscale_d_fx[b] = BASOP_Util_Add_Mant32Exp( tmp, tmp_e, Wscale_d_fx[b], Wscale_d_e, &Wscale_d_e ); + move32(); } - Wscale_d[b] = Wscale_d[b] / ( 1.0f + (float) sba_order ); /*DirAC normalized signal variance sums to 1 + order*/ - Wscale_d[b] = sqrtf( Wscale_d[b] ); - Wscale_d[b] = min( 2.0f, max( Wscale_d[b], 1.0f ) ); + Wscale_d_fx[b] = L_deposit_h( BASOP_Util_Divide3232_Scale( Wscale_d_fx[b], L_add( 1, sba_order ), &tmp_e ) ); + move32(); + tmp_e = add( tmp_e, sub( Wscale_d_e, Q31 ) ); + Wscale_d_fx[b] = Sqrt32( Wscale_d_fx[b], &tmp_e ); + move32(); + Wscale_d_fx[b] = L_shl_sat( Wscale_d_fx[b], sub( tmp_e, Q2 ) ); // saturating to Q29, as final value is limited to 2 below + move32(); + Wscale_d_fx[b] = L_min( ONE_IN_Q30, L_max( Wscale_d_fx[b], ONE_IN_Q29 ) ); // Q29 + move32(); } #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( b = d_start_band; b < d_end_band; b++ ) - { - for ( i_ts = 0; i_ts < hQMetaData->q_direction->cfg.nblocks; i_ts++ ) - { - azi_dirac_fx[b][i_ts] = float_to_fix( azi_dirac[b][i_ts], Q22 ); - ele_dirac_fx[b][i_ts] = float_to_fix( ele_dirac[b][i_ts], Q22 ); - } - diffuseness_fx[b] = float_to_fix( diffuseness[b], Q30 ); - Wscale_d_fx[b] = float_to_fix( Wscale_d[b], Q29 ); - } 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] = float_to_fix( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[i], Q22 ); - hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i] = float_to_fix( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[i], Q22 ); + 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 ); + 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 ); } hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx = Q22; hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx = Q22; @@ -958,14 +940,14 @@ static ivas_error ivas_spar_cov_md_process( { for ( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) { - hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[i] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], Q22 ); - hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[i] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], Q22 ); + hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[i] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx ); + hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[i] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx ); } for ( i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++ ) { for ( j = 0; j < IVAS_SPAR_MAX_DMX_CHS - 1; j++ ) { - hSpar->hMdEnc->spar_md.band_coeffs[b].C_re[i][j] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].C_re_fx[i][j], Q22 ); + hSpar->hMdEnc->spar_md.band_coeffs[b].C_re[i][j] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].C_re_fx[i][j], hSpar->hMdEnc->spar_md.band_coeffs[b].q_C_re_fx ); } } } @@ -975,13 +957,9 @@ static ivas_error ivas_spar_cov_md_process( #endif } - if ( hSpar->hMdEnc->spar_hoa_md_flag ) + IF( hSpar->hMdEnc->spar_hoa_md_flag ) { -#ifdef IVAS_FLOAT_FIXED error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ); -#else - error = ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ); -#endif } return error; @@ -1154,9 +1132,13 @@ static ivas_error ivas_spar_enc_process( { num_chs_alloc = 1; /* only W channel processed for predicting YZX */ } - FOR( Word16 m = 0; m < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; m++ ) +#ifdef MSAN_FIX + FOR( Word16 m = 0; m < nchan_fb_in; m++ ) +#else + FOR( Word16 m = 0; m <= nchan_fb_in + nchan_transport; m++ ) +#endif { - IF( data_f[m] != NULL && ( m <= nchan_fb_in + nchan_transport ) ) + IF( data_f[m] != NULL ) { q_data_fix[m] = Q_factor_arrL( data_f[m], input_frame ); floatToFixed_arrL( data_f[m], data_fix[m], q_data_fix[m], input_frame ); @@ -1272,6 +1254,12 @@ static ivas_error ivas_spar_enc_process( ppIn_FR_imag[i] = pcm_tmp[i] + input_frame; p_pcm_tmp[i] = pcm_tmp[i]; } + FOR( i = 0; i < nchan_fb_in; i++ ) + { + ppIn_FR_real_fx[i] = pcm_tmp_fx[i]; + ppIn_FR_imag_fx[i] = pcm_tmp_fx[i] + input_frame; + p_pcm_tmp_fx[i] = pcm_tmp_fx[i]; + } dtx_vad = ( hEncoderConfig->Opt_DTX_ON == 1 ) ? front_vad_flag : 1; @@ -1305,8 +1293,23 @@ static ivas_error ivas_spar_enc_process( /*-----------------------------------------------------------------------------------------* * Covariance and MD processing *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( ( error = ivas_spar_cov_md_process( hEncoderConfig, st_ivas->hSpar, st_ivas->hQMetaData, hMetaData, nchan_inp, sba_order, ppIn_FR_real, ppIn_FR_imag, transient_det, dtx_vad, nchan_transport, &dyn_active_w_flag ) ) != IVAS_ERR_OK ) + for ( b = hSpar->enc_param_start_band; b < IVAS_MAX_NUM_BANDS; b++ ) + { + Word16 dirac_band_idx = hSpar->dirac_to_spar_md_bands[b] - hSpar->enc_param_start_band; + hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0] = float_to_fix( hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0], Q30 ); + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( int ch_idx = 0; ch_idx < nchan_fb_in; ch_idx++ ) + { + floatToFixed_arrL32( ppIn_FR_real[ch_idx], ppIn_FR_real_fx[ch_idx], Q14 - gb, input_frame ); + floatToFixed_arrL32( ppIn_FR_imag[ch_idx], ppIn_FR_imag_fx[ch_idx], Q14 - gb, input_frame ); + } +#endif +#endif + + if ( ( error = ivas_spar_cov_md_process( hEncoderConfig, st_ivas->hSpar, st_ivas->hQMetaData, hMetaData, nchan_inp, sba_order, ppIn_FR_real_fx, ppIn_FR_imag_fx, transient_det, dtx_vad, nchan_transport, &dyn_active_w_flag, Q14 - gb ) ) != IVAS_ERR_OK ) { return error; } @@ -1328,9 +1331,73 @@ static ivas_error ivas_spar_enc_process( fprintf( fid, "%.6f\n", hSpar->hMdEnc->mixer_mat[1][0][band] ); } #endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 mixer_q = 31; + Word16 prior_mixer_q = 31; + Word32 num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); + for ( i = 0; i < num_channels; i++ ) + { + for ( j = 0; j < num_channels; j++ ) + { + mixer_q = s_min( mixer_q, Q_factor_arrL( hSpar->hMdEnc->mixer_mat[i][j], IVAS_MAX_NUM_BANDS ) ); + } + } + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + { + prior_mixer_q = s_min( prior_mixer_q, Q_factor_arrL( hSpar->hFbMixer->prior_mixer[i][j], IVAS_MAX_NUM_BANDS ) ); + } + } - ivas_fb_mixer_process( hSpar->hFbMixer, hSpar->hMdEnc->mixer_mat, p_pcm_tmp, input_frame, in_out_mixer_map ); + mixer_q = s_min( mixer_q, prior_mixer_q ); + // both should have a common q as there are values being copied inside function + // or need to do loop for updating values for unused values + for ( i = 0; i < num_channels; i++ ) + { + for ( j = 0; j < num_channels; j++ ) + { + floatToFixed_arrL32( hSpar->hMdEnc->mixer_mat[i][j], hSpar->hMdEnc->mixer_mat_fx[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); + } + } + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + { + floatToFixed_arrL32( hSpar->hFbMixer->prior_mixer[i][j], hSpar->hFbMixer->prior_mixer_fx[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); + } + } + + hSpar->hMdEnc->q_mixer_mat_fx = mixer_q; + hSpar->hFbMixer->q_prior_mixer_fx = mixer_q; + Word16 q_p_pcm_tmp_loc_fx[DIRAC_MAX_ANA_CHANS]; +#endif + + // both mixer_mat_fx and prior mixer_mat_fx should have a common q as there are values being copied inside function + // or need to do loop for updating values for unused values + ivas_fb_mixer_process( hSpar->hFbMixer, hSpar->hMdEnc->mixer_mat_fx, &hSpar->hMdEnc->q_mixer_mat_fx, p_pcm_tmp_fx, q_p_pcm_tmp_loc_fx, input_frame, in_out_mixer_map ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( int ch = ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hSpar->hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + for ( int k = 0; k < input_frame; k++ ) + { + p_pcm_tmp[ch][k] = (float) fixedToFloat( p_pcm_tmp_fx[ch][k], q_p_pcm_tmp_loc_fx[ch] ); + } + } + + // hSpar->hMdEnc->q_mixer_mat_fx = mixer_q; + // hSpar->hFbMixer->q_prior_mixer_fx = mixer_q; + // should be same + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + { + fixedToFloat_arrL32( hSpar->hFbMixer->prior_mixer_fx[i][j], hSpar->hFbMixer->prior_mixer[i][j], hSpar->hFbMixer->q_prior_mixer_fx, IVAS_MAX_NUM_BANDS ); + } + } +#endif if ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ) { @@ -1340,7 +1407,7 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag != dyn_active_w_flag ) { float new_w[L_FRAME48k]; - + Word32 new_w_fx[L_FRAME48k]; /* delayed W */ mvr2r( wyzx_del_buf[0], p_pcm_tmp[0], num_del_samples ); mvr2r( data_f[0], p_pcm_tmp[0] + num_del_samples, input_frame - num_del_samples ); @@ -1350,11 +1417,47 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag == 0 && dyn_active_w_flag == 1 ) { +#ifndef IVAS_FLOAT_FIXED ivas_fb_mixer_cross_fading( hSpar->hFbMixer, p_pcm_tmp, p_pcm_tmp[0], new_w, 0, input_frame, 0 ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arrL32( new_w, new_w_fx, Q11, input_frame ); + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + p_pcm_tmp_fx[i] = &pcm_tmp_fx[i][0]; + floatToFixed_arrL32( p_pcm_tmp[i], p_pcm_tmp_fx[i], Q11, input_frame ); + } +#endif + ivas_fb_mixer_cross_fading_fx( hSpar->hFbMixer, p_pcm_tmp_fx, p_pcm_tmp_fx[0], new_w_fx, 0, input_frame, 0 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + fixedToFloat_arrL32( p_pcm_tmp_fx[i], p_pcm_tmp[i], Q11, input_frame ); + } +#endif +#endif } else if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag == 1 && dyn_active_w_flag == 0 ) { +#ifndef IVAS_FLOAT_FIXED ivas_fb_mixer_cross_fading( hSpar->hFbMixer, p_pcm_tmp, new_w, p_pcm_tmp[0], 0, input_frame, 0 ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arrL32( new_w, new_w_fx, Q11, input_frame ); + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + p_pcm_tmp_fx[i] = &pcm_tmp_fx[i][0]; + floatToFixed_arrL32( p_pcm_tmp[i], p_pcm_tmp_fx[i], Q11, input_frame ); + } +#endif + ivas_fb_mixer_cross_fading_fx( hSpar->hFbMixer, p_pcm_tmp_fx, new_w_fx, p_pcm_tmp_fx[0], 0, input_frame, 0 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + fixedToFloat_arrL32( p_pcm_tmp_fx[i], p_pcm_tmp[i], Q11, input_frame ); + } +#endif +#endif } } else diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 53177f642789a497cd10eba479ad06e8869e77d0..357e52230833e9a99e54e7db3ebcf06ae152526e 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -82,23 +82,43 @@ static void ivas_band_mixer( float *cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], #else static void ivas_band_mixer_fx( Word32 *cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *cov_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const Word16 num_ch, Word16 *num_bands, Word16 red_band_fact ); #endif + +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_get_huffman_coded_bs_fx( ivas_spar_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, const Word16 nB, const Word16 qsi, const Word16 bands_bw ); +#else static int16_t ivas_get_huffman_coded_bs( ivas_spar_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, const int16_t nB, const int16_t qsi, const int16_t bands_bw ); +#endif + +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_get_arith_coded_bs_fx( ivas_spar_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, const Word16 *pDo_diff, const Word16 bands_bw, const Word16 nB, const Word16 qsi, const Word16 strat, const Word32 ivas_total_brate ); +#else static int16_t ivas_get_arith_coded_bs( ivas_spar_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, const int16_t *pDo_diff, const int16_t bands_bw, const int16_t nB, const int16_t qsi, const int16_t strat, const int32_t ivas_total_brate ); +#endif + static void ivas_spar_set_enc_config( ivas_spar_md_enc_state_t *hMdEnc, int16_t *max_freq_per_chan, const int16_t nchan_transport, float *pFC, const int16_t nchan_inp ); #ifdef IVAS_FLOAT_FIXED static void ivas_spar_set_enc_config_fx( ivas_spar_md_enc_state_t *hMdEnc, Word16 *max_freq_per_chan, const Word16 nchan_transport, Word32 *pFC, const Word16 nchan_inp ); #endif // IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED +static void ivas_select_next_strat_fx( ivas_strats_t prior_strat, ivas_strats_t cs[MAX_QUANT_STRATS], const Word16 dmx_switch, const Word16 dtx_vad ); +#else static void ivas_select_next_strat( ivas_strats_t prior_strat, ivas_strats_t cs[MAX_QUANT_STRATS], const int16_t dmx_switch, const int16_t dtx_vad ); +#endif #ifdef IVAS_FLOAT_FIXED static void ivas_store_prior_coeffs_fx( ivas_spar_md_enc_state_t *hMdEnc, const Word16 num_bands, const Word16 strat, const Word16 dtx_vad, const Word16 qsi ); #else static void ivas_store_prior_coeffs( ivas_spar_md_enc_state_t *hMdEnc, const int16_t num_bands, const int16_t strat, const int16_t dtx_vad, const int16_t qsi ); #endif + +#ifdef IVAS_FLOAT_FIXED +static void ivas_write_spar_md_bitstream_fx( ivas_spar_md_enc_state_t *hMdEnc, const Word16 nB, const Word16 bands_bw, BSTR_ENC_HANDLE hMetaData, const Word32 ivas_total_brate, const Word16 strat, const Word16 qsi ); +#else static void ivas_write_spar_md_bitstream( ivas_spar_md_enc_state_t *hMdEnc, const int16_t nB, const int16_t bands_bw, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate, const int16_t strat, const int16_t qsi ); +#endif #ifndef IVAS_FLOAT_FIXED @@ -108,7 +128,7 @@ static void ivas_quant_p_per_band_dtx( float *pP_mat, const int16_t num_dec, con static void ivas_spar_quant_pred_coeffs_dtx_fx( ivas_spar_md_t *pSpar_md, const Word32 *pValues, const Word16 ndm, Word16 *pIndex, const Word16 dim1, Word32 *pQuant ); static void ivas_quant_p_per_band_dtx_fx( Word32 *pP_mat, const Word16 num_dec, const Word16 num_dmx, Word16 *ppIdx_pd, Word32 *pP_out, const Word16 num_ch ); #endif -static void ivas_write_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, BSTR_ENC_HANDLE hMetaData, int16_t *num_dmx, int16_t *num_dec, const int16_t num_bands ); +static void ivas_write_parameter_bitstream_dtx_fx( ivas_spar_md_t *pSpar_md, BSTR_ENC_HANDLE hMetaData, Word16 *num_dmx, Word16 *num_dec, const Word16 num_bands ); #ifndef IVAS_FLOAT_FIXED static void ivas_quant_p_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t num_ch ); @@ -169,20 +189,19 @@ ivas_error ivas_spar_md_enc_open( } } } - - if ( ( hMdEnc->mixer_mat_local = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + IF( ( hMdEnc->mixer_mat_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - if ( ( hMdEnc->mixer_mat_local[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL ) + IF( ( hMdEnc->mixer_mat_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { - if ( ( hMdEnc->mixer_mat_local[i][j] = (float *) malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) + IF( ( hMdEnc->mixer_mat_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } @@ -231,7 +250,7 @@ ivas_error ivas_spar_md_enc_open_fx( ivas_error error; Word16 num_channels, i, j; error = IVAS_ERR_OK; - + move32(); IF( ( hMdEnc = (ivas_spar_md_enc_state_t *) malloc( sizeof( ivas_spar_md_enc_state_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD encoder" ); @@ -239,24 +258,11 @@ ivas_error ivas_spar_md_enc_open_fx( num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); - IF( ( hMdEnc->mixer_mat_local_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); - } - FOR( i = 0; i < num_channels; i++ ) + IF( ( hMdEnc->spar_md.band_coeffs = (ivas_band_coeffs_t *) malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) { - IF( ( hMdEnc->mixer_mat_local_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); - } - FOR( j = 0; j < num_channels; j++ ) - { - IF( ( hMdEnc->mixer_mat_local_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); - } - } + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); } + memset( hMdEnc->spar_md.band_coeffs, 0, IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ); IF( ( hMdEnc->mixer_mat_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { @@ -293,6 +299,60 @@ ivas_error ivas_spar_md_enc_open_fx( * Deallocate SPAR MD encoder handle *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_spar_md_enc_close( + ivas_spar_md_enc_state_t **hMdEnc_in /* i/o: SPAR MD encoder handle */ +) +{ + int16_t num_channels, i, j; + ivas_spar_md_enc_state_t *hMdEnc; + + if ( hMdEnc_in == NULL || *hMdEnc_in == NULL ) + { + return; + } + + hMdEnc = *hMdEnc_in; + num_channels = hMdEnc->num_umx_ch; + + if ( hMdEnc->spar_md.band_coeffs != NULL ) + { + free( hMdEnc->spar_md.band_coeffs ); + hMdEnc->spar_md.band_coeffs = NULL; + } + if ( hMdEnc->mixer_mat != NULL ) + { + for ( i = 0; i < num_channels; i++ ) + { + for ( j = 0; j < num_channels; j++ ) + { + free( hMdEnc->mixer_mat[i][j] ); + } + free( hMdEnc->mixer_mat[i] ); + } + free( hMdEnc->mixer_mat ); + } +#ifdef IVAS_FLOAT_FIXED + IF( hMdEnc->mixer_mat_fx != NULL ) + { + FOR( i = 0; i < num_channels; i++ ) + { + FOR( j = 0; j < num_channels; j++ ) + { + free( hMdEnc->mixer_mat_fx[i][j] ); + } + free( hMdEnc->mixer_mat_fx[i] ); + } + free( hMdEnc->mixer_mat_fx ); + } +#endif + + free( *hMdEnc_in ); + *hMdEnc_in = NULL; + + return; +} +#else void ivas_spar_md_enc_close( ivas_spar_md_enc_state_t **hMdEnc_in /* i/o: SPAR MD encoder handle */ ) @@ -345,6 +405,7 @@ void ivas_spar_md_enc_close( return; } +#endif /*-----------------------------------------------------------------------------------------* @@ -423,6 +484,20 @@ ivas_error ivas_spar_md_enc_init( } } +#ifdef MSAN_FIX + FOR( i = 0; i < num_channels; i++ ) + { + FOR( j = 0; j < num_channels; j++ ) + { + FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) + { + hMdEnc->mixer_mat_fx[i][j][k] = 0; + move32(); + } + } + } +#endif + ivas_clear_band_coeffs( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdEnc->spar_md.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdEnc->spar_md_prior.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); @@ -440,25 +515,38 @@ ivas_error ivas_spar_md_enc_init_fx( Word32 pFC[IVAS_MAX_NUM_BANDS]; Word16 table_idx; Word16 num_channels, i, j, k; - + Word32 PR_minmax_fx[2]; ivas_sba_get_spar_hoa_md_flag_fx( sba_order, hEncoderConfig->ivas_total_brate, &hMdEnc->spar_hoa_md_flag, &hMdEnc->spar_hoa_dirac2spar_md_flag ); num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); ivas_sba_get_spar_hoa_ch_ind_fx( num_channels, hEncoderConfig->ivas_total_brate, hMdEnc->HOA_md_ind ); table_idx = ivas_get_spar_table_idx_fx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); hMdEnc->spar_md.prior_dyn_active_w_flag = 0; + move16(); + Word16 num_bands; + IF( hMdEnc->spar_hoa_md_flag != 0 ) + { + num_bands = IVAS_MAX_NUM_BANDS; + move16(); + } + ELSE + { + num_bands = SPAR_DIRAC_SPLIT_START_BAND; + move16(); + } - ivas_spar_set_bitrate_config_fx( &hMdEnc->spar_md_cfg, table_idx, ( hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND, + ivas_spar_set_bitrate_config_fx( &hMdEnc->spar_md_cfg, table_idx, num_bands, hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, ivas_agc_enc_get_flag( ivas_spar_br_table_consts[table_idx].nchan_transport ) ); // TODO: some log operations pending. - /* get FB coefficients */ FOR( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) { pFC[i] = L_shr( Mpy_32_32( ivas_fb_fcs_12band_1ms_fx[i], hEncoderConfig->input_Fs ), 1 ); // Q0 + move32(); } ivas_spar_set_enc_config_fx( hMdEnc, hMdEnc->spar_md_cfg.max_freq_per_chan, hMdEnc->spar_md_cfg.nchan_transport, pFC, num_channels ); - + test(); + test(); IF( NE_16( hMdEnc->spar_md_cfg.nchan_transport, 2 ) && ( EQ_16( hMdEnc->spar_md_cfg.remix_unmix_order, 1 ) || EQ_16( hMdEnc->spar_md_cfg.remix_unmix_order, 2 ) ) ) { return IVAS_ERR_INTERNAL; @@ -466,18 +554,19 @@ ivas_error ivas_spar_md_enc_init_fx( ivas_spar_arith_coeffs_com_init_fx( &hMdEnc->arith_coeffs, &hMdEnc->spar_md_cfg, table_idx, ENC ); ivas_spar_huff_coeffs_com_init_fx( &hMdEnc->huff_coeffs, NULL, table_idx, ENC ); -#if 0 // Some issues - IF (EQ_16(hEncoderConfig->Opt_DTX_ON, 1)) - { - /* DTX quant init */ - PR_minmax_fx[0] = hMdEnc->spar_md_cfg.quant_strat[0].PR.min_fx; - PR_minmax_fx[1] = hMdEnc->spar_md_cfg.quant_strat[0].PR.max_fx; - ivas_spar_quant_dtx_init_fx(&hMdEnc->spar_md, PR_minmax_fx); - } -#endif + IF( EQ_16( hEncoderConfig->Opt_DTX_ON, 1 ) ) + { + /* DTX quant init */ + PR_minmax_fx[0] = hMdEnc->spar_md_cfg.quant_strat[0].PR.min_fx; + move32(); + PR_minmax_fx[1] = hMdEnc->spar_md_cfg.quant_strat[0].PR.max_fx; + move32(); + ivas_spar_quant_dtx_init_fx( &hMdEnc->spar_md, PR_minmax_fx ); + } hMdEnc->spar_md_cfg.prior_strat = START; + move16(); hMdEnc->spar_md_cfg.prev_quant_idx = -1; - + move16(); FOR( i = 0; i < num_channels; i++ ) { FOR( j = 0; j < num_channels; j++ ) @@ -485,13 +574,13 @@ ivas_error ivas_spar_md_enc_init_fx( FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { hMdEnc->mixer_mat_fx[i][j][k] = 0; + move32(); } } } hMdEnc->q_mixer_mat_fx = 0; -#if 0 // Some issue - ivas_clear_band_coeffs_fx(hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS); -#endif + move16(); + ivas_clear_band_coeffs_fx( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdEnc->spar_md.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdEnc->spar_md_prior.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, IVAS_MAX_NUM_BANDS ); @@ -561,19 +650,30 @@ static void ivas_spar_set_enc_config_fx( { IF( max_freq_per_chan != NULL ) { - hMdEnc->spar_md_cfg.max_freq_per_chan[i] = ( max_freq_per_chan[i] != 0 ) ? max_freq_per_chan[i] : max_freq_per_chan[0]; + IF( max_freq_per_chan[i] != 0 ) + { + hMdEnc->spar_md_cfg.max_freq_per_chan[i] = max_freq_per_chan[i]; + } + ELSE + { + hMdEnc->spar_md_cfg.max_freq_per_chan[i] = max_freq_per_chan[0]; + } + move16(); } ELSE { hMdEnc->spar_md_cfg.max_freq_per_chan[i] = IVAS_SPAR_FOA_DFLT_FREQ_PER_CHAN; + move16(); } } hMdEnc->num_umx_ch = nchan_inp; + move16(); hMdEnc->num_decorr = sub( nchan_inp, 1 ); - + move16(); FOR( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) { tmp_dmx_ch = 0; + move16(); FOR( j = 0; j < nchan_transport; j++ ) { IF( LT_32( pFC[i], hMdEnc->spar_md_cfg.max_freq_per_chan[j] ) ) @@ -583,7 +683,9 @@ static void ivas_spar_set_enc_config_fx( } hMdEnc->spar_md_cfg.num_dmx_chans_per_band[i] = tmp_dmx_ch; + move16(); hMdEnc->spar_md_cfg.num_decorr_per_band[i] = sub( hMdEnc->num_umx_ch, tmp_dmx_ch ); + move16(); } return; @@ -595,23 +697,25 @@ static void ivas_spar_set_enc_config_fx( * Band limit downmix matrix *-----------------------------------------------------------------------------------------*/ -static void ivas_band_limit_dmx_matrix( +static void ivas_band_limit_dmx_matrix_fx( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ - const int16_t num_ch, - const int16_t num_bands, - const int16_t bands_bw ) + const Word16 num_ch, + const Word16 num_bands, + const Word16 bands_bw ) { - int16_t i, j, b, ndm; + Word16 i, j, b, ndm; - for ( b = 0; b < num_bands; b++ ) + FOR( b = 0; b < num_bands; b++ ) { ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; + move16(); - for ( i = ndm; i < num_ch; i++ ) + FOR( i = ndm; i < num_ch; i++ ) { - for ( j = 0; j < num_ch; j++ ) + FOR( j = 0; j < num_ch; j++ ) { - hMdEnc->mixer_mat[i][j][b] = 0; + hMdEnc->mixer_mat_fx[i][j][b] = 0; + move32(); } } } @@ -626,32 +730,34 @@ static void ivas_band_limit_dmx_matrix( * Band mixing downmix matrix *-----------------------------------------------------------------------------------------*/ -static void ivas_band_mixing( +static void ivas_band_mixing_fx( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ - const int16_t num_ch, - const int16_t num_bands, - const int16_t nchan_transport, - const int16_t upmixed_bands ) + const Word16 num_ch, + const Word16 num_bands, + const Word16 nchan_transport, + const Word16 upmixed_bands ) { - int16_t i, j, k, b; - int16_t red_band_fact; + Word16 i, j, k, b; + Word16 red_band_fact; - red_band_fact = upmixed_bands / num_bands; + red_band_fact = idiv1616( upmixed_bands, num_bands ); - for ( i = 0; i < nchan_transport; i++ ) + FOR( i = 0; i < nchan_transport; i++ ) { - for ( j = 0; j < num_ch; j++ ) + FOR( j = 0; j < num_ch; j++ ) { - for ( k = num_bands - 1; k >= 0; k-- ) + FOR( k = num_bands - 1; k >= 0; k-- ) { - for ( b = red_band_fact - 1; b >= 0; b-- ) + FOR( b = red_band_fact - 1; b >= 0; b-- ) { - hMdEnc->mixer_mat[i][j][red_band_fact * k + b] = hMdEnc->mixer_mat[i][j][k]; + hMdEnc->mixer_mat_fx[i][j][red_band_fact * k + b] = hMdEnc->mixer_mat_fx[i][j][k]; + move32(); } } - for ( k = red_band_fact * num_bands; k < upmixed_bands; k++ ) + FOR( k = red_band_fact * num_bands; k < upmixed_bands; k++ ) { - hMdEnc->mixer_mat[i][j][k] = hMdEnc->mixer_mat[i][j][( red_band_fact * num_bands ) - 1]; + hMdEnc->mixer_mat_fx[i][j][k] = hMdEnc->mixer_mat_fx[i][j][( red_band_fact * num_bands ) - 1]; + move32(); } } } @@ -716,10 +822,11 @@ ivas_error ivas_spar_md_enc_process_fx( const Word16 dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ ) { - float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + Word32 pred_coeffs_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + Word16 q_dm_fv_re; Word16 i, j, b, qsi, ndm, ndec, num_ch, num_quant_strats; - float pred_coeffs_re_local[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + Word32 pred_coeffs_re_local_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word16 k, bwidth, num_bands, num_bands_full, num_bands_bw; Word16 active_w, nchan_transport, dmx_switch, strat; Word16 nB, bands_bw, packed_ok = 0; @@ -730,7 +837,12 @@ ivas_error ivas_spar_md_enc_process_fx( Indice *ind_list_tmp; Word16 md_indices_allocated; Word16 max_num_indices_tmp; + Word32 Wscale_fx[IVAS_MAX_NUM_BANDS]; + Word16 q_Wscale[IVAS_MAX_NUM_BANDS]; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS float Wscale[IVAS_MAX_NUM_BANDS]; + float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; +#endif /*extra 16 bits for arithmetic coder as overshoot check is after a symbol is written*/ md_indices_allocated = add( hMdEnc->spar_md_cfg.max_bits_per_blk, IVAS_SPAR_ARITH_OVERSHOOT_BITS ); @@ -845,6 +957,16 @@ ivas_error ivas_spar_md_enc_process_fx( bands_bw = 1; move16(); } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( b = 0; b < num_bands; b++ ) + { + for ( int ii = 0; ii < num_ch - 1; ii++ ) + { + hMdEnc->spar_md.band_coeffs[b].pred_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].pred_re[ii], Q28 ); + hMdEnc->spar_md.band_coeffs[b].P_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].P_re[ii], Q28 ); + } + } +#endif test(); IF( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) { @@ -852,7 +974,8 @@ ivas_error ivas_spar_md_enc_process_fx( { FOR( i = 0; i < DIRAC_TO_SPAR_HBR_PRED_CHS; i++ ) { - pred_coeffs_re_local[i][b] = hMdEnc->spar_md.band_coeffs[b].pred_re[i]; + pred_coeffs_re_local_fx[i][b] = hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i]; + move32(); } } } @@ -870,50 +993,128 @@ ivas_error ivas_spar_md_enc_process_fx( } #endif +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) + { + for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) + { + f2me( cov_real[i][j][k], &cov_real_fx[i][j][k], &cov_real_q[i][j][k] ); + cov_real_q[i][j][k] = 31 - cov_real_q[i][j][k]; + } + } + } + +#endif + ivas_compute_spar_params_enc_fx( cov_real_fx, cov_real_q, dm_fv_re_fx, &q_dm_fv_re, 0, hMdEnc->mixer_mat_fx, &hMdEnc->q_mixer_mat_fx, 0, nB, dtx_vad, num_ch, bands_bw, active_w, active_w_vlbr, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale_fx, q_Wscale, 0, dyn_active_w_flag ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < num_ch - 1; i++ ) + { + for ( j = 0; j < nB; j++ ) + { + dm_fv_re[i][j] = fixedToFloat_32( dm_fv_re_fx[i][j], q_dm_fv_re ); + } + } + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) + { + for ( b = 0; b < nB; b++ ) + { + hMdEnc->mixer_mat[i][j][b] = fixedToFloat_32( hMdEnc->mixer_mat_fx[i][j][b], hMdEnc->q_mixer_mat_fx ); + } + } + } + Word16 q_tmp; + for ( b = 0; b < nB; b++ ) + { + Wscale[b] = fixedToFloat_32( Wscale_fx[b], q_Wscale[b] ); + for ( i = 0; i < num_ch - 1; i++ ) + { + q_tmp = hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx; + hMdEnc->spar_md.band_coeffs[b].pred_re[i] = fixedToFloat_32( hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], q_tmp ); + } + + ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; + if ( ndm != num_ch ) + { + for ( i = 0; i < num_ch - ndm; i++ ) + { + q_tmp = hMdEnc->spar_md.band_coeffs[b].q_P_re_fx; + hMdEnc->spar_md.band_coeffs[b].P_re[i] = fixedToFloat_32( hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], q_tmp ); + } + if ( ndm != 1 ) + { + for ( i = 0; i < num_ch - ndm; i++ ) + { + for ( j = 0; j < ndm - 1; j++ ) + { + q_tmp = hMdEnc->spar_md.band_coeffs[b].q_C_re_fx; + hMdEnc->spar_md.band_coeffs[b].C_re[i][j] = fixedToFloat_32( hMdEnc->spar_md.band_coeffs[b].C_re_fx[i][j], q_tmp ); + } + } + } + } + } +#endif +#else ivas_compute_spar_params( cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, num_ch, bands_bw, active_w, active_w_vlbr, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale, 0, dyn_active_w_flag ); +#endif - if ( dirac_mono_flag ) +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( b = 0; b < num_bands; b++ ) { - int16_t i_ts; - int16_t num_md_sub_frames = 1; + for ( int ii = 0; ii < num_ch - 1; ii++ ) + { + hMdEnc->spar_md.band_coeffs[b].pred_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].pred_re[ii], Q28 ); + hMdEnc->spar_md.band_coeffs[b].P_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].P_re[ii], Q28 ); + } + } +#endif + IF( dirac_mono_flag ) + { + Word16 i_ts; + Word16 num_md_sub_frames = 1; + move16(); ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[0]; + move16(); ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[0]; + move16(); - for ( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) + FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { - for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { - for ( j = 0; j < ndm + ndec - 1; j++ ) + FOR( j = 0; j < ndm + ndec - 1; j++ ) { hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[j] = 0.0f; + hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[j] = 0; + move32(); } - for ( j = 0; j < ndec; j++ ) + FOR( j = 0; j < ndec; j++ ) { - for ( k = 0; k < ndm - 1; k++ ) + FOR( k = 0; k < ndm - 1; k++ ) { hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re[j][k] = 0.0f; + hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[j][k] = 0; + move32(); } } - for ( j = 0; j < ndec; j++ ) + FOR( j = 0; j < ndec; j++ ) { hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re[j] = 0.0f; + hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[j] = 0; + move32(); } } } } - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - for ( b = 0; b < num_bands; b++ ) - { - hMdEnc->mixer_mat_local[i][j][b] = hMdEnc->mixer_mat[i][j][b]; - } - } - } code_strat = 0; move16(); FOR( qsi = 0; qsi < num_quant_strats; qsi++ ) @@ -923,14 +1124,6 @@ ivas_error ivas_spar_md_enc_process_fx( hMdEnc->spar_md_cfg.quant_strat[qsi].P_r.max_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].P_r.max, Q28 ); hMdEnc->spar_md_cfg.quant_strat[qsi].PR.min_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].PR.min, Q28 ); hMdEnc->spar_md_cfg.quant_strat[qsi].PR.max_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].PR.max, Q28 ); - for ( b = 0; b < num_bands; b++ ) - { - for ( int ii = 0; ii < IVAS_SPAR_MAX_CH - 1; ii++ ) - { - hMdEnc->spar_md.band_coeffs[b].pred_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].pred_re[ii], Q28 ); - hMdEnc->spar_md.band_coeffs[b].P_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].P_re[ii], Q28 ); - } - } #endif FOR( b = 0; b < num_bands; b++ ) { @@ -1021,53 +1214,92 @@ ivas_error ivas_spar_md_enc_process_fx( hMdEnc->spar_md.band_coeffs[b].P_quant_re[ii] = fix_to_float( hMdEnc->spar_md.band_coeffs[b].P_quant_re_fx[ii], Q28 ); } } -#endif + Word16 Wscale_e, dm_fv_re_q = Q31, mixer_q = Q31; + f2me_buf( Wscale, Wscale_fx, &Wscale_e, (Word32) num_bands ); for ( i = 0; i < num_ch - 1; i++ ) { - for ( b = 0; b < num_bands; b++ ) + dm_fv_re_q = s_min( dm_fv_re_q, Q_factor_arrL( dm_fv_re[i], num_bands ) ); + } + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) { - pred_coeffs_re[i][b] = Wscale[b] * hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i]; + mixer_q = s_min( mixer_q, Q_factor_arrL( hMdEnc->mixer_mat[i][j], num_bands ) ); + } + } + mixer_q = mixer_q - Wscale_e; // Important + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) + { + floatToFixed_arrL32( hMdEnc->mixer_mat[i][j], hMdEnc->mixer_mat_fx[i][j], mixer_q, num_bands ); + } + } + for ( i = 0; i < num_ch - 1; i++ ) + { + floatToFixed_arrL32( dm_fv_re[i], dm_fv_re_fx[i], dm_fv_re_q, num_bands ); + } +#endif + FOR( i = 0; i < num_ch - 1; i++ ) + { + FOR( b = 0; b < num_bands; b++ ) + { + pred_coeffs_re_fx[i][b] = L_shl( Mpy_32_32( Wscale_fx[b], hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx[i] ), Wscale_e ); + move32(); } } - if ( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) + test(); + IF( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) { - for ( b = SPAR_DIRAC_SPLIT_START_BAND; b < num_bands; b++ ) + FOR( b = SPAR_DIRAC_SPLIT_START_BAND; b < num_bands; b++ ) { - for ( i = 0; i < DIRAC_TO_SPAR_HBR_PRED_CHS; i++ ) + FOR( i = 0; i < DIRAC_TO_SPAR_HBR_PRED_CHS; i++ ) { /* Use the prediction coeffs computed based on DirAC MD to generate mixer matrix */ - pred_coeffs_re[i][b] = pred_coeffs_re_local[i][b]; - hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] = 0; + pred_coeffs_re_fx[i][b] = pred_coeffs_re_local_fx[i][b]; + move32(); + hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx[i] = 0; + hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] = 0.0f; + move32(); hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re[i] = 0; + move16(); } } } - ivas_create_fullr_dmx_mat( pred_coeffs_re, dm_fv_re, hMdEnc->mixer_mat, num_ch, 0, num_bands, active_w, &hMdEnc->spar_md_cfg ); + ivas_create_fullr_dmx_mat_fx( pred_coeffs_re_fx, Q28, dm_fv_re_fx, dm_fv_re_q, hMdEnc->mixer_mat_fx, &mixer_q, num_ch, 0, num_bands, active_w, &hMdEnc->spar_md_cfg ); - for ( b = 0; b < num_bands; b++ ) + FOR( b = 0; b < num_bands; b++ ) { ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; + move16(); ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[b * bands_bw]; + move16(); - for ( i = 0; i < num_ch; i++ ) + FOR( i = 0; i < num_ch; i++ ) { - hMdEnc->mixer_mat[0][i][b] *= Wscale[b]; + hMdEnc->mixer_mat_fx[0][i][b] = L_shl( Mpy_32_32( hMdEnc->mixer_mat_fx[0][i][b], Wscale_fx[b] ), Wscale_e ); + move32(); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + hMdEnc->mixer_mat[0][i][b] = fix_to_float( hMdEnc->mixer_mat_fx[0][i][b], mixer_q ); +#endif } - if ( ( ndm != num_ch ) && ( ndm != 1 ) ) + IF( NE_16( ndm, num_ch ) && NE_16( ndm, 1 ) ) { ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat, num_ch, ndm, b, dtx_vad, 0, dyn_active_w_flag ); - if ( dirac_mono_flag ) + IF( dirac_mono_flag ) { ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[0]; + move16(); ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[0]; - for ( j = 0; j < ndec; j++ ) + move16(); + FOR( j = 0; j < ndec; j++ ) { - for ( k = 0; k < ndm - 1; k++ ) + FOR( k = 0; k < ndm - 1; k++ ) { hMdEnc->spar_md.band_coeffs[b].C_re[j][k] = 0.0f; } @@ -1080,21 +1312,38 @@ ivas_error ivas_spar_md_enc_process_fx( } /* band limit downmix matrix */ - ivas_band_limit_dmx_matrix( hMdEnc, num_ch, num_bands, bands_bw ); + ivas_band_limit_dmx_matrix_fx( hMdEnc, num_ch, num_bands, bands_bw ); /* band mixing */ - if ( bands_bw > 1 ) + IF( GT_16( bands_bw, 1 ) ) { - ivas_band_mixing( hMdEnc, num_ch, num_bands, nchan_transport, num_bands_full ); + ivas_band_mixing_fx( hMdEnc, num_ch, num_bands, nchan_transport, num_bands_full ); + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) + { + fixedToFloat_arrL32( hMdEnc->mixer_mat_fx[i][j], hMdEnc->mixer_mat[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); + } } +#endif - if ( dtx_vad == 0 ) + IF( dtx_vad == 0 ) { - ivas_write_parameter_bitstream_dtx( &hMdEnc->spar_md, hMetaData, hMdEnc->spar_md_cfg.num_dmx_chans_per_band, hMdEnc->spar_md_cfg.num_decorr_per_band, num_bands ); - break; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + hMdEnc->spar_md.min_max_fx[0] = float_to_fix( hMdEnc->spar_md.min_max[0], Q28 ); + hMdEnc->spar_md.min_max_fx[1] = float_to_fix( hMdEnc->spar_md.min_max[1], Q28 ); +#endif + ivas_write_parameter_bitstream_dtx_fx( &hMdEnc->spar_md, hMetaData, hMdEnc->spar_md_cfg.num_dmx_chans_per_band, hMdEnc->spar_md_cfg.num_decorr_per_band, num_bands ); + BREAK; } +#ifdef IVAS_FLOAT_FIXED + ivas_select_next_strat_fx( hMdEnc->spar_md_cfg.prior_strat, cs, dmx_switch, dtx_vad ); +#else ivas_select_next_strat( hMdEnc->spar_md_cfg.prior_strat, cs, dmx_switch, dtx_vad ); +#endif for ( i = 0; i < MAX_CODING_STRATS; i++ ) { @@ -1103,7 +1352,11 @@ ivas_error ivas_spar_md_enc_process_fx( { reset_indices_enc( &hMetaData_tmp, md_indices_allocated ); +#ifdef IVAS_FLOAT_FIXED + ivas_write_spar_md_bitstream_fx( hMdEnc, num_bands, bands_bw, &hMetaData_tmp, hEncoderConfig->ivas_total_brate, strat, qsi ); +#else ivas_write_spar_md_bitstream( hMdEnc, num_bands, bands_bw, &hMetaData_tmp, hEncoderConfig->ivas_total_brate, strat, qsi ); +#endif /*write to main buffer if its a valid bitstream*/ if ( hMetaData_tmp.nb_bits_tot > 0 ) @@ -1685,7 +1938,149 @@ static void ivas_band_mixer( * * Write MD parameters into bitstream *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void ivas_write_spar_md_bitstream_fx( + ivas_spar_md_enc_state_t *hMdEnc, + const Word16 nB, + const Word16 bands_bw, + BSTR_ENC_HANDLE hMetaData, + const Word32 ivas_total_brate, + const Word16 strat, + const Word16 qsi ) +{ + Word16 no_ec, i; + Word16 do_diff[IVAS_MAX_NUM_BANDS]; + Word16 entropy_coding_result; + + IF( EQ_16( strat, NO_STRAT ) ) + { + return; + } + + /* write quant strat */ + IF( GE_32( ivas_total_brate, BRATE_SPAR_Q_STRAT ) ) + { + push_next_indice( hMetaData, shr( qsi, 1 ), sub( hMdEnc->spar_md_cfg.quant_strat_bits, 1 ) ); + } + ELSE + { + push_next_indice( hMetaData, qsi, hMdEnc->spar_md_cfg.quant_strat_bits ); + } + + no_ec = 0; + move16(); + + IF( LT_32( ivas_total_brate, IVAS_24k4 ) ) + { + SWITCH( strat ) + { + case BASE: + push_next_indice( hMetaData, sub( bands_bw, 1 ), SPAR_NUM_CODING_STRAT_BITS ); + BREAK; + case BASE_NOEC: + push_next_indice( hMetaData, add( bands_bw, 1 ), SPAR_NUM_CODING_STRAT_BITS ); + no_ec = 1; + move16(); + BREAK; + case FOUR_A: + case FOUR_C: + case FOUR_B: + case FOUR_D: + push_next_indice( hMetaData, strat, SPAR_NUM_CODING_STRAT_BITS ); + BREAK; + } + /* for LBR SBA 40MS MD never do time diff */ + FOR( i = 0; i < nB; i++ ) + { + do_diff[i] = 0; + move16(); + } + } + ELSE + { + SWITCH( strat ) + { + case BASE: + push_next_indice( hMetaData, sub( bands_bw, 1 ), SPAR_NUM_CODING_STRAT_BITS ); + FOR( i = 0; i < nB; i++ ) + { + do_diff[i] = 0; + move16(); + } + BREAK; + case BASE_NOEC: + push_next_indice( hMetaData, add( bands_bw, 1 ), SPAR_NUM_CODING_STRAT_BITS ); + FOR( i = 0; i < nB; i++ ) + { + do_diff[i] = 0; + move16(); + } + no_ec = 1; + move16(); + BREAK; + case FOUR_A: + push_next_indice( hMetaData, 4, SPAR_NUM_CODING_STRAT_BITS ); + FOR( i = 0; i < nB; i++ ) + { + do_diff[i] = ( ( s_and( ( add( i, 1 ) ), 3 ) ) != 0 ); + move16(); + } + ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); + BREAK; + case FOUR_B: + push_next_indice( hMetaData, 5, SPAR_NUM_CODING_STRAT_BITS ); + FOR( i = 0; i < nB; i++ ) + { + do_diff[i] = (Word16) ( NE_16( ( s_and( ( add( i, 1 ) ), 3 ) ), 1 ) ); + move16(); + } + ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); + BREAK; + case FOUR_C: + push_next_indice( hMetaData, 6, SPAR_NUM_CODING_STRAT_BITS ); + FOR( i = 0; i < nB; i++ ) + { + do_diff[i] = (Word16) ( NE_16( ( s_and( ( add( i, 1 ) ), 3 ) ), 2 ) ); + move16(); + } + ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); + BREAK; + case FOUR_D: + push_next_indice( hMetaData, 7, SPAR_NUM_CODING_STRAT_BITS ); + FOR( i = 0; i < nB; i++ ) + { + do_diff[i] = (Word16) ( NE_16( ( s_and( ( add( i, 1 ) ), 3 ) ), 3 ) ); + move16(); + } + ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); + BREAK; + } + } + + IF( EQ_16( no_ec, 1 ) ) + { + entropy_coding_result = + ivas_get_huffman_coded_bs_fx( hMdEnc, hMetaData, nB, qsi, + bands_bw ); + move16(); + } + ELSE + { + entropy_coding_result = + ivas_get_arith_coded_bs_fx( hMdEnc, hMetaData, do_diff, bands_bw, nB, qsi, + strat, ivas_total_brate ); + move16(); + } + if ( entropy_coding_result < 0 ) + { + hMetaData->nb_bits_tot = 0; + move16(); + } + + return; +} +#else static void ivas_write_spar_md_bitstream( ivas_spar_md_enc_state_t *hMdEnc, const int16_t nB, @@ -1814,6 +2209,7 @@ static void ivas_write_spar_md_bitstream( return; } +#endif /*-----------------------------------------------------------------------------------------* @@ -1821,6 +2217,74 @@ static void ivas_write_spar_md_bitstream( * * Generate huffman coded bitstream *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_get_huffman_coded_bs_fx( + ivas_spar_md_enc_state_t *hMdEnc, + BSTR_ENC_HANDLE hMetaData, + const Word16 nB, + const Word16 qsi, + const Word16 bands_bw ) +{ + Word16 i, j; + Word16 pred_coeff_dim, pred_offset; + + FOR( i = 0; i < nB; i++ ) + { + Word16 code, len; + Word16 ndm, ndec; + ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[i * bands_bw]; + ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[i * bands_bw]; + move16(); + move16(); + + pred_coeff_dim = sub( add( ndm, ndec ), 1 ); + pred_offset = 0; + move16(); + test(); + IF( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) + { + if ( GE_16( i, SPAR_DIRAC_SPLIT_START_BAND ) ) + { + pred_offset = DIRAC_TO_SPAR_HBR_PRED_CHS; + move16(); + } + } + + FOR( j = pred_offset; j < pred_coeff_dim; j++ ) + { + ivas_huffman_encode( &hMdEnc->huff_coeffs.pred_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j], &code, &len ); + IF( GT_16( ( add( hMetaData->nb_bits_tot, len ) ), hMdEnc->spar_md_cfg.max_bits_per_blk ) ) + { + return -1; + } + push_next_indice( hMetaData, code, len ); + } + + Word16 n = imult1616( ndec, sub( ndm, 1 ) ); + FOR( j = 0; j < n; j++ ) + { + ivas_huffman_encode( &hMdEnc->huff_coeffs.drct_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].drct_index_re[j], &code, &len ); + IF( GT_16( ( add( hMetaData->nb_bits_tot, len ) ), hMdEnc->spar_md_cfg.max_bits_per_blk ) ) + { + return -1; + } + push_next_indice( hMetaData, code, len ); + } + + FOR( j = 0; j < ndec; j++ ) + { + ivas_huffman_encode( &hMdEnc->huff_coeffs.decd_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].decd_index_re[j], &code, &len ); + IF( GT_16( ( add( hMetaData->nb_bits_tot, len ) ), hMdEnc->spar_md_cfg.max_bits_per_blk ) ) + { + return -1; + } + push_next_indice( hMetaData, code, len ); + } + } + + return 0; +} +#else static int16_t ivas_get_huffman_coded_bs( ivas_spar_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, @@ -1881,6 +2345,7 @@ static int16_t ivas_get_huffman_coded_bs( return 0; } +#endif /*-----------------------------------------------------------------------------------------* @@ -1888,6 +2353,203 @@ static int16_t ivas_get_huffman_coded_bs( * * Generate arithmetic coded bitstream *-----------------------------------------------------------------------------------------*/ + +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_get_arith_coded_bs_fx( + ivas_spar_md_enc_state_t *hMdEnc, + BSTR_ENC_HANDLE hMetaData, + const Word16 *pDo_diff, + const Word16 bands_bw, + const Word16 nB, + const Word16 qsi, + const Word16 strat, + const Word32 ivas_total_brate ) +{ + Word16 i, any_diff; + Word16 j; + ivas_cell_dim_t pred_cell_dims[IVAS_MAX_NUM_BANDS]; + ivas_cell_dim_t drct_cell_dims[IVAS_MAX_NUM_BANDS]; + ivas_cell_dim_t decd_cell_dims[IVAS_MAX_NUM_BANDS]; + ivas_cell_dim_t decx_cell_dims[IVAS_MAX_NUM_BANDS]; + Word16 symbol_arr_re[IVAS_MAX_INPUT_LEN]; + Word16 symbol_arr_old_re[IVAS_MAX_INPUT_LEN]; + Word16 arith_result; + + FOR( i = 0; i < nB; i++ ) + { + Word16 ndm, ndec; + ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[bands_bw * i]; + ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[bands_bw * i]; + move16(); + move16(); + + test(); + test(); + test(); + test(); + test(); + IF( ( LT_32( ivas_total_brate, IVAS_24k4 ) ) && ( GT_16( strat, 3 ) ) && ( ( ( EQ_16( i % 2, 1 ) ) && ( strat % 2 == 0 ) ) || ( ( i % 2 == 0 ) && ( EQ_16( strat % 2, 1 ) ) ) ) ) + { + pred_cell_dims[i].dim1 = 0; + pred_cell_dims[i].dim2 = 0; + drct_cell_dims[i].dim1 = 0; + drct_cell_dims[i].dim2 = 0; + decd_cell_dims[i].dim1 = 0; + decd_cell_dims[i].dim2 = 0; + decx_cell_dims[i].dim1 = 0; + decx_cell_dims[i].dim2 = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + } + ELSE + { + pred_cell_dims[i].dim1 = sub( add( ndm, ndec ), 1 ); + move16(); + IF( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) + { + IF( GE_16( i, SPAR_DIRAC_SPLIT_START_BAND ) ) + { + pred_cell_dims[i].dim1 = sub( pred_cell_dims[i].dim1, ( FOA_CHANNELS - 1 ) ); + move16(); + } + } + pred_cell_dims[i].dim2 = 1; + drct_cell_dims[i].dim1 = ndec; + drct_cell_dims[i].dim2 = sub( ndm, 1 ); + decd_cell_dims[i].dim1 = ndec; + decd_cell_dims[i].dim2 = 1; + decx_cell_dims[i].dim1 = shr( ( imult1616( ndec, sub( ndec, 1 ) ) ), 1 ); + decx_cell_dims[i].dim2 = 1; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + } + } + + any_diff = 0; + move16(); + FOR( i = 0; i < nB; i++ ) + { + IF( pDo_diff[i] != 0 ) + { + any_diff = 1; + move16(); + BREAK; + } + } + + test(); + IF( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) + { + FOR( i = 0; i < nB; i++ ) + { + IF( GE_16( i, SPAR_DIRAC_SPLIT_START_BAND ) ) + { + FOR( j = 0; j < pred_cell_dims[i].dim1; j++ ) + { + hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j] = + hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j + DIRAC_TO_SPAR_HBR_PRED_CHS]; + move16(); + IF( EQ_16( any_diff, 1 ) ) + { + hMdEnc->spar_md_prior.band_coeffs_idx_mapped[i].pred_index_re[j] = + hMdEnc->spar_md_prior.band_coeffs_idx_mapped[i].pred_index_re[j + DIRAC_TO_SPAR_HBR_PRED_CHS]; + move16(); + } + } + } + } + } + ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md.band_coeffs_idx, nB, symbol_arr_re, pred_cell_dims, PRED_COEFF ); + + IF( EQ_16( any_diff, 1 ) ) + { + ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, nB, symbol_arr_old_re, pred_cell_dims, PRED_COEFF ); + } + + arith_result = ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.pred_arith_re[qsi], &hMdEnc->arith_coeffs.pred_arith_re_diff[qsi], pDo_diff, nB, + symbol_arr_re, symbol_arr_old_re, pred_cell_dims, hMetaData, any_diff, hMdEnc->spar_md_cfg.max_bits_per_blk ); + move16(); + IF( arith_result < 0 ) + { + return -1; + } + + test(); + IF( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) + { + FOR( i = 0; i < nB; i++ ) + { + IF( GE_16( i, SPAR_DIRAC_SPLIT_START_BAND ) ) + { + FOR( j = pred_cell_dims[i].dim1 - 1; j >= 0; j-- ) + { + hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j + DIRAC_TO_SPAR_HBR_PRED_CHS] = + hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j]; + move16(); + } + FOR( j = 0; j < DIRAC_TO_SPAR_HBR_PRED_CHS; j++ ) + { + hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j] = 0; + move16(); + } + } + } + } + + ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md.band_coeffs_idx, nB, symbol_arr_re, drct_cell_dims, DRCT_COEFF ); + + IF( EQ_16( any_diff, 1 ) ) + { + ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, nB, symbol_arr_old_re, drct_cell_dims, DRCT_COEFF ); + } + + + arith_result = ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.drct_arith_re[qsi], &hMdEnc->arith_coeffs.drct_arith_re_diff[qsi], pDo_diff, nB, + symbol_arr_re, symbol_arr_old_re, drct_cell_dims, hMetaData, any_diff, hMdEnc->spar_md_cfg.max_bits_per_blk ); + move16(); + + IF( arith_result < 0 ) + { + return -1; + } + + ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md.band_coeffs_idx, nB, symbol_arr_re, decd_cell_dims, DECD_COEFF ); + + IF( EQ_16( any_diff, 1 ) ) + { + ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, nB, symbol_arr_old_re, decd_cell_dims, DECD_COEFF ); + } + + arith_result = ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.decd_arith_re[qsi], &hMdEnc->arith_coeffs.decd_arith_re_diff[qsi], pDo_diff, nB, + symbol_arr_re, symbol_arr_old_re, decd_cell_dims, hMetaData, any_diff, hMdEnc->spar_md_cfg.max_bits_per_blk ); + move16(); + + IF( arith_result < 0 ) + { + return -1; + } + + ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md.band_coeffs_idx, nB, symbol_arr_re, decx_cell_dims, DECX_COEFF ); + + IF( EQ_16( any_diff, 1 ) ) + { + ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, nB, symbol_arr_old_re, decx_cell_dims, DECX_COEFF ); + } + + return 0; +} +#else static int16_t ivas_get_arith_coded_bs( ivas_spar_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, @@ -2045,6 +2707,7 @@ static int16_t ivas_get_arith_coded_bs( return 0; } +#endif /*-----------------------------------------------------------------------------------------* @@ -2052,7 +2715,63 @@ static int16_t ivas_get_arith_coded_bs( * * Select next strategy *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void ivas_select_next_strat_fx( + ivas_strats_t prior_strat, + ivas_strats_t cs[MAX_QUANT_STRATS], + const Word16 dmx_switch, + const Word16 dtx_vad ) +{ + cs[0] = BASE; + move16(); + cs[1] = BASE_NOEC; + move16(); + test(); + IF( dmx_switch == 0 && dtx_vad ) + { + SWITCH( prior_strat ) + { + case START: + cs[2] = NO_STRAT; + move16(); + BREAK; + case BASE: + cs[2] = FOUR_A; + move16(); + BREAK; + case BASE_DIFF: + cs[2] = FOUR_A; + move16(); + BREAK; + case BASE_NOEC: + cs[2] = FOUR_A; + move16(); + BREAK; + case FOUR_A: + cs[2] = FOUR_B; + move16(); + BREAK; + case FOUR_B: + cs[2] = FOUR_C; + move16(); + BREAK; + case FOUR_C: + cs[2] = FOUR_D; + move16(); + BREAK; + case FOUR_D: + cs[2] = FOUR_A; + move16(); + BREAK; + default: + assert( !"bad value of prior_strat" ); + } + } + + return; +} +#else static void ivas_select_next_strat( ivas_strats_t prior_strat, ivas_strats_t cs[MAX_QUANT_STRATS], @@ -2096,7 +2815,7 @@ static void ivas_select_next_strat( return; } - +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_store_prior_coeffs() @@ -2330,85 +3049,105 @@ static void ivas_quant_p_per_band_dtx_fx( * Write MD DTX parameters into bitstream *-----------------------------------------------------------------------------------------*/ -static void ivas_write_parameter_bitstream_dtx( +static void ivas_write_parameter_bitstream_dtx_fx( ivas_spar_md_t *pSpar_md, BSTR_ENC_HANDLE hMetaData, - int16_t *num_dmx, - int16_t *num_dec, - const int16_t num_bands ) + Word16 *num_dmx, + Word16 *num_dec, + const Word16 num_bands ) { int16_t i, j; - float val; - int16_t idx; - float pr_min_max[2]; - int16_t zero_pad_bits, sid_bits_len; + Word32 val; + Word16 idx; + Word32 pr_min_max[2]; + Word16 zero_pad_bits, sid_bits_len; sid_bits_len = hMetaData->nb_bits_tot; - pr_min_max[0] = pSpar_md->min_max[0]; - pr_min_max[1] = pSpar_md->min_max[1]; + move16(); + pr_min_max[0] = pSpar_md->min_max_fx[0]; + move32(); + pr_min_max[1] = pSpar_md->min_max_fx[1]; + move32(); - for ( i = 0; i < num_bands; i++ ) + FOR( i = 0; i < num_bands; i++ ) { - int16_t ndm = num_dmx[i]; - int16_t ndec = num_dec[i]; + Word16 ndm = num_dmx[i]; + move16(); + Word16 ndec = num_dec[i]; + move16(); - for ( j = 0; j < FOA_CHANNELS - 1; j++ ) + FOR( j = 0; j < FOA_CHANNELS - 1; j++ ) { - int16_t pr, pd; - int16_t pr_q_lvls, pd_q_lvls, pr_pd_bits; - int16_t pr_idx_1, pr_idx_2, pd_idx_1, pd_idx_2; - uint16_t value; + Word16 pr, pd; + Word16 pr_q_lvls, pd_q_lvls, pr_pd_bits; + Word16 pr_idx_1, pr_idx_2, pd_idx_1, pd_idx_2; + UWord16 value; pr_idx_1 = pr_pr_idx_pairs[ndm - 1][j][0]; + move16(); pr_idx_2 = pr_pr_idx_pairs[ndm - 1][j][1]; + move16(); pd_idx_1 = pr_pd_idx_pairs[ndm - 1][j][0]; + move16(); pd_idx_2 = pr_pd_idx_pairs[ndm - 1][j][1]; + move16(); - if ( pr_idx_1 != 0 || pd_idx_1 != 0 || pr_idx_2 != 0 || pd_idx_2 != 0 ) + test(); + test(); + test(); + IF( pr_idx_1 != 0 || pd_idx_1 != 0 || pr_idx_2 != 0 || pd_idx_2 != 0 ) { pr_q_lvls = dtx_pr_real_q_levels[ndm - 1][pd_idx_1 - 1]; + move16(); pr = pSpar_md->band_coeffs_idx[i].pred_index_re[pd_idx_1 - 1]; + move16(); - if ( ( j + 1 ) > ndec ) + IF( GT_16( add( j, 1 ), ndec ) ) { pd_q_lvls = 1; + move16(); pd = 0; + move16(); } - else + ELSE { pd_q_lvls = dtx_pd_real_q_levels[ndm - 1][pd_idx_2 - 1]; + move16(); pd = pSpar_md->band_coeffs_idx[i].decd_index_re[pd_idx_2 - 1]; + move16(); } - val = dtx_pd_real_min_max[0]; - ivas_quantise_real_values( &val, pd_q_lvls, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &idx, &val, 1 ); + val = dtx_pd_real_min_max_fx[0]; + move32(); + ivas_quantise_real_values_enc_fx( &val, pd_q_lvls, dtx_pd_real_min_max_fx[0], dtx_pd_real_min_max_fx[1], &idx, &val, 1 ); - pd -= idx; + pd = sub( pd, idx ); val = pr_min_max[0]; - ivas_quantise_real_values( &val, pr_q_lvls, pr_min_max[0], pr_min_max[1], &idx, &val, 1 ); + move32(); + ivas_quantise_real_values_enc_fx( &val, pr_q_lvls, pr_min_max[0], pr_min_max[1], &idx, &val, 1 ); - pr -= idx; - pr_pd_bits = ivas_get_bits_to_encode( pd_q_lvls * pr_q_lvls ); + pr = sub( pr, idx ); + pr_pd_bits = ivas_get_bits_to_encode( i_mult( pd_q_lvls, pr_q_lvls ) ); - value = (uint16_t) ( pr * pd_q_lvls + pd ); + value = (UWord16) ( add( i_mult( pr, pd_q_lvls ), pd ) ); push_next_indice( hMetaData, value, pr_pd_bits ); } } } - sid_bits_len = hMetaData->nb_bits_tot - sid_bits_len; - zero_pad_bits = ( SPAR_DTX_BANDS * SPAR_SID_BITS_TAR_PER_BAND ) - sid_bits_len; + sid_bits_len = sub( hMetaData->nb_bits_tot, sid_bits_len ); + zero_pad_bits = sub( i_mult( SPAR_DTX_BANDS, SPAR_SID_BITS_TAR_PER_BAND ), sid_bits_len ); assert( zero_pad_bits >= 0 ); - if ( num_dmx[0] == 2 ) + IF( EQ_16( num_dmx[0], 2 ) ) { - zero_pad_bits -= 1; + zero_pad_bits = sub( zero_pad_bits, 1 ); } - while ( zero_pad_bits > 0 ) + WHILE( GT_16( zero_pad_bits, 0 ) ) { - j = min( zero_pad_bits, 16 ); + j = s_min( zero_pad_bits, 16 ); push_next_indice( hMetaData, 0, j ); - zero_pad_bits -= j; + zero_pad_bits = sub( zero_pad_bits, j ); } return; diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 4f3b805cf7e72db6ee0a7152204327f0db21c7a1..8e8dc8f84773a68e712f363205a6c2b1d31841a8 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -47,33 +47,43 @@ typedef struct stereo_itd_data_struct { int16_t prev_itd; +#ifndef IVAS_FLOAT_FIXED float itd[STEREO_DFT_ENC_DFT_NB]; float deltaItd[STEREO_DFT_ENC_DFT_NB]; +#endif int16_t td_itd[STEREO_DFT_ENC_DFT_NB]; int16_t td_itd_32k[STEREO_DFT_ENC_DFT_NB]; int16_t itd_index[STEREO_DFT_ENC_DFT_NB]; +#ifndef IVAS_FLOAT_FIXED float xcorr_smooth[STEREO_DFT_N_32k_ENC]; - float lp_phat_peak; /* low-pass GCC PHAT peak value */ + float lp_phat_peak; /* low-pass GCC PHAT peak value */ +#endif int16_t itd_hangover; /* ITD hangover counter */ int16_t itd_cnt; /* Consecutive valid ITD counter */ +#ifndef IVAS_FLOAT_FIXED float prev_sum_nrg_L_lb; float prev_xcorr_lb[STEREO_DFT_XCORR_LB_MAX]; float E_band_n[STEREO_DFT_ITD_VAD_BAND_NUM]; +#endif int16_t vad_frm_cnt; int16_t pre_vad; int16_t itd_nonzero_cnt; +#ifndef IVAS_FLOAT_FIXED float acorr_L[STEREO_DFT_BAND_MAX]; float acorr_R[STEREO_DFT_BAND_MAX]; float cohSNR; float itd_thres; +#endif int16_t valid_itd_cnt; /* Extra variable to store value of itd_cnt for fine-control decision making */ int16_t detected_itd_flag; int16_t itd_tracking; +#ifndef IVAS_FLOAT_FIXED float prev_max; + float prev_avg_max; +#endif Word32 prev_max_fx; // Q31 int16_t prev_index; - float prev_avg_max; Word32 prev_avg_max_fx; Word16 prev_avg_max_fx_e; #ifndef IVAS_FLOAT_FIXED @@ -82,9 +92,11 @@ typedef struct stereo_itd_data_struct Word16 currFlatness_fx; /* Xtalk classifier */ +#ifndef IVAS_FLOAT_FIXED float prev_m1; - Word32 prev_m1_fx; // Q31 float prev_m2; +#endif + Word32 prev_m1_fx; // Q31 Word32 prev_m2_fx; // Q31 int16_t prev_itd1; int16_t prev_itd2; @@ -122,9 +134,11 @@ typedef struct dft_ana_struct int16_t dft_ovl; /* Overlap size */ int16_t dft_zp; /* Zero padding */ +#ifndef IVAS_FLOAT_FIXED const float *win_ana; /* DFT analysis window */ const float *dft_trigo; const float *dft_trigo_32k; +#endif const Word16 *win_ana_fx; /* DFT analysis window */ const Word16 *dft_trigo_fx; @@ -854,7 +868,7 @@ typedef struct ivas_stereo_classifier_data_structure Word32 xtalk_wscore_fx; // Q31 Word32 xtalk_score_fx; // Q31 Word32 xtalk_score_wrelE_fx; // Q31 - Word32 is_speech_fx; // Q9 + Word32 is_speech_fx; // Q25 } STEREO_CLASSIF_DATA, *STEREO_CLASSIF_HANDLE; @@ -928,8 +942,10 @@ typedef struct ivas_dirac_enc_data_structure float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ float diffuseness_m[DIRAC_MAX_NBANDS]; #ifdef IVAS_FLOAT_FIXED - Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ + Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ + Word16 direction_vector_m_exp[MAX_PARAM_SPATIAL_SUBFRAMES]; // direction_vector_m_fx[i][j][k] will map to direction_vector_m_exp[j] exponent. Word32 diffuseness_m_fx[DIRAC_MAX_NBANDS]; + Word16 diffuseness_m_exp[DIRAC_MAX_NBANDS]; #endif int16_t band_grouping[DIRAC_MAX_NBANDS + 1]; int16_t block_grouping[5]; @@ -938,10 +954,24 @@ typedef struct ivas_dirac_enc_data_structure float sec_I_vec_smth_x[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; float sec_I_vec_smth_y[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; float sec_I_vec_smth_z[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; +#ifdef IVAS_FLOAT_FIXED + Word32 sec_I_vec_smth_x_fx[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + Word16 sec_I_vec_smth_x_exp[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + Word32 sec_I_vec_smth_y_fx[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + Word16 sec_I_vec_smth_y_exp[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + Word32 sec_I_vec_smth_z_fx[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + Word16 sec_I_vec_smth_z_exp[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; +#endif float energy_smth[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; float azi_prev[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; float ele_prev[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; +#ifdef IVAS_FLOAT_FIXED + Word32 energy_smth_fx[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + Word16 energy_smth_exp[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + Word32 azi_prev_fx[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; + Word32 ele_prev_fx[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; +#endif /* diffuseness */ @@ -949,6 +979,12 @@ typedef struct ivas_dirac_enc_data_structure int16_t no_col_avg_diff; float **buffer_intensity_real[DIRAC_NUM_DIMS]; float *buffer_energy; +#ifdef IVAS_FLOAT_FIXED + Word32 **buffer_intensity_real_fx[DIRAC_NUM_DIMS]; + Word16 buffer_intensity_real_q[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF][DIRAC_MAX_NBANDS]; + Word32 *buffer_energy_fx; + Word16 buffer_energy_q[DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS]; +#endif /* Frame count for detecting mono */ int16_t mono_frame_count; @@ -1020,7 +1056,6 @@ typedef struct ivas_spar_md_enc_state_t Word16 num_decorr; float ***mixer_mat; - float ***mixer_mat_local; ivas_spar_md_com_cfg spar_md_cfg; ivas_arith_coeffs_t arith_coeffs; ivas_huff_coeffs_t huff_coeffs; @@ -1030,7 +1065,6 @@ typedef struct ivas_spar_md_enc_state_t Word16 HOA_md_ind[IVAS_SPAR_MAX_CH]; Word32 ***mixer_mat_fx; Word16 q_mixer_mat_fx; - Word32 ***mixer_mat_local_fx; } ivas_spar_md_enc_state_t; /* PCA structure */ @@ -1145,22 +1179,22 @@ typedef struct ivas_mc_paramupmix_enc_data_structure typedef struct ivas_omasa_enc_state_structure { #ifdef IVAS_FLOAT_FIXED - Word16 interpolator_fx[L_FRAME48k]; /*q15*/ - Word16 prev_object_dm_gains_fx[MAX_NUM_OBJECTS][MASA_MAX_TRANSPORT_CHANNELS]; /*q15*/ - Word32 chnlToFoaMtx_fx[DIRAC_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; /*q15*/ - Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ - Word16 **direction_vector_e[DIRAC_NUM_DIMS]; /* Average direction vector */ - Word32 *buffer_intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; - Word32 buffer_energy_fx[DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS]; - Word16 buffer_intensity_real_q[DIRAC_NO_COL_AVG_DIFF]; - Word16 buffer_energy_q[DIRAC_NO_COL_AVG_DIFF]; - Word32 broadband_energy_sm_fx[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; - Word16 broadband_energy_sm_e; - Word32 broadband_energy_prev_fx[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; - Word16 broadband_energy_prev_e; - Word16 fade_out_gain_fx[L_FRAME48k]; /*q15*/ - Word16 fade_in_gain_fx[L_FRAME48k]; /*q15*/ -#endif // IVAS_FLOAT_FIXED + Word16 interpolator_fx[L_FRAME48k]; /*q15*/ + Word16 prev_object_dm_gains_fx[MAX_NUM_OBJECTS][MASA_MAX_TRANSPORT_CHANNELS]; /*q15*/ + Word32 chnlToFoaMtx_fx[DIRAC_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; /*q31*/ + Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector*/ /*q is 31-direction_vector_e*/ + Word16 **direction_vector_e[DIRAC_NUM_DIMS]; /* exp for direction_vector_m_fx */ + Word32 *buffer_intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; /*q is buffer_intensity_real_q*/ + Word32 buffer_energy_fx[DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS]; /*q is buffer_energy_q*/ + Word16 buffer_intensity_real_q[DIRAC_NO_COL_AVG_DIFF]; /*q for buffer_intensity_real_fx*/ + Word16 buffer_energy_q[DIRAC_NO_COL_AVG_DIFF]; /*q for buffer_energy_fx*/ + Word32 broadband_energy_sm_fx[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; /* q is 31-broadband_energy_sm_e*/ + Word16 broadband_energy_sm_e; /*exponent for broadband_energy_sm_fx*/ + Word32 broadband_energy_prev_fx[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; /*q is 31-broadband_energy_prev_e*/ + Word16 broadband_energy_prev_e; /*exponent for broadband_energy_prev_fx*/ + Word16 fade_out_gain_fx[L_FRAME48k]; /*q15*/ + Word16 fade_in_gain_fx[L_FRAME48k]; /*q15*/ +#endif // IVAS_FLOAT_FIXED uint8_t nbands; uint8_t nCodingBands; uint8_t nSubframes; @@ -1170,47 +1204,59 @@ typedef struct ivas_omasa_enc_state_structure HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_OBJECTS]; /* DirAC parameter estimation */ +#ifndef IVAS_FLOAT_FIXED float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ +#endif int16_t band_grouping[MASA_FREQUENCY_BANDS + 1]; int16_t block_grouping[5]; /* diffuseness */ int16_t index_buffer_intensity; +#ifndef IVAS_FLOAT_FIXED float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; float buffer_energy[DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS]; float chnlToFoaMtx[DIRAC_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; float interpolator[L_FRAME48k]; +#endif // !IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED float prev_object_dm_gains[MAX_NUM_OBJECTS][MASA_MAX_TRANSPORT_CHANNELS]; float broadband_energy_sm[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; float broadband_energy_prev[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; +#endif // !IVAS_FLOAT_FIXED int16_t prev_selected_object; uint8_t changing_object; +#ifndef IVAS_FLOAT_FIXED float fade_out_gain[L_FRAME48k]; float fade_in_gain[L_FRAME48k]; +#endif // !IVAS_FLOAT_FIXED } OMASA_ENC_STATE, *OMASA_ENC_HANDLE; typedef struct ivas_omasa_encoder_one_data_struct { +#ifndef IVAS_FLOAT_FIXED float energy_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; -#ifdef IVAS_FLOAT_FIXED +#else Word32 energy_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word16 energy_ism_fx_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word32 energy_ratio_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; /*q30*/ Word32 q_energy_ratio_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; /* Q30 */ Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q30 */ #endif - float lp_noise_CPE; /* LP filtered total noise estimation */ - Word32 lp_noise_CPE_fx; /* LP filtered total noise estimation */ /*Q8*/ +#ifndef IVAS_FLOAT_FIXED + float lp_noise_CPE; /* LP filtered total noise estimation */ +#else + Word16 lp_noise_CPE_fx; /* LP filtered total noise estimation Q8 */ +#endif - int16_t omasa_stereo_sw_cnt; + Word16 omasa_stereo_sw_cnt; } OMASA_ENCODER_DATA_STATE, *OMASA_ENCODER_DATA_HANDLE; @@ -1227,13 +1273,14 @@ typedef struct ivas_masa_dir_align_struct Word32 previous_azi_dir2_fx[MASA_FREQUENCY_BANDS]; /*q22*/ Word32 previous_ele_dir2_fx[MASA_FREQUENCY_BANDS]; /*q22*/ -#endif // IVAS_FLOAT_FIXED +#else float previous_azi_dir1[MASA_FREQUENCY_BANDS]; float previous_ele_dir1[MASA_FREQUENCY_BANDS]; float previous_azi_dir2[MASA_FREQUENCY_BANDS]; float previous_ele_dir2[MASA_FREQUENCY_BANDS]; +#endif } MASA_DIR_ALIGN_STATE, *MASA_DIR_ALIGN_HANDLE; @@ -1249,29 +1296,31 @@ typedef struct ivas_masa_sync_struct typedef struct ivas_masa_encoder_data_struct { +#ifndef IVAS_FLOAT_FIXED float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; -#ifdef IVAS_FLOAT_FIXED +#else Word32 energy_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word16 energy_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word16 q_energy; // Common Q for all energy_fx elements + Word16 q_energy; // Common Q for all energy_fx elements #endif - int16_t num_Cldfb_instances; + Word16 num_Cldfb_instances; HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_ENC_CLDFB_INSTANCES]; - int16_t band_mapping[MASA_FREQUENCY_BANDS + 1]; - uint8_t twoDirBands[MASA_FREQUENCY_BANDS]; - float importanceWeight[MASA_FREQUENCY_BANDS]; + Word16 band_mapping[MASA_FREQUENCY_BANDS + 1]; + UWord8 twoDirBands[MASA_FREQUENCY_BANDS]; SPHERICAL_GRID_DATA Sph_Grid16; - float lfeToTotalEnergyRatio[MAX_PARAM_SPATIAL_SUBFRAMES]; #ifdef IVAS_FLOAT_FIXED - Word32 importanceWeight_fx[MASA_FREQUENCY_BANDS]; + Word32 importanceWeight_fx[MASA_FREQUENCY_BANDS]; /*q30*/ Word32 lfeToTotalEnergyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; Word16 lfeToTotalEnergyRatio_e[MAX_PARAM_SPATIAL_SUBFRAMES]; #endif +#ifndef IVAS_FLOAT_FIXED + float importanceWeight[MASA_FREQUENCY_BANDS]; + float lfeToTotalEnergyRatio[MAX_PARAM_SPATIAL_SUBFRAMES]; float prevq_lfeToTotalEnergyRatio; -#ifdef IVAS_FLOAT_FIXED +#else Word32 prevq_lfeToTotalEnergyRatio_fx; // Q31 #endif - int16_t prevq_lfeIndex; + Word16 prevq_lfeIndex; #ifndef IVAS_FLOAT_FIXED float onset_detector_1; @@ -1559,40 +1608,71 @@ typedef struct mct_enc_data_structure typedef struct stereo_dmx_evs_phase_only_correlation_structure { +#ifndef IVAS_FLOAT_FIXED float P[L_FRAME48k]; float peakQ[CPE_CHANNELS]; float peak_width[CPE_CHANNELS]; float confidence; +#endif + + Word32 P_fx[L_FRAME48k]; // Q31 + Word32 peakQ_fx[CPE_CHANNELS]; // Q16 + Word32 peak_width_fx[CPE_CHANNELS]; // Q16 + Word32 confidence_fx; // Q31 int16_t ispeak[CPE_CHANNELS]; int16_t itdLR[CPE_CHANNELS]; int16_t shift_limit; +#ifndef IVAS_FLOAT_FIXED const float *wnd; float eps; const float *sin; +#endif + + const Word32 *wnd_fx; + Word32 eps_fx; // Q31 + const Word16 *sin_fx; } STEREO_DMX_EVS_POC_DATA, *STEREO_DMX_EVS_POC_HANDLE; typedef struct stereo_dmx_evs_correlation_filter_structure { int16_t init_frmCntr; +#ifndef IVAS_FLOAT_FIXED float isd_rate_s; float iccr_s; float ipd_ff[STEREO_DMX_EVS_NB_SUBBAND_MAX]; float Pr[STEREO_DMX_EVS_NB_SUBBAND_MAX]; float Pi[STEREO_DMX_EVS_NB_SUBBAND_MAX]; float rfft_ipd_coef[L_FRAME48k / 2 + 1]; +#endif + + Word16 isd_rate_s_fx; // Q15 + Word32 iccr_s_fx; // Q31 + Word32 ipd_ff_fx[STEREO_DMX_EVS_NB_SUBBAND_MAX]; // Q31 + Word32 Pr_fx[STEREO_DMX_EVS_NB_SUBBAND_MAX]; // Q31 + Word32 Pi_fx[STEREO_DMX_EVS_NB_SUBBAND_MAX]; // Q31 + Word16 rfft_ipd_coef_fx[L_FRAME48k / 2 + 1]; int16_t pha_len; int16_t fad_len; +#ifndef IVAS_FLOAT_FIXED float win[STEREO_DMX_EVS_PHA_LEN_MAX]; float fad_g[STEREO_DMX_EVS_FAD_LEN_MAX]; float *p_prev_taps[CPE_CHANNELS], prev_taps[CPE_CHANNELS][STEREO_DMX_EVS_PHA_LEN_MAX]; float *p_curr_taps[CPE_CHANNELS], curr_taps[CPE_CHANNELS][STEREO_DMX_EVS_PHA_LEN_MAX]; float data_mem[CPE_CHANNELS][STEREO_DMX_EVS_PHA_LEN_MAX]; +#endif + + Word16 win_fx[STEREO_DMX_EVS_PHA_LEN_MAX]; // Q14 + Word32 fad_g_fx[STEREO_DMX_EVS_FAD_LEN_MAX]; // Q31 + Word32 *p_prev_taps_fx[CPE_CHANNELS], prev_taps_fx[CPE_CHANNELS][STEREO_DMX_EVS_PHA_LEN_MAX]; // Q31 + Word32 *p_curr_taps_fx[CPE_CHANNELS], curr_taps_fx[CPE_CHANNELS][STEREO_DMX_EVS_PHA_LEN_MAX]; // Q31 + + Word32 data_mem_fx[CPE_CHANNELS][STEREO_DMX_EVS_PHA_LEN_MAX]; // Q11 STEREO_DMX_EVS_PHA curr_pha; STEREO_DMX_EVS_PHA prev_pha; @@ -1602,11 +1682,20 @@ typedef struct stereo_dmx_evs_correlation_filter_structure STEREO_DMX_EVS_PRC curr_prc; STEREO_DMX_EVS_PRC prev_prc; int16_t prc_hys_cnt; +#ifndef IVAS_FLOAT_FIXED float fad_g_prc[L_FRAME48k]; +#endif + Word32 fad_g_prc_fx[L_FRAME48k]; // Q31 int16_t fad_len_prc; +#ifndef IVAS_FLOAT_FIXED float trns_aux_energy[CPE_CHANNELS]; float crst_fctr; +#endif + + Word32 trns_aux_energy_fx[CPE_CHANNELS]; + Word16 trns_aux_energy_fx_e[CPE_CHANNELS]; + Word32 crst_fctr_fx; // Q0 } STEREO_DMX_EVS_PHA_DATA, *STEREO_DMX_EVS_PHA_HANDLE; @@ -1615,6 +1704,7 @@ typedef struct stereo_dmx_evs_enc_data_structure STEREO_DMX_EVS_POC_HANDLE hPOC; STEREO_DMX_EVS_PHA_HANDLE hPHA; +#ifndef IVAS_FLOAT_FIXED float itd; float pre_dmx_energy[1]; @@ -1623,6 +1713,18 @@ typedef struct stereo_dmx_evs_enc_data_structure float dmx_weight[1 + CPE_CHANNELS]; const float *s_wnd; +#endif + + Word32 itd_fx; // Q16 + + Word32 pre_dmx_energy_fx[1]; + Word16 pre_dmx_energy_fx_e[1]; + Word32 aux_dmx_energy_fx[CPE_CHANNELS]; + Word16 aux_dmx_energy_fx_e[CPE_CHANNELS]; + + Word32 dmx_weight_fx[1 + CPE_CHANNELS]; // Q31 + + const Word32 *s_wnd_fx; } STEREO_DMX_EVS_ENC_DATA, *STEREO_DMX_EVS_ENC_HANDLE; diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index 1b1d27c34f638a067902e63be97058e4e3c96786..a0872c08e45777919f7479150bce8120b0d37333 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -249,8 +249,9 @@ Word16 select_stereo_mode( move16(); /* reset stereo classifier when switching from MDCT stereo to Unified stereo */ +#ifndef IVAS_FLOAT_FIXED stereo_classifier_init( hCPE->hStereoClassif ); -#ifdef IVAS_FLOAT_FIXED +#else stereo_classifier_init_fx( hCPE->hStereoClassif ); #endif hStereoClassif->lrtd_mode = lrtd_mode; @@ -381,9 +382,6 @@ int16_t select_stereo_mode( /* reset stereo classifier when switching from MDCT stereo to Unified stereo */ stereo_classifier_init( hCPE->hStereoClassif ); -#ifdef IVAS_FLOAT_FIXED - stereo_classifier_init_fx( hCPE->hStereoClassif ); -#endif hStereoClassif->lrtd_mode = lrtd_mode; } @@ -408,6 +406,7 @@ int16_t select_stereo_mode( } #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Function stereo_classifier_init() * @@ -421,7 +420,6 @@ void stereo_classifier_init( /* initialization of features for xtalk classifier and UNCLR classifier */ hStereoClassif->clas_ch1 = 0; set_s( hStereoClassif->pitch_ch1, 0, 3 ); -#ifndef IVAS_FLOAT_FIXED set_f( hStereoClassif->voicing_ch1, 0.0f, 3 ); hStereoClassif->cor_map_sum_ch1 = 0.0f; set_f( hStereoClassif->lsf_ch1, 0.0f, M ); @@ -439,46 +437,38 @@ void stereo_classifier_init( hStereoClassif->prev_g_IPD = 0.5f; hStereoClassif->prev_IPD = 0.0f; hStereoClassif->prev_ratio_m1_m2 = 0.0f; -#endif -#ifndef IVAS_FLOAT_FIXED set_f( hStereoClassif->xtalk_score_buf, 0.0f, XTALK_SCORE_BUF_LEN ); hStereoClassif->ratio_L = 0.5f; -#endif hStereoClassif->vad_flag_glob = 0; hStereoClassif->vad_relE = 0; + hStereoClassif->is_speech = 0.0f; set_s( hStereoClassif->aEn_raw, 0, CPE_CHANNELS ); -#ifndef IVAS_FLOAT_FIXED - hStereoClassif->is_speech = 0.0f; + hStereoClassif->Etot_dn = 0.0f; hStereoClassif->Etot_up = 0.0f; + set_f( hStereoClassif->relE_buf, 0.0f, UNCLR_L_RELE ); set_f( hStereoClassif->Etot_buf, 0.0f, UNCLR_L_ETOT ); -#endif -#ifndef IVAS_FLOAT_FIXED set_f( hStereoClassif->unclr_relE_0_1_LT, 0.0f, UNCLR_RC_ORDER ); -#endif + hStereoClassif->unclr_sw_enable_cnt[0] = 0; hStereoClassif->unclr_sw_enable_cnt[1] = 0; hStereoClassif->unclr_decision = 0; -#ifndef IVAS_FLOAT_FIXED hStereoClassif->unclr_wscore = 0.0f; + set_f( hStereoClassif->unclr_fv, -1.0f, SSC_MAX_NFEA ); -#endif hStereoClassif->unclr_corrLagMax_prev = 0; -#ifndef IVAS_FLOAT_FIXED hStereoClassif->ave_ener_L = 0; hStereoClassif->ave_ener_R = 0; hStereoClassif->relE_0_1 = 0.01f; hStereoClassif->relE_0_1_LT = 0.01f; -#endif -#ifndef IVAS_FLOAT_FIXED + set_f( hStereoClassif->xtalk_fv, -1.0f, SSC_MAX_NFEA ); hStereoClassif->xtalk_wscore = 0.0f; - hStereoClassif->xtalk_score_wrelE = 0.0f; -#endif hStereoClassif->xtalk_decision = 0; + hStereoClassif->xtalk_score_wrelE = 0.0f; hStereoClassif->lrtd_mode = 0; hStereoClassif->prev_lrtd_mode = 0; @@ -487,7 +477,13 @@ void stereo_classifier_init( return; } -#ifdef IVAS_FLOAT_FIXED +#else +/*-------------------------------------------------------------------* + * Function stereo_classifier_init_fx() + * + * Initialize stereo classifier handle + *-------------------------------------------------------------------*/ + void stereo_classifier_init_fx( STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ ) @@ -546,12 +542,12 @@ void stereo_classifier_init_fx( move16(); hStereoClassif->prev_g_IPD_fx = ONE_IN_Q28; // 0.5f in Q29 move32(); - hStereoClassif->prev_IPD_fx = 0; + hStereoClassif->prev_IPD_fx = 0; // Q29 move32(); - hStereoClassif->prev_ratio_m1_m2_fx = 0; + hStereoClassif->prev_ratio_m1_m2_fx = 0; // Q31 move32(); set_zero_fx( hStereoClassif->xtalk_score_buf_fx, XTALK_SCORE_BUF_LEN ); - hStereoClassif->ratio_L_fx = 1073741824; // Q31 + hStereoClassif->ratio_L_fx = ONE_IN_Q30; // 0.5f in Q31 move32(); hStereoClassif->ratio_L_e = 0; // Q31 move16(); @@ -559,7 +555,7 @@ void stereo_classifier_init_fx( move16(); hStereoClassif->vad_relE = 0; move16(); - hStereoClassif->is_speech_fx = 0; // Q31 + hStereoClassif->is_speech_fx = 0; // Q25 move32(); set16_fx( hStereoClassif->aEn_raw, 0, CPE_CHANNELS ); @@ -591,7 +587,7 @@ void stereo_classifier_init_fx( hStereoClassif->unclr_wscore_fx = 0; move32(); - set32_fx( hStereoClassif->unclr_fv_fx, -32768, SSC_MAX_NFEA ); // Q15 + set32_fx( hStereoClassif->unclr_fv_fx, -ONE_IN_Q15, SSC_MAX_NFEA ); // Q15 hStereoClassif->unclr_corrLagMax_prev = 0; move16(); hStereoClassif->ave_ener_L_fx = 0; @@ -607,12 +603,12 @@ void stereo_classifier_init_fx( hStereoClassif->relE_0_1_LT_fx = 21474836; // 0.01f in Q31 move32(); - set32_fx( hStereoClassif->xtalk_fv_fx, -32768, SSC_MAX_NFEA ); // Q15 - hStereoClassif->xtalk_wscore_fx = 0; + set32_fx( hStereoClassif->xtalk_fv_fx, -ONE_IN_Q15, SSC_MAX_NFEA ); // Q15 + hStereoClassif->xtalk_wscore_fx = 0; // Q31 move32(); hStereoClassif->xtalk_decision = 0; move16(); - hStereoClassif->xtalk_score_wrelE_fx = 0; + hStereoClassif->xtalk_score_wrelE_fx = 0; // Q31 move32(); hStereoClassif->lrtd_mode = 0; @@ -626,6 +622,8 @@ void stereo_classifier_init_fx( return; } #endif + + /*-----------------------------------------------------------------* * stereo_classifier_features() * diff --git a/lib_enc/ivas_stereo_cng_enc.c b/lib_enc/ivas_stereo_cng_enc.c index 91799b60aca99cae00dbfa099f9593cd768314ec..a9dc30e44ba35a3a5cedb55ed6a0d4f0a718dcc7 100644 --- a/lib_enc/ivas_stereo_cng_enc.c +++ b/lib_enc/ivas_stereo_cng_enc.c @@ -325,12 +325,11 @@ void stereo_dft_enc_sid_coh_fx( Word16 zeropad; Word16 nr_of_sid_stereo_bits; Word16 coh_pred_index; - Word16 min_pred_err; - Word16 min_pred_err_e; + Word64 min_pred_err; Word16 pred_err; // Q13 Word16 res_index; Word16 i; - Word16 tmp; + Word32 tmp; const Word16 *pptr; Word16 pred; // Q13 Word16 cohBandq[STEREO_DFT_BAND_MAX / 2]; /* Reconstructed coherence values for intra-frame prediction Q15 */ @@ -355,37 +354,33 @@ void stereo_dft_enc_sid_coh_fx( IF( sub( sub( nr_of_sid_stereo_bits, *nb_bits ), STEREO_DFT_N_COH_ALPHA_BITS + STEREO_DFT_PRED_NBITS ) > 0 ) { - min_pred_err = 31250; - move32(); - min_pred_err_e = 20; - move16(); + min_pred_err = 134217728000000; // 1e6 in Q27 + move64(); coh_pred_index = -1; move16(); pptr = dft_cng_coh_pred_fx[0]; // Q13 FOR( k = 0; k < STEREO_DFT_N_COH_PRED; k++ ) { - pred_err = 0; - move16(); + Word64 pred_err64 = 0; + move64(); FOR( b = 1; b < nbands; b++ ) /* Set b=1 to skip first coefficient (same error would otherwise be added for all predictors: (cohBand[0] - 0).^2) */ { - pred = 0; - move16(); + Word64 pred64 = 0; + move64(); FOR( i = 0; i < b; i++ ) { // pred += ( *pptr++ ) * cohBand[i]; - pred = add( pred, mult_r( extract_h( cohBand[i] ), ( *pptr++ ) ) ); // Q13 + pred64 = W_mac_32_16( pred64, cohBand[i], *pptr++ ); // Q45 (31+13+1) } - tmp = sub( shr_r( extract_h( cohBand[b] ), 2 ), pred ); // Q13 + tmp = L_sub( L_shr( cohBand[b], 18 ), W_extract_h( pred64 ) ); // Q13 // pred_err += tmp * tmp; - pred_err = add( pred_err, shl( mult_r( tmp, tmp ), 2 ) ); // Q13 + pred_err64 = W_mac_32_32( pred_err64, tmp, tmp ); // Q27 } // if ( pred_err < min_pred_err ) /* Store best candidate */ - IF( BASOP_Util_Cmp_Mant32Exp( pred_err, 16, min_pred_err, add( min_pred_err_e, 16 ) ) < 0 ) /* Store best candidate */ + IF( LT_64( pred_err64, min_pred_err ) ) /* Store best candidate */ { - min_pred_err = pred_err; - move32(); - min_pred_err_e = 0; - move16(); + min_pred_err = pred_err64; // Q27 + move64(); coh_pred_index = k; move16(); } diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index 95be17fb57f2f1d791eb78937f6ab7824a6b0064..f4afc47ab1b9145e03dbbcb33ae6d06b4bd0855a 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -1074,8 +1074,10 @@ void stereo_dft_enc_reset( hStereoDft->coh_fade_counter = 0; /* Xtalk classifier */ +#ifndef IVAS_FLOAT_FIXED hStereoDft->hItd->prev_m1 = 0; hStereoDft->hItd->prev_m2 = 0; +#endif hStereoDft->hItd->prev_itd1 = 0; hStereoDft->hItd->prev_itd2 = 0; @@ -1270,38 +1272,46 @@ void stereo_enc_itd_init( ) { hItd->prev_itd = 0; +#ifndef IVAS_FLOAT_FIXED set_zero( hItd->itd, STEREO_DFT_ENC_DFT_NB ); set_zero( hItd->deltaItd, STEREO_DFT_ENC_DFT_NB ); +#endif set_s( hItd->td_itd, 0, STEREO_DFT_ENC_DFT_NB ); set_s( hItd->td_itd_32k, 0, STEREO_DFT_ENC_DFT_NB ); set_s( hItd->itd_index, 0, STEREO_DFT_ENC_DFT_NB ); +#ifndef IVAS_FLOAT_FIXED set_zero( hItd->xcorr_smooth, STEREO_DFT_N_32k_ENC ); hItd->lp_phat_peak = 0.f; +#endif hItd->itd_hangover = 0; hItd->itd_cnt = 0; +#ifndef IVAS_FLOAT_FIXED hItd->prev_sum_nrg_L_lb = 0.f; set_zero( hItd->prev_xcorr_lb, STEREO_DFT_XCORR_LB_MAX ); set_f( hItd->E_band_n, (float) ITD_VAD_E_BAND_N_INIT, STEREO_DFT_ITD_VAD_BAND_NUM ); +#endif hItd->vad_frm_cnt = 0; hItd->pre_vad = 0; hItd->itd_nonzero_cnt = 0; +#ifndef IVAS_FLOAT_FIXED set_zero( hItd->acorr_L, STEREO_DFT_BAND_MAX ); set_zero( hItd->acorr_R, STEREO_DFT_BAND_MAX ); hItd->cohSNR = 15.f; hItd->itd_thres = 0.f; +#endif hItd->valid_itd_cnt = 0; hItd->detected_itd_flag = 0; hItd->itd_tracking = 0; - hItd->prev_max = 0.f; hItd->prev_index = 0; - hItd->prev_avg_max = 0.f; #ifndef IVAS_FLOAT_FIXED + hItd->prev_max = 0.f; + hItd->prev_avg_max = 0.f; hItd->currFlatness = 0.f; -#endif /* Xtalk classifier */ hItd->prev_m1 = 0; hItd->prev_m2 = 0; +#endif hItd->prev_itd1 = 0; hItd->prev_itd2 = 0; diff --git a/lib_enc/ivas_stereo_dft_td_itd.c b/lib_enc/ivas_stereo_dft_td_itd.c index 5c7b73a015153d7b22a90266cf773e68a218eb04..a61ee2250a45c69da0b95122a669b6f5637a5005 100644 --- a/lib_enc/ivas_stereo_dft_td_itd.c +++ b/lib_enc/ivas_stereo_dft_td_itd.c @@ -89,6 +89,7 @@ const Word16 wac_swb_l_fx[LPC_SHB_ORDER + 1] = { * * ---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void stereo_td_get_td_itd( int16_t *td_itd, /* o : td_itd in samples at sampling frequency */ int16_t *td_itd_32, /* o : td_itd in samples at 32kHz */ @@ -114,8 +115,7 @@ static void stereo_td_get_td_itd( return; } - -#ifdef IVAS_FLOAT_FIXED +#else static void stereo_td_get_td_itd_fx( Word16 *td_itd, /* o : td_itd in samples at sampling frequency */ Word16 *td_itd_32, /* o : td_itd in samples at 32kHz */ @@ -160,6 +160,7 @@ static void stereo_td_get_td_itd_fx( * * ---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void stereo_td_channel_extrapolate( Encoder_State **sts, const int16_t dft_ovl, @@ -287,8 +288,7 @@ static void stereo_td_channel_extrapolate( return; } - -#ifdef IVAS_FLOAT_FIXED +#else static void stereo_td_channel_extrapolate_fx( Encoder_State **sts, const Word16 dft_ovl, @@ -477,6 +477,7 @@ static void stereo_td_channel_extrapolate_fx( * * ---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void stereo_td_itd( ITD_DATA *hITD, /* i/o: ITD data structure */ float input_mem_itd[CPE_CHANNELS][STEREO_DFT_OVL_MAX], /* o : ITD memory (only used in DFT Stereo) */ @@ -600,8 +601,7 @@ void stereo_td_itd( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void stereo_td_itd_fx( ITD_DATA *hITD, /* i/o: ITD data structure */ Word16 input_mem_itd[CPE_CHANNELS][STEREO_DFT_OVL_MAX], /* o : ITD memory (only used in DFT Stereo) */ diff --git a/lib_enc/ivas_stereo_dmx_evs.c b/lib_enc/ivas_stereo_dmx_evs.c index 4e21a5c5f4e1d73c9e975df9fb0d1d14ac51a403..11a6fd49cbd95f7dd9c75049f2d359a9314f5094 100644 --- a/lib_enc/ivas_stereo_dmx_evs.c +++ b/lib_enc/ivas_stereo_dmx_evs.c @@ -37,10 +37,15 @@ #include "ivas_cnst.h" #include "rom_com.h" #include "prot.h" +#include "prot_fx.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" #include "ivas_rom_com.h" +#include "ivas_rom_com_fx.h" #include "ivas_rom_enc.h" #include "wmc_auto.h" +#include "ivas_prot_fx.h" +#include "prot_fx.h" /*-----------------------------------------------------------------------* @@ -50,35 +55,55 @@ #define STEREO_DMX_EVS_FIND_POC_PEAK_TAU 4 #define STEREO_DMX_EVS_FIND_POC_PEAK_TAU2 8 -#define STEREO_DMX_EVS_POC_GAMMA 0.75f -#define STEREO_DMX_EVS_POC_SMOOTH 1.25f -#define STEREO_DMX_EVS_POC_FORGETTING 0.78f -#define STEREO_DMX_EVS_TARGET_POC_FORGETTING 0.79f -#define STEREO_DMX_EVS_POC_W_FORGETTING 0.875f -#define STEREO_DMX_EVS_SHIFT_LIMIT 5.625f /* ms */ - -#define STEREO_DMX_EVS_DMX_EGY_FORGETTING 0.25f -#define STEREO_DMX_EVS_CORR_FORGETTING 0.78f - -#define Q_BAND 0.25f - - -#define STEREO_DMX_EVS_ISD_FORGETTING 0.95f -#define STEREO_DMX_EVS_ISD_THRES_H 1.69f -#define STEREO_DMX_EVS_ISD_THRES_L 0.9f -#define STEREO_DMX_EVS_ISD_DIST_THRES_IPD 0.5f - -#define STEREO_DMX_EVS_ISD_DIST_HYST_L 0.36f -#define STEREO_DMX_EVS_ISD_DIST_HYST_H 0.43f - -#define STEREO_DMX_EVS_ICCR_FORGETTING 0.7f -#define STEREO_DMX_EVS_ICCR_HYST_L 0.75f -#define STEREO_DMX_EVS_ICCR_HYST_H 0.85f +#define STEREO_DMX_EVS_POC_GAMMA 0.75f +#define STEREO_DMX_EVS_POC_SMOOTH 1.25f +#define STEREO_DMX_EVS_POC_SMOOTH_Q30 1342177280 +#define STEREO_DMX_EVS_POC_FORGETTING 0.78f +#define STEREO_DMX_EVS_POC_FORGETTING_Q31 1675037245 +#define STEREO_DMX_EVS_TARGET_POC_FORGETTING 0.79f +#define STEREO_DMX_EVS_TARGET_POC_FORGETTING_Q31 1696512082 +#define STEREO_DMX_EVS_POC_W_FORGETTING 0.875f +#define STEREO_DMX_EVS_SHIFT_LIMIT 5.625f /* ms */ +#define STEREO_DMX_EVS_SHIFT_LIMIT_Q12 23040 /* ms */ + + +#define STEREO_DMX_EVS_DMX_EGY_FORGETTING 0.25f +#define STEREO_DMX_EVS_DMX_EGY_FORGETTING_FX 536870912 // 0.25f in Q31 + +#define STEREO_DMX_EVS_CORR_FORGETTING 0.78f +#define STEREO_DMX_EVS_CORR_FORGETTING_FX 1610612736 /*Q31*/ +#define STEREO_DMX_EVS_POC_W_FORGETTING_FX 1879048192 /*Q31*/ + +#define Q_BAND 0.25f +#define Q_BAND_FX 536870912 /*Q31*/ + +#define STEREO_DMX_EVS_ISD_FORGETTING 0.95f +#define STEREO_DMX_EVS_ISD_FORGETTING_Q15 31129 +#define STEREO_DMX_EVS_ISD_THRES_H 1.69f +#define STEREO_DMX_EVS_ISD_THRES_L 0.9f +#define STEREO_DMX_EVS_ISD_THRES_L_Q31 1932735283 +#define STEREO_DMX_EVS_ISD_DIST_THRES_IPD 0.5f +#define STEREO_DMX_EVS_ISD_DIST_THRES_IPD_Q15 ONE_IN_Q14 + +#define STEREO_DMX_EVS_ISD_DIST_HYST_L 0.36f +#define STEREO_DMX_EVS_ISD_DIST_HYST_L_Q15 11796 +#define STEREO_DMX_EVS_ISD_DIST_HYST_H 0.43f +#define STEREO_DMX_EVS_ISD_DIST_HYST_H_Q15 14090 + +#define STEREO_DMX_EVS_ICCR_FORGETTING 0.7f +#define STEREO_DMX_EVS_ICCR_FORGETTING_Q31 1503238554 +#define STEREO_DMX_EVS_ICCR_HYST_L 0.75f +#define STEREO_DMX_EVS_ICCR_HYST_L_Q31 1610612736 +#define STEREO_DMX_EVS_ICCR_HYST_H 0.85f +#define STEREO_DMX_EVS_ICCR_HYST_H_Q31 1825361101 #define STEREO_DMX_EVS_SWTCH_HYS_THRES 1 #define STEREO_DMX_EVS_LR_EGY 15.0f +#define STEREO_DMX_EVS_LR_EGY_Q27 2013265920 #define STEREO_DMX_EVS_ILDS_EGY 10000.0f +#define STEREO_DMX_EVS_ILDS_EGY_Q17 1310720000 #define STEREO_DMX_EVS_ILD_PRC 0.1f +#define STEREO_DMX_EVS_ILD_PRC_Q15 3277 #define STEREO_DMX_EVS_SWTCH_PRC_THRES_16 55 #define STEREO_DMX_EVS_SWTCH_PRC_THRES_32 19 @@ -93,29 +118,196 @@ #define STEREO_DMX_EVS_CRST_FCTR_32 40.0f #define STEREO_DMX_EVS_CRST_FCTR_48 35.0f -#define STEREO_DMX_EVS_TRNS_EGY_FORGETTING 0.75f - - +#define STEREO_DMX_EVS_TRNS_EGY_FORGETTING 0.75f +#define STEREO_DMX_EVS_TRNS_EGY_FORGETTING_Q15 24576 + +const Word32 ipd_ff_Q31[STEREO_DMX_EVS_NB_SUBBAND_MAX] = { + 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, + 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, + 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, + 2027355264, 2023718656, 2020082048, 2016445440, 2012808832, 2009172224, 2005535616, 2001899008, 1998262400, 1994625664, + 1990989056, 1987352448, 1983715840, 1980079232, 1976442624, 1972806016, 1969169408, 1965532800, 1961896192, 1958259584, + 1954622976, 1950986368, 1947349760, 1943713152, 1940076544, 1936439936, 1932803328, 1929166592, 1925529984, 1921893376, + 1918256768, 1914620160, 1910983552, 1907346944, 1903710336, 1900073728, 1896437120, 1892800512, 1889163904, 1885527296, + 1881890688, 1878254080, 1874617344, 1870980864, 1867344128, 1863707520, 1860070912, 1856434304, 1852797696, 1849161088, + 1845524480, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, + 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, + 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, + 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, + 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, + 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, + 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, + 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, + 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, + 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, + 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, + 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, + 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, + 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, + 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, + 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872, 1841887872 +}; /*-----------------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void estimate_itd_wnd_fft_fx( + const Word32 *input, /* i : input signal Q16 */ + Word32 *specr, /* o : real-part spectra Q(31-spec_e) */ + Word32 *speci, /* o : imaginary-part spectra Q(31-spec_e) */ + Word16 *spec_e, + const Word16 *rfft_coef, /* i : rfft coef Q15 */ + const Word32 *wnd, /* i : window coef Q31 */ + const Word16 input_frame /* i : input frame length per channel */ +); +static void calc_poc_fx( + STEREO_DMX_EVS_POC_HANDLE hPOC, /* i/o: phase only correlation structure */ + STEREO_DMX_EVS_PHA_HANDLE hPHA, /* i/o: correlation filter structure */ + const Word32 wnd[], /* i : window coef Q31 */ + const Word16 rfft_coef[], /* i : RFFT coef Q15 */ + const Word32 specLr[], /* i : Lch real-part spectra Q(31-spec_e) */ + const Word32 specLi[], /* i : Lch imaginary-part input signal Q(31-spec_e) */ + const Word32 specRr[], /* i : Rch real-part spectra Q(31-spec_e) */ + const Word32 specRi[], /* i : Rch imaginary-part input signal Q(31-spec_e) */ + const Word16 spec_e, + const Word16 input_frame /* i : input frame length per channel */ +); +static ivas_error estimate_itd_fx( + Word16 *corr, /* o : correlation */ + STEREO_DMX_EVS_POC_HANDLE hPOC, /* i/o: phase only correlation structure */ + STEREO_DMX_EVS_PHA_HANDLE hPHA, /* i/o: correlation filter structure */ + const Word32 srcL[], /* i : Lch input signal Q16 */ + const Word32 srcR[], /* i : Rch input signal Q16 */ + Word32 itd[], /* o : estimated itd Q16 */ + const Word16 input_frame /* i : input frame length per channel */ +); +static void adapt_gain_fx( + const Word32 src_fx[], /* i : input signal Q16 */ + Word32 dst_fx[], /* o : output signal */ + const Word32 gain_fx, /* i : adapting gain Q31*/ + const Word32 old_gain_fx, /* i : adapting prev gain Q31*/ + const Word16 input_frame, /* i : input frame length per channel */ + const Word32 wnd_fx[] /* i : window coef Q31 */ +); +static void weighted_ave_fx( + const Word32 src1_fx[], /* i : Lch input signal Q16 */ + const Word32 src2_fx[], /* i : Rch input signal Q16 */ + Word32 dst_fx[], /* o : output signal */ + const Word32 gain_fx, /* i : adapting gain Q31 */ + const Word32 old_gain_fx, /* i : adapting prev gain Q31 */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word32 wnd_fx[] /* i : window coef Q31 */ +); +static void calc_energy_fx( + const Word32 src1_fx[], /* i : Lch input signal */ + const Word32 src2_fx[], /* i : Rch input signal */ + Word32 energy_fx[], /* o : calculated energy */ + Word16 *energy_fx_e, /* o : calculated energy */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word32 ratio_float_fx ); + +static void create_M_signal_fx( + const Word32 srcL_fx[], /* i : Lch input signal Q16 */ + const Word32 srcR_fx[], /* i : Rch input signal Q16 */ + Word32 dmx_fx[], /* o : output signal Q31 */ + const Word32 w_curr_fx, /* i : adapting weight Q31 */ + const int16_t input_frame, /* i : input frame length per channel */ + const Word32 wnd_fx[], /* i : window coef Q31 */ + Word32 *w_prev_fx, /* i/o: adapting prev weight Q31*/ + Word32 *dmx_energy_fx, /* i/o: downmix signal energy dmx_energy_fx_e */ + Word16 *dmx_energy_fx_e, /* i/o: downmix signal energy */ + Word32 *src_energy_fx, /* i/o: input signal energy src_energy_fx_e */ + Word16 *src_energy_fx_e /* i/o: input signal energy */ +); +static Word32 find_poc_peak_fx( + STEREO_DMX_EVS_POC_HANDLE hPOC, /* i/o: phase only correlation structure */ + Word32 itd_fx[], /* o : estimated itd */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word32 ratio_fixed /* i : adapting ratio */ +); +#else static void estimate_itd_wnd_fft( const float *input, float *specr, float *speci, const float *rfft_coef, const float *wnd, const int16_t input_frame ); static void calc_poc( STEREO_DMX_EVS_POC_HANDLE hPOC, STEREO_DMX_EVS_PHA_HANDLE hPHA, const float wnd[], const float rfft_coef[], const float specLr[], const float specLi[], const float specRr[], const float specRi[], const int16_t input_frame ); static ivas_error estimate_itd( float *corr, STEREO_DMX_EVS_POC_HANDLE hPOC, STEREO_DMX_EVS_PHA_HANDLE hPHA, const float srcL[], const float srcR[], float itd[], const int16_t input_frame ); static void weighted_ave( const float src1[], const float src2[], float dst[], const float gain, const float old_gain, const int16_t input_frame, const float wnd[] ); static void adapt_gain( const float src[], float dst[], const float gain, const float old_gain, const int16_t input_frame, const float wnd[] ); static void create_M_signal( const float srcL[], const float srcR[], float dmx[], const float w_curr, const int16_t input_frame, const float wnd[], float *w_prev, float *dmx_energy, float *src_energy ); -static float find_poc_peak( STEREO_DMX_EVS_POC_HANDLE hPOC, float itd[], const int16_t input_frame, const float ratio_float ); -static void calc_energy( const float src1[], const float src2[], float energy[], const int16_t input_frame, const float ratio_float ); +static float find_poc_peak( STEREO_DMX_EVS_POC_HANDLE hPOC, float itd[], const int16_t input_frame, const float ratio ); +static void calc_energy( const float src1[], const float src2[], float energy[], const int16_t input_frame, const float ratio ); +#endif /*-------------------------------------------------------------------* * estimate_itd_wnd_fft() * * Transforms input signal from time domain into frequency domain. * The input signal is windowed before being transformed. *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void estimate_itd_wnd_fft_fx( + const Word32 *input, /* i : input signal Q16 */ + Word32 *specr, /* o : real-part spectra Q(31-spec_e) */ + Word32 *speci, /* o : imaginary-part spectra Q(31-spec_e) */ + Word16 *spec_e, + const Word16 *rfft_coef, /* i : rfft coef Q15 */ + const Word32 *wnd, /* i : window coef Q31 */ + const Word16 input_frame /* i : input frame length per channel */ +) +{ + Word16 n0, i; + Word32 rfft_buf[L_FRAME48k]; + Word16 step, bias; + Word16 rshift; + n0 = shr( input_frame, 1 ); + IF( EQ_16( input_frame, L_FRAME16k ) ) + { + step = 3; + move16(); + bias = 1; + move16(); + } + ELSE + { + step = 1; + move16(); + bias = 0; + move16(); + } + + FOR( i = 0; i < input_frame; i++ ) + { + /* window */ + rfft_buf[i] = Mpy_32_32_r( input[i], wnd[i * step + bias] ); // Q16 + move32(); + } + + rshift = sub( getScaleFactor32( rfft_buf, input_frame ), find_guarded_bits_fx( input_frame ) ); + scale_sig32( rfft_buf, input_frame, rshift ); + *spec_e = sub( 15, rshift ); + move16(); + rfft_fx( rfft_buf, rfft_coef, input_frame, -1 ); + + FOR( i = 1; i < n0; i++ ) + { + specr[i] = rfft_buf[i * 2]; + move32(); + speci[i] = rfft_buf[i * 2 + 1]; + move32(); + } + + specr[0] = rfft_buf[0]; + move32(); + specr[n0] = rfft_buf[1]; + move32(); + speci[0] = 0; + move32(); + speci[n0] = 0; + move32(); + + return; +} +#else void estimate_itd_wnd_fft( const float *input, /* i : input signal */ float *specr, /* o : real-part spectra */ @@ -162,14 +354,828 @@ void estimate_itd_wnd_fft( return; } - +#endif /*-------------------------------------------------------------------* * calc_poc() * * calculate phase only correlation *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void calc_poc_fx( + STEREO_DMX_EVS_POC_HANDLE hPOC, /* i/o: phase only correlation structure */ + STEREO_DMX_EVS_PHA_HANDLE hPHA, /* i/o: correlation filter structure */ + const Word32 wnd[], /* i : window coef Q31 */ + const Word16 rfft_coef[], /* i : RFFT coef Q15 */ + const Word32 specLr[], /* i : Lch real-part spectra Q(31-spec_e) */ + const Word32 specLi[], /* i : Lch imaginary-part input signal Q(31-spec_e) */ + const Word32 specRr[], /* i : Rch real-part spectra Q(31-spec_e) */ + const Word32 specRi[], /* i : Rch imaginary-part input signal Q(31-spec_e) */ + const Word16 spec_e, + const Word16 input_frame /* i : input frame length per channel */ +) +{ + Word16 i, n1, n2; + Word16 n0, *itdLR; + const Word16 *s; + Word32 *P; + Word32 tmp1, tmp2, Lr, Li, Rr, Ri, gamma, igamma /*, iN*/; + + Word32 specPOr[L_FRAME48k / 2 + 1], specPOi[L_FRAME48k / 2]; /*real and imaginary values for searching phase angle Q31*/ + Word32 tmpPOC1[L_FRAME48k], tmpPOC2[L_FRAME48k]; + Word32 rfft_buf[L_FRAME48k]; // Q21 + Word16 step, bias; + Word16 mult_angle; + Word16 j; + Word16 end; + + Word16 cos_step, cos_max; + Word32 eps_cos, eps_sin, EPS; + + Word16 isd_cnt_h, isd_cnt_l, ild_cnt, n, freq_8k, freq_ipd_max, nsbd, input_frame_pha; + Word32 Nr, Ni, Dr, Di, tPr, tPi, Pn, energy; + Word16 Nr_e, Ni_e, tPr_e, tPi_e, Pn_e, energy_e; + Word16 isd_rate, isd_rate_e; + Word32 eneL, eneR, IPDr, IPDi, tIPDr, tIPDi, ICCr; + Word16 eneL_e, eneR_e, IPDr_e, IPDi_e; + Word32 *Pr, *Pi, *ipd_ff, *p_curr_taps; + Word32 rfft_pha_buf[L_FRAME48k] /*Q22*/, tEr[STEREO_DMX_EVS_NB_SUBBAND_MAX], tEl[STEREO_DMX_EVS_NB_SUBBAND_MAX]; + Word16 tEr_e[STEREO_DMX_EVS_NB_SUBBAND_MAX], tEl_e[STEREO_DMX_EVS_NB_SUBBAND_MAX]; + + Word32 L_tmp, L_tmp1, L_tmp2; + Word16 L_tmp_e, L_tmp1_e, L_tmp2_e; + Word64 W_tmp; + Word16 W_tmp_q; + + /* Initialization */ + // iN = 1.0f / (float) input_frame; + s = hPOC->sin_fx; + P = hPOC->P_fx; + n0 = shr( input_frame, 1 ); + itdLR = hPOC->itdLR; + + Pr = hPHA->Pr_fx; + Pi = hPHA->Pi_fx; + // nsbd = n0 / STEREO_DMX_EVS_SUBBAND_SIZE; + nsbd = shr( n0, 1 ); + // input_frame_pha = input_frame / STEREO_DMX_EVS_SUBBAND_SIZE; + input_frame_pha = shr( input_frame, 1 ); + + // igamma = STEREO_DMX_EVS_POC_GAMMA * iN; + IF( EQ_16( input_frame, L_FRAME16k ) ) + { + igamma = 5033165; + move16(); + } + ELSE IF( EQ_16( input_frame, L_FRAME32k ) ) + { + igamma = 3355444; + move16(); + } + ELSE IF( EQ_16( input_frame, L_FRAME48k ) ) + { + igamma = 1677722; + move16(); + } + ELSE + { + igamma = 1677722; + move16(); + IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid sample rate\n" ); + } + gamma = L_sub( MAX_32, igamma ); + + step = 1; + move16(); + bias = 0; + move16(); + cos_step = 2; + move16(); + cos_max = n0; + move16(); + mult_angle = 3; + move16(); + + IF( EQ_16( input_frame, L_FRAME16k ) ) + { + step = 3; + move16(); + bias = 1; + move16(); + cos_step = 4; + move16(); + cos_max = input_frame; + move16(); + mult_angle = 2; /*****/ + move16(); + } + if ( EQ_16( input_frame, L_FRAME32k ) ) + { + mult_angle = 2; + move16(); + } + + end = s_min( n0, 320 ); + // specPOr[0] = sign( specLr[0] * specRr[0] ) * wnd[bias]; + specPOr[0] = imult3216( wnd[bias], sign_fx( Mpy_32_32( specLr[0], specRr[0] ) ) ); + move32(); + specPOi[0] = 0; + move32(); + EPS = hPOC->eps_fx; + move16(); + IF( EQ_32( input_frame, L_FRAME48k ) ) + { + FOR( i = 1; i < n0 / 2; i++ ) + { + // eps_cos = s[cos_max - i * cos_step /*cos_max - i_for*/] * EPS; + eps_cos = Mpy_32_16_1( EPS, s[cos_max - i * cos_step /*cos_max - i_for*/] ); + // eps_sin = s[i * cos_step /*i_for*/] * EPS; + eps_sin = Mpy_32_16_1( EPS, s[i * cos_step /*i_for*/] ); + + Lr = L_add( L_add( specLr[i], Mpy_32_32_r( specRr[i], eps_cos ) ), Mpy_32_32_r( specRi[i], eps_sin ) ); + Li = L_add( L_sub( specLi[i], Mpy_32_32_r( specRr[i], eps_sin ) ), Mpy_32_32_r( specRi[i], eps_cos ) ); + Rr = L_add( L_add( specRr[i], Mpy_32_32_r( specLr[i], eps_cos ) ), Mpy_32_32_r( specLi[i], eps_sin ) ); + Ri = L_add( L_sub( specRi[i], Mpy_32_32_r( specLr[i], eps_sin ) ), Mpy_32_32_r( specLi[i], eps_cos ) ); + + specPOr[i] = L_add( Mpy_32_32_r( Lr, Rr ), Mpy_32_32_r( Li, Ri ) ); // 2*spec_e + move32(); + specPOi[i] = L_sub( Mpy_32_32_r( Lr, Ri ), Mpy_32_32_r( Li, Rr ) ); // 2*spec_e + move32(); + j = sub( n0, i ); + IF( LT_16( j, 320 ) ) + { + Lr = L_add( L_sub( specLr[j], Mpy_32_32_r( specRr[j], eps_cos ) ), Mpy_32_32_r( specRi[j], eps_sin ) ); + Li = L_sub( L_sub( specLi[j], Mpy_32_32_r( specRr[j], eps_sin ) ), Mpy_32_32_r( specRi[j], eps_cos ) ); + Rr = L_add( L_sub( specRr[j], Mpy_32_32_r( specLr[j], eps_cos ) ), Mpy_32_32_r( specLi[j], eps_sin ) ); + Ri = L_sub( L_sub( specRi[j], Mpy_32_32_r( specLr[j], eps_sin ) ), Mpy_32_32_r( specLi[j], eps_cos ) ); + + specPOr[j] = L_add( Mpy_32_32_r( Lr, Rr ), Mpy_32_32_r( Li, Ri ) ); // 2*spec_e + move32(); + specPOi[j] = L_sub( Mpy_32_32_r( Lr, Ri ), Mpy_32_32_r( Li, Rr ) ); // 2*spec_e + move32(); + } + } + } + ELSE /* 16kHz and 32 kHz*/ + { + FOR( i = 1; i < n0 / 2; i++ ) + { + // eps_cos = s[cos_max - i * cos_step /*cos_max - i_for*/] * EPS; + eps_cos = Mpy_32_16_1( EPS, s[cos_max - i * cos_step /*cos_max - i_for*/] ); + // eps_sin = s[i * cos_step /*i_for*/] * EPS; + eps_sin = Mpy_32_16_1( EPS, s[i * cos_step /*i_for*/] ); + + Lr = L_add( L_add( specLr[i], Mpy_32_32_r( specRr[i], eps_cos ) ), Mpy_32_32_r( specRi[i], eps_sin ) ); + Li = L_add( L_sub( specLi[i], Mpy_32_32_r( specRr[i], eps_sin ) ), Mpy_32_32_r( specRi[i], eps_cos ) ); + Rr = L_add( L_add( specRr[i], Mpy_32_32_r( specLr[i], eps_cos ) ), Mpy_32_32_r( specLi[i], eps_sin ) ); + Ri = L_add( L_sub( specRi[i], Mpy_32_32_r( specLr[i], eps_sin ) ), Mpy_32_32_r( specLi[i], eps_cos ) ); + specPOr[i] = L_add( Mpy_32_32_r( Lr, Rr ), Mpy_32_32_r( Li, Ri ) ); // 2*spec_e + move32(); + specPOi[i] = L_sub( Mpy_32_32_r( Lr, Ri ), Mpy_32_32_r( Li, Rr ) ); // 2*spec_e + move32(); + + j = sub( n0, i ); + Lr = L_add( L_sub( specLr[j], Mpy_32_32_r( specRr[j], eps_cos ) ), Mpy_32_32_r( specRi[j], eps_sin ) ); + Li = L_sub( L_sub( specLi[j], Mpy_32_32_r( specRr[j], eps_sin ) ), Mpy_32_32_r( specRi[j], eps_cos ) ); + Rr = L_add( L_sub( specRr[j], Mpy_32_32_r( specLr[j], eps_cos ) ), Mpy_32_32_r( specLi[j], eps_sin ) ); + Ri = L_sub( L_sub( specRi[j], Mpy_32_32_r( specLr[j], eps_sin ) ), Mpy_32_32_r( specLi[j], eps_cos ) ); + specPOr[j] = L_add( Mpy_32_32_r( Lr, Rr ), Mpy_32_32_r( Li, Ri ) ); // 2*spec_e + move32(); + specPOi[j] = L_sub( Mpy_32_32_r( Lr, Ri ), Mpy_32_32_r( Li, Rr ) ); // 2*spec_e + move32(); + } + } + { + /* i=n0/2*/ + Lr = L_add( specLr[i], Mpy_32_32_r( specRi[i], EPS ) ); + Li = L_sub( specLi[i], Mpy_32_32_r( specRr[i], EPS ) ); + Rr = L_add( specRr[i], Mpy_32_32_r( specLi[i], EPS ) ); + Ri = L_sub( specRi[i], Mpy_32_32_r( specLr[i], EPS ) ); + specPOr[i] = L_add( Mpy_32_32_r( Lr, Rr ), Mpy_32_32_r( Li, Ri ) ); + move32(); + specPOi[i] = L_sub( Mpy_32_32_r( Lr, Ri ), Mpy_32_32_r( Li, Rr ) ); + move32(); + } + /* complex spectrum (specPOr[i], specPOi[i]) are placed on an unit circle without using srqt()*/ + FOR( i = 1; i < 10; i++ ) /*search from 4 angles */ + { + tmp1 = Mpy_32_32_r( wnd[i * step + bias], gamma ); + + specPOr[i] = Mpy_32_16_1( tmp1, imult1616( sign_fx( specPOr[i] ), 28377 /*0.866f*/ ) ); /* low angles are more frequent for low frequency */ + move32(); + specPOi[i] = Mpy_32_16_1( tmp1, imult1616( sign_fx( specPOi[i] ), ONE_IN_Q14 /*0.5f*/ ) ); + move32(); + gamma = L_sub( gamma, igamma ); + } + FOR( ; i < n0 >> 4; i++ ) /*search from 4 angles */ + { + tmp1 = Mpy_32_16_1( Mpy_32_32_r( wnd[i * step + bias], gamma ), 23170 /*0.7071f*/ ); + specPOr[i] = imult3216( tmp1, sign_fx( specPOr[i] ) ); + move32(); + specPOi[i] = imult3216( tmp1, sign_fx( specPOi[i] ) ); /* low accuracy is adequate for low frequency */ + move32(); + gamma = L_sub( gamma, igamma ); + } + + FOR( ; i < n0 >> 3; i++ ) /* binary search from 8 angles */ + { + tmp1 = Mpy_32_32_r( wnd[i * step + bias], gamma ); + + IF( W_mult0_32_32( L_sub( specPOr[i], specPOi[i] ), L_add( specPOr[i], specPOi[i] ) ) > 0 ) + { + specPOr[i] = Mpy_32_16_1( tmp1, imult1616( sign_fx( specPOr[i] ), /*0.923880f*/ s[120 * mult_angle] ) ); /* cos(PI/8)*/ + move32(); + specPOi[i] = Mpy_32_16_1( tmp1, imult1616( sign_fx( specPOi[i] ), /*0.382683f*/ s[40 * mult_angle] ) ); + move32(); + } + ELSE + { + specPOr[i] = Mpy_32_16_1( tmp1, imult1616( sign_fx( specPOr[i] ), /*0.382683f*/ s[40 * mult_angle] ) ); /* cos(PI*3/8)*/ + move32(); + specPOi[i] = Mpy_32_16_1( tmp1, imult1616( sign_fx( specPOi[i] ), /*0.923880f*/ s[120 * mult_angle] ) ); + move32(); + } + gamma = L_sub( gamma, igamma ); + } + FOR( ; i < end; i++ ) /* binary search from 16 angles */ + { + tmp1 = Mpy_32_32_r( wnd[i * step + bias], gamma ); + IF( W_mult0_32_32( L_sub( specPOr[i], specPOi[i] ), L_add( specPOr[i], specPOi[i] ) ) > 0 ) + { + IF( W_mult0_32_32( L_sub( Mpy_32_16_1( specPOr[i], 13573 /*0.414213f*/ ), specPOi[i] ), L_add( Mpy_32_16_1( specPOr[i], 13573 /*0.414213f*/ ), specPOi[i] ) ) > 0 ) /*tan(PI/8)*/ + { + specPOr[i] = Mpy_32_16_1( tmp1 /*0.980785f */, imult1616( sign_fx( specPOr[i] ), s[140 * mult_angle] ) ); /* cos(PI/16)*/ + move32(); + specPOi[i] = Mpy_32_16_1( tmp1 /*0.195090f */, imult1616( sign_fx( specPOi[i] ), s[20 * mult_angle] ) ); + move32(); + } + ELSE + { + specPOr[i] = Mpy_32_16_1( tmp1 /* 0.831470f */, imult1616( sign_fx( specPOr[i] ), s[100 * mult_angle] ) ); /*cos(PI*3/16)*/ + move32(); + specPOi[i] = Mpy_32_16_1( tmp1 /* 0.555570f*/, imult1616( sign_fx( specPOi[i] ), s[60 * mult_angle] ) ); + move32(); + } + } + ELSE + { + IF( W_mult0_32_32( L_sub( specPOr[i], Mpy_32_16_1( specPOi[i], 13573 /*0.414213f*/ ) ), L_add( specPOr[i], Mpy_32_16_1( specPOi[i], 13573 /*0.414213f*/ ) ) ) > 0 ) /*tan(PI/8)*/ + { + specPOr[i] = Mpy_32_16_1( tmp1 /** 0.555570f*/, imult1616( sign_fx( specPOr[i] ), s[60 * mult_angle] ) ); /*cos(PI*5/16)*/ + move32(); + specPOi[i] = Mpy_32_16_1( tmp1 /** 0.831470f*/, imult1616( sign_fx( specPOi[i] ), s[100 * mult_angle] ) ); + move32(); + } + ELSE + { + specPOr[i] = Mpy_32_16_1( tmp1 /** 0.195090f*/, imult1616( sign_fx( specPOr[i] ), s[20 * mult_angle] ) ); /*cos(PI*7/16)*/ + move32(); + specPOi[i] = Mpy_32_16_1( tmp1 /** 0.980785f*/, imult1616( sign_fx( specPOi[i] ), s[140 * mult_angle] ) ); + move32(); + } + } + gamma = L_sub( gamma, igamma ); + } + + IF( LT_16( i, n0 ) ) + { + gamma = L_sub( gamma, imult3216( igamma, sub( n0, 320 ) ) ); + } + FOR( ; i < n0; i++ ) /*neglect higher frequency bins when 48 kHz samplng*/ + { + specPOr[i] = 0; + move32(); + specPOi[i] = 0; + move32(); + } + specPOr[n0] = imult3216( Mpy_32_32_r( wnd[i * step + bias], gamma ), sign_fx( Mpy_32_32_r( specLr[n0], specRr[n0] ) ) ); + move32(); + + + hPHA->init_frmCntr = sub( hPHA->init_frmCntr, 1 ); + if ( hPHA->init_frmCntr < 0 ) + { + hPHA->init_frmCntr = 0; + move16(); + } + freq_8k = L_FRAME16k / 2; + move16(); + // freq_ipd_max = (int16_t) ( freq_8k * 5000.0f / ( 8000.0f * STEREO_DMX_EVS_SUBBAND_SIZE ) ); + freq_ipd_max = 50; + move16(); + + /* Memorize the filters N-1 */ + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + IF( hPHA->p_curr_taps_fx[n] ) + { + hPHA->p_prev_taps_fx[n] = hPHA->prev_taps_fx[n]; + Copy32( hPHA->p_curr_taps_fx[n], hPHA->p_prev_taps_fx[n], hPHA->pha_len ); + } + ELSE + { + hPHA->p_prev_taps_fx[n] = NULL; + } + } + + /* ISD */ + isd_cnt_l = 0; + move16(); + isd_cnt_h = 0; + move16(); + FOR( i = 1; i <= freq_8k; i++ ) + { + Nr = L_sub( specLr[i], specRr[i] ); // spec_e + Ni = L_sub( specLi[i], specRi[i] ); // spec_e + Dr = L_add( specLr[i], specRr[i] ); // spec_e + Di = L_add( specLi[i], specRi[i] ); // spec_e + // if ( ( Nr * Nr + Ni * Ni ) > STEREO_DMX_EVS_ISD_THRES_H * ( Dr * Dr + Di * Di ) ) + if ( GT_32( Mpy_32_32_r( L_add( Mpy_32_32_r( Nr, Nr ), Mpy_32_32_r( Ni, Ni ) ), 1270700383 ), L_add( Mpy_32_32_r( Dr, Dr ), Mpy_32_32_r( Di, Di ) ) ) ) + { + isd_cnt_h = add( isd_cnt_h, 1 ); + } + if ( LT_32( L_add( Mpy_32_32_r( Nr, Nr ), Mpy_32_32_r( Ni, Ni ) ), Mpy_32_32_r( STEREO_DMX_EVS_ISD_THRES_L_Q31, L_add( Mpy_32_32_r( Dr, Dr ), Mpy_32_32_r( Di, Di ) ) ) ) ) + { + isd_cnt_l = add( isd_cnt_l, 1 ); + } + } + + isd_rate = BASOP_Util_Divide1616_Scale( isd_cnt_h, freq_8k, &isd_rate_e ); + isd_rate = shl_r( isd_rate, isd_rate_e ); // Q15 + hPHA->isd_rate_s_fx = add( mult_r( STEREO_DMX_EVS_ISD_FORGETTING_Q15, hPHA->isd_rate_s_fx ), mult_r( MAX_16 - STEREO_DMX_EVS_ISD_FORGETTING_Q15, isd_rate ) ); + move16(); + + IF( GT_16( hPHA->isd_rate_s_fx, STEREO_DMX_EVS_ISD_DIST_HYST_H_Q15 ) ) + { + IF( NE_32( hPHA->curr_pha, STEREO_DMX_EVS_PHA_IPD ) ) + { + IF( EQ_32( hPHA->prev_pha, STEREO_DMX_EVS_PHA_IPD ) ) + { + hPHA->pha_hys_cnt = add( hPHA->pha_hys_cnt, 1 ); + move16(); + } + ELSE + { + hPHA->pha_hys_cnt = 0; + move16(); + } + + if ( GE_32( hPHA->pha_hys_cnt, STEREO_DMX_EVS_SWTCH_HYS_THRES ) ) + { + hPHA->curr_pha = STEREO_DMX_EVS_PHA_IPD; + move32(); + } + } + + hPHA->prev_pha = STEREO_DMX_EVS_PHA_IPD; + move32(); + } + ELSE IF( LT_16( hPHA->isd_rate_s_fx, STEREO_DMX_EVS_ISD_DIST_HYST_L_Q15 ) ) + { + IF( NE_32( hPHA->curr_pha, STEREO_DMX_EVS_PHA_IPD2 ) ) + { + IF( EQ_32( hPHA->prev_pha, STEREO_DMX_EVS_PHA_IPD2 ) ) + { + hPHA->pha_hys_cnt = add( hPHA->pha_hys_cnt, 1 ); + move16(); + } + ELSE + { + hPHA->pha_hys_cnt = 0; + move16(); + } + + if ( GE_16( hPHA->pha_hys_cnt, STEREO_DMX_EVS_SWTCH_HYS_THRES ) ) + { + hPHA->curr_pha = STEREO_DMX_EVS_PHA_IPD2; + move32(); + } + } + hPHA->prev_pha = STEREO_DMX_EVS_PHA_IPD2; + move32(); + } + + ipd_ff = hPHA->ipd_ff_fx; + + Nr = 0; + move32(); + Nr_e = 0; + move16(); + Ni = 0; + move32(); + Ni_e = 0; + move16(); + eneL = 0; + move32(); + eneL_e = 0; + move16(); + eneR = 0; + move32(); + eneR_e = 0; + move16(); + + FOR( ( n = 1, i = 1 ); n < nsbd; n++ ) + { + tPr = 0; + move32(); + tPr_e = 0; + move16(); + tPi = 0; + move32(); + tPi_e = 0; + move16(); + tEr[n] = 0; + move32(); + tEr_e[n] = 0; + move16(); + tEl[n] = 0; + move32(); + tEl_e[n] = 0; + move16(); + + FOR( j = 0; j < STEREO_DMX_EVS_SUBBAND_SIZE; ( j++, i++ ) ) + { + /* Energy */ + tEl[n] = BASOP_Util_Add_Mant32Exp( tEl[n], tEl_e[n], L_add( Mpy_32_32_r( specLr[i], specLr[i] ), Mpy_32_32_r( specLi[i], specLi[i] ) ), shl( spec_e, 1 ), &tEl_e[n] ); + move32(); + tEr[n] = BASOP_Util_Add_Mant32Exp( tEr[n], tEr_e[n], L_add( Mpy_32_32_r( specRr[i], specRr[i] ), Mpy_32_32_r( specRi[i], specRi[i] ) ), shl( spec_e, 1 ), &tEr_e[n] ); + move32(); + + /* IPD */ + // IPDr = L_add(Mpy_32_32_r(specLr[i], specRr[i]), Mpy_32_32_r(specLi[i], specRi[i])); //2*spec_e + W_tmp = W_add( W_mult_32_32( specLr[i], specRr[i] ), W_mult_32_32( specLi[i], specRi[i] ) ); + W_tmp_q = W_norm( W_tmp ); + W_tmp = W_shl( W_tmp, W_tmp_q ); + IPDr = W_extract_h( W_tmp ); + IPDr_e = sub( shl( spec_e, 1 ), W_tmp_q ); + // IPDi = L_sub(Mpy_32_32_r(specLi[i] , specRr[i]), Mpy_32_32_r(specLr[i] , specRi[i])); //2*spec_e + W_tmp = W_sub( W_mult_32_32( specLi[i], specRr[i] ), W_mult_32_32( specLr[i], specRi[i] ) ); + W_tmp_q = W_norm( W_tmp ); + W_tmp = W_shl( W_tmp, W_tmp_q ); + IPDi = W_extract_h( W_tmp ); + IPDi_e = sub( shl( spec_e, 1 ), W_tmp_q ); + tPr = BASOP_Util_Add_Mant32Exp( tPr, tPr_e, IPDr, IPDr_e, &tPr_e ); + tPi = BASOP_Util_Add_Mant32Exp( tPi, tPi_e, IPDi, IPDi_e, &tPi_e ); + + /* ICCr */ + // Pn = (float) inv_sqrt( ( IPDr * IPDr + IPDi * IPDi ) + EPSILON ); + L_tmp = BASOP_Util_Add_Mant32Exp( Mpy_32_32_r( IPDr, IPDr ), shl( IPDr_e, 1 ), Mpy_32_32_r( IPDi, IPDi ), shl( IPDi_e, 1 ), &L_tmp_e ); + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, EPSILON_FX_M, EPSILON_FX_E, &L_tmp_e ); + Pn_e = L_tmp_e; + move16(); + Pn = ISqrt32( L_tmp, &Pn_e ); + IPDr = L_shl_sat( Mpy_32_32_r( IPDr, Pn ), add( IPDr_e, Pn_e ) ); // Q31 + IPDi = L_shl_sat( Mpy_32_32_r( IPDi, Pn ), add( IPDi_e, Pn_e ) ); // Q31 + + tIPDr = L_sub( Mpy_32_32_r( specRr[i], IPDr ), Mpy_32_32_r( specRi[i], IPDi ) ); // spec_e + tIPDi = L_add( Mpy_32_32_r( specRr[i], IPDi ), Mpy_32_32_r( specRi[i], IPDr ) ); // spec_e + + Nr = BASOP_Util_Add_Mant32Exp( Nr, Nr_e, L_add( Mpy_32_32_r( specLr[i], tIPDr ), Mpy_32_32_r( specLi[i], tIPDi ) ), shl( spec_e, 1 ), &Nr_e ); + Ni = BASOP_Util_Add_Mant32Exp( Ni, Ni_e, L_sub( Mpy_32_32_r( specLi[i], tIPDr ), Mpy_32_32_r( specLr[i], tIPDi ) ), shl( spec_e, 1 ), &Ni_e ); + + eneL = BASOP_Util_Add_Mant32Exp( eneL, eneL_e, L_add( Mpy_32_32_r( specLr[i], specLr[i] ), Mpy_32_32_r( specLi[i], specLi[i] ) ), shl( spec_e, 1 ), &eneL_e ); + eneR = BASOP_Util_Add_Mant32Exp( eneR, eneR_e, L_add( Mpy_32_32_r( specRr[i], specRr[i] ), Mpy_32_32_r( specRi[i], specRi[i] ) ), shl( spec_e, 1 ), &eneR_e ); + } + + // Pn = (float) inv_sqrt( ( tPr * tPr + tPi * tPi ) + EPSILON ); + L_tmp = BASOP_Util_Add_Mant32Exp( Mpy_32_32_r( tPr, tPr ), shl( tPr_e, 1 ), Mpy_32_32_r( tPi, tPi ), shl( tPi_e, 1 ), &L_tmp_e ); + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, EPSILON_FX_M, EPSILON_FX_E, &L_tmp_e ); + Pn_e = L_tmp_e; + move16(); + Pn = ISqrt32( L_tmp, &Pn_e ); + tPr = L_shl_sat( Mpy_32_32_r( tPr, Pn ), add( tPr_e, Pn_e ) ); // Q31 + tPi = L_shl_sat( Mpy_32_32_r( tPi, Pn ), add( tPi_e, Pn_e ) ); // Q31 + + IF( hPHA->init_frmCntr == 0 ) + { + Pr[n] = L_add( Mpy_32_32_r( ipd_ff[n], Pr[n] ), Mpy_32_32_r( L_sub( MAX_32, ipd_ff[n] ), tPr ) ); + move32(); + Pi[n] = L_add( Mpy_32_32_r( ipd_ff[n], Pi[n] ), Mpy_32_32_r( L_sub( MAX_32, ipd_ff[n] ), tPi ) ); + move32(); + // Pn = (float) inv_sqrt( ( Pr[n] * Pr[n] + Pi[n] * Pi[n] ) + EPSILON ); + L_tmp = L_add( L_shr( Mpy_32_32_r( Pr[n], Pr[n] ), 1 ), L_shr( Mpy_32_32_r( Pi[n], Pi[n] ), 1 ) ); + L_tmp_e = 1; + move16(); + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, EPSILON_FX_M, EPSILON_FX_E, &L_tmp_e ); + Pn_e = L_tmp_e; + move16(); + Pn = ISqrt32( L_tmp, &Pn_e ); + Pr[n] = L_shl_sat( Mpy_32_32_r( Pr[n], Pn ), Pn_e ); // Q31 + move32(); + Pi[n] = L_shl_sat( Mpy_32_32_r( Pi[n], Pn ), Pn_e ); // Q31 + move32(); + } + ELSE + { + Pr[n] = tPr; + move32(); + Pi[n] = tPi; + move32(); + } + + // Pr[n] = ( Pr[n] > 1.0f ) ? 1.0f : Pr[n]; + // Pr[n] = ( Pr[n] < -1.0f ) ? -1.0f : Pr[n]; + } + // ICCr = (float) sqrt( ( Nr * Nr + Ni * Ni ) / ( eneL * eneR + EPSILON ) ); + L_tmp1 = BASOP_Util_Add_Mant32Exp( Mpy_32_32_r( Nr, Nr ), shl( Nr_e, 1 ), Mpy_32_32_r( Ni, Ni ), shl( Ni_e, 1 ), &L_tmp1_e ); + L_tmp2 = BASOP_Util_Add_Mant32Exp( Mpy_32_32_r( eneL, eneR ), add( eneL_e, eneR_e ), EPSILON_FX_M, EPSILON_FX_E, &L_tmp2_e ); + ICCr = BASOP_Util_Divide3232_Scale_cadence( L_tmp1, L_tmp2, &L_tmp_e ); + L_tmp_e = add( L_tmp_e, sub( L_tmp1_e, L_tmp2_e ) ); + ICCr = Sqrt32( ICCr, &L_tmp_e ); + ICCr = L_shl_r( ICCr, L_tmp_e ); // Q31 + + // hPHA->iccr_s = STEREO_DMX_EVS_ICCR_FORGETTING * hPHA->iccr_s + ( 1.0f - STEREO_DMX_EVS_ICCR_FORGETTING ) * ICCr; + hPHA->iccr_s_fx = L_add( Mpy_32_32_r( STEREO_DMX_EVS_ICCR_FORGETTING_Q31, hPHA->iccr_s_fx ), Mpy_32_32_r( MAX_32 - STEREO_DMX_EVS_ICCR_FORGETTING_Q31, ICCr ) ); + move16(); + + IF( EQ_32( hPHA->curr_pha, STEREO_DMX_EVS_PHA_IPD ) ) + { + hPHA->p_curr_taps_fx[0] = NULL; + hPHA->p_curr_taps_fx[1] = hPHA->curr_taps_fx[1]; + + rfft_pha_buf[0] = ONE_IN_Q22; + move32(); + rfft_pha_buf[1] = ONE_IN_Q22; + move32(); + + ild_cnt = 0; + move16(); + FOR( i = 1; i < nsbd; i++ ) + { + rfft_pha_buf[i * 2] = L_shr_r( Pr[i], 9 ); // Q31->Q22 + move32(); + rfft_pha_buf[i * 2 + 1] = L_shr_r( Pi[i], 9 ); // Q31->Q22 + move32(); + // if ( ( tEr[i] > STEREO_DMX_EVS_LR_EGY * tEl[i] ) || ( tEl[i] > STEREO_DMX_EVS_LR_EGY * tEr[i] ) ) + test(); + IF( BASOP_Util_Cmp_Mant32Exp( tEr[i], tEr_e[i], Mpy_32_32_r( STEREO_DMX_EVS_LR_EGY_Q27, tEl[i] ), add( 4, tEl_e[i] ) ) > 0 || BASOP_Util_Cmp_Mant32Exp( tEl[i], tEl_e[i], Mpy_32_32_r( STEREO_DMX_EVS_LR_EGY_Q27, tEr[i] ), add( 4, tEr_e[i] ) ) > 0 ) + { + ild_cnt = add( ild_cnt, 1 ); + tEr[i] = MAX_32; + move32(); + tEr_e[i] = 0; + move16(); + } + ELSE + { + tEr[i] = MIN_32; + move32(); + tEr_e[i] = 0; + move16(); + } + } + IF( GT_16( ild_cnt, mult_r( nsbd, STEREO_DMX_EVS_ILD_PRC_Q15 ) ) ) + { + FOR( i = 1; i < nsbd; i++ ) + { + IF( tEr[i] > 0 ) + { + rfft_pha_buf[i * 2] = ONE_IN_Q22; + move32(); + rfft_pha_buf[i * 2 + 1] = 0; + move32(); + } + } + } + + rfft_fx( rfft_pha_buf, hPHA->rfft_ipd_coef_fx, input_frame_pha, +1 ); + // mvr2r( rfft_pha_buf, hPHA->p_curr_taps[1], hPHA->pha_len ); + Copy_Scale_sig32( rfft_pha_buf, hPHA->p_curr_taps_fx[1], hPHA->pha_len, 9 ); // Q22->Q31 + } + ELSE + { + test(); + test(); + IF( LT_32( hPHA->iccr_s_fx, STEREO_DMX_EVS_ICCR_HYST_L_Q31 ) || ( LT_32( hPHA->iccr_s_fx, STEREO_DMX_EVS_ICCR_HYST_H_Q31 ) && ( hPHA->p_curr_taps_fx[0] != NULL ) ) ) + { + /* IPDn */ + + set32_fx( &( Pr[freq_ipd_max] ), MAX_32, sub( nsbd, freq_ipd_max ) ); + set32_fx( &( Pi[freq_ipd_max] ), 0, sub( nsbd, freq_ipd_max ) ); + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + hPHA->p_curr_taps_fx[n] = hPHA->curr_taps_fx[n]; + } + + rfft_pha_buf[0] = ONE_IN_Q22; + move32(); + rfft_pha_buf[1] = ONE_IN_Q22; + move32(); + + ild_cnt = 0; + move16(); + isd_rate = BASOP_Util_Divide1616_Scale( isd_cnt_l, freq_8k, &isd_rate_e ); + isd_rate = shl_r( isd_rate, isd_rate_e ); // Q15 + FOR( i = 1; i < nsbd; i++ ) + { + // rfft_pha_buf[i * 2] = (float) sqrt( ( 1.0f + Pr[i] ) / 2.0f ); + L_tmp = L_add( ONE_IN_Q30, L_shr( Pr[i], 1 ) ); + L_tmp_e = 0; + move16(); + L_tmp = Sqrt32( L_tmp, &L_tmp_e ); + rfft_pha_buf[i * 2] = L_shl_r( L_tmp, sub( L_tmp_e, 9 ) ); // Q22 + move32(); + // rfft_pha_buf[i * 2 + 1] = (float) sqrt( ( 1.0f - Pr[i] ) / 2.0f ) * sign( Pi[i] ); + L_tmp = L_sub_sat( ONE_IN_Q30, L_shr( Pr[i], 1 ) ); // saturating as Pr does not exceed 1.0f + L_tmp_e = 0; + move16(); + L_tmp = Sqrt32( L_tmp, &L_tmp_e ); + rfft_pha_buf[i * 2 + 1] = imult3216( L_shl_r( L_tmp, sub( L_tmp_e, 9 ) ), sign_fx( Pi[i] ) ); // Q22 + move32(); + IF( GT_16( isd_rate, STEREO_DMX_EVS_ISD_DIST_THRES_IPD_Q15 ) ) + { + // rfft_pha_buf[i * 2 + 1] = (float) sqrt( ( 1.0f - rfft_pha_buf[i * 2] ) / 2.0f ) * sign( rfft_pha_buf[i * 2 + 1] ); + L_tmp = L_sub( ONE_IN_Q21, L_shr( rfft_pha_buf[i * 2], 1 ) ); + L_tmp_e = 9; + move16(); + L_tmp = Sqrt32( L_tmp, &L_tmp_e ); + rfft_pha_buf[i * 2 + 1] = imult3216( L_shl_r( L_tmp, sub( L_tmp_e, 9 ) ), sign_fx( rfft_pha_buf[i * 2 + 1] ) ); // Q22 + move32(); + // rfft_pha_buf[i * 2] = (float) sqrt( ( 1.0f + rfft_pha_buf[i * 2] ) / 2.0f ); + L_tmp = L_add( ONE_IN_Q21, L_shr( rfft_pha_buf[i * 2], 1 ) ); + L_tmp_e = 9; + move16(); + L_tmp = Sqrt32( L_tmp, &L_tmp_e ); + rfft_pha_buf[i * 2] = L_shl_r( L_tmp, sub( L_tmp_e, 9 ) ); // Q22 + move32(); + } + + // if ( ( tEr[i] > STEREO_DMX_EVS_LR_EGY * tEl[i] ) || ( tEl[i] > STEREO_DMX_EVS_LR_EGY * tEr[i] ) ) + test(); + IF( BASOP_Util_Cmp_Mant32Exp( tEr[i], tEr_e[i], Mpy_32_32_r( STEREO_DMX_EVS_LR_EGY_Q27, tEl[i] ), add( 4, tEl_e[i] ) ) > 0 || BASOP_Util_Cmp_Mant32Exp( tEl[i], tEl_e[i], Mpy_32_32_r( STEREO_DMX_EVS_LR_EGY_Q27, tEr[i] ), add( 4, tEr_e[i] ) ) > 0 ) + { + ild_cnt = add( ild_cnt, 1 ); + tEr[i] = MAX_32; + move32(); + tEr_e[i] = 0; + move16(); + } + ELSE + { + tEr[i] = MIN_32; + move32(); + tEr_e[i] = 0; + move16(); + } + } + IF( GT_16( ild_cnt, mult_r( nsbd, STEREO_DMX_EVS_ILD_PRC_Q15 ) ) ) + { + FOR( i = 1; i < nsbd; i++ ) + { + IF( tEr[i] > 0 ) + { + rfft_pha_buf[i * 2] = ONE_IN_Q22; + move32(); + rfft_pha_buf[i * 2 + 1] = 0; + move32(); + } + } + } + + rfft_fx( rfft_pha_buf, hPHA->rfft_ipd_coef_fx, input_frame_pha, +1 ); + // mvr2r( rfft_pha_buf, hPHA->p_curr_taps[1], hPHA->pha_len ); + Copy_Scale_sig32( rfft_pha_buf, hPHA->p_curr_taps_fx[1], hPHA->pha_len, 9 ); // Q22->Q31 + + /* PHA L2R */ + p_curr_taps = hPHA->p_curr_taps_fx[0]; + p_curr_taps[0] = L_shl( rfft_pha_buf[0], 9 ); // Q22->Q31 + move32(); + FOR( i = 1; i < hPHA->pha_len; i++ ) + { + p_curr_taps[i] = L_shl( rfft_pha_buf[input_frame_pha - i], 9 ); // Q22->Q31 + move32(); + } + } + ELSE + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + hPHA->p_curr_taps_fx[n] = NULL; + } + } + } + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + IF( hPHA->p_curr_taps_fx[n] ) + { + FOR( i = 0; i < hPHA->pha_len; i++ ) + { + // hPHA->p_curr_taps[n][i] *= hPHA->win[i]; + hPHA->p_curr_taps_fx[n][i] = L_shl( Mpy_32_16_1( hPHA->p_curr_taps_fx[n][i], hPHA->win_fx[i] ), 1 ); // Q31 + move32(); + } + + energy = 0; + move32(); + energy_e = 0; + move16(); + FOR( i = 0; i < hPHA->pha_len; i++ ) + { + energy = BASOP_Util_Add_Mant32Exp( energy, energy_e, Mpy_32_32_r( hPHA->p_curr_taps_fx[n][i], hPHA->p_curr_taps_fx[n][i] ), 0, &energy_e ); + } + // energy = (float) inv_sqrt( energy + EPSILON ); + energy = BASOP_Util_Add_Mant32Exp( energy, energy_e, EPSILON_FX_M, EPSILON_FX_E, &energy_e ); + energy = ISqrt32( energy, &energy_e ); + FOR( i = 0; i < hPHA->pha_len; i++ ) + { + hPHA->p_curr_taps_fx[n][i] = L_shl_r( Mpy_32_32_r( hPHA->p_curr_taps_fx[n][i], energy ), energy_e ); // Q31 + move32(); + } + } + } + + + rfft_buf[0] = L_shr_r( specPOr[0], 10 ); // Q31->Q21 + move32(); + rfft_buf[1] = L_shr_r( specPOr[n0], 10 ); // Q31->Q21 + move32(); + FOR( i = 1; i < n0; i++ ) + { + rfft_buf[i * 2] = L_shr_r( specPOr[i], 10 ); // Q31->Q21 + move32(); + rfft_buf[i * 2 + 1] = L_shr_r( specPOi[i], 10 ); // Q31->Q21 + move32(); + } + + rfft_fx( rfft_buf, rfft_coef, input_frame, +1 ); + scale_sig32( rfft_buf, input_frame, 10 ); // Q21->Q31 + + tmp1 = rfft_buf[0]; + move32(); + tmpPOC1[n0] = Mpy_32_32_r( tmp1, tmp1 ); + move32(); + + FOR( i = 1; i < hPOC->shift_limit + 1; i++ ) + { + n1 = add( n0, i ); + n2 = sub( n0, i ); + + tmp1 = rfft_buf[i]; + move32(); + tmpPOC1[n1] = Mpy_32_32_r( tmp1, tmp1 ); + move32(); + + tmp1 = rfft_buf[input_frame - i]; + move32(); + tmpPOC1[n2] = Mpy_32_32_r( tmp1, tmp1 ); + move32(); + } + + tmp1 = L_shl( Mpy_32_32_r( STEREO_DMX_EVS_POC_SMOOTH_Q30, tmpPOC1[n0] ) + Mpy_32_32_r( -ONE_IN_Q28 /*0.5f * ( 1.0f - STEREO_DMX_EVS_POC_SMOOTH )*/, L_add( L_shr( tmpPOC1[n0 - 1], 1 ), L_shr( tmpPOC1[n0 + 1], 1 ) ) ), 1 ); // Q31 + tmpPOC2[n0] = L_max( tmp1, 0 ); + move32(); + + FOR( i = 1; i < hPOC->shift_limit; i++ ) + { + n1 = add( n0, i ); + n2 = sub( n0, i ); + // tmp1 = STEREO_DMX_EVS_POC_SMOOTH * tmpPOC1[n1] + 0.5f * ( 1.0f - STEREO_DMX_EVS_POC_SMOOTH ) * ( tmpPOC1[n1 - 1] + tmpPOC1[n1 + 1] ); + tmp1 = L_shl( Mpy_32_32_r( STEREO_DMX_EVS_POC_SMOOTH_Q30, tmpPOC1[n1] ) + Mpy_32_32_r( -ONE_IN_Q28 /*0.5f * ( 1.0f - STEREO_DMX_EVS_POC_SMOOTH )*/, L_add( L_shr( tmpPOC1[n1 - 1], 1 ), L_shr( tmpPOC1[n1 + 1], 1 ) ) ), 1 ); // Q31 + // tmp2 = STEREO_DMX_EVS_POC_SMOOTH * tmpPOC1[n2] + 0.5f * ( 1.0f - STEREO_DMX_EVS_POC_SMOOTH ) * ( tmpPOC1[n2 - 1] + tmpPOC1[n2 + 1] ); + tmp2 = L_shl( Mpy_32_32_r( STEREO_DMX_EVS_POC_SMOOTH_Q30, tmpPOC1[n2] ) + Mpy_32_32_r( -ONE_IN_Q28 /*0.5f * ( 1.0f - STEREO_DMX_EVS_POC_SMOOTH )*/, L_add( L_shr( tmpPOC1[n2 - 1], 1 ), L_shr( tmpPOC1[n2 + 1], 1 ) ) ), 1 ); // Q31 + tmpPOC2[n1] = L_max( tmp1, 0 ); + move32(); + tmpPOC2[n2] = L_max( tmp2, 0 ); + move32(); + } + + P[n0] = L_add( Mpy_32_32_r( P[n0], STEREO_DMX_EVS_POC_FORGETTING_Q31 ), Mpy_32_32_r( tmpPOC2[n0], MAX_32 - STEREO_DMX_EVS_POC_FORGETTING_Q31 ) ); + move32(); + + FOR( i = 1; i < hPOC->shift_limit; i++ ) + { + n1 = add( n0, i ); + n2 = sub( n0, i ); + + IF( EQ_16( i, negate( itdLR[1] ) ) ) + { + P[n1] = L_add( Mpy_32_32_r( P[n1], STEREO_DMX_EVS_TARGET_POC_FORGETTING_Q31 ), Mpy_32_32_r( tmpPOC2[n1], MAX_32 - STEREO_DMX_EVS_TARGET_POC_FORGETTING_Q31 ) ); + move32(); + } + ELSE + { + P[n1] = L_add( Mpy_32_32_r( P[n1], STEREO_DMX_EVS_POC_FORGETTING_Q31 ), Mpy_32_32_r( tmpPOC2[n1], MAX_32 - STEREO_DMX_EVS_POC_FORGETTING_Q31 ) ); + move32(); + } + + IF( EQ_16( i, itdLR[0] ) ) + { + P[n2] = L_add( Mpy_32_32_r( P[n2], STEREO_DMX_EVS_TARGET_POC_FORGETTING_Q31 ), Mpy_32_32_r( tmpPOC2[n2], MAX_32 - STEREO_DMX_EVS_TARGET_POC_FORGETTING_Q31 ) ); + move32(); + } + ELSE + { + P[n2] = L_add( Mpy_32_32_r( P[n2], STEREO_DMX_EVS_POC_FORGETTING_Q31 ), Mpy_32_32_r( tmpPOC2[n2], MAX_32 - STEREO_DMX_EVS_POC_FORGETTING_Q31 ) ); + move32(); + } + } + + return; +} +#else static void calc_poc( STEREO_DMX_EVS_POC_HANDLE hPOC, /* i/o: phase only correlation structure */ STEREO_DMX_EVS_PHA_HANDLE hPHA, /* i/o: correlation filter structure */ @@ -726,16 +1732,307 @@ static void calc_poc( } } - return; -} + return; +} +#endif + + +/*-------------------------------------------------------------------* + * find_poc_peak() + * + * find peak phase only correlation + *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static Word32 find_poc_peak_fx( + STEREO_DMX_EVS_POC_HANDLE hPOC, /* i/o: phase only correlation structure */ + Word32 itd_fx[], /* o : estimated itd */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word32 ratio_fixed /* i : adapting ratio */ +) +{ + Word16 itd_cand[CPE_CHANNELS], i, n, cnt[CPE_CHANNELS], Lh, peak_range, *on, *itdLR, prev_off[CPE_CHANNELS], eps_fx; + Word32 Q_fx[CPE_CHANNELS], aQ_fx[CPE_CHANNELS], cQ_fx[CPE_CHANNELS], width_fx, *peak_width_fx, *peakQ_fx, cconfidence_fx, *P_fx, tmpf_fx, eps2_fx; + Word16 tmpf_e = 0, eps2_e = 0, Q_e[CPE_CHANNELS], eps_e = 15, peakQ_e[CPE_CHANNELS]; + move16(); + move16(); + move16(); + + /* Initialization */ + Lh = shr( input_frame, 1 ); + on = hPOC->ispeak; + itdLR = hPOC->itdLR; + itd_cand[0] = itd_cand[1] = 0; + move16(); + move16(); + move16(); + move16(); + + width_fx = 816043776; /*0.38f in Q31*/ + eps_fx = Inv16( input_frame, &eps_e ); + peak_width_fx = hPOC->peak_width_fx; + peakQ_fx = hPOC->peakQ_fx; // Q16 + move16(); + move16(); + move16(); + set16_fx( peakQ_e, 31 - Q16, CPE_CHANNELS ); + Q_fx[0] = hPOC->P_fx[Lh]; // Q31 + Q_fx[1] = 0; + move16(); + move16(); + set16_fx( Q_e, 0, CPE_CHANNELS ); // Q31 + + P_fx = hPOC->P_fx; + + FOR( i = 1; i < hPOC->shift_limit; i++ ) /*find peaks of POC P[] with positive and negative ITD */ + { + IF( GT_32( P_fx[Lh - i], Q_fx[0] ) ) + { + Q_fx[0] = P_fx[Lh - i]; // Q31 + itd_cand[0] = i; + Q_e[0] = 0; + move32(); + move16(); + move16(); + } + IF( GT_32( P_fx[Lh + i], Q_fx[1] ) ) + { + Q_fx[1] = P_fx[Lh + i]; // Q31 + itd_cand[1] = -i; + Q_e[1] = 0; + move32(); + move16(); + move16(); + } + } + + Word16 tmp1, tmp11, tmp_var1, tmp12 = 0, tmp13; + Word32 tmp4, tmp5, tmp6, tmp7, tmp8, tmp9, tmp10, tmp14, tmp15, tmp16; + Word16 tmp8_e, tmp9_e, tmp10_e, tmp11_e, tmp12_e, tmp13_e, tmp15_e; + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + prev_off[n] = !on[n]; + move16(); + + cnt[n] = 0; + aQ_fx[n] = Mpy_32_32( Q_fx[n], width_fx ); // Q31+Q31 - 31 + cQ_fx[n] = P_fx[Lh - itd_cand[n]]; // Q31 + move16(); + move16(); + move16(); + + tmp12 = 0, tmp8_e = 0, tmp9_e = 0, tmp10_e = 0, tmp11_e = 0, tmp12_e = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + + /*compute peak_range*/ + tmp1 = idiv1616( hPOC->shift_limit, STEREO_DMX_EVS_FIND_POC_PEAK_TAU ); + peak_range = idiv1616( add( (Word16) abs( itd_cand[n] ), tmp1 ), STEREO_DMX_EVS_FIND_POC_PEAK_TAU2 ); // Q0 + + FOR( i = 1; i <= peak_range; i++ ) + { + cnt[n] = add( cnt[n], extract_l( L_add( GT_32( P_fx[Lh - itd_cand[n] + i], aQ_fx[n] ), GT_32( P_fx[Lh - itd_cand[n] - i], aQ_fx[n] ) ) ) ); + tmp4 = L_add( P_fx[Lh - itd_cand[n] + i], P_fx[Lh - itd_cand[n] - i] ); // Q31 + cQ_fx[n] = L_add( cQ_fx[n], tmp4 ); + move16(); + move16(); + } + + /*compute eps2_fx*/ + tmp5 = Mpy_32_32( peak_width_fx[n], ratio_fixed ); // Q31 + Q16 - Q31 + tmp6 = Mpy_32_32( L_deposit_h( cnt[n] ), L_sub( ONE_IN_Q31, ratio_fixed ) ); // Q16 + Q31 - 31 + peak_width_fx[n] = L_add( tmp5, tmp6 ); // Q16 + move16(); + + tmp7 = Mpy_32_32( L_deposit_h( eps_fx ), peak_width_fx[n] ); // eps_e + 31 - Q16 + + eps2_fx = L_shr( tmp7, 2 ); + eps2_e = add( eps_e, 31 - Q16 ); + + /*compute Q_fx[n]*/ + tmp8 = BASOP_Util_Add_Mant32Exp( Q_fx[n], 0, eps2_fx, eps2_e, &tmp8_e ); + tmp_var1 = BASOP_Util_Divide3232_Scale( cQ_fx[n], L_deposit_h( ( add( shl( peak_range, 1 ), 1 ) ) ) /*Q16*/, &tmp9_e ); + tmp9_e = sub( tmp9_e, ( 31 - Q16 ) ); + tmp9 = L_deposit_h( tmp_var1 ); + tmp10 = BASOP_Util_Add_Mant32Exp( tmp9, tmp9_e, eps2_fx, eps2_e, &tmp10_e ); + tmp11 = BASOP_Util_Divide3232_Scale( tmp10, tmp8, &tmp11_e ); + tmp11_e = add( tmp11_e, sub( tmp10_e, tmp8_e ) ); + tmp12_e = BASOP_Util_Add_MantExp( ONE_IN_Q14, 1, negate( tmp11 ), tmp11_e, &tmp12 ); + + Q_fx[n] = L_deposit_h( tmp12 ); + Q_e[n] = tmp12_e; + Q_fx[n] = L_max( Q_fx[n], 0 ); + move16(); + move16(); + move16(); + if ( Q_fx[n] == 0 ) + { + Q_e[n] = 0; + move16(); + } + + IF( on[n] ) /*if channel n was active (likely to be preceding) in the previous frame*/ + { + tmp13_e = 0, tmp15_e = 0; + tmp13 = BASOP_Util_Divide1616_Scale( (Word16) abs( itd_cand[n] ), hPOC->shift_limit, &tmp13_e ); + tmp14 = L_mult( 6554 /*0.2f Q15*/, tmp13 ); // tmp13_e + tmp15 = BASOP_Util_Add_Mant32Exp( 644245120 /*0.75f in Q31*/, 0, L_negate( tmp14 ), tmp13_e, &tmp15_e ); + tmp15 = Mpy_32_32( tmp15, peakQ_fx[n] ); // tmp15_e + peakQ_e[n] + move16(); + move16(); + + tmpf_fx = tmp15; + move16(); + tmpf_e = add( tmp15_e, peakQ_e[n] ); + + Word16 flag1 = BASOP_Util_Cmp_Mant32Exp( Q_fx[n], Q_e[n], tmpf_fx, tmpf_e ); + tmp16 = Mpy_32_32( 1342177280 /*1.25f in Q30*/, peakQ_fx[n] ); // peakQ_e[n]+1 + Word16 flag2 = BASOP_Util_Cmp_Mant32Exp( Q_fx[n], Q_e[n], tmp16, peakQ_e[n] + 1 ); + + IF( EQ_16( flag1, negate( 1 ) ) ) + { + itdLR[n] = 0; + on[n] = 0; + peakQ_fx[n] = 0; + peakQ_e[n] = 0; + Q_fx[n] = 0; + Q_e[n] = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + } + ELSE IF( EQ_16( flag2, 1 ) ) + { + itdLR[n] = itd_cand[n]; + move16(); + } + Word16 flag3 = BASOP_Util_Cmp_Mant32Exp( peakQ_fx[n], peakQ_e[n], Q_fx[n], Q_e[n] ); + IF( EQ_16( flag3, negate( 1 ) ) ) + { + peakQ_fx[n] = Q_fx[n]; + peakQ_e[n] = Q_e[n]; + move16(); + move16(); + } + } + ELSE /*if channel n was not active (not likely to be preceding) in the previous frame*/ + { + tmp13_e = 0, tmp15_e = 0; + move16(); + move16(); + tmp13 = BASOP_Util_Divide1616_Scale( (Word16) abs( itd_cand[n] ), hPOC->shift_limit, &tmp13_e ); + tmp14 = L_mult( 6554 /*0.2f Q15*/, tmp13 ); // tmp13_e + tmp15 = BASOP_Util_Add_Mant32Exp( 1610612736 /*0.75f in Q31*/, 0, L_negate( tmp14 ), tmp13_e, &tmp15_e ); + + tmpf_fx = tmp15; + tmpf_e = tmp15_e; + move16(); + move16(); + + Word16 flag1 = BASOP_Util_Cmp_Mant32Exp( Q_fx[n], Q_e[n], tmpf_fx, tmpf_e ); + + IF( EQ_16( flag1, negate( 1 ) ) ) + { + itdLR[n] = 0; + Q_fx[n] = 0; + } + ELSE + { + itdLR[n] = itd_cand[n]; + on[n] = 1; + } + move16(); + move16(); + } + } + + Word32 var0, var1, var2, var3; + Word16 var0_e = 0, var1_e = 0, var2_e = 0, var3_e = 0; + Word16 var0_flag, var1_flag, var2_flag, var3_flag; + move16(); + move16(); + move16(); + move16(); + var0 = BASOP_Util_Add_Mant32Exp( Q_fx[0], Q_e[0], L_negate( 214748368 /*0.1 in Q31*/ ), 0, &var0_e ); + var1 = BASOP_Util_Add_Mant32Exp( Q_fx[1], Q_e[1], L_negate( 214748368 /*0.1 in Q31*/ ), 0, &var1_e ); + var2 = BASOP_Util_Add_Mant32Exp( Q_fx[1], Q_e[1], Q_BAND_FX, 0, &var2_e ); + var3 = BASOP_Util_Add_Mant32Exp( Q_fx[0], Q_e[0], Q_BAND_FX, 0, &var3_e ); + + /*flags for condtional checks*/ + var0_flag = BASOP_Util_Cmp_Mant32Exp( Q_fx[0], Q_e[0], var1, var1_e ); + var1_flag = BASOP_Util_Cmp_Mant32Exp( Q_fx[1], Q_e[1], var0, var0_e ); + var2_flag = BASOP_Util_Cmp_Mant32Exp( Q_fx[0], Q_e[0], var2, var2_e ); + var3_flag = BASOP_Util_Cmp_Mant32Exp( Q_fx[1], Q_e[1], var3, var3_e ); + + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( on[0] && prev_off[0] ) && ( on[1] && prev_off[1] ) ) /*if both channels have newly detected as active (possibility of preceding), select channel by peakness Q[] of POC */ + { + *itd_fx = ( GT_32( Q_fx[0], Q_fx[1] ) ) ? itdLR[0] : itdLR[1]; + } + ELSE IF( ( on[0] && prev_off[0] ) && ( EQ_16( var0_flag, 1 ) ) ) /* if channel 0 becomes active, select channel 0*/ + { + *itd_fx = itdLR[0]; + } + ELSE IF( ( on[1] && prev_off[1] ) && ( EQ_16( var1_flag, 1 ) ) ) /*if channel 1 becomes active, selsect channel 1*/ + { + *itd_fx = itdLR[1]; + } + ELSE IF( EQ_16( var2_flag, 1 ) ) /* if no status change, use Q[]*/ + { + *itd_fx = itdLR[0]; + } + ELSE IF( EQ_16( var3_flag, 1 ) ) /* if no status change, use Q[]*/ + { + *itd_fx = itdLR[1]; + } + ELSE IF( *itd_fx == 0 ) /*if no channels are likely to be preceding, follow the status of the previous frame*/ + { + *itd_fx = 0; + } + ELSE /*follow the status of the previous frame*/ + { + *itd_fx = ( *itd_fx > 0 ) ? itdLR[0] : itdLR[1]; + } + + move32(); + FOR( i = 0; i < CPE_CHANNELS; i++ ) + { + Q_fx[i] = L_shr( Q_fx[i], negate( Q_e[i] ) ); // Q31 + move32(); + } + FOR( i = 0; i < CPE_CHANNELS; i++ ) + { + peakQ_fx[i] = L_shr( peakQ_fx[i], sub( 15, peakQ_e[i] ) ); // Q16 + move32(); + } -/*-------------------------------------------------------------------* - * find_poc_peak() - * - * find peak phase only correlation - *-------------------------------------------------------------------*/ + Word16 Q_sub_sqrt_e = 0; + Word32 Q_sub_sqrt = Sqrt32( L_abs( L_sub( Q_fx[0], Q_fx[1] ) ), &Q_sub_sqrt_e ); + cconfidence_fx = Q_sub_sqrt; + move16(); + move16(); + + Word32 cconfidence_var1 = Mpy_32_32( hPOC->confidence_fx, STEREO_DMX_EVS_CORR_FORGETTING_FX ); // Q31 + Word32 cconfidence_var2 = Mpy_32_32( L_shr( cconfidence_fx, negate( Q_sub_sqrt_e ) ) /*Q31*/, L_sub( ONE_IN_Q30, L_shr( STEREO_DMX_EVS_CORR_FORGETTING_FX, 1 ) ) ); // Q30 + hPOC->confidence_fx = L_add( cconfidence_var1, L_shl( cconfidence_var2, 1 ) ); // Q31 + move16(); + return hPOC->confidence_fx; +} +#else static float find_poc_peak( STEREO_DMX_EVS_POC_HANDLE hPOC, /* i/o: phase only correlation structure */ float itd[], /* o : estimated itd */ @@ -863,13 +2160,90 @@ static float find_poc_peak( return hPOC->confidence = hPOC->confidence * STEREO_DMX_EVS_CORR_FORGETTING + cconfidence * ( 1.0f - STEREO_DMX_EVS_CORR_FORGETTING ); } - +#endif /*-------------------------------------------------------------------* * estimate_itd() * * estimate itd *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static ivas_error estimate_itd_fx( + Word16 *corr, /* o : correlation */ + STEREO_DMX_EVS_POC_HANDLE hPOC, /* i/o: phase only correlation structure */ + STEREO_DMX_EVS_PHA_HANDLE hPHA, /* i/o: correlation filter structure */ + const Word32 srcL[], /* i : Lch input signal Q16 */ + const Word32 srcR[], /* i : Rch input signal Q16 */ + Word32 itd[], /* o : estimated itd Q16 */ + const Word16 input_frame /* i : input frame length per channel */ +) +{ + Word32 specLr[L_FRAME48k / 2 + 1], specLi[L_FRAME48k / 2 + 1], specRr[L_FRAME48k / 2 + 1], specRi[L_FRAME48k / 2 + 1]; + Word16 rfft_coef[L_FRAME48k]; + const Word16 *p_w; + Word16 n, n0, n1; + Word16 rfft_coef_step; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + n0 = shr( input_frame, 1 ); + n1 = shr( input_frame, 2 ); + + IF( EQ_16( input_frame, L_FRAME16k ) ) + { + p_w = dft_trigo_32k_fx; + rfft_coef_step = 4; + move16(); + } + ELSE IF( EQ_16( input_frame, L_FRAME32k ) ) + { + p_w = dft_trigo_32k_fx; + rfft_coef_step = 2; + move16(); + } + ELSE IF( EQ_16( input_frame, L_FRAME48k ) ) + { + p_w = dft_trigo_48k_fx; + rfft_coef_step = 2; + move16(); + } + ELSE + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "failed estimate_itd()\n" ); + } + + FOR( n = 0; n < n1; n++ ) + { + rfft_coef[n] = p_w[n * rfft_coef_step]; + move16(); + rfft_coef[n0 - n] = p_w[n * rfft_coef_step]; + move16(); + } + rfft_coef[n1] = p_w[n1 * rfft_coef_step]; + move16(); + + Word16 specL_e, specR_e, spec_e; + estimate_itd_wnd_fft_fx( srcL, specLr, specLi, &specL_e, rfft_coef, hPOC->wnd_fx, input_frame ); + estimate_itd_wnd_fft_fx( srcR, specRr, specRi, &specR_e, rfft_coef, hPOC->wnd_fx, input_frame ); + + spec_e = s_max( sub( specL_e, s_min( getScaleFactor32( specLr, input_frame / 2 + 1 ), getScaleFactor32( specLi, input_frame / 2 + 1 ) ) ), + sub( specR_e, s_min( getScaleFactor32( specRr, input_frame / 2 + 1 ), getScaleFactor32( specRi, input_frame / 2 + 1 ) ) ) ); + spec_e = add( spec_e, 2 ); // guard bits + scale_sig32( specLr, input_frame / 2 + 1, sub( specL_e, spec_e ) ); + scale_sig32( specLi, input_frame / 2 + 1, sub( specL_e, spec_e ) ); + scale_sig32( specRr, input_frame / 2 + 1, sub( specR_e, spec_e ) ); + scale_sig32( specRi, input_frame / 2 + 1, sub( specR_e, spec_e ) ); + + calc_poc_fx( hPOC, hPHA, hPOC->wnd_fx, rfft_coef, specLr, specLi, specRr, specRi, spec_e, input_frame ); + + *corr = round_fx( find_poc_peak_fx( hPOC, itd, input_frame, STEREO_DMX_EVS_POC_W_FORGETTING_FX ) ); + move16(); + + return error; +} +#else static ivas_error estimate_itd( float *corr, /* o : correlation */ @@ -924,18 +2298,49 @@ static ivas_error estimate_itd( estimate_itd_wnd_fft( srcR, specRr, specRi, rfft_coef, hPOC->wnd, input_frame ); calc_poc( hPOC, hPHA, hPOC->wnd, rfft_coef, specLr, specLi, specRr, specRi, input_frame ); + *corr = find_poc_peak( hPOC, itd, input_frame, STEREO_DMX_EVS_POC_W_FORGETTING ); return error; } - +#endif /*-------------------------------------------------------------------* * weighted_ave() * * create weighted downmix signal *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void weighted_ave_fx( + const Word32 src1_fx[], /* i : Lch input signal Q16 */ + const Word32 src2_fx[], /* i : Rch input signal Q16 */ + Word32 dst_fx[], /* o : output signal Q16 */ + const Word32 gain_fx, /* i : adapting gain Q31 */ + const Word32 old_gain_fx, /* i : adapting prev gain Q31 */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word32 wnd_fx[] /* i : window coef Q31 */ +) +{ + Word16 i, len; + Word32 gain_tmp_fx = 0, gain_sub_fx; + move32(); + len = shr( input_frame, 4 ); + gain_sub_fx = L_sub( gain_fx, old_gain_fx ); + FOR( i = 0; i < len; i++ ) + { + gain_tmp_fx = L_add( old_gain_fx, Mpy_32_32( gain_sub_fx, wnd_fx[i] ) ); // Q31 + dst_fx[i] = L_add_sat( Mpy_32_32( src1_fx[i], gain_tmp_fx ), Mpy_32_32( src2_fx[i], L_sub( MAX_32, gain_tmp_fx ) ) ); // Q16 + move32(); + } + FOR( ; i < input_frame; i++ ) + { + dst_fx[i] = L_add_sat( Mpy_32_32( src1_fx[i], gain_fx ), Mpy_32_32( src2_fx[i], L_sub( MAX_32, gain_tmp_fx ) ) ); // Q16 + move32(); + } + return; +} +#else static void weighted_ave( const float src1[], /* i : Lch input signal */ const float src2[], /* i : Rch input signal */ @@ -965,13 +2370,89 @@ static void weighted_ave( return; } - +#endif /*-------------------------------------------------------------------* * calc_energy() * * calculate energy *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void calc_energy_fx( + const Word32 src1_fx[], /* i : Lch input signal Q16*/ + const Word32 src2_fx[], /* i : Rch input signal Q16 */ + Word32 energy_fx[], /* o : calculated energy energy_fx_e*/ + Word16 *energy_fx_e, /* o : calculated energy */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word32 ratio_float_fx // Q31 +) +{ + Word32 E_32_fx, wnd_fx, wnd_diff_fx; + Word16 i, adaptlen; + Word64 E_fx; + /* Initialization */ + E_fx = 0; + move32(); + adaptlen = shr( input_frame, 4 ); + // wnd = 0.5f / (float) adaptlen; adaptlen= 20;in Q31 + wnd_fx = 53687091; // initialising for L_FRAME16k =( 0.5f /20) in Q31; + move32(); + wnd_diff_fx = 107374182; // initialising for L_FRAME16k =( 1.0f /20) in Q31; + move32(); + switch ( input_frame ) + { + case L_FRAME16k: + wnd_fx = 53687091; // wnd = 0.5f / (float) adaptlen; adaptlen= 20;in Q31 + wnd_diff_fx = 107374182; // wnd = 1.0f / (float) adaptlen;adaptlen= 20;in Q31 + break; + case L_FRAME32k: + wnd_fx = 26843545; // wnd = 0.5f / (float) adaptlen; adaptlen= 40;in Q31 + wnd_diff_fx = 53687091; // wnd = 1.0f / (float) adaptlen;adaptlen= 40;in Q31 + break; + case L_FRAME48k: + wnd_fx = 17895697; // wnd = 0.5f / (float) adaptlen; adaptlen= 60;in Q31 + wnd_diff_fx = 35791394; // wnd = 1.0f / (float) adaptlen;adaptlen= 60;in Q31 + break; + } + move32(); + move32(); + // wnd = 0.5f / (float) adaptlen; + // wnd_diff = 1.0f / (float) adaptlen; + Word16 gb = find_guarded_bits_fx( input_frame ); + wnd_fx = L_shr( wnd_fx, gb ); + wnd_diff_fx = L_shr( wnd_diff_fx, gb ); + FOR( i = 0; i < adaptlen; i++ ) + { + // E += ( src1[i] * wnd ) * ( src2[i] * wnd ); + E_fx = W_add( E_fx, W_mult0_32_32( Mpy_32_32( src1_fx[i], wnd_fx ), Mpy_32_32( src2_fx[i], wnd_fx ) ) ); // 2*(Q16-gb) + + // wnd += wnd_diff; + wnd_fx = L_add( wnd_fx, wnd_diff_fx ); + } + FOR( ; i < input_frame - adaptlen; i++ ) + { + // E += src1[i] * src2[i]; + E_fx = W_add( E_fx, W_shr( W_mult0_32_32( src1_fx[i], src2_fx[i] ), shl( gb, 1 ) ) ); + } + FOR( ; i < input_frame; i++ ) + { + // wnd -= wnd_diff; + wnd_fx = L_sub( wnd_fx, wnd_diff_fx ); + + // E += ( src1[i] * wnd ) * ( src2[i] * wnd ); + E_fx = W_add( E_fx, W_mult0_32_32( Mpy_32_32( src1_fx[i], wnd_fx ), Mpy_32_32( src2_fx[i], wnd_fx ) ) ); // 2*(Q16-gb) + } + Word16 lshift = W_norm( E_fx ); + E_32_fx = W_extract_h( W_shl( E_fx, lshift ) ); // 2*(Q16-gb)+lshift -32 + Word16 q_E = sub( add( shl( sub( Q16, gb ), 1 ), lshift ), 32 ); + Word16 temp_e, q_temp32; + Word32 temp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( E_32_fx, input_frame, &temp_e ) ); // Q_E +(15-temp_e) + 16 + q_temp32 = add( add( q_E, sub( 15, temp_e ) ), 16 ); + // *energy = *energy * ratio_float + ( E / (float) input_frame ) * ( 1.0f - ratio_float ); + *energy_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( *energy_fx, ratio_float_fx ), *energy_fx_e, Mpy_32_32( temp32, L_sub( MAX_32, ratio_float_fx ) ), sub( 31, q_temp32 ), energy_fx_e ); + return; +} +#else static void calc_energy( const float src1[], /* i : Lch input signal */ const float src2[], /* i : Rch input signal */ @@ -1010,14 +2491,47 @@ static void calc_energy( return; } - +#endif /*-------------------------------------------------------------------* * adapt_gain() * * adapt gain to the signal *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void adapt_gain_fx( + const Word32 src_fx[], /* i : input signal Q16 */ + Word32 dst_fx[], /* o : output signal */ + const Word32 gain_fx, /* i : adapting gain Q31*/ + const Word32 old_gain_fx, /* i : adapting prev gain Q31*/ + const Word16 input_frame, /* i : input frame length per channel */ + const Word32 wnd_fx[] /* i : window coef Q31 */ +) +{ + Word16 i, len; + Word32 gain_tmp_fx, gain_sub_fx; + + len = shr( input_frame, 4 ); + // gain_sub = gain - old_gain; + gain_sub_fx = L_sub( gain_fx, old_gain_fx ); // Q31 + + FOR( i = 0; i < len; i++ ) + { + // gain_tmp = old_gain + gain_sub * wnd[i]; + gain_tmp_fx = L_add( old_gain_fx, Mpy_32_32( gain_sub_fx, wnd_fx[i] ) ); // Q31 // dst[i] = src[i] * gain_tmp; + dst_fx[i] = Mpy_32_32( src_fx[i], gain_tmp_fx ); // Q16 + move32(); + } + FOR( ; i < input_frame; i++ ) + { + // dst[i] = src[i] * gain; + dst_fx[i] = Mpy_32_32( src_fx[i], gain_fx ); // Q16 + move32(); + } + return; +} +#else static void adapt_gain( const float src[], /* i : input signal */ float dst[], /* o : output signal */ @@ -1038,77 +2552,542 @@ static void adapt_gain( gain_tmp = old_gain + gain_sub * wnd[i]; dst[i] = src[i] * gain_tmp; } - for ( ; i < input_frame; i++ ) + for ( ; i < input_frame; i++ ) + { + dst[i] = src[i] * gain; + } + + return; +} +#endif + +/*-------------------------------------------------------------------* + * create_M_signal() + * + * create downmix signal + *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void create_M_signal_fx( + const Word32 srcL_fx[], /* i : Lch input signal Q16 */ + const Word32 srcR_fx[], /* i : Rch input signal Q16 */ + Word32 dmx_fx[], /* o : output signal Q31 */ + const Word32 w_curr_fx, /* i : adapting weight Q31 */ + const int16_t input_frame, /* i : input frame length per channel */ + const Word32 wnd_fx[], /* i : window coef Q31 */ + Word32 *w_prev_fx, /* i/o: adapting prev weight Q31*/ + Word32 *dmx_energy_fx, /* i/o: downmix signal energy dmx_energy_fx_e */ + Word16 *dmx_energy_fx_e, /* i/o: downmix signal energy */ + Word32 *src_energy_fx, /* i/o: input signal energy src_energy_fx_e */ + Word16 *src_energy_fx_e /* i/o: input signal energy */ +) +{ + Word32 amp_mod_fx[CPE_CHANNELS]; + Word32 weighted_fx[L_FRAME48k], Lbias_fx; + Word32 eps_fx, temp_32; + Word32 temp32_1, temp32_2; + Word16 temp_e; + Word16 temp_e_1, temp_e_2; + /* Initialization */ + eps_fx = 1024; // 1024.0f in Q0 + move32(); + Lbias_fx = ( w_prev_fx[2] == 0 ) ? 1073741824 : 67108864; // 4.0f in Q28 : 0.25f in Q28 + move32(); + weighted_ave_fx( srcL_fx, srcR_fx, dmx_fx, w_curr_fx, w_prev_fx[0], input_frame, wnd_fx ); + calc_energy_fx( srcL_fx, srcL_fx, src_energy_fx, src_energy_fx_e, input_frame, STEREO_DMX_EVS_DMX_EGY_FORGETTING_FX ); + calc_energy_fx( srcR_fx, srcR_fx, src_energy_fx + 1, src_energy_fx_e + 1, input_frame, STEREO_DMX_EVS_DMX_EGY_FORGETTING_FX ); + calc_energy_fx( dmx_fx, dmx_fx, dmx_energy_fx, dmx_energy_fx_e, input_frame, STEREO_DMX_EVS_DMX_EGY_FORGETTING_FX ); + + temp32_1 = Mpy_32_32( src_energy_fx[0], Lbias_fx ); // 31 - src_energy_fx_e + Q28-31 + temp_e_1 = add( src_energy_fx_e[0], 3 ); + Word16 flag = BASOP_Util_Cmp_Mant32Exp( temp32_1, temp_e_1, src_energy_fx[1], src_energy_fx_e[1] ); + // if ( src_energy[0] * Lbias > src_energy[1] ) + IF( EQ_16( flag, 1 ) ) + { + temp32_1 = BASOP_Util_Add_Mant32Exp( dmx_energy_fx[0], dmx_energy_fx_e[0], eps_fx, Q31, &temp_e_1 ); + temp32_2 = BASOP_Util_Add_Mant32Exp( src_energy_fx[0], src_energy_fx_e[0], eps_fx, Q31, &temp_e_2 ); + temp_32 = L_deposit_h( BASOP_Util_Divide3232_Scale( temp32_1, temp32_2, &temp_e ) ); // Q31-temp_e+temp_e_2-temp_e_1 + temp_e_1 = sub( add( temp_e, temp_e_1 ), temp_e_2 ); + // temp = sqrtf( ( dmx_energy[0] + eps ) / ( src_energy[0] + eps ) ); + temp32_1 = Sqrt32( temp_32, &temp_e_1 ); + // amp_mod[0] = 1.0f - sqrtf( ( dmx_energy[0] + eps ) / ( src_energy[0] + eps ) ); + amp_mod_fx[0] = L_shl( L_sub( ONE_IN_Q30, L_shl( temp32_1, sub( temp_e_1, 1 ) ) ), 1 ); + move32(); + amp_mod_fx[0] = L_max( amp_mod_fx[0], 0 ); + move32(); + amp_mod_fx[1] = 0; + move32(); + } + ELSE + { + temp32_1 = BASOP_Util_Add_Mant32Exp( dmx_energy_fx[0], dmx_energy_fx_e[0], eps_fx, Q31, &temp_e_1 ); + temp32_2 = BASOP_Util_Add_Mant32Exp( src_energy_fx[1], src_energy_fx_e[1], eps_fx, Q31, &temp_e_2 ); + temp_32 = L_deposit_h( BASOP_Util_Divide3232_Scale( temp32_1, temp32_2, &temp_e ) ); // Q31-temp_e+temp_e_2-temp_e_1 + temp_e_1 = sub( add( temp_e, temp_e_1 ), temp_e_2 ); + // amp_mod[1] = 1.0f - sqrtf( ( dmx_energy[0] + eps ) / ( src_energy[1] + eps ) ); + temp32_1 = Sqrt32( temp_32, &temp_e_1 ); + amp_mod_fx[1] = L_shl( L_sub( ONE_IN_Q30, L_shl( temp32_1, sub( temp_e_1, 1 ) ) ), 1 ); + move32(); + // amp_mod[1] = max( amp_mod[1], 0.0f ); + amp_mod_fx[1] = L_max( amp_mod_fx[1], 0 ); + move32(); + amp_mod_fx[0] = 0; + move32(); + } + adapt_gain_fx( srcL_fx, weighted_fx, amp_mod_fx[0], w_prev_fx[1], input_frame, wnd_fx ); + v_add_fx( dmx_fx, weighted_fx, dmx_fx, input_frame ); // Q16 + adapt_gain_fx( srcR_fx, weighted_fx, amp_mod_fx[1], w_prev_fx[2], input_frame, wnd_fx ); + v_add_fx( dmx_fx, weighted_fx, dmx_fx, input_frame ); // Q16 + w_prev_fx[0] = w_curr_fx; + move32(); + w_prev_fx[1] = amp_mod_fx[0]; + move32(); + w_prev_fx[2] = amp_mod_fx[1]; + move32(); + + return; +} + +#else +static void create_M_signal( + const float srcL[], /* i : Lch input signal */ + const float srcR[], /* i : Rch input signal */ + float dmx[], /* o : output signal */ + const float w_curr, /* i : adapting weight */ + const int16_t input_frame, /* i : input frame length per channel */ + const float wnd[], /* i : window coef */ + float *w_prev, /* i/o: adapting prev weight */ + float *dmx_energy, /* i/o: downmix signal energy */ + float *src_energy /* i/o: input signal energy */ +) +{ + float weighted[L_FRAME48k], eps, amp_mod[CPE_CHANNELS], Lbias; + + /* Initialization */ + eps = 1024.0f; + Lbias = ( w_prev[2] == 0 ) ? 4.0f : 0.25f; + + weighted_ave( srcL, srcR, dmx, w_curr, w_prev[0], input_frame, wnd ); + + calc_energy( srcL, srcL, src_energy, input_frame, STEREO_DMX_EVS_DMX_EGY_FORGETTING ); + calc_energy( srcR, srcR, src_energy + 1, input_frame, STEREO_DMX_EVS_DMX_EGY_FORGETTING ); + calc_energy( dmx, dmx, dmx_energy, input_frame, STEREO_DMX_EVS_DMX_EGY_FORGETTING ); + + if ( src_energy[0] * Lbias > src_energy[1] ) + { + amp_mod[0] = 1.0f - sqrtf( ( dmx_energy[0] + eps ) / ( src_energy[0] + eps ) ); + amp_mod[0] = max( amp_mod[0], 0.0f ); + amp_mod[1] = 0.0f; + } + else + { + amp_mod[1] = 1.0f - sqrtf( ( dmx_energy[0] + eps ) / ( src_energy[1] + eps ) ); + amp_mod[1] = max( amp_mod[1], 0.0f ); + amp_mod[0] = 0.0f; + } + + adapt_gain( srcL, weighted, amp_mod[0], w_prev[1], input_frame, wnd ); + v_add( dmx, weighted, dmx, input_frame ); + adapt_gain( srcR, weighted, amp_mod[1], w_prev[2], input_frame, wnd ); + v_add( dmx, weighted, dmx, input_frame ); + + w_prev[0] = w_curr; + w_prev[1] = amp_mod[0]; + w_prev[2] = amp_mod[1]; + + return; +} + +#endif +/*-------------------------------------------------------------------* + * stereo_dmx_evs_enc() + * + * Stereo downmix for EVS encoder routine + *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void stereo_dmx_evs_enc_fx( + STEREO_DMX_EVS_ENC_HANDLE hStereoDmxEVS, /* i/o: Stereo downmix for EVS encoder handle */ + const Word32 input_Fs, /* i : input sampling rate */ + Word16 data[CPE_CHANNELS * L_FRAME48k], /* i/o: input signal Q0 */ + const Word16 n_samples, /* i : number of input samples */ + const bool is_binaural /* i : indication that input is binaural audio */ +) +{ + Word16 n; + Word16 dmx_weight, corr; // Q15 + Word32 data_fx[CPE_CHANNELS][L_FRAME48k]; // Q16/Q11 + + Word16 k, m, pha_len, fad_len; + Word32 mem_prev[STEREO_DMX_EVS_FAD_LEN_MAX], data_mem[STEREO_DMX_EVS_DATA_LEN_MAX]; // Q11 + Word32 *p_data_mem, *p_prev_taps, *p_curr_taps, *fad_g, *p_data; + Word32 dmx_poc_data[L_FRAME48k] /*Q11*/, dmx_pha_data[L_FRAME48k] /*Q11*/, *p_dmx_data, fx_tmp; + Word16 fx_tmp_e; + STEREO_DMX_EVS_PRC curr_prc; + Word16 input_subframe, is_transient; + Word32 *p_sub_frame, subframe_energy[STEREO_DMX_EVS_NB_SBFRM]; + Word16 subframe_energy_e[STEREO_DMX_EVS_NB_SBFRM]; + + Word16 input_frame; + + Word32 L_tmp1, L_tmp2; + Word16 L_tmp1_e, L_tmp2_e; + + Word64 W_tmp; + Word16 W_tmp_q; + + if ( is_binaural ) + { + /* use of is_binaural flag is to be considered */ + } + + // input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); + SWITCH( input_Fs ) + { + case 8000: + input_frame = 160; + BREAK; + case 16000: + input_frame = 320; + BREAK; + case 32000: + input_frame = 640; + BREAK; + case 48000: + input_frame = 960; + BREAK; + default: + input_frame = 960; + IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid sample rate\n" ); + BREAK; + } + move16(); + + FOR( n = 0; n < input_frame; n++ ) + { + data_fx[0][n] = L_deposit_h( data[2 * n] ); + move32(); + data_fx[1][n] = L_deposit_h( data[2 * n + 1] ); + move32(); + } + IF( LT_16( n_samples, input_frame ) ) + { + set32_fx( data_fx[0] + n_samples, 0, sub( input_frame, n_samples ) ); + set32_fx( data_fx[1] + n_samples, 0, sub( input_frame, n_samples ) ); + } + + + // input_subframe = n_samples / STEREO_DMX_EVS_NB_SBFRM; + IF( EQ_16( n_samples, L_FRAME16k ) ) + { + input_subframe = 64; + move16(); + } + ELSE IF( EQ_16( n_samples, L_FRAME32k ) ) + { + input_subframe = 128; + move16(); + } + ELSE IF( EQ_16( n_samples, L_FRAME48k ) ) + { + input_subframe = 192; + move16(); + } + ELSE + { + input_subframe = 192; + move16(); + IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid frame length\n" ); + } + + is_transient = 0; + move16(); + FOR( k = 0; k < CPE_CHANNELS; k++ ) + { + fx_tmp = 0; + move32(); + fx_tmp_e = 0; + move16(); + FOR( m = 0; m < STEREO_DMX_EVS_NB_SBFRM; m++ ) + { + p_sub_frame = &( data_fx[k][m * input_subframe] ); + subframe_energy[m] = 0; + move32(); + subframe_energy_e[m] = 0; + move16(); + FOR( n = 0; n < input_subframe; n++ ) + { + // subframe_energy[m] += p_sub_frame[n] * p_sub_frame[n]; + W_tmp = W_mult_32_32( p_sub_frame[n], p_sub_frame[n] ); + W_tmp_q = W_norm( W_tmp ); + W_tmp = W_shl( W_tmp, W_tmp_q ); + L_tmp1 = W_extract_h( W_tmp ); + L_tmp1_e = sub( 15 * 2, W_tmp_q ); + subframe_energy[m] = BASOP_Util_Add_Mant32Exp( subframe_energy[m], subframe_energy_e[m], L_tmp1, L_tmp1_e, &subframe_energy_e[m] ); + move32(); + } + + L_tmp1 = BASOP_Util_Add_Mant32Exp( hStereoDmxEVS->hPHA->trns_aux_energy_fx[k], hStereoDmxEVS->hPHA->trns_aux_energy_fx_e[k], EPSILON_FX_M, EPSILON_FX_E, &L_tmp1_e ); + L_tmp2 = BASOP_Util_Divide3232_Scale_cadence( subframe_energy[m], L_tmp1, &L_tmp2_e ); + L_tmp2_e = add( L_tmp2_e, sub( subframe_energy_e[m], L_tmp1_e ) ); + // if ( subframe_energy[m] / ( hStereoDmxEVS->hPHA->trns_aux_energy[k] + EPSILON ) > hStereoDmxEVS->hPHA->crst_fctr ) + if ( BASOP_Util_Cmp_Mant32Exp( L_tmp2, L_tmp2_e, hStereoDmxEVS->hPHA->crst_fctr_fx, 31 ) > 0 ) + { + is_transient = 1; + move16(); + } + + IF( hStereoDmxEVS->hPHA->init_frmCntr == 0 ) + { + // hStereoDmxEVS->hPHA->trns_aux_energy[k] = STEREO_DMX_EVS_TRNS_EGY_FORGETTING * hStereoDmxEVS->hPHA->trns_aux_energy[k] + ( 1.0f - STEREO_DMX_EVS_TRNS_EGY_FORGETTING ) * subframe_energy[m]; + hStereoDmxEVS->hPHA->trns_aux_energy_fx[k] = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( hStereoDmxEVS->hPHA->trns_aux_energy_fx[k], STEREO_DMX_EVS_TRNS_EGY_FORGETTING_Q15 ), hStereoDmxEVS->hPHA->trns_aux_energy_fx_e[k], Mpy_32_16_1( subframe_energy[m], sub( MAX_16, STEREO_DMX_EVS_TRNS_EGY_FORGETTING_Q15 ) ), subframe_energy_e[m], &hStereoDmxEVS->hPHA->trns_aux_energy_fx_e[k] ); + move32(); + } + ELSE + { + // hStereoDmxEVS->hPHA->trns_aux_energy[k] = 0.5f * hStereoDmxEVS->hPHA->trns_aux_energy[k] + 0.5f * subframe_energy[m]; + hStereoDmxEVS->hPHA->trns_aux_energy_fx[k] = BASOP_Util_Add_Mant32Exp( hStereoDmxEVS->hPHA->trns_aux_energy_fx[k], add( hStereoDmxEVS->hPHA->trns_aux_energy_fx_e[k], 1 ), subframe_energy[m], add( subframe_energy_e[m], 1 ), &hStereoDmxEVS->hPHA->trns_aux_energy_fx_e[k] ); + move32(); + } + + fx_tmp = BASOP_Util_Add_Mant32Exp( fx_tmp, fx_tmp_e, subframe_energy[m], subframe_energy_e[m], &fx_tmp_e ); + } + + FOR( m = 1; m < STEREO_DMX_EVS_NB_SBFRM; m++ ) + { + L_tmp1 = BASOP_Util_Add_Mant32Exp( subframe_energy[m - 1], subframe_energy_e[m - 1], EPSILON_FX_M, EPSILON_FX_E, &L_tmp1_e ); + L_tmp2 = BASOP_Util_Divide3232_Scale_cadence( subframe_energy[m], L_tmp1, &L_tmp2_e ); + L_tmp2_e = add( L_tmp2_e, sub( subframe_energy_e[m], L_tmp1_e ) ); + // if ( subframe_energy[m] / ( subframe_energy[m - 1] + EPSILON ) > STEREO_DMX_EVS_TRNS_DTC_INST ) + if ( BASOP_Util_Cmp_Mant32Exp( L_tmp2, L_tmp2_e, (Word16) STEREO_DMX_EVS_TRNS_DTC_INST, 31 ) > 0 ) + { + is_transient = 1; + move16(); + } + } + } + + estimate_itd_fx( &corr, hStereoDmxEVS->hPOC, hStereoDmxEVS->hPHA, data_fx[0], data_fx[1], &hStereoDmxEVS->itd_fx, input_frame ); + + /* poc */ + + IF( hStereoDmxEVS->itd_fx ) + { + // dmx_weight = ( ( hStereoDmxEVS->itd > 0 ) ? ( -1 ) : 1 ) * 0.5f * corr + 0.5f; + IF( hStereoDmxEVS->itd_fx > 0 ) + { + dmx_weight = add( negate( shr( corr, 1 ) ), ONE_IN_Q14 ); + } + ELSE + { + dmx_weight = add( shr( corr, 1 ), ONE_IN_Q14 ); + } + } + ELSE + { + dmx_weight = ONE_IN_Q14; + move16(); + } + + create_M_signal_fx( data_fx[0], data_fx[1], dmx_poc_data, dmx_weight, input_frame, hStereoDmxEVS->s_wnd_fx, + hStereoDmxEVS->dmx_weight_fx, hStereoDmxEVS->pre_dmx_energy_fx, hStereoDmxEVS->pre_dmx_energy_fx_e, hStereoDmxEVS->aux_dmx_energy_fx, hStereoDmxEVS->aux_dmx_energy_fx_e ); + + // Downscaling signals to avoid accumulation overflows + scale_sig32( data_fx[0], input_frame, -5 ); // Q16->Q11 + scale_sig32( data_fx[1], input_frame, -5 ); // Q16->Q11 + scale_sig32( dmx_poc_data, input_frame, -5 ); // Q16->Q11 + + /* pha */ + + pha_len = hStereoDmxEVS->hPHA->pha_len; + move16(); + fad_len = hStereoDmxEVS->hPHA->fad_len; + move16(); + fad_g = hStereoDmxEVS->hPHA->fad_g_fx; + + set_zero_fx( dmx_pha_data, n_samples ); + set_zero_fx( mem_prev, fad_len ); + + FOR( k = 0; k < CPE_CHANNELS; k++ ) + { + p_data = data_fx[k]; + Copy32( hStereoDmxEVS->hPHA->data_mem_fx[k], data_mem, pha_len ); + Copy32( &( p_data[n_samples - pha_len] ), hStereoDmxEVS->hPHA->data_mem_fx[k], pha_len ); + p_data_mem = &( data_mem[pha_len] ); + Copy32( p_data, p_data_mem, n_samples ); + + p_prev_taps = hStereoDmxEVS->hPHA->p_prev_taps_fx[k]; + IF( p_prev_taps ) + { + FOR( n = 0; n < fad_len; n++ ) + { + FOR( ( fx_tmp = 0, m = 0 ); m < pha_len; m++ ) + { + // ftmp += p_data_mem[n - m] * p_prev_taps[m]; + // fx_tmp = BASOP_Util_Add_Mant32Exp(fx_tmp, fx_tmp_e, Mpy_32_32(p_data_mem[n - m], p_prev_taps[m]),15,&fx_tmp_e); + fx_tmp = L_add( fx_tmp, Mpy_32_32( p_data_mem[n - m], p_prev_taps[m] ) ); // Q11 + } + mem_prev[n] = L_add( mem_prev[n], Mpy_32_32( fx_tmp, INV_SQRT_2_Q31 ) ); + move32(); + } + } + ELSE + { + FOR( n = 0; n < fad_len; n++ ) + { + // mem_prev[n] += p_data[n] * INV_SQRT_2; + mem_prev[n] = L_add( mem_prev[n], Mpy_32_32( p_data[n], INV_SQRT_2_Q31 ) ); // Q11 + move32(); + } + } + + p_curr_taps = hStereoDmxEVS->hPHA->p_curr_taps_fx[k]; + IF( p_curr_taps ) + { + FOR( n = 0; n < n_samples; n++ ) + { + FOR( ( fx_tmp = 0, m = 0 ); m < pha_len; m++ ) + { + // ftmp += p_data_mem[n - m] * p_curr_taps[m]; + fx_tmp = L_add( fx_tmp, Mpy_32_32( p_data_mem[n - m], p_curr_taps[m] ) ); // Q11 + } + // dmx_pha_data[n] += ftmp * INV_SQRT_2; + dmx_pha_data[n] = L_add( dmx_pha_data[n], Mpy_32_32( fx_tmp, INV_SQRT_2_Q31 ) ); // Q11 + move32(); + } + } + ELSE + { + FOR( n = 0; n < n_samples; n++ ) + { + // dmx_pha_data[n] += p_data[n] * INV_SQRT_2; + dmx_pha_data[n] = L_add( dmx_pha_data[n], Mpy_32_32( p_data[n], INV_SQRT_2_Q31 ) ); // Q11 + move32(); + } + } + } + + FOR( ( n = 0, m = ( fad_len - 1 ) ); n < fad_len; ( n++, m-- ) ) { - dst[i] = src[i] * gain; + dmx_pha_data[n] = Mpy_32_32( dmx_pha_data[n], fad_g[n] ); + move32(); + dmx_pha_data[n] = L_add( dmx_pha_data[n], Mpy_32_32( mem_prev[n], fad_g[m] ) ); // Q11 + move32(); } - return; -} + /* prc switch */ + curr_prc = hStereoDmxEVS->hPHA->curr_prc; + move32(); + // if ( abs( (int16_t) hStereoDmxEVS->itd ) > hStereoDmxEVS->hPHA->prc_thres ) + IF( GT_16( abs_s( round_fx( hStereoDmxEVS->itd_fx ) ), hStereoDmxEVS->hPHA->prc_thres ) ) + { + IF( NE_32( hStereoDmxEVS->hPHA->curr_prc, STEREO_DMX_EVS_PRC_POC ) ) + { + IF( EQ_32( hStereoDmxEVS->hPHA->prev_prc, STEREO_DMX_EVS_PRC_POC ) ) + { + hStereoDmxEVS->hPHA->prc_hys_cnt = add( hStereoDmxEVS->hPHA->prc_hys_cnt, 1 ); + move16(); + } + ELSE + { + hStereoDmxEVS->hPHA->prc_hys_cnt = 0; + move16(); + } -/*-------------------------------------------------------------------* - * create_M_signal() - * - * create downmix signal - *-------------------------------------------------------------------*/ + if ( GE_16( hStereoDmxEVS->hPHA->prc_hys_cnt, STEREO_DMX_EVS_SWTCH_PRC_HYS_THRES ) ) + { + hStereoDmxEVS->hPHA->curr_prc = STEREO_DMX_EVS_PRC_POC; + move32(); + } + } + hStereoDmxEVS->hPHA->prev_prc = STEREO_DMX_EVS_PRC_POC; + move32(); + } + ELSE + { + IF( NE_32( hStereoDmxEVS->hPHA->curr_prc, STEREO_DMX_EVS_PRC_PHA ) ) + { + IF( EQ_32( hStereoDmxEVS->hPHA->prev_prc, STEREO_DMX_EVS_PRC_PHA ) ) + { + hStereoDmxEVS->hPHA->prc_hys_cnt = add( hStereoDmxEVS->hPHA->prc_hys_cnt, 1 ); + move16(); + } + ELSE + { + hStereoDmxEVS->hPHA->prc_hys_cnt = 0; + move16(); + } -static void create_M_signal( - const float srcL[], /* i : Lch input signal */ - const float srcR[], /* i : Rch input signal */ - float dmx[], /* o : output signal */ - const float w_curr, /* i : adapting weight */ - const int16_t input_frame, /* i : input frame length per channel */ - const float wnd[], /* i : window coef */ - float *w_prev, /* i/o: adapting prev weight */ - float *dmx_energy, /* i/o: downmix signal energy */ - float *src_energy /* i/o: input signal energy */ -) -{ - float weighted[L_FRAME48k], eps, amp_mod[CPE_CHANNELS], Lbias; + if ( GE_16( hStereoDmxEVS->hPHA->prc_hys_cnt, STEREO_DMX_EVS_SWTCH_PRC_HYS_THRES ) ) + { + hStereoDmxEVS->hPHA->curr_prc = STEREO_DMX_EVS_PRC_PHA; + move32(); + } + } + hStereoDmxEVS->hPHA->prev_prc = STEREO_DMX_EVS_PRC_PHA; + move32(); + } - /* Initialization */ - eps = 1024.0f; - Lbias = ( w_prev[2] == 0 ) ? 4.0f : 0.25f; + // if ( ( is_transient == 1 ) || ( hStereoDmxEVS->aux_dmx_energy[0] > STEREO_DMX_EVS_ILDS_EGY * hStereoDmxEVS->aux_dmx_energy[1] ) || ( hStereoDmxEVS->aux_dmx_energy[1] > STEREO_DMX_EVS_ILDS_EGY * hStereoDmxEVS->aux_dmx_energy[0] ) || ( ( hStereoDmxEVS->hPHA->p_curr_taps[0] == NULL ) && ( hStereoDmxEVS->hPHA->p_curr_taps[1] == NULL ) ) ) + test(); + test(); + test(); + test(); + IF( EQ_16( is_transient, 1 ) || + BASOP_Util_Cmp_Mant32Exp( hStereoDmxEVS->aux_dmx_energy_fx[0], hStereoDmxEVS->aux_dmx_energy_fx_e[0], Mpy_32_32( STEREO_DMX_EVS_ILDS_EGY_Q17, hStereoDmxEVS->aux_dmx_energy_fx[1] ), add( hStereoDmxEVS->aux_dmx_energy_fx_e[1], 14 ) ) > 0 || + BASOP_Util_Cmp_Mant32Exp( hStereoDmxEVS->aux_dmx_energy_fx[1], hStereoDmxEVS->aux_dmx_energy_fx_e[1], Mpy_32_32( STEREO_DMX_EVS_ILDS_EGY_Q17, hStereoDmxEVS->aux_dmx_energy_fx[0] ), add( hStereoDmxEVS->aux_dmx_energy_fx_e[0], 14 ) ) > 0 || + ( ( hStereoDmxEVS->hPHA->p_curr_taps_fx[0] == NULL ) && ( hStereoDmxEVS->hPHA->p_curr_taps_fx[1] == NULL ) ) ) + { + hStereoDmxEVS->hPHA->curr_prc = STEREO_DMX_EVS_PRC_POC; + move32(); + hStereoDmxEVS->hPHA->prc_hys_cnt = 0; + move16(); + } - weighted_ave( srcL, srcR, dmx, w_curr, w_prev[0], input_frame, wnd ); + IF( hStereoDmxEVS->hPHA->curr_prc == STEREO_DMX_EVS_PRC_POC ) + { + p_dmx_data = dmx_poc_data; - calc_energy( srcL, srcL, src_energy, input_frame, STEREO_DMX_EVS_DMX_EGY_FORGETTING ); - calc_energy( srcR, srcR, src_energy + 1, input_frame, STEREO_DMX_EVS_DMX_EGY_FORGETTING ); - calc_energy( dmx, dmx, dmx_energy, input_frame, STEREO_DMX_EVS_DMX_EGY_FORGETTING ); + IF( NE_32( curr_prc, hStereoDmxEVS->hPHA->curr_prc ) ) + { + fad_len = hStereoDmxEVS->hPHA->fad_len_prc; + move16(); + fad_g = hStereoDmxEVS->hPHA->fad_g_prc_fx; - if ( src_energy[0] * Lbias > src_energy[1] ) - { - amp_mod[0] = 1.0f - sqrtf( ( dmx_energy[0] + eps ) / ( src_energy[0] + eps ) ); - amp_mod[0] = max( amp_mod[0], 0.0f ); - amp_mod[1] = 0.0f; + FOR( ( n = 0, m = ( fad_len - 1 ) ); n < fad_len; ( n++, m-- ) ) + { + p_dmx_data[n] = Mpy_32_32( p_dmx_data[n], fad_g[n] ); // Q11 + move32(); + p_dmx_data[n] = L_add( p_dmx_data[n], Mpy_32_32( fad_g[m], dmx_pha_data[n] ) ); // Q11 + move32(); + } + } } - else + ELSE { - amp_mod[1] = 1.0f - sqrtf( ( dmx_energy[0] + eps ) / ( src_energy[1] + eps ) ); - amp_mod[1] = max( amp_mod[1], 0.0f ); - amp_mod[0] = 0.0f; + p_dmx_data = dmx_pha_data; + + IF( NE_32( curr_prc, hStereoDmxEVS->hPHA->curr_prc ) ) + { + fad_len = hStereoDmxEVS->hPHA->fad_len_prc; + move16(); + fad_g = hStereoDmxEVS->hPHA->fad_g_prc_fx; + + FOR( ( n = 0, m = ( fad_len - 1 ) ); n < fad_len; ( n++, m-- ) ) + { + p_dmx_data[n] = Mpy_32_32( p_dmx_data[n], fad_g[n] ); // Q11 + move32(); + p_dmx_data[n] = L_add( p_dmx_data[n], Mpy_32_32( fad_g[m], dmx_poc_data[n] ) ); // Q11 + move32(); + } + } } - adapt_gain( srcL, weighted, amp_mod[0], w_prev[1], input_frame, wnd ); - v_add( dmx, weighted, dmx, input_frame ); - adapt_gain( srcR, weighted, amp_mod[1], w_prev[2], input_frame, wnd ); - v_add( dmx, weighted, dmx, input_frame ); + Copy_Scale_sig32_16( p_dmx_data, data, n_samples, 5 ); - w_prev[0] = w_curr; - w_prev[1] = amp_mod[0]; - w_prev[2] = amp_mod[1]; return; } - - -/*-------------------------------------------------------------------* - * stereo_dmx_evs_enc() - * - * Stereo downmix for EVS encoder routine - *-------------------------------------------------------------------*/ - +#else void stereo_dmx_evs_enc( STEREO_DMX_EVS_ENC_HANDLE hStereoDmxEVS, /* i/o: Stereo downmix for EVS encoder handle */ const int32_t input_Fs, /* i : input sampling rate */ @@ -1120,7 +3099,11 @@ void stereo_dmx_evs_enc( int16_t n; float dmx_weight, corr; float data_f[CPE_CHANNELS][L_FRAME48k]; - +#ifdef IVAS_FLOAT_FIXED + Word32 data_fx[CPE_CHANNELS][L_FRAME48k]; + Word32 dmx_weight_fx; + Word32 dmx_poc_data_fx[L_FRAME48k]; +#endif int16_t k, m, pha_len, fad_len; float mem_prev[STEREO_DMX_EVS_FAD_LEN_MAX], data_mem[STEREO_DMX_EVS_DATA_LEN_MAX]; float *p_data_mem, *p_prev_taps, *p_curr_taps, *fad_g, *p_data; @@ -1202,10 +3185,30 @@ void stereo_dmx_evs_enc( { dmx_weight = 0.5f; } - +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( int i = 0; i < CPE_CHANNELS; i++ ) + { + floatToFixed_arrL32( data_f[i], data_fx[i], Q16, L_FRAME48k ); + f2me( hStereoDmxEVS->aux_dmx_energy[i], &hStereoDmxEVS->aux_dmx_energy_fx[i], &hStereoDmxEVS->aux_dmx_energy_fx_e[i] ); + } + f2me( hStereoDmxEVS->pre_dmx_energy[0], &hStereoDmxEVS->pre_dmx_energy_fx[0], &hStereoDmxEVS->pre_dmx_energy_fx_e[0] ); + floatToFixed_arrL32( hStereoDmxEVS->dmx_weight, hStereoDmxEVS->dmx_weight_fx, Q31, 1 + CPE_CHANNELS ); + dmx_weight_fx = floatToFixed( dmx_weight, Q31 ); +#endif + create_M_signal_fx( data_fx[0], data_fx[1], dmx_poc_data_fx, dmx_weight_fx, input_frame, hStereoDmxEVS->s_wnd_fx, + hStereoDmxEVS->dmx_weight_fx, hStereoDmxEVS->pre_dmx_energy_fx, hStereoDmxEVS->pre_dmx_energy_fx_e, hStereoDmxEVS->aux_dmx_energy_fx, hStereoDmxEVS->aux_dmx_energy_fx_e ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + me2f_buf( dmx_poc_data_fx, 31 - 16, dmx_poc_data, input_frame ); + fixedToFloat_arrL32( hStereoDmxEVS->dmx_weight_fx, hStereoDmxEVS->dmx_weight, Q31, CPE_CHANNELS + 1 ); + hStereoDmxEVS->aux_dmx_energy[0] = me2f( hStereoDmxEVS->aux_dmx_energy_fx[0], hStereoDmxEVS->aux_dmx_energy_fx_e[0] ); + hStereoDmxEVS->aux_dmx_energy[1] = me2f( hStereoDmxEVS->aux_dmx_energy_fx[1], hStereoDmxEVS->aux_dmx_energy_fx_e[1] ); + hStereoDmxEVS->pre_dmx_energy[0] = me2f( hStereoDmxEVS->pre_dmx_energy_fx[0], hStereoDmxEVS->pre_dmx_energy_fx_e[0] ); +#endif +#else create_M_signal( data_f[0], data_f[1], dmx_poc_data, dmx_weight, input_frame, hStereoDmxEVS->s_wnd, hStereoDmxEVS->dmx_weight, hStereoDmxEVS->pre_dmx_energy, hStereoDmxEVS->aux_dmx_energy ); - +#endif /* pha */ pha_len = hStereoDmxEVS->hPHA->pha_len; @@ -1358,6 +3361,7 @@ void stereo_dmx_evs_enc( return; } +#endif /*-------------------------------------------------------------------* @@ -1365,7 +3369,406 @@ void stereo_dmx_evs_enc( * * open and initialize stereo downmix for EVS encoder *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error stereo_dmx_evs_init_encoder_fx( + STEREO_DMX_EVS_ENC_HANDLE *hStereoDmxEVS_out, /* o : Stereo downmix for EVS encoder handle */ + const Word32 input_Fs /* i : input sampling rate */ +) +{ + STEREO_DMX_EVS_ENC_HANDLE hStereoDmxEVS; + Word16 n, input_frame; + + Word16 m, len, pha_len, fad_len, fad_len2, trans_len /*, itrh*/, rfft_ipd_coef_step, n0, input_frame_pha; + Word32 *fad_g, fad_r /*, a_min, a_max, a_step*/, *ipd_ff; + Word16 *win, tmp_r; + const Word16 *p_ipd_w; + Word16 tmp_e; + + // input_frame = (Word16) ( input_Fs / FRAMES_PER_SEC ); + SWITCH( input_Fs ) + { + case 8000: + input_frame = 160; + BREAK; + case 16000: + input_frame = 320; + BREAK; + case 32000: + input_frame = 640; + BREAK; + case 48000: + input_frame = 960; + BREAK; + default: + input_frame = 960; + IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid sample rate\n" ); + BREAK; + } + move16(); + hStereoDmxEVS = NULL; + IF( ( hStereoDmxEVS = (STEREO_DMX_EVS_ENC_HANDLE) malloc( sizeof( STEREO_DMX_EVS_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for STEREO_DMX_EVS_ENC_DATA\n" ) ); + } + hStereoDmxEVS->itd_fx = 0; + move16(); + hStereoDmxEVS->pre_dmx_energy_fx[0] = 0; + move32(); + hStereoDmxEVS->pre_dmx_energy_fx_e[0] = 0; + move16(); + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + hStereoDmxEVS->aux_dmx_energy_fx[n] = 0; + move32(); + hStereoDmxEVS->aux_dmx_energy_fx_e[n] = 0; + move16(); + } + + hStereoDmxEVS->dmx_weight_fx[0] = ONE_IN_Q30; // 0.5f; + move32(); + hStereoDmxEVS->dmx_weight_fx[1] = 0; + move32(); + hStereoDmxEVS->dmx_weight_fx[2] = 0; + move32(); + + IF( EQ_16( input_frame, L_FRAME16k ) ) + { + hStereoDmxEVS->s_wnd_fx = Stereo_dmx_s_wnd_coef_16k_fx; + } + ELSE IF( EQ_16( input_frame, L_FRAME32k ) ) + { + hStereoDmxEVS->s_wnd_fx = Stereo_dmx_s_wnd_coef_32k_fx; + } + ELSE IF( EQ_16( input_frame, L_FRAME48k ) ) + { + hStereoDmxEVS->s_wnd_fx = Stereo_dmx_s_wnd_coef_48k_fx; + } + ELSE + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid frame length\n" ); + } + hStereoDmxEVS->hPOC = NULL; + IF( ( hStereoDmxEVS->hPOC = (STEREO_DMX_EVS_POC_HANDLE) malloc( sizeof( STEREO_DMX_EVS_POC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for STEREO_DMX_EVS_POC_DATA\n" ) ); + } + + // hStereoDmxEVS->hPOC->shift_limit = (int16_t) ( STEREO_DMX_EVS_SHIFT_LIMIT * input_Fs / 1000 ); + SWITCH( input_Fs ) + { + case 8000: + hStereoDmxEVS->hPOC->shift_limit = 45; + move16(); + BREAK; + case 16000: + hStereoDmxEVS->hPOC->shift_limit = 90; + move16(); + BREAK; + case 32000: + hStereoDmxEVS->hPOC->shift_limit = 180; + move16(); + BREAK; + case 48000: + hStereoDmxEVS->hPOC->shift_limit = 270; + move16(); + BREAK; + default: + IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid sample rate\n" ); + BREAK; + } + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + hStereoDmxEVS->hPOC->peakQ_fx[n] = 0; + move32(); + // hStereoDmxEVS->hPOC->peak_width_fx[n] = (float) hStereoDmxEVS->hPOC->shift_limit / 2; + hStereoDmxEVS->hPOC->peak_width_fx[n] = hStereoDmxEVS->hPOC->shift_limit; // Q1 + move32(); + hStereoDmxEVS->hPOC->ispeak[n] = 0; + move16(); + hStereoDmxEVS->hPOC->itdLR[n] = 0; + move16(); + } + set32_fx( hStereoDmxEVS->hPOC->P_fx, 0, L_FRAME48k ); + + IF( EQ_16( input_frame, L_FRAME16k ) ) + { + hStereoDmxEVS->hPOC->wnd_fx = Stereo_dmx_wnd_coef_48k_fx; + } + ELSE IF( EQ_16( input_frame, L_FRAME32k ) ) + { + hStereoDmxEVS->hPOC->wnd_fx = Stereo_dmx_wnd_coef_32k_fx; + } + ELSE IF( EQ_16( input_frame, L_FRAME48k ) ) + { + hStereoDmxEVS->hPOC->wnd_fx = Stereo_dmx_wnd_coef_48k_fx; + } + ELSE + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid frame length\n" ); + } + // hStereoDmxEVS->hPOC->eps = 2.0f * EVS_PI / ( (float) input_frame ); + SWITCH( input_frame ) + { + case 160: + hStereoDmxEVS->hPOC->eps_fx = 84331486; + BREAK; + case 320: + hStereoDmxEVS->hPOC->eps_fx = 42165743; + BREAK; + case 640: + hStereoDmxEVS->hPOC->eps_fx = 21082871; + BREAK; + case 960: + hStereoDmxEVS->hPOC->eps_fx = 14055248; + BREAK; + } + move32(); + + IF( EQ_16( input_frame, L_FRAME16k ) ) + { + hStereoDmxEVS->hPOC->sin_fx = dft_trigo_32k_fx; + } + ELSE IF( EQ_16( input_frame, L_FRAME32k ) ) + { + hStereoDmxEVS->hPOC->sin_fx = dft_trigo_32k_fx; + } + ELSE IF( EQ_16( input_frame, L_FRAME48k ) ) + { + hStereoDmxEVS->hPOC->sin_fx = dft_trigo_48k_fx; + } + ELSE + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid frame length\n" ); + } + + hStereoDmxEVS->hPOC->confidence_fx = 0; + move32(); + + hStereoDmxEVS->hPHA = NULL; + IF( ( hStereoDmxEVS->hPHA = (STEREO_DMX_EVS_PHA_HANDLE) malloc( sizeof( STEREO_DMX_EVS_PHA_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for STEREO_DMX_EVS_CORFILT_DATA\n" ) ); + } + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + hStereoDmxEVS->hPHA->p_curr_taps_fx[n] = NULL; + hStereoDmxEVS->hPHA->p_prev_taps_fx[n] = NULL; + + set_zero_fx( hStereoDmxEVS->hPHA->data_mem_fx[n], STEREO_DMX_EVS_PHA_LEN_MAX ); + set_zero_fx( hStereoDmxEVS->hPHA->curr_taps_fx[n], STEREO_DMX_EVS_PHA_LEN_MAX ); + } + + IF( EQ_32( input_Fs, 16000 ) ) + { + len = STEREO_DMX_EVS_PHA_LEN_16; + move16(); + hStereoDmxEVS->hPHA->fad_len = STEREO_DMX_EVS_FAD_LEN_16; + move16(); + hStereoDmxEVS->hPHA->prc_thres = STEREO_DMX_EVS_SWTCH_PRC_THRES_16; + move16(); + hStereoDmxEVS->hPHA->crst_fctr_fx = (Word16) STEREO_DMX_EVS_CRST_FCTR_16; + move32(); + } + ELSE IF( EQ_32( input_Fs, 32000 ) ) + { + len = STEREO_DMX_EVS_PHA_LEN_32; + move16(); + hStereoDmxEVS->hPHA->fad_len = STEREO_DMX_EVS_FAD_LEN_32; + move16(); + hStereoDmxEVS->hPHA->prc_thres = STEREO_DMX_EVS_SWTCH_PRC_THRES_32; + move16(); + hStereoDmxEVS->hPHA->crst_fctr_fx = (Word16) STEREO_DMX_EVS_CRST_FCTR_32; + move32(); + } + ELSE IF( EQ_32( input_Fs, 48000 ) ) + { + len = STEREO_DMX_EVS_PHA_LEN_48; + move16(); + hStereoDmxEVS->hPHA->fad_len = STEREO_DMX_EVS_FAD_LEN_48; + move16(); + hStereoDmxEVS->hPHA->prc_thres = STEREO_DMX_EVS_SWTCH_PRC_THRES_48; + move16(); + hStereoDmxEVS->hPHA->crst_fctr_fx = (Word16) STEREO_DMX_EVS_CRST_FCTR_48; + move32(); + } + ELSE + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid sampling frequency\n" ); + } + + hStereoDmxEVS->hPHA->pha_len = shr( len, 1 ); + move16(); + hStereoDmxEVS->hPHA->init_frmCntr = 10; // (int16_t)(FRAMES_PER_SEC * 0.2f) + move16(); + hStereoDmxEVS->hPHA->isd_rate_s_fx = 0; + move32(); + hStereoDmxEVS->hPHA->iccr_s_fx = 0; + move32(); + + pha_len = hStereoDmxEVS->hPHA->pha_len; + move16(); + fad_len = hStereoDmxEVS->hPHA->fad_len; + move16(); + + trans_len = idiv1616( pha_len, 20 ); + set16_fx( hStereoDmxEVS->hPHA->win_fx, 29491 /*1.8f in Q15*/, sub( pha_len, trans_len ) ); + hStereoDmxEVS->hPHA->win_fx[0] = ONE_IN_Q14; + // tmp_r = 1.0f / ( ( trans_len * 2 ) + 1 ); + tmp_r = div_s( 1, add( shl( trans_len, 1 ), 1 ) ); + win = &( hStereoDmxEVS->hPHA->win_fx[pha_len - trans_len] ); + FOR( n = 0; n < trans_len; n++ ) + { + // win[n] = ( 0.5f * ( 1.0f + cosf( ( PI2 * ( n + 1 ) ) * tmp_r ) ) ) * 1.8f; + win[n] = mult_r( add( ONE_IN_Q14, getCosWord16R2( imult1616( add( n, 1 ), tmp_r ) ) ), 29491 ); + move32(); + } + + fad_g = hStereoDmxEVS->hPHA->fad_g_fx; + // fad_r = 1.0f / (float) ( fad_len + 1 ); + fad_r = BASOP_Util_Divide3232_Scale_cadence( 1, add( fad_len, 1 ), &tmp_e ); + fad_r = L_shl_r( fad_r, tmp_e ); + fad_len2 = shr( fad_len, 1 ); + FOR( ( n = 0, m = sub( fad_len, 1 ) ); n < fad_len2; ( n++, m-- ) ) + { + fad_g[n] = imult3216( fad_r, add( n, 1 ) ); + move32(); + fad_g[m] = L_sub( MAX_32, fad_g[n] ); + move32(); + } + + hStereoDmxEVS->hPHA->curr_pha = STEREO_DMX_EVS_PHA_IPD; + move32(); + hStereoDmxEVS->hPHA->prev_pha = STEREO_DMX_EVS_PHA_IPD; + move32(); + hStereoDmxEVS->hPHA->pha_hys_cnt = 0; + move16(); + + /* Compute the forgetting factor */ + // replaced below logic with table as it is same for all frame lengths + ipd_ff = hStereoDmxEVS->hPHA->ipd_ff_fx; + Copy32( ipd_ff_Q31, ipd_ff, STEREO_DMX_EVS_NB_SUBBAND_MAX ); + + // a_min = 0.8576958985908941f; + // a_max = 0.9440608762859234f; + // itrh = (int16_t)((3000 * input_frame) / (input_Fs * STEREO_DMX_EVS_SUBBAND_SIZE)); /* 3kHz */ + // n0 = L_FRAME16k / (2 * STEREO_DMX_EVS_SUBBAND_SIZE); + // a_step = (a_min - a_max) / (n0 + 1 - itrh); + // for (n = 0; n < itrh; n++) + //{ + // ipd_ff[n] = a_max; + // } + // for (; n < (n0 + 1); n++) /* 8kHz */ + //{ + // ipd_ff[n] = a_max + (n - itrh) * a_step; + // } + // for (; n < STEREO_DMX_EVS_NB_SUBBAND_MAX; n++) + //{ + // ipd_ff[n] = a_min; + // } + + set32_fx( hStereoDmxEVS->hPHA->Pr_fx, MAX_32, STEREO_DMX_EVS_NB_SUBBAND_MAX ); + set_zero_fx( hStereoDmxEVS->hPHA->Pi_fx, STEREO_DMX_EVS_NB_SUBBAND_MAX ); + + // n0 = input_frame / ( 4 * STEREO_DMX_EVS_SUBBAND_SIZE ); + n0 = shr( input_frame, 3 ); + // input_frame_pha = input_frame / ( 2 * STEREO_DMX_EVS_SUBBAND_SIZE ); + input_frame_pha = shr( input_frame, 2 ); + + IF( EQ_16( input_frame, L_FRAME16k ) ) + { + p_ipd_w = dft_trigo_32k_fx; + rfft_ipd_coef_step = 4; + move16(); + } + ELSE IF( EQ_16( input_frame, L_FRAME32k ) ) + { + p_ipd_w = dft_trigo_32k_fx; + rfft_ipd_coef_step = 2; + move16(); + } + ELSE IF( EQ_16( input_frame, L_FRAME48k ) ) + { + p_ipd_w = dft_trigo_48k_fx; + rfft_ipd_coef_step = 2; + move16(); + } + ELSE + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid sampling frequency\n" ); + } + + win = hStereoDmxEVS->hPHA->rfft_ipd_coef_fx; + len = imult1616( rfft_ipd_coef_step, STEREO_DMX_EVS_SUBBAND_SIZE ); + FOR( n = 0; n < n0; n++ ) + { + win[n] = p_ipd_w[n * len]; + move16(); + win[input_frame_pha - n] = p_ipd_w[n * len]; + move16(); + } + win[n0] = p_ipd_w[n0 * len]; + move16(); + + hStereoDmxEVS->hPHA->curr_prc = STEREO_DMX_EVS_PRC_POC; + move32(); + hStereoDmxEVS->hPHA->prev_prc = STEREO_DMX_EVS_PRC_POC; + move32(); + hStereoDmxEVS->hPHA->prc_hys_cnt = 0; + move16(); + + // hStereoDmxEVS->hPHA->fad_len_prc = (int16_t) ( STEREO_DMX_EVS_FADE_LEN_PRC * (float) input_Fs / 1000.0f ); + SWITCH( input_Fs ) + { + case 8000: + hStereoDmxEVS->hPHA->fad_len_prc = (Word16) STEREO_DMX_EVS_FADE_LEN_PRC * 8; + move16(); + BREAK; + case 16000: + hStereoDmxEVS->hPHA->fad_len_prc = (Word16) STEREO_DMX_EVS_FADE_LEN_PRC * 16; + move16(); + BREAK; + case 32000: + hStereoDmxEVS->hPHA->fad_len_prc = (Word16) STEREO_DMX_EVS_FADE_LEN_PRC * 32; + move16(); + BREAK; + case 48000: + hStereoDmxEVS->hPHA->fad_len_prc = (Word16) STEREO_DMX_EVS_FADE_LEN_PRC * 48; + move16(); + BREAK; + default: + IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid sample rate\n" ); + BREAK; + } + fad_len = hStereoDmxEVS->hPHA->fad_len_prc; + move16(); + fad_g = hStereoDmxEVS->hPHA->fad_g_prc_fx; + // fad_r = 1.0f / (float) ( fad_len + 1 ); + fad_r = BASOP_Util_Divide3232_Scale_cadence( 1, add( fad_len, 1 ), &tmp_e ); + fad_r = L_shl_r( fad_r, tmp_e ); + fad_len2 = shr( fad_len, 1 ); + FOR( ( n = 0, m = sub( fad_len, 1 ) ); n < fad_len2; ( n++, m-- ) ) + { + fad_g[n] = imult3216( fad_r, add( n, 1 ) ); + move32(); + fad_g[m] = L_sub( MAX_32, fad_g[n] ); + move32(); + } + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + hStereoDmxEVS->hPHA->trns_aux_energy_fx[n] = 0; + move32(); + hStereoDmxEVS->hPHA->trns_aux_energy_fx_e[n] = 0; + move16(); + } + + *hStereoDmxEVS_out = hStereoDmxEVS; + + return IVAS_ERR_OK; +} +#else ivas_error stereo_dmx_evs_init_encoder( STEREO_DMX_EVS_ENC_HANDLE *hStereoDmxEVS_out, /* o : Stereo downmix for EVS encoder handle */ const int32_t input_Fs /* i : input sampling rate */ @@ -1617,6 +4020,7 @@ ivas_error stereo_dmx_evs_init_encoder( return IVAS_ERR_OK; } +#endif /*-------------------------------------------------------------------* @@ -1624,7 +4028,35 @@ ivas_error stereo_dmx_evs_init_encoder( * * close stereo downmix for EVS encoder *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void stereo_dmx_evs_close_encoder_fx( + STEREO_DMX_EVS_ENC_HANDLE *hStereoDmxEVS /* i/o: Stereo downmix for EVS encoder handle */ +) +{ + test(); + IF( hStereoDmxEVS == NULL || *hStereoDmxEVS == NULL ) + { + return; + } + + IF( ( *hStereoDmxEVS )->hPOC != NULL ) + { + free( ( *hStereoDmxEVS )->hPOC ); + ( *hStereoDmxEVS )->hPOC = NULL; + } + + IF( ( *hStereoDmxEVS )->hPHA != NULL ) + { + free( ( *hStereoDmxEVS )->hPHA ); + ( *hStereoDmxEVS )->hPHA = NULL; + } + + free( ( *hStereoDmxEVS ) ); + ( *hStereoDmxEVS ) = NULL; + return; +} +#else void stereo_dmx_evs_close_encoder( STEREO_DMX_EVS_ENC_HANDLE *hStereoDmxEVS /* i/o: Stereo downmix for EVS encoder handle */ ) @@ -1651,3 +4083,4 @@ void stereo_dmx_evs_close_encoder( return; } +#endif diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index 4bd59385850c79bf00a1030d0ee954c48c602e50..e57aadf5d7d14f04c53efaa7fd1e8532bf573878 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -626,10 +626,6 @@ void stereo_mdct_core_enc( st->prevEnergyHF_fx = floatToFixed_32( st->prevEnergyHF, q_com ); st->currEnergyHF_fx = floatToFixed_32( st->currEnergyHF, q_com ); st->currEnergyHF_e_fx = sub( Q31, q_com ); - IF( st->hTranDet ) - { - floatToFixed_arr( st->hTranDet->subblockEnergies.subblockNrgChange_flt, st->hTranDet->subblockEnergies.subblockNrgChange, Q15 - NRG_CHANGE_E, NSUBBLOCKS + MAX_TD_DELAY ); - } IF( st->hTcxEnc ) { st->hTcxEnc->tfm_mem_fx = floatToFixed_32( st->hTcxEnc->tfm_mem, Q31 ); @@ -663,23 +659,12 @@ void stereo_mdct_core_enc( #endif /* adaptively sync tcx modes*/ #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 temp_q = Q_factor_arrL( sts[0]->hTranDet->subblockEnergies.accSubblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY + 1 ); - temp_q = s_min( temp_q, Q_factor_arrL( sts[1]->hTranDet->subblockEnergies.accSubblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY + 1 ) ); - for ( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - st = sts[ch]; - floatToFixed_arrL32( st->hTranDet->subblockEnergies.accSubblockNrg_flt, st->hTranDet->subblockEnergies.accSubblockNrg, temp_q, NSUBBLOCKS + MAX_TD_DELAY + 1 ); - } -#endif - IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && ( GT_16( abs_s( sub( sts[0]->hTcxCfg->tcx_last_overlap_mode, sts[1]->hTcxCfg->tcx_last_overlap_mode ) ), extract_l( 2 ) ) || EQ_16( sts[0]->hTcxCfg->tcx_last_overlap_mode, sts[1]->hTcxCfg->tcx_last_overlap_mode ) || EQ_16( add( sts[0]->hTcxCfg->tcx_last_overlap_mode, sts[1]->hTcxCfg->tcx_last_overlap_mode ), extract_l( 5 ) ) ) ) /* disable syncing for stereo switching or large diff in last frame overlap */ { sync_tcx_mode( sts ); } - #else if ( ( hCPE->last_element_mode == IVAS_CPE_MDCT ) && ( abs( sts[0]->hTcxCfg->tcx_last_overlap_mode - sts[1]->hTcxCfg->tcx_last_overlap_mode ) > 2 || sts[0]->hTcxCfg->tcx_last_overlap_mode == sts[1]->hTcxCfg->tcx_last_overlap_mode || @@ -745,6 +730,9 @@ void stereo_mdct_core_enc( set_f( quantized_spectrum_long[ch], 0.0, N_MAX ); set_f( mdst_spectrum_long[ch], 0.0, N_MAX ); set_f( powerSpec[ch], 0.0, N_MAX ); +#ifdef MSAN_FIX + set_f( orig_spectrum_long[ch], 0.0, N_MAX ); +#endif } /*--------------------------------------------------------------* @@ -1226,7 +1214,7 @@ void stereo_mdct_core_enc( hPrivateData = &hIGFEnc[ch]->igfData; hGrid = &hPrivateData->igfInfo.grid[(Word16) igfGridIdx]; swb_offset = hGrid->swb_offset; - hIGFEnc[ch]->tns_predictionGain = float_to_fix16( hIGFEnc[ch]->tns_predictionGain_flt, Q23 ); + // hIGFEnc[ch]->tns_predictionGain = float_to_fix16( hIGFEnc[ch]->tns_predictionGain_flt, Q23 ); sts[ch]->hTcxEnc->spectrum_e[n] = 31 - Q_factor_arrL( sts[ch]->hTcxEnc->spectrum[n], hGrid->infoGranuleLen ); sts[ch]->hTcxEnc->spectrum_e[n] = s_max( sts[ch]->hTcxEnc->spectrum_e[n], 31 - Q_factor_arrL( &p_powerSpec[ch][0], hGrid->infoGranuleLen ) ); sts[ch]->hTcxEnc->spectrum_e[n] = s_max( sts[ch]->hTcxEnc->spectrum_e[n], 31 - Q_factor_arrL( inv_spectrum[ch][n], swb_offset[hGrid->sfbWrap[hGrid->nTiles]] ) ); @@ -1235,57 +1223,6 @@ void stereo_mdct_core_enc( floatToFixed_arr32( &p_powerSpec[ch][0], &p_powerSpec_fx[ch][0], 31 - sts[ch]->hTcxEnc->spectrum_e[n], hGrid->infoGranuleLen ); floatToFixed_arr32( inv_spectrum[ch][n], inv_spectrum_fx[ch][n], 31 - sts[ch]->hTcxEnc->spectrum_e[n], swb_offset[hGrid->sfbWrap[hGrid->nTiles]] ); floatToFixed_arr32( powerSpecMsInv[ch][0], powerSpecMsInv_fx[ch][0], 31 - sts[ch]->hTcxEnc->spectrum_e[n], swb_offset[hGrid->sfbWrap[hGrid->nTiles]] ); - 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 ); - } - } - floatToFixed_arr16( &hGrid->whiteningThreshold_flt[0][0], &hGrid->whiteningThreshold[0][0], Q13, 2 * IGF_MAX_TILES ); } #endif /**********************************flt to fix ends here*******************************************************/ hIGFEnc[0]->spec_be_igf_e = p_orig_spectrum_e[0]; @@ -1340,63 +1277,6 @@ void stereo_mdct_core_enc( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData = &st->hIGFEnc->igfData; - if ( st->hTdCngEnc != NULL ) - { - st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 ); - } - - 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 ); - } - } int igfGridIdx; if ( st->last_core == ACELP_CORE && st->core == TCX_20_CORE ) @@ -1433,11 +1313,7 @@ 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 ); - } - floatToFixed_arr16( &hPrivateData->igfInfo.grid[igfGridIdx].whiteningThreshold_flt[0][0], &hPrivateData->igfInfo.grid[igfGridIdx].whiteningThreshold[0][0], Q13, 2 * IGF_MAX_TILES ); + #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 @@ -1470,11 +1346,6 @@ void stereo_mdct_core_enc( hPrivateData->igfPastSFM[i][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[i][j], 13 ); } } - - if ( st->hTdCngEnc != NULL ) - { - st->hTdCngEnc->CNG_att = fix16_to_float( st->hTdCngEnc->CNG_att_fx, Q7 ); - } #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 ); @@ -1503,63 +1374,6 @@ void stereo_mdct_core_enc( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData = &st->hIGFEnc->igfData; - if ( st->hTdCngEnc != NULL ) - { - st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 ); - } - - 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 ); - } - } int igfGridIdx; if ( st->last_core == ACELP_CORE && st->core == TCX_20_CORE ) @@ -1600,7 +1414,7 @@ void stereo_mdct_core_enc( { st->hIGFEnc->tns_predictionGain = float_to_fix16( st->hIGFEnc->tns_predictionGain_flt, Q23 ); } - floatToFixed_arr16( &hPrivateData->igfInfo.grid[igfGridIdx].whiteningThreshold_flt[0][0], &hPrivateData->igfInfo.grid[igfGridIdx].whiteningThreshold[0][0], Q13, 2 * IGF_MAX_TILES ); + // floatToFixed_arr16( &hPrivateData->igfInfo.grid[igfGridIdx].whiteningThreshold_flt[0][0], &hPrivateData->igfInfo.grid[igfGridIdx].whiteningThreshold[0][0], Q13, 2 * IGF_MAX_TILES ); #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 @@ -1633,11 +1447,6 @@ void stereo_mdct_core_enc( hPrivateData->igfPastSFM[i][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[i][j], 13 ); } } - - if ( st->hTdCngEnc != NULL ) - { - st->hTdCngEnc->CNG_att = fix16_to_float( st->hTdCngEnc->CNG_att_fx, Q7 ); - } #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 ); @@ -1659,10 +1468,6 @@ void stereo_mdct_core_enc( sts[0]->side_bits_frame_channel -= SMDCT_NBBITS_SPLIT_RATIO; if ( !hStereoMdct->isSBAStereoMode ) { -#ifdef IVAS_FLOAT_FIXED - IF( hStereoMdct->hItd ) - hStereoMdct->hItd->itd_fx[1] = float_to_fix( hStereoMdct->hItd->itd[1], Q23 ); -#endif stereo_bits = write_stereo_to_bitstream( hStereoMdct, sts, ms_mask, 0, hBstr ); } else @@ -1727,31 +1532,14 @@ void stereo_mdct_core_enc( { sts = hCPE->hCoreCoder; st = sts[ch]; - TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; st->hTcxCfg->bandwidth = float_to_fix16( st->hTcxCfg->bandwidth_flt, Q15 ); st->hTcxCfg->preemph_fac = float_to_fix16( st->hTcxCfg->preemph_fac_flt, Q15 ); - st->hTcxEnc->tcx_target_bits_fac = float_to_fix16( st->hTcxEnc->tcx_target_bits_fac_flt, Q14 ); - st->hTcxCfg->sq_rounding = float_to_fix16( st->hTcxCfg->sq_rounding_flt, Q15 ); - if ( st->hTdCngEnc != NULL ) - { - st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 ); - } - floatToFixed_arr( hTcxEnc->ltpGainMemory, hTcxEnc->ltpGainMemory_fx, Q15, N_LTP_GAIN_MEMS ); st->hTcxEnc->measuredBwRatio = float_to_fix16( st->hTcxEnc->measuredBwRatio_flt, Q14 ); - st->hTcxEnc->noiseTiltFactor = float_to_fix16( st->hTcxEnc->noiseTiltFactor_flt, Q15 ); - st->hTcxEnc->tcxltp_gain = (Word16) ( st->hTcxEnc->tcxltp_gain_flt * ( 1 << Q15 ) ); } #endif ivas_mdct_quant_coder_fx( hCPE, tnsBits, tnsSize, p_param, 0 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - st = sts[ch]; - st->hTcxEnc->tcx_target_bits_fac_flt = me2f_16( st->hTcxEnc->tcx_target_bits_fac, Q15 - Q14 ); - } -#endif pop_wmops(); return; diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc.c b/lib_enc/ivas_stereo_mdct_stereo_enc.c index 5019512ebd2aae6c472f993f128f436cc85f47bc..da0cff0fe2b2f1dbe9906acc275bf3c41e8c485d 100644 --- a/lib_enc/ivas_stereo_mdct_stereo_enc.c +++ b/lib_enc/ivas_stereo_mdct_stereo_enc.c @@ -159,25 +159,6 @@ static void dft_ana_init( hDft_ana->win_ana_fx = win_ana_48k_fx; } -#if 1 // TODO: To be removed later - hDft_ana->dft_trigo_32k = dft_trigo_32k; - if ( input_Fs == 16000 ) - { - hDft_ana->dft_trigo = dft_trigo_32k; - hDft_ana->win_ana = win_ana_16k; - } - else if ( input_Fs == 32000 ) - { - hDft_ana->dft_trigo = dft_trigo_32k; - hDft_ana->win_ana = win_ana_32k; - } - else - { - hDft_ana->dft_trigo = dft_trigo_48k; - hDft_ana->win_ana = win_ana_48k; - } -#endif - return; } #endif @@ -250,7 +231,7 @@ static void write_itd_data_fx( k_offset = 1; move16(); - push_next_indice( hBstr, ( hItd->itd[k_offset] != 0 ), STEREO_DFT_ITD_MODE_NBITS ); + push_next_indice( hBstr, ( hItd->itd_fx[k_offset] != 0 ), STEREO_DFT_ITD_MODE_NBITS ); IF( hItd->itd_fx[k_offset] != 0 ) { @@ -2309,9 +2290,6 @@ ivas_error initMdctItdHandling( /*Initialize ITD parameters*/ stereo_enc_itd_init_fx( hStereoMdct->hItd ); -#if 1 // TODO: To be removed later - stereo_enc_itd_init( hStereoMdct->hItd ); -#endif /*Initialize DFT analysis parameters*/ dft_ana_init( hStereoMdct->hDft_ana, input_Fs ); diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index d308534f0521c961589161e37dca6689a7e1bcd9..683907e8afadb781a19ba4ca054623ffb7b6fa34 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -325,8 +325,8 @@ ivas_error stereo_memory_enc_fx( test(); IF( hCPE->hStereoTCA != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { - set16_fx( hCPE->hStereoTCA->prevCorrLagStats, (Word16) hCPE->hStereoDft->hItd->itd[1], 3 ); - IF( hCPE->hStereoDft->hItd->itd[1] >= 0 ) + set16_fx( hCPE->hStereoTCA->prevCorrLagStats, extract_h( hCPE->hStereoDft->hItd->itd_fx[1] ), 3 ); + IF( hCPE->hStereoDft->hItd->itd_fx[1] >= 0 ) { hCPE->hStereoTCA->prevRefChanIndx = L_CH_INDX; } @@ -632,7 +632,11 @@ ivas_error stereo_memory_enc_fx( { 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(); /* allocate and initialize MDCT stereo structure */ @@ -676,7 +680,10 @@ ivas_error stereo_memory_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n" ) ); } } - dtx_enc_init( st, 0, FIXED_SID_RATE ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr( st->lsp_old1, st->lsp_old1_fx, Q15, M ); +#endif + dtx_enc_init_fx( st, 0, FIXED_SID_RATE ); IF( st->hTdCngEnc != NULL ) { diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index c646d41f27263552015f81450e2a9e3b63090d32..b2dd2863fdb5c0ce8e2e81f658c9193c185f1e5a 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -468,7 +468,6 @@ void stereo_tcx_core_enc( Q_new = q_comm_Bin - ( QSCALE - 2 ); const Word16 Q_ener = Q_new + Q_SCALE - 2; // Q_new + Q_SCALE -2 - st->stab_fac_fx = float_to_fix16( st->stab_fac, Q15 ); floatToFixed_arrL( st->Bin_E_old, st->Bin_E_old_fx, q_comm_Bin, 128 ); floatToFixed_arrL( st->Bin_E, st->Bin_E_fx, q_comm_Bin, 256 ); floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); @@ -486,8 +485,6 @@ void stereo_tcx_core_enc( floatToFixed_arrL( st->hTcxEnc->spectrum[0], st->hTcxEnc->spectrum_fx[0], 31 - st->hTcxEnc->spectrum_e[0], N_MAX ); st->hTcxEnc->spectrum_e[1] = st->hTcxEnc->spectrum_e[0]; - hTcxEnc->tcxltp_gain = float_to_fix16( hTcxEnc->tcxltp_gain_flt, Q15 ); - Word16 L_frame = st->L_frame; Word16 L_frameTCX = hTcxEnc->L_frameTCX; Word16 L_spec = st->hTcxCfg->tcx_coded_lines; @@ -524,10 +521,6 @@ void stereo_tcx_core_enc( { floatToFixed_arr( st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_exc2_buf, Q_exc, HO_HIST_SIZE * L_FFT ); } - if ( st->hDtxEnc != NULL ) - { - floatToFixed_arr( st->hDtxEnc->lspCNG, st->hDtxEnc->lspCNG_fx, Q15, M ); - } floatToFixed_arr( st->synth_flt, st->synth, Q_new, st->L_frame ); floatToFixed_arr( st->hLPDmem->syn_flt, st->hLPDmem->syn, Q_new, M + 1 ); diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index bf22fb6011bdbe01a7d163374255bc8f9d1f51bc..4ba0f3444b7c78167119e8248bd2b2a500c492b1 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -479,14 +479,6 @@ ivas_error IVAS_ENC_FeedObjectMetadata( Word32 yaw_fx = float_to_fix( metadata.yaw, Q22 ); /* Q22 */ Word32 pitch_fx = float_to_fix( metadata.pitch, Q22 ); /* Q22 */ error = ivas_set_ism_metadata_fx( hIvasEnc->st_ivas->hIsmMetaData[ismIndex], azimuth_fx, elevation_fx, radius_fx, yaw_fx, pitch_fx, metadata.non_diegetic_flag ); - - /*================fix-to-flt====================*/ - hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->azimuth = fix_to_float( azimuth_fx, Q22 ); - hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->elevation = fix_to_float( elevation_fx, Q22 ); - hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->radius = fix_to_float( radius_fx, Q9 ); - hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->yaw = fix_to_float( yaw_fx, Q22 ); - hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->pitch = fix_to_float( pitch_fx, Q22 ); - /*================fix-to-flt====================*/ #else error = ivas_set_ism_metadata( hIvasEnc->st_ivas->hIsmMetaData[ismIndex], metadata.azimuth, metadata.elevation, metadata.radius, metadata.yaw, metadata.pitch, metadata.non_diegetic_flag ); #endif @@ -1327,7 +1319,7 @@ static ivas_error configureEncoder_fx( } IF( hEncoderConfig->Opt_DTX_ON && NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) && - ( ( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) && GT_32( ivas_get_sba_num_TCs( hEncoderConfig->ivas_total_brate, 1 ), 2 ) ) || + ( ( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) && GT_32( ivas_get_sba_num_TCs_fx( hEncoderConfig->ivas_total_brate, 1 ), 2 ) ) || EQ_16( hEncoderConfig->ivas_format, MC_FORMAT ) || EQ_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) || EQ_16( hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) ) { return IVAS_ERROR( IVAS_ERR_DTX_NOT_SUPPORTED, "DTX is not supported in this IVAS format and element mode." ); @@ -1567,15 +1559,11 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( { st_ivas->codec_mode = MODE1; move16(); - test(); - IF( NE_16( hEncoderConfig->element_mode_init, EVS_MONO ) ) - { - reset_rf_indices( hCoreCoder->hRF, hCoreCoder->L_frame, &( hCoreCoder->rf_target_bits_write ) ); - } - ELSE - { - reset_rf_indices_fx( hCoreCoder ); - } +#ifndef IVAS_FLOAT_FIXED + reset_rf_indices( hCoreCoder->hRF, hCoreCoder->L_frame, &( hCoreCoder->rf_target_bits_write ) ); +#else + reset_rf_indices_fx( hCoreCoder ); +#endif } hEncoderConfig->Opt_RF_ON = 0; move16(); @@ -1592,15 +1580,11 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( test(); if ( hEncoderConfig->Opt_RF_ON == 0 && EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) { - test(); - IF( NE_16( hEncoderConfig->element_mode_init, EVS_MONO ) ) - { - reset_rf_indices( hCoreCoder->hRF, hCoreCoder->L_frame, &( hCoreCoder->rf_target_bits_write ) ); - } - ELSE - { - reset_rf_indices_fx( hCoreCoder ); - } +#ifndef IVAS_FLOAT_FIXED + reset_rf_indices( hCoreCoder->hRF, hCoreCoder->L_frame, &( hCoreCoder->rf_target_bits_write ) ); +#else + reset_rf_indices_fx( hCoreCoder ); +#endif } hEncoderConfig->Opt_RF_ON = 1; hEncoderConfig->rf_fec_offset = hIvasEnc->rf_fec_offset_loc; @@ -1706,14 +1690,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( IF( hIvasEnc->switchingActive && EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) { test(); - IF( NE_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) ) - { - copy_encoder_config( st_ivas, hCoreCoder, 0 ); - } - ELSE - { - copy_encoder_config_fx( st_ivas, hCoreCoder, 0 ); - } + copy_encoder_config_fx( st_ivas, hCoreCoder, 0 ); hEncoderConfig->last_ivas_total_brate = hEncoderConfig->ivas_total_brate; move32(); } @@ -1726,7 +1703,11 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( IF( EQ_16( hEncoderConfig->stereo_dmx_evs, 1 ) ) { inputBufferSize /= 2; +#ifdef IVAS_FLOAT_FIXED + stereo_dmx_evs_enc_fx( st_ivas->hStereoDmxEVS, hEncoderConfig->input_Fs, inputBuffer, inputBufferSize, hEncoderConfig->is_binaural ); +#else stereo_dmx_evs_enc( st_ivas->hStereoDmxEVS, hEncoderConfig->input_Fs, inputBuffer, inputBufferSize, hEncoderConfig->is_binaural ); +#endif } IF( hEncoderConfig->Opt_AMR_WB ) diff --git a/lib_enc/lsf_enc.c b/lib_enc/lsf_enc.c index a999c061a3f530dd90c642cf592e773e884f9866..965caa246c1a57bc84e63a7c88f070bf8e1044ff 100644 --- a/lib_enc/lsf_enc.c +++ b/lib_enc/lsf_enc.c @@ -50,6 +50,7 @@ #include "ivas_rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------* * Local constants *-----------------------------------------------------------------*/ @@ -2099,3 +2100,4 @@ static void lsf_mid_enc( return; } +#endif diff --git a/lib_enc/ltd_stable_fx.c b/lib_enc/ltd_stable_fx.c index 5006202735a83f73d36e283c25e466b855296137..63ade58a8ce9eddacd3fb3d852aa0415ca57b67b 100644 --- a/lib_enc/ltd_stable_fx.c +++ b/lib_enc/ltd_stable_fx.c @@ -19,11 +19,11 @@ *-------------------------------------------------------------------*/ void ltd_stable_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 *ltd_stable_rate, /* o : time-domain stable rate*/ - const Word32 frame_energy, /* i : current frame energy*/ - const Word16 frameloop, /* i : amount of frames*/ - const Word16 Q_frames_power /* i : the Scaling of frames_power*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 *ltd_stable_rate, /* o : time-domain stable rate*/ + const Word32 frame_energy, /* i : current frame energy*/ + const Word16 frameloop, /* i : amount of frames*/ + const Word16 Q_frames_power /* i : the Scaling of frames_power*/ ) { diff --git a/lib_enc/mdct_classifier.c b/lib_enc/mdct_classifier.c index 4e346a9619b97129b9e9b4c298d834e7b6202000..d555ac555f26acc98c4f5987f5a97141bcb56bea 100644 --- a/lib_enc/mdct_classifier.c +++ b/lib_enc/mdct_classifier.c @@ -42,6 +42,7 @@ #include #include "ivas_prot_fx.h" +#ifndef IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* * Local constants *--------------------------------------------------------------------------*/ @@ -364,3 +365,4 @@ void MDCT_classifier_reset( return; } +#endif diff --git a/lib_enc/mdct_selector.c b/lib_enc/mdct_selector.c index af660e2f8bc54156f9f16775bbb42c98ff2917ca..36d1965707e8ac8784aaf434878e262c72dfb512 100644 --- a/lib_enc/mdct_selector.c +++ b/lib_enc/mdct_selector.c @@ -43,6 +43,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------* * Local constants *-----------------------------------------------------------------*/ @@ -287,3 +288,4 @@ void MDCT_selector_reset( return; } +#endif diff --git a/lib_enc/mdct_selector_fx.c b/lib_enc/mdct_selector_fx.c index bb9de2fb922fb6395e55364847e3d7d5a56139ca..bcca279fcf2cb5cecd04c26d62d4fce20fcf3cd7 100644 --- a/lib_enc/mdct_selector_fx.c +++ b/lib_enc/mdct_selector_fx.c @@ -393,8 +393,9 @@ void MDCT_classifier_reset_fx( ) { hTcxEnc->clas_sec_old_fx = 8192; /* 1.0f in Q13 */ - ; + move16(); hTcxEnc->clas_final_old = 1; /* Q0 */ + move16(); hTcxEnc->last_gain1 = 0; move32(); hTcxEnc->last_gain2 = 0; diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 2d2028492133be369545e790bba461f4a6b2b63d..525c2af46e078cfc4f5465bc75ed9c4a72a84f77 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -967,13 +967,13 @@ static void quant_peaks_ivas_fx( cb_class = w_vquant_fx( x, Qx, weights, 0, hvq_class_c_fx, HVQ_NUM_CLASS, 0 ); IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) { - indx = sub( HVQ_MAX_PEAKS_24k, Npeaks ); + indx = s_max( 0, sub( HVQ_MAX_PEAKS_24k, Npeaks ) ); search_overlap = hvq_cb_search_overlap24k[indx]; move16(); } ELSE { - indx = sub( HVQ_MAX_PEAKS_32k, Npeaks ); + indx = s_max( 0, sub( HVQ_MAX_PEAKS_32k, Npeaks ) ); search_overlap = hvq_cb_search_overlap32k[indx]; move16(); } diff --git a/lib_enc/ppp_enc.c b/lib_enc/ppp_enc.c index 4c9d2db4454f8891fbaa040271e83107c8c810e9..0f21f862978b851a2d788a9f392d6b465580cd3d 100644 --- a/lib_enc/ppp_enc.c +++ b/lib_enc/ppp_enc.c @@ -43,6 +43,7 @@ #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * DTFS_getSpEngyFromResAmp() * @@ -469,3 +470,4 @@ void set_ppp_mode( return; } +#endif diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 83ab7cc1e5807a14dea184a01032905c8ee12e9e..d113f7c4cffbf83766908b152e48c563b6ef902c 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -69,6 +69,25 @@ ivas_error acelp_core_enc_fx( const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ #endif ); +#ifdef IVAS_FLOAT_FIXED +void analy_lp_ivas_fx( + const Word16 speech[], /* i :(Q_new) pointer to the speech frame */ + const Word16 L_frame, /* i :(q0) length of the frame */ + const Word16 L_look, /* i :(q0) look-ahead */ + Word32 *ener, /* o :(Q_r) residual energy from Levinson-Durbin */ + Word16 A[], /* o :(q14) A(z) filter coefficients */ + Word16 epsP_h[], /* o :(high part of epsP(Q_r)) LP analysis residual energies for each iteration */ + Word16 epsP_l[], /* o :(low part of epsP(Q_r)) LP analysis residual energies for each iteration */ + Word16 lsp_new[], /* o :(q15) current frame LSPs */ + Word16 lsp_mid[], /* o :(q15) current mid-frame LSPs */ + Word16 lsp_old[], /* i/o:(q15) previous frame unquantized LSPs */ + const Word16 Top[2], /* i :(q0) open loop pitch lag */ + const Word16 Tnc[2], /* i :(q15) open loop pitch gain */ + const Word32 Core_sr, /* i :(q0) Internal core sampling rate */ + const Word16 sec_chan_low_rate, /* i :(q0) flag to signal second channel */ + Word16 Q_new, /*i: stores Q for speech*/ + Word16 *Q_r /*stores q for ener*/ ); +#endif void analy_lp_fx( const Word16 speech[], /* i : pointer to the speech frame */ @@ -1012,6 +1031,10 @@ void set_bw_fx( const Word16 codec_mode /* i : codec mode */ ); +void set_bw_stereo_fx( + CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structures */ +); + Word16 WB_BWE_encoding_fx( /* o : classification of wb signal */ const Word16 coder_type, /* i : coder type */ const Word16 *yos_fx, /* i : MDCT coefficients of weighted original */ @@ -2331,11 +2354,7 @@ void IGFEncSetMode_fx( const Word16 rf_mode /* i : flag to signal the RF mode */ ); -Word16 vad_init_fx( T_CldfbVadState_fx *vad_state ); - -Word16 vad_init_ivas_fx( - VAD_CLDFB_HANDLE hVAD_CLDFB /* i/o: CLDFB VAD state */ -); +Word16 vad_init_fx( VAD_CLDFB_HANDLE vad_state ); void init_PLC_enc_fx( PLC_ENC_EVS_HANDLE hPlcExt, @@ -2830,7 +2849,7 @@ void midlsf_enc_fx( const Word16 coder_type ); Word16 vad_proc_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real values */ Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag values */ Word16 riBuffer_exp, /* i : exponent of real & imag Buffer */ @@ -2855,15 +2874,15 @@ void calc_lf_snr_fx( ); void calc_lt_snr_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word32 *lt_snr_org_fp, /* o : original long time SNR*/ - Word32 *lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy*/ - Word32 fg_energy, /* i : foreground energy sum */ - Word16 fg_energy_count, /* i : amount of the foreground energy frame */ - Word32 bg_energy, /* i : background energy sum */ - Word16 bg_energy_count, /* i : amount of the background energy frame */ - Word16 bw_index, /* i : band width index*/ - Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32 *lt_snr_org_fp, /* o : original long time SNR*/ + Word32 *lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy*/ + Word32 fg_energy, /* i : foreground energy sum */ + Word16 fg_energy_count, /* i : amount of the foreground energy frame */ + Word32 bg_energy, /* i : background energy sum */ + Word16 bg_energy_count, /* i : amount of the background energy frame */ + Word16 bw_index, /* i : band width index*/ + Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0*/ ); void calc_snr_flux_fx( Word32 tsnr_fix, /*(i) time-domain SNR*/ @@ -2880,24 +2899,24 @@ Word16 vlpc_2st_cod_fx( /* o : number of allocated bits ); Word16 update_decision_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - const Word32 frame_energy, /* i : current frame energy*/ - Word32 HB_Power, /* i : current frame high frequency energy*/ - const Word16 frameloop, /* i : amount of frames*/ - const Word16 bw, /* i : band width index*/ - const Word16 frame_energy_Q, /* i : the Scaling of current frame energy*/ - const Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ - const Word32 snr, /* i : frequency domain SNR */ - const Word32 tsnr, /* i : time domain SNR */ - const Word16 vad_flag, /* i : VAD flag */ - const Word16 music_backgound_f /* i : background music flag*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + const Word32 frame_energy, /* i : current frame energy*/ + Word32 HB_Power, /* i : current frame high frequency energy*/ + const Word16 frameloop, /* i : amount of frames*/ + const Word16 bw, /* i : band width index*/ + const Word16 frame_energy_Q, /* i : the Scaling of current frame energy*/ + const Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ + const Word32 snr, /* i : frequency domain SNR */ + const Word32 tsnr, /* i : time domain SNR */ + const Word16 vad_flag, /* i : VAD flag */ + const Word16 music_backgound_f /* i : background music flag*/ ); void bg_music_decision_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 *music_backgound_f, /*(i) background music flag*/ - Word32 frame_energy, /*(i) current frame energy 1*/ - Word16 frame_energy_Q /*(i) the Scaling of current frame energy*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 *music_backgound_f, /*(i) background music flag*/ + Word32 frame_energy, /*(i) current frame energy 1*/ + Word16 frame_energy_Q /*(i) the Scaling of current frame energy*/ ); void spec_center_fx( @@ -2935,11 +2954,11 @@ void MDCT_classifier_reset_fx( ); void ltd_stable_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 *ltd_stable_rate, /* o : time-domain stable rate*/ - const Word32 frame_energy, /* i : current frame energy*/ - const Word16 frameloop, /* i : amount of frames*/ - const Word16 Q_frames_power /* i : the Scaling of frames_power*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 *ltd_stable_rate, /* o : time-domain stable rate*/ + const Word32 frame_energy, /* i : current frame energy*/ + const Word16 frameloop, /* i : amount of frames*/ + const Word16 Q_frames_power /* i : the Scaling of frames_power*/ ); /* IGFSCFEncoder.c */ void IGFSCFEncoderOpen_fx( @@ -2975,10 +2994,10 @@ void IGFSCFEncoderRestoreContextState_fx( ); void frame_spec_dif_cor_rate_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word32 *spec_amp, /* i : spectral amplitude*/ - Word16 sacle, /* i : the scaling of spec_amp*/ - Word16 f_tonality_rate[3] /* o : tonality rate*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32 *spec_amp, /* i : spectral amplitude*/ + Word16 sacle, /* i : the scaling of spec_amp*/ + Word16 f_tonality_rate[3] /* o : tonality rate*/ ); void est_energy_fx( @@ -2997,11 +3016,11 @@ void est_energy_fx( ); void background_update_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 scale, /* i : the scaling of frame energy*/ - Word32 frame_energy, /* i : current frame energy*/ - Word32 update_flag, /* i : update flag*/ - Word16 music_backgound_f, /* i : background music flag*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 scale, /* i : the scaling of frame energy*/ + Word32 frame_energy, /* i : current frame energy*/ + Word32 update_flag, /* i : update flag*/ + Word16 music_backgound_f, /* i : background music flag*/ Word32 snr ); /* enc_gain.c */ @@ -3034,7 +3053,7 @@ void core_acelp_tcx20_switching_fx( Word16 shift ); Word16 comvad_decision_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ const Word32 l_snr, /*(i) long time frequency domain*/ const Word32 lt_snr_org, /*(i) original long time SNR*/ const Word32 lt_snr, /*(i) long time SNR calculated by fg_energy and bg_energy*/ @@ -3051,12 +3070,12 @@ void amr_wb_enc_init_fx( ); void snr_calc( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - const Word16 sacle_sbpower, /* i : the Scaling of sbpower*/ - Word32 *snr, /* o : frequency domain SNR */ - Word32 *tsnr, /* o : time domain SNR */ - const Word32 frame_energy, /* i : current frame energy */ - const Word32 bwidth /* i : audio band width*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + const Word16 sacle_sbpower, /* i : the Scaling of sbpower*/ + Word32 *snr, /* o : frequency domain SNR */ + Word32 *tsnr, /* o : time domain SNR */ + const Word32 frame_energy, /* i : current frame energy */ + const Word32 bwidth /* i : audio band width*/ ); void FEC_encode_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -4319,11 +4338,13 @@ ivas_error init_encoder_fx( Encoder_State *st_fx /* i/o: Encoder static variables structure */ ); +#ifdef IVAS_FLOAT_FIXED void copy_encoder_config_fx( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ Encoder_State *st, /* o : encoder state structure */ const Word16 flag_all /* i : flag 1==update all, 0=partial update*/ ); +#endif void destroy_encoder_fx( Encoder_State *st_fx /* i/o: Encoder static variables structure */ diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 571636031e5613151337e815d3980fdb49293090..500dd1307ee3b1f573a0c5360591a9df90d2b7dc 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -139,8 +139,10 @@ typedef struct signal_buffers_enc_data_structure /* Delay buffer: Used to buffer input samples and to define the subblock size of a transient detector. */ typedef struct { - int16_t nSubblockSize; /* Subblock size of a transient detector that uses this delay buffer. */ + int16_t nSubblockSize; /* Subblock size of a transient detector that uses this delay buffer. */ +#ifndef IVAS_FLOAT_FIXED float buffer_flt[L_FRAME_MAX / NSUBBLOCKS]; /* Delay buffer */ +#endif Word16 buffer[L_FRAME48k / NSUBBLOCKS]; int16_t nDelay; /* Size of the delay buffer in use. Maximum delay from all users of this buffer. */ @@ -149,27 +151,37 @@ typedef struct /* Subblock energies: Holds subblock energies and recursively accumulated energies. Also buffers the energies. */ typedef struct { - DelayBuffer *pDelayBuffer; /* Delay buffer. */ + DelayBuffer *pDelayBuffer; /* Delay buffer. */ +#ifndef IVAS_FLOAT_FIXED float subblockNrg_flt[NSUBBLOCKS + MAX_TD_DELAY]; /* Subblock energies with a delay buffering. */ +#endif Word32 subblockNrg[NSUBBLOCKS + MAX_TD_DELAY]; Word16 subblockNrg_e; +#ifndef IVAS_FLOAT_FIXED float accSubblockNrg_flt[NSUBBLOCKS + MAX_TD_DELAY + 1]; /* Recursively accumulated subblock energies with a delay buffering. At index i the value corresponds to the accumulated subblock energy up to i-1, including block i-1 and without block i. */ +#endif Word32 accSubblockNrg[NSUBBLOCKS + MAX_TD_DELAY + 1]; Word16 accSubblockNrg_e; +#ifndef IVAS_FLOAT_FIXED float subblockNrgChange_flt[NSUBBLOCKS + MAX_TD_DELAY]; /* subblockNrgChange[i] = max(subblockNrg[i]/subblockNrg[i-1], subblockNrg[i-1]/subblockNrg[i]) */ - Word16 subblockNrgChange[NSUBBLOCKS + MAX_TD_DELAY]; /* Q7(15 - SUBBLOCK_NRG_CHANGE_E) */ - int16_t nDelay; /* Size of the delay buffer in use, as number of subblocks. Maximum delay from all users of this buffer. */ - int16_t nPartialDelay; /* Delay of the input (modulo pDelayBuffer->nSubblockSize), nPartialDelay <= pDelayBuffer->nDelay. */ +#endif + Word16 subblockNrgChange[NSUBBLOCKS + MAX_TD_DELAY]; /* Q7(15 - SUBBLOCK_NRG_CHANGE_E) */ + int16_t nDelay; /* Size of the delay buffer in use, as number of subblocks. Maximum delay from all users of this buffer. */ + int16_t nPartialDelay; /* Delay of the input (modulo pDelayBuffer->nSubblockSize), nPartialDelay <= pDelayBuffer->nDelay. */ /* Decay factor for the recursive accumulation */ +#ifndef IVAS_FLOAT_FIXED float facAccSubblockNrg_flt; +#endif Word16 facAccSubblockNrg; /* High-pass filter states (delay line) */ +#ifndef IVAS_FLOAT_FIXED float firState1_flt; float firState2_flt; +#endif Word16 firState1; Word16 firState2; @@ -190,11 +202,13 @@ typedef struct TransientDetector int16_t nSubblocksToCheck; /* Number of subblocks to check for transients. */ TCheckSubblocksForAttack CheckSubblocksForAttack; /* Function for checking a presence of an attack. */ TCheckSubblocksForAttack_fx CheckSubblocksForAttack_fx; /* Function for checking a presence of an attack. */ - float attackRatioThreshold_flt; /* Attack ratio threshold */ - Word16 attackRatioThreshold; /* Attack ratio threshold Q11 */ - int16_t bIsAttackPresent; /* True when an attack was detected. */ - int16_t prev_bIsAttackPresent; /* True if an attack was detected in the previous frame. */ - int16_t attackIndex; /* The index of an attack. */ +#ifndef IVAS_FLOAT_FIXED + float attackRatioThreshold_flt; /* Attack ratio threshold */ +#endif + Word16 attackRatioThreshold; /* Attack ratio threshold Q11 */ + int16_t bIsAttackPresent; /* True when an attack was detected. */ + int16_t prev_bIsAttackPresent; /* True if an attack was detected in the previous frame. */ + int16_t attackIndex; /* The index of an attack. */ } TransientDetector; /* Transient detection: Holds all transient detectors and buffers used by them. */ @@ -275,79 +289,98 @@ typedef struct cldfb_vad_structure int16_t bw_index; /* index of band width */ /* feature */ - float sp_center[SP_CENTER_NUM]; /* spectral center*/ - float ltd_stable_rate[STABLE_NUM]; /* time-domain stable rate*/ - - float sfm[SFM_NUM]; /* spectral flatness*/ - - float f_tonality_rate[TONA_NUM]; /* tonality rate*/ - float frame_sb_energy[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ - float frames_power[POWER_NUM]; /* energy of several frames*/ - +#ifndef IVAS_FLOAT_FIXED + float sp_center[SP_CENTER_NUM]; /* spectral center*/ + float ltd_stable_rate[STABLE_NUM]; /* time-domain stable rate*/ + float sfm[SFM_NUM]; /* spectral flatness*/ + float f_tonality_rate[TONA_NUM]; /* tonality rate*/ + float frame_sb_energy[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ + float frames_power[POWER_NUM]; /* energy of several frames*/ float pre_spec_low_dif[PRE_SPEC_DIF_NUM]; /* low frequency spectral different*/ - - float t_bg_energy; /* time background energy of several frames*/ - Word32 t_bg_energy_fx; /* time background energy of several frames*/ - float t_bg_energy_sum; /* number of time background energy*/ - Word32 t_bg_energy_sum_fx; /* number of time background energy*/ - int16_t tbg_energy_count; /* sum of time background energy of several frames*/ - int16_t bg_update_count; /* time of background update*/ - float frame_energy_smooth; /* smoothed energy of several frames*/ - Word32 frame_energy_smooth_fx; /* smoothed energy of several frames*/ + float t_bg_energy; /* time background energy of several frames*/ + float t_bg_energy_sum; /* number of time background energy*/ +#else + Word16 sp_center[SP_CENTER_NUM]; /* spectral center*/ + Word16 ltd_stable_rate[STABLE_NUM]; /* time-domain stable rate*/ + Word16 sfm[SFM_NUM]; /* spectral flatness*/ + Word16 f_tonality_rate[TONA_NUM]; /* tonality rate*/ + Word16 pre_spec_low_dif[PRE_SPEC_DIF_NUM]; /* low frequency spectral different*/ + Word16 scale_spec_low_dif; /* the Scaling of spec_low_dif*/ + Word32 frames_power_32[POWER_NUM]; /* energy of several frames*/ + Word16 Q_frames_power_32; /* the Scaling of frames_power_32*/ + Word32 frame_sb_energy[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ + Word16 frame_sb_energy_scale; /* the Scaling of frame_sb_energy*/ + Word32 t_bg_energy; /* time background energy of several frames*/ + Word16 scale_t_bg_energy; /* the Scaling of t_bg_energy*/ + T_VAD_EXP t_bg_energy_sum; /* number of time background energy*/ +#endif + int16_t tbg_energy_count; /* sum of time background energy of several frames*/ + int16_t bg_update_count; /* time of background update*/ +#ifndef IVAS_FLOAT_FIXED + float frame_energy_smooth; /* smoothed energy of several frames*/ +#else + Word32 frame_energy_smooth; /* smoothed energy of several frames*/ + Word16 frame_energy_smooth_scale; /* the Scaling of frame_energy_smooth*/ +#endif /* history parameters */ +#ifndef IVAS_FLOAT_FIXED float smooth_spec_amp[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ float sb_bg_energy[BG_ENG_NUM]; /* sub-band background energy*/ float pre_snr[PRE_SNR_NUM]; /* previous time SNR*/ - - float lt_snr_org; /* original long time SNR*/ - float lf_snr_smooth; /* smoothed lf_snr*/ - float l_silence_snr; /* sum of snr's of non active frames*/ - float l_speech_snr; /* sum of snr's of active frames*/ - Word32 lt_snr_org_fx; /* original long time SNR*/ - Word32 lf_snr_smooth_fx; /* smoothed lf_snr*/ - Word16 l_silence_snr_fx; /* sum of snr's of non active frames*/ - Word32 l_speech_snr_fx; /* sum of snr's of active frames*/ - int16_t l_silence_snr_count; /* number of non active frames*/ - int16_t l_speech_snr_count; /* number of active frames*/ - float fg_energy; /* foreground energy sum */ - float bg_energy; /* background energy sum */ - Word32 fg_energy_fx; /* foreground energy sum */ - Word32 bg_energy_fx; /* background energy sum */ - int16_t fg_energy_count; /* number of the foreground energy frame */ - int16_t bg_energy_count; /* number of the background energy frame */ - int16_t fg_energy_est_start; /* flag by that indicate whether if estimate energy*/ - int16_t speech_flag; /* residual number of hangover 1 */ - int16_t continuous_noise_num; /* time of continuous noise frames*/ - int16_t continuous_speech_num; /* time of continuous speech frames*/ - int16_t continuous_speech_num2; /* time 2 of continuous speech frames*/ - int16_t frameloop; /* number of frame*/ - float tonality_rate3; /* tonality rate*/ - float music_background_rate; /* music background rate*/ - float lt_noise_sp_center_diff_sum; /* different sum of long time noise sp_center*/ - float lt_noise_sp_center_diff_counter; /* number of the member lt_noise_sp_center_diff_sum*/ - float lt_noise_sp_center0; /* long time noise sp_center0*/ - float lt_noise_sp_center3; /* long time noise sp_center3*/ - float lt_bg_highf_eng; /* average of long time high frequency energy*/ - Word16 f_tonality_rate_fx[TONA_NUM]; /* tonality rate*/ - Word32 frame_sb_energy_fx[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ - Word32 frames_power_fx[POWER_NUM]; /* energy of several frames*/ - Word16 pre_spec_low_dif_fx[PRE_SPEC_DIF_NUM]; /* low frequency spectral different*/ - Word32 smooth_spec_amp_fx[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ - Word32 sb_bg_energy_fx[BG_ENG_NUM]; /* sub-band background energy*/ - Word32 pre_snr_fx[PRE_SNR_NUM]; /* previous time SNR*/ - Word16 sfm_fx[SFM_NUM]; /* spectral flatness*/ - Word16 sp_center_fx[SP_CENTER_NUM]; /* spectral center*/ - Word16 ltd_stable_rate_fx[STABLE_NUM]; /* time-domain stable rate*/ - Word16 tonality_rate3_fx; /* tonality rate*/ - Word16 music_background_rate_fx; /* music background rate*/ - Word16 lt_noise_sp_center_diff_sum_fx; /* different sum of long time noise sp_center*/ - Word32 lt_noise_sp_center_diff_counter_fx; /* number of the member lt_noise_sp_center_diff_sum*/ - Word16 lt_noise_sp_center0_fx; /* long time noise sp_center0*/ - Word16 lt_noise_sp_center3_fx; /* long time noise sp_center3*/ - Word32 lt_bg_highf_eng_fx; /* average of long time high frequency energy*/ - int16_t update_num_with_snr_fx; /* the number of the background update with SNR*/ - + float lt_snr_org; /* original long time SNR*/ + float lf_snr_smooth; /* smoothed lf_snr*/ + float l_silence_snr; /* sum of snr's of non active frames*/ + float l_speech_snr; /* sum of snr's of active frames*/ + int16_t l_silence_snr_count; /* number of non active frames*/ + int16_t l_speech_snr_count; /* number of active frames*/ + float fg_energy; /* foreground energy sum */ + float bg_energy; /* background energy sum */ +#else + Word32 smooth_spec_amp[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ + Word32 sb_bg_energy[BG_ENG_NUM]; /* sub-band background energy*/ + Word16 sb_bg_energy_scale; /* the Scaling of sb_bg_energy*/ + Word32 pre_snr[PRE_SNR_NUM]; /* previous time SNR*/ + Word32 lt_snr_org; /* original long time SNR*/ + Word32 lf_snr_smooth; /* smoothed lf_snr*/ + Word32 l_silence_snr; /* sum of snr's of non active frames*/ + Word32 l_speech_snr; /* sum of snr's of active frames*/ + Word32 l_silence_snr_count; /* number of non active frames*/ + Word32 l_speech_snr_count; /* number of active frames*/ + Word32 fg_energy; /* foreground energy sum */ + Word16 fg_energy_scale; /* the Scaling of fg_energy*/ + Word32 bg_energy; /* background energy sum */ + Word16 bg_energy_scale; /* the Scaling of bg_energy*/ +#endif + int16_t fg_energy_count; /* number of the foreground energy frame */ + int16_t bg_energy_count; /* number of the background energy frame */ +#ifndef IVAS_FLOAT_FIXED + int16_t fg_energy_est_start; /* flag by that indicate whether if estimate energy*/ +#else + Word32 fg_energy_est_start; /* flag by that indicate whether if estimate energy*/ +#endif + int16_t speech_flag; /* residual number of hangover 1 */ + int16_t continuous_noise_num; /* time of continuous noise frames*/ + int16_t continuous_speech_num; /* time of continuous speech frames*/ + int16_t continuous_speech_num2; /* time 2 of continuous speech frames*/ + int16_t frameloop; /* number of frame*/ +#ifndef IVAS_FLOAT_FIXED + float tonality_rate3; /* tonality rate*/ + float music_background_rate; /* music background rate*/ + float lt_noise_sp_center_diff_sum; /* different sum of long time noise sp_center*/ + float lt_noise_sp_center_diff_counter; /* number of the member lt_noise_sp_center_diff_sum*/ + float lt_noise_sp_center0; /* long time noise sp_center0*/ + float lt_noise_sp_center3; /* long time noise sp_center3*/ + float lt_bg_highf_eng; /* average of long time high frequency energy*/ +#else + Word16 tonality_rate3; /* tonality rate*/ + Word16 music_background_rate; /* music background rate*/ + Word32 lt_noise_sp_center_diff_sum; /* different sum of long time noise sp_center*/ + Word32 lt_noise_sp_center_diff_counter; /* number of the member lt_noise_sp_center_diff_sum*/ + Word16 lt_noise_sp_center0; /* long time noise sp_center0*/ + Word16 lt_noise_sp_center3; /* long time noise sp_center3*/ + Word32 lt_bg_highf_eng; /* average of long time high frequency energy*/ +#endif int16_t update_num_with_snr; /* the number of the background update with SNR*/ int16_t update_count; int16_t warm_hang_num; /* the number of hangover for warm up*/ @@ -355,68 +388,6 @@ typedef struct cldfb_vad_structure } T_CldfbVadState, *VAD_CLDFB_HANDLE; -typedef struct -{ - Word16 bw_index; /* index of band width */ - - /* feature */ - Word16 sp_center[SP_CENTER_NUM]; /* spectral center*/ - Word16 ltd_stable_rate[STABLE_NUM]; /* time-domain stable rate*/ - Word16 sfm[SFM_NUM]; /* spectral flatness*/ - Word16 f_tonality_rate[TONA_NUM]; /* tonality rate*/ - Word16 pre_spec_low_dif[PRE_SPEC_DIF_NUM]; /* low frequency spectral different*/ - Word32 frames_power_32[POWER_NUM]; /* energy of several frames*/ - Word32 frame_sb_energy[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ - Word32 t_bg_energy; /* time background energy of several frames*/ - T_VAD_EXP t_bg_energy_sum; /* number of time background energy*/ - Word16 tbg_energy_count; /* sum of time background energy of several frames*/ - Word16 bg_update_count; /* time of background update*/ - Word32 frame_energy_smooth; /* smoothed energy of several frames*/ - - /************************************************************************/ - /* history parameters */ - /************************************************************************/ - Word32 smooth_spec_amp[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ - Word32 pre_snr[PRE_SNR_NUM]; /* previous time SNR*/ - Word32 sb_bg_energy[BG_ENG_NUM]; /* sub-band background energy*/ - Word16 continuous_noise_num; /* time of continuous noise frames*/ - Word16 continuous_speech_num; /* time of continuous speech frames*/ - Word16 continuous_speech_num2; /* time 2 of continuous speech frames*/ - Word32 fg_energy_est_start; /* flag by that indicate whether if estimate energy*/ - Word16 speech_flag; /* residual number of hangover 1 */ - Word32 lt_noise_sp_center_diff_counter; /* number of the member lt_noise_sp_center_diff_sum*/ - Word32 fg_energy; /* foreground energy sum */ - Word32 bg_energy; /* background energy sum */ - Word32 lt_bg_highf_eng; /* average of long time high frequency energy*/ - Word32 lt_noise_sp_center_diff_sum; /* different sum of long time noise sp_center*/ - Word32 lt_snr_org; /* original long time SNR*/ - Word32 l_speech_snr; /* sum of snr's of active frames*/ - Word32 l_silence_snr; /* sum of snr's of non active frames*/ - Word32 l_speech_snr_count; /* number of active frames*/ - Word32 l_silence_snr_count; /* number of non active frames*/ - Word32 lf_snr_smooth; /* smoothed lf_snr*/ - Word16 frameloop; /* number of frame*/ - Word16 lt_noise_sp_center0; /* long time noise sp_center0*/ - Word16 lt_noise_sp_center3; /* long time noise sp_center3*/ - Word16 music_background_rate; /* music background rate*/ - Word16 tonality_rate3; /* tonality rate*/ - Word16 bg_energy_count; /* number of the background energy frame */ - Word16 fg_energy_count; /* number of the foreground energy frame */ - Word16 Q_frames_power_32; /* the Scaling of frames_power_fix32*/ - Word16 scale_spec_low_dif; /* the Scaling of spec_low_dif*/ - Word16 sb_bg_energy_scale; /* the Scaling of sb_bg_energy*/ - Word16 frame_sb_energy_scale; /* the Scaling of frame_sb_energy*/ - Word16 scale_t_bg_energy; /* the Scaling of t_bg_energy*/ - Word16 frame_energy_smooth_scale; /* the Scaling of frame_energy_smooth*/ - Word16 bg_energy_scale; /* the Scaling of bg_energy*/ - Word16 fg_energy_scale; /* the Scaling of fg_energy*/ - Word16 updateNumWithSnr; /* the number of the background update with SNR*/ - Word16 update_count; /* the number of the background update*/ - Word16 warm_hang_num; /* the number of hangover for warm up*/ - Word16 vad_flag_for_bk_update; -} T_CldfbVadState_fx, *VAD_CLDFB_HANDLE_FX; - - /*------------------------------------------------------------------------------------------* * DTX and TD CNG structure *------------------------------------------------------------------------------------------*/ @@ -425,32 +396,46 @@ typedef struct td_cng_enc_structure { int16_t lp_cng_mode2; - float lp_ener; /* CNG and DTX - low-pass filtered energy for CNG */ - Word32 lp_ener_fx; /* CNG and DTX - low-pass filtered energy for CNG */ /*Q6*/ - int16_t cng_seed; /* CNG and DTX - seed for white noise random generator */ - int16_t old_enr_index; /* CNG and DTX - index of last encoded CNG energy */ - float Enew; /* CNG and DTX - CNG target residual energy */ - Word32 Enew_fx; /* CNG and DTX - CNG target residual energy */ /*Q6*/ - int16_t cng_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ - float cng_lsp_hist[DTX_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ - float cng_ener_hist[DTX_HIST_SIZE]; /* CNG and DTX - log energy buffer for averaging */ - Word16 cng_lsp_hist_fx[DTX_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ - Word16 cng_ener_hist_fx[DTX_HIST_SIZE]; /* CNG and DTX - log energy buffer for averaging */ - int16_t cng_ener_seed; /* CNG and DTX - seed for random generator for variation of excitation energy */ +#ifndef IVAS_FLOAT_FIXED + float lp_ener; /* CNG and DTX - low-pass filtered energy for CNG */ +#else + Word32 lp_ener_fx; /* CNG and DTX - low-pass filtered energy for CNG Q6 */ +#endif + int16_t cng_seed; /* CNG and DTX - seed for white noise random generator */ + int16_t old_enr_index; /* CNG and DTX - index of last encoded CNG energy */ +#ifndef IVAS_FLOAT_FIXED + float Enew; /* CNG and DTX - CNG target residual energy */ +#else + Word32 Enew_fx; /* CNG and DTX - CNG target residual energy Q6 */ +#endif + int16_t cng_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ +#ifndef IVAS_FLOAT_FIXED + float cng_lsp_hist[DTX_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ + float cng_ener_hist[DTX_HIST_SIZE]; /* CNG and DTX - log energy buffer for averaging */ +#else + Word16 cng_lsp_hist_fx[DTX_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging Q15 */ + Word16 cng_ener_hist_fx[DTX_HIST_SIZE]; /* CNG and DTX - log energy buffer for averaging Q8 */ +#endif + int16_t cng_ener_seed; /* CNG and DTX - seed for random generator for variation of excitation energy */ int16_t cng_ener_seed1; +#ifndef IVAS_FLOAT_FIXED float lp_sp_enr; - - Word16 lp_sp_enr_fx; /*Q8*/ +#else + Word16 lp_sp_enr_fx; /* Q8 */ +#endif int16_t last_allow_cn_step; - int16_t ho_hist_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - int16_t ho_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ - int32_t ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ - Word16 ho_lsp_hist_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ - Word32 ho_ener_hist_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ - Word32 ho_env_hist_fx[HO_HIST_SIZE * NUM_ENV_CNG]; + int16_t ho_hist_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + int16_t ho_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ + int32_t ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ +#ifndef IVAS_FLOAT_FIXED float ho_lsp_hist[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ float ho_ener_hist[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ float ho_env_hist[HO_HIST_SIZE * NUM_ENV_CNG]; +#else + Word16 ho_lsp_hist_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging Q15 */ + Word32 ho_ener_hist_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging Q6 */ + Word32 ho_env_hist_fx[HO_HIST_SIZE * NUM_ENV_CNG]; /* Q6 */ +#endif Word16 ho_lsp_circ_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ @@ -467,36 +452,45 @@ typedef struct td_cng_enc_structure Word16 cng_exc2_buf[HO_HIST_SIZE * L_FFT]; /* CNG and DTX - exc2 buffer for storing */ Word16 cng_Qexc_buf[HO_HIST_SIZE]; /* CNG and DTX - Q_exc buffer for storing */ int32_t cng_brate_buf[HO_HIST_SIZE]; /* CNG and DTX - buffer for storing last_active_brate */ - float CNG_att; /* CNG and DTX - attenuation factor for CNG, in dB */ - Word16 CNG_att_fx; /* CNG and DTX - attenuation factor for CNG, in dB (Q7)*/ - int16_t ho_16k_lsp[HO_HIST_SIZE]; /* CNG and DTX - 16k LSPs flags */ - int16_t act_cnt2; /* CNG and DTX - counter of active frames for CNG_mode switching */ - float ho_lsp_circ2[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs */ - Word16 ho_lsp_circ2_fx[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs */ - int16_t num_ho; /* CNG and DTX - number of selected hangover frames */ +#ifndef IVAS_FLOAT_FIXED + float CNG_att; /* CNG and DTX - attenuation factor for CNG, in dB */ +#else + Word16 CNG_att_fx; /* CNG and DTX - attenuation factor for CNG, in dB Q7 */ +#endif + int16_t ho_16k_lsp[HO_HIST_SIZE]; /* CNG and DTX - 16k LSPs flags */ + int16_t act_cnt2; /* CNG and DTX - counter of active frames for CNG_mode switching */ + float ho_lsp_circ2[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs */ + Word16 ho_lsp_circ2_fx[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs */ + int16_t num_ho; /* CNG and DTX - number of selected hangover frames */ +#ifndef IVAS_FLOAT_FIXED float old_env[NUM_ENV_CNG]; float lp_env[NUM_ENV_CNG]; float cng_res_env[NUM_ENV_CNG * HO_HIST_SIZE]; +#else + Word32 old_env_fx[NUM_ENV_CNG]; /* Q6 */ + Word32 lp_env_fx[NUM_ENV_CNG]; /* Q6 */ + Word32 cng_res_env_fx[NUM_ENV_CNG * HO_HIST_SIZE]; /* Q6 */ +#endif float exc_mem[24]; float exc_mem1[30]; float exc_mem2[30]; - Word32 old_env_fx[NUM_ENV_CNG]; - Word32 lp_env_fx[NUM_ENV_CNG]; - Word32 cng_res_env_fx[NUM_ENV_CNG * HO_HIST_SIZE]; Word16 exc_mem_fx[24]; Word16 exc_mem1_fx[30]; Word16 exc_mem2_fx[30]; /* SWB DTX/CNG parameters */ int16_t last_vad; +#ifndef IVAS_FLOAT_FIXED float last_wb_cng_ener; float last_shb_cng_ener; float mov_wb_cng_ener; float mov_shb_cng_ener; - Word16 last_wb_cng_ener_fx; - Word16 last_shb_cng_ener_fx; - Word16 mov_wb_cng_ener_fx; - Word16 mov_shb_cng_ener_fx; +#else + Word16 last_wb_cng_ener_fx; /* Q8 */ + Word16 last_shb_cng_ener_fx; /* Q8 */ + Word16 mov_wb_cng_ener_fx; /* Q8 */ + Word16 mov_shb_cng_ener_fx; /* Q8 */ +#endif int16_t last_idx_ener; int16_t shb_cng_ini_cnt; int16_t last_SID_bwidth; @@ -632,13 +626,16 @@ 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 */ - float lspCNG[M]; /* CNG and DTX - LP filtered ISPs */ - Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered lsps */ + 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 */ +#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) */ #ifndef IVAS_FLOAT_FIXED @@ -1123,7 +1120,10 @@ typedef struct sp_mus_clas_structure typedef struct lpd_state_structure { + +#ifndef MSAN_FIX Word16 nbits; /* number of bits used by ACELP or TCX */ +#endif /* signal memory */ float syn_flt[1 + M]; /* Synthesis memory (non-pe) */ @@ -1682,22 +1682,28 @@ typedef struct rf_enc_structure ACELP_config acelp_cfg_rf; /* configuration for RF frame */ +#ifndef IVAS_FLOAT_FIXED float rf_mem_w0_flt; float rf_clip_var_flt[6]; float rf_tilt_code_flt; float rf_mem_syn2_flt[M]; float rf_dispMem[8]; float rf_gc_threshold_flt; +#else Word16 rf_mem_w0; Word16 rf_clip_var[6]; Word16 rf_tilt_code; Word16 rf_mem_syn2[M]; struct dispMem_fx rf_dm_fx; Word32 rf_gc_threshold; +#endif int16_t rf_target_bits; +#ifndef IVAS_FLOAT_FIXED float rf_tilt_buf_flt[NB_SUBFR16k]; +#else Word16 rf_tilt_buf[NB_SUBFR16k]; +#endif int16_t rf_indx_lsf[MAX_RF_FEC_OFFSET][3]; int16_t rf_indx_pitch[MAX_RF_FEC_OFFSET][NB_SUBFR16k]; @@ -1828,12 +1834,16 @@ typedef struct tcx_enc_structure float *spectrum[2]; /* MDCT output for a short block */ float spectrum_long[N_MAX]; /* MDCT output for a long block. Points to spectrum */ - float noiseTiltFactor_flt; /* compensation for LPC tilt in noise filling */ - Word16 noiseTiltFactor; /* compensation for LPC tilt in noise filling */ - int16_t noiseLevelMemory_cnt; /* counter of consecutive low TCX noise levels */ +#ifndef IVAS_FLOAT_FIXED + float noiseTiltFactor_flt; /* compensation for LPC tilt in noise filling */ +#else + Word16 noiseTiltFactor; /* compensation for LPC tilt in noise filling Q15 */ +#endif + int16_t noiseLevelMemory_cnt; /* counter of consecutive low TCX noise levels */ +#ifndef IVAS_FLOAT_FIXED float ltpGainMemory[N_LTP_GAIN_MEMS]; /* for smoothing noiseTransWidth */ -#ifdef IVAS_FLOAT_FIXED - Word16 ltpGainMemory_fx[N_LTP_GAIN_MEMS]; /* for smoothing noiseTransWidth */ +#else + Word16 ltpGainMemory_fx[N_LTP_GAIN_MEMS]; /* for smoothing noiseTransWidth Q15 */ #endif STnsData tnsData[2]; // int16_t fUseTns[2]; @@ -1852,19 +1862,26 @@ typedef struct tcx_enc_structure int16_t tcxltp; int16_t tcxltp_pitch_int; int16_t tcxltp_pitch_fr; +#ifndef IVAS_FLOAT_FIXED float tcxltp_gain_flt; - Word16 tcxltp_gain; +#else + Word16 tcxltp_gain; /* Q15 */ +#endif int16_t tcxltp_pitch_int_past; int16_t tcxltp_pitch_fr_past; +#ifndef IVAS_FLOAT_FIXED float tcxltp_gain_past_flt; +#else + Word16 tcxltp_gain_past; /* Q15 */ +#endif float tcxltp_norm_corr_past_flt; - Word16 tcxltp_gain_past; - Word16 tcxltp_norm_corr_past; + Word16 tcxltp_norm_corr_past; /* Q15 */ float tcxltp_norm_corr_mem_flt; + Word16 tcxltp_norm_corr_mem; /* Q15 */ +#ifndef IVAS_FLOAT_FIXED float kernel_switch_corr_past_flt; -#ifdef IVAS_FLOAT_FIXED - Word16 tcxltp_norm_corr_mem; - Word16 kernel_switch_corr_past; +#else + Word16 kernel_switch_corr_past; /* Q15 */ #endif uint16_t kernel_type[2]; /* transform kernel type in each subframe (MDCT or MDST) */ uint16_t kernel_symmetry_past; /* last TDA symmetry (0 for MDCT, 1 for MDST type) */ @@ -1898,25 +1915,36 @@ typedef struct tcx_enc_structure Word16 Q_old_out; /* MDCT switching */ +#ifndef IVAS_FLOAT_FIXED float prev_hi_ener_flt; +#else + Word16 prev_hi_ener; /* Q8 */ +#endif int16_t prev_hi_sparse; +#ifndef IVAS_FLOAT_FIXED float clas_sec_old_flt; +#else + Word16 clas_sec_old_fx; /* Q13 */ +#endif int16_t clas_final_old; +#ifndef IVAS_FLOAT_FIXED float last_gain1_flt; float last_gain2_flt; - // Fix - Word16 prev_hi_ener; - Word16 clas_sec_old_fx; /* MDCT classifier secondary decision memory */ - Word32 last_gain1; - Word32 last_gain2; +#else + Word32 last_gain1; /* Q(31 - st->last_enerBuffer_exp) */ + Word32 last_gain2; /* Q(31 - st->last_enerBuffer_exp) */ +#endif /* TCX memory */ float Txnq_flt[L_FRAME32k / 2 + 64]; /* Q target (overlap or ACELP+ZIR, use Aq) */ float *acelp_zir_flt; - float tcx_target_bits_fac_flt; Word16 Txnq[L_FRAME32k / 2 + 64]; /* Q target (overlap or ACELP+ZIR, use Aq) */ Word16 *acelp_zir; - Word16 tcx_target_bits_fac; // Q14// +#ifndef IVAS_FLOAT_FIXED + float tcx_target_bits_fac_flt; +#else + Word16 tcx_target_bits_fac; /* Q14 */ +#endif int16_t tns_ms_flag[2]; Word32 *spectrum_fx[2]; /* MDCT output for a short block */ @@ -2063,11 +2091,14 @@ typedef struct enc_core_structure Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz */ Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz */ - - int16_t pstreaklen; /* LSF quantizer */ - - float streaklimit; /* LSF quantizer */ - float stab_fac; /* LSF stability factor */ + int16_t pstreaklen; /* LSF quantizer */ +#ifndef IVAS_FLOAT_FIXED + float streaklimit; /* LSF quantizer */ + float stab_fac; /* LSF stability factor */ +#else + Word16 streaklimit_fx; /* LSF quantizer Q15 */ + Word16 stab_fac_fx; /* LSF stability factor Q15 */ +#endif float mem_preemph; /* preemphasis filter memory */ float old_wsp[L_WSP_MEM]; /* old weighted signal vector */ float old_wsp2[( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM]; /* old decimated weighted signal vector */ @@ -2077,14 +2108,12 @@ typedef struct enc_core_structure float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ // Word16 pstreaklen_fx; /* LSF quantizer */ - Word16 streaklimit_fx; /* LSF quantizer */ Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ Word32 offset_scale1_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ Word32 offset_scale2_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/ Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ - Word16 stab_fac_fx; /* LSF stability factor */ Word16 mem_preemph_fx; /* preemphasis filter memory */ @@ -2274,8 +2303,7 @@ typedef struct enc_core_structure VAD_HANDLE hVAD; VAD_CLDFB_HANDLE hVAD_CLDFB; - VAD_CLDFB_HANDLE_FX hVAD_CLDFB_fx; - T_CldfbVadState_fx vad_st; + T_CldfbVadState vad_st; int16_t vad_flag; /* i : VAD flag */ int16_t sharpFlag; @@ -2287,12 +2315,15 @@ typedef struct enc_core_structure Word32 bckr_tilt_lt; /* Q16 */ #endif float lp_speech; - float lp_noise; /* CNG and DTX - LP filtered total noise estimation */ Word16 lp_speech_fx; // Q8 +#ifndef IVAS_FLOAT_FIXED + float lp_noise; /* CNG and DTX - LP filtered total noise estimation */ +#else + Word16 lp_noise_fx; /* CNG and DTX - LP filtered total noise estimation Q8 */ +#endif Word16 Opt_HE_SAD_ON_fx; Word16 nb_active_frames_HE_SAD_fx; Word16 voicing_old_fx; - Word16 lp_noise_fx; /* CNG and DTX - LP filtered total noise estimation Q8 */ Word16 var_SID_rate_flag_fx; /* CNG and DTX - flag for variable SID rate */ Word16 interval_SID_fx; int16_t active_cnt; /* counter of active frames */ @@ -2375,12 +2406,15 @@ typedef struct enc_core_structure * WB, SWB and FB bandwidth detector *----------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED float lt_mean_NB; float lt_mean_WB; float lt_mean_SWB; - Word16 lt_mean_NB_fx; - Word16 lt_mean_WB_fx; - Word16 lt_mean_SWB_fx; +#else + Word16 lt_mean_NB_fx; /* Q11 */ + Word16 lt_mean_WB_fx; /* Q11 */ + Word16 lt_mean_SWB_fx; /* Q11 */ +#endif int16_t count_WB; int16_t count_SWB; int16_t count_FB; @@ -2835,7 +2869,7 @@ typedef struct enc_core_structure // // VAD_HANDLE hVAD; // -// VAD_CLDFB_HANDLE_FX hVAD_CLDFB; +// VAD_CLDFB_HANDLE hVAD_CLDFB; // Word16 lp_speech_fx; // Word16 Opt_HE_SAD_ON_fx; // Word16 nb_active_frames_HE_SAD_fx; diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index d3e56a079a50715e772235e8c98709c1d1024735..ba1fe063ffe54d2e5e0fc47f44d4fbafe68ed7a5 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -4084,7 +4084,11 @@ void fd_bwe_enc_init_fx( set16_fx( hBWE_FD->new_input_hp_fx, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ) ); set16_fx( hBWE_FD->old_input_fx, 0, NS2SA( 48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) ); set16_fx( hBWE_FD->old_input_wb_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ) ); +#ifndef MSAN_FIX set16_fx( hBWE_FD->old_input_lp_fx, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_SWB_TBE_16k_NS ) ); +#else + set16_fx( hBWE_FD->old_input_lp_fx, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ) ); +#endif set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); hBWE_FD->prev_mode = NORMAL; move16(); diff --git a/lib_enc/swb_pre_proc.c b/lib_enc/swb_pre_proc.c index de6cafa5562417d010dec2da88f572bcb16b1924..b8c891d3c131de7b7d568e9a0f9e120b5c929bcd 100644 --- a/lib_enc/swb_pre_proc.c +++ b/lib_enc/swb_pre_proc.c @@ -567,7 +567,7 @@ void swb_pre_proc_ivas_fx( { Word16 out_start_ind, out_end_ind; stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, new_swb_speech_fx, &out_start_ind, &out_end_ind, st->idchan, input_Fs, 32000, 0, NULL ); - Copy_Scale_sig32_16( new_swb_speech_fx, new_swb_speech, q_reImBuffer, L_FRAME48k ); + Copy_Scale_sig32_16( new_swb_speech_fx - STEREO_DFT_OVL_MAX, new_swb_speech - STEREO_DFT_OVL_MAX, q_reImBuffer, L_FRAME48k + STEREO_DFT_OVL_MAX ); Copy( new_swb_speech - Sample_Delay_SWB_BWE32k, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE32k ); } } diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index f75e6050fca3c8d7322ea719b5d2595d3f83133f..18ef67dbf2c04bc0a78813cfa6ceb76068041f08 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -1253,7 +1253,7 @@ void wb_tbe_enc_ivas_fx( FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) { L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); - hb_old_speech[i] = mac_r( L_tmp, hb_speech[j], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); + hb_old_speech[i] = mac_r( L_tmp, hb_speech[k], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); move16(); i = sub( i, 1 ); k = add( k, 1 ); diff --git a/lib_enc/tcx_utils_enc.c b/lib_enc/tcx_utils_enc.c index f377bfb0db9644558725649d7739f19a4cd1ea50..a4225f2ce8d001d8eeaf787e50bffb55f7b8a096 100644 --- a/lib_enc/tcx_utils_enc.c +++ b/lib_enc/tcx_utils_enc.c @@ -1092,6 +1092,7 @@ void tcx_noise_factor( } +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * tcx_encoder_memory_update() * @@ -1153,6 +1154,7 @@ void tcx_encoder_memory_update( return; } +#endif /*---------------------------------------------------------------------* @@ -1603,9 +1605,7 @@ void ProcessIGF_ivas_fx( return; } -#endif - - +#else /*---------------------------------------------------------------------* * ProcessIGF() * @@ -1677,6 +1677,7 @@ void ProcessIGF( return; } +#endif /*---------------------------------------------------------------------* @@ -1684,6 +1685,7 @@ void ProcessIGF( * * *---------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED void ProcessStereoIGF_fx( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, @@ -1777,7 +1779,7 @@ void ProcessStereoIGF_fx( } return; } -#endif +#else void ProcessStereoIGF( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, Encoder_State *sts[CPE_CHANNELS], /* i : Encoder state */ @@ -1858,6 +1860,7 @@ void ProcessStereoIGF( return; } +#endif /*---------------------------------------------------------------------* * attenuateNbSpectrum() diff --git a/lib_enc/tns_base_enc.c b/lib_enc/tns_base_enc.c index 761bbf8baebb8ff7499a7c8ec53225542f3fa480..76cbd6eeb05be00ad64eabc32c129e3ee9104f96 100644 --- a/lib_enc/tns_base_enc.c +++ b/lib_enc/tns_base_enc.c @@ -52,6 +52,7 @@ #define MAX_SUBDIVISIONS 3 +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------------- * Local prototypes *---------------------------------------------------------------------------*/ @@ -92,6 +93,7 @@ int16_t DetectTnsFilt( return ( pTnsData->nFilters > 0 ) ? 1 : 0; } +#endif /*---------------------------------------------------------------------* @@ -145,6 +147,7 @@ void EncodeTnsData( } +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * WriteTnsData() * @@ -483,3 +486,4 @@ static void TnsDecision( return; } +#endif diff --git a/lib_enc/transient_detection.c b/lib_enc/transient_detection.c index fc757ed493706bfb338443709b802d6c9f91e846..b88d296fb83c56bfef3c3218c73595bce4ec48c9 100644 --- a/lib_enc/transient_detection.c +++ b/lib_enc/transient_detection.c @@ -63,17 +63,17 @@ * Local function prototypes *---------------------------------------------------------------*/ -static void InitDelayBuffer( const int16_t nFrameLength, const int16_t nDelay, DelayBuffer *pDelayBuffer ); -static void InitSubblockEnergies( const int16_t nFrameLength, const int16_t nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); -static void InitTransientDetector( SubblockEnergies *pSubblockEnergies, const int16_t nDelay, const int16_t nSubblocksToCheck, TCheckSubblocksForAttack pCheckSubblocksForAttack, const float attackRatioThreshold, TransientDetector *pTransientDetector ); #ifndef IVAS_FLOAT_FIXED static void UpdateDelayBuffer( const float *inputconst, const int16_t nSamplesAvailable, DelayBuffer *pDelayBuffer ); static void HighPassFilter( const float *input, const int16_t length, float *pFirState1, float *pFirState2, float *output ); static void UpdateSubblockEnergies( const float *input, const int16_t nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); static void CalculateSubblockEnergies( const float *input, const int16_t nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); static void RunTransientDetector( TransientDetector *pTransientDetector ); -#endif +static void InitTransientDetector( SubblockEnergies *pSubblockEnergies, const int16_t nDelay, const int16_t nSubblocksToCheck, TCheckSubblocksForAttack pCheckSubblocksForAttack, const float attackRatioThreshold, TransientDetector *pTransientDetector ); +static void InitSubblockEnergies( const int16_t nFrameLength, const int16_t nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); +static void InitDelayBuffer( const int16_t nFrameLength, const int16_t nDelay, DelayBuffer *pDelayBuffer ); static void GetAttackForTCXDecision( const float *pSubblockNrg, const float *pAccSubblockNrg, const int16_t nSubblocks, const int16_t nPastSubblocks, const float attackRatioThreshold, int16_t *pbIsAttackPresent, int16_t *pAttackIndex ); +#endif /*-------------------------------------------------------------------* * InitTransientDetection() @@ -81,6 +81,7 @@ static void GetAttackForTCXDecision( const float *pSubblockNrg, const float *pAc * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void InitTransientDetection( const int16_t nFrameLength, const int16_t nTCXDelay, @@ -109,7 +110,7 @@ void InitTransientDetection( return; } - +#endif /*-------------------------------------------------------------------* * GetTCXAvgTemporalFlatnessMeasure() @@ -117,6 +118,7 @@ void InitTransientDetection( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED float GetTCXAvgTemporalFlatnessMeasure( TRAN_DET_HANDLE hTranDet, const int16_t nCurrentSubblocks, @@ -136,7 +138,9 @@ float GetTCXAvgTemporalFlatnessMeasure( sumTempFlatness = 0.0f; assert( ( nPrevSubblocks <= nRelativeDelay ) && ( nCurrentSubblocks <= NSUBBLOCKS + nDelay ) ); + pSubblockNrgChange = &pSubblockEnergies->subblockNrgChange_flt[nRelativeDelay - nPrevSubblocks]; + for ( i = 0; i < nTotBlocks; i++ ) { sumTempFlatness += pSubblockNrgChange[i]; @@ -144,14 +148,14 @@ float GetTCXAvgTemporalFlatnessMeasure( return sumTempFlatness / (float) nTotBlocks; } - +#endif /*-------------------------------------------------------------------* * GetTCXMaxenergyChange() * * *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED float GetTCXMaxenergyChange( TRAN_DET_HANDLE hTranDet, const int16_t isTCX10, @@ -208,6 +212,7 @@ float GetTCXMaxenergyChange( return maxEnergyChange; } +#endif #ifndef IVAS_FLOAT_FIXED @@ -415,6 +420,7 @@ void SetTCXModeInfo( * See TCheckSubblocksForAttack for definition of parameters. * It is assumed that the delay of MDCT overlap was not taken into account, so that the last subblock corresponds to the newest input subblock. */ +#ifndef IVAS_FLOAT_FIXED static void GetAttackForTCXDecision( const float *pSubblockNrg, const float *pAccSubblockNrg, @@ -506,8 +512,10 @@ static void InitDelayBuffer( return; } +#endif +#ifndef IVAS_FLOAT_FIXED static void InitSubblockEnergies( const int16_t nFrameLength, const int16_t nDelay, @@ -518,21 +526,22 @@ static void InitSubblockEnergies( assert( ( pDelayBuffer != NULL ) && ( pSubblockEnergies != NULL ) && ( pDelayBuffer->nSubblockSize * NSUBBLOCKS == nFrameLength ) && ( pDelayBuffer->nSubblockSize > 0 ) ); - set_f( pSubblockEnergies->subblockNrg_flt, MIN_BLOCK_ENERGY, nMaxBuffSize ); - set_f( pSubblockEnergies->accSubblockNrg_flt, MIN_BLOCK_ENERGY, nMaxBuffSize + 1 ); - set_f( pSubblockEnergies->subblockNrgChange_flt, 1.0f, nMaxBuffSize ); pSubblockEnergies->nDelay = nDelay / pDelayBuffer->nSubblockSize; assert( pSubblockEnergies->nDelay < nMaxBuffSize ); pSubblockEnergies->nPartialDelay = nDelay % pDelayBuffer->nSubblockSize; - pSubblockEnergies->facAccSubblockNrg_flt = 0.8125f; /* Energy accumulation factor */ + set_f( pSubblockEnergies->accSubblockNrg_flt, MIN_BLOCK_ENERGY, nMaxBuffSize + 1 ); + set_f( pSubblockEnergies->subblockNrg_flt, MIN_BLOCK_ENERGY, nMaxBuffSize ); + set_f( pSubblockEnergies->subblockNrgChange_flt, 1.0f, nMaxBuffSize ); pSubblockEnergies->firState1_flt = 0.0f; pSubblockEnergies->firState2_flt = 0.0f; + pSubblockEnergies->facAccSubblockNrg_flt = 0.8125f; /* Energy accumulation factor */ pSubblockEnergies->pDelayBuffer = pDelayBuffer; pDelayBuffer->nDelay = max( pDelayBuffer->nDelay, pSubblockEnergies->nPartialDelay ); return; } +#endif /** Init transient detector. @@ -545,6 +554,7 @@ static void InitSubblockEnergies( * @param attackRatioThreshold Attack ratio threshold. * @param pTransientDetector Structure to be initialized. */ +#ifndef IVAS_FLOAT_FIXED static void InitTransientDetector( SubblockEnergies *pSubblockEnergies, const int16_t nDelay, @@ -572,6 +582,7 @@ static void InitTransientDetector( return; } +#endif #ifndef IVAS_FLOAT_FIXED diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 7000b6fbee742e411a4fcc5cbfac013726264b9a..4c9907b2846451300ecbbacbc882f6df07d5edec 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -44,6 +44,7 @@ static void InitDelayBuffer( Word16 nFrameLength, Word16 nDelay, DelayBuffer *pDelayBuffer ); static void InitSubblockEnergies( Word16 nFrameLength, Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); +static void InitSubblockEnergies_ivas_fx( Word16 nFrameLength, Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); static void InitTransientDetector_fx( SubblockEnergies *pSubblockEnergies, Word16 nDelay, Word16 nSubblocksToCheck, TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, Word16 attackRatioThreshold, TransientDetector *pTransientDetector ); static void UpdateDelayBuffer( Word16 const *input, Word16 nSamplesAvailable, DelayBuffer *pDelayBuffer ); static void HighPassFilter( Word16 const *input, Word16 length, Word16 *pFirState1, Word16 *pFirState2, Word16 *output ); @@ -255,7 +256,7 @@ void InitTransientDetection_ivas_fx( Word16 nFrameLength, /* Init the delay buffer. */ InitDelayBuffer( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer ); /* Init a subblock energies buffer used for the TCX Short/Long decision. */ - InitSubblockEnergies( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer, &pTransientDetection->subblockEnergies ); + InitSubblockEnergies_ivas_fx( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer, &pTransientDetection->subblockEnergies ); /* Init the TCX Short/Long transient detector. */ InitTCXTransientDetector( nTCXDelay, &pTransientDetection->subblockEnergies, &pTransientDetection->transientDetector ); /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ @@ -558,7 +559,11 @@ void RunTransientDetection_ivas_fx( /* Update subblock energies. */ +#ifdef MSAN_FIX + Scale_sig( filteredInput_fx, length, 8 ); +#else Scale_sig( filteredInput_fx, L_FRAME_MAX, 8 ); +#endif Scale_sig32( pSubblockEnergies->subblockNrg, NSUBBLOCKS + MAX_TD_DELAY, 3 ); Scale_sig32( pSubblockEnergies->accSubblockNrg, NSUBBLOCKS + MAX_TD_DELAY + 1, 3 ); Scale_sig( pSubblockEnergies->subblockNrgChange, NSUBBLOCKS + MAX_TD_DELAY, 3 ); @@ -952,6 +957,28 @@ static void InitSubblockEnergies( Word16 nFrameLength, Word16 nDelay, DelayBuffe pDelayBuffer->nDelay = s_max( pDelayBuffer->nDelay, pSubblockEnergies->nPartialDelay ); } +static void InitSubblockEnergies_ivas_fx( Word16 nFrameLength, Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ) +{ + Word16 const nMaxBuffSize = sizeof( pSubblockEnergies->subblockNrg ) / sizeof( pSubblockEnergies->subblockNrg[0] ); + (void) nFrameLength; + + + assert( ( pDelayBuffer != NULL ) && ( pSubblockEnergies != NULL ) && ( pDelayBuffer->nSubblockSize * NSUBBLOCKS == nFrameLength ) && ( pDelayBuffer->nSubblockSize > 0 ) ); + + set32_fx( pSubblockEnergies->subblockNrg, 13743, nMaxBuffSize ); + set32_fx( pSubblockEnergies->accSubblockNrg, 13743, nMaxBuffSize + 1 ); + set16_fx( pSubblockEnergies->subblockNrgChange, ONE_IN_Q7, nMaxBuffSize ); + pSubblockEnergies->nDelay = nDelay / pDelayBuffer->nSubblockSize; + assert( pSubblockEnergies->nDelay < nMaxBuffSize ); + pSubblockEnergies->nPartialDelay = nDelay % pDelayBuffer->nSubblockSize; + pSubblockEnergies->facAccSubblockNrg = 26624 /*0.8125f Q15*/; /* Energy accumulation factor */ + pSubblockEnergies->firState1 = 0; + pSubblockEnergies->firState2 = 0; + + pSubblockEnergies->pDelayBuffer = pDelayBuffer; + pDelayBuffer->nDelay = s_max( pDelayBuffer->nDelay, pSubblockEnergies->nPartialDelay ); +} + /** Init transient detector. * Fills TransientDetector structure with sensible content and enable it. * @param pSubblockEnergies Subblock energies used in this transient detector. diff --git a/lib_enc/update_decision.c b/lib_enc/update_decision.c index 25e7a14d8eb59be0f95d9ddabb31b9f02e7d5ea2..5a31bc31407502ec6fc7f6dd400a73d17c75b125 100644 --- a/lib_enc/update_decision.c +++ b/lib_enc/update_decision.c @@ -41,6 +41,7 @@ #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * bg_music_decision() * @@ -285,3 +286,4 @@ int16_t update_decision( return update_flag; } +#endif diff --git a/lib_enc/update_decision_fx.c b/lib_enc/update_decision_fx.c index c161ac2563bbe1c976a7deccb8c1219d1b99374e..7fda8e5d2047fbc60d3bccab140d6b336b54c85c 100644 --- a/lib_enc/update_decision_fx.c +++ b/lib_enc/update_decision_fx.c @@ -16,10 +16,10 @@ * * -------------------------------------------------------------------*/ void bg_music_decision_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 *music_backgound_f, /* i : background music flag*/ - Word32 frame_energy, /* i : current frame energy 1*/ - Word16 frame_energy_Q /* i : the Scaling of current frame energy*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 *music_backgound_f, /* i : background music flag*/ + Word32 frame_energy, /* i : current frame energy 1*/ + Word16 frame_energy_Q /* i : the Scaling of current frame energy*/ ) { @@ -97,17 +97,17 @@ void bg_music_decision_fx( *-------------------------------------------------------------------*/ Word16 update_decision_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - const Word32 frame_energy, /* i : current frame energy*/ - Word32 HB_Power, /* i : current frame high frequency energy*/ - const Word16 frameloop, /* i : amount of frames*/ - const Word16 bw, /* i : band width index*/ - const Word16 frame_energy_Q, /* i : the Scaling of current frame energy*/ - const Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ - const Word32 snr, /* i : frequency domain SNR */ - const Word32 tsnr, /* i : time domain SNR */ - const Word16 vad_flag, /* i : VAD flag */ - const Word16 music_backgound_f /* i : background music flag*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + const Word32 frame_energy, /* i : current frame energy*/ + Word32 HB_Power, /* i : current frame high frequency energy*/ + const Word16 frameloop, /* i : amount of frames*/ + const Word16 bw, /* i : band width index*/ + const Word16 frame_energy_Q, /* i : the Scaling of current frame energy*/ + const Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ + const Word32 snr, /* i : frequency domain SNR */ + const Word32 tsnr, /* i : time domain SNR */ + const Word16 vad_flag, /* i : VAD flag */ + const Word16 music_backgound_f /* i : background music flag*/ ) { Word16 *sp_center = hVAD_CLDFB->sp_center; @@ -358,17 +358,17 @@ Word16 update_decision_fx( IF( update_flag == 0 ) { - hVAD_CLDFB->updateNumWithSnr = 0; + hVAD_CLDFB->update_num_with_snr = 0; } ELSE { test(); test(); - IF( vad_flag && GT_32( snr, 100663293 /* 3.0 Q25 */ ) && LT_16( hVAD_CLDFB->updateNumWithSnr, 10 ) ) + IF( vad_flag && GT_32( snr, 100663293 /* 3.0 Q25 */ ) && LT_16( hVAD_CLDFB->update_num_with_snr, 10 ) ) { update_flag = 0; move16(); - hVAD_CLDFB->updateNumWithSnr = add( hVAD_CLDFB->updateNumWithSnr, 1 ); + hVAD_CLDFB->update_num_with_snr = add( hVAD_CLDFB->update_num_with_snr, 1 ); } } diff --git a/lib_enc/vad_proc.c b/lib_enc/vad_proc.c index a22e5c2c170997a88ad94722877cd73c4fc49569..630b6b58c999ddd6b4a9851b300efe7168b532d2 100644 --- a/lib_enc/vad_proc.c +++ b/lib_enc/vad_proc.c @@ -42,6 +42,7 @@ #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * vad_init() * @@ -289,3 +290,4 @@ int16_t vad_proc( return vad_flag; } +#endif diff --git a/lib_enc/vad_proc_fx.c b/lib_enc/vad_proc_fx.c index cf235d96df85522ef26ea0524d55c1dd6ce9c644..2c12ec9963d302a67c8be4af01c4e3d35b1563cd 100644 --- a/lib_enc/vad_proc_fx.c +++ b/lib_enc/vad_proc_fx.c @@ -21,7 +21,7 @@ * *-------------------------------------------------------------------*/ Word16 vad_init_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB /* i/o: CLDFB VAD state */ + VAD_CLDFB_HANDLE hVAD_CLDFB /* i/o: CLDFB VAD state */ ) { Word16 i = 0; @@ -33,261 +33,159 @@ Word16 vad_init_fx( hVAD_CLDFB->frameloop = 0; move16(); - hVAD_CLDFB->continuous_noise_num = 0; - move16(); - hVAD_CLDFB->continuous_speech_num = 0; - move16(); - hVAD_CLDFB->continuous_speech_num2 = 0; - move16(); - hVAD_CLDFB->fg_energy_est_start = L_deposit_l( 0 ); - hVAD_CLDFB->speech_flag = 0; - move16(); - hVAD_CLDFB->frame_sb_energy_scale = 0; - move16(); - hVAD_CLDFB->updateNumWithSnr = 0; - move16(); - hVAD_CLDFB->update_count = 0; - move16(); - hVAD_CLDFB->warm_hang_num = 0; - move16(); - - FOR( i = 0; i < SPEC_AMP_NUM; i++ ) - { - hVAD_CLDFB->smooth_spec_amp[i] = L_deposit_l( 0 ); - } - - FOR( i = 0; i < PRE_SNR_NUM; i++ ) - { - hVAD_CLDFB->pre_snr[i] = L_deposit_l( 0 ); - } - - FOR( i = 0; i < BG_ENG_NUM; i++ ) - { - hVAD_CLDFB->frame_sb_energy[i] = L_deposit_l( 0 ); - } - - hVAD_CLDFB->sfm[0] = 28835 /* 0.88 Q15 */; - move16(); - hVAD_CLDFB->sfm[1] = 30146 /* 0.92 Q15 */; - move16(); - hVAD_CLDFB->sfm[2] = 30146 /* 0.92 Q15 */; - move16(); - hVAD_CLDFB->l_silence_snr_count = L_deposit_l( 1 ); - hVAD_CLDFB->l_speech_snr_count = L_deposit_l( 1 ); hVAD_CLDFB->lt_snr_org = 33554432; move32(); hVAD_CLDFB->lf_snr_smooth = 167772155 /* 5.0 Q25 */; move32(); + hVAD_CLDFB->l_silence_snr = 32768 /* 0.5 Q16 */; + move32(); + hVAD_CLDFB->l_speech_snr = 327675 /* 5.0 Q16 */; + move32(); + hVAD_CLDFB->l_silence_snr_count = L_deposit_l( 1 ); + move32(); + hVAD_CLDFB->l_speech_snr_count = L_deposit_l( 1 ); + move32(); hVAD_CLDFB->fg_energy = 1073741824; move32(); hVAD_CLDFB->fg_energy_scale = 41; move16(); - hVAD_CLDFB->bg_energy = 1073741824; move32(); hVAD_CLDFB->bg_energy_scale = 57; move16(); + hVAD_CLDFB->fg_energy_count = 16; + move16(); + hVAD_CLDFB->bg_energy_count = 16; + move16(); + hVAD_CLDFB->tonality_rate3 = 15073 /* 0.46 Q15 */; + move16(); + hVAD_CLDFB->music_background_rate = 15073 /* 0.46 Q15 */; + move16(); + hVAD_CLDFB->lt_noise_sp_center_diff_sum = 409 /* 0.4 Q10 */; + move32(); hVAD_CLDFB->lt_noise_sp_center_diff_counter = L_deposit_l( 4 ); - + move32(); + hVAD_CLDFB->lt_noise_sp_center0 = 1841 /* 0.4 Q10 */; + move16(); + hVAD_CLDFB->lt_noise_sp_center3 = 2046 /* 0.4 Q10 */; + move16(); + hVAD_CLDFB->lt_bg_highf_eng = 131070 /* 2.0 Q16 */; + move32(); hVAD_CLDFB->t_bg_energy = 1374389535; move32(); hVAD_CLDFB->scale_t_bg_energy = 37; move16(); - hVAD_CLDFB->t_bg_energy_sum.s16Exp = 37; move16(); hVAD_CLDFB->t_bg_energy_sum.s32Mantissa = 1374389535; move32(); hVAD_CLDFB->tbg_energy_count = 1; move16(); - hVAD_CLDFB->fg_energy_count = 16; - move16(); - hVAD_CLDFB->bg_energy_count = 16; - move16(); - hVAD_CLDFB->bg_update_count = 0; move16(); hVAD_CLDFB->frame_energy_smooth = 1073741824; move32(); hVAD_CLDFB->frame_energy_smooth_scale = 30; move16(); - hVAD_CLDFB->Q_frames_power_32 = 31; + hVAD_CLDFB->fg_energy_est_start = L_deposit_l( 0 ); + move32(); + hVAD_CLDFB->speech_flag = 0; move16(); - hVAD_CLDFB->lt_bg_highf_eng = 131070 /* 2.0 Q16 */; + hVAD_CLDFB->continuous_noise_num = 0; move16(); - hVAD_CLDFB->lt_noise_sp_center0 = 1841 /* 0.4 Q10 */; + hVAD_CLDFB->continuous_speech_num = 0; move16(); - hVAD_CLDFB->lt_noise_sp_center3 = 2046 /* 0.4 Q10 */; + hVAD_CLDFB->continuous_speech_num2 = 0; move16(); - hVAD_CLDFB->music_background_rate = 15073 /* 0.46 Q15 */; + hVAD_CLDFB->update_num_with_snr = 0; /* the number of the background update with SNR*/ move16(); - hVAD_CLDFB->tonality_rate3 = 15073 /* 0.46 Q15 */; + hVAD_CLDFB->update_count = 0; move16(); - hVAD_CLDFB->lt_noise_sp_center_diff_sum = 409 /* 0.4 Q10 */; - move32(); - hVAD_CLDFB->l_silence_snr = 32768 /* 0.5 Q16 */; - move32(); - hVAD_CLDFB->l_speech_snr = 327675 /* 5.0 Q16 */; - move32(); - - FOR( i = 0; i < SP_CENTER_NUM; i++ ) - { - hVAD_CLDFB->sp_center[i] = 1228 /* 1.2 Q10 */; - move16(); - } - - FOR( i = 0; i < STABLE_NUM; i++ ) - { - hVAD_CLDFB->ltd_stable_rate[i] = 2294 /* 0.07 Q15 */; - move16(); - } - - FOR( i = 0; i < BG_ENG_NUM; i++ ) - { - hVAD_CLDFB->sb_bg_energy[i] = 1374389535; - move32(); - } - hVAD_CLDFB->sb_bg_energy_scale = 37; + hVAD_CLDFB->warm_hang_num = 0; move16(); - hVAD_CLDFB->f_tonality_rate[0] = 7864 /* 0.48 Q14 */; - move16(); - hVAD_CLDFB->f_tonality_rate[1] = 7864 /* 0.48 Q14 */; - move16(); - hVAD_CLDFB->f_tonality_rate[2] = 7864 /* 0.48 Q14 */; + hVAD_CLDFB->frame_sb_energy_scale = 0; move16(); - - FOR( i = 0; i < PRE_SPEC_DIF_NUM; i++ ) + FOR( i = 0; i < PRE_SNR_NUM; i++ ) { - hVAD_CLDFB->pre_spec_low_dif[i] = 4095; - move16(); + hVAD_CLDFB->pre_snr[i] = L_deposit_l( 0 ); + move32(); } - hVAD_CLDFB->scale_spec_low_dif = 12; - move16(); FOR( i = 0; i < 56; i++ ) { hVAD_CLDFB->frames_power_32[i] = L_deposit_l( 0 ); + move32(); } - - return 0; -} - -Word16 vad_init_ivas_fx( - VAD_CLDFB_HANDLE hVAD_CLDFB /* i/o: CLDFB VAD state */ -) -{ - Word16 i = 0; - - IF( hVAD_CLDFB == NULL ) - { - return -1; - } - - hVAD_CLDFB->frameloop = 0; - hVAD_CLDFB->lt_snr_org_fx = 33554432; /*Q26 */ - hVAD_CLDFB->lf_snr_smooth_fx = 167772155 /* 5.0 Q25 */; - hVAD_CLDFB->l_silence_snr_fx = 32767 /* 0.5 Q16 */; - hVAD_CLDFB->l_speech_snr_fx = 327675 /* 5.0 Q16 */; - hVAD_CLDFB->l_silence_snr_count = 1; - hVAD_CLDFB->l_speech_snr_count = 1; - hVAD_CLDFB->fg_energy_fx = 1073741824; - hVAD_CLDFB->bg_energy_fx = 1073741824; - hVAD_CLDFB->fg_energy_count = 16; - hVAD_CLDFB->bg_energy_count = 16; - hVAD_CLDFB->tonality_rate3_fx = 15073 /* 0.46 Q15 */; - hVAD_CLDFB->music_background_rate_fx = 15073 /* 0.46 Q15 */; - hVAD_CLDFB->lt_noise_sp_center_diff_sum_fx = 409 /* 0.4 Q10 */; - hVAD_CLDFB->lt_noise_sp_center_diff_counter_fx = L_deposit_l( 4 ); - hVAD_CLDFB->lt_noise_sp_center0_fx = 1841 /* 0.4 Q10 */; - hVAD_CLDFB->lt_noise_sp_center3_fx = 2046 /* 0.4 Q10 */; - hVAD_CLDFB->lt_bg_highf_eng_fx = 131070 /* 2.0 Q16 */; - hVAD_CLDFB->t_bg_energy_fx = 1374389535; - hVAD_CLDFB->t_bg_energy_sum_fx = 1374389535; - hVAD_CLDFB->tbg_energy_count = 1; - hVAD_CLDFB->bg_update_count = 0; - hVAD_CLDFB->frame_energy_smooth_fx = 1073741824; - hVAD_CLDFB->fg_energy_est_start = 0; - hVAD_CLDFB->speech_flag = 0; - hVAD_CLDFB->continuous_noise_num = 0; - hVAD_CLDFB->continuous_speech_num = 0; - hVAD_CLDFB->continuous_speech_num2 = 0; - hVAD_CLDFB->update_num_with_snr = 0; /* the number of the background update with SNR*/ - hVAD_CLDFB->update_count = 0; - hVAD_CLDFB->warm_hang_num = 0; - - FOR( i = 0; i < PRE_SNR_NUM; i++ ) - { - hVAD_CLDFB->pre_snr_fx[i] = L_deposit_l( 0 ); - } - - FOR( i = 0; i < POWER_NUM; i++ ) - { - hVAD_CLDFB->frames_power_fx[i] = L_deposit_l( 0 ); - } + hVAD_CLDFB->Q_frames_power_32 = 31; + move16(); FOR( i = 0; i < SPEC_AMP_NUM; i++ ) { - hVAD_CLDFB->smooth_spec_amp_fx[i] = L_deposit_l( 0 ); + hVAD_CLDFB->smooth_spec_amp[i] = L_deposit_l( 0 ); + move32(); } - hVAD_CLDFB->sfm_fx[0] = 28835 /* 0.88 Q15 */; + hVAD_CLDFB->sfm[0] = 28835 /* 0.88 Q15 */; move16(); - hVAD_CLDFB->sfm_fx[1] = 30146 /* 0.92 Q15 */; + hVAD_CLDFB->sfm[1] = 30146 /* 0.92 Q15 */; move16(); - hVAD_CLDFB->sfm_fx[2] = 30146 /* 0.92 Q15 */; + hVAD_CLDFB->sfm[2] = 30146 /* 0.92 Q15 */; move16(); FOR( i = 0; i < SP_CENTER_NUM; i++ ) { - hVAD_CLDFB->sp_center_fx[i] = 1228 /* 1.2 Q10 */; + hVAD_CLDFB->sp_center[i] = 1228 /* 1.2 Q10 */; move16(); } FOR( i = 0; i < STABLE_NUM; i++ ) { - hVAD_CLDFB->ltd_stable_rate_fx[i] = 2294 /* 0.07 Q15 */; + hVAD_CLDFB->ltd_stable_rate[i] = 2294 /* 0.07 Q15 */; move16(); } FOR( i = 0; i < BG_ENG_NUM; i++ ) { - hVAD_CLDFB->sb_bg_energy_fx[i] = 1374389535; + hVAD_CLDFB->sb_bg_energy[i] = 1374389535; + move32(); + hVAD_CLDFB->frame_sb_energy[i] = L_deposit_l( 0 ); move32(); } - FOR( i = 0; i < BG_ENG_NUM; i++ ) - { - hVAD_CLDFB->frame_sb_energy_fx[i] = L_deposit_l( 0 ); - } + hVAD_CLDFB->sb_bg_energy_scale = 37; + move16(); - hVAD_CLDFB->f_tonality_rate_fx[0] = 7864 /* 0.48 Q14 */; + hVAD_CLDFB->f_tonality_rate[0] = 7864 /* 0.48 Q14 */; move16(); - hVAD_CLDFB->f_tonality_rate_fx[1] = 7864 /* 0.48 Q14 */; + hVAD_CLDFB->f_tonality_rate[1] = 7864 /* 0.48 Q14 */; move16(); - hVAD_CLDFB->f_tonality_rate_fx[2] = 7864 /* 0.48 Q14 */; + hVAD_CLDFB->f_tonality_rate[2] = 7864 /* 0.48 Q14 */; move16(); - FOR( i = 0; i < PRE_SPEC_DIF_NUM; i++ ) { - hVAD_CLDFB->pre_spec_low_dif_fx[i] = 4095; + hVAD_CLDFB->pre_spec_low_dif[i] = 4095; move16(); } + hVAD_CLDFB->scale_spec_low_dif = 12; + move16(); + return 0; } + static void UpdateState( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 vad_flag, /* i : VAD flag */ - Word32 frame_energy, /* i : current frame energy */ - Word16 sacle_sbpower, /* i : the Scaling of current frame energy */ - Word32 update_flag, /* i : current frame update flag */ - Word16 music_backgound_f, /* i : background music flag */ - Word32 HB_Power, /* i : current frame high frequency energy */ - Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 vad_flag, /* i : VAD flag */ + Word32 frame_energy, /* i : current frame energy */ + Word16 sacle_sbpower, /* i : the Scaling of current frame energy */ + Word32 update_flag, /* i : current frame update flag */ + Word16 music_backgound_f, /* i : background music flag */ + Word32 HB_Power, /* i : current frame high frequency energy */ + Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ Word32 snr ) { Word16 lt_bg_energy_scal; @@ -361,7 +259,7 @@ static void UpdateState( Word16 vad_proc_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real values */ Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag values */ Word16 riBuffer_exp, /* i : exponent of real & imag Buffer */ diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 255ad1b24a97d3a0f139657b3bd6f144e05673db..78ebf384d9e03d955c9cdce0e1a40b339613a2ec 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -306,22 +306,22 @@ static ivas_error ivas_rend_initCrend_fx( { hHrtf->max_num_ir = sub( hHrtf->max_num_ir, 1 ); /* subtract LFE */ move16(); - hHrtf->gain_lfe_fx = GAIN_LFE_FX; + hHrtf->gain_lfe_fx = GAIN_LFE_FX; // Q14 move16(); IF( EQ_32( output_Fs, 48000 ) ) { IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx; - hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_48kHz; - hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_48kHz; + hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx; // Q31 + hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_48kHz; // Q0 + hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_48kHz; // Q0 } ELSE { - hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx; - hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_48kHz; - hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_48kHz; + hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx; // Q31 + hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_48kHz; // Q0 + hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_48kHz; // Q0 } move32(); move16(); @@ -331,19 +331,19 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_48kHz[j]; - hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_48kHz[j]; + hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_48kHz[j]; // Q0 + hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_48kHz[j]; // Q0 - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_48kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_48kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31 } ELSE { - hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_48kHz[j]; - hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_48kHz[j]; + hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_48kHz[j]; // Q0 + hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_48kHz[j]; // Q0 - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_48kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_48kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31 } move32(); move32(); @@ -355,15 +355,15 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx; - hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_32kHz; - hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_32kHz; + hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx; // Q31 + hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_32kHz; // Q0 + hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_32kHz; // Q0 } ELSE { - hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx; - hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_32kHz; - hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_32kHz; + hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx; // Q31 + hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_32kHz; // Q0 + hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_32kHz; // Q0 } move32(); move16(); @@ -373,19 +373,19 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_32kHz[j]; - hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_32kHz[j]; + hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_32kHz[j]; // Q0 + hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_32kHz[j]; // Q0 - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_32kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_32kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31 } ELSE { - hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_32kHz[j]; - hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_32kHz[j]; + hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_32kHz[j]; // Q0 + hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_32kHz[j]; // Q0 - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_32kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_32kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31 } move32(); move32(); @@ -397,13 +397,13 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_16kHz; hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_16kHz; } ELSE { - hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_16kHz; hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_16kHz; } @@ -418,16 +418,16 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_16kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_16kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_16kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_16kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31 } ELSE { hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_16kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_16kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_16kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31 } move32(); move32(); @@ -472,11 +472,11 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_BRIR_inv_diffuse_weight_48kHz_fx[tmp]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_BRIR_inv_diffuse_weight_48kHz_fx[tmp]; // Q15 } ELSE { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_HRIR_inv_diffuse_weight_48kHz_fx[tmp]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_HRIR_inv_diffuse_weight_48kHz_fx[tmp]; // Q15 } move16(); @@ -487,16 +487,16 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_48kHz[tmp][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_48kHz[tmp][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_48kHz_fx[tmp][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_48kHz_fx[tmp][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_48kHz_fx[tmp][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_48kHz_fx[tmp][j]; // Q29 } ELSE { hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_48kHz[tmp][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_48kHz[tmp][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_48kHz_fx[tmp][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_48kHz_fx[tmp][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_48kHz_fx[tmp][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_48kHz_fx[tmp][j]; // Q29 } move32(); move32(); @@ -508,11 +508,11 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_BRIR_inv_diffuse_weight_32kHz_fx[tmp]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_BRIR_inv_diffuse_weight_32kHz_fx[tmp]; // Q15 } ELSE { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_HRIR_inv_diffuse_weight_32kHz_fx[tmp]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_HRIR_inv_diffuse_weight_32kHz_fx[tmp]; // Q15 } move16(); @@ -523,16 +523,16 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_32kHz[tmp][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_32kHz[tmp][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_32kHz_fx[tmp][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_32kHz_fx[tmp][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_32kHz_fx[tmp][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_32kHz_fx[tmp][j]; // Q29 } ELSE { hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_32kHz[tmp][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_32kHz[tmp][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_32kHz_fx[tmp][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_32kHz_fx[tmp][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_32kHz_fx[tmp][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_32kHz_fx[tmp][j]; // Q29 } move32(); move32(); @@ -544,11 +544,11 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_BRIR_inv_diffuse_weight_16kHz_fx[tmp]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_BRIR_inv_diffuse_weight_16kHz_fx[tmp]; // Q15 } ELSE { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_HRIR_inv_diffuse_weight_16kHz_fx[tmp]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_HRIR_inv_diffuse_weight_16kHz_fx[tmp]; // Q15 } move16(); @@ -559,16 +559,16 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_16kHz[tmp][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_16kHz[tmp][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_16kHz_fx[tmp][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_16kHz_fx[tmp][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_16kHz_fx[tmp][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_16kHz_fx[tmp][j]; // Q29 } ELSE { hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_16kHz[tmp][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_16kHz[tmp][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_16kHz_fx[tmp][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_16kHz_fx[tmp][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_16kHz_fx[tmp][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_16kHz_fx[tmp][j]; // Q29 } move32(); move32(); @@ -588,7 +588,7 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_32( output_Fs, 48000 ) ) { - hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_48kHz; hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_48kHz; move32(); @@ -597,7 +597,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_48kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_48kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -605,8 +605,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_48kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_48kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_48kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_48kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_48kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_48kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -618,8 +618,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_48kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_48kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_48kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_48kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -628,7 +628,7 @@ static ivas_error ivas_rend_initCrend_fx( } ELSE IF( EQ_32( output_Fs, 32000 ) ) { - hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_32kHz; hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_32kHz; move32(); @@ -637,7 +637,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_32kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_32kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -645,8 +645,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_32kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_32kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_32kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_32kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_32kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_32kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -659,8 +659,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_32kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_32kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_32kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_32kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -669,7 +669,7 @@ static ivas_error ivas_rend_initCrend_fx( } ELSE IF( EQ_32( output_Fs, 16000 ) ) { - hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_16kHz; hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_16kHz; move32(); @@ -678,7 +678,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_16kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_16kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -686,8 +686,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_16kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_16kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_16kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_16kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_16kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_16kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -700,8 +700,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_16kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_16kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_16kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_16kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -717,7 +717,7 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_32( output_Fs, 48000 ) ) { - hHrtf->latency_s_fx = CRendBin_HOA2_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_HOA2_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_48kHz; hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_48kHz; move32(); @@ -726,7 +726,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_48kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_48kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -734,8 +734,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_48kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_48kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA2_HRIR_coeff_re_48kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA2_HRIR_coeff_im_48kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA2_HRIR_coeff_re_48kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA2_HRIR_coeff_im_48kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -747,8 +747,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_48kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_48kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_48kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_48kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -757,7 +757,7 @@ static ivas_error ivas_rend_initCrend_fx( } ELSE IF( EQ_32( output_Fs, 32000 ) ) { - hHrtf->latency_s_fx = CRendBin_HOA2_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_HOA2_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_32kHz; hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_32kHz; move32(); @@ -766,7 +766,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_32kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_32kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -774,8 +774,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_32kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_32kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA2_HRIR_coeff_re_32kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA2_HRIR_coeff_im_32kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA2_HRIR_coeff_re_32kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA2_HRIR_coeff_im_32kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -788,8 +788,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_32kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_32kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_32kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_32kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -798,7 +798,7 @@ static ivas_error ivas_rend_initCrend_fx( } ELSE IF( EQ_32( output_Fs, 16000 ) ) { - hHrtf->latency_s_fx = CRendBin_HOA2_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_HOA2_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_16kHz; hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_16kHz; move32(); @@ -807,7 +807,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_16kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_16kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -815,8 +815,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_16kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_16kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA2_HRIR_coeff_re_16kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA2_HRIR_coeff_im_16kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA2_HRIR_coeff_re_16kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA2_HRIR_coeff_im_16kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -829,8 +829,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_16kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_16kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_16kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_16kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -846,7 +846,7 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_32( output_Fs, 48000 ) ) { - hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_48kHz; hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_48kHz; move32(); @@ -855,7 +855,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_FOA_HRIR_inv_diffuse_weight_48kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_FOA_HRIR_inv_diffuse_weight_48kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -863,8 +863,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_48kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_48kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_48kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_48kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_48kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_48kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -876,8 +876,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_48kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_48kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_48kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_48kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -886,7 +886,7 @@ static ivas_error ivas_rend_initCrend_fx( } ELSE IF( EQ_32( output_Fs, 32000 ) ) { - hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_32kHz; hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_32kHz; move32(); @@ -895,7 +895,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_FOA_HRIR_inv_diffuse_weight_32kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_FOA_HRIR_inv_diffuse_weight_32kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -903,8 +903,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_32kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_32kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_32kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_32kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_32kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_32kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -917,8 +917,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_32kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_32kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_32kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_32kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -927,7 +927,7 @@ static ivas_error ivas_rend_initCrend_fx( } ELSE IF( EQ_32( output_Fs, 16000 ) ) { - hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_16kHz; hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_16kHz; move32(); @@ -936,7 +936,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_FOA_HRIR_inv_diffuse_weight_16kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_FOA_HRIR_inv_diffuse_weight_16kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -944,8 +944,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_16kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_16kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_16kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_16kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_16kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_16kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -958,8 +958,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_16kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_16kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_16kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -992,13 +992,13 @@ static ivas_error ivas_rend_initCrend_fx( IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_brir_combined->latency_s_fx; + hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_brir_combined->latency_s_fx; // Q31 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_brir_combined->max_num_iterations; hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_brir_combined->index_frequency_max_diffuse; } ELSE { - hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_combined->latency_s_fx; + hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_combined->latency_s_fx; // Q31 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_combined->max_num_iterations; hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_hrir_combined->index_frequency_max_diffuse; } @@ -1013,16 +1013,16 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_brir_combined->num_iterations_diffuse[j]; hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_brir_combined->pIndex_frequency_max_diffuse[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_diffuse_re_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_diffuse_im_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_diffuse_re_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_diffuse_im_fx[j]; // Q31 } ELSE { hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_combined->num_iterations_diffuse[j]; hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_combined->pIndex_frequency_max_diffuse[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_diffuse_re_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_diffuse_im_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_diffuse_re_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_diffuse_im_fx[j]; // Q31 } move32(); move32(); @@ -1060,11 +1060,11 @@ static ivas_error ivas_rend_initCrend_fx( IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_brir_combined->inv_diffuse_weight_fx[tmp]; + hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_brir_combined->inv_diffuse_weight_fx[tmp]; // Q15 } ELSE { - hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_combined->inv_diffuse_weight_fx[tmp]; + hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_combined->inv_diffuse_weight_fx[tmp]; // Q15 } move16(); @@ -1075,16 +1075,16 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_brir_combined->num_iterations[tmp][j]; hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_brir_combined->pIndex_frequency_max[tmp][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_re_fx[tmp][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_im_fx[tmp][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_re_fx[tmp][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_im_fx[tmp][j]; // Q29 } ELSE { hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_combined->num_iterations[tmp][j]; hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_combined->pIndex_frequency_max[tmp][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_re_fx[tmp][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_im_fx[tmp][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_re_fx[tmp][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_im_fx[tmp][j]; // Q29 } move32(); move32(); @@ -1097,7 +1097,7 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA3 ) ) { - hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_hoa3->latency_s_fx; + hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_hoa3->latency_s_fx; // Q31 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_hoa3->max_num_iterations; hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_hrir_hoa3->index_frequency_max_diffuse; move32(); @@ -1106,7 +1106,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_hoa3->inv_diffuse_weight_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_hoa3->inv_diffuse_weight_fx[i]; // Q31 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -1114,8 +1114,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->num_iterations[i][j]; hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->pIndex_frequency_max[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_re_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_im_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_re_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_im_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -1127,8 +1127,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa3->num_iterations_diffuse[j]; hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa3->pIndex_frequency_max_diffuse[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_diffuse_re_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_diffuse_im_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_diffuse_re_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_diffuse_im_fx[j]; // Q31 move32(); move32(); move16(); @@ -1137,7 +1137,7 @@ static ivas_error ivas_rend_initCrend_fx( } ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA2 ) ) { - hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_hoa2->latency_s_fx; + hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_hoa2->latency_s_fx; // Q31 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_hoa2->max_num_iterations; hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_hrir_hoa2->index_frequency_max_diffuse; move32(); @@ -1146,7 +1146,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_hoa2->inv_diffuse_weight_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_hoa2->inv_diffuse_weight_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -1154,8 +1154,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->num_iterations[i][j]; hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->pIndex_frequency_max[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_re_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_im_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_re_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_im_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -1167,8 +1167,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa2->num_iterations_diffuse[j]; hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa2->pIndex_frequency_max_diffuse[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_diffuse_re_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_diffuse_im_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_diffuse_re_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_diffuse_im_fx[j]; // Q31 move32(); move32(); move16(); @@ -1177,7 +1177,7 @@ static ivas_error ivas_rend_initCrend_fx( } ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_FOA ) ) { - hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_foa->latency_s_fx; + hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_foa->latency_s_fx; // Q31 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_foa->max_num_iterations; hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_hrir_foa->index_frequency_max_diffuse; move32(); @@ -1186,7 +1186,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_foa->inv_diffuse_weight_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_foa->inv_diffuse_weight_fx[i]; // Q31 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -1194,8 +1194,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_foa->num_iterations[i][j]; hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_foa->pIndex_frequency_max[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_re_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_im_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_re_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_im_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -1207,8 +1207,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_foa->num_iterations_diffuse[j]; hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_foa->pIndex_frequency_max_diffuse[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_diffuse_re_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_diffuse_im_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_diffuse_re_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_diffuse_im_fx[j]; // Q31 move32(); move32(); move16(); @@ -2341,7 +2341,7 @@ static ivas_error ivas_er_init_handle( move32(); if ( EQ_16( i, 2 ) ) { - reflections->user_origin_fx[i] = ER_LIST_HEIGHT_FX; + reflections->user_origin_fx[i] = ER_LIST_HEIGHT_FX; // Q22 move32(); } } @@ -2675,7 +2675,7 @@ ivas_error ivas_rend_openCrend( /* Set sample rate and frame size */ - hCrend->reflections->output_Fs_fx = output_Fs; + hCrend->reflections->output_Fs_fx = output_Fs; // Q0 move32(); hCrend->reflections->max_frame_size = extract_l( Mult_32_16( output_Fs, INV_FRAME_PER_SEC_Q15 ) ); @@ -2721,6 +2721,7 @@ void ivas_rend_closeCrend( Word16 i; CREND_HANDLE hCrend; + test(); IF( pCrend == NULL || *pCrend == NULL ) { return; @@ -3086,8 +3087,8 @@ static ivas_error ivas_rend_crendConvolver( const CREND_WRAPPER *pCrend, AUDIO_CONFIG inConfig, AUDIO_CONFIG outConfig, - Word32 *pcm_in[], - Word32 *pcm_out[], + Word32 *pcm_in[], // Qx + Word32 *pcm_out[], // Qx const Word32 output_Fs, const Word16 i_ts ) { @@ -3149,26 +3150,26 @@ static ivas_error ivas_rend_crendConvolver( move16(); FOR( idx_in = 0; idx_in < nchan_in; idx_in++ ) { - pIn = &pcm_in[idx_in][imult1616( i_ts, subframe_length )]; + pIn = &pcm_in[idx_in][i_ts * subframe_length]; IF( NE_16( idx_in, lfe_idx_in ) ) { IF( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) { - pFreq_buf_re = &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse]; - pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse]; - pFreq_filt_re = &hCrend->freq_buffer_re_fx[i][offset]; - pFreq_filt_im = &hCrend->freq_buffer_im_fx[i][offset]; + pFreq_buf_re = &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse]; // Qx + pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse]; // Qx + pFreq_filt_re = &hCrend->freq_buffer_re_fx[i][offset]; // Qx + pFreq_filt_im = &hCrend->freq_buffer_im_fx[i][offset]; // Qx FOR( k = 0; k < pCrend->hHrtfCrend->index_frequency_max_diffuse; k++ ) { - pFreq_buf_re[k] = L_add( Mpy_32_16_r( pFreq_filt_re[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[i] ), pFreq_buf_re[k] ); - pFreq_buf_im[k] = L_add( Mpy_32_16_r( pFreq_filt_im[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[i] ), pFreq_buf_im[k] ); + pFreq_buf_re[k] = L_add( Mpy_32_16_r( pFreq_filt_re[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[i] ), pFreq_buf_re[k] ); // Qx + pFreq_buf_im[k] = L_add( Mpy_32_16_r( pFreq_filt_im[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[i] ), pFreq_buf_im[k] ); // Qx move32(); move32(); } } - pFreq_buf_re = &hCrend->freq_buffer_re_fx[i][offset]; - pFreq_buf_im = &hCrend->freq_buffer_im_fx[i][offset]; + pFreq_buf_re = &hCrend->freq_buffer_re_fx[i][offset]; // Qx + pFreq_buf_im = &hCrend->freq_buffer_im_fx[i][offset]; // Qx ivas_mdft_fx( pIn, pFreq_buf_re, pFreq_buf_im, subframe_length, subframe_length ); @@ -3198,15 +3199,15 @@ static ivas_error ivas_rend_crendConvolver( offset_in = offset_in % ( pCrend->hHrtfCrend->max_num_iterations ); move16(); offset_in = imult1616( offset_in, subframe_length ); - pFreq_buf_re = &hCrend->freq_buffer_re_fx[i][offset_in]; - pFreq_buf_im = &hCrend->freq_buffer_im_fx[i][offset_in]; - pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_re_fx[i][j][offset]; - pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_im_fx[i][j][offset]; + pFreq_buf_re = &hCrend->freq_buffer_re_fx[i][offset_in]; // Qx + pFreq_buf_im = &hCrend->freq_buffer_im_fx[i][offset_in]; // Qx + pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_re_fx[i][j][offset]; // Q29 + pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_im_fx[i][j][offset]; // Q29 FOR( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max[i][j][m]; k++ ) { - tmp_out_re[k] = L_add( L_shl( Msub_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_re[k] ), pFreq_buf_im[k], pFreq_filt_im[k] ), 2 ), tmp_out_re[k] ); - tmp_out_im[k] = L_add( L_shl( Madd_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_im[k] ), pFreq_buf_im[k], pFreq_filt_re[k] ), 2 ), tmp_out_im[k] ); + tmp_out_re[k] = L_add( L_shl( Msub_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_re[k] ), pFreq_buf_im[k], pFreq_filt_im[k] ), 2 ), tmp_out_re[k] ); // Qx + tmp_out_im[k] = L_add( L_shl( Madd_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_im[k] ), pFreq_buf_im[k], pFreq_filt_re[k] ), 2 ), tmp_out_im[k] ); // Qx move32(); move32(); } @@ -3224,14 +3225,14 @@ static ivas_error ivas_rend_crendConvolver( offset_diffuse = offset_diffuse % pCrend->hHrtfCrend->num_iterations_diffuse[0]; move16(); offset_diffuse = imult1616( offset_diffuse, subframe_length ); - pFreq_buf_re = &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse]; - pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse]; - pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_re_fx[j][offset]; - pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_im_fx[j][offset]; + pFreq_buf_re = &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse]; // Qx + pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse]; // Qx + pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_re_fx[j][offset]; // Q31 + pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_im_fx[j][offset]; // Q31 FOR( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max_diffuse[j][m]; k++ ) { - tmp_out_re[k] = L_add( Msub_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_re[k] ), pFreq_buf_im[k], pFreq_filt_im[k] ), tmp_out_re[k] ); - tmp_out_im[k] = L_add( Madd_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_im[k] ), pFreq_buf_im[k], pFreq_filt_re[k] ), tmp_out_im[k] ); + tmp_out_re[k] = L_add( Msub_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_re[k] ), pFreq_buf_im[k], pFreq_filt_im[k] ), tmp_out_re[k] ); // Qx + tmp_out_im[k] = L_add( Madd_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_im[k] ), pFreq_buf_im[k], pFreq_filt_re[k] ), tmp_out_im[k] ); // Qx move32(); move32(); } @@ -3243,11 +3244,11 @@ static ivas_error ivas_rend_crendConvolver( #ifdef DEBUGGING dbgwrite_txt( (const float *) pOut, subframe_length << 1, "Fixed_imdft_out.txt", NULL ); #endif - pFreq_buf_re = &pcm_out[j][imult1616( i_ts, subframe_length )]; + pFreq_buf_re = &pcm_out[j][i_ts * subframe_length]; FOR( k = 0; k < subframe_length; k++ ) { - pFreq_buf_re[k] = L_add( pOut[k], hCrend->prev_out_buffer_fx[j][k] ); - hCrend->prev_out_buffer_fx[j][k] = pOut[add( k, subframe_length )]; + pFreq_buf_re[k] = L_add( pOut[k], hCrend->prev_out_buffer_fx[j][k] ); // Qx + hCrend->prev_out_buffer_fx[j][k] = pOut[k + subframe_length]; // Qx move32(); move32(); } @@ -3454,7 +3455,7 @@ ivas_error ivas_rend_crendProcess( COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, IVAS_OUTPUT_SETUP_HANDLE hIntSetup, EFAP_HANDLE hEFAPdata, - Word32 *output_fx[], /* i/o: input/output audio channels */ + Word32 *output_fx[], /* i/o: input/output audio channels Qx */ const Word32 output_Fs, const Word16 num_subframes /* i : number of subframes to render */ ) @@ -3735,8 +3736,8 @@ ivas_error ivas_rend_crendProcessSubframe( const IVAS_OUTPUT_SETUP_HANDLE hIntSetup, /* i : internal setup handle */ const EFAP_HANDLE hEFAPdata, /* i : EFAP handle */ DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: JBM handle */ - Word32 *input_f[], /* i : transport channels */ - Word32 *output[], /* i/o: input/output audio channels */ + Word32 *input_f[], /* i : transport channels Qx */ + Word32 *output[], /* i/o: input/output audio channels Qx */ const Word16 n_samples_to_render, /* i : output frame length per channel */ const Word32 output_Fs /* i : output sampling rate */ ) @@ -3879,7 +3880,7 @@ ivas_error ivas_rend_crendProcessSubframe( { FOR( Word16 j = 0; j < n_samples_to_render; j++ ) { - output[i][j] = L_shr( output[i][j], 2 ); + output[i][j] = L_shr( output[i][j], 2 ); // Q = *pCrend->p_io_qfactor move32(); } } @@ -3887,7 +3888,7 @@ ivas_error ivas_rend_crendProcessSubframe( /* move to output */ FOR( ch = 0; ch < nchan_out; ch++ ) { - MVR2R_WORD32( pcm_tmp_fx[ch], output[ch], n_samples_to_render ); + MVR2R_WORD32( pcm_tmp_fx[ch], output[ch], n_samples_to_render ); // Qx } hTcBuffer->subframes_rendered = last_sf; diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 21c49189e78f281de440d196532e73da5b481157..166c9135aa042bbc9dd087670fcea41a9574ee07 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -2400,7 +2400,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric instEne_fx = Mpy_32_32( inRe_fx[ch][slot][bin], inRe_fx[ch][slot][bin] ); // 2q - 31 instEne_fx = L_add( instEne_fx, Mpy_32_32( inIm_fx[ch][slot][bin], inIm_fx[ch][slot][bin] ) ); // 2q - 31 hDiracDecBin->ChEne_fx[ch][bin] = BASOP_Util_Add_Mant32Exp( hDiracDecBin->ChEne_fx[ch][bin], hDiracDecBin->ChEne_e[ch][bin], instEne_fx, sub( 66, shl( q, 1 ) ), &hDiracDecBin->ChEne_e[ch][bin] ); - subFrameTotalEne_fx[bin] = L_add( subFrameTotalEne_fx[bin], instEne_fx ); // 2q - 31 + subFrameTotalEne_fx[bin] = L_add( subFrameTotalEne_fx[bin], L_shr( instEne_fx, 1 ) ); // 2q - 32 move32(); move32(); } @@ -2408,7 +2408,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric } q = sub( q, 2 ); - q_subFrameTotalEne = sub( shl( q, 1 ), 31 ); + q_subFrameTotalEne = sub( shl( q, 1 ), 32 ); /* Apply EQ at low bit rates */ IF( applyLowBitRateEQ != 0 ) @@ -2417,12 +2417,12 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric FOR( bin = LOW_BIT_RATE_BINAURAL_EQ_OFFSET; bin < lastEqBin; bin++ ) { - subFrameTotalEne_fx[bin] = Mpy_32_32( subFrameTotalEne_fx[bin], lowBitRateEQ_fx[bin] ); // 2q -31 + subFrameTotalEne_fx[bin] = Mpy_32_32( subFrameTotalEne_fx[bin], lowBitRateEQ_fx[bin] ); // 2q -32 move32(); } FOR( ; bin < nBins; bin++ ) { - subFrameTotalEne_fx[bin] = Mpy_32_32( subFrameTotalEne_fx[bin], lowBitRateEQ_fx[lastEqBin] ); // 2q -31 + subFrameTotalEne_fx[bin] = Mpy_32_32( subFrameTotalEne_fx[bin], lowBitRateEQ_fx[lastEqBin] ); // 2q -32 move32(); } } @@ -2434,9 +2434,6 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric Word32 tempRe, tempIm; Word32 subFrameSumEne_fx[CLDFB_NO_CHANNELS_MAX]; - scale_sig32( subFrameTotalEne_fx, nBins, -2 ); - q_subFrameTotalEne = sub( q_subFrameTotalEne, 1 ); - set32_fx( subFrameSumEne_fx, 0, CLDFB_NO_CHANNELS_MAX ); FOR( slot = 0; slot < hSpatParamRendCom->subframe_nbslots[subframe]; slot++ ) { @@ -2444,13 +2441,13 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric { tempRe = L_add( inRe_fx[0][slot][bin], inRe_fx[1][slot][bin] ); // q tempIm = L_add( inIm_fx[0][slot][bin], inIm_fx[1][slot][bin] ); // q - subFrameSumEne_fx[bin] = L_add( subFrameSumEne_fx[bin], L_add( L_shr( Mpy_32_32( tempRe, tempRe ), 1 ), L_shr( Mpy_32_32( tempIm, tempIm ), 1 ) ) ); // 2q -31 + subFrameSumEne_fx[bin] = L_add( subFrameSumEne_fx[bin], L_add( L_shr( Mpy_32_32( tempRe, tempRe ), 1 ), L_shr( Mpy_32_32( tempIm, tempIm ), 1 ) ) ); // 2q -32 move32(); } } FOR( bin = 0; bin < nBins; bin++ ) { - subFrameTotalEne_fx[bin] = L_max( subFrameTotalEne_fx[bin], subFrameSumEne_fx[bin] ); // 2q -31 + subFrameTotalEne_fx[bin] = L_max( subFrameTotalEne_fx[bin], subFrameSumEne_fx[bin] ); // 2q -32 move32(); } } @@ -2477,7 +2474,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric * HRTF data set and a BRIR-based data set. The HRTF data set is spectrally corrected to match * the early spectrum of the BRIR data, using the spectral correction data in * hBinaural->earlyPartEneCorrection[bin], based on the BRIR set. */ - meanEnePerCh_fx = Mpy_32_32( hDiracDecBin->earlyPartEneCorrection_fx[bin], subFrameTotalEne_fx[bin] ); // Q( 2q - 31 ) + meanEnePerCh_fx = Mpy_32_32( hDiracDecBin->earlyPartEneCorrection_fx[bin], subFrameTotalEne_fx[bin] ); // Q( q_meanEnePerCh ) q_meanEnePerCh = sub( add( q_earlyPartEneCorrection, q_subFrameTotalEne ), 30 ); /* Determine direct part target covariance matrix (for 1 or 2 directions) */ FOR( dirIndex = 0; dirIndex < hSpatParamRendCom->numSimultaneousDirections; dirIndex++ ) @@ -4181,12 +4178,12 @@ static void adaptTransportSignalsHeadtracked_fx( Word16 band_idx, bin_lo, bin_hi, norm, shift = 31; Word16 q_chEneIIR = 0, q_procChEneIIR = 0; Word32 temp_div; - Word16 e_div; + Word16 e_div, tmp, is_zero, i; move16(); move16(); move16(); - FOR( Word16 i = 0; i < 6; i++ ) + FOR( i = 0; i < 6; i++ ) { FOR( Word16 j = 0; j < nSlots; j++ ) { @@ -4412,11 +4409,57 @@ static void adaptTransportSignalsHeadtracked_fx( } } - - hHeadTrackData->q_chEneIIR = q_chEneIIR; - hHeadTrackData->q_procChEneIIR = q_procChEneIIR; + is_zero = 1; move16(); + FOR( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) + { + test(); + if ( ( hHeadTrackData->chEneIIR_fx[0][i] != 0 ) || ( hHeadTrackData->chEneIIR_fx[1][i] != 0 ) ) + { + is_zero = 0; + move16(); + BREAK; + } + } + IF( is_zero ) + { + hHeadTrackData->q_chEneIIR = 31; + move16(); + } + ELSE + { + tmp = sub( s_min( getScaleFactor32( hHeadTrackData->chEneIIR_fx[0], MASA_FREQUENCY_BANDS ), getScaleFactor32( hHeadTrackData->chEneIIR_fx[1], MASA_FREQUENCY_BANDS ) ), 1 ); + scale_sig32( hHeadTrackData->chEneIIR_fx[0], MASA_FREQUENCY_BANDS, tmp ); + scale_sig32( hHeadTrackData->chEneIIR_fx[1], MASA_FREQUENCY_BANDS, tmp ); + hHeadTrackData->q_chEneIIR = add( q_chEneIIR, tmp ); + move16(); + } + + is_zero = 1; move16(); + FOR( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) + { + test(); + if ( ( hHeadTrackData->procChEneIIR_fx[0][i] != 0 ) || ( hHeadTrackData->procChEneIIR_fx[1][i] != 0 ) ) + { + is_zero = 0; + move16(); + BREAK; + } + } + IF( is_zero ) + { + hHeadTrackData->q_procChEneIIR = 31; + move16(); + } + ELSE + { + tmp = sub( s_min( getScaleFactor32( hHeadTrackData->procChEneIIR_fx[0], MASA_FREQUENCY_BANDS ), getScaleFactor32( hHeadTrackData->procChEneIIR_fx[1], MASA_FREQUENCY_BANDS ) ), 1 ); + scale_sig32( hHeadTrackData->procChEneIIR_fx[0], MASA_FREQUENCY_BANDS, tmp ); + scale_sig32( hHeadTrackData->procChEneIIR_fx[1], MASA_FREQUENCY_BANDS, tmp ); + hHeadTrackData->q_procChEneIIR = add( q_procChEneIIR, tmp ); + move16(); + } return; } diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index e71bb53418176b22b8c81d562deaecec8e3183dd..ef7f34e829ea49eb7c23da16cc59231f9dc98b57 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -54,18 +54,24 @@ * Local constants *------------------------------------------------------------------------*/ -#define DIRAC_AVG_LENGTH_SYNTH_MS 20 /*averaging length in ms for DirAC synthesis*/ -#define DIRAC_ALPHA_MAX 0.1f -#define DIRAC_ALPHA_MAX_Q15 3276 +#define DIRAC_AVG_LENGTH_SYNTH_MS 20 /*averaging length in ms for DirAC synthesis*/ +#ifndef IVAS_FLOAT_FIXED +#define DIRAC_ALPHA_MAX 0.1f +#endif +#define DIRAC_ALPHA_MAX_Q15 3276 /*0.1f q15*/ #define DIRAC_AVG_LENGTH_SYNTH_MS_FAST 10 -#define DIRAC_ALPHA_MAX_FAST 0.12f -#define DIRAC_ALPHA_MAX_FAST_Q15 3932 -#define DIRECTION_SMOOTHNESS_ALPHA 0.01f -#define DIRECTION_SMOOTHNESS_ALPHA_Q31 ( 21474836 ) +#ifndef IVAS_FLOAT_FIXED +#define DIRAC_ALPHA_MAX_FAST 0.12f +#endif +#define DIRAC_ALPHA_MAX_FAST_Q15 3932 /*0.12f q15*/ +#ifndef IVAS_FLOAT_FIXED +#define DIRECTION_SMOOTHNESS_ALPHA 0.01f +#endif +#define DIRECTION_SMOOTHNESS_ALPHA_Q31 ( 21474836 ) /*0.01f q31*/ #ifdef IVAS_FLOAT_FIXED -#define POINT_3679_Q31 790059234 -#define POINT_1175_Q31 252329329 +#define POINT_3679_Q31 790059234 /*.3679 q31*/ +#define POINT_1175_Q31 252329329 /*.1175 q31*/ #endif /*------------------------------------------------------------------------- @@ -83,7 +89,7 @@ static void computeTargetPSDs_diffuse_subframe_fx( const Word16 num_channels, co static void computeTargetPSDs_diffuse_with_onsets_fx( const Word16 num_channels, const Word16 num_freq_bands, const Word16 num_decorr_freq_bands, const Word16 *proto_frame_diff_index, const Word32 *diffuse_power_factor, const Word32 *reference_power, const Word16 *q_reference_power, const Word32 *diffuse_responses_square, const Word32 *onset_filter, Word32 *cy_auto_diff_smooth, Word16 *q_cy_auto_diff_smooth ); -static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 averaging_length_ms, const Word16 maxAlpha_fx, Word16 *numAlphas, const Word16 slot_size, const Word16 num_freq_bands, Word16 *frequency_axis_fx, const Word32 output_Fs ); +static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx /*q15*/, const Word16 averaging_length_ms, const Word16 maxAlpha_fx /*q15*/, Word16 *numAlphas, const Word16 slot_size, const Word16 num_freq_bands, Word16 *frequency_axis_fx /*q0*/, const Word32 output_Fs ); static void spreadCoherencePanningHoa_fx( const Word16 azimuth, const Word16 elevation, const Word16 spreadCoh_fx, Word32 *direct_response_fx, Word16 *Q_direct_response_hoa, const Word16 num_channels_dir, const Word16 ambisonics_order ); @@ -321,7 +327,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - Copy( temp_alpha_synthesis_fx, dirac_output_synthesis_params->alpha_synthesis_fx, dirac_output_synthesis_params->numAlphas ); + Copy( temp_alpha_synthesis_fx, dirac_output_synthesis_params->alpha_synthesis_fx, dirac_output_synthesis_params->numAlphas ); /*q15*/ computeAlphaSynthesis_fx( temp_alpha_synthesis_fx, DIRAC_AVG_LENGTH_SYNTH_MS_FAST, DIRAC_ALPHA_MAX_FAST_Q15, &dirac_output_synthesis_params->numAlphasFast, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis_fx, output_Fs ); @@ -329,7 +335,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - Copy( temp_alpha_synthesis_fx, dirac_output_synthesis_params->alpha_synthesis_fast_fx, dirac_output_synthesis_params->numAlphasFast ); + Copy( temp_alpha_synthesis_fx, dirac_output_synthesis_params->alpha_synthesis_fast_fx, dirac_output_synthesis_params->numAlphasFast ); /*q15*/ IF( ( dirac_output_synthesis_state->reference_power_smooth_prev_fx = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { @@ -377,10 +383,10 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( FOR( ch_idx = 0; ch_idx < num_diffuse_responses; ++ch_idx ) { /*dirac_output_synthesis_state->diffuse_responses_square[ch_idx] = pow(dirac_output_synthesis_params->diffuse_response_function[ch_idx]/max_response, 2.0f);*/ - tmp_fx = hDirACRend->diffuse_response_function_fx[ch_idx]; + tmp_fx = hDirACRend->diffuse_response_function_fx[ch_idx]; /*q15*/ move16(); - dirac_output_synthesis_state->diffuse_responses_square_fx[ch_idx] = L_mult( tmp_fx, tmp_fx ); /* Q15 + Q15 -> Q31 */ + dirac_output_synthesis_state->diffuse_responses_square_fx[ch_idx] = L_mult( tmp_fx, tmp_fx ); /* Q15 + Q15 + 1 -> Q31 */ move32(); } } @@ -418,28 +424,28 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { diff_nrg_fx = L_shr( L_mult0( hDirACRend->diffuse_response_function_fx[ch_idx], hDirACRend->diffuse_response_function_fx[ch_idx] ), gaurd_bits ); // Q30 - gaurd_bits - diff_nrg_total_fx = L_add( diff_nrg_total_fx, diff_nrg_fx ); + diff_nrg_total_fx = L_add( diff_nrg_total_fx, diff_nrg_fx ); // Q30 - gaurd_bits /* is it a transport channel?*/ test(); if ( ch_idx == 0 || hDirACRend->proto_index_dir[ch_idx] != 0 ) { - diff_nrg_trans_fx = L_add( diff_nrg_trans_fx, diff_nrg_fx ); + diff_nrg_trans_fx = L_add( diff_nrg_trans_fx, diff_nrg_fx ); // Q30 - gaurd_bits } /* is it a decorrelated or transport channel?*/ if ( LT_16( ch_idx, hDirACRend->num_outputs_diff ) ) { - diff_nrg_decorr_fx = L_add( diff_nrg_decorr_fx, diff_nrg_fx ); + diff_nrg_decorr_fx = L_add( diff_nrg_decorr_fx, diff_nrg_fx ); // Q30 - gaurd_bits } } Word16 exp_1 = 0, exp_2 = 0, tmp; move16(); move16(); - tmp = BASOP_Util_Divide3232_Scale( diff_nrg_total_fx, diff_nrg_trans_fx, &exp_1 ); // (Q15 - exp_diff) + tmp = BASOP_Util_Divide3232_Scale( diff_nrg_total_fx, diff_nrg_trans_fx, &exp_1 ); // Q(15 - exp_1) dirac_output_synthesis_params->diffuse_compensation_factor_fx = L_shl( L_deposit_l( tmp ), add( Q12, exp_1 ) ); // Q27 move32(); - tmp = BASOP_Util_Divide3232_Scale( diff_nrg_total_fx, diff_nrg_decorr_fx, &exp_2 ); // (Q15 - exp_diff) + tmp = BASOP_Util_Divide3232_Scale( diff_nrg_total_fx, diff_nrg_decorr_fx, &exp_2 ); // (Q15 - exp_2) dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx = L_shl( L_deposit_l( tmp ), add( Q14, exp_2 ) ); // Q29 move32(); } @@ -1319,17 +1325,17 @@ void ivas_dirac_dec_output_synthesis_process_slot( } #else void ivas_dirac_dec_output_synthesis_process_slot_fx( - const Word32 *reference_power, /* i : Estimated power */ - const Word16 q_reference_power, /* i : Estimated power */ - const Word32 *onset, /* i : onset filter */ + const Word32 *reference_power, /* i : Estimated power Q(q_reference_power)*/ + const Word16 q_reference_power, /* i : Estimated power Q */ + const Word32 *onset, /* i : onset filter Q31*/ const Word16 *azimuth, const Word16 *elevation, - const Word32 *diffuseness, + const Word32 *diffuseness, /* Q(q_diffuseness)*/ Word16 q_diffuseness, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ const Word16 sh_rot_max_order, - const Word32 *p_Rmat, /* i : rotation matrix */ + const Word32 *p_Rmat, /* i : rotation matrix Q30*/ const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */ const IVAS_OUTPUT_SETUP hOutSetup, /* i : output setup structure */ const Word16 nchan_transport, /* i : number of transport channels*/ @@ -1348,7 +1354,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); - h_dirac_output_synthesis_state->onset_filter_fx = onset; + h_dirac_output_synthesis_state->onset_filter_fx = onset; /*Q31*/ /*-----------------------------------------------------------------* * processing @@ -1390,14 +1396,14 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( IF( h_dirac_output_synthesis_state->direct_responses_square_fx ) { - Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, imult1616( num_channels_dir, num_freq_bands ), sub( 31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); + Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, imult1616( num_channels_dir, num_freq_bands ), sub( 31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); /* h_dirac_output_synthesis_state->direct_responses_square_q->Q31*/ h_dirac_output_synthesis_state->direct_responses_square_q = 31; move16(); } - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); /*h_dirac_output_synthesis_state->direct_responses_q->Q31*/ IF( hodirac_flag ) { - Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); + Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir], i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); /*h_dirac_output_synthesis_state->direct_responses_q->Q31*/ } h_dirac_output_synthesis_state->direct_responses_q = 31; move16(); @@ -1409,23 +1415,23 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - v_multc_fixed( hSpatParamRendCom->energy_ratio1_fx[md_idx], -MAX_32, aux_buf, num_freq_bands ); - v_addc_fixed( aux_buf, ONE_IN_Q30, aux_buf, num_freq_bands ); + v_multc_fixed( hSpatParamRendCom->energy_ratio1_fx[md_idx], -MAX_32 /*-1 Q31*/, aux_buf, num_freq_bands ); /* 30 + 31 - 31 -> 30 */ + v_addc_fixed( aux_buf, ONE_IN_Q30 /*1 Q30*/, aux_buf, num_freq_bands ); /*30*/ Copy32( hSpatParamRendCom->energy_ratio1_fx[md_idx], h_dirac_output_synthesis_state->direct_power_factor_fx, - num_freq_bands ); + num_freq_bands ); /*Q30*/ Copy32( aux_buf, h_dirac_output_synthesis_state->diffuse_power_factor_fx, - num_freq_bands ); + num_freq_bands ); /*Q30*/ - v_multc_fixed( hSpatParamRendCom->energy_ratio2_fx[md_idx], -MAX_32, aux_buf, num_freq_bands ); - v_addc_fixed( aux_buf, ONE_IN_Q30, aux_buf, num_freq_bands ); + v_multc_fixed( hSpatParamRendCom->energy_ratio2_fx[md_idx], -MAX_32 /*-1 Q31*/, aux_buf, num_freq_bands ); /*30+31-31->30*/ + v_addc_fixed( aux_buf, ONE_IN_Q30 /*1 Q30*/, aux_buf, num_freq_bands ); /*30*/ Copy32( hSpatParamRendCom->energy_ratio2_fx[md_idx], &h_dirac_output_synthesis_state->direct_power_factor_fx[hSpatParamRendCom->num_freq_bands], - num_freq_bands ); + num_freq_bands ); /*Q30*/ Copy32( aux_buf, &h_dirac_output_synthesis_state->diffuse_power_factor_fx[hSpatParamRendCom->num_freq_bands], - num_freq_bands ); + num_freq_bands ); /*Q30*/ h_dirac_output_synthesis_state->diffuse_power_factor_q = 30; move16(); @@ -1462,14 +1468,14 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { IF( h_dirac_output_synthesis_state->direct_responses_square_fx ) { - Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, imult1616( num_channels_dir, num_freq_bands ), sub( 31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); + Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, imult1616( num_channels_dir, num_freq_bands ), sub( 31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); /*h_dirac_output_synthesis_state->direct_responses_square_q->Q31*/ h_dirac_output_synthesis_state->direct_responses_square_q = 31; move16(); } - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); /*h_dirac_output_synthesis_state->direct_responses_q->Q31*/ IF( hodirac_flag ) { - Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); + Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir], i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); /*h_dirac_output_synthesis_state->direct_responses_q->Q31*/ } h_dirac_output_synthesis_state->direct_responses_q = 31; move16(); @@ -1487,13 +1493,13 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( h_dirac_output_synthesis_state->diffuse_power_factor_q = sub( 31, h_dirac_output_synthesis_state->diffuse_power_factor_q ); v_multc_fixed( h_dirac_output_synthesis_state->direct_power_factor_fx, - ONE_IN_Q29, + ONE_IN_Q29 /*0.25f Q31*/, h_dirac_output_synthesis_state->direct_power_factor_fx, - num_freq_bands ); + num_freq_bands ); /*h_dirac_output_synthesis_state->direct_power_factor_q+Q31-Q31->h_dirac_output_synthesis_state->direct_power_factor_q*/ v_multc_fixed( h_dirac_output_synthesis_state->diffuse_power_factor_fx, - ONE_IN_Q29, + ONE_IN_Q29 /*0.25f Q31*/, h_dirac_output_synthesis_state->diffuse_power_factor_fx, - num_freq_bands ); + num_freq_bands ); /*h_dirac_output_synthesis_state->diffuse_power_factor_q+Q31-Q31->h_dirac_output_synthesis_state->diffuse_power_factor_q*/ /*Direct gain*/ @@ -1519,9 +1525,9 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( /*Directonal sound gain nrg compensation*/ FOR( k = 0; k < num_freq_bands_diff; k++ ) { - a = h_dirac_output_synthesis_state->direct_responses_fx[add( i_mult( ch_idx, num_freq_bands ), k )]; // Q = h_dirac_output_synthesis_state->q_direct_responses + a = h_dirac_output_synthesis_state->direct_responses_fx[ch_idx * num_freq_bands + k]; // Q = h_dirac_output_synthesis_state->q_direct_responses move32(); - IF( reference_power[add( k, num_freq_bands )] == 0 ) + IF( reference_power[k + num_freq_bands] == 0 ) { b = 0; move16(); @@ -1530,68 +1536,68 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( } ELSE { - b = BASOP_Util_Divide3232_Scale( reference_power[add( k, num_freq_bands )], L_add( reference_power[add( k, imult1616( add( ch_idx, 1 ), num_freq_bands ) )], EPSILON_FX ), &b_exp ); + b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], L_add( reference_power[k + ( ch_idx + 1 ) * num_freq_bands], EPSILON_FX ), &b_exp ); /*Q(15-b_exp)*/ } - c = L_add( ONE_IN_Q29, Mpy_32_16_1( L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 ), 5461 ) ); /*Diffuseness modellling nrg compensation*/ /* 1.0 / 6.0 = 5461 in Q15*/ + c = L_add( ONE_IN_Q29 /*1 Q29*/, Mpy_32_16_1( L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 /*1 Q29*/ ), 5461 /*1.0 / 6.0 Q15*/ ) ); /*Diffuseness modellling nrg compensation*/ /*Q29*/ - mpy_a_a_b = Mpy_32_32( a, Mpy_32_16_1( a, b ) ); // Q = (h_dirac_output_synthesis_state->q_direct_responses + (31 - b_exp) - 31) + (h_dirac_output_synthesis_state->q_direct_responses) - 31 - mpy_diff_aab = Mpy_32_32( L_sub( L_shl( 1, q_diffuseness ), diffuseness[k] ), mpy_a_a_b ); // Q = 2*(h_dirac_output_synthesis_state->q_direct_responses) - b_exp - 31 + q_diffuseness -31 - mpy_diff_c = Mpy_32_32( diffuseness[k], c ); // Q = q_diffuseness - 2 + mpy_a_a_b = Mpy_32_32( a, Mpy_32_16_1( a, b ) ); // Q = (h_dirac_output_synthesis_state->q_direct_responses + (15 - b_exp) - 15) + (h_dirac_output_synthesis_state->q_direct_responses) - 31 + mpy_diff_aab = Mpy_32_32( L_sub( L_shl( 1, q_diffuseness ), diffuseness[k] ), mpy_a_a_b ); // Q(q_diff_aab) = 2*(h_dirac_output_synthesis_state->q_direct_responses) - b_exp - 31 + q_diffuseness -31 + mpy_diff_c = Mpy_32_32( diffuseness[k], c ); // Q(q_diff_c) = q_diffuseness - 2 - q_diff_aab = add( sub( add( h_dirac_output_synthesis_state->direct_responses_q, sub( 31, b_exp ) ), 31 ), add( sub( h_dirac_output_synthesis_state->direct_responses_q, 31 ), sub( q_diffuseness, 31 ) ) ); + q_diff_aab = add( sub( add( h_dirac_output_synthesis_state->direct_responses_q, sub( 15, b_exp ) ), 15 ), add( sub( h_dirac_output_synthesis_state->direct_responses_q, 31 ), sub( q_diffuseness, 31 ) ) ); q_diff_c = sub( q_diffuseness, 2 ); test(); IF( mpy_diff_c != 0 && mpy_diff_aab != 0 ) { - sqr_inp = BASOP_Util_Add_Mant32Exp( mpy_diff_c, sub( 31, q_diff_c ), mpy_diff_aab, sub( 31, q_diff_aab ), &sqr_exp ); + sqr_inp = BASOP_Util_Add_Mant32Exp( mpy_diff_c, sub( 31, q_diff_c ), mpy_diff_aab, sub( 31, q_diff_aab ), &sqr_exp ); /*Q(31-sqr_exp)*/ } ELSE { IF( mpy_diff_c == 0 ) { - sqr_inp = mpy_diff_aab; + sqr_inp = mpy_diff_aab; /*Q(q_diff_aab)*/ move32(); sqr_exp = sub( 31, q_diff_aab ); } ELSE { - sqr_inp = mpy_diff_c; + sqr_inp = mpy_diff_c; /*Q(q_diff_c)*/ move32(); sqr_exp = sub( 31, q_diff_c ); } } - sqr = Sqrt32( sqr_inp, &sqr_exp ); - sqr = L_shr( sqr, 2 ); - IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] != 0 ) + sqr = Sqrt32( sqr_inp, &sqr_exp ); /*Q(31-sqr_exp)*/ + sqr = L_shr( sqr, 2 ); /*Q(31-sqr_exp)*/ + IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] != 0 ) { IF( LT_16( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth-> (31-sqr_exp) */ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } ELSE { - sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*( 31- sqr_exp )-> h_dirac_output_synthesis_state->q_cy_cross_dir_smooth*/ + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q_temp_cy_cross_dir_smooth_fx*/ move32(); } ELSE { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*31-sqr_exp*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } } FOR( ; k < num_freq_bands; k++ ) { - a = h_dirac_output_synthesis_state->direct_responses_fx[add( i_mult( ch_idx, num_freq_bands ), k )]; // Q = h_dirac_output_synthesis_state->q_direct_responses + a = h_dirac_output_synthesis_state->direct_responses_fx[ch_idx * num_freq_bands + k]; // Q = h_dirac_output_synthesis_state->q_direct_responses move32(); IF( reference_power[k + num_freq_bands] == 0 ) { @@ -1602,37 +1608,37 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( } ELSE { - IF( reference_power[add( k, imult1616( add( ch_idx, 1 ), num_freq_bands ) )] == 0 ) + IF( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] == 0 ) { - b = MAXVAL_WORD16; + b = MAXVAL_WORD16; /*Q(-9)*/ move16(); b_exp = 40; move16(); } ELSE { - b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], reference_power[add( k, imult1616( add( ch_idx, 1 ), num_freq_bands ) )], &b_exp ); + b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], reference_power[k + ( ch_idx + 1 ) * num_freq_bands], &b_exp ); /*q(15-b_exp)*/ } } - c = L_add( ONE_IN_Q29, Mpy_32_16_1( L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 ), 5461 ) ); /*Diffuseness modellling nrg compensation*/ /* 1.0 / 6.0 = 5461 in Q15*/ + c = L_add( ONE_IN_Q29 /*1 Q29*/, Mpy_32_16_1( L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 /*1 Q29*/ ), 5461 ) ); /*Diffuseness modellling nrg compensation*/ /* 1.0 / 6.0 = 5461 in Q15*/ /*Q29*/ - mpy_a_a_b = Mpy_32_32( a, Mpy_32_16_1( a, b ) ); // Q = (h_dirac_output_synthesis_state->q_direct_responses + (31 - b_exp) - 31) + (h_dirac_output_synthesis_state->q_direct_responses) - 31 + mpy_a_a_b = Mpy_32_32( a, Mpy_32_16_1( a, b ) ); // Q = (h_dirac_output_synthesis_state->q_direct_responses + (15 - b_exp) - 15) + (h_dirac_output_synthesis_state->q_direct_responses) - 31 mpy_diff_aab = Mpy_32_32( L_sub( L_shl( 1, q_diffuseness ), diffuseness[k] ), mpy_a_a_b ); // Q = 2*(h_dirac_output_synthesis_state->q_direct_responses) - b_exp - 31 + q_diffuseness -31 mpy_diff_c = Mpy_32_32( diffuseness[k], c ); // Q = q_diffuseness - 2 - q_diff_aab = add( h_dirac_output_synthesis_state->direct_responses_q + sub( sub( 31, b_exp ), 31 ), add( sub( h_dirac_output_synthesis_state->direct_responses_q, 31 ), sub( q_diffuseness, 31 ) ) ); + q_diff_aab = add( h_dirac_output_synthesis_state->direct_responses_q + sub( sub( 15, b_exp ), 15 ), add( sub( h_dirac_output_synthesis_state->direct_responses_q, 31 ), sub( q_diffuseness, 31 ) ) ); q_diff_c = sub( q_diffuseness, 2 ); test(); IF( mpy_diff_c != 0 && mpy_diff_aab != 0 ) { - sqr_inp = BASOP_Util_Add_Mant32Exp( mpy_diff_c, sub( 31, q_diff_c ), mpy_diff_aab, sub( 31, q_diff_aab ), &sqr_exp ); + sqr_inp = BASOP_Util_Add_Mant32Exp( mpy_diff_c, sub( 31, q_diff_c ), mpy_diff_aab, sub( 31, q_diff_aab ), &sqr_exp ); /*q(31-sqr_exp)*/ } ELSE { IF( mpy_diff_c == 0 ) { - sqr_inp = mpy_diff_aab; + sqr_inp = mpy_diff_aab; /*q_diff_aab*/ move32(); sqr_exp = sub( 31, q_diff_aab ); } @@ -1640,34 +1646,34 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { sqr_inp = mpy_diff_c; move32(); - sqr_exp = sub( 31, q_diff_c ); + sqr_exp = sub( 31, q_diff_c ); /*q_diff_c*/ } } - sqr = Sqrt32( sqr_inp, &sqr_exp ); - sqr = L_shr( sqr, 2 ); - IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] != 0 ) + sqr = Sqrt32( sqr_inp, &sqr_exp ); /*Q(31-sqr_exp)*/ + sqr = L_shr( sqr, 2 ); /*Q(31-sqr_exp)*/ + IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] != 0 ) { IF( LT_16( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth->Q( 31- sqr_exp )*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } ELSE { - sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*Q(31- sqr_exp)->h_dirac_output_synthesis_state->q_cy_cross_dir_smooth*/ + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k]*/ move32(); } ELSE { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q(31- sqr_exp)*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } } @@ -1679,73 +1685,74 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( /*Diffuseness modellling nrg compensation*/ FOR( k = 0; k < num_freq_bands_diff; k++ ) { - mpy_diff = Mpy_32_32( diffuseness[k], L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 ) ); // Q = q_diff - 1 - sqr_inp = L_add( L_shl( 1, sub( q_diffuseness, 1 ) ), mpy_diff ); + /*diffuseness[k] * 0.5f * ( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr - 1.f ) )*/ + mpy_diff = Mpy_32_32( diffuseness[k], L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx /*q29=0.5 * q30*/, ONE_IN_Q29 /*0.5 Q30*/ ) /*q30*/ ); // Q = q_diffuseness - 1 + sqr_inp = L_add( L_shl( 1, sub( q_diffuseness, 1 ) ), mpy_diff ); // Q = q_diffuseness - 1 sqr_exp = sub( 31, sub( q_diffuseness, 1 ) ); - sqr = Sqrt32( sqr_inp, &sqr_exp ); - sqr = L_shr( sqr, 2 ); - IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] != 0 ) + sqr = Sqrt32( sqr_inp, &sqr_exp ); /*Q(31-sqr_exp)*/ + sqr = L_shr( sqr, 2 ); /*Q(31-sqr_exp)*/ + IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] != 0 ) { IF( LT_16( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth->Q(31- sqr_exp)*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } ELSE { - sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*Q(31-sqr_exp)->h_dirac_output_synthesis_state->q_cy_cross_dir_smooth*/ + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k]*/ move32(); } ELSE { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q(31-sqr_exp)*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } } FOR( ; k < num_freq_bands; k++ ) { - mpy_diff = Mpy_32_32( diffuseness[k], L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 ) ); // Q = q_diff - 1 - sqr_inp = L_add( L_shl( 1, sub( q_diffuseness, 1 ) ), mpy_diff ); + mpy_diff = Mpy_32_32( diffuseness[k], L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 /*1 Q29*/ ) ); // Q = q_diffuseness - 1 + sqr_inp = L_add( L_shl( 1, sub( q_diffuseness, 1 ) ), mpy_diff ); // Q = q_diffuseness - 1 sqr_exp = sub( 31, sub( q_diffuseness, 1 ) ); - sqr = Sqrt32( sqr_inp, &sqr_exp ); - sqr = L_shr( sqr, 2 ); - IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] != 0 ) + sqr = Sqrt32( sqr_inp, &sqr_exp ); /*Q(31-sqr_exp)*/ + sqr = L_shr( sqr, 2 ); /*Q(31-sqr_exp)*/ + IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] != 0 ) { IF( LT_16( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, Q( 31- sqr_exp )*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } ELSE { - sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*Q( 31- sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth*/ + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k]*/ move32(); } ELSE { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q(31-sqr_exp)*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } } } } - Word16 temp = MAX_16; + Word16 temp = MAX_16; /*q0*/ move16(); tmp16 = imult1616( num_freq_bands, num_channels_dir ); FOR( Word16 kk = 0; kk < tmp16; kk++ ) @@ -1756,7 +1763,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( move16(); FOR( Word16 kk = 0; kk < tmp16; kk++ ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk] = L_shl( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk], sub( temp, Q_temp_cy_cross_dir_smooth_fx[kk] ) ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk] = L_shl( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk], sub( temp, Q_temp_cy_cross_dir_smooth_fx[kk] ) ); /*Q_temp_cy_cross_dir_smooth_fx[kk]->temp*/ move32(); } free( Q_temp_cy_cross_dir_smooth_fx ); @@ -1766,7 +1773,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { FOR( Word16 kk = 0; kk < tmp16; kk++ ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk] = L_shl( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk], sub( temp_q, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk] = L_shl( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk], sub( temp_q, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ->temp_q*/ move32(); } h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = temp_q; @@ -1775,33 +1782,37 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( FOR( ch_idx = s_min( 4, nchan_transport ); ch_idx < num_channels_dir; ch_idx++ ) { v_mult_fixed( h_dirac_output_synthesis_state->direct_power_factor_fx, - &h_dirac_output_synthesis_state->direct_responses_fx[i_mult( ch_idx, num_freq_bands )], + &h_dirac_output_synthesis_state->direct_responses_fx[ch_idx * num_freq_bands], aux_buf, - num_freq_bands ); + num_freq_bands ); /*temp_q*/ IF( NE_16( temp_q, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { - Scale_sig32( aux_buf, num_freq_bands, sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, temp_q ) ); + Scale_sig32( aux_buf, num_freq_bands, sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, temp_q ) ); /*temp_q->(h_dirac_output_synthesis_state->q_cy_cross_dir_smooth)*/ } v_add_fixed( aux_buf, - &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], - &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], - num_freq_bands, 0 ); // Todo:Hdrm + &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], + &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], + num_freq_bands, 0 ); /*Q(h_dirac_output_synthesis_state->q_cy_cross_dir_smooth)*/ } /*Diffuse gain*/ FOR( ch_idx = s_min( 4, nchan_transport ); ch_idx < num_channels_diff; ch_idx++ ) { - v_multc_fixed( h_dirac_output_synthesis_state->diffuse_power_factor_fx, - hDirACRend->diffuse_response_function_fx[ch_idx], - aux_buf, - num_freq_bands_diff ); - + v_multc_fixed_16( h_dirac_output_synthesis_state->diffuse_power_factor_fx, + hDirACRend->diffuse_response_function_fx[ch_idx], + aux_buf, + num_freq_bands_diff ); /* h_dirac_output_synthesis_state->diffuse_power_factor_q+15-15*/ + temp_q = h_dirac_output_synthesis_state->diffuse_power_factor_q; + IF( NE_16( temp_q, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ) + { + Scale_sig32( aux_buf, num_freq_bands, sub( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, temp_q ) ); /*temp_q->(h_dirac_output_synthesis_state->q_cy_auto_diff_smooth)*/ + } v_add_fixed( aux_buf, - &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], - &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], - num_freq_bands_diff, 0 ); // Todo:Hdrm + &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], + &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], + num_freq_bands_diff, 0 ); /*h_dirac_output_synthesis_state->q_cy_auto_diff_smooth*/ } return; @@ -1815,8 +1826,8 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( h_dirac_output_synthesis_state->direct_power_factor_fx, h_dirac_output_synthesis_state->diffuse_power_factor_fx ); - Scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, num_freq_bands, 2 ); - Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, num_freq_bands, 2 ); + Scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, num_freq_bands, 2 ); /*q29->q31*/ + Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, num_freq_bands, 2 ); /*q29->q31*/ h_dirac_output_synthesis_state->diffuse_power_factor_q = 31; move16(); h_dirac_output_synthesis_state->direct_power_factor_q = 31; @@ -1928,32 +1939,32 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /*Direct gain*/ FOR( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) { - v_multc_fixed( diffuseness, // Q30 - ONE_IN_Q31, // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q30 + v_multc_fixed( diffuseness, // Q30 + ONE_IN_Q31, // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q30 num_freq_bands ); - v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q30 - L_sub( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, ONE_IN_Q27 ), // Q27 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q26 + v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q30 + L_sub( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, ONE_IN_Q27 ), // Q27 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q26 num_freq_bands ); FOR( l = 0; l < num_freq_bands; l++ ) { exp = Q31 - Q26; - h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), l )] = - Sqrt32( L_add( ONE_IN_Q26, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), l )] ), + h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] = + Sqrt32( L_add( ONE_IN_Q26 /*1 in Q26*/, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] ), &exp ); // (Q31 - exp) move32(); } // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, sub( Q31, exp ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, sub( Q31, exp ) ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[imult1616( ch_idx, num_freq_bands )], + sub( q_com, sub( Q31, exp ) ) ); /*Q( Q31- exp)->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev->q_com*/ } /*Directional gain*/ @@ -1963,38 +1974,38 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { aux_buf[l] = L_sub( ONE_IN_Q30, diffuseness[l] ); // Q30 move32(); - ratio_float[l] = L_sub( ONE_IN_Q31, h_dirac_output_synthesis_state.direct_power_factor_fx[add( num_freq_bands, l )] ); // Q31 + ratio_float[l] = L_sub( ONE_IN_Q31, h_dirac_output_synthesis_state.direct_power_factor_fx[num_freq_bands + l] ); // Q31 move32(); - ratio_float[add( l, num_freq_bands )] = L_sub( ONE_IN_Q31, ratio_float[l] ); // Q31 + ratio_float[l + num_freq_bands] = L_sub( ONE_IN_Q31, ratio_float[l] ); // Q31 move32(); } v_mult_fixed( aux_buf, ratio_float, ratio_float, num_freq_bands ); //(Q30, Q31) -> Q30 v_mult_fixed( aux_buf, &ratio_float[num_freq_bands], &ratio_float[num_freq_bands], num_freq_bands ); //(Q30, Q31) -> Q30 - v_mult_fixed( ratio_float, // Q30 - &h_dirac_output_synthesis_state.direct_responses_fx[imult1616( ch_idx, num_freq_bands )], // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], //(Q30, Q31) -> Q30 + v_mult_fixed( ratio_float, // Q30 + &h_dirac_output_synthesis_state.direct_responses_fx[ch_idx * num_freq_bands], // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], //(Q30, Q31) -> Q30 num_freq_bands ); - v_mult_fixed( &ratio_float[num_freq_bands], // Q30 - &h_dirac_output_synthesis_state.direct_responses_fx[add( imult1616( ch_idx, num_freq_bands ), imult1616( num_freq_bands, num_channels_dir ) )], // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), imult1616( num_freq_bands, num_channels_dir ) )], //(Q30, Q31) -> Q30 + v_mult_fixed( &ratio_float[num_freq_bands], // Q30 + &h_dirac_output_synthesis_state.direct_responses_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], //(Q30, Q31) -> Q30 num_freq_bands ); // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q30 ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, Q30 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), imult1616( num_freq_bands, num_channels_dir ) )], + sub( q_com, Q30 ) ); /*Q30->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], num_freq_bands, - sub( q_com, Q30 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[imult1616( ch_idx, num_freq_bands )], + sub( q_com, Q30 ) ); /*Q30->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[add( imult1616( ch_idx, num_freq_bands ), imult1616( num_freq_bands, num_channels_dir ) )], + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], num_freq_bands, - sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev->q_com*/ } h_dirac_output_synthesis_state.q_cy_cross_dir_smooth = q_com; @@ -2005,19 +2016,19 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /*Diffuse gain*/ FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) { - v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 - hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 - &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], // Q31 + v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 + &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], // Q31 num_freq_bands_diff ); // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, Q31 ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], num_freq_bands_diff, - sub( q_com, Q31 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[imult1616( ch_idx, num_freq_bands_diff )], + sub( q_com, Q31 ) ); /*q31->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[ch_idx * num_freq_bands_diff], num_freq_bands_diff, - sub( q_com, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ); /* h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev->q_com*/ } h_dirac_output_synthesis_state.q_cy_auto_diff_smooth = q_com; @@ -2030,54 +2041,54 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /*Direct gain*/ FOR( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) { - v_mult_fixed( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 - h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q31 + v_mult_fixed( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q31 num_freq_bands ); - v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q31 + v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q31 L_sub( L_shr( h_dirac_output_synthesis_params.diffuse_compensation_factor_decorr_fx, Q3 ), ONE_IN_Q26 ), // Q26 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q26 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q26 num_freq_bands_diff ); - v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), num_freq_bands_diff )], // Q31 - L_sub( L_shr( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, Q1 ), ONE_IN_Q26 ), // Q26 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), num_freq_bands_diff )], // Q26 + v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands_diff], // Q31 + L_sub( L_shr( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, Q1 ), ONE_IN_Q26 ), // Q26 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands_diff], // Q26 num_freq_bands - num_freq_bands_diff ); FOR( l = 0; l < num_freq_bands; l++ ) { exp = Q31 - Q26; - h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), l )] = - Sqrt32( L_add( ONE_IN_Q26, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), l )] ), + h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] = + Sqrt32( L_add( ONE_IN_Q26, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] ), &exp ); // (Q31 - exp) move32(); } // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, sub( Q31, exp ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, sub( Q31, exp ) ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[imult1616( ch_idx, num_freq_bands )], + sub( q_com, sub( Q31, exp ) ) ); /*( Q31- exp )->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev->q_com*/ } /*Directional gain*/ FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_dir; ch_idx++ ) { - v_mult_fixed( h_dirac_output_synthesis_state.direct_power_factor_fx, // Q31 - &h_dirac_output_synthesis_state.direct_responses_fx[imult1616( ch_idx, num_freq_bands )], // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q31 + v_mult_fixed( h_dirac_output_synthesis_state.direct_power_factor_fx, // Q31 + &h_dirac_output_synthesis_state.direct_responses_fx[ch_idx * num_freq_bands], // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q31 num_freq_bands ); // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q31 ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, Q31 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[imult1616( ch_idx, num_freq_bands )], + sub( q_com, Q31 ) ); /*q31->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev->q_com*/ } h_dirac_output_synthesis_state.q_cy_cross_dir_smooth = q_com; @@ -2088,19 +2099,19 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /*Diffuse gain*/ FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) { - v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 - hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 - &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], // Q31 + v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 + &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], // Q31 num_freq_bands_diff ); // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, Q31 ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], num_freq_bands_diff, - sub( q_com, Q31 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[imult1616( ch_idx, num_freq_bands_diff )], + sub( q_com, Q31 ) ); /*q31->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[ch_idx * num_freq_bands_diff], num_freq_bands_diff, - sub( q_com, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev->q_com*/ } h_dirac_output_synthesis_state.q_cy_auto_diff_smooth = q_com; @@ -2228,9 +2239,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_dir_prev = h_dirac_output_synthesis_state.gains_dir_prev_fx; FOR( ch_idx = 0; ch_idx < num_channels_dir; ch_idx++ ) { - Scale_sig32( &h_dirac_output_synthesis_state.gains_dir_prev_fx[imult1616( ch_idx, num_freq_bands )], + Scale_sig32( &h_dirac_output_synthesis_state.gains_dir_prev_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, h_dirac_output_synthesis_state.gains_dir_prev_q ) ); + sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, h_dirac_output_synthesis_state.gains_dir_prev_q ) ); /*h_dirac_output_synthesis_state.gains_dir_prev_q->h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev*/ } h_dirac_output_synthesis_state.gains_dir_prev_q = h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev; move16(); @@ -2239,14 +2250,14 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { p_proto_diff = h_dirac_output_synthesis_state.proto_diffuse_buffer_f_fx + shl( i_mult( buf_idx, i_mult( num_freq_bands, num_channels_diff ) ), Q1 ) + - shl( i_mult( ch_idx, num_freq_bands ), Q1 ); + shl( ch_idx * num_freq_bands, Q1 ); FOR( l = 0; l < num_freq_bands; l++ ) { g = Madd_32_32( Mpy_32_32( g1, ( *( p_gains_dir++ ) ) ), g2, ( *( p_gains_dir_prev++ ) ) ); // (Q31, p_gains_dir_q) -> (p_gains_dir_q) - output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = Mpy_32_32( g, ( *( p_proto_diff++ ) ) ); // (p_gains_dir_q, p_proto_diff_q) -> (p_gains_dir_q + p_proto_diff_q - 31) + output_real[l * num_channels_dir + ch_idx] = Mpy_32_32( g, ( *( p_proto_diff++ ) ) ); // (p_gains_dir_q, p_proto_diff_q) -> (p_gains_dir_q + p_proto_diff_q - 31) move32(); - output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = Mpy_32_32( g, ( *( p_proto_diff++ ) ) ); // (p_gains_dir_q, p_proto_diff_q) -> (p_gains_dir_q + p_proto_diff_q - 31) + output_imag[l * num_channels_dir + ch_idx] = Mpy_32_32( g, ( *( p_proto_diff++ ) ) ); // (p_gains_dir_q, p_proto_diff_q) -> (p_gains_dir_q + p_proto_diff_q - 31) move32(); } } @@ -2274,7 +2285,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_dir_prev++; // ((p_gains_dir_q, p_proto_dir_q) >> 1) -> (p_gains_dir_q + p_proto_dir_q - 31) - output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = + output_real[l * num_channels_dir + ch_idx] = Madd_32_32( Mpy_32_32( gs1, ( L_add( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ) ), /* s1 */ gs2, L_sub( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ); /* s2 */ @@ -2283,7 +2294,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_proto2++; // ((p_gains_dir_q, p_proto_dir_q) >> 1) -> (p_gains_dir_q + p_proto_dir_q - 31) - output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = + output_imag[l * num_channels_dir + ch_idx] = Madd_32_32( Mpy_32_32( gs1, ( L_add( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ) ), gs2, L_sub( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ); @@ -2302,9 +2313,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_dir++; p_gains_dir_prev++; - output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) + output_real[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); - output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) + output_imag[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); } } @@ -2320,9 +2331,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { g = Madd_32_32( Mpy_32_32( g1, ( *( p_gains_dir++ ) ) ), g2, ( *( p_gains_dir_prev++ ) ) ); // (Q31, p_gains_dir_q) -> (p_gains_dir_q) - output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = Mpy_32_32( g, ( *( p_proto++ ) ) ); // (p_gains_dir_q, p_proto_dir_q) -> (p_gains_dir_q + p_proto_dir_q - 31) + output_real[l * num_channels_dir + ch_idx] = Mpy_32_32( g, ( *( p_proto++ ) ) ); // (p_gains_dir_q, p_proto_dir_q) -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); - output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = Mpy_32_32( g, ( *( p_proto++ ) ) ); // (p_gains_dir_q, p_proto_dir_q) -> (p_gains_dir_q + p_proto_dir_q - 31) + output_imag[l * num_channels_dir + ch_idx] = Mpy_32_32( g, ( *( p_proto++ ) ) ); // (p_gains_dir_q, p_proto_dir_q) -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); } } @@ -2333,9 +2344,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_dir++; p_gains_dir_prev++; - output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) + output_real[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); - output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) + output_imag[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); } } @@ -2347,9 +2358,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_diff_prev = h_dirac_output_synthesis_state.gains_diff_prev_fx + i_mult( nchan_transport_foa, num_freq_bands_diff ); FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) { - Scale_sig32( &h_dirac_output_synthesis_state.gains_diff_prev_fx[imult1616( ch_idx, num_freq_bands_diff )], + Scale_sig32( &h_dirac_output_synthesis_state.gains_diff_prev_fx[ch_idx * num_freq_bands_diff], num_freq_bands_diff, - sub( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, h_dirac_output_synthesis_state.gains_diff_prev_q ) ); + sub( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, h_dirac_output_synthesis_state.gains_diff_prev_q ) ); /*h_dirac_output_synthesis_state.gains_diff_prev_q->h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev*/ } h_dirac_output_synthesis_state.gains_diff_prev_q = h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev; move16(); @@ -2369,14 +2380,14 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( g = Madd_32_32( Mpy_32_32( g1, ( *( p_gains_diff++ ) ) ), g2, ( *( p_gains_diff_prev++ ) ) ); // (Q31, p_gains_diff_q) -> p_gains_diff_q // ((p_gains_diff_q, p_proto_diff_q) >> Q1) -> (p_gains_diff_q + p_proto_diff_q - 31) - output_real[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )] = - Madd_32_32( output_real[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )], + output_real[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]] = + Madd_32_32( output_real[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]], g, ( *( p_proto++ ) ) ); move32(); // ((p_gains_diff_q, p_proto_diff_q) >> Q1) -> (p_gains_diff_q + p_proto_diff_q - 31) - output_imag[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )] = - Madd_32_32( output_imag[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )], + output_imag[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]] = + Madd_32_32( output_imag[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]], g, ( *( p_proto++ ) ) ); move32(); } @@ -2396,6 +2407,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( *-----------------------------------------------------------------*/ test(); + /*q=(p_gains_dir_q + p_proto_dir_q - 31)*/ IF( hDirACRend->hOutSetup.is_loudspeaker_setup && hDirACRend->hoa_decoder != NULL ) { Word32 *p_real, *p_imag; @@ -2405,8 +2417,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( FOR( ch_idx = 0; ch_idx < hDirACRend->hOutSetup.nchan_out_woLFE; ch_idx++ ) { - p_real = RealBuffer[ch_idx][buf_idx]; - p_imag = ImagBuffer[ch_idx][buf_idx]; + p_real = RealBuffer[ch_idx][buf_idx]; /*q - Q2*/ + p_imag = ImagBuffer[ch_idx][buf_idx]; /*q - Q2*/ FOR( l = 0; l < num_freq_bands; l++ ) { @@ -2433,9 +2445,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - RealBuffer[ch_idx][buf_idx][l] = L_shr( output_real[add( imult1616( l, num_channels_dir ), ch_idx )], Q2 ); + RealBuffer[ch_idx][buf_idx][l] = L_shr( output_real[l * num_channels_dir + ch_idx], Q2 ); /* q - Q2*/ move32(); - ImagBuffer[ch_idx][buf_idx][l] = L_shr( output_imag[add( imult1616( l, num_channels_dir ), ch_idx )], Q2 ); + ImagBuffer[ch_idx][buf_idx][l] = L_shr( output_imag[l * num_channels_dir + ch_idx], Q2 ); /* q - Q2*/ move32(); } } @@ -2449,16 +2461,16 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /* store estimates for next synthesis block */ IF( hodirac_flag ) { - Copy32( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, imult1616( num_freq_bands, num_channels_dir ) * DIRAC_HO_NUMSECTORS ); + Copy32( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, imult1616( num_freq_bands, num_channels_dir ) * DIRAC_HO_NUMSECTORS ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev*/ } ELSE { - Copy32( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, imult1616( num_freq_bands, num_channels_dir ) ); + Copy32( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, imult1616( num_freq_bands, num_channels_dir ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev*/ } *q_cy_cross_dir_smooth_prev = h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev; move16(); - Copy32( h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx, h_dirac_output_synthesis_state.gains_diff_prev_fx, imult1616( num_freq_bands_diff, num_channels_diff ) ); + Copy32( h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx, h_dirac_output_synthesis_state.gains_diff_prev_fx, imult1616( num_freq_bands_diff, num_channels_diff ) ); /* h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev*/ *q_cy_auto_diff_smooth_prev = h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev; move16(); @@ -2925,15 +2937,15 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( - Word32 RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ - Word32 ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ + Word32 RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals Q(q_Cldfb)*/ + Word32 ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals Q(q_Cldfb)*/ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ const Word16 nbslots, /* i : number of slots to process */ - Word32 *diffuseness_vector, /* i : diffuseness (needed for direction smoothing)*/ - Word32 *reference_power_smooth, + Word32 *diffuseness_vector, /* i : diffuseness (needed for direction smoothing) Q(31)*/ + Word32 *reference_power_smooth, /*Q(q_reference_power_smooth)*/ Word16 *q_reference_power_smooth, - Word32 qualityBasedSmFactor, + Word32 qualityBasedSmFactor, /*Q(31)*/ const Word16 enc_param_start_band, Word16 *q_Cldfb ) { @@ -3036,11 +3048,11 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( IF( diff_start_band != 0 ) { q_com = s_min( *q_reference_power_smooth, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ); - scale_sig32( reference_power_smooth, num_freq_bands, sub( q_com, *q_reference_power_smooth ) ); - scale_sig32( h_dirac_output_synthesis_state->reference_power_smooth_prev_fx, num_freq_bands, sub( q_com, *q_reference_power_smooth ) ); + scale_sig32( reference_power_smooth, num_freq_bands, sub( q_com, *q_reference_power_smooth ) ); /**q_reference_power_smooth->q_com*/ + scale_sig32( h_dirac_output_synthesis_state->reference_power_smooth_prev_fx, num_freq_bands, sub( q_com, *q_reference_power_smooth ) ); /**q_reference_power_smooth->q_com*/ scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_freq_bands, nchan_target_psds ), - sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); + sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); /*h_dirac_output_synthesis_state->q_cy_auto_diff_smooth -> q_com*/ *q_reference_power_smooth = q_com; move16(); h_dirac_output_synthesis_state->reference_power_smooth_prev_q = q_com; @@ -3095,7 +3107,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( q_target_power_y1 = add( sub( Q31, exp1 ), sub( q_com, sub( Q31, exp ) ) ); q_target_power_y1 = sub( q_target_power_y1, 1 ); - target_power_y = L_add( L_shl( target_power_y, sub( s_min( q_target_power_y1, q_target_power_y ), q_target_power_y ) ), L_shl( target_power_y1, sub( s_min( q_target_power_y1, q_target_power_y ), q_target_power_y1 ) ) ); + target_power_y = L_add( L_shl( target_power_y, sub( s_min( q_target_power_y1, q_target_power_y ), q_target_power_y ) ), L_shl( target_power_y1, sub( s_min( q_target_power_y1, q_target_power_y ), q_target_power_y1 ) ) ); /*min(q_target_power_y1, q_target_power_y )*/ exp = s_min( q_target_power_y1, q_target_power_y ); } ELSE @@ -3190,8 +3202,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( exp = 0; move16(); - tmp = BASOP_Util_Divide3232_Scale( weightedDirectionSmoothness, L_add( sumWeight, EPSILON_FX ), &exp ); - smoothedDirectionSmoothness = L_shl_sat( L_deposit_l( tmp ), add( sub( Q31, Q15 ), exp ) ); // Q31 + tmp = BASOP_Util_Divide3232_Scale( weightedDirectionSmoothness, L_add( sumWeight, EPSILON_FX ), &exp ); /*Q(15-exp)*/ + smoothedDirectionSmoothness = L_shl_sat( L_deposit_l( tmp ), add( sub( Q31, Q15 ), exp ) ); // Q31 h_dirac_output_synthesis_state->direction_smoothness_prev_fx[l] = smoothedDirectionSmoothness; // Q31 move32(); @@ -3235,20 +3247,20 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( IF( EQ_32( *( p_power_smooth_prev ), EPSILON_FX ) ) { p_power_smooth_prev++; - L_tmp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q31, EPSILON_FX, &exp ); - exp_arr[add( i_mult( k, num_freq_bands ), l )] = exp; + L_tmp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q31, EPSILON_FX, &exp ); /*Q=31-(exp-(31-q_proto_power_smooth))*/ + exp_arr[k * num_freq_bands + l] = exp; move16(); - *( p_power_smooth++ ) = L_tmp; + *( p_power_smooth++ ) = L_tmp; /*Q=31-(exp-(31-q_proto_power_smooth))*/ move32(); } ELSE { - L_tmp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q31, *( p_power_smooth_prev++ ), &exp ); - exp_arr[add( i_mult( k, num_freq_bands ), l )] = exp; + L_tmp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q31, *( p_power_smooth_prev++ ), &exp ); /*Q=31-(exp-(31-q_proto_power_smooth))*/ + exp_arr[k * num_freq_bands + l] = exp; move16(); - *( p_power_smooth++ ) = L_tmp; + *( p_power_smooth++ ) = L_tmp; /*Q=31-(exp-(31-q_proto_power_smooth))*/ move32(); } } @@ -3264,9 +3276,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - IF( GT_16( exp_arr[add( i_mult( k, num_freq_bands ), l )], min_exp ) ) + IF( GT_16( exp_arr[k * num_freq_bands + l], min_exp ) ) { - min_exp = exp_arr[add( i_mult( k, num_freq_bands ), l )]; + min_exp = exp_arr[k * num_freq_bands + l]; move16(); } } @@ -3279,7 +3291,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - *p_power_smooth = L_shr( *p_power_smooth, sub( min_exp, exp_arr[add( i_mult( k, num_freq_bands ), l )] ) ); + *p_power_smooth = L_shr( *p_power_smooth, sub( min_exp, exp_arr[k * num_freq_bands + l] ) ); /*(31-(exp-(31-q_proto_power_smooth)))->(31-(min_exp-(31-q_proto_power_smooth)))*/ move32(); p_power_smooth++; q_tmp = add( sub( Q31, min_exp ), sub( Q31, h_dirac_output_synthesis_state->proto_power_smooth_q ) ); @@ -3305,12 +3317,12 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { q_cy_auto_dir_smooth_prev_local[k] = getScaleFactor32( p_cy_auto_dir_smooth_prev + imult1616( k, num_freq_bands ), num_freq_bands ); move16(); - scale_sig32( p_cy_auto_dir_smooth_prev + imult1616( k, num_freq_bands ), num_freq_bands, q_cy_auto_dir_smooth_prev_local[k] ); + scale_sig32( p_cy_auto_dir_smooth_prev + imult1616( k, num_freq_bands ), num_freq_bands, q_cy_auto_dir_smooth_prev_local[k] ); /*q_cy_auto_dir_smooth_prev_local[k]+h_dirac_output_synthesis_state -> q_cy_auto_dir_smooth_prev*/ q_cy_auto_dir_smooth_prev_local[k] = add( q_cy_auto_dir_smooth_prev_local[k], h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev ); move16(); q_com = s_min( q_cy_auto_dir_smooth_local[k], q_cy_auto_dir_smooth_prev_local[k] ); - scale_sig32( p_cy_auto_dir_smooth + imult1616( k, num_freq_bands ), num_freq_bands, sub( q_com, q_cy_auto_dir_smooth_local[k] ) ); - scale_sig32( p_cy_auto_dir_smooth_prev + imult1616( k, num_freq_bands ), num_freq_bands, sub( q_com, q_cy_auto_dir_smooth_prev_local[k] ) ); + scale_sig32( p_cy_auto_dir_smooth + imult1616( k, num_freq_bands ), num_freq_bands, sub( q_com, q_cy_auto_dir_smooth_local[k] ) ); /*q_cy_auto_dir_smooth_local -> q_com*/ + scale_sig32( p_cy_auto_dir_smooth_prev + imult1616( k, num_freq_bands ), num_freq_bands, sub( q_com, q_cy_auto_dir_smooth_prev_local[k] ) ); /*q_cy_auto_dir_smooth_prev_local -> q_com*/ q_cy_auto_dir_smooth_local[k] = q_cy_auto_dir_smooth_prev_local[k] = q_com; move16(); move16(); @@ -3320,8 +3332,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( p_cy_cross_dir_smooth = h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx; p_cy_cross_dir_smooth_prev = h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev_fx; q_com = s_min( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev ); - scale_sig32( p_cy_cross_dir_smooth, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); - scale_sig32( p_cy_cross_dir_smooth_prev, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev ) ); + scale_sig32( p_cy_cross_dir_smooth, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth -> q_com*/ + scale_sig32( p_cy_cross_dir_smooth_prev, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev -> q_com*/ h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev = q_com; move16(); move16(); @@ -3329,8 +3341,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( p_cy_auto_diff_smooth = h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx; p_cy_auto_diff_smooth_prev = h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx; q_com = s_min( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev ); - scale_sig32( p_cy_auto_diff_smooth, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); - scale_sig32( p_cy_auto_diff_smooth_prev, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev ) ); + scale_sig32( p_cy_auto_diff_smooth, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); /*h_dirac_output_synthesis_state->q_cy_auto_diff_smooth -> q_com*/ + scale_sig32( p_cy_auto_diff_smooth_prev, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev ) ); /*h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev -> q_com*/ h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev = q_com; move16(); move16(); @@ -3352,7 +3364,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Mpy_32_32( g2, ( *( p_cy_cross_dir_smooth_prev ) ) ) ); // (Q31, q_cy_cross_dir_smooth_prev) -> q_cy_cross_dir_smooth_prev move32(); - power_smooth_temp = L_shl( *p_power_smooth, norm_l( *p_power_smooth ) ); + power_smooth_temp = L_shl( *p_power_smooth, norm_l( *p_power_smooth ) ); // proto_power_smooth_q + norm_l( *p_power_smooth ) L_tmp = Mpy_32_32( power_smooth_temp, ( *( p_cy_auto_dir_smooth_prev++ ) ) ); // proto_power_smooth_q + norm_l( *p_power_smooth ) ) + q_cy_auto_dir_smooth_prev_local - 31 exp = sub( Q31, sub( add( add( h_dirac_output_synthesis_state->proto_power_smooth_q, norm_l( *p_power_smooth ) ), q_cy_auto_dir_smooth_prev_local[k] ), @@ -3371,13 +3383,13 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( } ELSE IF( GT_32( *( p_gains_dir ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ) ) ) { - *( p_gains_dir ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ); + *( p_gains_dir ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ); /*26 + h_dirac_output_synthesis_state->gains_dir_prev_q + 1 + 5 - 32 -> h_dirac_output_synthesis_state->gains_dir_prev_q*/ move32(); } IF( *( p_cy_cross_dir_smooth_prev++ ) < 0 ) { - *( p_gains_dir ) = L_negate( *( p_gains_dir ) ); + *( p_gains_dir ) = L_negate( *( p_gains_dir ) ); /*h_dirac_output_synthesis_state->gains_dir_prev_q*/ move32(); } p_gains_dir++; @@ -3406,9 +3418,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *( p_gains_diff ) = 0; move32(); } - ELSE IF( GT_32( *( p_gains_diff ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ) ) ) + ELSE IF( GT_32( *( p_gains_diff ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ) ) ) /*h_dirac_output_synthesis_state->gains_diff_prev_q*/ { - *( p_gains_diff ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ); + *( p_gains_diff ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ); /*h_dirac_output_synthesis_state->gains_diff_prev_q*/ move32(); } p_gains_diff++; @@ -3422,10 +3434,10 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( move32(); g2 = L_sub( ONE_IN_Q31, g1 ); // Q31 W_temp = W_add( W_mult_32_32( g1, ( *( p_cy_auto_dir_smooth++ ) ) ), - W_mult_32_32( g2, ( *( p_cy_auto_dir_smooth_prev ) ) ) ); + W_mult_32_32( g2, ( *( p_cy_auto_dir_smooth_prev ) ) ) ); /*32+q_cy_auto_dir_smooth_prev_local*/ q_tmp = W_norm( W_temp ); - L_tmp = W_extract_h( W_shl( W_temp, q_tmp ) ); // q_cy_auto_dir_smooth_prev_local + q_tmp - *( p_cy_auto_dir_smooth_prev++ ) = L_shr_r( L_tmp, q_tmp ); + L_tmp = W_extract_h( W_shl( W_temp, q_tmp ) ); // q_cy_auto_dir_smooth_prev_local + q_tmp + *( p_cy_auto_dir_smooth_prev++ ) = L_shr_r( L_tmp, q_tmp ); // q_cy_auto_dir_smooth_prev_local move32(); *( p_cy_cross_dir_smooth_prev ) = L_add( Mpy_32_32( g1, ( *( p_cy_cross_dir_smooth++ ) ) ), @@ -3448,15 +3460,15 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *( p_gains_dir ) = 0; move32(); } - ELSE IF( GT_32( *( p_gains_dir ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ) ) ) + ELSE IF( GT_32( *( p_gains_dir ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ) ) ) /*gains_dir_prev_q*/ { - *( p_gains_dir ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ); + *( p_gains_dir ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ); /*gains_dir_prev_q*/ move32(); } IF( *( p_cy_cross_dir_smooth_prev++ ) < 0 ) { - *( p_gains_dir ) = L_negate( *( p_gains_dir ) ); + *( p_gains_dir ) = L_negate( *( p_gains_dir ) ); /*gains_dir_prev_q*/ move32(); } p_gains_dir++; @@ -3466,14 +3478,14 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Mpy_32_32( g2, ( *( p_cy_auto_diff_smooth_prev ) ) ) ); // (Q31, q_cy_auto_diff_smooth_prev) -> q_cy_auto_diff_smooth_prev move32(); - power_smooth_temp = L_shl( *p_power_smooth, norm_l( *p_power_smooth ) ); + power_smooth_temp = L_shl( *p_power_smooth, norm_l( *p_power_smooth ) ); // proto_power_smooth_q + norm_l( *p_power_smooth ) L_tmp = Mpy_32_32( power_smooth_temp, ( *( p_cy_auto_diff_smooth_prev++ ) ) ); // proto_power_smooth_q + norm_l( *p_power_smooth ) ) + q_cy_auto_diff_smooth_prev - 31 exp = sub( Q31, sub( add( add( h_dirac_output_synthesis_state->proto_power_smooth_q, norm_l( *p_power_smooth ) ), h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev ), Q31 ) ); p_power_smooth++; - *( p_gains_diff ) = Sqrt32( L_tmp, &exp ); + *( p_gains_diff ) = Sqrt32( L_tmp, &exp ); /*31-exp*/ move32(); *( p_gains_diff ) = L_shl_sat( *( p_gains_diff ), sub( h_dirac_output_synthesis_state->gains_diff_prev_q, sub( Q31, exp ) ) ); // gains_diff_prev_q move32(); @@ -3483,9 +3495,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *( p_gains_diff ) = 0; move32(); } - ELSE IF( GT_32( *( p_gains_diff ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ) ) ) + ELSE IF( GT_32( *( p_gains_diff ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ) ) ) // gains_diff_prev_q { - *( p_gains_diff ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ); + *( p_gains_diff ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ); // gains_diff_prev_q move32(); } p_gains_diff++; @@ -3567,7 +3579,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { g = L_add( Mpy_32_32( g1, *( p_gain_1++ ) ), Mpy_32_32( g2, *( p_gain_2++ ) ) ); // (Q31, gains_diff_prev_q) -> gains_diff_prev_q Cldfb_RealBuffer64_fx[k][buf_idx][l] = W_add( Cldfb_RealBuffer64_fx[k][buf_idx][l], - W_mult0_32_32( g, ( *( p_power_smooth++ ) ) ) ); // (gains_diff_prev_q, q_proto_direct_buffer) >> Q1 -> gains_diff_prev_q + q_proto_direct_buffer - 32 + W_mult0_32_32( g, ( *( p_power_smooth++ ) ) ) ); // (gains_diff_prev_q, q_proto_direct_buffer) -> gains_diff_prev_q + q_proto_direct_buffer move64(); if ( LT_64( W_temp, W_abs( Cldfb_RealBuffer64_fx[k][buf_idx][l] ) ) ) @@ -3576,12 +3588,12 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( } Cldfb_ImagBuffer64_fx[k][buf_idx][l] = W_add( Cldfb_ImagBuffer64_fx[k][buf_idx][l], - W_mult0_32_32( g, ( *( p_power_smooth++ ) ) ) ); // (gains_diff_prev_q, q_proto_direct_buffer) >> Q1 -> gains_diff_prev_q + q_proto_direct_buffer - 32 + W_mult0_32_32( g, ( *( p_power_smooth++ ) ) ) ); // (gains_diff_prev_q, q_proto_direct_buffer) -> gains_diff_prev_q + q_proto_direct_buffer move64(); if ( LT_64( W_temp, W_abs( Cldfb_ImagBuffer64_fx[k][buf_idx][l] ) ) ) { - W_temp = W_abs( Cldfb_ImagBuffer64_fx[k][buf_idx][l] ); + W_temp = W_abs( Cldfb_ImagBuffer64_fx[k][buf_idx][l] ); // gains_diff_prev_q + q_proto_direct_buffer } } } @@ -3593,9 +3605,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - RealBuffer[k][buf_idx][l] = W_extract_h( W_shl( Cldfb_RealBuffer64_fx[k][buf_idx][l], q_align ) ); + RealBuffer[k][buf_idx][l] = W_extract_h( W_shl( Cldfb_RealBuffer64_fx[k][buf_idx][l], q_align ) ); /*( ( ( h_dirac_output_synthesis_state->proto_direct_buffer_f_q+h_dirac_output_synthesis_state->gains_dir_prev_q )+ q_align )- 32 )*/ move32(); - ImagBuffer[k][buf_idx][l] = W_extract_h( W_shl( Cldfb_ImagBuffer64_fx[k][buf_idx][l], q_align ) ); + ImagBuffer[k][buf_idx][l] = W_extract_h( W_shl( Cldfb_ImagBuffer64_fx[k][buf_idx][l], q_align ) ); /*( ( ( h_dirac_output_synthesis_state->proto_direct_buffer_f_q+h_dirac_output_synthesis_state->gains_dir_prev_q )+ q_align )- 32 )*/ move32(); } } @@ -3609,8 +3621,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *-----------------------------------------------------------------*/ /* store estimates for next synthesis block */ - Copy32( gains_dir, h_dirac_output_synthesis_state->gains_dir_prev_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); - Copy32( gains_diff, h_dirac_output_synthesis_state->gains_diff_prev_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); + Copy32( gains_dir, h_dirac_output_synthesis_state->gains_dir_prev_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); /*gains_dir_prev_q*/ + Copy32( gains_diff, h_dirac_output_synthesis_state->gains_diff_prev_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); /*gains_diff_prev_q*/ /* reset values */ set_zero_fx( h_dirac_output_synthesis_state->proto_power_smooth_fx, imult1616( num_freq_bands, num_protos_dir ) ); @@ -3622,7 +3634,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( minimum_fx( q_cy_auto_dir_smooth_prev_local, nchan_out_woLFE, &h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev ); FOR( k = 0; k < nchan_out_woLFE; k++ ) { - scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx + ( k * num_freq_bands ), num_freq_bands, sub( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev, q_cy_auto_dir_smooth_prev_local[k] ) ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx + ( k * num_freq_bands ), num_freq_bands, sub( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev, q_cy_auto_dir_smooth_prev_local[k] ) ); /*q_cy_auto_dir_smooth_prev_local[k] -> h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev*/ } set_zero_fx( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); @@ -4003,9 +4015,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( #ifdef IVAS_FLOAT_FIXED static void ivas_dirac_dec_get_response_split_order_fx( - const Word16 azimuth, - const Word16 elevation, - Word32 *response, + const Word16 azimuth, /*q0*/ + const Word16 elevation, /*q0*/ + Word32 *response, /*q_response*/ const Word16 shd_rot_max_order, const Word32 *p_Rmat /* Q30 */, Word16 *q_response ) @@ -4040,13 +4052,13 @@ static void ivas_dirac_dec_get_response_split_order_fx( IF( GT_16( index_elevation, 90 ) ) { - e = -ONE_IN_Q14; + e = -ONE_IN_Q14; /*-1 in Q14*/ move16(); el = sub( 180, index_elevation ); } ELSE { - e = ONE_IN_Q14; + e = ONE_IN_Q14; /*1 in Q14*/ move16(); el = index_elevation; move16(); @@ -4055,21 +4067,21 @@ static void ivas_dirac_dec_get_response_split_order_fx( IF( GT_16( index_azimuth, 180 ) ) { az = sub( 360, index_azimuth ); - f = -ONE_IN_Q30; + f = -ONE_IN_Q30; /*-1 Q30*/ move32(); } ELSE { az = index_azimuth; move16(); - f = ONE_IN_Q30; + f = ONE_IN_Q30; /*1 Q30*/ move32(); } // dirac_gains_trg_term_int Q30 cos_1 = L_shr( dirac_gains_trg_term_int[az][0], 1 ); // Q29 cos_2 = L_shl( Mpy_32_32( cos_1, cos_1 ), 2 ); // Q29 - sin_1 = Mpy_32_32( f, dirac_gains_trg_term_int[az][1] ); // Q29] + sin_1 = Mpy_32_32( f, dirac_gains_trg_term_int[az][1] ); // Q29 cos_az[0] = cos_1; // Q29 move32(); @@ -4173,13 +4185,13 @@ static void ivas_dirac_dec_get_response_split_order_fx( IF( GT_16( index_elevation, 90 ) ) { - e = -ONE_IN_Q14; + e = -ONE_IN_Q14; /*-1 Q14*/ move16(); el = sub( 180, index_elevation ); } ELSE { - e = ONE_IN_Q14; + e = ONE_IN_Q14; /*1 Q14*/ move16(); el = index_elevation; move16(); @@ -4188,14 +4200,14 @@ static void ivas_dirac_dec_get_response_split_order_fx( IF( GT_16( index_azimuth, 180 ) ) { az = sub( 360, index_azimuth ); - f = -ONE_IN_Q30; + f = -ONE_IN_Q30; /*-1 Q30*/ move32(); } ELSE { az = index_azimuth; move16(); - f = ONE_IN_Q30; + f = ONE_IN_Q30; /*1 Q30*/ move32(); } @@ -4452,10 +4464,10 @@ void ivas_dirac_dec_compute_directional_responses_fx( const Word16 *azimuth, const Word16 *elevation, const Word16 md_idx, - const Word32 *surCohRatio_fx, + const Word32 *surCohRatio_fx, /*i:Q_surCohRatio*/ Word16 Q_surCohRatio, const Word16 shd_rot_max_order, /* i : split-order rotation method */ - const Word32 *p_Rmat, /* i : rotation matrix */ + const Word32 *p_Rmat, /* i : rotation matrix Q30*/ const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ ) { @@ -4515,9 +4527,9 @@ void ivas_dirac_dec_compute_directional_responses_fx( move16(); IF( EQ_16( hSpatParamRendCom->numParametricDirections, 2 ) ) { - azimuth2 = hSpatParamRendCom->azimuth2[md_idx]; + azimuth2 = hSpatParamRendCom->azimuth2[md_idx]; /*q0*/ move16(); - elevation2 = hSpatParamRendCom->elevation2[md_idx]; + elevation2 = hSpatParamRendCom->elevation2[md_idx]; /*q0*/ move16(); } @@ -4527,11 +4539,15 @@ void ivas_dirac_dec_compute_directional_responses_fx( FOR( k = 0; k < hSpatParamRendCom->num_freq_bands; ++k ) { + test(); if ( masa_band_mapping != NULL && EQ_16( k, MASA_band_grouping_24[masa_band_mapping[add( codingBand, 1 )]] ) ) { codingBand = add( codingBand, 1 ); } + test(); + test(); + test(); IF( masa_band_mapping != NULL && GT_16( k, MASA_band_grouping_24[masa_band_mapping[codingBand]] ) && LT_16( k, MASA_band_grouping_24[masa_band_mapping[add( codingBand, 1 )]] ) && NE_16( k, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ) ) @@ -4541,20 +4557,20 @@ void ivas_dirac_dec_compute_directional_responses_fx( { mvr2r_inc_fixed( &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k - 1], hSpatParamRendCom->num_freq_bands, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], - hSpatParamRendCom->num_freq_bands, num_channels_dir ); + hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*direct_response_square_q*/ } mvr2r_inc_fixed( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k - 1], hSpatParamRendCom->num_freq_bands, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], - hSpatParamRendCom->num_freq_bands, num_channels_dir ); + hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*direct_response_q*/ } ELSE { /* HOA3 PANNING */ IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_HOA3 ) ) { - set32_fx( direct_response_hoa_fx, ONE_IN_Q29, MAX_OUTPUT_CHANNELS ); - set32_fx( direct_response_dir2_fx, ONE_IN_Q29, MAX_OUTPUT_CHANNELS ); + set32_fx( direct_response_hoa_fx, ONE_IN_Q29, MAX_OUTPUT_CHANNELS ); /*q29*/ + set32_fx( direct_response_dir2_fx, ONE_IN_Q29, MAX_OUTPUT_CHANNELS ); /*q29*/ Q_direct_response_hoa = Q29; move16(); @@ -4590,11 +4606,11 @@ void ivas_dirac_dec_compute_directional_responses_fx( test(); IF( masa_band_mapping == NULL && EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - mvr2r_inc_fixed( direct_response_hoa_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_hoa_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*Q_direct_response_hoa*/ IF( hodirac_flag ) { - mvr2r_inc_fixed( direct_response_dir2_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[add( k, i_mult( hSpatParamRendCom->num_freq_bands, num_channels_dir ) )], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_dir2_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k + hSpatParamRendCom->num_freq_bands * num_channels_dir], hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*Q_direct_response_dir2*/ } } ELSE IF( ( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) && ( masa_band_mapping != NULL ) ) || @@ -4603,7 +4619,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( /* Synthesize the first direction */ IF( GT_16( Q_direct_response_hoa, Q29 ) ) { - Scale_sig32( direct_response_hoa_fx, MAX_OUTPUT_CHANNELS, sub( Q_direct_response_hoa, Q29 ) ); + Scale_sig32( direct_response_hoa_fx, MAX_OUTPUT_CHANNELS, sub( Q_direct_response_hoa, Q29 ) ); /*Q_direct_response_hoa->q29*/ Q_direct_response_hoa = Q29; move16(); exp_direct_response_hoa = sub( 31, Q_direct_response_hoa ); @@ -4617,7 +4633,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( { IF( GT_16( Q_direct_response_dir2, Q29 ) ) { - Scale_sig32( direct_response_dir2_fx, MAX_OUTPUT_CHANNELS, sub( Q_direct_response_dir2, Q29 ) ); + Scale_sig32( direct_response_dir2_fx, MAX_OUTPUT_CHANNELS, sub( Q_direct_response_dir2, Q29 ) ); /*Q_direct_response_dir2->q29*/ Q_direct_response_dir2 = Q29; move16(); exp_direct_response_dir2 = sub( 31, Q_direct_response_dir2 ); @@ -4627,7 +4643,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( exp_direct_response_hoa = sub( 31, Q_direct_response_hoa ); /* Combine gains from the two directions */ - totalDirect_fx = L_add( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); + totalDirect_fx = L_add( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); /*q30*/ IF( totalDirect_fx == 0 ) { totalDirect_fx = EPSILON_FIX; @@ -4635,12 +4651,12 @@ void ivas_dirac_dec_compute_directional_responses_fx( } Word16 var_a, var_b, exp_1, exp_2; - var_a = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], totalDirect_fx, &exp_1 ); - var_b = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio2_fx[md_idx][k], totalDirect_fx, &exp_2 ); + var_a = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], totalDirect_fx, &exp_1 ); /*15-exp_1*/ + var_b = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio2_fx[md_idx][k], totalDirect_fx, &exp_2 ); /*15-exp_2*/ - directRatio_fx[0] = L_deposit_h( var_a ); + directRatio_fx[0] = L_deposit_h( var_a ); /*15-exp_1+16*/ move32(); - directRatio_fx[1] = L_deposit_h( var_b ); + directRatio_fx[1] = L_deposit_h( var_b ); /*15-exp_2+16*/ move32(); Word32 temp_a; @@ -4650,13 +4666,13 @@ void ivas_dirac_dec_compute_directional_responses_fx( FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], directRatio_fx[0] ); + direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], directRatio_fx[0] ); /*Q(Q_direct_response_hoa+31-exp_1-31)*/ move32(); exp_arr[l] = add( exp_1, sub( 31, Q_direct_response_hoa ) ); move16(); - temp_a = Mpy_32_32( directRatio_fx[1], direct_response_dir2_fx[l] ); + temp_a = Mpy_32_32( directRatio_fx[1], direct_response_dir2_fx[l] ); /*Q(Q_direct_response_dir2+31-exp_2-31)*/ exp_temp_a = add( exp_2, sub( 31, Q_direct_response_dir2 ) ); - direct_response_hoa_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_hoa_fx[l], exp_arr[l], temp_a, exp_temp_a, &final_exp ); + direct_response_hoa_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_hoa_fx[l], exp_arr[l], temp_a, exp_temp_a, &final_exp ); /*Q(31-final_exp)*/ move32(); exp_arr[l] = final_exp; move16(); @@ -4667,7 +4683,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, MAX_OUTPUT_CHANNELS, &max_exp ); FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { - direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); + direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); /*Q(31-exp_arr[l])->Q(31-max_exp)*/ move32(); } exp_direct_response_hoa = max_exp; @@ -4707,8 +4723,8 @@ void ivas_dirac_dec_compute_directional_responses_fx( set16_fx( exp_arr, 0, MAX_OUTPUT_CHANNELS ); FOR( l = 0; l < num_channels_dir; l++ ) { - temp_1 = Mpy_32_32( direct_response_temp_fx[l], hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // Q28 - direct_response_ism_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_ism_fx[l], exp_direct_response_ism, temp_1, exp_direct_response_temp + 1, &exp_temp ); + temp_1 = Mpy_32_32( direct_response_temp_fx[l], hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // Q28 + direct_response_ism_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_ism_fx[l], exp_direct_response_ism, temp_1, add( exp_direct_response_temp, 1 ), &exp_temp ); //(31-exp_temp) move32(); exp_arr[l] = exp_temp; move16(); @@ -4718,38 +4734,38 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, num_channels_dir, &max_exp ); FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_ism_fx[l] = L_shr( direct_response_ism_fx[l], max_exp - exp_arr[l] ); + direct_response_ism_fx[l] = L_shr( direct_response_ism_fx[l], sub( max_exp, exp_arr[l] ) ); /*Q(31- exp_arr[l])->Q(31-max_exp)*/ move32(); } exp_direct_response_ism = max_exp; move16(); } Word16 exp_1, exp_2; - masaDirect_fx = hSpatParamRendCom->energy_ratio1_fx[md_idx][k]; + masaDirect_fx = hSpatParamRendCom->energy_ratio1_fx[md_idx][k]; /*q30*/ move32(); if ( masaDirect_fx == 0 ) { - masaDirect_fx = L_add( masaDirect_fx, EPSILLON_FX ); + masaDirect_fx = L_add( masaDirect_fx, EPSILLON_FX ); /*q30*/ } if ( EQ_16( hSpatParamRendCom->numParametricDirections, 2 ) ) { - masaDirect_fx = L_add( masaDirect_fx, hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); + masaDirect_fx = L_add( masaDirect_fx, hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); /*q30*/ } - ismDirect_fx = hMasaIsm->energy_ratio_ism_fx[0][md_idx][k]; + ismDirect_fx = hMasaIsm->energy_ratio_ism_fx[0][md_idx][k]; /*q30*/ move32(); FOR( dir = 1; dir < hSpatParamRendCom->numIsmDirections; dir++ ) { - ismDirect_fx = L_add( ismDirect_fx, hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); + ismDirect_fx = L_add( ismDirect_fx, hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); /*q30*/ } - totalDirect_fx = L_add_sat( masaDirect_fx, ismDirect_fx ); // saturating as 1.0 (Q30) + 1.0 (Q30) is observed + totalDirect_fx = L_add_sat( masaDirect_fx, ismDirect_fx ); /*q30*/ // saturating as 1.0 (Q30) + 1.0 (Q30) is observed Word16 var_a = 0, var_b = 0; - var_a = BASOP_Util_Divide3232_Scale( masaDirect_fx, totalDirect_fx, &exp_1 ); - var_b = BASOP_Util_Divide3232_Scale( ismDirect_fx, totalDirect_fx, &exp_2 ); - directRatio_fx[0] = L_deposit_h( var_a ); + var_a = BASOP_Util_Divide3232_Scale( masaDirect_fx, totalDirect_fx, &exp_1 ); /*Q(15-exp_1)*/ + var_b = BASOP_Util_Divide3232_Scale( ismDirect_fx, totalDirect_fx, &exp_2 ); /*q(15-exp_2)*/ + directRatio_fx[0] = L_deposit_h( var_a ); // Q(31-exp_1) move32(); - directRatio_fx[1] = L_deposit_h( var_b ); + directRatio_fx[1] = L_deposit_h( var_b ); // Q(31-exp_2) move32(); Word32 temp_2, temp_3; @@ -4757,14 +4773,14 @@ void ivas_dirac_dec_compute_directional_responses_fx( set16_fx( exp_arr, exp_direct_response_hoa, MAX_OUTPUT_CHANNELS ); FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], directRatio_fx[0] ); + direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], directRatio_fx[0] ); /*31-exp_direct_response_hoa+31-exp_1-31*/ move32(); exp_arr[l] = add( exp_direct_response_hoa, exp_1 ); move16(); - temp_2 = Mpy_32_32( directRatio_fx[1], direct_response_ism_fx[l] ); - temp_3 = BASOP_Util_Add_Mant32Exp( direct_response_hoa_fx[l], exp_arr[l], temp_2, exp_2 + exp_direct_response_ism, &exp_temp_3 ); + temp_2 = Mpy_32_32( directRatio_fx[1], direct_response_ism_fx[l] ); /*31-exp_direct_response_ism+31-exp_2-31*/ + temp_3 = BASOP_Util_Add_Mant32Exp( direct_response_hoa_fx[l], exp_arr[l], temp_2, add( exp_2, exp_direct_response_ism ), &exp_temp_3 ); /*31-exp_temp_3*/ - direct_response_hoa_fx[l] = temp_3; + direct_response_hoa_fx[l] = temp_3; /*31-exp_temp_3*/ move32(); exp_arr[l] = exp_temp_3; move16(); @@ -4775,7 +4791,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, num_channels_dir, &max_exp ); FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); + direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); /*q(31-exp_arr[l])->q(31-max_exp)*/ move32(); } Q_direct_response_hoa = sub( 31, max_exp ); @@ -4794,9 +4810,9 @@ void ivas_dirac_dec_compute_directional_responses_fx( { exp = 0; move16(); - var_a = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( surCohRatio_fx[k] ), exp_surCohRatio, &exp ); - var_b = Sqrt32( var_a, &exp ); - direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], var_b ); + var_a = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30 /*1 Q30*/, 1, L_negate( surCohRatio_fx[k] ), exp_surCohRatio, &exp ); /*q(31-exp)*/ + var_b = Sqrt32( var_a, &exp ); /*31-exp*/ + direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], var_b ); /*Q_direct_response_hoa+31-exp-31*/ move32(); exp_arr[l] = add( sub( 31, Q_direct_response_hoa ), exp ); move16(); @@ -4806,7 +4822,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, MAX_OUTPUT_CHANNELS, &max_exp ); FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { - direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); + direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); /*q(31-exp_arr[l])->q(31-max_exp)*/ move32(); } Q_direct_response_hoa = sub( 31, max_exp ); @@ -4816,36 +4832,36 @@ void ivas_dirac_dec_compute_directional_responses_fx( Q_direct_response_hoa = sub( Q31, exp_direct_response_hoa ); - Scale_sig32( direct_response_hoa_fx, MAX_OUTPUT_CHANNELS, sub( Q29, Q_direct_response_hoa ) ); + Scale_sig32( direct_response_hoa_fx, MAX_OUTPUT_CHANNELS, sub( Q29, Q_direct_response_hoa ) ); /*Q_direct_response_hoa->q29*/ direct_response_q = Q29; move16(); direct_response_fx = direct_response_hoa_fx; IF( NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - v_mult_fixed( direct_response_fx, direct_response_fx, direct_response_square_fx, num_channels_dir ); + v_mult_fixed( direct_response_fx, direct_response_fx, direct_response_square_fx, num_channels_dir ); /*Q(2*direct_response_q-31)*/ direct_response_square_q = sub( add( direct_response_q, direct_response_q ), 31 ); - mvr2r_inc_fixed( direct_response_square_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_square_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*direct_response_square_q*/ IF( EQ_16( transport_signal_type, MASA_STEREO_SPACED_MICS ) ) { - direct_response_fx[0] = ONE_IN_Q29; + direct_response_fx[0] = ONE_IN_Q29; /*q29*/ move32(); test(); IF( GE_16( k, dipole_freq_range[0] ) && LT_16( k, dipole_freq_range[1] ) ) { - direct_response_fx[1] = ONE_IN_Q29; + direct_response_fx[1] = ONE_IN_Q29; /*q29*/ move32(); } } ELSE { - set32_fx( direct_response_fx, ONE_IN_Q29, hDirACRend->num_protos_ambi ); + set32_fx( direct_response_fx, ONE_IN_Q29, hDirACRend->num_protos_ambi ); /*q29*/ } } - mvr2r_inc_fixed( direct_response_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*q29*/ } ELSE { @@ -4867,7 +4883,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( normalizePanningGains_fx( direct_response_dir2_fx, &Q_direct_response_dir2, num_channels_dir ); /* Combine gains from the two directions */ - Word32 test = L_add( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); + Word32 test = L_add( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); /*q30*/ IF( test == 0 ) { @@ -4875,16 +4891,16 @@ void ivas_dirac_dec_compute_directional_responses_fx( } ELSE { - totalDirect_fx = test; + totalDirect_fx = test; // q30 move32(); } Word16 var_1, var_2, exp_1, exp_2; - var_1 = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], totalDirect_fx, &exp_1 ); - var_2 = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio2_fx[md_idx][k], totalDirect_fx, &exp_2 ); + var_1 = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], totalDirect_fx, &exp_1 ); // 15-exp_1 + var_2 = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio2_fx[md_idx][k], totalDirect_fx, &exp_2 ); // 15-exp_2 - directRatio_fx[0] = L_deposit_h( var_1 ); + directRatio_fx[0] = L_deposit_h( var_1 ); // 31-exp_1 move32(); - directRatio_fx[1] = L_deposit_h( var_2 ); + directRatio_fx[1] = L_deposit_h( var_2 ); // 31-exp_2 move32(); Word32 var_a; @@ -4904,7 +4920,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( var_a = Mpy_32_32( directRatio_fx[1], direct_response_dir2_fx[l] ); // exp_direct_response_dir2 + exp_2 exp_tmp = 0; move16(); - direct_response_ls_fx[l] = BASOP_Util_Add_Mant32Exp( temp, add( exp_direct_response_ls, exp_1 ), var_a, add( exp_direct_response_dir2, exp_2 ), &exp_tmp ); + direct_response_ls_fx[l] = BASOP_Util_Add_Mant32Exp( temp, add( exp_direct_response_ls, exp_1 ), var_a, add( exp_direct_response_dir2, exp_2 ), &exp_tmp ); // q(31-exp_tmp) move32(); exp_table[l] = exp_tmp; move16(); @@ -4914,7 +4930,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - direct_response_ls_fx[i] = L_shr( direct_response_ls_fx[i], sub( exp_max, exp_table[i] ) ); + direct_response_ls_fx[i] = L_shr( direct_response_ls_fx[i], sub( exp_max, exp_table[i] ) ); /*(q(31-exp_table[i])->q(31-exp_max))*/ move32(); } Q_direct_response_ls = sub( 31, exp_max ); @@ -4953,8 +4969,8 @@ void ivas_dirac_dec_compute_directional_responses_fx( Word16 Q_arr[MAX_OUTPUT_CHANNELS], exp_tmp; FOR( l = 0; l < num_channels_dir; l++ ) { - tmp = Mpy_32_32( direct_response_temp_fx[l], hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // Q30 * 2 - 31 - direct_response_ism_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_ism_fx[l], 0, tmp, 31 - ( 60 - 31 ), &exp_tmp ); + tmp = Mpy_32_32( direct_response_temp_fx[l], hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // Q30 * 2 - 31 + direct_response_ism_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_ism_fx[l], 0, tmp, 31 - ( 60 - 31 ), &exp_tmp ); // q(31-exp_tmp) move32(); Q_arr[l] = sub( 31, exp_tmp ); move16(); @@ -4964,7 +4980,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( minimum_fx( Q_arr, num_channels_dir, &Q_min ); FOR( i = 0; i < num_channels_dir; i++ ) { - direct_response_ism_fx[i] = L_shr( direct_response_ism_fx[i], sub( Q_arr[i], Q_min ) ); + direct_response_ism_fx[i] = L_shr( direct_response_ism_fx[i], sub( Q_arr[i], Q_min ) ); // Q_arr[i]->Q_min move32(); } Q_direct_response_temp = Q_min; @@ -4973,31 +4989,31 @@ void ivas_dirac_dec_compute_directional_responses_fx( } Word16 exp_1, exp_2; - masaDirect_fx = hSpatParamRendCom->energy_ratio1_fx[md_idx][k]; + masaDirect_fx = hSpatParamRendCom->energy_ratio1_fx[md_idx][k]; // q30 move32(); IF( masaDirect_fx == 0 ) { - masaDirect_fx = L_add( masaDirect_fx, EPSILLON_FX ); + masaDirect_fx = L_add( masaDirect_fx, EPSILLON_FX ); // q30 } IF( EQ_32( hSpatParamRendCom->numParametricDirections, 2 ) ) { - masaDirect_fx = L_add( masaDirect_fx, hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); + masaDirect_fx = L_add( masaDirect_fx, hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); // q30 } - ismDirect_fx = hMasaIsm->energy_ratio_ism_fx[0][md_idx][k]; + ismDirect_fx = hMasaIsm->energy_ratio_ism_fx[0][md_idx][k]; // q30 move32(); FOR( dir = 1; dir < hSpatParamRendCom->numIsmDirections; dir++ ) { - ismDirect_fx = L_add( ismDirect_fx, hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); + ismDirect_fx = L_add( ismDirect_fx, hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // q30 } - totalDirect_fx = L_add_sat( masaDirect_fx, ismDirect_fx ); // saturating as 1.0 (Q30) + 1.0 (Q30) is observed + totalDirect_fx = L_add_sat( masaDirect_fx, ismDirect_fx ); // q30 // saturating as 1.0 (Q30) + 1.0 (Q30) is observed Word16 var_a, var_b; - var_a = BASOP_Util_Divide3232_Scale( masaDirect_fx, totalDirect_fx, &exp_1 ); - var_b = BASOP_Util_Divide3232_Scale( ismDirect_fx, totalDirect_fx, &exp_2 ); - directRatio_fx[0] = L_deposit_h( var_a ); + var_a = BASOP_Util_Divide3232_Scale( masaDirect_fx, totalDirect_fx, &exp_1 ); // 15-exp_1 + var_b = BASOP_Util_Divide3232_Scale( ismDirect_fx, totalDirect_fx, &exp_2 ); // 15- exp_2 + directRatio_fx[0] = L_deposit_h( var_a ); // 31- exp_1 move32(); - directRatio_fx[1] = L_deposit_h( var_b ); + directRatio_fx[1] = L_deposit_h( var_b ); // 31 - exp_2 move32(); Word32 temp_2, temp_3; @@ -5005,14 +5021,14 @@ void ivas_dirac_dec_compute_directional_responses_fx( set16_fx( exp_arr, exp_direct_response_ls, MAX_OUTPUT_CHANNELS ); FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_ls_fx[l] = Mpy_32_32( direct_response_ls_fx[l], directRatio_fx[0] ); + direct_response_ls_fx[l] = Mpy_32_32( direct_response_ls_fx[l], directRatio_fx[0] ); // q(31-exp_direct_response_ls+31-exp_1-31) move32(); exp_arr[l] = add( exp_direct_response_ls, exp_1 ); move16(); - temp_2 = Mpy_32_32( directRatio_fx[1], direct_response_ism_fx[l] ); - temp_3 = BASOP_Util_Add_Mant32Exp( direct_response_ls_fx[l], exp_arr[l], temp_2, exp_2 + 31 - Q_direct_response_temp, &exp_temp_3 ); + temp_2 = Mpy_32_32( directRatio_fx[1], direct_response_ism_fx[l] ); // q(Q_direct_response_temp+31-exp_2-31) + temp_3 = BASOP_Util_Add_Mant32Exp( direct_response_ls_fx[l], exp_arr[l], temp_2, add( exp_2, sub( 31, Q_direct_response_temp ) ), &exp_temp_3 ); // 31-exp_temp_3 - direct_response_ls_fx[l] = temp_3; + direct_response_ls_fx[l] = temp_3; // 31-exp_temp_3 move32(); exp_arr[l] = exp_temp_3; move16(); @@ -5023,7 +5039,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, num_channels_dir, &max_exp ); FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], sub( max_exp, exp_arr[l] ) ); + direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], sub( max_exp, exp_arr[l] ) ); /*q(31-exp_arr[l])->q(31-max_exp)*/ move16(); } Q_direct_response_ls = sub( 31, max_exp ); @@ -5035,6 +5051,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( } /* Synthesize surrounding coherence */ + test(); IF( surCohRatio_fx != NULL && surCohRatio_fx[k] > 0 ) { Word16 num_channels_surrCoh; @@ -5052,9 +5069,9 @@ void ivas_dirac_dec_compute_directional_responses_fx( { exp_temp = 0; move16(); - temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( surCohRatio_fx[k] ), exp_surCohRatio, &exp_temp ); - temp = Sqrt32( temp, &exp_temp ); - direct_response_ls_fx[l] = Mpy_32_32( direct_response_ls_fx[l], temp ); // exp_direct_response_ls + exp_temp + temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30 /*1 Q30*/, 1, L_negate( surCohRatio_fx[k] ), exp_surCohRatio, &exp_temp ); // q(31-exp_temp) + temp = Sqrt32( temp, &exp_temp ); // q(31-exp_temp) + direct_response_ls_fx[l] = Mpy_32_32( direct_response_ls_fx[l], temp ); // Q31-(exp_direct_response_ls + exp_temp) move32(); exp_arr[l] = add( exp_direct_response_ls, exp_temp ); @@ -5063,25 +5080,25 @@ void ivas_dirac_dec_compute_directional_responses_fx( { exp_temp_a = 0; move16(); - temp_a = BASOP_Util_Divide3216_Scale( surCohRatio_fx[k], num_channels_surrCoh, &exp_temp_a ); + temp_a = BASOP_Util_Divide3216_Scale( surCohRatio_fx[k], num_channels_surrCoh, &exp_temp_a ); /*15-(exp_temp_a+exp_surCohRatio-15)*/ exp_temp_a = add( exp_temp_a, sub( exp_surCohRatio, 15 ) ); - temp_a = Sqrt16( temp_a, &exp_temp_a ); + temp_a = Sqrt16( temp_a, &exp_temp_a ); /*15-temp_a*/ final_exp = 0; move16(); - final = BASOP_Util_Add_Mant32Exp( direct_response_ls_fx[l], exp_arr[l], L_deposit_h( temp_a ), exp_temp_a, &final_exp ); - direct_response_ls_fx[l] = final; + final = BASOP_Util_Add_Mant32Exp( direct_response_ls_fx[l], exp_arr[l], L_deposit_h( temp_a ), exp_temp_a, &final_exp ); /*31-final_exp*/ + direct_response_ls_fx[l] = final; /*31-final_exp*/ move32(); exp_arr[l] = final_exp; move16(); } } - max_exp = MIN16B; + max_exp = MIN16B; /*Q0*/ move16(); maximum_fx( exp_arr, MAX_OUTPUT_CHANNELS, &max_exp ); FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { - direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], sub( max_exp, exp_arr[l] ) ); + direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], sub( max_exp, exp_arr[l] ) ); /*Q(31-exp_arr[l])->Q(31-max_exp)*/ move32(); } @@ -5093,17 +5110,17 @@ void ivas_dirac_dec_compute_directional_responses_fx( normalizePanningGains_fx( direct_response_ls_fx, &Q_direct_response_ls, num_channels_dir ); exp_direct_response_ls = sub( 31, Q_direct_response_ls ); - Scale_sig32( direct_response_ls_fx, MAX_OUTPUT_CHANNELS, sub( Q29, Q_direct_response_ls ) ); + Scale_sig32( direct_response_ls_fx, MAX_OUTPUT_CHANNELS, sub( Q29, Q_direct_response_ls ) ); /*Q_direct_response_ls->Q29*/ direct_response_q = Q29; move16(); /* Set computed gains */ direct_response_fx = direct_response_ls_fx; - v_mult_fixed( direct_response_fx, direct_response_fx, direct_response_square_fx, num_channels_dir ); + v_mult_fixed( direct_response_fx, direct_response_fx, direct_response_square_fx, num_channels_dir ); /*2*direct_response_q-31*/ direct_response_square_q = sub( add( direct_response_q, direct_response_q ), 31 ); - mvr2r_inc_fixed( direct_response_square_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); - mvr2r_inc_fixed( direct_response_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_square_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*direct_response_square_q*/ + mvr2r_inc_fixed( direct_response_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*direct_response_q*/ } ELSE { @@ -5459,9 +5476,9 @@ void ivas_dirac_dec_compute_directional_responses( #ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_compute_gain_factors_fx( const Word16 num_freq_bands, - const Word32 *diffuseness_fx, - Word32 *direct_gain_factor, - Word32 *diffuse_gain_factor, + const Word32 *diffuseness_fx, /*i:q30*/ + Word32 *direct_gain_factor, /*o:exponent is max_exp_direct*/ + Word32 *diffuse_gain_factor, /*o:exponent is max_exp_diffusion*/ Word16 *max_exp_direct_fx, Word16 *max_exp_diffusion ) { @@ -5475,9 +5492,9 @@ void ivas_dirac_dec_compute_gain_factors_fx( move16(); exp2 = 1; move16(); - direct_gain_factor[i] = Sqrt32( L_sub( ONE_IN_Q30, diffuseness_fx[i] ), &exp1 ); + direct_gain_factor[i] = Sqrt32( L_sub( ONE_IN_Q30 /*1 Q30*/, diffuseness_fx[i] ), &exp1 ); /*31-exp1*/ move32(); - diffuse_gain_factor[i] = Sqrt32( diffuseness_fx[i], &exp2 ); + diffuse_gain_factor[i] = Sqrt32( diffuseness_fx[i], &exp2 ); /*31-exp2*/ move32(); exp_direct_gain_factor[i] = exp1; move16(); @@ -5486,9 +5503,9 @@ void ivas_dirac_dec_compute_gain_factors_fx( } /*make common exp for both buffers*/ - Word16 max_exp_direct = MIN16B; + Word16 max_exp_direct = MIN16B; /*Q0*/ move16(); - Word16 max_exp_diffuse = MIN16B; + Word16 max_exp_diffuse = MIN16B; /*Q0*/ move16(); FOR( i = 0; i < num_freq_bands; i++ ) { @@ -5503,9 +5520,9 @@ void ivas_dirac_dec_compute_gain_factors_fx( FOR( i = 0; i < num_freq_bands; i++ ) { - direct_gain_factor[i] = L_shr( direct_gain_factor[i], sub( max_exp_direct, exp_direct_gain_factor[i] ) ); + direct_gain_factor[i] = L_shr( direct_gain_factor[i], sub( max_exp_direct, exp_direct_gain_factor[i] ) ); /*Q(31-max_exp_direct)*/ move32(); - diffuse_gain_factor[i] = L_shr( diffuse_gain_factor[i], sub( max_exp_diffuse, exp_diffuse_gain_factor[i] ) ); + diffuse_gain_factor[i] = L_shr( diffuse_gain_factor[i], sub( max_exp_diffuse, exp_diffuse_gain_factor[i] ) ); /*Q(31-max_exp_diffuse)*/ move32(); } @@ -5569,8 +5586,8 @@ void ivas_dirac_dec_compute_power_factors_fx( const Word16 num_freq_bands, const Word32 *diffuseness_fx, // Q3O const Word16 max_band_decorr, - Word32 *direct_power_factor, - Word32 *diffuse_power_factor ) + Word32 *direct_power_factor, /*input is q30 and ouput is q29*/ + Word32 *diffuse_power_factor /*input is q30 and ouput is q29*/ ) { Word16 i; @@ -5630,12 +5647,12 @@ void ivas_lfe_synth_with_filters_fx( /* Delay the separated channel to sync the LFE synthesis with the DirAC rendering */ delay = hMasaLfeSynth->delayBuffer_syncDirAC_size; move16(); - delay_signal_fx( data_fx[separateChannelIndex], output_frame, hMasaLfeSynth->delayBuffer_syncDirAC_fx, delay ); + delay_signal_fx( data_fx[separateChannelIndex], output_frame, hMasaLfeSynth->delayBuffer_syncDirAC_fx, delay ); /*q11*/ /* Filterbank for dividing the separated channel to LFE frequencies and higher frequencies */ lowpassCoef_fx_exp = 15; move16(); - lowpassCoef_fx = Inv16( hMasaLfeSynth->ringBufferSize, &lowpassCoef_fx_exp ); + lowpassCoef_fx = Inv16( hMasaLfeSynth->ringBufferSize, &lowpassCoef_fx_exp ); /*15-lowpassCoef_fx_exp*/ FOR( i = 0; i < output_frame; i++ ) { hMasaLfeSynth->lowpassSum_fx = L_add( hMasaLfeSynth->lowpassSum_fx, L_shl( Mpy_32_16_1( L_sub( data_fx[separateChannelIndex][i], hMasaLfeSynth->lfeSynthRingBuffer_fx[hMasaLfeSynth->ringBufferLoPointer] ), lowpassCoef_fx ), lowpassCoef_fx_exp ) ); // Q11 @@ -5685,7 +5702,7 @@ void ivas_lfe_synth_with_filters_fx( Word16 tmp_shift = W_norm( W_tmp ); - W_tmp = W_shl( W_tmp, tmp_shift ); + W_tmp = W_shl( W_tmp, tmp_shift ); /*Q22+tmp_shift*/ Word16 tmp_q = sub( add( Q22, tmp_shift ), 32 ); Word16 tmp_exp; @@ -5716,61 +5733,62 @@ void ivas_lfe_synth_with_filters_fx( IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( hMasaLfeSynth->targetEneLfeSmooth_fx, sub( Q31, hMasaLfeSynth->targetEneLfeSmooth_q ), /*EPSILON + */ hMasaLfeSynth->transportEneSmooth_fx, sub( Q31, hMasaLfeSynth->transportEneSmooth_q ) ), 1 ) ) { - lfeGain_fx = MAX_16; + lfeGain_fx = MAX_16; /* 1.0 in q15*/ move16(); } ELSE { - lfeGain_fx = extract_h( BASOP_Util_Divide3232_Scale_cadence( hMasaLfeSynth->targetEneLfeSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->transportEneSmooth_fx ), &lfeGain_fx_exp ) ); + lfeGain_fx = extract_h( BASOP_Util_Divide3232_Scale_cadence( hMasaLfeSynth->targetEneLfeSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->transportEneSmooth_fx ), &lfeGain_fx_exp ) ); /*Q(31-(lfeGain_fx_exp+hMasaLfeSynth->transportEneSmooth_q-hMasaLfeSynth->targetEneLfeSmooth_q))-16*/ lfeGain_fx_exp = add( sub( hMasaLfeSynth->transportEneSmooth_q, hMasaLfeSynth->targetEneLfeSmooth_q ), lfeGain_fx_exp ); - lfeGain_fx = Sqrt16( lfeGain_fx, &lfeGain_fx_exp ); - lfeGain_fx = shl_r( lfeGain_fx, lfeGain_fx_exp ); // Q15 + lfeGain_fx = Sqrt16( lfeGain_fx, &lfeGain_fx_exp ); // Q15-lfeGain_fx_exp + lfeGain_fx = shl_r( lfeGain_fx, lfeGain_fx_exp ); // Q15 } IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( hMasaLfeSynth->targetEneTransSmooth_fx, sub( Q31, hMasaLfeSynth->targetEneTransSmooth_q ), /*EPSILON + */ hMasaLfeSynth->transportEneSmooth_fx, sub( Q31, hMasaLfeSynth->transportEneSmooth_q ) ), 1 ) ) { - transportGain_fx = MAX_16; + transportGain_fx = MAX_16; // q15 move16(); } ELSE { - transportGain_fx = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneTransSmooth_fx, /*EPSILON + */ hMasaLfeSynth->transportEneSmooth_fx, &transportGain_fx_exp ); + Flag overFlow; + transportGain_fx = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneTransSmooth_fx, /*EPSILON + */ hMasaLfeSynth->transportEneSmooth_fx, &transportGain_fx_exp ); /*Q=15-(transportGain_fx_exp+hMasaLfeSynth->transportEneSmooth_q-hMasaLfeSynth->targetEneTransSmooth_q)*/ transportGain_fx_exp = add( sub( hMasaLfeSynth->transportEneSmooth_q, hMasaLfeSynth->targetEneTransSmooth_q ), transportGain_fx_exp ); - transportGain_fx = Sqrt16( transportGain_fx, &transportGain_fx_exp ); - transportGain_fx = shl_r( transportGain_fx, transportGain_fx_exp ); // Q15 + transportGain_fx = Sqrt16( transportGain_fx, &transportGain_fx_exp ); // q15-transportGain_fx_exp + transportGain_fx = shl_ro( transportGain_fx, transportGain_fx_exp, &overFlow ); // Q15 } j = 0; move16(); FOR( i = mrange[0]; i < mrange[1]; i++ ) { - Word32 L_tmp1 = L_mult( transportGain_fx, hMasaLfeSynth->interpolator_fx[j] ); // Q31 - Word32 L_tmp2 = L_mult( hMasaLfeSynth->transportGainPrev_fx, sub( MAX_16, hMasaLfeSynth->interpolator_fx[j] ) ); // Q31 - data_fx[separateChannelIndex][i] = L_add( Mpy_32_32( L_add( L_tmp1, L_tmp2 ), lowPassSignal_fx[i] ), highPassSignal_fx[i] ); + Word32 L_tmp1 = L_mult( transportGain_fx, hMasaLfeSynth->interpolator_fx[j] ); // Q31 + Word32 L_tmp2 = L_mult( hMasaLfeSynth->transportGainPrev_fx, sub( MAX_16, hMasaLfeSynth->interpolator_fx[j] ) ); // Q31 + data_fx[separateChannelIndex][i] = L_add( Mpy_32_32( L_add( L_tmp1, L_tmp2 ), lowPassSignal_fx[i] ), highPassSignal_fx[i] ); /*q31+q11-q31->q11*/ move32(); - Word32 L_tmp3 = L_mult( lfeGain_fx, hMasaLfeSynth->interpolator_fx[j] ); // Q31 - Word32 L_tmp4 = L_mult( hMasaLfeSynth->lfeGainPrev_fx, sub( MAX_16, hMasaLfeSynth->interpolator_fx[j] ) ); - data_fx[lfeChannelIndex][i] = Mpy_32_32( L_add( L_tmp3, L_tmp4 ), lowPassSignal_fx[i] ); + Word32 L_tmp3 = L_mult( lfeGain_fx, hMasaLfeSynth->interpolator_fx[j] ); // Q31 + Word32 L_tmp4 = L_mult( hMasaLfeSynth->lfeGainPrev_fx, sub( MAX_16, hMasaLfeSynth->interpolator_fx[j] ) ); /*q31*/ + data_fx[lfeChannelIndex][i] = Mpy_32_32( L_add( L_tmp3, L_tmp4 ), lowPassSignal_fx[i] ); /*q31+q11-q31->q11*/ move32(); j = add( j, 1 ); } - hMasaLfeSynth->lfeGainPrev_fx = lfeGain_fx; + hMasaLfeSynth->lfeGainPrev_fx = lfeGain_fx; /*q15*/ move16(); - hMasaLfeSynth->transportGainPrev_fx = transportGain_fx; + hMasaLfeSynth->transportGainPrev_fx = transportGain_fx; /*q15*/ move16(); } /* Lowpass filter for removing remaining mid and high frequencies from the LFE signal */ lowpassCoef_fx_exp = 15; move16(); - lowpassCoef_fx = Inv16( hMasaLfeSynth->ringBufferSize2, &lowpassCoef_fx_exp ); + lowpassCoef_fx = Inv16( hMasaLfeSynth->ringBufferSize2, &lowpassCoef_fx_exp ); // q15-lowpassCoef_fx_exp FOR( i = 0; i < output_frame; i++ ) { hMasaLfeSynth->lowpassSum2_fx = L_add( hMasaLfeSynth->lowpassSum2_fx, L_shl_r( L_sub( Mpy_32_16_1( data_fx[lfeChannelIndex][i], lowpassCoef_fx ), Mpy_32_16_1( hMasaLfeSynth->lfeSynthRingBuffer2_fx[hMasaLfeSynth->ringBufferLoPointer2], lowpassCoef_fx ) ), - lowpassCoef_fx_exp ) ); + lowpassCoef_fx_exp ) ); /*q11+15-lowpassCoef_fx_exp-15+lowpassCoef_fx_exp->q11*/ move32(); - hMasaLfeSynth->lfeSynthRingBuffer2_fx[hMasaLfeSynth->ringBufferLoPointer2] = data_fx[lfeChannelIndex][i]; + hMasaLfeSynth->lfeSynthRingBuffer2_fx[hMasaLfeSynth->ringBufferLoPointer2] = data_fx[lfeChannelIndex][i]; /*q11*/ move32(); hMasaLfeSynth->ringBufferLoPointer2 = sub( hMasaLfeSynth->ringBufferLoPointer2, 1 ); @@ -5781,14 +5799,14 @@ void ivas_lfe_synth_with_filters_fx( move16(); } - data_fx[lfeChannelIndex][i] = hMasaLfeSynth->lowpassSum2_fx; + data_fx[lfeChannelIndex][i] = hMasaLfeSynth->lowpassSum2_fx; /*q11*/ move32(); } /* Delay the separated channel to match the delay of the lowpass filter */ delay = hMasaLfeSynth->delayBuffer_syncLp_size; move16(); - delay_signal_fx( data_fx[separateChannelIndex], output_frame, hMasaLfeSynth->delayBuffer_syncLp_fx, delay ); + delay_signal_fx( data_fx[separateChannelIndex], output_frame, hMasaLfeSynth->delayBuffer_syncLp_fx, delay ); /*q11*/ return; } @@ -5911,14 +5929,14 @@ void ivas_lfe_synth_with_filters( static void computeTargetPSDs_direct_fx( const Word16 num_channels, const Word16 num_freq_bands, - const Word32 *direct_power_factor, - const Word32 *reference_power, + const Word32 *direct_power_factor, /*q31*/ + const Word32 *reference_power, /*q_reference_power*/ const Word16 *q_reference_power, - const Word32 *direct_responses, - const Word32 *direct_responses_square, - Word32 *cy_auto_dir_smooth, + const Word32 *direct_responses, /*q31*/ + const Word32 *direct_responses_square, /*q31*/ + Word32 *cy_auto_dir_smooth, /*q_cy_auto_dir_smooth*/ Word16 *q_cy_auto_dir_smooth, - Word32 *cy_cross_dir_smooth, + Word32 *cy_cross_dir_smooth, /*q_cy_cross_dir_smooth*/ Word16 *q_cy_cross_dir_smooth ) { Word16 ch_idx, cur_idx; @@ -5998,14 +6016,14 @@ static void computeTargetPSDs_direct( static void computeTargetPSDs_direct_subframe_fx( const Word16 num_channels, const Word16 num_freq_bands, - const Word32 *direct_power_factor, - const Word32 *reference_power, + const Word32 *direct_power_factor, /*q31*/ + const Word32 *reference_power, /*q_reference_power*/ const Word16 *q_reference_power, - const Word32 *direct_responses, - const Word32 *direct_responses_square, - Word32 *cy_auto_dir_smooth, + const Word32 *direct_responses, /*q31*/ + const Word32 *direct_responses_square, /*q31*/ + Word32 *cy_auto_dir_smooth, /*q_cy_auto_dir_smooth*/ Word16 *q_cy_auto_dir_smooth, - Word32 *cy_cross_dir_smooth, + Word32 *cy_cross_dir_smooth, /*q_cy_cross_dir_smooth*/ Word16 *q_cy_cross_dir_smooth ) { Word16 ch_idx, cur_idx, i, q_tmp; @@ -6027,14 +6045,17 @@ static void computeTargetPSDs_direct_subframe_fx( move64(); FOR( i = 0; i < num_freq_bands; i++ ) { - W_tmp[i] = W_mult_32_32( direct_power[i], direct_responses_square[cur_idx + i] ); // (q_reference_power, Q31) + 1 + W_tmp[i] = W_mult_32_32( direct_power[i], direct_responses_square[cur_idx + i] ); // q_reference_power + Q31 + 1 move64(); - W_max = W_max < W_abs( W_tmp[i] ) ? W_abs( W_tmp[i] ) : W_max; + IF( LT_64( W_max, W_abs( W_tmp[i] ) ) ) + { + W_max = W_abs( W_tmp[i] ); + } } q_tmp = W_norm( W_max ); FOR( i = 0; i < num_freq_bands; i++ ) { - cy_auto_dir_smooth[cur_idx + i] = W_extract_h( W_shl( W_tmp[i], q_tmp ) ); + cy_auto_dir_smooth[cur_idx + i] = W_extract_h( W_shl( W_tmp[i], q_tmp ) ); /*q_reference_power+q_tmp*/ move32(); } q_cy_auto_dir_smooth[ch_idx] = add( *q_reference_power, q_tmp ); @@ -6085,11 +6106,11 @@ static void computeTargetPSDs_diffuse_fx( const Word16 num_channels, const Word16 num_freq_bands, const Word16 start_band, - const Word32 *diffuse_power_factor, - const Word32 *reference_power, + const Word32 *diffuse_power_factor, /*q31*/ + const Word32 *reference_power, /*q_reference_power*/ const Word16 *q_reference_power, - const Word32 *diffuse_responses_square, - Word32 *cy_auto_diff_smooth, + const Word32 *diffuse_responses_square, /*Q31*/ + Word32 *cy_auto_diff_smooth, /*q_cy_auto_diff_smooth*/ Word16 *q_cy_auto_diff_smooth ) { Word16 ch_idx, cur_idx; @@ -6108,10 +6129,10 @@ static void computeTargetPSDs_diffuse_fx( { cur_idx = imult1616( ch_idx, num_freq_bands ); - v_multc_fixed( &diffuse_power[start_band], diffuse_responses_square[ch_idx], aux_buffer_res, sub( num_freq_bands, start_band ) ); /* Q31 + Q(q_reference_power) - Q31 = Q(q_reference_power) */ - scale_sig32( aux_buffer_res, sub( num_freq_bands, start_band ), sub( common_q, *q_reference_power ) ); /* Q(common_q) */ - scale_sig32( &cy_auto_diff_smooth[add( cur_idx, start_band )], sub( num_freq_bands, start_band ), sub( common_q, *q_cy_auto_diff_smooth ) ); /* Q(common_q) */ - v_add_fixed( &cy_auto_diff_smooth[add( cur_idx, start_band )], aux_buffer_res, &cy_auto_diff_smooth[add( cur_idx, start_band )], sub( num_freq_bands, start_band ), Q1 ); /* Q(common_q) - Q1 */ + v_multc_fixed( &diffuse_power[start_band], diffuse_responses_square[ch_idx], aux_buffer_res, sub( num_freq_bands, start_band ) ); /* Q31 + Q(q_reference_power) - Q31 = Q(q_reference_power) */ + scale_sig32( aux_buffer_res, sub( num_freq_bands, start_band ), sub( common_q, *q_reference_power ) ); /* Q(common_q) */ + scale_sig32( &cy_auto_diff_smooth[cur_idx + start_band], sub( num_freq_bands, start_band ), sub( common_q, *q_cy_auto_diff_smooth ) ); /* Q(common_q) */ + v_add_fixed( &cy_auto_diff_smooth[cur_idx + start_band], aux_buffer_res, &cy_auto_diff_smooth[cur_idx + start_band], sub( num_freq_bands, start_band ), Q1 ); /* Q(common_q) - Q1 */ } /* Q adjustment */ @@ -6157,11 +6178,11 @@ static void computeTargetPSDs_diffuse_subframe_fx( const Word16 num_channels, const Word16 num_freq_bands, const Word16 start_band, - const Word32 *diffuse_power_factor, - const Word32 *reference_power, + const Word32 *diffuse_power_factor, /*q31*/ + const Word32 *reference_power, /*q_reference_power*/ const Word16 *q_reference_power, - const Word32 *diffuse_responses_square, - Word32 *cy_auto_diff_smooth, + const Word32 *diffuse_responses_square, /*q31*/ + Word32 *cy_auto_diff_smooth, /*q_cy_auto_diff_smooth*/ Word16 *q_cy_auto_diff_smooth ) { Word16 ch_idx, cur_idx; @@ -6175,7 +6196,7 @@ static void computeTargetPSDs_diffuse_subframe_fx( { cur_idx = imult1616( ch_idx, num_freq_bands ); - v_multc_fixed( &diffuse_power[start_band], diffuse_responses_square[ch_idx], &cy_auto_diff_smooth[add( cur_idx, start_band )], sub( num_freq_bands, start_band ) ); // (q_reference_power, Q31) -> q_reference_power + v_multc_fixed( &diffuse_power[start_band], diffuse_responses_square[ch_idx], &cy_auto_diff_smooth[cur_idx + start_band], sub( num_freq_bands, start_band ) ); // (q_reference_power, Q31) -> q_reference_power } *q_cy_auto_diff_smooth = *q_reference_power; @@ -6218,12 +6239,12 @@ static void computeTargetPSDs_diffuse_with_onsets_fx( const Word16 num_freq_bands, const Word16 num_decorr_freq_bands, const Word16 *proto_frame_diff_index, - const Word32 *diffuse_power_factor, - const Word32 *reference_power, + const Word32 *diffuse_power_factor, /*q31*/ + const Word32 *reference_power, /* q_reference_power */ const Word16 *q_reference_power, - const Word32 *diffuse_responses_square, - const Word32 *onset_filter, - Word32 *cy_auto_diff_smooth, + const Word32 *diffuse_responses_square, /*q31*/ + const Word32 *onset_filter, /*q31*/ + Word32 *cy_auto_diff_smooth, /*q_cy_auto_diff_smooth*/ Word16 *q_cy_auto_diff_smooth ) { Word16 ch_idx, cur_idx, diff_idx; @@ -6327,7 +6348,7 @@ static void computeTargetPSDs_diffuse_with_onsets( #ifdef IVAS_FLOAT_FIXED -static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 averaging_length_ms, const Word16 maxAlpha_fx, Word16 *numAlphas, const Word16 slot_size, const Word16 num_freq_bands, Word16 *frequency_axis_fx, const Word32 output_Fs ) +static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx /*q15*/, const Word16 averaging_length_ms, const Word16 maxAlpha_fx /*q15*/, Word16 *numAlphas, const Word16 slot_size, const Word16 num_freq_bands, Word16 *frequency_axis_fx /*q0*/, const Word32 output_Fs ) { Word16 k; Word16 avg_length_f_ms_fx; @@ -6340,28 +6361,29 @@ static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 a IF( averaging_length_ms == 0 ) { - set16_fx( alpha_synthesis_fx, MAX16B, num_freq_bands ); + set16_fx( alpha_synthesis_fx, MAX16B, num_freq_bands ); /*q15*/ } ELSE { FOR( k = 0; k < num_freq_bands; k++ ) { Word16 faxis_idx = s_max( k, 1 ); + // avg_length_f_ms = 1000.f * (float)averaging_length_ms / fabsf(frequency_axis[faxis_idx]); Word16 tmp_exp = 0; - Word16 tmp_1 = BASOP_Util_Divide1616_Scale( averaging_length_ms, frequency_axis_fx[faxis_idx], &tmp_exp ); - Word16 tmp_2 = mult( tmp_1, 1000 ); // 15 - tmp_exp + 0 -15 = -tmp_exp (Q-fac) - avg_length_f_ms_fx = tmp_2; + Word16 tmp_1 = BASOP_Util_Divide1616_Scale( averaging_length_ms, frequency_axis_fx[faxis_idx], &tmp_exp ); /*Q(15-(tmp_exp+15-15))*/ + Word16 tmp_2 = mult( tmp_1, 1000 ); // 15 - tmp_exp + 0 -15 = -tmp_exp (Q-fac) + avg_length_f_ms_fx = tmp_2; // Q(-tmp_exp) move16(); move16(); - + /* alpha_synthesis[k] = min( (float) slot_size / ( avg_length_f_ms * (float) output_Fs / 1000.f ), 1.0f );*/ Word32 tmp_3 = Mpy_32_16_1( output_Fs, avg_length_f_ms_fx ); // 0 - tmp_exp - 15 (Q-fac) Word16 tmp_exp_3; - Word16 tmp_4 = BASOP_Util_Divide3232_Scale( tmp_3, 1000, &tmp_exp_3 ); + Word16 tmp_4 = BASOP_Util_Divide3232_Scale( tmp_3, 1000, &tmp_exp_3 ); /*tmp_exp_4 stores resultant exponent*/ Word16 tmp_exp_4 = sub( add( tmp_exp_3, add( add( 31, tmp_exp ), 15 ) ), 31 ); Word16 tmp_exp_5; - Word16 tmp_5 = BASOP_Util_Divide1616_Scale( slot_size, tmp_4, &tmp_exp_5 ); + Word16 tmp_5 = BASOP_Util_Divide1616_Scale( slot_size, tmp_4, &tmp_exp_5 ); /*res_exp stores resultant exponent*/ Word16 res_exp = sub( add( tmp_exp_5, 15 ), tmp_exp_4 ); Word16 flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( tmp_5 ), res_exp, 1, 31 ); @@ -6372,7 +6394,7 @@ static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 a } ELSE { - alpha_synthesis_fx[k] = MAX16B; + alpha_synthesis_fx[k] = MAX16B; /*q15*/ move16(); } @@ -6380,7 +6402,7 @@ static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 a test(); IF( flag2 == 0 || EQ_16( flag2, 1 ) ) { - alpha_synthesis_fx[k] = maxAlpha_fx; + alpha_synthesis_fx[k] = maxAlpha_fx; /*q15*/ move16(); *numAlphas = add( k, 1 ); move16(); @@ -6440,9 +6462,9 @@ static void computeAlphaSynthesis( static void spreadCoherencePanningHoa_fx( const Word16 azimuth, const Word16 elevation, - const Word16 spreadCoh_fx, /*Q15*/ - Word32 *direct_response_fx, /*Q29*/ - Word16 *Q_direct_response, /*Q29*/ + const Word16 spreadCoh_fx, /*i:Q15*/ + Word32 *direct_response_fx, /*i/o:Q_direct_response*/ + Word16 *Q_direct_response, /*i/o:stores q for direct_response_fx*/ const Word16 num_channels_dir, const Word16 ambisonics_order ) { @@ -6453,18 +6475,18 @@ static void spreadCoherencePanningHoa_fx( Word32 gainCenter_fx; Word32 gainSide_fx; - ivas_dirac_dec_get_response_fx( azimuth, elevation, direct_response_fx, ambisonics_order, *Q_direct_response ); + ivas_dirac_dec_get_response_fx( azimuth, elevation, direct_response_fx /*Q_direct_response*/, ambisonics_order, *Q_direct_response ); Word16 exp_Gain_side, exp_Gain_center; IF( spreadCoh_fx > 0 ) { - ivas_dirac_dec_get_response_fx( add( azimuth, 30 ), elevation, direct_response_left_fx, ambisonics_order, *Q_direct_response ); - ivas_dirac_dec_get_response_fx( add( azimuth, 330 ), elevation, direct_response_right_fx, ambisonics_order, *Q_direct_response ); + ivas_dirac_dec_get_response_fx( add( azimuth, 30 ), elevation, direct_response_left_fx /*Q_direct_response*/, ambisonics_order, *Q_direct_response ); + ivas_dirac_dec_get_response_fx( add( azimuth, 330 ), elevation, direct_response_right_fx /*Q_direct_response*/, ambisonics_order, *Q_direct_response ); Word16 var_a, var_b, exp_a; - IF( LT_16( spreadCoh_fx, ONE_IN_Q14 ) ) + IF( LT_16( spreadCoh_fx, ONE_IN_Q14 /*0.5 q15*/ ) ) { /*gainCenter = (3 - 4*spreadCoh )/3*/ var_a = sub( 24576 /*3 in Q13*/, spreadCoh_fx ); // Q13 @@ -6479,16 +6501,16 @@ static void spreadCoherencePanningHoa_fx( } ELSE { - var_a = shl( sub( 16384 /*2 in Q13*/, shr( spreadCoh_fx, 2 ) ), 1 ); + var_a = shl( sub( 16384 /*2 in Q13*/, shr( spreadCoh_fx, 2 ) ), 1 ); // q13 exp_a = 15 - Q13; move16(); - var_a = Inv16( var_a, &exp_a ); - gainSide_fx = L_deposit_h( var_a ); // Q14 + 16 = Q30 //exp_a + var_a = Inv16( var_a, &exp_a ); // 15-exp_a + gainSide_fx = L_deposit_h( var_a ); // 15-exp_a + 16 = Q31 -exp_a exp_Gain_side = exp_a; move16(); var_b = sub( 8192 /*2 in Q12*/, shr( spreadCoh_fx, 2 ) /*Q14*/ ); // exp => 3 - gainCenter_fx = L_deposit_h( mult( var_b, var_a ) ); // Q13 + 16 = Q29 // 3 + exp_a + gainCenter_fx = L_deposit_h( mult( var_b, var_a ) ); // 15-exp_a + 12-15+16=>28-exp_a = // 3 + exp_a exp_Gain_center = add( 3, exp_a ); } @@ -6502,7 +6524,7 @@ static void spreadCoherencePanningHoa_fx( mpy2 = Mpy_32_32( direct_response_fx[i], gainCenter_fx ); // 31 - Q_direct_response + exp_Gain_Center exp = 0; move16(); - direct_response_fx[i] = BASOP_Util_Add_Mant32Exp( mpy1, 31 - *Q_direct_response + exp_Gain_side, mpy2, add( sub( 31, *Q_direct_response ), exp_Gain_center ), &exp ); + direct_response_fx[i] = BASOP_Util_Add_Mant32Exp( mpy1, add( sub( 31, *Q_direct_response ), exp_Gain_side ), mpy2, add( sub( 31, *Q_direct_response ), exp_Gain_center ), &exp ); // 31-exp move32(); exp_arr[i] = exp; move16(); @@ -6515,7 +6537,7 @@ static void spreadCoherencePanningHoa_fx( } FOR( i = 0; i < 16; i++ ) { - direct_response_fx[i] = L_shr( direct_response_fx[i], sub( max_val, exp_arr[i] ) ); + direct_response_fx[i] = L_shr( direct_response_fx[i], sub( max_val, exp_arr[i] ) ); // Q(31-exp_arr[i])->q(31-max_val) move32(); } *Q_direct_response = sub( 31, max_val ); @@ -6571,11 +6593,11 @@ static void spreadCoherencePanningHoa( #ifdef IVAS_FLOAT_FIXED static void spreadCoherencePanningVbap_fx( - const Word16 azimuth, - const Word16 elevation, - const Word16 spreadCoh_fx, - Word32 *direct_response_fx, - Word16 *Q_direct_response, + const Word16 azimuth, /*i:q0*/ + const Word16 elevation, /*i:q0*/ + const Word16 spreadCoh_fx, /*i:q15*/ + Word32 *direct_response_fx, /*i/o:Q_direct_response*/ + Word16 *Q_direct_response, /*o: stores q for direct_response_fx*/ const Word16 num_channels_dir, const VBAP_HANDLE hVBAPdata ) { @@ -6601,14 +6623,14 @@ static void spreadCoherencePanningVbap_fx( } set32_fx( direct_response_fx, 0, MAX_OUTPUT_CHANNELS ); - vbap_determine_gains_fx( hVBAPdata, direct_response_fx, azimuth, elevation, 0 ); + vbap_determine_gains_fx( hVBAPdata, direct_response_fx /*q29*/, azimuth, elevation, 0 ); *Q_direct_response = Q29; move16(); IF( spreadCoh_fx > 0 ) { - vbap_determine_gains_fx( hVBAPdata, direct_response_left_fx, add( azimuth, 30 ), elevation, 0 ); - vbap_determine_gains_fx( hVBAPdata, direct_response_right_fx, sub( azimuth, 30 ), elevation, 0 ); + vbap_determine_gains_fx( hVBAPdata, direct_response_left_fx /*q29*/, add( azimuth, 30 ), elevation, 0 ); + vbap_determine_gains_fx( hVBAPdata, direct_response_right_fx /*q29*/, sub( azimuth, 30 ), elevation, 0 ); Word32 var1 = 0; move32(); @@ -6702,8 +6724,8 @@ static void spreadCoherencePanningVbap( #ifdef IVAS_FLOAT_FIXED static void normalizePanningGains_fx( - Word32 *direct_response_fx, - Word16 *q_direct_res, + Word32 *direct_response_fx, /*i/o:resultant q is q_direct_res*/ + Word16 *q_direct_res, /*i/o: stores q for direct_response_fx*/ const Word16 num_channels_dir ) { Word32 energySum_fx; @@ -6713,7 +6735,7 @@ static void normalizePanningGains_fx( move16(); Word16 gb = find_guarded_bits_fx( num_channels_dir ); - energySum_fx = sum2_f_32_fx( direct_response_fx, num_channels_dir, gb ); + energySum_fx = sum2_f_32_fx( direct_response_fx, num_channels_dir, gb ); // exp_energySum stores resultant exponent IF( GT_16( *q_direct_res, Q31 ) ) { exp_energySum = add( shl( sub( Q31, *q_direct_res ), 1 ), gb ); @@ -6722,17 +6744,17 @@ static void normalizePanningGains_fx( IF( energySum_fx > 0 ) { - normVal_fx = ISqrt32( energySum_fx, &exp_energySum ); + normVal_fx = ISqrt32( energySum_fx, &exp_energySum ); // 31-exp_energySum } ELSE { - energySum_fx = BASOP_Util_Add_Mant32Exp( energySum_fx, exp_energySum, ONE_IN_Q30, 1, &exp_energySum ); - normVal_fx = ISqrt32( energySum_fx, &exp_energySum ); + energySum_fx = BASOP_Util_Add_Mant32Exp( energySum_fx, exp_energySum, ONE_IN_Q30, 1, &exp_energySum ); // 31-exp_energySum + normVal_fx = ISqrt32( energySum_fx, &exp_energySum ); // 31-exp_energySum } FOR( i = 0; i < num_channels_dir; i++ ) { - direct_response_fx[i] = Mpy_32_32( direct_response_fx[i], normVal_fx ); + direct_response_fx[i] = Mpy_32_32( direct_response_fx[i], normVal_fx ); // q_direct_res stores resultant q for the same move32(); } Word16 exp = add( sub( Q31, *q_direct_res ), exp_energySum ); diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index 1b0f31f9bd5969647bc6292c12659ada07b80c20..2d0b9e08dd57b9243097beeb621f052e727df19e 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -55,8 +55,8 @@ #ifndef IVAS_FLOAT_FIXED #define POLY_THRESH 1e-4f #else -#define POLY_THRESH_Q29 53687 // Q29 -#define POLY_THRESH_Q28 26843 // Q28 +#define POLY_THRESH_Q29 53687LL // Q29 +#define POLY_THRESH_Q28 26843 // Q28 #endif #ifdef IVAS_FLOAT_FIXED #define Q22_1 4194304 @@ -83,7 +83,7 @@ static void sort_vertices( const EFAP_VERTEX *vertexArray, const int16_t *numVtx static void visible_edges( const EFAP_LS_TRIANGLE *triArray, const int16_t *visible, const int16_t numSurface, int16_t *numEdges, int16_t *edges ); #else static ivas_error poly_init_fx( EFAP *efap, const Word16 efip_flag ); -static ivas_error sphere_triangulation_fx( const Word16 numSpk, EFAP_VERTEX_DATA *vtxData, EFAP_POLYSET_DATA *polyData, Word32 ***dmTranspose, Word16 *numTot, const Word16 efip_flag ); +static ivas_error sphere_triangulation_fx( const Word16 numSpk, EFAP_VERTEX_DATA *vtxData, EFAP_POLYSET_DATA *polyData, Word32 ***dmTranspose /*q31*/, Word16 *numTot, const Word16 efip_flag ); static void initial_polyeder_fx( EFAP_VERTEX_DATA *vtxData, EFAP_LS_TRIANGLE *triArray, Word16 *numTri, Word16 *vtxInHull ); static void add_ghost_speakers_fx( EFAP_VERTEX *vertexArray, Word16 *numVtx, const Word16 efip_flag ); static void add_vertex_to_convex_hull_fx( const EFAP_VERTEX_DATA *vtxData, const Word16 vtxIdx, Word16 *vtxInHull, EFAP_LS_TRIANGLE *triArray, Word16 *szTri ); @@ -100,12 +100,12 @@ static void efap_panning( const float azi, const float ele, const EFAP_POLYSET_D static void get_poly_gains( const float azi, const float ele, const float aziPoly[EFAP_MAX_CHAN_NUM], const float elePoly[EFAP_MAX_CHAN_NUM], const int16_t numChan, float *buffer ); static float get_tri_gain( const float A[2], const float B[2], const float C[2], const float P_minus_A[2] ); #else -static void flip_plane_fx( const EFAP_VERTEX *vtxArray, Word16 *surface, const Word32 centroid[3] ); -static void remap_ghosts_fx( EFAP_VERTEX *vtxArray, EFAP_LS_TRIANGLE *triArray, Word16 numSpk, Word16 *numVertex, Word16 numTri, Word32 **downmixMatrix ); -static void vertex_init_fx( const Word32 *aziSpk, const Word32 *eleSpk, EFAP_VERTEX_DATA *efapVtxData ); -static void efap_panning_fx( const Word32 azi, const Word32 ele, const EFAP_POLYSET_DATA *polyData, Word32 *bufferL ); -static void get_poly_gains_fx( const Word32 azi, const Word32 ele, const Word32 aziPoly[EFAP_MAX_CHAN_NUM], const Word32 elePoly[EFAP_MAX_CHAN_NUM], const Word16 numChan, Word32 *buffer ); -static Word32 get_tri_gain_fx( const Word32 A[2], const Word32 B[2], const Word32 C[2], const Word32 P_minus_A[2] ); +static void flip_plane_fx( const EFAP_VERTEX *vtxArray, Word16 *surface, const Word32 centroid[3] /*q31*/ ); +static void remap_ghosts_fx( EFAP_VERTEX *vtxArray, EFAP_LS_TRIANGLE *triArray, Word16 numSpk, Word16 *numVertex, Word16 numTri, Word32 **downmixMatrix /*q31*/ ); +static void vertex_init_fx( const Word32 *aziSpk /*q22*/, const Word32 *eleSpk /*q22*/, EFAP_VERTEX_DATA *efapVtxData ); +static void efap_panning_fx( const Word32 azi /*q22*/, const Word32 ele /*q22*/, const EFAP_POLYSET_DATA *polyData, Word32 *bufferL /*q31*/ ); +static void get_poly_gains_fx( const Word32 azi /*q22*/, const Word32 ele /*q22*/, const Word32 aziPoly[EFAP_MAX_CHAN_NUM] /*q22*/, const Word32 elePoly[EFAP_MAX_CHAN_NUM] /*q22*/, const Word16 numChan, Word32 *buffer /*q31*/ ); +static Word32 get_tri_gain_fx( const Word32 A[2] /*q22*/, const Word32 B[2] /*q22*/, const Word32 C[2] /*q22*/, const Word32 P_minus_A[2] /*q22*/ ); #endif /*-----------------------------------------------------------------------* @@ -116,7 +116,7 @@ static Word32 get_tri_gain_fx( const Word32 A[2], const Word32 B[2], const Word3 static void add_vertex( EFAP_VERTEX *vtxArray, const float azi, const float ele, const int16_t pos, const EFAP_VTX_DMX_TYPE ); static void efap_sort_s( int16_t *x, int16_t *idx, const int16_t len ); #else -static void add_vertex_fx( EFAP_VERTEX *vtxArray, const Word32 azi, const Word32 ele, const Word16 pos, const EFAP_VTX_DMX_TYPE ); +static void add_vertex_fx( EFAP_VERTEX *vtxArray, const Word32 azi /*q22*/, const Word32 ele /*q22*/, const Word16 pos, const EFAP_VTX_DMX_TYPE ); static void efap_sort_s_fx( Word16 *x, Word16 *idx, const Word16 len ); #endif @@ -131,9 +131,9 @@ static void remove_vertex( EFAP_VERTEX *vtxArray, const int16_t idx, const int16 static int16_t get_neighbours( const EFAP_LS_TRIANGLE *triArray, const int16_t vtxIdx, const int16_t numTri, int16_t *neighbours ); #else static Word32 vertex_distance_fx( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE tri, const Word16 vtxIdx ); -static Word32 point_plane_distance_fx( const Word32 P1[3], const Word32 P2[3], const Word32 P3[3], const Word32 X[3] ); -static Word32 point_poly_distance_fx( const EFAP_POLYSET poly, const Word32 X[3] ); -static void efap_crossp_fx( const Word32 *v1, const Word32 *v2, Word32 *v ); +static Word32 point_plane_distance_fx( const Word32 P1[3] /*q31*/, const Word32 P2[3] /*q31*/, const Word32 P3[3] /*q31*/, const Word32 X[3] /*q31*/ ); +static Word32 point_poly_distance_fx( const EFAP_POLYSET poly, const Word32 X[3] /*q31*/ ); +static void efap_crossp_fx( const Word32 *v1 /*q30*/, const Word32 *v2 /*q30*/, Word32 *v /*q29*/ ); static Word16 find_int_in_tri_fx( const EFAP_LS_TRIANGLE *tri, const Word16 n, const Word16 r, Word16 *pos ); static void remove_vertex_fx( EFAP_VERTEX *vtxArray, const Word16 idx, const Word16 L ); static Word16 get_neighbours_fx( const EFAP_LS_TRIANGLE *triArray, const Word16 vtxIdx, const Word16 numTri, Word16 *neighbours ); @@ -145,7 +145,7 @@ static void matrix_times_row( float mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TM static void tri_to_poly( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, const int16_t numVtx, const int16_t numTri, int16_t sortedChan[EFAP_MAX_POLY_SET][EFAP_MAX_CHAN_NUM], int16_t *outLengthPS, int16_t outLengthSorted[EFAP_MAX_POLY_SET] ); static int16_t compare_poly( int16_t *old, int16_t lenOld, int16_t *new, int16_t lenNew ); #else -static void matrix_times_row_fx( Word32 mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF], const Word32 *vec, const Word16 L, Word32 *out ); +static void matrix_times_row_fx( Word32 mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF] /*q31*/, const Word32 *vec /*q31*/, const Word16 L, Word32 *out /*q31*/ ); static void tri_to_poly_fx( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, const Word16 numVtx, const Word16 numTri, Word16 sortedChan[EFAP_MAX_POLY_SET][EFAP_MAX_CHAN_NUM], Word16 *outLengthPS, Word16 outLengthSorted[EFAP_MAX_POLY_SET] ); static Word16 compare_poly_fx( Word16 *old, Word16 lenOld, Word16 *new, Word16 lenNew ); #endif @@ -160,11 +160,11 @@ static int16_t in_tri( float A[2], float B[2], float C[2], float P_minus_A[2] ); static void sph2cart( const float azi, const float ele, float *pos ); #else static void sort_channels_vertex_fx( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, Word16 channels[EFAP_MAX_CHAN_NUM], const Word16 lengthChannels, Word16 idxTri ); -static Word32 efap_32mod32( const Word32 x, const Word32 y ); -static Word16 get_poly_num_fx( const Word32 P[2], const EFAP_POLYSET_DATA *polyData ); -static Word16 in_poly_fx( const Word32 P[2], const EFAP_POLYSET poly ); -static Word16 in_tri_fx( Word32 A[2], Word32 B[2], Word32 C[2], Word32 P_minus_A[2] ); -static void sph2cart_fx( const Word32 azi, const Word32 ele, Word32 *pos ); +static Word32 efap_32mod32( const Word32 x /*q22*/, const Word32 y /*q22*/ ); +static Word16 get_poly_num_fx( const Word32 P[2] /*q22*/, const EFAP_POLYSET_DATA *polyData ); +static Word16 in_poly_fx( const Word32 P[2] /*q22*/, const EFAP_POLYSET poly ); +static Word16 in_tri_fx( Word32 A[2] /*q22*/, Word32 B[2] /*q22*/, Word32 C[2] /*q22*/, Word32 P_minus_A[2] /*q22*/ ); +static void sph2cart_fx( const Word32 azi /*q22*/, const Word32 ele /*q22*/, Word32 *pos /*q31*/ ); #endif /*-----------------------------------------------------------------------* @@ -245,8 +245,8 @@ ivas_error efap_init_data_fx( move16(); /* Loudspeaker configuration */ - Copy32( speaker_node_azi_deg, efap->aziSpk, num_speaker_nodes ); - Copy32( speaker_node_ele_deg, efap->eleSpk, num_speaker_nodes ); + Copy32( speaker_node_azi_deg, efap->aziSpk, num_speaker_nodes ); // Q22 + Copy32( speaker_node_ele_deg, efap->eleSpk, num_speaker_nodes ); // Q22 /* Initialization of the vertex */ vertex_init_fx( efap->aziSpk, efap->eleSpk, &efap->vtxData ); @@ -384,10 +384,10 @@ void efap_determine_gains_fx( set32_fx( hEFAPdata->bufferLong_fx, 0, hEFAPdata->vtxData.numVtx ); /* Wrap angles to correct range */ - panning_wrap_angles_fixed( azi_deg, ele_deg, &azi_wrap_int, &ele_wrap_int ); + panning_wrap_angles_fx( azi_deg, ele_deg, &azi_wrap_int, &ele_wrap_int ); // ouputs in q22 /* Panning */ - efap_panning_fx( azi_wrap_int, ele_wrap_int, &hEFAPdata->polyData, hEFAPdata->bufferLong_fx ); + efap_panning_fx( azi_wrap_int, ele_wrap_int, &hEFAPdata->polyData, hEFAPdata->bufferLong_fx ); // hEFAPdata->bufferLong_fx q31 IF( efap_mode == EFAP_MODE_EFAP ) { @@ -407,11 +407,11 @@ void efap_determine_gains_fx( } Word16 exp = 2; move16(); - normBuffer = ISqrt32( normBuffer, &exp ); + normBuffer = ISqrt32( normBuffer, &exp ); // Q=(31-exp) FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { - hEFAPdata->bufferShort_fx[j] = Mpy_32_32( hEFAPdata->bufferShort_fx[j], normBuffer ); + hEFAPdata->bufferShort_fx[j] = Mpy_32_32( hEFAPdata->bufferShort_fx[j], normBuffer ); // Q=(30+31-exp-31)=>(30-exp) move32(); hEFAPdata->bufferShort_fx[j] = L_shl( hEFAPdata->bufferShort_fx[j], exp ); /* Q30 */ move32(); @@ -435,12 +435,12 @@ void efap_determine_gains_fx( } Word16 exp = 2; move16(); - normBuffer = Inv16( extract_l( L_shr( normBuffer, Q16 ) ), &exp ); + normBuffer = Inv16( extract_l( L_shr( normBuffer, Q16 ) ), &exp ); /*Q=(15-exp)*/ FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { Word16 exp_temp = add( exp, 1 ); - hEFAPdata->bufferShort_fx[j] = Sqrt32( Mpy_32_16_1( hEFAPdata->bufferShort_fx[j], (Word16) normBuffer ), &exp_temp ); + hEFAPdata->bufferShort_fx[j] = Sqrt32( Mpy_32_16_1( hEFAPdata->bufferShort_fx[j], extract_l( normBuffer ) ) /*Q(30-exp)*/, &exp_temp ); // Q=(31-exp_temp) move32(); hEFAPdata->bufferShort_fx[j] = L_shl( hEFAPdata->bufferShort_fx[j], sub( exp_temp, 1 ) ); /* Q30 */ move32(); @@ -683,8 +683,8 @@ static ivas_error poly_init_fx( FOR( n = 0; n < efap->vtxData.numVtx; ++n ) { test(); - if ( GT_32( efap->vtxData.vertexArray[n].ele, L_sub( Q22_90_DEG, 4 ) ) || - LT_32( efap->vtxData.vertexArray[n].ele, L_sub( 4, Q22_90_DEG ) ) ) + if ( GT_32( efap->vtxData.vertexArray[n].ele /*Q22*/, ( Q22_90_DEG /*90.0 Q22*/ - 4 /*1e-6 Q22*/ ) ) || + LT_32( efap->vtxData.vertexArray[n].ele /*Q22*/, ( 4 /*1e-6 Q22*/ - Q22_90_DEG /*90.0 Q22*/ ) ) ) { efap->vtxData.vertexArray[n].isNaN = 1; move16(); @@ -722,35 +722,35 @@ static ivas_error poly_init_fx( maximum_l( efap->polyData.polysetArray[m].polyAzi, lengthTri2PolySorted[n], &tmpMax ); minimum_l( efap->polyData.polysetArray[m].polyAzi, lengthTri2PolySorted[n], &tmpMin ); - IF( GT_32( L_sub( tmpMax, tmpMin ), Q22_180_DEG ) /*180 in Q22*/ ) + IF( GT_32( L_sub( tmpMax /*q22*/, tmpMin /*q22*/ ), Q22_180_DEG /*180 in Q22*/ ) ) { FOR( j = 0; j < lengthTri2PolySorted[n]; ++j ) { assert( ( m + 2 < EFAP_MAX_POLY_SET ) && "EFAP: maximum polygons exceeded!" ); /* add two new polygons with azimuths wrapped to differing bounds */ - efap->polyData.polysetArray[add( m, 1 )].polyAzi[j] = efap_32mod32( efap->polyData.polysetArray[m].polyAzi[j], Q22_360_DEG ); /* Q22 */ + efap->polyData.polysetArray[m + 1].polyAzi[j] = efap_32mod32( efap->polyData.polysetArray[m].polyAzi[j] /*q22*/, Q22_360_DEG /*360 q22*/ ); /* Q22 */ move32(); - efap->polyData.polysetArray[add( m, 2 )].polyAzi[j] = L_sub( efap->polyData.polysetArray[add( m, 1 )].polyAzi[j], Q22_360_DEG ); /* Q22 */ + efap->polyData.polysetArray[m + 2].polyAzi[j] = L_sub( efap->polyData.polysetArray[m + 1].polyAzi[j] /*q22*/, Q22_360_DEG /*360 q22*/ ); /* Q22 */ move32(); /* Copy the rest of the fields */ - efap->polyData.polysetArray[add( m, 1 )].chan[j] = efap->polyData.polysetArray[m].chan[j]; + efap->polyData.polysetArray[m + 1].chan[j] = efap->polyData.polysetArray[m].chan[j]; move16(); - efap->polyData.polysetArray[add( m, 1 )].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ + efap->polyData.polysetArray[m + 1].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ move32(); - efap->polyData.polysetArray[add( m, 1 )].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; + efap->polyData.polysetArray[m + 1].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; move16(); - efap->polyData.polysetArray[add( m, 1 )].numChan = lengthTri2PolySorted[n]; + efap->polyData.polysetArray[m + 1].numChan = lengthTri2PolySorted[n]; move16(); - efap->polyData.polysetArray[add( m, 2 )].chan[j] = efap->polyData.polysetArray[m].chan[j]; + efap->polyData.polysetArray[m + 2].chan[j] = efap->polyData.polysetArray[m].chan[j]; move16(); - efap->polyData.polysetArray[add( m, 2 )].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ + efap->polyData.polysetArray[m + 2].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ move32(); - efap->polyData.polysetArray[add( m, 2 )].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; + efap->polyData.polysetArray[m + 2].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; move16(); - efap->polyData.polysetArray[add( m, 2 )].numChan = lengthTri2PolySorted[n]; + efap->polyData.polysetArray[m + 2].numChan = lengthTri2PolySorted[n]; move16(); } finalLength = add( finalLength, 2 ); @@ -928,7 +928,7 @@ static ivas_error sphere_triangulation_fx( *dmTranspose_fx = (Word32 **) p_dmTranspose; /* Remap Ghosts */ -remap_ghosts_fx( vtxData->vertexArray, polyData->triArray, numSpk, &vtxData->numVtx, polyData->numTri, *dmTranspose_fx ); +remap_ghosts_fx( vtxData->vertexArray, polyData->triArray, numSpk, &vtxData->numVtx, polyData->numTri, *dmTranspose_fx ); // dmTranspose_fx q31 return IVAS_ERR_OK; } @@ -1161,9 +1161,11 @@ static void initial_polyeder_fx( } /* 1. attempt to create an edge with nonzero length */ - WHILE( EQ_32( vtxData->vertexArray[tetrahedron[0]].azi, vtxData->vertexArray[tetrahedron[1]].azi ) && - EQ_32( vtxData->vertexArray[tetrahedron[0]].ele, vtxData->vertexArray[tetrahedron[1]].ele ) ) + test(); + WHILE( EQ_32( vtxData->vertexArray[tetrahedron[0]].azi /*q22*/, vtxData->vertexArray[tetrahedron[1]].azi /*q22*/ ) && + EQ_32( vtxData->vertexArray[tetrahedron[0]].ele /*q22*/, vtxData->vertexArray[tetrahedron[1]].ele /*q22*/ ) ) { + test(); tetrahedron[1] = add( tetrahedron[1], 1 ); move16(); assert( tetrahedron[1] < numVtx && "EFAP: convex hull construction failed, vertices are coincident!" ); @@ -1172,16 +1174,16 @@ static void initial_polyeder_fx( /* 2. attempt to create a triangle with nonzero area */ tmp = 0; move32(); - v_sub_fixed( vtxData->vertexArray[tetrahedron[1]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp1, 3, 1 ); + v_sub_fixed( vtxData->vertexArray[tetrahedron[1]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp1, 3, 1 ); // tmp1 Q(31-1) WHILE( LT_16( tetrahedron[2], numVtx ) ) { - v_sub_fixed( vtxData->vertexArray[tetrahedron[2]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp2, 3, 1 ); - efap_crossp_fx( tmp1, tmp2, tmpCross ); // tmpCross Q29 + v_sub_fixed( vtxData->vertexArray[tetrahedron[2]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp2, 3, 1 ); // tmp2 Q(31-1) + efap_crossp_fx( tmp1, tmp2, tmpCross ); // tmpCross Q29 FOR( i = 0; i < 3; i++ ) { tmp = L_add( tmp, Mpy_32_32( tmpCross[i], tmpCross[i] ) ); // tmp Q27 } - IF( GT_32( L_abs( tmp ), Mpy_32_32( POLY_THRESH_Q29, POLY_THRESH_Q29 ) ) ) /* compare tmp against POLY_THRESH^2 instead of sqrtf(tmp) */ + IF( GT_32( L_abs( tmp ), ( POLY_THRESH_Q29 /*1e-4f Q29*/ * POLY_THRESH_Q29 /*1e-4f Q29*/ ) >> 31 ) ) /* compare tmp against POLY_THRESH^2 instead of sqrtf(tmp) */ { BREAK; } @@ -1197,7 +1199,7 @@ static void initial_polyeder_fx( { v_sub_fixed( vtxData->vertexArray[tetrahedron[3]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp3, 3, 1 ); // tmp3 Q30 tmp = dotp_fixed( tmp3, tmpCross, 3 ); // tmp Q28 - IF( GT_32( L_abs( tmp ), POLY_THRESH_Q28 ) ) + IF( GT_32( L_abs( tmp ), POLY_THRESH_Q28 /*1e-4f Q28*/ ) ) { BREAK; } @@ -1211,11 +1213,11 @@ static void initial_polyeder_fx( { vtxInHull[tetrahedron[i]] = 1; /* set vertex as added to hull*/ move16(); - centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[0], Q2 ) ); + centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[0], Q2 ) ); // Q29 move32(); - centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[1], Q2 ) ); + centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[1], Q2 ) ); // Q29 move32(); - centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[2], Q2 ) ); + centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[2], Q2 ) ); // Q29 move32(); } /* Executed below float operation @@ -1460,33 +1462,34 @@ static void add_ghost_speakers_fx( Word32 tmpAngleDiff[EFAP_MAX_SIZE_TMP_BUFF]; /* tmp array of angles differences */ Word32 sectors[EFAP_MAX_SIZE_TMP_BUFF]; /* Help us determine the zone where we should extend LS */ EFAP_VTX_DMX_TYPE vtxDmxType; + Word16 new_diff_e; vtxDmxType = EFAP_DMX_INTENSITY; move32(); numVertex = *numVtx; move16(); - maxAngle = 13421773; - move32(); //(1.f / 160.0f) in Q31 + maxAngle = 13421773; //(1.f / 160.0f) in Q31 + move32(); /* Extracting Azi and Ele for computation purposes */ FOR( i = 0; i < numVertex; ++i ) { - ele[i] = vertexArray[i].ele; + ele[i] = vertexArray[i].ele; // q22 move32(); } /* ADD VOG IF NECESSERAY (i.e. if the elevation of the highest LS is < 90 deg) */ a = 0; move16(); - maximum_l( ele, numVertex, &tmpEle ); + maximum_l( ele, numVertex, &tmpEle ); // tmpEle q22 lengthVertGhst = 0; move16(); - IF( LT_32( tmpEle, Q22_90_DEG ) ) + IF( LT_32( tmpEle, Q22_90_DEG /*90 q22*/ ) ) { IF( efip_flag ) { - IF( GT_32( tmpEle, Q22_45_DEG ) ) + IF( GT_32( tmpEle, Q22_45_DEG /*45 q22*/ ) ) { vtxDmxType = EFAP_DMX_NONE; move32(); @@ -1497,18 +1500,18 @@ static void add_ghost_speakers_fx( move32(); } } - add_vertex_fx( vertexArray, 0, Q22_90_DEG, add( numVertex, a ), vtxDmxType ); + add_vertex_fx( vertexArray, 0, Q22_90_DEG /*90 q22*/, add( numVertex, a ), vtxDmxType ); lengthVertGhst = add( lengthVertGhst, 1 ); a = add( a, 1 ); } /* ADD VOH IF NECESSERAY (i.e. if the elevation of the lowest LS is > -90 deg) */ - minimum_l( ele, numVertex, &tmpEle ); - IF( GT_32( tmpEle, -Q22_90_DEG ) ) + minimum_l( ele, numVertex, &tmpEle ); /*tmpEle q22*/ + IF( GT_32( tmpEle, -Q22_90_DEG /*90 q22*/ ) ) { IF( efip_flag ) { - IF( LT_32( tmpEle, -Q22_45_DEG ) ) + IF( LT_32( tmpEle, -Q22_45_DEG /*45 q22*/ ) ) { vtxDmxType = EFAP_DMX_NONE; move32(); @@ -1520,7 +1523,7 @@ static void add_ghost_speakers_fx( } } - add_vertex_fx( vertexArray, 0, -Q22_90_DEG, add( numVertex, a ), vtxDmxType ); + add_vertex_fx( vertexArray, 0, -Q22_90_DEG /*90 q22*/, add( numVertex, a ), vtxDmxType ); lengthVertGhst = add( lengthVertGhst, 1 ); a = add( a, 1 ); @@ -1532,9 +1535,9 @@ static void add_ghost_speakers_fx( FOR( i = 0; i < numVertex; ++i ) { - IF( LT_32( L_abs( vertexArray[i].ele ), Q22_45_DEG ) ) + IF( LT_32( L_abs( vertexArray[i].ele ), Q22_45_DEG /*45 q22*/ ) ) { - tmpAzi[k] = vertexArray[i].azi; + tmpAzi[k] = vertexArray[i].azi; // q22 move32(); k = add( k, 1 ); } @@ -1542,44 +1545,44 @@ static void add_ghost_speakers_fx( lengthHorGhst = 0; move16(); - IF( EQ_16( k, 0 ) ) /* no speakers found: add a triangle of ghost speakers */ + IF( k == 0 ) /* no speakers found: add a triangle of ghost speakers */ { add_vertex_fx( vertexArray, 0, 0, add( numVertex, a ), EFAP_DMX_INTENSITY ); - add_vertex_fx( vertexArray, Q22_120_DEG, 0, add( add( numVertex, a ), 1 ), EFAP_DMX_INTENSITY ); - add_vertex_fx( vertexArray, Q22_240_DEG, 0, add( add( numVertex, a ), 2 ), EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, Q22_120_DEG /*120 q22*/, 0, add( add( numVertex, a ), 1 ), EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, Q22_240_DEG /*240 q22*/, 0, add( add( numVertex, a ), 2 ), EFAP_DMX_INTENSITY ); a = add( a, 3 ); lengthHorGhst = add( lengthHorGhst, 3 ); } ELSE IF( EQ_16( k, 1 ) ) /* only one speaker found: add two ghost speakers to complete a triangle */ { - add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_120_DEG ), 0, numVertex + a, EFAP_DMX_INTENSITY ); - add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_240_DEG ), 0, numVertex + a + 1, EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_120_DEG /*120 q22*/ ), 0, add( numVertex, a ), EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_240_DEG /*240 q22*/ ), 0, add( add( numVertex, a ), 1 ), EFAP_DMX_INTENSITY ); a = add( a, 2 ); lengthHorGhst = add( lengthHorGhst, 2 ); } ELSE /* fill gaps greater than maxAngle */ { /* Here, k correspond to the number of LS whose ele is < 45 deg, should be = numVertex */ - sort_l( tmpAzi, k ); + sort_l( tmpAzi, k ); // tmpAzi q22 /* The next lines correspond to angle_diff = [azi(2:end), azi(1) + 360] - azi; in Matlab */ FOR( i = 0; i < k - 1; ++i ) { - tmpAngleDiff[i] = L_sub( tmpAzi[i + 1], tmpAzi[i] ); + tmpAngleDiff[i] = L_sub( tmpAzi[i + 1], tmpAzi[i] ); // q22 move32(); - sectors[i] = ceil_fixed( Mpy_32_32( tmpAngleDiff[i], maxAngle ), Q22 ); + sectors[i] = ceil_fixed( Mpy_32_32( tmpAngleDiff[i], maxAngle ), Q22 ); // q22 move32(); - IF( GT_32( sectors[i], Q22_1 ) ) + if ( GT_32( sectors[i], Q22_1 /*1 q22*/ ) ) { lengthHorGhst = add( lengthHorGhst, 1 ); } } - tmpAngleDiff[sub( k, 1 )] = L_sub( L_add( tmpAzi[0], Q22_360_DEG ), tmpAzi[sub( k, 1 )] ); + tmpAngleDiff[k - 1] = L_sub( L_add( tmpAzi[0], Q22_360_DEG /*360 q22*/ ), tmpAzi[k - 1] ); // q22 - sectors[sub( k, 1 )] = ceil_fixed( Mpy_32_32( tmpAngleDiff[sub( k, 1 )], maxAngle ), Q22 ); + sectors[k - 1] = ceil_fixed( Mpy_32_32( tmpAngleDiff[k - 1], maxAngle ), Q22 ); // q22 - IF( GT_32( sectors[sub( k, 1 )], Q22_1 ) ) + if ( GT_32( sectors[k - 1], Q22_1 /*1 q22*/ ) ) { lengthHorGhst = add( lengthHorGhst, 1 ); } @@ -1587,19 +1590,20 @@ static void add_ghost_speakers_fx( /* Adding new virtual speakers */ FOR( i = 0; i < k; ++i ) { - IF( GT_32( sectors[i], Q22_1 ) ) + IF( GT_32( sectors[i], Q22_1 /*1 q22*/ ) ) { - newDiff = tmpAngleDiff[i] / sectors[i]; - num_new = (Word16) L_shr( L_sub( sectors[i], Q22_1 ), Q22 ); + newDiff = BASOP_Util_Divide3232_Scale( tmpAngleDiff[i], sectors[i], &new_diff_e ); // Q=15-new_diff_e + newDiff = L_shl( newDiff, add( new_diff_e, 7 ) ); // q22 + num_new = extract_l( L_shr( L_sub( sectors[i], Q22_1 /*1 q22*/ ), Q22 ) ); // q0 FOR( j = 0; j < num_new; ++j ) { - newAzi = L_add( tmpAzi[i], L_shl( ( j + 1 ) * newDiff, Q22 ) ); + newAzi = L_add( tmpAzi[i], imult3216( newDiff, add( j, 1 ) ) ); // q22 add_vertex_fx( vertexArray, newAzi, 0, add( numVertex, a ), EFAP_DMX_INTENSITY ); a = add( a, 1 ); - IF( j > 0 ) + if ( j > 0 ) { lengthHorGhst = add( lengthHorGhst, 1 ); } @@ -1784,8 +1788,8 @@ static void add_vertex_to_convex_hull_fx( Word16 surface[3]; Word32 numHullVtx; Word32 centroid[3]; - const Word32 threshold = -268; - move32(); // -1e-6f in Q28 + const Word32 threshold = -268; // -1e-6f in Q28 + move32(); Word32 tmpDist; EFAP_LS_TRIANGLE triArrayNew[EFAP_MAX_POLY_SET]; Word16 tmp16, tmp_e; @@ -1806,30 +1810,30 @@ static void add_vertex_to_convex_hull_fx( IF( vtxInHull[i] ) { numHullVtx = L_add( numHullVtx, 1 ); - centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[i].pos[0], Q4 ) ); + centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[i].pos[0], Q4 ) ); // q27 move32(); - centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[i].pos[1], Q4 ) ); + centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[i].pos[1], Q4 ) ); // q27 move32(); - centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[i].pos[2], Q4 ) ); + centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[i].pos[2], Q4 ) ); // q27 move32(); } } /* numHullVtx = 1.0f / numHullVtx; */ - tmp16 = BASOP_Util_Divide3232_Scale( 1, numHullVtx, &tmp_e ); - tmp32 = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ + tmp16 = BASOP_Util_Divide3232_Scale( 1, numHullVtx, &tmp_e ); // q15-tmp_e + tmp32 = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ - centroid[0] = Mpy_32_32( centroid[0], tmp32 ); + centroid[0] = Mpy_32_32( centroid[0], tmp32 ); // q27 move32(); - centroid[1] = Mpy_32_32( centroid[1], tmp32 ); + centroid[1] = Mpy_32_32( centroid[1], tmp32 ); // q27 move32(); - centroid[2] = Mpy_32_32( centroid[1], tmp32 ); + centroid[2] = Mpy_32_32( centroid[1], tmp32 ); // q27 move32(); - centroid[0] = L_shl( centroid[0], 4 ); + centroid[0] = L_shl( centroid[0], 4 ); // q31 move32(); - centroid[1] = L_shl( centroid[1], 4 ); + centroid[1] = L_shl( centroid[1], 4 ); // q31 move32(); - centroid[2] = L_shl( centroid[2], 4 ); + centroid[2] = L_shl( centroid[2], 4 ); // q31 move32(); /* Processing */ @@ -1920,13 +1924,13 @@ static void visible_edges_fx( /* Finding the max vertex */ FOR( i = 0; i < numSurface; ++i ) { - tmpMax[i] = triArray[visible[i]].LS[0]; + tmpMax[i] = triArray[visible[i]].LS[0]; // q0 move16(); FOR( j = 1; j < 3; ++j ) { if ( LT_16( tmpMax[i], triArray[visible[i]].LS[j] ) ) { - tmpMax[i] = triArray[visible[i]].LS[j]; + tmpMax[i] = triArray[visible[i]].LS[j]; // q0 move16(); } } @@ -1977,7 +1981,7 @@ static void visible_edges_fx( { edges[k] = a; move16(); - edges[add( k, 1 )] = b; + edges[k + 1] = b; move16(); k = add( k, 2 ); } @@ -2117,7 +2121,7 @@ static void flip_plane( static void flip_plane_fx( const EFAP_VERTEX *vtxArray, /* i : Vertex array */ Word16 *surface, /* i/o: Surface/vertices to be flipped */ - const Word32 centroid[3] /* i : Centroid of convex hull from which to orient the planes outward */ + const Word32 centroid[3] /* i : Centroid of convex hull from which to orient the planes outward q31*/ ) { Word16 tmp; @@ -2127,7 +2131,7 @@ static void flip_plane_fx( vtxArray[surface[0]].pos, vtxArray[surface[1]].pos, vtxArray[surface[2]].pos, - centroid ); + centroid ); // q31 IF( dist > 0 ) { @@ -2319,9 +2323,10 @@ static void remap_ghosts_fx( Word32 tmpMat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF]; /* Q31 */ Word32 tmpNewMat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF]; /* Q31 */ Word32 tmpDist; - const Word32 thresh = 214748; + Word16 tmpDist_e; + const Word32 thresh = 214748; // 1e-4f in Q31 Word16 tmp16, tmp_e; - move32(); // 1e-4f in Q31 + move32(); set32_fx( tmpVec, 0, EFAP_MAX_SIZE_TMP_BUFF ); set32_fx( tmpVec2, 0, EFAP_MAX_SIZE_TMP_BUFF ); @@ -2333,7 +2338,7 @@ static void remap_ghosts_fx( IF( find_int_in_tri_fx( triArray, g, numTri, posFound ) == 0 ) { remove_vertex_fx( vtxArray, g, numVtx ); - --numVtx; + numVtx = sub( numVtx, 1 ); FOR( i = 0; i < numTri; ++i ) { FOR( j = 0; j < 3; ++j ) @@ -2361,9 +2366,9 @@ static void remap_ghosts_fx( set32_fx( tmpMat[i], 0, numTot ); set32_fx( tmpNewMat[i], 0, numTot ); - tmpMat[i][i] = ONE_IN_Q31; + tmpMat[i][i] = ONE_IN_Q31; // q31 move32(); - tmpNewMat[i][i] = ONE_IN_Q31; + tmpNewMat[i][i] = ONE_IN_Q31; // q31 move32(); } @@ -2382,8 +2387,8 @@ static void remap_ghosts_fx( } /* The neighbours are set to 1.0/tmpL */ - tmp16 = BASOP_Util_Divide3232_Scale( 1, tmpL, &tmp_e ); - inv_tmpL = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ + tmp16 = BASOP_Util_Divide3232_Scale( 1, tmpL, &tmp_e ); // Q=15-tmp_e + inv_tmpL = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ FOR( j = 0; j < tmpL; ++j ) { tmpMat[neighbours[j]][i] = inv_tmpL; /* Q31 */ @@ -2405,18 +2410,22 @@ static void remap_ghosts_fx( FOR( i = numSpk; i < numTot; ++i ) { - Copy32( tmpNewMat[i], tmpVec, numTot ); + Copy32( tmpNewMat[i], tmpVec, numTot ); // q31 - tmpDist = sum_l( &tmpVec[numSpk], sub( numTot, numSpk ) ); + tmpDist_e = 0; + move16(); + tmpDist = sum_32_fx( &tmpVec[numSpk], sub( numTot, numSpk ), &tmpDist_e ); // Q=31-tmpDist_e - WHILE( GT_32( tmpDist, thresh ) ) + WHILE( EQ_16( BASOP_Util_Cmp_Mant32Exp( tmpDist, tmpDist_e, thresh, 0 ), 1 ) ) { - matrix_times_row_fx( tmpMat, tmpVec, numTot, tmpVec2 ); - Copy32( tmpVec2, tmpVec, numTot ); + matrix_times_row_fx( tmpMat, tmpVec, numTot, tmpVec2 ); // tmpVec2 Q31 + Copy32( tmpVec2, tmpVec, numTot ); // Q31 set32_fx( tmpVec2, 0, numTot ); - tmpDist = sum_l( &tmpVec[numSpk], sub( numTot, numSpk ) ); + tmpDist_e = 0; + move16(); + tmpDist = sum_32_fx( &tmpVec[numSpk], sub( numTot, numSpk ), &tmpDist_e ); } - Copy32( tmpVec, tmpNewMat[i], numTot ); + Copy32( tmpVec, tmpNewMat[i], numTot ); // q31 } FOR( i = 0; i < numSpk; ++i ) @@ -2425,7 +2434,7 @@ static void remap_ghosts_fx( FOR( j = 0; j < numSpk; ++j ) { test(); - IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], 0x7fffffff ) ) + IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], 0x7fffffff /*q31*/ ) ) { downmixMatrixTranspose[j][i] = tmpNewMat[j][i]; /* Q31 */ move32(); @@ -2434,9 +2443,9 @@ static void remap_ghosts_fx( { Word16 exp = 0; move16(); - Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); - tmp_sqrt = L_shl( tmp_sqrt, exp ); - downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ + Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); /*31-exp*/ + tmp_sqrt = L_shl( tmp_sqrt, exp ); /*q31*/ + downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ move32(); } } @@ -2456,7 +2465,7 @@ static void remap_ghosts_fx( case EFAP_DMX_INTENSITY: default: test(); - IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], ONE_IN_Q31 ) ) + IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], ONE_IN_Q31 /*q31*/ ) ) { downmixMatrixTranspose[j][i] = tmpNewMat[j][i]; /* Q31 */ move32(); @@ -2465,9 +2474,9 @@ static void remap_ghosts_fx( { Word16 exp = 0; move16(); - Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); - tmp_sqrt = L_shl( tmp_sqrt, exp ); - downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ + Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); /*31-exp*/ + tmp_sqrt = L_shl( tmp_sqrt, exp ); /*31*/ + downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ move32(); } BREAK; @@ -2515,8 +2524,8 @@ static void vertex_init( *-------------------------------------------------------------------------*/ static void vertex_init_fx( - const Word32 *aziSpk, /* i : Azimuths of the LS setup */ - const Word32 *eleSpk, /* i : Elevations of the LS setup */ + const Word32 *aziSpk, /* i : Azimuths of the LS setup q22 */ + const Word32 *eleSpk, /* i : Elevations of the LS setup q22 */ EFAP_VERTEX_DATA *efapVtxData /* i/o: Vertex data structure that will be updated */ ) { @@ -2606,10 +2615,10 @@ static void efap_panning( *-------------------------------------------------------------------------*/ static void efap_panning_fx( - const Word32 azi, /* i : Value of the azimuth */ - const Word32 ele, /* i : Value of the elevation */ + const Word32 azi, /* i : Value of the azimuth q22 */ + const Word32 ele, /* i : Value of the elevation q22 */ const EFAP_POLYSET_DATA *polyData, /* i : Polygon data */ - Word32 *bufferL /* o : 1D array of length numSpk that will contain the tmp values */ + Word32 *bufferL /* o : 1D array of length numSpk that will contain the tmp values q31*/ ) { Word16 i; @@ -2622,10 +2631,14 @@ static void efap_panning_fx( Word32 normTmpBuff; Word32 P[2]; - P[0] = azi; + P[0] = azi; // q22 move32(); - P[1] = ele; + P[1] = ele; // q22 move32(); + set32_fx( tmpBuff, 0, EFAP_MAX_CHAN_NUM ); + set32_fx( aziPoly, 0, EFAP_MAX_CHAN_NUM ); + set32_fx( elePoly, 0, EFAP_MAX_CHAN_NUM ); + set16_fx( chan, 0, EFAP_MAX_CHAN_NUM ); /* Finding in which polygon the point is */ polyIdx = get_poly_num_fx( P, polyData ); @@ -2640,32 +2653,32 @@ static void efap_panning_fx( { chan[i] = polyData->polysetArray[polyIdx].chan[i]; move16(); - aziPoly[i] = polyData->polysetArray[polyIdx].polyAzi[i]; + aziPoly[i] = polyData->polysetArray[polyIdx].polyAzi[i]; // q22 move32(); if ( EQ_16( polyData->polysetArray[polyIdx].isNaN[i], 1 ) ) { - aziPoly[i] = P[0]; + aziPoly[i] = P[0]; // q22 move32(); } - elePoly[i] = polyData->polysetArray[polyIdx].polyEle[i]; + elePoly[i] = polyData->polysetArray[polyIdx].polyEle[i]; // q22 move32(); } /* Computing the gain for the polygon */ - get_poly_gains_fx( P[0], P[1], aziPoly, elePoly, numChan, tmpBuff ); + get_poly_gains_fx( P[0], P[1], aziPoly, elePoly, numChan, tmpBuff ); // tmpBuff q31 /* Computing the norm of the tmp buffer */ - normTmpBuff = dotp_fixed( tmpBuff, tmpBuff, numChan ); + normTmpBuff = dotp_fixed( tmpBuff, tmpBuff, numChan ); // q31 Word16 exp = 0; move16(); - normTmpBuff = ISqrt32( normTmpBuff, &exp ); + normTmpBuff = ISqrt32( normTmpBuff, &exp ); // Q=31-exp /* Updating the buffer structure */ FOR( i = 0; i < numChan; ++i ) { - bufferL[chan[i]] = Mpy_32_32( tmpBuff[i], normTmpBuff ); + bufferL[chan[i]] = Mpy_32_32( tmpBuff[i], normTmpBuff ); // 31+(31-exp)-31=>31-exp move32(); bufferL[chan[i]] = L_shl( bufferL[chan[i]], exp ); // Q31 move32(); @@ -2738,12 +2751,12 @@ static void get_poly_gains( *-------------------------------------------------------------------------*/ static void get_poly_gains_fx( - const Word32 azi, /* i : Value of the azimuth */ - const Word32 ele, /* i : Value of the elevation */ - const Word32 aziPoly[EFAP_MAX_CHAN_NUM], /* i : Azimuths of the considered polygons */ - const Word32 elePoly[EFAP_MAX_CHAN_NUM], /* i : Elevations of the considered polygons */ + const Word32 azi, /* i : Value of the azimuth q22 */ + const Word32 ele, /* i : Value of the elevation q22 */ + const Word32 aziPoly[EFAP_MAX_CHAN_NUM], /* i : Azimuths of the considered polygons q22 */ + const Word32 elePoly[EFAP_MAX_CHAN_NUM], /* i : Elevations of the considered polygons q22 */ const Word16 numChan, /* i : Length of aziPoly & elePoly */ - Word32 *buffer /* o : 1D array of length numSpk that will contain the tmp values */ + Word32 *buffer /* o : 1D array of length numSpk that will contain the tmp values q31*/ ) { Word16 i, j; @@ -2752,39 +2765,39 @@ static void get_poly_gains_fx( Word32 A[2], B[2], C[2]; Word32 P_minus_A[2]; - P[0] = azi; + P[0] = azi; // q22 move32(); - P[1] = ele; + P[1] = ele; // q22 move32(); /* Processing, we search for the triangle in which belong P, then we compute the gain */ FOR( i = 1; i < numChan + 1; ++i ) { - A[0] = aziPoly[i - 1]; + A[0] = aziPoly[i - 1]; // q22 move32(); - A[1] = elePoly[i - 1]; + A[1] = elePoly[i - 1]; // q22 move32(); - v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) */ + v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) q22*/ FOR( j = i; j < numChan - 2 + i; ++j ) { idx1 = add( 1, ( j % numChan ) ); idx2 = add( 1, ( idx1 % numChan ) ); - B[0] = aziPoly[sub( idx1, 1 )]; + B[0] = aziPoly[idx1 - 1]; // q22 move32(); - B[1] = elePoly[sub( idx1, 1 )]; + B[1] = elePoly[idx1 - 1]; // q22 move32(); - C[0] = aziPoly[sub( idx2, 1 )]; + C[0] = aziPoly[idx2 - 1]; // q22 move32(); - C[1] = elePoly[sub( idx2, 1 )]; + C[1] = elePoly[idx2 - 1]; // q22 move32(); IF( in_tri_fx( A, B, C, P_minus_A ) ) { - buffer[i - 1] = L_shl_sat( get_tri_gain_fx( A, B, C, P_minus_A ), Q12 ); + buffer[i - 1] = L_shl_sat( get_tri_gain_fx( A, B, C, P_minus_A ), Q18 ); // q13+q18->q31 move32(); BREAK; } @@ -2843,10 +2856,10 @@ static float get_tri_gain( *-------------------------------------------------------------------------*/ static Word32 get_tri_gain_fx( - const Word32 A[2], /* i : Coordinate of one apex of the triangle */ - const Word32 B[2], /* i : Coordinate of one apex of the triangle */ - const Word32 C[2], /* i : Coordinate of one apex of the triangle */ - const Word32 P_minus_A[2] /* i : Value of (P - A) */ + const Word32 A[2], /* i : Coordinate of one apex of the triangle q22*/ + const Word32 B[2], /* i : Coordinate of one apex of the triangle q22*/ + const Word32 C[2], /* i : Coordinate of one apex of the triangle q22*/ + const Word32 P_minus_A[2] /* i : Value of (P - A) q22 */ ) { Word32 N[2], tmpN[2]; @@ -2855,32 +2868,38 @@ static Word32 get_tri_gain_fx( Word32 gain; /* Processing */ - tmpN[0] = L_sub( B[1], C[1] ); + tmpN[0] = L_sub( B[1], C[1] ); // q22 move32(); - tmpN[1] = L_sub( C[0], B[0] ); + tmpN[1] = L_sub( C[0], B[0] ); // q22 move32(); - v_sub_fixed( B, A, tmpSub1, 2, 0 ); + v_sub_fixed( B, A, tmpSub1, 2, 0 ); // tmpSub1 q22 tmpDot1 = dotp_fixed( tmpN, tmpSub1, 2 ); // Q13 - Word16 exp = Q13; + Word16 exp = Q18; move16(); Word32 inv_tmpDot2 = L_shl( tmpDot1, norm_l( tmpDot1 ) ); exp = sub( exp, norm_l( tmpDot1 ) ); - Word16 inv_tmpDot1 = Inv16( (Word16) L_shr( inv_tmpDot2, Q16 ), &exp ); - v_multc_fixed( tmpN, L_shl( inv_tmpDot1, add( Q16, exp ) ), N, 2 ); + Word16 inv_tmpDot1 = Inv16( extract_h( inv_tmpDot2 ), &exp ); // 15-exp + v_multc_fixed( tmpN, L_shl( inv_tmpDot1, add( Q16, exp ) ), N, 2 ); // 22+31-31->22 - tmpDot2 = dotp_fixed( P_minus_A, N, 2 ); // Q18 + tmpDot2 = dotp_fixed( P_minus_A, N, 2 ); // 22+22-31->13 - gain = L_sub( 0x00040000, tmpDot2 ); + if ( EQ_32( tmpDot2, 8191 ) ) + { + tmpDot2 = 8192; // Q13 + move32(); + } + + gain = L_sub( 8192, tmpDot2 ); // Q13 /* Set gains <= -60dB to 0 to avoid problems in SVD */ - if ( LT_32( L_abs( gain ), 1 ) ) + if ( EQ_16( BASOP_Util_Cmp_Mant32Exp( L_abs( gain ), 18, 2147 /*1e-6 q31*/, 0 ), -1 ) ) { gain = 0; move32(); } - return gain; // Q18 + return gain; // Q13 } #endif @@ -2960,32 +2979,39 @@ static void add_vertex_fx( /* Updating the vertex array */ - tmp = efap_32mod32( L_sub( Q22_180_DEG, azi ), Q22_360_DEG ); - vtxArray[pos].azi = L_sub( Q22_180_DEG, tmp ); + tmp = efap_32mod32( L_sub( Q22_180_DEG /*180 q22*/, azi ), Q22_360_DEG /*360 q22*/ ); // q22 + vtxArray[pos].azi = L_sub( Q22_180_DEG /*180 q22*/, tmp ); // q22 move32(); - tmp = ( LT_32( Q22_180_DEG, ele ) ? Q22_180_DEG : ele ); + IF( LT_32( Q22_180_DEG /*180 q22*/, ele ) ) + tmp = Q22_180_DEG /*180 q22*/; + ELSE + tmp = ele; // Q22 move32(); - vtxArray[pos].ele = ( GT_32( -Q22_180_DEG, tmp ) ? -Q22_180_DEG : tmp ); + IF( GT_32( -Q22_180_DEG /*180 q22*/, tmp ) ) + vtxArray[pos].ele = -Q22_180_DEG /*180 q22*/; + ELSE + vtxArray[pos] + .ele = tmp; // q22 move32(); /* Converting spherical coordinates to cartesians, assuming radius = 1 */ - sph2cart_fx( vtxArray[pos].azi, vtxArray[pos].ele, &vtxArray[pos].pos[0] ); + sph2cart_fx( vtxArray[pos].azi, vtxArray[pos].ele, &vtxArray[pos].pos[0] ); // vtxArray[pos].pos[0] q31 /* Computing the index defined by idx = idxAziTmp + 181 * idxEleTmp */ /* IdxAziTmp */ - tmp = L_abs( L_sub( Q22_90_DEG, L_abs( vtxArray[pos].azi ) ) ); // Q22 - idxAziTmp = L_shr( anint_fixed( tmp, Q22 ), Q22 ); + tmp = L_abs( L_sub( Q22_90_DEG /*90 q22*/, L_abs( vtxArray[pos].azi ) ) ); // Q22 + idxAziTmp = L_shr( anint_fixed( tmp, Q22 ), Q22 ); // q22-q22->q0 /* IdxEleTmp */ - tmp = L_abs( vtxArray[pos].ele ); - idxEleTmp = tmp; + tmp = L_abs( vtxArray[pos].ele ); // q22 + idxEleTmp = tmp; // q22 move16(); - idxEleTmp = L_sub( Q22_90_DEG, idxEleTmp ); + idxEleTmp = L_sub( Q22_90_DEG /*90 q22*/, idxEleTmp ); // q22 /* Final Idx */ - vtxArray[pos].idx = add( extract_l( idxAziTmp ), i_mult( 181, extract_l( L_shr( idxEleTmp, Q22 ) ) ) ); + vtxArray[pos].idx = add( extract_l( idxAziTmp ), i_mult( 181, extract_l( L_shr( idxEleTmp, Q22 ) ) ) ); // q0 /* Setting the nan flag to 0 */ vtxArray[pos].isNaN = 0; @@ -3029,8 +3055,10 @@ static void efap_sort_s_fx( move16(); tempi = idx[i]; move16(); + test(); FOR( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ ) { + test(); x[j - 1] = x[j]; move16(); idx[j - 1] = idx[j]; @@ -3118,18 +3146,18 @@ static Word32 vertex_distance_fx( /* Assigning the coordinates to the vector */ FOR( i = 0; i < 3; ++i ) { - A[i] = vtxArray[tri.LS[0]].pos[i]; + A[i] = vtxArray[tri.LS[0]].pos[i]; // q31 move32(); - B[i] = vtxArray[tri.LS[1]].pos[i]; + B[i] = vtxArray[tri.LS[1]].pos[i]; // q31 move32(); - C[i] = vtxArray[tri.LS[2]].pos[i]; + C[i] = vtxArray[tri.LS[2]].pos[i]; // q31 move32(); - P[i] = vtxArray[vtxIdx].pos[i]; + P[i] = vtxArray[vtxIdx].pos[i]; // q31 move32(); } - return point_plane_distance_fx( A, B, C, P ); + return point_plane_distance_fx( A, B, C, P ); // q28 } #endif @@ -3162,16 +3190,16 @@ static float point_poly_distance( static Word32 point_poly_distance_fx( const EFAP_POLYSET poly, /* i : The polygon which forms a plane */ - const Word32 X[3] /* i : Cartesian coordinates of the point of interest */ + const Word32 X[3] /* i : Cartesian coordinates of the point of interest q31*/ ) { Word32 P1[3], P2[3], P3[3]; - sph2cart_fx( poly.polyAzi[0], poly.polyEle[0], &P1[0] ); - sph2cart_fx( poly.polyAzi[1], poly.polyEle[1], &P2[0] ); - sph2cart_fx( poly.polyAzi[2], poly.polyEle[2], &P3[0] ); + sph2cart_fx( poly.polyAzi[0], poly.polyEle[0], &P1[0] ); // P1[0] q31 + sph2cart_fx( poly.polyAzi[1], poly.polyEle[1], &P2[0] ); // P2[0] q31 + sph2cart_fx( poly.polyAzi[2], poly.polyEle[2], &P3[0] ); // P3[0] q31 - return point_plane_distance_fx( P1, P2, P3, X ); + return point_plane_distance_fx( P1, P2, P3, X ); // q28 } #endif @@ -3228,10 +3256,10 @@ static float point_plane_distance( *-------------------------------------------------------------------------*/ static Word32 point_plane_distance_fx( // returns output in Q28 - const Word32 P1[3], /* i : First point of the triangle that defines the planes */ - const Word32 P2[3], /* i : Second point of the triangle */ - const Word32 P3[3], /* i : Third point of the triangle */ - const Word32 X[3] /* i : The point of interest */ + const Word32 P1[3], /* i : First point of the triangle that defines the planes q31*/ + const Word32 P2[3], /* i : Second point of the triangle q31*/ + const Word32 P3[3], /* i : Third point of the triangle q31*/ + const Word32 X[3] /* i : The point of interest q31*/ ) { Word32 tmpCross1[3], tmpCross2[3]; @@ -3257,8 +3285,8 @@ static Word32 point_plane_distance_fx( // returns output in Q28 } /* Cross Product */ - v_sub_fixed( P1, P2, tmpCross1, 3, 1 ); - v_sub_fixed( P1, P3, tmpCross2, 3, 1 ); + v_sub_fixed( P1, P2, tmpCross1, 3, 1 ); // tmpCross1 q30 + v_sub_fixed( P1, P3, tmpCross2, 3, 1 ); // tmpCross2 q30 /* resultCross = cross(P1-P2,P1-P3) */ efap_crossp_fx( tmpCross1, tmpCross2, resultCross ); // Q29 @@ -3612,10 +3640,10 @@ static void matrix_times_row( *-------------------------------------------------------------------------*/ static void matrix_times_row_fx( - Word32 mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF], /* i : The input matrix */ - const Word32 *vec, /* i : The input row vector */ + Word32 mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF], /* i : The input matrix q31 */ + const Word32 *vec, /* i : The input row vector q31*/ const Word16 L, /* i : Row length */ - Word32 *out /* o : Output vector */ + Word32 *out /* o : Output vector q31 */ ) { Word16 i, j; @@ -3624,7 +3652,7 @@ static void matrix_times_row_fx( { FOR( j = 0; j < L; ++j ) { - out[i] = L_add( out[i], Mpy_32_32( mat[i][j], vec[j] ) ); + out[i] = L_add( out[i], Mpy_32_32( mat[i][j], vec[j] ) ); /*31+31-31=>31*/ move32(); } } @@ -3680,7 +3708,7 @@ static void tri_to_poly_fx( vtxArray[triArray[i].LS[2]].pos, vtxArray[j].pos ) ); // Q28 - IF( LT_32( dist, 268435 ) /* 1e-3f in Q28 */ ) + IF( LT_32( dist, 268435 /* 1e-3f in Q28 */ ) ) { assert( lenPoly < EFAP_MAX_CHAN_NUM && "EFAP: exceeded max polygon vertices!" ); poly[lenPoly] = j; @@ -4064,7 +4092,7 @@ static void sort_channels_vertex_fx( v_sub_fixed( P2, P1, tmpU, 3, 1 ); // tmpU Q30 Word16 exp1 = 2; move16(); - normU = ISqrt32( dotp_fixed( tmpU, tmpU, 3 ), &exp1 ); + normU = ISqrt32( dotp_fixed( tmpU, tmpU, 3 ) /*q29*/, &exp1 ); /*q=31-exp1*/ // normU = L_shl_sat( normU, exp ); //normU Q31 v_multc_fixed( tmpU, normU, U, 3 ); // U Q30 - exp1 @@ -4074,21 +4102,21 @@ static void sort_channels_vertex_fx( FOR( i = 0; i < 3; i++ ) { - tmpV2[i] = L_shl( tmpV2[i], add( Q2, shl( exp1, 1 ) ) ); + tmpV2[i] = L_shl( tmpV2[i], add( Q2, shl( exp1, 1 ) ) ); // q30 move32(); } v_sub_fixed( tmpV1, tmpV2, tmpV3, 3, 0 ); // tmpV3 Q30 Word16 exp2 = 2; move16(); - normV = ISqrt32( dotp_fixed( tmpV3, tmpV3, 3 ), &exp2 ); + normV = ISqrt32( dotp_fixed( tmpV3, tmpV3, 3 ) /*q29*/, &exp2 ); // q=31-exp2 v_multc_fixed( tmpV3, normV, V, 3 ); // V Q30 - exp2 /* Center of the first Triangle */ FOR( i = 0; i < 3; ++i ) { - MC[i] = L_shl( Mpy_32_32( L_add( L_add( L_shr( P1[i], Q2 ), L_shr( P2[i], Q2 ) ), L_shr( P3[i], Q2 ) ), 715827883 /* 1 / 3 in Q31 */ ), Q2 ); + MC[i] = L_shl( Mpy_32_32( L_add( L_add( L_shr( P1[i], Q2 ), L_shr( P2[i], Q2 ) ), L_shr( P3[i], Q2 ) ), 715827883 /* 1 / 3 in Q31 */ ), Q2 ); // q29+2=>q31 move32(); } @@ -4097,7 +4125,7 @@ static void sort_channels_vertex_fx( { FOR( j = 0; j < 3; ++j ) { - tmpP[j] = vtxArray[channels[i]].pos[j]; + tmpP[j] = vtxArray[channels[i]].pos[j]; // q31 move32(); } @@ -4152,19 +4180,19 @@ static float efap_fmodf( *-------------------------------------------------------------------------*/ static Word32 efap_32mod32( - const Word32 x, /* i : Dividend */ - const Word32 y /* i : Divisor */ + const Word32 x, /* i : Dividend q22*/ + const Word32 y /* i : Divisor q22 */ ) { - Word32 result = x % y; + Word32 result = x % y; // q22 move32(); IF( result >= 0 ) { - return result; + return result; // q22 } ELSE { - return L_add( result, y ); + return L_add( result, y ); // q22 } } #endif @@ -4234,7 +4262,7 @@ static int16_t get_poly_num( } #else static Word16 get_poly_num_fx( - const Word32 P[2], /* i : Azimuth and elevation of the point */ + const Word32 P[2], /* i : Azimuth and elevation of the point q22*/ const EFAP_POLYSET_DATA *polyData /* i : Polyset struct */ ) { @@ -4249,7 +4277,7 @@ static Word16 get_poly_num_fx( num_poly = 0; move16(); - sph2cart_fx( P[0], P[1], &pos[0] ); + sph2cart_fx( P[0], P[1], &pos[0] ); // pos[0] q31 /* Filter the polygon list with a fast 2d check */ FOR( i = 0; i < polyData->numPoly; ++i ) @@ -4257,7 +4285,7 @@ static Word16 get_poly_num_fx( IF( in_poly_fx( P, polyData->polysetArray[i] ) ) { /* select only polygons which are visible from the point */ - dist_tmp = point_poly_distance_fx( polyData->polysetArray[i], pos ); + dist_tmp = point_poly_distance_fx( polyData->polysetArray[i], pos ); // q28 IF( dist_tmp == 0 ) { return i; @@ -4266,7 +4294,7 @@ static Word16 get_poly_num_fx( { poly_tmp[num_poly] = i; move16(); - poly_dist[num_poly] = dist_tmp; + poly_dist[num_poly] = dist_tmp; // q28 move32(); num_poly = add( num_poly, 1 ); } @@ -4280,7 +4308,7 @@ static Word16 get_poly_num_fx( /* select the polygon with the smallest distance */ found_poly = poly_tmp[0]; move16(); - dist_tmp = poly_dist[0]; + dist_tmp = poly_dist[0]; // q28 move32(); FOR( i = 1; i < num_poly; i++ ) { @@ -4288,7 +4316,7 @@ static Word16 get_poly_num_fx( { found_poly = poly_tmp[i]; move16(); - dist_tmp = poly_dist[i]; + dist_tmp = poly_dist[i]; // q28 move32(); } } @@ -4370,7 +4398,7 @@ static int16_t in_poly( } #else static Word16 in_poly_fx( /* Angles are in Q22 */ - const Word32 P[2], /* i : Azimuth and elevation of the point */ + const Word32 P[2], /* i : Azimuth and elevation of the point q22*/ const EFAP_POLYSET poly /* i : Polyset struct */ ) { @@ -4393,45 +4421,45 @@ static Word16 in_poly_fx( /* Angles are in Q22 */ IF( poly.isNaN[0] ) { - A[0] = P[0]; + A[0] = P[0]; // q22 move32(); } ELSE { - A[0] = poly.polyAzi[0]; + A[0] = poly.polyAzi[0]; // q22 move32(); } - A[1] = poly.polyEle[0]; + A[1] = poly.polyEle[0]; // q22 move32(); - v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) */ + v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) q22*/ FOR( n = 1; n < sub( numVertices, 1 ); ++n ) { IF( poly.isNaN[n] ) { - B[0] = P[0]; + B[0] = P[0]; // q22 move32(); } ELSE { - B[0] = poly.polyAzi[n]; + B[0] = poly.polyAzi[n]; // q22 move32(); } - B[1] = poly.polyEle[n]; + B[1] = poly.polyEle[n]; // q22 move32(); IF( poly.isNaN[n + 1] ) { - C[0] = P[0]; + C[0] = P[0]; // q22 move32(); } ELSE { - C[0] = poly.polyAzi[n + 1]; + C[0] = poly.polyAzi[n + 1]; // q22 move32(); } - C[1] = poly.polyEle[n + 1]; + C[1] = poly.polyEle[n + 1]; // q22 move32(); IF( in_tri_fx( A, B, C, P_minus_A ) ) @@ -4505,10 +4533,10 @@ static int16_t in_tri( } #else static Word16 in_tri_fx( - Word32 A[2], /* i : Coordinate of one apex of the triangle */ - Word32 B[2], /* i : Coordinate of one apex of the triangle */ - Word32 C[2], /* i : Coordinate of one apex of the triangle */ - Word32 P_minus_A[2] /* i : Value of (P - A) */ + Word32 A[2], /* i : Coordinate of one apex of the triangle q22*/ + Word32 B[2], /* i : Coordinate of one apex of the triangle q22*/ + Word32 C[2], /* i : Coordinate of one apex of the triangle q22*/ + Word32 P_minus_A[2] /* i : Value of (P - A) q22*/ ) { Word32 tmpDot1[2], tmpDot2[2]; @@ -4517,7 +4545,7 @@ static Word16 in_tri_fx( Word16 tmp16, tmp_e; Word64 S[2]; /* Threshold adjusted */ - Word64 thresh_int = 21475; // 1e-6f in Q32 + Word64 thresh_int = 4295; // 1e-6f in Q32 move64(); /* @@ -4527,11 +4555,11 @@ static Word16 in_tri_fx( I'll just compute the determinant and if it's equal to 0, that means the two vectors are colinear */ - v_sub_fixed( B, A, tmpDot1, 2, 0 ); - v_sub_fixed( C, A, tmpDot2, 2, 0 ); + v_sub_fixed( B, A, tmpDot1, 2, 0 ); // tmpDot1 q22 + v_sub_fixed( C, A, tmpDot2, 2, 0 ); // tmpDot 2q22 /* Verification of the non-colinearity : Q22 * Q22 = Q13 */ - invFactor = L_sub( Mpy_32_32( tmpDot1[0], tmpDot2[1] ), Mpy_32_32( tmpDot1[1], tmpDot2[0] ) ); + invFactor = L_sub( Mpy_32_32( tmpDot1[0], tmpDot2[1] ), Mpy_32_32( tmpDot1[1], tmpDot2[0] ) ); /*q22+q22-q31->q13*/ IF( invFactor == 0 ) { @@ -4539,20 +4567,20 @@ static Word16 in_tri_fx( } /* invFactor = 1.f / invFactor; */ - tmp16 = BASOP_Util_Divide3232_Scale( ONE_IN_Q13, invFactor, &tmp_e ); - invFactor = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ + tmp16 = BASOP_Util_Divide3232_Scale( ONE_IN_Q13, invFactor, &tmp_e ); /*15-tmp_e*/ + invFactor = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ Word16 invFactor_exp = norm_l( invFactor ); - invFactor = L_shl( invFactor, invFactor_exp ); + invFactor = L_shl( invFactor, invFactor_exp ); // 31+invFactor_exp // Q22 = Q22 * Q31 - matInv[0][0] = Mpy_32_32( tmpDot2[1], invFactor ); + matInv[0][0] = Mpy_32_32( tmpDot2[1], invFactor ); // q=22+invFactor_exp move32(); - matInv[0][1] = Mpy_32_32( L_negate( tmpDot2[0] ), invFactor ); + matInv[0][1] = Mpy_32_32( L_negate( tmpDot2[0] ), invFactor ); // q=22+invFactor_exp move32(); - matInv[1][0] = Mpy_32_32( L_negate( tmpDot1[1] ), invFactor ); + matInv[1][0] = Mpy_32_32( L_negate( tmpDot1[1] ), invFactor ); // q=22+invFactor_exp move32(); - matInv[1][1] = Mpy_32_32( tmpDot1[0], invFactor ); + matInv[1][1] = Mpy_32_32( tmpDot1[0], invFactor ); // q=22+invFactor_exp move32(); /* Computing S (Q13 + matInv_exp_final[i] + P_minus_A_exp_final + invFactor_exp - 1 ) = @@ -4584,35 +4612,37 @@ static Word16 in_tri_fx( P_minus_A_exp_final = s_min( P_minus_A_exp[0], P_minus_A_exp[1] ); S[0] = L_add( L_shr( Mpy_32_32( L_shl( matInv[0][0], matInv_exp_final[0] ), L_shl( P_minus_A[0], P_minus_A_exp_final ) ), Q1 ), - L_shr( Mpy_32_32( L_shl( matInv[0][1], matInv_exp_final[0] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); + L_shr( Mpy_32_32( L_shl( matInv[0][1], matInv_exp_final[0] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); //(22+invFactor_exp+matInv_exp_final[0]+22+P_minus_A_exp_final-1)-31=>12+invFactor_exp+matInv_exp_final[0]+P_minus_A_exp_final move64(); S[1] = L_add( L_shr( Mpy_32_32( L_shl( matInv[1][0], matInv_exp_final[1] ), L_shl( P_minus_A[0], P_minus_A_exp_final ) ), Q1 ), - L_shr( Mpy_32_32( L_shl( matInv[1][1], matInv_exp_final[1] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); + L_shr( Mpy_32_32( L_shl( matInv[1][1], matInv_exp_final[1] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); //(22+invFactor_exp+matInv_exp_final[1]+22+P_minus_A_exp_final-1)-31=>12+invFactor_exp+matInv_exp_final[0]+P_minus_A_exp_final move64(); /* Checking if we are in the triangle; For the theory, check Christian Borss article, section 3.2 */ // Q32 S IF( sub( sub( sub( Q20, matInv_exp_final[0] ), P_minus_A_exp_final ), invFactor_exp ) < 0 ) { - S[0] = W_shr( S[0], sub( add( add( matInv_exp_final[0], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); + S[0] = W_shr( S[0], sub( add( add( matInv_exp_final[0], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); // q32 move64(); } ELSE { - S[0] = W_shl( S[0], sub( sub( sub( Q20, matInv_exp_final[0] ), P_minus_A_exp_final ), invFactor_exp ) ); + S[0] = W_shl( S[0], sub( sub( sub( Q20, matInv_exp_final[0] ), P_minus_A_exp_final ), invFactor_exp ) ); // q32 move64(); } IF( sub( sub( sub( Q20, matInv_exp_final[1] ), P_minus_A_exp_final ), invFactor_exp ) < 0 ) { - S[1] = W_shr( S[1], sub( add( add( matInv_exp_final[1], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); + S[1] = W_shr( S[1], sub( add( add( matInv_exp_final[1], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); // q32 move64(); } ELSE { - S[1] = W_shl( S[1], sub( sub( sub( Q20, matInv_exp_final[1] ), P_minus_A_exp_final ), invFactor_exp ) ); + S[1] = W_shl( S[1], sub( sub( sub( Q20, matInv_exp_final[1] ), P_minus_A_exp_final ), invFactor_exp ) ); // q32 move64(); } + test(); + test(); IF( LT_64( S[0], -thresh_int ) || LT_64( S[1], -thresh_int ) || GT_64( W_add( S[0], S[1] ), W_add( W_shl( 1, 32 ), thresh_int ) ) ) { return 0; diff --git a/lib_rend/ivas_limiter.c b/lib_rend/ivas_limiter.c index 458dd5a08956f3a5aff763ef56c49bb23137dc22..199c14564b07fe9656f3a4d34b7f2436f6113984 100644 --- a/lib_rend/ivas_limiter.c +++ b/lib_rend/ivas_limiter.c @@ -35,6 +35,7 @@ #include #include "prot.h" #include "ivas_prot_rend.h" +#include "ivas_rom_rend.h" #include "wmc_auto.h" #include #ifdef IVAS_FLOAT_FIXED @@ -49,823 +50,6 @@ #define ATTACK_CNST_8k ( 1913946752 ) // Q31 #endif -Word32 release_cnst_table[4][201] = // Q31 - { - { - 1913946752, - 1919716352, - 1925351680, - 1930855552, - 1936230784, - 1941479808, - 1946605312, - 1951609728, - 1956495744, - 1961265792, - 1965922304, - 1970467584, - 1974904320, - 1979234560, - 1983460736, - 1987585024, - 1991609856, - 1995537280, - 1999369344, - 2003108480, - 2006756480, - 2010315520, - 2013787520, - 2017174528, - 2020478464, - 2023701248, - 2026844672, - 2029910656, - 2032900992, - 2035817344, - 2038661376, - 2041435008, - 2044139648, - 2046777088, - 2049348864, - 2051856384, - 2054301440, - 2056685312, - 2059009536, - 2061275520, - 2063484672, - 2065638272, - 2067737856, - 2069784448, - 2071779584, - 2073724416, - 2075620096, - 2077467904, - 2079268992, - 2081024512, - 2082735488, - 2084403200, - 2086028416, - 2087612544, - 2089156352, - 2090660864, - 2092127104, - 2093555968, - 2094948480, - 2096305408, - 2097627776, - 2098916352, - 2100172032, - 2101395584, - 2102587776, - 2103749504, - 2104881408, - 2105984384, - 2107059072, - 2108106112, - 2109126400, - 2110120448, - 2111088896, - 2112032512, - 2112951808, - 2113847552, - 2114720128, - 2115570304, - 2116398592, - 2117205504, - 2117991552, - 2118757504, - 2119503616, - 2120230400, - 2120938496, - 2121628288, - 2122300288, - 2122954880, - 2123592576, - 2124213760, - 2124818944, - 2125408384, - 2125982592, - 2126541952, - 2127086848, - 2127617664, - 2128134656, - 2128638336, - 2129128832, - 2129606784, - 2130072192, - 2130525568, - 2130967296, - 2131397376, - 2131816448, - 2132224640, - 2132622080, - 2133009408, - 2133386496, - 2133753856, - 2134111744, - 2134460288, - 2134799744, - 2135130368, - 2135452416, - 2135766144, - 2136071680, - 2136369152, - 2136659072, - 2136941312, - 2137216256, - 2137484160, - 2137744896, - 2137998976, - 2138246400, - 2138487424, - 2138722176, - 2138950656, - 2139173376, - 2139390208, - 2139601408, - 2139807104, - 2140007424, - 2140202624, - 2140392576, - 2140577664, - 2140758016, - 2140933504, - 2141104512, - 2141271040, - 2141433216, - 2141591168, - 2141745024, - 2141894912, - 2142040832, - 2142182912, - 2142321408, - 2142456192, - 2142587392, - 2142715264, - 2142839808, - 2142961152, - 2143079296, - 2143194240, - 2143306240, - 2143415424, - 2143521664, - 2143625216, - 2143725952, - 2143824128, - 2143919744, - 2144012800, - 2144103424, - 2144191744, - 2144277760, - 2144361472, - 2144443136, - 2144522496, - 2144599936, - 2144675200, - 2144748544, - 2144820096, - 2144889600, - 2144957440, - 2145023488, - 2145087744, - 2145150336, - 2145211264, - 2145270656, - 2145328512, - 2145384832, - 2145439616, - 2145493120, - 2145545088, - 2145595776, - 2145645056, - 2145693184, - 2145739904, - 2145785472, - 2145829888, - 2145873152, - 2145915136, - 2145956224, - 2145996032, - 2146034944, - 2146072832, - 2146109696, - 2146145664, - 2146180608, - 2146214656, - 2146247808, - }, - { - 2027355264, - 2030408704, - 2033386624, - 2036290944, - 2039123328, - 2041885440, - 2044578944, - 2047205376, - 2049766528, - 2052263680, - 2054698496, - 2057072384, - 2059387008, - 2061643520, - 2063843328, - 2065987968, - 2068078720, - 2070116864, - 2072103552, - 2074040192, - 2075927936, - 2077767936, - 2079561472, - 2081309568, - 2083013376, - 2084673920, - 2086292352, - 2087869696, - 2089406976, - 2090905216, - 2092365184, - 2093788032, - 2095174528, - 2096525824, - 2097842432, - 2099125632, - 2100375808, - 2101594240, - 2102781312, - 2103938048, - 2105065216, - 2106163456, - 2107233536, - 2108276096, - 2109292032, - 2110281728, - 2111246080, - 2112185728, - 2113101056, - 2113992960, - 2114861824, - 2115708288, - 2116532992, - 2117336448, - 2118119168, - 2118881792, - 2119624704, - 2120348416, - 2121053440, - 2121740288, - 2122409344, - 2123061120, - 2123696128, - 2124314624, - 2124917120, - 2125504128, - 2126075776, - 2126632832, - 2127175296, - 2127703808, - 2128218624, - 2128720000, - 2129208448, - 2129684352, - 2130147712, - 2130599168, - 2131038976, - 2131467264, - 2131884416, - 2132290816, - 2132686592, - 2133072256, - 2133447680, - 2133813504, - 2134169856, - 2134516864, - 2134854784, - 2135184000, - 2135504640, - 2135816960, - 2136121216, - 2136417536, - 2136706048, - 2136987136, - 2137260928, - 2137527552, - 2137787264, - 2138040192, - 2138286592, - 2138526464, - 2138760192, - 2138987776, - 2139209472, - 2139425408, - 2139635712, - 2139840512, - 2140039936, - 2140234240, - 2140423424, - 2140607744, - 2140787200, - 2140962048, - 2141132288, - 2141298048, - 2141459584, - 2141616896, - 2141769984, - 2141919232, - 2142064512, - 2142205952, - 2142343808, - 2142478080, - 2142608768, - 2142736128, - 2142860032, - 2142980864, - 2143098368, - 2143212928, - 2143324544, - 2143433088, - 2143538944, - 2143641984, - 2143742336, - 2143840000, - 2143935232, - 2144027904, - 2144118144, - 2144206080, - 2144291712, - 2144375168, - 2144456320, - 2144535424, - 2144612480, - 2144687488, - 2144760448, - 2144831616, - 2144900992, - 2144968448, - 2145034112, - 2145098112, - 2145160448, - 2145221248, - 2145280256, - 2145337856, - 2145393920, - 2145448576, - 2145501696, - 2145553536, - 2145603968, - 2145653120, - 2145700992, - 2145747456, - 2145792896, - 2145837056, - 2145880064, - 2145922048, - 2145962880, - 2146002560, - 2146041344, - 2146078976, - 2146115712, - 2146151424, - 2146186240, - 2146220160, - 2146253184, - 2146285312, - 2146316672, - 2146347136, - 2146376832, - 2146405760, - 2146433920, - 2146461440, - 2146488192, - 2146514176, - 2146539520, - 2146564224, - 2146588160, - 2146611584, - 2146634368, - 2146656640, - 2146678272, - 2146699264, - 2146719744, - 2146739712, - 2146759168, - 2146778112, - 2146796544, - 2146814464, - 2146832000, - 2146849024, - 2146865664, - }, - { - 2086555136, - 2088125824, - 2089656576, - 2091148416, - 2092602240, - 2094018944, - 2095399680, - 2096745088, - 2098056192, - 2099333888, - 2100578816, - 2101792000, - 2102974080, - 2104125824, - 2105248128, - 2106341760, - 2107407232, - 2108445440, - 2109456896, - 2110442496, - 2111402624, - 2112338176, - 2113249664, - 2114137728, - 2115002880, - 2115845760, - 2116666880, - 2117466880, - 2118246272, - 2119005568, - 2119745280, - 2120465920, - 2121167872, - 2121851776, - 2122517888, - 2123166976, - 2123799168, - 2124414976, - 2125014912, - 2125599360, - 2126168704, - 2126723200, - 2127263360, - 2127789568, - 2128302208, - 2128801408, - 2129287808, - 2129761536, - 2130222976, - 2130672512, - 2131110272, - 2131536768, - 2131952128, - 2132356736, - 2132750848, - 2133134720, - 2133508736, - 2133872896, - 2134227584, - 2134573184, - 2134909696, - 2135237504, - 2135556736, - 2135867648, - 2136170624, - 2136465536, - 2136752896, - 2137032832, - 2137305344, - 2137570816, - 2137829376, - 2138081280, - 2138326528, - 2138565504, - 2138798080, - 2139024768, - 2139245440, - 2139460480, - 2139669888, - 2139873792, - 2140072320, - 2140265856, - 2140454144, - 2140637696, - 2140816384, - 2140990464, - 2141159936, - 2141325056, - 2141485824, - 2141642368, - 2141794944, - 2141943424, - 2142088064, - 2142228992, - 2142366208, - 2142499840, - 2142630016, - 2142756736, - 2142880128, - 2143000448, - 2143117440, - 2143231488, - 2143342592, - 2143450752, - 2143556096, - 2143658624, - 2143758592, - 2143855872, - 2143950592, - 2144043008, - 2144132864, - 2144220416, - 2144305664, - 2144388608, - 2144469504, - 2144548224, - 2144624896, - 2144699648, - 2144772352, - 2144843264, - 2144912256, - 2144979328, - 2145044864, - 2145108480, - 2145170560, - 2145231104, - 2145289856, - 2145347200, - 2145403008, - 2145457408, - 2145510400, - 2145561984, - 2145612160, - 2145661056, - 2145708672, - 2145755136, - 2145800192, - 2145844224, - 2145887104, - 2145928832, - 2145969408, - 2146008960, - 2146047616, - 2146085120, - 2146121600, - 2146157184, - 2146191872, - 2146225664, - 2146258560, - 2146290560, - 2146321792, - 2146352128, - 2146381696, - 2146410496, - 2146438528, - 2146465920, - 2146492416, - 2146518400, - 2146543616, - 2146568192, - 2146592128, - 2146615424, - 2146638080, - 2146660224, - 2146681728, - 2146702720, - 2146723072, - 2146743040, - 2146762368, - 2146781184, - 2146799616, - 2146817408, - 2146834816, - 2146851840, - 2146868352, - 2146884352, - 2146900096, - 2146915328, - 2146930176, - 2146944640, - 2146958720, - 2146972416, - 2146985856, - 2146998784, - 2147011456, - 2147023872, - 2147035904, - 2147047552, - 2147058944, - 2147070080, - 2147080832, - 2147091456, - 2147101696, - 2147111680, - 2147121408, - 2147130880, - 2147140096, - 2147149056, - 2147157760, - 2147166336, - 2147174656, - }, - { - 2106670080, - 2107727232, - 2108757120, - 2109760640, - 2110738432, - 2111691008, - 2112619136, - 2113523328, - 2114404352, - 2115262592, - 2116098816, - 2116913408, - 2117707136, - 2118480256, - 2119233536, - 2119967360, - 2120682240, - 2121378688, - 2122057088, - 2122717952, - 2123361792, - 2123988992, - 2124599936, - 2125195136, - 2125774848, - 2126339584, - 2126889728, - 2127425536, - 2127947520, - 2128456064, - 2128951296, - 2129433856, - 2129903744, - 2130361600, - 2130807424, - 2131241728, - 2131664768, - 2132076928, - 2132478208, - 2132869248, - 2133250048, - 2133620992, - 2133982208, - 2134334080, - 2134676864, - 2135010688, - 2135335936, - 2135652608, - 2135961088, - 2136261504, - 2136554112, - 2136839168, - 2137116800, - 2137387136, - 2137650560, - 2137907072, - 2138156928, - 2138400256, - 2138637184, - 2138867968, - 2139092864, - 2139311744, - 2139524992, - 2139732736, - 2139934976, - 2140131968, - 2140323840, - 2140510720, - 2140692736, - 2140870016, - 2141042688, - 2141210752, - 2141374592, - 2141534080, - 2141689344, - 2141840640, - 2141987968, - 2142131456, - 2142271232, - 2142407424, - 2142539904, - 2142669056, - 2142794752, - 2142917248, - 2143036544, - 2143152640, - 2143265792, - 2143375872, - 2143483264, - 2143587712, - 2143689472, - 2143788544, - 2143885056, - 2143979136, - 2144070656, - 2144159872, - 2144246656, - 2144331264, - 2144413568, - 2144493824, - 2144571904, - 2144647936, - 2144722048, - 2144794240, - 2144864512, - 2144932864, - 2144999552, - 2145064448, - 2145127680, - 2145189248, - 2145249152, - 2145307520, - 2145364480, - 2145419776, - 2145473792, - 2145526272, - 2145577472, - 2145627264, - 2145675776, - 2145723008, - 2145768960, - 2145813760, - 2145857408, - 2145899904, - 2145941376, - 2145981696, - 2146020864, - 2146059136, - 2146096384, - 2146132608, - 2146167936, - 2146202368, - 2146235776, - 2146268416, - 2146300160, - 2146331136, - 2146361216, - 2146390528, - 2146419200, - 2146446976, - 2146474112, - 2146500480, - 2146526208, - 2146551168, - 2146575488, - 2146599296, - 2146622464, - 2146644864, - 2146666880, - 2146688128, - 2146708992, - 2146729216, - 2146748928, - 2146768128, - 2146786816, - 2146805120, - 2146822784, - 2146840064, - 2146856960, - 2146873344, - 2146889216, - 2146904832, - 2146919936, - 2146934656, - 2146948992, - 2146962944, - 2146976640, - 2146989824, - 2147002752, - 2147015296, - 2147027584, - 2147039488, - 2147051136, - 2147062400, - 2147073408, - 2147084160, - 2147094528, - 2147104768, - 2147114624, - 2147124352, - 2147133696, - 2147142912, - 2147151744, - 2147160448, - 2147168896, - 2147177088, - 2147185152, - 2147192960, - 2147200512, - 2147207936, - 2147215104, - 2147222144, - 2147229056, - 2147235712, - 2147242112, - 2147248384, - 2147254656, - 2147260544, - 2147266432, - 2147272064, - 2147277568, - }, - - - }; /*-------------------------------------------------------------------* * detect_strong_saturations() @@ -925,11 +109,11 @@ static int16_t detect_strong_saturations( } #else static Word16 detect_strong_saturations_fx( - const Word16 BER_detect, /* i : BER detect flag */ - Word16 *strong_saturation_cnt, /* i/o: counter of strong saturations */ - const Word32 max_val, /* i : maximum absolute value */ - Word32 *frame_gain, /* i/o: frame gain value */ - Word16 q_factor /* i : Q factor of the output samples */ + const Word16 BER_detect, /* i : BER detect flag */ + Word16 *strong_saturation_cnt, /* i/o: counter of strong saturations */ + const Word32 max_val, /* i : maximum absolute value q_factor */ + Word32 *frame_gain, /* i/o: frame gain value Q30 */ + Word16 q_factor /* i : Q factor of the output samples */ ) { Word16 apply_strong_limiting; @@ -937,8 +121,8 @@ static Word16 detect_strong_saturations_fx( apply_strong_limiting = 0; move16(); - compare_max_value_Mul_3 = W_shl( 98187, q_factor ); // 3 * IVAS_LIMITER_THRESHOLD - compare_max_value_Mul_10 = W_shl( 327290, q_factor ); // 10 * IVAS_LIMITER_THRESHOLD + compare_max_value_Mul_3 = W_shl( 98187, q_factor ); // 3 * IVAS_LIMITER_THRESHOLD : Q(q_factor) + compare_max_value_Mul_10 = W_shl( 327290, q_factor ); // 10 * IVAS_LIMITER_THRESHOLD : Q(q_factor) test(); IF( BER_detect ) { @@ -1035,19 +219,19 @@ ivas_error ivas_limiter_open_fx( SWITCH( sampling_rate ) { case 48000: - attack_cnst_fx = ATTACK_CNST_48k; + attack_cnst_fx = ATTACK_CNST_48k; /*Q31*/ move32(); BREAK; case 32000: - attack_cnst_fx = ATTACK_CNST_32k; + attack_cnst_fx = ATTACK_CNST_32k; /*Q31*/ move32(); BREAK; case 16000: - attack_cnst_fx = ATTACK_CNST_16k; + attack_cnst_fx = ATTACK_CNST_16k; /*Q31*/ move32(); BREAK; case 8000: - attack_cnst_fx = ATTACK_CNST_8k; + attack_cnst_fx = ATTACK_CNST_8k; /*Q31*/ move32(); BREAK; default: @@ -1164,12 +348,12 @@ void ivas_limiter_close( #ifdef IVAS_FLOAT_FIXED void ivas_limiter_dec_fx( - IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ - Word32 *output[MAX_OUTPUT_CHANNELS], /* i/o: input/output buffer */ - const Word16 num_channels, /* i : number of channels to be processed */ - const Word16 output_frame, /* i : number of samples per channel in the buffer */ - const Word16 BER_detect, /* i : BER detect flag */ - Word16 q_factor /* i : Q factor of the output samples */ + IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ + Word32 *output[MAX_OUTPUT_CHANNELS], /* i/o: input/output buffer Q : q_factor */ + const Word16 num_channels, /* i : number of channels to be processed */ + const Word16 output_frame, /* i : number of samples per channel in the buffer */ + const Word16 BER_detect, /* i : BER detect flag */ + Word16 q_factor /* i : Q factor of the output samples */ ) { Word16 c; @@ -1191,9 +375,9 @@ void ivas_limiter_dec_fx( FOR( c = 0; c < num_channels; ++c ) { - channels[c] = output[c]; + channels[c] = output[c]; /*q_factor*/ } - Word32 limiter_thresold = L_shl( IVAS_LIMITER_THRESHOLD, q_factor ); + Word32 limiter_thresold = L_shl( IVAS_LIMITER_THRESHOLD, q_factor ); /*q_factor*/ limiter_process_fx( hLimiter, output_frame, limiter_thresold, BER_detect, &hLimiter->strong_saturation_count, q_factor ); return; @@ -1243,12 +427,12 @@ void ivas_limiter_dec( #ifdef IVAS_FLOAT_FIXED void limiter_process_fx( - IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ - const Word16 output_frame, /* i : number of samples to be processed per channel in the I/O buffer */ - const Word32 threshold, /* i : signal amplitude above which limiting starts to be applied */ - const Word16 BER_detect, /* i : BER detect flag */ - Word16 *strong_saturation_cnt, /* i/o: counter of strong saturations (can be NULL) */ - Word16 q_factor /* i : Q factor of output samples */ + IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ + const Word16 output_frame, /* i : number of samples to be processed per channel in the I/O buffer */ + const Word32 threshold, /* i : signal amplitude above which limiting starts to be applied Q : q_factor */ + const Word16 BER_detect, /* i : BER detect flag */ + Word16 *strong_saturation_cnt, /* i/o: counter of strong saturations (can be NULL) */ + Word16 q_factor /* i : Q factor of output samples */ ) { Word16 i, c; @@ -1274,7 +458,7 @@ void limiter_process_fx( apply_strong_limiting = 0; move16(); - gain = hLimiter->gain_fx; + gain = hLimiter->gain_fx; /* Q30 */ move32(); output = hLimiter->channel_ptrs_fx; num_channels = hLimiter->num_channels; @@ -1296,7 +480,7 @@ void limiter_process_fx( tmp = L_abs( output[c][i] ); if ( GT_32( tmp, max_val ) ) { - max_val = tmp; + max_val = tmp; /*q_factor*/ move32(); } } @@ -1321,15 +505,15 @@ void limiter_process_fx( case 640: case 320: case 160: - releaseHeuristic_cnst = 85899345; + releaseHeuristic_cnst = 85899345; /*Q30*/ move32(); - releaseHeuristic_cnst_2 = 21474836; + releaseHeuristic_cnst_2 = 21474836; /*Q30*/ move32(); BREAK; default: - releaseHeuristic_cnst = 21474836; + releaseHeuristic_cnst = 21474836; /*Q30*/ move32(); - releaseHeuristic_cnst_2 = 5368709; + releaseHeuristic_cnst_2 = 5368709; /*Q30*/ move32(); BREAK; } @@ -1338,7 +522,7 @@ void limiter_process_fx( IF( GT_32( max_val, threshold ) ) { - frame_gain = L_shl( divide3232( threshold, max_val ), 15 ); // to q30 + frame_gain = L_shl( divide3232( threshold, max_val ), 15 ); // to Q30 releaseHeuristic = L_min( ONE_IN_Q30, L_add( releaseHeuristic, releaseHeuristic_cnst ) ); // releaseHeuristic_cnst is Q30 of ( 4.f * output_frame / sampling_rate ) // release_constant = powf( 0.01f, 1.0f / ( 0.005f * powf( 200.f, .08 ) * sampling_rate ) ); /* Unoptimized code for reference */ @@ -1365,6 +549,7 @@ void limiter_process_fx( /* No samples above threshold but gain from previous frame is not 1.f, * transition to gain == 1.f */ frame_gain = ONE_IN_Q30; + move32(); } /* Detection of very strong saturations */ IF( strong_saturation_cnt != NULL ) @@ -1376,9 +561,9 @@ void limiter_process_fx( /* Limit gain reduction to 20dB. Any peaks that require gain reduction * higher than this are most likely due to bit errors during decoding */ test(); - IF( LT_32( frame_gain, compare_value ) && !apply_strong_limiting ) + if ( LT_32( frame_gain, compare_value ) && !apply_strong_limiting ) { - frame_gain = compare_value; + frame_gain = compare_value; /*Q30*/ move32(); } @@ -1394,7 +579,8 @@ void limiter_process_fx( result = BASOP_Util_Divide3232_Scale( releaseHeuristic, div32, &scale ); idx = extract_l( Mpy_32_32( hLimiter->sampling_rate, 134218 ) ); - release_constant = release_cnst_table[idx][shr( result, sub( 15, scale ) )]; /* Q31 */ + result = shr( result, sub( 15, scale ) ); + release_constant = release_cnst_table[idx][result]; /* Q31 */ move32(); /* Unoptimized code for reference */ /* releaseTimeInSeconds = 0.005f * powf(200.f, releaseHeuristic); <-- Map heuristic value (0; 1) exponentially to range (0.005; 1) diff --git a/lib_rend/ivas_objectRenderer_mix.c b/lib_rend/ivas_objectRenderer_mix.c index 72b35aa90eedaecd8da642981a76910bc1e4b797..ff564234462e77b15e5e3fd9ef577c9407176c92 100644 --- a/lib_rend/ivas_objectRenderer_mix.c +++ b/lib_rend/ivas_objectRenderer_mix.c @@ -51,8 +51,8 @@ #define RESAMPLE_FACTOR_32_48 ( 32.0f / 48.0f ) #ifdef IVAS_FLOAT_FIXED -#define RESAMPLE_FACTOR_16_48_FX ( 5461 ) -#define RESAMPLE_FACTOR_32_48_FX ( 10922 ) +#define RESAMPLE_FACTOR_16_48_FX ( 5461 ) // Q14 +#define RESAMPLE_FACTOR_32_48_FX ( 10922 ) // Q14 #endif @@ -73,8 +73,8 @@ static ivas_error DefaultBSplineModel_fx( TDREND_HRFILT_FiltSet_t *HrFiltSet_p, #ifdef IVAS_FLOAT_FIXED void TDREND_MIX_LIST_SetPos_fx( - BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - const Word32 *Pos_p /* i : Listener's position */ + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ + const Word32 *Pos_p /* i : Listener's position */ // Q Pos_fx->q_fact ) { TDREND_MIX_Listener_t *Listener_p; @@ -85,7 +85,7 @@ void TDREND_MIX_LIST_SetPos_fx( IF( NE_32( Pos_p[0], Listener_p->Pos_fx[0] ) || NE_32( Pos_p[1], Listener_p->Pos_fx[1] ) || NE_32( Pos_p[2], Listener_p->Pos_fx[2] ) ) { /* Set position */ - Copy32( Pos_p, Listener_p->Pos_fx, 3 ); + Copy32( Pos_p, Listener_p->Pos_fx, 3 ); // Q Pos_fx->q_fact /* Set pose update flag */ Listener_p->PoseUpdated = TRUE; @@ -154,9 +154,11 @@ ivas_error TDREND_MIX_LIST_SetOrient( #else ivas_error TDREND_MIX_LIST_SetOrient_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - const Word32 *FrontVec_p_fx, /* i : Listener's orientation front vector */ - const Word32 *UpVec_p_fx, /* i : Listener's orientation up vector */ - const Word16 orient_q /* i : Listener's orientation q-factor */ + const Word32 *FrontVec_p_fx, + /* i : Listener's orientation front vector */ // orient_q + const Word32 *UpVec_p_fx, + /* i : Listener's orientation up vector */ // orient_q + const Word16 orient_q /* i : Listener's orientation q-factor */ ) { @@ -180,7 +182,7 @@ ivas_error TDREND_MIX_LIST_SetOrient_fx( List_p = hBinRendererTd->Listener_p; /* Evaluate the normalized orientation vectors and set pose update flag */ - List_p->PoseUpdated = TDREND_SPATIAL_EvalOrthonormOrient_fx( List_p->Front_fx, List_p->Up_fx, List_p->Right_fx, FrontVec_p_fx, UpVec_p_fx, orient_q ); + List_p->PoseUpdated = TDREND_SPATIAL_EvalOrthonormOrient_fx( List_p->Front_fx, List_p->Up_fx, List_p->Right_fx, FrontVec_p_fx, UpVec_p_fx, orient_q ); // Q0 move16(); return IVAS_ERR_OK; @@ -313,10 +315,10 @@ void TDREND_MIX_Dealloc( --------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_MIX_Init_fx( - BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - TDREND_HRFILT_FiltSet_t **hHrtfTD, /* i/o: HRTF data (initialized in case of NULL) */ - const TDREND_MixSpatSpec_t *MixSpatSpec_p, /* i : Mixer spatial specification */ - const Word32 output_Fs /* i : Output sampling rate */ + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ + TDREND_HRFILT_FiltSet_t **hHrtfTD, /* i/o: HRTF data (initialized in case of NULL) */ + const TDREND_MixSpatSpec_t *MixSpatSpec_p, /* i : Mixer spatial specification */ + const Word32 output_Fs /* i : Output sampling rate */ // Q0 ) { ivas_error error; @@ -326,16 +328,16 @@ ivas_error TDREND_MIX_Init_fx( /* Spatial settings */ IF( MixSpatSpec_p != NULL ) { - hBinRendererTd->UseCommonDistAttenModel = MixSpatSpec_p->UseCommonDistAttenModel; + hBinRendererTd->UseCommonDistAttenModel = MixSpatSpec_p->UseCommonDistAttenModel; // Q0 move16(); - hBinRendererTd->DistAttenModel = MixSpatSpec_p->DistAttenModel; + hBinRendererTd->DistAttenModel = MixSpatSpec_p->DistAttenModel; // Q0 move16(); } ELSE { - hBinRendererTd->UseCommonDistAttenModel = TRUE; + hBinRendererTd->UseCommonDistAttenModel = TRUE; // Q0 move16(); - hBinRendererTd->DistAttenModel = 0x0000; /* Distance attenuation not activated; */ + hBinRendererTd->DistAttenModel = 0x0000; /* Distance attenuation not activated; */ // Q0 move16(); } /* Init virtual and rendering listeners for spatial mixers */ @@ -452,15 +454,15 @@ ivas_error TDREND_MIX_SetDistAttenModel( ELSE { /* Set the common distance attenuation model */ - hBinRendererTd->DistAttenModel = DistAttenModel; + hBinRendererTd->DistAttenModel = DistAttenModel; // Q0 move32(); /* If using common distance attenuation model, set it. */ IF( hBinRendererTd->UseCommonDistAttenModel ) { - hBinRendererTd->DistAttenEnabled = TRUE; + hBinRendererTd->DistAttenEnabled = TRUE; // Q0 move16(); - hBinRendererTd->DistAttenModel = DistAttenModel; + hBinRendererTd->DistAttenModel = DistAttenModel; // Q0 move32(); } } @@ -504,8 +506,9 @@ ivas_error TDREND_MIX_SetDistAttenModel( #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_MIX_AddSrc_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - Word16 *SrcInd, /* o : Source index */ - const TDREND_PosType_t PosType /* i : Position type (absolute/relative) */ + Word16 *SrcInd, + /* o : Source index */ // Q0 + const TDREND_PosType_t PosType /* i : Position type (absolute/relative) */ ) { TDREND_SRC_t *Src_p; @@ -514,11 +517,11 @@ ivas_error TDREND_MIX_AddSrc_fx( error = IVAS_ERR_OK; move32(); /* Get unique source index */ - *SrcInd = add( hBinRendererTd->MaxSrcInd, 1 ); + *SrcInd = add( hBinRendererTd->MaxSrcInd, 1 ); // Q0 move16(); - hBinRendererTd->MaxSrcInd = add( hBinRendererTd->MaxSrcInd, 1 ); + hBinRendererTd->MaxSrcInd = add( hBinRendererTd->MaxSrcInd, 1 ); // Q0 move16(); - hBinRendererTd->NumOfSrcs = add( hBinRendererTd->NumOfSrcs, 1 ); + hBinRendererTd->NumOfSrcs = add( hBinRendererTd->NumOfSrcs, 1 ); // Q0 move16(); IF( GT_16( hBinRendererTd->NumOfSrcs, MAX_NUM_TDREND_CHANNELS ) ) @@ -545,9 +548,9 @@ ivas_error TDREND_MIX_AddSrc_fx( /* Special OpenAL initialization due to a common distance attenuation model */ IF( NE_16( hBinRendererTd->DistAttenModel, 0 ) ) { - Src_p->SrcSpatial_p->DistAttenEnabled = TRUE; + Src_p->SrcSpatial_p->DistAttenEnabled = TRUE; // Q0 move16(); - Src_p->SrcSpatial_p->DistAtten.DistAttenModel = hBinRendererTd->DistAttenModel; + Src_p->SrcSpatial_p->DistAtten.DistAttenModel = hBinRendererTd->DistAttenModel; // Q0 move32(); } /* Add source to mixer */ @@ -662,8 +665,8 @@ static ivas_error BSplineModelEvalAlloc( #ifdef IVAS_FLOAT_FIXED static ivas_error DefaultBSplineModel_fx( - TDREND_HRFILT_FiltSet_t *HrFiltSet_p, /* o : Loaded HR filter set */ - const Word32 output_Fs /* i : Output sampling rate */ + TDREND_HRFILT_FiltSet_t *HrFiltSet_p, /* o : Loaded HR filter set */ + const Word32 output_Fs /* i : Output sampling rate */ // Q0 ) { ModelParams_t *model; @@ -678,19 +681,19 @@ static ivas_error DefaultBSplineModel_fx( SWITCH( output_Fs ) { case 48000: - HrFiltSet_p->lr_energy_and_iac_fx[0] = defaultHRIR_left_avg_power_48kHz_fx; - HrFiltSet_p->lr_energy_and_iac_fx[1] = defaultHRIR_right_avg_power_48kHz_fx; - HrFiltSet_p->lr_energy_and_iac_fx[2] = defaultHRIR_coherence_48kHz_fx; + HrFiltSet_p->lr_energy_and_iac_fx[0] = defaultHRIR_left_avg_power_48kHz_fx; // Q23 + HrFiltSet_p->lr_energy_and_iac_fx[1] = defaultHRIR_right_avg_power_48kHz_fx; // Q23 + HrFiltSet_p->lr_energy_and_iac_fx[2] = defaultHRIR_coherence_48kHz_fx; // Q23 BREAK; case 32000: - HrFiltSet_p->lr_energy_and_iac_fx[0] = defaultHRIR_left_avg_power_32kHz_fx; - HrFiltSet_p->lr_energy_and_iac_fx[1] = defaultHRIR_right_avg_power_32kHz_fx; - HrFiltSet_p->lr_energy_and_iac_fx[2] = defaultHRIR_coherence_32kHz_fx; + HrFiltSet_p->lr_energy_and_iac_fx[0] = defaultHRIR_left_avg_power_32kHz_fx; // Q23 + HrFiltSet_p->lr_energy_and_iac_fx[1] = defaultHRIR_right_avg_power_32kHz_fx; // Q23 + HrFiltSet_p->lr_energy_and_iac_fx[2] = defaultHRIR_coherence_32kHz_fx; // Q23 BREAK; case 16000: - HrFiltSet_p->lr_energy_and_iac_fx[0] = defaultHRIR_left_avg_power_16kHz_fx; - HrFiltSet_p->lr_energy_and_iac_fx[1] = defaultHRIR_right_avg_power_16kHz_fx; - HrFiltSet_p->lr_energy_and_iac_fx[2] = defaultHRIR_coherence_16kHz_fx; + HrFiltSet_p->lr_energy_and_iac_fx[0] = defaultHRIR_left_avg_power_16kHz_fx; // Q23 + HrFiltSet_p->lr_energy_and_iac_fx[1] = defaultHRIR_right_avg_power_16kHz_fx; // Q23 + HrFiltSet_p->lr_energy_and_iac_fx[2] = defaultHRIR_coherence_16kHz_fx; // Q23 BREAK; } @@ -699,52 +702,52 @@ static ivas_error DefaultBSplineModel_fx( move16(); /* int16_t parameters */ - model->UseItdModel = 1; + model->UseItdModel = 1; // Q0 move16(); - model->SplineDegree = 4; + model->SplineDegree = 4; // Q0 move16(); - model->elevDim2 = 17; + model->elevDim2 = 17; // Q0 move16(); - model->elevDim3 = 15; + model->elevDim3 = 15; // Q0 move16(); - model->AlphaN = 470; + model->AlphaN = 470; // Q0 move16(); - model->num_unique_azim_splines = 1; + model->num_unique_azim_splines = 1; // Q0 move16(); - model->elevSegSamples = 4; + model->elevSegSamples = 4; // Q0 move16(); - model->elevBsLen[0] = 5; + model->elevBsLen[0] = 5; // Q0 move16(); - model->elevBsLen[1] = 9; + model->elevBsLen[1] = 9; // Q0 move16(); - model->elevBsLen[2] = 13; + model->elevBsLen[2] = 13; // Q0 move16(); - model->elevBsLen[3] = 9; + model->elevBsLen[3] = 9; // Q0 move16(); - model->elevBsStart[0] = 0; + model->elevBsStart[0] = 0; // Q0 move16(); - model->elevBsStart[1] = 5; + model->elevBsStart[1] = 5; // Q0 move16(); - model->elevBsStart[2] = 14; + model->elevBsStart[2] = 14; // Q0 move16(); - model->elevBsStart[3] = 27; + model->elevBsStart[3] = 27; // Q0 move16(); - model->azimDim2 = defaultHRIR_rom_azimDim2; - model->azimDim3 = defaultHRIR_rom_azimDim3; - model->azim_start_idx = defaultHRIR_rom_azim_start_idx; - model->azimSegSamples = defaultHRIR_rom_azimSegSamples; - model->azimShapeIdx = defaultHRIR_rom_azimShapeIdx; - model->azimShapeSampFactor = defaultHRIR_rom_azimShapeSampFactor; + model->azimDim2 = defaultHRIR_rom_azimDim2; // Q0 + model->azimDim3 = defaultHRIR_rom_azimDim3; // Q0 + model->azim_start_idx = defaultHRIR_rom_azim_start_idx; // Q0 + model->azimSegSamples = defaultHRIR_rom_azimSegSamples; // Q0 + model->azimShapeIdx = defaultHRIR_rom_azimShapeIdx; // Q0 + model->azimShapeSampFactor = defaultHRIR_rom_azimShapeSampFactor; // Q0 - model->elevKSeq_fx = defaultHRIR_rom_elevKSeq_fx; - model->elevBsShape_fx = (const Word32 *) defaultHRIR_rom_elevBsShape_fx; + model->elevKSeq_fx = defaultHRIR_rom_elevKSeq_fx; // Q22 + model->elevBsShape_fx = (const Word32 *) defaultHRIR_rom_elevBsShape_fx; // Q30 IF( ( model->azimBsShape_fx = (const Word32 **) malloc( model->num_unique_azim_splines * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); } - model->azimBsShape_fx[0] = defaultHRIR_rom_azimBsShape_fx; + model->azimBsShape_fx[0] = defaultHRIR_rom_azimBsShape_fx; // Q30 IF( ( model->azimKSeq_fx = (Word32 **) malloc( 18 * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); @@ -759,8 +762,8 @@ static ivas_error DefaultBSplineModel_fx( } model->azimKSeq_fx[0][0] = 0; model->azimKSeq_fx[model->elevDim3 - 1][0] = 0; - model->azimKSeq_fx[0][1] = 360 << Q22; - model->azimKSeq_fx[model->elevDim3 - 1][1] = 360 << Q22; + model->azimKSeq_fx[0][1] = 360 << Q22; // Q22 + model->azimKSeq_fx[model->elevDim3 - 1][1] = 360 << Q22; // Q22 move32(); move32(); move32(); @@ -774,7 +777,7 @@ static ivas_error DefaultBSplineModel_fx( } FOR( j = 0; j < model->azimDim2[i]; j++ ) { - model->azimKSeq_fx[i][j] = L_shl( L_mult0( defaultHRIR_rom_azimSegSamples[0], j ), Q22 ); + model->azimKSeq_fx[i][j] = L_shl( L_mult0( defaultHRIR_rom_azimSegSamples[0], j ), Q22 ); // Q22 move32(); } } @@ -782,65 +785,65 @@ static ivas_error DefaultBSplineModel_fx( SWITCH( output_Fs ) { case 48000: - model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL48_fx; + model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL48_fx; // Q30 model->AlphaL_e = 1; move16(); - model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR48_fx; + model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR48_fx; // Q30 model->AlphaR_e = 1; move16(); - model->EL_fx = (const Word32 *) defaultHRIR_rom_EL48_fx; + model->EL_fx = (const Word32 *) defaultHRIR_rom_EL48_fx; // Q28 model->EL_e = 3; move16(); - model->ER_fx = (const Word32 *) defaultHRIR_rom_ER48_fx; + model->ER_fx = (const Word32 *) defaultHRIR_rom_ER48_fx; // Q28 model->ER_e = 3; move16(); - model->K = 128; + model->K = 128; // Q0 move16(); IF( HrFiltSet_p->ModelParams.UseItdModel ) { - modelITD->resamp_factor_fx = ONE_IN_Q14; + modelITD->resamp_factor_fx = ONE_IN_Q14; // Q14 move16(); } BREAK; case 32000: - model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL32_fx; + model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL32_fx; // Q30 model->AlphaL_e = 1; move16(); - model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR32_fx; + model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR32_fx; // Q30 model->AlphaR_e = 1; move16(); - model->EL_fx = (const Word32 *) defaultHRIR_rom_EL32_fx; + model->EL_fx = (const Word32 *) defaultHRIR_rom_EL32_fx; // Q28 model->EL_e = 3; move16(); - model->ER_fx = (const Word32 *) defaultHRIR_rom_ER32_fx; + model->ER_fx = (const Word32 *) defaultHRIR_rom_ER32_fx; // Q28 model->ER_e = 3; move16(); - model->K = 86; + model->K = 86; // Q0 move16(); IF( HrFiltSet_p->ModelParams.UseItdModel ) { - modelITD->resamp_factor_fx = RESAMPLE_FACTOR_32_48_FX; + modelITD->resamp_factor_fx = RESAMPLE_FACTOR_32_48_FX; // Q14 move16(); } BREAK; case 16000: - model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL16_fx; + model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL16_fx; // Q30 model->AlphaL_e = 1; move16(); - model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR16_fx; + model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR16_fx; // Q30 model->AlphaR_e = 1; move16(); - model->EL_fx = (const Word32 *) defaultHRIR_rom_EL16_fx; + model->EL_fx = (const Word32 *) defaultHRIR_rom_EL16_fx; // Q28 model->EL_e = 3; move16(); - model->ER_fx = (const Word32 *) defaultHRIR_rom_ER16_fx; + model->ER_fx = (const Word32 *) defaultHRIR_rom_ER16_fx; // Q28 model->ER_e = 3; move16(); - model->K = 43; + model->K = 43; // Q0 move16(); IF( HrFiltSet_p->ModelParams.UseItdModel ) { - modelITD->resamp_factor_fx = RESAMPLE_FACTOR_16_48_FX; + modelITD->resamp_factor_fx = RESAMPLE_FACTOR_16_48_FX; // Q14 move16(); } BREAK; @@ -848,69 +851,69 @@ static ivas_error DefaultBSplineModel_fx( BREAK; } - modelITD->N = 4; + modelITD->N = 4; // Q0 move16(); - modelITD->elevDim2 = 20; + modelITD->elevDim2 = 20; // Q0 move16(); - modelITD->elevDim3 = 18; + modelITD->elevDim3 = 18; // Q0 move16(); - modelITD->azimDim2 = 41; + modelITD->azimDim2 = 41; // Q0 move16(); - modelITD->azimDim3 = 41; + modelITD->azimDim3 = 41; // Q0 move16(); - modelITD->elevSegSamples = 3; + modelITD->elevSegSamples = 3; // Q0 move16(); - modelITD->elevBsLen[0] = 4; + modelITD->elevBsLen[0] = 4; // Q0 move16(); - modelITD->elevBsLen[1] = 7; + modelITD->elevBsLen[1] = 7; // Q0 move16(); - modelITD->elevBsLen[2] = 10; + modelITD->elevBsLen[2] = 10; // Q0 move16(); - modelITD->elevBsLen[3] = 7; + modelITD->elevBsLen[3] = 7; // Q0 move16(); - modelITD->elevBsStart[0] = 0; + modelITD->elevBsStart[0] = 0; // Q0 move16(); - modelITD->elevBsStart[1] = 4; + modelITD->elevBsStart[1] = 4; // Q0 move16(); - modelITD->elevBsStart[2] = 11; + modelITD->elevBsStart[2] = 11; // Q0 move16(); - modelITD->elevBsStart[3] = 21; + modelITD->elevBsStart[3] = 21; // Q0 move16(); - modelITD->elevKSeq_fx = defaultHRIR_rom_ITD_elevKSeq_fx; + modelITD->elevKSeq_fx = defaultHRIR_rom_ITD_elevKSeq_fx; // Q22 - modelITD->azimBsLen[0] = 11; + modelITD->azimBsLen[0] = 11; // Q0 move16(); - modelITD->azimBsLen[1] = 21; + modelITD->azimBsLen[1] = 21; // Q0 move16(); - modelITD->azimBsLen[2] = 31; + modelITD->azimBsLen[2] = 31; // Q0 move16(); - modelITD->azimBsLen[3] = 21; + modelITD->azimBsLen[3] = 21; // Q0 move16(); - modelITD->azimBsStart[0] = 0; + modelITD->azimBsStart[0] = 0; // Q0 move16(); - modelITD->azimBsStart[1] = 11; + modelITD->azimBsStart[1] = 11; // Q0 move16(); - modelITD->azimBsStart[2] = 32; + modelITD->azimBsStart[2] = 32; // Q0 move16(); - modelITD->azimBsStart[3] = 63; + modelITD->azimBsStart[3] = 63; // Q0 move16(); - modelITD->azimSegSamples = 10; + modelITD->azimSegSamples = 10; // Q0 move16(); - modelITD->azimKSeq_fx = defaultHRIR_rom_ITD_azimKSeq_fx; + modelITD->azimKSeq_fx = defaultHRIR_rom_ITD_azimKSeq_fx; // Q22 modelITD->W_fx = (const Word32 *) defaultHRIR_rom_ITD_W_fx; // Q25 modelITD->W_e = 6; move16(); - modelITD->azimBsShape_fx = defaultHRIR_rom_ITD_azimBsShape_fx; - modelITD->elevBsShape_fx = defaultHRIR_rom_ITD_elevBsShape_fx; + modelITD->azimBsShape_fx = defaultHRIR_rom_ITD_azimBsShape_fx; // Q30 + modelITD->elevBsShape_fx = defaultHRIR_rom_ITD_elevBsShape_fx; // Q30 HRTF_model_precalc( model ); - HrFiltSet_p->latency_s_fx = defaultHRIR_rom_latency_s_fx; + HrFiltSet_p->latency_s_fx = defaultHRIR_rom_latency_s_fx; // Q31 move32(); - HrFiltSet_p->SampleRate = output_Fs; + HrFiltSet_p->SampleRate = output_Fs; // Q0 move32(); - HrFiltSet_p->FiltLength = HrFiltSet_p->ModelParams.K; + HrFiltSet_p->FiltLength = HrFiltSet_p->ModelParams.K; // Q0 move16(); IF( NE_32( ( error = BSplineModelEvalAlloc_fx( &HrFiltSet_p->ModelParams, &HrFiltSet_p->ModelEval ) ), IVAS_ERR_OK ) ) diff --git a/lib_rend/ivas_objectRenderer_sfx.c b/lib_rend/ivas_objectRenderer_sfx.c index cbd860f49c1a95a2954975cf26cd5c5b387b8c53..cc81d0d6d1e055d526707036afd280b919c546f3 100644 --- a/lib_rend/ivas_objectRenderer_sfx.c +++ b/lib_rend/ivas_objectRenderer_sfx.c @@ -168,10 +168,10 @@ void TDREND_Apply_ITD_fx( Word32 *input_fx, /* i : Input subframe to be time adjusted Qx */ Word32 *out_left_fx, /* o : Output left channel with ITD applied Qx */ Word32 *out_right_fx, /* o : Output right channel with ITD applied Qx */ - Word16 *previtd, /* i/o: Previous ITD value */ - const Word16 itd, /* i : Current subframe ITD value */ + Word16 *previtd, /* i/o: Previous ITD value Q0 */ + const Word16 itd, /* i : Current subframe ITD value Q0 */ Word32 *mem_itd_fx, /* i/o: ITD buffer memory Qx */ - const Word16 length /* i : Subframe length */ + const Word16 length /* i : Subframe length Q0 */ ) { Word16 transition_len; @@ -183,95 +183,95 @@ void TDREND_Apply_ITD_fx( Word32 *pstart1_fx; Word32 *pstart2_fx; Word32 *pstart3_fx; - Word32 buffer_fx[ITD_MEM_LEN + L_SUBFRAME5MS_48k]; + Word32 buffer_fx[ITD_MEM_LEN + L_SUBFRAME5MS_48k]; // Qx Word32 *p_input_fx; Word32 *out_buf_A_fx, *out_buf_B_fx; push_wmops( "TDREND_Apply_ITD" ); /* Prepare resampling buffer */ - Copy32( mem_itd_fx, buffer_fx, ITD_MEM_LEN ); /* Retrieve memory */ - p_input_fx = buffer_fx + ITD_MEM_LEN; /* pointer to the current subframe */ - Copy32( input_fx, p_input_fx, length ); /* input current subframe */ - Copy32( buffer_fx + length, mem_itd_fx, ITD_MEM_LEN ); /* update memory for next frame */ + Copy32( mem_itd_fx, buffer_fx, ITD_MEM_LEN ); /* Retrieve memory */ // Qx + p_input_fx = buffer_fx + ITD_MEM_LEN; /* pointer to the current subframe */ // Qx + Copy32( input_fx, p_input_fx, length ); /* input current subframe */ // Qx + Copy32( buffer_fx + length, mem_itd_fx, ITD_MEM_LEN ); /* update memory for next frame */ // Qx - currShift = abs_s( itd ); - prevShift = abs_s( *previtd ); - tlen3 = s_max( 0, sub( SFX_SPAT_BIN_SINC_M, currShift ) ); /* Make sure there is enough look-ahead for the sinc resampling */ - transition_len = sub( length, tlen3 ); + currShift = abs_s( itd ); // Q0 + prevShift = abs_s( *previtd ); // Q0 + tlen3 = s_max( 0, sub( SFX_SPAT_BIN_SINC_M, currShift ) ); /* Make sure there is enough look-ahead for the sinc resampling */ // Q0 + transition_len = sub( length, tlen3 ); // Q0 IF( i_mult( ( *previtd ), itd ) < 0 ) { /* ITD sign change - apply shift on both channels */ - Word16 tmp1 = imult1616( transition_len, prevShift ); - Word16 tmp2 = add( prevShift, currShift ); + Word16 tmp1 = imult1616( transition_len, prevShift ); // Q0 + Word16 tmp2 = add( prevShift, currShift ); // Q0 Word16 tmp_e; - Word16 tmp3 = BASOP_Util_Divide1616_Scale( tmp1, tmp2, &tmp_e ); + Word16 tmp3 = BASOP_Util_Divide1616_Scale( tmp1, tmp2, &tmp_e ); // exp(tmp_e) Word16 tmp4; - Word16 tmp_e2 = BASOP_Util_Add_MantExp( tmp3, tmp_e, ONE_IN_Q14, 0, &tmp4 ); - tmp4 = shr( tmp4, sub( 15, tmp_e2 ) ); // Q0 - tlen1 = tmp4; + Word16 tmp_e2 = BASOP_Util_Add_MantExp( tmp3, tmp_e, ONE_IN_Q14, 0, &tmp4 ); // exp(tmp4) + tmp4 = shr( tmp4, sub( 15, tmp_e2 ) ); // Q0 + tlen1 = tmp4; // Q0 move16(); - tlen2 = sub( transition_len, tlen1 ); - pstart1_fx = p_input_fx - prevShift; - length_in1 = add( tlen1, prevShift ); - pstart2_fx = pstart1_fx + length_in1; - length_in2 = sub( tlen2, currShift ); - pstart3_fx = pstart2_fx + length_in2; + tlen2 = sub( transition_len, tlen1 ); // Q0 + pstart1_fx = p_input_fx - prevShift; // Qx + length_in1 = add( tlen1, prevShift ); // Q0 + pstart2_fx = pstart1_fx + length_in1; // Qx + length_in2 = sub( tlen2, currShift ); // Q0 + pstart3_fx = pstart2_fx + length_in2; // Qx } ELSE { /* ITD sign stays the same, or one of them is zero */ - tlen1 = transition_len; + tlen1 = transition_len; // Q0 move16(); - tlen2 = 0; + tlen2 = 0; // Q0 move16(); - pstart1_fx = p_input_fx - prevShift; - length_in1 = sub( add( transition_len, prevShift ), currShift ); - pstart2_fx = pstart1_fx + length_in1; - length_in2 = 0; + pstart1_fx = p_input_fx - prevShift; // Qx + length_in1 = sub( add( transition_len, prevShift ), currShift ); // Q0 + pstart2_fx = pstart1_fx + length_in1; // Qx + length_in2 = 0; // Q0 move16(); - pstart3_fx = pstart2_fx + add( length_in2, currShift ); + pstart3_fx = pstart2_fx + add( length_in2, currShift ); // Qx } IF( *previtd == 0 ) { IF( itd > 0 ) { - out_buf_A_fx = out_right_fx; - out_buf_B_fx = out_left_fx; + out_buf_A_fx = out_right_fx; // Qx + out_buf_B_fx = out_left_fx; // Qx } ELSE { - out_buf_A_fx = out_left_fx; - out_buf_B_fx = out_right_fx; + out_buf_A_fx = out_left_fx; // Qx + out_buf_B_fx = out_right_fx; // Qx } } ELSE { IF( *previtd > 0 ) { - out_buf_A_fx = out_right_fx; - out_buf_B_fx = out_left_fx; + out_buf_A_fx = out_right_fx; // Qx + out_buf_B_fx = out_left_fx; // Qx } ELSE { - out_buf_A_fx = out_left_fx; - out_buf_B_fx = out_right_fx; + out_buf_A_fx = out_left_fx; // Qx + out_buf_B_fx = out_right_fx; // Qx } } /* Output buffer A */ sincResample_fx( pstart1_fx, out_buf_A_fx, length_in1, tlen1 ); - Copy32( pstart2_fx, out_buf_A_fx + tlen1, sub( length, tlen1 ) ); + Copy32( pstart2_fx, out_buf_A_fx + tlen1, sub( length, tlen1 ) ); // Qx /* Output buffer B */ - Copy32( p_input_fx, out_buf_B_fx, tlen1 ); + Copy32( p_input_fx, out_buf_B_fx, tlen1 ); // Qx sincResample_fx( pstart2_fx, out_buf_B_fx + tlen1, length_in2, tlen2 ); - Copy32( pstart3_fx, out_buf_B_fx + transition_len, tlen3 ); + Copy32( pstart3_fx, out_buf_B_fx + transition_len, tlen3 ); // Qx - *previtd = itd; + *previtd = itd; // Q0 move16(); pop_wmops(); @@ -355,8 +355,8 @@ static void sincResample( static void sincResample_fx( const Word32 *input_fx, /*i : Input signal Qx */ Word32 *output_fx, /*o : Output signal Qx */ - const Word16 length_in, /*i : Input length */ - const Word16 length_out /*i : Output length */ + const Word16 length_in, /*i : Input length Q0 */ + const Word16 length_out /*i : Output length Q0 */ ) { Word16 snc0; @@ -366,7 +366,7 @@ static void sincResample_fx( Word16 t_step_e; Word32 t_frac_fx; Word16 t_frac_e; - Word64 tmp64_fx; + Word64 tmp64_fx; // Qx + 32 const Word32 *p_mid_fx; const Word32 *p_forward_fx; const Word32 *p_backward_fx; @@ -374,7 +374,7 @@ static void sincResample_fx( const Word32 *p_sinc_backward_fx; // epsilon: 1e-15f - const Word32 eps = 1208925824; + const Word32 eps = 1208925824; // exp(eps_e) move32(); const Word16 eps_e = -49; move16(); @@ -386,7 +386,7 @@ static void sincResample_fx( } /* Compute fractional time step */ - t_step_fx = L_deposit_h( BASOP_Util_Divide1616_Scale( length_in, length_out, &t_step_e ) ); + t_step_fx = L_deposit_h( BASOP_Util_Divide1616_Scale( length_in, length_out, &t_step_e ) ); // exp(t_step_e) t_frac_fx = 0; move32(); t_frac_e = 0; @@ -395,42 +395,42 @@ static void sincResample_fx( FOR( i = 0; i < length_out; i++ ) { Word16 t_frac_plus_eps_e; - Word32 t_frac_plus_eps = BASOP_Util_Add_Mant32Exp( t_frac_fx, t_frac_e, eps, eps_e, &t_frac_plus_eps_e ); - t = extract_l( L_shr( t_frac_plus_eps, sub( 31, t_frac_plus_eps_e ) ) ); // Q0 + Word32 t_frac_plus_eps = BASOP_Util_Add_Mant32Exp( t_frac_fx, t_frac_e, eps, eps_e, &t_frac_plus_eps_e ); // exp(t_frac_plus_eps_e) + t = extract_l( L_shr( t_frac_plus_eps, sub( 31, t_frac_plus_eps_e ) ) ); // Q0 /* Calculate the sinc-index for the center value of the sinc */ Word32 center_val; Word16 center_val_e; - center_val = BASOP_Util_Add_Mant32Exp( t_frac_plus_eps, t_frac_plus_eps_e, L_negate( L_deposit_h( t ) ), 15, ¢er_val_e ); - center_val_e = add( center_val_e, 6 ); // center_val * SFX_SPAT_BIN_NUM_SUBSAMPLES (i.e. 64) - center_val = BASOP_Util_Add_Mant32Exp( center_val, center_val_e, ONE_IN_Q29, 1, ¢er_val_e ); - snc0 = extract_l( L_shr( center_val, sub( 31, center_val_e ) ) ); + center_val = BASOP_Util_Add_Mant32Exp( t_frac_plus_eps, t_frac_plus_eps_e, L_negate( L_deposit_h( t ) ), 15, ¢er_val_e ); // exp(center_val_e) + center_val_e = add( center_val_e, 6 ); // center_val * SFX_SPAT_BIN_NUM_SUBSAMPLES (i.e. 64) + center_val = BASOP_Util_Add_Mant32Exp( center_val, center_val_e, ONE_IN_Q29, 1, ¢er_val_e ); // exp(center_val_e) + snc0 = extract_l( L_shr( center_val, sub( 31, center_val_e ) ) ); // Q0 /* Run convolution forward and backward from mid point */ - p_mid_fx = input_fx + t; - p_forward_fx = p_mid_fx + 1; - p_backward_fx = p_mid_fx - 1; - p_sinc_forward_fx = SincTable_fx + sub( SFX_SPAT_BIN_NUM_SUBSAMPLES, snc0 ); - p_sinc_backward_fx = SincTable_fx + add( SFX_SPAT_BIN_NUM_SUBSAMPLES, snc0 ); + p_mid_fx = input_fx + t; // Qx + p_forward_fx = p_mid_fx + 1; // Qx + p_backward_fx = p_mid_fx - 1; // Qx + p_sinc_forward_fx = SincTable_fx + sub( SFX_SPAT_BIN_NUM_SUBSAMPLES, snc0 ); // Q31 + p_sinc_backward_fx = SincTable_fx + add( SFX_SPAT_BIN_NUM_SUBSAMPLES, snc0 ); // Q31 - tmp64_fx = W_mult_32_32( *p_mid_fx, SincTable_fx[snc0] ); /* Middle point */ + tmp64_fx = W_mult_32_32( *p_mid_fx, SincTable_fx[snc0] ); /* Middle point */ // Qx + 32 FOR( j = 0; j < SFX_SPAT_BIN_SINC_M - 1; j++ ) { - tmp64_fx = W_add( tmp64_fx, W_mac_32_32( W_mult_32_32( *p_forward_fx, *p_sinc_forward_fx ), *p_backward_fx, *p_sinc_backward_fx ) ); - p_sinc_forward_fx += SFX_SPAT_BIN_NUM_SUBSAMPLES; - p_sinc_backward_fx += SFX_SPAT_BIN_NUM_SUBSAMPLES; - p_forward_fx++; - p_backward_fx--; + tmp64_fx = W_add( tmp64_fx, W_mac_32_32( W_mult_32_32( *p_forward_fx, *p_sinc_forward_fx ), *p_backward_fx, *p_sinc_backward_fx ) ); // Qx + 32 + p_sinc_forward_fx += SFX_SPAT_BIN_NUM_SUBSAMPLES; // Q31 + p_sinc_backward_fx += SFX_SPAT_BIN_NUM_SUBSAMPLES; // Q31 + p_forward_fx++; // Qx + p_backward_fx--; // Qx } - tmp64_fx = W_mac_32_32( tmp64_fx, *p_forward_fx, *p_sinc_forward_fx ); /* Integer index always rounded down --> 4 steps backward, 5 steps forward */ + tmp64_fx = W_mac_32_32( tmp64_fx, *p_forward_fx, *p_sinc_forward_fx ); /* Integer index always rounded down --> 4 steps backward, 5 steps forward */ // Qx + 32 - output_fx[i] = W_extract_h( tmp64_fx ); + output_fx[i] = W_extract_h( tmp64_fx ); // Qx move32(); /* Advance fractional time */ - t_frac_fx = BASOP_Util_Add_Mant32Exp( t_frac_fx, t_frac_e, t_step_fx, t_step_e, &t_frac_e ); + t_frac_fx = BASOP_Util_Add_Mant32Exp( t_frac_fx, t_frac_e, t_step_fx, t_step_e, &t_frac_e ); // exp( t_frac_fx ) } return; @@ -501,39 +501,39 @@ void TDREND_firfilt( #else void TDREND_firfilt_fx( Word32 *signal_fx, /* i/o: Input signal / Filtered signal Qx */ - Word32 *filter_fx, /* i/o: FIR filter Qy */ - const Word16 filter_e, /* i : FIR filter exp */ - const Word32 *filter_delta_fx, /* i : FIR filter delta Qy */ - const Word16 intp_count, /* i : interpolation count */ + Word32 *filter_fx, /* i/o: FIR filter filter_e */ + const Word16 filter_e, /* i : FIR filter exp Q0 */ + const Word32 *filter_delta_fx, /* i : FIR filter delta filter_e */ + const Word16 intp_count, /* i : interpolation count Q0 */ Word32 *mem_fx, /* i/o: filter memory Qx */ - const Word16 subframe_length, /* i : Length of signal */ - const Word16 filterlength, /* i : Filter length */ + const Word16 subframe_length, /* i : Length of signal Q0 */ + const Word16 filterlength, /* i : Filter length Q0 */ const Word16 Gain_fx, /* i : Gain Q14 */ const Word16 prevGain_fx /* i : Previous gain Q14 */ ) { /* NOTE: this function is implemented with the assumption that the exponent/Q-factor of input signal will not change. */ - Word32 buffer_fx[SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 + L_SUBFRAME5MS_48k]; - Word32 *p_signal_fx; - Word32 *p_tmp_fx; - Word32 *p_filter_fx; + Word32 buffer_fx[SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 + L_SUBFRAME5MS_48k]; // Qx + Word32 *p_signal_fx; // Qx + Word32 *p_tmp_fx; // Qx + Word32 *p_filter_fx; // exp(filter_e) Word16 i, j; Word32 tmp_fx; - Word16 step_fx, gain_tmp_fx, gain_delta_fx; + Word16 step_fx /* Q15 */, gain_tmp_fx /* Q15 */, gain_delta_fx /* Q14 */; Word16 tmp_e; Word64 tmp64_fx; - gain_delta_fx = sub( Gain_fx, prevGain_fx ); // Q14 - step_fx = BASOP_Util_Divide1616_Scale( gain_delta_fx, subframe_length, &tmp_e ); + gain_delta_fx = sub( Gain_fx, prevGain_fx ); // Q14 + step_fx = BASOP_Util_Divide1616_Scale( gain_delta_fx, subframe_length, &tmp_e ); // exp(tmp_e) tmp_e = sub( tmp_e, Q14 ); step_fx = shl_sat( step_fx, tmp_e ); // Q15 gain_tmp_fx = shl_sat( prevGain_fx, 1 ); // Q15 /* Handle memory */ - p_signal_fx = buffer_fx + sub( filterlength, 1 ); - Copy32( mem_fx, buffer_fx, sub( filterlength, 1 ) ); /* Insert memory */ - Copy32( signal_fx, buffer_fx + sub( filterlength, 1 ), subframe_length ); /* Insert current frame */ - Copy32( signal_fx + add( sub( subframe_length, filterlength ), 1 ), mem_fx, sub( filterlength, 1 ) ); /* Update memory for next frame */ + p_signal_fx = buffer_fx + sub( filterlength, 1 ); // Qx + Copy32( mem_fx, buffer_fx, sub( filterlength, 1 ) ); /* Insert memory */ // Qx + Copy32( signal_fx, buffer_fx + sub( filterlength, 1 ), subframe_length ); /* Insert current frame */ // Qx + Copy32( signal_fx + add( sub( subframe_length, filterlength ), 1 ), mem_fx, sub( filterlength, 1 ) ); /* Update memory for next frame */ // Qx /* Convolution */ FOR( i = 0; i < subframe_length; i++ ) @@ -542,28 +542,28 @@ void TDREND_firfilt_fx( move64(); tmp_e = 0; move16(); - p_tmp_fx = p_signal_fx + i; - p_filter_fx = filter_fx; + p_tmp_fx = p_signal_fx + i; // Qx + p_filter_fx = filter_fx; // exp(filter_e) FOR( j = 0; j < filterlength; j++ ) { - tmp64_fx = W_mac_32_32( tmp64_fx, *p_filter_fx, *p_tmp_fx ); - p_filter_fx++; - p_tmp_fx--; + tmp64_fx = W_mac_32_32( tmp64_fx, *p_filter_fx, *p_tmp_fx ); // Qx + (Q31 - filter_e) + 1 + p_filter_fx++; // exp(filter_e) + p_tmp_fx--; // Qx } // This is done to keep the output Q same as input Q for signal - tmp64_fx = W_shl( tmp64_fx, filter_e ); - tmp_fx = W_extract_h( tmp64_fx ); + tmp64_fx = W_shl( tmp64_fx, filter_e ); // Qx + 32 + tmp_fx = W_extract_h( tmp64_fx ); // Qx /* Apply linear gain interpolation in case of abrupt gain changes */ - gain_tmp_fx = add( gain_tmp_fx, step_fx ); - signal_fx[i] = Mpy_32_16_1( tmp_fx, gain_tmp_fx ); + gain_tmp_fx = add( gain_tmp_fx, step_fx ); // Q15 + signal_fx[i] = Mpy_32_16_1( tmp_fx, gain_tmp_fx ); // Qx move32(); IF( LT_16( i, intp_count ) ) { - v_add_fx( filter_fx, filter_delta_fx, filter_fx, filterlength ); + v_add_fx( filter_fx, filter_delta_fx, filter_fx, filterlength ); // exp(filter_e) } } diff --git a/lib_rend/ivas_objectRenderer_sources.c b/lib_rend/ivas_objectRenderer_sources.c index 066e7779622022b7d44bb3707a9a3f6eb2e8f8e7..c9d84191526360fd155fe4bd49d7ff786417ed57 100644 --- a/lib_rend/ivas_objectRenderer_sources.c +++ b/lib_rend/ivas_objectRenderer_sources.c @@ -72,7 +72,7 @@ static void TDREND_SRC_SPATIAL_Dealloc( TDREND_SRC_SPATIAL_t *SrcSpatial_p ); ivas_error TDREND_MIX_SRC_SetPos_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ const Word16 SrcInd, /* i : Source index */ - const Word32 *Vec_p /* i : Position vector */ + const Word32 *Vec_p /* i : Position vector Q25 */ ) { TDREND_SRC_SPATIAL_t *SrcSpatial_p; @@ -84,11 +84,11 @@ ivas_error TDREND_MIX_SRC_SetPos_fx( ELSE { SrcSpatial_p = hBinRendererTd->Sources[SrcInd]->SrcSpatial_p; - SrcSpatial_p->Pos_p_fx[0] = L_shr( SrcSpatial_p->Pos_p_fx[0], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); + SrcSpatial_p->Pos_p_fx[0] = L_shr( SrcSpatial_p->Pos_p_fx[0], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); // Q25 move32(); - SrcSpatial_p->Pos_p_fx[1] = L_shr( SrcSpatial_p->Pos_p_fx[1], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); + SrcSpatial_p->Pos_p_fx[1] = L_shr( SrcSpatial_p->Pos_p_fx[1], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); // Q25 move32(); - SrcSpatial_p->Pos_p_fx[2] = L_shr( SrcSpatial_p->Pos_p_fx[2], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); + SrcSpatial_p->Pos_p_fx[2] = L_shr( SrcSpatial_p->Pos_p_fx[2], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); // Q25 move32(); SrcSpatial_p->q_Pos_p = Q25; move16(); @@ -96,7 +96,7 @@ ivas_error TDREND_MIX_SRC_SetPos_fx( test(); IF( NE_32( SrcSpatial_p->Pos_p_fx[0], Vec_p[0] ) || NE_32( SrcSpatial_p->Pos_p_fx[1], Vec_p[1] ) || NE_32( SrcSpatial_p->Pos_p_fx[2], Vec_p[2] ) ) { - Copy32( Vec_p, SrcSpatial_p->Pos_p_fx, 3 ); + Copy32( Vec_p, SrcSpatial_p->Pos_p_fx, 3 ); // Q25 SrcSpatial_p->Updated = TRUE; move16(); } @@ -140,10 +140,10 @@ ivas_error TDREND_MIX_SRC_SetPos( --------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_MIX_SRC_SetDir_fx( - BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - const Word16 SrcInd, /* i : Source index */ - const Word32 *Vec_p, /* i : Direction vector */ - const Word16 Vec_p_q /* i : Direction vector q */ + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ + const Word16 SrcInd, /* i : Source index */ + const Word32 *Vec_p, /* i : Direction vector Vec_p_q */ + const Word16 Vec_p_q /* i : Direction vector q */ ) { TDREND_SRC_SPATIAL_t *SrcSpatial_p; @@ -204,8 +204,8 @@ ivas_error TDREND_MIX_SRC_SetDir( --------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_MIX_SRC_SetDirAtten_fx( - BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - const Word16 SrcInd, /* i : Source index */ + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ + const Word16 SrcInd, /* i : Source index Q0 */ const TDREND_DirAtten_t *DirAtten_p /* i : Directional attenuation specifier */ ) { @@ -253,8 +253,8 @@ ivas_error TDREND_MIX_SRC_SetDirAtten( #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_MIX_SRC_SetPlayState( - BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - const Word16 SrcInd, /* i : Source index */ + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ + const Word16 SrcInd, /* i : Source index Q0 */ const TDREND_PlayStatus_t PlayStatus /* i : Play state */ ) { @@ -334,11 +334,11 @@ static void TDREND_SRC_REND_Init_fx( /* SrcGain */ FOR( nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) { - SrcRend_p->SrcGainMin_p_fx[nC] = 0; /*Assuming Q15*/ + SrcRend_p->SrcGainMin_p_fx[nC] = 0; /* Q15 */ move16(); - SrcRend_p->SrcGain_p_fx[nC] = ONE_IN_Q14; + SrcRend_p->SrcGain_p_fx[nC] = ONE_IN_Q14; // Q14 move16(); - SrcRend_p->SrcGainMax_p_fx[nC] = 32767; /*Assuming Q15*/ + SrcRend_p->SrcGainMax_p_fx[nC] = 32767; /* Q15 */ move16(); } SrcRend_p->SrcGainUpdated = FALSE; @@ -346,9 +346,9 @@ static void TDREND_SRC_REND_Init_fx( /* Init directional and distance gains */ FOR( nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) { - SrcRend_p->DirGain_p_fx[nC] = ONE_IN_Q14; + SrcRend_p->DirGain_p_fx[nC] = ONE_IN_Q14; // Q14 move16(); - SrcRend_p->DistGain_p_fx[nC] = ONE_IN_Q14; + SrcRend_p->DistGain_p_fx[nC] = ONE_IN_Q14; // Q14 move16(); } return; @@ -520,19 +520,31 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ TDREND_SRC_REND_t *SrcRend_p, /* i/o: Source object */ TDREND_SRC_SPATIAL_t *SrcSpatial_p, /* i : Spatial aspects of source */ - Word32 *hrf_left_prev, /* i/o: Left filter */ - Word16 *hrf_left_prev_e, /* i/o: Left filter exponent */ - Word32 *hrf_right_prev, /* i/o: Right filter */ - Word16 *hrf_right_prev_e, /* i/o: Right filter exponent */ - Word32 *hrf_left_delta, /* o : Left filter interpolation delta */ - Word16 *hrf_left_delta_e, /* o : Left filter interpolation delta exponent */ - Word32 *hrf_right_delta, /* o : Right filter interpolation delta */ - Word16 *hrf_right_delta_e, /* o : Right filter interpolation delta exponent */ - Word16 *intp_count, /* o : Interpolation count */ - Word16 *filterlength, /* o : Length of filters */ - Word16 *itd, /* o : ITD value */ - Word16 *Gain, /* o : Gain value */ - TDREND_SRC_t *Src_p, /* i/o: Source pointer */ + Word32 *hrf_left_prev, + /* i/o: Left filter */ // exp(hrf_left_prev_e) + Word16 *hrf_left_prev_e, + /* i/o: Left filter exponent */ // Q0 + Word32 *hrf_right_prev, + /* i/o: Right filter */ // exp(hrf_right_prev_e) + Word16 *hrf_right_prev_e, + /* i/o: Right filter exponent */ // Q0 + Word32 *hrf_left_delta, + /* o : Left filter interpolation delta */ // exp(hrf_left_delta_e) + Word16 *hrf_left_delta_e, + /* o : Left filter interpolation delta exponent */ // Q0 + Word32 *hrf_right_delta, + /* o : Right filter interpolation delta */ // exp(hrf_right_delta_e) + Word16 *hrf_right_delta_e, + /* o : Right filter interpolation delta exponent */ // Q0 + Word16 *intp_count, + /* o : Interpolation count */ // Q0 + Word16 *filterlength, + /* o : Length of filters */ // Q0 + Word16 *itd, + /* o : ITD value */ // Q0 + Word16 *Gain, + /* o : Gain value */ // Q14 + TDREND_SRC_t *Src_p, /* i/o: Source pointer */ const Word16 subframe_update_flag ) { TDREND_MIX_Listener_t *Listener_p; @@ -552,7 +564,7 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( Listener_p = hBinRendererTd->Listener_p; HrFiltSet_p = hBinRendererTd->HrFiltSet_p; - *filterlength = s_min( HrFiltSet_p->FiltLength, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); + *filterlength = s_min( HrFiltSet_p->FiltLength, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); // Q0 move16(); IF( EQ_16( SrcSpatial_p->PosType, TDREND_POSTYPE_ABSOLUTE ) ) { @@ -575,16 +587,16 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( } ELSE { - Word32 tmp1 = Mpy_32_32( ListRelPos[0], ListRelPos[0] ); - Word32 tmp2 = Mpy_32_32( ListRelPos[1], ListRelPos[1] ); - Word32 tmp3 = L_add( tmp1, tmp2 ); + Word32 tmp1 = Mpy_32_32( ListRelPos[0], ListRelPos[0] ); // exp(2*ListRelPos_e) + Word32 tmp2 = Mpy_32_32( ListRelPos[1], ListRelPos[1] ); // exp(2*ListRelPos_e) + Word32 tmp3 = L_add( tmp1, tmp2 ); // exp(2*ListRelPos_e) Word16 tmp_e = shl( ListRelPos_e, 1 ); - Word32 tmp4 = Sqrt32( tmp3, &tmp_e ); - Word16 tmp5 = BASOP_util_atan2( ListRelPos[2], tmp4, sub( ListRelPos_e, tmp_e ) ); - Word32 tmp6 = Mpy_32_16_1( _180_OVER_PI_Q25, tmp5 ); // Q25 + Q13 - Q15 = Q23 + Word32 tmp4 = Sqrt32( tmp3, &tmp_e ); // exp(tmp_e) + Word16 tmp5 = BASOP_util_atan2( ListRelPos[2], tmp4, sub( ListRelPos_e, tmp_e ) ); // Q13 + Word32 tmp6 = Mpy_32_16_1( _180_OVER_PI_Q25, tmp5 ); // Q25 + Q13 - Q15 = Q23 /* Basis set is [front, right, up], which is a left-handed coordinate system. Minus sign here is to change to a positive-left system for azimuth */ - Word16 tmp7 = BASOP_util_atan2( ListRelPos[1], ListRelPos[0], 0 ); - Word32 tmp8 = L_negate( Mpy_32_16_1( _180_OVER_PI_Q25, tmp7 ) ); // Q25 + Q13 - Q15 = Q23 + Word16 tmp7 = BASOP_util_atan2( ListRelPos[1], ListRelPos[0], 0 ); // Q13 + Word32 tmp8 = L_negate( Mpy_32_16_1( _180_OVER_PI_Q25, tmp7 ) ); // Q25 + Q13 - Q15 = Q23 Elev = L_shr( tmp6, 1 ); // Q22 Azim = L_shr( tmp8, 1 ); // Q22 @@ -594,7 +606,7 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( /* 6. Evaluate the directional and distance gains */ /* Directional gain */ - *SrcRend_p->DirGain_p_fx = ONE_IN_Q14; + *SrcRend_p->DirGain_p_fx = ONE_IN_Q14; // Q14 move16(); IF( SrcSpatial_p->DirAttenEnabled ) { @@ -602,7 +614,7 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( } /* Distance gain */ - *SrcRend_p->DistGain_p_fx = ONE_IN_Q14; + *SrcRend_p->DistGain_p_fx = ONE_IN_Q14; // Q14 move16(); IF( hBinRendererTd->UseCommonDistAttenModel ) { @@ -610,69 +622,69 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( { SrcSpatial_p->DistAtten.DistAttenModel = hBinRendererTd->DistAttenModel; move32(); - *SrcRend_p->DistGain_p_fx = TDREND_SRC_SPATIAL_GetDistGain_fx( &SrcSpatial_p->DistAtten, ListRelDist, ListRelDist_e ); + *SrcRend_p->DistGain_p_fx = TDREND_SRC_SPATIAL_GetDistGain_fx( &SrcSpatial_p->DistAtten, ListRelDist, ListRelDist_e ); // Q14 move32(); } } ELSE IF( SrcSpatial_p->DistAttenEnabled ) { - *SrcRend_p->DistGain_p_fx = TDREND_SRC_SPATIAL_GetDistGain_fx( &SrcSpatial_p->DistAtten, ListRelDist, ListRelDist_e ); + *SrcRend_p->DistGain_p_fx = TDREND_SRC_SPATIAL_GetDistGain_fx( &SrcSpatial_p->DistAtten, ListRelDist, ListRelDist_e ); // Q14 move32(); } /* Update total gains */ - *Gain = extract_h( L_shl( Mpy_32_32( L_shl( L_mult( *SrcRend_p->SrcGain_p_fx, *SrcRend_p->DirGain_p_fx ), 1 ), L_shl( L_mult( *SrcRend_p->DistGain_p_fx, hBinRendererTd->Gain_fx ), 1 ) ), 1 ) ); + *Gain = extract_h( L_shl( Mpy_32_32( L_shl( L_mult( *SrcRend_p->SrcGain_p_fx, *SrcRend_p->DirGain_p_fx ), 1 ), L_shl( L_mult( *SrcRend_p->DistGain_p_fx, hBinRendererTd->Gain_fx ), 1 ) ), 1 ) ); // Q14 move16(); /* Delta for interpolation, in case the angular step exceeds MAX_ANGULAR_STEP */ - Word32 ele_tmp = Src_p->elev_prev_fx; + Word32 ele_tmp = Src_p->elev_prev_fx; // Q22 move32(); IF( GT_32( ele_tmp, DEG_180_IN_Q22 ) ) { - ele_tmp = L_sub( ele_tmp, DEG_360_IN_Q22 ); + ele_tmp = L_sub( ele_tmp, DEG_360_IN_Q22 ); // Q22 } ELSE IF( LT_32( ele_tmp, -DEG_180_IN_Q22 ) ) { - ele_tmp = L_add( ele_tmp, DEG_360_IN_Q22 ); + ele_tmp = L_add( ele_tmp, DEG_360_IN_Q22 ); // Q22 } - elev_delta = L_sub( Elev, ele_tmp ); + elev_delta = L_sub( Elev, ele_tmp ); // Q22 - Word32 azi_tmp = Src_p->azim_prev_fx; + Word32 azi_tmp = Src_p->azim_prev_fx; // Q22 IF( GT_32( azi_tmp, DEG_180_IN_Q22 ) ) { - azi_tmp = L_sub( azi_tmp, DEG_360_IN_Q22 ); + azi_tmp = L_sub( azi_tmp, DEG_360_IN_Q22 ); // Q22 } ELSE IF( LT_32( azi_tmp, -DEG_180_IN_Q22 ) ) { - azi_tmp = L_add( azi_tmp, DEG_360_IN_Q22 ); + azi_tmp = L_add( azi_tmp, DEG_360_IN_Q22 ); // Q22 } - azim_delta = L_sub( Azim, azi_tmp ); + azim_delta = L_sub( Azim, azi_tmp ); // Q22 - Src_p->elev_prev_fx = Elev; + Src_p->elev_prev_fx = Elev; // Q22 move32(); - Src_p->azim_prev_fx = Azim; + Src_p->azim_prev_fx = Azim; // Q22 move32(); /* map to -180:180 range */ IF( GT_32( azim_delta, DEG_180_IN_Q22 ) ) { - azim_delta = L_sub( azim_delta, DEG_360_IN_Q22 ); + azim_delta = L_sub( azim_delta, DEG_360_IN_Q22 ); // Q22 } ELSE IF( LT_32( azim_delta, -DEG_180_IN_Q22 ) ) { - azim_delta = L_add( azim_delta, DEG_360_IN_Q22 ); + azim_delta = L_add( azim_delta, DEG_360_IN_Q22 ); // Q22 } Word16 tmp1 = extract_l( Mpy_32_32( L_abs( azim_delta ), 100 << Q9 ) ); // Q22 + Q9 - Q31 = Q0 Word16 tmp2 = extract_l( Mpy_32_32( L_abs( elev_delta ), 100 << Q9 ) ); // Q22 + Q9 - Q31 = Q0 - *intp_count = s_min( MAX_INTERPOLATION_STEPS, s_max( tmp1, tmp2 ) ); + *intp_count = s_min( MAX_INTERPOLATION_STEPS, s_max( tmp1, tmp2 ) ); // Q0 move16(); } ELSE /* TDREND_POSTYPE_NON_DIEGETIC */ { - *itd = 0; + *itd = 0; // Q0 move16(); - *Gain = ONE_IN_Q14; + *Gain = ONE_IN_Q14; // Q14 move16(); set32_fx( hrf_left, 0, *filterlength ); set32_fx( hrf_right, 0, *filterlength ); @@ -684,11 +696,11 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( move16(); hrf_right_e = 6; move16(); - *intp_count = MAX_INTERPOLATION_STEPS; + *intp_count = MAX_INTERPOLATION_STEPS; // Q22 move16(); - Src_p->elev_prev_fx = 0; + Src_p->elev_prev_fx = 0; // Q22 move16(); - Src_p->azim_prev_fx = DEG_360_IN_Q22; /* Dummy angle -- sets max interpolation if switching to TDREND_POSTYPE_ABSOLUTE */ + Src_p->azim_prev_fx = DEG_360_IN_Q22; /* Dummy angle -- sets max interpolation if switching to TDREND_POSTYPE_ABSOLUTE */ // Q22 move16(); } @@ -700,47 +712,47 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( tmp_e = s_max( *hrf_left_prev_e, hrf_left_e ); FOR( Word16 i = 0; i < *filterlength; i++ ) { - hrf_left[i] = L_shr( hrf_left[i], sub( tmp_e, hrf_left_e ) ); + hrf_left[i] = L_shr( hrf_left[i], sub( tmp_e, hrf_left_e ) ); // exp(tmp_e) move32(); - hrf_left_prev[i] = L_shr( hrf_left_prev[i], sub( tmp_e, *hrf_left_prev_e ) ); + hrf_left_prev[i] = L_shr( hrf_left_prev[i], sub( tmp_e, *hrf_left_prev_e ) ); // exp(tmp_e) move32(); } *hrf_left_prev_e = tmp_e; move16(); hrf_left_e = tmp_e; move16(); - v_sub_32( hrf_left, hrf_left_prev, hrf_left_delta, *filterlength ); + v_sub_32( hrf_left, hrf_left_prev, hrf_left_delta, *filterlength ); // exp(tmp_e) *hrf_left_delta_e = tmp_e; move16(); - Word32 fac = L_deposit_h( div_s( 1, *intp_count ) ); - v_multc_fixed( hrf_left_delta, fac, hrf_left_delta, *filterlength ); + Word32 fac = L_deposit_h( div_s( 1, *intp_count ) ); // Q15 + v_multc_fixed( hrf_left_delta, fac, hrf_left_delta, *filterlength ); // exp(hrf_left_delta_e) tmp_e = s_max( *hrf_right_prev_e, hrf_right_e ); FOR( Word16 i = 0; i < *filterlength; i++ ) { - hrf_right[i] = L_shr( hrf_right[i], sub( tmp_e, hrf_right_e ) ); + hrf_right[i] = L_shr( hrf_right[i], sub( tmp_e, hrf_right_e ) ); // exp(tmp_e) move32(); - hrf_right_prev[i] = L_shr( hrf_right_prev[i], sub( tmp_e, *hrf_right_prev_e ) ); + hrf_right_prev[i] = L_shr( hrf_right_prev[i], sub( tmp_e, *hrf_right_prev_e ) ); // exp(tmp_e) move32(); } *hrf_right_prev_e = tmp_e; move16(); hrf_right_e = tmp_e; move16(); - v_sub_32( hrf_right, hrf_right_prev, hrf_right_delta, *filterlength ); + v_sub_32( hrf_right, hrf_right_prev, hrf_right_delta, *filterlength ); // exp(hrf_right_delta_e) *hrf_right_delta_e = tmp_e; move16(); - v_multc_fixed( hrf_right_delta, fac, hrf_right_delta, *filterlength ); + v_multc_fixed( hrf_right_delta, fac, hrf_right_delta, *filterlength ); // exp(hrf_right_delta_e) } ELSE { /* No interpolation, just set the new filters and reset deltas */ - Copy32( hrf_left, hrf_left_prev, *filterlength ); + Copy32( hrf_left, hrf_left_prev, *filterlength ); // exp(hrf_left_prev_e) *hrf_left_prev_e = hrf_left_e; move16(); - Copy32( hrf_right, hrf_right_prev, *filterlength ); + Copy32( hrf_right, hrf_right_prev, *filterlength ); // exp(hrf_right_prev_e) *hrf_right_prev_e = hrf_right_e; move16(); set32_fx( hrf_left_delta, 0, *filterlength ); @@ -830,7 +842,7 @@ static void TDREND_SRC_SPATIAL_Init_fx( const TDREND_PosType_t PosType /* i : Relative/absolute position type */ ) { - Word16 nC; + Word16 nC; // Q0 /* Initialize variables */ SrcSpatial_p->Updated = FALSE; @@ -854,25 +866,25 @@ static void TDREND_SRC_SPATIAL_Init_fx( #endif /* Source directional attenuation */ - SrcSpatial_p->DirAttenEnabled = FALSE; + SrcSpatial_p->DirAttenEnabled = FALSE; // Q0 move16(); - SrcSpatial_p->DirAtten.ConeInnerAngle_fx = DEG_360_IN_Q22; + SrcSpatial_p->DirAtten.ConeInnerAngle_fx = DEG_360_IN_Q22; // Q22 move32(); - SrcSpatial_p->DirAtten.ConeOuterAngle_fx = DEG_360_IN_Q22; + SrcSpatial_p->DirAtten.ConeOuterAngle_fx = DEG_360_IN_Q22; // Q22 move32(); - SrcSpatial_p->DirAtten.ConeOuterGain_fx = ONE_IN_Q30; + SrcSpatial_p->DirAtten.ConeOuterGain_fx = ONE_IN_Q30; // Q30 move16(); /* Source distance attenuation */ - SrcSpatial_p->DistAttenEnabled = FALSE; + SrcSpatial_p->DistAttenEnabled = FALSE; // Q0 move16(); - SrcSpatial_p->DistAtten.DistAttenModel = TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED; + SrcSpatial_p->DistAtten.DistAttenModel = TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED; // Q0 move16(); - SrcSpatial_p->DistAtten.RefDist_fx = ONE_IN_Q30; + SrcSpatial_p->DistAtten.RefDist_fx = ONE_IN_Q30; // Q30 move32(); SrcSpatial_p->DistAtten.MaxDist_fx = 2113929216; /* Maximum radius (2^ISM_RADIUS_NBITS-1)*0.25 */ /*15.75 in Q27*/ move32(); - SrcSpatial_p->DistAtten.RollOffFactor_fx = ONE_IN_Q30; + SrcSpatial_p->DistAtten.RollOffFactor_fx = ONE_IN_Q30; // Q30 move16(); return; @@ -928,10 +940,10 @@ static void TDREND_SRC_SPATIAL_SetDirAtten_fx( ) { /* Set directional attenuation */ - SrcSpatial_p->DirAttenEnabled = TRUE; - SrcSpatial_p->DirAtten.ConeInnerAngle_fx = DirAtten_p->ConeInnerAngle_fx; - SrcSpatial_p->DirAtten.ConeOuterAngle_fx = DirAtten_p->ConeOuterAngle_fx; - SrcSpatial_p->DirAtten.ConeOuterGain_fx = DirAtten_p->ConeOuterGain_fx; + SrcSpatial_p->DirAttenEnabled = TRUE; // Q0 + SrcSpatial_p->DirAtten.ConeInnerAngle_fx = DirAtten_p->ConeInnerAngle_fx; // Q22 + SrcSpatial_p->DirAtten.ConeOuterAngle_fx = DirAtten_p->ConeOuterAngle_fx; // Q22 + SrcSpatial_p->DirAtten.ConeOuterGain_fx = DirAtten_p->ConeOuterGain_fx; // Q30 move16(); move16(); move16(); @@ -1008,9 +1020,9 @@ static float TDREND_SRC_SPATIAL_GetDirGain( #else static Word16 TDREND_SRC_SPATIAL_GetDirGain_fx( /* o : Directional Gain Output Q14 */ const TDREND_DirAtten_t *DirAtten_p, /* i : Directional attenuation specification */ - const Word32 *Front_p_fx, /* i : Front-pointing vector */ + const Word32 *Front_p_fx, /* i : Front-pointing vector Q30 */ const Word32 *RelPos_p_fx, /* i : Relative position */ - const Word16 RelPos_p_e /* i : Relative position exp */ + const Word16 RelPos_p_e /* i : Relative position exp RelPos_p_e */ ) { Word16 DirGain_fx; // Q14 @@ -1028,12 +1040,12 @@ static Word16 TDREND_SRC_SPATIAL_GetDirGain_fx( /* Angle = acos ( Proj coeff from projecting -RelPos onto Front / norm(RelPos) ); */ FOR( Word16 i = 0; i < 3; i++ ) { - Vec_fx[i] = L_negate( RelPos_p_fx[i] ); + Vec_fx[i] = L_negate( RelPos_p_fx[i] ); // exp(RelPos_p_e) move32(); } ProjCoef_fx = dotp_fixed( Vec_fx, Front_p_fx, 3 ); // exp: RelPos_p_e + 1 ProjCoef_e = add( RelPos_p_e, 1 ); - NormRelPos_fx = TDREND_SPATIAL_VecNorm_fx( RelPos_p_fx, RelPos_p_e, &NormRelPos_e ); + NormRelPos_fx = TDREND_SPATIAL_VecNorm_fx( RelPos_p_fx, RelPos_p_e, &NormRelPos_e ); // exp(NormRelPos_e) IF( NormRelPos_fx != 0 ) { @@ -1043,15 +1055,15 @@ static Word16 TDREND_SRC_SPATIAL_GetDirGain_fx( Word32 tmp1, tmp2, tmp3, tmp4; // acos(x/y) = atan( sqrt(1-(x/y)^2) / (x/y) ) - tmp1 = L_deposit_h( BASOP_Util_Divide3232_Scale( ProjCoef_fx, NormRelPos_fx, &tmp_e1 ) ); // x/y + tmp1 = L_deposit_h( BASOP_Util_Divide3232_Scale( ProjCoef_fx, NormRelPos_fx, &tmp_e1 ) ); // x/y /* exp(tmp_e1) */ tmp_e1 = add( tmp_e1, sub( ProjCoef_e, NormRelPos_e ) ); - tmp2 = Mpy_32_32( tmp1, tmp1 ); // (x/y)^2 + tmp2 = Mpy_32_32( tmp1, tmp1 ); // (x/y)^2 /* exp(tmp_e2 */ tmp_e2 = shl( tmp_e1, 1 ); - tmp3 = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( tmp2 ), tmp_e2, &tmp_e3 ); // 1 - (x/y)^2 + tmp3 = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( tmp2 ), tmp_e2, &tmp_e3 ); // 1 - (x/y)^2 /* exp(tmp_e3) */ tmp_e4 = tmp_e3; move16(); tmp3 = L_abs( tmp3 ); // for safety: sometimes it can go negative due to slight precision difference between numerator and denominator. - tmp4 = Sqrt32( tmp3, &tmp_e4 ); // sqrt(1 - (x/y)^2) + tmp4 = Sqrt32( tmp3, &tmp_e4 ); // sqrt(1 - (x/y)^2) /* exp(tmp_e4) */ acosfx = BASOP_util_atan2( tmp4, tmp1, sub( tmp_e4, tmp_e1 ) ); // 2Q13 AngleDeg_fx = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, acosfx ), 1 ); // Q22 } @@ -1063,21 +1075,21 @@ static Word16 TDREND_SRC_SPATIAL_GetDirGain_fx( IF( LE_32( AngleDeg_fx, L_shr( DirAtten_p->ConeInnerAngle_fx, 1 ) ) ) { - DirGain_fx = ONE_IN_Q14; + DirGain_fx = ONE_IN_Q14; // Q14 move16(); } ELSE IF( LE_32( AngleDeg_fx, L_shr( DirAtten_p->ConeOuterAngle_fx, 1 ) ) ) { // DirGain = 1.0f - ( 2.0f * AngleDeg - DirAtten_p->ConeInnerAngle ) / ( DirAtten_p->ConeOuterAngle - DirAtten_p->ConeInnerAngle ) * ( 1.0f - DirAtten_p->ConeOuterGain ); Word32 tmp1, tmp2, tmp3; - tmp1 = L_sub( ONE_IN_Q30, DirAtten_p->ConeOuterGain_fx ); - tmp2 = L_sub( DirAtten_p->ConeOuterAngle_fx, DirAtten_p->ConeInnerAngle_fx ); - tmp3 = L_sub( L_shl( AngleDeg_fx, 1 ), DirAtten_p->ConeInnerAngle_fx ); - DirGain_fx = sub( ONE_IN_Q14, div_l( Mpy_32_32( tmp1, tmp3 ), extract_h( tmp2 ) ) ); + tmp1 = L_sub( ONE_IN_Q30, DirAtten_p->ConeOuterGain_fx ); // Q30 + tmp2 = L_sub( DirAtten_p->ConeOuterAngle_fx, DirAtten_p->ConeInnerAngle_fx ); // Q22 + tmp3 = L_sub( L_shl( AngleDeg_fx, 1 ) /* 2.0f * AngleDeg */, DirAtten_p->ConeInnerAngle_fx ); // Q22 + DirGain_fx = sub( ONE_IN_Q14, div_l( Mpy_32_32( tmp1, tmp3 ), extract_h( tmp2 ) ) ); // Q14 } ELSE { - DirGain_fx = extract_h( DirAtten_p->ConeOuterGain_fx ); + DirGain_fx = extract_h( DirAtten_p->ConeOuterGain_fx ); // Q14 } return DirGain_fx; @@ -1131,11 +1143,11 @@ static float TDREND_SRC_SPATIAL_GetDistGain( #else static Word16 TDREND_SRC_SPATIAL_GetDistGain_fx( /* o : Distance gain Q14 */ const TDREND_DistAtten_t *DistAtten_p, /* i : Distance attenuation parameters */ - const Word32 Dist_fx, /* i : Distance value */ + const Word32 Dist_fx, /* i : Distance value Dist_e */ const Word16 Dist_e /* i : Distance value exp */ ) { - Word16 DistGain_fx; + Word16 DistGain_fx; // Q14 Word32 Dist2_fx; Word16 Dist2_e; Word16 tmp_e; @@ -1143,7 +1155,7 @@ static Word16 TDREND_SRC_SPATIAL_GetDistGain_fx( Word32 tmp32; Word16 flag; - DistGain_fx = ONE_IN_Q14; + DistGain_fx = ONE_IN_Q14; // Q14 move16(); DistGain_e = 1; move16(); @@ -1158,7 +1170,7 @@ static Word16 TDREND_SRC_SPATIAL_GetDistGain_fx( tmp32 = BASOP_Util_Add_Mant32Exp( Dist2_fx, Dist2_e, L_negate( DistAtten_p->RefDist_fx ), 1, &tmp_e ); // exp: tmp_e tmp32 = Mpy_32_32( tmp32, DistAtten_p->RollOffFactor_fx ); // exp: 1 + tmp_e tmp32 = BASOP_Util_Add_Mant32Exp( DistAtten_p->RefDist_fx, 1, tmp32, add( 1, tmp_e ), &tmp_e ); // exp: tmp_e - DistGain_fx = BASOP_Util_Divide3232_Scale( DistAtten_p->RefDist_fx, tmp32, &DistGain_e ); + DistGain_fx = BASOP_Util_Divide3232_Scale( DistAtten_p->RefDist_fx, tmp32, &DistGain_e ); // exp: DistGain_e DistGain_e = add( DistGain_e, sub( 1, tmp_e ) ); BREAK; @@ -1166,7 +1178,7 @@ static Word16 TDREND_SRC_SPATIAL_GetDistGain_fx( flag = BASOP_Util_Cmp_Mant32Exp( Dist2_fx, Dist2_e, DistAtten_p->RefDist_fx, 1 ); IF( flag < 0 ) { - Dist2_fx = DistAtten_p->RefDist_fx; + Dist2_fx = DistAtten_p->RefDist_fx; // Q30 move32(); Dist2_e = 1; move16(); @@ -1174,7 +1186,7 @@ static Word16 TDREND_SRC_SPATIAL_GetDistGain_fx( flag = BASOP_Util_Cmp_Mant32Exp( Dist2_fx, Dist2_e, DistAtten_p->MaxDist_fx, 4 ); IF( flag > 0 ) { - Dist2_fx = DistAtten_p->MaxDist_fx; + Dist2_fx = DistAtten_p->MaxDist_fx; // Q27 move32(); Dist2_e = 4; move16(); @@ -1182,7 +1194,7 @@ static Word16 TDREND_SRC_SPATIAL_GetDistGain_fx( tmp32 = BASOP_Util_Add_Mant32Exp( Dist2_fx, Dist2_e, L_negate( DistAtten_p->RefDist_fx ), 1, &tmp_e ); // exp: tmp_e tmp32 = Mpy_32_32( tmp32, DistAtten_p->RollOffFactor_fx ); // exp: 1 + tmp_e tmp32 = BASOP_Util_Add_Mant32Exp( DistAtten_p->RefDist_fx, 1, tmp32, add( 1, tmp_e ), &tmp_e ); // exp: tmp_e - DistGain_fx = BASOP_Util_Divide3232_Scale( DistAtten_p->RefDist_fx, tmp32, &DistGain_e ); + DistGain_fx = BASOP_Util_Divide3232_Scale( DistAtten_p->RefDist_fx, tmp32, &DistGain_e ); // exp: DistGain_e DistGain_e = add( DistGain_e, sub( 1, tmp_e ) ); BREAK; @@ -1339,11 +1351,11 @@ void TDREND_SRC_Init_fx( TDREND_SRC_REND_Init_fx( Src_p->SrcRend_p ); /* Reset memory buffers */ - Src_p->itd = 0; + Src_p->itd = 0; // Q0 move16(); - Src_p->previtd = 0; + Src_p->previtd = 0; // Q0 move16(); - Src_p->filterlength = 1; /* Init to unit impulse of length 1 */ + Src_p->filterlength = 1; /* Init to unit impulse of length 1 */ // Q0 move16(); set32_fx( Src_p->mem_itd_fx, 0, ITD_MEM_LEN ); set32_fx( Src_p->mem_hrf_left_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 ); @@ -1351,21 +1363,21 @@ void TDREND_SRC_Init_fx( set32_fx( Src_p->hrf_left_prev_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); set32_fx( Src_p->hrf_right_prev_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); - Src_p->hrf_left_prev_fx[0] = ONE_IN_Q30; + Src_p->hrf_left_prev_fx[0] = ONE_IN_Q30; // Q30 move32(); Src_p->hrf_left_prev_e = 1; move16(); - Src_p->hrf_right_prev_fx[0] = ONE_IN_Q30; + Src_p->hrf_right_prev_fx[0] = ONE_IN_Q30; // Q30 move32(); Src_p->hrf_right_prev_e = 1; move16(); - Src_p->azim_prev_fx = 0; + Src_p->azim_prev_fx = 0; // Q22 move32(); - Src_p->elev_prev_fx = 0; + Src_p->elev_prev_fx = 0; // Q22 move32(); - Src_p->Gain_fx = ONE_IN_Q14; + Src_p->Gain_fx = ONE_IN_Q14; // Q14 move16(); - Src_p->prevGain_fx = ONE_IN_Q14; + Src_p->prevGain_fx = ONE_IN_Q14; // Q14 move16(); return; } diff --git a/lib_rend/ivas_objectRenderer_vec.c b/lib_rend/ivas_objectRenderer_vec.c index 5491d10bcdf5e1192dd4800ad38cd2bb922da039..a83637fc2cdb8863bb18b5c3945ac2109ac1bbe0 100644 --- a/lib_rend/ivas_objectRenderer_vec.c +++ b/lib_rend/ivas_objectRenderer_vec.c @@ -142,7 +142,7 @@ void TDREND_SPATIAL_VecNormalize( #ifdef IVAS_FLOAT_FIXED void TDREND_SPATIAL_VecNormalize_fx( - const Word32 *Vec_p_fx, /* i : Input vector Qx */ + const Word32 *Vec_p_fx, /* i : Input vector q */ Word16 q, /* i : Input vector Q-factor */ Word32 *VecNorm_p_fx /* o : Normalised output vector Q30 */ ) @@ -155,21 +155,21 @@ void TDREND_SPATIAL_VecNormalize_fx( exp = shl( sub( 31, q ), 1 ); scaler_fx = ISqrt32( sqrd_sum, &exp ); - VecNorm_p_fx[0] = Mpy_32_32( scaler_fx, Vec_p_fx[0] ); + VecNorm_p_fx[0] = Mpy_32_32( scaler_fx, Vec_p_fx[0] ); // Q: ( q + ( 31 - exp ) ) - 31 move32(); - VecNorm_p_fx[1] = Mpy_32_32( scaler_fx, Vec_p_fx[1] ); + VecNorm_p_fx[1] = Mpy_32_32( scaler_fx, Vec_p_fx[1] ); // Q: ( q + ( 31 - exp ) ) - 31 move32(); - VecNorm_p_fx[2] = Mpy_32_32( scaler_fx, Vec_p_fx[2] ); + VecNorm_p_fx[2] = Mpy_32_32( scaler_fx, Vec_p_fx[2] ); // Q: ( q + ( 31 - exp ) ) - 31 move32(); exp = add( exp, sub( 31, q ) ); // Since vector is normalised, all values will be <= 1. Hence making all values in Q30 shift = sub( exp, 1 ); - VecNorm_p_fx[0] = L_shl( VecNorm_p_fx[0], shift ); + VecNorm_p_fx[0] = L_shl( VecNorm_p_fx[0], shift ); // Q30 move32(); - VecNorm_p_fx[1] = L_shl( VecNorm_p_fx[1], shift ); + VecNorm_p_fx[1] = L_shl( VecNorm_p_fx[1], shift ); // Q30 move32(); - VecNorm_p_fx[2] = L_shl( VecNorm_p_fx[2], shift ); + VecNorm_p_fx[2] = L_shl( VecNorm_p_fx[2], shift ); // Q30 move32(); return; @@ -197,11 +197,11 @@ void TDREND_SPATIAL_VecMapToNewCoordSystem_fx( v_sub_32( Vec_p, TranslVec_p, LisRelPosAbs, 3 ); /* Evalute the relative Vec in the coordinates of the Orientation vectors, */ /* which form an orthonormal basis */ - MappedVec_p[0] = dotp_fixed( LisRelPosAbs, DirVec_p, 3 ); + MappedVec_p[0] = dotp_fixed( LisRelPosAbs, DirVec_p, 3 ); // Q: Qy + Qy - Q31 move32(); - MappedVec_p[1] = dotp_fixed( LisRelPosAbs, RightVec_p, 3 ); + MappedVec_p[1] = dotp_fixed( LisRelPosAbs, RightVec_p, 3 ); // Q: Qy + Qy - Q31 move32(); - MappedVec_p[2] = dotp_fixed( LisRelPosAbs, UpVec_p, 3 ); + MappedVec_p[2] = dotp_fixed( LisRelPosAbs, UpVec_p, 3 ); // Q: Qy + Qy - Q31 move32(); return; } @@ -285,15 +285,15 @@ int16_t TDREND_SPATIAL_EvalOrthonormOrient( #ifdef IVAS_FLOAT_FIXED Word16 TDREND_SPATIAL_EvalOrthonormOrient_fx( - Word32 *FrontVecON_p_fx, /* i/o: Normalized front vector Q30 */ - Word32 *UpVecON_p_fx, /* i/o: Normalized up vector Q30 */ - Word32 *RightVecON_p_fx, /* i/o: Normalized right vector Q30 */ - const Word32 *FrontVec_p_fx, /* i : Input front vector */ - const Word32 *UpVec_p_fx, /* i : Input up vector */ - const Word16 orient_q /* i : Input up Q-factor */ + Word32 *FrontVecON_p_fx, /* i/o: Normalized front vector Q30 */ + Word32 *UpVecON_p_fx, /* i/o: Normalized up vector Q30 */ + Word32 *RightVecON_p_fx, /* i/o: Normalized right vector Q30 */ + const Word32 *FrontVec_p_fx, /* i : Input front vector Qx */ + const Word32 *UpVec_p_fx, /* i : Input up vector orient_q */ + const Word16 orient_q /* i : Input up Q-factor */ ) { - Word32 tmp_fx[9]; + Word32 tmp_fx[9]; // Q30 Word16 orientation_updated; orientation_updated = FALSE; @@ -310,22 +310,22 @@ Word16 TDREND_SPATIAL_EvalOrthonormOrient_fx( /* Evaluate the orthonormal right vector */ /* through the cross product of the front and the up vectors */ - RightVecON_p_fx[0] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[1], UpVec_p_fx[2] ), Mpy_32_32( FrontVecON_p_fx[2], UpVec_p_fx[1] ) ), 1 ); + RightVecON_p_fx[0] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[1], UpVec_p_fx[2] ), Mpy_32_32( FrontVecON_p_fx[2], UpVec_p_fx[1] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); - RightVecON_p_fx[1] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[2], UpVec_p_fx[0] ), Mpy_32_32( FrontVecON_p_fx[0], UpVec_p_fx[2] ) ), 1 ); + RightVecON_p_fx[1] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[2], UpVec_p_fx[0] ), Mpy_32_32( FrontVecON_p_fx[0], UpVec_p_fx[2] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); - RightVecON_p_fx[2] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[0], UpVec_p_fx[1] ), Mpy_32_32( FrontVecON_p_fx[1], UpVec_p_fx[0] ) ), 1 ); + RightVecON_p_fx[2] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[0], UpVec_p_fx[1] ), Mpy_32_32( FrontVecON_p_fx[1], UpVec_p_fx[0] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); TDREND_SPATIAL_VecNormalize_fx( RightVecON_p_fx, orient_q, RightVecON_p_fx ); // RightVecON_p_fx -> Q30 /* Evaluate the orthonormal up vector */ /* through the cross product of the front and the right vectors */ - UpVecON_p_fx[0] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[1], FrontVecON_p_fx[2] ), Mpy_32_32( RightVecON_p_fx[2], FrontVecON_p_fx[1] ) ), 1 ); + UpVecON_p_fx[0] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[1], FrontVecON_p_fx[2] ), Mpy_32_32( RightVecON_p_fx[2], FrontVecON_p_fx[1] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); - UpVecON_p_fx[1] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[2], FrontVecON_p_fx[0] ), Mpy_32_32( RightVecON_p_fx[0], FrontVecON_p_fx[2] ) ), 1 ); + UpVecON_p_fx[1] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[2], FrontVecON_p_fx[0] ), Mpy_32_32( RightVecON_p_fx[0], FrontVecON_p_fx[2] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); - UpVecON_p_fx[2] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[0], FrontVecON_p_fx[1] ), Mpy_32_32( RightVecON_p_fx[1], FrontVecON_p_fx[0] ) ), 1 ); + UpVecON_p_fx[2] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[0], FrontVecON_p_fx[1] ), Mpy_32_32( RightVecON_p_fx[1], FrontVecON_p_fx[0] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); TDREND_SPATIAL_VecNormalize_fx( UpVecON_p_fx, orient_q, UpVecON_p_fx ); // UpVecON_p_fx -> Q30 diff --git a/lib_rend/ivas_omasa_ana.c b/lib_rend/ivas_omasa_ana.c index da163f570dc1b10b75ce094e84fc3a8aacc82508..1d7e191b427c8836e0ad03edf6be731db5b1b057 100644 --- a/lib_rend/ivas_omasa_ana.c +++ b/lib_rend/ivas_omasa_ana.c @@ -124,7 +124,7 @@ ivas_error ivas_omasa_ana_open( Copy( MASA_band_grouping_24, hOMasa->band_grouping, 24 + 1 ); /* maxBin = (int16_t) ( input_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); */ - maxBin = extract_l( Mpy_32_32( input_Fs, 2684355 /* INV_CLDFB_BANDWIDTH in Q31 */ ) ); + maxBin = extract_l( Mpy_32_32( input_Fs, 2684355 /* INV_CLDFB_BANDWIDTH in Q31 */ ) ); // Q: ( ( Q0 + Q31 ) - Q31 ) -> Q0 FOR( i = 1; i < hOMasa->nbands + 1; i++ ) { @@ -853,9 +853,9 @@ static void ivas_omasa_param_est_ana_fx( FOR( Word16 ind = 0; ind < CLDFB_NO_CHANNELS_MAX; ind++ ) { - Chnl_RealBuffer_fx[i][ind] = L_shr( Chnl_RealBuffer_fx[i][ind], 4 ); + Chnl_RealBuffer_fx[i][ind] = L_shr( Chnl_RealBuffer_fx[i][ind], 4 ); // Q: in_q - 4 move32(); - Chnl_ImagBuffer_fx[i][ind] = L_shr( Chnl_ImagBuffer_fx[i][ind], 4 ); + Chnl_ImagBuffer_fx[i][ind] = L_shr( Chnl_ImagBuffer_fx[i][ind], 4 ); // Q: in_q - 4 move32(); } @@ -875,8 +875,8 @@ static void ivas_omasa_param_est_ana_fx( { FOR( i = 0; i < nchan_ism; i++ ) { - L_tmp1 = Mpy_32_32( Chnl_RealBuffer_fx[i][j], Chnl_RealBuffer_fx[i][j] ); - L_tmp2 = Mpy_32_32( Chnl_ImagBuffer_fx[i][j], Chnl_ImagBuffer_fx[i][j] ); + L_tmp1 = Mpy_32_32( Chnl_RealBuffer_fx[i][j], Chnl_RealBuffer_fx[i][j] ); // Chnl_RealBuffer_q + Chnl_RealBuffer_q - 31 + L_tmp2 = Mpy_32_32( Chnl_ImagBuffer_fx[i][j], Chnl_ImagBuffer_fx[i][j] ); // Chnl_ImagBuffer_q + Chnl_ImagBuffer_q - 31 hOMasa->energy_fx[block_m_idx][band_m_idx] = L_add( hOMasa->energy_fx[block_m_idx][band_m_idx], L_add( L_tmp1, L_tmp2 ) ); // Chnl_RealBuffer_q + Chnl_RealBuffer_q - 31 move32(); hOMasa->energy_q = sub( add( Chnl_RealBuffer_q, Chnl_RealBuffer_q ), 31 ); @@ -893,39 +893,39 @@ static void ivas_omasa_param_est_ana_fx( FOR( i = 1; i < nchan_ism; i++ ) { - v_add_fixed( Chnl_RealBuffer_fx[i], Foa_RealBuffer_fx[0], Foa_RealBuffer_fx[0], num_freq_bins, 0 ); - v_add_fixed( Chnl_ImagBuffer_fx[i], Foa_ImagBuffer_fx[0], Foa_ImagBuffer_fx[0], num_freq_bins, 0 ); + v_add_fixed( Chnl_RealBuffer_fx[i], Foa_RealBuffer_fx[0], Foa_RealBuffer_fx[0], num_freq_bins, 0 ); // Q: Chnl_RealBuffer_q + v_add_fixed( Chnl_ImagBuffer_fx[i], Foa_ImagBuffer_fx[0], Foa_ImagBuffer_fx[0], num_freq_bins, 0 ); // Q: Chnl_ImagBuffer_q } /* Y */ - v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[1][0] ), Foa_RealBuffer_fx[1], num_freq_bins ); - v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[1][0] ), Foa_ImagBuffer_fx[1], num_freq_bins ); + v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[1][0] ), Foa_RealBuffer_fx[1], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[1][0] ), Foa_ImagBuffer_fx[1], num_freq_bins ); // Q: Chnl_ImagBuffer_q FOR( i = 1; i < nchan_ism; i++ ) { - v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_RealBuffer_fx[1], num_freq_bins ); - v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_ImagBuffer_fx[1], num_freq_bins ); + v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_RealBuffer_fx[1], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_ImagBuffer_fx[1], num_freq_bins ); // Q: Chnl_ImagBuffer_q } /* Z */ - v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[2][0] ), Foa_RealBuffer_fx[2], num_freq_bins ); - v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[2][0] ), Foa_ImagBuffer_fx[2], num_freq_bins ); + v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[2][0] ), Foa_RealBuffer_fx[2], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[2][0] ), Foa_ImagBuffer_fx[2], num_freq_bins ); // Q: Chnl_ImagBuffer_q FOR( i = 1; i < nchan_ism; i++ ) { - v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_RealBuffer_fx[2], num_freq_bins ); - v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_ImagBuffer_fx[2], num_freq_bins ); + v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_RealBuffer_fx[2], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_ImagBuffer_fx[2], num_freq_bins ); // Q: Chnl_ImagBuffer_q } - v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[3][0] ), Foa_RealBuffer_fx[2], num_freq_bins ); - v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[3][0] ), Foa_ImagBuffer_fx[2], num_freq_bins ); + v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[3][0] ), Foa_RealBuffer_fx[2], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[3][0] ), Foa_ImagBuffer_fx[2], num_freq_bins ); // Q: Chnl_ImagBuffer_q FOR( i = 1; i < nchan_ism; i++ ) { - v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_RealBuffer_fx[3], num_freq_bins ); - v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_ImagBuffer_fx[3], num_freq_bins ); + v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_RealBuffer_fx[3], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_ImagBuffer_fx[3], num_freq_bins ); // Q: Chnl_ImagBuffer_q } /* Direction estimation */ @@ -933,9 +933,9 @@ static void ivas_omasa_param_est_ana_fx( { FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { - Foa_RealBuffer_fx[i][j] = L_shr( Foa_RealBuffer_fx[i][j], 5 ); + Foa_RealBuffer_fx[i][j] = L_shr( Foa_RealBuffer_fx[i][j], 5 ); // Q: ( Chnl_RealBuffer_q - 5 ) move32(); - Foa_ImagBuffer_fx[i][j] = L_shr( Foa_ImagBuffer_fx[i][j], 5 ); + Foa_ImagBuffer_fx[i][j] = L_shr( Foa_ImagBuffer_fx[i][j], 5 ); // Q: ( Chnl_RealBuffer_q - 5 ) move32(); } } @@ -948,7 +948,7 @@ static void ivas_omasa_param_est_ana_fx( /* Power estimation for diffuseness */ - computeReferencePower_ana_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, reference_power_fx, num_freq_bands ); // 2*inputq - 30 + computeReferencePower_ana_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, reference_power_fx, num_freq_bands ); // 2 * inputq - 30 reference_power_q = sub( shl( Chnl_ImagBuffer_q, 1 ), 30 ); /* Fill buffers of length "averaging_length" time slots for intensity and energy */ @@ -960,33 +960,33 @@ static void ivas_omasa_param_est_ana_fx( FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { /* only real part needed */ - Copy32( intensity_real_fx[i], &( hOMasa->buffer_intensity_real_fx[i][sub( index, 1 )][0] ), num_freq_bands ); + Copy32( intensity_real_fx[i], &( hOMasa->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); // intensity_q } - hOMasa->buffer_intensity_real_q[sub( index, 1 )] = intensity_q; + hOMasa->buffer_intensity_real_q[index - 1] = intensity_q; move16(); - Copy32( reference_power_fx, &( hOMasa->buffer_energy_fx[i_mult( sub( index, 1 ), num_freq_bands )] ), num_freq_bands ); - hOMasa->buffer_energy_q[sub( index, 1 )] = reference_power_q; + Copy32( reference_power_fx, &( hOMasa->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); + hOMasa->buffer_energy_q[index - 1] = reference_power_q; move16(); computeDiffuseness_fixed( hOMasa->buffer_intensity_real_fx, hOMasa->buffer_energy_fx, num_freq_bands, diffuseness_vector_fx, hOMasa->buffer_intensity_real_q, hOMasa->buffer_energy_q, &diffuseness_q ); FOR( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { - norm_tmp_fx = Mpy_32_32( reference_power_fx[band_m_idx], L_sub( 1073741824, diffuseness_vector_fx[band_m_idx] ) ); // reference_power_q + 30 - 31 + norm_tmp_fx = Mpy_32_32( reference_power_fx[band_m_idx], L_sub( ONE_IN_Q30, diffuseness_vector_fx[band_m_idx] ) ); // reference_power_q + 30 - 31 norm_tmp_q = sub( add( reference_power_q, 30 ), 31 ); - hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ) ); + hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ) ); // Q: hOMasa->direction_vector_m_q: ( ( norm_tmp_q + direction_q ) - 31 ) move32(); - hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ) ); + hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ) ); // Q: hOMasa->direction_vector_m_q: ( ( norm_tmp_q + direction_q ) - 31 ) move32(); - hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ) ); + hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ) ); // Q: hOMasa->direction_vector_m_q: ( ( norm_tmp_q + direction_q ) - 31 ) move32(); hOMasa->direction_vector_m_q = sub( add( norm_tmp_q, direction_q ), 31 ); - diffuseness_m_fx[band_m_idx] = L_add( diffuseness_m_fx[band_m_idx], Mpy_32_32( reference_power_fx[band_m_idx], diffuseness_vector_fx[band_m_idx] ) ); + diffuseness_m_fx[band_m_idx] = L_add( diffuseness_m_fx[band_m_idx], Mpy_32_32( reference_power_fx[band_m_idx], diffuseness_vector_fx[band_m_idx] ) ); // diffuseness_m_q: ( ( reference_power_q + diffuseness_q ) - 31 ); move32(); diffuseness_m_q = sub( add( reference_power_q, diffuseness_q ), 31 ); renormalization_factor_diff_fx[band_m_idx] = L_add( renormalization_factor_diff_fx[band_m_idx], reference_power_fx[band_m_idx] ); @@ -1033,7 +1033,7 @@ static void ivas_omasa_param_est_ana_fx( diffuseness_m_fx[band_m_idx] = 0; move32(); } - energyRatio_fx[block_m_idx][band_m_idx] = L_sub( L_shl( 1, diffuseness_m_q ), diffuseness_m_fx[band_m_idx] ); + energyRatio_fx[block_m_idx][band_m_idx] = L_sub( L_shl( 1, diffuseness_m_q ), diffuseness_m_fx[band_m_idx] ); // Q: diffuseness_m_q move32(); } @@ -1092,8 +1092,8 @@ static void ivas_omasa_dmx_fx( FOR( i = 0; i < nchan_ism; i++ ) { - azimuth_fx = extract_l( L_shr( ism_azimuth_fx[i], Q22 ) ); - elevation_fx = extract_l( L_shr( ism_elevation_fx[i], Q22 ) ); + azimuth_fx = extract_l( L_shr( ism_azimuth_fx[i], Q22 ) ); // Q0 + elevation_fx = extract_l( L_shr( ism_elevation_fx[i], Q22 ) ); // Q0 ivas_ism_get_stereo_gains_fx( azimuth_fx, elevation_fx, &gains_fx[0], &gains_fx[1] ); @@ -1111,10 +1111,10 @@ static void ivas_omasa_dmx_fx( scale = BASOP_Util_Add_MantExp( 16384, 1, negate( g1_fx ), 0, &g2_fx ); tmp1 = mult( g1_fx, gains_fx[j] ); - tmp2 = mult( g2_fx, (Word16) L_shr( prev_gains_fx[i][j], 16 ) ); + tmp2 = mult( g2_fx, (Word16) L_shr( prev_gains_fx[i][j], 16 ) ); // Q: ( ( ( 15 - scale ) + ( Q31 - Q16 ) ) - Q15 ) -> ( 15 - scale ) scale = BASOP_Util_Add_MantExp( tmp1, 0, tmp2, scale, &tmp1 ); - L_tmp = data_in_f_fx[i][k]; + L_tmp = data_in_f_fx[i][k]; // data_in_q move32(); tmp_e = sub( 31, *data_in_q ); move16(); @@ -1139,7 +1139,7 @@ static void ivas_omasa_dmx_fx( FOR( l = 0; l < L_FRAME48k; l++ ) { - data_out_f_fx[j][l] = L_shr( data_out_f_fx[j][l], sub( max_e, in_e[l] ) ); + data_out_f_fx[j][l] = L_shr( data_out_f_fx[j][l], sub( max_e, in_e[l] ) ); // exponent: max_e, Q: ( 15 - max_e ) move32(); } data_e[j] = max_e; @@ -1165,7 +1165,7 @@ static void ivas_omasa_dmx_fx( { FOR( j = 0; j < input_frame; j++ ) { - data_out_f_fx[i][j] = L_shr( data_out_f_fx[i][j], sub( max_e, data_e[i] ) ); + data_out_f_fx[i][j] = L_shr( data_out_f_fx[i][j], sub( max_e, data_e[i] ) ); // exponent: max_e, Q: ( 15 - max_e ) move32(); } } @@ -1245,11 +1245,11 @@ static void ivas_omasa_dmx( *--------------------------------------------------------------------------*/ void computeIntensityVector_ana_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ - Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ - Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ - const Word16 num_frequency_bands, /* i : Number of frequency bands */ - Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] /* o : Intensity vector */ + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal Qx */ + Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input sig Qx */ + const Word16 num_frequency_bands, /* i : Number of frequency bands */ + Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] /* o : Intensity 2 * Qx -31 */ ) { /* Reminder @@ -1276,14 +1276,14 @@ void computeIntensityVector_ana_fx( FOR( j = brange[0]; j < brange[1]; j++ ) { - real = Cldfb_RealBuffer[0][j]; - img = Cldfb_ImagBuffer[0][j]; + real = Cldfb_RealBuffer[0][j]; // Qx + img = Cldfb_ImagBuffer[0][j]; // Qx /* Intensity is XYZ order, audio is WYZX order. */ - intensity_real[0][i] = L_add( intensity_real[0][i], L_add( Mpy_32_32( Cldfb_RealBuffer[3][j], real ), Mpy_32_32( Cldfb_ImagBuffer[3][j], img ) ) ); // output Q= 2* input_q -31 + intensity_real[0][i] = L_add( intensity_real[0][i], L_add( Mpy_32_32( Cldfb_RealBuffer[3][j], real ), Mpy_32_32( Cldfb_ImagBuffer[3][j], img ) ) ); // output Q = 2 * Qx -31 move32(); - intensity_real[1][i] = L_add( intensity_real[1][i], L_add( Mpy_32_32( Cldfb_RealBuffer[1][j], real ), Mpy_32_32( Cldfb_ImagBuffer[1][j], img ) ) ); // output Q= 2* input_q -31 + intensity_real[1][i] = L_add( intensity_real[1][i], L_add( Mpy_32_32( Cldfb_RealBuffer[1][j], real ), Mpy_32_32( Cldfb_ImagBuffer[1][j], img ) ) ); // output Q = 2 * Qx -31 move32(); - intensity_real[2][i] = L_add( intensity_real[2][i], L_add( Mpy_32_32( Cldfb_RealBuffer[2][j], real ), Mpy_32_32( Cldfb_ImagBuffer[2][j], img ) ) ); // output Q= 2* input_q -31 + intensity_real[2][i] = L_add( intensity_real[2][i], L_add( Mpy_32_32( Cldfb_RealBuffer[2][j], real ), Mpy_32_32( Cldfb_ImagBuffer[2][j], img ) ) ); // output Q = 2 * Qx -31 move32(); } } @@ -1345,11 +1345,11 @@ void computeIntensityVector_ana( *--------------------------------------------------------------------------*/ void computeReferencePower_ana_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ - Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ - Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ - Word32 *reference_power, /* o : Estimated power */ - const Word16 num_freq_bands /* i : Number of frequency bands */ + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal input_q */ + Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal input_q */ + Word32 *reference_power, /* o : Estimated power 2 * inputq - 31 */ + const Word16 num_freq_bands /* i : Number of frequency bands */ ) { Word16 brange[2]; diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 7cc330e679b106da5dafff11e8fb875b500068e5..334f52ee3d9177ec945e7aa4d726977b53a4d2c0 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -125,13 +125,13 @@ void QuaternionProduct_fx( IVAS_QUATERNION tmp; // once verify// - tmp.w_fx = L_sub( ( L_sub( Mpy_32_32( q1.w_fx, q2.w_fx ), Mpy_32_32( q1.x_fx, q2.x_fx ) ) ), ( L_add( Mpy_32_32( q1.y_fx, q2.y_fx ), Mpy_32_32( q1.z_fx, q2.z_fx ) ) ) ); + tmp.w_fx = L_sub( ( L_sub( Mpy_32_32( q1.w_fx, q2.w_fx ), Mpy_32_32( q1.x_fx, q2.x_fx ) ) ), ( L_add( Mpy_32_32( q1.y_fx, q2.y_fx ), Mpy_32_32( q1.z_fx, q2.z_fx ) ) ) ); // ( q1.q_fact + q2.q_fact ) - 31 move32(); - tmp.x_fx = L_add( ( L_add( Mpy_32_32( q1.w_fx, q2.x_fx ), Mpy_32_32( q1.x_fx, q2.w_fx ) ) ), ( L_sub( Mpy_32_32( q1.y_fx, q2.z_fx ), Mpy_32_32( q1.z_fx, q2.y_fx ) ) ) ); + tmp.x_fx = L_add( ( L_add( Mpy_32_32( q1.w_fx, q2.x_fx ), Mpy_32_32( q1.x_fx, q2.w_fx ) ) ), ( L_sub( Mpy_32_32( q1.y_fx, q2.z_fx ), Mpy_32_32( q1.z_fx, q2.y_fx ) ) ) ); // ( q1.q_fact + q2.q_fact ) - 31 move32(); - tmp.y_fx = L_add( ( L_sub( Mpy_32_32( q1.w_fx, q2.y_fx ), Mpy_32_32( q1.x_fx, q2.z_fx ) ) ), ( L_add( Mpy_32_32( q1.y_fx, q2.w_fx ), Mpy_32_32( q1.z_fx, q2.x_fx ) ) ) ); + tmp.y_fx = L_add( ( L_sub( Mpy_32_32( q1.w_fx, q2.y_fx ), Mpy_32_32( q1.x_fx, q2.z_fx ) ) ), ( L_add( Mpy_32_32( q1.y_fx, q2.w_fx ), Mpy_32_32( q1.z_fx, q2.x_fx ) ) ) ); // ( q1.q_fact + q2.q_fact ) - 31 move32(); - tmp.z_fx = L_sub( ( L_add( Mpy_32_32( q1.w_fx, q2.z_fx ), Mpy_32_32( q1.x_fx, q2.y_fx ) ) ), ( L_sub( Mpy_32_32( q1.y_fx, q2.x_fx ), Mpy_32_32( q1.z_fx, q2.w_fx ) ) ) ); + tmp.z_fx = L_sub( ( L_add( Mpy_32_32( q1.w_fx, q2.z_fx ), Mpy_32_32( q1.x_fx, q2.y_fx ) ) ), ( L_sub( Mpy_32_32( q1.y_fx, q2.x_fx ), Mpy_32_32( q1.z_fx, q2.w_fx ) ) ) ); // ( q1.q_fact + q2.q_fact ) - 31 move32(); tmp.q_fact = sub( add( q1.q_fact, q2.q_fact ), 31 ); move16(); @@ -164,7 +164,7 @@ static Word32 QuaternionDotProduct_fx( Word32 result = 0; move32(); - result = L_add( ( L_add( Mpy_32_32( q1.x_fx, q2.x_fx ), Mpy_32_32( q1.y_fx, q2.y_fx ) ) ), ( L_add( Mpy_32_32( q1.z_fx, q2.z_fx ), Mpy_32_32( q1.w_fx, q2.w_fx ) ) ) ); + result = L_add( ( L_add( Mpy_32_32( q1.x_fx, q2.x_fx ), Mpy_32_32( q1.y_fx, q2.y_fx ) ) ), ( L_add( Mpy_32_32( q1.z_fx, q2.z_fx ), Mpy_32_32( q1.w_fx, q2.w_fx ) ) ) ); // ( q1.q_fact + q2.q_fact ) - 31 *q_fact = sub( add( q1.q_fact, q2.q_fact ), 31 ); move16(); @@ -223,13 +223,13 @@ static void QuaternionDivision_fx( result_q = sub( s_min( s_min( w_q, x_q ), s_min( y_q, z_q ) ), 1 ); // gaurdbits// - r->w_fx = L_shr( r->w_fx, sub( w_q, result_q ) ); + r->w_fx = L_shr( r->w_fx, sub( w_q, result_q ) ); // result_q move32(); - r->x_fx = L_shr( r->x_fx, sub( x_q, result_q ) ); + r->x_fx = L_shr( r->x_fx, sub( x_q, result_q ) ); // result_q move32(); - r->y_fx = L_shr( r->y_fx, sub( y_q, result_q ) ); + r->y_fx = L_shr( r->y_fx, sub( y_q, result_q ) ); // result_q move32(); - r->z_fx = L_shr( r->z_fx, sub( z_q, result_q ) ); + r->z_fx = L_shr( r->z_fx, sub( z_q, result_q ) ); // result_q move32(); r->q_fact = result_q; move16(); @@ -355,21 +355,21 @@ void QuaternionSlerp_fx( cosPhi = QuaternionDotProduct_fx( r1, r2, &q_dot ); q_min = s_min( r1.q_fact, r2.q_fact ); - r1.w_fx = L_shr( r1.w_fx, sub( r1.q_fact, q_min ) ); + r1.w_fx = L_shr( r1.w_fx, sub( r1.q_fact, q_min ) ); // q_min move32(); - r1.x_fx = L_shr( r1.x_fx, sub( r1.q_fact, q_min ) ); + r1.x_fx = L_shr( r1.x_fx, sub( r1.q_fact, q_min ) ); // q_min move32(); - r1.y_fx = L_shr( r1.y_fx, sub( r1.q_fact, q_min ) ); + r1.y_fx = L_shr( r1.y_fx, sub( r1.q_fact, q_min ) ); // q_min move32(); - r1.z_fx = L_shr( r1.z_fx, sub( r1.q_fact, q_min ) ); + r1.z_fx = L_shr( r1.z_fx, sub( r1.q_fact, q_min ) ); // q_min move32(); - r2.w_fx = L_shr( r2.w_fx, sub( r2.q_fact, q_min ) ); + r2.w_fx = L_shr( r2.w_fx, sub( r2.q_fact, q_min ) ); // q_min move32(); - r2.x_fx = L_shr( r2.x_fx, sub( r2.q_fact, q_min ) ); + r2.x_fx = L_shr( r2.x_fx, sub( r2.q_fact, q_min ) ); // q_min move32(); - r2.y_fx = L_shr( r2.y_fx, sub( r2.q_fact, q_min ) ); + r2.y_fx = L_shr( r2.y_fx, sub( r2.q_fact, q_min ) ); // q_min move32(); - r2.z_fx = L_shr( r2.z_fx, sub( r2.q_fact, q_min ) ); + r2.z_fx = L_shr( r2.z_fx, sub( r2.q_fact, q_min ) ); // q_min move32(); r1.q_fact = r2.q_fact = q_min; move16(); @@ -406,7 +406,7 @@ void QuaternionSlerp_fx( } ELSE { - temp_32 = L_sub( L_shr( ONE_IN_Q31, sub( 62, 2 * q_dot ) ), ( Mpy_32_32( cosPhi, cosPhi ) ) ); + temp_32 = L_sub( L_shr( ONE_IN_Q31, sub( 62, shl( q_dot, 1 ) ) ), ( Mpy_32_32( cosPhi, cosPhi ) ) ); // exp: sin_e sin_e = sub( 62, shl( q_dot, 1 ) ); sinPhi = Sqrt32( temp_32, &sin_e ); @@ -416,10 +416,12 @@ void QuaternionSlerp_fx( temp_16 = extract_h( temp_32 ); // Q13 s1 = getSineWord16R2( mult( temp_16, 20860 ) ); // Q15 + // 2 / pi in Q15 -> 20860 temp_32 = L_shl( Mpy_32_16_1( t_fx, phi ), 1 ); // Q29 temp_16 = extract_h( temp_32 ); // Q13 s2 = getSineWord16R2( mult( temp_16, 20860 ) ); // Q15 + // 2 / pi in Q15 -> 20860 tmp_quat.w_fx = L_add( Mpy_32_16_1( r1.w_fx, s1 ), Mpy_32_16_1( r2.w_fx, s2 ) ); // q_min move32(); @@ -606,11 +608,11 @@ static IVAS_VECTOR3 VectorSubtract_fx( z_qfact = sub( 31, e_result ); q_result = sub( s_min( s_min( x_qfact, y_qfact ), z_qfact ), 1 ); // guardbit// - result.x_fx = L_shr( result.x_fx, sub( x_qfact, q_result ) ); + result.x_fx = L_shr( result.x_fx, sub( x_qfact, q_result ) ); // q_result move32(); - result.y_fx = L_shr( result.y_fx, sub( y_qfact, q_result ) ); + result.y_fx = L_shr( result.y_fx, sub( y_qfact, q_result ) ); // q_result move32(); - result.z_fx = L_shr( result.z_fx, sub( z_qfact, q_result ) ); + result.z_fx = L_shr( result.z_fx, sub( z_qfact, q_result ) ); // q_result move32(); result.q_fact = q_result; move16(); @@ -645,11 +647,11 @@ static IVAS_VECTOR3 VectorCrossProduct_fx( { IVAS_VECTOR3 result_fx; - result_fx.x_fx = L_sub( Mpy_32_32( p1.y_fx, p2.z_fx ), Mpy_32_32( p1.z_fx, p2.y_fx ) ); + result_fx.x_fx = L_sub( Mpy_32_32( p1.y_fx, p2.z_fx ), Mpy_32_32( p1.z_fx, p2.y_fx ) ); // Q: ( p1.q_fact + p2.q_fact ) - 31 move32(); - result_fx.y_fx = L_sub( Mpy_32_32( p1.z_fx, p2.x_fx ), Mpy_32_32( p1.x_fx, p2.z_fx ) ); + result_fx.y_fx = L_sub( Mpy_32_32( p1.z_fx, p2.x_fx ), Mpy_32_32( p1.x_fx, p2.z_fx ) ); // Q: ( p1.q_fact + p2.q_fact ) - 31 move32(); - result_fx.z_fx = L_sub( Mpy_32_32( p1.x_fx, p2.y_fx ), Mpy_32_32( p1.y_fx, p2.x_fx ) ); + result_fx.z_fx = L_sub( Mpy_32_32( p1.x_fx, p2.y_fx ), Mpy_32_32( p1.y_fx, p2.x_fx ) ); // Q: ( p1.q_fact + p2.q_fact ) - 31 move32(); result_fx.q_fact = sub( add( p1.q_fact, p2.q_fact ), 31 ); move16(); @@ -680,7 +682,7 @@ static Word32 VectorDotProduct_fx( Word32 result_fx = 0; move32(); - result_fx = L_add( L_add( Mpy_32_32( p1.x_fx, p2.x_fx ), Mpy_32_32( p1.y_fx, p2.y_fx ) ), Mpy_32_32( p1.z_fx, p2.z_fx ) ); + result_fx = L_add( L_add( Mpy_32_32( p1.x_fx, p2.x_fx ), Mpy_32_32( p1.y_fx, p2.y_fx ) ), Mpy_32_32( p1.z_fx, p2.z_fx ) ); // // Q: ( p1.q_fact + p2.q_fact ) - 31 *q_fact = sub( add( p1.q_fact, p2.q_fact ), 31 ); move16(); @@ -707,7 +709,7 @@ static Word32 VectorLength_fx( { Word32 result_fx = 0; move32(); - result_fx = L_add( L_add( Mpy_32_32( p.x_fx, p.x_fx ), Mpy_32_32( p.y_fx, p.y_fx ) ), Mpy_32_32( p.z_fx, p.z_fx ) ); + result_fx = L_add( L_add( Mpy_32_32( p.x_fx, p.x_fx ), Mpy_32_32( p.y_fx, p.y_fx ) ), Mpy_32_32( p.z_fx, p.z_fx ) ); // // Q: ( p1.q_fact + p2.q_fact ) - 31 *q_fact = sub( add( p.q_fact, p.q_fact ), 31 ); move16(); @@ -758,11 +760,11 @@ static IVAS_VECTOR3 VectorNormalize_fx( z_qfact = sub( Q31, add( scale, sub( q_len, p.q_fact ) ) ); q_result = s_min( s_min( x_qfact, y_qfact ), z_qfact ); - result_fx.x_fx = L_shr( result_fx.x_fx, sub( x_qfact, q_result ) ); + result_fx.x_fx = L_shr( result_fx.x_fx, sub( x_qfact, q_result ) ); // Q: q_result move32(); - result_fx.y_fx = L_shr( result_fx.y_fx, sub( y_qfact, q_result ) ); + result_fx.y_fx = L_shr( result_fx.y_fx, sub( y_qfact, q_result ) ); // Q: q_result move32(); - result_fx.z_fx = L_shr( result_fx.z_fx, sub( z_qfact, q_result ) ); + result_fx.z_fx = L_shr( result_fx.z_fx, sub( z_qfact, q_result ) ); // Q: q_result move32(); result_fx.q_fact = q_result; move16(); @@ -1411,7 +1413,7 @@ ivas_error ivas_orient_trk_Process_fx( Word32 cutoffFrequency_fx, cutoff_prod; Word16 q_cutoff_prod = 0; move16(); - Word32 alpha_fx = L_shl( pOTR->alpha_fx, sub( Q30, pOTR->Q_alpha ) ); + Word32 alpha_fx = L_shl( pOTR->alpha_fx, sub( Q30, pOTR->Q_alpha ) ); // Q30 test(); IF( pOTR == NULL || pTrkRot == NULL ) @@ -1460,7 +1462,7 @@ ivas_error ivas_orient_trk_Process_fx( move16(); Word16 temp_result = BASOP_Util_Divide3232_Scale( angle_fx, pOTR->adaptationAngle_fx, &result_e ); relativeOrientationRate_fx = L_deposit_h( temp_result ); - Word32 one_fx = 1073741824; + Word32 one_fx = ONE_IN_Q30; move32(); IF( GT_32( relativeOrientationRate_fx, one_fx ) ) @@ -1493,7 +1495,7 @@ ivas_error ivas_orient_trk_Process_fx( temp_diff = sub( 31, q_cutoff_prod ); cutoff_prod = L_shl( cutoff_prod, temp_diff ); /* Compute adaptivity cutoff frequency: interpolate between minimum (center) and maximum (off-center) values */ - cutoffFrequency_fx = L_add( pOTR->centerAdaptationRate_fx, cutoff_prod ); + cutoffFrequency_fx = L_add( pOTR->centerAdaptationRate_fx, cutoff_prod ); // Q31 cutoff_prod = Mpy_32_32( cutoffFrequency_fx, PI2_C_Q28 ); q_cutoff_prod = ( ( 31 + 28 ) - 31 ); temp_result = BASOP_Util_Divide3232_Scale( cutoff_prod, updateRate_fx, &result_e ); diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index b3dde96037e9f2cb52efd1695eb23ad310fd5f24..8a9e8185d112cb9a33fb9c20ddb2089a36c397a1 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -254,19 +254,21 @@ void efap_determine_gains( #ifdef IVAS_FLOAT_FIXED ivas_error vbap_init_data_fx( - VBAP_HANDLE *hVBAPdata, /* i/o: handle for VBAP data structure that will be initialized */ - const Word32 *speaker_node_azi_deg, /* i : vector of speaker node azimuths (positive left) */ - const Word32 *speaker_node_ele_deg, /* i : vector of speaker node elevations (positive up) */ - const Word16 num_speaker_nodes, /* i : number of speaker nodes in the set */ - const IVAS_FORMAT ivas_format /* i : IVAS format */ + VBAP_HANDLE *hVBAPdata, /* i/o: handle for VBAP data structure that will be initialized */ + const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths (positive left) Q22 */ + const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations (positive up) Q22 */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes in the set */ + const IVAS_FORMAT ivas_format /* i : IVAS format */ ); + void vbap_determine_gains_fx( - const VBAP_HANDLE hVBAPdata, /* i : prepared VBAP structure */ - Word32 *gains_fx, /* o : gain vector for loudspeakers for given direction */ - const Word16 azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ - const Word16 ele_deg, /* i : elevation in degrees for panning direction (positive up) */ - const Word16 use_object_mode /* i : select between object mode panning and spatial mode panning */ + const VBAP_HANDLE hVBAPdata, /* i : prepared VBAP structure */ + Word32 *gains_fx, /* o : gain vector for loudspeakers for given direction Q29 */ + const Word16 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q0 */ + const Word16 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q0 */ + const Word16 use_object_mode /* i : select between object mode panning and spatial mode panning */ ); + void vbap_free_data_fx( VBAP_HANDLE *hVBAPdata /* i/o: VBAP handle to be freed */ ); @@ -1552,12 +1554,12 @@ void TDREND_SPATIAL_VecMapToNewCoordSystem( #ifdef IVAS_FLOAT_FIXED Word16 TDREND_SPATIAL_EvalOrthonormOrient_fx( - Word32 *FrontVecON_p_fx, /* i/o: Normalized front vector Q30 */ - Word32 *UpVecON_p_fx, /* i/o: Normalized up vector Q30 */ - Word32 *RightVecON_p_fx, /* i/o: Normalized right vector Q30 */ - const Word32 *FrontVec_p_fx, /* i : Input front vector */ - const Word32 *UpVec_p_fx, /* i : Input up vector */ - const Word16 orient_q /* i : Input up Q-factor */ + Word32 *FrontVecON_p_fx, /* i/o: Normalized front vector Q30 */ + Word32 *UpVecON_p_fx, /* i/o: Normalized up vector Q30 */ + Word32 *RightVecON_p_fx, /* i/o: Normalized right vector Q30 */ + const Word32 *FrontVec_p_fx, /* i : Input front vector Qx */ + const Word32 *UpVec_p_fx, /* i : Input up vector orient_q */ + const Word16 orient_q /* i : Input up Q-factor */ ); #endif /*! r: Flag if the orientation has been updated */ @@ -1872,10 +1874,10 @@ ivas_error ivas_reverb_process( ); #ifdef IVAS_FLOAT_FIXED void ivas_rev_delay_line_init( - ivas_rev_delay_line_t *pDelay, /* o : the delay line to initialize */ - Word32 *memory_buffer, /* i : the memory buffer to use for the delay line */ - const UWord16 delay, /* i : the delay */ - const UWord16 maxdelay /* i : maximum delay to be supported */ + ivas_rev_delay_line_t *pDelay, /* o : the delay line to initialize */ + Word32 *memory_buffer, /* i : the memory buffer to use for the delay line Q11 */ + const UWord16 delay, /* i : the delay */ + const UWord16 maxdelay /* i : maximum delay to be supported */ ); #else void ivas_rev_delay_line_init( @@ -1887,13 +1889,13 @@ void ivas_rev_delay_line_init( #endif #ifdef IVAS_FLOAT_FIXED /*! r: sample gotten out of delay line, and amplified by set gain */ -Word32 ivas_rev_delay_line_get_sample_fx( - ivas_rev_delay_line_t *pDelay /* i/o: the delay line */ +Word32 ivas_rev_delay_line_get_sample_fx( /* Q11 */ + ivas_rev_delay_line_t *pDelay /* i/o: the delay line */ ); void ivas_rev_delay_line_feed_sample_fx( - ivas_rev_delay_line_t *pDelay, /* i : the delay line */ - Word32 input /* i : the sample to feed */ + ivas_rev_delay_line_t *pDelay, /* i : the delay line */ + Word32 input /* i : the sample to feed Q11 */ ); void ivas_rev_delay_line_get_sample_blk_fx( @@ -1903,9 +1905,9 @@ void ivas_rev_delay_line_get_sample_blk_fx( ); void ivas_rev_delay_line_feed_sample_blk_fx( - ivas_rev_delay_line_t *pDelay, /* i/o: the delay line */ - const UWord16 blk_size, /* i : number of samples in the input data block */ - Word32 *input /* i : the samples to feed */ + ivas_rev_delay_line_t *pDelay, /* i/o: the delay line */ + const UWord16 blk_size, /* i : number of samples in the input data block */ + Word32 *input /* i : the samples to feed Q11 */ ); #else /*! r: sample gotten out of delay line, and amplified by set gain */ @@ -1987,20 +1989,20 @@ void ivas_reverb_t2f_f2t_ClearHistory( ivas_reverb_t2f_f2t_t *t2f_f2t ); #ifdef IVAS_FLOAT_FIXED -void ivas_reverb_t2f_f2t_in_fx( - ivas_reverb_t2f_f2t_t *t2f_f2t, - Word32 *input_L, - Word32 *input_R, - Word32 *buffer_L, - Word32 *buffer_R +void ivas_reverb_t2f_f2t_in_fx( + ivas_reverb_t2f_f2t_t *t2f_f2t, + Word32 *input_L, // i: Qx + Word32 *input_R, // i: Qx + Word32 *buffer_L, // o: Qx + 1 + Word32 *buffer_R // o: Qx + 1 ); void ivas_reverb_t2f_f2t_out_fx( ivas_reverb_t2f_f2t_t *t2f_f2t, - Word32 *buffer_L, - Word32 *buffer_R, - Word32 *output_L, - Word32 *output_R + Word32 *buffer_L, // i/o: Qx + Word32 *buffer_R, // i/o: Qx + Word32 *output_L, // i/o: Qx + Word32 *output_R // i/o: Qx ); #else void ivas_reverb_t2f_f2t_in( @@ -2025,12 +2027,12 @@ Word16 ivas_reverb_fft_filter_init( ); void ivas_reverb_fft_filter_ComplexMul_fx( - ivas_reverb_fft_filter_t *fft_filter, - Word32 *buffer + ivas_reverb_fft_filter_t *fft_filter, /* i */ + Word32 *buffer /* i/o: Qx */ ); void ivas_reverb_fft_filter_CrossMix_fx( - Word32 *buffer0, - Word32 *buffer1, + Word32 *buffer0, // i/o: Qx + Word32 *buffer1, // i/o: Qx const Word16 fft_size ); #else @@ -2057,9 +2059,9 @@ void ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR( ); #ifdef IVAS_FLOAT_FIXED void ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR_fx( - rv_fftwf_type_complex_fx *spectrum, - Word32 *fft_real, - const Word16 fft_size); + rv_fftwf_type_complex_fx *spectrum, // i: Qx + Word32 *fft_real, // o: Qx + const Word16 fft_size); void ivas_reverb_define_window_fft_fx( Word32 *pWindow, //output in Q31 const Word16 transitionStart, @@ -2751,11 +2753,11 @@ void ivas_omasa_ana_close( ); #ifdef IVAS_FLOAT_FIXED void computeIntensityVector_ana_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ - Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ - Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ - const Word16 num_frequency_bands, /* i : Number of frequency bands */ - Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] /* o : Intensity vector */ + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal Qx */ + Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal Qx */ + const Word16 num_frequency_bands, /* i : Number of frequency bands */ + Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] /* o : Intensity vector 2 * Qx -31 */ ); #endif void computeIntensityVector_ana( @@ -2767,11 +2769,11 @@ void computeIntensityVector_ana( ); #ifdef IVAS_FLOAT_FIXED void computeReferencePower_ana_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ - Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ - Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ - Word32 *reference_power, /* o : Estimated power */ - const Word16 num_freq_bands /* i : Number of frequency bands */ + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal input_q */ + Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal input_q */ + Word32 *reference_power, /* o : Estimated power */ + const Word16 num_freq_bands /* i : Number of frequency bands 2 * input_q - 31 */ ); #endif void computeReferencePower_ana( diff --git a/lib_rend/ivas_reverb_delay_line.c b/lib_rend/ivas_reverb_delay_line.c index 32599fd27fe3bd6ff2e18c9fd379e44742ef7b02..9025b1597a4b3e0bea3089498afb7e745b59eb56 100644 --- a/lib_rend/ivas_reverb_delay_line.c +++ b/lib_rend/ivas_reverb_delay_line.c @@ -48,10 +48,10 @@ *-----------------------------------------------------------------------------------------*/ void ivas_rev_delay_line_init( - ivas_rev_delay_line_t *pDelay, /* o : the delay line to initialize */ - Word32 *memory_buffer, /* i : the memory buffer to use for the delay line */ - const UWord16 delay, /* i : the delay */ - const UWord16 maxdelay /* i : maximum delay to be supported */ + ivas_rev_delay_line_t *pDelay, /* o : the delay line to initialize */ + Word32 *memory_buffer, /* i : the memory buffer to use for the delay line Q11 */ + const UWord16 delay, /* i : the delay */ + const UWord16 maxdelay /* i : maximum delay to be supported */ ) { pDelay->MaxDelay = maxdelay; @@ -85,11 +85,11 @@ void ivas_rev_delay_line_init( *-----------------------------------------------------------------------------------------*/ void ivas_rev_delay_line_feed_sample_fx( - ivas_rev_delay_line_t *pDelay, /* i : the delay line */ - Word32 input /* i : the sample to feed */ + ivas_rev_delay_line_t *pDelay, /* i : the delay line */ + Word32 input /* i : the sample to feed Q11 */ ) { - pDelay->pBuffer_fx[pDelay->BufferPos] = input; + pDelay->pBuffer_fx[pDelay->BufferPos] = input; // Q11 pDelay->BufferPos = u_extract_l( UL_addNsD( pDelay->BufferPos, 1 ) ); move16(); @@ -223,9 +223,9 @@ void ivas_rev_delay_line_feed_sample_blk( *-----------------------------------------------------------------------------------------*/ void ivas_rev_delay_line_feed_sample_blk_fx( - ivas_rev_delay_line_t *pDelay, /* i/o: the delay line */ - const UWord16 blk_size, /* i : number of samples in the input data block */ - Word32 *input /* i : the samples to feed */ + ivas_rev_delay_line_t *pDelay, /* i/o: the delay line */ + const UWord16 blk_size, /* i : number of samples in the input data block */ + Word32 *input /* i : the samples to feed Q11 */ ) { Word32 *pDst, *pSrc; @@ -246,14 +246,14 @@ void ivas_rev_delay_line_feed_sample_blk_fx( pDst = &pDelay->pBuffer_fx[pos]; FOR( i = 0; i < blk_size_1; i++ ) { - pDst[i] = input[i]; + pDst[i] = input[i]; // Q11 move32(); } - pDst = &pDelay->pBuffer_fx[0]; - pSrc = &input[blk_size_1]; + pDst = &pDelay->pBuffer_fx[0]; // Q11 + pSrc = &input[blk_size_1]; // Q11 FOR( i = 0; i < blk_size_2; i++ ) { - pDst[i] = pSrc[i]; + pDst[i] = pSrc[i]; // Q11 move32(); } pos = blk_size_2; @@ -261,10 +261,10 @@ void ivas_rev_delay_line_feed_sample_blk_fx( } ELSE /* copy only 1 data block directly if it fits in the buffer */ { - pDst = &pDelay->pBuffer_fx[pos]; + pDst = &pDelay->pBuffer_fx[pos]; // Q11 FOR( i = 0; i < blk_size; i++ ) { - pDst[i] = input[i]; + pDst[i] = input[i]; // Q11 move32(); } pos = (UWord16) L_add( pos, blk_size ); @@ -289,8 +289,8 @@ void ivas_rev_delay_line_feed_sample_blk_fx( *-----------------------------------------------------------------------------------------*/ /*! r: sample gotten out of delay line, and amplified by set gain */ -Word32 ivas_rev_delay_line_get_sample_fx( - ivas_rev_delay_line_t *pDelay /* i/o: the delay line */ +Word32 ivas_rev_delay_line_get_sample_fx( /* Q11 */ + ivas_rev_delay_line_t *pDelay /* i/o: the delay line */ ) { IF( EQ_16( pDelay->Gain_fx, ONE_IN_Q14 ) ) @@ -301,7 +301,7 @@ Word32 ivas_rev_delay_line_get_sample_fx( ELSE { - return ( L_shl( Mpy_32_16_r( pDelay->pBuffer_fx[pDelay->BufferPos], pDelay->Gain_fx ), 1 ) ); + return ( L_shl( Mpy_32_16_r( pDelay->pBuffer_fx[pDelay->BufferPos], pDelay->Gain_fx ), 1 ) ); // Q11 + Q14 - 15 + 1 = Q11 } } /*-----------------------------------------------------------------------------------------* @@ -311,9 +311,9 @@ Word32 ivas_rev_delay_line_get_sample_fx( *-----------------------------------------------------------------------------------------*/ void ivas_rev_delay_line_get_sample_blk_fx( - ivas_rev_delay_line_t *pDelay, /* i : the delay line */ - const UWord16 blk_size, /* i : number of samples in the data block */ - Word32 *output /* i/o: amples gotten out of delay line, and amplified by set gainin */ + ivas_rev_delay_line_t *pDelay, /* i : the delay line */ + const UWord16 blk_size, /* i : number of samples in the data block */ + Word32 *output /* i/o: amples gotten out of delay line, and amplified by set gainin Q11 */ ) { Word32 *pDst, *pSrc; @@ -334,16 +334,16 @@ void ivas_rev_delay_line_get_sample_blk_fx( move16(); blk_size_2 = (UWord16) L_sub( blk_size, blk_size_1 ); move16(); - pSrc = &pDelay->pBuffer_fx[pos]; + pSrc = &pDelay->pBuffer_fx[pos]; // Q11 IF( EQ_16( gain, ONE_IN_Q14 ) ) { FOR( i = 0; i < blk_size_1; i++ ) { - output[i] = pSrc[i]; + output[i] = pSrc[i]; // Q11 move32(); } - pSrc = &pDelay->pBuffer_fx[0]; - pDst = &output[blk_size_1]; + pSrc = &pDelay->pBuffer_fx[0]; // Q11 + pDst = &output[blk_size_1]; // Q11 FOR( i = 0; i < blk_size_2; i++ ) { pDst[i] = pSrc[i]; @@ -354,14 +354,14 @@ void ivas_rev_delay_line_get_sample_blk_fx( { FOR( i = 0; i < blk_size_1; i++ ) { - output[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); + output[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); // Q11 + Q14 - 15 + 1 = Q11 move32(); } pSrc = &pDelay->pBuffer_fx[0]; pDst = &output[blk_size_1]; FOR( i = 0; i < blk_size_2; i++ ) { - pDst[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); + pDst[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); // Q11 + Q14 - 15 + 1 = Q11 move32(); } } @@ -374,7 +374,7 @@ void ivas_rev_delay_line_get_sample_blk_fx( { FOR( i = 0; i < blk_size; i++ ) { - output[i] = pSrc[i]; + output[i] = pSrc[i]; // Q11 move32(); } } @@ -382,7 +382,7 @@ void ivas_rev_delay_line_get_sample_blk_fx( { FOR( i = 0; i < blk_size; i++ ) { - output[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); + output[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); // Q11 + Q14 - 15 + 1 = Q11 move32(); } } diff --git a/lib_rend/ivas_reverb_fft_filter.c b/lib_rend/ivas_reverb_fft_filter.c index 2e9ce6cdab11f297edb1d061b8869cd175d039e7..bae4d3f3653993c27f707f789bd7532106b3d758 100644 --- a/lib_rend/ivas_reverb_fft_filter.c +++ b/lib_rend/ivas_reverb_fft_filter.c @@ -139,8 +139,8 @@ uint16_t int_log2( *-----------------------------------------------------------------------------------------*/ static void fft_wrapper_2ch_fx( - Word32 *buffer_L_fx, - Word32 *buffer_R_fx, + Word32 *buffer_L_fx, // input Q: Qx -> output Q: (Qx + 1) + Word32 *buffer_R_fx, // input Q: Qx -> output Q: (Qx + 1) const Word16 fft_size ) { const Word16 half_sz = shr( fft_size, 1 ); @@ -149,27 +149,27 @@ static void fft_wrapper_2ch_fx( DoRTFTn_fx_ivas( buffer_L_fx, buffer_R_fx, fft_size ); /* separating left and right channel spectra */ - buffer_L_fx[0] = L_shl( buffer_L_fx[0], 1 ); + buffer_L_fx[0] = L_shl( buffer_L_fx[0], 1 ); // Qx + 1 move32(); - buffer_R_fx[0] = L_shl( buffer_R_fx[0], 1 ); + buffer_R_fx[0] = L_shl( buffer_R_fx[0], 1 ); // Qx + 1 move32(); FOR( k = 1; k < half_sz; k++ ) { mirror_k = sub( fft_size, k ); - left_re_fx = ( L_add( buffer_L_fx[k], buffer_L_fx[mirror_k] ) ); - left_im_fx = ( L_sub( buffer_R_fx[k], buffer_R_fx[mirror_k] ) ); + left_re_fx = ( L_add( buffer_L_fx[k], buffer_L_fx[mirror_k] ) ); // Qx + 1 + left_im_fx = ( L_sub( buffer_R_fx[k], buffer_R_fx[mirror_k] ) ); // Qx + 1 - right_re_fx = ( L_add( buffer_R_fx[k], buffer_R_fx[mirror_k] ) ); - right_im_fx = L_negate( ( L_sub( buffer_L_fx[k], buffer_L_fx[mirror_k] ) ) ); + right_re_fx = ( L_add( buffer_R_fx[k], buffer_R_fx[mirror_k] ) ); // Qx + 1 + right_im_fx = L_negate( ( L_sub( buffer_L_fx[k], buffer_L_fx[mirror_k] ) ) ); // Qx + 1 - buffer_L_fx[k] = left_re_fx; + buffer_L_fx[k] = left_re_fx; // Qx + 1 move32(); - buffer_R_fx[k] = right_re_fx; + buffer_R_fx[k] = right_re_fx; // Qx + 1 move32(); - buffer_L_fx[mirror_k] = left_im_fx; + buffer_L_fx[mirror_k] = left_im_fx; // Qx + 1 move32(); - buffer_R_fx[mirror_k] = right_im_fx; + buffer_R_fx[mirror_k] = right_im_fx; // Qx + 1 move32(); } @@ -221,8 +221,8 @@ static void fft_wrapper_2ch( *-----------------------------------------------------------------------------------------*/ static void ifft_wrapper_2ch_fx( - Word32 *buffer_L, - Word32 *buffer_R, + Word32 *buffer_L, // i/o: Qx + Word32 *buffer_R, // i/o: Qx const Word16 fft_size ) { Word32 buffer_L_re, buffer_L_im, buffer_R_re, buffer_R_im; @@ -234,22 +234,22 @@ static void ifft_wrapper_2ch_fx( { mirror_k = sub( fft_size, k ); - buffer_L_re = buffer_L[k]; + buffer_L_re = buffer_L[k]; // Qx move32(); - buffer_L_im = buffer_L[mirror_k]; + buffer_L_im = buffer_L[mirror_k]; // Qx move32(); - buffer_R_re = buffer_R[k]; + buffer_R_re = buffer_R[k]; // Qx move32(); - buffer_R_im = buffer_R[mirror_k]; + buffer_R_im = buffer_R[mirror_k]; // Qx move32(); - buffer_L[k] = L_add( buffer_L_re, buffer_R_im ); + buffer_L[k] = L_add( buffer_L_re, buffer_R_im ); // Qx move32(); - buffer_L[mirror_k] = L_sub( buffer_L_re, buffer_R_im ); + buffer_L[mirror_k] = L_sub( buffer_L_re, buffer_R_im ); // Qx move32(); - buffer_R[k] = L_sub( buffer_R_re, buffer_L_im ); + buffer_R[k] = L_sub( buffer_R_re, buffer_L_im ); // Qx move32(); - buffer_R[mirror_k] = L_add( buffer_R_re, buffer_L_im ); + buffer_R[mirror_k] = L_add( buffer_R_re, buffer_L_im ); // Qx move32(); } @@ -441,26 +441,26 @@ void ivas_reverb_t2f_f2t_ClearHistory( void ivas_reverb_t2f_f2t_in_fx( ivas_reverb_t2f_f2t_t *t2f_f2t, - Word32 *input_L, - Word32 *input_R, - Word32 *buffer_L, - Word32 *buffer_R ) + Word32 *input_L, // i: Qx + Word32 *input_R, // i: Qx + Word32 *buffer_L, // o: Qx + 1 + Word32 *buffer_R ) // o: Qx + 1 { Word16 i; Word16 hlen = t2f_f2t->hist_size; move16(); Word16 bsiz = t2f_f2t->block_size; move16(); - Word32 *hist_L = t2f_f2t->fft_history_L_fx; - Word32 *hist_R = t2f_f2t->fft_history_R_fx; + Word32 *hist_L = t2f_f2t->fft_history_L_fx; // Qx + Word32 *hist_R = t2f_f2t->fft_history_R_fx; // Qx Word32 *pL, *pR; /* copy history to buffer */ FOR( i = 0; i < hlen; i++ ) { - buffer_L[i] = hist_L[i]; + buffer_L[i] = hist_L[i]; // Qx move16(); - buffer_R[i] = hist_R[i]; + buffer_R[i] = hist_R[i]; // Qx move16(); } @@ -469,9 +469,9 @@ void ivas_reverb_t2f_f2t_in_fx( pR = &buffer_R[hlen]; FOR( i = 0; i < bsiz; i++ ) { - pL[i] = input_L[i]; + pL[i] = input_L[i]; // Qx move32(); - pR[i] = input_R[i]; + pR[i] = input_R[i]; // Qx move32(); } @@ -480,14 +480,14 @@ void ivas_reverb_t2f_f2t_in_fx( pR = &buffer_R[bsiz]; FOR( i = 0; i < hlen; i++ ) { - hist_L[i] = pL[i]; + hist_L[i] = pL[i]; // Qx move32(); - hist_R[i] = pR[i]; + hist_R[i] = pR[i]; // Qx move32(); } /* do FFT */ - fft_wrapper_2ch_fx( buffer_L, buffer_R, t2f_f2t->fft_size ); + fft_wrapper_2ch_fx( buffer_L, buffer_R, t2f_f2t->fft_size ); // Qx -> Qx + 1 return; } @@ -552,10 +552,10 @@ void ivas_reverb_t2f_f2t_in( void ivas_reverb_t2f_f2t_out_fx( ivas_reverb_t2f_f2t_t *t2f_f2t, - Word32 *buffer_L, - Word32 *buffer_R, - Word32 *output_L, - Word32 *output_R ) + Word32 *buffer_L, // i/o: Qx + Word32 *buffer_R, // i/o: Qx + Word32 *output_L, // i/o: Qx + Word32 *output_R ) // i/o: Qx { Word16 i; Word32 *pL = &buffer_L[t2f_f2t->hist_size]; @@ -565,9 +565,9 @@ void ivas_reverb_t2f_f2t_out_fx( FOR( i = 0; i < t2f_f2t->block_size; i++ ) { - output_L[i] = pL[i]; + output_L[i] = pL[i]; // Qx move32(); - output_R[i] = pR[i]; + output_R[i] = pR[i]; // Qx move32(); } @@ -654,8 +654,9 @@ int16_t ivas_reverb_fft_filter_init( *-----------------------------------------------------------------------------------------*/ void ivas_reverb_fft_filter_ComplexMul_fx( - ivas_reverb_fft_filter_t *fft_filter, - Word32 *buffer ) + ivas_reverb_fft_filter_t *fft_filter, /* i */ + Word32 *buffer /* i/o: Qx */ +) { Word16 f_spec, h, i, j; Word32 *spec; @@ -665,18 +666,18 @@ void ivas_reverb_fft_filter_ComplexMul_fx( h = shr( f_spec, 1 ); spec = fft_filter->fft_spectrum_fx; - buffer[0] = Mpy_32_32( spec[0], buffer[0] ); /* real multiply f0 DC */ + buffer[0] = Mpy_32_32( spec[0], buffer[0] ); /* real multiply f0 DC */ // Q31 + Qx - 31 = Qx move32(); - buffer[h] = Mpy_32_32( spec[h], buffer[h] ); /* real multiply f_spec Nyquist */ + buffer[h] = Mpy_32_32( spec[h], buffer[h] ); /* real multiply f_spec Nyquist */ // Q31 + Qx - 31 = Qx move32(); j = sub( f_spec, 1 ); FOR( i = 1; i < h; i++ ) /*actual complex multiply in loop */ { t = buffer[i]; move32(); - buffer[i] = L_sub( Mpy_32_32( t, spec[i] ), Mpy_32_32( buffer[j], spec[j] ) ); + buffer[i] = L_sub( Mpy_32_32( t, spec[i] ), Mpy_32_32( buffer[j], spec[j] ) ); // Qx + Q31 - 31 = Qx move32(); - buffer[j] = L_add( Mpy_32_32( t, spec[j] ), Mpy_32_32( buffer[j], spec[i] ) ); + buffer[j] = L_add( Mpy_32_32( t, spec[j] ), Mpy_32_32( buffer[j], spec[i] ) ); // Qx + Q31 - 31 = Qx move32(); j = sub( j, 1 ); } @@ -723,22 +724,22 @@ void ivas_reverb_fft_filter_ComplexMul( *-----------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR_fx( - rv_fftwf_type_complex_fx *spectrum, - Word32 *fft_real, + rv_fftwf_type_complex_fx *spectrum, // i: Qx + Word32 *fft_real, // o: Qx const Word16 fft_size ) { Word16 i, h; h = shr( fft_size, 1 ); - fft_real[0] = spectrum[0][0]; + fft_real[0] = spectrum[0][0]; // Qx move32(); - fft_real[h] = spectrum[h][0]; + fft_real[h] = spectrum[h][0]; // Qx move32(); FOR( i = 1; i < h; i++ ) { - fft_real[i] = spectrum[i][0]; + fft_real[i] = spectrum[i][0]; // Qx move32(); - fft_real[sub( fft_size, i )] = spectrum[i][1]; + fft_real[fft_size - i] = spectrum[i][1]; // Qx move32(); } @@ -775,8 +776,8 @@ void ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR( *-----------------------------------------------------------------------------------------*/ void ivas_reverb_fft_filter_CrossMix_fx( - Word32 *buffer0, - Word32 *buffer1, + Word32 *buffer0, // i/o: Qx + Word32 *buffer1, // i/o: Qx const Word16 fft_size ) { Word32 t; @@ -784,11 +785,11 @@ void ivas_reverb_fft_filter_CrossMix_fx( FOR( i = 0; i < fft_size; i++ ) { - t = buffer0[i]; + t = buffer0[i]; // Qx move32(); - buffer0[i] = L_add( t, buffer1[i] ); + buffer0[i] = L_add( t, buffer1[i] ); // Qx move32(); - buffer1[i] = L_sub( t, buffer1[i] ); + buffer1[i] = L_sub( t, buffer1[i] ); // Qx move32(); } diff --git a/lib_rend/ivas_reverb_filter_design.c b/lib_rend/ivas_reverb_filter_design.c index 79ad2c1514cf78f30ec855acd31bd8ae95bedd5c..c0d147123f55b5f9813705f0c874b0c103994d79 100644 --- a/lib_rend/ivas_reverb_filter_design.c +++ b/lib_rend/ivas_reverb_filter_design.c @@ -46,12 +46,15 @@ * Local constants *------------------------------------------------------------------------------------------*/ -#define STEP_LIMIT_PIVOT_FREQ ( 1000.0f ) /* Pivot (initial reference) frequency for response gradient limit */ -#define RESPONSE_STEP_LIMIT_LF ( 4.0f ) /* Maximum step in dB per bin at low frequencies (< pivot frequency) */ -#define RESPONSE_STEP_LIMIT_LF_FX ( 536870912 ) /* Maximum step in dB per bin at low frequencies (< pivot frequency) */ -#define RESPONSE_STEP_LIMIT_HF ( 1.5f ) /* Maximum step in dB per bin at high frequencies (> pivot frequency) */ -#define RESPONSE_STEP_LIMIT_HF_FX ( 1610612736 ) /* Maximum step in dB per bin at high frequencies (> pivot frequency) */ -#define EPS ( 1e-30f ) +#ifndef IVAS_FLOAT_FIXED +#define STEP_LIMIT_PIVOT_FREQ ( 1000.0f ) /* Pivot (initial reference) frequency for response gradient limit */ +#define RESPONSE_STEP_LIMIT_LF ( 4.0f ) /* Maximum step in dB per bin at low frequencies (< pivot frequency) */ +#define RESPONSE_STEP_LIMIT_HF ( 1.5f ) /* Maximum step in dB per bin at high frequencies (> pivot frequency) */ +#define EPS ( 1e-30f ) +#else +#define RESPONSE_STEP_LIMIT_LF_FX ( 536870912 ) /* Q27 Maximum step in dB per bin at low frequencies (< pivot frequency) */ +#define RESPONSE_STEP_LIMIT_HF_FX ( 1610612736 ) /* Q30 Maximum step in dB per bin at high frequencies (> pivot frequency) */ +#endif /*------------------------------------------------------------------------------------------* @@ -194,9 +197,9 @@ static void calc_min_phase( #endif #ifdef IVAS_FLOAT_FIXED static void calc_min_phase_fx( - rv_fftwf_type_complex_fx *pSpectrum, + rv_fftwf_type_complex_fx *pSpectrum /*Q31*/, const Word16 fft_size, - Word32 *pMinPhase, + Word32 *pMinPhase, /*q_pCepstrum*/ Word16 *q_pCepstrum ) { Word16 idx; @@ -244,13 +247,13 @@ static void calc_min_phase_fx( /* Initial angle set to match Hann window alignment in Matlab */ - initial_angle = shr( add( ( EVS_PI_FX ), shr( angle_increment, 2 ) ), 1 ); // q = 13 + initial_angle = shr( add( ( EVS_PI_FX /*Q13*/ ), shr( angle_increment, 2 ) ), 1 ); // Q13 FOR( idx = 0; idx < cepstrum_smoothing_extent; idx++ ) { - const Word16 sine_value = getSinWord16( add( initial_angle, shl( mult( shl( idx, 8 ), angle_increment ), 5 ) ) ); // q15 + const Word16 sine_value = getSinWord16( add( initial_angle, shl( mult( shl( idx, 8 ), angle_increment ), 5 ) ) ); // Q15 - pFolded_cepstrum_smoothing_win[add( idx, sub( half_fft_size, cepstrum_smoothing_extent ) )] = L_mult( sine_value, sine_value ); // q31 + pFolded_cepstrum_smoothing_win[idx + half_fft_size - cepstrum_smoothing_extent] = L_mult( sine_value, sine_value ); // Q31 move32(); } @@ -264,9 +267,9 @@ static void calc_min_phase_fx( /* Compute the log amplitude spectrum */ FOR( idx = 0; idx < spectrum_size; idx++ ) { - W_tmp0 = W_mult_32_32( pSpectrum[idx][0], pSpectrum[idx][0] ); - W_tmp1 = W_mult_32_32( pSpectrum[idx][1], pSpectrum[idx][1] ); - W_tmp0 = W_add( W_tmp0, W_tmp1 ); + W_tmp0 = W_mult_32_32( pSpectrum[idx][0], pSpectrum[idx][0] ); // Q30 * 2 - 1 + W_tmp1 = W_mult_32_32( pSpectrum[idx][1], pSpectrum[idx][1] ); // Q30 * 2 - 1 + W_tmp0 = W_add( W_tmp0, W_tmp1 ); // Q30 * 2 - 1 W_shift = W_norm( W_tmp0 ); pCepstrum[idx] = Mpy_32_32( L_add( BASOP_Util_Log2( W_extract_h( W_shl( W_tmp0, W_shift ) ) ), L_shl( negate( W_shift ), 25 ) ), LN_2_Q31 ); /* log2 = 0.693147, q = 31, value = 1488521848 */ // q =26 move32(); @@ -275,7 +278,7 @@ static void calc_min_phase_fx( /* Extending one-sided spectrum to double-sided one */ FOR( idx = spectrum_size; idx < fft_size; idx++ ) { - pCepstrum[idx] = pCepstrum[sub( fft_size, idx )]; + pCepstrum[idx] = pCepstrum[fft_size - idx]; move32(); } Word16 guarded_bits; @@ -311,7 +314,7 @@ static void calc_min_phase_fx( { pFolded_cepstrum_re[idx] = L_shl( pCepstrum[idx], 1 ); // q = q_pCepstrum move32(); - pFolded_cepstrum_im[idx] = L_negate( L_shl( pCepstrum[sub( fft_size, idx )], 1 ) ); // q = q_pCepstrum + pFolded_cepstrum_im[idx] = L_negate( L_shl( pCepstrum[fft_size - idx], 1 ) ); // q = q_pCepstrum move32(); /* Note: sign inverted because of fft rather than ifft used before */ } @@ -414,7 +417,7 @@ static void calc_min_phase_filter( #ifdef IVAS_FLOAT_FIXED static void calc_min_phase_filter_fx( - rv_fftwf_type_complex_fx *pH_flt, + rv_fftwf_type_complex_fx *pH_flt, // Q31 const Word16 fft_size ) { const Word16 spectrum_size = add( shr( fft_size, 1 ), 1 ); @@ -433,21 +436,21 @@ static void calc_min_phase_filter_fx( /* Cancel out initial phase by computing amplitude */ /* Note: slightly different (but mathematically equivalent) approach used for better efficiency */ move16(); - W_tmp1 = W_mult_32_32( pH_flt[idx][0], pH_flt[idx][0] ); - W_tmp2 = W_mult_32_32( pH_flt[idx][1], pH_flt[idx][1] ); - W_tmp1 = W_add( W_tmp1, W_tmp2 ); + W_tmp1 = W_mult_32_32( pH_flt[idx][0], pH_flt[idx][0] ); // Q31 *2 - 1 + W_tmp2 = W_mult_32_32( pH_flt[idx][1], pH_flt[idx][1] ); // Q31 *2 - 1 + W_tmp1 = W_add( W_tmp1, W_tmp2 ); // Q31 *2 - 1 W_shift = W_norm( W_tmp1 ); - L_tmp = W_extract_h( W_shl( W_tmp1, W_shift ) ); - Word16 exp = negate( W_shift ); // 31-31-W_shift + L_tmp = W_extract_h( W_shl( W_tmp1, W_shift ) ); // Q31 *2 - 1 + W_shift - 31 + Word16 exp = negate( W_shift ); // 31-31-W_shift - Word32 current_ampl = Sqrt32( L_tmp, &exp ); // q = 31 -exp == 31 - current_ampl = L_shl( current_ampl, exp ); + Word32 current_ampl = Sqrt32( L_tmp, &exp ); // q = 31 - exp = q31 + current_ampl = L_shl( current_ampl, exp ); // Q31 /* Using the phase computed by calc_min_phase() + additional delay */ /* Apply the computed phase */ - pH_flt[idx][0] = Mpy_32_16_1( current_ampl, shl_sat( getCosWord16( abs_s( (Word16) L_shr( pMin_phase[idx], sub( q_pMin_phase, 13 ) ) ) ), 1 ) ); // shifting right for next function. + pH_flt[idx][0] = Mpy_32_16_1( current_ampl, shl_sat( getCosWord16( abs_s( (Word16) L_shr( pMin_phase[idx], sub( q_pMin_phase, 13 ) ) ) ), 1 ) ); // shifting right for next function.//Q31 + Q13 + 1 - 15 move32(); - pH_flt[idx][1] = Mpy_32_16_1( current_ampl, getSinWord16( (Word16) L_shr( pMin_phase[idx], sub( q_pMin_phase, 13 ) ) ) ); + pH_flt[idx][1] = Mpy_32_16_1( current_ampl, getSinWord16( (Word16) L_shr( pMin_phase[idx], sub( q_pMin_phase, 13 ) ) ) ); // Q31 + Q15 - 15 move32(); } @@ -511,8 +514,8 @@ static void apply_window_fft( #endif #ifdef IVAS_FLOAT_FIXED static void apply_window_fft_fx( - rv_fftwf_type_complex_fx *pH_flt, - const Word32 *pWindow, + rv_fftwf_type_complex_fx *pH_flt, // q_pFilter + const Word32 *pWindow, // Q30 const Word16 fft_size, Word16 *q_pFilter ) { @@ -525,13 +528,13 @@ static void apply_window_fft_fx( /* Real parts */ FOR( idx = 0; idx <= half_fft_size; idx++ ) { - pFilter[idx] = pH_flt[idx][0]; + pFilter[idx] = pH_flt[idx][0]; // Q31 move32(); } /* Img parts */ FOR( idx = 1; idx < half_fft_size; idx++ ) { - pFilter[sub( fft_size, idx )] = pH_flt[idx][1]; + pFilter[fft_size - idx] = pH_flt[idx][1]; // Q31 move32(); } *q_pFilter = 31; @@ -545,10 +548,11 @@ static void apply_window_fft_fx( { FOR( Word16 j = 0; j < fft_size; j++ ) { - pFilter[j] = L_shl( pFilter[j], temp ); + pFilter[j] = L_shl( pFilter[j], temp ); // q_pFilter + temp move32(); } *q_pFilter = add( *q_pFilter, temp ); + move16(); } ifft_rel_fx32( pFilter, fft_size, log2_fft_size ); @@ -575,12 +579,12 @@ static void apply_window_fft_fx( move16(); } - fft_rel_fx32( pFilter, fft_size, log2_fft_size ); // q = q_pFilter + fft_rel_fx32( pFilter, fft_size, log2_fft_size ); // q_pFilter /* Copy data to the output with format conversion */ - pH_flt[0][0] = pFilter[0]; + pH_flt[0][0] = pFilter[0]; // q_pFilter move32(); - pH_flt[half_fft_size][0] = pFilter[half_fft_size]; + pH_flt[half_fft_size][0] = pFilter[half_fft_size]; // q_pFilter move32(); pH_flt[0][1] = 0; move32(); @@ -588,9 +592,9 @@ static void apply_window_fft_fx( move32(); FOR( idx = 1; idx < half_fft_size; idx++ ) { - pH_flt[idx][0] = pFilter[idx]; + pH_flt[idx][0] = pFilter[idx]; // q_pFilter move32(); - pH_flt[idx][1] = pFilter[sub( fft_size, idx )]; + pH_flt[idx][1] = pFilter[fft_size - idx]; // q_pFilter move32(); } @@ -665,28 +669,40 @@ static void response_step_limit( return; } #else - static void response_step_limit_fx( - Word32 *X, + Word32 *X, // Q30 const Word16 dim_x, const Word16 pivot_bin_idx ) { Word16 i; - const Word32 positive_step_limit_lf = 1701766107; - const Word32 negative_step_limit_lf = 677485289; // 1.0f / positive_step_limit_lf = 0.63095734448019324;//q = 30 - const Word32 positive_step_limit_hf = 1276144549; - const Word32 negative_step_limit_hf = 903441154; // 1.0f / positive_step_limit_hf = 1.26209271246779263; //q = 30 + const Word32 positive_step_limit_lf = 1701766107; // Q30 + const Word32 negative_step_limit_lf = 677485289; // 1.0f / positive_step_limit_lf = 0.63095734448019324;//q = 30 + const Word32 positive_step_limit_hf = 1276144549; // Q30 + const Word32 negative_step_limit_hf = 903441154; // 1.0f / positive_step_limit_hf = 1.26209271246779263; //q = 30 + move32(); + move32(); + move32(); + move32(); /* Go up from pivot frequency and limit the slope to the maximum given by T. */ FOR( i = add( pivot_bin_idx, 1 ); i < dim_x; i++ ) { Word16 div_e; - Word32 desiredChange = BASOP_Util_Divide3232_Scale_cadence( X[i], X[i - 1], &div_e ); - Word16 desiredChange_q = sub( 31, ( div_e ) ); + Word32 desiredChange = 0; + move32(); + Word16 desiredChange_q = Q31; + move16(); Word64 temp; + + IF( X[i] ) + { + desiredChange = BASOP_Util_Divide3232_Scale_cadence( X[i], X[i - 1], &div_e ); + desiredChange_q = sub( 31, ( div_e ) ); + } + IF( GT_16( desiredChange_q, 30 ) ) { - desiredChange = L_shr( desiredChange, desiredChange_q - 30 ); + desiredChange = L_shr( desiredChange, sub( desiredChange_q, 30 ) ); // Q30 desiredChange_q = 30; move16(); } @@ -694,23 +710,23 @@ static void response_step_limit_fx( IF( GE_32( X[i], X[i - 1] ) ) { - IF( GT_32( change, L_shr( positive_step_limit_hf, 30 - desiredChange_q ) ) ) + IF( GT_32( change, L_shr( positive_step_limit_hf, sub( 30, desiredChange_q ) ) ) ) { - change = positive_step_limit_hf; // q = 30; + change = positive_step_limit_hf; // Q30 move32(); - temp = W_mult0_32_32( X[i - 1], change ); - X[i] = (Word32) W_shr( temp, 30 ); + temp = W_mult0_32_32( X[i - 1], change ); // Q30+Q30 + X[i] = (Word32) W_shr( temp, 30 ); // Q30 move32(); } } ELSE { - IF( LT_32( change, L_shr( negative_step_limit_hf, 30 - desiredChange_q ) ) ) + IF( LT_32( change, L_shr( negative_step_limit_hf, sub( 30, desiredChange_q ) ) ) ) { - change = negative_step_limit_hf; // q = 30; + change = negative_step_limit_hf; // Q30; move32(); - temp = W_mult0_32_32( X[i - 1], change ); - X[i] = (Word32) W_shr( temp, 30 ); + temp = W_mult0_32_32( X[i - 1], change ); // Q30+Q30 + X[i] = (Word32) W_shr( temp, 30 ); // Q30 move32(); } } @@ -720,12 +736,20 @@ static void response_step_limit_fx( FOR( i = sub( pivot_bin_idx, 1 ); i >= 0; i-- ) { Word16 div_e; - Word32 desiredChange = BASOP_Util_Divide3232_Scale_cadence( X[i], X[i + 1], &div_e ); - Word16 desiredChange_q = sub( 31, ( div_e ) ); + Word32 desiredChange = 0; + move32(); + Word16 desiredChange_q = Q31; + move16(); Word64 temp; + + IF( X[i] ) + { + desiredChange = BASOP_Util_Divide3232_Scale_cadence( X[i], X[i + 1], &div_e ); + desiredChange_q = sub( 31, ( div_e ) ); + } IF( GT_16( desiredChange_q, 30 ) ) { - desiredChange = L_shr( desiredChange, desiredChange_q - 30 ); + desiredChange = L_shr( desiredChange, sub( desiredChange_q, 30 ) ); // Q30 desiredChange_q = 30; move16(); } @@ -735,10 +759,10 @@ static void response_step_limit_fx( { IF( GT_32( change, L_shr( positive_step_limit_lf, sub( 30, desiredChange_q ) ) ) ) { - change = positive_step_limit_lf; // q = 30; + change = positive_step_limit_lf; // Q30 move32(); - temp = W_mult0_32_32( X[i + 1], change ); - X[i] = (Word32) W_shr( temp, 30 ); + temp = W_mult0_32_32( X[i + 1], change ); // Q30 + Q30 + X[i] = (Word32) W_shr( temp, 30 ); // Q30 move32(); } } @@ -746,10 +770,10 @@ static void response_step_limit_fx( { IF( LT_32( change, L_shr( negative_step_limit_lf, sub( 30, desiredChange_q ) ) ) ) { - change = negative_step_limit_lf; // q = 30; + change = negative_step_limit_lf; // Q30 move32(); - temp = W_mult0_32_32( X[i + 1], change ); - X[i] = (Word32) W_shr( temp, 30 ); + temp = W_mult0_32_32( X[i + 1], change ); // Q30 + Q30 + X[i] = (Word32) W_shr( temp, 30 ); // Q30 move32(); } } @@ -803,7 +827,6 @@ void ivas_reverb_define_window_fft( return; } #else - void ivas_reverb_define_window_fft_fx( Word32 *pWindow, // output in Q31 const Word16 transitionStart, @@ -819,32 +842,32 @@ void ivas_reverb_define_window_fft_fx( /* The first portion of the sequence is kept unchanged, window == 1 */ FOR( idx = 0; idx < transitionStart; idx++ ) { - pWindow[idx] = ONE_IN_Q31; // q31 + pWindow[idx] = ONE_IN_Q31; // Q31 move32(); } /* Adding Hann half-window for smooth transition */ Word16 s1 = sub( norm_s( shr( EVS_PI_FX, 1 ) ), 1 ); Word16 s2 = norm_s( sub( shl( transitionLength, 1 ), 1 ) ); - Word16 var1 = shl( EVS_PI_FX, s1 ); + Word16 var1 = shl( EVS_PI_FX, s1 ); // Q13+s1 Word16 var2 = shl( sub( shl( transitionLength, 1 ), 1 ), s2 ); - angle_increment = div_s( shr( var1, 5 ), var2 ); // q = 15 + angle_increment = div_s( shr( var1, 5 ), var2 ); // Q15 /* Initial angle set to match Hann window alignment in Matlab */ - initial_angle = shr( add( ( EVS_PI_FX ), shr( angle_increment, 2 ) ), 1 ); // q = 13 + initial_angle = shr( add( ( EVS_PI_FX ), shr( angle_increment, 2 ) ), 1 ); // Q13 FOR( idx = 0; idx < transitionLength; idx++ ) { - const Word16 sine_value = getSineWord16R2( mult( add( initial_angle, shl( mult( shl( idx, 8 ), angle_increment ), 5 ) ), 20858 ) ); // q31 + const Word16 sine_value = getSineWord16R2( mult( add( initial_angle, shl( mult( shl( idx, 8 ), angle_increment ), 5 ) ), 20858 ) ); // Q31 - pWindow[add( idx, transitionStart )] = L_mult( sine_value, sine_value ); + pWindow[idx + transitionStart] = L_mult( sine_value, sine_value ); // Q31 move32(); } /* Padding the rest with zeros */ FOR( idx = add( transitionStart, transitionLength ); idx < fftLength; idx++ ) { - pWindow[idx] = 0; + pWindow[idx] = 0; // Q31 move32(); } @@ -901,12 +924,12 @@ int16_t ivas_reverb_calc_color_filters( #endif #ifdef IVAS_FLOAT_FIXED Word16 ivas_reverb_calc_color_filters_fx( - const Word32 *pTargetL, - const Word32 *pTargetR, - const Word32 *pWindow, + const Word32 *pTargetL, // Q30 + const Word32 *pTargetR, // Q30 + const Word32 *pWindow, // Q30 const Word16 fft_size, - rv_fftwf_type_complex_fx *pBeqL, - rv_fftwf_type_complex_fx *pBeqR, + rv_fftwf_type_complex_fx *pBeqL, // q_pBeqL + rv_fftwf_type_complex_fx *pBeqR, // q_pBeqR Word16 *q_pBeqL, Word16 *q_pBeqR ) { @@ -915,11 +938,11 @@ Word16 ivas_reverb_calc_color_filters_fx( half_fft_size = shr( fft_size, 1 ); FOR( idx = 0; idx <= half_fft_size; idx++ ) { - pBeqL[idx][0] = L_shl( pTargetL[idx], 1 ); + pBeqL[idx][0] = L_shl( pTargetL[idx], 1 ); // Q31 move32(); pBeqL[idx][1] = 0; move32(); - pBeqR[idx][0] = L_shl( pTargetR[idx], 1 ); + pBeqR[idx][0] = L_shl( pTargetR[idx], 1 ); // Q31 move32(); pBeqR[idx][1] = 0; move32(); @@ -1155,7 +1178,6 @@ void ivas_reverb_calc_color_levels( return; } #else - void ivas_reverb_calc_color_levels_fx( const Word32 output_Fs, const Word16 freq_count, @@ -1212,9 +1234,9 @@ void ivas_reverb_calc_color_levels_fx( /* Obtaining T60 filters coefficients for the current loop */ FOR( i = 0; i < nrcoefs; i++ ) { - coefA[i] = pT60_filter_coeff[add( i_mult( shl( nrcoefs, 1 ), loop_idx ), add( i, nrcoefs ) )]; // q = 31 + coefA[i] = pT60_filter_coeff[2 * nrcoefs * loop_idx + i + nrcoefs]; // q = 31 move32(); - coefB[i] = pT60_filter_coeff[add( i_mult( shl( nrcoefs, 1 ), loop_idx ), i )]; // // q = 31 + coefB[i] = pT60_filter_coeff[2 * nrcoefs * loop_idx + i]; // // q = 31 move32(); } t60_e[freq_count] = -100; @@ -1253,7 +1275,7 @@ void ivas_reverb_calc_color_levels_fx( /* Dividing by the number of loops to compute the average T60 estimate */ FOR( freq_idx = 0; freq_idx < freq_count; freq_idx++ ) { - t60[freq_idx] = Mpy_32_32( t60[freq_idx], L_shl( loop_count_inverted, 16 ) ); + t60[freq_idx] = Mpy_32_32( t60[freq_idx], L_shl( loop_count_inverted, 16 ) ); // t60_e[freq_idx] + 31 - 15 + 16 move32(); } @@ -1393,11 +1415,11 @@ void ivas_reverb_interpolate_acoustic_data_fx( const Word32 *pInput_t60, // input in Q26 const Word32 *pInput_dsr, // input in Q30 const Word16 output_table_size, - const Word32 *pOutput_fc, - Word32 *pOutput_t60, - Word32 *pOutput_dsr, - Word16 *pOutput_t60_e, // output e - Word16 *pOutput_dsr_e // output e + const Word32 *pOutput_fc, // Q16 + Word32 *pOutput_t60, // pOutput_t60_e + Word32 *pOutput_dsr, // pOutput_dsr_e + Word16 *pOutput_t60_e, // output e + Word16 *pOutput_dsr_e // output e ) { Word16 input_idx, output_idx; @@ -1640,10 +1662,10 @@ void ivas_reverb_get_hrtf_set_properties( #else void ivas_reverb_get_hrtf_set_properties_fx( - Word32 **ppHrtf_set_L_re, - Word32 **ppHrtf_set_L_im, - Word32 **ppHrtf_set_R_re, - Word32 **ppHrtf_set_R_im, + Word32 **ppHrtf_set_L_re, // Q29 + Word32 **ppHrtf_set_L_im, // Q29 + Word32 **ppHrtf_set_R_re, // Q29 + Word32 **ppHrtf_set_R_im, // Q29 const AUDIO_CONFIG input_audio_config, const Word16 hrtf_count, const Word16 in_freq_count, @@ -1658,6 +1680,18 @@ void ivas_reverb_get_hrtf_set_properties_fx( { MAX_WORD16, 0, MAX_WORD16 }, { MAX_WORD16, 0, -MAX_WORD16 } }; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); const Word32 inp_freq_step = divide3232( ONE_IN_Q22, L_shl( in_freq_count, 23 ) ); // q= 15 const Word32 inp_freq_offset = L_shr( inp_freq_step, 1 ); // q= 15 const Word16 out_freq_step = divide3232( ONE_IN_Q21, L_shl( L_sub( out_freq_count, 1 ), 22 ) ); // q = 15 @@ -1726,7 +1760,7 @@ void ivas_reverb_get_hrtf_set_properties_fx( IF( GT_32( base_idx, L_sub( in_freq_count, 2 ) ) ) /* In case of extrapolation (above last bin), choose nearest */ { base_idx = L_sub( in_freq_count, 2 ); - relative_pos = ONE_IN_Q31; + relative_pos = ONE_IN_Q31; // Q31 move32(); } } @@ -1764,10 +1798,10 @@ void ivas_reverb_get_hrtf_set_properties_fx( /* In case of 5.1 or 7.1 formats, use the available HRTF paires directly*/ IF( !is_ambisonics ) { - current_base_L_ptr_re = ( ppHrtf_set_L_re[hrtf_idx] + base_idx ); - current_base_R_ptr_re = ( ppHrtf_set_R_re[hrtf_idx] + base_idx ); - current_base_L_ptr_im = ( ppHrtf_set_L_im[hrtf_idx] + base_idx ); - current_base_R_ptr_im = ( ppHrtf_set_R_im[hrtf_idx] + base_idx ); + current_base_L_ptr_re = ( ppHrtf_set_L_re[hrtf_idx] + base_idx ); // Q29 + current_base_R_ptr_re = ( ppHrtf_set_R_re[hrtf_idx] + base_idx ); // Q29 + current_base_L_ptr_im = ( ppHrtf_set_L_im[hrtf_idx] + base_idx ); // Q29 + current_base_R_ptr_im = ( ppHrtf_set_R_im[hrtf_idx] + base_idx ); // Q29 } /* In case of FOA format, combine the W channel with the X/Y channels */ @@ -1786,31 +1820,31 @@ void ivas_reverb_get_hrtf_set_properties_fx( FOR( ch_index = 0; ch_index < 3; ch_index++ ) { - combined_channels_L_re[freq_idx] = L_add( combined_channels_L_re[freq_idx], Mpy_32_16_1( ppHrtf_set_L_re[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); + combined_channels_L_re[freq_idx] = L_add( combined_channels_L_re[freq_idx], Mpy_32_16_1( ppHrtf_set_L_re[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); // Q29 + Q15 - 15 move32(); - combined_channels_R_re[freq_idx] = L_add( combined_channels_R_re[freq_idx], Mpy_32_16_1( ppHrtf_set_R_re[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); + combined_channels_R_re[freq_idx] = L_add( combined_channels_R_re[freq_idx], Mpy_32_16_1( ppHrtf_set_R_re[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); // Q29 + Q15 - 15 move32(); - combined_channels_L_im[freq_idx] = L_add( combined_channels_L_im[freq_idx], Mpy_32_16_1( ppHrtf_set_L_im[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); + combined_channels_L_im[freq_idx] = L_add( combined_channels_L_im[freq_idx], Mpy_32_16_1( ppHrtf_set_L_im[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); // Q29 + Q15 - 15 move32(); - combined_channels_R_im[freq_idx] = L_add( combined_channels_R_im[freq_idx], Mpy_32_16_1( ppHrtf_set_R_im[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); + combined_channels_R_im[freq_idx] = L_add( combined_channels_R_im[freq_idx], Mpy_32_16_1( ppHrtf_set_R_im[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); // Q29 + Q15 - 15 move32(); } } - current_base_L_ptr_re = &combined_channels_L_re[0]; - current_base_R_ptr_re = &combined_channels_R_re[0]; - current_base_L_ptr_im = &combined_channels_L_im[0]; - current_base_R_ptr_im = &combined_channels_R_im[0]; + current_base_L_ptr_re = &combined_channels_L_re[0]; // Q29 + current_base_R_ptr_re = &combined_channels_R_re[0]; // Q29 + current_base_L_ptr_im = &combined_channels_L_im[0]; // Q29 + current_base_R_ptr_im = &combined_channels_R_im[0]; // Q29 } FOR( freq_idx = 0; freq_idx < 2; freq_idx++ ) { Word32 L_re, L_im, R_re, R_im, C_re; - L_re = current_base_L_ptr_re[freq_idx]; // q = 29 - R_re = current_base_R_ptr_re[freq_idx]; // q = 29 - L_im = current_base_L_ptr_im[freq_idx]; // q = 29 - R_im = current_base_R_ptr_im[freq_idx]; // q = 29 + L_re = current_base_L_ptr_re[freq_idx]; // Q29 + R_re = current_base_R_ptr_re[freq_idx]; // Q29 + L_im = current_base_L_ptr_im[freq_idx]; // Q29 + R_im = current_base_R_ptr_im[freq_idx]; // Q29 move32(); move32(); move32(); @@ -1855,9 +1889,9 @@ void ivas_reverb_get_hrtf_set_properties_fx( IA_coherence[freq_idx] = L_shl( IA_coherence[freq_idx], sub( 27, sub( 15, temp ) ) ); // q = 27 move32(); /* Limiting to (0...1) range in case of small numerical errors or negative values */ - IA_coherence[freq_idx] = min( IA_coherence[freq_idx], ONE_IN_Q27 ); + IA_coherence[freq_idx] = min( IA_coherence[freq_idx], ONE_IN_Q27 ); // Q27 move32(); - IA_coherence[freq_idx] = max( IA_coherence[freq_idx], 0 ); + IA_coherence[freq_idx] = max( IA_coherence[freq_idx], 0 ); // Q27 move32(); } diff --git a/lib_rend/ivas_reverb_iir_filter.c b/lib_rend/ivas_reverb_iir_filter.c index 85245aadcccfb44dc15fde8aa3d2d928662de202..5ec718a3fdd2aaa20249f817e60f10f5fdcbc444 100644 --- a/lib_rend/ivas_reverb_iir_filter.c +++ b/lib_rend/ivas_reverb_iir_filter.c @@ -63,9 +63,9 @@ void ivas_reverb_iir_filt_init( FOR( UWord16 i = 0; i < maxTaps; i++ ) { - iirFilter->CoefA_fx[i] = 0; + iirFilter->CoefA_fx[i] = 0; /*Q30*/ move32(); - iirFilter->CoefB_fx[i] = 0; + iirFilter->CoefB_fx[i] = 0; /*Q30*/ move32(); } @@ -111,8 +111,8 @@ void ivas_reverb_iir_filt_init( void ivas_reverb_iir_filt_set( ivas_rev_iir_filter_t *iirFilter, /* i/o: IIR filter */ UWord16 nr_taps, /* i : number of IIR filter taps */ - const Word16 *coefA, /* i : A filter coefficients to set */ - const Word16 *coefB /* i : the B filter coefficients to set */ + const Word16 *coefA, /* i : A filter coefficients to set Q14*/ + const Word16 *coefB /* i : the B filter coefficients to set Q14*/ ) { UWord16 i; @@ -132,7 +132,7 @@ void ivas_reverb_iir_filt_set( { FOR( i = 0; i < iirFilter->nr_taps; i++ ) { - iirFilter->CoefB_fx[i] = L_shl( coefB[i], 16 ); /*Q30*/ + iirFilter->CoefB_fx[i] = L_shl( coefB[i] /*Q14*/, 16 ); /*Q30*/ move32(); } } @@ -140,9 +140,9 @@ void ivas_reverb_iir_filt_set( { FOR( i = 0; i < iirFilter->nr_taps; i++ ) { - iirFilter->CoefA_fx[i] = L_shl( coefA[i], 16 ); /*Q30*/ + iirFilter->CoefA_fx[i] = L_shl( coefA[i] /*Q14*/, 16 ); /*Q30*/ move32(); - iirFilter->CoefB_fx[i] = L_shl( coefB[i], 16 ); /*Q30*/ + iirFilter->CoefB_fx[i] = L_shl( coefB[i] /*Q14*/, 16 ); /*Q30*/ move32(); } } @@ -202,35 +202,35 @@ void ivas_reverb_iir_filt_set( void ivas_reverb_iir_filt_2taps_feed_blk_fx( ivas_rev_iir_filter_t *iirFilter, /* i/o: IIR filter */ const UWord16 blk_size, /* i : size */ - const Word32 *input, /* i : input buffer */ - Word32 *output /* i : output buffer */ + const Word32 *input, /* i : input buffer Q30 */ + Word32 *output /* i/o : output buffer Q30 */ ) { UWord16 i; Word32 flt_output_fx = 0; move32(); - Word32 flt_CoefB_0_fx = iirFilter->CoefB_fx[0]; + Word32 flt_CoefB_0_fx = iirFilter->CoefB_fx[0]; /*Q30*/ move32(); - Word32 flt_CoefB_1_fx = iirFilter->CoefB_fx[1]; + Word32 flt_CoefB_1_fx = iirFilter->CoefB_fx[1]; /*Q30*/ move32(); - Word32 flt_CoefA_1_fx = iirFilter->CoefA_fx[1]; + Word32 flt_CoefA_1_fx = iirFilter->CoefA_fx[1]; /*Q30*/ move32(); - Word32 flt_pBuffer_0_fx = iirFilter->pBuffer_fx[0]; + Word32 flt_pBuffer_0_fx = iirFilter->pBuffer_fx[0]; /*Q30*/ move32(); - Word32 flt_pBuffer_1_fx = iirFilter->pBuffer_fx[1]; + Word32 flt_pBuffer_1_fx = iirFilter->pBuffer_fx[1]; /*Q30*/ move32(); FOR( i = 0; i < blk_size; i++ ) { - flt_output_fx = L_add( L_shl( Mpy_32_32( input[i], flt_CoefB_0_fx ), 1 ), flt_pBuffer_0_fx ); - flt_pBuffer_0_fx = L_sub( L_add( flt_pBuffer_1_fx, L_shl( Mpy_32_32( input[i], flt_CoefB_1_fx ), 1 ) ), L_shl( Mpy_32_32( flt_output_fx, flt_CoefA_1_fx ), 1 ) ); - output[i] = flt_output_fx; + flt_output_fx = L_add( L_shl( Mpy_32_32( input[i], flt_CoefB_0_fx ), 1 ), flt_pBuffer_0_fx ); // Q30 + flt_pBuffer_0_fx = L_sub( L_add( flt_pBuffer_1_fx /*Q30*/, L_shl( Mpy_32_32( input[i] /*Q30*/, flt_CoefB_1_fx /*Q30*/ ) /*Q29*/, 1 ) /*Q30*/ ), L_shl( Mpy_32_32( flt_output_fx /*Q30*/, flt_CoefA_1_fx /*Q30*/ ), 1 /*Q30*/ ) ); /*Q30*/ + output[i] = flt_output_fx; /*Q30*/ move32(); } - iirFilter->pBuffer_fx[0] = flt_pBuffer_0_fx; + iirFilter->pBuffer_fx[0] = flt_pBuffer_0_fx; /*Q30*/ move32(); - iirFilter->pBuffer_fx[1] = flt_pBuffer_1_fx; + iirFilter->pBuffer_fx[1] = flt_pBuffer_1_fx; /*Q30*/ move32(); - iirFilter->Output_fx = flt_output_fx; + iirFilter->Output_fx = flt_output_fx; // Q30 move32(); return; diff --git a/lib_rend/ivas_rom_binaural_crend_head.c b/lib_rend/ivas_rom_binaural_crend_head.c index a34162e4919cc87244f19e09a8a7fa475ab1a5c6..d688ccdedf13adcf2114e5fef5745ad5cc4d9914 100644 --- a/lib_rend/ivas_rom_binaural_crend_head.c +++ b/lib_rend/ivas_rom_binaural_crend_head.c @@ -678,7 +678,7 @@ const Word32 *CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS #ifndef IVAS_FLOAT_FIXED const float CRendBin_FOA_HRIR_latency_s = 0.000020834f; #else -const Word32 CRendBin_FOA_HRIR_latency_s_fx = 44741; +const Word32 CRendBin_FOA_HRIR_latency_s_fx = 44741; // Q31 #endif // IVAS_FLOAT_FIXED /* Sample Rate = 48000 */ @@ -904,7 +904,7 @@ const Word32 *CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]={NU #ifndef IVAS_FLOAT_FIXED const float CRendBin_HOA2_HRIR_latency_s = 0.000020834f; #else -const Word32 CRendBin_HOA2_HRIR_latency_s_fx = 44741; +const Word32 CRendBin_HOA2_HRIR_latency_s_fx = 44741; // Q31 #endif // IVAS_FLOAT_FIXED /* Sample Rate = 48000 */ diff --git a/lib_rend/ivas_rom_rend.c b/lib_rend/ivas_rom_rend.c index b78c6fba1d17349b54b9e0dc741a08c464e53708..ae3482a4fc0699d8dc1a4e1d60c353e3e8de43d8 100644 --- a/lib_rend/ivas_rom_rend.c +++ b/lib_rend/ivas_rom_rend.c @@ -204,9 +204,9 @@ const float * const ap_lattice_coeffs[DIRAC_DECORR_NUM_SPLIT_BANDS] = }; #else -const Word16 ap_lattice_coeffs_1_fx[330] = { 26061, 16472, 6699, 13650, 15061, 8862, -6617, 917, 2222, -1724, -1270, -1880, 671, 12048, -19454, 17487, 6635, -63, 6392, -6044, -7663, 7474, -10790, -11098, -2611, 1716, -310, 5859, 6253, -15691, 1442, 25837, 4375, -5690, 17871, 22329, 10907, 9656, 10658, 1560, 5157, 3810, 7175, -6201, -10400, -24696, 25309, -16625, 9076, -22700, 7612, -11624, -511, -7309, 10174, -1147, 2810, -16383, 7053, 6599, -16238, -9884, 6439, 10687, -19476, 10319, 21911, 2511, 1497, -4089, -6660, -9738, 4122, -5881, -6611, 5279, 12977, 8745, 11684, 15995, -1843, 4563, -9712, -3697, 1225, -12039, -7087, -9088, 12760, 3772, -7879, -8880, 13982, -362, 4974, 8306, 7397, 16341, -4468, 14516, -9994, -1025, -352, 5581, 16268, -4583, -7929, -3435, 9645, -2219, -16128, -15978, 1192, 3584, 12981, -11562, -6747, -2719, -15172, -10135, 848, -3029, -4100, -5115, -160, 5847, 2935, 1468, 7805, -10227, -12802, -5850, 14890, 12681, -12742, -6481, 1164, 14922, -1782, 12452, 9534, 1599, 2576, 7265, -7128, 3974, -12998, -7159, -4170, -8831, -11279, -15238, -13808, -852, 7259, 11861, -11411, 9666, 11998, 2315, -2819, 8261, 5113, -2057, 13401, 7944, -9888, -2167, 12735, -15146, -5206, 7562, -3053, 1542, 2405, -10977, 751, 11619, 2372, 638, 11039, -15746, 5579, 8508, -12896, -11422, -3570, 9137, 12631, 11870, -10444, 11872, 9467, 9542, -9110, -14722, -9453, -13565, -13280, -9671, -8031, 82, 9433, 11410, -5844, -6767, 11504, -15800, 699, -16128, 1593, 14853, 3576, 7621, -15524, 4603, 11551, -3231, 4822, -1828, 3530, -7570, 11708, 11404, 7615, -10642, 5324, 1888, -1990, -319, -7346, -9252, -2144, 2119, 9187, -9335, -15417, 638, -14493, 12360, 14659, -9519, 11322, 12130, -10260, 3918, 9830, 13336, -9106, 14648, 6383, 5167, -7320, -4822, 12421, -7089, 4520, -13014, 2421, -8949, -14517, -5515, 11346, 1230, 2142, 5370, -4014, 11975, -10365, 3842, -9872, 5558, -11025, 8844, -13767, -10855, 16335, -12878, -15144, -10587, 15432, -11778, 8661, 7104, 16167, 4963, -10539, 15217, -11654, 13775, 6039, -9900, 4474, -8285, 6353, 9790, 7825, -12658, -5963, -2533, 4090, -8630, 12766, 147, 11134, 13605, 12378, 13114, 11548, -124, -6046, 14199, -7784, 4839, 13343, 2215, -8169, -11600, 10516, 13959, 10144, -6215, -6863, 5209, -2684, 12675, 5851, -13341, 7280, -4885, }; -const Word16 ap_lattice_coeffs_2_fx[132] = { 20764, 22321, -1619, 9395, 4784, 4436, -13439, -6775, -21527, -3334, 14296, 11135, -4305, -25354, -9883, 10733, 10886, 6745, 23514, -18100, -4919, 1787, 7848, -21249, -23653, 6205, 2234, 203, 2523, 1267, 13874, -3560, 14157, -13586, 9104, 13712, 2549, -9275, -11698, 151, -14504, -12200, 13216, 7963, 10301, 14565, 11387, 16254, 3552, 15380, -5579, 10692, 5641, 14428, 1914, 11130, -6388, 16096, -9217, -1412, -15810, -10977, -11015, 6437, -5394, 14499, -4429, -11612, 14815, -10198, -11391, 16329, -9469, 12334, -5830, 6407, 10940, -5003, 1744, 15000, 14499, 7708, -11310, -9374, 5093, 13283, 7113, -3537, 350, 12090, -16330, -16246, -7060, -3075, 10494, -453, 16036, 15427, -2157, 11366, 893, 4918, 15860, -16298, 5531, -16182, -5686, 10966, 8658, -13914, -10319, 8293, 13021, -16107, -14867, -15183, -626, 11, 10336, 15477, 3117, 9285, -7375, -3924, -15626, 1229, 11041, 16204, -2051, 5821, 15200, 16032, }; -const Word16 ap_lattice_coeffs_3_fx[66] = { 621, -6953, 13851, -13128, -3502, -805, 4587, 9161, 1060, 20726, 18957, -24071, 563, 433, -908, -11578, -15799, -16097, 14975, 5410, 15391, -6412, 14421, -15642, 11802, -16074, 15880, -5694, 247, 9115, 14234, 1977, -6347, -1104, 16260, 96, -15756, -3589, -760, 10639, -9570, -11670, -12012, 12481, -9887, 3614, 12575, 9960, -16373, -11455, 10969, -662, -14092, -5069, -12161, 10947, 11367, -5465, -7506, 3865, 11183, 16071, 16176, -12049, 13976, -1499, }; +const Word16 ap_lattice_coeffs_1_fx[330] /* Q15 */ = { 26061, 16472, 6699, 13650, 15061, 8862, -6617, 917, 2222, -1724, -1270, -1880, 671, 12048, -19454, 17487, 6635, -63, 6392, -6044, -7663, 7474, -10790, -11098, -2611, 1716, -310, 5859, 6253, -15691, 1442, 25837, 4375, -5690, 17871, 22329, 10907, 9656, 10658, 1560, 5157, 3810, 7175, -6201, -10400, -24696, 25309, -16625, 9076, -22700, 7612, -11624, -511, -7309, 10174, -1147, 2810, -16383, 7053, 6599, -16238, -9884, 6439, 10687, -19476, 10319, 21911, 2511, 1497, -4089, -6660, -9738, 4122, -5881, -6611, 5279, 12977, 8745, 11684, 15995, -1843, 4563, -9712, -3697, 1225, -12039, -7087, -9088, 12760, 3772, -7879, -8880, 13982, -362, 4974, 8306, 7397, 16341, -4468, 14516, -9994, -1025, -352, 5581, 16268, -4583, -7929, -3435, 9645, -2219, -16128, -15978, 1192, 3584, 12981, -11562, -6747, -2719, -15172, -10135, 848, -3029, -4100, -5115, -160, 5847, 2935, 1468, 7805, -10227, -12802, -5850, 14890, 12681, -12742, -6481, 1164, 14922, -1782, 12452, 9534, 1599, 2576, 7265, -7128, 3974, -12998, -7159, -4170, -8831, -11279, -15238, -13808, -852, 7259, 11861, -11411, 9666, 11998, 2315, -2819, 8261, 5113, -2057, 13401, 7944, -9888, -2167, 12735, -15146, -5206, 7562, -3053, 1542, 2405, -10977, 751, 11619, 2372, 638, 11039, -15746, 5579, 8508, -12896, -11422, -3570, 9137, 12631, 11870, -10444, 11872, 9467, 9542, -9110, -14722, -9453, -13565, -13280, -9671, -8031, 82, 9433, 11410, -5844, -6767, 11504, -15800, 699, -16128, 1593, 14853, 3576, 7621, -15524, 4603, 11551, -3231, 4822, -1828, 3530, -7570, 11708, 11404, 7615, -10642, 5324, 1888, -1990, -319, -7346, -9252, -2144, 2119, 9187, -9335, -15417, 638, -14493, 12360, 14659, -9519, 11322, 12130, -10260, 3918, 9830, 13336, -9106, 14648, 6383, 5167, -7320, -4822, 12421, -7089, 4520, -13014, 2421, -8949, -14517, -5515, 11346, 1230, 2142, 5370, -4014, 11975, -10365, 3842, -9872, 5558, -11025, 8844, -13767, -10855, 16335, -12878, -15144, -10587, 15432, -11778, 8661, 7104, 16167, 4963, -10539, 15217, -11654, 13775, 6039, -9900, 4474, -8285, 6353, 9790, 7825, -12658, -5963, -2533, 4090, -8630, 12766, 147, 11134, 13605, 12378, 13114, 11548, -124, -6046, 14199, -7784, 4839, 13343, 2215, -8169, -11600, 10516, 13959, 10144, -6215, -6863, 5209, -2684, 12675, 5851, -13341, 7280, -4885, }; +const Word16 ap_lattice_coeffs_2_fx[132] /* Q15 */ = { 20764, 22321, -1619, 9395, 4784, 4436, -13439, -6775, -21527, -3334, 14296, 11135, -4305, -25354, -9883, 10733, 10886, 6745, 23514, -18100, -4919, 1787, 7848, -21249, -23653, 6205, 2234, 203, 2523, 1267, 13874, -3560, 14157, -13586, 9104, 13712, 2549, -9275, -11698, 151, -14504, -12200, 13216, 7963, 10301, 14565, 11387, 16254, 3552, 15380, -5579, 10692, 5641, 14428, 1914, 11130, -6388, 16096, -9217, -1412, -15810, -10977, -11015, 6437, -5394, 14499, -4429, -11612, 14815, -10198, -11391, 16329, -9469, 12334, -5830, 6407, 10940, -5003, 1744, 15000, 14499, 7708, -11310, -9374, 5093, 13283, 7113, -3537, 350, 12090, -16330, -16246, -7060, -3075, 10494, -453, 16036, 15427, -2157, 11366, 893, 4918, 15860, -16298, 5531, -16182, -5686, 10966, 8658, -13914, -10319, 8293, 13021, -16107, -14867, -15183, -626, 11, 10336, 15477, 3117, 9285, -7375, -3924, -15626, 1229, 11041, 16204, -2051, 5821, 15200, 16032, }; +const Word16 ap_lattice_coeffs_3_fx[66] /* Q15 */ = { 621, -6953, 13851, -13128, -3502, -805, 4587, 9161, 1060, 20726, 18957, -24071, 563, 433, -908, -11578, -15799, -16097, 14975, 5410, 15391, -6412, 14421, -15642, 11802, -16074, 15880, -5694, 247, 9115, 14234, 1977, -6347, -1104, 16260, 96, -15756, -3589, -760, 10639, -9570, -11670, -12012, 12481, -9887, 3614, 12575, 9960, -16373, -11455, 10969, -662, -14092, -5069, -12161, 10947, 11367, -5465, -7506, 3865, 11183, 16071, 16176, -12049, 13976, -1499, }; const Word16 * const ap_lattice_coeffs_fx[DIRAC_DECORR_NUM_SPLIT_BANDS] = { @@ -269,7 +269,7 @@ const float surCohEne[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS] = 3.0903f, 2.0053f, 1.0860f, 0.8072f, 0.7079f }; #else -const Word16 surCohEne_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS] = +const Word16 surCohEne_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS] /* Q13 */ = { 25315, 16427, 8896, 6612, 5799 }; @@ -302,7 +302,7 @@ const float lowBitRateBinauralEQ[LOW_BIT_RATE_BINAURAL_EQ_BINS] = 0.979f, 0.893f, 0.762f, 0.615f, 0.52f, 0.48f, 0.477f, 0.477f, 0.48f, 0.501f, 0.546f, 0.602f, 0.652f, 0.664f, 0.652f, 0.639f, 0.635f }; #else -const Word32 lowBitRateBinauralEQ_fx[LOW_BIT_RATE_BINAURAL_EQ_BINS] = +const Word32 lowBitRateBinauralEQ_fx[LOW_BIT_RATE_BINAURAL_EQ_BINS] /* Q31 */ = { 2102386432, 1917702912, 1636382592, 1320702464, 1116691456, 1030792128, 1024349696, 1024349696, 1030792128, 1075889280, 1172526080, 1292785152, 1400159360, 1425929088, 1400159360, 1372242048, 1363652096 @@ -1155,6 +1155,825 @@ const float ivas_reverb_default_DSR[IVAS_REVERB_DEFAULT_N_BANDS] = 6.2001e-08f, 2.8483e-08f, 2.6267e-08f }; +const Word32 release_cnst_table[4][201] = // Q31 + { + { + 1913946752, + 1919716352, + 1925351680, + 1930855552, + 1936230784, + 1941479808, + 1946605312, + 1951609728, + 1956495744, + 1961265792, + 1965922304, + 1970467584, + 1974904320, + 1979234560, + 1983460736, + 1987585024, + 1991609856, + 1995537280, + 1999369344, + 2003108480, + 2006756480, + 2010315520, + 2013787520, + 2017174528, + 2020478464, + 2023701248, + 2026844672, + 2029910656, + 2032900992, + 2035817344, + 2038661376, + 2041435008, + 2044139648, + 2046777088, + 2049348864, + 2051856384, + 2054301440, + 2056685312, + 2059009536, + 2061275520, + 2063484672, + 2065638272, + 2067737856, + 2069784448, + 2071779584, + 2073724416, + 2075620096, + 2077467904, + 2079268992, + 2081024512, + 2082735488, + 2084403200, + 2086028416, + 2087612544, + 2089156352, + 2090660864, + 2092127104, + 2093555968, + 2094948480, + 2096305408, + 2097627776, + 2098916352, + 2100172032, + 2101395584, + 2102587776, + 2103749504, + 2104881408, + 2105984384, + 2107059072, + 2108106112, + 2109126400, + 2110120448, + 2111088896, + 2112032512, + 2112951808, + 2113847552, + 2114720128, + 2115570304, + 2116398592, + 2117205504, + 2117991552, + 2118757504, + 2119503616, + 2120230400, + 2120938496, + 2121628288, + 2122300288, + 2122954880, + 2123592576, + 2124213760, + 2124818944, + 2125408384, + 2125982592, + 2126541952, + 2127086848, + 2127617664, + 2128134656, + 2128638336, + 2129128832, + 2129606784, + 2130072192, + 2130525568, + 2130967296, + 2131397376, + 2131816448, + 2132224640, + 2132622080, + 2133009408, + 2133386496, + 2133753856, + 2134111744, + 2134460288, + 2134799744, + 2135130368, + 2135452416, + 2135766144, + 2136071680, + 2136369152, + 2136659072, + 2136941312, + 2137216256, + 2137484160, + 2137744896, + 2137998976, + 2138246400, + 2138487424, + 2138722176, + 2138950656, + 2139173376, + 2139390208, + 2139601408, + 2139807104, + 2140007424, + 2140202624, + 2140392576, + 2140577664, + 2140758016, + 2140933504, + 2141104512, + 2141271040, + 2141433216, + 2141591168, + 2141745024, + 2141894912, + 2142040832, + 2142182912, + 2142321408, + 2142456192, + 2142587392, + 2142715264, + 2142839808, + 2142961152, + 2143079296, + 2143194240, + 2143306240, + 2143415424, + 2143521664, + 2143625216, + 2143725952, + 2143824128, + 2143919744, + 2144012800, + 2144103424, + 2144191744, + 2144277760, + 2144361472, + 2144443136, + 2144522496, + 2144599936, + 2144675200, + 2144748544, + 2144820096, + 2144889600, + 2144957440, + 2145023488, + 2145087744, + 2145150336, + 2145211264, + 2145270656, + 2145328512, + 2145384832, + 2145439616, + 2145493120, + 2145545088, + 2145595776, + 2145645056, + 2145693184, + 2145739904, + 2145785472, + 2145829888, + 2145873152, + 2145915136, + 2145956224, + 2145996032, + 2146034944, + 2146072832, + 2146109696, + 2146145664, + 2146180608, + 2146214656, + 2146247808, + }, + { + 2027355264, + 2030408704, + 2033386624, + 2036290944, + 2039123328, + 2041885440, + 2044578944, + 2047205376, + 2049766528, + 2052263680, + 2054698496, + 2057072384, + 2059387008, + 2061643520, + 2063843328, + 2065987968, + 2068078720, + 2070116864, + 2072103552, + 2074040192, + 2075927936, + 2077767936, + 2079561472, + 2081309568, + 2083013376, + 2084673920, + 2086292352, + 2087869696, + 2089406976, + 2090905216, + 2092365184, + 2093788032, + 2095174528, + 2096525824, + 2097842432, + 2099125632, + 2100375808, + 2101594240, + 2102781312, + 2103938048, + 2105065216, + 2106163456, + 2107233536, + 2108276096, + 2109292032, + 2110281728, + 2111246080, + 2112185728, + 2113101056, + 2113992960, + 2114861824, + 2115708288, + 2116532992, + 2117336448, + 2118119168, + 2118881792, + 2119624704, + 2120348416, + 2121053440, + 2121740288, + 2122409344, + 2123061120, + 2123696128, + 2124314624, + 2124917120, + 2125504128, + 2126075776, + 2126632832, + 2127175296, + 2127703808, + 2128218624, + 2128720000, + 2129208448, + 2129684352, + 2130147712, + 2130599168, + 2131038976, + 2131467264, + 2131884416, + 2132290816, + 2132686592, + 2133072256, + 2133447680, + 2133813504, + 2134169856, + 2134516864, + 2134854784, + 2135184000, + 2135504640, + 2135816960, + 2136121216, + 2136417536, + 2136706048, + 2136987136, + 2137260928, + 2137527552, + 2137787264, + 2138040192, + 2138286592, + 2138526464, + 2138760192, + 2138987776, + 2139209472, + 2139425408, + 2139635712, + 2139840512, + 2140039936, + 2140234240, + 2140423424, + 2140607744, + 2140787200, + 2140962048, + 2141132288, + 2141298048, + 2141459584, + 2141616896, + 2141769984, + 2141919232, + 2142064512, + 2142205952, + 2142343808, + 2142478080, + 2142608768, + 2142736128, + 2142860032, + 2142980864, + 2143098368, + 2143212928, + 2143324544, + 2143433088, + 2143538944, + 2143641984, + 2143742336, + 2143840000, + 2143935232, + 2144027904, + 2144118144, + 2144206080, + 2144291712, + 2144375168, + 2144456320, + 2144535424, + 2144612480, + 2144687488, + 2144760448, + 2144831616, + 2144900992, + 2144968448, + 2145034112, + 2145098112, + 2145160448, + 2145221248, + 2145280256, + 2145337856, + 2145393920, + 2145448576, + 2145501696, + 2145553536, + 2145603968, + 2145653120, + 2145700992, + 2145747456, + 2145792896, + 2145837056, + 2145880064, + 2145922048, + 2145962880, + 2146002560, + 2146041344, + 2146078976, + 2146115712, + 2146151424, + 2146186240, + 2146220160, + 2146253184, + 2146285312, + 2146316672, + 2146347136, + 2146376832, + 2146405760, + 2146433920, + 2146461440, + 2146488192, + 2146514176, + 2146539520, + 2146564224, + 2146588160, + 2146611584, + 2146634368, + 2146656640, + 2146678272, + 2146699264, + 2146719744, + 2146739712, + 2146759168, + 2146778112, + 2146796544, + 2146814464, + 2146832000, + 2146849024, + 2146865664, + }, + { + 2086555136, + 2088125824, + 2089656576, + 2091148416, + 2092602240, + 2094018944, + 2095399680, + 2096745088, + 2098056192, + 2099333888, + 2100578816, + 2101792000, + 2102974080, + 2104125824, + 2105248128, + 2106341760, + 2107407232, + 2108445440, + 2109456896, + 2110442496, + 2111402624, + 2112338176, + 2113249664, + 2114137728, + 2115002880, + 2115845760, + 2116666880, + 2117466880, + 2118246272, + 2119005568, + 2119745280, + 2120465920, + 2121167872, + 2121851776, + 2122517888, + 2123166976, + 2123799168, + 2124414976, + 2125014912, + 2125599360, + 2126168704, + 2126723200, + 2127263360, + 2127789568, + 2128302208, + 2128801408, + 2129287808, + 2129761536, + 2130222976, + 2130672512, + 2131110272, + 2131536768, + 2131952128, + 2132356736, + 2132750848, + 2133134720, + 2133508736, + 2133872896, + 2134227584, + 2134573184, + 2134909696, + 2135237504, + 2135556736, + 2135867648, + 2136170624, + 2136465536, + 2136752896, + 2137032832, + 2137305344, + 2137570816, + 2137829376, + 2138081280, + 2138326528, + 2138565504, + 2138798080, + 2139024768, + 2139245440, + 2139460480, + 2139669888, + 2139873792, + 2140072320, + 2140265856, + 2140454144, + 2140637696, + 2140816384, + 2140990464, + 2141159936, + 2141325056, + 2141485824, + 2141642368, + 2141794944, + 2141943424, + 2142088064, + 2142228992, + 2142366208, + 2142499840, + 2142630016, + 2142756736, + 2142880128, + 2143000448, + 2143117440, + 2143231488, + 2143342592, + 2143450752, + 2143556096, + 2143658624, + 2143758592, + 2143855872, + 2143950592, + 2144043008, + 2144132864, + 2144220416, + 2144305664, + 2144388608, + 2144469504, + 2144548224, + 2144624896, + 2144699648, + 2144772352, + 2144843264, + 2144912256, + 2144979328, + 2145044864, + 2145108480, + 2145170560, + 2145231104, + 2145289856, + 2145347200, + 2145403008, + 2145457408, + 2145510400, + 2145561984, + 2145612160, + 2145661056, + 2145708672, + 2145755136, + 2145800192, + 2145844224, + 2145887104, + 2145928832, + 2145969408, + 2146008960, + 2146047616, + 2146085120, + 2146121600, + 2146157184, + 2146191872, + 2146225664, + 2146258560, + 2146290560, + 2146321792, + 2146352128, + 2146381696, + 2146410496, + 2146438528, + 2146465920, + 2146492416, + 2146518400, + 2146543616, + 2146568192, + 2146592128, + 2146615424, + 2146638080, + 2146660224, + 2146681728, + 2146702720, + 2146723072, + 2146743040, + 2146762368, + 2146781184, + 2146799616, + 2146817408, + 2146834816, + 2146851840, + 2146868352, + 2146884352, + 2146900096, + 2146915328, + 2146930176, + 2146944640, + 2146958720, + 2146972416, + 2146985856, + 2146998784, + 2147011456, + 2147023872, + 2147035904, + 2147047552, + 2147058944, + 2147070080, + 2147080832, + 2147091456, + 2147101696, + 2147111680, + 2147121408, + 2147130880, + 2147140096, + 2147149056, + 2147157760, + 2147166336, + 2147174656, + }, + { + 2106670080, + 2107727232, + 2108757120, + 2109760640, + 2110738432, + 2111691008, + 2112619136, + 2113523328, + 2114404352, + 2115262592, + 2116098816, + 2116913408, + 2117707136, + 2118480256, + 2119233536, + 2119967360, + 2120682240, + 2121378688, + 2122057088, + 2122717952, + 2123361792, + 2123988992, + 2124599936, + 2125195136, + 2125774848, + 2126339584, + 2126889728, + 2127425536, + 2127947520, + 2128456064, + 2128951296, + 2129433856, + 2129903744, + 2130361600, + 2130807424, + 2131241728, + 2131664768, + 2132076928, + 2132478208, + 2132869248, + 2133250048, + 2133620992, + 2133982208, + 2134334080, + 2134676864, + 2135010688, + 2135335936, + 2135652608, + 2135961088, + 2136261504, + 2136554112, + 2136839168, + 2137116800, + 2137387136, + 2137650560, + 2137907072, + 2138156928, + 2138400256, + 2138637184, + 2138867968, + 2139092864, + 2139311744, + 2139524992, + 2139732736, + 2139934976, + 2140131968, + 2140323840, + 2140510720, + 2140692736, + 2140870016, + 2141042688, + 2141210752, + 2141374592, + 2141534080, + 2141689344, + 2141840640, + 2141987968, + 2142131456, + 2142271232, + 2142407424, + 2142539904, + 2142669056, + 2142794752, + 2142917248, + 2143036544, + 2143152640, + 2143265792, + 2143375872, + 2143483264, + 2143587712, + 2143689472, + 2143788544, + 2143885056, + 2143979136, + 2144070656, + 2144159872, + 2144246656, + 2144331264, + 2144413568, + 2144493824, + 2144571904, + 2144647936, + 2144722048, + 2144794240, + 2144864512, + 2144932864, + 2144999552, + 2145064448, + 2145127680, + 2145189248, + 2145249152, + 2145307520, + 2145364480, + 2145419776, + 2145473792, + 2145526272, + 2145577472, + 2145627264, + 2145675776, + 2145723008, + 2145768960, + 2145813760, + 2145857408, + 2145899904, + 2145941376, + 2145981696, + 2146020864, + 2146059136, + 2146096384, + 2146132608, + 2146167936, + 2146202368, + 2146235776, + 2146268416, + 2146300160, + 2146331136, + 2146361216, + 2146390528, + 2146419200, + 2146446976, + 2146474112, + 2146500480, + 2146526208, + 2146551168, + 2146575488, + 2146599296, + 2146622464, + 2146644864, + 2146666880, + 2146688128, + 2146708992, + 2146729216, + 2146748928, + 2146768128, + 2146786816, + 2146805120, + 2146822784, + 2146840064, + 2146856960, + 2146873344, + 2146889216, + 2146904832, + 2146919936, + 2146934656, + 2146948992, + 2146962944, + 2146976640, + 2146989824, + 2147002752, + 2147015296, + 2147027584, + 2147039488, + 2147051136, + 2147062400, + 2147073408, + 2147084160, + 2147094528, + 2147104768, + 2147114624, + 2147124352, + 2147133696, + 2147142912, + 2147151744, + 2147160448, + 2147168896, + 2147177088, + 2147185152, + 2147192960, + 2147200512, + 2147207936, + 2147215104, + 2147222144, + 2147229056, + 2147235712, + 2147242112, + 2147248384, + 2147254656, + 2147260544, + 2147266432, + 2147272064, + 2147277568, + }, + + + }; + + /*----------------------------------------------------------------------------------* * Renderer SBA & MC enc/dec matrices *----------------------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index 06590cee18298ec12ebdcb5a522a26751bd7cd4a..ff45a79550328c72de5fe0bfe61c310347973ab3 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -49,15 +49,15 @@ extern const float diffuse_response_CICP6[5]; extern const float diffuse_response_CICP14[7]; extern const float diffuse_response_CICP16[9]; #else -extern const Word32 ls_azimuth_4d4_fx[8]; -extern const Word32 ls_elevation_4d4_fx[8]; -extern const Word16 diffuse_response_CICP6_fx[5]; -extern const Word16 diffuse_response_CICP14_fx[7]; -extern const Word16 diffuse_response_CICP16_fx[9]; +extern const Word32 ls_azimuth_4d4_fx[8]; /*Q-22*/ +extern const Word32 ls_elevation_4d4_fx[8]; /*Q-22*/ +extern const Word16 diffuse_response_CICP6_fx[5]; /*Q-15*/ +extern const Word16 diffuse_response_CICP14_fx[7]; /*Q-15*/ +extern const Word16 diffuse_response_CICP16_fx[9]; /*Q-15*/ #endif -extern const int16_t ap_pre_delay[DIRAC_DECORR_NUM_SPLIT_BANDS]; -extern const int16_t ap_filter_length[DIRAC_DECORR_NUM_SPLIT_BANDS]; +extern const Word16 ap_pre_delay[DIRAC_DECORR_NUM_SPLIT_BANDS]; +extern const Word16 ap_filter_length[DIRAC_DECORR_NUM_SPLIT_BANDS]; #ifndef IVAS_FLOAT_FIXED extern const float ap_lattice_delta_phi[DIRAC_MAX_NUM_DECORR_FILTERS * DIRAC_MAX_DECORR_FILTER_LEN]; extern const float ap_lattice_coeffs_1[DIRAC_DECORR_FILTER_LEN_1 * DIRAC_MAX_NUM_DECORR_FILTERS]; @@ -66,26 +66,26 @@ extern const float ap_lattice_coeffs_3[DIRAC_DECORR_FILTER_LEN_3 * DIRAC_MAX_NUM extern const float *const ap_lattice_coeffs[DIRAC_DECORR_NUM_SPLIT_BANDS]; extern const float ap_split_frequencies[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; #else -extern const Word16 ap_lattice_delta_phi_fx[DIRAC_MAX_NUM_DECORR_FILTERS * DIRAC_MAX_DECORR_FILTER_LEN]; -extern const Word16 ap_lattice_coeffs_1_fx[DIRAC_DECORR_FILTER_LEN_1 * DIRAC_MAX_NUM_DECORR_FILTERS]; -extern const Word16 ap_lattice_coeffs_2_fx[DIRAC_DECORR_FILTER_LEN_2 * DIRAC_MAX_NUM_DECORR_FILTERS]; -extern const Word16 ap_lattice_coeffs_3_fx[DIRAC_DECORR_FILTER_LEN_3 * DIRAC_MAX_NUM_DECORR_FILTERS]; +extern const Word16 ap_lattice_delta_phi_fx[DIRAC_MAX_NUM_DECORR_FILTERS * DIRAC_MAX_DECORR_FILTER_LEN]; /*Q-14*/ +extern const Word16 ap_lattice_coeffs_1_fx[DIRAC_DECORR_FILTER_LEN_1 * DIRAC_MAX_NUM_DECORR_FILTERS]; /*Q-15*/ +extern const Word16 ap_lattice_coeffs_2_fx[DIRAC_DECORR_FILTER_LEN_2 * DIRAC_MAX_NUM_DECORR_FILTERS]; /*Q-15*/ +extern const Word16 ap_lattice_coeffs_3_fx[DIRAC_DECORR_FILTER_LEN_3 * DIRAC_MAX_NUM_DECORR_FILTERS]; /*Q-15*/ extern const Word16 *const ap_lattice_coeffs_fx[DIRAC_DECORR_NUM_SPLIT_BANDS]; -extern const Word16 ap_split_frequencies_fx[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; +extern const Word16 ap_split_frequencies_fx[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; /*Q-14*/ #endif -extern const int16_t sba_map_tc[11]; -extern const int16_t sba_map_tc_512[11]; +extern const Word16 sba_map_tc[11]; /*Q-0*/ +extern const Word16 sba_map_tc_512[11]; /*Q-0*/ /*----------------------------------------------------------------------------------* * FASTCONV and PARAMETRIC binaural renderer ROM tables *----------------------------------------------------------------------------------*/ -extern const int16_t channelIndex_CICP6[5]; -extern const int16_t channelIndex_CICP12[7]; -extern const int16_t channelIndex_CICP14[7]; -extern const int16_t channelIndex_CICP16[9]; -extern const int16_t channelIndex_CICP19[11]; +extern const Word16 channelIndex_CICP6[5]; /*Q-0*/ +extern const Word16 channelIndex_CICP12[7]; /*Q-0*/ +extern const Word16 channelIndex_CICP14[7]; /*Q-0*/ +extern const Word16 channelIndex_CICP16[9]; /*Q-0*/ +extern const Word16 channelIndex_CICP19[11]; /*Q-0*/ #ifndef IVAS_FLOAT_FIXED /* These are equalization values for spread and surround coherent sounds, approximating the spectrum @@ -104,17 +104,17 @@ extern const float diffuseFieldCoherenceDifferenceZ[BINAURAL_COHERENCE_DIFFERENC #else /* These are equalization values for spread and surround coherent sounds, approximating the spectrum * for such sounds at anechoic multichannel listening. */ -extern const Word16 surCohEne_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; -extern const Word16 spreadCohEne05_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; -extern const Word16 spreadCohEne1_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; +extern const Word16 surCohEne_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; /*Q-13*/ +extern const Word16 spreadCohEne05_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; /*Q-13*/ +extern const Word16 spreadCohEne1_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; /*Q-14*/ /* Values for low-bit-rate equalization */ -extern const Word32 lowBitRateBinauralEQ_fx[LOW_BIT_RATE_BINAURAL_EQ_BINS]; +extern const Word32 lowBitRateBinauralEQ_fx[LOW_BIT_RATE_BINAURAL_EQ_BINS]; /*Q-31*/ /* Diffuse field binaural coherence directional adjustment values */ -extern const Word32 diffuseFieldCoherenceDifferenceX_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; -extern const Word32 diffuseFieldCoherenceDifferenceY_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; -extern const Word32 diffuseFieldCoherenceDifferenceZ_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; +extern const Word32 diffuseFieldCoherenceDifferenceX_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; /*Q-31*/ +extern const Word32 diffuseFieldCoherenceDifferenceY_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; /*Q-31*/ +extern const Word32 diffuseFieldCoherenceDifferenceZ_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; /*Q-31*/ #endif // IVAS_FLOAT_FIXED @@ -122,7 +122,7 @@ extern const Word32 diffuseFieldCoherenceDifferenceZ_fx[BINAURAL_COHERENCE_DIFFE * TD ISM Object renderer *----------------------------------------------------------------------------------*/ -extern const int16_t HRTF_MODEL_N_CPTS_VAR[HRTF_MODEL_N_SECTIONS]; +extern const Word16 HRTF_MODEL_N_CPTS_VAR[HRTF_MODEL_N_SECTIONS]; #ifndef IVAS_FLOAT_FIXED extern const float SincTable[321]; @@ -166,26 +166,28 @@ extern const float t_design_11_azimuth[70]; extern const float t_design_11_elevation[70]; #else /* SN3D norm (Fixed) */ -extern const Word32 norm_sn3d_hoa3_int[16]; +extern const Word32 norm_sn3d_hoa3_int[16]; /*Q-29*/ /* Order 11 t-design (Fixed) */ -extern const Word32 t_design_11_azimuth_int[70]; -extern const Word32 t_design_11_elevation_int[70]; +extern const Word32 t_design_11_azimuth_int[70]; /*Q-22*/ +extern const Word32 t_design_11_elevation_int[70]; /*Q-22*/ #endif /*----------------------------------------------------------------------* * Reverberator ROM tables *-----------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -extern const Word32 ivas_reverb_default_fc_fx[]; -extern const Word32 ivas_reverb_default_RT60_fx[]; -extern const Word32 ivas_reverb_default_DSR_fx[]; +extern const Word32 ivas_reverb_default_fc_fx[]; /*Q-16*/ +extern const Word32 ivas_reverb_default_RT60_fx[]; /*Q-26*/ +extern const Word32 ivas_reverb_default_DSR_fx[]; /*Q-30*/ #endif extern const float ivas_reverb_default_fc[]; extern const float ivas_reverb_default_RT60[]; extern const float ivas_reverb_default_DSR[]; +extern const Word32 release_cnst_table[4][201]; // Q31 + /*----------------------------------------------------------------------------------* * Renderer SBA & MC enc/dec matrices *----------------------------------------------------------------------------------*/ @@ -206,8 +208,8 @@ extern const float ls_conversion_cicpX_stereo[12][2]; /* Mapping table of input config : output config with corresponding matrix */ extern const LS_CONVERSION_MAPPING ls_conversion_mapping[]; #else -extern const Word32 ls_conversion_cicpX_mono_fx[12][1]; -extern const Word32 ls_conversion_cicpX_stereo_fx[12][2]; +extern const Word32 ls_conversion_cicpX_mono_fx[12][1]; /*Q-30*/ +extern const Word32 ls_conversion_cicpX_stereo_fx[12][2]; /*Q-30*/ /* Mapping table of input config : output config with corresponding matrix */ extern const LS_CONVERSION_MAPPING_FX ls_conversion_mapping_fx[]; diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 874fa8bf0aaf2a8d160f6ff7e5003f54ac5ba99b..e6865348433ed85148f17fe438c60600388a1e9c 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -272,7 +272,7 @@ void QuatToRotMat_fx( Word32 Rmat[3][3] /* o : real-space rotation matrix for this rotation 2*Qx-32 */ ) { - Word32 w = quat.w_fx; + Word32 w = quat.w_fx; // Qx move32(); Word32 x = quat.x_fx; move32(); @@ -288,7 +288,7 @@ void QuatToRotMat_fx( Word32 yy = L_shr( Mpy_32_32( y, y ), 1 ); Word32 zz = L_shr( Mpy_32_32( z, z ), 1 ); - Word32 wx = Mpy_32_32( w, x ); + Word32 wx = Mpy_32_32( w, x ); // 2 * Qx - 31 Word32 wz = Mpy_32_32( w, z ); Word32 wy = Mpy_32_32( w, y ); @@ -297,21 +297,21 @@ void QuatToRotMat_fx( Word32 yz = Mpy_32_32( y, z ); - Rmat[0][0] = L_sub( L_sub( L_add( ww, xx ), yy ), zz ); + Rmat[0][0] = L_sub( L_sub( L_add( ww, xx ), yy ), zz ); // 2 * Qx - 31 - 1 = 2*Qx-32 move32(); Rmat[0][1] = L_sub( xy, wz ); move32(); Rmat[0][2] = L_add( xz, wy ); move32(); - Rmat[1][0] = L_add( xy, wz ); + Rmat[1][0] = L_add( xy, wz ); // 2 * Qx - 32 move32(); Rmat[1][1] = L_sub( L_add( L_sub( ww, xx ), yy ), zz ); move32(); Rmat[1][2] = L_sub( yz, wx ); move32(); - Rmat[2][0] = L_sub( xz, wy ); + Rmat[2][0] = L_sub( xz, wy ); // 2 * Qx - 32 move32(); Rmat[2][1] = L_add( yz, wx ); move32(); @@ -372,13 +372,13 @@ void Euler2Quat( #else void Euler2Quat_fx( - const Word32 yaw, /* i : yaw (x) */ - const Word32 pitch, /* i : pitch (y) */ - const Word32 roll, /* i : roll (z) */ - IVAS_QUATERNION *quat /* o : quaternion describing the rotation */ + const Word32 yaw, /* i : yaw (x) Q22 */ + const Word32 pitch, /* i : pitch (y) Q22 */ + const Word32 roll, /* i : roll (z) Q22 */ + IVAS_QUATERNION *quat /* o : quaternion describing the rotation Q19 */ ) { - Word16 cr = getCosWord16( extract_l( L_shr_r( roll, 10 ) ) ); + Word16 cr = getCosWord16( extract_l( L_shr_r( roll, 10 ) ) ); // Q14 Word16 sr = getSinWord16( extract_l( L_shr_r( roll, 10 ) ) ); Word16 cp = getCosWord16( extract_l( L_shr_r( pitch, 10 ) ) ); Word16 sp = getSinWord16( extract_l( L_shr_r( pitch, 10 ) ) ); @@ -487,7 +487,7 @@ void rotateAziEle_fx( Word16 *azi, /* o : rotated azimuth Q0 */ Word16 *ele, /* o : rotated elevation Q0 */ Word32 Rmat_fx[3][3], /* i : real-space rotation matrix Q30*/ - const Word16 isPlanar /* i : is rotation planar and elevation meaningless? */ + const Word16 isPlanar /* i : is rotation planar and elevation meaningless? Q0*/ ) { Word16 n; @@ -511,19 +511,19 @@ void rotateAziEle_fx( } temp_16 = ele_in; move16(); - w_fx = cosine_table_Q31[abs_s( temp_16 )]; + w_fx = cosine_table_Q31[abs_s( temp_16 )]; // Q31 move32(); temp_16 = azi_in; move16(); - dv_fx[0] = Mpy_32_32( w_fx, cosine_table_Q31[abs_s( temp_16 )] ); + dv_fx[0] = Mpy_32_32( w_fx, cosine_table_Q31[abs_s( temp_16 )] ); // Q31 move32(); temp_16 = azi_in; move16(); - dv_fx[1] = Mpy_32_32( w_fx, sine_table_Q31[add( temp_16, 180 )] ); + dv_fx[1] = Mpy_32_32( w_fx, sine_table_Q31[add( temp_16, 180 )] ); // Q31 move32(); temp_16 = ele_in; move16(); - dv_fx[2] = sine_table_Q31[add( temp_16, 180 )]; + dv_fx[2] = sine_table_Q31[add( temp_16, 180 )]; // Q31 move32(); /*Rotation mtx multiplication*/ FOR( n = 0; n < 3; n++ ) @@ -538,7 +538,7 @@ void rotateAziEle_fx( move32(); x = dv_r_fx[0]; move32(); - radian = atan2_fx( L_abs( L_shr( y, 15 ) ), L_abs( L_shr( x, 15 ) ) ); + radian = atan2_fx( L_abs( L_shr( y, 15 ) ), L_abs( L_shr( x, 15 ) ) ); // Q14 if ( y <= 0 ) { @@ -549,11 +549,11 @@ void rotateAziEle_fx( { IF( radian < 0 ) { - angle = negate( add( 180, extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ) ); + angle = negate( add( 180, extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ) ); // Q0 } ELSE { - angle = sub( 180, extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ); + angle = sub( 180, extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ); // Q0 } IF( radian == 0 ) { @@ -565,7 +565,7 @@ void rotateAziEle_fx( } ELSE { - angle = extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 24 ) ); + angle = extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 24 ) ); // Q0 } *azi = s_max( -180, min( 180, angle ) ); @@ -578,7 +578,7 @@ void rotateAziEle_fx( move32(); x = sqrt_fx; move32(); - radian = atan2_fx( L_abs( L_shr( y, 15 ) ), L_abs( L_shr( x, 15 ) ) ); + radian = atan2_fx( L_abs( L_shr( y, 15 ) ), L_abs( L_shr( x, 15 ) ) ); // Q14 if ( y <= 0 ) { radian = negate( radian ); @@ -588,11 +588,11 @@ void rotateAziEle_fx( { IF( radian < 0 ) { - angle = negate( add( 180, extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ) ); + angle = negate( add( 180, extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ) ); // Q0 } ELSE { - angle = sub( 180, extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ); + angle = sub( 180, extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ); // Q0 } IF( radian == 0 ) { @@ -604,10 +604,10 @@ void rotateAziEle_fx( } ELSE { - angle = extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ); + angle = extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ); // Q0 } - *ele = s_max( -90, s_min( 90, angle ) ); + *ele = s_max( -90, s_min( 90, angle ) ); // Q0 move16(); } ELSE @@ -630,7 +630,7 @@ void rotateAziEle_fx_frac_az_el( Word32 *azi, /* o : rotated azimuth Q22 */ Word32 *ele, /* o : rotated elevation Q22 */ Word32 Rmat_fx[3][3], /* i : real-space rotation matrix Q30 */ - const Word16 isPlanar /* i : is rotation planar and elevation meaningless? */ + const Word16 isPlanar /* i : is rotation planar and elevation meaningless? Q0*/ ) { Word16 n, radian; // temp_16; @@ -654,8 +654,8 @@ void rotateAziEle_fx_frac_az_el( } azi_in_q13 = extract_l( L_shr( Mpy_32_32( azi_in, PI_OVER_180_FX ), Q9 ) ); ele_in_q13 = extract_l( L_shr( Mpy_32_32( ele_in, PI_OVER_180_FX ), Q9 ) ); - w_fx = getCosWord16( ele_in_q13 ); // Q14 - dv_fx[0] = L_mult( w_fx, getCosWord16( azi_in_q13 ) ); + w_fx = getCosWord16( ele_in_q13 ); // Q14 + dv_fx[0] = L_mult( w_fx, getCosWord16( azi_in_q13 ) ); // Q28 move32(); IF( EQ_32( dv_fx[0], ONE_IN_Q29 ) ) { @@ -667,7 +667,7 @@ void rotateAziEle_fx_frac_az_el( dv_fx[0] = L_shl( dv_fx[0], 2 ); move32(); } - dv_fx[1] = L_mult( w_fx, getSinWord16( azi_in_q13 ) ); + dv_fx[1] = L_mult( w_fx, getSinWord16( azi_in_q13 ) ); // Q28 move32(); IF( EQ_32( dv_fx[1], ONE_IN_Q30 ) ) { @@ -679,7 +679,7 @@ void rotateAziEle_fx_frac_az_el( dv_fx[1] = L_shl( dv_fx[1], 1 ); move32(); } - dv_fx[2] = L_deposit_l( getSinWord16( ele_in_q13 ) ); + dv_fx[2] = L_deposit_l( getSinWord16( ele_in_q13 ) ); // Q14 move32(); IF( EQ_32( dv_fx[2], ONE_IN_Q15 ) ) { @@ -726,7 +726,7 @@ void rotateAziEle_fx_frac_az_el( move32(); x = sqrt_fx; move32(); - radian = BASOP_util_atan2( y, x, 0 ); + radian = BASOP_util_atan2( y, x, 0 ); // Q13 angle = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 1 ); // Q22 @@ -762,7 +762,7 @@ void rotateAziEle_fixed( Word32 *azi, /* o : rotated azimuth Q22 */ Word32 *ele, /* o : rotated elevation Q22 */ Word32 Rmat_fx[3][3], /* i : real-space rotation matrix Q30 */ - const Word16 isPlanar /* i : is rotation planar and elevation meaningless? */ + const Word16 isPlanar /* i : is rotation planar and elevation meaningless? Q0*/ ) { Word16 n, radian, temp_16; @@ -789,7 +789,7 @@ void rotateAziEle_fixed( move32(); temp_16 = azi_in; move16(); - dv_fx[0] = Mpy_32_32( w_fx, cosine_table_Q31[abs_s( temp_16 )] ); + dv_fx[0] = Mpy_32_32( w_fx, cosine_table_Q31[abs( temp_16 )] ); move32(); temp_16 = azi_in; move16(); @@ -815,7 +815,19 @@ void rotateAziEle_fixed( radian = BASOP_util_atan2( y, x, 0 ); // Q13 angle = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 1 ); // Q22 - + /* Handeled roudning off operation*/ + IF( angle > 0 ) + { + temp = L_add( angle, ONE_IN_Q21 /* 0.5 in Q22*/ ); + temp_16 = extract_l( L_shr( temp, Q22 ) ); + angle = L_shl( temp_16, Q22 ); // Q22 + } + ELSE + { + temp = L_sub( angle, ONE_IN_Q21 /* 0.5 in Q22*/ ); + temp_16 = add( extract_l( L_shr( temp, Q22 ) ), 1 ); + angle = L_shl( temp_16, Q22 ); // Q22 + } *azi = L_max( L_shl( -180, 22 ), L_min( L_shl( 180, 22 ), angle ) ); // Q22 move32(); if ( LE_32( L_abs( *azi ), ONE_IN_Q22 ) ) @@ -830,7 +842,7 @@ void rotateAziEle_fixed( move32(); x = sqrt_fx; move32(); - radian = BASOP_util_atan2( y, x, 0 ); + radian = BASOP_util_atan2( y, x, 0 ); // Q13 angle = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 1 ); // Q22 @@ -911,9 +923,9 @@ void rotateAziEle( void rotateFrame_shd( COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : head and external orientation combined handle */ Word32 *output[], /* i/o: unrotated HOA3 signal buffer in TD Q11 */ - const Word16 subframe_len, /* i : subframe length per channel */ + const Word16 subframe_len, /* i : subframe length per channel Q0 */ const IVAS_OUTPUT_SETUP hTransSetup, /* i : format for rotation */ - const Word16 subframe_idx /* i : subframe index */ + const Word16 subframe_idx /* i : subframe index Q0 */ ) { // Not yet tested, no test cases entering the function. @@ -934,7 +946,7 @@ void rotateFrame_shd( SWITCH( subframe_len ) { case L_SUBFRAME_48k: - tmp = Q31_BY_SUB_FRAME_240; + tmp = Q31_BY_SUB_FRAME_240; // Q31 move32(); BREAK; case L_SUBFRAME_32k: @@ -989,7 +1001,7 @@ void rotateFrame_shd( FOR( m = m1; m < m2; m++ ) { /* crossfade with previous rotation gains */ - tmp = L_add( Mpy_32_32( Mpy_32_16_r( cross_fade[i], SHrotmat[n][m] ) /*Q30*/, output[m][add( offset, i )] /*Q11*/ ), Mpy_32_32( Mpy_32_16_r( L_sub( ONE_IN_Q31, cross_fade[i] ), SHrotmat_prev[n][m] ) /*Q30*/, output[m][add( offset, i )] /*Q11*/ ) ); + tmp = L_add( Mpy_32_32( Mpy_32_16_r( cross_fade[i], SHrotmat[n][m] ) /*Q30*/, output[m][offset + i] /*Q11*/ ), Mpy_32_32( Mpy_32_16_r( L_sub( ONE_IN_Q31, cross_fade[i] ), SHrotmat_prev[n][m] ) /*Q30*/, output[m][offset + i] /*Q11*/ ) ); tmpRot[n - m1] = L_add( L_shl( tmp, 1 ), tmpRot[n - m1] ); // Q11 } } @@ -997,7 +1009,7 @@ void rotateFrame_shd( /* write back the result */ FOR( n = m1; n < m2; n++ ) { - output[n][add( offset, i )] = tmpRot[n - m1]; // Q11 + output[n][offset + i] = tmpRot[n - m1]; // Q11 move32(); } m1 = m2; @@ -1028,7 +1040,7 @@ void rotateFrame_shd( MVR2R_WORD32( hCombinedOrientationData->Rmat_fx[subframe_idx][i], hCombinedOrientationData->Rmat_prev_fx[i], - 3 ); + 3 ); // Q14 } return; @@ -1239,8 +1251,8 @@ void rotateFrame_sd( test(); IF( hEFAPdata != NULL && ( NE_16( extract_l( L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ) ), azimuth ) || NE_16( extract_l( L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ) ), elevation ) ) ) { - azimuth_fx = L_shl( L_deposit_l( azimuth ), Q22 ); - elevation_fx = L_shl( L_deposit_l( elevation ), Q22 ); + azimuth_fx = L_shl( L_deposit_l( azimuth ), Q22 ); // Q0->Q22 + elevation_fx = L_shl( L_deposit_l( elevation ), Q22 ); // Q0->Q22 efap_determine_gains_fx( hEFAPdata, tmp_gains_fx, azimuth_fx, elevation_fx, EFAP_MODE_EFAP ); @@ -1274,8 +1286,8 @@ void rotateFrame_sd( IF( hEFAPdata != NULL && ( NE_16( extract_l( L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ) ), azimuth ) || NE_16( extract_l( L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ) ), elevation ) ) ) { - azimuth_fx = L_shl( L_deposit_l( azimuth ), Q22 ); - elevation_fx = L_shl( L_deposit_l( elevation ), Q22 ); + azimuth_fx = L_shl( L_deposit_l( azimuth ), Q22 ); // Q0->Q22 + elevation_fx = L_shl( L_deposit_l( elevation ), Q22 ); // Q0->Q22 efap_determine_gains_fx( hEFAPdata, tmp_gains_fx, azimuth_fx, elevation_fx, EFAP_MODE_EFAP ); FOR( ch_out = 0; ch_out < nchan; ch_out++ ) @@ -1327,14 +1339,14 @@ void rotateFrame_sd( FOR( i = 0; i < 3; i++ ) { MVR2R_WORD32( - hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx][i], + hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx][i], // Q30 hCombinedOrientationData->Rmat_prev_fx[i], 3 ); } /* copy to output */ FOR( ch_out = 0; ch_out < nchan; ch_out++ ) { - MVR2R_WORD32( &output_tmp_fx[ch_out][offset], &output[ch_out][offset], subframe_len ); + MVR2R_WORD32( &output_tmp_fx[ch_out][offset], &output[ch_out][offset], subframe_len ); // Q11 } pop_wmops(); @@ -1545,9 +1557,9 @@ void rotateFrame_shd_cldfb( move32(); FOR( m = m1; m < m2; m++ ) { - temp1 = Mpy_32_16_r( Cldfb_RealBuffer[m][i][iBand], SHrotmat[n][m] ); - temp2 = Mpy_32_16_r( Cldfb_ImagBuffer[m][i][iBand], SHrotmat[n][m] ); - realRot[n - m1] = L_add( temp1, realRot[n - m1] ); // Q(x + 14 - 15) + temp1 = Mpy_32_16_r( Cldfb_RealBuffer[m][i][iBand], SHrotmat[n][m] ); // Q(x + 14 - 15) + temp2 = Mpy_32_16_r( Cldfb_ImagBuffer[m][i][iBand], SHrotmat[n][m] ); // Q(x + 14 - 15) + realRot[n - m1] = L_add( temp1, realRot[n - m1] ); // Q(x + 14 - 15) move32(); imagRot[n - m1] = L_add( temp2, imagRot[n - m1] ); // Q(x + 14 - 15) move32(); @@ -1856,7 +1868,7 @@ void rotateFrame_sd_cldfb_fixed( ELSE { set32_fx( gains_fx[n], 0, nInChannels ); - gains_fx[n][n] = 0x7fffffff; // Q31 + gains_fx[n][n] = 0x7fffffff; // 1 in Q31 move32(); } } @@ -1868,7 +1880,7 @@ void rotateFrame_sd_cldfb_fixed( set32_fx( imagRot_fx[n], 0, shl( nb_band, 2 ) ); FOR( m = 0; m < nInChannels; m++ ) { - g1_fx = gains_fx[m][n]; + g1_fx = gains_fx[m][n]; // Q31 move32(); p_realRot_fx = realRot_fx[n]; p_imagRot_fx = imagRot_fx[n]; @@ -2505,13 +2517,13 @@ ivas_error combine_external_and_head_orientations( Word16 l_shift = 0; move16(); l_shift = s_min( s_min( Q_factor_L_32( hCombinedOrientationData->Quaternions[i].w_fx ), Q_factor_L_32( hCombinedOrientationData->Quaternions[i].x_fx ) ), s_min( Q_factor_L_32( hCombinedOrientationData->Quaternions[i].y_fx ), Q_factor_L_32( hCombinedOrientationData->Quaternions[i].z_fx ) ) ); - hCombinedOrientationData->Quaternions[i].w_fx = L_shl( hCombinedOrientationData->Quaternions[i].w_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].w_fx = L_shl( hCombinedOrientationData->Quaternions[i].w_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].x_fx = L_shl( hCombinedOrientationData->Quaternions[i].x_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].x_fx = L_shl( hCombinedOrientationData->Quaternions[i].x_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].y_fx = L_shl( hCombinedOrientationData->Quaternions[i].y_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].y_fx = L_shl( hCombinedOrientationData->Quaternions[i].y_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].z_fx = L_shl( hCombinedOrientationData->Quaternions[i].z_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].z_fx = L_shl( hCombinedOrientationData->Quaternions[i].z_fx, l_shift ); // q_fact+l_shift move32(); hCombinedOrientationData->Quaternions[i].q_fact = add( hCombinedOrientationData->Quaternions[i].q_fact, l_shift ); move16(); @@ -2601,9 +2613,9 @@ ivas_error combine_external_and_head_orientations( /* Save the current orientations */ IF( hExtOrientationData != NULL ) { - IF( hExtOrientationData->enableExternalOrientation[sub( hExtOrientationData->num_subframes, 1 )] > 0 ) + IF( hExtOrientationData->enableExternalOrientation[hExtOrientationData->num_subframes - 1] > 0 ) { - hCombinedOrientationData->Quaternion_prev_extOrientation = hExtOrientationData->Quaternions[sub( hExtOrientationData->num_subframes, 1 )]; + hCombinedOrientationData->Quaternion_prev_extOrientation = hExtOrientationData->Quaternions[hExtOrientationData->num_subframes - 1]; } ELSE { @@ -2696,13 +2708,13 @@ ivas_error combine_external_and_head_orientations( FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ ) { l_shift = s_min( s_min( Q_factor_L_32( hCombinedOrientationData->Quaternions[i].w_fx ), Q_factor_L_32( hCombinedOrientationData->Quaternions[i].x_fx ) ), s_min( Q_factor_L_32( hCombinedOrientationData->Quaternions[i].y_fx ), Q_factor_L_32( hCombinedOrientationData->Quaternions[i].z_fx ) ) ); - hCombinedOrientationData->Quaternions[i].w_fx = L_shl( hCombinedOrientationData->Quaternions[i].w_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].w_fx = L_shl( hCombinedOrientationData->Quaternions[i].w_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].x_fx = L_shl( hCombinedOrientationData->Quaternions[i].x_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].x_fx = L_shl( hCombinedOrientationData->Quaternions[i].x_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].y_fx = L_shl( hCombinedOrientationData->Quaternions[i].y_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].y_fx = L_shl( hCombinedOrientationData->Quaternions[i].y_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].z_fx = L_shl( hCombinedOrientationData->Quaternions[i].z_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].z_fx = L_shl( hCombinedOrientationData->Quaternions[i].z_fx, l_shift ); // q_fact+l_shift move32(); hCombinedOrientationData->Quaternions[i].q_fact = add( hCombinedOrientationData->Quaternions[i].q_fact, l_shift ); move16(); @@ -2989,7 +3001,7 @@ static void external_target_interpolation_fx( { IF( i > 0 ) { - IF( hExtOrientationData->enableExternalOrientation[sub( i, 1 )] == 0 ) + IF( hExtOrientationData->enableExternalOrientation[i - 1] == 0 ) { IVAS_QUATERNION identity; identity.w_fx = ONE_IN_Q31; @@ -3002,13 +3014,13 @@ static void external_target_interpolation_fx( move16(); hCombinedOrientationData->Quaternions_ext_interpolation_start = identity; } - ELSE IF( EQ_16( hExtOrientationData->enableExternalOrientation[sub( i, 1 )], 2 ) ) + ELSE IF( EQ_16( hExtOrientationData->enableExternalOrientation[i - 1], 2 ) ) { hCombinedOrientationData->Quaternions_ext_interpolation_start = hCombinedOrientationData->Quaternion_frozen_ext; } ELSE { - hCombinedOrientationData->Quaternions_ext_interpolation_start = hExtOrientationData->Quaternions[sub( i, 1 )]; + hCombinedOrientationData->Quaternions_ext_interpolation_start = hExtOrientationData->Quaternions[i - 1]; } } ELSE @@ -3187,10 +3199,10 @@ static bool are_orientations_same_fx( test(); test(); test(); - IF( EQ_16( Flag_1, 1 ) || - EQ_16( Flag_2, 1 ) || - EQ_16( Flag_3, 1 ) || - EQ_16( Flag_4, 1 ) ) + if ( EQ_16( Flag_1, 1 ) || + EQ_16( Flag_2, 1 ) || + EQ_16( Flag_3, 1 ) || + EQ_16( Flag_4, 1 ) ) { orientationsAreSame = false; move16(); @@ -3248,34 +3260,36 @@ static Word32 SHrot_p_fx( Word32 p = 0; move32(); - ri1 = SHrotmat[add( add( i, 1 ), 1 )][add( add( 1, 1 ), 1 )]; + ri1 = SHrotmat[i + 1 + 1][1 + 1 + 1]; // Q14 move16(); - rim1 = SHrotmat[add( add( i, 1 ), 1 )][add( add( -1, 1 ), 1 )]; + rim1 = SHrotmat[i + 1 + 1][-1 + 1 + 1]; // Q14 move16(); - ri0 = SHrotmat[add( add( i, 1 ), 1 )][add( 1, 1 )]; + ri0 = SHrotmat[i + 1 + 1][0 + 1 + 1]; // Q14 move16(); IF( EQ_16( b, -l ) ) { - R_lm1_1 = R_lm1[sub( add( a, l ), 1 )][0]; + R_lm1_1 = R_lm1[a + l - 1][0]; // Q14 move16(); - R_lm1_2 = R_lm1[sub( add( a, l ), 1 )][sub( shl( l, 1 ), 2 )]; + R_lm1_2 = R_lm1[a + l - 1][2 * l - 2]; // Q14 move16(); - p = L_mac0( L_mult0( ri1, R_lm1_1 ), rim1, R_lm1_2 ); + p = L_mac0( L_mult0( ri1, R_lm1_1 ), rim1, R_lm1_2 ); // Q28 } ELSE { IF( EQ_16( b, l ) ) { - R_lm1_1 = R_lm1[sub( add( a, l ), 1 )][sub( shl( l, 1 ), 2 )]; - R_lm1_2 = R_lm1[sub( add( a, l ), 1 )][0]; - p = L_msu0( L_mult0( ri1, R_lm1_1 ), rim1, R_lm1_2 ); + R_lm1_1 = R_lm1[a + l - 1][2 * l - 2]; // Q14 + move16(); + R_lm1_2 = R_lm1[a + l - 1][0]; // Q14 + move16(); + p = L_msu0( L_mult0( ri1, R_lm1_1 ), rim1, R_lm1_2 ); // Q28 } ELSE { - R_lm1_1 = R_lm1[sub( add( a, l ), 1 )][sub( add( b, l ), 1 )]; + R_lm1_1 = R_lm1[a + l - 1][b + l - 1]; move16(); - p = L_mult0( ri0, R_lm1_1 ); + p = L_mult0( ri0, R_lm1_1 ); // Q28 } } @@ -3450,9 +3464,9 @@ static Word32 SHrot_v_fx( d = 1; move16(); } - p0 = SHrot_p_fx( 1, l, sub( m, 1 ), n, SHrotmat, R_lm1 ); - p1 = SHrot_p_fx( -1, l, add( negate( m ), 1 ), n, SHrotmat, R_lm1 ); - result = Msub_32_16_r( Mpy_32_16_r( p0, square_root16_table[add( 1, d )] ), p1, shl( sub( 1, d ), 14 ) ); // Q27 + p0 = SHrot_p_fx( 1, l, sub( m, 1 ), n, SHrotmat, R_lm1 ); // Q28 + p1 = SHrot_p_fx( -1, l, add( negate( m ), 1 ), n, SHrotmat, R_lm1 ); // Q28 + result = Msub_32_16_r( Mpy_32_16_r( p0, square_root16_table[1 + d] ), p1, shl( sub( 1, d ), 14 ) ); // Q27 } ELSE { @@ -3465,7 +3479,7 @@ static Word32 SHrot_v_fx( } p0 = SHrot_p_fx( 1, l, add( m, 1 ), n, SHrotmat, R_lm1 ); p1 = SHrot_p_fx( -1, l, negate( add( m, 1 ) ), n, SHrotmat, R_lm1 ); - result = Madd_32_16_r( Mpy_32_16_r( p0, shl( sub( 1, d ), 14 ) ), p1, square_root16_table[add( 1, d )] ); // Q27 + result = Madd_32_16_r( Mpy_32_16_r( p0, shl( sub( 1, d ), 14 ) ), p1, square_root16_table[1 + d] ); // Q27 } } return result; // Q27 @@ -3490,15 +3504,15 @@ static Word32 SHrot_w_fx( { IF( m > 0 ) { - p0 = SHrot_p_fx( 1, l, add( m, 1 ), n, SHrotmat, R_lm1 ); - p1 = SHrot_p_fx( -1, l, negate( add( m, 1 ) ), n, SHrotmat, R_lm1 ); - result = L_add( p0, p1 ); + p0 = SHrot_p_fx( 1, l, add( m, 1 ), n, SHrotmat, R_lm1 ); // Q28 + p1 = SHrot_p_fx( -1, l, negate( add( m, 1 ) ), n, SHrotmat, R_lm1 ); // Q28 + result = L_add( p0, p1 ); // Q28 } ELSE { - p0 = SHrot_p_fx( 1, l, sub( m, 1 ), n, SHrotmat, R_lm1 ); - p1 = SHrot_p_fx( -1, l, sub( 1, m ), n, SHrotmat, R_lm1 ); - result = L_sub( p0, p1 ); + p0 = SHrot_p_fx( 1, l, sub( m, 1 ), n, SHrotmat, R_lm1 ); // Q28 + p1 = SHrot_p_fx( -1, l, sub( 1, m ), n, SHrotmat, R_lm1 ); // Q28 + result = L_sub( p0, p1 ); // Q28 } } @@ -3555,21 +3569,21 @@ void SHrotmatgen_fx( SHrotmat[0][0] = ONE_IN_Q14; move16(); - SHrotmat[1][1] = extract_h( Rmat[1][1] ); + SHrotmat[1][1] = extract_h( Rmat[1][1] ); // Q14 move16(); SHrotmat[1][2] = extract_h( Rmat[1][2] ); move16(); SHrotmat[1][3] = extract_h( Rmat[1][0] ); move16(); - SHrotmat[2][1] = extract_h( Rmat[2][1] ); + SHrotmat[2][1] = extract_h( Rmat[2][1] ); // Q14 move16(); SHrotmat[2][2] = extract_h( Rmat[2][2] ); move16(); SHrotmat[2][3] = extract_h( Rmat[2][0] ); move16(); - SHrotmat[3][1] = extract_h( Rmat[0][1] ); + SHrotmat[3][1] = extract_h( Rmat[0][1] ); // Q14 move16(); SHrotmat[3][2] = extract_h( Rmat[0][2] ); move16(); @@ -3580,7 +3594,7 @@ void SHrotmatgen_fx( { FOR( j = 0; j < 2 * 1 + 1; j++ ) { - R_lm1[i][j] = SHrotmat[i + 1][j + 1]; + R_lm1[i][j] = SHrotmat[i + 1][j + 1]; // Q14 move16(); } } @@ -3600,23 +3614,23 @@ void SHrotmatgen_fx( } absm = extract_l( L_abs( m ) ); - sql2mm2 = square_root30_q12[sub( imult1616( l, l ), imult1616( m, m ) )]; + sql2mm2 = square_root30_q12[l * l - m * m]; // Q12 move16(); - sqdabsm = square_root30_q12[imult1616( add( 1, d ), imult1616( sub( add( l, absm ), 1 ), add( l, absm ) ) )]; + sqdabsm = square_root30_q12[( 1 + d ) * ( l + absm - 1 ) * ( l + absm )]; // Q12 move16(); - sqlabsm = square_root30_q12[imult1616( sub( l, add( absm, 1 ) ), sub( l, absm ) )]; + sqlabsm = square_root30_q12[( ( l - ( absm + 1 ) ) * ( l - absm ) )]; // Q12 move16(); FOR( n = -l; n <= l; n++ ) { IF( EQ_16( abs_s( n ), l ) ) { - sqdenom = square_root30_q12[imult1616( shl( l, 1 ), sub( shl( l, 1 ), 1 ) )]; + sqdenom = square_root30_q12[( ( 2 * l ) * ( 2 * l - 1 ) )]; // Q12 move16(); } ELSE { - sqdenom = square_root30_q12[sub( imult1616( l, l ), imult1616( n, n ) )]; + sqdenom = square_root30_q12[( l * l - n * n )]; // Q12 move16(); } @@ -3641,7 +3655,7 @@ void SHrotmatgen_fx( w32_fx = Mpy_32_16_r( result, w ); // Q27 } // Addind and converting to 16 bit integer of Q14 - R_l[add( m, l )][add( n, l )] = extract_h( L_shl( L_add( L_add( L_shr( u32_fx, 1 ), v32_fx ), L_shr( w32_fx, 1 ) ), 4 ) ); // Q14 + R_l[m + l][n + l] = extract_h( L_shl( L_add( L_add( L_shr( u32_fx, 1 ), v32_fx ), L_shr( w32_fx, 1 ) ), 4 ) ); // Q14 move16(); } } @@ -3650,7 +3664,7 @@ void SHrotmatgen_fx( { FOR( j = 0; j < 2 * l + 1; j++ ) { - SHrotmat[add( band_idx, i )][add( band_idx, j )] = R_l[i][j]; + SHrotmat[band_idx + i][band_idx + j] = R_l[i][j]; // Q14 move16(); } } @@ -3832,7 +3846,7 @@ void ivas_combined_orientation_update_index( hCombinedOrientationData->cur_subframe_samples_rendered = add( hCombinedOrientationData->cur_subframe_samples_rendered, samples_rendered ); move16(); div_result = BASOP_Util_Divide3216_Scale( hCombinedOrientationData->cur_subframe_samples_rendered, hCombinedOrientationData->subframe_size, &exp ); - hCombinedOrientationData->subframe_idx = add( hCombinedOrientationData->subframe_idx, shl( div_result, exp + 1 ) ); + hCombinedOrientationData->subframe_idx = add( hCombinedOrientationData->subframe_idx, shl( div_result, add( exp, 1 ) ) ); move16(); hCombinedOrientationData->cur_subframe_samples_rendered = hCombinedOrientationData->cur_subframe_samples_rendered % hCombinedOrientationData->subframe_size; move16(); diff --git a/lib_rend/ivas_sba_rendering.c b/lib_rend/ivas_sba_rendering.c index 380faaf9f5e3880a3587a4cb99e08c097da4b0c5..4a23da243947ce991ffae3d9b3b887352299c01b 100644 --- a/lib_rend/ivas_sba_rendering.c +++ b/lib_rend/ivas_sba_rendering.c @@ -111,8 +111,8 @@ void ivas_sba_prototype_renderer_fx( { FOR( Word16 j = 0; j < CLDFB_SLOTS_PER_SUBFRAME; j++ ) { - scale_sig32( inRe_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( norm_q, 2 ) ); - scale_sig32( inIm_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( norm_q, 2 ) ); + scale_sig32( inRe_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( norm_q, 2 ) ); // q_cldfb -> q_cldfb + 2 -norm_q + scale_sig32( inIm_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( norm_q, 2 ) ); // q_cldfb -> q_cldfb + 2 -norm_q q_cldfb[i][j] = sub( add( q_cldfb[i][j], norm_q ), 2 ); move16(); } @@ -170,7 +170,7 @@ void ivas_sba_prototype_renderer_fx( { spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; move16(); - cldfb_par_fx = mixer_mat_fx[out_ch][in_ch][spar_band]; // q30 + cldfb_par_fx = mixer_mat_fx[out_ch][in_ch][spar_band]; // hMdDec->Q_mixer_matrix move32(); } ELSE @@ -180,12 +180,12 @@ void ivas_sba_prototype_renderer_fx( FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ - cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ) ); // q30 + cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ) ); // hMdDec->Q_mixer_matrix } } - out_re_fx[out_ch] = L_add_sat( out_re_fx[out_ch], Mpy_32_32( inRe_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // q30+q_cldfb[i][j]; - out_im_fx[out_ch] = L_add_sat( out_im_fx[out_ch], Mpy_32_32( inIm_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // q30+q_cldfb[i][j + out_re_fx[out_ch] = L_add_sat( out_re_fx[out_ch], Mpy_32_32( inRe_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 + out_im_fx[out_ch] = L_add_sat( out_im_fx[out_ch], Mpy_32_32( inIm_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 move32(); move32(); } @@ -194,8 +194,8 @@ void ivas_sba_prototype_renderer_fx( /*update CLDFB data with the parameter-modified data*/ FOR( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ ) { - inRe_fx[out_ch][ts][cldfb_band] = L_shl_sat( out_re_fx[out_ch], 1 ); // q30+q_cldfb[i][j]; + q1 //to keep constat q to entire buffer - inIm_fx[out_ch][ts][cldfb_band] = L_shl_sat( out_im_fx[out_ch], 1 ); + inRe_fx[out_ch][ts][cldfb_band] = L_shl_sat( out_re_fx[out_ch], 1 ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 +1; + q1 //to keep constat q to entire buffer + inIm_fx[out_ch][ts][cldfb_band] = L_shl_sat( out_im_fx[out_ch], 1 ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 +1; + q1 //to keep constat q to entire buffer move32(); move32(); } @@ -216,10 +216,10 @@ void ivas_sba_prototype_renderer_fx( move16(); hSpar->i_subframe = s_min( hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES ); move16(); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], hSpar->hMdDec->mixer_mat_prev_fx[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[4][0][0], hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], hSpar->hMdDec->mixer_mat_prev_fx[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); // Q_mixer_mat + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); // Q_mixer_mat + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); // Q_mixer_mat + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[4][0][0], hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); // Q_mixer_mat FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) { @@ -252,9 +252,9 @@ void ivas_sba_prototype_renderer_fx( Word32 temp_signal_fx[CLDFB_NO_CHANNELS_MAX]; FOR( Word16 idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { - temp_signal_fx[idx] = L_add( L_shr( inRe_fx[0][ts][idx], 1 ), L_shr( inRe_fx[1][ts][idx], 1 ) ); + temp_signal_fx[idx] = L_add( L_shr( inRe_fx[0][ts][idx], 1 ), L_shr( inRe_fx[1][ts][idx], 1 ) ); // q_cldfb[][]-1 move32(); - inRe_fx[1][ts][idx] = L_sub( L_shr( inRe_fx[0][ts][idx], 1 ), L_shr( inRe_fx[1][ts][idx], 1 ) ); + inRe_fx[1][ts][idx] = L_sub( L_shr( inRe_fx[0][ts][idx], 1 ), L_shr( inRe_fx[1][ts][idx], 1 ) ); // q_cldfb[][]-1 move32(); inRe_fx[0][ts][idx] = temp_signal_fx[idx]; move32(); @@ -262,9 +262,9 @@ void ivas_sba_prototype_renderer_fx( FOR( Word16 idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { - temp_signal_fx[idx] = L_add( L_shr( inIm_fx[0][ts][idx], 1 ), L_shr( inIm_fx[1][ts][idx], 1 ) ); + temp_signal_fx[idx] = L_add( L_shr( inIm_fx[0][ts][idx], 1 ), L_shr( inIm_fx[1][ts][idx], 1 ) ); // q_cldfb[][]-1 move32(); - inIm_fx[1][ts][idx] = L_sub( L_shr( inIm_fx[0][ts][idx], 1 ), L_shr( inIm_fx[1][ts][idx], 1 ) ); + inIm_fx[1][ts][idx] = L_sub( L_shr( inIm_fx[0][ts][idx], 1 ), L_shr( inIm_fx[1][ts][idx], 1 ) ); // q_cldfb[][]-1 move32(); inIm_fx[0][ts][idx] = temp_signal_fx[idx]; move32(); diff --git a/lib_rend/ivas_shoebox.c b/lib_rend/ivas_shoebox.c index 58569676051c721bc95f7b8deeaa0144dfcaefb9..1cbdc63c189668c016f9c3bff294538fc4678c27 100644 --- a/lib_rend/ivas_shoebox.c +++ b/lib_rend/ivas_shoebox.c @@ -49,18 +49,19 @@ * Local constants *------------------------------------------------------------------------*/ -#define ER_MAX_SOURCES 25 -#define ER_REF_ORDER 1 +#define ER_MAX_SOURCES 25 +#define ER_REF_ORDER 1 +#ifndef IVAS_FLOAT_FIXED #define ER_AIR_COEFF ( 0.00137f ) #define ER_SOUND_SPEED ( 343.0f ) #define ER_MIN_WALL_DIST ( 0.1f ) #define ER_EUCLIDEAN_SCALE ( 1.29246971E-26f ) -#ifdef IVAS_FLOAT_FIXED -#define ER_AIR_COEFF_FX ( Word32 )( 0.00137 * ONE_IN_Q31 ) // Q.31 -#define ER_SOUND_SPEED_FX ( Word32 )( 1 / 343.0 * ONE_IN_Q31 ) // 1/343.0f in Q1.31 -#define ER_MIN_WALL_DIST_FX ( Word32 )( 0.1 * ONE_IN_Q22 ) // Q.22 -#define ER_EUCLIDEAN_SCALE_FX ( 0x1 ) ////Q.22 -#define ER_RECIPROCAL_EUCLIDEAN_SCALE_FX ( 0x1 ) // Q.22 +#else +#define ER_AIR_COEFF_FX ( Word32 )( 2942053 ) // 0.00137f in Q.31 +#define ER_SOUND_SPEED_FX ( Word32 )( 6260885 ) // 1/343.0f in Q1.31 +#define ER_MIN_WALL_DIST_FX ( Word32 )( 419430 ) // Q.22 +#define ER_EUCLIDEAN_SCALE_FX ( 0x1 ) // Q.22 +#define ER_RECIPROCAL_EUCLIDEAN_SCALE_FX ( 0x1 ) // Q.22 #endif @@ -192,9 +193,8 @@ void ivas_shoebox_init( move32(); /* Add defaults */ obj->max_bands = 1; - obj->MAX_SOURCES = ER_MAX_SOURCES; - obj->REF_ORDER = ER_REF_ORDER; - move16(); + obj->MAX_SOURCES = ER_MAX_SOURCES; // Q0 + obj->REF_ORDER = ER_REF_ORDER; // Q0 move16(); move16(); move16(); @@ -225,10 +225,10 @@ void ivas_shoebox_init( move16(); /* Params */ - obj->radius_fx = ER_RADIUS_FX; - obj->min_wall_dist_fx = ER_MIN_WALL_DIST_FX; - obj->soundspeed_fx = ER_SOUND_SPEED_FX; - obj->air_coeff_fx = ER_AIR_COEFF_FX; + obj->radius_fx = ER_RADIUS_FX; // Q30 + obj->min_wall_dist_fx = ER_MIN_WALL_DIST_FX; // Q22 + obj->soundspeed_fx = ER_SOUND_SPEED_FX; // Q31 + obj->air_coeff_fx = ER_AIR_COEFF_FX; // Q31 move32(); move32(); move32(); @@ -305,7 +305,8 @@ static void shoebox_bound( #else static void shoebox_bound_fx( shoebox_obj_t *obj, - Word32 *out_pos ) + Word32 *out_pos // Q22 +) { Word32 out_tmp, out_tmp1; Word32 i; @@ -360,7 +361,7 @@ static void shoebox_bound_fx( } move32(); } - out_pos[1] = W_extract_l( W_mult0_32_32( out_tmp, i ) ); + out_pos[1] = W_extract_l( W_mult0_32_32( out_tmp, i ) ); // Q22 move32(); } @@ -387,7 +388,7 @@ static void shoebox_bound_fx( } move32(); } - out_pos[2] = (Word32) W_mult0_32_32( out_tmp, (Word32) i ); + out_pos[2] = W_extract_l( W_mult0_32_32( out_tmp, (Word32) i ) ); // Q22 move32(); } @@ -482,9 +483,9 @@ static void shoebox_get_coord( static void shoebox_get_coord_fx( shoebox_obj_t *obj, - Word32 *fcnOutput_data, - const Word32 src_pos_data[], - Word32 *tmp_pos, + Word32 *fcnOutput_data, // 0th and 1st idx in Q0 and 2nd idx in Q30 + const Word32 src_pos_data[], // Q22 + Word32 *tmp_pos, // Q22 Word32 out_tmp, Word32 coord, Word32 loop_ub, @@ -501,18 +502,18 @@ static void shoebox_get_coord_fx( IF( obj->isCartesian == 0 ) { /* Convert Spherical to Cartesian */ - tmp_data[2] = Mpy_32_32( fcnOutput_data[2], shoebox_sin_cos_tbl_fx[fcnOutput_data[1]][0] ); //.29 = .30 * .30 + tmp_data[2] = Mpy_32_32( fcnOutput_data[2] /* Q30 */, shoebox_sin_cos_tbl_fx[fcnOutput_data[1] /* Q0 */][0] ); // Q29 = .Q30 * Q30 move32(); - rcoselev = Mpy_32_32( fcnOutput_data[2], shoebox_sin_cos_tbl_fx[fcnOutput_data[1]][1] ); //.29 = .30 * .30 - tmp_data[0] = Mpy_32_32( rcoselev, shoebox_sin_cos_tbl_fx[fcnOutput_data[0]][1] ); // .28 =.29*.30 + rcoselev = Mpy_32_32( fcnOutput_data[2] /* Q30 */, shoebox_sin_cos_tbl_fx[fcnOutput_data[1] /* Q0 */][1] ); // Q29 = Q30 * Q30 + tmp_data[0] = Mpy_32_32( rcoselev, shoebox_sin_cos_tbl_fx[fcnOutput_data[0] /* Q0 */][1] ); // Q28 =Q29*Q30 move32(); - tmp_data[1] = Mpy_32_32( rcoselev, shoebox_sin_cos_tbl_fx[fcnOutput_data[0]][0] ); // .28 = .29*.30 + tmp_data[1] = Mpy_32_32( rcoselev, shoebox_sin_cos_tbl_fx[fcnOutput_data[0] /* Q0 */][0] ); // Q28 = Q29*Q30 move32(); - tmp_data[0] = L_shr( tmp_data[0], 6 ); + tmp_data[0] = L_shr( tmp_data[0], 6 ); // Q28 -> Q22 move32(); - tmp_data[1] = L_shr( tmp_data[1], 6 ); + tmp_data[1] = L_shr( tmp_data[1], 6 ); // Q28 -> Q22 move32(); - tmp_data[2] = L_shr( tmp_data[2], 7 ); + tmp_data[2] = L_shr( tmp_data[2], 7 ); // Q29 -> Q22 move32(); } ELSE @@ -528,14 +529,14 @@ static void shoebox_get_coord_fx( IF( obj->isZHeight != 0 ) { /* FIX Z COORDINATE */ - tmp_data[2] = L_sub( src_pos_data[L_add( k, 2 )], L_shr( obj->cal.room_H_fx, 1 ) ); + tmp_data[2] = L_sub( src_pos_data[k + 2] /* Q22 */, L_shr( obj->cal.room_H_fx, 1 ) ); // Q22 move32(); } } FOR( k = 0; k < tmp_size_idx_1; k++ ) { - obj->src_pos_fx[L_add( coord, k ) - 1] = tmp_data[k]; //.22 + obj->src_pos_fx[coord + k - 1] = tmp_data[k]; // Q22 move32(); } @@ -543,18 +544,18 @@ static void shoebox_get_coord_fx( k = L_add( out_tmp, 1 ); - tmp_pos[0] = obj->src_pos_fx[k - 1]; //.22 - tmp_pos[1] = obj->src_pos_fx[k]; - tmp_pos[2] = obj->src_pos_fx[k + 1]; + tmp_pos[0] = obj->src_pos_fx[k - 1]; // Q22 + tmp_pos[1] = obj->src_pos_fx[k]; // Q22 + tmp_pos[2] = obj->src_pos_fx[k + 1]; // Q22 move32(); move32(); move32(); IF( isRelative != 0 ) { - tmp_pos[0] = L_add( tmp_pos[0], obj->list_pos_fx[0] ); //.22 - tmp_pos[1] = L_add( tmp_pos[1], obj->list_pos_fx[1] ); - tmp_pos[2] = L_add( tmp_pos[2], obj->list_pos_fx[2] ); + tmp_pos[0] = L_add( tmp_pos[0], obj->list_pos_fx[0] ); // Q22 + tmp_pos[1] = L_add( tmp_pos[1], obj->list_pos_fx[1] ); // Q22 + tmp_pos[2] = L_add( tmp_pos[2], obj->list_pos_fx[2] ); // Q22 move32(); move32(); @@ -627,13 +628,14 @@ static float shoebox_get_euclidian_distance_internal( #else static Word32 shoebox_get_euclidian_distance_internal_fx( shoebox_obj_t *obj, - Word32 *tmp_pos, - Word32 *scale ) + Word32 *tmp_pos, // Q22 + Word32 *scale // Q22 +) { Word32 absxk, out_tmp, t; Word16 q; - absxk = L_abs( L_sub( obj->list_pos_fx[0], tmp_pos[0] ) ); // Q.22-Q22 + absxk = L_abs( L_sub( obj->list_pos_fx[0], tmp_pos[0] ) ); // Q22-Q22 IF( GT_32( absxk, ER_EUCLIDEAN_SCALE_FX ) ) { @@ -658,15 +660,15 @@ static Word32 shoebox_get_euclidian_distance_internal_fx( out_tmp = W_extract_h( W_shl( W_mult_32_32( out_tmp, t ), q ) ); // Q22 + Q31 + Q1 - 32 = Q22 out_tmp = W_extract_h( W_shl( W_mult_32_32( out_tmp, t ), q ) ); // Q22 + Q31 + Q1 - 32 = Q22 - out_tmp = L_add( out_tmp, ONE_IN_Q22 ); //.22 - *scale = absxk; // Q.22 + out_tmp = L_add( out_tmp, ONE_IN_Q22 ); // Q22 + *scale = absxk; // Q22 move32(); } ELSE { t = (Word32) BASOP_Util_Divide3232_Scale_cadence( absxk, *scale, &q ); t = W_extract_h( W_shl( W_mult_32_32( t, t ), sub( shl( q, 1 ), 9 ) ) ); // Q31 + Q31 + Q1 - 9 - 32 = Q22 - out_tmp = L_add( out_tmp, t ); //.22 + out_tmp = L_add( out_tmp, t ); // Q22 move32(); } @@ -676,17 +678,17 @@ static Word32 shoebox_get_euclidian_distance_internal_fx( { t = (Word32) BASOP_Util_Divide3232_Scale_cadence( *scale, absxk, &q ); - out_tmp = W_extract_h( W_shl( W_mult_32_32( out_tmp, t ), q ) ); // Q22 + Q31 + Q1 - 32 = Q22 - out_tmp = W_extract_h( W_shl( W_mult_32_32( out_tmp, t ), q ) ); // Q22 + Q31 + Q1 - 32 = Q22 - out_tmp = L_add( out_tmp, ONE_IN_Q22 ); //.22 - *scale = absxk; // Q.22 + out_tmp = W_extract_h( W_shl( W_mult_32_32( out_tmp, t ), q ) ); // Q22 + Q31 + Q1 - 32 = Q22 + out_tmp = W_extract_h( W_shl( W_mult_32_32( out_tmp, t ), q ) ); // Q22 + Q31 + Q1 - 32 = Q22 + out_tmp = L_add( out_tmp, ONE_IN_Q22 ); // Q22 + *scale = absxk; // Q22 move32(); } ELSE { t = (Word32) BASOP_Util_Divide3232_Scale_cadence( absxk, *scale, &q ); t = W_extract_h( W_shl( W_mult_32_32( t, t ), sub( shl( q, 1 ), 9 ) ) ); // Q31 + Q31 + Q1 - 9 - 32 = Q22 - out_tmp = L_add( out_tmp, t ); //.22 + out_tmp = L_add( out_tmp, t ); // Q22 } return out_tmp; @@ -851,8 +853,8 @@ void ivas_shoebox_set_scene( void ivas_shoebox_set_scene( shoebox_obj_t *obj, shoebox_output_t *ER_PARAMS, - const Word32 list_pos_fx[3], - const Word32 src_pos_data[], + const Word32 list_pos_fx[3], // Q22 + const Word32 src_pos_data[], // 0th and 1st idx in Q0 and 2nd idx in Q30 const UWord16 isCartesian, const UWord16 isRelative ) { @@ -881,20 +883,20 @@ void ivas_shoebox_set_scene( set32_fx( &obj->src_pos_fx[0], 0, 75U ); - obj->list_pos_fx[0] = list_pos_fx[0]; - obj->list_pos_fx[1] = list_pos_fx[1]; - obj->list_pos_fx[2] = list_pos_fx[2]; + obj->list_pos_fx[0] = list_pos_fx[0]; // Q22 + obj->list_pos_fx[1] = list_pos_fx[1]; // Q22 + obj->list_pos_fx[2] = list_pos_fx[2]; // Q22 move32(); move32(); move32(); /* ---------- ADJUST LISTENER ------------- */ IF( obj->isZHeight != 0 ) { - obj->list_pos_fx[2] = L_sub( list_pos_fx[2], L_shr( obj->cal.room_H_fx, 1 ) ); // Q.22 + obj->list_pos_fx[2] = L_sub( list_pos_fx[2], L_shr( obj->cal.room_H_fx, 1 ) ); // Q22 move32(); } - tmp_pos_fx[1] = obj->list_pos_fx[1]; - tmp_pos_fx[2] = obj->list_pos_fx[2]; + tmp_pos_fx[1] = obj->list_pos_fx[1]; // Q22 + tmp_pos_fx[2] = obj->list_pos_fx[2]; // Q22 move32(); move32(); @@ -922,14 +924,14 @@ void ivas_shoebox_set_scene( FOR( n = 0; n < loop_ub; n++ ) { - fcnOutput_data_fx[n] = src_pos_data[L_add( k, n )]; + fcnOutput_data_fx[n] = src_pos_data[k + n]; move32(); } shoebox_get_coord_fx( obj, fcnOutput_data_fx, src_pos_data, tmp_pos_fx, out_tmp, coord, loop_ub, k, isRelative ); shoebox_bound_fx( obj, tmp_pos_fx ); - scale_fx = ER_EUCLIDEAN_SCALE_FX; + scale_fx = ER_EUCLIDEAN_SCALE_FX; // Q22 move32(); out_tmp_fx = shoebox_get_euclidian_distance_internal_fx( obj, tmp_pos_fx, &scale_fx ); q_format = Q31 - Q22; @@ -950,7 +952,7 @@ void ivas_shoebox_set_scene( /* 2. ER_struct : Early reflection structure */ /* 3. src_num : Index of source to compute patterns for */ /* ------ */ - out_tmp_fx = obj->src_dist_fx[j]; + out_tmp_fx = obj->src_dist_fx[j]; // Q22 move32(); FOR( loop_ub = 0; loop_ub < 6; loop_ub++ ) @@ -970,8 +972,8 @@ void ivas_shoebox_set_scene( /* Initialize image position coordinates */ im_pos_fx[0] = tmp_pos_fx[0]; // Q:22 - im_pos_fx[1] = tmp_pos_fx[1]; - im_pos_fx[2] = tmp_pos_fx[2]; + im_pos_fx[1] = tmp_pos_fx[1]; // Q:22 + im_pos_fx[2] = tmp_pos_fx[2]; // Q:22 move32(); move32(); move32(); @@ -996,7 +998,7 @@ void ivas_shoebox_set_scene( im_pos_fx[coord] = L_add( tmp_pos_fx[coord], - L_shl( L_sub( L_shr( (Word32) W_mult0_32_32( ( L_negate( L_sub( 1, L_shl( L_and( L_add( loop_ub, 1 ), 1 ), 1 ) ) ) ), scale_fx ), 1 ), tmp_pos_fx[coord] ), 1 ) ); // Q:22 + L_shl( L_sub( L_shr( W_extract_l( W_mult0_32_32( ( L_negate( L_sub( 1, L_shl( L_and( L_add( loop_ub, 1 ), 1 ), 1 ) ) ) ), scale_fx ) ), 1 ), tmp_pos_fx[coord] ), 1 ) ); // Q:22 move32(); /* 0. Get euclidean distance from IMAGE SOURCE [N,W] to LIST */ @@ -1006,23 +1008,23 @@ void ivas_shoebox_set_scene( q_format = Q31 - Q22; move16(); - path_dist_fx = Sqrt32( path_dist_fx, &q_format ); // Input: Q:22, Output : Q.30 + path_dist_fx = Sqrt32( path_dist_fx, &q_format ); // Input: Q:22, Output : Q30 - path_dist_fx = Mpy_32_32( scale_fx, path_dist_fx ); // Q22 * Q = Q - path_dist_fx = L_shl( path_dist_fx, q_format ); + path_dist_fx = Mpy_32_32( scale_fx, path_dist_fx ); // Q22 + (31 - q_format) - 31 = Q22 - q_format + path_dist_fx = L_shl( path_dist_fx, q_format ); // Q22 - q_format + (q_format) = Q22 /* 1. Compute time-of arrival (TOA) */ - ER_PARAMS->times.data_fx[rcoselev - 1] = Mpy_32_32( path_dist_fx, obj->soundspeed_fx ); // Q.22 + ER_PARAMS->times.data_fx[rcoselev - 1] = Mpy_32_32( path_dist_fx, obj->soundspeed_fx ); // Q22 move32(); /* 2./3. DOA */ - sub_im_nd_list_pos_1 = L_sub( im_pos_fx[1], obj->list_pos_fx[1] ); // Q.22 - sub_im_nd_list_pos_0 = L_sub( im_pos_fx[0], obj->list_pos_fx[0] ); // Q.22 + sub_im_nd_list_pos_1 = L_sub( im_pos_fx[1], obj->list_pos_fx[1] ); // Q22 + sub_im_nd_list_pos_0 = L_sub( im_pos_fx[0], obj->list_pos_fx[0] ); // Q22 q_format = Q22 - Q22; move16(); - atan_pos = BASOP_util_atan2( sub_im_nd_list_pos_1, sub_im_nd_list_pos_0, q_format ); // Q.13 - az_angle_d = rad2deg_fx( atan_pos ); // Q.23 + atan_pos = BASOP_util_atan2( sub_im_nd_list_pos_1, sub_im_nd_list_pos_0, q_format ); // Q13 + az_angle_d = rad2deg_fx( atan_pos ); // Q23 ER_PARAMS->az_angle.data_fx[rcoselev - 1] = az_angle_d; move32(); @@ -1045,7 +1047,7 @@ void ivas_shoebox_set_scene( q_format_n = Q31 - Q31; asin_val = BASOP_util_atan2( sub_im_nd_list_div_path, one_minus_sub_im_nd_list_div_path_sq_rt, q_format_n ); // Q13 - asin_val_deg = rad2deg_fx( asin_val ); // Q.23 + asin_val_deg = rad2deg_fx( asin_val ); // Q23 ER_PARAMS->el_angle.data_fx[rcoselev - 1] = asin_val_deg; move32(); @@ -1054,7 +1056,7 @@ void ivas_shoebox_set_scene( /* and propagation loss */ if ( LT_32( path_dist_fx, out_tmp_fx ) ) { - path_dist_fx = out_tmp_fx; + path_dist_fx = out_tmp_fx; // Q22 move32(); } @@ -1068,7 +1070,7 @@ void ivas_shoebox_set_scene( pro_pd_air_coeff = Mpy_32_32( path_dist_fx, obj->air_coeff_fx ); // Q.22 *Q.31 =Q.22 result_gain = L_sub( product, pro_pd_air_coeff ); - ER_PARAMS->gains.data_fx[rcoselev - 1] = result_gain; + ER_PARAMS->gains.data_fx[rcoselev - 1] = result_gain; // Q22 move32(); } } diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index b6f6274cf413f44126604b86b023552c28268d15..49808bdd1c7936dd81301e37533bdb54424ca4f1 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -94,10 +94,10 @@ typedef struct ivas_output_setup_structure typedef struct ivas_td_decorr_APD_filt_state_t { - int16_t order[IVAS_MAX_DECORR_APD_SECTIONS]; - int16_t idx[IVAS_MAX_DECORR_APD_SECTIONS]; + Word16 order[IVAS_MAX_DECORR_APD_SECTIONS]; + Word16 idx[IVAS_MAX_DECORR_APD_SECTIONS]; #ifdef IVAS_FLOAT_FIXED - Word16 coeffs[IVAS_MAX_DECORR_APD_SECTIONS]; + Word16 coeffs[IVAS_MAX_DECORR_APD_SECTIONS]; // Q15 Word32 *state[IVAS_MAX_DECORR_APD_SECTIONS]; #else float coeffs[IVAS_MAX_DECORR_APD_SECTIONS]; @@ -116,11 +116,11 @@ typedef struct ivas_td_decorr_state_t #endif ivas_td_decorr_APD_filt_state_t APD_filt_state[IVAS_MAX_DECORR_CHS]; - int16_t num_apd_outputs; - int16_t num_apd_sections; - int16_t ducking_flag; + Word16 num_apd_outputs; + Word16 num_apd_sections; + Word16 ducking_flag; - int16_t offset; + Word16 offset; } ivas_td_decorr_state_t; @@ -132,8 +132,8 @@ typedef struct ivas_td_decorr_state_t /*Onset detector*/ typedef struct dirac_onset_detection_params_structure { - int16_t num_freq_bands; - int16_t max_band_decorr; + Word16 num_freq_bands; + Word16 max_band_decorr; } DIRAC_ONSET_DETECTION_PARAMS; @@ -153,11 +153,11 @@ typedef struct dirac_onset_detection_state_structure /*Decorrelator*/ typedef struct dirac_decorr_params_structure { - int16_t max_band_decorr; - int16_t max_frequency; + Word16 max_band_decorr; + Word16 max_frequency; - int16_t *pre_delay; - int16_t *filter_length; + Word16 *pre_delay; + Word16 *filter_length; #ifndef IVAS_FLOAT_FIXED float *filter_coeff_num_real; float *filter_coeff_den_real; @@ -169,11 +169,11 @@ typedef struct dirac_decorr_params_structure Word16 *phase_coeff_real_fx; /* Q14 */ Word16 *phase_coeff_imag_fx; /* Q14 */ #endif - int16_t *split_frequency_bands; - int16_t num_split_frequency_bands; + Word16 *split_frequency_bands; + Word16 num_split_frequency_bands; - int16_t use_ducker; - int16_t add_back_onsets_on; + Word16 use_ducker; + Word16 add_back_onsets_on; DIRAC_ONSET_DETECTION_PARAMS h_onset_detection_power_params; @@ -201,23 +201,23 @@ typedef struct dirac_decorr_state_structure typedef struct ivas_spatial_parametric_rend_common_data_structure { - int16_t slot_size; - int16_t subframe_nbslots[MAX_JBM_SUBFRAMES_5MS]; - int16_t subframes_rendered; - int16_t slots_rendered; - int16_t num_slots; - int16_t render_to_md_map[MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME]; - int16_t nb_subframes; + Word16 slot_size; + Word16 subframe_nbslots[MAX_JBM_SUBFRAMES_5MS]; + Word16 subframes_rendered; + Word16 slots_rendered; + Word16 num_slots; + Word16 render_to_md_map[MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME]; + Word16 nb_subframes; - int16_t num_freq_bands; - int16_t numSimultaneousDirections; /* From 1 to 2 + MAX_NUM_OBJECTS */ - int16_t numParametricDirections; /* 1 or 2 */ - int16_t numIsmDirections; /* From 0 to MAX_NUM_OBJECTS */ + Word16 num_freq_bands; + Word16 numSimultaneousDirections; /* From 1 to 2 + MAX_NUM_OBJECTS */ + Word16 numParametricDirections; /* 1 or 2 */ + Word16 numIsmDirections; /* From 0 to MAX_NUM_OBJECTS */ - int16_t **azimuth; - int16_t **elevation; - int16_t **azimuth2; - int16_t **elevation2; + Word16 **azimuth; + Word16 **elevation; + Word16 **azimuth2; + Word16 **elevation2; #ifndef IVAS_FLOAT_FIXED float **diffuseness_vector; @@ -241,9 +241,9 @@ typedef struct ivas_spatial_parametric_rend_common_data_structure #endif /* Metadata access indices and buffer size */ - int16_t dirac_bs_md_write_idx; - int16_t dirac_read_idx; - int16_t dirac_md_buffer_length; + Word16 dirac_bs_md_write_idx; + Word16 dirac_read_idx; + Word16 dirac_md_buffer_length; } SPAT_PARAM_REND_COMMON_DATA, *SPAT_PARAM_REND_COMMON_DATA_HANDLE; @@ -335,9 +335,9 @@ typedef struct dirac_dec_stack_mem /*Output synthesis*/ typedef struct dirac_output_synthesis_params_structure { - int16_t max_band_decorr; + Word16 max_band_decorr; - int16_t use_onset_filters; + Word16 use_onset_filters; #ifndef IVAS_FLOAT_FIXED float *interpolator; @@ -348,8 +348,8 @@ typedef struct dirac_output_synthesis_params_structure Word16 *alpha_synthesis_fx; /* Q15 */ Word16 *alpha_synthesis_fast_fx; /* Q15 */ #endif - int16_t numAlphas; - int16_t numAlphasFast; + Word16 numAlphas; + Word16 numAlphasFast; #ifdef IVAS_FLOAT_FIXED Word32 *proto_matrix_fx; @@ -521,7 +521,7 @@ typedef struct MASA_TRANSPORT_SIGNAL_TYPE current_stereo_type; MASA_TRANSPORT_SIGNAL_TYPE type_change_direction; - int16_t dipole_freq_range[2]; + Word16 dipole_freq_range[2]; #ifndef IVAS_FLOAT_FIXED float left_bb_power; @@ -584,8 +584,8 @@ typedef struct Word32 subtract_target_ratio_db_fx; /* Q21 */ #endif - int16_t counter; - int16_t interpolator; + Word16 counter; + Word16 interpolator; } MASA_STEREO_TYPE_DETECT; @@ -597,7 +597,7 @@ typedef struct ivas_mcmasa_lfe_synth_struct #else Word16 lfeToTotalEnergyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q14 */ #endif - int16_t lfeGainPrevIndex; + Word16 lfeGainPrevIndex; #ifndef IVAS_FLOAT_FIXED float transportEneSmooth; float protoLfeEneSmooth; @@ -619,41 +619,41 @@ typedef struct ivas_mcmasa_lfe_synth_struct #else Word32 *lfeSynthRingBuffer_fx; /* Q11 */ #endif - int16_t ringBufferLoPointer; - int16_t ringBufferHiPointer; + Word16 ringBufferLoPointer; + Word16 ringBufferHiPointer; #ifndef IVAS_FLOAT_FIXED float lowpassSum; #else Word32 lowpassSum_fx; /* Q11 */ #endif - int16_t ringBufferSize; + Word16 ringBufferSize; #ifndef IVAS_FLOAT_FIXED float *lfeSynthRingBuffer2; #else Word32 *lfeSynthRingBuffer2_fx; /* Q11 */ #endif - int16_t ringBufferLoPointer2; + Word16 ringBufferLoPointer2; #ifndef IVAS_FLOAT_FIXED float lowpassSum2; #else Word32 lowpassSum2_fx; /* Q11 */ #endif - int16_t ringBufferSize2; + Word16 ringBufferSize2; #ifndef IVAS_FLOAT_FIXED float *delayBuffer_syncLp; #else Word32 *delayBuffer_syncLp_fx; /* Q11 */ #endif - int16_t delayBuffer_syncLp_size; + Word16 delayBuffer_syncLp_size; #ifndef IVAS_FLOAT_FIXED float *delayBuffer_syncDirAC; #else Word32 *delayBuffer_syncDirAC_fx; /* Q11 */ #endif - int16_t delayBuffer_syncDirAC_size; + Word16 delayBuffer_syncDirAC_size; #ifndef IVAS_FLOAT_FIXED float lfeGainPrev; @@ -673,7 +673,7 @@ typedef struct ivas_dirac_rend_data_structure IVAS_OUTPUT_SETUP hOutSetup; /*Parameter estimation*/ - int16_t index_buffer_intensity; + Word16 index_buffer_intensity; #ifndef IVAS_FLOAT_FIXED float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; float *buffer_energy; @@ -697,19 +697,19 @@ typedef struct ivas_dirac_rend_data_structure #endif /*Decoder parameters */ /*Prototypes*/ - int16_t num_outputs_dir; - int16_t num_outputs_diff; - int16_t num_protos_dir; - int16_t num_protos_diff; - int16_t num_protos_ambi; + Word16 num_outputs_dir; + Word16 num_outputs_diff; + Word16 num_protos_dir; + Word16 num_protos_diff; + Word16 num_protos_ambi; DIRAC_SYNTHESIS_CONFIG synthesisConf; DIRAC_PANNING_CONFIG panningConf; /* prototype computing */ - int16_t *proto_index_dir; - int16_t *proto_index_diff; + Word16 *proto_index_dir; + Word16 *proto_index_diff; - int16_t proto_signal_decorr_on; + Word16 proto_signal_decorr_on; /*Decoder states=memories*/ #ifndef IVAS_FLOAT_FIXED @@ -727,9 +727,9 @@ typedef struct ivas_dirac_rend_data_structure DIRAC_DEC_STACK_MEM stack_mem; MASA_STEREO_TYPE_DETECT *masa_stereo_type_detect; - int16_t num_ele_spk_no_diffuse_rendering; + Word16 num_ele_spk_no_diffuse_rendering; - const int16_t *sba_map_tc; + const Word16 *sba_map_tc; DIRAC_OUTPUT_SYNTHESIS_PARAMS h_output_synthesis_psd_params; DIRAC_OUTPUT_SYNTHESIS_STATE h_output_synthesis_psd_state; @@ -748,7 +748,7 @@ typedef struct ivas_dirac_rend_data_structure * with a precalculated inverse matrix */ typedef struct vbap_vs_triplet_structure { - uint8_t speaker_node[3]; + UWord8 speaker_node[3]; #ifndef IVAS_FLOAT_FIXED float inverse_matrix[3][3]; #else @@ -763,8 +763,8 @@ typedef struct vbap_vs_triplet_structure typedef struct triplet_search_structure { VBAP_VS_TRIPLET *triplets; - int16_t num_triplets; - int16_t initial_search_indices[VBAP_NUM_SEARCH_SECTORS]; + Word16 num_triplets; + Word16 initial_search_indices[VBAP_NUM_SEARCH_SECTORS]; } VBAP_SEARCH_STRUCT; @@ -773,19 +773,19 @@ typedef struct triplet_search_structure typedef struct vbap_data_structure { VBAP_SEARCH_STRUCT search_struct[2]; /* Default to max two groups in this implementation */ - int16_t num_search_structs; - int16_t num_speaker_nodes; - int16_t num_speaker_nodes_internal; - int16_t top_virtual_speaker_node_index; /* These indices can be negative */ - int16_t bottom_virtual_speaker_node_index; - int16_t back_virtual_speaker_node_index; + Word16 num_search_structs; + Word16 num_speaker_nodes; + Word16 num_speaker_nodes_internal; + Word16 top_virtual_speaker_node_index; /* These indices can be negative */ + Word16 bottom_virtual_speaker_node_index; + Word16 back_virtual_speaker_node_index; #ifdef IVAS_FLOAT_FIXED - Word16 *bottom_virtual_speaker_node_division_gains_fx; - Word16 *top_virtual_speaker_node_division_gains_fx; - Word16 *back_virtual_speaker_node_division_gains_fx; - Word16 *object_mode_bottom_virtual_speaker_node_division_gains_fx; - Word16 *object_mode_top_virtual_speaker_node_division_gains_fx; - Word16 *object_mode_back_virtual_speaker_node_division_gains_fx; + Word16 *bottom_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *top_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *back_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *object_mode_bottom_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *object_mode_top_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *object_mode_back_virtual_speaker_node_division_gains_fx; /* Q16 */ #else float *bottom_virtual_speaker_node_division_gains; float *top_virtual_speaker_node_division_gains; @@ -904,7 +904,7 @@ typedef struct ivas_dirac_dec_binaural_data_structure float earlyPartEneCorrection[CLDFB_NO_CHANNELS_MAX]; #endif REVERB_STRUCT_HANDLE hReverb; - uint8_t renderStereoOutputInsteadOfBinaural; + UWord8 renderStereoOutputInsteadOfBinaural; #ifndef IVAS_FLOAT_FIXED float frameMeanDiffuseness[CLDFB_NO_CHANNELS_MAX]; float processMtxRePrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; @@ -968,7 +968,7 @@ typedef struct ivas_dirac_dec_binaural_data_structure Word32 diffuseFieldCoherenceY_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; Word32 diffuseFieldCoherenceZ_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; #endif - uint16_t useTdDecorr; + UWord16 useTdDecorr; ivas_td_decorr_state_t *hTdDecorr; #ifndef IVAS_FLOAT_FIXED float reqularizationFactor; @@ -1046,8 +1046,8 @@ typedef struct EFAP_VERTEX typedef struct EFAP_VERTEX_DATA { EFAP_VERTEX *vertexArray; /* Array of vertices */ - int16_t numVtx; /* Number of vertices */ - int16_t *vtxOrder; /* Array that indicates the order of the vertex ranked by increasing azimuth */ + Word16 numVtx; /* Number of vertices */ + Word16 *vtxOrder; /* Array that indicates the order of the vertex ranked by increasing azimuth */ } EFAP_VERTEX_DATA; #ifndef IVAS_FLOAT_FIXED @@ -1073,22 +1073,22 @@ typedef struct EFAP_POLYSET #endif typedef struct EFAP_LS_TRIANGLE { - int16_t LS[3]; /* Array indicating the loudspeaker index of the triangle vertices */ + Word16 LS[3]; /* Array indicating the loudspeaker index of the triangle vertices */ } EFAP_LS_TRIANGLE; typedef struct EFAP_POLYSET_DATA { EFAP_POLYSET polysetArray[EFAP_MAX_POLY_SET]; /* Array of polygons */ - int16_t numPoly; /* Number of polygons */ + Word16 numPoly; /* Number of polygons */ EFAP_LS_TRIANGLE triArray[EFAP_MAX_POLY_SET]; /* Array of triangles */ - int16_t numTri; /* Number of triangles */ + Word16 numTri; /* Number of triangles */ } EFAP_POLYSET_DATA; typedef struct EFAP { - int16_t numSpk; /* Number of loudspeakers */ + Word16 numSpk; /* Number of loudspeakers */ #ifndef IVAS_FLOAT_FIXED float *aziSpk; /* Loudspeaker azimuths */ float *eleSpk; /* Loudspeaker elevations */ @@ -1107,7 +1107,7 @@ typedef struct EFAP Word32 *bufferLong_fx; /* tmp buffer that will be given as a parameter for computing the gain; this is a 1D array of length numVtx */ Word32 *bufferShort_fx; /* tmp buffer that will be given as a parameter for computing the gain; this is the result of downMixMatrix*bufferLong, length is numSpk */ #endif - int16_t numTot; /* Total number of real + ghost loudspeakers, used later for freeing memory */ + Word16 numTot; /* Total number of real + ghost loudspeakers, used later for freeing memory */ } EFAP, *EFAP_HANDLE; @@ -1317,21 +1317,21 @@ typedef struct ivas_rev_delay_line_t #else Word32 *pBuffer_fx; #endif - uint16_t MaxDelay; - int16_t Delay; - uint16_t BufferPos; + UWord16 MaxDelay; + Word16 Delay; + UWord16 BufferPos; #ifndef IVAS_FLOAT_FIXED float Gain; #else - Word16 Gain_fx; + Word16 Gain_fx; // Q14 #endif } ivas_rev_delay_line_t; typedef struct ivas_rev_iir_filter_t { - uint16_t MaxTaps; - uint16_t nr_taps; - uint16_t isFIR; + UWord16 MaxTaps; + UWord16 nr_taps; + UWord16 isFIR; #ifndef IVAS_FLOAT_FIXED float Output; float CoefA[IVAS_REV_MAX_IIR_FILTER_LENGTH]; @@ -1397,14 +1397,14 @@ typedef struct ivas_reverb_state_t ivas_rev_delay_line_t predelay_line; Word32 *pPredelay_buffer_fx; /* jot reverberator: */ - uint16_t nr_of_branches; /* number of feedback loops */ + UWord16 nr_of_branches; /* number of feedback loops */ ivas_rev_delay_line_t delay_line[IVAS_REV_MAX_NR_BRANCHES]; /* feedback loop delays */ Word32 *loop_delay_buffer_fx[IVAS_REV_MAX_NR_BRANCHES]; /* feedback loop delay sample buffers */ ivas_rev_iir_filter_t t60[IVAS_REV_MAX_NR_BRANCHES]; /* feedback loop filters */ Word32 gain_matrix_fx[IVAS_REV_MAX_NR_BRANCHES][IVAS_REV_MAX_NR_BRANCHES]; /* feedback matrix */ Word16 mixer_fx[BINAURAL_CHANNELS][IVAS_REV_MAX_NR_BRANCHES]; /* binauralization filters: */ - int16_t do_corr_filter; + Word16 do_corr_filter; ivas_reverb_t2f_f2t_t fft_filter_ols; ivas_reverb_fft_filter_t fft_filter_correl_0; ivas_reverb_fft_filter_t fft_filter_correl_1; @@ -1473,24 +1473,24 @@ typedef struct float abs_coeff[IVAS_ROOM_ABS_COEFF]; float list_orig[3]; #else - Word32 room_L_fx; - Word32 room_W_fx; - Word32 room_H_fx; - Word32 abs_coeff_fx[IVAS_ROOM_ABS_COEFF]; - Word32 list_orig_fx[3]; + Word32 room_L_fx; // Q22 + Word32 room_W_fx; // Q22 + Word32 room_H_fx; // Q22 + Word32 abs_coeff_fx[IVAS_ROOM_ABS_COEFF]; // Q30 + Word32 list_orig_fx[3]; // Q22 #endif } shoebox_config_t; /* Structure to hold the corrected( bounded ) source and listener positions */ typedef struct { - uint16_t isCartesian; - uint16_t isRelative; - uint16_t isZHeight; - uint16_t isRadians; - uint16_t MAX_SOURCES; - uint16_t max_bands; - uint16_t REF_ORDER; + UWord16 isCartesian; + UWord16 isRelative; + UWord16 isZHeight; + UWord16 isRadians; + UWord16 MAX_SOURCES; + UWord16 max_bands; + UWord16 REF_ORDER; #ifndef IVAS_FLOAT_FIXED float src_pos[75]; @@ -1501,15 +1501,15 @@ typedef struct float soundspeed; float air_coeff; #else - Word32 src_dist_fx[25]; - Word32 list_pos_fx[3]; - Word32 src_pos_fx[75]; - Word32 radius_fx; - Word32 min_wall_dist_fx; - Word32 soundspeed_fx; - Word32 air_coeff_fx; + Word32 src_dist_fx[25]; // Q22 + Word32 list_pos_fx[3]; // Q22 + Word32 src_pos_fx[75]; // Q22 + Word32 radius_fx; // Q30 + Word32 min_wall_dist_fx; // Q22 + Word32 soundspeed_fx; // Q31 + Word32 air_coeff_fx; // Q31 #endif // IVAS_FLOAT_FIXED - uint16_t nSrc; + UWord16 nSrc; shoebox_config_t cal; @@ -1520,7 +1520,7 @@ typedef struct shoebox_data_t #ifndef IVAS_FLOAT_FIXED float data[150]; #else - Word32 data_fx[150]; + Word32 data_fx[150]; // Q22 #endif Word32 size[1]; @@ -1528,8 +1528,8 @@ typedef struct shoebox_data_t typedef struct { - uint16_t n_sources; - uint16_t n_ref; + UWord16 n_sources; + UWord16 n_ref; shoebox_data_t times; shoebox_data_t gains; shoebox_data_t az_angle; @@ -1584,24 +1584,24 @@ typedef struct er_struct_t typedef struct { - int16_t modelROM; /* Flag that indicates that the model resides in ROM (controls init/dealloc). */ - int16_t UseItdModel; /* Controls whether ITD model is used. */ - int16_t SplineDegree; /* Degree of the spline functions */ - int16_t K; /* Length of filter */ - int16_t elevDim2; - int16_t elevDim3; - int16_t AlphaN; /* Number of rows in Alpha matrices */ - int16_t num_unique_azim_splines; - int16_t elevSegSamples; - - int16_t elevBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; - int16_t elevBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; - const int16_t *azimDim2; - const int16_t *azimDim3; - const int16_t *azim_start_idx; - const int16_t *azimSegSamples; - const int16_t *azimShapeIdx; - const int16_t *azimShapeSampFactor; + Word16 modelROM; /* Flag that indicates that the model resides in ROM (controls init/dealloc). */ + Word16 UseItdModel; /* Controls whether ITD model is used. */ + Word16 SplineDegree; /* Degree of the spline functions */ + Word16 K; /* Length of filter */ + Word16 elevDim2; + Word16 elevDim3; + Word16 AlphaN; /* Number of rows in Alpha matrices */ + Word16 num_unique_azim_splines; + Word16 elevSegSamples; + + Word16 elevBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + Word16 elevBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + const Word16 *azimDim2; + const Word16 *azimDim3; + const Word16 *azim_start_idx; + const Word16 *azimSegSamples; + const Word16 *azimShapeIdx; + const Word16 *azimShapeSampFactor; #ifdef IVAS_FLOAT_FIXED const Word32 *elevKSeq_fx; /* Array, N x elevDim2 x elevDim3 */ @@ -1625,9 +1625,9 @@ typedef struct const float **azimBsShape; #endif // IVAS_FLOAT_FIXED - int16_t azimDim3Max; - int16_t iSecFirst[HRTF_MODEL_N_SECTIONS]; /* Indices for start of sections */ - int16_t iSecLast[HRTF_MODEL_N_SECTIONS]; /* Indices for end of sections */ + Word16 azimDim3Max; + Word16 iSecFirst[HRTF_MODEL_N_SECTIONS]; /* Indices for start of sections */ + Word16 iSecLast[HRTF_MODEL_N_SECTIONS]; /* Indices for end of sections */ #ifndef IVAS_FLOAT_FIXED const float *EL; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ const float *ER; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ @@ -1656,12 +1656,12 @@ typedef struct float *elevKSeq_dyn; float *elevBsShape_dyn; #endif - int16_t *azimDim2_dyn; - int16_t *azimDim3_dyn; - int16_t *azim_start_idx_dyn; - int16_t *azimSegSamples_dyn; - int16_t *azimShapeIdx_dyn; - int16_t *azimShapeSampFactor_dyn; + Word16 *azimDim2_dyn; + Word16 *azimDim3_dyn; + Word16 *azim_start_idx_dyn; + Word16 *azimSegSamples_dyn; + Word16 *azimShapeIdx_dyn; + Word16 *azimShapeSampFactor_dyn; #ifdef IVAS_FLOAT_FIXED Word32 **azimBsShape_dyn_fx; #else @@ -1672,33 +1672,33 @@ typedef struct typedef struct { - int16_t N; /* Polynomial degree */ + Word16 N; /* Polynomial degree */ - int16_t elevDim2; - int16_t elevDim3; + Word16 elevDim2; + Word16 elevDim3; #ifndef IVAS_FLOAT_FIXED const float *elevKSeq; /* Array, length elevDim3-2 */ #endif - int16_t azimDim2; - int16_t azimDim3; + Word16 azimDim2; + Word16 azimDim3; #ifndef IVAS_FLOAT_FIXED const float *azimKSeq; /* Array, length azimDim3-2 */ const float *W; /* Array, size (elevDim3*azimDim3) x K */ #endif - int16_t azimBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; - int16_t azimBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + Word16 azimBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + Word16 azimBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; #ifndef IVAS_FLOAT_FIXED const float *azimBsShape; #endif - int16_t azimSegSamples; + Word16 azimSegSamples; - int16_t elevBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; - int16_t elevBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + Word16 elevBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + Word16 elevBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; #ifndef IVAS_FLOAT_FIXED const float *elevBsShape; #endif - int16_t elevSegSamples; + Word16 elevSegSamples; #ifndef IVAS_FLOAT_FIXED float resamp_factor; #else @@ -1743,7 +1743,7 @@ typedef struct #else Word32 val_fx; #endif - int16_t i; + Word16 i; } ValueIndex_t; @@ -1757,8 +1757,8 @@ typedef struct #endif ValueIndex_t BMEnergiesL[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; ValueIndex_t BMEnergiesR[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; - int16_t UseIndsL[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; - int16_t UseIndsR[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; + Word16 UseIndsL[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; + Word16 UseIndsR[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; #ifndef IVAS_FLOAT_FIXED float *hrfModL; float *hrfModR; @@ -1786,7 +1786,7 @@ typedef struct /* Mixer listener */ typedef struct { - int16_t PoseUpdated; + Word16 PoseUpdated; #ifdef IVAS_FLOAT_FIXED Word32 Pos_fx[3]; Word16 Pos_q; @@ -1802,16 +1802,16 @@ typedef struct float Vel[3]; #endif // IVAS_FLOAT_FIXED - int16_t VelUpdated; + Word16 VelUpdated; } TDREND_MIX_Listener_t; /* HR filter */ typedef struct TDREND_HRFILT_FiltSet_struct { - int32_t SampleRate; /* Sample rate of the HR filter */ - int16_t NumPos; - int16_t NumElev; + Word32 SampleRate; /* Sample rate of the HR filter */ + Word16 NumPos; + Word16 NumElev; #ifndef IVAS_FLOAT_FIXED float Dist; float *ItdSet_p; @@ -1819,7 +1819,7 @@ typedef struct TDREND_HRFILT_FiltSet_struct Word32 Dist_fx; Word32 *ItdSet_p_fx; #endif - int16_t FiltLength; + Word16 FiltLength; #ifndef IVAS_FLOAT_FIXED float *Azim_p; float *Elev_p; @@ -1883,18 +1883,18 @@ typedef struct /* Mixer spatial specification */ typedef struct { - int16_t UseCommonDistAttenModel; /* Common distance attenuation model flag */ + Word16 UseCommonDistAttenModel; /* Common distance attenuation model flag */ TDREND_DistAttenModel_t DistAttenModel; /* Distance attenuation model */ } TDREND_MixSpatSpec_t; typedef struct TDREND_SRC_REND_s { - int16_t InputAvailable; + Word16 InputAvailable; TDREND_PlayStatus_t PlayStatus; /* Gains */ - int16_t SrcGainUpdated; + Word16 SrcGainUpdated; #ifdef IVAS_FLOAT_FIXED Word16 SrcGain_p_fx[SPAT_BIN_MAX_INPUT_CHANNELS]; // Q14 Word16 SrcGainMin_p_fx[SPAT_BIN_MAX_INPUT_CHANNELS]; @@ -1913,7 +1913,7 @@ typedef struct TDREND_SRC_REND_s /* Source spatial parameters */ typedef struct { - int16_t Updated; + Word16 Updated; TDREND_PosType_t PosType; #ifndef IVAS_FLOAT_FIXED float Pos_p[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; @@ -1924,9 +1924,9 @@ typedef struct Word16 q_Pos_p; Word32 Front_p_fx[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; // Q30 #endif // IVAS_FLOAT_FIXED - int16_t DirAttenEnabled; + Word16 DirAttenEnabled; TDREND_DirAtten_t DirAtten; - int16_t DistAttenEnabled; + Word16 DistAttenEnabled; TDREND_DistAtten_t DistAtten; } TDREND_SRC_SPATIAL_t; @@ -1940,9 +1940,9 @@ typedef struct #endif TDREND_SRC_SPATIAL_t *SrcSpatial_p; TDREND_SRC_REND_t *SrcRend_p; - int16_t itd; - int16_t previtd; - int16_t filterlength; + Word16 itd; + Word16 previtd; + Word16 filterlength; #ifdef IVAS_FLOAT_FIXED Word32 mem_itd_fx[ITD_MEM_LEN]; /* Q11 */ Word32 mem_hrf_left_fx[SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1]; @@ -1974,8 +1974,8 @@ typedef struct ivas_binaural_td_rendering_struct { TDREND_MixSpatSpec_t *TdRend_MixSpatSpec_p; TDREND_DirAtten_t *DirAtten_p; - int16_t NumOfSrcs; - int16_t MaxSrcInd; + Word16 NumOfSrcs; + Word16 MaxSrcInd; TDREND_SRC_t *Sources[MAX_NUM_TDREND_CHANNELS]; #ifdef IVAS_FLOAT_FIXED @@ -1987,8 +1987,8 @@ typedef struct ivas_binaural_td_rendering_struct TDREND_MIX_Listener_t *Listener_p; /* The virtual listener */ TDREND_HRFILT_FiltSet_t *HrFiltSet_p; /* HR filter set */ - int16_t UseCommonDistAttenModel; /* Use common dist atten model (TRUE/FALSE) */ - int16_t DistAttenEnabled; /* (TRUE/FALSE) */ + Word16 UseCommonDistAttenModel; /* Use common dist atten model (TRUE/FALSE) */ + Word16 DistAttenEnabled; /* (TRUE/FALSE) */ TDREND_DistAttenModel_t DistAttenModel; /* Common distance attenuation model */ } BINAURAL_TD_OBJECT_RENDERER, *BINAURAL_TD_OBJECT_RENDERER_HANDLE; @@ -2008,10 +2008,10 @@ typedef struct #ifdef IVAS_FLOAT_FIXED typedef struct ivas_hrtfs_structure { - Word32 *pOut_to_bin_re_fx[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS]; - Word32 *pOut_to_bin_im_fx[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS]; - Word32 *pOut_to_bin_diffuse_re_fx[BINAURAL_CHANNELS]; - Word32 *pOut_to_bin_diffuse_im_fx[BINAURAL_CHANNELS]; + Word32 *pOut_to_bin_re_fx[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS]; // Q29 + Word32 *pOut_to_bin_im_fx[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS]; // Q29 + Word32 *pOut_to_bin_diffuse_re_fx[BINAURAL_CHANNELS]; // Q31 + Word32 *pOut_to_bin_diffuse_im_fx[BINAURAL_CHANNELS]; // Q31 UWord16 num_iterations[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS]; UWord16 num_iterations_diffuse[BINAURAL_CHANNELS]; UWord16 *pIndex_frequency_max[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS]; @@ -2019,9 +2019,9 @@ typedef struct ivas_hrtfs_structure UWord16 index_frequency_max_diffuse; Word16 max_num_ir; Word16 max_num_iterations; - Word16 inv_diffuse_weight_fx[MAX_INTERN_CHANNELS]; /* inverse diffuse weights array, access one inverse weight by pInvDiffuseWeight[channel] */ + Word16 inv_diffuse_weight_fx[MAX_INTERN_CHANNELS]; /* inverse diffuse weights array, access one inverse weight by pInvDiffuseWeight[channel] Q15 */ Word32 latency_s_fx; - Word16 gain_lfe_fx; + Word16 gain_lfe_fx; // Q14 } HRTFS_DATA, *HRTFS_HANDLE; #else typedef struct ivas_hrtfs_structure @@ -2202,7 +2202,7 @@ typedef struct ivas_hrtfs_fastconv_struct float FASTCONV_FOA_latency_s; #endif - int16_t allocate_init_flag; /*Memory allocation flag 0: if the hrtf pointers are allocated at application level , 1: of allocated at ivas_binaural_hrtf_open() */ + Word16 allocate_init_flag; /*Memory allocation flag 0: if the hrtf pointers are allocated at application level , 1: of allocated at ivas_binaural_hrtf_open() */ #ifdef IVAS_FLOAT_FIXED Word32 fastconvReverberationTimes_fx[CLDFB_NO_CHANNELS_MAX]; /* Q31 */ @@ -2290,8 +2290,8 @@ typedef struct ivas_LS_setupconversion_struct #else Word32 *dmxEnergyPrev_fx[MAX_OUTPUT_CHANNELS]; #endif - int16_t sfbOffset[MAX_SFB + 2]; - int16_t sfbCnt; + Word16 sfbOffset[MAX_SFB + 2]; + Word16 sfbCnt; #ifdef IVAS_FLOAT_FIXED Word16 te_prev_exp; Word16 dmx_prev_exp; @@ -2350,8 +2350,8 @@ typedef struct ivas_LS_setup_custom { Word16 is_planar_setup; /* flag to indicate if setup is planar or not */ Word16 num_spk; /* number of custom loudspeakers */ - Word32 ls_azimuth_fx[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker azimuths */ - Word32 ls_elevation_fx[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker elevations */ + Word32 ls_azimuth_fx[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker azimuths Q22 */ + Word32 ls_elevation_fx[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker elevations Q22 */ Word16 num_lfe; /* number of LFE channels */ Word16 lfe_idx[MAX_OUTPUT_CHANNELS]; /* index for LFE channel insertion */ Word16 separate_ch_found; /* flag to indicate if a center channel was found */ @@ -2388,8 +2388,8 @@ typedef enum typedef struct ivas_masa_external_rendering_struct { - int16_t nchan_input; - int16_t nchan_output; + Word16 nchan_input; + Word16 nchan_output; RENDERER_TYPE renderer_type; DIRAC_REND_HANDLE hDirACRend; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; @@ -2495,10 +2495,10 @@ typedef struct ivas_mcmasa_ana_data_structure typedef struct ivas_omasa_ana_data_structure { - int16_t nbands; + Word16 nbands; /* CLDFB analysis */ - int16_t num_Cldfb_instances; + Word16 num_Cldfb_instances; HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_OBJECTS]; /* DirAC parameter estimation */ @@ -2507,11 +2507,11 @@ typedef struct ivas_omasa_ana_data_structure float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ #endif - int16_t band_grouping[MASA_FREQUENCY_BANDS + 1]; - int16_t block_grouping[5]; + Word16 band_grouping[MASA_FREQUENCY_BANDS + 1]; + Word16 block_grouping[5]; /* diffuseness */ - int16_t index_buffer_intensity; + Word16 index_buffer_intensity; #ifndef IVAS_FLOAT_FIXED float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; @@ -2560,10 +2560,10 @@ typedef struct ivas_omasa_ana_data_structure #ifdef IVAS_FLOAT_FIXED typedef struct ivas_dirac_ana_data_structure { - int16_t nbands; + Word16 nbands; /* CLDFB analysis */ - int16_t num_Cldfb_instances; + Word16 num_Cldfb_instances; HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[DIRAC_MAX_ANA_CHANS]; /* DirAC parameter estimation */ @@ -2572,11 +2572,11 @@ typedef struct ivas_dirac_ana_data_structure #else Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ #endif - int16_t band_grouping[MASA_FREQUENCY_BANDS + 1]; - int16_t block_grouping[5]; + Word16 band_grouping[MASA_FREQUENCY_BANDS + 1]; + Word16 block_grouping[5]; /* diffuseness */ - int16_t index_buffer_intensity; + Word16 index_buffer_intensity; #ifndef IVAS_FLOAT_FIXED float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; #else @@ -2632,7 +2632,7 @@ typedef struct ivas_dirac_ana_data_structure typedef struct ivas_masa_prerend_data_structure { /* CLDFB analysis */ - int16_t num_Cldfb_instances; + Word16 num_Cldfb_instances; HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MASA_MAX_TRANSPORT_CHANNELS]; MASA_DECODER_EXT_OUT_META_HANDLE hMasaOut; diff --git a/lib_rend/ivas_td_decorr.c b/lib_rend/ivas_td_decorr.c index 1e6632af4a7dd3ff8338024cd0eeed265cf5fc76..ab172f9729371564a81af392c00f3bdeefef3ca7 100644 --- a/lib_rend/ivas_td_decorr.c +++ b/lib_rend/ivas_td_decorr.c @@ -90,30 +90,30 @@ static const float ivas_three_pow_frac[IVAS_MAX_DECORR_APD_SECTIONS] = { }; #else -static const Word16 ivas_hadamard_decorr_APD_coeff[IVAS_APD_16_SECT][IVAS_APD_16_SECT] = { - { 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107 }, - { 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107 }, - { 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107 }, - { 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107 }, - { 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107 }, - { 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107 }, - { 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107 }, - { 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107 }, - { 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107 }, - { 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107 }, - { 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107 }, - { 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107 }, - { 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107 }, - { 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107 }, - { 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107 }, - { 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107 } +static const Word16 ivas_hadamard_decorr_APD_coeff[IVAS_APD_16_SECT][IVAS_APD_16_SECT] = { /* Q15 */ + { 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107 }, + { 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107 }, + { 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107 }, + { 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107 }, + { 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107 }, + { 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107 }, + { 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107 }, + { 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107 }, + { 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107 }, + { 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107 }, + { 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107 }, + { 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107 }, + { 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107 }, + { 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107 }, + { 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107 }, + { 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107 } }; /* For R = 3.^([0:obj.parm_APD_nSections-1]/4); Q22 */ -static const Word32 ivas_three_pow_frac[IVAS_MAX_DECORR_APD_SECTIONS] = { - 4194304, 5520015, 7264748, 9560946, 12582912, 16560043, 21794242, - 28682836, 37748736, 49680132, 65382728, 86048512, 113246208, - 149040384, 196148192, 258145536 +static const Word32 ivas_three_pow_frac[IVAS_MAX_DECORR_APD_SECTIONS] = { /* Q22 */ + 4194304, 5520015, 7264748, 9560946, 12582912, 16560043, 21794242, + 28682836, 37748736, 49680132, 65382728, 86048512, 113246208, + 149040384, 196148192, 258145536 }; #endif @@ -212,12 +212,12 @@ ivas_error ivas_td_decorr_reconfig_dec( IF( LT_32( ivas_total_brate, IVAS_24k4 ) ) { - ( *hTdDecorr )->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR; + ( *hTdDecorr )->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR; // Q29 move32(); } ELSE { - ( *hTdDecorr )->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN; + ( *hTdDecorr )->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN; // Q29 move32(); } } @@ -349,8 +349,7 @@ ivas_error ivas_td_decorr_dec_open_fx( ivas_td_decorr_state_t *hTdDecorr_loc; ivas_error error; - buf_len = extract_l( Mpy_32_32( output_Fs, 4294968 ) ); - // IVAS_DECORR_PARM_LOOKAHEAD_TAU * 2 ^ 31 -> 4294968 + buf_len = extract_l( Mpy_32_32( output_Fs, 4294968 ) ); // IVAS_DECORR_PARM_LOOKAHEAD_TAU * 2 ^ 31 -> 4294968 num_out_chans = sub( nchan_internal, 1 ); @@ -678,7 +677,7 @@ static void ivas_td_decorr_init( FOR( j = 0; j < hTdDecorr->num_apd_sections; j++ ) { hTdDecorr->APD_filt_state[i].order[j] = hTdDecorr->APD_filt_state[0].order[j]; - hTdDecorr->APD_filt_state[i].coeffs[j] = ivas_hadamard_decorr_APD_coeff[i][j]; + hTdDecorr->APD_filt_state[i].coeffs[j] = ivas_hadamard_decorr_APD_coeff[i][j]; // Q15 hTdDecorr->APD_filt_state[i].idx[j] = 0; move16(); @@ -825,7 +824,7 @@ void ivas_td_decorr_process( void ivas_td_decorr_APD_iir_filter_fx( ivas_td_decorr_APD_filt_state_t *filter_state, - Word32 *pIn_out, + Word32 *pIn_out, // Q11 const Word16 num_APD_sections, const Word16 length ) { @@ -838,7 +837,7 @@ void ivas_td_decorr_APD_iir_filter_fx( FOR( k = 0; k < num_APD_sections; k++ ) { Word32 *pFilt_state = filter_state->state[k]; - Word16 filt_coeff = filter_state->coeffs[k]; + Word16 filt_coeff = filter_state->coeffs[k]; // Q15 Word16 order = filter_state->order[k]; move16(); move16(); @@ -851,10 +850,10 @@ void ivas_td_decorr_APD_iir_filter_fx( tmp_pIn_buf_i = pIn[i]; move32(); - pOut[i] = Madd_32_16( pFilt_state[idx], pIn[i], filt_coeff ); + pOut[i] = Madd_32_16( pFilt_state[idx], pIn[i], filt_coeff ); // Q11 move32(); - pFilt_state[idx++] = Msub_32_16( tmp_pIn_buf_i, pOut[i], filt_coeff ); + pFilt_state[idx++] = Msub_32_16( tmp_pIn_buf_i, pOut[i], filt_coeff ); // Q11 move32(); if ( EQ_16( order, idx ) ) @@ -898,8 +897,8 @@ static void ivas_td_decorr_APD_sections_fx( void ivas_td_decorr_process_fx( ivas_td_decorr_state_t *hTdDecorr, /* i/o: SPAR Covar. decoder handle */ - Word32 *pcm_in[], /* i : input audio channels */ - Word32 **ppOut_pcm, /* o : output audio channels */ + Word32 *pcm_in[], /* i : input audio channels Q11 */ + Word32 **ppOut_pcm, /* o : output audio channels Q11 */ const Word16 output_frame /* i : output frame length */ ) { @@ -917,7 +916,7 @@ void ivas_td_decorr_process_fx( FOR( j = 0; j < output_frame; j++ ) { - ppOut_pcm[0][j] = L_shl( Mpy_32_32( ppOut_pcm[0][j], in_duck_gain[j] ), 1 ); + ppOut_pcm[0][j] = L_shl( Mpy_32_32( ppOut_pcm[0][j], in_duck_gain[j] ), 1 ); // Q11 move32(); } } @@ -937,7 +936,7 @@ void ivas_td_decorr_process_fx( { FOR( j = 0; j < output_frame; j++ ) { - ppOut_pcm[i][j] = L_shl( Mpy_32_32( ppOut_pcm[i][j], out_duck_gain[j] ), 1 ); + ppOut_pcm[i][j] = L_shl( Mpy_32_32( ppOut_pcm[i][j], out_duck_gain[j] ), 1 ); // Q11 move32(); } } diff --git a/lib_rend/ivas_vbap.c b/lib_rend/ivas_vbap.c index 3d62f595289f68e961bdd8c9636b893193245e46..4c14067ec4d9ceb1a913448c9dc3a1a0e034baa0 100644 --- a/lib_rend/ivas_vbap.c +++ b/lib_rend/ivas_vbap.c @@ -94,8 +94,8 @@ typedef struct connection_option Word16 chA; Word16 chB; #ifdef IVAS_FLOAT_FIXED - Word32 arc_weighted_fx; - Word32 arc_fx; + Word32 arc_weighted_fx; /* Q29 */ + Word32 arc_fx; /* Q29 */ #else float arc; float arc_weighted; @@ -115,9 +115,9 @@ enum SpeakerNodeGroup typedef struct vbap_speaker_node_structure { #ifdef IVAS_FLOAT_FIXED - Word32 azi_deg_fx; - Word32 ele_deg_fx; - Word32 unit_vec_fx[3]; + Word32 azi_deg_fx; /* Q22 */ + Word32 ele_deg_fx; /* Q22 */ + Word32 unit_vec_fx[3]; /* Q30 */ #else float azi_deg; float ele_deg; @@ -137,13 +137,13 @@ static UWord8 vector_matrix_multiply_3x3_fx( const Word16 *src_vector, Word32 ma static UWord8 vector_matrix_multiply_3x3_32_fx( const Word32 *src_vector, Word32 matrix[3][3], Word32 *result, Word16 q_matrix ); -static void init_speaker_node_direction_data_fx( VBAP_SPEAKER_NODE *speaker_node_data, const Word32 *speaker_node_azi_deg_fx, const Word32 *speaker_node_ele_deg_fx, const int16_t num_speaker_nodes ); +static void init_speaker_node_direction_data_fx( VBAP_SPEAKER_NODE *speaker_node_data, const Word32 *speaker_node_azi_deg_fx, const Word32 *speaker_node_ele_deg_fx, const Word16 num_speaker_nodes ); static Word16 determine_virtual_surface_triplets_fx( const Word16 num_speaker_nodes, const VBAP_SPEAKER_NODE *speaker_node_data, Word16 connections[][2], const Word16 max_num_connections, VBAP_VS_TRIPLET *triplets, Word16 initial_search_indices[VBAP_NUM_SEARCH_SECTORS], enum SpeakerNodeGroup allowed_group ); -static void determine_initial_search_indices_fx( const int16_t num_triplets, const Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS], int16_t initial_search_indices[VBAP_NUM_SEARCH_SECTORS] ); +static void determine_initial_search_indices_fx( const Word16 num_triplets, const Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS], Word16 initial_search_indices[VBAP_NUM_SEARCH_SECTORS] ); -static ivas_error determine_connections_fx( const Word16 num_speaker_nodes, const VBAP_SPEAKER_NODE *speaker_node_data, Word16 connections[][2], const Word16 max_num_connections, Word16 *group1_count, Word16 *group2_start, int16_t *group2_count ); +static ivas_error determine_connections_fx( const Word16 num_speaker_nodes, const VBAP_SPEAKER_NODE *speaker_node_data, Word16 connections[][2], const Word16 max_num_connections, Word16 *group1_count, Word16 *group2_start, Word16 *group2_count ); static void formulate_horizontal_connections_fx( const VBAP_SPEAKER_NODE *speaker_node_data, const Word16 num_speaker_nodes, Word16 connections[][2], Word16 *connection_write_index ); @@ -157,7 +157,7 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node_fx( VBAP_H static Word16 determine_best_triplet_and_gains_fx( VBAP_SEARCH_STRUCT *search_struct, const Word16 panning_unit_vec_fx[3], const Word16 azi_deg, Word32 gains_fx[3] ); -static void determine_virtual_speaker_node_division_gains_fx( const Word16 virtual_speaker_node_index, Word16 *virtual_node_division_gains_fx, Word16 *max_exp, int16_t connections[][2], const enum VirtualSpeakerNodeType type, const Word16 max_num_connections, const Word16 num_speaker_nodes, const Word16 use_object_mode ); +static void determine_virtual_speaker_node_division_gains_fx( const Word16 virtual_speaker_node_index, Word16 *virtual_node_division_gains_fx, Word16 connections[][2], const enum VirtualSpeakerNodeType type, const Word16 max_num_connections, const Word16 num_speaker_nodes, const Word16 use_object_mode ); static void reorder_triplets_fx( VBAP_VS_TRIPLET *triplets, const Word16 *target_order, const Word16 num_triplets ); #else @@ -193,13 +193,14 @@ static void reorder_triplets( VBAP_VS_TRIPLET *triplets, const int16_t *target_o * * Initialize VBAP data structure for the speaker node set *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED ivas_error vbap_init_data_fx( - VBAP_HANDLE *hVBAPdata, /* i/o: handle for VBAP data structure that will be initialized */ - const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths (positive left) */ - const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations (positive up) */ - const Word16 num_speaker_nodes, /* i : number of speaker nodes in the set */ - const IVAS_FORMAT ivas_format /* i : IVAS format */ + VBAP_HANDLE *hVBAPdata, /* i/o: handle for VBAP data structure that will be initialized */ + const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths (positive left) Q22 */ + const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations (positive up) Q22 */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes in the set */ + const IVAS_FORMAT ivas_format /* i : IVAS format */ ) { /* Variables */ @@ -213,8 +214,8 @@ ivas_error vbap_init_data_fx( enum VirtualSpeakerNodeType virtual_bottom_type; enum VirtualSpeakerNodeType virtual_back_type; - Word32 speaker_node_azi_deg_internal_fx[VBAP_MAX_NUM_SPEAKER_NODES]; - Word32 speaker_node_ele_deg_internal_fx[VBAP_MAX_NUM_SPEAKER_NODES]; + Word32 speaker_node_azi_deg_internal_fx[VBAP_MAX_NUM_SPEAKER_NODES]; /* Q22 */ + Word32 speaker_node_ele_deg_internal_fx[VBAP_MAX_NUM_SPEAKER_NODES]; /* Q22 */ VBAP_SPEAKER_NODE speaker_node_data[VBAP_MAX_NUM_SPEAKER_NODES]; VBAP_DATA *vbap; @@ -299,7 +300,7 @@ ivas_error vbap_init_data_fx( is_success &= vbap->object_mode_bottom_virtual_speaker_node_division_gains_fx != NULL; } speaker_node_azi_deg_internal_fx[vbap->bottom_virtual_speaker_node_index] = 0; - speaker_node_ele_deg_internal_fx[vbap->bottom_virtual_speaker_node_index] = -377487360; /*-90.0f in Q22*/ + speaker_node_ele_deg_internal_fx[vbap->bottom_virtual_speaker_node_index] = -377487360; /* -90.0f in Q22 */ move32(); move32(); } @@ -323,7 +324,7 @@ ivas_error vbap_init_data_fx( is_success &= vbap->object_mode_top_virtual_speaker_node_division_gains_fx != NULL; } speaker_node_azi_deg_internal_fx[vbap->top_virtual_speaker_node_index] = 0; - speaker_node_ele_deg_internal_fx[vbap->top_virtual_speaker_node_index] = 377487360; /*90.0f in Q22*/ + speaker_node_ele_deg_internal_fx[vbap->top_virtual_speaker_node_index] = 377487360; /* 90.0f in Q22 */ move32(); move16(); } @@ -346,24 +347,14 @@ ivas_error vbap_init_data_fx( set16_fx( vbap->object_mode_back_virtual_speaker_node_division_gains_fx, 0, num_speaker_nodes ); is_success &= vbap->object_mode_back_virtual_speaker_node_division_gains_fx != NULL; } - speaker_node_azi_deg_internal_fx[vbap->back_virtual_speaker_node_index] = 754974720; + speaker_node_azi_deg_internal_fx[vbap->back_virtual_speaker_node_index] = 754974720; /* 180.0f in Q22 */ speaker_node_ele_deg_internal_fx[vbap->back_virtual_speaker_node_index] = 0; move32(); move16(); } + init_speaker_node_direction_data_fx( speaker_node_data, speaker_node_azi_deg_internal_fx, speaker_node_ele_deg_internal_fx, vbap->num_speaker_nodes_internal ); -#ifdef TRUE0 - /*TODO: Clean up of update float buffers*/ - for ( int ch = 0; ch < vbap->num_speaker_nodes_internal; ch++ ) - { - speaker_node_data[ch].unit_vec[0] = fix_to_float( speaker_node_data[ch].unit_vec_fx[0], Q30 ); - speaker_node_data[ch].unit_vec[1] = fix_to_float( speaker_node_data[ch].unit_vec_fx[1], Q30 ); - speaker_node_data[ch].unit_vec[2] = fix_to_float( speaker_node_data[ch].unit_vec_fx[2], Q30 ); - speaker_node_data[ch].ele_deg = fix_to_float( speaker_node_data[ch].ele_deg_fx, Q22 ); - speaker_node_data[ch].azi_deg = fix_to_float( speaker_node_data[ch].azi_deg_fx, Q22 ); - } -#endif /* Allocate and determine node-node connections */ max_num_connections = mult0( ( sub( vbap->num_speaker_nodes_internal, 2 ) ), 3 ); /* Theoretical maximum */ @@ -382,10 +373,12 @@ ivas_error vbap_init_data_fx( Word16 speaker_nodes_horiz_internal = 0; move16(); UWord8 loop_done = 0; + move16(); /* Count nodes in different groups to reserve correct memory */ FOR( ch = 0; ch < vbap->num_speaker_nodes_internal && !loop_done; ch++ ) { + test(); SWITCH( speaker_node_data[ch].group ) { case SPEAKER_NODE_ALL: @@ -411,21 +404,21 @@ ivas_error vbap_init_data_fx( } } - IF( ( vbap->search_struct[0].triplets = (VBAP_VS_TRIPLET *) malloc( ( ( speaker_nodes_group1_internal - 2 ) * 2 - ( max( 0, ( speaker_nodes_horiz_internal - 2 ) ) ) ) * sizeof( VBAP_VS_TRIPLET ) ) ) == NULL ) + IF( ( vbap->search_struct[0].triplets = (VBAP_VS_TRIPLET *) malloc( ( ( speaker_nodes_group1_internal - 2 ) * 2 - ( s_max( 0, ( speaker_nodes_horiz_internal - 2 ) ) ) ) * sizeof( VBAP_VS_TRIPLET ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); } - is_success &= vbap->search_struct[0].triplets != NULL; + is_success = s_and( is_success, vbap->search_struct[0].triplets != NULL ); IF( speaker_nodes_group2_internal > 0 ) { vbap->num_search_structs = 2; move16(); - IF( ( vbap->search_struct[1].triplets = (VBAP_VS_TRIPLET *) malloc( ( ( speaker_nodes_group2_internal - 2 ) * 2 - ( max( 0, ( speaker_nodes_horiz_internal - 2 ) ) ) ) * sizeof( VBAP_VS_TRIPLET ) ) ) == NULL ) + IF( ( vbap->search_struct[1].triplets = (VBAP_VS_TRIPLET *) malloc( ( ( speaker_nodes_group2_internal - 2 ) * 2 - ( s_max( 0, ( speaker_nodes_horiz_internal - 2 ) ) ) ) * sizeof( VBAP_VS_TRIPLET ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); } - is_success &= vbap->search_struct[1].triplets != NULL; + is_success = s_and( is_success, vbap->search_struct[1].triplets != NULL ); } ELSE { @@ -441,32 +434,34 @@ ivas_error vbap_init_data_fx( { /* If all speaker nodes belong to ALL set, then we only create one triplet set and search structure */ vbap->search_struct[0].num_triplets = determine_virtual_surface_triplets_fx( vbap->num_speaker_nodes_internal, speaker_node_data, connections, max_num_connections, vbap->search_struct[0].triplets, vbap->search_struct[0].initial_search_indices, SPEAKER_NODE_ALL ); + move16(); } ELSE { /* Otherwise, we have two sets and can handle them separately for more opmitized processing. */ vbap->search_struct[0].num_triplets = determine_virtual_surface_triplets_fx( vbap->num_speaker_nodes_internal, speaker_node_data, connections, connection_group1_count, vbap->search_struct[0].triplets, vbap->search_struct[0].initial_search_indices, SPEAKER_NODE_BOTTOM_HALF ); + move16(); vbap->search_struct[1].num_triplets = determine_virtual_surface_triplets_fx( vbap->num_speaker_nodes_internal, speaker_node_data, connections + connection_group2_start, connection_group2_count, vbap->search_struct[1].triplets, vbap->search_struct[1].initial_search_indices, SPEAKER_NODE_TOP_HALF ); + move16(); } } /* Determine how the virtual node gains should be distributed to real nodes, if necessary (checked within function). */ IF( is_success ) { - Word16 max_exp = 31; - move16(); - - determine_virtual_speaker_node_division_gains_fx( vbap->top_virtual_speaker_node_index, vbap->top_virtual_speaker_node_division_gains_fx, &max_exp, connections, virtual_top_type, max_num_connections, num_speaker_nodes, 0 ); - determine_virtual_speaker_node_division_gains_fx( vbap->bottom_virtual_speaker_node_index, vbap->bottom_virtual_speaker_node_division_gains_fx, &max_exp, connections, virtual_bottom_type, max_num_connections, num_speaker_nodes, 0 ); - determine_virtual_speaker_node_division_gains_fx( vbap->back_virtual_speaker_node_index, vbap->back_virtual_speaker_node_division_gains_fx, &max_exp, connections, virtual_back_type, max_num_connections, num_speaker_nodes, 0 ); + determine_virtual_speaker_node_division_gains_fx( vbap->top_virtual_speaker_node_index, vbap->top_virtual_speaker_node_division_gains_fx, connections, virtual_top_type, max_num_connections, num_speaker_nodes, 0 ); + determine_virtual_speaker_node_division_gains_fx( vbap->bottom_virtual_speaker_node_index, vbap->bottom_virtual_speaker_node_division_gains_fx, connections, virtual_bottom_type, max_num_connections, num_speaker_nodes, 0 ); + determine_virtual_speaker_node_division_gains_fx( vbap->back_virtual_speaker_node_index, vbap->back_virtual_speaker_node_division_gains_fx, connections, virtual_back_type, max_num_connections, num_speaker_nodes, 0 ); IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { - determine_virtual_speaker_node_division_gains_fx( vbap->top_virtual_speaker_node_index, vbap->object_mode_top_virtual_speaker_node_division_gains_fx, &max_exp, connections, virtual_top_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); - determine_virtual_speaker_node_division_gains_fx( vbap->bottom_virtual_speaker_node_index, vbap->object_mode_bottom_virtual_speaker_node_division_gains_fx, &max_exp, connections, virtual_bottom_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); - determine_virtual_speaker_node_division_gains_fx( vbap->back_virtual_speaker_node_index, vbap->object_mode_back_virtual_speaker_node_division_gains_fx, &max_exp, connections, virtual_back_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); + determine_virtual_speaker_node_division_gains_fx( vbap->top_virtual_speaker_node_index, vbap->object_mode_top_virtual_speaker_node_division_gains_fx, connections, virtual_top_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); + determine_virtual_speaker_node_division_gains_fx( vbap->bottom_virtual_speaker_node_index, vbap->object_mode_bottom_virtual_speaker_node_division_gains_fx, connections, virtual_bottom_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); + determine_virtual_speaker_node_division_gains_fx( vbap->back_virtual_speaker_node_index, vbap->object_mode_back_virtual_speaker_node_division_gains_fx, connections, virtual_back_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); } } + pop_wmops(); + IF( is_success ) { *hVBAPdata = vbap; @@ -730,6 +725,8 @@ ivas_error vbap_init_data( return IVAS_ERR_OK; } #endif + + /*-------------------------------------------------------------------------* * vbap_free_data() * @@ -843,33 +840,33 @@ void vbap_free_data( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void vbap_determine_gains_fx( - const VBAP_HANDLE hVBAPdata, /* i : prepared VBAP structure */ - Word32 *gains_fx, /* o : gain vector for loudspeakers for given direction */ - const Word16 azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ - const Word16 ele_deg, /* i : elevation in degrees for panning direction (positive up) */ - const Word16 use_object_mode /* i : select between object mode panning and spatial mode panning */ + const VBAP_HANDLE hVBAPdata, /* i : prepared VBAP structure */ + Word32 *gains_fx, /* o : gain vector for loudspeakers for given direction Q29 */ + const Word16 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q0 */ + const Word16 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q0 */ + const Word16 use_object_mode /* i : select between object mode panning and spatial mode panning */ ) { /* This function formulates gains for the given angle. The triplet-selection has been pre-formulated. */ Word16 ch, ch2; Word16 triplet_ch; Word16 triplet_index; - Word16 panning_unit_vec_fx[3]; - Word32 gain_triplet_fx[3]; + Word16 panning_unit_vec_fx[3]; /* Q15 */ + Word32 gain_triplet_fx[3]; /* Q16 */ Word32 norm_value_fx; Word32 gain_ene_fx; - Word32 azi_norm; - Word32 ele_norm; - Word32 azi_temp_fx; - Word32 ele_temp_fx; + Word16 azi_norm; /* Q15 */ + Word16 ele_norm; /* Q15 */ + Word32 azi_temp_fx; /* Q22 */ + Word32 ele_temp_fx; /* Q22 */ Word16 num_speaker_nodes; Word16 bottom_virtual_speaker_node_index; Word16 top_virtual_speaker_node_index; Word16 back_virtual_speaker_node_index; VBAP_VS_TRIPLET *selected_triplet; - Word16 *bottom_virtual_speaker_node_division_gains_fx; - Word16 *top_virtual_speaker_node_division_gains_fx; - Word16 *back_virtual_speaker_node_division_gains_fx; + Word16 *bottom_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *top_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *back_virtual_speaker_node_division_gains_fx; /* Q16 */ push_wmops( "vbap_gains" ); @@ -895,13 +892,14 @@ void vbap_determine_gains_fx( back_virtual_speaker_node_division_gains_fx = hVBAPdata->back_virtual_speaker_node_division_gains_fx; } - panning_wrap_angles_fixed( L_shl( azi_deg, 22 ), L_shl( ele_deg, 22 ), &azi_temp_fx, &ele_temp_fx ); - azi_norm = L_shr( Mpy_32_32( azi_temp_fx, 5965232 ), 7 ); - ele_norm = L_shr( Mpy_32_32( ele_temp_fx, 5965232 ), 7 ); + panning_wrap_angles_fx( L_shl( azi_deg, Q22 ), L_shl( ele_deg, Q22 ), &azi_temp_fx, &ele_temp_fx ); + azi_norm = extract_l( L_shr( Mpy_32_32( azi_temp_fx, ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ + ele_norm = extract_l( L_shr( Mpy_32_32( ele_temp_fx, ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ - panning_unit_vec_fx[0] = mult( getCosWord16R2( (Word16) azi_norm ), getCosWord16R2( (Word16) ele_norm ) ); - panning_unit_vec_fx[1] = mult( getSineWord16R2( (Word16) azi_norm ), getCosWord16R2( (Word16) ele_norm ) ); - panning_unit_vec_fx[2] = getSineWord16R2( (Word16) ele_norm ); + panning_unit_vec_fx[0] = mult( getCosWord16R2( azi_norm ), getCosWord16R2( ele_norm ) ); /* Q15 */ + panning_unit_vec_fx[1] = mult( getSineWord16R2( azi_norm ), getCosWord16R2( ele_norm ) ); /* Q15 */ + panning_unit_vec_fx[2] = getSineWord16R2( ele_norm ); /* Q15 */ + move16(); move16(); move16(); @@ -911,13 +909,11 @@ void vbap_determine_gains_fx( IF( EQ_16( hVBAPdata->num_search_structs, 2 ) && ele_deg > 0 ) { triplet_index = determine_best_triplet_and_gains_fx( &( hVBAPdata->search_struct[1] ), panning_unit_vec_fx, azi_deg, gain_triplet_fx ); - move16(); selected_triplet = &hVBAPdata->search_struct[1].triplets[triplet_index]; } ELSE { triplet_index = determine_best_triplet_and_gains_fx( &( hVBAPdata->search_struct[0] ), panning_unit_vec_fx, azi_deg, gain_triplet_fx ); - move16(); selected_triplet = &hVBAPdata->search_struct[0].triplets[triplet_index]; } @@ -926,14 +922,14 @@ void vbap_determine_gains_fx( move32(); FOR( ch = 0; ch < 3; ch++ ) { - gain_ene_fx = L_add( gain_ene_fx, Mpy_32_32( gain_triplet_fx[ch], gain_triplet_fx[ch] ) ); // 2q -31 = 27 + gain_ene_fx = L_add( gain_ene_fx, Mpy_32_32( gain_triplet_fx[ch], gain_triplet_fx[ch] ) ); /* Q(2 * VBAP_VS_TRIPLET.q_inverse_matrix - 31) */ } - norm_value_fx = Isqrt( L_shr( gain_ene_fx, 1 ) ); // q = 47 - hVBAPdata->search_struct[0].triplets->q_inverse_matrix = 18 + norm_value_fx = Isqrt( L_shr( gain_ene_fx, 1 ) ); /* Q(31 - (2 * VBAP_VS_TRIPLET.q_inverse_matrix - 31 - 1) / 2 ) = Q(47 - VBAP_VS_TRIPLET.q_inverse_matrix) */ FOR( ch = 0; ch < 3; ch++ ) { - gain_triplet_fx[ch] = Mpy_32_32( gain_triplet_fx[ch], norm_value_fx ); // Q16 + gain_triplet_fx[ch] = Mpy_32_32( gain_triplet_fx[ch], norm_value_fx ); /* 47 - VBAP_VS_TRIPLET.q_inverse_matrix + VBAP_VS_TRIPLET.q_inverse_matrix - 31 = Q16 */ move32(); /* Sanity check for rounding issues */ @@ -956,7 +952,7 @@ void vbap_determine_gains_fx( { FOR( ch2 = 0; ch2 < num_speaker_nodes; ch2++ ) { - gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], bottom_virtual_speaker_node_division_gains_fx[ch2] ), 12 ) ); // Q29 + gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], bottom_virtual_speaker_node_division_gains_fx[ch2] ), Q12 ) ); /* Q16 + Q16 - Q15 + Q12 = Q29 */ move32(); } } @@ -964,7 +960,7 @@ void vbap_determine_gains_fx( { FOR( ch2 = 0; ch2 < num_speaker_nodes; ch2++ ) { - gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], top_virtual_speaker_node_division_gains_fx[ch2] ), 12 ) ); // Q29 + gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], top_virtual_speaker_node_division_gains_fx[ch2] ), Q12 ) ); /* Q16 + Q16 - Q15 + Q12 = Q29 */ move32(); } } @@ -972,13 +968,13 @@ void vbap_determine_gains_fx( { FOR( ch2 = 0; ch2 < num_speaker_nodes; ch2++ ) { - gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], back_virtual_speaker_node_division_gains_fx[ch2] ), 12 ) ); // Q29 + gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], back_virtual_speaker_node_division_gains_fx[ch2] ), Q12 ) ); /* Q16 + Q16 - Q15 + Q12 = Q29 */ move32(); } } ELSE { - gains_fx[triplet_ch] = L_add( gains_fx[triplet_ch], L_shl( gain_triplet_fx[ch], 13 ) ); // Q29 + gains_fx[triplet_ch] = L_add( gains_fx[triplet_ch], L_shl( gain_triplet_fx[ch], Q13 ) ); /* Q16 + Q13 = Q29 */ move32(); } } @@ -1126,11 +1122,12 @@ void vbap_determine_gains( * * 3-by-3 vector cross product *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static void vbap_crossp_fx( - const Word32 *vec1_fx, /* i : input vector 1 */ - const Word32 *vec2_fx, /* i : input vector 2 */ - Word32 *crossProduct_fx /* o : cross product output */ + const Word32 *vec1_fx, /* i : input vector 1 Qx */ + const Word32 *vec2_fx, /* i : input vector 2 Qy */ + Word32 *crossProduct_fx /* o : cross product output Qx + Qy - 31 */ ) { @@ -1168,43 +1165,43 @@ static void vbap_crossp( #ifdef IVAS_FLOAT_FIXED /*! r: Status result if triplet is usable for panning. Allows early exit. */ static UWord8 vector_matrix_multiply_3x3_fx( - const Word16 *src_vector, /* i : input vector */ - Word32 matrix[3][3], /* i : input matrix */ - Word32 *result, /* o : output vector */ + const Word16 *src_vector, /* i : input vector Q15 */ + Word32 matrix[3][3], /* i : input matrix Q(q_matrix) */ + Word32 *result, /* o : output vector Q(q_matrix) */ Word16 q_matrix ) { - result[0] = Mpy_32_16_1( matrix[0][0], src_vector[0] ); // q = q_matrix - result[0] = L_add( result[0], Mpy_32_16_1( matrix[1][0], src_vector[1] ) ); - result[0] = L_add( result[0], Mpy_32_16_1( matrix[2][0], src_vector[2] ) ); + result[0] = Mpy_32_16_1( matrix[0][0], src_vector[0] ); /* Q(q_matrix) */ + result[0] = L_add( result[0], Mpy_32_16_1( matrix[1][0], src_vector[1] ) ); /* Q(q_matrix) */ + result[0] = L_add( result[0], Mpy_32_16_1( matrix[2][0], src_vector[2] ) ); /* Q(q_matrix) */ move32(); move32(); move32(); - IF( LT_32( result[0], Mpy_32_16_1( L_lshl( 1, q_matrix ), -327 ) ) ) // 327 = 0.01 in Q = 15 + IF( LT_32( result[0], Mpy_32_16_1( L_lshl( 1, q_matrix ), -327 /* -0.01 in Q15 */ ) ) ) { return 0; } - result[1] = Mpy_32_16_1( matrix[0][1], src_vector[0] ); - result[1] = L_add( result[1], Mpy_32_16_1( matrix[1][1], src_vector[1] ) ); - result[1] = L_add( result[1], Mpy_32_16_1( matrix[2][1], src_vector[2] ) ); + result[1] = Mpy_32_16_1( matrix[0][1], src_vector[0] ); /* Q(q_matrix) */ + result[1] = L_add( result[1], Mpy_32_16_1( matrix[1][1], src_vector[1] ) ); /* Q(q_matrix) */ + result[1] = L_add( result[1], Mpy_32_16_1( matrix[2][1], src_vector[2] ) ); /* Q(q_matrix) */ move32(); move32(); move32(); - IF( LT_32( result[1], Mpy_32_16_1( L_shl( 1, q_matrix ), -327 ) ) ) + IF( LT_32( result[1], Mpy_32_16_1( L_shl( 1, q_matrix ), -327 /* -0.01 in Q15 */ ) ) ) { return 0; } - result[2] = Mpy_32_16_1( matrix[0][2], src_vector[0] ); - result[2] = L_add( result[2], Mpy_32_16_1( matrix[1][2], src_vector[1] ) ); - result[2] = L_add( result[2], Mpy_32_16_1( matrix[2][2], src_vector[2] ) ); + result[2] = Mpy_32_16_1( matrix[0][2], src_vector[0] ); /* Q(q_matrix) */ + result[2] = L_add( result[2], Mpy_32_16_1( matrix[1][2], src_vector[1] ) ); /* Q(q_matrix) */ + result[2] = L_add( result[2], Mpy_32_16_1( matrix[2][2], src_vector[2] ) ); /* Q(q_matrix) */ move32(); move32(); move32(); - IF( LT_32( result[2], Mpy_32_16_1( L_shl( 1, q_matrix ), -327 ) ) ) + IF( LT_32( result[2], Mpy_32_16_1( L_shl( 1, q_matrix ), -327 /* -0.01 in Q15 */ ) ) ) { return 0; } @@ -1213,42 +1210,42 @@ static UWord8 vector_matrix_multiply_3x3_fx( } static UWord8 vector_matrix_multiply_3x3_32_fx( - const Word32 *src_vector, /* i : input vector */ - Word32 matrix[3][3], /* i : input matrix */ - Word32 *result, /* o : output vector */ + const Word32 *src_vector, /* i : input vector Q30 */ + Word32 matrix[3][3], /* i : input matrix Q(q_matrix) */ + Word32 *result, /* o : output vector Q(q_matrix - 1) */ Word16 q_matrix ) { - result[0] = Mpy_32_32( matrix[0][0], src_vector[0] ); // q = ( q_matrix + 30 ) - 31 - result[0] = L_add( result[0], Mpy_32_32( matrix[1][0], src_vector[1] ) ); - result[0] = L_add( result[0], Mpy_32_32( matrix[2][0], src_vector[2] ) ); + result[0] = Mpy_32_32( matrix[0][0], src_vector[0] ); /* Q(q_matrix - 1) */ + result[0] = L_add( result[0], Mpy_32_32( matrix[1][0], src_vector[1] ) ); /* Q(q_matrix - 1) */ + result[0] = L_add( result[0], Mpy_32_32( matrix[2][0], src_vector[2] ) ); /* Q(q_matrix - 1) */ move32(); move32(); move32(); - IF( LT_32( result[0], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 ) ) ) // 21474836 = 0.01 in Q = 31 + IF( LT_32( result[0], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 /* -0.01 in Q31 */ ) ) ) { return 0; } - result[1] = Mpy_32_32( matrix[0][1], src_vector[0] ); - result[1] = L_add( result[1], Mpy_32_32( matrix[1][1], src_vector[1] ) ); - result[1] = L_add( result[1], Mpy_32_32( matrix[2][1], src_vector[2] ) ); + result[1] = Mpy_32_32( matrix[0][1], src_vector[0] ); /* Q(q_matrix - 1) */ + result[1] = L_add( result[1], Mpy_32_32( matrix[1][1], src_vector[1] ) ); /* Q(q_matrix - 1) */ + result[1] = L_add( result[1], Mpy_32_32( matrix[2][1], src_vector[2] ) ); /* Q(q_matrix - 1) */ move32(); move32(); move32(); - IF( LT_32( result[1], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 ) ) ) // 21474836 = 0.01 in Q = 31 + IF( LT_32( result[1], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 /* -0.01 in Q31 */ ) ) ) { return 0; } - result[2] = Mpy_32_32( matrix[0][2], src_vector[0] ); - result[2] = L_add( result[2], Mpy_32_32( matrix[1][2], src_vector[1] ) ); - result[2] = L_add( result[2], Mpy_32_32( matrix[2][2], src_vector[2] ) ); + result[2] = Mpy_32_32( matrix[0][2], src_vector[0] ); /* Q(q_matrix - 1) */ + result[2] = L_add( result[2], Mpy_32_32( matrix[1][2], src_vector[1] ) ); /* Q(q_matrix - 1) */ + result[2] = L_add( result[2], Mpy_32_32( matrix[2][2], src_vector[2] ) ); /* Q(q_matrix - 1) */ move32(); move32(); move32(); - IF( LT_32( result[2], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 ) ) ) // 21474836 = 0.01 in Q = 31 + IF( LT_32( result[2], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 /* -0.01 in Q31 */ ) ) ) { return 0; } @@ -1292,8 +1289,8 @@ static uint8_t vector_matrix_multiply_3x3( return 1; } - #endif + /*----------------------------------------------------------------------------------------------* * determine_best_triplet_and_gains() * @@ -1301,14 +1298,12 @@ static uint8_t vector_matrix_multiply_3x3( *----------------------------------------------------------------------------------------------*/ /*! r: triplet id */ - - #ifdef IVAS_FLOAT_FIXED static Word16 determine_best_triplet_and_gains_fx( - VBAP_SEARCH_STRUCT *search_struct, /* i : VBAP search struct */ - const Word16 panning_unit_vec_fx[3], /* i : panning unit vector */ - const Word16 azi_deg, /* i : panning azimuth */ - Word32 gains_fx[3] /* o : panning gains */ + VBAP_SEARCH_STRUCT *search_struct, /* i : VBAP search struct */ + const Word16 panning_unit_vec_fx[3], /* i : panning unit vector Q15 */ + const Word16 azi_deg, /* i : panning azimuth */ + Word32 gains_fx[3] /* o : panning gains Q(VBAP_VS_TRIPLET.q_inverse_matrix) */ ) { Word16 i, tr, k; @@ -1334,13 +1329,23 @@ static Word16 determine_best_triplet_and_gains_fx( * the chosen four sectors. */ IF( GT_16( abs_s( azi_deg ), 90 ) ) { - sector = azi_deg < 0 ? 2 : 1; + sector = 1; move16(); + if ( azi_deg < 0 ) + { + sector = 2; + move16(); + } } ELSE { - sector = azi_deg < 0 ? 3 : 0; + sector = 0; move16(); + if ( azi_deg < 0 ) + { + sector = 3; + move16(); + } } first_triplet = search_struct->initial_search_indices[sector]; move16(); @@ -1355,7 +1360,6 @@ static Word16 determine_best_triplet_and_gains_fx( IF( triplet_ok ) { min_gain_this_fx = L_min( ( L_min( unnormalized_gains_fx[0], unnormalized_gains_fx[1] ) ), unnormalized_gains_fx[2] ); - move32(); IF( GT_32( min_gain_this_fx, best_min_gain_fx ) ) { @@ -1365,7 +1369,7 @@ static Word16 determine_best_triplet_and_gains_fx( move16(); FOR( k = 0; k < 3; k++ ) { - gains_fx[k] = unnormalized_gains_fx[k]; + gains_fx[k] = unnormalized_gains_fx[k]; /* Q(VBAP_VS_TRIPLET.q_inverse_matrix) */ move32(); } IF( best_min_gain_fx >= 0 ) @@ -1472,21 +1476,22 @@ static int16_t determine_best_triplet_and_gains( return best_triplet; } #endif + /*-------------------------------------------------------------------------* * determine_virtual_speaker_node_division_gains() * * Determines how the virtual node gains are distributed to real nodes *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static void determine_virtual_speaker_node_division_gains_fx( - const Word16 virtual_speaker_node_index, /* i : virtual speaker node index */ - Word16 *virtual_node_division_gains_fx, - Word16 *max_exp, - Word16 connections[][2], /* i : vector of all connections */ - const enum VirtualSpeakerNodeType type, /* i : virtual speaker node typel */ - const Word16 max_num_connections, /* i : max number of connections */ - const Word16 num_speaker_nodes, /* i : max number of speaker nodes */ - const Word16 use_object_mode /* i : use VBAP in object panning mode vs. spatial panning mode */ + const Word16 virtual_speaker_node_index, /* i : virtual speaker node index */ + Word16 *virtual_node_division_gains_fx, /* o : virtual speaker node division gains Q16 */ + Word16 connections[][2], /* i : vector of all connections */ + const enum VirtualSpeakerNodeType type, /* i : virtual speaker node typel */ + const Word16 max_num_connections, /* i : max number of connections */ + const Word16 num_speaker_nodes, /* i : max number of speaker nodes */ + const Word16 use_object_mode /* i : use VBAP in object panning mode vs. spatial panning mode */ ) { /* When node type is VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, the gains of the virtual node @@ -1536,7 +1541,7 @@ static void determine_virtual_speaker_node_division_gains_fx( Word16 guard_bits = find_guarded_bits_fx( num_speaker_nodes ); FOR( ch = 0; ch < num_speaker_nodes; ch++ ) { - sum_val_fx = add( sum_val_fx, shr( virtual_node_division_gains_fx[ch], guard_bits ) ); // Q10 + sum_val_fx = add( sum_val_fx, shr( virtual_node_division_gains_fx[ch], guard_bits ) ); } Word16 final_exp = 0, res_exp; Word32 tmp_1, tmp_2, tmp_3; @@ -1545,7 +1550,7 @@ static void determine_virtual_speaker_node_division_gains_fx( { IF( virtual_node_division_gains_fx[ch] != 0 ) { - BASOP_Util_Divide_MantExp( virtual_node_division_gains_fx[ch], 1, sum_val_fx, add( guard_bits, 1 ), &virtual_node_division_gains_fx[ch], &final_exp ); // Q15 + BASOP_Util_Divide_MantExp( virtual_node_division_gains_fx[ch], 1, sum_val_fx, add( guard_bits, 1 ), &virtual_node_division_gains_fx[ch], &final_exp ); } ELSE { @@ -1565,9 +1570,9 @@ static void determine_virtual_speaker_node_division_gains_fx( } ELSE { - Word32 tmp32 = L_deposit_h( virtual_node_division_gains_fx[ch] ); // q is 15-final_exp// ldep -> 31-final_exp (q) + Word32 tmp32 = L_deposit_h( virtual_node_division_gains_fx[ch] ); tmp_1 = L_add( BASOP_Util_Log2( tmp32 ), L_shl( ( sub( 31, sub( 31, final_exp ) ) ), 25 ) ); // Q25 - tmp_2 = Mpy_32_32( 26843546 /*0.8f in Q25*/, tmp_1 ); + tmp_2 = Mpy_32_32( 26843546 /* 0.8f in Q25 */, tmp_1 ); tmp_3 = BASOP_util_Pow2( tmp_2, Q31 - Q19, &res_exp ); exp_virtual_node_division_gains[ch] = res_exp; move16(); @@ -1577,10 +1582,9 @@ static void determine_virtual_speaker_node_division_gains_fx( } } /*make a common exp*/ - *max_exp = -1; /*Q16*/ FOR( i = 0; i < num_speaker_nodes; i++ ) { - virtual_node_division_gains_fx[i] = shr( virtual_node_division_gains_fx[i], sub( *max_exp, exp_virtual_node_division_gains[i] ) ); + virtual_node_division_gains_fx[i] = shr( virtual_node_division_gains_fx[i], sub( -1, exp_virtual_node_division_gains[i] ) ); /* Q16 */ move16(); } } @@ -1662,13 +1666,13 @@ static void determine_virtual_speaker_node_division_gains( #ifdef IVAS_FLOAT_FIXED static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node_fx( VBAP_HANDLE hVBAPdata, /* i/o: VBAP structure */ - const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths */ - const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations */ + const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths Q22 */ + const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations Q22 */ enum SpeakerNodeGroup group /* i : group of speaker nodes where this belongs */ ) { Word16 ch; - Word32 max_elevation_fx = 0; + Word32 max_elevation_fx = 0; /* Q22 */ Word16 Flag1, Flag2, Flag3; move32(); @@ -1677,17 +1681,17 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node_fx( { Word16 virtual_back_needed = 1; move16(); - const Word16 virtual_back_epsilon_fx = -573; /* -0.0175f Q15*/ + const Word16 virtual_back_epsilon_fx = -573; /* -0.0175f in Q15 */ move16(); FOR( ch = 0; ch < hVBAPdata->num_speaker_nodes; ch++ ) { Flag1 = BASOP_Util_Cmp_Mant32Exp( speaker_node_ele_deg_fx[ch], Q31 - Q22, 23040 /*45.0f Q9*/, Q31 - Q9 ); - IF( EQ_16( Flag1, (Word16) -1 ) ) + IF( EQ_16( Flag1, -1 ) ) { Word16 azi_temp; - azi_temp = extract_l( L_shr( Mpy_32_32( speaker_node_azi_deg_fx[ch], ONE_BY_180_Q31 ), Q8 ) ); /* Q15 */ - Word16 cos_res = getCosWord16R2( azi_temp ); // Q15 + azi_temp = extract_l( L_shr( Mpy_32_32( speaker_node_azi_deg_fx[ch], ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ + Word16 cos_res = getCosWord16R2( azi_temp ); /* Q15 */ IF( LT_16( cos_res, virtual_back_epsilon_fx ) ) { @@ -1729,7 +1733,7 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node_fx( } } } - Flag2 = BASOP_Util_Cmp_Mant32Exp( max_elevation_fx, Q31 - Q22, 23039 /*44.9990005 Q9*/, Q31 - Q9 ); + Flag2 = BASOP_Util_Cmp_Mant32Exp( max_elevation_fx, Q31 - Q22, 23039 /* 44.9990005 in Q9 */, Q31 - Q9 ); IF( EQ_16( Flag2, 1 ) ) { return NO_VIRTUAL_SPEAKER_NODE; @@ -1749,7 +1753,7 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node_fx( hVBAPdata->num_speaker_nodes_internal = add( hVBAPdata->num_speaker_nodes_internal, 1 ); move16(); - Flag3 = BASOP_Util_Cmp_Mant32Exp( max_elevation_fx, Q31 - Q22, 20478 /*19.9990005 Q10*/, Q31 - Q10 ); + Flag3 = BASOP_Util_Cmp_Mant32Exp( max_elevation_fx, Q31 - Q22, 20478 /* 19.9990005 in Q10 */, Q31 - Q10 ); IF( EQ_16( Flag3, 1 ) ) { @@ -1849,31 +1853,28 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node( #ifdef IVAS_FLOAT_FIXED static void init_speaker_node_direction_data_fx( - VBAP_SPEAKER_NODE *speaker_node_data, /* o : storage for speaker node data */ - const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths */ - const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations */ - const Word16 num_speaker_nodes /* i : number of speaker nodes */ + VBAP_SPEAKER_NODE *speaker_node_data, /* o : storage for speaker node data */ + const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths Q22 */ + const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations Q22 */ + const Word16 num_speaker_nodes /* i : number of speaker nodes */ ) { Word16 ch; - - Word16 azi_rad_fx = 0; - Word16 ele_rad_fx = 0; - + Word16 azi_rad_fx; + Word16 ele_rad_fx; Word16 num_horiz = 0; UWord8 in_all_mode = TRUE; - move32(); - move32(); - move32(); move16(); + move16(); + FOR( ch = 0; ch < num_speaker_nodes; ch++ ) { speaker_node_data[ch].azi_deg_fx = speaker_node_azi_deg_fx[ch]; move32(); - azi_rad_fx = extract_l( L_shr( Mpy_32_32( speaker_node_azi_deg_fx[ch], ONE_BY_180_Q31 ), Q8 ) ); + azi_rad_fx = extract_l( L_shr( Mpy_32_32( speaker_node_azi_deg_fx[ch], ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ test(); - IF( GE_32( L_shr( speaker_node_ele_deg_fx[ch], 22 ), -5 ) && LE_32( L_shr( speaker_node_ele_deg_fx[ch], 22 ), 5 ) ) + IF( GE_32( L_shr( speaker_node_ele_deg_fx[ch], Q22 ), -5 ) && LE_32( L_shr( speaker_node_ele_deg_fx[ch], Q22 ), 5 ) ) { speaker_node_data[ch].ele_deg_fx = 0; move32(); @@ -1887,7 +1888,7 @@ static void init_speaker_node_direction_data_fx( { speaker_node_data[ch].ele_deg_fx = speaker_node_ele_deg_fx[ch]; move32(); - ele_rad_fx = extract_l( L_shr( Mpy_32_32( speaker_node_ele_deg_fx[ch], ONE_BY_180_Q31 ), Q8 ) ); + ele_rad_fx = extract_l( L_shr( Mpy_32_32( speaker_node_ele_deg_fx[ch], ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ IF( ele_rad_fx < 0 ) { @@ -1901,11 +1902,11 @@ static void init_speaker_node_direction_data_fx( } } - speaker_node_data[ch].unit_vec_fx[0] = L_shr( L_mult( getCosWord16R2( azi_rad_fx ), getCosWord16R2( ele_rad_fx ) ), 1 ); // Q30 (add one gaurd bit , buffer being used in Q30) + speaker_node_data[ch].unit_vec_fx[0] = L_shr( L_mult( getCosWord16R2( azi_rad_fx ), getCosWord16R2( ele_rad_fx ) ), 1 ); /* Q15 + Q15 + Q1 - Q1 = Q30 */ move32(); - speaker_node_data[ch].unit_vec_fx[1] = L_shr( L_mult( getSineWord16R2( azi_rad_fx ), getCosWord16R2( ele_rad_fx ) ), 1 ); // Q30 + speaker_node_data[ch].unit_vec_fx[1] = L_shr( L_mult( getSineWord16R2( azi_rad_fx ), getCosWord16R2( ele_rad_fx ) ), 1 ); /* Q15 + Q15 + Q1 - Q1 = Q30 */ move32(); - speaker_node_data[ch].unit_vec_fx[2] = L_shr( L_deposit_h( getSineWord16R2( ele_rad_fx ) ), 1 ); // Q30 + speaker_node_data[ch].unit_vec_fx[2] = L_shr( L_deposit_h( getSineWord16R2( ele_rad_fx ) ), 1 ); /* Q15 + Q16 - Q1 = Q30 */ move32(); } /* Check for largest horizontal gap if there are at least 3 horizontal speaker nodes */ @@ -1921,18 +1922,19 @@ static void init_speaker_node_direction_data_fx( move16(); FOR( ch = 0; ch < num_speaker_nodes && i < num_horiz; ch++ ) { + test(); IF( EQ_16( speaker_node_data[ch].group, SPEAKER_NODE_HORIZONTAL ) ) { Word16 exp1; - Word32 Mant2 = BASOP_Util_Add_Mant32Exp( speaker_node_azi_deg_fx[ch], 31 - 22, 23040, 31 - 6, &exp1 ); + Word32 Mant2 = BASOP_Util_Add_Mant32Exp( speaker_node_azi_deg_fx[ch], Q31 - Q22, 23040 /* 360.0f in Q6 */, Q31 - Q6, &exp1 ); IF( L_shr( speaker_node_azi_deg_fx[ch], 22 ) < 0 ) { - horiz_azi[i] = (UWord16) L_shr( Mant2, sub( 31, exp1 ) ); + horiz_azi[i] = (UWord16) L_shr( Mant2, sub( 31, exp1 ) ); /* Q0 */ } ELSE { - horiz_azi[i] = (UWord16) L_shr( speaker_node_azi_deg_fx[ch], 22 ); + horiz_azi[i] = (UWord16) L_shr( speaker_node_azi_deg_fx[ch], Q22 ); /* Q0 */ } i = add( i, 1 ); } @@ -1944,7 +1946,7 @@ static void init_speaker_node_direction_data_fx( /* Find largest gap. Initialize with the wrap over gap. */ largest_gap = add( sub( horiz_azi[0], horiz_azi[num_horiz - 1] ), 360 ); - FOR( ch = 0; ch < sub( num_horiz, 1 ); ch++ ) + FOR( ch = 0; ch < num_horiz - 1; ch++ ) { temp = sub( horiz_azi[ch + 1], horiz_azi[ch] ); if ( GT_16( temp, largest_gap ) ) @@ -2082,26 +2084,25 @@ static void init_speaker_node_direction_data( #ifdef IVAS_FLOAT_FIXED static void matrix_inverse_3x3_32_fx( - const Word32 **input_matrix_fx, /* i : input matrix */ - Word32 inverse_matrix_fx[3][3], /* o : output matrix */ + const Word32 **input_matrix_fx, /* i : input matrix Q30 */ + Word32 inverse_matrix_fx[3][3], /* o : output matrix Q(31 - exp_inv_mat) */ Word16 *exp_inv_mat ) { Word16 k; - Word32 determinant_fx; - Word32 cross_vec_fx[3]; + Word32 determinant_fx; /* Q28 */ + Word32 cross_vec_fx[3]; /* Q29 */ Word16 exp_inverse_matrix_fx[3][3]; vbap_crossp_fx( input_matrix_fx[1], input_matrix_fx[2], cross_vec_fx ); - determinant_fx = dotp_fixed( input_matrix_fx[0], cross_vec_fx, 3 ); // Q30 + Q29 - Q31 = Q28 + determinant_fx = dotp_fixed( input_matrix_fx[0], cross_vec_fx, 3 ); Word16 inv_mat_exp = 0; move16(); FOR( k = 0; k < 3; k++ ) { inverse_matrix_fx[k][0] = L_deposit_h( BASOP_Util_Divide3232_Scale( cross_vec_fx[k], determinant_fx, &inv_mat_exp ) ); - inv_mat_exp = add( inv_mat_exp, ( ( 31 - 29 ) - ( 31 - 28 ) ) ); - exp_inverse_matrix_fx[k][0] = inv_mat_exp; - move32(); + inv_mat_exp = add( inv_mat_exp, ( ( Q31 - Q29 ) - ( Q31 - Q28 ) ) ); + exp_inverse_matrix_fx[k][0] = inv_mat_exp; move16(); } @@ -2110,10 +2111,9 @@ static void matrix_inverse_3x3_32_fx( FOR( k = 0; k < 3; k++ ) { inverse_matrix_fx[k][1] = L_deposit_h( BASOP_Util_Divide3232_Scale( cross_vec_fx[k], determinant_fx, &inv_mat_exp ) ); - inv_mat_exp = add( inv_mat_exp, ( ( 31 - 29 ) - ( 31 - 28 ) ) ); - exp_inverse_matrix_fx[k][1] = inv_mat_exp; - move32(); + inv_mat_exp = add( inv_mat_exp, ( ( Q31 - Q29 ) - ( Q31 - Q28 ) ) ); + exp_inverse_matrix_fx[k][1] = inv_mat_exp; move16(); } @@ -2123,7 +2123,7 @@ static void matrix_inverse_3x3_32_fx( { inverse_matrix_fx[k][2] = L_deposit_h( BASOP_Util_Divide3232_Scale( cross_vec_fx[k], determinant_fx, &inv_mat_exp ) ); move32(); - inv_mat_exp = add( inv_mat_exp, ( ( 31 - 29 ) - ( 31 - 28 ) ) ); + inv_mat_exp = add( inv_mat_exp, ( ( Q31 - Q29 ) - ( Q31 - Q28 ) ) ); exp_inverse_matrix_fx[k][2] = inv_mat_exp; move16(); } @@ -2149,13 +2149,13 @@ static void matrix_inverse_3x3_32_fx( IF( LT_16( exp_inverse_matrix_fx[i][j], -15 ) && inverse_matrix_fx[i][j] != 0 ) { inverse_matrix_fx[i][j] = 1; - exp_inverse_matrix_fx[i][j] = 0; move32(); + exp_inverse_matrix_fx[i][j] = 0; move16(); } ELSE { - inverse_matrix_fx[i][j] = L_shr( inverse_matrix_fx[i][j], *exp_inv_mat - exp_inverse_matrix_fx[i][j] ); + inverse_matrix_fx[i][j] = L_shr( inverse_matrix_fx[i][j], sub( *exp_inv_mat, exp_inverse_matrix_fx[i][j] ) ); /* Q(31 - *exp_inv_mat) */ move32(); } } @@ -2205,37 +2205,41 @@ static void matrix_inverse_3x3( * Check if the given loudspeaker triplet is a valid one and store data when * valid triplet is found. *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static Word16 check_and_store_triplet_fx( - const Word16 chA, /* i : first channel index that forms the loudspeaker triplet */ - const Word16 chB, /* i : second channel index that forms the loudspeaker triplet */ - const Word16 chC, /* i : third channel index that forms the loudspeaker triplet */ - const Word16 num_speaker_nodes, /* i : number of speaker nodes */ - const VBAP_SPEAKER_NODE *speaker_node_data, /* i : speaker node data structure */ - VBAP_VS_TRIPLET *triplets, /* o : vector of virtual surface triplets */ - Word16 *triplet_index, /* i/o: index for the next free triplet slot */ - Word32 *triplet_azidegs_fx, - Word16 *triplet_order /* o : initial order of triplet indices */ + const Word16 chA, /* i : first channel index that forms the loudspeaker triplet */ + const Word16 chB, /* i : second channel index that forms the loudspeaker triplet */ + const Word16 chC, /* i : third channel index that forms the loudspeaker triplet */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes */ + const VBAP_SPEAKER_NODE *speaker_node_data, /* i : speaker node data structure */ + VBAP_VS_TRIPLET *triplets, /* o : vector of virtual surface triplets */ + Word16 *triplet_index, /* i/o: index for the next free triplet slot */ + Word32 *triplet_azidegs_fx, /* o : center azimuths of the found triplets Q19 */ + Word16 *triplet_order /* o : initial order of triplet indices */ ) { Word16 ch_check; Word16 k; Word16 speaker_node_found_inside_triplet; UWord8 triplet_ok; + Word16 exp_inv_mat; - Word32 inverse_matrix_fx[3][3], unnormalized_gains_fx[3]; + Word32 inverse_matrix_fx[3][3] /* Q(31 - exp_inv_mat) */, unnormalized_gains_fx[3] /* Q(31 - exp_inv_mat - 1) */; set32_fx( unnormalized_gains_fx, 0, 3 ); - const Word32 *speaker_node_triplet_unit_vec_matrix_fx[3]; + const Word32 *speaker_node_triplet_unit_vec_matrix_fx[3]; /* Q30 */ /* Triplet found, determine inverse matrix for VBAP formulation */ speaker_node_triplet_unit_vec_matrix_fx[0] = speaker_node_data[chA].unit_vec_fx; + move32(); speaker_node_triplet_unit_vec_matrix_fx[1] = speaker_node_data[chB].unit_vec_fx; + move32(); speaker_node_triplet_unit_vec_matrix_fx[2] = speaker_node_data[chC].unit_vec_fx; - Word16 exp_inv_mat = 31; - move16(); + move32(); matrix_inverse_3x3_32_fx( speaker_node_triplet_unit_vec_matrix_fx, inverse_matrix_fx, &exp_inv_mat ); triplets[*triplet_index].q_inverse_matrix = sub( 31, exp_inv_mat ); + move16(); /* Check through all speaker nodes that none of them are within the triplet. * Node within the triplet is identified by that all three panning gains are positive. @@ -2248,7 +2252,7 @@ static Word16 check_and_store_triplet_fx( test(); IF( ( NE_16( ch_check, chA ) ) && NE_16( ch_check, chB ) && NE_16( ch_check, chC ) ) { - triplet_ok = vector_matrix_multiply_3x3_32_fx( speaker_node_data[ch_check].unit_vec_fx, inverse_matrix_fx, unnormalized_gains_fx, sub( 31, exp_inv_mat ) ); + triplet_ok = vector_matrix_multiply_3x3_32_fx( speaker_node_data[ch_check].unit_vec_fx, inverse_matrix_fx, unnormalized_gains_fx, sub( Q31, exp_inv_mat ) ); test(); test(); test(); @@ -2275,16 +2279,16 @@ static Word16 check_and_store_triplet_fx( Copy32( inverse_matrix_fx[k], triplets[*triplet_index].inverse_matrix_fx[k], 3 ); } /* Get center azimuth for fast search use */ - Word32 tmp_a = L_add( L_shr( L_add( speaker_node_data[chA].unit_vec_fx[1], speaker_node_data[chB].unit_vec_fx[1] ), 2 ), L_shr( speaker_node_data[chC].unit_vec_fx[1], 2 ) ); // Q28 + Word32 tmp_a = L_add( L_shr( L_add( speaker_node_data[chA].unit_vec_fx[1], speaker_node_data[chB].unit_vec_fx[1] ), Q2 ), L_shr( speaker_node_data[chC].unit_vec_fx[1], Q2 ) ); /* Q28 */ /*Condition to make tmp_a 0 to adress precision loss seen*/ - if ( EQ_32( tmp_a, -8193 ) ) + if ( EQ_32( tmp_a, -8193 /* -0.0000305 in Q28 */ ) ) { tmp_a = 0; move32(); } - Word32 tmp_b = L_add( L_shr( L_add( speaker_node_data[chA].unit_vec_fx[0], speaker_node_data[chB].unit_vec_fx[0] ), 2 ), L_shr( speaker_node_data[chC].unit_vec_fx[0], 2 ) ); // Q28 - Word16 tmp_tan = shr( BASOP_util_atan2( tmp_a, tmp_b, 0 ), Q13 - Q9 ); - triplet_azidegs_fx[*triplet_index] = L_mult( tmp_tan, 29335 /*_180_OVER_PI in Q9*/ ); // Q3 + Word32 tmp_b = L_add( L_shr( L_add( speaker_node_data[chA].unit_vec_fx[0], speaker_node_data[chB].unit_vec_fx[0] ), 2 ), L_shr( speaker_node_data[chC].unit_vec_fx[0], 2 ) ); /* Q28 */ + Word16 tmp_tan = shr( BASOP_util_atan2( tmp_a, tmp_b, 0 ), Q13 - Q9 ); /* Q9 */ + triplet_azidegs_fx[*triplet_index] = L_mult( tmp_tan, 29335 /*_180_OVER_PI in Q9*/ ); /* Q19 */ move32(); /* Store increasing order indices for the later sorting step. */ triplet_order[*triplet_index] = *triplet_index; @@ -2300,7 +2304,6 @@ static Word16 check_and_store_triplet_fx( return 0; } #else - static int16_t check_and_store_triplet( const int16_t chA, /* i : first channel index that forms the loudspeaker triplet */ const int16_t chB, /* i : second channel index that forms the loudspeaker triplet */ @@ -2399,7 +2402,7 @@ static Word16 determine_virtual_surface_triplets_fx( Word16 num_connected_to_chA; Word16 connected_to_chA[VBAP_MAX_NUM_SPEAKER_NODES]; Word16 connection_uses_left[VBAP_MAX_NUM_SPEAKER_NODES]; - Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS]; + Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS]; /* Q19 */ Word16 triplet_order[VBAP_MAX_NUM_TRIPLETS]; /* Each connection can be used exactly by two different virtual surface triplets. */ @@ -2441,12 +2444,24 @@ static Word16 determine_virtual_surface_triplets_fx( { Word16 connect_index_k = connected_to_chA[k]; move16(); - chB = EQ_16( connections[connect_index_k][0], chA ) ? connections[connect_index_k][1] : connections[connect_index_k][0]; + chB = connections[connect_index_k][0]; + move16(); + if ( EQ_16( connections[connect_index_k][0], chA ) ) + { + chB = connections[connect_index_k][1]; + move16(); + } FOR( l = k + 1; l < num_connected_to_chA; l++ ) { Word16 connect_index_l = connected_to_chA[l]; move16(); - chC = EQ_16( connections[connect_index_l][0], chA ) ? connections[connect_index_l][1] : connections[connect_index_l][0]; + chC = connections[connect_index_l][0]; + move16(); + if ( EQ_16( connections[connect_index_l][0], chA ) ) + { + chC = connections[connect_index_l][1]; + move16(); + } /* With chA, chB, and chC selected, we still need to find connection between chB and chC and verify that the triplet is valid */ FOR( m = 0; m < max_num_connections; m++ ) @@ -2485,7 +2500,7 @@ static Word16 determine_virtual_surface_triplets_fx( * each search sector for this search struct. */ v_sort_ind_fixed( triplet_azidegs_fx, triplet_order, num_triplets ); reorder_triplets_fx( triplets, triplet_order, num_triplets ); - determine_initial_search_indices_fx( num_triplets, triplet_azidegs_fx /*Q19*/, initial_search_indices ); + determine_initial_search_indices_fx( num_triplets, triplet_azidegs_fx, initial_search_indices ); return num_triplets; } @@ -2593,18 +2608,18 @@ static int16_t determine_virtual_surface_triplets( #ifdef IVAS_FLOAT_FIXED static void determine_initial_search_indices_fx( - const Word16 num_triplets, /* i : number of triplets */ - const Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS], - Word16 initial_search_indices[VBAP_NUM_SEARCH_SECTORS] /* o : initial search indices */ + const Word16 num_triplets, /* i : number of triplets */ + const Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS], /* i : azimuths of triplets (in degrees) Q19 */ + Word16 initial_search_indices[VBAP_NUM_SEARCH_SECTORS] /* o : initial search indices */ ) { Word16 i, j; - Word32 sector_reference_azideg_fx; - Word32 sector_border_start_azideg_fx; - Word32 sector_border_end_azideg_fx; + Word32 sector_reference_azideg_fx; /* Q0 */ + Word32 sector_border_start_azideg_fx; /* Q0 */ + Word32 sector_border_end_azideg_fx; /* Q0 */ Word16 best_index; Word32 min_azideg_diff_fx; - Word32 azideg_diff_fx; + Word32 azideg_diff_fx; /* Q19 */ FOR( i = 0; i < VBAP_NUM_SEARCH_SECTORS; i++ ) { @@ -2622,13 +2637,13 @@ static void determine_initial_search_indices_fx( { azideg_diff_fx = L_sub( L_shl( sector_reference_azideg_fx, Q19 ), triplet_azidegs_fx[j] ); - IF( GT_32( azideg_diff_fx, 94371840 ) ) + IF( GT_32( azideg_diff_fx, 94371840 /* 180.0f in Q19 */ ) ) { - azideg_diff_fx = L_sub( azideg_diff_fx, 188743680 ); + azideg_diff_fx = L_sub( azideg_diff_fx, 188743680 /* 360.0f in Q19 */ ); } - ELSE IF( LT_32( azideg_diff_fx, -94371840 ) ) + ELSE IF( LT_32( azideg_diff_fx, -94371840 /* -180.0f in Q19 */ ) ) { - azideg_diff_fx = L_add( azideg_diff_fx, 188743680 ); + azideg_diff_fx = L_add( azideg_diff_fx, 188743680 /* 360.0f in Q19 */ ); } azideg_diff_fx = L_abs( azideg_diff_fx ); @@ -2718,7 +2733,7 @@ static ivas_error determine_connections_fx( Word16 c; Word16 connection_write_index = 0; move16(); - Word32 non_crossing_plane_elevation_deg_fx[VBAP_MAX_PLANES]; + Word32 non_crossing_plane_elevation_deg_fx[VBAP_MAX_PLANES]; /* Q14 */ ivas_error error; @@ -2844,15 +2859,15 @@ static enum ConnectionClass determine_connection_class_fx( Word16 ch, k; const Word32 *p1_fx, *v2_fx; - Word32 v1v1_fx, v1v2_fx, v2v2_fx, v1p1_fx, v2p1_fx; - Word32 determinant_fx; + Word32 v1v1_fx, v1v2_fx, v2v2_fx, v1p1_fx, v2p1_fx; /* Q25, Q27, Q29, Q27, Q29 */ + Word32 determinant_fx; /* Q23 */ Word32 norm_distance_on_v1_fx; Word32 vec_diff_fx[3]; - Word32 v1_fx[3]; + Word32 v1_fx[3]; /* Q28 */ Word32 vTarget_fx[3]; Word32 energy_sum_fx; Word32 eq_value_fx; - Word32 uvecdot_fx; + Word32 uvecdot_fx; /* Q30 */ /* Check if connection passes through origin. This is not desired. * When this happens, unit vectors point in opposite directions. */ @@ -2885,9 +2900,10 @@ static enum ConnectionClass determine_connection_class_fx( FOR( k = 0; k < 3; k++ ) { - v1_fx[k] = L_sub( L_shr( node_data[chB].unit_vec_fx[k], 2 ), L_shr( node_data[chA].unit_vec_fx[k], 2 ) ); // q28 (Add two guard bit) + v1_fx[k] = L_sub( L_shr( node_data[chB].unit_vec_fx[k], 2 ), L_shr( node_data[chA].unit_vec_fx[k], 2 ) ); /* Q28 (Add two guard bit) */ + move32(); } - v2_fx = node_data[ch].unit_vec_fx; // q30 + v2_fx = node_data[ch].unit_vec_fx; // Q30 move32(); v1v1_fx = dotp_fixed( v1_fx, v1_fx, 3 ); // Q25 @@ -2939,13 +2955,13 @@ static enum ConnectionClass determine_connection_class_fx( FOR( k = 0; k < 3; k++ ) { var1 = Mpy_32_32( norm_distance_on_v1_fx, v1_fx[k] ); // Q(25 - exp) + Q28 - 31 - vTarget_fx[k] = BASOP_Util_Add_Mant32Exp( p1_fx[k], 1, var1, Q31 - ( Q25 - exp + Q28 - Q31 ), &exp_vTarget ); + vTarget_fx[k] = BASOP_Util_Add_Mant32Exp( p1_fx[k], 1, var1, sub( Q31, add( sub( Q25, exp ), Q28 - Q31 ) ), &exp_vTarget ); move16(); vTarget_fx_e[k] = exp_vTarget; move16(); var2 = Mpy_32_32( vTarget_fx[k], vTarget_fx[k] ); // 2*exp_vTarget - energy_sum_fx = BASOP_Util_Add_Mant32Exp( energy_sum_fx, exp_energy_sum, var2, 2 * exp_vTarget, &exp_energy_sum ); + energy_sum_fx = BASOP_Util_Add_Mant32Exp( energy_sum_fx, exp_energy_sum, var2, shl( exp_vTarget, 1 ), &exp_energy_sum ); vec_diff_fx[k] = BASOP_Util_Add_Mant32Exp( vTarget_fx[k], exp_vTarget, L_negate( v2_fx[k] ), 1, &exp_vec_diff ); move16(); vec_diff_e[k] = exp_vec_diff; @@ -2990,7 +3006,7 @@ static enum ConnectionClass determine_connection_class_fx( Word32 res = dotp_fixed( vTarget_fx, v2_fx, 3 ); // 31 - (max_vTarget_e + 2) + 30 - 31 = 28 - max_vTarget_e move32(); - IF( GT_32( res, L_shr( 2147054208, sub( 31, sub( 28, max_vTarget_e ) ) ) ) ) + IF( GT_32( res, L_shr( 2147054208 /* 0.9998f in Q31 */, sub( 31, sub( 28, max_vTarget_e ) ) ) ) ) { return CONNECTION_WITH_SPEAKER_NODE_BEHIND; } @@ -3001,10 +3017,10 @@ static enum ConnectionClass determine_connection_class_fx( Word32 vec_diff_dotp = dotp_fixed( vec_diff_fx, vec_diff_fx, 3 ); // exp : 2 * max_vec_diff_e + 4 move32(); Word32 var = Mpy_32_32( vec_diff_dotp, 51200 /*25.0f in Q11*/ ); // exp : 2 * max_vec_diff_e + 4 + 20 - Word16 Flag1 = BASOP_Util_Cmp_Mant32Exp( v1v1_fx, Q31 - Q25, var, 2 * max_vec_diff_e + 4 + 20 ); + Word16 Flag1 = BASOP_Util_Cmp_Mant32Exp( v1v1_fx, Q31 - Q25, var, add( shl( max_vec_diff_e, 1 ), 4 + 20 ) ); IF( EQ_16( Flag1, 1 ) ) { - IF( LT_32( L_abs( L_sub( node_data[chB].unit_vec_fx[2], node_data[chA].unit_vec_fx[2] ) ), 2147483 ) ) + IF( LT_32( L_abs( L_sub( node_data[chB].unit_vec_fx[2], node_data[chA].unit_vec_fx[2] ) ), 1073742 /* 0.001f in Q30 */ ) ) { return ELEVATED_PLANE_THIN_TRIANGLE_CONNECTION; } @@ -3240,10 +3256,10 @@ static void formulate_horizontal_connections( /*! r: truth value for crossing */ #ifdef IVAS_FLOAT_FIXED static Word16 check_plane_crossing_fx( - const Word32 ele1_deg_fx, /* i : speaker node 1 elevation */ - const Word32 ele2_deg_fx, /* i : speaker node 2 elevation */ - const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ - const Word32 *non_crossing_plane_elevation_deg_fx /* i : vector non-crossing plane elevations*/ + const Word32 ele1_deg_fx, /* i : speaker node 1 elevation Q22 */ + const Word32 ele2_deg_fx, /* i : speaker node 2 elevation Q22 */ + const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ + const Word32 *non_crossing_plane_elevation_deg_fx /* i : vector non-crossing plane elevations Q14 */ ) { /* Find if the connection crosses a non-crossing plane, with 1-degree threshold. */ @@ -3300,13 +3316,13 @@ static int16_t check_plane_crossing( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static ivas_error get_half_sphere_connection_options_fx( - const VBAP_SPEAKER_NODE *speaker_node_data, /* i : speaker node data */ - const enum SpeakerNodeGroup group, /* i : speaker node group */ - const Word16 num_speaker_nodes, /* i : number of speaker nodes */ - const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ - const Word32 *non_crossing_plane_elevation_deg_fx, /* i : vector of non-crossing plane elevations */ - ConnectionOption **connection_options_pr, /* o : list of connection options */ - Word16 *num_connection_options /* o : number of connection options */ + const VBAP_SPEAKER_NODE *speaker_node_data, /* i : speaker node data */ + const enum SpeakerNodeGroup group, /* i : speaker node group */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes */ + const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ + const Word32 *non_crossing_plane_elevation_deg_fx, /* i : vector of non-crossing plane elevations Q14 */ + ConnectionOption **connection_options_pr, /* o : list of connection options */ + Word16 *num_connection_options /* o : number of connection options */ ) { Word16 max_num_connection_options = 0; @@ -3380,8 +3396,8 @@ static ivas_error get_half_sphere_connection_options_fx( Word16 exp_uv = Q31 - Q27; move16(); one_minus_unit_vec_dotp_sq_root = Sqrt32( one_minus_unit_vec_dotp_sq, &exp_uv ); - acos_val = BASOP_util_atan2( one_minus_unit_vec_dotp_sq_root, unit_vec_dotp, exp_uv - 2 ); // Q13 - c_options[index].arc_fx = L_deposit_h( acos_val ); // Q29 + acos_val = BASOP_util_atan2( one_minus_unit_vec_dotp_sq_root, unit_vec_dotp, sub( exp_uv, 2 ) ); // Q13 + c_options[index].arc_fx = L_deposit_h( acos_val ); // Q29 move32(); c_options[index].arc_weighted_fx = c_options[index].arc_fx; // Q29 move32(); @@ -3397,7 +3413,7 @@ static ivas_error get_half_sphere_connection_options_fx( /* If the connection passes a pre-determined plane of speaker nodes, then add further penalty */ - IF( check_plane_crossing_fx( speaker_node_data[chA].ele_deg_fx /*q22*/, speaker_node_data[chB].ele_deg_fx, num_non_crossing_planes, non_crossing_plane_elevation_deg_fx ) ) + IF( check_plane_crossing_fx( speaker_node_data[chA].ele_deg_fx, speaker_node_data[chB].ele_deg_fx, num_non_crossing_planes, non_crossing_plane_elevation_deg_fx ) ) { c_options[index].arc_weighted_fx = L_shl( c_options[index].arc_weighted_fx, 1 ); move32(); @@ -3595,9 +3611,9 @@ static ivas_error formulate_half_sphere_connections_fx( const enum SpeakerNodeGroup group, /* i : speaker node group */ Word16 connections[][2], /* o : vector of connections */ Word16 *connection_write_index, - const Word16 max_num_connections, /* i : max number of connections */ - const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ - const Word32 *non_crossing_plane_elevation_deg_fx /* i : vector of non-crossing plane elevations */ + const Word16 max_num_connections, /* i : max number of connections */ + const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ + const Word32 *non_crossing_plane_elevation_deg_fx /* i : vector of non-crossing plane elevations Q14*/ ) { /* Variable initializations */ @@ -3607,11 +3623,11 @@ static ivas_error formulate_half_sphere_connections_fx( Word32 new_cross_fx[3]; Word32 planeCrossingVec_fx[3]; Word16 Q_planeCrossingVec; - Word32 new_arc_fx; - Word32 connection_arc_fx[( VBAP_MAX_NUM_SPEAKER_NODES - 2 ) * 3]; - Word32 connection_cross_fx[( VBAP_MAX_NUM_SPEAKER_NODES - 2 ) * 3][3]; + Word32 new_arc_fx; /* Q29 */ + Word32 connection_arc_fx[( VBAP_MAX_NUM_SPEAKER_NODES - 2 ) * 3]; /* Q29 */ + Word32 connection_cross_fx[( VBAP_MAX_NUM_SPEAKER_NODES - 2 ) * 3][3]; /* Q29 */ Word32 tmpFloat_fx; - Word32 cmp_arc_fx; + Word32 cmp_arc_fx; /* Q29 */ Word32 normVal_fx; Word16 angleCmp_fx; ConnectionOption *connection_options; @@ -3648,6 +3664,7 @@ static ivas_error formulate_half_sphere_connections_fx( move16(); WHILE( c_opt < num_connection_options && *connection_write_index < max_num_connections ) { + test(); chA = connection_options[c_opt].chA; move16(); chB = connection_options[c_opt].chB; @@ -3747,10 +3764,10 @@ static ivas_error formulate_half_sphere_connections_fx( sub_exp = 0, sub_exp_2 = 0, sub_final_exp = 0; var_a = BASOP_Util_Add_Mant32Exp( new_arc_fx, Q31 - Q29, L_negate( L_deposit_h( angleCmp_fx ) ), final_exp, &sub_exp ); - comp1 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_a ), sub_exp, 21474836, 0 ); + comp1 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_a ), sub_exp, 21474836 /* 0.01f in Q31 */, 0 ); var_b = BASOP_Util_Add_Mant32Exp( 25735, Q31 - Q12, L_negate( L_deposit_h( angleCmp_fx ) ), final_exp, &sub_exp_2 ); var_c = BASOP_Util_Add_Mant32Exp( new_arc_fx, Q31 - Q29, L_negate( var_b ), sub_exp_2, &sub_final_exp ); - comp2 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_c ), sub_final_exp, 21474836, 0 ); + comp2 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_c ), sub_final_exp, 21474836 /* 0.01f in Q31 */, 0 ); within_first_arc = 0; move16(); @@ -3771,7 +3788,7 @@ static ivas_error formulate_half_sphere_connections_fx( move32(); } /*update Q for planeCrossingVec */ - Q_planeCrossingVec = sub( sub( add( Q27, Q27 ), tmp_exp ), Q31 ); + Q_planeCrossingVec = sub( sub( Q27 + Q27, tmp_exp ), Q31 ); } /* Study if the crossing is also between arc cmp_chA-cmp_chB */ @@ -3803,13 +3820,13 @@ static ivas_error formulate_half_sphere_connections_fx( } one_minus_var1_sq = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( var1_sq ), exp_var1_sq, &final_exp_A ); var1_sqrt = Sqrt32( one_minus_var1_sq, &final_exp_A ); - var1_cos = BASOP_util_atan2( var1_sqrt, var1, final_exp_A - ( Q31 - ( Q_planeCrossingVec + Q30 - Q31 ) ) ); // Q13 + var1_cos = BASOP_util_atan2( var1_sqrt, var1, sub( final_exp_A, sub( Q31, add( Q_planeCrossingVec, Q30 - Q31 ) ) ) ); // Q13 angleCmp_fx = var1_cos; move16(); one_minus_var2_sq = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( var2_sq ), exp_var2_sq, &final_exp_B ); var2_sqrt = Sqrt32( one_minus_var2_sq, &final_exp_B ); - var2_cos = BASOP_util_atan2( var2_sqrt, var2, final_exp_B - ( Q31 - ( Q_planeCrossingVec + Q30 - Q31 ) ) ); // Q13 + var2_cos = BASOP_util_atan2( var2_sqrt, var2, sub( final_exp_B, sub( Q31, add( Q_planeCrossingVec, Q30 - Q31 ) ) ) ); // Q13 final_exp = BASOP_Util_Add_MantExp( angleCmp_fx, Q15 - Q13, var2_cos, Q15 - Q13, &angleCmp_fx ); @@ -3818,7 +3835,7 @@ static ivas_error formulate_half_sphere_connections_fx( move16(); move16(); var_a = BASOP_Util_Add_Mant32Exp( cmp_arc_fx, Q31 - Q29, L_negate( L_deposit_h( angleCmp_fx ) ), final_exp, &sub_exp ); - comp1 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_a ), sub_exp, 21474836, 0 ); + comp1 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_a ), sub_exp, 21474836 /* 0.01f in Q31 */, 0 ); if ( EQ_16( comp1, -1 ) ) { @@ -3839,13 +3856,13 @@ static ivas_error formulate_half_sphere_connections_fx( move16(); connections[*connection_write_index][1] = chB; move16(); - connection_arc_fx[*connection_write_index] = new_arc_fx; // Q29 + connection_arc_fx[*connection_write_index] = new_arc_fx; /* Q29 */ move16(); - connection_cross_fx[*connection_write_index][0] = new_cross_fx[0]; + connection_cross_fx[*connection_write_index][0] = new_cross_fx[0]; /* Q29 */ move16(); - connection_cross_fx[*connection_write_index][1] = new_cross_fx[1]; + connection_cross_fx[*connection_write_index][1] = new_cross_fx[1]; /* Q29 */ move16(); - connection_cross_fx[*connection_write_index][2] = new_cross_fx[2]; + connection_cross_fx[*connection_write_index][2] = new_cross_fx[2]; /* Q29 */ move16(); *connection_write_index = add( *connection_write_index, 1 ); } @@ -4013,15 +4030,15 @@ static ivas_error formulate_half_sphere_connections( #ifdef IVAS_FLOAT_FIXED static Word16 determine_non_crossing_planes_fx( - const Word16 num_speaker_nodes, /* i : number of speaker nodes */ - const VBAP_SPEAKER_NODE *node_data, /* i : speaker node data */ - Word32 *non_crossing_plane_elevation_deg_fx /* o : vector of non-crossing plane elevations */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes */ + const VBAP_SPEAKER_NODE *node_data, /* i : speaker node data */ + Word32 *non_crossing_plane_elevation_deg_fx /* o : vector of non-crossing plane elevations Q14 */ ) { - Word32 next_ele_check_fx; - Word32 ele_check_fx; - Word32 max_gap_fx; - Word32 gap_to_next_ls_fx; + Word32 next_ele_check_fx; /* Q14 */ + Word32 ele_check_fx; /* Q14 */ + Word32 max_gap_fx; /* Q14 */ + Word32 gap_to_next_ls_fx; /* Q14 */ Word16 ch, ch_cmp; Word16 num_planes; @@ -4046,7 +4063,7 @@ static Word16 determine_non_crossing_planes_fx( tmp2 = L_sub( next_ele_check_fx, 16 /*VBAP_EPSILON in Q14*/ ); test(); test(); - IF( ( node_data[ch].group != SPEAKER_NODE_HORIZONTAL ) && GT_32( L_shr( node_data[ch].ele_deg_fx, 8 ), tmp1 ) && LT_32( L_shr( node_data[ch].ele_deg_fx, 8 ), tmp2 ) ) + IF( NE_32( node_data[ch].group, SPEAKER_NODE_HORIZONTAL ) && GT_32( L_shr( node_data[ch].ele_deg_fx, 8 ), tmp1 ) && LT_32( L_shr( node_data[ch].ele_deg_fx, 8 ), tmp2 ) ) { next_ele_check_fx = L_shr( node_data[ch].ele_deg_fx, 8 ); // shift due to comparision with 90.0f } @@ -4098,7 +4115,7 @@ static Word16 determine_non_crossing_planes_fx( test(); IF( LT_32( max_gap_fx, 2293776 /*Q14*/ ) && max_gap_fx > 0 ) { - non_crossing_plane_elevation_deg_fx[num_planes] = ele_check_fx; // q14 + non_crossing_plane_elevation_deg_fx[num_planes] = ele_check_fx; /* Q14 */ move32(); num_planes = add( num_planes, 1 ); IF( EQ_16( num_planes, VBAP_MAX_PLANES ) ) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 4ddf64c89d5e9754273c6bb19877872372851bbc..90ac02ce1dcc9944e3f01d1b9319d0e03fe1dacc 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -133,7 +133,7 @@ typedef struct #ifndef IVAS_FLOAT_FIXED float gain; /* Linear, not in dB */ #else - Word32 gain_fx; /* Linear, not in dB */ + Word32 gain_fx; /* Linear, not in dB Q30 */ #endif rendering_context ctx; Word32 numNewSamplesPerChannel; /* Used to keep track how much new audio was fed before rendering current frame */ @@ -164,7 +164,7 @@ typedef struct rotation_matrix_fx rot_mat_prev_fx; #endif pan_vector prev_pan_gains; - int8_t firstFrameRendered; + Word8 firstFrameRendered; #ifndef IVAS_FLOAT_FIXED float *bufferData; #endif @@ -174,10 +174,10 @@ typedef struct float nonDiegeticPanGain; #endif #ifdef IVAS_FLOAT_FIXED - Word32 nonDiegeticPanGain_fx; + Word32 nonDiegeticPanGain_fx; /* Q31 */ #endif OMASA_ANA_HANDLE hOMasa; - uint16_t total_num_objects; + UWord16 total_num_objects; #ifdef IVAS_FLOAT_FIXED Word32 ism_metadata_delay_ms_fx; /* Q0 */ #else @@ -210,13 +210,13 @@ typedef struct Word16 numLfeChannels; bool pan_lfe; // float lfeInputGain; - Word32 lfeInputGain_fx; + Word32 lfeInputGain_fx; /* Q31 */ // float lfeOutputAzimuth; Word16 lfeOutputAzimuth_fx; // float lfeOutputElevation; Word16 lfeOutputElevation_fx; // IVAS_REND_LfePanMtx lfePanMtx; - IVAS_REND_LfePanMtx_fx lfePanMtx_fx; + IVAS_REND_LfePanMtx_fx lfePanMtx_fx; /* Q31 */ } lfe_routing; #else typedef struct @@ -236,16 +236,22 @@ typedef struct /* Full panning matrix. 1st index is input channel, 2nd index is output channel. All LFE channels should be included, both for inputs and outputs */ +#ifndef IVAS_FLOAT_FIXED pan_matrix panGains; - pan_matrix_fx panGains_fx; +#else + pan_matrix_fx panGains_fx; /* Q31 */ +#endif LSSETUP_CUSTOM_STRUCT customLsInput; EFAP_WRAPPER efapInWrapper; TDREND_WRAPPER tdRendWrapper; CREND_WRAPPER_HANDLE crendWrapper; REVERB_HANDLE hReverb; +#ifndef IVAS_FLOAT_FIXED rotation_gains rot_gains_prev; +#else rotation_gains_Word32 rot_gains_prev_fx; +#endif Word16 nonDiegeticPan; Word32 nonDiegeticPanGain_fx; lfe_routing lfeRouting; @@ -253,7 +259,7 @@ typedef struct #ifndef IVAS_FLOAT_FIXED float *bufferData; #endif - int16_t binauralDelaySmp; + Word16 binauralDelaySmp; #ifndef IVAS_FLOAT_FIXED float nonDiegeticPanGain; float *lfeDelayBuffer; @@ -292,12 +298,13 @@ typedef struct // pan_matrix hoaDecMtx; pan_matrix_fx hoaDecMtx_fx; CREND_WRAPPER_HANDLE crendWrapper; - rotation_gains rot_gains_prev; - rotation_gains_fx rot_gains_prev_fx; #ifndef IVAS_FLOAT_FIXED + rotation_gains rot_gains_prev; float *bufferData; -#endif +#else + rotation_gains_fx rot_gains_prev_fx; Word32 *bufferData_fx; +#endif DIRAC_ANA_HANDLE hDirAC; } input_sba; #else @@ -397,7 +404,7 @@ static void intermidiate_ext_dirac_render( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static ivas_error allocateInputBaseBufferData_fx( - Word32 **data, + Word32 **data, /* Qx */ const Word16 data_size ) { *data = (Word32 *) malloc( data_size * sizeof( Word32 ) ); @@ -424,7 +431,7 @@ static ivas_error allocateInputBaseBufferData( #endif #ifdef IVAS_FLOAT_FIXED static void freeInputBaseBufferData_fx( - Word32 **data ) + Word32 **data /* Qx */ ) { IF( *data != NULL ) { @@ -449,7 +456,7 @@ static void freeInputBaseBufferData( #endif #ifdef IVAS_FLOAT_FIXED static ivas_error allocateMcLfeDelayBuffer_fx( - Word32 **lfeDelayBuffer, + Word32 **lfeDelayBuffer, /* Qx */ const Word16 data_size ) { *lfeDelayBuffer = (Word32 *) malloc( data_size * sizeof( Word32 ) ); @@ -477,7 +484,7 @@ static ivas_error allocateMcLfeDelayBuffer( #endif #ifdef IVAS_FLOAT_FIXED static void freeMcLfeDelayBuffer_fx( - Word32 **lfeDelayBuffer ) + Word32 **lfeDelayBuffer /* Qx */ ) { IF( *lfeDelayBuffer != NULL ) { @@ -521,11 +528,6 @@ static IVAS_QUATERNION quaternionInit_fx( move16(); move16(); -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - q.w = 1.0f; - q.x = q.y = q.z = 0.0f; -#endif - return q; } #else @@ -651,7 +653,7 @@ static void accumulate2dArrayToBuffer( /*! r: number of clipped output samples */ static Word32 limitRendererOutput_fx( IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ - Word32 *output, /* i/o: I/O buffer */ + Word32 *output, /* i/o: I/O buffer Q(q_factor) */ const Word16 output_frame, /* i : number of samples per channel in the buffer */ const Word32 threshold, /* i : signal amplitude above which limiting starts to be applied */ Word16 q_factor ) /* i : q factor of output samples */ @@ -1208,7 +1210,7 @@ static LSSETUP_CUSTOM_STRUCT defaultCustomLs( #ifdef IVAS_FLOAT_FIXED static ivas_error getSpeakerAzimuths_fx( AUDIO_CONFIG config, - const Word32 **azimuths ) + const Word32 **azimuths /* Q22 */ ) { SWITCH( config ) { @@ -1279,7 +1281,7 @@ static ivas_error getSpeakerAzimuths( #ifdef IVAS_FLOAT_FIXED static ivas_error getSpeakerElevations_fx( AUDIO_CONFIG config, - const Word32 **elevations ) + const Word32 **elevations /* Q22 */ ) { SWITCH( config ) { @@ -1514,8 +1516,8 @@ static ivas_error getNumNonLfeChannelsInSpeakerLayout( static ivas_error getMcConfigValues_fx( AUDIO_CONFIG inConfig, const LSSETUP_CUSTOM_STRUCT *pInCustomLs, - const Word32 **azimuth, - const Word32 **elevation, + const Word32 **azimuth, /* Q22 */ + const Word32 **elevation, /* Q22 */ Word16 *lfe_idx, Word16 *is_planar ) { @@ -1666,8 +1668,8 @@ static ivas_error initEfap( const LSSETUP_CUSTOM_STRUCT *pCustomLsOut ) { ivas_error error; - const Word32 *azimuths; - const Word32 *elevations; + const Word32 *azimuths; /* Q22 */ + const Word32 *elevations; /* Q22 */ Word16 numNonLfeChannels; test(); @@ -1798,11 +1800,11 @@ static ivas_error initEfap( #ifdef IVAS_FLOAT_FIXED static ivas_error getEfapGains_fx( EFAP_WRAPPER efapWrapper, - const Word32 azi, - const Word32 ele, - pan_vector_fx panGains ) + const Word32 azi, /* Q22 */ + const Word32 ele, /* Q22 */ + pan_vector_fx panGains /* Q31 */ ) { - pan_vector_fx tmpPanGains; /* tmp pan gain buffer without LFE channels */ + pan_vector_fx tmpPanGains; /* tmp pan gain buffer without LFE channels */ /* Q30 */ Word32 *readPtr; Word16 i; Word16 lfeCount; @@ -1826,7 +1828,7 @@ static ivas_error getEfapGains_fx( { panGains[i] = 0; move32(); - ++lfeCount; + lfeCount = add( lfeCount, 1 ); } ELSE { @@ -1947,7 +1949,7 @@ static ivas_error initHeadRotation_fx( IVAS_REND_HANDLE hIvasRend ) { Word16 i, crossfade_len; - Word32 tmp_fx; + Word32 tmp_fx; /* Q31 */ ivas_error error; /* Head rotation is enabled by default */ @@ -2117,7 +2119,7 @@ static void initRotGainsWord32_fx( return; } -#endif +#else static void initRotGains( rotation_gains rot_gains ) { @@ -2132,6 +2134,7 @@ static void initRotGains( return; } +#endif #ifdef IVAS_FLOAT_FIXED static void initRendInputBase_fx( input_base *inputBase, @@ -2232,6 +2235,7 @@ static IVAS_ISM_METADATA defaultObjectPosition( } #endif // IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED static int8_t checkObjectPositionChanged( IVAS_ISM_METADATA *currentPos, IVAS_ISM_METADATA *previousPos ) @@ -2239,8 +2243,7 @@ static int8_t checkObjectPositionChanged( return !( fabs( currentPos->azimuth - previousPos->azimuth ) < EPSILON && fabs( currentPos->elevation - previousPos->elevation ) < EPSILON ); } - -#ifdef IVAS_FLOAT_FIXED +#else static Word8 checkObjectPositionChanged_fx( IVAS_ISM_METADATA *currentPos, IVAS_ISM_METADATA *previousPos ) @@ -2409,6 +2412,7 @@ static ivas_error setRendInputActiveIsm( initRendInputBase_fx( &inputIsm->base, inConfig, id, rendCtx, inputIsm->bufferData_fx, MAX_BUFFER_LENGTH ); inputIsm->firstFrameRendered = FALSE; + move16(); inputIsm->currentPos = defaultObjectPosition(); inputIsm->previousPos = defaultObjectPosition(); @@ -2662,7 +2666,7 @@ static void copyLsConversionMatrixToPanMatrix_fx( } ELSE { - panMatrix[inCh][outCh] = L_shl( lsConvMatrix[i].value, 1 ); + panMatrix[inCh][outCh] = L_shl( lsConvMatrix[i].value, 1 ); /* Q30 + Q1 = Q31 */ } move32(); } @@ -2670,7 +2674,6 @@ static void copyLsConversionMatrixToPanMatrix_fx( return; } #else - static void copyLsConversionMatrixToPanMatrix( const LS_CONVERSION_MATRIX *lsConvMatrix, pan_matrix panMatrix ) @@ -2695,6 +2698,8 @@ static void copyLsConversionMatrixToPanMatrix( return; } #endif + +#ifndef IVAS_FLOAT_FIXED static void setZeroPanMatrix( pan_matrix panMatrix ) { @@ -2707,7 +2712,7 @@ static void setZeroPanMatrix( return; } -#ifdef IVAS_FLOAT_FIXED +#else static void setZeroPanMatrix_fx( pan_matrix_fx panMatrix ) { @@ -2721,6 +2726,7 @@ static void setZeroPanMatrix_fx( return; } #endif + #ifdef IVAS_FLOAT_FIXED /* Note: this only sets non-zero elements, call setZeroPanMatrix() to init first. */ static void fillIdentityPanMatrix_fx( @@ -2850,7 +2856,7 @@ static ivas_error initMcPanGainsWithEfap_fx( Word16 i; Word16 numNonLfeInChannels; Word16 inLfeChIdx, outChIdx; - const Word32 *spkAzi, *spkEle; + const Word32 *spkAzi, *spkEle; /* Q22 */ ivas_error error; IF( NE_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) @@ -2895,14 +2901,14 @@ static ivas_error initMcPanGainsWithEfap_fx( { IF( EQ_16( i, inLfeChIdx ) ) { - ++outChIdx; + outChIdx = add( outChIdx, 1 ); } IF( NE_32( ( error = getEfapGains_fx( *inputMc->base.ctx.pEfapOutWrapper, spkAzi[i], spkEle[i], inputMc->panGains_fx[outChIdx] ) ), IVAS_ERR_OK ) ) { return error; } - ++outChIdx; + outChIdx = add( outChIdx, 1 ); } test(); @@ -3085,6 +3091,7 @@ static ivas_error initMcPanGainsWithMonoOut_fx( /* ls_conversion_cicpX_stereo contains gains for side speakers. * These should be skipped with 5.1+X inputs. */ skipSideSpeakers = false; + move16(); test(); if ( EQ_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_5_1_4 ) ) { @@ -3121,7 +3128,7 @@ static ivas_error initMcPanGainsWithMonoOut_fx( inputMc->panGains_fx[writeIdx][0] = L_shl( ls_conversion_cicpX_mono_fx[readIdx][0], 1 ); // Q31 } move32(); - ++readIdx; + readIdx = add( readIdx, 1 ); } } @@ -3198,9 +3205,9 @@ static ivas_error initMcPanGainsWithStereoLookup_fx( * Use gains for center CICP speaker and return early. */ IF( EQ_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_MONO ) ) { - inputMc->panGains_fx[0][0] = L_shl( ls_conversion_cicpX_stereo_fx[2][0], 1 ); // Q31 + inputMc->panGains_fx[0][0] = L_shl( ls_conversion_cicpX_stereo_fx[2][0], 1 ); /* Q30 + Q1 = Q31 */ move32(); - inputMc->panGains_fx[0][1] = L_shl( ls_conversion_cicpX_stereo_fx[2][1], 1 ); // Q31 + inputMc->panGains_fx[0][1] = L_shl( ls_conversion_cicpX_stereo_fx[2][1], 1 ); /* Q30 + Q1 = Q31 */ move32(); return IVAS_ERR_OK; } @@ -3237,7 +3244,7 @@ static ivas_error initMcPanGainsWithStereoLookup_fx( } ELSE { - inputMc->panGains_fx[writeIdx][0] = L_shl( ls_conversion_cicpX_stereo_fx[readIdx][0], 1 ); + inputMc->panGains_fx[writeIdx][0] = L_shl( ls_conversion_cicpX_stereo_fx[readIdx][0], 1 ); /* Q30 + Q1 = Q31 */ } move32(); @@ -3247,10 +3254,10 @@ static ivas_error initMcPanGainsWithStereoLookup_fx( } ELSE { - inputMc->panGains_fx[writeIdx][1] = L_shl( ls_conversion_cicpX_stereo_fx[readIdx][1], 1 ); + inputMc->panGains_fx[writeIdx][1] = L_shl( ls_conversion_cicpX_stereo_fx[readIdx][1], 1 ); /* Q30 + Q1 = Q31 */ } move32(); - ++readIdx; + readIdx = add( readIdx, 1 ); } return IVAS_ERR_OK; @@ -3449,7 +3456,7 @@ static ivas_error updateLfePanGainsForMcOut( } /* linear input gain */ - v_multc_fixed( inputMc->lfeRouting.lfePanMtx_fx[i], inputMc->lfeRouting.lfeInputGain_fx, inputMc->lfeRouting.lfePanMtx_fx[i], numOutChannels ); + v_multc_fixed( inputMc->lfeRouting.lfePanMtx_fx[i], inputMc->lfeRouting.lfeInputGain_fx, inputMc->lfeRouting.lfePanMtx_fx[i], numOutChannels ); /* Q31 */ } return error; @@ -3528,7 +3535,7 @@ static ivas_error updateLfePanGainsForAmbiOut( ivas_dirac_dec_get_response_fx( inputMc->lfeRouting.lfeOutputAzimuth_fx, inputMc->lfeRouting.lfeOutputElevation_fx, inputMc->lfeRouting.lfePanMtx_fx[i], outAmbiOrder, Q29 ); /* linear input gain */ - v_multc_fixed( inputMc->lfeRouting.lfePanMtx_fx[i], inputMc->lfeRouting.lfeInputGain_fx, inputMc->lfeRouting.lfePanMtx_fx[i], IVAS_MAX_OUTPUT_CHANNELS ); + v_multc_fixed( inputMc->lfeRouting.lfePanMtx_fx[i], inputMc->lfeRouting.lfeInputGain_fx, inputMc->lfeRouting.lfePanMtx_fx[i], IVAS_MAX_OUTPUT_CHANNELS ); /* Q31 */ } return error; @@ -3606,7 +3613,7 @@ static ivas_error updateMcPanGainsForMcOut( } ELSE { - inputMc->panGains_fx[0][0] = L_add( L_shr( inputMc->nonDiegeticPanGain_fx, 1 ), ONE_IN_Q30 ); + inputMc->panGains_fx[0][0] = L_add( L_shr( inputMc->nonDiegeticPanGain_fx, 1 ), ONE_IN_Q30 /* 0.5f in Q31 */ ); /* Q31 */ } move32(); inputMc->panGains_fx[0][1] = L_sub( ONE_IN_Q31, inputMc->panGains_fx[0][0] ); @@ -3713,7 +3720,7 @@ static ivas_error updateMcPanGainsForAmbiOut( { Word16 ch_in, ch_out, lfeIdx, i; Word16 numNonLfeInChannels, outAmbiOrder; - const Word32 *spkAzi_fx, *spkEle_fx; + const Word32 *spkAzi_fx, *spkEle_fx; /* Q22 */ ivas_error error; IF( NE_32( ( error = getAmbisonicsOrder_fx( outConfig, &outAmbiOrder ) ), IVAS_ERR_OK ) ) @@ -3768,11 +3775,11 @@ static ivas_error updateMcPanGainsForAmbiOut( } ELSE { - inputMc->panGains_fx[ch_out][i] = L_shl( temp, 2 ); + inputMc->panGains_fx[ch_out][i] = L_shl( temp, 2 ); /* Q29 + Q2 = Q31 */ move32(); } } - ++ch_in; + ch_in = add( ch_in, 1 ); } } ELSE @@ -3816,11 +3823,11 @@ static ivas_error updateMcPanGainsForAmbiOut( } ELSE { - inputMc->panGains_fx[ch_out][i] = L_shl( temp, 2 ); + inputMc->panGains_fx[ch_out][i] = L_shl( temp, 2 ); /* Q29 + Q2 = Q31 */ move32(); } } - ++ch_in; + ch_in = add( ch_in, 1 ); } } @@ -4053,11 +4060,13 @@ static ivas_error initMcBinauralRendering( IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && NE_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { useTDRend = TRUE; + move16(); } ELSE IF( ( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( inConfig, IVAS_AUDIO_CONFIG_7_1 ) ) && ( inputMc->base.ctx.pHeadRotData->headRotEnabled ) ) { useTDRend = TRUE; + move16(); } } @@ -4177,8 +4186,8 @@ static ivas_error initMcBinauralRendering( Word16 exp = 0; move16(); Word16 var1 = BASOP_Util_Divide3232_Scale( *inputMc->base.ctx.pOutSampleRate, 1000000000, &exp ); - Word32 var2 = L_shr_r( Mpy_32_32( binauralDelayNs, L_deposit_h( var1 ) ), negate( exp ) ); // 31 + exp - inputMc->binauralDelaySmp = (Word16) var2; + Word32 var2 = L_shr_r( Mpy_32_32( binauralDelayNs, L_deposit_h( var1 ) ), negate( exp ) ); /* Q0 */ + inputMc->binauralDelaySmp = extract_l( var2 ); move16(); // inputMc->binauralDelaySmp = (int16_t) roundf( (float) binauralDelayNs * *inputMc->base.ctx.pOutSampleRate / 1000000000.f ); @@ -4406,6 +4415,7 @@ static lfe_routing defaultLfeRouting( case IVAS_AUDIO_CONFIG_LS_CUSTOM: FOR( i = 0; i < routing.numLfeChannels && i < customLsOut.num_lfe; ++i ) { + test(); routing.lfePanMtx_fx[i][customLsOut.lfe_idx[i]] = ONE_IN_Q31; move32(); } @@ -4507,7 +4517,6 @@ static ivas_error setRendInputActiveMc( } initRendInputBase_fx( &inputMc->base, inConfig, id, rendCtx, inputMc->bufferData_fx, MAX_BUFFER_LENGTH ); - setZeroPanMatrix( inputMc->panGains ); setZeroPanMatrix_fx( inputMc->panGains_fx ); inputMc->customLsInput = defaultCustomLs(); @@ -4516,7 +4525,6 @@ static ivas_error setRendInputActiveMc( inputMc->hReverb = NULL; inputMc->hMcMasa = NULL; - initRotGains( inputMc->rot_gains_prev ); initRotGainsWord32_fx( inputMc->rot_gains_prev_fx ); inputMc->lfeRouting = defaultLfeRouting( inConfig, inputMc->customLsInput, outConfig, *inputMc->base.ctx.pCustomLsOut ); set32_fx( inputMc->lfeDelayBuffer_fx, 0, MAX_BIN_DELAY_SAMPLES ); @@ -4747,7 +4755,7 @@ static ivas_error initSbaPanGainsForMcOut( { CONTINUE; /* nothing to be rendered to LFE */ } - inputSba->hoaDecMtx_fx[chInIdx][chOutIdx] = L_shl_sat( *readPtr++, 2 ); + inputSba->hoaDecMtx_fx[chInIdx][chOutIdx] = L_shl_sat( *readPtr++, Q2 ); /* Q29 + Q2 = Q31 */ move32(); } } @@ -4876,7 +4884,6 @@ static ivas_error updateSbaPanGains( rendering_context rendCtx; /* Reset to all zeros - some functions below only write non-zero elements. */ - // setZeroPanMatrix( inputSba->hoaDecMtx ); setZeroPanMatrix_fx( inputSba->hoaDecMtx_fx ); inConfig = inputSba->base.inConfig; @@ -5269,7 +5276,7 @@ static ivas_error setRendInputActiveMasa( } initRendInputBase_fx( &inputMasa->base, inConfig, id, rendCtx, inputMasa->bufferData_fx, MAX_BUFFER_LENGTH ); - IF( ( error = getAudioConfigNumChannels( inConfig, &numInChannels ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = getAudioConfigNumChannels( inConfig, &numInChannels ) ), IVAS_ERR_OK ) ) { return error; } @@ -5288,7 +5295,7 @@ static ivas_error setRendInputActiveMasa( temp = 2; } move16(); - IF( ( error = masaPrerendOpen_fx( &inputMasa->hMasaPrerend, temp, *( inputMasa->base.ctx.pOutSampleRate ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = masaPrerendOpen_fx( &inputMasa->hMasaPrerend, temp, *( inputMasa->base.ctx.pOutSampleRate ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -5358,7 +5365,7 @@ ivas_error IVAS_REND_Open( const Word32 outputSampleRate, const AUDIO_CONFIG outConfig, const Word16 nonDiegeticPan, - const Word32 nonDiegeticPanGain, /*Q31*/ + const Word32 nonDiegeticPanGain, /* Q31 */ const Word16 num_subframes ) { Word16 i; @@ -5635,11 +5642,6 @@ static LSSETUP_CUSTOM_STRUCT makeCustomLsSetup( /* Copy layout description */ customLs.num_spk = rendCustomLsLayout.num_spk; move16(); - FOR( i = 0; i < rendCustomLsLayout.num_spk; i++ ) - { - customLs.ls_azimuth_fx[i] = (Word32) ( rendCustomLsLayout.azimuth[i] * ONE_IN_Q22 ); - customLs.ls_elevation_fx[i] = (Word32) ( rendCustomLsLayout.elevation[i] * ONE_IN_Q22 ); - } Copy32( rendCustomLsLayout.azimuth_fx, customLs.ls_azimuth_fx, rendCustomLsLayout.num_spk ); Copy32( rendCustomLsLayout.elevation_fx, customLs.ls_elevation_fx, rendCustomLsLayout.num_spk ); customLs.is_planar_setup = 1; @@ -6696,9 +6698,9 @@ ivas_error IVAS_REND_SetInputGain( } #else ivas_error IVAS_REND_SetInputGain_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const Word32 gain /* i : linear gain (not in dB) */ + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const Word32 gain /* i : linear gain (not in dB) Q30 */ ) { input_base *inputBase; @@ -6823,11 +6825,11 @@ ivas_error IVAS_REND_SetInputLfeMtx_fx( *-------------------------------------------------------------------*/ ivas_error IVAS_REND_SetInputLfePos_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const Word32 inputGain, /* i : Input gain to be applied to the LFE channel(s) */ - const Word16 outputAzimuth, /* i : Output azimuth position */ - const Word16 outputElevation /* i : Output elevation position */ + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const Word32 inputGain, /* i : Input gain to be applied to the LFE channel(s) Q31 */ + const Word16 outputAzimuth, /* i : Output azimuth position Q0 */ + const Word16 outputElevation /* i : Output elevation position Q0 */ ) { input_base *pInputBase; @@ -6854,11 +6856,11 @@ ivas_error IVAS_REND_SetInputLfePos_fx( pInputMc->lfeRouting.pan_lfe = true; move16(); - pInputMc->lfeRouting.lfeInputGain_fx = inputGain; // Q31 + pInputMc->lfeRouting.lfeInputGain_fx = inputGain; /* Q31 */ move32(); - pInputMc->lfeRouting.lfeOutputAzimuth_fx = (Word16) ( outputAzimuth ); // Q0 + pInputMc->lfeRouting.lfeOutputAzimuth_fx = outputAzimuth; /* Q0 */ move16(); - pInputMc->lfeRouting.lfeOutputElevation_fx = (Word16) ( outputElevation ); // Q0 + pInputMc->lfeRouting.lfeOutputElevation_fx = outputElevation; /* Q0 */ move16(); IF( NE_32( ( error = updateMcPanGains( pInputMc, hIvasRend->outputConfig ) ), IVAS_ERR_OK ) ) @@ -7160,6 +7162,13 @@ ivas_error IVAS_REND_GetDelay_fx( Word32 max_latency_ns; Word32 timescale_by_ns[7] = { 0, 17180, 34360, 0, 68719, 0, 103079 }; + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); /* Validate function arguments */ test(); @@ -7242,6 +7251,7 @@ ivas_error IVAS_REND_GetDelay_fx( IF( NE_32( hIvasRend->inputsMasa[i].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) { latency_ns = (Word32) ( IVAS_FB_DEC_DELAY_NS ); + move32(); max_latency_ns = L_max( max_latency_ns, latency_ns ); } } @@ -7508,7 +7518,9 @@ ivas_error IVAS_REND_FeedInputObjectMetadataToOMasa( /* Set position to OMasa struct */ hIvasRend->inputsIsm->hOMasa->ism_azimuth_fx[inputIndex] = objectPosition.azimuth_fx; + move32(); hIvasRend->inputsIsm->hOMasa->ism_elevation_fx[inputIndex] = objectPosition.elevation_fx; + move32(); return IVAS_ERR_OK; } @@ -7933,25 +7945,25 @@ ivas_error IVAS_REND_SetHeadRotation( rotQuat = headRot; } - Word32 updateRate_fx = 1677721600; // value is 200 in Q23 - rotQuat.w_fx = L_shl( rotQuat.w_fx, sub( Q29, rotQuat.q_fact ) ); - rotQuat.x_fx = L_shl( rotQuat.x_fx, sub( Q29, rotQuat.q_fact ) ); - rotQuat.y_fx = L_shl( rotQuat.y_fx, sub( Q29, rotQuat.q_fact ) ); - rotQuat.z_fx = L_shl( rotQuat.z_fx, sub( Q29, rotQuat.q_fact ) ); + Word32 updateRate_fx = 1677721600; // value is 200 in Q23 + rotQuat.w_fx = L_shl( rotQuat.w_fx, sub( Q29, rotQuat.q_fact ) ); /* Q29 */ + rotQuat.x_fx = L_shl( rotQuat.x_fx, sub( Q29, rotQuat.q_fact ) ); /* Q29 */ + rotQuat.y_fx = L_shl( rotQuat.y_fx, sub( Q29, rotQuat.q_fact ) ); /* Q29 */ + rotQuat.z_fx = L_shl( rotQuat.z_fx, sub( Q29, rotQuat.q_fact ) ); /* Q29 */ move32(); move32(); move32(); move32(); - hIvasRend->headRotData.hOrientationTracker->refRot.w_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.w_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ) ); - hIvasRend->headRotData.hOrientationTracker->refRot.x_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.x_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ); - hIvasRend->headRotData.hOrientationTracker->refRot.y_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.y_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ); - hIvasRend->headRotData.hOrientationTracker->refRot.z_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.z_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ); - hIvasRend->headRotData.hOrientationTracker->absAvgRot.w_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.w_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ); - hIvasRend->headRotData.hOrientationTracker->absAvgRot.x_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.x_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ); - hIvasRend->headRotData.hOrientationTracker->absAvgRot.y_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.y_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ); - hIvasRend->headRotData.hOrientationTracker->absAvgRot.z_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.z_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ); + hIvasRend->headRotData.hOrientationTracker->refRot.w_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.w_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->refRot.x_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.x_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->refRot.y_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.y_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->refRot.z_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.z_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->absAvgRot.w_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.w_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->absAvgRot.x_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.x_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->absAvgRot.y_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.y_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->absAvgRot.z_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.z_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ) ); /* Q29 */ move32(); move32(); @@ -8504,8 +8516,8 @@ static void renderBufferChannelLerp( static void renderBufferChannelLerp_fx( const IVAS_REND_AudioBuffer inAudio, const Word32 inChannelIdx, - const Word32 *const gainsCurrent, - const Word32 *const gainsPrev, + const Word32 *const gainsCurrent, /* Q31 */ + const Word32 *const gainsPrev, /* Q31 */ IVAS_REND_AudioBuffer outAudio ) { const Word32 *inSmpl; @@ -8515,8 +8527,8 @@ static void renderBufferChannelLerp_fx( Word32 i; const Word32 *lastInSmpl; Word16 outChnlIdx; - Word32 currentGain; - Word32 previousGain; + Word32 currentGain; /* Q31 */ + Word32 previousGain; /* Q31 */ /* Pointer to behind last input sample */ lastInSmpl = getSmplPtr_fx( inAudio, inChannelIdx, inAudio.config.numSamplesPerChannel ); @@ -8524,9 +8536,17 @@ static void renderBufferChannelLerp_fx( FOR( outChnlIdx = 0; outChnlIdx < outAudio.config.numChannels; ++outChnlIdx ) { currentGain = gainsCurrent[outChnlIdx]; - previousGain = gainsPrev == NULL ? 0 : gainsPrev[outChnlIdx]; - move32(); move32(); + if ( gainsPrev == NULL ) + { + previousGain = 0; + move32(); + } + else + { + previousGain = gainsPrev[outChnlIdx]; + move32(); + } /* Process current output channel only if applying non-zero gains */ test(); @@ -8621,7 +8641,7 @@ static void renderBufferChannelLerp_fx( static void renderBufferChannel_fx( const IVAS_REND_AudioBuffer inAudio, const Word32 inChannelIdx, - const Word32 *const outputGains, + const Word32 *const outputGains, /* Q31 */ IVAS_REND_AudioBuffer outAudio ) { renderBufferChannelLerp_fx( inAudio, inChannelIdx, outputGains, NULL, outAudio ); @@ -8656,7 +8676,7 @@ static ivas_error chooseCrossfade( #else static ivas_error chooseCrossfade_fx( const IVAS_REND_HeadRotData *headRotData, - const Word32 **pCrossfade ) + const Word32 **pCrossfade /* Q31 */ ) { *pCrossfade = headRotData->crossfade_fx; @@ -8679,10 +8699,10 @@ static ivas_error rotateFrameMc_fx( { Word16 i; Word16 j; - const Word32 *crossfade; + const Word32 *crossfade; /* Q31 */ Word16 num_subframes; Word16 subframe_idx, subframe_len; - Word32 azimuth_fx, elevation_fx; + Word32 azimuth_fx, elevation_fx; /* Q22 */ Word16 is_planar_setup, lfe_idx; Word16 nchan; Word16 ch_in, ch_out; @@ -8691,10 +8711,10 @@ static ivas_error rotateFrameMc_fx( const Word32 *ls_azimuth, *ls_elevation; rotation_matrix_fx Rmat_fx; rotation_gains_Word32 gains; - Word32 tmp_gains[MAX_INPUT_CHANNELS]; + Word32 tmp_gains[MAX_INPUT_CHANNELS]; /* Q30 */ ivas_error error; push_wmops( "rotateFrameMc_fx" ); - IF( NE_32( ( error = chooseCrossfade_fx( headRotData, &crossfade ) ), IVAS_ERR_OK ) ) // Q31 + IF( NE_32( ( error = chooseCrossfade_fx( headRotData, &crossfade ) ), IVAS_ERR_OK ) ) { return error; } @@ -8770,10 +8790,8 @@ static ivas_error rotateFrameMc_fx( } /* input channel index without LFE */ - ch_in_woLFE = ( ( GT_16( lfe_idx, 0 ) ) && ( GE_16( ch_in, lfe_idx ) ) ) ? sub( ch_in, 1 ) : ch_in; - test(); - IF( ( GT_16( lfe_idx, 0 ) ) && ( GE_16( ch_in, lfe_idx ) ) ) + IF( ( lfe_idx > 0 ) && ( GE_16( ch_in, lfe_idx ) ) ) { ch_in_woLFE = sub( ch_in, 1 ); } @@ -8824,14 +8842,14 @@ static ivas_error rotateFrameMc_fx( { FOR( ch_in = 0; ch_in < nchan; ch_in++ ) { - writePtr = getSmplPtr_fx( outAudio, ch_out, imult1616( subframe_idx, subframe_len ) ); - readPtr = getSmplPtr_fx( inAudio, ch_in, imult1616( subframe_idx, subframe_len ) ); + writePtr = getSmplPtr_fx( outAudio, ch_out, imult1616( subframe_idx, subframe_len ) ); /* Qx */ + readPtr = getSmplPtr_fx( inAudio, ch_in, imult1616( subframe_idx, subframe_len ) ); /* Qx */ /* crossfade with previous rotation gains */ FOR( i = 0; i < subframe_len; i++ ) { *writePtr = - L_add( *writePtr, L_add( Mpy_32_32( ( *readPtr ), Mpy_32_32( ( ONE_IN_Q31 - crossfade[i] ), gains_prev[ch_in][ch_out] ) ), - Mpy_32_32( ( *readPtr ), Mpy_32_32( crossfade[i], gains[ch_in][ch_out] ) ) ) ); // Qinp -1 + L_add( *writePtr, L_add( Mpy_32_32( ( *readPtr ), Mpy_32_32( L_sub( ONE_IN_Q31, crossfade[i] ), gains_prev[ch_in][ch_out] ) ), + Mpy_32_32( ( *readPtr ), Mpy_32_32( crossfade[i], gains[ch_in][ch_out] ) ) ) ); /* Qx - 1 */ move32(); readPtr++; writePtr++; @@ -8997,28 +9015,28 @@ static ivas_error rotateFrameMc( #ifdef IVAS_FLOAT_FIXED static ivas_error rotateFrameSba_fx( - IVAS_REND_AudioBuffer inAudio, /* i : Input Audio buffer */ - const AUDIO_CONFIG inConfig, /* i : Input Audio config */ - const IVAS_REND_HeadRotData *headRotData, /* i : Head rotation data */ + IVAS_REND_AudioBuffer inAudio, /* i : Input Audio buffer */ + const AUDIO_CONFIG inConfig, /* i : Input Audio config */ + const IVAS_REND_HeadRotData *headRotData, /* i : Head rotation data */ const COMBINED_ORIENTATION_HANDLE *hCombinedOrientationData, /* i : Combined head and external orientations */ - Word16 gains_prev[MAX_INPUT_CHANNELS][MAX_INPUT_CHANNELS], /* i/o: Previous frame rotation gains */ - IVAS_REND_AudioBuffer outAudio /* o : Output Audio buffer */ + Word16 gains_prev[MAX_INPUT_CHANNELS][MAX_INPUT_CHANNELS], /* i/o: Previous frame rotation gains Q14 */ + IVAS_REND_AudioBuffer outAudio /* o : Output Audio buffer */ ) { Word16 i, l, n, m; Word16 m1, m2; Word16 shd_rot_max_order; - const Word32 *crossfade; + const Word32 *crossfade; /* Q31 */ Word16 num_subframes; Word16 subframe_idx, subframe_len; Word32 *writePtr; Word32 tmpRot[2 * HEADROT_ORDER + 1]; - Word16 gains[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; + Word16 gains[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; /* Q14 */ Word32 temp; - Word32 Rmat[3][3]; + Word32 Rmat[3][3]; /* Q30 */ ivas_error error; Word16 idx, exp; - Word32 cf, oneminuscf; + Word32 cf, oneminuscf; /* Q31 */ Word32 val; push_wmops( "rotateFrameSba" ); @@ -9052,7 +9070,7 @@ static ivas_error rotateFrameSba_fx( { FOR( l = 0; l < 3; l++ ) { - Rmat[i][l] = ( *hCombinedOrientationData )->Rmat_fx[subframe_idx][i][l]; // Q30 + Rmat[i][l] = ( *hCombinedOrientationData )->Rmat_fx[subframe_idx][i][l]; /* Q30 */ move32(); } } @@ -9091,14 +9109,14 @@ static ivas_error rotateFrameSba_fx( /* compute mtx-vector product for this l */ FOR( n = m1; n < m2; n++ ) { - tmpRot[sub( n, m1 )] = 0; + tmpRot[n - m1] = 0; move32(); FOR( m = m1; m < m2; m++ ) { - val = inAudio.data_fx[add( imult1616( m, inAudio.config.numSamplesPerChannel ), idx )]; + val = inAudio.data_fx[m * inAudio.config.numSamplesPerChannel + idx]; /* crossfade with previous rotation gains */ temp = Mpy_32_32( L_add( Mpy_32_16_r( cf, gains[n][m] ), ( Mpy_32_16_r( oneminuscf, gains_prev[n][m] ) ) ), val ); - tmpRot[sub( n, m1 )] = L_add( L_shl( temp, 1 ), tmpRot[sub( n, m1 )] ); // Qexp + tmpRot[n - m1] = L_add( L_shl( temp, 1 ), tmpRot[n - m1] ); move32(); move32(); } @@ -9107,19 +9125,19 @@ static ivas_error rotateFrameSba_fx( FOR( n = m1; n < m2; n++ ) { writePtr = getSmplPtr_fx( outAudio, n, idx ); - ( *writePtr ) = tmpRot[sub( n, m1 )]; + ( *writePtr ) = tmpRot[n - m1]; move32(); } m1 = m2; move16(); - m2 = add( m2, 2 * ( l + 1 ) + 1 ); + m2 = add( m2, add( shl( add( l, 1 ), 1 ), 1 ) ); } } /* move SHrotmat to SHrotmat_prev */ FOR( i = 0; i < HEADROT_SHMAT_DIM; i++ ) { - Copy( gains[i], gains_prev[i], HEADROT_SHMAT_DIM ); // Q14 + Copy( gains[i], gains_prev[i], HEADROT_SHMAT_DIM ); } } pop_wmops(); @@ -9261,7 +9279,7 @@ static ivas_error renderIsmToBinaural( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpTDRendBuffer[i], L_FRAME48k, sub( 11, exp ) ); + Scale_sig32( tmpTDRendBuffer[i], L_FRAME48k, sub( Q11, exp ) ); /* Q11 */ } IF( NE_32( ( error = ivas_td_binaural_renderer_ext_fx( &ismInput->tdRendWrapper, ismInput->base.inConfig, NULL, ismInput->base.ctx.pCombinedOrientationData, &ismInput->currentPos, ismInput->hReverb, ism_md_subframe_update_ext, @@ -9273,7 +9291,7 @@ static ivas_error renderIsmToBinaural( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpTDRendBuffer[i], L_FRAME48k, negate( sub( 11, exp ) ) ); + Scale_sig32( tmpTDRendBuffer[i], L_FRAME48k, negate( sub( Q11, exp ) ) ); /* Q(exp) */ } IF( ismInput->hReverb != NULL ) @@ -9282,7 +9300,7 @@ static ivas_error renderIsmToBinaural( { FOR( Word16 j = 0; j < outAudio.config.numSamplesPerChannel; j++ ) { - tmpTDRendBuffer[i][j] = L_shl( tmpTDRendBuffer[i][j], 2 ); + tmpTDRendBuffer[i][j] = L_shl( tmpTDRendBuffer[i][j], Q2 ); /* Q(exp + 2) */ move32(); } } @@ -9333,9 +9351,9 @@ static Word16 getNumSubframesInBuffer( const IVAS_REND_AudioBuffer *buffer, const Word32 sampleRate ) { - Word16 scale, temp = extract_l( Mpy_32_32( sampleRate, 10737418 ) ); // Q0 + Q31 - Q31 -> Q0 + Word16 scale, temp = extract_l( Mpy_32_32( sampleRate, 10737418 /* 1 / FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES in Q31 */ ) ); temp = BASOP_Util_Divide1616_Scale( buffer->config.numSamplesPerChannel, temp, &scale ); - temp = shr( temp, sub( 15, scale ) ); + temp = shr( temp, sub( 15, scale ) ); /* Q0 */ return temp; } #else @@ -9358,7 +9376,7 @@ static ivas_error renderIsmToBinauralRoom( { Word16 position_changed; Word16 i, j; - Word32 azi_rot, ele_rot; + Word32 azi_rot, ele_rot; /* Q22 */ Word16 subframe_idx; Word16 tmp; rotation_matrix_fx Rmat; @@ -9389,7 +9407,6 @@ static ivas_error renderIsmToBinauralRoom( { FOR( subframe_idx = 0; subframe_idx < ( *hCombinedOrientationData )->num_subframes; subframe_idx++ ) { - IF( ( *hCombinedOrientationData )->enableCombinedOrientation[subframe_idx] != 0 ) { combinedOrientationEnabled = 1; @@ -9459,7 +9476,9 @@ static ivas_error renderIsmToBinauralRoom( move32(); } + test(); position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged_fx( &rotatedPos, &rotatedPosPrev ); + move16(); /* set previous gains if this is the first frame */ IF( NE_32( ( error = getEfapGains_fx( *ismInput->base.ctx.pEfapOutWrapper, rotatedPosPrev.azimuth_fx, rotatedPosPrev.elevation_fx, ismInput->prev_pan_gains_fx ) ), IVAS_ERR_OK ) ) @@ -9493,11 +9512,20 @@ static ivas_error renderIsmToBinauralRoom( tmpMcBuffer.data_fx = malloc( imult1616( tmpMcBuffer.config.numSamplesPerChannel, tmpMcBuffer.config.numChannels ) * sizeof( Word32 ) ); set_zero_fx( tmpMcBuffer.data_fx, imult1616( tmpMcBuffer.config.numSamplesPerChannel, tmpMcBuffer.config.numChannels ) ); - - renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, - position_changed ? currentPanGains : ismInput->prev_pan_gains_fx, - position_changed ? ismInput->prev_pan_gains_fx : NULL, - tmpMcBuffer ); + IF( position_changed ) + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + currentPanGains, + ismInput->prev_pan_gains_fx, + tmpMcBuffer ); + } + ELSE + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + ismInput->prev_pan_gains_fx, + NULL, + tmpMcBuffer ); + } copyBufferTo2dArray_fx( tmpMcBuffer, tmpRendBuffer ); @@ -9512,11 +9540,8 @@ static ivas_error renderIsmToBinauralRoom( Copy32( currentPanGains, ismInput->prev_pan_gains_fx, MAX_OUTPUT_CHANNELS ); } // Crend_process porting - move16(); CREND_HANDLE hCrend; hCrend = ismInput->crendWrapper->hCrend; - move16(); - move16(); IF( hCrend->reflections != NULL ) { test(); @@ -9524,7 +9549,7 @@ static ivas_error renderIsmToBinauralRoom( { FOR( i = 0; i < 150; i++ ) { - hCrend->reflections->shoebox_data.gains.data_fx[i] = L_shl( hCrend->reflections->shoebox_data.gains.data_fx[i], 9 ); + hCrend->reflections->shoebox_data.gains.data_fx[i] = L_shl( hCrend->reflections->shoebox_data.gains.data_fx[i], Q9 ); move32(); } } @@ -9735,7 +9760,7 @@ static ivas_error renderIsmToBinauralReverb( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, sub( 11, exp ) ); + Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, sub( Q11, exp ) ); /* Q11 */ } IF( NE_32( ( error = ivas_td_binaural_renderer_ext_fx( &ismInput->tdRendWrapper, ismInput->base.inConfig, NULL, ismInput->base.ctx.pCombinedOrientationData, &ismInput->currentPos, ismInput->hReverb, ism_md_subframe_update_ext, *ismInput->base.ctx.pOutSampleRate, outAudio.config.numSamplesPerChannel, tmpRendBuffer_fx, &exp ) ), IVAS_ERR_OK ) ) @@ -9745,7 +9770,7 @@ static ivas_error renderIsmToBinauralReverb( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, negate( sub( 11, exp ) ) ); + Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, negate( sub( 11, exp ) ) ); /* Q(exp) */ } IF( ismInput->hReverb != NULL ) @@ -9754,7 +9779,7 @@ static ivas_error renderIsmToBinauralReverb( { FOR( Word16 j = 0; j < outAudio.config.numSamplesPerChannel; j++ ) { - tmpRendBuffer_fx[i][j] = L_shl( tmpRendBuffer_fx[i][j], 2 ); + tmpRendBuffer_fx[i][j] = L_shl( tmpRendBuffer_fx[i][j], 2 ); /* Q(exp + 2) */ move16(); } } @@ -9799,26 +9824,31 @@ static ivas_error renderIsmToMc( const IVAS_REND_AudioBuffer outAudio ) { Word8 position_changed; - pan_vector_fx currentPanGains_fx; + pan_vector_fx currentPanGains_fx; /* Q31 */ ivas_error error; push_wmops( "renderIsmToMc" ); ismInput->currentPos.azimuth_fx = L_shl( L_shr( L_add( ismInput->currentPos.azimuth_fx, ONE_IN_Q21 ), Q22 ), Q22 ); + move32(); ismInput->currentPos.elevation_fx = L_shl( L_shr( L_add( ismInput->currentPos.elevation_fx, ONE_IN_Q21 ), Q22 ), Q22 ); + move32(); ismInput->previousPos.azimuth_fx = L_shl( L_shr( L_add( ismInput->previousPos.azimuth_fx, ONE_IN_Q21 ), Q22 ), Q22 ); + move32(); ismInput->previousPos.elevation_fx = L_shl( L_shr( L_add( ismInput->previousPos.elevation_fx, ONE_IN_Q21 ), Q22 ), Q22 ); + move32(); - position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged( &ismInput->currentPos, &ismInput->previousPos ); test(); + position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged_fx( &ismInput->currentPos, &ismInput->previousPos ); + move16(); IF( EQ_32( *ismInput->base.ctx.pOutConfig, IVAS_AUDIO_CONFIG_STEREO ) ) { IF( ismInput->nonDiegeticPan ) { - currentPanGains_fx[0] = L_add( L_shr( ismInput->nonDiegeticPanGain_fx, 1 ), ONE_IN_Q30 ); - currentPanGains_fx[1] = L_sub( ONE_IN_Q31, currentPanGains_fx[0] ); - ismInput->prev_pan_gains_fx[0] = currentPanGains_fx[0]; // Q31 - ismInput->prev_pan_gains_fx[1] = currentPanGains_fx[1]; // Q31 + currentPanGains_fx[0] = L_add( L_shr( ismInput->nonDiegeticPanGain_fx, 1 ), ONE_IN_Q30 ); /* Q31 */ + currentPanGains_fx[1] = L_sub( ONE_IN_Q31, currentPanGains_fx[0] ); /* Q31 */ + ismInput->prev_pan_gains_fx[0] = currentPanGains_fx[0]; /* Q31 */ + ismInput->prev_pan_gains_fx[1] = currentPanGains_fx[1]; /* Q31 */ move32(); move32(); move32(); @@ -9835,8 +9865,8 @@ static ivas_error renderIsmToMc( elevation_tmp = extract_l( L_shr( ismInput->currentPos.elevation_fx, Q22 ) ); ivas_ism_get_stereo_gains_fx( azimuth_tmp, elevation_tmp, &gains_fx[0], &gains_fx[1] ); - currentPanGains_fx[0] = L_deposit_h( gains_fx[0] ); // Q31 - currentPanGains_fx[1] = L_deposit_h( gains_fx[1] ); // Q31 + currentPanGains_fx[0] = L_deposit_h( gains_fx[0] ); /* Q31 */ + currentPanGains_fx[1] = L_deposit_h( gains_fx[1] ); /* Q31 */ move32(); move32(); @@ -9845,8 +9875,8 @@ static ivas_error renderIsmToMc( set32_fx( ismInput->prev_pan_gains_fx, 0, MAX_OUTPUT_CHANNELS ); ivas_ism_get_stereo_gains_fx( azimuth_tmp, elevation_tmp, &gains_fx[0], &gains_fx[1] ); - ismInput->prev_pan_gains_fx[0] = L_deposit_h( gains_fx[0] ); // Q31 - ismInput->prev_pan_gains_fx[1] = L_deposit_h( gains_fx[1] ); // Q31 + ismInput->prev_pan_gains_fx[0] = L_deposit_h( gains_fx[0] ); /* Q31 */ + ismInput->prev_pan_gains_fx[1] = L_deposit_h( gains_fx[1] ); /* Q31 */ move32(); move32(); } @@ -9885,10 +9915,20 @@ static ivas_error renderIsmToMc( /* Assume num channels in audio buffer to be 1. * This should have been validated in IVAS_REND_FeedInputAudio() */ - renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, - position_changed ? currentPanGains_fx : ismInput->prev_pan_gains_fx, - position_changed ? ismInput->prev_pan_gains_fx : NULL, - outAudio ); + IF( position_changed ) + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + currentPanGains_fx, + ismInput->prev_pan_gains_fx, + outAudio ); + } + ELSE + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + ismInput->prev_pan_gains_fx, + NULL, + outAudio ); + } IF( position_changed ) { @@ -9989,6 +10029,7 @@ static ivas_error renderIsmToSba( pan_vector_fx currentPanGains_fx; ivas_error error; error = IVAS_ERR_OK; + move32(); ismInput->currentPos.azimuth_fx = L_shl( L_shr( L_add( ismInput->currentPos.azimuth_fx, ONE_IN_Q21 ), Q22 ), Q22 ); ismInput->currentPos.elevation_fx = L_shl( L_shr( L_add( ismInput->currentPos.elevation_fx, ONE_IN_Q21 ), Q22 ), Q22 ); @@ -10011,8 +10052,9 @@ static ivas_error renderIsmToSba( return error; } - position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged( &ismInput->currentPos, &ismInput->previousPos ); test(); + position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged_fx( &ismInput->currentPos, &ismInput->previousPos ); + move16(); /* set previous gains if this is the first frame */ Word16 azimuth_tmp, elevation_tmp; @@ -10028,7 +10070,7 @@ static ivas_error renderIsmToSba( Q29 ); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - ismInput->prev_pan_gains_fx[i] = L_shl_sat( ismInput->prev_pan_gains_fx[i], Q2 ); + ismInput->prev_pan_gains_fx[i] = L_shl_sat( ismInput->prev_pan_gains_fx[i], Q2 ); /* Q29 + Q2 = Q31 */ move32(); } } @@ -10046,22 +10088,31 @@ static ivas_error renderIsmToSba( Q29 ); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - currentPanGains_fx[i] = L_shl_sat( currentPanGains_fx[i], Q2 ); + currentPanGains_fx[i] = L_shl_sat( currentPanGains_fx[i], Q2 ); /* Q29 + Q2 = Q31 */ move32(); } } /* Assume num channels in audio buffer to be 1. * This should have been validated in IVAS_REND_FeedInputAudio() */ - renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, - position_changed ? currentPanGains_fx : ismInput->prev_pan_gains_fx, - position_changed ? ismInput->prev_pan_gains_fx : NULL, - outAudio ); + IF( position_changed ) + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + currentPanGains_fx, + ismInput->prev_pan_gains_fx, + outAudio ); + } + ELSE + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + ismInput->prev_pan_gains_fx, + NULL, + outAudio ); + } IF( position_changed ) { Copy32( currentPanGains_fx, ismInput->prev_pan_gains_fx, MAX_OUTPUT_CHANNELS ); - // mvr2r( currentPanGains, ismInput->prev_pan_gains, MAX_OUTPUT_CHANNELS ); } pop_wmops(); @@ -10158,16 +10209,18 @@ static void renderIsmToMasa( FOR( i = 1; i < MAX_NUM_OBJECTS; i++ ) { - IF( LT_16( max_e, input_e[0] ) ) - max_e = input_e[i]; - move16(); + if ( LT_16( max_e, input_e[0] ) ) + { + max_e = input_e[i]; + move16(); + } } FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) { FOR( j = 0; j < L_FRAME48k; j++ ) { - tmpRendBuffer_fx[i][j] = L_shr( tmpRendBuffer_fx[i][j], add( sub( max_e, sub( 31, *outAudio.pq_fact ) ), guard_bits ) ); + tmpRendBuffer_fx[i][j] = L_shr( tmpRendBuffer_fx[i][j], add( sub( max_e, sub( 31, *outAudio.pq_fact ) ), guard_bits ) ); /* Q(31 - (max_e + guard_bits)) */ move32(); } } @@ -10232,10 +10285,10 @@ static ivas_error renderInputIsm( /* Apply input gain to new audio */ v_multc_fixed( inAudio.data_fx, ismInput->base.gain_fx, inAudio.data_fx, imult1616( inAudio.config.numSamplesPerChannel, inAudio.config.numChannels ) ); *outAudio.pq_fact = sub( *outAudio.pq_fact, Q1 ); - exp = *outAudio.pq_fact; - move16(); + exp = *outAudio.pq_fact; move16(); + /* set combined orientation subframe info to start info */ ivas_combined_orientation_set_to_start_index( *ismInput->base.ctx.pCombinedOrientationData ); @@ -10283,11 +10336,11 @@ static ivas_error renderInputIsm( } ismInput->firstFrameRendered = TRUE; + move16(); *outAudio.pq_fact = exp; - - move16(); move16(); + return error; } #else @@ -10382,7 +10435,7 @@ static ivas_error renderActiveInputsIsm( } FOR( Word16 j = 0; j < outAudio.config.numSamplesPerChannel * outAudio.config.numChannels; ++j ) { - outAudio.data_fx[j] = L_shl( outAudio.data_fx[j], sub( sub( input_q, 1 ), ( *outAudio.pq_fact ) ) ); + outAudio.data_fx[j] = L_shl( outAudio.data_fx[j], sub( sub( input_q, 1 ), ( *outAudio.pq_fact ) ) ); /* Q(input_q - 1) */ move32(); } *outAudio.pq_fact = sub( input_q, 1 ); @@ -10434,7 +10487,7 @@ static ivas_error renderLfeToBinaural_fx( assert( ( outAudio.config.numChannels == 2 ) && "Must be binaural output" ); push_wmops( "renderLfeToBinaural" ); - gain_fx = GAIN_LFE_WORD32; + gain_fx = GAIN_LFE_WORD32; /* 1.88364911f in Q30 */ move32(); IF( NE_32( mcInput->base.inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) @@ -10455,7 +10508,6 @@ static ivas_error renderLfeToBinaural_fx( /* --- Prepare LFE signal to be added to binaural output --- */ lfeInput = getSmplPtr_fx( mcInput->base.inputBuffer, lfe_idx, 0 ); - move32(); frame_size = mcInput->base.inputBuffer.config.numSamplesPerChannel; move16(); num_cpy_smpl_prev_frame = mcInput->binauralDelaySmp; @@ -10466,10 +10518,10 @@ static ivas_error renderLfeToBinaural_fx( assert( mcInput->binauralDelaySmp < frame_size ); /* Get delayed LFE signal from previous frame, apply gain and save in tmp buffer */ - v_multc_fixed( mcInput->lfeDelayBuffer_fx, gain_fx, tmpLfeBuffer, num_cpy_smpl_prev_frame ); // Qinp-1 + v_multc_fixed( mcInput->lfeDelayBuffer_fx, gain_fx, tmpLfeBuffer, num_cpy_smpl_prev_frame ); /* Qx - 1 */ /* Continue filling tmp buffer, now with LFE signal from current frame */ - v_multc_fixed( lfeInput, gain_fx, tmpLfeBuffer + num_cpy_smpl_prev_frame, num_cpy_smpl_cur_frame ); // Qinp-1 + v_multc_fixed( lfeInput, gain_fx, tmpLfeBuffer + num_cpy_smpl_prev_frame, num_cpy_smpl_cur_frame ); /* Qx - 1 */ /* Save remaining LFE samples of current frame for next frame */ MVR2R_WORD32( lfeInput + num_cpy_smpl_cur_frame, mcInput->lfeDelayBuffer_fx, num_cpy_smpl_prev_frame ); @@ -10479,8 +10531,7 @@ static ivas_error renderLfeToBinaural_fx( { FOR( i = 0; i < add( num_cpy_smpl_prev_frame, num_cpy_smpl_cur_frame ); i++ ) { - tmpLfeBuffer[i] = L_shr( tmpLfeBuffer[i], r_shift ); // out_q - + tmpLfeBuffer[i] = L_shr( tmpLfeBuffer[i], r_shift ); /* Q(out_q) */ move32(); } } @@ -10489,7 +10540,7 @@ static ivas_error renderLfeToBinaural_fx( { writePtr = getSmplPtr_fx( outAudio, ear_idx, 0 ); move32(); - v_add_fixed( writePtr, tmpLfeBuffer, writePtr, frame_size, 0 ); // out_q + v_add_fixed( writePtr, tmpLfeBuffer, writePtr, frame_size, 0 ); /* Q(out_q) */ } pop_wmops(); @@ -10608,7 +10659,7 @@ static ivas_error renderMcToBinaural( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, sub( 11, exp ) ); + Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, sub( Q11, exp ) ); /* Q11 */ } IF( NE_32( ( error = ivas_td_binaural_renderer_ext_fx( &mcInput->tdRendWrapper, mcInput->base.inConfig, &mcInput->customLsInput, mcInput->base.ctx.pCombinedOrientationData, NULL, mcInput->hReverb, 0, *mcInput->base.ctx.pOutSampleRate, mcInput->base.inputBuffer.config.numSamplesPerChannel, tmpRendBuffer_fx, &exp ) ), @@ -10619,7 +10670,7 @@ static ivas_error renderMcToBinaural( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, -sub( Q11, exp ) ); + Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, negate( sub( Q11, exp ) ) ); /* Q(exp) */ } } ELSE @@ -10791,9 +10842,8 @@ static ivas_error renderMcToBinauralRoom( inConfig = mcInput->base.inConfig; move32(); hCombinedOrientationData = mcInput->base.ctx.pCombinedOrientationData; - move32(); combinedOrientationEnabled = 0; - move32(); + move16(); IF( hCombinedOrientationData != NULL ) { FOR( subframe_idx = 0; subframe_idx < ( *hCombinedOrientationData )->num_subframes; subframe_idx++ ) @@ -10818,7 +10868,7 @@ static ivas_error renderMcToBinauralRoom( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpRendBuffer[i], L_FRAME48k, sub( Q11, exp ) ); + Scale_sig32( tmpRendBuffer[i], L_FRAME48k, sub( Q11, exp ) ); /* Q11 */ } IF( NE_32( ( error = ivas_td_binaural_renderer_ext_fx( &mcInput->tdRendWrapper, mcInput->base.inConfig, &mcInput->customLsInput, mcInput->base.ctx.pCombinedOrientationData, NULL, mcInput->hReverb, @@ -10830,9 +10880,8 @@ static ivas_error renderMcToBinauralRoom( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpRendBuffer[i], L_FRAME48k, -sub( Q11, exp ) ); + Scale_sig32( tmpRendBuffer[i], L_FRAME48k, negate( sub( Q11, exp ) ) ); /* Q(exp) */ } - //*outAudio.pq_fact = exp; } ELSE { @@ -11273,28 +11322,35 @@ static void renderMcToSba( } #endif +#ifdef IVAS_FLOAT_FIXED static void renderMcToMasa( input_mc *mcInput, IVAS_REND_AudioBuffer outAudio ) { -#ifdef IVAS_FLOAT_FIXED push_wmops( "renderMcToMasa" ); Word32 tmpRendBuffer_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; copyBufferTo2dArray_fx( mcInput->base.inputBuffer, tmpRendBuffer_fx ); ivas_mcmasa_ana_fx( mcInput->hMcMasa, tmpRendBuffer_fx, *( outAudio.pq_fact ), mcInput->base.inputBuffer.config.numSamplesPerChannel, outAudio.config.numChannels, mcInput->base.inputBuffer.config.numChannels ); accumulate2dArrayToBuffer_fx( tmpRendBuffer_fx, &outAudio ); + pop_wmops(); + return; +} #else +static void renderMcToMasa( + input_mc *mcInput, + IVAS_REND_AudioBuffer outAudio ) +{ push_wmops( "renderMcToMasa" ); float tmpRendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; copyBufferTo2dArray( mcInput->base.inputBuffer, tmpRendBuffer ); ivas_mcmasa_ana( mcInput->hMcMasa, tmpRendBuffer, mcInput->base.inputBuffer.config.numSamplesPerChannel, outAudio.config.numChannels, mcInput->base.inputBuffer.config.numChannels ); accumulate2dArrayToBuffer( tmpRendBuffer, &outAudio ); -#endif // IVAS_FLOAT_FIXED pop_wmops(); return; } +#endif #ifdef IVAS_FLOAT_FIXED static ivas_error renderInputMc( @@ -11317,6 +11373,7 @@ static ivas_error renderInputMc( move32(); v_multc_fixed( inAudio.data_fx, mcInput->base.gain_fx, inAudio.data_fx, inAudio.config.numSamplesPerChannel * inAudio.config.numChannels ); *outAudio.pq_fact = sub( *outAudio.pq_fact, Q1 ); // reducing the Q by 1 compensating for the v_mult_fixed done + move16(); /* set combined orientation subframe info to start info */ ivas_combined_orientation_set_to_start_index( *( mcInput->base.ctx.pCombinedOrientationData ) ); @@ -11595,7 +11652,7 @@ static ivas_error renderSbaToBinaural( tmpRotBuffer.data_fx = malloc( tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels * sizeof( Word32 ) ); /* copy input for in-place rotation */ - MVR2R_WORD32( sbaInput->base.inputBuffer.data_fx, tmpRotBuffer.data_fx, tmpRotBuffer.config.numChannels * tmpRotBuffer.config.numSamplesPerChannel ); + Copy32( sbaInput->base.inputBuffer.data_fx, tmpRotBuffer.data_fx, i_mult( tmpRotBuffer.config.numChannels, tmpRotBuffer.config.numSamplesPerChannel ) ); IF( NE_16( ( error = rotateFrameSba_fx( sbaInput->base.inputBuffer, sbaInput->base.inConfig, sbaInput->base.ctx.pHeadRotData, sbaInput->base.ctx.pCombinedOrientationData, sbaInput->rot_gains_prev_fx, tmpRotBuffer ) ), @@ -11765,7 +11822,7 @@ static ivas_error renderSbaToBinauralRoom( tmpRotBuffer.data_fx = malloc( imult1616( tmpRotBuffer.config.numSamplesPerChannel, tmpRotBuffer.config.numChannels ) * sizeof( Word32 ) ); /* copy input for in-place rotation */ - MVR2R_WORD32( sbaInput->base.inputBuffer.data_fx, tmpRotBuffer.data_fx, tmpRotBuffer.config.numChannels * tmpRotBuffer.config.numSamplesPerChannel ); + Copy32( sbaInput->base.inputBuffer.data_fx, tmpRotBuffer.data_fx, i_mult( tmpRotBuffer.config.numChannels, tmpRotBuffer.config.numSamplesPerChannel ) ); IF( NE_32( ( error = rotateFrameSba_fx( sbaInput->base.inputBuffer, sbaInput->base.inConfig, sbaInput->base.ctx.pHeadRotData, sbaInput->base.ctx.pCombinedOrientationData, @@ -11788,7 +11845,7 @@ static ivas_error renderSbaToBinauralRoom( tmpMcBuffer.config.numChannels = tmp; move16(); tmpMcBuffer.data_fx = malloc( tmpMcBuffer.config.numSamplesPerChannel * tmpMcBuffer.config.numChannels * sizeof( Word32 ) ); - set32_fx( tmpMcBuffer.data_fx, 0, tmpMcBuffer.config.numChannels * tmpMcBuffer.config.numSamplesPerChannel ); + set32_fx( tmpMcBuffer.data_fx, 0, i_mult( tmpMcBuffer.config.numChannels, tmpMcBuffer.config.numSamplesPerChannel ) ); IF( combinedOrientationEnabled ) { @@ -11980,7 +12037,7 @@ static ivas_error renderInputSba( *outAudio.pq_fact = outAudio.q_factor; move16(); /* Apply input gain to new audio */ - v_multc_fixed( inAudio.data_fx, sbaInput->base.gain_fx, inAudio.data_fx, inAudio.config.numSamplesPerChannel * inAudio.config.numChannels ); + v_multc_fixed( inAudio.data_fx, sbaInput->base.gain_fx, inAudio.data_fx, i_mult( inAudio.config.numSamplesPerChannel, inAudio.config.numChannels ) ); *outAudio.pq_fact = sub( *outAudio.pq_fact, 1 ); // to compensate for the qfactor reduction in gain multiplication. move16(); @@ -12149,9 +12206,9 @@ static void copyMasaMetadataToDiracRenderer_fx( { FOR( bin = MASA_band_grouping_24[band]; bin < MASA_band_grouping_24[band + 1] && bin < maxBin; bin++ ) { - hSpatParamRendCom->azimuth[meta_write_index][bin] = (Word16) meta->directional_meta[0].azimuth[sf][band]; + hSpatParamRendCom->azimuth[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[0].azimuth_fx[sf][band], Q22 ) ); /* Q22 - Q22 = Q0 */ move16(); - hSpatParamRendCom->elevation[meta_write_index][bin] = (Word16) meta->directional_meta[0].elevation[sf][band]; + hSpatParamRendCom->elevation[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[0].elevation_fx[sf][band], Q22 ) ); /* Q22 - Q22 = Q0 */ move16(); hSpatParamRendCom->energy_ratio1_fx[meta_write_index][bin] = meta->directional_meta[0].energy_ratio_fx[sf][band]; move32(); @@ -12164,9 +12221,9 @@ static void copyMasaMetadataToDiracRenderer_fx( IF( EQ_16( hSpatParamRendCom->numSimultaneousDirections, 2 ) ) { - hSpatParamRendCom->azimuth2[meta_write_index][bin] = (Word16) meta->directional_meta[1].azimuth[sf][band]; + hSpatParamRendCom->azimuth2[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[1].azimuth_fx[sf][band], Q22 ) ); /* Q22 - Q22 = Q0 */ move16(); - hSpatParamRendCom->elevation2[meta_write_index][bin] = (Word16) meta->directional_meta[1].elevation[sf][band]; + hSpatParamRendCom->elevation2[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[1].elevation_fx[sf][band], Q22 ) ); /* Q22 - Q22 = Q0 */ move16(); hSpatParamRendCom->energy_ratio2_fx[meta_write_index][bin] = meta->directional_meta[1].energy_ratio_fx[sf][band]; move32(); @@ -12179,7 +12236,7 @@ static void copyMasaMetadataToDiracRenderer_fx( } } - hSpatParamRendCom->dirac_bs_md_write_idx = ( hSpatParamRendCom->dirac_bs_md_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; + hSpatParamRendCom->dirac_bs_md_write_idx = add( hSpatParamRendCom->dirac_bs_md_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; move16(); return; @@ -12236,7 +12293,7 @@ static void renderMasaToMasa( IVAS_REND_AudioBuffer outAudio ) { Word16 sf, band, dir, numDirs; - Word32 ratioSum_fx; + Word32 ratioSum_fx; /* Q30 */ MASA_DECODER_EXT_OUT_META_HANDLE outMeta; MASA_METADATA_FRAME *inMeta; Word32 tmpBuffer_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; @@ -12256,7 +12313,8 @@ static void renderMasaToMasa( move16(); move16(); /* Calculate energy */ - l_ts = masaInput->base.inputBuffer.config.numSamplesPerChannel / CLDFB_NO_COL_MAX; + // l_ts = masaInput->base.inputBuffer.config.numSamplesPerChannel / CLDFB_NO_COL_MAX; + l_ts = shr( masaInput->base.inputBuffer.config.numSamplesPerChannel, 4 ); numAnalysisChannels = masaInput->hMasaPrerend->num_Cldfb_instances; move16(); /* do processing over all CLDFB time slots */ @@ -12282,8 +12340,8 @@ static void renderMasaToMasa( cldfbAnalysis_ts_fx_fixed_q( &( tmpBuffer_fx[i][l_ts * ts] ), Chan_RealBuffer_fx[i], Chan_ImagBuffer_fx[i], l_ts, masaInput->hMasaPrerend->cldfbAnaEnc[i], &q_cldfb_out ); scale_factor = s_min( scale_factor, s_min( getScaleFactor32( Chan_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ), getScaleFactor32( Chan_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ) ); scale_factor = sub( scale_factor, 1 ); - scale_sig32( Chan_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, scale_factor ); // Q17 - scale_sig32( Chan_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, scale_factor ); // Q17 + scale_sig32( Chan_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, scale_factor ); /* Q(q_cldfb_out + scale_factor) */ + scale_sig32( Chan_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, scale_factor ); /* Q(q_cldfb_out + scale_factor) */ } Word16 q_add = sub( 31, add( scale_factor, q_cldfb_out ) ); @@ -12298,8 +12356,8 @@ static void renderMasaToMasa( { FOR( i = 0; i < numAnalysisChannels; i++ ) { - Word32 temp = L_add( Mult_32_32( Chan_RealBuffer_fx[0][j], Chan_RealBuffer_fx[0][j] ), Mult_32_32( Chan_ImagBuffer_fx[0][j], Chan_ImagBuffer_fx[0][j] ) ); - masaInput->hMasaPrerend->energy_fx[block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( masaInput->hMasaPrerend->energy_fx[block_m_idx][band_m_idx], tmp_energy_e[block_m_idx][band_m_idx], temp, ( 2 * q_add ), &tmp_energy_e[block_m_idx][band_m_idx] ); + Word32 temp = L_add( Mpy_32_32( Chan_RealBuffer_fx[0][j], Chan_RealBuffer_fx[0][j] ), Mpy_32_32( Chan_ImagBuffer_fx[0][j], Chan_ImagBuffer_fx[0][j] ) ); /* 2 * Q(q_cldfb_out + scale_factor) - 31 */ + masaInput->hMasaPrerend->energy_fx[block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( masaInput->hMasaPrerend->energy_fx[block_m_idx][band_m_idx], tmp_energy_e[block_m_idx][band_m_idx], temp, shl( q_add, 1 ), &tmp_energy_e[block_m_idx][band_m_idx] ); move32(); } } @@ -12312,7 +12370,6 @@ static void renderMasaToMasa( move16(); FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - max_e = s_max( max_e, tmp_energy_e[i][j] ); } masaInput->hMasaPrerend->energy_e[i] = max_e; @@ -12320,7 +12377,7 @@ static void renderMasaToMasa( FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - masaInput->hMasaPrerend->energy_fx[i][j] = L_shr( masaInput->hMasaPrerend->energy_fx[i][j], sub( max_e, tmp_energy_e[i][j] ) ); + masaInput->hMasaPrerend->energy_fx[i][j] = L_shr( masaInput->hMasaPrerend->energy_fx[i][j], sub( max_e, tmp_energy_e[i][j] ) ); /* Q(31 - max_e) */ move32(); } } @@ -12329,7 +12386,7 @@ static void renderMasaToMasa( test(); IF( EQ_16( masaInput->base.inputBuffer.config.numChannels, 1 ) && EQ_16( outAudio.config.numChannels, 2 ) ) { - MVR2R_WORD32( tmpBuffer_fx[0], tmpBuffer_fx[1], masaInput->base.inputBuffer.config.numSamplesPerChannel ); + Copy32( tmpBuffer_fx[0], tmpBuffer_fx[1], masaInput->base.inputBuffer.config.numSamplesPerChannel ); } ELSE IF( EQ_16( masaInput->base.inputBuffer.config.numChannels, 2 ) && EQ_16( outAudio.config.numChannels, 1 ) ) { @@ -12378,14 +12435,16 @@ static void renderMasaToMasa( FOR( dir = 0; dir < numDirs; dir++ ) { tmp = BASOP_Util_Divide3232_Scale_cadence( inMeta->directional_meta[dir].energy_ratio_fx[sf][band], ratioSum_fx, &tmp_e ); - inMeta->directional_meta[dir].energy_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 1 ) ); // Q30 + inMeta->directional_meta[dir].energy_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 1 ) ); /* Q30 */ + move32(); } tmp_e = 0; move16(); tmp = 0; move32(); tmp = BASOP_Util_Divide3232_Scale_cadence( inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], ratioSum_fx, &tmp_e ); - inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 1 ) ); // Q30 + inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 1 ) ); /* Q30 */ + move32(); } } } @@ -12400,7 +12459,7 @@ static void renderMasaToMasa( { outMeta->directionIndex[dir][sf][band] = index_theta_phi_16_fx( &inMeta->directional_meta[dir].elevation_fx[sf][band], &inMeta->directional_meta[dir].azimuth_fx[sf][band], masaInput->hMasaPrerend->sph_grid16 ); outMeta->directToTotalRatio[dir][sf][band] = (UWord8) L_shr( inMeta->directional_meta[dir].energy_ratio_fx[sf][band], Q22 ); - outMeta->diffuseToTotalRatio[sf][band] -= outMeta->directToTotalRatio[dir][sf][band]; + outMeta->diffuseToTotalRatio[sf][band] = (UWord8) sub( outMeta->diffuseToTotalRatio[sf][band], outMeta->directToTotalRatio[dir][sf][band] ); outMeta->spreadCoherence[dir][sf][band] = (UWord8) shr( inMeta->directional_meta[dir].spread_coherence_fx[sf][band], Q7 ); move16(); @@ -12575,11 +12634,11 @@ static ivas_error renderInputMasa( *outAudio.pq_fact = outAudio.q_factor; move16(); /* Apply input gain to new audio */ - v_multc_fixed( inAudio.data_fx, masaInput->base.gain_fx, inAudio.data_fx, inAudio.config.numSamplesPerChannel * inAudio.config.numChannels ); + v_multc_fixed( inAudio.data_fx, masaInput->base.gain_fx, inAudio.data_fx, i_mult( inAudio.config.numSamplesPerChannel, inAudio.config.numChannels ) ); *outAudio.pq_fact = sub( *outAudio.pq_fact, 1 ); // to compensate for the qfactor reduction in gain multiplication. move16(); - maxBin = extract_l( Mpy_32_32( *masaInput->base.ctx.pOutSampleRate, INV_CLDFB_BANDWIDTH_Q31 ) ); + maxBin = extract_l( Mpy_32_32( *masaInput->base.ctx.pOutSampleRate, INV_CLDFB_BANDWIDTH_Q31 ) ); /* Q0 */ /* set combined orientation subframe info to start info */ ivas_combined_orientation_set_to_start_index( *( masaInput->base.ctx.pCombinedOrientationData ) ); @@ -12600,7 +12659,7 @@ static ivas_error renderInputMasa( copyBufferTo2dArray_fx( masaInput->base.inputBuffer, tmpBuffer_buff_fx ); num_subframes = BASOP_Util_Divide3232_Scale( L_mult0( masaInput->base.inputBuffer.config.numSamplesPerChannel, IVAS_NUM_FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ), *masaInput->base.ctx.pOutSampleRate, &exp ); - num_subframes = shr( num_subframes, sub( 15, exp ) ); + num_subframes = shr( num_subframes, sub( 15, exp ) ); /* Q0 */ SWITCH( masaInput->hMasaExtRend->renderer_type ) { @@ -12611,10 +12670,11 @@ static ivas_error renderInputMasa( FOR( ch = 0; ch < masaInput->hMasaExtRend->hDirACRend->hOutSetup.nchan_out_woLFE + masaInput->hMasaExtRend->hDirACRend->hOutSetup.num_lfe; ch++ ) { masaInput->hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state = Q11; + move16(); } FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) { - Scale_sig32( tmpBuffer_buff_fx[ch], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); + Scale_sig32( tmpBuffer_buff_fx[ch], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ } ivas_masa_ext_dirac_render_fx( masaInput->hMasaExtRend, tmpBuffer_fx, num_subframes ); @@ -12623,8 +12683,9 @@ static ivas_error renderInputMasa( FOR( ch = 0; ch < masaInput->hMasaExtRend->hDirACRend->hOutSetup.nchan_out_woLFE + masaInput->hMasaExtRend->hDirACRend->hOutSetup.num_lfe; ch++ ) { - scale_sig32( masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, masaInput->hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state ) ); + scale_sig32( masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, masaInput->hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state ) ); /* Q11 */ masaInput->hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; + move16(); } intermidiate_ext_dirac_render( masaInput->hMasaExtRend, 0 ); @@ -12635,8 +12696,8 @@ static ivas_error renderInputMasa( copyMasaMetadataToDiracRenderer_fx( &masaInput->masaMetadata, masaInput->hMasaExtRend->hSpatParamRendCom, maxBin ); - Scale_sig32( tmpBuffer_buff_fx[0], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); - Scale_sig32( tmpBuffer_buff_fx[1], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); + Scale_sig32( tmpBuffer_buff_fx[0], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ + Scale_sig32( tmpBuffer_buff_fx[1], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ ivas_masa_ext_rend_parambin_render_fx( masaInput->hMasaExtRend, *masaInput->base.ctx.pCombinedOrientationData, tmpBuffer_fx, num_subframes ); *outAudio.pq_fact = Q11; @@ -13157,7 +13218,7 @@ static ivas_error getSamplesInternal( test(); IF( EQ_32( getAudioConfigType( hIvasRend->outputConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ) && - NE_32( outAudio.config.numSamplesPerChannel * 1000, ( hIvasRend->num_subframes * BINAURAL_RENDERING_FRAME_SIZE_MS ) * hIvasRend->sampleRateOut ) ) + NE_32( L_mult0( outAudio.config.numSamplesPerChannel, 1000 ), imult3216( hIvasRend->sampleRateOut, i_mult( hIvasRend->num_subframes, BINAURAL_RENDERING_FRAME_SIZE_MS ) ) ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BUFFER_SIZE, "Binaural rendering requires specific frame size" ); } @@ -13581,13 +13642,13 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( hDirACRend->hOutSetup.ls_elevation_fx = inputMasa->base.ctx.pCustomLsOut->ls_elevation_fx; hDirACRend->hOutSetup.num_lfe = inputMasa->base.ctx.pCustomLsOut->num_lfe; + move16(); hDirACRend->hOutSetup.index_lfe[0] = inputMasa->base.ctx.pCustomLsOut->lfe_idx[0]; + move16(); hDirACRend->hOutSetup.is_loudspeaker_setup = TRUE; - hDirACRend->hOutSetup.is_planar_setup = (Word8) inputMasa->base.ctx.pCustomLsOut->is_planar_setup; - move16(); - move16(); move16(); + hDirACRend->hOutSetup.is_planar_setup = (Word8) inputMasa->base.ctx.pCustomLsOut->is_planar_setup; move16(); } @@ -13605,7 +13666,8 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( { hDirACRend->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */ move16(); - IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + test(); + if ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { hDirACRend->hOutSetup.ambisonics_order = SBA_FOA_ORDER; move16(); @@ -13625,10 +13687,10 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_MONO; - hDirACRend->panningConf = DIRAC_PANNING_HOA3; - nchan_out_woLFE = 1; move32(); + hDirACRend->panningConf = DIRAC_PANNING_HOA3; move32(); + nchan_out_woLFE = 1; move16(); } ELSE IF( hDirACRend->hOutSetup.is_loudspeaker_setup ) @@ -13641,15 +13703,15 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( ELSE IF( !hDirACRend->hOutSetup.is_loudspeaker_setup && GT_16( nchan_transport, 1 ) ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_SHD; - hDirACRend->panningConf = DIRAC_PANNING_HOA3; move32(); + hDirACRend->panningConf = DIRAC_PANNING_HOA3; move32(); } ELSE { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_GAIN_SHD; - hDirACRend->panningConf = DIRAC_PANNING_HOA3; move32(); + hDirACRend->panningConf = DIRAC_PANNING_HOA3; move32(); } @@ -13688,39 +13750,35 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( { /* Directional and diffuses components in output LS format */ hDirACRend->num_outputs_diff = nchan_out_woLFE; - hDirACRend->num_outputs_dir = nchan_out_woLFE; move16(); + hDirACRend->num_outputs_dir = nchan_out_woLFE; move16(); } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { /* Directional and diffuses components in SHD */ /* Diffuseness components up to 1st order */ - hDirACRend->num_outputs_diff = imult1616( ( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ) + 1 ), ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ) ); + hDirACRend->num_outputs_diff = imult1616( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ), ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ) ); hDirACRend->num_outputs_dir = ivas_sba_get_nchan_fx( hDirACRend->hOutSetup.ambisonics_order, 0 ); - move16(); - move16(); } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) { hDirACRend->num_outputs_diff = DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS; - hDirACRend->num_outputs_dir = nchan_out_woLFE; move16(); + hDirACRend->num_outputs_dir = nchan_out_woLFE; move16(); } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { hDirACRend->num_outputs_diff = 1; /* There is one output channel in mono */ - hDirACRend->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */ move16(); + hDirACRend->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */ move16(); } ELSE { assert( 0 && "DirAC: not existing synthesis methods!" ); } - move16(); - move16(); IF( ( hDirACRend->proto_index_dir = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_dir ) ) == NULL ) { @@ -13740,10 +13798,10 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( IF( EQ_16( nchan_transport, 1 ) ) { hDirACRend->num_protos_ambi = 1; - hDirACRend->num_protos_dir = 1; - hDirACRend->num_protos_diff = 1; move16(); + hDirACRend->num_protos_dir = 1; move16(); + hDirACRend->num_protos_diff = 1; move16(); } ELSE IF( EQ_16( nchan_transport, 2 ) ) @@ -13751,33 +13809,33 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { hDirACRend->num_protos_ambi = 2; - hDirACRend->num_protos_diff = 1; - hDirACRend->num_protos_dir = 2; - hDirACRend->proto_index_dir[1] = 1; move16(); + hDirACRend->num_protos_diff = 1; move16(); + hDirACRend->num_protos_dir = 2; move16(); + hDirACRend->proto_index_dir[1] = 1; move16(); } ELSE IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) ) { /* Following the foa rendering for code compatibility */ hDirACRend->num_protos_ambi = 2; - hDirACRend->num_protos_dir = 2; - hDirACRend->num_protos_diff = 3; - hDirACRend->proto_index_dir[0] = 0; - hDirACRend->proto_index_diff[0] = 0; move16(); + hDirACRend->num_protos_dir = 2; move16(); + hDirACRend->num_protos_diff = 3; move16(); + hDirACRend->proto_index_dir[0] = 0; move16(); + hDirACRend->proto_index_diff[0] = 0; move16(); } ELSE { hDirACRend->num_protos_ambi = 2; - hDirACRend->num_protos_diff = 3; move16(); + hDirACRend->num_protos_diff = 3; move16(); FOR( k = 0; k < hDirACRend->num_outputs_diff; k++ ) @@ -13806,8 +13864,8 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( ELSE { hDirACRend->num_protos_dir = 2; - hDirACRend->proto_index_dir[1] = 1; move16(); + hDirACRend->proto_index_dir[1] = 1; move16(); } } @@ -13841,7 +13899,7 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set32_fx( hDirACRend->hoa_encoder_fx, 0, nchan_out_woLFE * hDirACRend->num_outputs_diff ); + set32_fx( hDirACRend->hoa_encoder_fx, 0, imult1616( nchan_out_woLFE, hDirACRend->num_outputs_diff ) ); compute_hoa_encoder_mtx_fx( ls_azimuth_fx, ls_elevation_fx, hDirACRend->hoa_encoder_fx, hDirACRend->num_outputs_diff, hDirACRend->hOutSetup.ambisonics_order ); } @@ -13874,7 +13932,7 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( /* decorrelation */ hDirACRend->proto_signal_decorr_on = 1; move16(); - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) + if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { hDirACRend->proto_signal_decorr_on = 0; move16(); @@ -13906,7 +13964,7 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( move16(); test(); - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0; move16(); @@ -14466,8 +14524,8 @@ static ivas_error ivas_masa_ext_rend_parambin_init( /* Set common variables and defaults */ output_Fs = *( inputMasa->base.ctx.pOutSampleRate ); - nBins = inputMasa->hMasaExtRend->hSpatParamRendCom->num_freq_bands; move32(); + nBins = inputMasa->hMasaExtRend->hSpatParamRendCom->num_freq_bands; move16(); renderer_type = inputMasa->hMasaExtRend->renderer_type; move32(); @@ -14543,7 +14601,7 @@ static ivas_error ivas_masa_ext_rend_parambin_init( tmpFloat_fx = s_max( 0, sub( shl_sat( 1, sub( 15, tmp_e ) ), tmp ) ) /*max( 0.0f, 1.0f - binCenterFreq / 2700.0f )*/; /*Q30*/ tmp2 = extract_l( Mult_32_32( binCenterFreq_fx, 1952258 /*=2^31*180/(550)/360*/ ) % 32767 ); //*binCenterFreq_fx * EVS_PI / 550.0f*/ hDiracDecBin->diffuseFieldCoherence_fx[bin] = L_shl( L_mult0( divide3232( tmpFloat_fx, Mult_32_16( binCenterFreq_fx, 187 /*2^15*pi/550*/ ) ), getSineWord16R2( tmp2 ) ), tmp_e ); /*tmpFloat * sinf( binCenterFreq * EVS_PI / 550.0f ) / ( binCenterFreq * EVS_PI / 550.0f );*/ - hDiracDecBin->diffuseFieldCoherence_fx[bin] = L_shl( hDiracDecBin->diffuseFieldCoherence_fx[bin], 1 ); // Q31 + hDiracDecBin->diffuseFieldCoherence_fx[bin] = L_shl( hDiracDecBin->diffuseFieldCoherence_fx[bin], 1 ); /* Q31 */ move32(); move32(); } @@ -14606,7 +14664,7 @@ static ivas_error ivas_masa_ext_rend_parambin_init( return error; } /* External renderer uses constant regularization factor */ - hDiracDecBin->reqularizationFactor_fx = 6554; + hDiracDecBin->reqularizationFactor_fx = 6554; /* 0.4f in Q14 */ move16(); inputMasa->hMasaExtRend->hDiracDecBin = hDiracDecBin; @@ -15118,7 +15176,7 @@ static void intermidiate_ext_dirac_render( move16(); FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); /* Q30 */ hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; move16(); } @@ -15126,22 +15184,22 @@ static void intermidiate_ext_dirac_render( IF( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx ) { Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len, shift ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len, shift ); /* Q(hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth + shift) */ hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, shift ); move16(); } IF( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx ) { Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len, shift ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len, shift ); /* Q(hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev + shift) */ hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, shift ); move16(); } IF( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx ) { - Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len, shift ); + Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, imult1616( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len, shift ); /* Q(hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth + shift) */ hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, shift ); move16(); } @@ -15157,8 +15215,8 @@ static void intermidiate_ext_dirac_render( IF( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx ) { - tmp = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len, tmp ); + tmp = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len, tmp ); /* Q(h_dirac_output_synthesis_state->q_cy_auto_diff_smooth + tmp) */ h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, tmp ); move16(); } @@ -15166,21 +15224,21 @@ static void intermidiate_ext_dirac_render( IF( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx ) { tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len, tmp ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len, tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev + tmp) */ hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, tmp ); move16(); } - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_len, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_len, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); /* Q26 */ hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26; move16(); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_len, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_len, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); /* Q26 */ hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26; move16(); IF( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx ) { - Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len, shift ); + Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len, shift ); /* Q(hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev + shift) */ hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, shift ); move16(); } @@ -15188,7 +15246,7 @@ static void intermidiate_ext_dirac_render( IF( EQ_16( hDirACRend->proto_signal_decorr_on, 1 ) ) { tmp = L_norm_arr( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len ); - scale_sig32( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); + scale_sig32( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); /* Q(hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer + tmp) */ hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer = add( hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer, tmp ); move16(); } @@ -15224,8 +15282,9 @@ static void intermidiate_ext_dirac_render( Word16 hr_exp = sub( 31, shift ); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, sub( sub( 31, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q ), hr_exp ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, sub( sub( 31, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q ), hr_exp ) ); /* Q(31 - hr_exp) */ hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = sub( 31, hr_exp ); + move16(); } FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) @@ -15242,25 +15301,25 @@ static void intermidiate_ext_dirac_render( IF( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx ) { - tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len, tmp ); + tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len, tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q + tmp) */ hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, tmp ); move16(); - tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len, tmp ); + tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len, tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q + tmp) */ hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = add( tmp, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ); move16(); } tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, tmp ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q + tmp) */ hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, tmp ); move16(); IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 ) { tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, tmp ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q + tmp) */ hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, tmp ); move16(); } @@ -15272,7 +15331,7 @@ static void intermidiate_ext_dirac_render( /* CLDFB Analysis*/ FOR( ch = 0; ch < nchan_transport; ch++ ) { - scale_sig32( hMasaExtRend->cldfbAnaRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbAnaRend[ch]->cldfb_size, sub( Q11, hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state ) ); + scale_sig32( hMasaExtRend->cldfbAnaRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbAnaRend[ch]->cldfb_size, sub( Q11, hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state ) ); /* Q11 */ hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state = Q11; move16(); } @@ -15280,7 +15339,7 @@ static void intermidiate_ext_dirac_render( FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE + hDirACRend->hOutSetup.num_lfe; ch++ ) { - scale_sig32( hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state ) ); + scale_sig32( hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state ) ); /* Q11 */ hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; move16(); } diff --git a/lib_rend/lib_rend.h b/lib_rend/lib_rend.h index beb2af28948b8439e4d588b077eb12fb69924fd1..1d8c36cf5e5bf8163877f5ca3d03a350fa2525f6 100644 --- a/lib_rend/lib_rend.h +++ b/lib_rend/lib_rend.h @@ -133,12 +133,12 @@ typedef enum _IVAS_REND_COMPLEXITY_LEVEL #ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_Open( - IVAS_REND_HANDLE *phIvasRend, /* i/o: Pointer to renderer handle */ - const Word32 outputSampleRate, /* i : output sampling rate */ - const IVAS_AUDIO_CONFIG outConfig, /* i : output audio config */ - const Word16 nonDiegeticPan, /* i : non-diegetic object flag */ - const Word32 nonDiegeticPanGain, /* i : non-diegetic panning gain */ - const Word16 num_subframes /* i : number of subframes */ + IVAS_REND_HANDLE *phIvasRend, /* i/o: Pointer to renderer handle */ + const Word32 outputSampleRate, /* i : output sampling rate */ + const IVAS_AUDIO_CONFIG outConfig, /* i : output audio config */ + const Word16 nonDiegeticPan, /* i : non-diegetic object flag */ + const Word32 nonDiegeticPanGain, /* i : non-diegetic panning gain Q31 */ + const Word16 num_subframes /* i : number of subframes */ ); #else ivas_error IVAS_REND_Open( @@ -149,7 +149,7 @@ ivas_error IVAS_REND_Open( const float nonDiegeticPanGain, /* i : non-diegetic panning gain */ const int16_t num_subframes /* i : number of subframes */ ); -#endif // IVAS_FLOAT_FIXED +#endif /* Note: this will reset custom LFE routings set for any MC input */ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( @@ -160,30 +160,30 @@ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( /* Functions to be called before/during rendering */ -#ifndef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_NumOutChannels( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ - int16_t *numOutChannels /* o : number of output channels */ + Word16 *numOutChannels /* o : number of output channels */ +); + +ivas_error IVAS_REND_AddInput_fx( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_AUDIO_CONFIG inConfig, /* i : audio config for a new input */ + IVAS_REND_InputId *inputId /* o : ID of the new input */ ); #else ivas_error IVAS_REND_NumOutChannels( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ - Word16 *numOutChannels /* o : number of output channels */ + int16_t *numOutChannels /* o : number of output channels */ ); -#endif ivas_error IVAS_REND_AddInput( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_AUDIO_CONFIG inConfig, /* i : audio config for a new input */ IVAS_REND_InputId *inputId /* o : ID of the new input */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error IVAS_REND_AddInput_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_AUDIO_CONFIG inConfig, /* i : audio config for a new input */ - IVAS_REND_InputId *inputId /* o : ID of the new input */ -); #endif + /* Note: this will reset any custom LFE routing set for the input */ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ @@ -191,24 +191,33 @@ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( const IVAS_CUSTOM_LS_DATA layout /* i : custom loudspeaker layout for input */ ); -ivas_error IVAS_REND_SetInputGain( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const float gain /* i : linear gain (not in dB) */ -); #ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_SetInputGain_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const Word32 gain /* i : linear gain (not in dB) */ + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const Word32 gain /* i : linear gain (not in dB) Q30 */ ); ivas_error IVAS_REND_SetInputLfeMtx_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const IVAS_REND_LfePanMtx_fx *lfePanMtx /* i : LFE panning matrix */ + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const IVAS_REND_LfePanMtx_fx *lfePanMtx /* i : LFE panning matrix */ +); + +ivas_error IVAS_REND_SetInputLfePos_fx( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const Word32 inputGain, /* i : Input gain to be applied to the LFE channel(s) Q31 */ + const Word16 outputAzimuth, /* i : Output azimuth position Q0 */ + const Word16 outputElevation /* i : Output elevation position Q0 */ +); +#else +ivas_error IVAS_REND_SetInputGain( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const float gain /* i : linear gain (not in dB) */ ); -#endif // IVAS_FLOAT_FIXED + ivas_error IVAS_REND_SetInputLfeMtx( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ @@ -222,15 +231,8 @@ ivas_error IVAS_REND_SetInputLfePos( const float outputAzimuth, /* i : Output azimuth position */ const float outputElevation /* i : Output elevation position */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error IVAS_REND_SetInputLfePos_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const Word32 inputGain, /* i : Input gain to be applied to the LFE channel(s) */ - const Word16 outputAzimuth, /* i : Output azimuth position */ - const Word16 outputElevation /* i : Output elevation position */ -); -#endif // IVAS_FLOAT_FIXED +#endif + ivas_error IVAS_REND_RemoveInput( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId /* i : ID of the input */ @@ -240,7 +242,13 @@ ivas_error IVAS_REND_RemoveInput( ivas_error IVAS_REND_GetInputNumChannels( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ - Word16 *numChannels /* o : number of channels of the input */ + Word16 *numChannels /* o : number of channels of the input */ +); + +ivas_error IVAS_REND_GetDelay_fx( + IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer state */ + Word16 *nSamples, /* o : Renderer delay in samples */ + Word32 *timeScale /* o : Time scale of the delay, equal to renderer output sampling rate */ ); #else ivas_error IVAS_REND_GetInputNumChannels( @@ -248,46 +256,47 @@ ivas_error IVAS_REND_GetInputNumChannels( const IVAS_REND_InputId inputId, /* i : ID of the input */ int16_t *numChannels /* o : number of channels of the input */ ); -#endif -#ifndef IVAS_FLOAT_FIXED ivas_error IVAS_REND_GetDelay( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ int16_t *nSamples, /* o : Renderer delay in samples */ int32_t *timeScale /* o : Time scale of the delay, equal to renderer output sampling rate */ ); -#else -ivas_error IVAS_REND_GetDelay( - IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ - Word16 *nSamples, /* o : Renderer delay in samples */ - Word32 *timeScale /* o : Time scale of the delay, equal to renderer output sampling rate */ -); #endif -#ifdef IVAS_FLOAT_FIXED -ivas_error IVAS_REND_GetDelay_fx( - IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer state */ - Word16 *nSamples, /* o : Renderer delay in samples */ - Word32 *timeScale /* o : Time scale of the delay, equal to renderer output sampling rate */ -); -#endif // IVAS_FLOAT_FIXED - /* Functions to be called during rendering */ -ivas_error IVAS_REND_FeedInputAudio( +#ifdef IVAS_FLOAT_FIXED +ivas_error IVAS_REND_FeedInputAudio_fx( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ const IVAS_REND_ReadOnlyAudioBuffer inputAudio /* i : buffer with input audio */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error IVAS_REND_FeedInputAudio_fx( +ivas_error IVAS_REND_FeedInputObjectMetadata( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const IVAS_ISM_METADATA objectPosition /* i : object position struct */ +); + +ivas_error IVAS_REND_FeedInputObjectMetadataToOMasa( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const Word16 inputIndex, /* i : Index of the input */ + const IVAS_ISM_METADATA objectPosition /* i : object position struct */ +); + +ivas_error IVAS_REND_FeedInputObjectMetadataToOMasa( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const Word16 inputIndex, /* i : Index of the input */ + const IVAS_ISM_METADATA objectPosition /* i : object position struct */ +); +#else +ivas_error IVAS_REND_FeedInputAudio( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ const IVAS_REND_ReadOnlyAudioBuffer inputAudio /* i : buffer with input audio */ ); -#endif ivas_error IVAS_REND_FeedInputObjectMetadata( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ @@ -300,6 +309,14 @@ ivas_error IVAS_REND_FeedInputObjectMetadataToOMasa( const IVAS_ISM_METADATA objectPosition /* i : object position struct */ ); +ivas_error IVAS_REND_FeedInputObjectMetadataToOMasa( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const int16_t inputIndex, /* i : Index of the input */ + const IVAS_ISM_METADATA objectPosition /* i : object position struct */ +); +#endif + + ivas_error IVAS_REND_FeedInputMasaMetadata( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ @@ -311,45 +328,40 @@ ivas_error IVAS_REND_InitConfig( const IVAS_AUDIO_CONFIG outAudioConfig /* i : output audioConfig */ ); -#ifndef IVAS_FLOAT_FIXED -int16_t IVAS_REND_GetRenderConfig( - IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ - const IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render configuration handle */ -); -#else +#ifdef IVAS_FLOAT_FIXED Word16 IVAS_REND_GetRenderConfig( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ const IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render configuration handle */ ); -#endif -#ifndef IVAS_FLOAT_FIXED -int16_t IVAS_REND_FeedRenderConfig( +Word16 IVAS_REND_FeedRenderConfig( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ const IVAS_RENDER_CONFIG_DATA renderConfig /* i : Render configuration struct */ ); + +ivas_error IVAS_REND_SetHeadRotation( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_QUATERNION headRot, /* i : head orientations for next rendering call */ + const IVAS_VECTOR3 Pos, /* i : listener positions for next rendering call */ + const Word16 sf_idx /* i : subframe index */ +); #else -Word16 IVAS_REND_FeedRenderConfig( +int16_t IVAS_REND_GetRenderConfig( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ - const IVAS_RENDER_CONFIG_DATA renderConfig /* i : Render configuration struct */ + const IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render configuration handle */ ); -#endif +int16_t IVAS_REND_FeedRenderConfig( + IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ + const IVAS_RENDER_CONFIG_DATA renderConfig /* i : Render configuration struct */ +); -#ifndef IVAS_FLOAT_FIXED ivas_error IVAS_REND_SetHeadRotation( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_QUATERNION headRot, /* i : head orientations for next rendering call */ const IVAS_VECTOR3 Pos, /* i : listener positions for next rendering call */ const int16_t sf_idx /* i : subframe index */ ); -#else -ivas_error IVAS_REND_SetHeadRotation( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_QUATERNION headRot, /* i : head orientations for next rendering call */ - const IVAS_VECTOR3 Pos, /* i : listener positions for next rendering call */ - const Word16 sf_idx /* i : subframe index */ -); #endif /* Head rotation becomes enabled by calling IVAS_REND_SetHeadRotation. Use this to disable. */ @@ -433,31 +445,27 @@ ivas_error IVAS_REND_SetTotalNumberOfObjects( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ const UWord16 total_num_objects /* i : total number of objects */ ); -#else -ivas_error IVAS_REND_SetTotalNumberOfObjects( - IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ - const uint16_t total_num_objects /* i : total number of objects */ -); -#endif -#ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_SetIsmMetadataDelay( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ const Word32 sync_md_delay /* i : Metadata Delay in ms to sync with audio delay */ ); -#else -ivas_error IVAS_REND_SetIsmMetadataDelay( - IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ - const float sync_md_delay /* i : Metadata Delay in ms to sync with audio delay */ -); -#endif -#ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_GetNumAllObjects( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ Word16 *numChannels /* o : number of all objects */ ); #else +ivas_error IVAS_REND_SetTotalNumberOfObjects( + IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ + const uint16_t total_num_objects /* i : total number of objects */ +); + +ivas_error IVAS_REND_SetIsmMetadataDelay( + IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ + const float sync_md_delay /* i : Metadata Delay in ms to sync with audio delay */ +); + ivas_error IVAS_REND_GetNumAllObjects( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ int16_t *numChannels /* o : number of all objects */ diff --git a/lib_util/masa_file_reader.c b/lib_util/masa_file_reader.c index 11178d54c378ed1e88ec3a3185e61cc704ea9924..59d7b632c35ae4198e67e9633fc6d5387430313d 100644 --- a/lib_util/masa_file_reader.c +++ b/lib_util/masa_file_reader.c @@ -190,8 +190,9 @@ ivas_error MasaFileReader_readNextFrame( for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ ) { +#ifndef IVAS_FLOAT_FIXED deindex_sph_idx( readIndex[b], &self->sph_grid16, &( hMeta->directional_meta[i].elevation[j][b] ), &( hMeta->directional_meta[i].azimuth[j][b] ) ); -#ifdef IVAS_FLOAT_FIXED +#else deindex_sph_idx_fx( readIndex[b], &self->sph_grid16, &( hMeta->directional_meta[i].elevation_fx[j][b] ), &( hMeta->directional_meta[i].azimuth_fx[j][b] ) ); #endif hMeta->directional_meta[i].spherical_index[j][b] = readIndex[b]; @@ -205,9 +206,10 @@ ivas_error MasaFileReader_readNextFrame( for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ ) { +#ifndef IVAS_FLOAT_FIXED hMeta->directional_meta[i].energy_ratio[j][b] = ( (float) readOther[b] ) / UINT8_MAX; -#ifdef IVAS_FLOAT_FIXED - hMeta->directional_meta[i].energy_ratio_fx[j][b] = (Word32) ( readOther[b] * ONE_IN_Q22 ); // Q30 +#else + hMeta->directional_meta[i].energy_ratio_fx[j][b] = (Word32) ( readOther[b] * ONE_IN_Q22 ); // Q30 #endif } @@ -220,8 +222,9 @@ ivas_error MasaFileReader_readNextFrame( for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ ) { +#ifndef IVAS_FLOAT_FIXED hMeta->directional_meta[i].spread_coherence[j][b] = ( (float) readOther[b] ) / UINT8_MAX; -#ifdef IVAS_FLOAT_FIXED +#else hMeta->directional_meta[i].spread_coherence_fx[j][b] = (Word16) ( readOther[b] * ONE_IN_Q7 ); // Q15 #endif @@ -237,9 +240,10 @@ ivas_error MasaFileReader_readNextFrame( for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ ) { +#ifndef IVAS_FLOAT_FIXED hMeta->common_meta.diffuse_to_total_ratio[j][b] = ( (float) readOther[b] ) / UINT8_MAX; -#ifdef IVAS_FLOAT_FIXED - hMeta->common_meta.diffuse_to_total_ratio_fx[j][b] = (Word32) ( readOther[b] * ONE_IN_Q22 ); // Q30 +#else + hMeta->common_meta.diffuse_to_total_ratio_fx[j][b] = (Word32) ( readOther[b] * ONE_IN_Q22 ); // Q30 #endif } @@ -252,9 +256,10 @@ ivas_error MasaFileReader_readNextFrame( for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ ) { +#ifndef IVAS_FLOAT_FIXED hMeta->common_meta.surround_coherence[j][b] = ( (float) readOther[b] ) / UINT8_MAX; -#ifdef IVAS_FLOAT_FIXED - hMeta->common_meta.surround_coherence_fx[j][b] = shl( (Word16) readOther[b], 7 ); // Q8->Q15 +#else + hMeta->common_meta.surround_coherence_fx[j][b] = shl( (Word16) readOther[b], 7 ); // Q8->Q15 move16(); #endif } @@ -267,7 +272,12 @@ ivas_error MasaFileReader_readNextFrame( for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ ) { +#ifndef IVAS_FLOAT_FIXED hMeta->common_meta.remainder_to_total_ratio[j][b] = ( (float) readOther[b] ) / UINT8_MAX; +#else + hMeta->common_meta.remainder_to_total_ratio_fx[j][b] = L_shl( (Word32) readOther[b], Q22 ); // Q8 -> Q30 + move32(); +#endif } }