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/core_com_config.c b/lib_com/core_com_config.c index d7d6b9136c5f6583a216d610903d051e0305cc9d..a3af3148735d5a4217e917fa9c8fdf64f23e167b 100644 --- a/lib_com/core_com_config.c +++ b/lib_com/core_com_config.c @@ -1402,7 +1402,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 +1457,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 +1475,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/ivas_cnst.h b/lib_com/ivas_cnst.h index 327d14f91b93683f803f65efef68959d3b018923..fec6669810343795b308f60575e97958f142333d 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1417,9 +1417,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 */ diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 49ae9424ab32fa10d6f98b4d65ac9829e3a9c79a..18ab4ccf98497fcfcecde82d3939f1d8b7a7269b 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1400,7 +1400,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 @@ -8111,7 +8111,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 diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 0a94203298d3464b396d3db25b57371aa0d359fe..5f13befaa59d5f95dc8ec3ee90e30f3115e278cf 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3286,7 +3286,9 @@ 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( @@ -3441,4 +3443,22 @@ Word16 ivas_arith_encode_cmplx_cell_array( 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 */ +); + #endif diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 8fac54f5e3fb963330b74dd2e0509d9f70276664..c0a3b61a4c6f34354c8d91fe5905843f8692fa71 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10368,7 +10368,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( 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/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/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_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_stereo_dft_plc_fx.c b/lib_dec/ivas_stereo_dft_plc_fx.c index de5dae9ecb6c0d8fc9ba80fd3ab24bfbc5aded2c..f6551e090566b2f4b81a1c4b7686cb49e064bae4 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 }; @@ -86,7 +86,7 @@ void stereo_dft_res_ecu_fx( 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 +103,35 @@ 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 */ 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 ); 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 +141,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 +156,13 @@ 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 ); + hStereoDft->time_offs = add( hStereoDft->time_offs, L_FRAME8k ); /* Q0 */ move16(); } @@ -184,22 +184,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 +207,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 +234,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 +250,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 +271,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 +292,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 +308,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 +344,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 +364,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 +378,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 +412,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 +429,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 +443,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 +464,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 +483,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 +508,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 +538,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 +568,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 +577,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 +598,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 +618,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 +662,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 +681,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 +707,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 +725,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 +744,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 +764,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 +778,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 +813,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_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/cod_tcx.c b/lib_enc/cod_tcx.c index 4508bfb64bc3b1c81ca9091215c86bf6a56265f0..0656104d68960ee164e9a2f78a052bd7fa4c2945 100644 --- a/lib_enc/cod_tcx.c +++ b/lib_enc/cod_tcx.c @@ -752,7 +752,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 +1213,9 @@ void TNSAnalysisStereo( return; } +#endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * TNSAnalysis() * @@ -1298,7 +1300,6 @@ void TNSAnalysis( } -#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * ShapeSpectrum() * @@ -1475,7 +1476,6 @@ void ShapeSpectrum( return; } -#endif /*-------------------------------------------------------------------* @@ -1506,7 +1506,6 @@ static int16_t GetTransWidth( } -#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------* * EstimateTCXNoiseLevel() * @@ -1566,7 +1565,6 @@ static void EstimateTCXNoiseLevel( return; } -#endif /*-----------------------------------------------------------* @@ -1662,7 +1660,6 @@ void EstimateStereoTCXNoiseLevel( } -#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------* * DecideTonalSideInfo() * @@ -2799,7 +2796,6 @@ void coder_tcx( return; } -#endif /*-------------------------------------------------------------------* * coder_tcx_post() @@ -2827,3 +2823,4 @@ void coder_tcx_post( return; } +#endif diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index f5e997e626d273132f2ac241ff4aa7b13cde8c18..cad53d59963999bbd4f00a02139b509957e63e6e 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -734,10 +734,18 @@ static void init_tcx( /* Init TCX target bits correction factor */ hTcxEnc->tcx_target_bits_fac_flt = 1.0f; 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 */ @@ -747,7 +755,11 @@ 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; hTcxEnc->kernel_switch_corr_past_flt = 0.f; 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/ext_sig_ana.c b/lib_enc/ext_sig_ana.c index 90c1855e87321f283131ab640eb310c1db6314c7..aeb6804b20bc97e70efa1f0a45dd870b971980de 100644 --- a/lib_enc/ext_sig_ana.c +++ b/lib_enc/ext_sig_ana.c @@ -134,7 +134,6 @@ void core_signal_analysis_high_bitrate( 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 ); @@ -151,7 +150,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 +172,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 ); } @@ -497,14 +491,6 @@ void core_signal_analysis_high_bitrate( #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 ); 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/init_enc.c b/lib_enc/init_enc.c index abbdba3126c166749da3e8ab7ac3d5da2a1e3b37..bd75d6636cc10dd4c7b2341a624fa436026decce 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -511,9 +511,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 +535,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; @@ -877,12 +884,16 @@ ivas_error init_encoder( 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 +947,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 { @@ -1259,11 +1274,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 @@ -2073,10 +2084,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 ) { diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index b578a8eeffacb38549253eb9fdb8b595fb3b12ff..baaf780daaa65f3dcb74e6f847a68d64ff5a3c87 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -264,14 +264,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 ) ) { @@ -328,15 +320,6 @@ ivas_error ivas_core_enc( { 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 ); { @@ -477,9 +459,7 @@ ivas_error ivas_core_enc( 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 ); @@ -538,16 +518,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 diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 00bfb09530718d84a95c97d605620f4542dc6988..6d707f9cf2e30599f3bdc3f641f7c571b2a76365 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -1605,7 +1605,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 +1615,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 +1782,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 ); @@ -1954,7 +1946,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 @@ -2358,7 +2349,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 +2667,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 @@ -3023,7 +3011,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..c95570a07717880c2f4eebd89d2700feb63797e3 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -238,7 +238,6 @@ ivas_error ivas_cpe_enc( 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(); @@ -1067,10 +1066,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 +1118,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 ) ) diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index efa570ee96628e893dd9a36041d25c5241e33071..58746812a350b722aa67dc3315166ac1112cbded 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -1308,12 +1308,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]; @@ -1323,35 +1329,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 diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index cb2965b62f1bf99fca24d84532e0f9f5d273b2d5..8a1c2ffb85a989d59bacb3732b13f7ae52fdae85 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -1251,7 +1251,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; } diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index d2cada5f9e90db83c8d0197d6151475956d0320a..db5e9816b6b54e754548ec7b19cefcc7dc309dda 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -885,7 +885,6 @@ 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; @@ -964,7 +963,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 ); diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 3dc5c4cd1d60fed98c012d0b2469cd65e7e4c79d..e48d2983dada813492b6517c5b4c114faa20bf97 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -775,10 +775,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 ) @@ -1417,9 +1424,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; } @@ -2181,7 +2188,11 @@ void ivas_destroy_enc( 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..9d8612ff074dfd7e77d4aaad50be67a55796c204 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -682,11 +682,6 @@ ivas_error ivas_ism_enc( { 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 +692,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 +729,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; } diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index fdd17fa68c988b853ac2608da1eb4cd492e919ef..d383d7b327b84f56f842091f8fa770e21fb31cb3 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 ) { diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index e3028474e193ddec8b7e8000d0188cbf5bc1bb81..f5f0cbdbe85aee3ed142a063a3df8787790feedb 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -275,7 +275,11 @@ ivas_error ivas_masa_enc_open( { set_f( hOmasaData->masa_to_total_energy_ratio[i], 0, MASA_FREQUENCY_BANDS ); } +#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++ ) @@ -2133,11 +2137,19 @@ ivas_error ivas_masa_enc_config( { if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT || st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX ) { +#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 } } @@ -4077,6 +4089,7 @@ static void reduce_metadata_further_fx( Word16 band; Word16 selectedBand; Word32 energy[MAX_PARAM_SPATIAL_SUBFRAMES][LOWBITRATE_NUM_BANDS]; + Word64 W_tmp; Word32 totalEnergySum; UWord8 numCodingBands; UWord8 computeCoherence; @@ -4085,7 +4098,7 @@ static void reduce_metadata_further_fx( Word32 bandEnergy; UWord8 mergeOverFreqBands; Word32 meanRatio; - Word16 tmp; + Word16 tmp, tmp2; numCodingBands = hMasa->config.numCodingBands; test(); @@ -4100,8 +4113,8 @@ static void reduce_metadata_further_fx( move16(); /* Get energy for the input data in 4-subframe, 5-band format */ - totalEnergySum = 0; - move32(); + 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 */ { @@ -4126,7 +4139,7 @@ static void reduce_metadata_further_fx( } energy[sf][band] = eneSum; // hMasa->data.q_energy move32(); - totalEnergySum = L_add( totalEnergySum, eneSum ); // hMasa->data.q_energy + W_tmp = W_add( W_tmp, eneSum ); // hMasa->data.q_energy } } } @@ -4138,11 +4151,16 @@ static void reduce_metadata_further_fx( { 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 + W_tmp = W_add( W_tmp, energy[sf][band] ); // hMasa->data.q_energy } } } + tmp2 = W_norm( W_tmp ); + tmp2 = s_min( 32, tmp2 ); + totalEnergySum = W_extract_h( W_shl( W_tmp, tmp2 ) ); + tmp2 = sub( tmp2, 32 ); + /* Determine onsets */ hMasa->data.onset_detector_1_fx = Mpy_32_32( hMasa->data.onset_detector_1_fx, LOWBITRATE_ONSET_ALPHA_Q31 ); move32(); @@ -4152,7 +4170,7 @@ static void reduce_metadata_further_fx( 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; + hMasa->data.q_onset_detector = add( hMasa->data.q_energy, tmp2 ); move32(); move16(); } @@ -4203,7 +4221,7 @@ static void reduce_metadata_further_fx( // 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 ) ); + 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(); @@ -4235,7 +4253,7 @@ static void reduce_metadata_further_fx( IF( totalEnergySum != 0 ) { 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 + exp = add( add( exp, 1 ), tmp2 ); // 31 - (hMasa->data.q_energy - 1) - 31 - hMasa->data.q_energy - tmp2 => 1 + tmp2 } ELSE { @@ -4268,7 +4286,7 @@ static void reduce_metadata_further_fx( IF( !mergeOverFreqBands ) /* Merge values over subframes */ { Word32 xSum, ySum, zSum; - Word64 W_xSum_sq, W_ySum_sq, W_tmp; + Word64 W_xSum_sq, W_ySum_sq; Word32 bandSumEnergy; Word16 aziRad, eleRad, q_shift, exp_diff; Word32 x, y, z; @@ -4500,34 +4518,39 @@ static Word16 encode_lfe_to_total_energy_ratio_fx( /* 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 + linearLFEaverage = L_shl_sat( linearLFEaverage, sub( linearLFEaverage_e, Q1 ) ); // Q30 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 ) ) ) ) + 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 ) ) ) ) { 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 + 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( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, MCMASA_LFE_BETA_Q31 ); /* default "bump-up" to LFE-to-total energy ratio */ // Q31 + 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 { - hMasa->data.prevq_lfeToTotalEnergyRatio_fx = Mpy_32_32( MCMASA_LFE_ALPHA_Q31, hMasa->data.prevq_lfeToTotalEnergyRatio_fx ); /* exponential decay */ // Q31 + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = Mpy_32_32( MCMASA_LFE_ALPHA_Q30, hMasa->data.prevq_lfeToTotalEnergyRatio_fx ); /* exponential decay */ // Q30 move32(); } - if ( GT_32( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, ONE_IN_Q31 ) ) + IF( GE_32( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, ONE_IN_Q30 ) ) + { + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = ONE_IN_Q31; // Q31 + move32(); + } + ELSE { - hMasa->data.prevq_lfeToTotalEnergyRatio_fx = ONE_IN_Q31; + 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 */ diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 00f8197c451e41dd248a0fc08c90842883842aa4..a15484bfddc7f6dd50510425c6fc7df45c0790f5 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -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 3b0c84b66709c7a472a43606f03a0d777a6d22a1..93d19238b808600d4f7dde3a7647c30babd6c2ac 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -746,19 +746,14 @@ 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 ); @@ -1911,9 +1906,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..10768a52c45ad25a7815c6d9e3117e1001f9e2d8 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -1777,7 +1777,6 @@ void ivas_mdct_core_whitening_enc( #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 +1785,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 @@ -1914,7 +1911,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 ); @@ -1923,7 +1919,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 ); @@ -2063,23 +2058,6 @@ void ivas_mdct_core_whitening_enc( { 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 ); @@ -2094,15 +2072,11 @@ void ivas_mdct_core_whitening_enc( 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 ); } @@ -2563,8 +2537,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 +2553,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 +2772,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 +2783,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 +2844,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 +2860,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 +2893,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 +2905,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..a7c26b856c96b07b3222bdb23b57878a982aebb8 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -1098,14 +1098,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 +1121,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 +1170,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 +1229,7 @@ void ivas_set_ism_importance_interformat( return; } +#endif /*--------------------------------------------------------------------------* * ivas_set_surplus_brate_enc() 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_stat_enc.h b/lib_enc/ivas_stat_enc.h index ad0f7f379a2d89d93b2c40d4df95949b2976d020..0184f55fcd5d7ac15658a9be5644768fb3057a08 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1210,8 +1210,11 @@ typedef struct ivas_omasa_encoder_one_data_struct 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; @@ -1562,40 +1565,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; @@ -1605,11 +1639,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; @@ -1618,6 +1661,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]; @@ -1626,6 +1670,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_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 82f334783c1f5227fb64e7d8a7ef0782d92d2926..3552cb9ae49b5e03e04f3f6ff4bd213f279df113 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -1400,7 +1400,6 @@ void stereo_mdct_core_enc( st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 ); } - int igfGridIdx; if ( st->last_core == ACELP_CORE && st->core == TCX_20_CORE ) { @@ -1567,19 +1566,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 diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index d308534f0521c961589161e37dca6689a7e1bcd9..786f0004c54d49cd20095702b9a3fdf3d9ee98a7 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -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 */ diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index c646d41f27263552015f81450e2a9e3b63090d32..a66c732959db3495b82f8b813102244a0a4389cd 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -486,8 +486,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; diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index bf22fb6011bdbe01a7d163374255bc8f9d1f51bc..8e3b4a2e42a91c977b2211bd71726784252352cf 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1726,7 +1726,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/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/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..6d1ce0d06cae1b7eb6fcdaab762f8153f0059e43 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1012,6 +1012,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 */ diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 571636031e5613151337e815d3980fdb49293090..286db595443a1e82d2622ddfb616f891dcf379d3 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1828,12 +1828,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,13 +1856,19 @@ 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; float tcxltp_norm_corr_mem_flt; float kernel_switch_corr_past_flt; @@ -1898,17 +1908,25 @@ 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) */ @@ -2287,12 +2305,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 +2396,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; diff --git a/lib_enc/tcx_utils_enc.c b/lib_enc/tcx_utils_enc.c index f377bfb0db9644558725649d7739f19a4cd1ea50..5999ca2ccf33e6c3be3a0282adc2b26a00215b6b 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 /*---------------------------------------------------------------------* 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