diff --git a/lib_com/bits_alloc_fx.c b/lib_com/bits_alloc_fx.c index c556a8386c058efc4ceadb82f73671449a9fc2e6..8190378b74aed346ca46cccab766c650ea773e14 100644 --- a/lib_com/bits_alloc_fx.c +++ b/lib_com/bits_alloc_fx.c @@ -609,6 +609,8 @@ ivas_error config_acelp1( const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ ) { + UNUSED_PARAM(active_cnt); + Word16 i, bits, nb_subfr; Word16 flag_hardcoded, coder_type_sw, fix_first; Word32 core_brate; diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index db9fd9b27245e69ee26fd16ce9f5a0ce584d5af7..f8b27dd6115b81f66449d008e1d08ba8dd04eac4 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -1659,6 +1659,7 @@ ivas_error openCldfb_ivas( hs->cldfb_state_length = buf_len;//Temporarily added to store the length of buffer hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ set32_fx(hs->cldfb_state_fx, 0, buf_len); + hs->Q_cldfb_state = Q31; #endif // IVAS_FLOAT_FIXED @@ -2468,6 +2469,10 @@ void cldfb_restore_memory_ivas_fx( } hs->cldfb_state_length = size; hs->memory_length = 0; +#if 1 //Remove later + free(hs->memory_flt); + hs->memory_flt = NULL; +#endif free( hs->memory32 ); hs->memory32 = NULL; diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 4d432ca7b65f65d0546462f5f16f6992bcdef179..93712860a5dc550bfab1989ee23e789b02e32ff1 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -224,6 +224,9 @@ enum{ #define MIN_LOG_VAL_60dB -60.0f #define INV_LOG_2 1.442695040888963f /* 1/log(2) */ +#ifdef IVAS_FLOAT_FIXED +#define INV_LOG_2_FX 23637 /*Q14*//* 1/log(2) */ +#endif // IVAS_FLOAT_FIXED #define INV_SQRT_2 0.70710676908493f /* 1/sqrt(2) */ #define INV_SQRT_2_Q15 23170 /* 1/sqrt(2) in Q15 */ #define INV_SQRT_2_Q31 (Word32)1.51850022e+09 /* 1/sqrt(2) in Q31 */ @@ -1355,6 +1358,7 @@ enum #define PLC_MIN_CNG_LEV_FLT 0.01f /* minimum background level */ #define PLC_MIN_CNG_LEV 328/*0.01f Q15*/ +#define PLC_MIN_CNG_LEV_Q21 20992/*0.01f Q21*/ #define PLC_MIN_STAT_BUFF_SIZE 50 /* buffer size for minimum statistics */ #define G_LPC_RECOVERY_BITS 1 diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index 54f1a34ec7591f9dbbc6d5ca58a3ea0e60463653..9de8aae0554393ce087e4e628a8896c0e66aad63 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -223,7 +223,11 @@ typedef struct _IVAS_ROOM_ACOUSTICS_CONFIG float acousticPreDelay; /* Time elapsed between input signal and late reverberation start, float, range [0.001..10] */ float inputPreDelay; /* Offset in seconds from where DSR is computed in the RIR (0 = at source), float, range [0.001..10] */ #ifdef IVAS_FLOAT_FIXED + Word32 pFc_input_fx[IVAS_CLDFB_NO_CHANNELS_MAX]; /* Center frequencies for which following values are provided: */ + Word32 pAcoustic_rt60_fx[IVAS_CLDFB_NO_CHANNELS_MAX]; /* - The room's T60 per center frequency */ + Word32 pAcoustic_dsr_fx[IVAS_CLDFB_NO_CHANNELS_MAX]; /* - The room's Diffuse to Source Ratio per center frequency */ Word32 acousticPreDelay_fx; /* Time elapsed between input signal and late reverberation start, float, range [0.001..10] *//*Assumed Q-27*/ + Word32 inputPreDelay_fx; /* Offset in seconds from where DSR is computed in the RIR (0 = at source), float, range [0.001..10] *//* Assumed Q-27*/ #endif // IVAS_FLOAT_FIXED /* early reflections */ diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index b07d1cf6bded06f2af977a5b0525033c779ddd0c..1bfff493f685e98557f23c7f5120b02236905a73 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -90,6 +90,7 @@ void initFdCngCom_flt( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ const float scale ) { +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /* Calculate FFT scaling factor */ hFdCngCom->scalingFactor_flt = 1 / ( scale * scale * 8.f ); @@ -97,11 +98,12 @@ void initFdCngCom_flt( set_f( hFdCngCom->timeDomainBuffer_flt, 0.0f, L_FRAME16k ); set_f( hFdCngCom->olapBufferAna_flt, 0.0f, FFTLEN ); set_f( hFdCngCom->olapBufferSynth_flt, 0.0f, FFTLEN ); - set_f( hFdCngCom->olapBufferSynth2_flt, 0.0f, FFTLEN ); /* Initialize the comfort noise generation */ set_f( hFdCngCom->fftBuffer_flt, 0.0f, FFTLEN ); +#endif set_f( hFdCngCom->cngNoiseLevel_flt, 0.0f, FFTCLDFBLEN ); + set_f( hFdCngCom->olapBufferSynth2_flt, 0.0f, FFTLEN ); /* Initialize quantizer */ set_f( hFdCngCom->sidNoiseEst_flt, 0.0f, NPART ); @@ -131,7 +133,7 @@ void initFdCngCom_flt( hFdCngCom->seed2 = 1; hFdCngCom->seed3 = 2; hFdCngCom->CngBitrate = -1; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /* Initialize noise estimation algorithm */ set_f( hFdCngCom->periodog_flt, 0.0f, PERIODOGLEN ); mhvals_flt( MSNUMSUBFR * MSSUBFRLEN, &( hFdCngCom->msM_win_flt ) ); @@ -140,15 +142,18 @@ void initFdCngCom_flt( set_f( hFdCngCom->msPsdSum_flt, 0.0f, 2 ); set_f( hFdCngCom->msSlope_flt, 0.0f, 2 ); set_f( hFdCngCom->msQeqInvAv_flt, 0.0f, 2 ); + hFdCngCom->init_old_flt = 0; +#endif hFdCngCom->msFrCnt_init_counter = 0; hFdCngCom->msFrCnt_init_thresh = 1; - hFdCngCom->init_old_flt = 0; hFdCngCom->offsetflag = 0; hFdCngCom->msFrCnt = MSSUBFRLEN; hFdCngCom->msMinBufferPtr = 0; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( hFdCngCom->msAlphaCor_flt, 0.3f, 2 ); hFdCngCom->coherence_flt = 0.5f; +#endif return; } @@ -831,7 +836,7 @@ static void getmidbands( return; } - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*------------------------------------------------------------------- * AnalysisSTFT_flt() * @@ -860,7 +865,7 @@ void AnalysisSTFT_flt( return; } - +#endif /*------------------------------------------------------------------- * SynthesisSTFT_flt() * @@ -1059,7 +1064,7 @@ void SynthesisSTFT_fx( return; } #endif - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*------------------------------------------------------------------- * SynthesisSTFT_dirac_flt() * @@ -1125,7 +1130,7 @@ void SynthesisSTFT_dirac_flt( return; } - +#endif #ifdef IVAS_FLOAT_FIXED void SynthesisSTFT_dirac_fx( Word32 *fftBuffer, /* i : FFT bins */ diff --git a/lib_com/float_to_fix_ops.c b/lib_com/float_to_fix_ops.c index 74c2cd642bff3a2cf1225aba0d698eb1de7d9efb..5024b356e57dd5ea6f0a24eab70dd9f3c29d5282 100644 --- a/lib_com/float_to_fix_ops.c +++ b/lib_com/float_to_fix_ops.c @@ -76,6 +76,76 @@ void floatToFixed_arr32( float *f, Word32 *i, Word16 Q, Word16 l ) i[j] = float_to_fix( f[j], Q ); } } + +float fixedToFloat_32( Word32 number, Word16 Q ) +{ + float val = 0.0f; + assert( fabs( Q ) <= 63 ); + if ( fabs( Q ) > 31 ) + { + if ( Q > 0 ) + { + val = (float) ( ( number / ( 1 << ( Q - 31 ) ) ) / ( (unsigned int) MAX_32 + 1 ) ); + } + else + { + val = (float) ( number * ( 1 << ( -Q - 31 ) ) * (unsigned int)MIN_32 ); + } + } + else + { + val = fixedToFloat( number, Q ); + } + return val; +} + +Word32 floatToFixed_32( float number, Word16 Q ) +{ + float val = 0.0f; + assert( fabs( Q ) <= 63 ); + if ( fabs( Q ) > 31 ) + { + if ( Q > 0 ) + { + val = ( number * ( (unsigned int) MAX_32 + 1 ) ) * ( 1 << ( Q - 31 ) ); + } + else + { + val = ( number / ( 1 << ( -Q - 31 ) ) ) / (unsigned int)MIN_32; + } + if ( val >= 0.0f ) + { + assert( (Word32) val <= MAX_32 ); + } + else + { + assert( (Word32) val >= MIN_32 ); + } + } + else + { + return floatToFixed( number, Q ); + } + + return (Word32) val; +} + +void floatToFixed_arrL32( float *f, Word32 *i, Word16 Q, Word16 l ) +{ + for ( int j = 0; j < l; j++ ) + { + i[j] = floatToFixed_32( f[j], Q ); + } +} + +void fixedToFloat_arrL32( Word32 *i, float *f, Word16 Q, Word16 l ) +{ + for ( int j = 0; j < l; j++ ) + { + f[j] = fixedToFloat_32( i[j], Q ); + } +} + void floatToFixed_arr(float *f, Word16 *i, Word16 Q, Word16 l) { for (int j = 0; j < l; j++) @@ -197,18 +267,17 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; hPrivateData = &st->hIGFDec->igfData; H_IGF_INFO hIGFInfo = &hPrivateData->igfInfo; - ACELP_config *pConfigAcelp = &( st->acelp_cfg ); + //ACELP_config *pConfigAcelp = &( st->acelp_cfg ); Word16 i = 0, - Q_old_synth = 0, Q_syn = 0, Q_synth_history = 0, Q_fer_samples = 0, - Q_cldfbAna_cldfb_state = 0, Q_cldfbBPF_cldfb_state = 0, Q_cldfbSyn_cldfb_state = 0, Q_cldfbSynHB_cldfb_state = 0, - Q_pst_old_syn = 0, - delay_comp = 0, Q_loBuffer = 0; + Q_old_synth = 0, Q_syn = 0, Q_synth_history = 0, /*Q_fer_samples = 0,*/ + Q_cldfbAna_cldfb_state = 0, Q_cldfbBPF_cldfb_state = 0, Q_cldfbSyn_cldfb_state = 0, Q_cldfbSynHB_cldfb_state = 0, + //Q_pst_old_syn = 0, + delay_comp = 0; Word16 Q_lsf_cng = Q_factor( 6400 ); - Word16 Q_tcxltp_mem_in = 0, Q_tcxltp_mem_out = 0, Q_tcxltp_gain_post_prev = 0; + Word16 Q_tcxltp_mem_in = 0, Q_tcxltp_mem_out = 0; TD_BWE_DEC_HANDLE hBWE_TD = st->hBWE_TD; - Word16 Q_state_lsyn_filt_shb = 0, Q_state_lsyn_filt_dwn_shb = 0, Q_mem_resamp_HB = 0, Q_syn_overlap = 0, Q_int_3_over_2_tbemem_dec = 0, Q_mem_resamp_HB_32k = 0, Q_prev_fb_ener_adjust = 0, Q_fb_state_lpc_syn = 0, - Q_genSHBsynth_Hilbert_Mem = 0, Q_genSHBsynth_state_lsyn_filt_shb_local = 0; + Word16 Q_state_lsyn_filt_shb = 0, Q_state_lsyn_filt_dwn_shb = 0, Q_mem_resamp_HB = 0, Q_syn_overlap = 0, Q_int_3_over_2_tbemem_dec = 0, Q_mem_resamp_HB_32k = 0/*, Q_prev_fb_ener_adjust = 0 */; if ( tofix ) { @@ -230,50 +299,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/ st->sr_core = getCoreSamplerateMode2( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); st->L_frame = extract_l( Mult_32_16( st->sr_core, 0x0290 ) ); - st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_float, 15 ); - Q_syn = Q_factor_arr( st->syn_float, 17 ); - floatToFixed_arr( st->syn_float, st->syn, Q_syn, M + 1 ); - //floatToFixed_arr( st->lsp_old, st->lsp_old_fx, 15, M ); - FOR( i = 0; i < M; i++ ) - { - st->mem_MA_fx[i] = (Word16) floatToFixed( (float) ( st->mem_MA[i] * 2.56 ), 0 ); - st->mem_AR_fx[i] = (Word16) floatToFixed( (float) ( st->mem_AR[i] * 2.56 ), 0 ); - } - IF( st->hTcxCfg ) - { - Word16 n = st->L_frame; - Word16 n0 = shr( imult1616( n, 9 ), 5 ); - Word16 n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ - Word16 n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ - n = NS2SA_fx2( st->output_Fs, FRAME_SIZE_NS ); - n0 = shr( imult1616( n, 9 ), 5 ); - n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ - n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ - FOR( i = 0; i < n0; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB[i] = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_FB_flt[i], 15 ); - } - FOR( i = n0; i < n / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB_trunc[i - n0].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_FB_flt[i], 15 ); - } - FOR( i = 0; i < n1 - n / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB_trunc[n1 - n / 2 - i - 1].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_FB_flt[n / 2 + i], 15 ); - } - FOR( i = 0; i < n2 / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_2_FB[i].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_2_FB_flt[i], 15 ); - } - FOR( i = n2 / 2; i < n2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_2_FB[n2 - i - 1].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_2_FB_flt[i], 15 ); - } - } - FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) - { - st->old_pitch_buf_fx[i] = floatToFixed( st->old_pitch_buf[i], 16 ); - } + IF( st->hTcxDec ) { st->hTcxDec->Q_old_syn_Overl = Q_factor_arr( st->hTcxDec->old_syn_Overl_float, L_FRAME32k / 2 ) - 1; @@ -290,26 +316,17 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( floatToFixed_arr( st->hTcxDec->syn_OverlFB_float, st->hTcxDec->syn_OverlFB, st->hTcxDec->Q_syn_OverlFB, L_FRAME_MAX / 2 ); floatToFixed_arr( st->hTcxDec->old_synth_float, st->hTcxDec->old_synth, Q_old_synth, OLD_SYNTH_INTERNAL_DEC ); floatToFixed_arr( st->hTcxDec->synth_history, st->hTcxDec->synth_history_fx, Q_synth_history, L_PROT48k + L_FRAME_MAX ); - Word16 Q_old_gaintcx_bfi = Q_factor( st->hTcxDec->old_gaintcx_bfi_float ); - st->hTcxDec->old_gaintcx_bfi = (Word16) floatToFixed( st->hTcxDec->old_gaintcx_bfi_float, Q_old_gaintcx_bfi ); st->hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); st->hTcxDec->tcxltp_last_gain_unmodified = (Word16) floatToFixed( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); st->output_frame_fx = st->hTcxDec->L_frameTCX; st->hTcxDec->CngLevelBackgroundTrace_bfi_fx = floatToFixed( st->hTcxDec->CngLevelBackgroundTrace_bfi, 15 ); st->hTcxDec->conceal_eof_gain = (Word16) floatToFixed( st->hTcxDec->conceal_eof_gain_float, 14 ); - st->hTcxDec->LastFrameLevel_bfi_fx = (Word16) floatToFixed( st->hTcxDec->LastFrameLevel_bfi, 15 ); - FOR( i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++ ) - { - st->hTcxDec->NoiseLevelMemory_bfi_fx[i] = (Word16) floatToFixed( st->hTcxDec->NoiseLevelMemory_bfi[i], 15 ); - } - st->hTcxDec->cummulative_damping_tcx = (Word16) floatToFixed( st->hTcxDec->cummulative_damping_tcx_float, 15 ); } IF( st->hHQ_core ) { - st->hHQ_core->Q_fer_samples = Q_factor_arr( st->hHQ_core->fer_samples + delay_comp, shr( st->hTcxDec->L_frameTCX, 1 ) ) - 1; st->hHQ_core->Q_old_out = Q_factor_arr( st->hHQ_core->old_out, L_FRAME48k ); st->hHQ_core->Q_old_outLB = Q_factor_arr( st->hHQ_core->old_outLB, L_FRAME32k ); - floatToFixed_arr( st->hHQ_core->fer_samples + delay_comp, st->hHQ_core->fer_samples_fx + delay_comp, Q_fer_samples, shr( st->hTcxDec->L_frameTCX, 1 ) ); + st->hHQ_core->Q_fer_samples = 0; floatToFixed_arr( st->hHQ_core->old_out, st->hHQ_core->old_out_fx, st->hHQ_core->Q_old_out, L_FRAME48k ); floatToFixed_arr( st->hHQ_core->old_outLB, st->hHQ_core->old_out_LB_fx, st->hHQ_core->Q_old_outLB, L_FRAME32k ); } @@ -333,22 +350,11 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( Q_cldfbSynHB_cldfb_state = Q_factor_arrL( st->cldfbSynHB->cldfb_state, st->cldfbSynHB->cldfb_state_length ) - 1; floatToFixed_arrL( st->cldfbSynHB->cldfb_state, st->cldfbSynHB->cldfb_state_fx, Q_cldfbSynHB_cldfb_state, st->cldfbSynHB->cldfb_state_length ); } - IF( st->hBPF ) - { - Q_pst_old_syn = Q_syn; - Q_pst_old_syn = Q_factor_arr( st->hBPF->pst_old_syn, NBPSF_PIT_MAX ); - floatToFixed_arr( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, Q_pst_old_syn, NBPSF_PIT_MAX ); - } - st->last_concealed_gain_syn_deemph = (Word16) floatToFixed( st->last_concealed_gain_syn_deemph_float, 14 ); - st->enr_old_fx = (Word16) floatToFixed( st->enr_old, 0 ); - floatToFixed_arr( st->previoussynth, st->previoussynth_fx, 0, 960 ); IF( st->hTcxLtpDec ) { Q_tcxltp_mem_in = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY ); Q_tcxltp_mem_out = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k ); - Q_tcxltp_gain_post_prev = Q_factor( st->hTcxLtpDec->tcxltp_gain_post_prev_float ); - st->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) floatToFixed( st->hTcxLtpDec->tcxltp_gain_post_prev_float, Q_tcxltp_gain_post_prev ); floatToFixed_arr( st->hTcxLtpDec->tcxltp_mem_in_float, st->hTcxLtpDec->tcxltp_mem_in, Q_tcxltp_mem_in, TCXLTP_MAX_DELAY ); floatToFixed_arr( st->hTcxLtpDec->tcxltp_mem_out_float, st->hTcxLtpDec->tcxltp_mem_out, Q_tcxltp_mem_out, L_FRAME48k ); } @@ -367,27 +373,13 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( floatToFixed_arr( hBWE_TD->syn_overlap, hBWE_TD->syn_overlap_fx, Q_syn_overlap, 20 ); Q_int_3_over_2_tbemem_dec = Q_factor_arr( hBWE_TD->int_3_over_2_tbemem_dec, 15 ); Q_mem_resamp_HB_32k = Q_factor_arr( hBWE_TD->mem_resamp_HB_32k, 7 ); - Q_prev_fb_ener_adjust = Q_factor( (Word16) st->hBWE_FD->prev_fb_ener_adjust ); - Q_fb_state_lpc_syn = Q_factor_arr( hBWE_TD->fb_state_lpc_syn, 10 ); - st->prev_fb_ener_adjust_fx = (Word16) floatToFixed( st->hBWE_FD->prev_fb_ener_adjust, Q_prev_fb_ener_adjust ); - floatToFixed_arr( hBWE_TD->fb_state_lpc_syn, hBWE_TD->fb_state_lpc_syn_fx, Q_fb_state_lpc_syn, 10 ); floatToFixed_arr( hBWE_TD->int_3_over_2_tbemem_dec, hBWE_TD->int_3_over_2_tbemem_dec_fx, Q_int_3_over_2_tbemem_dec, INTERP_3_2_MEM_LEN ); floatToFixed_arr( hBWE_TD->mem_resamp_HB_32k, hBWE_TD->mem_resamp_HB_32k_fx, Q_mem_resamp_HB_32k, 7 ); - Q_genSHBsynth_Hilbert_Mem = Q_factor_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem, 21 ); - floatToFixed_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, Q_genSHBsynth_Hilbert_Mem, 21 ); - Q_genSHBsynth_state_lsyn_filt_shb_local = Q_factor_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 6 ); - floatToFixed_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, Q_genSHBsynth_state_lsyn_filt_shb_local, 6 ); } - IF( st->hTECDec ) - { - Q_loBuffer = Q_factor_arr( st->hTECDec->loBuffer_flt, MAX_TEC_SMOOTHING_DEG ); - floatToFixed_arr( st->hTECDec->loBuffer_flt, st->hTECDec->loBuffer, Q_loBuffer, MAX_TEC_SMOOTHING_DEG ); - } - st->TcxBandwidth = (Word16) floatToFixed( st->TcxBandwidth_float, 15 ); + //st->TcxBandwidth = (Word16) floatToFixed( st->TcxBandwidth_float, 15 ); } else { - Q_syn = Q_factor_arr( st->syn_float, 17 ); hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM]; fixedToFloat_arr( &hGrid->whiteningThreshold[0][0], &hGrid->whiteningThreshold_flt[0][0], 13, IGF_MAX_TILES * 2 ); hGrid->gFactor_flt = fixedToFloat( hGrid->gFactor, 14 ); @@ -409,8 +401,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( st->hIGFDec->igfData.pSpecFlat_float = &st->hIGFDec->igfData.pSpecFlatBuf[0]; st->hIGFDec->igfData.igfInfo.nfSeed = &st->hIGFDec->igfData.igfInfo.nfSeedBuf[0]; } - st->preemph_fac_float = fixedToFloat( st->preemph_fac, 15 ); - st->TcxBandwidth_float = fixedToFloat( st->TcxBandwidth, 15 ); + //st->TcxBandwidth_float = fixedToFloat( st->TcxBandwidth, 15 ); IF( st->hBWE_TD != NULL ) { @@ -420,70 +411,12 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( Q_syn_overlap = Q_factor_arr( hBWE_TD->syn_overlap, 20 ); Q_int_3_over_2_tbemem_dec = Q_factor_arr( hBWE_TD->int_3_over_2_tbemem_dec, 15 ); Q_mem_resamp_HB_32k = Q_factor_arr( hBWE_TD->mem_resamp_HB_32k, 7 ); - Q_prev_fb_ener_adjust = Q_factor( (Word16) st->hBWE_FD->prev_fb_ener_adjust ); - Q_fb_state_lpc_syn = Q_factor_arr( hBWE_TD->fb_state_lpc_syn, 10 ); - Q_genSHBsynth_Hilbert_Mem = Q_factor_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem, 21 ); - Q_genSHBsynth_state_lsyn_filt_shb_local = Q_factor_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 6 ); - st->hBWE_TD->prev_tilt_para = 0.0f; fixedToFloat_arr( hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_shb, Q_state_lsyn_filt_shb, 6 ); fixedToFloat_arr( hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb, Q_state_lsyn_filt_dwn_shb, 6 ); fixedToFloat_arr( hBWE_TD->mem_resamp_HB_fx, hBWE_TD->mem_resamp_HB, Q_mem_resamp_HB, 13 ); fixedToFloat_arr( hBWE_TD->syn_overlap_fx, hBWE_TD->syn_overlap, Q_syn_overlap, 20 ); - fixedToFloat_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, Q_genSHBsynth_state_lsyn_filt_shb_local, HILBERT_MEM_SIZE ); - fixedToFloat_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_Hilbert_Mem, Q_genSHBsynth_Hilbert_Mem, HILBERT_MEM_SIZE ); fixedToFloat_arr( hBWE_TD->int_3_over_2_tbemem_dec_fx, hBWE_TD->int_3_over_2_tbemem_dec, Q_int_3_over_2_tbemem_dec, 15 ); fixedToFloat_arr( hBWE_TD->mem_resamp_HB_32k_fx, hBWE_TD->mem_resamp_HB_32k, Q_mem_resamp_HB_32k, 7 ); - //bool des = ( st->bwidth == WB && st->last_extl != WB_TBE ) || ( st->bwidth == SWB && st->last_extl != SWB_TBE ) || ( st->bwidth == FB && st->last_extl != FB_TBE ); - st->hBWE_FD->prev_fb_ener_adjust = fixedToFloat( st->prev_fb_ener_adjust_fx, Q_prev_fb_ener_adjust ); - } - st->preemph_fac_float = fixedToFloat( st->preemph_fac, 15 ); - IF( st->hTECDec != NULL ) - { - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - st->hTECDec->pGainTemp[i] = 0; - } - Q_loBuffer = Q_factor_arr( st->hTECDec->loBuffer_flt, MAX_TEC_SMOOTHING_DEG ); - fixedToFloat_arr( st->hTECDec->loBuffer, st->hTECDec->loBuffer_flt, Q_loBuffer, MAX_TEC_SMOOTHING_DEG ); - } - IF( st->hTcxCfg ) - { - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_min_lengthFB / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_window_minimumFB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.im, 15 ); - st->hTcxCfg->tcx_mdct_window_minimumFB_flt[st->hTcxCfg->tcx_mdct_window_min_lengthFB - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.re, 15 ); - } - Word16 n = st->L_frame; - Word16 n0 = shr( imult1616( n, 9 ), 5 ); - Word16 n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ - Word16 n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ - - n = NS2SA_fx2( st->output_Fs, FRAME_SIZE_NS ); - n0 = shr( imult1616( n, 9 ), 5 ); - n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ - n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ - FOR( i = 0; i < n0; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_FB[i], 15 ); - } - FOR( i = n0; i < n / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_FB_trunc[i - n0].v.im, 15 ); - } - FOR( i = 0; i < n1 - n / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB_flt[n / 2 + i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_FB_trunc[n1 - n / 2 - i - 1].v.re, 15 ); - } - FOR( i = 0; i < n2 / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_2_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_2_FB[i].v.im, 15 ); - } - FOR( i = n2 / 2; i < n2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_2_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_2_FB[n2 - i - 1].v.re, 15 ); - } - st->hTcxCfg->tcx_aldo_window_1_trunc_flt = st->hTcxCfg->tcx_aldo_window_1_flt + NS2SA( st->sr_core, N_ZERO_MDCT_NS ); - st->hTcxCfg->tcx_aldo_window_1_FB_trunc_flt = st->hTcxCfg->tcx_aldo_window_1_FB_flt + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ); } IF( st->hTcxDec ) { @@ -498,26 +431,10 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( fixedToFloat_arr( st->hTcxDec->old_synth, st->hTcxDec->old_synth_float, Q_old_synth, OLD_SYNTH_INTERNAL_DEC ); fixedToFloat_arr( st->hTcxDec->synth_history_fx, st->hTcxDec->synth_history, Q_synth_history, L_PROT48k + L_FRAME_MAX ); st->hTcxDec->q_synth_history_fx = Q_synth_history; - fixedToFloat_arr( st->hTcxDec->ltpGainMemory_fx, st->hTcxDec->ltpGainMemory, 15, N_LTP_GAIN_MEMS ); - st->hTcxDec->tcxltp_second_last_pitch_float = fixedToFloat( st->hTcxDec->tcxltp_second_last_pitch, 16 ); - st->hTcxDec->tcxltp_third_last_pitch_float = fixedToFloat( st->hTcxDec->tcxltp_third_last_pitch, 16 ); - Word16 Q_old_gaintcx_bfi = Q_factor( st->hTcxDec->old_gaintcx_bfi_float ); - st->hTcxDec->old_gaintcx_bfi_float = fixedToFloat( st->hTcxDec->old_gaintcx_bfi, Q_old_gaintcx_bfi ); st->hTcxDec->conceal_eof_gain_float = fixedToFloat( st->hTcxDec->conceal_eof_gain, 14 ); st->hTcxDec->CngLevelBackgroundTrace_bfi = fixedToFloat( st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, 15 ); - st->hTcxDec->LastFrameLevel_bfi = fixedToFloat( st->hTcxDec->LastFrameLevel_bfi_fx, 15 ); - FOR( i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++ ) - { - st->hTcxDec->NoiseLevelMemory_bfi[i] = fixedToFloat( st->hTcxDec->NoiseLevelMemory_bfi_fx[i], 15 ); - } - st->hTcxDec->cummulative_damping_tcx_float = fixedToFloat( st->hTcxDec->cummulative_damping_tcx, 15 ); - } - fixedToFloat_arr( st->syn, st->syn_float, Q_syn, M + 1 ); - FOR( i = 0; i < M; i++ ) - { - st->mem_AR[i] = fixedToFloat( L_mult( st->mem_AR_fx[i], 100 ), 9 ); - st->mem_MA[i] = fixedToFloat( L_mult( st->mem_MA_fx[i], 100 ), 9 ); } + IF( st->hHQ_core ) { fixedToFloat_arr( st->hHQ_core->old_out_fx, st->hHQ_core->old_out, st->hHQ_core->Q_old_out, L_FRAME48k ); @@ -544,46 +461,13 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( fixedToFloat_arrL( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_state, Q_cldfbSynHB_cldfb_state, st->cldfbSynHB->cldfb_state_length ); } - IF( st->hBPF ) - { - Q_pst_old_syn = Q_syn; - Q_pst_old_syn = Q_factor_arr( st->hBPF->pst_old_syn, NBPSF_PIT_MAX ); - fixedToFloat_arr( st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, Q_pst_old_syn, NBPSF_PIT_MAX ); - st->hBPF->pst_mem_deemp_err = 0; - } - Q_lsf_cng = Q_factor( 6400 ); - st->past_gpit_float = fixedToFloat( st->past_gpit, 0 ); - st->past_gcode_float = fixedToFloat( st->past_gcode, 0 ); - fixedToFloat_arr( st->Aq_cng, st->Aq_cng_float, 2, M ); - - if ( st->last_gain_syn_deemph == 16384 ) - { - st->last_gain_syn_deemph_float = 1; - } - st->last_concealed_gain_syn_deemph_float = fixedToFloat( st->last_concealed_gain_syn_deemph, 14 ); - st->enr_old = fixedToFloat( st->enr_old_fx, 0 ); - st->lp_gainc = fixedToFloat( st->lp_gainc_fx, 0 ); - st->lp_gainp = fixedToFloat( st->lp_gainp_fx, 0 ); - st->cummulative_damping_float = 1; - FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) - { - st->old_pitch_buf[i] = fixedToFloat( st->old_pitch_buf_fx[i], 16 ); - } - - st->old_fpitch_float = fixedToFloat( st->old_fpitch, 16 ); - FOR( i = 0; i < 8; i++ ) - { - st->dispMem[i] = 0; - } IF( st->hTcxLtpDec != NULL ) { Q_tcxltp_mem_in = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY ); Q_tcxltp_mem_out = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k ); - Q_tcxltp_gain_post_prev = Q_factor( st->hTcxLtpDec->tcxltp_gain_post_prev_float ); fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_in, st->hTcxLtpDec->tcxltp_mem_in_float, Q_tcxltp_mem_in, TCXLTP_MAX_DELAY ); fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_out, st->hTcxLtpDec->tcxltp_mem_out_float, Q_tcxltp_mem_out, L_FRAME48k ); - st->hTcxLtpDec->tcxltp_gain_post_prev_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain_post_prev, Q_tcxltp_gain_post_prev ); } IF( st->hTonalMDCTConc ) { @@ -592,22 +476,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( st->hTonalMDCTConc->scaleFactorsBackground_flt[i] = fixedToFloat( st->hTonalMDCTConc->scaleFactorsBackground[i], 15 ); } } - IF( st->hPlcInfo ) - { - FOR( i = 0; i < L_FRAME_MAX; i++ ) - { - //st->hPlcInfo->data_reci2[i] = fixedToFloat( st->hPlcInfo->data_reci2_fx[i], 0 ); - } - } - st->old_fpitchFB_float = fixedToFloat( st->old_fpitchFB, 16 ); - - IF( pConfigAcelp != NULL ) - { - pConfigAcelp->formant_enh_num_flt = fixedToFloat( pConfigAcelp->formant_enh_num, 15 ); - pConfigAcelp->formant_enh_den_flt = fixedToFloat( pConfigAcelp->formant_enh_den, 15 ); - st->acelp_cfg_rf.formant_enh_num_flt = fixedToFloat( st->acelp_cfg_rf.formant_enh_num, 15 ); - st->acelp_cfg_rf.formant_enh_den_flt = fixedToFloat( st->acelp_cfg_rf.formant_enh_den, 15 ); - } } } } @@ -641,17 +509,16 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; hPrivateData = &st->hIGFDec->igfData; H_IGF_INFO hIGFInfo = &hPrivateData->igfInfo; - ACELP_config *pConfigAcelp = &( st->acelp_cfg ); + //ACELP_config *pConfigAcelp = &( st->acelp_cfg ); Word16 /*i = 0,*/ - Q_old_synth = 0, Q_syn = 0, Q_synth_history = 0, Q_old_exc = 0, Q_fer_samples = 0, + Q_old_synth = 0, Q_syn = 0, Q_synth_history = 0, Q_old_exc = 0,/* Q_fer_samples = 0,*/ Q_cldfbAna_cldfb_state = 0, Q_cldfbBPF_cldfb_state = 0, Q_cldfbSyn_cldfb_state = 0, Q_cldfbSynHB_cldfb_state = 0, - Q_pst_old_syn = 0, - delay_comp = 0, Q_loBuffer = 0; + //Q_pst_old_syn = 0, + delay_comp = 0; - Word16 Q_tcxltp_mem_in = 0, Q_tcxltp_mem_out = 0, Q_tcxltp_gain_post_prev = 0; + Word16 Q_tcxltp_mem_in = 0, Q_tcxltp_mem_out = 0; TD_BWE_DEC_HANDLE hBWE_TD = st->hBWE_TD; - Word16 Q_state_lsyn_filt_shb = 0, Q_state_lsyn_filt_dwn_shb = 0, Q_mem_resamp_HB = 0, Q_syn_overlap = 0, Q_int_3_over_2_tbemem_dec = 0, Q_mem_resamp_HB_32k = 0, Q_prev_fb_ener_adjust = 0, Q_fb_state_lpc_syn = 0, - Q_genSHBsynth_Hilbert_Mem = 0, Q_genSHBsynth_state_lsyn_filt_shb_local = 0; + Word16 Q_state_lsyn_filt_shb = 0, Q_state_lsyn_filt_dwn_shb = 0, Q_mem_resamp_HB = 0, Q_syn_overlap = 0, Q_int_3_over_2_tbemem_dec = 0, Q_mem_resamp_HB_32k = 0/*, Q_prev_fb_ener_adjust = 0*/; if ( tofix ) { @@ -673,50 +540,8 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/ st->sr_core = getCoreSamplerateMode2( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); st->L_frame = extract_l( Mult_32_16( st->sr_core, 0x0290 ) ); - st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_float, 15 ); Q_syn = 0; - floatToFixed_arr( st->syn_float, st->syn, Q_syn, M + 1 ); - FOR( i = 0; i < M; i++ ) - { - st->mem_MA_fx[i] = (Word16) floatToFixed( (float) ( st->mem_MA[i] * 2.56 ), 0 ); - st->mem_AR_fx[i] = (Word16) floatToFixed( (float) ( st->mem_AR[i] * 2.56 ), 0 ); - } - IF( st->hTcxCfg ) - { - Word16 n = st->L_frame; - Word16 n0 = shr( imult1616( n, 9 ), 5 ); - Word16 n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ - Word16 n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ - n = NS2SA_fx2( st->output_Fs, FRAME_SIZE_NS ); - n0 = shr( imult1616( n, 9 ), 5 ); - n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ - n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ - FOR( i = 0; i < n0; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB[i] = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_FB_flt[i], 15 ); - } - FOR( i = n0; i < n / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB_trunc[i - n0].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_FB_flt[i], 15 ); - } - FOR( i = 0; i < n1 - n / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB_trunc[n1 - n / 2 - i - 1].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_FB_flt[n / 2 + i], 15 ); - } - FOR( i = 0; i < n2 / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_2_FB[i].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_2_FB_flt[i], 15 ); - } - FOR( i = n2 / 2; i < n2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_2_FB[n2 - i - 1].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_2_FB_flt[i], 15 ); - } - } - FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) - { - st->old_pitch_buf_fx[i] = floatToFixed( st->old_pitch_buf[i], 16 ); - } IF( st->hTcxDec ) { st->hTcxDec->Q_old_syn_Overl = 0; @@ -733,26 +558,17 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( floatToFixed_arr( st->hTcxDec->syn_OverlFB_float, st->hTcxDec->syn_OverlFB, st->hTcxDec->Q_syn_OverlFB, L_FRAME_MAX / 2 ); floatToFixed_arr( st->hTcxDec->old_synth_float, st->hTcxDec->old_synth, Q_old_synth, OLD_SYNTH_INTERNAL_DEC ); floatToFixed_arr( st->hTcxDec->synth_history, st->hTcxDec->synth_history_fx, Q_synth_history, L_PROT48k + L_FRAME_MAX ); - Word16 Q_old_gaintcx_bfi = Q_factor( st->hTcxDec->old_gaintcx_bfi_float ); - st->hTcxDec->old_gaintcx_bfi = (Word16) floatToFixed( st->hTcxDec->old_gaintcx_bfi_float, Q_old_gaintcx_bfi ); st->hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); st->hTcxDec->tcxltp_last_gain_unmodified = (Word16) floatToFixed( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); st->output_frame_fx = st->hTcxDec->L_frameTCX; st->hTcxDec->CngLevelBackgroundTrace_bfi_fx = floatToFixed( st->hTcxDec->CngLevelBackgroundTrace_bfi, 15 ); st->hTcxDec->conceal_eof_gain = (Word16) floatToFixed( st->hTcxDec->conceal_eof_gain_float, 14 ); - st->hTcxDec->LastFrameLevel_bfi_fx = (Word16) floatToFixed( st->hTcxDec->LastFrameLevel_bfi, 15 ); - FOR( i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++ ) - { - st->hTcxDec->NoiseLevelMemory_bfi_fx[i] = (Word16) floatToFixed( st->hTcxDec->NoiseLevelMemory_bfi[i], 15 ); - } - st->hTcxDec->cummulative_damping_tcx = (Word16) floatToFixed( st->hTcxDec->cummulative_damping_tcx_float, 15 ); } IF( st->hHQ_core ) { - st->hHQ_core->Q_fer_samples = Q_factor_arr( st->hHQ_core->fer_samples + delay_comp, shr( st->hTcxDec->L_frameTCX, 1 ) ) - 1; st->hHQ_core->Q_old_out = 0; st->hHQ_core->Q_old_outLB = 0; - floatToFixed_arr( st->hHQ_core->fer_samples + delay_comp, st->hHQ_core->fer_samples_fx + delay_comp, Q_fer_samples, shr( st->hTcxDec->L_frameTCX, 1 ) ); + st->hHQ_core->Q_fer_samples = 0; floatToFixed_arr( st->hHQ_core->old_out, st->hHQ_core->old_out_fx, st->hHQ_core->Q_old_out, L_FRAME48k ); floatToFixed_arr( st->hHQ_core->old_outLB, st->hHQ_core->old_out_LB_fx, st->hHQ_core->Q_old_outLB, L_FRAME32k ); } @@ -776,22 +592,10 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( Q_cldfbSynHB_cldfb_state = Q_factor_arrL( st->cldfbSynHB->cldfb_state, st->cldfbSynHB->cldfb_state_length ) - 1; floatToFixed_arrL( st->cldfbSynHB->cldfb_state, st->cldfbSynHB->cldfb_state_fx, Q_cldfbSynHB_cldfb_state, st->cldfbSynHB->cldfb_state_length ); } - IF( st->hBPF ) - { - Q_pst_old_syn = Q_syn; - Q_pst_old_syn = Q_factor_arr( st->hBPF->pst_old_syn, NBPSF_PIT_MAX ); - floatToFixed_arr( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, Q_pst_old_syn, NBPSF_PIT_MAX ); - } - - st->last_concealed_gain_syn_deemph = (Word16) floatToFixed( st->last_concealed_gain_syn_deemph_float, 14 ); - st->enr_old_fx = (Word16) floatToFixed( st->enr_old, 0 ); - floatToFixed_arr( st->previoussynth, st->previoussynth_fx, 0, 960 ); IF( st->hTcxLtpDec ) { Q_tcxltp_mem_in = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY ); Q_tcxltp_mem_out = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k ); - Q_tcxltp_gain_post_prev = Q_factor( st->hTcxLtpDec->tcxltp_gain_post_prev_float ); - st->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) floatToFixed( st->hTcxLtpDec->tcxltp_gain_post_prev_float, Q_tcxltp_gain_post_prev ); floatToFixed_arr( st->hTcxLtpDec->tcxltp_mem_in_float, st->hTcxLtpDec->tcxltp_mem_in, Q_tcxltp_mem_in, TCXLTP_MAX_DELAY ); floatToFixed_arr( st->hTcxLtpDec->tcxltp_mem_out_float, st->hTcxLtpDec->tcxltp_mem_out, Q_tcxltp_mem_out, L_FRAME48k ); } @@ -810,24 +614,9 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( floatToFixed_arr( hBWE_TD->syn_overlap, hBWE_TD->syn_overlap_fx, Q_syn_overlap, 20 ); Q_int_3_over_2_tbemem_dec = Q_factor_arr( hBWE_TD->int_3_over_2_tbemem_dec, 15 ); Q_mem_resamp_HB_32k = Q_factor_arr( hBWE_TD->mem_resamp_HB_32k, 7 ); - Q_prev_fb_ener_adjust = Q_factor( (Word16) st->hBWE_FD->prev_fb_ener_adjust ); - Q_fb_state_lpc_syn = Q_factor_arr( hBWE_TD->fb_state_lpc_syn, 10 ); - st->prev_fb_ener_adjust_fx = (Word16) floatToFixed( st->hBWE_FD->prev_fb_ener_adjust, Q_prev_fb_ener_adjust ); - floatToFixed_arr( hBWE_TD->fb_state_lpc_syn, hBWE_TD->fb_state_lpc_syn_fx, Q_fb_state_lpc_syn, 10 ); floatToFixed_arr( hBWE_TD->int_3_over_2_tbemem_dec, hBWE_TD->int_3_over_2_tbemem_dec_fx, Q_int_3_over_2_tbemem_dec, INTERP_3_2_MEM_LEN ); floatToFixed_arr( hBWE_TD->mem_resamp_HB_32k, hBWE_TD->mem_resamp_HB_32k_fx, Q_mem_resamp_HB_32k, 7 ); - Q_genSHBsynth_Hilbert_Mem = Q_factor_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem, 21 ); - floatToFixed_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, Q_genSHBsynth_Hilbert_Mem, 21 ); - Q_genSHBsynth_state_lsyn_filt_shb_local = Q_factor_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 6 ); - floatToFixed_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, Q_genSHBsynth_state_lsyn_filt_shb_local, 6 ); } - IF( st->hTECDec ) - { - Q_loBuffer = Q_factor_arr( st->hTECDec->loBuffer_flt, MAX_TEC_SMOOTHING_DEG ); - floatToFixed_arr( st->hTECDec->loBuffer_flt, st->hTECDec->loBuffer, Q_loBuffer, MAX_TEC_SMOOTHING_DEG ); - } - st->TcxBandwidth = (Word16) floatToFixed( st->TcxBandwidth_float, 15 ); - } else { @@ -854,8 +643,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( st->hIGFDec->igfData.pSpecFlat_float = &st->hIGFDec->igfData.pSpecFlatBuf[0]; st->hIGFDec->igfData.igfInfo.nfSeed = &st->hIGFDec->igfData.igfInfo.nfSeedBuf[0]; } - st->preemph_fac_float = fixedToFloat( st->preemph_fac, 15 ); - st->TcxBandwidth_float = fixedToFloat( st->TcxBandwidth, 15 ); + //st->TcxBandwidth_float = fixedToFloat( st->TcxBandwidth, 15 ); IF( st->hBWE_TD != NULL ) { Q_state_lsyn_filt_shb = Q_factor_arr( hBWE_TD->state_lsyn_filt_shb, 6 ); @@ -864,75 +652,16 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( Q_syn_overlap = Q_factor_arr( hBWE_TD->syn_overlap, 20 ); Q_int_3_over_2_tbemem_dec = Q_factor_arr( hBWE_TD->int_3_over_2_tbemem_dec, 15 ); Q_mem_resamp_HB_32k = Q_factor_arr( hBWE_TD->mem_resamp_HB_32k, 7 ); - Q_prev_fb_ener_adjust = Q_factor( (Word16) st->hBWE_FD->prev_fb_ener_adjust ); - Q_fb_state_lpc_syn = Q_factor_arr( hBWE_TD->fb_state_lpc_syn, 10 ); - Q_genSHBsynth_Hilbert_Mem = Q_factor_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem, 21 ); - Q_genSHBsynth_state_lsyn_filt_shb_local = Q_factor_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 6 ); - st->hBWE_TD->prev_tilt_para = 0.0f; fixedToFloat_arr( hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_shb, Q_state_lsyn_filt_shb, 6 ); fixedToFloat_arr( hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb, Q_state_lsyn_filt_dwn_shb, 6 ); fixedToFloat_arr( hBWE_TD->mem_resamp_HB_fx, hBWE_TD->mem_resamp_HB, Q_mem_resamp_HB, 13 ); fixedToFloat_arr( hBWE_TD->syn_overlap_fx, hBWE_TD->syn_overlap, Q_syn_overlap, 20 ); - fixedToFloat_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, Q_genSHBsynth_state_lsyn_filt_shb_local, HILBERT_MEM_SIZE ); - fixedToFloat_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_Hilbert_Mem, Q_genSHBsynth_Hilbert_Mem, HILBERT_MEM_SIZE ); fixedToFloat_arr( hBWE_TD->int_3_over_2_tbemem_dec_fx, hBWE_TD->int_3_over_2_tbemem_dec, Q_int_3_over_2_tbemem_dec, 15 ); fixedToFloat_arr( hBWE_TD->mem_resamp_HB_32k_fx, hBWE_TD->mem_resamp_HB_32k, Q_mem_resamp_HB_32k, 7 ); - // bool des = ( st->bwidth == WB && st->last_extl != WB_TBE ) || ( st->bwidth == SWB && st->last_extl != SWB_TBE ) || ( st->bwidth == FB && st->last_extl != FB_TBE ); - st->hBWE_FD->prev_fb_ener_adjust = fixedToFloat( st->prev_fb_ener_adjust_fx, Q_prev_fb_ener_adjust ); - } - st->preemph_fac_float = fixedToFloat( st->preemph_fac, 15 ); - IF( st->hTECDec != NULL ) - { - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - st->hTECDec->pGainTemp[i] = 0; - } - Q_loBuffer = Q_factor_arr( st->hTECDec->loBuffer_flt, MAX_TEC_SMOOTHING_DEG ); - fixedToFloat_arr( st->hTECDec->loBuffer, st->hTECDec->loBuffer_flt, Q_loBuffer, MAX_TEC_SMOOTHING_DEG ); - } - IF( st->hTcxCfg ) - { - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_min_lengthFB / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_window_minimumFB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.im, 15 ); - st->hTcxCfg->tcx_mdct_window_minimumFB_flt[st->hTcxCfg->tcx_mdct_window_min_lengthFB - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.re, 15 ); - } - Word16 n = st->L_frame; - Word16 n0 = shr( imult1616( n, 9 ), 5 ); - Word16 n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ - Word16 n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ - - n = NS2SA_fx2( st->output_Fs, FRAME_SIZE_NS ); - n0 = shr( imult1616( n, 9 ), 5 ); - n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ - n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ - FOR( i = 0; i < n0; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_FB[i], 15 ); - } - FOR( i = n0; i < n / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_FB_trunc[i - n0].v.im, 15 ); - } - FOR( i = 0; i < n1 - n / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB_flt[n / 2 + i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_FB_trunc[n1 - n / 2 - i - 1].v.re, 15 ); - } - FOR( i = 0; i < n2 / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_2_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_2_FB[i].v.im, 15 ); - } - FOR( i = n2 / 2; i < n2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_2_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_2_FB[n2 - i - 1].v.re, 15 ); - } - st->hTcxCfg->tcx_aldo_window_1_trunc_flt = st->hTcxCfg->tcx_aldo_window_1_flt + NS2SA( st->sr_core, N_ZERO_MDCT_NS ); - st->hTcxCfg->tcx_aldo_window_1_FB_trunc_flt = st->hTcxCfg->tcx_aldo_window_1_FB_flt + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ); } IF( st->hTcxDec ) { Q_old_synth = Q_syn; - // Q_synth_history = Q_factor_arr( st->hTcxDec->synth_history, L_PROT48k + L_FRAME_MAX ); Q_synth_history = 0; st->hTcxDec->Q_old_syn_Overl = st->Q_syn + 1; fixedToFloat_arr( st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl_float, st->hTcxDec->Q_old_syn_Overl, L_FRAME32k / 2 ); @@ -943,33 +672,16 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( fixedToFloat_arr( st->hTcxDec->old_synth, st->hTcxDec->old_synth_float, Q_old_synth, OLD_SYNTH_INTERNAL_DEC ); fixedToFloat_arr( st->hTcxDec->synth_history_fx, st->hTcxDec->synth_history, Q_synth_history, L_PROT48k + L_FRAME_MAX ); st->hTcxDec->q_synth_history_fx = Q_synth_history; - fixedToFloat_arr( st->hTcxDec->ltpGainMemory_fx, st->hTcxDec->ltpGainMemory, 15, N_LTP_GAIN_MEMS ); - st->hTcxDec->tcxltp_second_last_pitch_float = fixedToFloat( st->hTcxDec->tcxltp_second_last_pitch, 16 ); - st->hTcxDec->tcxltp_third_last_pitch_float = fixedToFloat( st->hTcxDec->tcxltp_third_last_pitch, 16 ); - Word16 Q_old_gaintcx_bfi = Q_factor( st->hTcxDec->old_gaintcx_bfi_float ); - st->hTcxDec->old_gaintcx_bfi_float = fixedToFloat( st->hTcxDec->old_gaintcx_bfi, Q_old_gaintcx_bfi ); st->hTcxDec->conceal_eof_gain_float = fixedToFloat( st->hTcxDec->conceal_eof_gain, 14 ); st->hTcxDec->CngLevelBackgroundTrace_bfi = fixedToFloat( st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, 15 ); st->hTcxDec->conCngLevelBackgroundTrace = (Word16) st->hTcxDec->CngLevelBackgroundTrace_bfi_fx; st->hTcxDec->conCngLevelBackgroundTrace_e = 0; st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; - st->hTcxDec->LastFrameLevel_bfi = fixedToFloat( st->hTcxDec->LastFrameLevel_bfi_fx, 15 ); st->hTcxDec->conLastFrameLevel = st->hTcxDec->LastFrameLevel_bfi_fx; st->hTcxDec->conLastFrameLevel_e = 0; - FOR( i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++ ) - { - st->hTcxDec->NoiseLevelMemory_bfi[i] = fixedToFloat( st->hTcxDec->NoiseLevelMemory_bfi_fx[i], 15 ); - st->hTcxDec->conNoiseLevelMemory[i] = st->hTcxDec->NoiseLevelMemory_bfi_fx[i]; - } - st->hTcxDec->cummulative_damping_tcx_float = fixedToFloat( st->hTcxDec->cummulative_damping_tcx, 15 ); - } - fixedToFloat_arr( st->syn, st->syn_float, Q_syn, M + 1 ); - FOR( i = 0; i < M; i++ ) - { - st->mem_AR[i] = fixedToFloat( L_mult( st->mem_AR_fx[i], 100 ), 9 ); - st->mem_MA[i] = fixedToFloat( L_mult( st->mem_MA_fx[i], 100 ), 9 ); } + IF( st->hHQ_core ) { fixedToFloat_arr( st->hHQ_core->old_out_fx, st->hHQ_core->old_out, st->hHQ_core->Q_old_out, L_FRAME48k ); @@ -996,45 +708,12 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( fixedToFloat_arrL( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_state, Q_cldfbSynHB_cldfb_state, st->cldfbSynHB->cldfb_state_length ); } - IF( st->hBPF ) - { - Q_pst_old_syn = Q_syn; - Q_pst_old_syn = Q_factor_arr( st->hBPF->pst_old_syn, NBPSF_PIT_MAX ); - fixedToFloat_arr( st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, Q_pst_old_syn, NBPSF_PIT_MAX ); - st->hBPF->pst_mem_deemp_err = 0; - } - - st->past_gpit_float = fixedToFloat( st->past_gpit, 0 ); - st->past_gcode_float = fixedToFloat( st->past_gcode, 0 ); - fixedToFloat_arr( st->Aq_cng, st->Aq_cng_float, 2, M ); - - if ( st->last_gain_syn_deemph == 16384 ) - { - st->last_gain_syn_deemph_float = 1; - } - st->last_concealed_gain_syn_deemph_float = fixedToFloat( st->last_concealed_gain_syn_deemph, 14 ); - st->enr_old = fixedToFloat( st->enr_old_fx, 0 ); - st->lp_gainc = fixedToFloat( st->lp_gainc_fx, 3 ); - st->lp_gainp = fixedToFloat( st->lp_gainp_fx, 14 ); - st->cummulative_damping_float = 1; - FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) - { - st->old_pitch_buf[i] = fixedToFloat( st->old_pitch_buf_fx[i], 16 ); - } - - st->old_fpitch_float = fixedToFloat( st->old_fpitch, 16 ); - FOR( i = 0; i < 8; i++ ) - { - st->dispMem[i] = 0; - } IF( st->hTcxLtpDec != NULL ) { Q_tcxltp_mem_in = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY ); Q_tcxltp_mem_out = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k ); - Q_tcxltp_gain_post_prev = Q_factor( st->hTcxLtpDec->tcxltp_gain_post_prev_float ); fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_in, st->hTcxLtpDec->tcxltp_mem_in_float, Q_tcxltp_mem_in, TCXLTP_MAX_DELAY ); fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_out, st->hTcxLtpDec->tcxltp_mem_out_float, Q_tcxltp_mem_out, L_FRAME48k ); - st->hTcxLtpDec->tcxltp_gain_post_prev_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain_post_prev, Q_tcxltp_gain_post_prev ); } IF( st->hTonalMDCTConc ) { @@ -1043,22 +722,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( st->hTonalMDCTConc->scaleFactorsBackground_flt[i] = fixedToFloat( st->hTonalMDCTConc->scaleFactorsBackground[i], 15 ); } } - IF( st->hPlcInfo ) - { - FOR( i = 0; i < L_FRAME_MAX; i++ ) - { - //st->hPlcInfo->data_reci2[i] = fixedToFloat( st->hPlcInfo->data_reci2_fx[i], 0 ); - } - } - st->old_fpitchFB_float = fixedToFloat( st->old_fpitchFB, 16 ); - - IF( pConfigAcelp != NULL ) - { - pConfigAcelp->formant_enh_num_flt = fixedToFloat( pConfigAcelp->formant_enh_num, 15 ); - pConfigAcelp->formant_enh_den_flt = fixedToFloat( pConfigAcelp->formant_enh_den, 15 ); - st->acelp_cfg_rf.formant_enh_num_flt = fixedToFloat( st->acelp_cfg_rf.formant_enh_num, 15 ); - st->acelp_cfg_rf.formant_enh_den_flt = fixedToFloat( st->acelp_cfg_rf.formant_enh_den, 15 ); - } } } @@ -1075,10 +738,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( } st->hTcxDec->tcxltp_last_gain_unmodified = (Word16) floatToFixed( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); - st->hTcxDec->tcxltp_second_last_pitch = floatToFixed( st->hTcxDec->tcxltp_second_last_pitch_float, 16 ); - st->hTcxDec->tcxltp_third_last_pitch = floatToFixed( st->hTcxDec->tcxltp_third_last_pitch_float, 16 ); - st->old_fpitch = floatToFixed( st->old_fpitch_float, Q16 ); - floatToFixed_arrL( st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2 ); if ( st->hTonalMDCTConc != NULL ) { floatToFixed_arr( st->hTonalMDCTConc->secondLastPcmOut_float, st->hTonalMDCTConc->secondLastPcmOut, 0, st->hTonalMDCTConc->nSamples ); @@ -1086,56 +745,19 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( st->Q_syn = 0; - for ( int p = 0; p < M; p++ ) - { - st->mem_MA_fx[p] = (Word16) ( st->mem_MA[p] * 2.56 ); - st->mem_AR_fx[p] = (Word16) ( st->mem_AR[p] * 2.56 ); - } - - for ( int p = 0; p < 2 * NB_SUBFR16k + 2; p++ ) - { - st->old_pitch_buf_fx[p] = (Word32) ( st->old_pitch_buf[p] * ONE_IN_Q16 ); - } for ( int p = 0; p < st->L_frame; p++ ) { st->hTcxDec->old_excFB_fx[p] = (Word16) ( st->hTcxDec->old_excFB[p] * ( 1u << st->Q_exc ) ); } st->prev_Q_syn = st->Q_syn; - st->old_fpitchFB = (Word32) ( st->old_fpitchFB_float * ONE_IN_Q16 ); - st->old_fpitch = (Word32) ( st->old_fpitch_float * ONE_IN_Q16 ); - st->lp_gainp_fx = (Word16) floatToFixed( st->lp_gainp, Q14 ); - - st->hTcxDec->gainHelper = (Word16) floatToFixed( st->hTcxDec->gainHelper_float, Q14 ); - st->hTcxDec->gainHelper_e = 1; - st->hTcxDec->stepCompensate = (Word16) floatToFixed( st->hTcxDec->stepCompensate_float, Q14 ); - st->hTcxDec->stepCompensate_e = 1; - st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_float, Q15 ); - st->hTcxDec->damping = (Word16) floatToFixed( st->hTcxDec->damping_float, Q14 ); - st->old_fpitch = float_to_fix( st->old_fpitch_float, Q16 ); - if ( st->hPlcInfo ) - { - //st->hPlcInfo->step_concealgain_fx = (Word16) floatToFixed( st->hPlcInfo->step_concealgain, Q15 ); - } st->hTcxDec->conceal_eof_gain = (Word16) floatToFixed( st->hTcxDec->conceal_eof_gain_float, Q14 ); st->hTcxDec->conCngLevelBackgroundTrace = (Word16) floatToFixed( st->hTcxDec->CngLevelBackgroundTrace_bfi, Q15 - st->hTcxDec->conCngLevelBackgroundTrace_e ); - st->hTcxDec->conLastFrameLevel = (Word16) floatToFixed( st->hTcxDec->LastFrameLevel_bfi, 15 - st->hTcxDec->conLastFrameLevel_e ); if ( st->hTcxDec->conNoiseLevelMemory_e[0] < 0 ) { set16_fx( st->hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); } - if ( st->hPlcInfo ) - { - //st->hPlcInfo->recovery_gain = (Word16) floatToFixed( st->hPlcInfo->recovery_gain_float, Q14 ); - //st->hPlcInfo->step_concealgain_fx = (Word16) floatToFixed( st->hPlcInfo->step_concealgain, Q15 ); - } - floatToFixed_arr( st->hTcxDec->NoiseLevelMemory_bfi, st->hTcxDec->conNoiseLevelMemory, Q15, PLC_MIN_STAT_BUFF_SIZE ); st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; - floatToFixed_arrL( st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2 ); - floatToFixed_arr( st->syn_float, st->syn, 0, M + 1 ); - - st->old_fpitch = floatToFixed( st->old_fpitch_float, Q16 ); - st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_float, Q15 ); if ( hTcxLtpDec->tcxltp ) { hTcxDec->tcxltp_last_gain_unmodified = (Word16) floatToFixed( hTcxDec->tcxltp_last_gain_unmodified_float, Q15 ); @@ -1147,16 +769,15 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( { floatToFixed_arr( st->p_bpf_noise_buf_float, st->p_bpf_noise_buf, 0, L_FRAME_16k ); } - floatToFixed_arr( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); - - st->mem_error = floatToFixed( st->hBPF->pst_mem_deemp_err, Q16 ); + st->mem_error = st->hBPF->pst_mem_deemp_err_fx; + if ( st->hFdCngDec != NULL && ( st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) && st->total_brate <= MAX_ACELP_BRATE ) { - for ( int p = 0; p < PERIODOGLEN; p++ ) - { - st->hFdCngDec->hFdCngCom->periodog[p] = (Word32) ( st->hFdCngDec->hFdCngCom->periodog_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->periodog_exp ) ) ); - } + //for ( int p = 0; p < PERIODOGLEN; p++ ) + //{ + // st->hFdCngDec->hFdCngCom->periodog[p] = (Word32) ( st->hFdCngDec->hFdCngCom->periodog_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->periodog_exp ) ) ); + //} for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) { st->hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32) ( st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); @@ -1165,19 +786,9 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) { st->hFdCngDec->msNoiseEst[p] = (Word32) ( st->hFdCngDec->msNoiseEst_float[p] * ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); - st->hFdCngDec->msPeriodog[p] = (Word32) ( st->hFdCngDec->msPeriodog_float[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); - st->hFdCngDec->msPeriodog_ST_fx[p] = (Word32) ( st->hFdCngDec->msPeriodog_ST[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); - } - for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) - { - if ( ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << Q15 ) ) >= (float) MAX_32 ) - { - st->hFdCngDec->msMinBuf[p] = MAX_32; - } - else - { - st->hFdCngDec->msMinBuf[p] = (Word32) ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << ( 31 - 6 ) ) ); - } + // st->hFdCngDec->msPeriodog[p] = (Word32) ( st->hFdCngDec->msPeriodog_float[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); + //st->hFdCngDec->msPeriodog_ST_fx[p] = (Word32) ( st->hFdCngDec->msPeriodog_ST[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); + } st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4 @@ -1185,49 +796,27 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( { st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32) ( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); } - st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; - st->hFdCngDec->partNoiseShape_exp = 31 - Q4; - for ( int p = 0; p < NPART; p++ ) - { - st->hFdCngDec->hFdCngCom->sidNoiseEst[p] = (Word32) ( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ) ); - } - for ( int p = 0; p < 24; p++ ) - { - st->hFdCngDec->partNoiseShape[p] = (Word32) ( st->hFdCngDec->partNoiseShape_float[p] * ( 1u << ( 31 - st->hFdCngDec->partNoiseShape_exp ) ) ); - } + //st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; + //st->hFdCngDec->partNoiseShape_exp = 31 - Q4; + //for ( int p = 0; p < NPART; p++ ) + //{ + // st->hFdCngDec->hFdCngCom->sidNoiseEst[p] = (Word32) ( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ) ); + //} + //for ( int p = 0; p < 24; p++ ) + //{ + //st->hFdCngDec->partNoiseShape[p] = (Word32) ( st->hFdCngDec->partNoiseShape_float[p] * ( 1u << ( 31 - st->hFdCngDec->partNoiseShape_exp ) ) ); + //} } - //st->gamma = float_to_fix16( st->gamma_float, Q15 ); - st->hTcxDec->cummulative_damping_tcx = float_to_fix16( st->hTcxDec->cummulative_damping_tcx_float, Q15 ); - // st->Mode2_lp_gainp = float_to_fix(st->lp_gainp, Q16); - st->Mode2_lp_gainp = float_to_fix( st->lp_gainp, Q29 ); - f2me_16( st->last_gain_syn_deemph_float, &st->last_gain_syn_deemph, &st->last_gain_syn_deemph_e ); - f2me_16( st->last_concealed_gain_syn_deemph_float, &st->last_concealed_gain_syn_deemph, &st->last_concealed_gain_syn_deemph_e ); - //st->last_concealed_gain_syn_deemph = float_to_fix16( st->last_concealed_gain_syn_deemph_float, Q14 ); - //st->last_concealed_gain_syn_deemph_e = 1; - f2me_16( st->hTcxDec->old_gaintcx_bfi_float, &st->hTcxDec->old_gaintcx_bfi, &st->hTcxDec->old_gaintcx_bfi_e ); - - FOR( Word16 l = 0; l < N_LTP_GAIN_MEMS; l++ ) - { - st->hTcxDec->ltpGainMemory_fx[l] = float_to_fix16( st->hTcxDec->ltpGainMemory[l], Q15 ); - } - st->hTonalMDCTConc->lastPitchLag = float_to_fix( st->hTonalMDCTConc->lastPitchLag_float, Q16 ); - // st->hTonalMDCTConc->nFramesLost = float_to_fix16(st->hTonalMDCTConc->nFramesLost_float, Q1); - /*===========*/ IF(bfi && st->tonal_mdct_plc_active && NE_16(st->element_mode, IVAS_CPE_MDCT)) { - FOR(Word16 i = 0; i < FDNS_NPTS; i++) + FOR(Word16 ii = 0; ii < FDNS_NPTS; ii++) { - f2me_16(st->hTonalMDCTConc->secondLastBlockData.scaleFactors_float[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]); - st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e = s_max(st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]); + f2me_16(st->hTonalMDCTConc->secondLastBlockData.scaleFactors_float[ii], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors[ii], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[ii]); + st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e = s_max(st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[ii]); } } - IF(st->enablePlcWaveadjust) - { - //f2me_buf(st->hPlcInfo->data_reci2, st->hPlcInfo->data_reci2_fx, &st->hPlcInfo->data_reci2_scale, st->hPlcInfo->L_frameTCX); - } - // u8bit to 16bit FOR(int l = 0; l < IGF_START_MX; l++) { @@ -1249,19 +838,12 @@ void fixed_to_float_stereo_tcx_core_dec( float *signal_out ) { TCX_DEC_HANDLE hTcxDec = st->hTcxDec; - Word16 q_Aq; + //Word16 q_Aq; st->hTcxDec->tcxltp_last_gain_unmodified_float = (Word16) fixedToFloat( st->hTcxDec->tcxltp_last_gain_unmodified, Q15 ); if ( EQ_16( st->core, ACELP_CORE ) ) { - for ( int p = 0; p < M + 1; p++ ) - { - st->syn_float[p] = (float) st->syn[p] / (float) pow( 2, st->Q_syn ); - } - for ( int p = 0; p < 2 * NB_SUBFR16k + 2; p++ ) - { - st->old_pitch_buf[p] = (float) st->old_pitch_buf_fx[p] / ONE_IN_Q16; - } + for ( int p = 0; p < st->L_frame / 2; p++ ) { st->hTcxDec->syn_OverlFB_float[p] = (float) st->hTcxDec->syn_OverlFB[p] / (float) pow( 2, st->Q_syn ); @@ -1279,19 +861,6 @@ void fixed_to_float_stereo_tcx_core_dec( { st->hTcxDec->old_excFB[p] = (float) ( st->hTcxDec->old_excFB_fx[p] ) / ( 1u << st->Q_exc ); } - st->preemph_fac_float = (float) st->preemph_fac / MAX_16; - st->lp_gainc = (float) st->Mode2_lp_gainc / ONE_IN_Q16; - st->lp_gainp = (float) st->Mode2_lp_gainp / ONE_IN_Q29; - st->cummulative_damping_float = (float) st->cummulative_damping / MAX_16; - - if ( !st->tcxonly ) - { - for ( int p = 0; p < shr( st->L_frame, 6 ); p++ ) - { - q_Aq = 15 - ( norm_s( st->Aq_cng[p * ( M + 1 )] - 1 ) ); - fixedToFloat_arr( st->Aq_cng + p * ( M + 1 ), st->Aq_cng_float + p * ( M + 1 ), q_Aq, ( M + 1 ) ); - } - } } if ( st->lpcQuantization ) @@ -1300,31 +869,10 @@ void fixed_to_float_stereo_tcx_core_dec( st->mid_lsf_int = st->mid_lsf_int; } - for ( int p = 0; p < M; p++ ) - { - st->mem_MA[p] = (float) st->mem_MA_fx[p] / 2.56f; - st->mem_AR[p] = (float) st->mem_AR_fx[p] / 2.56f; - } - - fixedToFloat_arr( st->syn, st->syn_float, 0, M + 1 ); hTcxDec->tcxltp_last_gain_unmodified_float = fixedToFloat( hTcxDec->tcxltp_last_gain_unmodified, Q15 ); - st->hTcxLtpDec->tcxltp_gain_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain, Q15 ); st->hTcxDec->conceal_eof_gain_float = fixedToFloat( st->hTcxDec->conceal_eof_gain, Q14 ); - st->old_fpitch_float = fix_to_float( st->old_fpitch, Q16 ); - for ( int p = 0; p < PLC_MIN_STAT_BUFF_SIZE; p++ ) - { - st->hTcxDec->NoiseLevelMemory_bfi[p] = fixedToFloat( st->hTcxDec->conNoiseLevelMemory[p], 15 - st->hTcxDec->conNoiseLevelMemory_e[p] ); - } - fixedToFloat_arrL( st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2 ); - st->hTcxDec->CngLevelBackgroundTrace_bfi = fixedToFloat( st->hTcxDec->conCngLevelBackgroundTrace, 15 - st->hTcxDec->conCngLevelBackgroundTrace_e ); - st->hTcxDec->LastFrameLevel_bfi = fixedToFloat( st->hTcxDec->conLastFrameLevel, 15 - st->hTcxDec->conLastFrameLevel_e ); - if ( st->hPlcInfo ) - { - //st->hPlcInfo->recovery_gain_float = fixedToFloat( st->hPlcInfo->recovery_gain, Q14 ); - //st->hPlcInfo->step_concealgain = fixedToFloat( st->hPlcInfo->step_concealgain_fx, Q15 ); - } - st->enr_old = (float) st->enr_old_fx; + st->hTcxDec->CngLevelBackgroundTrace_bfi = fixedToFloat( st->hTcxDec->conCngLevelBackgroundTrace, 15 - st->hTcxDec->conCngLevelBackgroundTrace_e ); fixedToFloat_arr( hTcxDec->old_synth, hTcxDec->old_synth_float, 0, hTcxDec->old_synth_len ); fixedToFloat_arr( hTcxDec->synth_history_fx, hTcxDec->synth_history, 0, NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ) ); @@ -1336,9 +884,8 @@ void fixed_to_float_stereo_tcx_core_dec( { fixedToFloat_arr( st->p_bpf_noise_buf, st->p_bpf_noise_buf_float, 0, L_FRAME_16k ); } - fixedToFloat_arr( st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, 0, NBPSF_PIT_MAX ); - st->hBPF->pst_mem_deemp_err = fixedToFloat( st->mem_error, Q16 ); + st->hBPF->pst_mem_deemp_err_fx = st->mem_error; /*=================================*/ if ( st->hFdCngDec != NULL && ( st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) && st->total_brate <= MAX_ACELP_BRATE ) { @@ -1357,7 +904,7 @@ void fixed_to_float_stereo_tcx_core_dec( ( st->m_frame_type == ZERO_FRAME ) ) { st->hTcxDec->CngLevelBackgroundTrace_bfi = fix_to_float( st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, ( 31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp ) ); - st->cngTDLevel_float = fixedToFloat( st->cngTDLevel, ( 15 - st->cngTDLevel_e ) ); + //st->cngTDLevel_float = fixedToFloat( st->cngTDLevel, ( 15 - st->cngTDLevel_e ) ); for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) { st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->fftBuffer[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); @@ -1370,16 +917,12 @@ void fixed_to_float_stereo_tcx_core_dec( { st->hFdCngDec->bandNoiseShape_float[p] = ( (float) st->hFdCngDec->bandNoiseShape[p] / ( 1u << ( 31 - st->hFdCngDec->bandNoiseShape_exp ) ) ); } - for ( int p = 0; p < st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; p++ ) - { - st->hFdCngDec->hFdCngCom->periodog_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->periodog[p] / (float) ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->periodog_exp ) ) ); - } + + for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) { - st->hFdCngDec->msPsd_float[p] = ( (float) st->hFdCngDec->msPsd_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPsd_exp_fft ) ) ); st->hFdCngDec->msNoiseEst_float[p] = (float) st->hFdCngDec->msNoiseEst[p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ); - st->hFdCngDec->msPeriodog_float[p] = ( (float) st->hFdCngDec->msPeriodog[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); - st->hFdCngDec->msPeriodog_ST[p] = ( (float) st->hFdCngDec->msPeriodog_ST_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); + } if ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) { @@ -1388,54 +931,7 @@ void fixed_to_float_stereo_tcx_core_dec( st->hFdCngDec->smoothed_psd[st->hFdCngDec->hFdCngCom->startBand + p] = ( (float) st->hFdCngDec->smoothed_psd_fx[st->hFdCngDec->hFdCngCom->startBand + p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); } } - IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) - { - for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) - { - if ( ( st->hFdCngDec->msMinBuf[p] == MAX_32 ) ) - { - st->hFdCngDec->msMinBuf_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msMinBuf_float[p] = (float) st->hFdCngDec->msMinBuf[p] / ( 1u << ( 31 - 6 ) ); // CNG_S = 6 - } - } - for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) - { - st->hFdCngDec->msPeriodogBuf_float[p] = ( (float) st->hFdCngDec->msPeriodogBuf[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msPsdFirstMoment_float[p] = ( (float) st->hFdCngDec->msPsdFirstMoment[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msPsdSecondMoment_float[p] = ( (float) st->hFdCngDec->msPsdSecondMoment[p] / ( 1u << Q19 ) ); - st->hFdCngDec->msNoiseFloor_float[p] = ( (float) st->hFdCngDec->msNoiseFloor[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msAlpha_float[p] = ( (float) st->hFdCngDec->msAlpha[p] / ( 1u << Q31 ) ); - st->hFdCngDec->msBminWin_float[p] = ( (float) st->hFdCngDec->msBminWin[p] / ( 1u << Q27 ) ); - st->hFdCngDec->msBminSubWin_float[p] = ( (float) st->hFdCngDec->msBminSubWin[p] / ( 1u << Q27 ) ); - if ( st->hFdCngDec->msCurrentMin[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMin_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMin_float[p] = ( (float) st->hFdCngDec->msCurrentMin[p] / ( 1u << ( 31 - ( 6 + 1 + 4 ) ) ) ); // exp : CNG_S + 1 + 4 - } - if ( st->hFdCngDec->msCurrentMinOut[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinOut_float[p] = ( (float) st->hFdCngDec->msCurrentMinOut[p] / ( 1u << ( 31 - 6 ) ) ); - } - if ( st->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = ( (float) st->hFdCngDec->msCurrentMinSubWindow[p] / ( 1u << ( 31 - 6 ) ) ); - } - } - } + int A_cng_q = 14; if ( st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE ) { @@ -1449,23 +945,7 @@ void fixed_to_float_stereo_tcx_core_dec( } } - st->last_gain_syn_deemph_float = fixedToFloat(st->last_gain_syn_deemph, 15 - st->last_gain_syn_deemph_e); - st->hTcxDec->old_gaintcx_bfi_float = fixedToFloat(st->hTcxDec->old_gaintcx_bfi, 15 - st->hTcxDec->old_gaintcx_bfi_e); - st->hTcxDec->cummulative_damping_tcx_float = fix16_to_float(st->hTcxDec->cummulative_damping_tcx, Q15); - st->hTcxDec->damping_float = fix16_to_float(st->hTcxDec->damping, Q14); - st->hTcxDec->stepCompensate_float = fixedToFloat(st->hTcxDec->stepCompensate, 15 - st->hTcxDec->stepCompensate_e); - st->hTcxDec->gainHelper_float = fixedToFloat(st->hTcxDec->gainHelper, 15 - st->hTcxDec->gainHelper_e); - FOR(Word16 l = 0; l < N_LTP_GAIN_MEMS; l++) - { - st->hTcxDec->ltpGainMemory[l] = fix16_to_float(st->hTcxDec->ltpGainMemory_fx[l], Q15); - } - st->hTonalMDCTConc->lastPitchLag_float = fix_to_float(st->hTonalMDCTConc->lastPitchLag, Q16); - st->hTonalMDCTConc->nFramesLost_float = fix16_to_float(st->hTonalMDCTConc->nFramesLost, Q1); me2f_buf(st->hIGFDec->virtualSpec, st->hIGFDec->virtualSpec_e, st->hIGFDec->virtualSpecBuf, (N_MAX_TCX - IGF_START_MN)); - st->hTcxDec->tcxltp_third_last_pitch_float = fix_to_float(st->hTcxDec->tcxltp_third_last_pitch, 16); - st->hTcxDec->tcxltp_second_last_pitch_float = fix_to_float(st->hTcxDec->tcxltp_second_last_pitch, 16); - st->old_fpitchFB_float = fix_to_float(st->old_fpitchFB, 16); - st->last_concealed_gain_syn_deemph_float = fix16_to_float( st->last_concealed_gain_syn_deemph, 15 - st->last_concealed_gain_syn_deemph_e ); IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) { diff --git a/lib_com/guided_plc_util.c b/lib_com/guided_plc_util.c index ea0c843aa57dfca82e1cc3fbe6d03a3fe8b65051..4d3d8bbb8ba3d1a9ddb178d9ea745a698ffd6cbd 100644 --- a/lib_com/guided_plc_util.c +++ b/lib_com/guided_plc_util.c @@ -139,7 +139,7 @@ void getConcealedLP_flt( * * *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void RecLpcSpecPowDiffuseLc_flt( float *lspq, float *lsp_old, @@ -182,7 +182,7 @@ void RecLpcSpecPowDiffuseLc_flt( return; } - +#endif /*-------------------------------------------------------------------* * modify_lsf_flt() diff --git a/lib_com/isf_dec_amr_wb.c b/lib_com/isf_dec_amr_wb.c index 690fd9df6c7fc2e683779db85ff0e2a0638b2019..1a4159286ebaf276a0e85afb7014d01a4830212b 100644 --- a/lib_com/isf_dec_amr_wb.c +++ b/lib_com/isf_dec_amr_wb.c @@ -46,7 +46,7 @@ * * Decoding of ISF parameters in AMR-WB IO mode *---------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void isf_dec_amr_wb( Decoder_State *st, /* i/o: State structure */ float *Aq, /* o : quantized A(z) for 4 subframes */ @@ -145,7 +145,7 @@ void isf_dec_amr_wb( return; } - +#endif /*-------------------------------------------------------------------* * disf_ns_28b() * diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index fb40d730331d5139dbe63135d986d361c1751bc3..098eda07c014ea1cf0d42466dab14ee71540c83c 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -45,10 +45,13 @@ #define PI_OVER_2 ( EVS_PI / 2.0f ) #define PI_OVER_180 ( EVS_PI / 180.0f ) +#define ONE_BY_PI_OVER_180_Q25 ( 1922527360 ) #define _180_OVER_PI ( 180.0f / EVS_PI ) #ifdef IVAS_FLOAT_FIXED #define _180_OVER_PI_Q25 1922527233 #define _180_OVER_PI_FX (Word32) (( 180.0f / EVS_PI ) *ONE_IN_Q10) +#define PI_OVER_180_Q15 ( 572 ) +#define _180_OVER_PI_Q9 ( 29335 ) #define PI_OVER_4_Q29 421657440 #define _180_OVER_PI_Q9 ( 29335 ) #define PI_OVER_Q29 1686629760 @@ -1337,7 +1340,9 @@ typedef enum #define MCMASA_LFE_BETA 0.09f #define MCMASA_LFE_THETA 1.3f #define MCMASA_LFE_SYNTH_ALPHA 0.95f /* Smoothing coefficient for LFE synthesis */ - +#ifdef IVAS_FLOAT_FIXED +#define MCMASA_LFE_SYNTH_ALPHA_Q15 (31129) +#endif #define MCMASA_LFE_ALPHA_Q15 (21954) #define MCMASA_LFE_BETA_Q15 (2949) #define MCMASA_LFE_BETA_Q14 (1474) @@ -1445,9 +1450,17 @@ typedef enum #define PARAM_MC_ICC_ERROR_BIAS_FAC (1.15f) /* factor for favouring past ICC maps in the adaptive ICC map decision */ #define PARAM_MC_TRANSIENT_BAND_STEP 2 /* Number of parameter bands combined in case of a transient frame*/ #define PARAM_MC_MAX_DECORR_CLDFB_BANDS 20 /* Maximum number of CLDFB bands with decorrelation */ +#ifdef FIX_901_PARAMMC_DEAD_CODE +#define PARAM_MC_MAX_TRANSPORT_CHANS 3 /* Number of down mix channels */ +#else #define PARAM_MC_MAX_TRANSPORT_CHANS 4 /* Number of down mix channels */ +#endif #define PARAM_MC_MAX_ILD_REF_CHANNELS 2 /* Maximum number of reference channels for a coded ILD */ +#ifdef FIX_901_PARAMMC_DEAD_CODE +#define PARAM_MC_NUM_CONFIGS 14 /* Number of available Parametric MC configurations */ +#else #define PARAM_MC_NUM_CONFIGS 15 /* Number of available Parametric MC configurations */ +#endif #define PARAM_MC_MAX_BAND_LFE 1 /* Number of parameter bands for LFE coding */ #define PARAM_MC_SZ_ICC_MAP 11 /* Maximum number of transmitted ICCs per parameter band */ #define PARAM_MC_SZ_ILD_MAP 12 /* Maximum number of transmitted channel energies per band*/ @@ -1458,6 +1471,9 @@ typedef enum #define PARAM_MC_SZ_ILD_QUANTIZER_4BITS 16 /* Length of the ILD quantizer for Parametric MC */ #define PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT 4 /* Number of bits for ILD uniform coding */ #define PARAM_MC_DEFAULT_MIN_ILD (-92.0f) /* Default relative channel level for untransmitted channel energies */ +#ifdef IVAS_FLOAT_FIXED +#define PARAM_MC_DEFAULT_MIN_ILD_FX (-23552) /* Default relative channel level for untransmitted channel energies *//*Q8*/ +#endif // IVAS_FLOAT_FIXED #define PARAM_MC_MAX_BITS 1024 /* Maximum number of bits for the Parametric MC metadata */ #define PARAM_MC_MAX_BAND_ABS_COV_ENC 10 #define PARAM_MC_MAX_PARAM_BAND_ABS_COV_ENC 10 diff --git a/lib_com/ivas_mc_param_com.c b/lib_com/ivas_mc_param_com.c index edfd83775b95c1bbf0695d272086b82c536714f5..a56d013d07e5f28c548eb50a8cb02b127c6d3c34 100644 --- a/lib_com/ivas_mc_param_com.c +++ b/lib_com/ivas_mc_param_com.c @@ -103,16 +103,22 @@ uint16_t ivas_param_mc_get_configuration_index( #ifdef IVAS_FLOAT_FIXED void ivas_param_mc_metadata_open( const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ +#ifndef FIX_901_PARAMMC_DEAD_CODE const Word16 lfe_index, /* i : channel index of LFE */ +#endif const Word32 ivas_total_brate, /* i : IVAS total bitrate */ HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* o : handle for the Parametric MC parameter coding state */ ) { +#ifndef FIX_901_PARAMMC_DEAD_CODE Word16 i; +#endif UWord16 config_index; +#ifndef FIX_901_PARAMMC_DEAD_CODE Word16 nchan_setup; nchan_setup = ivas_mc_ls_setup_get_num_channels( mc_ls_setup ); +#endif /* get coding band mappings */ set16_fx( hMetadataPMC->coding_band_mapping, 0, PARAM_MC_MAX_PARAMETER_BANDS ); @@ -144,25 +150,28 @@ void ivas_param_mc_metadata_open( { assert( 0 && "nbands must be 20 or 14!" ); } - +#ifndef FIX_901_PARAMMC_DEAD_CODE /* create map of all possible ICCs */ ivas_param_mc_create_full_icc_mapping( nchan_setup, lfe_index, hMetadataPMC->icc_map_full, &hMetadataPMC->icc_map_size_full ); +#endif hMetadataPMC->icc_mapping_conf = ivas_param_mc_conf[config_index].icc_mapping_conf; hMetadataPMC->ild_mapping_conf = ivas_param_mc_conf[config_index].ild_mapping_conf; hMetadataPMC->ild_factors = ivas_param_mc_conf[config_index].ild_factors; //float hMetadataPMC->ild_factors_fx = ivas_param_mc_conf[config_index].ild_factors_fx; - +#ifndef FIX_901_PARAMMC_DEAD_CODE /* set default ICC maps */ FOR ( i = 0; i < PARAM_MC_PARAMETER_FRAMES; i++ ) { ivas_param_mc_default_icc_map( hMetadataPMC->icc_mapping_conf, hMetadataPMC->icc_mapping[i] ); } - +#endif /* init remaining flags and indices */ hMetadataPMC->param_frame_idx = 0; move16(); +#ifndef FIX_901_PARAMMC_DEAD_CODE hMetadataPMC->flag_use_adaptive_icc_map = 0; move16(); +#endif hMetadataPMC->bAttackPresent = 0; move16(); hMetadataPMC->attackIndex = 0; @@ -183,16 +192,22 @@ void ivas_param_mc_metadata_open( #else void ivas_param_mc_metadata_open( const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ +#ifndef FIX_901_PARAMMC_DEAD_CODE const int16_t lfe_index, /* i : channel index of LFE */ +#endif const int32_t ivas_total_brate, /* i : IVAS total bitrate */ HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* o : handle for the Parametric MC parameter coding state */ ) { +#ifndef FIX_901_PARAMMC_DEAD_CODE int16_t i; +#endif uint16_t config_index; +#ifndef FIX_901_PARAMMC_DEAD_CODE int16_t nchan_setup; nchan_setup = ivas_mc_ls_setup_get_num_channels( mc_ls_setup ); +#endif /* get coding band mappings */ set_s( hMetadataPMC->coding_band_mapping, 0, PARAM_MC_MAX_PARAMETER_BANDS ); @@ -225,21 +240,26 @@ void ivas_param_mc_metadata_open( assert( 0 && "nbands must be 20 or 14!" ); } +#ifndef FIX_901_PARAMMC_DEAD_CODE /* create map of all possible ICCs */ ivas_param_mc_create_full_icc_mapping( nchan_setup, lfe_index, hMetadataPMC->icc_map_full, &hMetadataPMC->icc_map_size_full ); +#endif hMetadataPMC->icc_mapping_conf = ivas_param_mc_conf[config_index].icc_mapping_conf; hMetadataPMC->ild_mapping_conf = ivas_param_mc_conf[config_index].ild_mapping_conf; hMetadataPMC->ild_factors = ivas_param_mc_conf[config_index].ild_factors; +#ifndef FIX_901_PARAMMC_DEAD_CODE /* set default ICC maps */ for ( i = 0; i < PARAM_MC_PARAMETER_FRAMES; i++ ) { ivas_param_mc_default_icc_map( hMetadataPMC->icc_mapping_conf, hMetadataPMC->icc_mapping[i] ); } - +#endif /* init remaining flags and indices */ hMetadataPMC->param_frame_idx = 0; +#ifndef FIX_901_PARAMMC_DEAD_CODE hMetadataPMC->flag_use_adaptive_icc_map = 0; +#endif hMetadataPMC->bAttackPresent = 0; hMetadataPMC->attackIndex = 0; hMetadataPMC->lfe_on = 1; @@ -333,6 +353,7 @@ void ivas_param_mc_set_coded_bands( } #endif +#ifndef FIX_901_PARAMMC_DEAD_CODE /*------------------------------------------------------------------------- * ivas_param_mc_metadata_close() * @@ -379,7 +400,7 @@ void ivas_param_mc_metadata_close( } #endif - +#endif /*------------------------------------------------------------------------- * ivas_param_mc_getNumTransportChannels() * @@ -421,6 +442,7 @@ int16_t ivas_param_mc_getNumTransportChannels( #endif +#ifndef FIX_901_PARAMMC_DEAD_CODE /*------------------------------------------------------------------------- * ivas_param_mc_create_full_icc_mapping() * @@ -574,7 +596,7 @@ void ivas_param_mc_default_icc_map( return; } #endif - +#endif /*------------------------------------------------------------------------- * ivas_param_mc_get_num_param_bands() @@ -668,10 +690,12 @@ static Word16 ivas_param_mc_get_num_param_bands( num_parameter_bands = 14; move16(); BREAK; +#ifndef FIX_901_PARAMMC_DEAD_CODE case IVAS_160k: num_parameter_bands = 20; move16(); BREAK; +#endif } BREAK; default: @@ -756,9 +780,11 @@ static int16_t ivas_param_mc_get_num_param_bands( case IVAS_128k: num_parameter_bands = 14; break; +#ifndef FIX_901_PARAMMC_DEAD_CODE case IVAS_160k: num_parameter_bands = 20; break; +#endif } break; default: diff --git a/lib_com/ivas_pca_tools.c b/lib_com/ivas_pca_tools.c index bcd24fe1ff031b4805dd20d6466795f8a89a5905..9cf0732c7258ef83dd9803afef420727841ec100 100644 --- a/lib_com/ivas_pca_tools.c +++ b/lib_com/ivas_pca_tools.c @@ -792,7 +792,7 @@ static void norm_quat_fx( Word16 *q) { Word32 norm_q; - Word16 i, exp1 = 0, exp; + Word16 i, exp1 = 0; norm_q = dotp_fx(q, q, IVAS_PCA_INTERP, &exp1); exp1 = (31 - (exp1 + 2)); norm_q = ISqrt32(norm_q, &exp1); /*q(15 - exp)*/ diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index dbcf4d4b8035584d0ab74df5978b3dd46962f8bd..5c2428173afc1e55ea7a18eb3b2efada5a27390e 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -363,6 +363,11 @@ ivas_error create_cpe_dec( const int32_t element_brate /* i : element bitrate */ ); #endif // !IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED +ivas_error create_mct_dec_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); +#endif // IVAS_FLOAT_FIXED ivas_error create_mct_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ @@ -394,6 +399,17 @@ void ivas_mct_dec_close( MCT_DEC_HANDLE *hMCT /* i/o: MCT decoder structure */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_corecoder_dec_reconfig_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nSCE_old, /* i : number of SCEs in previous frame */ + Word16 nCPE_old, /* i : number of CPEs in previous frame */ + const Word16 nchan_transport_old, /* i : number of TCs in previous frame */ + const Word16 sba_dirac_stereo_flag_old, /* i : signal stereo rendering using DFT upmix in previous frame */ + const Word32 brate_SCE, /* i : bitrate to be set for the SCEs */ + const Word32 brate_CPE /* i : bitrate to be set for the CPEs */ +); +#endif ivas_error ivas_corecoder_dec_reconfig( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ @@ -1903,7 +1919,15 @@ void stereo_td_itd( void stereo_dft_dmx_out_reset( STEREO_DFT_DMX_DATA_HANDLE hStereoDftDmx /* i/o: DFT stereo DMX decoder */ ); - +#ifdef IVAS_FLOAT_FIXED +void stereo_dft_unify_dmx_fx( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ + Decoder_State *st0, /* i/o: decoder state structure */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ + Word32 *input_mem, /* i/o: mem of buffer DFT analysis */ + const Word16 prev_sid_nodata /* i : Previous SID/No data indicator */ +); +#endif void stereo_dft_unify_dmx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ Decoder_State *st0, /* i/o: decoder state structure */ @@ -3080,6 +3104,11 @@ void FdCngEncodeMDCTStereoSID( void FdCngDecodeMDCTStereoSID( CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error initMdctStereoDtxData_fx( + CPE_DEC_HANDLE hCPE /* i/o: CPE handle */ +); +#endif // IVAS_FLOAT_FIXED ivas_error initMdctStereoDtxData( CPE_DEC_HANDLE hCPE /* i/o: CPE decoder handle */ @@ -4506,7 +4535,9 @@ void ivas_mc_paramupmix_dec_render( void ivas_param_mc_metadata_open( const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ +#ifndef FIX_901_PARAMMC_DEAD_CODE const int16_t lfe_index, /* i : channel index of LFE */ +#endif const int32_t ivas_total_brate, /* i : IVAS total bitrate */ HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* o : handle for the Parametric MC parameter coding state */ ); @@ -4515,6 +4546,7 @@ void ivas_param_mc_set_coded_bands( HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* i/o: handle for the Parametric MC parameter coding state */ ); +#ifndef FIX_901_PARAMMC_DEAD_CODE void ivas_param_mc_metadata_close( HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* i/o: handle for the Parametric MC parameter coding state */ ); @@ -4525,12 +4557,19 @@ void ivas_param_mc_create_full_icc_mapping( int16_t *icc_map[2], /* o : map of all possible ICCs */ int16_t *icc_map_size_full /* o : number of all possible ICCs */ ); - +#endif /*! r: number of IVAS transport channels */ +#ifdef IVAS_FLOAT_FIXED +Word16 ivas_param_mc_getNumTransportChannels( + const Word32 ivas_total_bitrate, /* i : IVAS total bitrate */ + const MC_LS_SETUP mc_ls_setup /* i : MC ls setup */ +); +#else int16_t ivas_param_mc_getNumTransportChannels( const int32_t ivas_total_bitrate, /* i : IVAS total bitrate */ const MC_LS_SETUP mc_ls_setup /* i : MC ls setup */ ); +#endif // IVAS_FLOAT_FIXED ivas_error ivas_param_mc_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ @@ -4556,6 +4595,12 @@ ivas_error ivas_param_mc_dec_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_param_mc_dec_reconfig_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); +#endif // IVAS_FLOAT_FIXED + ivas_error ivas_param_mc_dec_reconfig( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); @@ -4590,21 +4635,30 @@ void ivas_param_mc_dec( float *output_f[] /* i/o: synthesized core-coder transport channels/DirAC output */ ); +#ifndef FIX_901_PARAMMC_DEAD_CODE void ivas_param_mc_default_icc_map( const PARAM_MC_ICC_MAPPING * hIccMapping, /* i : handle to ICC mapping configuration */ int16_t icc_map[PARAM_MC_SZ_ICC_MAP][2] /* o : copy of map from the configuration */ ); +#endif /*! r: number of cldfb synthesis instances */ int16_t param_mc_get_num_cldfb_syntheses( Decoder_Struct *st_ivas /* i : IVAS decoder structure */ ); +#ifdef IVAS_FLOAT_FIXED +UWord16 ivas_param_mc_get_configuration_index( + const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +); +#else /*! r: index into the ParamMC configuration tables */ uint16_t ivas_param_mc_get_configuration_index( const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ const int32_t ivas_total_brate /* i : total bitrate */ ); +#endif // IVAS_FLOAT_FIXED int16_t matrix_product( const float *X, /* i : left hand matrix */ @@ -4749,6 +4803,19 @@ int16_t svd( const int16_t nChannelsL, /* i : number of rows in the matrix to be decomposed */ const int16_t nChannelsC /* i : number of columns in the matrix to be decomposed */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( + DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ + DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: hanlde for the covariance synthesis state */ + const Word16 max_band_decorr, /* i : uppermost frequency band where decorrelation is applied */ + const Word16 interp_length, /* i : length for interpolating the mixing matrices in time slots */ + const Word16 num_param_bands, /* i : number of parameter bands */ + const Word16 num_param_bands_residual, /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ + const Word16 nchan_in, /* i : number of input (transport) channels */ + const Word16 nchan_out, /* i : number of output channels */ + const Word32 *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) */ +); +#endif // IVAS_FLOAT_FIXED ivas_error ivas_dirac_dec_output_synthesis_cov_open( DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ @@ -4773,6 +4840,15 @@ void ivas_dirac_dec_output_synthesis_get_interpolator( DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ const uint16_t interp_length /* i : interpolator length */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_dec_output_synthesis_cov_init_fx( + DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: pointer to the state of the covariance synthesis */ + const Word16 nchan_in, /* i : number of input (tranport) channels */ + const Word16 nchan_out, /* i : number of output channels */ + const Word16 n_param_bands, /* i : number of total parameter bands */ + const Word16 n_param_bands_res /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ +); +#endif void ivas_dirac_dec_output_synthesis_cov_init( DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: pointer to the state of the covariance synthesis */ @@ -4781,6 +4857,12 @@ void ivas_dirac_dec_output_synthesis_cov_init( const int16_t n_param_bands, /* i : number of total parameter bands */ const int16_t n_param_bands_res /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ ); +#ifdef IVAS_FLOAT_FIXED1 +void ivas_dirac_dec_output_synthesis_cov_close_fx( + DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i : handle for the covariance synthesis parameters */ + DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state /* i/o: handle for the covariance synthesis state */ +); +#endif // IVAS_FLOAT_FIXED void ivas_dirac_dec_output_synthesis_cov_close( DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i : handle for the covariance synthesis parameters */ @@ -5388,14 +5470,23 @@ void ivas_spar_md_dec_close( ivas_spar_md_dec_state_t **hMdDec /* i/o: SPAR MD decoder handle */ ); -void ivas_spar_get_parameters( +void ivas_spar_get_parameters_fx( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ const int16_t ts, /* i : time slot index */ const int16_t num_ch_out, /* i : number of channels out */ const int16_t num_ch_in, /* i : number of channels in */ const int16_t num_spar_bands, /* i : number of SPAR bands */ - float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */ + Word32 par_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */ +); +void ivas_spar_get_parameters( + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t ts, /* i : time slot index */ + const int16_t num_ch_out, /* i : number of channels out */ + const int16_t num_ch_in, /* i : number of channels in */ + const int16_t num_spar_bands, /* i : number of SPAR bands */ + float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */ ); ivas_error ivas_spar_md_dec_init( @@ -6213,6 +6304,14 @@ void ivas_spar_param_to_masa_param_mapping( const int16_t subframe /* i : Subframe to map */ ); +void ivas_spar_param_to_masa_param_mapping_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ + Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ + Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ + Word16 q_cldfb[6][CLDFB_SLOTS_PER_SUBFRAME], + const Word16 subframe /* i : Subframe to map */ +); + /*---------------------------------------------------------------------------------* * Binaural FastConv Renderer Prototypes @@ -6753,6 +6852,7 @@ ivas_error ivas_osba_dirac_td_binaural_jbm_fx( UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ Word32 *output_fx[], /* o : rendered time signal */ + const Word16 q_factor, /* i : q_factor of rendered time signal */ Word16 out_len/*Store the length of values in each channel*/ ); #endif // IVAS_FLOAT_FIXED @@ -6933,6 +7033,16 @@ void ivas_omasa_dirac_rend_jbm( float *output_f[] /* o : rendered time signal */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( + Decoder_Struct *st_ivas, + Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + Word16 *cldfb_buf_q, + const Word16 nBins, + const Word16 subframe +); +#endif void ivas_omasa_preProcessStereoTransportsForMovedObjects( Decoder_Struct *st_ivas, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index f8a66b48709b8dedacbc2530186229ca0d204876..3779a30888b6118196d20e21c571b77209f8fe89 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -156,9 +156,10 @@ ivas_error ivas_omasa_dec_config_fx( Word16 *data /* o : output synthesis signal */ ); ivas_error ivas_td_binaural_renderer_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - float *output[], /* i/o: SCE channels / Binaural synthesis */ - const int16_t n_samples_granularity /* i : granularity of the renderer/buffer */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis */ + const Word16 q_factor, /* i : Q-factor of input/output */ + const Word16 n_samples_granularity /* i : granularity of the renderer/buffer */ ); #endif @@ -486,6 +487,19 @@ void stereo_dft_res_ecu_burst_att_fx( const Word16 L_res, /* i : Bandwidth of residual */ const Word16 L_ana /* i : Length of FFT analysis */ ); + +void stereo_dft_generate_res_pred_fx( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word16 samp_ratio, /* i : sampling ratio */ + Word32 *pDFT_DMX, /* i : downmix signal */ + Word32 *DFT_PRED_RES, /* o : residual prediction signal */ + Word32 *pPredGain, /* i : residual prediction gains */ + const Word16 k, /* i : subframe index */ + Word32 *ap_filt_DMX, /* i : enhanced stereo filling signal */ + Word16 *stop, /* o : last FD stereo filling bin */ + const Word16 bfi /* i : BFI flag */ +); + #endif void stereo_dft_dec_analyze_fx( @@ -1059,6 +1073,13 @@ void stereo_dft_dec_synthesize_fx( const Word16 output_frame /* i : output frame length */ ); +void stereo_dft_dec_smooth_parameters_fx( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word16 prev_sid_nodata, /* i : Previous SID/No data indicator */ + const Word16 active_frame_counter, /* i : Active frame counter */ + const Word32 element_brate /* i : Element bitrate */ +); + void stereo_dft_dec_res_fx( CPE_DEC_HANDLE hCPE, /* i/o: decoder CPE handle */ Word32 res_buf[STEREO_DFT_N_8k], /* i : residual buffer */ @@ -1191,8 +1212,8 @@ Word16 matrix_product_diag_fx( void stereo_mdct_core_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - float *signal_out[CPE_CHANNELS], /* o : synthesis @internal_FS */ - float signal_outFB[CPE_CHANNELS][L_FRAME48k] /* o : synthesis @output_FS */ + Word32 *signal_out[CPE_CHANNELS], /* o : synthesis @internal_FS */ + Word16 signal_outFB[CPE_CHANNELS][L_FRAME48k] /* o : synthesis @output_FS */ ); // ivas_stereo_mdct_stereo_com.c @@ -1269,9 +1290,10 @@ void stereo_icBWE_decproc_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *output[CPE_CHANNELS], /* i/o: output synthesis */ Word32 outputHB[CPE_CHANNELS][L_FRAME48k], /* i : HB synthesis */ - const int16_t last_core, /* i : last core, primary channel */ - const int16_t last_bwidth, /* i : last bandwidth */ - const int16_t output_frame /* i : frame length */ + const Word16 last_core, /* i : last core, primary channel */ + const Word16 last_bwidth, /* i : last bandwidth */ + const Word16 output_frame, /* i : frame length */ + Word16 q_output /* i : Q-fac of output */ ); void add_HB_to_mono_dmx_fx( @@ -1972,6 +1994,24 @@ void ivas_mct_side_bits_fx( const Word16 nb_bits_metadata /* i : number of metadata bits */ ); +#ifdef BASOP_NOGLOB /*Critical overflow */ +Flag conv_fx_32( +#else +void conv_fx_32( +#endif + const Word16 x[], /* i : i vector Q_new*/ + const Word16 h[], /* i : impulse response (or second i vector) Q(15)*/ + Word32 y[], /* o : output vetor (result of convolution) 12 bits*/ + const Word16 L /* i : vector size */ +); + +void stereo_dtf_cng_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ + const Word16 output_frame, /* i : output frame size */ + Word16 q_dft /* i : Q factor of the DFT data */ +); #endif // IVAS_FLOAT_FIXED @@ -1990,4 +2030,25 @@ void ivas_spar_setup_md_smoothing_fx( const Word16 num_bands_out, /* i : number of output bands */ const Word16 num_md_sub_frames /* i : number of metadata subframes */ ); + +ivas_error ivas_mct_dec_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output_fx[], /* o : output synthesis signal */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +); +void swb_tbe_reset_synth_ivas_fx( + Word32 genSHBsynth_Hilbert_Mem[], + Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[], + Word32 genSHBsynth_state_lsyn_filt_shb_local_fx_32[] ); + +void InitSWBdecBuffer_ivas_fx( + Decoder_State* st_fx /* i/o: SHB decoder structure */ +); + +void td_bwe_dec_init_ivas_fx( + Decoder_State* st_fx, /* i/o: SHB decoder structure */ + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + const Word32 output_Fs /* i : output sampling rate */ +); #endif diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index a48fc0fd2eafd6d9f9d80c94b48f85f3f2769969..038c09f5d4d98ec1abc94fd75acb30818ad32866 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2085,6 +2085,62 @@ const float ivas_param_mc_dmx_fac_CICP19_4tc[48] = 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, /*Lut*/ 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, /*Rut*/ }; +#ifdef IVAS_FLOAT_FIXED + +const Word32 ivas_param_mc_dmx_fac_CICP6_2tc_fx[12] = +{ + 2147483647,0,1518500224,1518500224,2147483647,0, /*Lt*/ + 0,2147483647,1518500224,1518500224,0,2147483647 /*Rt*/ +}; + +const Word32 ivas_param_mc_dmx_fac_CICP12_2tc_fx[16] = +{ + 2147483647,0,1518500224,1518500224,2147483647,0,2147483647,0, /*Lt*/ + 0,2147483647,1518500224,1518500224,0,2147483647,0,2147483647 /*Rt*/ +}; + +const Word32 ivas_param_mc_dmx_fac_CICP12_3tc_fx[24] = +{ + 2147483647,0,0,0,2147483647,0,2147483647,0, /*Lt*/ + 0,2147483647,0,0,0,2147483647,0,2147483647, /*Rt*/ + 0,0,2147483647,2147483647,0,0,0,0 /*Ct*/ +}; + +const Word32 ivas_param_mc_dmx_fac_CICP14_2tc_fx[16] = +{ + 2147483647,0,1518500224,1518500224,2147483647,0,2147483647,0, /*Lt*/ + 0,2147483647,1518500224,1518500224,0,2147483647,0,2147483647 /*Rt*/ +}; +const Word32 ivas_param_mc_dmx_fac_CICP14_3tc_fx[24] = +{ + 2147483647,0,0,0,2147483647,0,2147483647,0, /*Lt*/ + 0,2147483647,0,0,0,2147483647,0,2147483647, /*Rt*/ + 0,0,2147483647,2147483647,0,0,0,0 /*Ct*/ +}; + +const Word32 ivas_param_mc_dmx_fac_CICP16_3tc_fx[30] = +{ + 2147483647,0,0,0,2147483647,0,2147483647,0,2147483647,0, /*Lt*/ + 0,2147483647,0,0,0,2147483647,0,2147483647,0,2147483647, /*Rt*/ + 0,0,2147483647,2147483647,0,0,0,0,0,0 /*Ct*/ +}; + +const Word32 ivas_param_mc_dmx_fac_CICP19_3tc_fx[36] = +{ + 2147483647,0,0,0,2147483647,0,2147483647,0,2147483647,0,2147483647,0, /*Lt*/ + 0,2147483647,0,0,0,2147483647,0,2147483647,0,2147483647,0,2147483647, /*Rt*/ + 0,0,2147483647,2147483647,0,0,0,0,0,0,0,0 /*Ct*/ +}; + +const Word32 ivas_param_mc_dmx_fac_CICP19_4tc_fx[48] = +{ + 2147483647,0,1518500224,1518500224,2147483647,0,2147483647,0,0,0,0,0, /*Lht*/ + 0,2147483647,1518500224,1518500224,0,2147483647,0,2147483647,0,0,0,0, /*Rht*/ + 0,0,0,0,0,0,0,0,2147483647,0,2147483647,0, /*Lut*/ + 0,0,0,0,0,0,0,0,0,2147483647,0,2147483647 /*Rut*/ +}; + +#endif // IVAS_FLOAT_FIXED /* Coefficient for Parametric MC ILD factorization */ const float ivas_param_mc_ild_fac_CICP6_2tc[6] = @@ -2263,6 +2319,7 @@ const Word16 ivas_param_mc_ild_fac_CICP19_3tc_fx[12] = 16384 }; +#ifndef FIX_901_PARAMMC_DEAD_CODE const float ivas_param_mc_ild_fac_CICP19_4tc[12] = { 0.35f, @@ -2295,6 +2352,7 @@ const Word16 ivas_param_mc_ild_fac_CICP19_4tc_fx[12] = 6553 }; +#endif const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP6_2tc = { 5, @@ -2358,6 +2416,7 @@ const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP19_3tc = {{0},{1},{0},{1},{0},{1},{0},{1},{0},{1},{2},{2}} }; +#ifndef FIX_901_PARAMMC_DEAD_CODE const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP19_4tc = { 11, @@ -2367,6 +2426,7 @@ const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP19_4tc = {{0},{1},{0,1},{0},{1},{0},{1},{2},{3},{2},{3},{0,1}} }; +#endif const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP6_2tc = { 4, @@ -2467,6 +2527,7 @@ const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP19_3tc = } }; +#ifndef FIX_901_PARAMMC_DEAD_CODE const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP19_4tc = { 8, @@ -2483,6 +2544,7 @@ const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP19_4tc = } }; +#endif const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = { /* CICP6 48000 */ @@ -2496,7 +2558,8 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = &ivas_param_mc_dmx_fac_CICP6_2tc[0], &ivas_param_mc_ild_fac_CICP6_2tc[0], #ifdef IVAS_FLOAT_FIXED - &ivas_param_mc_ild_fac_CICP6_2tc_fx[0] + &ivas_param_mc_ild_fac_CICP6_2tc_fx[0], + &ivas_param_mc_dmx_fac_CICP6_2tc_fx[0] #endif }, /* CICP6 64000 */ @@ -2510,7 +2573,8 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = &ivas_param_mc_dmx_fac_CICP6_2tc[0], &ivas_param_mc_ild_fac_CICP6_2tc[0], #ifdef IVAS_FLOAT_FIXED - &ivas_param_mc_ild_fac_CICP6_2tc_fx[0] + &ivas_param_mc_ild_fac_CICP6_2tc_fx[0], + & ivas_param_mc_dmx_fac_CICP6_2tc_fx[0] #endif }, /* CICP6 80000 */ @@ -2524,7 +2588,8 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = &ivas_param_mc_dmx_fac_CICP6_2tc[0], &ivas_param_mc_ild_fac_CICP6_2tc[0], #ifdef IVAS_FLOAT_FIXED - &ivas_param_mc_ild_fac_CICP6_2tc_fx[0] + &ivas_param_mc_ild_fac_CICP6_2tc_fx[0], + & ivas_param_mc_dmx_fac_CICP6_2tc_fx[0] #endif }, /* CICP12 48000 */ @@ -2538,7 +2603,8 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = &ivas_param_mc_dmx_fac_CICP12_2tc[0], &ivas_param_mc_ild_fac_CICP12_2tc[0], #ifdef IVAS_FLOAT_FIXED - &ivas_param_mc_ild_fac_CICP12_2tc_fx[0] + &ivas_param_mc_ild_fac_CICP12_2tc_fx[0], + &ivas_param_mc_dmx_fac_CICP12_2tc_fx[0] #endif }, /* CICP12 64000 */ @@ -2552,7 +2618,8 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = &ivas_param_mc_dmx_fac_CICP12_2tc[0], &ivas_param_mc_ild_fac_CICP12_2tc[0], #ifdef IVAS_FLOAT_FIXED - &ivas_param_mc_ild_fac_CICP12_2tc_fx[0] + &ivas_param_mc_ild_fac_CICP12_2tc_fx[0], + &ivas_param_mc_dmx_fac_CICP12_2tc_fx[0] #endif }, /* CICP12 80000 */ @@ -2566,7 +2633,8 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = &ivas_param_mc_dmx_fac_CICP12_2tc[0], &ivas_param_mc_ild_fac_CICP12_2tc[0], #ifdef IVAS_FLOAT_FIXED - &ivas_param_mc_ild_fac_CICP12_2tc_fx[0] + &ivas_param_mc_ild_fac_CICP12_2tc_fx[0], + &ivas_param_mc_dmx_fac_CICP12_2tc_fx[0], #endif }, /* CICP12 96000 */ @@ -2580,7 +2648,8 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = &ivas_param_mc_dmx_fac_CICP12_3tc[0], &ivas_param_mc_ild_fac_CICP12_3tc[0], #ifdef IVAS_FLOAT_FIXED - &ivas_param_mc_ild_fac_CICP12_3tc_fx[0] + &ivas_param_mc_ild_fac_CICP12_3tc_fx[0], + &ivas_param_mc_dmx_fac_CICP12_3tc_fx[0] #endif }, /* CICP14 48000 */ @@ -2594,7 +2663,8 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = &ivas_param_mc_dmx_fac_CICP14_2tc[0], &ivas_param_mc_ild_fac_CICP14_2tc[0], #ifdef IVAS_FLOAT_FIXED - &ivas_param_mc_ild_fac_CICP14_2tc_fx[0] + &ivas_param_mc_ild_fac_CICP14_2tc_fx[0], + &ivas_param_mc_dmx_fac_CICP14_2tc_fx[0] #endif }, /* CICP14 64000 */ @@ -2608,7 +2678,8 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = &ivas_param_mc_dmx_fac_CICP14_2tc[0], &ivas_param_mc_ild_fac_CICP14_2tc[0], #ifdef IVAS_FLOAT_FIXED - &ivas_param_mc_ild_fac_CICP14_2tc_fx[0] + &ivas_param_mc_ild_fac_CICP14_2tc_fx[0], + &ivas_param_mc_dmx_fac_CICP14_2tc_fx[0] #endif }, /* CICP14 80000 */ @@ -2622,7 +2693,8 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = &ivas_param_mc_dmx_fac_CICP14_2tc[0], &ivas_param_mc_ild_fac_CICP14_2tc[0], #ifdef IVAS_FLOAT_FIXED - &ivas_param_mc_ild_fac_CICP14_2tc_fx[0] + &ivas_param_mc_ild_fac_CICP14_2tc_fx[0], + & ivas_param_mc_dmx_fac_CICP14_2tc_fx[0] #endif }, /* CICP14 96000 */ @@ -2636,7 +2708,8 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = &ivas_param_mc_dmx_fac_CICP14_3tc[0], &ivas_param_mc_ild_fac_CICP14_3tc[0], #ifdef IVAS_FLOAT_FIXED - &ivas_param_mc_ild_fac_CICP14_3tc_fx[0] + &ivas_param_mc_ild_fac_CICP14_3tc_fx[0], + & ivas_param_mc_dmx_fac_CICP14_3tc_fx[0] #endif }, /* CICP16 96000 */ @@ -2650,7 +2723,8 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = &ivas_param_mc_dmx_fac_CICP16_3tc[0], &ivas_param_mc_ild_fac_CICP16_3tc[0], #ifdef IVAS_FLOAT_FIXED - &ivas_param_mc_ild_fac_CICP16_3tc_fx[0] + &ivas_param_mc_ild_fac_CICP16_3tc_fx[0], + & ivas_param_mc_dmx_fac_CICP16_3tc_fx[0] #endif }, /* CICP16 128000 */ @@ -2664,7 +2738,8 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = &ivas_param_mc_dmx_fac_CICP16_3tc[0], &ivas_param_mc_ild_fac_CICP16_3tc[0], #ifdef IVAS_FLOAT_FIXED - &ivas_param_mc_ild_fac_CICP16_3tc_fx[0] + &ivas_param_mc_ild_fac_CICP16_3tc_fx[0], + & ivas_param_mc_dmx_fac_CICP16_3tc_fx[0] #endif }, /* CICP19 128000 */ @@ -2678,9 +2753,12 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = &ivas_param_mc_dmx_fac_CICP19_3tc[0], &ivas_param_mc_ild_fac_CICP19_3tc[0], #ifdef IVAS_FLOAT_FIXED - &ivas_param_mc_ild_fac_CICP19_3tc_fx[0] + &ivas_param_mc_ild_fac_CICP19_3tc_fx[0], + & ivas_param_mc_dmx_fac_CICP19_3tc_fx[0] #endif - }, + } +#ifndef FIX_901_PARAMMC_DEAD_CODE + , /* CICP19 160000 */ { MC_LS_SETUP_7_1_4, @@ -2692,9 +2770,11 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = &ivas_param_mc_dmx_fac_CICP19_4tc[0], &ivas_param_mc_ild_fac_CICP19_4tc[0], #ifdef IVAS_FLOAT_FIXED - &ivas_param_mc_ild_fac_CICP19_4tc_fx[0] + &ivas_param_mc_ild_fac_CICP19_4tc_fx[0], + &ivas_param_mc_dmx_fac_CICP19_4tc_fx[0] #endif } +#endif }; const float ivas_param_mc_quant_ild_5d1_48[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = @@ -3265,12 +3345,12 @@ const int16_t ls_azimuth_CICP19_idx[11] = { 1, 2, 0, 9, 10, 5, 6, 1, 2, 9, 10 const int16_t ls_elevation_CICP19_idx[11] = { 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3 }; -const float shoebox_sin_cos_tbl[11][2] ={{0.00000000, 1.00000000 }, //0 - {0.500000000, 0.866025388}, { -0.500000000, 0.866025388}, //30, -30 - {0.573576450 , 0.819152057}, {-0.573576450, 0.819152057}, //35, -35 - {1.00000000 , 0.00000000} , { -1.00000000, 0.00000000 }, //90, -90 - {0.939692616 , -0.342020124}, {-0.939692616,-0.342020124},//110,-110 - {0.707106769 , -0.707106769}, {-0.707106769,-0.707106769}}; //135, -135 +const float shoebox_sin_cos_tbl[11][2] ={{0.00000000f, 1.00000000f }, //0 + {0.500000000f, 0.866025388f}, { -0.500000000f, 0.866025388f}, //30, -30 + {0.573576450f , 0.819152057f}, {-0.573576450f, 0.819152057f}, //35, -35 + {1.00000000f , 0.00000000f} , { -1.00000000f, 0.00000000f }, //90, -90 + {0.939692616f , -0.342020124f}, {-0.939692616f,-0.342020124f},//110,-110 + {0.707106769f , -0.707106769f}, {-0.707106769f,-0.707106769f}}; //135, -135 const Word32 shoebox_sin_cos_tbl_fx[11][2] ={{0,1073741824} , //0 {536870912, 929887680},{-536870912, 929887680}, //30, -30 @@ -6070,7 +6150,7 @@ const Word32 dirac_gains_trg_term_int[181][2] = //Q30 const Word32 dirac_gains_trg_term_fx[181][2] = //Q31 { - {-2147483648,187}, + {(-2147483647 - 1),187}, {-2147156608,-37478872}, {-2146175360,-74946000}, {-2144540544,-112390808}, @@ -6160,7 +6240,7 @@ const Word32 dirac_gains_trg_term_fx[181][2] = //Q31 { -112390576,-2144540544 }, { -74946016,-2146175360 }, { -37478636,-2147156608 }, - { -93,-2147483648 }, + { -93,(-2147483647 - 1) }, { 37478700,-2147156608 }, { 74946104,-2146175360 }, { 112390640,-2144540544 }, diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 61e86b2addb03a2d52679f7a65269ea961de4609..743a706350e26bd885237dc492675ec6197815a5 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -2014,7 +2014,7 @@ void ivas_get_spar_md_from_dirac_fx( //float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; float Wscale[IVAS_MAX_NUM_BANDS]; - Word32 Wscale_fx[IVAS_MAX_NUM_BANDS]; + //Word32 Wscale_fx[IVAS_MAX_NUM_BANDS]; float mixer_mat_local[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; Word32 mixer_mat_local_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; float **ppMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH]; diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c index 7536018e01732c809b83c163c88e25c4b6117d57..c1933745dd6b00b76d1c37df809808c1cfef1eab 100644 --- a/lib_com/ivas_spar_com_quant_util.c +++ b/lib_com/ivas_spar_com_quant_util.c @@ -109,9 +109,9 @@ void ivas_quantise_real_values_fx( else if ( q_levels && max_value_fx != min_value_fx) { Word16 nor_q_level = norm_l(q_levels - 1); - Word32 one_by_q_level = divide3232(L_shl(1, (nor_q_level)), L_shl((q_levels - 1), (nor_q_level))); - one_by_q_level = L_shl(one_by_q_level, 16); - q_step_fx = Mpy_32_32((max_value_fx - min_value_fx), one_by_q_level); + Word32 one_by_q_levels = divide3232(L_shl(1, (nor_q_level)), L_shl((q_levels - 1), (nor_q_level))); + one_by_q_levels = L_shl(one_by_q_levels, 16); + q_step_fx = Mpy_32_32((max_value_fx - min_value_fx), one_by_q_levels); Word32 one_by_max_min = divide3232(ONE_IN_Q28,L_sub(max_value_fx, min_value_fx)); one_by_q_step_fx = (q_levels - 1)*one_by_max_min; Word32 val_fx; diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 86a9bc8307383d13b5c21ddc27596cd749722f6e..753f3cd1052c43482c6df48eb2476e3696da62c4 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -622,6 +622,7 @@ typedef struct ivas_param_mc_conf_struct /* structure for ROM Table */ const float *ild_factors; #ifdef IVAS_FLOAT_FIXED const Word16 *ild_factors_fx; + const Word32 *dmx_fac_fx; #endif } PARAM_MC_CONF; @@ -645,11 +646,15 @@ typedef struct ivas_parametric_mc_metadata_struct { const PARAM_MC_ILD_MAPPING *ild_mapping_conf; const PARAM_MC_ICC_MAPPING *icc_mapping_conf; +#ifndef FIX_901_PARAMMC_DEAD_CODE int16_t icc_mapping[PARAM_MC_PARAMETER_FRAMES][PARAM_MC_SZ_ICC_MAP][2]; int16_t *icc_map_full[2]; +#endif int16_t icc_map_size_full; int16_t param_frame_idx; +#ifndef FIX_901_PARAMMC_DEAD_CODE int16_t flag_use_adaptive_icc_map; +#endif const float *ild_factors; #ifdef IVAS_FLOAT_FIXED const Word16 *ild_factors_fx; @@ -789,6 +794,7 @@ typedef struct ivas_fb_bin_to_band_data_t Word32 *pFb_bin_to_band_fx[IVAS_MAX_NUM_FB_BANDS]; Word32 p_short_stride_bin_to_band_fx[2 * MDFT_FB_BANDS_240]; Word32 *pp_short_stride_bin_to_band_fx[IVAS_MAX_NUM_FB_BANDS]; + Word32 pp_cldfb_weights_per_spar_band_fx[CLDFB_NO_CHANNELS_MAX][IVAS_MAX_NUM_FB_BANDS]; #endif } ivas_fb_bin_to_band_data_t; diff --git a/lib_com/ivas_stereo_ica_com_fx.c b/lib_com/ivas_stereo_ica_com_fx.c index 1e6c2bb84dff30c9cf55b2914ca09ce08f29399c..e24e688a168be2028afd3d5b8ff5f9ca77ac7fe1 100644 --- a/lib_com/ivas_stereo_ica_com_fx.c +++ b/lib_com/ivas_stereo_ica_com_fx.c @@ -125,8 +125,7 @@ static void interpTargetChannel_fx( const Word32 *win_fx; Word32 *ptr1_fx, *ptr2_fx; Word32 tempBuff1_fx[INTERP_FACTOR1 * ( L_SHIFT_ADAPT_MAX + 2 * N_MAX_SHIFT_CHANGE + 2 )], tempBuff2_fx[L_SHIFT_ADAPT_MAX - 1]; - Word16 temp_int; - Word32 x_fx[4], y_fx[4], tempF_fx, tempF1_fx; + Word32 x_fx[4], y_fx[4], tempF1_fx; Word32 interp_factor2_fx, factor_fx; Word32 spread_factor2_fx; Word64 tempD1_fx, tempD2_fx; @@ -188,20 +187,10 @@ static void interpTargetChannel_fx( ptr2_fx[i] = 0; /* lim1 = ceil((i - SINC_ORDER1)*SPREAD_FACTOR1); */ /* lim2 = floor((i + SINC_ORDER1)*SPREAD_FACTOR1); */ - temp_int = shr( ( i - SINC_ORDER1 ), 1 ); - tempF_fx = ( i - SINC_ORDER1 ) % 2; //*SPREAD_FACTOR1 - lim1 = (Word16) ( temp_int ); - IF( tempF_fx == 1 ) - { - lim1++; - } - tempF_fx = ( i + SINC_ORDER1 ) % 2; //*SPREAD_FACTOR1 - temp_int = shr( ( i + SINC_ORDER1 ), 1 ); //*SPREAD_FACTOR1 - lim2 = (Word16) ( temp_int ); - IF( tempF_fx == -1 ) - { - lim2--; - } + lim1 = add(shr((i - SINC_ORDER1), 1), 1); + + lim2 = shr((i + SINC_ORDER1), 1); + FOR( j = lim1; j <= lim2; j++ ) { ptr2_fx[i] = L_add( Mpy_32_32( win_fx[j * INTERP_FACTOR1 - i], ptr1_fx[j] ), ptr2_fx[i] ); diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 727320628cdbdf5468f1ce53c79f22389c9a6931..ac837f7473901e13540f3d28a72aed87c08b85db 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -411,7 +411,6 @@ void v_add_inc_fx( Word16 ix1 = 0; Word16 ix2 = 0; Word16 iy = 0; - Word16 e_result; FOR( i = 0; i < N; i++ ) { y[iy] = L_add(x1[ix1], x2[ix2]); diff --git a/lib_com/lag_wind.c b/lib_com/lag_wind.c index f22c4d6a6f51c30e0762a55663a7c76fdbb511ea..53cbcd97ba192721917d0b55c0a838dd1a4ad1c7 100644 --- a/lib_com/lag_wind.c +++ b/lib_com/lag_wind.c @@ -245,7 +245,6 @@ void lag_wind_32( ) { Word16 i; - Word32 tmp; const Word32* wnd; diff --git a/lib_com/options.h b/lib_com/options.h index 3536ef9cc62776750e94101eceb8d6540f8e88ac..3fb633b7fd6528afdaed380799a98ace41c3fb00 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -80,7 +80,7 @@ #define FIX_854_ARRAY_SIZE_MISMATCH /* VA: issue 854: correct the mismatch between definition and declaration of `ivas_core_dec() */ #define FIX_785_REMOVE_DEAD_CODE /* VA: issue 785: remove dead code */ #define FIX_852_FIX_HANDLE_DEREF /* VA: issue 852: Fix missing handle dereferencing of hIsmMetadaData in ivas_ism_metadata_close() */ - +#define FIX_901_PARAMMC_DEAD_CODE /* FhG: issue 901: remove dead ParamMC code */ /* #################### End BE switches ################################## */ @@ -120,4 +120,6 @@ /* clang-format on */ #define NONBE_FIX_1010_STEREO_CNG_DIV_BY_ZERO +#define UNUSED_PARAM(...) (void)(__VA_ARGS__) + #endif diff --git a/lib_com/prot.h b/lib_com/prot.h index ec3d3bc2ca9c315ad5bf7903413e1caa9e9343ba..2341895efdd46d2ba0bc8fdb0fc5b1bdb2be1671 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -5286,6 +5286,12 @@ ivas_error init_decoder( const MC_MODE mc_mode /* i : MC mode */ ); +#ifdef IVAS_FLOAT_FIXED +void destroy_cldfb_decoder_ivas_fx( + Decoder_State *st /* o : Decoder static variables structure */ +); +#endif // IVAS_FLOAT_FIXED + void destroy_cldfb_decoder_flt( Decoder_State *st /* o : Decoder static variables structure */ ); diff --git a/lib_com/prot_fx1.h b/lib_com/prot_fx1.h index 3654f330a994b64f331b4f474fd6c93865b34863..9ddacf686372e8ab4604258edf4d30653a7e3b20 100644 --- a/lib_com/prot_fx1.h +++ b/lib_com/prot_fx1.h @@ -183,6 +183,11 @@ Word16 maximum_fx( /* o : index of the maximum value i const Word16 lvec_fx, /* i : length of input vector */ Word16 *max_fx /* o : maximum value in the input vector */ ); +Word16 minimum_abs32_fx( /* o : index of the minimum value in the input vector */ + const Word32 *vec_fx, /* i : input vector */ + const Word16 lvec_fx, /* i : length of input vector */ + Word32 *min_fx /* o : minimum value in the input vector */ +); Word16 minimum_32_fx( /* o : index of the minimum value in the input vector */ const Word32 *vec_fx, /* i : input vector */ const Word16 lvec_fx, /* i : length of input vector */ diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 362e51c917c3d4519959c801c0ad58c518772fa8..b7530b6745d31228f4e5fe2f69ac0608ef38ced1 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -93,6 +93,8 @@ void floatToFixed_arrL( float * f, Word32* i, Word16 Q, Word16 l); void floatToFixed_arr( float * f, Word16* i, Word16 Q, Word16 l); void fixedToFloat_arrL( Word32 *i, float * f, Word16 Q, Word16 l); void fixedToFloat_arr( Word16 *i, float * f, Word16 Q, Word16 l); +void floatToFixed_arrL32(float * f, Word32* i, Word16 Q, Word16 l); +void fixedToFloat_arrL32(Word32 *i, float * f, Word16 Q, Word16 l); Word16 Q_factor(float x); Word16 Q_factor_L(float x); Word16 Q_factor_arr(float* x, Word16 l); @@ -100,6 +102,8 @@ Word16 Q_factor_arrL(float* x, Word16 l); //Handles the cases where Q is negative Word32 floatToFixed( float f, Word16 Q); float fixedToFloat( Word32 i, Word16 Q); +Word32 floatToFixed_32(float f, Word16 Q); +float fixedToFloat_32(Word32 i, Word16 Q); void floatToFixed_arr16(float *f, Word16 *i, Word16 Q, Word16 l); void floatToFixed_arr32(float *f, Word32 *i, Word16 Q, Word16 l); @@ -7080,6 +7084,7 @@ void GSC_dec_init_ivas_fx( Word16 *timeDomainInput, /* i : pointer to time domain input */ Word16 Q, Word32 *powerSpectrum, + Word16 Q_power_spectrum, Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ @@ -7110,6 +7115,7 @@ void GSC_dec_init_ivas_fx( const Word16 *timeDomainInput, /* i: pointer to time domain input */ const Word16 Q, Word32 *power_spectrum, + Word16 Q_power_spectrum, HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure containing all buffers and variables */ const Word16 element_mode, /* i : element mode */ const Word16 bwidth, /* i : audio bandwidth */ @@ -9062,6 +9068,7 @@ void cldfbAnalysis_ts_fx( HANDLE_CLDFB_FILTER_BANK h_cldfb , Word16* q_cldfb ); +Word16 floor_log_2(Word32 num); void cldfbAnalysis_ts_fx_fixed_q( const Word32 *timeIn_fx, /* i : time buffer */ // q diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index ce5353b2091675a7ad5446298c6061ed67d596af..bc6b565f819a0ff77dc1c1332c892ad203ee564c 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -461,6 +461,7 @@ typedef struct Word16 exp_cldfb_periodog; Word32 cngNoiseLevel[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band */ + Word16 q_cngNoiseLevel; Word16 cngNoiseLevelExp; int16_t seed; /* Seed memory (for random function) */ @@ -817,11 +818,13 @@ typedef struct pfstat_structure { int16_t on; /* On/off flag */ int16_t reset; /* reset flag */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mem_pf_in_flt[L_SUBFR]; /* Input memory */ float mem_stp_flt[L_SUBFR]; /* 1/A(gamma1) memory */ float mem_res2_flt[DECMEM_RES2]; /* A(gamma2) residual */ float mem_zero_flt[M]; /* null memory to compute i.r. of A(gamma2)/A(gamma1) */ float gain_prec_flt; /* for gain adjustment */ +#endif Word16 mem_pf_in[L_SUBFR]; /* Input memory */ Word16 mem_stp[L_SUBFR]; /* 1/A(gamma1) memory */ Word16 mem_res2[DECMEM_RES2]; /* A(gamma2) residual */ diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c index e42141e001c53f532465788b254912806c1fd81a..170f4f5e5311fc1820e6bfdbc16d3ce1c55786c4 100644 --- a/lib_com/swb_tbe_com.c +++ b/lib_com/swb_tbe_com.c @@ -1365,6 +1365,7 @@ void GenShapedSHBExcitation( return; } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * GenSHBSynth() * @@ -1398,6 +1399,7 @@ void GenSHBSynth( return; } +#endif #ifdef IVAS_FLOAT_FIXED void GenSHBSynth_fx_32( const Word32 *input_synspeech, /* i : input synthesized speech Qx*/ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index a04f3c5ae75591ad123cd0f8dd793e544f077d18..72f498925218adda6f526f1dcd73684834fbdbf5 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -11,6 +11,9 @@ #include "prot_fx1.h" #include "prot_fx2.h" #include "basop_util.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif #define POW_EXC16k_WHTND 1.14e11f /* power of random excitation, length 320 samples, uniform distribution */ #define POW_EXC16k_WHTND_FX_INV_SQRT 6360 //Q31 @@ -72,7 +75,20 @@ void swb_tbe_reset_fx( * Reset the extra parameters needed for synthesis of the SWB TBE output *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void swb_tbe_reset_synth_ivas_fx( + Word32 genSHBsynth_Hilbert_Mem[], + Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[], + Word32 genSHBsynth_state_lsyn_filt_shb_local_fx_32[] ) +{ + set32_fx( genSHBsynth_Hilbert_Mem, 0, HILBERT_MEM_SIZE ); + set16_fx( genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2*ALLPASSSECTIONS_STEEP ); + set32_fx( genSHBsynth_state_lsyn_filt_shb_local_fx_32, 0, 2*ALLPASSSECTIONS_STEEP ); + + return; +} +#endif void swb_tbe_reset_synth_fx( Word32 genSHBsynth_Hilbert_Mem[], Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[] ) @@ -2631,7 +2647,6 @@ void GenShapedSHBExcitation_ivas_fx( Word16 prev_Q_bwe_exc_fb; #if 1//def ADD_IVAS_TBE_CODE - Word32 tempD; Word16 alpha, step, mem_csfilt_left, mem_csfilt_right, excNoisyEnvLeft[L_FRAME16k], excNoisyEnvRight[L_FRAME16k]; Word16 cbsize; Word16 mix_factor, old_fact, new_fact, fact, old_scale, new_scale, step_scale; @@ -3040,6 +3055,8 @@ void GenShapedSHBExcitation_ivas_fx( } } else +#else + UNUSED_PARAM(Env_error_part, Env_error, EnvSHBres_4k, c5_part, c1, den, c3_part, c0, delta, c3, c2_part, c1_part, EnvWhiteExc16k, g2, c5, c4_part, EnvWhiteExc16k_4k, c2, g, cbsize, g1, EnvExc16kWhtnd, c0_part, EnvExc16kWhtnd_4k, c4); #endif { Estimate_mix_factors_fx(shb_res, Q_shb, exc16kWhtnd, *Q_bwe_exc, White_exc16k, diff --git a/lib_com/tcx_ltp.c b/lib_com/tcx_ltp.c index ffb0522323e5ca9e6b46e610aab916f2df0a50ea..5c79b03d1c4f1ef9af59af10d3d6190259a893f4 100644 --- a/lib_com/tcx_ltp.c +++ b/lib_com/tcx_ltp.c @@ -801,7 +801,7 @@ static void tcx_ltp_synth_filter_11_unequal_pitch_flt( * * *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void tcx_ltp_post_flt( Decoder_State *st, TCX_LTP_DEC_HANDLE hTcxLtpDec, @@ -1093,3 +1093,4 @@ void tcx_ltp_post_flt( return; } +#endif \ No newline at end of file diff --git a/lib_com/tec_com_flt.c b/lib_com/tec_com_flt.c index 46a38b916bbd85a63d9d9be8399968de0c7f4db3..b8a9c4e01d6a428affe258757ac9105deace74de 100644 --- a/lib_com/tec_com_flt.c +++ b/lib_com/tec_com_flt.c @@ -269,6 +269,7 @@ static float calcCorrelationCoefficient2( } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*------------------------------------------------------------------- * resetTecDec() * @@ -284,6 +285,7 @@ void resetTecDec( return; } +#endif /*------------------------------------------------------------------- diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index bba479099e4b0044b710b2146b3eb2950838572a..3e23761517afffc62529c4237e5273445d856cc7 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -79,6 +79,7 @@ float fix_to_float( Word32 number, Word32 Q ) Word16 float_to_fix16( float number, Word16 Q ) { assert( Q >= 0 ); + IF(isnan(number)) return 0; if ( number == 1.0f && Q == Q15 ) return MAX16B; assert( fabs( number ) < pow( 2, 15 - Q ) ); @@ -1048,6 +1049,41 @@ Word16 maximum_fx( /* o : index of the maximum value in the input vecto return ind; } +/*---------------------------------------------------------------------* + * minimum_abs32_fx() + * + * Find index and value of the absolute minimum in a vector + *---------------------------------------------------------------------*/ +Word16 minimum_abs32_fx( /* o : index of the minimum value in the input vector */ + const Word32 *vec_fx, /* i : input vector */ + const Word16 lvec_fx, /* i : length of input vector */ + Word32 *min_fx /* o : minimum value in the input vector */ +) +{ + Word16 j, ind; + Word32 tmp; + ind = 0; + move16(); + tmp = vec_fx[0]; + move16(); + + FOR ( j=1 ; jLDm_mem_etot = 0.0f; #endif #ifdef IVAS_FLOAT_FIXED - hMusicPF->LDm_mem_etot_fx = 0.0f; + hMusicPF->LDm_mem_etot_fx = 0; #endif for ( i = 0; i < VOIC_BINS_HR; i++ ) diff --git a/lib_dec/LD_music_post_filter_fx.c b/lib_dec/LD_music_post_filter_fx.c index a7eb8764b03c440a12b17488a026bd16b81f9030..042791463c56510f66e330f8bed2aa5da12eff16 100644 --- a/lib_dec/LD_music_post_filter_fx.c +++ b/lib_dec/LD_music_post_filter_fx.c @@ -439,7 +439,18 @@ static void spectrum_mod_dct_fx( *-----------------------------------------------------------------*/ scaling = add(shl(Qdct,1),10); - dot5_scaled = L_shl(1, sub(scaling,1)); + IF(LE_16(scaling, 31)) + { + /* Calculate .5 in Qscaling only if scaling <= 31 */ + dot5_scaled = L_shl(1, sub(scaling,1)); + } + ELSE + { + /* This is only for avaoiding build warning */ + dot5_scaled = MAX_32; + move32(); + } + FOR ( i=0; i<=MBANDS_GN_LD-1; i++) { /*inv_noise[i] = 1.0f / noiseE[i];*/ @@ -561,7 +572,8 @@ static void spectrum_mod_dct_fx( /*gain = 1.0f;*/ Lgain = L_deposit_h(16384); /*if (noiseE[i] >= 0.5f)*/ - IF (GT_32(noiseE[i], dot5_scaled))/* Do not alter if noise E very low */ + test(); + IF (LT_16(scaling, 32) && GT_32(noiseE[i], dot5_scaled))/* Do not alter if noise E very low */ { /*gain = tmpN * *pt2 + shift;*/ /* limits: [x,y] = {[1, minE], [MAX_SNR1, 1]}, */ e_binE = norm_l(*Lpt2); diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index d97fcd0c58426aa4747178e3441e733e52714cfc..6af132d21edad1813ba64eee93861537eff6781d 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -208,42 +208,18 @@ ivas_error acelp_core_dec_ivas_fx( } #ifdef IVAS_FLOAT_FIXED - /*st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; - for ( int p = 0; p < NPART; p++ ) - { - st->hFdCngDec->hFdCngCom->sidNoiseEstLp[p] = (Word32) ( st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ) ); - st->hFdCngDec->hFdCngCom->sidNoiseEst[p] = (Word32) ( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ) ); - } + for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) { st->hFdCngDec->bandNoiseShape[p] = (Word32) ( st->hFdCngDec->bandNoiseShape_float[p] * ( 1u << ( 31 - st->hFdCngDec->bandNoiseShape_exp ) ) ); - }*/ + } - ApplyFdCng_fx( NULL, 0, NULL, NULL, NULL, NULL, st, 0, 0 ); + ApplyFdCng_fx( NULL, 0, NULL, 0, NULL, NULL, NULL, st, 0, 0 ); if (st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0) { Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; } - /*for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) - { - if ( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp <= 31 ) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); - } - else - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] * ( 1u << ( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - 31 ) ) ); - } - } - for ( int p = 0; p < NPART; p++ ) - { - st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt[p] = (float) st->hFdCngDec->hFdCngCom->sidNoiseEstLp[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ); - } - for ( int p = 0; p < 24; p++ ) - { - st->hFdCngDec->partNoiseShape_float[p] = (float) st->hFdCngDec->partNoiseShape[p] / ( 1u << ( 31 - st->hFdCngDec->partNoiseShape_exp ) ); - }*/ #else ApplyFdCng_flt( NULL, NULL, NULL, NULL, st, 0, 0 ); #endif // IVAS_FLOAT_FIXED @@ -415,7 +391,6 @@ ivas_error acelp_core_dec_ivas_fx( { st->gamma = GAMMA1; st->inv_gamma = GAMMA1_INV; - st->preemph_fac_float = PREEMPH_FAC_FLT; st->preemph_fac = PREEMPH_FAC; int_fs = INT_FS_12k8; } @@ -423,7 +398,6 @@ ivas_error acelp_core_dec_ivas_fx( { st->gamma = GAMMA16k; st->inv_gamma = GAMMA16k_INV; - st->preemph_fac_float = PREEMPH_FAC_16k_FLT; st->preemph_fac = PREEMPH_FAC_16k; int_fs = INT_FS_16k; } @@ -630,7 +604,7 @@ ivas_error acelp_core_dec_ivas_fx( } //st->bfi_pitch *= tmpF; //st->bfi_pitch_frame = L_FRAME; - st->bfi_pitch = mult_r(st->bfi_pitch, tmpF_fx); + st->bfi_pitch_fx = mult_r(st->bfi_pitch_fx, tmpF_fx); st->bfi_pitch_frame = L_FRAME; move16(); } @@ -656,7 +630,7 @@ ivas_error acelp_core_dec_ivas_fx( } //st->bfi_pitch *= tmpF; //st->bfi_pitch_frame = L_FRAME16k; - st->bfi_pitch = mult_r( shl_sat( st->bfi_pitch, exp ), tmpF_fx ); + st->bfi_pitch_fx = mult_r( shl_sat( st->bfi_pitch_fx, exp ), tmpF_fx ); st->bfi_pitch_frame = L_FRAME16k; move16(); } @@ -664,7 +638,6 @@ ivas_error acelp_core_dec_ivas_fx( /*Local fix2float (to be removed)*/ /*fixedToFloat_arr(old_exc_fx, old_exc, st->Q_exc, L_EXC_DEC); - fixedToFloat_arr(old_exc2_fx, old_exc2, st->Q_exc, L_FRAME16k + L_EXC_MEM); fixedToFloat_arr(gain_buf_fx, gain_buf, Q14, NB_SUBFR16k);*/ if ( st->last_bwidth == NB && st->bwidth != NB && st->ini_frame != 0 ) @@ -756,28 +729,12 @@ ivas_error acelp_core_dec_ivas_fx( Mpy_32_32( STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] ) ); } #ifdef IVAS_FLOAT_FIXED - /*Word16 syn_fx[L_FRAME16k + L_SUBFR] = { 0 }; - st->Q_syn = 0; - for ( int p = 0; p < L_FRAME16k; p++ ) - { - syn_fx[L_SUBFR + p] = (Word16) ( syn[p] * ( 1u << st->Q_syn ) ); - }*/ /* local float2fix (to be removed) */ - /*for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) + for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) { st->hFdCngDec->bandNoiseShape[p] = (Word32) ( st->hFdCngDec->bandNoiseShape_float[p] * ( 1u << ( 31 - st->hFdCngDec->bandNoiseShape_exp ) ) ); } - st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; - for ( int p = 0; p < NPART; p++ ) - { - st->hFdCngDec->hFdCngCom->sidNoiseEstLp[p] = (Word32)(st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt[p] * (1u << (31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp))); - st->hFdCngDec->hFdCngCom->sidNoiseEst[p] = (Word32) ( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ) ); - } - for (int p = 0; p < FFTCLDFBLEN; p++) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32)(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * (1u << (31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp))); - }*/ - Word16 new_sidNoiseEstExp = 31 - Q4; + Word16 new_sidNoiseEstExp = 31 - Q4; Scale_sig32(st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - new_sidNoiseEstExp); Scale_sig32(st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - new_sidNoiseEstExp); st->hFdCngDec->hFdCngCom->sidNoiseEstExp = new_sidNoiseEstExp; @@ -785,31 +742,12 @@ ivas_error acelp_core_dec_ivas_fx( Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - new_cngNoiseLevelExp); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = new_cngNoiseLevelExp; - ApplyFdCng_fx(psyn_fx, st->Q_syn, NULL, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); + ApplyFdCng_fx(psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); if (st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0) { Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; } - /*for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) - { - if ( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp <= 31 ) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); - } - else - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] * ( 1u << ( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - 31 ) ) ); - } - } - for ( int p = 0; p < NPART; p++ ) - { - st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt[p] = (float) st->hFdCngDec->hFdCngCom->sidNoiseEstLp[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ); - } - for ( int p = 0; p < 24; p++ ) - { - st->hFdCngDec->partNoiseShape_float[p] = (float) st->hFdCngDec->partNoiseShape[p] / ( 1u << ( 31 - st->hFdCngDec->partNoiseShape_exp ) ); - }*/ #else ApplyFdCng_flt( syn, NULL, realBuffer, imagBuffer, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); #endif // IVAS_FLOAT_FIXED @@ -1041,7 +979,8 @@ ivas_error acelp_core_dec_ivas_fx( old_exc_s_fx = st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame; //tmpF = *old_exc_s; tmpF_fx = *old_exc_s_fx; - st->mem_deemph = old_exc_s_fx[st->L_frame - 1]; + //st->mem_deemph = old_exc_s_fx[st->L_frame - 1]; + st->mem_deemph_fx = old_exc_s_fx[st->L_frame - 1]; //preemph( old_exc_s, st->preemph_fac_float, L_FRAME16k, &tmpF ); preemph_fx( old_exc_s_fx, st->preemph_fac, L_FRAME16k, &tmpF_fx ); //mvr2r( old_exc_s + st->L_frame - M, st->mem_syn2, M ); @@ -1778,40 +1717,7 @@ ivas_error acelp_core_dec_ivas_fx( { /*Noise estimate*/ #ifdef IVAS_FLOAT_FIXED - //Word16 syn_fx[L_FRAME16k + L_SUBFR] = { 0 }; - /*st->Q_syn = 0; - for ( int p = 0; p < L_FRAME16k; p++ ) - { - syn_fx[L_SUBFR + p] = (Word16) ( syn[p] * ( 1u << st->Q_syn ) ); - }*/ - /*for (int p = 0; p < L_FRAME16k; p++) - { - psyn_fx[p] = (Word16)(syn[p] * (1u << st->Q_syn)); - }*/ - //for (int p = 0; p < st->L_frame; p++) - //{ - // st->hFdCngDec->hFdCngCom->periodog[p] = (Word32)(st->hFdCngDec->hFdCngCom->periodog_flt[p] * (1u << (31 - st->hFdCngDec->hFdCngCom->periodog_exp))); - //} - //st->hFdCngDec->hFdCngCom->fftBuffer_exp = 31 - Q4; - //for (int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++) - //{ - // st->hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32)(st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] * (1u << (31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp))); - //} - //st->hFdCngDec->msNoiseEst_exp = 31 - Q4; // Q4 - //for (int p = 0; p < st->hFdCngDec->npart_shaping; p++) - //{ - // st->hFdCngDec->msNoiseEst[p] = (Word32)(st->hFdCngDec->msNoiseEst_float[p] * (1u << (31 - st->hFdCngDec->msNoiseEst_exp))); - // st->hFdCngDec->msPeriodog[p] = (Word32)(st->hFdCngDec->msPeriodog_float[p] * (1u << (31 - st->hFdCngDec->msPeriodog_exp))); - // st->hFdCngDec->msPeriodog_ST_fx[p] = (Word32)(st->hFdCngDec->msPeriodog_ST[p] * (1u << (31 - st->hFdCngDec->msPeriodog_ST_exp))); - //} - //st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4 - //for (int p = 0; p < FFTCLDFBLEN; p++) - //{ - // st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32)(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * (1u << (31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp))); - //} - //st->hFdCngDec->partNoiseShape_exp = 31 - Q4; // Q4 - //floatToFixed_arrL(st->hFdCngDec->partNoiseShape_float, st->hFdCngDec->partNoiseShape, Q31 - st->hFdCngDec->partNoiseShape_exp, NPART); - //Scale_sig(syn_tmp_fx, L_FRAME16k + L_SUBFR, 0 - st->Q_syn); //Q0 + Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - Q27); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4 @@ -1820,7 +1726,7 @@ ivas_error acelp_core_dec_ivas_fx( st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; // Q4 /*==========================================================*/ //ApplyFdCng_fx( syn_fx + L_SUBFR, st->Q_syn, NULL, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); - ApplyFdCng_fx(psyn_fx, st->Q_syn, NULL, realBuffer_fx, imagBuffer_fx, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); + ApplyFdCng_fx(psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); /*==========================================================*/ if (st->hFdCngDec->partNoiseShape_exp < 0) { Scale_sig32(st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp); @@ -1830,120 +1736,7 @@ ivas_error acelp_core_dec_ivas_fx( Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; } - //Scale_sig(syn_tmp_fx, L_FRAME16k + L_SUBFR, st->Q_syn); //Q_syn - //fixedToFloat_arrL(st->hFdCngDec->partNoiseShape, st->hFdCngDec->partNoiseShape_float, Q31 - st->hFdCngDec->partNoiseShape_exp, NPART); - - //if (((st->m_frame_type == ACTIVE_FRAME) && ((st->bfi == 0 && - // (psyn_fx == NULL || - // (*psyn_fx(-FLT_MAX) && - // *(psyn_fx + st->hFdCngDec->hFdCngCom->frameSize - 1) < FLT_MAX && - // *(psyn_fx + st->hFdCngDec->hFdCngCom->frameSize - 1) > (-FLT_MAX))) && - // ((((st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && st->hFdCngDec->flag_dtx_mode) || !st->VAD || (st->ini_frame < 100 && st->is_ism_format)) && - // !(st->cng_type == LP_CNG && st->hFdCngDec->flag_dtx_mode)) || - // (st->element_mode == IVAS_CPE_TD)) && - // (!st->BER_detect)) || - // ((st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT) && (st->hFdCngDec->hFdCngCom->active_frame_counter > 0)) || ((st->bfi == 1) && (st->nbLostCmpt == 1)))) || - // (st->m_frame_type == ZERO_FRAME) && (st != NULL && st->cng_type == LP_CNG)) - //{ - // { - // for (int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++) - // { - // st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ((float)st->hFdCngDec->hFdCngCom->fftBuffer[p] / (1u << (31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp))); - // } - - // for (int p = 0; p < (st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand); p++) - // { - // st->hFdCngDec->bandNoiseShape_float[p] = ((float)st->hFdCngDec->bandNoiseShape[p] / (1u << (31 - st->hFdCngDec->bandNoiseShape_exp))); - // } - // for (int p = 0; p < st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; p++) - // { - // st->hFdCngDec->hFdCngCom->periodog_flt[p] = ((float)st->hFdCngDec->hFdCngCom->periodog[p] / (float)(1u << (31 - st->hFdCngDec->hFdCngCom->periodog_exp))); - // } - // for (int p = 0; p < st->hFdCngDec->npart_shaping; p++) - // { - // st->hFdCngDec->msPsd_float[p] = ((float)st->hFdCngDec->msPsd_fx[p] / (1u << (31 - st->hFdCngDec->msPsd_exp_fft))); - // st->hFdCngDec->msNoiseEst_float[p] = (float)st->hFdCngDec->msNoiseEst[p] / (1u << (31 - st->hFdCngDec->msNoiseEst_exp)); - // st->hFdCngDec->msPeriodog_float[p] = ((float)st->hFdCngDec->msPeriodog[p] / (1u << (31 - st->hFdCngDec->msPeriodog_exp))); - // st->hFdCngDec->msPeriodog_ST[p] = ((float)st->hFdCngDec->msPeriodog_ST_fx[p] / (1u << (31 - st->hFdCngDec->msPeriodog_ST_exp))); - // } - // if (st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT) - // { - // for (int p = 0; p < L_FRAME16k - st->hFdCngDec->hFdCngCom->startBand; p++) - // { - // st->hFdCngDec->smoothed_psd[st->hFdCngDec->hFdCngCom->startBand + p] = ((float)st->hFdCngDec->smoothed_psd_fx[st->hFdCngDec->hFdCngCom->startBand + p] / (1u << (31 - st->hFdCngDec->msNoiseEst_exp))); - // } - // } - // } - // if (!((st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT) && (st->hFdCngDec->hFdCngCom->active_frame_counter > 0))) - // { - // st->hTcxDec->CngLevelBackgroundTrace_bfi = fix_to_float(st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, (31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp)); - // st->cngTDLevel_float = fixedToFloat(st->cngTDLevel, (15 - st->cngTDLevel_e)); - // for (int p = 0; p < (st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand); p++) - // { - // st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ((float)st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / (1u << (31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp))); - // } - // IF(!(EQ_16(st->element_mode, IVAS_CPE_TD) || EQ_16(st->element_mode, IVAS_CPE_DFT))) - // { - // for (int p = 0; p < MSNUMSUBFR * NPART_SHAPING; p++) - // { - // if ((st->hFdCngDec->msMinBuf[p] == MAX_32)) - // { - // st->hFdCngDec->msMinBuf_float[p] = FLT_MAX; - // } - // else - // { - // st->hFdCngDec->msMinBuf_float[p] = (float)st->hFdCngDec->msMinBuf[p] / (1u << (31 - 6)); // CNG_S = 6 - // } - // } - // for (int p = 0; p < st->hFdCngDec->npart_shaping; p++) - // { - // st->hFdCngDec->msPeriodogBuf_float[p] = ((float)st->hFdCngDec->msPeriodogBuf[p] / (1u << Q9)); - // st->hFdCngDec->msPsdFirstMoment_float[p] = ((float)st->hFdCngDec->msPsdFirstMoment[p] / (1u << Q9)); - // st->hFdCngDec->msPsdSecondMoment_float[p] = ((float)st->hFdCngDec->msPsdSecondMoment[p] / (1u << Q19)); - // st->hFdCngDec->msNoiseFloor_float[p] = ((float)st->hFdCngDec->msNoiseFloor[p] / (1u << Q9)); - // st->hFdCngDec->msAlpha_float[p] = ((float)st->hFdCngDec->msAlpha[p] / (1u << Q31)); - // st->hFdCngDec->msBminWin_float[p] = ((float)st->hFdCngDec->msBminWin[p] / (1u << Q27)); - // st->hFdCngDec->msBminSubWin_float[p] = ((float)st->hFdCngDec->msBminSubWin[p] / (1u << Q27)); - // if (st->hFdCngDec->msCurrentMin[p] == MAX_32) - // { - // st->hFdCngDec->msCurrentMin_float[p] = FLT_MAX; - // } - // else - // { - // st->hFdCngDec->msCurrentMin_float[p] = ((float)st->hFdCngDec->msCurrentMin[p] / (1u << (31 - (6 + 1 + 4)))); // exp : CNG_S + 1 + 4 - // } - // if (st->hFdCngDec->msCurrentMinOut[p] == MAX_32) - // { - // st->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX; - // } - // else - // { - // st->hFdCngDec->msCurrentMinOut_float[p] = ((float)st->hFdCngDec->msCurrentMinOut[p] / (1u << (31 - 6))); - // } - // if (st->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32) - // { - // st->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX; - // } - // else - // { - // st->hFdCngDec->msCurrentMinSubWindow_float[p] = ((float)st->hFdCngDec->msCurrentMinSubWindow[p] / (1u << (31 - 6))); - // } - // } - // } - // if ( sum_f( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt + st->hFdCngDec->hFdCngCom->startBand, st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ) > 0.01f ) - // { - // if ( st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE ) - // { - // int A_cng_q = 15 - norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ); - // for ( int p = 0; p < M; p++ ) - // { - // st->hFdCngDec->hFdCngCom->A_cng_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->A_cng[p] / ( 1u << A_cng_q ) ); - // st->lspold_cng_float[p] = ( (float) st->lspold_cng[p] / ( 1u << Q15 ) ); - // } - // } - // } - // } - //} + #else ApplyFdCng_flt(syn, NULL, realBuffer, imagBuffer, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); #endif // IVAS_FLOAT_FIXED @@ -2035,37 +1828,7 @@ ivas_error acelp_core_dec_ivas_fx( if (st->idchan == 0 && (nchan_out == 2 || (st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40))) { #ifdef IVAS_FLOAT_FIXED - //Word16 syn_fx[L_FRAME16k + L_SUBFR] = { 0 }; - //st->Q_syn = 0; - //for (int p = 0; p < L_FRAME16k; p++) - //{ - // psyn_fx[p] = (Word16)(syn[p] * (1u << st->Q_syn)); - //} - //for (int p = 0; p < st->L_frame; p++) - //{ - // st->hFdCngDec->hFdCngCom->periodog[p] = (Word32)(st->hFdCngDec->hFdCngCom->periodog_flt[p] * (1u << (31 - st->hFdCngDec->hFdCngCom->periodog_exp))); - //} - //st->hFdCngDec->hFdCngCom->fftBuffer_exp = 31 - Q4; - //for (int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++) - //{ - // st->hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32)(st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] * (1u << (31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp))); - //} - //st->hFdCngDec->msNoiseEst_exp = 31 - Q4; - //for (int p = 0; p < st->hFdCngDec->npart_shaping; p++) - //{ - // st->hFdCngDec->msNoiseEst[p] = (Word32)(st->hFdCngDec->msNoiseEst_float[p] * (1u << (31 - st->hFdCngDec->msNoiseEst_exp))); - // st->hFdCngDec->msPeriodog[p] = (Word32)(st->hFdCngDec->msPeriodog_float[p] * (1u << (31 - st->hFdCngDec->msPeriodog_exp))); - // st->hFdCngDec->msPeriodog_ST_fx[p] = (Word32)(st->hFdCngDec->msPeriodog_ST[p] * (1u << (31 - st->hFdCngDec->msPeriodog_ST_exp))); - //} - //st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; - //for (int p = 0; p < FFTCLDFBLEN; p++) - //{ - // st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32)(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * (1u << (31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp))); - //} - //st->hFdCngDec->partNoiseShape_exp = 31 - Q4; // Q4 - //floatToFixed_arrL(st->hFdCngDec->partNoiseShape_float, st->hFdCngDec->partNoiseShape, Q31 - st->hFdCngDec->partNoiseShape_exp, NPART); - - ApplyFdCng_fx(psyn_fx, st->Q_syn, NULL, realBuffer_fx, imagBuffer_fx, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); + ApplyFdCng_fx(psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); if (st->hFdCngDec->partNoiseShape_exp < 0) { Scale_sig32(st->hFdCngDec->partNoiseShape, NPART, -st->hFdCngDec->partNoiseShape_exp); st->hFdCngDec->partNoiseShape_exp = 0; @@ -2078,119 +1841,7 @@ ivas_error acelp_core_dec_ivas_fx( Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; } - //fixedToFloat_arrL(st->hFdCngDec->partNoiseShape, st->hFdCngDec->partNoiseShape_float, Q31 - st->hFdCngDec->partNoiseShape_exp, NPART); - - //if (((st->m_frame_type == ACTIVE_FRAME) && ((st->bfi == 0 && - // (psyn_fx == NULL || - // (*psyn_fx(-FLT_MAX) && - // *(psyn_fx + st->hFdCngDec->hFdCngCom->frameSize - 1) < FLT_MAX && - // *(psyn_fx + st->hFdCngDec->hFdCngCom->frameSize - 1) > (-FLT_MAX))) && - // ((((st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && st->hFdCngDec->flag_dtx_mode) || !st->VAD || (st->ini_frame < 100 && st->is_ism_format)) && - // !(st->cng_type == LP_CNG && st->hFdCngDec->flag_dtx_mode)) || - // (st->element_mode == IVAS_CPE_TD)) && - // (!st->BER_detect)) || - // ((st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT) && (st->hFdCngDec->hFdCngCom->active_frame_counter > 0)) || ((st->bfi == 1) && (st->nbLostCmpt == 1)))) || - // (st->m_frame_type == ZERO_FRAME) && (st != NULL && st->cng_type == LP_CNG)) - //{ - // { - // for (int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++) - // { - // st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ((float)st->hFdCngDec->hFdCngCom->fftBuffer[p] / (1u << (31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp))); - // } - - // for (int p = 0; p < (st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand); p++) - // { - // st->hFdCngDec->bandNoiseShape_float[p] = ((float)st->hFdCngDec->bandNoiseShape[p] / (1u << (31 - st->hFdCngDec->bandNoiseShape_exp))); - // } - // for (int p = 0; p < st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; p++) - // { - // st->hFdCngDec->hFdCngCom->periodog_flt[p] = ((float)st->hFdCngDec->hFdCngCom->periodog[p] / (float)(1u << (31 - st->hFdCngDec->hFdCngCom->periodog_exp))); - // } - // for (int p = 0; p < st->hFdCngDec->npart_shaping; p++) - // { - // st->hFdCngDec->msPsd_float[p] = ((float)st->hFdCngDec->msPsd_fx[p] / (1u << (31 - st->hFdCngDec->msPsd_exp_fft))); - // st->hFdCngDec->msNoiseEst_float[p] = (float)st->hFdCngDec->msNoiseEst[p] / (1u << (31 - st->hFdCngDec->msNoiseEst_exp)); - // st->hFdCngDec->msPeriodog_float[p] = ((float)st->hFdCngDec->msPeriodog[p] / (1u << (31 - st->hFdCngDec->msPeriodog_exp))); - // st->hFdCngDec->msPeriodog_ST[p] = ((float)st->hFdCngDec->msPeriodog_ST_fx[p] / (1u << (31 - st->hFdCngDec->msPeriodog_ST_exp))); - // } - // if (st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT) - // { - // for (int p = 0; p < L_FRAME16k - st->hFdCngDec->hFdCngCom->startBand; p++) - // { - // st->hFdCngDec->smoothed_psd[st->hFdCngDec->hFdCngCom->startBand + p] = ((float)st->hFdCngDec->smoothed_psd_fx[st->hFdCngDec->hFdCngCom->startBand + p] / (1u << (31 - st->hFdCngDec->msNoiseEst_exp))); - // } - // } - // } - // if (!((st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT) && (st->hFdCngDec->hFdCngCom->active_frame_counter > 0))) - // { - // st->hTcxDec->CngLevelBackgroundTrace_bfi = fix_to_float(st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, (31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp)); - // st->cngTDLevel_float = fixedToFloat(st->cngTDLevel, (15 - st->cngTDLevel_e)); - // for (int p = 0; p < (st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand); p++) - // { - // st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ((float)st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / (1u << (31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp))); - // } - // IF(!(EQ_16(st->element_mode, IVAS_CPE_TD) || EQ_16(st->element_mode, IVAS_CPE_DFT))) - // { - // for (int p = 0; p < MSNUMSUBFR * NPART_SHAPING; p++) - // { - // if ((st->hFdCngDec->msMinBuf[p] == MAX_32)) - // { - // st->hFdCngDec->msMinBuf_float[p] = FLT_MAX; - // } - // else - // { - // st->hFdCngDec->msMinBuf_float[p] = (float)st->hFdCngDec->msMinBuf[p] / (1u << (31 - 6)); // CNG_S = 6 - // } - // } - // for (int p = 0; p < st->hFdCngDec->npart_shaping; p++) - // { - // st->hFdCngDec->msPeriodogBuf_float[p] = ((float)st->hFdCngDec->msPeriodogBuf[p] / (1u << Q9)); - // st->hFdCngDec->msPsdFirstMoment_float[p] = ((float)st->hFdCngDec->msPsdFirstMoment[p] / (1u << Q9)); - // st->hFdCngDec->msPsdSecondMoment_float[p] = ((float)st->hFdCngDec->msPsdSecondMoment[p] / (1u << Q19)); - // st->hFdCngDec->msNoiseFloor_float[p] = ((float)st->hFdCngDec->msNoiseFloor[p] / (1u << Q9)); - // st->hFdCngDec->msAlpha_float[p] = ((float)st->hFdCngDec->msAlpha[p] / (1u << Q31)); - // st->hFdCngDec->msBminWin_float[p] = ((float)st->hFdCngDec->msBminWin[p] / (1u << Q27)); - // st->hFdCngDec->msBminSubWin_float[p] = ((float)st->hFdCngDec->msBminSubWin[p] / (1u << Q27)); - // if (st->hFdCngDec->msCurrentMin[p] == MAX_32) - // { - // st->hFdCngDec->msCurrentMin_float[p] = FLT_MAX; - // } - // else - // { - // st->hFdCngDec->msCurrentMin_float[p] = ((float)st->hFdCngDec->msCurrentMin[p] / (1u << (31 - (6 + 1 + 4)))); // exp : CNG_S + 1 + 4 - // } - // if (st->hFdCngDec->msCurrentMinOut[p] == MAX_32) - // { - // st->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX; - // } - // else - // { - // st->hFdCngDec->msCurrentMinOut_float[p] = ((float)st->hFdCngDec->msCurrentMinOut[p] / (1u << (31 - 6))); - // } - // if (st->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32) - // { - // st->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX; - // } - // else - // { - // st->hFdCngDec->msCurrentMinSubWindow_float[p] = ((float)st->hFdCngDec->msCurrentMinSubWindow[p] / (1u << (31 - 6))); - // } - // } - // } - // if (sum_f(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt + st->hFdCngDec->hFdCngCom->startBand, st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand) > 0.01f) - // { - // if (st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE) - // { - // int A_cng_q = 15 - norm_s(st->hFdCngDec->hFdCngCom->A_cng[0]); - // for (int p = 0; p < M; p++) - // { - // st->hFdCngDec->hFdCngCom->A_cng_flt[p] = ((float)st->hFdCngDec->hFdCngCom->A_cng[p] / (1u << A_cng_q)); - // st->lspold_cng_float[p] = ((float)st->lspold_cng[p] / (1u << Q15)); - // } - // } - // } - // } - //} + #else ApplyFdCng_flt(syn, NULL, realBuffer, imagBuffer, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); #endif // IVAS_FLOAT_FIXED @@ -2272,15 +1923,10 @@ ivas_error acelp_core_dec_ivas_fx( Word32 pitch_buf_fx_q20[12]; - /*FOR(Word16 lp = 0; lp < 12; lp++) - { - st->old_pitch_buf_fx[lp] = (Word32)(st->old_pitch_buf[lp] * (1u << 20)); - }*/ Scale_sig32(st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4); Word16 lim = st->L_frame / 64; for (Word16 lp = 0; lp < lim; lp++) { - //pitch_buf_fx[lp] = (Word32)(pitch_buf[lp] * (1u << 20)); pitch_buf_fx_q20[lp] = L_shl(pitch_buf_fx[lp], Q14); } @@ -2459,12 +2105,6 @@ ivas_error acelp_core_dec_ivas_fx( /*WB/SWB-FD_CNG*/ IF((EQ_32(st->core_brate, FRAME_NO_DATA) || EQ_32(st->core_brate, SID_2k40)) && (EQ_16(st->cng_type, FD_CNG)) && (LE_16(st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels))) { - /* Float to fixed */ - //f2me_buf(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt, st->hFdCngDec->hFdCngCom->cngNoiseLevel, &st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, FFTCLDFBLEN); - - // NOTE: this should be removed later. - //st->hFdCngDec->hFdCngCom->q_cngNoiseLevel = 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp; - Word16 tmpBufferScale = 0; generate_comfort_noise_dec_hf_ivas_fx(realBuffer_fx, imagBuffer_fx, /*realBuffer, imagBuffer,*/ &tmpBufferScale, st->hFdCngDec->hFdCngCom, st->cng_ism_flag); @@ -2660,7 +2300,6 @@ ivas_error acelp_core_dec_ivas_fx( } /* save synthesis - needed in case of core switching */ - //mvr2r(synth, st->previoussynth, output_frame); Copy32(synth_fx, st->previoussynth_fx_32, output_frame); //Q0 } @@ -2821,7 +2460,8 @@ ivas_error acelp_core_dec_ivas_fx( Word16 tmp_exp = 0; //Word16 output_subfr = output_frame / NB_SUBFR; - Copy_Scale_sig_32_16(synth_fx, synth_fx16, 0, L_FRAME48k); + Copy_Scale_sig_32_16(synth_fx, synth_fx16, L_FRAME48k, 0); + hf_synth_ivas_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2, st->hBWE_zero->delay_syn_hf_fx, &tmp_exp, st->hBWE_zero->mem_hp_interp_fx, st->extl, st->CNG_mode, st->element_mode ); @@ -2967,60 +2607,10 @@ ivas_error acelp_core_dec_ivas_fx( } void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hStereoCng) { - Word16 i; - st->coder_type = st->coder_type; - st->last_coder_type = st->last_coder_type; - st->last_core_from_bs = st->last_core_from_bs; - //floatToFixed_arr(st->lsp_old, st->lsp_old_fx, Q15, M); - st->lp_ener_fx = floatToFixed(st->lp_ener, Q6); - for (i = 0; i < M; i++) { - st->mem_MA_fx[i] = (Word16)(st->mem_MA[i] * 2.56f); - st->mem_AR_fx[i] = (Word16)(st->mem_AR[i] * 2.56f); - } - floatToFixed_arrL(st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2); if (hStereoCng) { floatToFixed_arr(hStereoCng->olapBufferSynth22, hStereoCng->olapBufferSynth22_fx, st->Q_syn, FFTLEN); } - /* st->mem_deemph_fx will need to be handled with proper Q */ - st->mem_deemph_fx = (Word16)floatToFixed((Word16)check_bounds_l((Word32)st->mem_deemph, -32768, 32767), st->Q_syn); - //floatToFixed_arr(st->agc_mem2, st->agc_mem_fx, st->prev_Q_syn - 1, 2); - floatToFixed_arr(st->Aq_cng_float, st->Aq_cng, Q12, M + 1); - - /*Flags (should be unified!)*/ - st->last_nq_preQ = st->last_nq_preQ; - st->safety_net = st->safety_net; - st->nelp_mode_dec = st->nelp_mode_dec; - st->ppp_mode_dec = st->ppp_mode_dec; - st->relax_prev_lsf_interp = st->relax_prev_lsf_interp; - st->unv_cnt = st->unv_cnt; - st->uv_count = st->uv_count; - st->act_count = st->act_count; - st->GSC_noisy_speech = st->GSC_noisy_speech; - st->Last_GSC_noisy_speech_flag = st->Last_GSC_noisy_speech_flag; - st->mid_lsf_int = st->mid_lsf_int; - st->last_vbr_hw_BWE_disable_dec = st->last_vbr_hw_BWE_disable_dec; - st->vbr_hw_BWE_disable_dec = st->vbr_hw_BWE_disable_dec; - - /* dec_exc */ - st->lp_gainc_fx = float_to_fix16(st->lp_gainc, Q3); - st->dm_fx.prev_state = float_to_fix16(st->dispMem[0], 0); - st->dm_fx.prev_gain_code = floatToFixed(st->dispMem[1], Q16); - floatToFixed_arr(&(st->dispMem[2]), st->dm_fx.prev_gain_pit, Q14, 6); - st->prev_gain_pit_dec_fx = float_to_fix16(st->prev_gain_pit_dec, Q14); - st->prev_tilt_code_dec_fx = float_to_fix16(st->prev_tilt_code_dec, Q15); - st->lp_gainp_fx = float_to_fix16(st->lp_gainp, Q14); - st->past_gpit = float_to_fix16(st->past_gpit_float, Q14); - - /* Bad frame */ - - st->ge_sm_fx = (Word16)floatToFixed(st->ge_sm, st->Q_stat_noise_ge); - - - /* After dec_exc */ - st->enr_old_fx = floatToFixed(st->enr_old, 0); - st->exc_pe_fx = (Word16)floatToFixed(st->exc_pe, st->Q_stat_noise); - floatToFixed_arr(st->syn_float, st->syn, 0, M + 1); /* CLDFB */ Word16 old_len_ana, old_len_bpf; @@ -3038,51 +2628,22 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte floatToFixed_arrL(st->cldfbSynHB->cldfb_state, st->cldfbSynHB->cldfb_state_fx, Q10, st->cldfbSynHB->p_filter_length); floatToFixed_arrL(st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_fx, Q10, st->cldfbSyn->p_filter_length); - //Word16 offset = sub(st->cldfbAna->p_filter_length, st->cldfbAna->no_channels); - - floatToFixed_arrL(st->previoussynth, st->previoussynth_fx_32, 0, L_FRAME48k); - - //hBPF - if (st->hBPF) { - floatToFixed_arr(st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, st->Q_syn2 - 1, NBPSF_PIT_MAX); - st->hBPF->pst_mem_deemp_err_fx = (Word16)floatToFixed(st->hBPF->pst_mem_deemp_err, st->Q_syn2 - 1); - floatToFixed_arr(st->hBPF->mem_mean_pit, st->hBPF->mem_mean_pit_fx, Q4, L_TRACK_HIST); - st->hBPF->psf_att_fx = float_to_fix16(st->hBPF->psf_att, Q15); - } - - /*ZERO_BWE_DEC_HANDLE*/ - if (st->hBWE_zero) { - floatToFixed_arr(st->hBWE_zero->mem_hp400, st->hBWE_zero->mem_hp400_fx, 0, 4); - if (st->hBWE_FD) { - floatToFixed_arr(st->hBWE_zero->mem_hf, st->hBWE_zero->mem_hf_fx, -2 - st->hBWE_FD->memExp1, L_FIR - 1); - } - else { - floatToFixed_arr(st->hBWE_zero->mem_hf, st->hBWE_zero->mem_hf_fx, -2, L_FIR - 1); - } - floatToFixed_arr(st->hBWE_zero->mem_syn_hf, st->hBWE_zero->mem_syn_hf_fx, 0, M); - floatToFixed_arr(st->hBWE_zero->delay_syn_hf, st->hBWE_zero->delay_syn_hf_fx, 0, NS2SA(16000, DELAY_CLDFB_NS)); - floatToFixed_arr(st->hBWE_zero->mem_hp_interp, st->hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN); - } - //FdCng if ( st->hFdCngDec ) { - floatToFixed_arrL( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt, st->hFdCngDec->hFdCngCom->sidNoiseEst, Q31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp, NPART ); + //floatToFixed_arrL( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt, st->hFdCngDec->hFdCngCom->sidNoiseEst, Q31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp, NPART ); floatToFixed_arrL( st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt, st->hFdCngDec->hFdCngCom->sidNoiseEstLp, Q31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp, NPART ); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = Q31 - 4; floatToFixed_arrL(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt, st->hFdCngDec->hFdCngCom->cngNoiseLevel, Q31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, FFTCLDFBLEN); floatToFixed_arr(st->hFdCngDec->hFdCngCom->A_cng_flt, st->hFdCngDec->hFdCngCom->A_cng, Q12, M + 1); st->hFdCngDec->hFdCngCom->A_cng[0] = 4096; floatToFixed_arr(st->hFdCngDec->hFdCngCom->exc_cng_flt, st->hFdCngDec->hFdCngCom->exc_cng, st->Q_exc_cng, L_FRAME16k); - //floatToFixed_arrL(st->hFdCngDec->hFdCngCom->fftBuffer_flt, st->hFdCngDec->hFdCngCom->fftBuffer, st->Q_syn, FFTLEN); - floatToFixed_arr(st->hFdCngDec->hFdCngCom->timeDomainBuffer_flt, st->hFdCngDec->hFdCngCom->timeDomainBuffer, st->Q_syn_cng, L_FRAME16k); - floatToFixed_arr(st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->fftlenShift, FFTLEN); + floatToFixed_arr(st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->fftlenShift, FFTLEN); st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = float_to_fix16(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt, Q15); floatToFixed_arrL( st->hFdCngDec->bandNoiseShape_float, st->hFdCngDec->bandNoiseShape, Q31 - st->hFdCngDec->bandNoiseShape_exp, FFTLEN2); - st->hFdCngDec->partNoiseShape_exp = 31 - Q4; - floatToFixed_arrL( st->hFdCngDec->partNoiseShape_float, st->hFdCngDec->partNoiseShape, Q31 - st->hFdCngDec->partNoiseShape_exp, NPART); - + //st->hFdCngDec->partNoiseShape_exp = 31 - Q4; + //floatToFixed_arrL(st->hFdCngDec->partNoiseShape_float, st->hFdCngDec->partNoiseShape, Q31 - st->hFdCngDec->partNoiseShape_exp, NPART); /*CNA: ApplyFdCng*/ if ((st->hFdCngDec != NULL || st->idchan == 1) && st->element_mode != IVAS_CPE_MDCT) { @@ -3091,48 +2652,18 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte if (st->element_mode != IVAS_CPE_TD && !st->cng_ism_flag) { st->hFdCngDec->hFdCngCom->fftBuffer_exp = st->hFdCngDec->msNoiseEst_exp = Q31 - Q4; //st->hFdCngDec->hFdCngCom->periodog_exp = st->hFdCngDec->msPsd_exp_fft = st->hFdCngDec->msPeriodog_exp = st->hFdCngDec->msPeriodog_ST_exp = 31 - Q4; Q4 - floatToFixed_arrL(st->hFdCngDec->hFdCngCom->periodog_flt, st->hFdCngDec->hFdCngCom->periodog, Q31 - st->hFdCngDec->hFdCngCom->periodog_exp, PERIODOGLEN); - floatToFixed_arrL(st->hFdCngDec->hFdCngCom->fftBuffer_flt, st->hFdCngDec->hFdCngCom->fftBuffer, Q31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp, st->hFdCngDec->hFdCngCom->fftlen); - floatToFixed_arrL(st->hFdCngDec->msPsd_float, st->hFdCngDec->msPsd_fx, Q31 - st->hFdCngDec->msPsd_exp_fft, NPART_SHAPING); + floatToFixed_arrL(st->hFdCngDec->hFdCngCom->fftBuffer_flt, st->hFdCngDec->hFdCngCom->fftBuffer, Q31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp, st->hFdCngDec->hFdCngCom->fftlen); floatToFixed_arrL(st->hFdCngDec->msNoiseEst_float, st->hFdCngDec->msNoiseEst, Q31 - st->hFdCngDec->msNoiseEst_exp, st->hFdCngDec->npart_shaping); - floatToFixed_arrL(st->hFdCngDec->msPeriodog_float, st->hFdCngDec->msPeriodog, Q31 - st->hFdCngDec->msPeriodog_exp, st->hFdCngDec->npart_shaping); - floatToFixed_arrL(st->hFdCngDec->msPeriodog_ST, st->hFdCngDec->msPeriodog_ST_fx, Q31 - st->hFdCngDec->msPeriodog_ST_exp, st->hFdCngDec->npart_shaping); + if (st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT) { floatToFixed_arrL(st->hFdCngDec->smoothed_psd, st->hFdCngDec->smoothed_psd_fx, Q31 - st->hFdCngDec->msNoiseEst_exp, L_FRAME16k - st->hFdCngDec->hFdCngCom->startBand); } - //st->hTcxDec->CngLevelBackgroundTrace_bfi_fx = floatToFixed(st->hTcxDec->CngLevelBackgroundTrace_bfi, (31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp)); - //st->cngTDLevel = float_to_fix16(st->cngTDLevel_float, (15 - st->cngTDLevel_e)); - //floatToFixed_arrL(st->hFdCngDec->msMinBuf_float, st->hFdCngDec->msMinBuf, Q31 - Q6, MSNUMSUBFR * NPART_SHAPING); // CNG_S = 6 - //floatToFixed_arr(st->hFdCngDec->msPeriodogBuf_float, st->hFdCngDec->msPeriodogBuf, Q9, NPART_SHAPING); - //floatToFixed_arr(st->hFdCngDec->msPsdFirstMoment_float, st->hFdCngDec->msPsdFirstMoment, Q9, NPART_SHAPING); - //floatToFixed_arrL(st->hFdCngDec->msPsdSecondMoment_float, st->hFdCngDec->msPsdSecondMoment, Q19, NPART_SHAPING); - //floatToFixed_arr(st->hFdCngDec->msNoiseFloor_float, st->hFdCngDec->msNoiseFloor, Q9, NPART_SHAPING); - //floatToFixed_arrL(st->hFdCngDec->msAlpha_float, st->hFdCngDec->msAlpha, Q31, NPART_SHAPING); - //floatToFixed_arrL(st->hFdCngDec->msBminWin_float, st->hFdCngDec->msBminWin, Q27, NPART_SHAPING); - //floatToFixed_arrL(st->hFdCngDec->msBminSubWin_float, st->hFdCngDec->msBminSubWin, Q27, NPART_SHAPING); - //floatToFixed_arrL(st->hFdCngDec->msCurrentMin_float, st->hFdCngDec->msCurrentMin, Q31 - (Q6 + Q1 + Q4), NPART_SHAPING);// exp : CNG_S + 1 + 4 - //floatToFixed_arrL(st->hFdCngDec->msCurrentMinOut_float, st->hFdCngDec->msCurrentMinOut, Q31 - Q6, NPART_SHAPING); - //floatToFixed_arrL(st->hFdCngDec->msCurrentMinSubWindow_float, st->hFdCngDec->msCurrentMinSubWindow, Q31 - Q6, NPART_SHAPING);// exp : CNG_S + 1 + 4 } } } } - //TdCng - if (st->hTdCngDec) - { - st->hTdCngDec->ho_hist_size = st->hTdCngDec->ho_hist_size; - st->hTdCngDec->act_cnt2 = st->hTdCngDec->act_cnt2; - st->hTdCngDec->act_cnt = st->hTdCngDec->act_cnt; - } - - /*WI_DEC_HANDLE*/ - if (st->hWIDec) { - floatToFixed_arr(st->hWIDec->old_exc2, st->hWIDec->old_exc2_fx, st->prev_Q_exc_fr, L_EXC_MEM); - floatToFixed_arr(st->hWIDec->old_syn2, st->hWIDec->old_syn2_fx, st->prev_Q_syn_fr, L_EXC_MEM); - } - /*TD_BWE_DEC_HANDLE*/ if (st->hBWE_TD) { floatToFixed_arr(st->hBWE_TD->old_bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET); @@ -3143,82 +2674,15 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte floatToFixed_arr(st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_Overl, 0, L_FRAME32k / 2); floatToFixed_arr(st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, -1, st->L_frame / 2); } - - /*MUSIC_POSTFILT_HANDLE*/ - if (st->hMusicPF) { - //floatToFixed_arr(st->hMusicPF->dct_post_old_exc, st->hMusicPF->dct_post_old_exc_fx, st->Q_exc, DCT_L_POST - OFFSET2); - floatToFixed_arr(st->hMusicPF->filt_lfE, st->hMusicPF->filt_lfE_fx, Q15, DCT_L_POST); - //floatToFixed_arr(st->hMusicPF->LDm_enh_lp_gbin, st->hMusicPF->LDm_enh_lp_gbin_fx, Q14, VOIC_BINS_HR); - //st->hMusicPF->LDm_enh_min_ns_gain_fx = float_to_fix16(st->hMusicPF->LDm_enh_min_ns_gain, Q15); - //floatToFixed_arrL(st->hMusicPF->LDm_enh_lf_EO, st->hMusicPF->LDm_enh_lf_EO_fx, Q10, VOIC_BINS_HR); - //floatToFixed_arr(st->hMusicPF->LDm_lt_diff_etot, st->hMusicPF->LDm_lt_diff_etot_fx, Q15, MAX_LT); - //st->hMusicPF->LDm_mem_etot_fx = float_to_fix16(st->hMusicPF->LDm_mem_etot, Q8); - //floatToFixed_arr(st->hMusicPF->LDm_thres, st->hMusicPF->LDm_thres_fx, Q12, 4); - //floatToFixed_arrL(st->hMusicPF->LDm_bckr_noise, st->hMusicPF->LDm_bckr_noise_fx, Q10, MBANDS_GN_LD); - } - - /*FD_BWE_DEC_HANDLE*/ - if (st->hBWE_FD) { - floatToFixed_arr(st->hBWE_FD->old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, -1, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); - st->hBWE_FD->mem_deemph_old_syn_fx = extract_l( floatToFixed( st->hBWE_FD->mem_deemph_old_syn, -1 ) ); - } - } void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hStereoCng) { - Word16 i; - st->last_core_from_bs = st->last_core_from_bs; st->prev_Q_syn = st->Q_syn; - //fixedToFloat_arr(st->lsp_old_fx, st->lsp_old, Q15, M); - st->lp_ener = fixedToFloat(st->lp_ener_fx, Q6); - for (i = 0; i < M; i++) { - st->mem_MA[i] = st->mem_MA_fx[i] / 2.56f; - st->mem_AR[i] = st->mem_AR_fx[i] / 2.56f; - } - fixedToFloat_arrL(st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2); if (hStereoCng) { fixedToFloat_arr(hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22, st->Q_syn, FFTLEN); } - st->mem_deemph = fixedToFloat(st->mem_deemph_fx, st->Q_syn); - fixedToFloat_arr(st->Aq_cng, st->Aq_cng_float, Q14 - norm_s(st->Aq_cng[0]), M + 1); - - /*Flags (should be unified!)*/ - st->last_nq_preQ = st->last_nq_preQ; - st->safety_net = st->safety_net; - st->nelp_mode_dec = st->nelp_mode_dec; - st->ppp_mode_dec = st->ppp_mode_dec; - st->relax_prev_lsf_interp = st->relax_prev_lsf_interp; - st->unv_cnt = st->unv_cnt; - st->uv_count = st->uv_count; - st->act_count = st->act_count; - st->GSC_noisy_speech = st->GSC_noisy_speech; - st->Last_GSC_noisy_speech_flag = st->Last_GSC_noisy_speech_flag; - st->mid_lsf_int = st->mid_lsf_int; - st->last_vbr_hw_BWE_disable_dec = st->last_vbr_hw_BWE_disable_dec; - st->vbr_hw_BWE_disable_dec = st->vbr_hw_BWE_disable_dec; - - /* dec_exc */ - st->lp_gainc = fixedToFloat(st->lp_gainc_fx, Q3); - st->dispMem[0] = fixedToFloat(st->dm_fx.prev_state, 0); - st->dispMem[1] = fixedToFloat(st->dm_fx.prev_gain_code, Q16); - fixedToFloat_arr(st->dm_fx.prev_gain_pit, &(st->dispMem[2]), Q14, 6); - - st->prev_gain_pit_dec = fixedToFloat(st->prev_gain_pit_dec_fx, Q14); - st->prev_tilt_code_dec = fixedToFloat(st->prev_tilt_code_dec_fx, Q15); - st->lp_gainp = fixedToFloat(st->lp_gainp_fx, Q14); - st->lp_gainc = fixedToFloat(st->lp_gainc_fx, Q3); - st->past_gpit_float = fixedToFloat(st->past_gpit, Q14); - - /* Bad frame */ - st->ge_sm = fixedToFloat(st->ge_sm_fx, st->Q_stat_noise_ge); - st->exc_pe = fixedToFloat(st->exc_pe_fx, st->Q_stat_noise); - - - /* After dec_exc */ - st->enr_old = fixedToFloat(st->enr_old_fx, 0); - fixedToFloat_arr(st->syn, st->syn_float, 0, M + 1); /* CLDFB */ Word16 new_len; @@ -3229,52 +2693,21 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte fixedToFloat_arrL(st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_state, Q10, st->cldfbSynHB->p_filter_length); fixedToFloat_arrL(st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_state, Q10, st->cldfbSyn->p_filter_length); - //Word16 offset = sub(st->cldfbAna->p_filter_length, st->cldfbAna->no_channels); - IF(st->p_bpf_noise_buf_32) { fixedToFloat_arrL(st->p_bpf_noise_buf_32, st->p_bpf_noise_buf_float, st->Q_syn-1, st->L_frame); } - fixedToFloat_arrL(st->previoussynth_fx_32, st->previoussynth, 0, L_FRAME48k); - - //hBPF - if (st->hBPF) { - fixedToFloat_arr(st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, st->Q_syn2 - 1, NBPSF_PIT_MAX); - st->hBPF->pst_mem_deemp_err = fixedToFloat(st->hBPF->pst_mem_deemp_err_fx, st->Q_syn2 - 1); - fixedToFloat_arr(st->hBPF->mem_mean_pit_fx, st->hBPF->mem_mean_pit, Q4, L_TRACK_HIST); - st->hBPF->psf_att = fixedToFloat(st->hBPF->psf_att_fx, Q15); - } - - /*ZERO_BWE_DEC_HANDLE*/ - if (st->hBWE_zero) { - fixedToFloat_arr(st->hBWE_zero->mem_hp400_fx, st->hBWE_zero->mem_hp400, 0, 4); - if (st->hBWE_FD) { - fixedToFloat_arr(st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, -2 - st->hBWE_FD->memExp1, L_FIR - 1); - } - else { - fixedToFloat_arr(st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, -2, L_FIR - 1); - } - fixedToFloat_arr(st->hBWE_zero->mem_syn_hf_fx, st->hBWE_zero->mem_syn_hf, 0, M); - fixedToFloat_arr(st->hBWE_zero->delay_syn_hf_fx, st->hBWE_zero->delay_syn_hf, 0, NS2SA(16000, DELAY_CLDFB_NS)); - fixedToFloat_arr(st->hBWE_zero->mem_hp_interp_fx, st->hBWE_zero->mem_hp_interp, 0, INTERP_3_1_MEM_LEN); - } - //FdCng if ( st->hFdCngDec ) { - fixedToFloat_arrL( st->hFdCngDec->hFdCngCom->sidNoiseEst, st->hFdCngDec->hFdCngCom->sidNoiseEst_flt, Q31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp, NPART ); fixedToFloat_arrL(st->hFdCngDec->hFdCngCom->sidNoiseEstLp, st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt, Q31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp, NPART); fixedToFloat_arrL( st->hFdCngDec->hFdCngCom->cngNoiseLevel, st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt, Q31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, FFTCLDFBLEN ); fixedToFloat_arr( st->hFdCngDec->hFdCngCom->A_cng, st->hFdCngDec->hFdCngCom->A_cng_flt, Q12, M + 1 ); fixedToFloat_arr(st->hFdCngDec->hFdCngCom->exc_cng, st->hFdCngDec->hFdCngCom->exc_cng_flt, st->Q_exc_cng, L_FRAME16k); - //fixedToFloat_arrL(st->hFdCngDec->hFdCngCom->fftBuffer, st->hFdCngDec->hFdCngCom->fftBuffer_flt, st->Q_exc, FFTLEN); - fixedToFloat_arr(st->hFdCngDec->hFdCngCom->timeDomainBuffer, st->hFdCngDec->hFdCngCom->timeDomainBuffer_flt, 0, L_FRAME16k); - fixedToFloat_arr(st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->hFdCngDec->hFdCngCom->fftlenShift, FFTLEN); - fixedToFloat_arr(st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->hFdCngDec->hFdCngCom->fftlenShift, FFTLEN); + fixedToFloat_arr(st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->hFdCngDec->hFdCngCom->fftlenShift, FFTLEN); st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt = fixedToFloat(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, Q15); fixedToFloat_arrL(st->hFdCngDec->bandNoiseShape, st->hFdCngDec->bandNoiseShape_float, Q31 - st->hFdCngDec->bandNoiseShape_exp, FFTLEN2); - fixedToFloat_arrL(st->hFdCngDec->partNoiseShape, st->hFdCngDec->partNoiseShape_float, Q31 - st->hFdCngDec->partNoiseShape_exp, NPART); - + //fixedToFloat_arrL(st->hFdCngDec->partNoiseShape, st->hFdCngDec->partNoiseShape_float, Q31 - st->hFdCngDec->partNoiseShape_exp, NPART); /*CNA: ApplyFdCng*/ if ((st->hFdCngDec != NULL || st->idchan == 1) && st->element_mode != IVAS_CPE_MDCT) { @@ -3292,12 +2725,12 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte (st->m_frame_type == ZERO_FRAME) && (st != NULL && st->cng_type == LP_CNG) ) { - fixedToFloat_arrL(st->hFdCngDec->hFdCngCom->periodog, st->hFdCngDec->hFdCngCom->periodog_flt, Q31 - st->hFdCngDec->hFdCngCom->periodog_exp, PERIODOGLEN); + //fixedToFloat_arrL(st->hFdCngDec->hFdCngCom->periodog, st->hFdCngDec->hFdCngCom->periodog_flt, Q31 - st->hFdCngDec->hFdCngCom->periodog_exp, PERIODOGLEN); fixedToFloat_arrL(st->hFdCngDec->hFdCngCom->fftBuffer, st->hFdCngDec->hFdCngCom->fftBuffer_flt, Q31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp, st->hFdCngDec->hFdCngCom->fftlen); - fixedToFloat_arrL(st->hFdCngDec->msPsd_fx, st->hFdCngDec->msPsd_float, Q31 - st->hFdCngDec->msPsd_exp_fft, st->hFdCngDec->npart_shaping); fixedToFloat_arrL(st->hFdCngDec->msNoiseEst, st->hFdCngDec->msNoiseEst_float, Q31 - st->hFdCngDec->msNoiseEst_exp, st->hFdCngDec->npart_shaping); - fixedToFloat_arrL(st->hFdCngDec->msPeriodog, st->hFdCngDec->msPeriodog_float, Q31 - st->hFdCngDec->msPeriodog_exp, st->hFdCngDec->npart_shaping); - fixedToFloat_arrL(st->hFdCngDec->msPeriodog_ST_fx, st->hFdCngDec->msPeriodog_ST, Q31 - st->hFdCngDec->msPeriodog_ST_exp, st->hFdCngDec->npart_shaping); + // fixedToFloat_arrL(st->hFdCngDec->msPeriodog, st->hFdCngDec->msPeriodog_float, Q31 - st->hFdCngDec->msPeriodog_exp, st->hFdCngDec->npart_shaping); + //fixedToFloat_arrL(st->hFdCngDec->msPeriodog_ST_fx, st->hFdCngDec->msPeriodog_ST, Q31 - st->hFdCngDec->msPeriodog_ST_exp, st->hFdCngDec->npart_shaping); + if (st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT) { fixedToFloat_arrL(st->hFdCngDec->smoothed_psd_fx, st->hFdCngDec->smoothed_psd, Q31 - st->hFdCngDec->msNoiseEst_exp, L_FRAME16k - st->hFdCngDec->hFdCngCom->startBand); @@ -3305,55 +2738,6 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte if (!((st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT) && (st->hFdCngDec->hFdCngCom->active_frame_counter > 0))) { st->hTcxDec->CngLevelBackgroundTrace_bfi = fixedToFloat(st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, (31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp)); - st->cngTDLevel_float = fixedToFloat(st->cngTDLevel, (15 - st->cngTDLevel_e)); - IF(!(EQ_16(st->element_mode, IVAS_CPE_TD) || EQ_16(st->element_mode, IVAS_CPE_DFT))) - { - for (int p = 0; p < MSNUMSUBFR * NPART_SHAPING; p++) - { - if ((st->hFdCngDec->msMinBuf[p] == MAX_32)) - { - st->hFdCngDec->msMinBuf_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msMinBuf_float[p] = (float)st->hFdCngDec->msMinBuf[p] / (1u << (31 - 6)); // CNG_S = 6 - } - } - fixedToFloat_arr(st->hFdCngDec->msPeriodogBuf, st->hFdCngDec->msPeriodogBuf_float, Q9, st->hFdCngDec->npart_shaping); - fixedToFloat_arr(st->hFdCngDec->msPsdFirstMoment, st->hFdCngDec->msPsdFirstMoment_float, Q9, st->hFdCngDec->npart_shaping); - fixedToFloat_arrL(st->hFdCngDec->msPsdSecondMoment, st->hFdCngDec->msPsdSecondMoment_float, Q19, st->hFdCngDec->npart_shaping); - fixedToFloat_arr(st->hFdCngDec->msNoiseFloor, st->hFdCngDec->msNoiseFloor_float, Q9, st->hFdCngDec->npart_shaping); - fixedToFloat_arrL(st->hFdCngDec->msAlpha, st->hFdCngDec->msAlpha_float, Q31, st->hFdCngDec->npart_shaping); - fixedToFloat_arrL(st->hFdCngDec->msBminWin, st->hFdCngDec->msBminWin_float, Q27, st->hFdCngDec->npart_shaping); - fixedToFloat_arrL(st->hFdCngDec->msBminSubWin, st->hFdCngDec->msBminSubWin_float, Q27, st->hFdCngDec->npart_shaping); - for (int p = 0; p < st->hFdCngDec->npart_shaping; p++) - { - if (st->hFdCngDec->msCurrentMin[p] == MAX_32) - { - st->hFdCngDec->msCurrentMin_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMin_float[p] = ((float)st->hFdCngDec->msCurrentMin[p] / (1u << (31 - (6 + 1 + 4)))); // exp : CNG_S + 1 + 4 - } - if (st->hFdCngDec->msCurrentMinOut[p] == MAX_32) - { - st->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinOut_float[p] = ((float)st->hFdCngDec->msCurrentMinOut[p] / (1u << (31 - 6))); - } - if (st->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32) - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = ((float)st->hFdCngDec->msCurrentMinSubWindow[p] / (1u << (31 - 6))); - } - } - } } } } @@ -3361,20 +2745,6 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte } } - //TdCng - if (st->hTdCngDec) - { - st->hTdCngDec->ho_hist_size = st->hTdCngDec->ho_hist_size; - st->hTdCngDec->act_cnt2 = st->hTdCngDec->act_cnt2; - st->hTdCngDec->act_cnt = st->hTdCngDec->act_cnt; - } - - /*WI_DEC_HANDLE*/ - if (st->hWIDec) { - fixedToFloat_arr(st->hWIDec->old_exc2_fx, st->hWIDec->old_exc2, st->prev_Q_exc_fr, L_EXC_MEM); - fixedToFloat_arr(st->hWIDec->old_syn2_fx, st->hWIDec->old_syn2, st->prev_Q_syn_fr, L_EXC_MEM); - } - /*TD_BWE_DEC_HANDLE*/ if (st->hBWE_TD) { fixedToFloat_arr(st->hBWE_TD->old_bwe_exc_extended_fx, st->hBWE_TD->old_bwe_exc_extended, 0, NL_BUFF_OFFSET); @@ -3385,25 +2755,6 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte fixedToFloat_arr(st->hTcxDec->syn_Overl, st->hTcxDec->syn_Overl_float, 0, L_FRAME32k / 2); fixedToFloat_arr(st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl_float, -1, st->L_frame / 2); } - - /*MUSIC_POSTFILT_HANDLE*/ - if (st->hMusicPF) { - //fixedToFloat_arr(st->hMusicPF->dct_post_old_exc_fx, st->hMusicPF->dct_post_old_exc, st->Q_exc, DCT_L_POST - OFFSET2); - fixedToFloat_arr(st->hMusicPF->filt_lfE_fx, st->hMusicPF->filt_lfE, Q15, DCT_L_POST); - //fixedToFloat_arr(st->hMusicPF->LDm_enh_lp_gbin_fx, st->hMusicPF->LDm_enh_lp_gbin, Q14, VOIC_BINS_HR); - //st->hMusicPF->LDm_enh_min_ns_gain = fixedToFloat(st->hMusicPF->LDm_enh_min_ns_gain_fx, Q15); - //fixedToFloat_arrL(st->hMusicPF->LDm_enh_lf_EO_fx, st->hMusicPF->LDm_enh_lf_EO, Q10, VOIC_BINS_HR); - //fixedToFloat_arr(st->hMusicPF->LDm_lt_diff_etot_fx, st->hMusicPF->LDm_lt_diff_etot, Q15, MAX_LT); - //st->hMusicPF->LDm_mem_etot = fixedToFloat(st->hMusicPF->LDm_mem_etot_fx, Q8); - //fixedToFloat_arr(st->hMusicPF->LDm_thres_fx, st->hMusicPF->LDm_thres, Q12, 4); - //fixedToFloat_arrL(st->hMusicPF->LDm_bckr_noise_fx, st->hMusicPF->LDm_bckr_noise, Q10, MBANDS_GN_LD); - } - - /*FD_BWE_DEC_HANDLE*/ - if (st->hBWE_FD) { - fixedToFloat_arr(st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, -1, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); - st->hBWE_FD->mem_deemph_old_syn = fixedToFloat(st->hBWE_FD->mem_deemph_old_syn_fx, -1); - } } static void rescale_fdCngDec(HANDLE_FD_CNG_DEC hFdCngDec, Word16 Exp_diff) { diff --git a/lib_dec/acelp_core_switch_dec.c b/lib_dec/acelp_core_switch_dec.c index de7719a779a976b596a3091728f5f10ce34c54b2..5161773da54e7883ff11e26e2564f6af24270b86 100644 --- a/lib_dec/acelp_core_switch_dec.c +++ b/lib_dec/acelp_core_switch_dec.c @@ -53,7 +53,7 @@ static void decod_gen_voic_core_switch( Decoder_State *st, const int16_t L_frame * * ACELP core decoder in the first ACELP->HQ switching frame *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) ivas_error acelp_core_switch_dec( Decoder_State *st, /* i/o: decoder state structure */ float *synth_subfr_out, /* o : synthesized ACELP subframe */ @@ -634,3 +634,4 @@ static void decod_gen_voic_core_switch( return; } +#endif diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index 234a7b78eb6d03c56f672d792af54c9fd794591f..f30644cc0b8980655da508bbc617b06e4d10105f 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -621,8 +621,8 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( Word32 *realBuffer[CLDFB_NO_COL_MAX_SWITCH_BFI], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH_BFI]; Word32 realBufferTmp[CLDFB_NO_COL_MAX_SWITCH_BFI][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH_BFI][CLDFB_NO_CHANNELS_MAX]; Word16 i; - CLDFB_SCALE_FACTOR scaleFactor; - Word32 workBuffer[128*3]; + //CLDFB_SCALE_FACTOR scaleFactor; + //Word32 workBuffer[128*3]; Word32 synth32[L_FRAME48k]; MUSIC_POSTFILT_HANDLE hMusicPF; BPF_DEC_HANDLE hBPF; @@ -833,7 +833,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( Copy_Scale_sig_32_16(synth32, synth_out, L_FRAME48k, -5); /* output to Q0 */ - Copy_Scale_sig32_16(syn32, synth_out, L_FRAME48k, -5); + Copy_Scale_sig32_16(syn32, synth_out, L_FRAME16k, -5); //Scale_sig(synth_out,L_FRAME48k, negate(st_fx->Q_syn)); cldfb_restore_memory_ivas_fx( st_fx->cldfbSyn ); diff --git a/lib_dec/ari_hm_dec.c b/lib_dec/ari_hm_dec.c index 6333e76fd2dfe2507538ebbcc3fa286f3176826a..ebb57567bdce79b4bb97f1e17dba5825bd376e4a 100644 --- a/lib_dec/ari_hm_dec.c +++ b/lib_dec/ari_hm_dec.c @@ -44,7 +44,7 @@ #include "rom_com.h" #include "wmc_auto.h" #include "prot_fx2.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * DecodeIndex() * @@ -76,7 +76,7 @@ int16_t DecodeIndex( return 8; } } - +#endif Word16 DecodeIndex_fx( Decoder_State *st, diff --git a/lib_dec/arith_coder_dec.c b/lib_dec/arith_coder_dec.c index 5ee7d53a831d768685b1c7c4f0d50b11261a904e..5c16c17cc96df985c994b94f80c7f381137c9cfb 100644 --- a/lib_dec/arith_coder_dec.c +++ b/lib_dec/arith_coder_dec.c @@ -190,7 +190,7 @@ static Word16 tcx_arith_decode_fx( * * *-------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void tcx_arith_decode_envelope_flt( Decoder_State *st, /* i/o: coder state */ float q_spectrum[], /* o : quantised MDCT coefficients */ @@ -289,7 +289,7 @@ void tcx_arith_decode_envelope_flt( return; } - +#endif void tcx_arith_decode_envelope_fx( Decoder_State *st, /* i/o: coder state */ Word32 q_spectrum[], /* o : quantised MDCT coefficients */ diff --git a/lib_dec/bass_psfilter.c b/lib_dec/bass_psfilter.c index ef42f1d8a404ad20c60ea4ecf5df250146ce8a24..cd1be6136a660a43013f1bf022827b8dc2d75a93 100644 --- a/lib_dec/bass_psfilter.c +++ b/lib_dec/bass_psfilter.c @@ -74,7 +74,7 @@ static int16_t Pit_track( const float syn[], int16_t T ); * * Initialisation of postfiltering variables *---------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void bass_psfilter_init( BPF_DEC_HANDLE hBPF /* o : BPF data handle */ ) @@ -91,13 +91,13 @@ void bass_psfilter_init( return; } - +#endif /*---------------------------------------------------------------------* * bass_psfilter() * * Perform low-frequency postfiltering *---------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void bass_psfilter( BPF_DEC_HANDLE hBPF, /* o : BPF data handle */ const int16_t Opt_AMR_WB, /* i : AMR-WB IO flag */ @@ -396,7 +396,7 @@ void bass_psfilter( return; } - +#endif /*---------------------------------------------------------------------* * Pit_track() @@ -727,12 +727,13 @@ Word16 res_bpf_adapt_fx( return res_bpf_flag; } #endif // IVAS_FLOAT_FIXED - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*---------------------------------------------------------------------* * bpf_pitch_coherence() * * Analyse pitch coherence *---------------------------------------------------------------------*/ + void bpf_pitch_coherence( Decoder_State *st, /* i/o: decoder state structure */ const float pitch_buf[] /* i : pitch for every subfr [0,1,2,3] */ @@ -766,7 +767,7 @@ void bpf_pitch_coherence( return; } - +#endif void bpf_pitch_coherence_fx( Decoder_State *st, /* i/o: decoder state structure */ const Word32 pitch_buf[] /* i : pitch for every subfr [0,1,2,3] */ @@ -826,7 +827,7 @@ void bpf_pitch_coherence_fx( IF( LT_32( L_add( pcn1, L_add( pcn2, pcn3 ) ), 10240 ) ) { st->hBPF->psf_att_fx = 13107; /*Q15*/ - st->hBPF->psf_att = 0.4f; + //st->hBPF->psf_att = 0.4f; set16_fx( &st->hBPF->Track_on_hist[L_TRACK_HIST - nb_subfr], 1, nb_subfr ); } } diff --git a/lib_dec/bass_psfilter_fx.c b/lib_dec/bass_psfilter_fx.c index 61171bea7e29a1aceed4738cf0e2652340f346d9..645308b077a849fa6280d8dcebdf514290fc6a47 100644 --- a/lib_dec/bass_psfilter_fx.c +++ b/lib_dec/bass_psfilter_fx.c @@ -41,7 +41,7 @@ void bass_psfilter_init_fx( set16_fx(hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX); set16_fx(hBPF->Track_on_hist, 0, L_TRACK_HIST); set16_fx(hBPF->vibrato_hist, 0, L_TRACK_HIST); - set16_fx(hBPF->mem_mean_pit_fx, 80, L_TRACK_HIST); + set16_fx(hBPF->mem_mean_pit_fx, 1280, L_TRACK_HIST); /* 80 in Q4*/ hBPF->psf_att_fx = 32767; return; diff --git a/lib_dec/cng_dec.c b/lib_dec/cng_dec.c index 52bd5261af6a5e557040aa0088960c306da03056..7548747a85d35d2b60393ce6e8eee7abff13519a 100644 --- a/lib_dec/cng_dec.c +++ b/lib_dec/cng_dec.c @@ -46,7 +46,7 @@ /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) static void shb_CNG_decod( Decoder_State *st, const float *synth, float *shb_synth, const int16_t sid_bw ); @@ -55,7 +55,7 @@ static void shb_CNG_decod( Decoder_State *st, const float *synth, float *shb_syn * * Decoding of CNG parameters *---------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void CNG_dec( Decoder_State *st, /* i/o: State structure */ const int16_t last_element_mode, /* i : last element mode */ @@ -528,8 +528,9 @@ void CNG_dec( return; } +#endif - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*---------------------------------------------------------------------* * swb_CNG_dec() * @@ -757,6 +758,7 @@ static void shb_CNG_decod( return; } +#endif /*-------------------------------------------------------------------* @@ -778,8 +780,10 @@ void td_cng_dec_init_flt( hTdCngDec->cng_ener_seed = RANDOM_INITSEED; hTdCngDec->cng_ener_seed1 = RANDOM_INITSEED; hTdCngDec->old_enr_index = -1; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hTdCngDec->Enew = 0.0f; - mvr2r( st->lsp_old, st->lspCNG, M ); + mvr2r(st->lsp_old, st->lspCNG, M); +#endif hTdCngDec->last_allow_cn_step = 0; hTdCngDec->shb_cng_ener = -6.02f; if ( st->element_mode != EVS_MONO ) @@ -839,3 +843,4 @@ void td_cng_dec_init_flt( return; } +#endif \ No newline at end of file diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index a8019d21e7ce9944527c0b0848471752fb2096a6..54d7121180d2da44a8a163225676ac9c1447138e 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -1143,9 +1143,11 @@ static void shb_CNG_decod_ivas_fx( E_LPC_lsf_lsp_conversion(shb_lspCNG_fx, tmp_lsp, LPC_SHB_ORDER); /*Q14*/ E_LPC_f_lsp_a_conversion(tmp_lsp, shb_lpcCNG_fx, LPC_SHB_ORDER); - Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER+1, sub(norm_s(shb_lpcCNG_fx[0]),2) ); /* Q12 */ + Copy_Scale_sig( shb_lpcCNG_fx, st->hTdCngDec->shb_lpcCNG_fx, LPC_SHB_ORDER+1, sub(norm_s(shb_lpcCNG_fx[0]),-1) ); /* Q15 */ + + Copy_Scale_sig(shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub(norm_s(shb_lpcCNG_fx[0]), 2)); /* Q12 */ - mvs2s(shb_lpcCNG_fx, st->hTdCngDec->shb_lpcCNG_fx, LPC_SHB_ORDER + 1); + //mvs2s(shb_lpcCNG_fx, st->hTdCngDec->shb_lpcCNG_fx, LPC_SHB_ORDER + 1); /* SHB energy estimation */ wb_ener_fx = L_deposit_l(1);/*Q1 */ diff --git a/lib_dec/core_dec_init.c b/lib_dec/core_dec_init.c index b01f2d0581777dfc933897182f7e8829c751f694..d2e00d93a9cc149221761ef7c5899db98ac6e4c3 100644 --- a/lib_dec/core_dec_init.c +++ b/lib_dec/core_dec_init.c @@ -102,7 +102,9 @@ void open_decoder_LPD_flt( st->nb_subfr = NB_SUBFR; } st->bits_frame = (int16_t) ( ( (float) st->L_frame / (float) st->fscale ) * (float) FSCALE_DENOM / 128.0f * (float) total_brate / 100.0f + 0.49f ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) st->TcxBandwidth_float = getTcxBandwidth_flt(bwidth); +#endif st->narrowBand = (bwidth == NB) ? 1 : 0; encoderLookahead = (L_LOOK_12k8 * st->fscale) / FSCALE_DENOM; encoderLookaheadFB = (L_LOOK_12k8 * fscaleFB) / FSCALE_DENOM; @@ -128,6 +130,7 @@ void open_decoder_LPD_flt( st->pit_res_max_past = st->pit_res_max; } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*Preemphasis param*/ if (st->fscale < (16000 * FSCALE_DENOM) / 12800) { @@ -142,18 +145,19 @@ void open_decoder_LPD_flt( st->preemph_fac_float = PREEMPH_FAC_SWB_FLT; /*SWB*/ } - if (st->sr_core == INT_FS_16k) - { - st->gamma_float = GAMMA16k_FLT; - } - else if (st->sr_core > INT_FS_16k && st->element_mode == IVAS_CPE_MDCT) - { - st->gamma_float = GAMMA16k_FLT; - } - else - { - st->gamma_float = GAMMA1_FLT; - } + if (st->sr_core == INT_FS_16k) + { + st->gamma_float = GAMMA16k_FLT; + } + else if (st->sr_core > INT_FS_16k && st->element_mode == IVAS_CPE_MDCT) + { + st->gamma_float = GAMMA16k_FLT; + } + else + { + st->gamma_float = GAMMA1_FLT; + } +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /* LPC quantization */ if (st->sr_core <= INT_FS_16k && st->tcxonly == 0) @@ -176,18 +180,31 @@ void open_decoder_LPD_flt( /* Initialize TBE */ st->prev_coder_type = GENERIC; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if (st->hBWE_TD != NULL) { set_f(st->hBWE_TD->prev_lsf_diff, 0.5f, LPC_SHB_ORDER - 2); st->hBWE_TD->prev_tilt_para = 0.0f; set_zero(st->hBWE_TD->cur_sub_Aq, M + 1); } +#endif +#ifdef IVAS_FLOAT_FIXED + if (st->hBWE_TD != NULL) + { + set16_fx(st->hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2); + st->hBWE_TD->prev_tilt_para_fx = 0; + set16_fx(st->hBWE_TD->cur_sub_Aq_fx, 0, M + 1); + } +#endif if (st->hIGFDec != NULL) { if (!is_init || st->element_mode != IVAS_CPE_MDCT) { - init_tcx_cfg(st->hTcxCfg, total_brate, st->sr_core, st->output_Fs, st->L_frame, st->bwidth, st->hTcxDec->L_frameTCX, st->fscale, encoderLookahead, encoderLookaheadFB, st->preemph_fac_float, st->tcxonly, st->rf_flag, st->igf, st->hIGFDec->infoIGFStopFreq, st->element_mode, st->ini_frame, MCT_flag); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + init_tcx_cfg(st->hTcxCfg, total_brate, st->sr_core, st->output_Fs, st->L_frame, st->bwidth, st->hTcxDec->L_frameTCX, st->fscale, encoderLookahead, encoderLookaheadFB, st->preemph_fac_float, st->tcxonly, st->rf_flag, st->igf, st->hIGFDec->infoIGFStopFreq, st->element_mode, st->ini_frame, MCT_flag); +#endif + } else { @@ -196,10 +213,18 @@ void open_decoder_LPD_flt( } } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if (st->hTECDec != NULL) { resetTecDec(st->hTECDec); } +#endif +#ifdef IVAS_FLOAT_FIXED + if ( st->hTECDec != NULL ) + { + resetTecDec_Fx( st->hTECDec ); + } +#endif if (st->element_mode != IVAS_SCE) { @@ -228,9 +253,11 @@ void open_decoder_LPD_flt( set_zero(st->hTcxDec->synth_history, L_PROT48k + L_FRAME_MAX); } - set_zero(st->syn_float, M + 1); - set_zero(st->mem_syn_r_float, L_SYN_MEM); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + set_zero(st->syn_float, M + 1); + set_zero(st->mem_syn_r_float, L_SYN_MEM); +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ @@ -249,6 +276,7 @@ void open_decoder_LPD_flt( mem_syn_r_size_old = (int16_t)(1.25 * st->last_L_frame / 20.f); mem_syn_r_size_new = (int16_t)(1.25 * st->L_frame / 20.f); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*Reset LPC mem*/ if ((st->L_frame != st->last_L_frame) || (st->last_core == AMR_WB_CORE) || (st->last_core == HQ_CORE)) { @@ -262,13 +290,15 @@ void open_decoder_LPD_flt( mvr2r(GEWB_Ave, st->mem_AR, M); } } - +#endif /*Mode 1/2 switching*/ if (st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO) { - mvr2r(st->lsp_old, st->lspold_uw_float, M); - mvr2r(st->lsf_old, st->lsfold_uw_float, M); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + mvr2r(st->lsp_old, st->lspold_uw_float, M); + mvr2r(st->lsf_old, st->lsfold_uw_float, M); set_zero(st->syn_float, M); +#endif } if (st->last_core == AMR_WB_CORE) { @@ -298,10 +328,12 @@ void open_decoder_LPD_flt( /*Reset of ACELP memories*/ st->rate_switching_reset = 1; - st->tilt_code = TILT_CODE_FLT; - set_zero(st->old_exc, L_EXC_MEM_DEC); - set_zero(st->syn_float, 1 + M); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + st->tilt_code = TILT_CODE_FLT; + set_zero(st->old_exc, L_EXC_MEM_DEC); set_zero(st->mem_syn2, M); + set_zero(st->syn_float, 1 + M); +#endif /*OLA -> zero */ if (st->hTcxDec != NULL) @@ -344,18 +376,20 @@ void open_decoder_LPD_flt( /*Interpolation of ACELP memories*/ /* convert quantized LSP vector */ - st->rate_switching_reset = lsp_convert_poly(st->lsp_old, st->L_frame, 0); - lsp2a_stab(st->lsp_old, st->old_Aq_12_8, M); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + st->rate_switching_reset = lsp_convert_poly(st->lsp_old, st->L_frame, 0); + lsp2a_stab(st->lsp_old, st->old_Aq_12_8, M); - lsp2lsf(st->lsp_old, st->lsf_old, M, st->sr_core); - mvr2r(st->lsp_old, st->lspold_uw_float, M); - mvr2r(st->lsf_old, st->lsfold_uw_float, M); + lsp2lsf(st->lsp_old, st->lsf_old, M, st->sr_core); + mvr2r(st->lsp_old, st->lspold_uw_float, M); + mvr2r(st->lsf_old, st->lsfold_uw_float, M); - if (!st->last_con_tcx) - { - synth_mem_updt2_flt(st->L_frame, st->last_L_frame, st->old_exc, st->mem_syn_r_float, st->mem_syn2, NULL, DEC); - } + if (!st->last_con_tcx) + { + synth_mem_updt2_flt(st->L_frame, st->last_L_frame, st->old_exc, st->mem_syn_r_float, st->mem_syn2, NULL, DEC); + } +#endif /*mem of deemphasis stayed unchanged.*/ } else if (st->L_frame != st->last_L_frame) /* Rate switching involving TCX only modes */ @@ -364,17 +398,19 @@ void open_decoder_LPD_flt( st->rate_switching_reset = 1; /*reset partly some memories*/ - st->tilt_code = TILT_CODE_FLT; - if (!st->last_con_tcx) - { - set_zero(st->old_exc, L_EXC_MEM_DEC); - } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + st->tilt_code = TILT_CODE_FLT; + if (!st->last_con_tcx) + { + set_zero(st->old_exc, L_EXC_MEM_DEC); + } set_zero(st->old_Aq_12_8, M + 1); /*Resamp others memories*/ /*Size of LPC syn memory*/ lerp_flt(st->mem_syn_r_float + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r_float + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); - mvr2r(st->mem_syn_r_float + L_SYN_MEM - M, st->mem_syn2, M); + mvr2r(st->mem_syn_r_float + L_SYN_MEM - M, st->mem_syn2, M); +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) } /* update of lsf_old only needed in BASOP */ /* else if( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */ @@ -396,16 +432,18 @@ void open_decoder_LPD_flt( /* bass pf reset */ st->bpf_gain_param = 0; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if (st->hBPF != NULL) { set_f(st->hBPF->pst_old_syn, 0, NBPSF_PIT_MAX); } - +#endif /* Formant postfilter */ if (st->ini_frame == 0) { /* do nothing */ } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) else if (st->last_codec_mode == MODE2) { if (!st->tcxonly) @@ -454,51 +492,61 @@ void open_decoder_LPD_flt( { st->hTcxDec->old_synth_float[st->hTcxDec->old_synth_len - 1] = st->syn_float[M]; } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if (st->hBPF != NULL) { st->hBPF->pst_old_syn[NBPSF_PIT_MAX - 1] = st->syn_float[M]; } +#endif } } - +#endif /* lsf and lsp initialization */ - if (st->ini_frame == 0) - { - mvr2r(st->lsp_old, st->lspold_uw_float, M); - mvr2r(st->lsf_old, st->lsfold_uw_float, M); - - set_zero(st->lsf_cng_float, M); - } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + if (st->ini_frame == 0) + { + mvr2r(st->lsp_old, st->lspold_uw_float, M); + mvr2r(st->lsf_old, st->lsfold_uw_float, M); + + set_zero(st->lsf_cng_float, M); + } + st->gc_threshold = 0.0f; +#endif st->seed_tcx_plc = RANDOM_INITSEED; + st->plcBackgroundNoiseUpdated = 0; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) st->past_gpit_float = 0.0f; st->past_gcode_float = 0.0f; - st->gc_threshold = 0.0f; lsf2lsp(st->lsf_cng_float, st->lspold_cng_float, M, INT_FS_12k8); lsp2a_stab(st->lspold_cng_float, st->Aq_cng_float, M); - st->plcBackgroundNoiseUpdated = 0; - mvr2r(st->lsf_old, st->lsf_q_cng_float, M); - mvr2r(st->lsf_old, st->old_lsf_q_cng_float, M); - mvr2r(st->lsp_old, st->lsp_q_cng_float, M); - mvr2r(st->lsp_old, st->old_lsp_q_cng_float, M); + mvr2r(st->lsf_old, st->lsf_q_cng_float, M); + mvr2r(st->lsf_old, st->old_lsf_q_cng_float, M); + mvr2r(st->lsp_old, st->lsp_q_cng_float, M); + mvr2r(st->lsp_old, st->old_lsp_q_cng_float, M); set_zero(st->mem_syn_unv_back_float, M); st->last_gain_syn_deemph_float = 1.f; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if (st->last_codec_mode == MODE1 || st->ini_frame == 0) { /* this assumes that MODE1 fades out in the frequency domain - otherwise some data from MODE1 would be needed here */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) st->last_concealed_gain_syn_deemph_float = 1.f; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if (hTcxDec != NULL) { hTcxDec->conceal_eof_gain_float = 1.0f; } } /* Post processing */ - set_zero(st->mem_Aq_float, NB_SUBFR16k * (M + 1)); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + set_zero(st->mem_Aq_float, NB_SUBFR16k * (M + 1)); - st->lp_ener_bfi = 60.0f; + st->lp_ener_bfi = 60.0f; +#endif if (st->ini_frame == 0) { st->prev_bfi = 0; @@ -514,35 +562,45 @@ void open_decoder_LPD_flt( { st->hTcxDec->noise_filling_index[0] = st->hTcxDec->noise_filling_index[1] = 0; st->hTcxDec->tnsActive[0] = st->hTcxDec->tnsActive[1] = 0; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f(st->hTcxDec->ltpGainMemory, 0.0f, N_LTP_GAIN_MEMS); +#endif } - mvr2r(st->lsf_old, st->lsf_adaptive_mean, M); - mvr2r(st->lsf_old, st->lsfoldbfi0, M); - mvr2r(st->lsf_old, st->lsfoldbfi1, M); - - st->clas_dec = UNVOICED_CLAS; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + mvr2r(st->lsf_old, st->lsf_adaptive_mean, M); + mvr2r(st->lsf_old, st->lsfoldbfi0, M); + mvr2r(st->lsf_old, st->lsfoldbfi1, M); if (!st->last_con_tcx) { st->old_enr_LP_float = 0.0f; /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */ } +#endif + + st->clas_dec = UNVOICED_CLAS; if (st->prev_bfi) { - /* calculate energy at the end of the previous frame */ - if (st->core == ACELP_CORE && st->last_core == HQ_CORE) - { - fer_energy(st->hTcxDec->L_frameTCX, UNVOICED_CLAS, st->previoussynth, -1, &st->enr_old, 1); - } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + /* calculate energy at the end of the previous frame */ + if (st->core == ACELP_CORE && st->last_core == HQ_CORE) + { + fer_energy(st->hTcxDec->L_frameTCX, UNVOICED_CLAS, st->previoussynth, -1, &st->enr_old, 1); + } +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) } else { st->last_good = UNVOICED_CLAS; /* last good received frame for concealment */ - st->enr_old = 0.0f; /* energy at the end of the previous frame */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + st->enr_old = 0.0f; /* energy at the end of the previous frame */ +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) st->lp_gainc = 0.0f; st->lp_gainp = 0.0f; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if (st->hTcxDec != NULL) { @@ -553,35 +611,40 @@ void open_decoder_LPD_flt( st->hTcxDec->CngLevelBackgroundTrace_bfi = PLC_MIN_CNG_LEV_FLT; st->hTcxDec->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE - 1; st->hTcxDec->CurrLevelIndex_bfi = 0; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) st->hTcxDec->LastFrameLevel_bfi = PLC_MIN_CNG_LEV_FLT; set_f(st->hTcxDec->NoiseLevelMemory_bfi, PLC_MIN_CNG_LEV_FLT, PLC_MIN_STAT_BUFF_SIZE); st->hTcxDec->cummulative_damping_tcx_float = 1.0f; +#endif } } - st->cummulative_damping_float = 1.0f; - for (i = 0; i < 2 * NB_SUBFR16k + 2; i++) - { - st->old_pitch_buf[i] = (float)st->pit_min; - } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) for (i = 0; i < 2 * NB_SUBFR16k + 2; i++) { - st->mem_pitch_gain_float[i] = 1.f; + st->old_pitch_buf[i] = (float)st->pit_min; } - + st->cummulative_damping_float = 1.0f; + for (i = 0; i < 2 * NB_SUBFR16k + 2; i++) + { + st->mem_pitch_gain_float[i] = 1.f; + } st->old_fpitch_float = (float)st->pit_min; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + st->rate_switching_init = 1; st->reset_mem_AR = 0; - /* For phase dispersion */ - set_zero(st->dispMem, 8); - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + /* For phase dispersion */ + set_zero(st->dispMem, 8); st->voice_fac_float = -1; /* purely unvoiced */ +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /* TCX-LTP */ if (hTcxLtpDec != NULL) @@ -592,7 +655,9 @@ void open_decoder_LPD_flt( /* TCX */ if (hTcxDec != NULL) { - st->old_fpitchFB_float = (float)hTcxDec->pit_min_TCX; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + st->old_fpitchFB_float = (float)hTcxDec->pit_min_TCX; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if (st->ini_frame == 0 || (st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO)) { @@ -604,12 +669,12 @@ void open_decoder_LPD_flt( hTcxDec->envWeighted = 0; } - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if (st->hBPF != NULL) { st->hBPF->pst_mem_deemp_err = 0.0f; } - +#endif if (st->tcxonly) { st->p_bpf_noise_buf_float = NULL; @@ -676,11 +741,13 @@ void open_decoder_LPD_flt( { st->hTcxCfg->fIsTNSAllowed = getTnsAllowed(is_init ? total_brate : st->bits_frame_nominal * FRAMES_PER_SEC, st->igf, st->element_mode); } - if (hTcxDec != NULL) - { - hTcxDec->tcxltp_second_last_pitch_float = st->old_fpitch_float; - hTcxDec->tcxltp_third_last_pitch_float = st->old_fpitch_float; - } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + if (hTcxDec != NULL) + { + hTcxDec->tcxltp_second_last_pitch_float = st->old_fpitch_float; + hTcxDec->tcxltp_third_last_pitch_float = st->old_fpitch_float; + } +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if ( ( total_brate == ACELP_9k60 || total_brate == ACELP_16k40 || total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO ) { @@ -697,9 +764,9 @@ void open_decoder_LPD_flt( if ( hTcxDec != NULL ) { hTcxDec->enableTcxLpc = 1; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hTcxDec->old_gaintcx_bfi_float = 0.0f; - +#endif hTcxDec->tcx_hm_LtpPitchLag = -1; } @@ -725,8 +792,9 @@ void tcxltp_dec_init( const int16_t pit_max, const int32_t sr_core ) { +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hTcxLtpDec->tcxltp_gain_float = 0.0f; - +#endif hTcxLtpDec->tcxltp = getTcxLtp( sr_core ); if ( ini_frame == 0 || ( last_codec_mode == MODE1 && element_mode == EVS_MONO ) ) @@ -745,7 +813,7 @@ void tcxltp_dec_init( #endif // IVAS_FLOAT_FIXED hTcxLtpDec->tcxltp_pitch_int_post_prev = 0; hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0; - hTcxLtpDec->tcxltp_gain_post_prev_float = 0.f; + //hTcxLtpDec->tcxltp_gain_post_prev_float = 0.f; #ifdef IVAS_FLOAT_FIXED hTcxLtpDec->tcxltp_gain_post_prev = 0; #endif // IVAS_FLOAT_FIXED diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index e4c253c92b8d3e8ca1d836c2680de16309ffb694..8efdf9c406bae318f334348e2a36a892f95e3a79 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -779,7 +779,7 @@ void open_decoder_LPD( st->hTcxDec->cummulative_damping_tcx = 1.0f; } #else - hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV; /*Q15*/ move16(); + hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/ move16(); hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1; move16(); hTcxDec->conCurrLevelIndex = 0; @@ -788,7 +788,7 @@ void open_decoder_LPD( set16_fx(hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE); /*Q15*/ set16_fx(hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE); hTcxDec->conLastFrameLevel_e = 0; - hTcxDec->conCngLevelBackgroundTrace_e = 0; + hTcxDec->conCngLevelBackgroundTrace_e = -6; hTcxDec->cummulative_damping_tcx = 32767/*1.0f Q15*/; #endif @@ -1670,7 +1670,6 @@ void open_decoder_LPD_ivas_fx( IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->last_core, HQ_CORE ) ) { st->output_frame_fx = st->hTcxDec->L_frameTCX; - floatToFixed_arr( st->previoussynth, st->previoussynth_fx, 0, 960 ); frame_ener_fx( st->output_frame_fx, UNVOICED_CLAS, st->previoussynth_fx, -1, &st->enr_old_fx, 1, 0, 0, 0 ); } } @@ -1695,11 +1694,12 @@ void open_decoder_LPD_ivas_fx( st->hTcxDec->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE - 1; st->hTcxDec->CurrLevelIndex_bfi = 0; st->hTcxDec->LastFrameLevel_bfi_fx = PLC_MIN_CNG_LEV; - set16_fx( st->hTcxDec->NoiseLevelMemory_bfi_fx, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); + set16_fx( st->hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); + set16_fx( st->hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); st->hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/; - hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV; /*Q15*/ move16(); + hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/ move16(); hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1; move16(); hTcxDec->conCurrLevelIndex = 0; @@ -1708,7 +1708,7 @@ void open_decoder_LPD_ivas_fx( set16_fx(hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE); /*Q15*/ set16_fx(hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE); hTcxDec->conLastFrameLevel_e = 0; - hTcxDec->conCngLevelBackgroundTrace_e = 0; + hTcxDec->conCngLevelBackgroundTrace_e = -6; hTcxDec->cummulative_damping_tcx = 32767/*1.0f Q15*/; } @@ -1808,13 +1808,17 @@ void open_decoder_LPD_ivas_fx( { concealment_init_ivas_fx( st->hTcxDec->L_frameTCX, st->hPlcInfo ); //---------------- To be removed later : Only initializations +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) st->hPlcInfo->outx_new_n1 = 0.0f; st->hPlcInfo->nsapp_gain = 0.0f; +#endif +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) st->hPlcInfo->nsapp_gain_n = 0.0f; st->hPlcInfo->ener_mean = 59.4260f; st->hPlcInfo->ener = 0.0f; st->hPlcInfo->recovery_gain_float = 0.0f; st->hPlcInfo->step_concealgain = 0.0f; +#endif //-------------------To be removed later } } @@ -1842,17 +1846,19 @@ void open_decoder_LPD_ivas_fx( st->hTonalMDCTConc->secondLastPowerSpectrum_float = st->hTonalMDCTConc->secondLastBlockData.spectralData_float; st->hTonalMDCTConc->lastBlockData.scaleFactors_float = st->hTonalMDCTConc->scaleFactorsBuffers_float[0]; st->hTonalMDCTConc->secondLastBlockData.scaleFactors_float = st->hTonalMDCTConc->scaleFactorsBuffers_float[1]; - //st->hTonalMDCTConc->pTCI_float = (TonalComponentsInfo_float *) st->hTonalMDCTConc->timeDataBuffer_float; - st->hTonalMDCTConc->pTCI_float = &st->hTonalMDCTConc->pTCI_float1; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + //st->hTonalMDCTConc->pTCI = (TonalComponentsInfo *) st->hTonalMDCTConc->timeDataBuffer_float; + st->hTonalMDCTConc->pTCI = &st->hTonalMDCTConc->pTCI1; st->hTonalMDCTConc->lastPitchLag_float = 0; st->hTonalMDCTConc->scf_fadeout_flt = 1.0f; st->hTonalMDCTConc->last_block_nrg_flt = 0.0f; st->hTonalMDCTConc->curr_noise_nrg_flt = 0.0f; st->hTonalMDCTConc->faded_signal_nrg_flt = 0.0f; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) st->hTonalMDCTConc->secondLastPcmOut_float = &st->hTonalMDCTConc->timeDataBuffer_float[( 3 * L_FRAME_MAX ) / 2 - imult1616( 3, shr( s_min( L_FRAME_MAX, st->hTcxDec->L_frameTCX ), 1 ) )]; st->hTonalMDCTConc->lastPcmOut_float = &st->hTonalMDCTConc->timeDataBuffer_float[( 3 * L_FRAME_MAX ) / 2 - s_min( L_FRAME_MAX, st->hTcxDec->L_frameTCX )]; //---------------To be removed later - assert( sizeof( *st->hTonalMDCTConc->pTCI_float ) <= ( st->hTonalMDCTConc->lastPcmOut_float - st->hTonalMDCTConc->timeDataBuffer_float ) * sizeof( st->hTonalMDCTConc->timeDataBuffer_float[0] ) ); + assert( sizeof( *st->hTonalMDCTConc->pTCI ) <= ( st->hTonalMDCTConc->lastPcmOut_float - st->hTonalMDCTConc->timeDataBuffer_float ) * sizeof( st->hTonalMDCTConc->timeDataBuffer_float[0] ) ); } st->last_tns_active = 0; diff --git a/lib_dec/core_dec_reconf.c b/lib_dec/core_dec_reconf.c index 56af9cc81ed7baef0a840eb06083c758f4ee3fab..6e6b8018fd34fd43c41e0d168f39dee90551c21b 100644 --- a/lib_dec/core_dec_reconf.c +++ b/lib_dec/core_dec_reconf.c @@ -169,13 +169,17 @@ void reconfig_decoder_LPD_ivas( oldLen = L_SYN_MEM_CLAS_ESTIM; newLen = L_SYN_MEM_CLAS_ESTIM * st->L_frame / st->last_L_frame; } - lerp_flt( &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - oldLen], &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - newLen], newLen, oldLen ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + lerp_flt(&st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - oldLen], &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - newLen], newLen, oldLen); +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) } } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) else { - set_zero( st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ); + set_zero(st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM); } +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) } } diff --git a/lib_dec/core_dec_switch.c b/lib_dec/core_dec_switch.c index 2d4d460c340df255aabea42900ee2bf0ca946d50..dc331314c5d23135100aa6c7d90950e0d1344aef 100644 --- a/lib_dec/core_dec_switch.c +++ b/lib_dec/core_dec_switch.c @@ -155,8 +155,9 @@ void mode_switch_decoder_LPD_flt( { st->narrowBand = 0; } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) st->TcxBandwidth_float = getTcxBandwidth_flt( bwidth ); - +#endif if ( st->hTcxCfg != NULL ) { st->hTcxCfg->pCurrentTnsConfig = NULL; @@ -174,6 +175,7 @@ void mode_switch_decoder_LPD_flt( frame_size = FrameSizeConfig[frame_size_index].frame_net_bits; reconfig_decoder_LPD_ivas( st, frame_size, bwidth, total_brate, st->last_L_frame ); +#if ( defined EVS_FLOAT ) || !( defined IVAS_FLOAT_FIXED ) if ( hTcxDec->envWeighted && !hTcxDec->enableTcxLpc ) { mvr2r( st->lspold_uw_float, st->lsp_old, M ); @@ -185,6 +187,7 @@ void mode_switch_decoder_LPD_flt( lsp2lsf( st->lsp_old, st->lsfoldbfi1, M, st->sr_core ); mvr2r( st->lsfoldbfi1, st->lsfoldbfi0, M ); mvr2r( st->lsfoldbfi1, st->lsf_adaptive_mean, M ); +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if ( st->igf && st->hBWE_TD != NULL ) { @@ -197,11 +200,20 @@ void mode_switch_decoder_LPD_flt( } else { +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( st->hBWE_TD->state_lpc_syn, 0.0f, LPC_SHB_ORDER ); set_f( st->hBWE_TD->state_syn_shbexc, 0.0f, L_SHB_LAHEAD ); set_f( st->hBWE_TD->mem_stp_swb, 0.0f, LPC_SHB_ORDER ); set_f( st->hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER ); st->hBWE_TD->gain_prec_swb = 1.0f; +#endif +#ifdef IVAS_FLOAT_FIXED + set_val_Word16(st->hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER); + set_val_Word16( st->hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); + set_val_Word16( st->hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); + set_val_Word16( st->hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); + st->hBWE_TD->gain_prec_swb_fx = 16384; +#endif } } @@ -209,7 +221,12 @@ void mode_switch_decoder_LPD_flt( { if ( st->tec_tfa == 0 && st->hTECDec != NULL ) { +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_zero( st->hTECDec->loBuffer_flt, MAX_TEC_SMOOTHING_DEG ); +#endif +#ifdef IVAS_FLOAT_FIXED + set_val_Word16( st->hTECDec->loBuffer, 0, MAX_TEC_SMOOTHING_DEG ); +#endif } st->tec_tfa = 1; } diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c index bc416760805b0a83feb64291c6e349deb04151f3..b92493183f47548b0f10d972d79e284d2d1f12f0 100644 --- a/lib_dec/core_switching_dec.c +++ b/lib_dec/core_switching_dec.c @@ -97,8 +97,8 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); IF( st->hBPF != NULL ) { - set32_fx( st->hBPF->pst_old_syn_32, 0, NBPSF_PIT_MAX ); - st->hBPF->pst_mem_deemp_err_32 = 0; + set16_fx( st->hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); + st->hBPF->pst_mem_deemp_err_fx = 0; move32(); } st->psf_lp_noise_fx = round_fx(L_shl(st->lp_noise, 1)); @@ -400,11 +400,7 @@ ivas_error core_switching_pre_dec_ivas_fx( { Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); } -#if 1 /*To be removed later: floating point initializations*/ - st->tilt_code = 0.0f; - st->gc_threshold = 0.0f; - set_f( st->dispMem, 0, 8 ); -#endif + st->tilt_code_fx = 0; st->gc_threshold_fx = 0; st->dm_fx.prev_gain_code = 0; @@ -419,15 +415,12 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); fer_energy_fx( output_frame, UNVOICED_CLAS, st->previoussynth_fx_32, 0, -1, &st->enr_old_fx, 1 ); /*Q-0*/ -#if 1 /*To be removed later: floating point initializations*/ - st->lp_gainp = 0.0f; -#endif st->lp_gainp_fx = 0; move16(); st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/ st->lp_gainc_fx = shr( st->lp_gainc_fx, 12 - exp ); /*Q3*/ -#if 1 /*To be removed later: floating point initializations*/ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*To be removed later: floating point initializations*/ st->last_voice_factor = 0; #endif st->last_voice_factor_fx = 0; @@ -476,9 +469,9 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); } #if 1 - st->tilt_code = 0.0f; - st->gc_threshold = 0.0f; - set_f( st->dispMem, 0, 8 ); + //st->tilt_code = 0.0f; + //st->gc_threshold = 0.0f; + //set_f( st->dispMem, 0, 8 ); #endif st->tilt_code_fx = 0; @@ -494,16 +487,12 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); fer_energy_fx( output_frame, UNVOICED_CLAS, st->previoussynth_fx_32, 0, -1, &st->enr_old_fx, 1 ); /*Q-0*/ -#if 1 /*To be removed later: Floating point initialization*/ - st->lp_gainp = 0.0f; -#endif - st->lp_gainp_fx = 0; move16(); st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/ st->lp_gainc_fx = shr( st->lp_gainc_fx, 12 - exp ); /*Q3*/ -#if 1 /*To be removed later: Floating point initialization*/ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) st->last_voice_factor = 0; #endif // st->last_voice_factor_fx = 0; @@ -581,7 +570,7 @@ ivas_error core_switching_pre_dec_ivas_fx( //st->hHQ_core->energy_lt = 300.0f; //set_f( st->hHQ_core->prev_noise_level, 0.0f, 2 ); //st->hHQ_core->prev_ni_ratio = 0.5f; - set_f( st->hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS ); + //set_f( st->hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS ); #endif st->hHQ_core->energy_lt_fx = 2457600;/*300.0f Q13*/ move32(); @@ -708,7 +697,7 @@ ivas_error core_switching_pre_dec_ivas_fx( return error; } #endif // IVAS_FLOAT_FIXED - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) ivas_error core_switching_pre_dec( Decoder_State *st, /* i/o: decoder state structure */ const int16_t output_frame, /* i : frame length */ @@ -1201,8 +1190,8 @@ ivas_error core_switching_pre_dec( return error; } - - +#endif +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*---------------------------------------------------------------------* * core_switching_post_dec() * @@ -1225,7 +1214,7 @@ ivas_error core_switching_post_dec( int16_t i, delay_comp, delta; #ifdef IVAS_FLOAT_FIXED Word32 synth_fx[960]; - Word32 output_fx[1500]; + //Word32 output_fx[1500]; #endif float tmpF; float tmpDelta; @@ -1337,75 +1326,7 @@ ivas_error core_switching_post_dec( /* if this is first active MDCT-Stereo frame after a CNG frame and output format is mono DMX, this should only be done for the zero-th channel, the other one will simply be copied over after this function */ if ( ( ( st->last_core_brate != SID_2k40 && st->last_core_brate != FRAME_NO_DATA ) || ( st->element_mode != IVAS_CPE_DFT && st->element_mode != IVAS_CPE_TD ) || nchan_out == 1 ) && !( st->element_mode == IVAS_CPE_MDCT && st->idchan == 1 && ( nchan_out == 1 || last_element_mode == IVAS_CPE_DFT ) ) ) { -#ifdef IVAS_FLOAT_FIXED - // float to fix - // cldfb size calculaions - Word16 no_channel_ana = st->cldfbAna->no_channels; - Word16 no_channel_bpf = st->cldfbBPF->no_channels; - Word16 no_col_ana = st->cldfbAna->no_col; - Word16 no_col_bpf = st->cldfbBPF->no_col; - Word16 p_filter_ana = st->cldfbAna->p_filter_length; - Word16 p_filter_bpf = st->cldfbBPF->p_filter_length; - Word32 sampling_rate = st->L_frame * FRAMES_PER_SEC; - if ( ( st->cldfbAna->no_channels * st->cldfbAna->no_col ) != st->L_frame ) - { - no_channel_ana = (Word16) ( sampling_rate * INV_CLDFB_BANDWIDTH + 0.5 ); - no_col_ana = 16; - p_filter_ana = 10 * no_channel_ana; - if ( st->cldfbBPF != NULL && st->L_frame <= L_FRAME16k ) - { - no_channel_bpf = (Word16) ( sampling_rate * INV_CLDFB_BANDWIDTH + 0.5 ); - no_col_bpf = 16; - p_filter_bpf = 10 * no_channel_bpf; - } - - if ( st->ini_frame > 0 ) - { - st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - no_channel_ana; - } - } - // buffer sized calculations - Word16 size = 0; - Word16 no_col = st->cldfbSyn->no_col; - if ( CLDFB_OVRLP_MIN_SLOTS * st->cldfbSyn->no_channels > -1 ) - { - no_col = min( no_col, ( CLDFB_OVRLP_MIN_SLOTS * st->cldfbSyn->no_channels + st->cldfbSyn->no_channels - 1 ) / st->cldfbSyn->no_channels ); - } - if ( CLDFB_OVRLP_MIN_SLOTS * no_channel_ana > -1 ) - { - size = CLDFB_OVRLP_MIN_SLOTS * no_channel_ana; - } - else - { - size = no_channel_ana * no_col_ana; - } - size = max( size, no_col * st->cldfbSyn->no_channels ); - - Word16 size_ana_len = max( p_filter_ana - no_channel_ana, st->cldfbAna->p_filter_length - st->cldfbAna->no_channels ); - Word16 size_bpf_len = max( p_filter_bpf - no_channel_bpf, st->cldfbBPF->p_filter_length - st->cldfbBPF->no_channels ); - - floatToFixed_arrL( output, output_fx, 10, size ); - floatToFixed_arrL( st->bpf_noise_buf_float, st->bpf_noise_buf_32, 11, size ); - floatToFixed_arrL( st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_fx, 10, size_ana_len ); - floatToFixed_arrL( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_fx, 11, size_bpf_len ); - floatToFixed_arrL( st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_fx, 4, st->cldfbSyn->p_filter_length ); - - // ------- - core_switch_lb_upsamp_fx( st, output_fx ); - // ------- - - fixedToFloat_arrL( output_fx, output, 4, size ); - fixedToFloat_arrL( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_state, 10, size_ana_len ); - fixedToFloat_arrL( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_state, 11, size_bpf_len ); - fixedToFloat_arrL( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_state, 4, st->cldfbSyn->p_filter_length ); - if ( st->hTcxDec != NULL ) - { - fixedToFloat_arrL( st->previoussynth_fx_32, st->previoussynth, 4, st->hTcxDec->L_frameTCX ); - } - -#else core_switch_lb_upsamp( st, output ); -#endif } mvr2r( st->previoussynth, synth, delay_comp ); @@ -1673,7 +1594,7 @@ ivas_error core_switching_post_dec( return error; } - +#endif /*---------------------------------------------------------------------* * core_switching_hq_prepare_dec() * @@ -1928,7 +1849,7 @@ void bandwidth_switching_detect_ivas_fx( * * Band-width switching pre-processing *---------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void bw_switching_pre_proc( Decoder_State *st, /* i/o: decoder state structure */ const float *old_syn_12k8_16k, /* i : ACELP core synthesis at 12.8kHz or 16kHz */ @@ -2033,7 +1954,7 @@ void bw_switching_pre_proc( return; } - +#endif #ifdef IVAS_FLOAT_FIXED void ivas_bw_switching_pre_proc_fx( Decoder_State *st, /* i/o: decoder state structure */ @@ -2046,7 +1967,6 @@ void ivas_bw_switching_pre_proc_fx( { Word16 i; Word32 syn_dct_fx[L_FRAME]; - Word32 L_tmp; Flag Overflow = 0; @@ -2108,9 +2028,7 @@ void ivas_bw_switching_pre_proc_fx( { IF ( st->hHQ_core->old_is_transient[0] ) { - Word64 W_tmp = 0; Word32 tmp, L_tmp = 0; - Word16 shift; FOR ( i = 0; i < 32; i++ ) { L_tmp = L_mac0_o(L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow); @@ -2134,7 +2052,6 @@ void ivas_bw_switching_pre_proc_fx( ELSE { Word32 tmp, L_tmp = 0; - Word16 shift; L_tmp = 0; FOR ( i = 0; i < L_FRAME / 2; i++ ) { @@ -2159,12 +2076,12 @@ void ivas_bw_switching_pre_proc_fx( IF ( EQ_16( st->last_bwidth, 0 ) && LE_16( st->extl, SWB_CNG ) ) { - st->prev_ener_shb = 0.0f; + //st->prev_ener_shb = 0.0f; st->prev_ener_shb_fx = 0; IF( st->hBWE_FD != NULL ) { - set_f( st->hBWE_FD->prev_SWB_fenv, 0, SWB_FENV ); + //set_f( st->hBWE_FD->prev_SWB_fenv, 0, SWB_FENV ); set_s( st->prev_SWB_fenv_fx, 0, SWB_FENV ); } } diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index f20061d4efd940cf4b42d7909fa24a16d22786a7..8f3b24184ba1b537dc9a0ee6cea5f6c34342e8ff 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -9,6 +9,9 @@ #include "prot_fx1.h" /* Function prototypes */ #include "prot_fx2.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif /*---------------------------------------------------------------------* @@ -1446,8 +1449,10 @@ ivas_error core_switching_post_dec_fx( { /* reset in case that SWB TBE layer is transmitted, but the output is 16kHz sampled */ set16_fx(hBWE_TD->mem_resamp_HB_32k_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); + set32_fx(hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1); } set16_fx(hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN); + set32_fx(hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN); } ELSE IF( ( EQ_16(st_fx->extl, SWB_TBE)||EQ_16(st_fx->extl,FB_TBE))&& ( NE_32(st_fx->last_total_brate, st_fx->total_brate) || NE_16(st_fx->last_bwidth, st_fx->bwidth) || @@ -2015,7 +2020,8 @@ ivas_error core_switching_post_dec_ivas_fx( hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 ); - swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); + //swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); + swb_tbe_reset_synth_ivas_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32); st_fx->hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /* Q0 1.f */ st_fx->hBWE_TD->prev_mix_factor_fx = 32767; /* Q15 1.f */ @@ -2024,8 +2030,10 @@ ivas_error core_switching_post_dec_ivas_fx( { /* reset in case that SWB TBE layer is transmitted, but the output x`x`is 16kHz sampled */ set16_fx( hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + set32_fx(hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1); } set16_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN ); + set32_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN ); } ELSE IF( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && ( NE_32( st_fx->last_total_brate, st_fx->total_brate ) || NE_16( st_fx->last_bwidth, st_fx->bwidth ) || diff --git a/lib_dec/dec_LPD.c b/lib_dec/dec_LPD.c index bcba3ef8e757fd8ce22bc1bf668a6e7fd4a18d56..a307cba3a0b4b0ec27d05d40383bddc21de97a28 100644 --- a/lib_dec/dec_LPD.c +++ b/lib_dec/dec_LPD.c @@ -52,7 +52,7 @@ * * Core decoder MODE2 *--------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void decoder_LPD_flt( Decoder_State *st, /* i/o: decoder memory state pointer */ float signal_out[], /* o : signal with LPD delay (7 subfrs) */ @@ -787,3 +787,4 @@ void decoder_LPD_flt( return; } +#endif \ No newline at end of file diff --git a/lib_dec/dec_ace.c b/lib_dec/dec_ace.c index 84717665ab4f63390835cbcb3ce748ef1e9bbaba..a643e05c23848349b5f9a68387ef67e0d250f4c2 100644 --- a/lib_dec/dec_ace.c +++ b/lib_dec/dec_ace.c @@ -40,7 +40,7 @@ #include #include "rom_com.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * decoder_acelp_flt() * @@ -540,3 +540,4 @@ void decoder_acelp_flt( return; } +#endif diff --git a/lib_dec/dec_acelp_tcx_main.c b/lib_dec/dec_acelp_tcx_main.c index 33b37ece95b0aa6b483074520e339bd8257f54dc..149c1206eb4266972f205e51c743660c394bbaaf 100644 --- a/lib_dec/dec_acelp_tcx_main.c +++ b/lib_dec/dec_acelp_tcx_main.c @@ -41,7 +41,7 @@ #include "options.h" #include "stat_dec.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * decode_frame_type_flt() * @@ -487,3 +487,4 @@ void dec_acelp_tcx_frame_flt( pop_wmops(); return; } +#endif \ No newline at end of file diff --git a/lib_dec/dec_amr_wb.c b/lib_dec/dec_amr_wb.c index ce636756a866bca085a9411da92ca8bb2d83ca4e..7ddb784cc923faa357fc33f9264840b211f3c525 100644 --- a/lib_dec/dec_amr_wb.c +++ b/lib_dec/dec_amr_wb.c @@ -46,7 +46,7 @@ * * Decode excitation signal in AMR-WB IO mode *---------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void decod_amr_wb( Decoder_State *st, /* i/o: decoder static memory */ const float *Aq, /* i : LP filter coefficients */ @@ -168,3 +168,4 @@ void decod_amr_wb( return; } +#endif diff --git a/lib_dec/dec_gen_voic.c b/lib_dec/dec_gen_voic.c index e555faec3fd4902710d69ad2e5e0ae121156318f..a62b3f40864fa814d0b8fb3aff70e1922c252adc 100644 --- a/lib_dec/dec_gen_voic.c +++ b/lib_dec/dec_gen_voic.c @@ -40,7 +40,7 @@ #include "rom_com.h" #include "prot.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*---------------------------------------------------------------------* * decod_gen_voic() * @@ -292,3 +292,4 @@ ivas_error decod_gen_voic( return error; } +#endif diff --git a/lib_dec/dec_higher_acelp.c b/lib_dec/dec_higher_acelp.c index f14658150f731abf7545d5d7547216d4580897aa..0d6856b84f4bb3a7b4ec6c4ffb7431d84495384d 100644 --- a/lib_dec/dec_higher_acelp.c +++ b/lib_dec/dec_higher_acelp.c @@ -50,7 +50,7 @@ * * Transform domain contribution decoding *-----------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void transf_cdbk_dec( Decoder_State *st, /* i/o: decoder state structure */ const int16_t harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ @@ -234,3 +234,4 @@ float gain_dequant( return ( gain ); } +#endif diff --git a/lib_dec/dec_nelp.c b/lib_dec/dec_nelp.c index 586df0f7adcc2a9c109284902e9f7899bba4f43f..80e86881f8c2ec5bc31929e2393e63dcbafb8625 100644 --- a/lib_dec/dec_nelp.c +++ b/lib_dec/dec_nelp.c @@ -39,7 +39,7 @@ #include "cnst.h" #include "prot.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * decod_nelp() * @@ -99,3 +99,4 @@ void decod_nelp( return; } +#endif diff --git a/lib_dec/dec_pit_exc.c b/lib_dec/dec_pit_exc.c index 029343f326e44183e5cd57ecd7db142222f37906..431bdf9b41e16051d470cc4721321ad75beb9a60 100644 --- a/lib_dec/dec_pit_exc.c +++ b/lib_dec/dec_pit_exc.c @@ -46,7 +46,7 @@ * * Decode pitch-only contribution (used by the GSC technology) *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void dec_pit_exc( Decoder_State *st, /* i/o: decoder static memory */ const int16_t L_frame, /* i : length of the frame */ @@ -339,3 +339,4 @@ void dec_pit_exc( return; } +#endif diff --git a/lib_dec/dec_post.c b/lib_dec/dec_post.c index 43b28d4926ce03ccca225b69db4dae94b91a008c..a8ea1fa10472c66514c722c2d3dbac314450667d 100644 --- a/lib_dec/dec_post.c +++ b/lib_dec/dec_post.c @@ -75,7 +75,7 @@ static void Dec_formant_postfilt( PFSTAT *pfstat, const float *signal_ptr, const * * Post-filter initialization *--------------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void Init_post_filter_ivas( PFSTAT_HANDLE hPFstat /* i/o: post-filter state memories handle */ ) @@ -103,14 +103,14 @@ void Init_post_filter_ivas( return; } - +#endif /*-------------------------------------------------------------------------- * nb_post_filt_ivas() * * Main routine to perform post filtering of NB signals *--------------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void nb_post_filt_ivas( const int16_t L_frame, /* i : frame length */ const int16_t L_subfr, /* i : sub-frame length */ @@ -178,14 +178,14 @@ void nb_post_filt_ivas( return; } - +#endif /*-------------------------------------------------------------------------- * formant_post_filt: * * WB and SWB formant post-filtering *--------------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void formant_post_filt_ivas( PFSTAT_HANDLE hPFstat, /* i/o: Post filter related memories */ float *synth_in, /* i : 12k8 synthesis */ @@ -291,7 +291,7 @@ void formant_post_filt_ivas( return; } - +#endif /*---------------------------------------------------------------------------- * Dec_postfilt() @@ -316,7 +316,7 @@ void formant_post_filt_ivas( * 1. search around 1st subframe delay (3 integer values) * 2. search around best integer with fract. delays (1/8) *----------------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) static void Dec_postfilt( const int16_t L_subfr, /* i : sub-frame length */ PFSTAT *pfstat, /* i/o: Post filter related memories */ @@ -385,7 +385,7 @@ static void Dec_postfilt( return; } - +#endif /*---------------------------------------------------------------------------- * Dec_formant_postfilt @@ -402,7 +402,7 @@ static void Dec_postfilt( * k1 = 1st parcor calculated on {hi} * gamma3 = gamma3_minus if k1<0, gamma3_plus if k1>0 *----------------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) static void Dec_formant_postfilt( PFSTAT_HANDLE hPFstat, /* i/o: states strucure */ const float *signal_ptr, /* i : input signal (pointer to current subframe */ @@ -447,7 +447,7 @@ static void Dec_formant_postfilt( return; } - +#endif /*---------------------------------------------------------------------------- * pst_ltp() diff --git a/lib_dec/dec_ppp.c b/lib_dec/dec_ppp.c index 58d21e75c6ed02dc1a43c2442ea504d18f594404..5e2d86a69cfc47b43fd048429f88ec4542475558 100644 --- a/lib_dec/dec_ppp.c +++ b/lib_dec/dec_ppp.c @@ -39,7 +39,7 @@ #include "cnst.h" #include "prot.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*------------------------------------------------------------------- * decod_ppp() * @@ -106,3 +106,4 @@ ivas_error decod_ppp( return error; } +#endif diff --git a/lib_dec/dec_prm.c b/lib_dec/dec_prm.c index e1460b02d53e059c757350b4a93cc2b85c9d6b3a..296a15cf98d63cc28acd85d861452e733cd5e08a 100644 --- a/lib_dec/dec_prm.c +++ b/lib_dec/dec_prm.c @@ -402,7 +402,7 @@ void getLPCparam_ivas( return; } - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * getTCXparam_ivas() * @@ -757,7 +757,7 @@ void dec_prm_hm_ivas( return; } - +#endif /*-----------------------------------------------------------------* * Function dec_prm_ivas() * @@ -767,7 +767,7 @@ void dec_prm_hm_ivas( * * decode parameters according to selected mode * *-----------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void dec_prm_ivas( Decoder_State *st, /* i/o: decoder memory state */ int16_t param[], /* o : decoded parameters */ @@ -1170,3 +1170,4 @@ void dec_prm_ivas( } return; } +#endif \ No newline at end of file diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index 8c9a9958a923198527b3fe25d2e3cc3333f70ab7..f38d285a7d546f818624e2200be2dd8e5f5888ea 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -118,7 +118,7 @@ void decoder_tcx_flt( * * *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void decoder_tcx_post_flt( Decoder_State *st, /* i/o: decoder memory state */ float *synth, /* i/o: synthesis */ @@ -260,7 +260,9 @@ void decoder_tcx_post_flt( st->old_pitch_buf[1] = st->old_pitch_buf[st->nb_subfr + 1]; mvr2r( &st->old_pitch_buf[st->nb_subfr + 2], &st->old_pitch_buf[2], st->nb_subfr ); set_f( &st->old_pitch_buf[st->nb_subfr + 2], st->old_fpitch_float, st->nb_subfr ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) st->bfi_pitch = st->old_fpitch_float; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) st->bfi_pitch_frame = st->L_frame; st->mem_pitch_gain_float[2 * st->nb_subfr + 1] = st->mem_pitch_gain_float[st->nb_subfr + 1]; @@ -1152,7 +1154,6 @@ void decoder_tcx_invQ( return; } -#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * decoder_tcx_noisefilling() * @@ -1907,32 +1908,7 @@ void decoder_tcx_imdct( /* Generate additional comfort noise to mask potential coding artefacts */ if ( st->flag_cna && st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && !st->cna_dirac_flag ) { -#ifdef IVAS_FLOAT_FIXED - Word32 x_fx[960]; - Word16 x_e; - float maxim = 0; - f2me_buf(x, x_fx, &x_e, L_frame); - FOR(Word16 ind = 0; ind < L_frame; ind++) x_fx[ind] = L_shr(x_fx[ind], 1); - x_e += 1; - maxim = 0; - FOR(Word16 ind = 0; ind < FFTCLDFBLEN; ind++) - { - maxim = fmaxf(maxim, fabsf(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[ind])); - } - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; - IF(L_abs((Word32)maxim)!=0) st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - norm_l((Word32)maxim); - FOR(Word16 ind = 0; ind < FFTCLDFBLEN; ind++) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel[ind] = (Word32)(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[ind] * (1LL<<(31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp))); - } - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = float_to_fix16(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt, 15); - - generate_masking_noise_mdct( x_fx, &x_e, st->hFdCngDec->hFdCngCom, L_frame ); - - me2f_buf(x_fx, x_e, x, L_frame); -#else generate_masking_noise_mdct_flt( x, st->hFdCngDec->hFdCngCom ); -#endif } if ( st->element_mode == IVAS_CPE_DFT || sba_dirac_stereo_flag ) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index acdba363cb93ced038341a801a070934ff048882..9f19d4396073bc7f90ce2e3b202bf990d096f65e 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -1710,7 +1710,8 @@ void decoder_tcx_post_ivas_fx(Decoder_State *st_fx, #else tmp1 = round_fx(L_shl(tmp32, tmp2)); #endif - s = sub(sub(sub(1, shl(s, 1)), 6/*table lookup for inverse framelength*/), tmp2); + //s = sub(sub(sub(1, shl(s, 1)), 6/*table lookup for inverse framelength*/), tmp2); + s = sub(25, add(shl(add(-2, s), 1), tmp2)); tmp1 = Sqrt16(tmp1, &s); move16(); level_syn = tmp1; /*Q0*/ @@ -1718,7 +1719,7 @@ void decoder_tcx_post_ivas_fx(Decoder_State *st_fx, /* PLC: [TCX: Fade-out] * PLC: estimate and update CNG energy */ - level_syn_e = add(s,15); + level_syn_e = s;// add(s, 15); test(); test(); IF (bfi == 0 && st_fx->tcxonly != 0 && ( NE_16(st_fx->element_mode, IVAS_CPE_MDCT) || MCT_flag ) && EQ_16(st_fx->clas_dec , UNVOICED_CLAS)) @@ -1728,8 +1729,8 @@ void decoder_tcx_post_ivas_fx(Decoder_State *st_fx, Qnew_levelBackgroundTrace = 0; move16(); minimumStatistics(hTcxDec->conNoiseLevelMemory, /*Q15*/ - &hTcxDec->conNoiseLevelIndex, /*Q0 */ - &hTcxDec->conCurrLevelIndex, /*Q0 */ + &hTcxDec->NoiseLevelIndex_bfi, /*Q0 */ + &hTcxDec->CurrLevelIndex_bfi, /*Q0 */ &hTcxDec->conCngLevelBackgroundTrace, /*Q15*/ &hTcxDec->conLastFrameLevel, /*Q15*/ level_syn, /*Q15*/ @@ -4443,7 +4444,7 @@ void decoder_tcx_noisefilling_fx( IF( bfi == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x, *x_e, L_frameTCX, L_frame, gainlpc2, gainlpc2_e, gain_tcx_e, infoIGFStartLine ); - st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); + //st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); } ELSE IF( bfi ) { @@ -4549,8 +4550,8 @@ void decoder_tcx_noisefilling_fx( TonalMDCTConceal_InsertNoise_ivas_fx( st->hTonalMDCTConc, x, x_e, st->tonal_mdct_plc_active, &st->seed_tcx_plc, noiseTiltFactor, f, NULL, 0, hTcxDec->CngLevelBackgroundTrace_bfi_fx, hTcxDec->CngLevelBackgroundTrace_bfi_exp, infoIGFStartLine ); } - st->hTonalMDCTConc->faded_signal_nrg_flt = me2f( st->hTonalMDCTConc->faded_signal_nrg, st->hTonalMDCTConc->faded_signal_nrg_exp ); - st->hTonalMDCTConc->curr_noise_nrg_flt = me2f( st->hTonalMDCTConc->curr_noise_nrg, st->hTonalMDCTConc->curr_noise_nrg_exp ); + //st->hTonalMDCTConc->faded_signal_nrg_flt = me2f( st->hTonalMDCTConc->faded_signal_nrg, st->hTonalMDCTConc->faded_signal_nrg_exp ); + //st->hTonalMDCTConc->curr_noise_nrg_flt = me2f( st->hTonalMDCTConc->curr_noise_nrg, st->hTonalMDCTConc->curr_noise_nrg_exp ); } } } @@ -4741,9 +4742,9 @@ void decoder_tcx_noiseshaping_igf_fx( *x_e = s_max( curr_x_e, prev_x_e ); FOR( i = 0; i < L_frameTCX; i++ ) { - Word16 n_idx = st->hTonalMDCTConc->pTCI_float->numIndexes; - Word16 l_idx = st->hTonalMDCTConc->pTCI_float->lowerIndex[0]; - Word16 u_idx = st->hTonalMDCTConc->pTCI_float->upperIndex[n_idx - 1]; + Word16 n_idx = st->hTonalMDCTConc->pTCI->numIndexes; + Word16 l_idx = st->hTonalMDCTConc->pTCI->lowerIndex[0]; + Word16 u_idx = st->hTonalMDCTConc->pTCI->upperIndex[n_idx - 1]; test(); IF( GE_16( i, l_idx ) && LE_16( i, u_idx ) ) { diff --git a/lib_dec/dec_tran.c b/lib_dec/dec_tran.c index 900212817e122dcdeaa6e4f9e046f05f99fc9858..65878183e15280237484c10c9e54ac484836be92 100644 --- a/lib_dec/dec_tran.c +++ b/lib_dec/dec_tran.c @@ -45,7 +45,7 @@ * * Decode transition (TC) frames *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void decod_tran( Decoder_State *st, /* i/o: decoder static memory */ const int16_t L_frame, /* i : length of the frame */ @@ -195,3 +195,4 @@ void decod_tran( return; } +#endif diff --git a/lib_dec/dec_uv.c b/lib_dec/dec_uv.c index 05d139ea261cfd203a8c859d32c4ace6b9adebed..34866754ac0349c76b1b2cc2f0af4f293532a047 100644 --- a/lib_dec/dec_uv.c +++ b/lib_dec/dec_uv.c @@ -38,7 +38,7 @@ #include "options.h" #include "prot.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * decod_unvoiced() * @@ -166,3 +166,4 @@ void decod_unvoiced( return; } +#endif diff --git a/lib_dec/dlpc_stoch.c b/lib_dec/dlpc_stoch.c index 9e90f885999633c1a0fc45a9dc4da4ead51970fc..332e7cddbf9bac5c4a5dab52677a10e1f099205c 100644 --- a/lib_dec/dlpc_stoch.c +++ b/lib_dec/dlpc_stoch.c @@ -47,7 +47,7 @@ * * *------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void lpc_unquantize_flt( Decoder_State *st, float *lsf, @@ -118,3 +118,4 @@ void lpc_unquantize_flt( return; } +#endif \ No newline at end of file diff --git a/lib_dec/er_dec_acelp.c b/lib_dec/er_dec_acelp.c index 3bd3d522b649290645613610bd765c06cd376761..01eb2389a32d405cb018f988f9871987705b4fa3 100644 --- a/lib_dec/er_dec_acelp.c +++ b/lib_dec/er_dec_acelp.c @@ -40,7 +40,7 @@ #include #include "prot.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * con_acelp_flt() * @@ -721,3 +721,4 @@ void con_acelp_flt( return; } +#endif diff --git a/lib_dec/er_dec_tcx.c b/lib_dec/er_dec_tcx.c index b9c3578f9139ced30d0dda15af419ae19bb06cfe..e6b31d69dedfab16226a9e26e93e2b0059cd6e7e 100644 --- a/lib_dec/er_dec_tcx.c +++ b/lib_dec/er_dec_tcx.c @@ -44,6 +44,7 @@ #include "rom_dec.h" #include "wmc_auto.h" +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-----------------------------------------------------------------* * con_tcx_flt() * @@ -650,3 +651,4 @@ void con_tcx_flt( return; } +#endif diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 1fe4f1bba590ae043a9c14a0575289fe8e51e368..d0b2b1df91a8e5693faeda7cf896074e28703726 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -1829,7 +1829,7 @@ void con_tcx_ivas_fx( tmp_e = norm_l(L_tmp); L_tmp = L_shl(L_tmp,tmp_e); gain_inov_e = add(sub(gain_inov_e,tmp_e),31-29);/*->Q31*/ - gain_inov = round_fx(L_tmp);/*Q15,gain_inov_e*/ + gain_inov = round_fx_sat(L_tmp);/*Q15,gain_inov_e*/ } st->Mode2_lp_gainp = L_shr(L_deposit_h(alpha/*Q14*/)/*Q14+16*/,1);/*Q29*/ diff --git a/lib_dec/er_util.c b/lib_dec/er_util.c index 8f40017908a28205b0796f3537b845f651db77e5..9ff9543f8118811a89a7d3380a56f5314603fc3c 100644 --- a/lib_dec/er_util.c +++ b/lib_dec/er_util.c @@ -42,7 +42,7 @@ #include "stat_com.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*---------------------------------------------------------------------* * minimumStatistics_flt() * @@ -336,3 +336,4 @@ int16_t GetPLCModeDecision_flt( return core; } +#endif diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index 34968d8f7e810b59b6f829778eb95c0ec88a27d5..fff93ee219eea52765b7e6cc0b6ee246e90f2a86 100644 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -119,6 +119,12 @@ void minimumStatistics( tmp = mult_r(tmp,currentFrameLevel); /*Q_tmp = tmp2 + currentFrameLevel_e*/ tmp2 = add(tmp2,currentFrameLevel_e); + IF(EQ_16(tmp, 0)) + { + tmp2 = 0; + move16(); + } + *new_noiseEstimate_e = BASOP_Util_Add_MantExp(round_fx(tmp32),add(aOpt_e,noiseLevelMemory_e[tmp_e - 1]),negate(s_max(tmp,-32767)/*to avoid negate(-32768)*/),tmp2,&f); assert(f >= 0); diff --git a/lib_dec/evs_dec.c b/lib_dec/evs_dec.c index 76c2fe87249f156e7ac0e6ceeb0c46834bc4cb56..2f9e2e22ea4faa0f4d670f06984455e124ce62b7 100644 --- a/lib_dec/evs_dec.c +++ b/lib_dec/evs_dec.c @@ -46,7 +46,7 @@ #include "prot_fx2.h" #include "ivas_prot_fx.h" #endif - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*--------------------------------------------------------------------------* * evs_dec_flt() * @@ -945,3 +945,4 @@ ivas_error evs_dec_flt( pop_wmops(); return error; } +#endif diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index f4ac3042e10cf629ff8b4803f8c0c338f25695b5..4e961098795e2e8100595f856c61a47b2657981e 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -74,7 +74,7 @@ /*------------------------------------------------------------------- * Local fucntions declarations *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) static void perform_noise_estimation_dec_flt( const float *timeDomainInput, float *power_spectrum, HANDLE_FD_CNG_DEC hFdCngDec, const int16_t element_mode, const int16_t bwidth, const int16_t L_frame, const int16_t last_L_frame, const int32_t last_core_brate, const int16_t VAD ); #endif // IVAS_FLOAT_FIXED @@ -130,6 +130,7 @@ void initFdCngDec_flt( /* Set some counters and flags */ hFdCngDec->flag_dtx_mode = 0; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hFdCngDec->lp_noise_float = -20.f; hFdCngDec->lp_speech_float = 25.f; @@ -137,8 +138,8 @@ void initFdCngDec_flt( set_f( hFdCngDec->bandNoiseShape_float, 0.0f, FFTLEN2 ); set_f( hFdCngDec->partNoiseShape_float, 0.0f, NPART ); set_f( hFdCngDec->msPeriodog_float, 0.0f, NPART_SHAPING ); - set_f( hFdCngDec->msAlpha_float, 0.0f, NPART_SHAPING ); - set_f( hFdCngDec->msBminWin_float, 0.0f, NPART_SHAPING ); + set_f( hFdCngDec->msAlpha_float, 0.0f, NPART_SHAPING ); + set_f( hFdCngDec->msBminWin_float, 0.0f, NPART_SHAPING ); set_f( hFdCngDec->msBminSubWin_float, 0.0f, NPART_SHAPING ); set_f( hFdCngDec->msPsd_float, 0.0f, NPART_SHAPING ); set_f( hFdCngDec->msNoiseFloor_float, 0.0f, NPART_SHAPING ); @@ -147,44 +148,58 @@ void initFdCngDec_flt( set_f( hFdCngDec->msCurrentMin_float, FLT_MAX, NPART_SHAPING ); set_f( hFdCngDec->msCurrentMinOut_float, FLT_MAX, NPART_SHAPING ); set_f( hFdCngDec->msCurrentMinSubWindow_float, FLT_MAX, NPART_SHAPING ); +#endif set_s( hFdCngDec->msLocalMinFlag, 0, NPART_SHAPING ); set_s( hFdCngDec->msNewMinFlag, 0, NPART_SHAPING ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( hFdCngDec->msPsdFirstMoment_float, 0.0f, NPART_SHAPING ); set_f( hFdCngDec->msPsdSecondMoment_float, 0.0f, NPART_SHAPING ); +#endif + hFdCngDec->msPeriodogBufPtr = 0; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( hFdCngDec->msPeriodogBuf_float, 0.0f, MSBUFLEN * NPART_SHAPING ); set_f( hFdCngDec->msLogPeriodog_float, 0.0f, NPART_SHAPING ); set_f( hFdCngDec->msLogNoiseEst_float, 0.0f, NPART_SHAPING ); set_f( hFdCngDec->psize_shaping_float, 0.0f, NPART_SHAPING ); +#endif hFdCngDec->nFFTpart_shaping = 0; set_f( hFdCngDec->hFdCngCom->sidNoiseEstLp_flt, 0.0f, NPART ); - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( hFdCngDec->smoothed_psd, 0.0f, L_FRAME16k ); set_f( hFdCngDec->msPeriodog_ST, 0.0f, NPART_SHAPING ); +#endif hFdCngDec->ms_last_inactive_bwidth = NB; hFdCngDec->ms_cnt_bw_up = 0; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hFdCngDec->cna_LR_LT = 0.5f; hFdCngDec->cna_ILD_LT = 0.0f; +#endif hFdCngDec->first_cna_noise_updated = 0; hFdCngDec->first_cna_noise_update_cnt = 0; hFdCngDec->cna_nbands = CNA_INIT_NBANDS; mvs2s( cna_init_bands, hFdCngDec->cna_band_limits, CNA_INIT_NBANDS + 1 ); hFdCngDec->cna_act_fact = 1.0f; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hFdCngDec->cna_rescale_fact = 0.0f; +#endif hFdCngDec->cna_seed = 5687; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_zero( hFdCngDec->cna_cm, STEREO_DFT_BAND_MAX ); set_zero( hFdCngDec->cna_g_state, STEREO_DFT_BAND_MAX ); +#endif st->CNG_mode = -1; - mvr2r( st->lsp_old, st->lspCNG, M ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + mvr2r(st->lsp_old, st->lspCNG, M); +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) return; } - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*------------------------------------------------------------------- * configureFdCngDec_flt() * @@ -305,8 +320,9 @@ void configureFdCngDec_flt( hsCom->startBand = 2; hsCom->stopBand = hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions - 1] + 1; +#ifndef IVAS_FLOAT_FIXED initPartitions_flt( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize_flt, hsCom->psize_inv_flt, 0 ); -#ifdef IVAS_FLOAT_FIXED +#else // IVAS_FLOAT_FIXED initPartitions(hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0); #endif // IVAS_FLOAT_FIXED @@ -334,8 +350,9 @@ void configureFdCngDec_flt( { stopBandFR = hsCom->stopFFTbin; } +#ifndef IVAS_FLOAT_FIXED initPartitions_flt( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping_float, hFdCngDec->psize_inv_shaping_float, stopBandFR ); -#ifdef IVAS_FLOAT_FIXED +#else // IVAS_FLOAT_FIXED initPartitions( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping, hFdCngDec->psize_shaping_norm, &hFdCngDec->psize_shaping_norm_exp, hFdCngDec->psize_inv_shaping, stopBandFR ); #endif // IVAS_FLOAT_FIXED @@ -371,7 +388,7 @@ void configureFdCngDec_flt( return; } - +#endif #ifdef IVAS_FLOAT_FIXED void configureFdCngDec_fx( HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the FD-based CNG process */ @@ -518,9 +535,12 @@ void configureFdCngDec_fx( hsCom->startBand = 2; move16(); hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions - 1], 1 ); +#ifndef IVAS_FLOAT_FIXED /* remove floating point dependency */ initPartitions_flt( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize_flt, hsCom->psize_inv_flt, 0 ); +#else // IVAS_FLOAT_FIXED initPartitions(hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0); +#endif // IVAS_FLOAT_FIXED IF ( EQ_16( hsCom->stopFFTbin, 160 ) ) { @@ -541,7 +561,9 @@ void configureFdCngDec_fx( FOR ( j = 0; j < hsCom->nCLDFBpart; j++ ) { hsCom->CLDFBpart[j] = sub( hsCom->part[j + hsCom->nFFTpart], sub( hsCom->stopFFTbin, hsCom->startBand ) ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hsCom->CLDFBpsize_inv_flt[j] = hsCom->psize_inv_flt[j + hsCom->nFFTpart]; // TODO remove floating point dependency +#endif hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[j + hsCom->nFFTpart]; move16(); } @@ -554,9 +576,12 @@ void configureFdCngDec_fx( move16(); } +#ifdef IVAS_FLOAT_FIXED initPartitions( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping, hFdCngDec->psize_shaping_norm, &hFdCngDec->psize_shaping_norm_exp, hFdCngDec->psize_inv_shaping, stopBandFR ); +#else // IVAS_FLOAT_FIXED /* remove floating point dependency */ initPartitions_flt( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping_float, hFdCngDec->psize_inv_shaping_float, stopBandFR ); +#endif // IVAS_FLOAT_FIXED hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; move16(); @@ -570,12 +595,12 @@ void configureFdCngDec_fx( hsCom->olapWinAna_fx = olapWinAna512_fx; hsCom->fftSineTab_fx = NULL; hsCom->olapWinSyn_fx = olapWinSyn256_fx; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /* TODO: remove floating point dependency */ hsCom->fftSineTab_flt = NULL; hsCom->olapWinAna_flt = olapWinAna512; hsCom->olapWinSyn_flt = olapWinSyn256; - +#endif hsCom->fftlenShift = 8; move16(); hsCom->fftlenFac = 32767/*1.0 Q15*/; @@ -585,12 +610,12 @@ void configureFdCngDec_fx( hsCom->olapWinAna_fx = olapWinAna640_fx; hsCom->fftSineTab_fx = fftSineTab640_fx; hsCom->olapWinSyn_fx = olapWinSyn320_fx; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /* remove floating point dependency */ hsCom->fftSineTab_flt = fftSineTab640; hsCom->olapWinAna_flt = olapWinAna640; hsCom->olapWinSyn_flt = olapWinSyn320; - +#endif hsCom->fftlenShift = 9; move16(); hsCom->fftlenFac = 20480/*0.625 Q15*/; @@ -635,528 +660,256 @@ void deleteFdCngDec_flt( * * Apply the CLDFB-based CNG at the decoder *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void ApplyFdCng_flt( - float *timeDomainInput, - float *powerSpectrum, - float **realBuffer, /* i/o: Real part of the buffer */ - float **imagBuffer, /* i/o: Imaginary part of the buffer */ - Decoder_State *st, - const int16_t concealWholeFrame, - const int16_t is_music ) + float *timeDomainInput, + float *powerSpectrum, + float **realBuffer, /* i/o: Real part of the buffer */ + float **imagBuffer, /* i/o: Imaginary part of the buffer */ + Decoder_State *st, + const int16_t concealWholeFrame, + const int16_t is_music ) { - HANDLE_FD_CNG_DEC hFdCngDec = st->hFdCngDec; - HANDLE_FD_CNG_COM hFdCngCom = hFdCngDec->hFdCngCom; - float *cngNoiseLevel_flt = hFdCngCom->cngNoiseLevel_flt; - float *sidNoiseEst_flt = hFdCngCom->sidNoiseEst_flt; - int16_t j, k; - float factor; - float lsp_cng[M]; - int16_t L_frame, last_L_frame; - int32_t sr_core; - - push_wmops( "ApplyFdCng_flt" ); - - /* limit L_frame and core Fs values for MDCT-Stereo modes which can have higher core sampling than 16kHz, but use a downsampled buffer */ - L_frame = min( st->L_frame, L_FRAME16k ); - last_L_frame = min( st->last_L_frame, L_FRAME16k ); - sr_core = min( st->sr_core, INT_FS_16k ); - - if ( hFdCngCom->frame_type_previous == ACTIVE_FRAME ) - { - hFdCngCom->inactive_frame_counter = 0; - } - - if ( st->element_mode == IVAS_CPE_TD ) - { - hFdCngDec->flag_dtx_mode = hFdCngDec->flag_dtx_mode || st->first_CNG; - } - - switch ( st->m_frame_type ) - { - - case ACTIVE_FRAME: - /************************** - * ACTIVE_FRAME at DECODER * - **************************/ - - hFdCngCom->inactive_frame_counter = 0; - hFdCngCom->sid_frame_counter = 0; - /* set noise estimation inactive during concealment, as no update with noise generated by concealment should be performed. */ - /* set noise estimation inactive when we have bit errors, as no update with noise generated by corrupt frame (biterror) should be performed. */ - if ( concealWholeFrame == 0 && - ( timeDomainInput == NULL || - ( *timeDomainInput( -FLT_MAX ) && - *( timeDomainInput + hFdCngCom->frameSize - 1 ) < FLT_MAX && - *( timeDomainInput + hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) ) ) && - ( ( ( ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && hFdCngDec->flag_dtx_mode ) || !st->VAD || ( st->ini_frame < 100 && st->is_ism_format ) ) && - !( st->cng_type == LP_CNG && hFdCngDec->flag_dtx_mode ) && ( is_music == 0 ) ) || - ( st->element_mode == IVAS_CPE_TD ) ) && - ( !st->BER_detect ) ) - { - /* Perform noise estimation at the decoder */ -#ifdef IVAS_FLOAT_FIXED - Word16 timeDomainInput_fx[L_FRAME16k], q_tdi = 0; - Word32 powerSpectrum_fx[L_FRAME16k]; - if ( timeDomainInput != NULL ) - { - float max1 = 0.f; - for ( int p = 0; p < L_frame; p++ ) - { - if ( (float) fabs( (float) timeDomainInput[p] ) > max1 ) - max1 = (float) fabs( (float) timeDomainInput[p] ); - } - q_tdi = norm_s( (Word16) max1 ); - for ( int p = 0; p < L_frame; p++ ) - { - timeDomainInput_fx[p] = (Word16) ( timeDomainInput[p] * ( 1u << q_tdi ) ); - } - } - for ( int p = 0; p < L_frame; p++ ) - { - hFdCngDec->hFdCngCom->periodog[p] = (Word32) ( hFdCngDec->hFdCngCom->periodog_flt[p] * ( 1u << ( 31 - hFdCngDec->hFdCngCom->periodog_exp ) ) ); - } - if ( powerSpectrum != NULL ) - { - for ( int p = 0; p < L_FRAME16k; p++ ) - { - if ( powerSpectrum[p] <= (float) MAX_32 ) - { - powerSpectrum_fx[p] = (Word32) ( powerSpectrum[p] /** ( 1u << 0 )*/ ); - } - else - { - powerSpectrum_fx[p] = MAX_32; - } - } - } - for ( int p = 0; p < hFdCngDec->hFdCngCom->fftlen; p++ ) - { - hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32) ( hFdCngDec->hFdCngCom->fftBuffer_flt[p] * ( 1u << ( 31 - hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); - } - hFdCngDec->msNoiseEst_exp = 31 - Q4; - for ( int p = 0; p < NPART_SHAPING; p++ ) - { - hFdCngDec->msNoiseEst[p] = (Word32) ( hFdCngDec->msNoiseEst_float[p] * ( 1u << ( 31 - hFdCngDec->msNoiseEst_exp ) ) ); - hFdCngDec->msPeriodog_ST_fx[p] = (Word32) ( hFdCngDec->msPeriodog_ST[p] * ( 1u << ( 31 - hFdCngDec->msPeriodog_ST_exp ) ) ); - } - for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) - { - if ( ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << Q15 ) ) >= (float) MAX_32 ) - { - st->hFdCngDec->msMinBuf[p] = MAX_32; - } - else - { - st->hFdCngDec->msMinBuf[p] = (Word32) ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << ( 31 - 6 ) ) ); - } - } - - perform_noise_estimation_dec_fx( timeDomainInput_fx, q_tdi, powerSpectrum_fx, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); - - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) - { - for ( int p = 0; p < hFdCngDec->hFdCngCom->stopFFTbin - hFdCngDec->hFdCngCom->startBand; p++ ) - { - hFdCngDec->hFdCngCom->periodog_flt[p] = ( (float) hFdCngDec->hFdCngCom->periodog[p] / (float) ( 1u << ( 31 - hFdCngDec->hFdCngCom->periodog_exp ) ) ); - hFdCngDec->bandNoiseShape_float[p] = ( (float) hFdCngDec->bandNoiseShape[p] / ( 1u << ( 31 - hFdCngDec->msNoiseEst_exp ) ) ); - } - - for ( int p = 0; p < L_FRAME16k - hFdCngDec->hFdCngCom->startBand; p++ ) - { - hFdCngDec->smoothed_psd[hFdCngDec->hFdCngCom->startBand + p] = ( (float) hFdCngDec->smoothed_psd_fx[hFdCngDec->hFdCngCom->startBand + p] / ( 1u << ( 31 - hFdCngDec->msNoiseEst_exp ) ) ); - } - for ( int p = 0; p < hFdCngDec->npart_shaping; p++ ) - { - hFdCngDec->msPsd_float[p] = ( (float) hFdCngDec->msPsd_fx[p] / ( 1u << ( 31 - hFdCngDec->msNoiseEst_exp ) ) ); - } - } - for ( int p = 0; p < hFdCngDec->hFdCngCom->fftlen; p++ ) - { - hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ( (float) hFdCngDec->hFdCngCom->fftBuffer[p] / ( 1u << ( 31 - hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); - } - for ( int p = 0; p < hFdCngDec->npart_shaping; p++ ) - { - hFdCngDec->msNoiseEst_float[p] = ( (float) hFdCngDec->msNoiseEst[p] / ( 1u << ( 31 - hFdCngDec->msNoiseEst_exp ) ) ); - } - IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) - { - for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) - { - if ( ( st->hFdCngDec->msMinBuf[p] == MAX_32 ) ) - { - st->hFdCngDec->msMinBuf_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msMinBuf_float[p] = (float) st->hFdCngDec->msMinBuf[p] / ( 1u << ( 31 - 6 ) ); // CNG_S = 6 - } - } - for ( int p = 0; p < hFdCngDec->npart_shaping; p++ ) - { - hFdCngDec->msPsd_float[p] = ( (float) hFdCngDec->msPsd[p] / ( 1u << Q9 ) ); - hFdCngDec->msPeriodog_float[p] = ( (float) hFdCngDec->msPeriodog[p] / ( 1u << ( 31 - hFdCngDec->msPeriodog_exp ) ) ); - hFdCngDec->msPeriodogBuf_float[p] = ( (float) hFdCngDec->msPeriodogBuf[p] / ( 1u << Q9 ) ); - hFdCngDec->msPeriodog_ST[p] = ( (float) hFdCngDec->msPeriodog_ST_fx[p] / ( 1u << ( 31 - hFdCngDec->msPeriodog_ST_exp ) ) ); - hFdCngDec->msPsdFirstMoment_float[p] = ( (float) hFdCngDec->msPsdFirstMoment[p] / ( 1u << Q9 ) ); - hFdCngDec->msPsdSecondMoment_float[p] = ( (float) hFdCngDec->msPsdSecondMoment[p] / ( 1u << Q19 ) ); - hFdCngDec->msNoiseFloor_float[p] = ( (float) hFdCngDec->msNoiseFloor[p] / ( 1u << Q9 ) ); - hFdCngDec->msAlpha_float[p] = ( (float) hFdCngDec->msAlpha[p] / ( 1u << Q31 ) ); - hFdCngDec->msBminWin_float[p] = ( (float) hFdCngDec->msBminWin[p] / ( 1u << Q27 ) ); - hFdCngDec->msBminSubWin_float[p] = ( (float) hFdCngDec->msBminSubWin[p] / ( 1u << Q27 ) ); - if (st->hFdCngDec->msCurrentMin[p] == MAX_32) - { - st->hFdCngDec->msCurrentMin_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMin_float[p] = ((float)st->hFdCngDec->msCurrentMin[p] / (1u << (31 - (6 + 1 + 4)))); // exp : CNG_S + 1 + 4 - } - if (st->hFdCngDec->msCurrentMinOut[p] == MAX_32) - { - st->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinOut_float[p] = ((float)st->hFdCngDec->msCurrentMinOut[p] / (1u << (31 - 6))); - } - if (st->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32) - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = ((float)st->hFdCngDec->msCurrentMinSubWindow[p] / (1u << (31 - 6))); - } - } - } -#else - perform_noise_estimation_dec_flt( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); -#endif // IVAS_FLOAT_FIXED - - - if ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT ) - { - /* Update the shaping parameters */ - scalebands_flt( hFdCngDec->msNoiseEst_float, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngDec->bandNoiseShape_float, 1 ); - } - - /* Update CNG levels */ - if ( hFdCngDec->flag_dtx_mode && st->cng_type == FD_CNG ) - { - bandcombinepow_flt( hFdCngDec->bandNoiseShape_float, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngCom->part, hFdCngCom->nFFTpart, hFdCngCom->psize_inv_flt, hFdCngDec->partNoiseShape_float); /* This needs to be done only once per inactive phase */ - - j = 0; - for ( k = 0; k < hFdCngCom->nFFTpart; k++ ) - { - factor = ( hFdCngCom->sidNoiseEst_flt[k] + DELTA ) / ( hFdCngDec->partNoiseShape_float[k] + DELTA ); - for ( ; j <= hFdCngCom->part[k]; j++ ) - { - cngNoiseLevel_flt[j] = hFdCngDec->bandNoiseShape_float[j] * factor; - } - } - } - else - { - /* This sets the new CNG levels until a SID update overwrites it */ - if ( !( st->element_mode == IVAS_CPE_TD ) || ( st->element_mode == IVAS_CPE_TD && !hFdCngDec->flag_dtx_mode && !st->VAD ) ) - { - mvr2r( hFdCngDec->bandNoiseShape_float, cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ); /* This sets the new CNG levels until a SID update overwrites it */ - } - } - - if ( st->element_mode == IVAS_CPE_MDCT && timeDomainInput == NULL ) - { - st->hTcxDec->CngLevelBackgroundTrace_bfi = sqrtf( sum_f( cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / NORM_MDCT_FACTOR ); - } - else - { - st->hTcxDec->CngLevelBackgroundTrace_bfi = (float) sqrt( ( sum_f( cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame ); - } - st->cngTDLevel_float = (float) sqrt( ( sum_f( cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / st->L_frame ); - } - else if ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) - { - if ( hFdCngCom->active_frame_counter > 0 ) - { - /* Perform noise estimation in active frames in the decoder for downward updates */ -#ifdef IVAS_FLOAT_FIXED - Word16 timeDomainInput_fx[L_FRAME16k], q_tdi; - Word32 *powerSpectrum_fx = NULL; - float max1 = 0.f; - for ( int p = 0; p < L_frame; p++ ) - { - if ( (float) fabs( (double) timeDomainInput[p] ) > max1 ) - max1 = (float) fabs( (double) timeDomainInput[p] ); - } - q_tdi = norm_s( (Word16) max1 ); - for ( int p = 0; p < L_frame; p++ ) - { - timeDomainInput_fx[p] = (Word16) ( timeDomainInput[p] * ( 1u << q_tdi ) ); - hFdCngDec->hFdCngCom->periodog[p] = (Word32) ( hFdCngDec->hFdCngCom->periodog_flt[p] * ( 1u << ( 31 - hFdCngDec->hFdCngCom->periodog_exp ) ) ); - } - for ( int p = 0; p < hFdCngDec->hFdCngCom->fftlen; p++ ) - { - hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32) ( hFdCngDec->hFdCngCom->fftBuffer_flt[p] * ( 1u << ( 31 - hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); - } - hFdCngDec->msNoiseEst_exp = 31 - Q4; - for ( int p = 0; p < NPART_SHAPING; p++ ) - { - hFdCngDec->msNoiseEst[p] = (Word32) ( hFdCngDec->msNoiseEst_float[p] * (1u << (31 - hFdCngDec->msNoiseEst_exp))); - hFdCngDec->msPeriodog_ST_fx[p] = (Word32) ( hFdCngDec->msPeriodog_ST[p] * ( 1u << ( 31 - hFdCngDec->msPeriodog_ST_exp ) ) ); - } - - perform_noise_estimation_dec_fx( timeDomainInput_fx, q_tdi, powerSpectrum_fx, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); - - for ( int p = 0; p < hFdCngDec->hFdCngCom->stopFFTbin - hFdCngDec->hFdCngCom->startBand; p++ ) - { - hFdCngDec->hFdCngCom->periodog_flt[p] = ( (float) hFdCngDec->hFdCngCom->periodog[p] / (float) ( 1u << ( 31 - hFdCngDec->hFdCngCom->periodog_exp ) ) ); - hFdCngDec->bandNoiseShape_float[p] = ( (float) hFdCngDec->bandNoiseShape[p] / (1u << (31 - hFdCngDec->msNoiseEst_exp))); - } - - for ( int p = 0; p < L_FRAME16k - hFdCngDec->hFdCngCom->startBand; p++ ) - { - hFdCngDec->smoothed_psd[hFdCngDec->hFdCngCom->startBand + p] = ( (float) hFdCngDec->smoothed_psd_fx[hFdCngDec->hFdCngCom->startBand + p] / (1u << (31 - hFdCngDec->msNoiseEst_exp))); - } - for ( int p = 0; p < hFdCngDec->hFdCngCom->fftlen; p++ ) - { - hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ( (float) hFdCngDec->hFdCngCom->fftBuffer[p] / ( 1u << ( 31 - hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); - } - for ( int p = 0; p < hFdCngDec->npart_shaping; p++ ) - { - hFdCngDec->msNoiseEst_float[p] = ( (float) hFdCngDec->msNoiseEst[p] / (1u << (31 - hFdCngDec->msNoiseEst_exp))); - hFdCngDec->msPsd_float[p] = ( (float) hFdCngDec->msPsd_fx[p] / (1u << (31 - hFdCngDec->msNoiseEst_exp))); - hFdCngDec->msPeriodog_float[p] = ( (float) hFdCngDec->msPeriodog[p] / ( 1u << ( 31 - hFdCngDec->hFdCngCom->periodog_exp ) ) ); - hFdCngDec->msPeriodog_ST[p] = ( (float) hFdCngDec->msPeriodog_ST_fx[p] / ( 1u << ( 31 - hFdCngDec->msPeriodog_ST_exp ) ) ); - } -#else - perform_noise_estimation_dec_flt( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); -#endif // IVAS_FLOAT_FIXED - } - } - - if ( ( concealWholeFrame == 1 ) && ( st->nbLostCmpt == 1 ) ) - { - /* update lsf cng estimate for concealment. Do that during concealment, in order to avoid addition clean channel complexity*/ - - /* always set psychParameters for MDCT-Stereo ... */ - if ( st->element_mode == IVAS_CPE_MDCT && st->hTonalMDCTConc != NULL ) - { - st->hTonalMDCTConc->psychParams = ( st->core == TCX_20_CORE ) ? &st->hTonalMDCTConc->psychParamsTCX20 : &st->hTonalMDCTConc->psychParamsTCX10; - } - - /* ... but do actual computations only if sufficient energy in noise shape */ - if ( sum_f( cngNoiseLevel_flt + hFdCngCom->startBand, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) > 0.01f ) - { - if ( st->element_mode == IVAS_CPE_MDCT && st->core != ACELP_CORE ) - { -#ifdef IVAS_FLOAT_FIXED - hFdCngCom->cngNoiseLevelExp = 28; - for ( int p = 0; p < hFdCngCom->stopFFTbin - hFdCngCom->startBand; p++ ) - { - hFdCngCom->cngNoiseLevel[p] = (Word32) (cngNoiseLevel_flt[p] * ( 1u << ( 31 - hFdCngCom->cngNoiseLevelExp ) ) ); - } - - TonalMdctConceal_whiten_noise_shape_ivas_fx( st, L_frame, ON_FIRST_LOST_FRAME ); - - for (int p = 0; p < hFdCngCom->stopFFTbin - hFdCngCom->startBand; p++) - { - cngNoiseLevel_flt[p] = (float)hFdCngCom->cngNoiseLevel[p] / (1u << (31 - hFdCngCom->cngNoiseLevelExp)); - } - for ( int p = 0; p < FDNS_NPTS; p++ ) - { - st->hTonalMDCTConc->scaleFactorsBackground_flt[p] = (float) st->hTonalMDCTConc->scaleFactorsBackground_fx[p] / ONE_IN_Q16; - } -#else - TonalMdctConceal_whiten_noise_shape_ivas(st, L_frame, ON_FIRST_LOST_FRAME); -#endif // IVAS_FLOAT_FIXED - - } - else if ( st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE ) - { - lpc_from_spectrum_flt( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0.f ); - a2lsp_stab( hFdCngCom->A_cng_flt, lsp_cng, st->lspold_cng_float); - mvr2r( lsp_cng, st->lspold_cng_float, M ); - lsp2lsf( lsp_cng, st->lsf_cng_float, M, sr_core ); - } - st->plcBackgroundNoiseUpdated = 1; - } - } - break; - - case SID_FRAME: - hFdCngDec->flag_dtx_mode = 1; - /* FALLTHRU */ - - case ZERO_FRAME: - - if ( st != NULL && st->cng_type == LP_CNG ) - { - /* Perform noise estimation on inactive phase at the decoder */ -#ifdef IVAS_FLOAT_FIXED - Word16 timeDomainInput_fx[L_FRAME16k], q_tdi = 0; - Word32 powerSpectrum_fx[L_FRAME16k]; - if ( timeDomainInput != NULL ) - { - float max1 = 0.f; - for ( int p = 0; p < L_frame; p++ ) - { - if ( (float) fabs( (double) timeDomainInput[p] ) > max1 ) - max1 = (float) fabs( (double) timeDomainInput[p] ); - } - q_tdi = norm_s( (Word16) max1 ); - for ( int p = 0; p < L_frame; p++ ) - { - timeDomainInput_fx[p] = (Word16) ( timeDomainInput[p] * ( 1u << q_tdi ) ); - } - } - for ( int p = 0; p < L_frame; p++ ) - { - hFdCngDec->hFdCngCom->periodog[p] = (Word32) ( hFdCngDec->hFdCngCom->periodog_flt[p] * ( 1u << ( 31 - hFdCngDec->hFdCngCom->periodog_exp ) ) ); - } - if ( powerSpectrum != NULL ) - { - for ( int p = 0; p < L_FRAME16k; p++ ) - { - powerSpectrum_fx[p] = (Word32) ( powerSpectrum[p] * ( 1u << Q2 ) ); - } - } - for ( int p = 0; p < hFdCngDec->hFdCngCom->fftlen; p++ ) - { - hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32) ( hFdCngDec->hFdCngCom->fftBuffer_flt[p] * ( 1u << ( 31 - hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); - } - hFdCngDec->msNoiseEst_exp = 31 - Q4; - for ( int p = 0; p < NPART_SHAPING; p++ ) - { - hFdCngDec->msNoiseEst[p] = (Word32) ( hFdCngDec->msNoiseEst_float[p] * ( 1u << ( 31 - hFdCngDec->msNoiseEst_exp ) ) ); - hFdCngDec->msPeriodog_ST_fx[p] = (Word32) ( hFdCngDec->msPeriodog_ST[p] * ( 1u << ( 31 - hFdCngDec->msPeriodog_ST_exp ) ) ); - } - - perform_noise_estimation_dec_fx( timeDomainInput_fx, q_tdi, powerSpectrum_fx, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); - - for ( int p = 0; p < hFdCngDec->hFdCngCom->stopFFTbin - hFdCngDec->hFdCngCom->startBand; p++ ) - { - hFdCngDec->hFdCngCom->periodog_flt[p] = ( (float) hFdCngDec->hFdCngCom->periodog[p] / (float) ( 1u << ( 31 - hFdCngDec->hFdCngCom->periodog_exp ) ) ); - hFdCngDec->bandNoiseShape_float[p] = ( (float) hFdCngDec->bandNoiseShape[p] / ( 1u << ( 31 - hFdCngDec->msNoiseEst_exp ) ) ); - } - - for ( int p = 0; p < L_FRAME16k - hFdCngDec->hFdCngCom->startBand; p++ ) - { - hFdCngDec->smoothed_psd[hFdCngDec->hFdCngCom->startBand + p] = ( (float) hFdCngDec->smoothed_psd_fx[hFdCngDec->hFdCngCom->startBand + p] / ( 1u << ( 31 - hFdCngDec->msNoiseEst_exp ) ) ); - } - for ( int p = 0; p < hFdCngDec->hFdCngCom->fftlen; p++ ) - { - hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ( (float) hFdCngDec->hFdCngCom->fftBuffer[p] / ( 1u << ( 31 - hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); - } - for ( int p = 0; p < hFdCngDec->npart_shaping; p++ ) - { - hFdCngDec->msNoiseEst_float[p] = ( (float) hFdCngDec->msNoiseEst[p] / ( 1u << ( 31 - hFdCngDec->msNoiseEst_exp ) ) ); - hFdCngDec->msPsd_float[p] = ( (float) hFdCngDec->msPsd_fx[p] / ( 1u << ( 31 - hFdCngDec->msNoiseEst_exp ) ) ); - hFdCngDec->msPeriodog_float[p] = ( (float) hFdCngDec->msPeriodog[p] / ( 1u << ( 31 - hFdCngDec->hFdCngCom->periodog_exp ) ) ); - hFdCngDec->msPeriodog_ST[p] = ( (float) hFdCngDec->msPeriodog_ST_fx[p] / ( 1u << ( 31 - hFdCngDec->msPeriodog_ST_exp ) ) ); - } -#else - perform_noise_estimation_dec_flt( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); -#endif // IVAS_FLOAT_FIXED - - if ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT ) - { - /* Update the shaping parameters */ - scalebands_flt( hFdCngDec->msNoiseEst_float, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngDec->bandNoiseShape_float, 1 ); - } - - /* This sets the new CNG levels until a SID update overwrites it */ - mvr2r( hFdCngDec->bandNoiseShape_float, cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ); /* This sets the new CNG levels until a SID update overwrites it */ - - st->cngTDLevel_float = (float) sqrt( ( sum_f( cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame ); - break; - } - - hFdCngCom->inactive_frame_counter++; - - /************************************* - * SID_FRAME or ZERO_FRAME at DECODER * - *************************************/ - - /* Detect first non-active frame */ - if ( hFdCngCom->inactive_frame_counter == 1 ) - { - /* Compute the fine spectral structure of the comfort noise shape using the decoder-side noise estimates */ - bandcombinepow_flt( hFdCngDec->bandNoiseShape_float, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngCom->part, hFdCngCom->nFFTpart, hFdCngCom->psize_inv_flt, hFdCngDec->partNoiseShape_float); - - if ( st->element_mode == IVAS_CPE_DFT ) - { - mvr2r( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt, st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt, NPART ); - } - } - - if ( st->m_frame_type == SID_FRAME ) - { - if ( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) - { - /* At initialization, interpolate the bin/band-wise levels from the partition levels */ - scalebands_flt( sidNoiseEst_flt, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, cngNoiseLevel_flt, 1 ); - } - else - { - if ( st->element_mode == IVAS_CPE_DFT ) - { - sidNoiseEst_flt = hFdCngCom->sidNoiseEstLp_flt; - } - - /* Interpolate the CLDFB band levels from the SID (partition) levels */ - if ( hFdCngCom->regularStopBand > hFdCngCom->numCoreBands ) - { - scalebands_flt( sidNoiseEst_flt, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, cngNoiseLevel_flt, 0 ); - } - - - /* Shape the SID noise levels in each FFT bin */ - j = 0; - for ( k = 0; k < hFdCngCom->nFFTpart; k++ ) - { - factor = ( sidNoiseEst_flt[k] + DELTA ) / ( hFdCngDec->partNoiseShape_float[k] + DELTA ); - for ( ; j <= hFdCngCom->part[k]; j++ ) - { - cngNoiseLevel_flt[j] = hFdCngDec->bandNoiseShape_float[j] * factor; - } - } - } - } - else if ( st->element_mode == IVAS_CPE_DFT ) - { - if ( !( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) ) - { - sidNoiseEst_flt = hFdCngCom->sidNoiseEstLp_flt; - j = 0; - for ( k = 0; k < hFdCngCom->nFFTpart; k++ ) - { - factor = ( sidNoiseEst_flt[k] + DELTA ) / ( hFdCngDec->partNoiseShape_float[k] + DELTA ); - for ( ; j <= hFdCngCom->part[k]; j++ ) - { - cngNoiseLevel_flt[j] = hFdCngDec->bandNoiseShape_float[j] * factor; - } - } - } - } - if ( st->codec_mode == MODE2 ) - { - /* Generate comfort noise during SID or zero frames */ - generate_comfort_noise_dec_flt( realBuffer, imagBuffer, st, -1 ); - } - - break; - - default: - break; - } + HANDLE_FD_CNG_DEC hFdCngDec = st->hFdCngDec; + HANDLE_FD_CNG_COM hFdCngCom = hFdCngDec->hFdCngCom; + float *cngNoiseLevel_flt = hFdCngCom->cngNoiseLevel_flt; + float *sidNoiseEst_flt = hFdCngCom->sidNoiseEst_flt; + int16_t j, k; + float factor; + float lsp_cng[M]; + int16_t L_frame, last_L_frame; + int32_t sr_core; + + push_wmops( "ApplyFdCng_flt" ); + + /* limit L_frame and core Fs values for MDCT-Stereo modes which can have higher core sampling than 16kHz, but use a downsampled buffer */ + L_frame = min( st->L_frame, L_FRAME16k ); + last_L_frame = min( st->last_L_frame, L_FRAME16k ); + sr_core = min( st->sr_core, INT_FS_16k ); + + if ( hFdCngCom->frame_type_previous == ACTIVE_FRAME ) + { + hFdCngCom->inactive_frame_counter = 0; + } + + if ( st->element_mode == IVAS_CPE_TD ) + { + hFdCngDec->flag_dtx_mode = hFdCngDec->flag_dtx_mode || st->first_CNG; + } + + switch ( st->m_frame_type ) + { + + case ACTIVE_FRAME: + /************************** + * ACTIVE_FRAME at DECODER * + **************************/ + + hFdCngCom->inactive_frame_counter = 0; + hFdCngCom->sid_frame_counter = 0; + /* set noise estimation inactive during concealment, as no update with noise generated by concealment should be performed. */ + /* set noise estimation inactive when we have bit errors, as no update with noise generated by corrupt frame (biterror) should be performed. */ + if ( concealWholeFrame == 0 && + ( timeDomainInput == NULL || + ( *timeDomainInput( -FLT_MAX ) && + *( timeDomainInput + hFdCngCom->frameSize - 1 ) < FLT_MAX && + *( timeDomainInput + hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) ) ) && + ( ( ( ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && hFdCngDec->flag_dtx_mode ) || !st->VAD || ( st->ini_frame < 100 && st->is_ism_format ) ) && + !( st->cng_type == LP_CNG && hFdCngDec->flag_dtx_mode ) && ( is_music == 0 ) ) || + ( st->element_mode == IVAS_CPE_TD ) ) && + ( !st->BER_detect ) ) + { + /* Perform noise estimation at the decoder */ + perform_noise_estimation_dec_flt( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); + + if ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT ) + { + /* Update the shaping parameters */ + scalebands_flt( hFdCngDec->msNoiseEst_float, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngDec->bandNoiseShape_float, 1 ); + } + + /* Update CNG levels */ + if ( hFdCngDec->flag_dtx_mode && st->cng_type == FD_CNG ) + { + bandcombinepow_flt( hFdCngDec->bandNoiseShape_float, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngCom->part, hFdCngCom->nFFTpart, hFdCngCom->psize_inv_flt, hFdCngDec->partNoiseShape_float); /* This needs to be done only once per inactive phase */ + + j = 0; + for ( k = 0; k < hFdCngCom->nFFTpart; k++ ) + { + factor = ( hFdCngCom->sidNoiseEst_flt[k] + DELTA ) / ( hFdCngDec->partNoiseShape_float[k] + DELTA ); + for ( ; j <= hFdCngCom->part[k]; j++ ) + { + cngNoiseLevel_flt[j] = hFdCngDec->bandNoiseShape_float[j] * factor; + } + } + } + else + { + /* This sets the new CNG levels until a SID update overwrites it */ + if ( !( st->element_mode == IVAS_CPE_TD ) || ( st->element_mode == IVAS_CPE_TD && !hFdCngDec->flag_dtx_mode && !st->VAD ) ) + { + mvr2r( hFdCngDec->bandNoiseShape_float, cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ); /* This sets the new CNG levels until a SID update overwrites it */ + } + } + + if ( st->element_mode == IVAS_CPE_MDCT && timeDomainInput == NULL ) + { + st->hTcxDec->CngLevelBackgroundTrace_bfi = sqrtf( sum_f( cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / NORM_MDCT_FACTOR ); + } + else + { + st->hTcxDec->CngLevelBackgroundTrace_bfi = (float) sqrt( ( sum_f( cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame ); + } + st->cngTDLevel_float = (float) sqrt( ( sum_f( cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / st->L_frame ); + } + else if ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) + { + if ( hFdCngCom->active_frame_counter > 0 ) + { + /* Perform noise estimation in active frames in the decoder for downward updates */ + perform_noise_estimation_dec_flt( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); + } + } + + if ( ( concealWholeFrame == 1 ) && ( st->nbLostCmpt == 1 ) ) + { + /* update lsf cng estimate for concealment. Do that during concealment, in order to avoid addition clean channel complexity*/ + + /* always set psychParameters for MDCT-Stereo ... */ + if ( st->element_mode == IVAS_CPE_MDCT && st->hTonalMDCTConc != NULL ) + { + st->hTonalMDCTConc->psychParams = ( st->core == TCX_20_CORE ) ? &st->hTonalMDCTConc->psychParamsTCX20 : &st->hTonalMDCTConc->psychParamsTCX10; + } + + /* ... but do actual computations only if sufficient energy in noise shape */ + if ( sum_f( cngNoiseLevel_flt + hFdCngCom->startBand, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) > 0.01f ) + { + if ( st->element_mode == IVAS_CPE_MDCT && st->core != ACELP_CORE ) + { + TonalMdctConceal_whiten_noise_shape_ivas( st, L_frame, ON_FIRST_LOST_FRAME ); + } + else if ( st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE ) + { + lpc_from_spectrum_flt( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0.f ); + a2lsp_stab( hFdCngCom->A_cng_flt, lsp_cng, st->lspold_cng_float); + mvr2r( lsp_cng, st->lspold_cng_float, M ); + lsp2lsf( lsp_cng, st->lsf_cng_float, M, sr_core ); + } + st->plcBackgroundNoiseUpdated = 1; + } + } + break; + + case SID_FRAME: + hFdCngDec->flag_dtx_mode = 1; + /* FALLTHRU */ + + case ZERO_FRAME: + + if ( st != NULL && st->cng_type == LP_CNG ) + { + /* Perform noise estimation on inactive phase at the decoder */ + perform_noise_estimation_dec_flt( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); + + if ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT ) + { + /* Update the shaping parameters */ + scalebands_flt( hFdCngDec->msNoiseEst_float, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngDec->bandNoiseShape_float, 1 ); + } + + /* This sets the new CNG levels until a SID update overwrites it */ + mvr2r( hFdCngDec->bandNoiseShape_float, cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ); /* This sets the new CNG levels until a SID update overwrites it */ + + st->cngTDLevel_float = (float) sqrt( ( sum_f( cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame ); + break; + } + + hFdCngCom->inactive_frame_counter++; + + /************************************* + * SID_FRAME or ZERO_FRAME at DECODER * + *************************************/ + + /* Detect first non-active frame */ + if ( hFdCngCom->inactive_frame_counter == 1 ) + { + /* Compute the fine spectral structure of the comfort noise shape using the decoder-side noise estimates */ + bandcombinepow_flt( hFdCngDec->bandNoiseShape_float, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngCom->part, hFdCngCom->nFFTpart, hFdCngCom->psize_inv_flt, hFdCngDec->partNoiseShape_float); + + if ( st->element_mode == IVAS_CPE_DFT ) + { + mvr2r( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt, st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt, NPART ); + } + } + + if ( st->m_frame_type == SID_FRAME ) + { + if ( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) + { + /* At initialization, interpolate the bin/band-wise levels from the partition levels */ + scalebands_flt( sidNoiseEst_flt, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, cngNoiseLevel_flt, 1 ); + } + else + { + if ( st->element_mode == IVAS_CPE_DFT ) + { + sidNoiseEst_flt = hFdCngCom->sidNoiseEstLp_flt; + } + + /* Interpolate the CLDFB band levels from the SID (partition) levels */ + if ( hFdCngCom->regularStopBand > hFdCngCom->numCoreBands ) + { + scalebands_flt( sidNoiseEst_flt, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, cngNoiseLevel_flt, 0 ); + } + + + /* Shape the SID noise levels in each FFT bin */ + j = 0; + for ( k = 0; k < hFdCngCom->nFFTpart; k++ ) + { + factor = ( sidNoiseEst_flt[k] + DELTA ) / ( hFdCngDec->partNoiseShape_float[k] + DELTA ); + for ( ; j <= hFdCngCom->part[k]; j++ ) + { + cngNoiseLevel_flt[j] = hFdCngDec->bandNoiseShape_float[j] * factor; + } + } + } + } + else if ( st->element_mode == IVAS_CPE_DFT ) + { + if ( !( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) ) + { + sidNoiseEst_flt = hFdCngCom->sidNoiseEstLp_flt; + j = 0; + for ( k = 0; k < hFdCngCom->nFFTpart; k++ ) + { + factor = ( sidNoiseEst_flt[k] + DELTA ) / ( hFdCngDec->partNoiseShape_float[k] + DELTA ); + for ( ; j <= hFdCngCom->part[k]; j++ ) + { + cngNoiseLevel_flt[j] = hFdCngDec->bandNoiseShape_float[j] * factor; + } + } + } + } + if ( st->codec_mode == MODE2 ) + { + /* Generate comfort noise during SID or zero frames */ + generate_comfort_noise_dec_flt( realBuffer, imagBuffer, st, -1 ); + } + + break; + + default: + break; + } + + pop_wmops(); + + return; +} - pop_wmops(); - return; -} -#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * perform_noise_estimation_dec_flt() * @@ -1501,14 +1254,14 @@ static void perform_noise_estimation_dec_flt( return; } -#endif // IVAS_FLOAT_FIXED +#endif /*------------------------------------------------------------------- * FdCng_decodeSID_flt() * * Decode the FD-CNG bitstream *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void FdCng_decodeSID_flt( Decoder_State *st /* i/o: decoder state structure */ ) @@ -1583,7 +1336,7 @@ void FdCng_decodeSID_flt( return; } - +#endif #ifdef IVAS_FLOAT_FIXED @@ -1692,7 +1445,7 @@ void FdCng_decodeSID_ivas_fx( * * *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void noisy_speech_detection_flt( HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure */ const int16_t vad, /* i : VAD flag */ @@ -1722,14 +1475,14 @@ void noisy_speech_detection_flt( return; } - +#endif /*------------------------------------------------------------------- * generate_comfort_noise_dec_flt() * * Generate the comfort noise based on the target noise level *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void generate_comfort_noise_dec_flt( float **bufferReal, /* o : Real part of input bands */ float **bufferImag, /* o : Imaginary part of input bands */ @@ -1841,30 +1594,8 @@ void generate_comfort_noise_dec_flt( } /* Perform STFT synthesis */ -#ifndef IVAS_FLOAT_FIXED SynthesisSTFT_flt( fftBuffer, timeDomainOutput, hFdCngCom->olapBufferSynth_flt, hFdCngCom->olapWinSyn_flt, tcx_transition, hFdCngCom, st->element_mode, nchan_out ); -#else - Word32 fftBuffer_fx[FFTLEN], timeDomainBuffer_fx[L_FRAME16k]; - Word16 exp = Q14; - for ( i = 0; i < hFdCngCom->fftlen; i++ ) - { - fftBuffer_fx[i] = float_to_fix( fftBuffer[i], exp ); - } - for ( i = 0; i < hFdCngCom->fftlen; i++ ) - { - hFdCngCom->olapBufferSynth_fx[i] = float_to_fix( hFdCngCom->olapBufferSynth_flt[i], exp ); - } - SynthesisSTFT_fx( fftBuffer_fx, exp, timeDomainBuffer_fx, hFdCngCom->olapBufferSynth_fx, hFdCngCom->olapWinSyn_fx, tcx_transition, hFdCngCom, st->element_mode, nchan_out ); - for ( i = 0; i < hFdCngCom->fftlen; i++ ) - { - hFdCngCom->olapBufferSynth_flt[i] = fix_to_float( hFdCngCom->olapBufferSynth_fx[i], exp ); - } - exp = exp - 9; - for ( i = 0; i < hFdCngCom->frameSize; i++ ) - { - timeDomainOutput[i] = fix_to_float( timeDomainBuffer_fx[i], exp ); - } -#endif + /* update CNG excitation energy for LP_CNG */ /* calculate the residual signal energy */ @@ -2012,8 +1743,8 @@ void generate_comfort_noise_dec_flt( return; } - - +#endif +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*------------------------------------------------------------------- * generate_comfort_noise_dec_hf_flt() * @@ -2086,7 +1817,7 @@ void generate_comfort_noise_dec_hf_flt( return; } - +#endif /*------------------------------------------------------------------- * generate_masking_noise_flt() @@ -3741,8 +3472,7 @@ void FdCngDecodeMDCTStereoSID_fx( return; } -#endif - +#else void FdCngDecodeMDCTStereoSID( CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */ ) @@ -3759,26 +3489,8 @@ void FdCngDecodeMDCTStereoSID( float *invTrfMatrix; float tmpRAM[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC]; -#ifdef IVAS_FLOAT_FIXED - Word32 *invTrfMatrix_fx; - Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC]; -#endif - invTrfMatrix = (float *) tmpRAM; -#ifdef IVAS_FLOAT_FIXED - invTrfMatrix_fx = (Word32 *)tmpRAM_fx; - create_IDCT_N_Matrix_fx(invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof(tmpRAM_fx) / (sizeof(Word32))); - - FOR( i = 0; i < FDCNG_VQ_MAX_LEN; i++) { - FOR(Word16 j = 0; j < FDCNG_VQ_DCT_MAXTRUNC; j++) { - Word16 index = i * FDCNG_VQ_DCT_MAXTRUNC + j; - invTrfMatrix[index] = fix_to_float(invTrfMatrix_fx[index], 31); // Q factor 31 - } - } - -#else create_IDCT_N_Matrix( invTrfMatrix, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM ) / ( sizeof( float ) ) ); -#endif is_out_ms = 0; if ( hCPE->hCoreCoder[0]->cng_sba_flag ) @@ -3861,6 +3573,7 @@ void FdCngDecodeMDCTStereoSID( return; } +#endif /*------------------------------------------------------------------- @@ -3972,11 +3685,6 @@ void FdCngDecodeDiracMDCTStereoSID_fx( lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac ); } - - /* TODO: remove the floating point dependency */ - sts[0]->hFdCngDec->hFdCngCom->coherence_flt = 0.0f; - sts[1]->hFdCngDec->hFdCngCom->coherence_flt = 0.0f; - sts[0]->hFdCngDec->hFdCngCom->coherence_fx = 0; move16(); sts[1]->hFdCngDec->hFdCngCom->coherence_fx = 0; @@ -4008,8 +3716,7 @@ void FdCngDecodeDiracMDCTStereoSID_fx( return; } -#endif - +#else void FdCngDecodeDiracMDCTStereoSID( CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */ ) @@ -4091,3 +3798,4 @@ void FdCngDecodeDiracMDCTStereoSID( return; } +#endif diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 1970f0eedcbfd495c387ac0ec0935a136333c3bc..77e8728668ada32a7726f7bff32058c3c74b3d71 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -111,6 +111,7 @@ void ivas_initFdCngDec_fx( set32_fx( hFdCngDec->msBminSubWin, 0, NPART_SHAPING ); set16_fx( hFdCngDec->msPsd, 0, NPART_SHAPING ); + set32_fx( hFdCngDec->msPsd_fx, 0, NPART_SHAPING ); set16_fx( hFdCngDec->msNoiseFloor, 0, NPART_SHAPING ); set32_fx( hFdCngDec->msNoiseEst, 0, NPART_SHAPING ); @@ -226,6 +227,7 @@ void initFdCngDec( set32_fx( hFdCngDec->msBminSubWin, 0, NPART_SHAPING ); set16_fx( hFdCngDec->msPsd, 0, NPART_SHAPING ); + set32_fx( hFdCngDec->msPsd_fx, 0, NPART_SHAPING ); set16_fx( hFdCngDec->msNoiseFloor, 0, NPART_SHAPING ); set32_fx( hFdCngDec->msNoiseEst, 0, NPART_SHAPING ); @@ -1174,6 +1176,7 @@ Word16 ApplyFdCng_fx( Word16 *timeDomainInput, /* i : pointer to time domain input */ Word16 Q, Word32 *powerSpectrum, + Word16 Q_power_spectrum, Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ @@ -1264,7 +1267,7 @@ Word16 ApplyFdCng_fx( ( !st->BER_detect ) ) { /* Perform noise estimation at the decoder */ - perform_noise_estimation_dec_fx( timeDomainInput, Q, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); + perform_noise_estimation_dec_fx( timeDomainInput, Q, powerSpectrum, Q_power_spectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); /* Update the shaping parameters */ test(); @@ -1380,7 +1383,7 @@ Word16 ApplyFdCng_fx( IF( ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && timeDomainInput == NULL ) ) { - // st->hTcxDec->CngLevelBackgroundTrace_bfi = sqrtf(sum_f(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / NORM_MDCT_FACTOR); + //st->hTcxDec->CngLevelBackgroundTrace_bfi = sqrtf(sum_f(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / NORM_MDCT_FACTOR); tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); L_tmp = L_deposit_h( 0 ); @@ -1429,7 +1432,7 @@ Word16 ApplyFdCng_fx( } ELSE { - // st->hTcxDec->CngLevelBackgroundTrace_bfi = (float)sqrt((sum_f(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / L_frame); + //st->hTcxDec->CngLevelBackgroundTrace_bfi = (float)sqrt((sum_f(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / L_frame); tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); L_tmp = L_deposit_h( 0 ); @@ -1526,7 +1529,7 @@ Word16 ApplyFdCng_fx( IF( hFdCngCom->active_frame_counter > 0 ) { /* Perform noise estimation in active frames in the decoder for downward updates */ - perform_noise_estimation_dec_fx( timeDomainInput, Q, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); + perform_noise_estimation_dec_fx( timeDomainInput, Q, powerSpectrum, Q_power_spectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); } } test(); @@ -1585,7 +1588,7 @@ Word16 ApplyFdCng_fx( IF( st != NULL && EQ_16( st->cng_type, LP_CNG ) ) { /* Perform noise estimation on inactive phase at the decoder */ - perform_noise_estimation_dec_fx( timeDomainInput, Q, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); + perform_noise_estimation_dec_fx( timeDomainInput, Q, powerSpectrum, Q_power_spectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); /* Update the shaping parameters */ @@ -2330,6 +2333,7 @@ void perform_noise_estimation_dec_fx( const Word16 *timeDomainInput, /* i: pointer to time domain input */ const Word16 Q, Word32 *power_spectrum, + Word16 Q_power_spectrum, HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure containing all buffers and variables */ const Word16 element_mode, /* i : element mode */ const Word16 bwidth, /* i : audio bandwidth */ @@ -2791,7 +2795,7 @@ void perform_noise_estimation_dec_fx( { /* use power spectrum calculated in the MDCT-domain instead of calculating new power spectrum */ periodog = power_spectrum; - periodog_exp = 31; + periodog_exp = 31 - Q_power_spectrum; } ELSE { diff --git a/lib_dec/gs_dec.c b/lib_dec/gs_dec.c index bec4c17d269f9eb2d207720c4e5994b841d5e409..140241660b96e3b78c309f5a41a4bbcacaf89f42 100644 --- a/lib_dec/gs_dec.c +++ b/lib_dec/gs_dec.c @@ -48,7 +48,7 @@ * * Decode audio (AC) frames *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void decod_audio( Decoder_State *st, /* i/o: decoder static memory */ float dct_epit[], /* o : GSC excitation in DCT domain */ @@ -453,7 +453,6 @@ void decod_audio( return; } - /*-------------------------------------------------------------------* * gsc_dec() * @@ -725,3 +724,4 @@ void GSC_dec_init_ivas( return; } +#endif diff --git a/lib_dec/hf_synth.c b/lib_dec/hf_synth.c index 7af1f829174f0f4ccf472812f750ea64b317f9c9..25f94331caeec4e912d7cdaf0a7ad727b7bac9e4 100644 --- a/lib_dec/hf_synth.c +++ b/lib_dec/hf_synth.c @@ -63,6 +63,7 @@ static void envelope( AMRWB_IO_DEC_HANDLE hAmrwb_IO, const int32_t core_brate, c static void AdaptiveStartBand( int16_t *start_band, const int32_t core_brate, const float *lsf, const float voicing_fac, const int16_t clas, int16_t *voicing_flag, int16_t *start_band_old, float *OptCrit_old ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * hf_synth_init() * @@ -88,6 +89,8 @@ void hf_synth_init( return; } +#endif + /*-------------------------------------------------------------------* * hf_synth_amr_wb_init() * @@ -116,6 +119,7 @@ void hf_synth_amr_wb_init( return; } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * hf_synth_amr_wb_reset() * @@ -476,7 +480,7 @@ void hf_synth_amr_wb( return; } - +#endif /*-----------------------------------------------------------------------------------* * hf_synthesis_amr_wb() * @@ -878,6 +882,7 @@ static void AdaptiveStartBand( } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * hf_synth_reset() * @@ -1067,6 +1072,7 @@ static void hf_synthesis( return; } +#endif /*-----------------------------------------------------------------------* * hp400_12k8() diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index 011e0006edd581544df47c160f1d563e820d2e67..82b515c144c12e381c6dc74613c68654255174d7 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -61,6 +61,27 @@ void hf_synth_init_fx( return; } + +void hf_synth_reset_fx( + ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ +) +{ + Word16 i; + + FOR(i = 0; i < L_FRAME16k; i++) + { + Random(&hBWE_zero->seed2); + } + + set16_fx(hBWE_zero->mem_hf_fx, 0, ( L_FIR - 1 ) ); + set16_fx(hBWE_zero->mem_syn_hf_fx, 0, M); + set16_fx(hBWE_zero->mem_hp400_fx, 0, 6); + + set16_fx(hBWE_zero->delay_syn_hf_fx, 0, NS2SA(16000, DELAY_CLDFB_NS)); + set16_fx(hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN); + + return; +} #else void hf_synth_init_fx( ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ @@ -76,7 +97,6 @@ void hf_synth_init_fx( return; } -#endif void hf_synth_reset_fx( ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ ) @@ -97,6 +117,7 @@ void hf_synth_reset_fx( return; } +#endif /*---------------------------------------------------------------------* * hf_synth() diff --git a/lib_dec/hq_core_dec.c b/lib_dec/hq_core_dec.c index c3d58e470e2e495be4f543256d55e634a6eaafa5..bbb7d817491a40fbdb4329ad108633ef412ee429 100644 --- a/lib_dec/hq_core_dec.c +++ b/lib_dec/hq_core_dec.c @@ -54,7 +54,7 @@ * * HQ core decoder *--------------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void hq_core_dec( Decoder_State *st, /* i/o: decoder state structure */ float synth[], /* o : output synthesis */ @@ -642,7 +642,7 @@ void hq_core_dec( pop_wmops(); return; } - +#endif /*-------------------------------------------------------------------* * hq_core_dec_init() @@ -666,7 +666,9 @@ void HQ_core_dec_init_flt( hHQ_core->oldHqVoicing = 0; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( hHQ_core->prev_noise_level, 0.0f, 2 ); +#endif hHQ_core->prev_R = 0; set_f( hHQ_core->prev_coeff_out, 0, L_HQ_WB_BWE ); set_s( hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); @@ -682,41 +684,55 @@ void HQ_core_dec_init_flt( hHQ_core->HqVoicing = 0; set_f( hHQ_core->fer_samples, 0, L_FRAME48k ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( hHQ_core->prev_env, 0, SFM_N_WB ); set_f( hHQ_core->prev_normq, 0, SFM_N_WB ); +#endif hHQ_core->prev_hqswb_clas = HQ_NORMAL; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( hHQ_core->last_ni_gain, 0, BANDS_MAX ); - set_f( hHQ_core->last_env, 0, BANDS_MAX ); + set_f( hHQ_core->last_env, 0, BANDS_MAX ); +#endif hHQ_core->last_max_pos_pulse = 0; hHQ_core->prev_frm_hfe2 = 0; hHQ_core->prev_stab_hfe2 = 0; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hHQ_core->prev_ni_ratio = 0.5f; set_f( hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS ); +#endif /*----------------------------------------------------------------------------------* * HQ FEC *----------------------------------------------------------------------------------*/ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( hHQ_core->X_sav, 0.0f, PH_ECU_SPEC_SIZE ); - hHQ_core->num_p = 0; +#endif + hHQ_core->num_p = 0; hHQ_core->ph_ecu_active = 0; hHQ_core->ni_seed_forfec = 0; hHQ_core->last_fec = 0; hHQ_core->ph_ecu_HqVoicing = 0; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( hHQ_core->oldgapsynth, 0.0f, L_FRAME48k ); hHQ_core->env_stab = 0.75f; +#endif hHQ_core->mem_norm_hqfec[0] = 31; set_s( hHQ_core->mem_norm_hqfec + 1, 39, SFM_N_ENV_STAB - 1 ); hHQ_core->mem_env_delta_hqfec = 0; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hHQ_core->env_stab_plc = 0.0f; set_f( hHQ_core->env_stab_state_p, 1.0f / NUM_ENV_STAB_PLC_STATES, NUM_ENV_STAB_PLC_STATES ); - hHQ_core->envstabplc_hocnt = 0; +#endif + hHQ_core->envstabplc_hocnt = 0; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( hHQ_core->mag_chg_1st, 1.0f, LGW_MAX ); set_f( hHQ_core->Xavg, 0.0f, LGW_MAX ); hHQ_core->beta_mute = BETA_MUTE_FAC_INI_FLT; +#endif hHQ_core->time_offs = 0; hHQ_core->ber_occured_in_pvq = 0; @@ -728,6 +744,7 @@ void HQ_core_dec_init_flt( return; } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * HQ_nbfec_init_flt() * @@ -776,3 +793,4 @@ void HQ_nbfec_init_flt( return; } +#endif diff --git a/lib_dec/hq_hr_dec.c b/lib_dec/hq_hr_dec.c index bd15037103c75c76029b59b349ebfc073abc27cc..4ecdfb91462b0734a935c23bc332cddacaf9bc8b 100644 --- a/lib_dec/hq_hr_dec.c +++ b/lib_dec/hq_hr_dec.c @@ -40,7 +40,7 @@ #include "rom_com.h" #include "prot.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*--------------------------------------------------------------------------* * hq_pred_hb_bws() * @@ -298,3 +298,4 @@ void hq_hr_dec( return; } +#endif diff --git a/lib_dec/hq_lr_dec.c b/lib_dec/hq_lr_dec.c index 1811a9baa87c293b54c16ebe7461144247ffef26..90b5d0f05e5462e98edfd254a87cb9c21fd5eb62 100644 --- a/lib_dec/hq_lr_dec.c +++ b/lib_dec/hq_lr_dec.c @@ -63,7 +63,7 @@ static void spt_shorten_domain_set_dec( Decoder_State *st, const int16_t p2a_fla * * HQ low rate decoding routine *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void hq_lr_dec( Decoder_State *st, /* i/o: decoder state structure */ float yout[], /* o : transform-domain output coefs. */ @@ -946,7 +946,7 @@ void hq_lr_dec( return; } - +#endif /*------------------------------------------------------------------------------------ * small_symbol_dec_tran() diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c index 609a82bc120e5a5845f54188251a089a4460a7af..4092bc41856f3970af99af2c20c6e298dbf408dd 100644 --- a/lib_dec/init_dec.c +++ b/lib_dec/init_dec.c @@ -411,14 +411,6 @@ ivas_error init_decoder( } td_bwe_dec_init( st->hBWE_TD, st->extl, st->output_Fs ); - -#ifdef IVAS_FLOAT_FIXED - td_bwe_dec_init_fx(st, st->hBWE_TD, -#ifdef ADD_IVAS_BWE - st->extl,//not needed -#endif - st->output_Fs); -#endif } else { @@ -815,12 +807,14 @@ void reset_preecho_dec( HQ_DEC_HANDLE hHQ_core /* i/o: HQ decoder handle */ ) { +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hHQ_core->memfilt_lb = 0; hHQ_core->mean_prev_hb = 0; hHQ_core->smoothmem = 1; hHQ_core->mean_prev = 0; hHQ_core->mean_prev_nc = 0; hHQ_core->wmold_hb = 1; +#endif hHQ_core->prevflag = 0; hHQ_core->pastpre = 0; @@ -833,6 +827,22 @@ void reset_preecho_dec( * * Free memory which was allocated in init_decoder() *----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void destroy_cldfb_decoder_ivas_fx( + Decoder_State *st /* o : Decoder static variables structure */ +) +{ + /* CLDFB BPF & resampling tools */ + deleteCldfb_ivas_fx( &st->cldfbAna ); /* delete analysis at max. sampling rate 48kHz */ + deleteCldfb_ivas_fx( &st->cldfbBPF ); /* delete analysis BPF at max. internal sampling rate 16kHz */ + deleteCldfb_ivas_fx( &st->cldfbSyn ); /* delete synthesis at output sampling rate */ + deleteCldfb_ivas_fx( &st->cldfbSynHB ); + + deleteFdCngDec( &st->hFdCngDec ); + + return; +} +#endif // IVAS_FLOAT_FIXED void destroy_cldfb_decoder_flt( Decoder_State *st /* o : Decoder static variables structure */ diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index d5bf467b1c9e6253a8c84397dabe1fed2f4ce55e..302c87efbf8dbf93b1812b034b10bb33651a604a 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -910,15 +910,15 @@ ivas_error init_decoder_ivas_fx( /* LSF initilaizations */ #ifdef ISM_DISABLE // Remove once fixed version is present. - if ( st_fx->ivas_format != ISM_FORMAT ) - { - mvr2r(GEWB_Ave, st_fx->mem_AR, M); - - set_f(st_fx->mem_MA, 0, M); - set_f(st_fx->dispMem, 0, 8); - st_fx->tilt_code = 0.0f; - st_fx->gc_threshold = 0.0f; - } + // if ( st_fx->ivas_format != ISM_FORMAT ) + // { + //mvr2r(GEWB_Ave, st_fx->mem_AR, M); + + //set_f(st_fx->mem_MA, 0, M); + //set_f(st_fx->dispMem, 0, 8); + //st_fx->tilt_code = 0.0f; + //st_fx->gc_threshold = 0.0f; + //} #endif Copy(GEWB_Ave_fx, st_fx->mem_AR_fx, M); @@ -952,13 +952,13 @@ ivas_error init_decoder_ivas_fx( st_fx->last_low_rate_mode = 0; /* low-rate mode flag */ #ifdef ISM_DISABLE // Remove once fixed version is present. - if ( st_fx->ivas_format != ISM_FORMAT ) - { - st_fx->lp_gainp = 0.0f; - st_fx->lp_gainc = 0.0f; + //if ( st_fx->ivas_format != ISM_FORMAT ) + //{ + //st_fx->lp_gainp = 0.0f; + //st_fx->lp_gainc = 0.0f; //set_f(st_fx->old_exc, 0, L_EXC_MEM_DEC); - } + //} #endif st_fx->lp_gainp_fx = 0; @@ -969,7 +969,7 @@ ivas_error init_decoder_ivas_fx( set16_fx(st_fx->old_exc_fx, 0, L_EXC_MEM_DEC); //++To be removed -#ifdef IVAS_FLOAT_FIXED +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) mvr2r( GEWB_Ave, st_fx->lsf_old, M ); lsf2lsp( st_fx->lsf_old, st_fx->lsp_old, M, INT_FS_12k8 ); #endif//IVAS_FLOAT_FIXED @@ -984,17 +984,20 @@ ivas_error init_decoder_ivas_fx( st_fx->last_code_preq = 0; st_fx->use_acelp_preq = 0; - st_fx->mem_deemph = 0.0f; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + st_fx->stab_fac = 0.0f; + st_fx->mem_deemph = 0.0f; set_f(st_fx->mem_syn1, 0, M); set_f(st_fx->mem_syn2, 0, M); - st_fx->stab_fac = 0.0f; - st_fx->stab_fac_smooth = 0.0f; - set_f(st_fx->agc_mem2, 0, 2); - set_f(st_fx->mem_syn3, 0, M); - st_fx->stab_fac_smooth_lt = 0.0f; - st_fx->log_energy_diff_lt = 0.0f; - st_fx->log_energy_old = 0.0f; + st_fx->stab_fac_smooth = 0.0f; + set_f(st_fx->agc_mem2, 0, 2); + set_f(st_fx->mem_syn3, 0, M); +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + + //st_fx->stab_fac_smooth_lt = 0.0f; + //st_fx->log_energy_diff_lt = 0.0f; + //st_fx->log_energy_old = 0.0f; // mvr2r(GEWB_Ave, st_fx->lsf_old, M); // lsf2lsp(st_fx->lsf_old, st_fx->lsp_old, M, INT_FS_12k8); @@ -1040,28 +1043,28 @@ ivas_error init_decoder_ivas_fx( { /* FEC */ st_fx->scaling_flag = 0; - st_fx->lp_ener_FEC_av_float = 5.0e5f; - st_fx->lp_ener_FEC_max_float = 5.0e5f; + //st_fx->lp_ener_FEC_av_float = 5.0e5f; + //st_fx->lp_ener_FEC_max_float = 5.0e5f; st_fx->prev_bfi = 0; - st_fx->lp_ener_bfi = 60.0f; - st_fx->old_enr_LP_float = 0.0f; - st_fx->lp_ener = 0.0f; - st_fx->enr_old = 0.0f; - st_fx->bfi_pitch = (float)L_SUBFR; + //st_fx->lp_ener_bfi = 60.0f; + //st_fx->old_enr_LP_float = 0.0f; + //st_fx->lp_ener = 0.0f; + //st_fx->enr_old = 0.0f; + //st_fx->bfi_pitch = (float)L_SUBFR; st_fx->bfi_pitch_frame = L_FRAME; - set_f(st_fx->mem_syn_clas_estim, 0.0f, L_SYN_MEM_CLAS_ESTIM); + //set_f(st_fx->mem_syn_clas_estim, 0.0f, L_SYN_MEM_CLAS_ESTIM); st_fx->last_con_tcx = 0; - for (i = 0; i < 2 * NB_SUBFR16k; i++) - { - st_fx->old_pitch_buf[i] = (float)L_SUBFR; - } + //for (i = 0; i < 2 * NB_SUBFR16k; i++) + //{ + // st_fx->old_pitch_buf[i] = (float)L_SUBFR; + //} st_fx->upd_cnt = MAX_UPD_CNT; - mvr2r(GEWB_Ave, st_fx->lsfoldbfi0, M); - mvr2r(GEWB_Ave, st_fx->lsfoldbfi1, M); - mvr2r(GEWB_Ave, st_fx->lsf_adaptive_mean, M); + //mvr2r(GEWB_Ave, st_fx->lsfoldbfi0, M); + //mvr2r(GEWB_Ave, st_fx->lsfoldbfi1, M); + //mvr2r(GEWB_Ave, st_fx->lsf_adaptive_mean, M); st_fx->seed_acelp = RANDOM_INITSEED; st_fx->seed = RANDOM_INITSEED; @@ -1121,24 +1124,24 @@ ivas_error init_decoder_ivas_fx( if ( st_fx->ivas_format != ISM_FORMAT ) { st_fx->unv_cnt = 0; - st_fx->ge_sm = 10; + //st_fx->ge_sm = 10; st_fx->uv_count = 0; st_fx->act_count = 3; - mvr2r(st_fx->lsp_old, st_fx->lspold_s, M); + //mvr2r(st_fx->lsp_old, st_fx->lspold_s, M); st_fx->noimix_seed = RANDOM_INITSEED; - st_fx->exc_pe = 0; + //st_fx->exc_pe = 0; st_fx->prev_coder_type = GENERIC; - st_fx->tilt_wb = 0.0f; + //st_fx->tilt_wb = 0.0f; - st_fx->last_voice_factor = 0.0f; + //st_fx->last_voice_factor = 0.0f; set_f(st_fx->prev_synth_buffer, 0, NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS)); st_fx->old_bfi_cnt = 0; } #endif - st_fx->min_alpha = 1; + //st_fx->min_alpha = 1; st_fx->unv_cnt = 0; move16(); st_fx->ge_sm_fx = L_deposit_l(640); /*Q(GE_SHIFT)*/ @@ -1193,10 +1196,12 @@ ivas_error init_decoder_ivas_fx( return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n")); } #ifdef ISM_DISABLE // To be removed when fixed version is available. +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if ( st_fx->ivas_format != ISM_FORMAT ) { GSC_dec_init_ivas(st_fx->hGSCDec); } +#endif #endif GSC_dec_init_ivas_fx(st_fx->hGSCDec); } @@ -1216,11 +1221,13 @@ ivas_error init_decoder_ivas_fx( return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FEC WI\n")); } #ifdef ISM_DISABLE // To be removed when fixed version is available. +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if ( st_fx->ivas_format != ISM_FORMAT ) { set_f(st_fx->hWIDec->old_exc2, 0, L_EXC_MEM); set_f(st_fx->hWIDec->old_syn2, 0, L_EXC_MEM); } +#endif #endif set16_fx(st_fx->hWIDec->old_exc2_fx, 0, L_EXC_MEM); set16_fx(st_fx->hWIDec->old_syn2_fx, 0, L_EXC_MEM); @@ -1241,7 +1248,7 @@ ivas_error init_decoder_ivas_fx( return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n")); } -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) Init_post_filter_ivas(st_fx->hPFstat); st_fx->psf_lp_noise = 0.0f; #endif @@ -1264,9 +1271,6 @@ ivas_error init_decoder_ivas_fx( return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for zero BWE\n")); } -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. - hf_synth_init(st_fx->hBWE_zero); -#endif hf_synth_init_fx(st_fx->hBWE_zero); } ELSE @@ -1328,19 +1332,7 @@ ivas_error init_decoder_ivas_fx( } #ifdef IVAS_FLOAT_FIXED -#if 1 // Float To Fix conversions - floatToFixed_arr(st_fx->hTdCngDec->shb_lpcCNG, st_fx->hTdCngDec->shb_lpcCNG_fx, 15, LPC_SHB_ORDER + 1); - st_fx->hTdCngDec->shb_cng_gain_fx_32 = floatToFixed(st_fx->hTdCngDec->shb_cng_gain, 11); - //floatToFixed_arr(st_fx->lsp_old, st_fx->lsp_old_fx, 15, M); -#endif // Float to fix conversions - td_cng_dec_init_ivas_fx( st_fx ); - -#if 1 // Fix to float conversions - st_fx->hTdCngDec->shb_cng_ener = fix_to_float(st_fx->hTdCngDec->shb_cng_ener_fx_32, 11); - fixedToFloat_arr(st_fx->hTdCngDec->shb_lpcCNG_fx, st_fx->hTdCngDec->shb_lpcCNG, 15, LPC_SHB_ORDER + 1); - st_fx->hTdCngDec->shb_cng_gain = fix_to_float(st_fx->hTdCngDec->shb_cng_gain_fx_32, 11); -#endif // Fix to float conversions #else td_cng_dec_init_flt( st_fx ); #endif // IVAS_FLOAT_FIXED @@ -1357,14 +1349,6 @@ ivas_error init_decoder_ivas_fx( * HQ core parameters *-----------------------------------------------------------------*/ -#ifdef ISM_DISABLE // To be removed when fixed version is available. - if ( st_fx->ivas_format != ISM_FORMAT ) - { - st_fx->prev_old_bfi = 0; - set_f(st_fx->delay_buf_out, 0, HQ_DELTA_MAX * HQ_DELAY_COMP); - set_f(st_fx->previoussynth, 0, L_FRAME48k); - } -#endif st_fx->prev_old_bfi = 0; set16_fx(st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX* HQ_DELAY_COMP); @@ -1399,8 +1383,10 @@ ivas_error init_decoder_ivas_fx( { return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ NB FEC\n")); } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. HQ_nbfec_init_flt(st_fx->hHQ_nbfec); +#endif #endif HQ_nbfec_init(st_fx->hHQ_nbfec); } @@ -1431,12 +1417,7 @@ ivas_error init_decoder_ivas_fx( #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. td_bwe_dec_init(st_fx->hBWE_TD, st_fx->extl, st_fx->output_Fs); #endif - td_bwe_dec_init_fx(st_fx, st_fx->hBWE_TD, -#ifdef ADD_IVAS_BWE - st_fx->extl, -#endif - st_fx->output_Fs); - + td_bwe_dec_init_ivas_fx(st_fx, st_fx->hBWE_TD, st_fx->output_Fs); } ELSE { @@ -1465,7 +1446,7 @@ ivas_error init_decoder_ivas_fx( } #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. - fd_bwe_dec_init_flt(st_fx->hBWE_FD); + //fd_bwe_dec_init_flt(st_fx->hBWE_FD); #endif fd_bwe_dec_init(st_fx, st_fx->hBWE_FD); } @@ -1481,12 +1462,12 @@ ivas_error init_decoder_ivas_fx( #ifdef ISM_DISABLE // To be removed when fixed version is available. if ( st_fx->ivas_format != ISM_FORMAT ) { - st_fx->tilt_swb = 0.0f; - st_fx->prev_ener_shb = 0.0f; - st_fx->prev_enerLH = 0.0f; - st_fx->enerLH = 0.0f; - st_fx->enerLL = 0.0f; - st_fx->prev_enerLL = 0.0f; + //st_fx->tilt_swb = 0.0f; + //st_fx->prev_ener_shb = 0.0f; + //st_fx->prev_enerLH = 0.0f; + //st_fx->enerLH = 0.0f; + //st_fx->enerLL = 0.0f; + //st_fx->prev_enerLL = 0.0f; st_fx->prev_fractive = 0; st_fx->prev_bws_cnt = 0; st_fx->bws_cnt = N_WS2N_FRAMES; @@ -1529,10 +1510,12 @@ ivas_error init_decoder_ivas_fx( return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HR BWE\n")); } #ifdef ISM_DISABLE // To be removed when fixed version is available. +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if ( st_fx->ivas_format != ISM_FORMAT ) { hr_bwe_dec_init_flt(st_fx->hBWE_FD_HR); } +#endif #endif hr_bwe_dec_init(st_fx->hBWE_FD_HR); } @@ -1577,12 +1560,6 @@ ivas_error init_decoder_ivas_fx( * channel-aware mode parameters *-----------------------------------------------------------------*/ -#ifdef ISM_DISABLE // To be removed when fixed version is available. - if ( st_fx->ivas_format != ISM_FORMAT ) - { - set_f(st_fx->tilt_code_dec, 0.0f, NB_SUBFR16k); - } -#endif set16_fx(st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k); st_fx->use_partial_copy = 0; @@ -1624,7 +1601,7 @@ ivas_error init_decoder_ivas_fx( { return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF\n")); } -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) bass_psfilter_init(st_fx->hBPF); #endif bass_psfilter_init_fx(st_fx->hBPF); @@ -1701,14 +1678,6 @@ ivas_error init_decoder_ivas_fx( set16_fx(st_fx->flag_buffer, 0, 20); st_fx->avg_nrg_LT = 0; -#ifdef ISM_DISABLE // To be removed when fixed version is available. - if ( st_fx->ivas_format != ISM_FORMAT ) - { - st_fx->perc_bwddec_float = 0.0f; - st_fx->avg_nrg_LT_float = 0.0f; - } -#endif - /*-----------------------------------------------------------------* * Noise gate parameters *-----------------------------------------------------------------*/ @@ -1716,11 +1685,11 @@ ivas_error init_decoder_ivas_fx( #ifdef ISM_DISABLE // To be removed when fixed version is available. if ( st_fx->ivas_format != ISM_FORMAT ) { - st_fx->ng_ener_ST = -51.0f; + //st_fx->ng_ener_ST = -51.0f; - st_fx->old_Es_pred = 0; - set_f(st_fx->old_Aq_12_8 + 1, 0, M); - st_fx->old_Aq_12_8[0] = 1; + //st_fx->old_Es_pred = 0; + //set_f(st_fx->old_Aq_12_8 + 1, 0, M); + //st_fx->old_Aq_12_8[0] = 1; } #endif #ifdef IVAS_FLOAT_FIXED @@ -1745,7 +1714,7 @@ ivas_error init_decoder_ivas_fx( { return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n")); } -#ifdef ISM_DISABLE // To be removed when fixed version is available. +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if ( st_fx->ivas_format != ISM_FORMAT ) { sc_vbr_dec_init_flt(st_fx->hSC_VBR); @@ -1766,8 +1735,8 @@ ivas_error init_decoder_ivas_fx( st_fx->ppp_mode_dec = 0; st_fx->last_nelp_mode_dec = 0; st_fx->nelp_mode_dec = 0; - st_fx->prev_gain_pit_dec = 0.0f; - st_fx->prev_tilt_code_dec = 0.0f; + //st_fx->prev_gain_pit_dec = 0.0f; + //st_fx->prev_tilt_code_dec = 0.0f; st_fx->vbr_hw_BWE_disable_dec = 0; st_fx->last_vbr_hw_BWE_disable_dec = 0; } @@ -1979,11 +1948,11 @@ ivas_error init_decoder_ivas_fx( move16(); #ifdef ISM_DISABLE // To be removed when fixed version is available. - if ( st_fx->ivas_format != ISM_FORMAT ) - { - st_fx->cngTDLevel_float = 0.f; - st_fx->lp_noise_float = -20.0f; - } + //if ( st_fx->ivas_format != ISM_FORMAT ) + //{ + //st_fx->cngTDLevel_float = 0.f; + //st_fx->lp_noise_float = -20.0f; + //} #endif /*-----------------------------------------------------------------* diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index f330e7f649055cb5463c75c9ff8a8a4a475d25e8..d952c32114cdd0cbbd36c144996eaeea4500ab04 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -2101,8 +2101,10 @@ void ivas_binRenderer( #else //float reverbRe[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; //float reverbIm[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - Word64 reverbRe_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - Word64 reverbIm_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word32 reverbRe_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word32 reverbIm_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word64 reverbRe_fx_64[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word64 reverbIm_fx_64[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; //float inRe[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; //float inIm[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; Word32 inRe_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; @@ -2115,13 +2117,26 @@ void ivas_binRenderer( { FOR( k = 0; k < numTimeSlots; k++ ) { - set64_fx( reverbRe_fx[chIdx][k], 0, hBinRenderer->max_band ); - set64_fx( reverbIm_fx[chIdx][k], 0, hBinRenderer->max_band ); + set32_fx( reverbRe_fx[chIdx][k], 0, hBinRenderer->max_band ); + set32_fx( reverbIm_fx[chIdx][k], 0, hBinRenderer->max_band ); } } ivas_binaural_reverb_processSubframe_fx( hBinRenderer->hReverb, BINAURAL_CHANNELS, numTimeSlots, inRe_fx, inIm_fx, reverbRe_fx, reverbIm_fx ); - // reverbRe_fx Q = exp_real_final - Q1 + Q30 = exp_real_final + Q29 + // reverbRe_fx Q = exp_real_final + Q30 // + + FOR(i = 0; i < BINAURAL_CHANNELS; i++) + { + FOR(j = 0; j < numTimeSlots; j++) + { + + FOR(k = 0; k < hBinRenderer->hReverb->numBins; k++) + { + reverbRe_fx_64[i][j][k] = W_shl(reverbRe_fx[i][j][k], Q29); + reverbIm_fx_64[i][j][k] = W_shl(reverbIm_fx[i][j][k], Q29); + } + } + } /* Add the conv module and reverb module output */ FOR( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) @@ -2129,8 +2144,8 @@ void ivas_binRenderer( FOR( k = 0; k < numTimeSlots; k++ ) { /* Combine first and second parts to generate binaural output signal with room effect */ - v_add_w64( Cldfb_RealBuffer_Binaural_fx[chIdx][k], reverbRe_fx[chIdx][k], Cldfb_RealBuffer_Binaural_fx[chIdx][k], hBinRenderer->conv_band, 0 ); - v_add_w64( Cldfb_ImagBuffer_Binaural_fx[chIdx][k], reverbIm_fx[chIdx][k], Cldfb_ImagBuffer_Binaural_fx[chIdx][k], hBinRenderer->conv_band, 0 ); + v_add_w64( Cldfb_RealBuffer_Binaural_fx[chIdx][k], reverbRe_fx_64[chIdx][k], Cldfb_RealBuffer_Binaural_fx[chIdx][k], hBinRenderer->conv_band, 0 ); + v_add_w64( Cldfb_ImagBuffer_Binaural_fx[chIdx][k], reverbIm_fx_64[chIdx][k], Cldfb_ImagBuffer_Binaural_fx[chIdx][k], hBinRenderer->conv_band, 0 ); } } #endif diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index c827839717104eff80ae7228b44771f918e11288..2bc9bb7741924de6586ce7ebddac287da57dc46f 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -108,31 +108,40 @@ ivas_error ivas_core_dec( float synth[CPE_CHANNELS][L_FRAME48k]; float tmp_buffer[L_FRAME48k]; #ifdef IVAS_FLOAT_FIXED - Word32 synth_fx[CPE_CHANNELS][L_FRAME48k]; + //Word32 synth_fx[CPE_CHANNELS][L_FRAME48k]; set_zero( tmp_buffer, L_FRAME48k ); Word16 tmp_buffer_fx[L_FRAME48k]; + //Word32 tmp_buffer_fx_32[L_FRAME48k]; set_s(tmp_buffer_fx, 0, L_FRAME48k); - Word16 tmp16, tmp16_2, j; + Word16 tmp16 = 0, tmp16_2, j; Word16 Q_white_exc; Q_white_exc = 0; #endif int16_t tmps, incr; - float bwe_exc_extended[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; - float voice_factors[CPE_CHANNELS][NB_SUBFR16k]; + //float bwe_exc_extended[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; +#ifdef IVAS_FLOAT_FIXED + Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; +#endif + //float voice_factors[CPE_CHANNELS][NB_SUBFR16k]; #ifdef IVAS_FLOAT_FIXED Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; +#else + float voice_factors[CPE_CHANNELS][NB_SUBFR16k]; + float tmp; #endif int16_t core_switching_flag[CPE_CHANNELS]; - float old_syn_12k8_16k[CPE_CHANNELS][L_FRAME16k]; - float tmp; - float pitch_buf[CPE_CHANNELS][NB_SUBFR16k]; + //float old_syn_12k8_16k[CPE_CHANNELS][L_FRAME16k]; + //float pitch_buf[CPE_CHANNELS][NB_SUBFR16k]; #ifdef IVAS_FLOAT_FIXED - for ( i = 0; i < CPE_CHANNELS; i++ ) - { - for (int j = 0; j < NB_SUBFR16k; j++) { - pitch_buf[i][j] = 0.f; - } - } + Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; + Word32 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; + //for ( i = 0; i < CPE_CHANNELS; i++ ) + //{ + // for ( int j = 0; j < NB_SUBFR16k; j++ ) + // { + // pitch_buf[i][j] = 0.f; + // } + //} #endif int16_t unbits[CPE_CHANNELS]; int16_t sid_bw[CPE_CHANNELS]; @@ -148,13 +157,16 @@ ivas_error ivas_core_dec( int16_t nchan_out; float *save_hb_synth; ivas_error error; - Word16 tmp1, tmp2; - Word32 L_tmp; - Word16 Q_synth; + Word32 L_tmp; + Word16 Q_synth; + + FOR( i = 0; i < CPE_CHANNELS; i++ ) + { + set16_fx( pitch_buf_fx[i], 0, NB_SUBFR16k ); + } #ifdef IVAS_FLOAT_FIXED Word16 hb_synth_fx[6][L_FRAME48k]; /*not sure about number of channels so kept it as 6 will change it later*/ - Word32 hb_synth_32[6][L_FRAME48k]; Word16 output_16fx[CPE_CHANNELS][L_FRAME48k]; Word16 synth_16fx[CPE_CHANNELS][L_FRAME48k]; Word32 pitch_buf_32fx[CPE_CHANNELS][NB_SUBFR16k]; @@ -192,7 +204,7 @@ ivas_error ivas_core_dec( floatToFixed_arr( sts[k]->hHQ_core->old_outLB, sts[k]->hHQ_core->old_out_LB_fx, 0, L_FRAME32k ); floatToFixed_arrL( sts[k]->hHQ_core->old_outLB, sts[k]->hHQ_core->old_outLB_fx, 11, L_FRAME32k ); sts[k]->hTcxDec->conceal_eof_gain32 = floatToFixed( sts[k]->hTcxDec->conceal_eof_gain_float, 15 ); - f2me_16( sts[k]->last_concealed_gain_syn_deemph_float, &sts[k]->last_concealed_gain_syn_deemph, &sts[k]->last_concealed_gain_syn_deemph_e ); + //f2me_16( sts[k]->last_concealed_gain_syn_deemph_float, &sts[k]->last_concealed_gain_syn_deemph, &sts[k]->last_concealed_gain_syn_deemph_e ); } } @@ -206,9 +218,8 @@ ivas_error ivas_core_dec( { FOR( Word16 ch = 0; ch < CPE_CHANNELS; ++ch ) { - f2me_buf( sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst, &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[ch]->hFdCngDec->hFdCngCom->npart ); + //f2me_buf( sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst, &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[ch]->hFdCngDec->hFdCngCom->npart ); f2me_buf( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt, sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel, &sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, sts[ch]->hFdCngDec->hFdCngCom->stopBand - sts[ch]->hFdCngDec->hFdCngCom->startBand ); - hCPE->hCoreCoder[ch]->preemph_fac = float_to_fix16( hCPE->hCoreCoder[ch]->preemph_fac_float, Q15 ); floatToFixed_arr( sts[ch]->hFdCngDec->hFdCngCom->A_cng_flt, sts[ch]->hFdCngDec->hFdCngCom->A_cng, Q14, M + 1 ); } } @@ -457,7 +468,7 @@ ivas_error ivas_core_dec( if ( hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_MDCT && hCPE->element_mode == IVAS_CPE_DFT ) { fixedToFloat_arrL( hCPE->input_mem_LB_fx[0], hCPE->input_mem_LB[0], 11, STEREO_DFT32MS_OVL_16k ); - fixedToFloat_arrL( hCPE->old_outLB_mdct_fx, hCPE->old_outLB_mdct, 11, STEREO_MDCT2DFT_FADE_LEN_48k ); + //fixedToFloat_arrL( hCPE->old_outLB_mdct_fx, hCPE->old_outLB_mdct, 11, STEREO_MDCT2DFT_FADE_LEN_48k ); } // n_channels loop // sts is initialized here @@ -468,14 +479,14 @@ ivas_error ivas_core_dec( fixedToFloat_arr( sts[k]->hHQ_core->old_out_fx, sts[k]->hHQ_core->old_out, 0, L_FRAME48k ); fixedToFloat_arr( sts[k]->hHQ_core->old_out_LB_fx, sts[k]->hHQ_core->old_outLB, 0, L_FRAME32k ); } - fixedToFloat_arr( voice_factors_fx[k], voice_factors[k], 15, NB_SUBFR16k ); + //fixedToFloat_arr( voice_factors_fx[k], voice_factors[k], 15, NB_SUBFR16k ); fixedToFloat_arr( hb_synth_fx[k], hb_synth[k], 0, L_FRAME48k ); // 0 is assumed as original values are set to 0 } IF( sts[0]->element_mode == IVAS_CPE_MDCT && sts[0]->total_brate == SID_2k40 ) { FOR( Word16 ch = 0; ch < CPE_CHANNELS; ++ch ) { - me2f_buf( sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst, sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, sts[ch]->hFdCngDec->hFdCngCom->npart ); + //me2f_buf( sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst, sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, sts[ch]->hFdCngDec->hFdCngCom->npart ); me2f_buf( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel, sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt, sts[ch]->hFdCngDec->hFdCngCom->stopBand - sts[ch]->hFdCngDec->hFdCngCom->startBand ); fixedToFloat_arr( sts[ch]->hFdCngDec->hFdCngCom->A_cng, sts[ch]->hFdCngDec->hFdCngCom->A_cng_flt, Q14, M + 1 ); } @@ -531,46 +542,16 @@ ivas_error ivas_core_dec( #ifdef IVAS_FLOAT_FIXED #if 1 /*Float to fix conversions*/ - Word16 Q_mem_syn, Q_agc_mem, Q_syn, Q_pst_old_syn = 0, Q_pst_mem_deemp_err = 0, Q_hb_prev_synth_buffer, Q_mem_hf = 0, Q_mem_syn_hf = 0, Q_mem_hp400 = 0, Q_delay_syn_hf = 0, Q_mem_hp_interp = 0, - Q_old_syn_12k8_16k = 0, Q_prev_env = 0, Q_FBTCXdelayBuf = 15, Q_prev_synth_buffer, Q_syn_Overl = 15, Q_fer_samples = 15, Q_old_syn_Overl = 15, Q_olapBufferAna = 15, Q_olapBufferSynth = 15, - Q_olapBufferSynth2 = 15, Q_old_synthFB = 15, Q_mem_deemph = 15; /*Initializing with max values to avoid warnings*/ - Q_mem_syn = 0; - Q_agc_mem = 0; - Q_syn = Q_factor_arr( st->syn_float, M + 1 ); - Q_mem_deemph = s_min( Q_syn, Q_factor( st->mem_deemph ) ) - 1; + Word16 Q_hb_prev_synth_buffer, + Q_FBTCXdelayBuf = 15, Q_prev_synth_buffer, Q_syn_Overl = 15, Q_fer_samples = 15, Q_old_syn_Overl = 15, /*Q_olapBufferAna = 15,*/ Q_olapBufferSynth = 15, + Q_olapBufferSynth2 = 15, Q_old_synthFB = 15; /*Initializing with max values to avoid warnings*/ + Q_hb_prev_synth_buffer = Q_factor_arr( st->hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); Q_prev_synth_buffer = Q_factor_arr( st->prev_synth_buffer, 96 ); - floatToFixed_arr( st->syn_float, st->syn, Q_mem_deemph, M + 1 ); - st->mem_deemph_fx = (Word16) floatToFixed( st->mem_deemph, Q_mem_deemph ); floatToFixed_arr( st->hb_prev_synth_buffer, st->hb_prev_synth_buffer_fx, Q_hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); - IF( st->hBPF ) - { - Q_pst_old_syn = Q_factor_arrL( st->hBPF->pst_old_syn, NBPSF_PIT_MAX ); - Q_pst_mem_deemp_err = Q_factor_L( st->hBPF->pst_mem_deemp_err ); - floatToFixed_arr32( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_32, Q_pst_old_syn, NBPSF_PIT_MAX ); - st->hBPF->pst_mem_deemp_err_32 = float_to_fix( st->hBPF->pst_mem_deemp_err, Q_pst_mem_deemp_err ); - } - IF( st->hBWE_zero ) - { - Q_mem_hf = Q_factor_arr( st->hBWE_zero->mem_hf, ( L_FIR - 1 ) ); - Q_mem_syn_hf = Q_factor_arr( st->hBWE_zero->mem_syn_hf, M ); - Q_mem_hp400 = Q_factor_arr( st->hBWE_zero->mem_hp400, 4 ); - Q_delay_syn_hf = Q_factor_arr( st->hBWE_zero->delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); - Q_mem_hp_interp = Q_factor_arr( st->hBWE_zero->mem_hp_interp, INTERP_3_1_MEM_LEN ); - floatToFixed_arr16( st->hBWE_zero->mem_hf, st->hBWE_zero->mem_hf_fx, Q_mem_hf, ( L_FIR - 1 ) ); - floatToFixed_arr16( st->hBWE_zero->mem_syn_hf, st->hBWE_zero->mem_syn_hf_fx, Q_mem_syn_hf, M ); - floatToFixed_arr16( st->hBWE_zero->mem_hp400, st->hBWE_zero->mem_hp400_fx, Q_mem_hp400, 4 ); - floatToFixed_arr16( st->hBWE_zero->delay_syn_hf, st->hBWE_zero->delay_syn_hf_fx, Q_delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); - floatToFixed_arr16( st->hBWE_zero->mem_hp_interp, st->hBWE_zero->mem_hp_interp_fx, Q_mem_hp_interp, INTERP_3_1_MEM_LEN ); - } - IF( st->hBWE_FD ) - { - Q_old_syn_12k8_16k = Q_factor_arr( st->hBWE_FD->old_syn_12k8_16k, 36 ); - floatToFixed_arr16( st->hBWE_FD->old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, Q_old_syn_12k8_16k, 36 ); - } + IF( st->hHQ_core ) { - Q_prev_env = Q_factor_arrL( st->hHQ_core->prev_env, SFM_N_WB ); Q_fer_samples = Q_factor_arr( st->hHQ_core->fer_samples, 960 ); } IF( st->hTcxDec ) @@ -583,18 +564,7 @@ ivas_error ivas_core_dec( Q_syn_Overl = s_min( Q_fer_samples, Q_syn_Overl ) - 1; IF( st->hHQ_core ) { - //floatToFixed_arr32( st->hHQ_core->prev_env, st->hHQ_core->prev_env_fx, Q_prev_env, SFM_N_WB ); - //floatToFixed_arr32( st->hHQ_core->prev_normq, st->hHQ_core->prev_normq_fx, 14, SFM_N_WB ); /*Q-14*/ - //floatToFixed_arr32( st->hHQ_core->last_ni_gain, st->hHQ_core->last_ni_gain_fx, 17, BANDS_MAX ); /*Q-17*/ - //floatToFixed_arr16( st->hHQ_core->last_env, st->hHQ_core->last_env_fx, 1, BANDS_MAX ); /*Q-1*/ floatToFixed_arr32( st->hHQ_core->prev_coeff_out, st->hHQ_core->prev_coeff_out_fx, Q12, L_HQ_WB_BWE ); /*Q-12*/ - floatToFixed_arr16( st->hHQ_core->fer_samples, st->hHQ_core->fer_samples_fx, Q_syn_Overl, 960 ); - //st->hHQ_core->memfilt_lb_fx = float_to_fix16( st->hHQ_core->memfilt_lb, 0 ); - //st->hHQ_core->mean_prev_hb_fx = float_to_fix( st->hHQ_core->mean_prev_hb, 0 ); - //st->hHQ_core->smoothmem_fx = float_to_fix16( st->hHQ_core->smoothmem, 15 ); - //st->hHQ_core->mean_prev_fx = floatToFixed( st->hHQ_core->mean_prev, 0 ); - //st->hHQ_core->mean_prev_nc_fx = floatToFixed( st->hHQ_core->mean_prev_nc, 0 ); - //st->hHQ_core->wmold_hb_fx = float_to_fix16( st->hHQ_core->wmold_hb, 15 ); } IF( st->hTcxDec ) { @@ -613,32 +583,18 @@ ivas_error ivas_core_dec( floatToFixed_arr32( st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_fx, Q11, st->cldfbSyn->cldfb_state_length ); } - FOR( i = 0; i < M; i++ ) - { - //st->lsp_old_fx[i] = float_to_fix16( st->lsp_old[i], 15 ); - st->mem_AR_fx[i] = float_to_fix16( ( st->mem_AR[i] * 2.56f ), 0 ); - st->mem_MA_fx[i] = (Word16) ( ( st->mem_MA[i] * 2.56f ) ); - } IF( st->hFdCngDec ) { - Q_olapBufferAna = Q_factor_arr( st->hFdCngDec->hFdCngCom->olapBufferAna_flt, FFTLEN ) - 1; - floatToFixed_arr16( st->hFdCngDec->hFdCngCom->olapBufferAna_flt, st->hFdCngDec->hFdCngCom->olapBufferAna_fx, Q_olapBufferAna, L_FRAME32k ); - Q_olapBufferSynth = Q_factor_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, 640 ) - 2; - floatToFixed_arr32( st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, Q_olapBufferSynth, 640 ); + //Q_olapBufferAna = Q_factor_arr( st->hFdCngDec->hFdCngCom->olapBufferAna_flt, FFTLEN ) - 1; + //floatToFixed_arr16( st->hFdCngDec->hFdCngCom->olapBufferAna_flt, st->hFdCngDec->hFdCngCom->olapBufferAna_fx, Q_olapBufferAna, L_FRAME32k ); + //Q_olapBufferSynth = Q_factor_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, 640 ) - 2; + //floatToFixed_arr32( st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, Q_olapBufferSynth, 640 ); Q_olapBufferSynth2 = Q_factor_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, 640 ) - 1; floatToFixed_arr32( st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, Q_olapBufferSynth2, 640 ); } IF( st->cldfbBPF ) floatToFixed_arr32( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_fx, Q11, st->cldfbBPF->cldfb_state_length ); - //Q_old_exc = Q_factor_arr( st->old_exc, 480 ) - 1; - //floatToFixed_arr16( st->old_exc, st->old_exc_fx, Q_old_exc, 480 ); - floatToFixed_arr32( st->previoussynth, st->previoussynth_fx_32, 0, 960 ); - st->enr_old_fx = (Word32) st->enr_old; - st->log_energy_diff_lt_fx = float_to_fix( st->log_energy_diff_lt, Q15 ); - st->stab_fac_smooth_lt_fx = float_to_fix16( st->stab_fac_smooth_lt, Q15 ); - st->lp_ener_fx = float_to_fix( st->lp_ener, Q6 ); - st->lp_gainc_fx = (Word16) L_min( 32767, float_to_fix( st->lp_gainc, 3 ) ); - //floatToFixed_arr16( st->mem_syn_r_float, st->mem_syn_r, Q_mem_syn, L_SYN_MEM ); + IF( ( EQ_16( st->core, ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) ) { IF( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && LE_32( st->element_brate, IVAS_24k4 ) && GT_32( last_element_brate, IVAS_24k4 ) ) @@ -648,43 +604,22 @@ ivas_error ivas_core_dec( } } #endif + Copy_Scale_sig_16_32( st->previoussynth_fx, st->previoussynth_fx_32, L_FRAME48k, 0 ); + IF ( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, Q_old_synthFB, &Q_olapBufferSynth, &Q_olapBufferSynth2) ) != IVAS_ERR_OK ) { return error; } #if 1 /*Fixed to float function changes*/ - st->mem_deemph = fixedToFloat( st->mem_deemph_fx, Q_mem_deemph ); fixedToFloat_arr( st->hb_prev_synth_buffer_fx, st->hb_prev_synth_buffer, Q_hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); fixedToFloat_arr( st->prev_synth_buffer_fx, st->prev_synth_buffer, Q_prev_synth_buffer, 96 ); st->q_prev_synth_buffer_fx = Q_prev_synth_buffer; - st->enr_old = fixedToFloat( st->enr_old_fx, 0 ); - st->lp_gainc = fixedToFloat( st->lp_gainc_fx, 3 ); /*Q3*/ - FOR( i = 0; i < M; i++ ) - { - st->mem_MA[i] = (float) ( st->mem_MA_fx[i] / 2.56f ); - st->mem_AR[i] = (float) ( st->mem_AR_fx[i] / 2.56f ); - //st->lsp_old[i] = fixedToFloat( st->lsp_old_fx[i], 15 ); - } - IF( st->hBPF ) - { - fixedToFloat_arrL( st->hBPF->pst_old_syn_32, st->hBPF->pst_old_syn, Q_pst_old_syn, NBPSF_PIT_MAX ); - st->hBPF->pst_mem_deemp_err = fixedToFloat( st->hBPF->pst_mem_deemp_err_32, Q_pst_mem_deemp_err ); - } IF( st->hTcxDec ) { fixedToFloat_arr( st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl_float, Q_old_syn_Overl, L_FRAME32k / 2 ); } - IF( st->hBWE_FD ) - fixedToFloat_arr( st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, Q_old_syn_12k8_16k, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); - IF( st->hBWE_zero ) - { - fixedToFloat_arr( st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, Q_mem_hf, ( L_FIR - 1 ) ); - fixedToFloat_arr( st->hBWE_zero->mem_syn_hf_fx, st->hBWE_zero->mem_syn_hf, Q_mem_syn_hf, M ); - fixedToFloat_arr( st->hBWE_zero->mem_hp400_fx, st->hBWE_zero->mem_hp400, Q_mem_hp400, 4 ); - fixedToFloat_arr( st->hBWE_zero->delay_syn_hf_fx, st->hBWE_zero->delay_syn_hf, Q_delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); - fixedToFloat_arr( st->hBWE_zero->mem_hp_interp_fx, st->hBWE_zero->mem_hp_interp, Q_mem_hp_interp, INTERP_3_1_MEM_LEN ); - } + IF( st->cldfbAna ) fixedToFloat_arrL( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_state, Q10, st->cldfbAna->cldfb_state_length ); IF( st->cldfbSyn ) @@ -693,24 +628,13 @@ ivas_error ivas_core_dec( fixedToFloat_arrL( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_state, Q11, st->cldfbBPF->cldfb_state_length ); IF( st->hHQ_core ) { - //fixedToFloat_arrL( st->hHQ_core->prev_env_fx, st->hHQ_core->prev_env, Q_prev_env, SFM_N_WB ); - //fixedToFloat_arrL( st->hHQ_core->prev_normq_fx, st->hHQ_core->prev_normq, 14, SFM_N_WB ); /*Q-14*/ - //fixedToFloat_arrL( st->hHQ_core->last_ni_gain_fx, st->hHQ_core->last_ni_gain, 17, BANDS_MAX ); /*Q-17*/ - //fixedToFloat_arr( st->hHQ_core->last_env_fx, st->hHQ_core->last_env, 1, BANDS_MAX ); /*Q-1*/ fixedToFloat_arrL( st->hHQ_core->prev_coeff_out_fx, st->hHQ_core->prev_coeff_out, Q12, L_HQ_WB_BWE ); - //st->hHQ_core->memfilt_lb = fixedToFloat( st->hHQ_core->memfilt_lb_fx, 0 ); - //st->hHQ_core->mean_prev_hb = fixedToFloat( st->hHQ_core->mean_prev_hb_fx, 0 ); - //st->hHQ_core->smoothmem = st->hHQ_core->smoothmem_fx / 32767.f; - //st->hHQ_core->mean_prev = fixedToFloat( st->hHQ_core->mean_prev_fx, 0 ); - //st->hHQ_core->mean_prev_nc = fixedToFloat( st->hHQ_core->mean_prev_nc_fx, 0 ); - //st->hHQ_core->wmold_hb = st->hHQ_core->wmold_hb_fx / 32767.f; - fixedToFloat_arr( st->hHQ_core->fer_samples_fx, st->hHQ_core->fer_samples, Q_syn_Overl, 960 ); } IF( st->hFdCngDec ) { - fixedToFloat_arr( st->hFdCngDec->hFdCngCom->olapBufferAna_fx, st->hFdCngDec->hFdCngCom->olapBufferAna_flt, Q_olapBufferAna, L_FRAME32k ); + //fixedToFloat_arr( st->hFdCngDec->hFdCngCom->olapBufferAna_fx, st->hFdCngDec->hFdCngCom->olapBufferAna_flt, Q_olapBufferAna, L_FRAME32k ); fixedToFloat_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, Q_olapBufferSynth2, L_FRAME32k ); - fixedToFloat_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, Q_olapBufferSynth, L_FRAME32k ); + //fixedToFloat_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, Q_olapBufferSynth, L_FRAME32k ); } #endif #else @@ -736,7 +660,7 @@ ivas_error ivas_core_dec( { /* ACELP core decoder */ #ifdef IVAS_FLOAT_FIXED - Word16 output_fx[L_FRAME48k], synth_fx[L_FRAME48k], old_syn_12k8_16k_fx[L_FRAME16k], pitch_buf_fx[NB_SUBFR16k]; + Word16 output_fx[L_FRAME48k], synth_fxl[L_FRAME48k], old_syn_12k8_16k_fx_16[L_FRAME16k]; set_s(output_fx, 0, L_FRAME48k); Word16 save_hb_synth_fx_arr[L_FRAME48k], *save_hb_synth_fx; if (save_hb_synth) { @@ -745,28 +669,29 @@ ivas_error ivas_core_dec( else { save_hb_synth_fx = NULL; } - Word32 bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]; + //Word32 bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]; /* float2fix, to be removed */ acelp_decoder_state_float2fix(st, hCPE == NULL ? NULL : hCPE->hStereoCng); if (hStereoTD) { floatToFixed_arr(hStereoTD->tdm_Pri_pitch_buf, hStereoTD->tdm_Pri_pitch_buf_fx, Q6, NB_SUBFR); } - if ( ( error = acelp_core_dec_ivas_fx( st, output_fx, synth_fx, save_hb_synth_fx, bwe_exc_extended_fx, voice_factors_fx[n], old_syn_12k8_16k_fx, sharpFlag[n], pitch_buf_fx, &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE == NULL ? NULL : hCPE->hStereoCng, read_sid_info ) ) != IVAS_ERR_OK ) + if ( ( error = acelp_core_dec_ivas_fx( st, output_fx, synth_fxl, save_hb_synth_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE == NULL ? NULL : hCPE->hStereoCng, read_sid_info ) ) != IVAS_ERR_OK ) { return error; } /* fix2float, to be removed */ acelp_decoder_state_fix2float(st, hCPE == NULL ? NULL : hCPE->hStereoCng); fixedToFloat_arr(output_fx, output[n], st->Q_syn2, L_FRAME48k); - fixedToFloat_arr(synth_fx, synth[n], 0, L_FRAME48k); + fixedToFloat_arr(synth_fxl, synth[n], 0, L_FRAME48k); if (save_hb_synth) { fixedToFloat_arr(save_hb_synth_fx, save_hb_synth, 0, L_FRAME48k); } - fixedToFloat_arrL(bwe_exc_extended_fx, bwe_exc_extended[n], 2*st->Q_exc, L_FRAME32k + NL_BUFF_OFFSET); - fixedToFloat_arr(voice_factors_fx[n], voice_factors[n], Q15, NB_SUBFR16k); - fixedToFloat_arr(old_syn_12k8_16k_fx, old_syn_12k8_16k[n], -1, L_FRAME16k); - fixedToFloat_arr(pitch_buf_fx, pitch_buf[n], Q6, NB_SUBFR16k); + //fixedToFloat_arrL(bwe_exc_extended_fx, bwe_exc_extended[n], 2*st->Q_exc, L_FRAME32k + NL_BUFF_OFFSET); + //fixedToFloat_arr(voice_factors_fx[n], voice_factors[n], Q15, NB_SUBFR16k); + //fixedToFloat_arr(old_syn_12k8_16k_fx, old_syn_12k8_16k[n], -1, L_FRAME16k); + Copy_Scale_sig_16_32(old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n],L_FRAME16k,Q11 - (-1)); + //fixedToFloat_arr(pitch_buf_fx[n], pitch_buf[n], Q6, NB_SUBFR16k); #else if ((error = acelp_core_dec(st, output[n], synth[n], save_hb_synth, bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], sharpFlag[n], pitch_buf[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh, tdm_lsfQ_PCh, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE == NULL ? NULL : hCPE->hStereoCng, read_sid_info)) != IVAS_ERR_OK) { @@ -775,6 +700,8 @@ ivas_error ivas_core_dec( #endif } + Copy_Scale_sig_32_16(st->previoussynth_fx_32, st->previoussynth_fx, L_FRAME48k, 0); + #ifdef IVAS_FLOAT_FIXED IF( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { @@ -789,7 +716,9 @@ ivas_error ivas_core_dec( fixedToFloat_arr( output_16fx[n], output[n], 0, st->L_frame ); fixedToFloat_arr( synth_16fx[n], synth[n], 0, st->hTcxDec->L_frameTCX ); - fixedToFloat_arrL( pitch_buf_32fx[n], pitch_buf[n], Q6, NB_SUBFR16k ); + //fixedToFloat_arrL( pitch_buf_32fx[n], pitch_buf[n], Q6, NB_SUBFR16k ); + + Copy_Scale_sig_32_16(pitch_buf_32fx[n], pitch_buf_fx[n],NB_SUBFR16k,0); stereo_tcx_dec_mode_switch_reconf_To_fixed_2( st, 0, last_element_mode, frameMode[n]); fixed_to_float_stereo_tcx_core_dec( st, output[n] ); @@ -806,7 +735,7 @@ ivas_error ivas_core_dec( { /* HQ core decoder */ #ifdef IVAS_FLOAT_FIXED - Word16 synth_fx[L_FRAME48k]; + Word16 synth_fxl[L_FRAME48k]; Word16 output_fx[L_FRAME48k]; Q_synth = 0; Word16 Q_output = 0; @@ -821,86 +750,33 @@ ivas_error ivas_core_dec( st->hHQ_core->Q_old_wtda = -1; st->hHQ_core->Q_old_wtda_LB = -1; - floatToFixed_arr( synth[n], synth_fx, st->Q_syn, L_FRAME48k ); + floatToFixed_arr( synth[n], synth_fxl, st->Q_syn, L_FRAME48k ); floatToFixed_arr( output[n], output_fx, st->Q_syn, L_FRAME48k ); #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED floatToFixed_arr( hHQ_core->old_out, hHQ_core->old_out_fx, hHQ_core->Q_old_wtda, L_FRAME48k ); floatToFixed_arr( hHQ_core->old_outLB, hHQ_core->old_out_LB_fx, hHQ_core->Q_old_wtda_LB, L_FRAME32k ); floatToFixed_arr( st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, -1, L_FRAME32k / 2 ); - floatToFixed_arrL( st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2 ); floatToFixed_arrL( hHQ_core->prev_coeff_out, hHQ_core->prev_coeff_out_fx, Q12, L_HQ_WB_BWE ); - FOR( i = 0; i < 3; ++i ) - { - hHQ_core->old_is_transient[i] = hHQ_core->old_is_transient[i]; - } - hHQ_core->HqVoicing = hHQ_core->HqVoicing; - hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing; - hHQ_core->prev_hqswb_clas = hHQ_core->prev_hqswb_clas; - hHQ_core->hq_generic_seed = hHQ_core->hq_generic_seed; - FOR( i = 0; i < SFM_N_ENV_STAB; ++i ) - { - hHQ_core->mem_norm[i] = hHQ_core->mem_norm[i]; - hHQ_core->mem_norm_hqfec[i] = hHQ_core->mem_norm_hqfec[i]; - } - hHQ_core->mem_env_delta = hHQ_core->mem_env_delta; - hHQ_core->mem_env_delta_hqfec = hHQ_core->mem_env_delta_hqfec; - hHQ_core->no_att_hangover = hHQ_core->no_att_hangover; - hHQ_core->oldHqVoicing = hHQ_core->oldHqVoicing; - hHQ_core->envstabplc_hocnt = hHQ_core->envstabplc_hocnt; floatToFixed_arr( st->hTcxDec->prev_good_synth - tmp_size, st->hTcxDec->prev_good_synth_fx - tmp_size, 0, 2 * output_frame + tmp_size ); - hHQ_core->time_offs = hHQ_core->time_offs; - hHQ_core->num_p = hHQ_core->num_p; - FOR( i = 0; i < MAX_PLOCS; ++i ) - { - hHQ_core->plocs[i] = hHQ_core->plocs[i]; - } - hHQ_core->last_fec = hHQ_core->last_fec; - hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing; - hHQ_core->ph_ecu_active = hHQ_core->ph_ecu_active; #endif - ivas_hq_core_dec_fx( st, synth_fx, &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_fx, &Q_output ); + ivas_hq_core_dec_fx( st, synth_fxl, &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_fx, &Q_output ); - fixedToFloat_arr( synth_fx, synth[n], Q_synth, L_FRAME48k ); + fixedToFloat_arr( synth_fxl, synth[n], Q_synth, L_FRAME48k ); fixedToFloat_arr( output_fx, output[n], Q_output, L_FRAME48k ); #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED fixedToFloat_arr( hHQ_core->old_out_fx, hHQ_core->old_out, hHQ_core->Q_old_wtda, L_FRAME48k ); fixedToFloat_arr( hHQ_core->old_out_LB_fx, hHQ_core->old_outLB, hHQ_core->Q_old_wtda_LB, L_FRAME32k ); fixedToFloat_arr( st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl_float, -1, L_FRAME32k / 2 ); - fixedToFloat_arrL( st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2 ); fixedToFloat_arrL( hHQ_core->prev_coeff_out_fx, hHQ_core->prev_coeff_out, Q12, L_HQ_WB_BWE ); FOR( i = 0; i < 3; ++i ) { hHQ_core->prev_coeff_out[i] = hHQ_core->old_is_transient[i]; } - hHQ_core->HqVoicing = hHQ_core->HqVoicing; - hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing; - hHQ_core->prev_hqswb_clas = hHQ_core->prev_hqswb_clas; - hHQ_core->hq_generic_seed = hHQ_core->hq_generic_seed; - FOR( i = 0; i < SFM_N_ENV_STAB; ++i ) - { - hHQ_core->mem_norm[i] = hHQ_core->mem_norm[i]; - hHQ_core->mem_norm_hqfec[i] = hHQ_core->mem_norm_hqfec[i]; - } - hHQ_core->mem_env_delta = hHQ_core->mem_env_delta; - hHQ_core->mem_env_delta_hqfec = hHQ_core->mem_env_delta_hqfec; - hHQ_core->no_att_hangover = hHQ_core->no_att_hangover; - hHQ_core->oldHqVoicing = hHQ_core->oldHqVoicing; - hHQ_core->envstabplc_hocnt = hHQ_core->envstabplc_hocnt; fixedToFloat_arr( st->hTcxDec->prev_good_synth_fx - tmp_size, st->hTcxDec->prev_good_synth - tmp_size, 0, 2 * output_frame + tmp_size ); - hHQ_core->time_offs = hHQ_core->time_offs; - hHQ_core->num_p = hHQ_core->num_p; - FOR( i = 0; i < MAX_PLOCS; ++i ) - { - hHQ_core->plocs[i] = hHQ_core->plocs[i]; - } - //fixedToFloat_arrL( hHQ_core->plocsi_fx, hHQ_core->plocsi, Q16, MAX_PLOCS ); - //hHQ_core->env_stab = fixedToFloat( hHQ_core->env_stab_fx, Q15 ); - hHQ_core->last_fec = hHQ_core->last_fec; - hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing; - hHQ_core->ph_ecu_active = hHQ_core->ph_ecu_active; + #endif #else hq_core_dec( st, synth[n], output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output[n] ); @@ -915,25 +791,19 @@ ivas_error ivas_core_dec( { #ifdef IVAS_FLOAT_FIXED /* To be cleaned up once the caller function is converted // These changes are for system testing of fixed changes made */ - float max_val = 0; - Word16 tdm_Pri_pitch_buf_fx[NB_SUBFR], old_pitch_buf_fx[2 * NB_SUBFR16k + 2]; - FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) - { - max_val = max( st->old_pitch_buf[i], max_val ); - } - Word16 Q_var = norm_s( (Word16) max_val ); + Word16 tdm_Pri_pitch_buf_fx[NB_SUBFR]; - for ( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) - { - old_pitch_buf_fx[i] = float_to_fix16( st->old_pitch_buf[i], Q_var ); - } - td_stereo_param_updt_fx( st->lsp_old_fx, st->lsf_old_fx, old_pitch_buf_fx + st->nb_subfr, - tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc, Q_var ); + Copy_Scale_sig_32_16(hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, 2 * NB_SUBFR16k + 2, -10); + + 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, tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc, Q16 ); + + 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); for ( i = 0; i < NB_SUBFR; i++ ) { - hStereoTD->tdm_Pri_pitch_buf[i] = fix16_to_float( tdm_Pri_pitch_buf_fx[i], Q_var ); + hStereoTD->tdm_Pri_pitch_buf[i] = fix16_to_float( tdm_Pri_pitch_buf_fx[i], Q16 ); } #else @@ -961,7 +831,298 @@ ivas_error ivas_core_dec( else { #ifdef IVAS_FLOAT_FIXED - stereo_mdct_core_dec_fx( st_ivas, hCPE, output, synth ); +#if 1 + Word16 e_sig = 17; + Word32 *output_fx[CPE_CHANNELS]; + Word16 synth_fx_16[CPE_CHANNELS][L_FRAME48k]; + Word16 ch; + sts = hCPE->hCoreCoder; + Word16 will_estimate_noise_on_channel[CPE_CHANNELS]; + + will_estimate_noise_on_channel[0] = sts[0]->core == TCX_20_CORE && !sts[0]->VAD; + will_estimate_noise_on_channel[1] = sts[1]->core == TCX_20_CORE && !sts[1]->VAD; + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + output_fx[ch] = malloc( sizeof( Word32 ) * L_FRAME48k ); + // synth_fx[ch] = malloc(sizeof(Word16) * L_FRAME48k); + stereo_tcx_dec_mode_switch_reconf_To_fixed( sts[ch], 1, hCPE->last_element_mode ); + //sts[ch]->hTcxLtpDec->tcxltp_gain = float_to_fix16( sts[ch]->hTcxLtpDec->tcxltp_gain_float, Q15 ); + + st = sts[ch]; + IF( st->hTonalMDCTConc ) + { + FOR( i = 0; i < s_min( st->hTonalMDCTConc->nScaleFactors, 64 ); i++ ) + { + st->hTonalMDCTConc->scaleFactorsBackground_fx[i] = floatToFixed( st->hTonalMDCTConc->scaleFactorsBackground_flt[i], 15 ); + } + + if ( sts[0]->bfi && st->tonal_mdct_plc_active && st->hTonalMDCTConc->pTCI ) + { + FOR( i = 0; i < s_min( st->hTonalMDCTConc->pTCI->numIndexes, 30 ); i++ ) + { + float pd = st->hTonalMDCTConc->pTCI->phaseDiff_float[i]; + if ( pd >= PI2 ) + pd = fmodf( pd, PI2 ) - PI2; + st->hTonalMDCTConc->pTCI->phaseDiff[i] = (Word16) floatToFixed( pd, Q12 ); + } + FOR( i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++ ) + { + float pd = st->hTonalMDCTConc->pTCI->phase_currentFramePredicted_float[i]; + pd = fmodf( pd, PI2 ); + st->hTonalMDCTConc->pTCI->phase_currentFramePredicted[i] = (Word16) ( pd * ( 1u << Q13 ) ); + } + } + } + IF( st->hTcxDec ) + st->hTcxDec->tcxltp_last_gain_unmodified = (Word16) floatToFixed( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); + + if ( !sts[0]->bfi && ( will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] ) ) + { + sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = floatToFixed( sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt, 31 ); + } + IF( will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] || sts[ch]->bfi ) + { + for ( int p = 0; p < s_min( sts[ch]->hFdCngDec->hFdCngCom->fftlen, 640 ); p++ ) + { + sts[ch]->hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32) ( sts[ch]->hFdCngDec->hFdCngCom->fftBuffer_flt[p] * ( 1u << ( 31 - sts[ch]->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); + } + sts[ch]->hFdCngDec->msNoiseEst_exp = 31 - Q4; + for ( int p = 0; p < NPART_SHAPING; p++ ) + { + sts[ch]->hFdCngDec->msNoiseEst[p] = (Word32) ( sts[ch]->hFdCngDec->msNoiseEst_float[p] * ( 1u << ( 31 - sts[ch]->hFdCngDec->msNoiseEst_exp ) ) ); + } + sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q3; // Q3 + IF( st->hFdCngDec && st->hFdCngDec->hFdCngCom ) + { + FOR( Word16 ind = 0; ind < 340; ind++ ) + { + st->hFdCngDec->hFdCngCom->cngNoiseLevel[ind] = (Word32) ( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[ind] * ( 1LL << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); + } + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = float_to_fix16( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt, 15 ); + } + } + + IF( st->hTcxDec ) + floatToFixed_arr( st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_Overl, st->Q_syn, L_FRAME32k / 2 ); + IF( st->hTcxDec ) + floatToFixed_arr( st->hTcxDec->syn_OverlFB_float, st->hTcxDec->syn_OverlFB, st->Q_syn, L_FRAME_MAX / 2 ); + + st->prev_Q_syn = st->Q_syn; + + IF( st->hHQ_core ) + floatToFixed_arr( st->hHQ_core->old_outLB, st->hHQ_core->old_out_LB_fx, st->Q_syn, L_FRAME32k ); + IF( st->hTcxDec ) + floatToFixed_arr( st->hTcxDec->syn_Overl_TDACFB_float, st->hTcxDec->syn_Overl_TDACFB, -1 - st->Q_syn, L_FRAME_MAX / 2 ); + IF( st->hTcxDec ) + floatToFixed_arr( st->hTcxDec->syn_Overl_TDAC_float, st->hTcxDec->syn_Overl_TDAC, -1 - st->Q_syn, L_FRAME32k / 2 ); + IF( st->hTcxDec ) + floatToFixed_arr( st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, -1 - st->Q_syn, L_FRAME32k / 2 ); + + IF( st->hTcxDec ) + floatToFixed_arr( st->hTcxDec->old_excFB, st->hTcxDec->old_excFB_fx, st->Q_exc, s_min( 960, st->L_frame ) ); + + if ( !st->tcxonly ) + { + floatToFixed_arr( st->p_bpf_noise_buf_float, st->p_bpf_noise_buf, 0, L_FRAME_16k ); + } + + IF( st->hTcxDec ) + floatToFixed_arr( st->hTcxDec->old_synth_float, st->hTcxDec->old_synth, st->Q_syn, 1280 ); + IF( st->hTcxDec ) + floatToFixed_arr( st->hTcxDec->synth_history, st->hTcxDec->synth_history_fx, st->Q_syn, s_min( 2496, NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ) ); + + IF( st->hHQ_core ) + floatToFixed_arr( st->hHQ_core->old_out, st->hHQ_core->old_out_fx, st->Q_syn, 960 ); + IF( st->hTonalMDCTConc ) + floatToFixed_arr( st->hTonalMDCTConc->lastPcmOut_float, st->hTonalMDCTConc->lastPcmOut, 0, s_min( 960, st->hTonalMDCTConc->nSamples ) ); + IF( st->hTonalMDCTConc ) + floatToFixed_arr( st->hTonalMDCTConc->secondLastPcmOut_float, st->hTonalMDCTConc->secondLastPcmOut, 0, s_min( 960, st->hTonalMDCTConc->nSamples ) / 2 ); + IF( st->hTcxDec ) + st->hTcxDec->conceal_eof_gain = (Word16) floatToFixed( st->hTcxDec->conceal_eof_gain_float, Q14 ); + IF( st->hTcxDec ) + f2me_16( st->hTcxDec->CngLevelBackgroundTrace_bfi, &st->hTcxDec->conCngLevelBackgroundTrace, &st->hTcxDec->conCngLevelBackgroundTrace_e ); + if ( st->hTcxDec && st->hTcxDec->conLastFrameLevel_e < 0 ) + { + st->hTcxDec->conLastFrameLevel_e = 0; + } + if ( st->hTcxDec && st->hTcxDec->conNoiseLevelMemory_e[0] < 0 ) + { + set16_fx( st->hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); + } + IF( st->hTcxDec ) + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + IF( st->hTcxDec ) + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + IF( st->hFdCngDec && st->hFdCngDec->hFdCngCom ) + floatToFixed_arr( st->hFdCngDec->hFdCngCom->A_cng_flt, st->hFdCngDec->hFdCngCom->A_cng, 15, 17 ); + } + + IF( st_ivas->hLsSetUpConversion ) + f2me_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); + IF( st_ivas->hLsSetUpConversion ) + f2me_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); + FOR( Word16 chOutIdx = 0; chOutIdx < st_ivas->hDecoderConfig->nchan_out; chOutIdx++ ) + { + FOR( Word16 chInIdx = 0; chInIdx < s_min( st_ivas->nchan_transport, 16 ); chInIdx++ ) + { + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->dmxMtx_fx[chInIdx] ) + st_ivas->hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx] = float_to_fix( st_ivas->hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx], 30 ); /*Q30*/ + } + } + + IF( sts[0]->bfi && ( hCPE->hStereoMdct->mdct_stereo_mode[0] > SMDCT_DUAL_MONO || hCPE->hStereoMdct->mdct_stereo_mode[1] > SMDCT_DUAL_MONO ) ) + { + floatToFixed_arr( sts[0]->hTonalMDCTConc->lastBlockData.spectralData_float, sts[0]->hTonalMDCTConc->lastBlockData.spectralData, ( 15 - sts[0]->hTonalMDCTConc->lastBlockData.spectralData_exp ), L_FRAME_MAX ); + floatToFixed_arr( sts[1]->hTonalMDCTConc->lastBlockData.spectralData_float, sts[1]->hTonalMDCTConc->lastBlockData.spectralData, ( 15 - sts[1]->hTonalMDCTConc->lastBlockData.spectralData_exp ), L_FRAME_MAX ); + } +#endif + stereo_mdct_core_dec_fx( st_ivas, hCPE, output_fx, synth_fx_16 ); +#if 1 // Fix to float conversion + IF( sts[0]->bfi && ( hCPE->hStereoMdct->mdct_stereo_mode[0] > SMDCT_DUAL_MONO || hCPE->hStereoMdct->mdct_stereo_mode[1] > SMDCT_DUAL_MONO ) ) + { + fixedToFloat_arr( sts[0]->hTonalMDCTConc->lastBlockData.spectralData, sts[0]->hTonalMDCTConc->lastBlockData.spectralData_float, ( 15 - sts[0]->hTonalMDCTConc->lastBlockData.spectralData_exp ), sts[0]->L_frameTCX_past ); + fixedToFloat_arr( sts[1]->hTonalMDCTConc->lastBlockData.spectralData, sts[1]->hTonalMDCTConc->lastBlockData.spectralData_float, ( 15 - sts[1]->hTonalMDCTConc->lastBlockData.spectralData_exp ), sts[0]->L_frameTCX_past ); + } + + IF( st_ivas->hLsSetUpConversion ) + me2f_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); + IF( st_ivas->hLsSetUpConversion ) + me2f_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); + + FOR( ch = 0; ch < 2; ch++ ) + { + stereo_tcx_dec_mode_switch_reconf_To_fixed( sts[ch], 0, hCPE->last_element_mode ); + me2f_buf( sts[ch]->hIGFDec->virtualSpec, sts[ch]->hIGFDec->virtualSpec_e, sts[ch]->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); + st = hCPE->hCoreCoder[ch]; + fixedToFloat_arr( st->hTcxDec->syn_OverlFB, st->hTcxDec->syn_OverlFB_float, st->Q_syn, L_FRAME_MAX / 2 ); + fixedToFloat_arr( st->hTcxDec->syn_Overl, st->hTcxDec->syn_Overl_float, st->Q_syn, L_FRAME32k / 2 ); + st->hTcxDec->tcxltp_last_gain_unmodified_float = fix16_to_float( st->hTcxDec->tcxltp_last_gain_unmodified, Q15 ); + //st->hTcxLtpDec->tcxltp_gain_float = fix16_to_float( st->hTcxLtpDec->tcxltp_gain, Q15 ); + st->hTcxDec->conceal_eof_gain_float = fix16_to_float( st->hTcxDec->conceal_eof_gain, Q14 ); + + if ( sts[ch]->last_core != -1 && sts[ch]->nbLostCmpt == 1 ) + { + if ( !( sts[ch]->rf_flag && sts[ch]->use_partial_copy && ( sts[ch]->rf_frame_type == RF_TCXTD1 || sts[ch]->rf_frame_type == RF_TCXTD2 ) ) ) + { + IF( sts[ch]->hTonalMDCTConc != NULL && sts[ch]->last_core == TCX_20_CORE && sts[ch]->second_last_core == TCX_20_CORE && ( ( sts[ch]->old_fpitch <= L_shl( sts[ch]->L_frame, 15 ) ) || ( sts[ch]->hTcxDec->tcxltp_last_gain_unmodified <= 13107 /*0.4f*/ ) ) + /* it is fine to call the detection even if no ltp information + is available, meaning that st->old_fpitch == + st->tcxltp_second_last_pitch == st->L_frame */ + && ( sts[ch]->old_fpitch == sts[ch]->hTcxDec->tcxltp_second_last_pitch ) && !sts[ch]->last_tns_active && !sts[ch]->second_last_tns_active ) + { + + if ( sts[ch]->hTonalMDCTConc->pTCI->numIndexes < MAX_NUMBER_OF_IDX ) + { + FOR( i = 0; i < s_min( 30, sts[ch]->hTonalMDCTConc->pTCI->numIndexes ); i++ ) + { + sts[ch]->hTonalMDCTConc->pTCI->phaseDiff_float[i] = fixedToFloat( sts[ch]->hTonalMDCTConc->pTCI->phaseDiff[i], Q12 ); + } + FOR( i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++ ) + { + sts[ch]->hTonalMDCTConc->pTCI->phase_currentFramePredicted_float[i] = fixedToFloat( sts[ch]->hTonalMDCTConc->pTCI->phase_currentFramePredicted[i], Q13 ); + } + } + } + } + } + + if ( !sts[0]->bfi && ( will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] ) ) + { + sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt = fixedToFloat( sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx, 31 ); + } + + IF( will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] || sts[ch]->bfi ) + { + if ( !sts[ch]->bfi ) + { + for ( int p = 0; p < s_min( 640, sts[ch]->hFdCngDec->hFdCngCom->fftlen ); p++ ) + { + sts[ch]->hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ( (float) sts[ch]->hFdCngDec->hFdCngCom->fftBuffer[p] / ( 1u << ( 31 - sts[ch]->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); + } + for ( int p = 0; p < s_min( 62, sts[ch]->hFdCngDec->npart_shaping ); p++ ) + { + sts[ch]->hFdCngDec->msNoiseEst_float[p] = ( (float) sts[ch]->hFdCngDec->msNoiseEst[p] / ( 1u << ( 31 - sts[ch]->hFdCngDec->msNoiseEst_exp ) ) ); + } + + + for ( int p = 0; p < s_min( 320, sts[ch]->hFdCngDec->hFdCngCom->stopFFTbin - sts[ch]->hFdCngDec->hFdCngCom->startBand ); p++ ) + { + sts[ch]->hFdCngDec->bandNoiseShape_float[p] = ( (float) sts[ch]->hFdCngDec->bandNoiseShape[p] / ( 1u << ( 31 - sts[ch]->hFdCngDec->bandNoiseShape_exp ) ) ); + } + + for ( int p = 0; p < s_min( 340, sts[ch]->hFdCngDec->hFdCngCom->stopFFTbin - sts[ch]->hFdCngDec->hFdCngCom->startBand ); p++ ) + { + sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); + } + } + else if ( ( ( sts[ch]->bfi == 1 ) && ( sts[ch]->nbLostCmpt == 1 ) ) && ( sum_f( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt + sts[ch]->hFdCngDec->hFdCngCom->startBand, sts[ch]->hFdCngDec->hFdCngCom->stopFFTbin - sts[ch]->hFdCngDec->hFdCngCom->startBand ) > 0.01f ) ) + { + if ( sts[ch]->element_mode == IVAS_CPE_MDCT && sts[ch]->core != ACELP_CORE ) + { + for ( int p = 0; p < s_min( 340, sts[ch]->hFdCngDec->hFdCngCom->stopFFTbin - sts[ch]->hFdCngDec->hFdCngCom->startBand ); p++ ) + { + sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); + } + for ( int p = 0; p < FDNS_NPTS; p++ ) + { + sts[ch]->hTonalMDCTConc->scaleFactorsBackground_flt[p] = (float) sts[ch]->hTonalMDCTConc->scaleFactorsBackground_fx[p] / ONE_IN_Q16; + } + } + if ( sts[ch]->element_mode != IVAS_CPE_MDCT || sts[ch]->core == ACELP_CORE ) + { + int A_cng_q = 15 - norm_s( sts[ch]->hFdCngDec->hFdCngCom->A_cng[0] ); + for ( int p = 0; p < M; p++ ) + { + sts[ch]->hFdCngDec->hFdCngCom->A_cng_flt[p] = ( (float) sts[ch]->hFdCngDec->hFdCngCom->A_cng[p] / ( 1u << A_cng_q ) ); + } + } + } + } + for ( int p = 0; p < s_min( 960, st->L_frame ); p++ ) + { + st->hTcxDec->old_excFB[p] = (float) ( st->hTcxDec->old_excFB_fx[p] ) / ( 1u << st->Q_exc ); + } + + for ( int p = 0; p < s_min( 320, st->L_frame / 2 ); p++ ) + { + st->hTcxDec->old_syn_Overl_float[p] = (float) st->hTcxDec->old_syn_Overl[p] * 2 * ( 1u << st->Q_syn ); + st->hTcxDec->syn_Overl_TDACFB_float[p] = (float) ( (float) st->hTcxDec->syn_Overl_TDACFB[p] * 2 * pow( 2, st->Q_syn ) ); + st->hTcxDec->syn_Overl_TDAC_float[p] = (float) ( (float) st->hTcxDec->syn_Overl_TDAC[p] * 2 * pow( 2, st->Q_syn ) ); + } + for ( int p = 0; p < 640; p++ ) + { + st->hHQ_core->old_outLB[p] = (float) st->hHQ_core->old_out_LB_fx[p] / ( 1u << st->Q_syn ); + } + + if ( !st->tcxonly ) + { + fixedToFloat_arr( st->p_bpf_noise_buf, st->p_bpf_noise_buf_float, 0, L_FRAME_16k ); + } + + + fixedToFloat_arr( st->hTcxDec->old_synth, st->hTcxDec->old_synth_float, st->Q_syn, 1280 ); + fixedToFloat_arr( st->hTcxDec->synth_history_fx, st->hTcxDec->synth_history, st->Q_syn, s_min( 2496, NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ) ); + fixedToFloat_arr( st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synthFB, st->Q_syn, s_min( 2496, st->hTcxDec->old_synth_lenFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ) ); + + for ( int p = 0; p < 960; p++ ) + { + st->hHQ_core->old_out[p] = (float) st->hHQ_core->old_out_fx[p] / ( 1u << st->Q_syn ); + } + + IF( st->hTcxDec ) + st->hTcxDec->CngLevelBackgroundTrace_bfi = me2f_16( st->hTcxDec->conCngLevelBackgroundTrace, st->hTcxDec->conCngLevelBackgroundTrace_e ); + + IF( st->hTonalMDCTConc && st->hTonalMDCTConc->lastPcmOut_float ) + fixedToFloat_arr( st->hTonalMDCTConc->lastPcmOut, st->hTonalMDCTConc->lastPcmOut_float, 0, s_min( 960, st->hTonalMDCTConc->nSamples ) ); + IF( sts[0]->bfi == 0 && !st->hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive ) + fixedToFloat_arr( st->hTonalMDCTConc->secondLastPcmOut, st->hTonalMDCTConc->secondLastPcmOut_float, 0, s_min( 480, st->hTonalMDCTConc->nSamples / 2 ) ); + } + + fixedToFloat_arr( synth_fx_16[0], synth[0], 15 - e_sig, 960 ); + fixedToFloat_arr( synth_fx_16[1], synth[1], 15 - e_sig, 960 ); + fixedToFloat_arrL( output_fx[0], output[0], Q11, 960 ); + fixedToFloat_arrL( output_fx[1], output[1], Q11, 960 ); +#endif #else stereo_mdct_core_dec( st_ivas, hCPE, output, synth ); #endif @@ -973,7 +1134,7 @@ ivas_error ivas_core_dec( #ifdef IVAS_FLOAT_FIXED /* To be cleaned up once the caller function is converted // These changes are for system testing of fixed changes made */ double max_synth = 0.0f; - Word16 Q_syn = 15, synth_fx[CPE_CHANNELS][L_FRAME48k]; + Word16 Q_syn = 15, synth_fxl[CPE_CHANNELS][L_FRAME48k]; double max_output = 0.0f; Word16 Q_output = 31; Word32 output_fx[CPE_CHANNELS][L_FRAME48k]; @@ -983,37 +1144,37 @@ ivas_error ivas_core_dec( if ( hCPE->last_element_brate <= IVAS_SID_5k2 ) { - for ( int j = 0; j < output_frame; j++ ) + for ( int jj = 0; jj < output_frame; jj++ ) { - max_synth = max( max_synth, fabs( synth[0][j] ) ); + max_synth = max( max_synth, fabs( synth[0][jj] ) ); } if ( (Word16) max_synth != 0 ) { Q_syn = norm_s( (Word16) max_synth ); } - for ( int j = 0; j < output_frame; j++ ) + for ( int jj = 0; jj < output_frame; jj++ ) { - synth_fx[0][j] = float_to_fix16( synth[0][j], Q_syn ); + synth_fxl[0][jj] = float_to_fix16( synth[0][jj], Q_syn ); } - for ( int j = 0; j < output_frame; j++ ) + for ( int jj = 0; jj < output_frame; jj++ ) { - max_output = max( max_output, fabs( output[0][j] ) ); + max_output = max( max_output, fabs( output[0][jj] ) ); } if ( (Word32) max_output != 0 ) { Q_output = norm_l( (Word32) max_output ); } - for ( int j = 0; j < output_frame; j++ ) + for ( int jj = 0; jj < output_frame; jj++ ) { - output_fx[0][j] = float_to_fix( output[0][j], Q_output ); + output_fx[0][jj] = float_to_fix( output[0][jj], Q_output ); } } - f2me_buf( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst, &sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp, NPART ); - f2me_buf( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst, &sts[1]->hFdCngDec->hFdCngCom->sidNoiseEstExp, NPART ); + //f2me_buf( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst, &sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp, NPART ); + //f2me_buf( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst, &sts[1]->hFdCngDec->hFdCngCom->sidNoiseEstExp, NPART ); if ( hCPE->last_element_brate <= IVAS_SID_5k2 ) { @@ -1027,10 +1188,10 @@ ivas_error ivas_core_dec( f2me_buf_16( sts[0]->hHQ_core->old_out, sts[0]->hHQ_core->old_out_fx, &sts[0]->hHQ_core->exp_old_out, L_FRAME48k ); f2me_buf_16( sts[1]->hHQ_core->old_out, sts[1]->hHQ_core->old_out_fx, &sts[1]->hHQ_core->exp_old_out, L_FRAME48k ); } - updateBuffersForDmxMdctStereo_fx( hCPE, output_frame, output_fx[0], output_fx[1], synth_fx ); + updateBuffersForDmxMdctStereo_fx( hCPE, output_frame, output_fx[0], output_fx[1], synth_fxl ); - me2f_buf( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst, sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, NPART ); - me2f_buf( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst, sts[1]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, NPART ); + //me2f_buf( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst, sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, NPART ); + //me2f_buf( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst, sts[1]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, NPART ); if ( hCPE->last_element_brate <= IVAS_SID_5k2 ) { me2f_buf_16( sts[0]->hTcxLtpDec->tcxltp_mem_in, sts[0]->hTcxLtpDec->exp_tcxltp_mem_in, sts[0]->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY ); @@ -1042,17 +1203,17 @@ ivas_error ivas_core_dec( for ( i = 1; i < CPE_CHANNELS; i++ ) { - for ( int j = 0; j < L_FRAME48k; j++ ) + for ( int jj = 0; jj < L_FRAME48k; jj++ ) { - output[i][j] = fix_to_float( output_fx[i][j], Q_output ); + output[i][jj] = fix_to_float( output_fx[i][jj], Q_output ); } } for ( i = 1; i < CPE_CHANNELS; i++ ) { - for ( int j = 0; j < output_frame; j++ ) + for ( int jj = 0; jj < output_frame; jj++ ) { - synth[i][j] = fix16_to_float( synth_fx[i][j], Q_syn ); + synth[i][jj] = fix16_to_float( synth_fxl[i][jj], Q_syn ); } } #else @@ -1110,9 +1271,9 @@ ivas_error ivas_core_dec( for ( i = 0; i < CPE_CHANNELS; i++ ) { - for ( int j = 0; j < L_FRAME16k; j++ ) + for ( int jj = 0; jj < L_FRAME16k; jj++ ) { - max_output_fx = max( max_output_fx, fabs( output[i][j] ) ); + max_output_fx = max( max_output_fx, fabs( output[i][jj] ) ); } } @@ -1122,9 +1283,9 @@ ivas_error ivas_core_dec( } for ( i = 0; i < CPE_CHANNELS; i++ ) { - for ( int j = 0; j < L_FRAME16k; j++ ) + for ( int jj = 0; jj < L_FRAME16k; jj++ ) { - output_fx[i][j] = float_to_fix( output[i][j], Q_output ); + output_fx[i][jj] = float_to_fix( output[i][jj], Q_output ); } } @@ -1152,7 +1313,7 @@ ivas_error ivas_core_dec( * Postprocessing, BWEs and updates *---------------------------------------------------------------------*/ - for ( n = 0; n < n_channels; n++ ) + FOR ( n = 0; n < n_channels; n++ ) { st = sts[n]; @@ -1161,55 +1322,54 @@ ivas_error ivas_core_dec( *---------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED - Word32 hb_synth_fx[CPE_CHANNELS][L_FRAME48k]; + Word32 hb_synth_fxg[CPE_CHANNELS][L_FRAME48k]; if (st->last_core == ACELP_CORE && (st->core == TCX_20_CORE || st->core == TCX_10_CORE || st->core == HQ_CORE) && st->hBWE_TD != NULL) { FOR(int ch_ind = 0; ch_ind < n_channels; ch_ind++) { FOR(int ind = 0; ind < L_FRAME48k; ind++) { - hb_synth_fx[ch_ind][ind] = (Word32)(hb_synth[ch_ind][ind] * (1 << 11)); + hb_synth_fxg[ch_ind][ind] = (Word32)(hb_synth[ch_ind][ind] * (1 << 11)); } } + if (st->hBWE_TD != NULL) { for (int i = 0; i < L_SHB_LAHEAD; i++) { - st->hBWE_TD->syn_overlap_fx_32[i] = (Word32)(st->hBWE_TD->syn_overlap[i] * (1 << 11)); - } - for (int i = 0; i < INTERP_3_2_MEM_LEN; i++) - { - st->hBWE_TD->int_3_over_2_tbemem_dec_fx_32[i] = (Word32)(st->hBWE_TD->int_3_over_2_tbemem_dec[i] * (1 << 11)); - } - for (int i = 0; i < HILBERT_MEM_SIZE; i++) - { - st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = (Word32)(st->hBWE_TD->genSHBsynth_Hilbert_Mem[i] * (1 << 11)); - } - for (int i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++) - { - st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32[i] = (Word32)(st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local[i] * (1 << 11)); - } - for (int i = 0; i < L_SHB_TRANSITION_LENGTH; i++) - { - st->hBWE_TD->old_tbe_synth_fx_32[i] = (Word32)(st->hBWE_TD->old_tbe_synth[i] * (1 << 11)); - } - for (int i = 0; i < 2 * ALLPASSSECTIONS_STEEP + 1; i++) - { - st->hBWE_TD->mem_resamp_HB_32k_fx_32[i] = (Word32)(st->hBWE_TD->mem_resamp_HB_32k[i] * (1 << 11)); - } - for (int i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++) - { - st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32[i] = (Word32)(st->hBWE_TD->state_lsyn_filt_dwn_shb[i] * (1 << 11)); - st->hBWE_TD->state_lsyn_filt_shb_fx_32[i] = (Word32)(st->hBWE_TD->state_lsyn_filt_shb[i] * (1 << 11)); - } - for (int i = 0; i < INTERP_3_1_MEM_LEN; i++) - { - st->hBWE_TD->mem_resamp_HB_fx_32[i] = (Word32)(st->hBWE_TD->mem_resamp_HB[i] * (1 << 11)); + for (int ii = 0; ii < L_SHB_LAHEAD; ii++) + { + st->hBWE_TD->syn_overlap_fx_32[ii] = (Word32)(st->hBWE_TD->syn_overlap[ii] * (1 << 11)); + } + for (int ii = 0; ii < INTERP_3_2_MEM_LEN; ii++) + { + st->hBWE_TD->int_3_over_2_tbemem_dec_fx_32[ii] = (Word32)(st->hBWE_TD->int_3_over_2_tbemem_dec[ii] * (1 << 11)); + } + for (int ii = 0; ii < L_SHB_TRANSITION_LENGTH; ii++) + { + st->hBWE_TD->old_tbe_synth_fx_32[ii] = (Word32)(st->hBWE_TD->old_tbe_synth[ii] * (1 << 11)); + } + for (int ii = 0; ii < 2 * ALLPASSSECTIONS_STEEP + 1; ii++) + { + st->hBWE_TD->mem_resamp_HB_32k_fx_32[ii] = (Word32)(st->hBWE_TD->mem_resamp_HB_32k[ii] * (1 << 11)); + } + for (int ii = 0; ii < 2 * ALLPASSSECTIONS_STEEP; ii++) + { + st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32[ii] = (Word32)(st->hBWE_TD->state_lsyn_filt_dwn_shb[ii] * (1 << 11)); + st->hBWE_TD->state_lsyn_filt_shb_fx_32[ii] = (Word32)(st->hBWE_TD->state_lsyn_filt_shb[ii] * (1 << 11)); + } + for (int ii = 0; ii < INTERP_3_1_MEM_LEN; ii++) + { + st->hBWE_TD->mem_resamp_HB_fx_32[ii] = (Word32)(st->hBWE_TD->mem_resamp_HB[ii] * (1 << 11)); + } } } } /*cldfb struct*/ - + IF(st->hBWE_TD != NULL) + { + floatToFixed_arr(st->hBWE_TD->old_bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended_fx, st->prev_Q_bwe_exc - 16, NL_BUFF_OFFSET); + } /*------------------fix-to-fix-start---------------------*/ /*core_switching_post_dec*/ Q_synth = 0; @@ -1228,10 +1388,8 @@ ivas_error ivas_core_dec( Word16 *synth_fx16; Word16 *output_mem_fx; - //Word32 *output_fx32; synth_fx16 = (Word16 *)malloc(L_FRAME48k * sizeof(Word16)); - //output_fx32 = (Word32 *)malloc(L_FRAME48k * sizeof(Word32)); Word32 output_fx32[L_FRAME48k]; output_mem_fx = (Word16 *)malloc(NS2SA(st->output_Fs, 3125000) * sizeof(Word16)); @@ -1258,24 +1416,12 @@ ivas_error ivas_core_dec( delta = shr(Fs_kHz, 3); } - Word16 delay_comp = i_mult2(delta, HQ_DELAY_COMP); + //Word16 delay_comp = i_mult2(delta, HQ_DELAY_COMP); - if (st->hBWE_FD != NULL) - { - st->hBWE_FD->mem_deemph_old_syn_fx = (Word16)floatToFixed(st->hBWE_FD->mem_deemph_old_syn, 0); - } IF(st->hHQ_core != NULL) { floatToFixed_arr(st->hHQ_core->old_out, st->hHQ_core->old_out_fx, 0, L_FRAME48k); - floatToFixed_arr(st->hHQ_core->fer_samples, st->hHQ_core->fer_samples_fx, 0, NS2SA(st->output_Fs, 3000000)); - //FOR(i = 0; i < SFM_N_WB; ++i) - //{ - // st->hHQ_core->prev_env_fx[i] = floatToFixed(st->hHQ_core->prev_env[i], st->hHQ_core->prev_env_Q[i]); - //} - //floatToFixed_arrL(st->hHQ_core->prev_normq, st->hHQ_core->prev_normq_fx, 14, SFM_N_WB); } - floatToFixed_arr(st->previoussynth, st->previoussynth_fx, 0, L_FRAME48k); - //floatToFixed_arr(st->delay_buf_out, st->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP); if (st->hTcxDec != NULL) { @@ -1283,13 +1429,9 @@ ivas_error ivas_core_dec( } /*size of synth is choosen as delay comp to start with*/ - // synth //Q0 -> Qsynth - // output_fx //Q ? - // delay_buf_buf //Q0 -> Q_old_postdec - // fer_samples //Q0 -> Q? /*-------------------cldfb-start-------------------------*/ - Word16 cldfb_size = (Word16)(st->L_frame / 16 + 0.5); + //Word16 cldfb_size = (Word16)(st->L_frame / 16 + 0.5); floatToFixed_arrL(st->bpf_noise_buf_float, st->bpf_noise_buf_32, 11, L_FRAME_16k); if (st->cldfbAna != NULL) @@ -1307,26 +1449,10 @@ ivas_error ivas_core_dec( /*-------------------cldfb-end---------------------------*/ - //floatToFixed_arr(st->old_exc, st->old_exc_fx, st->Q_exc, L_EXC_MEM_DEC); - IF(st->hWIDec != NULL) - { - floatToFixed_arr(st->hWIDec->old_exc2, st->hWIDec->old_exc2_fx, st->Q_exc, L_EXC_MEM); - } - if (st->hMusicPF != NULL) - { - //floatToFixed_arr(st->hMusicPF->dct_post_old_exc, st->hMusicPF->dct_post_old_exc_fx, st->Q_exc, DCT_L_POST - OFFSET2); - } - if (st->hBPF) { - floatToFixed_arr(st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, st->Q_syn2 - 1, NBPSF_PIT_MAX); - st->hBPF->pst_mem_deemp_err_fx = (Word16)floatToFixed(st->hBPF->pst_mem_deemp_err, st->Q_syn2 - 1); - floatToFixed_arr(st->hBPF->mem_mean_pit, st->hBPF->mem_mean_pit_fx, Q4, L_TRACK_HIST); - st->hBPF->psf_att_fx = float_to_fix16(st->hBPF->psf_att, Q15); - } - - Word32 old_syn_12k8_16k_fx[L_FRAME16k]; + //Word32 old_syn_12k8_16k_fx[L_FRAME16k]; Word16 q_audio, old_syn_fx; old_syn_fx = Q11; - floatToFixed_arrL(old_syn_12k8_16k[n], old_syn_12k8_16k_fx, old_syn_fx, L_FRAME16k); + //floatToFixed_arrL(old_syn_12k8_16k[n], old_syn_12k8_16k_fx, old_syn_fx, L_FRAME16k); q_audio = Q12; #endif @@ -1336,16 +1462,33 @@ ivas_error ivas_core_dec( test(); test(); test(); test(); IF ( (EQ_16(st->bwidth, SWB) || EQ_16(st->bwidth, FB) ) && (EQ_16(st->last_extl, SWB_TBE) || EQ_16(st->last_extl, FB_TBE) ) ) { - GenTransition_fixed( st->hBWE_TD, hb_synth_fx[n], output_Fs, st->element_mode, st->L_frame, st->rf_flag, st->total_brate ); + GenTransition_fixed( st->hBWE_TD, hb_synth_fxg[n], output_Fs, st->element_mode, st->L_frame, st->rf_flag, st->total_brate ); } ELSE IF (EQ_16(st->bwidth, WB) && EQ_16(st->last_extl, WB_TBE) ) { - GenTransition_WB_fixed( st->hBWE_TD, hb_synth_fx[n], output_Fs ); + GenTransition_WB_fixed( st->hBWE_TD, hb_synth_fxg[n], output_Fs ); move16(); - } + } + + /* Memories Scaling */ + Copy_Scale_sig_32_16(st->hBWE_TD->syn_overlap_fx_32, st->hBWE_TD->syn_overlap_fx, sub(11, st->prev_Q_bwe_syn2), L_SHB_LAHEAD); + Copy_Scale_sig_32_16(st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, sub(11, st->prev_Qx), L_SHB_TRANSITION_LENGTH); + Copy_Scale_sig_32_16(st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, sub(11, st->prev_Qx), add(shl(ALLPASSSECTIONS_STEEP, 1), 1)); + Copy_Scale_sig_32_16(st->hBWE_TD->state_lsyn_filt_shb_fx_32, st->hBWE_TD->state_lsyn_filt_shb_fx, sub(11, st->prev_Qx), add(shl(ALLPASSSECTIONS_STEEP, 1), 1)); + Copy_Scale_sig_32_16(st->hBWE_TD->mem_resamp_HB_fx_32, st->hBWE_TD->mem_resamp_HB_fx, sub(11, st->prev_Qx), INTERP_3_1_MEM_LEN); } + /* 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, negate(sub(11, st->prev_Q_bwe_syn2)), L_SHB_LAHEAD); + Copy_Scale_sig_16_32(st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, negate(sub(11, st->prev_Qx)), L_SHB_TRANSITION_LENGTH); + Copy_Scale_sig_16_32(st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, negate(sub(11, st->prev_Qx)), add(shl(ALLPASSSECTIONS_STEEP, 1), 1)); + Copy_Scale_sig_16_32(st->hBWE_TD->state_lsyn_filt_shb_fx, st->hBWE_TD->state_lsyn_filt_shb_fx_32, negate(sub(11, st->prev_Qx)), add(shl(ALLPASSSECTIONS_STEEP, 1), 1)); + Copy_Scale_sig_16_32(st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->mem_resamp_HB_fx_32, sub(11, st->prev_Qx), INTERP_3_1_MEM_LEN); + 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 *---------------------------------------------------------------------*/ @@ -1354,7 +1497,7 @@ ivas_error ivas_core_dec( test(); test(); 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))) { - Copy32(synth_fx[n], hSCE->save_synth_fx, output_frame); + Copy_Scale_sig_16_32(synth_fx16, hSCE->save_synth_fx, output_frame, 0); } IF ( ( error = core_switching_post_dec_ivas_fx( st, synth_fx16, output_fx32, output_mem_fx, ( st_ivas != NULL ) ? st_ivas->ivas_format : UNDEFINED_FORMAT, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, ( hCPE != NULL ) ? hCPE->last_element_mode : IVAS_SCE, &Q_synth ) ) != IVAS_ERR_OK ) @@ -1366,7 +1509,7 @@ ivas_error ivas_core_dec( test(); test(); test(); IF (sba_dirac_stereo_flag && hSCE && EQ_32(st->core_brate, SID_2k40) && EQ_16(st->cng_type, FD_CNG)) { - Copy32(synth_fx[n], hSCE->save_synth_fx, output_frame); + Copy_Scale_sig_16_32(synth_fx16, hSCE->save_synth_fx, output_frame, 0); } /* 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 */ @@ -1379,7 +1522,7 @@ ivas_error ivas_core_dec( * Pre-processing for bandwidth switching *---------------------------------------------------------------------*/ - ivas_bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx, old_syn_fx, q_audio ); + ivas_bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx[n], old_syn_fx, q_audio ); Copy_Scale_sig_16_32(st->delay_buf_out_fx, st->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP, Q11); @@ -1389,40 +1532,13 @@ ivas_error ivas_core_dec( // Delete from here FOR(int ch_ind = 0; ch_ind < n_channels; ch_ind++) { - fixedToFloat_arrL(hb_synth_fx[ch_ind], hb_synth[ch_ind], 11, L_FRAME48k); - } - if (st->hBWE_TD != NULL) - { - - fixedToFloat_arrL(st->hBWE_TD->syn_overlap_fx_32, st->hBWE_TD->syn_overlap, 11, L_SHB_LAHEAD); - fixedToFloat_arrL(st->hBWE_TD->int_3_over_2_tbemem_dec_fx_32, st->hBWE_TD->int_3_over_2_tbemem_dec, 11, INTERP_3_2_MEM_LEN); - fixedToFloat_arrL(st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, st->hBWE_TD->genSHBsynth_Hilbert_Mem, 11, HILBERT_MEM_SIZE); - fixedToFloat_arrL(st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 11, 2 * ALLPASSSECTIONS_STEEP); - fixedToFloat_arrL(st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth, 11, L_SHB_TRANSITION_LENGTH); - fixedToFloat_arrL(st->hBWE_TD->mem_resamp_HB_32k_fx_32, st->hBWE_TD->mem_resamp_HB_32k, 11, 2 * ALLPASSSECTIONS_STEEP + 1); - fixedToFloat_arrL(st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, st->hBWE_TD->state_lsyn_filt_dwn_shb, 11, 2 * ALLPASSSECTIONS_STEEP + 1); - fixedToFloat_arrL(st->hBWE_TD->state_lsyn_filt_shb_fx_32, st->hBWE_TD->state_lsyn_filt_shb, 11, 2 * ALLPASSSECTIONS_STEEP + 1); - - fixedToFloat_arrL(st->hBWE_TD->mem_resamp_HB_fx_32, st->hBWE_TD->mem_resamp_HB, 11, INTERP_3_1_MEM_LEN); - + fixedToFloat_arrL(hb_synth_fxg[ch_ind], hb_synth[ch_ind], 11, L_FRAME48k); } } if (sba_dirac_stereo_flag && st->element_mode != IVAS_CPE_MDCT && !(st->core_brate == SID_2k40 && st->cng_type == FD_CNG)) { mvr2r(synth[n], hSCE->save_synth, output_frame); } - //fixedToFloat_arr(st->old_exc_fx, st->old_exc, st->Q_exc, L_EXC_MEM_DEC); - if (st->hMusicPF != NULL) - { - //fixedToFloat_arr(st->hMusicPF->dct_post_old_exc_fx, st->hMusicPF->dct_post_old_exc, st->Q_exc, DCT_L_POST - OFFSET2); - } - if (st->hBPF) { - fixedToFloat_arr(st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, st->Q_syn2 - 1, NBPSF_PIT_MAX); - st->hBPF->pst_mem_deemp_err = fixedToFloat(st->hBPF->pst_mem_deemp_err_fx, st->Q_syn2 - 1); - fixedToFloat_arr(st->hBPF->mem_mean_pit_fx, st->hBPF->mem_mean_pit, Q4, L_TRACK_HIST); - st->hBPF->psf_att = fixedToFloat(st->hBPF->psf_att_fx, Q15); - } - /*-------------------cldfb-start-------------------------*/ /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ @@ -1444,18 +1560,10 @@ ivas_error ivas_core_dec( fixedToFloat_arr(synth_fx16, synth[n], Q_synth, L_FRAME48k); fixedToFloat_arrL(output_fx32, output[n], 4, L_FRAME48k); - //fixedToFloat_arr(st->delay_buf_out_fx, st->delay_buf_out, 0, HQ_DELTA_MAX * HQ_DELAY_COMP); IF(st->hHQ_core != NULL) { fixedToFloat_arr(st->hHQ_core->old_out_fx, st->hHQ_core->old_out, 0, L_FRAME48k); - fixedToFloat_arr(st->hHQ_core->fer_samples_fx, st->hHQ_core->fer_samples, 0, NS2SA(st->output_Fs, 3000000)); - //FOR(i = 0; i < SFM_N_WB; ++i) - //{ - // st->hHQ_core->prev_env[i] = fixedToFloat(st->hHQ_core->prev_env_fx[i], st->hHQ_core->prev_env_Q[i]); - //} - //fixedToFloat_arrL(st->hHQ_core->prev_normq_fx, st->hHQ_core->prev_normq, 14, SFM_N_WB); } - fixedToFloat_arr(st->previoussynth_fx, st->previoussynth, 0, L_FRAME48k); @@ -1464,122 +1572,21 @@ ivas_error ivas_core_dec( /*reset function flags*/ Word8 reset_wb_tbe_synth = 0; Word8 reset_swb_tbe = 0; - Word8 reset_swb_tbe_synth = 0; - - if (st->hBWE_FD != NULL) - { - st->hBWE_FD->mem_deemph_old_syn = fixedToFloat(st->hBWE_FD->mem_deemph_old_syn_fx, 0); - } - - IF((NE_16(st->last_extl, SWB_BWE) && EQ_16(st->extl, SWB_BWE)) || (NE_16(st->last_extl, FB_BWE) && EQ_16(st->extl, FB_BWE)) || - ((EQ_16(st->last_core, HQ_CORE) || EQ_16(st->last_extl, SWB_TBE)) && st->extl < 0 && NE_16(st->core, HQ_CORE)) || (EQ_16(st->last_core, ACELP_CORE) && EQ_16(st->core, ACELP_CORE) && ((NE_16(st->prev_coder_type, INACTIVE) && EQ_16(st->coder_type, INACTIVE)) || (NE_16(st->prev_coder_type, AUDIO) && EQ_16(st->coder_type, AUDIO))) && st->bws_cnt > 0)) - { - fixedToFloat_arr(st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, 0, output_frame); - - st->hBWE_FD->prev_Energy = fixedToFloat(st->hBWE_FD->prev_Energy_fx, 0); // setting to zero - st->hBWE_FD->prev_frica_flag = st->hBWE_FD->prev_frica_flag; // fixed - st->hBWE_FD->prev_td_energy = st->hBWE_FD->prev_td_energy_fx; // setting to zero - st->hBWE_FD->prev_weight = fixedToFloat(st->hBWE_FD->prev_weight_fx, 15); // 6554; /*0.2 in Q15*/ - st->hBWE_FD->prev_fb_ener_adjust = fixedToFloat(st->prev_fb_ener_adjust_fx, 0); // setting to zero - fixedToFloat_arr(st->hBWE_FD->mem_imdct_fx, st->hBWE_FD->mem_imdct, 0, L_FRAME48k); // setting to zero - } /* reset WB BWE buffers */ IF(NE_16(st->last_extl, WB_BWE) && EQ_16(st->extl, WB_BWE) && st->hBWE_FD != NULL) { - // set16_fx( st->hBWE_FD->L_old_wtda_swb_fx, 0, output_frame ); - fixedToFloat_arr(st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, 0, output_frame); IF(NE_16(st->last_extl, SWB_BWE) && NE_16(st->last_extl, FB_BWE)) { st->hBWE_FD->prev_mode = st->hBWE_FD->prev_mode; } - st->hBWE_FD->prev_Energy_wb = (float)st->hBWE_FD->prev_Energy_wb_fx; st->hBWE_FD->prev_L_swb_norm = st->hBWE_FD->prev_L_swb_norm; st->hBWE_FD->prev_flag = st->hBWE_FD->prev_flag; - fixedToFloat_arr(st->hBWE_FD->mem_imdct_fx, st->hBWE_FD->mem_imdct, 0, L_FRAME48k); // setting to zero - } - - /* reset TBE buffers */ - if (st->hBWE_TD != NULL) - { - IF(((EQ_16(st->extl, SWB_TBE) || EQ_16(st->extl, FB_TBE) || EQ_16(st->extl, SWB_CNG)) && - (NE_16(st->L_frame, st->last_L_frame) || (NE_16(st->last_extl, SWB_TBE) && NE_16(st->last_extl, FB_TBE)) || EQ_16(st->last_core, HQ_CORE))) || - (LT_16(st->bwidth, st->last_bwidth) && NE_16(st->last_extl, SWB_TBE)) || st->old_ppp_mode || ((EQ_16(st->prev_coder_type, AUDIO) || EQ_16(st->prev_coder_type, INACTIVE)) && st->bws_cnt > 0) || (st->bws_cnt == 0 && EQ_16(st->prev_bws_cnt, N_WS2N_FRAMES))) - { - - reset_swb_tbe = 1; - reset_swb_tbe_synth = 1; - - IF(EQ_16(output_frame, L_FRAME16k)) - { - /* reset in case that SWB TBE layer is transmitted, but the output x`x`is 16kHz sampled */ - fixedToFloat_arr(st->hBWE_TD->mem_resamp_HB_32k_fx, st->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1); - } - fixedToFloat_arr(st->hBWE_TD->int_3_over_2_tbemem_dec_fx, st->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN); - } - ELSE IF(st->hBWE_TD != NULL && (st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE)) - { - /*------------TBEreset_dec_ivas_fx-start------------------*/ - IF(EQ_16(st->bwidth, WB)) - { - reset_wb_tbe_synth = 1; - - fixedToFloat_arr(st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD); - } - ELSE IF(EQ_16(st->bwidth, SWB) || EQ_16(st->bwidth, FB)) - { - reset_swb_tbe = 1; - reset_swb_tbe_synth = 1; - fixedToFloat_arr(st->hBWE_TD->int_3_over_2_tbemem_dec_fx, st->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN); // setting to zero - fixedToFloat_arr(st->hBWE_TD->mem_resamp_HB_32k_fx, st->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1); // setting to zero - - IF(EQ_16(st->bwidth, FB)) - { - IF(st->hBWE_FD != NULL) - { - st->hBWE_FD->prev_fb_ener_adjust = fixedToFloat(st->prev_fb_ener_adjust_fx, 0); - } - fixedToFloat_arr(st->hBWE_TD->fb_state_lpc_syn_fx, st->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER); - } - } - /*------------TBEreset_dec_ivas_fx-end--------------------*/ - } - - IF(EQ_16(st->extl, FB_TBE) && (NE_16(st->last_extl, FB_TBE) || NE_16(st->L_frame, st->last_L_frame))) - { - fixedToFloat_arr(st->hBWE_TD->fb_state_lpc_syn_fx, st->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER); - } - - - IF(NE_16(st->last_extl, WB_TBE) && EQ_16(st->extl, WB_TBE)) - { - reset_wb_tbe_synth = 1; - fixedToFloat_arr(st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD); // setting to zero - } - - IF(reset_swb_tbe) - { - fixedToFloat_arr(st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD); // setting to zero - } - IF(reset_swb_tbe_synth) - { - fixedToFloat_arrL(st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, st->hBWE_TD->genSHBsynth_Hilbert_Mem, 0, HILBERT_MEM_SIZE); // setting to zero // setting to zero - fixedToFloat_arr(st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 0, 2 * ALLPASSSECTIONS_STEEP); // setting to zero - } - IF(reset_wb_tbe_synth) - { - fixedToFloat_arr(st->hBWE_TD->state_lsyn_filt_shb_fx, st->hBWE_TD->state_lsyn_filt_shb, 0, 2 * ALLPASSSECTIONS_STEEP); // setting to zero - fixedToFloat_arr(st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->hBWE_TD->state_lsyn_filt_dwn_shb, 0, 2 * ALLPASSSECTIONS_STEEP); // setting to zero - // fixedToFloat(st->hBWE_TD->state_32and48k_WB_upsample_fx, st->hBWE_TD->state_32and48k_WB_upsample,0, 2 * ALLPASSSECTIONS_STEEP); buffer not there in float code* - fixedToFloat_arr(st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->mem_resamp_HB, 0, INTERP_3_1_MEM_LEN); // setting to zero - } } - /*------------------reset-code-end-----------------------*/ free(synth_fx16); - //free(output_fx32); free(output_mem_fx); if (sba_dirac_stereo_flag && hSCE && st->core_brate == SID_2k40 && st->cng_type == FD_CNG) @@ -1587,36 +1594,26 @@ ivas_error ivas_core_dec( mvr2r(synth[n], hSCE->save_synth, output_frame); } - /* 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 */ - if (n == 0 && st->element_mode == IVAS_CPE_MDCT && st->last_core == ACELP_CORE && st->core != ACELP_CORE && (nchan_out == 1 || (hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_DFT))) - { - mvr2r(sts[0]->previoussynth, sts[1]->previoussynth, st->hTcxDec->L_frameTCX); - } - - st->enerLH = fixedToFloat(st->enerLH_fx, st->enerLH_fx_Q); // Q / 2 - st->enerLL = fixedToFloat(st->enerLL_fx, st->enerLL_fx_Q); #endif /*---------------------------------------------------------------------* * WB TBE decoding * WB BWE decoding *---------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED + #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; - Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; + //Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; + //Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; Word16 hb_synth_fx_16[CPE_CHANNELS][L_FRAME48k]; - Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; + //Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; Word16 output_fx_16[CPE_CHANNELS][L_FRAME48k]; Word16 synth_fx_16[CPE_CHANNELS][L_FRAME48k]; - Word16 Q_input, Q_hb_synth_fx, Q_synth_fx, i; + Word16 Q_input, Q_hb_synth_fx, Q_synth_fx; Word32 synth_fx32[L_FRAME48k]; Word32 hb_synth_fx32[L_FRAME48k]; Word16 Q_syn_hb; - //st->Q_syn = 0; - //st->Q_exc = 8; Q_input = 0; Q_hb_synth_fx = 0; Q_synth_fx = 0; @@ -1628,91 +1625,16 @@ ivas_error ivas_core_dec( FD_BWE_DEC_HANDLE hBWE_FD; hBWE_FD = st->hBWE_FD; - st->prev_tilt_code_dec_fx = (Word16) floatToFixed( st->prev_tilt_code_dec, Q15 ); - floatToFixed_arr( voice_factors[n], voice_factors_fx[n], Q15, NB_SUBFR16k ); - floatToFixed_arr( pitch_buf[n], pitch_buf_fx[n], Q6, NB_SUBFR16k ); - st->cummulative_damping = float_to_fix16( st->cummulative_damping_float, Q15 ); - st->prev_ener_shb_fx = float_to_fix16( st->prev_ener_shb, 1 ); - st->enerLH_fx = floatToFixed( st->enerLH, 0 ); // Check if Q_syn2 - st->prev_enerLH_fx = floatToFixed( st->prev_enerLH, 0 ); // Check if Q_syn2 - - floatToFixed_arrL( old_syn_12k8_16k[n], old_syn_12k8_16k_fx, Q11, L_FRAME16k ); // Can be removed got from last fn + //floatToFixed_arrL( old_syn_12k8_16k[n], old_syn_12k8_16k_fx, Q11, L_FRAME16k ); // Can be removed got from last fn - floatToFixed_arrL( bwe_exc_extended[n], bwe_exc_extended_fx[n], 2 * st->Q_exc, L_FRAME32k + NL_BUFF_OFFSET ); + //floatToFixed_arrL( bwe_exc_extended[n], bwe_exc_extended_fx[n], 2 * st->Q_exc, L_FRAME32k + NL_BUFF_OFFSET ); floatToFixed_arr( hb_synth[n], hb_synth_fx_16[n], Q_hb_synth_fx, L_FRAME48k ); floatToFixed_arr( output[n], output_fx_16[n], Q_input, L_FRAME48k ); floatToFixed_arr( synth[n], synth_fx_16[n], Q_synth_fx, L_FRAME48k ); IF( hBWE_TD != NULL ) { - floatToFixed_arr( hBWE_TD->state_lsyn_filt_shb, hBWE_TD->state_lsyn_filt_shb_fx, st->prev_Qx, 2 * ALLPASSSECTIONS_STEEP ); - floatToFixed_arr( hBWE_TD->state_lsyn_filt_dwn_shb, hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->prev_Qx, 2 * ALLPASSSECTIONS_STEEP ); - - floatToFixed_arr( hBWE_TD->mem_resamp_HB, hBWE_TD->state_32and48k_WB_upsample_fx, st->prev_Qx, 2 * ALLPASSSECTIONS_STEEP ); - floatToFixed_arr( hBWE_TD->mem_resamp_HB, hBWE_TD->mem_resamp_HB_fx, st->prev_Qx, INTERP_3_1_MEM_LEN ); - floatToFixed_arr( hBWE_TD->old_bwe_exc_extended, hBWE_TD->old_bwe_exc_extended_fx, st->prev_Q_bwe_exc - 16, NL_BUFF_OFFSET ); - - floatToFixed_arr( hBWE_TD->fb_state_lpc_syn, hBWE_TD->fb_state_lpc_syn_fx, st->prev_Q_bwe_exc_fb - 16 - 4, LPC_SHB_ORDER ); - - hBWE_TD->prev_wb_bwe_frame_pow_fx = floatToFixed( hBWE_TD->prev_wb_bwe_frame_pow, st->prev_frame_pow_exp ); - - floatToFixed_arr( hBWE_TD->old_tbe_synth, hBWE_TD->old_tbe_synth_fx, st->prev_Qx, L_SHB_TRANSITION_LENGTH ); - floatToFixed_arr( hBWE_TD->syn_overlap, hBWE_TD->syn_overlap_fx, st->prev_Q_bwe_syn2, L_SHB_LAHEAD ); // Check - - for ( int i = 0; i < INTERP_3_2_MEM_LEN; i++ ) - { - st->hBWE_TD->int_3_over_2_tbemem_dec_fx_32[i] = floatToFixed( st->hBWE_TD->int_3_over_2_tbemem_dec[i], Q11 ); - } - for ( int i = 0; i < HILBERT_MEM_SIZE; i++ ) - { - st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = floatToFixed( st->hBWE_TD->genSHBsynth_Hilbert_Mem[i], Q11 ); - } - for ( int i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) - { - st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32[i] = floatToFixed( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local[i], Q11 ); - } - - for ( int i = 0; i < 2 * ALLPASSSECTIONS_STEEP + 1; i++ ) - { - st->hBWE_TD->mem_resamp_HB_32k_fx_32[i] = floatToFixed( st->hBWE_TD->mem_resamp_HB_32k[i], Q11 ); - } - } - - IF( hBWE_FD != NULL ) - { - st->last_wb_bwe_ener_fx = (Word16) floatToFixed( hBWE_FD->last_wb_bwe_ener, Q3 ); - floatToFixed_arr( hBWE_FD->prev_SWB_fenv, st->prev_SWB_fenv_fx, Q1, SWB_FENV ); - floatToFixed_arr( hBWE_FD->mem_imdct, hBWE_FD->mem_imdct_fx, hBWE_FD->mem_imdct_exp_fx, L_FRAME48k ); - - st->hBWE_FD->prev_Energy_fx = (Word16) ( st->hBWE_FD->prev_Energy * ( 1 << 3 ) ); - st->hBWE_FD->prev_weight_fx = (Word16) ( st->hBWE_FD->prev_weight * ( 1 << 15 ) ); - - st->hBWE_FD->prev_td_energy_fx = (Word16) st->hBWE_FD->prev_td_energy; - - hBWE_FD->prev_Energy_wb_fx = floatToFixed( hBWE_FD->prev_Energy_wb, st->prev_Q_synth ); - } - - IF( st->hTdCngDec != NULL ) - { - st->hTdCngDec->shb_cng_gain_fx_32 = float_to_fix(st->hTdCngDec->shb_cng_gain, Q11); - st->hTdCngDec->shb_cng_ener_fx_32 = float_to_fix(st->hTdCngDec->shb_cng_ener, Q11); - } - - if ( hStereoICBWE != NULL ) - { - if ( hStereoICBWE->nlExc16k && hStereoICBWE->nlExc16k_fx ) - { - floatToFixed_arr( hStereoICBWE->nlExc16k, hStereoICBWE->nlExc16k_fx, st->prev_Q_bwe_exc - 16, L_FRAME16k ); - } - if ( hStereoICBWE->mixExc16k && hStereoICBWE->mixExc16k_fx ) - { - floatToFixed_arr( hStereoICBWE->mixExc16k, hStereoICBWE->mixExc16k_fx, st->Q_exc, L_FRAME16k ); - } - floatToFixed_arrL( hStereoICBWE->lpSHBRef, hStereoICBWE->lpSHBRef_fx, Q12, LPC_SHB_ORDER + 1 ); - floatToFixed_arr( hStereoICBWE->gshapeRef, hStereoICBWE->gshapeRef_fx, Q15, NUM_SHB_SUBFR ); - floatToFixed_arrL( &hStereoICBWE->gFrameRef, &hStereoICBWE->gFrameRef_fx, Q18, 1 ); - floatToFixed_arr( hStereoICBWE->shbSynthRef, hStereoICBWE->shbSynthRef_fx, st->prev_Qx, L_FRAME16k ); } #endif test(); @@ -1721,6 +1643,10 @@ ivas_error ivas_core_dec( test(); test(); test(); + IF(hBWE_TD != NULL) + { + //Copy_Scale_sig_32_16(hBWE_TD->syn_overlap_fx_32, hBWE_TD->syn_overlap_fx, -st->prev_Q_bwe_syn2, L_SHB_LAHEAD); // Check + } IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE decoder */ @@ -1737,12 +1663,10 @@ ivas_error ivas_core_dec( Q_hb_synth_fx = ivas_wb_bwe_dec_fx( st, output_fx_16[n], synth_fx_16[n], hb_synth_fx_16[n], use_cldfb_for_dft, output_frame, voice_factors_fx[n], pitch_buf_fx[n], &Q_synth_fx ); } - // Scale hb_synth_fx_16, output_fx_16 and synth_fx_16 to Q11 Copy_Scale_sig_16_32( hb_synth_fx_16[n], hb_synth_fx32, L_FRAME48k, Q11 - Q_hb_synth_fx ); Copy_Scale_sig_16_32( output_fx_16[n], output_fx32, L_FRAME48k, Q11 - Q_input ); Copy_Scale_sig_16_32( synth_fx_16[n], synth_fx32, L_FRAME48k, Q11 - Q_synth_fx ); - // Scaling for old_tbe_synth_fx_32, mem_resamp_HB_32k_fx_32 and L_old_wtda_swb_fx32 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, Q11 - hBWE_FD->old_wtda_swb_fx_exp ); @@ -1770,15 +1694,16 @@ ivas_error ivas_core_dec( IF( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) || ( NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) && GE_32( st->core_brate, SID_2k40 ) && EQ_16( st->core, ACELP_CORE ) && !st->con_tcx && GE_32( output_Fs, 32000 ) && GT_16( st->bwidth, NB ) && GT_16( st->bws_cnt, 0 ) ) ) { /* SWB TBE decoder */ - Q_white_exc = 0; + Q_white_exc = 0; 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_fx32, pitch_buf_fx[n], &Q_white_exc ); - ivas_swb_tbe_dec_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx, tmp_buffer_fx /*fb_exc*/, hb_synth_fx32, pitch_buf_fx[n], &Q_white_exc ); Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, st->prev_Qx - Q11 ); // Check - IF( Q_white_exc > 31 ) + IF( GT_16(Q_white_exc, 31 )) { Scale_sig( tmp_buffer_fx, L_FRAME48k, 31 - Q_white_exc ); - Q_white_exc = 31; + Q_white_exc = 31; move16(); } /* FB TBE decoder */ @@ -1838,36 +1763,28 @@ ivas_error ivas_core_dec( { /* SHB CNG decoder */ #ifdef IVAS_FLOAT_FIXED - Word16 synth_fx[960], hb_synth_fx[960]; /* Q-2 */ + Word16 synth_fxl[960], hb_synth_fxl[960]; /* Q-2 */ Word16 q = 2; - st->prev_Q_bwe_syn2 = 0; - Copy_Scale_sig_32_16(hb_synth_fx32, hb_synth_fx, L_FRAME48k, -(Q11 + q)); - Copy_Scale_sig_32_16(synth_fx32, synth_fx, L_FRAME48k, -(Q11 + q)); + //st->prev_Q_bwe_syn2 = 0; + Copy_Scale_sig_32_16(hb_synth_fx32, hb_synth_fxl, L_FRAME48k, -(Q11 + q)); + Copy_Scale_sig_32_16(synth_fx32, synth_fxl, L_FRAME48k, -(Q11 + q)); Scale_sig(st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, (Q8 - st->prev_Q_bwe_syn)); - Scale_sig32(st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, -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, -Q11); + Scale_sig32(st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, (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, (st->prev_Q_bwe_syn2 - Q11)); - swb_CNG_dec_ivas_fx( st, synth_fx, hb_synth_fx, sid_bw[n], -q ); + swb_CNG_dec_ivas_fx( st, synth_fxl, hb_synth_fxl, sid_bw[n], -q ); - Copy_Scale_sig_16_32(hb_synth_fx, hb_synth_fx32, L_FRAME48k, (Q11 + q)); - Copy_Scale_sig_16_32(synth_fx, synth_fx32, L_FRAME48k, (Q11 + q)); + Copy_Scale_sig_16_32(hb_synth_fxl, hb_synth_fx32, L_FRAME48k, (Q11 + q)); + Copy_Scale_sig_16_32(synth_fxl, synth_fx32, L_FRAME48k, (Q11 + q)); Scale_sig(st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, -(Q8 - st->prev_Q_bwe_syn)); - Scale_sig32(st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, Q11); - Copy_Scale_sig_16_32(st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 2 * ALLPASSSECTIONS_STEEP, Q11); + Scale_sig32(st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, -(st->prev_Q_bwe_syn2 - Q11)); + Copy_Scale_sig_16_32(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)); #endif } #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - st->prev_tilt_code_dec = fixedToFloat(st->prev_tilt_code_dec_fx, Q15); - fixedToFloat_arr(voice_factors_fx[n], voice_factors[n], Q15, NB_SUBFR16k); - fixedToFloat_arr(pitch_buf_fx[n], pitch_buf[n], Q6, NB_SUBFR16k); - st->prev_ener_shb = (float)st->prev_ener_shb_fx / 2; - st->cummulative_damping_float = fixedToFloat(st->cummulative_damping, Q15); - st->prev_ener_shb = fixedToFloat(st->prev_ener_shb_fx, 1); - st->enerLH = fixedToFloat(st->enerLH_fx, 0); // Check if Q_syn2 - st->prev_enerLH = fixedToFloat(st->prev_enerLH_fx, 0); // Check if Q_syn2 - fixedToFloat_arrL(bwe_exc_extended_fx[n], bwe_exc_extended[n], 2 * st->Q_exc, L_FRAME32k + NL_BUFF_OFFSET); + //fixedToFloat_arrL(bwe_exc_extended_fx[n], bwe_exc_extended[n], 2 * st->Q_exc, L_FRAME32k + NL_BUFF_OFFSET); fixedToFloat_arrL(hb_synth_fx32, hb_synth[n], Q11, L_FRAME48k); fixedToFloat_arrL(output_fx32, output[n], Q11, L_FRAME48k); @@ -1882,146 +1799,28 @@ ivas_error ivas_core_dec( fixedToFloat_arr(hBWE_TD->old_bwe_exc_extended_fx, hBWE_TD->old_bwe_exc_extended, st->prev_Q_bwe_exc - 16, NL_BUFF_OFFSET); - if (st->prev_Q_bwe_exc_fb != 51) - { - fixedToFloat_arr(hBWE_TD->fb_state_lpc_syn_fx, hBWE_TD->fb_state_lpc_syn, st->prev_Q_bwe_exc_fb - 16 - 4, LPC_SHB_ORDER); - } - else - { - hBWE_TD->fb_tbe_demph = 0; - set_f(hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER); - } - hBWE_TD->prev_wb_bwe_frame_pow = fixedToFloat(hBWE_TD->prev_wb_bwe_frame_pow_fx, st->prev_frame_pow_exp); - fixedToFloat_arr(hBWE_TD->syn_overlap_fx, hBWE_TD->syn_overlap, st->prev_Q_bwe_syn2, L_SHB_LAHEAD); // Check - for (int i = 0; i < INTERP_3_2_MEM_LEN; i++) - { - st->hBWE_TD->int_3_over_2_tbemem_dec[i] = fixedToFloat(st->hBWE_TD->int_3_over_2_tbemem_dec_fx_32[i], Q11); - } - for (int i = 0; i < HILBERT_MEM_SIZE; i++) - { - st->hBWE_TD->genSHBsynth_Hilbert_Mem[i] = fixedToFloat(st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], Q11); - } - for (int i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++) + for (int ii = 0; ii < INTERP_3_2_MEM_LEN; ii++) { - st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local[i] = fixedToFloat(st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32[i], Q11); + st->hBWE_TD->int_3_over_2_tbemem_dec[ii] = fixedToFloat(st->hBWE_TD->int_3_over_2_tbemem_dec_fx_32[ii], Q11); } - for (int i = 0; i < L_SHB_TRANSITION_LENGTH; i++) + for (int ii = 0; ii < L_SHB_TRANSITION_LENGTH; ii++) { - st->hBWE_TD->old_tbe_synth[i] = fixedToFloat(hBWE_TD->old_tbe_synth_fx_32[i], Q11); + st->hBWE_TD->old_tbe_synth[ii] = fixedToFloat(hBWE_TD->old_tbe_synth_fx_32[ii], Q11); } - for (int i = 0; i < 2 * ALLPASSSECTIONS_STEEP + 1; i++) + for (int ii = 0; ii < 2 * ALLPASSSECTIONS_STEEP + 1; ii++) { - st->hBWE_TD->mem_resamp_HB_32k[i] = fixedToFloat(st->hBWE_TD->mem_resamp_HB_32k_fx_32[i], Q11); + st->hBWE_TD->mem_resamp_HB_32k[ii] = fixedToFloat(st->hBWE_TD->mem_resamp_HB_32k_fx_32[ii], Q11); } } - - IF(hBWE_FD != NULL) - { - hBWE_FD->last_wb_bwe_ener = fixedToFloat(st->last_wb_bwe_ener_fx, Q3); - fixedToFloat_arr(st->prev_SWB_fenv_fx, hBWE_FD->prev_SWB_fenv, Q1, SWB_FENV); - fixedToFloat_arr(hBWE_FD->mem_imdct_fx, hBWE_FD->mem_imdct, hBWE_FD->mem_imdct_exp_fx, L_FRAME48k); - - st->hBWE_FD->prev_Energy = ((float)st->hBWE_FD->prev_Energy_fx / (1 << 3)); - st->hBWE_FD->prev_weight = ((float)st->hBWE_FD->prev_weight_fx / (1 << 15)); - st->hBWE_FD->prev_td_energy = (float)st->hBWE_FD->prev_td_energy_fx; - - hBWE_FD->prev_Energy_wb = fixedToFloat(hBWE_FD->prev_Energy_wb_fx, st->prev_Q_synth); - - // Check - fixedToFloat_arrL(hBWE_FD->L_old_wtda_swb_fx32, hBWE_FD->old_wtda_swb, Q11, L_FRAME48k); - } - - IF(st->hTdCngDec != NULL) - { - st->hTdCngDec->shb_cng_gain = fix_to_float(st->hTdCngDec->shb_cng_gain_fx_32, Q11); - st->hTdCngDec->shb_cng_ener = fix_to_float(st->hTdCngDec->shb_cng_ener_fx_32, Q11); - } - - if (hStereoICBWE != NULL) - { - if (hStereoICBWE->nlExc16k && hStereoICBWE->nlExc16k_fx) - { - fixedToFloat_arr(hStereoICBWE->nlExc16k_fx, hStereoICBWE->nlExc16k, st->prev_Q_bwe_exc - 16, L_FRAME16k); - } - if (hStereoICBWE->mixExc16k && hStereoICBWE->mixExc16k_fx) - { - fixedToFloat_arr(hStereoICBWE->mixExc16k_fx, hStereoICBWE->mixExc16k, st->Q_exc, L_FRAME16k); - } - fixedToFloat_arrL(hStereoICBWE->lpSHBRef_fx, hStereoICBWE->lpSHBRef, Q12, LPC_SHB_ORDER + 1); - fixedToFloat_arr(hStereoICBWE->gshapeRef_fx, hStereoICBWE->gshapeRef, Q15, NUM_SHB_SUBFR); - fixedToFloat_arrL(&hStereoICBWE->gFrameRef_fx, &hStereoICBWE->gFrameRef, Q18, 1); - fixedToFloat_arr(hStereoICBWE->shbSynthRef_fx, hStereoICBWE->shbSynthRef, st->prev_Qx, L_FRAME16k); - } - - //free(output_fx32); #endif -#else - if ( st->extl == WB_TBE ) - { - /* WB TBE decoder */ - wb_tbe_dec( st, bwe_exc_extended[n], voice_factors[n], hb_synth[n] ); - } - else if ( st->element_mode == IVAS_CPE_TD && n == 1 && !tdm_LRTD_flag && st->extl != -1 && st->bws_cnt == 0 && st->extl_brate == 0 ) - { - /* do nothing */ - } - else if ( st->extl == WB_BWE && st->bws_cnt == 0 ) - { - /* WB BWE decoder */ - wb_bwe_dec_flt( st, output[n], synth[n], hb_synth[n], use_cldfb_for_dft, output_frame, voice_factors[n], pitch_buf[n] ); - } - - /*---------------------------------------------------------------------* - * SWB(FB) TBE decoding - * SWB(FB) BWE decoding - *---------------------------------------------------------------------*/ - if (st->extl == SWB_TBE || st->extl == FB_TBE || (st->coder_type != AUDIO && st->coder_type != INACTIVE && st->core_brate >= SID_2k40 && st->core == ACELP_CORE && !st->con_tcx && output_Fs >= 32000 && st->bwidth > NB && st->bws_cnt > 0)) - { - swb_tbe_dec( st, hStereoICBWE, bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], tmp_buffer /*fb_exc*/, hb_synth[n], pitch_buf[n] ); - if ( st->extl == FB_TBE ) - { - fb_tbe_dec( st, tmp_buffer /*fb_exc*/, hb_synth[n], tmp_buffer /*fb_synth_ref*/, output_frame ); - } - } - else if ( st->extl == SWB_BWE || st->extl == FB_BWE || ( output_Fs >= 32000 && st->core == ACELP_CORE && st->bwidth > NB && st->bws_cnt > 0 && !st->ppp_mode_dec && !( st->nelp_mode_dec == 1 && st->bfi == 1 ) ) ) - { - swb_bwe_dec_flt( st, output[n], synth[n], hb_synth[n], use_cldfb_for_dft, output_frame ); - } - - /*---------------------------------------------------------------------* - * FEC - recovery after lost HQ core (smoothing of the BWE component) - *---------------------------------------------------------------------*/ - - if ( st->prev_bfi && st->last_core == HQ_CORE && st->extl != -1 ) - { - tmp = FRAC_BWE_SMOOTH / output_frame; - - for ( i = 0; i < output_frame / FRAC_BWE_SMOOTH; i++ ) - { - hb_synth[n][i] *= ( i * tmp ); - } - } - - /*---------------------------------------------------------------------* - * SWB CNG - *---------------------------------------------------------------------*/ - - if ( ( output_frame >= L_FRAME32k && st->hTdCngDec != NULL ) || ( st->element_mode == IVAS_CPE_DFT && st->bwidth >= SWB && st->hTdCngDec != NULL ) ) - { - /* SHB CNG decoder */ - swb_CNG_dec( st, synth[n], hb_synth[n], sid_bw[n] ); - } -#endif - /*-------------------------------------------------------------------* * Inter-channel BWE decoding *-------------------------------------------------------------------*/ - - if ( n == 0 && st->element_mode >= IVAS_CPE_DFT ) + test(); + IF ( EQ_16(n, 0) && GE_16(st->element_mode, IVAS_CPE_DFT )) { -#ifdef IVAS_FLOAT_FIXED Word32 *hb_synth_0 = (Word32 *) malloc( sizeof( Word32 ) * L_FRAME48k ); Word32 *hb_synth_1 = (Word32 *) malloc( sizeof( Word32 ) * L_FRAME48k ); Word16 q = 11; @@ -2032,10 +1831,6 @@ ivas_error ivas_core_dec( if ( hCPE->hStereoDft != NULL ) { floatToFixed_arrL( hCPE->hStereoDft->hb_stefi_sig, hCPE->hStereoDft->hb_stefi_sig_fx, q, L_FRAME48k + NS2SA( 48000, STEREO_DFT_TD_STEFI_DELAY_NS ) ); - for ( int lp = 0; lp < 39; lp++ ) - { - hCPE->hStereoDft->side_gain_fx[lp] = (Word32) ( hCPE->hStereoDft->side_gain[lp] * ( 0x7fffffff ) ); - } hCPE->hStereoDft->td_gain_fx[0] = 1; } if ( hCPE->hStereoDftDmx != NULL ) @@ -2043,11 +1838,6 @@ ivas_error ivas_core_dec( hCPE->hStereoDftDmx->targetGain_fx = (Word32) ( hCPE->hStereoDftDmx->targetGain * ( 1u << 29 ) ); } - if ( hCPE->hStereoTCA != NULL ) - { - - hCPE->hStereoTCA->targetGain_fx = (Word32) ( hCPE->hStereoTCA->targetGain * ( 1u << 29 ) ); - } Scale_sig( tmp_buffer_fx, L_FRAME48k, Q11 - Q_white_exc ); stereo_icBWE_dec_fx( hCPE, hb_synth_0, hb_synth_1, tmp_buffer_fx /*fb_synth_ref*/, voice_factors_fx[0], output_frame, &q ); @@ -2074,12 +1864,8 @@ ivas_error ivas_core_dec( free( hb_synth_0 ); free( hb_synth_1 ); -#else - stereo_icBWE_dec( hCPE, hb_synth[0], hb_synth[1], tmp_buffer /*fb_synth_ref*/, voice_factors[0], output_frame ); -#endif } -#ifdef IVAS_FLOAT_FIXED IF( EQ_16( st->element_mode, EVS_MONO ) ) { /*----------------------------------------------------------------* @@ -2097,44 +1883,28 @@ ivas_error ivas_core_dec( st->hPlcInfo->Pitch = 0; } } -#else - if ( st->element_mode == EVS_MONO ) - { - /*----------------------------------------------------------------* - * BFI waveform adjustment - *----------------------------------------------------------------*/ - - if ( st->core == ACELP_CORE && !st->bfi && st->prev_bfi && st->last_total_brate >= HQ_48k && st->last_codec_mode == MODE2 && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hPlcInfo->concealment_method == TCX_NONTONAL && st->hPlcInfo->nbLostCmpt < 4 ) - { - tmps = NS2SA( output_Fs, DELAY_CLDFB_NS ); - - waveform_adj2( st->hPlcInfo, st->hTonalMDCTConc->secondLastPcmOut_float, synth[n] + tmps, tmps, st->hPlcInfo->nbLostCmpt + 1, st->bfi ); - - st->hPlcInfo->Pitch = 0; - } - } -#endif // IVAS_FLOAT_FIXED /*----------------------------------------------------------------* * Transition and synchronization of BWE components *----------------------------------------------------------------*/ - if ( ( st->extl != -1 && ( st->extl != IGF_BWE || st->last_core == ACELP_CORE ) ) || ( st->bws_cnt > 0 && st->core == ACELP_CORE ) ) + test(); test(); test(); test(); + IF ( ( NE_16(st->extl, -1) && ( NE_16(st->extl, IGF_BWE) || EQ_16(st->last_core, ACELP_CORE) ) ) || ( GT_16(st->bws_cnt, 0) && EQ_16(st->core, ACELP_CORE) ) ) { /* Calculate an additional delay of extension layer components to be synchronized with ACELP synthesis */ - if ( st->L_frame == L_FRAME ) + IF ( EQ_16(st->L_frame, L_FRAME )) { /* TBE on top of ACELP@12.8kHz */ tmps = NS2SA( output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); } - else + ELSE { - if ( st->extl == SWB_BWE_HIGHRATE || st->extl == FB_BWE_HIGHRATE ) + IF ( EQ_16(st->extl, SWB_BWE_HIGHRATE) || EQ_16(st->extl, FB_BWE_HIGHRATE )) { /* HR SWB BWE on top of ACELP@16kHz */ tmps = NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ); } - else + ELSE { /* TBE on top of ACELP@16kHz */ tmps = NS2SA( output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); @@ -2142,89 +1912,173 @@ ivas_error ivas_core_dec( } /* Smooth transitions when switching between different technologies */ - if ( !( ( st->core == TCX_20_CORE || st->core == TCX_10_CORE || st->core == HQ_CORE ) && st->last_core == ACELP_CORE ) && - ( st->extl != st->last_extl || ( st->extl == st->last_extl && ( st->core ^ st->last_core ) == HQ_CORE ) ) && !( st->extl == SWB_CNG && st->last_extl == SWB_TBE ) && ( st->element_mode != IVAS_CPE_TD || ( hCPE->element_mode == IVAS_CPE_TD && tdm_LRTD_flag ) ) ) + test(); test(); test(); test(); test(); test(); test(); test(); test(); + + IF ( !( ( EQ_16(st->core, TCX_20_CORE) || EQ_16(st->core, TCX_10_CORE) || EQ_16(st->core, HQ_CORE) ) && EQ_16(st->last_core, ACELP_CORE) ) && + ( NE_16(st->extl, st->last_extl) || ( EQ_16(st->extl, st->last_extl) && ( 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 = (int16_t) ( L_FRAME / ( tmps + 0.5f ) ); - for ( i = 0; i < tmps; i++ ) + incr = idiv1616(L_FRAME * 2, add(shl(tmps, 1), 1)); + tmp16 = 0; + move16(); + FOR ( i = 0; i < tmps; i++ ) { - hb_synth[n][i] *= sin_table256[i * incr]; + hb_synth_fx[n][i] = mult_r(hb_synth_fx[i], sin_table256_fx[tmp16]); + move16(); + tmp16 = add(tmp16, incr); } - set_f( st->hb_prev_synth_buffer, 0.0f, tmps ); + set16_fx( st->hb_prev_synth_buffer_fx, 0, tmps ); +#if 1 //To be removed + for (i = 0; i < tmps; i++) + { + hb_synth[n][i] *= sin_table256[i * incr]; + } + set_f(st->hb_prev_synth_buffer, 0.0f, tmps); +#endif } - else if ( tmps < st->old_bwe_delay ) + ELSE IF ( LT_16(tmps, st->old_bwe_delay )) { /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */ - incr = (int16_t) ( L_FRAME / ( tmps + 0.5f ) ); - for ( i = 0; i < tmps; i++ ) + + incr = idiv1616(L_FRAME * 2, add(shl(tmps, 1), 1)); + tmp16 = 0; + move16(); + FOR(i = 0; i < tmps; i++) { - tmp_buffer[i] = st->hb_prev_synth_buffer[i] * sin_table256[255 - i * incr] + - st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr]; + 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))); + tmp_buffer_fx[i] = shl_sat(tmp_buffer_fx[i], 1); + tmp16 = add(tmp16, incr); + } + Copy(tmp_buffer_fx, st->hb_prev_synth_buffer_fx, tmps); +#if 1 //To be removed + for (i = 0; i < tmps; i++) + { + tmp_buffer[i] = st->hb_prev_synth_buffer[i] * sin_table256[255 - i * incr] + + st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr]; } - mvr2r( tmp_buffer, st->hb_prev_synth_buffer, tmps ); + mvr2r(tmp_buffer, st->hb_prev_synth_buffer, tmps); +#endif } - else if ( tmps > st->old_bwe_delay ) + ELSE IF ( GT_16(tmps, st->old_bwe_delay )) { /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */ - incr = (int16_t) ( L_FRAME / ( st->old_bwe_delay + 0.5f ) ); - for ( i = 0; i < st->old_bwe_delay; i++ ) + incr = idiv1616(L_FRAME*2, add(shl(st->old_bwe_delay,1),1)); + tmp16 = 0; + move16(); + FOR (i=0; iold_bwe_delay; i++) { - tmp_buffer[i] = st->hb_prev_synth_buffer[i] * sin_table256[255 - i * incr]; + tmp_buffer_fx[i] = mult_r(st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16]); + move16(); + tmp16 = add(tmp16, incr); + + } + FOR (; iold_bwe_delay; i++) + { + /*tmp_buffer[tmps - 1 - i] += st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr];*/ + tmp_buffer_fx[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*/])); + tmp16 = add(tmp16, incr); } - for ( ; i < tmps; i++ ) + Copy( tmp_buffer_fx, st->hb_prev_synth_buffer_fx, tmps ); + +#if 1 //To be removed + for (i = 0; i < st->old_bwe_delay; i++) { - tmp_buffer[i] = 0.0f; + tmp_buffer[i] = st->hb_prev_synth_buffer[i] * sin_table256[255 - i * incr]; } - for ( i = 0; i < st->old_bwe_delay; i++ ) + for (; i < tmps; i++) { - tmp_buffer[tmps - 1 - i] += st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr]; + tmp_buffer[i] = 0.0f; } - mvr2r( tmp_buffer, st->hb_prev_synth_buffer, tmps ); - } + for (i = 0; i < st->old_bwe_delay; i++) + { + tmp_buffer[tmps - 1 - i] += st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr]; + } - if ( ( st->element_mode != IVAS_CPE_TD && !use_cldfb_for_dft ) || ( hCPE->element_mode == IVAS_CPE_TD && tdm_LRTD_flag ) ) + mvr2r(tmp_buffer, st->hb_prev_synth_buffer, tmps); +#endif + } + + test(); test(); test(); + IF ( ( NE_16(st->element_mode, IVAS_CPE_TD) && !use_cldfb_for_dft ) || ( EQ_16(hCPE->element_mode, IVAS_CPE_TD) && tdm_LRTD_flag ) ) { /* Delay hb_synth */ -#ifdef IVAS_FLOAT_FIXED - Word32 hb_synth_fx[960], hb_prev_synth_buffer_fx_32[111]; - floatToFixed_arrL(hb_synth[n], hb_synth_fx, Q11, 960); + Word32 hb_synth_fxl[960], hb_prev_synth_buffer_fx_32[111]; + floatToFixed_arrL(hb_synth[n], hb_synth_fxl, Q11, 960); floatToFixed_arrL(st->hb_prev_synth_buffer, hb_prev_synth_buffer_fx_32, Q11, 111); - delay_signal_fx( hb_synth_fx, output_frame, hb_prev_synth_buffer_fx_32, tmps ); + delay_signal_fx( hb_synth_fxl, output_frame, hb_prev_synth_buffer_fx_32, tmps ); - fixedToFloat_arrL(hb_synth_fx, hb_synth[n], Q11, 960); + fixedToFloat_arrL(hb_synth_fxl, hb_synth[n], Q11, 960); fixedToFloat_arrL(hb_prev_synth_buffer_fx_32, st->hb_prev_synth_buffer, Q11, 111); -#else - delay_signal_float( hb_synth[n], output_frame, st->hb_prev_synth_buffer, tmps ); -#endif } - else + ELSE { - mvr2r( hb_synth[n] + output_frame - tmps, st->hb_prev_synth_buffer, tmps ); + Copy32( hb_synth_fx[n] + output_frame - tmps, st->hb_prev_synth_buffer_fx, tmps ); //ToDo: Scale Signl with appropriate Q. +#if 1 // TO BE REMOVED + mvr2r(hb_synth[n] + output_frame - tmps, st->hb_prev_synth_buffer, tmps); +#endif } st->old_bwe_delay = tmps; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if ( st->hBWE_TD != NULL ) { mvr2r( hb_synth[n], st->hBWE_TD->old_hb_synth, output_frame ); } +#endif /* SWB CNG/DTX - calculate SHB energy */ - if ( output_frame >= L_FRAME32k && st->extl > SWB_CNG && st->core == ACELP_CORE && st->hTdCngDec != NULL ) + test(); test(); test(); + IF ( GE_16(output_frame, L_FRAME32k) && GT_16(st->extl, SWB_CNG) && EQ_16(st->core, ACELP_CORE) && st->hTdCngDec != NULL ) { - st->hTdCngDec->last_shb_ener = sum2_f( hb_synth[n], output_frame ) + 0.001f; - st->hTdCngDec->last_shb_ener /= (float) output_frame; - st->hTdCngDec->last_shb_ener = 10 * log10f( st->hTdCngDec->last_shb_ener ); +#ifdef IVAS_FLOAT_FIXED + Word32 hb_synth_fxl[960]; + //Word32 L_tmp; + Word16 exp, fra; + floatToFixed_arrL(hb_synth[n], hb_synth_fxl, Q11, 960); +#endif + SWITCH(output_frame) + { + case L_FRAME8k: + tmp16 = 205; + BREAK; /*Q15*/ + case L_FRAME16k: + tmp16 = 102; + BREAK; /*Q15*/ + case L_FRAME32k: + tmp16 = 51; + BREAK; /*Q15*/ + case L_FRAME48k: + tmp16 = 34; + BREAK; /*Q15*/ + } + + L_tmp = L_deposit_l(2); /*0.001 in Q11*/ + + Word16 gb = find_guarded_bits_fx(output_frame); + L_tmp = L_add(L_tmp, sum2_f_32_fx(hb_synth_fxl, output_frame, sub(11, gb))); + L_tmp = Mpy_32_16_1(L_tmp , tmp16); + exp = norm_l(L_tmp); + fra = Log2_norm_lc(L_shl(L_tmp, exp)); + exp = sub(sub(30, shl(sub(Q11, 0), 1)), exp); + L_tmp = Mpy_32_16(exp, fra, LG10); + st->last_shb_ener_fx = round_fx_sat(L_shl_sat(L_tmp, 10)); /*Q8*/ } } - if ( sba_dirac_stereo_flag && st->element_mode != IVAS_CPE_MDCT ) + test(); + 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; @@ -2239,15 +2093,16 @@ ivas_error ivas_core_dec( #ifdef IVAS_FLOAT_FIXED // TO DO delete below Word32 output_fx[CPE_CHANNELS][L_FRAME48k]; - Word32 synth_fx[CPE_CHANNELS][L_FRAME48k]; + Word32 synth_fxg[CPE_CHANNELS][L_FRAME48k]; + //Word32 hb_synth_fxg[CPE_CHANNELS][L_FRAME48k]; FOR(int ch_ind = 0; ch_ind < n_channels; ch_ind++) { FOR(int ind = 0; ind < L_FRAME48k; ind++) { output_fx[ch_ind][ind] = (Word32)(output[ch_ind][ind] * (1 << 11)); - synth_fx[ch_ind][ind] = (Word32)(synth[ch_ind][ind] * (1 << 11)); - hb_synth_fx[ch_ind][ind] = (Word32)(hb_synth[ch_ind][ind] * (1 << 11)); + synth_fxg[ch_ind][ind] = (Word32)(synth[ch_ind][ind] * (1 << 11)); + hb_synth_fxg[ch_ind][ind] = (Word32)(hb_synth[ch_ind][ind] * (1 << 11)); } } Word16 q_DFT[2] = { 3, 3 }; @@ -2257,9 +2112,9 @@ ivas_error ivas_core_dec( { FOR(int ind = 0; ind < CPE_CHANNELS; ind++) { - FOR(int j = 0; j < STEREO_DFT_BUF_MAX; j++) + FOR(int jj = 0; jj < STEREO_DFT_BUF_MAX; jj++) { - DFT_fx[ind][j] = (Word32)(DFT[ind][j] * (1 << q_DFT[ind])); + DFT_fx[ind][jj] = (Word32)(DFT[ind][jj] * (1 << q_DFT[ind])); } } } @@ -2281,10 +2136,6 @@ ivas_error ivas_core_dec( hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx[ind] = (Word32)(hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out[ind] * (1 << 11)); } } - //FOR(int ind = 0; ind < HQ_DELTA_MAX * HQ_DELAY_COMP; ind++) - //{ - // hCPE->hCoreCoder[ch_ind]->delay_buf_out32_fx[ind] = (Word32)(hCPE->hCoreCoder[ch_ind]->delay_buf_out[ind] * (1 << 11)); - //} if (hCPE->hCoreCoder[ch_ind]->p_bpf_noise_buf_float != NULL) { FOR(int ind = 0; ind < L_FRAME16k; ind++) @@ -2316,9 +2167,9 @@ ivas_error ivas_core_dec( } IF(hCPE->output_mem[ch_ind] != NULL) { - FOR(Word32 k = 0; k < NS2SA(hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS); k++) + FOR(Word32 kk = 0; kk < NS2SA(hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS); kk++) { - hCPE->output_mem_fx[ch_ind][k] = (Word32)(hCPE->output_mem[ch_ind][k] * (1 << OUTPUT_Q)); + hCPE->output_mem_fx[ch_ind][kk] = (Word32)(hCPE->output_mem[ch_ind][kk] * (1 << OUTPUT_Q)); } } IF(hCPE->hStereoDft != NULL) @@ -2342,8 +2193,6 @@ ivas_error ivas_core_dec( { hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * (1u << OUTPUT_Q)); } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15); - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain = (Word16)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15); } } @@ -2357,14 +2206,12 @@ ivas_error ivas_core_dec( { hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32)(hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_mem_in_float[p] * (1u << OUTPUT_Q)); } - hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15); - hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain = (Word16)(hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15); } IF(hCPE->hCoreCoder[ch_ind]->hTcxDec != NULL) { - FOR(Word32 k = 0; k < 111; k++) + FOR(Word32 kk = 0; kk < 111; kk++) { - hCPE->hCoreCoder[ch_ind]->hTcxDec->FBTCXdelayBuf_32[k] = (Word32)(hCPE->hCoreCoder[ch_ind]->hTcxDec->FBTCXdelayBuf_float[k] * (1 << OUTPUT_Q)); + hCPE->hCoreCoder[ch_ind]->hTcxDec->FBTCXdelayBuf_32[kk] = (Word32)(hCPE->hCoreCoder[ch_ind]->hTcxDec->FBTCXdelayBuf_float[kk] * (1 << OUTPUT_Q)); } } } @@ -2384,15 +2231,11 @@ ivas_error ivas_core_dec( hSCE->hCoreCoder[0]->hHQ_core->oldOut_fx[ind] = (Word32)(hSCE->hCoreCoder[0]->hHQ_core->old_out[ind] * (1 << 11)); } } - //FOR(int ind = 0; ind < HQ_DELTA_MAX * HQ_DELAY_COMP; ind++) - //{ - // hSCE->hCoreCoder[0]->delay_buf_out32_fx[ind] = (Word32)(hSCE->hCoreCoder[0]->delay_buf_out[ind] * (1 << 11)); - //} IF(hSCE->hCoreCoder[0]->hTcxDec != NULL) { - FOR(Word32 k = 0; k < 111; k++) + FOR(Word32 kk = 0; kk < 111; kk++) { - hSCE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32[k] = (Word32)(hSCE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_float[k] * (1 << OUTPUT_Q)); + hSCE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32[kk] = (Word32)(hSCE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_float[kk] * (1 << OUTPUT_Q)); } } IF(hSCE->hCoreCoder[0]->hTcxLtpDec != NULL) @@ -2405,20 +2248,12 @@ ivas_error ivas_core_dec( { hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32)(hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_float[p] * (1u << OUTPUT_Q)); } - hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15); - hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain = (Word16)(hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15); } } } Word16 exp_max = 0; Word32 output_fx_loc[L_FRAME48k]; - floatToFixed_arr(st->old_synth_sw, st->old_synth_sw_fx, -2, 429); - st->prev_tilt_code_dec_fx = (Word16)floatToFixed(st->prev_tilt_code_dec, Q15); - FOR(Word16 ind = 0; ind < 16; ind++) { - st->mem_AR_fx[ind] = (Word16)(st->mem_AR[ind] * 2.56f); - } - fixedToFloat_arr(st->old_synth_sw_fx, st->old_synth_sw, 0, 429); #endif IF ( NE_16(st->element_mode, IVAS_CPE_DFT )) @@ -2426,7 +2261,7 @@ ivas_error ivas_core_dec( IF ( NE_16(st->element_mode, IVAS_CPE_MDCT) || sba_dirac_stereo_flag ) { - ivas_post_proc_fx( hSCE, hCPE, n, synth_fx[n], NULL, output_frame, sba_dirac_stereo_flag ); + ivas_post_proc_fx( hSCE, hCPE, n, synth_fxg[n], NULL, output_frame, sba_dirac_stereo_flag ); } /* update OLA buffers - needed for switching to DFT stereo */ @@ -2434,7 +2269,7 @@ ivas_error ivas_core_dec( { IF ( hCPE != NULL ) { - stereo_td2dft_update_fx( hCPE, n, output_fx[n], synth_fx[n], hb_synth_fx[n], output_frame ); + stereo_td2dft_update_fx( hCPE, n, output_fx[n], synth_fxg[n], hb_synth_fxg[n], output_frame ); } } } @@ -2443,29 +2278,29 @@ ivas_error ivas_core_dec( Word16 q = 11; IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_MDCT )) { - stereo_mdct2dft_update_fx( hCPE, output_fx[0], synth_fx[0] ); + stereo_mdct2dft_update_fx( hCPE, output_fx[0], synth_fxg[0] ); } - stereo_dft_dec_core_switching_fx( hCPE, output_fx[0], synth_fx[0], hb_synth_fx[0], DFT_fx, output_frame, use_cldfb_for_dft, 0, &q, q_DFT ); + stereo_dft_dec_core_switching_fx( hCPE, output_fx[0], synth_fxg[0], hb_synth_fxg[0], DFT_fx, output_frame, use_cldfb_for_dft, 0, &q, q_DFT ); IF (EQ_16(hCPE->nchan_out, 1) && EQ_16(hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF )) { /* mono output for non-residual coding modes uses CLDFB instead of DFT - requires DFT buffer update in case of bitrate switching */ - stereo_td2dft_update_fx( hCPE, n, output_fx[n], synth_fx[n], hb_synth_fx[n], output_frame ); + stereo_td2dft_update_fx( hCPE, n, output_fx[n], synth_fxg[n], hb_synth_fxg[n], output_frame ); } } - Copy32( synth_fx[n], output_fx[n], output_frame ); + Copy32( synth_fxg[n], output_fx[n], output_frame ); /*--------------------------------------------------------* * Common updates *--------------------------------------------------------*/ /*Scale Memories*/ -#if 1 + test(); test(); 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))) { - Word16 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0, temp = 0; move16(); move16(); move16(); move16(); move16(); move16(); + Word16 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0/*, temp = 0*/; move16(); move16(); move16(); move16(); move16(); move16(); exp_ouput = Find_Max_Norm32(output_fx[n], output_frame); exp_ouput += 11; exp_prev_synth_buffer = Find_Max_Norm16(st->prev_synth_buffer_fx, NS2SA(48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)); @@ -2491,7 +2326,6 @@ ivas_error ivas_core_dec( st->hTcxDec->q_synth_history_fx = exp_max - st->q_prev_synth_buffer_fx; st->q_prev_synth_buffer_fx = exp_max - st->q_prev_synth_buffer_fx; } -#endif /* Save synthesis for HQ FEC */ save_synthesis_hq_fec_fx( st, output_fx_loc, output_frame, hCPE ); @@ -2508,17 +2342,17 @@ ivas_error ivas_core_dec( FOR( i = 0; i < L_FRAME48k; i++ ) { output[ch_ind][i] = fixedToFloat(output_fx[ch_ind][i], 11); - synth[ch_ind][i] = (float) synth_fx[ch_ind][i] / (float) ( 1 << 11 ); - hb_synth[ch_ind][i] = (float) hb_synth_fx[ch_ind][i] / (float) ( 1 << 11 ); + synth[ch_ind][i] = (float) synth_fxg[ch_ind][i] / (float) ( 1 << 11 ); + hb_synth[ch_ind][i] = (float) hb_synth_fxg[ch_ind][i] / (float) ( 1 << 11 ); } } IF( DFT != NULL ) { FOR( i = 0; i < CPE_CHANNELS; i++ ) { - FOR( Word16 j = 0; j < STEREO_DFT_BUF_MAX; j++ ) + FOR( Word16 jj = 0; jj < STEREO_DFT_BUF_MAX; jj++ ) { - DFT[i][j] = (float) DFT_fx[i][j] / (float) ( 1 << q_DFT[i] ); + DFT[i][jj] = (float) DFT_fx[i][jj] / (float) ( 1 << q_DFT[i] ); } } } @@ -2540,10 +2374,6 @@ ivas_error ivas_core_dec( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out[ind] = (float) hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx[ind] / (float) ( 1 << 11 ); } } - //FOR( int ind = 0; ind < HQ_DELTA_MAX * HQ_DELAY_COMP; ind++ ) - //{ - // hCPE->hCoreCoder[ch_ind]->delay_buf_out[ind] = (float) hCPE->hCoreCoder[ch_ind]->delay_buf_out32_fx[ind] / (float) ( 1 << 11 ); - //} if ( hCPE->hCoreCoder[ch_ind]->p_bpf_noise_buf_float != NULL ) { FOR( int ind = 0; ind < L_FRAME16k; ind++ ) @@ -2561,14 +2391,12 @@ ivas_error ivas_core_dec( { hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float)hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_mem_in_32[p] / (1u << OUTPUT_Q); } - hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; - hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_float = (float)hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } IF(hCPE->hCoreCoder[ch_ind]->hTcxDec != NULL) { - FOR(Word32 k = 0; k < 111; k++) + FOR(Word32 kk = 0; kk < 111; kk++) { - hCPE->hCoreCoder[ch_ind]->hTcxDec->FBTCXdelayBuf_float[k] = (float)hCPE->hCoreCoder[ch_ind]->hTcxDec->FBTCXdelayBuf_32[k] / (1 << OUTPUT_Q); + hCPE->hCoreCoder[ch_ind]->hTcxDec->FBTCXdelayBuf_float[kk] = (float)hCPE->hCoreCoder[ch_ind]->hTcxDec->FBTCXdelayBuf_32[kk] / (1 << OUTPUT_Q); } } } @@ -2581,9 +2409,9 @@ ivas_error ivas_core_dec( } IF(hCPE->output_mem[ch_ind] != NULL) { - FOR(Word32 k = 0; k < NS2SA(hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS); k++) + FOR(Word32 kk = 0; kk < NS2SA(hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS); kk++) { - hCPE->output_mem[ch_ind][k] = (float)hCPE->output_mem_fx[ch_ind][k] / (1u << 11); + hCPE->output_mem[ch_ind][kk] = (float)hCPE->output_mem_fx[ch_ind][kk] / (1u << 11); } } if ( hCPE->input_mem_LB[ch_ind] ) @@ -2619,8 +2447,6 @@ ivas_error ivas_core_dec( { hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / (1u << OUTPUT_Q); } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } } } @@ -2641,15 +2467,11 @@ ivas_error ivas_core_dec( hSCE->hCoreCoder[0]->hHQ_core->old_out[ind] = (float) hSCE->hCoreCoder[0]->hHQ_core->oldOut_fx[ind] / (float) ( 1 << 11 ); } } - //FOR( int ind = 0; ind < HQ_DELTA_MAX * HQ_DELAY_COMP; ind++ ) - //{ - // hSCE->hCoreCoder[0]->delay_buf_out[ind] = (float) hSCE->hCoreCoder[0]->delay_buf_out32_fx[ind] / (float) ( 1 << 11 ); - //} IF(hSCE->hCoreCoder[0]->hTcxDec != NULL) { - FOR(Word32 k = 0; k < 111; k++) + FOR(Word32 kk = 0; kk < 111; kk++) { - hSCE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_float[k] = (float)hSCE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32[k] / (1 << OUTPUT_Q); + hSCE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_float[kk] = (float)hSCE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32[kk] / (1 << OUTPUT_Q); } } IF(hSCE->hCoreCoder[0]->hTcxLtpDec != NULL) @@ -2662,8 +2484,6 @@ ivas_error ivas_core_dec( { hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float)hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_32[p] / (1u << OUTPUT_Q); } - hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; - hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_float = (float)hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } } } @@ -2675,12 +2495,6 @@ ivas_error ivas_core_dec( fix2f_16(&st->hTcxDec->synth_history_fx[i], &st->hTcxDec->synth_history[i], st->hTcxDec->q_synth_history_fx); } } - - fixedToFloat_arr(st->old_synth_sw_fx, st->old_synth_sw, -2, 429); - FOR(Word16 ind = 0; ind < 16; ind++) { - st->mem_AR[ind] = st->mem_AR_fx[ind] / 2.56f; - } - st->prev_tilt_code_dec = fixedToFloat(st->prev_tilt_code_dec_fx, Q15); #endif } /* n_channels loop */ diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index 07fe4e1c6148915d382e3a4254e2f5f50aaef957..e5eabe3d44508ca86754cefead30c3280d9a67da 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -48,6 +48,419 @@ * Allocate, initialize, and configure SCE/CPE/MCT handles in case of bitrate switching *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_corecoder_dec_reconfig_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nSCE_old, /* i : number of SCEs in previous frame */ + Word16 nCPE_old, /* i : number of CPEs in previous frame */ + const Word16 nchan_transport_old, /* i : number of TCs in previous frame */ + const Word16 sba_dirac_stereo_flag_old, /* i : signal stereo rendering using DFT upmix in previous frame */ + const Word32 brate_SCE, /* i : bitrate to be set for the SCEs */ + const Word32 brate_CPE /* i : bitrate to be set for the CPEs */ +) +{ + Word16 n, sce_id, cpe_id, output_frame; + Word16 nSCE_existing, nCPE_existing; + Word32 ivas_total_brate; + Word16 nchan_transport_real; + MC_MODE last_mc_mode; + DECODER_CONFIG_HANDLE hDecoderConfig; + ivas_error error; + Word16 prev_bfi; + Decoder_State *st0; + + /*-----------------------------------------------------------------* + * Initialization + *-----------------------------------------------------------------*/ + + hDecoderConfig = st_ivas->hDecoderConfig; + ivas_total_brate = hDecoderConfig->ivas_total_brate; + move32(); + output_frame = extract_l( Mpy_32_16_1( hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); + error = IVAS_ERR_OK; + move32(); + + IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) ) + { + last_mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ + } + ELSE + { + last_mc_mode = MC_MODE_NONE; + move32(); + } + + nchan_transport_real = st_ivas->nchan_transport; + move16(); + + IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + nchan_transport_real = add( nchan_transport_real, st_ivas->nchan_ism ); + } + /*-----------------------------------------------------------------* + * Allocate, initialize, and configure SCE/CPE/MCT handles + *-----------------------------------------------------------------*/ + + /* remove dummy CPE element for DFT stereo-like upmix */ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && sba_dirac_stereo_flag_old && EQ_16( nchan_transport_old, 1 ) && ( !st_ivas->sba_dirac_stereo_flag || GT_16( st_ivas->nchan_transport, 1 ) ) ) || + ( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( last_mc_mode, MC_MODE_MCMASA ) && sba_dirac_stereo_flag_old && EQ_16( nchan_transport_old, 1 ) && ( !st_ivas->sba_dirac_stereo_flag || GT_16( st_ivas->nchan_transport, 1 ) ) ) ) + { + st_ivas->hCPE[0]->hCoreCoder[0] = NULL; + st_ivas->hCPE[0]->hCoreCoder[1] = NULL; + destroy_cpe_dec( st_ivas->hCPE[0] ); + st_ivas->hCPE[0] = NULL; + + if ( st_ivas->hSCE[0] != NULL ) + { +#if 1 /*TODO:To be removed later*/ + free( st_ivas->hSCE[0]->save_synth ); + st_ivas->hSCE[0]->save_synth = NULL; + + free( st_ivas->hSCE[0]->save_hb_synth ); + st_ivas->hSCE[0]->save_hb_synth = NULL; +#endif + free( st_ivas->hSCE[0]->save_synth_fx ); + st_ivas->hSCE[0]->save_synth_fx = NULL; + + free( st_ivas->hSCE[0]->save_hb_synth_fx ); + st_ivas->hSCE[0]->save_hb_synth_fx = NULL; + } + } + + test(); + test(); + IF( EQ_16( nchan_transport_real, nchan_transport_old ) && EQ_16( st_ivas->nSCE, nSCE_old ) && EQ_16( st_ivas->nCPE, nCPE_old ) ) + { + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + st_ivas->hSCE[sce_id]->element_brate = brate_SCE; + move32(); + st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + } + + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; + move32(); + + /* prepare bitstream buffers */ + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + } + } + + IF( GT_16( st_ivas->nCPE, 1 ) ) + { + IF( ( error = mct_dec_reconfigure_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + ELSE + { + st0 = GT_16( nSCE_old, 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; + prev_bfi = st0->prev_bfi; + move16(); + nSCE_existing = s_min( nSCE_old, st_ivas->nSCE ); + nCPE_existing = s_min( nCPE_old, st_ivas->nCPE ); + + /* destroy superfluous core coder elements */ + FOR( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) + { + destroy_sce_dec( st_ivas->hSCE[sce_id] ); + st_ivas->hSCE[sce_id] = NULL; + } + + test(); + test(); + IF( sba_dirac_stereo_flag_old && EQ_16( nCPE_old, 0 ) && st_ivas->hCPE[0] ) + { + st_ivas->hCPE[0]->hCoreCoder[0] = 0; /* this has been deallocated as part of the SCE it actually belongs to */ + destroy_cpe_dec( st_ivas->hCPE[0] ); + st_ivas->hCPE[0] = NULL; + } + + FOR( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ ) + { + /* don't deallocate first CPE in case of mono/stereo output of 1 TC SBA, only deallocate core coder */ + test(); + test(); + IF( EQ_16( cpe_id, 0 ) && st_ivas->sba_dirac_stereo_flag && sba_dirac_stereo_flag_old ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + IF( st_ivas->hCPE[cpe_id]->hCoreCoder[n] != NULL ) + { + destroy_core_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] ); + + free( st_ivas->hCPE[cpe_id]->hCoreCoder[n] ); + st_ivas->hCPE[cpe_id]->hCoreCoder[n] = NULL; + } + } + CONTINUE; + } + destroy_cpe_dec( st_ivas->hCPE[cpe_id] ); + st_ivas->hCPE[cpe_id] = NULL; + } + + /* the CPE-internal settings depend from ivas_format and mc_mode, so clean-up when switching between mc_modes */ + test(); + test(); + test(); + IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && NE_16( st_ivas->mc_mode, last_mc_mode ) && ( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) || EQ_16( last_mc_mode, MC_MODE_MCMASA ) ) ) + { + FOR( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) + { + destroy_cpe_dec( st_ivas->hCPE[cpe_id] ); + st_ivas->hCPE[cpe_id] = NULL; + } + nCPE_old = 0; + move16(); + nCPE_existing = s_min( nCPE_old, st_ivas->nCPE ); + } + test(); + IF( LE_16( st_ivas->nCPE, 1 ) && st_ivas->hMCT != NULL ) + { + ivas_mct_dec_close( &st_ivas->hMCT ); + } + + /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles from the first CPE*/ + test(); + IF( GT_16( st_ivas->nCPE, 1 ) && EQ_16( nCPE_old, 1 ) ) + { + free( st_ivas->hCPE[0]->hStereoMdct ); + st_ivas->hCPE[0]->hStereoMdct = NULL; + } + + FOR( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) + { + st_ivas->hSCE[sce_id]->element_brate = brate_SCE; + move32(); + st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + } + FOR( ; sce_id < st_ivas->nSCE; sce_id++ ) + { + IF( ( error = create_sce_dec( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK ) + { + return error; + } + st_ivas->hSCE[sce_id]->hCoreCoder[0]->prev_bfi = prev_bfi; + move16(); + } + test(); + test(); + test(); + IF( st_ivas->sba_dirac_stereo_flag && sba_dirac_stereo_flag_old && EQ_16( st_ivas->nchan_transport, 1 ) && EQ_16( nSCE_old, 0 ) ) + { + st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ + st_ivas->hCPE[0]->hCoreCoder[1] = NULL; + } + + FOR( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) + { + st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; + move32(); + + /* prepare bitstream buffers */ + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + } + } + FOR( ; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + test(); + IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && st_ivas->hOutSetup.separateChannelEnabled ) + { + st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); + } + + IF( ( error = create_cpe_dec( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK ) + { + return error; + } + st_ivas->hCPE[cpe_id]->hCoreCoder[0]->prev_bfi = prev_bfi; + move16(); + st_ivas->hCPE[cpe_id]->hCoreCoder[1]->prev_bfi = prev_bfi; + move16(); + } + + test(); + test(); + IF( GT_16( st_ivas->nCPE, 1 ) && LE_16( nCPE_old, 1 ) ) + { + IF( EQ_16( nCPE_old, 1 ) ) + { + /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */ + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + 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_16_1( st_ivas->hCPE[0]->element_brate, INV_FRAME_PER_SEC_Q15 ) ); + st_ivas->hCPE[0]->hCoreCoder[n]->igf = 0; + move16(); + } + } + + IF( ( error = create_mct_dec_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE IF( st_ivas->hMCT != NULL && GT_16( st_ivas->nCPE, 1 ) ) + { + IF( ( error = mct_dec_reconfigure_fx( st_ivas, (UWord16) NE_16( st_ivas->nchan_transport, nchan_transport_old ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */ + test(); + IF( EQ_16( st_ivas->nCPE, 1 ) && GT_16( nCPE_old, 1 ) ) + { + IF( ( st_ivas->hCPE[sub( st_ivas->nCPE, 1 )]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); + } + + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->use_itd = 0; + move16(); + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->reverse_dmx = 0; + move16(); + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; /* Q26 */ + move32(); + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->lastCoh_fx = ONE_IN_Q14; /* Q14 */ + move16(); + set16_fx( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->prev_ms_mask[0], 0, MAX_SFB ); + set16_fx( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->prev_ms_mask[1], 0, MAX_SFB ); + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->mdct_stereo_mode[0] = SMDCT_DUAL_MONO; + move16(); + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO; + move16(); + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->IGFStereoMode[0] = -1; + move16(); + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->IGFStereoMode[1] = -1; + move16(); + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + /* reset mct_chan_mode */ + st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + move32(); + } + } + } + + /* create dummy CPE element for DFT stereo-like upmix */ + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) || + ( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) ) + { + /* if at least one CPE is already available, only allocate DFT Stereo struct */ + IF( GT_16( st_ivas->nCPE, 0 ) ) + { + IF( ( error = stereo_dft_dec_create_fx( &( st_ivas->hCPE[0]->hStereoDft ), st_ivas->hCPE[0]->element_brate, st_ivas->hDecoderConfig->output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + { + return error; + } + } + /* otherwise create extra dummy CPE */ + ELSE + { + IF( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + set32_fx( st_ivas->hCPE[0]->hStereoDft->buff_LBTCX_mem_fx, 0, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ) ); +#if 1 /*TODO: To be removed later*/ + set_f( st_ivas->hCPE[0]->hStereoDft->buff_LBTCX_mem, 0, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ) ); +#endif + + st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ + st_ivas->hCPE[0]->hCoreCoder[1] = NULL; + + IF( st_ivas->hSCE[0]->save_synth == NULL ) + { +#if 1 /*TODO: To be removed later*/ + IF( ( st_ivas->hSCE[0]->save_synth = (float *) malloc( sizeof( float ) * output_frame ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo output\n" ) ); + } + set_zero( st_ivas->hSCE[0]->save_synth, output_frame ); +#endif + IF( ( st_ivas->hSCE[0]->save_synth_fx = (Word32 *) malloc( sizeof( *( st_ivas->hSCE[0]->save_synth_fx ) ) * output_frame ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo output\n" ) ); + } + set32_fx( st_ivas->hSCE[0]->save_synth_fx, 0, output_frame ); + st_ivas->hSCE[0]->q_save_synth_fx = 0; + move16(); + } + + IF( st_ivas->hSCE[0]->save_hb_synth == NULL ) + { +#if 1 /*TODO: To be removed later*/ + IF( ( st_ivas->hSCE[0]->save_hb_synth = (float *) malloc( sizeof( float ) * output_frame ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate HB memory for stereo output\n" ) ); + } + set_zero( st_ivas->hSCE[0]->save_hb_synth, output_frame ); +#endif + IF( ( st_ivas->hSCE[0]->save_hb_synth_fx = (Word32 *) malloc( sizeof( *( st_ivas->hSCE[0]->save_hb_synth_fx ) ) * output_frame ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate HB memory for stereo output\n" ) ); + } + set32_fx( st_ivas->hSCE[0]->save_hb_synth_fx, 0, output_frame ); + } + } + + /*-----------------------------------------------------------------* + * Set CNA/CNG flags + *-----------------------------------------------------------------*/ + + test(); + IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) ) + { + ivas_sba_set_cna_cng_flag( st_ivas ); + } + + /* special case, if the decoder goes from 1TC DTX to 2TC active frame (in case the bitstream started with an SBA SID frame), allocate DTX memories */ + test(); + IF( LE_32( hDecoderConfig->last_ivas_total_brate, IVAS_SID_5k2 ) && GE_16( st_ivas->nCPE, 1 ) ) + { + IF( ( error = initMdctStereoDtxData_fx( st_ivas->hCPE[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + return error; +} +#else ivas_error ivas_corecoder_dec_reconfig( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ @@ -112,13 +525,6 @@ ivas_error ivas_corecoder_dec_reconfig( free( st_ivas->hSCE[0]->save_hb_synth ); st_ivas->hSCE[0]->save_hb_synth = NULL; -#ifdef IVAS_FLOAT_FIXED - free( st_ivas->hSCE[0]->save_synth_fx ); - st_ivas->hSCE[0]->save_synth_fx = NULL; - - free( st_ivas->hSCE[0]->save_hb_synth_fx ); - st_ivas->hSCE[0]->save_hb_synth_fx = NULL; -#endif } } @@ -143,17 +549,10 @@ ivas_error ivas_corecoder_dec_reconfig( if ( st_ivas->nCPE > 1 ) { -#ifdef IVAS_FLOAT_FIXED - if ( ( error = mct_dec_reconfigure_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) - { - return error; - } -#else if ( ( error = mct_dec_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK ) { return error; } -#endif } } else @@ -285,17 +684,10 @@ ivas_error ivas_corecoder_dec_reconfig( } else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 ) { -#ifdef IVAS_FLOAT_FIXED - if ( ( error = mct_dec_reconfigure_fx( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK ) - { - return error; - } -#else if ( ( error = mct_dec_reconfigure( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK ) { return error; } -#endif } /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */ @@ -309,9 +701,6 @@ ivas_error ivas_corecoder_dec_reconfig( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->use_itd = 0; st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->reverse_dmx = 0; st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->smooth_ratio = 1.f; -#ifdef IVAS_FLOAT_FIXED - st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; -#endif set_s( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->prev_ms_mask[0], 0, MAX_SFB ); set_s( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->prev_ms_mask[1], 0, MAX_SFB ); st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->lastCoh = 1.f; @@ -360,14 +749,6 @@ ivas_error ivas_corecoder_dec_reconfig( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo output\n" ) ); } set_zero( st_ivas->hSCE[0]->save_synth, output_frame ); -#ifdef IVAS_FLOAT_FIXED - if ( ( st_ivas->hSCE[0]->save_synth_fx = (Word32 *) malloc( sizeof( *(st_ivas->hSCE[0]->save_synth_fx)) * output_frame ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo output\n" ) ); - } - set_l( st_ivas->hSCE[0]->save_synth_fx, 0, output_frame ); - st_ivas->hSCE[0]->q_save_synth_fx = 0; -#endif } if ( st_ivas->hSCE[0]->save_hb_synth == NULL ) @@ -377,13 +758,6 @@ ivas_error ivas_corecoder_dec_reconfig( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate HB memory for stereo output\n" ) ); } set_zero( st_ivas->hSCE[0]->save_hb_synth, output_frame ); -#ifdef IVAS_FLOAT_FIXED - if ( ( st_ivas->hSCE[0]->save_hb_synth_fx = (Word32 *) malloc( sizeof(*(st_ivas->hSCE[0]->save_hb_synth_fx)) * output_frame ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate HB memory for stereo output\n" ) ); - } - set_l( st_ivas->hSCE[0]->save_hb_synth_fx, 0, output_frame ); -#endif } } @@ -407,6 +781,7 @@ ivas_error ivas_corecoder_dec_reconfig( return error; } +#endif /*-------------------------------------------------------------------* diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index 8f8c7fee151f4ce0421d14a4232fd7a45fdc31ed..a8f9a12d03cd73c3517ce6dc7222bca64cd6d21f 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -40,6 +40,7 @@ #include "prot.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" +#include "prot_fx1.h" #include "prot_fx2.h" #include "ivas_rom_com.h" #include "wmc_auto.h" @@ -140,7 +141,7 @@ ivas_error ivas_cpe_dec_fx( #else #if 1 // Float to fix conversions float maxim = 0; - Word16 q_output_mem, q_buff_LBTCX_mem, q_input_mem_LB, q_old_out = 31, q_old_out_LB = 31, q_tcxltp_mem_in_float=15, q_tcxltp_gain_post_prev = 15; + Word16 q_output_mem, q_buff_LBTCX_mem, q_input_mem_LB, q_old_out = 31, q_old_out_LB = 31, q_tcxltp_mem_in_float=15; q_output_mem = 11; IF(hCPE->hStereoDft) FOR(Word16 ind1 = 0; ind1 < 2; ind1++) { @@ -201,10 +202,6 @@ ivas_error ivas_cpe_dec_fx( FOR(Word16 ind = 0; ind < s_min(12, (Word16)( L_FRAME48k * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[ind] = (Word32)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[ind] * (1<hStereoDft && hCPE->hStereoDft->hTcxLtpDec) { - IF(fabsf(hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float) > 1) assert(0);//q_tcxltp_gain_post_prev = norm_s(hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev); - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * (1 << q_tcxltp_gain_post_prev)); - } FOR(Word16 ind2 = 0; ind2 < 2; ind2++) { IF(hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) FOR(Word16 ind = 0; ind < s_min(12, (Word16)(TCXLTP_MAX_DELAY * st_ivas->hDecoderConfig->output_Fs) / 48000); ind++) { @@ -214,15 +211,9 @@ ivas_error ivas_cpe_dec_fx( FOR(Word16 ind = 0; ind < s_min(12, (Word16)(L_FRAME48k * st_ivas->hDecoderConfig->output_Fs) / 48000); ind++) { hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_out_32[ind] = (Word32)(hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_out_float[ind] * (1 << q_tcxltp_mem_in_float)); } - IF(hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) { - IF(fabsf(hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev_float) > 1) assert(0);//q_tcxltp_gain_post_prev = norm_s(hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev_float); - hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev_float * (1 << q_tcxltp_gain_post_prev)); - } IF(hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->cldfbSyn) hCPE->hCoreCoder[ind2]->cldfbSyn->scale = (Word16)(hCPE->hCoreCoder[ind2]->cldfbSyn->scale_flt * (1u << norm_s((Word16)hCPE->hCoreCoder[0]->cldfbSyn->scale_flt))); } - IF(hCPE->hStereoMdct) - hCPE->hStereoMdct->smooth_ratio_fx = (Word32)(hCPE->hStereoMdct->smooth_ratio * (ONE_IN_Q26)); FOR(Word16 ind = 0; ind < L_FRAME16k / 2; ind++) { IF(hCPE->hCoreCoder[0] && hCPE->hCoreCoder[0]->hTcxDec) hCPE->hCoreCoder[0]->hTcxDec->old_syn_Overl_32[ind] = (Word32)(hCPE->hCoreCoder[0]->hTcxDec->old_syn_Overl_float[ind] * (ONE_IN_Q11)); @@ -275,8 +266,6 @@ ivas_error ivas_cpe_dec_fx( FOR(Word16 ind = 0; ind < s_min(12, (Word16)( L_FRAME48k * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[ind] = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[ind] / (float)(1<hStereoDft && hCPE->hStereoDft->hTcxLtpDec) - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / (float)(1 << q_tcxltp_gain_post_prev); FOR(Word16 ind2 = 0; ind2 < 2; ind2++) { IF(hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) FOR(Word16 ind = 0; ind < s_min(12, (Word16)( TCXLTP_MAX_DELAY * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { @@ -286,11 +275,7 @@ ivas_error ivas_cpe_dec_fx( FOR(Word16 ind = 0; ind < s_min(12, (Word16)( L_FRAME48k * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_out_float[ind] = (float)hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_out_32[ind] / (float)(1<hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) - hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev / (float)(1 << q_tcxltp_gain_post_prev); } - IF(hCPE->hStereoMdct) - hCPE->hStereoMdct->smooth_ratio = hCPE->hStereoMdct->smooth_ratio_fx / (float)(ONE_IN_Q26); FOR(Word16 ind = 0; ind < L_FRAME16k / 2; ind++) { IF(hCPE->hCoreCoder[0] && hCPE->hCoreCoder[0]->hTcxDec) hCPE->hCoreCoder[0]->hTcxDec->old_syn_Overl_float[ind] = (float)hCPE->hCoreCoder[0]->hTcxDec->old_syn_Overl_32[ind] / (float)(ONE_IN_Q11); @@ -355,10 +340,6 @@ ivas_error ivas_cpe_dec_fx( floatToFixed_arrL(&hCPE->hCoreCoder[n]->prev_synth_buffer[0], &hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[0], q_temp, NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS)); floatToFixed_arr(&hCPE->hCoreCoder[n]->prev_synth_buffer[0], &hCPE->hCoreCoder[n]->prev_synth_buffer_fx[0], 0, NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS)); } - if (hCPE->hStereoDft != NULL ) - { - floatToFixed_arrL(&hCPE->hStereoDft->side_gain[0], &hCPE->hStereoDft->side_gain_fx[0], 31, STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX); - } } stereo_switching_dec( hCPE, ivas_total_brate ); @@ -382,10 +363,6 @@ ivas_error ivas_cpe_dec_fx( fixedToFloat_arrL(&hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[0], &hCPE->hCoreCoder[n]->prev_synth_buffer[0], q_temp, NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS)); //fixedToFloat_arrL(&hCPE->hCoreCoder[n]->prev_synth_buffer_fx[0], &hCPE->hCoreCoder[n]->prev_synth_buffer[0], 0, NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS)); } - if (hCPE->hStereoDft) - { - fixedToFloat_arrL(&hCPE->hStereoDft->side_gain_fx[0], &hCPE->hStereoDft->side_gain[0], 31, STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX); - } } /*----------------------------------------------------------------* * Configuration of stereo decoder @@ -507,23 +484,10 @@ ivas_error ivas_cpe_dec_fx( // Q_res_buf = Q_factor_arrL( res_buf, STEREO_DFT_N_8k ); floatToFixed_arr(hCPE->hStereoCng->coh, hCPE->hStereoCng->coh_fx, Q_coh, 14 ); floatToFixed_arrL( res_buf, res_buf_fx, Q_res_buf, STEREO_DFT_N_8k ); - floatToFixed_arrL(hCPE->hStereoDft->side_gain, hCPE->hStereoDft->side_gain_fx, 31, 39 ); - floatToFixed_arrL(hCPE->hStereoDft->res_pred_gain, hCPE->hStereoDft->res_pred_gain_fx, 31, 39 ); - floatToFixed_arrL(hCPE->hStereoDft->itd, hCPE->hStereoDft->itd_fx, Q15, 3 ); - floatToFixed_arrL( hCPE->hStereoDft->gipd, hCPE->hStereoDft->gipd_fx, Q13, 3 ); - hCPE->hStereoDft->itd_xfade_target_fx = floatToFixed( hCPE->hStereoDft->itd_xfade_target, 15 ); - hCPE->hStereoDft->ipd_xfade_target_fx = floatToFixed( hCPE->hStereoDft->ipd_xfade_target, 13 ); - floatToFixed_arrL( &hCPE->hStereoDft->res_gains_ind[0][0], &hCPE->hStereoDft->res_gains_ind_fx[0][0], Q26, 2 * 26 ); #endif stereo_dft_dec_read_BS_fx( ivas_total_brate, hCPE->element_brate, &sts[0]->total_brate, sts[1], hCPE->hStereoDft, sts[0]->bwidth, output_frame, res_buf_fx, &nb_bits, hCPE->hStereoCng->coh_fx, st_ivas->ivas_format ); #if 1 /*Fixed To Float changes*/ fixedToFloat_arr( hCPE->hStereoCng->coh_fx, hCPE->hStereoCng->coh, Q_coh, 14 ); /*Q-13*/ - fixedToFloat_arrL( hCPE->hStereoDft->itd_fx, hCPE->hStereoDft->itd, Q15, 3 ); - fixedToFloat_arrL( hCPE->hStereoDft->gipd_fx, hCPE->hStereoDft->gipd, Q13, 3 ); - fixedToFloat_arrL( hCPE->hStereoDft->side_gain_fx, hCPE->hStereoDft->side_gain, 31, 39 ); - fixedToFloat_arrL( hCPE->hStereoDft->res_pred_gain_fx, hCPE->hStereoDft->res_pred_gain, 31, 39 ); - fixedToFloat_arrL( &hCPE->hStereoDft->res_gains_ind_fx[0][0], &hCPE->hStereoDft->res_gains_ind[0][0], Q26, 2 * 26 ); - hCPE->hStereoDft->res_global_gain = ( (float) hCPE->hStereoDft->res_global_gain_fx / ONE_IN_Q15 ); fixedToFloat_arrL( res_buf_fx, res_buf, Q_res_buf, STEREO_DFT_N_8k ); #endif #else @@ -568,7 +532,7 @@ ivas_error ivas_cpe_dec_fx( IF( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) && ( EQ_16( sts[0]->first_CNG, 0 ) || EQ_16( sts[1]->first_CNG, 0 ) ) ) { - IF( ( error = initMdctStereoDtxData( hCPE ) ) != IVAS_ERR_OK ) + IF( ( error = initMdctStereoDtxData_fx( hCPE ) ) != IVAS_ERR_OK ) { return error; } @@ -725,19 +689,13 @@ ivas_error ivas_cpe_dec_fx( Word32 output_fix[L_FRAME8k]; hCPE->hStereoDft->q_res_cod_mem_fx = 0; // keeping same as shift needed inside. floatToFixed_arrL(hCPE->hStereoDft->res_cod_mem, hCPE->hStereoDft->res_cod_mem_fx, Q16, sizeof(hCPE->hStereoDft->res_cod_mem_fx) / sizeof(hCPE->hStereoDft->res_cod_mem_fx[0])); - floatToFixed_arr(hCPE->hStereoDft->hBpf->pst_old_syn, hCPE->hStereoDft->hBpf->pst_old_syn_fx, 0, sizeof(hCPE->hStereoDft->hBpf->pst_old_syn_fx) / sizeof(hCPE->hStereoDft->hBpf->pst_old_syn_fx[0])); - floatToFixed_arr(hCPE->hStereoDft->hBpf->mem_mean_pit, hCPE->hStereoDft->hBpf->mem_mean_pit_fx, Q4, sizeof(hCPE->hStereoDft->hBpf->mem_mean_pit) / sizeof(hCPE->hStereoDft->hBpf->mem_mean_pit[0])); - floatToFixed_arr(hCPE->hCoreCoder[0]->old_pitch_buf, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, Q6, sizeof(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx) / sizeof(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx[0])); - hCPE->hStereoDft->hBpf->psf_att_fx = (Word16)floatToFixed(hCPE->hStereoDft->hBpf->psf_att, Q15); - hCPE->hStereoDft->stab_fac_smooth_res_fx = (Word16)floatToFixed(hCPE->hStereoDft->stab_fac_smooth_res, Q15); + + Copy_Scale_sig_32_16(hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, 2 * NB_SUBFR16k + 2, -10); stereo_dft_dec_res_fx(hCPE, res_buf_fx, Q8, output_fix); - hCPE->hStereoDft->stab_fac_smooth_res = fixedToFloat(hCPE->hStereoDft->stab_fac_smooth_res_fx, Q15); - hCPE->hStereoDft->hBpf->psf_att = fixedToFloat(hCPE->hStereoDft->hBpf->psf_att_fx, Q15); - fixedToFloat_arr(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf, Q6, sizeof(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx) / sizeof(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx[0])); - fixedToFloat_arr(hCPE->hStereoDft->hBpf->mem_mean_pit_fx, hCPE->hStereoDft->hBpf->mem_mean_pit, Q4, sizeof(hCPE->hStereoDft->hBpf->mem_mean_pit) / sizeof(hCPE->hStereoDft->hBpf->mem_mean_pit[0])); - fixedToFloat_arr(hCPE->hStereoDft->hBpf->pst_old_syn_fx, hCPE->hStereoDft->hBpf->pst_old_syn, 0, sizeof(hCPE->hStereoDft->hBpf->pst_old_syn_fx) / sizeof(hCPE->hStereoDft->hBpf->pst_old_syn_fx[0])); + Copy_Scale_sig_16_32(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, 10); + fixedToFloat_arrL(hCPE->hStereoDft->res_cod_mem_fx, hCPE->hStereoDft->res_cod_mem, Q16, sizeof(hCPE->hStereoDft->res_cod_mem_fx) / sizeof(hCPE->hStereoDft->res_cod_mem_fx[0])); fixedToFloat_arrL(&output_fix[0], output_flt[1], Q15, L_FRAME8k); } @@ -747,16 +705,13 @@ ivas_error ivas_cpe_dec_fx( } /* DFT stereo CNG */ +#ifndef IVAS_FLOAT_FIXED stereo_dtf_cng( hCPE, ivas_total_brate, DFT, output_frame ); - - /* decoding */ - IF( EQ_16( hCPE->nchan_out, 1 ) ) - { - stereo_dft_unify_dmx( hCPE->hStereoDft, sts[0], DFT, hCPE->input_mem[1], hCPE->hStereoCng->prev_sid_nodata ); -#ifdef IVAS_FLOAT_FIXED +#else { + Word16 q_dft, q_smoothed_psd; float max_val = 0.0; - int i_max_val =0; + int i_max_val =0, i_max_val_psd = 0; for (int ii = 0; ii < sizeof(DFT) / sizeof(DFT[0]); ii++) { for (int jj = 0; jj < sizeof(DFT[0]) / sizeof(DFT[0][0]); jj++) @@ -767,14 +722,172 @@ ivas_error ivas_cpe_dec_fx( } } } - i_max_val = (int)max_val; - hCPE->hStereoDft->q_dft = norm_l(i_max_val) - Q10; - IF (hCPE->hStereoDft->q_dft > Q15) + max_val = 0.0; + for (int ii = 0; ii < sizeof(sts[0]->hFdCngDec->smoothed_psd) / sizeof(sts[0]->hFdCngDec->smoothed_psd[0]); ii++) { - hCPE->hStereoDft->q_dft = Q15; + if (max_val < fabs(sts[0]->hFdCngDec->smoothed_psd[ii])) + { + max_val = (float)fabs(sts[0]->hFdCngDec->smoothed_psd[ii]); + } } + i_max_val_psd = (int)max_val; + sts[0]->hFdCngDec->q_smoothed_psd = norm_l(i_max_val_psd) - Q4; + i_max_val = (int)max_val; + q_dft = s_min(Q8, norm_l(i_max_val)); + //hCPE->hStereoDft->q_dft = norm_l(i_max_val); + //IF (hCPE->hStereoDft->q_dft > Q8) + //{ + // hCPE->hStereoDft->q_dft = Q8; + //} + floatToFixed_arrL(sts[0]->hFdCngDec->bandNoiseShape_float, sts[0]->hFdCngDec->bandNoiseShape, Q31 - sts[0]->hFdCngDec->bandNoiseShape_exp, FFTLEN2); + floatToFixed_arrL(&DFT[0][0], &DFT_fx[0][0], q_dft, sizeof(DFT) / sizeof(DFT[0][0])); + //floatToFixed_arr(&hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG[0], &hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG_fx[0], Q15, sizeof(hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG_fx) / sizeof(hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG_fx[0])); + floatToFixed_arr(&hCPE->hStereoCng->cm[0], &hCPE->hStereoCng->cm_fx[0], Q15, sizeof( hCPE->hStereoCng->cm_fx ) / sizeof( hCPE->hStereoCng->cm_fx[0] ) ); + floatToFixed_arr(&hCPE->hStereoCng->coh[0], &hCPE->hStereoCng->coh_fx[0], Q15, sizeof(hCPE->hStereoCng->coh_fx) / sizeof(hCPE->hStereoCng->coh_fx[0]) ); + floatToFixed_arrL(&sts[0]->hFdCngDec->smoothed_psd[0], &sts[0]->hFdCngDec->smoothed_psd_fx[0], sts[0]->hFdCngDec->q_smoothed_psd, sizeof(sts[0]->hFdCngDec->smoothed_psd_fx) / sizeof(sts[0]->hFdCngDec->smoothed_psd_fx[0])); + hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->q_cngNoiseLevel = s_max(0, Q31 - hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp); + floatToFixed_arrL(&hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[0], + &hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel[0], + hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->q_cngNoiseLevel, + FFTCLDFBLEN); + + stereo_dtf_cng_fx( hCPE, ivas_total_brate, DFT_fx, output_frame, q_dft ); + + fixedToFloat_arrL(&hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel[0], + &hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[0], + hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->q_cngNoiseLevel, + FFTCLDFBLEN); + fixedToFloat_arrL(&sts[0]->hFdCngDec->smoothed_psd_fx[0], &sts[0]->hFdCngDec->smoothed_psd[0], sts[0]->hFdCngDec->q_smoothed_psd, sizeof(sts[0]->hFdCngDec->smoothed_psd_fx) / sizeof(sts[0]->hFdCngDec->smoothed_psd_fx[0])); + fixedToFloat_arr(&hCPE->hStereoCng->coh_fx[0], &hCPE->hStereoCng->coh[0], Q15, sizeof(hCPE->hStereoCng->coh_fx) / sizeof(hCPE->hStereoCng->coh_fx[0]) ); + fixedToFloat_arr( &hCPE->hStereoCng->cm_fx[0], &hCPE->hStereoCng->cm[0], Q15, sizeof( hCPE->hStereoCng->cm_fx ) / sizeof( hCPE->hStereoCng->cm_fx[0] ) ); + //fixedToFloat_arr(&hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG_fx[0], &hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG[0], Q15, sizeof(hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG) / sizeof(hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG[0])); + fixedToFloat_arrL(sts[0]->hFdCngDec->bandNoiseShape, sts[0]->hFdCngDec->bandNoiseShape_float, Q31 - sts[0]->hFdCngDec->bandNoiseShape_exp, FFTLEN2); + fixedToFloat_arrL(&DFT_fx[0][0], &DFT[0][0], q_dft, sizeof(DFT) / sizeof(DFT[0][0])); } #endif + + /* decoding */ + IF( EQ_16( hCPE->nchan_out, 1 ) ) + { +#if 1 + float l_hb_nrg = 0.0, l_hb_nrg_subr = 0.0; + float max_val = 0.0; + int i_max_val = 0, i_max_val_psd; + { + for (int ii = 0; ii < sizeof(sts[0]->hFdCngDec->smoothed_psd) / sizeof(sts[0]->hFdCngDec->smoothed_psd[0]); ii++) + { + if (max_val < fabs(sts[0]->hFdCngDec->smoothed_psd[ii])) + { + max_val = (float)fabs(sts[0]->hFdCngDec->smoothed_psd[ii]); + } + } + i_max_val_psd = (int)max_val; + sts[0]->hFdCngDec->q_smoothed_psd = norm_l(i_max_val_psd) - Q4; + max_val = 0.0; + for (int ii = 0; ii < sizeof(DFT) / sizeof(DFT[0]); ii++) + { + for (int jj = 0; jj < sizeof(DFT[0]) / sizeof(DFT[0][0]); jj++) + { + if (max_val < fabs(DFT[ii][jj])) + { + max_val = (float)fabs(DFT[ii][jj]); + } + } + } + i_max_val = (int)max_val; + hCPE->hStereoDft->q_dft = norm_l(i_max_val) - Q6; + IF(hCPE->hStereoDft->q_dft > Q15) + { + hCPE->hStereoDft->q_dft = Q15; + } + ELSE IF(hCPE->hStereoDft->q_dft < 0) + { + hCPE->hStereoDft->q_dft = 0; + } + //hCPE->hStereoDft->q_dft = s_min(hCPE->hStereoDft->q_dft, sts[0]->hFdCngDec->q_smoothed_psd); + IF(hCPE->hStereoDft->q_dft < 0) + { + hCPE->hStereoDft->q_dft = 0; + } + IF(EQ_16(hCPE->hStereoDft->first_frame, 1)) + { + hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft; + FOR(int ii = 0; ii < sizeof(hCPE->hStereoDft->q_DFT_past_DMX_fx) / sizeof(hCPE->hStereoDft->q_DFT_past_DMX_fx[0]); ii++) + { + hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft; + } + hCPE->hStereoDft->first_frame = 0; + } + + floatToFixed_arrL(&DFT[0][0], &DFT_fx[0][0], hCPE->hStereoDft->q_dft, sizeof(DFT) / sizeof(DFT[0][0])); + floatToFixed_arrL(&hCPE->hStereoDft->res_cod_mem[0], &hCPE->hStereoDft->res_cod_mem_fx[0], hCPE->hStereoDft->q_dft, sizeof(hCPE->hStereoDft->res_cod_mem_fx) / sizeof(hCPE->hStereoDft->res_cod_mem_fx[0])); + for (int ii = 0; ii < sizeof(hCPE->hStereoDft->hb_nrg_subr_fx) / sizeof(hCPE->hStereoDft->hb_nrg_subr_fx[0]); ii++) + { + if (l_hb_nrg_subr < hCPE->hStereoDft->hb_nrg_subr[ii]) + { + l_hb_nrg_subr = hCPE->hStereoDft->hb_nrg_subr[ii]; + } + } + hCPE->hStereoDft->q_hb_nrg_subr = 0; + if (l_hb_nrg_subr > (float)MAX_32) + { + int quotient = (int)ceil(l_hb_nrg_subr / (float)MAX_32); + hCPE->hStereoDft->q_hb_nrg_subr = Q31 - norm_l(quotient); + } + for (int ii = 0; ii < sizeof(hCPE->hStereoDft->hb_nrg_subr_fx) / sizeof(hCPE->hStereoDft->hb_nrg_subr_fx[0]); ii++) + { + hCPE->hStereoDft->hb_nrg_subr_fx[ii] = (Word32)(hCPE->hStereoDft->hb_nrg_subr[ii] / ((float)(1 << hCPE->hStereoDft->q_hb_nrg_subr))); + } + + + for (int ii = 0; ii < sizeof(hCPE->hStereoDft->hb_nrg_fx) / sizeof(hCPE->hStereoDft->hb_nrg_fx[0]); ii++) + { + if (l_hb_nrg < hCPE->hStereoDft->hb_nrg[ii]) + { + l_hb_nrg = hCPE->hStereoDft->hb_nrg[ii]; + } + } + hCPE->hStereoDft->q_hb_nrg = 0; + if (l_hb_nrg > (float)MAX_32) + { + int quotient = (int)ceil(l_hb_nrg / (float)MAX_32); + hCPE->hStereoDft->q_hb_nrg = Q31 - norm_l(quotient); + } + for (int ii = 0; ii < sizeof(hCPE->hStereoDft->hb_nrg_fx) / sizeof(hCPE->hStereoDft->hb_nrg_fx[0]); ii++) + { + hCPE->hStereoDft->hb_nrg_fx[ii] = (Word32)(hCPE->hStereoDft->hb_nrg[ii] / ((float)(1 << hCPE->hStereoDft->q_hb_nrg))); + } + + floatToFixed_arr(&hCPE->hStereoCng->cm[0], &hCPE->hStereoCng->cm_fx[0], Q15, sizeof(hCPE->hStereoCng->cm_fx) / sizeof(hCPE->hStereoCng->cm_fx[0])); + } +#endif + stereo_dft_unify_dmx_fx( hCPE->hStereoDft, sts[0], DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng->prev_sid_nodata ); +#if 1 + { + if (hCPE->hStereoDft->res_cod_band_max > 0) + { + if (!sts[0]->bfi) + { + fixedToFloat_arrL(&hCPE->hStereoDft->res_mem_fx[0], &hCPE->hStereoDft->res_mem[0], hCPE->hStereoDft->q_res_mem, 2 * hCPE->hStereoDft->band_limits[hCPE->hStereoDft->res_cod_band_max]); + } + else + { + fixedToFloat_arrL(&hCPE->hStereoDft->res_cod_mem_fx[0], &hCPE->hStereoDft->res_cod_mem[0], hCPE->hStereoDft->q_res_cod_mem_fx, sizeof(hCPE->hStereoDft->res_cod_mem_fx) / sizeof(hCPE->hStereoDft->res_cod_mem_fx[0])); + } + } + fixedToFloat_arrL(&DFT_fx[0][0], &DFT[0][0], hCPE->hStereoDft->q_dft, (sizeof(DFT) / (2 * sizeof(DFT[0][0])))); + for (int ii = 0; ii < sizeof(hCPE->hStereoDft->hb_nrg_subr_fx) / sizeof(hCPE->hStereoDft->hb_nrg_subr_fx[0]); ii++) + { + hCPE->hStereoDft->hb_nrg_subr[0] = ((float)hCPE->hStereoDft->hb_nrg_subr_fx[0] * ((float)(1 << hCPE->hStereoDft->q_hb_nrg_subr))); + } + for (int ii = 0; ii < sizeof(hCPE->hStereoDft->hb_nrg_fx) / sizeof(hCPE->hStereoDft->hb_nrg_fx[0]); ii++) + { + hCPE->hStereoDft->hb_nrg[ii] = ((float)hCPE->hStereoDft->hb_nrg_fx[ii] * ((float)(1 << hCPE->hStereoDft->q_hb_nrg))); + } + fixedToFloat_arr(&hCPE->hStereoCng->cm_fx[0], &hCPE->hStereoCng->cm[0], Q15, sizeof(hCPE->hStereoCng->cm_fx) / sizeof(hCPE->hStereoCng->cm_fx[0])); + fixedToFloat_arrL(&hCPE->hStereoDft->td_gain_fx[0], &hCPE->hStereoDft->td_gain[0], Q15, sizeof(hCPE->hStereoDft->td_gain_fx) / sizeof(hCPE->hStereoDft->td_gain_fx[0])); + } +#endif } ELSE { @@ -827,11 +940,8 @@ ivas_error ivas_cpe_dec_fx( hCPE->hStereoDft->first_frame = 0; } - sts[0]->hFdCngDec->cna_rescale_fact_fx = (Word16)floatToFixed(sts[0]->hFdCngDec->cna_rescale_fact, 15); + // sts[0]->hFdCngDec->cna_rescale_fact_fx = (Word16)floatToFixed(sts[0]->hFdCngDec->cna_rescale_fact, 15); sts[0]->hFdCngDec->cna_act_fact_fx = (Word16)floatToFixed(sts[0]->hFdCngDec->cna_act_fact, 15); - floatToFixed_arrL(&hCPE->hStereoDft->res_gains_ind[0][0], &hCPE->hStereoDft->res_gains_ind_fx[0][0], Q26, sizeof(hCPE->hStereoDft->res_gains_ind_fx) / sizeof(hCPE->hStereoDft->res_gains_ind_fx[0][0])); - floatToFixed_arrL(&hCPE->hStereoDft->res_pred_gain[0], &hCPE->hStereoDft->res_pred_gain_fx[0], Q31, sizeof(hCPE->hStereoDft->res_pred_gain_fx)/ sizeof(hCPE->hStereoDft->res_pred_gain_fx[0])); - floatToFixed_arrL(&hCPE->hStereoDft->itd[0], &hCPE->hStereoDft->itd_fx[0], Q15, sizeof(hCPE->hStereoDft->itd_fx) / sizeof(hCPE->hStereoDft->itd_fx[0])); floatToFixed_arrL(&sts[0]->hFdCngDec->smoothed_psd[0], &sts[0]->hFdCngDec->smoothed_psd_fx[0], sts[0]->hFdCngDec->q_smoothed_psd, sizeof(sts[0]->hFdCngDec->smoothed_psd_fx) / sizeof(sts[0]->hFdCngDec->smoothed_psd_fx[0])); floatToFixed_arrL(&DFT[0][0], &DFT_fx[0][0], hCPE->hStereoDft->q_dft , sizeof(DFT) / sizeof(DFT[0][0])); floatToFixed_arrL(&hCPE->hStereoDft->res_cod_mem[0], &hCPE->hStereoDft->res_cod_mem_fx[0], hCPE->hStereoDft->q_dft, sizeof(hCPE->hStereoDft->res_cod_mem_fx) / sizeof(hCPE->hStereoDft->res_cod_mem_fx[0])); @@ -872,20 +982,14 @@ ivas_error ivas_cpe_dec_fx( hCPE->hStereoDft->hb_nrg_fx[ii] = (Word32)(hCPE->hStereoDft->hb_nrg[ii] / ((float)(1 << hCPE->hStereoDft->q_hb_nrg))); } - floatToFixed_arrL(&hCPE->hStereoDft->side_gain[0], &hCPE->hStereoDft->side_gain_fx[0], Q31,sizeof(hCPE->hStereoDft->side_gain_fx) / sizeof(hCPE->hStereoDft->side_gain_fx[0])); - floatToFixed_arrL(&hCPE->hStereoDft->gipd[0], &hCPE->hStereoDft->gipd_fx[0], Q13, sizeof(hCPE->hStereoDft->gipd_fx) / sizeof(hCPE->hStereoDft->gipd_fx[0])); - floatToFixed_arr(&hCPE->hStereoDft->g_state[0], &hCPE->hStereoDft->g_state_fx[0], Q15, sizeof(hCPE->hStereoDft->g_state_fx) / sizeof(hCPE->hStereoDft->g_state_fx[0])); - floatToFixed_arr(&sts[0]->hFdCngDec->cna_cm[0], &sts[0]->hFdCngDec->cna_cm_fx[0], Q15, sizeof(sts[0]->hFdCngDec->cna_cm_fx) / sizeof(sts[0]->hFdCngDec->cna_cm_fx[0])); + //floatToFixed_arr(&sts[0]->hFdCngDec->cna_cm[0], &sts[0]->hFdCngDec->cna_cm_fx[0], Q15, sizeof(sts[0]->hFdCngDec->cna_cm_fx) / sizeof(sts[0]->hFdCngDec->cna_cm_fx[0])); floatToFixed_arr(&hCPE->hStereoCng->cm[0], &hCPE->hStereoCng->cm_fx[0], Q15, sizeof(hCPE->hStereoCng->cm_fx) / sizeof(hCPE->hStereoCng->cm_fx[0])); - floatToFixed_arr(&sts[0]->hFdCngDec->cna_g_state[0], &sts[0]->hFdCngDec->cna_g_state_fx[0], Q15, sizeof(sts[0]->hFdCngDec->cna_g_state_fx) / sizeof(sts[0]->hFdCngDec->cna_g_state_fx[0])); + //floatToFixed_arr(&sts[0]->hFdCngDec->cna_g_state[0], &sts[0]->hFdCngDec->cna_g_state_fx[0], Q15, sizeof(sts[0]->hFdCngDec->cna_g_state_fx) / sizeof(sts[0]->hFdCngDec->cna_g_state_fx[0])); } stereo_dft_dec_fx( hCPE->hStereoDft, sts[0], DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng, 0, 0, 0, 0, 0, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); { - sts[0]->hFdCngDec->cna_rescale_fact = fixedToFloat(sts[0]->hFdCngDec->cna_rescale_fact_fx, 15); + // sts[0]->hFdCngDec->cna_rescale_fact = fixedToFloat(sts[0]->hFdCngDec->cna_rescale_fact_fx, 15); sts[0]->hFdCngDec->cna_act_fact = fixedToFloat(sts[0]->hFdCngDec->cna_act_fact_fx, 15); - fixedToFloat_arrL(&hCPE->hStereoDft->res_gains_ind_fx[0][0], &hCPE->hStereoDft->res_gains_ind[0][0], Q26, sizeof(hCPE->hStereoDft->res_gains_ind_fx) / sizeof(hCPE->hStereoDft->res_gains_ind_fx[0][0])); - fixedToFloat_arrL(&hCPE->hStereoDft->res_pred_gain_fx[0], &hCPE->hStereoDft->res_pred_gain[0], Q31, sizeof(hCPE->hStereoDft->res_pred_gain_fx)/ sizeof(hCPE->hStereoDft->res_pred_gain_fx[0])); - fixedToFloat_arrL(&hCPE->hStereoDft->itd_fx[0], &hCPE->hStereoDft->itd[0], Q15, sizeof(hCPE->hStereoDft->itd_fx) / sizeof(hCPE->hStereoDft->itd_fx[0])); fixedToFloat_arrL(&sts[0]->hFdCngDec->smoothed_psd_fx[0], &sts[0]->hFdCngDec->smoothed_psd[0], sts[0]->hFdCngDec->q_smoothed_psd, sizeof(sts[0]->hFdCngDec->smoothed_psd_fx) / sizeof(sts[0]->hFdCngDec->smoothed_psd_fx[0])); fixedToFloat_arrL(&DFT_fx[0][0], &DFT[0][0], hCPE->hStereoDft->q_dft , sizeof(DFT) / sizeof(DFT[0][0])); for (int ii = 0; ii < sizeof(hCPE->hStereoDft->hb_nrg_subr_fx) / sizeof(hCPE->hStereoDft->hb_nrg_subr_fx[0]); ii++) @@ -896,12 +1000,9 @@ ivas_error ivas_cpe_dec_fx( { hCPE->hStereoDft->hb_nrg[ii] = ((float)hCPE->hStereoDft->hb_nrg_fx[ii] * ((float)(1 << hCPE->hStereoDft->q_hb_nrg))); } - fixedToFloat_arrL(&hCPE->hStereoDft->side_gain_fx[0], &hCPE->hStereoDft->side_gain[0], Q31,sizeof(hCPE->hStereoDft->side_gain_fx) / sizeof(hCPE->hStereoDft->side_gain_fx[0])); - fixedToFloat_arrL(&hCPE->hStereoDft->gipd_fx[0], &hCPE->hStereoDft->gipd[0], Q13, sizeof(hCPE->hStereoDft->gipd_fx) / sizeof(hCPE->hStereoDft->gipd_fx[0])); - fixedToFloat_arr(&hCPE->hStereoDft->g_state_fx[0], &hCPE->hStereoDft->g_state[0], Q15, sizeof(hCPE->hStereoDft->g_state_fx) / sizeof(hCPE->hStereoDft->g_state_fx[0])); - fixedToFloat_arr(&sts[0]->hFdCngDec->cna_cm_fx[0], &sts[0]->hFdCngDec->cna_cm[0], Q15, sizeof(sts[0]->hFdCngDec->cna_cm_fx) / sizeof(sts[0]->hFdCngDec->cna_cm_fx[0])); + //fixedToFloat_arr(&sts[0]->hFdCngDec->cna_cm_fx[0], &sts[0]->hFdCngDec->cna_cm[0], Q15, sizeof(sts[0]->hFdCngDec->cna_cm_fx) / sizeof(sts[0]->hFdCngDec->cna_cm_fx[0])); fixedToFloat_arr(&hCPE->hStereoCng->cm_fx[0], &hCPE->hStereoCng->cm[0], Q15, sizeof(hCPE->hStereoCng->cm_fx) / sizeof(hCPE->hStereoCng->cm_fx[0])); - fixedToFloat_arr(&sts[0]->hFdCngDec->cna_g_state_fx[0], &sts[0]->hFdCngDec->cna_g_state[0], Q15, sizeof(sts[0]->hFdCngDec->cna_g_state_fx) / sizeof(sts[0]->hFdCngDec->cna_g_state_fx[0])); + //fixedToFloat_arr(&sts[0]->hFdCngDec->cna_g_state_fx[0], &sts[0]->hFdCngDec->cna_g_state[0], Q15, sizeof(sts[0]->hFdCngDec->cna_g_state_fx) / sizeof(sts[0]->hFdCngDec->cna_g_state_fx[0])); fixedToFloat_arrL(&hCPE->hStereoDft->td_gain_fx[0], &hCPE->hStereoDft->td_gain[0], Q15, sizeof(hCPE->hStereoDft->td_gain_fx) / sizeof(hCPE->hStereoDft->td_gain_fx[0])); fixedToFloat_arrL(&hCPE->hStereoDft->res_cod_mem_fx[0], &hCPE->hStereoDft->res_cod_mem[0], hCPE->hStereoDft->q_dft, sizeof(hCPE->hStereoDft->res_cod_mem_fx) / sizeof(hCPE->hStereoDft->res_cod_mem_fx[0])); } @@ -914,13 +1015,13 @@ ivas_error ivas_cpe_dec_fx( stereo_dft_dec_synthesize( hCPE, DFT, n, output_flt[n], output_frame ); #else hCPE->q_output_mem_fx[n] = hCPE->hStereoDft->q_dft; - hCPE->lt_es_em_fx = floatToFixed(hCPE->lt_es_em, Q15); + //hCPE->lt_es_em_fx = floatToFixed(hCPE->lt_es_em, Q15); floatToFixed_arrL(&DFT[n][0], &DFT_fx[n][0],hCPE->hStereoDft->q_dft, sizeof(DFT[n]) / sizeof(DFT[0][0])); floatToFixed_arrL(&hCPE->output_mem[n][0], &hCPE->output_mem_fx[n][0], hCPE->hStereoDft->q_dft, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS )); stereo_dft_dec_synthesize_fx( hCPE, DFT_fx, n, output[n], output_frame ); fixedToFloat_arrL(&hCPE->output_mem_fx[n][0], &hCPE->output_mem[n][0], hCPE->hStereoDft->q_dft, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS )); fixedToFloat_arrL(&DFT_fx[n][0], &DFT[n][0],hCPE->hStereoDft->q_dft, sizeof(DFT_fx[n]) / sizeof(DFT_fx[0][0])); - hCPE->lt_es_em = fixedToFloat(hCPE->lt_es_em_fx, Q15); + //hCPE->lt_es_em = fixedToFloat(hCPE->lt_es_em_fx, Q15); #endif } @@ -954,7 +1055,6 @@ ivas_error ivas_cpe_dec_fx( } /* TD stereo upmixing */ - //stereo_tdm_combine( hCPE, output_flt[0], output_flt[1], output_frame, 0, tdm_ratio_idx ); stereo_tdm_combine_fx(hCPE, output[0], output[1], output_frame, 0, tdm_ratio_idx); IF( sts[0]->tdm_LRTD_flag ) { @@ -967,8 +1067,7 @@ ivas_error ivas_cpe_dec_fx( IF( EQ_16( hCPE->nchan_out, 1 ) ) { /* Scale the Right channel with the gain */ - stereo_tca_scale_R_channel( hCPE, output_flt[1], output_frame ); - //stereo_tca_scale_R_channel_fx(hCPE, output[1], output_frame); + stereo_tca_scale_R_channel_fx( hCPE, output[1], output_frame ); /* stereo to mono downmix */ FOR( i = 0; i < output_frame; i++ ) { @@ -1013,8 +1112,6 @@ ivas_error ivas_cpe_dec_fx( { hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << output_q ) ); } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); } } IF( hCPE->hCoreCoder[n] != NULL ) @@ -1029,8 +1126,6 @@ ivas_error ivas_cpe_dec_fx( { hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << output_q ) ); } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); } FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) @@ -1065,10 +1160,10 @@ ivas_error ivas_cpe_dec_fx( } } - FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) - { - hCPE->prev_hb_synth_fx[n][k] = (Word32) ( hCPE->prev_hb_synth[n][k] * ( 1 << output_q ) ); - } + //FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) + //{ + // hCPE->prev_hb_synth_fx[n][k] = (Word32) ( hCPE->prev_hb_synth[n][k] * ( 1 << output_q ) ); + //} FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) { hCPE->prev_synth_fx[n][k] = (Word32) ( hCPE->prev_synth[n][k] * ( 1 << output_q ) ); @@ -1091,8 +1186,6 @@ ivas_error ivas_cpe_dec_fx( { hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } } FOR( n = 0; n < CPE_CHANNELS; n++ ) @@ -1116,8 +1209,6 @@ ivas_error ivas_cpe_dec_fx( { hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) { @@ -1142,10 +1233,10 @@ ivas_error ivas_cpe_dec_fx( hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << output_q ) ); } } - FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) - { - hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << output_q ); - } + //FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) + //{ + // hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << output_q ); + //} FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) { hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << output_q ); @@ -1163,7 +1254,7 @@ ivas_error ivas_cpe_dec_fx( * IC-BWE: output LB and HB mix in ACELP mode *----------------------------------------------------------------*/ - stereo_icBWE_decproc_fx(hCPE, output, outputHB_fx, last_core, last_bwidth, output_frame); + stereo_icBWE_decproc_fx(hCPE, output, outputHB_fx, last_core, last_bwidth, output_frame, *q_output); smooth_dft2td_transition_fx( hCPE, output, output_frame ); @@ -1263,7 +1354,7 @@ ivas_error create_cpe_dec( hCPE->stereo_switching_counter = 10; hCPE->NbFrameMod = 7; - hCPE->lt_es_em = 0.0f; + //hCPE->lt_es_em = 0.0f; hCPE->lt_es_em_fx = 0; /* Note: nchan_out is considered to be related to the structure. This is nchan_out for CPE and for MASA_format is always 2. */ @@ -1295,7 +1386,7 @@ ivas_error create_cpe_dec( #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED for ( n = 0; n < CPE_CHANNELS; n++ ) { - set_f( hCPE->prev_hb_synth[n], 0, NS2SA( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) ); + //set_f( hCPE->prev_hb_synth[n], 0, NS2SA( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) ); set_f( hCPE->prev_synth[n], 0, NS2SA( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ) ); } #endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED @@ -1385,21 +1476,6 @@ ivas_error create_cpe_dec( { hCPE->prev_synth_chs_fx[i] = NULL; } - -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - if ( i < hCPE->nchan_out ) - { - if ( ( hCPE->prev_synth_chs[i] = (float *) malloc( sizeof( float ) * NS2SA( output_Fs, FRAME_SIZE_NS ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) ); - } - set_zero( hCPE->prev_synth_chs[i], NS2SA( output_Fs, FRAME_SIZE_NS ) ); - } - else - { - hCPE->prev_synth_chs[i] = NULL; - } -#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED } ELSE { @@ -1420,7 +1496,6 @@ ivas_error create_cpe_dec( hCPE->input_mem_BPF[0] = NULL; } hCPE->output_mem[i] = NULL; - hCPE->prev_synth_chs[i] = NULL; #endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED } } @@ -1517,7 +1592,6 @@ ivas_error create_cpe_dec( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE\n" ) ); } - //stereo_icBWE_init_dec( hCPE->hStereoICBWE ); #ifdef IVAS_FLOAT_FIXED stereo_icBWE_init_dec_fx(hCPE->hStereoICBWE); #else @@ -1561,10 +1635,18 @@ ivas_error create_cpe_dec( } hCPE->hStereoMdct->reverse_dmx = 0; +#ifndef IVAS_FLOAT_FIXED hCPE->hStereoMdct->smooth_ratio = 1.f; +#else + hCPE->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; +#endif set_s( hCPE->hStereoMdct->prev_ms_mask[0], 0, MAX_SFB ); set_s( hCPE->hStereoMdct->prev_ms_mask[1], 0, MAX_SFB ); +#ifndef IVAS_FLOAT_FIXED hCPE->hStereoMdct->lastCoh = 1.f; +#else + hCPE->hStereoMdct->lastCoh_fx = ONE_IN_Q14; +#endif hCPE->hStereoMdct->mdct_stereo_mode[0] = SMDCT_DUAL_MONO; hCPE->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO; hCPE->hStereoMdct->IGFStereoMode[0] = -1; @@ -1667,13 +1749,10 @@ void destroy_cpe_dec( hCPE->input_mem_LB_fx[n] = NULL; free( hCPE->input_mem_fx[n] ); hCPE->input_mem_fx[n] = NULL; + free(hCPE->output_mem_fx[n]); + hCPE->output_mem_fx[n] = NULL; #endif - IF( hCPE->prev_synth_chs[n] != NULL ) - { - free( hCPE->prev_synth_chs[n] ); - hCPE->prev_synth_chs[n] = NULL; - } IF( hCPE->prev_synth_chs_fx[n] != NULL ) { free( hCPE->prev_synth_chs_fx[n] ); diff --git a/lib_dec/ivas_decision_matrix_dec.c b/lib_dec/ivas_decision_matrix_dec.c index c90f6c1a3900c61c5efd7c0e3eba0604d7339de6..3e6b18cdcf409da1907b42350bd4c26a352483bc 100644 --- a/lib_dec/ivas_decision_matrix_dec.c +++ b/lib_dec/ivas_decision_matrix_dec.c @@ -53,7 +53,7 @@ static Word16 get_next_index_4_by_15[16] = 0, 2184, 4369, 6553, 8738, 10922, 13107, 15291, 17476, 19660, 21845, 24029, 26214, 28398, 30583, 32767 }; #endif - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void ivas_decision_matrix_dec( Decoder_State *st, /* i/o: decoder state structure */ int16_t *sharpFlag, /* o : formant sharpening flag */ @@ -471,7 +471,7 @@ void ivas_decision_matrix_dec( return; } - +#endif #ifdef IVAS_FLOAT_FIXED void ivas_decision_matrix_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ @@ -546,8 +546,8 @@ void ivas_decision_matrix_dec_fx( index = get_next_indice( st, 4 ); st->hFdCngDec->hFdCngCom->coherence_fx = get_next_index_4_by_15[index]; - /* TODO: remove floating point dependency */ - st->hFdCngDec->hFdCngCom->coherence_flt = ( (float) get_next_index_4_by_15[index] ) / ( ( 1 << 15 ) - 1 ); + ///* TODO: remove floating point dependency */ + //st->hFdCngDec->hFdCngCom->coherence_flt = ( (float) get_next_index_4_by_15[index] ) / ( ( 1 << 15 ) - 1 ); /* read flag for no side noise shape */ st->hFdCngDec->hFdCngCom->no_side_flag = get_next_indice( st, 1 ); diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 1f3a3a0e033e9b3f13a5c5d3a01f5dce5df505b8..da8ddb41050259a570fb7c394325eea5d89af790 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -734,9 +734,9 @@ static ivas_error ivas_dirac_rend_config_fx( IF( ( EQ_16( flag_config, DIRAC_OPEN && hDirACRend->proto_signal_decorr_on ) ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirACRend->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) ) { #ifdef IVAS_FLOAT_FIXED - FOR( int i = 0; i < st_ivas->hSpatParamRendCom->num_freq_bands; i++ ) + FOR( int ii = 0; ii < st_ivas->hSpatParamRendCom->num_freq_bands; ii++ ) { - hDirACRend->frequency_axis_fx[i] = (Word16) hDirACRend->frequency_axis[i]; + hDirACRend->frequency_axis_fx[ii] = (Word16) hDirACRend->frequency_axis[ii]; } IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) @@ -762,9 +762,9 @@ static ivas_error ivas_dirac_rend_config_fx( /* close and reopen the decorrelator */ ivas_dirac_dec_decorr_close( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); #ifdef IVAS_FLOAT_FIXED - FOR( int i = 0; i < st_ivas->hSpatParamRendCom->num_freq_bands; i++ ) + FOR( int ii = 0; ii < st_ivas->hSpatParamRendCom->num_freq_bands; ii++ ) { - hDirACRend->frequency_axis_fx[i] = (Word16) hDirACRend->frequency_axis[i]; + hDirACRend->frequency_axis_fx[ii] = (Word16) hDirACRend->frequency_axis[ii]; } IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) @@ -1739,8 +1739,7 @@ ivas_error ivas_dirac_dec_config( IF( st_ivas->hDiracDecBin == NULL ) { - /*WIP*/ - IF( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) { return error; } @@ -1793,7 +1792,7 @@ ivas_error ivas_dirac_dec_config( } #ifdef IVAS_FLOAT_FIXED - st_ivas->hDiracDecBin->reqularizationFactor = (float) configure_reqularization_factor_fx( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ) / ( 1 << 14 ); + st_ivas->hDiracDecBin->reqularizationFactor_fx = configure_reqularization_factor_fx( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); #else st_ivas->hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); #endif @@ -3381,6 +3380,109 @@ void ivas_dirac_dec_set_md_map_fx( return; } #endif +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * ivas_dirac_dec_render_fx() + * + * DirAC decoding renderer process + *------------------------------------------------------------------------*/ + +void ivas_dirac_dec_render( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const Word16 nchan_transport, /* i : number of transport channels */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ + float *output_f[] /* o : rendered time signal */ +) +{ + Word16 slots_to_render, first_sf, last_sf, subframe_idx; + UWord16 slot_size, n_samples_sf, ch, nchan_intern; + Word16 temp = 0; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + float *output_f_local[MAX_OUTPUT_CHANNELS]; + float output_f_local_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; // VE2SB: TBV + + Word32 *output_f_local_fx[MAX_OUTPUT_CHANNELS]; + Word32 output_f_local_buff_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; // VE2SB: TBV + Word32 output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; + + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + + nchan_intern = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); + FOR( ch = 0; ch < nchan_intern; ch++ ) + { + output_f_local[ch] = output_f_local_buff[ch]; + set_zero( output_f_local_buff[ch], nSamplesAsked ); + + output_f_local_fx[ch] = output_f_local_buff_fx[ch]; + set_zero_fx( output_f_local_fx[ch], nSamplesAsked ); + } + slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // cL + move16(); + + /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ + slots_to_render = s_min( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) ); + + *nSamplesRendered = i_mult( slots_to_render, slot_size ); + move16(); + + first_sf = hSpatParamRendCom->subframes_rendered; + move16(); + last_sf = first_sf; + move16(); + + WHILE( GT_16( slots_to_render, 0 ) ) + { + slots_to_render = sub( slots_to_render, hSpatParamRendCom->subframe_nbslots[last_sf] ); + last_sf++; + } + + FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) + { + ivas_dirac_dec_render_sf( st_ivas, output_f_local, nchan_transport, NULL, NULL ); + + n_samples_sf = i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slot_size ); + + FOR( ch = 0; ch < nchan_intern; ch++ ) + { + output_f_local[ch] += n_samples_sf; + output_f_local_fx[ch] += n_samples_sf; + } + + /* update combined orientation access index */ + ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf ); + } + + FOR( ch = 0; ch < nchan_intern; ch++ ) + { + IF( !( L_and( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ), ( L_or( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ), EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) ) ) ) + { + mvr2r( output_f_local_buff[ch], output_f[ch], *nSamplesRendered ); + Copy32( output_f_local_buff_fx[ch], output_fx[ch], *nSamplesRendered ); + } + } + + IF( EQ_16( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->num_slots ) ) + { + IF( EQ_16( st_ivas->hDirAC->hConfig->dec_param_estim, 1 ) ) + { + temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_CLDFB_TIMESLOTS ); + hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); + } + ELSE + { + temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS ); + hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); + } + } + + *nSamplesAvailableNext = i_mult(sub(hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered), slot_size); + move16(); + + return; +} +#else /*------------------------------------------------------------------------- * ivas_dirac_dec_render() * @@ -3461,7 +3563,7 @@ void ivas_dirac_dec_render( return; } - +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_render_sf() @@ -3479,12 +3581,6 @@ void ivas_dirac_dec_render_sf( int16_t i, ch, idx_in, idx_lfe; DIRAC_DEC_HANDLE hDirAC; DIRAC_REND_HANDLE hDirACRend; - float dirEne; - float surCohEner; - float surCohRatio[CLDFB_NO_CHANNELS_MAX]; -#ifdef IVAS_FLOAT_FIXED - set_zero( surCohRatio, CLDFB_NO_CHANNELS_MAX ); -#endif int16_t subframe_idx; int16_t slot_idx, index_slot; int16_t hodirac_flag; @@ -3496,8 +3592,6 @@ void ivas_dirac_dec_render_sf( float Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; float Cldfb_RealBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; float Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - float Cldfb_RealBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - float Cldfb_ImagBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; int16_t index, num_freq_bands; /* local copies of azi, ele, diffuseness */ @@ -3507,22 +3601,41 @@ void ivas_dirac_dec_render_sf( #ifdef IVAS_FLOAT_FIXED Word32 diffuseness_vector_fx[CLDFB_NO_CHANNELS_MAX]; Word32 *p_Rmat_fx; - /////////////////////////////////// to be removed //////////////////////////////////////////////// - if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] ) - { - p_Rmat_fx = &st_ivas->hCombinedOrientationData->Rmat_fx[st_ivas->hCombinedOrientationData->subframe_idx][0][0]; - floatToFixed_arrL( &st_ivas->hCombinedOrientationData->Rmat[st_ivas->hCombinedOrientationData->subframe_idx][0][0], p_Rmat_fx, Q29, 9 ); - } - else - { - p_Rmat_fx = 0; - } - ///////////////////////////////////////////////////////////////////////////////////////////////////////// + Word32 *reference_power_fx, *reference_power_smooth_fx, *onset_filter_fx, *onset_filter_subframe_fx; + Word32 dirEne_fx; + Word32 surCohEner_fx; + Word32 surCohRatio_fx[CLDFB_NO_CHANNELS_MAX]; + Word16 surCohRatio_q_fx = 0, temp_q = 0; + Word16 diffuse_power_factor_q = 0, direct_power_factor_q = 0; + Word32 Cldfb_RealBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word32 Cldfb_ImagBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word16 cldfb_buf_q; + Word32 pppQMfFrame_ts_re_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 pppQMfFrame_ts_im_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; + Word32 Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; + set_zero_fx(surCohRatio_fx, CLDFB_NO_CHANNELS_MAX); + Word16 q_cldfb;; + Word16 Q_cldfb_scale; + Word32 proto_frame_f_fx[2 * MAX_OUTPUT_CHANNELS * CLDFB_SLOTS_PER_SUBFRAME * CLDFB_NO_CHANNELS_MAX]; + Word32 proto_direct_buffer_f_fx[2 * MAX_OUTPUT_CHANNELS * CLDFB_SLOTS_PER_SUBFRAME * CLDFB_NO_CHANNELS_MAX]; + Word32 proto_power_smooth_fx[2 * CLDFB_NO_CHANNELS_MAX * MAX_OUTPUT_CHANNELS]; + Word32 reference_power_fix[5 * CLDFB_NO_CHANNELS_MAX]; + Word32 onset_filter_subframe_fix[2 * MAX_OUTPUT_CHANNELS]; + Word32 proto_diffuse_buffer_f_fx[2 * MAX_OUTPUT_CHANNELS * CLDFB_SLOTS_PER_SUBFRAME * CLDFB_NO_CHANNELS_MAX]; + set_zero_fx( &proto_frame_f_fx[0], 2 * MAX_OUTPUT_CHANNELS * CLDFB_SLOTS_PER_SUBFRAME * CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( &proto_direct_buffer_f_fx[0], 2 * CLDFB_SLOTS_PER_SUBFRAME * CLDFB_NO_CHANNELS_MAX * MAX_OUTPUT_CHANNELS ); + set_zero_fx( &proto_power_smooth_fx[0], 2 * CLDFB_NO_CHANNELS_MAX * MAX_OUTPUT_CHANNELS ); + set_zero_fx( &reference_power_fix[0], 5 * CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( &proto_diffuse_buffer_f_fx[0], 2 * CLDFB_SLOTS_PER_SUBFRAME * CLDFB_NO_CHANNELS_MAX * MAX_OUTPUT_CHANNELS ); #endif DIRAC_DEC_STACK_MEM DirAC_mem; float *reference_power, *reference_power_smooth; float *onset_filter, *onset_filter_subframe, *p_onset_filter = NULL; +#ifdef IVAS_FLOAT_FIXED + Word32 *p_onset_filter_fx = NULL; +#endif uint16_t coherence_flag; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; @@ -3539,7 +3652,580 @@ void ivas_dirac_dec_render_sf( reference_power_smooth = ( DirAC_mem.reference_power == NULL ) ? NULL : DirAC_mem.reference_power + hSpatParamRendCom->num_freq_bands; onset_filter = DirAC_mem.onset_filter; onset_filter_subframe = ( DirAC_mem.onset_filter == NULL ) ? NULL : DirAC_mem.onset_filter + hSpatParamRendCom->num_freq_bands; +#ifdef IVAS_FLOAT_FIXED + reference_power_fx = DirAC_mem.reference_power_fx; + reference_power_smooth_fx = ( DirAC_mem.reference_power_fx == NULL ) ? NULL : DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands; + onset_filter_fx = DirAC_mem.onset_filter_fx; + onset_filter_subframe_fx = ( DirAC_mem.onset_filter_fx == NULL ) ? NULL : DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands; + + //////////////////////////////////////////////////////////////////////////// to be removed /////////////////////////////////////////////////////////////////// + reference_power_smooth_fx = &reference_power_fix[hSpatParamRendCom->num_freq_bands]; + onset_filter_subframe_fx = &onset_filter_subframe_fix[hSpatParamRendCom->num_freq_bands]; + IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + { + mvr2r( hSpatParamRendCom->diffuseness_vector[hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->subframes_rendered]], diffuseness_vector, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL32( diffuseness_vector, hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->subframes_rendered]], Q30, hSpatParamRendCom->num_freq_bands ); + md_idx = hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->subframes_rendered]; + } + ELSE + { + set_zero( diffuseness_vector, hSpatParamRendCom->num_freq_bands ); + md_idx = hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->slots_rendered]; + } + + IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + set_zero( reference_power_smooth, hSpatParamRendCom->num_freq_bands ); + } + ELSE + { + set_zero( onset_filter_subframe, hSpatParamRendCom->num_freq_bands ); +#ifdef IVAS_FLOAT_FIXED + set_zero_fx( onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands ); +#endif + } + IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] ) + { + p_Rmat = &st_ivas->hCombinedOrientationData->Rmat[st_ivas->hCombinedOrientationData->subframe_idx][0][0]; + p_Rmat_fx = &st_ivas->hCombinedOrientationData->Rmat_fx[st_ivas->hCombinedOrientationData->subframe_idx][0][0]; + floatToFixed_arrL32( &st_ivas->hCombinedOrientationData->Rmat[st_ivas->hCombinedOrientationData->subframe_idx][0][0], p_Rmat_fx, Q29, 9 ); + } + ELSE + { + p_Rmat = 0; + p_Rmat_fx = 0; + } + IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) + { + IF( EQ_16( hSpatParamRendCom->numParametricDirections, 2 ) ) + { + floatToFixed_arr( hDirACRend->diffuse_response_function, hDirACRend->diffuse_response_function_fx, Q15, hDirACRend->num_outputs_dir ); + floatToFixed_arrL32( hSpatParamRendCom->energy_ratio1[md_idx], hSpatParamRendCom->energy_ratio1_fx[md_idx], Q30, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL32( hSpatParamRendCom->energy_ratio2[md_idx], hSpatParamRendCom->energy_ratio2_fx[md_idx], Q30, hSpatParamRendCom->num_freq_bands ); + } + } + + IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] ) + { + floatToFixed_arrL32( &st_ivas->hCombinedOrientationData->Rmat[st_ivas->hCombinedOrientationData->subframe_idx][0][0], &st_ivas->hCombinedOrientationData->Rmat_fx[st_ivas->hCombinedOrientationData->subframe_idx][0][0], Q29, 9 ); + } + + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[hSpatParamRendCom->subframes_rendered]; slot_idx++ ) + { + IF( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) + { + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + floatToFixed_arrL32( pppQMfFrame_ts_re[ch][slot_idx], pppQMfFrame_ts_re_fx[ch][slot_idx], Q6, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL32( pppQMfFrame_ts_im[ch][slot_idx], pppQMfFrame_ts_im_fx[ch][slot_idx], Q6, hSpatParamRendCom->num_freq_bands ); + } + } + ELSE + { + Word32 offset = i_mult( hSpatParamRendCom->num_freq_bands, add( hSpatParamRendCom->slots_rendered, slot_idx ) ); + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + floatToFixed_arrL32( &st_ivas->hTcBuffer->tc[hDirACRend->sba_map_tc[ch]][offset], &st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][offset], Q11, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL32( st_ivas->cldfbAnaDec[ch]->cldfb_state, st_ivas->cldfbAnaDec[ch]->cldfb_state_fx, Q11, ( st_ivas->cldfbAnaDec[ch]->p_filter_length - st_ivas->cldfbAnaDec[ch]->no_channels ) ); + } + } + } + + IF( EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && !( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) ) + { + floatToFixed_arrL32( st_ivas->hTcBuffer->tc[1], st_ivas->hTcBuffer->tc_fx[1], Q11, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL32( st_ivas->cldfbAnaDec[1]->cldfb_state, st_ivas->cldfbAnaDec[1]->cldfb_state_fx, Q11, ( st_ivas->cldfbAnaDec[1]->p_filter_length - st_ivas->cldfbAnaDec[1]->no_channels ) ); + } + + IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled && !( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && EQ_16( hDirACRend->hOutSetup.num_lfe, 0 ) ) ) + { + st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth_fx = floatToFixed_32( st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth, st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth_q ); + st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth_fx = floatToFixed_32( st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth, st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth_q ); + st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_fx = floatToFixed_32( st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth, st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_q ); + st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth_fx = floatToFixed_32( st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth, st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth_q ); + } + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); + + IF( st_ivas->hQMetaData != NULL && st_ivas->ivas_format != SBA_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT ) + { + coherence_flag = st_ivas->hQMetaData->coherence_flag; + move16(); + } + ELSE + { + coherence_flag = 0; + move16(); + } + /* Subframe loop */ + slot_idx_start = hSpatParamRendCom->slots_rendered; + move16(); + slot_idx_start_cldfb_synth = 0; + move16(); + + subframe_idx = hSpatParamRendCom->subframes_rendered; + move16(); + IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + { + md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; + move16(); + } + ELSE + { + md_idx = hSpatParamRendCom->render_to_md_map[slot_idx_start]; + move16(); + } + + /* copy parameters into local buffers*/ + IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + { + Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands ); + Copy( hSpatParamRendCom->azimuth[hSpatParamRendCom->render_to_md_map[subframe_idx]], azimuth, hSpatParamRendCom->num_freq_bands ); + Copy( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands ); + } + ELSE + { + set32_fx( diffuseness_vector_fx, 0, hSpatParamRendCom->num_freq_bands ); + } + + IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + set_zero_fx( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands ); + } + ELSE + { + set_zero_fx( onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands ); + } + + IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] ) + { + p_Rmat_fx = &st_ivas->hCombinedOrientationData->Rmat_fx[st_ivas->hCombinedOrientationData->subframe_idx][0][0]; + + IF( EQ_16( st_ivas->hCombinedOrientationData->shd_rot_max_order, 0 ) ) + { + num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; + move16(); + IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + { + rotateAziEle_DirAC_fx( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat_fx ); + } + } + } + ELSE + { + p_Rmat_fx = 0; + } + + IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + { + /* compute response */ + IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + ivas_dirac_dec_compute_power_factors_fx( hSpatParamRendCom->num_freq_bands, + diffuseness_vector_fx, + hDirACRend->h_output_synthesis_psd_params.max_band_decorr, + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx ); + + direct_power_factor_q = Q29; + move16(); + diffuse_power_factor_q = Q29; + move16(); + + IF( coherence_flag ) + { + FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) + { + dirEne_fx = hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i]; // Q29 + move32(); + surCohEner_fx = Mpy_32_16_1( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); // Q29 + Q15 - Q15 = Q29 + + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i] = L_sub( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], surCohEner_fx ); // Q29 + move32(); + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i] = L_add( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], surCohEner_fx ); // Q29 + move32(); + + surCohRatio_fx[i] = BASOP_Util_Divide3232_Scale( surCohEner_fx, ( L_add( EPSILLON_FX, L_add( dirEne_fx, surCohEner_fx ) ) ), &temp_q ); + move32(); + surCohRatio_fx[i] = L_shl( surCohRatio_fx[i], temp_q ); + move32(); + } + } + ELSE + { + set_zero_fx( surCohRatio_fx, hSpatParamRendCom->num_freq_bands ); + } + surCohRatio_q_fx = Q15; + move16(); + } + ELSE + { + Word16 max_exp_direct = 0, max_exp_diffusion = 0; + ivas_dirac_dec_compute_gain_factors_fx( hSpatParamRendCom->num_freq_bands, + hSpatParamRendCom->diffuseness_vector_fx[md_idx], + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, + &max_exp_direct, &max_exp_diffusion ); + + direct_power_factor_q = sub( Q31, max_exp_direct ); + diffuse_power_factor_q = sub( Q31, max_exp_diffusion ); + + IF( coherence_flag ) + { + FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) + { + surCohRatio_fx[i] = (Word32) hSpatParamRendCom->surroundingCoherence_fx[md_idx][i]; + move32(); + } + } + ELSE + { + set_zero_fx( surCohRatio_fx, hSpatParamRendCom->num_freq_bands ); + } + surCohRatio_q_fx = Q15; + move16(); + } + + IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && EQ_16( st_ivas->hCombinedOrientationData->shd_rot_max_order, 1 ) ) + { + ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom, + hDirACRend, + st_ivas->hVBAPdata, + st_ivas->hMasa == NULL ? NULL : st_ivas->hMasa->data.band_mapping, + st_ivas->hMasaIsmData, + azimuth, + elevation, + md_idx, + surCohRatio_fx, + surCohRatio_q_fx, + st_ivas->hCombinedOrientationData->shd_rot_max_order, + p_Rmat_fx, + hodirac_flag ); + } + ELSE + { + ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom, + hDirACRend, + st_ivas->hVBAPdata, + st_ivas->hMasa == NULL ? NULL : st_ivas->hMasa->data.band_mapping, + st_ivas->hMasaIsmData, + azimuth, + elevation, + md_idx, + surCohRatio_fx, + surCohRatio_q_fx, + 0, + NULL, + hodirac_flag ); + } + } + + IF( L_and( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ), EQ_16( nchan_transport, 2 ) ) ) + { + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + index_slot = add( slot_idx_start, slot_idx ); + Word32 offset = i_mult( hSpatParamRendCom->num_freq_bands, index_slot ); + /* CLDFB Analysis*/ + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + Q_cldfb_scale = Q11; + move16(); + cldfbAnalysis_ts_fx_fixed_q( &st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][offset], + Cldfb_RealBuffer_Temp_fx[ch][slot_idx], + Cldfb_ImagBuffer_Temp_fx[ch][slot_idx], + hSpatParamRendCom->num_freq_bands, + st_ivas->cldfbAnaDec[ch], &Q_cldfb_scale ); + } + } + + IF( L_and( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ), NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) + { + ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( st_ivas, Cldfb_RealBuffer_Temp_fx, Cldfb_ImagBuffer_Temp_fx, &cldfb_buf_q, hSpatParamRendCom->num_freq_bands, subframe_idx ); + } + } + + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + index_slot = add( slot_idx_start, slot_idx ); + IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) ) + { + md_idx = hSpatParamRendCom->render_to_md_map[index_slot]; + move16(); + } + ELSE + { + md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; + move16(); + } + IF( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) + { + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + Copy32( pppQMfFrame_ts_re_fx[ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands ); + Copy32( pppQMfFrame_ts_im_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands ); + } + } + ELSE IF( L_and( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ), EQ_16( nchan_transport, 2 ) ) ) + { + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + Copy32( Cldfb_RealBuffer_Temp_fx[ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands ); + Copy32( Cldfb_ImagBuffer_Temp_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands ); + } + } + ELSE + { + /* CLDFB Analysis*/ + Word32 offset = i_mult( hSpatParamRendCom->num_freq_bands, index_slot ); + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + Q_cldfb_scale = Q11; + move16(); + cldfbAnalysis_ts_fx_fixed_q( &st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][offset], + Cldfb_RealBuffer_fx[ch][0], + Cldfb_ImagBuffer_fx[ch][0], + hSpatParamRendCom->num_freq_bands, + st_ivas->cldfbAnaDec[ch], &Q_cldfb_scale ); + } + } + + /* CNG in DirAC, extra CLDFB ana for CNA*/ + IF( EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && !( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) ) + { + Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; + Q_cldfb_scale = Q11; + move16(); + Word16 Q_input = Q11; + move16(); + generate_masking_noise_dirac_fx( st->hFdCngDec->hFdCngCom, + st_ivas->cldfbAnaDec[1], + st_ivas->hTcBuffer->tc_fx[1], + Cldfb_RealBuffer_fx[1][0], + Cldfb_ImagBuffer_fx[1][0], + index_slot, + st->cna_dirac_flag && st->flag_cna, + ( L_or( EQ_32( st->core_brate, FRAME_NO_DATA ), EQ_32( st->core_brate, SID_2k40 ) ) ) && EQ_16( st->cng_type, FD_CNG ) && st->cng_sba_flag, Q_input, &Q_cldfb_scale ); + Scale_sig32( Cldfb_RealBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_cldfb_scale ) ); + Scale_sig32( Cldfb_ImagBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_cldfb_scale ) ); + } + + /* LFE synthesis */ + IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled && !( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && EQ_16( hDirACRend->hOutSetup.num_lfe, 0 ) ) ) + { + Word16 cldfb_q = Q6; + move16(); + ivas_lfe_synth_with_cldfb_fx( st_ivas->hMasa->hMasaLfeSynth, + Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, + Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS - 1], Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS - 1], + slot_idx, + md_idx, + nchan_transport, cldfb_q ); + } + + + /////////////////////////////////////////////////////// to be removed ///////////////////////////////////////////////////////////////////////// + IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) && EQ_16( slot_idx, 0 ) ) + { + IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor, diffuse_power_factor_q, hSpatParamRendCom->num_freq_bands ); + fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hDirACRend->h_output_synthesis_psd_state.direct_power_factor, direct_power_factor_q, hSpatParamRendCom->num_freq_bands ); + } + ELSE + { + me2f_buf( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, 31 - diffuse_power_factor_q, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor, hSpatParamRendCom->num_freq_bands ); + me2f_buf( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, 31 - direct_power_factor_q, hDirACRend->h_output_synthesis_psd_state.direct_power_factor, hSpatParamRendCom->num_freq_bands ); + } + } + + IF( st_ivas->hMasa == NULL && EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + { + fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + + IF( hodirac_flag ) + { + fixedToFloat_arrL32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], &hDirACRend->h_output_synthesis_psd_state.direct_responses[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + } + } + ELSE + { + fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_square, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + } + } + + IF( !( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) ) + { + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + fixedToFloat_arrL32( st_ivas->cldfbAnaDec[ch]->cldfb_state_fx, st_ivas->cldfbAnaDec[ch]->cldfb_state, Q11, ( st_ivas->cldfbAnaDec[ch]->p_filter_length - st_ivas->cldfbAnaDec[ch]->no_channels ) ); + } + } + + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + fixedToFloat_arrL32( Cldfb_RealBuffer_fx[ch][0], Cldfb_RealBuffer[ch][0], Q6, hSpatParamRendCom->num_freq_bands ); + fixedToFloat_arrL32( Cldfb_ImagBuffer_fx[ch][0], Cldfb_ImagBuffer[ch][0], Q6, hSpatParamRendCom->num_freq_bands ); + } + + IF( EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && !( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) ) + { + fixedToFloat_arrL32( st_ivas->cldfbAnaDec[1]->cldfb_state_fx, st_ivas->cldfbAnaDec[1]->cldfb_state, Q11, ( st_ivas->cldfbAnaDec[1]->p_filter_length - st_ivas->cldfbAnaDec[1]->no_channels ) ); + fixedToFloat_arrL32( Cldfb_RealBuffer_fx[1][0], Cldfb_RealBuffer[1][0], Q6, CLDFB_NO_CHANNELS_MAX ); + fixedToFloat_arrL32( Cldfb_ImagBuffer_fx[1][0], Cldfb_ImagBuffer[1][0], Q6, CLDFB_NO_CHANNELS_MAX ); + } + + IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled && !( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && EQ_16( hDirACRend->hOutSetup.num_lfe, 0 ) ) ) + { + FOR( i = 0; i < nchan_transport; i++ ) + { + Cldfb_RealBuffer[i][0][0] = fixedToFloat_32( Cldfb_RealBuffer_fx[i][0][0], Q6 ); + Cldfb_ImagBuffer[i][0][0] = fixedToFloat_32( Cldfb_ImagBuffer_fx[i][0][0], Q6 ); + } + fixedToFloat_arrL32( Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS - 1][slot_idx], Cldfb_RealBuffer[MAX_OUTPUT_CHANNELS - 1][slot_idx], Q6, CLDFB_NO_CHANNELS_MAX ); + fixedToFloat_arrL32( Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS - 1][slot_idx], Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS - 1][slot_idx], Q6, CLDFB_NO_CHANNELS_MAX ); + st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth = fixedToFloat_32( st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth_fx, st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth_q ); + st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth = fixedToFloat_32( st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth_fx, st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth_q ); + st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth = fixedToFloat_32( st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_fx, st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_q ); + st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth = fixedToFloat_32( st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth_fx, st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth_q ); + } + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + + /*-----------------------------------------------------------------* + * protoype signal computation + *-----------------------------------------------------------------*/ + q_cldfb = Q6; + move16(); + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + { + IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && EQ_16( st_ivas->hCombinedOrientationData->shd_rot_max_order, 0 ) ) + { + protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, + proto_direct_buffer_f_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, + proto_diffuse_buffer_f_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, + reference_power_fix, &DirAC_mem.reference_power_q, + slot_idx, nchan_transport, + hDirACRend->num_outputs_diff, + hSpatParamRendCom->num_freq_bands, + p_Rmat_fx, q_cldfb ); + } + ELSE + { + protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, + proto_direct_buffer_f_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, + proto_diffuse_buffer_f_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, + reference_power_fix, &DirAC_mem.reference_power_q, + slot_idx, nchan_transport, + hDirACRend->num_outputs_diff, + hSpatParamRendCom->num_freq_bands, + 0, q_cldfb ); + } + /////////////////////////////////////////// to be removed /////////////////////////////////////////////// + fixedToFloat_arrL32( &proto_direct_buffer_f_fx[i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, nchan_transport ) )], hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f + i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, nchan_transport ) ), hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, 2 * nchan_transport * hSpatParamRendCom->num_freq_bands ); + fixedToFloat_arrL32( &proto_diffuse_buffer_f_fx[i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) )], hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f + i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ), hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, 2 * s_min( nchan_transport, hDirACRend->num_outputs_diff ) * hSpatParamRendCom->num_freq_bands ); + IF( nchan_transport >= 4 ) + { + fixedToFloat_arrL32( reference_power_fix, reference_power, DirAC_mem.reference_power_q, 5 * hSpatParamRendCom->num_freq_bands ); + } + ///////////////////////////////////////////////////////////////////////////////////////////////////////// + } + else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) + { + protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer, hDirACRend->proto_frame_f, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + reference_power, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, + 0, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect ); + } + else + { + switch ( nchan_transport ) + { + case 11: + case 8: + case 6: + case 4: + ///////////////////////////////////////// to be removed ///////////////////////////////////////// + floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff ); + /////////////////////////////////////////////////////////////////////////////////////////////// + protoSignalComputation4_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, + proto_frame_f_fx, + &hDirACRend->proto_frame_f_q, + proto_direct_buffer_f_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, + reference_power_fix, + &DirAC_mem.reference_power_q, + proto_power_smooth_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, + slot_idx, hDirACRend->num_outputs_diff, + hSpatParamRendCom->num_freq_bands, + hDirACRend->hoa_decoder, + nchan_transport, + hDirACRend->sba_map_tc, q_cldfb ); + //////////////////////////////////////////////// to be removed ///////////////////////////////////////////////////////// + Word16 offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ); + fixedToFloat_arrL32( proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ); + fixedToFloat_arrL32( &proto_direct_buffer_f_fx[offset], &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f[offset], hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ) ); + fixedToFloat_arrL32( proto_frame_f_fx, hDirACRend->proto_frame_f, hDirACRend->proto_frame_f_q, i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ) ); + fixedToFloat_arrL32( reference_power_fix, reference_power, DirAC_mem.reference_power_q, hSpatParamRendCom->num_freq_bands ); + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + break; + case 2: + protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer, + hDirACRend->proto_frame_f, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + reference_power, + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, + hDirACRend->hOutSetup.is_loudspeaker_setup, + slot_idx, + hSpatParamRendCom->num_freq_bands, + hDirACRend->masa_stereo_type_detect ); + break; + case 1: + ////////////////////////////////// to be removed ///////////////////////////////////////////////////////// + floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hSpatParamRendCom->num_freq_bands ); + ///////////////////////////////////////////////////////////////////////////////////////////////////////// + protoSignalComputation1_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, + proto_frame_f_fx, + &hDirACRend->proto_frame_f_q, + proto_direct_buffer_f_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, + reference_power_fix, + &DirAC_mem.reference_power_q, + proto_power_smooth_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, + slot_idx, + hDirACRend->num_protos_diff, + hSpatParamRendCom->num_freq_bands, q_cldfb ); + ////////////////////////////// to be removed /////////////////////////////////////////////////////////////////////////////////////// + fixedToFloat_arrL32( proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hSpatParamRendCom->num_freq_bands ); + fixedToFloat_arrL32( &proto_direct_buffer_f_fx[i_mult( slot_idx, i_mult( 2, hSpatParamRendCom->num_freq_bands ) )], hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f + i_mult( slot_idx, i_mult( 2, hSpatParamRendCom->num_freq_bands ) ), hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, i_mult( 2, hSpatParamRendCom->num_freq_bands ) ); + fixedToFloat_arrL32( proto_frame_f_fx, hDirACRend->proto_frame_f, hDirACRend->proto_frame_f_q, i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_diff ) ) ); + fixedToFloat_arrL32( reference_power_fix, reference_power, DirAC_mem.reference_power_q, hSpatParamRendCom->num_freq_bands ); + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + break; + default: + return; + } + } +#else + float dirEne; + float surCohEner; + float surCohRatio[CLDFB_NO_CHANNELS_MAX]; + float Cldfb_RealBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; +#ifdef IVAS_FLOAT_FIXED + set_zero( surCohRatio, CLDFB_NO_CHANNELS_MAX ); +#endif hodirac_flag = ivas_get_hodirac_flag( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); if ( st_ivas->hQMetaData != NULL && st_ivas->ivas_format != SBA_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT ) { @@ -3572,14 +4258,14 @@ void ivas_dirac_dec_render_sf( mvs2s( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands ); mvr2r( hSpatParamRendCom->diffuseness_vector[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector, hSpatParamRendCom->num_freq_bands ); #ifdef IVAS_FLOAT_FIXED - Copy32(hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands); + Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands ); #endif } else { set_zero( diffuseness_vector, hSpatParamRendCom->num_freq_bands ); #ifdef IVAS_FLOAT_FIXED - set32_fx(diffuseness_vector_fx, 0, hSpatParamRendCom->num_freq_bands); + set32_fx( diffuseness_vector_fx, 0, hSpatParamRendCom->num_freq_bands ); #endif } @@ -4022,7 +4708,7 @@ void ivas_dirac_dec_render_sf( return; } } - +#endif /*-----------------------------------------------------------------* * Compute DirAC parameters at decoder side @@ -4089,6 +4775,11 @@ void ivas_dirac_dec_render_sf( v_multc( onset_filter, 0.25f, onset_filter, hSpatParamRendCom->num_freq_bands ); v_add( onset_filter, onset_filter_subframe, onset_filter_subframe, hSpatParamRendCom->num_freq_bands ); p_onset_filter = onset_filter_subframe; +#ifdef IVAS_FLOAT_FIXED + floatToFixed_arrL( onset_filter, onset_filter_fx, Q30, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL( onset_filter_subframe, onset_filter_subframe_fx, Q30, hSpatParamRendCom->num_freq_bands ); + p_onset_filter_fx = onset_filter_subframe_fx; +#endif } else { @@ -4107,6 +4798,10 @@ void ivas_dirac_dec_render_sf( hDirACRend->proto_frame_dec_f = DirAC_mem.frame_dec_f; p_onset_filter = onset_filter; +#ifdef IVAS_FLOAT_FIXED + floatToFixed_arrL( onset_filter, onset_filter_fx, Q30, hSpatParamRendCom->num_freq_bands ); + p_onset_filter_fx = onset_filter_fx; +#endif } } else @@ -4115,12 +4810,19 @@ void ivas_dirac_dec_render_sf( { set_f( onset_filter_subframe, 1.f, hSpatParamRendCom->num_freq_bands ); p_onset_filter = onset_filter_subframe; +#ifdef IVAS_FLOAT_FIXED + set_l( onset_filter_subframe_fx, ONE_IN_Q30, hSpatParamRendCom->num_freq_bands ); + p_onset_filter_fx = onset_filter_subframe_fx; +#endif } else { /* no frequency domain decorrelation: use prototype frame */ hDirACRend->proto_frame_dec_f = hDirACRend->proto_frame_f; p_onset_filter = NULL; +#ifdef IVAS_FLOAT_FIXED + p_onset_filter_fx = NULL; +#endif } } @@ -4194,6 +4896,107 @@ void ivas_dirac_dec_render_sf( if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { +#ifdef IVAS_FLOAT_FIXED + Word16 size, size_ho; + size = hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands; + size_ho = ( hodirac_flag ) ? size * DIRAC_HO_NUMSECTORS : size; + + IF( hDirACRend->hOutSetup.is_loudspeaker_setup && hDirACRend->hoa_decoder != NULL ) + { + FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ ) + { + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + floatToFixed_arrL( Cldfb_RealBuffer[ch][slot_idx], Cldfb_RealBuffer_fx[ch][slot_idx], + Q6, + hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL( Cldfb_ImagBuffer[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][slot_idx], + Q6, + hSpatParamRendCom->num_freq_bands ); + } + } + } + ELSE + { + FOR( ch = 0; ch < hDirACRend->num_outputs_dir; ch++ ) + { + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + floatToFixed_arrL( Cldfb_RealBuffer[ch][slot_idx], Cldfb_RealBuffer_fx[ch][slot_idx], + Q6, + hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL( Cldfb_ImagBuffer[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][slot_idx], + Q6, + hSpatParamRendCom->num_freq_bands ); + } + } + } + + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = Q26; + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, size_ho ); + + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26; + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, size_ho ); + + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q31; + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.direct_power_factor, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, ( hodirac_flag ) ? hSpatParamRendCom->num_freq_bands * DIRAC_HO_NUMSECTORS : hSpatParamRendCom->num_freq_bands ); + + hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q31; + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, size_ho ); + + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q31; + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ); + + hDirACRend->diffuse_response_function_q = Q15; + floatToFixed_arr( hDirACRend->diffuse_response_function, hDirACRend->diffuse_response_function_fx, hDirACRend->diffuse_response_function_q, hDirACRend->num_outputs_dir ); + + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = Q26; + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr ); + + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = Q26; + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr ); + + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + floatToFixed_arrL( &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f[i_mult( i_mult( slot_idx, 2 ), + i_mult( hSpatParamRendCom->num_freq_bands, nchan_transport ) )], + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + + i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, nchan_transport ) ), + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, + 2 * nchan_transport * hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL( &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f[i_mult( i_mult( slot_idx, 2 ), + i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) )], + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + + i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ), + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, + 2 * s_min( nchan_transport, hDirACRend->num_outputs_diff ) * hSpatParamRendCom->num_freq_bands ); + } + + floatToFixed_arrL( p_onset_filter, p_onset_filter_fx, Q30, hSpatParamRendCom->num_freq_bands ); // Q30 + floatToFixed_arrL( diffuseness_vector, diffuseness_vector_fx, Q30, hSpatParamRendCom->num_freq_bands ); // Q30 + hDirACRend->h_output_synthesis_psd_params.diffuse_compensation_factor_fx = floatToFixed( hDirACRend->h_output_synthesis_psd_params.diffuse_compensation_factor, Q27 ); // Q27 + + hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26; + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, size ); + + hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26; + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr ); +#endif + +#ifdef IVAS_FLOAT_FIXED + ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( Cldfb_RealBuffer_fx, + Cldfb_ImagBuffer_fx, + hSpatParamRendCom, + hDirACRend, + nchan_transport, + hSpatParamRendCom->subframe_nbslots[subframe_idx], + p_onset_filter_fx, + diffuseness_vector_fx, + hodirac_flag, + hDirAC->hConfig->dec_param_estim, + &hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, + &hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ); +#else ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( Cldfb_RealBuffer, Cldfb_ImagBuffer, hSpatParamRendCom, @@ -4204,6 +5007,50 @@ void ivas_dirac_dec_render_sf( diffuseness_vector, hodirac_flag, hDirAC->hConfig->dec_param_estim ); +#endif + +#ifdef IVAS_FLOAT_FIXED + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, size_ho ); + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr ); + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, size_ho ); + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr ); + + hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev; + hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev; + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, size ); + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr ); + + IF( hDirACRend->hOutSetup.is_loudspeaker_setup && hDirACRend->hoa_decoder != NULL ) + { + FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ ) + { + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + fixedToFloat_arrL( Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_RealBuffer[ch][slot_idx], + add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ), + hSpatParamRendCom->num_freq_bands ); + fixedToFloat_arrL( Cldfb_ImagBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer[ch][slot_idx], + add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ), + hSpatParamRendCom->num_freq_bands ); + } + } + } + ELSE + { + FOR( ch = 0; ch < hDirACRend->num_outputs_dir; ch++ ) + { + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + fixedToFloat_arrL( Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_RealBuffer[ch][slot_idx], + add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ), + hSpatParamRendCom->num_freq_bands ); + fixedToFloat_arrL( Cldfb_ImagBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer[ch][slot_idx], + add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ), + hSpatParamRendCom->num_freq_bands ); + } + } + } +#endif } else { @@ -4269,7 +5116,13 @@ void ivas_dirac_dec_render_sf( rotateAziEle( st_ivas->hIsmMetaData[i]->azimuth, st_ivas->hIsmMetaData[i]->elevation, &az1, &el1, st_ivas->hCombinedOrientationData->Rmat[0], st_ivas->hIntSetup.is_planar_setup ); if ( st_ivas->hEFAPdata != NULL ) { +#ifdef IVAS_FLOAT_FIXED + float gains[MAX_OUTPUT_CHANNELS]; + fixedToFloat_arrL(st_ivas->hIsmRendererData->gains_fx[i], gains, Q30, MAX_OUTPUT_CHANNELS); + efap_determine_gains( st_ivas->hEFAPdata, gains, az1, el1, EFAP_MODE_EFAP ); +#else efap_determine_gains( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains[i], az1, el1, EFAP_MODE_EFAP ); +#endif } } @@ -4281,14 +5134,24 @@ void ivas_dirac_dec_render_sf( ( lfe_index < ( st_ivas->hIntSetup.num_lfe - 1 ) ) ? ( lfe_index++, j2++ ) : j2++; } +#ifdef IVAS_FLOAT_FIXED + gain = fix_to_float( st_ivas->hIsmRendererData->gains_fx[i][j], Q30 ); + prev_gain = fix_to_float( st_ivas->hIsmRendererData->prev_gains_fx[i][j], Q30 ); +#else gain = st_ivas->hIsmRendererData->gains[i][j]; prev_gain = st_ivas->hIsmRendererData->prev_gains[i][j]; +#endif if ( fabsf( gain ) > 0.0f || fabsf( prev_gain ) > 0.0f ) { float *tc_re, *tc_im; float *w1, w2; +#ifdef IVAS_FLOAT_FIXED + Word16 *w1_fx; + w1_fx = &st_ivas->hIsmRendererData->interpolator_fx[interp_offset]; +#else w1 = &st_ivas->hIsmRendererData->interpolator[interp_offset]; +#endif tc_re = pppQMfFrame_ts_re[nchan_transport + i][0]; tc_im = pppQMfFrame_ts_im[nchan_transport + i][0]; @@ -4296,22 +5159,35 @@ void ivas_dirac_dec_render_sf( { float g; +#ifdef IVAS_FLOAT_FIXED + w2 = 1.0f - fix16_to_float(*w1_fx, Q15); + g = ( fix16_to_float(*w1_fx, Q15) * gain + w2 * prev_gain ); +#else w2 = 1.0f - *w1; - g = ( *w1 * gain + w2 * prev_gain ); + g = (*w1 * gain + w2 * prev_gain); +#endif for ( l = 0; l < hSpatParamRendCom->num_freq_bands; l++ ) { Cldfb_RealBuffer[j2][0][k * hSpatParamRendCom->num_freq_bands + l] += g * *( tc_re++ ); Cldfb_ImagBuffer[j2][0][k * hSpatParamRendCom->num_freq_bands + l] += g * *( tc_im++ ); } +#ifdef IVAS_FLOAT_FIXED + w1_fx += hSpatParamRendCom->num_freq_bands; +#else w1 += hSpatParamRendCom->num_freq_bands; +#endif } } /* update here only in case of head rotation */ if ( st_ivas->hCombinedOrientationData != NULL && st_ivas->hCombinedOrientationData->enableCombinedOrientation[0] == 1 ) { +#ifdef IVAS_FLOAT_FIXED + st_ivas->hIsmRendererData->prev_gains_fx[i][j] = float_to_fix(gain, Q30); +#else st_ivas->hIsmRendererData->prev_gains[i][j] = gain; +#endif } } } diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov.c index 7d7b5baa5255876133a8349c3c55a8a1c2cbd512..d86071d93ee3d48e19d802b3d795de319e9ee795 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov.c @@ -30,6 +30,7 @@ *******************************************************************************************************/ +#include #include #include #include @@ -60,6 +61,184 @@ * Sets up the state and parameters for the Covariance Synthesis *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( + DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ + DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: hanlde for the covariance synthesis state */ + const Word16 max_band_decorr, /* i : uppermost frequency band where decorrelation is applied */ + const Word16 interp_length, /* i : length for interpolating the mixing matrices in time slots */ + const Word16 num_param_bands, /* i : number of parameter bands */ + const Word16 num_param_bands_residual, /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ + const Word16 nchan_in, /* i : number of input (transport) channels */ + const Word16 nchan_out, /* i : number of output channels */ + const Word32 *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) */ +) +{ + Word16 idx; + + h_dirac_output_synthesis_params->max_band_decorr = max_band_decorr; + move16(); + + /*-----------------------------------------------------------------* + * memory allocation + *-----------------------------------------------------------------*/ + + /* buffer length and interpolator */ + h_dirac_output_synthesis_params->alpha_synthesis_fx = NULL; + if ( ( h_dirac_output_synthesis_params->proto_matrix_fx = (Word32 *) malloc( nchan_out * nchan_in * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } + + /* cov buffers */ + for ( idx = 0; idx < num_param_bands; idx++ ) + { + + if ( ( h_dirac_output_synthesis_state->cx_old_fx[idx] = (Word32 *) malloc( nchan_in * nchan_in * sizeof(Word32) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } + if ( ( h_dirac_output_synthesis_state->cy_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof(Word32) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } + if ( ( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_in * sizeof(Word32) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } + set_zero_fx( h_dirac_output_synthesis_state->cx_old_fx[idx], nchan_in * nchan_in ); + set_zero_fx( h_dirac_output_synthesis_state->cy_old_fx[idx], nchan_out * nchan_out ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx], nchan_out * nchan_in ); + + if ( ( h_dirac_output_synthesis_state->mixing_matrix_fx[idx] = (Word32 *) malloc( nchan_out * nchan_in * sizeof(Word32) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); + } + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_fx[idx], nchan_out * nchan_in ); + } + for ( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) + { + h_dirac_output_synthesis_state->cx_old_fx[idx] = NULL; + h_dirac_output_synthesis_state->cy_old_fx[idx] = NULL; + h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx] = NULL; + h_dirac_output_synthesis_state->mixing_matrix_fx[idx] = NULL; + } + + for ( idx = 0; idx < num_param_bands_residual; idx++ ) + { + if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof(Word32) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx],nchan_out * nchan_out ); + + if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof(Word32) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); + } + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx],nchan_out * nchan_out ); + } + for ( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) + { + h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx] = NULL; + h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] = NULL; + } + + /*-----------------------------------------------------------------* + * prepare processing parameters + *-----------------------------------------------------------------*/ + + /* compute interpolator */ + IF( ( h_dirac_output_synthesis_params->interpolator_fx = (Word16 *) malloc( interp_length * sizeof( Word16 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } + for ( idx = 1; idx <= interp_length; ++idx ) + { + h_dirac_output_synthesis_params->interpolator_fx[idx - 1] = div_s( idx, interp_length ); + } + Copy32( proto_matrix, h_dirac_output_synthesis_params->proto_matrix_fx, nchan_in * nchan_out ); + +#if 1 /*TODO: To be removed later***************************************************************************************/ + h_dirac_output_synthesis_params->alpha_synthesis = NULL; + if ( ( h_dirac_output_synthesis_params->proto_matrix = (float *) malloc( nchan_out * nchan_in * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } + + /* cov buffers */ + for ( idx = 0; idx < num_param_bands; idx++ ) + { + + if ( ( h_dirac_output_synthesis_state->cx_old[idx] = (float *) malloc( nchan_in * nchan_in * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } + if ( ( h_dirac_output_synthesis_state->cy_old[idx] = (float *) malloc( nchan_out * nchan_out * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } + if ( ( h_dirac_output_synthesis_state->mixing_matrix_old[idx] = (float *) malloc( nchan_out * nchan_in * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } + set_zero( h_dirac_output_synthesis_state->cx_old[idx], nchan_in * nchan_in ); + set_zero( h_dirac_output_synthesis_state->cy_old[idx], nchan_out * nchan_out ); + set_zero( h_dirac_output_synthesis_state->mixing_matrix_old[idx], nchan_out * nchan_in ); + + if ( ( h_dirac_output_synthesis_state->mixing_matrix[idx] = (float *) malloc( nchan_out * nchan_in * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); + } + set_zero( h_dirac_output_synthesis_state->mixing_matrix[idx], nchan_out * nchan_in ); + } + for ( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) + { + h_dirac_output_synthesis_state->cx_old[idx] = NULL; + h_dirac_output_synthesis_state->cy_old[idx] = NULL; + h_dirac_output_synthesis_state->mixing_matrix_old[idx] = NULL; + h_dirac_output_synthesis_state->mixing_matrix[idx] = NULL; + } + + for ( idx = 0; idx < num_param_bands_residual; idx++ ) + { + if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_old[idx] = (float *) malloc( nchan_out * nchan_out * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } + set_zero( h_dirac_output_synthesis_state->mixing_matrix_res_old[idx], nchan_out * nchan_out ); + + if ( ( h_dirac_output_synthesis_state->mixing_matrix_res[idx] = (float *) malloc( nchan_out * nchan_out * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); + } + set_zero( h_dirac_output_synthesis_state->mixing_matrix_res[idx], nchan_out * nchan_out ); + } + for ( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) + { + h_dirac_output_synthesis_state->mixing_matrix_res_old[idx] = NULL; + h_dirac_output_synthesis_state->mixing_matrix_res[idx] = NULL; + } + + /*-----------------------------------------------------------------* + * prepare processing parameters + *-----------------------------------------------------------------*/ + + /* compute interpolator */ + if ( ( h_dirac_output_synthesis_params->interpolator = (float *) malloc( interp_length * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } + + for ( idx = 1; idx <= interp_length; ++idx ) + { + h_dirac_output_synthesis_params->interpolator[idx - 1] = (float) idx / (float) interp_length; + } + +#endif + return IVAS_ERR_OK; +} +#endif ivas_error ivas_dirac_dec_output_synthesis_cov_open( DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: hanlde for the covariance synthesis state */ @@ -81,6 +260,9 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open( *-----------------------------------------------------------------*/ /* buffer length and interpolator */ +#ifdef IVAS_FLOAT_FIXED + h_dirac_output_synthesis_params->alpha_synthesis_fx = NULL; +#endif // IVAS_FLOAT_FIXED h_dirac_output_synthesis_params->alpha_synthesis = NULL; if ( ( h_dirac_output_synthesis_params->proto_matrix = (float *) malloc( nchan_out * nchan_in * sizeof( float ) ) ) == NULL ) { @@ -146,6 +328,16 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open( *-----------------------------------------------------------------*/ /* compute interpolator */ +#ifdef IVAS_FLOAT_FIXED + IF ( ( h_dirac_output_synthesis_params->interpolator_fx = (Word16 *) malloc( interp_length * sizeof(Word16) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } + for ( idx = 1; idx <= interp_length; ++idx ) + { + h_dirac_output_synthesis_params->interpolator_fx[idx - 1] = div_s(idx,interp_length); + } +#endif if ( ( h_dirac_output_synthesis_params->interpolator = (float *) malloc( interp_length * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); @@ -161,7 +353,6 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open( return IVAS_ERR_OK; } - #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * ivas_dirac_dec_output_synthesis_get_interpolator_fx() @@ -217,6 +408,52 @@ void ivas_dirac_dec_output_synthesis_get_interpolator( * * initialize the states for the covariance synthesis *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_dec_output_synthesis_cov_init_fx( + DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: pointer to the state of the covariance synthesis */ + const Word16 nchan_in, /* i : number of input (tranport) channels */ + const Word16 nchan_out, /* i : number of output channels */ + const Word16 n_param_bands, /* i : number of total parameter bands */ + const Word16 n_param_bands_res /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ +) +{ + + Word16 idx; + + /* initialize buffers */ + FOR( idx = 0; idx < n_param_bands; idx++ ) + { + set_zero_fx( h_dirac_output_synthesis_state->cx_old_fx[idx], nchan_in * nchan_in ); + set_zero_fx( h_dirac_output_synthesis_state->cy_old_fx[idx], nchan_out * nchan_out ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx], nchan_out * nchan_in ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_fx[idx], nchan_out * nchan_in ); + } + + FOR( idx = 0; idx < n_param_bands_res; idx++ ) + { + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx], nchan_out * nchan_out ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx], nchan_out * nchan_out ); + } + +#if 1/*TODO: To be removed :Floating point initializations*/ + FOR ( idx = 0; idx < n_param_bands; idx++ ) + { + set_zero( h_dirac_output_synthesis_state->cx_old[idx], nchan_in * nchan_in ); + set_zero( h_dirac_output_synthesis_state->cy_old[idx], nchan_out * nchan_out ); + set_zero( h_dirac_output_synthesis_state->mixing_matrix_old[idx], nchan_out * nchan_in ); + set_zero( h_dirac_output_synthesis_state->mixing_matrix[idx], nchan_out * nchan_in ); + } + + FOR ( idx = 0; idx < n_param_bands_res; idx++ ) + { + set_zero( h_dirac_output_synthesis_state->mixing_matrix_res_old[idx], nchan_out * nchan_out ); + set_zero( h_dirac_output_synthesis_state->mixing_matrix_res[idx], nchan_out * nchan_out ); + } +#endif + + return; +} +#endif // IVAS_FLOAT_FIXED void ivas_dirac_dec_output_synthesis_cov_init( DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: pointer to the state of the covariance synthesis */ @@ -254,6 +491,143 @@ void ivas_dirac_dec_output_synthesis_cov_init( * deallocate dynamic memory in the covariance synthesis state *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_dec_output_synthesis_cov_close( + DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i : handle for the covariance synthesis parameters */ + DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state /* i/o: handle for the covariance synthesis state */ +) +{ + Word16 idx; + + /*-----------------------------------------------------------------* + * memory deallocation + *-----------------------------------------------------------------*/ + + /* free interpolator */ + IF( h_dirac_output_synthesis_params->interpolator_fx != NULL ) + { + free( h_dirac_output_synthesis_params->interpolator_fx ); + h_dirac_output_synthesis_params->interpolator_fx = NULL; + } + + /* free alpha */ + IF ( h_dirac_output_synthesis_params->alpha_synthesis_fx != NULL ) + { + free( h_dirac_output_synthesis_params->alpha_synthesis_fx ); + h_dirac_output_synthesis_params->alpha_synthesis_fx = NULL; + } + + /* free proto_matrix */ + IF ( h_dirac_output_synthesis_params->proto_matrix_fx != NULL ) + { + free( h_dirac_output_synthesis_params->proto_matrix_fx ); + h_dirac_output_synthesis_params->proto_matrix_fx = NULL; + } + + /* free cov buffers */ + FOR ( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) + { + IF ( h_dirac_output_synthesis_state->cx_old_fx[idx] != NULL ) + { + free( h_dirac_output_synthesis_state->cx_old_fx[idx] ); + h_dirac_output_synthesis_state->cx_old_fx[idx] = NULL; + } + + IF ( h_dirac_output_synthesis_state->cy_old_fx[idx] != NULL ) + { + free( h_dirac_output_synthesis_state->cy_old_fx[idx] ); + h_dirac_output_synthesis_state->cy_old_fx[idx] = NULL; + } + + IF ( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx] != NULL ) + { + free( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx] ); + h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx] = NULL; + } + + IF ( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx] != NULL ) + { + free( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx] ); + h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx] = NULL; + } + + IF ( h_dirac_output_synthesis_state->mixing_matrix_fx[idx] != NULL ) + { + free( h_dirac_output_synthesis_state->mixing_matrix_fx[idx] ); + h_dirac_output_synthesis_state->mixing_matrix_fx[idx] = NULL; + } + + IF ( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] != NULL ) + { + free( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] ); + h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] = NULL; + } + } +#if 1/*TODO: To be removed later(floating point dealloc)*/ + /* free interpolator */ + IF ( h_dirac_output_synthesis_params->interpolator != NULL ) + { + free( h_dirac_output_synthesis_params->interpolator ); + h_dirac_output_synthesis_params->interpolator = NULL; + } + + /* free alpha */ + IF ( h_dirac_output_synthesis_params->alpha_synthesis != NULL ) + { + free( h_dirac_output_synthesis_params->alpha_synthesis ); + h_dirac_output_synthesis_params->alpha_synthesis = NULL; + } + + /* free proto_matrix */ + IF ( h_dirac_output_synthesis_params->proto_matrix != NULL ) + { + free( h_dirac_output_synthesis_params->proto_matrix ); + h_dirac_output_synthesis_params->proto_matrix = NULL; + } + + /* free cov buffers */ + FOR ( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) + { + IF ( h_dirac_output_synthesis_state->cx_old[idx] != NULL ) + { + free( h_dirac_output_synthesis_state->cx_old[idx] ); + h_dirac_output_synthesis_state->cx_old[idx] = NULL; + } + + IF ( h_dirac_output_synthesis_state->cy_old[idx] != NULL ) + { + free( h_dirac_output_synthesis_state->cy_old[idx] ); + h_dirac_output_synthesis_state->cy_old[idx] = NULL; + } + + IF ( h_dirac_output_synthesis_state->mixing_matrix_old[idx] != NULL ) + { + free( h_dirac_output_synthesis_state->mixing_matrix_old[idx] ); + h_dirac_output_synthesis_state->mixing_matrix_old[idx] = NULL; + } + + IF ( h_dirac_output_synthesis_state->mixing_matrix_res_old[idx] != NULL ) + { + free( h_dirac_output_synthesis_state->mixing_matrix_res_old[idx] ); + h_dirac_output_synthesis_state->mixing_matrix_res_old[idx] = NULL; + } + + IF ( h_dirac_output_synthesis_state->mixing_matrix[idx] != NULL ) + { + free( h_dirac_output_synthesis_state->mixing_matrix[idx] ); + h_dirac_output_synthesis_state->mixing_matrix[idx] = NULL; + } + + IF ( h_dirac_output_synthesis_state->mixing_matrix_res[idx] != NULL ) + { + free( h_dirac_output_synthesis_state->mixing_matrix_res[idx] ); + h_dirac_output_synthesis_state->mixing_matrix_res[idx] = NULL; + } + } +#endif + return; +} +#else void ivas_dirac_dec_output_synthesis_cov_close( DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i : handle for the covariance synthesis parameters */ DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state /* i/o: handle for the covariance synthesis state */ @@ -328,7 +702,7 @@ void ivas_dirac_dec_output_synthesis_cov_close( return; } - +#endif /*-------------------------------------------------------------------* * ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot() diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index f110710553942fda1e6313bfb37894b73f042fd8..3ec9035a7939e1f377186c0f336a1f97fd0a2eae 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -247,7 +247,7 @@ ivas_error ivas_dec_setup( IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { st_ivas->hBinRendererTd->Gain = 1.0f; /*1.0f Q15*/ - fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Pos_fx, st_ivas->hBinRendererTd->Listener_p->Pos, Q25, 3 ); + fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Pos_fx, st_ivas->hBinRendererTd->Listener_p->Pos, st_ivas->hBinRendererTd->Listener_p->Pos_q, 3 ); fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Vel_fx, st_ivas->hBinRendererTd->Listener_p->Vel, Q30, 3 ); fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Front_fx, st_ivas->hBinRendererTd->Listener_p->Front, Q30, 3 ); fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Up_fx, st_ivas->hBinRendererTd->Listener_p->Up, Q30, 3 ); @@ -388,7 +388,7 @@ ivas_error ivas_dec_setup( IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { st_ivas->hBinRendererTd->Gain = 1.0f; /*1.0f Q15*/ - fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Pos_fx, st_ivas->hBinRendererTd->Listener_p->Pos, Q25, 3 ); + fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Pos_fx, st_ivas->hBinRendererTd->Listener_p->Pos, st_ivas->hBinRendererTd->Listener_p->Pos_q, 3 ); fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Vel_fx, st_ivas->hBinRendererTd->Listener_p->Vel, Q30, 3 ); fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Front_fx, st_ivas->hBinRendererTd->Listener_p->Front, Q30, 3 ); fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Up_fx, st_ivas->hBinRendererTd->Listener_p->Up, Q30, 3 ); @@ -1993,7 +1993,7 @@ ivas_error ivas_init_decoder( } } - IF ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) { return error; } @@ -2152,19 +2152,6 @@ ivas_error ivas_init_decoder( { return error; } - FOR(Word16 ind = 0; ind < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind++) - { - st_ivas->hIsmRendererData->interpolator[ind] = (float)(st_ivas->hIsmRendererData->interpolator_fx[ind]) / (float)(1 << 15); - } - FOR(Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++) - { - FOR(Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++) - { - // q factors might be different. Here we are just initializing to zero - st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float)(st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2]) / (float)(1<<31); - st_ivas->hIsmRendererData->gains[ind1][ind2] = (float)(st_ivas->hIsmRendererData->gains_fx[ind1][ind2]) / (float)(1<<31); - } - } #else IF ( ( error = ivas_ism_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) { @@ -2370,7 +2357,11 @@ void destroy_core_dec( DEC_CORE_HANDLE hCoreCoder /* i/o: core decoder structure */ ) { - destroy_cldfb_decoder_flt( hCoreCoder ); +#ifdef IVAS_FLOAT_FIXED + destroy_cldfb_decoder_ivas_fx( hCoreCoder ); +#else + destroy_cldfb_decoder_flt( hCoreCoder ); +#endif // IVAS_FLOAT_FIXED IF ( hCoreCoder->hGSCDec != NULL ) { @@ -2661,16 +2652,6 @@ void ivas_destroy_dec( } /* HP20 filter handles */ - IF ( st_ivas->mem_hp20_out != NULL ) - { - FOR ( i = 0; i < getNumChanSynthesis( st_ivas ); i++ ) - { - free( st_ivas->mem_hp20_out[i] ); - st_ivas->mem_hp20_out[i] = NULL; - } - free( st_ivas->mem_hp20_out ); - st_ivas->mem_hp20_out = NULL; - } #ifdef IVAS_FLOAT_FIXED IF( st_ivas->mem_hp20_out_fx != NULL ) { @@ -2682,6 +2663,17 @@ void ivas_destroy_dec( free( st_ivas->mem_hp20_out_fx ); st_ivas->mem_hp20_out_fx = NULL; } +#else + IF(st_ivas->mem_hp20_out != NULL) + { + FOR(i = 0; i < getNumChanSynthesis(st_ivas); i++) + { + free(st_ivas->mem_hp20_out[i]); + st_ivas->mem_hp20_out[i] = NULL; + } + free(st_ivas->mem_hp20_out); + st_ivas->mem_hp20_out = NULL; + } #endif /* ISM metadata handles */ ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 433a971923d995d57850a8e61246081bf7be6858..b0fafc05de1edd0908aebbecbdd5ffacc176658f 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -48,6 +48,335 @@ * *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static ivas_error ivas_ism_bitrate_switching_dec_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nchan_transport_old, /* i : last number of transport channels */ + const ISM_MODE last_ism_mode, /* i : last ISM mode */ + UWord16 *nSamplesRendered, /* o : number of samples rendered */ + Word16 *data /* o : output synthesis signal */ +) +{ + ivas_error error; + Word32 element_brate_tmp[MAX_NUM_OBJECTS]; + Word16 nSCE_old, nCPE_old; + Word16 numCldfbAnalyses_old, numCldfbSyntheses_old, ism_mode; + TC_BUFFER_MODE tc_buffer_mode_new; + Word16 tc_nchan_tc_new; + Word16 tc_nchan_allocate_new; + Word16 tc_granularity_new; + Word16 nchan_out_buff, nchan_out_buff_old; + AUDIO_CONFIG intern_config_old; + IVAS_OUTPUT_SETUP hIntSetupOld; + RENDERER_TYPE renderer_type_old; + + error = IVAS_ERR_OK; + nCPE_old = st_ivas->nCPE; + nSCE_old = st_ivas->nSCE; + + /* temporarily set the ism mode back to the old one, otherwise this can give wrong results*/ + ism_mode = st_ivas->ism_mode; + move16(); + st_ivas->ism_mode = last_ism_mode; + move16(); + ivas_init_dec_get_num_cldfb_instances_ivas_fx( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); + st_ivas->ism_mode = ism_mode; + move16(); + nchan_out_buff_old = ivas_get_nchan_buffers_dec_ivas_fx( st_ivas, -1, -1 ); + + IF ( ( error = ivas_ism_config_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->nchan_ism, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + + st_ivas->nSCE = st_ivas->nchan_transport; + move16(); + + /*-----------------------------------------------------------------* + * Allocate, initialize, and configure SCE/CPE/MCT handles + *-----------------------------------------------------------------*/ + + IF ( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, 0, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + { + return error; + } + + /*-----------------------------------------------------------------* + * HP20 memories + *-----------------------------------------------------------------*/ + IF ( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_transport_old ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* save old IntSetup, might be needed for JBM flushing...*/ + intern_config_old = st_ivas->intern_config; + hIntSetupOld = st_ivas->hIntSetup; + tc_granularity_new = 1; + move16(); + renderer_type_old = st_ivas->renderer_type; + + /*-----------------------------------------------------------------* + * Initialize the needed renderer struct and destroy the unnecessary renderer struct + *-----------------------------------------------------------------*/ + + /* select the renderer */ + ivas_renderer_select( st_ivas ); + + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); + + IF ( ( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && ( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) ) ) + { + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->hDecoderConfig->output_config ); + } + + { + test(); test(); test(); + /* transfer subframe info from DirAC or ParamMC to central tc buffer */ + IF ( EQ_32( last_ism_mode, ISM_MODE_PARAM ) && st_ivas->hSpatParamRendCom != NULL && ( NE_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) ) ) + { + st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; + move16(); + st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; + move16(); + st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots; + move16(); + st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; + move16(); + Copy( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + } + + /* JBM: when granularity goes down (e.g. Discrete ISM with TD Obj Renderer -> ParamISM with binaural fastconv + render what still fits in the new granularity */ + tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); + + IF ( LT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) + { + IF ( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, MC_MODE_NONE, last_ism_mode, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + { + return error; + } + } + /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ + ELSE IF( GT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) + { + IF( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + IF( NE_16( st_ivas->ism_mode, last_ism_mode ) ) + { + /* EFAP handle */ + efap_free_data( &st_ivas->hEFAPdata ); + } + + /*-----------------------------------------------------------------* + * Switching between ParamISM and DiscISM + *-----------------------------------------------------------------*/ + + /* switching from ParamISM to DiscISM */ + IF ( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) && EQ_32( last_ism_mode, ISM_MODE_PARAM ) ) + { + /* Deallocate the ParamISM struct */ + ivas_param_ism_dec_close( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); + + IF ( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + { + /* close the parametric binaural renderer */ + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + /* Open the TD Binaural renderer */ + IF ( st_ivas->hHrtfTD == NULL || st_ivas->hBinRendererTd == NULL ) + { + Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; + Word16 num_src; + IF ( ( error = ivas_td_binaural_open_fx( st_ivas , SrcInd, &num_src ) ) != IVAS_ERR_OK ) + { + return error; + } + IF ( st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + { + IF ( ( error = ivas_reverb_open( &st_ivas->hReverb, st_ivas->hDecoderConfig->output_config, NULL, st_ivas->hBinRendererTd->HrFiltSet_p->lr_energy_and_iac, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + } + ELSE + { + /* close the ISM renderer and reinitialize */ + ivas_ism_renderer_close( &st_ivas->hIsmRendererData ); + IF ( ( error = ivas_ism_renderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + IF( EQ_16( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) + { + /* close the parametric binaural renderer */ + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + + /* Open Crend Binaural renderer */ + IF( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + + st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; + move32(); + } + } + + /* switching from Discrete ISM to ParamISM */ + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) && EQ_32( last_ism_mode, ISM_MODE_DISC ) ) + { + /* Allocate and initialize the ParamISM struct */ + IF( ( error = ivas_param_ism_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + { + /* open the parametric binaural renderer */ + IF ( ( error = ivas_dirac_dec_binaural_copy_hrtfs_fx( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + { + return error; + } + + IF ( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Close the TD Binaural renderer */ + IF ( st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) + { + ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); + st_ivas->hHrtfTD = NULL; + + IF( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + { + ivas_reverb_close( &st_ivas->hReverb ); + } + } + } + ELSE + { + /* Close the ISM renderer */ + ivas_ism_renderer_close( &st_ivas->hIsmRendererData ); + } + + IF ( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) + { + /* open the parametric binaural renderer */ + IF ( ( error = ivas_dirac_dec_binaural_copy_hrtfs_fx( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + { + return error; + } + + IF ( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* close the crend binaural renderer */ + ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); + } + } + + /*-----------------------------------------------------------------* + * CLDFB instances + *-----------------------------------------------------------------*/ + + Word16 Q_cldfbSynDec = Q21; + IF ( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ,Q_cldfbSynDec) ) != IVAS_ERR_OK ) + { + return error; + } + + /*-----------------------------------------------------------------* + * floating-point output audio buffers + *-----------------------------------------------------------------*/ + + { + nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); + + IF( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } +#if 1 /* TODO: remove float code */ + if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + } + + /*-----------------------------------------------------------------* + * JBM TC buffers + *-----------------------------------------------------------------*/ + { + Word16 tc_nchan_full_new; + DECODER_TC_BUFFER_HANDLE hTcBuffer; + + hTcBuffer = st_ivas->hTcBuffer; + tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); + tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels( st_ivas ); + tc_nchan_allocate_new = tc_nchan_tc_new; + move16(); + tc_nchan_full_new = tc_nchan_tc_new; + move16(); + + IF ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) + { + tc_nchan_allocate_new = 2 * BINAURAL_CHANNELS; + move16(); + tc_nchan_full_new = tc_nchan_allocate_new; + move16(); + } + + IF ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) && ( NE_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) && NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) + { + tc_nchan_full_new = 0; + move16(); + } + + /* reconfigure buffer */ + IF ( NE_32( hTcBuffer->tc_buffer_mode, tc_buffer_mode_new ) || NE_16( hTcBuffer->nchan_transport_jbm, tc_nchan_tc_new ) || + NE_16( hTcBuffer->nchan_buffer_full, tc_nchan_full_new ) || NE_16( hTcBuffer->nchan_transport_internal, tc_nchan_allocate_new ) ) + { + IF ( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ + IF ( st_ivas->hSpatParamRendCom != NULL ) + { + st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + move16(); + st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + move16(); + st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; + move16(); + st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + move16(); + + Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + } + } + + return error; +} +#endif + static ivas_error ivas_ism_bitrate_switching_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nchan_transport_old, /* i : last number of transport channels */ @@ -103,10 +432,17 @@ static ivas_error ivas_ism_bitrate_switching_dec( * Allocate, initialize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED + IF ( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, 0, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, 0, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) { return error; } +#endif // IVAS_FLOAT_FIXED /*-----------------------------------------------------------------* * HP20 memories @@ -168,21 +504,6 @@ static ivas_error ivas_ism_bitrate_switching_dec( #if 1 /*Float to fixed conversion*/ DECODER_TC_BUFFER_HANDLE hTcBuffer; hTcBuffer = st_ivas->hTcBuffer; - if ( st_ivas->hIsmRendererData ) - { - FOR( Word16 ind1 = 0; ind1 < st_ivas->hIsmRendererData->interpolator_len; ind1++ ) - { - st_ivas->hIsmRendererData->interpolator_fx[ind1] = (Word16) L_min( 32767, floatToFixed( st_ivas->hIsmRendererData->interpolator_fx[ind1], 15 ) ); - } - FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->gains[ind1][ind2] * ( 1 << 30 ) ); - st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->prev_gains[ind1][ind2] * ( 1 << 30 ) ); - } - } - } FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { if ( st_ivas->hIsmMetaData[ind1] ) @@ -277,14 +598,23 @@ static ivas_error ivas_ism_bitrate_switching_dec( } } } + Word16 n_tc; + if (st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) + n_tc = st_ivas->nchan_ism; + else + n_tc = st_ivas->hTcBuffer->nchan_transport_internal; + for (int ch = 0; ch < n_tc; ch++) + { + floatToFixed_arrL(st_ivas->hTcBuffer->tc[ch], st_ivas->hTcBuffer->tc_fx[ch], Q11, L_FRAME48k); + } #endif if ( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, MC_MODE_NONE, last_ism_mode, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { return error; } #if 1 /*Fixed to float */ - IF ( hTcBuffer->tc_buffer ) - fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); + if ( hTcBuffer->tc_buffer ) + fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); IF( hSpar ) { FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) @@ -328,21 +658,6 @@ static ivas_error ivas_ism_bitrate_switching_dec( } } } - if ( st_ivas->hIsmRendererData ) - { - FOR( Word16 ind1 = 0; ind1 < st_ivas->hIsmRendererData->interpolator_len; ind1++ ) - { - st_ivas->hIsmRendererData->interpolator[ind1] = (float) ( st_ivas->hIsmRendererData->interpolator_fx[ind1] ) / (float) ( 1 << 15 ); - } - FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->gains_fx[ind1][ind2] ) / ( 1 << 30 ); - st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] ) / ( 1 << 30 ); - } - } - } FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { if ( st_ivas->hIsmMetaData[ind1] ) @@ -410,7 +725,7 @@ static ivas_error ivas_ism_bitrate_switching_dec( } #if 1 // Cleanup changes for ivas_td_binaural_open: fixed to float st_ivas->hBinRendererTd->Gain = 1.0f; /*1.0f Q15*/ - fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Pos_fx, st_ivas->hBinRendererTd->Listener_p->Pos, Q25, 3 ); + fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Pos_fx, st_ivas->hBinRendererTd->Listener_p->Pos, st_ivas->hBinRendererTd->Listener_p->Pos_q, 3 ); fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Vel_fx, st_ivas->hBinRendererTd->Listener_p->Vel, Q30, 3 ); fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Front_fx, st_ivas->hBinRendererTd->Listener_p->Front, Q30, 3 ); fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Up_fx, st_ivas->hBinRendererTd->Listener_p->Up, Q30, 3 ); @@ -490,19 +805,6 @@ static ivas_error ivas_ism_bitrate_switching_dec( { return error; } - FOR(Word16 ind = 0; ind < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind++) - { - st_ivas->hIsmRendererData->interpolator[ind] = (float)(st_ivas->hIsmRendererData->interpolator_fx[ind]) / (float)(1 << 15); - } - FOR(Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++) - { - FOR(Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++) - { - // q factors might be different. Here we are just initializing to zero - st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float)(st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2]) / (float)(1<<31); - st_ivas->hIsmRendererData->gains[ind1][ind2] = (float)(st_ivas->hIsmRendererData->gains_fx[ind1][ind2]) / (float)(1<<31); - } - } #else if ( ( error = ivas_ism_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) { @@ -564,7 +866,7 @@ static ivas_error ivas_ism_bitrate_switching_dec( } #endif // IVAS_FLOAT_FIXED - if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) { return error; } @@ -774,7 +1076,7 @@ ivas_error ivas_ism_dec_config( { IF( ( NE_16( st_ivas->ism_mode, last_ism_mode ) ) || ( NE_32( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) ) { - IF( NE_16( ( error = ivas_ism_bitrate_switching_dec( st_ivas, nchan_transport_old, last_ism_mode, nSamplesRendered, + IF( NE_16( ( error = ivas_ism_bitrate_switching_dec_fx( st_ivas, nchan_transport_old, last_ism_mode, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) { @@ -799,7 +1101,7 @@ ivas_error ivas_ism_dec_config( /* ISM mode switching */ IF( NE_16( st_ivas->ism_mode, last_ism_mode ) ) { - IF( NE_16( ( error = ivas_ism_bitrate_switching_dec( st_ivas, nchan_transport_old, last_ism_mode, nSamplesRendered, + IF( NE_16( ( error = ivas_ism_bitrate_switching_dec_fx( st_ivas, nchan_transport_old, last_ism_mode, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) { diff --git a/lib_dec/ivas_ism_dtx_dec.c b/lib_dec/ivas_ism_dtx_dec.c index 2d81aae62e42ecef970931824a814b0995049479..6aa3e6b78190e30eb84e8745deb364456d0ad3f9 100644 --- a/lib_dec/ivas_ism_dtx_dec.c +++ b/lib_dec/ivas_ism_dtx_dec.c @@ -146,14 +146,7 @@ void ivas_ism_dtx_dec_fx( return; } -#endif // IVAS_FLOAT_FIXED - -/*-------------------------------------------------------------------* - * ivas_ism_dtx_dec() - * - * ISM DTX Metadata decoding routine - *-------------------------------------------------------------------*/ - +#else void ivas_ism_dtx_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ int16_t *nb_bits_metadata /* o : number of metadata bits */ @@ -183,33 +176,8 @@ void ivas_ism_dtx_dec( } /* Metadata decoding and dequantization */ -#ifdef IVAS_FLOAT_FIXED - FOR (Word16 ind = 0; ind < st_ivas->nchan_ism; ind++) { - st_ivas->hIsmMetaData[ind]->azimuth_fx = (Word32)(st_ivas->hIsmMetaData[ind]->azimuth * (1 << 22)); - st_ivas->hIsmMetaData[ind]->elevation_fx = (Word32)(st_ivas->hIsmMetaData[ind]->elevation * (1 << 22)); - st_ivas->hIsmMetaData[ind]->last_azimuth_fx = (Word32)(st_ivas->hIsmMetaData[ind]->last_azimuth * (1 << 22)); - st_ivas->hIsmMetaData[ind]->last_elevation_fx = (Word32)(st_ivas->hIsmMetaData[ind]->last_elevation * (1 << 22)); - st_ivas->hIsmMetaData[ind]->last_true_azimuth_fx = (Word32)(st_ivas->hIsmMetaData[ind]->last_true_azimuth * (1 << 22)); - st_ivas->hIsmMetaData[ind]->last_true_elevation_fx = (Word32)(st_ivas->hIsmMetaData[ind]->last_true_elevation * (1 << 22)); - } - FOR(Word16 ind = 0; ind < st_ivas->nchan_transport; ind++) - st_ivas->hSCE[ind]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = (Word16)(st_ivas->hSCE[ind]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_flt * 32767); - ivas_ism_metadata_sid_dec_fx( st_ivas->hSCE, ivas_total_brate, st_ivas->bfi, nchan_ism, st_ivas->nchan_transport, st_ivas->ism_mode, - &flag_noisy_speech, &sce_id_dtx, st_ivas->hIsmMetaData, nb_bits_metadata ); - FOR (Word16 ind = 0; ind < st_ivas->nchan_ism; ind++) { - st_ivas->hIsmMetaData[ind]->azimuth = (float)(st_ivas->hIsmMetaData[ind]->azimuth_fx) / (float)(1 << 22); - st_ivas->hIsmMetaData[ind]->elevation = (float)(st_ivas->hIsmMetaData[ind]->elevation_fx) / (float)(1 << 22); - st_ivas->hIsmMetaData[ind]->last_azimuth = (float)(st_ivas->hIsmMetaData[ind]->last_azimuth_fx) / (float)(1 << 22); - st_ivas->hIsmMetaData[ind]->last_elevation = (float)(st_ivas->hIsmMetaData[ind]->last_elevation_fx) / (float)(1 << 22); - st_ivas->hIsmMetaData[ind]->last_true_azimuth = (float)(st_ivas->hIsmMetaData[ind]->last_true_azimuth_fx) / (float)(1 << 22); - st_ivas->hIsmMetaData[ind]->last_true_elevation = (float)(st_ivas->hIsmMetaData[ind]->last_true_elevation_fx) / (float)(1 << 22); - } - FOR(Word16 ind = 0; ind < st_ivas->nchan_transport; ind++) - st_ivas->hSCE[ind]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_flt = (float)(st_ivas->hSCE[ind]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx) / 32767.f; -#else ivas_ism_metadata_sid_dec( st_ivas->hSCE, ivas_total_brate, st_ivas->bfi, nchan_ism, st_ivas->nchan_transport, st_ivas->ism_mode, &flag_noisy_speech, &sce_id_dtx, st_ivas->hIsmMetaData, nb_bits_metadata ); -#endif if ( ivas_total_brate == IVAS_SID_5k2 && !st_ivas->bfi ) { @@ -240,29 +208,8 @@ void ivas_ism_dtx_dec( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed = st_ivas->hSCE[st_ivas->hISMDTX.sce_id_dtx]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed; } } -#ifdef IVAS_FLOAT_FIXED - for ( ch = 0; ch < nchan_ism; ch++ ) - { - if ( EQ_16(md_diff_flag[ch], 1 ) ) - { - st_ivas->hIsmMetaData[ch]->azimuth_fx = float_to_fix16(st_ivas->hIsmMetaData[ch]->azimuth, 7); // azimuth -180 to +180 - st_ivas->hIsmMetaData[ch]->elevation_fx = float_to_fix16(st_ivas->hIsmMetaData[ch]->elevation, 8); // azimuth -180 to +180 - } - } - - update_last_metadata_fx( nchan_ism, st_ivas->hIsmMetaData, md_diff_flag ); - for ( ch = 0; ch < nchan_ism; ch++ ) - { - if ( EQ_16(md_diff_flag[ch], 1 ) ) - { - st_ivas->hIsmMetaData[ch]->last_azimuth = fixedToFloat(st_ivas->hIsmMetaData[ch]->last_azimuth_fx, 7 ); - st_ivas->hIsmMetaData[ch]->last_elevation = fixedToFloat(st_ivas->hIsmMetaData[ch]->last_elevation_fx, 8); - } - } -#else update_last_metadata( nchan_ism, st_ivas->hIsmMetaData, md_diff_flag ); -#endif st_ivas->hISMDTX.ism_dtx_hangover_cnt = 0; @@ -288,6 +235,7 @@ void ivas_ism_dtx_dec( return; } +#endif /*-------------------------------------------------------------------* diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index f2da41369d676e27ec86dd76265b5b639986535c..319ddf6eef6d7bf95e36f29d46dae038d45d8f79 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -520,6 +520,14 @@ ivas_error ivas_ism_metadata_dec( { nb_bits_metadata[ch] = st0->next_bit_pos - nb_bits_start; } +#ifdef IVAS_FLOAT_FIXED + /* This is done here to update the fixed point values which will be required later during rendering */ + hIsmMetaData->azimuth_fx = float_to_fix(hIsmMetaData->azimuth, Q22); + hIsmMetaData->elevation_fx = float_to_fix(hIsmMetaData->elevation, Q22); + hIsmMetaData->yaw_fx = float_to_fix(hIsmMetaData->yaw, Q22); + hIsmMetaData->pitch_fx = float_to_fix(hIsmMetaData->pitch, Q22); + hIsmMetaData->radius_fx = float_to_fix16(hIsmMetaData->radius, Q9); +#endif } if ( ism_mode == ISM_MODE_PARAM ) @@ -1784,7 +1792,7 @@ static int16_t decode_radius( return idx_radius; } #endif - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * ivas_ism_metadata_sid_dec() * @@ -1954,7 +1962,7 @@ void ivas_ism_metadata_sid_dec( return; } - +#endif #ifdef IVAS_FLOAT_FIXED void ivas_ism_metadata_sid_dec_fx( SCE_DEC_HANDLE hSCE[MAX_SCE], /* i/o: SCE decoder structure */ diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 0e1bdaf00edfce839969408e8106717819960de4..e8ed168402448e798d8959584e1e3d34bcb6dcb4 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -55,7 +55,7 @@ #ifdef IVAS_FLOAT_FIXED static void ivas_param_ism_dec_dequant_DOA_fx( PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */ - const Word16 nchan_ism /* i : number of ISM channels */ + const Word16 nchan_ism /* i : number of ISM channels */ ) { Word16 i; @@ -66,15 +66,17 @@ static void ivas_param_ism_dec_dequant_DOA_fx( assert( nchan_ism <= MAX_NUM_OBJECTS ); /* Get the azimuth and elevation values */ - FOR ( i = 0; i < nchan_ism; i++ ) + FOR( i = 0; i < nchan_ism; i++ ) { hParamIsmDec->azimuth_values_fx[i] = ism_dequant_meta_fx( hParamIsm->azi_index[i], ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); + move32(); hParamIsmDec->elevation_values_fx[i] = ism_dequant_meta_fx( hParamIsm->ele_index[i], ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_ELEVATION_NBITS ); + move32(); } return; } -#endif // IVAS_FLOAT_FIXED +#else static void ivas_param_ism_dec_dequant_DOA( PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */ const int16_t nchan_ism /* i : number of ISM channels */ @@ -96,6 +98,7 @@ static void ivas_param_ism_dec_dequant_DOA( return; } +#endif #ifdef IVAS_FLOAT_FIXED static void ivas_param_ism_dec_dequant_powrat_fx( @@ -107,18 +110,19 @@ static void ivas_param_ism_dec_dequant_powrat_fx( hParamIsm = hParamIsmDec->hParamIsm; /* Get the power ratio values */ - for ( band_idx = 0; band_idx < hParamIsm->nbands; band_idx++ ) + FOR( band_idx = 0; band_idx < hParamIsm->nbands; band_idx++ ) { - for ( slot_idx = 0; slot_idx < hParamIsm->nblocks[band_idx]; slot_idx++ ) + FOR( slot_idx = 0; slot_idx < hParamIsm->nblocks[band_idx]; slot_idx++ ) { hParamIsmDec->power_ratios_fx[band_idx][slot_idx][0] = add( shr( div_s( ( hParamIsm->power_ratios_idx[band_idx][slot_idx] ), ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) ), 1 ), 16384 ); + move16(); hParamIsmDec->power_ratios_fx[band_idx][slot_idx][1] = sub( 32767, hParamIsmDec->power_ratios_fx[band_idx][slot_idx][0] ); + move16(); } } return; } -#endif // IVAS_FLOAT_FIXED - +#else static void ivas_param_ism_dec_dequant_powrat( PARAM_ISM_DEC_HANDLE hParamIsmDec /* i/o: decoder ParamISM handle */ ) @@ -140,33 +144,35 @@ static void ivas_param_ism_dec_dequant_powrat( return; } +#endif -static void ivas_ism_get_interpolator( - const int16_t subframe_nbslots, - float *interpolator ) +#ifdef IVAS_FLOAT_FIXED +static void ivas_ism_get_interpolator_fx( + const Word16 subframe_nbslots, + Word16 *interpolator ) { - int16_t interp_idx = 0; + Word16 interp_idx, q_tmp, tmp; - for ( interp_idx = 0; interp_idx < subframe_nbslots; interp_idx++ ) + FOR( interp_idx = 0; interp_idx < subframe_nbslots; interp_idx++ ) { - interpolator[interp_idx] = (float) ( interp_idx + 1 ) / (float) subframe_nbslots; + tmp = BASOP_Util_Divide1616_Scale( add( interp_idx, 1 ), subframe_nbslots, &q_tmp ); /*Q = 15 - q_tmp*/ + interpolator[interp_idx] = shl_sat( tmp, q_tmp ); /* Q15 */ + move16(); } return; } - -#ifdef IVAS_FLOAT_FIXED -static void ivas_ism_get_interpolator_fx( - const Word16 subframe_nbslots, - Word16 *interpolator ) +#else +static void ivas_ism_get_interpolator( + const int16_t subframe_nbslots, + float *interpolator ) { - Word16 interp_idx, q_tmp, tmp; + int16_t interp_idx = 0; - FOR ( interp_idx = 0; interp_idx < subframe_nbslots; interp_idx++ ) + for ( interp_idx = 0; interp_idx < subframe_nbslots; interp_idx++ ) { - tmp = BASOP_Util_Divide1616_Scale(add(interp_idx, 1), subframe_nbslots, &q_tmp);/*Q = 15 - q_tmp*/ - interpolator[interp_idx] = shl_sat(tmp, q_tmp); /* Q15 */move16(); + interpolator[interp_idx] = (float) ( interp_idx + 1 ) / (float) subframe_nbslots; } return; @@ -174,44 +180,51 @@ static void ivas_ism_get_interpolator_fx( #endif -static void ivas_ism_get_proto_matrix( +#ifdef IVAS_FLOAT_FIXED +static void ivas_ism_get_proto_matrix_fx( IVAS_OUTPUT_SETUP hOutSetup, - const int16_t nchan_transport, - float *proto_matrix ) + const Word16 nchan_transport, + Word16 *proto_matrix ) { - int16_t idx; + Word16 idx; /* compute proto_matrix */ - switch ( nchan_transport ) + SWITCH( nchan_transport ) { case 2: { - if ( hOutSetup.nchan_out_woLFE ) + IF( hOutSetup.nchan_out_woLFE ) { - for ( idx = 0; idx < hOutSetup.nchan_out_woLFE; idx++ ) + FOR( idx = 0; idx < hOutSetup.nchan_out_woLFE; idx++ ) { - if ( hOutSetup.ls_azimuth[idx] > 0.0f ) + IF( GT_32( hOutSetup.ls_azimuth_fx[idx], 0 ) ) { - proto_matrix[idx] = 1.0f; - proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0.0f; + proto_matrix[idx] = shl_sat( ONE_IN_Q14, 1 ); + move16(); + proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0; + move16(); } - else if ( hOutSetup.ls_azimuth[idx] < 0.0f ) + ELSE IF( LT_32( hOutSetup.ls_azimuth_fx[idx], 0 ) ) { - proto_matrix[idx] = 0.0f; - proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 1.0f; + proto_matrix[idx] = 0; + move16(); + proto_matrix[idx + hOutSetup.nchan_out_woLFE] = shl_sat( ONE_IN_Q14, 1 ); + move16(); } - else + ELSE { - proto_matrix[idx] = 0.5f; - proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0.5f; + proto_matrix[idx] = ONE_IN_Q14; /* 0.5 -> Q15*/ + move16(); + proto_matrix[idx + hOutSetup.nchan_out_woLFE] = ONE_IN_Q14; /* 0.5 -> Q15*/ + move16(); } } } - else + ELSE { assert( 0 && "Error: number of output channels not supported" ); } - break; + BREAK; } default: @@ -220,47 +233,45 @@ static void ivas_ism_get_proto_matrix( return; } - - -#ifdef IVAS_FLOAT_FIXED -static void ivas_ism_get_proto_matrix_fx( +#else +static void ivas_ism_get_proto_matrix( IVAS_OUTPUT_SETUP hOutSetup, - const Word16 nchan_transport, - Word16 *proto_matrix ) + const int16_t nchan_transport, + float *proto_matrix ) { - Word16 idx; + int16_t idx; /* compute proto_matrix */ - SWITCH ( nchan_transport ) + switch ( nchan_transport ) { case 2: { - IF ( hOutSetup.nchan_out_woLFE ) + if ( hOutSetup.nchan_out_woLFE ) { - FOR ( idx = 0; idx < hOutSetup.nchan_out_woLFE; idx++ ) + for ( idx = 0; idx < hOutSetup.nchan_out_woLFE; idx++ ) { - IF (GT_32(hOutSetup.ls_azimuth_fx[idx], 0) ) + if ( hOutSetup.ls_azimuth[idx] > 0.0f ) { - proto_matrix[idx] = shl_sat(ONE_IN_Q14, 1);move16(); - proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0;move16(); + proto_matrix[idx] = 1.0f; + proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0.0f; } - ELSE IF ( LT_32(hOutSetup.ls_azimuth_fx[idx], 0) ) + else if ( hOutSetup.ls_azimuth[idx] < 0.0f ) { - proto_matrix[idx] = 0;move16(); - proto_matrix[idx + hOutSetup.nchan_out_woLFE] = shl_sat(ONE_IN_Q14, 1);move16(); + proto_matrix[idx] = 0.0f; + proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 1.0f; } - ELSE + else { - proto_matrix[idx] = ONE_IN_Q14;/* 0.5 -> Q15*/move16(); - proto_matrix[idx + hOutSetup.nchan_out_woLFE] = ONE_IN_Q14;/* 0.5 -> Q15*/move16(); + proto_matrix[idx] = 0.5f; + proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0.5f; } } } - ELSE + else { assert( 0 && "Error: number of output channels not supported" ); } - BREAK; + break; } default: @@ -271,6 +282,7 @@ static void ivas_ism_get_proto_matrix_fx( } #endif + static void ivas_param_ism_collect_slot( PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */ float *Cldfb_RealBuffer_in, @@ -440,77 +452,94 @@ static void ivas_param_ism_render_slot_fx( Word16 outchIdx, inchIdx, bin_idx; Word32 tmp_1_fx, mixing_matrix_smooth_fx; - tmp_1_fx = L_deposit_h( hParamIsmDec->hParamIsmRendering->interpolator_fx[interpolator_idx] ); // Q30 + tmp_1_fx = L_deposit_h( hParamIsmDec->hParamIsmRendering->interpolator_fx[interpolator_idx] ); /* Q31 */ Word16 res_exp = 0; Word16 real_buf_exp = hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp; Word16 imag_buf_exp = hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp; - Word16 i, j, k; + Word16 i, j, k; + move16(); + move16(); + move16(); /*exponent buffers to handle variable exp*/ Word16 exp_buf_real[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; Word16 exp_buf_imag[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - FOR (i = 0; i < PARAM_ISM_MAX_CHAN; i++) { - FOR (j = 0; j < JBM_CLDFB_SLOTS_IN_SUBFRAME; j++) { - FOR (k = 0; k < CLDFB_NO_CHANNELS_MAX; k++) { + FOR( i = 0; i < PARAM_ISM_MAX_CHAN; i++ ) + { + FOR( j = 0; j < JBM_CLDFB_SLOTS_IN_SUBFRAME; j++ ) + { + FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ ) + { exp_buf_real[i][j][k] = 0; + move16(); exp_buf_imag[i][j][k] = 0; + move16(); } } } - FOR ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ ) + FOR( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ ) { /* smooth the mixing matrix */ - FOR ( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ ) + FOR( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ ) { - FOR ( inchIdx = 0; inchIdx < nchan_transport; inchIdx++ ) + FOR( inchIdx = 0; inchIdx < nchan_transport; inchIdx++ ) { - Word32 tmp_2 = Mpy_32_32( tmp_1_fx, mixing_matrix_fx[bin_idx][outchIdx + inchIdx * num_ch_LS] ); // 1 + hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin // Q29 - Word32 tmp_3 = Mpy_32_32( L_sub( ONE_IN_Q30, tmp_1_fx ), hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old_fx[bin_idx][outchIdx + inchIdx * num_ch_LS] ); // 1 + hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_old - mixing_matrix_smooth_fx = BASOP_Util_Add_Mant32Exp( tmp_2, 1 + hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_fx, tmp_3, 1 + hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_old_fx, &res_exp ); + Word32 tmp_2 = Mpy_32_32( tmp_1_fx, mixing_matrix_fx[bin_idx][outchIdx + inchIdx * num_ch_LS] ); // hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin + Word32 tmp_3 = Mpy_32_32( L_sub( ONE_IN_Q31, tmp_1_fx ), hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old_fx[bin_idx][outchIdx + inchIdx * num_ch_LS] ); // 1 + hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_old + mixing_matrix_smooth_fx = BASOP_Util_Add_Mant32Exp( tmp_2, hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_fx, tmp_3, hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_old_fx, &res_exp ); Word32 tmp_4 = Mpy_32_32( mixing_matrix_smooth_fx, Cldfb_RealBuffer_in_fx[inchIdx][bin_idx] ); // res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp Word32 tmp_5 = Mpy_32_32( mixing_matrix_smooth_fx, Cldfb_ImagBuffer_in_fx[inchIdx][bin_idx] ); // res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx] = BASOP_Util_Add_Mant32Exp( Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx], real_buf_exp, tmp_4, res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp, &real_buf_exp ); + move32(); Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx] = BASOP_Util_Add_Mant32Exp( Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx], imag_buf_exp, tmp_5, res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp, &imag_buf_exp ); - + move32(); + exp_buf_real[outchIdx][out_slot_idx][bin_idx] = real_buf_exp; + move16(); exp_buf_imag[outchIdx][out_slot_idx][bin_idx] = imag_buf_exp; + move16(); } } } /*Make same exponent for whole buffer*/ - Word16 max_exp_real = MIN_16; + Word16 max_exp_real = MIN_16; + move16(); Word16 max_exp_imag = MIN_16; - FOR (bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++) + move16(); + FOR( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ ) { - FOR (outchIdx = 0; outchIdx < num_ch_LS; outchIdx++) + FOR( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ ) { - max_exp_real = max(max_exp_real, exp_buf_real[outchIdx][out_slot_idx][bin_idx]); - max_exp_imag = max(max_exp_imag, exp_buf_imag[outchIdx][out_slot_idx][bin_idx]); + max_exp_real = s_max( max_exp_real, exp_buf_real[outchIdx][out_slot_idx][bin_idx] ); + max_exp_imag = s_max( max_exp_imag, exp_buf_imag[outchIdx][out_slot_idx][bin_idx] ); } } - FOR (bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++) + FOR( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ ) { - FOR (outchIdx = 0; outchIdx < num_ch_LS; outchIdx++) + FOR( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ ) { - Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx] = L_shr(Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx], sub(max_exp_real , exp_buf_real[outchIdx][out_slot_idx][bin_idx])); - Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx] = L_shr(Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx], sub(max_exp_imag , exp_buf_imag[outchIdx][out_slot_idx][bin_idx])); + Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx] = L_shr( Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx], sub( max_exp_real, exp_buf_real[outchIdx][out_slot_idx][bin_idx] ) ); + move32(); + Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx] = L_shr( Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx], sub( max_exp_imag, exp_buf_imag[outchIdx][out_slot_idx][bin_idx] ) ); + move32(); } } - + *exp_real = max_exp_real; + move16(); *exp_imag = max_exp_imag; + move16(); return; } -#endif - +#else static void ivas_param_ism_render_slot( PARAM_ISM_DEC_HANDLE hParamIsmDec, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, @@ -547,8 +576,10 @@ static void ivas_param_ism_render_slot( return; } +#endif +#ifndef IVAS_FLOAT_FIXED static void ivas_param_ism_rendering( PARAM_ISM_DEC_HANDLE hParamIsmDec, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, @@ -585,28 +616,24 @@ static void ivas_param_ism_rendering( return; } +#endif +#ifdef IVAS_FLOAT_FIXED static ivas_error ivas_param_ism_rendering_init( PARAM_ISM_RENDERING_HANDLE hParamIsmRendering, IVAS_OUTPUT_SETUP hOutSetup, - const int16_t nchan_transport, - const int16_t subframe_nbslots, + const Word16 nchan_transport, + const Word16 subframe_nbslots, AUDIO_CONFIG output_config ) { - int16_t bin_idx; + Word16 bin_idx; /* initialization of mixing matrix buffer for smoothing */ - for ( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ ) - { - set_zero( hParamIsmRendering->mixing_matrix_lin_old[bin_idx], PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX ); - } -#ifdef IVAS_FLOAT_FIXED FOR( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ ) { set32_fx( hParamIsmRendering->mixing_matrix_lin_old_fx[bin_idx], 0, PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX ); } -#endif /* memory allocation for proto matrix and interpolator */ if ( ( hParamIsmRendering->proto_matrix = (float *) malloc( hOutSetup.nchan_out_woLFE * nchan_transport * sizeof( float ) ) ) == NULL ) @@ -619,26 +646,23 @@ static ivas_error ivas_param_ism_rendering_init( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for proto matrix\n" ) ); } #endif // IVAS_FLOAT_FIXED - if ( ( hParamIsmRendering->interpolator = (float *) malloc( subframe_nbslots * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n" ) ); - } -#ifdef IVAS_FLOAT_FIXED IF( ( hParamIsmRendering->interpolator_fx = (Word16 *) malloc( subframe_nbslots * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n" ) ); } -#endif // IVAS_FLOAT_FIXED - if ( !( output_config == IVAS_AUDIO_CONFIG_EXTERNAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + test(); + test(); + test(); + IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) { /* computation of proto matrix */ #ifdef IVAS_FLOAT_FIXED ivas_ism_get_proto_matrix_fx( hOutSetup, nchan_transport, hParamIsmRendering->proto_matrix_fx ); for ( int idx = 0; idx < hOutSetup.nchan_out_woLFE; idx++ ) { - hParamIsmRendering->proto_matrix[idx] = (float)hParamIsmRendering->proto_matrix_fx[idx]/(1<<15); - hParamIsmRendering->proto_matrix[idx + hOutSetup.nchan_out_woLFE] = (float)hParamIsmRendering->proto_matrix_fx[idx + hOutSetup.nchan_out_woLFE]/(1<<15); + hParamIsmRendering->proto_matrix[idx] = (float) hParamIsmRendering->proto_matrix_fx[idx] / ( 1 << 15 ); + hParamIsmRendering->proto_matrix[idx + hOutSetup.nchan_out_woLFE] = (float) hParamIsmRendering->proto_matrix_fx[idx + hOutSetup.nchan_out_woLFE] / ( 1 << 15 ); } #else ivas_ism_get_proto_matrix( hOutSetup, nchan_transport, hParamIsmRendering->proto_matrix ); @@ -646,18 +670,48 @@ static ivas_error ivas_param_ism_rendering_init( } /* computation of interpolator*/ -#ifdef IVAS_FLOAT_FIXED ivas_ism_get_interpolator_fx( subframe_nbslots, hParamIsmRendering->interpolator_fx ); - for ( int i = 0; i < subframe_nbslots; i++ ) + + return IVAS_ERR_OK; +} +#else +static ivas_error ivas_param_ism_rendering_init( + PARAM_ISM_RENDERING_HANDLE hParamIsmRendering, + IVAS_OUTPUT_SETUP hOutSetup, + const int16_t nchan_transport, + const int16_t subframe_nbslots, + AUDIO_CONFIG output_config ) +{ + int16_t bin_idx; + + /* initialization of mixing matrix buffer for smoothing */ + for ( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ ) { - hParamIsmRendering->interpolator[i] = (float)hParamIsmRendering->interpolator_fx[i]/(1<<15); + set_zero( hParamIsmRendering->mixing_matrix_lin_old[bin_idx], PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX ); } -#else + + /* memory allocation for proto matrix and interpolator */ + if ( ( hParamIsmRendering->proto_matrix = (float *) malloc( hOutSetup.nchan_out_woLFE * nchan_transport * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for proto matrix\n" ) ); + } + if ( ( hParamIsmRendering->interpolator = (float *) malloc( subframe_nbslots * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n" ) ); + } + + if ( !( output_config == IVAS_AUDIO_CONFIG_EXTERNAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + { + /* computation of proto matrix */ + ivas_ism_get_proto_matrix( hOutSetup, nchan_transport, hParamIsmRendering->proto_matrix ); + } + + /* computation of interpolator*/ ivas_ism_get_interpolator( subframe_nbslots, hParamIsmRendering->interpolator ); -#endif // IVAS_FLOAT_FIXED return IVAS_ERR_OK; } +#endif #ifdef IVAS_FLOAT_FIXED static void ivas_param_ism_update_mixing_matrix_fx( @@ -665,34 +719,37 @@ static void ivas_param_ism_update_mixing_matrix_fx( Word32 mixing_matrix_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], Word16 mixing_matrix_exp, const Word16 nchan_in, - const Word16 nchan_out) + const Word16 nchan_out ) { Word16 inchIdx, outchIdx, bin_idx, band_idx; Word16 brange[2]; - FOR (band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++) + FOR( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ ) { brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx]; + move16(); brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1]; + move16(); - FOR (bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++) + FOR( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ ) { - FOR (inchIdx = 0; inchIdx < nchan_in; inchIdx++) + FOR( inchIdx = 0; inchIdx < nchan_in; inchIdx++ ) { - FOR (outchIdx = 0; outchIdx < nchan_out; outchIdx++) + FOR( outchIdx = 0; outchIdx < nchan_out; outchIdx++ ) { hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old_fx[bin_idx][outchIdx + inchIdx * nchan_out] = mixing_matrix_fx[bin_idx][outchIdx + inchIdx * nchan_out]; + move32(); } } } } - hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_old_fx = mixing_matrix_exp; + hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_old_fx = mixing_matrix_exp; + move16(); return; } -#endif - +#else static void ivas_param_ism_update_mixing_matrix( PARAM_ISM_DEC_HANDLE hParamIsmDec, float mixing_matrix[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], @@ -721,6 +778,7 @@ static void ivas_param_ism_update_mixing_matrix( return; } +#endif /*-------------------------------------------------------------------------* @@ -851,8 +909,13 @@ ivas_error ivas_param_ism_dec_open( } /* Azi and Ele values are transmitted once per frame per object */ +#ifdef IVAS_FLOAT_FIXED + set32_fx( hParamIsmDec->azimuth_values_fx, 0, MAX_NUM_OBJECTS ); + set32_fx( hParamIsmDec->elevation_values_fx, 0, MAX_NUM_OBJECTS ); +#else set_zero( hParamIsmDec->azimuth_values, MAX_NUM_OBJECTS ); set_zero( hParamIsmDec->elevation_values, MAX_NUM_OBJECTS ); +#endif hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; hSpatParamRendCom->dirac_bs_md_write_idx = 0; @@ -1007,11 +1070,6 @@ void ivas_param_ism_dec_close( { /* Param ISM Rendering */ // To be removed later: Freeing memory allocated to float pointers - IF( hParamIsmDec->hParamIsmRendering->interpolator != NULL ) - { - free( hParamIsmDec->hParamIsmRendering->interpolator ); - hParamIsmDec->hParamIsmRendering->interpolator = NULL; - } IF( hParamIsmDec->hParamIsmRendering->proto_matrix != NULL ) { free( hParamIsmDec->hParamIsmRendering->proto_matrix ); @@ -1157,6 +1215,7 @@ void ivas_param_ism_dec_close( #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * ivas_param_ism_dec() * @@ -1235,36 +1294,8 @@ void ivas_param_ism_dec( /* De-quantization */ if ( !( ivas_total_brate == IVAS_SID_5k2 || ivas_total_brate == FRAME_NO_DATA ) ) { -#ifdef IVAS_FLOAT_FIXED - ivas_param_ism_dec_dequant_DOA_fx( hParamIsmDec, st_ivas->nchan_ism ); - fixedToFloat_arrL( hParamIsmDec->azimuth_values_fx, hParamIsmDec->azimuth_values, 22, st_ivas->nchan_ism ); - fixedToFloat_arrL( hParamIsmDec->elevation_values_fx, hParamIsmDec->elevation_values, 22, st_ivas->nchan_ism ); - for ( int i = 0; i < 11; i++ ) - { - for ( int j = 0; j < 1; j++ ) - { - for ( int k = 0; k < 2; k++ ) - { - hParamIsmDec->power_ratios_fx[i][j][k] = (Word16) floatToFixed( hParamIsmDec->power_ratios[i][j][k], 15 ); - } - } - } - ivas_param_ism_dec_dequant_powrat_fx( hParamIsmDec ); - for ( int i = 0; i < 11; i++ ) - { - for ( int j = 0; j < 1; j++ ) - { - for ( int k = 0; k < 2; k++ ) - { - hParamIsmDec->power_ratios[i][j][k] = fixedToFloat( hParamIsmDec->power_ratios_fx[i][j][k], 15 ); - } - } - } -#else ivas_param_ism_dec_dequant_DOA( hParamIsmDec, st_ivas->nchan_ism ); ivas_param_ism_dec_dequant_powrat( hParamIsmDec ); -#endif // IVAS_FLOAT_FIXED - st_ivas->hISMDTX.dtx_flag = 0; } else @@ -1428,6 +1459,7 @@ void ivas_param_ism_dec( return; } +#endif /*-------------------------------------------------------------------------* @@ -1442,33 +1474,45 @@ void ivas_ism_dec_digest_tc_fx( { ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas ); - IF( st_ivas->renderer_type == RENDERER_TD_PANNING || - st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || - st_ivas->renderer_type == RENDERER_OSBA_AMBI || - st_ivas->renderer_type == RENDERER_OSBA_LS || - st_ivas->renderer_type == RENDERER_OSBA_STEREO || - ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM && st_ivas->hDecoderConfig->Opt_Headrotation == 0 ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_TD_PANNING ) || + EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || + EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || + EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || + EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || + EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) || + EQ_32( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) || + ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) && EQ_16( st_ivas->hDecoderConfig->Opt_Headrotation, 0 ) ) ) { Word16 i, num_objects; Word32 azimuth_fx, elevation_fx; /* we have a full frame interpolator, adapt it */ /* for BE testing */ - IF( ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ) == st_ivas->hTcBuffer->n_samples_available ) + IF( EQ_16( extract_l( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ), st_ivas->hTcBuffer->n_samples_available ) ) { - int16_t interpolator_length = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); + Word16 interpolator_length = extract_l( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); - IF( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || - st_ivas->renderer_type == RENDERER_OSBA_AMBI || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || + EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || + EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { st_ivas->hIsmRendererData->interpolator_fx[0] = 0; + move16(); FOR( i = 1; i < interpolator_length; i++ ) { Word16 tmp = div_s( 1, interpolator_length - 1 ); st_ivas->hIsmRendererData->interpolator_fx[i] = add( st_ivas->hIsmRendererData->interpolator_fx[i - 1], tmp ); // Q15 + move16(); } } ELSE @@ -1476,6 +1520,7 @@ void ivas_ism_dec_digest_tc_fx( FOR( i = 0; i < interpolator_length; i++ ) { st_ivas->hIsmRendererData->interpolator_fx[i] = div_s( i, sub( interpolator_length, 1 ) ); // Q15 + move16(); } } } @@ -1486,6 +1531,7 @@ void ivas_ism_dec_digest_tc_fx( /* also get the gains here */ num_objects = st_ivas->nchan_transport; + move16(); FOR( i = 0; i < num_objects; i++ ) { Copy32( st_ivas->hIsmRendererData->gains_fx[i], st_ivas->hIsmRendererData->prev_gains_fx[i], MAX_OUTPUT_CHANNELS ); @@ -1495,7 +1541,9 @@ void ivas_ism_dec_digest_tc_fx( Word16 gains_fx[2]; ivas_ism_get_stereo_gains_fx( (Word16) st_ivas->hIsmMetaData[i]->azimuth, (Word16) st_ivas->hIsmMetaData[i]->elevation, &gains_fx[0], &gains_fx[1] ); st_ivas->hIsmRendererData->gains_fx[i][0] = L_shr( L_deposit_h( gains_fx[0] ), 1 ); + move32(); st_ivas->hIsmRendererData->gains_fx[i][1] = L_shr( L_deposit_h( gains_fx[1] ), 1 ); + move32(); } ELSE { @@ -1503,15 +1551,19 @@ void ivas_ism_dec_digest_tc_fx( azimuth_fx = L_shr( L_add( st_ivas->hIsmMetaData[i]->azimuth_fx, 2097152 ), Q22 ); elevation_fx = L_shr( L_add( st_ivas->hIsmMetaData[i]->elevation_fx, 2097152 ), Q22 ); - IF( ( st_ivas->renderer_type == RENDERER_TD_PANNING || - st_ivas->renderer_type == RENDERER_OSBA_LS || - st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) && + test(); + test(); + test(); + IF( ( EQ_32( st_ivas->renderer_type, RENDERER_TD_PANNING ) || + EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) || + EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) && st_ivas->hCombinedOrientationData == NULL ) { IF( st_ivas->hIntSetup.is_planar_setup ) { /* If no elevation support in output format, then rendering should be done with zero elevation */ elevation_fx = 0; + move32(); } IF( st_ivas->hEFAPdata != NULL ) @@ -1521,9 +1573,9 @@ void ivas_ism_dec_digest_tc_fx( efap_determine_gains_fixed( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains_fx[i], azimuth_fx, elevation_fx, EFAP_MODE_EFAP ); } } - ELSE IF( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || - st_ivas->renderer_type == RENDERER_OSBA_AMBI || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || + EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || + EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { /*get HOA gets for direction (ACN/SN3D)*/ Word16 azi = shr( extract_h( st_ivas->hIsmMetaData[i]->azimuth_fx ), 22 - 16 ); @@ -1536,8 +1588,7 @@ void ivas_ism_dec_digest_tc_fx( return; } -#endif - +#else void ivas_ism_dec_digest_tc( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) @@ -1558,39 +1609,6 @@ void ivas_ism_dec_digest_tc( /* we have a full frame interpolator, adapt it */ /* for BE testing */ -#ifdef IVAS_FLOAT_FIXED - IF((st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC) == st_ivas->hTcBuffer->n_samples_available) - { - int16_t interpolator_length = (int16_t)(st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC); - - IF(st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || - st_ivas->renderer_type == RENDERER_OSBA_AMBI || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV) - { - st_ivas->hIsmRendererData->interpolator_fx[0] = 0; - FOR(i = 1; i < interpolator_length; i++) - { - Word16 tmp = div_s(1, interpolator_length - 1); - st_ivas->hIsmRendererData->interpolator_fx[i] = add(st_ivas->hIsmRendererData->interpolator_fx[i - 1], tmp); // Q15 - } - } - ELSE - { - FOR(i = 0; i < interpolator_length; i++) - { - st_ivas->hIsmRendererData->interpolator_fx[i] = div_s(i, sub(interpolator_length, 1)); // Q15 - } - } - } - ELSE - { - ivas_jbm_dec_get_adapted_linear_interpolator_fx((int16_t)(st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC), st_ivas->hTcBuffer->n_samples_available, st_ivas->hIsmRendererData->interpolator_fx); - } - FOR(i = 0; i < (int16_t)(st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC); i++) - { - st_ivas->hIsmRendererData->interpolator[i] = fixedToFloat(st_ivas->hIsmRendererData->interpolator_fx[i], Q15); - } -#else if ( ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ) == st_ivas->hTcBuffer->n_samples_available ) { int16_t interpolator_length = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); @@ -1617,7 +1635,6 @@ void ivas_ism_dec_digest_tc( { ivas_jbm_dec_get_adapted_linear_interpolator( (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ), st_ivas->hTcBuffer->n_samples_available, st_ivas->hIsmRendererData->interpolator ); } -#endif /* also get the gains here */ num_objects = st_ivas->nchan_transport; @@ -1627,14 +1644,7 @@ void ivas_ism_dec_digest_tc( if ( st_ivas->intern_config == IVAS_AUDIO_CONFIG_STEREO ) { -#ifdef IVAS_FLOAT_FIXED - Word16 gains_fx[2]; - ivas_ism_get_stereo_gains_fx( (Word16)st_ivas->hIsmMetaData[i]->azimuth, (Word16)st_ivas->hIsmMetaData[i]->elevation, &gains_fx[0], &gains_fx[1] ); - st_ivas->hIsmRendererData->gains[i][0] = (float)gains_fx[0] / 32768.f; - st_ivas->hIsmRendererData->gains[i][1] = (float)gains_fx[1] / 32768.f; -#else ivas_ism_get_stereo_gains( st_ivas->hIsmMetaData[i]->azimuth, st_ivas->hIsmMetaData[i]->elevation, &st_ivas->hIsmRendererData->gains[i][0], &st_ivas->hIsmRendererData->gains[i][1] ); -#endif } else { @@ -1655,17 +1665,7 @@ void ivas_ism_dec_digest_tc( if ( st_ivas->hEFAPdata != NULL ) { -#ifdef IVAS_FLOAT_FIXED - Word32 azimuth_fx = L_shr(L_add(st_ivas->hIsmMetaData[i]->azimuth_fx, 2097152), Q22); - Word32 elevation_fx = L_shr(L_add(st_ivas->hIsmMetaData[i]->elevation_fx, 2097152), Q22); - efap_determine_gains_fixed(st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains_fx[i], azimuth_fx, elevation_fx, EFAP_MODE_EFAP); - FOR(Word32 j = 0; j < MAX_OUTPUT_CHANNELS; j++) - { - st_ivas->hIsmRendererData->gains[i][j] = ((float)st_ivas->hIsmRendererData->gains_fx[i][j]) / L_shl(1, Q30); - } -#else efap_determine_gains(st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains[i], azimuth, elevation, EFAP_MODE_EFAP); -#endif } } else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || @@ -1673,16 +1673,7 @@ void ivas_ism_dec_digest_tc( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) { /*get HOA gets for direction (ACN/SN3D)*/ -#ifdef IVAS_FLOAT_FIXED - Word16 azi = shr(extract_h(st_ivas->hIsmMetaData[i]->azimuth_fx), 22 - 16); - Word16 ele = shr(extract_h(st_ivas->hIsmMetaData[i]->elevation_fx), 22 - 16); - ivas_dirac_dec_get_response_fx(azi, ele, st_ivas->hIsmRendererData->gains_fx[i], st_ivas->hIntSetup.ambisonics_order); - for (int j = 0; j < MAX_OUTPUT_CHANNELS; j++) { - st_ivas->hIsmRendererData->gains[i][j] = fixedToFloat(st_ivas->hIsmRendererData->gains_fx[i][j], Q30); - } -#else ivas_dirac_dec_get_response(azimuth, elevation, st_ivas->hIsmRendererData->gains[i], st_ivas->hIntSetup.ambisonics_order); -#endif } } } @@ -1690,6 +1681,7 @@ void ivas_ism_dec_digest_tc( return; } +#endif /*-------------------------------------------------------------------------* * ivas_param_ism_dec_digest_tc() @@ -1710,6 +1702,9 @@ void ivas_param_ism_dec_digest_tc( float ref_power[CLDFB_NO_CHANNELS_MAX]; float cx_diag[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_DMX]; /* Direct Response/EFAP Gains */ +#ifdef IVAS_FLOAT_FIXED + Word32 direct_response_fx[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN]; +#endif float direct_response[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN]; PARAM_ISM_DEC_HANDLE hParamIsmDec; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; @@ -1741,7 +1736,11 @@ void ivas_param_ism_dec_digest_tc( push_wmops( "ivas_param_ism_dec" ); /* general setup */ +#ifdef IVAS_FLOAT_FIXED + ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hParamIsmDec->hParamIsmRendering->interpolator_fx ); +#else ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hParamIsmDec->hParamIsmRendering->interpolator ); +#endif #ifdef IVAS_FLOAT_FIXED ivas_dirac_dec_set_md_map_fx( st_ivas, nCldfbSlots ); @@ -1761,8 +1760,6 @@ void ivas_param_ism_dec_digest_tc( { #ifdef IVAS_FLOAT_FIXED ivas_param_ism_dec_dequant_DOA_fx( hParamIsmDec, st_ivas->nchan_ism ); - fixedToFloat_arrL( hParamIsmDec->azimuth_values_fx, hParamIsmDec->azimuth_values, 22, st_ivas->nchan_ism ); - fixedToFloat_arrL( hParamIsmDec->elevation_values_fx, hParamIsmDec->elevation_values, 22, st_ivas->nchan_ism ); for ( int i = 0; i < 11; i++ ) { for ( int j = 0; j < 1; j++ ) @@ -1798,10 +1795,22 @@ void ivas_param_ism_dec_digest_tc( /* obtain the direct response using EFAP */ if ( !( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) ) { +#ifdef IVAS_FLOAT_FIXED + FOR( i = 0; i < st_ivas->nchan_ism; i++ ) + { + efap_determine_gains_fixed( st_ivas->hEFAPdata, direct_response_fx[i], hParamIsmDec->azimuth_values_fx[i], hParamIsmDec->elevation_values_fx[i], EFAP_MODE_EFAP ); + } + + FOR( i = 0; i < st_ivas->nchan_ism; i++ ) + { + fixedToFloat_arrL( direct_response_fx[i], direct_response[i], Q30, PARAM_ISM_MAX_CHAN ); + } +#else for ( i = 0; i < st_ivas->nchan_ism; i++ ) { efap_determine_gains( st_ivas->hEFAPdata, direct_response[i], hParamIsmDec->azimuth_values[i], hParamIsmDec->elevation_values[i], EFAP_MODE_EFAP ); } +#endif } else { @@ -1824,14 +1833,22 @@ void ivas_param_ism_dec_digest_tc( for ( j = 0; j < nchan_out_woLFE; j++ ) { +#ifdef IVAS_FLOAT_FIXED + IF( GT_32( hParamIsmDec->azimuth_values_fx[j], 0 ) ) +#else if ( hParamIsmDec->azimuth_values[j] > 0.0f ) +#endif { hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 1.0f; hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 0.0f; } else { +#ifdef IVAS_FLOAT_FIXED + IF( LT_32( hParamIsmDec->azimuth_values_fx[j], 0 ) ) +#else if ( hParamIsmDec->azimuth_values[j] < 0.0f ) +#endif { hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 0.0f; hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 1.0f; @@ -1983,6 +2000,7 @@ void ivas_ism_param_dec_tc_gain_ajust_fx( last_gain_fx = st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain_fx; + move16(); Word32 ch0, ch1; Word16 ch0_e, ch1_e; @@ -2033,11 +2051,13 @@ void ivas_ism_param_dec_tc_gain_ajust_fx( gain_fx = Sqrt16( gain_fx, &tmp_e1 ); tmp_e2 = st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain_e; + move16(); IF( GT_16( tmp_e2, tmp_e1 ) ) { gain_fx = shr( gain_fx, tmp_e2 - tmp_e1 ); tmp_e1 = tmp_e2; + move16(); } ELSE { @@ -2052,20 +2072,25 @@ void ivas_ism_param_dec_tc_gain_ajust_fx( /* slope between two consecutive gains, 480 samples length */ invFade = div_s( 1, nFadeLength ); tmp = 0; + move16(); FOR( i = 0; i < ( nFadeLength ); i++ ) { /* tmp2 = ( last_gain_fx + i * grad_fx )*/ tmp2 = add( mult_r( sub( 32767, tmp ), last_gain_fx ), mult_r( tmp, gain_fx ) ); transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], tmp2 ); + move32(); transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], tmp2 ); + move32(); tmp = add( tmp, invFade ); } FOR( ; i < nSamples; i++ ) { transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], gain_fx ); + move32(); transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], gain_fx ); + move32(); } } ELSE @@ -2073,7 +2098,9 @@ void ivas_ism_param_dec_tc_gain_ajust_fx( FOR( i = 0; i < nSamples; i++ ) { transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], gain_fx ); + move32(); transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], gain_fx ); + move32(); } } @@ -2220,8 +2247,7 @@ static void ivas_ism_param_dec_render_sf_fx( return; } -#endif - +#else static void ivas_ism_param_dec_render_sf( Decoder_Struct *st_ivas, IVAS_OUTPUT_SETUP hSetup, @@ -2310,6 +2336,7 @@ static void ivas_ism_param_dec_render_sf( return; } +#endif /*-------------------------------------------------------------------------* @@ -2653,8 +2680,7 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( } return; } -#endif // IVAS_FLOAT_FIXED - +#else void ivas_param_ism_params_to_masa_param_mapping( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) @@ -2773,3 +2799,4 @@ void ivas_param_ism_params_to_masa_param_mapping( return; } +#endif diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index e28b36a69273c594856d4d7165c106f18d2573e2..c596935460d275faf1a76de74dc59a256a8d9981 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -159,25 +159,14 @@ ivas_error ivas_ism_renderer_open_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM renderer interpolator\n" ) ); } -#if 1/*TODO: To be removed later: Storing length of interpolator_fx*/ st_ivas->hIsmRendererData->interpolator_len = init_interpolator_length; -#endif + move16(); + FOR ( i = 0; i < interpolator_length - 1; i++ ) { - st_ivas->hIsmRendererData->interpolator_fx[i] = div_s( i, interpolator_length - 1 ); + st_ivas->hIsmRendererData->interpolator_fx[i] = div_s( i, sub( interpolator_length, 1 ) ); } st_ivas->hIsmRendererData->interpolator_fx[interpolator_length - 1] = 32767; - // To be removed later ///////////////////////////////////////////////////////////////////////////////////////////////////////// - IF ( ( st_ivas->hIsmRendererData->interpolator = (float *) malloc( sizeof( float ) * init_interpolator_length ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM renderer interpolator\n" ) ); - } - - FOR ( i = 0; i < interpolator_length; i++ ) - { - st_ivas->hIsmRendererData->interpolator[i] = (float) i / ( (float) interpolator_length - 1 ); - } - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// return IVAS_ERR_OK; } @@ -225,13 +214,6 @@ void ivas_ism_renderer_close( free( ( *hIsmRendererData )->interpolator_fx ); ( *hIsmRendererData )->interpolator_fx = NULL; } - // To be removed later ///////////////////////////// - IF ((*hIsmRendererData)->interpolator != NULL) - { - free((*hIsmRendererData)->interpolator); - (*hIsmRendererData)->interpolator = NULL; - } - //////////////////////////////////////////////////// free( *hIsmRendererData ); *hIsmRendererData = NULL; @@ -309,7 +291,13 @@ void ivas_ism_render_sf( if ( st_ivas->hEFAPdata != NULL ) { +#ifdef IVAS_FLOAT_FIXED + float gains[MAX_OUTPUT_CHANNELS]; + fixedToFloat_arrL(st_ivas->hIsmRendererData->gains_fx[i], gains, Q30, MAX_OUTPUT_CHANNELS); + efap_determine_gains( st_ivas->hEFAPdata, gains, azimuth, elevation, EFAP_MODE_EFAP ); +#else efap_determine_gains( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains[i], azimuth, elevation, EFAP_MODE_EFAP ); +#endif } } @@ -321,23 +309,43 @@ void ivas_ism_render_sf( ( lfe_index < ( st_ivas->hIntSetup.num_lfe - 1 ) ) ? ( lfe_index++, j2++ ) : j2++; } +#ifdef IVAS_FLOAT_FIXED + gain = fix_to_float(st_ivas->hIsmRendererData->gains_fx[i][j], Q30); + prev_gain = fix_to_float(st_ivas->hIsmRendererData->prev_gains_fx[i][j], Q30); +#else gain = st_ivas->hIsmRendererData->gains[i][j]; prev_gain = st_ivas->hIsmRendererData->prev_gains[i][j]; +#endif if ( fabsf( gain ) > 0.0f || fabsf( prev_gain ) > 0.0f ) { +#ifdef IVAS_FLOAT_FIXED + Word16 *g1_fx; + g1_fx = &st_ivas->hIsmRendererData->interpolator_fx[interp_offset]; +#else g1 = &st_ivas->hIsmRendererData->interpolator[interp_offset]; +#endif tc = p_tc[i]; for ( k = 0; k < n_samples_to_render; k++ ) { +#ifdef IVAS_FLOAT_FIXED + g2 = 1.0f - fix16_to_float(*g1_fx, Q15); + output_f[j2][k] += ( fix16_to_float(*g1_fx, Q15) * gain + g2 * prev_gain ) * *( tc++ ); + g1_fx++; +#else g2 = 1.0f - *g1; output_f[j2][k] += ( *( g1++ ) * gain + g2 * prev_gain ) * *( tc++ ); +#endif } } /* update here only in case of head rotation */ if ( st_ivas->hCombinedOrientationData != NULL && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] == 1 ) { +#ifdef IVAS_FLOAT_FIXED + st_ivas->hIsmRendererData->prev_gains_fx[i][j] = float_to_fix( gain, Q30 ); +#else st_ivas->hIsmRendererData->prev_gains[i][j] = gain; +#endif } } } @@ -476,56 +484,15 @@ void ivas_ism_render_sf_fx( * *-------------------------------------------------------------------------*/ -void ivas_ism_get_stereo_gains( - const float azimuth, /* i : object azimuth */ - const float elevation, /* i : object elevation */ - float *left_gain, /* o : left channel gain */ - float *right_gain /* o : right channel gain */ -) -{ - float aziRad, eleRad; - float y, mappedX, aziRadMapped, A, A2, A3; - const float LsAngleRad = 30.0f * PI_OVER_180; - - /* Convert azi and ele to an azi value of the cone of confusion */ - aziRad = azimuth * PI_OVER_180; - eleRad = elevation * PI_OVER_180; - y = ( sinf( aziRad ) * cosf( eleRad ) ); - mappedX = sqrtf( max( 0.0f, 1.0f - ( y * y ) ) ); - aziRadMapped = atan2f( y, mappedX ); - - /* Determine the amplitude panning gains */ - if ( aziRadMapped >= LsAngleRad ) - { /* Left side */ - *left_gain = 1.0f; - *right_gain = 0.0f; - } - else if ( aziRadMapped <= -LsAngleRad ) - { /* Right side */ - *left_gain = 0.0f; - *right_gain = 1.0f; - } - else /* Tangent panning law */ - { - A = tanf( aziRadMapped ) / tanf( LsAngleRad ); - A2 = ( A - 1.0f ) / max( 0.001f, A + 1.0f ); - A3 = 1.0f / ( A2 * A2 + 1.0f ); - *left_gain = sqrtf( A3 ); - *right_gain = sqrtf( 1.0f - A3 ); - } - - return; -} #ifdef IVAS_FLOAT_FIXED - #define SIN_NEG_30_DEGREES_Q15 ( (Word16) 0xC000 ) #define SIN_30_DEGREES_Q15 ( (Word16) 0x4000 ) void ivas_ism_get_stereo_gains_fx( - const Word16 aziDeg, /* i : object azimuth */ - const Word16 eleDeg, /* i : object elevation */ - Word16 *left_gain_fx, /* o : left channel gain */ - Word16 *right_gain_fx /* o : right channel gain */ + const Word16 aziDeg, /* i : object azimuth */ + const Word16 eleDeg, /* i : object elevation */ + Word16 *left_gain_fx, /* o : left channel gain */ + Word16 *right_gain_fx /* o : right channel gain */ ) { /* Convert azi and ele to an azi value of the cone of confusion */ @@ -553,7 +520,7 @@ void ivas_ism_get_stereo_gains_fx( } // sin_az_cos_el = (ptr_sin_az[azAddEl] + ptr_sin_az[azSubEl])/2; Word16 sin_az_cos_el = extract_l( L_shr( L_add( L_deposit_l( ptr_sin_az[azAddEl + 180] ), L_deposit_l( ptr_sin_az[azSubEl + 180] ) ), 1 ) ); - //Word16 sin_az_cos_el = extract_l( L_shr( L_add( L_deposit_l( ptr_sin_az[azAddEl] ), L_deposit_l( ptr_sin_az[azSubEl] ) ), 1 ) ); + // Word16 sin_az_cos_el = extract_l( L_shr( L_add( L_deposit_l( ptr_sin_az[azAddEl] ), L_deposit_l( ptr_sin_az[azSubEl] ) ), 1 ) ); IF( GE_16( sin_az_cos_el, SIN_30_DEGREES_Q15 ) ) { /* Left side */ @@ -575,7 +542,50 @@ void ivas_ism_get_stereo_gains_fx( } *left_gain_fx = gains[0]; + move16(); *right_gain_fx = gains[1]; + move16(); + + return; +} +#else +void ivas_ism_get_stereo_gains( + const float azimuth, /* i : object azimuth */ + const float elevation, /* i : object elevation */ + float *left_gain, /* o : left channel gain */ + float *right_gain /* o : right channel gain */ +) +{ + float aziRad, eleRad; + float y, mappedX, aziRadMapped, A, A2, A3; + const float LsAngleRad = 30.0f * PI_OVER_180; + + /* Convert azi and ele to an azi value of the cone of confusion */ + aziRad = azimuth * PI_OVER_180; + eleRad = elevation * PI_OVER_180; + y = ( sinf( aziRad ) * cosf( eleRad ) ); + mappedX = sqrtf( max( 0.0f, 1.0f - ( y * y ) ) ); + aziRadMapped = atan2f( y, mappedX ); + + /* Determine the amplitude panning gains */ + if ( aziRadMapped >= LsAngleRad ) + { /* Left side */ + *left_gain = 1.0f; + *right_gain = 0.0f; + } + else if ( aziRadMapped <= -LsAngleRad ) + { /* Right side */ + *left_gain = 0.0f; + *right_gain = 1.0f; + } + else /* Tangent panning law */ + { + A = tanf( aziRadMapped ) / tanf( LsAngleRad ); + A2 = ( A - 1.0f ) / max( 0.001f, A + 1.0f ); + A3 = 1.0f / ( A2 * A2 + 1.0f ); + *left_gain = sqrtf( A3 ); + *right_gain = sqrtf( 1.0f - A3 ); + } return; } @@ -710,15 +720,6 @@ ivas_error ivas_omasa_separate_object_renderer_open( } // To be removed later ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - FOR ( i = 0; i < MAX_NUM_OBJECTS; i++ ) - { - set_f( st_ivas->hIsmRendererData->prev_gains[i], 0.0f, MAX_OUTPUT_CHANNELS ); - } - st_ivas->hIsmRendererData->interpolator = (float *) malloc( sizeof( float ) * init_interpolator_length ); - FOR ( i = 0; i < interpolator_length; i++ ) - { - st_ivas->hIsmRendererData->interpolator[i] = (float) i / ( (float) interpolator_length ); - } IF ( ( st_ivas->hMasaIsmData->delayBuffer = (float **) malloc( st_ivas->hMasaIsmData->delayBuffer_nchan * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) ); @@ -928,7 +929,11 @@ void ivas_omasa_separate_object_render_jbm( { for ( k = 0; k < n_samples_sf; k++ ) { +#ifdef IVAS_FLOAT_FIXED + hRendererData->interpolator_fx[k] = div_s( k, n_samples_sf ); +#else hRendererData->interpolator[k] = (float) k / ( (float) n_samples_sf ); +#endif } hRendererData->interpolator_length = n_samples_sf; } @@ -982,16 +987,32 @@ void ivas_omasa_separate_object_render_jbm( j2 = j; } +#ifdef IVAS_FLOAT_FIXED + if ( fabsf( gains[j] ) > 0.0f || fabsf( fix_to_float( hRendererData->prev_gains_fx[obj][j], Q30 ) ) > 0.0f ) +#else if ( fabsf( gains[j] ) > 0.0f || fabsf( hRendererData->prev_gains[obj][j] ) > 0.0f ) +#endif { for ( k = 0; k < n_samples_sf; k++ ) { +#ifdef IVAS_FLOAT_FIXED + g1 = fix16_to_float(hRendererData->interpolator_fx[k],Q15); +#else g1 = hRendererData->interpolator[k]; +#endif g2 = 1.0f - g1; +#ifdef IVAS_FLOAT_FIXED + output_f_local[j2][k + offsetSamples] += ( g1 * gains[j] + g2 * fix_to_float( hRendererData->prev_gains_fx[obj][j], Q30 ) ) * input_f[obj][k + offsetSamples]; +#else output_f_local[j2][k + offsetSamples] += ( g1 * gains[j] + g2 * hRendererData->prev_gains[obj][j] ) * input_f[obj][k + offsetSamples]; +#endif } } +#ifdef IVAS_FLOAT_FIXED + hRendererData->prev_gains_fx[obj][j] = float_to_fix(gains[j], Q30); +#else hRendererData->prev_gains[obj][j] = gains[j]; +#endif } offsetSamples += n_samples_sf; diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index eb93e7a7f1717c9a80dba2711f7a2c043c12edff..ffb4813bba0acc63cb8d634958878306473067b5 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -264,13 +264,8 @@ ivas_error ivas_jbm_dec_tc( st_ivas->hIsmMetaData[ind]->last_true_azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->last_true_azimuth * ( 1 << 22 ) ); st_ivas->hIsmMetaData[ind]->last_true_elevation_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->last_true_elevation * ( 1 << 22 ) ); } - FOR( Word16 ind = 0; ind < st_ivas->nchan_transport; ind++ ) - st_ivas->hSCE[ind]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = (Word16) ( st_ivas->hSCE[ind]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_flt * 32767 ); - IF( st_ivas->hParamIsmDec ) - { - floatToFixed_arrL( st_ivas->hParamIsmDec->azimuth_values, st_ivas->hParamIsmDec->azimuth_values_fx, 22, st_ivas->nchan_ism ); - floatToFixed_arrL( st_ivas->hParamIsmDec->elevation_values, st_ivas->hParamIsmDec->elevation_values_fx, 22, st_ivas->nchan_ism ); - } + //FOR( Word16 ind = 0; ind < st_ivas->nchan_transport; ind++ ) + //st_ivas->hSCE[ind]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = (Word16) ( st_ivas->hSCE[ind]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_flt * 32767 ); FOR( Word16 ch = 0; ch < st_ivas->nchan_ism; ch++ ) { st_ivas->hIsmMetaData[ch]->last_azimuth_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->last_azimuth, 22 ); @@ -288,13 +283,8 @@ ivas_error ivas_jbm_dec_tc( st_ivas->hIsmMetaData[ind]->last_true_azimuth = (float) ( st_ivas->hIsmMetaData[ind]->last_true_azimuth_fx ) / (float) ( 1 << 22 ); st_ivas->hIsmMetaData[ind]->last_true_elevation = (float) ( st_ivas->hIsmMetaData[ind]->last_true_elevation_fx ) / (float) ( 1 << 22 ); } - FOR( Word16 ind = 0; ind < st_ivas->nchan_transport; ind++ ) - st_ivas->hSCE[ind]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_flt = (float) ( st_ivas->hSCE[ind]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx ) / 32767.f; - IF( st_ivas->hParamIsmDec ) - { - fixedToFloat_arrL( st_ivas->hParamIsmDec->azimuth_values_fx, st_ivas->hParamIsmDec->azimuth_values, 22, st_ivas->nchan_ism ); - fixedToFloat_arrL( st_ivas->hParamIsmDec->elevation_values_fx, st_ivas->hParamIsmDec->elevation_values, 22, st_ivas->nchan_ism ); - } + //FOR( Word16 ind = 0; ind < st_ivas->nchan_transport; ind++ ) + //st_ivas->hSCE[ind]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_flt = (float) ( st_ivas->hSCE[ind]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx ) / 32767.f; FOR( Word16 ch = 0; ch < st_ivas->nchan_ism; ch++ ) { st_ivas->hIsmMetaData[ch]->last_azimuth = fixedToFloat( st_ivas->hIsmMetaData[ch]->last_azimuth_fx, 22 ); @@ -309,10 +299,10 @@ ivas_error ivas_jbm_dec_tc( Word32 *output_fx[1]; output_fx[0] = malloc( sizeof( Word32 ) * L_FRAME48k ); set32_fx( output_fx[0], 0, L_FRAME48k ); - for ( int k = 0; k < 45; k++ ) - { - st_ivas->hSCE[st_ivas->hISMDTX.sce_id_dtx]->prev_hb_synth_fx[k] = (Word32) ( st_ivas->hSCE[st_ivas->hISMDTX.sce_id_dtx]->prev_hb_synth[k] * ONE_IN_Q11 ); - } + //for ( int k = 0; k < 45; k++ ) + //{ + // st_ivas->hSCE[st_ivas->hISMDTX.sce_id_dtx]->prev_hb_synth_fx[k] = (Word32) ( st_ivas->hSCE[st_ivas->hISMDTX.sce_id_dtx]->prev_hb_synth[k] * ONE_IN_Q11 ); + //} IF( ( error = ivas_sce_dec_fx( st_ivas, st_ivas->hISMDTX.sce_id_dtx, &output_fx[0], output_frame, nb_bits_metadata[st_ivas->hISMDTX.sce_id_dtx] ) ) != IVAS_ERR_OK ) { @@ -325,8 +315,8 @@ ivas_error ivas_jbm_dec_tc( for ( int k = 0; k < 96; k++ ) { st_ivas->hSCE[st_ivas->hISMDTX.sce_id_dtx]->hCoreCoder[0]->prev_synth_buffer[k] = (float) st_ivas->hSCE[st_ivas->hISMDTX.sce_id_dtx]->hCoreCoder[0]->prev_synth_buffer32_fx[k] / ONE_IN_Q11; - if ( k < 45 ) - st_ivas->hSCE[st_ivas->hISMDTX.sce_id_dtx]->prev_hb_synth[k] = (float) st_ivas->hSCE[st_ivas->hISMDTX.sce_id_dtx]->prev_hb_synth_fx[k] / ONE_IN_Q11; + //if ( k < 45 ) + // st_ivas->hSCE[st_ivas->hISMDTX.sce_id_dtx]->prev_hb_synth[k] = (float) st_ivas->hSCE[st_ivas->hISMDTX.sce_id_dtx]->prev_hb_synth_fx[k] / ONE_IN_Q11; } free( output_fx[0] ); #else @@ -456,10 +446,10 @@ ivas_error ivas_jbm_dec_tc( Word32 *output_fx[1]; output_fx[0] = malloc( sizeof( Word32 ) * L_FRAME48k ); set32_fx( output_fx[0], 0, L_FRAME48k ); - for ( int k = 0; k < 45; k++ ) - { - st_ivas->hSCE[n]->prev_hb_synth_fx[k] = (Word32) ( st_ivas->hSCE[n]->prev_hb_synth[k] * ONE_IN_Q11 ); - } + //for ( int k = 0; k < 45; k++ ) + //{ + // st_ivas->hSCE[n]->prev_hb_synth_fx[k] = (Word32) ( st_ivas->hSCE[n]->prev_hb_synth[k] * ONE_IN_Q11 ); + //} IF( ( error = ivas_sce_dec_fx( st_ivas, n, &output_fx[0], output_frame, nb_bits_metadata[n] ) ) != IVAS_ERR_OK ) { @@ -473,8 +463,8 @@ ivas_error ivas_jbm_dec_tc( for ( int k = 0; k < 96; k++ ) { st_ivas->hSCE[n]->hCoreCoder[0]->prev_synth_buffer[k] = (float) st_ivas->hSCE[n]->hCoreCoder[0]->prev_synth_buffer32_fx[k] / ONE_IN_Q11; - if ( k < 45 ) - st_ivas->hSCE[n]->prev_hb_synth[k] = (float) st_ivas->hSCE[n]->prev_hb_synth_fx[k] / ONE_IN_Q11; + //if ( k < 45 ) + // st_ivas->hSCE[n]->prev_hb_synth[k] = (float) st_ivas->hSCE[n]->prev_hb_synth_fx[k] / ONE_IN_Q11; } free( output_fx[0] ); #else @@ -737,10 +727,10 @@ ivas_error ivas_jbm_dec_tc( output_fx[0] = malloc( sizeof( Word32 ) * L_FRAME48k ); set32_fx( output_fx[0], 0, L_FRAME48k ); - for ( int k = 0; k < 45; k++ ) - { - st_ivas->hSCE[0]->prev_hb_synth_fx[k] = (Word32) ( st_ivas->hSCE[0]->prev_hb_synth[k] * ( 1 << q_output ) ); - } + //for ( int k = 0; k < 45; k++ ) + //{ + // st_ivas->hSCE[0]->prev_hb_synth_fx[k] = (Word32) ( st_ivas->hSCE[0]->prev_hb_synth[k] * ( 1 << q_output ) ); + //} IF( ( error = ivas_sce_dec_fx( st_ivas, 0, &output_fx[0], output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { @@ -754,8 +744,8 @@ ivas_error ivas_jbm_dec_tc( for ( int k = 0; k < 96; k++ ) { st_ivas->hSCE[0]->hCoreCoder[0]->prev_synth_buffer[k] = (float) st_ivas->hSCE[0]->hCoreCoder[0]->prev_synth_buffer32_fx[k] / ( 1 << q_output ); - if ( k < 45 ) - st_ivas->hSCE[0]->prev_hb_synth[k] = (float) st_ivas->hSCE[0]->prev_hb_synth_fx[k] / ( 1 << q_output ); + //if ( k < 45 ) + // st_ivas->hSCE[0]->prev_hb_synth[k] = (float) st_ivas->hSCE[0]->prev_hb_synth_fx[k] / ( 1 << q_output ); } free( output_fx[0] ); } @@ -797,10 +787,524 @@ ivas_error ivas_jbm_dec_tc( #endif // IVAS_FLOAT_FIXED else if ( st_ivas->nCPE > 1 ) { +#ifdef IVAS_FLOAT_FIXED +#if 1 // Float to fix + + Decoder_State *st, **sts; + MCT_DEC_HANDLE hMCT; + CPE_DEC_HANDLE hCPE; + + Word16 ch, nCPE, cpe_id; + Word16 q_output = 11; + Word16 k, l, i, j; + + nCPE = st_ivas->nCPE; + move16(); + hMCT = st_ivas->hMCT; + FOR( i = 0; i < 12; i++ ) + if ( p_output[i] ) + { + p_output_fx[i] = malloc( sizeof( Word32 ) * L_FRAME48k ); + floatToFixed_arrL( p_output[i], p_output_fx[i], Q11, L_FRAME48k ); + } + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + hCPE = st_ivas->hCPE[cpe_id]; + sts = hCPE->hCoreCoder; + + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + st = hCPE->hCoreCoder[n]; + IF( st->hTonalMDCTConc ) + { + + FOR( i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) + { + st->hTonalMDCTConc->scaleFactorsBackground_fx[i] = float_to_fix( st->hTonalMDCTConc->scaleFactorsBackground_flt[i], 15 ); + } + //st->hTonalMDCTConc->scf_fadeout = float_to_fix16( st->hTonalMDCTConc->scf_fadeout_flt, 15 ); + if ( hCPE->hCoreCoder[n]->bfi && st->tonal_mdct_plc_active ) + { + FOR( i = 0; i < FDNS_NPTS; i++ ) + { + f2me_16( st->hTonalMDCTConc->secondLastBlockData.scaleFactors_float[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ); + } + FOR( i = 0; i < 30; i++ ) + { + float pd = st->hTonalMDCTConc->pTCI->phaseDiff_float[i]; + if ( pd >= PI2 ) + pd = fmodf( pd, PI2 ) - PI2; + st->hTonalMDCTConc->pTCI->phaseDiff[i] = (Word16) floatToFixed( pd, Q12 ); + } + FOR( i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++ ) + { + float pd = st->hTonalMDCTConc->pTCI->phase_currentFramePredicted_float[i]; + pd = fmodf( pd, PI2 ); + st->hTonalMDCTConc->pTCI->phase_currentFramePredicted[i] = (Word16) ( pd * ( 1u << Q13 ) ); + } + } + //f2me( st->hTonalMDCTConc->last_block_nrg_flt, &st->hTonalMDCTConc->last_block_nrg, &st->hTonalMDCTConc->last_block_nrg_exp ); + } + // st->old_fpitch = float_to_fix(st->old_fpitch_float, 16); + st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); + + IF( sts[n]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) + { + // u8bit to 16bit + FOR( l = 0; l < IGF_START_MX; l++ ) + { + sts[n]->hIGFDec->infoTCXNoise_evs[l] = (Word16) sts[n]->hIGFDec->infoTCXNoise[l]; + } + } + + + IF( st->hTcxDec ) + f2me_16( st->hTcxDec->CngLevelBackgroundTrace_bfi, &st->hTcxDec->conCngLevelBackgroundTrace, &st->hTcxDec->conCngLevelBackgroundTrace_e ); + if ( st->hTcxDec && st->hTcxDec->conLastFrameLevel_e < 0 ) + { + st->hTcxDec->conLastFrameLevel_e = 0; + } + if ( st->hTcxDec && st->hTcxDec->conNoiseLevelMemory_e[0] < 0 ) + { + set16_fx( st->hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); + } + IF( st->hTcxDec ) + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + IF( st->hTcxDec ) + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + IF( st->hTcxDec ) + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hTcxDec->old_excFB_fx[p] = (Word16) ( st->hTcxDec->old_excFB[p] * ( 1u << st->Q_exc ) ); + } + IF( st->hFdCngDec && st->hFdCngDec->hFdCngCom ) + floatToFixed_arr( st->hFdCngDec->hFdCngCom->A_cng_flt, st->hFdCngDec->hFdCngCom->A_cng, 15, 17 ); + // st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15); + + IF( hCPE->hCoreCoder[n]->hTcxLtpDec ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float, hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32, q_output, L_FRAME48k ); + floatToFixed_arrL( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float, hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32, q_output, TCXLTP_MAX_DELAY ); + floatToFixed_arrL( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, Q11, 111 ); + } + + + /*cldfb struct*/ + + /*------------------fix-to-fix-start---------------------*/ + /*core_switching_post_dec*/ + if ( hCPE->hCoreCoder[n]->hHQ_core != NULL ) + { + hCPE->hCoreCoder[n]->hHQ_core->Q_old_postdec = 0; + hCPE->hCoreCoder[n]->hHQ_core->Q_old_wtda = 0; + } + /*-------------------cldfb-start-------------------------*/ + + floatToFixed_arrL( hCPE->hCoreCoder[n]->bpf_noise_buf_float, hCPE->hCoreCoder[n]->bpf_noise_buf_32, 11, L_FRAME_16k ); + if ( hCPE->hCoreCoder[n]->cldfbAna != NULL ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->cldfbAna->cldfb_state, hCPE->hCoreCoder[n]->cldfbAna->cldfb_state_fx, 10, hCPE->hCoreCoder[n]->cldfbAna->cldfb_size ); + } + if ( hCPE->hCoreCoder[n]->cldfbSyn != NULL ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->cldfbSyn->cldfb_state, hCPE->hCoreCoder[n]->cldfbSyn->cldfb_state_fx, 4, hCPE->hCoreCoder[n]->cldfbSyn->p_filter_length ); + } + if ( hCPE->hCoreCoder[n]->cldfbBPF != NULL ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->cldfbBPF->cldfb_state, hCPE->hCoreCoder[n]->cldfbBPF->cldfb_state_fx, 11, hCPE->hCoreCoder[n]->cldfbBPF->cldfb_size ); + } + + + /*-------------------cldfb-end---------------------------*/ + + floatToFixed_arr( sts[n]->prev_synth_buffer, hCPE->hCoreCoder[n]->prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); + } + + IF( hCPE->output_mem[0] != NULL ) + { + floatToFixed_arrL( hCPE->output_mem[0], hCPE->output_mem_fx[0], Q11, NS2SA( hCPE->hCoreCoder[0]->output_Fs, 3125000 ) ); + } + IF( hCPE->output_mem[1] != NULL ) + { + floatToFixed_arrL( hCPE->output_mem[1], hCPE->output_mem_fx[1], Q11, NS2SA( hCPE->hCoreCoder[0]->output_Fs, 3125000 ) ); + } + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + + IF( hCPE->hStereoDft != NULL ) + { + IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) + { + FOR( Word32 p = 0; p < L_FRAME48k; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << q_output ) ); + } + FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q_output ) ); + } + } + } + + IF( hCPE->input_mem_LB[n] != NULL ) + { + FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) + { + hCPE->input_mem_LB_fx[n][ind] = (Word32) ( hCPE->input_mem_LB[n][ind] * ( 1 << q_output ) ); + } + } + + //FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) + //{ + // hCPE->prev_hb_synth_fx[n][k] = (Word32) ( hCPE->prev_hb_synth[n][k] * ( 1 << q_output ) ); + //} + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->prev_synth_fx[n][k] = (Word32) ( hCPE->prev_synth[n][k] * ( 1 << q_output ) ); + } + } + } + + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->targetEnergyPrev ) + f2me_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->dmxEnergyPrev ) + f2me_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); + IF( st_ivas->hParamMC && st_ivas->hParamMC->icld_q ) + floatToFixed_arr16( st_ivas->hParamMC->icld_q, st_ivas->hParamMC->icld_q_fx, 8, st_ivas->hParamMC->hMetadataPMC->num_parameter_bands * st_ivas->hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); + IF( st_ivas->hParamMC && st_ivas->hParamMC->ls_conv_dmx_matrix ) + floatToFixed_arr32( st_ivas->hParamMC->ls_conv_dmx_matrix, st_ivas->hParamMC->ls_conv_dmx_matrix_fx, 15, st_ivas->hDecoderConfig->nchan_out * ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) ); + IF( st_ivas->hLsSetUpConversion ) + FOR( Word16 chOutIdx = 0; chOutIdx < st_ivas->hDecoderConfig->nchan_out; chOutIdx++ ) + { + FOR( Word16 chInIdx = 0; chInIdx < st_ivas->nchan_transport; chInIdx++ ) + { + st_ivas->hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx] = float_to_fix( st_ivas->hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx], 30 ); /*Q30*/ + } + } + + +#endif // Float to fix + if ( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } +#if 1 // Fix to float + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + hCPE = st_ivas->hCPE[cpe_id]; + sts = hCPE->hCoreCoder; + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + st = hCPE->hCoreCoder[ch]; + st->hTcxDec->tcxltp_last_gain_unmodified_float = fixedToFloat(st->hTcxLtpDec->tcxltp_gain, 15); + //st->hTcxDec->tcxltp_last_gain_unmodified_float = st->hTcxLtpDec->tcxltp_gain_float; + IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) + { + // 16bit to u8bit + FOR( l = 0; l < IGF_START_MX; l++ ) + { + sts[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t) sts[ch]->hIGFDec->infoTCXNoise_evs[l]; + } + IF( !sts[0]->bfi || ( sts[0]->bfi && sts[ch]->core != ACELP_CORE ) ) + { + me2f_buf( sts[ch]->hIGFDec->virtualSpec, sts[ch]->hIGFDec->virtualSpec_e, sts[ch]->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); + } + } + IF( st->hTonalMDCTConc != NULL ) + { + //st->hTonalMDCTConc->scf_fadeout_flt = fixedToFloat( st->hTonalMDCTConc->scf_fadeout, 15 ); + //st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); + if ( hCPE->hCoreCoder[ch]->bfi && st->tonal_mdct_plc_active ) + { + //st->hTonalMDCTConc->nFramesLost_float = fix16_to_float( st->hTonalMDCTConc->nFramesLost, Q1 ); + } + } + + if ( sts[ch]->last_core != -1 && sts[ch]->nbLostCmpt == 1 ) + { + if ( !( sts[ch]->rf_flag && sts[ch]->use_partial_copy && ( sts[ch]->rf_frame_type == RF_TCXTD1 || sts[ch]->rf_frame_type == RF_TCXTD2 ) ) ) + { + IF( sts[ch]->hTonalMDCTConc != NULL && sts[ch]->last_core == TCX_20_CORE && sts[ch]->second_last_core == TCX_20_CORE && ( ( sts[ch]->old_fpitch <= L_shl( sts[ch]->L_frame, 15 ) ) || ( sts[ch]->hTcxDec->tcxltp_last_gain_unmodified <= 13107 /*0.4f*/ ) ) + /* it is fine to call the detection even if no ltp information + is available, meaning that st->old_fpitch == + st->tcxltp_second_last_pitch == st->L_frame */ + && ( sts[ch]->old_fpitch == sts[ch]->hTcxDec->tcxltp_second_last_pitch ) && !sts[ch]->last_tns_active && !sts[ch]->second_last_tns_active ) + { + + if ( sts[ch]->hTonalMDCTConc->pTCI->numIndexes < MAX_NUMBER_OF_IDX ) + { + FOR( i = 0; i < sts[ch]->hTonalMDCTConc->pTCI->numIndexes; i++ ) + { + sts[ch]->hTonalMDCTConc->pTCI->phaseDiff_float[i] = fixedToFloat( sts[ch]->hTonalMDCTConc->pTCI->phaseDiff[i], Q12 ); + } + FOR( i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++ ) + { + sts[ch]->hTonalMDCTConc->pTCI->phase_currentFramePredicted_float[i] = fixedToFloat( sts[ch]->hTonalMDCTConc->pTCI->phase_currentFramePredicted[i], Q13 ); + } + } + } + } + } + } + + FOR( n = 0; n < 2; n++ ) + { + st = hCPE->hCoreCoder[n]; + sts = hCPE->hCoreCoder; + IF( st->hTcxDec ) + st->hTcxDec->CngLevelBackgroundTrace_bfi = me2f_16( st->hTcxDec->conCngLevelBackgroundTrace, st->hTcxDec->conCngLevelBackgroundTrace_e ); + IF( st->hTonalMDCTConc && st->hTonalMDCTConc->lastPcmOut_float ) + fixedToFloat_arr( st->hTonalMDCTConc->lastPcmOut, st->hTonalMDCTConc->lastPcmOut_float, 0, st->hTonalMDCTConc->nSamples ); + IF( sts[0]->bfi == 0 && !st->hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive ) + fixedToFloat_arr( st->hTonalMDCTConc->secondLastPcmOut, st->hTonalMDCTConc->secondLastPcmOut_float, 0, st->hTonalMDCTConc->nSamples / 2 ); + fixedToFloat_arr( st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synthFB, st->Q_syn, st->hTcxDec->old_synth_lenFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + fixedToFloat_arr( st->hTcxDec->old_synth, st->hTcxDec->old_synth_float, st->Q_syn, 1280 ); + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hTcxDec->old_excFB[p] = (float) ( st->hTcxDec->old_excFB_fx[p] ) / ( 1u << st->Q_exc ); + } + // st->preemph_fac_float = (float)st->preemph_fac / MAX_16; + // st->lp_gainc = (float)st->Mode2_lp_gainc / ONE_IN_Q16; + // st->lp_gainp = (float)st->Mode2_lp_gainp / ONE_IN_Q29; + // st->cummulative_damping_float = (float)st->cummulative_damping / MAX_16; + // st->old_enr_LP_float = (float)st->old_enr_LP / ONE_IN_Q3; + for ( int p = 0; p < st->L_frame / 2; p++ ) + { + st->hTcxDec->old_syn_Overl_float[p] = (float) st->hTcxDec->old_syn_Overl[p] * 2 * ( 1u << st->Q_syn ); + st->hTcxDec->syn_Overl_TDACFB_float[p] = (float) st->hTcxDec->syn_Overl_TDACFB[p] * 2 * (float) pow( 2, st->Q_syn ); + st->hTcxDec->syn_Overl_TDAC_float[p] = (float) st->hTcxDec->syn_Overl_TDAC[p] * 2 * (float) pow( 2, st->Q_syn ); + } + for ( int p = 0; p < 640; p++ ) + { + st->hHQ_core->old_outLB[p] = (float) st->hHQ_core->old_out_LB_fx[p] / ( 1u << st->Q_syn ); + } + + if ( !st->tcxonly ) + { + fixedToFloat_arr( st->p_bpf_noise_buf, st->p_bpf_noise_buf_float, 0, L_FRAME_16k ); + } + + fixedToFloat_arr( st->hTcxDec->syn_OverlFB, st->hTcxDec->syn_OverlFB_float, st->Q_syn, L_FRAME_MAX / 2 ); + fixedToFloat_arr( st->hTcxDec->syn_Overl, st->hTcxDec->syn_Overl_float, st->Q_syn, L_FRAME32k / 2 ); + st->hTcxDec->tcxltp_last_gain_unmodified_float = fix16_to_float( st->hTcxDec->tcxltp_last_gain_unmodified, Q15 ); + st->hTcxDec->conceal_eof_gain_float = fix16_to_float( st->hTcxDec->conceal_eof_gain, Q14 ); + + /*-------------------cldfb-start-------------------------*/ + + /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ + + if ( sts[n]->cldfbAna != NULL ) + { + fixedToFloat_arrL( sts[n]->cldfbAna->cldfb_state_fx, sts[n]->cldfbAna->cldfb_state, 10, sts[n]->cldfbAna->cldfb_state_length ); + } + if ( sts[n]->cldfbSyn != NULL ) + { + fixedToFloat_arrL( sts[n]->cldfbSyn->cldfb_state_fx, sts[n]->cldfbSyn->cldfb_state, 4, sts[n]->cldfbSyn->p_filter_length ); + } + if ( sts[n]->cldfbBPF != NULL ) + { + fixedToFloat_arrL( sts[n]->cldfbBPF->cldfb_state_fx, sts[n]->cldfbBPF->cldfb_state, 11, sts[n]->cldfbBPF->cldfb_state_length ); + } + + /*-------------------cldfb-end---------------------------*/ + + IF( sts[n]->hHQ_core != NULL ) + { + fixedToFloat_arr( sts[n]->hHQ_core->old_out_fx, sts[n]->hHQ_core->old_out, 0, L_FRAME48k ); + } + + + /*------------------reset-code-start---------------------*/ + + /*reset function flags*/ + Word8 reset_wb_tbe_synth = 0; + Word8 reset_swb_tbe = 0; + + /* reset WB BWE buffers */ + + IF( NE_16( sts[n]->last_extl, WB_BWE ) && EQ_16( sts[n]->extl, WB_BWE ) && sts[n]->hBWE_FD != NULL ) + { + + IF( NE_16( sts[n]->last_extl, SWB_BWE ) && NE_16( sts[n]->last_extl, FB_BWE ) ) + { + sts[n]->hBWE_FD->prev_mode = sts[n]->hBWE_FD->prev_mode; + } + sts[n]->hBWE_FD->prev_L_swb_norm = sts[n]->hBWE_FD->prev_L_swb_norm; + sts[n]->hBWE_FD->prev_flag = sts[n]->hBWE_FD->prev_flag; + } + + /* reset TBE buffers */ + if ( sts[n]->hBWE_TD != NULL ) + { + IF( ( ( EQ_16( sts[n]->extl, SWB_TBE ) || EQ_16( sts[n]->extl, FB_TBE ) || EQ_16( sts[n]->extl, SWB_CNG ) ) && + ( NE_16( sts[n]->L_frame, sts[n]->last_L_frame ) || ( NE_16( sts[n]->last_extl, SWB_TBE ) && NE_16( sts[n]->last_extl, FB_TBE ) ) || EQ_16( sts[n]->last_core, HQ_CORE ) ) ) || + ( LT_16( sts[n]->bwidth, sts[n]->last_bwidth ) && NE_16( sts[n]->last_extl, SWB_TBE ) ) || sts[n]->old_ppp_mode || ( ( EQ_16( sts[n]->prev_coder_type, AUDIO ) || EQ_16( sts[n]->prev_coder_type, INACTIVE ) ) && sts[n]->bws_cnt > 0 ) || ( sts[n]->bws_cnt == 0 && EQ_16( sts[n]->prev_bws_cnt, N_WS2N_FRAMES ) ) ) + { + + reset_swb_tbe = 1; + + IF( EQ_16( output_frame, L_FRAME16k ) ) + { + fixedToFloat_arr( sts[n]->hBWE_TD->mem_resamp_HB_32k_fx, sts[n]->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + } + fixedToFloat_arr( sts[n]->hBWE_TD->int_3_over_2_tbemem_dec_fx, sts[n]->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN ); + } + ELSE IF( sts[n]->hBWE_TD != NULL && ( sts[n]->last_core == TCX_20_CORE || sts[n]->last_core == TCX_10_CORE ) ) + { + /*------------TBEreset_dec_ivas_fx-start------------------*/ + IF( EQ_16( sts[n]->bwidth, WB ) ) + { + reset_wb_tbe_synth = 1; + + fixedToFloat_arr( sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); + } + ELSE IF( EQ_16( sts[n]->bwidth, SWB ) || EQ_16( sts[n]->bwidth, FB ) ) + { + reset_swb_tbe = 1; + fixedToFloat_arr( sts[n]->hBWE_TD->int_3_over_2_tbemem_dec_fx, sts[n]->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN ); // setting to zero + fixedToFloat_arr( sts[n]->hBWE_TD->mem_resamp_HB_32k_fx, sts[n]->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); // setting to zero + } + /*------------TBEreset_dec_ivas_fx-end--------------------*/ + } + + IF( NE_16( sts[n]->last_extl, WB_TBE ) && EQ_16( sts[n]->extl, WB_TBE ) ) + { + reset_wb_tbe_synth = 1; + fixedToFloat_arr( sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); // setting to zero + } + + IF( reset_swb_tbe ) + { + fixedToFloat_arr( sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); // setting to zero + } + IF( reset_wb_tbe_synth ) + { + fixedToFloat_arr( sts[n]->hBWE_TD->state_lsyn_filt_shb_fx, sts[n]->hBWE_TD->state_lsyn_filt_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); // setting to zero + fixedToFloat_arr( sts[n]->hBWE_TD->state_lsyn_filt_dwn_shb_fx, sts[n]->hBWE_TD->state_lsyn_filt_dwn_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); // setting to zero + fixedToFloat_arr( sts[n]->hBWE_TD->mem_resamp_HB_fx, sts[n]->hBWE_TD->mem_resamp_HB, 0, INTERP_3_1_MEM_LEN ); // setting to zero + } + } + + /*------------------reset-code-end-----------------------*/ + + + for ( int p = 0; p < L_FRAME48k; p++ ) + { + + IF( hCPE->hCoreCoder[n]->hTcxLtpDec ) + { + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q_output ); + if ( p < TCXLTP_MAX_DELAY ) + { + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q_output ); + } + } + } + if ( hCPE->hCoreCoder[n]->hTcxDec ) + { + for ( k = 0; k < 111; k++ ) + { + hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ( 1u << q_output ); + } + } + IF( hCPE->hCoreCoder[n]->hTcxLtpDec ) + + if ( ( hCPE->hCoreCoder[n]->codec_mode == MODE1 && hCPE->hCoreCoder[n]->hTcxDec != NULL ) && ( ( hCPE->hCoreCoder[n]->core == ACELP_CORE && !( hCPE->hCoreCoder[n]->bfi == 1 && hCPE->hCoreCoder[n]->con_tcx == 1 ) ) || hCPE->hCoreCoder[n]->core == HQ_CORE ) ) + { + fixedToFloat_arr( hCPE->hCoreCoder[n]->hTcxDec->synth_history_fx, hCPE->hCoreCoder[n]->hTcxDec->synth_history, 0, output_frame ); + } + } + + IF( hCPE->hStereoDft != NULL ) + { + IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) + { + FOR( Word32 p = 0; p < L_FRAME48k; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q_output ); + } + FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q_output ); + } + } + } + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + IF( hCPE->output_mem[n] != NULL ) + { + FOR( k = 0; k < NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->output_mem[n][k] = (float) hCPE->output_mem_fx[n][k] / ( 1u << 11 ); + } + } + IF( hCPE->hCoreCoder[n] != NULL ) + { + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) + { + hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << q_output ); + } + } + IF( hCPE->input_mem[n] != NULL ) + { + FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) + { + hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << q_output ) ); + } + } + //FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) + //{ + // hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << q_output ); + //} + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << q_output ); + } + } + } + + + IF( st_ivas->hCPE[0]->hCoreCoder[0]->igf ) + { + IF( !hMCT->currBlockDataCnt ) + { + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + IF( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->igf ) + { + me2f_buf( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec_e, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); + FOR( l = 0; l < IGF_START_MX; l++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t) st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise_evs[l]; + } + } + } + } + } + } + + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->targetEnergyPrev ) + me2f_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx ) + me2f_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); + + FOR( i = 0; i < 12; i++ ) + if ( p_output[i] ) + { + fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, L_FRAME48k ); + free( p_output_fx[i] ); + } +#endif // Fix to float +#else if ( ( error = ivas_mct_dec( st_ivas, p_output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } +#endif } /* TCs remapping */ @@ -1004,13 +1508,10 @@ ivas_error ivas_jbm_dec_tc( hCPE->hStereoDft->q_smoothed_nrg = Q6;//hCPE->hStereoDft->q_dft; hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft; } - st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact, 15); + // st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact, 15); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact, 15); - floatToFixed_arrL(&hCPE->hStereoDft->res_gains_ind[0][0], &hCPE->hStereoDft->res_gains_ind_fx[0][0], Q26, sizeof(hCPE->hStereoDft->res_gains_ind_fx) / sizeof(hCPE->hStereoDft->res_gains_ind_fx[0][0])); - floatToFixed_arrL(&hCPE->hStereoDft->res_pred_gain[0], &hCPE->hStereoDft->res_pred_gain_fx[0], Q31, sizeof(hCPE->hStereoDft->res_pred_gain_fx)/ sizeof(hCPE->hStereoDft->res_pred_gain_fx[0])); - floatToFixed_arrL(&hCPE->hStereoDft->itd[0], &hCPE->hStereoDft->itd_fx[0], Q1, sizeof(hCPE->hStereoDft->itd_fx) / sizeof(hCPE->hStereoDft->itd_fx[0])); floatToFixed_arrL(&st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0], st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->q_smoothed_psd, sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx) / sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0])); - floatToFixed_arrL(&hCPE->prev_hb_synth[0][0], &hCPE->prev_hb_synth_fx[0][0], hCPE->hStereoDft->q_dft, sizeof(hCPE->prev_hb_synth_fx) / sizeof(hCPE->prev_hb_synth_fx[0][0])); + //floatToFixed_arrL(&hCPE->prev_hb_synth[0][0], &hCPE->prev_hb_synth_fx[0][0], hCPE->hStereoDft->q_dft, sizeof(hCPE->prev_hb_synth_fx) / sizeof(hCPE->prev_hb_synth_fx[0][0])); for (int ii = 0; ii < sizeof(hCPE->hStereoDft->hb_nrg_subr_fx) / sizeof(hCPE->hStereoDft->hb_nrg_subr_fx[0]); ii++) { if ( l_hb_nrg_subr < hCPE->hStereoDft->hb_nrg_subr[ii] ) @@ -1046,15 +1547,12 @@ ivas_error ivas_jbm_dec_tc( hCPE->hStereoDft->hb_nrg_fx[ii] = (Word32)(hCPE->hStereoDft->hb_nrg[ii] * ((float)(1 << hCPE->hStereoDft->q_hb_nrg))); } - floatToFixed_arrL( &hCPE->hStereoDft->side_gain[0], &hCPE->hStereoDft->side_gain_fx[0], Q31, sizeof( hCPE->hStereoDft->side_gain_fx ) / sizeof( hCPE->hStereoDft->side_gain_fx[0] ) ); - floatToFixed_arrL( &hCPE->hStereoDft->gipd[0], &hCPE->hStereoDft->gipd_fx[0], Q13, sizeof( hCPE->hStereoDft->gipd_fx ) / sizeof( hCPE->hStereoDft->gipd_fx[0] ) ); - floatToFixed_arr( &hCPE->hStereoDft->g_state[0], &hCPE->hStereoDft->g_state_fx[0], Q15, sizeof( hCPE->hStereoDft->g_state_fx ) / sizeof( hCPE->hStereoDft->g_state_fx[0] ) ); - floatToFixed_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0] ) ); + //floatToFixed_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0] ) ); IF( hCPE->hStereoCng != NULL ) { floatToFixed_arr( &hCPE->hStereoCng->cm[0], &hCPE->hStereoCng->cm_fx[0], Q15, sizeof( hCPE->hStereoCng->cm_fx ) / sizeof( hCPE->hStereoCng->cm_fx[0] ) ); } - floatToFixed_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0] ) ); + //floatToFixed_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0] ) ); for ( int ii = 0; ii < 2; ii++ ) { floatToFixed_arrL( &p_output[ii][0], &p_output_fix[ii][0], hCPE->hStereoDft->q_dft, ( 48000 / FRAMES_PER_SEC ) ); @@ -1067,8 +1565,8 @@ ivas_error ivas_jbm_dec_tc( floatToFixed_arrL(&hCPE->input_mem_LB[1][0], &hCPE->input_mem_LB_fx[1][0], q, STEREO_DFT32MS_OVL_16k); if (hSCE != NULL) { - floatToFixed_arrL(&hSCE->prev_hb_synth[0], &hSCE->prev_hb_synth_fx[0], hCPE->hStereoDft->q_dft, sizeof(hSCE->prev_hb_synth_fx) / sizeof(hSCE->prev_hb_synth_fx[0])); - hSCE->q_prev_hb_synth_fx = hCPE->hStereoDft->q_dft; + //floatToFixed_arrL(&hSCE->prev_hb_synth[0], &hSCE->prev_hb_synth_fx[0], hCPE->hStereoDft->q_dft, sizeof(hSCE->prev_hb_synth_fx) / sizeof(hSCE->prev_hb_synth_fx[0])); + //hSCE->q_prev_hb_synth_fx = hCPE->hStereoDft->q_dft; floatToFixed_arrL(&hSCE->save_hb_synth[0], &hSCE->save_hb_synth_fx[0], q, (Word16)(hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC)); hSCE->q_save_hb_synth_fx = q; floatToFixed_arrL(&hSCE->save_synth[0], &hSCE->save_synth_fx[0], q, (Word16)(hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC)); @@ -1103,7 +1601,7 @@ ivas_error ivas_jbm_dec_tc( st_ivas->hSpar->hMdDec->mix_mat_dim_2); } } - hCPE->lt_es_em_fx = floatToFixed(hCPE->lt_es_em, Q15); + //hCPE->lt_es_em_fx = floatToFixed(hCPE->lt_es_em, Q15); for (int ii = 0; ii < CPE_CHANNELS; ii++) { hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; @@ -1113,17 +1611,9 @@ ivas_error ivas_jbm_dec_tc( ivas_sba_dirac_stereo_dec_fx( st_ivas, p_output_fix, output_frame, st_ivas->ivas_format == MC_FORMAT ); - IF (hSCE != NULL) - { - hSCE->hCoreCoder[0]->log_energy_diff_lt = fixedToFloat(hSCE->hCoreCoder[0]->log_energy_diff_lt_fx, Q15); - hSCE->hCoreCoder[0]->stab_fac_smooth_lt = fixedToFloat(hSCE->hCoreCoder[0]->stab_fac_smooth_lt_fx, Q15); - } fixedToFloat_arrL(&hCPE->prev_synth_fx[0][0], &hCPE->prev_synth[0][0], hCPE->q_prev_synth_fx, sizeof(hCPE->prev_synth) / sizeof(hCPE->prev_synth[0][0])); - st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact = fixedToFloat( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx, 15 ); + // st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact = fixedToFloat( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx, 15 ); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact = fixedToFloat( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact_fx, 15 ); - fixedToFloat_arrL( &hCPE->hStereoDft->res_gains_ind_fx[0][0], &hCPE->hStereoDft->res_gains_ind[0][0], Q26, sizeof( hCPE->hStereoDft->res_gains_ind_fx ) / sizeof( hCPE->hStereoDft->res_gains_ind_fx[0][0] ) ); - fixedToFloat_arrL( &hCPE->hStereoDft->res_pred_gain_fx[0], &hCPE->hStereoDft->res_pred_gain[0], Q31, sizeof( hCPE->hStereoDft->res_pred_gain_fx ) / sizeof( hCPE->hStereoDft->res_pred_gain_fx[0] ) ); - fixedToFloat_arrL( &hCPE->hStereoDft->itd_fx[0], &hCPE->hStereoDft->itd[0], Q1, sizeof( hCPE->hStereoDft->itd_fx ) / sizeof( hCPE->hStereoDft->itd_fx[0] ) ); fixedToFloat_arrL( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd[0], st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->q_smoothed_psd, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0] ) ); for ( int ii = 0; ii < sizeof( hCPE->hStereoDft->hb_nrg_subr_fx ) / sizeof( hCPE->hStereoDft->hb_nrg_subr_fx[0] ); ii++ ) { @@ -1133,16 +1623,13 @@ ivas_error ivas_jbm_dec_tc( { hCPE->hStereoDft->hb_nrg[ii] = ( (float) hCPE->hStereoDft->hb_nrg_fx[ii] * ( (float) ( 1 << hCPE->hStereoDft->q_hb_nrg ) ) ); } - fixedToFloat_arrL(&hCPE->hStereoDft->side_gain_fx[0], &hCPE->hStereoDft->side_gain[0], Q31,sizeof(hCPE->hStereoDft->side_gain_fx) / sizeof(hCPE->hStereoDft->side_gain_fx[0])); - fixedToFloat_arrL(&hCPE->hStereoDft->gipd_fx[0], &hCPE->hStereoDft->gipd[0], Q13, sizeof(hCPE->hStereoDft->gipd_fx) / sizeof(hCPE->hStereoDft->gipd_fx[0])); - fixedToFloat_arr(&hCPE->hStereoDft->g_state_fx[0], &hCPE->hStereoDft->g_state[0], Q15, sizeof(hCPE->hStereoDft->g_state_fx) / sizeof(hCPE->hStereoDft->g_state_fx[0])); - fixedToFloat_arr(&st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm[0], Q15, sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx) / sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0])); - fixedToFloat_arrL(&hCPE->prev_hb_synth_fx[0][0], &hCPE->prev_hb_synth[0][0], hCPE->hStereoDft->q_dft, sizeof(hCPE->prev_hb_synth_fx) / sizeof(hCPE->prev_hb_synth_fx[0][0])); + //fixedToFloat_arr(&st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm[0], Q15, sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx) / sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0])); + //fixedToFloat_arrL(&hCPE->prev_hb_synth_fx[0][0], &hCPE->prev_hb_synth[0][0], hCPE->hStereoDft->q_dft, sizeof(hCPE->prev_hb_synth_fx) / sizeof(hCPE->prev_hb_synth_fx[0][0])); IF (hCPE->hStereoCng != NULL) { fixedToFloat_arr( &hCPE->hStereoCng->cm_fx[0], &hCPE->hStereoCng->cm[0], Q15, sizeof( hCPE->hStereoCng->cm_fx ) / sizeof( hCPE->hStereoCng->cm_fx[0] ) ); } - fixedToFloat_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0] ) ); + //fixedToFloat_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0] ) ); for ( int ii = 0; ii < 2; ii++ ) { fixedToFloat_arrL( &p_output_fix[ii][0], &p_output[ii][0], hCPE->hStereoDft->q_dft, ( 48000 / FRAMES_PER_SEC ) ); @@ -1154,7 +1641,7 @@ ivas_error ivas_jbm_dec_tc( fixedToFloat_arrL(&hCPE->input_mem_LB_fx[1][0], &hCPE->input_mem_LB[1][0], q, STEREO_DFT32MS_OVL_16k); if (hSCE != NULL) { - fixedToFloat_arrL(&hSCE->prev_hb_synth_fx[0], &hSCE->prev_hb_synth[0], hCPE->hStereoDft->q_dft, sizeof(hSCE->prev_hb_synth_fx) / sizeof(hSCE->prev_hb_synth_fx[0])); + //fixedToFloat_arrL(&hSCE->prev_hb_synth_fx[0], &hSCE->prev_hb_synth[0], hCPE->hStereoDft->q_dft, sizeof(hSCE->prev_hb_synth_fx) / sizeof(hSCE->prev_hb_synth_fx[0])); fixedToFloat_arrL(&hSCE->save_synth_fx[0], &hSCE->save_synth[0], q, (Word16)(hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC)); fixedToFloat_arrL(&hSCE->save_hb_synth_fx[0], &hSCE->save_hb_synth[0], q, (Word16)(hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC)); } @@ -1189,7 +1676,7 @@ ivas_error ivas_jbm_dec_tc( { fixedToFloat_arrL(&hCPE->output_mem_fx[ii][0], &hCPE->output_mem[ii][0], hCPE->hStereoDft->q_dft, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS )); } - hCPE->lt_es_em = fixedToFloat(hCPE->lt_es_em_fx, Q15); + //hCPE->lt_es_em = fixedToFloat(hCPE->lt_es_em_fx, Q15); } #endif } @@ -1547,10 +2034,10 @@ ivas_error ivas_jbm_dec_tc( FOR( n = 0; n < tmp_nchan_ism; n++ ) { set32_fx( output_fx[n], 0, L_FRAME48k ); - FOR( int k = 0; k < 45; k++ ) - { - st_ivas->hSCE[n]->prev_hb_synth_fx[k] = (Word32) ( st_ivas->hSCE[n]->prev_hb_synth[k] * ONE_IN_Q11 ); - } + //FOR( int k = 0; k < 45; k++ ) + //{ + // st_ivas->hSCE[n]->prev_hb_synth_fx[k] = (Word32) ( st_ivas->hSCE[n]->prev_hb_synth[k] * ONE_IN_Q11 ); + //} } ///////////////////////////////////// Float to fix conversion ends here. /////////////////////////////////// @@ -1710,8 +2197,8 @@ ivas_error ivas_jbm_dec_tc( FOR( int k = 0; k < 96; k++ ) { st_ivas->hSCE[n]->hCoreCoder[0]->prev_synth_buffer[k] = (float) st_ivas->hSCE[n]->hCoreCoder[0]->prev_synth_buffer32_fx[k] / ONE_IN_Q11; - IF( k < 45 ) - st_ivas->hSCE[n]->prev_hb_synth[k] = (float) st_ivas->hSCE[n]->prev_hb_synth_fx[k] / ONE_IN_Q11; + //IF( k < 45 ) + // st_ivas->hSCE[n]->prev_hb_synth[k] = (float) st_ivas->hSCE[n]->prev_hb_synth_fx[k] / ONE_IN_Q11; } } FOR( n = 0; n < s_max( getNumChanSynthesis( st_ivas ), nchan_transport_ism + st_ivas->nchan_transport ); n++ ) @@ -1835,10 +2322,10 @@ ivas_error ivas_jbm_dec_tc( { output_fx[0] = malloc( sizeof( Word32 ) * L_FRAME48k ); set32_fx( output_fx[0], 0, L_FRAME48k ); - for ( int k = 0; k < 45; k++ ) - { - st_ivas->hSCE[0]->prev_hb_synth_fx[k] = (Word32) ( st_ivas->hSCE[0]->prev_hb_synth[k] * ( 1 << q_output ) ); - } + //for ( int k = 0; k < 45; k++ ) + //{ + // st_ivas->hSCE[0]->prev_hb_synth_fx[k] = (Word32) ( st_ivas->hSCE[0]->prev_hb_synth[k] * ( 1 << q_output ) ); + //} IF( ( error = ivas_sce_dec_fx( st_ivas, 0, &output_fx[0], output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) { @@ -1852,8 +2339,8 @@ ivas_error ivas_jbm_dec_tc( for ( int k = 0; k < 96; k++ ) { st_ivas->hSCE[0]->hCoreCoder[0]->prev_synth_buffer[k] = (float) st_ivas->hSCE[0]->hCoreCoder[0]->prev_synth_buffer32_fx[k] / ( 1 << q_output ); - if ( k < 45 ) - st_ivas->hSCE[0]->prev_hb_synth[k] = (float) st_ivas->hSCE[0]->prev_hb_synth_fx[k] / ( 1 << q_output ); + //if ( k < 45 ) + // st_ivas->hSCE[0]->prev_hb_synth[k] = (float) st_ivas->hSCE[0]->prev_hb_synth_fx[k] / ( 1 << q_output ); } free( output_fx[0] ); } @@ -1893,13 +2380,524 @@ ivas_error ivas_jbm_dec_tc( #endif // IVAS_FLOAT_FIXED else if ( st_ivas->nCPE > 1 ) { - if ( ( error = ivas_mct_dec( st_ivas, p_output, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) +#ifdef IVAS_FLOAT_FIXED +#if 1 // Float to fix + + Decoder_State *st, **sts; + MCT_DEC_HANDLE hMCT; + CPE_DEC_HANDLE hCPE; + + Word16 ch, nCPE, cpe_id; + Word16 q_output = 11; + Word16 k, l, i, j; + + nCPE = st_ivas->nCPE; + move16(); + hMCT = st_ivas->hMCT; + FOR( i = 0; i < 12; i++ ) + if ( p_output[i] ) { - return error; + p_output_fx[i] = malloc( sizeof( Word32 ) * L_FRAME48k ); + floatToFixed_arrL( p_output[i], p_output_fx[i], Q11, L_FRAME48k ); } - } + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + hCPE = st_ivas->hCPE[cpe_id]; + sts = hCPE->hCoreCoder; - if ( st_ivas->sba_dirac_stereo_flag ) + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + st = hCPE->hCoreCoder[n]; + IF( st->hTonalMDCTConc ) + { + + FOR( i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) + { + st->hTonalMDCTConc->scaleFactorsBackground_fx[i] = float_to_fix( st->hTonalMDCTConc->scaleFactorsBackground_flt[i], 15 ); + } + //st->hTonalMDCTConc->scf_fadeout = float_to_fix16( st->hTonalMDCTConc->scf_fadeout_flt, 15 ); + if ( hCPE->hCoreCoder[n]->bfi && st->tonal_mdct_plc_active ) + { + FOR( i = 0; i < FDNS_NPTS; i++ ) + { + f2me_16( st->hTonalMDCTConc->secondLastBlockData.scaleFactors_float[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ); + } + FOR( i = 0; i < 30; i++ ) + { + float pd = st->hTonalMDCTConc->pTCI->phaseDiff_float[i]; + if ( pd >= PI2 ) + pd = fmodf( pd, PI2 ) - PI2; + st->hTonalMDCTConc->pTCI->phaseDiff[i] = (Word16) floatToFixed( pd, Q12 ); + } + FOR( i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++ ) + { + float pd = st->hTonalMDCTConc->pTCI->phase_currentFramePredicted_float[i]; + pd = fmodf( pd, PI2 ); + st->hTonalMDCTConc->pTCI->phase_currentFramePredicted[i] = (Word16) ( pd * ( 1u << Q13 ) ); + } + // st->hTonalMDCTConc->nFramesLost = float_to_fix16( st->hTonalMDCTConc->nFramesLost, Q1 ); + } + //f2me( st->hTonalMDCTConc->last_block_nrg_flt, &st->hTonalMDCTConc->last_block_nrg, &st->hTonalMDCTConc->last_block_nrg_exp ); + } + // st->old_fpitch = float_to_fix(st->old_fpitch_float, 16); + st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); + + IF( sts[n]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) + { + // sts[n]->Mode2_lp_gainp = floatToFixed( sts[n]->lp_gainp, Q16 ); + // u8bit to 16bit + FOR( l = 0; l < IGF_START_MX; l++ ) + { + sts[n]->hIGFDec->infoTCXNoise_evs[l] = (Word16) sts[n]->hIGFDec->infoTCXNoise[l]; + } + } + + + IF( st->hTcxDec ) + f2me_16( st->hTcxDec->CngLevelBackgroundTrace_bfi, &st->hTcxDec->conCngLevelBackgroundTrace, &st->hTcxDec->conCngLevelBackgroundTrace_e ); + if ( st->hTcxDec && st->hTcxDec->conLastFrameLevel_e < 0 ) + { + st->hTcxDec->conLastFrameLevel_e = 0; + } + if ( st->hTcxDec && st->hTcxDec->conNoiseLevelMemory_e[0] < 0 ) + { + set16_fx( st->hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); + } + IF( st->hTcxDec ) + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + IF( st->hTcxDec ) + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + IF( st->hTcxDec ) + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hTcxDec->old_excFB_fx[p] = (Word16) ( st->hTcxDec->old_excFB[p] * ( 1u << st->Q_exc ) ); + } + IF( st->hFdCngDec && st->hFdCngDec->hFdCngCom ) + floatToFixed_arr( st->hFdCngDec->hFdCngCom->A_cng_flt, st->hFdCngDec->hFdCngCom->A_cng, 15, 17 ); + // st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15); + + IF( hCPE->hCoreCoder[n]->hTcxLtpDec ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float, hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32, q_output, L_FRAME48k ); + floatToFixed_arrL( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float, hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32, q_output, TCXLTP_MAX_DELAY ); + floatToFixed_arrL( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, Q11, 111 ); + } + + + /*cldfb struct*/ + + /*------------------fix-to-fix-start---------------------*/ + /*core_switching_post_dec*/ + if ( hCPE->hCoreCoder[n]->hHQ_core != NULL ) + { + hCPE->hCoreCoder[n]->hHQ_core->Q_old_postdec = 0; + hCPE->hCoreCoder[n]->hHQ_core->Q_old_wtda = 0; + } + + /*-------------------cldfb-start-------------------------*/ + + floatToFixed_arrL( hCPE->hCoreCoder[n]->bpf_noise_buf_float, hCPE->hCoreCoder[n]->bpf_noise_buf_32, 11, L_FRAME_16k ); + if ( hCPE->hCoreCoder[n]->cldfbAna != NULL ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->cldfbAna->cldfb_state, hCPE->hCoreCoder[n]->cldfbAna->cldfb_state_fx, 10, hCPE->hCoreCoder[n]->cldfbAna->cldfb_size ); + } + if ( hCPE->hCoreCoder[n]->cldfbSyn != NULL ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->cldfbSyn->cldfb_state, hCPE->hCoreCoder[n]->cldfbSyn->cldfb_state_fx, 4, hCPE->hCoreCoder[n]->cldfbSyn->p_filter_length ); + } + if ( hCPE->hCoreCoder[n]->cldfbBPF != NULL ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->cldfbBPF->cldfb_state, hCPE->hCoreCoder[n]->cldfbBPF->cldfb_state_fx, 11, hCPE->hCoreCoder[n]->cldfbBPF->cldfb_size ); + } + + + /*-------------------cldfb-end---------------------------*/ + + floatToFixed_arr( sts[n]->prev_synth_buffer, hCPE->hCoreCoder[n]->prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); + } + + IF( hCPE->output_mem[0] != NULL ) + { + floatToFixed_arrL( hCPE->output_mem[0], hCPE->output_mem_fx[0], Q11, NS2SA( hCPE->hCoreCoder[0]->output_Fs, 3125000 ) ); + } + IF( hCPE->output_mem[1] != NULL ) + { + floatToFixed_arrL( hCPE->output_mem[1], hCPE->output_mem_fx[1], Q11, NS2SA( hCPE->hCoreCoder[0]->output_Fs, 3125000 ) ); + } + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + + IF( hCPE->hStereoDft != NULL ) + { + IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) + { + FOR( Word32 p = 0; p < L_FRAME48k; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << q_output ) ); + } + FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q_output ) ); + } + } + } + + IF( hCPE->input_mem_LB[n] != NULL ) + { + FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) + { + hCPE->input_mem_LB_fx[n][ind] = (Word32) ( hCPE->input_mem_LB[n][ind] * ( 1 << q_output ) ); + } + } + + //FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) + //{ + // hCPE->prev_hb_synth_fx[n][k] = (Word32) ( hCPE->prev_hb_synth[n][k] * ( 1 << q_output ) ); + //} + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->prev_synth_fx[n][k] = (Word32) ( hCPE->prev_synth[n][k] * ( 1 << q_output ) ); + } + } + } + + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->targetEnergyPrev ) + f2me_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->dmxEnergyPrev ) + f2me_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); + IF( st_ivas->hParamMC && st_ivas->hParamMC->icld_q ) + floatToFixed_arr16( st_ivas->hParamMC->icld_q, st_ivas->hParamMC->icld_q_fx, 8, st_ivas->hParamMC->hMetadataPMC->num_parameter_bands * st_ivas->hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); + IF( st_ivas->hParamMC && st_ivas->hParamMC->ls_conv_dmx_matrix ) + floatToFixed_arr32( st_ivas->hParamMC->ls_conv_dmx_matrix, st_ivas->hParamMC->ls_conv_dmx_matrix_fx, 15, st_ivas->hDecoderConfig->nchan_out * ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) ); + IF( st_ivas->hLsSetUpConversion ) + FOR( Word16 chOutIdx = 0; chOutIdx < st_ivas->hDecoderConfig->nchan_out; chOutIdx++ ) + { + FOR( Word16 chInIdx = 0; chInIdx < st_ivas->nchan_transport; chInIdx++ ) + { + st_ivas->hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx] = float_to_fix( st_ivas->hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx], 30 ); /*Q30*/ + } + } + + +#endif // Float to fix + if ( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + { + return error; + } +#if 1 // Fix to float + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + hCPE = st_ivas->hCPE[cpe_id]; + sts = hCPE->hCoreCoder; + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + st = hCPE->hCoreCoder[ch]; + st->hTcxDec->tcxltp_last_gain_unmodified_float = fixedToFloat(st->hTcxLtpDec->tcxltp_gain, 15); + //st->hTcxDec->tcxltp_last_gain_unmodified_float = st->hTcxLtpDec->tcxltp_gain_float; + IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) + { + // 16bit to u8bit + FOR( l = 0; l < IGF_START_MX; l++ ) + { + sts[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t) sts[ch]->hIGFDec->infoTCXNoise_evs[l]; + } + + IF( !sts[0]->bfi || ( sts[0]->bfi && sts[ch]->core != ACELP_CORE ) ) + { + me2f_buf( sts[ch]->hIGFDec->virtualSpec, sts[ch]->hIGFDec->virtualSpec_e, sts[ch]->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); + } + } + IF( st->hTonalMDCTConc != NULL ) + { + //st->hTonalMDCTConc->scf_fadeout_flt = fixedToFloat( st->hTonalMDCTConc->scf_fadeout, 15 ); + //st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); + if ( hCPE->hCoreCoder[ch]->bfi && st->tonal_mdct_plc_active ) + { + //st->hTonalMDCTConc->nFramesLost_float = fix16_to_float( st->hTonalMDCTConc->nFramesLost, Q1 ); + } + } + + if ( sts[ch]->last_core != -1 && sts[ch]->nbLostCmpt == 1 ) + { + if ( !( sts[ch]->rf_flag && sts[ch]->use_partial_copy && ( sts[ch]->rf_frame_type == RF_TCXTD1 || sts[ch]->rf_frame_type == RF_TCXTD2 ) ) ) + { + IF( sts[ch]->hTonalMDCTConc != NULL && sts[ch]->last_core == TCX_20_CORE && sts[ch]->second_last_core == TCX_20_CORE && ( ( sts[ch]->old_fpitch <= L_shl( sts[ch]->L_frame, 15 ) ) || ( sts[ch]->hTcxDec->tcxltp_last_gain_unmodified <= 13107 /*0.4f*/ ) ) + /* it is fine to call the detection even if no ltp information + is available, meaning that st->old_fpitch == + st->tcxltp_second_last_pitch == st->L_frame */ + && ( sts[ch]->old_fpitch == sts[ch]->hTcxDec->tcxltp_second_last_pitch ) && !sts[ch]->last_tns_active && !sts[ch]->second_last_tns_active ) + { + + if ( sts[ch]->hTonalMDCTConc->pTCI->numIndexes < MAX_NUMBER_OF_IDX ) + { + FOR( i = 0; i < sts[ch]->hTonalMDCTConc->pTCI->numIndexes; i++ ) + { + sts[ch]->hTonalMDCTConc->pTCI->phaseDiff_float[i] = fixedToFloat( sts[ch]->hTonalMDCTConc->pTCI->phaseDiff[i], Q12 ); + } + FOR( i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++ ) + { + sts[ch]->hTonalMDCTConc->pTCI->phase_currentFramePredicted_float[i] = fixedToFloat( sts[ch]->hTonalMDCTConc->pTCI->phase_currentFramePredicted[i], Q13 ); + } + } + } + } + } + } + + FOR( n = 0; n < 2; n++ ) + { + st = hCPE->hCoreCoder[n]; + sts = hCPE->hCoreCoder; + IF( st->hTcxDec ) + st->hTcxDec->CngLevelBackgroundTrace_bfi = me2f_16( st->hTcxDec->conCngLevelBackgroundTrace, st->hTcxDec->conCngLevelBackgroundTrace_e ); + IF( st->hTonalMDCTConc && st->hTonalMDCTConc->lastPcmOut_float ) + fixedToFloat_arr( st->hTonalMDCTConc->lastPcmOut, st->hTonalMDCTConc->lastPcmOut_float, 0, st->hTonalMDCTConc->nSamples ); + IF( sts[0]->bfi == 0 && !st->hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive ) + fixedToFloat_arr( st->hTonalMDCTConc->secondLastPcmOut, st->hTonalMDCTConc->secondLastPcmOut_float, 0, st->hTonalMDCTConc->nSamples / 2 ); + fixedToFloat_arr( st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synthFB, st->Q_syn, st->hTcxDec->old_synth_lenFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + fixedToFloat_arr( st->hTcxDec->old_synth, st->hTcxDec->old_synth_float, st->Q_syn, 1280 ); + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hTcxDec->old_excFB[p] = (float) ( st->hTcxDec->old_excFB_fx[p] ) / ( 1u << st->Q_exc ); + } + for ( int p = 0; p < st->L_frame / 2; p++ ) + { + st->hTcxDec->old_syn_Overl_float[p] = (float) st->hTcxDec->old_syn_Overl[p] * 2 * ( 1u << st->Q_syn ); + st->hTcxDec->syn_Overl_TDACFB_float[p] = (float) st->hTcxDec->syn_Overl_TDACFB[p] * 2 * (float) pow( 2, st->Q_syn ); + st->hTcxDec->syn_Overl_TDAC_float[p] = (float) st->hTcxDec->syn_Overl_TDAC[p] * 2 * (float) pow( 2, st->Q_syn ); + } + for ( int p = 0; p < 640; p++ ) + { + st->hHQ_core->old_outLB[p] = (float) st->hHQ_core->old_out_LB_fx[p] / ( 1u << st->Q_syn ); + } + + if ( !st->tcxonly ) + { + fixedToFloat_arr( st->p_bpf_noise_buf, st->p_bpf_noise_buf_float, 0, L_FRAME_16k ); + } + + fixedToFloat_arr( st->hTcxDec->syn_OverlFB, st->hTcxDec->syn_OverlFB_float, st->Q_syn, L_FRAME_MAX / 2 ); + fixedToFloat_arr( st->hTcxDec->syn_Overl, st->hTcxDec->syn_Overl_float, st->Q_syn, L_FRAME32k / 2 ); + st->hTcxDec->tcxltp_last_gain_unmodified_float = fix16_to_float( st->hTcxDec->tcxltp_last_gain_unmodified, Q15 ); + st->hTcxDec->conceal_eof_gain_float = fix16_to_float( st->hTcxDec->conceal_eof_gain, Q14 ); + + /*-------------------cldfb-start-------------------------*/ + + /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ + + if ( sts[n]->cldfbAna != NULL ) + { + fixedToFloat_arrL( sts[n]->cldfbAna->cldfb_state_fx, sts[n]->cldfbAna->cldfb_state, 10, sts[n]->cldfbAna->cldfb_state_length ); + } + if ( sts[n]->cldfbSyn != NULL ) + { + fixedToFloat_arrL( sts[n]->cldfbSyn->cldfb_state_fx, sts[n]->cldfbSyn->cldfb_state, 4, sts[n]->cldfbSyn->p_filter_length ); + } + if ( sts[n]->cldfbBPF != NULL ) + { + fixedToFloat_arrL( sts[n]->cldfbBPF->cldfb_state_fx, sts[n]->cldfbBPF->cldfb_state, 11, sts[n]->cldfbBPF->cldfb_state_length ); + } + + /*-------------------cldfb-end---------------------------*/ + + IF( sts[n]->hHQ_core != NULL ) + { + fixedToFloat_arr( sts[n]->hHQ_core->old_out_fx, sts[n]->hHQ_core->old_out, 0, L_FRAME48k ); + } + /*------------------reset-code-start---------------------*/ + + /*reset function flags*/ + Word8 reset_wb_tbe_synth = 0; + Word8 reset_swb_tbe = 0; + + /* reset WB BWE buffers */ + + IF( NE_16( sts[n]->last_extl, WB_BWE ) && EQ_16( sts[n]->extl, WB_BWE ) && sts[n]->hBWE_FD != NULL ) + { + + IF( NE_16( sts[n]->last_extl, SWB_BWE ) && NE_16( sts[n]->last_extl, FB_BWE ) ) + { + sts[n]->hBWE_FD->prev_mode = sts[n]->hBWE_FD->prev_mode; + } + sts[n]->hBWE_FD->prev_L_swb_norm = sts[n]->hBWE_FD->prev_L_swb_norm; + sts[n]->hBWE_FD->prev_flag = sts[n]->hBWE_FD->prev_flag; + } + + /* reset TBE buffers */ + if ( sts[n]->hBWE_TD != NULL ) + { + IF( ( ( EQ_16( sts[n]->extl, SWB_TBE ) || EQ_16( sts[n]->extl, FB_TBE ) || EQ_16( sts[n]->extl, SWB_CNG ) ) && + ( NE_16( sts[n]->L_frame, sts[n]->last_L_frame ) || ( NE_16( sts[n]->last_extl, SWB_TBE ) && NE_16( sts[n]->last_extl, FB_TBE ) ) || EQ_16( sts[n]->last_core, HQ_CORE ) ) ) || + ( LT_16( sts[n]->bwidth, sts[n]->last_bwidth ) && NE_16( sts[n]->last_extl, SWB_TBE ) ) || sts[n]->old_ppp_mode || ( ( EQ_16( sts[n]->prev_coder_type, AUDIO ) || EQ_16( sts[n]->prev_coder_type, INACTIVE ) ) && sts[n]->bws_cnt > 0 ) || ( sts[n]->bws_cnt == 0 && EQ_16( sts[n]->prev_bws_cnt, N_WS2N_FRAMES ) ) ) + { + + reset_swb_tbe = 1; + + IF( EQ_16( output_frame, L_FRAME16k ) ) + { + fixedToFloat_arr( sts[n]->hBWE_TD->mem_resamp_HB_32k_fx, sts[n]->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + } + fixedToFloat_arr( sts[n]->hBWE_TD->int_3_over_2_tbemem_dec_fx, sts[n]->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN ); + } + ELSE IF( sts[n]->hBWE_TD != NULL && ( sts[n]->last_core == TCX_20_CORE || sts[n]->last_core == TCX_10_CORE ) ) + { + /*------------TBEreset_dec_ivas_fx-start------------------*/ + IF( EQ_16( sts[n]->bwidth, WB ) ) + { + reset_wb_tbe_synth = 1; + + fixedToFloat_arr( sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); + } + ELSE IF( EQ_16( sts[n]->bwidth, SWB ) || EQ_16( sts[n]->bwidth, FB ) ) + { + reset_swb_tbe = 1; + fixedToFloat_arr( sts[n]->hBWE_TD->int_3_over_2_tbemem_dec_fx, sts[n]->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN ); // setting to zero + fixedToFloat_arr( sts[n]->hBWE_TD->mem_resamp_HB_32k_fx, sts[n]->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); // setting to zero + } + /*------------TBEreset_dec_ivas_fx-end--------------------*/ + } + + IF( NE_16( sts[n]->last_extl, WB_TBE ) && EQ_16( sts[n]->extl, WB_TBE ) ) + { + reset_wb_tbe_synth = 1; + fixedToFloat_arr( sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); // setting to zero + } + + IF( reset_swb_tbe ) + { + fixedToFloat_arr( sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); // setting to zero + } + IF( reset_wb_tbe_synth ) + { + fixedToFloat_arr( sts[n]->hBWE_TD->state_lsyn_filt_shb_fx, sts[n]->hBWE_TD->state_lsyn_filt_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); // setting to zero + fixedToFloat_arr( sts[n]->hBWE_TD->state_lsyn_filt_dwn_shb_fx, sts[n]->hBWE_TD->state_lsyn_filt_dwn_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); // setting to zero + fixedToFloat_arr( sts[n]->hBWE_TD->mem_resamp_HB_fx, sts[n]->hBWE_TD->mem_resamp_HB, 0, INTERP_3_1_MEM_LEN ); // setting to zero + } + } + + /*------------------reset-code-end-----------------------*/ + + + for ( int p = 0; p < L_FRAME48k; p++ ) + { + + IF( hCPE->hCoreCoder[n]->hTcxLtpDec ) + { + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q_output ); + if ( p < TCXLTP_MAX_DELAY ) + { + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q_output ); + } + } + } + if ( hCPE->hCoreCoder[n]->hTcxDec ) + { + for ( k = 0; k < 111; k++ ) + { + hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ( 1u << q_output ); + } + } + IF( hCPE->hCoreCoder[n]->hTcxLtpDec ) + + if ( ( hCPE->hCoreCoder[n]->codec_mode == MODE1 && hCPE->hCoreCoder[n]->hTcxDec != NULL ) && ( ( hCPE->hCoreCoder[n]->core == ACELP_CORE && !( hCPE->hCoreCoder[n]->bfi == 1 && hCPE->hCoreCoder[n]->con_tcx == 1 ) ) || hCPE->hCoreCoder[n]->core == HQ_CORE ) ) + { + fixedToFloat_arr( hCPE->hCoreCoder[n]->hTcxDec->synth_history_fx, hCPE->hCoreCoder[n]->hTcxDec->synth_history, 0, output_frame ); + } + } + + IF( hCPE->hStereoDft != NULL ) + { + IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) + { + FOR( Word32 p = 0; p < L_FRAME48k; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q_output ); + } + FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q_output ); + } + } + } + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + IF( hCPE->output_mem[n] != NULL ) + { + FOR( k = 0; k < NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->output_mem[n][k] = (float) hCPE->output_mem_fx[n][k] / ( 1u << 11 ); + } + } + IF( hCPE->hCoreCoder[n] != NULL ) + { + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) + { + hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << q_output ); + } + } + IF( hCPE->input_mem[n] != NULL ) + { + FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) + { + hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << q_output ) ); + } + } + //FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) + //{ + // hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << q_output ); + //} + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << q_output ); + } + } + } + + + IF( st_ivas->hCPE[0]->hCoreCoder[0]->igf ) + { + IF( !hMCT->currBlockDataCnt ) + { + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + IF( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->igf ) + { + me2f_buf( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec_e, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); + FOR( l = 0; l < IGF_START_MX; l++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t) st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise_evs[l]; + } + } + } + } + } + } + + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->targetEnergyPrev ) + me2f_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx ) + me2f_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); + + FOR( i = 0; i < 12; i++ ) + if ( p_output[i] ) + { + fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, L_FRAME48k ); + free( p_output_fx[i] ); + } +#endif // Fix to float +#else + if ( ( error = ivas_mct_dec( st_ivas, p_output, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + } + + if ( st_ivas->sba_dirac_stereo_flag ) { #ifndef IVAS_FLOAT_FIXED ivas_agc_dec_process( st_ivas->hSpar->hAgcDec, &p_output[sba_ch_idx], &p_output[sba_ch_idx], st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame ); @@ -1992,13 +2990,10 @@ ivas_error ivas_jbm_dec_tc( hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft; } - st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact, 15); + // st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact, 15); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact, 15); - floatToFixed_arrL(&hCPE->hStereoDft->res_gains_ind[0][0], &hCPE->hStereoDft->res_gains_ind_fx[0][0], Q26, sizeof(hCPE->hStereoDft->res_gains_ind_fx) / sizeof(hCPE->hStereoDft->res_gains_ind_fx[0][0])); - floatToFixed_arrL(&hCPE->hStereoDft->res_pred_gain[0], &hCPE->hStereoDft->res_pred_gain_fx[0], Q31, sizeof(hCPE->hStereoDft->res_pred_gain_fx)/ sizeof(hCPE->hStereoDft->res_pred_gain_fx[0])); - floatToFixed_arrL(&hCPE->hStereoDft->itd[0], &hCPE->hStereoDft->itd_fx[0], Q1, sizeof(hCPE->hStereoDft->itd_fx) / sizeof(hCPE->hStereoDft->itd_fx[0])); floatToFixed_arrL(&st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0], st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->q_smoothed_psd, sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx) / sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0])); - floatToFixed_arrL(&hCPE->prev_hb_synth[0][0], &hCPE->prev_hb_synth_fx[0][0], hCPE->hStereoDft->q_dft, sizeof(hCPE->prev_hb_synth_fx) / sizeof(hCPE->prev_hb_synth_fx[0][0])); + //floatToFixed_arrL(&hCPE->prev_hb_synth[0][0], &hCPE->prev_hb_synth_fx[0][0], hCPE->hStereoDft->q_dft, sizeof(hCPE->prev_hb_synth_fx) / sizeof(hCPE->prev_hb_synth_fx[0][0])); for (int ii = 0; ii < sizeof(hCPE->hStereoDft->hb_nrg_subr_fx) / sizeof(hCPE->hStereoDft->hb_nrg_subr_fx[0]); ii++) { if ( l_hb_nrg_subr < hCPE->hStereoDft->hb_nrg_subr[ii] ) @@ -2034,15 +3029,12 @@ ivas_error ivas_jbm_dec_tc( hCPE->hStereoDft->hb_nrg_fx[ii] = (Word32)(hCPE->hStereoDft->hb_nrg[ii] * ((float)(1 << hCPE->hStereoDft->q_hb_nrg))); } - floatToFixed_arrL( &hCPE->hStereoDft->side_gain[0], &hCPE->hStereoDft->side_gain_fx[0], Q31, sizeof( hCPE->hStereoDft->side_gain_fx ) / sizeof( hCPE->hStereoDft->side_gain_fx[0] ) ); - floatToFixed_arrL( &hCPE->hStereoDft->gipd[0], &hCPE->hStereoDft->gipd_fx[0], Q13, sizeof( hCPE->hStereoDft->gipd_fx ) / sizeof( hCPE->hStereoDft->gipd_fx[0] ) ); - floatToFixed_arr( &hCPE->hStereoDft->g_state[0], &hCPE->hStereoDft->g_state_fx[0], Q15, sizeof( hCPE->hStereoDft->g_state_fx ) / sizeof( hCPE->hStereoDft->g_state_fx[0] ) ); - floatToFixed_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0] ) ); + //floatToFixed_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0] ) ); IF( hCPE->hStereoCng != NULL ) { floatToFixed_arr( &hCPE->hStereoCng->cm[0], &hCPE->hStereoCng->cm_fx[0], Q15, sizeof( hCPE->hStereoCng->cm_fx ) / sizeof( hCPE->hStereoCng->cm_fx[0] ) ); } - floatToFixed_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0] ) ); + //floatToFixed_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0] ) ); for ( int ii = sba_ch_idx; ii < sba_ch_idx + 2; ii++ ) { floatToFixed_arrL( &p_output[ii][0], &p_output_fix[ii][0], hCPE->hStereoDft->q_dft, ( 48000 / FRAMES_PER_SEC ) ); @@ -2055,8 +3047,8 @@ ivas_error ivas_jbm_dec_tc( floatToFixed_arrL(&hCPE->input_mem_LB[1][0], &hCPE->input_mem_LB_fx[1][0], q, STEREO_DFT32MS_OVL_16k); if (hSCE != NULL) { - floatToFixed_arrL(&hSCE->prev_hb_synth[0], &hSCE->prev_hb_synth_fx[0], hCPE->hStereoDft->q_dft, sizeof(hSCE->prev_hb_synth_fx) / sizeof(hSCE->prev_hb_synth_fx[0])); - hSCE->q_prev_hb_synth_fx = hCPE->hStereoDft->q_dft; + //floatToFixed_arrL(&hSCE->prev_hb_synth[0], &hSCE->prev_hb_synth_fx[0], hCPE->hStereoDft->q_dft, sizeof(hSCE->prev_hb_synth_fx) / sizeof(hSCE->prev_hb_synth_fx[0])); + //hSCE->q_prev_hb_synth_fx = hCPE->hStereoDft->q_dft; floatToFixed_arrL(&hSCE->save_hb_synth[0], &hSCE->save_hb_synth_fx[0], q, (Word16)(hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC)); hSCE->q_save_hb_synth_fx = q; floatToFixed_arrL(&hSCE->save_synth[0], &hSCE->save_synth_fx[0], q, (Word16)(hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC)); @@ -2091,7 +3083,7 @@ ivas_error ivas_jbm_dec_tc( st_ivas->hSpar->hMdDec->mix_mat_dim_2); } } - hCPE->lt_es_em_fx = floatToFixed(hCPE->lt_es_em, Q15); + //hCPE->lt_es_em_fx = floatToFixed(hCPE->lt_es_em, Q15); for (int ii = 0; ii < CPE_CHANNELS; ii++) { hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; @@ -2101,17 +3093,9 @@ ivas_error ivas_jbm_dec_tc( ivas_sba_dirac_stereo_dec_fx( st_ivas, &p_output_fix[sba_ch_idx], output_frame, 0 ); - IF (hSCE != NULL) - { - hSCE->hCoreCoder[0]->log_energy_diff_lt = fixedToFloat(hSCE->hCoreCoder[0]->log_energy_diff_lt_fx, Q15); - hSCE->hCoreCoder[0]->stab_fac_smooth_lt = fixedToFloat(hSCE->hCoreCoder[0]->stab_fac_smooth_lt_fx, Q15); - } fixedToFloat_arrL(&hCPE->prev_synth_fx[0][0], &hCPE->prev_synth[0][0], hCPE->q_prev_synth_fx, sizeof(hCPE->prev_synth) / sizeof(hCPE->prev_synth[0][0])); - st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact = fixedToFloat( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx, 15 ); + // st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact = fixedToFloat( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx, 15 ); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact = fixedToFloat( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact_fx, 15 ); - fixedToFloat_arrL( &hCPE->hStereoDft->res_gains_ind_fx[0][0], &hCPE->hStereoDft->res_gains_ind[0][0], Q26, sizeof( hCPE->hStereoDft->res_gains_ind_fx ) / sizeof( hCPE->hStereoDft->res_gains_ind_fx[0][0] ) ); - fixedToFloat_arrL( &hCPE->hStereoDft->res_pred_gain_fx[0], &hCPE->hStereoDft->res_pred_gain[0], Q31, sizeof( hCPE->hStereoDft->res_pred_gain_fx ) / sizeof( hCPE->hStereoDft->res_pred_gain_fx[0] ) ); - fixedToFloat_arrL( &hCPE->hStereoDft->itd_fx[0], &hCPE->hStereoDft->itd[0], Q1, sizeof( hCPE->hStereoDft->itd_fx ) / sizeof( hCPE->hStereoDft->itd_fx[0] ) ); fixedToFloat_arrL( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd[0], st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->q_smoothed_psd, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0] ) ); for ( int ii = 0; ii < sizeof( hCPE->hStereoDft->hb_nrg_subr_fx ) / sizeof( hCPE->hStereoDft->hb_nrg_subr_fx[0] ); ii++ ) { @@ -2121,16 +3105,13 @@ ivas_error ivas_jbm_dec_tc( { hCPE->hStereoDft->hb_nrg[ii] = ( (float) hCPE->hStereoDft->hb_nrg_fx[ii] * ( (float) ( 1 << hCPE->hStereoDft->q_hb_nrg ) ) ); } - fixedToFloat_arrL(&hCPE->hStereoDft->side_gain_fx[0], &hCPE->hStereoDft->side_gain[0], Q31,sizeof(hCPE->hStereoDft->side_gain_fx) / sizeof(hCPE->hStereoDft->side_gain_fx[0])); - fixedToFloat_arrL(&hCPE->hStereoDft->gipd_fx[0], &hCPE->hStereoDft->gipd[0], Q13, sizeof(hCPE->hStereoDft->gipd_fx) / sizeof(hCPE->hStereoDft->gipd_fx[0])); - fixedToFloat_arr(&hCPE->hStereoDft->g_state_fx[0], &hCPE->hStereoDft->g_state[0], Q15, sizeof(hCPE->hStereoDft->g_state_fx) / sizeof(hCPE->hStereoDft->g_state_fx[0])); - fixedToFloat_arr(&st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm[0], Q15, sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx) / sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0])); - fixedToFloat_arrL(&hCPE->prev_hb_synth_fx[0][0], &hCPE->prev_hb_synth[0][0], hCPE->hStereoDft->q_dft, sizeof(hCPE->prev_hb_synth_fx) / sizeof(hCPE->prev_hb_synth_fx[0][0])); + //fixedToFloat_arr(&st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm[0], Q15, sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx) / sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0])); + //fixedToFloat_arrL(&hCPE->prev_hb_synth_fx[0][0], &hCPE->prev_hb_synth[0][0], hCPE->hStereoDft->q_dft, sizeof(hCPE->prev_hb_synth_fx) / sizeof(hCPE->prev_hb_synth_fx[0][0])); IF (hCPE->hStereoCng != NULL) { fixedToFloat_arr( &hCPE->hStereoCng->cm_fx[0], &hCPE->hStereoCng->cm[0], Q15, sizeof( hCPE->hStereoCng->cm_fx ) / sizeof( hCPE->hStereoCng->cm_fx[0] ) ); } - fixedToFloat_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0] ) ); + //fixedToFloat_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0] ) ); for ( int ii = sba_ch_idx; ii < sba_ch_idx + 2; ii++ ) { fixedToFloat_arrL( &p_output_fix[ii][0], &p_output[ii][0], hCPE->hStereoDft->q_dft, ( 48000 / FRAMES_PER_SEC ) ); @@ -2142,7 +3123,7 @@ ivas_error ivas_jbm_dec_tc( fixedToFloat_arrL(&hCPE->input_mem_LB_fx[1][0], &hCPE->input_mem_LB[1][0], q, STEREO_DFT32MS_OVL_16k); if (hSCE != NULL) { - fixedToFloat_arrL(&hSCE->prev_hb_synth_fx[0], &hSCE->prev_hb_synth[0], hCPE->hStereoDft->q_dft, sizeof(hSCE->prev_hb_synth_fx) / sizeof(hSCE->prev_hb_synth_fx[0])); + //fixedToFloat_arrL(&hSCE->prev_hb_synth_fx[0], &hSCE->prev_hb_synth[0], hCPE->hStereoDft->q_dft, sizeof(hSCE->prev_hb_synth_fx) / sizeof(hSCE->prev_hb_synth_fx[0])); fixedToFloat_arrL(&hSCE->save_synth_fx[0], &hSCE->save_synth[0], q, (Word16)(hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC)); fixedToFloat_arrL(&hSCE->save_hb_synth_fx[0], &hSCE->save_hb_synth[0], q, (Word16)(hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC)); } @@ -2177,7 +3158,7 @@ ivas_error ivas_jbm_dec_tc( { fixedToFloat_arrL(&hCPE->output_mem_fx[ii][0], &hCPE->output_mem[ii][0], hCPE->hStereoDft->q_dft, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS )); } - hCPE->lt_es_em = fixedToFloat(hCPE->lt_es_em_fx, Q15); + //hCPE->lt_es_em = fixedToFloat(hCPE->lt_es_em_fx, Q15); } #endif } @@ -2474,27 +3455,541 @@ ivas_error ivas_jbm_dec_tc( ivas_lfe_dec( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output[LFE_CHANNEL] ); #endif // IVAS_FLOAT_FIXED - if ( ( error = ivas_mct_dec( st_ivas, p_output, output_frame, 0 ) ) != IVAS_ERR_OK ) +#ifdef IVAS_FLOAT_FIXED +#if 1 // Float to fix + + Decoder_State *st, **sts; + MCT_DEC_HANDLE hMCT; + CPE_DEC_HANDLE hCPE; + + Word16 ch, nCPE, cpe_id; + Word16 q_output = 11; + Word16 k, l, i, j; + + nCPE = st_ivas->nCPE; + move16(); + hMCT = st_ivas->hMCT; + FOR( i = 0; i < 12; i++ ) + if ( p_output[i] ) { - return error; + p_output_fx[i] = malloc( sizeof( Word32 ) * L_FRAME48k ); + floatToFixed_arrL( p_output[i], p_output_fx[i], Q11, L_FRAME48k ); } - - /* HP filtering */ - for ( n = 0; n < st_ivas->nchan_transport; n++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - if ( n != LFE_CHANNEL ) + hCPE = st_ivas->hCPE[cpe_id]; + sts = hCPE->hCoreCoder; + + + FOR( n = 0; n < CPE_CHANNELS; n++ ) { -#ifdef IVAS_FLOAT_FIXED - Word32 p_output_fix[L_FRAME48k]; - for ( int i = 0; i < output_frame; i++ ) - { - p_output_fix[i] = (Word32) ( p_output[n][i] * ( 1 << 11 ) ); - } - hp20_fix32( p_output_fix, output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); - for ( int i = 0; i < output_frame; i++ ) + st = hCPE->hCoreCoder[n]; + IF( st->hTonalMDCTConc ) { - p_output[n][i] = (float) p_output_fix[i] / ( 1 << 11 ); - } + + FOR( i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) + { + st->hTonalMDCTConc->scaleFactorsBackground_fx[i] = float_to_fix( st->hTonalMDCTConc->scaleFactorsBackground_flt[i], 15 ); + } + //st->hTonalMDCTConc->scf_fadeout = float_to_fix16( st->hTonalMDCTConc->scf_fadeout_flt, 15 ); + if ( hCPE->hCoreCoder[n]->bfi && st->tonal_mdct_plc_active ) + { + FOR( i = 0; i < FDNS_NPTS; i++ ) + { + f2me_16( st->hTonalMDCTConc->secondLastBlockData.scaleFactors_float[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ); + } + FOR( i = 0; i < 30; i++ ) + { + float pd = st->hTonalMDCTConc->pTCI->phaseDiff_float[i]; + if ( pd >= PI2 ) + pd = fmodf( pd, PI2 ) - PI2; + st->hTonalMDCTConc->pTCI->phaseDiff[i] = (Word16) floatToFixed( pd, Q12 ); + } + FOR( i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++ ) + { + float pd = st->hTonalMDCTConc->pTCI->phase_currentFramePredicted_float[i]; + pd = fmodf( pd, PI2 ); + st->hTonalMDCTConc->pTCI->phase_currentFramePredicted[i] = (Word16) ( pd * ( 1u << Q13 ) ); + } + // st->hTonalMDCTConc->nFramesLost = float_to_fix16( st->hTonalMDCTConc->nFramesLost, Q1 ); + } + //f2me( st->hTonalMDCTConc->last_block_nrg_flt, &st->hTonalMDCTConc->last_block_nrg, &st->hTonalMDCTConc->last_block_nrg_exp ); + } + // st->old_fpitch = float_to_fix(st->old_fpitch_float, 16); + st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); + + IF( sts[n]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) + { + // sts[n]->Mode2_lp_gainp = floatToFixed( sts[n]->lp_gainp, Q16 ); + // u8bit to 16bit + FOR( l = 0; l < IGF_START_MX; l++ ) + { + sts[n]->hIGFDec->infoTCXNoise_evs[l] = (Word16) sts[n]->hIGFDec->infoTCXNoise[l]; + } + } + + + IF( st->hTcxDec ) + f2me_16( st->hTcxDec->CngLevelBackgroundTrace_bfi, &st->hTcxDec->conCngLevelBackgroundTrace, &st->hTcxDec->conCngLevelBackgroundTrace_e ); + if ( st->hTcxDec && st->hTcxDec->conLastFrameLevel_e < 0 ) + { + st->hTcxDec->conLastFrameLevel_e = 0; + } + IF( st->hTcxDec ) + //st->hTcxDec->conLastFrameLevel = (Word16) floatToFixed( st->hTcxDec->LastFrameLevel_bfi, 15 - st->hTcxDec->conLastFrameLevel_e ); + if ( st->hTcxDec && st->hTcxDec->conNoiseLevelMemory_e[0] < 0 ) + { + set16_fx( st->hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); + } + IF( st->hTcxDec ) + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + IF( st->hTcxDec ) + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + IF( st->hTcxDec ) + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hTcxDec->old_excFB_fx[p] = (Word16) ( st->hTcxDec->old_excFB[p] * ( 1u << st->Q_exc ) ); + } + IF( st->hFdCngDec && st->hFdCngDec->hFdCngCom ) + floatToFixed_arr( st->hFdCngDec->hFdCngCom->A_cng_flt, st->hFdCngDec->hFdCngCom->A_cng, 15, 17 ); + // st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15); + + IF( hCPE->hCoreCoder[n]->hTcxLtpDec ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float, hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32, q_output, L_FRAME48k ); + floatToFixed_arrL( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float, hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32, q_output, TCXLTP_MAX_DELAY ); + floatToFixed_arrL( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, Q11, 111 ); + } + + + /*cldfb struct*/ + + /*------------------fix-to-fix-start---------------------*/ + /*core_switching_post_dec*/ + if ( hCPE->hCoreCoder[n]->hHQ_core != NULL ) + { + hCPE->hCoreCoder[n]->hHQ_core->Q_old_postdec = 0; + hCPE->hCoreCoder[n]->hHQ_core->Q_old_wtda = 0; + } + + /*-------------------cldfb-start-------------------------*/ + + floatToFixed_arrL( hCPE->hCoreCoder[n]->bpf_noise_buf_float, hCPE->hCoreCoder[n]->bpf_noise_buf_32, 11, L_FRAME_16k ); + if ( hCPE->hCoreCoder[n]->cldfbAna != NULL ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->cldfbAna->cldfb_state, hCPE->hCoreCoder[n]->cldfbAna->cldfb_state_fx, 10, hCPE->hCoreCoder[n]->cldfbAna->cldfb_size ); + } + if ( hCPE->hCoreCoder[n]->cldfbSyn != NULL ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->cldfbSyn->cldfb_state, hCPE->hCoreCoder[n]->cldfbSyn->cldfb_state_fx, 4, hCPE->hCoreCoder[n]->cldfbSyn->p_filter_length ); + } + if ( hCPE->hCoreCoder[n]->cldfbBPF != NULL ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->cldfbBPF->cldfb_state, hCPE->hCoreCoder[n]->cldfbBPF->cldfb_state_fx, 11, hCPE->hCoreCoder[n]->cldfbBPF->cldfb_size ); + } + + + /*-------------------cldfb-end---------------------------*/ + + floatToFixed_arr( sts[n]->prev_synth_buffer, hCPE->hCoreCoder[n]->prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); + } + + IF( hCPE->output_mem[0] != NULL ) + { + floatToFixed_arrL( hCPE->output_mem[0], hCPE->output_mem_fx[0], Q11, NS2SA( hCPE->hCoreCoder[0]->output_Fs, 3125000 ) ); + } + IF( hCPE->output_mem[1] != NULL ) + { + floatToFixed_arrL( hCPE->output_mem[1], hCPE->output_mem_fx[1], Q11, NS2SA( hCPE->hCoreCoder[0]->output_Fs, 3125000 ) ); + } + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + + IF( hCPE->hStereoDft != NULL ) + { + IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) + { + FOR( Word32 p = 0; p < L_FRAME48k; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << q_output ) ); + } + FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q_output ) ); + } + } + } + + IF( hCPE->input_mem_LB[n] != NULL ) + { + FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) + { + hCPE->input_mem_LB_fx[n][ind] = (Word32) ( hCPE->input_mem_LB[n][ind] * ( 1 << q_output ) ); + } + } + + //FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) + //{ + // hCPE->prev_hb_synth_fx[n][k] = (Word32) ( hCPE->prev_hb_synth[n][k] * ( 1 << q_output ) ); + //} + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->prev_synth_fx[n][k] = (Word32) ( hCPE->prev_synth[n][k] * ( 1 << q_output ) ); + } + } + } + + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->targetEnergyPrev ) + f2me_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->dmxEnergyPrev ) + f2me_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); + IF( st_ivas->hParamMC && st_ivas->hParamMC->icld_q ) + floatToFixed_arr16( st_ivas->hParamMC->icld_q, st_ivas->hParamMC->icld_q_fx, 8, st_ivas->hParamMC->hMetadataPMC->num_parameter_bands * st_ivas->hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); + IF( st_ivas->hParamMC && st_ivas->hParamMC->ls_conv_dmx_matrix ) + floatToFixed_arr32( st_ivas->hParamMC->ls_conv_dmx_matrix, st_ivas->hParamMC->ls_conv_dmx_matrix_fx, 15, st_ivas->hDecoderConfig->nchan_out * ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) ); + IF( st_ivas->hLsSetUpConversion ) + FOR( Word16 chOutIdx = 0; chOutIdx < st_ivas->hDecoderConfig->nchan_out; chOutIdx++ ) + { + FOR( Word16 chInIdx = 0; chInIdx < st_ivas->nchan_transport; chInIdx++ ) + { + st_ivas->hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx] = float_to_fix( st_ivas->hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx], 30 ); /*Q30*/ + } + } + + +#endif // Float to fix + if ( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } +#if 1 // Fix to float + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + hCPE = st_ivas->hCPE[cpe_id]; + sts = hCPE->hCoreCoder; + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + st = hCPE->hCoreCoder[ch]; + st->hTcxDec->tcxltp_last_gain_unmodified_float = fixedToFloat(st->hTcxLtpDec->tcxltp_gain, 15); + //st->hTcxDec->tcxltp_last_gain_unmodified_float = st->hTcxLtpDec->tcxltp_gain_float; + IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) + { + // 16bit to u8bit + FOR( l = 0; l < IGF_START_MX; l++ ) + { + sts[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t) sts[ch]->hIGFDec->infoTCXNoise_evs[l]; + } + + IF( !sts[0]->bfi || ( sts[0]->bfi && sts[ch]->core != ACELP_CORE ) ) + { + me2f_buf( sts[ch]->hIGFDec->virtualSpec, sts[ch]->hIGFDec->virtualSpec_e, sts[ch]->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); + } + } + IF( st->hTonalMDCTConc != NULL ) + { + //st->hTonalMDCTConc->scf_fadeout_flt = fixedToFloat( st->hTonalMDCTConc->scf_fadeout, 15 ); + //st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); + if ( hCPE->hCoreCoder[ch]->bfi && st->tonal_mdct_plc_active ) + { + //st->hTonalMDCTConc->nFramesLost_float = fix16_to_float( st->hTonalMDCTConc->nFramesLost, Q1 ); + } + } + + if ( sts[ch]->last_core != -1 && sts[ch]->nbLostCmpt == 1 ) + { + if ( !( sts[ch]->rf_flag && sts[ch]->use_partial_copy && ( sts[ch]->rf_frame_type == RF_TCXTD1 || sts[ch]->rf_frame_type == RF_TCXTD2 ) ) ) + { + IF( sts[ch]->hTonalMDCTConc != NULL && sts[ch]->last_core == TCX_20_CORE && sts[ch]->second_last_core == TCX_20_CORE && ( ( sts[ch]->old_fpitch <= L_shl( sts[ch]->L_frame, 15 ) ) || ( sts[ch]->hTcxDec->tcxltp_last_gain_unmodified <= 13107 /*0.4f*/ ) ) + /* it is fine to call the detection even if no ltp information + is available, meaning that st->old_fpitch == + st->tcxltp_second_last_pitch == st->L_frame */ + && ( sts[ch]->old_fpitch == sts[ch]->hTcxDec->tcxltp_second_last_pitch ) && !sts[ch]->last_tns_active && !sts[ch]->second_last_tns_active ) + { + + if ( sts[ch]->hTonalMDCTConc->pTCI->numIndexes < MAX_NUMBER_OF_IDX ) + { + FOR( i = 0; i < sts[ch]->hTonalMDCTConc->pTCI->numIndexes; i++ ) + { + sts[ch]->hTonalMDCTConc->pTCI->phaseDiff_float[i] = fixedToFloat( sts[ch]->hTonalMDCTConc->pTCI->phaseDiff[i], Q12 ); + } + FOR( i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++ ) + { + sts[ch]->hTonalMDCTConc->pTCI->phase_currentFramePredicted_float[i] = fixedToFloat( sts[ch]->hTonalMDCTConc->pTCI->phase_currentFramePredicted[i], Q13 ); + } + } + } + } + } + } + + FOR( n = 0; n < 2; n++ ) + { + st = hCPE->hCoreCoder[n]; + sts = hCPE->hCoreCoder; + IF( st->hTcxDec ) + st->hTcxDec->CngLevelBackgroundTrace_bfi = me2f_16( st->hTcxDec->conCngLevelBackgroundTrace, st->hTcxDec->conCngLevelBackgroundTrace_e ); + IF( st->hTonalMDCTConc && st->hTonalMDCTConc->lastPcmOut_float ) + fixedToFloat_arr( st->hTonalMDCTConc->lastPcmOut, st->hTonalMDCTConc->lastPcmOut_float, 0, st->hTonalMDCTConc->nSamples ); + IF( sts[0]->bfi == 0 && !st->hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive ) + fixedToFloat_arr( st->hTonalMDCTConc->secondLastPcmOut, st->hTonalMDCTConc->secondLastPcmOut_float, 0, st->hTonalMDCTConc->nSamples / 2 ); + fixedToFloat_arr( st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synthFB, st->Q_syn, st->hTcxDec->old_synth_lenFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + fixedToFloat_arr( st->hTcxDec->old_synth, st->hTcxDec->old_synth_float, st->Q_syn, 1280 ); + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hTcxDec->old_excFB[p] = (float) ( st->hTcxDec->old_excFB_fx[p] ) / ( 1u << st->Q_exc ); + } + for ( int p = 0; p < st->L_frame / 2; p++ ) + { + st->hTcxDec->old_syn_Overl_float[p] = (float) st->hTcxDec->old_syn_Overl[p] * 2 * ( 1u << st->Q_syn ); + st->hTcxDec->syn_Overl_TDACFB_float[p] = (float) st->hTcxDec->syn_Overl_TDACFB[p] * 2 * (float) pow( 2, st->Q_syn ); + st->hTcxDec->syn_Overl_TDAC_float[p] = (float) st->hTcxDec->syn_Overl_TDAC[p] * 2 * (float) pow( 2, st->Q_syn ); + } + for ( int p = 0; p < 640; p++ ) + { + st->hHQ_core->old_outLB[p] = (float) st->hHQ_core->old_out_LB_fx[p] / ( 1u << st->Q_syn ); + } + + if ( !st->tcxonly ) + { + fixedToFloat_arr( st->p_bpf_noise_buf, st->p_bpf_noise_buf_float, 0, L_FRAME_16k ); + } + + fixedToFloat_arr( st->hTcxDec->syn_OverlFB, st->hTcxDec->syn_OverlFB_float, st->Q_syn, L_FRAME_MAX / 2 ); + fixedToFloat_arr( st->hTcxDec->syn_Overl, st->hTcxDec->syn_Overl_float, st->Q_syn, L_FRAME32k / 2 ); + st->hTcxDec->tcxltp_last_gain_unmodified_float = fix16_to_float( st->hTcxDec->tcxltp_last_gain_unmodified, Q15 ); + st->hTcxDec->conceal_eof_gain_float = fix16_to_float( st->hTcxDec->conceal_eof_gain, Q14 ); + + /*-------------------cldfb-start-------------------------*/ + + /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ + + if ( sts[n]->cldfbAna != NULL ) + { + fixedToFloat_arrL( sts[n]->cldfbAna->cldfb_state_fx, sts[n]->cldfbAna->cldfb_state, 10, sts[n]->cldfbAna->cldfb_state_length ); + } + if ( sts[n]->cldfbSyn != NULL ) + { + fixedToFloat_arrL( sts[n]->cldfbSyn->cldfb_state_fx, sts[n]->cldfbSyn->cldfb_state, 4, sts[n]->cldfbSyn->p_filter_length ); + } + if ( sts[n]->cldfbBPF != NULL ) + { + fixedToFloat_arrL( sts[n]->cldfbBPF->cldfb_state_fx, sts[n]->cldfbBPF->cldfb_state, 11, sts[n]->cldfbBPF->cldfb_state_length ); + } + + /*-------------------cldfb-end---------------------------*/ + + IF( sts[n]->hHQ_core != NULL ) + { + fixedToFloat_arr( sts[n]->hHQ_core->old_out_fx, sts[n]->hHQ_core->old_out, 0, L_FRAME48k ); + } + + /*------------------reset-code-start---------------------*/ + + /*reset function flags*/ + Word8 reset_wb_tbe_synth = 0; + Word8 reset_swb_tbe = 0; + + /* reset WB BWE buffers */ + + IF( NE_16( sts[n]->last_extl, WB_BWE ) && EQ_16( sts[n]->extl, WB_BWE ) && sts[n]->hBWE_FD != NULL ) + { + + IF( NE_16( sts[n]->last_extl, SWB_BWE ) && NE_16( sts[n]->last_extl, FB_BWE ) ) + { + sts[n]->hBWE_FD->prev_mode = sts[n]->hBWE_FD->prev_mode; + } + sts[n]->hBWE_FD->prev_L_swb_norm = sts[n]->hBWE_FD->prev_L_swb_norm; + sts[n]->hBWE_FD->prev_flag = sts[n]->hBWE_FD->prev_flag; + } + + /* reset TBE buffers */ + if ( sts[n]->hBWE_TD != NULL ) + { + IF( ( ( EQ_16( sts[n]->extl, SWB_TBE ) || EQ_16( sts[n]->extl, FB_TBE ) || EQ_16( sts[n]->extl, SWB_CNG ) ) && + ( NE_16( sts[n]->L_frame, sts[n]->last_L_frame ) || ( NE_16( sts[n]->last_extl, SWB_TBE ) && NE_16( sts[n]->last_extl, FB_TBE ) ) || EQ_16( sts[n]->last_core, HQ_CORE ) ) ) || + ( LT_16( sts[n]->bwidth, sts[n]->last_bwidth ) && NE_16( sts[n]->last_extl, SWB_TBE ) ) || sts[n]->old_ppp_mode || ( ( EQ_16( sts[n]->prev_coder_type, AUDIO ) || EQ_16( sts[n]->prev_coder_type, INACTIVE ) ) && sts[n]->bws_cnt > 0 ) || ( sts[n]->bws_cnt == 0 && EQ_16( sts[n]->prev_bws_cnt, N_WS2N_FRAMES ) ) ) + { + + reset_swb_tbe = 1; + + IF( EQ_16( output_frame, L_FRAME16k ) ) + { + fixedToFloat_arr( sts[n]->hBWE_TD->mem_resamp_HB_32k_fx, sts[n]->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + } + fixedToFloat_arr( sts[n]->hBWE_TD->int_3_over_2_tbemem_dec_fx, sts[n]->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN ); + } + ELSE IF( sts[n]->hBWE_TD != NULL && ( sts[n]->last_core == TCX_20_CORE || sts[n]->last_core == TCX_10_CORE ) ) + { + /*------------TBEreset_dec_ivas_fx-start------------------*/ + IF( EQ_16( sts[n]->bwidth, WB ) ) + { + reset_wb_tbe_synth = 1; + + fixedToFloat_arr( sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); + } + ELSE IF( EQ_16( sts[n]->bwidth, SWB ) || EQ_16( sts[n]->bwidth, FB ) ) + { + reset_swb_tbe = 1; + fixedToFloat_arr( sts[n]->hBWE_TD->int_3_over_2_tbemem_dec_fx, sts[n]->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN ); // setting to zero + fixedToFloat_arr( sts[n]->hBWE_TD->mem_resamp_HB_32k_fx, sts[n]->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); // setting to zero + } + /*------------TBEreset_dec_ivas_fx-end--------------------*/ + } + + IF( NE_16( sts[n]->last_extl, WB_TBE ) && EQ_16( sts[n]->extl, WB_TBE ) ) + { + reset_wb_tbe_synth = 1; + fixedToFloat_arr( sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); // setting to zero + } + + IF( reset_swb_tbe ) + { + fixedToFloat_arr( sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); // setting to zero + } + IF( reset_wb_tbe_synth ) + { + fixedToFloat_arr( sts[n]->hBWE_TD->state_lsyn_filt_shb_fx, sts[n]->hBWE_TD->state_lsyn_filt_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); // setting to zero + fixedToFloat_arr( sts[n]->hBWE_TD->state_lsyn_filt_dwn_shb_fx, sts[n]->hBWE_TD->state_lsyn_filt_dwn_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); // setting to zero + fixedToFloat_arr( sts[n]->hBWE_TD->mem_resamp_HB_fx, sts[n]->hBWE_TD->mem_resamp_HB, 0, INTERP_3_1_MEM_LEN ); // setting to zero + } + } + + /*------------------reset-code-end-----------------------*/ + + + for ( int p = 0; p < L_FRAME48k; p++ ) + { + + IF( hCPE->hCoreCoder[n]->hTcxLtpDec ) + { + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q_output ); + if ( p < TCXLTP_MAX_DELAY ) + { + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q_output ); + } + } + } + if ( hCPE->hCoreCoder[n]->hTcxDec ) + { + for ( k = 0; k < 111; k++ ) + { + hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ( 1u << q_output ); + } + } + IF( hCPE->hCoreCoder[n]->hTcxLtpDec ) + + if ( ( hCPE->hCoreCoder[n]->codec_mode == MODE1 && hCPE->hCoreCoder[n]->hTcxDec != NULL ) && ( ( hCPE->hCoreCoder[n]->core == ACELP_CORE && !( hCPE->hCoreCoder[n]->bfi == 1 && hCPE->hCoreCoder[n]->con_tcx == 1 ) ) || hCPE->hCoreCoder[n]->core == HQ_CORE ) ) + { + fixedToFloat_arr( hCPE->hCoreCoder[n]->hTcxDec->synth_history_fx, hCPE->hCoreCoder[n]->hTcxDec->synth_history, 0, output_frame ); + } + } + + IF( hCPE->hStereoDft != NULL ) + { + IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) + { + FOR( Word32 p = 0; p < L_FRAME48k; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q_output ); + } + FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q_output ); + } + } + } + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + IF( hCPE->output_mem[n] != NULL ) + { + FOR( k = 0; k < NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->output_mem[n][k] = (float) hCPE->output_mem_fx[n][k] / ( 1u << 11 ); + } + } + IF( hCPE->hCoreCoder[n] != NULL ) + { + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) + { + hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << q_output ); + } + } + IF( hCPE->input_mem[n] != NULL ) + { + FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) + { + hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << q_output ) ); + } + } + //FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) + //{ + // hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << q_output ); + //} + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << q_output ); + } + } + } + + + IF( st_ivas->hCPE[0]->hCoreCoder[0]->igf ) + { + IF( !hMCT->currBlockDataCnt ) + { + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + IF( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->igf ) + { + me2f_buf( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec_e, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); + FOR( l = 0; l < IGF_START_MX; l++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t) st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise_evs[l]; + } + } + } + } + } + } + + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->targetEnergyPrev ) + me2f_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx ) + me2f_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); + + FOR( i = 0; i < 12; i++ ) + if ( p_output[i] ) + { + fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, L_FRAME48k ); + free( p_output_fx[i] ); + } +#endif // Fix to float +#else + if ( ( error = ivas_mct_dec( st_ivas, p_output, output_frame, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + + /* HP filtering */ + for ( n = 0; n < st_ivas->nchan_transport; n++ ) + { + if ( n != LFE_CHANNEL ) + { +#ifdef IVAS_FLOAT_FIXED + Word32 p_output_fix[L_FRAME48k]; + for ( int i = 0; i < output_frame; i++ ) + { + p_output_fix[i] = (Word32) ( p_output[n][i] * ( 1 << 11 ) ); + } + hp20_fix32( p_output_fix, output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); + for ( int i = 0; i < output_frame; i++ ) + { + p_output[n][i] = (float) p_output_fix[i] / ( 1 << 11 ); + } #else hp20_flt( p_output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs ); #endif // IVAS_FLOAT_FIXED @@ -2557,54 +4052,565 @@ ivas_error ivas_jbm_dec_tc( p_output_fx[i] = malloc( L_FRAME48k * sizeof( Word32 ) ); floatToFixed_arrL( p_output[i], p_output_fx[i], q, output_frame ); } - FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) + FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) + { + FOR( j = 0; j < st_ivas->nchan_transport; j++ ) + { + st_ivas->hLsSetUpConversion->dmxMtx_fx[j][i] = float_to_fix( st_ivas->hLsSetUpConversion->dmxMtx[j][i], Q30 ); + } + } + ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, output_frame, p_output_fx, p_output_fx ); + FOR( i = 0; i < max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i ) + { + fixedToFloat_arrL( p_output_fx[i], p_output[i], q, output_frame ); + free( p_output_fx[i] ); + } +#else + ivas_ls_setup_conversion( st_ivas, st_ivas->nchan_transport, output_frame, p_output, p_output ); +#endif + } + else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) + { + ivas_mc2sba( st_ivas->hIntSetup, p_output, p_output, output_frame, st_ivas->hOutSetup.ambisonics_order, 0.f ); + } + } + } + else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + { + /* LFE channel decoder */ +#ifdef IVAS_FLOAT_FIXED + Word32 *p_output_fx1; + + p_output_fx1 = (Word32 *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ); + + ivas_lfe_dec_fx( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output_fx1 ); + + for ( int p = 0; p < 960; p++ ) + { + p_output[LFE_CHANNEL][p] = (float) p_output_fx1[p] / ONE_IN_Q9; + } + free( p_output_fx1 ); +#else + ivas_lfe_dec( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output[LFE_CHANNEL] ); +#endif // IVAS_FLOAT_FIXED + + ivas_mc_paramupmix_dec_read_BS( st_ivas, st, st_ivas->hMCParamUpmix, &nb_bits_metadata[0] ); + +#ifdef IVAS_FLOAT_FIXED +#if 1 // Float to fix + + Decoder_State *st, **sts; + MCT_DEC_HANDLE hMCT; + CPE_DEC_HANDLE hCPE; + + Word16 ch, nCPE, cpe_id; + Word16 q_output = 11; + Word16 k, l, i, j; + + nCPE = st_ivas->nCPE; + move16(); + hMCT = st_ivas->hMCT; + FOR( i = 0; i < 12; i++ ) + if ( p_output[i] ) + { + p_output_fx[i] = malloc( sizeof( Word32 ) * L_FRAME48k ); + floatToFixed_arrL( p_output[i], p_output_fx[i], Q11, L_FRAME48k ); + } + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + hCPE = st_ivas->hCPE[cpe_id]; + sts = hCPE->hCoreCoder; + + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + st = hCPE->hCoreCoder[n]; + IF( st->hTonalMDCTConc ) + { + + FOR( i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) + { + st->hTonalMDCTConc->scaleFactorsBackground_fx[i] = float_to_fix( st->hTonalMDCTConc->scaleFactorsBackground_flt[i], 15 ); + } + //st->hTonalMDCTConc->scf_fadeout = float_to_fix16( st->hTonalMDCTConc->scf_fadeout_flt, 15 ); + if ( hCPE->hCoreCoder[n]->bfi && st->tonal_mdct_plc_active ) + { + FOR( i = 0; i < FDNS_NPTS; i++ ) + { + f2me_16( st->hTonalMDCTConc->secondLastBlockData.scaleFactors_float[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ); + } + FOR( i = 0; i < 30; i++ ) + { + float pd = st->hTonalMDCTConc->pTCI->phaseDiff_float[i]; + if ( pd >= PI2 ) + pd = fmodf( pd, PI2 ) - PI2; + st->hTonalMDCTConc->pTCI->phaseDiff[i] = (Word16) floatToFixed( pd, Q12 ); + } + FOR( i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++ ) + { + float pd = st->hTonalMDCTConc->pTCI->phase_currentFramePredicted_float[i]; + pd = fmodf( pd, PI2 ); + st->hTonalMDCTConc->pTCI->phase_currentFramePredicted[i] = (Word16) ( pd * ( 1u << Q13 ) ); + } + // st->hTonalMDCTConc->nFramesLost = float_to_fix16( st->hTonalMDCTConc->nFramesLost, Q1 ); + } + //f2me( st->hTonalMDCTConc->last_block_nrg_flt, &st->hTonalMDCTConc->last_block_nrg, &st->hTonalMDCTConc->last_block_nrg_exp ); + } + // st->old_fpitch = float_to_fix(st->old_fpitch_float, 16); + st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); + + IF( sts[n]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) + { + // u8bit to 16bit + FOR( l = 0; l < IGF_START_MX; l++ ) + { + sts[n]->hIGFDec->infoTCXNoise_evs[l] = (Word16) sts[n]->hIGFDec->infoTCXNoise[l]; + } + } + + + IF( st->hTcxDec ) + f2me_16( st->hTcxDec->CngLevelBackgroundTrace_bfi, &st->hTcxDec->conCngLevelBackgroundTrace, &st->hTcxDec->conCngLevelBackgroundTrace_e ); + if ( st->hTcxDec && st->hTcxDec->conLastFrameLevel_e < 0 ) + { + st->hTcxDec->conLastFrameLevel_e = 0; + } + if ( st->hTcxDec && st->hTcxDec->conNoiseLevelMemory_e[0] < 0 ) + { + set16_fx( st->hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); + } + IF( st->hTcxDec ) + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + IF( st->hTcxDec ) + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + IF( st->hTcxDec ) + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hTcxDec->old_excFB_fx[p] = (Word16) ( st->hTcxDec->old_excFB[p] * ( 1u << st->Q_exc ) ); + } + IF( st->hFdCngDec && st->hFdCngDec->hFdCngCom ) + floatToFixed_arr( st->hFdCngDec->hFdCngCom->A_cng_flt, st->hFdCngDec->hFdCngCom->A_cng, 15, 17 ); + // st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15); + + IF( hCPE->hCoreCoder[n]->hTcxLtpDec ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float, hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32, q_output, L_FRAME48k ); + floatToFixed_arrL( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float, hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32, q_output, TCXLTP_MAX_DELAY ); + floatToFixed_arrL( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, Q11, 111 ); + } + + + /*cldfb struct*/ + + /*------------------fix-to-fix-start---------------------*/ + /*core_switching_post_dec*/ + if ( hCPE->hCoreCoder[n]->hHQ_core != NULL ) + { + hCPE->hCoreCoder[n]->hHQ_core->Q_old_postdec = 0; + hCPE->hCoreCoder[n]->hHQ_core->Q_old_wtda = 0; + } + + /*-------------------cldfb-start-------------------------*/ + + floatToFixed_arrL( hCPE->hCoreCoder[n]->bpf_noise_buf_float, hCPE->hCoreCoder[n]->bpf_noise_buf_32, 11, L_FRAME_16k ); + if ( hCPE->hCoreCoder[n]->cldfbAna != NULL ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->cldfbAna->cldfb_state, hCPE->hCoreCoder[n]->cldfbAna->cldfb_state_fx, 10, hCPE->hCoreCoder[n]->cldfbAna->cldfb_size ); + } + if ( hCPE->hCoreCoder[n]->cldfbSyn != NULL ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->cldfbSyn->cldfb_state, hCPE->hCoreCoder[n]->cldfbSyn->cldfb_state_fx, 4, hCPE->hCoreCoder[n]->cldfbSyn->p_filter_length ); + } + if ( hCPE->hCoreCoder[n]->cldfbBPF != NULL ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->cldfbBPF->cldfb_state, hCPE->hCoreCoder[n]->cldfbBPF->cldfb_state_fx, 11, hCPE->hCoreCoder[n]->cldfbBPF->cldfb_size ); + } + + + /*-------------------cldfb-end---------------------------*/ + + floatToFixed_arr( sts[n]->prev_synth_buffer, hCPE->hCoreCoder[n]->prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); + } + + IF( hCPE->output_mem[0] != NULL ) + { + floatToFixed_arrL( hCPE->output_mem[0], hCPE->output_mem_fx[0], Q11, NS2SA( hCPE->hCoreCoder[0]->output_Fs, 3125000 ) ); + } + IF( hCPE->output_mem[1] != NULL ) + { + floatToFixed_arrL( hCPE->output_mem[1], hCPE->output_mem_fx[1], Q11, NS2SA( hCPE->hCoreCoder[0]->output_Fs, 3125000 ) ); + } + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + + IF( hCPE->hStereoDft != NULL ) + { + IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) + { + FOR( Word32 p = 0; p < L_FRAME48k; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << q_output ) ); + } + FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q_output ) ); + } + } + } + + IF( hCPE->input_mem_LB[n] != NULL ) + { + FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) + { + hCPE->input_mem_LB_fx[n][ind] = (Word32) ( hCPE->input_mem_LB[n][ind] * ( 1 << q_output ) ); + } + } + + //FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) + //{ + // hCPE->prev_hb_synth_fx[n][k] = (Word32) ( hCPE->prev_hb_synth[n][k] * ( 1 << q_output ) ); + //} + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->prev_synth_fx[n][k] = (Word32) ( hCPE->prev_synth[n][k] * ( 1 << q_output ) ); + } + } + } + + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->targetEnergyPrev ) + f2me_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->dmxEnergyPrev ) + f2me_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); + IF( st_ivas->hParamMC && st_ivas->hParamMC->icld_q ) + floatToFixed_arr16( st_ivas->hParamMC->icld_q, st_ivas->hParamMC->icld_q_fx, 8, st_ivas->hParamMC->hMetadataPMC->num_parameter_bands * st_ivas->hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); + IF( st_ivas->hParamMC && st_ivas->hParamMC->ls_conv_dmx_matrix ) + floatToFixed_arr32( st_ivas->hParamMC->ls_conv_dmx_matrix, st_ivas->hParamMC->ls_conv_dmx_matrix_fx, 15, st_ivas->hDecoderConfig->nchan_out * ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) ); + IF( st_ivas->hLsSetUpConversion ) + FOR( Word16 chOutIdx = 0; chOutIdx < st_ivas->hDecoderConfig->nchan_out; chOutIdx++ ) + { + FOR( Word16 chInIdx = 0; chInIdx < st_ivas->nchan_transport; chInIdx++ ) + { + st_ivas->hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx] = float_to_fix( st_ivas->hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx], 30 ); /*Q30*/ + } + } + + +#endif // Float to fix + if ( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } +#if 1 // Fix to float + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + hCPE = st_ivas->hCPE[cpe_id]; + sts = hCPE->hCoreCoder; + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + st = hCPE->hCoreCoder[ch]; + st->hTcxDec->tcxltp_last_gain_unmodified_float = fixedToFloat(st->hTcxLtpDec->tcxltp_gain, 15); + //st->hTcxDec->tcxltp_last_gain_unmodified_float = st->hTcxLtpDec->tcxltp_gain_float; + IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) + { + // 16bit to u8bit + FOR( l = 0; l < IGF_START_MX; l++ ) + { + sts[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t) sts[ch]->hIGFDec->infoTCXNoise_evs[l]; + } + + IF( !sts[0]->bfi || ( sts[0]->bfi && sts[ch]->core != ACELP_CORE ) ) + { + me2f_buf( sts[ch]->hIGFDec->virtualSpec, sts[ch]->hIGFDec->virtualSpec_e, sts[ch]->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); + } + } + IF( st->hTonalMDCTConc != NULL ) + { + //st->hTonalMDCTConc->scf_fadeout_flt = fixedToFloat( st->hTonalMDCTConc->scf_fadeout, 15 ); + //st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); + if ( hCPE->hCoreCoder[ch]->bfi && st->tonal_mdct_plc_active ) + { + //st->hTonalMDCTConc->nFramesLost_float = fix16_to_float( st->hTonalMDCTConc->nFramesLost, Q1 ); + } + } + + if ( sts[ch]->last_core != -1 && sts[ch]->nbLostCmpt == 1 ) + { + if ( !( sts[ch]->rf_flag && sts[ch]->use_partial_copy && ( sts[ch]->rf_frame_type == RF_TCXTD1 || sts[ch]->rf_frame_type == RF_TCXTD2 ) ) ) + { + IF( sts[ch]->hTonalMDCTConc != NULL && sts[ch]->last_core == TCX_20_CORE && sts[ch]->second_last_core == TCX_20_CORE && ( ( sts[ch]->old_fpitch <= L_shl( sts[ch]->L_frame, 15 ) ) || ( sts[ch]->hTcxDec->tcxltp_last_gain_unmodified <= 13107 /*0.4f*/ ) ) + /* it is fine to call the detection even if no ltp information + is available, meaning that st->old_fpitch == + st->tcxltp_second_last_pitch == st->L_frame */ + && ( sts[ch]->old_fpitch == sts[ch]->hTcxDec->tcxltp_second_last_pitch ) && !sts[ch]->last_tns_active && !sts[ch]->second_last_tns_active ) + { + + if ( sts[ch]->hTonalMDCTConc->pTCI->numIndexes < MAX_NUMBER_OF_IDX ) + { + FOR( i = 0; i < sts[ch]->hTonalMDCTConc->pTCI->numIndexes; i++ ) + { + sts[ch]->hTonalMDCTConc->pTCI->phaseDiff_float[i] = fixedToFloat( sts[ch]->hTonalMDCTConc->pTCI->phaseDiff[i], Q12 ); + } + FOR( i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++ ) + { + sts[ch]->hTonalMDCTConc->pTCI->phase_currentFramePredicted_float[i] = fixedToFloat( sts[ch]->hTonalMDCTConc->pTCI->phase_currentFramePredicted[i], Q13 ); + } + } + } + } + } + } + + FOR( n = 0; n < 2; n++ ) + { + st = hCPE->hCoreCoder[n]; + sts = hCPE->hCoreCoder; + IF( st->hTcxDec ) + st->hTcxDec->CngLevelBackgroundTrace_bfi = me2f_16( st->hTcxDec->conCngLevelBackgroundTrace, st->hTcxDec->conCngLevelBackgroundTrace_e ); + IF( st->hTonalMDCTConc && st->hTonalMDCTConc->lastPcmOut_float ) + fixedToFloat_arr( st->hTonalMDCTConc->lastPcmOut, st->hTonalMDCTConc->lastPcmOut_float, 0, st->hTonalMDCTConc->nSamples ); + IF( sts[0]->bfi == 0 && !st->hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive ) + fixedToFloat_arr( st->hTonalMDCTConc->secondLastPcmOut, st->hTonalMDCTConc->secondLastPcmOut_float, 0, st->hTonalMDCTConc->nSamples / 2 ); + fixedToFloat_arr( st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synthFB, st->Q_syn, st->hTcxDec->old_synth_lenFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + fixedToFloat_arr( st->hTcxDec->old_synth, st->hTcxDec->old_synth_float, st->Q_syn, 1280 ); + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hTcxDec->old_excFB[p] = (float) ( st->hTcxDec->old_excFB_fx[p] ) / ( 1u << st->Q_exc ); + } + for ( int p = 0; p < st->L_frame / 2; p++ ) + { + st->hTcxDec->old_syn_Overl_float[p] = (float) st->hTcxDec->old_syn_Overl[p] * 2 * ( 1u << st->Q_syn ); + st->hTcxDec->syn_Overl_TDACFB_float[p] = (float) st->hTcxDec->syn_Overl_TDACFB[p] * 2 * (float) pow( 2, st->Q_syn ); + st->hTcxDec->syn_Overl_TDAC_float[p] = (float) st->hTcxDec->syn_Overl_TDAC[p] * 2 * (float) pow( 2, st->Q_syn ); + } + for ( int p = 0; p < 640; p++ ) + { + st->hHQ_core->old_outLB[p] = (float) st->hHQ_core->old_out_LB_fx[p] / ( 1u << st->Q_syn ); + } + + if ( !st->tcxonly ) + { + fixedToFloat_arr( st->p_bpf_noise_buf, st->p_bpf_noise_buf_float, 0, L_FRAME_16k ); + } + + fixedToFloat_arr( st->hTcxDec->syn_OverlFB, st->hTcxDec->syn_OverlFB_float, st->Q_syn, L_FRAME_MAX / 2 ); + fixedToFloat_arr( st->hTcxDec->syn_Overl, st->hTcxDec->syn_Overl_float, st->Q_syn, L_FRAME32k / 2 ); + st->hTcxDec->tcxltp_last_gain_unmodified_float = fix16_to_float( st->hTcxDec->tcxltp_last_gain_unmodified, Q15 ); + st->hTcxDec->conceal_eof_gain_float = fix16_to_float( st->hTcxDec->conceal_eof_gain, Q14 ); + + /*-------------------cldfb-start-------------------------*/ + + /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ + + if ( sts[n]->cldfbAna != NULL ) + { + fixedToFloat_arrL( sts[n]->cldfbAna->cldfb_state_fx, sts[n]->cldfbAna->cldfb_state, 10, sts[n]->cldfbAna->cldfb_state_length ); + } + if ( sts[n]->cldfbSyn != NULL ) + { + fixedToFloat_arrL( sts[n]->cldfbSyn->cldfb_state_fx, sts[n]->cldfbSyn->cldfb_state, 4, sts[n]->cldfbSyn->p_filter_length ); + } + if ( sts[n]->cldfbBPF != NULL ) + { + fixedToFloat_arrL( sts[n]->cldfbBPF->cldfb_state_fx, sts[n]->cldfbBPF->cldfb_state, 11, sts[n]->cldfbBPF->cldfb_state_length ); + } + + /*-------------------cldfb-end---------------------------*/ + + IF( sts[n]->hHQ_core != NULL ) + { + fixedToFloat_arr( sts[n]->hHQ_core->old_out_fx, sts[n]->hHQ_core->old_out, 0, L_FRAME48k ); + } + + /*------------------reset-code-start---------------------*/ + + /*reset function flags*/ + Word8 reset_wb_tbe_synth = 0; + Word8 reset_swb_tbe = 0; + + /* reset WB BWE buffers */ + + IF( NE_16( sts[n]->last_extl, WB_BWE ) && EQ_16( sts[n]->extl, WB_BWE ) && sts[n]->hBWE_FD != NULL ) + { + + IF( NE_16( sts[n]->last_extl, SWB_BWE ) && NE_16( sts[n]->last_extl, FB_BWE ) ) + { + sts[n]->hBWE_FD->prev_mode = sts[n]->hBWE_FD->prev_mode; + } + sts[n]->hBWE_FD->prev_L_swb_norm = sts[n]->hBWE_FD->prev_L_swb_norm; + sts[n]->hBWE_FD->prev_flag = sts[n]->hBWE_FD->prev_flag; + } + + /* reset TBE buffers */ + if ( sts[n]->hBWE_TD != NULL ) + { + IF( ( ( EQ_16( sts[n]->extl, SWB_TBE ) || EQ_16( sts[n]->extl, FB_TBE ) || EQ_16( sts[n]->extl, SWB_CNG ) ) && + ( NE_16( sts[n]->L_frame, sts[n]->last_L_frame ) || ( NE_16( sts[n]->last_extl, SWB_TBE ) && NE_16( sts[n]->last_extl, FB_TBE ) ) || EQ_16( sts[n]->last_core, HQ_CORE ) ) ) || + ( LT_16( sts[n]->bwidth, sts[n]->last_bwidth ) && NE_16( sts[n]->last_extl, SWB_TBE ) ) || sts[n]->old_ppp_mode || ( ( EQ_16( sts[n]->prev_coder_type, AUDIO ) || EQ_16( sts[n]->prev_coder_type, INACTIVE ) ) && sts[n]->bws_cnt > 0 ) || ( sts[n]->bws_cnt == 0 && EQ_16( sts[n]->prev_bws_cnt, N_WS2N_FRAMES ) ) ) + { + + reset_swb_tbe = 1; + + IF( EQ_16( output_frame, L_FRAME16k ) ) + { + fixedToFloat_arr( sts[n]->hBWE_TD->mem_resamp_HB_32k_fx, sts[n]->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + } + fixedToFloat_arr( sts[n]->hBWE_TD->int_3_over_2_tbemem_dec_fx, sts[n]->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN ); + } + ELSE IF( sts[n]->hBWE_TD != NULL && ( sts[n]->last_core == TCX_20_CORE || sts[n]->last_core == TCX_10_CORE ) ) + { + /*------------TBEreset_dec_ivas_fx-start------------------*/ + IF( EQ_16( sts[n]->bwidth, WB ) ) + { + reset_wb_tbe_synth = 1; + + fixedToFloat_arr( sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); + } + ELSE IF( EQ_16( sts[n]->bwidth, SWB ) || EQ_16( sts[n]->bwidth, FB ) ) + { + reset_swb_tbe = 1; + fixedToFloat_arr( sts[n]->hBWE_TD->int_3_over_2_tbemem_dec_fx, sts[n]->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN ); // setting to zero + fixedToFloat_arr( sts[n]->hBWE_TD->mem_resamp_HB_32k_fx, sts[n]->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); // setting to zero + } + /*------------TBEreset_dec_ivas_fx-end--------------------*/ + } + + IF( NE_16( sts[n]->last_extl, WB_TBE ) && EQ_16( sts[n]->extl, WB_TBE ) ) + { + reset_wb_tbe_synth = 1; + fixedToFloat_arr( sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); // setting to zero + } + + IF( reset_swb_tbe ) + { + fixedToFloat_arr( sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); // setting to zero + } + IF( reset_wb_tbe_synth ) + { + fixedToFloat_arr( sts[n]->hBWE_TD->state_lsyn_filt_shb_fx, sts[n]->hBWE_TD->state_lsyn_filt_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); // setting to zero + fixedToFloat_arr( sts[n]->hBWE_TD->state_lsyn_filt_dwn_shb_fx, sts[n]->hBWE_TD->state_lsyn_filt_dwn_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); // setting to zero + fixedToFloat_arr( sts[n]->hBWE_TD->mem_resamp_HB_fx, sts[n]->hBWE_TD->mem_resamp_HB, 0, INTERP_3_1_MEM_LEN ); // setting to zero + } + } + + /*------------------reset-code-end-----------------------*/ + + + for ( int p = 0; p < L_FRAME48k; p++ ) + { + + IF( hCPE->hCoreCoder[n]->hTcxLtpDec ) + { + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q_output ); + if ( p < TCXLTP_MAX_DELAY ) + { + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q_output ); + } + } + } + if ( hCPE->hCoreCoder[n]->hTcxDec ) + { + for ( k = 0; k < 111; k++ ) + { + hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ( 1u << q_output ); + } + } + IF( hCPE->hCoreCoder[n]->hTcxLtpDec ) + + if ( ( hCPE->hCoreCoder[n]->codec_mode == MODE1 && hCPE->hCoreCoder[n]->hTcxDec != NULL ) && ( ( hCPE->hCoreCoder[n]->core == ACELP_CORE && !( hCPE->hCoreCoder[n]->bfi == 1 && hCPE->hCoreCoder[n]->con_tcx == 1 ) ) || hCPE->hCoreCoder[n]->core == HQ_CORE ) ) + { + fixedToFloat_arr( hCPE->hCoreCoder[n]->hTcxDec->synth_history_fx, hCPE->hCoreCoder[n]->hTcxDec->synth_history, 0, output_frame ); + } + } + + IF( hCPE->hStereoDft != NULL ) + { + IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) + { + FOR( Word32 p = 0; p < L_FRAME48k; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q_output ); + } + FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q_output ); + } + } + } + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + IF( hCPE->output_mem[n] != NULL ) + { + FOR( k = 0; k < NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->output_mem[n][k] = (float) hCPE->output_mem_fx[n][k] / ( 1u << 11 ); + } + } + IF( hCPE->hCoreCoder[n] != NULL ) + { + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) + { + hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << q_output ); + } + } + IF( hCPE->input_mem[n] != NULL ) { - FOR( j = 0; j < st_ivas->nchan_transport; j++ ) + FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) { - st_ivas->hLsSetUpConversion->dmxMtx_fx[j][i] = float_to_fix( st_ivas->hLsSetUpConversion->dmxMtx[j][i], Q30 ); + hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << q_output ) ); } } - ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, output_frame, p_output_fx, p_output_fx ); - FOR( i = 0; i < max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i ) + //FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) + //{ + // hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << q_output ); + //} + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) { - fixedToFloat_arrL( p_output_fx[i], p_output[i], q, output_frame ); - free( p_output_fx[i] ); + hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << q_output ); } -#else - ivas_ls_setup_conversion( st_ivas, st_ivas->nchan_transport, output_frame, p_output, p_output ); -#endif } - else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) + } + + + IF( st_ivas->hCPE[0]->hCoreCoder[0]->igf ) + { + IF( !hMCT->currBlockDataCnt ) { - ivas_mc2sba( st_ivas->hIntSetup, p_output, p_output, output_frame, st_ivas->hOutSetup.ambisonics_order, 0.f ); + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + IF( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->igf ) + { + me2f_buf( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec_e, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); + FOR( l = 0; l < IGF_START_MX; l++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t) st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise_evs[l]; + } + } + } + } } } - } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) - { - /* LFE channel decoder */ -#ifdef IVAS_FLOAT_FIXED - Word32 *p_output_fx1; - - p_output_fx1 = (Word32 *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ); - ivas_lfe_dec_fx( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output_fx1 ); + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->targetEnergyPrev ) + me2f_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx ) + me2f_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); - for ( int p = 0; p < 960; p++ ) + FOR( i = 0; i < 12; i++ ) + if ( p_output[i] ) { - p_output[LFE_CHANNEL][p] = (float) p_output_fx1[p] / ONE_IN_Q9; + fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, L_FRAME48k ); + free( p_output_fx[i] ); } - free( p_output_fx1 ); +#endif // Fix to float #else - ivas_lfe_dec( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output[LFE_CHANNEL] ); -#endif // IVAS_FLOAT_FIXED - - ivas_mc_paramupmix_dec_read_BS( st_ivas, st, st_ivas->hMCParamUpmix, &nb_bits_metadata[0] ); - if ( ( error = ivas_mct_dec( st_ivas, p_output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } +#endif /* HP filtering */ for ( n = 0; n < st_ivas->nchan_transport; n++ ) @@ -2698,16 +4704,525 @@ ivas_error ivas_jbm_dec_tc( { if ( ( error = ivas_cpe_dec( st_ivas, 0, p_output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { - return error; + return error; + } + } +#endif // IVAS_FLOAT_FIXED + else if ( st_ivas->nCPE > 1 ) + { + #ifdef IVAS_FLOAT_FIXED +#if 1 // Float to fix + + Decoder_State *st, **sts; + MCT_DEC_HANDLE hMCT; + CPE_DEC_HANDLE hCPE; + + Word16 ch, nCPE, cpe_id; + Word16 q_output = 11; + Word16 k, l, i, j; + + nCPE = st_ivas->nCPE; + move16(); + hMCT = st_ivas->hMCT; + FOR( i = 0; i < 12; i++ ) + if ( p_output[i] ) + { + p_output_fx[i] = malloc( sizeof( Word32 ) * L_FRAME48k ); + floatToFixed_arrL( p_output[i], p_output_fx[i], Q11, L_FRAME48k ); + } + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + hCPE = st_ivas->hCPE[cpe_id]; + sts = hCPE->hCoreCoder; + + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + st = hCPE->hCoreCoder[n]; + IF( st->hTonalMDCTConc ) + { + + FOR( i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) + { + st->hTonalMDCTConc->scaleFactorsBackground_fx[i] = float_to_fix( st->hTonalMDCTConc->scaleFactorsBackground_flt[i], 15 ); + } + //st->hTonalMDCTConc->scf_fadeout = float_to_fix16( st->hTonalMDCTConc->scf_fadeout_flt, 15 ); + if ( hCPE->hCoreCoder[n]->bfi && st->tonal_mdct_plc_active ) + { + FOR( i = 0; i < FDNS_NPTS; i++ ) + { + f2me_16( st->hTonalMDCTConc->secondLastBlockData.scaleFactors_float[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ); + } + FOR( i = 0; i < 30; i++ ) + { + float pd = st->hTonalMDCTConc->pTCI->phaseDiff_float[i]; + if ( pd >= PI2 ) + pd = fmodf( pd, PI2 ) - PI2; + st->hTonalMDCTConc->pTCI->phaseDiff[i] = (Word16) floatToFixed( pd, Q12 ); + } + FOR( i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++ ) + { + float pd = st->hTonalMDCTConc->pTCI->phase_currentFramePredicted_float[i]; + pd = fmodf( pd, PI2 ); + st->hTonalMDCTConc->pTCI->phase_currentFramePredicted[i] = (Word16) ( pd * ( 1u << Q13 ) ); + } + // st->hTonalMDCTConc->nFramesLost = float_to_fix16( st->hTonalMDCTConc->nFramesLost, Q1 ); + } + //f2me( st->hTonalMDCTConc->last_block_nrg_flt, &st->hTonalMDCTConc->last_block_nrg, &st->hTonalMDCTConc->last_block_nrg_exp ); + } + // st->old_fpitch = float_to_fix(st->old_fpitch_float, 16); + st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); + + IF( sts[n]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) + { + // u8bit to 16bit + FOR( l = 0; l < IGF_START_MX; l++ ) + { + sts[n]->hIGFDec->infoTCXNoise_evs[l] = (Word16) sts[n]->hIGFDec->infoTCXNoise[l]; + } + } + + + IF( st->hTcxDec ) + f2me_16( st->hTcxDec->CngLevelBackgroundTrace_bfi, &st->hTcxDec->conCngLevelBackgroundTrace, &st->hTcxDec->conCngLevelBackgroundTrace_e ); + if ( st->hTcxDec && st->hTcxDec->conLastFrameLevel_e < 0 ) + { + st->hTcxDec->conLastFrameLevel_e = 0; + } + if ( st->hTcxDec && st->hTcxDec->conNoiseLevelMemory_e[0] < 0 ) + { + set16_fx( st->hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); + } + IF( st->hTcxDec ) + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + IF( st->hTcxDec ) + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + IF( st->hTcxDec ) + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hTcxDec->old_excFB_fx[p] = (Word16) ( st->hTcxDec->old_excFB[p] * ( 1u << st->Q_exc ) ); + } + IF( st->hFdCngDec && st->hFdCngDec->hFdCngCom ) + floatToFixed_arr( st->hFdCngDec->hFdCngCom->A_cng_flt, st->hFdCngDec->hFdCngCom->A_cng, 15, 17 ); + // st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15); + + IF( hCPE->hCoreCoder[n]->hTcxLtpDec ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float, hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32, q_output, L_FRAME48k ); + floatToFixed_arrL( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float, hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32, q_output, TCXLTP_MAX_DELAY ); + floatToFixed_arrL( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, Q11, 111 ); + } + + + /*cldfb struct*/ + + /*------------------fix-to-fix-start---------------------*/ + /*core_switching_post_dec*/ + if ( hCPE->hCoreCoder[n]->hHQ_core != NULL ) + { + hCPE->hCoreCoder[n]->hHQ_core->Q_old_postdec = 0; + hCPE->hCoreCoder[n]->hHQ_core->Q_old_wtda = 0; + } + + /*-------------------cldfb-start-------------------------*/ + + floatToFixed_arrL( hCPE->hCoreCoder[n]->bpf_noise_buf_float, hCPE->hCoreCoder[n]->bpf_noise_buf_32, 11, L_FRAME_16k ); + if ( hCPE->hCoreCoder[n]->cldfbAna != NULL ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->cldfbAna->cldfb_state, hCPE->hCoreCoder[n]->cldfbAna->cldfb_state_fx, 10, hCPE->hCoreCoder[n]->cldfbAna->cldfb_size ); + } + if ( hCPE->hCoreCoder[n]->cldfbSyn != NULL ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->cldfbSyn->cldfb_state, hCPE->hCoreCoder[n]->cldfbSyn->cldfb_state_fx, 4, hCPE->hCoreCoder[n]->cldfbSyn->p_filter_length ); + } + if ( hCPE->hCoreCoder[n]->cldfbBPF != NULL ) + { + floatToFixed_arrL( hCPE->hCoreCoder[n]->cldfbBPF->cldfb_state, hCPE->hCoreCoder[n]->cldfbBPF->cldfb_state_fx, 11, hCPE->hCoreCoder[n]->cldfbBPF->cldfb_size ); + } + + + /*-------------------cldfb-end---------------------------*/ + + floatToFixed_arr( sts[n]->prev_synth_buffer, hCPE->hCoreCoder[n]->prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); + } + + IF( hCPE->output_mem[0] != NULL ) + { + floatToFixed_arrL( hCPE->output_mem[0], hCPE->output_mem_fx[0], Q11, NS2SA( hCPE->hCoreCoder[0]->output_Fs, 3125000 ) ); + } + IF( hCPE->output_mem[1] != NULL ) + { + floatToFixed_arrL( hCPE->output_mem[1], hCPE->output_mem_fx[1], Q11, NS2SA( hCPE->hCoreCoder[0]->output_Fs, 3125000 ) ); + } + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + + IF( hCPE->hStereoDft != NULL ) + { + IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) + { + FOR( Word32 p = 0; p < L_FRAME48k; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << q_output ) ); + } + FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q_output ) ); + } + } + } + + IF( hCPE->input_mem_LB[n] != NULL ) + { + FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) + { + hCPE->input_mem_LB_fx[n][ind] = (Word32) ( hCPE->input_mem_LB[n][ind] * ( 1 << q_output ) ); + } + } + + //FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) + //{ + // hCPE->prev_hb_synth_fx[n][k] = (Word32) ( hCPE->prev_hb_synth[n][k] * ( 1 << q_output ) ); + //} + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->prev_synth_fx[n][k] = (Word32) ( hCPE->prev_synth[n][k] * ( 1 << q_output ) ); + } + } + } + + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->targetEnergyPrev ) + f2me_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->dmxEnergyPrev ) + f2me_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); + IF( st_ivas->hParamMC && st_ivas->hParamMC->icld_q ) + floatToFixed_arr16( st_ivas->hParamMC->icld_q, st_ivas->hParamMC->icld_q_fx, 8, st_ivas->hParamMC->hMetadataPMC->num_parameter_bands * st_ivas->hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); + IF( st_ivas->hParamMC && st_ivas->hParamMC->ls_conv_dmx_matrix ) + floatToFixed_arr32( st_ivas->hParamMC->ls_conv_dmx_matrix, st_ivas->hParamMC->ls_conv_dmx_matrix_fx, 15, st_ivas->hDecoderConfig->nchan_out * ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) ); + IF( st_ivas->hLsSetUpConversion ) + FOR( Word16 chOutIdx = 0; chOutIdx < st_ivas->hDecoderConfig->nchan_out; chOutIdx++ ) + { + FOR( Word16 chInIdx = 0; chInIdx < st_ivas->nchan_transport; chInIdx++ ) + { + st_ivas->hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx] = float_to_fix( st_ivas->hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx], 30 ); /*Q30*/ + } + } + + +#endif // Float to fix + if ( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } +#if 1 // Fix to float + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + hCPE = st_ivas->hCPE[cpe_id]; + sts = hCPE->hCoreCoder; + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + st = hCPE->hCoreCoder[ch]; + st->hTcxDec->tcxltp_last_gain_unmodified_float = fixedToFloat(st->hTcxLtpDec->tcxltp_gain, 15); + IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) + { + // 16bit to u8bit + FOR( l = 0; l < IGF_START_MX; l++ ) + { + sts[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t) sts[ch]->hIGFDec->infoTCXNoise_evs[l]; + } + IF( !sts[0]->bfi || ( sts[0]->bfi && sts[ch]->core != ACELP_CORE ) ) + { + me2f_buf( sts[ch]->hIGFDec->virtualSpec, sts[ch]->hIGFDec->virtualSpec_e, sts[ch]->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); + } + } + IF( st->hTonalMDCTConc != NULL ) + { + //st->hTonalMDCTConc->scf_fadeout_flt = fixedToFloat( st->hTonalMDCTConc->scf_fadeout, 15 ); + //st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); + if ( hCPE->hCoreCoder[ch]->bfi && st->tonal_mdct_plc_active ) + { + //st->hTonalMDCTConc->nFramesLost_float = fix16_to_float( st->hTonalMDCTConc->nFramesLost, Q1 ); + } + } + + if ( sts[ch]->last_core != -1 && sts[ch]->nbLostCmpt == 1 ) + { + if ( !( sts[ch]->rf_flag && sts[ch]->use_partial_copy && ( sts[ch]->rf_frame_type == RF_TCXTD1 || sts[ch]->rf_frame_type == RF_TCXTD2 ) ) ) + { + IF( sts[ch]->hTonalMDCTConc != NULL && sts[ch]->last_core == TCX_20_CORE && sts[ch]->second_last_core == TCX_20_CORE && ( ( sts[ch]->old_fpitch <= L_shl( sts[ch]->L_frame, 15 ) ) || ( sts[ch]->hTcxDec->tcxltp_last_gain_unmodified <= 13107 /*0.4f*/ ) ) + /* it is fine to call the detection even if no ltp information + is available, meaning that st->old_fpitch == + st->tcxltp_second_last_pitch == st->L_frame */ + && ( sts[ch]->old_fpitch == sts[ch]->hTcxDec->tcxltp_second_last_pitch ) && !sts[ch]->last_tns_active && !sts[ch]->second_last_tns_active ) + { + + if ( sts[ch]->hTonalMDCTConc->pTCI->numIndexes < MAX_NUMBER_OF_IDX ) + { + FOR( i = 0; i < sts[ch]->hTonalMDCTConc->pTCI->numIndexes; i++ ) + { + sts[ch]->hTonalMDCTConc->pTCI->phaseDiff_float[i] = fixedToFloat( sts[ch]->hTonalMDCTConc->pTCI->phaseDiff[i], Q12 ); + } + FOR( i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++ ) + { + sts[ch]->hTonalMDCTConc->pTCI->phase_currentFramePredicted_float[i] = fixedToFloat( sts[ch]->hTonalMDCTConc->pTCI->phase_currentFramePredicted[i], Q13 ); + } + } + } + } + } + } + + FOR( n = 0; n < 2; n++ ) + { + st = hCPE->hCoreCoder[n]; + sts = hCPE->hCoreCoder; + IF( st->hTcxDec ) + st->hTcxDec->CngLevelBackgroundTrace_bfi = me2f_16( st->hTcxDec->conCngLevelBackgroundTrace, st->hTcxDec->conCngLevelBackgroundTrace_e ); + IF( st->hTonalMDCTConc && st->hTonalMDCTConc->lastPcmOut_float ) + fixedToFloat_arr( st->hTonalMDCTConc->lastPcmOut, st->hTonalMDCTConc->lastPcmOut_float, 0, st->hTonalMDCTConc->nSamples ); + IF( sts[0]->bfi == 0 && !st->hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive ) + fixedToFloat_arr( st->hTonalMDCTConc->secondLastPcmOut, st->hTonalMDCTConc->secondLastPcmOut_float, 0, st->hTonalMDCTConc->nSamples / 2 ); + fixedToFloat_arr( st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synthFB, st->Q_syn, st->hTcxDec->old_synth_lenFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + fixedToFloat_arr( st->hTcxDec->old_synth, st->hTcxDec->old_synth_float, st->Q_syn, 1280 ); + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hTcxDec->old_excFB[p] = (float) ( st->hTcxDec->old_excFB_fx[p] ) / ( 1u << st->Q_exc ); + } + for ( int p = 0; p < st->L_frame / 2; p++ ) + { + st->hTcxDec->old_syn_Overl_float[p] = (float) st->hTcxDec->old_syn_Overl[p] * 2 * ( 1u << st->Q_syn ); + st->hTcxDec->syn_Overl_TDACFB_float[p] = (float) st->hTcxDec->syn_Overl_TDACFB[p] * 2 * (float) pow( 2, st->Q_syn ); + st->hTcxDec->syn_Overl_TDAC_float[p] = (float) st->hTcxDec->syn_Overl_TDAC[p] * 2 * (float) pow( 2, st->Q_syn ); + } + for ( int p = 0; p < 640; p++ ) + { + st->hHQ_core->old_outLB[p] = (float) st->hHQ_core->old_out_LB_fx[p] / ( 1u << st->Q_syn ); + } + + if ( !st->tcxonly ) + { + fixedToFloat_arr( st->p_bpf_noise_buf, st->p_bpf_noise_buf_float, 0, L_FRAME_16k ); + } + + fixedToFloat_arr( st->hTcxDec->syn_OverlFB, st->hTcxDec->syn_OverlFB_float, st->Q_syn, L_FRAME_MAX / 2 ); + fixedToFloat_arr( st->hTcxDec->syn_Overl, st->hTcxDec->syn_Overl_float, st->Q_syn, L_FRAME32k / 2 ); + st->hTcxDec->tcxltp_last_gain_unmodified_float = fix16_to_float( st->hTcxDec->tcxltp_last_gain_unmodified, Q15 ); + st->hTcxDec->conceal_eof_gain_float = fix16_to_float( st->hTcxDec->conceal_eof_gain, Q14 ); + + /*-------------------cldfb-start-------------------------*/ + + /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ + + if ( sts[n]->cldfbAna != NULL ) + { + fixedToFloat_arrL( sts[n]->cldfbAna->cldfb_state_fx, sts[n]->cldfbAna->cldfb_state, 10, sts[n]->cldfbAna->cldfb_state_length ); + } + if ( sts[n]->cldfbSyn != NULL ) + { + fixedToFloat_arrL( sts[n]->cldfbSyn->cldfb_state_fx, sts[n]->cldfbSyn->cldfb_state, 4, sts[n]->cldfbSyn->p_filter_length ); + } + if ( sts[n]->cldfbBPF != NULL ) + { + fixedToFloat_arrL( sts[n]->cldfbBPF->cldfb_state_fx, sts[n]->cldfbBPF->cldfb_state, 11, sts[n]->cldfbBPF->cldfb_state_length ); + } + + /*-------------------cldfb-end---------------------------*/ + + IF( sts[n]->hHQ_core != NULL ) + { + fixedToFloat_arr( sts[n]->hHQ_core->old_out_fx, sts[n]->hHQ_core->old_out, 0, L_FRAME48k ); + } + + /*------------------reset-code-start---------------------*/ + + /*reset function flags*/ + Word8 reset_wb_tbe_synth = 0; + Word8 reset_swb_tbe = 0; + + /* reset WB BWE buffers */ + + IF( NE_16( sts[n]->last_extl, WB_BWE ) && EQ_16( sts[n]->extl, WB_BWE ) && sts[n]->hBWE_FD != NULL ) + { + + IF( NE_16( sts[n]->last_extl, SWB_BWE ) && NE_16( sts[n]->last_extl, FB_BWE ) ) + { + sts[n]->hBWE_FD->prev_mode = sts[n]->hBWE_FD->prev_mode; + } + sts[n]->hBWE_FD->prev_L_swb_norm = sts[n]->hBWE_FD->prev_L_swb_norm; + sts[n]->hBWE_FD->prev_flag = sts[n]->hBWE_FD->prev_flag; + } + + /* reset TBE buffers */ + if ( sts[n]->hBWE_TD != NULL ) + { + IF( ( ( EQ_16( sts[n]->extl, SWB_TBE ) || EQ_16( sts[n]->extl, FB_TBE ) || EQ_16( sts[n]->extl, SWB_CNG ) ) && + ( NE_16( sts[n]->L_frame, sts[n]->last_L_frame ) || ( NE_16( sts[n]->last_extl, SWB_TBE ) && NE_16( sts[n]->last_extl, FB_TBE ) ) || EQ_16( sts[n]->last_core, HQ_CORE ) ) ) || + ( LT_16( sts[n]->bwidth, sts[n]->last_bwidth ) && NE_16( sts[n]->last_extl, SWB_TBE ) ) || sts[n]->old_ppp_mode || ( ( EQ_16( sts[n]->prev_coder_type, AUDIO ) || EQ_16( sts[n]->prev_coder_type, INACTIVE ) ) && sts[n]->bws_cnt > 0 ) || ( sts[n]->bws_cnt == 0 && EQ_16( sts[n]->prev_bws_cnt, N_WS2N_FRAMES ) ) ) + { + + reset_swb_tbe = 1; + + IF( EQ_16( output_frame, L_FRAME16k ) ) + { + fixedToFloat_arr( sts[n]->hBWE_TD->mem_resamp_HB_32k_fx, sts[n]->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + } + fixedToFloat_arr( sts[n]->hBWE_TD->int_3_over_2_tbemem_dec_fx, sts[n]->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN ); + } + ELSE IF( sts[n]->hBWE_TD != NULL && ( sts[n]->last_core == TCX_20_CORE || sts[n]->last_core == TCX_10_CORE ) ) + { + /*------------TBEreset_dec_ivas_fx-start------------------*/ + IF( EQ_16( sts[n]->bwidth, WB ) ) + { + reset_wb_tbe_synth = 1; + + fixedToFloat_arr( sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); + } + ELSE IF( EQ_16( sts[n]->bwidth, SWB ) || EQ_16( sts[n]->bwidth, FB ) ) + { + reset_swb_tbe = 1; + fixedToFloat_arr( sts[n]->hBWE_TD->int_3_over_2_tbemem_dec_fx, sts[n]->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN ); // setting to zero + fixedToFloat_arr( sts[n]->hBWE_TD->mem_resamp_HB_32k_fx, sts[n]->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); // setting to zero + } + /*------------TBEreset_dec_ivas_fx-end--------------------*/ + } + + IF( NE_16( sts[n]->last_extl, WB_TBE ) && EQ_16( sts[n]->extl, WB_TBE ) ) + { + reset_wb_tbe_synth = 1; + fixedToFloat_arr( sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); // setting to zero + } + + IF( reset_swb_tbe ) + { + fixedToFloat_arr( sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); // setting to zero + } + IF( reset_wb_tbe_synth ) + { + fixedToFloat_arr( sts[n]->hBWE_TD->state_lsyn_filt_shb_fx, sts[n]->hBWE_TD->state_lsyn_filt_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); // setting to zero + fixedToFloat_arr( sts[n]->hBWE_TD->state_lsyn_filt_dwn_shb_fx, sts[n]->hBWE_TD->state_lsyn_filt_dwn_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); // setting to zero + fixedToFloat_arr( sts[n]->hBWE_TD->mem_resamp_HB_fx, sts[n]->hBWE_TD->mem_resamp_HB, 0, INTERP_3_1_MEM_LEN ); // setting to zero + } + } + + /*------------------reset-code-end-----------------------*/ + + + for ( int p = 0; p < L_FRAME48k; p++ ) + { + + IF( hCPE->hCoreCoder[n]->hTcxLtpDec ) + { + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q_output ); + if ( p < TCXLTP_MAX_DELAY ) + { + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q_output ); + } + } + } + if ( hCPE->hCoreCoder[n]->hTcxDec ) + { + for ( k = 0; k < 111; k++ ) + { + hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ( 1u << q_output ); + } + } + IF( hCPE->hCoreCoder[n]->hTcxLtpDec ) + + if ( ( hCPE->hCoreCoder[n]->codec_mode == MODE1 && hCPE->hCoreCoder[n]->hTcxDec != NULL ) && ( ( hCPE->hCoreCoder[n]->core == ACELP_CORE && !( hCPE->hCoreCoder[n]->bfi == 1 && hCPE->hCoreCoder[n]->con_tcx == 1 ) ) || hCPE->hCoreCoder[n]->core == HQ_CORE ) ) + { + fixedToFloat_arr( hCPE->hCoreCoder[n]->hTcxDec->synth_history_fx, hCPE->hCoreCoder[n]->hTcxDec->synth_history, 0, output_frame ); + } + } + + IF( hCPE->hStereoDft != NULL ) + { + IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) + { + FOR( Word32 p = 0; p < L_FRAME48k; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q_output ); + } + FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q_output ); + } + } + } + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + IF( hCPE->output_mem[n] != NULL ) + { + FOR( k = 0; k < NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->output_mem[n][k] = (float) hCPE->output_mem_fx[n][k] / ( 1u << 11 ); + } + } + IF( hCPE->hCoreCoder[n] != NULL ) + { + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) + { + hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << q_output ); + } + } + IF( hCPE->input_mem[n] != NULL ) + { + FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) + { + hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << q_output ) ); + } + } + //FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) + //{ + // hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << q_output ); + //} + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << q_output ); + } + } + } + + + IF( st_ivas->hCPE[0]->hCoreCoder[0]->igf ) + { + IF( !hMCT->currBlockDataCnt ) + { + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + IF( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->igf ) + { + me2f_buf( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec_e, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); + FOR( l = 0; l < IGF_START_MX; l++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t) st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise_evs[l]; + } + } + } + } + } + } + + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->targetEnergyPrev ) + me2f_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); + IF( st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx ) + me2f_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); + + FOR( i = 0; i < 12; i++ ) + if ( p_output[i] ) + { + fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, L_FRAME48k ); + free( p_output_fx[i] ); } - } -#endif // IVAS_FLOAT_FIXED - else if ( st_ivas->nCPE > 1 ) - { +#endif // Fix to float +#else if ( ( error = ivas_mct_dec( st_ivas, p_output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } +#endif } /* HP filtering */ @@ -2913,10 +5428,10 @@ ivas_error ivas_jbm_dec_tc( #ifdef IVAS_FLOAT_FIXED output_fx[0] = malloc( sizeof( Word32 ) * L_FRAME48k ); set32_fx( output_fx[0], 0, L_FRAME48k ); - for ( int k = 0; k < 45; k++ ) - { - st_ivas->hSCE[0]->prev_hb_synth_fx[k] = (Word32) ( st_ivas->hSCE[0]->prev_hb_synth[k] * ONE_IN_Q11 ); - } + //for ( int k = 0; k < 45; k++ ) + //{ + // st_ivas->hSCE[0]->prev_hb_synth_fx[k] = (Word32) ( st_ivas->hSCE[0]->prev_hb_synth[k] * ONE_IN_Q11 ); + //} IF( ( error = ivas_sce_dec_fx( st_ivas, 0, &output_fx[0], output_frame, 0 ) ) != IVAS_ERR_OK ) { @@ -2930,8 +5445,8 @@ ivas_error ivas_jbm_dec_tc( for ( int k = 0; k < 96; k++ ) { st_ivas->hSCE[0]->hCoreCoder[0]->prev_synth_buffer[k] = (float) st_ivas->hSCE[0]->hCoreCoder[0]->prev_synth_buffer32_fx[k] / ONE_IN_Q11; - if ( k < 45 ) - st_ivas->hSCE[0]->prev_hb_synth[k] = (float) st_ivas->hSCE[0]->prev_hb_synth_fx[k] / ONE_IN_Q11; + //if ( k < 45 ) + // st_ivas->hSCE[0]->prev_hb_synth[k] = (float) st_ivas->hSCE[0]->prev_hb_synth_fx[k] / ONE_IN_Q11; } free( output_fx[0] ); #else @@ -2963,10 +5478,10 @@ ivas_error ivas_jbm_dec_tc( { output_fx[0] = malloc( sizeof( Word32 ) * L_FRAME48k ); set32_fx( output_fx[0], 0, L_FRAME48k ); - for ( int k = 0; k < 45; k++ ) - { - st_ivas->hSCE[0]->prev_hb_synth_fx[k] = (Word32) ( st_ivas->hSCE[0]->prev_hb_synth[k] * ( 1 << q_output ) ); - } + //for ( int k = 0; k < 45; k++ ) + //{ + // st_ivas->hSCE[0]->prev_hb_synth_fx[k] = (Word32) ( st_ivas->hSCE[0]->prev_hb_synth[k] * ( 1 << q_output ) ); + //} IF( ( error = ivas_sce_dec_fx( st_ivas, 0, &output_fx[0], output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { @@ -2980,8 +5495,8 @@ ivas_error ivas_jbm_dec_tc( for ( int k = 0; k < 96; k++ ) { st_ivas->hSCE[0]->hCoreCoder[0]->prev_synth_buffer[k] = (float) st_ivas->hSCE[0]->hCoreCoder[0]->prev_synth_buffer32_fx[k] / ( 1 << q_output ); - if ( k < 45 ) - st_ivas->hSCE[0]->prev_hb_synth[k] = (float) st_ivas->hSCE[0]->prev_hb_synth_fx[k] / ( 1 << q_output ); + //if ( k < 45 ) + // st_ivas->hSCE[0]->prev_hb_synth[k] = (float) st_ivas->hSCE[0]->prev_hb_synth_fx[k] / ( 1 << q_output ); } free( output_fx[0] ); } @@ -3073,13 +5588,10 @@ ivas_error ivas_jbm_dec_tc( hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft; } - st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact, 15); + // st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact, 15); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact, 15); - floatToFixed_arrL(&hCPE->hStereoDft->res_gains_ind[0][0], &hCPE->hStereoDft->res_gains_ind_fx[0][0], Q26, sizeof(hCPE->hStereoDft->res_gains_ind_fx) / sizeof(hCPE->hStereoDft->res_gains_ind_fx[0][0])); - floatToFixed_arrL(&hCPE->hStereoDft->res_pred_gain[0], &hCPE->hStereoDft->res_pred_gain_fx[0], Q31, sizeof(hCPE->hStereoDft->res_pred_gain_fx)/ sizeof(hCPE->hStereoDft->res_pred_gain_fx[0])); - floatToFixed_arrL(&hCPE->hStereoDft->itd[0], &hCPE->hStereoDft->itd_fx[0], Q1, sizeof(hCPE->hStereoDft->itd_fx) / sizeof(hCPE->hStereoDft->itd_fx[0])); floatToFixed_arrL(&st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0], st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->q_smoothed_psd, sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx) / sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0])); - floatToFixed_arrL(&hCPE->prev_hb_synth[0][0], &hCPE->prev_hb_synth_fx[0][0], hCPE->hStereoDft->q_dft, sizeof(hCPE->prev_hb_synth_fx) / sizeof(hCPE->prev_hb_synth_fx[0][0])); + //floatToFixed_arrL(&hCPE->prev_hb_synth[0][0], &hCPE->prev_hb_synth_fx[0][0], hCPE->hStereoDft->q_dft, sizeof(hCPE->prev_hb_synth_fx) / sizeof(hCPE->prev_hb_synth_fx[0][0])); for (int ii = 0; ii < sizeof(hCPE->hStereoDft->hb_nrg_subr_fx) / sizeof(hCPE->hStereoDft->hb_nrg_subr_fx[0]); ii++) { if ( l_hb_nrg_subr < hCPE->hStereoDft->hb_nrg_subr[ii] ) @@ -3115,15 +5627,12 @@ ivas_error ivas_jbm_dec_tc( hCPE->hStereoDft->hb_nrg_fx[ii] = (Word32)(hCPE->hStereoDft->hb_nrg[ii] * ((float)(1 << hCPE->hStereoDft->q_hb_nrg))); } - floatToFixed_arrL( &hCPE->hStereoDft->side_gain[0], &hCPE->hStereoDft->side_gain_fx[0], Q31, sizeof( hCPE->hStereoDft->side_gain_fx ) / sizeof( hCPE->hStereoDft->side_gain_fx[0] ) ); - floatToFixed_arrL( &hCPE->hStereoDft->gipd[0], &hCPE->hStereoDft->gipd_fx[0], Q13, sizeof( hCPE->hStereoDft->gipd_fx ) / sizeof( hCPE->hStereoDft->gipd_fx[0] ) ); - floatToFixed_arr( &hCPE->hStereoDft->g_state[0], &hCPE->hStereoDft->g_state_fx[0], Q15, sizeof( hCPE->hStereoDft->g_state_fx ) / sizeof( hCPE->hStereoDft->g_state_fx[0] ) ); - floatToFixed_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0] ) ); + //floatToFixed_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0] ) ); IF( hCPE->hStereoCng != NULL ) { floatToFixed_arr( &hCPE->hStereoCng->cm[0], &hCPE->hStereoCng->cm_fx[0], Q15, sizeof( hCPE->hStereoCng->cm_fx ) / sizeof( hCPE->hStereoCng->cm_fx[0] ) ); } - floatToFixed_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0] ) ); + //floatToFixed_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0] ) ); for ( int ii = 0; ii < 2; ii++ ) { floatToFixed_arrL( &p_output[ii][0], &p_output_fix[ii][0], hCPE->hStereoDft->q_dft, ( 48000 / FRAMES_PER_SEC ) ); @@ -3136,8 +5645,8 @@ ivas_error ivas_jbm_dec_tc( floatToFixed_arrL(&hCPE->input_mem_LB[1][0], &hCPE->input_mem_LB_fx[1][0], q, STEREO_DFT32MS_OVL_16k); if (hSCE != NULL) { - floatToFixed_arrL(&hSCE->prev_hb_synth[0], &hSCE->prev_hb_synth_fx[0], hCPE->hStereoDft->q_dft, sizeof(hSCE->prev_hb_synth_fx) / sizeof(hSCE->prev_hb_synth_fx[0])); - hSCE->q_prev_hb_synth_fx = hCPE->hStereoDft->q_dft; + //floatToFixed_arrL(&hSCE->prev_hb_synth[0], &hSCE->prev_hb_synth_fx[0], hCPE->hStereoDft->q_dft, sizeof(hSCE->prev_hb_synth_fx) / sizeof(hSCE->prev_hb_synth_fx[0])); + //hSCE->q_prev_hb_synth_fx = hCPE->hStereoDft->q_dft; floatToFixed_arrL(&hSCE->save_hb_synth[0], &hSCE->save_hb_synth_fx[0], q, (Word16)(hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC)); hSCE->q_save_hb_synth_fx = q; floatToFixed_arrL(&hSCE->save_synth[0], &hSCE->save_synth_fx[0], q, (Word16)(hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC)); @@ -3175,7 +5684,7 @@ ivas_error ivas_jbm_dec_tc( } } } - hCPE->lt_es_em_fx = floatToFixed(hCPE->lt_es_em, Q15); + //hCPE->lt_es_em_fx = floatToFixed(hCPE->lt_es_em, Q15); for (int ii = 0; ii < CPE_CHANNELS; ii++) { hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; @@ -3185,17 +5694,9 @@ ivas_error ivas_jbm_dec_tc( ivas_sba_dirac_stereo_dec_fx( st_ivas, p_output_fix, output_frame, 1 ); - IF (hSCE != NULL) - { - hSCE->hCoreCoder[0]->log_energy_diff_lt = fixedToFloat(hSCE->hCoreCoder[0]->log_energy_diff_lt_fx, Q15); - hSCE->hCoreCoder[0]->stab_fac_smooth_lt = fixedToFloat(hSCE->hCoreCoder[0]->stab_fac_smooth_lt_fx, Q15); - } fixedToFloat_arrL(&hCPE->prev_synth_fx[0][0], &hCPE->prev_synth[0][0], hCPE->q_prev_synth_fx, sizeof(hCPE->prev_synth) / sizeof(hCPE->prev_synth[0][0])); - st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact = fixedToFloat( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx, 15 ); + // st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact = fixedToFloat( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx, 15 ); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact = fixedToFloat( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact_fx, 15 ); - fixedToFloat_arrL( &hCPE->hStereoDft->res_gains_ind_fx[0][0], &hCPE->hStereoDft->res_gains_ind[0][0], Q26, sizeof( hCPE->hStereoDft->res_gains_ind_fx ) / sizeof( hCPE->hStereoDft->res_gains_ind_fx[0][0] ) ); - fixedToFloat_arrL( &hCPE->hStereoDft->res_pred_gain_fx[0], &hCPE->hStereoDft->res_pred_gain[0], Q31, sizeof( hCPE->hStereoDft->res_pred_gain_fx ) / sizeof( hCPE->hStereoDft->res_pred_gain_fx[0] ) ); - fixedToFloat_arrL( &hCPE->hStereoDft->itd_fx[0], &hCPE->hStereoDft->itd[0], Q1, sizeof( hCPE->hStereoDft->itd_fx ) / sizeof( hCPE->hStereoDft->itd_fx[0] ) ); fixedToFloat_arrL( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd[0], st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->q_smoothed_psd, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0] ) ); for ( int ii = 0; ii < sizeof( hCPE->hStereoDft->hb_nrg_subr_fx ) / sizeof( hCPE->hStereoDft->hb_nrg_subr_fx[0] ); ii++ ) { @@ -3205,16 +5706,13 @@ ivas_error ivas_jbm_dec_tc( { hCPE->hStereoDft->hb_nrg[ii] = ( (float) hCPE->hStereoDft->hb_nrg_fx[ii] * ( (float) ( 1 << hCPE->hStereoDft->q_hb_nrg ) ) ); } - fixedToFloat_arrL(&hCPE->hStereoDft->side_gain_fx[0], &hCPE->hStereoDft->side_gain[0], Q31,sizeof(hCPE->hStereoDft->side_gain_fx) / sizeof(hCPE->hStereoDft->side_gain_fx[0])); - fixedToFloat_arrL(&hCPE->hStereoDft->gipd_fx[0], &hCPE->hStereoDft->gipd[0], Q13, sizeof(hCPE->hStereoDft->gipd_fx) / sizeof(hCPE->hStereoDft->gipd_fx[0])); - fixedToFloat_arr(&hCPE->hStereoDft->g_state_fx[0], &hCPE->hStereoDft->g_state[0], Q15, sizeof(hCPE->hStereoDft->g_state_fx) / sizeof(hCPE->hStereoDft->g_state_fx[0])); - fixedToFloat_arr(&st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm[0], Q15, sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx) / sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0])); - fixedToFloat_arrL(&hCPE->prev_hb_synth_fx[0][0], &hCPE->prev_hb_synth[0][0], hCPE->hStereoDft->q_dft, sizeof(hCPE->prev_hb_synth_fx) / sizeof(hCPE->prev_hb_synth_fx[0][0])); + //fixedToFloat_arr(&st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm[0], Q15, sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx) / sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0])); + //fixedToFloat_arrL(&hCPE->prev_hb_synth_fx[0][0], &hCPE->prev_hb_synth[0][0], hCPE->hStereoDft->q_dft, sizeof(hCPE->prev_hb_synth_fx) / sizeof(hCPE->prev_hb_synth_fx[0][0])); IF (hCPE->hStereoCng != NULL) { fixedToFloat_arr( &hCPE->hStereoCng->cm_fx[0], &hCPE->hStereoCng->cm[0], Q15, sizeof( hCPE->hStereoCng->cm_fx ) / sizeof( hCPE->hStereoCng->cm_fx[0] ) ); } - fixedToFloat_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0] ) ); + //fixedToFloat_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_g_state_fx[0] ) ); for ( int ii = 0; ii < 2; ii++ ) { fixedToFloat_arrL( &p_output_fix[ii][0], &p_output[ii][0], hCPE->hStereoDft->q_dft, ( 48000 / FRAMES_PER_SEC ) ); @@ -3226,7 +5724,7 @@ ivas_error ivas_jbm_dec_tc( fixedToFloat_arrL(&hCPE->input_mem_LB_fx[1][0], &hCPE->input_mem_LB[1][0], q, STEREO_DFT32MS_OVL_16k); if (hSCE != NULL) { - fixedToFloat_arrL(&hSCE->prev_hb_synth_fx[0], &hSCE->prev_hb_synth[0], hCPE->hStereoDft->q_dft, sizeof(hSCE->prev_hb_synth_fx) / sizeof(hSCE->prev_hb_synth_fx[0])); + //fixedToFloat_arrL(&hSCE->prev_hb_synth_fx[0], &hSCE->prev_hb_synth[0], hCPE->hStereoDft->q_dft, sizeof(hSCE->prev_hb_synth_fx) / sizeof(hSCE->prev_hb_synth_fx[0])); fixedToFloat_arrL(&hSCE->save_synth_fx[0], &hSCE->save_synth[0], q, (Word16)(hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC)); fixedToFloat_arrL(&hSCE->save_hb_synth_fx[0], &hSCE->save_hb_synth[0], q, (Word16)(hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC)); } @@ -3264,7 +5762,7 @@ ivas_error ivas_jbm_dec_tc( { fixedToFloat_arrL(&hCPE->output_mem_fx[ii][0], &hCPE->output_mem[ii][0], hCPE->hStereoDft->q_dft, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS )); } - hCPE->lt_es_em = fixedToFloat(hCPE->lt_es_em_fx, Q15); + //hCPE->lt_es_em = fixedToFloat(hCPE->lt_es_em_fx, Q15); } #endif } @@ -3578,8 +6076,6 @@ void ivas_jbm_dec_feed_tc_to_renderer( #if 1/*Float to fix */ PARAM_ISM_DEC_HANDLE hParamIsmDec; hParamIsmDec = st_ivas->hParamIsmDec; - floatToFixed_arrL( hParamIsmDec->azimuth_values, hParamIsmDec->azimuth_values_fx, 22, st_ivas->nchan_ism ); - floatToFixed_arrL( hParamIsmDec->elevation_values, hParamIsmDec->elevation_values_fx, 22, st_ivas->nchan_ism ); FOR( Word16 i = 0; i < 11; i++ ) { FOR( Word16 j = 0; j < 1; j++ ) @@ -3590,7 +6086,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( } } } - st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = float_to_fix16( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_flt, 15 ); + //st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = float_to_fix16( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_flt, 15 ); SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; hSpatParamRendCom = st_ivas->hSpatParamRendCom; Word16 nBins = hSpatParamRendCom->num_freq_bands; @@ -3608,8 +6104,6 @@ void ivas_jbm_dec_feed_tc_to_renderer( #endif // IVAS_FLOAT_FIXED ivas_param_ism_params_to_masa_param_mapping_fx( st_ivas ); #if 1 /*Fix to float*/ - fixedToFloat_arrL( hParamIsmDec->azimuth_values_fx, hParamIsmDec->azimuth_values, 22, st_ivas->nchan_ism ); - fixedToFloat_arrL( hParamIsmDec->elevation_values_fx, hParamIsmDec->elevation_values, 22, st_ivas->nchan_ism ); FOR( Word16 i = 0; i < 11; i++ ) { FOR( Word16 j = 0; j < 1; j++ ) @@ -3646,65 +6140,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( { #ifdef IVAS_FLOAT_FIXED - Word16 len = (int16_t)(st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC); - Word16 num_objects = st_ivas->nchan_transport; - IF(st_ivas->renderer_type == RENDERER_TD_PANNING || - st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || - st_ivas->renderer_type == RENDERER_OSBA_AMBI || - st_ivas->renderer_type == RENDERER_OSBA_LS || - st_ivas->renderer_type == RENDERER_OSBA_STEREO || - (st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM && st_ivas->hDecoderConfig->Opt_Headrotation == 0)) - { - if (st_ivas->hIsmRendererData != NULL) { - FOR(int idx = 0; idx < len; idx++) - { - st_ivas->hIsmRendererData->interpolator_fx[idx] = (Word16)floatToFixed(st_ivas->hIsmRendererData->interpolator[idx], Q15); - } - for (int i = 0; i < num_objects; i++) { - for (int j = 0; j < MAX_OUTPUT_CHANNELS; j++) { - st_ivas->hIsmRendererData->gains_fx[i][j] = floatToFixed(st_ivas->hIsmRendererData->gains[i][j], Q30); - } - } - for (int i = 0; i < num_objects; i++) - { - for (int j = 0; j < MAX_OUTPUT_CHANNELS; j++) { - st_ivas->hIsmRendererData->prev_gains_fx[i][j] = floatToFixed(st_ivas->hIsmRendererData->prev_gains[i][j], Q30); - } - } - } - } - ivas_ism_dec_digest_tc_fx(st_ivas); - - IF(st_ivas->renderer_type == RENDERER_TD_PANNING || - st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || - st_ivas->renderer_type == RENDERER_OSBA_AMBI || - st_ivas->renderer_type == RENDERER_OSBA_LS || - st_ivas->renderer_type == RENDERER_OSBA_STEREO || - (st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM && st_ivas->hDecoderConfig->Opt_Headrotation == 0)) - { - if (st_ivas->hIsmRendererData != NULL) { - FOR(int idx = 0; idx < len; idx++) - { - st_ivas->hIsmRendererData->interpolator[idx] = fixedToFloat(st_ivas->hIsmRendererData->interpolator_fx[idx], Q15); - } - for (int i = 0; i < num_objects; i++) - { - for (int j = 0; j < MAX_OUTPUT_CHANNELS; j++) { - st_ivas->hIsmRendererData->prev_gains[i][j] = fixedToFloat(st_ivas->hIsmRendererData->prev_gains_fx[i][j], Q30); - } - } - for (int i = 0; i < num_objects; i++) { - for (int j = 0; j < MAX_OUTPUT_CHANNELS; j++) { - st_ivas->hIsmRendererData->gains[i][j] = fixedToFloat(st_ivas->hIsmRendererData->gains_fx[i][j], Q30); - } - } - } - } #else ivas_ism_dec_digest_tc(st_ivas); #endif @@ -3943,65 +6379,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) { #ifdef IVAS_FLOAT_FIXED - Word16 len = (int16_t)(st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC); - Word16 num_objects = st_ivas->nchan_transport; - IF(st_ivas->renderer_type == RENDERER_TD_PANNING || - st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || - st_ivas->renderer_type == RENDERER_OSBA_AMBI || - st_ivas->renderer_type == RENDERER_OSBA_LS || - st_ivas->renderer_type == RENDERER_OSBA_STEREO || - (st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM && st_ivas->hDecoderConfig->Opt_Headrotation == 0)) - { - if (st_ivas->hIsmRendererData != NULL) { - FOR(int idx = 0; idx < len; idx++) - { - st_ivas->hIsmRendererData->interpolator_fx[idx] = (Word16)floatToFixed(st_ivas->hIsmRendererData->interpolator[idx], Q15); - } - for (int i = 0; i < num_objects; i++) { - for (int j = 0; j < MAX_OUTPUT_CHANNELS; j++) { - st_ivas->hIsmRendererData->gains_fx[i][j] = floatToFixed(st_ivas->hIsmRendererData->gains[i][j], Q30); - } - } - for (int i = 0; i < num_objects; i++) - { - for (int j = 0; j < MAX_OUTPUT_CHANNELS; j++) { - st_ivas->hIsmRendererData->prev_gains_fx[i][j] = floatToFixed(st_ivas->hIsmRendererData->prev_gains[i][j], Q30); - } - } - } - } - ivas_ism_dec_digest_tc_fx( st_ivas ); - - IF(st_ivas->renderer_type == RENDERER_TD_PANNING || - st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || - st_ivas->renderer_type == RENDERER_OSBA_AMBI || - st_ivas->renderer_type == RENDERER_OSBA_LS || - st_ivas->renderer_type == RENDERER_OSBA_STEREO || - (st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM && st_ivas->hDecoderConfig->Opt_Headrotation == 0)) - { - if (st_ivas->hIsmRendererData != NULL) { - FOR(int idx = 0; idx < len; idx++) - { - st_ivas->hIsmRendererData->interpolator[idx] = fixedToFloat(st_ivas->hIsmRendererData->interpolator_fx[idx], Q15); - } - for (int i = 0; i < num_objects; i++) - { - for (int j = 0; j < MAX_OUTPUT_CHANNELS; j++) { - st_ivas->hIsmRendererData->prev_gains[i][j] = fixedToFloat(st_ivas->hIsmRendererData->prev_gains_fx[i][j], Q30); - } - } - for (int i = 0; i < num_objects; i++) { - for (int j = 0; j < MAX_OUTPUT_CHANNELS; j++) { - st_ivas->hIsmRendererData->gains[i][j] = fixedToFloat(st_ivas->hIsmRendererData->gains_fx[i][j], Q30); - } - } - } - } #else ivas_ism_dec_digest_tc(st_ivas); #endif @@ -4049,65 +6427,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { #ifdef IVAS_FLOAT_FIXED - Word16 len = (int16_t)(st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC); - Word16 num_objects = st_ivas->nchan_transport; - IF(st_ivas->renderer_type == RENDERER_TD_PANNING || - st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || - st_ivas->renderer_type == RENDERER_OSBA_AMBI || - st_ivas->renderer_type == RENDERER_OSBA_LS || - st_ivas->renderer_type == RENDERER_OSBA_STEREO || - (st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM && st_ivas->hDecoderConfig->Opt_Headrotation == 0)) - { - if (st_ivas->hIsmRendererData != NULL) { - FOR(int idx = 0; idx < len; idx++) - { - st_ivas->hIsmRendererData->interpolator_fx[idx] = (Word16)floatToFixed(st_ivas->hIsmRendererData->interpolator[idx], Q15); - } - for (int i = 0; i < num_objects; i++) { - for (int j = 0; j < MAX_OUTPUT_CHANNELS; j++) { - st_ivas->hIsmRendererData->gains_fx[i][j] = floatToFixed(st_ivas->hIsmRendererData->gains[i][j], Q30); - } - } - for (int i = 0; i < num_objects; i++) - { - for (int j = 0; j < MAX_OUTPUT_CHANNELS; j++) { - st_ivas->hIsmRendererData->prev_gains_fx[i][j] = floatToFixed(st_ivas->hIsmRendererData->prev_gains[i][j], Q30); - } - } - } - } - ivas_ism_dec_digest_tc_fx(st_ivas); - - IF(st_ivas->renderer_type == RENDERER_TD_PANNING || - st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || - st_ivas->renderer_type == RENDERER_OSBA_AMBI || - st_ivas->renderer_type == RENDERER_OSBA_LS || - st_ivas->renderer_type == RENDERER_OSBA_STEREO || - (st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM && st_ivas->hDecoderConfig->Opt_Headrotation == 0)) - { - if (st_ivas->hIsmRendererData != NULL) { - FOR(int idx = 0; idx < len; idx++) - { - st_ivas->hIsmRendererData->interpolator[idx] = fixedToFloat(st_ivas->hIsmRendererData->interpolator_fx[idx], Q15); - } - for (int i = 0; i < num_objects; i++) - { - for (int j = 0; j < MAX_OUTPUT_CHANNELS; j++) { - st_ivas->hIsmRendererData->prev_gains[i][j] = fixedToFloat(st_ivas->hIsmRendererData->prev_gains_fx[i][j], Q30); - } - } - for (int i = 0; i < num_objects; i++) { - for (int j = 0; j < MAX_OUTPUT_CHANNELS; j++) { - st_ivas->hIsmRendererData->gains[i][j] = fixedToFloat(st_ivas->hIsmRendererData->gains_fx[i][j], Q30); - } - } - } - } #else ivas_ism_dec_digest_tc(st_ivas); #endif @@ -4167,6 +6487,7 @@ ivas_error ivas_jbm_dec_render( Word32 *p_temp_fx[MAX_OUTPUT_CHANNELS]; Word32 *p_tc_fx[MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS]; Word16 subframe_len, gd_bits, exp, nchan_in, i, j; + const Word16 output_q_factor = Q11; #endif SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; @@ -4377,13 +6698,6 @@ ivas_error ivas_jbm_dec_render( /*--------------------------------------------------------------------------------------------------------------*/ f2me_buf( (float *) st_ivas->hParamIsmDec->hParamIsmRendering->mixing_matrix_lin, (Word32 *) st_ivas->hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_fx, &st_ivas->hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_fx, CLDFB_NO_CHANNELS_MAX * ( PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX ) ); - f2me_buf( (float *) st_ivas->hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old, (Word32 *) st_ivas->hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old_fx, &st_ivas->hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_old_fx, CLDFB_NO_CHANNELS_MAX * ( PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX ) ); - - for ( ch = 0; ch < st_ivas->nchan_ism; ch++ ) - { - st_ivas->hParamIsmDec->azimuth_values_fx[ch] = floatToFixed( st_ivas->hParamIsmDec->azimuth_values[ch], Q22 ); - st_ivas->hParamIsmDec->elevation_values_fx[ch] = floatToFixed( st_ivas->hParamIsmDec->elevation_values[ch], Q22 ); - } Word16 n_slots_to_alloc = st_ivas->hDecoderConfig->Opt_tsm == 1 ? 32 : 16; Word16 n_chan_transport_t = st_ivas->nchan_transport; @@ -4393,7 +6707,6 @@ ivas_error ivas_jbm_dec_render( f2me_buf( st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc, st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx, &st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp, size ); f2me_buf( st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc, st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx, &st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp, size ); - floatToFixed_arr( st_ivas->hParamIsmDec->hParamIsmRendering->interpolator, st_ivas->hParamIsmDec->hParamIsmRendering->interpolator_fx, Q14, n_slots_to_alloc ); Word16 n_out; if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) @@ -4424,7 +6737,6 @@ ivas_error ivas_jbm_dec_render( fixedToFloat_arrL( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_state, Q11, st_ivas->cldfbSynDec[ch]->p_filter_length ); fixedToFloat_arrL( p_output_fx_tmp[ch], p_output[ch], Q11, L_FRAME48k ); } - me2f_buf( (Word32 *) st_ivas->hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old_fx, st_ivas->hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_old_fx, (float *) st_ivas->hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old, CLDFB_NO_CHANNELS_MAX * ( PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX ) ); /*-----------------------------------------fix 2 flt--------------------------------------------*/ #else @@ -4495,25 +6807,6 @@ ivas_error ivas_jbm_dec_render( st_ivas->hTcBuffer->tc_fx[ind1][ind2] = (Word32) ( st_ivas->hTcBuffer->tc[ind1][ind2] * ( 1 << q ) ); } } - - FOR( Word16 ind1 = 0; ind1 < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) - { - } - } - FOR( Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++ ) - { - st_ivas->hIsmRendererData->interpolator_fx[ind1] = (Word16) ( st_ivas->hIsmRendererData->interpolator[ind1] * ( 32767 ) ); - } - FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->gains[ind1][ind2] * ( 1 << 30 ) ); - st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->prev_gains[ind1][ind2] * ( 1 << 30 ) ); - } - } FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { st_ivas->hIsmMetaData[ind1]->azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->azimuth * ( 1 << 22 ) ); @@ -4536,18 +6829,6 @@ ivas_error ivas_jbm_dec_render( p_output[ind1][ind2] = (float) ( p_output_fx[ind1][ind2] ) / (float) ( 1 << q ); } } - FOR( Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++ ) - { - st_ivas->hIsmRendererData->interpolator[ind1] = (float) ( st_ivas->hIsmRendererData->interpolator_fx[ind1] ) / (float) ( 1 << 15 ); - } - FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->gains_fx[ind1][ind2] ) / ( 1 << 30 ); - st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] ) / ( 1 << 30 ); - } - } FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { st_ivas->hIsmMetaData[ind1]->azimuth = (float) ( st_ivas->hIsmMetaData[ind1]->azimuth_fx ) / (float) ( 1 << 22 ); @@ -4586,16 +6867,12 @@ ivas_error ivas_jbm_dec_render( { /* Convert to Ambisonics; used also for ISM->HOA3->binaural rendering */ #ifdef IVAS_FLOAT_FIXED - FOR( i = 0; i < *nSamplesRendered + st_ivas->hTcBuffer->n_samples_rendered; i++ ) - { - st_ivas->hIsmRendererData->interpolator_fx[i] = (Word16) float_to_fix16( st_ivas->hIsmRendererData->interpolator[i], 15 ); - } FOR( i = 0; i < 15; i++ ) { FOR( j = 0; j < 16; j++ ) { - st_ivas->hIsmRendererData->gains_fx[i][j] = floatToFixed( st_ivas->hIsmRendererData->gains[i][j], Q29 ); - st_ivas->hIsmRendererData->prev_gains_fx[i][j] = floatToFixed( st_ivas->hIsmRendererData->prev_gains[i][j], Q29 ); + st_ivas->hIsmRendererData->gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q30 -> Q29 + st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q30 -> Q29 } } Word32 *p_output_fx[20]; @@ -4628,6 +6905,15 @@ ivas_error ivas_jbm_dec_render( free( p_output_fx[lp] ); } } + + FOR(i = 0; i < 15; i++) + { + FOR(j = 0; j < 16; j++) + { + st_ivas->hIsmRendererData->gains_fx[i][j] = L_shl(st_ivas->hIsmRendererData->gains_fx[i][j], 1); // Q29 -> Q30 + st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shl(st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1); // Q29 -> Q30 + } + } #else ivas_ism2sba_sf( st_ivas->hTcBuffer->tc, p_output, st_ivas->hIsmRendererData, st_ivas->nchan_transport, *nSamplesRendered, st_ivas->hTcBuffer->n_samples_rendered, st_ivas->hIntSetup.ambisonics_order ); #endif // IVAS_FLOAT_FIXED @@ -4637,13 +6923,37 @@ ivas_error ivas_jbm_dec_render( if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { #ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) + Word16 output_q_factor = Q11; + for (int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++) + { + for (int j = 0; j < L_FRAME48k; j++) + { + p_output_fx[i][j] = floatToFixed(p_output[i][j], Q11); + } + } + for (int ch = 0; ch < st_ivas->hTcBuffer->nchan_transport_internal; ch++) + { + floatToFixed_arrL(st_ivas->hTcBuffer->tc[ch], st_ivas->hTcBuffer->tc_fx[ch], Q11, L_FRAME48k); + } + IF ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, output_q_factor, *nSamplesRendered ) ) != IVAS_ERR_OK ) + { + return error; + } + + // Fixed to float + for (int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++) + { + for (int j = 0; j < L_FRAME48k; j++) + { + p_output[i][j] = fixedToFloat(p_output_fx[i][j], Q11); + } + } #else if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) -#endif { return error; } +#endif } else if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) { @@ -4950,11 +7260,25 @@ ivas_error ivas_jbm_dec_render( } } #endif // - if ( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx,960) ) != IVAS_ERR_OK ) + +#if 1 /* NOTE: remove float to fix conversion */ + Word16 n_tc; + if (st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) + n_tc = st_ivas->nchan_ism; + else + n_tc = st_ivas->hTcBuffer->nchan_transport_internal; + for (int ch = 0; ch < n_tc; ch++) + { + floatToFixed_arrL(st_ivas->hTcBuffer->tc[ch], st_ivas->hTcBuffer->tc_fx[ch], Q11, L_FRAME48k); + } +#endif + + IF ( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, output_q_factor, 960 ) ) != IVAS_ERR_OK ) { return error; } -#ifdef IVAS_FLOAT_FIXED /*Fixed to float */ + +#if 1 /*Fixed to float */ for ( n = 0; n < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; n++ ) { fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); @@ -5000,6 +7324,16 @@ ivas_error ivas_jbm_dec_render( } } #endif + +#if 1 /*TODO: remove fixed to float conversions */ + for (int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++) + { + for (int j = 0; j < L_FRAME48k; j++) + { + p_output[i][j] = fixedToFloat(p_output_fx[i][j], Q11); + } + } +#endif #else if ( ( error = ivas_osba_dirac_td_binaural_jbm( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK ) { @@ -5036,24 +7370,6 @@ ivas_error ivas_jbm_dec_render( } } - FOR( Word16 ind1 = 0; ind1 < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) - { - } - } - FOR( Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++ ) - { - st_ivas->hIsmRendererData->interpolator_fx[ind1] = (Word16) ( st_ivas->hIsmRendererData->interpolator[ind1] * ( 32767 ) ); - } - FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->gains[ind1][ind2] * ( 1 << 30 ) ); - st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->prev_gains[ind1][ind2] * ( 1 << 30 ) ); - } - } FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { st_ivas->hIsmMetaData[ind1]->azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->azimuth * ( 1 << 22 ) ); @@ -5076,18 +7392,6 @@ ivas_error ivas_jbm_dec_render( p_output[ind1][ind2] = (float) ( p_output_fx[ind1][ind2] ) / (float) ( 1 << q ); } } - FOR( Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++ ) - { - st_ivas->hIsmRendererData->interpolator[ind1] = (float) ( st_ivas->hIsmRendererData->interpolator_fx[ind1] ) / (float) ( 1 << 15 ); - } - FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->gains_fx[ind1][ind2] ) / ( 1 << 30 ); - st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] ) / ( 1 << 30 ); - } - } FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { st_ivas->hIsmMetaData[ind1]->azimuth = (float) ( st_ivas->hIsmMetaData[ind1]->azimuth_fx ) / (float) ( 1 << 22 ); @@ -5639,13 +7943,40 @@ ivas_error ivas_jbm_dec_render( else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { #ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) +#if 1 /* TODO: remove float to fix conversions: */ + Word16 output_q_factor = Q11; + for (int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++) + { + for (int j = 0; j < L_FRAME48k; j++) + { + p_output_fx[i][j] = floatToFixed(p_output[i][j], output_q_factor); + } + } + for (int ch = 0; ch < st_ivas->hTcBuffer->nchan_transport_internal; ch++) + { + floatToFixed_arrL(st_ivas->hTcBuffer->tc[ch], st_ivas->hTcBuffer->tc_fx[ch], Q11, L_FRAME48k); + } +#endif + IF ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, output_q_factor, *nSamplesRendered ) ) != IVAS_ERR_OK ) + { + return error; + } + +#if 1 /* TODO: remove Fixed to float */ + for (int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++) + { + for (int j = 0; j < L_FRAME48k; j++) + { + p_output[i][j] = fixedToFloat(p_output_fx[i][j], Q11); + } + } +#endif #else if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) -#endif { return error; } +#endif #ifdef IVAS_FLOAT_FIXED Word16 q = Q16; @@ -5927,13 +8258,10 @@ ivas_error ivas_jbm_dec_flush_renderer_fx( Word16 n_slots_still_available; Word16 n_samples_to_render; DECODER_TC_BUFFER_HANDLE hTcBuffer; -#if 1/*TODO:To be removed later(after ivas_td_binaural_renderer_sf_fx is integerated)*/ - float output[MAX_CICP_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; - float *p_output[MAX_CICP_CHANNELS]; -#endif Word32 output_fx[MAX_CICP_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; Word32 *p_output_fx[MAX_CICP_CHANNELS]; Word16 nchan_in, nchan_out; + const Word16 output_q_factor = Q11; IF ( !st_ivas->hDecoderConfig->Opt_tsm ) { return IVAS_ERR_OK; @@ -5985,9 +8313,6 @@ ivas_error ivas_jbm_dec_flush_renderer_fx( FOR ( ch_idx = 0; ch_idx < MAX_CICP_CHANNELS; ch_idx++ ) { -#if 1/*TODO: To be removed later*/ - p_output[ch_idx] = output[ch_idx]; -#endif p_output_fx[ch_idx] = output_fx[ch_idx]; } @@ -5998,17 +8323,7 @@ ivas_error ivas_jbm_dec_flush_renderer_fx( /* Binaural rendering */ IF ( EQ_16(renderer_type_old , RENDERER_BINAURAL_OBJECTS_TD) ) { -#ifdef IVAS_FLOAT_FIXED - IF ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output, hTcBuffer->n_samples_granularity ) ) != IVAS_ERR_OK ) -#if 1/*TODO:To be removed later when ivas_td_binaural_renderer_sf_fx is integerated*/ - FOR ( ch_idx = 0; ch_idx < MAX_CICP_CHANNELS; ch_idx++ ) - { - floatToFixed_arrL( p_output[ch_idx], p_output_fx[ch_idx], 11, L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES ); - } -#endif -#else - if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, hTcBuffer->n_samples_granularity ) ) != IVAS_ERR_OK ) -#endif + IF ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, output_q_factor, hTcBuffer->n_samples_granularity ) ) != IVAS_ERR_OK ) { return error; } @@ -6019,12 +8334,8 @@ ivas_error ivas_jbm_dec_flush_renderer_fx( /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */ set16_fx( st_ivas->hIsmRendererData->interpolator_fx, 32767, hTcBuffer->n_samples_granularity ); -#ifdef IVAS_FLOAT_FIXED ivas_ism_render_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ); -#else - ivas_ism_render_sf( st_ivas, p_output, hTcBuffer->n_samples_granularity ); -#endif st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; *st_ivas->hCrendWrapper->p_io_qfactor = 11; move16(); @@ -6069,20 +8380,10 @@ ivas_error ivas_jbm_dec_flush_renderer_fx( } ELSE IF ( EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_OBJECTS_TD) ) { -#ifdef IVAS_FLOAT_FIXED - IF ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output, hTcBuffer->n_samples_granularity ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, hTcBuffer->n_samples_granularity ) ) != IVAS_ERR_OK ) -#endif + IF ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, output_q_factor, hTcBuffer->n_samples_granularity ) ) != IVAS_ERR_OK ) { return error; } -#if 1/*TODO: To be removed later when ivas_td_binaural_renderer_sf_fx is integerated*/ - FOR ( ch_idx = 0; ch_idx < MAX_CICP_CHANNELS; ch_idx++ ) - { - floatToFixed_arrL( p_output[ch_idx], p_output_fx[ch_idx], 11, L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES ); - } -#endif ivas_binaural_add_LFE_fix( st_ivas, *nSamplesRendered, st_ivas->hTcBuffer->tc_fx, p_output_fx ); } } @@ -6107,20 +8408,10 @@ ivas_error ivas_jbm_dec_flush_renderer_fx( IF ( GT_16(st_ivas->nchan_ism , 0) ) { -#ifdef IVAS_FLOAT_FIXED - IF ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output, hTcBuffer->n_samples_granularity ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, hTcBuffer->n_samples_granularity ) ) != IVAS_ERR_OK ) -#endif + IF ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, output_q_factor, hTcBuffer->n_samples_granularity ) ) != IVAS_ERR_OK ) { return error; } -#if 1/*TODO: To be removed later when ivas_td_binaural_renderer_sf_fx is integerated*/ - FOR ( ch_idx = 0; ch_idx < MAX_CICP_CHANNELS; ch_idx++ ) - { - floatToFixed_arrL( p_output[ch_idx], p_output_fx[ch_idx], q, L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES ); - } -#endif // 1 } ELSE { @@ -6169,8 +8460,7 @@ ivas_error ivas_jbm_dec_flush_renderer_fx( set16_fx( st_ivas->hSpatParamRendCom->render_to_md_map, last_dirac_md_idx, n_slots_still_available ); /* render the last subframe */ - - IF ( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, (UWord16) hTcBuffer->n_samples_granularity, nSamplesRendered, &nSamplesAvailableNext, p_output_fx, L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, (UWord16) hTcBuffer->n_samples_granularity, nSamplesRendered, &nSamplesAvailableNext, p_output_fx, output_q_factor, L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES) ) != IVAS_ERR_OK ) { return error; } @@ -6303,11 +8593,7 @@ ivas_error ivas_jbm_dec_flush_renderer( /* Binaural rendering */ if ( renderer_type_old == RENDERER_BINAURAL_OBJECTS_TD ) { -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output, hTcBuffer->n_samples_granularity ) ) != IVAS_ERR_OK ) -#else if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, hTcBuffer->n_samples_granularity ) ) != IVAS_ERR_OK ) -#endif { return error; } @@ -6315,7 +8601,11 @@ ivas_error ivas_jbm_dec_flush_renderer( else if ( renderer_type_old == RENDERER_BINAURAL_MIXER_CONV_ROOM ) { /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */ +#ifdef IVAS_FLOAT_FIXED + set16_fx( st_ivas->hIsmRendererData->interpolator_fx, MAX16B, hTcBuffer->n_samples_granularity ); +#else set_f( st_ivas->hIsmRendererData->interpolator, 1.0f, hTcBuffer->n_samples_granularity ); +#endif #ifdef IVAS_FLOAT_FIXED Word16 q = 15; @@ -6338,18 +8628,6 @@ ivas_error ivas_jbm_dec_flush_renderer( { } } - FOR( Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++ ) - { - st_ivas->hIsmRendererData->interpolator_fx[ind1] = (Word16) ( st_ivas->hIsmRendererData->interpolator[ind1] * ( 32767 ) ); - } - FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->gains[ind1][ind2] * ( 1 << 30 ) ); - st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->prev_gains[ind1][ind2] * ( 1 << 30 ) ); - } - } FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { st_ivas->hIsmMetaData[ind1]->azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->azimuth * ( 1 << 22 ) ); @@ -6372,18 +8650,6 @@ ivas_error ivas_jbm_dec_flush_renderer( p_output[ind1][ind2] = (float) ( p_output_fx[ind1][ind2] ) / (float) ( 1 << q ); } } - FOR( Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++ ) - { - st_ivas->hIsmRendererData->interpolator[ind1] = (float) ( st_ivas->hIsmRendererData->interpolator_fx[ind1] ) / (float) ( 1 << 15 ); - } - FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->gains_fx[ind1][ind2] ) / ( 1 << 30 ); - st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] ) / ( 1 << 30 ); - } - } FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { st_ivas->hIsmMetaData[ind1]->azimuth = (float) ( st_ivas->hIsmMetaData[ind1]->azimuth_fx ) / (float) ( 1 << 22 ); @@ -6495,11 +8761,7 @@ ivas_error ivas_jbm_dec_flush_renderer( } else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output, hTcBuffer->n_samples_granularity ) ) != IVAS_ERR_OK ) -#else if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, hTcBuffer->n_samples_granularity ) ) != IVAS_ERR_OK ) -#endif { return error; } @@ -6548,11 +8810,7 @@ ivas_error ivas_jbm_dec_flush_renderer( if ( st_ivas->nchan_ism > 0 ) { -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output, hTcBuffer->n_samples_granularity ) ) != IVAS_ERR_OK ) -#else if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, hTcBuffer->n_samples_granularity ) ) != IVAS_ERR_OK ) -#endif { return error; } @@ -7395,14 +9653,14 @@ Word16 ivas_jbm_dec_get_num_tc_channels_fx( { IF( st_ivas->hOutSetup.separateChannelEnabled ) { - num_tc = add( num_tc, st_ivas->nchan_ism ); + num_tc = add( num_tc, 1 ); } IF( st_ivas->hOutSetup.separateChannelEnabled && ( EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( st_ivas->hOutSetup.num_lfe, 0 ) ) ) ) { /* LFE is synthesized in TD with the TCs*/ - num_tc = add( num_tc, st_ivas->nchan_ism ); + num_tc = add( num_tc, 1 ); } } } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 77f838d9846780a10c2db9373fbfa0bb0ac60f5a..167ad9237e74f26fd4b3ad0739f5dab908fbb6b6 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -39,6 +39,8 @@ #include "ivas_rom_com.h" #include "ivas_stat_dec.h" #include "prot.h" +#include "prot_fx1.h" +#include "prot_fx2.h" #include #include "wmc_auto.h" #include "prot_fx1.h" @@ -88,7 +90,9 @@ static ivas_error init_lfe_synth_data_fx( Decoder_Struct *st_ivas, MASA_DECODER_ #endif static void compute_foa_cov_matrix( float foaCov[FOA_CHANNELS][FOA_CHANNELS], float inCov[FOA_CHANNELS][FOA_CHANNELS], float mixMtx[FOA_CHANNELS][FOA_CHANNELS] ); - +#ifdef IVAS_FLOAT_FIXED +static void compute_foa_cov_matrix_fx(Word32 foaCov_fx[FOA_CHANNELS][FOA_CHANNELS], Word32 inCov_fx[FOA_CHANNELS][FOA_CHANNELS], Word32 mixMtx_fx[FOA_CHANNELS][FOA_CHANNELS]); +#endif static int16_t decode_lfe_to_total_energy_ratio( MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, uint16_t *bitstream, int16_t *index, const int32_t ivas_total_brate ); #ifdef IVAS_FLOAT_FIXED @@ -2572,12 +2576,20 @@ static ivas_error init_lfe_synth_data_fx( #endif hMasa->hMasaLfeSynth->transportEneSmooth_fx = 0; + move32(); + hMasa->hMasaLfeSynth->transportEneSmooth_q = Q31; move16(); hMasa->hMasaLfeSynth->protoLfeEneSmooth_fx = 0; + move32(); + hMasa->hMasaLfeSynth->protoLfeEneSmooth_q = Q31; move16(); hMasa->hMasaLfeSynth->targetEneLfeSmooth_fx = 0; + move32(); + hMasa->hMasaLfeSynth->targetEneLfeSmooth_q = Q31; move16(); hMasa->hMasaLfeSynth->targetEneTransSmooth_fx = 0; + move32(); + hMasa->hMasaLfeSynth->targetEneTransSmooth_q = Q31; move16(); #if 1 /* TODO: remove float code. */ @@ -3155,7 +3167,7 @@ ivas_error ivas_masa_dec_reconfigure( { /* regularization factor is bitrate-dependent */ #ifdef IVAS_FLOAT_FIXED - st_ivas->hDiracDecBin->reqularizationFactor = (float) configure_reqularization_factor_fx( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ) / ( 1 << 14 ); + st_ivas->hDiracDecBin->reqularizationFactor_fx = configure_reqularization_factor_fx( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); #else st_ivas->hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); #endif @@ -3255,14 +3267,6 @@ ivas_error ivas_masa_dec_reconfigure( { st_ivas->hIsmRendererData->interpolator_fx[ind1] = (Word16) L_min( 32767, floatToFixed( st_ivas->hIsmRendererData->interpolator_fx[ind1], 15 ) ); } - FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->gains[ind1][ind2] * ( 1 << 30 ) ); - st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->prev_gains[ind1][ind2] * ( 1 << 30 ) ); - } - } } FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { @@ -3358,14 +3362,23 @@ ivas_error ivas_masa_dec_reconfigure( } } } + Word16 n_tc; + if (st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) + n_tc = st_ivas->nchan_ism; + else + n_tc = st_ivas->hTcBuffer->nchan_transport_internal; + for (int ch = 0; ch < n_tc; ch++) + { + floatToFixed_arrL(st_ivas->hTcBuffer->tc[ch], st_ivas->hTcBuffer->tc_fx[ch], Q11, L_FRAME48k); + } #endif if ( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, n_samples_granularity, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, MC_MODE_NONE, ISM_MASA_MODE_DISC, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { return error; } #if 1 /*Fixed to float */ - IF ( hTcBuffer->tc_buffer ) - fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); + if ( hTcBuffer->tc_buffer ) + fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); IF( hSpar ) { FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) @@ -3409,21 +3422,6 @@ ivas_error ivas_masa_dec_reconfigure( } } } - if ( st_ivas->hIsmRendererData ) - { - FOR( Word16 ind1 = 0; ind1 < st_ivas->hIsmRendererData->interpolator_len; ind1++ ) - { - st_ivas->hIsmRendererData->interpolator[ind1] = (float) ( st_ivas->hIsmRendererData->interpolator_fx[ind1] ) / (float) ( 1 << 15 ); - } - FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->gains_fx[ind1][ind2] ) / ( 1 << 30 ); - st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] ) / ( 1 << 30 ); - } - } - } FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { if ( st_ivas->hIsmMetaData[ind1] ) @@ -3677,7 +3675,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( IF( st_ivas->hDiracDecBin != NULL ) { /* regularization factor is bitrate-dependent */ - st_ivas->hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); + st_ivas->hDiracDecBin->reqularizationFactor_fx = configure_reqularization_factor_fx( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); } test(); @@ -3790,14 +3788,6 @@ ivas_error ivas_masa_dec_reconfigure_fx( { st_ivas->hIsmRendererData->interpolator_fx[ind1] = (Word16) L_min( 32767, floatToFixed( st_ivas->hIsmRendererData->interpolator_fx[ind1], 15 ) ); } - FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->gains[ind1][ind2] * ( 1 << 30 ) ); - st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->prev_gains[ind1][ind2] * ( 1 << 30 ) ); - } - } } FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { @@ -3893,14 +3883,23 @@ ivas_error ivas_masa_dec_reconfigure_fx( } } } + Word16 n_tc; + if (st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) + n_tc = st_ivas->nchan_ism; + else + n_tc = st_ivas->hTcBuffer->nchan_transport_internal; + for (int ch = 0; ch < n_tc; ch++) + { + floatToFixed_arrL(st_ivas->hTcBuffer->tc[ch], st_ivas->hTcBuffer->tc_fx[ch], Q11, L_FRAME48k); + } #endif IF( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, n_samples_granularity, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, MC_MODE_NONE, ISM_MASA_MODE_DISC, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { return error; } #if 1 /*Fixed to float */ - IF ( hTcBuffer->tc_buffer ) - fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); + if ( hTcBuffer->tc_buffer ) + fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); IF( hSpar ) { FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) @@ -3944,22 +3943,6 @@ ivas_error ivas_masa_dec_reconfigure_fx( } } } - - if ( st_ivas->hIsmRendererData ) - { - FOR( Word16 ind1 = 0; ind1 < st_ivas->hIsmRendererData->interpolator_len; ind1++ ) - { - st_ivas->hIsmRendererData->interpolator[ind1] = (float) ( st_ivas->hIsmRendererData->interpolator_fx[ind1] ) / (float) ( 1 << 15 ); - } - FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->gains_fx[ind1][ind2] ) / ( 1 << 30 ); - st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] ) / ( 1 << 30 ); - } - } - } FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { if ( st_ivas->hIsmMetaData[ind1] ) @@ -4026,35 +4009,69 @@ ivas_error ivas_masa_dec_reconfigure_fx( * * Determine MASA metadata from the SPAR metadata *-------------------------------------------------------------------*/ - -void ivas_spar_param_to_masa_param_mapping( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ - float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ - float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ - const int16_t subframe /* i : Subframe to map */ +void fixedToFloat_arrL_check (Word32 *i, float *f, Word16 Q, Word16 l) +{ + for (int j = 0; j < l; j++) + { + float check = f[j]; + f[j] = fixedToFloat(i[j], Q); + float per = (check - f[j]) / check; + per = per * 100; + if (per > 5) + { + per = per; + } + } +} +void ivas_spar_param_to_masa_param_mapping_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ + Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ + Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ + Word16 q_cldfb[6][CLDFB_SLOTS_PER_SUBFRAME], + const Word16 subframe /* i : Subframe to map */ ) { - int16_t i, j, band, bin, slot, ch, nBins, nchan_transport; - int16_t mixer_mat_index; - int16_t dirac_write_idx; + Word16 i, j, band, bin, slot, ch, nBins, nchan_transport; + Word16 mixer_mat_index; + Word16 dirac_write_idx; DIRAC_DEC_HANDLE hDirAC; DIFFUSE_DISTRIBUTION_HANDLE hDiffuseDist; - float mixer_mat_sf_bands_real[SPAR_DIRAC_SPLIT_START_BAND][FOA_CHANNELS][FOA_CHANNELS]; - float mixer_mat_sf_bins_real[CLDFB_NO_CHANNELS_MAX][FOA_CHANNELS][FOA_CHANNELS]; - int16_t *band_grouping; - int16_t band_start, band_end; - float transportSignalEnergies[2][CLDFB_NO_CHANNELS_MAX]; - float transportSignalCrossCorrelation[CLDFB_NO_CHANNELS_MAX]; - float instEne; - float inCovarianceMtx[FOA_CHANNELS][FOA_CHANNELS]; - float foaCovarianceMtx[FOA_CHANNELS][FOA_CHANNELS]; - float Iy, Iz, Ix, E, azi, ele, I, ratio_float; - float diffuseGainX, diffuseGainY, diffuseGainZ, diffuseGainSum; - int16_t slot_idx, slot_idx_start, sf; + Word32 mixer_mat_sf_bands_real_fx[SPAR_DIRAC_SPLIT_START_BAND][FOA_CHANNELS][FOA_CHANNELS]; + Word32 mixer_mat_sf_bins_real_fx[CLDFB_NO_CHANNELS_MAX][FOA_CHANNELS][FOA_CHANNELS]; + Word16 *band_grouping; + Word16 band_start, band_end; + Word32 transportSignalEnergies_32[2][CLDFB_NO_CHANNELS_MAX] = { 0 }; + Word64 transportSignalEnergies_64[2][CLDFB_NO_CHANNELS_MAX] = { 0 }; + Word32 transportSignalCrossCorrelation_32[CLDFB_NO_CHANNELS_MAX] = { 0 }; + Word64 transportSignalCrossCorrelation_64[CLDFB_NO_CHANNELS_MAX] = { 0 }; + Word64 instEne_fx; + Word32 inCovarianceMtx_fx[FOA_CHANNELS][FOA_CHANNELS] = { 0 }; + Word16 q_inCovarianceMtx = 31; + Word32 foaCovarianceMtx_fx[FOA_CHANNELS][FOA_CHANNELS] = { 0 }; + Word32 Iy_fx, Iz_fx, Ix_fx, E_fx, azi_fx, ele_fx, I_fx, ratio_float_fx; + Word32 diffuseGainX_fx, diffuseGainY_fx, diffuseGainZ_fx, diffuseGainSum_fx; + Word16 slot_idx, slot_idx_start, sf; SPAR_DEC_HANDLE hSpar; - float slot_fac; + Word16 slot_fac_fx; + Word16 q_slot_fac = 0; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - + Word16 common_q = 31; + Word64 azi_val, ele_val; + Word64 transportSignalEnergies_max = 0; + Word64 transportSignalCrossCorrelation_max = 0; + Word64 max_common_val = 0; + Word16 azi_q = 0, ele_q = 0; + Word16 num_q, denom_q, res_q; + Word16 headroom_left_max_common = 63; // 0 value + Word16 q_max_common = 31; + Word32 ratio_float_fx_Q15, max_ratio_1_Q15; + FOR( Word16 ind = 0; ind < 6; ind++ ) + { + FOR( Word16 ind2 = 0; ind2 < 4; ind2++ ) + { + common_q = common_q < q_cldfb[ind][ind2] ? common_q : q_cldfb[ind][ind2]; + } + } /* Set values */ hDirAC = st_ivas->hDirAC; hSpatParamRendCom = st_ivas->hSpatParamRendCom; @@ -4067,43 +4084,46 @@ void ivas_spar_param_to_masa_param_mapping( dirac_write_idx = hSpatParamRendCom->render_to_md_map[subframe]; /* Init arrays */ - for ( i = 0; i < FOA_CHANNELS; i++ ) + FOR( i = 0; i < FOA_CHANNELS; i++ ) { - set_zero( inCovarianceMtx[i], FOA_CHANNELS ); + set32_fx( inCovarianceMtx_fx[i], 0, FOA_CHANNELS ); } /* Delay the SPAR mixing matrices to have them synced with the audio */ slot_idx_start = hSpar->slots_rendered; - slot_fac = 1.0f / (float) hSpar->subframe_nbslots[subframe]; - - for ( slot_idx = 0; slot_idx < hSpar->subframe_nbslots[subframe]; slot_idx++ ) + slot_fac_fx = BASOP_Util_Divide3232_Scale( 1, hSpar->subframe_nbslots[subframe], &q_slot_fac ); + IF( q_slot_fac < 0 ) + { + slot_fac_fx = shr( slot_fac_fx, -1 * q_slot_fac ); + } + FOR( slot_idx = 0; slot_idx < hSpar->subframe_nbslots[subframe]; slot_idx++ ) { sf = hSpar->render_to_md_map[slot_idx + slot_idx_start] / JBM_CLDFB_SLOTS_IN_SUBFRAME; - if ( ( sf < SPAR_META_DELAY_SUBFRAMES ) ) + IF( ( sf < SPAR_META_DELAY_SUBFRAMES ) ) { mixer_mat_index = sf + MAX_PARAM_SPATIAL_SUBFRAMES - SPAR_META_DELAY_SUBFRAMES + 1; - for ( band = 0; band < SPAR_DIRAC_SPLIT_START_BAND; band++ ) + FOR( band = 0; band < SPAR_DIRAC_SPLIT_START_BAND; band++ ) { - for ( i = 0; i < FOA_CHANNELS; i++ ) + FOR( i = 0; i < FOA_CHANNELS; i++ ) { - for ( j = 0; j < FOA_CHANNELS; j++ ) + FOR( j = 0; j < FOA_CHANNELS; j++ ) { - mixer_mat_sf_bands_real[band][i][j] = slot_fac * st_ivas->hSpar->hMdDec->mixer_mat_prev[mixer_mat_index][i][j][band]; + mixer_mat_sf_bands_real_fx[band][i][j] = L_shl( Mpy_32_16_1( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[mixer_mat_index][i][j][band], slot_fac_fx ), 1 ); // 30//making q to 31 } } } } - else + ELSE { mixer_mat_index = ( ivas_get_spar_dec_md_num_subframes( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ) == 1 ) ? 0 : ( sf - SPAR_META_DELAY_SUBFRAMES ); - for ( band = 0; band < SPAR_DIRAC_SPLIT_START_BAND; band++ ) + FOR( band = 0; band < SPAR_DIRAC_SPLIT_START_BAND; band++ ) { - for ( i = 0; i < FOA_CHANNELS; i++ ) + FOR( i = 0; i < FOA_CHANNELS; i++ ) { - for ( j = 0; j < FOA_CHANNELS; j++ ) + FOR( j = 0; j < FOA_CHANNELS; j++ ) { - mixer_mat_sf_bands_real[band][i][j] = slot_fac * st_ivas->hSpar->hMdDec->mixer_mat[i][j][band + mixer_mat_index * IVAS_MAX_NUM_BANDS]; + mixer_mat_sf_bands_real_fx[band][i][j] = L_shl( Mpy_32_16_1( st_ivas->hSpar->hMdDec->mixer_mat_fx[i][j][band + mixer_mat_index * IVAS_MAX_NUM_BANDS], slot_fac_fx ), 1 ); // 30//making q to 31 } } } @@ -4112,135 +4132,314 @@ void ivas_spar_param_to_masa_param_mapping( /* Map the mixing matrices from the frequency bands to frequency bins */ bin = 0; - for ( band = 0; band < SPAR_DIRAC_SPLIT_START_BAND; band++ ) + FOR( band = 0; band < SPAR_DIRAC_SPLIT_START_BAND; band++ ) { band_start = band_grouping[band]; band_end = band_grouping[band + 1]; - for ( bin = band_start; bin < band_end; bin++ ) + FOR( bin = band_start; bin < band_end; bin++ ) { - for ( i = 0; i < FOA_CHANNELS; i++ ) + FOR( i = 0; i < FOA_CHANNELS; i++ ) { - for ( j = 0; j < FOA_CHANNELS; j++ ) + FOR( j = 0; j < FOA_CHANNELS; j++ ) { - mixer_mat_sf_bins_real[bin][i][j] = mixer_mat_sf_bands_real[band][i][j]; + mixer_mat_sf_bins_real_fx[bin][i][j] = mixer_mat_sf_bands_real_fx[band][i][j]; // 31+q_slot_fac } } } } + nBins = bin; /* Determine MASA metadata */ /* Determine transport signal energies and cross correlations when more than 1 TC */ - if ( nchan_transport == 2 ) + IF( nchan_transport == 2 ) { - set_zero( transportSignalEnergies[0], nBins ); - set_zero( transportSignalEnergies[1], nBins ); - set_zero( transportSignalCrossCorrelation, nBins ); + FOR( slot = 0; slot < hSpatParamRendCom->subframe_nbslots[subframe]; slot++ ) + { + FOR( bin = 0; bin < nBins; bin++ ) + { + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + instEne_fx = ( (Word64) L_shr_sat( inRe_fx[ch][slot][bin], (Word16) ( q_cldfb[ch][slot] - common_q ) ) * L_shr_sat( inRe_fx[ch][slot][bin], (Word16) ( q_cldfb[ch][slot] - common_q ) ) ); + instEne_fx += ( (Word64) L_shr_sat( inIm_fx[ch][slot][bin], (Word16) ( q_cldfb[ch][slot] - common_q ) ) * L_shr_sat( inIm_fx[ch][slot][bin], (Word16) ( q_cldfb[ch][slot] - common_q ) ) ); + transportSignalEnergies_64[ch][bin] += instEne_fx; + } + transportSignalCrossCorrelation_64[bin] += (Word64) L_shr_sat( inRe_fx[0][slot][bin], (Word16) ( q_cldfb[0][slot] - common_q ) ) * L_shr_sat( inRe_fx[1][slot][bin], (Word16) ( q_cldfb[0][slot] - common_q ) ); + transportSignalCrossCorrelation_64[bin] += (Word64) L_shr_sat( inIm_fx[0][slot][bin], (Word16) ( q_cldfb[0][slot] - common_q ) ) * L_shr_sat( inIm_fx[1][slot][bin], (Word16) ( q_cldfb[0][slot] - common_q ) ); + } + } + + + FOR( bin = 0; bin < nBins; bin++ ) + { + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + transportSignalEnergies_max = transportSignalEnergies_max > transportSignalEnergies_64[ch][bin] ? transportSignalEnergies_max : transportSignalEnergies_64[ch][bin]; + } + transportSignalCrossCorrelation_max = transportSignalCrossCorrelation_max > transportSignalCrossCorrelation_64[bin] ? transportSignalCrossCorrelation_max : transportSignalCrossCorrelation_64[bin]; + } + + max_common_val = transportSignalEnergies_max > transportSignalCrossCorrelation_max ? transportSignalEnergies_max : transportSignalCrossCorrelation_max; - for ( slot = 0; slot < hSpatParamRendCom->subframe_nbslots[subframe]; slot++ ) + IF( max_common_val != 0 ) + { + headroom_left_max_common = W_norm( max_common_val ); + IF( headroom_left_max_common > 32 ) + { + FOR( bin = 0; bin < nBins; bin++ ) + { + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + transportSignalEnergies_32[ch][bin] = (Word32) transportSignalEnergies_64[ch][bin]; + } + transportSignalCrossCorrelation_32[bin] = (Word32) transportSignalCrossCorrelation_64[bin]; + } + q_max_common = ( 2 * common_q ); + } + ELSE + { + FOR( bin = 0; bin < nBins; bin++ ) + { + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + transportSignalEnergies_32[ch][bin] = (Word32) W_shr( transportSignalEnergies_64[ch][bin], 32 - headroom_left_max_common ); + } + transportSignalCrossCorrelation_32[bin] = (Word32) W_shr( transportSignalCrossCorrelation_64[bin], 32 - headroom_left_max_common ); + } + q_max_common = ( 2 * common_q ) - ( 32 - headroom_left_max_common ); + } + } + ELSE { - for ( bin = 0; bin < nBins; bin++ ) + FOR( bin = 0; bin < nBins; bin++ ) { - for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - instEne = ( inRe[ch][slot][bin] * inRe[ch][slot][bin] ); - instEne += ( inIm[ch][slot][bin] * inIm[ch][slot][bin] ); - transportSignalEnergies[ch][bin] += instEne; + transportSignalEnergies_32[ch][bin] = 0; } - transportSignalCrossCorrelation[bin] += inRe[0][slot][bin] * inRe[1][slot][bin]; - transportSignalCrossCorrelation[bin] += inIm[0][slot][bin] * inIm[1][slot][bin]; + transportSignalCrossCorrelation_32[bin] = 0; } + q_max_common = 31; } } - if ( hDiffuseDist != NULL ) + + IF( hDiffuseDist != NULL ) { - set_zero( hDiffuseDist->diffuseRatioX, CLDFB_NO_CHANNELS_MAX ); - set_zero( hDiffuseDist->diffuseRatioY, CLDFB_NO_CHANNELS_MAX ); - set_zero( hDiffuseDist->diffuseRatioZ, CLDFB_NO_CHANNELS_MAX ); + set32_fx( hDiffuseDist->diffuseRatioX_fx, 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( hDiffuseDist->diffuseRatioY_fx, 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( hDiffuseDist->diffuseRatioZ_fx, 0, CLDFB_NO_CHANNELS_MAX ); } - for ( bin = 0; bin < nBins; bin++ ) + FOR( bin = 0; bin < nBins; bin++ ) { /* Set the energy of the first transport signal */ - if ( nchan_transport == 1 ) + IF( nchan_transport == 1 ) { - inCovarianceMtx[0][0] = 1.0f; /* In case of 1TC, fixed value can be used */ + inCovarianceMtx_fx[0][0] = ONE_IN_Q31; /* In case of 1TC, fixed value can be used */ + q_inCovarianceMtx = 31; /* In case of 1TC, fixed value can be used */ } - else + ELSE { - inCovarianceMtx[0][0] = transportSignalEnergies[0][bin]; /* In case of 2TC, use actual energies */ + inCovarianceMtx_fx[0][0] = transportSignalEnergies_32[0][bin]; /* In case of 2TC, use actual energies */ + q_inCovarianceMtx = q_max_common; /* In case of 1TC, fixed value can be used */ } /* Decorrelated channels assumed to have the same energy as the source channel */ - inCovarianceMtx[1][1] = inCovarianceMtx[0][0]; - inCovarianceMtx[2][2] = inCovarianceMtx[0][0]; - inCovarianceMtx[3][3] = inCovarianceMtx[0][0]; + inCovarianceMtx_fx[1][1] = inCovarianceMtx_fx[0][0]; + inCovarianceMtx_fx[2][2] = inCovarianceMtx_fx[0][0]; + inCovarianceMtx_fx[3][3] = inCovarianceMtx_fx[0][0]; /* In case residuals were transmitted, use their actual energies and cross correlations */ - if ( nchan_transport == 2 ) + IF( nchan_transport == 2 ) { - inCovarianceMtx[1][1] = transportSignalEnergies[1][bin]; - inCovarianceMtx[0][1] = transportSignalCrossCorrelation[bin]; - inCovarianceMtx[1][0] = inCovarianceMtx[0][1]; + + inCovarianceMtx_fx[1][1] = transportSignalEnergies_32[1][bin]; + inCovarianceMtx_fx[0][1] = transportSignalCrossCorrelation_32[bin]; + inCovarianceMtx_fx[1][0] = inCovarianceMtx_fx[0][1]; + q_inCovarianceMtx = q_max_common; } - compute_foa_cov_matrix( foaCovarianceMtx, inCovarianceMtx, mixer_mat_sf_bins_real[bin] ); + compute_foa_cov_matrix_fx( foaCovarianceMtx_fx, inCovarianceMtx_fx, mixer_mat_sf_bins_real_fx[bin] ); - /* Estimate MASA metadata */ - Iy = foaCovarianceMtx[0][1]; /* Intensity in Y direction */ - Iz = foaCovarianceMtx[0][2]; /* Intensity in Z direction */ - Ix = foaCovarianceMtx[0][3]; /* Intensity in X direction */ - I = sqrtf( Ix * Ix + Iy * Iy + Iz * Iz ); /* Intensity vector length */ - E = ( foaCovarianceMtx[0][0] + foaCovarianceMtx[1][1] + foaCovarianceMtx[2][2] + foaCovarianceMtx[3][3] ) / 2.0f; /* Overall energy */ - azi = atan2f( Iy, Ix ); /* Azimuth */ - ele = atan2f( Iz, sqrtf( Ix * Ix + Iy * Iy ) ); /* Elevation */ - ratio_float = I / fmaxf( 1e-12f, E ); /* Energy ratio */ - ratio_float = fmaxf( 0.0f, fminf( 1.0f, ratio_float ) ); + Iy_fx = foaCovarianceMtx_fx[0][1]; /* Intensity in Y direction */ + Iz_fx = foaCovarianceMtx_fx[0][2]; /* Intensity in Z direction */ + Ix_fx = foaCovarianceMtx_fx[0][3]; /* Intensity in X direction */ - hSpatParamRendCom->azimuth[dirac_write_idx][bin] = (int16_t) roundf( azi / PI_OVER_180 ); - hSpatParamRendCom->elevation[dirac_write_idx][bin] = (int16_t) roundf( ele / PI_OVER_180 ); - hSpatParamRendCom->energy_ratio1[dirac_write_idx][bin] = ratio_float; - hSpatParamRendCom->diffuseness_vector[dirac_write_idx][bin] = 1.0f - ratio_float; + Word64 I1 = (Word64) Ix_fx * Ix_fx; + Word64 I2 = (Word64) Iy_fx * Iy_fx; + Word64 I3 = (Word64) Iz_fx * Iz_fx; + Word64 I_res = W_add( W_add( I1, I2 ), I3 ); + Word64 E_fx_64 = W_add( W_add( W_add( foaCovarianceMtx_fx[0][0], foaCovarianceMtx_fx[1][1] ), foaCovarianceMtx_fx[2][2] ), foaCovarianceMtx_fx[3][3] ); + E_fx = L_shr_sat( L_add_sat( L_add_sat( L_add_sat( foaCovarianceMtx_fx[0][0], foaCovarianceMtx_fx[1][1] ), foaCovarianceMtx_fx[2][2] ), foaCovarianceMtx_fx[3][3] ), 1 ); + E_fx_64 = W_shr( E_fx_64, 1 ); + + Word16 headroom_left_I_res = W_norm( I_res ); + Word16 q_I_res; + IF( headroom_left_I_res < 32 ) + { + I_res = W_shr( I_res, (Word16) ( 32 - headroom_left_I_res ) ); + q_I_res = (Word16) ( 31 - ( ( 2 * q_inCovarianceMtx ) - ( 32 - headroom_left_I_res ) ) ); + } + ELSE + { + q_I_res = 31 - ( 2 * q_inCovarianceMtx ); + } + I_fx = Sqrt32( (Word32) I_res, &q_I_res ); + IF( q_I_res < 0 ) + { + I_fx = L_shr( I_fx, -1 * q_I_res ); + q_I_res = 0; + } + azi_q = 0; + azi_fx = BASOP_util_atan2( Iy_fx, Ix_fx, azi_q ); /* Azimuth */ + + Word64 I_ele_x = (Word64) Ix_fx * Ix_fx; + Word64 I_ele_y = (Word64) Iy_fx * Iy_fx; + Word64 I_ele = W_add( I_ele_x, I_ele_y ); + Word16 headroom_left_I_ele = W_norm( I_ele ); + ele_q; + IF( headroom_left_I_ele < 32 ) + { + I_ele = W_shr( I_ele, (Word16) ( 32 - headroom_left_I_ele ) ); + ele_q = (Word16) ( 31 - ( ( 2 * q_inCovarianceMtx ) - ( 32 - headroom_left_I_ele ) ) ); + } + ELSE + { + ele_q = 31 - ( 2 * q_inCovarianceMtx ); + } + I_ele = Sqrt32( (Word32) I_ele, &ele_q ); + IF( ele_q < 0 ) + { + I_ele = L_shr( (Word32) I_ele, -1 * ele_q ); + ele_q = 0; + } + ele_fx = BASOP_util_atan2( Iz_fx, (Word32) I_ele, ( 31 - q_inCovarianceMtx ) - ( ele_q ) ); + + num_q = 31 - q_I_res; + denom_q = q_inCovarianceMtx; + res_q = 0; + E_fx = E_fx > 0 ? E_fx : 1; + ratio_float_fx = BASOP_Util_Divide3232_Scale( I_fx, E_fx, &res_q ); + res_q = res_q - ( num_q - denom_q ); + IF( res_q < 0 ) + { + ratio_float_fx = L_shr( ratio_float_fx, -1 * res_q ); + res_q = 0; + } + ratio_float_fx_Q15 = L_shl( ratio_float_fx, res_q ); + max_ratio_1_Q15 = MAX_WORD16; + IF( ratio_float_fx_Q15 > max_ratio_1_Q15 ) + { + ratio_float_fx_Q15 = max_ratio_1_Q15; + } + azi_val = (Word64) azi_fx * ONE_BY_PI_OVER_180_Q25; + IF( azi_val < 0 ) + { + azi_val = W_shr( -1 * azi_val, 13 + 25 ); + azi_val = -1 * azi_val; + } + ELSE + { + azi_val = W_shr( azi_val, 13 + 25 ); + } + ele_val = (Word64) ele_fx * ONE_BY_PI_OVER_180_Q25; + IF( ele_val < 0 ) + { + ele_val = W_shr( -1 * ele_val, 13 + 25 ); + ele_val = -1 * ele_val; + } + ELSE + { + ele_val = W_shr( ele_val, 13 + 25 ); + } + + hSpatParamRendCom->azimuth[dirac_write_idx][bin] = (Word16) azi_val; + hSpatParamRendCom->elevation[dirac_write_idx][bin] = (Word16) ele_val; + + hSpatParamRendCom->energy_ratio1_fx[dirac_write_idx][bin] = L_deposit_h( (Word16) ratio_float_fx_Q15 ); + hSpatParamRendCom->diffuseness_vector_fx[dirac_write_idx][bin] = L_deposit_h( sub( 32767, (Word16) ratio_float_fx_Q15 ) ); + hSpatParamRendCom->spreadCoherence_fx[dirac_write_idx][bin] = 0; + hSpatParamRendCom->surroundingCoherence_fx[dirac_write_idx][bin] = 0; + + + // Tobe deleted + hSpatParamRendCom->energy_ratio1[dirac_write_idx][bin] = (float) hSpatParamRendCom->energy_ratio1_fx[dirac_write_idx][bin] / ONE_IN_Q31; + hSpatParamRendCom->diffuseness_vector[dirac_write_idx][bin] = (float) hSpatParamRendCom->diffuseness_vector_fx[dirac_write_idx][bin] / ONE_IN_Q31; hSpatParamRendCom->spreadCoherence[dirac_write_idx][bin] = 0.0f; hSpatParamRendCom->surroundingCoherence[dirac_write_idx][bin] = 0.0f; + //// + /* Determine directional distribution of the indirect audio based on the SPAR mixing matrices (and the transport audio signals when 2 TC) */ - if ( hDiffuseDist != NULL ) + IF( hDiffuseDist != NULL ) { - if ( nchan_transport == 1 ) + IF( nchan_transport == 1 ) { - diffuseGainY = fabsf( mixer_mat_sf_bins_real[bin][1][1] ); - diffuseGainX = fabsf( mixer_mat_sf_bins_real[bin][3][2] ); - diffuseGainZ = fabsf( mixer_mat_sf_bins_real[bin][2][3] ); + diffuseGainY_fx = L_abs( mixer_mat_sf_bins_real_fx[bin][1][1] ); + diffuseGainX_fx = L_abs( mixer_mat_sf_bins_real_fx[bin][3][2] ); + diffuseGainZ_fx = L_abs( mixer_mat_sf_bins_real_fx[bin][2][3] ); } - else if ( nchan_transport == 2 ) + ELSE IF( nchan_transport == 2 ) { - diffuseGainY = fabsf( mixer_mat_sf_bins_real[bin][1][1] * transportSignalEnergies[1][bin] ); - diffuseGainX = fabsf( mixer_mat_sf_bins_real[bin][3][2] * transportSignalEnergies[0][bin] ) + fabsf( mixer_mat_sf_bins_real[bin][3][1] * transportSignalEnergies[1][bin] ); - diffuseGainZ = fabsf( mixer_mat_sf_bins_real[bin][2][3] * transportSignalEnergies[0][bin] ) + fabsf( mixer_mat_sf_bins_real[bin][2][1] * transportSignalEnergies[1][bin] ); + diffuseGainY_fx = L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][1][1], transportSignalEnergies_32[1][bin] ) ); + diffuseGainX_fx = L_add_sat( L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][3][2], transportSignalEnergies_32[0][bin] ) ), L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][3][1], transportSignalEnergies_32[1][bin] ) ) ); + diffuseGainZ_fx = L_add_sat( L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][2][3], transportSignalEnergies_32[0][bin] ) ), L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][2][1], transportSignalEnergies_32[1][bin] ) ) ); } - else + ELSE { - diffuseGainY = 1.0f; - diffuseGainX = 1.0f; - diffuseGainZ = 1.0f; + diffuseGainY_fx = ONE_IN_Q31; + diffuseGainX_fx = ONE_IN_Q31; + diffuseGainZ_fx = ONE_IN_Q31; } + diffuseGainSum_fx = L_add_sat( L_add_sat( diffuseGainY_fx, diffuseGainX_fx ), diffuseGainZ_fx ); - diffuseGainSum = diffuseGainY + diffuseGainX + diffuseGainZ; - - if ( diffuseGainSum == 0.0f ) + IF( diffuseGainSum_fx == 0 ) { - hDiffuseDist->diffuseRatioX[bin] = 1.0f / 3.0f; - hDiffuseDist->diffuseRatioY[bin] = 1.0f / 3.0f; - hDiffuseDist->diffuseRatioZ[bin] = 1.0f / 3.0f; + hDiffuseDist->diffuseRatioX_fx[bin] = 715827904; + hDiffuseDist->diffuseRatioY_fx[bin] = 715827904; + hDiffuseDist->diffuseRatioZ_fx[bin] = 715827904; } - else + ELSE { - hDiffuseDist->diffuseRatioX[bin] = diffuseGainX / ( diffuseGainSum + EPSILON ); - hDiffuseDist->diffuseRatioY[bin] = diffuseGainY / ( diffuseGainSum + EPSILON ); - hDiffuseDist->diffuseRatioZ[bin] = diffuseGainZ / ( diffuseGainSum + EPSILON ); + Word16 temp_q = 0; + Word16 intermediate_results; + intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainX_fx, diffuseGainSum_fx + EPSILON_FX_SMALL, &temp_q ); + // saturating value to less than 1 + IF( temp_q <= 0 ) + { + intermediate_results = shr( (Word16) intermediate_results, -1 * temp_q ); + } + ELSE + { + intermediate_results = shl_sat( (Word16) intermediate_results, temp_q ); + } + hDiffuseDist->diffuseRatioX_fx[bin] = L_deposit_h( intermediate_results ); + + intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainY_fx, diffuseGainSum_fx + EPSILON_FX_SMALL, &temp_q ); + // saturating value to less than 1 + IF( temp_q <= 0 ) + { + intermediate_results = shr( (Word16) intermediate_results, -1 * temp_q ); + } + ELSE + { + intermediate_results = shl_sat( (Word16) intermediate_results, temp_q ); + } + hDiffuseDist->diffuseRatioY_fx[bin] = L_deposit_h( intermediate_results ); + + intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainZ_fx, diffuseGainSum_fx + EPSILON_FX_SMALL, &temp_q ); + // saturating value to less than 1 + IF( temp_q <= 0 ) + { + intermediate_results = shr( (Word16) intermediate_results, -1 * temp_q ); + } + ELSE + { + intermediate_results = shl_sat( (Word16) intermediate_results, temp_q ); + } + hDiffuseDist->diffuseRatioZ_fx[bin] = L_deposit_h( intermediate_results ); } } } @@ -4248,39 +4447,259 @@ void ivas_spar_param_to_masa_param_mapping( return; } +void ivas_spar_param_to_masa_param_mapping( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ + float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ + float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ + const int16_t subframe /* i : Subframe to map */ +) +{ + int16_t i, j, band, bin, slot, ch, nBins, nchan_transport; + int16_t mixer_mat_index; + int16_t dirac_write_idx; + DIRAC_DEC_HANDLE hDirAC; + DIFFUSE_DISTRIBUTION_HANDLE hDiffuseDist; + float mixer_mat_sf_bands_real[SPAR_DIRAC_SPLIT_START_BAND][FOA_CHANNELS][FOA_CHANNELS]; + float mixer_mat_sf_bins_real[CLDFB_NO_CHANNELS_MAX][FOA_CHANNELS][FOA_CHANNELS]; + int16_t *band_grouping; + int16_t band_start, band_end; + float transportSignalEnergies[2][CLDFB_NO_CHANNELS_MAX]; + float transportSignalCrossCorrelation[CLDFB_NO_CHANNELS_MAX]; + float instEne; + float inCovarianceMtx[FOA_CHANNELS][FOA_CHANNELS]; + float foaCovarianceMtx[FOA_CHANNELS][FOA_CHANNELS]; + float Iy, Iz, Ix, E, azi, ele, I, ratio_float; + float diffuseGainX, diffuseGainY, diffuseGainZ, diffuseGainSum; + int16_t slot_idx, slot_idx_start, sf; + SPAR_DEC_HANDLE hSpar; + float slot_fac; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + + /* Set values */ + hDirAC = st_ivas->hDirAC; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + hSpatParamRendCom->numParametricDirections = 1; + hSpatParamRendCom->numSimultaneousDirections = 1; + hDiffuseDist = st_ivas->hDiracDecBin->hDiffuseDist; + nchan_transport = st_ivas->nchan_transport; + band_grouping = hDirAC->band_grouping; + hSpar = st_ivas->hSpar; + dirac_write_idx = hSpatParamRendCom->render_to_md_map[subframe]; + + /* Init arrays */ + for (i = 0; i < FOA_CHANNELS; i++) + { + set_zero(inCovarianceMtx[i], FOA_CHANNELS); + } + + /* Delay the SPAR mixing matrices to have them synced with the audio */ + slot_idx_start = hSpar->slots_rendered; + slot_fac = 1.0f / (float)hSpar->subframe_nbslots[subframe]; + + for (slot_idx = 0; slot_idx < hSpar->subframe_nbslots[subframe]; slot_idx++) + { + sf = hSpar->render_to_md_map[slot_idx + slot_idx_start] / JBM_CLDFB_SLOTS_IN_SUBFRAME; + + if ((sf < SPAR_META_DELAY_SUBFRAMES)) + { + mixer_mat_index = sf + MAX_PARAM_SPATIAL_SUBFRAMES - SPAR_META_DELAY_SUBFRAMES + 1; + for (band = 0; band < SPAR_DIRAC_SPLIT_START_BAND; band++) + { + for (i = 0; i < FOA_CHANNELS; i++) + { + for (j = 0; j < FOA_CHANNELS; j++) + { + mixer_mat_sf_bands_real[band][i][j] = slot_fac * st_ivas->hSpar->hMdDec->mixer_mat_prev[mixer_mat_index][i][j][band]; + } + } + } + } + else + { + mixer_mat_index = (ivas_get_spar_dec_md_num_subframes(st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate) == 1) ? 0 : (sf - SPAR_META_DELAY_SUBFRAMES); + for (band = 0; band < SPAR_DIRAC_SPLIT_START_BAND; band++) + { + for (i = 0; i < FOA_CHANNELS; i++) + { + for (j = 0; j < FOA_CHANNELS; j++) + { + mixer_mat_sf_bands_real[band][i][j] = slot_fac * st_ivas->hSpar->hMdDec->mixer_mat[i][j][band + mixer_mat_index * IVAS_MAX_NUM_BANDS]; + } + } + } + } + } + + /* Map the mixing matrices from the frequency bands to frequency bins */ + bin = 0; + for (band = 0; band < SPAR_DIRAC_SPLIT_START_BAND; band++) + { + band_start = band_grouping[band]; + band_end = band_grouping[band + 1]; + for (bin = band_start; bin < band_end; bin++) + { + for (i = 0; i < FOA_CHANNELS; i++) + { + for (j = 0; j < FOA_CHANNELS; j++) + { + mixer_mat_sf_bins_real[bin][i][j] = mixer_mat_sf_bands_real[band][i][j]; + } + } + } + } + nBins = bin; + + /* Determine MASA metadata */ + /* Determine transport signal energies and cross correlations when more than 1 TC */ + if (nchan_transport == 2) + { + set_zero(transportSignalEnergies[0], nBins); + set_zero(transportSignalEnergies[1], nBins); + set_zero(transportSignalCrossCorrelation, nBins); + + for (slot = 0; slot < hSpatParamRendCom->subframe_nbslots[subframe]; slot++) + { + for (bin = 0; bin < nBins; bin++) + { + for (ch = 0; ch < BINAURAL_CHANNELS; ch++) + { + instEne = (inRe[ch][slot][bin] * inRe[ch][slot][bin]); + instEne += (inIm[ch][slot][bin] * inIm[ch][slot][bin]); + transportSignalEnergies[ch][bin] += instEne; + } + transportSignalCrossCorrelation[bin] += inRe[0][slot][bin] * inRe[1][slot][bin]; + transportSignalCrossCorrelation[bin] += inIm[0][slot][bin] * inIm[1][slot][bin]; + } + } + } + + if (hDiffuseDist != NULL) + { + set_zero(hDiffuseDist->diffuseRatioX, CLDFB_NO_CHANNELS_MAX); + set_zero(hDiffuseDist->diffuseRatioY, CLDFB_NO_CHANNELS_MAX); + set_zero(hDiffuseDist->diffuseRatioZ, CLDFB_NO_CHANNELS_MAX); + } + + for (bin = 0; bin < nBins; bin++) + { + /* Set the energy of the first transport signal */ + if (nchan_transport == 1) + { + inCovarianceMtx[0][0] = 1.0f; /* In case of 1TC, fixed value can be used */ + } + else + { + inCovarianceMtx[0][0] = transportSignalEnergies[0][bin]; /* In case of 2TC, use actual energies */ + } + + /* Decorrelated channels assumed to have the same energy as the source channel */ + inCovarianceMtx[1][1] = inCovarianceMtx[0][0]; + inCovarianceMtx[2][2] = inCovarianceMtx[0][0]; + inCovarianceMtx[3][3] = inCovarianceMtx[0][0]; + + /* In case residuals were transmitted, use their actual energies and cross correlations */ + if (nchan_transport == 2) + { + inCovarianceMtx[1][1] = transportSignalEnergies[1][bin]; + inCovarianceMtx[0][1] = transportSignalCrossCorrelation[bin]; + inCovarianceMtx[1][0] = inCovarianceMtx[0][1]; + } + + compute_foa_cov_matrix(foaCovarianceMtx, inCovarianceMtx, mixer_mat_sf_bins_real[bin]); + + /* Estimate MASA metadata */ + Iy = foaCovarianceMtx[0][1]; /* Intensity in Y direction */ + Iz = foaCovarianceMtx[0][2]; /* Intensity in Z direction */ + Ix = foaCovarianceMtx[0][3]; /* Intensity in X direction */ + I = sqrtf(Ix * Ix + Iy * Iy + Iz * Iz); /* Intensity vector length */ + E = (foaCovarianceMtx[0][0] + foaCovarianceMtx[1][1] + foaCovarianceMtx[2][2] + foaCovarianceMtx[3][3]) / 2.0f; /* Overall energy */ + azi = atan2f(Iy, Ix); /* Azimuth */ + ele = atan2f(Iz, sqrtf(Ix * Ix + Iy * Iy)); /* Elevation */ + ratio_float = I / fmaxf(1e-12f, E); /* Energy ratio */ + ratio_float = fmaxf(0.0f, fminf(1.0f, ratio_float)); + + hSpatParamRendCom->azimuth[dirac_write_idx][bin] = (int16_t)roundf(azi / PI_OVER_180); + hSpatParamRendCom->elevation[dirac_write_idx][bin] = (int16_t)roundf(ele / PI_OVER_180); + hSpatParamRendCom->energy_ratio1[dirac_write_idx][bin] = ratio_float; + hSpatParamRendCom->diffuseness_vector[dirac_write_idx][bin] = 1.0f - ratio_float; + + hSpatParamRendCom->spreadCoherence[dirac_write_idx][bin] = 0.0f; + hSpatParamRendCom->surroundingCoherence[dirac_write_idx][bin] = 0.0f; + + /* Determine directional distribution of the indirect audio based on the SPAR mixing matrices (and the transport audio signals when 2 TC) */ + if (hDiffuseDist != NULL) + { + if (nchan_transport == 1) + { + diffuseGainY = fabsf(mixer_mat_sf_bins_real[bin][1][1]); + diffuseGainX = fabsf(mixer_mat_sf_bins_real[bin][3][2]); + diffuseGainZ = fabsf(mixer_mat_sf_bins_real[bin][2][3]); + } + else if (nchan_transport == 2) + { + diffuseGainY = fabsf(mixer_mat_sf_bins_real[bin][1][1] * transportSignalEnergies[1][bin]); + diffuseGainX = fabsf(mixer_mat_sf_bins_real[bin][3][2] * transportSignalEnergies[0][bin]) + fabsf(mixer_mat_sf_bins_real[bin][3][1] * transportSignalEnergies[1][bin]); + diffuseGainZ = fabsf(mixer_mat_sf_bins_real[bin][2][3] * transportSignalEnergies[0][bin]) + fabsf(mixer_mat_sf_bins_real[bin][2][1] * transportSignalEnergies[1][bin]); + } + else + { + diffuseGainY = 1.0f; + diffuseGainX = 1.0f; + diffuseGainZ = 1.0f; + } + + diffuseGainSum = diffuseGainY + diffuseGainX + diffuseGainZ; + + if (diffuseGainSum == 0.0f) + { + hDiffuseDist->diffuseRatioX[bin] = 1.0f / 3.0f; + hDiffuseDist->diffuseRatioY[bin] = 1.0f / 3.0f; + hDiffuseDist->diffuseRatioZ[bin] = 1.0f / 3.0f; + } + else + { + hDiffuseDist->diffuseRatioX[bin] = diffuseGainX / (diffuseGainSum + EPSILON); + hDiffuseDist->diffuseRatioY[bin] = diffuseGainY / (diffuseGainSum + EPSILON); + hDiffuseDist->diffuseRatioZ[bin] = diffuseGainZ / (diffuseGainSum + EPSILON); + } + } + } + + return; +} + /* Estimate FOA properties: foaCov = mixMtx * inCov * mixMtx' */ -static void compute_foa_cov_matrix( - float foaCov[FOA_CHANNELS][FOA_CHANNELS], /* o : Estimated FOA covariance matrix */ - float inCov[FOA_CHANNELS][FOA_CHANNELS], /* i : Input covariance matrix */ - float mixMtx[FOA_CHANNELS][FOA_CHANNELS] /* i : Mixing matrix */ +static void compute_foa_cov_matrix_fx( + Word32 foaCov_fx[FOA_CHANNELS][FOA_CHANNELS], /* o : Estimated FOA covariance matrix */ + Word32 inCov_fx[FOA_CHANNELS][FOA_CHANNELS], /* i : Input covariance matrix */ + Word32 mixMtx_fx[FOA_CHANNELS][FOA_CHANNELS] /* i : Mixing matrix */ ) { - float tmpMtx[FOA_CHANNELS][FOA_CHANNELS]; - int16_t i, j, k; - + Word32 tmpMtx_fx[FOA_CHANNELS][FOA_CHANNELS]; + Word16 i, j, k; /* tmpMtx = mixMtx * inCov */ - for ( i = 0; i < FOA_CHANNELS; i++ ) + FOR( i = 0; i < FOA_CHANNELS; i++ ) { - for ( j = 0; j < FOA_CHANNELS; j++ ) + FOR( j = 0; j < FOA_CHANNELS; j++ ) { - tmpMtx[i][j] = 0.0f; - for ( k = 0; k < FOA_CHANNELS; k++ ) + tmpMtx_fx[i][j] = 0; + FOR( k = 0; k < FOA_CHANNELS; k++ ) { - tmpMtx[i][j] += mixMtx[i][k] * inCov[k][j]; + tmpMtx_fx[i][j] = L_add_sat( tmpMtx_fx[i][j], Mpy_32_32( mixMtx_fx[i][k], inCov_fx[k][j] ) ); } } } /* foaCov = inCov * mixMtx' */ - for ( i = 0; i < FOA_CHANNELS; i++ ) + FOR( i = 0; i < FOA_CHANNELS; i++ ) { - for ( j = 0; j < FOA_CHANNELS; j++ ) + FOR( j = 0; j < FOA_CHANNELS; j++ ) { - foaCov[i][j] = 0.0f; - for ( k = 0; k < FOA_CHANNELS; k++ ) + foaCov_fx[i][j] = 0; + FOR( k = 0; k < FOA_CHANNELS; k++ ) { - foaCov[i][j] += tmpMtx[i][k] * mixMtx[j][k]; + foaCov_fx[i][j] = L_add_sat( foaCov_fx[i][j], Mpy_32_32( tmpMtx_fx[i][k], mixMtx_fx[j][k] ) ); } } } @@ -4288,6 +4707,45 @@ static void compute_foa_cov_matrix( return; } + +static void compute_foa_cov_matrix( + float foaCov[FOA_CHANNELS][FOA_CHANNELS], /* o : Estimated FOA covariance matrix */ + float inCov[FOA_CHANNELS][FOA_CHANNELS], /* i : Input covariance matrix */ + float mixMtx[FOA_CHANNELS][FOA_CHANNELS] /* i : Mixing matrix */ +) +{ + float tmpMtx[FOA_CHANNELS][FOA_CHANNELS]; + int16_t i, j, k; + + /* tmpMtx = mixMtx * inCov */ + for (i = 0; i < FOA_CHANNELS; i++) + { + for (j = 0; j < FOA_CHANNELS; j++) + { + tmpMtx[i][j] = 0.0f; + for (k = 0; k < FOA_CHANNELS; k++) + { + tmpMtx[i][j] += mixMtx[i][k] * inCov[k][j]; + } + } + } + + /* foaCov = inCov * mixMtx' */ + for (i = 0; i < FOA_CHANNELS; i++) + { + for (j = 0; j < FOA_CHANNELS; j++) + { + foaCov[i][j] = 0.0f; + for (k = 0; k < FOA_CHANNELS; k++) + { + foaCov[i][j] += tmpMtx[i][k] * mixMtx[j][k]; + } + } + } + + return; +} + static void create_masa_ext_out_meta( MASA_DECODER *hMasa, IVAS_QMETADATA_HANDLE hQMetaData, diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 4690c7af314967ab2efb79e069edb4e5785fe6f4..23f2cbeb96a66d27a2b08043501d37b3ad55c338 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -68,6 +68,9 @@ typedef struct parameter_band_mapping_struct int16_t n_source_bands[20]; int16_t source_band_idx[20][4]; float source_band_factor[20][4]; +#ifdef IVAS_FLOAT_FIXED + Word16 source_band_factor_fx[20][4];/*Q15*/ +#endif // IVAS_FLOAT_FIXED } PARAM_MC_PARAMETER_BAND_MAPPING; @@ -78,9 +81,11 @@ typedef struct parameter_band_mapping_struct static void ivas_param_mc_dec_init( PARAM_MC_DEC_HANDLE hParamMC, const int16_t nchan_in, const int16_t nchan_out ); static void param_mc_protoSignalComputation( float *RealBuffer, float *ImagBuffer, float *proto_frame_f, const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, const int16_t num_freq_bands ); - +#ifdef IVAS_FLOAT_FIXED +static void ivas_param_mc_dec_copy_diffuse_proto(PARAM_MC_DEC_HANDLE hParamMC, Word32 Cldfb_buffer_real_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 Cldfb_buffer_imag_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const Word16 nY, const Word16 slot_idx); +#else static void ivas_param_mc_dec_copy_diffuse_proto( PARAM_MC_DEC_HANDLE hParamMC, float Cldfb_buffer_real[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float Cldfb_buffer_imag[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const int16_t nY, const int16_t slot_idx ); - +#endif static int16_t ivas_param_mc_range_decoder_LC( uint16_t *bit_buffer, int16_t *x, int16_t *BER_detect, const int16_t sz_seq, const int16_t sz_alphabet, const uint16_t *cft, const uint16_t *sft, const int16_t tot_shift, const int16_t nbbits ); static int16_t ivas_param_mc_uniform_decoder( float *seq, const int16_t sz_seq, const float *alphabet, const int16_t N, uint16_t bit_buffer[PARAM_MC_MAX_BITS] ); @@ -93,6 +98,10 @@ static void ivas_param_mc_get_mono_stereo_mixing_matrices( PARAM_MC_DEC_HANDLE h static void param_mc_update_mixing_matrices( PARAM_MC_DEC_HANDLE hParamMC, float *mixing_matrix[], float *mixing_matrix_res[], const uint16_t nX, const uint16_t nY ); +#ifdef IVAS_FLOAT_FIXED +static void ivas_param_mc_dec_compute_interpolator_fx( const UWord16 bAttackPresent, const UWord16 attackPos, const UWord16 interp_length, Word16 *interpolator ); +#endif // IVAS_FLOAT_FIXED + static void ivas_param_mc_dec_compute_interpolator( const uint16_t bAttackPresent, const uint16_t attackPos, const uint16_t interp_length, float *interpolator ); static void param_mc_set_num_synth_bands( const int32_t output_Fs, PARAM_MC_DEC_HANDLE hParamMC ); @@ -105,6 +114,7 @@ static void ivas_param_mc_bs_decode_parameter_values( uint16_t bit_buffer[], int #ifdef IVAS_FLOAT_FIXED static void ivas_param_mc_dequantize_cov_fx(PARAM_MC_DEC_HANDLE hParamMC, Word16 *ild_q_fx, Word16 *icc_q_fx, const Word16 param_band_index, const Word16 nY_cov, const PARAM_MC_SYNTHESIS_CONF synth_conf, const Word16 nY_int, const Word16 nX, Word32 *Cx_state_fx, Word16 Cx_state_e, Word32 *Cproto_fx, Word16 Cproto_e, Word32 *Cy_state_fx, Word16 *Cy_state_e); +static ivas_error param_mc_get_diff_proto_info_fx(const Word32 *proto_mtx, const UWord16 nchan_transport, const UWord16 nchan_out_cov, PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info); #endif /*------------------------------------------------------------------------- @@ -119,9 +129,14 @@ ivas_error ivas_param_mc_dec_open( { int16_t k, nchan_transport; PARAM_MC_DEC_HANDLE hParamMC; +#ifndef FIX_901_PARAMMC_DEAD_CODE IVAS_OUTPUT_SETUP hTransportSetup; +#endif int16_t nchan_out_transport; int16_t nchan_out_cov; +#ifdef IVAS_FLOAT_FIXED + Word32 proto_matrix_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; +#endif // IVAS_FLOAT_FIXED float proto_matrix[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; float proto_mtx_norm; int16_t max_param_band_residual; @@ -151,8 +166,9 @@ ivas_error ivas_param_mc_dec_open( output_Fs = st_ivas->hDecoderConfig->output_Fs; output_config = st_ivas->hDecoderConfig->output_config; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - +#ifndef FIX_901_PARAMMC_DEAD_CODE hTransportSetup = st_ivas->hTransSetup; +#endif mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; hParamMC->hoa_encoder = NULL; @@ -229,9 +245,19 @@ ivas_error ivas_param_mc_dec_open( hParamMC->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands; +#ifndef FIX_901_PARAMMC_DEAD_CODE ivas_param_mc_metadata_open( mc_ls_setup, hTransportSetup.index_lfe[0], ivas_total_brate, hParamMC->hMetadataPMC ); +#else + ivas_param_mc_metadata_open( mc_ls_setup, ivas_total_brate, hParamMC->hMetadataPMC ); +#endif /* init arrays for quantized parameters */ +#ifdef IVAS_FLOAT_FIXED + if ( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof(Word16) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } +#endif if ( ( hParamMC->icc_q = (float *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); @@ -335,6 +361,12 @@ ivas_error ivas_param_mc_dec_open( } } } +#ifdef IVAS_FLOAT_FIXED + if ( ( hParamMC->proto_matrix_int_fx = (Word32 *) malloc( nchan_out_transport * nchan_transport * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } +#endif // IVAS_FLOAT_FIXED if ( ( hParamMC->proto_matrix_int = (float *) malloc( nchan_out_transport * nchan_transport * sizeof( float ) ) ) == NULL ) { @@ -438,11 +470,20 @@ ivas_error ivas_param_mc_dec_open( } /* output synthesis */ +#ifdef IVAS_FLOAT_FIXED + floatToFixed_arrL( proto_matrix, proto_matrix_fx ,Q30,64); + if ( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ) != IVAS_ERR_OK ) + { + return error; + } + fixedToFloat_arrL( hParamMC->h_output_synthesis_params.proto_matrix_fx, hParamMC->h_output_synthesis_params.proto_matrix, 30, nchan_transport * nchan_out_cov ); +#else if ( ( error = ivas_dirac_dec_output_synthesis_cov_open( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix ) ) != IVAS_ERR_OK ) { return error; } +#endif // IVAS_FLOAT_FIXED ivas_param_mc_dec_compute_interpolator( 0, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hParamMC->h_output_synthesis_params.interpolator ); @@ -471,11 +512,20 @@ ivas_error ivas_param_mc_dec_open( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } +#ifdef IVAS_FLOAT_FIXED + if ((hParamMC->proto_frame_dec_f_fx = (Word32 *)malloc(2 * nchan_out_cov * hParamMC->num_freq_bands * sizeof(Word32))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n")); + } +#endif } else { hParamMC->proto_frame_f = NULL; hParamMC->proto_frame_dec_f = NULL; +#ifdef IVAS_FLOAT_FIXED + hParamMC->proto_frame_dec_f_fx = NULL; +#endif } ivas_param_mc_dec_init( hParamMC, nchan_transport, nchan_out_cov ); @@ -550,6 +600,60 @@ ivas_error ivas_param_mc_dec_open( * *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void ivas_param_mc_get_param_band_mapping( + const Word16 n_target_bands, + const Word16 *target_band_grouping, + const Word16 n_source_bands, + const Word16 *source_band_grouping, + PARAM_MC_PARAMETER_BAND_MAPPING *parameter_band_mapping ) +{ + Word16 target_band_idx; + Word16 source_band_idx = 0; + move16(); + Word16 source_band_cnt_total; + + FOR ( target_band_idx = 0; target_band_idx < n_target_bands; target_band_idx++ ) + { + Word16 upper = target_band_grouping[target_band_idx + 1]; + Word16 lower = target_band_grouping[target_band_idx]; + Word16 source_band_in_target_band_cnt = 0; + Word16 norm_fac_fx = 32767; + source_band_cnt_total = 0; + move16();move16();move16(); + + FOR ( source_band_idx = 0; source_band_idx < n_source_bands; source_band_idx++ ) + { + /* find lowest corresponding source band*/ + IF ( LE_16(source_band_grouping[source_band_idx] , lower) && GE_16(source_band_grouping[source_band_idx + 1] , lower) ) + { + DO + { + Word16 source_bands_in_target_band = sub(s_min( source_band_grouping[source_band_idx + 1], upper ) , s_max( source_band_grouping[source_band_idx], lower )); + IF ( source_bands_in_target_band ) + { + source_band_cnt_total = add(source_band_cnt_total,source_bands_in_target_band); + parameter_band_mapping->source_band_idx[target_band_idx][source_band_in_target_band_cnt] = source_band_idx; + parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_in_target_band_cnt++] = shl(source_bands_in_target_band,10); /*Q10*/ + move16(); + move16(); + } + source_band_idx++; + } WHILE ( LE_16(source_band_grouping[source_band_idx] , upper) && LT_16(source_band_idx , n_source_bands) ); + BREAK; + } + } + norm_fac_fx = div_s(1, source_band_cnt_total );/*Q15*/ + for ( source_band_idx = 0; source_band_idx < source_band_in_target_band_cnt; source_band_idx++ ) + { + parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_idx] = shl_sat(mult(parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_idx],norm_fac_fx)/*Q10*/,5);/*Q15*/ + } + parameter_band_mapping->n_source_bands[target_band_idx] = source_band_in_target_band_cnt; + move16(); + } + return; +} +#else static void ivas_param_mc_get_param_band_mapping( const int16_t n_target_bands, const int16_t *target_band_grouping, @@ -598,6 +702,7 @@ static void ivas_param_mc_get_param_band_mapping( return; } +#endif // IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- @@ -605,6 +710,569 @@ static void ivas_param_mc_get_param_band_mapping( * * Reconfiguration of ParamMC decoder *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_param_mc_dec_reconfig_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + Word16 k, nchan_transport; + PARAM_MC_DEC_HANDLE hParamMC; +#ifndef FIX_901_PARAMMC_DEAD_CODE + IVAS_OUTPUT_SETUP hTransportSetup; +#endif + Word16 nchan_out_transport; + Word16 nchan_out_cov; + Word32 proto_matrix_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; + Word32 proto_mtx_norm_fx; + Word16 max_param_band_residual; + UWord16 config_index; + MC_LS_SETUP mc_ls_setup; + Word32 output_Fs, ivas_total_brate; + ivas_error error; + Word16 nchan_transport_old; + Word16 num_param_bands_old; + PARAM_MC_PARAMETER_BAND_MAPPING parameter_band_mapping; + Word16 band_grouping_old[20 + 1]; + + hParamMC = st_ivas->hParamMC; + error = IVAS_ERR_OK; + /* save important config information from the previous state */ + nchan_transport_old = st_ivas->nchan_transport; + num_param_bands_old = hParamMC->hMetadataPMC->num_parameter_bands; + + /*-----------------------------------------------------------------* + * prepare library opening + *-----------------------------------------------------------------*/ + + output_Fs = st_ivas->hDecoderConfig->output_Fs; + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; +#ifndef FIX_901_PARAMMC_DEAD_CODE + hTransportSetup = st_ivas->hTransSetup; +#endif + mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); + nchan_out_transport = add(st_ivas->hTransSetup.nchan_out_woLFE , st_ivas->hTransSetup.num_lfe); + + IF ( EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_LS_CONV_COV) || EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) + { + nchan_out_cov = add(st_ivas->hOutSetup.nchan_out_woLFE , st_ivas->hOutSetup.num_lfe); + } + ELSE + { + nchan_out_cov = nchan_out_transport; + } + + st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); + config_index = ivas_param_mc_get_configuration_index( mc_ls_setup, ivas_total_brate ); + nchan_transport = st_ivas->nchan_transport; + + SWITCH ( nchan_transport ) + { + case 4: + case 3: + st_ivas->nCPE = 2; + st_ivas->nSCE = 0; + st_ivas->element_mode_init = IVAS_CPE_MDCT; + BREAK; + case 2: + st_ivas->nCPE = 1; + st_ivas->nSCE = 0; + st_ivas->element_mode_init = IVAS_CPE_MDCT; + + BREAK; + } + + /*-----------------------------------------------------------------* + * set input parameters + *-----------------------------------------------------------------*/ + hParamMC->num_freq_bands = shr( add( (Word16) Mpy_32_32( output_Fs, INV_CLDFB_BANDWIDTH_Q31 << 1 ), 1 ), 1 ); + hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands; + +#ifndef FIX_901_PARAMMC_DEAD_CODE + /* deallocate the full icc map, gets newly allocated in the metadata open function */ + + FOR ( k = 0; k < 2; k++ ) + { + IF ( hParamMC->hMetadataPMC->icc_map_full[k] != NULL ) + { + free( hParamMC->hMetadataPMC->icc_map_full[k] ); + hParamMC->hMetadataPMC->icc_map_full[k] = NULL; + } + } +#endif + Copy( hParamMC->band_grouping, band_grouping_old, add(hParamMC->hMetadataPMC->num_parameter_bands , 1) ); +#ifndef FIX_901_PARAMMC_DEAD_CODE + ivas_param_mc_metadata_open( mc_ls_setup, hTransportSetup.index_lfe[0], ivas_total_brate, hParamMC->hMetadataPMC ); +#else + ivas_param_mc_metadata_open( mc_ls_setup, ivas_total_brate, hParamMC->hMetadataPMC ); +#endif + /* Band Grouping */ + IF ( EQ_16(hParamMC->hMetadataPMC->num_parameter_bands , 20) ) + { + Copy( param_mc_band_grouping_20, hParamMC->band_grouping, 20 + 1 ); + } + ELSE IF ( EQ_16(hParamMC->hMetadataPMC->num_parameter_bands , 14) ) + { + Copy( param_mc_band_grouping_14, hParamMC->band_grouping, 14 + 1 ); + } + ELSE IF ( EQ_16(hParamMC->hMetadataPMC->num_parameter_bands , 10) ) + { + Copy( param_mc_band_grouping_10, hParamMC->band_grouping, 10 + 1 ); + } + ELSE + { + assert( 0 && "nbands must be 20, 14, or 10!" ); + } + + ivas_param_mc_get_param_band_mapping( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->band_grouping, num_param_bands_old, band_grouping_old, ¶meter_band_mapping ); + + IF ( NE_16(nchan_transport_old , nchan_transport) || NE_16(num_param_bands_old , hParamMC->hMetadataPMC->num_parameter_bands) ) + { + Word16 *ild_q_old_fx = hParamMC->icld_q_fx; + Word16 *icc_q_old_fx = hParamMC->icc_q_fx; +#if 1/*To be removed later*/ + + /* init arrays for the quantized parameters */ + IF ( ( hParamMC->icc_q = (float *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + IF ( ( hParamMC->icld_q = (float *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + set_f( hParamMC->icld_q, PARAM_MC_DEFAULT_MIN_ILD, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); + set_f( hParamMC->icc_q, 0.0f, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); +#endif + + IF ( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof(Word16) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + IF ( ( hParamMC->icld_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( Word16 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe );/*Q8*/ + set16_fx( hParamMC->icc_q_fx, 0, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe );/*Q15*/ + + /* map old to new parameter banding, only for same number of TCs, needs some more thought for a changing number of TCs */ + IF ( NE_16(num_param_bands_old , hParamMC->hMetadataPMC->num_parameter_bands) && EQ_16(nchan_transport_old , nchan_transport) ) + { + Word16 new_param_band_idx, param_idx, source_param_idx; + Word16 num_param_lfe; + Word16 *p_icc_new_fx = hParamMC->icc_q_fx; + Word16 *p_ild_new_fx = hParamMC->icld_q_fx; + Word16 p_ild_new_e = 23; + Word16 p_ild_new_tmp; + + /* ICC */ + num_param_lfe = hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe; + FOR ( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ ) + { + FOR ( param_idx = 0; param_idx < num_param_lfe; param_idx++ ) + { + *p_icc_new_fx = 0; + FOR ( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) + { + *p_icc_new_fx = add( *p_icc_new_fx, mult( icc_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]* num_param_lfe + param_idx], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] ) ); /*Q15*/ + } + p_icc_new_fx++; + } + } + + /* ILD */ + num_param_lfe = hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe; + FOR ( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ ) + { + FOR ( param_idx = 0; param_idx < num_param_lfe; param_idx++ ) + { + *p_ild_new_fx = 0; + FOR ( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) + { + p_ild_new_tmp = extract_h(BASOP_util_Pow2( L_mult0( 10885/*log2(10)/10*2^15*/, ild_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx] ), 8, &p_ild_new_e )); + *p_ild_new_fx = add(*p_ild_new_fx,mult(p_ild_new_tmp, parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] )); + } + *p_ild_new_fx = extract_l(L_shr(Mpy_32_16_1(L_add(BASOP_Util_Log2(*p_ild_new_fx),L_add(16<band_grouping[k] , PARAM_MC_MAX_BAND_ABS_COV_DEC) ) + { + hParamMC->max_param_band_abs_cov = ( k++ ); + } + + /*-----------------------------------------------------------------* + * open sub-modules + *-----------------------------------------------------------------*/ + + /* prototype signal computation */ + + IF ( EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) + { + IF ( NE_16(nchan_transport_old , nchan_transport) ) + { + IF ( st_ivas->hLsSetUpConversion != NULL ) + { + ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); + } + + IF ( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */ +#if 1/*To be removed later*/ + free( hParamMC->ls_conv_dmx_matrix ); +#endif + free( hParamMC->ls_conv_dmx_matrix_fx ); +#if 1 + IF ( ( hParamMC->ls_conv_dmx_matrix = (float *) malloc( nchan_out_transport * nchan_out_cov * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } +#endif + IF ( ( hParamMC->ls_conv_dmx_matrix_fx = (Word32 *) malloc( nchan_out_transport * nchan_out_cov * sizeof(Word32) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + FOR ( k = 0; k < nchan_out_transport; k++ ) + { + Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov ); + Scale_sig32( &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov],nchan_out_cov,1 ); + } + } + /* convert ParamMC parameter bands to SFB */ + + st_ivas->hLsSetUpConversion->sfbCnt = hParamMC->num_param_bands_synth; + FOR ( k = 0; k <= hParamMC->num_param_bands_synth; k++ ) + { + st_ivas->hLsSetUpConversion->sfbOffset[k] = PARAM_MC_BAND_TO_MDCT_BAND_RATIO * hParamMC->band_grouping[k]; + } + FOR ( ; k < MAX_SFB + 2; k++ ) + { + st_ivas->hLsSetUpConversion->sfbOffset[k] = 0; + } + } + + IF ( NE_16(nchan_transport_old , nchan_transport) ) + { +#if 1 + free( hParamMC->proto_matrix_int ); + IF ( ( hParamMC->proto_matrix_int = (float *) malloc( nchan_out_transport * nchan_transport * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } +#endif + free( hParamMC->proto_matrix_int_fx ); + IF ( ( hParamMC->proto_matrix_int_fx = (Word32 *) malloc( nchan_out_transport * nchan_transport * sizeof(Word32) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, nchan_transport * nchan_out_transport );/*Q31*/ + } + + IF ( EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_LS_CONV_COV) || EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) + { + matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0, + ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0, + proto_matrix_fx ); + + IF ( EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) + { + proto_mtx_norm_fx = MAX_32; + FOR ( k = 0; k < nchan_transport * nchan_out_cov; k++ ) + { + proto_mtx_norm_fx = L_max(L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); + } + proto_mtx_norm_fx = divide3232(1 , proto_mtx_norm_fx);/*Q15*/ + + /* transfer flattened proto_matrix to 2D in hLsSetupConversion->dmxMtx */ + FOR ( k = 0; k < nchan_transport; k++ ) + { + FOR ( Word16 i = 0; i < nchan_out_cov; i++ ) + { + st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shr(Mpy_32_16_1(proto_matrix_fx[k * nchan_out_cov + i] , (Word16)proto_mtx_norm_fx),1); + st_ivas->hLsSetUpConversion->dmxMtx[k][i] = fixedToFloat( st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i], Q30 ); + } + } + } + } + ELSE + { + Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, nchan_out_transport * nchan_transport ); + } + + IF ( NE_16(nchan_transport_old , nchan_transport) && NE_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) + { + Word16 i; + Word16 len; + + /* close decorrelator */ + ivas_dirac_dec_decorr_close( &hParamMC->h_freq_domain_decorr_ap_params, &hParamMC->h_freq_domain_decorr_ap_state ); + + /* deallocate diffuse prototype info */ + IF ( hParamMC->diff_proto_info ) + { +#if 1/*To be removed later*/ + FOR ( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) + { + free( hParamMC->diff_proto_info->proto_fac[i] ); + hParamMC->diff_proto_info->proto_fac[i] = NULL; + } + + free( hParamMC->diff_proto_info->proto_fac ); + hParamMC->diff_proto_info->proto_fac = NULL; +#endif + FOR ( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) + { + free( hParamMC->diff_proto_info->source_chan_idx[i] ); + hParamMC->diff_proto_info->source_chan_idx[i] = NULL; + + free( hParamMC->diff_proto_info->proto_fac_fx[i] ); + hParamMC->diff_proto_info->proto_fac_fx[i] = NULL; + } + + free( hParamMC->diff_proto_info->source_chan_idx ); + hParamMC->diff_proto_info->source_chan_idx = NULL; + + free( hParamMC->diff_proto_info->proto_fac_fx ); + hParamMC->diff_proto_info->proto_fac_fx = NULL; + + free( hParamMC->diff_proto_info->proto_index_diff ); + hParamMC->diff_proto_info->proto_index_diff = NULL; + + free( hParamMC->diff_proto_info->num_source_chan_diff ); + hParamMC->diff_proto_info->num_source_chan_diff = NULL; + + free( hParamMC->diff_proto_info ); + hParamMC->diff_proto_info = NULL; + } + + hParamMC->num_outputs_diff = nchan_out_cov; + IF ( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + IF ( ( param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* decorrelation */ + hParamMC->h_freq_domain_decorr_ap_params = NULL; + hParamMC->h_freq_domain_decorr_ap_state = NULL; + + Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX]; + ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); + + IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff, + hParamMC->diff_proto_info->num_protos_diff, DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + hParamMC->h_output_synthesis_params.use_onset_filters = 0; + hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr; + /* init decorrelation */ + IF ( GT_16(hParamMC->max_band_decorr , 0) ) + { + + len = hParamMC->diff_proto_info->num_protos_diff * hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr; + + /* init onsetDetectionPower */ + set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx, len ); + set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx, len ); +#if 1/*To be removed later*/ + set_zero( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1, len ); + set_zero( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2, len ); +#endif + } + } + hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->hMetadataPMC->nbands_coded]; + max_param_band_residual = 0; + + FOR ( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- ) + { + IF (LE_16( hParamMC->band_grouping[k] , hParamMC->max_band_decorr) ) + { + max_param_band_residual = k; + assert( hParamMC->band_grouping[k] == hParamMC->max_band_decorr ); + break; + } + } + + IF ( NE_16(nchan_transport_old , nchan_transport) || NE_16(num_param_bands_old , hParamMC->hMetadataPMC->num_parameter_bands) ) + { + DIRAC_OUTPUT_SYNTHESIS_COV_STATE cov_state_old = hParamMC->h_output_synthesis_cov_state; + DIRAC_OUTPUT_SYNTHESIS_PARAMS params_old = hParamMC->h_output_synthesis_params; + + Word32 tmp_buf_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + + set_zero_fx( tmp_buf_fx,MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); + + /* output synthesis */ + IF ( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, + hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ) != IVAS_ERR_OK ) + { + return error; + } + + ivas_param_mc_dec_compute_interpolator_fx( 0, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hParamMC->h_output_synthesis_params.interpolator_fx ); + + ivas_dirac_dec_output_synthesis_cov_init_fx( &( hParamMC->h_output_synthesis_cov_state ), nchan_transport, nchan_out_cov, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual ); + + /* map old to new parameter banding, only for same number of TCs, needs some more thought for changing number of TCs */ + IF ( NE_16(num_param_bands_old , hParamMC->hMetadataPMC->num_parameter_bands) && EQ_16(nchan_transport_old , nchan_transport) ) + { + Word16 new_param_band_idx, source_param_idx; + + FOR ( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ ) + { + FOR ( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) + { + /* Cx */ + v_multc_fixed_16( cov_state_old.cx_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, nchan_transport_old * nchan_transport_old ); + v_add_fx( tmp_buf_fx, hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], nchan_transport_old * nchan_transport_old ); + /* Cy */ + v_multc_fixed_16( cov_state_old.cy_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, nchan_out_cov * nchan_out_cov ); + v_add_fx( tmp_buf_fx, hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], nchan_out_cov * nchan_out_cov ); + /* mixing matrix*/ + v_multc_fixed_16( cov_state_old.mixing_matrix_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, nchan_transport_old * nchan_out_cov ); + v_add_fx( tmp_buf_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], nchan_transport_old * nchan_out_cov ); + } + } + FOR ( new_param_band_idx = 0; new_param_band_idx < max_param_band_residual; new_param_band_idx++ ) + { + FOR ( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) + { + /* residual mixing matrix*/ + v_multc_fixed_16( cov_state_old.mixing_matrix_res_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, nchan_out_cov * nchan_out_cov ); + v_add_fx( tmp_buf_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], nchan_out_cov * nchan_out_cov ); + } + } + } + ivas_dirac_dec_output_synthesis_cov_close( ¶ms_old, &cov_state_old ); + } + + /*-----------------------------------------------------------------* + * memory allocation + *-----------------------------------------------------------------*/ + + IF ( GT_16(hParamMC->max_band_decorr , 0) && NE_16(nchan_transport_old , nchan_transport) ) + { +#if 1 /*To be removed later:floating point memory alocations*/ + free( hParamMC->proto_frame_f ); + IF ( ( hParamMC->proto_frame_f = (float *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + set_zero( hParamMC->proto_frame_f, 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands ); +#endif + free( hParamMC->proto_frame_f_fx ); + IF ( ( hParamMC->proto_frame_f_fx = (Word32 *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof(Word32) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + set_zero_fx( hParamMC->proto_frame_f_fx, 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands ); + } + + + IF ( NE_16(nchan_transport_old , nchan_transport) ) + { + IF ( NE_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) + { + Word16 n_cldfb_slots; +#if 1 /*TODO: To be removed later*/ + IF ( hParamMC->Cldfb_RealBuffer_tc != NULL ) + { + free( hParamMC->Cldfb_RealBuffer_tc ); + hParamMC->Cldfb_RealBuffer_tc = NULL; + } + IF ( hParamMC->Cldfb_ImagBuffer_tc != NULL ) + { + free( hParamMC->Cldfb_ImagBuffer_tc ); + hParamMC->Cldfb_ImagBuffer_tc = NULL; + } +#endif + IF ( hParamMC->Cldfb_RealBuffer_tc_fx != NULL ) + { + free( hParamMC->Cldfb_RealBuffer_tc_fx ); + hParamMC->Cldfb_RealBuffer_tc_fx = NULL; + } + IF ( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL ) + { + free( hParamMC->Cldfb_ImagBuffer_tc_fx ); + hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; + } + + n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS; + IF ( st_ivas->hDecoderConfig->Opt_tsm ) + { + n_cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS; + } +#if 1/*TODO: To be removed later*/ + IF ( ( hParamMC->Cldfb_RealBuffer_tc = (float *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); + } + set_zero( hParamMC->Cldfb_RealBuffer_tc, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); + + IF ( ( hParamMC->Cldfb_ImagBuffer_tc = (float *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); + } + set_zero( hParamMC->Cldfb_ImagBuffer_tc, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); +#endif + IF ( ( hParamMC->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof(Word32) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); + } + set_zero_fx( hParamMC->Cldfb_RealBuffer_tc_fx, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); + + IF ( ( hParamMC->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof(Word32) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); + } + set_zero_fx( hParamMC->Cldfb_ImagBuffer_tc_fx, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); + } + ELSE + { +#if 1/*TODO:To be removed later(floating point memory dealloc)*/ + IF ( hParamMC->Cldfb_RealBuffer_tc != NULL ) + { + free( hParamMC->Cldfb_RealBuffer_tc ); + hParamMC->Cldfb_RealBuffer_tc = NULL; + } + IF ( hParamMC->Cldfb_ImagBuffer_tc != NULL ) + { + free( hParamMC->Cldfb_ImagBuffer_tc ); + hParamMC->Cldfb_ImagBuffer_tc = NULL; + } +#endif + IF ( hParamMC->Cldfb_RealBuffer_tc_fx != NULL ) + { + free( hParamMC->Cldfb_RealBuffer_tc_fx ); + hParamMC->Cldfb_RealBuffer_tc_fx = NULL; + } + IF ( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL ) + { + free( hParamMC->Cldfb_ImagBuffer_tc_fx ); + hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; + } + } + } + return error; +} +#endif // IVAS_FLOAT_FIXED ivas_error ivas_param_mc_dec_reconfig( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ @@ -612,7 +1280,9 @@ ivas_error ivas_param_mc_dec_reconfig( { int16_t k, nchan_transport; PARAM_MC_DEC_HANDLE hParamMC; +#ifndef FIX_901_PARAMMC_DEAD_CODE IVAS_OUTPUT_SETUP hTransportSetup; +#endif int16_t nchan_out_transport; int16_t nchan_out_cov; float proto_matrix[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; @@ -641,8 +1311,9 @@ ivas_error ivas_param_mc_dec_reconfig( output_Fs = st_ivas->hDecoderConfig->output_Fs; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - +#ifndef FIX_901_PARAMMC_DEAD_CODE hTransportSetup = st_ivas->hTransSetup; +#endif mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; @@ -682,6 +1353,7 @@ ivas_error ivas_param_mc_dec_reconfig( hParamMC->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands; +#ifndef FIX_901_PARAMMC_DEAD_CODE /* deallocate the full icc map, gets newly allocated in the metadata open function */ for ( k = 0; k < 2; k++ ) @@ -693,9 +1365,14 @@ ivas_error ivas_param_mc_dec_reconfig( } } +#endif mvs2s( hParamMC->band_grouping, band_grouping_old, hParamMC->hMetadataPMC->num_parameter_bands + 1 ); +#ifndef FIX_901_PARAMMC_DEAD_CODE ivas_param_mc_metadata_open( mc_ls_setup, hTransportSetup.index_lfe[0], ivas_total_brate, hParamMC->hMetadataPMC ); +#else + ivas_param_mc_metadata_open( mc_ls_setup, ivas_total_brate, hParamMC->hMetadataPMC ); +#endif /* Band Grouping */ if ( hParamMC->hMetadataPMC->num_parameter_bands == 20 ) @@ -1179,8 +1856,9 @@ void ivas_param_mc_dec_close( /* parameter decoding */ if ( hParamMC->hMetadataPMC != NULL ) { +#ifndef FIX_901_PARAMMC_DEAD_CODE ivas_param_mc_metadata_close( hParamMC->hMetadataPMC ); - +#endif free( hParamMC->hMetadataPMC ); hParamMC->hMetadataPMC = NULL; } @@ -1296,7 +1974,10 @@ void ivas_param_mc_dec_read_BS( int16_t num_lfe_bands; int16_t num_param_bands; int16_t metadata_bit_pos; - int16_t i, j, k, l; + int16_t i, j, k; +#ifndef FIX_901_PARAMMC_DEAD_CODE + int16_t l; +#endif int16_t icc_map_size; int16_t icc_map_size_wo_lfe; int16_t ild_map_size; @@ -1385,6 +2066,7 @@ void ivas_param_mc_dec_read_BS( num_lfe_bands = 0; } +#ifndef FIX_901_PARAMMC_DEAD_CODE if ( hMetadataPMC->flag_use_adaptive_icc_map == 1 ) { int16_t icc_mapping_index[PARAM_MC_SZ_ICC_MAP]; @@ -1444,6 +2126,7 @@ void ivas_param_mc_dec_read_BS( } } +#endif ivas_param_mc_bs_decode_parameter_values( bit_buffer, &bit_pos, bits_to_copy, &st->BER_detect, hMetadataPMC, &hMetadataPMC->icc_coding, icc_map_size_wo_lfe, icc_map_size, num_lfe_bands, band_step, num_param_bands, hParamMC->icc_q ); if ( !st->BER_detect ) @@ -1741,6 +2424,10 @@ void ivas_param_mc_dec_render( /*CLDFB*/ float Cldfb_RealBuffer[MAX_INTERN_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; float Cldfb_ImagBuffer[MAX_INTERN_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; +#ifdef IVAS_FLOAT_FIXED + Word32 Cldfb_RealBuffer_fx[MAX_INTERN_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word32 Cldfb_ImagBuffer_fx[MAX_INTERN_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; +#endif float Cldfb_RealBuffer_Binaural[BINAURAL_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; float Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; /*Decorrelator*/ @@ -1799,6 +2486,10 @@ void ivas_param_mc_dec_render( { set_zero( &( Cldfb_RealBuffer[ch][slot_idx][nband_synth] ), nbands_to_zero ); set_zero( &( Cldfb_ImagBuffer[ch][slot_idx][nband_synth] ), nbands_to_zero ); +#ifdef IVAS_FLOAT_FIXED + set32_fx(&(Cldfb_RealBuffer_fx[ch][slot_idx][nband_synth]), 0,nbands_to_zero); + set32_fx(&(Cldfb_ImagBuffer_fx[ch][slot_idx][nband_synth]), 0,nbands_to_zero); +#endif } } @@ -1850,14 +2541,27 @@ void ivas_param_mc_dec_render( hParamMC->proto_frame_f, hParamMC->diff_proto_info->num_protos_diff, hParamMC->diff_proto_info->proto_index_diff, - hParamMC->proto_frame_dec_f, + hParamMC->proto_frame_dec_f,//output onset_filter, hParamMC->h_freq_domain_decorr_ap_params, hParamMC->h_freq_domain_decorr_ap_state ); /* copy decorrelated frame directly to output CLDFB buffer, acts also as intermediate */ /* memory for the decorrelated signal */ +#ifdef IVAS_FLOAT_FIXED + f2me_buf(hParamMC->proto_frame_dec_f, hParamMC->proto_frame_dec_f_fx, &hParamMC->exp_proto_frame_dec_f, nchan_out_cov * 2 * hParamMC->num_freq_bands); + ivas_param_mc_dec_copy_diffuse_proto(hParamMC, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, nchan_out_cov, slot_idx); + FOR(int k = 0; k < nchan_out_cov; k++) + { + FOR(int l = 0; l < hParamMC->h_output_synthesis_params.max_band_decorr; l++) + { + Cldfb_RealBuffer[k][slot_idx][l] = me2f(Cldfb_RealBuffer_fx[k][slot_idx][l], hParamMC->exp_proto_frame_dec_f); + Cldfb_ImagBuffer[k][slot_idx][l] = me2f(Cldfb_ImagBuffer_fx[k][slot_idx][l], hParamMC->exp_proto_frame_dec_f); + } + } +#else ivas_param_mc_dec_copy_diffuse_proto( hParamMC, Cldfb_RealBuffer, Cldfb_ImagBuffer, nchan_out_cov, slot_idx ); +#endif } /*-----------------------------------------------------------------* @@ -2147,6 +2851,9 @@ static void ivas_param_mc_dec_init( { set_zero( hParamMC->proto_frame_f, 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands ); set_zero( hParamMC->proto_frame_dec_f, 2 * nchan_cov * hParamMC->num_freq_bands ); +#ifdef IVAS_FLOAT_FIXED + set32_fx(hParamMC->proto_frame_dec_f_fx, 0, 2 * nchan_cov * hParamMC->num_freq_bands); +#endif } return; @@ -2211,7 +2918,35 @@ static void param_mc_protoSignalComputation( * Transfer decorrelated signals back from the decorrelator buffer to * the buffers used in the final synthesis *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void ivas_param_mc_dec_copy_diffuse_proto( + PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */ + Word32 Cldfb_buffer_real_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : CLDFB buffer used in the final synthesis (real part) */ + Word32 Cldfb_buffer_imag_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : CLDFB buffer used in the final synthesis (imaginary part) */ + const Word16 nY, /* i : number of decorrelated channels */ + const Word16 slot_idx /* i : current time slot index */ +) +{ + Word16 k, l; + Word16 num_freq_bands, num_freq_bands_diff; + Word32 *p_proto_diff_fx; + num_freq_bands = hParamMC->num_freq_bands; + num_freq_bands_diff = hParamMC->h_output_synthesis_params.max_band_decorr; + + FOR( k = 0; k < nY; k++ ) + { + p_proto_diff_fx = hParamMC->proto_frame_dec_f_fx + imult1616( shl( k, 1 ), num_freq_bands ); + + FOR( l = 0; l < num_freq_bands_diff; l++ ) + { + Cldfb_buffer_real_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); + Cldfb_buffer_imag_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); + } + } + return; +} +#else static void ivas_param_mc_dec_copy_diffuse_proto( PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */ float Cldfb_buffer_real[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : CLDFB buffer used in the final synthesis (real part) */ @@ -2239,7 +2974,7 @@ static void ivas_param_mc_dec_copy_diffuse_proto( return; } - +#endif /*------------------------------------------------------------------------- * ivas_param_mc_bin2dec() @@ -2372,6 +3107,42 @@ static int16_t ivas_param_mc_range_decoder_LC( * * compute the interpolator used in the final synthesis *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void ivas_param_mc_dec_compute_interpolator_fx( + const UWord16 bAttackPresent, /* i : flag indicating if we have a transient in the current frame */ + const UWord16 attackPos, /* i : position of the transient */ + const UWord16 interp_length, /* i : number of interpolation values to be calculated */ + Word16 *interpolator /* o : interpolator */ +) +{ + Word16 idx; + + IF ( bAttackPresent ) + { + FOR ( idx = 0; idx < 2 * attackPos; idx++ ) + { + interpolator[idx] = 0; + move16(); + } + FOR ( ; idx < interp_length; idx++ ) + { + interpolator[idx] = 32767;/*1.0f Q15*/ + move16(); + } + } + ELSE + { +#ifdef IVAS_FLOAT_FIXED + ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, interp_length, interpolator ); +#else + ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, interp_length, interpolator ); +#endif // IVAS_FLOAT_FIXED + + } + + return; +} +#endif // IVAS_FLOAT_FIXED static void ivas_param_mc_dec_compute_interpolator( const uint16_t bAttackPresent, /* i : flag indicating if we have a transient in the current frame */ @@ -3087,11 +3858,15 @@ static void ivas_param_mc_dequantize_cov( int16_t l; float *Cyp; float ap; +#ifndef FIX_901_PARAMMC_DEAD_CODE int16_t param_frame_idx; +#endif const PARAM_MC_ILD_MAPPING *h_ild_mapping; float Cy_state_int[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS]; +#ifndef FIX_901_PARAMMC_DEAD_CODE param_frame_idx = hParamMC->hMetadataPMC->param_frame_idx; +#endif set_zero( Nrqq, MAX_OUTPUT_CHANNELS ); h_ild_mapping = hParamMC->hMetadataPMC->ild_mapping_conf; @@ -3133,8 +3908,13 @@ static void ivas_param_mc_dequantize_cov( /* replace some estimated ICCs with transmitted values */ for ( k = 0; k < hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe; k++ ) { +#ifndef FIX_901_PARAMMC_DEAD_CODE Cy_state_int[hParamMC->hMetadataPMC->icc_mapping[param_frame_idx][k][0] + nY_int * hParamMC->hMetadataPMC->icc_mapping[param_frame_idx][k][1]] = icc_q[k]; Cy_state_int[hParamMC->hMetadataPMC->icc_mapping[param_frame_idx][k][1] + nY_int * hParamMC->hMetadataPMC->icc_mapping[param_frame_idx][k][0]] = icc_q[k]; +#else + Cy_state_int[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] + nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1]] = icc_q[k]; + Cy_state_int[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] + nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0]] = icc_q[k]; +#endif } if ( param_band_index >= PARAM_MC_MAX_BAND_LFE || !hParamMC->hMetadataPMC->lfe_on ) @@ -3258,7 +4038,9 @@ static void ivas_param_mc_dequantize_cov_fx( Word16 *Cyp_e; Word32 ap_fx; Word16 ap_e; +#ifndef FIX_901_PARAMMC_DEAD_CODE Word16 param_frame_idx; +#endif Word32 L_tmp; Word16 tmp, tmp_e; const PARAM_MC_ILD_MAPPING *h_ild_mapping; @@ -3266,8 +4048,9 @@ static void ivas_param_mc_dequantize_cov_fx( Word16 Cy_state_int_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS]; set16_fx( Cp_buf_e, Cproto_e, MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS ); - +#ifndef FIX_901_PARAMMC_DEAD_CODE param_frame_idx = hParamMC->hMetadataPMC->param_frame_idx; +#endif set32_fx( Nrqq_fx, 0, MAX_OUTPUT_CHANNELS ); set16_fx( Nrqq_e, 0, MAX_OUTPUT_CHANNELS ); h_ild_mapping = hParamMC->hMetadataPMC->ild_mapping_conf; @@ -3355,6 +4138,7 @@ static void ivas_param_mc_dequantize_cov_fx( /* replace some estimated ICCs with transmitted values */ FOR( k = 0; k < hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe; k++ ) { +#ifndef FIX_901_PARAMMC_DEAD_CODE Cy_state_int_fx[hParamMC->hMetadataPMC->icc_mapping[param_frame_idx][k][0] + nY_int * hParamMC->hMetadataPMC->icc_mapping[param_frame_idx][k][1]] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp ); move32(); Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping[param_frame_idx][k][0] + nY_int * hParamMC->hMetadataPMC->icc_mapping[param_frame_idx][k][1]] = tmp; @@ -3363,6 +4147,16 @@ static void ivas_param_mc_dequantize_cov_fx( move32(); Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping[param_frame_idx][k][1] + nY_int * hParamMC->hMetadataPMC->icc_mapping[param_frame_idx][k][0]] = tmp; move16(); +#else + Cy_state_int_fx[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] + nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1]] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp ); + move32(); + Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] + nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1]] = tmp; + move16(); + Cy_state_int_fx[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] + nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0]] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp ); + move32(); + Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] + nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0]] = tmp; + move16(); +#endif } test(); @@ -3545,6 +4339,51 @@ static void ivas_param_mc_dequantize_cov_fx( * set the number of frequency bands to be synthesized *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void param_mc_set_num_synth_bands( + const Word32 output_Fs, /* i : output sampling frequency */ + PARAM_MC_DEC_HANDLE hParamMC /* i/o: Parametric MC handle */ +) +{ + UWord16 max_param_band_synth; + const UWord16 *param_mc_bands_coded; + + SWITCH ( hParamMC->hMetadataPMC->num_parameter_bands ) + { + case 20: + param_mc_bands_coded = (UWord16*)param_mc_bands_coded_20; + BREAK; + case 10: + param_mc_bands_coded = (UWord16*)param_mc_bands_coded_10; + BREAK; + case 14: + default: + param_mc_bands_coded = (UWord16*)param_mc_bands_coded_14; + BREAK; + } + move16(); + SWITCH ( output_Fs ) + { + case 8000: + max_param_band_synth = param_mc_bands_coded[NB]; + break; + case 16000: + max_param_band_synth = param_mc_bands_coded[WB]; + break; + case 32000: + max_param_band_synth = param_mc_bands_coded[SWB]; + break; + case 48000: + default: + max_param_band_synth = param_mc_bands_coded[FB]; + break; + } + move16(); + hParamMC->num_param_bands_synth = s_min( hParamMC->hMetadataPMC->nbands_coded, max_param_band_synth ); + + return; +} +#else static void param_mc_set_num_synth_bands( const int32_t output_Fs, /* i : output sampling frequency */ PARAM_MC_DEC_HANDLE hParamMC /* i/o: Parametric MC handle */ @@ -3588,6 +4427,7 @@ static void param_mc_set_num_synth_bands( return; } +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* @@ -3596,6 +4436,174 @@ static void param_mc_set_num_synth_bands( * calculated the diffuse prototype information *-------------------------------------------------------------------------*/ +#define FLT_ENABLE 0 +#ifdef IVAS_FLOAT_FIXED +static ivas_error param_mc_get_diff_proto_info_fx( + const Word32 *proto_mtx, /* i : protoype matrix for the synthesis */ + const UWord16 nchan_transport, /* i : number of transport channels */ + const UWord16 nchan_out_cov, /* i : number if output channels of the covariance synthesis */ + PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info /* o : generated diffuse prototype info */ +) +{ +#if FLT_ENABLE + float proto_fac[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; +#endif + Word32 proto_fac_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; + uint16_t cur_out_ch; + uint16_t cur_diff_proto; + uint16_t cur_transport_ch; + uint16_t max_num_src_chan; + + /* Initializations */ + max_num_src_chan = 0; +#if FLT_ENABLE + set_zero( proto_fac, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS ); +#endif + set_zero_fx( proto_fac_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS ); + if ( ( p_diff_proto_info->proto_index_diff = (int16_t *) malloc( nchan_out_cov * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + set16_fx( p_diff_proto_info->proto_index_diff, 0, nchan_out_cov ); + + if ( ( p_diff_proto_info->num_source_chan_diff = (int16_t *) malloc( nchan_out_cov * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + set16_fx( p_diff_proto_info->num_source_chan_diff, 0, nchan_out_cov ); + + /* we have at least one prototype, copy the first one */ + p_diff_proto_info->num_protos_diff = 1; +#if FLT_ENABLE + mvr2r_inc( proto_mtx, nchan_out_cov, proto_fac, nchan_out_cov, nchan_transport ); +#endif + mvr2r_inc_fixed( proto_mtx, nchan_out_cov, proto_fac_fx, nchan_out_cov, nchan_transport ); + p_diff_proto_info->proto_index_diff[0] = 0; + + /* search for distinct prototypes */ + for ( cur_out_ch = 1; cur_out_ch < nchan_out_cov; cur_out_ch++ ) + { + uint16_t found = 0; + + for ( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ ) + { +#if FLT_ENABLE + float diff = 0; + float *proto_fac_ptr = proto_fac + cur_diff_proto; + //const float *proto_mtx_ptr = proto_mtx + cur_out_ch; +#endif + Word32 diff_fx = 0; + Word32 *proto_fac_ptr_fx = proto_fac_fx + cur_diff_proto; + const Word32 *proto_mtx_ptr = proto_mtx + cur_out_ch; + for ( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ ) + { +#if FLT_ENABLE + diff += fabsf( *proto_fac_ptr - *proto_mtx_ptr ); + proto_fac_ptr += nchan_out_cov; + proto_mtx_ptr += nchan_out_cov; +#endif + diff_fx += L_abs( *proto_fac_ptr_fx - *proto_mtx_ptr ); + proto_fac_ptr_fx += nchan_out_cov; + proto_mtx_ptr += nchan_out_cov; + } + + /* we already have this prototype, save the index */ +#if FLT_ENABLE + if ( diff < 0.1f ) +#else + if ( LT_64( diff_fx * 10, 2147483648 ) ) +#endif + { + found = 1; + p_diff_proto_info->proto_index_diff[cur_out_ch] = cur_diff_proto; + break; + } + } + + /* new distinct prototype, add it */ + if ( found == 0 ) + { +#if FLT_ENABLE + const float *proto_mtx_ptr = proto_mtx + cur_out_ch; +#else + const Word32 *proto_mtx_ptr = proto_mtx + cur_out_ch; +#endif + int16_t cur_num_src_chan; + + cur_num_src_chan = 0; + for ( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ ) + { + if ( *proto_mtx_ptr > EPSILON ) + { + cur_num_src_chan++; + } + proto_mtx_ptr += nchan_out_cov; + } + +#if FLT_ENABLE + mvr2r_inc( proto_mtx + cur_out_ch, nchan_out_cov, proto_fac + p_diff_proto_info->num_protos_diff, nchan_out_cov, nchan_transport ); +#else + mvr2r_inc_fixed( proto_mtx + cur_out_ch, nchan_out_cov, proto_fac_fx + p_diff_proto_info->num_protos_diff, nchan_out_cov, nchan_transport ); +#endif + p_diff_proto_info->proto_index_diff[cur_out_ch] = p_diff_proto_info->num_protos_diff; + p_diff_proto_info->num_protos_diff++; + max_num_src_chan = s_max( max_num_src_chan, cur_num_src_chan ); + } + } + + /* set up the prototype info struct */ + if ( ( p_diff_proto_info->source_chan_idx = (int16_t **) malloc( p_diff_proto_info->num_protos_diff * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } +#if 1/*To be removed later*/ + if ( ( p_diff_proto_info->proto_fac = (float **) malloc( p_diff_proto_info->num_protos_diff * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } +#endif + if ( ( p_diff_proto_info->proto_fac_fx = (Word32 **) malloc( p_diff_proto_info->num_protos_diff * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + for ( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ ) + { +#if FLT_ENABLE + float *proto_fac_ptr; +#endif + Word32 *proto_fac_ptr; + + if ( ( p_diff_proto_info->source_chan_idx[cur_diff_proto] = (int16_t *) malloc( max_num_src_chan * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } +#if 1/*To be removed later*/ + if ( ( p_diff_proto_info->proto_fac[cur_diff_proto] = (float *) malloc( max_num_src_chan * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } +#endif + if ( ( p_diff_proto_info->proto_fac_fx[cur_diff_proto] = (Word32 *) malloc( max_num_src_chan * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + + proto_fac_ptr = proto_fac_fx + cur_diff_proto; + for ( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ ) + { + if ( *proto_fac_ptr > EPSILON_FX_SMALL ) + { + p_diff_proto_info->source_chan_idx[cur_diff_proto][p_diff_proto_info->num_source_chan_diff[cur_diff_proto]] = cur_transport_ch; + p_diff_proto_info->proto_fac_fx[cur_diff_proto][p_diff_proto_info->num_source_chan_diff[cur_diff_proto]] = *proto_fac_ptr; + p_diff_proto_info->num_source_chan_diff[cur_diff_proto]++; + } + proto_fac_ptr += nchan_out_cov; + } + } + return IVAS_ERR_OK; +} +#endif +#undef FLT_ENABLE static ivas_error param_mc_get_diff_proto_info( const float *proto_mtx, /* i : protoype matrix for the synthesis */ const uint16_t nchan_transport, /* i : number of transport channels */ @@ -3690,6 +4698,12 @@ static ivas_error param_mc_get_diff_proto_info( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } +#ifdef IVAS_FLOAT_FIXED + if ( ( p_diff_proto_info->proto_fac_fx = (Word32 **) malloc( p_diff_proto_info->num_protos_diff * sizeof(Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } +#endif for ( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ ) { float *proto_fac_ptr; @@ -3702,6 +4716,12 @@ static ivas_error param_mc_get_diff_proto_info( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } +#ifdef IVAS_FLOAT_FIXED + if ( ( p_diff_proto_info->proto_fac_fx[cur_diff_proto] = (Word32 *) malloc( max_num_src_chan * sizeof(Word32) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } +#endif // IVAS_FLOAT_FIXED proto_fac_ptr = proto_fac + cur_diff_proto; for ( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ ) diff --git a/lib_dec/ivas_mcmasa_dec.c b/lib_dec/ivas_mcmasa_dec.c index 2562581ae2f487b3faffedc0f69ea0776e6ca34e..a096ee901e60d6e646eb2b954aec306aff29236c 100644 --- a/lib_dec/ivas_mcmasa_dec.c +++ b/lib_dec/ivas_mcmasa_dec.c @@ -45,7 +45,58 @@ * * Reconfigure McMASA decoder *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_mcmasa_dec_reconfig( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + ivas_error error; + Word32 ivas_total_brate; + + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + + /* close the old MASA instance */ + ivas_masa_dec_close_fx( &( st_ivas->hMasa ) ); + + /* get new McMASA settings */ + ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); + ivas_mcmasa_set_separate_channel_mode_fx( &( st_ivas->hOutSetup.separateChannelEnabled ), &( st_ivas->hOutSetup.separateChannelIndex ), ivas_total_brate ); + + /* transport channel settings may affect renderer */ + ivas_renderer_select( st_ivas ); + + /* renderer change may affect internal config */ + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); + ivas_mcmasa_set_separate_channel_mode_fx( &( st_ivas->hIntSetup.separateChannelEnabled ), &( st_ivas->hIntSetup.separateChannelIndex ), ivas_total_brate ); + IF ( ( error = ivas_masa_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); + + IF ( NE_16(st_ivas->renderer_type , RENDERER_DISABLE) && NE_16(st_ivas->renderer_type , RENDERER_MCMASA_MONO_STEREO) ) + { + IF ( st_ivas->hDirAC == NULL ) + { + IF ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE + { + IF ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + return error; +} +#else ivas_error ivas_mcmasa_dec_reconfig( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) @@ -113,3 +164,4 @@ ivas_error ivas_mcmasa_dec_reconfig( return error; } +#endif // IVAS_FLOAT_FIXED diff --git a/lib_dec/ivas_mct_core_dec.c b/lib_dec/ivas_mct_core_dec.c index 2196423cc809041ace526f67e0b1c7d535d66dc1..d6af26d16d63f403090edb24798dcb3a99265a48 100644 --- a/lib_dec/ivas_mct_core_dec.c +++ b/lib_dec/ivas_mct_core_dec.c @@ -54,6 +54,7 @@ * Read mct related side bits and distribute bits per channel * *-----------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_mct_side_bits( MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ CPE_DEC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE decoder structure */ @@ -108,11 +109,7 @@ void ivas_mct_side_bits( { availableBits = 0; -#ifdef IVAS_FLOAT_FIXED - ivas_mct_dec_mct_fx( hMCT, sts, nChannels ); -#else ivas_mct_dec_mct( hMCT, sts, nChannels ); -#endif /*read channel bitrate ratios from bitstream*/ for ( ch = 0; ch < nChannels; ch++ ) @@ -156,8 +153,7 @@ void ivas_mct_side_bits( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void ivas_mct_side_bits_fx( MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ CPE_DEC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE decoder structure */ diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 9c519146cbeb8ff73a5ae6798b187485f429e337..3942a5f9f78d6bdf5a243e373d6ef91a58c1df3c 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -226,7 +226,7 @@ ivas_error ivas_mct_dec( sts[ch]->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( sts[ch]->hTcxDec->tcxltp_last_gain_unmodified_float, Q15 ); sts[ch]->old_fpitch = float_to_fix( sts[ch]->old_fpitch_float, Q16 ); - sts[ch]->hTonalMDCTConc->lastPitchLag = float_to_fix( sts[ch]->hTonalMDCTConc->lastPitchLag_float, Q16 ); + //sts[ch]->hTonalMDCTConc->lastPitchLag = float_to_fix( sts[ch]->hTonalMDCTConc->lastPitchLag_float, Q16 ); // u8bit to 16bit FOR( l = 0; l < IGF_START_MX; l++ ) { @@ -262,7 +262,7 @@ ivas_error ivas_mct_dec( IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) { sts[ch]->lp_gainp = fix_to_float( sts[ch]->Mode2_lp_gainp, Q16 ); - sts[ch]->hTonalMDCTConc->lastPitchLag_float = fix_to_float( sts[ch]->hTonalMDCTConc->lastPitchLag, Q16 ); + //sts[ch]->hTonalMDCTConc->lastPitchLag_float = fix_to_float( sts[ch]->hTonalMDCTConc->lastPitchLag, Q16 ); sts[ch]->hTonalMDCTConc->nFramesLost_float = fix16_to_float( sts[ch]->hTonalMDCTConc->nFramesLost, Q1 ); sts[ch]->hTcxDec->damping_float = fix16_to_float( sts[ch]->hTcxDec->damping, Q14 ); sts[ch]->hTcxDec->stepCompensate_float = me2f_16( sts[ch]->hTcxDec->stepCompensate, sts[ch]->hTcxDec->stepCompensate_e ); @@ -795,141 +795,34 @@ ivas_error ivas_mct_dec( return error; } #else -ivas_error ivas_mct_dec( +ivas_error ivas_mct_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - float *output[], /* o : output synthesis signal */ + Word32 *output_fx[], /* o : output synthesis signal */ const Word16 output_frame, /* i : output frame length per channel */ const Word16 nb_bits_metadata /* i : number of metadata bits */ ) { - Word16 n, nCPE, cpe_id; + Word16 ch, nCPE, cpe_id; MCT_DEC_HANDLE hMCT; CPE_DEC_HANDLE hCPE; - float *x[CPE_CHANNELS][NB_DIV]; Word16 param[MCT_MAX_BLOCKS][CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV]; Word16 param_lpc[MCT_MAX_BLOCKS][CPE_CHANNELS][NPRM_LPC_NEW]; Word16 p_param[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; Word16 nTnsBitsTCX10[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; Word16 fUseTns[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; STnsData tnsData[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; - Decoder_State **sts; - float synth[CPE_CHANNELS][L_FRAME_PLUS]; - int32_t ivas_total_brate; - ivas_error error; - - -#if 1 // Float to fix - - Decoder_State *st; - Word32 *output_fx[16]; - Word16 q_output = 11; - Word32 output_lfe_ch_fx[L_FRAME48k]; - FOR(Word16 i = 0; i < 12; i++) if(output[i]) { - output_fx[i] = malloc( sizeof( Word32 ) * L_FRAME48k ); - floatToFixed_arrL(output[i], output_fx[i], Q11, L_FRAME48k); - } Word16 Aq_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; - Word16 ch, k, l, i, j; + Word32 output_lfe_ch_fx[L_FRAME48k]; + Word16 q_output = 11; + Word16 n, k, l, i, j; Word32 *x_fx[CPE_CHANNELS][NB_DIV]; Word16 x_e[MAX_CICP_CHANNELS][NB_DIV]; Word16 x_len[CPE_CHANNELS][NB_DIV] = { 0 }; - FOR(cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++) - { - hCPE = st_ivas->hCPE[cpe_id]; - sts = hCPE->hCoreCoder; - - FOR( i = 0; i < CPE_CHANNELS; ++i ) - { - FOR( j = 0; j < NB_DIV; ++j ) - { - x_e[i][j] = 20; - } - } - - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - st = hCPE->hCoreCoder[ch]; - IF(st->hTonalMDCTConc) - { - - FOR( i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++) - { - st->hTonalMDCTConc->scaleFactorsBackground_fx[i] = float_to_fix(st->hTonalMDCTConc->scaleFactorsBackground_flt[i], 15); - } - st->hTonalMDCTConc->scf_fadeout = float_to_fix16(st->hTonalMDCTConc->scf_fadeout_flt, 15); - if (hCPE->hCoreCoder[ch]->bfi && st->tonal_mdct_plc_active) - { - FOR( i = 0; i < FDNS_NPTS; i++) - { - f2me_16(st->hTonalMDCTConc->secondLastBlockData.scaleFactors_float[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]); - } - FOR( i = 0; i < 30; i++) - { - float pd = st->hTonalMDCTConc->pTCI_float->phaseDiff_float[i]; - if (pd >= PI2) - pd = fmodf(pd, PI2) - PI2; - st->hTonalMDCTConc->pTCI_float->phaseDiff[i] = (Word16)floatToFixed(pd, Q12); - } - FOR( i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++) - { - float pd = st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float[i]; - pd = fmodf(pd, PI2); - st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted[i] = (Word16)(pd * (1u << Q13)); - } - //st->hTonalMDCTConc->nFramesLost = float_to_fix16( st->hTonalMDCTConc->nFramesLost, Q1 ); - } - f2me(st->hTonalMDCTConc->last_block_nrg_flt, &st->hTonalMDCTConc->last_block_nrg, &st->hTonalMDCTConc->last_block_nrg_exp); - } - st->old_fpitch = float_to_fix(st->old_fpitch_float, 16); - st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16(st->hTcxDec->tcxltp_last_gain_unmodified_float, 15); - - IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) - { - //sts[ch]->gamma = (Word16)floatToFixed( sts[ch]->gamma_float, Q15 ); - sts[ch]->preemph_fac = (Word16)floatToFixed( sts[ch]->preemph_fac_float, Q15 ); - sts[ch]->Mode2_lp_gainp = floatToFixed( sts[ch]->lp_gainp, Q16 ); - sts[ch]->hTcxLtpDec->tcxltp_gain = (Word16)floatToFixed( sts[ch]->hTcxLtpDec->tcxltp_gain_float, Q15 ); - //sts[ch]->inv_gamma = (Word16)floatToFixed( 1 / sts[ch]->gamma_float, Q14 ); - //sts[ch]->hTcxCfg->preemph_fac = (Word16)floatToFixed( sts[ch]->hTcxCfg->preemph_fac_flt, Q15 ); - f2me_16( sts[ch]->last_gain_syn_deemph_float, &sts[ch]->last_gain_syn_deemph, &sts[ch]->last_gain_syn_deemph_e ); - f2me_16( sts[ch]->last_concealed_gain_syn_deemph_float, &sts[ch]->last_concealed_gain_syn_deemph, &sts[ch]->last_concealed_gain_syn_deemph_e ); - f2me_16( sts[ch]->hTcxDec->old_gaintcx_bfi_float, &sts[ch]->hTcxDec->old_gaintcx_bfi, &sts[ch]->hTcxDec->old_gaintcx_bfi_e ); - - sts[ch]->hTonalMDCTConc->lastPitchLag = float_to_fix( sts[ch]->hTonalMDCTConc->lastPitchLag_float, Q16 ); - // u8bit to 16bit - FOR( l = 0; l < IGF_START_MX; l++ ) - { - sts[ch]->hIGFDec->infoTCXNoise_evs[l] = (Word16) sts[ch]->hIGFDec->infoTCXNoise[l]; - } - FOR( l = 0; l < N_LTP_GAIN_MEMS; l++ ) - { - sts[ch]->hTcxDec->ltpGainMemory_fx[l] = float_to_fix16( sts[ch]->hTcxDec->ltpGainMemory[l], Q15 ); - } - sts[ch]->hTcxDec->cummulative_damping_tcx = float_to_fix16( sts[ch]->hTcxDec->cummulative_damping_tcx_float, Q15 ); - } - } - //FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - //{ - // IF( sts[ch]->rate_switching_reset ) - // { - // floatToFixed_arr( sts[ch]->lsp_old, sts[ch]->lsp_old_fx, Q15, M ); - // } - //} - } - - IF(st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->targetEnergyPrev) f2me_buf(st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt); - IF(st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->dmxEnergyPrev) f2me_buf(st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt); - IF(st_ivas->hParamMC && st_ivas->hParamMC->icld_q) floatToFixed_arr16(st_ivas->hParamMC->icld_q, st_ivas->hParamMC->icld_q_fx, 8, st_ivas->hParamMC->hMetadataPMC->num_parameter_bands * st_ivas->hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe); - IF(st_ivas->hParamMC && st_ivas->hParamMC->ls_conv_dmx_matrix) floatToFixed_arr32(st_ivas->hParamMC->ls_conv_dmx_matrix, st_ivas->hParamMC->ls_conv_dmx_matrix_fx, 15, st_ivas->hDecoderConfig->nchan_out * (st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe)); - IF(st_ivas->hLsSetUpConversion) FOR(Word16 chOutIdx = 0; chOutIdx < st_ivas->hDecoderConfig->nchan_out; chOutIdx++) - { - FOR(Word16 chInIdx = 0; chInIdx < st_ivas->nchan_transport; chInIdx++) - { - st_ivas->hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx] = float_to_fix(st_ivas->hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx], 30); /*Q30*/ - } - } -#endif //Float to fix + Decoder_State **sts; + Word16 synth_fx[CPE_CHANNELS][L_FRAME_PLUS]; + int32_t ivas_total_brate; + ivas_error error; push_wmops( "ivas_mct_dec" ); @@ -1006,7 +899,11 @@ ivas_error ivas_mct_dec( FOR ( n = 0; n < CPE_CHANNELS; n++ ) { x_fx[n][0] = output_fx[n + cpe_id * CPE_CHANNELS]; + x_e[n][0] = 20; x_fx[n][1] = output_fx[n + cpe_id * CPE_CHANNELS] + shr( L_FRAME48k, 1 ); + x_e[n][1] = 20; + move16(); + move16(); set32_fx( x_fx[n][0], 0, shr(L_FRAME48k, 1) ); set32_fx( x_fx[n][1], 0, shr(L_FRAME48k, 1) ); @@ -1124,297 +1021,73 @@ ivas_error ivas_mct_dec( } - -#if 1 /*Fixed to float conversions*/ - - FOR(cpe_id = 0; cpe_id < nCPE; cpe_id++) - { - hCPE = st_ivas->hCPE[cpe_id]; - sts = hCPE->hCoreCoder; - - FOR( ch = 0; ch < CPE_CHANNELS; ch++) - { - st = hCPE->hCoreCoder[ch]; - IF( sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) - { - sts[ch]->hTcxDec->damping_float = fix16_to_float( sts[ch]->hTcxDec->damping, Q14 ); - sts[ch]->hTcxDec->gainHelper_float = me2f_16( sts[ch]->hTcxDec->gainHelper, sts[ch]->hTcxDec->gainHelper_e ); - sts[ch]->hTcxDec->stepCompensate_float = me2f_16( sts[ch]->hTcxDec->stepCompensate, sts[ch]->hTcxDec->stepCompensate_e ); - } - IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) - { - sts[ch]->lp_gainp = fix_to_float( sts[ch]->Mode2_lp_gainp, Q16 ); - sts[ch]->hTonalMDCTConc->lastPitchLag_float = fix_to_float( sts[ch]->hTonalMDCTConc->lastPitchLag, Q16 ); - sts[ch]->hTonalMDCTConc->nFramesLost_float = fix16_to_float( sts[ch]->hTonalMDCTConc->nFramesLost, Q1 ); - sts[ch]->hTcxDec->damping_float = fix16_to_float( sts[ch]->hTcxDec->damping, Q14 ); - sts[ch]->hTcxDec->stepCompensate_float = me2f_16( sts[ch]->hTcxDec->stepCompensate, sts[ch]->hTcxDec->stepCompensate_e ); - sts[ch]->hTcxDec->gainHelper_float = me2f_16( sts[ch]->hTcxDec->gainHelper, sts[ch]->hTcxDec->gainHelper_e ); - sts[ch]->last_concealed_gain_syn_deemph_float = me2f_16( sts[ch]->last_concealed_gain_syn_deemph, sts[ch]->last_concealed_gain_syn_deemph_e ); - sts[ch]->last_gain_syn_deemph_float = me2f_16( sts[ch]->last_gain_syn_deemph, sts[ch]->last_gain_syn_deemph_e ); - sts[ch]->hTcxDec->old_gaintcx_bfi_float = me2f_16( sts[ch]->hTcxDec->old_gaintcx_bfi, sts[ch]->hTcxDec->old_gaintcx_bfi_e ); - //sts[ch]->stab_fac = fix16_to_float( sts[ch]->stab_fac_fx, Q15 ); - // 16bit to u8bit - FOR( l = 0; l < IGF_START_MX; l++ ) - { - sts[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t) sts[ch]->hIGFDec->infoTCXNoise_evs[l]; - } - FOR( l = 0; l < N_LTP_GAIN_MEMS; l++ ) - { - sts[ch]->hTcxDec->ltpGainMemory[l] = fix16_to_float( sts[ch]->hTcxDec->ltpGainMemory_fx[l], Q15 ); - } - - IF( !sts[0]->bfi || ( sts[0]->bfi && sts[ch]->core != ACELP_CORE ) ) - { - me2f_buf( sts[ch]->hIGFDec->virtualSpec, sts[ch]->hIGFDec->virtualSpec_e, sts[ch]->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); - } - sts[ch]->hTcxDec->cummulative_damping_tcx_float = fix16_to_float( sts[ch]->hTcxDec->cummulative_damping_tcx, Q15 ); - } - //IF( sts[ch]->rate_switching_reset ) - //{ - // Word16 old_Aq_12_8_e = norm_s( sts[ch]->old_Aq_12_8_fx[0] ); - // fixedToFloat_arr( sts[ch]->old_Aq_12_8_fx, sts[ch]->old_Aq_12_8, ( 15 - old_Aq_12_8_e ), M + 1 ); - //} - IF(st->hTonalMDCTConc != NULL) - { - st->hTonalMDCTConc->scf_fadeout_flt = fixedToFloat(st->hTonalMDCTConc->scf_fadeout, 15); - st->hTonalMDCTConc->last_block_nrg_flt = me2f(st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp); - st->hTonalMDCTConc->lastPitchLag_float = fixedToFloat(st->hTonalMDCTConc->lastPitchLag, Q16); - if (hCPE->hCoreCoder[ch]->bfi && st->tonal_mdct_plc_active) - { - st->hTonalMDCTConc->nFramesLost_float = fix16_to_float(st->hTonalMDCTConc->nFramesLost, Q1); - } - } - } - } - - IF (st_ivas->hCPE[0]->hCoreCoder[0]->igf) - { - IF (!hMCT->currBlockDataCnt) - { - FOR (cpe_id = 0; cpe_id < nCPE; cpe_id++) - { - FOR ( ch = 0; ch < CPE_CHANNELS; ch++) - { - IF(st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->igf) - { - me2f_buf(st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec_e, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec_float, (N_MAX_TCX - IGF_START_MN)); - FOR( l = 0; l < IGF_START_MX; l++) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t)st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise_evs[l]; - } - } - } - } - } - } - - IF(st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->targetEnergyPrev) me2f_buf(st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt); - IF(st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx) me2f_buf(st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt); -#endif /*Fixed to float conversions*/ - -#if 1 - - FOR( i = 0; i < 12; i++) if(output[i]) { - fixedToFloat_arrL(output_fx[i], output[i], Q11, L_FRAME48k); - } -#endif - for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + FOR ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { hCPE = st_ivas->hCPE[cpe_id]; sts = hCPE->hCoreCoder; - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR ( n = 0; n < CPE_CHANNELS; n++ ) { - x[n][0] = output[n + cpe_id * CPE_CHANNELS]; - x[n][1] = output[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); + x_fx[n][0] = output_fx[n + cpe_id * CPE_CHANNELS]; + x_fx[n][1] = output_fx[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); } - - ivas_mdct_core_reconstruct( hCPE, x, synth, fUseTns[cpe_id], 1 ); - - /*----------------------------------------------------------------* - * CoreCoder Post-processing and updates - *----------------------------------------------------------------*/ - Word32 synth_fx[CPE_CHANNELS][L_FRAME48k]; - Word16 Q_synth = 0; - Word16 q = 11; -#ifndef IVAS_CODE_TO_BE_REMOVED - FOR( n = 0; n < 2; n++) + FOR(n = 0; n < CPE_CHANNELS; n++) { - floatToFixed_arrL(synth[n], synth_fx[n], Q11, L_FRAME48k); - IF(hCPE->hCoreCoder[n]->hTcxLtpDec) { - floatToFixed_arrL(hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float, hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32, q, L_FRAME48k); - floatToFixed_arrL(hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float, hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32, q, TCXLTP_MAX_DELAY); - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15); - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain = (Word16)(hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15); - floatToFixed_arrL(hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, Q11, 111); - } - //floatToFixed_arrL(hCPE->hCoreCoder[n]->delay_buf_out, hCPE->hCoreCoder[n]->delay_buf_out32_fx, Q11, HQ_DELTA_MAX * HQ_DELAY_COMP); - - - - /*cldfb struct*/ - - /*------------------fix-to-fix-start---------------------*/ - /*core_switching_post_dec*/ - if (sts[n]->hHQ_core != NULL) - { - sts[n]->hHQ_core->Q_old_postdec = 0; - sts[n]->hHQ_core->Q_old_wtda = 0; - } - - /*------------------fix-to-fix-end-----------------------*/ - - - IF(hCPE->output_mem[0] != NULL) - { - floatToFixed_arrL(hCPE->output_mem[0], hCPE->output_mem_fx[0], Q11, NS2SA(sts[n]->output_Fs, 3125000)); - } - IF(hCPE->output_mem[1] != NULL) - { - floatToFixed_arrL(hCPE->output_mem[1], hCPE->output_mem_fx[1], Q11, NS2SA(sts[n]->output_Fs, 3125000)); - } - - floatToFixed_arrL(output[cpe_id * CPE_CHANNELS + n], output_fx[cpe_id * CPE_CHANNELS + n], 4, L_FRAME48k); - - Word16 tmp = extract_l(L_shr(sts[n]->output_Fs, 13)); - Word16 Fs_kHz = shl(add(tmp, 1), 3); - - Word16 delta = 1; - move16(); - IF(GE_16(output_frame, L_FRAME16k)) + IF(NE_16(hCPE->hCoreCoder[n]->Q_syn, 0)) { - delta = shr(Fs_kHz, 3); + Scale_sig(hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, hCPE->hCoreCoder[n]->Q_syn); } - - if (sts[n]->hBWE_FD != NULL) - { - sts[n]->hBWE_FD->mem_deemph_old_syn_fx = (Word16)floatToFixed(sts[n]->hBWE_FD->mem_deemph_old_syn, 0); - } - IF(sts[n]->hHQ_core != NULL) + if ( sts[n]->hTcxDec && sts[n]->hTcxDec->conCngLevelBackgroundTrace_e < 0 ) { - floatToFixed_arr(sts[n]->hHQ_core->old_out, sts[n]->hHQ_core->old_out_fx, 0, L_FRAME48k); - floatToFixed_arr(sts[n]->hHQ_core->fer_samples, sts[n]->hHQ_core->fer_samples_fx, 0, NS2SA(sts[n]->output_Fs, 3000000)); - //FOR(i = 0; i < SFM_N_WB; ++i) - //{ - // sts[n]->hHQ_core->prev_env_fx[i] = floatToFixed(sts[n]->hHQ_core->prev_env[i], sts[n]->hHQ_core->prev_env_Q[i]); - //} - //floatToFixed_arrL(sts[n]->hHQ_core->prev_normq, sts[n]->hHQ_core->prev_normq_fx, 14, SFM_N_WB); + sts[n]->hTcxDec->conCngLevelBackgroundTrace_e = 0; } - floatToFixed_arr(sts[n]->previoussynth, sts[n]->previoussynth_fx, 0, L_FRAME48k); - //floatToFixed_arr(sts[n]->delay_buf_out, sts[n]->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP); - - if (sts[n]->hTcxDec != NULL) - { - sts[n]->hTcxDec->conceal_eof_gain = (Word16)floatToFixed(sts[n]->hTcxDec->conceal_eof_gain_float, 14); - } - - /*size of synth is choosen as delay comp to start with*/ - // synth //Q0 -> Qsynth - // output_fx //Q ? - // delay_buf_buf //Q0 -> Q_old_postdec - // fer_samples //Q0 -> Q? - /*-------------------cldfb-start-------------------------*/ + } + + Copy_Scale_sig_16_32(hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, M + 1, (28 - norm_s(hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0] - 1))); + Copy_Scale_sig_16_32(hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, M + 1, (28 - norm_s(hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0] - 1))); + ivas_mdct_core_reconstruct_fx( hCPE, x_fx, synth_fx, fUseTns[cpe_id], 1, q_output, 15 ); - floatToFixed_arrL(sts[n]->bpf_noise_buf_float, sts[n]->bpf_noise_buf_32, 11, L_FRAME_16k); - if (sts[n]->cldfbAna != NULL) - { - floatToFixed_arrL(sts[n]->cldfbAna->cldfb_state, sts[n]->cldfbAna->cldfb_state_fx, 10, sts[n]->cldfbAna->cldfb_size); - } - if (sts[n]->cldfbSyn != NULL) + FOR(n = 0; n < CPE_CHANNELS; n++) + { + IF(NE_16(hCPE->hCoreCoder[n]->Q_syn, 0)) { - floatToFixed_arrL(sts[n]->cldfbSyn->cldfb_state, sts[n]->cldfbSyn->cldfb_state_fx, 4, sts[n]->cldfbSyn->p_filter_length); + Scale_sig(hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, negate(hCPE->hCoreCoder[n]->Q_syn)); } - if (sts[n]->cldfbBPF != NULL) + IF(hCPE->hCoreCoder[n]->hBPF) { - floatToFixed_arrL(sts[n]->cldfbBPF->cldfb_state, sts[n]->cldfbBPF->cldfb_state_fx, 11, sts[n]->cldfbBPF->cldfb_size); + hCPE->hCoreCoder[n]->hBPF->pst_mem_deemp_err_fx = extract_l( L_shr( hCPE->hCoreCoder[n]->mem_error, sub(Q16, hCPE->hCoreCoder[n]->Q_syn2 - 1) ) ); + Scale_sig(hCPE->hCoreCoder[n]->hBPF->pst_old_syn_fx, NBPSF_PIT_MAX, hCPE->hCoreCoder[n]->Q_syn2 - 1); } - - /*-------------------cldfb-end---------------------------*/ - - //sts[n]->stab_fac_fx = float_to_fix16(sts[n]->stab_fac, Q15); - //floatToFixed_arr(sts[n]->old_exc, sts[n]->old_exc_fx, sts[n]->Q_exc, L_EXC_MEM_DEC); - IF(sts[n]->hWIDec != NULL) + IF(hCPE->hCoreCoder[n]->hTcxDec) { - floatToFixed_arr(sts[n]->hWIDec->old_exc2, sts[n]->hWIDec->old_exc2_fx, sts[n]->Q_exc, L_EXC_MEM); + Scale_sig(hCPE->hCoreCoder[n]->hTcxDec->synth_history_fx, NS2SA(hCPE->hCoreCoder[n]->output_Fs, PH_ECU_MEM_NS), negate(hCPE->hCoreCoder[n]->Q_syn)); } -#ifndef IVAS_FLOAT_FIXED - if (sts[n]->hMusicPF != NULL) + IF(hCPE->hCoreCoder[n]->hHQ_core) { - floatToFixed_arr(sts[n]->hMusicPF->dct_post_old_exc, sts[n]->hMusicPF->dct_post_old_exc_fx, sts[n]->Q_exc, DCT_L_POST - OFFSET2); - } -#endif - if (sts[n]->hBPF) { - floatToFixed_arr(sts[n]->hBPF->pst_old_syn, sts[n]->hBPF->pst_old_syn_fx, sts[n]->Q_syn2 - 1, NBPSF_PIT_MAX); - sts[n]->hBPF->pst_mem_deemp_err_fx = (Word16)floatToFixed(sts[n]->hBPF->pst_mem_deemp_err, sts[n]->Q_syn2 - 1); - floatToFixed_arr(sts[n]->hBPF->mem_mean_pit, sts[n]->hBPF->mem_mean_pit_fx, Q4, L_TRACK_HIST); - sts[n]->hBPF->pst_lp_ener_fx = float_to_fix16(sts[n]->hBPF->pst_lp_ener, Q8); - sts[n]->hBPF->psf_att_fx = float_to_fix16(sts[n]->hBPF->psf_att, Q15); + Scale_sig(hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, negate(hCPE->hCoreCoder[n]->Q_syn)); } - floatToFixed_arr(sts[n]->prev_synth_buffer, sts[n]->prev_synth_buffer_fx, 0, NS2SA(48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)); - floatToFixed_arr(sts[n]->hTcxDec->synth_history, sts[n]->hTcxDec->synth_history_fx, 0, 2 * output_frame - NS2SA(sts[n]->output_Fs, DELAY_CLDFB_NS) + NS2SA(sts[n]->output_Fs, PH_ECU_MEM_NS)); } + + + /*----------------------------------------------------------------* + * CoreCoder Post-processing and updates + *----------------------------------------------------------------*/ + Word32 synth_fx_32[CPE_CHANNELS][L_FRAME48k]; - - Word16 output_q = OUTPUT_Q; - FOR( n = 0; n < CPE_CHANNELS; n++ ) - { - - IF( hCPE->hStereoDft != NULL ) - { - IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) - { - FOR( Word32 p = 0; p < L_FRAME48k; p++ ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << output_q ) ); - } - FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << output_q ) ); - } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); - } - } - - IF( hCPE->output_mem[n] != NULL ) - { - FOR( k = 0; k < NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ); k++ ) - { - hCPE->output_mem_fx[n][k] = (Word32) ( hCPE->output_mem[n][k] * ( 1 << output_q ) ); - } - } - IF( hCPE->input_mem[n] != NULL ) - { - FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) - { - hCPE->input_mem_LB_fx[n][ind] = (Word32) ( hCPE->input_mem_LB[n][ind] * ( 1 << output_q ) ); - } - } - - FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) - { - hCPE->prev_hb_synth_fx[n][k] = (Word32) ( hCPE->prev_hb_synth[n][k] * ( 1 << output_q ) ); - } - FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) - { - hCPE->prev_synth_fx[n][k] = (Word32) ( hCPE->prev_synth[n][k] * ( 1 << output_q ) ); - } - } -#endif FOR ( n = 0; n < CPE_CHANNELS; n++ ) { - IF ( NE_16(st_ivas->sba_dirac_stereo_flag, 0) && ( NE_16(st_ivas->ivas_format, SBA_ISM_FORMAT) || GE_16(cpe_id, sub(nCPE, 2)) ) ) { + Copy_Scale_sig_16_32(synth_fx[n], synth_fx_32[n], L_FRAME48k, sub(Q11, 0)); Copy_Scale_sig_16_32(hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx, output_frame, Q11); - ivas_post_proc_fx( NULL, hCPE, n, synth_fx[n], NULL, output_frame, 1 ); + ivas_post_proc_fx( NULL, hCPE, n, synth_fx_32[n], NULL, output_frame, 1 ); + Copy_Scale_sig_32_16(synth_fx_32[n], synth_fx[n], L_FRAME48k, sub(0, Q11)); } /* Postprocessing for ACELP/MDCT core switching and synchronization */ - Word16 synth_fx16[L_FRAME48k]; Word16 output_mem_fx[L_FRAME48k]; IF( hCPE->output_mem[1] != NULL ) { @@ -1424,15 +1097,15 @@ ivas_error ivas_mct_dec( { set16_fx( output_mem_fx, 0, NS2SA( sts[n]->output_Fs, 3125000 ) ); } + + Word16 Q_synth = 0; - Copy_Scale_sig_32_16(synth_fx[n], synth_fx16, L_FRAME48k, sub(Q_synth, Q11)); - - IF ( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx16, output_fx[cpe_id * CPE_CHANNELS + n], output_mem_fx, st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, ( st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2 ) ? st_ivas->sba_dirac_stereo_flag : 0, -1, hCPE->last_element_mode, &Q_synth ) ) != IVAS_ERR_OK ) + IF ( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx[n], output_fx[cpe_id * CPE_CHANNELS + n], output_mem_fx, st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, ( st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2 ) ? st_ivas->sba_dirac_stereo_flag : 0, -1, hCPE->last_element_mode, &Q_synth ) ) != IVAS_ERR_OK ) { return error; } - Copy_Scale_sig_16_32(synth_fx16, output_fx[cpe_id * CPE_CHANNELS + n], output_frame, sub(Q11, Q_synth)); + Copy_Scale_sig_16_32(synth_fx[n], output_fx[cpe_id * CPE_CHANNELS + n], output_frame, sub(Q11, Q_synth)); /* Save synthesis for HQ FEC */ Word32 output_fx_[L_FRAME48k]; @@ -1457,288 +1130,9 @@ ivas_error ivas_mct_dec( { synchro_synthesis_fx( ivas_total_brate, hCPE, output_fx + cpe_id * CPE_CHANNELS, output_frame, 0 ); } - -#ifndef IVAS_CODE_TO_BE_REMOVED - FOR(n = 0; n < 2; n++) - { - fixedToFloat_arrL(output_fx[cpe_id * CPE_CHANNELS + n], output[cpe_id * CPE_CHANNELS + n], Q11, L_FRAME48k); - } - FOR( n = 0; n < 2; n++) - { - fixedToFloat_arrL(output_fx[cpe_id * CPE_CHANNELS + n], output[cpe_id * CPE_CHANNELS + n], Q11, L_FRAME48k); - //fixedToFloat_arr(sts[n]->old_exc_fx, sts[n]->old_exc, sts[n]->Q_exc, L_EXC_MEM_DEC); -#ifndef IVAS_FLOAT_FIXED - if (sts[n]->hMusicPF != NULL) - { - fixedToFloat_arr(sts[n]->hMusicPF->dct_post_old_exc_fx, sts[n]->hMusicPF->dct_post_old_exc, sts[n]->Q_exc, DCT_L_POST - OFFSET2); - } -#endif - if (sts[n]->hBPF) { - fixedToFloat_arr(sts[n]->hBPF->pst_old_syn_fx, sts[n]->hBPF->pst_old_syn, sts[n]->Q_syn2 - 1, NBPSF_PIT_MAX); - sts[n]->hBPF->pst_mem_deemp_err = fixedToFloat(sts[n]->hBPF->pst_mem_deemp_err_fx, sts[n]->Q_syn2 - 1); - fixedToFloat_arr(sts[n]->hBPF->mem_mean_pit_fx, sts[n]->hBPF->mem_mean_pit, Q4, L_TRACK_HIST); - sts[n]->hBPF->pst_lp_ener = fixedToFloat(sts[n]->hBPF->pst_lp_ener_fx, Q8); - sts[n]->hBPF->psf_att = fixedToFloat(sts[n]->hBPF->psf_att_fx, Q15); - } - - /*-------------------cldfb-start-------------------------*/ - - /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ - - if (sts[n]->cldfbAna != NULL) - { - fixedToFloat_arrL(sts[n]->cldfbAna->cldfb_state_fx, sts[n]->cldfbAna->cldfb_state, 10, sts[n]->cldfbAna->cldfb_state_length); - } - if (sts[n]->cldfbSyn != NULL) - { - fixedToFloat_arrL(sts[n]->cldfbSyn->cldfb_state_fx, sts[n]->cldfbSyn->cldfb_state, 4, sts[n]->cldfbSyn->p_filter_length); - } - if (sts[n]->cldfbBPF != NULL) - { - fixedToFloat_arrL(sts[n]->cldfbBPF->cldfb_state_fx, sts[n]->cldfbBPF->cldfb_state, 11, sts[n]->cldfbBPF->cldfb_state_length); - } - - /*-------------------cldfb-end---------------------------*/ - - //fixedToFloat_arr(sts[n]->delay_buf_out_fx, sts[n]->delay_buf_out, 0, HQ_DELTA_MAX * HQ_DELAY_COMP); - IF(sts[n]->hHQ_core != NULL) - { - fixedToFloat_arr(sts[n]->hHQ_core->old_out_fx, sts[n]->hHQ_core->old_out, 0, L_FRAME48k); - fixedToFloat_arr(sts[n]->hHQ_core->fer_samples_fx, sts[n]->hHQ_core->fer_samples, 0, NS2SA(sts[n]->output_Fs, 3000000)); - //FOR(i = 0; i < SFM_N_WB; ++i) - //{ - // sts[n]->hHQ_core->prev_env[i] = fixedToFloat(sts[n]->hHQ_core->prev_env_fx[i], sts[n]->hHQ_core->prev_env_Q[i]); - //} - //fixedToFloat_arrL(sts[n]->hHQ_core->prev_normq_fx, sts[n]->hHQ_core->prev_normq, 14, SFM_N_WB); - } - fixedToFloat_arr(sts[n]->previoussynth_fx, sts[n]->previoussynth, 0, L_FRAME48k); - - - - /*------------------reset-code-start---------------------*/ - - /*reset function flags*/ - Word8 reset_wb_tbe_synth = 0; - Word8 reset_swb_tbe = 0; - Word8 reset_swb_tbe_synth = 0; - - if (sts[n]->hBWE_FD != NULL) - { - sts[n]->hBWE_FD->mem_deemph_old_syn = fixedToFloat(sts[n]->hBWE_FD->mem_deemph_old_syn_fx, 0); - } - - IF((NE_16(sts[n]->last_extl, SWB_BWE) && EQ_16(sts[n]->extl, SWB_BWE)) || (NE_16(sts[n]->last_extl, FB_BWE) && EQ_16(sts[n]->extl, FB_BWE)) || - ((EQ_16(sts[n]->last_core, HQ_CORE) || EQ_16(sts[n]->last_extl, SWB_TBE)) && sts[n]->extl < 0 && NE_16(sts[n]->core, HQ_CORE)) || (EQ_16(sts[n]->last_core, ACELP_CORE) && EQ_16(sts[n]->core, ACELP_CORE) && ((NE_16(sts[n]->prev_coder_type, INACTIVE) && EQ_16(sts[n]->coder_type, INACTIVE)) || (NE_16(sts[n]->prev_coder_type, AUDIO) && EQ_16(sts[n]->coder_type, AUDIO))) && sts[n]->bws_cnt > 0)) - { - fixedToFloat_arr(sts[n]->hBWE_FD->L_old_wtda_swb_fx, sts[n]->hBWE_FD->old_wtda_swb, 0, output_frame); - - - sts[n]->hBWE_FD->prev_Energy = fixedToFloat(sts[n]->hBWE_FD->prev_Energy_fx, 0); // setting to zero - sts[n]->hBWE_FD->prev_frica_flag = sts[n]->hBWE_FD->prev_frica_flag; // fixed - sts[n]->hBWE_FD->prev_td_energy = sts[n]->hBWE_FD->prev_td_energy_fx; // setting to zero - sts[n]->hBWE_FD->prev_weight = fixedToFloat(sts[n]->hBWE_FD->prev_weight_fx, 15); // 6554; /*0.2 in Q15*/ - sts[n]->hBWE_FD->prev_fb_ener_adjust = fixedToFloat(sts[n]->prev_fb_ener_adjust_fx, 0); // setting to zero - fixedToFloat_arr(sts[n]->hBWE_FD->mem_imdct_fx, sts[n]->hBWE_FD->mem_imdct, 0, L_FRAME48k); // setting to zero - } - - /* reset WB BWE buffers */ - - IF(NE_16(sts[n]->last_extl, WB_BWE) && EQ_16(sts[n]->extl, WB_BWE) && sts[n]->hBWE_FD != NULL) - { - // set16_fx( sts[n]->hBWE_FD->L_old_wtda_swb_fx, 0, output_frame ); - fixedToFloat_arr(sts[n]->hBWE_FD->L_old_wtda_swb_fx, sts[n]->hBWE_FD->old_wtda_swb, 0, output_frame); - - IF(NE_16(sts[n]->last_extl, SWB_BWE) && NE_16(sts[n]->last_extl, FB_BWE)) - { - sts[n]->hBWE_FD->prev_mode = sts[n]->hBWE_FD->prev_mode; - } - sts[n]->hBWE_FD->prev_Energy_wb = (float)sts[n]->hBWE_FD->prev_Energy_wb_fx; - sts[n]->hBWE_FD->prev_L_swb_norm = sts[n]->hBWE_FD->prev_L_swb_norm; - sts[n]->hBWE_FD->prev_flag = sts[n]->hBWE_FD->prev_flag; - fixedToFloat_arr(sts[n]->hBWE_FD->mem_imdct_fx, sts[n]->hBWE_FD->mem_imdct, 0, L_FRAME48k); // setting to zero - } - - /* reset TBE buffers */ - if (sts[n]->hBWE_TD != NULL) - { - IF(((EQ_16(sts[n]->extl, SWB_TBE) || EQ_16(sts[n]->extl, FB_TBE) || EQ_16(sts[n]->extl, SWB_CNG)) && - (NE_16(sts[n]->L_frame, sts[n]->last_L_frame) || (NE_16(sts[n]->last_extl, SWB_TBE) && NE_16(sts[n]->last_extl, FB_TBE)) || EQ_16(sts[n]->last_core, HQ_CORE))) || - (LT_16(sts[n]->bwidth, sts[n]->last_bwidth) && NE_16(sts[n]->last_extl, SWB_TBE)) || sts[n]->old_ppp_mode || ((EQ_16(sts[n]->prev_coder_type, AUDIO) || EQ_16(sts[n]->prev_coder_type, INACTIVE)) && sts[n]->bws_cnt > 0) || (sts[n]->bws_cnt == 0 && EQ_16(sts[n]->prev_bws_cnt, N_WS2N_FRAMES))) - { - - reset_swb_tbe = 1; - reset_swb_tbe_synth = 1; - - IF(EQ_16(output_frame, L_FRAME16k)) - { - /* reset in case that SWB TBE layer is transmitted, but the output x`x`is 16kHz sampled */ - fixedToFloat_arr(sts[n]->hBWE_TD->mem_resamp_HB_32k_fx, sts[n]->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1); - } - fixedToFloat_arr(sts[n]->hBWE_TD->int_3_over_2_tbemem_dec_fx, sts[n]->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN); - } - ELSE IF(sts[n]->hBWE_TD != NULL && (sts[n]->last_core == TCX_20_CORE || sts[n]->last_core == TCX_10_CORE)) - { - /*------------TBEreset_dec_ivas_fx-start------------------*/ - IF(EQ_16(sts[n]->bwidth, WB)) - { - reset_wb_tbe_synth = 1; - - fixedToFloat_arr(sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD); - } - ELSE IF(EQ_16(sts[n]->bwidth, SWB) || EQ_16(sts[n]->bwidth, FB)) - { - reset_swb_tbe = 1; - reset_swb_tbe_synth = 1; - fixedToFloat_arr(sts[n]->hBWE_TD->int_3_over_2_tbemem_dec_fx, sts[n]->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN); // setting to zero - fixedToFloat_arr(sts[n]->hBWE_TD->mem_resamp_HB_32k_fx, sts[n]->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1); // setting to zero - - IF(EQ_16(sts[n]->bwidth, FB)) - { - IF(sts[n]->hBWE_FD != NULL) - { - sts[n]->hBWE_FD->prev_fb_ener_adjust = fixedToFloat(sts[n]->prev_fb_ener_adjust_fx, 0); - } - fixedToFloat_arr(sts[n]->hBWE_TD->fb_state_lpc_syn_fx, sts[n]->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER); - } - } - /*------------TBEreset_dec_ivas_fx-end--------------------*/ - } - - IF(EQ_16(sts[n]->extl, FB_TBE) && (NE_16(sts[n]->last_extl, FB_TBE) || NE_16(sts[n]->L_frame, sts[n]->last_L_frame))) - { - fixedToFloat_arr(sts[n]->hBWE_TD->fb_state_lpc_syn_fx, sts[n]->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER); - } - - - IF(NE_16(sts[n]->last_extl, WB_TBE) && EQ_16(sts[n]->extl, WB_TBE)) - { - reset_wb_tbe_synth = 1; - fixedToFloat_arr(sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD); // setting to zero - } - - IF(reset_swb_tbe) - { - fixedToFloat_arr(sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD); // setting to zero - } - IF(reset_swb_tbe_synth) - { - fixedToFloat_arrL(sts[n]->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, sts[n]->hBWE_TD->genSHBsynth_Hilbert_Mem, 0, HILBERT_MEM_SIZE); // setting to zero // setting to zero - fixedToFloat_arr(sts[n]->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, sts[n]->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 0, 2 * ALLPASSSECTIONS_STEEP); // setting to zero - } - IF(reset_wb_tbe_synth) - { - fixedToFloat_arr(sts[n]->hBWE_TD->state_lsyn_filt_shb_fx, sts[n]->hBWE_TD->state_lsyn_filt_shb, 0, 2 * ALLPASSSECTIONS_STEEP); // setting to zero - fixedToFloat_arr(sts[n]->hBWE_TD->state_lsyn_filt_dwn_shb_fx, sts[n]->hBWE_TD->state_lsyn_filt_dwn_shb, 0, 2 * ALLPASSSECTIONS_STEEP); // setting to zero - // fixedToFloat(sts[n]->hBWE_TD->state_32and48k_WB_upsample_fx, sts[n]->hBWE_TD->state_32and48k_WB_upsample,0, 2 * ALLPASSSECTIONS_STEEP); buffer not there in float code* - fixedToFloat_arr(sts[n]->hBWE_TD->mem_resamp_HB_fx, sts[n]->hBWE_TD->mem_resamp_HB, 0, INTERP_3_1_MEM_LEN); // setting to zero - } - } - - /*------------------reset-code-end-----------------------*/ - - - for (int p = 0; p < L_FRAME48k; p++) - { - - IF(hCPE->hCoreCoder[n]->hTcxLtpDec) - { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float)hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / (1u << q); - if (p < TCXLTP_MAX_DELAY) - { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float)hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / (1u << q); - } - } - } - if (hCPE->hCoreCoder[n]->hTcxDec) - { - for (k = 0; k < 111; k++) - { - hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float)hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / (1u << q); - } - } - IF(hCPE->hCoreCoder[n]->hTcxLtpDec) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; - IF(hCPE->hCoreCoder[n]->hTcxLtpDec) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float)hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; - - if ((sts[n]->codec_mode == MODE1 && sts[n]->hTcxDec != NULL) && ((sts[n]->core == ACELP_CORE && !(sts[n]->bfi == 1 && sts[n]->con_tcx == 1)) || sts[n]->core == HQ_CORE)) - { - fixedToFloat_arr(sts[n]->hTcxDec->synth_history_fx, sts[n]->hTcxDec->synth_history, 0, output_frame); - } - - - fixedToFloat_arr(sts[n]->old_synth_sw_fx, sts[n]->old_synth_sw, -2, 429); - FOR(Word16 ind = 0; ind < 16; ind++) { - sts[n]->mem_AR[ind] = sts[n]->mem_AR_fx[ind] / 2.56f; - } - sts[n]->prev_tilt_code_dec = fixedToFloat(sts[n]->prev_tilt_code_dec_fx, Q15); - - floatToFixed_arr(sts[n]->tilt_code_dec, sts[n]->tilt_code_dec_fx, Q15, 5); - floatToFixed_arr(sts[n]->old_synth_sw, sts[n]->old_synth_sw_fx, -2, 429); - sts[n]->prev_tilt_code_dec_fx = (Word16)floatToFixed(sts[n]->prev_tilt_code_dec, Q15); - FOR(Word16 ind = 0; ind < 16; ind++) { - sts[n]->mem_AR_fx[ind] = (Word16)(sts[n]->mem_AR[ind] * 2.56f); - } - fixedToFloat_arr(sts[n]->old_synth_sw_fx, sts[n]->old_synth_sw, 0, 429); - } - - IF( hCPE->hStereoDft != NULL ) - { - IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) - { - FOR( Word32 p = 0; p < L_FRAME48k; p++ ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << output_q ); - } - FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); - } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; - } - } - FOR( n = 0; n < CPE_CHANNELS; n++ ) - { - IF( hCPE->output_mem[n] != NULL ) - { - FOR( k = 0; k < NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ); k++ ) - { - hCPE->output_mem[n][k] = (float) hCPE->output_mem_fx[n][k] / ( 1u << 11 ); - } - } - IF( hCPE->hCoreCoder[n] != NULL ) - { - FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) - { - hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << output_q ); - } - //FOR( k = 0; k < HQ_DELTA_MAX * HQ_DELAY_COMP; k++ ) - //{ - // hCPE->hCoreCoder[n]->delay_buf_out[k] = (float) hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] / ( 1 << output_q ); - //} - } - IF( hCPE->input_mem[n] != NULL ) - { - FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) - { - hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << output_q ) ); - } - } - FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) - { - hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << output_q ); - } - FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) - { - hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << output_q ); - } - } -#endif } /* move channels after LFE to correct output for multi-channel MCT */ - FOR(Word16 ind = 0; ind < 12; ind++) if(output[ind]) { - floatToFixed_arrL(output[ind], output_fx[ind], Q11, 960); - } IF ( EQ_16(st_ivas->ivas_format, MC_FORMAT) && ( EQ_16(st_ivas->mc_mode, MC_MODE_MCT) || EQ_16(st_ivas->mc_mode, MC_MODE_PARAMUPMIX) ) ) { Word32 tmp[L_FRAME48k]; @@ -1756,12 +1150,9 @@ ivas_error ivas_mct_dec( mvl2l( output_lfe_ch_fx, output_fx[LFE_CHANNEL], output_frame ); } - FOR(i = 0; i < 12; i++) if(output[i]) { - fixedToFloat_arrL(output_fx[i], output[i], Q11, L_FRAME48k); - free(output_fx[i]); - } pop_wmops(); return error; + } #endif @@ -1771,6 +1162,125 @@ ivas_error ivas_mct_dec( * * Create, allocate and initialize IVAS decoder MCT handle *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error create_mct_dec_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + MCT_DEC_HANDLE hMCT; + Word16 n; + Word32 cp_bitrate; + Word16 max_blocks; + Word16 cpe_id; + + /*--------------------------------------------------------- --------* + * Allocate MCT handle + *-----------------------------------------------------------------*/ + + IF( ( hMCT = (MCT_DEC_HANDLE) malloc( sizeof( MCT_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CPE\n" ) ); + } + + /*-----------------------------------------------------------------* + * Allocate MCT BlockData handles + *-----------------------------------------------------------------*/ + + /* Determine active channels */ + IF( ( EQ_16(st_ivas->ivas_format , MC_FORMAT) && EQ_16(st_ivas->mc_mode , MC_MODE_PARAMMC) ) || EQ_16(st_ivas->ivas_format , SBA_FORMAT) || EQ_16(st_ivas->ivas_format , SBA_ISM_FORMAT) ) + { + hMCT->nchan_out_woLFE = st_ivas->nchan_transport; + IF( EQ_16(st_ivas->ism_mode , ISM_SBA_MODE_DISC) ) + { + hMCT->nchan_out_woLFE = add(hMCT->nchan_out_woLFE,st_ivas->nchan_ism); + } + } + ELSE IF( EQ_16(st_ivas->mc_mode , MC_MODE_MCT) ) + { + hMCT->nchan_out_woLFE = sub(st_ivas->nchan_transport , st_ivas->hTransSetup.num_lfe); + } + ELSE IF( EQ_16(st_ivas->ivas_format , MC_FORMAT) && EQ_16(st_ivas->mc_mode , MC_MODE_PARAMUPMIX) ) + { + hMCT->nchan_out_woLFE = sub(st_ivas->nchan_transport , st_ivas->hTransSetup.num_lfe); + } + ELSE + { + assert( !"IVAS format currently not supported for MCT" ); + } + + cp_bitrate = L_shl( Mult_32_16( st_ivas->hDecoderConfig->ivas_total_brate, div_s( 1, hMCT->nchan_out_woLFE ) ), 1 ); + + IF( EQ_16(st_ivas->ism_mode , ISM_SBA_MODE_DISC) ) + { + cp_bitrate = L_shl( Mult_32_16( st_ivas->hDecoderConfig->ivas_total_brate, div_s( 1, st_ivas->nchan_transport ) ), 1 ); + } + + /* indicate LFE for appropriate core-coder channel */ + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + } + } + + /* in case we have an uneven number of transport channels, indicate last channel ID as inactive */ + IF( hMCT->nchan_out_woLFE % 2 ) + { + st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + } + + /*Initialize MCT block data */ + max_blocks = shr(hMCT->nchan_out_woLFE , 1); + + FOR( n = 0; n < max_blocks; n++ ) + { + IF( ( hMCT->hBlockData[n] = (MCT_DEC_BLOCK_DATA_HANDLE) malloc( sizeof( MCT_DEC_BLOCK_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT block data structure\n" ) ); + } + + /*Initialize all parameters to zero*/ + hMCT->hBlockData[n]->ch1 = 0; + hMCT->hBlockData[n]->ch2 = 0; + + /*-----------------------------------------------------------------* + * MDCT stereo initialization + *-----------------------------------------------------------------*/ + + IF( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); + } + + initMdctStereoDecData_fx( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, SWB ); + hMCT->hBlockData[n]->hStereoMdct->use_itd = 0; + hMCT->hBlockData[n]->hStereoMdct->reverse_dmx = 0; + hMCT->hBlockData[n]->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; + } + FOR( ; n < MCT_MAX_BLOCKS; n++ ) + { + hMCT->hBlockData[n] = NULL; + } + + /*-----------------------------------------------------------------* + * Initializations + *-----------------------------------------------------------------*/ + + hMCT->currBlockDataCnt = 0; + + /*Initialize bits required to signal channel-pair index*/ + // hMCT->bitsChannelPairIndex = max( 1, (Word16) ( floorf( ( logf( (float) hMCT->nchan_out_woLFE * ( hMCT->nchan_out_woLFE - 1 ) / 2 - 1 ) * INV_LOG_2 ) ) + 1 ) ); + hMCT->bitsChannelPairIndex = s_max( 1, floor_log_2( (Word32) hMCT->nchan_out_woLFE * ( (Word32) hMCT->nchan_out_woLFE - 1 ) / 2 - 1 )+ 1 ); + + set16_fx( hMCT->chBitRatios, 0, MCT_MAX_CHANNELS ); + set16_fx( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS ); + + st_ivas->hMCT = hMCT; + + return IVAS_ERR_OK; +} +#endif // IVAS_FLOAT_FIXED ivas_error create_mct_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ @@ -1862,11 +1372,16 @@ ivas_error create_mct_dec( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } +#ifndef IVAS_FLOAT_FIXED initMdctStereoDecData( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, SWB ); +#else + initMdctStereoDecData_fx( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, SWB ); +#endif hMCT->hBlockData[n]->hStereoMdct->use_itd = 0; hMCT->hBlockData[n]->hStereoMdct->reverse_dmx = 0; +#ifndef IVAS_FLOAT_FIXED hMCT->hBlockData[n]->hStereoMdct->smooth_ratio = 1.f; -#ifdef IVAS_FLOAT_FIXED +#else hMCT->hBlockData[n]->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; #endif } @@ -2023,9 +1538,7 @@ ivas_error mct_dec_reconfigure_fx( } } -#ifdef IVAS_FLOAT_FIXED - initMdctStereoDecData( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, st_ivas->hCPE[0]->hCoreCoder[0]->bwidth ); -#endif + initMdctStereoDecData_fx( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, st_ivas->hCPE[0]->hCoreCoder[0]->bwidth ); hMCT->hBlockData[n]->hStereoMdct->use_itd = 0; move16(); @@ -2059,7 +1572,7 @@ ivas_error mct_dec_reconfigure_fx( /*Initialize bits required to signal channel-pair index*/ Word32 log_tmp; - L_tmp = L_sub( L_shr( L_mult0( hMCT->nchan_out_woLFE, L_sub(hMCT->nchan_out_woLFE, 1) ), 1 ), 1 ); + L_tmp = L_sub( L_shr( L_mult0( hMCT->nchan_out_woLFE, sub(hMCT->nchan_out_woLFE, 1) ), 1 ), 1 ); tmp_exp = norm_l(L_tmp); L_tmp = L_shl(L_tmp, tmp_exp); log_tmp = BASOP_Util_Log2(L_tmp); // ( 31 - tmp_exp ) @@ -2076,8 +1589,7 @@ ivas_error mct_dec_reconfigure_fx( return IVAS_ERR_OK; } -#endif - +#else ivas_error mct_dec_reconfigure( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const uint16_t b_nchan_change /* i : flag indicating different channel count */ @@ -2226,6 +1738,7 @@ ivas_error mct_dec_reconfigure( return IVAS_ERR_OK; } +#endif /*------------------------------------------------------------------------- @@ -2475,14 +1988,6 @@ static ivas_error ivas_mc_dec_reconfig( { st_ivas->hIsmRendererData->interpolator_fx[ind1] = (Word16) L_min( 32767, floatToFixed( st_ivas->hIsmRendererData->interpolator_fx[ind1], 15 ) ); } - FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->gains[ind1][ind2] * ( 1 << 30 ) ); - st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->prev_gains[ind1][ind2] * ( 1 << 30 ) ); - } - } } FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { @@ -2578,14 +2083,23 @@ static ivas_error ivas_mc_dec_reconfig( } } } + Word16 n_tc; + if (st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) + n_tc = st_ivas->nchan_ism; + else + n_tc = st_ivas->hTcBuffer->nchan_transport_internal; + for (int ch = 0; ch < n_tc; ch++) + { + floatToFixed_arrL(st_ivas->hTcBuffer->tc[ch], st_ivas->hTcBuffer->tc_fx[ch], Q11, L_FRAME48k); + } #endif if ( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, last_mc_mode, ISM_MODE_NONE, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { return error; } #if 1 /*Fixed to float */ - IF ( hTcBuffer->tc_buffer ) - fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); + if ( hTcBuffer->tc_buffer ) + fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); IF( hSpar ) { FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) @@ -2629,22 +2143,6 @@ static ivas_error ivas_mc_dec_reconfig( } } } - - if ( st_ivas->hIsmRendererData ) - { - FOR( Word16 ind1 = 0; ind1 < st_ivas->hIsmRendererData->interpolator_len; ind1++ ) - { - st_ivas->hIsmRendererData->interpolator[ind1] = (float) ( st_ivas->hIsmRendererData->interpolator_fx[ind1] ) / (float) ( 1 << 15 ); - } - FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->gains_fx[ind1][ind2] ) / ( 1 << 30 ); - st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] ) / ( 1 << 30 ); - } - } - } FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { if ( st_ivas->hIsmMetaData[ind1] ) @@ -2812,10 +2310,147 @@ static ivas_error ivas_mc_dec_reconfig( } else { +#ifdef IVAS_FLOAT_FIXED +#if 1 /*TODO: To be removed later (i/o: Float to fixed conversions) */ + PARAM_MC_DEC_HANDLE hParamMC; + hParamMC = st_ivas->hParamMC; + Word16 nchan_out_transport, nchan_out_cov; + MC_LS_SETUP mc_ls_setup; + Word16 nchan_transport; + mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); + st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); + nchan_transport = st_ivas->nchan_transport; + nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; + Word16 cx_e=0, cy_e=0, mmo_e=0, mmro_e=0; + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { + nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + } + else + { + nchan_out_cov = nchan_out_transport; + } + if ( st_ivas->hLsSetUpConversion ) + { + for ( Word16 k = 0; k < nchan_out_transport; k++ ) + { + floatToFixed_arr32( st_ivas->hLsSetUpConversion->dmxMtx[k], st_ivas->hLsSetUpConversion->dmxMtx_fx[k], Q30, nchan_out_cov ); + } + } + if ( st_ivas->hParamMC ) + { + floatToFixed_arr( hParamMC->icc_q, hParamMC->icc_q_fx, Q15, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); + floatToFixed_arr( hParamMC->icld_q, hParamMC->icld_q_fx, Q8, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); + if ( hParamMC->ls_conv_dmx_matrix ) + floatToFixed_arr32( hParamMC->ls_conv_dmx_matrix, hParamMC->ls_conv_dmx_matrix_fx, Q31, nchan_out_cov * nchan_out_transport ); + Word32 max_cx_old_fx, max_cy_old_fx, max_mix_matrix_old_fx, max_mix_matrix_res_old_fx; + float max_cx_old = hParamMC->h_output_synthesis_cov_state.cx_old[0][0], max_cy_old = hParamMC->h_output_synthesis_cov_state.cy_old[0][0], max_mix_matrix_old = hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[0][0], max_mix_matrix_res_old = hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[0][0]; + for ( int i = 0; i < hParamMC->hMetadataPMC->num_parameter_bands; i++ ) + { + if ( hParamMC->h_output_synthesis_cov_state.cx_old[i] ) + { + for ( int j = 0; j < nchan_transport_old * nchan_transport_old; j++ ) + max_cx_old = max( max_cx_old, hParamMC->h_output_synthesis_cov_state.cx_old[i][j] ); + for ( int j = 0; j < nchan_out_cov * nchan_out_cov; j++ ) + max_cy_old = max( max_cy_old, hParamMC->h_output_synthesis_cov_state.cy_old[i][j] ); + for ( int j = 0; j < nchan_transport_old * nchan_out_cov; j++ ) + max_mix_matrix_old = max( max_mix_matrix_old, hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[i][j] ); + } + } + for ( int i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) + { + if ( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i] ) + { + for ( int j = 0; j < nchan_out_cov * nchan_out_cov; j++ ) + max_mix_matrix_res_old = max( max_mix_matrix_res_old, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i][j] ); + } + } + f2me( max_cx_old, &max_cx_old_fx, &cx_e ); + f2me( max_cy_old, &max_cy_old_fx, &cy_e ); + f2me( max_mix_matrix_old, &max_mix_matrix_old_fx, &mmo_e ); + f2me( max_mix_matrix_res_old, &max_mix_matrix_res_old_fx, &mmro_e ); + if ( mmo_e < 0 ) + mmo_e = 0; + if ( mmro_e < 0 ) + mmro_e = 0; + for ( int i = 0; i < hParamMC->hMetadataPMC->num_parameter_bands; i++ ) + { + if ( hParamMC->h_output_synthesis_cov_state.cx_old[i] ) + { + + floatToFixed_arrL( hParamMC->h_output_synthesis_cov_state.cx_old[i], hParamMC->h_output_synthesis_cov_state.cx_old_fx[i], 31 - cx_e, nchan_transport_old * nchan_transport_old ); + floatToFixed_arrL( hParamMC->h_output_synthesis_cov_state.cy_old[i], hParamMC->h_output_synthesis_cov_state.cy_old_fx[i], 31 - cy_e, nchan_out_cov * nchan_out_cov ); + floatToFixed_arrL( hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[i], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[i], 31 - mmo_e, nchan_transport_old * nchan_out_cov ); + } + } + for ( int i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) + { + if ( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i] ) + { + floatToFixed_arrL( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[i], 31 - mmro_e, nchan_out_cov * nchan_out_cov ); + } + } + floatToFixed_arr16( hParamMC->h_output_synthesis_params.interpolator, hParamMC->h_output_synthesis_params.interpolator_fx, 15, DEFAULT_JBM_CLDFB_TIMESLOTS ); + floatToFixed_arrL( hParamMC->proto_matrix_int, hParamMC->proto_matrix_int_fx, Q31, nchan_out_transport * nchan_transport ); + FOR( Word16 i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) + { + if ( hParamMC->diff_proto_info ) + floatToFixed_arrL( hParamMC->diff_proto_info->proto_fac[i], hParamMC->diff_proto_info->proto_fac_fx[i], 31, hParamMC->diff_proto_info->num_source_chan_diff[i] ); + } + } +#endif + if ( ( error = ivas_param_mc_dec_reconfig_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#if 1 + if ( hParamMC ) + { + fixedToFloat_arr( hParamMC->icc_q_fx, hParamMC->icc_q, Q15, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); + fixedToFloat_arr( hParamMC->icld_q_fx, hParamMC->icld_q, Q8, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); + fixedToFloat_arr( hParamMC->h_output_synthesis_params.interpolator_fx, hParamMC->h_output_synthesis_params.interpolator, 15, DEFAULT_JBM_CLDFB_TIMESLOTS ); + for ( int i = 0; i < hParamMC->hMetadataPMC->num_parameter_bands; i++ ) + { + if ( hParamMC->h_output_synthesis_cov_state.cx_old[i] ) + { + fixedToFloat_arrL( hParamMC->h_output_synthesis_cov_state.cx_old_fx[i], hParamMC->h_output_synthesis_cov_state.cx_old[i], 31 - cx_e, nchan_transport_old * nchan_transport_old ); + fixedToFloat_arrL( hParamMC->h_output_synthesis_cov_state.cy_old_fx[i], hParamMC->h_output_synthesis_cov_state.cy_old[i], 31 - cy_e, nchan_out_cov * nchan_out_cov ); + fixedToFloat_arrL( hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[i], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[i], 31 - mmo_e, nchan_transport_old * nchan_out_cov ); + } + } + for ( int i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) + { + if ( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i] ) + { + fixedToFloat_arrL( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[i], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[i], 31 - mmro_e, nchan_out_cov * nchan_out_cov ); + } + } + fixedToFloat_arrL( hParamMC->h_output_synthesis_params.proto_matrix_fx, hParamMC->h_output_synthesis_params.proto_matrix, 31, nchan_transport * nchan_out_cov ); + FOR( Word16 i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) + { + fixedToFloat_arrL( hParamMC->diff_proto_info->proto_fac_fx[i], hParamMC->diff_proto_info->proto_fac[i], 31, hParamMC->diff_proto_info->num_source_chan_diff[i] ); + } + if ( st_ivas->hLsSetUpConversion ) + { + for (Word16 k = 0; k < nchan_transport; k++ ) + { + for ( int16_t i = 0; i < nchan_out_cov; i++ ) + { + st_ivas->hLsSetUpConversion->dmxMtx[k][i] = fixedToFloat( st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i], Q30 ); + } + } + } + fixedToFloat_arrL( hParamMC->proto_matrix_int_fx, hParamMC->proto_matrix_int, Q31, nchan_out_transport * nchan_transport ); + if ( hParamMC->ls_conv_dmx_matrix ) + fixedToFloat_arrL( hParamMC->ls_conv_dmx_matrix_fx, hParamMC->ls_conv_dmx_matrix, Q31, nchan_out_transport * nchan_out_cov ); + } +#endif +#else if ( ( error = ivas_param_mc_dec_reconfig( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#endif // IVAS_FLOAT_FIXED } /* De-allocate McMasa-related handles */ @@ -2952,7 +2587,18 @@ static ivas_error ivas_mc_dec_reconfig( } st->igf = 0; +#ifdef IVAS_FLOAT_FIXED + init_igf_dec( st->hIGFDec ); +#if 1/*TODO: To be removed later(floating point initialization)*/ + st->hIGFDec->virtualSpec_float = &st->hIGFDec->virtualSpecBuf[0]; + FOR(Word16 l = 0; l < IGF_START_MX; l++ ) + st->hIGFDec->infoTCXNoiseBuf[l] = (uint8_t) st->hIGFDec->infoTCXNoise_evs[l]; + set_f( st->hIGFDec->igfData.pSpecFlatBuf, 0, IGF_START_MX ); + st->hIGFDec->igfData.pSpecFlat_float = &st->hIGFDec->igfData.pSpecFlatBuf[0]; +#endif +#else init_igf_dec_flt( st->hIGFDec ); +#endif // IVAS_FLOAT_FIXED } if ( st->hHQ_core == NULL ) @@ -2963,7 +2609,10 @@ static ivas_error ivas_mc_dec_reconfig( } /* HQ core initialization */ +#if 1 HQ_core_dec_init_flt( st->hHQ_core ); +#endif + HQ_core_dec_init(st->hHQ_core); } /* check if we have a doubly used hTxcCfg, if so, allocate a distint one for the old MCT LFE channel */ @@ -3005,10 +2654,17 @@ static ivas_error ivas_mc_dec_reconfig( new_brate_CPE = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; } +#ifdef IVAS_FLOAT_FIXED + IF ( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, new_brate_SCE, new_brate_CPE ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, new_brate_SCE, new_brate_CPE ) ) != IVAS_ERR_OK ) { return error; } +#endif if ( last_mc_mode == MC_MODE_MCT && st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->nchan_transport > CPE_CHANNELS ) { @@ -3030,7 +2686,6 @@ static ivas_error ivas_mc_dec_reconfig( { fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_in, st->hTcxLtpDec->tcxltp_mem_in_float, 0, TCXLTP_MAX_DELAY ); fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_out, st->hTcxLtpDec->tcxltp_mem_out_float, 0, L_FRAME48k ); - st->hTcxLtpDec->tcxltp_gain_post_prev_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain_post_prev, 0 ); } } #else @@ -3203,7 +2858,7 @@ static ivas_error ivas_mc_dec_reconfig( } #if 1 // Cleanup changes for ivas_td_binaural_open: fixed to float st_ivas->hBinRendererTd->Gain = 1.0f; /*1.0f Q15*/ - fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Pos_fx, st_ivas->hBinRendererTd->Listener_p->Pos, Q25, 3 ); + fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Pos_fx, st_ivas->hBinRendererTd->Listener_p->Pos, st_ivas->hBinRendererTd->Listener_p->Pos_q, 3 ); fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Vel_fx, st_ivas->hBinRendererTd->Listener_p->Vel, Q30, 3 ); fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Front_fx, st_ivas->hBinRendererTd->Listener_p->Front, Q30, 3 ); fixedToFloat_arrL( st_ivas->hBinRendererTd->Listener_p->Up_fx, st_ivas->hBinRendererTd->Listener_p->Up, Q30, 3 ); diff --git a/lib_dec/ivas_mct_dec_mct.c b/lib_dec/ivas_mct_dec_mct.c index 6b503420af9927d689f3d062ba62a7ea55f21395..6d071cedb0910750aca5e72602b8a66db3959bd7 100644 --- a/lib_dec/ivas_mct_dec_mct.c +++ b/lib_dec/ivas_mct_dec_mct.c @@ -43,6 +43,7 @@ #endif +#ifndef IVAS_FLOAT_FIXED /*----------------------------------------------------------* * indexToChannelPair() * @@ -227,7 +228,8 @@ void apply_MCT_dec( return; } -#ifndef IVAS_FLOAT_FIXED + + /*----------------------------------------------------------* * mctStereoIGF_dec() * diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 0101c5e49d6ace93964b49714bbf22a0c09a22ea..2560aab8340624449cedf2498bfd05e2e95b1d7f 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -160,7 +160,7 @@ static void dec_prm_tcx_sidebits_fx( /* Init LTP data */ st->hTcxDec->tcx_hm_LtpPitchLag = -1; - st->hTcxLtpDec->tcxltp_gain_float = 0.0f; + st->hTcxLtpDec->tcxltp_gain = 0; /*--------------------------------------------------------------------------------* * Header @@ -228,14 +228,14 @@ static void dec_prm_tcx_sidebits_fx( * TCX20/TCX10 parameters *--------------------------------------------------------------------------------*/ - getTCXparam_ivas( st, st0, hm_cfg, param, 0, 0, ( ( ch > 0 ) && ( tnsSize ) && ( tnsSize[0] + tnsSize[1] > 0 ) ? tnsSize : NULL ), p_param, nTnsBitsTCX10, 0 ); + getTCXparam( st, st0, hm_cfg, param, 0, 0, ( ( ch > 0 ) && ( tnsSize ) && ( tnsSize[0] + tnsSize[1] > 0 ) ? tnsSize : NULL ), p_param, nTnsBitsTCX10, 0 ); st->side_bits_frame_channel = st0->next_bit_pos - start_bit_pos; return; } #endif - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) static void dec_prm_tcx_sidebits( int16_t param[], /* o : decoded parameters */ Decoder_State *st, /* i/o: decoder memory state */ @@ -334,7 +334,7 @@ static void dec_prm_tcx_sidebits( return; } - +#endif /*-----------------------------------------------------------------* * Function dec_prm_tcx_spec() @@ -412,7 +412,7 @@ static void dec_prm_tcx_spec_fx( return; } #endif - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) static void dec_prm_tcx_spec( Decoder_State *st, /* i/o: decoder memory state */ int16_t param[], /* o : decoded parameters */ @@ -472,7 +472,7 @@ static void dec_prm_tcx_spec( return; } - +#endif /*-----------------------------------------------------------------* * Function ivas_mdct_dec_side_bits_frame_channel() @@ -676,7 +676,7 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( return; } #endif - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void ivas_mdct_dec_side_bits_frame_channel( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ int16_t param_lpc[CPE_CHANNELS][NPRM_LPC_NEW], /* o : lpc_parameters */ @@ -876,7 +876,7 @@ void ivas_mdct_dec_side_bits_frame_channel( return; } - +#endif /*-----------------------------------------------------------------* * ivas_mdct_core_invQ() @@ -926,10 +926,6 @@ void ivas_mdct_core_invQ_fx( Word16 L_frameTCX_global[CPE_CHANNELS]; Word16 tmp_ms_sig[CPE_CHANNELS][N_MAX]; Word16 tmp_ms_sig_e[CPE_CHANNELS]; -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - // PLC case kept - float concealment_noise[CPE_CHANNELS][L_FRAME48k]; -#endif Word32 concealment_noise_fx[CPE_CHANNELS][L_FRAME48k]; Word16 concealment_noise_e[CPE_CHANNELS] = { 0 }, concealment_noise_len[CPE_CHANNELS]; TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode_bfi; @@ -948,6 +944,7 @@ void ivas_mdct_core_invQ_fx( push_wmops( "mdct_core_invQ" ); sts = hCPE->hCoreCoder; bfi = sts[0]->bfi; + move16(); noise_gen_mode_bfi = NOISE_GEN_MODE_UNDEF; move32(); @@ -1088,8 +1085,7 @@ void ivas_mdct_core_invQ_fx( /* PLC: [Common: mode decision] * PLC: Decide which Concealment to use. Update pitch lags if needed */ - // PLC to be done - st->core = GetPLCModeDecision_flt( st ); + st->core = GetPLCModeDecision_ivas_fx( st ); } test(); @@ -1213,18 +1209,18 @@ void ivas_mdct_core_invQ_fx( { IF( bfi && sts[ch]->tonal_mdct_plc_active && NE_16( sts[ch]->element_mode, IVAS_CPE_MDCT ) ) { - FOR( Word16 i = 0; i < sts[ch]->hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + FOR( Word16 i = 0; i < sts[ch]->hTonalMDCTConc->pTCI->numIndexes; i++ ) { - float pd = sts[ch]->hTonalMDCTConc->pTCI_float->phaseDiff_float[i]; + float pd = sts[ch]->hTonalMDCTConc->pTCI->phaseDiff_float[i]; IF( pd >= PI2 ) pd = fmodf( pd, PI2 ) - PI2; - sts[ch]->hTonalMDCTConc->pTCI_float->phaseDiff[i] = float_to_fix16( pd, Q12 ); + sts[ch]->hTonalMDCTConc->pTCI->phaseDiff[i] = float_to_fix16( pd, Q12 ); } FOR( Word16 i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++ ) { - float pd = sts[ch]->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float[i]; + float pd = sts[ch]->hTonalMDCTConc->pTCI->phase_currentFramePredicted_float[i]; pd = fmodf( pd, PI2 ); - sts[ch]->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted[i] = (Word16) ( pd * ( 1u << Q13 ) ); + sts[ch]->hTonalMDCTConc->pTCI->phase_currentFramePredicted[i] = (Word16) ( pd * ( 1u << Q13 ) ); } FOR( Word16 i = 0; i < FDNS_NPTS; i++ ) { @@ -1232,10 +1228,6 @@ void ivas_mdct_core_invQ_fx( sts[ch]->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e = s_max( sts[ch]->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, sts[ch]->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ); } } - IF( sts[ch]->enablePlcWaveadjust ) - { - //f2me_buf( sts[ch]->hPlcInfo->data_reci2, sts[ch]->hPlcInfo->data_reci2_fx, &sts[ch]->hPlcInfo->data_reci2_scale, sts[ch]->hPlcInfo->L_frameTCX ); - } } } #endif @@ -1286,7 +1278,9 @@ void ivas_mdct_core_invQ_fx( /* Set pointer to parameters */ prm[ch] = param[ch] + ( k * DEC_NPRM_DIV ); L_frameTCX_global[ch] = st->hTcxDec->L_frameTCX / nSubframes[ch]; + move16(); L_spec[ch] = st->hTcxCfg->tcx_coded_lines / nSubframes[ch]; + move16(); init_tcx_info_fx( st, st->L_frame / nSubframes[ch], st->hTcxDec->L_frameTCX / nSubframes[ch], k, bfi, &tcx_offset[ch], &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] ); @@ -1344,8 +1338,7 @@ void ivas_mdct_core_invQ_fx( pop_wmops(); return; } -#endif - +#else void ivas_mdct_core_invQ( CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ int16_t nTnsBitsTCX10[CPE_CHANNELS][NB_DIV], /* i : number of TNS bits */ @@ -1370,9 +1363,6 @@ void ivas_mdct_core_invQ( /* LPC */ Word16 Aind[CPE_CHANNELS][M + 1]; float sns[CPE_CHANNELS][NB_DIV][M]; -#ifdef IVAS_FLOAT_FIXED - Word32 sns_fx[CPE_CHANNELS][NB_DIV][M]; -#endif /* TCX */ float xn_buf[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; int16_t tcx_offset[CPE_CHANNELS]; @@ -1390,20 +1380,12 @@ void ivas_mdct_core_invQ( float concealment_noise[CPE_CHANNELS][L_FRAME48k]; TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode_bfi; -#ifdef IVAS_FLOAT_FIXED - Word16 xn_buf_fx[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; - Word16 gain_tcx_fx = 0, gain_tcx_e = 0; -#endif - push_wmops( "mdct_core_invQ" ); sts = hCPE->hCoreCoder; bfi = sts[0]->bfi; noise_gen_mode_bfi = NOISE_GEN_MODE_UNDEF; set_f( xn_buf, 0, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX ); -#ifdef IVAS_FLOAT_FIXED - set16_fx( xn_buf_fx, 0, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX ); -#endif set_s( total_nbbits, 0, CPE_CHANNELS ); set_s( bitsRead, 0, CPE_CHANNELS ); tmp_concealment_method = 0; @@ -1551,60 +1533,13 @@ void ivas_mdct_core_invQ( { if ( !MCT_flag && sts[0]->sr_core == 25600 && ( ( hCPE->element_brate == IVAS_48k || hCPE->element_brate == IVAS_64k ) ) ) { -#ifdef IVAS_FLOAT_FIXED - Word32 snsQ_out_fx[CPE_CHANNELS][NB_DIV][M]; - - dequantize_sns_fx( param_lpc, snsQ_out_fx, sts ); - for ( int j = 0; j < NB_DIV; j++ ) - { - for ( k = 0; k < M; k++ ) - { - sns[0][j][k] = fix_to_float( snsQ_out_fx[0][j][k], 16 ); - sns[1][j][k] = fix_to_float( snsQ_out_fx[1][j][k], 16 ); - } - } -#ifdef DUMPS_ENABLED - Word16 tmp_nSubframes = ( sts[0]->core == TCX_20_CORE ) ? 1 : NB_DIV; - for ( int j = 0; j < tmp_nSubframes; j++ ) - { - dbgwrite_txt( sns[0][j], M, "Fixed_code_sns_0.txt", NULL ); - dbgwrite_txt( sns[1][j], M, "Fixed_code_sns_1.txt", NULL ); - } -#endif - -#else dequantize_sns( param_lpc, sns, sts ); -#ifdef DUMPS_ENABLED - Word16 tmp_nSubframes = ( sts[0]->core == TCX_20_CORE ) ? 1 : NB_DIV; - for ( int j = 0; j < tmp_nSubframes; j++ ) - { - dbgwrite_txt( sns[0][j], M, "Float_code_sns_0.txt", NULL ); - dbgwrite_txt( sns[1][j], M, "Float_code_sns_1.txt", NULL ); - } -#endif -#endif } else { if ( sts[0]->core == TCX_20_CORE && sts[1]->core == TCX_20_CORE && sts[0]->mct_chan_mode != MCT_CHAN_MODE_IGNORE && sts[1]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) { -#ifdef IVAS_FLOAT_FIXED - Word16 q_l = 0, q_r = 0; - sns_avq_dec_stereo_fx( param_lpc[0], param_lpc[1], sts[0]->L_frame, &sns_fx[0][0][0], &q_l, &sns_fx[1][0][0], &q_r ); - for ( int i = 0; i < M; i++ ) - { - sns[0][0][i] = fix_to_float( sns_fx[0][0][i], q_l ); - sns[1][0][i] = fix_to_float( sns_fx[1][0][i], q_r ); - } -#ifdef DUMPS_ENABLED - dbgwrite_txt( &sns[1][0][0], M, "Fixed_code_sns_buf.txt", NULL ); -#endif -#else sns_avq_dec_stereo( param_lpc[0], param_lpc[1], sts[0]->L_frame, &sns[0][0][0], &sns[1][0][0] ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( &sns[1][0][0], M, "Float_code_sns_buf.txt", NULL ); -#endif -#endif } else { @@ -1613,38 +1548,7 @@ void ivas_mdct_core_invQ( st = sts[ch]; if ( st->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) { -#ifdef IVAS_FLOAT_FIXED - Word32 SNS_Q_fx[NB_DIV][M]; - Word16 q_snsq = 0; - sns_avq_dec_fx( param_lpc[ch], SNS_Q_fx, &q_snsq, st->L_frame, st->numlpc ); - for ( int j = 0; j < NB_DIV; j++ ) - { - for ( k = 0; k < M; k++ ) - { - sns[ch][j][k] = fix_to_float( SNS_Q_fx[j][k], q_snsq ); - } - } -#ifdef DUMPS_ENABLED - for ( int i = 0; i < CPE_CHANNELS; i++ ) - { - for ( int j = 0; j < NB_DIV; j++ ) - { - dbgwrite_txt( sns, M, "Fixed_code_output.txt", NULL ); - } - } -#endif -#else sns_avq_dec( param_lpc[ch], sns[ch], st->L_frame, st->numlpc ); -#ifdef DUMPS_ENABLED - for ( int i = 0; i < CPE_CHANNELS; i++ ) - { - for ( int j = 0; j < NB_DIV; j++ ) - { - dbgwrite_txt( sns, M, "Float_code_output.txt", NULL ); - } - } -#endif -#endif } } } @@ -1716,75 +1620,8 @@ void ivas_mdct_core_invQ( } nf_seed = 0; -#ifdef IVAS_FLOAT_FIXED - Word32 x_fx[N_MAX]; - Word16 Aq_fx[M + 1], Aq_e, x_e; - set32_fx(x_fx, 0, N_MAX); -#endif - -#ifdef IVAS_FLOAT_FIXED - - f2me_buf(x[ch][k], x_fx, &x_e, L_frameTCX[ch]); - f2me_buf_16(Aq[ch], Aq_fx, &Aq_e, M + 1); - - //st->gamma = float_to_fix16(st->gamma_float, Q15); - st->preemph_fac = float_to_fix16(st->preemph_fac_float, Q15); - st->hTcxDec->cummulative_damping_tcx = float_to_fix16(st->hTcxDec->cummulative_damping_tcx_float, Q15); - st->Mode2_lp_gainp = float_to_fix(st->lp_gainp, Q16); - st->hTcxLtpDec->tcxltp_gain = float_to_fix16(st->hTcxLtpDec->tcxltp_gain_float, Q15); - //st->inv_gamma = FL2WORD16_SCALE(1 / st->gamma_float, 1); - f2me_16(st->last_gain_syn_deemph_float, &st->last_gain_syn_deemph, &st->last_gain_syn_deemph_e); - f2me_16(st->last_concealed_gain_syn_deemph_float, &st->last_concealed_gain_syn_deemph, &st->last_concealed_gain_syn_deemph_e); - f2me_16(st->hTcxDec->old_gaintcx_bfi_float, &st->hTcxDec->old_gaintcx_bfi, &st->hTcxDec->old_gaintcx_bfi_e); - - decoder_tcx_invQ_fx( st, prm[ch], Aq_fx, Aind[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x_fx, &x_e, NULL, NULL, xn_buf_fx, &fUseTns[ch][k], &tnsData[ch][k], &gain_tcx_fx, &gain_tcx_e, &prm_sqQ, &nf_seed, bfi, k ); - - /* TODO: remove float dependency */ - st->hTcxDec->stepCompensate_float = me2f_16(st->hTcxDec->stepCompensate, st->hTcxDec->stepCompensate_e); - st->hTcxDec->gainHelper_float = me2f_16(st->hTcxDec->gainHelper, st->hTcxDec->gainHelper_e); - st->last_concealed_gain_syn_deemph_float = me2f_16(st->last_concealed_gain_syn_deemph, st->last_concealed_gain_syn_deemph_e); - st->last_gain_syn_deemph_float = me2f_16(st->last_gain_syn_deemph, st->last_gain_syn_deemph_e); - st->hTcxDec->old_gaintcx_bfi_float = me2f_16(st->hTcxDec->old_gaintcx_bfi, st->hTcxDec->old_gaintcx_bfi_e); - - st->hTcxDec->cummulative_damping_tcx_float = fix16_to_float(st->hTcxDec->cummulative_damping_tcx, Q15); - st->hTcxDec->damping_float = fix16_to_float(st->hTcxDec->damping, Q14); - st->lp_gainp = fix_to_float(st->Mode2_lp_gainp, Q16); - - me2f_buf(x_fx, x_e, x[ch][k], L_frameTCX[ch]); - gain_tcx = me2f_16(gain_tcx_fx, gain_tcx_e); - for (int i = 0; i < max(max(L_frame[ch], L_spec[ch]), L_frameTCX[ch]); i++) - { - xn_buf[i] = fix16_to_float(xn_buf_fx[i], Q14); - } -#if 0 - dbgwrite_txt(x[ch][k], L_frameTCX[ch], "logs\\dir\\Fixed_code_decoderTcxInvQ_x.txt", NULL); - dbgwrite_txt(xn_buf, max(max(L_frame[ch], L_spec[ch]), L_frameTCX[ch]), "logs\\dir\\Fixed_code_decoderTcxInvQ_xnBuf.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->stepCompensate_float), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_stepCompensate.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->gainHelper_float), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_gainHelper.txt", NULL); - dbgwrite_txt(&(st->last_concealed_gain_syn_deemph_float), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_lastConcealedGainSynDeemph.txt", NULL); - dbgwrite_txt(&(gain_tcx), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_gainTcx.txt", NULL); - dbgwrite_txt(&(st->last_gain_syn_deemph_float), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_lastGainSynDeemph.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->old_gaintcx_bfi_float), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_oldGaintcxBfi.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->cummulative_damping_tcx_float), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_cummulativeDampingTcx.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->damping_float), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_dampingFact.txt", NULL); - dbgwrite_txt(&(st->lp_gainp), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_lpGainp.txt", NULL); -#endif -#else decoder_tcx_invQ(st, prm[ch], Aq[ch], Aind[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x[ch][k], NULL, xn_buf, &fUseTns[ch][k], &tnsData[ch][k], &gain_tcx, &prm_sqQ, &nf_seed, bfi, k); -#if 0 - dbgwrite_txt(x[ch][k], L_frameTCX[ch], "logs\\dir\\Float_code_decoderTcxInvQ_x.txt", NULL); - dbgwrite_txt(xn_buf, max(max(L_frame[ch], L_spec[ch]), L_frameTCX[ch]), "logs\\dir\\Float_code_decoderTcxInvQ_xnBuf.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->stepCompensate_float), 1, "logs\\dir\\Float_code_decoderTcxInvQ_stepCompensate.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->gainHelper_float), 1, "logs\\dir\\Float_code_decoderTcxInvQ_gainHelper.txt", NULL); - dbgwrite_txt(&(st->last_concealed_gain_syn_deemph_float), 1, "logs\\dir\\Float_code_decoderTcxInvQ_lastConcealedGainSynDeemph.txt", NULL); - dbgwrite_txt(&(gain_tcx), 1, "logs\\dir\\Float_code_decoderTcxInvQ_gainTcx.txt", NULL); - dbgwrite_txt(&(st->last_gain_syn_deemph_float), 1, "logs\\dir\\Float_code_decoderTcxInvQ_lastGainSynDeemph.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->old_gaintcx_bfi_float), 1, "logs\\dir\\Float_code_decoderTcxInvQ_oldGaintcxBfi.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->cummulative_damping_tcx_float), 1, "logs\\dir\\Float_code_decoderTcxInvQ_cummulativeDampingTcx.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->damping_float), 1, "logs\\dir\\Float_code_decoderTcxInvQ_dampingFact.txt", NULL); - dbgwrite_txt(&(st->lp_gainp), 1, "logs\\dir\\Float_code_decoderTcxInvQ_lpGainp.txt", NULL); -#endif -#endif + mvr2r( x[ch][k], x_0[ch][k], L_frameTCX[ch] ); if ( bfi && !MCT_flag ) @@ -1792,87 +1629,9 @@ void ivas_mdct_core_invQ( TonalMdctConceal_create_concealment_noise_ivas( concealment_noise[ch], hCPE, L_frameTCX[ch], L_frame[ch], ch, k, st->core, st->hTcxDec->cummulative_damping_tcx_float, noise_gen_mode_bfi ); } -#ifdef IVAS_FLOAT_FIXED - f2me_buf( x[ch][k], x_fx, &x_e, L_frameTCX[ch] ); - f2me_buf_16( Aq[ch], Aq_fx, &Aq_e, M + 1 ); - f2me_16( gain_tcx, &gain_tcx_fx, &gain_tcx_e ); - st->hTcxLtpDec->tcxltp_gain = float_to_fix16( st->hTcxLtpDec->tcxltp_gain_float, Q15 ); - st->hTcxDec->cummulative_damping_tcx = float_to_fix16( st->hTcxDec->cummulative_damping_tcx_float, Q15 ); - Word32 concealment_noise_fx[L_FRAME48k]; - Word16 concealment_noise_e = 0, concealment_noise_len; - concealment_noise_len = get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ); - IF( bfi && MCT_flag == 0 )/* to check if concealment_noise was initialised */ - { - f2me_buf( concealment_noise[ch], concealment_noise_fx, &concealment_noise_e, concealment_noise_len ); - } - FOR( Word16 l = 0; l < N_LTP_GAIN_MEMS; l++ ) - { - st->hTcxDec->ltpGainMemory_fx[l] = float_to_fix16( st->hTcxDec->ltpGainMemory[l], Q15 ); - } - decoder_tcx_noisefilling_fx( st, concealment_noise_fx, concealment_noise_e, Aq_fx, L_frameTCX_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x_fx, &x_e, NULL, NULL, &tmp_concealment_method, gain_tcx_fx, gain_tcx_e, prm_sqQ, nf_seed, bfi, MCT_flag, k ); - FOR( Word16 l = 0; l < N_LTP_GAIN_MEMS; l++ ) - { - st->hTcxDec->ltpGainMemory[l] = fix16_to_float( st->hTcxDec->ltpGainMemory_fx[l], Q15 ); - } - me2f_buf( x_fx, x_e, x[ch][k], L_frameTCX[ch] ); -#else decoder_tcx_noisefilling( st, concealment_noise[ch], Aq[ch], L_frameTCX_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x[ch][k], NULL, &tmp_concealment_method, gain_tcx, prm_sqQ, nf_seed, bfi, MCT_flag, k ); -#endif -#ifdef IVAS_FLOAT_FIXED - // Float to fix starts here - Word16 x_len; - IF(bfi && st->tonal_mdct_plc_active && NE_16(st->element_mode, IVAS_CPE_MDCT)) - { - FOR(Word16 i = 0; i < st->hTonalMDCTConc->pTCI_float->numIndexes; i++) - { - float pd = st->hTonalMDCTConc->pTCI_float->phaseDiff_float[i]; - if (pd >= PI2) - pd = fmodf(pd, PI2) - PI2; - st->hTonalMDCTConc->pTCI_float->phaseDiff[i] = float_to_fix16(pd, Q12); - } - FOR(Word16 i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++) - { - float pd = st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float[i]; - pd = fmodf(pd, PI2); - st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted[i] = (Word16)(pd * (1u << Q13)); - } - FOR(Word16 i = 0; i < FDNS_NPTS; i++) - { - f2me_16(st->hTonalMDCTConc->secondLastBlockData.scaleFactors_float[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]); - st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e = s_max(st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]); - } - } - st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16(st->hTcxDec->tcxltp_last_gain_unmodified_float, Q15); - st->old_fpitch = float_to_fix(st->old_fpitch_float, Q16); - st->hTonalMDCTConc->lastPitchLag = float_to_fix(st->hTonalMDCTConc->lastPitchLag_float, Q16); - IF(st->enablePlcWaveadjust) - { - //f2me_buf(st->hPlcInfo->data_reci2, st->hPlcInfo->data_reci2_fx, &st->hPlcInfo->data_reci2_scale, st->hPlcInfo->L_frameTCX); - } - // u8bit to 16bit - FOR(int l = 0; l < IGF_START_MX; l++) - { - st->hIGFDec->infoTCXNoise_evs[l] = (Word16)st->hIGFDec->infoTCXNoise[l]; - } - // Float to fix ends here - - decoder_tcx_noiseshaping_igf_fx( st, L_spec[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx, &x_e, &x_len, NULL, NULL, &tmp_concealment_method, bfi ); - - // Fixed to float starts here - st->hTonalMDCTConc->lastPitchLag_float = fix_to_float(st->hTonalMDCTConc->lastPitchLag, Q16); - st->hTonalMDCTConc->nFramesLost_float = fix16_to_float(st->hTonalMDCTConc->nFramesLost, Q1); - // 16bit to u8bit - FOR(Word16 l = 0; l < IGF_START_MX; l++) - { - st->hIGFDec->infoTCXNoise[l] = (uint8_t)st->hIGFDec->infoTCXNoise_evs[l]; - } - me2f_buf(st->hIGFDec->virtualSpec, st->hIGFDec->virtualSpec_e, st->hIGFDec->virtualSpec_float, (N_MAX_TCX - IGF_START_MN)); - me2f_buf(x_fx, x_e, x[ch][k], x_len); - // Fixed to float ends here -#else decoder_tcx_noiseshaping_igf( st, L_spec[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x[ch][k], NULL, &tmp_concealment_method, bfi ); -#endif } } } @@ -1880,6 +1639,8 @@ void ivas_mdct_core_invQ( pop_wmops(); return; } +#endif + /*-----------------------------------------------------------------* * ivas_mdct_core_reconstruct() @@ -1887,6 +1648,7 @@ void ivas_mdct_core_invQ( * reconstruct time signal *-----------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_mdct_core_reconstruct( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ float *x[][NB_DIV], /* i/o: synthesis @internal_FS */ @@ -1955,126 +1717,9 @@ void ivas_mdct_core_reconstruct( if ( !skip_decoding ) { -#ifdef IVAS_FLOAT_FIXED - // - Word16 synth_fx[2040], synthFB_fx[2040]; - Word16 q_x = Q11, q_win = -2; - Word32 x_fx[1200]; - Word16 x_e; - - FOR(Word16 i = 0; i < s_min(s_max(s_max(st->hIGFDec->infoIGFStopLine, s_max(L_frameTCX[ch], L_spec[ch])), L_frame[ch]), 1200); i++) { - x_fx[i] = (Word32)(x[ch][k][i] * (1 << q_x)); - } - x_e = 31 - q_x; - st->hIGFDec->virtualSpec_e = x_e; -#ifndef IVAS_FLOAT_FIXED - IF ( NE_16(st->igf, 0) ) - FOR(Word16 i = 0; i < s_min(st->hIGFDec->infoIGFStopLine - st->hIGFDec->infoIGFStartLine, 856); i++) { - st->hIGFDec->virtualSpec_fx[st->hIGFDec->infoIGFStartLine - IGF_START_MN + i] = (Word32)(st->hIGFDec->virtualSpec_float[st->hIGFDec->infoIGFStartLine - IGF_START_MN + i] * (1 << (31 - st->hIGFDec->virtualSpec_e))); - } -#endif - - FOR( Word16 ind = 0; ind < 320; ind++ ) - { - st->hTcxDec->syn_Overl[ind] = (Word16)(st->hTcxDec->syn_Overl_float[ind] / (1<<(-q_win))); - } - FOR(Word16 ind = 0; ind < 320; ind++) { - st->hTcxDec->syn_Overl_TDAC[ind] = (Word16)(st->hTcxDec->syn_Overl_TDAC_float[ind] / (1<<(-q_win))); - } - FOR( Word16 ind = 0; ind < 480; ind++ ) - { - st->hTcxDec->syn_OverlFB[ind] = (Word16)(st->hTcxDec->syn_OverlFB_float[ind] / (1<<(-q_win))); - } - FOR(Word16 ind = 0; ind < 480; ind++) { - st->hTcxDec->syn_Overl_TDACFB[ind] = (Word16)(st->hTcxDec->syn_Overl_TDACFB_float[ind] / (1<<(-q_win))); - } - FOR(Word16 ind = 0; ind < 640; ind++) { - st->hHQ_core->old_out_LB_fx[ind] = (Word16)(st->hHQ_core->old_outLB[ind] / (1<<(-q_win))); - } - //FOR(Word16 ind = 0; ind < 17; ind++) { - // st->old_Aq_12_8_fx_32[ind] = (Word32)(st->old_Aq_12_8[ind] * (1<<28)); - //} - //FOR( Word16 ind = 0; ind < M + 1; ind++ ) - //{ - // st->old_Aq_12_8_fx[ind] = (Word16) ( st->old_Aq_12_8[ind] * 4096.f ); - //} - FOR(Word16 ind = 0; ind < 320; ind++) { - st->hTcxDec->old_syn_Overl[ind] = (Word16)(st->hTcxDec->old_syn_Overl_float[ind] / (1<<(-q_win))); - } - FOR(Word16 ind = 0; ind < 320; ind++) { - st->hTcxDec->syn_Overl_TDAC[ind] = (Word16)(st->hTcxDec->syn_Overl_TDAC_float[ind] / (1<<(-q_win))); - } - FOR(Word16 ind = 0; ind < 480; ind++) { - st->hTcxDec->syn_OverlFB[ind] = (Word16)(st->hTcxDec->syn_OverlFB_float[ind] / (1<<(-q_win))); - } - FOR(Word16 ind = 0; ind < 320; ind++) { - st->hTcxDec->syn_Overl[ind] = (Word16)(st->hTcxDec->syn_Overl_float[ind] / (1<<(-q_win))); - } - st->hTcxDec->conceal_eof_gain = (Word16)(st->hTcxDec->conceal_eof_gain_float * 16384.f); - st->last_concealed_gain_syn_deemph = (Word16)(st->last_concealed_gain_syn_deemph_float * 32767.f); - float maxim = 0; - IF(st->hFdCngDec && st->hFdCngDec->hFdCngCom) { - FOR(Word16 ind = 0; ind < FFTCLDFBLEN; ind++) - { - maxim = fmaxf(maxim, fabsf(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[ind])); - } - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; - IF(L_abs((Word32)maxim)!=0) st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - norm_l((Word32)maxim); - FOR(Word16 ind = 0; ind < FFTCLDFBLEN; ind++) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel[ind] = (Word32)(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[ind] * (1LL<<(31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp))); - } - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = float_to_fix16(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt, 15); - } - FOR(Word16 ind = 0; ind < 960; ind++) { - st->hHQ_core->old_out_fx[ind] = (Word16)(st->hHQ_core->old_out[ind] / (1<<(-q_win))); - } - FOR(Word16 ind = 0; ind < L_frame_global[ch]; ind++) { - synth_fx[k * L_frame[ch] + ind] = (Word16)(synth[k * L_frame[ch] + ind] / (1<<(-q_win))); - } - FOR(Word16 ind = 0; ind < L_frame_globalTCX[ch]; ind++) { - synthFB_fx[k * L_frameTCX[ch] + ind] = (Word16)(synthFB[k * L_frameTCX[ch] + ind] / (1<<(-q_win))); - } - - Copy_Scale_sig_16_32( st->old_Aq_12_8_fx, st->old_Aq_12_8_fx_32, M + 1, ( 28 - norm_s( st->old_Aq_12_8_fx[0] - 1 ) ) ); - decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], &x_fx[0], q_x, xn_buf_fx, q_win, - ( ( hCPE->nchan_out == 1 && st->hTcxDec->kernel_type[k] == MDST_IV ) || st->hTcxCfg->tcx_last_overlap_mode == TRANSITION_OVERLAP ) ? MDCT_IV : st->hTcxDec->kernel_type[k], - fUseTns[ch][k], &synth_fx[k * L_frame[ch]], &synthFB_fx[k * L_frameTCX[ch]], bfi, k, 0 ); - - IF(st->igf) me2f_buf(x_fx, x_e, x[ch][k], s_max(st->hIGFDec->infoIGFStopLine, s_max(L_frameTCX[ch], L_spec[ch]) ) ); - - //FOR(Word16 ind = 0; ind < 17; ind++) { - // st->old_Aq_12_8[ind] = (float)(st->old_Aq_12_8_fx[ind]) / (float)(1<<12); - //} - FOR(Word16 ind = 0; ind < 640; ind++) { - st->hHQ_core->old_outLB[ind] = (float)st->hHQ_core->old_out_LB_fx[ind] * (1<<(-q_win)); - } - FOR(Word16 ind = 0; ind < 960; ind++) { - st->hHQ_core->old_out[ind] = (float)st->hHQ_core->old_out_fx[ind] * (1<<(-q_win)); - } - FOR(Word16 ind = 0; ind < L_frame_global[ch]; ind++) { - synth[k * L_frame[ch] + ind] = (float)synth_fx[k * L_frame[ch] + ind] * (1<<(-q_win)); - } - FOR(Word16 ind = 0; ind < L_frame_globalTCX[ch]; ind++) { - synthFB[k * L_frameTCX[ch] + ind] = (float)synthFB_fx[k * L_frameTCX[ch] + ind] * (1<<(-q_win)); - } - IF ( EQ_16(st->hTcxCfg->last_aldo, 0) ) FOR(Word16 ind = 0; ind < L_FRAME32k / 2; ind++) { - st->hTcxDec->syn_Overl_float[ind] = (float)st->hTcxDec->syn_Overl[ind] * (1<<(-q_win)); - } - IF ( EQ_16(st->hTcxCfg->last_aldo, 0) ) FOR(Word16 ind = 0; ind < L_FRAME_MAX / 2; ind++) { - st->hTcxDec->syn_OverlFB_float[ind] = (float)st->hTcxDec->syn_OverlFB[ind] * (1<<(-q_win)); - } - st->hTcxDec->tcxltp_third_last_pitch_float = fix_to_float(st->hTcxDec->tcxltp_third_last_pitch, 16); - st->hTcxDec->tcxltp_second_last_pitch_float = fix_to_float(st->hTcxDec->tcxltp_second_last_pitch, 16); - st->old_fpitch_float = fix_to_float(st->old_fpitch, 16); - st->old_fpitchFB_float = fix_to_float(st->old_fpitchFB, 16); - // - -#else decoder_tcx_imdct( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], &x[ch][k][0], xn_buf, ( ( hCPE->nchan_out == 1 && st->hTcxDec->kernel_type[k] == MDST_IV ) || st->hTcxCfg->tcx_last_overlap_mode == TRANSITION_OVERLAP ) ? MDCT_IV : st->hTcxDec->kernel_type[k], fUseTns[ch][k], &synth[k * L_frame[ch]], &synthFB[k * L_frameTCX[ch]], bfi, k, 0 ); -#endif } else { @@ -2183,8 +1828,7 @@ void ivas_mdct_core_reconstruct( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void ivas_mdct_core_reconstruct_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *x_fx[][NB_DIV], /* i/o: synthesis @internal_FS */ // Q(q_x) @@ -2252,8 +1896,9 @@ void ivas_mdct_core_reconstruct_fx( Scale_sig(st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub(q_win, st->Q_syn)); Scale_sig(st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub(q_win, st->Q_syn)); Scale_sig(st->hHQ_core->old_out_fx, L_FRAME48k, sub(q_win, st->Q_syn)); - Scale_sig(synth_buf_fx, 3136, sub(-2, q_syn)); - Scale_sig(synth_bufFB_fx, 3136, sub(-2, q_syn)); + Scale_sig(synth_buf_fx, 3136, sub(q_win, q_syn)); + Scale_sig(synth_bufFB_fx, 3136, sub(q_win, q_syn)); + Scale_sig(st->syn, M + 1, q_win - st->Q_syn); FOR( k = 0; k < nSubframes[ch]; k++ ) { L_spec[ch] = st->hTcxCfg->tcx_coded_lines / nSubframes[ch]; @@ -2279,16 +1924,18 @@ void ivas_mdct_core_reconstruct_fx( IF ( EQ_16(bfi, 0) && st->hTonalMDCTConc != NULL ) { - TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synthFB_fx, L_frameTCX[ch] ); + Word16 synth_tmp[L_FRAME48k]; + Copy_Scale_sig(synthFB_fx, synth_tmp, st->hTonalMDCTConc->nSamples, 2); + TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synth_tmp, L_frameTCX[ch] ); } decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, NULL, bfi, MCT_flag ); Scale_sig(st->hTcxDec->syn_Overl_TDACFB, shr(L_FRAME_MAX, 1), sub(-1 - st->Q_syn, q_win)); Scale_sig(st->hTcxDec->syn_Overl_TDAC, shr(L_FRAME32k, 1), sub(-1 - st->Q_syn, q_win)); Scale_sig(st->hTcxDec->old_syn_Overl, shr(L_FRAME32k, 1), sub(-1 - st->Q_syn, q_win)); - Scale_sig(synth_buf_fx, 3136, sub(q_syn, -2)); - Scale_sig(synth_bufFB_fx, 3136, sub(q_syn, -2)); - Scale_sig(st->syn, M + 1, st->Q_syn + 1); + Scale_sig(synth_buf_fx, 3136, sub(q_syn, q_win)); + Scale_sig(synth_bufFB_fx, 3136, sub(q_syn, q_win)); + Scale_sig(st->syn, M + 1, st->Q_syn + 2); Scale_sig(st->hTcxDec->syn_OverlFB, shr(L_FRAME_MAX, 1), sub(st->Q_syn, q_win)); Scale_sig(st->hTcxDec->syn_Overl, shr(L_FRAME32k, 1), sub(st->Q_syn, q_win)); Scale_sig(st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub(st->Q_syn, q_win)); @@ -2367,7 +2014,7 @@ void ivas_mdct_core_reconstruct_fx( /* Postfiltering */ Word16 x_fx_16[1200]; - Copy_Scale_sig_32_16(x_fx[ch][0], x_fx_16, 1200, sub(0, q_x)); + Copy_Scale_sig_32_16(x_fx[ch][0], x_fx_16, st->L_frame, sub(0, q_x)); post_decoder_ivas_fx( st, synth_buf_fx, pit_gain_fx[ch], pitch[ch], x_fx_16, st->p_bpf_noise_buf ); @@ -2430,6 +2077,8 @@ void ivas_mdct_core_reconstruct_fx( } #endif + +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-----------------------------------------------------------------* * ivas_mdct_core_tns_ns() * @@ -2537,7 +2186,7 @@ void ivas_mdct_core_tns_ns( x_e = 31 - q_x;*/ TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx, x_e, L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); - st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); + //st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); #else TonalMDCTConceal_SaveFreqSignal_ivas( st->hTonalMDCTConc, x[ch][k], L_frameTCX[ch], L_frame[ch], &sns_int_scf[0], get_igf_startline_flt( st, L_frame[ch], L_frameTCX[ch] ) ); #endif @@ -2641,19 +2290,19 @@ void ivas_mdct_core_tns_ns( // Float to fixed Word32 x_fx[N_MAX]; Word16 x_e; - f2me_buf(x[ch][0], x_fx, &x_e, st->hTonalMDCTConc->pTCI_float->upperIndex[st->hTonalMDCTConc->pTCI_float->numIndexes - 1]); - FOR(Word16 i = 0; i < st->hTonalMDCTConc->pTCI_float->numIndexes; i++) + f2me_buf(x[ch][0], x_fx, &x_e, st->hTonalMDCTConc->pTCI->upperIndex[st->hTonalMDCTConc->pTCI->numIndexes - 1]); + FOR(Word16 i = 0; i < st->hTonalMDCTConc->pTCI->numIndexes; i++) { - float pd = st->hTonalMDCTConc->pTCI_float->phaseDiff_float[i]; + float pd = st->hTonalMDCTConc->pTCI->phaseDiff_float[i]; if (pd >= PI2) pd = fmodf(pd, PI2) - PI2; - st->hTonalMDCTConc->pTCI_float->phaseDiff[i] = float_to_fix16(pd, Q12); + st->hTonalMDCTConc->pTCI->phaseDiff[i] = float_to_fix16(pd, Q12); } FOR(Word16 i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++) { - float pd = st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float[i]; + float pd = st->hTonalMDCTConc->pTCI->phase_currentFramePredicted_float[i]; pd = fmodf(pd, PI2); - st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted[i] = (Word16)(pd * (1u << Q13)); + st->hTonalMDCTConc->pTCI->phase_currentFramePredicted[i] = (Word16)(pd * (1u << Q13)); } FOR(Word16 i = 0; i < FDNS_NPTS; i++) { @@ -2662,14 +2311,14 @@ void ivas_mdct_core_tns_ns( } TonalMDCTConceal_Apply_ivas_fx( st->hTonalMDCTConc, x_fx, &x_e, st->hTcxCfg->psychParamsCurrent ); // Fix to float - FOR(Word16 i = 0; i < st->hTonalMDCTConc->pTCI_float->numIndexes; i++) + FOR(Word16 i = 0; i < st->hTonalMDCTConc->pTCI->numIndexes; i++) { - FOR(Word16 l = st->hTonalMDCTConc->pTCI_float->lowerIndex[i]; l <= st->hTonalMDCTConc->pTCI_float->upperIndex[i]; l++) + FOR(Word16 l = st->hTonalMDCTConc->pTCI->lowerIndex[i]; l <= st->hTonalMDCTConc->pTCI->upperIndex[i]; l++) { x[ch][0][l] = me2f(x_fx[l], x_e); } } - st->hTonalMDCTConc->nFramesLost_float = fix16_to_float(st->hTonalMDCTConc->nFramesLost, Q1); + //st->hTonalMDCTConc->nFramesLost_float = fix16_to_float(st->hTonalMDCTConc->nFramesLost, Q1); #else TonalMDCTConceal_Apply_ivas( st->hTonalMDCTConc, x[ch][0], st->hTcxCfg->psychParamsCurrent ); #endif @@ -2683,6 +2332,7 @@ void ivas_mdct_core_tns_ns( return; } +#endif #ifdef IVAS_FLOAT_FIXED /* Has a missing dependency: TonalMDCTConceal_Apply. Currently not used anywhere and untested.*/ void ivas_mdct_core_tns_ns_fx( @@ -2890,9 +2540,9 @@ void ivas_mdct_core_tns_ns_fx( IF( LT_16(q_x_old , q_x) ) { x_e[ch][0] = sub(31 , q_x_old); - FOR( Word16 i = 0; i < st->hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + FOR( Word16 i = 0; i < st->hTonalMDCTConc->pTCI->numIndexes; i++ ) { - FOR( Word16 l = st->hTonalMDCTConc->pTCI_float->lowerIndex[i]; l <= st->hTonalMDCTConc->pTCI_float->upperIndex[i]; l++ ) + FOR( Word16 l = st->hTonalMDCTConc->pTCI->lowerIndex[i]; l <= st->hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { x_fx[ch][0][l] = L_shr( x_fx[ch][0][l], q_x - q_x_old ); } @@ -2901,13 +2551,13 @@ void ivas_mdct_core_tns_ns_fx( ELSE { x_e[ch][0] = sub(31 , q_x); - FOR( Word16 i = 0; i < st->hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + FOR( Word16 i = 0; i < st->hTonalMDCTConc->pTCI->numIndexes; i++ ) { - FOR( Word16 l = 0; l < st->hTonalMDCTConc->pTCI_float->lowerIndex[i]; l++ ) + FOR( Word16 l = 0; l < st->hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { x_fx[ch][0][l] = L_shr( x_fx[ch][0][l], sub(q_x_old , q_x) ); } - FOR( Word16 l = st->hTonalMDCTConc->pTCI_float->upperIndex[i] + 1; l < L_spec[ch]; l++ ) + FOR( Word16 l = st->hTonalMDCTConc->pTCI->upperIndex[i] + 1; l < L_spec[ch]; l++ ) { x_fx[ch][0][l] = L_shr( x_fx[ch][0][l], sub(q_x_old , q_x) ); } @@ -2927,4 +2577,4 @@ void ivas_mdct_core_tns_ns_fx( return; } -#endif +#endif \ No newline at end of file diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index 5430837c07b2617434a8c1ff0380783a43bdebda..235e1cfadb397fae430fd7bdcef1fa53313dbde4 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -87,7 +87,6 @@ ivas_error ivas_td_binaural_open( st_ivas->transport_config, st_ivas->hRenderConfig->directivity, st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns ); } - /*---------------------------------------------------------------------* * ivas_td_binaural_renderer() * @@ -341,29 +340,14 @@ ivas_error ivas_td_binaural_renderer_sf( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_td_binaural_renderer_sf_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - float *output[], /* i/o: SCE channels / Binaural synthesis */ + Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis */ + const Word16 q_factor, /* i : Q-factor of input/output */ const int16_t n_samples_granularity /* i : granularity of the renderer/buffer */ ) { -#define FIXED_CODE_WIP -#ifdef FIXED_CODE_WIP - Word32 output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; - for (int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++) - { - for (int j = 0; j < L_FRAME48k; j++) - { - output_fx[i][j] = floatToFixed(output[i][j], Q11); - } - } -#endif - Word16 first_sf, last_sf, subframe_idx; - float reverb_signal[BINAURAL_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; - float *p_reverb_signal[BINAURAL_CHANNELS]; - float *output_f_local[BINAURAL_CHANNELS]; - float *tc_local[MAX_TRANSPORT_CHANNELS]; - Word32 reverb_signal_fx[BINAURAL_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; Word32 *output_fx_local[BINAURAL_CHANNELS]; + Word32 reverb_signal_fx[BINAURAL_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; Word32 *p_reverb_signal_fx[BINAURAL_CHANNELS]; Word32 *tc_local_fx[MAX_TRANSPORT_CHANNELS]; Word16 ch, slot_size, slots_to_render, output_frame, tmp; @@ -373,6 +357,10 @@ ivas_error ivas_td_binaural_renderer_sf_fx( Word16 c_indx, nS; Word16 nchan_ism_internal, nchan_ism, ch_offset; + IVAS_QUATERNION *tmp_Quaternion_fx; + IVAS_VECTOR3 *tmp_vector_fx; + Word16 enableCombinedOrientation; + /* Set the number of ISMs */ IF ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { @@ -419,26 +407,16 @@ ivas_error ivas_td_binaural_renderer_sf_fx( FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - p_reverb_signal[ch] = reverb_signal[ch]; -#ifdef FIXED_CODE_WIP p_reverb_signal_fx[ch] = reverb_signal_fx[ch]; -#endif } - FOR( ch = 0; ch < nchan_ism_internal; ch++ ) { - tc_local[ch] = st_ivas->hTcBuffer->tc[ch + ch_offset] + st_ivas->hTcBuffer->n_samples_rendered; -#ifdef FIXED_CODE_WIP tc_local_fx[ch] = st_ivas->hTcBuffer->tc_fx[ch + ch_offset] + st_ivas->hTcBuffer->n_samples_rendered; -#endif } FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) { - output_f_local[ch] = output[ch]; -#ifdef FIXED_CODE_WIP output_fx_local[ch] = output_fx[ch]; -#endif } slot_size = st_ivas->hTcBuffer->n_samples_granularity; @@ -475,127 +453,80 @@ ivas_error ivas_td_binaural_renderer_sf_fx( { IF( !( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( nS, LFE_CHANNEL ) ) ) /* Skip LFE for MC */ { - st_ivas->hBinRendererTd->Sources[c_indx]->InputFrame_p = tc_local[nS]; -#ifdef FIXED_CODE_WIP st_ivas->hBinRendererTd->Sources[c_indx]->InputFrame_p_fx = tc_local_fx[nS]; -#endif + st_ivas->hBinRendererTd->Sources[c_indx]->InputFrame_p_q = q_factor; st_ivas->hBinRendererTd->Sources[c_indx]->SrcRend_p->InputAvailable = TRUE; move16(); c_indx = add(c_indx, 1); } } + IF ( EQ_16( subframe_idx, ism_md_subframe_update_jbm ) ) { -#ifdef FIXED_CODE_WIP - if (st_ivas->hBinRendererTd != NULL) - { - st_ivas->hBinRendererTd->DirAtten_p->ConeInnerAngle_fx = float_to_fix(st_ivas->hBinRendererTd->DirAtten_p->ConeInnerAngle, Q22); - st_ivas->hBinRendererTd->DirAtten_p->ConeOuterAngle_fx = float_to_fix(st_ivas->hBinRendererTd->DirAtten_p->ConeOuterAngle, Q22); - st_ivas->hBinRendererTd->DirAtten_p->ConeOuterGain_fx = float_to_fix(st_ivas->hBinRendererTd->DirAtten_p->ConeOuterGain, Q30); - IF(st_ivas->ivas_format == ISM_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) - { - FOR(int nS1 = 0; nS1 < nchan_ism; nS1++) - { - st_ivas->hIsmMetaData[nS1]->radius_fx = float_to_fix16(st_ivas->hIsmMetaData[nS1]->radius, Q9); - st_ivas->hIsmMetaData[nS1]->azimuth_fx = float_to_fix(st_ivas->hIsmMetaData[nS1]->azimuth, Q22); - st_ivas->hIsmMetaData[nS1]->elevation_fx = float_to_fix(st_ivas->hIsmMetaData[nS1]->elevation, Q22); - st_ivas->hIsmMetaData[nS1]->yaw_fx = float_to_fix(st_ivas->hIsmMetaData[nS1]->yaw, Q22); - st_ivas->hIsmMetaData[nS1]->pitch_fx = float_to_fix(st_ivas->hIsmMetaData[nS1]->pitch, Q22); - } - } - } - IF ( ( error = TDREND_Update_object_positions_fx( st_ivas->hBinRendererTd, nchan_ism, st_ivas->ivas_format, st_ivas->hIsmMetaData ) ) != IVAS_ERR_OK ) { return error; } - - // Fixed to float // - if (st_ivas->hBinRendererTd != NULL) - { - IF(st_ivas->ivas_format == ISM_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) - { - FOR(int nS1 = 0; nS1 < nchan_ism; nS1++) - { - st_ivas->hBinRendererTd->Sources[nS1]->SrcSpatial_p->DirAtten.ConeInnerAngle = fix_to_float(st_ivas->hBinRendererTd->Sources[nS1]->SrcSpatial_p->DirAtten.ConeInnerAngle_fx, Q22); - st_ivas->hBinRendererTd->Sources[nS1]->SrcSpatial_p->DirAtten.ConeOuterAngle = fix_to_float(st_ivas->hBinRendererTd->Sources[nS1]->SrcSpatial_p->DirAtten.ConeOuterAngle_fx, Q22); - st_ivas->hBinRendererTd->Sources[nS1]->SrcSpatial_p->DirAtten.ConeOuterGain = fix_to_float(st_ivas->hBinRendererTd->Sources[nS1]->SrcSpatial_p->DirAtten.ConeOuterGain_fx, Q30); - FOR(int i = 0; i < 3; i++) - { - st_ivas->hBinRendererTd->Sources[nS1]->SrcSpatial_p->Pos_p[i] = fix_to_float(st_ivas->hBinRendererTd->Sources[nS1]->SrcSpatial_p->Pos_p_fx[i], Q25 ); - st_ivas->hBinRendererTd->Sources[nS1]->SrcSpatial_p->Front_p[i] = fix_to_float(st_ivas->hBinRendererTd->Sources[nS1]->SrcSpatial_p->Front_p_fx[i], Q30 ); // This is actually a normalised vector. can be scaled to Q14 (since it includes 1.0f) - } - } - } - } -#else - IF ( ( error = TDREND_Update_object_positions( st_ivas->hBinRendererTd, nchan_ism, st_ivas->ivas_format, st_ivas->hIsmMetaData ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif } /* Update the listener's location/orientation */ -#ifdef FIXED_CODE_WIP - IVAS_QUATERNION *tmp_Quaternion_fx; - IVAS_QUATERNION *tmp_Quaternion; - IVAS_VECTOR3 *tmp_vector_fx; - IVAS_VECTOR3 *tmp_vector; - Word16 enableCombinedOrientation = 0; - /////////////////////////////////////////// Float to fixed starts here /////////////////////////////////////////// - if (st_ivas->hCombinedOrientationData != NULL) + IF( st_ivas->hCombinedOrientationData != NULL ) { - // For Quaternion - tmp_Quaternion = &st_ivas->hCombinedOrientationData->Quaternions[st_ivas->hCombinedOrientationData->subframe_idx]; - tmp_Quaternion_fx = &st_ivas->hCombinedOrientationData->Quaternions_fx[st_ivas->hCombinedOrientationData->subframe_idx]; - float max_val = 0; - max_val = (float)max(max_val, fabs(tmp_Quaternion->w)); - max_val = (float)max(max_val, fabs(tmp_Quaternion->x)); - max_val = (float)max(max_val, fabs(tmp_Quaternion->y)); - max_val = (float)max(max_val, fabs(tmp_Quaternion->z)); - Word16 quat_q = Q_factor_L(max_val); - tmp_Quaternion_fx->w_fx = (Word32)float_to_fix(tmp_Quaternion->w, quat_q); - tmp_Quaternion_fx->x_fx = (Word32)float_to_fix(tmp_Quaternion->x, quat_q); - tmp_Quaternion_fx->y_fx = (Word32)float_to_fix(tmp_Quaternion->y, quat_q); - tmp_Quaternion_fx->z_fx = (Word32)float_to_fix(tmp_Quaternion->z, quat_q); - tmp_Quaternion_fx->w_qfact = tmp_Quaternion_fx->x_qfact = tmp_Quaternion_fx->y_qfact = tmp_Quaternion_fx->z_qfact = quat_q; - // For Vector - tmp_vector = &st_ivas->hCombinedOrientationData->listenerPos[st_ivas->hCombinedOrientationData->subframe_idx]; - tmp_vector_fx = &st_ivas->hCombinedOrientationData->listenerPos_fx[st_ivas->hCombinedOrientationData->subframe_idx]; - Word16 pos_q = Q25; - tmp_vector_fx->x_fx = (Word32)float_to_fix(tmp_vector->x, pos_q); - tmp_vector_fx->y_fx = (Word32)float_to_fix(tmp_vector->y, pos_q); - tmp_vector_fx->z_fx = (Word32)float_to_fix(tmp_vector->z, pos_q); - tmp_vector_fx->x_qfact = tmp_vector_fx->y_qfact = tmp_vector_fx->z_qfact = pos_q; - // For enableCombinedOrientation + tmp_Quaternion_fx = &st_ivas->hCombinedOrientationData->Quaternions[st_ivas->hCombinedOrientationData->subframe_idx]; + tmp_vector_fx = &st_ivas->hCombinedOrientationData->listenerPos[st_ivas->hCombinedOrientationData->subframe_idx]; enableCombinedOrientation = st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx]; - } - for (int i = 0; i < 3; i++) - { - //st_ivas->hBinRendererTd->Listener_p->Front_fx[i] = float_to_fix(st_ivas->hBinRendererTd->Listener_p->Front[i], Q30); - //st_ivas->hBinRendererTd->Listener_p->Up_fx[i] = float_to_fix(st_ivas->hBinRendererTd->Listener_p->Up[i], Q30); - //st_ivas->hBinRendererTd->Listener_p->Right_fx[i] = float_to_fix(st_ivas->hBinRendererTd->Listener_p->Right[i], Q30); - st_ivas->hBinRendererTd->Listener_p->Pos_q = Q25; - st_ivas->hBinRendererTd->Listener_p->Pos_fx[i] = float_to_fix(st_ivas->hBinRendererTd->Listener_p->Pos[i], st_ivas->hBinRendererTd->Listener_p->Pos_q); - } - /////////////////////////////////////////// Float to fixed ends here /////////////////////////////////////////// + /* Shifting w_fx, x_fx, y_fx, z_fx to a common Q-factor if they are not having the same Q-factor */ + Word16 min_q; + IF ( !( EQ_16( tmp_Quaternion_fx->w_qfact, tmp_Quaternion_fx->x_qfact ) + && EQ_16( tmp_Quaternion_fx->x_qfact, tmp_Quaternion_fx->y_qfact ) + && EQ_16( tmp_Quaternion_fx->y_qfact, tmp_Quaternion_fx->z_qfact ) ) ) + { + min_q = MAX16B; + move16(); + min_q = s_min( min_q, tmp_Quaternion_fx->w_qfact ); + min_q = s_min( min_q, tmp_Quaternion_fx->x_qfact ); + min_q = s_min( min_q, tmp_Quaternion_fx->y_qfact ); + min_q = s_min( min_q, tmp_Quaternion_fx->z_qfact ); + tmp_Quaternion_fx->w_fx = L_shr( tmp_Quaternion_fx->w_fx, sub( tmp_Quaternion_fx->w_qfact, min_q ) ); + tmp_Quaternion_fx->x_fx = L_shr( tmp_Quaternion_fx->x_fx, sub( tmp_Quaternion_fx->x_qfact, min_q ) ); + tmp_Quaternion_fx->y_fx = L_shr( tmp_Quaternion_fx->y_fx, sub( tmp_Quaternion_fx->y_qfact, min_q ) ); + tmp_Quaternion_fx->z_fx = L_shr( tmp_Quaternion_fx->z_fx, sub( tmp_Quaternion_fx->z_qfact, min_q ) ); + tmp_Quaternion_fx->w_qfact = min_q; + move16(); + tmp_Quaternion_fx->x_qfact = min_q; + move16(); + tmp_Quaternion_fx->y_qfact = min_q; + move16(); + tmp_Quaternion_fx->z_qfact = min_q; + move16(); + } - IF(st_ivas->hCombinedOrientationData != NULL) - { - tmp_Quaternion_fx = &st_ivas->hCombinedOrientationData->Quaternions_fx[st_ivas->hCombinedOrientationData->subframe_idx]; - tmp_vector_fx = &st_ivas->hCombinedOrientationData->listenerPos_fx[st_ivas->hCombinedOrientationData->subframe_idx]; - enableCombinedOrientation = st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx]; + /* Shifting x_fx, y_fx, z_fx to the same Q-factor as Listener_p->Pos_q (usually Q25) */ + Word16 pos_q = st_ivas->hBinRendererTd->Listener_p->Pos_q; + move16(); + IF( NE_16( tmp_vector_fx->x_qfact, pos_q ) || NE_16( tmp_vector_fx->z_qfact, pos_q ) || NE_16( tmp_vector_fx->y_qfact, pos_q ) ) + { + tmp_vector_fx->x_fx = L_shr( tmp_vector_fx->x_fx, sub( tmp_vector_fx->x_qfact, pos_q ) ); + tmp_vector_fx->y_fx = L_shr( tmp_vector_fx->y_fx, sub( tmp_vector_fx->y_qfact, pos_q ) ); + tmp_vector_fx->z_fx = L_shr( tmp_vector_fx->z_fx, sub( tmp_vector_fx->z_qfact, pos_q ) ); + tmp_vector_fx->x_qfact = pos_q; + move16(); + tmp_vector_fx->y_qfact = pos_q; + move16(); + tmp_vector_fx->z_qfact = pos_q; + move16(); + } } ELSE { tmp_Quaternion_fx = NULL; tmp_vector_fx = NULL; enableCombinedOrientation = 0; + move16(); } - if ( ( error = TDREND_Update_listener_orientation_fx( st_ivas->hBinRendererTd, + IF ( ( error = TDREND_Update_listener_orientation_fx( st_ivas->hBinRendererTd, enableCombinedOrientation, tmp_Quaternion_fx, tmp_vector_fx ) ) != IVAS_ERR_OK ) @@ -603,131 +534,37 @@ ivas_error ivas_td_binaural_renderer_sf_fx( return error; } - /////////////////////////////////////////// Fixed to float starts here /////////////////////////////////////////// - for (int i = 0; i < 3; i++) + IF ( st_ivas->hRenderConfig != NULL && st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { - st_ivas->hBinRendererTd->Listener_p->Front[i] = fix_to_float(st_ivas->hBinRendererTd->Listener_p->Front_fx[i], Q30); - st_ivas->hBinRendererTd->Listener_p->Up[i] = fix_to_float(st_ivas->hBinRendererTd->Listener_p->Up_fx[i], Q30); - st_ivas->hBinRendererTd->Listener_p->Right[i] = fix_to_float(st_ivas->hBinRendererTd->Listener_p->Right_fx[i], Q30); - st_ivas->hBinRendererTd->Listener_p->Pos[i] = fix_to_float(st_ivas->hBinRendererTd->Listener_p->Pos_fx[i], st_ivas->hBinRendererTd->Listener_p->Pos_q); - } - /////////////////////////////////////////// Fixed to float ends here ///////////////////////////////////////////// -#else - if ( ( error = TDREND_Update_listener_orientation( st_ivas->hBinRendererTd, - ( st_ivas->hCombinedOrientationData != NULL ) ? st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] : 0, - ( st_ivas->hCombinedOrientationData != NULL ) ? &st_ivas->hCombinedOrientationData->Quaternions[st_ivas->hCombinedOrientationData->subframe_idx] : NULL, - ( st_ivas->hCombinedOrientationData != NULL ) ? &st_ivas->hCombinedOrientationData->listenerPos[st_ivas->hCombinedOrientationData->subframe_idx] : NULL ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif - - if ( st_ivas->hRenderConfig != NULL && st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) - { -#ifdef IVAS_FLOAT_FIXED - Word16 i,j,exp; - Word32 pcm_in_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - Word32 pcm_out_buff[BINAURAL_CHANNELS][L_FRAME48k]; - Word32 *pcm_in_fx[MAX_OUTPUT_CHANNELS]; - Word32 *pcm_out_fx[BINAURAL_CHANNELS]; - Word16 nchan_transport = audioCfg2channels( st_ivas->transport_config ); - REVERB_HANDLE hReverb = st_ivas->hReverb; - exp = Q7; - for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - pcm_in_fx[i] = pcm_in_buff[i]; - } - for ( i = 0; i < nchan_transport; i++ ) - { - - for ( j = 0; j < ( ( 0 + 1 ) * hReverb->full_block_size ); j++ ) - { - - pcm_in_fx[i][j] = (Word32) float_to_fixed( tc_local[i][j], exp ); - } - } - for ( i = 0; i < BINAURAL_CHANNELS; i++ ) - { - pcm_out_fx[i] = pcm_out_buff[i]; - } - for ( i = 0; i < BINAURAL_CHANNELS; i++ ) - { - - for ( j = 0; j < ( hReverb->full_block_size ); j++ ) - { - pcm_out_fx[i][0 * hReverb->full_block_size + j] = (Word32) float_to_fixed( p_reverb_signal[i][0 * hReverb->full_block_size + j], ( exp ) ); - } - } - - if ( ( error = ivas_reverb_process_fx( st_ivas->hReverb, st_ivas->transport_config, 0, pcm_in_fx, pcm_out_fx, 0 ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_reverb_process( st_ivas->hReverb, st_ivas->transport_config, 0, tc_local, p_reverb_signal, 0 ) ) != IVAS_ERR_OK ) -#endif + IF ( ( error = ivas_reverb_process_fx( st_ivas->hReverb, st_ivas->transport_config, 0, tc_local_fx, p_reverb_signal_fx, 0 ) ) != IVAS_ERR_OK ) { return error; } -#ifdef IVAS_FLOAT_FIXED - for ( i = 0; i < BINAURAL_CHANNELS; i++ ) - { - - for ( j = 0; j < ( hReverb->full_block_size ); j++ ) - { - - p_reverb_signal[i][0 * hReverb->full_block_size + j] = fixed_to_float( pcm_out_fx[i][0 * hReverb->full_block_size + j], ( exp - 2 ) ); - } - } -#endif } /* Render subframe */ /* ism_md_subframe_update_jbm != subframe_idx: trigger update only for ism_md_subframe_update_jbm == subframe_idx, where then the two TDREND_GetMix()-arguments subframe_idx and ism_md_subframe_update are equal, and we want to enforce the update inside TDREND_GetMix to use subframe_idx == 0 */ -#ifdef IVAS_FLOAT_FIXED - ////// Float to fix ///// - Word16 sf_idx = 0; - FOR(Word16 i = 0; i < st_ivas->hBinRendererTd->NumOfSrcs; i++) - { - FOR (int j = 0; j < 3; j++) - { - st_ivas->hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p_fx[j] = float_to_fix(st_ivas->hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p[j], Q25); - } - st_ivas->hBinRendererTd->Sources[i]->InputFrame_p_q = Q11; - FOR (int j = 0; j < output_frame; j++) - { - st_ivas->hBinRendererTd->Sources[i]->InputFrame_p_fx[j] = - float_to_fix(st_ivas->hBinRendererTd->Sources[i]->InputFrame_p[j], st_ivas->hBinRendererTd->Sources[i]->InputFrame_p_q); - } - } IF ( ( error = TDREND_GetMix_fx( st_ivas->hBinRendererTd, output_fx_local, output_frame, 0, ism_md_subframe_update_jbm != subframe_idx ) ) != IVAS_ERR_OK ) { return error; } - /////// Fix to float //////// - me2f_buf(output_fx_local[0], 31 - Q11, output_f_local[0], (sf_idx + 1)*output_frame); - me2f_buf(output_fx_local[1], 31 - Q11, output_f_local[1], (sf_idx + 1)*output_frame); -#else - if ( ( error = TDREND_GetMix( st_ivas->hBinRendererTd, output_f_local, output_frame, 0, ism_md_subframe_update_jbm != subframe_idx ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif - if ( st_ivas->hRenderConfig != NULL && st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + IF ( st_ivas->hRenderConfig != NULL && st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { /* add reverb to rendered signals */ - v_add( reverb_signal[0], output_f_local[0], output_f_local[0], output_frame ); - v_add( reverb_signal[1], output_f_local[1], output_f_local[1], output_frame ); + v_add_32( reverb_signal_fx[0], output_fx_local[0], output_fx_local[0], output_frame ); + v_add_32( reverb_signal_fx[1], output_fx_local[1], output_fx_local[1], output_frame ); } - - for ( ch = 0; ch < nchan_ism_internal; ch++ ) + FOR ( ch = 0; ch < nchan_ism_internal; ch++ ) { - tc_local[ch] += output_frame; + tc_local_fx[ch] += output_frame; } - for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) + FOR ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) { - output_f_local[ch] += output_frame; + output_fx_local[ch] += output_frame; } /* update combined orientation access index */ @@ -735,16 +572,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( } st_ivas->hTcBuffer->subframes_rendered = last_sf; - -#ifdef FIXED_CODE_WIP - for (int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++) - { - for (int j = 0; j < L_FRAME48k; j++) - { - output[i][j] = fixedToFloat(floatToFixed(output[i][j], Q11),Q11); - } - } -#endif + move16(); return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index e57d0325c01e205515e08546726e4cc82a7926a0..dccf07af14c42f5e8ba85f765dd9ef034570e078 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -41,6 +41,9 @@ #include "wmc_auto.h" #include "ivas_prot_fx.h" #include "prot_fx2.h" +#ifdef IVAS_FLOAT_FIXED +#include "math.h" // temporary (for fabs) +#endif #define IVAS_FLOAT_FIXED_TO_BE_REMOVED @@ -417,10 +420,17 @@ ivas_error ivas_omasa_dec_config_fx( move32(); } brate_CPE = L_sub( ivas_total_brate, ism_total_brate ); +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, 1, 2, 0, brate_SCE, brate_CPE ) ) != IVAS_ERR_OK ) + { + return error; + } +#else IF( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, 1, 2, 0, brate_SCE, brate_CPE ) ) != IVAS_ERR_OK ) { return error; } +#endif IF ( NE_16(ism_mode_old, st_ivas->ism_mode) ) { @@ -673,10 +683,17 @@ ivas_error ivas_omasa_dec_config( ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; } +#ifdef IVAS_FLOAT_FIXED + IF ( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, 1, 2, 0, st_ivas->nSCE > 0 ? sep_object_brate[k - 2][st_ivas->nSCE - 1] : 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, 1, 2, 0, st_ivas->nSCE > 0 ? sep_object_brate[k - 2][st_ivas->nSCE - 1] : 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) { return error; } +#endif // IVAS_FLOAT_FIXED if ( ism_mode_old != st_ivas->ism_mode ) { @@ -1291,15 +1308,11 @@ void ivas_omasa_dirac_rend_jbm( st_ivas->hMasaIsmData->delayBuffer_fx[ind1][ind2] = floatToFixed(st_ivas->hMasaIsmData->delayBuffer[ind1][ind2] , q_output); } } - FOR ( Word16 k = 0; k < st_ivas->hIsmRendererData->interpolator_length; k++ ) - { - st_ivas->hIsmRendererData->interpolator_fx[k] = (Word16)(st_ivas->hIsmRendererData->interpolator[k] * (1<<15)); - } FOR(Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++) { FOR(Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++) { - st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = (Word32)(st_ivas->hIsmRendererData->prev_gains[ind1][ind2] * (1 << 29)); + st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = L_shr(st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2], 1); // Q30 -> Q29 } } @@ -1319,7 +1332,7 @@ void ivas_omasa_dirac_rend_jbm( { FOR(Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++) { - st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float)(st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2]) / (float)(1 << 29); + st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = L_shl(st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2], 1); // Q29 -> Q30 } } IF( st_ivas->hDecoderConfig->Opt_tsm ) @@ -1339,10 +1352,6 @@ void ivas_omasa_dirac_rend_jbm( st_ivas->hMasaIsmData->delayBuffer[ind1][ind2] = fixedToFloat(st_ivas->hMasaIsmData->delayBuffer_fx[ind1][ind2], q_output); } } - FOR ( Word16 k = 0; k < st_ivas->hIsmRendererData->interpolator_length; k++ ) - { - st_ivas->hIsmRendererData->interpolator[k] = (float)st_ivas->hIsmRendererData->interpolator_fx[k] / (float)(1<<15); - } //dbgwrite2_txt(output_f[1],960,"../omasa_soutput_f.txt"); #else @@ -1410,10 +1419,41 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm( ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData ); #ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_sepobj, *nSamplesRendered ) ) != IVAS_ERR_OK ) +#if 1 /* TODO: remove float to fix conversions */ + Word16 q_factor = Q11; + Word32 rend_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; + Word32 *p_rend_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; + for (int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++) + { + p_rend_output_fx[i] = rend_output_fx[i]; + for (int j = 0; j < L_FRAME48k; j++) + { + p_rend_output_fx[i][j] = floatToFixed(p_sepobj[i][j], Q11); + } + } + Word16 n_tc; + if (st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) + n_tc = st_ivas->nchan_ism; + else + n_tc = st_ivas->hTcBuffer->nchan_transport_internal; + for (int ch = 0; ch < n_tc; ch++) + { + floatToFixed_arrL(st_ivas->hTcBuffer->tc[ch], st_ivas->hTcBuffer->tc_fx[ch], Q11, L_FRAME48k); + } +#endif + IF ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_rend_output_fx, q_factor, *nSamplesRendered ) ) != IVAS_ERR_OK ) { return error; } +#if 1 /* TODO: remove fixed to float conversions */ + for (int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++) + { + for (int j = 0; j < L_FRAME48k; j++) + { + p_sepobj[i][j] = fixedToFloat(p_rend_output_fx[i][j], Q11); + } + } +#endif #else if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_sepobj, *nSamplesRendered ) ) != IVAS_ERR_OK ) { diff --git a/lib_dec/ivas_osba_dec.c b/lib_dec/ivas_osba_dec.c index 98f3beee006a2f134899ce7145bd5c18637594c8..a223534ef550dfbc9bf5a676775b27f3ec90f663 100644 --- a/lib_dec/ivas_osba_dec.c +++ b/lib_dec/ivas_osba_dec.c @@ -41,6 +41,7 @@ #include "ivas_prot_fx.h" #ifdef IVAS_FLOAT_FIXED #include "prot_fx2.h" +#include "math.h" // temporary (for fabs) #endif // IVAS_FLOAT_FIXED @@ -144,24 +145,18 @@ ivas_error ivas_osba_dirac_td_binaural_jbm_fx( UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ Word32 *output_fx[], /* o : rendered time signal */ + const Word16 q_factor, /* i : q_factor of rendered time signal */ Word16 out_len/*Store the length of values in each channel*/ ) { Word16 n; ivas_error error; -#if 1/*TODO: To be removed when ivas_td_binaural_renderer_sf_fx is integerated*/ - float output_separated_objects[BINAURAL_CHANNELS][L_FRAME48k]; // VE2SB: TBV - float *p_sepobj[BINAURAL_CHANNELS]; -#endif Word32 output_separated_objects_fx[BINAURAL_CHANNELS][L_FRAME48k]; // VE2SB: TBV Word32 *p_sepobj_fx[BINAURAL_CHANNELS]; int16_t channel_offset; FOR ( n = 0; n < BINAURAL_CHANNELS; n++ ) { -#if 1/*TODO: To be removed when ivas_td_binaural_renderer_sf_fx is integerated*/ - p_sepobj[n] = &output_separated_objects[n][0]; -#endif p_sepobj_fx[n] = &output_separated_objects_fx[n][0]; } @@ -173,16 +168,11 @@ ivas_error ivas_osba_dirac_td_binaural_jbm_fx( return error; } - IF ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_sepobj, *nSamplesRendered ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_sepobj_fx, q_factor, *nSamplesRendered ) ) != IVAS_ERR_OK ) { return error; } -#if 1/*TODO: To be removed when ivas_td_binaural_renderer_sf_fx is integerated*/ - FOR ( n = 0; n < BINAURAL_CHANNELS; n++ ) - { - floatToFixed_arrL( p_sepobj[n], p_sepobj_fx[n], Q11, L_FRAME48k ); - } -#endif + FOR ( n = 0; n < BINAURAL_CHANNELS; n++ ) { Word16 i; @@ -222,24 +212,20 @@ ivas_error ivas_osba_dirac_td_binaural_jbm( return error; } + if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_sepobj, *nSamplesRendered ) ) != IVAS_ERR_OK ) + { + return error; + } -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_sepobj, *nSamplesRendered ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_sepobj, *nSamplesRendered ) ) != IVAS_ERR_OK ) -#endif + for ( n = 0; n < BINAURAL_CHANNELS; n++ ) + { + int16_t i; + for ( i = 0; i < nSamplesAsked; i++ ) { - return error; + output_f[n][i] = 0.5f * output_f[channel_offset + n][i] + 0.5f * p_sepobj[n][i]; } + } - for ( n = 0; n < BINAURAL_CHANNELS; n++ ) - { - int16_t i; - for ( i = 0; i < nSamplesAsked; i++ ) - { - output_f[n][i] = 0.5f * output_f[channel_offset + n][i] + 0.5f * p_sepobj[n][i]; - } - } return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_post_proc.c b/lib_dec/ivas_post_proc.c index 5e61a16e75ccb5ae349f14a80ae3405c85328fe0..0226e232b6e5f8d7a9e8a614eb1890bc1ce7b5e7 100644 --- a/lib_dec/ivas_post_proc.c +++ b/lib_dec/ivas_post_proc.c @@ -50,7 +50,7 @@ * - in CPE_DFT, post-processing on output channels * - in CPE_TD, post-processing on decoded channels before upmixing *-------------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void ivas_post_proc( SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -148,7 +148,7 @@ void ivas_post_proc( return; } - +#endif #ifdef IVAS_FLOAT_FIXED void ivas_post_proc_fx( SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ @@ -695,7 +695,7 @@ void stereo_dft_dec_core_switching_fx( return; } #endif - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void stereo_dft_dec_core_switching( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ float output[], /* i/o: synthesis @internal Fs */ @@ -1074,4 +1074,5 @@ void stereo_dft_dec_core_switching( } return; -} \ No newline at end of file +} +#endif diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 9fd193f193541c4d418d62b4e550940ea8db20f1..85871fdd596a21b7d3e44e93cccb12396fb89888 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -259,14 +259,6 @@ ivas_error ivas_sba_dec_reconfigure( { st_ivas->hIsmRendererData->interpolator_fx[ind1] = (Word16) L_min( 32767, floatToFixed( st_ivas->hIsmRendererData->interpolator_fx[ind1], 15 ) ); } - FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->gains[ind1][ind2] * ( 1 << 30 ) ); - st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->prev_gains[ind1][ind2] * ( 1 << 30 ) ); - } - } } FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { @@ -362,14 +354,23 @@ ivas_error ivas_sba_dec_reconfigure( } } } + Word16 n_tc; + if (st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) + n_tc = st_ivas->nchan_ism; + else + n_tc = st_ivas->hTcBuffer->nchan_transport_internal; + for (int ch = 0; ch < n_tc; ch++) + { + floatToFixed_arrL(st_ivas->hTcBuffer->tc[ch], st_ivas->hTcBuffer->tc_fx[ch], Q11, L_FRAME48k); + } #endif if ( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, granularity_new, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, st_ivas->mc_mode, ism_mode_old, nSamplesFlushed, data ) ) != IVAS_ERR_OK ) { return error; } #if 1 /*Fixed to float */ - IF ( hTcBuffer->tc_buffer ) - fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); + if ( hTcBuffer->tc_buffer ) + fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); IF( hSpar ) { FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) @@ -413,22 +414,6 @@ ivas_error ivas_sba_dec_reconfigure( } } } - - if ( st_ivas->hIsmRendererData ) - { - FOR( Word16 ind1 = 0; ind1 < st_ivas->hIsmRendererData->interpolator_len; ind1++ ) - { - st_ivas->hIsmRendererData->interpolator[ind1] = (float) ( st_ivas->hIsmRendererData->interpolator_fx[ind1] ) / (float) ( 1 << 15 ); - } - FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->gains_fx[ind1][ind2] ) / ( 1 << 30 ); - st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] ) / ( 1 << 30 ); - } - } - } FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { if ( st_ivas->hIsmMetaData[ind1] ) @@ -701,19 +686,6 @@ ivas_error ivas_sba_dec_reconfigure( { return error; } - FOR(Word16 ind = 0; ind < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind++) - { - st_ivas->hIsmRendererData->interpolator[ind] = (float)(st_ivas->hIsmRendererData->interpolator_fx[ind]) / (float)(1 << 15); - } - FOR(Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++) - { - FOR(Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++) - { - // q factors might be different. Here we are just initializing to zero - st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float)(st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2]) / (float)(1<<31); - st_ivas->hIsmRendererData->gains[ind1][ind2] = (float)(st_ivas->hIsmRendererData->gains_fx[ind1][ind2]) / (float)(1<<31); - } - } #else if ( ( error = ivas_ism_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) { @@ -785,10 +757,17 @@ ivas_error ivas_sba_dec_reconfigure( } } +#ifdef IVAS_FLOAT_FIXED + IF ( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) { return error; } +#endif /*-----------------------------------------------------------------* * HP20 memories diff --git a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c index f5d9b1442cd1792545b20d7f131cd545b0cae8ff..4bf0e880729d5ba1a9603b0ed29d363f8417958e 100644 --- a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c +++ b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c @@ -34,6 +34,7 @@ #include "options.h" #include "cnst.h" #include "ivas_cnst.h" +#include "prot_fx1.h" #include "prot_fx2.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" @@ -1260,6 +1261,13 @@ void ivas_sba_dirac_stereo_dec_fx( q_dft[0] = hCPE->hStereoDft->q_dft; q_dft[1] = hCPE->hStereoDft->q_dft; + Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), -( Q11 - hCPE->hStereoDft->q_dft ) ); + IF( hSCE != NULL ) + { + Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), -( Q11 - hCPE->hStereoDft->q_dft ) ); + hSCE->q_prev_hb_synth_fx = hCPE->hStereoDft->q_dft; + } + IF ( GT_16(st_ivas->nchan_transport, 1) && EQ_16(mcmasa, 0) ) { dtx_flag = 0; @@ -1362,6 +1370,13 @@ void ivas_sba_dirac_stereo_dec_fx( set_val_Word32( output[ch], 0, output_frame ); } + Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), ( Q11 - hCPE->hStereoDft->q_dft ) ); + IF( hSCE != NULL ) + { + Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), ( Q11 - hCPE->hStereoDft->q_dft ) ); + hSCE->q_prev_hb_synth_fx = Q11; + } + return; } #endif diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal.c index f67ea1874eae2935afbf6d3b7caf3e6733965fe1..5a872443a85678fd20b476025679adf78f497520 100644 --- a/lib_dec/ivas_sba_rendering_internal.c +++ b/lib_dec/ivas_sba_rendering_internal.c @@ -686,8 +686,13 @@ void ivas_ism2sba_sf( g2 = hIsmRendererData->interpolator + offset; tc = buffer_in[i] + offset; out = buffer_tmp[j]; +#ifdef IVAS_FLOAT_FIXED + gain = fix_to_float(hIsmRendererData->gains_fx[i][j], Q30); + prev_gain = fix_to_float(hIsmRendererData->prev_gains_fx[i][j], Q30); +#else gain = hIsmRendererData->gains[i][j]; prev_gain = hIsmRendererData->prev_gains[i][j]; +#endif for ( k = 0; k < n_samples_to_render; k++ ) { g1 = 1.0f - *g2; diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index b6dda3c230577b69fb8bc4154c1c95935a8a38a0..d49c292a8d98d4c18ba519d8a883179ace7e31f5 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -46,7 +46,7 @@ #include "ivas_prot_fx.h" #endif - +#ifndef IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* * ivas_sce_dec() * @@ -288,7 +288,7 @@ ivas_error ivas_sce_dec( return error; } -#ifndef IVAS_FLOAT_FIXED + /*------------------------------------------------------------------------- * create_sce_dec() * diff --git a/lib_dec/ivas_sce_dec_fx.c b/lib_dec/ivas_sce_dec_fx.c index 119c173c34a3dd26a04287b542f8f5fd7eec2e58..b73d9082fb6c1198a68c07ba9dac5740e82fdfc8 100644 --- a/lib_dec/ivas_sce_dec_fx.c +++ b/lib_dec/ivas_sce_dec_fx.c @@ -348,7 +348,7 @@ ivas_error create_sce_dec( hSCE->element_brate = element_brate; #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - set_f( hSCE->prev_hb_synth, 0.0f, NS2SA( st_ivas->hDecoderConfig->output_Fs, L_sub( IVAS_DEC_DELAY_NS, DELAY_BWE_TOTAL_NS ) ) ); + //set_f( hSCE->prev_hb_synth, 0.0f, NS2SA( st_ivas->hDecoderConfig->output_Fs, L_sub( IVAS_DEC_DELAY_NS, DELAY_BWE_TOTAL_NS ) ) ); #endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED set32_fx( hSCE->prev_hb_synth_fx, 0, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, L_sub( IVAS_DEC_DELAY_NS, DELAY_BWE_TOTAL_NS ) ) ); @@ -402,19 +402,7 @@ ivas_error create_sce_dec( } #ifdef IVAS_FLOAT_FIXED -#if 1 // Float To Fix conversions - floatToFixed_arr(st->hTdCngDec->shb_lpcCNG, st->hTdCngDec->shb_lpcCNG_fx, 15, LPC_SHB_ORDER + 1); - st->hTdCngDec->shb_cng_gain_fx_32 = floatToFixed(st->hTdCngDec->shb_cng_gain, 11); - //floatToFixed_arr(st->lsp_old, st->lsp_old_fx, 15, M); -#endif // Float to fix conversions - td_cng_dec_init_ivas_fx( st ); - -#if 1 // Fix to float conversions - st->hTdCngDec->shb_cng_ener = fix_to_float(st->hTdCngDec->shb_cng_ener_fx_32, 11); - fixedToFloat_arr(st->hTdCngDec->shb_lpcCNG_fx, st->hTdCngDec->shb_lpcCNG, 15, LPC_SHB_ORDER + 1); - st->hTdCngDec->shb_cng_gain = fix_to_float(st->hTdCngDec->shb_cng_gain_fx_32, 11); -#endif // Fix to float conversions #else td_cng_dec_init_flt( st ); #endif // IVAS_FLOAT_FIXED diff --git a/lib_dec/ivas_sns_dec.c b/lib_dec/ivas_sns_dec.c index 7b655edd167b8da71f8ea5478d08bb5fdf955307..fdc1a31de2a0febb92be18088f91ff675dfbe60b 100644 --- a/lib_dec/ivas_sns_dec.c +++ b/lib_dec/ivas_sns_dec.c @@ -40,6 +40,7 @@ #include #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * sns_1st_dec() * @@ -297,3 +298,4 @@ void dequantize_sns( return; } +#endif diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 12bf3e49978d2034d70202403edd615a033039de..94dd189973d0e66ff774e2791874f41307bfe4ba 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -1687,29 +1687,46 @@ static ivas_error ivas_spar_dec_MD( * * *-------------------------------------------------------------------*/ - -static float ivas_spar_get_cldfb_slot_gain( +static Word16 ivas_spar_get_cldfb_slot_gain_fx( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ const int16_t time_slot_idx, int16_t *time_slot_idx0, int16_t *time_slot_idx1, - float *weight_lowfreq ) + Word16 *weight_lowfreq_fx +) { - float weight; - float output_Fs, encfb_delay, decfb_delay; - float xfade_start_ns; + Word16 weight_fx; + Word32 encfb_delay_fx, decfb_delay_fx; + Word32 xfade_start_ns_fx; int16_t xfade_delay_subframes; int16_t i_hist; int16_t split_band; - *weight_lowfreq = hSpar->hFbMixer->cldfb_cross_fade[time_slot_idx]; + *weight_lowfreq_fx = hSpar->hFbMixer->cldfb_cross_fade_fx[time_slot_idx]; - output_Fs = (float) hDecoderConfig->output_Fs; - encfb_delay = IVAS_FB_ENC_DELAY_NS; - decfb_delay = IVAS_FB_DEC_DELAY_NS; - xfade_start_ns = hSpar->hFbMixer->cross_fade_start_offset / output_Fs * 1000000000.f - encfb_delay + decfb_delay * 0.5f; - xfade_delay_subframes = (int16_t) ( xfade_start_ns / ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ) ); + encfb_delay_fx = IVAS_FB_ENC_DELAY_NS; + decfb_delay_fx = IVAS_FB_DEC_DELAY_NS; + Word32 one_by_outfs = 0;//q15 + switch (hDecoderConfig->output_Fs) + { + case 16000: + one_by_outfs = 2048000000; + break; + case 32000: + one_by_outfs = 1024000000; + break; + case 48000: + one_by_outfs = 682666688; + break; + default: + assert(0); + } + + Word64 fade_start = (Word64)one_by_outfs * hSpar->hFbMixer->cross_fade_start_offset; + fade_start = W_shr(fade_start, 15); + xfade_start_ns_fx = ((Word32)fade_start - encfb_delay_fx + L_shr(decfb_delay_fx,1)); + xfade_delay_subframes = (int16_t) (xfade_start_ns_fx / ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ) ); i_hist = 4 - xfade_delay_subframes; split_band = SPAR_DIRAC_SPLIT_START_BAND; @@ -1718,11 +1735,30 @@ static float ivas_spar_get_cldfb_slot_gain( { if ( hSpar->i_subframe > 3 ) { - weight = (float) ( time_slot_idx % MAX_PARAM_SPATIAL_SUBFRAMES ) / (float) MAX_PARAM_SPATIAL_SUBFRAMES; + Word16 mod_res = time_slot_idx % MAX_PARAM_SPATIAL_SUBFRAMES; + switch (mod_res) + { + case 0: + weight_fx = 0; + break; + case 1: + weight_fx = 8191; + break; + case 2: + weight_fx = 16383; + break; + case 3: + weight_fx = 24575; + break; + default: + weight_fx = 0; + break; + + } } else { - weight = 0.0f; + weight_fx = 0; } *time_slot_idx0 = i_hist; *time_slot_idx1 = i_hist + 1; @@ -1732,12 +1768,63 @@ static float ivas_spar_get_cldfb_slot_gain( /* determine cross-fade gain for current frame Parameters*/ *time_slot_idx0 = hSpar->hFbMixer->cldfb_cross_fade_start; *time_slot_idx1 = hSpar->hFbMixer->cldfb_cross_fade_end; - weight = *weight_lowfreq; + weight_fx = *weight_lowfreq_fx; } - return weight; + return weight_fx; } +static float ivas_spar_get_cldfb_slot_gain( + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t time_slot_idx, + int16_t *time_slot_idx0, + int16_t *time_slot_idx1, + float *weight_lowfreq) +{ + float weight; + float output_Fs, encfb_delay, decfb_delay; + float xfade_start_ns; + int16_t xfade_delay_subframes; + int16_t i_hist; + int16_t split_band; + + *weight_lowfreq = hSpar->hFbMixer->cldfb_cross_fade[time_slot_idx]; + + output_Fs = (float)hDecoderConfig->output_Fs; + encfb_delay = IVAS_FB_ENC_DELAY_NS; + decfb_delay = IVAS_FB_DEC_DELAY_NS; + xfade_start_ns = hSpar->hFbMixer->cross_fade_start_offset / output_Fs * 1000000000.f - encfb_delay + decfb_delay * 0.5f; + xfade_delay_subframes = (int16_t)(xfade_start_ns / (FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES)); + + i_hist = 4 - xfade_delay_subframes; + split_band = SPAR_DIRAC_SPLIT_START_BAND; + + if (split_band < IVAS_MAX_NUM_BANDS) + { + if (hSpar->i_subframe > 3) + { + weight = (float)(time_slot_idx % MAX_PARAM_SPATIAL_SUBFRAMES) / (float)MAX_PARAM_SPATIAL_SUBFRAMES; + } + else + { + weight = 0.0f; + } + *time_slot_idx0 = i_hist; + *time_slot_idx1 = i_hist + 1; + } + else + { + /* determine cross-fade gain for current frame Parameters*/ + *time_slot_idx0 = hSpar->hFbMixer->cldfb_cross_fade_start; + *time_slot_idx1 = hSpar->hFbMixer->cldfb_cross_fade_end; + weight = *weight_lowfreq; + } + + return weight; +} + + /*-------------------------------------------------------------------* * ivas_spar_get_parameters() @@ -1745,20 +1832,22 @@ static float ivas_spar_get_cldfb_slot_gain( * *-------------------------------------------------------------------*/ -void ivas_spar_get_parameters( +void ivas_spar_get_parameters_fx( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ const int16_t ts, const int16_t num_ch_out, const int16_t num_ch_in, const int16_t num_spar_bands, - float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] ) + Word32 par_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] +) { int16_t spar_band, out_ch, in_ch; - float weight, weight_20ms; + Word16 weight_fx, weight_20ms_fx; int16_t ts0, ts1, split_band; - weight = ivas_spar_get_cldfb_slot_gain( hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms ); + //weight = ivas_spar_get_cldfb_slot_gain(hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms); + weight_fx = ivas_spar_get_cldfb_slot_gain_fx( hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms_fx); split_band = SPAR_DIRAC_SPLIT_START_BAND; for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) @@ -1774,13 +1863,15 @@ void ivas_spar_get_parameters( { if ( hSpar->i_subframe > 3 ) { - par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight ) * hSpar->hMdDec->mixer_mat_prev[ts0][out_ch][in_ch][spar_band] + - weight * hSpar->hMdDec->mixer_mat_prev[ts1][out_ch][in_ch][spar_band]; + + par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat(Mpy_32_16_1(hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], sub(MAX_WORD16, weight_fx)), + Mpy_32_16_1(hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx)); } else { - par_mat[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; + par_mat_fx[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band]; } + } } else @@ -1789,7 +1880,9 @@ void ivas_spar_get_parameters( { /* 20ms Transport channel reconstruction with matching encoder/decoder processing */ int16_t prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ - par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight_20ms ) * hSpar->hMdDec->mixer_mat_prev[prev_idx][out_ch][in_ch][spar_band] + weight_20ms * hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; + par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat(Mpy_32_16_1(hSpar->hMdDec->mixer_mat_prev_fx[prev_idx][out_ch][in_ch][spar_band], sub(MAX_WORD16, weight_20ms_fx)) + ,Mpy_32_16_1(hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band], weight_20ms_fx)); + } } } @@ -1798,6 +1891,59 @@ void ivas_spar_get_parameters( return; } +void ivas_spar_get_parameters( + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t ts, + const int16_t num_ch_out, + const int16_t num_ch_in, + const int16_t num_spar_bands, + float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]) +{ + int16_t spar_band, out_ch, in_ch; + float weight, weight_20ms; + int16_t ts0, ts1, split_band; + + weight = ivas_spar_get_cldfb_slot_gain(hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms); + + split_band = SPAR_DIRAC_SPLIT_START_BAND; + for (spar_band = 0; spar_band < num_spar_bands; spar_band++) + { + for (out_ch = 0; out_ch < num_ch_out; out_ch++) + { + if (split_band < IVAS_MAX_NUM_BANDS + /* 20ms cross-fade for Transport channels in all frequency bands */ + && (0 == ivas_is_res_channel(out_ch, hSpar->hMdDec->spar_md_cfg.nchan_transport)) /* sub-frame processing for missing channels in all frequency bands*/ + ) + { + for (in_ch = 0; in_ch < num_ch_in; in_ch++) + { + if (hSpar->i_subframe > 3) + { + par_mat[out_ch][in_ch][spar_band] = (1.0f - weight) * hSpar->hMdDec->mixer_mat_prev[ts0][out_ch][in_ch][spar_band] + + weight * hSpar->hMdDec->mixer_mat_prev[ts1][out_ch][in_ch][spar_band]; + } + else + { + par_mat[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; + } + } + } + else + { + for (in_ch = 0; in_ch < num_ch_in; in_ch++) + { + /* 20ms Transport channel reconstruction with matching encoder/decoder processing */ + int16_t prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ + par_mat[out_ch][in_ch][spar_band] = (1.0f - weight_20ms) * hSpar->hMdDec->mixer_mat_prev[prev_idx][out_ch][in_ch][spar_band] + weight_20ms * hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; + } + } + } + } + + return; +} + /*-------------------------------------------------------------------* * ivas_spar_get_skip_mat() diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index bcca73613a9d1f8737be5deef26eb81cc7d580f7..0db56ddccfb8f8b34be10e5e6bfb3dca155d967f 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -87,47 +87,53 @@ typedef struct stereo_dft_dec_data_struct int16_t NFFT; /* Size of DFT */ /*FFT*/ +#ifndef IVAS_FLOAT_FIXED const float *dft_trigo; const float *dft_trigo_12k8; const float *dft_trigo_16k; const float *dft_trigo_8k; +#endif int16_t dft_trigo_step; #ifdef IVAS_FLOAT_FIXED - Word32 ONE_NFFT; /* Size of DFT */ - const Word16 *dft_trigo_fx; - const Word16 *dft_trigo_12k8_fx; - const Word16 *dft_trigo_16k_fx; - const Word16 *dft_trigo_8k_fx; + Word32 ONE_NFFT; /* Size of DFT */ + const Word16 *dft_trigo_fx; /* Q15 */ + const Word16 *dft_trigo_12k8_fx; /* Q15 */ + const Word16 *dft_trigo_16k_fx; /* Q15 */ + const Word16 *dft_trigo_8k_fx; /* Q15 */ #endif int16_t dft32ms_ovl; /* Overlap size */ +#ifndef IVAS_FLOAT_FIXED const float *win32ms; /* DFT window */ const float *win32ms_12k8; /* DFT window */ const float *win32ms_16k; /* DFT window */ const float *win32ms_8k; /* DFT window */ -#ifdef IVAS_FLOAT_FIXED - const Word16 *win32ms_fx; /* DFT window */ - const Word16 *win32ms_12k8_fx; /* DFT window */ - const Word16 *win32ms_16k_fx; /* DFT window */ - const Word16 *win32ms_8k_fx; /* DFT window */ +#else + const Word16 *win32ms_fx; /* DFT window */ /* Q15 */ + const Word16 *win32ms_12k8_fx; /* DFT window */ /* Q15 */ + const Word16 *win32ms_16k_fx; /* DFT window */ /* Q15 */ + const Word16 *win32ms_8k_fx; /* DFT window */ /* Q15 */ #endif int16_t dft32ms_ovl2; /* Overlap2 size */ +#ifndef IVAS_FLOAT_FIXED const float *win232ms; /* DFT window */ const float *win232ms_12k8; /* DFT window */ const float *win232ms_16k; /* DFT window */ const float *win232ms_8k; /* DFT window */ -#ifdef IVAS_FLOAT_FIXED - const Word16 *win232ms_fx; /* DFT window */ - const Word16 *win232ms_12k8_fx; /* DFT window */ - const Word16 *win232ms_16k_fx; /* DFT window */ - const Word16 *win232ms_8k_fx; /* DFT window */ - const Word16 *win_8k_fx; /* DFT window residual */ +#else + const Word16 *win232ms_fx; /* DFT window */ /* Q15 */ + const Word16 *win232ms_12k8_fx; /* DFT window */ /* Q15 */ + const Word16 *win232ms_16k_fx; /* DFT window */ /* Q15 */ + const Word16 *win232ms_8k_fx; /* DFT window */ /* Q15 */ + const Word16 *win_8k_fx; /* DFT window residual */ /* Q15 */ #endif +#ifndef IVAS_FLOAT_FIXED const float *win_8k; /* DFT window residual */ +#endif /*Bands*/ int16_t band_res[STEREO_DFT_DEC_DFT_NB]; @@ -138,52 +144,61 @@ typedef struct stereo_dft_dec_data_struct int16_t prm_res[STEREO_DFT_DEC_DFT_NB]; /*Stereo parameters*/ +#ifndef IVAS_FLOAT_FIXED float side_gain[STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX]; -#ifdef IVAS_FLOAT_FIXED - Word32 side_gain_fx[STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX]; +#else + Word32 side_gain_fx[STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX]; /* Q31 */ #endif int16_t side_gain_flag_1; int16_t side_gain_flag_2; int16_t side_gain_index_previous[STEREO_DFT_BAND_MAX]; int16_t side_gain_index[STEREO_DFT_BAND_MAX]; +#ifndef IVAS_FLOAT_FIXED float gipd[STEREO_DFT_DEC_DFT_NB]; -#ifdef IVAS_FLOAT_FIXED - Word32 gipd_fx[STEREO_DFT_DEC_DFT_NB]; +#else + Word32 gipd_fx[STEREO_DFT_DEC_DFT_NB]; /* Q13 */ #endif int16_t no_ipd_flag; /* flag to indicate when no IPD gets used */ +#ifndef IVAS_FLOAT_FIXED float itd[STEREO_DFT_DEC_DFT_NB]; -#if 0 -#ifdef IVAS_FLOAT_FIXED - Word16 itd_fx[STEREO_DFT_DEC_DFT_NB]; -#endif #endif +#ifndef IVAS_FLOAT_FIXED float itd_xfade_step; float itd_xfade_target; +#endif int16_t itd_xfade_counter; +#ifndef IVAS_FLOAT_FIXED float itd_xfade_prev; +#endif int32_t last_active_element_brate; +#ifndef IVAS_FLOAT_FIXED float ipd_xfade_target; float ipd_xfade_step; +#endif int16_t ipd_xfade_counter; +#ifndef IVAS_FLOAT_FIXED float ipd_xfade_prev; +#endif /*residual prediction*/ int16_t res_pred_mode[STEREO_DFT_DEC_DFT_NB]; /* residual prediction mode: 0(off), 1(stereo filling only), 2(enhanced stereo filling) */ +#ifndef IVAS_FLOAT_FIXED float res_pred_gain[STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX]; /* prediction gain for the residual HFs */ +#endif #ifdef IVAS_FLOAT_FIXED - Word32 itd_fx[STEREO_DFT_DEC_DFT_NB]; + Word32 itd_fx[STEREO_DFT_DEC_DFT_NB]; /* Q15 */ - Word32 itd_xfade_step_fx; - Word32 itd_xfade_target_fx; - Word32 itd_xfade_prev_fx; + Word32 itd_xfade_step_fx; /* Q15 */ + Word32 itd_xfade_target_fx; /* Q15 */ + Word32 itd_xfade_prev_fx; /* Q15 */ - Word32 ipd_xfade_target_fx; - Word32 ipd_xfade_step_fx; - Word32 ipd_xfade_prev_fx; - Word32 res_pred_gain_fx[STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX]; /* prediction gain for the residual HFs */ + Word32 ipd_xfade_target_fx; /* Q13 */ + Word32 ipd_xfade_step_fx; /* Q13 */ + Word32 ipd_xfade_prev_fx; /* Q13 */ + Word32 res_pred_gain_fx[STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX]; /* prediction gain for the residual HFs */ /* Q31 */ #endif int16_t res_pred_band_min; /* Band min for prediction of residual */ float DFT_past_DMX[STEREO_DFT_PAST_MAX][STEREO_DFT32MS_N_32k]; /* Past DMX for residual prediction */ @@ -191,8 +206,10 @@ typedef struct stereo_dft_dec_data_struct int16_t res_pred_flag_0; int16_t res_pred_flag_1; int16_t res_pred_index_previous[STEREO_DFT_BAND_MAX]; +#ifndef IVAS_FLOAT_FIXED float past_res_pred_gain[STEREO_DFT_PAST_MAX][STEREO_DFT_BAND_MAX]; float res_gains_ind[2][2 * STEREO_DFT_BAND_MAX]; +#endif int16_t reverb_flag; int16_t nbands_respred; @@ -200,16 +217,20 @@ typedef struct stereo_dft_dec_data_struct /*residual coding*/ int16_t res_cod_mode[STEREO_DFT_DEC_DFT_NB]; /* mode from 0 (off) to 3 */ int16_t res_cod_band_max; /* Band max for coding of residual */ +#ifndef IVAS_FLOAT_FIXED float res_global_gain; +#endif int16_t res_cod_line_max; +#ifndef IVAS_FLOAT_FIXED float res_hb_nrg_mem; +#endif float bpf_error_signal_last; float bpf_error_ratio_mem; #ifdef IVAS_FLOAT_FIXED - Word32 DFT_past_DMX_fx[STEREO_DFT_PAST_MAX][STEREO_DFT32MS_N_32k]; /* Past DMX for residual prediction */ - Word32 past_res_pred_gain_fx[STEREO_DFT_PAST_MAX][STEREO_DFT_BAND_MAX]; - Word32 res_gains_ind_fx[2][2 * STEREO_DFT_BAND_MAX]; - Word32 res_hb_nrg_mem_fx; + Word32 DFT_past_DMX_fx[STEREO_DFT_PAST_MAX][STEREO_DFT32MS_N_32k]; /* Past DMX for residual prediction */ + Word32 past_res_pred_gain_fx[STEREO_DFT_PAST_MAX][STEREO_DFT_BAND_MAX]; /* Q31 */ + Word32 res_gains_ind_fx[2][2 * STEREO_DFT_BAND_MAX]; /* Q26 */ + Word32 res_hb_nrg_mem_fx; /* Q0 */ Word32 bpf_error_signal_last_fx; Word16 bpf_error_ratio_mem_fx; Word16 q_dft; @@ -217,7 +238,7 @@ typedef struct stereo_dft_dec_data_struct Word16 q_ap_delay_mem_fx; Word16 q_smoothed_nrg; Word16 q_DFT_past_DMX_fx[STEREO_DFT_PAST_MAX]; - Word32 res_global_gain_fx; + Word32 res_global_gain_fx; /* Q15 */ #endif // IVAS_FLOAT_FIXED float res_cod_mem[STEREO_DFT_OVL_8k]; float buff_LBTCX_mem[NS2SA( 16000, STEREO_DFT32MS_OVL_NS )]; @@ -227,7 +248,9 @@ typedef struct stereo_dft_dec_data_struct Word16 q_res_cod_mem_fx; #endif +#ifndef IVAS_FLOAT_FIXED float stab_fac_smooth_res; /* low-pass filtered stability factor */ +#endif BPF_DEC_HANDLE hBpf; TCX_LTP_DEC_HANDLE hTcxLtpDec; @@ -238,19 +261,21 @@ typedef struct stereo_dft_dec_data_struct float lt_pred_gain; float lt_pred_gain_variation; float lt_var_mean_ratio; +#ifndef IVAS_FLOAT_FIXED float stefi_short_gain; float stefi_long_gain; +#endif basic_allpass_t ap1, ap2, ap3; float ap_delay_mem[NS2SA( 16000, DELAY_BWE_TOTAL_NS )]; float ap_fade_mem[STEREO_DFT_ALLPASS_FADELEN_16k]; #ifdef IVAS_FLOAT_FIXED - Word16 stab_fac_smooth_res_fx; /* low-pass filtered stability factor */ + Word16 stab_fac_smooth_res_fx; /* low-pass filtered stability factor */ /* Q15 */ Word32 lt_pred_gain_fx; Word32 lt_pred_gain_variation_fx; Word32 lt_var_mean_ratio_fx; - Word16 stefi_short_gain_fx; - Word16 stefi_long_gain_fx; + Word16 stefi_short_gain_fx; /* Q15 */ + Word16 stefi_long_gain_fx; /* Q15 */ Word16 q_lt_pred_gain; Word32 ap_delay_mem_fx[NS2SA( 16000, DELAY_BWE_TOTAL_NS )]; Word32 ap_fade_mem_fx[STEREO_DFT_ALLPASS_FADELEN_16k]; @@ -258,8 +283,10 @@ typedef struct stereo_dft_dec_data_struct #endif int16_t ap_wasTransient; +#ifndef IVAS_FLOAT_FIXED float smooth_dmx_nrg[STEREO_DFT_BAND_MAX]; float smooth_res_nrg[STEREO_DFT_BAND_MAX]; +#endif int16_t core_hist[STEREO_DFT_CORE_HIST_MAX]; float hb_stefi_sig[L_FRAME48k + NS2SA( 48000, STEREO_DFT_TD_STEFI_DELAY_NS )]; int16_t hb_stefi_delay; @@ -267,8 +294,8 @@ typedef struct stereo_dft_dec_data_struct float hb_nrg_subr[STEREO_DFT_NBDIV]; float td_gain[STEREO_DFT_CORE_HIST_MAX]; #ifdef IVAS_FLOAT_FIXED - Word32 smooth_dmx_nrg_fx[STEREO_DFT_BAND_MAX]; - Word32 smooth_res_nrg_fx[STEREO_DFT_BAND_MAX]; + Word32 smooth_dmx_nrg_fx[STEREO_DFT_BAND_MAX]; /* Q(q_smoothed_nrg) */ + Word32 smooth_res_nrg_fx[STEREO_DFT_BAND_MAX]; /* Q(q_smoothed_nrg) */ Word32 td_gain_fx[STEREO_DFT_CORE_HIST_MAX]; #endif @@ -284,15 +311,19 @@ typedef struct stereo_dft_dec_data_struct #endif /* stereo DTX */ +#ifndef IVAS_FLOAT_FIXED float g_state[STEREO_DFT_BAND_MAX]; -#ifdef IVAS_FLOAT_FIXED - Word16 g_state_fx[STEREO_DFT_BAND_MAX]; +#else + Word16 g_state_fx[STEREO_DFT_BAND_MAX]; /* Q15 */ #endif int16_t frame_sid_nodata; int16_t frame_nodata; int16_t frame_sid; float scale; +#ifdef IVAS_FLOAT_FIXED + Word16 scale_fx; +#endif /* PLC on residual signal */ float res_mem[STEREO_DFT_RES_BW_MAX]; @@ -314,6 +345,7 @@ typedef struct stereo_dft_dec_data_struct Word16 q_smooth_buf_fx; Word16 q_hb_nrg; Word16 q_hb_nrg_subr; + Word16 q_res_mem; #endif int16_t first_frame; @@ -445,22 +477,25 @@ typedef struct stereo_mdct_dec_data_structure int16_t use_itd; int16_t itd_mode; /*0/1*/ +#ifndef IVAS_FLOAT_FIXED float itd; -#ifdef IVAS_FLOAT_FIXED - Word32 itd_fx; +#else + Word32 itd_fx; /* Q15 */ #endif int16_t reverse_dmx; +#ifndef IVAS_FLOAT_FIXED float smooth_ratio; -#ifdef IVAS_FLOAT_FIXED - Word32 smooth_ratio_fx; +#else + Word32 smooth_ratio_fx; /* Q26 */ #endif int16_t prev_ms_mask[NB_DIV][MAX_SFB]; -#ifdef IVAS_FLOAT_FIXED - Word16 lastCoh_fx; -#endif +#ifndef IVAS_FLOAT_FIXED float lastCoh; +#else + Word16 lastCoh_fx; /* Q14 */ +#endif int16_t noise_seeds_channels[CPE_CHANNELS]; int16_t noise_seed_common; int16_t isSBAStereoMode; @@ -478,11 +513,12 @@ typedef struct stereo_tca_dec_data_structure int16_t prevRefChanIndx; /* reference channel index in previous frame */ int16_t indx_ica_NCShift; /* ICA target channel inter-channel corrstats */ int16_t indx_ica_gD; /* ICA target gain */ - float targetGain; /* gain norm applied on target (or right) channel in current frame */ +#ifndef IVAS_FLOAT_FIXED + float targetGain; /* gain norm applied on target (or right) channel in current frame */ float prevTargetGain; /* gain norm applied on target (or right) channel in previous frame */ -#ifdef IVAS_FLOAT_FIXED - Word32 targetGain_fx; // Q29 - Word32 prevTargetGain_fx; // Q29 +#else + Word32 targetGain_fx; /* gain norm applied on target (or right) channel in current frame */ // Q29 + Word32 prevTargetGain_fx; /* gain norm applied on target (or right) channel in previous frame */ // Q29 #endif int16_t corrLagStats; /* corr lag stats in current frame */ @@ -508,87 +544,92 @@ typedef struct stereo_tca_dec_data_structure typedef struct stereo_icbwe_dec_data_structure { - int16_t prev_refChanIndx_bwe; - int16_t refChanIndx_bwe; - int16_t prev_spIndx; - int16_t prev_gsIndx; + Word16 prev_refChanIndx_bwe; + Word16 refChanIndx_bwe; + Word16 prev_spIndx; + Word16 prev_gsIndx; /* SHB output memory */ +#ifndef IVAS_FLOAT_FIXED float memOutHB[CPE_CHANNELS][NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )]; float memTransitionHB[CPE_CHANNELS][NS2SA( 48000, STEREO_DFT32MS_OVL_NS )]; +#else + Word32 memOutHB_fx[CPE_CHANNELS][NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )]; /* Q11 */ -#ifdef IVAS_FLOAT_FIXED - Word32 memOutHB_fx[CPE_CHANNELS][NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS)]; - Word32 memTransitionHB_fx[CPE_CHANNELS][NS2SA(48000, STEREO_DFT32MS_OVL_NS)]; + Word32 memTransitionHB_fx[CPE_CHANNELS][NS2SA( 48000, STEREO_DFT32MS_OVL_NS )]; /* Q11 */ #endif + /* unscaled & scaled SHB synthesis memory */ +#ifndef IVAS_FLOAT_FIXED float mem_syn_shb_nonref[L_SHB_LAHEAD]; float mem_lpc_shbsynth_nonref[LPC_SHB_ORDER]; float mem_syn_shb_ola_nonref[L_SHB_LAHEAD]; -#ifdef IVAS_FLOAT_FIXED - Word32 mem_syn_shb_nonref_fx[L_SHB_LAHEAD]; - Word32 mem_lpc_shbsynth_nonref_fx[LPC_SHB_ORDER]; - Word32 mem_syn_shb_ola_nonref_fx[L_SHB_LAHEAD]; +#else + Word32 mem_syn_shb_nonref_fx[L_SHB_LAHEAD]; /* Q(prev_Q_syn_shb_nonref) */ + Word32 mem_lpc_shbsynth_nonref_fx[LPC_SHB_ORDER]; /* Q(prev_Q_lpc_shbsynth_nonref) */ + Word32 mem_syn_shb_ola_nonref_fx[L_SHB_LAHEAD]; /* Q(prev_Q_syn_shb_ola_nonref) */ Word16 prev_Q_syn_shb_nonref; - Word16 prev_Q_lpc_shbsynth; - Word16 prev_Q_syn_shb_ola; - + Word16 prev_Q_lpc_shbsynth_nonref; + Word16 prev_Q_syn_shb_ola_nonref; #endif /* inter-channel BWE spectral shape adj. */ +#ifndef IVAS_FLOAT_FIXED float prevSpecMapping; float memShbSpecMapping; float prevgsMapping; - -#ifdef IVAS_FLOAT_FIXED - Word16 prevSpecMapping_fx; - Word32 memShbSpecMapping_fx; - Word16 prevgsMapping_fx; +#else + Word16 prevSpecMapping_fx; /* Q15 */ + Word32 memShbSpecMapping_fx; /* Q(prev_Q_memshbspec) */ + Word16 prevgsMapping_fx; /* Q14 */ Word16 prev_Q_memshbspec; #endif +#ifndef IVAS_FLOAT_FIXED float memShbHilbert_nonref[HILBERT_MEM_SIZE]; float memShbInterp_nonref[2 * ALLPASSSECTIONS_STEEP + 1]; float memShb_fsout_nonref[INTERP_3_2_MEM_LEN]; -#ifdef IVAS_FLOAT_FIXED - Word32 memShbHilbert_nonref_fx[HILBERT_MEM_SIZE]; - Word32 memShbInterp_nonref_fx[2 * ALLPASSSECTIONS_STEEP + 1]; - Word32 memShb_fsout_nonref_fx[INTERP_3_2_MEM_LEN]; +#else + Word32 memShbHilbert_nonref_fx[HILBERT_MEM_SIZE]; /* Q(prev_Q_hilb) */ + Word32 memShbInterp_nonref_fx[2 * ALLPASSSECTIONS_STEEP + 1]; /* Q(prev_Q_interp) */ + Word32 memShb_fsout_nonref_fx[INTERP_3_2_MEM_LEN]; /* Q(prev_Q_fsout) */ - Word16 prev_Q_gen_syn; Word16 prev_Q_hilb; Word16 prev_Q_interp; Word16 prev_Q_fsout; - #endif - int16_t syn_dm_phase_nonref; + Word16 syn_dm_phase_nonref; + +#ifndef IVAS_FLOAT_FIXED float icbweM2Ref_prev; -#ifdef IVAS_FLOAT_FIXED - Word16 icbweM2Ref_prev_fx; +#else + Word16 icbweM2Ref_prev_fx; /* Q14 */ #endif + +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float nlExc16k[L_FRAME16k]; float mixExc16k[L_FRAME16k]; + float shbSynthRef[L_FRAME16k]; +#endif #ifdef IVAS_FLOAT_FIXED - Word16 nlExc16k_fx[L_FRAME16k]; - Word16 mixExc16k_fx[L_FRAME16k]; + Word16 nlExc16k_fx[L_FRAME16k]; /* Q(st->prev_Q_bwe_exc - 16) */ + Word16 mixExc16k_fx[L_FRAME16k]; /* Q(st->Q_exc) */ + Word16 shbSynthRef_fx[L_FRAME16k]; /* Q(st->prev_Qx) */ #endif - float shbSynthRef[L_FRAME16k]; - int16_t MSFlag; + Word16 MSFlag; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float lpSHBRef[LPC_SHB_ORDER + 1]; float gshapeRef[NUM_SHB_SUBFR]; -#ifdef IVAS_FLOAT_FIXED - Word16 shbSynthRef_fx[L_FRAME16k]; - Word32 lpSHBRef_fx[LPC_SHB_ORDER + 1]; - Word16 gshapeRef_fx[NUM_SHB_SUBFR]; -#endif - float gFrameRef; +#endif #ifdef IVAS_FLOAT_FIXED - Word32 gFrameRef_fx; + Word32 lpSHBRef_fx[LPC_SHB_ORDER + 1]; /* Q12 */ + Word16 gshapeRef_fx[NUM_SHB_SUBFR]; /* Q15 */ + Word32 gFrameRef_fx; /* Q18 */ #endif } STEREO_ICBWE_DEC_DATA, *STEREO_ICBWE_DEC_HANDLE; @@ -616,7 +657,7 @@ typedef struct param_ism_rendering { #ifdef IVAS_FLOAT_FIXED Word16 *proto_matrix_fx; - Word16 *interpolator_fx; + Word16 *interpolator_fx; /* Q15 */ Word32 *Cldfb_RealBuffer_tc_fx; Word16 *Cldfb_RealBuffer_tc_e; Word16 Cldfb_RealBuffer_tc_exp; @@ -629,8 +670,10 @@ typedef struct param_ism_rendering Word16 exp_mixing_matrix_lin_old_fx; #endif // IVAS_FLOAT_FIXED float *proto_matrix; +#ifndef IVAS_FLOAT_FIXED float *interpolator; float mixing_matrix_lin_old[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX]; +#endif float mixing_matrix_lin[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX]; float *Cldfb_RealBuffer_tc; float *Cldfb_ImagBuffer_tc; @@ -641,11 +684,12 @@ typedef struct param_ism_rendering typedef struct ivas_param_ism_dec_data_structure { /*Parameter decoding*/ +#ifndef IVAS_FLOAT_FIXED float azimuth_values[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; float elevation_values[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; -#ifdef IVAS_FLOAT_FIXED - Word32 azimuth_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; - Word32 elevation_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; +#else + Word32 azimuth_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; /* Q22 */ + Word32 elevation_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; /* Q22 */ Word16 power_ratios_fx[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS][MAX_PARAM_ISM_WAVE]; #endif // IVAS_FLOAT_FIXED float power_ratios[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS][MAX_PARAM_ISM_WAVE]; @@ -701,6 +745,14 @@ typedef struct dirac_output_synthesis_cov_state_structure float *mixing_matrix_res_old[CLDFB_NO_CHANNELS_MAX]; float *mixing_matrix[CLDFB_NO_CHANNELS_MAX]; float *mixing_matrix_res[CLDFB_NO_CHANNELS_MAX]; +#ifdef IVAS_FLOAT_FIXED + Word32 *cx_old_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 *cy_old_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 *mixing_matrix_old_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 *mixing_matrix_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 *mixing_matrix_res_old_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 *mixing_matrix_res_fx[CLDFB_NO_CHANNELS_MAX]; +#endif // IVAS_FLOAT_FIXED } DIRAC_OUTPUT_SYNTHESIS_COV_STATE; @@ -716,6 +768,9 @@ typedef struct ivas_param_mc_diff_proto_info_structure int16_t *num_source_chan_diff; int16_t **source_chan_idx; float **proto_fac; +#ifdef IVAS_FLOAT_FIXED + Word32 **proto_fac_fx; +#endif // IVAS_FLOAT_FIXED } PARAM_MC_DIFF_PROTO_INFO; @@ -753,6 +808,10 @@ typedef struct ivas_param_mc_dec_data_structure /*Decoder states=memories*/ float *proto_frame_f; float *proto_frame_dec_f; +#ifdef IVAS_FLOAT_FIXED + Word32 *proto_frame_dec_f_fx; + Word16 exp_proto_frame_dec_f; +#endif DIRAC_OUTPUT_SYNTHESIS_COV_STATE h_output_synthesis_cov_state; DIRAC_OUTPUT_SYNTHESIS_PARAMS h_output_synthesis_params; @@ -768,8 +827,11 @@ typedef struct ivas_param_mc_dec_data_structure float *ls_conv_dmx_matrix; float *proto_matrix_int; #ifdef IVAS_FLOAT_FIXED + Word32 *proto_frame_f_fx; + Word16 q_proto_frame_f; Word32 *ls_conv_dmx_matrix_fx; Word16 ls_conv_dmx_e; + Word32 *proto_matrix_int_fx; #endif /*sub-modules*/ @@ -956,9 +1018,9 @@ typedef struct sce_dec_data_structure /* core coder handle */ DEC_CORE_HANDLE hCoreCoder[1]; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_hb_synth[NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )]; /* HB synthesis synchro buffer */ - +#endif float *save_synth; float *save_hb_synth; @@ -989,8 +1051,9 @@ typedef struct cpe_dec_data_structure int16_t stereo_switching_counter; int16_t NbFrameMod; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float lt_es_em; - +#endif /* core coder handle */ DEC_CORE_HANDLE hCoreCoder[CPE_CHANNELS]; @@ -1004,8 +1067,10 @@ typedef struct cpe_dec_data_structure STEREO_CNG_DEC_HANDLE hStereoCng; /* Stereo CNG data structure */ int16_t nchan_out; /* number of output channels (1: mono dmx, 2: default stereo) */ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_hb_synth[CPE_CHANNELS][NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )]; + float *prev_synth_chs[CPE_CHANNELS]; +#endif float prev_synth[CPE_CHANNELS][NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS )]; /* DFT stereo I/O channel buffer memories that need to be updated for TD->DFT stereo switching */ @@ -1013,7 +1078,6 @@ typedef struct cpe_dec_data_structure float *input_mem_LB[CPE_CHANNELS]; float *input_mem_BPF[1]; float *output_mem[CPE_CHANNELS]; - float *prev_synth_chs[CPE_CHANNELS]; #ifdef IVAS_FLOAT_FIXED Word32 lt_es_em_fx;//24 @@ -1036,8 +1100,10 @@ typedef struct cpe_dec_data_structure #endif /* buffers used for fading between MDCT and DFT Stereo */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_out_mdct[STEREO_MDCT2DFT_FADE_LEN_48k]; float old_outLB_mdct[2 * STEREO_MDCT2DFT_FADE_LEN_48k]; +#endif int32_t brate_surplus; /* bitrate surplus for bitrate adaptation in combined format coding */ @@ -1228,10 +1294,10 @@ typedef struct ivas_masa_ism_data_structure #ifdef IVAS_FLOAT_FIXED Word32 **delayBuffer_fx; Word16 ismPreprocMatrix_fx[2][2][CLDFB_NO_CHANNELS_MAX]; - Word16 eneMoveIIR_fx[2][CLDFB_NO_CHANNELS_MAX]; - Word16 enePreserveIIR_fx[2][CLDFB_NO_CHANNELS_MAX]; - Word16 preprocEneTarget_fx[CLDFB_NO_CHANNELS_MAX]; - Word16 preprocEneRealized_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 eneMoveIIR_fx[2][CLDFB_NO_CHANNELS_MAX]; + Word32 enePreserveIIR_fx[2][CLDFB_NO_CHANNELS_MAX]; + Word32 preprocEneTarget_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 preprocEneRealized_fx[CLDFB_NO_CHANNELS_MAX]; #endif int16_t delayBuffer_size; diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index 352115551355a69f31f152b386581c8370b7ea87..baf805c908fc4e603911d6ae667548cbb6f8c5f2 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -49,15 +49,23 @@ *-------------------------------------------------------------------*/ #define A_GFILT 0.8f /* LP-filter coefficient for coherence and sidegain */ +#ifdef IVAS_FLOAT_FIXED +#define A_GFILT_FX (Word16)(0x6666) /* LP-filter coefficient for coherence and sidegain */ +#define ONE_MINUS_A_GFILT_FX (Word16)(0x199A) /* LP-filter coefficient for coherence and sidegain */ +#endif #define SKIP_XFADE_FRAMES 2 /* DTX/CNG */ #define MAX_K 50.0f +#define ONE_BY_MAX_K (Word16)(0x028F) #define STEREO_TD_PS_CORR_FILT 0.8f #define STEREO_TD_PS_CORR_FILT_FX 1717986918 #define STEREO_TD_PS_CORR_FILT_Q31 1717986944 #define ONE_MINUS_STEREO_TD_PS_CORR_FILT_Q31 429496704 #define MAX_XFADE 50.0f +#ifdef IVAS_FLOAT_FIXED +#define MAX_XFADE_FX 50 +#endif #define CM_INIT 50 #define CORR_INIT 8 #define SID_INIT 6 @@ -184,6 +192,7 @@ void stereo_dft_dec_sid_coh( } +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * stereo_dft_generate_comfort_noise() * @@ -602,10 +611,6 @@ static void stereo_dft_generate_comfort_noise( st->lp_noise_float = st->hFdCngDec->lp_noise_float; st->hFdCngDec->hFdCngCom->flag_noisy_speech = ( st->hFdCngDec->lp_speech_float - st->hFdCngDec->lp_noise_float ) < 28.f; st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt = 0.99f * st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt + 0.01f * st->hFdCngDec->hFdCngCom->flag_noisy_speech; -#ifdef IVAS_FLOAT_FIXED - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), - st->hFdCngDec->hFdCngCom->flag_noisy_speech * Q31_0_01); -#endif } if ( chan == 0 && st->core_brate <= SID_2k40 ) @@ -650,14 +655,748 @@ static void stereo_dft_generate_comfort_noise( pop_wmops(); return; } +#else +/*------------------------------------------------------------------- + * stereo_dft_generate_comfort_noise_fx() + * + * Generate the comfort noise based on the target noise level for the CLDFB part + *-------------------------------------------------------------------*/ + +static void stereo_dft_generate_comfort_noise_fx( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT Stereo decoder handle */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ + const Word16 last_element_mode, /* i : last element mode */ + Decoder_State *st, /* i/o: Core coder decoder state */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ + Decoder_State *st1, /* i/o: Core coder decoder state secondary channel */ + const Word16 targetGain, /* i : ICA target gain */ + const Word16 chan, /* i : channel number */ + const Word16 output_frame, /* i : output frame size */ + Word16 q_dft /* i : Q of DFT */ +) +{ + Word16 i, j, k; + Word32 *ptr_level, *ptr_shb, *ptr_r, *ptr_i; + HANDLE_FD_CNG_COM hFdCngCom; + Word16 numSlots; + Word16 scale, inv_scale, tmp_16; + Word32 lp_noise; + Word32 tmp, enr; + Word16 q_enr; + Word32 shb_shape[L_FRAME16k]; + Word16 q_shb_shape[L_FRAME16k]; + Word32 *ptr0, *ptr1, *ptr2; + Word16 *ptr_q_shb; + Word16 dmpf[M + 2], Atmp[M + 2]; + Word32 cngNoiseLevel_upd[L_FRAME16k], cngNoiseLevel_hist[L_FRAME16k - 2]; + Word32 *ptr_tmp, *ptr_cng; + Word32 E0, E1; + Word16 b, q_cngNoiseLevel_upd, q_cngNoiseLevel; + Word32 *pSideGain; + Word16 gamma; + Word16 c; + Word16 scaleMS; + Word16 scaleAvg; + Word16 LR_ratio; + Word16 factor; + Word16 alpha; + Word32 ftmp; + Word16 trigo_dec[STEREO_DFT32MS_N_16k / 2 + 1]; + const Word16 *pTrigo; + Word16 trigo_step; + Word16 addl_guard_bits; + + /* + * The additional guard bits data is added to tackle very small shb_cng_gain_fx_32. + * One additional guard bit is added for every 6dB post -12dB. + * -12dB in Q11 is (Word32)0xFFFFA000. + * The guard bits are calculated by converting the power of 10 exponent to power of 2 exponent. + */ + addl_guard_bits = s_max(1, shr(extract_l(L_shr(Mpy_32_16_1(L_sub((Word32)0xFFFFA000, st->hTdCngDec->shb_cng_gain_fx_32), (Word16)0x2A85), Q11)), 1)); + + move16(); + + hFdCngCom = st->hFdCngDec->hFdCngCom; + + push_wmops( "DFT_CNG" ); + + set_val_Word16( dmpf, 0, M + 2 ); + set_val_Word16( Atmp, 0, M + 2 ); + + set_val_Word32( DFT[chan], 0, STEREO_DFT_BUF_MAX ); + + enr = 0; /* Eliminates compiler warning. They are always set before they are used */ + move32(); + q_enr = 0; + move16(); + E0 = 0; + move32(); + E1 = 0; + move32(); + lp_noise = 0; + move32(); + q_cngNoiseLevel_upd = 0; + move16(); + q_cngNoiseLevel = 0; + move16(); + + IF( EQ_16( chan, 0 ) ) + { + pSideGain = hStereoDft->side_gain_fx + STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX; + FOR( b = 0; b < hStereoDft->nbands; b++ ) + { + IF( EQ_16( hStereoCng->xfade_frame_counter, 0 ) ) + { + hStereoDft->g_state_fx[b] = extract_h( *pSideGain++ ); + move16(); + } + ELSE + { + hStereoDft->g_state_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, extract_h( *pSideGain++ ) ), mult( A_GFILT_FX, hStereoDft->g_state_fx[b] ) ); + move16(); + } + + IF( hStereoCng->first_SID ) + { + IF( hStereoCng->first_SID_after_TD ) + { + hStereoCng->cm_fx[b] = extract_h( Mpy_32_32( hStereoCng->c_LR_LT_fx, hStereoCng->c_LR_LT_fx ) ); + move16(); + } + ELSE + { + hStereoCng->cm_fx[b] = hStereoCng->coh_fx[b]; + move16(); + } + } + ELSE IF( LT_16( hStereoCng->nr_dft_frames, CM_INIT ) && LT_16( hStereoCng->nr_sid_frames, SID_INIT ) ) + { + IF( GT_16( hStereoCng->nr_corr_frames, CORR_INIT ) ) + { + hStereoCng->cm_fx[b] = extract_h( Mpy_32_32( hStereoCng->c_LR_LT_fx, hStereoCng->c_LR_LT_fx ) ); + move16(); + } + ELSE + { + hStereoCng->cm_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), mult( A_GFILT_FX, hStereoCng->cm_fx[b] ) ); + move16(); + } + } + ELSE + { + hStereoCng->cm_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), mult( A_GFILT_FX, hStereoCng->cm_fx[b] ) ); + move16(); + } + } + + IF( hStereoCng->first_SID_after_TD ) + { + Word16 q_div, q_sqrt; + scaleAvg = 0; + move16(); + FOR( b = 0; b < hStereoDft->nbands; b++ ) + { + Word32 tmp_n, tmp_d; + Word16 sqrt_res; + IF( LT_16( hStereoCng->cm_fx[b], (Word32) ( 0x7333 ) ) ) + { + gamma = hStereoCng->cm_fx[b]; + move16(); + gamma = BASOP_Util_Divide1616_Scale( gamma, sub( MAX_16, gamma ), &q_div ); + tmp_16 = Sqrt16( gamma, &q_div ); + gamma = Sqrt16( add( gamma, sub( MAX_16, mult( hStereoDft->g_state_fx[b], hStereoDft->g_state_fx[b] ) ) ), &q_sqrt ); + gamma = shl( gamma, sub( q_sqrt, q_div ) ); // Bring both gamma and tmp to same Q i.e., q_div. + gamma = shl( sub( gamma, tmp_16 ), q_div ); // Apply appropriate left shift on the result. + } + ELSE + { + gamma = 0; + move16(); + } + + LR_ratio = extract_h( tdm_ratio_tabl_fx[hStereoCng->last_tdm_idx] ); + c = BASOP_Util_Divide3232_Scale( + L_add( L_mult( add( ONE_IN_Q13, shr( hStereoDft->g_state_fx[b], 2 ) ), + add( ONE_IN_Q13, shr( hStereoDft->g_state_fx[b], 2 ) ) ), + L_shr( L_mult( gamma, gamma ), 2 ) ), + L_add( Mpy_32_32( sub( ONE_IN_Q13, shr( hStereoDft->g_state_fx[b], 2 ) ), + sub( ONE_IN_Q13, shr( hStereoDft->g_state_fx[b], 2 ) ) ), + L_shr( L_mult( gamma, gamma ), 2 ) ), + &q_div ); + q_sqrt = q_div; + move16(); + sqrt_res = Sqrt16( mult( c, hStereoCng->cm_fx[b] ), &q_sqrt ); + // Add 1 to q_sqrt to account for multiplication with 2.0 in float computation. + q_sqrt = add( q_sqrt, 1 ); + tmp_n = L_add( L_add( L_shl( 1, sub( Q15, q_div ) ), c ), L_shr( L_deposit_l( sqrt_res ), sub( q_div, q_sqrt ) ) ); + q_sqrt = q_div; + move16(); + sqrt_res = Sqrt16( mult( c, hStereoCng->cm_fx[b] ), &q_sqrt ); + tmp_d = L_shl( L_add( L_shl( L_deposit_l( mult( c, mult( LR_ratio, LR_ratio ) ) ), q_div ), + L_add( mult( mult( sub( MAX_16, LR_ratio ), sub( MAX_16, LR_ratio ) ), mult( targetGain, targetGain ) ), + L_shl( L_deposit_l( mult( mult( LR_ratio, sub( MAX_16, LR_ratio ) ), mult( targetGain, sqrt_res ) ) ), add( 1, q_sqrt ) ) ) ), // add(1, q_sqrt) to account for multiplication with 2 and also to maintain uniform q. + 2 ); + scaleMS = BASOP_Util_Divide3232_Scale( tmp_n, tmp_d, &q_div ); + q_sqrt = q_div; + move16(); + scaleMS = Sqrt16( scaleMS, &q_sqrt ); + scaleAvg = add( scaleAvg, shr( scaleMS, sub( Q15, q_sqrt ) ) ); + } + scaleAvg = BASOP_Util_Divide1616_Scale( scaleAvg, hStereoDft->nbands, &q_div ); + hStereoDft->scale_fx = shl( scaleAvg, q_div ); + } + } + + IF( EQ_16( st->cng_type, LP_CNG ) ) + { + Word16 q_sqrt, q_div, q_inv_sqrt, rshift_shb = 0, rshift_cng; + Word32 min_val; + move16(); + set_val_Word32( cngNoiseLevel_upd, 0, st->L_frame ); + + /* Deemphasis */ + dmpf[0] = MAX_16; + move16(); + dmpf[1] = negate( st->preemph_fac ); + move16(); + Copy( st->Aq_cng, Atmp, M + 1 ); + conv_fx_32( Atmp, dmpf, cngNoiseLevel_upd, M + 2 ); + + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + pTrigo = hStereoDft->dft_trigo_12k8_fx; + trigo_step = STEREO_DFT_TRIGO_SRATE_12k8_STEP * STEREO_DFT_TRIGO_DEC_STEP; + move16(); + } + ELSE + { + pTrigo = hStereoDft->dft_trigo_16k_fx; + trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP * STEREO_DFT_TRIGO_DEC_STEP; + move16(); + } + + FOR( i = 0; i < shr( st->L_frame, 2 ); i++ ) + { + trigo_dec[i] = pTrigo[i * trigo_step]; + move16(); + trigo_dec[sub( shr( st->L_frame, 1 ), i )] = pTrigo[i * trigo_step]; + move16(); + } + trigo_dec[shr( st->L_frame, 2 )] = pTrigo[shr( st->L_frame, 2 ) * trigo_step]; + move16(); + + rshift_cng = getScaleFactor32(cngNoiseLevel_upd, st->L_frame); + rshift_cng = sub(find_guarded_bits_fx(st->L_frame), rshift_cng); + /* + * The guardbits calculated here are not sufficient for all cases. + * Due to the gain values like shb_cng_gain and other things in the ensuing code blocks, + * additional guard bits have to be added. The choice based on existing test vector set is Q2 + */ + rshift_cng = add(rshift_cng, addl_guard_bits); + v_shr_32(cngNoiseLevel_upd, cngNoiseLevel_upd, st->L_frame, rshift_cng); + // Input Q to fft will be Q30 - rshift. + rfft_fx( cngNoiseLevel_upd, trigo_dec, st->L_frame, -1 ); + // v_shr_32(cngNoiseLevel_upd, cngNoiseLevel_upd, st->L_frame, negate(rshift)); + + /* Compute 1/|A| */ + ptr0 = cngNoiseLevel_upd; + ptr1 = ptr0 + 2; + ptr2 = ptr1 + 1; + assert( st->lp_ener_fx > 0 ); + // lp_ener_fx will be in Q6 at this point. + // So applying appropriate left shift on the denominator. + factor = shr( BASOP_Util_Divide3232_Scale( st->lp_ener_fx, L_shl( st->L_frame, Q6 ), &q_div ), 1 ); /* fixed factor in the loop below */ + factor = Sqrt16( factor, &q_div ); + // there is multiplication with 2.0 that has to be applied on the factor and + // a left shift of q_div as shown in the below two steps. + // factor = shl(factor, add(q_div, 1)); + // q_div = 0; move16(); + // The left shift of q_div and 1 (because of multiplication factor 2.0) is handled below. + // by adjusting q_inv_sqrt. + minimum_abs32_fx( ptr0, st->L_frame, &min_val ); + q_inv_sqrt = sub( sub( Q31, norm_l( L_abs( min_val ) ) ), add( q_div, 1 ) ); + FOR( i = 0; i < shr( st->L_frame, 1 ) - 1; i++ ) + { + //if ((*ptr1 == 0) && (*ptr2 == 0)) + // assert(0); + //assert( (*ptr1 != 0) || (*ptr2 != 0)); + IF (norm_l(*ptr1) > rshift_cng && norm_l(*ptr2) > rshift_cng) + { + ftmp = Madd_32_32(Mpy_32_32(L_shl(*ptr1, rshift_cng) , L_shl(*ptr1, rshift_cng)) , L_shl(*ptr2, rshift_cng) , L_shl(*ptr2, rshift_cng)); + q_sqrt = Q2; + } + ELSE + { + ftmp = Madd_32_32(Mpy_32_32(*ptr1 , *ptr1) , *ptr2, *ptr2); + q_sqrt = sub(Q31, sub(shl(sub(Q30, rshift_cng), 1) , Q31)); + } + IF (EQ_32(ftmp , 0)) + { + ftmp = EPSILON_FX; move32(); + q_sqrt = s_max(0, q_sqrt); + } + tmp = ISqrt32(ftmp, &q_sqrt); + tmp = Mpy_32_16_1(tmp, factor); + tmp = L_shl(tmp, add(sub(sub(Q30, rshift_cng), sub(Q31, q_sqrt)), add(q_div, 1))); + *ptr0++ = tmp; move32(); + ptr1 += 2; + ptr2 += 2; + } + // q_div + 1 has to be added back to q_inv_sqrt. + q_cngNoiseLevel_upd = sub(Q30, rshift_cng); + + IF( GT_16( sub( s_min( output_frame, L_FRAME32k ), hFdCngCom->stopFFTbin ), 0 ) ) + { + /* Transform shb LP spectrum */ + set_val_Word32( shb_shape, 0, L_FRAME16k ); + set_val_Word16( q_shb_shape, 0, L_FRAME16k ); + Copy_Scale_sig_16_32( st->hTdCngDec->shb_lpcCNG_fx, shb_shape, LPC_SHB_ORDER + 1, Q15 ); + + IF( NE_16( st->L_frame, L_FRAME16k ) ) + { + pTrigo = hStereoDft->dft_trigo_16k_fx; + trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP * STEREO_DFT_TRIGO_DEC_STEP; + move16(); + FOR( i = 0; i < L_FRAME16k / 4; i++ ) + { + trigo_dec[i] = pTrigo[i * trigo_step]; + move16(); + trigo_dec[L_FRAME16k / 2 - i] = pTrigo[i * trigo_step]; + move16(); + } + trigo_dec[L_FRAME16k / 4] = pTrigo[L_FRAME16k / 4 * trigo_step]; + move16(); + } + + rshift_shb = getScaleFactor32(shb_shape, L_FRAME16k); + rshift_shb = sub(find_guarded_bits_fx(L_FRAME16k), rshift_shb); + /* + * The guardbits calculated here are not sufficient for all cases. + * Due to the gain values like shb_cng_gain and other things in the ensuing code blocks, + * additional guard bits have to be added. The choice based on existing test vector set is Q2 + */ + rshift_shb = add(rshift_shb, addl_guard_bits); + v_shr_32(shb_shape, shb_shape, L_FRAME16k, rshift_shb); + rfft_fx( shb_shape, trigo_dec, L_FRAME16k, -1 ); + // v_shr_32(shb_shape, shb_shape, L_FRAME16k, negate(rshift)); + + /* Compute 1/|A| */ + enr = Madd_32_32(Mpy_32_32(L_shl(shb_shape[0], addl_guard_bits), L_shl(shb_shape[0], addl_guard_bits)), + L_shl(shb_shape[1], addl_guard_bits) , L_shl(shb_shape[1], addl_guard_bits)); + q_enr = add(sub(shl(sub(Q30, rshift_shb), 1), Q31), shl(addl_guard_bits, 1)); + IF (EQ_32(enr , 0)) + { + enr = EPSILON_FX; move32(); + q_enr = s_max(0, q_enr); + } + ptr0 = shb_shape; + ptr1 = ptr0 + 2; + ptr2 = ptr1 + 1; + + FOR( i = 0; i < L_FRAME16k / 2 - 1; i++ ) + { + Word16 q_shift = sub(shl(sub(Q30, rshift_shb), 1), Q31); + //assert((*ptr1 != 0) || (*ptr2 != 0)); + ftmp = Madd_32_32( Mpy_32_32(L_shl(*ptr1, addl_guard_bits) , L_shl(*ptr1, addl_guard_bits)) , + L_shl(*ptr2, addl_guard_bits) , L_shl(*ptr2, addl_guard_bits)); + q_shift = add(q_shift, shl(addl_guard_bits, 1)) ; + IF(EQ_32(ftmp, 0)) + { + ftmp = EPSILON_FX; move32(); + q_shift = s_max(0, q_shift); + } + ftmp = L_deposit_l( BASOP_Util_Divide3232_Scale( L_sub( L_shl( Q1, q_shift ), 1 ), ftmp, &q_div ) ); + ftmp = L_shl( ftmp, sub( q_div, sub( Q15, q_shift ) ) ); + /* in float: + both a = "div"=(1/(x^2+y^2) and sqrt(a) is used and summed up in the same loop. + + in BASOP: + sum up using inv_sqrt( *ptr1 * *ptr1 + *ptr2 * *ptr2 ), in this loop + and then sum up enr = sum( *ptr0 * *ptr0 ), in a subsequent MAC loop */ + enr = L_add( enr, ftmp ); + q_div = sub( Q31, q_shift ); + ftmp = Sqrt32( ftmp, &q_div ); + // Reduce the Q of shb_shape back to its original Q i.e., Q30 - rshift + ftmp = L_shr(ftmp, sub(sub(Q31, q_div), sub(Q30, rshift_shb))); + *ptr0++ = ftmp; move32(); + ptr1 += 2; + ptr2 += 2; + } + } + + /* Update CNG noise level from MS noise estimation */ + Copy32( st->hFdCngDec->bandNoiseShape, cngNoiseLevel_hist, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); + ptr_cng = cngNoiseLevel_hist; + FOR( i = 0; i < shr( sub( st->last_L_frame, hFdCngCom->startBand ), 1 ); i++ ) + { + tmp = *( cngNoiseLevel_hist + i * 2 ); + move32(); + tmp = L_add( tmp, *( cngNoiseLevel_hist + i * 2 + 1 ) ); + *ptr_cng++ = L_shr( tmp, 1 ); + move32(); + } + + IF( last_element_mode == IVAS_CPE_TD && chan == 0 && hStereoCng->xfade_frame_counter == 0 && !( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) ) + { + ptr_cng = cngNoiseLevel_hist + hFdCngCom->startBand; + ptr_tmp = cngNoiseLevel_upd + hFdCngCom->startBand; + FOR( i = 0; i < shr( sub( st->last_L_frame, hFdCngCom->startBand ), 1 ); i++ ) + { + E0 = L_add( E0, *ptr_cng++ ); + E1 = Madd_32_32( E1, ( *ptr_tmp ), ( *ptr_tmp ) ); + ptr_tmp++; + } + + tmp_16 = BASOP_Util_Divide3232_Scale( E0, E1, &q_div ); + tmp_16 = Sqrt16( tmp_16, &q_div ); + IF( LT_16( tmp_16, shr( MAX_16, q_div ) ) ) + { + tmp_16 = shl( tmp_16, q_div ); + hStereoCng->xfade_length = sub( MAX_XFADE_FX, extract_l( L_shr( imult3216( MAX_XFADE_FX, tmp_16 ), Q15 ) ) ); + } + ELSE + { + Word16 q_inv; + tmp_16 = Invert16( tmp_16, &q_inv ); + tmp_16 = shl( tmp_16, add( q_inv, q_div ) ); + hStereoCng->xfade_length = sub( MAX_XFADE_FX, extract_l( L_shr( imult3216( MAX_XFADE_FX, tmp_16 ), Q15 ) ) ); + } + } + + IF( LT_16( hStereoCng->xfade_frame_counter, hStereoCng->xfade_length ) ) + { + ptr_cng = cngNoiseLevel_hist + hFdCngCom->startBand; + ptr_tmp = cngNoiseLevel_upd + hFdCngCom->startBand; + FOR( i = 0; i < ( st->last_L_frame - hFdCngCom->startBand ) / 2; i++ ) + { + tmp_16 = BASOP_Util_Divide1616_Scale( hStereoCng->xfade_frame_counter, hStereoCng->xfade_length, &q_div ); + tmp_16 = shl( tmp_16, q_div ); + tmp = Sqrt32( *ptr_cng++, &q_sqrt ); + tmp = L_shl( tmp, q_sqrt ); + *ptr_tmp = L_add( Mpy_32_16_1( *ptr_tmp, tmp_16 ), Mpy_32_16_1( Mpy_32_16_1( tmp, sub( MAX_16, tmp_16 ) ), hStereoDft->scale_fx ) ); + move32(); + ptr_tmp++; + } + } + + FOR( k = 0; k < STEREO_DFT_NBDIV; k++ ) + { + Word16 shift_val = sub( Q31, q_cngNoiseLevel_upd ); + /* low band */ + ptr_level = cngNoiseLevel_upd; + ptr_r = DFT[chan] + hFdCngCom->startBand + k * STEREO_DFT32MS_N_MAX; + ptr_i = ptr_r + 1; + scale = shr( output_frame, 1 ); + + FOR( i = 0; i < shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); i++ ) + { + /* Real part in FFT bins */ + rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft ); + // the Q factor of ptr_level is q_cngNoiseLevel_upd + // To ensure the result of the multiplication is with optimal precision + // apply left shift on the input data and use it for multiplication + // result of multiplication will be in same Q as ptr_r buffer + tmp = imult3216(( *ptr_r ), scale); + IF (GE_16(norm_l(tmp), shift_val)) + { + ( *ptr_r ) = Mpy_32_32(L_shl(tmp, shift_val), *ptr_level); move32(); + } + ELSE + { + ( *ptr_r ) = L_shl(Mpy_32_32(tmp, *ptr_level), shift_val); move32(); + } + ptr_r += 2; + /* Imaginary part in FFT bins */ + rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); + tmp = imult3216(( *ptr_i ) , scale); move32(); + IF (GE_16(norm_l(tmp), shift_val)) + { + ( *ptr_i ) = Mpy_32_32(L_shl(tmp, shift_val), *ptr_level); + } + ELSE + { + ( *ptr_i ) = L_shl(Mpy_32_32(tmp, *ptr_level), shift_val); + } + ptr_i += 2; + ptr_level++; + } + + IF( GT_16( sub( s_min( output_frame, L_FRAME32k ), hFdCngCom->stopFFTbin ), 0 ) ) + { + Word16 q_res = 0; + Word32 scale_32; + /* high band generation, flipped spectrum */ + assert( enr != 0 ); + // 10 ^ (0.1 * st->hTdCngDec->shb_cng_gain) + // Above expression equivalent to 2 ^ (3.321928094 * 0.1 * st->hTdCngDec->shb_cng_gain) + // 3.321928094 * 0.1 = 0.3321928094 + // st->hTdCngDec->shb_cng_gain_fx_32 Q is 11 + scale_32 = BASOP_util_Pow2( Mpy_32_16_1(st->hTdCngDec->shb_cng_gain_fx_32, (Word16)0x2A85), Q31 - Q11, &q_res); + //Q of scale_32 is Q31 - q_res, Q of enr is + //scale_32 = L_shl(scale_32, sub( q_enr, sub(Q31, q_res))); + q_div = 0; move16(); + scale = BASOP_Util_Divide3232_Scale( scale_32, enr, &q_div); + //q_res = add(q_div, sub( q_enr, sub(Q31, q_res))); move16(); + q_res = sub(Q15, add(sub(Q15, q_div), sub(sub(Q31, q_res), q_enr))); move16(); + //q_div = sub(Q15, q_res); move16(); + q_div = q_res; + inv_scale = ISqrt16( scale, &q_res); + scale = Sqrt16(scale, &q_div); + ptr_shb = shb_shape + L_FRAME16k / 2 - 1; + ptr_q_shb = q_shb_shape + L_FRAME16k / 2 - 1; + /* Averaging for Nyquist frequency */ + tmp = Mpy_32_16_1( cngNoiseLevel_upd[sub( shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ), 1 )], inv_scale ); + // q of cngNoiseLevel_upd is Q16. + // ptr_shb will be in Q30 - rshift. tmp is in Q16(Q15 + 1 (for the 0.5 in multiplication)) - q_res, Applying appropriate shift on tmp + q_res = sub(sub(Q30, rshift_cng), sub(Q16, q_res)); + IF (LT_16(q_res, norm_l(tmp))) + { + tmp = L_shl( tmp, q_res ); + q_res = 0; + move16(); + } + *ptr_q_shb = q_res; + move16(); + + // Bring both ptr_shb and ptr_shb - 1 to the same Q. + *ptr_shb = L_shr( L_add( tmp, L_shr( *( ptr_shb - 1 ), sub( q_res, *( ptr_q_shb - 1 ) ) ) ), 1 ); + move32(); + ptr_r = DFT[chan] + hFdCngCom->stopFFTbin + k * STEREO_DFT32MS_N_MAX; + ptr_i = ptr_r + 1; + + FOR( i = 0; i < ( min( output_frame, hFdCngCom->regularStopBand * 16 ) - hFdCngCom->stopFFTbin ) / 2; i++ ) + { + /* Real part in FFT bins */ + rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft); + //ptr_shb will be in Q30 - rshift at this point. So apply left shift by 1 to compensate Mpy_32_32 right shift.. + ( *ptr_r ) = L_shl(Mpy_32_32(L_shl(*ptr_r, add(1, *ptr_q_shb)), *ptr_shb), rshift_shb); move32(); + ptr_r += 2; + /* Imaginary part in FFT bins */ + rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft); + ( *ptr_i ) = L_shl(Mpy_32_32(L_shl(*ptr_i, add(1, *ptr_q_shb)), *ptr_shb), rshift_shb); move32(); + ptr_i += 2; + ptr_shb--; + } + + /* rescale */ + // scale = L_shr(imult3216(scale, output_frame) , 1); + // multiplication with shr(output_frame, 1) is carried out below. + ptr_r = DFT[chan] + hFdCngCom->stopFFTbin + k * STEREO_DFT32MS_N_MAX; + ptr_i = ptr_r + 1; + FOR( i = 0; i < shr( sub( s_min( output_frame, shl( hFdCngCom->regularStopBand, 4 ) ), hFdCngCom->stopFFTbin ), 1 ); i++ ) + { + ( *ptr_r ) = imult3216(L_shl(Mpy_32_16_1(*ptr_r, scale), q_div), shr(output_frame, 1)); + move32(); + ( *ptr_i ) = imult3216(L_shl(Mpy_32_16_1(*ptr_i, scale), q_div), shr(output_frame, 1)); + move32(); + ptr_r += 2; + ptr_i += 2; + } + } + } + + /* Expand cngNoiseLevel_flt from 0-159 to 0-318, compute noise level */ + lp_noise = 0; move32(); + ptr_level = hFdCngCom->cngNoiseLevel + sub(sub(hFdCngCom->stopFFTbin , hFdCngCom->startBand) , 1); + ptr_tmp = cngNoiseLevel_upd + sub(shr(sub( hFdCngCom->stopFFTbin , hFdCngCom->startBand ) , 1) , 1); + rshift_cng = sub(hFdCngCom->q_cngNoiseLevel, sub(shl(q_cngNoiseLevel_upd, 1), Q31)); + FOR ( i = 0; i < shr(sub( hFdCngCom->stopFFTbin , hFdCngCom->startBand ) , 1); i++ ) + { + IF (norm_l(*ptr_tmp) >= rshift_cng) + { + *ptr_level-- = Mpy_32_32(L_shl(*ptr_tmp, rshift_cng) , *ptr_tmp); + move32(); + } + ELSE + { + *ptr_level-- = L_shl(Mpy_32_32(*ptr_tmp, *ptr_tmp), rshift_cng); + move32(); + } + + ptr_tmp--; + *ptr_level = *( ptr_level + 1 ); + move32(); + lp_noise = L_add( lp_noise, L_shl( *ptr_level--, 1 ) ); + } + // q_cngNoiseLevel = sub(shl(q_cngNoiseLevel_upd, 1), Q31); + // hFdCngCom->q_cngNoiseLevel = q_cngNoiseLevel; move16(); + } + ELSE + { + /* FD-CNG */ + IF( !( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) ) + { + IF( hStereoCng->xfade_frame_counter <= MAX_K && hStereoCng->last_act_element_mode == IVAS_CPE_TD && chan == 0 ) + { + /* Fade MS -> SID/MS */ + j = 0; + move16(); + FOR( k = 0; k < ( hFdCngCom->nFFTpart - 2 ); k++ ) + { + Word16 q_div; + factor = BASOP_Util_Divide3232_Scale( ( hFdCngCom->sidNoiseEstLp[k] + DELTA_FX ), ( st->hFdCngDec->partNoiseShape[k] + DELTA_FX ), &q_div ); + factor = s_min( add( hStereoDft->scale_fx, extract_l( Mpy_32_16_1( L_mult( sub( factor, hStereoDft->scale_fx ), hStereoCng->xfade_frame_counter ), ONE_BY_MAX_K ) ) ), factor ); + FOR( ; j <= hFdCngCom->part[k]; j++ ) + { + hFdCngCom->cngNoiseLevel[j] = Mpy_32_16_1( st->hFdCngDec->bandNoiseShape[j], factor ); + move32(); + } + } + } + } + scale = shr( output_frame, 1 ); + numSlots = shr( hFdCngCom->numSlots, 2 ); + FOR( k = 0; k < STEREO_DFT_NBDIV; k++ ) + { + ptr_level = hFdCngCom->cngNoiseLevel; + ptr_r = DFT[chan] + hFdCngCom->startBand + k * STEREO_DFT32MS_N_MAX; + ptr_i = ptr_r + 1; + q_cngNoiseLevel = hFdCngCom->q_cngNoiseLevel; + FOR( i = 0; i < shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); i++ ) + { + Word16 q_sqrt; + /* Real part in FFT bins */ + tmp = *ptr_level++; + move32(); + tmp = L_add( tmp, *ptr_level++ ); + tmp = L_shr( tmp, 1 ); + rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft ); + q_sqrt = sub( Q31, q_cngNoiseLevel ); + tmp = Sqrt32( tmp, &q_sqrt ); + tmp = Mpy_32_32( *( ptr_r ), tmp ); + tmp = imult3216( tmp, scale ); + ( *ptr_r ) = L_shl( tmp, q_sqrt ); + move32(); + ptr_r += 2; + /* Imaginary part in FFT bins */ + rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); + ( *ptr_i ) = Mpy_32_32( ( *ptr_i ), tmp ); + move32(); + ptr_i += 2; + } + ptr_level = hFdCngCom->cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; + ptr_r = DFT[chan] + hFdCngCom->stopFFTbin + k * STEREO_DFT32MS_N_MAX; + ptr_i = ptr_r + 1; + FOR( j = hFdCngCom->numCoreBands; j < hFdCngCom->regularStopBand; j++ ) + { + FOR( i = 0; i < numSlots; i++ ) + { + Word16 q_sqrt; + /* Real part in FFT bins */ + rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft ); + tmp = Mpy_32_16_1( Sqrt32( *ptr_level, &q_sqrt ), scale ); + ( *ptr_r ) = Mpy_32_32( *ptr_r, tmp ); + move32(); + ptr_r += 2; + /* Imaginary part in FFT bins */ + rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); + ( *ptr_i ) = Mpy_32_32( *ptr_i, tmp ); + move32(); + ptr_i += 2; + } + ptr_level++; + } + } + + /* Compute noise level */ + lp_noise = 0; + move32(); + ptr_level = hFdCngCom->cngNoiseLevel; + FOR( i = 0; i < sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); i++ ) + { + lp_noise = L_add( lp_noise, *ptr_level++ ); + } + } + + IF( hStereoCng->last_act_element_mode == IVAS_CPE_TD && chan > 0 ) + { + Word32 log_lp_noise = L_add( L_shl( sub( Q31, hFdCngCom->q_cngNoiseLevel ), Q25 ), BASOP_Util_Log2( lp_noise + DELTA_FX ) ); + // log10(x) is computed as log2(x) * log10(2) + // log_lp_noise at this stage is in Q25. where as the structure value is in Q23 + // Hence the 16-bit constant log10(2) will be stored in Q13 + log_lp_noise = Mpy_32_16_1( log_lp_noise, (Word16) 0x09A2 ); + st1->lp_noise = L_add( Mpy_32_16_1( st1->lp_noise, (Word16) ( 0x7333 ) ), log_lp_noise ); + move32(); + } + ELSE IF( EQ_16( chan, 0 ) ) + { + Word16 q_lp_noise = 0; // st->hFdCngDec->q_lp_noise; // to be populated appropriately. + Word32 log_lp_noise = L_add( L_shl( sub( Q31, hFdCngCom->q_cngNoiseLevel ), Q25 ), BASOP_Util_Log2( lp_noise + DELTA_FX ) ); + move16(); + // log10(x) is computed as log2(x) * log10(2) + // log_lp_noise at this stage is in Q25. where as the structure value is in Q23 + // Hence the 16-bit constant log10(2) will be stored in Q13 + log_lp_noise = Mpy_32_16_1( log_lp_noise, (Word16) 0x09A2 ); + st->hFdCngDec->lp_noise = L_add( Mpy_32_16_1( st->hFdCngDec->lp_noise, (Word16) ( 0x7333 ) ), log_lp_noise ); + move32(); + st->lp_noise = st->hFdCngDec->lp_noise; + move32(); + st->hFdCngDec->hFdCngCom->flag_noisy_speech = (Word16) LT_32( L_shr( L_sub( st->hFdCngDec->lp_speech, st->hFdCngDec->lp_noise ), q_lp_noise ), 28 ); + move16(); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), + imult3216( Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); + move32(); + } + + IF( EQ_16( chan, 0 ) && LE_32( st->core_brate, SID_2k40 ) ) + { + /* update smoothed periodogram used by stereo CNA in SID and NO_DATA frames from cngNoiseLevel_flt */ + FOR( i = hFdCngCom->startBand; i < hFdCngCom->stopFFTbin; i++ ) + { + Word16 l_shift_val = sub(st->hFdCngDec->q_smoothed_psd, hFdCngCom->q_cngNoiseLevel); + move16(); + ftmp = hFdCngCom->cngNoiseLevel[i - hFdCngCom->startBand]; + move32(); + IF( !st->hFdCngDec->first_cna_noise_updated ) + { + /* very first update */ + alpha = 0; + move16(); + } + ELSE + { + alpha = (Word16) ( 0x799A ); + move16(); + IF( GT_32( st->hFdCngDec->smoothed_psd_fx[i], 0 ) && GT_32( Mpy_32_16_1( ftmp, (Word16) 0x3333 ), st->hFdCngDec->smoothed_psd_fx[i] ) ) + { + /* prevent abrupt upward update steps */ + ftmp = L_add(L_shl(st->hFdCngDec->smoothed_psd_fx[i], 2), L_shr(st->hFdCngDec->smoothed_psd_fx[i], 1)); + l_shift_val = 0; move16(); + } + ELSE IF ( LT_32(ftmp , L_shr(st->hFdCngDec->smoothed_psd_fx[i], l_shift_val)) ) + { + /* faster downward updates */ + alpha = (Word16) ( 0x599A ); + move16(); + } + } + + /* smoothing */ + st->hFdCngDec->smoothed_psd_fx[i] = L_add(Mpy_32_16_1(st->hFdCngDec->smoothed_psd_fx[i], alpha) , L_shl(Mpy_32_16_1(ftmp, sub( MAX_16 , alpha )), l_shift_val)); + move32(); + } + + /* update msNoiseEst in SID and NO_DATA frames */ + bandcombinepow( &st->hFdCngDec->smoothed_psd_fx[hFdCngCom->startBand], st->hFdCngDec->q_smoothed_psd, hFdCngCom->stopFFTbin - hFdCngCom->startBand, st->hFdCngDec->part_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->psize_inv_shaping, st->hFdCngDec->msNoiseEst, &st->hFdCngDec->msNoiseEst_exp ); + st->hFdCngDec->first_cna_noise_updated = 1; + move16(); + Copy32( st->hFdCngDec->msNoiseEst, st->hFdCngDec->msPeriodog_ST_fx, st->hFdCngDec->nFFTpart_shaping ); + st->hFdCngDec->ms_last_inactive_bwidth = st->bwidth; + move16(); + } + + pop_wmops(); + return; +} +#endif /*------------------------------------------------------------------- * stereo_dtf_cng() * * DFT stereo CNG *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void stereo_dtf_cng( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ const int32_t ivas_total_brate, /* i : IVAS total bitrate */ @@ -693,6 +1432,45 @@ void stereo_dtf_cng( return; } +#else +void stereo_dtf_cng_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ + const Word16 output_frame, /* i : output frame size */ + Word16 q_dft /* i : Q factor of the DFT data */ +) +{ + Decoder_State **sts; + Word16 n; + + sts = hCPE->hCoreCoder; + + IF( hCPE->hStereoCng != NULL ) + { + IF( LT_16( hCPE->hStereoCng->nr_dft_frames, CM_INIT ) ) + { + hCPE->hStereoCng->nr_dft_frames++; + } + + IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) + { + test(); + IF( LT_16( hCPE->hStereoCng->nr_sid_frames, SID_INIT ) && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) + { + hCPE->hStereoCng->nr_sid_frames++; + } + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + stereo_dft_generate_comfort_noise_fx( hCPE->hStereoDft, hCPE->hStereoCng, hCPE->last_element_mode, sts[0], DFT, sts[1], extract_h(hCPE->hStereoTCA->targetGain_fx), n, output_frame, q_dft); + } + } + } + + return; +} +#endif /*------------------------------------------------------------------- @@ -1217,7 +1995,7 @@ static void FindEmEs_fx( return; } - +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Function stereo_cna_update_params() * @@ -1333,7 +2111,7 @@ void stereo_cna_update_params( return; } -#ifdef IVAS_FLOAT_FIXED +#else void stereo_cna_update_params_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *output_fx[CPE_CHANNELS], /* i : Output signal */ @@ -1359,14 +2137,8 @@ void stereo_cna_update_params_fx( //delete below hFdCngDec->cna_act_fact_fx = (Word16)(hFdCngDec->cna_act_fact * (1 << 15)); - hFdCngDec->cna_LR_LT_fx = (Word16)(hFdCngDec->cna_LR_LT * (1 << 15)); - hFdCngDec->cna_ILD_LT_fx = (Word16)(hFdCngDec->cna_ILD_LT * (1 << 15)); - for (int idx = 0; idx < STEREO_DFT_BAND_MAX; idx++) - { - hFdCngDec->cna_g_state_fx[idx] = (Word16)(hFdCngDec->cna_g_state[idx] * (1 << 15)); - hFdCngDec->cna_cm_fx[idx] = (Word16)(hFdCngDec->cna_cm[idx] * (1 << 15)); - hCPE->lt_es_em_fx = (Word32)(hCPE->lt_es_em*(1 << 24)); - } + // hFdCngDec->cna_LR_LT_fx = (Word16)(hFdCngDec->cna_LR_LT * (1 << 15)); + // hFdCngDec->cna_ILD_LT_fx = (Word16)(hFdCngDec->cna_ILD_LT * (1 << 15)); ///// @@ -1541,14 +2313,14 @@ void stereo_cna_update_params_fx( } //delete below - hCPE->lt_es_em = (float)hCPE->lt_es_em_fx / (1 << 24); + //hCPE->lt_es_em = (float)hCPE->lt_es_em_fx / (1 << 24); hFdCngDec->cna_act_fact = (float) hFdCngDec->cna_act_fact_fx / ( 1 << 15 ); - hFdCngDec->cna_LR_LT = (float )hFdCngDec->cna_LR_LT_fx / ( 1 << 15 ); - hFdCngDec->cna_ILD_LT= (float )hFdCngDec->cna_ILD_LT_fx / ( 1 << 15 ); + // hFdCngDec->cna_LR_LT = (float )hFdCngDec->cna_LR_LT_fx / ( 1 << 15 ); + // hFdCngDec->cna_ILD_LT= (float )hFdCngDec->cna_ILD_LT_fx / ( 1 << 15 ); for (int idx = 0; idx < STEREO_DFT_BAND_MAX; idx++) { - hFdCngDec->cna_g_state[idx] = (float)hFdCngDec->cna_g_state_fx[idx]/ (1 << 15); - hFdCngDec->cna_cm[idx] = (float)hFdCngDec->cna_cm_fx[idx]/ (1 << 15); + //hFdCngDec->cna_g_state[idx] = (float)hFdCngDec->cna_g_state_fx[idx]/ (1 << 15); + //hFdCngDec->cna_cm[idx] = (float)hFdCngDec->cna_cm_fx[idx]/ (1 << 15); } return; diff --git a/lib_dec/ivas_stereo_dft_dec.c b/lib_dec/ivas_stereo_dft_dec.c index df82229251ddf72f125fc479895bd15ed9b39c00..f0b562271741d1c0df0cf0c0dc788a01e95ba5cb 100644 --- a/lib_dec/ivas_stereo_dft_dec.c +++ b/lib_dec/ivas_stereo_dft_dec.c @@ -84,6 +84,7 @@ static void stereo_dft_compute_td_stefi_params( STEREO_DFT_DEC_DATA_HANDLE hSter static void stereo_dft_adapt_sf_delay( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, float *pPredGain ); +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- * stereo_dft_dequantize_res_gains() * @@ -112,6 +113,7 @@ static void stereo_dft_dequantize_res_gains( return; } + /*--------------------------------------------------------------------------- * stereo_dft_dequantize_res_gains_f() * @@ -240,6 +242,7 @@ void stereo_dft_dequantize_itd( return; } +#endif /*------------------------------------------------------------------------- @@ -382,9 +385,6 @@ void stereo_dft_dec_open( /*Init. DFT sizes*/ hStereoDft->NFFT = (Word16) ( STEREO_DFT32MS_N_MAX * output_Fs / 48000 ); - hStereoDft->dft_trigo_8k = dft_trigo_32k; - hStereoDft->dft_trigo_12k8 = dft_trigo_12k8; - hStereoDft->dft_trigo_16k = dft_trigo_32k; SWITCH (output_Fs) { case 48000: @@ -406,21 +406,11 @@ void stereo_dft_dec_open( hStereoDft->dft_trigo_12k8_fx = dft_trigo_12k8_fx; hStereoDft->dft_trigo_16k_fx = dft_trigo_32k_fx; - /* TODO: remove floating point dependency */ - hStereoDft->win232ms_8k = dft_win232ms_8k; - hStereoDft->win232ms_12k8 = dft_win232ms_12k8; - hStereoDft->win232ms_16k = dft_win232ms_16k; - hStereoDft->dft32ms_ovl = (Word16) ( ( STEREO_DFT32MS_OVL_MAX * output_Fs ) / 48000 ); hStereoDft->win232ms_8k_fx = dft_win232ms_8k_fx; hStereoDft->win232ms_12k8_fx = dft_win232ms_12k8_fx; hStereoDft->win232ms_16k_fx = dft_win232ms_16k_fx; - /* TODO: remove floating point dependency */ - hStereoDft->win32ms_8k = dft_win232ms_8k + 1; - hStereoDft->win32ms_12k8 = dft_win232ms_12k8 + 1; - hStereoDft->win32ms_16k = dft_win232ms_16k + 1; - hStereoDft->dft32ms_ovl2 = (Word16) ( ( STEREO_DFT32MS_OVL2_MAX * output_Fs ) / 48000 ); hStereoDft->win32ms_8k_fx = dft_win232ms_8k_fx + 1; hStereoDft->win32ms_12k8_fx = dft_win232ms_12k8_fx + 1; @@ -429,11 +419,6 @@ void stereo_dft_dec_open( IF ( EQ_32( output_Fs, 16000 ) ) { - /* TODO: remove floating point dependency */ - hStereoDft->dft_trigo = dft_trigo_32k; - hStereoDft->win232ms = dft_win232ms_16k; - hStereoDft->win32ms = dft_win232ms_16k + 1; - hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; hStereoDft->win232ms_fx = dft_win232ms_16k_fx; @@ -441,11 +426,6 @@ void stereo_dft_dec_open( } ELSE IF ( EQ_32( output_Fs, 32000 ) ) { - /* TODO: remove floating point dependency */ - hStereoDft->dft_trigo = dft_trigo_32k; - hStereoDft->win232ms = dft_win232ms_32k; - hStereoDft->win32ms = dft_win232ms_32k + 1; - hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; hStereoDft->win232ms_fx = dft_win232ms_32k_fx; @@ -454,10 +434,6 @@ void stereo_dft_dec_open( ELSE { assert( EQ_32( output_Fs, 48000 ) ); - /* TODO: remove floating point dependency */ - hStereoDft->dft_trigo = dft_trigo_48k; - hStereoDft->win232ms = dft_win232ms_48k; - hStereoDft->win32ms = dft_win232ms_48k + 1; hStereoDft->dft_trigo_fx = dft_trigo_48k_fx; hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; @@ -465,10 +441,7 @@ void stereo_dft_dec_open( hStereoDft->win32ms_fx = dft_win232ms_48k_fx + 1; } - hStereoDft->win_8k = dft_win_8k; -#ifdef IVAS_FLOAT_FIXED hStereoDft->win_8k_fx = dft_win_8k_fx; -#endif /*Bands: find the number of bands, Nyquist freq. is not taken into account*/ set_s( hStereoDft->band_res, hStereoDft->hConfig->band_res, STEREO_DFT_DEC_DFT_NB ); @@ -677,7 +650,11 @@ void stereo_dft_dec_reset( for ( i = 0; i < STEREO_DFT_PAST_MAX; i++ ) { set_zero( hStereoDft->DFT_past_DMX[i], STEREO_DFT32MS_N_32k ); +#ifndef IVAS_FLOAT_FIXED set_zero( hStereoDft->past_res_pred_gain[i], STEREO_DFT_BAND_MAX ); +#else + set32_fx( hStereoDft->past_res_pred_gain_fx[i], 0, STEREO_DFT_BAND_MAX ); +#endif } #ifdef IVAS_FLOAT_FIXED @@ -693,17 +670,17 @@ void stereo_dft_dec_reset( set_s( hStereoDft->res_pred_index_previous, 0, STEREO_DFT_BAND_MAX ); +#ifndef IVAS_FLOAT_FIXED for ( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) { hStereoDft->res_gains_ind[0][i] = 15.f; } set_zero( hStereoDft->res_gains_ind[1], STEREO_DFT_BAND_MAX ); - -#ifdef IVAS_FLOAT_FIXED - FOR ( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) +#else + FOR( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) { - hStereoDft->res_gains_ind_fx[0][i] = L_shl(15, Q26); + hStereoDft->res_gains_ind_fx[0][i] = 1006632960; /* 15.0f in Q26 */ } set_val_Word32( hStereoDft->res_gains_ind_fx[1], 0, STEREO_DFT_BAND_MAX ); @@ -719,27 +696,40 @@ void stereo_dft_dec_reset( hStereoDft->res_pred_band_min = max( STEREO_DFT_RES_PRED_BAND_MIN, hStereoDft->res_cod_band_max ); +#ifndef IVAS_FLOAT_FIXED hStereoDft->stab_fac_smooth_res = 0.f; - bass_psfilter_init( hStereoDft->hBpf ); - +#else + hStereoDft->stab_fac_smooth_res_fx = 0; +#endif +#ifdef IVAS_FLOAT_FIXED + bass_psfilter_init_fx(hStereoDft->hBpf); +#endif tcxltp_dec_init( hStereoDft->hTcxLtpDec, 0, MODE1, IVAS_CPE_DFT, PIT_MAX, 12800 ); hStereoDft->reverb_flag = 0; hStereoDft->bpf_error_signal_last = 0.0f; hStereoDft->bpf_error_ratio_mem = 1.0f; +#ifndef IVAS_FLOAT_FIXED hStereoDft->res_hb_nrg_mem = 0.0f; -#ifdef IVAS_FLOAT_FIXED +#else hStereoDft->res_hb_nrg_mem_fx = 0; hStereoDft->bpf_error_signal_last_fx = 0; hStereoDft->bpf_error_ratio_mem_fx = ONE_IN_Q12; #endif // IVAS_FLOAT_FIXED /*reset parameters*/ +#ifndef IVAS_FLOAT_FIXED set_zero( hStereoDft->side_gain, STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX ); set_zero( hStereoDft->gipd, STEREO_DFT_DEC_DFT_NB ); set_zero( hStereoDft->itd, STEREO_DFT_DEC_DFT_NB ); set_zero( hStereoDft->res_pred_gain, STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX ); +#else + set32_fx( hStereoDft->side_gain_fx, 0, STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX ); + set32_fx( hStereoDft->gipd_fx, 0, STEREO_DFT_DEC_DFT_NB ); + set32_fx( hStereoDft->itd_fx, 0, STEREO_DFT_DEC_DFT_NB ); + set32_fx( hStereoDft->res_pred_gain_fx, 0, STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX ); +#endif #ifdef IVAS_FLOAT_FIXED /*reset parameters*/ @@ -755,9 +745,10 @@ void stereo_dft_dec_reset( hStereoDft->lt_pred_gain = 0.0f; hStereoDft->lt_pred_gain_variation = 0.0f; hStereoDft->lt_var_mean_ratio = STEREO_DFT_RES_RATIO_LIMIT; +#ifndef IVAS_FLOAT_FIXED hStereoDft->stefi_short_gain = 1.0f; hStereoDft->stefi_long_gain = 0.0f; -#ifdef IVAS_FLOAT_FIXED +#else hStereoDft->lt_pred_gain_fx = 0; hStereoDft->lt_pred_gain_variation_fx = 0; hStereoDft->lt_var_mean_ratio_fx = STEREO_DFT_RES_RATIO_LIMIT_FX; @@ -766,14 +757,13 @@ void stereo_dft_dec_reset( hStereoDft->q_lt_pred_gain = 0; #endif - set_zero( hStereoDft->g_state, STEREO_DFT_BAND_MAX ); - #ifdef IVAS_FLOAT_FIXED set_val_Word16( hStereoDft->g_state_fx, 0, STEREO_DFT_BAND_MAX ); init_basic_allpass( &hStereoDft->ap1, dft_ap_gains[0], dft_ap_gains_fx[0], dft_ap_delays[0] ); init_basic_allpass( &hStereoDft->ap2, dft_ap_gains[1], dft_ap_gains_fx[1], dft_ap_delays[1] ); init_basic_allpass( &hStereoDft->ap3, dft_ap_gains[2], dft_ap_gains_fx[2], dft_ap_delays[2] ); #else + set_zero( hStereoDft->g_state, STEREO_DFT_BAND_MAX ); init_basic_allpass( &hStereoDft->ap1, dft_ap_gains[0], dft_ap_delays[0] ); init_basic_allpass( &hStereoDft->ap2, dft_ap_gains[1], dft_ap_delays[1] ); init_basic_allpass( &hStereoDft->ap3, dft_ap_gains[2], dft_ap_delays[2] ); @@ -782,8 +772,13 @@ void stereo_dft_dec_reset( set_zero( hStereoDft->ap_delay_mem, NS2SA( 16000, DELAY_BWE_TOTAL_NS ) ); set_zero( hStereoDft->ap_fade_mem, STEREO_DFT_ALLPASS_FADELEN_16k ); hStereoDft->ap_wasTransient = 0; - set_zero( hStereoDft->smooth_dmx_nrg, STEREO_DFT_BAND_MAX ); - set_zero( hStereoDft->smooth_res_nrg, STEREO_DFT_BAND_MAX ); +#ifdef IVAS_FLOAT_FIXED + set32_fx( hStereoDft->smooth_dmx_nrg_fx, 0, STEREO_DFT_BAND_MAX ); + set32_fx( hStereoDft->smooth_res_nrg_fx, 0, STEREO_DFT_BAND_MAX ); +#else + set_zero(hStereoDft->smooth_dmx_nrg, STEREO_DFT_BAND_MAX); + set_zero(hStereoDft->smooth_res_nrg, STEREO_DFT_BAND_MAX); +#endif set_s( hStereoDft->core_hist, ACELP_CORE, STEREO_DFT_CORE_HIST_MAX ); @@ -811,15 +806,33 @@ void stereo_dft_dec_reset( set_zero( hStereoDft->smooth_fac[0], SBA_DIRAC_STEREO_NUM_BANDS ); set_zero( hStereoDft->smooth_fac[1], SBA_DIRAC_STEREO_NUM_BANDS ); +#ifdef IVAS_FLOAT_FIXED + hStereoDft->itd_xfade_target_fx = 0; + hStereoDft->itd_xfade_step_fx = 0; +#else hStereoDft->itd_xfade_target = 0.0f; hStereoDft->itd_xfade_step = 0.0f; +#endif hStereoDft->itd_xfade_counter = 0; +#ifdef IVAS_FLOAT_FIXED + hStereoDft->itd_xfade_prev_fx = 0; +#else hStereoDft->itd_xfade_prev = 0.0f; +#endif hStereoDft->last_active_element_brate = 0; +#ifdef IVAS_FLOAT_FIXED + hStereoDft->ipd_xfade_target_fx = 0; + hStereoDft->ipd_xfade_step_fx = 0; +#else hStereoDft->ipd_xfade_target = 0.0f; hStereoDft->ipd_xfade_step = 0.0f; +#endif hStereoDft->ipd_xfade_counter = 0; +#ifdef IVAS_FLOAT_FIXED + hStereoDft->ipd_xfade_prev_fx = 0; +#else hStereoDft->ipd_xfade_prev = 0.0f; +#endif for ( b = 0; b < hStereoDft->nbands; b++ ) { @@ -905,23 +918,42 @@ void stereo_dft_dec_update( k_offset = STEREO_DFT_OFFSET; /*Add an offset*/ /* Update parameters */ +#ifndef IVAS_FLOAT_FIXED for ( i = 0; i < k_offset * STEREO_DFT_BAND_MAX; i++ ) { hStereoDft->side_gain[i] = hStereoDft->side_gain[STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX + i]; hStereoDft->res_pred_gain[i] = hStereoDft->res_pred_gain[STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX + i]; } +#else + FOR( i = 0; i < k_offset * STEREO_DFT_BAND_MAX; i++ ) + { + hStereoDft->side_gain_fx[i] = hStereoDft->side_gain_fx[STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX + i]; + hStereoDft->res_pred_gain_fx[i] = hStereoDft->res_pred_gain_fx[STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX + i]; + } +#endif +#ifndef IVAS_FLOAT_FIXED for ( i = 0; i < k_offset; i++ ) { hStereoDft->gipd[i] = hStereoDft->gipd[STEREO_DFT_NBDIV + i]; } +#else + FOR(i = 0; i < k_offset; i++) + { + hStereoDft->gipd_fx[i] = hStereoDft->gipd_fx[STEREO_DFT_NBDIV + i]; + } +#endif /* Update configuration memories */ for ( i = 0; i < k_offset; i++ ) { hStereoDft->band_res[i] = hStereoDft->band_res[i + STEREO_DFT_NBDIV]; hStereoDft->prm_res[i] = hStereoDft->prm_res[i + STEREO_DFT_NBDIV]; +#ifndef IVAS_FLOAT_FIXED hStereoDft->itd[i] = hStereoDft->itd[STEREO_DFT_NBDIV + i]; +#else + hStereoDft->itd_fx[i] = hStereoDft->itd_fx[STEREO_DFT_NBDIV + i]; +#endif hStereoDft->res_cod_mode[i] = hStereoDft->res_cod_mode[i + STEREO_DFT_NBDIV]; hStereoDft->res_pred_mode[i] = hStereoDft->res_pred_mode[i + STEREO_DFT_NBDIV]; } @@ -1960,6 +1992,7 @@ void stereo_dft_dec_analyze( } #endif +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- * stereo_dft_dec_synthesize() * @@ -2104,7 +2137,6 @@ void stereo_dft_dec_synthesize( } -#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- * stereo_dft_dec() * @@ -2681,7 +2713,6 @@ void stereo_dft_dec( return; } -#endif /*------------------------------------------------------------------------- @@ -2934,11 +2965,7 @@ void stereo_dft_dec_read_BS( { hStereoDft->band_res[k_offset] = STEREO_DFT_BAND_RES_LOW; hStereoDft->res_cod_mode[k_offset] = STEREO_DFT_RES_COD_OFF; -#ifdef IVAS_FLOAT_FIXED - hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], min( STEREO_DFT32MS_N_MAX, NFFT_inner ), DEC ); -#else hStereoDft->nbands = stereo_dft_band_config( hStereoDft->band_limits, hStereoDft->band_res[k_offset], min( STEREO_DFT32MS_N_MAX, NFFT_inner ), DEC ); -#endif if ( hStereoDft->nbands > STEREO_DFT_COH_MAXBAND ) { @@ -2948,11 +2975,7 @@ void stereo_dft_dec_read_BS( } else { -#ifdef IVAS_FLOAT_FIXED - hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], NFFT_inner, DEC ); -#else hStereoDft->nbands = stereo_dft_band_config( hStereoDft->band_limits, hStereoDft->band_res[k_offset], NFFT_inner, DEC ); -#endif } hStereoDft->res_cod_band_max = dft_band_res_cod[hStereoDft->band_res[k_offset]][hStereoDft->res_cod_mode[k_offset]]; @@ -3237,13 +3260,7 @@ void stereo_dft_dec_read_BS( if ( ivas_total_brate > IVAS_SID_5k2 ) { -#ifdef IVAS_FLOAT_FIXED - floatToFixed_arrL( hStereoDft->side_gain, hStereoDft->side_gain_fx, 31, 39 ); - hStereoDft->recovery_flg = stereo_dft_sg_recovery_fx( hStereoDft ); - hStereoDft->sg_mean = fixedToFloat( hStereoDft->sg_mean_fx, 31 ); -#else hStereoDft->recovery_flg = stereo_dft_sg_recovery( hStereoDft ); -#endif // IVAS_FLOAT_FIXED if ( hStereoDft->recovery_flg ) { @@ -3268,35 +3285,15 @@ void stereo_dft_dec_read_BS( push_wmops( "residual_decode" ); if ( I != ECSQ_GLOBAL_GAIN_INDEX_ALL_ZERO ) { -#ifdef IVAS_FLOAT_FIXED - ECSQ_init_instance_fx( &ecsq_inst, 0 /*dummy index*/, &range_uni_dec_state ); -#else ECSQ_init_instance( &ecsq_inst, 0 /*dummy index*/, &range_uni_dec_state ); -#endif // IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED - rc_uni_dec_init_fx( &range_uni_dec_state, bit_stream_side + *nb_bits, max_bits - *nb_bits ); -#else rc_uni_dec_init( &range_uni_dec_state, bit_stream_side + *nb_bits, max_bits - *nb_bits ); -#endif // IVAS_FLOAT_FIXED - -#ifdef IVAS_FLOAT_FIXED - Word32 res_global_gain_fx; - - res_global_gain_fx = ECSQ_dequantize_gain_fx( I ); - hStereoDft->res_global_gain = ( (float) res_global_gain_fx / ONE_IN_Q15 ); - -#ifdef DUMPS_ENABLED - dbgwrite_txt( &hStereoDft->res_global_gain, 1, "fixed_res_global_gain.txt", NULL ); -#endif // DUMPS_ENABLED -#else hStereoDft->res_global_gain = ECSQ_dequantize_gain( I ); #ifdef DUMPS_ENABLED dbgwrite_txt( &hStereoDft->res_global_gain, 1, "float_res_global_gain.txt", NULL ); #endif // DUMPS_ENABLED -#endif // IVAS_FLOAT_FIXED ecsq_inst.config_index = 2 * hStereoDft->res_cod_mode[k_offset] - 1; @@ -3304,33 +3301,12 @@ void stereo_dft_dec_read_BS( n_bits = rc_uni_dec_finish( &range_uni_dec_state ); - set_zero( res_buf, STEREO_DFT_N_8k ); -#ifdef IVAS_FLOAT_FIXED - Word32 res_buf_fx[800]; - Word16 dec_fx[800]; - Word16 c; - FOR( c = 0; c < hStereoDft->res_cod_line_max; c++ ) - { - dec_fx[c] = dec[c] * ONE_IN_Q8; - } - - ECSQ_dequantize_vector_fx( dec_fx, res_global_gain_fx, hStereoDft->res_cod_line_max, res_buf_fx ); - - FOR( c = 0; c < hStereoDft->res_cod_line_max; c++ ) - { - res_buf[c] = ( (float) res_buf_fx[c] / ONE_IN_Q8 ); - } -#ifdef DUMPS_ENABLED - dbgwrite_txt( res_buf, hStereoDft->res_cod_line_max, "fixed_res_buf.txt", NULL ); -#endif // DUMPS_ENABLED -#else ECSQ_dequantize_vector( dec, hStereoDft->res_global_gain, hStereoDft->res_cod_line_max, res_buf ); #ifdef DUMPS_ENABLED dbgwrite_txt( res_buf, hStereoDft->res_cod_line_max, "float_res_buf.txt", NULL ); #endif // DUMPS_ENABLED -#endif // IVAS_FLOAT_FIXED } else @@ -4216,3 +4192,4 @@ static void stereo_dft_adapt_sf_delay( return; } +#endif diff --git a/lib_dec/ivas_stereo_dft_dec_dmx.c b/lib_dec/ivas_stereo_dft_dec_dmx.c index 9ac04152fc661c46d6f1681019491346635572f5..ae5a608014bdc8bab278dcb8cc6c43a1572b265f 100644 --- a/lib_dec/ivas_stereo_dft_dec_dmx.c +++ b/lib_dec/ivas_stereo_dft_dec_dmx.c @@ -97,7 +97,269 @@ void stereo_dft_dmx_out_reset_fx( * create a uniform dmx in case of residual coding by converting from passive * to active dmx in residual coding region *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void stereo_dft_unify_dmx_fx( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ + Decoder_State *st0, /* i/o: decoder state structure */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ + Word32 *input_mem, /* i/o: mem of buffer DFT analysis */ + const Word16 prev_sid_nodata /* i : Previous SID/No data indicator */ +) +{ + Word16 i, k, b, N_div; + Word32 DFT_L[STEREO_DFT32MS_N_MAX]; + Word32 DFT_R[STEREO_DFT32MS_N_MAX]; + Word32 *pDFT_DMX; + Word32 *pDFT_RES; + Word32 g, tmp; + Word32 *pSideGain; + Word16 k_offset; + + /* Variables for stereo residual PLC */ + Word32 DFT_PRED_RES[STEREO_DFT32MS_N_32k]; + Word16 samp_ratio, q_samp_ratio; + Word16 prev_bfi; + Word32 dmx_nrg; + Word32 *pPredGain; + Word16 stop; + Word16 output_frame; + Word16 plocs[STEREO_DFT_RES_N_PEAKS_MAX]; + Word16 num_plocs; + Word32 plocsi[STEREO_DFT_RES_N_PEAKS_MAX]; + + output_frame = (Word16)(st0->output_Fs / FRAMES_PER_SEC); + samp_ratio = BASOP_Util_Divide3232_Scale(st0->sr_core, st0->output_Fs, &q_samp_ratio); + samp_ratio = shr(samp_ratio, sub(Q15 - Q12, q_samp_ratio)); + + prev_bfi = st0->prev_old_bfi; move32(); + + /* Initialization */ + k_offset = 1; move16(); + N_div = STEREO_DFT_NBDIV; move16(); + + dmx_nrg = 0; move32(); + /* make sure number of bands corresponds to output bwidth in case it is lower than parameter bwidth */ + IF ( LT_16(output_frame, inner_frame_tbl[st0->bwidth] )) + { + hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], hStereoDft->NFFT, DEC ); + } + IF ( prev_bfi ) + { + //dmx_nrg = stereo_dft_dmx_swb_nrg_fx( DFT[0], DFT[0] + STEREO_DFT32MS_N_MAX, s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ), hStereoDft->q_dft, hStereoDft->q_dft ); + dmx_nrg = stereo_dft_dmx_swb_nrg_fx( DFT[0], DFT[0] + STEREO_DFT32MS_N_MAX, s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ), 0, 0); + } + + /* Analyze nature of current frame */ + test(); test(); test(); test(); test(); test(); test(); test(); + hStereoDft->trans = (Word16)((EQ_16(st0->clas_dec, ONSET) || EQ_16(st0->clas_dec, SIN_ONSET) || EQ_16(st0->clas_dec, UNVOICED_CLAS) || EQ_16(st0->clas_dec, UNVOICED_TRANSITION)) || LE_16(st0->stab_fac_fx, (Word16)0x2000)) || + ((EQ_16(st0->core, TCX_20_CORE) && (EQ_16(st0->hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP) || EQ_16(st0->hTcxCfg->tcx_last_overlap_mode, HALF_OVERLAP))) || EQ_16(st0->core, TCX_10_CORE)); + + /* Smoothing for the current frame */ + stereo_dft_dec_smooth_parameters_fx( hStereoDft, prev_sid_nodata, st0->hFdCngDec->hFdCngCom->active_frame_counter, st0->element_brate ); + + FOR ( k = 0; k < N_div; k++ ) + { + pDFT_DMX = DFT[0] + i_mult(k, STEREO_DFT32MS_N_MAX); + pDFT_RES = DFT[1] + i_mult(k, STEREO_DFT32MS_N_MAX); + + assert( hStereoDft->hConfig->dmx_active ); + /*Apply Stereo*/ + g = MAX_16; + move16(); + /* since delay is just 3.125ms, the parameters received are used for the second window */ + pSideGain = hStereoDft->side_gain_fx + i_mult(add(k, k_offset), STEREO_DFT_BAND_MAX); + + /* Stereo residual PLC */ + IF ( GT_16(hStereoDft->res_cod_band_max, 0 )) + { + IF ( !st0->bfi ) + { + IF ( EQ_16(k, 1 )) + { + Copy32( pDFT_RES, hStereoDft->res_mem_fx, shl(hStereoDft->band_limits[hStereoDft->res_cod_band_max], 1) ); + hStereoDft->q_res_mem = hStereoDft->q_dft; + hStereoDft->time_offs = 0; + move16(); + } + } + ELSE + { + hStereoDft->nbands = hStereoDft->res_cod_band_max; /* Limit nbands since residual PLC only needs the low frequency range of the stereo filling */ + move16(); + pPredGain = hStereoDft->res_pred_gain_fx + i_mult(add(k, k_offset), STEREO_DFT_BAND_MAX); + hStereoDft->past_DMX_pos = ( sub(add(hStereoDft->past_DMX_pos, STEREO_DFT_PAST_MAX), 1 )) % STEREO_DFT_PAST_MAX; + stereo_dft_generate_res_pred_fx( hStereoDft, samp_ratio, pDFT_DMX, DFT_PRED_RES, pPredGain, k, DFT[1] + k * STEREO_DFT32MS_N_MAX, &stop, st0->bfi ); + stereo_dft_res_ecu_fx( hStereoDft, pDFT_RES, DFT_PRED_RES, k, output_frame, prev_bfi, dmx_nrg, &num_plocs, plocs, plocsi, input_mem ); + hStereoDft->q_res_cod_mem_fx = hStereoDft->q_dft; + } + } + + /* Apply active DMX */ + DFT_L[0] = pDFT_DMX[0]; + DFT_R[0] = pDFT_DMX[0]; + + /* upmix residual part */ + FOR ( b = 0; b < hStereoDft->res_cod_band_max; b++ ) + { + g = extract_h(pSideGain[b]); + move16(); + + FOR ( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) + { + tmp = Madd_32_16(pDFT_RES[2 * i], pDFT_DMX[2 * i], g); + + DFT_L[2 * i] = L_add(pDFT_DMX[2 * i], tmp); + DFT_R[2 * i] = L_sub(pDFT_DMX[2 * i], tmp); + + tmp = Madd_32_16(pDFT_RES[2 * i + 1], pDFT_DMX[2 * i + 1], g); + + DFT_L[2 * i + 1] = L_add(pDFT_DMX[2 * i + 1], tmp); + DFT_R[2 * i + 1] = L_sub(pDFT_DMX[2 * i + 1], tmp); + } + } + + /* downmix residual part with active downmix */ + FOR ( b = 0; b < hStereoDft->res_cod_band_max; b++ ) + { + Word16 j, max_e; + Word32 sum_nrg_Mid, sum_abs, dot_prod_abs; + Word16 wR, wL; + Word16 norm_sum_nrg_L, norm_sum_nrg_R, norm_dot_prod_real, norm_dot_prod_imag, guard_bit, min_norm, q_sum_nrg_L, q_sum_nrg_R, q_dot_prod_real; + Word16 exp_sum_nrg_l, exp_sum_nrg_R, exp_dot_prod_abs, exp_sum_nrg_Mid; + Word32 sum_nrg_L_32, sum_nrg_R_32, dot_prod_real_32, dot_prod_img_32; + Word64 sum_nrg_L = 0, sum_nrg_R = 0; + Word64 dot_prod_real = 0, dot_prod_img = 0; + + FOR ( j = hStereoDft->band_limits[b]; j < hStereoDft->band_limits[b + 1]; j++ ) + { + sum_nrg_L = W_add(sum_nrg_L, W_add(W_mult_32_32(DFT_L[2 * j], DFT_L[2 * j]), W_mult_32_32(DFT_L[2 * j + 1], DFT_L[2 * j + 1]))); + sum_nrg_R = W_add(sum_nrg_R, W_add(W_mult_32_32(DFT_R[2 * j], DFT_R[2 * j]), W_mult_32_32(DFT_R[2 * j + 1], DFT_R[2 * j + 1]))); + + dot_prod_real = W_add(dot_prod_real, W_add(W_mult_32_32(DFT_L[2 * j], DFT_R[2 * j]), W_mult_32_32(DFT_L[2 * j + 1], DFT_R[2 * j + 1]))); + dot_prod_img = W_add(dot_prod_img, W_sub(W_mult_32_32(DFT_L[2 * j + 1], DFT_R[2 * j]), W_mult_32_32(DFT_L[2 * j], DFT_R[2 * j + 1]))); + } + + norm_sum_nrg_L = W_norm(sum_nrg_L); + norm_sum_nrg_R = W_norm(sum_nrg_R); + norm_dot_prod_real = W_norm(dot_prod_real); + norm_dot_prod_imag = W_norm(dot_prod_img); + + guard_bit = find_guarded_bits_fx(4); + min_norm = s_min(s_min(s_min(norm_sum_nrg_L, norm_sum_nrg_R), norm_dot_prod_real), norm_dot_prod_imag) - guard_bit; + sum_nrg_L_32 = W_extract_h(W_shl(sum_nrg_L, min_norm)); + sum_nrg_R_32 = W_extract_h(W_shl(sum_nrg_R, min_norm)); + dot_prod_real_32 = W_extract_h(W_shl(dot_prod_real, min_norm)); + dot_prod_img_32 = W_extract_h(W_shl(dot_prod_img, min_norm)); + + q_sum_nrg_L = sub(add(shl(hStereoDft->q_dft, 1), min_norm), 31); + q_sum_nrg_R = sub(add(shl(hStereoDft->q_dft, 1), min_norm), 31); + q_dot_prod_real = sub(add(shl(hStereoDft->q_dft, 1), min_norm), 31); + + exp_sum_nrg_l = sub(31, q_sum_nrg_L); + exp_sum_nrg_R = sub(31, q_sum_nrg_R); + exp_dot_prod_abs = sub(31, sub(shl(q_dot_prod_real, 1), 31)); + exp_sum_nrg_Mid = sub(31, q_sum_nrg_L); + + sum_nrg_Mid = L_max(0, L_add(L_add(sum_nrg_L_32, sum_nrg_R_32), L_shl(dot_prod_real_32, 1))); + + Word32 tmp_nrg_L = Sqrt32(sum_nrg_L_32, &exp_sum_nrg_l); + Word32 tmp_nrg_R = Sqrt32(sum_nrg_R_32, &exp_sum_nrg_R); + Word16 exp_sum_abs = exp_sum_nrg_l; + + IF(GT_16(exp_sum_nrg_R, exp_sum_nrg_l)) + { + exp_sum_abs = exp_sum_nrg_R; move16(); + } + exp_sum_abs = add(exp_sum_abs, 1); + sum_abs = L_add(L_shr(tmp_nrg_L, exp_sum_abs - exp_sum_nrg_l), L_shr(tmp_nrg_R, exp_sum_abs - exp_sum_nrg_R)); + dot_prod_abs = Sqrt32(L_add(Mpy_32_32(dot_prod_real_32, dot_prod_real_32), Mpy_32_32(dot_prod_img_32, dot_prod_img_32)), &exp_dot_prod_abs); + Word32 num = L_add(L_shr(L_add(sum_nrg_L_32, sum_nrg_R_32), 1), L_shr(dot_prod_abs, (31 - exp_dot_prod_abs) - q_sum_nrg_L)); + Word16 E_num = sub(31, q_sum_nrg_L); + Word32 num_sqrt = Sqrt32(num, &E_num); + Word16 exp_wR = exp_sum_abs; move16(); + + IF( LT_16(exp_sum_abs, E_num )) + { + exp_wR = E_num; move16(); + } + Word16 wR_temp; + IF( EQ_32(num_sqrt, 0) && EQ_32(sum_abs, 0) ) + { + wR_temp = 6364; // 0.776887059 in Q13 + move16(); + } + ELSE IF( num_sqrt == 0 && sum_abs != 0 ) + { + wR_temp = 5793; // 0.707106769 in Q13 + move16(); + } + ELSE + { + wR_temp = shr( divide3232( L_shr( num_sqrt, exp_wR - E_num ), L_shr( sum_abs, exp_wR - exp_sum_abs ) ), 2 ); + } + + Word32 sum_nrg_Mid_sqrt = Sqrt32( sum_nrg_Mid, &exp_sum_nrg_Mid ); + + Word16 exp_wL = exp_sum_abs; + IF( LT_16(exp_sum_abs, exp_sum_nrg_Mid )) + { + exp_wL = exp_sum_nrg_Mid; move16(); + } + Word16 wL_temp; + IF( EQ_32(sum_nrg_Mid_sqrt, 0) && EQ_32(sum_abs, 0) ) + { + wL_temp = 6364; move16(); + } + ELSE IF( sum_nrg_Mid_sqrt == 0 && sum_abs != 0 ) + { + wL_temp = 5793; move16(); + } + ELSE + { + wL_temp = shr( divide3232( L_shr( sum_nrg_Mid_sqrt, exp_wL - exp_sum_nrg_Mid ), L_shr( sum_abs, exp_wL - exp_sum_abs ) ), 1 ); + } + + wR = wR_temp; move16(); + wL = add(wR, mult( 23170 /*sqrt(2.0f in Q14)*/, sub( 16384 /* 1.0f in Q14 */, wL_temp ) ) ); + + FOR ( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) + { + /*DMX Mapping*/ + pDFT_DMX[2 * i] = Mpy_32_32( L_add(Mpy_32_16_1(DFT_L[2 * i], wL), Mpy_32_16_1(DFT_R[2 * i], wR)), INV_SQRT_2_Q31); + pDFT_DMX[2 * i + 1] = Mpy_32_32( L_add(Mpy_32_16_1(DFT_L[2 * i + 1], wL), Mpy_32_16_1(DFT_R[2 * i + 1], wR)), INV_SQRT_2_Q31); + } + } + Scale_sig32(pDFT_DMX, (hStereoDft->band_limits[0]), -2); + Scale_sig32(pDFT_DMX + hStereoDft->band_limits[hStereoDft->res_cod_band_max + 1], hStereoDft->NFFT - hStereoDft->band_limits[hStereoDft->res_cod_band_max + 1], -2); + + Copy32( pDFT_DMX, DFT[0] + i_mult(k, STEREO_DFT32MS_N_MAX), hStereoDft->NFFT ); + + /* Update DFT_past_DMX, needed for stereo filling used by stereo residual PLC */ + hStereoDft->past_DMX_pos = ( hStereoDft->past_DMX_pos + 1 ) % STEREO_DFT_PAST_MAX; + Copy32( pDFT_DMX, hStereoDft->DFT_past_DMX_fx[hStereoDft->past_DMX_pos], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ) ); + //Scale_sig32(hStereoDft->DFT_past_DMX_fx[hStereoDft->past_DMX_pos], s_min(hStereoDft->NFFT, STEREO_DFT32MS_N_32k), -2); + hStereoDft->q_DFT_past_DMX_fx[hStereoDft->past_DMX_pos] = sub(add(hStereoDft->q_dft, 13), 15); + IF ( st0->bfi && !prev_bfi ) + { + Word16 idx_k0, idx_k1; + Word16 q_shift0; + Word16 q_shift1; + idx_k0 = ( add(hStereoDft->past_DMX_pos, 1) ) % STEREO_DFT_PAST_MAX; + idx_k1 = ( add(idx_k0, 1) ) % STEREO_DFT_PAST_MAX; + q_shift0 = sub(hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[idx_k0]); + q_shift1 = sub(hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[idx_k1]); + + /*dmx energy memory*/ + hStereoDft->past_dmx_nrg = stereo_dft_dmx_swb_nrg_fx( hStereoDft->DFT_past_DMX_fx[idx_k0], hStereoDft->DFT_past_DMX_fx[idx_k1], min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ), q_shift0, q_shift1); + } + } + + hStereoDft->q_dft = sub(add(hStereoDft->q_dft, 13), 15); + + return; +} +#else void stereo_dft_unify_dmx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ Decoder_State *st0, /* i/o: decoder state structure */ @@ -139,11 +401,7 @@ void stereo_dft_unify_dmx( /* make sure number of bands corresponds to output bwidth in case it is lower than parameter bwidth */ if ( output_frame < inner_frame_tbl[st0->bwidth] ) { -#ifdef IVAS_FLOAT_FIXED - hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], hStereoDft->NFFT, DEC ); -#else hStereoDft->nbands = stereo_dft_band_config( hStereoDft->band_limits, hStereoDft->band_res[k_offset], hStereoDft->NFFT, DEC ); -#endif } if ( prev_bfi ) { @@ -264,7 +522,7 @@ void stereo_dft_unify_dmx( return; } - +#endif /*-------------------------------------------------------------------* * add_HB_to_mono_dmx() @@ -272,6 +530,7 @@ void stereo_dft_unify_dmx( * add ACELP HB for DFT Stereo mono output with residual coding *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void add_HB_to_mono_dmx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ float output[L_FRAME48k], /* i/o: output synthesis */ @@ -368,8 +627,7 @@ void add_HB_to_mono_dmx( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void add_HB_to_mono_dmx_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 output[L_FRAME48k], /* i/o: output synthesis */ @@ -383,7 +641,7 @@ void add_HB_to_mono_dmx_fx( Word32 winSlope_fx = 0; Word32 alpha_fx; - const Word32 *win_dft_fx; + const Word16 *win_dft_fx; int32_t output_Fs; Word32 *memOutHB_fx, *memTransitionHB_fx; @@ -443,20 +701,20 @@ void add_HB_to_mono_dmx_fx( Copy32(outputHB + output_frame - memOffset, memOutHB_fx, memOffset); - win_dft_fx = (Word32 *)hCPE->hStereoDft->win32ms_fx; + win_dft_fx = hCPE->hStereoDft->win32ms_fx; dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; /* Preparing buffers in anticipation of an ACELP to TCX switch */ j = 0; FOR (i = 0; i < memOffset; i++) { - memTransitionHB_fx[i] = memOutHB_fx[i] * win_dft_fx[STEREO_DFT32MS_STEP * (dftOvlLen - 1 - j)]; + memTransitionHB_fx[i] = Mpy_32_16_1(memOutHB_fx[i], win_dft_fx[STEREO_DFT32MS_STEP * (dftOvlLen - 1 - j)]); j++; } FOR (i = 0; j < dftOvlLen; i++) { - memTransitionHB_fx[memOffset + i] = outputHB[output_frame - i - 1] * win_dft_fx[STEREO_DFT32MS_STEP * (dftOvlLen - 1 - j)]; + memTransitionHB_fx[memOffset + i] = Mpy_32_16_1(outputHB[output_frame - i - 1], win_dft_fx[STEREO_DFT32MS_STEP * (dftOvlLen - 1 - j)]); j++; } } diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index e2eb413819f4e99cd6ff41edf6bf8b96c7f0b2d1..d8090097287bba4649ca51402e96b13b374b24e1 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -85,18 +85,6 @@ static void stereo_dft_compute_td_stefi_params_fx( STEREO_DFT_DEC_DATA_HANDLE hS static void stereo_dft_adapt_sf_delay_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, Word32 *pPredGain ); -void stereo_dft_generate_res_pred_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word16 samp_ratio, /* i : sampling ratio */ - Word32 *pDFT_DMX, /* i : downmix signal */ - Word32 *DFT_PRED_RES, /* o : residual prediction signal */ - Word32 *pPredGain, /* i : residual prediction gains */ - const Word16 k, /* i : subframe index */ - Word32 *ap_filt_DMX, /* i : enhanced stereo filling signal */ - Word16 *stop, /* o : last FD stereo filling bin */ - const Word16 bfi /* i : BFI flag */ -); - #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- * stereo_dft_dec_reset_fx() @@ -150,8 +138,9 @@ void stereo_dft_dec_reset_fx( hStereoDft->stab_fac_smooth_res_fx = 0; move16(); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) bass_psfilter_init( hStereoDft->hBpf ); - +#endif tcxltp_dec_init( hStereoDft->hTcxLtpDec, 0, MODE1, IVAS_CPE_DFT, PIT_MAX, 12800 ); hStereoDft->reverb_flag = 0; @@ -631,6 +620,8 @@ void stereo_dft_dec_synthesize_fx( hStereoDft = hCPE->hStereoDft; + hCPE->lt_es_em_fx = L_shr(hCPE->lt_es_em_fx, 9); // Q24 -> Q15 + outputFs = L_mult0(output_frame, FRAMES_PER_SEC); zp = NS2SA( outputFs, STEREO_DFT32MS_ZP_NS ); @@ -758,6 +749,7 @@ void stereo_dft_dec_synthesize_fx( p_DFT += STEREO_DFT32MS_N_MAX; } + hCPE->lt_es_em_fx = L_shl(hCPE->lt_es_em_fx, 9); // Q15 -> Q24 pop_wmops(); return; @@ -1265,7 +1257,7 @@ void stereo_dft_dec_res_fx( Copy( win, out_16, L_FRAME8k ); - IF ( hCPE->hCoreCoder[0]->core == ACELP_CORE ) + IF ( EQ_16(hCPE->hCoreCoder[0]->core , ACELP_CORE) ) { /* bass post-filter */ bass_psfilter_fx( hCPE->hStereoDft->hBpf, hCPE->hCoreCoder[0]->Opt_AMR_WB, out_16, L_FRAME8k, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx + ( L_FRAME8k / STEREO_DFT_L_SUBFR_8k ), hCPE->hCoreCoder[0]->bpf_off, @@ -2689,10 +2681,10 @@ void stereo_dft_generate_res_pred_fx( IF ( GT_16(g_short , 0) ) { - Word16 q_nrom_fac, q_divide, q_shift; + Word16 q_divide, q_shift; Word32 op = BASOP_Util_Divide3232_Scale( (EPSILON_FIX + dmx_nrg ) , ( EPSILON_FIX + past_dmx_nrg ) , &q_divide); q_norm_fac = Q16 + q_divide + hStereoDft->q_hb_nrg_subr; - op = Sqrt32( op, &q_nrom_fac); + op = Sqrt32( op, &q_norm_fac); g2 = Mpy_32_32(pPredGain[b], op); pred_gain_avg = Mpy_32_16_1(hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short); IF (LT_16(q_norm_fac, 0)) @@ -3661,7 +3653,8 @@ void stereo_dft_dec_read_BS_fx( IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - hStereoDft->recovery_flg = stereo_dft_sg_recovery( hStereoDft ); + //hStereoDft->recovery_flg = stereo_dft_sg_recovery( hStereoDft ); + hStereoDft->recovery_flg = stereo_dft_sg_recovery_fx( hStereoDft ); IF( hStereoDft->recovery_flg ) { diff --git a/lib_dec/ivas_stereo_dft_plc.c b/lib_dec/ivas_stereo_dft_plc.c index ef46e08d9a4334d4b8ba30a53f0d45bb8e86c1aa..945d8d1093b969bc32f547cfb2fa9466e7ea7822 100644 --- a/lib_dec/ivas_stereo_dft_plc.c +++ b/lib_dec/ivas_stereo_dft_plc.c @@ -39,6 +39,7 @@ #include "math.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*--------------------------------------------------------------- * Local constants * ---------------------------------------------------------------*/ @@ -382,3 +383,4 @@ int16_t stereo_dft_sg_recovery( return 0; } +#endif diff --git a/lib_dec/ivas_stereo_dft_plc_fx.c b/lib_dec/ivas_stereo_dft_plc_fx.c index 17b50c5f3482227f918c615500ec8bab321b4c1c..fd39b1cec1cf8a893cf76fadb5bfe2487811ba33 100644 --- a/lib_dec/ivas_stereo_dft_plc_fx.c +++ b/lib_dec/ivas_stereo_dft_plc_fx.c @@ -64,16 +64,16 @@ 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 */ + 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 */ ) { Word32 res_buf[L_FRAME8k]; @@ -92,24 +92,24 @@ void stereo_dft_res_ecu_fx( 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 ); - fac = BASOP_Util_Divide3232_Scale( L_FRAME8k , hStereoDft->NFFT, &q_fac); - IF (GT_16(q_fac, 0)) + fac = BASOP_Util_Divide3232_Scale( L_FRAME8k, hStereoDft->NFFT, &q_fac ); + IF( GT_16( q_fac, 0 ) ) { - assert(0); + assert( 0 ); } ELSE { - fac = shl(fac, q_fac); + fac = shl( fac, q_fac ); } - IF ( EQ_16(hStereoDft->core_hist[0] , ACELP_CORE) ) + IF( EQ_16( 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 ) ); } trigo_step = STEREO_DFT_TRIGO_SRATE_8k_STEP * STEREO_DFT_TRIGO_DEC_STEP; move16(); - FOR ( i = 0; i < STEREO_DFT32MS_N_8k / 4; i++ ) + FOR( i = 0; i < STEREO_DFT32MS_N_8k / 4; i++ ) { trigo_dec[i] = hStereoDft->dft_trigo_8k_fx[i * trigo_step]; move16(); @@ -120,7 +120,7 @@ void stereo_dft_res_ecu_fx( move16(); /* estimation of res_cod_mem (ola part in imdct residual signal) and input_mem (memory for buffer in DFT analysis)*/ - IF ( EQ_16(k , 0) ) + IF( EQ_16( k, 0 ) ) { Copy32( pDFT_RES, res_buf, L_FRAME8k ); 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 ); @@ -132,17 +132,18 @@ void stereo_dft_res_ecu_fx( 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_ip_mem = hStereoDft->q_dft; + move16(); } ELSE { - Word16 scale_fac = getScaleFactor32(res_buf, L_FRAME8k); + Word16 scale_fac = getScaleFactor32( res_buf, L_FRAME8k ); Word16 q_shift = 8 - scale_fac; - //Copy32( pDFT_RES, res_buf, L_FRAME8k ); - v_shr_32(pDFT_RES, res_buf, L_FRAME8k, q_shift); + // Copy32( pDFT_RES, res_buf, L_FRAME8k ); + v_shr_32( pDFT_RES, res_buf, L_FRAME8k, 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 ) ); v_multc_fixed( res_buf, fac, res_buf, L_FRAME8k ); @@ -151,20 +152,20 @@ void stereo_dft_res_ecu_fx( move16(); step = ONE_BY_NS2A_8K_ST_DFT32MS_OVL_NS; move16(); - FOR ( i = 0; i < NS2SA( 8000, STEREO_DFT32MS_OVL_NS ); i++ ) + 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 ); move32(); - fac = add(fac, step); + 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 ); } set_l( DFT_PRED_RES, 0, 2 * L_res ); - IF ( prev_bfi ) + IF( prev_bfi ) { stereo_dft_res_ecu_burst_att_fx( hStereoDft, pDFT_RES, dmx_nrg, L_res, L_FRAME8k ); } @@ -188,61 +189,71 @@ Word32 imax_pos_fx( 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]; + move32(); y2 = y[1]; + move32(); y3 = y[2]; - 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); + 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 ); - IF ( EQ_32(ftmp_den2 , 0) || EQ_32(ftmp_den1 , 0) ) + test(); + IF( EQ_32( ftmp_den2, 0 ) || EQ_32( ftmp_den1, 0 ) ) { 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)); - IF (LT_16(q_div_2i, 0)) + y2i = Mpy_32_16_1( Mpy_32_16_1( y3_y1, BASOP_Util_Divide3232_Scale( y3_y1, ftmp_den1, &q_div_2i ) ), (Word16) ( 0xF000 ) ); + IF( LT_16( q_div_2i, 0 ) ) { - y2i = L_shl(y2i, q_div_2i); + y2i = L_shl( y2i, q_div_2i ); q_div_2i = 0; - y2i = L_add(y2i, y2); + move16(); + y2i = L_add( y2i, y2 ); } ELSE { - y2i = L_add(y2i, L_shr(y2, q_div_2i)); + y2i = L_add( y2i, L_shr( y2, q_div_2i ) ); } /* their corresponding normalized locations */ - posi = BASOP_Util_Divide3232_Scale(y3_y1 , ( ftmp_den2 ), &q_div_posi); - IF (NE_16(q_div_posi, 0)) + posi = BASOP_Util_Divide3232_Scale( y3_y1, ( ftmp_den2 ), &q_div_posi ); + IF( NE_16( q_div_posi, 0 ) ) { - posi = L_shl(posi, q_div_posi); + posi = L_shl( posi, q_div_posi ); q_div_posi = 0; + move16(); } /* Interpolated maxima if locations are not within [-1,1], calculated extrema are ignored */ - IF ( GE_32(posi, L_shr(ONE_IN_Q15, q_div_posi)) || LE_32(posi , L_shr(MIN_16, q_div_posi)) ) + test(); + IF( GE_32( posi, L_shr( ONE_IN_Q15, q_div_posi ) ) || LE_32( posi, L_shr( MIN_16, q_div_posi ) ) ) { - posi = y3 > y1 ? ONE_IN_Q15 : MIN_16; + posi = GT_32( y3, y1 ) ? ONE_IN_Q15 : MIN_16; + move16(); } ELSE { - IF ( GE_32(L_shr(y1, q_div_2i), y2i) ) + IF( GE_32( L_shr( y1, q_div_2i ), y2i ) ) { - posi = ( y1 > y3 ) ? MIN_16 : ONE_IN_Q15; + posi = GT_32( y1, y3 ) ? MIN_16 : ONE_IN_Q15; + move16(); } - ELSE IF ( GE_32(L_shr(y3, q_div_2i) , y2i) ) + ELSE IF( GE_32( L_shr( y3, q_div_2i ), y2i ) ) { posi = ONE_IN_Q15; + move16(); } } - return L_add(posi , ONE_IN_Q15); + return L_add( posi, ONE_IN_Q15 ); } static void ivas_peakfinder_fx( - const Word32 *x0, /* i : vector from which the maxima will be found */ + 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 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 */ ) { @@ -252,68 +263,86 @@ static void ivas_peakfinder_fx( Word16 *ind, indarr[L_PROT48k_2 + 1], peakLoc[MAX_PLOCS]; ind = indarr; + move16(); /* Find derivative */ v_sub_32( x0 + 1, x0, dx0, len0 - 1 ); /* This is so we find the first of repeated values */ - FOR ( i = 0; i < len0 - 1; i++ ) + FOR( i = 0; i < len0 - 1; i++ ) { - IF ( EQ_32(dx0[i] , 0) ) + IF( EQ_32( dx0[i], 0 ) ) { dx0[i] = -EPSILON_FX; + move32(); } } /* Find where the derivative changes sign Include endpoints in potential peaks and valleys */ k = 0; + move16(); - IF ( endpoints ) + IF( endpoints ) { x[k] = x0[0]; + move32(); ind[k++] = 0; + move16(); } - FOR ( i = 1; i < len0 - 1; i++ ) + FOR( i = 1; i < len0 - 1; i++ ) { - IF ( L_xor(dx0[i - 1] , dx0[i]) < 0 ) + IF( LT_32( L_xor( dx0[i - 1], dx0[i] ), 0 ) ) { ind[k] = i; + move16(); x[k++] = x0[i]; + move32(); } } - IF ( endpoints ) + IF( endpoints ) { - ind[k] = sub(len0 , 1); + ind[k] = sub( len0, 1 ); + move16(); x[k++] = x0[len0 - 1]; + move32(); } /* x only has the peaks, valleys, and endpoints */ len = k; + move16(); minimum_l( x, len, &minMag ); - IF ( ( len > 2 ) || ( !endpoints && ( len > 0 ) ) ) + test(); + test(); + IF( GT_16( len, 2 ) || ( !endpoints && GT_16( len, 0 ) ) ) { /* Set initial parameters for loop */ tempMag = minMag; + move32(); foundPeak = 0; + move16(); leftMin = minMag; + move32(); - IF ( endpoints ) + IF( endpoints ) { /* Deal with first point a little differently since tacked it on Calculate the sign of the derivative since we taked the first point on it does not necessarily alternate like the rest. */ /* The first point is larger or equal to the second */ - IF ( GE_32(x[0] , x[1]) ) + IF( GE_32( x[0], x[1] ) ) { ii = -1; - IF ( GE_32(x[1] , x[2]) ) /* x[1] is not extremum -> overwrite with x[0] */ + move16(); + IF( GE_32( x[1], x[2] ) ) /* x[1] is not extremum -> overwrite with x[0] */ { x[1] = x[0]; + move32(); ind[1] = ind[0]; + move16(); ind++; len--; } @@ -321,10 +350,13 @@ static void ivas_peakfinder_fx( ELSE /* First point is smaller than the second */ { ii = 0; - IF ( LT_32(x[1] , x[2]) ) /* x[1] is not extremum -> overwrite with x[0] */ + move16(); + IF( LT_32( x[1], x[2] ) ) /* x[1] is not extremum -> overwrite with x[0] */ { x[1] = x[0]; + move32(); ind[1] = ind[0]; + move16(); ind++; len--; } @@ -333,387 +365,134 @@ static void ivas_peakfinder_fx( ELSE { ii = -1; /* First point is a peak */ - IF ( GE_16(len , 2) ) + move16(); + IF( GE_16( len, 2 ) ) { - IF ( GE_32(x[1] , x[0]) ) + IF( GE_32( x[1], x[0] ) ) { ii = 0; /* First point is a valley, skip it */ + move16(); } } } *cInd = 0; + move16(); /* Loop through extrema which should be peaks and then valleys */ - WHILE ( ii < len - 1 ) + WHILE( LT_16( ii, sub( len, 1 ) ) ) { ii++; /* This is a peak */ /*Reset peak finding if we had a peak and the next peak is bigger than the last or the left min was small enough to reset.*/ - IF ( foundPeak ) + IF( foundPeak ) { tempMag = minMag; + move32(); foundPeak = 0; + move16(); } /* Make sure we don't iterate past the length of our vector */ - IF ( ii == len - 1 ) + IF( EQ_16( ii, sub( len, 1 ) ) ) { BREAK; /* We assign the last point differently out of the loop */ } /* Found new peak that was larger than temp mag and selectivity larger than the minimum to its left. */ - IF ( ( x[ii] > tempMag ) && ( x[ii] > leftMin + sel ) ) + test(); + IF( GT_32( x[ii], tempMag ) && GT_32( x[ii], L_add( leftMin, sel ) ) ) { tempLoc = ii; + move16(); tempMag = x[ii]; + move32(); } ii++; /* Move onto the valley */ /* Come down at least sel from peak */ - IF ( !foundPeak && ( tempMag > sel + x[ii] ) ) + test(); + IF( !foundPeak && GT_32( tempMag, L_add( sel, x[ii] ) ) ) { foundPeak = 1; /* We have found a peak */ + move16(); leftMin = x[ii]; + move32(); peakLoc[*cInd] = tempLoc; /* Add peak to index */ + move16(); peakMag[*cInd] = tempMag; + move32(); ( *cInd )++; } - ELSE IF ( x[ii] < leftMin ) /* New left minimum */ + ELSE IF( LT_32( x[ii], leftMin ) ) /* New left minimum */ { leftMin = x[ii]; + move32(); } } /* Check end point */ - IF ( x[len - 1] > tempMag && x[len - 1] > leftMin + sel ) + test(); + test(); + IF( GT_32( x[len - 1], tempMag ) && GT_32( x[len - 1], L_add( leftMin, sel ) ) ) { - peakLoc[*cInd] = len - 1; + peakLoc[*cInd] = sub( len, 1 ); + move16(); peakMag[*cInd] = x[len - 1]; + move32(); ( *cInd )++; } - ELSE IF ( !foundPeak && tempMag > minMag ) /* Check if we still need to add the last point */ + ELSE IF( !foundPeak && GT_32( tempMag, minMag ) ) /* Check if we still need to add the last point */ { peakLoc[*cInd] = tempLoc; + move16(); peakMag[*cInd] = tempMag; + move32(); ( *cInd )++; } /* Create output */ - FOR ( i = 0; i < *cInd; i++ ) + FOR( i = 0; i < *cInd; i++ ) { plocs[i] = ind[peakLoc[i]]; + move16(); } } ELSE { - IF ( endpoints ) + IF( endpoints ) { /* This is a monotone function where an endpoint is the only peak */ - xInd = ( x[0] > x[1] ) ? 0 : 1; + xInd = GT_32( x[0], x[1] ) ? 0 : 1; + move16(); peakMag[0] = x[xInd]; - IF ( GT_32(peakMag[0] , L_add(minMag , sel)) ) + move32(); + IF( GT_32( peakMag[0], L_add( minMag, sel ) ) ) { plocs[0] = ind[xInd]; + move16(); *cInd = 1; + move16(); } ELSE { *cInd = 0; + move16(); } } ELSE { /* Input constant or all zeros -- no peaks found */ *cInd = 0; + move16(); } } return; } -#if 0 -static void peakfinder_fx_32( - const Word32 *x0, /* i : vector from which the maxima will be found */ - const Word16 len0, /* i : length of input vector */ - Word16 *plocs, /* o : the indices 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 */ - ,const Word16 endpoints /* i : Flag to include endpoints in peak search */ -) -{ - const Word32 *pX0; - Word32 minMag, tempMag, leftMin; - Word32 dx0[L_PROT48k_2], x[L_PROT48k_2+1], peakMag[MAX_PLOCS]; - Word32 *pDx0, *pDx01, *pX; - Word16 i, len, tempLoc, foundPeak, ii, xInd, tmp16; - Word32 threshold, xAt0, xAt1, xAt2; - Word16 len0Minus1, len0Minus2, lenMinus1; - Word16 indarr[L_PROT48k_2+1], peakLoc[MAX_PLOCS]; - Word16 *pInd; - - tempLoc = 0; - - /* Find derivative */ - len0Minus1 = sub(len0, 1); - pX0 = x0 + 1; - v_sub_32(pX0, x0, dx0, len0Minus1); - - FOR (i=0; i 0))) - { - /* Set initial parameters for loop */ - tempMag = minMag; - move16(); - foundPeak = 0; - move16(); - leftMin = minMag; - move32(); - threshold = L_add(leftMin, sel); - - IF(endpoints) - { - /* Deal with first point a little differently since tacked it on - Calculate the sign of the derivative since we took the first point - on it does not necessarily alternate like the rest. */ - - /* The first point is larger or equal to the second */ - pX = x; - xAt0 = *pX++; - move32(); - xAt1 = *pX++; - move32(); - xAt2 = *pX--; /* After decrement, pX points to x[1]. */ move16(); - IF(GE_32(xAt0, xAt1)) - { - ii = -1; - move16(); - IF(GE_32(xAt1, xAt2)) /* x[1] is not extremum -> overwrite with x[0] */ - { - *pX = xAt0; /* x[1] = x[0] */ move16(); - tmp16 = *pInd++; - move16(); - *pInd++ = tmp16; /* ind[1] = ind[0] */ move16(); - len = sub(len, 1); - } - pX--; /* After decrement, pX points to x[0]. */ - } - ELSE /* First point is smaller than the second */ - { - ii = 0; - IF(LT_32(xAt1, xAt2)) /* x[1] is not extremum -> overwrite with x[0] */ - { - *pX = xAt0; /* x[1] = x[0] */ move16(); - tmp16 = *pInd++; - move16(); - *pInd++ = tmp16; /* ind[1] = ind[0] */ move16(); - len = sub(len, 1); - } - } - pX--; /* After decrement, pX points to either x[-1] or x[0]. */ - } - ELSE - { - ii = -1; /* First point is a peak */ - IF (GE_16(len , 2)) - { - IF (GE_32(x[1] , x[0])) - { - ii = 0; /* First point is a valley, skip it */ - } - } - } - *cInd = 0; - move16(); - /*Loop through extrema which should be peaks and then valleys*/ - lenMinus1 = sub(len, 1); - FOR (;;) - { - ii = add(ii, 1); /* This is a peak */ - - /* Make sure we don't iterate past the length of our vector */ - IF (GE_16(ii, lenMinus1)) - { - BREAK; - } - - /*Reset peak finding if we had a peak and the next peak is bigger - than the last or the left min was small enough to reset.*/ - IF (GT_16(foundPeak,0)) - { - tempMag = minMag; - move16(); - foundPeak = 0; - move16(); - } - - /* Found new peak that was larger than temp mag and selectivity larger - than the minimum to its left. */ - IF (GT_32(*(++pX), tempMag)) - { - IF ( GT_32(*pX, threshold)) /* threshold = leftMin + sel */ - { - tempLoc = ii; - move16(); - tempMag = *pX; - move16(); - } - } - - ii = add(ii, 1); /* Move onto the valley */ - pX++; - - /* Come down at least sel from peak */ - IF (foundPeak == 0) - { - IF (GT_32(tempMag, L_add(sel, *pX))) - { - foundPeak = 1; /* We have found a peak */ move16(); - leftMin = *pX; - move16(); - threshold = L_add(leftMin, sel); - peakLoc[*cInd] = tempLoc; /* Add peak to index */ move16(); - peakMag[*cInd] = tempMag; - move16(); - *cInd = add(*cInd, 1); - } - } - IF (foundPeak == 0) /* The above IF-block has not found the peak yet. */ - { - IF (LT_32(*pX, leftMin))/* New left minimum */ - { - leftMin = *pX; - move16(); - threshold = L_add(leftMin, sel); - } - } - } - - /* Check end point */ - IF (GT_32(x[lenMinus1], tempMag)) - { - IF (GT_32(x[lenMinus1], threshold)) /* threshold = leftMin + sel */ - { - peakLoc[*cInd] = lenMinus1; - move16(); - peakMag[*cInd] = x[lenMinus1]; - move16(); - *cInd = add(*cInd, 1); - foundPeak = 1; - move16(); - } - } - IF (foundPeak == 0) /* Check if we still need to add the last point */ - { - IF (GT_32(tempMag, minMag)) - { - peakLoc[*cInd] = tempLoc; - move16(); - peakMag[*cInd] = tempMag; - move16(); - *cInd = add(*cInd, 1); - } - } - - /* Create output */ - FOR (i = 0; i < *cInd; i++) - { - plocs[i] = *(indarr + peakLoc[i]); - move16(); - move16(); - } - } - ELSE /* This is a monotone function where an endpoint is the only peak */ - { - IF(endpoints) - { - xInd = 1; - move16(); - IF (GT_32(x[0], x[1])) - { - xInd = 0; - move16(); - } - - peakMag[0] = x[xInd]; - move16(); - IF(GT_32(peakMag[0], L_add(minMag, sel))) - { - plocs[0] = *(indarr + xInd); - move16(); - *cInd = 1; - move16(); - } - ELSE - { - *cInd = 0; - move16(); - } - } - ELSE - {/* Input constant or all zeros -- no peaks found */ - *cInd = 0; - move16(); - } - } -} -#endif /*--------------------------------------------------------------- * stereo_dft_res_subst_spec_fx() @@ -723,16 +502,16 @@ static void peakfinder_fx_32( 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 */ + 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 */ ) { Word16 i, idx; @@ -755,50 +534,51 @@ void stereo_dft_res_subst_spec_fx( Copy32( DFT_PRED_RES, pDFT_RES, 2 * L_res ); p_mem = hStereoDft->res_mem_fx; Np = 1; + move16(); - IF ( analysis_flag ) + IF( analysis_flag ) { - Word16 q_res = sub(getScaleFactor32(p_mem, shl(L_res, 1)) , 2); + 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 */ move32(); - FOR ( i = 1; i < L_res; i++ ) + FOR( i = 1; i < L_res; i++ ) { - Word32 r = L_shl(p_mem[2 * i], q_res); - Word32 l = L_shl(p_mem[2 * i + 1], q_res); - abs_res[i] = Madd_32_32(Mpy_32_32( r, r) , l, l ); + Word32 r = L_shl( p_mem[2 * i], q_res ); + Word32 l = L_shl( p_mem[2 * i + 1], q_res ); + abs_res[i] = Madd_32_32( Mpy_32_32( r, r ), l, l ); 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 ) ); ivas_peakfinder_fx( abs_res, L_res, plocs, num_plocs, sel, FALSE ); /* Refine peaks */ - FOR ( i = 0; i < *num_plocs; i++ ) + FOR( i = 0; i < *num_plocs; i++ ) { - IF ( EQ_16(plocs[i] , 0) ) + IF( EQ_16( 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 ) ); move32(); } - ELSE IF ( EQ_16(plocs[i] , L_res) ) + 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 ) ); 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 ) ); move16(); } } } /* Apply phase of stereo filling on noise spectrum */ - FOR ( i = 1; i < L_res; i++ ) + FOR( i = 1; i < L_res; i++ ) { s1 = sign_l( pDFT_RES[2 * i] ); s2 = sign_l( pDFT_RES[2 * i + 1] ); @@ -810,73 +590,80 @@ void stereo_dft_res_subst_spec_fx( fac = MAX_16; move16(); /* Low-complex phase matching that brings the angle within pi/4 of the target angle */ - IF ( ( GT_32( abs1 , abs2 ) && LT_32( abs3 , abs4 ) ) || ( LE_32( abs1 , abs2 ) && GE_32( abs3 , abs4 ) ) ) + 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 ); move32(); - pDFT_RES[2 * i + 1] = Mpy_32_32(s2 , abs3); + pDFT_RES[2 * i + 1] = Mpy_32_32( s2, abs3 ); move32(); } ELSE { - pDFT_RES[2 * i] = Mpy_32_32(s1 , abs3); + pDFT_RES[2 * i] = Mpy_32_32( s1, abs3 ); move32(); - pDFT_RES[2 * i + 1] = Mpy_32_32(s2 , abs4); + pDFT_RES[2 * i + 1] = Mpy_32_32( s2, abs4 ); move32(); } } /* Apply phase adjustment of identified peaks, including Np=1 peak neighbors on each side */ - FOR ( i = *num_plocs - 1; i >= 0; i-- ) + FOR( i = *num_plocs - 1; i >= 0; i-- ) { Flag flg_ov; - IF ( EQ_16(k , 0) ) + IF( EQ_16( k, 0 ) ) { Word32 op; Word16 q_div, q_shift; /* For 1st subframe, apply reversed time ECU to get correct analysis window */ - f_frac = extract_l(L_shr(L_sub(plocsi[i] , L_shl(plocs[i], Q16)),1)); + f_frac = extract_l( L_shr( L_sub( plocsi[i], L_shl( plocs[i], Q16 ) ), 1 ) ); peak_phase = BASOP_util_atan2( p_mem[2 * plocs[i] + 1], p_mem[2 * plocs[i]], 0 ); - phase_tmp = L_sub(peak_phase , mult(f_frac , STEREO_DFT_PLC_PH_C_FX)); - phase = L_sub(phase_tmp , mult(f_frac , EVS_PI_FX)); - op = L_negate(L_shl(phase, 1)); - corr_phase = L_add( L_add( STEREO_DFT_PLC_STEP21 , L_ana) , time_offs ) ; - q_shift = norm_l(corr_phase); - corr_phase = Mpy_32_32(L_shl(corr_phase, q_shift), plocsi[i]); - 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); - WHILE ( LT_32(corr_phase, -EVS_PI_FX) ) + phase_tmp = L_sub( peak_phase, mult( f_frac, STEREO_DFT_PLC_PH_C_FX ) ); + phase = L_sub( phase_tmp, mult( f_frac, EVS_PI_FX ) ); + op = L_negate( L_shl( phase, 1 ) ); + corr_phase = L_add( L_add( STEREO_DFT_PLC_STEP21, L_ana ), time_offs ); + q_shift = norm_l( corr_phase ); + corr_phase = Mpy_32_32( L_shl( corr_phase, q_shift ), plocsi[i] ); + 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 ); + 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 ); } - WHILE ( GT_32(corr_phase, EVS_PI_FX) ) + 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 ); } conj_sign = MIN_32; + move32(); } ELSE { - Word32 op = L_add(L_ana, time_offs); + Word32 op = L_add( L_ana, time_offs ); Word16 q_div; - op = Mpy_32_32(L_shl(op, Q15), plocsi[i]); - 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)); + op = Mpy_32_32( L_shl( op, Q15 ), plocsi[i] ); + 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 ) ); /* For 2nd subframe, do regular phase shift */ - corr_phase = L_negate(L_shr(L_mult0(extract_l(corr_phase), EVS_PI_FX), Q14)); + corr_phase = L_negate( L_shr( L_mult0( extract_l( corr_phase ), EVS_PI_FX ), Q14 ) ); conj_sign = MAX_32; + move32(); } - cos_F = shl_o(getCosWord16(extract_l(corr_phase)), 1, &flg_ov); - sin_F = getSinWord16(extract_l(corr_phase)); + cos_F = shl_o( getCosWord16( extract_l( corr_phase ) ), 1, &flg_ov ); + sin_F = getSinWord16( extract_l( corr_phase ) ); - idx = max( 0, plocs[i] - Np ); /* Iterate over plocs[i]-1:plocs[i]+1, considering the edges of the spectrum */ - WHILE ( ( idx < plocs[i] + Np + 1 ) && ( idx < L_res ) ) + idx = s_max( 0, 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[2 * idx + 1] , sin_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)); + pDFT_RES[2 * idx] = Msub_32_16( Mpy_32_16_1( p_mem[2 * idx], cos_F ), p_mem[2 * idx + 1], sin_F ); + move32(); + 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 ) ); + move32(); idx++; } } @@ -892,30 +679,32 @@ 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 */ + 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 */ ) { Word32 fac; Word16 q_fac; Word16 exponent; - q_fac = 0; move16(); - exponent = 0; move16(); + q_fac = 0; + move16(); + exponent = 0; + move16(); /* attenuation of residual; follow attenuation of DMX */ - IF ( EQ_16(hStereoDft->core_hist[0] , ACELP_CORE) ) + IF( EQ_16( 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 ) ); } 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 ) ) ); } - v_multc_fixed( pDFT_RES, fac, pDFT_RES, shl(L_res, 1) ); + v_multc_fixed( pDFT_RES, fac, pDFT_RES, shl( L_res, 1 ) ); return; } @@ -932,30 +721,30 @@ Word32 stereo_dft_dmx_swb_nrg_fx( const Word32 *dmx_k1, /* i : second subframe spectrum */ const int16_t frame_length, /* i : frame lanegth */ const Word16 q0, - const Word16 q1 -) + const Word16 q1 ) { int16_t i; Word32 dmx_nrg; dmx_nrg = EPSILON_FIX; move32(); - IF (EQ_16(q0, 0) && EQ_16(q1, 0)) + test(); + IF( EQ_16( q0, 0 ) && EQ_16( q1, 0 ) ) { - FOR ( i = 0; i < shr(frame_length, 1); i++ ) + FOR( i = 0; i < shr( frame_length, 1 ); 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)]))); + 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 )] ) ) ); } } ELSE { - FOR ( i = 0; i < shr(frame_length, 1); i++ ) + FOR( i = 0; i < shr( frame_length, 1 ); 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))); + 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 ) ) ); } } @@ -978,31 +767,36 @@ Word16 stereo_dft_sg_recovery_fx( Word32 sg_m; Word16 beta; - IF ( !hStereoDft->sg_mem_corrupt ) + test(); + IF( !hStereoDft->sg_mem_corrupt ) { pSideGain = hStereoDft->side_gain_fx + 2 * STEREO_DFT_BAND_MAX; - beta = (Word16)(0x3666); + beta = (Word16) ( 0x3666 ); + move16(); sg_m = EPSILON_FIX; - FOR ( b = 0; b < hStereoDft->nbands; b++ ) + 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 ) ); } sg_m /= hStereoDft->nbands; sg_m = L_shl_sat( sg_m, 5 ); - IF ( LT_32(sg_m , (Word32)0x4CCCCCCD) && GT_32(sg_m , (Word32)(0xB3333333) )) + test(); + IF( LT_32( sg_m, (Word32) 0x4CCCCCCD ) && GT_32( sg_m, (Word32) ( 0xB3333333 ) ) ) { hStereoDft->sg_mean_fx = 0; + 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 */ } } - ELSE IF ( GT_32(hStereoDft->sg_mean_fx , (Word32)0x4CCCCCCD) || LT_32(hStereoDft->sg_mean_fx , (Word32)(0xB3333333)) ) + ELSE IF( GT_32( hStereoDft->sg_mean_fx, (Word32) 0x4CCCCCCD ) || LT_32( hStereoDft->sg_mean_fx, (Word32) ( 0xB3333333 ) ) ) { - return MAX_16; + return 1; } return 0; diff --git a/lib_dec/ivas_stereo_ica_dec.c b/lib_dec/ivas_stereo_ica_dec.c index ee8e8b4759a6b11f6f4e5d330d0df25caa50b17e..9c1f34218c728359d777049b10ab8869bda3351a 100644 --- a/lib_dec/ivas_stereo_ica_dec.c +++ b/lib_dec/ivas_stereo_ica_dec.c @@ -54,9 +54,6 @@ * upnmix, convert L/R to M/S. * ---------------------------------------------------------------*/ - - - #ifdef IVAS_FLOAT_FIXED void stereo_tca_dec_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -79,27 +76,31 @@ void stereo_tca_dec_fx( hStereoTCA = hCPE->hStereoTCA; output_Fs = hCPE->hCoreCoder[0]->output_Fs; + move32(); - IF( hCPE->nchan_out == 1 ) + test(); + IF( EQ_16( hCPE->nchan_out, 1 ) ) { IF( hCPE->hStereoDftDmx ) { - IF( hCPE->element_mode == IVAS_CPE_DFT ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { // to be deleted next MR hCPE->hStereoDftDmx->targetGain = 1.0f; hCPE->hStereoDftDmx->targetGain_fx = ONE_IN_Q29; + move32(); } /* save the target gain for next frame */ // to be deleted next MR hCPE->hStereoDftDmx->prevTargetGain = hCPE->hStereoDftDmx->targetGain; hCPE->hStereoDftDmx->prevTargetGain_fx = hCPE->hStereoDftDmx->targetGain_fx; + move32(); } return; } - ELSE IF( hCPE->element_mode == IVAS_CPE_MDCT && !hCPE->hStereoMdct->use_itd ) + ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && !hCPE->hStereoMdct->use_itd ) { return; } @@ -123,109 +124,139 @@ void stereo_tca_dec_fx( /* TCA parameter de-quantize */ dsFactor = (Word16) ( output_Fs / 8000 ); tempMax = NS2SA( output_Fs, L_NCSHIFT_NS ); - hStereoTCA->corrLagStats = min( hStereoTCA->indx_ica_NCShift * dsFactor, tempMax ); + hStereoTCA->corrLagStats = s_min( hStereoTCA->indx_ica_NCShift * dsFactor, tempMax ); bothChannelShift = 0; - IF( hCPE->element_mode == IVAS_CPE_DFT || hCPE->element_mode == IVAS_CPE_MDCT ) + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { hStereoTCA->corrLagStats = 0; + move16(); hStereoTCA->refChanIndx = L_CH_INDX; - hStereoTCA->targetGain = 1.0f; + move16(); hStereoTCA->targetGain_fx = ONE_IN_Q29; + move16(); - IF( hCPE->element_mode == IVAS_CPE_DFT ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - hStereoTCA->corrLagStats = (Word16) fabsf( hCPE->hStereoDft->itd[1] ); - hStereoTCA->refChanIndx = ( hCPE->hStereoDft->itd[1] >= 0 ) ? ( L_CH_INDX ) : ( R_CH_INDX ); + hStereoTCA->corrLagStats = extract_l( L_abs( L_shr( hCPE->hStereoDft->itd_fx[1], Q15 ) ) ); + hStereoTCA->refChanIndx = GE_32( hCPE->hStereoDft->itd_fx[1], 0 ) ? ( L_CH_INDX ) : ( R_CH_INDX ); + move16(); } - ELSE IF( hCPE->element_mode == IVAS_CPE_MDCT ) + ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { - float itd; + Word32 itd; - itd = hCPE->hStereoMdct->itd; - hStereoTCA->corrLagStats = (Word16) fabsf( itd ); - hStereoTCA->refChanIndx = ( itd >= 0 ) ? ( L_CH_INDX ) : ( R_CH_INDX ); + itd = hCPE->hStereoMdct->itd_fx; + move32(); + hStereoTCA->corrLagStats = extract_l( L_abs( L_shr( itd, Q15 ) ) ); + hStereoTCA->refChanIndx = GE_32( itd, 0 ) ? ( L_CH_INDX ) : ( R_CH_INDX ); + move16(); } - IF( hStereoTCA->refChanIndx != hStereoTCA->prevRefChanIndx && hStereoTCA->corrLagStats != 0 ) + test(); + IF( NE_16( hStereoTCA->refChanIndx, hStereoTCA->prevRefChanIndx ) && NE_16( hStereoTCA->corrLagStats, 0 ) ) { bothChannelShift = 1; + move16(); } } - prevNCShift = (Word16) abs( hStereoTCA->prevCorrLagStats ); - currentNCShift = (Word16) abs( hStereoTCA->corrLagStats ); + prevNCShift = abs_s( hStereoTCA->prevCorrLagStats ); + currentNCShift = abs_s( hStereoTCA->corrLagStats ); - IF( hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode == IVAS_CPE_TD ) + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) ) { - IF( hStereoTCA->corrLagStats == hStereoTCA->prevCorrLagStats && hStereoTCA->interp_dec_switch_to_zero_diff == 0 ) + test(); + IF( EQ_16( hStereoTCA->corrLagStats, hStereoTCA->prevCorrLagStats ) && EQ_16( hStereoTCA->interp_dec_switch_to_zero_diff, 0 ) ) { hStereoTCA->interp_dec_switch_to_zero_diff = 1; + move16(); } ELSE { hStereoTCA->interp_dec_switch_to_zero_diff = 0; + move16(); } - IF( currentNCShift != 0 ) + IF( NE_16( currentNCShift, 0 ) ) { - currentNCShift = TRUNC( 0.6 * prevNCShift + 0.4 * currentNCShift ); + currentNCShift = add( mult( 19660, prevNCShift ), mult( 13106, currentNCShift ) ); } prevNCShift = hStereoTCA->interp_dec_prevNCShift; + move16(); hStereoTCA->interp_dec_prevNCShift = currentNCShift; + move16(); } ELSE { hStereoTCA->interp_dec_prevNCShift = currentNCShift; + move16(); hStereoTCA->interp_dec_switch_to_zero_diff = 0; + move16(); } ref_fx = ptrChanL_fx; target_fx = ptrChanR_fx; target_idx = R_CH_INDX; + move16(); /* identify target signal to adjust for shift variations */ - IF( ( prevNCShift == 0 && hStereoTCA->refChanIndx == R_CH_INDX ) || ( hStereoTCA->prevRefChanIndx == R_CH_INDX ) ) + test(); + test(); + test(); + IF( ( EQ_16( prevNCShift, 0 ) && EQ_16( hStereoTCA->refChanIndx, R_CH_INDX ) ) || EQ_16( hStereoTCA->prevRefChanIndx, R_CH_INDX ) ) { ref_fx = ptrChanR_fx; target_fx = ptrChanL_fx; target_idx = L_CH_INDX; + move16(); } - IF( bothChannelShift == 1 ) + IF( EQ_16( bothChannelShift, 1 ) ) { ref_fx = ptrChanL_fx; target_fx = ptrChanR_fx; target_idx = R_CH_INDX; - IF( hStereoTCA->refChanIndx == R_CH_INDX ) + move16(); + IF( EQ_16( hStereoTCA->refChanIndx, R_CH_INDX ) ) { ref_fx = ptrChanR_fx; target_fx = ptrChanL_fx; target_idx = L_CH_INDX; + move16(); } } /* target signal adjustment for temporal shift variations */ - IF( hStereoTCA->prevCorrLagStats != hStereoTCA->corrLagStats || bothChannelShift || ( hStereoTCA->interp_dec_switch_to_zero_diff == 1 && hCPE->element_mode == IVAS_CPE_TD ) ) + test(); + test(); + test(); + IF( NE_16( hStereoTCA->prevCorrLagStats, hStereoTCA->corrLagStats ) || bothChannelShift || ( EQ_16( hStereoTCA->interp_dec_switch_to_zero_diff, 1 ) && EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) ) { l_shift_adapt = L_SHIFT_ADAPT_16k; - IF( output_Fs > 16000 ) + move16(); + IF( GT_32( output_Fs, 16000 ) ) { l_shift_adapt = L_SHIFT_ADAPT_MAX; + move16(); } - IF( hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode == IVAS_CPE_DFT ) + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { - l_shift_adapt = l_shift_adapt >> 1; + l_shift_adapt = shr( l_shift_adapt, 1 ); } - IF( abs( currentNCShift - prevNCShift ) <= N_MAX_SHIFT_CHANGE && bothChannelShift == 0 ) + test(); + IF( LE_16( abs_s( sub( currentNCShift, prevNCShift ) ), N_MAX_SHIFT_CHANGE ) && EQ_16( bothChannelShift, 0 ) ) { adjustTargetSignal_fx( target_fx - currentNCShift, currentNCShift, prevNCShift, l_shift_adapt, 0 ); } ELSE { - IF( bothChannelShift == 1 ) + IF( EQ_16( bothChannelShift, 1 ) ) { adjustTargetSignal_fx( ref_fx, 0, prevNCShift, l_shift_adapt, 1 ); adjustTargetSignal_fx( target_fx - currentNCShift, currentNCShift, 0, l_shift_adapt, 1 ); @@ -251,18 +282,18 @@ void stereo_tca_dec_fx( /* save the reference channel index for next frame */ hStereoTCA->prevRefChanIndx = hStereoTCA->refChanIndx; + move16(); /* save the corr lag stats for next frame */ hStereoTCA->prevCorrLagStats = hStereoTCA->corrLagStats; + move16(); /* save the target gain for next frame */ - //To delete below in next MR - hStereoTCA->prevTargetGain = hStereoTCA->targetGain; hStereoTCA->prevTargetGain_fx = hStereoTCA->targetGain_fx; + move32(); return; } #else - void stereo_tca_dec( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ float *synth[CPE_CHANNELS], /* i/o: output synth */ @@ -467,6 +498,7 @@ void stereo_tca_dec( * Scale the Right channel with the gain *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void stereo_tca_scale_R_channel( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ float *output, /* i/o: output synthesis, R channel */ @@ -538,9 +570,7 @@ void stereo_tca_scale_R_channel( return; } - -#ifdef IVAS_FLOAT_FIXED - +#else #define MAX_TARGET_GAIN_Q29 1904890240 void stereo_tca_scale_R_channel_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -553,52 +583,61 @@ void stereo_tca_scale_R_channel_fx( Word16 i_fx; Word32 tempF_fx, tempF1_fx, winSlope_fx = 0; Word32 output_Fs; + move16(); hStereoTCA = hCPE->hStereoTCA; output_Fs = hCPE->hCoreCoder[0]->output_Fs; + move32(); - IF( hCPE->hCoreCoder[0]->core_brate <= SID_2k40 && hCPE->nchan_out == 2 ) + test(); + IF( LE_32( hCPE->hCoreCoder[0]->core_brate, SID_2k40 ) && EQ_16( hCPE->nchan_out, 2 ) ) { return; } /* Scale the Right channel with the gain */ l_ica_ovl = NS2SA( output_Fs, STEREO_L_TCA_OVLP_NS ); + move16(); - - IF( hCPE->nchan_out == 1 ) + test(); + IF( EQ_16( hCPE->nchan_out, 1 ) ) { /* in mono DMX, the scaling is done before synchro_synthesis() */ flat_old = NS2SA( output_Fs, ACELP_LOOK_NS + IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); + move16(); - IF( hCPE->last_element_mode == IVAS_CPE_TD && hCPE->element_mode == IVAS_CPE_DFT ) + test(); + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { Word64 local_value; // to be deleted next MR - hCPE->hStereoDftDmx->prevTargetGain *= 2.0f; - hCPE->hStereoDftDmx->prevTargetGain = min( hCPE->hStereoDftDmx->prevTargetGain, powf( 10, ( ( 1 << STEREO_BITS_TCA_GD ) - 1 ) * STEREO_TCA_GDSTEP + STEREO_TCA_GDMIN ) ); - local_value = (Word64) hCPE->hStereoDftDmx->prevTargetGain_fx << 1; + // hCPE->hStereoDftDmx->prevTargetGain *= 2.0f; + // hCPE->hStereoDftDmx->prevTargetGain = min( hCPE->hStereoDftDmx->prevTargetGain, powf( 10, ( ( 1 << STEREO_BITS_TCA_GD ) - 1 ) * STEREO_TCA_GDSTEP + STEREO_TCA_GDMIN ) ); + local_value = W_shl( hCPE->hStereoDftDmx->prevTargetGain_fx, 1 ); hCPE->hStereoDftDmx->prevTargetGain_fx = (Word32) min( local_value, MAX_TARGET_GAIN_Q29 ); - // to be deleted next MR - hCPE->hStereoDftDmx->targetGain = 1.0f; hCPE->hStereoDftDmx->targetGain_fx = ONE_IN_Q29; + move32(); flat_old = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); + move16(); } } - ELSE IF( hCPE->last_element_mode == IVAS_CPE_TD && hCPE->element_mode == IVAS_CPE_DFT ) + ELSE IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { flat_old = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); + move16(); } ELSE { flat_old = NS2SA( output_Fs, ACELP_LOOK_NS + IVAS_DEC_DELAY_NS ); + move16(); } - IF( hCPE->nchan_out == 1 ) + IF( EQ_16( hCPE->nchan_out, 1 ) ) { - IF( hCPE->hStereoDftDmx->targetGain_fx == ONE_IN_Q29 ) + IF( EQ_32( hCPE->hStereoDftDmx->targetGain_fx, ONE_IN_Q29 ) ) { tempF1_fx = ONE_IN_Q27; + move32(); } ELSE { @@ -608,9 +647,10 @@ void stereo_tca_scale_R_channel_fx( tempF1_fx = L_shl( tempF1_fx, ( 31 - 4 ) - ( 15 - temp_a_q ) ); } - IF( hCPE->hStereoDftDmx->prevTargetGain_fx == ONE_IN_Q29 ) + IF( EQ_32( hCPE->hStereoDftDmx->prevTargetGain_fx, ONE_IN_Q29 ) ) { tempF_fx = ONE_IN_Q27; + move32(); } ELSE { @@ -623,9 +663,10 @@ void stereo_tca_scale_R_channel_fx( ELSE { - IF( hStereoTCA->targetGain_fx == ONE_IN_Q29 ) + IF( EQ_32( hStereoTCA->targetGain_fx, ONE_IN_Q29 ) ) { tempF1_fx = ONE_IN_Q27; + move32(); } ELSE { @@ -636,9 +677,10 @@ void stereo_tca_scale_R_channel_fx( } - IF( hStereoTCA->prevTargetGain_fx == ONE_IN_Q29 ) + IF( EQ_32( hStereoTCA->prevTargetGain_fx, ONE_IN_Q29 ) ) { tempF_fx = ONE_IN_Q27; + move32(); } ELSE { @@ -652,73 +694,82 @@ void stereo_tca_scale_R_channel_fx( { case 16000: winSlope_fx = 26843546; - break; + move32(); + BREAK; case 32000: winSlope_fx = 13421773; - break; + move32(); + BREAK; case 48000: winSlope_fx = 8947849; - break; + move32(); + BREAK; } - IF( tempF_fx == ONE_IN_Q27 ) + IF( EQ_32( tempF_fx, ONE_IN_Q27 ) ) { - for ( i_fx = 0; i_fx < flat_old; i_fx++ ) + FOR( i_fx = 0; i_fx < flat_old; i_fx++ ) { output_fx[i_fx] = output_fx[i_fx]; + move32(); } } ELSE { - for ( i_fx = 0; i_fx < flat_old; i_fx++ ) + FOR( i_fx = 0; i_fx < flat_old; i_fx++ ) { output_fx[i_fx] = L_shl_sat( Mpy_32_32( output_fx[i_fx], tempF_fx ), 4 ); + move32(); } } - - IF( tempF1_fx == ONE_IN_Q27 && tempF_fx == ONE_IN_Q27 ) + test(); + IF( EQ_32( tempF1_fx, ONE_IN_Q27 ) && EQ_32( tempF_fx, ONE_IN_Q27 ) ) { - for ( j = 0; i_fx < flat_old + l_ica_ovl; i_fx++, j++ ) + FOR( j = 0; i_fx < flat_old + l_ica_ovl; ( i_fx++, j++ ) ) { Word32 slope_gain_decend = L_sub( ONE_IN_Q31, j * winSlope_fx ); Word32 slope_gain_ascend = ( j * winSlope_fx ); Word32 left_res = Mpy_32_32( slope_gain_decend, output_fx[i_fx] ); Word32 right_res = Mpy_32_32( slope_gain_ascend, output_fx[i_fx] ); output_fx[i_fx] = left_res + right_res; + move32(); } } ELSE { - for ( j = 0; i_fx < flat_old + l_ica_ovl; i_fx++, j++ ) + FOR( j = 0; i_fx < flat_old + l_ica_ovl; ( i_fx++, j++ ) ) { Word32 slope_gain_decend = L_sub( ONE_IN_Q31, j * winSlope_fx ); Word32 slope_gain_ascend = ( j * winSlope_fx ); Word32 left_res = Mpy_32_32( slope_gain_decend, output_fx[i_fx] ); Word32 right_res = Mpy_32_32( slope_gain_ascend, output_fx[i_fx] ); output_fx[i_fx] = L_add_sat( L_shl_sat( Mpy_32_32( tempF_fx, left_res ), 4 ), L_shl_sat( Mpy_32_32( right_res, tempF1_fx ), 4 ) ); + move32(); } } - IF( tempF1_fx == ONE_IN_Q27 ) + IF( EQ_32( tempF1_fx, ONE_IN_Q27 ) ) { - for ( ; i_fx < output_frame; i_fx++ ) + FOR( ; i_fx < output_frame; i_fx++ ) { output_fx[i_fx] = output_fx[i_fx]; + move32(); } } ELSE { - for ( ; i_fx < output_frame; i_fx++ ) + FOR( ; i_fx < output_frame; i_fx++ ) { output_fx[i_fx] = L_shl_sat( Mpy_32_32( output_fx[i_fx], tempF1_fx ), 4 ); + move32(); } } return; } - #endif + /*-------------------------------------------------------------------* * stereo_tca_init_dec() * @@ -733,30 +784,34 @@ void stereo_tca_init_dec_fx( ) { hStereoTCA->refChanIndx = L_CH_INDX; + move16(); hStereoTCA->prevRefChanIndx = L_CH_INDX; + move16(); hStereoTCA->indx_ica_NCShift = 0; + move16(); hStereoTCA->indx_ica_gD = 0; - hStereoTCA->targetGain = 1.0f; /* TODO: Remove float init*/ + move16(); hStereoTCA->targetGain_fx = ONE_IN_Q29; + move32(); hStereoTCA->prevTargetGain_fx = ONE_IN_Q29; - hStereoTCA->prevTargetGain = 1.0f; /* TODO: Remove float init*/ + move32(); hStereoTCA->corrLagStats = 0; + move16(); hStereoTCA->prevCorrLagStats = 0; + move16(); hStereoTCA->interp_dec_prevNCShift = 0; + move16(); hStereoTCA->interp_dec_switch_to_zero_diff = 0; - + move16(); set32_fx( hStereoTCA->memChanL_fx, 0, L_DEC_MEM_LEN_ICA ); set32_fx( hStereoTCA->memChanR_fx, 0, L_DEC_MEM_LEN_ICA ); - return; } - #else - void stereo_tca_init_dec( STEREO_TCA_DEC_HANDLE hStereoTCA /* i/o: Stereo TCA handle */ ) diff --git a/lib_dec/ivas_stereo_icbwe_dec.c b/lib_dec/ivas_stereo_icbwe_dec.c index c2e2f43930fb79bc12474389cc3f6b18222748b3..7e0d1ab82abc730263c9524b84e58200698f16b6 100644 --- a/lib_dec/ivas_stereo_icbwe_dec.c +++ b/lib_dec/ivas_stereo_icbwe_dec.c @@ -53,6 +53,7 @@ * core switching reset of IC BWE memory *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void ic_bwe_dec_reset( STEREO_ICBWE_DEC_HANDLE hStereoICBWE /* i/o: Stereo ICBWE handle */ ) @@ -61,42 +62,60 @@ static void ic_bwe_dec_reset( set_f( hStereoICBWE->mem_syn_shb_nonref, 0, L_SHB_LAHEAD ); /* use samples from !acelp) */ set_f( hStereoICBWE->mem_lpc_shbsynth_nonref, 0, LPC_SHB_ORDER ); set_f( hStereoICBWE->mem_syn_shb_ola_nonref, 0, L_SHB_LAHEAD ); /* use samples from !acelp) */ -#ifdef IVAS_FLOAT_FIXED + + /* inter-channel BWE SP and GSP mem reset */ + hStereoICBWE->memShbSpecMapping = 0; + + set_f( hStereoICBWE->memShbHilbert_nonref, 0, HILBERT_MEM_SIZE ); + set_f( hStereoICBWE->memShbInterp_nonref, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set_f( hStereoICBWE->memShb_fsout_nonref, 0, INTERP_3_2_MEM_LEN ); + hStereoICBWE->syn_dm_phase_nonref = 0; + + return; +} +#else +static void ic_bwe_dec_reset_fx( + STEREO_ICBWE_DEC_HANDLE hStereoICBWE /* i/o: Stereo ICBWE handle */ +) +{ + /* unscaled & scaled SHB synthesis memory */ set32_fx( hStereoICBWE->mem_syn_shb_nonref_fx, 0, L_SHB_LAHEAD ); /* use samples from !acelp) */ set32_fx( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 0, LPC_SHB_ORDER ); set32_fx( hStereoICBWE->mem_syn_shb_ola_nonref_fx, 0, L_SHB_LAHEAD ); /* use samples from !acelp) */ - hStereoICBWE->prev_Q_lpc_shbsynth = 31; hStereoICBWE->prev_Q_syn_shb_nonref = 31; - hStereoICBWE->prev_Q_syn_shb_ola = 31; + move16(); + hStereoICBWE->prev_Q_lpc_shbsynth_nonref = 31; + move16(); + hStereoICBWE->prev_Q_syn_shb_ola_nonref = 31; + move16(); -#endif /* inter-channel BWE SP and GSP mem reset */ - hStereoICBWE->memShbSpecMapping = 0; -#ifdef IVAS_FLOAT_FIXED hStereoICBWE->memShbSpecMapping_fx = 0; + move32(); hStereoICBWE->prev_Q_memshbspec = 31; + move16(); -#endif - - set_f( hStereoICBWE->memShbHilbert_nonref, 0, HILBERT_MEM_SIZE ); - set_f( hStereoICBWE->memShbInterp_nonref, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set_f( hStereoICBWE->memShb_fsout_nonref, 0, INTERP_3_2_MEM_LEN ); -#ifdef IVAS_FLOAT_FIXED set32_fx( hStereoICBWE->memShbHilbert_nonref_fx, 0, HILBERT_MEM_SIZE ); set32_fx( hStereoICBWE->memShbInterp_nonref_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set32_fx( hStereoICBWE->memShb_fsout_nonref_fx, 0, INTERP_3_2_MEM_LEN ); hStereoICBWE->prev_Q_hilb = 31; + move16(); hStereoICBWE->prev_Q_interp = 31; + move16(); hStereoICBWE->prev_Q_fsout = 31; -#endif + move16(); + hStereoICBWE->syn_dm_phase_nonref = 0; + move16(); return; } +#endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * stereo_icBWE_dec() * @@ -506,8 +525,7 @@ void stereo_icBWE_dec( return; } -#ifdef IVAS_FLOAT_FIXED - +#else static Word16 FindScale( Word32 *buff, Word16 len, @@ -522,9 +540,10 @@ static Word16 FindScale( IF( EQ_32( maxVal, 0 ) ) { norm_shift = 31; + move16(); } - Q_out = min( Q_prev, add( Q_buff, norm_shift ) ); + Q_out = s_min( Q_prev, add( Q_buff, norm_shift ) ); return Q_out; } @@ -540,9 +559,9 @@ void stereo_icBWE_dec_fx( Word16 *Q_syn /* i : Q of synth and synthRef buffers */ ) { - int16_t i, j, k, nbSubFr; + Word16 i, j, k, nbSubFr; Decoder_State *st; /* i/o: decoder state structure, primary channel */ - int16_t spIndx, gsIndx; + Word16 spIndx, gsIndx; Word32 excSHB_nonref_fx[L_FRAME16k]; Word32 shb_synth_nonref_fx[L_FRAME16k + L_SHB_LAHEAD]; Word32 error_fx[L_FRAME32k]; @@ -583,7 +602,6 @@ void stereo_icBWE_dec_fx( } ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) { - return; } @@ -638,6 +656,7 @@ void stereo_icBWE_dec_fx( } hCPE->hStereoDft->hb_nrg_subr_fx[1] = hb_nrg2_fx; // 2*(Qx + SynthRef_shift) - 31 + move32(); hb_nrg_fx = L_add( hb_nrg_fx, hb_nrg2_fx ); Copy32( synthRef_fx, hCPE->hStereoDft->hb_stefi_sig_fx + hCPE->hStereoDft->hb_stefi_delay, output_frame ); @@ -647,7 +666,9 @@ void stereo_icBWE_dec_fx( set32_fx( hCPE->hStereoDft->hb_stefi_sig_fx + hCPE->hStereoDft->hb_stefi_delay, 0, output_frame ); } hCPE->hStereoDft->hb_nrg_subr_fx[0] = ( Mpy_32_16_1( hCPE->hStereoDft->hb_nrg_subr_fx[0], shl( hCPE->hStereoDft->NFFT / 2, 6 ) ) ); // 2 * (Qx + SynthRef_shift) - 40 // 2 * (Qx + SynthRef_shift) - 31 - 15 + move32(); hCPE->hStereoDft->hb_nrg_subr_fx[1] = ( Mpy_32_16_1( hCPE->hStereoDft->hb_nrg_subr_fx[1], shl( hCPE->hStereoDft->NFFT / 2, 6 ) ) ); // 2 * (Qx + SynthRef_shift) - 40 + move32(); hCPE->hStereoDft->Q_nrg_subr = sub( shl( ( *Q_syn + synthRef_shift ), 1 ), 40 ); hCPE->hStereoDft->hb_nrg_fx[0] = hb_nrg_fx; // 2 * (Qx + SynthRef_shift) - 31 move32(); @@ -681,7 +702,7 @@ void stereo_icBWE_dec_fx( test(); IF( NE_16( st->last_core, ACELP_CORE ) || EQ_16( st->bwidth, (Word16) WB ) ) { - ic_bwe_dec_reset( hStereoICBWE ); + ic_bwe_dec_reset_fx( hStereoICBWE ); IF( NE_16( st->last_core, ACELP_CORE ) ) { @@ -723,16 +744,19 @@ void stereo_icBWE_dec_fx( winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); //(int16_t)((SHB_OVERLAP_LEN * st->output_Fs) / 16000); winSlope_fx = div_s( 1, winLen_fx ); alpha_fx = winSlope_fx; + move16(); FOR( i = 0; i < winLen_fx; i++ ) { L_tmp = L_mult0( alpha_fx, icbweM2Ref_fx ); // Q15 + Q14 L_tmp = L_mac0( L_tmp, sub( 32767, alpha_fx ), ( hStereoICBWE->icbweM2Ref_prev_fx ) ); // Q15 + Q14; tmp = shl( round_fx( L_tmp ), 1 ); // Q = 15 + 14 - 16 + 1 = Q14 synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], tmp ); + move32(); L_tmp = L_mult0( alpha_fx, gsMapping_fx ); L_tmp = L_mac0( L_tmp, ( sub( 32767, alpha_fx ) ), ( prevgsMapping_fx ) ); tmp = shl( round_fx( L_tmp ), 1 ); // Q = 15 + 14 - 16 + 1 = Q14 synth_fx[i] = Mpy_32_16_1( synth_fx[i], tmp ); + move32(); IF( LE_16( alpha_fx, sub( 32767, winSlope_fx ) ) ) { alpha_fx = add( alpha_fx, winSlope_fx ); @@ -741,7 +765,9 @@ void stereo_icBWE_dec_fx( FOR( ; i < NS2SA( st->output_Fs, FRAME_SIZE_NS ); i++ ) { synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); + move32(); synth_fx[i] = Mpy_32_16_1( synth_fx[i], gsMapping_fx ); + move32(); } hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; move16(); @@ -757,34 +783,40 @@ void stereo_icBWE_dec_fx( IF( EQ_16( st->bfi, 0 ) ) { - hStereoICBWE->refChanIndx_bwe = get_next_indice( st, STEREO_ICBWE_REFBITS ); + hStereoICBWE->refChanIndx_bwe = get_next_indice_fx( st, STEREO_ICBWE_REFBITS ); IF( EQ_16( st->flag_ACELP16k, 1 ) ) { - spIndx = get_next_indice( st, STEREO_ICBWE_SPBITS ); + spIndx = get_next_indice_fx( st, STEREO_ICBWE_SPBITS ); } ELSE { spIndx = 3; + move16(); } IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - gsIndx = get_next_indice( st, STEREO_ICBWE_GSBITS ); + gsIndx = get_next_indice_fx( st, STEREO_ICBWE_GSBITS ); } ELSE { - gsIndx = get_next_indice( st, STEREO_ICBWE_GSBITS_DFT ); + gsIndx = get_next_indice_fx( st, STEREO_ICBWE_GSBITS_DFT ); } /* Store indices in case of frame loss */ hStereoICBWE->prev_spIndx = spIndx; + move16(); hStereoICBWE->prev_gsIndx = gsIndx; + move16(); } ELSE /*bfi*/ { /* Retrieve last decoded indices */ spIndx = hStereoICBWE->prev_spIndx; + move16(); gsIndx = hStereoICBWE->prev_gsIndx; + move16(); hStereoICBWE->refChanIndx_bwe = hStereoICBWE->prev_refChanIndx_bwe; + move16(); } /* IC-BWE parameter de-quant */ @@ -793,14 +825,17 @@ void stereo_icBWE_dec_fx( /* gs Mapping */ prevgsMapping_fx = hStereoICBWE->prevgsMapping_fx; // Q14 + move16(); IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { hStereoICBWE->prevgsMapping_fx = pow_10_icbwe_gsMapping_tbl_fx[gsIndx]; + move16(); } ELSE { hStereoICBWE->prevgsMapping_fx = pow_10_icbwe_gsMappingDFT_tbl_fx[gsIndx]; + move16(); } // hStereoICBWE->prevgsMapping = powf( 10, hStereoICBWE->prevgsMapping ); @@ -814,7 +849,7 @@ void stereo_icBWE_dec_fx( test(); IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && EQ_16( st->flag_ACELP16k, 1 ) ) { - Copy( voice_factors_fx, nlMixFac_fx, NB_SUBFR16k ); //Q15 + Copy( voice_factors_fx, nlMixFac_fx, NB_SUBFR16k ); // Q15 IF( hCPE->hStereoDftDmx != NULL ) { test(); @@ -836,10 +871,12 @@ void stereo_icBWE_dec_fx( IF( EQ_16( st->flag_ACELP16k, 0 ) ) { nbSubFr = NB_SUBFR; + move16(); } ELSE { nbSubFr = NB_SUBFR16k; + move16(); } k = 0; move16(); @@ -856,14 +893,14 @@ void stereo_icBWE_dec_fx( { tmp = 0; move16(); - temp1_fx = Sqrt16( nlMixFac_fx[i] , &tmp ); + temp1_fx = Sqrt16( nlMixFac_fx[i], &tmp ); IF( LT_16( tmp, 0 ) ) { temp1_fx = shl( temp1_fx, tmp ); } tmp = 0; move16(); - temp2_fx = Sqrt16( sub( 32767, nlMixFac_fx[i] ), &tmp ); + temp2_fx = Sqrt16( sub( 32767, nlMixFac_fx[i] ), &tmp ); IF( LT_16( tmp, 0 ) ) { temp2_fx = shl( temp2_fx, tmp ); @@ -890,21 +927,21 @@ void stereo_icBWE_dec_fx( Q_syn_shb = FindScale( hStereoICBWE->mem_syn_shb_nonref_fx, LPC_SHB_ORDER, hStereoICBWE->prev_Q_syn_shb_nonref, Q_syn_shb ); Q_syn_shb = FindScale( hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, 12, Q_syn_shb ); Q_syn_shb = FindScale( excSHB_nonref_fx, L_FRAME16k, 18, Q_syn_shb ); - Q_syn_shb = FindScale( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, LPC_SHB_ORDER, hStereoICBWE->prev_Q_lpc_shbsynth, Q_syn_shb ); + Q_syn_shb = FindScale( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, LPC_SHB_ORDER, hStereoICBWE->prev_Q_lpc_shbsynth_nonref, Q_syn_shb ); Q_syn_shb = sub( Q_syn_shb, 3 ); // gaurded bits Scale_sig32( hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, sub( Q_syn_shb, 12 ) ); Scale_sig32( excSHB_nonref_fx, L_FRAME16k, sub( Q_syn_shb, 18 ) ); - Scale_sig32( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, LPC_SHB_ORDER, sub( Q_syn_shb, hStereoICBWE->prev_Q_lpc_shbsynth ) ); + Scale_sig32( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, LPC_SHB_ORDER, sub( Q_syn_shb, hStereoICBWE->prev_Q_lpc_shbsynth_nonref ) ); Scale_sig32( hStereoICBWE->mem_syn_shb_nonref_fx, L_SHB_LAHEAD, sub( Q_syn_shb, hStereoICBWE->prev_Q_syn_shb_nonref ) ); Copy32( hStereoICBWE->mem_syn_shb_nonref_fx, shb_synth_nonref_fx, L_SHB_LAHEAD ); - + E_UTIL_synthesis_fx( 0, hStereoICBWE->lpSHBRef_fx, excSHB_nonref_fx, shb_synth_nonref_fx + L_SHB_LAHEAD, L_FRAME16k, hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 1, LPC_SHB_ORDER ); - hStereoICBWE->prev_Q_lpc_shbsynth = Q_syn_shb; + hStereoICBWE->prev_Q_lpc_shbsynth_nonref = Q_syn_shb; move16(); maximum_abs_32_fx( shb_synth_nonref_fx, L_SHB_LAHEAD + 10 + L_SHB_LAHEAD + 10, &maxVal1 ); // Qsyn_shb @@ -949,6 +986,7 @@ void stereo_icBWE_dec_fx( FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { shb_synth_nonref_fx[i] = Mpy_32_16_1( shb_synth_nonref_fx[i], scale_fx ); + move32(); } tmp = 3276; move16(); @@ -967,6 +1005,7 @@ void stereo_icBWE_dec_fx( L_tmp = L_mult0( tmp, temp1_fx ); L_tmp = L_mac0( L_tmp, sub( 32767, tmp ), scale_fx ); shb_synth_nonref_fx[i] = Mpy_32_16_1( shb_synth_nonref_fx[i], shl( round_fx( L_tmp ), 1 ) ); + move32(); IF( LT_16( tmp, 29492 ) ) { tmp = add( tmp, 3276 ); @@ -987,7 +1026,7 @@ void stereo_icBWE_dec_fx( move16(); } temp1_fx = add( temp1_fx, hStereoICBWE->prev_Q_memshbspec ); - tmp = min( temp1_fx, tmp ); + tmp = s_min( temp1_fx, tmp ); tmp = sub( tmp, 9 ); @@ -1009,16 +1048,16 @@ void stereo_icBWE_dec_fx( tmp = 31; move16(); tmp = FindScale( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, Q_syn_shb, tmp ); - tmp = FindScale( hStereoICBWE->mem_syn_shb_ola_nonref_fx, L_SHB_LAHEAD, hStereoICBWE->prev_Q_syn_shb_ola, tmp ); + tmp = FindScale( hStereoICBWE->mem_syn_shb_ola_nonref_fx, L_SHB_LAHEAD, hStereoICBWE->prev_Q_syn_shb_ola_nonref, tmp ); tmp = sub( tmp, 3 ); Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, tmp - Q_syn_shb ); - Scale_sig32( hStereoICBWE->mem_syn_shb_ola_nonref_fx, L_SHB_LAHEAD, tmp - hStereoICBWE->prev_Q_syn_shb_ola ); + Scale_sig32( hStereoICBWE->mem_syn_shb_ola_nonref_fx, L_SHB_LAHEAD, tmp - hStereoICBWE->prev_Q_syn_shb_ola_nonref ); - ScaleShapedSHB_32( SHB_OVERLAP_LEN, shb_synth_nonref_fx, hStereoICBWE->mem_syn_shb_ola_nonref_fx, hStereoICBWE->gshapeRef_fx, ( Mpy_32_16_1( L_shl(hStereoICBWE->gFrameRef_fx,1), mult_r( gsMapping_fx, 29492 ) ) ), window_shb_fx, subwin_shb_fx, &tmp, &temp1_fx ); + ScaleShapedSHB_32( SHB_OVERLAP_LEN, shb_synth_nonref_fx, hStereoICBWE->mem_syn_shb_ola_nonref_fx, hStereoICBWE->gshapeRef_fx, ( Mpy_32_16_1( L_shl( hStereoICBWE->gFrameRef_fx, 1 ), mult_r( gsMapping_fx, 29492 ) ) ), window_shb_fx, subwin_shb_fx, &tmp, &temp1_fx ); - hStereoICBWE->prev_Q_syn_shb_ola = tmp; + hStereoICBWE->prev_Q_syn_shb_ola_nonref = tmp; move16(); Q_syn_shb = tmp; move16(); @@ -1056,7 +1095,7 @@ void stereo_icBWE_dec_fx( { Copy32( synthRef_fx, synth_fx, output_frame ); - winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); + winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); winSlope_fx = div_s( 1, winLen_fx ); alpha_fx = winSlope_fx; move16(); @@ -1069,7 +1108,7 @@ void stereo_icBWE_dec_fx( } ELSE { - ratio_L_fx = extract_h(tdm_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx]); + ratio_L_fx = extract_h( tdm_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx] ); move16(); } @@ -1110,9 +1149,9 @@ void stereo_icBWE_dec_fx( #else tmp = mult_r( sub( 32767, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15 #endif - tmp = mult_r( tmp, gsMapping_fx ); // Q14 - tmp = mult_r( tmp, gsMapping_fx ); // Q13 - IF( tmp < 4096 ) + tmp = mult_r( tmp, gsMapping_fx ); // Q14 + tmp = mult_r( tmp, gsMapping_fx ); // Q13 + IF( LT_16( tmp, 4096 ) ) { temp1_fx = 0; move16(); @@ -1128,11 +1167,10 @@ void stereo_icBWE_dec_fx( icbweM2Ref_fx = 0; move16(); } - } } - icbweM2Ref_fx = max( gsMapping_fx, icbweM2Ref_fx ); + icbweM2Ref_fx = s_max( gsMapping_fx, icbweM2Ref_fx ); FOR( i = 0; i < winLen_fx; i++ ) { @@ -1140,10 +1178,12 @@ void stereo_icBWE_dec_fx( L_tmp = L_mac0( L_tmp, sub( 32767, alpha_fx ), hStereoICBWE->icbweM2Ref_prev_fx ); tmp = shl( round_fx( L_tmp ), 1 ); synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], tmp ); + move32(); L_tmp = L_mult0( alpha_fx, gsMapping_fx ); L_tmp = L_mac0( L_tmp, sub( 32767, alpha_fx ), prevgsMapping_fx ); tmp = shl( round_fx( L_tmp ), 1 ); synth_fx[i] = Mpy_32_16_1( synth_fx[i], tmp ); + move32(); IF( LE_16( alpha_fx, sub( 32767, winSlope_fx ) ) ) { alpha_fx = add( alpha_fx, winSlope_fx ); @@ -1152,13 +1192,16 @@ void stereo_icBWE_dec_fx( FOR( ; i < NS2SA( st->output_Fs, FRAME_SIZE_NS ); i++ ) { synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); + move32(); synth_fx[i] = Mpy_32_16_1( synth_fx[i], gsMapping_fx ); + move32(); } hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; move16(); - ic_bwe_dec_reset( hStereoICBWE ); + ic_bwe_dec_reset_fx( hStereoICBWE ); hStereoICBWE->prevSpecMapping_fx = 0; + move16(); *Q_syn = sub( *Q_syn, 1 ); @@ -1209,7 +1252,7 @@ void stereo_icBWE_dec_fx( IF( EQ_16( st->extl, FB_TBE ) && EQ_32( st->output_Fs, 48000 ) ) { - //v_add( fb_synth_nonref_fx, synth_fx, synth_fx, L_FRAME48k, 0 ); + // v_add( fb_synth_nonref_fx, synth_fx, synth_fx, L_FRAME48k, 0 ); FOR( i = 0; i < L_FRAME48k; i++ ) { synth_fx[i] = L_add( synth_fx[i], L_deposit_l( fb_synth_nonref_fx[i] ) ); @@ -1226,7 +1269,7 @@ void stereo_icBWE_dec_fx( } ELSE { - ratio_L_fx = extract_h(tdm_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx]); + ratio_L_fx = extract_h( tdm_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx] ); move16(); } @@ -1264,10 +1307,10 @@ void stereo_icBWE_dec_fx( #ifdef FIX_TMP_714 tmp = mult_r( ratio_L_fx, ratio_L_fx ); // Q15 #else - tmp = mult_r( sub( 32767, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15 + tmp = mult_r( sub( 32767, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15 #endif - tmp = mult_r( tmp, gsMapping_fx ); // Q14 - tmp = mult_r( tmp, gsMapping_fx ); // Q13 + tmp = mult_r( tmp, gsMapping_fx ); // Q14 + tmp = mult_r( tmp, gsMapping_fx ); // Q13 IF( LT_16( tmp, 4096 ) ) { temp1_fx = 0; @@ -1284,13 +1327,12 @@ void stereo_icBWE_dec_fx( icbweM2Ref_fx = 0; move16(); } - } } - icbweM2Ref_fx = max( gsMapping_fx, icbweM2Ref_fx ); + icbweM2Ref_fx = s_max( gsMapping_fx, icbweM2Ref_fx ); - winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); + winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); winSlope_fx = div_s( 1, winLen_fx ); alpha_fx = winSlope_fx; move16(); @@ -1300,6 +1342,7 @@ void stereo_icBWE_dec_fx( L_tmp = L_mac0( L_tmp, sub( 32767, alpha_fx ), hStereoICBWE->icbweM2Ref_prev_fx ); tmp = shl( round_fx( L_tmp ), 1 ); synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], tmp ); + move32(); IF( LE_16( alpha_fx, sub( 32767, winSlope_fx ) ) ) { alpha_fx = add( alpha_fx, winSlope_fx ); @@ -1309,6 +1352,7 @@ void stereo_icBWE_dec_fx( FOR( ; i < NS2SA( st->output_Fs, FRAME_SIZE_NS ); i++ ) { synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); + move32(); } hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; @@ -1324,6 +1368,7 @@ void stereo_icBWE_dec_fx( * Stereo (inter-channel) BWE mapping - decoder initialization *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void stereo_icBWE_decproc( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ float *output[CPE_CHANNELS], /* i/o: output synthesis */ @@ -1349,11 +1394,7 @@ void stereo_icBWE_decproc( if ( ( hCPE->element_mode == IVAS_CPE_TD || hCPE->element_mode == IVAS_CPE_DFT ) && hCPE->nchan_out == 2 /*&& hCPE->hCoreCoder[0]->core_brate > SID_2k40*/ && hCPE->hCoreCoder[0]->last_core_brate <= SID_2k40 ) { -#ifdef IVAS_FLOAT_FIXED - stereo_icBWE_init_dec_fx( hCPE->hStereoICBWE ); -#else stereo_icBWE_init_dec( hCPE->hStereoICBWE ); -#endif } if ( hCPE->hCoreCoder[0]->core_brate <= SID_2k40 ) @@ -1563,11 +1604,7 @@ void stereo_icBWE_decproc( } else if ( hCPE->element_mode == IVAS_CPE_TD && hCPE->hCoreCoder[0]->tdm_LRTD_flag && hStereoICBWE != NULL ) { -#ifdef IVAS_FLOAT_FIXED - stereo_icBWE_init_dec_fx( hCPE->hStereoICBWE ); -#else stereo_icBWE_init_dec( hCPE->hStereoICBWE ); -#endif } else if ( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->last_element_mode == IVAS_CPE_DFT && last_core == ACELP_CORE ) { @@ -1582,18 +1619,8 @@ void stereo_icBWE_decproc( } /* reset BWE structs as they are only needed in the transition frame in MDCT Stereo */ td_bwe_dec_init( hCPE->hCoreCoder[0]->hBWE_TD, -1, output_Fs ); -#ifdef IVAS_FLOAT_FIXED - td_bwe_dec_init_fx(hCPE->hCoreCoder[0], hCPE->hCoreCoder[0]->hBWE_TD, -#ifdef ADD_IVAS_BWE - hCPE->hCoreCoder[0]->extl, -#endif - hCPE->hCoreCoder[0]->output_Fs); -#endif fd_bwe_dec_init_flt( hCPE->hCoreCoder[0]->hBWE_FD ); -#ifdef IVAS_FLOAT_FIXED - fd_bwe_dec_init(hCPE->hCoreCoder[0], hCPE->hCoreCoder[0]->hBWE_FD); -#endif } if ( hCPE->element_mode == IVAS_CPE_DFT && ( max( hCPE->hStereoDft->td_gain[0], hCPE->hStereoDft->td_gain[1] ) > 0 ) ) @@ -1622,24 +1649,24 @@ void stereo_icBWE_decproc( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void stereo_icBWE_decproc_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *output[CPE_CHANNELS], /* i/o: output synthesis */ Word32 outputHB[CPE_CHANNELS][L_FRAME48k], /* i : HB synthesis */ - const int16_t last_core, /* i : last core, primary channel */ - const int16_t last_bwidth, /* i : last bandwidth */ - const int16_t output_frame /* i : frame length */ + const Word16 last_core, /* i : last core, primary channel */ + const Word16 last_bwidth, /* i : last bandwidth */ + const Word16 output_frame, /* i : frame length */ + Word16 q_output /* i : Q-fac of output */ ) { - int16_t i, j, n, decoderDelay, icbweOLASize, dftOvlLen; - int16_t core, memOffset, refChanIndx_bwe; + Word16 i, j, n, decoderDelay, icbweOLASize, dftOvlLen; + Word16 core, memOffset, refChanIndx_bwe; Word32 temp0_fx[L_FRAME48k + NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )], temp1_fx[L_FRAME48k + NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )]; Word32 winSlope_fx = 0, alpha_fx; - const Word32 *win_dft_fx; - int32_t extl_brate, output_Fs; + const Word16 *win_dft_fx; + Word32 extl_brate, output_Fs; STEREO_ICBWE_DEC_HANDLE hStereoICBWE = hCPE->hStereoICBWE; @@ -1647,13 +1674,12 @@ void stereo_icBWE_decproc_fx( * skip IC-BWE in case of SID or NO_DATA frame * -------------------------------------------------------------------*/ + test(); + test(); + test(); IF( ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) && EQ_16( hCPE->nchan_out, 2 ) /*&& hCPE->hCoreCoder[0]->core_brate > SID_2k40*/ && LE_32( hCPE->hCoreCoder[0]->last_core_brate, SID_2k40 ) ) { -#ifdef IVAS_FLOAT_FIXED stereo_icBWE_init_dec_fx( hCPE->hStereoICBWE ); -#else - stereo_icBWE_init_dec( hCPE->hStereoICBWE ); -#endif } IF( LE_32( hCPE->hCoreCoder[0]->core_brate, SID_2k40 ) ) @@ -1665,6 +1691,8 @@ void stereo_icBWE_decproc_fx( * skip IC-BWE in case of mono DMX output * * -------------------------------------------------------------------*/ + test(); + test(); IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { add_HB_to_mono_dmx_fx( hCPE, output[0], outputHB[0], last_core, output_frame ); @@ -1680,12 +1708,16 @@ void stereo_icBWE_decproc_fx( * -------------------------------------------------------------------*/ core = hCPE->hCoreCoder[0]->core; + move16(); extl_brate = hCPE->hCoreCoder[0]->extl_brate; + move32(); output_Fs = hCPE->hCoreCoder[0]->output_Fs; + move32(); memOffset = NS2SA( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); /* LRTD stereo mode - 2xBWEs used */ + test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && hCPE->hCoreCoder[0]->tdm_LRTD_flag ) { /* delay HB synth */ @@ -1703,6 +1735,7 @@ void stereo_icBWE_decproc_fx( FOR( i = 0; i < output_frame; i++ ) { outputHB[0][i] = L_shr( ( outputHB[0][i] + outputHB[1][i] ), 1 ); + move32(); } v_add_32( output[0], outputHB[0], output[0], output_frame ); } @@ -1723,6 +1756,12 @@ void stereo_icBWE_decproc_fx( } } + test(); + test(); + test(); + test(); + test(); + test(); IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && !( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && hCPE->hCoreCoder[0]->tdm_LRTD_flag ) ) { IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) @@ -1734,38 +1773,48 @@ void stereo_icBWE_decproc_fx( set32_fx( hStereoICBWE->memTransitionHB_fx[1], 0, NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) ); } + test(); IF( EQ_16( core, ACELP_CORE ) && GT_32( extl_brate, 0 ) ) { refChanIndx_bwe = hStereoICBWE->refChanIndx_bwe; + move16(); + test(); + test(); + test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && GT_16( hCPE->hCoreCoder[0]->bwidth, WB ) && EQ_16( last_bwidth, WB ) && GT_16( hCPE->hCoreCoder[0]->ini_frame, 1 ) /* counter wass already updated */ ) { /* fad-in reference HB signal */ IF( GT_16( memOffset, 0 ) ) { - switch ( memOffset ) + SWITCH( memOffset ) { case 15: winSlope_fx = 71582792; - break; + move32(); + BREAK; case 30: winSlope_fx = 35791396; - break; + move32(); + BREAK; case 45: winSlope_fx = 23860930; - break; + move32(); + BREAK; } // memOffset for 16K 32K 48K are 15 30 45 respectively.camera } ELSE { winSlope_fx = 0; + move32(); } - for ( i = 0; i < memOffset; i++ ) + FOR( i = 0; i < memOffset; i++ ) { Word32 mul_win = Mpy_32_16_1( winSlope_fx, ( i + 1 ) ); // Q30 + Q0 - 15 = Q15 mul_win = L_shl( mul_win, 15 ); // Q30 outputHB[refChanIndx_bwe][i] = L_shl( Mpy_32_32( outputHB[refChanIndx_bwe][i] /* Q11 + Q30 - 31 = Q10)*/, mul_win ), 1 ); // + move32(); } } /* Resampled LB and HB offset */ @@ -1774,6 +1823,7 @@ void stereo_icBWE_decproc_fx( decoderDelay = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); + test(); IF( NE_16( last_core, ACELP_CORE ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { /* hb_synth of mid band is faded out in the 1.25 ms prior to DFT analysis and the icbwe is faded in time domain */ @@ -1782,7 +1832,9 @@ void stereo_icBWE_decproc_fx( FOR( i = 0; i < decoderDelay; i++ ) { temp0_fx[i] = 0; + move32(); temp1_fx[i] = 0; + move32(); } assert( icbweOLASize > 0 ); @@ -1790,19 +1842,25 @@ void stereo_icBWE_decproc_fx( { case 60: winSlope_fx = 17895698; - break; + move32(); + BREAK; case 40: winSlope_fx = 26843546; - break; + move32(); + BREAK; case 20: winSlope_fx = 53687092; - break; + move32(); + BREAK; } alpha_fx = winSlope_fx; // Q30 + move32(); FOR( ; i < decoderDelay + icbweOLASize; i++ ) { temp0_fx[i] = L_shl_sat( Mpy_32_32( temp0_fx[i], alpha_fx ), 1 ); // Q11 + move32(); temp1_fx[i] = L_shl_sat( Mpy_32_32( temp1_fx[i], alpha_fx ), 1 ); + move32(); alpha_fx = L_add( alpha_fx, winSlope_fx ); } } @@ -1816,27 +1874,30 @@ void stereo_icBWE_decproc_fx( { case 15: winSlope_fx = 71582792; - break; + BREAK; case 30: winSlope_fx = 35791396; - break; + BREAK; case 45: winSlope_fx = 23860930; // Q30 - break; + BREAK; } // memOffset for 16K 32K 48K are 15 30 45 respectively.camera } ELSE { winSlope_fx = 0; + move32(); } FOR( i = 0; i < memOffset; i++ ) { temp0_fx[i] = L_add( L_shl( Mpy_32_32( Mpy_32_16_1( winSlope_fx, ( i + 1 ) ), hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i] ), 16 ), L_shl( Mpy_32_32( Mpy_32_16_1( winSlope_fx, 1 - ( i + 1 ) ), hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i] ), 16 ) ); + move32(); temp1_fx[i] = L_add( L_shl( Mpy_32_32( Mpy_32_16_1( winSlope_fx, ( i + 1 ) ), hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i] ), 16 ), L_shl( Mpy_32_32( Mpy_32_16_1( winSlope_fx, ( 1 - ( i + 1 ) ) ), hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i] ), 16 ) ); + move32(); } } ELSE @@ -1852,8 +1913,11 @@ void stereo_icBWE_decproc_fx( FOR( i = 0; i < output_frame; i++ ) { temp0_fx[i] = L_add( temp0_fx[i], temp1_fx[i] ); + move32(); temp0_fx[i] = L_shr( temp0_fx[i], 1 ); + move32(); output[0][i] = L_add( output[0][i], temp0_fx[i] ); + move32(); } } ELSE @@ -1868,29 +1932,36 @@ void stereo_icBWE_decproc_fx( IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { /*win_dft = hCPE->hStereoDft->win32ms;*/ - win_dft_fx = (Word32 *) hCPE->hStereoDft->win32ms_fx; + win_dft_fx = hCPE->hStereoDft->win32ms_fx; dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; + move16(); /* Preparing buffers in anticipation of an ACELP to TCX switch */ j = 0; + move16(); FOR( i = 0; i < memOffset; i++ ) { - Word16 tmp_mul = mult0( STEREO_DFT32MS_STEP, ( dftOvlLen - 1 - j ) ); - hStereoICBWE->memTransitionHB_fx[0][i] = Mpy_32_32( hStereoICBWE->memOutHB_fx[0][i], win_dft_fx[tmp_mul] ); - hStereoICBWE->memTransitionHB_fx[1][i] = Mpy_32_32( hStereoICBWE->memOutHB_fx[1][i], win_dft_fx[tmp_mul] ); + Word16 tmp_mul = mult0( STEREO_DFT32MS_STEP, ( sub( dftOvlLen, add( 1, j ) ) ) ); + hStereoICBWE->memTransitionHB_fx[0][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[0][i], win_dft_fx[tmp_mul] ); + move32(); + hStereoICBWE->memTransitionHB_fx[1][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[1][i], win_dft_fx[tmp_mul] ); + move32(); j++; } FOR( i = 0; j < dftOvlLen; i++ ) { - Word16 tmp_mul = mult0( STEREO_DFT32MS_STEP, ( dftOvlLen - 1 - j ) ); - hStereoICBWE->memTransitionHB_fx[0][memOffset + i] = Mpy_32_32( outputHB[0][output_frame - i - 1], win_dft_fx[tmp_mul] ); - hStereoICBWE->memTransitionHB_fx[1][memOffset + i] = Mpy_32_32( outputHB[1][output_frame - i - 1], win_dft_fx[tmp_mul] ); + Word16 tmp_mul = mult0( STEREO_DFT32MS_STEP, ( sub( dftOvlLen, add( 1, j ) ) ) ); + hStereoICBWE->memTransitionHB_fx[0][memOffset + i] = Mpy_32_16_1( outputHB[0][output_frame - i - 1], win_dft_fx[tmp_mul] ); + move32(); + hStereoICBWE->memTransitionHB_fx[1][memOffset + i] = Mpy_32_16_1( outputHB[1][output_frame - i - 1], win_dft_fx[tmp_mul] ); + move32(); j++; } } hStereoICBWE->prev_refChanIndx_bwe = refChanIndx_bwe; + move16(); } ELSE { @@ -1918,53 +1989,57 @@ void stereo_icBWE_decproc_fx( } ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && hCPE->hCoreCoder[0]->tdm_LRTD_flag && hStereoICBWE != NULL ) { -#ifdef IVAS_FLOAT_FIXED stereo_icBWE_init_dec_fx( hCPE->hStereoICBWE ); -#else - stereo_icBWE_init_dec( hCPE->hStereoICBWE ); -#endif } ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && EQ_16( last_core, ACELP_CORE ) ) { - int16_t delay_tdbwe = NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ); + Word16 delay_tdbwe = NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ); FOR( n = 0; n < hCPE->nchan_out; n++ ) { FOR( i = 0; i < delay_tdbwe; i++ ) { output[n][NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) - delay_tdbwe + i] = L_add_sat( output[n][NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) - delay_tdbwe + i], outputHB[0][i] ); + move32(); } } /* reset BWE structs as they are only needed in the transition frame in MDCT Stereo */ - td_bwe_dec_init_fx( hCPE->hCoreCoder[0], hCPE->hCoreCoder[0]->hBWE_TD, -#ifdef ADD_IVAS_BWE - st_fx->extl, -#endif - output_Fs ); + td_bwe_dec_init_ivas_fx( hCPE->hCoreCoder[0], hCPE->hCoreCoder[0]->hBWE_TD, output_Fs ); fd_bwe_dec_init( hCPE->hCoreCoder[0], hCPE->hCoreCoder[0]->hBWE_FD ); } - - IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && ( max( hCPE->hStereoDft->td_gain_fx[0], hCPE->hStereoDft->td_gain_fx[1] ) > 0 ) ) + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && GT_32( L_max( hCPE->hStereoDft->td_gain_fx[0], hCPE->hStereoDft->td_gain_fx[1] ), 0 ) ) { - Word32 win_in_fx, win_out_fx, tmp_fx; + Word32 win_in_fx, win_out_fx, tmp_fx, gain0_fx, gain1_fx; - win_dft_fx = (Word32 *) hCPE->hStereoDft->win32ms_fx; + win_dft_fx = hCPE->hStereoDft->win32ms_fx; dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; + move16(); FOR( i = 0; i < dftOvlLen; i++ ) { - win_in_fx = Mpy_32_32( win_dft_fx[mult0( STEREO_DFT32MS_STEP, i )], win_dft_fx[mult0( STEREO_DFT32MS_STEP, i )] ); - win_out_fx = L_sub( 1, win_in_fx ); - tmp_fx = Mpy_32_32( L_add( Mpy_32_32( win_in_fx, hCPE->hStereoDft->td_gain_fx[0] ), Mpy_32_32( win_out_fx, hCPE->hStereoDft->td_gain_fx[1] ) ), hCPE->hStereoDft->hb_stefi_sig_fx[i] ); - output[0][i] = L_add( output[0][i], tmp_fx ); - output[1][i] = L_sub( output[1][i], tmp_fx ); + win_in_fx = L_mult( win_dft_fx[mult0( STEREO_DFT32MS_STEP, i )], win_dft_fx[mult0( STEREO_DFT32MS_STEP, i )] ); /* Q31 */ + win_out_fx = L_sub( ONE_IN_Q31, win_in_fx ); /* Q31 */ + + gain0_fx = Mpy_32_32( win_in_fx, hCPE->hStereoDft->td_gain_fx[0] ); /* Q --> q_td_gain[0] */ + gain0_fx = (Word32) W_shr( ( (Word64) gain0_fx * hCPE->hStereoDft->hb_stefi_sig_fx[i] ), sub( add( (Word16) hCPE->hStereoDft->q_td_gain[0], hCPE->hStereoDft->q_hb_stefi_sig_fx ), q_output ) ); /* Q --> q_output */ + gain1_fx = Mpy_32_32( win_out_fx, hCPE->hStereoDft->td_gain_fx[1] ); /* Q --> q_td_gain[1] */ + gain1_fx = (Word32) W_shr( ( (Word64) gain1_fx * hCPE->hStereoDft->hb_stefi_sig_fx[i] ), sub( add( (Word16) hCPE->hStereoDft->q_td_gain[1], hCPE->hStereoDft->q_hb_stefi_sig_fx ), q_output ) ); /* Q --> q_output */ + tmp_fx = L_add_sat( gain0_fx, gain1_fx ); /* Q --> q_output */ + + output[0][i] = L_add_sat( output[0][i], tmp_fx ); + move32(); + output[1][i] = L_sub_sat( output[1][i], tmp_fx ); + move32(); } FOR( i = dftOvlLen; i < output_frame; i++ ) { - tmp_fx = Mpy_32_32( hCPE->hStereoDft->td_gain_fx[0], hCPE->hStereoDft->hb_stefi_sig_fx[i] ); + tmp_fx = (Word32) W_shr( ( (Word64) hCPE->hStereoDft->td_gain_fx[0] * hCPE->hStereoDft->hb_stefi_sig_fx[i] ), sub( add( (Word16) hCPE->hStereoDft->q_td_gain[0], hCPE->hStereoDft->q_hb_stefi_sig_fx ), q_output ) ); /* Q --> q_output */ output[0][i] = L_add_sat( output[0][i], tmp_fx ); + move32(); output[1][i] = L_sub_sat( output[1][i], tmp_fx ); + move32(); } } @@ -1978,6 +2053,7 @@ void stereo_icBWE_decproc_fx( * Stereo (inter-channel) BWE mapping - decoder initialization *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void stereo_icBWE_init_dec( STEREO_ICBWE_DEC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */ ) @@ -1999,66 +2075,48 @@ void stereo_icBWE_init_dec( hStereoICBWE->prevSpecMapping = 0; hStereoICBWE->prevgsMapping = 1.0f; -#ifdef IVAS_FLOAT_FIXED - hStereoICBWE->prevSpecMapping_fx = 0; - hStereoICBWE->prevgsMapping_fx = 16384; -#endif - hStereoICBWE->icbweM2Ref_prev = 1.0f; -#ifdef IVAS_FLOAT_FIXED - hStereoICBWE->icbweM2Ref_prev_fx = 16384; -#endif - hStereoICBWE->prev_spIndx = 0; hStereoICBWE->prev_gsIndx = 0; ic_bwe_dec_reset( hStereoICBWE ); return; } - -#ifdef IVAS_FLOAT_FIXED +#else void stereo_icBWE_init_dec_fx( STEREO_ICBWE_DEC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */ ) { /* BWE ref channel */ hStereoICBWE->refChanIndx_bwe = L_CH_INDX; + move16(); hStereoICBWE->prev_refChanIndx_bwe = L_CH_INDX; + move16(); /* SHB output memory */ -#if 1 /* TODO: remove float init later. */ - set_f( hStereoICBWE->memOutHB[0], 0, NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) ); - set_f( hStereoICBWE->memOutHB[1], 0, NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) ); -#endif - set32_fx( hStereoICBWE->memOutHB_fx[0], 0, NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) ); set32_fx( hStereoICBWE->memOutHB_fx[1], 0, NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) ); - /* SHB output memory */ -#if 1 /*TODO: remove float init later. */ - set_f( hStereoICBWE->memTransitionHB[0], 0, NS2SA( 48000, STEREO_DFT32MS_OVL_NS ) ); - set_f( hStereoICBWE->memTransitionHB[1], 0, NS2SA( 48000, STEREO_DFT32MS_OVL_NS ) ); -#endif + /* SHB output memory */ set32_fx( hStereoICBWE->memTransitionHB_fx[0], 0, NS2SA( 48000, STEREO_DFT32MS_OVL_NS ) ); set32_fx( hStereoICBWE->memTransitionHB_fx[1], 0, NS2SA( 48000, STEREO_DFT32MS_OVL_NS ) ); /* inter-channel BWE spectral shape adj. */ -#if 1 /* TODO: remove float init later*/ - hStereoICBWE->prevSpecMapping = 0; - hStereoICBWE->prevgsMapping = 1.0f; - hStereoICBWE->icbweM2Ref_prev = 1.0f; -#endif - hStereoICBWE->prevSpecMapping_fx = 0; + move16(); hStereoICBWE->prevgsMapping_fx = 16384; + move16(); hStereoICBWE->icbweM2Ref_prev_fx = 16384; + move16(); hStereoICBWE->prev_spIndx = 0; + move16(); hStereoICBWE->prev_gsIndx = 0; + move16(); - ic_bwe_dec_reset( hStereoICBWE ); + ic_bwe_dec_reset_fx( hStereoICBWE ); return; } diff --git a/lib_dec/ivas_stereo_mdct_core_dec.c b/lib_dec/ivas_stereo_mdct_core_dec.c index ef6046c6f0eba1bb68c55a88e65098c701344e80..4fc77c669eace9b483d4197bac3b9e77e7a6cac3 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec.c +++ b/lib_dec/ivas_stereo_mdct_core_dec.c @@ -412,7 +412,7 @@ void stereo_mdct_core_dec( f2me_16( sns_int_scf[j], &scf_fx[j], &scf_e[j] ); } TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx_, x_e, L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); - st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); + //st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); #else TonalMDCTConceal_SaveFreqSignal_ivas( st->hTonalMDCTConc, x[ch][k], L_frameTCX[ch], L_frame[ch], &sns_int_scf[0], get_igf_startline_flt( st, L_frame[ch], L_frameTCX[ch] ) ); #endif @@ -485,7 +485,7 @@ void stereo_mdct_core_dec( pop_wmops(); return; } -#endif + /*-------------------------------------------------------------------* * apply_dmx_weights() @@ -771,3 +771,5 @@ static void run_min_stats( return; } +#endif + diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index c573e023b0453842d3302d7f6af3b16d619abfaf..632e6ee3403307abc4f05e3ba94fb9e413241f79 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -52,7 +52,7 @@ static void apply_dmx_weights_fx( CPE_DEC_HANDLE hCPE, Word32 *x[CPE_CHANNELS][NB_DIV], int16_t transform_type_left[NB_DIV], int16_t transform_type_right[NB_DIV] ); static void apply_dmx_weights( CPE_DEC_HANDLE hCPE, float *x[CPE_CHANNELS][NB_DIV], int16_t transform_type_left[NB_DIV], int16_t transform_type_right[NB_DIV] ); -static void run_min_stats_fx( Decoder_State **sts, float *x[CPE_CHANNELS][NB_DIV] ); +static void run_min_stats_fx( Decoder_State **sts, Word32 *x[CPE_CHANNELS][NB_DIV], Word16 x_e[MAX_CICP_CHANNELS][NB_DIV]); /*-------------------------------------------------------------------* * stereo_mdct_dec_stereo() @@ -95,50 +95,51 @@ static void stereo_mdct_dec_stereo_fx( void stereo_mdct_core_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - float *signal_out[CPE_CHANNELS], /* o : synthesis @internal_FS */ - float signal_outFB[CPE_CHANNELS][L_FRAME48k] /* o : synthesis @output_FS */ + Word32 *signal_out_fx[CPE_CHANNELS], /* o : synthesis @internal_FS */ + Word16 signal_outFB_fx[CPE_CHANNELS][L_FRAME48k] /* o : synthesis @output_FS */ ) { - int16_t k, ch, nChannels; + Word16 k, ch, nChannels; + Word16 i, l, j; Decoder_State *st, **sts; /* bitstream */ - int16_t param[CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV]; - int16_t param_lpc[CPE_CHANNELS][NPRM_LPC_NEW]; + Word16 param[CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV]; + Word16 param_lpc[CPE_CHANNELS][NPRM_LPC_NEW]; - float Aq[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; -#ifdef IVAS_FLOAT_FIXED - /* NOTE: temporary fix to avoid garbage values while calculating its - q-factor when not initialised. */ - set_zero((float *)Aq, CPE_CHANNELS * (NB_SUBFR16k + 1) * (M + 1)); -#endif - float *x[CPE_CHANNELS][NB_DIV]; + Word16 Aq_fx[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; + Word32 Aq_fx_32[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; + + Word32 *x_fx[CPE_CHANNELS][NB_DIV]; + Word16 x_e[CPE_CHANNELS][NB_DIV]; + Word16 x_len[CPE_CHANNELS][NB_DIV]; /*needed to allocate N_MAX to prevent stereo switching crash */ - float x_0_buf[CPE_CHANNELS][N_MAX]; - float *x_0[CPE_CHANNELS][NB_DIV]; + Word32 x_0_buf_fx[CPE_CHANNELS][N_MAX]; + Word32 *x_0_fx[CPE_CHANNELS][NB_DIV]; + Word16 x_0_e[CPE_CHANNELS][NB_DIV]; /* Concealment */ - int16_t bfi; + Word16 bfi; /* Framing */ - int16_t L_frame[CPE_CHANNELS], L_frameTCX[CPE_CHANNELS], nSubframes[CPE_CHANNELS]; + Word16 L_frame[CPE_CHANNELS], L_frameTCX[CPE_CHANNELS], nSubframes[CPE_CHANNELS]; /* TCX */ - int16_t fUseTns[CPE_CHANNELS][NB_DIV]; + Word16 fUseTns[CPE_CHANNELS][NB_DIV]; STnsData tnsData[CPE_CHANNELS][NB_DIV]; - int16_t tcx_offset[CPE_CHANNELS]; - int16_t tcx_offsetFB[CPE_CHANNELS]; - int16_t left_rect[CPE_CHANNELS]; - int16_t L_spec[CPE_CHANNELS]; + Word16 tcx_offset[CPE_CHANNELS]; + Word16 tcx_offsetFB[CPE_CHANNELS]; + Word16 left_rect[CPE_CHANNELS]; + Word16 L_spec[CPE_CHANNELS]; /* stereo */ - int16_t ms_mask[NB_DIV][MAX_SFB]; + Word16 ms_mask[NB_DIV][MAX_SFB]; - int16_t p_param[CPE_CHANNELS][NB_DIV]; - int16_t nTnsBitsTCX10[CPE_CHANNELS][NB_DIV]; - float signal_outFB_tmp[CPE_CHANNELS][L_FRAME_PLUS]; - float signal_out_tmp[CPE_CHANNELS][L_FRAME_PLUS]; + Word16 p_param[CPE_CHANNELS][NB_DIV]; + Word16 nTnsBitsTCX10[CPE_CHANNELS][NB_DIV]; + Word16 signal_outFB_tmp_fx[CPE_CHANNELS][L_FRAME_PLUS]; + Word32 signal_out_tmp_fx[CPE_CHANNELS][L_FRAME_PLUS]; push_wmops( "stereo_mdct_core_dec" ); /*--------------------------------------------------------------------------------* @@ -150,46 +151,46 @@ void stereo_mdct_core_dec_fx( nChannels = CPE_CHANNELS; bfi = sts[0]->bfi; + move16(); - for ( ch = 0; ch < nChannels; ch++ ) + FOR( ch = 0; ch < nChannels; ch++ ) { /* Initialization or re-configuration of Stereo TCX */ -#ifdef IVAS_FLOAT_FIXED - /* stereo_tcx_dec_mode_switch_reconf_To_fixed is for intermediatery conversions which is needed to be removed */ - stereo_tcx_dec_mode_switch_reconf_To_fixed( sts[ch], 1, hCPE->last_element_mode ); - /*============*/ stereo_tcx_init_dec_fx( sts[ch], 0, hCPE->last_element_mode ); - /*============*/ - stereo_tcx_dec_mode_switch_reconf_To_fixed( sts[ch], 0, hCPE->last_element_mode ); -#else - stereo_tcx_init_dec( sts[ch], 0, hCPE->last_element_mode ); -#endif + sts[ch]->hTcxDec->tnsActive[0] = sts[ch]->hTcxDec->tnsActive[1] = 0; + move16(); sts[ch]->enablePlcWaveadjust = 0; - set_zero( signal_out_tmp[ch], L_FRAME_PLUS ); - x[ch][0] = &signal_out_tmp[ch][0]; - x[ch][1] = &signal_out_tmp[ch][0] + L_FRAME_PLUS / 2; - - set_zero( x_0_buf[ch], N_MAX ); - x_0[ch][0] = &x_0_buf[ch][0]; - x_0[ch][1] = &x_0_buf[ch][0] + L_FRAME48k / 2; + move16(); + set32_fx( signal_out_tmp_fx[ch], 0,L_FRAME_PLUS ); + x_fx[ch][0] = &signal_out_tmp_fx[ch][0]; + x_fx[ch][1] = &signal_out_tmp_fx[ch][0] + L_FRAME_PLUS / 2; + + set32_fx( x_0_buf_fx[ch], 0, N_MAX ); + x_0_fx[ch][0] = &x_0_buf_fx[ch][0]; + x_0_fx[ch][1] = &x_0_buf_fx[ch][0] + L_FRAME48k / 2; nTnsBitsTCX10[ch][0] = 0; + move16(); nTnsBitsTCX10[ch][1] = 0; + move16(); set_s( param_lpc[ch], 0, NPRM_LPC_NEW ); } + set_s( ms_mask[0], 0, MAX_SFB ); set_s( ms_mask[1], 0, MAX_SFB ); initMdctStereoDecData_fx( hCPE->hStereoMdct, sts[0]->igf, sts[0]->hIGFDec->igfData.igfInfo.grid, hCPE->element_brate, sts[0]->bwidth ); - hCPE->hStereoMdct->isSBAStereoMode = ( ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); - if ( !bfi ) + hCPE->hStereoMdct->isSBAStereoMode = ( ( EQ_16(st_ivas->ivas_format, SBA_FORMAT) || EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT) ) && EQ_16( st_ivas->nchan_transport, 2 ) ); + move16(); + + IF( EQ_16(bfi, 0) ) { ivas_mdct_dec_side_bits_frame_channel_fx( hCPE, param_lpc, p_param, hCPE->hCoreCoder[0], nTnsBitsTCX10, param, 0, 0 ); - if ( sts[0]->igf ) + IF( NE_16(sts[0]->igf, 0) ) { - for ( ch = 0; ch < nChannels; ch++ ) + FOR ( ch = 0; ch < nChannels; ch++ ) { st = sts[ch]; mdct_read_IGF_bits_fx( st, sts[0] ); @@ -198,59 +199,39 @@ void stereo_mdct_core_dec_fx( stereo_mdct_dec_stereo_fx( hCPE, ms_mask ); } - else + ELSE { mvs2s( hCPE->hStereoMdct->prev_ms_mask[0], ms_mask[0], MAX_SFB ); mvs2s( hCPE->hStereoMdct->prev_ms_mask[1], ms_mask[1], MAX_SFB ); - if ( sts[0]->core != TCX_10_CORE && sts[1]->core != TCX_10_CORE ) + IF ( NE_16(sts[0]->core, TCX_10_CORE) && NE_16(sts[1]->core, TCX_10_CORE) ) { hCPE->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO; + move16(); hCPE->hStereoMdct->IGFStereoMode[1] = SMDCT_DUAL_MONO; + move16(); } - else if ( sts[0]->core == TCX_10_CORE && sts[1]->core == TCX_10_CORE ) + ELSE IF ( EQ_16(sts[0]->core, TCX_10_CORE) && EQ_16(sts[1]->core, TCX_10_CORE) ) { hCPE->hStereoMdct->global_ild[0] = hCPE->hStereoMdct->global_ild[1]; + move16(); hCPE->hStereoMdct->mdct_stereo_mode[0] = hCPE->hStereoMdct->mdct_stereo_mode[1]; + move16(); hCPE->hStereoMdct->IGFStereoMode[0] = hCPE->hStereoMdct->IGFStereoMode[1]; + move16(); } } -#ifdef IVAS_FLOAT_FIXED -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - Word16 Aq_fx[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; - - Word32 *x_0_fx[CPE_CHANNELS][NB_DIV]; - Word32 *x_fx[CPE_CHANNELS][NB_DIV]; - Word16 x_e[CPE_CHANNELS][NB_DIV]; - Word16 x_0_e[CPE_CHANNELS][NB_DIV]; - Word16 x_len[CPE_CHANNELS][NB_DIV] = { 0 }; - - Word16 i, l, j; - FOR( i = 0; i < CPE_CHANNELS; ++i ) { - x_fx[i][0] = malloc( L_FRAME_PLUS * sizeof( Word32 ) ); - x_fx[i][1] = x_fx[i][0] + L_FRAME_PLUS / 2; - floatToFixed_arrL( x[i][0], x_fx[i][0], 0, L_FRAME_PLUS / 2 ); - floatToFixed_arrL( x[i][1], x_fx[i][1], 0, L_FRAME_PLUS / 2 ); - FOR( j = 0; j < NB_DIV; ++j ) { x_e[i][j] = 31; - } - } - - FOR( i = 0; i < CPE_CHANNELS; ++i ) - { - x_0_fx[i][0] = malloc( N_MAX * sizeof( Word32 ) ); - x_0_fx[i][1] = x_0_fx[i][0] + L_FRAME48k / 2; - floatToFixed_arrL( x_0[i][0], x_0_fx[i][0], 0, L_FRAME48k / 2 ); - floatToFixed_arrL( x_0[i][1], x_0_fx[i][1], 0, L_FRAME48k / 2 ); - - FOR( j = 0; j < NB_DIV; ++j ) - { + move16(); + x_len[i][j] = 0; + move16(); x_0_e[i][j] = 31; + move16(); } } @@ -258,777 +239,239 @@ void stereo_mdct_core_dec_fx( { IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) { - //sts[ch]->gamma = float_to_fix16( sts[ch]->gamma_float, Q15 ); - sts[ch]->preemph_fac = float_to_fix16( sts[ch]->preemph_fac_float, Q15 ); - sts[ch]->Mode2_lp_gainp = float_to_fix( sts[ch]->lp_gainp, Q16 ); - sts[ch]->hTcxLtpDec->tcxltp_gain = float_to_fix16( sts[ch]->hTcxLtpDec->tcxltp_gain_float, Q15 ); - //sts[ch]->inv_gamma = float_to_fix16( 1 / sts[ch]->gamma_float, Q14 ); - f2me_16( sts[ch]->last_gain_syn_deemph_float, &sts[ch]->last_gain_syn_deemph, &sts[ch]->last_gain_syn_deemph_e ); - f2me_16( sts[ch]->last_concealed_gain_syn_deemph_float, &sts[ch]->last_concealed_gain_syn_deemph, &sts[ch]->last_concealed_gain_syn_deemph_e ); - f2me_16( sts[ch]->hTcxDec->old_gaintcx_bfi_float, &sts[ch]->hTcxDec->old_gaintcx_bfi, &sts[ch]->hTcxDec->old_gaintcx_bfi_e ); - floatToFixed_arr( Aq[ch], Aq_fx[ch], Q12, ( NB_SUBFR16k + 1 ) * ( M + 1 ) ); - - sts[ch]->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( sts[ch]->hTcxDec->tcxltp_last_gain_unmodified_float, Q15 ); - sts[ch]->old_fpitch = float_to_fix( sts[ch]->old_fpitch_float, Q16 ); - sts[ch]->hTonalMDCTConc->lastPitchLag = float_to_fix( sts[ch]->hTonalMDCTConc->lastPitchLag_float, Q16 ); - // u8bit to 16bit FOR( l = 0; l < IGF_START_MX; l++ ) { sts[ch]->hIGFDec->infoTCXNoise_evs[l] = (Word16) sts[ch]->hIGFDec->infoTCXNoise[l]; + move16(); } - FOR( l = 0; l < N_LTP_GAIN_MEMS; l++ ) - { - sts[ch]->hTcxDec->ltpGainMemory_fx[l] = float_to_fix16( sts[ch]->hTcxDec->ltpGainMemory[l], Q15 ); - } - sts[ch]->hTcxDec->cummulative_damping_tcx = float_to_fix16( sts[ch]->hTcxDec->cummulative_damping_tcx_float, Q15 ); } } - //FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - //{ - // IF( sts[ch]->rate_switching_reset ) - // { - // floatToFixed_arr( sts[ch]->lsp_old, sts[ch]->lsp_old_fx, Q15, M ); - // } - //} - IF( sts[0]->bfi && ( hCPE->hStereoMdct->mdct_stereo_mode[0] > SMDCT_DUAL_MONO || hCPE->hStereoMdct->mdct_stereo_mode[1] > SMDCT_DUAL_MONO ) ) - { - floatToFixed_arr( sts[0]->hTonalMDCTConc->lastBlockData.spectralData_float, sts[0]->hTonalMDCTConc->lastBlockData.spectralData, ( 15 - sts[0]->hTonalMDCTConc->lastBlockData.spectralData_exp ), L_FRAME_MAX ); - floatToFixed_arr( sts[1]->hTonalMDCTConc->lastBlockData.spectralData_float, sts[1]->hTonalMDCTConc->lastBlockData.spectralData, ( 15 - sts[1]->hTonalMDCTConc->lastBlockData.spectralData_exp ), L_FRAME_MAX ); - } -#endif + ivas_mdct_core_invQ_fx( hCPE, nTnsBitsTCX10, p_param, param_lpc, param, fUseTns, tnsData, x_0_fx, x_0_e, x_fx, x_e, x_len, Aq_fx, ms_mask, 0 ); -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + + FOR(ch = 0; ch < CPE_CHANNELS; ch++) { - IF( sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) - { - me2f_buf( x_fx[ch][0], x_e[ch][0], x[ch][0], sts[ch]->hTcxCfg->tcx_coded_lines ); - sts[ch]->hTcxDec->damping_float = fix16_to_float( sts[ch]->hTcxDec->damping, Q14 ); - sts[ch]->hTcxDec->gainHelper_float = me2f_16( sts[ch]->hTcxDec->gainHelper, sts[ch]->hTcxDec->gainHelper_e ); - sts[ch]->hTcxDec->stepCompensate_float = me2f_16( sts[ch]->hTcxDec->stepCompensate, sts[ch]->hTcxDec->stepCompensate_e ); - } - IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) + IF(sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE) { - sts[ch]->lp_gainp = fix_to_float( sts[ch]->Mode2_lp_gainp, Q16 ); - sts[ch]->hTonalMDCTConc->lastPitchLag_float = fix_to_float( sts[ch]->hTonalMDCTConc->lastPitchLag, Q16 ); - sts[ch]->hTonalMDCTConc->nFramesLost_float = fix16_to_float( sts[ch]->hTonalMDCTConc->nFramesLost, Q1 ); - sts[ch]->hTcxDec->damping_float = fix16_to_float( sts[ch]->hTcxDec->damping, Q14 ); - sts[ch]->hTcxDec->stepCompensate_float = me2f_16( sts[ch]->hTcxDec->stepCompensate, sts[ch]->hTcxDec->stepCompensate_e ); - sts[ch]->hTcxDec->gainHelper_float = me2f_16( sts[ch]->hTcxDec->gainHelper, sts[ch]->hTcxDec->gainHelper_e ); - sts[ch]->last_concealed_gain_syn_deemph_float = me2f_16( sts[ch]->last_concealed_gain_syn_deemph, sts[ch]->last_concealed_gain_syn_deemph_e ); - sts[ch]->last_gain_syn_deemph_float = me2f_16( sts[ch]->last_gain_syn_deemph, sts[ch]->last_gain_syn_deemph_e ); - sts[ch]->hTcxDec->old_gaintcx_bfi_float = me2f_16( sts[ch]->hTcxDec->old_gaintcx_bfi, sts[ch]->hTcxDec->old_gaintcx_bfi_e ); - fixedToFloat_arr( Aq_fx[ch], Aq[ch], Q12, ( NB_SUBFR16k + 1 ) * ( M + 1 ) ); // 16bit to u8bit - FOR( l = 0; l < IGF_START_MX; l++ ) - { - sts[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t) sts[ch]->hIGFDec->infoTCXNoise_evs[l]; - } - FOR( l = 0; l < N_LTP_GAIN_MEMS; l++ ) + FOR(l = 0; l < IGF_START_MX; l++) { - sts[ch]->hTcxDec->ltpGainMemory[l] = fix16_to_float( sts[ch]->hTcxDec->ltpGainMemory_fx[l], Q15 ); + sts[ch]->hIGFDec->infoTCXNoise[l] = (UWord8)sts[ch]->hIGFDec->infoTCXNoise_evs[l]; } - Word16 subFrames = ( sts[ch]->core == TCX_10_CORE ) ? NB_DIV : 1; - FOR( k = 0; k < subFrames; ++k ) - { - // To be made into Q11 - me2f_buf( x_fx[ch][k], x_e[ch][k], x[ch][k], x_len[ch][k] ); - me2f_buf( x_0_fx[ch][k], x_0_e[ch][k], x_0[ch][k], sts[ch]->L_frameTCX_past ); - } - IF( !sts[0]->bfi || ( sts[0]->bfi && sts[ch]->core != ACELP_CORE ) ) - { - me2f_buf( sts[ch]->hIGFDec->virtualSpec, sts[ch]->hIGFDec->virtualSpec_e, sts[ch]->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); - } - sts[ch]->hTcxDec->cummulative_damping_tcx_float = fix16_to_float( sts[ch]->hTcxDec->cummulative_damping_tcx, Q15 ); } } - //FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - //{ - // IF( sts[ch]->rate_switching_reset ) - // { - // Word16 old_Aq_12_8_e = norm_s( sts[ch]->old_Aq_12_8_fx[0] ); - // fixedToFloat_arr( sts[ch]->old_Aq_12_8_fx, sts[ch]->old_Aq_12_8, ( 15 - old_Aq_12_8_e ), M + 1 ); - // } - //} - IF( sts[0]->bfi && ( hCPE->hStereoMdct->mdct_stereo_mode[0] > SMDCT_DUAL_MONO || hCPE->hStereoMdct->mdct_stereo_mode[1] > SMDCT_DUAL_MONO ) ) - { - fixedToFloat_arr( sts[0]->hTonalMDCTConc->lastBlockData.spectralData, sts[0]->hTonalMDCTConc->lastBlockData.spectralData_float, ( 15 - sts[0]->hTonalMDCTConc->lastBlockData.spectralData_exp ), sts[0]->L_frameTCX_past ); - fixedToFloat_arr( sts[1]->hTonalMDCTConc->lastBlockData.spectralData, sts[1]->hTonalMDCTConc->lastBlockData.spectralData_float, ( 15 - sts[1]->hTonalMDCTConc->lastBlockData.spectralData_exp ), sts[0]->L_frameTCX_past ); - } - FOR( i = 0; i < CPE_CHANNELS; ++i ) + + FOR(ch = 0; ch < CPE_CHANNELS; ch++) { - free( x_fx[i][0] ); - free( x_0_fx[i][0] ); + Word16 subFrames = (hCPE->hCoreCoder[ch]->core == TCX_10_CORE) ? NB_DIV : 1; + FOR(k = 0; k < subFrames; ++k) + { + Scale_sig32(x_fx[ch][k], x_len[ch][k], sub(x_e[ch][k], 20)); + x_e[ch][k] = 20; + move16(); + Scale_sig32(x_0_fx[ch][k], x_len[ch][k], sub(x_0_e[ch][k], 20)); + x_0_e[ch][k] = 20; + move16(); + } } -#endif -#else - ivas_mdct_core_invQ( hCPE, nTnsBitsTCX10, p_param, param_lpc, param, fUseTns, tnsData, x_0, x, Aq, ms_mask, 0 ); -#endif - for ( ch = 0; ch < nChannels; ch++ ) + FOR( ch = 0; ch < nChannels; ch++ ) { - nSubframes[ch] = ( sts[ch]->core == TCX_10_CORE ) ? NB_DIV : 1; - for ( k = 0; k < nSubframes[ch]; k++ ) + nSubframes[ch] = EQ_16( sts[ch]->core, TCX_10_CORE ) ? NB_DIV : 1; + move16(); + + FOR( k = 0; k < nSubframes[ch]; k++ ) { - L_spec[ch] = sts[ch]->hTcxCfg->tcx_coded_lines / nSubframes[ch]; + L_spec[ch] = idiv1616(sts[ch]->hTcxCfg->tcx_coded_lines, nSubframes[ch]); init_tcx_info( sts[ch], sts[ch]->L_frame / nSubframes[ch], sts[ch]->hTcxDec->L_frameTCX / nSubframes[ch], k, bfi, &tcx_offset[ch], &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] ); } } /* IGF decoding */ - if ( sts[0]->igf || sts[1]->igf ) + IF ( NE_16(sts[0]->igf, 0) || NE_16(sts[1]->igf, 0) ) { - if ( sts[0]->core != sts[1]->core ) + IF ( NE_16(sts[0]->core, sts[1]->core) ) { - for ( ch = 0; ch < nChannels; ch++ ) + FOR ( ch = 0; ch < nChannels; ch++ ) { st = sts[ch]; - if ( !bfi || ( bfi && st->core != ACELP_CORE ) ) + IF ( !EQ_16(bfi, 0) || ( NE_16(bfi, 0) && NE_16(st->core, ACELP_CORE) ) ) { - for ( k = 0; k < nSubframes[ch]; k++ ) + FOR ( k = 0; k < nSubframes[ch]; k++ ) { /* mono or dual mono IGF decoding */ -#ifdef IVAS_FLOAT_FIXED - // Float to fixed - Word32 x_fx[N_MAX]; - Word16 x_e; - Word16 x_len; - -#if 1 - // NOTE: The folloing code is to pre-calculate "stop", which is the length of x that will get - // updated inside the function decoder_tcx_IGF_mono_fx. Can remove this later. - Word16 stop; - Word16 tmp_igfGridIdx = IGF_GRID_LB_SHORT; - IF(NE_16(L_frame[ch], shr(st->L_frame, 1)) && st->tcxonly) - { - tmp_igfGridIdx = (EQ_16(st->last_core, ACELP_CORE) || (left_rect[ch] && bfi)) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM; - } - stop = st->hIGFDec->igfData.igfInfo.grid[tmp_igfGridIdx].stopLine; + decoder_tcx_IGF_mono_fx( st, x_fx[ch][k], &x_e[ch][k], &x_len[ch][k], L_frame[ch], left_rect[ch], bfi, k ); + Scale_sig32(x_fx[ch][k], x_len[ch][k], sub(x_e[ch][k], 20)); + x_e[ch][k] = 20; + move16(); IF(st->igf) { - f2me_buf(x[ch][k], x_fx, &x_e, stop); - } -#endif - decoder_tcx_IGF_mono_fx( st, x_fx, &x_e, &x_len, L_frame[ch], left_rect[ch], bfi, k ); - IF(st->igf) - { - // Fixed to float - me2f_buf(x_fx, x_e, x[ch][k], x_len); - me2f_buf(st->hIGFDec->virtualSpec, st->hIGFDec->virtualSpec_e, st->hIGFDec->virtualSpec_float, ((tmp_igfGridIdx == IGF_GRID_LB_SHORT) ? (N_MAX_TCX - IGF_START_MN) / 2 : (N_MAX_TCX - IGF_START_MN))); // 16bit to u8bit - FOR(Word16 l = 0; l < IGF_START_MX; l++) + FOR( l = 0; l < IGF_START_MX; l++) { - st->hIGFDec->infoTCXNoise[l] = (uint8_t)st->hIGFDec->infoTCXNoise_evs[l]; + st->hIGFDec->infoTCXNoise[l] = (UWord8)st->hIGFDec->infoTCXNoise_evs[l]; } } -#else - decoder_tcx_IGF_mono( st, x[ch][k], L_frame[ch], left_rect[ch], bfi, k ); -#endif } } } } - else if ( sts[0]->core != ACELP_CORE ) + ELSE IF ( NE_16(sts[0]->core, ACELP_CORE) ) { - assert( nSubframes[0] == nSubframes[1] ); + assert( EQ_16(nSubframes[0], nSubframes[1]) ); - for ( k = 0; k < nSubframes[0]; k++ ) + FOR ( k = 0; k < nSubframes[0]; k++ ) { - if ( ( hCPE->hStereoMdct->IGFStereoMode[k] != SMDCT_DUAL_MONO || hCPE->hStereoMdct->mdct_stereo_mode[k] != SMDCT_DUAL_MONO ) && !hCPE->hStereoMdct->isSBAStereoMode ) + IF ( ( NE_16(hCPE->hStereoMdct->IGFStereoMode[k], SMDCT_DUAL_MONO) || NE_16(hCPE->hStereoMdct->mdct_stereo_mode[k], SMDCT_DUAL_MONO) ) && EQ_16(hCPE->hStereoMdct->isSBAStereoMode, 0) ) { - assert( ( sts[0]->core == sts[1]->core ) || ( hCPE->hStereoMdct->mdct_stereo_mode[0] == SMDCT_DUAL_MONO ) ); + assert( ( EQ_16(sts[0]->core, sts[1]->core) ) || ( EQ_16(hCPE->hStereoMdct->mdct_stereo_mode[0], SMDCT_DUAL_MONO) ) ); /* stereo IGF decoding */ -#ifdef IVAS_FLOAT_FIXED - Word16 x_e[CPE_CHANNELS][NB_DIV]; - Word16 x_len[CPE_CHANNELS][NB_DIV]; - Word32 *x_fx_ptr[CPE_CHANNELS][NB_DIV]; - FOR(Word16 i = 0; i < CPE_CHANNELS; i++) - { - FOR(Word16 j = 0; j < NB_DIV; j++) - { - x_fx_ptr[i][j] = (Word32 *)malloc(sizeof(Word32) * N_MAX); - } - } - -#if 1 - // NOTE: The folloing code is to calcuate stop1 and stop2 which are the lengths of x[0][k] and x[1][k] - // that are going to get updated in the decoder_tcx_IGF_stereo_fx function. can remove this part later. - Word16 stop1, stop2, igfGridIdx; - igfGridIdx = IGF_GRID_LB_SHORT; - if (!(L_frame[0] == sts[0]->L_frame >> 1) && (sts[0]->tcxonly)) - { - igfGridIdx = (sts[0]->last_core == ACELP_CORE || (left_rect[0] && bfi)) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM; - } - stop1 = sts[0]->hIGFDec->igfData.igfInfo.grid[igfGridIdx].stopLine; - stop2 = sts[1]->hIGFDec->igfData.igfInfo.grid[igfGridIdx].stopLine; - // NOTE end. -#endif - - f2me_buf(x[0][k], x_fx_ptr[0][k], &x_e[0][k], stop1); - f2me_buf(x[1][k], x_fx_ptr[1][k], &x_e[1][k], stop2); - - decoder_tcx_IGF_stereo_fx( sts, hCPE->hStereoMdct, ms_mask, x_fx_ptr, x_e, x_len, L_frame[0], left_rect[0], k, bfi, 0 /* MCT_flag */ ); - - me2f_buf(x_fx_ptr[0][k], x_e[0][k], x[0][k], x_len[0][k]); - me2f_buf(x_fx_ptr[1][k], x_e[1][k], x[1][k], x_len[1][k]); - FOR(Word16 i = 0; i < IGF_START_MX; i++) + decoder_tcx_IGF_stereo_fx( sts, hCPE->hStereoMdct, ms_mask, x_fx, x_e, x_len, L_frame[0], left_rect[0], k, bfi, 0 /* MCT_flag */ ); + Scale_sig32(x_fx[0][k], x_len[0][k], sub(x_e[0][k], 20)); + Scale_sig32(x_fx[1][k], x_len[1][k], sub(x_e[1][k], 20)); + x_e[0][k] = 20; + x_e[1][k] = 20; + move16(); move16(); + + FOR( i = 0; i < IGF_START_MX; i++) { - sts[0]->hIGFDec->infoTCXNoise[i] = (uint8_t)sts[0]->hIGFDec->infoTCXNoise_evs[i]; - sts[1]->hIGFDec->infoTCXNoise[i] = (uint8_t)sts[1]->hIGFDec->infoTCXNoise_evs[i]; + sts[0]->hIGFDec->infoTCXNoise[i] = (UWord8)sts[0]->hIGFDec->infoTCXNoise_evs[i]; + sts[1]->hIGFDec->infoTCXNoise[i] = (UWord8)sts[1]->hIGFDec->infoTCXNoise_evs[i]; } - FOR(Word16 i = 0; i < CPE_CHANNELS; i++) - { - FOR(Word16 j = 0; j < NB_DIV; j++) - { - free(x_fx_ptr[i][j]);; - } - } -#else - decoder_tcx_IGF_stereo( sts, hCPE->hStereoMdct, ms_mask, x, L_frame[0], left_rect[0], k, bfi, 0 /* MCT_flag */ ); -#endif } - else + ELSE { - for ( ch = 0; ch < nChannels; ch++ ) + FOR ( ch = 0; ch < nChannels; ch++ ) { st = sts[ch]; /* mono or dual mono IGF decoding */ -#ifdef IVAS_FLOAT_FIXED - // Float to fixed - Word32 x_fx[N_MAX]; - Word16 x_e; - Word16 x_len; - -#if 1 - // NOTE: The folloing code is to pre-calculate "stop", which is the length of x that will get - // updated inside the function decoder_tcx_IGF_mono_fx. Can remove this later. - Word16 stop; - Word16 tmp_igfGridIdx = IGF_GRID_LB_SHORT; - IF(NE_16(L_frame[ch], shr(st->L_frame, 1)) && st->tcxonly) - { - tmp_igfGridIdx = (EQ_16(st->last_core, ACELP_CORE) || (left_rect[ch] && bfi)) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM; - } - stop = st->hIGFDec->igfData.igfInfo.grid[tmp_igfGridIdx].stopLine; + decoder_tcx_IGF_mono_fx( st, x_fx[ch][k], &x_e[ch][k], &x_len[ch][k], L_frame[ch], left_rect[ch], bfi, k ); + Scale_sig32(x_fx[ch][k], x_len[ch][k], sub(x_e[ch][k], 20)); + x_e[ch][k] = 20; + move16(); IF(st->igf) { - f2me_buf(x[ch][k], x_fx, &x_e, stop); - } - // NOTE end -#endif - decoder_tcx_IGF_mono_fx( st, x_fx, &x_e, &x_len, L_frame[ch], left_rect[ch], bfi, k ); - // Fixed to float - IF(st->igf) - { - me2f_buf(x_fx, x_e, x[ch][k], x_len); - me2f_buf(st->hIGFDec->virtualSpec, st->hIGFDec->virtualSpec_e, st->hIGFDec->virtualSpec_float, (N_MAX_TCX - IGF_START_MN)); // 16bit to u8bit - FOR(Word16 l = 0; l < IGF_START_MX; l++) + FOR( l = 0; l < IGF_START_MX; l++) { - st->hIGFDec->infoTCXNoise[l] = (uint8_t)st->hIGFDec->infoTCXNoise_evs[l]; + st->hIGFDec->infoTCXNoise[l] = (UWord8)st->hIGFDec->infoTCXNoise_evs[l]; } } -#else - decoder_tcx_IGF_mono( st, x[ch][k], L_frame[ch], left_rect[ch], bfi, k ); -#endif } } } } } + FOR(ch = 0; ch < CPE_CHANNELS; ch++) + { + Copy_Scale_sig_16_32(Aq_fx[ch], Aq_fx_32[ch], (NB_SUBFR16k + 1) * (M + 1), sub(Q16, Q12)); + } + /*--------------------------------------------------------------------------------* * Stereo processing *--------------------------------------------------------------------------------*/ - if ( !bfi ) + IF ( EQ_16(bfi, 0) ) { - for ( ch = 0; ch < CPE_CHANNELS; ch++ ) + FOR ( ch = 0; ch < CPE_CHANNELS; ch++ ) { + Word32 sns_int_scf_fx[FDNS_NPTS]; + Word16 scf_fx[FDNS_NPTS], scf_e[FDNS_NPTS]; + Word16 norm; + st = sts[ch]; - for ( k = 0; k < nSubframes[ch]; k++ ) + FOR ( k = 0; k < nSubframes[ch]; k++ ) { - float sns_int_scf[FDNS_NPTS]; - -#ifdef IVAS_FLOAT_FIXED - Word32 sns_int_scf_fx[FDNS_NPTS], Aq_fx[(NB_SUBFR16k + 1) * (M + 1)]; - FOR(int c = 0; c < (NB_SUBFR16k + 1) * (M + 1); c++) - { - Aq_fx[c] = (Word32) ( Aq[ch][k * M + c] * ONE_IN_Q16 ); - } - - sns_interpolate_scalefactors_fx( sns_int_scf_fx, Aq_fx, DEC ); - - FOR( int c = 0; c < FDNS_NPTS; c++ ) - { - sns_int_scf[c] = ( (float) sns_int_scf_fx[c] / ONE_IN_Q16 ); - } -#else - sns_interpolate_scalefactors( &sns_int_scf[0], &Aq[ch][k * M], DEC ); -#endif // IVAS_FLOAT_FIXED - - if ( st->hTonalMDCTConc != NULL && ( ( k + 1 ) == nSubframes[ch] ) ) + sns_interpolate_scalefactors_fx( sns_int_scf_fx, Aq_fx_32[ch], DEC ); + + IF ( st->hTonalMDCTConc != NULL && EQ_16( add( k, 1 ), nSubframes[ch] ) ) { -#ifdef IVAS_FLOAT_FIXED - Word32 x_fx[N_MAX]; - Word16 x_e, scf_fx[FDNS_NPTS], scf_e[FDNS_NPTS]; - f2me_buf( x[ch][k], x_fx, &x_e, L_frameTCX[ch] ); - for ( int j = 0; j < st->hTonalMDCTConc->nScaleFactors; j++ ) + x_e[ch][k] = 20; + move16(); + FOR ( j = 0; j < st->hTonalMDCTConc->nScaleFactors; j++ ) { - f2me_16( sns_int_scf[j], &scf_fx[j], &scf_e[j] ); + norm = norm_l(sns_int_scf_fx[j]); + scf_e[j] = sub(15, norm); + scf_fx[j] = extract_h(L_shl(sns_int_scf_fx[j], norm)); } - TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx, x_e, L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); - st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); -#else - TonalMDCTConceal_SaveFreqSignal_ivas( st->hTonalMDCTConc, x[ch][k], L_frameTCX[ch], L_frame[ch], &sns_int_scf[0], get_igf_startline_flt( st, L_frame[ch], L_frameTCX[ch] ) ); -#endif + Word16 s = getScaleFactor32(x_fx[ch][k], L_frameTCX[ch]); + Scale_sig32(x_fx[ch][k], L_frameTCX[ch], s); + TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx[ch][k], sub(x_e[ch][k], s), L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); + Scale_sig32(x_fx[ch][k], L_frameTCX[ch], negate(s)); } } - TonalMDCTConceal_UpdateState_ivas( st->hTonalMDCTConc, L_frameTCX[ch], ( st->hTcxDec->tcxltp_last_gain_unmodified_float > 0 ) ? st->old_fpitch_float : 0, bfi, bfi && st->tonal_mdct_plc_active ); + TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX[ch], ( st->hTcxDec->tcxltp_last_gain_unmodified > 0 ) ? st->old_fpitch : 0, bfi, bfi && st->tonal_mdct_plc_active ); } mvs2s( ms_mask[0], hCPE->hStereoMdct->prev_ms_mask[0], MAX_SFB ); mvs2s( ms_mask[1], hCPE->hStereoMdct->prev_ms_mask[1], MAX_SFB ); } - if ( ( !bfi || !( sts[0]->core == ACELP_CORE && sts[1]->core == ACELP_CORE ) ) && !hCPE->hStereoMdct->isSBAStereoMode ) + IF ( ( EQ_16(bfi, 0) || ( NE_16(sts[0]->core, ACELP_CORE) || NE_16(sts[1]->core, ACELP_CORE) ) ) && EQ_16(hCPE->hStereoMdct->isSBAStereoMode, 0) ) { -#ifdef IVAS_FLOAT_FIXED -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - Word16 q_in_out = Q11; Word16 q_x_1 = 11, q_x_0 = 11; - FOR( i = 0; i < CPE_CHANNELS; ++i ) - { - x_fx[i][0] = malloc( L_FRAME_PLUS * sizeof( Word32 ) ); - x_fx[i][1] = x_fx[i][0] + L_FRAME_PLUS / 2; - floatToFixed_arrL( x[i][0], x_fx[i][0], q_in_out, L_FRAME_PLUS / 2 ); - floatToFixed_arrL( x[i][1], x_fx[i][1], q_in_out, L_FRAME_PLUS / 2 ); - } - FOR( i = 0; i < CPE_CHANNELS; ++i ) - { - x_0_fx[i][0] = malloc( N_MAX * sizeof( Word32 ) ); - x_0_fx[i][1] = x_0_fx[i][0] + L_FRAME48k / 2; - floatToFixed_arrL( x_0[i][0], x_0_fx[i][0], q_in_out, L_FRAME48k / 2 ); - floatToFixed_arrL( x_0[i][1], x_0_fx[i][1], q_in_out, L_FRAME48k / 2 ); - } -#endif stereo_decoder_tcx_fx( hCPE->hStereoMdct, ms_mask, x_0_fx[1], x_fx[0], x_fx[1], &hCPE->hStereoMdct->mdct_stereo_mode[0], sts[0]->core, sts[1]->core, sts[0]->igf, L_frameTCX[0], L_frameTCX[1], 0, sts[0]->last_core, sts[1]->last_core, 0, &q_x_1, &q_x_0 ); -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - FOR( k = 0; k < CPE_CHANNELS; ++k ) - { - fixedToFloat_arrL( x_fx[k][0], x[k][0], q_in_out, L_FRAME_PLUS / 2 ); - fixedToFloat_arrL( x_fx[k][1], x[k][1], q_in_out, L_FRAME_PLUS / 2 ); - - fixedToFloat_arrL( x_0_fx[k][0], x_0[k][0], q_in_out, L_FRAME48k / 2 ); - fixedToFloat_arrL( x_0_fx[k][1], x_0[k][1], q_in_out, L_FRAME48k / 2 ); - free( x_fx[k][0] ); - free( x_0_fx[k][0] ); - } -#endif -#else - stereo_decoder_tcx( hCPE->hStereoMdct, ms_mask, x_0[1], x[0], x[1], &hCPE->hStereoMdct->mdct_stereo_mode[0], sts[0]->core, sts[1]->core, sts[0]->igf, L_frameTCX[0], L_frameTCX[1], 0, sts[0]->last_core, sts[1]->last_core, 0 ); -#endif } + + ivas_mdct_core_tns_ns_fx( hCPE, fUseTns, tnsData, x_fx, Aq_fx_32, 0, x_e ); + + FOR( Word16 ind = 0; ind < 2; ind++ ) { -#ifdef IVAS_FLOAT_FIXED -#if 1 /*Float to fixed conversion*/ - Word32 Aq_fx[2][102]; - Word16 x_e[MAX_CICP_CHANNELS][2] = { 0 }; - Word32 *x_fx[CPE_CHANNELS][NB_DIV]; - FOR( Word16 ind = 0; ind < 2; ind++ ) - { - FOR( Word16 ind2 = 0; ind2 < 102; ind2++ ) - { - Aq_fx[ind][ind2] = (Word32) ( Aq[ind][ind2] * ( ONE_IN_Q16 ) ); - } - FOR( Word16 ind2 = 0; ind2 < NB_DIV; ind2++ ) - { - x_fx[ind][ind2] = (Word32 *) malloc( sizeof( Word32 ) * N_MAX ); - } - f2me_buf( x[ind][0], x_fx[ind][0], &x_e[ind][0], 1200 ); - f2me_buf( x[ind][1], x_fx[ind][1], &x_e[ind][1], 600 ); - } - for ( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - st = sts[ch]; - st->hTcxDec->cummulative_damping_tcx = (Word16) ( st->hTcxDec->cummulative_damping_tcx_float * ( ONE_IN_Q15 ) ); - IF( st->hTonalMDCTConc ) - { - FOR( Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++ ) - { - f2me_16( st->hTonalMDCTConc->lastBlockData.scaleFactors_float[ind], &st->hTonalMDCTConc->lastBlockData.scaleFactors[ind], &st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[ind] ); - } - FOR( Word16 i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) - { - st->hTonalMDCTConc->scaleFactorsBackground_fx[i] = float_to_fix( st->hTonalMDCTConc->scaleFactorsBackground_flt[i], 15 ); - } - st->hTonalMDCTConc->scf_fadeout = float_to_fix16( st->hTonalMDCTConc->scf_fadeout_flt, 15 ); - st->hTonalMDCTConc->lastPitchLag = float_to_fix( st->hTonalMDCTConc->lastPitchLag_float, Q16 ); - if ( sts[0]->bfi && st->tonal_mdct_plc_active ) - { - FOR( Word16 i = 0; i < FDNS_NPTS; i++ ) - { - f2me_16( st->hTonalMDCTConc->secondLastBlockData.scaleFactors_float[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ); - } - FOR( Word16 i = 0; i < st->hTonalMDCTConc->pTCI_float->numIndexes; i++ ) - { - float pd = st->hTonalMDCTConc->pTCI_float->phaseDiff_float[i]; - if ( pd >= PI2 ) - pd = fmodf( pd, PI2 ) - PI2; - st->hTonalMDCTConc->pTCI_float->phaseDiff[i] = float_to_fix16( pd, Q12 ); - } - FOR( Word16 i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++ ) - { - float pd = st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float[i]; - pd = fmodf( pd, PI2 ); - st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted[i] = (Word16) ( pd * ( 1u << Q13 ) ); - } - //st->hTonalMDCTConc->nFramesLost = float_to_fix16( st->hTonalMDCTConc->nFramesLost, Q1 ); - } - f2me( st->hTonalMDCTConc->last_block_nrg_flt, &st->hTonalMDCTConc->last_block_nrg, &st->hTonalMDCTConc->last_block_nrg_exp ); - } - st->old_fpitch = float_to_fix( st->old_fpitch_float, 16 ); - st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); - } -#endif // IVAS_FLOAT_FIXED - ivas_mdct_core_tns_ns_fx( hCPE, fUseTns, tnsData, x_fx, Aq_fx, 0, x_e ); -#if 1 /*Fixed to float conversions*/ - FOR( Word16 ind = 0; ind < 2; ind++ ) - { - me2f_buf( x_fx[ind][0], x_e[ind][0], x[ind][0], 1200 ); - me2f_buf( x_fx[ind][1], x_e[ind][1], x[ind][1], 600 ); - } - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + Word16 nSubFrames = EQ_16( hCPE->hCoreCoder[ind]->core, TCX_20_CORE ) ? 1 : NB_DIV; + Scale_sig32( x_fx[ind][0], shr( L_FRAME_MAX, sub( nSubFrames, 1 ) ), sub( x_e[ind][0], 20 ) ); + x_e[ind][0] = 20; + move16(); + IF( nSubFrames == 2 ) { - st = sts[ch]; - IF( st->hTonalMDCTConc != NULL ) - { - st->hTonalMDCTConc->scf_fadeout_flt = fixedToFloat( st->hTonalMDCTConc->scf_fadeout, 15 ); - st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); - st->hTonalMDCTConc->lastPitchLag_float = fixedToFloat( st->hTonalMDCTConc->lastPitchLag, Q16 ); - if ( sts[0]->bfi && st->tonal_mdct_plc_active ) - { - st->hTonalMDCTConc->nFramesLost_float = fix16_to_float( st->hTonalMDCTConc->nFramesLost, Q1 ); - } - } + Scale_sig32( x_fx[ind][1], shr( L_FRAME_MAX, 1 ), sub( x_e[ind][1], 20 ) ); + x_e[ind][1] = 20; + move16(); } -#endif -#else - ivas_mdct_core_tns_ns( hCPE, fUseTns, tnsData, x, Aq, 0 ); -#endif - if ( st_ivas->renderer_type == RENDERER_MC_PARAMMC && ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO ) ) + } + + IF( EQ_16( st_ivas->renderer_type, RENDERER_MC_PARAMMC ) && ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { -#ifdef IVAS_FLOAT_FIXED - f2me_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); - f2me_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); - FOR(Word16 chOutIdx = 0; chOutIdx < st_ivas->hDecoderConfig->nchan_out; chOutIdx++ ) - { - FOR(Word16 chInIdx = 0; chInIdx < st_ivas->nchan_transport; chInIdx++ ) - { - st_ivas->hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx] = float_to_fix( st_ivas->hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx], 30 ); /*Q30*/ - } - } - ivas_ls_setup_conversion_process_mdct_param_mc_fx( st_ivas, x_fx, x_e ); - me2f_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); - me2f_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); -#else - ivas_ls_setup_conversion_process_mdct_param_mc( st_ivas, x ); -#endif // IVAS_FLOAT_FIXED - } - FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) - { - FOR( Word16 j = 0; j < NB_DIV; j++ ) - { - free( x_fx[i][j] ); - } - } + ivas_ls_setup_conversion_process_mdct_param_mc_fx( st_ivas, x_fx, x_e ); } - run_min_stats_fx( sts, x ); + run_min_stats_fx( sts, x_fx, x_e ); - if ( hCPE->nchan_out == 1 && ( !bfi || ( bfi && sts[0]->core != ACELP_CORE && sts[1]->core != ACELP_CORE ) ) ) + IF( EQ_16( hCPE->nchan_out, 1 ) && ( EQ_16( bfi, 0 ) || ( NE_16( bfi, 0 ) && NE_16( sts[0]->core, ACELP_CORE ) && NE_16( sts[1]->core, ACELP_CORE ) ) ) ) { -#ifdef IVAS_FLOAT_FIXED - Word32 *x_fx[CPE_CHANNELS][NB_DIV]; - FOR ( ch = 0; ch < nChannels; ch++ ) - { - x_fx[ch][0] = malloc( L_FRAME_PLUS * sizeof( Word32 ) ); - x_fx[ch][1] = x_fx[ch][0] + L_FRAME_PLUS / 2; - FOR ( Word16 j = 0; j < L_FRAME_PLUS / 2; ++j ) - { - x_fx[ch][0][j] = (Word32) ( x[ch][0][j] * ONE_IN_Q11 ); - x_fx[ch][1][j] = (Word32) ( x[ch][1][j] * ONE_IN_Q11 ); - } - } apply_dmx_weights_fx( hCPE, x_fx, sts[0]->transform_type, sts[1]->transform_type ); - FOR ( ch = 0; ch < nChannels; ch++ ) - { - FOR ( Word16 j = 0; j < L_FRAME_PLUS / 2; ++j ) - { - x[ch][0][j] = (float) x_fx[ch][0][j] / ONE_IN_Q11; - x[ch][1][j] = (float) x_fx[ch][1][j] / ONE_IN_Q11; - } - free( x_fx[ch][0] ); - } -#else - apply_dmx_weights( hCPE, x, sts[0]->transform_type, sts[1]->transform_type ); -#endif - } -#ifdef IVAS_FLOAT_FIXED - // - - Word16 signal_outFB_tmp_fx[2][1200]; - Word16 e_sig = 17; - - Word32 *x_fx_[2][2]; - Word16 q_x = Q11; - Word16 x_e_; - FOR(i = 0; i < 2; i++) { - FOR(j = 0; j < 2; j++) { - x_fx_[i][j] = malloc(1200 * sizeof(Word32)); - } } - Word16 L_frame_global[CPE_CHANNELS], L_frame_globalTCX[CPE_CHANNELS]; - x_e_ = 31 - q_x; - IF(signal_outFB_tmp[0]) floatToFixed_arr(signal_outFB_tmp[0], signal_outFB_tmp_fx[0], 15-e_sig, 960); - IF(signal_outFB_tmp[1]) floatToFixed_arr(signal_outFB_tmp[1], signal_outFB_tmp_fx[1], 15-e_sig, 960); - FOR( ch = 0; ch < 2; ch++) { - st = hCPE->hCoreCoder[ch]; - L_spec[0] = st->hTcxCfg->tcx_coded_lines / nSubframes[0]; - L_frame_global[0] = st->L_frame / nSubframes[0]; - L_frame_globalTCX[0] = st->hTcxDec->L_frameTCX / nSubframes[0]; - - FOR( i = 0; i < 1200; i++) { - x_fx_[ch][0][i] = (Word32)(x[ch][0][i] * (1 << q_x)); - } - FOR( i = 0; i < 600; i++) { - x_fx_[ch][1][i] = (Word32)(x[ch][1][i] * (1 << q_x)); - } - st->hIGFDec->virtualSpec_e = x_e_; -#ifndef IVAS_FLOAT_FIXED - IF ( NE_16(st->igf, 0) && st->hIGFDec && st->hIGFDec->virtualSpec_fx ) - FOR( i = 0; i < s_min(st->hIGFDec->infoIGFStopLine - st->hIGFDec->infoIGFStartLine, 856); i++) { - st->hIGFDec->virtualSpec_fx[st->hIGFDec->infoIGFStartLine - IGF_START_MN + i] = (Word32)(st->hIGFDec->virtualSpec_float[st->hIGFDec->infoIGFStartLine - IGF_START_MN + i] * (1 << (31 - st->hIGFDec->virtualSpec_e))); - } -#endif - IF(st->hTcxDec)st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( st->hTcxDec->tcxltp_last_gain_unmodified_float, Q15 ); - - IF(st->hTcxDec) st->hTcxDec->conceal_eof_gain = (Word16)(st->hTcxDec->conceal_eof_gain_float * 16384.f); - st->last_concealed_gain_syn_deemph = (Word16)(st->last_concealed_gain_syn_deemph_float * 32767.f); - - IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_Overl, st->Q_syn, L_FRAME32k / 2); - IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->syn_OverlFB_float, st->hTcxDec->syn_OverlFB, st->Q_syn, L_FRAME_MAX / 2); - IF(st->hTcxDec) st->hTcxDec->gainHelper = float_to_fix16( st->hTcxDec->gainHelper_float, Q14 ); - IF(st->hTcxDec) st->hTcxDec->gainHelper_e = 1; - IF(st->hTcxDec) st->hTcxDec->stepCompensate = float_to_fix16( st->hTcxDec->stepCompensate_float, Q14 ); - IF(st->hTcxDec) st->hTcxDec->stepCompensate_e = 1; - st->preemph_fac = float_to_fix16( st->preemph_fac_float, Q15 ); - IF(st->hTcxDec) st->hTcxDec->damping = float_to_fix16( st->hTcxDec->damping_float, Q14 ); - st->old_fpitch = float_to_fix( st->old_fpitch_float, Q16 ); - - st->prev_Q_syn = st->Q_syn; - st->old_fpitchFB = (Word32) ( st->old_fpitchFB_float * ONE_IN_Q16 ); - IF(hCPE->hStereoMdct) hCPE->hStereoMdct->lastCoh_fx = (Word16)(hCPE->hStereoMdct->lastCoh * (1<<14)); - st->lp_gainp_fx = float_to_fix16(st->lp_gainp, 14); - IF(st->hTonalMDCTConc) st->hTonalMDCTConc->lastPitchLag = float_to_fix(st->hTonalMDCTConc->lastPitchLag_float, Q16); - - st->enr_old_fx = (Word32)st->enr_old; - - IF(st->hHQ_core) floatToFixed_arr(st->hHQ_core->old_outLB, st->hHQ_core->old_out_LB_fx, st->Q_syn, L_FRAME32k); - IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->syn_Overl_TDACFB_float, st->hTcxDec->syn_Overl_TDACFB, -1 - st->Q_syn, L_FRAME_MAX / 2); - IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->syn_Overl_TDAC_float, st->hTcxDec->syn_Overl_TDAC, -1 - st->Q_syn, L_FRAME32k / 2); - IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, -1 - st->Q_syn, L_FRAME32k / 2); - //floatToFixed_arr( st->mem_syn2, st->mem_syn2_fx, st->Q_syn, M ); - //floatToFixed_arr( st->mem_syn_r_float, st->mem_syn_r, st->Q_syn, L_SYN_MEM ); - floatToFixed_arr( st->syn_float, st->syn, -1, M + 1 ); - //floatToFixed_arr( st->old_exc, st->old_exc_fx, st->Q_exc, L_EXC_MEM_DEC ); - - IF(st->hTcxDec) st->hTcxDec->tcxltp_third_last_pitch = float_to_fix(st->hTcxDec->tcxltp_third_last_pitch_float, 16); - IF(st->hTcxDec) st->hTcxDec->tcxltp_second_last_pitch = float_to_fix(st->hTcxDec->tcxltp_second_last_pitch_float, 16); - IF(st->hTcxDec) st->hTcxLtpDec->tcxltp_gain = (Word16)floatToFixed(st->hTcxLtpDec->tcxltp_gain_float, Q15); - - IF(st->hBPF) st->mem_error = floatToFixed( st->hBPF->pst_mem_deemp_err, Q16 ); - IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->old_excFB, st->hTcxDec->old_excFB_fx, st->Q_exc, st->L_frame); - - st->Mode2_lp_gainc = (Word32) (st->lp_gainc * ONE_IN_Q16); - st->Mode2_lp_gainp= (Word32) (st->lp_gainp * ONE_IN_Q29); - st->cummulative_damping = (Word16) (st->cummulative_damping_float * MAX_16); - //st->old_enr_LP = (Word16) (st->old_enr_LP_float * ONE_IN_Q3); - - if ( !st->tcxonly ) - { - floatToFixed_arr( st->p_bpf_noise_buf_float, st->p_bpf_noise_buf, 0, L_FRAME_16k ); - } - IF(st->hBPF) floatToFixed_arr( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); - - //floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); - - IF(st->hBPF) st->mem_error = floatToFixed( st->hBPF->pst_mem_deemp_err, Q16 ); - - IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->old_synth_float, st->hTcxDec->old_synth, st->Q_syn, 1280); - IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->old_synthFB, st->hTcxDec->old_synthFB_fx, st->Q_syn, s_max(st->hTcxDec->L_frameTCX, st->hTcxDec->old_synth_lenFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ))); - IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->synth_history, st->hTcxDec->synth_history_fx, st->Q_syn, NS2SA( st->output_Fs, PH_ECU_MEM_NS )); - - float maxim = 0; - IF(st->hFdCngDec && st->hFdCngDec->hFdCngCom) { - FOR(Word16 ind = 0; ind < 340; ind++) - { - maxim = fmaxf(maxim, fabsf(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[ind])); - } - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; - IF(L_abs((Word32)maxim)!=0) st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - norm_l((Word32)maxim); - FOR(Word16 ind = 0; ind < 340; ind++) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel[ind] = (Word32)(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[ind] * (1LL<<(31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp))); - } - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = float_to_fix16(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt, 15); - } - IF(st->hHQ_core) floatToFixed_arr(st->hHQ_core->old_out, st->hHQ_core->old_out_fx, st->Q_syn, 960); - IF(st->hTonalMDCTConc) floatToFixed_arr(st->hTonalMDCTConc->lastPcmOut_float, st->hTonalMDCTConc->lastPcmOut, -2, st->hTonalMDCTConc->nSamples); - IF(st->hTonalMDCTConc) floatToFixed_arr(st->hTonalMDCTConc->secondLastPcmOut_float, st->hTonalMDCTConc->secondLastPcmOut, -2, st->hTonalMDCTConc->nSamples / 2); - if ( st->hPlcInfo ) - { - //st->hPlcInfo->step_concealgain_fx = float_to_fix16( st->hPlcInfo->step_concealgain, Q15 ); - //st->hPlcInfo->recovery_gain_float = float_to_fix16( st->hPlcInfo->recovery_gain, Q14 ); - } - IF(st->hTcxDec) - st->hTcxDec->conceal_eof_gain = float_to_fix16( st->hTcxDec->conceal_eof_gain_float, Q14 ); - if ( st->hTcxDec && st->hTcxDec->conCngLevelBackgroundTrace_e < 0 ) - { - st->hTcxDec->conCngLevelBackgroundTrace_e = 0; - } - IF(st->hTcxDec) f2me_16(st->hTcxDec->CngLevelBackgroundTrace_bfi, &st->hTcxDec->conCngLevelBackgroundTrace, &st->hTcxDec->conCngLevelBackgroundTrace_e); - if ( st->hTcxDec && st->hTcxDec->conLastFrameLevel_e < 0 ) - { - st->hTcxDec->conLastFrameLevel_e = 0; - } - IF(st->hTcxDec) st->hTcxDec->conLastFrameLevel = (Word16) floatToFixed( st->hTcxDec->LastFrameLevel_bfi, 15 - st->hTcxDec->conLastFrameLevel_e ); - if ( st->hTcxDec && st->hTcxDec->conNoiseLevelMemory_e[0] < 0 ) + + Word16 s; + FOR(ch = 0; ch < CPE_CHANNELS; ch++) + { + IF(sts[ch]->hFdCngDec && sts[ch]->hFdCngDec->hFdCngCom) { - set16_fx( st->hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); + s = getScaleFactor32(sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN); + Scale_sig32(sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, s); + sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = add(sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, s); } - IF(st->hTcxDec) floatToFixed_arr( st->hTcxDec->NoiseLevelMemory_bfi, st->hTcxDec->conNoiseLevelMemory, Q15, PLC_MIN_STAT_BUFF_SIZE ); - IF(st->hTcxDec) st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; - IF(st->hTcxDec) st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; - floatToFixed_arrL( st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2 ); - IF(st->hTcxDec) for ( int p = 0; p < st->L_frame; p++ ) - { - st->hTcxDec->old_excFB_fx[p] = (Word16) ( st->hTcxDec->old_excFB[p] * ( 1u << st->Q_exc ) ); + IF(sts[ch]->hFdCngDec && sts[ch]->hFdCngDec->hFdCngCom) { + sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h(sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx); } - IF(st->hFdCngDec && st->hFdCngDec->hFdCngCom) floatToFixed_arr(st->hFdCngDec->hFdCngCom->A_cng_flt, st->hFdCngDec->hFdCngCom->A_cng, 15, 17); - } - //FOR( Word16 ind = 0; ind < M + 1; ind++ ) - //{ - // hCPE->hCoreCoder[0]->old_Aq_12_8_fx[ind] = (Word16) ( hCPE->hCoreCoder[0]->old_Aq_12_8[ind] * 4096.f ); - // hCPE->hCoreCoder[1]->old_Aq_12_8_fx[ind] = (Word16) ( hCPE->hCoreCoder[1]->old_Aq_12_8[ind] * 4096.f ); - // hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32[ind] = (Word32)(hCPE->hCoreCoder[0]->old_Aq_12_8[ind] * (1<<28)); - // hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32[ind] = (Word32)(hCPE->hCoreCoder[1]->old_Aq_12_8[ind] * (1<<28)); - //} - // + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, M + 1, ( 28 - norm_s( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0] - 1 ) ) ); Copy_Scale_sig_16_32( hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, M + 1, ( 28 - norm_s( hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0] - 1 ) ) ); - ivas_mdct_core_reconstruct_fx( hCPE, x_fx_, signal_outFB_tmp_fx, fUseTns, 0, q_x, e_sig ); - // - IF(hCPE->hStereoMdct) hCPE->hStereoMdct->lastCoh = fix16_to_float(hCPE->hStereoMdct->lastCoh_fx, 14); - IF(signal_outFB_tmp[0]) fixedToFloat_arr(signal_outFB_tmp_fx[0], signal_outFB_tmp[0], 15 - e_sig, 960); - IF(signal_outFB_tmp[1]) fixedToFloat_arr(signal_outFB_tmp_fx[1], signal_outFB_tmp[1], 15 - e_sig, 960); - FOR( ch = 0; ch < 2; ch++) { - st = hCPE->hCoreCoder[ch]; - IF(st->igf) me2f_buf(x_fx_[ch][0], 31 - q_x, x[ch][0], s_min(1200, s_max(st->hIGFDec->infoIGFStopLine, s_max(L_frameTCX[ch], L_spec[ch]) ))); - IF(st->igf && nSubframes[ch] > 1) me2f_buf(x_fx_[ch][1], 31 - q_x, x[ch][1], s_min(s_max(st->hIGFDec->infoIGFStopLine, s_max(L_frameTCX[ch], L_spec[ch])), 600) ); - fixedToFloat_arr(st->hTcxDec->syn_OverlFB, st->hTcxDec->syn_OverlFB_float, st->Q_syn, L_FRAME_MAX / 2); - fixedToFloat_arr(st->hTcxDec->syn_Overl, st->hTcxDec->syn_Overl_float, st->Q_syn, L_FRAME32k / 2); - fixedToFloat_arr( st->syn, st->syn_float, st->Q_syn, M + 1 ); - st->hTonalMDCTConc->lastPitchLag_float = fix_to_float(st->hTonalMDCTConc->lastPitchLag, Q16); - st->hTcxDec->tcxltp_third_last_pitch_float = fix_to_float(st->hTcxDec->tcxltp_third_last_pitch, 16); - st->hTcxDec->tcxltp_second_last_pitch_float = fix_to_float(st->hTcxDec->tcxltp_second_last_pitch, 16); - st->old_fpitch_float = fix_to_float(st->old_fpitch, 16); - st->old_fpitchFB_float = fix_to_float(st->old_fpitchFB, 16); - st->hTcxDec->tcxltp_last_gain_unmodified_float = fix16_to_float( st->hTcxDec->tcxltp_last_gain_unmodified, Q15 ); - st->hTcxLtpDec->tcxltp_gain_float = fix16_to_float( st->hTcxLtpDec->tcxltp_gain, Q15 ); - st->hTcxDec->conceal_eof_gain_float = fix16_to_float( st->hTcxDec->conceal_eof_gain, Q14 ); - //FOR(Word16 ind = 0; ind < 17; ind++) { - // st->old_Aq_12_8[ind] = (float)(st->old_Aq_12_8_fx[ind]) / (float)(1<<12); - //} - - IF(st->hBPF) st->hBPF->pst_mem_deemp_err = fixedToFloat( st->mem_error, Q16 ); - for ( int p = 0; p < st->L_frame; p++ ) - { - st->hTcxDec->old_excFB[p] = (float) ( st->hTcxDec->old_excFB_fx[p] ) / ( 1u << st->Q_exc ); - } - st->preemph_fac_float = (float) st->preemph_fac / MAX_16; - st->lp_gainc = (float) st->Mode2_lp_gainc / ONE_IN_Q16; - st->lp_gainp = (float) st->Mode2_lp_gainp / ONE_IN_Q29; - st->cummulative_damping_float = (float) st->cummulative_damping / MAX_16; - //st->old_enr_LP_float = (float) st->old_enr_LP / ONE_IN_Q3; - for ( int p = 0; p < st->L_frame / 2; p++ ) - { - st->hTcxDec->old_syn_Overl_float[p] = (float) st->hTcxDec->old_syn_Overl[p] * 2 * ( 1u << st->Q_syn ); - st->hTcxDec->syn_Overl_TDACFB_float[p] = (float)((float) st->hTcxDec->syn_Overl_TDACFB[p] * 2 * pow( 2, st->Q_syn )); - st->hTcxDec->syn_Overl_TDAC_float[p] = (float)((float) st->hTcxDec->syn_Overl_TDAC[p] * 2 * pow( 2, st->Q_syn )); - } - for ( int p = 0; p < 640; p++ ) - { - st->hHQ_core->old_outLB[p] = (float) st->hHQ_core->old_out_LB_fx[p] / ( 1u << st->Q_syn ); - } - - if ( !st->tcxonly ) - { - fixedToFloat_arr( st->p_bpf_noise_buf, st->p_bpf_noise_buf_float, 0, L_FRAME_16k ); - } - IF(st->hBPF && st->hBPF->pst_old_syn) fixedToFloat_arr( st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, 0, NBPSF_PIT_MAX ); - st->enr_old = (float)st->enr_old_fx; - //me2f_buf_16(st->old_lsp_q_cng, e_lsp, st->old_lsp_q_cng_float, 16); - - fixedToFloat_arr(st->hTcxDec->old_synth, st->hTcxDec->old_synth_float, st->Q_syn, 1280); - fixedToFloat_arr(st->hTcxDec->synth_history_fx, st->hTcxDec->synth_history, st->Q_syn, NS2SA( st->output_Fs, PH_ECU_MEM_NS )); - fixedToFloat_arr(st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synthFB, st->Q_syn, st->hTcxDec->old_synth_lenFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS )); - - for ( int p = 0; p < 960; p++ ) - { - st->hHQ_core->old_out[p] = (float) st->hHQ_core->old_out_fx[p] / ( 1u << st->Q_syn ); - } - - if ( st->hPlcInfo ) - { - //st->hPlcInfo->recovery_gain_float = fix16_to_float( st->hPlcInfo->recovery_gain, Q14 ); - //st->hPlcInfo->step_concealgain = fix16_to_float( st->hPlcInfo->step_concealgain_fx, Q15 ); - } - fixedToFloat_arrL( st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2 ); - IF(st->hTcxDec) st->hTcxDec->CngLevelBackgroundTrace_bfi = me2f_16(st->hTcxDec->conCngLevelBackgroundTrace, st->hTcxDec->conCngLevelBackgroundTrace_e); - //st->hTcxDec->CngLevelBackgroundTrace_bfi = fix16_to_float( st->hTcxDec->conCngLevelBackgroundTrace, 15 - st->hTcxDec->conCngLevelBackgroundTrace_e ); - st->hTcxDec->LastFrameLevel_bfi = me2f_16( st->hTcxDec->conLastFrameLevel, st->hTcxDec->conLastFrameLevel_e ); - for ( int p = 0; p < PLC_MIN_STAT_BUFF_SIZE; p++ ) - { - st->hTcxDec->NoiseLevelMemory_bfi[p] = me2f_16( st->hTcxDec->conNoiseLevelMemory[p], 0 ); - } - IF(st->hTonalMDCTConc && st->hTonalMDCTConc->lastPcmOut_float) fixedToFloat_arr(st->hTonalMDCTConc->lastPcmOut, st->hTonalMDCTConc->lastPcmOut_float, -2, st->hTonalMDCTConc->nSamples); - IF( bfi == 0 && !st->hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive ) fixedToFloat_arr(st->hTonalMDCTConc->secondLastPcmOut, st->hTonalMDCTConc->secondLastPcmOut_float, -2, st->hTonalMDCTConc->nSamples / 2); - } - FOR( i = 0; i < 2; i++ ) - { - FOR( j = 0; j < 2; j++ ) - { - free(x_fx_[i][j]); - } - } - -#else - ivas_mdct_core_reconstruct( hCPE, x, signal_outFB_tmp, fUseTns, 0 ); -#endif + ivas_mdct_core_reconstruct_fx( hCPE, x_fx, signal_outFB_tmp_fx, fUseTns, 0, Q11, 17 ); - mvr2r( signal_out_tmp[0], signal_out[0], L_FRAME48k ); - mvr2r( signal_out_tmp[1], signal_out[1], L_FRAME48k ); + mvl2l( signal_out_tmp_fx[0], signal_out_fx[0], L_FRAME48k ); + mvl2l( signal_out_tmp_fx[1], signal_out_fx[1], L_FRAME48k ); - mvr2r( signal_outFB_tmp[0], signal_outFB[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX ); - mvr2r( signal_outFB_tmp[1], signal_outFB[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX ); + mvs2s( signal_outFB_tmp_fx[0], signal_outFB_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX ); + mvs2s( signal_outFB_tmp_fx[1], signal_outFB_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX ); pop_wmops(); return; @@ -1509,13 +952,15 @@ static void apply_dmx_weights_fx( static void run_min_stats_fx( Decoder_State **sts, - float *x[CPE_CHANNELS][NB_DIV] /* i/o: MDCT Spectrum */ + Word32 *x[CPE_CHANNELS][NB_DIV], /* i/o: MDCT Spectrum */ + Word16 x_e[MAX_CICP_CHANNELS][NB_DIV] ) { int16_t ch, will_estimate_noise_on_channel[CPE_CHANNELS], save_VAD[CPE_CHANNELS]; - float power_spec[L_FRAME16k]; - float *spec_in; - + Word32 power_spec[L_FRAME16k]; + Word16 power_spec_16[L_FRAME16k], power_spec_e = 0; + Word32 *spec_in; + Word16 spec_e; /* Check if the minimum statistics would run on the respective channels. They are run on inactive TCX20 channels */ will_estimate_noise_on_channel[0] = sts[0]->core == TCX_20_CORE && !sts[0]->VAD; will_estimate_noise_on_channel[1] = sts[1]->core == TCX_20_CORE && !sts[1]->VAD; @@ -1528,195 +973,58 @@ static void run_min_stats_fx( for the two different channels. If they would only run on one of the channels, the VAD of the other one is patched so that the MS will still run. This other channel then uses the power spectrum of the other channel to run the MS. This is done to keep continuity and synchronicity between the two noise levels and silently assumes that the background noise is somehow diffuse and at leas partly shared between the channels */ - for ( ch = 0; ch < CPE_CHANNELS; ch++ ) + FOR ( ch = 0; ch < CPE_CHANNELS; ch++ ) { Decoder_State *st; st = sts[ch]; - if ( !sts[0]->bfi && ( will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] ) ) + IF ( !sts[0]->bfi && ( will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] ) ) { /* if noise estimation is expected to run on this channel, compute power spectrum from it, otherwise, use other channel's signal */ - if ( will_estimate_noise_on_channel[ch] ) + IF ( will_estimate_noise_on_channel[ch] ) { spec_in = &x[ch][0][0]; + spec_e = x_e[ch][0]; } - else + ELSE { spec_in = &x[( ch + 1 ) % 2][0][0]; + spec_e = x_e[(ch + 1) % 2][0]; /* patch VAD to zero so that estimation runs, will later be restored */ st->VAD = 0; } /* Compute power spectrum twice if estimation will run on both channels. If only on one channel, it is computed only once (for ch == 0) and not again in the second run sive the outcome will be the same anyway */ - if ( ( will_estimate_noise_on_channel[0] == will_estimate_noise_on_channel[1] ) || ch == 0 ) + IF ( ( EQ_16(will_estimate_noise_on_channel[0], will_estimate_noise_on_channel[1]) ) || EQ_16(ch, 0) ) { /* calculate power spectrum from MDCT coefficients and estimated MDST coeffs */ - power_spec[0] = spec_in[0] * spec_in[0]; - power_spec[L_FRAME16k - 1] = spec_in[L_FRAME16k - 1] * spec_in[L_FRAME16k - 1]; - for ( int16_t i = 1; i < L_FRAME16k - 1; i++ ) + power_spec[0] = Mpy_32_32(L_shr(spec_in[0], 2), L_shr(spec_in[0], 2)); + power_spec[L_FRAME16k - 1] = Mpy_32_32(L_shr(spec_in[L_FRAME16k - 1], 1), L_shr(spec_in[L_FRAME16k - 1], 1)); + FOR ( Word16 i = 1; i < L_FRAME16k - 1; i++ ) { - float mdst; - mdst = spec_in[i + 1] - spec_in[i - 1]; - power_spec[i] = spec_in[i] * spec_in[i] + mdst * mdst; + Word32 mdst; + mdst = L_sub(L_shr(spec_in[i + 1], 2), L_shr(spec_in[i - 1], 2)); + power_spec[i] = L_add(Mpy_32_32(L_shr(spec_in[i], 2), L_shr(spec_in[i], 2)), Mpy_32_32(L_shr(mdst, 0), L_shr(mdst, 0))); } } + power_spec_e = add(4, shl(spec_e, 1)); - noisy_speech_detection_flt( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, power_spec ); + Copy_Scale_sig32_16(power_spec, power_spec_16, L_FRAME16k, 0); + + noisy_speech_detection( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, power_spec_16, sub(15, power_spec_e)); - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt = 0.99f * st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt + 0.01f * (float) st->hFdCngDec->hFdCngCom->flag_noisy_speech; + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add(Mpy_32_32(Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx), Mpy_32_32(st->hFdCngDec->hFdCngCom->flag_noisy_speech, Q31_0_01)); - st->lp_noise_float = st->hFdCngDec->lp_noise_float; + st->lp_noise = st->hFdCngDec->lp_noise; } - if ( will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] || st->bfi ) + IF ( will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] || st->bfi ) { -#ifdef IVAS_FLOAT_FIXED - Word32 power_spec_fx[L_FRAME16k]; - - if ( !st->bfi ) - { - for ( int p = 0; p < L_FRAME16k; p++ ) - { - if ( power_spec[p] <= (float) MAX_32 ) - { - power_spec_fx[p] = (Word32) ( power_spec[p] /** ( 1u << 0 )*/ ); - } - else - { - power_spec_fx[p] = MAX_32; - } - } - } - - for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) - { - st->hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32) ( st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); - } - st->hFdCngDec->msNoiseEst_exp = 31 - Q4; - for ( int p = 0; p < NPART_SHAPING; p++ ) - { - st->hFdCngDec->msNoiseEst[p] = (Word32) ( st->hFdCngDec->msNoiseEst_float[p] * ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); - st->hFdCngDec->msPeriodog_ST_fx[p] = (Word32) ( st->hFdCngDec->msPeriodog_ST[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); - } - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q3; // Q3 - for ( int p = 0; p < FFTCLDFBLEN; p++ ) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32) ( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); - } - for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) - { - if ( ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << Q15 ) ) >= (float) MAX_32 ) - { - st->hFdCngDec->msMinBuf[p] = MAX_32; - } - else - { - st->hFdCngDec->msMinBuf[p] = (Word32) ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << ( 31 - 6 ) ) ); - } - } /*=================================================*/ - ApplyFdCng_fx( NULL, 0, st->bfi ? NULL : power_spec_fx, NULL, NULL, NULL, st, st->bfi, 0 ); + ApplyFdCng_fx( NULL, 0, st->bfi ? NULL : power_spec, sub(31, power_spec_e), NULL, NULL, NULL, st, st->bfi, 0 ); /*=================================================*/ - if ( !st->bfi ) - { - for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) - { - st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->fftBuffer[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); - } - for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) - { - st->hFdCngDec->msNoiseEst_float[p] = ( (float) st->hFdCngDec->msNoiseEst[p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); - } - - st->hTcxDec->CngLevelBackgroundTrace_bfi = (float) ( st->hTcxDec->CngLevelBackgroundTrace_bfi_fx / powf( 2.f, (Float32)( 31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp ) ) ); - st->cngTDLevel_float = fixedToFloat( st->cngTDLevel, ( 15 - st->cngTDLevel_e ) ); - - for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) - { - st->hFdCngDec->bandNoiseShape_float[p] = ( (float) st->hFdCngDec->bandNoiseShape[p] / ( 1u << ( 31 - st->hFdCngDec->bandNoiseShape_exp ) ) ); - } - for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) - { - if ( ( st->hFdCngDec->msMinBuf[p] == MAX_32 ) ) - { - st->hFdCngDec->msMinBuf_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msMinBuf_float[p] = (float) st->hFdCngDec->msMinBuf[p] / ( 1u << ( 31 - 6 ) ); // CNG_S = 6 - } - } - for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) - { - st->hFdCngDec->msPsd_float[p] = ( (float) st->hFdCngDec->msPsd[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msPeriodog_float[p] = ( (float) st->hFdCngDec->msPeriodog[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); - st->hFdCngDec->msPeriodogBuf_float[p] = ( (float) st->hFdCngDec->msPeriodogBuf[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msPeriodog_ST[p] = ( (float) st->hFdCngDec->msPeriodog_ST_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); - st->hFdCngDec->msPsdFirstMoment_float[p] = ( (float) st->hFdCngDec->msPsdFirstMoment[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msPsdSecondMoment_float[p] = ( (float) st->hFdCngDec->msPsdSecondMoment[p] / ( 1u << Q19 ) ); - st->hFdCngDec->msNoiseFloor_float[p] = ( (float) st->hFdCngDec->msNoiseFloor[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msAlpha_float[p] = ( (float) st->hFdCngDec->msAlpha[p] / ( 1u << Q31 ) ); - st->hFdCngDec->msBminWin_float[p] = ( (float) st->hFdCngDec->msBminWin[p] / ( 1u << Q27 ) ); - st->hFdCngDec->msBminSubWin_float[p] = ( (float) st->hFdCngDec->msBminSubWin[p] / ( 1u << Q27 ) ); - if ( st->hFdCngDec->msCurrentMin[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMin_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMin_float[p] = ( (float) st->hFdCngDec->msCurrentMin[p] / ( 1u << ( 31 - ( 6 + 1 + 4 ) ) ) ); // exp : CNG_S + 1 + 4 - } - if ( st->hFdCngDec->msCurrentMinOut[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinOut_float[p] = ( (float) st->hFdCngDec->msCurrentMinOut[p] / ( 1u << ( 31 - 6 ) ) ); - } - if ( st->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = ( (float) st->hFdCngDec->msCurrentMinSubWindow[p] / ( 1u << ( 31 - 6 ) ) ); - } - } - for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); - } - } - else if ( ( ( st->bfi == 1 ) && ( st->nbLostCmpt == 1 ) ) && ( sum_f( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt + st->hFdCngDec->hFdCngCom->startBand, st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ) > 0.01f ) ) - { - if ( st->element_mode == IVAS_CPE_MDCT && st->core != ACELP_CORE ) - { - for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); - } - for ( int p = 0; p < FDNS_NPTS; p++ ) - { - st->hTonalMDCTConc->scaleFactorsBackground_flt[p] = (float) st->hTonalMDCTConc->scaleFactorsBackground_fx[p] / ONE_IN_Q16; - } - } - if ( st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE ) - { - int A_cng_q = 15 - norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ); - for ( int p = 0; p < M; p++ ) - { - st->hFdCngDec->hFdCngCom->A_cng_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->A_cng[p] / ( 1u << A_cng_q ) ); - //st->lspold_cng_float[p] = ( (float) st->lspold_cng[p] / ( 1u << Q15 ) ); - //st->lsf_cng_float[p] = ( (float) st->lsf_cng[p] / 2.56f ); // Q2.56 - } - } - } -#else - ApplyFdCng_flt( NULL, st->bfi ? NULL : power_spec, NULL, NULL, st, st->bfi, 0 ); -#endif // IVAS_FLOAT_FIXED } /* restore VAD (see above) */ @@ -1725,4 +1033,4 @@ static void run_min_stats_fx( return; } -#endif // IVAS_FLOAT_FIXED +#endif diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec.c b/lib_dec/ivas_stereo_mdct_stereo_dec.c index b9bf4a9fe39feae1b2d8c0633db6a7b94559909d..dc352d85892d33fc69e555bd175d269d093036f9 100644 --- a/lib_dec/ivas_stereo_mdct_stereo_dec.c +++ b/lib_dec/ivas_stereo_mdct_stereo_dec.c @@ -49,7 +49,11 @@ * Local function prototypes *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void inverseBwMS( const int16_t startLine, const int16_t stopLine, float x0[], float x1[], const float norm_fac ); +#else +static void inverseBwMS_fx( const Word16 startLine, const Word16 stopLine, Word32 x0[], Word32 x1[], const Word32 norm_fac ); +#endif #ifndef IVAS_FLOAT_FIXED @@ -191,7 +195,6 @@ void parse_stereo_from_bitstream( return; } -#endif /*-------------------------------------------------------------------* @@ -327,6 +330,7 @@ void stereo_decoder_tcx( return; } +#endif #ifdef IVAS_FLOAT_FIXED #define NF_RED_FAC_FIXED 1610612736 // Q31 @@ -368,27 +372,24 @@ void parse_stereo_from_bitstream( { Word16 I; - hStereoMdct->itd_mode = (Word16) get_next_indice_fx( st0, STEREO_DFT_ITD_MODE_NBITS ); + hStereoMdct->itd_mode = extract_l( get_next_indice_fx( st0, STEREO_DFT_ITD_MODE_NBITS ) ); /*(*nb_bits) += STEREO_DFT_ITD_MODE_NBITS;*/ /*ITD mode flag: 1bit*/ - hStereoMdct->itd = 0.f; -#ifdef IVAS_FLOAT_FIXED hStereoMdct->itd_fx = 0; move32(); -#endif IF( hStereoMdct->itd_mode ) { /*(*nb_bits) += */ read_itd( st0, &I ); - stereo_dft_dequantize_itd( &I, &hStereoMdct->itd, st0->output_Fs ); + stereo_dft_dequantize_itd_fx( &I, &hStereoMdct->itd_fx, st0->output_Fs ); } } FOR( k = 0; k < nSubframes; k++ ) { - mdct_stereo_mode = (Word16) get_next_indice_fx( st0, 1 ); + mdct_stereo_mode = extract_l( get_next_indice_fx( st0, 1 ) ); IF( mdct_stereo_mode ) { - mdct_stereo_mode = add( 1, (Word16) get_next_indice_fx( st0, 1 ) ); + mdct_stereo_mode = add( 1, extract_l( get_next_indice_fx( st0, 1 ) ) ); } SWITCH( mdct_stereo_mode ) { @@ -413,7 +414,7 @@ void parse_stereo_from_bitstream( test(); IF( EQ_16( sts[0]->core, sts[1]->core ) || EQ_16( k, 0 ) ) { - hStereoMdct->global_ild[k] = (Word16) get_next_indice_fx( st0, SMDCT_GLOBAL_ILD_BITS ); + hStereoMdct->global_ild[k] = extract_l( get_next_indice_fx( st0, SMDCT_GLOBAL_ILD_BITS ) ); move16(); assert( ( GT_16( hStereoMdct->global_ild[k], 0 ) ) && ( LT_16( hStereoMdct->global_ild[k], SMDCT_ILD_RANGE ) ) ); } @@ -430,17 +431,17 @@ void parse_stereo_from_bitstream( { FOR( i = 0; i < sfbConf->nBandsStereoCore; i++ ) { - ms_mask[k][i] = (Word16) get_next_indice_fx( st0, 1 ); + ms_mask[k][i] = extract_l( get_next_indice_fx( st0, 1 ) ); move16(); } } IF( st0->igf ) { - mdct_stereo_mode = (Word16) get_next_indice_fx( st0, 1 ); + mdct_stereo_mode = extract_l( get_next_indice_fx( st0, 1 ) ); IF( mdct_stereo_mode ) { - mdct_stereo_mode = add( 1, (Word16) get_next_indice_fx( st0, 1 ) ); + mdct_stereo_mode = add( 1, extract_l( get_next_indice_fx( st0, 1 ) ) ); } SWITCH( mdct_stereo_mode ) @@ -467,7 +468,7 @@ void parse_stereo_from_bitstream( { FOR( i = sfbConf->nBandsStereoCore; i < sfbConf->sfbCnt; i++ ) { - ms_mask[k][i] = (Word16) get_next_indice_fx( st0, 1 ); + ms_mask[k][i] = extract_l( get_next_indice_fx( st0, 1 ) ); move16(); } } @@ -484,7 +485,7 @@ void parse_stereo_from_bitstream( { hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE; /* Equal bits to both channels */ move16(); - hStereoMdct->split_ratio = (Word16) get_next_indice_fx( st0, SMDCT_NBBITS_SPLIT_RATIO ); + hStereoMdct->split_ratio = extract_l( get_next_indice_fx( st0, SMDCT_NBBITS_SPLIT_RATIO ) ); assert( GT_16( hStereoMdct->split_ratio, 0 ) ); } @@ -494,6 +495,11 @@ void parse_stereo_from_bitstream( } +/*-------------------------------------------------------------------* + * inverseBwMS() + * + * Band-wise M/S stereo processing + *-------------------------------------------------------------------*/ static void inverseBwMS_fx( const Word16 startLine, /* i : start line of sfb */ const Word16 stopLine, /* i : stop line of sfb */ @@ -519,6 +525,11 @@ static void inverseBwMS_fx( } +/*-------------------------------------------------------------------* + * inverseMS() + * + * M/S stereo processing + *-------------------------------------------------------------------*/ void inverseMS_fx( const Word16 L_frame, /* i : frame length */ Word32 x0[], /* i/o: mid/left channel coefficients */ @@ -532,6 +543,11 @@ void inverseMS_fx( } +/*-------------------------------------------------------------------* + * stereo_decoder_tcx() + * + * apply stereo processing (inverse MS and global ILD) + *-------------------------------------------------------------------*/ void stereo_decoder_tcx_fx( STEREO_MDCT_DEC_DATA *hStereoMdct, /* i/o: MDCT stereo decoder structure */ Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ @@ -702,10 +718,10 @@ void stereo_decoder_tcx_fx( return; } - #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * inverseBwMS() * @@ -751,6 +767,7 @@ void inverseMS( return; } +#endif /*-------------------------------------------------------------------* @@ -791,17 +808,22 @@ void initMdctStereoDecData_fx( ELSE { hStereoMdct->stbParamsTCX20.sfbIgfStart = -1; + move16(); hStereoMdct->stbParamsTCX10.sfbIgfStart = -1; + move16(); hStereoMdct->stbParamsTCX20afterACELP.sfbIgfStart = -1; + move16(); hStereoMdct->stbParamsTCX10.nBandsStereoCore = hStereoMdct->stbParamsTCX10.sfbCnt; + move16(); hStereoMdct->stbParamsTCX20.nBandsStereoCore = hStereoMdct->stbParamsTCX20.sfbCnt; + move16(); hStereoMdct->stbParamsTCX20afterACELP.nBandsStereoCore = hStereoMdct->stbParamsTCX20afterACELP.sfbCnt; + move16(); } return; } -#endif - +#else void initMdctStereoDecData( STEREO_MDCT_DEC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ const int16_t igf, /* i : flag indicating IGF activity */ @@ -842,6 +864,7 @@ void initMdctStereoDecData( return; } +#endif /*-------------------------------------------------------------------* @@ -850,6 +873,66 @@ void initMdctStereoDecData( * Allocate and initialize structures for MDCT-Stereo DTX operation *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error initMdctStereoDtxData_fx( + CPE_DEC_HANDLE hCPE /* i/o: CPE handle */ +) +{ + Word16 ch; + ivas_error error; + + error = IVAS_ERR_OK; + move16(); + + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + DEC_CORE_HANDLE st = hCPE->hCoreCoder[ch]; + + IF( st->hFdCngDec == NULL ) + { + /* Create FD_CNG instance */ + IF( ( error = createFdCngDec( &st->hFdCngDec ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Init FD-CNG */ +#if 1/*TODO: To be removed later*/ + initFdCngDec_flt( st ); +#endif + ivas_initFdCngDec_fx( st, st->cldfbSyn->scale ); + } + + IF( EQ_16( st->first_CNG, 0 ) ) + { + IF( EQ_16( ch, 1 ) && st->cng_sba_flag ) + { + st->hFdCngDec->hFdCngCom->seed = add( st->hFdCngDec->hFdCngCom->seed, 3 ); + } + } + + IF( st->cldfbAna == NULL ) + { + /* open analysis for max. sampling rate 48kHz */ + IF( ( error = openCldfb_ivas_fx( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + IF( st->cldfbBPF == NULL ) + { + /* open analysis BPF for max. internal sampling rate 16kHz */ + IF( ( error = openCldfb_ivas_fx( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + return error; +} +#else ivas_error initMdctStereoDtxData( CPE_DEC_HANDLE hCPE /* i/o: CPE handle */ ) @@ -876,7 +959,7 @@ ivas_error initMdctStereoDtxData( initFdCngDec_flt( st ); #ifdef IVAS_FLOAT_FIXED st->cldfbSyn->scale = (Word16) ( st->cldfbSyn->scale_flt * ( 1u << norm_s( (Word16) st->cldfbSyn->scale_flt ) ) ); - initFdCngDec( st, st->cldfbSyn->scale ); + ivas_initFdCngDec_fx( st, st->cldfbSyn->scale ); #endif IVAS_FLOAT_FIXED } @@ -909,6 +992,8 @@ ivas_error initMdctStereoDtxData( return error; } +#endif + /*-------------------------------------------------------------------* * synchonize_channels_mdct_sid() @@ -919,16 +1004,17 @@ ivas_error initMdctStereoDtxData( #ifdef IVAS_FLOAT_FIXED void synchonize_channels_mdct_sid_fx( Decoder_State *sts[CPE_CHANNELS], /* i/o: decoder state structure */ - const Word16 n /* i : channel number */ + const Word16 n /* i : channel number */ ) { Decoder_State *st; st = sts[n]; - IF ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_32( st->total_brate, SID_2k40 ) ) + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_32( st->total_brate, SID_2k40 ) ) { - IF ( EQ_16( n, 1 ) ) + IF( EQ_16( n, 1 ) ) { /* synchronize channels */ sts[1]->L_frame = sts[0]->L_frame; @@ -937,21 +1023,20 @@ void synchonize_channels_mdct_sid_fx( move16(); sts[1]->bwidth = sts[0]->bwidth; move16(); - /* TODO remove floating point dependency */ - sts[0]->hFdCngDec->hFdCngCom->coherence_flt = sts[1]->hFdCngDec->hFdCngCom->coherence_flt; /* coherence is stored in sts[1] - see ivas_decision_matrix_dec() */ - sts[0]->hFdCngDec->hFdCngCom->coherence_fx = sts[1]->hFdCngDec->hFdCngCom->coherence_fx; + sts[0]->hFdCngDec->hFdCngCom->coherence_fx = sts[1]->hFdCngDec->hFdCngCom->coherence_fx; /* coherence is stored in sts[1] - see ivas_decision_matrix_dec() */ move16(); sts[0]->hFdCngDec->hFdCngCom->no_side_flag = sts[1]->hFdCngDec->hFdCngCom->no_side_flag; move16(); /* configure when there is a switching from DFT CNG to MDCT CNG */ - IF ( EQ_16( sts[0]->first_CNG, 1 ) && EQ_16( sts[1]->first_CNG, 0 ) ) + test(); + IF( EQ_16( sts[0]->first_CNG, 1 ) && EQ_16( sts[1]->first_CNG, 0 ) ) { configureFdCngDec_fx( st->hFdCngDec, st->bwidth, st->element_brate, st->L_frame, st->last_L_frame, st->element_mode ); } } - IF ( EQ_16( sts[0]->first_CNG, 0 ) ) + IF( EQ_16( sts[0]->first_CNG, 0 ) ) { /* configure CNG after reading first side info from SID to get correct values for L_frame and bwidth if first SID is also first valid frame */ configureFdCngDec_fx( st->hFdCngDec, st->bwidth, st->element_brate, st->L_frame, st->last_L_frame, st->element_mode ); @@ -960,9 +1045,7 @@ void synchonize_channels_mdct_sid_fx( return; } -#endif - - +#else void synchonize_channels_mdct_sid( Decoder_State *sts[CPE_CHANNELS], /* i/o: decoder state structure */ const int16_t n /* i : channel number */ @@ -999,6 +1082,7 @@ void synchonize_channels_mdct_sid( return; } +#endif /*-------------------------------------------------------------------* @@ -1040,7 +1124,7 @@ static void update_exp( Word16 *a_exp, Word16 *b_exp, Word16 *buff_a, Word16 *bu void updateBuffersForDmxMdctStereo_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ - const int16_t output_frame, /* i : output frame length */ + const Word16 output_frame, /* i : output frame length */ Word32 output0_fx[], Word32 output1_fx[], Word16 synth_fx[CPE_CHANNELS][L_FRAME48k] /* i/o: decoder synthesis */ @@ -1172,8 +1256,7 @@ void updateBuffersForDmxMdctStereo_fx( return; } -#endif - +#else void updateBuffersForDmxMdctStereo( CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ const int16_t output_frame, /* i : output frame length */ @@ -1247,6 +1330,8 @@ void updateBuffersForDmxMdctStereo( return; } +#endif + /*-------------------------------------------------------------------* * applyDmxMdctStereo() @@ -1255,6 +1340,7 @@ void updateBuffersForDmxMdctStereo( * between active/inactive coding in MDCT-Stereo DTX *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void applyDmxMdctStereo( const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ float *output[CPE_CHANNELS], /* i/o: core decoder output */ @@ -1307,8 +1393,7 @@ void applyDmxMdctStereo( return; } - - +#else void applyDmxMdctStereo_fx( const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ Word32 *output_fx[CPE_CHANNELS], /* i/o: core decoder output */ @@ -1320,69 +1405,86 @@ void applyDmxMdctStereo_fx( Word32 fade_fx, step_fx; step_fx = ONE_IN_Q31; + move32(); fade_fx = ONE_IN_Q31; + move32(); dmx_len = output_frame; + move16(); - IF( hCPE->last_element_brate <= IVAS_SID_5k2 ) + test(); + test(); + IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) { crossfade_len = NS2SA( hCPE->hCoreCoder[0]->output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); SWITCH( hCPE->hCoreCoder[0]->output_Fs ) { case 48000: step_fx = 22369622; - break; + move32(); + BREAK; case 32000: step_fx = 33554432; - break; + move32(); + BREAK; case 16000: step_fx = 67108864; - break; + move32(); + BREAK; default: assert( 0 ); - break; + BREAK; } } /* for first inactive CNG frame after active decoding we have to do a fade-OUT FROM the passive DMX */ - ELSE IF( hCPE->element_brate <= IVAS_SID_5k2 && hCPE->last_element_brate > IVAS_SID_5k2 ) + ELSE IF( LE_32( hCPE->element_brate, IVAS_SID_5k2 ) && GT_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) { - crossfade_len = output_frame / 4; + crossfade_len = shr( output_frame, 2 ); SWITCH( output_frame ) { case 960: step_fx = -8947849; - break; + move32(); + BREAK; case 640: step_fx = -13421773; - break; + move32(); + BREAK; case 320: step_fx = -26843546; - break; + move32(); + BREAK; } fade_fx = 0; + move32(); dmx_len = crossfade_len; + move16(); } - ELSE IF( hCPE->last_element_mode == IVAS_CPE_DFT && hCPE->last_element_brate <= IVAS_32k ) + ELSE IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && LE_32( hCPE->last_element_brate, IVAS_32k ) ) { crossfade_len = NS2SA( hCPE->hCoreCoder[0]->output_Fs, DELAY_CLDFB_NS ); SWITCH( hCPE->hCoreCoder[0]->output_Fs ) { case 48000: step_fx = 35791396; - break; + move32(); + BREAK; case 32000: step_fx = 53687092; - break; + move32(); + BREAK; case 16000: step_fx = 107374184; - break; + move32(); + BREAK; default: assert( 0 ); - break; + BREAK; } } ELSE { crossfade_len = 0; + move16(); } /* apply crossfade */ @@ -1390,7 +1492,8 @@ void applyDmxMdctStereo_fx( { Word32 temp_1 = Mpy_32_32( output_fx[0][i], fade_fx ); Word32 temp_2 = Mpy_32_32( L_add_sat( output_fx[0][i], output_fx[1][i] ), Mpy_32_32( INV_SQRT2_FX, L_sub_sat( ONE_IN_Q31, fade_fx ) ) ); - output_fx[0][i] = temp_1 + temp_2; + output_fx[0][i] = L_add( temp_1, temp_2 ); + move32(); fade_fx = L_sub_sat( fade_fx, step_fx ); } @@ -1398,7 +1501,9 @@ void applyDmxMdctStereo_fx( FOR( ; i < dmx_len; i++ ) { output_fx[0][i] = Mpy_32_32( L_add_sat( output_fx[0][i], output_fx[1][i] ), INV_SQRT2_FX ); + move32(); } return; } +#endif diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index f588aa1c02b5b3c515bae1ed3505daf8065c3711..0178161545b0245cb1ae8a200ff7e8cbad3555fc 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -227,6 +227,7 @@ static ivas_error allocate_CoreCoder_TCX_fx( } #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Function allocate_CoreCoder() * @@ -249,10 +250,6 @@ static ivas_error allocate_CoreCoder( } GSC_dec_init_ivas( st->hGSCDec ); -#ifdef IVAS_FLOAT_FIXED - GSC_dec_init_ivas( st->hGSCDec ); -#endif // IVAS_FLOAT_FIXED - } if ( st->hPFstat == NULL ) @@ -319,6 +316,7 @@ static ivas_error allocate_CoreCoder( return error; } +#endif #ifdef IVAS_FLOAT_FIXED static ivas_error allocate_CoreCoder_fx( @@ -336,11 +334,7 @@ static ivas_error allocate_CoreCoder_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); } - GSC_dec_init( st->hGSCDec ); - -#if 1 // TODO: To be removed later - GSC_dec_init_ivas( st->hGSCDec ); -#endif + GSC_dec_init_ivas_fx( st->hGSCDec ); } IF ( st->hPFstat == NULL ) @@ -354,7 +348,7 @@ static ivas_error allocate_CoreCoder_fx( st->psf_lp_noise_fx = 0; move16(); -#if 1 // TODO: To be removed later +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) Init_post_filter_ivas( st->hPFstat ); st->psf_lp_noise = 0.0f; #endif @@ -382,10 +376,6 @@ static ivas_error allocate_CoreCoder_fx( } bass_psfilter_init_fx( st->hBPF ); - -#if 1 // TODO: To be removed later - bass_psfilter_init( st->hBPF ); -#endif } IF ( st->hBWE_zero == NULL ) @@ -396,10 +386,6 @@ static ivas_error allocate_CoreCoder_fx( } hf_synth_init_fx( st->hBWE_zero ); - -#if 1 // TODO: To be removed later - hf_synth_init( st->hBWE_zero ); -#endif } IF ( st->cldfbAna == NULL ) @@ -575,6 +561,7 @@ static void deallocate_CoreCoder_fx( * channel to the correct structure in the new mode *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void cpy_tcx_ltp_data( TCX_LTP_DEC_HANDLE hTcxLtpDecOld, /* i : TCX-LTP structure to copy from */ TCX_LTP_DEC_HANDLE hTcxLtpDecNew, /* o : TCX-LTP structure to copy to */ @@ -591,7 +578,7 @@ static void cpy_tcx_ltp_data( return; } -#ifdef IVAS_FLOAT_FIXED +#else static void cpy_tcx_ltp_data_fx( TCX_LTP_DEC_HANDLE hTcxLtpDecOld, /* i : TCX-LTP structure to copy from */ TCX_LTP_DEC_HANDLE hTcxLtpDecNew, /* o : TCX-LTP structure to copy to */ @@ -626,7 +613,7 @@ static void cpy_tcx_ltp_data_fx( * * Dynamically allocate/deallocate data structures depending on the actual CPE mode *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED ivas_error stereo_memory_dec( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ CPE_DEC_HANDLE hCPE, /* i : CPE decoder structure */ @@ -733,11 +720,7 @@ ivas_error stereo_memory_dec( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE \n" ) ); } -#ifdef IVAS_FLOAT_FIXED - stereo_icBWE_init_dec_fx(hCPE->hStereoICBWE); -#else stereo_icBWE_init_dec(hCPE->hStereoICBWE); -#endif } /* allocate HQ core */ @@ -801,11 +784,7 @@ ivas_error stereo_memory_dec( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD Stereo\n" ) ); } -#ifndef IVAS_FLOAT_FIXED stereo_td_init_dec( hCPE->hStereoTD, hCPE->last_element_mode ); -#else - stereo_td_init_dec_fx( hCPE->hStereoTD, hCPE->last_element_mode ); -#endif /* allocate CoreCoder secondary channel */ if ( ( error = allocate_CoreCoder( hCPE->hCoreCoder[1] ) ) != IVAS_ERR_OK ) { @@ -850,11 +829,7 @@ ivas_error stereo_memory_dec( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo DFT mono output\n" ) ); } -#ifdef IVAS_FLOAT_FIXED - stereo_dft_dmx_out_reset_fx(hCPE->hStereoDftDmx); -#else stereo_dft_dmx_out_reset(hCPE->hStereoDftDmx); -#endif } /* allocate TCA data structure */ @@ -864,11 +839,7 @@ ivas_error stereo_memory_dec( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); } -#ifdef IVAS_FLOAT_FIXED - stereo_tca_init_dec_fx( hCPE->hStereoTCA ); -#else stereo_tca_init_dec( hCPE->hStereoTCA ); -#endif } st = hCPE->hCoreCoder[0]; @@ -888,22 +859,13 @@ ivas_error stereo_memory_dec( } td_bwe_dec_init( st->hBWE_TD, -1, st->output_Fs ); -#ifdef IVAS_FLOAT_FIXED - td_bwe_dec_init_fx(st, st->hBWE_TD, -#ifdef ADD_IVAS_BWE - st->extl,//not needed -#endif - st->output_Fs); -#endif + if ( ( st->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); } fd_bwe_dec_init_flt( st->hBWE_FD ); -#ifdef IVAS_FLOAT_FIXED - fd_bwe_dec_init(st, st->hBWE_FD); -#endif } /* Allocated FD_CNG instance for primary channel*/ @@ -915,10 +877,6 @@ ivas_error stereo_memory_dec( return error; } initFdCngDec_flt( st ); -#ifdef IVAS_FLOAT_FIXED - st->cldfbSyn->scale = (Word16) ( st->cldfbSyn->scale_flt * ( 1u << norm_s( (Word16) st->cldfbSyn->scale_flt ) ) ); - initFdCngDec( st, st->cldfbSyn->scale ); -#endif // IVAS_FLOAT_FIXED configureFdCngDec_flt( st->hFdCngDec, st->bwidth, st->total_brate, st->L_frame, st->last_L_frame, st->element_mode ); } @@ -1023,10 +981,6 @@ ivas_error stereo_memory_dec( /* Init FD-CNG */ initFdCngDec_flt( st ); -#ifdef IVAS_FLOAT_FIXED - st->cldfbSyn->scale = (Word16)(st->cldfbSyn->scale_flt * (1u << norm_s((Word16)st->cldfbSyn->scale_flt))); - initFdCngDec( st, st->cldfbSyn->scale); -#endif // IVAS_FLOAT_FIXED if ( hCPE->last_element_mode == IVAS_CPE_DFT ) { @@ -1059,11 +1013,7 @@ ivas_error stereo_memory_dec( set_f( st->hTcxDec->FBTCXdelayBuf_float, 0.0f, 111 ); st->hTcxDec->old_synthFB = st->hTcxDec->synth_history + NS2SA( st->output_Fs, PH_ECU_MEM_NS ); st->hTcxDec->prev_good_synth = st->hTcxDec->old_synthFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ); -#ifdef IVAS_FLOAT_FIXED - set16_fx(st->hTcxDec->FBTCXdelayBuf, 0, 111); - st->hTcxDec->old_synthFB_fx = st->hTcxDec->synth_history_fx + NS2SA(st->output_Fs, PH_ECU_MEM_NS); - st->hTcxDec->prev_good_synth_fx = st->hTcxDec->old_synthFB_fx + NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS); -#endif + /* allocate and initialize MDCT stereo structure */ if ( ( hCPE->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) { @@ -1079,10 +1029,6 @@ ivas_error stereo_memory_dec( } hCPE->hStereoMdct->reverse_dmx = 0; hCPE->hStereoMdct->smooth_ratio = 1.f; -#ifdef IVAS_FLOAT_FIXED - hCPE->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; -#endif - } } @@ -1115,22 +1061,13 @@ ivas_error stereo_memory_dec( } td_bwe_dec_init( st->hBWE_TD, -1, st->output_Fs ); -#ifdef IVAS_FLOAT_FIXED - td_bwe_dec_init_fx(st, st->hBWE_TD, -#ifdef ADD_IVAS_BWE - -1, -#endif - st->output_Fs); -#endif + if ( ( st->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); } fd_bwe_dec_init_flt( st->hBWE_FD ); -#ifdef IVAS_FLOAT_FIXED - fd_bwe_dec_init(st, st->hBWE_FD); -#endif } } else /* tdm_LRTD_flag == 0 */ @@ -1159,11 +1096,7 @@ ivas_error stereo_memory_dec( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE \n" ) ); } -#ifdef IVAS_FLOAT_FIXED - stereo_icBWE_init_dec_fx(hCPE->hStereoICBWE); -#else stereo_icBWE_init_dec(hCPE->hStereoICBWE); -#endif } } } @@ -1187,11 +1120,7 @@ ivas_error stereo_memory_dec( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); } } -#ifdef IVAS_FLOAT_FIXED - stereo_tca_init_dec_fx( hCPE->hStereoTCA ); -#else stereo_tca_init_dec( hCPE->hStereoTCA ); -#endif } hCPE->hStereoMdct->use_itd = 1; @@ -1230,11 +1159,7 @@ ivas_error stereo_memory_dec( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo DFT mono output\n" ) ); } -#ifdef IVAS_FLOAT_FIXED - stereo_dft_dmx_out_reset_fx(hCPE->hStereoDftDmx); -#else stereo_dft_dmx_out_reset(hCPE->hStereoDftDmx); -#endif } if ( hCPE->prev_synth_chs[1] != NULL ) @@ -1243,13 +1168,6 @@ ivas_error stereo_memory_dec( hCPE->prev_synth_chs[1] = NULL; } -#ifdef IVAS_FLOAT_FIXED - if (hCPE->prev_synth_chs_fx[1] != NULL) - { - free(hCPE->prev_synth_chs_fx[1]); - hCPE->prev_synth_chs_fx[1] = NULL; - } -#endif if ( hCPE->hStereoTCA != NULL ) { free( hCPE->hStereoTCA ); @@ -1274,17 +1192,6 @@ ivas_error stereo_memory_dec( set_zero( hCPE->prev_synth_chs[1], NS2SA( st->output_Fs, FRAME_SIZE_NS ) ); } -#ifdef IVAS_FLOAT_FIXED - if (hCPE->prev_synth_chs_fx[1] == NULL) - { - st = hCPE->hCoreCoder[1]; - if ((hCPE->prev_synth_chs_fx[1] = (Word32 *)malloc(sizeof(Word32) * NS2SA(st->output_Fs, FRAME_SIZE_NS))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n")); - } - set32_fx(hCPE->prev_synth_chs_fx[1],0, NS2SA(st->output_Fs, FRAME_SIZE_NS)); - } -#endif if ( hCPE->hStereoICBWE == NULL && hCPE->element_mode == IVAS_CPE_DFT ) { if ( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL ) @@ -1292,11 +1199,7 @@ ivas_error stereo_memory_dec( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE \n" ) ); } -#ifdef IVAS_FLOAT_FIXED - stereo_icBWE_init_dec_fx(hCPE->hStereoICBWE); -#else stereo_icBWE_init_dec(hCPE->hStereoICBWE); -#endif } if ( hCPE->hStereoTCA == NULL && ( hCPE->element_mode == IVAS_CPE_DFT || hCPE->element_mode == IVAS_CPE_TD ) ) @@ -1306,11 +1209,7 @@ ivas_error stereo_memory_dec( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); } -#ifdef IVAS_FLOAT_FIXED - stereo_tca_init_dec_fx( hCPE->hStereoTCA ); -#else stereo_tca_init_dec( hCPE->hStereoTCA ); -#endif } if ( hCPE->element_mode == IVAS_CPE_MDCT ) @@ -1365,10 +1264,6 @@ ivas_error stereo_memory_dec( return error; } initFdCngDec_flt( hCPE->hCoreCoder[i] ); -#ifdef IVAS_FLOAT_FIXED - hCPE->hCoreCoder[i]->cldfbSyn->scale = (Word16) ( hCPE->hCoreCoder[i]->cldfbSyn->scale_flt * ( 1u << norm_s( (Word16) hCPE->hCoreCoder[i]->cldfbSyn->scale_flt ) ) ); - initFdCngDec( hCPE->hCoreCoder[i], hCPE->hCoreCoder[i]->cldfbSyn->scale ); -#endif // IVAS_FLOAT_FIXED } } } @@ -1376,8 +1271,7 @@ ivas_error stereo_memory_dec( return error; } - -#ifdef IVAS_FLOAT_FIXED +#else ivas_error stereo_memory_dec_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ CPE_DEC_HANDLE hCPE, /* i : CPE decoder structure */ @@ -1519,7 +1413,7 @@ ivas_error stereo_memory_dec_fx( td_cng_dec_init( st ); #if 1 // TODO: To be removed later - td_cng_dec_init_flt( st ); + //td_cng_dec_init_flt( st ); #endif } } @@ -1565,7 +1459,7 @@ ivas_error stereo_memory_dec_fx( stereo_td_init_dec_fx( hCPE->hStereoTD, hCPE->last_element_mode ); /* allocate CoreCoder secondary channel */ - IF ( NE_16(( error = allocate_CoreCoder( hCPE->hCoreCoder[1] ) ), IVAS_ERR_OK) ) + IF ( NE_16(( error = allocate_CoreCoder_fx( hCPE->hCoreCoder[1] ) ), IVAS_ERR_OK) ) { return error; } @@ -1643,7 +1537,7 @@ ivas_error stereo_memory_dec_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - td_bwe_dec_init_fx( st, st->hBWE_TD, st->output_Fs ); + td_bwe_dec_init_ivas_fx( st, st->hBWE_TD, st->output_Fs ); #if 1 // TODO: To be removed later td_bwe_dec_init( st->hBWE_TD, -1, st->output_Fs ); @@ -1667,9 +1561,9 @@ ivas_error stereo_memory_dec_fx( move16(); #if 1 // TODO: To be removed later - fd_bwe_dec_init_flt( st->hBWE_FD ); + //fd_bwe_dec_init_flt( st->hBWE_FD ); #endif - + fd_bwe_dec_init(st, st->hBWE_FD); st->hBWE_FD->old_wtda_swb_fx_exp = 0; st->hBWE_FD->mem_imdct_exp_fx = 0; st->prev_Q_synth = 0; @@ -1684,7 +1578,7 @@ ivas_error stereo_memory_dec_fx( return error; } - initFdCngDec( st, st->cldfbSyn->scale ); + ivas_initFdCngDec_fx( st, st->cldfbSyn->scale ); configureFdCngDec_fx( st->hFdCngDec, st->bwidth, st->total_brate, st->L_frame, st->last_L_frame, st->element_mode ); } @@ -1716,7 +1610,7 @@ ivas_error stereo_memory_dec_fx( IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_DFT) ) { - cpy_tcx_ltp_data( hCPE->hStereoDft->hTcxLtpDec, &tcxLtpTmp, output_Fs ); + cpy_tcx_ltp_data_fx( hCPE->hStereoDft->hTcxLtpDec, &tcxLtpTmp, output_Fs ); } /* deallocate data structure of the previous CPE mode */ @@ -1791,7 +1685,7 @@ ivas_error stereo_memory_dec_fx( } /* Init FD-CNG */ - initFdCngDec( st, st->cldfbSyn->scale); + ivas_initFdCngDec_fx( st, st->cldfbSyn->scale); #if 1 // TODO: To be removed later initFdCngDec_flt( st ); #endif @@ -1811,11 +1705,11 @@ ivas_error stereo_memory_dec_fx( { IF ( EQ_16(hCPE->nchan_out, 1) ) { - cpy_tcx_ltp_data( hCPE->hCoreCoder[0]->hTcxLtpDec, hCPE->hCoreCoder[1]->hTcxLtpDec, output_Fs ); + cpy_tcx_ltp_data_fx( hCPE->hCoreCoder[0]->hTcxLtpDec, hCPE->hCoreCoder[1]->hTcxLtpDec, output_Fs ); } ELSE { - cpy_tcx_ltp_data( &tcxLtpTmp, hCPE->hCoreCoder[1]->hTcxLtpDec, output_Fs ); + cpy_tcx_ltp_data_fx( &tcxLtpTmp, hCPE->hCoreCoder[1]->hTcxLtpDec, output_Fs ); } } @@ -1885,7 +1779,7 @@ ivas_error stereo_memory_dec_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - td_bwe_dec_init_fx( st, st->hBWE_TD, st->output_Fs ); + td_bwe_dec_init_ivas_fx( st, st->hBWE_TD, st->output_Fs ); #if 1 // TODO: To be removed later td_bwe_dec_init( st->hBWE_TD, -1, st->output_Fs ); #endif @@ -1907,9 +1801,9 @@ ivas_error stereo_memory_dec_fx( move16(); #if 1 // TODO: To be removed later - fd_bwe_dec_init_flt( st->hBWE_FD ); + //fd_bwe_dec_init_flt( st->hBWE_FD ); #endif - + fd_bwe_dec_init(st, st->hBWE_FD); st->hBWE_FD->old_wtda_swb_fx_exp = 0; st->hBWE_FD->mem_imdct_exp_fx = 0; st->prev_Q_synth = 0; @@ -2013,13 +1907,6 @@ ivas_error stereo_memory_dec_fx( stereo_dft_dmx_out_reset_fx(hCPE->hStereoDftDmx); } -#if 1 // TODO: To be removed later - IF ( hCPE->prev_synth_chs[1] != NULL ) - { - free( hCPE->prev_synth_chs[1] ); - hCPE->prev_synth_chs[1] = NULL; - } -#endif IF (hCPE->prev_synth_chs_fx[1] != NULL) { free(hCPE->prev_synth_chs_fx[1]); @@ -2040,18 +1927,6 @@ ivas_error stereo_memory_dec_fx( hCPE->hStereoDftDmx = NULL; } -#if 1 // TODO : To be removed later - IF ( hCPE->prev_synth_chs[1] == NULL ) - { - st = hCPE->hCoreCoder[1]; - IF ( ( hCPE->prev_synth_chs[1] = (float *) malloc( sizeof( float ) * NS2SA( st->output_Fs, FRAME_SIZE_NS ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) ); - } - set_zero( hCPE->prev_synth_chs[1], NS2SA( st->output_Fs, FRAME_SIZE_NS ) ); - } -#endif - IF (hCPE->prev_synth_chs_fx[1] == NULL) { st = hCPE->hCoreCoder[1]; @@ -2133,7 +2008,7 @@ ivas_error stereo_memory_dec_fx( { return error; } - initFdCngDec( hCPE->hCoreCoder[i], hCPE->hCoreCoder[i]->cldfbSyn->scale ); + ivas_initFdCngDec_fx( hCPE->hCoreCoder[i], hCPE->hCoreCoder[i]->cldfbSyn->scale ); #if 1 initFdCngDec_flt( hCPE->hCoreCoder[i] ); #endif @@ -2153,7 +2028,7 @@ ivas_error stereo_memory_dec_fx( * Synchronize upmixed DFT/TD/MDCT stereo synthesis to match the overall delay of 32ms * Handling of TD stereo <-> DFT stereo transitions *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void synchro_synthesis( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -2293,10 +2168,8 @@ void synchro_synthesis( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q ) ); } } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); } - hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); for ( int p = 0; p < 111; p++ ) { @@ -2322,7 +2195,6 @@ void synchro_synthesis( hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q ); } } - hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; if ( !( ( hCPE->hCoreCoder[0]->element_mode != IVAS_CPE_DFT && !( sba_dirac_stereo_flag && hCPE->hCoreCoder[0]->element_mode != IVAS_CPE_MDCT ) ) || ( hCPE->hCoreCoder[0]->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ) ) { @@ -2334,7 +2206,6 @@ void synchro_synthesis( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q ); } } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } #else @@ -2553,7 +2424,6 @@ void synchro_synthesis( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q ) ); } } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); for ( int p = 0; p < 111; p++ ) { @@ -2573,7 +2443,6 @@ void synchro_synthesis( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q ); } } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; #else ivas_post_proc( NULL, hCPE, n, output[n], output, output_frame, 0 ); @@ -2628,9 +2497,7 @@ void synchro_synthesis( return; } - - -#ifdef IVAS_FLOAT_FIXED +#else void synchro_synthesis_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -2641,10 +2508,6 @@ void synchro_synthesis_fx( { Word16 output_q = OUTPUT_Q; - IF (hCPE->hStereoDft != NULL) - { - output_q = hCPE->hStereoDft->q_dft; - } Word16 n, delay_comp_TD, delay_comp_DFT; Word32 output_Fs; @@ -2665,6 +2528,15 @@ void synchro_synthesis_fx( sts = hCPE->hCoreCoder; output_Fs = sts[0]->output_Fs; + IF( hCPE->hStereoDft != NULL ) + { + output_q = hCPE->hStereoDft->q_dft; + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + Scale_sig32( hCPE->prev_hb_synth_fx[n], NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), -( Q11 - output_q ) ); + } + } + use_cldfb_for_last_dft = 0; IF( ( hCPE->element_mode != IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_24k4 ) /* note: this is to mimic the DFT stereo condition "hCPE->hStereoDft->hConfig->res_cod_mode == 0" in last frame */ || ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ) @@ -3115,6 +2987,14 @@ void synchro_synthesis_fx( } } + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + IF( hCPE->hStereoDft != NULL ) + { + Scale_sig32( hCPE->prev_hb_synth_fx[n], NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), Q11 - output_q ); + } + } + IF( hCPE->hStereoDft != NULL ) { @@ -3128,8 +3008,6 @@ void synchro_synthesis_fx( { hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } } FOR( n = 0; n < CPE_CHANNELS; n++ ) @@ -3153,8 +3031,6 @@ void synchro_synthesis_fx( { hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) { @@ -3179,10 +3055,10 @@ void synchro_synthesis_fx( hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << output_q ) ); } } - FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) - { - hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << output_q ); - } + //FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) + //{ + // hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << output_q ); + //} FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) { hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << output_q ); @@ -3238,12 +3114,6 @@ void stereo_switching_dec( const Word32 ivas_total_brate /* i : IVAS total bitrate */ ) { -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - IF( hCPE->hStereoTCA != NULL ) - { - hCPE->hStereoTCA->prevTargetGain_fx = (Word32)(hCPE->hStereoTCA->prevTargetGain * ONE_IN_Q29); - } -#endif Word16 i, n; Word16 dft32ms_ovl; Decoder_State **sts; @@ -3260,9 +3130,6 @@ void stereo_switching_dec( hCPE->last_element_mode = hCPE->element_mode; hCPE->stereo_switching_counter = 10; hCPE->NbFrameMod = 7; -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - hCPE->lt_es_em = 0.0f; -#endif hCPE->lt_es_em_fx = 0; } @@ -3407,21 +3274,22 @@ void stereo_switching_dec( cldfb_reset_memory_fx( sts[0]->cldfbBPF ); cldfb_reset_memory_fx( sts[0]->cldfbSyn ); - sts[0]->mem_deemph = 0; + //sts[0]->mem_deemph = 0; + sts[0]->mem_deemph_fx = 0; #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - sts[0]->tilt_code = 0.0f; - sts[0]->gc_threshold = 0.0f; + //sts[0]->tilt_code = 0.0f; + //sts[0]->gc_threshold = 0.0f; #endif sts[0]->tilt_code_fx = 0; sts[0]->gc_threshold_fx = 0; #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - set_f( sts[0]->mem_syn1, 0, M ); - set_f( sts[0]->mem_syn2, 0, M ); - set_f( sts[0]->mem_syn3, 0, M ); - set_f( sts[0]->mem_syn_r_float, 0.0f, L_SYN_MEM ); + //set_f( sts[0]->mem_syn1, 0, M ); + //set_f( sts[0]->mem_syn2, 0, M ); + //set_f( sts[0]->mem_syn3, 0, M ); + //set_f( sts[0]->mem_syn_r_float, 0.0f, L_SYN_MEM ); #endif set16_fx( sts[0]->mem_syn1_fx, 0, M ); @@ -3433,9 +3301,9 @@ void stereo_switching_dec( #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED /* reset PCh memories */ - set_f( sts[0]->old_exc, 0, L_EXC_MEM_DEC ); - set_f( sts[0]->lsf_old, 0, M ); - set_f( sts[0]->lsp_old, 0, M ); + //set_f( sts[0]->old_exc, 0, L_EXC_MEM_DEC ); + //set_f( sts[0]->lsf_old, 0, M ); + //set_f( sts[0]->lsp_old, 0, M ); #endif set16_fx( sts[0]->old_exc_fx, 0, L_EXC_MEM_DEC ); @@ -3446,8 +3314,10 @@ void stereo_switching_dec( sts[1]->prev_bfi = sts[0]->prev_bfi; - set_f( sts[1]->old_pitch_buf, (float) L_SUBFR, 2 * NB_SUBFR16k ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + set_f(sts[1]->old_pitch_buf, (float)L_SUBFR, 2 * NB_SUBFR16k); sts[1]->old_fpitchFB_float = 2 * (float) L_SUBFR; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) // fix need to do correctly set32_fx( sts[1]->old_pitch_buf_fx, L_deposit_h( L_SUBFR ), 2 * NB_SUBFR16k ); @@ -3464,20 +3334,21 @@ void stereo_switching_dec( cldfb_reset_memory_fx( sts[1]->cldfbBPF ); cldfb_reset_memory_fx( sts[1]->cldfbSyn ); - sts[1]->mem_deemph = 0; + //sts[1]->mem_deemph = 0; + sts[1]->mem_deemph_fx = 0; #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - sts[1]->tilt_code = 0.0f; - sts[1]->gc_threshold = 0.0f; + //sts[1]->tilt_code = 0.0f; + //sts[1]->gc_threshold = 0.0f; #endif sts[1]->tilt_code_fx = 0; sts[1]->gc_threshold_fx = 0; #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - set_f( sts[1]->mem_syn1, 0, M ); - set_f( sts[1]->mem_syn2, 0, M ); - set_f( sts[1]->mem_syn3, 0, M ); - set_f( sts[1]->mem_syn_r_float, 0.0f, L_SYN_MEM ); + //set_f( sts[1]->mem_syn1, 0, M ); + //set_f( sts[1]->mem_syn2, 0, M ); + //set_f( sts[1]->mem_syn3, 0, M ); + //set_f( sts[1]->mem_syn_r_float, 0.0f, L_SYN_MEM ); #endif set16_fx( sts[1]->mem_syn1_fx, 0, M ); @@ -3487,13 +3358,6 @@ void stereo_switching_dec( sts[1]->last_L_frame = sts[0]->last_L_frame; -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - /* populate PCh memories into the SCh */ - //mvr2r( sts[0]->old_exc, sts[1]->old_exc, L_EXC_MEM_DEC ); - mvr2r( sts[0]->lsf_old, sts[1]->lsf_old, M ); - mvr2r( sts[0]->lsp_old, sts[1]->lsp_old, M ); -#endif - Copy( sts[0]->old_exc_fx, sts[1]->old_exc_fx, L_EXC_MEM_DEC ); Copy( sts[0]->lsf_old_fx, sts[1]->lsf_old_fx, M ); Copy( sts[0]->lsp_old_fx, sts[1]->lsp_old_fx, M ); @@ -3504,9 +3368,11 @@ void stereo_switching_dec( #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED mvr2r( sts[0]->hHQ_core->old_out, sts[1]->hHQ_core->old_out, L_FRAME48k ); - mvr2r( sts[0]->delay_buf_out, sts[1]->delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP ); mvr2r( sts[0]->hTcxDec->old_syn_Overl_float, sts[1]->hTcxDec->old_syn_Overl_float, 256 ); #endif +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + mvr2r(sts[0]->delay_buf_out, sts[1]->delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP); +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) // 32bit buffer Copy32( sts[0]->hHQ_core->oldOut_fx, sts[1]->hHQ_core->oldOut_fx, L_FRAME48k ); @@ -4278,7 +4144,7 @@ static Word32 ncross_corr_self_fx( c_c_fx_return = (Word32)c_c_fx; return c_c_fx_return; } - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * Function smooth_dft2td_transition() * @@ -4431,7 +4297,7 @@ void smooth_dft2td_transition( return; } - +#endif #ifdef IVAS_FLOAT_FIXED void smooth_dft2td_transition_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -4440,15 +4306,6 @@ void smooth_dft2td_transition_fx( ) { - //Delete below - for (int n = 0; n < hCPE->nchan_out; n++) - { - FOR(Word16 lp = 0; lp < 12; lp++) - { - hCPE->hCoreCoder[n]->old_pitch_buf_fx[lp] = (Word32)(hCPE->hCoreCoder[n]->old_pitch_buf[lp] * (1u << 16)); - } - } - Decoder_State **sts; Word16 ipit, i, ipit_max, ipit_min, idiff, ilen, j, ch, lsearch, corr_len, subsampl; Word32 flen_fx, ftmp_corr_fx, fmaxcorr_fx, fac_fs_fx; diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index 5945c9a6cbe1fa4e3ec35e536c7b40b3eda73e19..f3c3c4ee4ab95c557dbf2d6da91f6ae86ee85eab 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -287,9 +287,6 @@ void tdm_configure_dec( hCPE->hStereoTCA->indx_ica_gD = 20; } hCPE->hStereoTCA->targetGain_fx = power_table[hCPE->hStereoTCA->indx_ica_gD]; -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - hCPE->hStereoTCA->targetGain = fixedToFloat( hCPE->hStereoTCA->targetGain_fx, 29 ); -#endif } /* set the BW of the secondary channel */ IF( hStereoTD->tdm_LRTD_flag && sts[1]->bits_frame_channel >= IVAS_16k4 / FRAMES_PER_SEC ) @@ -880,6 +877,7 @@ static void tdm_upmix_fade_fx( * Combine Primary and Secondary channels into L and R channels *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void stereo_tdm_combine( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ float *PCh_2_L, /* i/o: Primary channel -> output as left channel */ @@ -1040,8 +1038,7 @@ void stereo_tdm_combine( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void stereo_tdm_combine_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *PCh_2_L_fx, /* i/o: Primary channel -> output as left channel */ @@ -1059,48 +1056,60 @@ void stereo_tdm_combine_fx( Word16 stereo_tdm_coder_type; Word16 tdm_n_OVA; Word16 tdm_last_ratio_idx = hCPE->hStereoTD->tdm_last_ratio_idx; + move16(); output_Fs = hCPE->hCoreCoder[0]->output_Fs; + move32(); tdm_n_OVA = NS2SA( output_Fs, TDM_L_NOVA_NS ); + move16(); IF( flag_HB ) { upmixing_delay = NS2SA( output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ); + move16(); } ELSE { upmixing_delay = NS2SA( output_Fs, ACELP_LOOK_NS + DELAY_CLDFB_NS ); + move16(); } LR_ratio_fx = tdm_ratio_tabl_fx[tdm_ratio_idx]; + move32(); LR_ratio_mem_fx = tdm_ratio_tabl_fx[tdm_last_ratio_idx]; + move32(); IF( hCPE->hStereoTD->flag_skip_DMX ) { stereo_tdm_coder_type = 10; /* no DMX */ + move16(); Copy32( PCh_2_L_fx, Left_fx, output_frame ); Copy32( SCh_2_R_fx, Right_fx, output_frame ); } - ELSE IF( hCPE->hStereoTD->tdm_last_SM_flag == 1 ) + ELSE IF( EQ_16( hCPE->hStereoTD->tdm_last_SM_flag, 1 ) ) { - IF( hCPE->hStereoTD->tdm_prev_last_SM_flag == 0 ) + IF( EQ_16( hCPE->hStereoTD->tdm_prev_last_SM_flag, 0 ) ) { stereo_tdm_coder_type = 0; /* mode 1 : Switching from YX scheme to SM scheme*/ + move16(); } ELSE { stereo_tdm_coder_type = 1; /* mode 2 : SM scheme*/ + move16(); } } ELSE { - IF( hCPE->hStereoTD->tdm_prev_last_SM_flag == 1 ) + IF( EQ_16( hCPE->hStereoTD->tdm_prev_last_SM_flag, 1 ) ) { stereo_tdm_coder_type = 2; /* mode 3 : Switching from SM scheme to YX scheme*/ + move16(); } ELSE { stereo_tdm_coder_type = 3; /* mode 4 : YX scheme*/ + move16(); } } @@ -1117,24 +1126,24 @@ void stereo_tdm_combine_fx( /* Do the upmixing of the other samples with the new coefficient and formular for SM scheme */ tdm_upmix_plain_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay + tdm_n_OVA, output_frame, 0 ); } - break; + BREAK; case ( 1 ): { /* Do the upmixing of the first upmixing_delay samples with the old coefficient and formular for SM scheme */ tdm_upmix_plain_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_mem_fx, tdm_den_ratio_tabl_fx[tdm_last_ratio_idx], 0, upmixing_delay, 0 ); /* Do the upmixing of the other samples with the new coefficient and formular for SM scheme */ - if ( LR_ratio_fx == LR_ratio_mem_fx ) + IF( EQ_32( LR_ratio_fx, LR_ratio_mem_fx ) ) { tdm_upmix_plain_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_mem_fx, tdm_den_ratio_tabl_fx[tdm_last_ratio_idx], upmixing_delay, output_frame, 0 ); } - else + ELSE { tdm_upmix_fade_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_mem_fx, tdm_den_ratio_tabl_fx[tdm_last_ratio_idx], LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay, upmixing_delay + tdm_n_OVA, 1 ); tdm_upmix_plain_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay + tdm_n_OVA, output_frame, 0 ); } } - break; + BREAK; case ( 2 ): { /* Do the upmixing of the first upmixing_delay samples with the old coefficient and formular for SM scheme */ @@ -1146,71 +1155,80 @@ void stereo_tdm_combine_fx( /* Do the upmixing of the other samples with the new coefficient and formular for YX scheme */ tdm_upmix_plain_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay + tdm_n_OVA, output_frame, 1 ); } - break; + BREAK; case ( 3 ): { /* Do the upmixing of the first upmixing_delay samples with the old coefficient and formular for YX scheme */ tdm_upmix_plain_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_mem_fx, tdm_den_ratio_tabl_fx[tdm_last_ratio_idx], 0, upmixing_delay, 1 ); /* Do the upmixing of the other samples with the new coefficient and formular for YX scheme */ - if ( LR_ratio_fx == LR_ratio_mem_fx ) + IF( EQ_32( LR_ratio_fx, LR_ratio_mem_fx ) ) { tdm_upmix_plain_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_mem_fx, tdm_den_ratio_tabl_fx[tdm_last_ratio_idx], upmixing_delay, output_frame, 1 ); } - else + ELSE { tdm_upmix_fade_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_mem_fx, tdm_den_ratio_tabl_fx[tdm_last_ratio_idx], LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay, upmixing_delay + tdm_n_OVA, 3 ); tdm_upmix_plain_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay + tdm_n_OVA, output_frame, 1 ); } } - break; + BREAK; default: - break; + BREAK; } FOR( i = 0; i < output_frame; i++ ) { PCh_2_L_fx[i] = Left_fx[i]; + move32(); SCh_2_R_fx[i] = Right_fx[i]; + move32(); } /* DFT -> TD stereo switching: equalize signal energies */ - IF( hCPE->last_element_mode != IVAS_CPE_TD ) + IF( NE_16( hCPE->last_element_mode, IVAS_CPE_TD ) ) { Word32 incr_fx, fac_fx; IF( hCPE->hStereoDftDmx != NULL ) { fac_fx = ONE_IN_Q29; + move32(); } ELSE { fac_fx = hCPE->hStereoTCA->targetGain_fx; + move32(); } - IF( fac_fx < ONE_IN_Q29 ) + IF( LT_32( fac_fx, ONE_IN_Q29 ) ) { Word32 step = 0; + move32(); SWITCH( output_Fs ) { case ( 16000 ): step = 15339168; - break; + move32(); + BREAK; case ( 32000 ): step = 7669584; - break; + move32(); + BREAK; case ( 48000 ): step = 5113056; - break; + move32(); + BREAK; default: assert( 0 ); - break; + BREAK; } incr_fx = Mpy_32_32( L_sub( ONE_IN_Q29, fac_fx ), step ); FOR( i = 0; i < NS2SA( output_Fs, ACELP_LOOK_NS ); i++ ) { PCh_2_L_fx[i] = L_shl_sat( Mpy_32_32( PCh_2_L_fx[i], fac_fx ), 2 ); + move32(); fac_fx = L_add( incr_fx, fac_fx ); } @@ -1218,6 +1236,4 @@ void stereo_tdm_combine_fx( } return; } - - #endif \ No newline at end of file diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index 2a4e4f5b371e61b9e103f870bcaa11dab2e2a356..4d0ab1beaf8c54f735f32e0a013173fc432e7501 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -392,20 +392,20 @@ void stereo_tcx_core_dec_fx( st->tcxltp_second_last_pitch == st->L_frame */ && ( st->old_fpitch == st->hTcxDec->tcxltp_second_last_pitch ) && !st->last_tns_active && !st->second_last_tns_active ) { - //st->hTonalMDCTConc->pTCI_float->numIndexes = st->hTonalMDCTConc->pTCI_float->numIndexes; - FOR( i = 0; i < st->hTonalMDCTConc->pTCI_float->numIndexes; ++i ) + //st->hTonalMDCTConc->pTCI->numIndexes = st->hTonalMDCTConc->pTCI->numIndexes; + FOR( i = 0; i < st->hTonalMDCTConc->pTCI->numIndexes; ++i ) { - st->hTonalMDCTConc->pTCI_float->indexOfTonalPeak[i] = st->hTonalMDCTConc->pTCI_float->indexOfTonalPeak[i]; - st->hTonalMDCTConc->pTCI_float->lowerIndex[i] = st->hTonalMDCTConc->pTCI_float->lowerIndex[i]; - st->hTonalMDCTConc->pTCI_float->upperIndex[i] = st->hTonalMDCTConc->pTCI_float->upperIndex[i]; + st->hTonalMDCTConc->pTCI->indexOfTonalPeak[i] = st->hTonalMDCTConc->pTCI->indexOfTonalPeak[i]; + st->hTonalMDCTConc->pTCI->lowerIndex[i] = st->hTonalMDCTConc->pTCI->lowerIndex[i]; + st->hTonalMDCTConc->pTCI->upperIndex[i] = st->hTonalMDCTConc->pTCI->upperIndex[i]; } - FOR( i = 0; i < st->hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + FOR( i = 0; i < st->hTonalMDCTConc->pTCI->numIndexes; i++ ) { - st->hTonalMDCTConc->pTCI_float->phaseDiff_float[i] = fixedToFloat( st->hTonalMDCTConc->pTCI_float->phaseDiff[i], Q12 ); + st->hTonalMDCTConc->pTCI->phaseDiff_float[i] = fixedToFloat( st->hTonalMDCTConc->pTCI->phaseDiff[i], Q12 ); } FOR( i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++ ) { - st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float[i] = fixedToFloat( st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted[i], Q13 ); + st->hTonalMDCTConc->pTCI->phase_currentFramePredicted_float[i] = fixedToFloat( st->hTonalMDCTConc->pTCI->phase_currentFramePredicted[i], Q13 ); } } } @@ -734,7 +734,7 @@ void stereo_tcx_core_dec_fx( IF( bfi && NE_16( st->last_core, ACELP_CORE ) ) { /* Update FEC_scale_syn parameters */ - IF( hTcxLtpDec->tcxltp_gain_float == 0 ) + IF( EQ_16( hTcxLtpDec->tcxltp_gain, 0 ) ) { frame_ener_fx( st->L_frame, UNVOICED, synth_fx, shr( st->L_frame, 1 ), &st->enr_old_fx, st->L_frame, 0, 0, 0 ); } @@ -862,11 +862,11 @@ void stereo_tcx_core_dec_fx( { Word16 buffer[L_FRAME16k]; lerp( signal_outFB_fx, buffer, st->L_frame, hTcxDec->L_frameTCX ); - ApplyFdCng_fx( buffer, 0 /* Q of buffer */, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); + ApplyFdCng_fx( buffer, 0 /* Q of buffer */, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); } ELSE { - ApplyFdCng_fx( signal_out_fx, 0, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); + ApplyFdCng_fx( signal_out_fx, 0, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); } } @@ -894,7 +894,7 @@ void stereo_tcx_core_dec_fx( IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 0 ) ) { - ApplyFdCng_fx( signal_out_fx, 0, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); + ApplyFdCng_fx( signal_out_fx, 0, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); } } @@ -1811,7 +1811,7 @@ static void dec_prm_tcx_ivas_fx( } #if 1 /*Fixed to float changes*/ - st->hTcxLtpDec->tcxltp_gain_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain, 15 ); + //st->hTcxLtpDec->tcxltp_gain_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain, 15 ); st->hTcxDec->tcxltp_last_gain_unmodified_float = fixedToFloat( st->hTcxDec->tcxltp_last_gain_unmodified, 15 ); #endif // Ends here return; diff --git a/lib_dec/ivas_td_low_rate_dec.c b/lib_dec/ivas_td_low_rate_dec.c index 2b1d358d7106c02b47d3e8f1053a3e8cf11c16d7..f32863d6739146179400f0cb1b781c5cdfe6c3db 100644 --- a/lib_dec/ivas_td_low_rate_dec.c +++ b/lib_dec/ivas_td_low_rate_dec.c @@ -42,7 +42,7 @@ #include "prot_fx2.h" #include "ivas_prot.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * tdm_low_rate_dec() * @@ -173,7 +173,7 @@ void tdm_low_rate_dec( /*hGSCDec float2fix*/ st->GSC_noisy_speech = st->GSC_noisy_speech; - st->lp_gainc_fx = float_to_fix16(st->lp_gainc, Q3); + //st->lp_gainc_fx = float_to_fix16(st->lp_gainc, Q3); st->last_good = st->last_good; st->Last_GSC_noisy_speech_flag = st->Last_GSC_noisy_speech_flag; st->last_coder_type = st->last_coder_type; @@ -209,13 +209,13 @@ void tdm_low_rate_dec( /*hGSCDec fix2float*/ st->GSC_noisy_speech = st->GSC_noisy_speech; - st->lp_gainc = fixedToFloat(st->lp_gainc_fx, Q3); + //st->lp_gainc = fixedToFloat(st->lp_gainc_fx, Q3); /*hGSCDec end*/ *tmp_noise = st->lp_gainc; #endif } - +#endif #ifdef IVAS_FLOAT_FIXED void tdm_low_rate_dec_fx( Decoder_State *st, /* i/o: decoder static memory */ @@ -357,7 +357,7 @@ void tdm_low_rate_dec_fx( * * Decode generic (GC), 2 subframes mode *---------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void decod_gen_2sbfr( Decoder_State *st, /* i/o: decoder static memory */ const int16_t sharpFlag, /* i : formant sharpening flag */ @@ -493,7 +493,7 @@ void decod_gen_2sbfr( /*hGSCDec float2fix*/ st->GSC_noisy_speech = st->GSC_noisy_speech; - st->lp_gainc_fx = float_to_fix16( st->lp_gainc, Q3 ); + //st->lp_gainc_fx = float_to_fix16( st->lp_gainc, Q3 ); st->dm_fx.prev_state = float_to_fix16(st->dispMem[0], 0); st->dm_fx.prev_gain_code = floatToFixed(st->dispMem[1], Q16); floatToFixed_arr(&(st->dispMem[2]), st->dm_fx.prev_gain_pit, Q14, 6); @@ -514,7 +514,6 @@ void decod_gen_2sbfr( floatToFixed_arr((Float32 *)tdm_Pri_pitch_buf, tdm_Pri_pitch_buf_fx, Q6, NB_SUBFR); floatToFixed_arr(exc - L_EXC_MEM_DEC, old_exc_fx, st->Q_exc, L_EXC_DEC); exc_fx = old_exc_fx + L_EXC_MEM_DEC; - floatToFixed_arr(exc2 - L_EXC_MEM, old_exc2_fx, st->Q_exc, L_FRAME16k + L_EXC_MEM); exc2_fx = old_exc2_fx + L_EXC_MEM; floatToFixed_arr(gain_buf, gain_buf_fx, Q14, NB_SUBFR16k); if (bwe_exc) { @@ -536,14 +535,14 @@ void decod_gen_2sbfr( /*hGSCDec fix2float*/ st->GSC_noisy_speech = st->GSC_noisy_speech; - st->lp_gainc = fixedToFloat( st->lp_gainc_fx, Q3 ); + //st->lp_gainc = fixedToFloat( st->lp_gainc_fx, Q3 ); st->dispMem[0] = fixedToFloat(st->dm_fx.prev_state, 0); st->dispMem[1] = fixedToFloat(st->dm_fx.prev_gain_code, Q16); fixedToFloat_arr(st->dm_fx.prev_gain_pit, &(st->dispMem[2]), Q14, 6); /*hGSCDec end*/ #endif } - +#endif #ifdef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * decod_gen_2sbfr_ivas_fx() @@ -712,12 +711,15 @@ void decod_gen_2sbfr_ivas_fx( gain_buf[i_subfr / L_SUBFR] = gain_pit; gain_buf[( i_subfr + L_SUBFR ) / L_SUBFR] = gain_pit; - st->tilt_code_dec[i_subfr / L_SUBFR] = st->tilt_code; - st->tilt_code_dec[( i_subfr + L_SUBFR ) / L_SUBFR] = st->tilt_code; + st->tilt_code_dec_fx[i_subfr / L_SUBFR] = st->tilt_code_fx; + st->tilt_code_dec_fx[( i_subfr + L_SUBFR ) / L_SUBFR] = st->tilt_code_fx; + //st->tilt_code_dec[i_subfr / L_SUBFR] = st->tilt_code; + //st->tilt_code_dec[( i_subfr + L_SUBFR ) / L_SUBFR] = st->tilt_code; } /* SC-VBR */ - st->prev_gain_pit_dec = gain_pit; + //st->prev_gain_pit_dec = gain_pit; + st->prev_gain_pit_dec_fx = gain_pit; return; } diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 961cb27441ae61ca7207cfceae369e16d9db24e5..b9df10d50115058acfa36d3bab444f73339348a7 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -1455,6 +1455,14 @@ ivas_error IVAS_DEC_FeedHeadTrackData( hHeadTrackData->Pos[subframe_idx].x = Pos.x; hHeadTrackData->Pos[subframe_idx].y = Pos.y; hHeadTrackData->Pos[subframe_idx].z = Pos.z; +#ifdef IVAS_FLOAT_FIXED + hHeadTrackData->Pos[subframe_idx].x_fx = Pos.x_fx; + hHeadTrackData->Pos[subframe_idx].y_fx = Pos.y_fx; + hHeadTrackData->Pos[subframe_idx].z_fx = Pos.z_fx; + hHeadTrackData->Pos[subframe_idx].x_qfact = Pos.x_qfact; + hHeadTrackData->Pos[subframe_idx].y_qfact = Pos.y_qfact; + hHeadTrackData->Pos[subframe_idx].z_qfact = Pos.z_qfact; +#endif hIvasDec->updateOrientation = true; @@ -1578,15 +1586,15 @@ ivas_error IVAS_DEC_FeedExternalOrientationData( orientation_fx.y_fx = float_to_fix(orientation.y, orientation_fx.y_qfact); orientation_fx.z_fx = float_to_fix(orientation.z, orientation_fx.z_qfact); /* Move external orientation data to the decoder handle (invert orientations) */ - QuaternionInverse_fx(orientation_fx, &hExternalOrientationData->Quaternions_fx[subframe_idx]); - hExternalOrientationData->Quaternions[subframe_idx].w = me2f(hExternalOrientationData->Quaternions_fx[subframe_idx].w_fx, - 31 - hExternalOrientationData->Quaternions_fx[subframe_idx].w_qfact); - hExternalOrientationData->Quaternions[subframe_idx].x = me2f(hExternalOrientationData->Quaternions_fx[subframe_idx].x_fx, - 31 - hExternalOrientationData->Quaternions_fx[subframe_idx].x_qfact); - hExternalOrientationData->Quaternions[subframe_idx].y = me2f(hExternalOrientationData->Quaternions_fx[subframe_idx].y_fx, - 31 - hExternalOrientationData->Quaternions_fx[subframe_idx].y_qfact); - hExternalOrientationData->Quaternions[subframe_idx].z = me2f(hExternalOrientationData->Quaternions_fx[subframe_idx].z_fx, - 31 - hExternalOrientationData->Quaternions_fx[subframe_idx].z_qfact); + QuaternionInverse_fx(orientation_fx, &hExternalOrientationData->Quaternions[subframe_idx]); + hExternalOrientationData->Quaternions[subframe_idx].w = me2f(hExternalOrientationData->Quaternions[subframe_idx].w_fx, + 31 - hExternalOrientationData->Quaternions[subframe_idx].w_qfact); + hExternalOrientationData->Quaternions[subframe_idx].x = me2f(hExternalOrientationData->Quaternions[subframe_idx].x_fx, + 31 - hExternalOrientationData->Quaternions[subframe_idx].x_qfact); + hExternalOrientationData->Quaternions[subframe_idx].y = me2f(hExternalOrientationData->Quaternions[subframe_idx].y_fx, + 31 - hExternalOrientationData->Quaternions[subframe_idx].y_qfact); + hExternalOrientationData->Quaternions[subframe_idx].z = me2f(hExternalOrientationData->Quaternions[subframe_idx].z_fx, + 31 - hExternalOrientationData->Quaternions[subframe_idx].z_qfact); #else /* Move external orientation data to the decoder handle (invert orientations) */ QuaternionInverse( orientation, &hExternalOrientationData->Quaternions[subframe_idx] ); diff --git a/lib_dec/lsf_dec.c b/lib_dec/lsf_dec.c index d475c7292da3986e808f82b25ac7d6d5992f3554..11ed2e25f79172fd3b9b06a47a50b2bbaaa9c643 100644 --- a/lib_dec/lsf_dec.c +++ b/lib_dec/lsf_dec.c @@ -60,7 +60,7 @@ static void dqlsf_CNG( Decoder_State *st, float *lsf_q ); * * LSF decoder *---------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void lsf_dec( Decoder_State *st, /* i/o: State structure */ const int16_t tc_subfr, /* i : TC subframe index */ @@ -806,3 +806,4 @@ static void dqlsf_CNG( return; } +#endif diff --git a/lib_dec/nelp_dec.c b/lib_dec/nelp_dec.c index abfa3d0be2b9e5aceed49ba3b8371d722e3ab37d..d65de698588b18808a0f7666bac52bb2932e3de6 100644 --- a/lib_dec/nelp_dec.c +++ b/lib_dec/nelp_dec.c @@ -47,7 +47,7 @@ * * NELP decoder *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void nelp_decoder( Decoder_State *st, /* i/o: decoder static memory */ float *exc_nelp, /* o : adapt. excitation/total exc*/ @@ -217,3 +217,4 @@ void nelp_decoder( return; } +#endif \ No newline at end of file diff --git a/lib_dec/pitch_extr.c b/lib_dec/pitch_extr.c index c1d53494f93d827d3bd315df79e6722a0251153f..941f4711b205c8a84c75a142ac5f2e0bec613dcf 100644 --- a/lib_dec/pitch_extr.c +++ b/lib_dec/pitch_extr.c @@ -44,7 +44,7 @@ #include "basop_util.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-----------------------------------------------------------------* * Pitch prediction for frame erasure using linear fitting * *-----------------------------------------------------------------*/ @@ -346,3 +346,4 @@ void get_subframe_pitch_flt( return; } +#endif diff --git a/lib_dec/post_dec.c b/lib_dec/post_dec.c index 120046fa8be01e42847eb78011d7480a74fa4b50..4b8d13eaacb251ad7cf62ecd15040b7d97533349 100644 --- a/lib_dec/post_dec.c +++ b/lib_dec/post_dec.c @@ -53,7 +53,7 @@ static void bass_pf_1sf_delay( float *syn, const int16_t *T_sf, const float *gai * * Perform post-processing *---------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void post_decoder_flt( Decoder_State *st, /* i/o: decoder memory state pointer */ float synth_buf[], @@ -181,7 +181,7 @@ void post_decoder_flt( return; } - +#endif /*---------------------------------------------------------------------* * bass_pf_1sf_delay() @@ -340,6 +340,7 @@ static void bass_pf_1sf_delay( return; } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*---------------------------------------------------------------------* * cldfb_synth_set_bandsToZero_flt() * @@ -474,3 +475,4 @@ void cldfb_synth_set_bandsToZero_flt( return; } +#endif diff --git a/lib_dec/rst_dec.c b/lib_dec/rst_dec.c index 4206f56521bd9ccbd509b0e6e370102adf4cd923..f3b744c7be5b3756f996c27c703f60857b81aa9b 100644 --- a/lib_dec/rst_dec.c +++ b/lib_dec/rst_dec.c @@ -47,7 +47,7 @@ * * Reset decoder static variables in case of CNG frame *----------------------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void CNG_reset_dec( Decoder_State *st, /* i/o: decoder state structure */ float *pitch_buf, /* o : floating pitch for each subframe */ @@ -93,3 +93,4 @@ void CNG_reset_dec( return; } +#endif diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 27a60c3cc9972403623af4df5418d406fd42c3df..f29b6e5735b79d440adcd73623165f69cf9379f5 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -84,62 +84,78 @@ typedef struct Word16 olapBufferAna[320]; Word16 olapBufferSynth2[FFTLEN]; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float msPeriodog_float[NPART_SHAPING]; /* Periodogram */ +#endif Word32 msPeriodog[NPART_SHAPING]; /* Periodogram */ Word16 msPeriodog_exp; /* Common exponent for fft and cldfb energies */ Word16 msPeriodog_exp_fft; Word16 msPeriodog_exp_cldfb; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float msBminWin_float[NPART_SHAPING]; +#endif Word32 msBminWin[NPART_SHAPING]; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float msBminSubWin_float[NPART_SHAPING]; +#endif Word32 msBminSubWin[NPART_SHAPING]; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float msPsd_float[NPART_SHAPING]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ +#endif Word16 msPsd[NPART_SHAPING]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ Word32 msPsd_fx[NPART_SHAPING]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ Word16 msPsd_exp_fft; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float msAlpha_float[NPART_SHAPING]; /* Optimal smoothing parameter */ +#endif Word32 msAlpha[NPART_SHAPING]; /* Optimal smoothing parameter */ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float msMinBuf_float[MSNUMSUBFR * NPART_SHAPING]; /* Buffer of minima */ +#endif Word32 msMinBuf[MSNUMSUBFR*NPART_SHAPING]; /* Buffer of minima */ - + +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float msCurrentMinOut_float[NPART_SHAPING]; +#endif Word32 msCurrentMinOut[NPART_SHAPING]; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float msCurrentMin_float[NPART_SHAPING]; +#endif Word32 msCurrentMin[NPART_SHAPING]; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float msCurrentMinSubWindow_float[NPART_SHAPING]; +#endif Word32 msCurrentMinSubWindow[NPART_SHAPING]; int16_t msLocalMinFlag[NPART_SHAPING]; int16_t msNewMinFlag[NPART_SHAPING]; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float msPsdFirstMoment_float[NPART_SHAPING]; +#endif Word16 msPsdFirstMoment[NPART_SHAPING]; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float msPsdSecondMoment_float[NPART_SHAPING]; +#endif Word32 msPsdSecondMoment[NPART_SHAPING]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float msNoiseFloor_float[NPART_SHAPING]; /* Estimated noise floor */ +#endif Word16 msNoiseFloor[NPART_SHAPING]; /* Estimated noise floor */ float msNoiseEst_float[NPART_SHAPING]; /* Estimated noise level */ Word32 msNoiseEst[NPART_SHAPING]; /* Estimated noise level */ Word16 msNoiseEst_exp; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float msLogPeriodog_float[NPART_SHAPING]; /* Periodogram */ +#endif Word16 msLogPeriodog[NPART_SHAPING]; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float msLogNoiseEst_float[NPART_SHAPING]; /* Estimated noise level */ +#endif Word16 msLogNoiseEst[NPART_SHAPING]; int16_t npart_shaping; /* Number of partitions */ @@ -156,49 +172,66 @@ typedef struct float psize_inv_shaping_float[NPART_SHAPING]; /* Inverse of partition sizes */ Word16 psize_inv_shaping[NPART_SHAPING]; /* Inverse of partition sizes */ - + float bandNoiseShape_float[FFTLEN2]; /* CNG spectral shape computed at the decoder */ + Word32 bandNoiseShape[FFTLEN2]; /* CNG spectral shape computed at the decoder */ Word16 bandNoiseShape_exp; /* exponent of bandNoiseShape */ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float partNoiseShape_float[NPART]; /* CNG spectral shape computed at the decoder */ +#endif Word32 partNoiseShape[NPART]; /* CNG spectral shape computed at the decoder */ Word16 partNoiseShape_exp; /* exponent of partNoiseShape */ float smoothed_psd[L_FRAME16k]; /* stereo CNA - periodogram smoothed with IIR filter */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float msPeriodog_ST[NPART_SHAPING]; /* stereo CNA - short-term periodogram */ +#endif Word32 msPeriodog_ST_fx[NPART_SHAPING]; /* stereo CNA - short-term periodogram */ Word16 msPeriodog_ST_exp; /* exponent of stereo CNA - short-term periodogram */ int16_t ms_last_inactive_bwidth; /* stereo CNA - bandwidth from the last inactive frame */ int16_t ms_cnt_bw_up; /* stereo CNA - downward counter of frames since the last NB->WB switch */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float cna_LR_LT; /* stereo CNA - long-term L/R correlation factor calculated on stereo upmix */ +#endif Word16 cna_LR_LT_fx; /* stereo CNA - long-term L/R correlation factor calculated on stereo upmix */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float cna_ILD_LT; /* stereo CNA - long-term ILD factor calculated on stereo upmix */ - Word16 cna_ILD_LT_fx; /* stereo CNA - long-term ILD factor calculated on stereo upmix */ +#endif + Word16 cna_ILD_LT_fx; /* stereo CNA - long-term ILD factor calculated on stereo upmix */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float cna_g_state[STEREO_DFT_BAND_MAX]; /* stereo CNA - side gains from the last inactive frame */ float cna_cm[STEREO_DFT_BAND_MAX]; /* stereo CNA - coherence from the last inactive frame */ +#endif int16_t first_cna_noise_updated; /* stereo CNA - flag indicating that comfort noise has been properly initialized during warmup */ int16_t first_cna_noise_update_cnt; /* stereo CNA - counter of CN initialization frames */ int16_t cna_nbands; /* stereo CNA - number of frequency bands used by the CNA in DFT stereo mode */ int16_t cna_band_limits[STEREO_DFT_BAND_MAX + 1]; /* stereo CNA - band limits used by the CNA in DFT stereo mode */ float cna_act_fact; /* stereo CNA - long-term signal activity factor (0-1) */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float cna_rescale_fact; /* stereo CNA - CN energy re-scaling factor to maintain decoded energy */ +#endif int16_t cna_seed; /* stereo CNA - seed for random CN generator */ int16_t flag_dtx_mode; - - float lp_speech_float; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float lp_speech_float; +#endif Word32 lp_speech; /* format: Q9.23 */ - + Word16 q_lp_speech; + +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float lp_noise_float; +#endif Word32 lp_noise; /* format: Q9.23 */ + Word16 q_lp_noise; - - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float msPeriodogBuf_float[MSBUFLEN * NPART_SHAPING]; +#endif Word16 msPeriodogBuf[MSBUFLEN*NPART_SHAPING]; int16_t msPeriodogBufPtr; @@ -231,37 +264,46 @@ typedef struct int16_t Transient[MAX_POST_LEN]; int16_t TCX_Tonality[DEC_STATE_LEN]; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float outx_new_n1; +#endif Word16 outx_new_n1_fx; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float nsapp_gain; +#endif Word16 nsapp_gain_fx; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float nsapp_gain_n; +#endif Word16 nsapp_gain_n_fx; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float data_reci2[L_FRAME_MAX]; +#endif Word32 data_reci2_fx[L_FRAME_MAX]; Word16 data_reci2_scale; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float data_noise_float[L_FRAME_MAX]; +#endif Word16 data_noise[L_FRAME_MAX]; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float ener_mean; +#endif Word32 ener_mean_fx; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float ener; +#endif Word32 ener_fx; int16_t zp; Word16 zp_fx; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float recovery_gain_float; +#endif Word16 recovery_gain; /*outside waveformadjustment: Q14 - insinde waveformadjustment: Q15*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float step_concealgain; +#endif Word16 step_concealgain_fx; int16_t concealment_method; @@ -316,7 +358,7 @@ typedef struct Float32 phaseDiff_float[MAX_NUMBER_OF_IDX]; /* This one can be stored with 16 bits in range 0..2*PI */ Float32 phase_currentFramePredicted_float[MAX_NUMBER_OF_IDX * GROUP_LENGTH]; /* This one can be stored with 16 bits in range 0..2*PI, but the code has to be adapted to use moduo(2*PI) after adding */ -} TonalComponentsInfo_float; +} TonalComponentsInfo; typedef struct { @@ -340,7 +382,9 @@ typedef struct tonalmdctconceal int16_t nNonZeroSamples; int16_t nScaleFactors; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float lastPitchLag_float; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) Word32 lastPitchLag; blockData lastBlockData; @@ -372,29 +416,37 @@ typedef struct tonalmdctconceal float scaleFactorsBackground_flt[FDNS_NPTS]; Word16 scaleFactorsBackground[FDNS_NPTS]; Word32 scaleFactorsBackground_fx[FDNS_NPTS]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float scf_fadeout_flt; +#endif Word16 scf_fadeout; PsychoacousticParameters *psychParams; PsychoacousticParameters psychParamsTCX20; PsychoacousticParameters psychParamsTCX10; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float last_block_nrg_flt; +#endif Word32 last_block_nrg; Word16 last_block_nrg_exp; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float curr_noise_nrg_flt; +#endif Word32 curr_noise_nrg; Word16 curr_noise_nrg_exp; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float faded_signal_nrg_flt; +#endif Word32 faded_signal_nrg; Word16 faded_signal_nrg_exp; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float nFramesLost_float; +#endif Word16 nFramesLost; #if 0 //Memory ovelap issue #endif - TonalComponentsInfo_float *pTCI_float; - TonalComponentsInfo_float pTCI_float1; + TonalComponentsInfo *pTCI; + TonalComponentsInfo pTCI1; } TonalMDCTConceal_INSTANCE, *TonalMDCTConcealPtr; @@ -514,8 +566,10 @@ typedef struct igfdec_instance_struct typedef struct tec_dec_structure { +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float pGainTemp[CLDFB_NO_COL_MAX]; float loBuffer_flt[CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG]; +#endif //fixed variable Word16 pGainTemp_m[CLDFB_NO_COL_MAX]; @@ -535,8 +589,9 @@ typedef struct tcx_ltp_dec_structure { /* TCX-LTP */ int16_t tcxltp; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float tcxltp_gain_float; +#endif Word16 tcxltp_gain; int16_t tcxltp_pitch_int; @@ -560,7 +615,10 @@ typedef struct tcx_ltp_dec_structure int16_t tcxltp_pitch_int_post_prev; int16_t tcxltp_pitch_fr_post_prev; +//#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) +#if 1 float tcxltp_gain_post_prev_float; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) Word16 tcxltp_gain_post_prev; int16_t tcxltp_filt_idx_prev; @@ -578,10 +636,12 @@ typedef struct tcx_dec_structure int16_t envWeighted; /* are is{p,f}_old[] weighted or not? */ /* tonal PLC */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float tcxltp_second_last_pitch_float; + float tcxltp_third_last_pitch_float; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) Word32 tcxltp_second_last_pitch; - float tcxltp_third_last_pitch_float; Word32 tcxltp_third_last_pitch; float tcxltp_last_gain_unmodified_float; @@ -640,7 +700,9 @@ typedef struct tcx_dec_structure /* PLC */ int16_t noise_filling_index[NB_DIV]; /* PLC - last decoded noise filling index */ int16_t tnsActive[NB_DIV]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float ltpGainMemory[N_LTP_GAIN_MEMS]; /* for smoothing noiseTransWidth */ +#endif Word16 ltpGainMemory_fx[N_LTP_GAIN_MEMS]; /* Q15 */ uint16_t kernel_type[2]; /* transform kernel type in each subframe (MDCT or MDST) */ @@ -649,17 +711,20 @@ typedef struct tcx_dec_structure Word32 CngLevelBackgroundTrace_bfi_fx; /* PLC - long term gain estimate for background level, used for PLC fade out */ Word16 CngLevelBackgroundTrace_bfi_exp; /* state variables for the minimum statistics used for PLC */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float NoiseLevelMemory_bfi[PLC_MIN_STAT_BUFF_SIZE]; +#endif #ifdef IVAS_FLOAT_FIXED - Word16 NoiseLevelMemory_bfi_fx[PLC_MIN_STAT_BUFF_SIZE]; + //Word16 NoiseLevelMemory_bfi_fx[PLC_MIN_STAT_BUFF_SIZE]; #endif // IVAS_FLOAT_FIXED int16_t NoiseLevelIndex_bfi; int16_t CurrLevelIndex_bfi; Word16 conCngLevelBackgroundTrace; /* Q15 long term gain estimate for background level, used for PLC fade out */ Word16 conCngLevelBackgroundTrace_e; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float LastFrameLevel_bfi; +#endif #ifdef IVAS_FLOAT_FIXED Word16 LastFrameLevel_bfi_fx; #endif // IVAS_FLOAT_FIXED @@ -668,8 +733,9 @@ typedef struct tcx_dec_structure Word16 conNoiseLevelIndex; /*Q0*/ Word16 conCurrLevelIndex; /*Q0*/ Word16 conLastFrameLevel, conLastFrameLevel_e;/*Q15*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_gaintcx_bfi_float; +#endif Word16 old_gaintcx_bfi, old_gaintcx_bfi_e; float conceal_eof_gain_float; @@ -677,20 +743,24 @@ typedef struct tcx_dec_structure #ifdef IVAS_FLOAT_FIXED Word32 conceal_eof_gain32; /*have been created for further calculation */ #endif - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float damping_float; +#endif Word16 damping; /* 1Q14 */ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float gainHelper_float; +#endif Word16 gainHelper, gainHelper_e; /*can be >1*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float stepCompensate_float; +#endif Word16 stepCompensate, stepCompensate_e; int16_t tcxConceal_recalc_exc; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float cummulative_damping_tcx_float; +#endif Word16 cummulative_damping_tcx; @@ -709,28 +779,40 @@ typedef struct gsc_dec_structure int16_t cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ //Word16 cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_y_gain[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ +#endif Word16 old_y_gain_fx[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ int16_t noise_lev; /* AC mode (GSC) - noise level */ //Word16 noise_lev; /* AC mode (GSC) - noise level Q0*/ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float lt_ener_per_band[MBANDS_GN16k]; +#endif Word16 lt_ener_per_band_fx[MBANDS_GN16k]; /* Q12 */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float Last_frame_ener; /* AC mode (GSC) - last frame energy */ +#endif Word32 Last_frame_ener_fx; /* AC mode (GSC) - last frame energy */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float Last_GSC_spectrum[L_FRAME16k]; /* AC mode (GSC) - Last good GSC spectrum */ +#endif Word16 Last_GSC_spectrum_fx[L_FRAME16k]; /* AC mode (GSC) - Last good GSC spectrum */ int16_t Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index */ //Word16 Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index Q0*/ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float last_exc_dct_in[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ +#endif Word16 last_exc_dct_in_fx[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float last_ener; /* AC mode (GSC) - previous energy */ +#endif Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ int16_t last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ @@ -746,10 +828,14 @@ typedef struct gsc_dec_structure typedef struct WI_dec_structure { +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_exc2[L_EXC_MEM]; /* FEC - old excitation2 used in fast recovery */ +#endif Word16 old_exc2_fx[L_EXC_MEM]; /* FEC - old excitation2 used in fast recovery */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_syn2[L_EXC_MEM]; /* FEC - old syn speech used in fast recovery */ +#endif Word16 old_syn2_fx[L_EXC_MEM]; /* FEC - old syn speech used in fast recovery */ @@ -831,18 +917,19 @@ typedef struct ld_music_postfilt_structure typedef struct bass_postfilt_structure { +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float pst_old_syn[NBPSF_PIT_MAX]; /* Bass post-filter - old synthesis buffer 1 */ +#endif Word16 pst_old_syn_fx[NBPSF_PIT_MAX]; /* Bass post-filter - old synthesis buffer 1 Q_syn2-1*/ Word16 q_pst_old_syn; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float pst_mem_deemp_err; /* Bass post-filter - filter memory of noise LP filter */ +#endif Word16 pst_mem_deemp_err_fx; /* Bass post-filter - filter memory of noise LP filter Q_syn2-1*/ -#ifdef IVAS_FLOAT_FIXED - Word32 pst_mem_deemp_err_32; - Word32 pst_old_syn_32[NBPSF_PIT_MAX]; /* Bass post-filter - old synthesis buffer 1 Q_syn2-1*/ -#endif // IVAS_FLOAT_FIXED - + +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float pst_lp_ener; /* Bass post-filter - long-term energy */ +#endif Word16 pst_lp_ener_fx; /* Bass post-filter - long-term energy Q8*/ int16_t Track_on_hist[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ @@ -850,11 +937,13 @@ typedef struct bass_postfilt_structure int16_t vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ //Word16 vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float psf_att; /* Bass post-filter - post filter attenuation factor */ +#endif Word16 psf_att_fx; /* Bass post-filter - post filter attenuation factor */ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mem_mean_pit[L_TRACK_HIST]; /* Bass post-filter - average pitch memory */ +#endif Word16 mem_mean_pit_fx[L_TRACK_HIST]; /* Bass post-filter - average pitch memory */ @@ -870,8 +959,9 @@ typedef struct td_cng_dec_structure { int16_t cng_seed; /* DTX/CNG - seed for white noise random generator */ // Word16 cng_seed; /*CNG and DTX - seed for white noise random generator*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float Enew; /* DTX/CNG - decoded residual energy */ +#endif Word32 Enew_fx; /* CNG and DTX - decoded residual energy Q6*/ int16_t old_enr_index; /* DTX/CNG - index of last encoded CNG energy */ @@ -894,14 +984,17 @@ typedef struct td_cng_dec_structure int32_t ho_sid_bw; /* DTX/CNG - SID bandwidth flags */ //Word32 ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float ho_lsp_hist[HO_HIST_SIZE * M]; /* DTX/CNG - old LSP buffer for averaging */ +#endif Word16 ho_lsp_hist_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float ho_ener_hist[HO_HIST_SIZE]; /* DTX/CNG - energy buffer for averaging */ +#endif Word32 ho_ener_hist_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ /*Q6 */ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float ho_env_hist[HO_HIST_SIZE * NUM_ENV_CNG]; +#endif Word32 ho_env_hist_fx[HO_HIST_SIZE * NUM_ENV_CNG]; @@ -914,14 +1007,17 @@ typedef struct td_cng_dec_structure int16_t ho_circ_ptr; /* DTX/CNG - pointer for averaging buffers */ //Word16 ho_circ_ptr; /* CNG and DTX - pointer for averaging buffers */ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float ho_lsp_circ[HO_HIST_SIZE * M]; /* DTX/CNG - old LSP buffer for averaging */ +#endif Word16 ho_lsp_circ_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float ho_ener_circ[HO_HIST_SIZE]; /* DTX/CNG - energy buffer for averaging */ +#endif Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ /* Q6 */ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float ho_env_circ[HO_HIST_SIZE * NUM_ENV_CNG]; +#endif Word32 ho_env_circ_fx[HO_HIST_SIZE * NUM_ENV_CNG]; @@ -934,37 +1030,46 @@ typedef struct td_cng_dec_structure int16_t act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ // Word16 act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_env[20]; +#endif Word32 old_env_fx[20]; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float lp_env[20]; +#endif Word32 lp_env_fx[20]; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float exc_mem[24]; +#endif Word16 exc_mem_fx[24]; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float exc_mem1[30]; +#endif Word16 exc_mem1_fx[30]; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float interpol_3_2_cng_dec[INTERP_3_2_MEM_LEN]; /* SWB DTX/CNG parameters */ float shb_cng_ener; float shb_lpcCNG[LPC_SHB_ORDER + 1]; +#endif Word16 shb_lpcCNG_fx[LPC_SHB_ORDER + 1]; /* Assumed in Q12 */ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float shb_cng_gain; +#endif Word16 shb_cng_gain_fx; /* Assumed in Q8 */ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float wb_cng_ener; float last_wb_cng_ener; float last_shb_cng_ener; +#endif int16_t swb_cng_seed; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float lsp_shb_prev_prev[LPC_SHB_ORDER]; float lsp_shb_prev[LPC_SHB_ORDER]; +#endif int16_t shb_dtx_count; int16_t trans_cnt; @@ -982,8 +1087,9 @@ typedef struct td_cng_dec_structure #endif int16_t burst_cnt; //Word16 burst_cnt; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float last_shb_ener; +#endif #ifdef IVAS_FLOAT_FIXED Word32 last_shb_ener_fx; //Q(11) #endif @@ -1006,10 +1112,13 @@ typedef struct sc_vbr_dec_structure //Word16 firstTime_voiceddec; /*Q0*/ /* DTFS variables */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float dtfs_dec_a[MAXLAG_WI]; +#endif Word16 dtfs_dec_a_fx[MAXLAG_WI]; /*Variable Q format in dtfs_dec_Q*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float dtfs_dec_b[MAXLAG_WI]; +#endif Word16 dtfs_dec_b_fx[MAXLAG_WI]; /*Variable Q format in dtfs_dec_Q*/ int16_t dtfs_dec_lag; @@ -1021,42 +1130,54 @@ typedef struct sc_vbr_dec_structure int16_t dtfs_dec_nH_4kHz; //Word16 dtfs_dec_nH_4kHz; /*Q0*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float dtfs_dec_upper_cut_off_freq_of_interest; +#endif Word16 dtfs_dec_upper_cut_off_freq_of_interest_fx; /*Q0*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float dtfs_dec_upper_cut_off_freq; +#endif Word16 dtfs_dec_upper_cut_off_freq_fx; /*Q0*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float ph_offset_D; +#endif Word16 ph_offset_D_fx; /* normalized by 2Pi Q15*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float lastLgainD; /* previous gain value for the low band */ +#endif Word16 lastLgainD_fx; /* previous gain value for the low band Q11*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float lastHgainD; /* previous gain value for the high band */ +#endif Word16 lastHgainD_fx; /* previous gain value for the high band Q11 */ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float lasterbD[NUM_ERB_WB]; /* previous amplitude spectrum (ERB) */ +#endif Word16 lasterbD_fx[NUM_ERB_WB]; /* previous amplitude spectrum (ERB) Q13*/ Word16 dtfs_dec_Q; /*Q0*/ /* NELP decoder variables */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float bp1_filt_mem_nb_dec[14]; +#endif Word32 bp1_filt_mem_nb_dec_fx[14]; /* qfm currently Q0*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float bp1_filt_mem_wb_dec[8]; +#endif Word16 bp1_filt_mem_wb_dec_fx[8]; /* qfm currently Q0*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float shape1_filt_mem_dec[20]; +#endif Word16 shape1_filt_mem_dec_fx[10]; /* qfm currently Q0*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float shape2_filt_mem_dec[20]; +#endif Word16 shape2_filt_mem_dec_fx[10]; /* qfm currently Q0*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float shape3_filt_mem_dec[20]; +#endif Word16 shape3_filt_mem_dec_fx[10]; /* qfm currently Q0*/ @@ -1078,7 +1199,9 @@ typedef struct hq_nbfec_structure int16_t prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ //Word16 prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float diff_energy; +#endif Word16 diff_energy_fx; int16_t stat_mode_out; @@ -1097,19 +1220,29 @@ typedef struct hq_nbfec_structure int16_t old_Min_ind; //Word16 old_Min_ind; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_auOut_2fr[L_FRAME8k * 2]; +#endif Word16 old_auOut_2fr_fx[L_FRAME8k * 2]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_out_pha[2][N_LEAD_NB]; /* FEC for HQ Core, 0-phase matching old_out, 1-overlapping original old_out and phase matching old_out*/ +#endif Word16 old_out_pha_fx[2][N_LEAD_NB]; /* FEC for HQ Core, 0-phase matching old_out, 1-overlapping original old_out and phase matching old_out*/ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float ynrm_values[MAX_SB_NB][MAX_PGF]; +#endif Word32 ynrm_values_fx[MAX_SB_NB][MAX_PGF]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float r_p_values[MAX_SB_NB][MAX_ROW]; +#endif Word32 r_p_values_fx[MAX_SB_NB][MAX_ROW]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float Norm_gain[SFM_N_NB]; +#endif Word16 Norm_gain_fx[SFM_N_NB]; /*Word16 old_hqswb_clas;*/ /* only used in inactive code, where it might probably be replaced by old_hqswb_clas_fx */ @@ -1119,7 +1252,9 @@ typedef struct hq_nbfec_structure int16_t HQ_FEC_seed; //Word16 HQ_FEC_seed; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float energy_MA_Curr[2]; +#endif Word16 energy_MA_Curr_fx[2]; int16_t prev_sign_switch[HQ_FEC_SIGN_SFM]; @@ -1128,13 +1263,19 @@ typedef struct hq_nbfec_structure int16_t prev_sign_switch_2[HQ_FEC_SIGN_SFM]; //Word16 prev_sign_switch_2[HQ_FEC_SIGN_SFM]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_coeffs[L_FRAME8k]; /* HQ core - old coefficients (for FEC) */ +#endif Word32 old_coeffs_fx[L_FRAME8k]; /* HQ core - old coefficients (for FEC) */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float oldIMDCTout[L_FRAME8k / 2]; +#endif Word32 oldIMDCTout_fx[L_FRAME8k / 2]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_oldauOut[L_FRAME8k]; +#endif Word16 prev_oldauOut_fx[L_FRAME8k]; @@ -1146,9 +1287,8 @@ typedef struct hq_nbfec_structure typedef struct hq_dec_structure { -#ifndef IVAS_DISABLE + float old_out[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ -#endif #ifdef IVAS_FLOAT_FIXED Word32 oldOut_fx[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ #endif @@ -1185,7 +1325,7 @@ typedef struct hq_dec_structure //int16_t no_att_hangover; Word16 no_att_hangover; /* Q0 */ -#ifndef IVAS_DISABLE +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float energy_lt; #endif Word32 energy_lt_fx; /* Q13 */ @@ -1193,7 +1333,7 @@ typedef struct hq_dec_structure //int16_t hq_generic_seed; Word16 hq_generic_seed; -#ifndef IVAS_DISABLE +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_noise_level[2]; #endif Word16 prev_noise_level_fx[2]; /* Q15 */ @@ -1204,9 +1344,7 @@ typedef struct hq_dec_structure //int16_t prev_R; /* the table of bit allocation of last frame */ Word16 prev_R; /* the table of bit allocation of last frame */ -#ifndef IVAS_DISABLE - float prev_coeff_out[L_HQ_WB_BWE]; /* the highest coefficients of last frame */ -#endif + float prev_coeff_out[L_HQ_WB_BWE]; /* the highest coefficients of last frame */ int16_t prev_SWB_peak_pos[SPT_SHORTEN_SBNUM]; Word32 prev_coeff_out_fx[L_HQ_WB_BWE]; /* Q12 */ /* the coefficients of last frame */ @@ -1219,40 +1357,62 @@ typedef struct hq_dec_structure float fer_samples[L_FRAME48k]; Word16 fer_samples_fx[L_FRAME48k]; Word16 Q_fer_samples; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_normq[SFM_N_WB]; /* previous norms */ +#endif Word32 prev_normq_fx[SFM_N_WB]; /* Q14 */ /* previous norms */ - + + +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_env[SFM_N_WB]; /* previous noise envelopes */ +#endif Word32 prev_env_fx[SFM_N_WB]; /* previous noise envelopes */ Word16 prev_env_Q[SFM_N_WB]; + +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float last_ni_gain[BANDS_MAX]; +#endif Word32 last_ni_gain_fx[BANDS_MAX]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float last_env[BANDS_MAX]; +#endif Word16 last_env_fx[BANDS_MAX]; //int16_t last_max_pos_pulse; Word16 last_max_pos_pulse; /* pre-echo reduction */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float memfilt_lb; +#endif Word16 memfilt_lb_fx; /* Q0 */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mean_prev_hb; +#endif Word32 mean_prev_hb_fx; /* Q0 */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float smoothmem; +#endif Word16 smoothmem_fx; /* Q15 */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mean_prev; +#endif Word32 mean_prev_fx; /* Q0 */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mean_prev_nc; +#endif Word32 mean_prev_nc_fx; /* Q0 */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float wmold_hb; +#endif Word16 wmold_hb_fx; /* Q15 */ int16_t prevflag; @@ -1266,13 +1426,16 @@ typedef struct hq_dec_structure //int16_t prev_stab_hfe2; Word16 prev_stab_hfe2; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_ni_ratio; +#endif Word16 prev_ni_ratio_fx; /* 15 */ - + +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_En_sb[NB_SWB_SUBBANDS]; +#endif Word16 prev_En_sb_fx[NB_SWB_SUBBANDS]; /* QsEn(4) */ - /*----------------------------------------------------------------------------------* * HQ FEC *----------------------------------------------------------------------------------*/ @@ -1281,7 +1444,9 @@ typedef struct hq_dec_structure //int16_t time_offs; Word16 time_offs; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float X_sav[PH_ECU_SPEC_SIZE]; +#endif Word16 X_sav_fx[PH_ECU_SPEC_SIZE]; Word16 Q_X_sav; @@ -1292,10 +1457,14 @@ typedef struct hq_dec_structure //int16_t plocs[MAX_PLOCS]; Word16 plocs[MAX_PLOCS]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float plocsi[MAX_PLOCS]; +#endif Word32 plocsi_fx[MAX_PLOCS]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float env_stab; +#endif Word16 env_stab_fx; //int16_t mem_norm_hqfec[SFM_N_ENV_STAB]; @@ -1304,22 +1473,32 @@ typedef struct hq_dec_structure //int16_t mem_env_delta_hqfec; Word16 mem_env_delta_hqfec; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float env_stab_plc; +#endif Word16 env_stab_plc_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float env_stab_state_p[NUM_ENV_STAB_PLC_STATES]; +#endif Word16 env_stab_state_p_fx[NUM_ENV_STAB_PLC_STATES]; //int16_t envstabplc_hocnt; Word16 envstabplc_hocnt; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mag_chg_1st[LGW_MAX]; /* i/o: per band magnitude modifier for transients*/ +#endif Word16 mag_chg_1st_fx[LGW_MAX]; /* i/o: per band magnitude modifier for transients*/ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float Xavg[LGW_MAX]; /* Frequency group average gain to fade to */ +#endif Word16 Xavg_fx[LGW_MAX]; /* Frequency group average gain to fade to */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float beta_mute; /* Factor for long-term mute */ +#endif Word16 beta_mute_fx; /* Factor for long-term mute */ //int16_t last_fec; @@ -1331,7 +1510,9 @@ typedef struct hq_dec_structure //int16_t oldHqVoicing; Word16 oldHqVoicing; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float oldgapsynth[L_FRAME48k]; +#endif Word16 oldgapsynth_fx[L_FRAME48k]; //int16_t ph_ecu_active; /* Set to 1 if Phase ECU was used in last bad frame; Set to 2 if TCX TD PLC was used */ @@ -1354,22 +1535,28 @@ typedef struct zero_bwe_dec_structure { int16_t seed2; /* HF (6-7kHz) BWE - seed for random signal generator */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mem_hp400[4]; /* HF (6-7kHz) BWE - hp400 filter memory */ - Word16 mem_hp400_fx[6]; /* HF (6-7kHz) BWE - hp400 filter memory */ float mem_hf[( L_FIR - 1 )]; /* HF (6-7kHz) BWE - band-pass filter memory */ - Word16 mem_hf_fx[2 * L_FILT16k]; /* HF (6-7kHz) BWE - band-pass filter memory Q(-2-memExp1)*/ float mem_syn_hf[M]; /* HF (6-7kHz) BWE - synthesis filter memory */ - Word16 mem_syn_hf_fx[M]; /* HF (6-7kHz) BWE - synthesis filter memory Q0*/ float delay_syn_hf[NS2SA( 16000, DELAY_CLDFB_NS )]; /* HF (6-7kHz) BWE - To synchronise BWE content with postfiltered synthesis */ - Word16 delay_syn_hf_fx[NS2SA(16000, DELAY_CLDFB_NS)]; /* HF (6-7kHz) BWE - To synchronise BWE content with postfiltered synthesis Q0*/ float mem_hp_interp[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */ - Word16 mem_hp_interp_fx[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */ +#endif + Word16 mem_hp400_fx[6]; /* HF (6-7kHz) BWE - hp400 filter memory */ + Word16 q_mem_hp400_fx; + Word16 mem_hf_fx[2 * L_FILT16k]; /* HF (6-7kHz) BWE - band-pass filter memory Q(-2-memExp1)*/ + + Word16 mem_syn_hf_fx[M]; /* HF (6-7kHz) BWE - synthesis filter memory Q0*/ + + Word16 delay_syn_hf_fx[NS2SA(16000, DELAY_CLDFB_NS)]; /* HF (6-7kHz) BWE - To synchronise BWE content with postfiltered synthesis Q0*/ + + Word16 mem_hp_interp_fx[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */ } ZERO_BWE_DEC_DATA, *ZERO_BWE_DEC_HANDLE; @@ -1381,14 +1568,20 @@ typedef struct zero_bwe_dec_structure typedef struct td_bwe_dec_structure { /* states for the filters used in generating SHB excitation from WB excitation */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float state_lpc_syn[LPC_SHB_ORDER]; +#endif Word16 state_lpc_syn_fx[LPC_SHB_ORDER]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mem_csfilt[2]; +#endif Word32 mem_csfilt_fx[2]; /* states for the filters used in generating SHB signal from SHB excitation*/ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float state_syn_shbexc[L_SHB_LAHEAD]; +#endif Word16 state_syn_shbexc_fx[L_SHB_LAHEAD]; float syn_overlap[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ @@ -1396,26 +1589,38 @@ typedef struct td_bwe_dec_structure Word32 syn_overlap_fx_32[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ /* previous frame parameters for frame error concealment */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float lsp_prevfrm[LPC_SHB_ORDER]; +#endif Word16 lsp_prevfrm_fx[LPC_SHB_ORDER]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float GainFrame_prevfrm; +#endif Word32 GainFrame_prevfrm_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float GainShape_Delay[NUM_SHB_SUBFR / 2]; +#endif Word16 GainShape_Delay_fx[NUM_SHB_SUBFR / 2]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float GainAttn; +#endif Word16 GainAttn_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_bwe_exc[PIT16k_MAX * 2]; /* old excitation */ +#endif Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ int16_t bwe_seed[2]; //Word16 bwe_seed[2]; /*Q0*/ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float bwe_non_lin_prev_scale; +#endif Word32 bwe_non_lin_prev_scale_fx; float old_bwe_exc_extended[NL_BUFF_OFFSET]; @@ -1423,19 +1628,29 @@ typedef struct td_bwe_dec_structure +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float genSHBsynth_Hilbert_Mem[HILBERT_MEM_SIZE]; +#endif Word32 genSHBsynth_Hilbert_Mem_fx[HILBERT_MEM_SIZE]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mem_genSHBexc_filt_down_shb[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; +#endif Word16 mem_genSHBexc_filt_down_shb_fx[2 * ALLPASSSECTIONS_STEEP + 1]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mem_genSHBexc_filt_down_wb2[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; +#endif Word16 mem_genSHBexc_filt_down_wb2_fx[2 * ALLPASSSECTIONS_STEEP + 1]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mem_genSHBexc_filt_down_wb3[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; +#endif Word16 mem_genSHBexc_filt_down_wb3_fx[2 * ALLPASSSECTIONS_STEEP + 1]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float genSHBsynth_state_lsyn_filt_shb_local[2 * ALLPASSSECTIONS_STEEP]; +#endif Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[2 * ALLPASSSECTIONS_STEEP]; Word32 genSHBsynth_state_lsyn_filt_shb_local_fx_32[2 * ALLPASSSECTIONS_STEEP]; @@ -1457,33 +1672,49 @@ typedef struct td_bwe_dec_structure Word16 state_32and48k_WB_upsample_fx[2 * ALLPASSSECTIONS_STEEP]; /* !!! this memory in FLP is called mem_resamp_HB */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_pow_exc16kWhtnd; /* power of the LB excitation signal in the previous frame */ +#endif //Word16 prev_pow_exc16kWhtnd_fx; /* power of the LB excitation signal in the previous frame */ - Don't use this Word32 prev_pow_exc16kWhtnd_fx32; /* power of the LB excitation signal in the previous frame */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_mix_factor; /* mixing factor in the previous frame */ +#endif Word16 prev_mix_factor_fx; /* mixing factor in the previous frame */ int16_t syn_dm_phase; //Word16 syn_dm_phase; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float fbbwe_hpf_mem[4][4]; +#endif Word32 fbbwe_hpf_mem_fx[4][4]; Word16 fbbwe_hpf_mem_fx_Q[4]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_wb_bwe_frame_pow; +#endif Word32 prev_wb_bwe_frame_pow_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_swb_bwe_frame_pow; +#endif Word32 prev_swb_bwe_frame_pow_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_ener; +#endif Word32 prev_ener_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_GainShape; +#endif Word16 prev_GainShape_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float fb_state_lpc_syn[LPC_SHB_ORDER]; +#endif Word16 fb_state_lpc_syn_fx[LPC_SHB_ORDER]; //Word16 prev_Q_bwe_exc_fb; @@ -1491,49 +1722,77 @@ typedef struct td_bwe_dec_structure //Word16 prev_Q_bwe_exc; //Word16 prev_Q_synth; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float fb_tbe_demph; +#endif Word16 fb_tbe_demph_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_fbbwe_ratio; +#endif Word16 prev_fbbwe_ratio_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float tbe_demph; +#endif Word16 tbe_demph_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float tbe_premph; +#endif Word16 tbe_premph_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mem_stp_swb[LPC_SHB_ORDER]; +#endif Word16 mem_stp_swb_fx[LPC_SHB_ORDER]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float *ptr_mem_stp_swb; +#endif Word16* ptr_mem_stp_swb_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float gain_prec_swb; +#endif Word16 gain_prec_swb_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mem_zero_swb[LPC_SHB_ORDER]; +#endif Word16 mem_zero_swb_fx[LPC_SHB_ORDER]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float swb_lsp_prev_interp[LPC_SHB_ORDER]; +#endif Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev1_shb_ener_sf, prev2_shb_ener_sf, prev3_shb_ener_sf, prev_res_shb_gshape, prev_mixFactors; +#endif Word32 prev1_shb_ener_sf_fx, prev2_shb_ener_sf_fx, prev3_shb_ener_sf_fx; Word16 prev_res_shb_gshape_fx, prev_mixFactors_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float tilt_mem; /* Formant factor adaptation tilt smoothing memory */ +#endif Word16 tilt_mem_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_lsf_diff[LPC_SHB_ORDER - 2]; +#endif Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_tilt_para; +#endif Word16 prev_tilt_para_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float cur_sub_Aq[M + 1]; +#endif Word16 cur_sub_Aq_fx[M + 1]; @@ -1571,7 +1830,9 @@ typedef struct td_bwe_dec_structure int16_t idxGain; //Word16 idxGain; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_core_synth[L_FRAME16k]; +#endif Word16 old_core_synth_fx[L_FRAME16k]; float old_tbe_synth[L_SHB_TRANSITION_LENGTH]; @@ -1582,10 +1843,14 @@ typedef struct td_bwe_dec_structure Word16 int_3_over_2_tbemem_dec_fx[INTERP_3_2_MEM_LEN]; Word32 int_3_over_2_tbemem_dec_fx_32[INTERP_3_2_MEM_LEN]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_hb_synth[L_FRAME48k]; +#endif Word16 old_hb_synth_fx[L_FRAME48k]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float tilt_swb_fec; /* FEC - SWB TBE TILT */ +#endif Word16 tilt_swb_fec_fx; /* FEC - SWB TBE TILT */ Word16 prev_hb_synth_fx_exp; @@ -1601,28 +1866,40 @@ typedef struct fd_bwe_dec_structure { Word16 old_wtda_wb_fx_exp; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_wtda_swb[L_FRAME48k]; +#endif Word16 L_old_wtda_swb_fx[L_FRAME48k]; Word32 L_old_wtda_swb_fx32[L_FRAME48k]; Word16 old_wtda_swb_fx_exp; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_syn_12k8_16k[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; +#endif Word16 old_syn_12k8_16k_fx[NS2SA(16000, DELAY_FD_BWE_ENC_NS)]; /*Q_syn2-1*/ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mem_deemph_old_syn; +#endif Word16 mem_deemph_old_syn_fx; int16_t prev_mode; //Word16 prev_mode; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_SWB_fenv[SWB_FENV]; +#endif //Word16 prev_SWB_fenv_fx[SWB_FENV]; // Don't use this. Use prev_SWB_fenv_fx present in Decoder_State +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_Energy; +#endif Word16 prev_Energy_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_Energy_wb; +#endif Word32 prev_Energy_wb_fx; int16_t prev_L_swb_norm; @@ -1636,24 +1913,34 @@ typedef struct fd_bwe_dec_structure int16_t prev_frica_flag; //Word16 prev_frica_flag; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mem_imdct[L_FRAME48k]; +#endif Word16 mem_imdct_fx[L_FRAME48k]; Word16 mem_imdct_exp_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_td_energy; +#endif Word16 prev_td_energy_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_weight; +#endif Word16 prev_weight_fx; int16_t prev_flag; //Word16 prev_flag; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float last_wb_bwe_ener; +#endif //Word16 last_wb_bwe_ener_fx; // Don't use this. Use last_wb_bwe_ener_fx present in Decoder_State +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_fb_ener_adjust; +#endif //Word16 prev_fb_ener_adjust_fx; // Don't use this. Use prev_fb_ener_adjust_fx present in Decoder_State //Word16 prev_frame_pow_exp; @@ -1674,8 +1961,10 @@ typedef struct hr_swb_bwe_dec_structure int16_t bwe_highrate_seed; Word16 bwe_highrate_seed_fx; - + +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float t_audio_prev[2 * END_FREQ_BWE_FULL_FB / FRAMES_PER_SEC - NUM_NONTRANS_START_FREQ_COEF]; +#endif Word16 t_audio_prev_fx[2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_START_FREQ_COEF]; Word16 t_audio_prev_fx_exp[NUM_TIME_SWITCHING_BLOCKS]; @@ -1683,7 +1972,9 @@ typedef struct hr_swb_bwe_dec_structure int16_t old_is_transient_hr_bwe; Word16 old_is_transient_hr_bwe_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mem_EnergyLT; +#endif Word32 L_mem_EnergyLT_fx; Word16 mem_EnergyLT_fx_exp; @@ -1898,42 +2189,42 @@ typedef struct Decoder_State *----------------------------------------------------------------------------------*/ + + Word16 tilt_code_fx; /* tilt of code Q15*/ + +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_exc[L_EXC_MEM_DEC]; /* old excitation */ float lsp_old[M]; /* old LSP vector at the end of the frame */ float lsf_old[M]; /* old LSF vector at the end of the frame */ - float tilt_code; /* tilt of code */ - Word16 tilt_code_fx; /* tilt of code Q15*/ - - float mem_syn1[M]; /* synthesis filter memory (for core switching and FD BWE) */ + + float mem_syn1[M]; /* synthesis filter memory (for core switching and FD BWE) */ + float mem_syn2[M]; /* synthesis filter memory */ + float mem_syn3[M]; + + float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ + float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) */ + float mem_deemph; /* deemphasis filter memory */ +#endif // 0 + Word16 mem_syn1_fx[M]; /* synthesis filter memory (for core switching and FD BWE) */ - - float mem_syn2[M]; /* synthesis filter memory */ Word16 mem_syn2_fx[M]; /* synthesis filter memory Q_syn*/ - - float mem_syn3[M]; - Word16 mem_syn3_fx[M]; - - float mem_deemph; /* deemphasis filter memory */ + Word16 mem_syn3_fx[M]; + Word16 mem_deemph_fx; /* deemphasis filter memory Q_syn*/ - float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean)(Qx2.56) */ - float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) */ Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual)(Qx2.56)*/ - float stab_fac; /* LSF stability factor */ Word16 stab_fac_fx; /* LSF stability factor Q15*/ - float stab_fac_smooth; /* low-pass filtered stability factor */ Word16 stab_fac_smooth_fx; /* low-pass filtered stability factor Q15*/ int16_t last_coder_type; /* previous coder type */ //Word16 last_coder_type; /* previous coder type Q0*/ - float agc_mem2[2]; /* memory of AGC for saturation control */ Word16 agc_mem_fx[2]; /* memory of AGC for saturation control Q0*/ int16_t mid_lsf_int; @@ -1942,14 +2233,19 @@ typedef struct Decoder_State int16_t safety_net; //Word16 safety_net; - float stab_fac_smooth_lt; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float stab_fac; /* LSF stability factor */ + float stab_fac_smooth; /* low-pass filtered stability factor */ + float agc_mem2[2]; /* memory of AGC for saturation control */ + float stab_fac_smooth_lt; float log_energy_old; + float log_energy_diff_lt; +#endif #ifdef IVAS_FLOAT_FIXED Word32 log_energy_diff_lt_fx;/*In range of word16*//*Q-15*/ Word16 stab_fac_smooth_lt_fx;/*In range of word16*//*Q-15*/ Word32 log_energy_old_fx; #endif - float log_energy_diff_lt; Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ @@ -1971,10 +2267,12 @@ typedef struct Decoder_State GSC_DEC_HANDLE hGSCDec; - float gc_threshold; /* Noise enhancer - threshold for gain_code */ Word32 gc_threshold_fx; /* Noise enhancer - threshold for gain_code Q16*/ - float dispMem[8]; /* Noise enhancer - phase dispersion algorithm memory */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float gc_threshold; /* Noise enhancer - threshold for gain_code */ + float dispMem[8]; /* Noise enhancer - phase dispersion algorithm memory */ +#endif struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ ZERO_BWE_DEC_HANDLE hBWE_zero; /* HF (6-7kHz) BWE */ @@ -1988,21 +2286,23 @@ typedef struct Decoder_State int16_t act_count; /* Stationary noise UV modification - activation counter */ //Word16 act_count; /* Stationary noise UV modification - activation counter Q0*/ - float ge_sm; /* Stationary noise UV modification - smoothed excitation gain */ Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain Q(GE_SHIFT)*/ - float lspold_s[M]; /* Stationary noise UV modification - old LSP vector */ Word16 lspold_s_fx[M]; /* Stationary noise UV modification - old LSP vector Q15*/ int16_t noimix_seed; /* Stationary noise UV modification - mixture seed */ //Word16 noimix_seed; /* Stationary noise UV modification - mixture seed Q0*/ - float min_alpha; /* Stationary noise UV modification - minimum alpha */ Word16 min_alpha_fx; /* Stationary noise UV modification - minimum alpha Q15*/ Word16 Q_stat_noise; /* Q of Exc_pe */ - float exc_pe; /* Stationary noise UV modification - memory of the preemphasis filter */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float min_alpha; /* Stationary noise UV modification - minimum alpha */ + float lspold_s[M]; /* Stationary noise UV modification - old LSP vector */ + float ge_sm; /* Stationary noise UV modification - smoothed excitation gain */ + float exc_pe; /* Stationary noise UV modification - memory of the preemphasis filter */ +#endif // 0 Word16 exc_pe_fx; /* Stationary noise UV modification - scale (Q_stat_noise) */ Word16 Q_stat_noise_ge; /* Q of ge_sm_fx */ @@ -2019,29 +2319,33 @@ typedef struct Decoder_State int16_t seed; /* FEC - seed for random generator for excitation */ //Word16 seed_fx; /* FEC - seed for random generator for excitation Q0*/ - float lp_ener_bfi; /* FEC - long-term active-signal average energy */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float lp_ener_bfi; /* FEC - long-term active-signal average energy */ + float lp_ener; /* FEC - low-pass filtered energy */ +#endif int16_t last_good; /* FEC - clas of last good received */ - float lp_gainp; /* FEC - low-pass filtered pitch gain */ Word16 lp_gainp_fx; /* FEC - low-pass filtered pitch gain Q14 */ - float lp_gainc; /* FEC - low-pass filtered code gain */ Word16 lp_gainc_fx; /* FEC - low-pass filtered code gain Q3*/ - float lp_ener; /* FEC - low-pass filtered energy */ Word32 lp_ener_fx; /* FEC - low-pass filtered energy Q6*/ - float enr_old; /* FEC - energy of the concealed frame */ Word32 enr_old_fx; /* FEC - energy of the concealed frame Q0*/ - float bfi_pitch; /* FEC - pitch for FEC */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float lp_gainp; /* FEC - low-pass filtered pitch gain */ + float lp_gainc; /* FEC - low-pass filtered code gain */ + float enr_old; /* FEC - energy of the concealed frame */ + float bfi_pitch; /* FEC - pitch for FEC */ + float old_pitch_buf[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values */ +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) Word16 bfi_pitch_fx; /* FEC - pitch for FEC */ int16_t bfi_pitch_frame; /* FEC - frame length when pitch for FEC is saved */ //Word16 bfi_pitch_frame_fx; /*FEC - frame length when pitch for FEC is saved Q0*/ - float old_pitch_buf[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values */ Word16 old_pitch_buf_16_fx[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values 15Q16 */ Word32 old_pitch_buf_fx[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values 15Q16 */ @@ -2050,25 +2354,28 @@ typedef struct Decoder_State int16_t scaling_flag; /* FEC - flag to indicate energy control of syn */ - float lp_ener_FEC_av_float; /* FEC - averaged voiced signal energy */ Word32 lp_ener_FEC_av; /* FEC - averaged voiced signal energy Q0 */ - float lp_ener_FEC_max_float; /* FEC - averaged voiced signal energy */ Word32 lp_ener_FEC_max; /* FEC - averaged voiced signal energy Q0 */ - float old_enr_LP_float; /* FEC - LP filter gain */ Word16 old_enr_LP; /* FEC - LP filter gain Q5*/ int16_t prev_nbLostCmpt; /* FEC - compt for number of consecutive lost frame at the previous frame*/ int16_t mode_lvq; /* FEC - index for LSF mean vector*/ - float lsfoldbfi0[M]; /* FEC - LSF vector of the previous frame */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float old_enr_LP_float; /* FEC - LP filter gain */ + float lp_ener_FEC_av_float; /* FEC - averaged voiced signal energy */ + float lp_ener_FEC_max_float; /* FEC - averaged voiced signal energy */ + float lsfoldbfi0[M]; /* FEC - LSF vector of the previous frame */ + float lsfoldbfi1[M]; /* FEC - LSF vector of the past previous frame */ + float lsf_adaptive_mean[M]; /* FEC - adaptive mean LSF vector for FEC */ +#endif + Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame (Qx2.56)*/ - float lsfoldbfi1[M]; /* FEC - LSF vector of the past previous frame */ Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame (Qx2.56) */ - float lsf_adaptive_mean[M]; /* FEC - adaptive mean LSF vector for FEC */ Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC (Qx2.56)*/ int16_t decision_hyst; /* FEC - hysteresis of the music/speech decision */ @@ -2083,7 +2390,9 @@ typedef struct Decoder_State int16_t relax_prev_lsf_interp; //Word16 relax_prev_lsf_interp; - float mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) Word16 mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ int16_t bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ @@ -2106,23 +2415,24 @@ typedef struct Decoder_State int16_t last_active_bandsToZero_bwdec; int16_t last_flag_filter_NB; - float perc_bwddec_float; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float perc_bwddec_float; + float avg_nrg_LT_float; + float ng_ener_ST; /* Noise gate - short-term energy */ +#endif // 0 Word16 perc_bwddec; /*Q14*/ int16_t active_frame_cnt_bwddec; int16_t flag_buffer[20]; int16_t total_frame_cnt_bwddec; - float avg_nrg_LT_float; Word32 avg_nrg_LT; - float ng_ener_ST; /* Noise gate - short-term energy */ Word16 Ng_ener_ST_fx; /* Noise gate - short-term energy Q8*/ int16_t last_L_frame; /* ACELP@16kHz - last value of st->L_frame */ //Word16 last_L_frame_fx; /* ACELP@16kHz - last value of st->L_frame */ - float mem_preemp_preQ; /* ACELP@16kHz - prequantizer preemhasis memory */ Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */ int16_t last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ @@ -2136,10 +2446,13 @@ typedef struct Decoder_State /* NB and formant post-filter */ PFSTAT_HANDLE hPFstat; /* NB and formant post-filter states */ - float psf_lp_noise; /* NB post-filter - long-term noise */ Word16 psf_lp_noise_fx; - float last_voice_factor; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float mem_preemp_preQ; /* ACELP@16kHz - prequantizer preemhasis memory */ + float psf_lp_noise; /* NB post-filter - long-term noise */ + float last_voice_factor; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) Word16 last_voice_factor_fx; /* Q6*/ float prev_synth_buffer[NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS )]; @@ -2167,7 +2480,9 @@ typedef struct Decoder_State int16_t CNG_mode; /* DTX/CNG - mode for DTX configuration */ //Word16 CNG_mode_fx; /* DTX/CNG - mode for DTX configuration */ - float lspCNG[M]; /* DTX/CNG - LP filtered ISPs */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float lspCNG[M]; /* DTX/CNG - LP filtered ISPs */ +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered ISPs Q15*/ int16_t active_cnt; @@ -2199,10 +2514,14 @@ typedef struct Decoder_State int16_t nelp_mode_dec; //Word16 nelp_mode_dec; /* Q0 */ - float prev_gain_pit_dec; Word16 prev_gain_pit_dec_fx; /*Q14*/ - float prev_tilt_code_dec; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float prev_gain_pit_dec; + float prev_tilt_code_dec; + float tilt_code_dec[NB_SUBFR16k]; +#endif + Word16 prev_tilt_code_dec_fx; /*Q15*/ int16_t vbr_hw_BWE_disable_dec; @@ -2215,7 +2534,6 @@ typedef struct Decoder_State * channel-aware mode *----------------------------------------------------------------------------------*/ - float tilt_code_dec[NB_SUBFR16k]; Word16 tilt_code_dec_fx[NB_SUBFR16k]; int16_t rf_frame_type; @@ -2256,25 +2574,28 @@ typedef struct Decoder_State int16_t last_L_frame_ori; //Word16 last_L_frame_ori_fx; - float previoussynth[L_FRAME48k]; /* note: only 60+111 out of 960 samples are needed in IVAS (for ACELP->TCX switching */ Word16 previoussynth_fx[L_FRAME48k]; Word32 previoussynth_fx_32[L_FRAME48k]; - float old_synth_sw[NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS )]; /* note: buffer used only in EVS mono */ + +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float previoussynth[L_FRAME48k]; /* note: only 60+111 out of 960 samples are needed in IVAS (for ACELP->TCX switching */ + float old_synth_sw[NS2SA(48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS)]; /* note: buffer used only in EVS mono */ +#endif // 0 Word16 old_synth_sw_fx[NS2SA(48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS)]; - float delay_buf_out[HQ_DELTA_MAX * HQ_DELAY_COMP]; Word16 delay_buf_out_fx[HQ_DELTA_MAX * HQ_DELAY_COMP]; /*Q0*/ Word32 delay_buf_out32_fx[HQ_DELTA_MAX * HQ_DELAY_COMP]; /*Q11*/ -#ifdef IVAS_FLOAT_FIXED - //Word16 exp_delay_buf_out; -#endif - float old_Aq_12_8[M + 1]; /* old Aq[] for core switching */ + Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */ Word32 old_Aq_12_8_fx_32[M + 1]; /* Q28 old Aq[] for core switching */ - float old_Es_pred; /* old Es_pred for core switching */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float delay_buf_out[HQ_DELTA_MAX * HQ_DELAY_COMP]; + float old_Aq_12_8[M + 1]; /* old Aq[] for core switching */ + float old_Es_pred; /* old Es_pred for core switching */ +#endif Word16 old_Es_pred_fx; /* old Es_pred for core switching */ // Word16 old_bfi_cnt; /* HQ core - # of bfi until previous frame(for FEC) */ @@ -2295,27 +2616,30 @@ typedef struct Decoder_State Word16 hb_prev_synth_buffer_fx[NS2SA(48000, DELAY_BWE_TOTAL_NS)]; /* WB/SWB bandwidth switching */ - float tilt_wb; Word16 tilt_wb_fx; - float tilt_swb; Word16 tilt_swb_fx; - float prev_ener_shb; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float tilt_wb; + float tilt_swb; + float prev_ener_shb; + float prev_enerLH; + float prev_enerLL; + + float enerLH; + float enerLL; +#endif Word16 prev_ener_shb_fx; - float enerLH; Word32 enerLH_fx; Word16 enerLH_fx_Q; - float prev_enerLH; Word32 prev_enerLH_fx; - float enerLL; Word32 enerLL_fx; Word16 enerLL_fx_Q; - float prev_enerLL; Word32 prev_enerLL_fx; int16_t prev_fractive; @@ -2330,7 +2654,10 @@ typedef struct Decoder_State int16_t bws_cnt1; // Word16 bws_cnt1; - float attenu1; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float attenu1; + float t_audio_q[L_FRAME]; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) Word16 attenu_fx; int16_t last_inner_frame; @@ -2339,7 +2666,6 @@ typedef struct Decoder_State int16_t last_bwidth; //Word16 last_bwidth_fx; - float t_audio_q[L_FRAME]; Word16 t_audio_q_fx[L_FRAME]; Word16 interpol_3_2_cng_dec_fx[INTERP_3_2_MEM_LEN]; @@ -2454,52 +2780,56 @@ typedef struct Decoder_State int16_t L_frame_past; int16_t L_frameTCX_past; - float lsfold_uw_float[M]; /* old lsf (unweighted) */ Word16 lsfold_uw[M]; /* old lsf (unweighted) */ - float lspold_uw_float[M]; /* old lsp (unweighted) */ Word16 lspold_uw[M]; /* old lsp (unweighted) */ int16_t seed_tcx_plc; /* seed memory (for random function in TCX PLC) */ - float past_gpit_float; /* past gain of pitch (for frame recovery) */ - Word16 past_gpit; /* past gain of pitch (for frame recovery) */ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float lsfold_uw_float[M]; /* old lsf (unweighted) */ + float lspold_uw_float[M]; /* old lsp (unweighted) */ + float past_gpit_float; /* past gain of pitch (for frame recovery) */ float past_gcode_float; /* past energy (!) of code (for frame recovery) */ + float lsf_cng_float[M]; /* lsf coefficients used for CNG generation (long term) */ + float lspold_cng_float[M]; /* lsp coefficients used for CNG generation (long term) */ + float lsp_q_cng_float[M]; /* lsp coefficients used for CNG generation (short term interpolated) */ + float old_lsp_q_cng_float[M]; /* lsp coefficients used for CNG generation (short term interpolated) */ + float lsf_q_cng_float[M]; /* lsf coefficients used for CNG generation (short term interpolated) */ + float old_lsf_q_cng_float[M]; /* lsf: old quantized lsfs for background noise */ + float Aq_cng_float[( NB_SUBFR16k + 1 ) * ( M + 1 )]; /* LPC coefficients derived from CNG estimate */ +#endif // 0 + + Word16 past_gpit; /* past gain of pitch (for frame recovery) */ Word32 past_gcode; /* past energy (!) of code (for frame recovery) */ /*15Q16*/ - float lsf_cng_float[M]; /* lsf coefficients used for CNG generation (long term) */ Word16 lsf_cng[M]; /* xSF coefficients used for CNG generation (long term) */ - float lspold_cng_float[M]; /* lsp coefficients used for CNG generation (long term) */ Word16 lspold_cng[M]; /* xSP coefficients used for CNG generation (long term) */ - float lsp_q_cng_float[M]; /* lsp coefficients used for CNG generation (short term interpolated) */ Word16 lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */ - float old_lsp_q_cng_float[M]; /* lsp coefficients used for CNG generation (short term interpolated) */ Word16 old_lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */ - float lsf_q_cng_float[M]; /* lsf coefficients used for CNG generation (short term interpolated) */ Word16 lsf_q_cng[M]; /* xSF coefficients used for CNG generation (short term interpolated) */ - float old_lsf_q_cng_float[M]; /* lsf: old quantized lsfs for background noise */ Word16 old_lsf_q_cng[M]; /* xSF: old quantized lsfs for background noise */ - float Aq_cng_float[( NB_SUBFR16k + 1 ) * ( M + 1 )]; /* LPC coefficients derived from CNG estimate */ Word16 Aq_cng[(NB_SUBFR16k + 1)*(M + 1)]; /* LPC coefficients derived from CNG estimate */ - float mem_syn_unv_back_float[M]; /* filter memory for unvoiced synth */ Word16 mem_syn_unv_back[M]; /* filter memory for unvoiced synth */ int16_t plcBackgroundNoiseUpdated; /* flag: Is background noise estimate updated? */ - float last_gain_syn_deemph_float; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float mem_syn_unv_back_float[M]; /* filter memory for unvoiced synth */ + float last_gain_syn_deemph_float; + float last_concealed_gain_syn_deemph_float; +#endif Word16 last_gain_syn_deemph; /*Q15*/ Word16 last_gain_syn_deemph_e; - float last_concealed_gain_syn_deemph_float; Word16 last_concealed_gain_syn_deemph; /*Q15*/ Word16 last_concealed_gain_syn_deemph_e; @@ -2521,31 +2851,42 @@ typedef struct Decoder_State int16_t pit_res_max_past; /*Preemphasis factor*/ - float preemph_fac_float; Word16 preemph_fac; /*0Q15*/ - float gamma_float; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + /*Preemphasis factor*/ + float preemph_fac_float; + + float gamma_float; + /*for AMR-WB like 6.4 to 7 kHz upsampling and noise filling*/ + float mem_Aq_float[NB_SUBFR16k * ( M + 1 )]; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + Word16 gamma; Word16 inv_gamma; /*for AMR-WB like 6.4 to 7 kHz upsampling and noise filling*/ - float mem_Aq_float[NB_SUBFR16k * ( M + 1 )]; Word16 mem_Aq[(NB_SUBFR16k)*(M + 1)]; /* Q12 */ /* Error concealment */ int16_t last_core_bfi; /* PLC - mode in previous frame */ int16_t nbLostCmpt; /* PLC - compt for number of consecutive lost frame */ - float old_fpitch_float; /* PLC - last pitch of previous frame (as transmitted) */ Word32 old_fpitch; /* last pitch of previous frame */ /*15Q16*/ - float old_fpitchFB_float; /* PLC - last pitch of previous FB frame (depends on output sr) */ Word32 old_fpitchFB; /* PLC - last pitch of previous FB frame (depends on output sr) */ /*15Q16*/ int16_t clas_dec; /* PLC - frame class at the decoder */ - float mem_pitch_gain_float[2 * NB_SUBFR16k + 2]; /* PLC - Pitch gain memory */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float old_fpitch_float; /* PLC - last pitch of previous frame (as transmitted) */ + float old_fpitchFB_float; /* PLC - last pitch of previous FB frame (depends on output sr) */ + float mem_pitch_gain_float[2 * NB_SUBFR16k + 2]; /* PLC - Pitch gain memory */ + + float cummulative_damping_float; + float cngTDLevel_float; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) Word16 mem_pitch_gain[2 * NB_SUBFR16k + 2]; /* Pitch gain memory Q14 */ int16_t plc_use_future_lag; /* PLC - flag indicating if info (pitch lag / pitch gain) about future frame is usable */ @@ -2554,12 +2895,9 @@ typedef struct Decoder_State Word32 Mode2_lp_gainp; /* 15Q16 low passed pitch gain used for concealment*/ - float cummulative_damping_float; Word16 cummulative_damping; /*Q15*/ - float cngTDLevel_float; Word16 cngTDLevel; - Word16 cngTDLevel_e; Word16 prev_widow_left_rect; @@ -2576,10 +2914,14 @@ typedef struct Decoder_State int16_t numlpc; /* Bandwidth */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float TcxBandwidth_float; +#endif Word16 TcxBandwidth; - float voice_fac_float; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float voice_fac_float; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) Word16 voice_fac; int16_t tcxonly; @@ -2595,7 +2937,9 @@ typedef struct Decoder_State int16_t second_last_core; /* parameters for switching */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mem_syn_r_float[L_SYN_MEM]; /*LPC synthesis memory needed for rate switching*/ +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) Word16 mem_syn_r[L_SYN_MEM]; /*LPC synthesis memory needed for rate switching*/ int16_t rate_switching_reset; @@ -2622,7 +2966,9 @@ typedef struct Decoder_State int16_t flag_cna; int16_t last_flag_cna; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float lp_noise_float; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) Word32 lp_noise; int16_t seed_acelp; diff --git a/lib_dec/stat_noise_uv_dec.c b/lib_dec/stat_noise_uv_dec.c index 58c40337d4b70e6ceab20fbf567b8a97867b2da0..ed0faa4b999894d7a5be7d575a4ff162db5f8a7c 100644 --- a/lib_dec/stat_noise_uv_dec.c +++ b/lib_dec/stat_noise_uv_dec.c @@ -38,7 +38,7 @@ #include "options.h" #include "prot.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*---------------------------------------------------------* * stat_noise_uv_dec() * @@ -107,3 +107,4 @@ void stat_noise_uv_dec( return; } +#endif diff --git a/lib_dec/swb_bwe_dec.c b/lib_dec/swb_bwe_dec.c index 823506ead54e3ada6f46fad62a46e046bc0c76d1..a4bea1d4737e136bf722df7b64818b548cfdd870 100644 --- a/lib_dec/swb_bwe_dec.c +++ b/lib_dec/swb_bwe_dec.c @@ -49,7 +49,7 @@ #include "prot_fx1.h" #endif // IVAS_FLOAT_FIXED - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * para_pred_bws() * @@ -218,7 +218,7 @@ static int16_t para_pred_bws( return mode; } - +#endif #ifdef IVAS_FLOAT_FIXED static @@ -531,6 +531,7 @@ static int16_t WB_BWE_gain_deq( return ( mode ); } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * wb_bwe_dec_flt() * @@ -640,6 +641,7 @@ void wb_bwe_dec_flt( return; } +#endif /*-------------------------------------------------------------------* * swb_bwe_gain_deq_flt() @@ -845,7 +847,7 @@ int16_t swb_bwe_gain_deq_flt( * * SWB BWE decoder *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void swb_bwe_dec_flt( Decoder_State *st, /* i/o: decoder state structure */ const float output[], /* i : synthesis @internal Fs */ @@ -1051,7 +1053,7 @@ void swb_bwe_dec_flt( return; } - +#endif #ifdef IVAS_FLOAT_FIXED @@ -1351,6 +1353,7 @@ Word16 swb_bwe_dec_fx32( #endif // IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * fd_bwe_dec_init_flt() * @@ -1382,6 +1385,7 @@ void fd_bwe_dec_init_flt( return; } +#endif #ifdef IVAS_FLOAT_FIXED void fd_bwe_dec_init_fx( diff --git a/lib_dec/swb_bwe_dec_hr.c b/lib_dec/swb_bwe_dec_hr.c index 8c0b1b2fd65b9a6442c321d007e5f06a6e253fa4..d4b1847663fb52117501394a5b1db07dbeddc587 100644 --- a/lib_dec/swb_bwe_dec_hr.c +++ b/lib_dec/swb_bwe_dec_hr.c @@ -49,7 +49,7 @@ * * HR SWB BWE decoder *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void swb_bwe_dec_hr( Decoder_State *st, /* i/o: decoder state structure */ const float *syn_12k8_16k, /* i : ACELP core synthesis @16kHz */ @@ -824,3 +824,4 @@ void hr_bwe_dec_init_flt( return; } +#endif diff --git a/lib_dec/swb_bwe_dec_lr.c b/lib_dec/swb_bwe_dec_lr.c index 5a22500afc3bd21285788025d41fa867a1efbb5e..f7d7fc0439f49d8538ae27525ecb1063e769b351 100644 --- a/lib_dec/swb_bwe_dec_lr.c +++ b/lib_dec/swb_bwe_dec_lr.c @@ -84,7 +84,7 @@ static void DecodeSWBGenericParameters( return; } - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * DecodeSWBSubbands() * @@ -234,8 +234,9 @@ static void DecodeSWBSubbands( return; } +#endif - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * swb_bwe_dec_lr() * @@ -304,3 +305,4 @@ void swb_bwe_dec_lr( return; } +#endif \ No newline at end of file diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index 2a6858056aed079e0bf5226449bdc93e97d1c6af..d8482b2efc33ca2d6658df56e13f253d26c87a00 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -45,6 +45,9 @@ #include "rom_dec.h" #include "wmc_auto.h" #include "ivas_prot.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif /*-----------------------------------------------------------------* * Local function prototypes @@ -68,6 +71,7 @@ void ResetSHBbuffer_Dec( ) { int16_t i; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float f; float inc; @@ -89,7 +93,7 @@ void ResetSHBbuffer_Dec( set_f( hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD ); set_f( hBWE_TD->state_lpc_syn, 0, LPC_SHB_ORDER ); - if ( extl == FB_TBE ) + if (extl == FB_TBE) { set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph = 0; @@ -97,9 +101,47 @@ void ResetSHBbuffer_Dec( } /* states for the filters used in generating SHB signal from SHB excitation in wideband*/ - set_f( hBWE_TD->mem_genSHBexc_filt_down_shb, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set_f( hBWE_TD->mem_genSHBexc_filt_down_wb2, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set_f( hBWE_TD->mem_genSHBexc_filt_down_wb3, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set_f(hBWE_TD->mem_genSHBexc_filt_down_shb, 0.0f, (2 * ALLPASSSECTIONS_STEEP + 1)); + set_f(hBWE_TD->mem_genSHBexc_filt_down_wb2, 0.0f, (2 * ALLPASSSECTIONS_STEEP + 1)); + set_f(hBWE_TD->mem_genSHBexc_filt_down_wb3, 0.0f, (2 * ALLPASSSECTIONS_STEEP + 1)); +#endif +#ifdef IVAS_FLOAT_FIXED + Word16 f_fx; + Word16 inc_fx; + IF( extl != WB_TBE ) + { + f_fx = 1489; + move16(); /* Q15 */ + inc_fx = 1489; + move16(); /* Q15 */ + } + ELSE + { + f_fx = 5461; + move16();/* Q15 */ + inc_fx = 5461; + move16(); /* Q15 */ + } + + /* states for the filters used in generating SHB excitation from WB excitation*/ + set_val_Word32( hBWE_TD->mem_csfilt_fx, 0, 2 ); + + /* states for the filters used in generating SHB signal from SHB excitation*/ + set_val_Word16( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); + set_val_Word16( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + + IF ( extl == FB_TBE ) + { + set_val_Word16( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 0; + fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx ); + } + + /* states for the filters used in generating SHB signal from SHB excitation in wideband*/ + set_val_Word16( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set_val_Word16( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set_val_Word16( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); +#endif set_f( hBWE_TD->state_lsyn_filt_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); set_f( hBWE_TD->state_lsyn_filt_dwn_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); @@ -108,6 +150,7 @@ void ResetSHBbuffer_Dec( /* States for the local synthesis filters */ set_f( hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /* States for FEC */ if ( extl != WB_TBE ) { @@ -136,17 +179,62 @@ void ResetSHBbuffer_Dec( hBWE_TD->tbe_premph = 0.0f; set_f( hBWE_TD->mem_stp_swb, 0, LPC_SHB_ORDER ); hBWE_TD->gain_prec_swb = 1.0f; - set_f( hBWE_TD->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 ); + set_f(hBWE_TD->GainShape_Delay, 0, NUM_SHB_SUBFR / 2); hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; hBWE_TD->prev_mix_factor = 1.0f; - set_f( hBWE_TD->old_core_synth, 0, L_FRAME16k ); + set_f(hBWE_TD->old_core_synth, 0, L_FRAME16k); +#endif +#ifdef IVAS_FLOAT_FIXED + IF( extl != WB_TBE ) + { + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + move16(); /*Q15*/ + f_fx = add( f_fx, inc_fx ); + move16(); + } + } + ELSE + { + FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) + { + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + move16();/*Q15*/ + f_fx = add( f_fx, inc_fx ); + move16(); + } + FOR( ; ilsp_prevfrm_fx[i] = 0; + move16(); + } + } + + hBWE_TD->GainFrame_prevfrm_fx = 0; + hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->tbe_demph_fx = 0; + hBWE_TD->tbe_premph_fx = 0; + set_val_Word16( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->gain_prec_swb_fx = 16384; + set_val_Word16( hBWE_TD->GainShape_Delay_fx, 0, NUM_SHB_SUBFR / 2 ); + hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /* Q0 1.f */ + hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 1.f*/ + set16_fx( hBWE_TD->old_core_synth_fx, 0, L_FRAME16k ); +#endif + set_f( hBWE_TD->old_tbe_synth, 0, L_SHB_TRANSITION_LENGTH ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hBWE_TD->tilt_swb_fec = 0.0f; +#endif +#ifdef IVAS_FLOAT_FIXED + hBWE_TD->tilt_swb_fec_fx = 0; +#endif return; } - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * wb_tbe_dec() * @@ -445,7 +533,7 @@ void wb_tbe_dec( return; } - +#endif void calc_tilt_bwe_fx_loc( const Word32 *sp_fx, /* i : input signal */ Word32 *tilt_fx, /* o : signal tilt */ @@ -2630,7 +2718,7 @@ void ivas_swb_tbe_dec_fx( return; } #endif - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * swb_tbe_dec() * @@ -3720,7 +3808,7 @@ void swb_tbe_dec( return; } - +#endif /*-------------------------------------------------------------------* * Dequant_lower_LSF() * @@ -4149,6 +4237,7 @@ static void dequantizeSHBparams( } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * fb_tbe_dec() * @@ -4216,6 +4305,7 @@ void fb_tbe_dec( return; } +#endif /*---------------------------------------------------------------------* @@ -4307,6 +4397,7 @@ void tbe_read_bitstream( } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*---------------------------------------------------------------------* * GenTransition() * @@ -4370,6 +4461,7 @@ void GenTransition( return; } +#endif #ifdef IVAS_FLOAT_FIXED void GenTransition_fixed( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ @@ -4555,40 +4647,89 @@ void TBEreset_dec( if ( st->last_core != ACELP_CORE ) { +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( hBWE_TD->old_bwe_exc, 0.0f, PIT16k_MAX * 2 ); hBWE_TD->bwe_non_lin_prev_scale = 0.f; +#endif +#ifdef IVAS_FLOAT_FIXED + set_val_Word16( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + st->prev_Q_bwe_exc = 31; +#endif } if ( st->bwidth == WB ) { +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) wb_tbe_extras_reset( hBWE_TD->mem_genSHBexc_filt_down_wb2, hBWE_TD->mem_genSHBexc_filt_down_wb3 ); +#endif +#ifdef IVAS_FLOAT_FIXED + wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); +#endif wb_tbe_extras_reset_synth( hBWE_TD->state_lsyn_filt_shb, hBWE_TD->state_lsyn_filt_dwn_shb, hBWE_TD->mem_resamp_HB ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( hBWE_TD->mem_genSHBexc_filt_down_shb, 0, 7 ); set_f( hBWE_TD->state_lpc_syn, 0, 10 ); set_f( hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD / 4 ); +#endif +#ifdef IVAS_FLOAT_FIXED + set_val_Word16( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set_val_Word16( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set_val_Word16( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); +#endif set_f( hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( hBWE_TD->mem_csfilt, 0, 2 ); +#endif +#ifdef IVAS_FLOAT_FIXED + set_val_Word32( hBWE_TD->mem_csfilt_fx, 0, 2 ); +#endif } else if ( st->bwidth == SWB || st->bwidth == FB ) { +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) swb_tbe_reset( hBWE_TD->mem_csfilt, hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->state_lpc_syn, hBWE_TD->syn_overlap, hBWE_TD->state_syn_shbexc, &( hBWE_TD->tbe_demph ), &( hBWE_TD->tbe_premph ), hBWE_TD->mem_stp_swb, &( hBWE_TD->gain_prec_swb ) ); set_f( hBWE_TD->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 ); +#endif +#ifdef IVAS_FLOAT_FIXED + swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); + + set_val_Word16( hBWE_TD->GainShape_Delay_fx, 0, NUM_SHB_SUBFR / 2 ); +#endif + set_f( hBWE_TD->int_3_over_2_tbemem_dec, 0.f, INTERP_3_2_MEM_LEN ); set_f( hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; hBWE_TD->prev_mix_factor = 1.0f; swb_tbe_reset_synth( hBWE_TD->genSHBsynth_Hilbert_Mem, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local ); +#endif +#ifdef IVAS_FLOAT_FIXED + hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /* Q0 1.f */ + hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 1.f*/ + + swb_tbe_reset_synth_ivas_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32 ); +#endif if ( st->bwidth == FB ) { if ( st->hBWE_FD != NULL ) { +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) st->hBWE_FD->prev_fb_ener_adjust = 0.0f; +#endif } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph = 0; fb_tbe_reset_synth( hBWE_TD->fbbwe_hpf_mem, &hBWE_TD->prev_fbbwe_ratio ); +#endif +#ifdef IVAS_FLOAT_FIXED + set_val_Word16( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 0; + fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx ); +#endif } } @@ -4610,23 +4751,45 @@ void td_bwe_dec_init( int16_t i; /* init. SHB buffers */; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( hBWE_TD->old_bwe_exc, 0.0f, ( PIT16k_MAX * 2 ) ); +#endif +#ifdef IVAS_FLOAT_FIXED + set_val_Word16( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); +#endif hBWE_TD->bwe_seed[0] = 23; /* 1; */ hBWE_TD->bwe_seed[1] = 59; /* 10000; */ set_f( hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hBWE_TD->bwe_non_lin_prev_scale = 0; - set_f( hBWE_TD->genSHBsynth_Hilbert_Mem, 0.0f, HILBERT_MEM_SIZE ); - set_f( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 0.0f, 2 * ALLPASSSECTIONS_STEEP ); + set_f(hBWE_TD->genSHBsynth_Hilbert_Mem, 0.0f, HILBERT_MEM_SIZE); + set_f(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 0.0f, 2 * ALLPASSSECTIONS_STEEP); +#endif +#ifdef IVAS_FLOAT_FIXED + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + + set32_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, 0, HILBERT_MEM_SIZE ); + set16_fx( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); + set32_fx( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP ); +#endif hBWE_TD->syn_dm_phase = 0; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hBWE_TD->prev_fbbwe_ratio = 1.0f; hBWE_TD->prev_wb_bwe_frame_pow = 0.001f; hBWE_TD->prev_swb_bwe_frame_pow = 0.001f; +#endif +#ifdef IVAS_FLOAT_FIXED + hBWE_TD->prev_fbbwe_ratio_fx = 32767/*1.0f Q15*/; + hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; + hBWE_TD->prev_swb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; +#endif /* reset SHB buffers */ ResetSHBbuffer_Dec( hBWE_TD, extl ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if ( output_Fs == 48000 ) { set_f( hBWE_TD->fbbwe_hpf_mem[0], 0, 4 ); @@ -4634,19 +4797,41 @@ void td_bwe_dec_init( set_f( hBWE_TD->fbbwe_hpf_mem[2], 0, 4 ); set_f( hBWE_TD->fbbwe_hpf_mem[3], 0, 4 ); } +#endif +#ifdef IVAS_FLOAT_FIXED + IF(EQ_32(output_Fs, 48000)) + { + set32_fx(hBWE_TD->fbbwe_hpf_mem_fx[0], 0, 4); + set32_fx(hBWE_TD->fbbwe_hpf_mem_fx[1], 0, 4); + set32_fx(hBWE_TD->fbbwe_hpf_mem_fx[2], 0, 4); + set32_fx(hBWE_TD->fbbwe_hpf_mem_fx[3], 0, 4); + set16_fx(hBWE_TD->fbbwe_hpf_mem_fx_Q, 0, 4); + } +#endif set_f( hBWE_TD->mem_resamp_HB, 0, INTERP_3_1_MEM_LEN ); set32_fx( hBWE_TD->mem_resamp_HB_fx_32, 0, INTERP_3_1_MEM_LEN ); set_f( hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); set32_fx( hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hBWE_TD->tilt_mem = 0.0f; set_f( hBWE_TD->prev_lsf_diff, 0.5f, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para = 0.0f; set_f( hBWE_TD->cur_sub_Aq, 0.0f, M + 1 ); +#endif +#ifdef IVAS_FLOAT_FIXED + hBWE_TD->tilt_mem_fx = 0; + set16_fx(hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2); + hBWE_TD->prev_tilt_para_fx = 0; + set16_fx(hBWE_TD->cur_sub_Aq_fx, 0, M + 1); +#endif + + set_f( hBWE_TD->int_3_over_2_tbemem_dec, 0.0f, INTERP_3_2_MEM_LEN ); /* TD BWE post-processing */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hBWE_TD->ptr_mem_stp_swb = hBWE_TD->mem_stp_swb + LPC_SHB_ORDER - 1; set_f( hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER ); @@ -4661,14 +4846,40 @@ void td_bwe_dec_init( hBWE_TD->prev_res_shb_gshape = 0.125f; hBWE_TD->prev_mixFactors = 0.5f; hBWE_TD->prev_GainShape = 0.0f; - set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); - hBWE_TD->fb_tbe_demph = 0.0f; - set_f( hBWE_TD->old_hb_synth, 0, L_FRAME48k ); + set_f(hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER); + hBWE_TD->fb_tbe_demph = 0.0f; + set_f(hBWE_TD->old_hb_synth, 0, L_FRAME48k); hBWE_TD->GainFrame_prevfrm = 0.0f; hBWE_TD->prev_ener = 0.0f; +#endif +#ifdef IVAS_FLOAT_FIXED + hBWE_TD->ptr_mem_stp_swb_fx = hBWE_TD->mem_stp_swb_fx + LPC_SHB_ORDER - 1; + set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); + + FOR(i = 0; i < LPC_SHB_ORDER; i++) + { + hBWE_TD->swb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; + move16(); + } + + hBWE_TD->prev1_shb_ener_sf_fx = 32767; + hBWE_TD->prev2_shb_ener_sf_fx = 32767; + hBWE_TD->prev3_shb_ener_sf_fx = 32767; + hBWE_TD->prev_res_shb_gshape_fx = 8192; + hBWE_TD->prev_mixFactors_fx = 16384; + hBWE_TD->prev_GainShape_fx = 0; + + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 0; + set16_fx( hBWE_TD->old_hb_synth_fx, 0, L_FRAME48k ); + + hBWE_TD->GainFrame_prevfrm_fx = 0; + + hBWE_TD->prev_ener_fx = 0; +#endif return; } \ No newline at end of file diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index e39a2dd719a6434b6e52543f4cd421bcd873bd52..70722637e5b22c5636e03cba9513af6c48962794 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -385,7 +385,50 @@ void rescale_genWB_mem( Decoder_State* st_fx, Word16 sf ) } +#ifdef IVAS_FLOAT_FIXED +void InitSWBdecBuffer_ivas_fx( + Decoder_State* st_fx /* i/o: SHB decoder structure */ +) +{ + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; + + set16_fx(hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); + hBWE_TD->bwe_seed[0] = 23; + move16(); + hBWE_TD->bwe_seed[1] = 59; + move16(); + + set16_fx(hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move16(); + set32_fx(hBWE_TD->genSHBsynth_Hilbert_Mem_fx, 0, HILBERT_MEM_SIZE ); + set16_fx(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2*ALLPASSSECTIONS_STEEP); /* Interp all pass memory */ + set32_fx(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 0, 2*ALLPASSSECTIONS_STEEP); /* Interp all pass memory */ + + hBWE_TD->syn_dm_phase = 0; + move16(); + hBWE_TD->prev_fbbwe_ratio_fx = 32767/*1.0f Q15*/; + + /* these are fd-bwe constants */ + hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; /* Q22 */ + hBWE_TD->prev_swb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; /* Q22 */ + st_fx->prev_Q_bwe_exc = 31; + move16(); + st_fx->prev_ener_fx_Q = 31; + move16(); + st_fx->prev_Qx = 0; + move16(); + st_fx->prev_frame_pow_exp = 0; + move16(); + st_fx->prev_Q_bwe_syn = 0; + move16(); + st_fx->prev_Q_bwe_syn2 = 0; + move16(); + return; +} +#endif void InitSWBdecBuffer_fx( Decoder_State* st_fx /* i/o: SHB decoder structure */ ) @@ -471,7 +514,9 @@ void ResetSHBbuffer_Dec_fx( Decoder_State* st_fx /* i/o: SHB encoder structure * set16_fx(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); set16_fx(hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); set16_fx(hBWE_TD->state_lsyn_filt_shb_fx,0, 2 * ALLPASSSECTIONS_STEEP ); + set32_fx(hBWE_TD->state_lsyn_filt_shb_fx_32,0, 2 * ALLPASSSECTIONS_STEEP ); set16_fx(hBWE_TD->state_lsyn_filt_dwn_shb_fx,0, 2 * ALLPASSSECTIONS_STEEP ); + set32_fx(hBWE_TD->state_lsyn_filt_dwn_shb_fx_32,0, 2 * ALLPASSSECTIONS_STEEP ); set16_fx(hBWE_TD->state_32and48k_WB_upsample_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); /* States for the local synthesis filters */ @@ -518,6 +563,7 @@ void ResetSHBbuffer_Dec_fx( Decoder_State* st_fx /* i/o: SHB encoder structure * set16_fx(hBWE_TD->old_core_synth_fx, 0, L_FRAME16k); set16_fx(hBWE_TD->old_tbe_synth_fx, 0, L_SHB_TRANSITION_LENGTH); + set32_fx(hBWE_TD->old_tbe_synth_fx_32, 0, L_SHB_TRANSITION_LENGTH); hBWE_TD->tilt_swb_fec_fx = 0; move16(); @@ -4863,7 +4909,9 @@ void TBEreset_dec_fx( set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR/2 ); set16_fx(hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN); + set32_fx(hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN); set16_fx(hBWE_TD->mem_resamp_HB_32k_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); + set32_fx(hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1); IF( EQ_16(bandwidth, FB)) { @@ -4911,10 +4959,13 @@ void TBEreset_dec_ivas_fx( set16_fx( st->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 ); set16_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN ); + set32_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN ); set16_fx( hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + set32_fx(hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1); hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /* Q0 1.f */ hBWE_TD->prev_mix_factor_fx = 32767; /* Q15 1.f */ - swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); + //swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); + swb_tbe_reset_synth_ivas_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32 ); IF( EQ_16( st->bwidth, FB ) ) @@ -4941,6 +4992,72 @@ void TBEreset_dec_ivas_fx( * Initialize TD BWE state structure at the decoder *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void td_bwe_dec_init_ivas_fx( + Decoder_State* st_fx, /* i/o: SHB decoder structure */ + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + const Word32 output_Fs /* i : output sampling rate */ +) +{ + int16_t i; + + /* init. SHB buffers */; + InitSWBdecBuffer_ivas_fx(st_fx); + + /* reset SHB buffers */ + ResetSHBbuffer_Dec_fx(st_fx); + IF(EQ_32(output_Fs, 48000)) + { + set32_fx(hBWE_TD->fbbwe_hpf_mem_fx[0], 0, 4); + set32_fx(hBWE_TD->fbbwe_hpf_mem_fx[1], 0, 4); + set32_fx(hBWE_TD->fbbwe_hpf_mem_fx[2], 0, 4); + set32_fx(hBWE_TD->fbbwe_hpf_mem_fx[3], 0, 4); + set16_fx(hBWE_TD->fbbwe_hpf_mem_fx_Q, 0, 4); + } + + set16_fx(hBWE_TD->mem_resamp_HB_fx, 0, INTERP_3_1_MEM_LEN); + set32_fx(hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1); + set16_fx(hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1); + set32_fx(hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1); + + hBWE_TD->tilt_mem_fx = 0; + move16(); + set16_fx(hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2); + hBWE_TD->prev_tilt_para_fx = 0; + move16(); + set16_fx(hBWE_TD->cur_sub_Aq_fx, 0, M + 1); + set16_fx(hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN); + set32_fx(hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN); + /* TD BWE post-processing */ + hBWE_TD->ptr_mem_stp_swb_fx = hBWE_TD->mem_stp_swb_fx + LPC_SHB_ORDER - 1; + set16_fx(hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER); + + FOR(i = 0; i < LPC_SHB_ORDER; i++) + { + hBWE_TD->swb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; + move16(); + } + + hBWE_TD->prev1_shb_ener_sf_fx = 32767; /* Q15*/ move16(); + hBWE_TD->prev2_shb_ener_sf_fx = 32767; /* Q15*/ move16(); + hBWE_TD->prev3_shb_ener_sf_fx = 32767; /* Q15*/ move16(); + hBWE_TD->prev_res_shb_gshape_fx = 8192; /* 0.125 in Q14*/ move16(); + hBWE_TD->prev_mixFactors_fx = 16384; /* 0.5 in Q15*/ move16(); + hBWE_TD->prev_GainShape_fx = 0; + move16(); + st_fx->prev_Q_bwe_exc_fb = 51; + move16(); + set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER); + hBWE_TD->fb_tbe_demph_fx = 0; + move16(); + + set16_fx(hBWE_TD->old_hb_synth_fx, 0, L_FRAME48k); + + hBWE_TD->prev_ener_fx = L_deposit_l(0); + + return; +} +#endif void td_bwe_dec_init_fx( Decoder_State* st_fx, /* i/o: SHB decoder structure */ TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ @@ -4967,7 +5084,9 @@ void td_bwe_dec_init_fx( } set16_fx(hBWE_TD->mem_resamp_HB_fx, 0, INTERP_3_1_MEM_LEN); + set32_fx(hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1); set16_fx(hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1); + set32_fx(hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1); hBWE_TD->tilt_mem_fx = 0; move16(); @@ -4976,7 +5095,7 @@ void td_bwe_dec_init_fx( move16(); set16_fx(hBWE_TD->cur_sub_Aq_fx, 0, M + 1); set16_fx(hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN); - + set32_fx(hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN); /* TD BWE post-processing */ hBWE_TD->ptr_mem_stp_swb_fx = hBWE_TD->mem_stp_swb_fx + LPC_SHB_ORDER - 1; set16_fx(hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER); diff --git a/lib_dec/tcx_utils_dec.c b/lib_dec/tcx_utils_dec.c index 6b970918e6f6dbb3e80e07d5005aa78714cce143..4d2cda73528aec545ae5ff0f3f517e643f3992ed 100644 --- a/lib_dec/tcx_utils_dec.c +++ b/lib_dec/tcx_utils_dec.c @@ -47,7 +47,7 @@ * * *--------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void tcx_decoder_memory_update_flt( Decoder_State *st, /* i/o: decoder memory state */ const float *xn_buf, /* i/o: mdct output buffer used also as temporary buffer */ @@ -298,3 +298,4 @@ int16_t tcx_res_invQ_spec_flt( return bits; } +#endif diff --git a/lib_dec/tonalMDCTconcealment.c b/lib_dec/tonalMDCTconcealment.c index 0d488de8875fdd077b45c49927a77a6fc4c03bb1..0acc63ef7bf5fc4c11f77e3b53dfe8c00cc08c02 100644 --- a/lib_dec/tonalMDCTconcealment.c +++ b/lib_dec/tonalMDCTconcealment.c @@ -82,9 +82,11 @@ ivas_error TonalMDCTConceal_Init_ivas( hTonalMDCTConc->lastBlockData.blockIsConcealed = 0; hTonalMDCTConc->secondLastBlockData.blockIsConcealed = 0; - hTonalMDCTConc->pTCI_float = (TonalComponentsInfo_float *) hTonalMDCTConc->timeDataBuffer_float; + hTonalMDCTConc->pTCI = (TonalComponentsInfo *) hTonalMDCTConc->timeDataBuffer_float; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hTonalMDCTConc->lastPitchLag_float = 0; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if ( hTonalMDCTConc->nSamples != nSamples ) { @@ -96,16 +98,18 @@ ivas_error TonalMDCTConceal_Init_ivas( hTonalMDCTConc->nScaleFactors = nScaleFactors; set_zero( hTonalMDCTConc->scaleFactorsBackground_flt, FDNS_NPTS ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hTonalMDCTConc->scf_fadeout_flt = 1.0f; +#endif PsychoacousticParameters_Init( INT_FS_16k, L_FRAME16k, 64, 1, 1, &hTonalMDCTConc->psychParamsTCX20 ); PsychoacousticParameters_Init( INT_FS_16k, L_FRAME16k / 2, 64, 0, 1, &hTonalMDCTConc->psychParamsTCX10 ); hTonalMDCTConc->psychParams = NULL; - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hTonalMDCTConc->last_block_nrg_flt = 0.0f; hTonalMDCTConc->curr_noise_nrg_flt = 0.0f; hTonalMDCTConc->faded_signal_nrg_flt = 0.0f; - - /* Offset the pointer to the end of buffer, so that pTCI_float is not destroyed when +#endif + /* Offset the pointer to the end of buffer, so that pTCI is not destroyed when new time samples are stored in lastPcmOut */ /* just the second half of the second last pcm output is needed */ hTonalMDCTConc->secondLastPcmOut_float = &hTonalMDCTConc->timeDataBuffer_float[( 3 * L_FRAME_MAX ) / 2 - ( 3 * min( L_FRAME_MAX, nSamples ) ) / 2]; @@ -113,12 +117,12 @@ ivas_error TonalMDCTConceal_Init_ivas( /* If the second last frame was lost and concealed with tonal PLC, we reuse saved TonalComponentsInfo and don't update pcm buffers */ - assert( sizeof( *hTonalMDCTConc->pTCI_float ) <= ( hTonalMDCTConc->lastPcmOut_float - hTonalMDCTConc->timeDataBuffer_float) * sizeof( hTonalMDCTConc->timeDataBuffer_float[0] ) ); + assert( sizeof( *hTonalMDCTConc->pTCI ) <= ( hTonalMDCTConc->lastPcmOut_float - hTonalMDCTConc->timeDataBuffer_float) * sizeof( hTonalMDCTConc->timeDataBuffer_float[0] ) ); return IVAS_ERR_OK; } - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void TonalMDCTConceal_SaveFreqSignal_ivas( TonalMDCTConcealPtr hTonalMDCTConc, const float *mdctSpectrum, @@ -219,7 +223,7 @@ void TonalMDCTConceal_UpdateState_ivas( return; } - +#endif static void FindPhases( const TonalMDCTConcealPtr hTonalMDCTConc, @@ -230,11 +234,11 @@ static void FindPhases( int16_t l; float *pCurrentPhase; - pCurrentPhase = hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float; + pCurrentPhase = hTonalMDCTConc->pTCI->phase_currentFramePredicted_float; /* for each index/index group */ - for ( i = 0; i < hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + for ( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - for ( l = hTonalMDCTConc->pTCI_float->lowerIndex[i]; l <= hTonalMDCTConc->pTCI_float->upperIndex[i]; l++ ) + for ( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { *pCurrentPhase++ = (float) atan2( secondLastMDST[l], secondLastMDCT[l] ); } @@ -262,10 +266,10 @@ static void FindPhaseDifferences( float fractional; float Q, a; - phaseDiff = hTonalMDCTConc->pTCI_float->phaseDiff_float; - for ( i = 0; i < hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + phaseDiff = hTonalMDCTConc->pTCI->phaseDiff_float; + for ( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - k = hTonalMDCTConc->pTCI_float->indexOfTonalPeak[i]; + k = hTonalMDCTConc->pTCI->indexOfTonalPeak[i]; odft_left = powerSpectrum[k - 1]; odft_right = powerSpectrum[k + 1]; if ( odft_left >= CNST_maxRatio * odft_right ) @@ -312,7 +316,7 @@ static void CalcPowerSpec( return; } - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) static void CalcPowerSpecAndDetectTonalComponents( const TonalMDCTConcealPtr hTonalMDCTConc, float secondLastMDST[], @@ -344,14 +348,14 @@ static void CalcPowerSpecAndDetectTonalComponents( set_zero( powerSpectrum + hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamplesCore - hTonalMDCTConc->nSamples ); } - DetectTonalComponents_flt( hTonalMDCTConc->pTCI_float->indexOfTonalPeak, hTonalMDCTConc->pTCI_float->lowerIndex, hTonalMDCTConc->pTCI_float->upperIndex, &hTonalMDCTConc->pTCI_float->numIndexes, hTonalMDCTConc->lastPitchLag_float, pitchLag, + DetectTonalComponents_flt( hTonalMDCTConc->pTCI->indexOfTonalPeak, hTonalMDCTConc->pTCI->lowerIndex, hTonalMDCTConc->pTCI->upperIndex, &hTonalMDCTConc->pTCI->numIndexes, hTonalMDCTConc->lastPitchLag_float, pitchLag, hTonalMDCTConc->lastBlockData.spectralData_float, hTonalMDCTConc->lastBlockData.scaleFactors_float, powerSpectrum, nSamples, hTonalMDCTConc->nSamplesCore, floorPowerSpectrum, psychParamsCurrent ); FindPhases( hTonalMDCTConc, secondLastMDCT, secondLastMDST ); FindPhaseDifferences( hTonalMDCTConc, powerSpectrum ); - if ( hTonalMDCTConc->pTCI_float->numIndexes > 0 ) + if ( hTonalMDCTConc->pTCI->numIndexes > 0 ) { hTonalMDCTConc->secondLastPowerSpectrum_float = hTonalMDCTConc->secondLastBlockData.spectralData_float; @@ -424,7 +428,7 @@ static void CalcPowerSpecAndDetectTonalComponents( return; } - +#endif static void CalcMDXT( const TonalMDCTConcealPtr hTonalMDCTConc, @@ -451,7 +455,7 @@ static void CalcMDXT( return; } - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void TonalMDCTConceal_Detect_ivas( const TonalMDCTConcealPtr hTonalMDCTConc, const float pitchLag, @@ -549,8 +553,8 @@ void TonalMDCTConceal_Detect_ivas( v_multc( powerSpectrum + hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->secondLastBlockData.scaleFactors_float[nBands - 1], powerSpectrum + hTonalMDCTConc->nSamplesCore, nSamples - hTonalMDCTConc->nSamplesCore ); v_mult( powerSpectrum, powerSpectrum, powerSpectrum, nSamples ); - RefineTonalComponents_flt( hTonalMDCTConc->pTCI_float->indexOfTonalPeak, hTonalMDCTConc->pTCI_float->lowerIndex, hTonalMDCTConc->pTCI_float->upperIndex, hTonalMDCTConc->pTCI_float->phaseDiff_float, - hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float, &hTonalMDCTConc->pTCI_float->numIndexes, hTonalMDCTConc->lastPitchLag_float, pitchLag, + RefineTonalComponents_flt( hTonalMDCTConc->pTCI->indexOfTonalPeak, hTonalMDCTConc->pTCI->lowerIndex, hTonalMDCTConc->pTCI->upperIndex, hTonalMDCTConc->pTCI->phaseDiff_float, + hTonalMDCTConc->pTCI->phase_currentFramePredicted_float, &hTonalMDCTConc->pTCI->numIndexes, hTonalMDCTConc->lastPitchLag_float, pitchLag, hTonalMDCTConc->lastBlockData.spectralData_float, hTonalMDCTConc->lastBlockData.scaleFactors_float, powerSpectrum, nSamples, hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples * hTonalMDCTConc->nSamples / 400.0f /* floorPowerSpectrum */, psychParamsCurrent ); } @@ -558,10 +562,10 @@ void TonalMDCTConceal_Detect_ivas( } else { - hTonalMDCTConc->pTCI_float->numIndexes = 0; + hTonalMDCTConc->pTCI->numIndexes = 0; } - *numIndices = hTonalMDCTConc->pTCI_float->numIndexes; + *numIndices = hTonalMDCTConc->pTCI->numIndexes; return; } @@ -663,15 +667,15 @@ void TonalMDCTConceal_InsertNoise_ivas( } else { - assert( hTonalMDCTConc->pTCI_float->numIndexes > 0 ); + assert( hTonalMDCTConc->pTCI->numIndexes > 0 ); /* initialize bins of tonal components with zero: basically not necessary, but currently the whole spectrum is rescaled in mdct_noiseShaping_flt() and then there would be a processing of uninitialized values */ - for ( i = 0; i < hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + for ( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - for ( l = hTonalMDCTConc->pTCI_float->lowerIndex[i]; l <= hTonalMDCTConc->pTCI_float->upperIndex[i]; l++ ) + for ( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { mdctSpectrum[l] = 0; if ( l < crossOverFreq ) @@ -685,7 +689,7 @@ void TonalMDCTConceal_InsertNoise_ivas( /* if fadeout has not started yet, only apply sign scrambling */ if ( crossfadeGain == 1.0f ) { - for ( l = 0; l < hTonalMDCTConc->pTCI_float->lowerIndex[0]; l++ ) + for ( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { if ( concealment_noise[l] > 0 ) { @@ -696,9 +700,9 @@ void TonalMDCTConceal_InsertNoise_ivas( mdctSpectrum[l] = -hTonalMDCTConc->lastBlockData.spectralData_float[l]; } } - for ( i = 1; i < hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + for ( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - for ( l = hTonalMDCTConc->pTCI_float->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI_float->lowerIndex[i]; l++ ) + for ( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { if ( concealment_noise[l] > 0 ) { @@ -711,7 +715,7 @@ void TonalMDCTConceal_InsertNoise_ivas( } } - for ( l = hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] + 1; l < crossOverFreq; l++ ) + for ( l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++ ) { if ( concealment_noise[l] > 0 ) { @@ -733,7 +737,7 @@ void TonalMDCTConceal_InsertNoise_ivas( { g *= (float) sqrt( cngLevelBackgroundTrace_bfi / hTonalMDCTConc->curr_noise_nrg_flt ); - for ( l = 0; l < hTonalMDCTConc->pTCI_float->lowerIndex[0]; l++ ) + for ( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { x = hTonalMDCTConc->lastBlockData.spectralData_float[l]; y = concealment_noise[l]; @@ -748,9 +752,9 @@ void TonalMDCTConceal_InsertNoise_ivas( } hTonalMDCTConc->faded_signal_nrg_flt += mdctSpectrum[l] * mdctSpectrum[l]; } - for ( i = 1; i < hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + for ( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - for ( l = hTonalMDCTConc->pTCI_float->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI_float->lowerIndex[i]; l++ ) + for ( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { x = hTonalMDCTConc->lastBlockData.spectralData_float[l]; y = concealment_noise[l]; @@ -767,7 +771,7 @@ void TonalMDCTConceal_InsertNoise_ivas( } } - for ( l = hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] + 1; l < crossOverFreq; l++ ) + for ( l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++ ) { x = hTonalMDCTConc->lastBlockData.spectralData_float[l]; y = concealment_noise[l]; @@ -837,8 +841,8 @@ void TonalMDCTConceal_InsertNoise_ivas( } else { - assert( hTonalMDCTConc->pTCI_float->numIndexes > 0 ); - for ( l = 0; l < hTonalMDCTConc->pTCI_float->lowerIndex[0]; l++ ) + assert( hTonalMDCTConc->pTCI->numIndexes > 0 ); + for ( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { x = hTonalMDCTConc->lastBlockData.spectralData_float[l]; rnd = own_random( &rnd ); @@ -848,10 +852,10 @@ void TonalMDCTConceal_InsertNoise_ivas( nrgWhiteNoise += mdctSpectrum[l] * mdctSpectrum[l]; } - for ( i = 1; i < hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + for ( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - tilt *= (float) pow( tiltFactor, hTonalMDCTConc->pTCI_float->upperIndex[i - 1] - hTonalMDCTConc->pTCI_float->lowerIndex[i - 1] + 1 ); - for ( l = hTonalMDCTConc->pTCI_float->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI_float->lowerIndex[i]; l++ ) + tilt *= (float) pow( tiltFactor, hTonalMDCTConc->pTCI->upperIndex[i - 1] - hTonalMDCTConc->pTCI->lowerIndex[i - 1] + 1 ); + for ( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { x = hTonalMDCTConc->lastBlockData.spectralData_float[l]; rnd = own_random( &rnd ); @@ -861,9 +865,9 @@ void TonalMDCTConceal_InsertNoise_ivas( nrgWhiteNoise += mdctSpectrum[l] * mdctSpectrum[l]; } } - tilt *= (float) pow( tiltFactor, hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] - hTonalMDCTConc->pTCI_float->lowerIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] + 1 ); + tilt *= (float) pow( tiltFactor, hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] - hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1 ); - for ( l = hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] + 1; l < crossOverFreq; l++ ) + for ( l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++ ) { x = hTonalMDCTConc->lastBlockData.spectralData_float[l]; rnd = own_random( &rnd ); @@ -876,7 +880,7 @@ void TonalMDCTConceal_InsertNoise_ivas( { g *= (float) sqrt( nrgNoiseInLastFrame / nrgWhiteNoise ); } - for ( l = 0; l < hTonalMDCTConc->pTCI_float->lowerIndex[0]; l++ ) + for ( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { x = hTonalMDCTConc->lastBlockData.spectralData_float[l]; y = mdctSpectrum[l]; @@ -890,9 +894,9 @@ void TonalMDCTConceal_InsertNoise_ivas( mdctSpectrum[l] = g * y - crossfadeGain * x; } } - for ( i = 1; i < hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + for ( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - for ( l = hTonalMDCTConc->pTCI_float->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI_float->lowerIndex[i]; l++ ) + for ( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { x = hTonalMDCTConc->lastBlockData.spectralData_float[l]; y = mdctSpectrum[l]; @@ -911,14 +915,14 @@ void TonalMDCTConceal_InsertNoise_ivas( necessary, but currently the whole spectrum is rescaled in mdct_noiseShaping_flt() and then there would be a processing of uninitialized values */ - for ( i = 0; i < hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + for ( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - for ( l = hTonalMDCTConc->pTCI_float->lowerIndex[i]; l <= hTonalMDCTConc->pTCI_float->upperIndex[i]; l++ ) + for ( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { mdctSpectrum[l] = 0; } } - for ( l = hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] + 1; l < crossOverFreq; l++ ) + for ( l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++ ) { x = hTonalMDCTConc->lastBlockData.spectralData_float[l]; y = mdctSpectrum[l]; @@ -947,7 +951,6 @@ void TonalMDCTConceal_InsertNoise_ivas( return; } - void TonalMDCTConceal_Apply_ivas( TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ float *mdctSpectrum, /*OUT */ @@ -962,10 +965,10 @@ void TonalMDCTConceal_Apply_ivas( if ( hTonalMDCTConc->lastBlockData.blockIsValid & hTonalMDCTConc->secondLastBlockData.blockIsValid ) { - assert( hTonalMDCTConc->pTCI_float->numIndexes > 0 ); + assert( hTonalMDCTConc->pTCI->numIndexes > 0 ); nSamples = hTonalMDCTConc->nNonZeroSamples; - assert( hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] < nSamples ); + assert( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] < nSamples ); mvr2r( hTonalMDCTConc->secondLastPowerSpectrum_float, powerSpectrum, nSamples ); /* Convert from 16 bits to 32 bits */ if ( psychParamsCurrent == NULL ) { @@ -1022,8 +1025,8 @@ void TonalMDCTConceal_Apply_ivas( v_multc( powerSpectrum + hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->secondLastBlockData.scaleFactors_float[nBands - 1], powerSpectrum + hTonalMDCTConc->nSamplesCore, nSamples - hTonalMDCTConc->nSamplesCore ); - phaseDiff = hTonalMDCTConc->pTCI_float->phaseDiff_float; /* if multiple frame loss occurs use the phase from the last frame and continue rotating */ - pCurrentPhase = hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float; + phaseDiff = hTonalMDCTConc->pTCI->phaseDiff_float; /* if multiple frame loss occurs use the phase from the last frame and continue rotating */ + pCurrentPhase = hTonalMDCTConc->pTCI->phase_currentFramePredicted_float; if ( !hTonalMDCTConc->lastBlockData.blockIsConcealed ) { @@ -1038,7 +1041,7 @@ void TonalMDCTConceal_Apply_ivas( } /* for each index group */ - for ( i = 0; i < hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + for ( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { phaseToAdd = hTonalMDCTConc->nFramesLost_float * phaseDiff[i]; @@ -1054,7 +1057,7 @@ void TonalMDCTConceal_Apply_ivas( phaseToAdd += PI2; } - for ( l = hTonalMDCTConc->pTCI_float->lowerIndex[i]; l <= hTonalMDCTConc->pTCI_float->upperIndex[i]; l++ ) + for ( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { const float currentPhase = ( *pCurrentPhase++ ) + phaseToAdd; /* *pCurrentPhase and phaseToAdd are in range -EVS_PI..EVS_PI */ mdctSpectrum[l] = (float) cos( currentPhase ) * powerSpectrum[l]; @@ -1066,7 +1069,7 @@ void TonalMDCTConceal_Apply_ivas( return; } - +#endif void TonalMDCTConceal_SaveTimeSignal_ivas( TonalMDCTConcealPtr hTonalMDCTConc, @@ -1087,6 +1090,8 @@ void TonalMDCTConceal_SaveTimeSignal_ivas( return; } + + #ifdef IVAS_FLOAT_FIXED void TonalMdctConceal_create_concealment_noise_ivas_fx( Word32 concealment_noise[L_FRAME48k], @@ -1106,13 +1111,16 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( HANDLE_FD_CNG_COM hFdCngCom; Word16 *rnd_c, *rnd; Word16 crossOverFreq, i, save_rnd_c, max_noise_line; - Word16 c, c_inv; - Word32 noise_shape_buffer[L_FRAME48k], inc; + Word16 c, c_inv, inc; + Word32 noise_shape_buffer[L_FRAME48k]; Word16 noise_shape_buffer_e[L_FRAME48k]; Word16 start_idx, stop_idx, noise_shape_buffer_common_exp = MIN16B_FLT_FX, last_scf_e, temp_e; Word32 *cngNoiseLevelPtr; Word32 last_scf; + Word16 c_e, c_inv_e; + move16(); + push_wmops( "create_conc_noise" ); hStereoMdct = hCPE->hStereoMdct; @@ -1123,9 +1131,9 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( rnd_c = &hStereoMdct->noise_seed_common; /* determine start bin for IGF */ - IF ( EQ_16(st->igf, 0 )) + IF( EQ_16( st->igf, 0 ) ) { - IF ( EQ_16(st->narrowBand, 0 )) + IF( EQ_16( st->narrowBand, 0 ) ) { /* minimum needed for output with sampling rates lower then the nominal sampling rate */ @@ -1133,7 +1141,8 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( } ELSE { - crossOverFreq = L_frameTCX; move16(); + crossOverFreq = L_frameTCX; + move16(); } } ELSE @@ -1142,148 +1151,179 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( } /* for tonal mdct concealment with tonal components above the crossover frequency, conditionally raise the frequency index until which noise is generated */ - max_noise_line = crossOverFreq; move16(); - IF ( st->tonal_mdct_plc_active ) + max_noise_line = crossOverFreq; + move16(); + IF( st->tonal_mdct_plc_active ) { - max_noise_line = s_max( max_noise_line, hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] + 1 ); + max_noise_line = s_max( max_noise_line, hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1 ); } /* first lost frame is handled separately */ - IF ( !hTonalMDCTConc->lastBlockData.blockIsConcealed ) + IF( !hTonalMDCTConc->lastBlockData.blockIsConcealed ) { - *rnd = add(1977, idchan); + *rnd = add( 1977, idchan ); /* will be set twice when looping over two channels, but does not matter */ *rnd_c = 1979; + move16(); } - IF (GT_16(crossfade_gain, 32734)) /* Due to precision loss */ /* 0.999 in Q15*/ + IF( GT_16( crossfade_gain, 32734 ) ) + /* Due to precision loss */ /* 0.999 in Q15*/ { /* In first frame, noise is weighted with zero anyway, we only need the random numbers for the sign scrambling */ - FOR ( i = 0; i < max_noise_line; i++ ) + FOR( i = 0; i < max_noise_line; i++ ) { *rnd = own_random( rnd ); concealment_noise[i] = *rnd; + move32(); } *concealment_noise_exp = 31; + move16(); pop_wmops(); return; } save_rnd_c = *rnd_c; + move16(); - Word16 c_e = 1; - Word16 c_inv_e = 1; + c_e = 1; + move16(); + c_inv_e = 1; + move16(); - c = Sqrt16( hStereoMdct->lastCoh_fx, &c_e); //Q1 = 15 - c_e - c_inv = Sqrt16( sub(ONE_IN_Q14, hStereoMdct->lastCoh_fx), &c_inv_e); //Q2 = 15 - c_inv_e + c = Sqrt16( hStereoMdct->lastCoh_fx, &c_e ); // Q1 = 15 - c_e + c_inv = Sqrt16( sub( ONE_IN_Q14, hStereoMdct->lastCoh_fx ), &c_inv_e ); // Q2 = 15 - c_inv_e - IF(NE_16(c_e, c_inv_e)) + IF( NE_16( c_e, c_inv_e ) ) { - IF(LT_16(c_e, c_inv_e)) - { - c = shr(c, sub(c_inv_e, c_e)); - c_e = c_inv_e; - } - ELSE - { - c_inv = shr(c_inv, sub(c_e, c_inv_e)); - } + IF( LT_16( c_e, c_inv_e ) ) + { + c = shr( c, sub( c_inv_e, c_e ) ); + c_e = c_inv_e; + move16(); + } + ELSE + { + c_inv = shr( c_inv, sub( c_e, c_inv_e ) ); + } } /* pre-compute the noise shape for later weighting of the noise spectra */ cngNoiseLevelPtr = &hFdCngCom->cngNoiseLevel[0]; last_scf_e = hFdCngCom->cngNoiseLevelExp; + move16(); - inc = ( st->core > TCX_20_CORE ) ? 2 : 1; - start_idx = idiv1616(hFdCngCom->startBand, inc); - stop_idx = idiv1616(hFdCngCom->stopFFTbin, inc); + inc = GT_16( st->core, TCX_20_CORE ) ? 2 : 1; + move32(); + start_idx = idiv1616( hFdCngCom->startBand, inc ); + stop_idx = idiv1616( hFdCngCom->stopFFTbin, inc ); - FOR ( i = 0; i < start_idx; i++ ) + FOR( i = 0; i < start_idx; i++ ) { noise_shape_buffer[i] = 0; + move32(); noise_shape_buffer_e[i] = 0; + move16(); } - FOR ( ; i < stop_idx;( i++, cngNoiseLevelPtr += inc) ) + FOR( ; i < stop_idx; ( i++, cngNoiseLevelPtr += inc ) ) { noise_shape_buffer_e[i] = hFdCngCom->cngNoiseLevelExp; - noise_shape_buffer[i] = Sqrt32( *( cngNoiseLevelPtr ), &noise_shape_buffer_e[i]); - noise_shape_buffer_common_exp = s_max(noise_shape_buffer_e[i], noise_shape_buffer_common_exp); + move16(); + noise_shape_buffer[i] = Sqrt32( *( cngNoiseLevelPtr ), &noise_shape_buffer_e[i] ); + move32(); + noise_shape_buffer_common_exp = s_max( noise_shape_buffer_e[i], noise_shape_buffer_common_exp ); } - FOR(i = 0; i < stop_idx; i++) - { - IF(NE_16(noise_shape_buffer_common_exp, noise_shape_buffer_e[i])) - noise_shape_buffer[i] = L_shr(noise_shape_buffer[i], sub(noise_shape_buffer_common_exp, noise_shape_buffer_e[i])); + FOR( i = 0; i < stop_idx; i++ ) + { + IF( NE_16( noise_shape_buffer_common_exp, noise_shape_buffer_e[i] ) ) + { + + noise_shape_buffer[i] = L_shr( noise_shape_buffer[i], sub( noise_shape_buffer_common_exp, noise_shape_buffer_e[i] ) ); + move32(); + } } - last_scf = Sqrt32( *( cngNoiseLevelPtr - inc ), &last_scf_e); + last_scf = Sqrt32( *( cngNoiseLevelPtr - inc ), &last_scf_e ); - IF(LT_16(noise_shape_buffer_common_exp, last_scf_e)) + IF( LT_16( noise_shape_buffer_common_exp, last_scf_e ) ) { - Scale_sig32(noise_shape_buffer, stop_idx, sub(noise_shape_buffer_common_exp, last_scf_e)); + Scale_sig32( noise_shape_buffer, stop_idx, sub( noise_shape_buffer_common_exp, last_scf_e ) ); noise_shape_buffer_common_exp = last_scf_e; + move16(); } ELSE { - last_scf = L_shl(last_scf, sub(last_scf_e, noise_shape_buffer_common_exp)); + last_scf = L_shl( last_scf, sub( last_scf_e, noise_shape_buffer_common_exp ) ); } - FOR ( ; i < max_noise_line; i++ ) + FOR( ; i < max_noise_line; i++ ) { noise_shape_buffer[i] = last_scf; + move32(); } /* fill the noise vector */ hTonalMDCTConc->curr_noise_nrg = MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG_Q31; - hTonalMDCTConc->curr_noise_nrg_exp = 0; move16(); - *concealment_noise_exp = add(16 ,add(noise_shape_buffer_common_exp, c_e)); - temp_e = hTonalMDCTConc->curr_noise_nrg_exp; move16(); - - test(); test(); test(); test(); - IF ( EQ_16(noise_gen_mode, EQUAL_CORES) || ( (EQ_16(noise_gen_mode, TCX20_IN_0_TCX10_IN_1) && EQ_16(idchan, 0) ) || (EQ_16(noise_gen_mode, TCX10_IN_0_TCX20_IN_1) && EQ_16(idchan, 1) ) ) ) + move32(); + hTonalMDCTConc->curr_noise_nrg_exp = 0; + move16(); + *concealment_noise_exp = add( 16, add( noise_shape_buffer_common_exp, c_e ) ); + temp_e = hTonalMDCTConc->curr_noise_nrg_exp; + move16(); + + test(); + test(); + test(); + test(); + IF( EQ_16( noise_gen_mode, EQUAL_CORES ) || ( ( EQ_16( noise_gen_mode, TCX20_IN_0_TCX10_IN_1 ) && EQ_16( idchan, 0 ) ) || ( EQ_16( noise_gen_mode, TCX10_IN_0_TCX20_IN_1 ) && EQ_16( idchan, 1 ) ) ) ) { /* current channel is TCX20 -> generate noise for "full-length" spectrum */ - FOR ( i = 0; i < max_noise_line; i++ ) + FOR( i = 0; i < max_noise_line; i++ ) { *rnd = own_random( rnd ); *rnd_c = own_random( rnd_c ); - concealment_noise[i] = Mpy_32_32(L_add(L_shr(L_mult(c_inv, *rnd), 1), L_shr(L_mult(c, *rnd_c), 1)), noise_shape_buffer[i]); - IF(NE_32(concealment_noise[i], 0)) + concealment_noise[i] = Mpy_32_32( L_add( L_shr( L_mult( c_inv, *rnd ), 1 ), L_shr( L_mult( c, *rnd_c ), 1 ) ), noise_shape_buffer[i] ); + move32(); + IF( NE_32( concealment_noise[i], 0 ) ) { - hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp(hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32(concealment_noise[i], concealment_noise[i]), shl(*concealment_noise_exp, 1), &temp_e); + hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); } hTonalMDCTConc->curr_noise_nrg_exp = temp_e; + move16(); } - } ELSE /* ( ( noise_gen_mode == TCX10_IN_0_TCX20_IN_1 && idchan == 0 ) || ( noise_gen_mode == TCX20_IN_0_TCX10_IN_1 && idchan == 1 ) ) */ { /* current channel is TCX10 and the other is TCX20 -> generate noise for "half-length" spectrum, but "increment" mid seed twice, to have the same seed in mid as the other (TCX20) channel for next frame */ - FOR ( i = 0; i < max_noise_line; i++ ) + FOR( i = 0; i < max_noise_line; i++ ) { *rnd = own_random( rnd ); *rnd_c = own_random( rnd_c ); - concealment_noise[i] = Mpy_32_32(L_add(L_shr(L_mult(c_inv, *rnd), 1), L_shr(L_mult(c, *rnd_c), 1)), noise_shape_buffer[i]); - IF(NE_32(concealment_noise[i], 0)) + concealment_noise[i] = Mpy_32_32( L_add( L_shr( L_mult( c_inv, *rnd ), 1 ), L_shr( L_mult( c, *rnd_c ), 1 ) ), noise_shape_buffer[i] ); + move32(); + IF( NE_32( concealment_noise[i], 0 ) ) { - hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp(hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32(concealment_noise[i], concealment_noise[i]), shl(*concealment_noise_exp, 1), &temp_e); + hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); } hTonalMDCTConc->curr_noise_nrg_exp = temp_e; + move16(); *rnd_c = own_random( rnd_c ); } } - IF ( st->tonal_mdct_plc_active ) + IF( st->tonal_mdct_plc_active ) { - FOR ( i = crossOverFreq; i < s_max( crossOverFreq, hTonalMDCTConc->pTCI_float->lowerIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] ); ++i ) + FOR( i = crossOverFreq; i < s_max( crossOverFreq, hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1] ); ++i ) { concealment_noise[i] = 0; + move32(); } } @@ -1291,20 +1331,25 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( - after finishing the first channel - after a first subframe if the current channel is TCX10 */ - test(); test(); test(); test(); - - IF ( ( EQ_16(idchan, 0) && (EQ_16(core, TCX_20) || (EQ_16(core, TCX_10) && EQ_16(subframe_idx, 1) ) ) ) || (EQ_16(core, TCX_10) && EQ_16(subframe_idx, 0) ) ) + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( idchan, 0 ) && ( EQ_16( core, TCX_20 ) || ( EQ_16( core, TCX_10 ) && EQ_16( subframe_idx, 1 ) ) ) ) || ( EQ_16( core, TCX_10 ) && EQ_16( subframe_idx, 0 ) ) ) { *rnd_c = save_rnd_c; + move16(); } st->seed_tcx_plc = *rnd; + move16(); pop_wmops(); return; } -#endif +#else void TonalMdctConceal_create_concealment_noise_ivas( float concealment_noise[L_FRAME48k], CPE_DEC_HANDLE hCPE, @@ -1360,7 +1405,7 @@ void TonalMdctConceal_create_concealment_noise_ivas( max_noise_line = crossOverFreq; if ( st->tonal_mdct_plc_active ) { - max_noise_line = max( max_noise_line, hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] + 1 ); + max_noise_line = max( max_noise_line, hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1 ); } /* first lost frame is handled separately */ @@ -1444,7 +1489,7 @@ void TonalMdctConceal_create_concealment_noise_ivas( if ( st->tonal_mdct_plc_active ) { - for ( i = crossOverFreq; i < max( crossOverFreq, hTonalMDCTConc->pTCI_float->lowerIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] ); ++i ) + for ( i = crossOverFreq; i < max( crossOverFreq, hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1] ); ++i ) { concealment_noise[i] *= 0.0f; } @@ -1464,7 +1509,10 @@ void TonalMdctConceal_create_concealment_noise_ivas( return; } -#ifndef IVAS_FLOAT_FIXED +#endif + + +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void TonalMdctConceal_whiten_noise_shape_ivas( Decoder_State *st, const int16_t L_frame, @@ -1506,7 +1554,7 @@ void TonalMdctConceal_whiten_noise_shape_ivas( Word16 q = 31; FOR( Word16 k = 0; k < L_FRAME16k; k++ ) { - if(abs((Word32)whitenend_noise_shape[k])!=0) q = s_min(q, norm_l( whitenend_noise_shape[k] )); + if(abs((Word32)whitenend_noise_shape[k])!=0) q = s_min(q, norm_l( (Word32)whitenend_noise_shape[k] )); } q -= find_guarded_bits_fx(L_frame) - 2; @@ -1559,12 +1607,12 @@ void TonalMdctConceal_whiten_noise_shape_ivas( FOR( Word16 k = 0; k < L_FRAME16k; k++ ) { if ( abs( (Word32) whitenend_noise_shape[k] ) != 0 ) - q_wns = s_min( q_wns, norm_l( whitenend_noise_shape[k] ) ); + q_wns = s_min( q_wns, norm_l( (Word32)whitenend_noise_shape[k] ) ); } FOR( Word16 k = 0; k < FDNS_NPTS; k++ ) { if ( abs( (Word32) scfs_for_shaping[k] ) != 0 ) - q_sfs = s_min( q_sfs, norm_l( scfs_for_shaping[k] ) ); + q_sfs = s_min( q_sfs, norm_l( (Word32)scfs_for_shaping[k] ) ); } q_wns -= 1; q_sfs -= 1; @@ -1605,7 +1653,8 @@ void TonalMdctConceal_whiten_noise_shape_ivas( pop_wmops(); } -#else +#endif +#ifdef IVAS_FLOAT_FIXED void TonalMdctConceal_whiten_noise_shape_ivas_fx( Decoder_State *st, const Word16 L_frame, diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index f0c57650b15a79372b54b26cb216bef9267fa260..7769fb8b59883492f99862a0c596ac0955c83904 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -117,7 +117,7 @@ ivas_error TonalMDCTConceal_Init( hTonalMDCTConc->faded_signal_nrg_flt = 0.0f; #endif - /* Offset the pointer to the end of buffer, so that pTCI_float is not destroyed when + /* Offset the pointer to the end of buffer, so that pTCI is not destroyed when new time samples are stored in lastPcmOut */ move16(); move16(); /* just the second half of the second last pcm output is needed */ @@ -127,7 +127,7 @@ ivas_error TonalMDCTConceal_Init( /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */ #if 1 //TO do enable when only fix code is present currently disabled due to float array in structure - //assert(sizeof(*hTonalMDCTConc->pTCI_float) <= (hTonalMDCTConc->lastPcmOut-hTonalMDCTConc->timeDataBuffer)*sizeof(hTonalMDCTConc->timeDataBuffer[0])); + //assert(sizeof(*hTonalMDCTConc->pTCI) <= (hTonalMDCTConc->lastPcmOut-hTonalMDCTConc->timeDataBuffer)*sizeof(hTonalMDCTConc->timeDataBuffer[0])); #endif return IVAS_ERR_OK; } @@ -178,9 +178,9 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( move16(); hTonalMDCTConc->secondLastBlockData.blockIsConcealed = 0; move16(); - //hTonalMDCTConc->pTCI_float = (TonalComponentsInfo_fix *) hTonalMDCTConc->timeDataBuffer; + //hTonalMDCTConc->pTCI = (TonalComponentsInfo_fix *) hTonalMDCTConc->timeDataBuffer; - hTonalMDCTConc->pTCI_float = &hTonalMDCTConc->pTCI_float1; + hTonalMDCTConc->pTCI = &hTonalMDCTConc->pTCI1; move16(); hTonalMDCTConc->lastPitchLag = L_deposit_l( 0 ); @@ -221,7 +221,7 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( hTonalMDCTConc->faded_signal_nrg_exp = 0; move16(); - /* Offset the pointer to the end of buffer, so that pTCI_float is not destroyed when + /* Offset the pointer to the end of buffer, so that pTCI is not destroyed when new time samples are stored in lastPcmOut */ move16(); move16(); @@ -231,10 +231,10 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */ #if 1 // TO do enable when only fix code is present currently disabled due to float array in structure - //assert( sizeof( *hTonalMDCTConc->pTCI_float ) <= ( hTonalMDCTConc->lastPcmOut - hTonalMDCTConc->timeDataBuffer ) * sizeof( hTonalMDCTConc->timeDataBuffer[0] ) ); + //assert( sizeof( *hTonalMDCTConc->pTCI ) <= ( hTonalMDCTConc->lastPcmOut - hTonalMDCTConc->timeDataBuffer ) * sizeof( hTonalMDCTConc->timeDataBuffer[0] ) ); /* TODO: remove float code*/ - assert( sizeof( *hTonalMDCTConc->pTCI_float ) <= ( hTonalMDCTConc->lastPcmOut_float - hTonalMDCTConc->timeDataBuffer_float ) * sizeof( hTonalMDCTConc->timeDataBuffer_float[0] ) ); + assert( sizeof( *hTonalMDCTConc->pTCI ) <= ( hTonalMDCTConc->lastPcmOut_float - hTonalMDCTConc->timeDataBuffer_float ) * sizeof( hTonalMDCTConc->timeDataBuffer_float[0] ) ); #endif return IVAS_ERR_OK; @@ -615,11 +615,11 @@ static void FindPhases( /* o: currenc phase [-p - pCurrentPhase = hTonalMDCTConc->pTCI_float->phase_currentFramePredicted; + pCurrentPhase = hTonalMDCTConc->pTCI->phase_currentFramePredicted; /* for each index/index group */ - FOR( i = 0; i < hTonalMDCTConc->pTCI_float->numIndexes; i++) + FOR( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++) { - FOR (l = hTonalMDCTConc->pTCI_float->lowerIndex[i]; l <= hTonalMDCTConc->pTCI_float->upperIndex[i]; l++) + FOR (l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++) { /* in contrast to the float code, the parameter secondLastMDST[l] needs not to be negated - due to a different implementation of @@ -654,16 +654,16 @@ static void FindPhaseDifferences( /* o: Phase j = J; move16(); - phaseDiff = hTonalMDCTConc->pTCI_float->phaseDiff; + phaseDiff = hTonalMDCTConc->pTCI->phaseDiff; - FOR (i = 0; i < hTonalMDCTConc->pTCI_float->numIndexes; i++) + FOR (i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++) { m = MM; move16(); n = N; move16(); - k = hTonalMDCTConc->pTCI_float->indexOfTonalPeak[i]; + k = hTonalMDCTConc->pTCI->indexOfTonalPeak[i]; move16(); IF (GE_32(Mpy_32_16_1(powerSpectrum[k-1],512/*1.0f Q9*/),Mpy_32_16_1(powerSpectrum[k+1], MAXRATIO))) @@ -766,6 +766,9 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( Flag Overflow = 0; #endif + Word16 nBands; + Word32 invScaleFactors_fx[FDNS_NPTS]; + Word16 old_power_spectrum_q, power_spectrum_q; nSamples = hTonalMDCTConc->nNonZeroSamples; move16(); @@ -795,10 +798,10 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( set32_fx(powerSpectrum+hTonalMDCTConc->nSamples, 0, sub(hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples)); } - //DetectTonalComponents(hTonalMDCTConc->pTCI_float->indexOfTonalPeak, - // hTonalMDCTConc->pTCI_float->lowerIndex, - // hTonalMDCTConc->pTCI_float->upperIndex, - // &hTonalMDCTConc->pTCI_float->numIndexes, + //DetectTonalComponents(hTonalMDCTConc->pTCI->indexOfTonalPeak, + // hTonalMDCTConc->pTCI->lowerIndex, + // hTonalMDCTConc->pTCI->upperIndex, + // &hTonalMDCTConc->pTCI->numIndexes, // hTonalMDCTConc->lastPitchLag, // pitchLag, // hTonalMDCTConc->lastBlockData.spectralData, @@ -811,10 +814,10 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( // hTonalMDCTConc->nSamplesCore, // floorPowerSpectrum); - ivas_DetectTonalComponents_fx(hTonalMDCTConc->pTCI_float->indexOfTonalPeak, - hTonalMDCTConc->pTCI_float->lowerIndex, - hTonalMDCTConc->pTCI_float->upperIndex, - &hTonalMDCTConc->pTCI_float->numIndexes, + ivas_DetectTonalComponents_fx(hTonalMDCTConc->pTCI->indexOfTonalPeak, + hTonalMDCTConc->pTCI->lowerIndex, + hTonalMDCTConc->pTCI->upperIndex, + &hTonalMDCTConc->pTCI->numIndexes, hTonalMDCTConc->lastPitchLag, pitchLag, hTonalMDCTConc->lastBlockData.spectralData, @@ -830,7 +833,7 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( FindPhaseDifferences(hTonalMDCTConc, powerSpectrum); - IF (hTonalMDCTConc->pTCI_float->numIndexes > 0) + IF (hTonalMDCTConc->pTCI->numIndexes > 0) { hTonalMDCTConc->secondLastPowerSpectrum = hTonalMDCTConc->secondLastBlockData.spectralData; @@ -855,21 +858,33 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( } + power_spectrum_q = 31 - powerSpectrum_exp; + old_power_spectrum_q = power_spectrum_q; /* here mdct_shaping() is intentionally used rather then mdct_shaping_16() */ -#ifdef IVAS_CODE_MDCT_GSHAPE IF (psychParamsCurrent == NULL) -#endif { mdct_shaping(powerSpectrum, hTonalMDCTConc->nSamplesCore, invScaleFactors, invScaleFactors_exp); } -#ifdef IVAS_CODE_MDCT_GSHAPE ELSE { -PMTE() - sns_shape_spectrum(powerSpectrum, psychParamsCurrent, invScaleFactors, hTonalMDCTConc->nSamplesCore); + FOR( Word16 i = 0; i < FDNS_NPTS; i++ ) + { + invScaleFactors_fx[i] = L_shl(invScaleFactors[i], 1 + invScaleFactors_exp[i]); // Q16 + } + sns_shape_spectrum_fx( powerSpectrum, &power_spectrum_q, psychParamsCurrent, invScaleFactors_fx, 16, hTonalMDCTConc->nSamplesCore ); + power_spectrum_q++; + // sns_shape_spectrum(powerSpectrum, psychParamsCurrent, invScaleFactors, hTonalMDCTConc->nSamplesCore); nBands = psychParamsCurrent->nBands; } -#endif + IF( old_power_spectrum_q < power_spectrum_q ) + Scale_sig32( powerSpectrum, hTonalMDCTConc->nSamplesCore, old_power_spectrum_q - power_spectrum_q ); + ELSE + { + Scale_sig32( powerSpectrum + hTonalMDCTConc->nSamplesCore, nSamples - hTonalMDCTConc->nSamplesCore, power_spectrum_q - old_power_spectrum_q ); + powerSpectrum_exp = 31 - power_spectrum_q; + } + Scale_sig32( powerSpectrum, nSamples, -3 );/*Adding guard bits*/ + powerSpectrum_exp += 3; FOR (i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++) { powerSpectrum[i] = L_shl(Mpy_32_16_1(powerSpectrum[i], invScaleFactors[FDNS_NPTS-1]), invScaleFactors_exp[FDNS_NPTS-1]); @@ -945,10 +960,10 @@ static void CalcPowerSpecAndDetectTonalComponents( set32_fx(powerSpectrum+hTonalMDCTConc->nSamples, 0, sub(hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples)); } - DetectTonalComponents(hTonalMDCTConc->pTCI_float->indexOfTonalPeak, - hTonalMDCTConc->pTCI_float->lowerIndex, - hTonalMDCTConc->pTCI_float->upperIndex, - &hTonalMDCTConc->pTCI_float->numIndexes, + DetectTonalComponents(hTonalMDCTConc->pTCI->indexOfTonalPeak, + hTonalMDCTConc->pTCI->lowerIndex, + hTonalMDCTConc->pTCI->upperIndex, + &hTonalMDCTConc->pTCI->numIndexes, hTonalMDCTConc->lastPitchLag, pitchLag, hTonalMDCTConc->lastBlockData.spectralData, @@ -964,7 +979,7 @@ static void CalcPowerSpecAndDetectTonalComponents( FindPhaseDifferences(hTonalMDCTConc, powerSpectrum); - IF (hTonalMDCTConc->pTCI_float->numIndexes > 0) + IF (hTonalMDCTConc->pTCI->numIndexes > 0) { hTonalMDCTConc->secondLastPowerSpectrum = hTonalMDCTConc->secondLastBlockData.spectralData; @@ -1166,12 +1181,12 @@ void TonalMDCTConceal_Detect( move32(); } - RefineTonalComponents(hTonalMDCTConc->pTCI_float->indexOfTonalPeak, - hTonalMDCTConc->pTCI_float->lowerIndex, - hTonalMDCTConc->pTCI_float->upperIndex, - hTonalMDCTConc->pTCI_float->phaseDiff, - hTonalMDCTConc->pTCI_float->phase_currentFramePredicted, - &hTonalMDCTConc->pTCI_float->numIndexes, + RefineTonalComponents(hTonalMDCTConc->pTCI->indexOfTonalPeak, + hTonalMDCTConc->pTCI->lowerIndex, + hTonalMDCTConc->pTCI->upperIndex, + hTonalMDCTConc->pTCI->phaseDiff, + hTonalMDCTConc->pTCI->phase_currentFramePredicted, + &hTonalMDCTConc->pTCI->numIndexes, hTonalMDCTConc->lastPitchLag, pitchLag, hTonalMDCTConc->lastBlockData.spectralData, @@ -1189,11 +1204,11 @@ void TonalMDCTConceal_Detect( } ELSE { - hTonalMDCTConc->pTCI_float->numIndexes = 0; + hTonalMDCTConc->pTCI->numIndexes = 0; move16(); } - *numIndices = hTonalMDCTConc->pTCI_float->numIndexes; + *numIndices = hTonalMDCTConc->pTCI->numIndexes; move16(); @@ -1309,12 +1324,12 @@ void TonalMDCTConceal_Detect_ivas_fx( move32(); } - RefineTonalComponents(hTonalMDCTConc->pTCI_float->indexOfTonalPeak, - hTonalMDCTConc->pTCI_float->lowerIndex, - hTonalMDCTConc->pTCI_float->upperIndex, - hTonalMDCTConc->pTCI_float->phaseDiff, - hTonalMDCTConc->pTCI_float->phase_currentFramePredicted, - &hTonalMDCTConc->pTCI_float->numIndexes, + RefineTonalComponents(hTonalMDCTConc->pTCI->indexOfTonalPeak, + hTonalMDCTConc->pTCI->lowerIndex, + hTonalMDCTConc->pTCI->upperIndex, + hTonalMDCTConc->pTCI->phaseDiff, + hTonalMDCTConc->pTCI->phase_currentFramePredicted, + &hTonalMDCTConc->pTCI->numIndexes, hTonalMDCTConc->lastPitchLag, pitchLag, hTonalMDCTConc->lastBlockData.spectralData, @@ -1332,11 +1347,11 @@ void TonalMDCTConceal_Detect_ivas_fx( } ELSE { - hTonalMDCTConc->pTCI_float->numIndexes = 0; + hTonalMDCTConc->pTCI->numIndexes = 0; move16(); } - *numIndices = hTonalMDCTConc->pTCI_float->numIndexes; + *numIndices = hTonalMDCTConc->pTCI->numIndexes; move16(); @@ -1522,7 +1537,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( } ELSE { - assert( hTonalMDCTConc->pTCI_float->numIndexes > 0 ); + assert( hTonalMDCTConc->pTCI->numIndexes > 0 ); /* initialize bins of tonal components with zero: basically not necessary, but currently the whole spectrum is rescaled in @@ -1532,9 +1547,9 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( ld = sub( 14, norm_s( hTonalMDCTConc->lastBlockData.nSamples ) ); fac = shr( -32768, ld ); - FOR( i = 0; i < hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + FOR( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - FOR( l = hTonalMDCTConc->pTCI_float->lowerIndex[i]; l <= hTonalMDCTConc->pTCI_float->upperIndex[i]; l++ ) + FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { mdctSpectrum[l] = L_deposit_h( 0 ); IF( LT_16( l, crossOverFreq ) ) @@ -1552,7 +1567,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( /* if fadeout has not started yet, only apply sign scrambling */ IF( GE_16( crossfadeGain, CROSSFADE_THRESHOLD ) ) { - FOR( l = 0; l < hTonalMDCTConc->pTCI_float->lowerIndex[0]; l++ ) + FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { IF( GT_32( concealment_noise[l], 0 ) ) { @@ -1563,9 +1578,9 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); } } - FOR( i = 1; i < hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - FOR( l = hTonalMDCTConc->pTCI_float->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI_float->lowerIndex[i]; l++ ) + FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { IF( GT_32( concealment_noise[l], 0 ) ) { @@ -1578,7 +1593,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( } } - FOR( l = hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] + 1; l < crossOverFreq; l++ ) + FOR( l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++ ) { IF( GT_32( concealment_noise[l], 0 ) ) { @@ -1649,7 +1664,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( exp = 0; } - FOR( l = 0; l < hTonalMDCTConc->pTCI_float->lowerIndex[0]; l++ ) + FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 y = concealment_noise[l]; @@ -1670,9 +1685,9 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); } - FOR( i = 1; i < hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - FOR( l = hTonalMDCTConc->pTCI_float->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI_float->lowerIndex[i]; l++ ) + FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 y = concealment_noise[l]; @@ -1689,7 +1704,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( } } - FOR( l = hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] + 1; l < crossOverFreq; l++ ) + FOR( l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 y = concealment_noise[l]; @@ -1862,15 +1877,15 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( } ELSE { - assert( hTonalMDCTConc->pTCI_float->numIndexes > 0 ); - FOR( l = hTonalMDCTConc->pTCI_float->lowerIndex[0]; l <= hTonalMDCTConc->pTCI_float->upperIndex[0]; l++ ) + assert( hTonalMDCTConc->pTCI->numIndexes > 0 ); + FOR( l = hTonalMDCTConc->pTCI->lowerIndex[0]; l <= hTonalMDCTConc->pTCI->upperIndex[0]; l++ ) { mdctSpectrum[l] = L_deposit_l( 0 ); } ld = sub( 14, norm_s( hTonalMDCTConc->lastBlockData.nSamples ) ); fac = shr( -32768, ld ); - FOR( l = 0; l < hTonalMDCTConc->pTCI_float->lowerIndex[0]; l++ ) + FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 y; @@ -1888,17 +1903,17 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( tilt = mult_r( tilt, tiltFactor ); /* Q15 */ } - FOR( i = 1; i < hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, L_deposit_h( hTonalMDCTConc->pTCI_float->upperIndex[i - 1] - hTonalMDCTConc->pTCI_float->lowerIndex[i - 1] + 1 ), 15, &exp ) ); + tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, L_deposit_h( hTonalMDCTConc->pTCI->upperIndex[i - 1] - hTonalMDCTConc->pTCI->lowerIndex[i - 1] + 1 ), 15, &exp ) ); tmp = shl( tmp, exp ); tilt = mult_r( tilt, tmp ); // Q15 - FOR( l = hTonalMDCTConc->pTCI_float->lowerIndex[i]; l <= hTonalMDCTConc->pTCI_float->upperIndex[i]; l++ ) + FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { mdctSpectrum[l] = L_deposit_l( 0 ); } - FOR( l = hTonalMDCTConc->pTCI_float->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI_float->lowerIndex[i]; l++ ) + FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 y; @@ -1918,7 +1933,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( } tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, - L_deposit_h( hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] - hTonalMDCTConc->pTCI_float->lowerIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] + 1 ), 15, &exp ) ); + L_deposit_h( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] - hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1 ), 15, &exp ) ); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ #ifdef BASOP_NOGLOB tmp = shl_sat( tmp, exp ); @@ -1928,7 +1943,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( BASOP_SATURATE_WARNING_ON_EVS tilt = mult_r( tilt, tmp ); - FOR( l = add( hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) + FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 y; @@ -1998,7 +2013,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( exp = 0; } - FOR( l = 0; l < hTonalMDCTConc->pTCI_float->lowerIndex[0]; l++ ) + FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 const y = mdctSpectrum[l]; @@ -2017,9 +2032,9 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( move32(); } - FOR( i = 1; i < hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - FOR( l = hTonalMDCTConc->pTCI_float->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI_float->lowerIndex[i]; l++ ) + FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 const y = mdctSpectrum[l]; @@ -2043,15 +2058,15 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( necessary, but currently the whole spectrum is rescaled in mdct_noiseShaping() and then there would be a processing of uninitialized values */ - FOR( i = 0; i < hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + FOR( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - FOR( l = hTonalMDCTConc->pTCI_float->lowerIndex[i]; l <= hTonalMDCTConc->pTCI_float->upperIndex[i]; l++ ) + FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { mdctSpectrum[l] = L_deposit_l( 0 ); } } - FOR( l = add( hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) + FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 const y = mdctSpectrum[l]; @@ -2189,15 +2204,15 @@ void TonalMDCTConceal_InsertNoise( } else { - assert(hTonalMDCTConc->pTCI_float->numIndexes > 0); + assert(hTonalMDCTConc->pTCI->numIndexes > 0); /* initialize bins of tonal components with zero: basically not necessary, but currently the whole spectrum is rescaled in mdct_noiseShaping() and then there would be a processing of uninitialized values */ - for (i = 0; i < hTonalMDCTConc->pTCI_float->numIndexes; i++) + for (i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++) { - for (l = hTonalMDCTConc->pTCI_float->lowerIndex[i]; l <= hTonalMDCTConc->pTCI_float->upperIndex[i]; l++) + for (l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++) { mdctSpectrum[l] = 0; if (l < crossOverFreq) @@ -2211,7 +2226,7 @@ void TonalMDCTConceal_InsertNoise( /* if fadeout has not started yet, only apply sign scrambling */ if (crossfadeGain == 1.0f) { - for (l = 0; l < hTonalMDCTConc->pTCI_float->lowerIndex[0]; l++) + for (l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++) { if (concealment_noise[l] > 0) { @@ -2222,9 +2237,9 @@ void TonalMDCTConceal_InsertNoise( mdctSpectrum[l] = -hTonalMDCTConc->lastBlockData.spectralData[l]; } } - for (i = 1; i < hTonalMDCTConc->pTCI_float->numIndexes; i++) + for (i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++) { - for (l = hTonalMDCTConc->pTCI_float->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI_float->lowerIndex[i]; l++) + for (l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++) { if (concealment_noise[l] > 0) { @@ -2237,7 +2252,7 @@ void TonalMDCTConceal_InsertNoise( } } - for (l = hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] + 1; l < crossOverFreq; l++) + for (l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++) { if (concealment_noise[l] > 0) { @@ -2259,7 +2274,7 @@ void TonalMDCTConceal_InsertNoise( { g *= (float)sqrt(cngLevelBackgroundTrace_bfi / hTonalMDCTConc->curr_noise_nrg_flt); - for (l = 0; l < hTonalMDCTConc->pTCI_float->lowerIndex[0]; l++) + for (l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++) { x = hTonalMDCTConc->lastBlockData.spectralData[l]; y = concealment_noise[l]; @@ -2274,9 +2289,9 @@ void TonalMDCTConceal_InsertNoise( } hTonalMDCTConc->faded_signal_nrg_flt += mdctSpectrum[l] * mdctSpectrum[l]; } - for (i = 1; i < hTonalMDCTConc->pTCI_float->numIndexes; i++) + for (i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++) { - for (l = hTonalMDCTConc->pTCI_float->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI_float->lowerIndex[i]; l++) + for (l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++) { x = hTonalMDCTConc->lastBlockData.spectralData[l]; y = concealment_noise[l]; @@ -2293,7 +2308,7 @@ void TonalMDCTConceal_InsertNoise( } } - for (l = hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] + 1; l < crossOverFreq; l++) + for (l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++) { x = hTonalMDCTConc->lastBlockData.spectralData[l]; y = concealment_noise[l]; @@ -2457,16 +2472,16 @@ void TonalMDCTConceal_InsertNoise( ELSE { Word16 l; - assert(hTonalMDCTConc->pTCI_float->numIndexes > 0); + assert(hTonalMDCTConc->pTCI->numIndexes > 0); - FOR (l = hTonalMDCTConc->pTCI_float->lowerIndex[0]; l <= hTonalMDCTConc->pTCI_float->upperIndex[0]; l++) + FOR (l = hTonalMDCTConc->pTCI->lowerIndex[0]; l <= hTonalMDCTConc->pTCI->upperIndex[0]; l++) { mdctSpectrum[l] = L_deposit_l(0); } ld = sub(14,norm_s(hTonalMDCTConc->lastBlockData.nSamples)); fac = shr(-32768,ld); - FOR (l = 0; l < hTonalMDCTConc->pTCI_float->lowerIndex[0]; l++) + FOR (l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 y; @@ -2482,19 +2497,19 @@ void TonalMDCTConceal_InsertNoise( tilt = mult_r(tilt,tiltFactor); } - FOR (i = 1; i < hTonalMDCTConc->pTCI_float->numIndexes; i++) + FOR (i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++) { - /*tilt *= (float)pow(tiltFactor, hTonalMDCTConc->pTCI_float->upperIndex[i-1]-hTonalMDCTConc->pTCI_float->lowerIndex[i-1]+1);*/ - tmp= round_fx(BASOP_Util_fPow(L_deposit_h(tiltFactor), 0, L_deposit_h(hTonalMDCTConc->pTCI_float->upperIndex[i-1]-hTonalMDCTConc->pTCI_float->lowerIndex[i-1]+1),15, &exp)); + /*tilt *= (float)pow(tiltFactor, hTonalMDCTConc->pTCI->upperIndex[i-1]-hTonalMDCTConc->pTCI->lowerIndex[i-1]+1);*/ + tmp= round_fx(BASOP_Util_fPow(L_deposit_h(tiltFactor), 0, L_deposit_h(hTonalMDCTConc->pTCI->upperIndex[i-1]-hTonalMDCTConc->pTCI->lowerIndex[i-1]+1),15, &exp)); tmp = shl(tmp, exp); tilt = mult_r(tilt,tmp); - FOR (l = hTonalMDCTConc->pTCI_float->lowerIndex[i]; l <= hTonalMDCTConc->pTCI_float->upperIndex[i]; l++) + FOR (l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++) { mdctSpectrum[l] = L_deposit_l(0); } - FOR (l = hTonalMDCTConc->pTCI_float->upperIndex[i-1]+1; l < hTonalMDCTConc->pTCI_float->lowerIndex[i]; l++) + FOR (l = hTonalMDCTConc->pTCI->upperIndex[i-1]+1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 y; @@ -2511,7 +2526,7 @@ void TonalMDCTConceal_InsertNoise( } } - tmp = round_fx(BASOP_Util_fPow(L_deposit_h(tiltFactor), 0, L_deposit_h(hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes-1]-hTonalMDCTConc->pTCI_float->lowerIndex[hTonalMDCTConc->pTCI_float->numIndexes-1]+1),15, &exp)); + tmp = round_fx(BASOP_Util_fPow(L_deposit_h(tiltFactor), 0, L_deposit_h(hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes-1]-hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes-1]+1),15, &exp)); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ #ifdef BASOP_NOGLOB tmp = shl_sat( tmp, exp ); @@ -2521,7 +2536,7 @@ void TonalMDCTConceal_InsertNoise( BASOP_SATURATE_WARNING_ON_EVS tilt = mult_r(tilt,tmp); - FOR (l = add(hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes-1], 1); l < crossOverFreq; l++) + FOR (l = add(hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes-1], 1); l < crossOverFreq; l++) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 y; @@ -2591,7 +2606,7 @@ void TonalMDCTConceal_InsertNoise( exp = 0; } - FOR (l = 0; l < hTonalMDCTConc->pTCI_float->lowerIndex[0]; l++) + FOR (l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 const y = mdctSpectrum[l]; @@ -2610,9 +2625,9 @@ void TonalMDCTConceal_InsertNoise( move32(); } - FOR (i = 1; i < hTonalMDCTConc->pTCI_float->numIndexes; i++) + FOR (i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++) { - FOR (l = hTonalMDCTConc->pTCI_float->upperIndex[i-1]+1; l < hTonalMDCTConc->pTCI_float->lowerIndex[i]; l++) + FOR (l = hTonalMDCTConc->pTCI->upperIndex[i-1]+1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 const y = mdctSpectrum[l]; @@ -2636,15 +2651,15 @@ void TonalMDCTConceal_InsertNoise( necessary, but currently the whole spectrum is rescaled in mdct_noiseShaping() and then there would be a processing of uninitialized values */ - FOR (i = 0; i < hTonalMDCTConc->pTCI_float->numIndexes; i++) + FOR (i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++) { - FOR (l = hTonalMDCTConc->pTCI_float->lowerIndex[i]; l <= hTonalMDCTConc->pTCI_float->upperIndex[i]; l++) + FOR (l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++) { mdctSpectrum[l] = L_deposit_l(0); } } - FOR (l = add(hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes-1], 1); l < crossOverFreq; l++) + FOR (l = add(hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes-1], 1); l < crossOverFreq; l++) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 const y = mdctSpectrum[l]; @@ -2697,11 +2712,11 @@ void TonalMDCTConceal_Apply( IF (hTonalMDCTConc->lastBlockData.blockIsValid & hTonalMDCTConc->secondLastBlockData.blockIsValid) { - assert(hTonalMDCTConc->pTCI_float->numIndexes > 0); + assert(hTonalMDCTConc->pTCI->numIndexes > 0); nSamples = hTonalMDCTConc->nNonZeroSamples; move16(); - assert(hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes-1] < nSamples); + assert(hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes-1] < nSamples); #ifdef IVAS_CODE_MDCT_GSHAPE IF (psychParamsCurrent == NULL) @@ -2720,8 +2735,8 @@ void TonalMDCTConceal_Apply( } #endif - phaseDiff = hTonalMDCTConc->pTCI_float->phaseDiff; /* if multiple frame loss occurs use the phase from the last frame and continue rotating */ - pCurrentPhase = hTonalMDCTConc->pTCI_float->phase_currentFramePredicted; + phaseDiff = hTonalMDCTConc->pTCI->phaseDiff; /* if multiple frame loss occurs use the phase from the last frame and continue rotating */ + pCurrentPhase = hTonalMDCTConc->pTCI->phase_currentFramePredicted; exp = sub(*mdctSpectrum_exp, add(add(hTonalMDCTConc->secondLastPowerSpectrum_exp, add(hTonalMDCTConc->secondLastBlockData.gain_tcx_exp,1)),hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e)); @@ -2737,7 +2752,7 @@ void TonalMDCTConceal_Apply( } } /* for each index group */ - FOR (i = 0; i < hTonalMDCTConc->pTCI_float->numIndexes; i++) + FOR (i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++) { /*phaseToAdd = hTonalMDCTConc->nFramesLost*phaseDiff[i]; */ phaseToAdd = L_mult0(hTonalMDCTConc->nFramesLost,phaseDiff[i]); /*Q1*3Q12=2Q13*/ @@ -2752,7 +2767,7 @@ void TonalMDCTConceal_Apply( phaseToAdd = L_add(phaseToAdd, 51472l/*2*EVS_PI Q13*/); } - FOR (l = hTonalMDCTConc->pTCI_float->lowerIndex[i]; l <= hTonalMDCTConc->pTCI_float->upperIndex[i]; l++) + FOR (l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++) { /* *pCurrentPhase and phaseToAdd are in range -PI..PI */ currentPhase = L_mac0(phaseToAdd, (*pCurrentPhase++), 1); /*2Q13+2Q13=3Q13*/ @@ -2786,7 +2801,7 @@ void TonalMDCTConceal_Apply_ivas_fx( const PsychoacousticParameters *psychParamsCurrent ) { - /* TODO: change pTCI_float to pTCI_float in this function. */ + /* TODO: change pTCI to pTCI in this function. */ Word16 i, l; Word16 *phaseDiff, *pCurrentPhase; @@ -2815,11 +2830,11 @@ void TonalMDCTConceal_Apply_ivas_fx( IF ( hTonalMDCTConc->lastBlockData.blockIsValid & hTonalMDCTConc->secondLastBlockData.blockIsValid ) { - assert( hTonalMDCTConc->pTCI_float->numIndexes > 0 ); + assert( hTonalMDCTConc->pTCI->numIndexes > 0 ); nSamples = hTonalMDCTConc->nNonZeroSamples; move16(); - assert( hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] < nSamples ); + assert( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] < nSamples ); //mvr2r( hTonalMDCTConc->secondLastPowerSpectrum_float, powerSpectrum_flt, nSamples ); /* Convert from 16 bits to 32 bits */ FOR (i = 0; i < nSamples; i++) { @@ -2893,8 +2908,8 @@ void TonalMDCTConceal_Apply_ivas_fx( powerSpectrum_exp = max_e; move16(); - phaseDiff = hTonalMDCTConc->pTCI_float->phaseDiff; /* if multiple frame loss occurs use the phase from the last frame and continue rotating */ - pCurrentPhase = hTonalMDCTConc->pTCI_float->phase_currentFramePredicted; + phaseDiff = hTonalMDCTConc->pTCI->phaseDiff; /* if multiple frame loss occurs use the phase from the last frame and continue rotating */ + pCurrentPhase = hTonalMDCTConc->pTCI->phase_currentFramePredicted; IF(!hTonalMDCTConc->lastBlockData.blockIsConcealed) { @@ -2911,7 +2926,7 @@ void TonalMDCTConceal_Apply_ivas_fx( } /* for each index group */ - FOR ( i = 0; i < hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + FOR ( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { phaseToAdd = L_mult0(hTonalMDCTConc->nFramesLost, phaseDiff[i]); /*Q1*3Q12=2Q13*/ @@ -2925,7 +2940,7 @@ void TonalMDCTConceal_Apply_ivas_fx( phaseToAdd = L_add(phaseToAdd, 51472l/*2*EVS_PI Q13*/); } - FOR ( l = hTonalMDCTConc->pTCI_float->lowerIndex[i]; l <= hTonalMDCTConc->pTCI_float->upperIndex[i]; l++ ) + FOR ( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { /* *pCurrentPhase and phaseToAdd are in range -PI..PI */ Word32 currentPhase = L_mac0(phaseToAdd, ( *pCurrentPhase++ ), 1); /*2Q13+2Q13=3Q13*/ @@ -3080,7 +3095,7 @@ void TonalMdctConceal_create_concealment_noise( max_noise_line = crossOverFreq; if (st->tonal_mdct_plc_active) { - max_noise_line = max(max_noise_line, hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] + 1); + max_noise_line = max(max_noise_line, hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1); } /* first lost frame is handled separately */ @@ -3162,7 +3177,7 @@ void TonalMdctConceal_create_concealment_noise( } if (st->tonal_mdct_plc_active) { - for (i = crossOverFreq; i < max(crossOverFreq, hTonalMDCTConc->pTCI_float->lowerIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1]); ++i) + for (i = crossOverFreq; i < max(crossOverFreq, hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1]); ++i) { concealment_noise[i] *= 0.0f; } diff --git a/lib_dec/updt_dec.c b/lib_dec/updt_dec.c index c7088ed2482b9a833c10eafb40ae152d4ff7e30e..3f37a73144e880505efcc0534f8aae1269066407 100644 --- a/lib_dec/updt_dec.c +++ b/lib_dec/updt_dec.c @@ -42,7 +42,7 @@ #include "cnst.h" #include #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * updt_dec() * @@ -776,3 +776,4 @@ void update_decoder_LPD_cng_flt( return; } +#endif diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 049dca937de510e1433a2922496a35dc2f1fa580..e24c95e12ad0e7bca2a85f97792b284acdb87687 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -964,8 +964,7 @@ void ivas_updt_dec_common_fx( Word32 log_energy_diff = L_abs(L_sub(st_fx->log_energy_old_fx , log_energy)); st_fx->log_energy_old_fx = log_energy; st_fx->log_energy_diff_lt_fx = Madd_32_16(Mpy_32_16_1(log_energy_diff, ENV_SMOOTH_FAC_FX ), st_fx->log_energy_diff_lt_fx, sub(MAX_16 , ENV_SMOOTH_FAC_FX)); - //To be deleted. - st_fx->log_energy_diff_lt = fixedToFloat(st_fx->log_energy_diff_lt_fx, Q15); + if (st_fx->core == HQ_CORE) { st_fx->stab_fac_fx = extract_l(L_min(MAX_16, L_add(L_shr(STAB_FAC_EST1_FX, Q15), Madd_32_32(L_shr(Mpy_32_16_1(STAB_FAC_EST2_FX , st_fx->hHQ_core->mem_env_delta), Q15), STAB_FAC_EST3_FX, st_fx->log_energy_diff_lt_fx)))); @@ -974,8 +973,6 @@ void ivas_updt_dec_common_fx( st_fx->stab_fac_smooth_lt_fx = extract_h(L_add(L_mult(ENV_SMOOTH_FAC_FX , st_fx->stab_fac_fx), L_mult(sub(MAX_16, ENV_SMOOTH_FAC_FX) , st_fx->stab_fac_smooth_lt_fx))); - //To be deleted - st_fx->stab_fac_smooth_lt = fixedToFloat(st_fx->stab_fac_smooth_lt_fx, Q15); } #endif IF( ((LE_32(st_fx->core_brate,SID_2k40))&&EQ_16(st_fx->cng_type,FD_CNG)) diff --git a/lib_dec/voiced_dec.c b/lib_dec/voiced_dec.c index fc51d2f869184266304357e28581214ef68ed5e2..37d6db9d51518ae21a31a592a9e37646593d29ee 100644 --- a/lib_dec/voiced_dec.c +++ b/lib_dec/voiced_dec.c @@ -47,7 +47,7 @@ * * Voiced decoder for SC-VBR *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) ivas_error ppp_voiced_decoder( Decoder_State *st, /* i/o: state structure */ float *out, /* o : residual signal */ @@ -239,14 +239,14 @@ ivas_error ppp_voiced_decoder( return error; } - +#endif /*---------------------------------------------------------------------* * sc_vbr_dec_init_flt() * * Initialize SC-VBR decoder *---------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void sc_vbr_dec_init_flt( SC_VBR_DEC_HANDLE hSC_VBR /* i/o: SC-VBR decoder handle */ ) @@ -276,3 +276,4 @@ void sc_vbr_dec_init_flt( return; } +#endif \ No newline at end of file diff --git a/lib_dec/waveadjust_fec_dec.c b/lib_dec/waveadjust_fec_dec.c index 9c0296eb2e918159b9146774dd63812773043649..6038ea775962258e29737aa239a79e3e545ccb36 100644 --- a/lib_dec/waveadjust_fec_dec.c +++ b/lib_dec/waveadjust_fec_dec.c @@ -455,7 +455,7 @@ static void add_noise( return; } - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) static int16_t waveform_adj( T_PLCInfo_HANDLE hPlcInfo, float *overlapbuf, @@ -542,13 +542,13 @@ static int16_t waveform_adj( return pitch; } - +#endif /*-------------------------------------------------------------------* * waveform_adj2() * *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void waveform_adj2( T_PLCInfo_HANDLE hPlcInfo, float *overlapbuf, @@ -639,7 +639,7 @@ void waveform_adj2( return; } - +#endif /*-------------------------------------------------------------------* * set_state_ivas() @@ -679,14 +679,22 @@ void concealment_init( hPlcInfo->L_frameTCX = L_frameTCX; hPlcInfo->Pitch = 0; hPlcInfo->T_bfi = 0; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hPlcInfo->outx_new_n1 = 0.0f; hPlcInfo->nsapp_gain = 0.0f; +#endif +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hPlcInfo->nsapp_gain_n = 0.0f; hPlcInfo->ener_mean = 59.4260f; +#endif +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hPlcInfo->ener = 0.0f; +#endif hPlcInfo->zp = L_frameTCX; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hPlcInfo->recovery_gain_float = 0.0f; hPlcInfo->step_concealgain = 0.0f; +#endif hPlcInfo->concealment_method = TCX_NONTONAL; hPlcInfo->subframe = 0; hPlcInfo->nbLostCmpt = 0; @@ -704,12 +712,12 @@ void concealment_init( { hPlcInfo->Transient[i] = 1; } - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) for ( i = 0; i < L_FRAME_MAX; i++ ) { hPlcInfo->data_reci2[i] = 0; } - +#endif return; } @@ -719,7 +727,7 @@ void concealment_init( * * *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void concealment_decode( const int16_t core, float *invkoef, @@ -747,14 +755,14 @@ void concealment_decode( return; } - +#endif /*-------------------------------------------------------------------* * concealment_update() * * *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void concealment_update( const int16_t bfi, const int16_t core, @@ -805,13 +813,14 @@ void concealment_update( } return; } - +#endif /*-------------------------------------------------------------------* * concealment_update2() * * *-------------------------------------------------------------------*/ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void concealment_update2( const float *outx_new, @@ -829,14 +838,14 @@ void concealment_update2( return; } - +#endif /*-------------------------------------------------------------------* * concealment_signal_tuning() * * *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void concealment_signal_tuning( Decoder_State *st, const int16_t bfi, @@ -888,3 +897,4 @@ void concealment_signal_tuning( return; } +#endif \ No newline at end of file diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 40d21e326f977355fdfc3a34098eba1611153502..923cd6eea966cbe84b727c4d48f8768362c340d5 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -422,20 +422,20 @@ ivas_error acelp_core_enc( Word16 lsp_new_fx[M]; Word16 tdm_lsfQ_PCh_fx[M]; Word16 lsf_wgts_fx[M]; - for (int i = 0; i < M; i++) + for (int ii = 0; ii < M; ii++) { - lsf_new_fx[i] = (Word16)((lsf_new[i]) * 2.56f); - tdm_lsfQ_PCh_fx[i] = (Word16)((tdm_lsfQ_PCh[i]) * 2.56f); - lsf_wgts_fx[i] = (Word16)((lsf_wgts[i]) * 2.56f); + lsf_new_fx[ii] = (Word16)((lsf_new[ii]) * 2.56f); + tdm_lsfQ_PCh_fx[ii] = (Word16)((tdm_lsfQ_PCh[ii]) * 2.56f); + lsf_wgts_fx[ii] = (Word16)((lsf_wgts[ii]) * 2.56f); } floatToFixed_arr(lsp_new, lsp_new_fx, 15, M); tdm_SCh_lsf_reuse_fx(ENC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, lsf_wgts_fx, &beta_index); - for (int i = 0; i < M; i++) + for (int ii = 0; ii < M; ii++) { - lsf_new[i] = (Word16)((lsf_new_fx[i]) / 2.56f); - lsf_wgts[i] = (Word16)((lsf_wgts_fx[i]) / 2.56f); + lsf_new[ii] = (Word16)((lsf_new_fx[ii]) / 2.56f); + lsf_wgts[ii] = (Word16)((lsf_wgts_fx[ii]) / 2.56f); } fixedToFloat_arr(lsp_new_fx, lsp_new, 15, M); #else diff --git a/lib_enc/ivas_agc_enc.c b/lib_enc/ivas_agc_enc.c index 0af4eb00c064f64cac8db8d7a3ac601b2530ee7b..aaab62ab6d2ae46e3eacd99765d12602760e1058 100644 --- a/lib_enc/ivas_agc_enc.c +++ b/lib_enc/ivas_agc_enc.c @@ -741,7 +741,6 @@ void ivas_agc_enc_process_fx( Word16 per_ch_bit[FOA_CHANNELS], AGC_flag; Word16 extendedExpVal = FALSE; Word16 isGainAdjusted; - Word32 gain; Word16 q_predMaxAbsVal, q_MaxAbsVal; ivas_agc_enc_state_t *pState = hAgcEnc; diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 41d6bca9ed4be0c3d48c52080b9c9212be9b1081..464d7b57001ecf9316149a54ff39bcd0786e7bc2 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -438,9 +438,9 @@ ivas_error ivas_enc( Word32 data_lfe_ch_fx[L_FRAME48k]; float max_val = 0; - for (int i = 0; i < input_frame; i++) { - if (max_val < (float)fabs(data_f[LFE_CHANNEL][i])) - max_val = (float)fabs(data_f[LFE_CHANNEL][i]); + for (int ii = 0; ii < input_frame; ii++) { + if (max_val < (float)fabs(data_f[LFE_CHANNEL][ii])) + max_val = (float)fabs(data_f[LFE_CHANNEL][ii]); } if ((Word32)max_val == 0) @@ -449,8 +449,8 @@ ivas_error ivas_enc( q_data_lfe_ch = norm_l((Word32)max_val); - for (int i = 0; i < input_frame; i++) { - data_lfe_ch_fx[i] = (Word32)(data_f[LFE_CHANNEL][i] * (1 << q_data_lfe_ch)); + for (int ii = 0; ii < input_frame; ii++) { + data_lfe_ch_fx[ii] = (Word32)(data_f[LFE_CHANNEL][ii] * (1 << q_data_lfe_ch)); } ivas_lfe_enc_fx( st_ivas->hLFE, data_lfe_ch_fx, q_data_lfe_ch, input_frame, st_ivas->hLFE->hBstr ); @@ -479,9 +479,9 @@ ivas_error ivas_enc( Word32 data_lfe_ch_fx[L_FRAME48k]; float max_val = 0; - for (int i = 0; i < input_frame; i++) { - if (max_val < (float)fabs(data_f[LFE_CHANNEL][i])) - max_val = (float)fabs(data_f[LFE_CHANNEL][i]); + for (int ii = 0; ii < input_frame; ii++) { + if (max_val < (float)fabs(data_f[LFE_CHANNEL][ii])) + max_val = (float)fabs(data_f[LFE_CHANNEL][ii]); } if ((Word32)max_val == 0) @@ -490,8 +490,8 @@ ivas_error ivas_enc( q_data_lfe_ch = norm_l((Word32)max_val); - for (int i = 0; i < input_frame; i++) { - data_lfe_ch_fx[i] = (Word32)(data_f[LFE_CHANNEL][i] * (1 << q_data_lfe_ch)); + for (int ii = 0; ii < input_frame; ii++) { + data_lfe_ch_fx[ii] = (Word32)(data_f[LFE_CHANNEL][ii] * (1 << q_data_lfe_ch)); } ivas_lfe_enc_fx(st_ivas->hLFE, data_lfe_ch_fx, q_data_lfe_ch, input_frame, st_ivas->hLFE->hBstr); diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index b0f53b9ebc855d4bcaf2065c8d6f4cb97db35e1b..ed2cc5a68ef7067addd4aaca52cd89e6335e70cd 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -56,8 +56,10 @@ static void ivas_param_mc_parameter_quantizer( const float *x, const int16_t L, static void ivas_param_mc_transient_detection( PARAM_MC_ENC_HANDLE hParamMC, TRAN_DET_HANDLE hTranDet, int16_t *bAttackPresent, int16_t *attackIdx ); +#ifndef FIX_901_PARAMMC_DEAD_CODE static void ivas_param_mc_enc_find_icc_map( PARAM_MC_ENC_HANDLE hParamMC, float Cx_sum[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], float Cy_sum[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float ILD_q[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_SZ_ILD_MAP], const int16_t nchan_input, const int16_t nchan_transport ); +#endif static void ivas_param_mc_quantize_iccs( PARAM_MC_ENC_HANDLE hParamMC, float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], const int16_t freq_idx, const int16_t nchan_input, int16_t *ICC_idx_out ); static void ivas_param_mc_quantize_ilds( PARAM_MC_ENC_HANDLE hParamMC, float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float Cx[PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], const int16_t freq_idx, const int16_t nchan_input, const int16_t nchan_transport, int16_t *ILD_idx_out, float ILD_q[PARAM_MC_SZ_ILD_MAP] ); @@ -80,7 +82,10 @@ ivas_error ivas_param_mc_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ) { - int16_t i, k, l; + int16_t i; +#ifndef FIX_901_PARAMMC_DEAD_CODE + int16_t k, l; +#endif IVAS_FB_CFG *fb_cfg; PARAM_MC_ENC_HANDLE hParamMC; uint16_t config_index; @@ -142,8 +147,12 @@ ivas_error ivas_param_mc_enc_open( } /* open/init parameter coding */ +#ifndef FIX_901_PARAMMC_DEAD_CODE ivas_param_mc_metadata_open( mc_input_setup, hParamMC->lfe_index, ivas_total_brate, &hParamMC->hMetadataPMC ); - +#else + ivas_param_mc_metadata_open( mc_input_setup, ivas_total_brate, &hParamMC->hMetadataPMC ); +#endif +#ifndef FIX_901_PARAMMC_DEAD_CODE /* init icc index states */ for ( i = 0; i < PARAM_MC_PARAMETER_FRAMES; i++ ) { @@ -160,6 +169,7 @@ ivas_error ivas_param_mc_enc_open( } } } +#endif /* Band Grouping */ if ( hParamMC->hMetadataPMC.num_parameter_bands == 20 ) @@ -225,7 +235,10 @@ ivas_error ivas_param_mc_enc_reconfig( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ) { - int16_t i, k, l; + int16_t i; +#ifndef FIX_901_PARAMMC_DEAD_CODE + int16_t k, l; +#endif PARAM_MC_ENC_HANDLE hParamMC; uint16_t config_index; MC_LS_SETUP mc_input_setup; @@ -266,6 +279,7 @@ ivas_error ivas_param_mc_enc_reconfig( /* get dmx factors */ hParamMC->dmx_factors = ivas_param_mc_conf[config_index].dmx_fac; +#ifndef FIX_901_PARAMMC_DEAD_CODE /* deallocate the full icc map, gets newly allocated in the metadata open function */ for ( i = 0; i < 2; i++ ) { @@ -276,9 +290,15 @@ ivas_error ivas_param_mc_enc_reconfig( } } +#endif /* open/init parameter coding */ +#ifndef FIX_901_PARAMMC_DEAD_CODE ivas_param_mc_metadata_open( mc_input_setup, hParamMC->lfe_index, ivas_total_brate, &hParamMC->hMetadataPMC ); +#else + ivas_param_mc_metadata_open( mc_input_setup, ivas_total_brate, &hParamMC->hMetadataPMC ); +#endif +#ifndef FIX_901_PARAMMC_DEAD_CODE /* init icc index states */ for ( i = 0; i < PARAM_MC_PARAMETER_FRAMES; i++ ) { @@ -296,6 +316,7 @@ ivas_error ivas_param_mc_enc_reconfig( } } +#endif /* Band Grouping */ if ( hParamMC->hMetadataPMC.num_parameter_bands == 20 ) { @@ -358,8 +379,9 @@ void ivas_param_mc_enc_close( return; } +#ifndef FIX_901_PARAMMC_DEAD_CODE ivas_param_mc_metadata_close( &( *hParamMC )->hMetadataPMC ); - +#endif ivas_FB_mixer_close( &( *hParamMC )->hFbMixer, sampling_rate, 0 ); free( ( *hParamMC ) ); @@ -489,6 +511,7 @@ void ivas_param_mc_enc( ivas_param_mc_quantize_ilds( hParamMC, Cy_sum[k], Cx_sum[k], k, nchan_inp, st_ivas->nchan_transport, ILD_idx, ILD_q[k] ); } +#ifndef FIX_901_PARAMMC_DEAD_CODE /* get icc map */ if ( hParamMC->hMetadataPMC.flag_use_adaptive_icc_map == 1 ) { @@ -499,6 +522,7 @@ void ivas_param_mc_enc( ivas_param_mc_default_icc_map( hParamMC->hMetadataPMC.icc_mapping_conf, hParamMC->hMetadataPMC.icc_mapping[hParamMC->hMetadataPMC.param_frame_idx] ); } +#endif /* ICC parameter quantization */ for ( k = 0; k < hParamMC->hMetadataPMC.nbands_coded; k += band_step ) { @@ -965,7 +989,7 @@ static void ivas_param_mc_param_est_enc( return; } - +#ifndef FIX_901_PARAMMC_DEAD_CODE /*------------------------------------------------------------------------- * ivas_param_mc_enc_find_icc_map() * @@ -1188,7 +1212,7 @@ static void ivas_param_mc_enc_find_icc_map( return; } - +#endif /*------------------------------------------------------------------------- * ivas_param_mc_quantize_ilds() @@ -1426,8 +1450,13 @@ static void ivas_param_mc_quantize_iccs( /* Reduce set of parameters and quantize them */ for ( k = 0; k < num_iccs_to_code; ++k ) { +#ifndef FIX_901_PARAMMC_DEAD_CODE tmp_map[0] = hParamMC->hMetadataPMC.icc_mapping[hParamMC->hMetadataPMC.param_frame_idx][k][0]; tmp_map[1] = hParamMC->hMetadataPMC.icc_mapping[hParamMC->hMetadataPMC.param_frame_idx][k][1]; +#else + tmp_map[0] = hParamMC->hMetadataPMC.icc_mapping_conf->icc_mapping[k][0]; + tmp_map[1] = hParamMC->hMetadataPMC.icc_mapping_conf->icc_mapping[k][1]; +#endif ICC_vect[k] = Cy[tmp_map[0]][tmp_map[1]]; } @@ -1605,6 +1634,7 @@ static void ivas_param_mc_write_bs( nbands = hParamMC->hMetadataPMC.nbands_coded / band_step + ( ( hParamMC->hMetadataPMC.nbands_coded % band_step ) ? 1 : 0 ); } +#ifndef FIX_901_PARAMMC_DEAD_CODE /* Encoding of the ICC mapping done as simple bitmap */ if ( hParamMC->hMetadataPMC.flag_use_adaptive_icc_map == 1 ) { @@ -1623,6 +1653,7 @@ static void ivas_param_mc_write_bs( *bit_pos += hParamMC->hMetadataPMC.icc_map_size_full - 1; } +#endif ivas_param_mc_encode_parameter( ICC_idx, &hParamMC->hMetadataPMC, &hParamMC->hMetadataPMC.icc_coding, nbands, band_step, icc_map_size_wo_lfe, icc_map_size, bit_buffer, bit_pos ); diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 7b938eae17f18b155edd17e3dd6fea746ce54709..3227e1017c809c1220b8639a203aefd09c01828f 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -784,8 +784,8 @@ static ivas_error ivas_spar_enc_process( #ifdef IVAS_FLOAT_FIXED Word32 pcm_tmp_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; Word32 *p_pcm_tmp_fx[DIRAC_MAX_ANA_CHANS]; - Word16 q_pcm_tmp_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; - Word16 *q_p_pcm_tmp_fx[DIRAC_MAX_ANA_CHANS]; + //Word16 q_pcm_tmp_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; + //Word16 *q_p_pcm_tmp_fx[DIRAC_MAX_ANA_CHANS]; Word16 q_pcm_fx[DIRAC_MAX_ANA_CHANS]; #endif int16_t i, j, input_frame, dtx_vad; diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index 4825edc607a835c9748232afe7bb35c4d6cec767..da68c4fe55ec48860f14a2ecc5e63fef72ee9c63 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -327,14 +327,14 @@ void stereo_classifier_init_fx( hStereoClassif->unclr_decision = 0; hStereoClassif->unclr_wscore_fx = 0; - set32_fx(hStereoClassif->unclr_fv_fx, -2147483648, SSC_MAX_NFEA);//Q31 + set32_fx(hStereoClassif->unclr_fv_fx, -2147483647 - 1, SSC_MAX_NFEA);//Q31 hStereoClassif->unclr_corrLagMax_prev = 0; hStereoClassif->ave_ener_L = 0; hStereoClassif->ave_ener_R = 0; hStereoClassif->relE_0_1_fx = 21474836; //Q31 hStereoClassif->relE_0_1_LT_fx = 21474836; //Q31 - set32_fx(hStereoClassif->xtalk_fv_fx, -2147483648, SSC_MAX_NFEA);//Q31 + set32_fx(hStereoClassif->xtalk_fv_fx, -2147483647 - 1, SSC_MAX_NFEA);//Q31 hStereoClassif->xtalk_wscore_fx = 0; hStereoClassif->xtalk_decision = 0; hStereoClassif->xtalk_score_wrelE_fx = 0; diff --git a/lib_enc/lsf_enc.c b/lib_enc/lsf_enc.c index 951d1145f91e23e5540424c4bf918772ffbbfba3..46949eab562f7a7364a99dbd37b7f68eacf0a41c 100644 --- a/lib_enc/lsf_enc.c +++ b/lib_enc/lsf_enc.c @@ -557,17 +557,17 @@ void lsf_end_enc( #ifdef IVAS_FLOAT_FIXED Word16 tdm_lsfQ_PCh_fx[M]; Word16 pred3_fx[M]; - for (int i = 0; i < M; i++) + for (int ii = 0; ii < M; ii++) { - tdm_lsfQ_PCh_fx[i] = (Word16)((tdm_lsfQ_PCh[i]) * 2.56f); - pred3_fx[i] = (Word16)((pred3[i]) * 2.56f); + tdm_lsfQ_PCh_fx[ii] = (Word16)((tdm_lsfQ_PCh[ii]) * 2.56f); + pred3_fx[ii] = (Word16)((pred3[ii]) * 2.56f); } tdm_SCh_LSF_intra_pred_fx(st->element_brate, tdm_lsfQ_PCh_fx, pred3_fx); - for (int i = 0; i < M; i++) + for (int ii = 0; ii < M; ii++) { - pred3[i] = (pred3_fx[i]) / 2.56f; + pred3[ii] = (pred3_fx[ii]) / 2.56f; } #else tdm_SCh_LSF_intra_pred( st->element_brate, tdm_lsfQ_PCh, pred3 ); diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 7050f8b64c93ff7dd908b22c0bd99c4fdba45b8e..fb421900391ce77ecc172f5823b9919559daba3c 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -2879,9 +2879,9 @@ ivas_error ivas_rend_openCrend( hRendCfg->roomAcoustics.dimensions.z_fx = (Word32)(hRendCfg->roomAcoustics.dimensions.z * 4194304); // Q10.22 - for ( int i = 0; i < 6; i++ ) + for ( int ii = 0; ii < 6; ii++ ) { - hRendCfg->roomAcoustics.AbsCoeff_fx[i] = (Word32)(hRendCfg->roomAcoustics.AbsCoeff[i] * 1073741824); // Q2.30 min :0 max 1 + hRendCfg->roomAcoustics.AbsCoeff_fx[ii] = (Word32)(hRendCfg->roomAcoustics.AbsCoeff[ii] * 1073741824); // Q2.30 min :0 max 1 } hRendCfg->roomAcoustics.ListenerOrigin.x_fx = (Word32)(hRendCfg->roomAcoustics.ListenerOrigin.x * 4194304); //( 2147483648 >> 2 ); diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index eb3ce6ccfeb8cbc81dd4a726f8276755a62d2b65..f8e79837ce0cd20f61df18559f59a1e892121349 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -48,7 +48,9 @@ #include "wmc_auto.h" - +#ifdef IVAS_FLOAT_FIXED +Word16 slot_fx[4] = {32767, 16384, 10922 ,8192}; +#endif /*------------------------------------------------------------------------- * Local constants *------------------------------------------------------------------------*/ @@ -59,7 +61,9 @@ #define SBA_CARDI_TARGET_ENERGY_GAIN 0.5f #define STEREO_PREPROCESS_IIR_FACTOR ( 0.9f ) - +#ifdef IVAS_FLOAT_FIXED +#define STEREO_PREPROCESS_IIR_FACTOR_Q15 (29491 ) +#endif /* powf(0.95f, 4.0f) for sub-frame smoothing instead of CLDFB slot */ #define ADAPT_HTPROTO_IIR_FAC 0.81450625f @@ -109,6 +113,10 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( DIRAC_DEC_BIN static void ivas_dirac_dec_binaural_process_output( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, HANDLE_CLDFB_FILTER_BANK cldfbSynDec[MAX_OUTPUT_CHANNELS], float *output_f[], float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const int16_t max_band_decorr, const int16_t numInChannels, const int16_t processReverb, const int16_t subframe ); +#ifdef IVAS_FLOAT_FIXED +static void ivas_dirac_dec_binaural_process_output_fx( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, HANDLE_CLDFB_FILTER_BANK cldfbSynDec[MAX_OUTPUT_CHANNELS], Word32 *output_fx[], Word16 *q_out,Word32 inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const Word16 max_band_decorr, const Word16 numInChannels, const Word16 processReverb, const Word16 subframe ); +#endif + static void adaptTransportSignalsHeadtracked( COMBINED_ORIENTATION_HANDLE hHeadTrackData, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const int16_t nBins, const int16_t nSlots, float Rmat[3][3] ); static void ivas_dirac_dec_binaural_check_and_switch_transports_headtracked( COMBINED_ORIENTATION_HANDLE hHeadTrackData, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const int16_t nBins, const int16_t nSlots, float Rmat[3][3] ); @@ -143,7 +151,6 @@ ivas_error ivas_dirac_dec_init_binaural_data( int16_t j, k, bin; float binCenterFreq, tmpFloat; ivas_error error; - float frequency_axis[CLDFB_NO_CHANNELS_MAX]; hDiracDecBin = st_ivas->hDiracDecBin; if ( hDiracDecBin == NULL ) @@ -169,6 +176,10 @@ ivas_error ivas_dirac_dec_init_binaural_data( { set_zero( hDiracDecBin->processMtxRe[j][k], nBins ); set_zero( hDiracDecBin->processMtxIm[j][k], nBins ); +#ifdef IVAS_FLOAT_FIXED //must be removed// + set_zero(hDiracDecBin->processMtxRePrev[j][k], nBins); + set_zero(hDiracDecBin->processMtxImPrev[j][k], nBins); +#endif } for ( k = 0; k < BINAURAL_CHANNELS; k++ ) @@ -259,10 +270,6 @@ ivas_error ivas_dirac_dec_init_binaural_data( #ifdef IVAS_FLOAT_FIXED Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX]; ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, nBins ); - FOR( Word16 i = 0; i < nBins; i++ ) - { - frequency_axis[i] = (float) frequency_axis_fx[i]; - } IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hDiracDecBin->h_freq_domain_decorr_ap_params ), &( hDiracDecBin->h_freq_domain_decorr_ap_state ), @@ -296,7 +303,7 @@ ivas_error ivas_dirac_dec_init_binaural_data( } #ifdef IVAS_FLOAT_FIXED - hDiracDecBin->reqularizationFactor = (float) configure_reqularization_factor_fx( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ) / ( 1 << 14 ); + hDiracDecBin->reqularizationFactor_fx = configure_reqularization_factor_fx( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); #else hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); #endif @@ -333,6 +340,196 @@ ivas_error ivas_dirac_dec_init_binaural_data( return IVAS_ERR_OK; } +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_dirac_dec_init_binaural_data_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i : HRTF structure for rendering */ +) +{ + DIRAC_DEC_BIN_HANDLE hDiracDecBin; + Word16 nBins; + Word32 output_Fs; + RENDERER_TYPE renderer_type; + Word16 j, k, bin; + ivas_error error; + hDiracDecBin = st_ivas->hDiracDecBin; + + IF ( hDiracDecBin == NULL ) + { + IF ( ( hDiracDecBin = (DIRAC_DEC_BIN_HANDLE) malloc( sizeof( DIRAC_DEC_BIN_DATA ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC binaural handle " ); + } + + hDiracDecBin->hTdDecorr = NULL; + hDiracDecBin->hReverb = NULL; + hDiracDecBin->h_freq_domain_decorr_ap_params = NULL; + hDiracDecBin->h_freq_domain_decorr_ap_state = NULL; + } + + output_Fs = st_ivas->hDecoderConfig->output_Fs; + move32(); + nBins = st_ivas->hSpatParamRendCom->num_freq_bands; + move16(); + renderer_type = st_ivas->renderer_type; + + FOR ( j = 0; j < BINAURAL_CHANNELS; j++ ) + { + FOR ( k = 0; k < BINAURAL_CHANNELS + MAX_NUM_OBJECTS; k++ ) + { +#if 1 /* todo: remove float */ + set_zero( hDiracDecBin->processMtxRe[j][k], nBins ); + set_zero( hDiracDecBin->processMtxIm[j][k], nBins ); + set_zero(hDiracDecBin->processMtxRePrev[j][k], nBins); + set_zero(hDiracDecBin->processMtxImPrev[j][k], nBins); +#endif + set16_fx(hDiracDecBin->processMtxRe_fx[j][k], 0, nBins); + set16_fx(hDiracDecBin->processMtxIm_fx[j][k], 0, nBins); + set16_fx(hDiracDecBin->processMtxRePrev_fx[j][k], 0, nBins); + set16_fx(hDiracDecBin->processMtxImPrev_fx[j][k], 0, nBins); + } + + FOR ( k = 0; k < BINAURAL_CHANNELS; k++ ) + { +#if 1 /* todo: remove float */ + set_zero( hDiracDecBin->processMtxDecRe[j][k], nBins ); + set_zero( hDiracDecBin->processMtxDecIm[j][k], nBins ); +#endif + set16_fx( hDiracDecBin->processMtxDecRe_fx[j][k], 0, nBins ); + set16_fx( hDiracDecBin->processMtxDecIm_fx[j][k], 0, nBins ); + } +#if 1 /* to be converted */ + set_zero( hDiracDecBin->ChEnePrev[j], nBins ); + set_zero( hDiracDecBin->ChEneOutPrev[j], nBins ); +#endif + } +#if 1 /* to be converted */ + set_zero( hDiracDecBin->ChCrossRePrev, nBins ); + set_zero( hDiracDecBin->ChCrossImPrev, nBins ); + set_zero( hDiracDecBin->ChCrossReOutPrev, nBins ); + set_zero( hDiracDecBin->ChCrossImOutPrev, nBins ); +#endif + hDiracDecBin->renderStereoOutputInsteadOfBinaural = 0; + + FOR ( bin = 0; bin < nBins; bin++ ) + { + float binCenterFreq, tmpFloat; + binCenterFreq = ( (float) bin + CLDFB_HALF_BIN_FREQUENCY_OFFSET ) / (float) nBins * ( (float) output_Fs / 2.0f ); + /* These formulas and values are from Christian Borss's publication for binaural diffuse field coherence */ + tmpFloat = max( 0.0f, 1.0f - binCenterFreq / 2700.0f ); + hDiracDecBin->diffuseFieldCoherence[bin] = tmpFloat * sinf( binCenterFreq * EVS_PI / 550.0f ) / ( binCenterFreq * EVS_PI / 550.0f ); + } + + for ( bin = 0; bin < BINAURAL_COHERENCE_DIFFERENCE_BINS; bin++ ) + { + hDiracDecBin->diffuseFieldCoherenceX[bin] = hDiracDecBin->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceX[bin]; + hDiracDecBin->diffuseFieldCoherenceY[bin] = hDiracDecBin->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceY[bin]; + hDiracDecBin->diffuseFieldCoherenceZ[bin] = hDiracDecBin->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceZ[bin]; + } + + if ( renderer_type == RENDERER_BINAURAL_PARAMETRIC ) /* Indication of binaural rendering without room effect */ + { + set_f( hDiracDecBin->earlyPartEneCorrection, 1.0f, CLDFB_NO_CHANNELS_MAX ); + hDiracDecBin->hReverb = NULL; + } + else if ( renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) /* Indication of binaural rendering with room effect */ + { + mvr2r( hHrtfParambin->parametricEarlyPartEneCorrection, hDiracDecBin->earlyPartEneCorrection, nBins ); + + /* reconfiguration needed when Reverb. parameters are changed -> close and open the handle again */ + if ( hDiracDecBin->hReverb != NULL && ( ( hDiracDecBin->hReverb->numBins != nBins ) || + ( hDiracDecBin->hReverb->blockSize != CLDFB_SLOTS_PER_SUBFRAME ) ) ) + { + ivas_binaural_reverb_close( &( hDiracDecBin->hReverb ) ); + } + + if ( hDiracDecBin->hReverb == NULL ) + { + /* Todo Philips: Room acoustics should be passed here once the underlying part works. Probably enough to pick it from st_ivas but you know best. */ + if ( ( error = ivas_binaural_reverb_open_parambin( &hDiracDecBin->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, output_Fs, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else if ( renderer_type == RENDERER_STEREO_PARAMETRIC ) + { + set_f( hDiracDecBin->earlyPartEneCorrection, 1.0f, CLDFB_NO_CHANNELS_MAX ); + hDiracDecBin->hReverb = NULL; + hDiracDecBin->renderStereoOutputInsteadOfBinaural = 1; + } + else /* Not valid renderer type for this renderer */ + { + assert( false ); + } + + hDiracDecBin->hDiffuseDist = NULL; /* Memory is allocated from stack during runtime when needed */ + + if ( hDiracDecBin->hTdDecorr == NULL ) + { + hDiracDecBin->useTdDecorr = 0; + } + + if ( hDiracDecBin->h_freq_domain_decorr_ap_params != NULL ) + { + ivas_dirac_dec_decorr_close( &hDiracDecBin->h_freq_domain_decorr_ap_params, &hDiracDecBin->h_freq_domain_decorr_ap_state ); + } + + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( hDiracDecBin->hTdDecorr ), &( hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( !hDiracDecBin->useTdDecorr && !( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM ) ) + { + Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX]; + ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, nBins ); + + IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hDiracDecBin->h_freq_domain_decorr_ap_params ), + &( hDiracDecBin->h_freq_domain_decorr_ap_state ), + nBins, + BINAURAL_CHANNELS, + BINAURAL_CHANNELS, + DIRAC_SYNTHESIS_PSD_LS, + frequency_axis_fx, + BINAURAL_CHANNELS, + output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + + } + + hDiracDecBin->reqularizationFactor_fx = configure_reqularization_factor_fx( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); + + st_ivas->hDiracDecBin = hDiracDecBin; + + /* allocate transport channels */ + if ( st_ivas->hTcBuffer == NULL ) + { + int16_t nchan_to_allocate; + int16_t n_samples_granularity; + + nchan_to_allocate = 2 * BINAURAL_CHANNELS; + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + nchan_to_allocate = 2 * BINAURAL_CHANNELS + 2; + } + + n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); /* Use the same granularity as tdrend */ + } + + IF ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, ivas_jbm_dec_get_num_tc_channels( st_ivas ), nchan_to_allocate, nchan_to_allocate, n_samples_granularity ) ) != IVAS_ERR_OK ) + { + return error; + } + } + return IVAS_ERR_OK; +} +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_close_binaural_data() @@ -352,7 +549,6 @@ void ivas_dirac_dec_close_binaural_data( IF ((*hBinaural)->hReverb != NULL) { - /*TODO : remove the float buffers being freed*/ ivas_binaural_reverb_close(&((*hBinaural)->hReverb)); } @@ -912,7 +1108,7 @@ static void ivas_dirac_dec_binaural_internal( { st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel[ind] = (Word32)(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[ind] * (1<<(31 - st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp))); } - Word16 q_cldfb[6][CLDFB_SLOTS_PER_SUBFRAME]; + Word16 q_cldfb[6][CLDFB_SLOTS_PER_SUBFRAME] = { 0 }; FOR(Word16 ind = 0; ind < 6; ind++) { FOR(Word16 ind2 = 0; ind2 < 4; ind2++) @@ -1134,23 +1330,69 @@ static void ivas_dirac_dec_binaural_internal( { st_ivas->cldfbAnaDec[cha]->cldfb_state[ind] = (float)(st_ivas->cldfbAnaDec[cha]->cldfb_state_fx[ind]) / (float)(1 << q_input); } - FOR(Word16 cha = 0; cha < 6; cha++) FOR(slot = 0; slot < 4; slot++) - FOR(Word16 ind = 0; ind < 60; ind++) + if (st_ivas->hSpar != NULL) { - Cldfb_RealBuffer_in[cha][slot][ind] = (float)Cldfb_RealBuffer_in_fx[cha][slot][ind] / (float)(1 << (q_cldfb[cha][slot])); - Cldfb_ImagBuffer_in[cha][slot][ind] = (float)Cldfb_ImagBuffer_in_fx[cha][slot][ind] / (float)(1 << (q_cldfb[cha][slot])); + floatToFixed_arrL(&st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], Q30, sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx) / sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0])); + for (int ii = 0; ii < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; ii++) + { + for (int jj = 0; jj < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; jj++) + { + floatToFixed_arrL(&st_ivas->hSpar->hMdDec->mixer_mat[ii][jj][0], + &st_ivas->hSpar->hMdDec->mixer_mat_fx[ii][jj][0], + Q30, + st_ivas->hSpar->hMdDec->mix_mat_dim_2); + } + } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// + if ( config_data.ivas_format == SBA_FORMAT || config_data.ivas_format == SBA_ISM_FORMAT ) { hDiracDecBin->hDiffuseDist = &diffuseDistData; + ivas_spar_param_to_masa_param_mapping_fx( st_ivas, Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, q_cldfb, subframe ); + ivas_sba_prototype_renderer_fx( st_ivas, Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, q_cldfb, subframe ); + } - ivas_spar_param_to_masa_param_mapping( st_ivas, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, subframe ); - ivas_sba_prototype_renderer( st_ivas, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, subframe ); + + //////////////////to be deletede from here + if (st_ivas->hDiracDecBin != NULL) + { + DIFFUSE_DISTRIBUTION_HANDLE hDiffuseDist = st_ivas->hDiracDecBin->hDiffuseDist; + IF(hDiffuseDist != NULL) + { + fixedToFloat_arrL(hDiffuseDist->diffuseRatioX_fx, hDiffuseDist->diffuseRatioX, Q31, CLDFB_NO_CHANNELS_MAX); + fixedToFloat_arrL(hDiffuseDist->diffuseRatioY_fx, hDiffuseDist->diffuseRatioY, Q31, CLDFB_NO_CHANNELS_MAX); + fixedToFloat_arrL(hDiffuseDist->diffuseRatioZ_fx, hDiffuseDist->diffuseRatioZ, Q31, CLDFB_NO_CHANNELS_MAX); + } + } + + + if (st_ivas->hSpar != NULL) + { + fixedToFloat_arrL(&st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], Q30, sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx) / sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0])); + for (int ii = 0; ii < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; ii++) + { + for (int jj = 0; jj < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; jj++) + { + fixedToFloat_arrL(&st_ivas->hSpar->hMdDec->mixer_mat_fx[ii][jj][0], + &st_ivas->hSpar->hMdDec->mixer_mat[ii][jj][0], + Q30, + st_ivas->hSpar->hMdDec->mix_mat_dim_2); + } + } + } + + FOR(Word16 cha = 0; cha < 6; cha++) FOR(slot = 0; slot < 4; slot++) + FOR(Word16 ind = 0; ind < 60; ind++) + { + Cldfb_RealBuffer_in[cha][slot][ind] = (float)Cldfb_RealBuffer_in_fx[cha][slot][ind] / (float)(1 << (q_cldfb[cha][slot])); + Cldfb_ImagBuffer_in[cha][slot][ind] = (float)Cldfb_ImagBuffer_in_fx[cha][slot][ind] / (float)(1 << (q_cldfb[cha][slot])); } + + //////////////////to be deletedeto here if ( st_ivas->ivas_format == MASA_ISM_FORMAT && nchan_transport == 2 && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) { ivas_omasa_preProcessStereoTransportsForMovedObjects( st_ivas, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, subframe ); @@ -1205,8 +1447,53 @@ static void ivas_dirac_dec_binaural_internal( ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat, subframe, hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, nchanSeparateChannels, st_ivas->hMasaIsmData ); - ivas_dirac_dec_binaural_process_output( hDiracDecBin, hSpatParamRendCom, st_ivas->cldfbSynDec, output_f, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, max_band_decorr, numInChannels, config_data.processReverb, subframe ); +#ifdef IVAS_FLOAT_FIXED + Word32 *output_fx[MAX_OUTPUT_CHANNELS]; + Word32 output_fx_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; + Word16 q_out; + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + output_fx[ch] = output_fx_buff[ch]; + } + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + FOR( slot = 0; slot < BINAURAL_CHANNELS; slot++ ) + { + floatToFixed_arr16( hDiracDecBin->processMtxDecRe[ch][slot], hDiracDecBin->processMtxDecRe_fx[ch][slot], Q11, nBins ); + floatToFixed_arr16( hDiracDecBin->processMtxDecIm[ch][slot], hDiracDecBin->processMtxDecIm_fx[ch][slot], Q11, nBins ); + floatToFixed_arr16( hDiracDecBin->processMtxDecRePrev[ch][slot], hDiracDecBin->processMtxDecRePrev_fx[ch][slot], Q11, nBins ); + floatToFixed_arr16( hDiracDecBin->processMtxDecImPrev[ch][slot], hDiracDecBin->processMtxDecImPrev_fx[ch][slot], Q11, nBins ); + } + } + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + FOR( slot = 0; slot < 4; slot++ ) + { + floatToFixed_arr16( hDiracDecBin->processMtxRe[ch][slot], hDiracDecBin->processMtxRe_fx[ch][slot], Q11, nBins ); + floatToFixed_arr16( hDiracDecBin->processMtxIm[ch][slot], hDiracDecBin->processMtxIm_fx[ch][slot], Q11, nBins ); + floatToFixed_arr16( hDiracDecBin->processMtxRePrev[ch][slot], hDiracDecBin->processMtxRePrev_fx[ch][slot], Q11, nBins ); + floatToFixed_arr16( hDiracDecBin->processMtxImPrev[ch][slot], hDiracDecBin->processMtxImPrev_fx[ch][slot], Q11, nBins ); + } + floatToFixed_arrL( st_ivas->cldfbSynDec[ch]->cldfb_state, st_ivas->cldfbSynDec[ch]->cldfb_state_fx, Q11, st_ivas->cldfbSynDec[ch]->p_filter_length ); + st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; + } + FOR( Word16 cha = 0; cha < 6; cha++ ) + FOR( slot = 0; slot < 4; slot++ ) + FOR( Word16 ind = 0; ind < 60; ind++ ) + { + Cldfb_RealBuffer_in_fx[cha][slot][ind] = float_to_fix( Cldfb_RealBuffer_in[cha][slot][ind], Q6 ); + Cldfb_ImagBuffer_in_fx[cha][slot][ind] = float_to_fix( Cldfb_ImagBuffer_in[cha][slot][ind], Q6 ); + } + ivas_dirac_dec_binaural_process_output_fx( hDiracDecBin, hSpatParamRendCom, st_ivas->cldfbSynDec, output_fx, &q_out, Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, max_band_decorr, numInChannels, config_data.processReverb, subframe ); + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + fixedToFloat_arrL32( output_fx[ch], output_f[ch], q_out, imult1616(nBins , hSpatParamRendCom->subframe_nbslots[subframe]) ); + fixedToFloat_arrL32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_state, st_ivas->cldfbSynDec[ch]->Q_cldfb_state, st_ivas->cldfbSynDec[ch]->p_filter_length ); + } +#else + ivas_dirac_dec_binaural_process_output( hDiracDecBin, hSpatParamRendCom, st_ivas->cldfbSynDec, output_f, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, max_band_decorr, numInChannels, config_data.processReverb, subframe ); +#endif hDiracDecBin->hDiffuseDist = NULL; hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe]; @@ -1855,7 +2142,12 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin->ChCrossRe[bin], hDiracDecBin->ChCrossIm[bin], hDiracDecBin->ChEneOut[0][bin], hDiracDecBin->ChEneOut[1][bin], hDiracDecBin->ChCrossReOut[bin], hDiracDecBin->ChCrossImOut[bin], - prototypeMtx, Mre, Mim, hDiracDecBin->reqularizationFactor ); + prototypeMtx, Mre, Mim, +#ifdef IVAS_FLOAT_FIXED + fix16_to_float(hDiracDecBin->reqularizationFactor_fx,Q14) ); +#else + hDiracDecBin->reqularizationFactor ); +#endif /* Load estimated covariance matrix to the [2][2] matrix form */ CxRe[0][0] = hDiracDecBin->ChEne[0][bin]; @@ -2028,6 +2320,200 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( } +#ifdef IVAS_FLOAT_FIXED +static void ivas_dirac_dec_binaural_process_output_fx( + DIRAC_DEC_BIN_HANDLE hDiracDecBin, + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, + HANDLE_CLDFB_FILTER_BANK cldfbSynDec[MAX_OUTPUT_CHANNELS], + Word32 *output_fx[], + Word16 *q_out, + Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + const Word16 max_band_decorr, + const Word16 numInChannels, + const Word16 processReverb, + const Word16 subframe ) +{ + Word16 slot, bin, chA, chB; + Word16 nBins; + Word16 offsetSamples; + Word16 nSlots; + + nBins = hSpatParamRendCom->num_freq_bands; + offsetSamples = 0; + nSlots = hSpatParamRendCom->subframe_nbslots[subframe]; + + Word32 decSlotRe_fx[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX], decSlotIm_fx[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word32 outSlotRe_fx[CLDFB_NO_CHANNELS_MAX], outSlotIm_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 reverbRe_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word32 reverbIm_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word16 q_inp[6][CLDFB_SLOTS_PER_SUBFRAME]; + Word16 interpVal_fx; + Word32 *decSlotRePointer_fx; + Word32 *decSlotImPointer_fx; + Word16 q_inp_mix, q_reverb = 31; + + + IF( processReverb ) + { + /* Process second / room effect part of binaural output when needed */ + ivas_binaural_reverb_processSubframe_fx( hDiracDecBin->hReverb, numInChannels, nSlots, inRe_fx, inIm_fx, reverbRe_fx, reverbIm_fx ); + } + + // scaling input and reverb to same q// + // input scaling is to maintain precision in ivas_dirac_dec_decorrelate_slot fn// + Word16 shift = s_min( L_norm_arr( cldfbSynDec[0]->cldfb_state_fx, cldfbSynDec[0]->p_filter_length ), L_norm_arr( cldfbSynDec[1]->cldfb_state_fx, cldfbSynDec[1]->p_filter_length ) ); + q_inp_mix = 31; + FOR( Word16 i = 0; i < 6; i++ ) + { + FOR( Word16 j = 0; j < nSlots; j++ ) + { + q_inp[i][j] = s_min( L_norm_arr( inRe_fx[i][j], nBins ), L_norm_arr( inIm_fx[i][j], nBins ) ); + IF( ( processReverb ) && ( i < 2 ) ) + { + q_reverb = s_min( L_norm_arr( reverbRe_fx[i][j], CLDFB_NO_CHANNELS_MAX ), L_norm_arr( reverbIm_fx[i][j], CLDFB_NO_CHANNELS_MAX ) ); + q_inp[i][j] = s_min( q_reverb, q_inp[i][j] ); + } + q_inp_mix = s_min( q_inp[i][j], q_inp_mix ); + } + } + + Word16 cldfb_state_shift = sub(add(q_inp_mix, Q1), cldfbSynDec[0]->Q_cldfb_state); + IF(GT_16(cldfb_state_shift, shift)) + { + q_inp_mix = q_inp_mix + shift - cldfb_state_shift; + cldfb_state_shift = shift; + } + + FOR( Word16 i = 0; i < 6; i++ ) + { + FOR( Word16 j = 0; j < nSlots; j++ ) + { + + scale_sig32(inRe_fx[i][j], nBins, q_inp_mix); + scale_sig32(inIm_fx[i][j], nBins, q_inp_mix); + IF( processReverb && ( i < 2 ) ) + { + scale_sig32(reverbRe_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub(q_inp_mix, 4)); + scale_sig32(reverbIm_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub(q_inp_mix, 4)); + } + } + } + + // scaling cldfb states to q_result-1// + scale_sig32(cldfbSynDec[0]->cldfb_state_fx, cldfbSynDec[0]->p_filter_length, cldfb_state_shift); + scale_sig32(cldfbSynDec[1]->cldfb_state_fx, cldfbSynDec[1]->p_filter_length, cldfb_state_shift); + + q_inp_mix = add(q_inp_mix, Q6); + + interpVal_fx = 0; + Word16 q_result = sub( q_inp_mix, 4 ); // setting it prior// + cldfbSynDec[0]->Q_cldfb_state = sub( q_result, 1 ); + cldfbSynDec[1]->Q_cldfb_state = sub( q_result, 1 ); + + FOR( slot = 0; slot < nSlots; slot++ ) + { + IF( NE_16( slot, sub( nSlots, 1 ) ) ) + { + interpVal_fx = add( interpVal_fx, slot_fx[nSlots - 1] ); + } + ELSE + { + interpVal_fx = 32767; + } + IF( !hDiracDecBin->useTdDecorr && (GT_16(max_band_decorr , 0)) ) + { + ivas_dirac_dec_decorrelate_slot_fx( hDiracDecBin, nBins, slot, inRe_fx, inIm_fx, q_inp_mix, decSlotRe_fx, decSlotIm_fx ); + } + + FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) + { + Word32 *outSlotRePr_fx, *outSlotImPr_fx; /* Pointers needed for function call compatibility */ + + set_zero_fx( outSlotRe_fx, CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( outSlotIm_fx, CLDFB_NO_CHANNELS_MAX ); + + /* Processing of the first / HRTF part of the binaural output. */ + FOR( chB = 0; chB < numInChannels; chB++ ) + { + IF( LT_16( chB, BINAURAL_CHANNELS ) ) + { + /* Decorrelator signal for TD decorrelation is stored in two input channels above the two normal inputs. + * It should be noted that TD decorrelation is used only in cases where numInChannels is 2. If this + * changes, additional adjustments are required. When using CLDFB decorrelator, we simply assign the + * pointers to buffers. */ + IF( hDiracDecBin->useTdDecorr ) + { + decSlotRePointer_fx = inRe_fx[chB + 2][slot]; + decSlotImPointer_fx = inIm_fx[chB + 2][slot]; + } + ELSE + { + decSlotRePointer_fx = decSlotRe_fx[chB]; + decSlotImPointer_fx = decSlotIm_fx[chB]; + } + } + ELSE + { + decSlotRePointer_fx = NULL; /* below these pointers are used only for chB < 2 */ + decSlotImPointer_fx = NULL; + } + + + FOR( bin = 0; bin < nBins; bin++ ) + { + Word16 gain; + + /* Mixing using the formulated processing matrix M */ + gain = add( mult( sub( 32767, interpVal_fx ), hDiracDecBin->processMtxRePrev_fx[chA][chB][bin] ), mult( interpVal_fx, hDiracDecBin->processMtxRe_fx[chA][chB][bin] ) ); // Q11 + + outSlotRe_fx[bin] = L_add( outSlotRe_fx[bin], Mpy_32_16_1( inRe_fx[chB][slot][bin], gain ) ); // q_inp_mix-4//q_result + outSlotIm_fx[bin] = L_add( outSlotIm_fx[bin], Mpy_32_16_1( inIm_fx[chB][slot][bin], gain ) ); // q_inp_mix-4//q_result + + gain = add( mult( sub( 32767, interpVal_fx ), hDiracDecBin->processMtxImPrev_fx[chA][chB][bin] ), mult( interpVal_fx, hDiracDecBin->processMtxIm_fx[chA][chB][bin] ) ); // Q11 + + // interpVal * hDiracDecBin->processMtxIm[chA][chB][bin]; + outSlotRe_fx[bin] = L_sub( outSlotRe_fx[bin], Mpy_32_16_1( inIm_fx[chB][slot][bin], gain ) ); // q_inp_mix-4//q_result + outSlotIm_fx[bin] = L_add( outSlotIm_fx[bin], Mpy_32_16_1( inRe_fx[chB][slot][bin], gain ) ); // q_inp_mix-4//q_result + + + /* Mixing decorrelated signals using the formulated residual processing matrix Mdec */ + IF( bin < max_band_decorr && chB < 2 ) + { + gain = add( mult( sub( 32767, interpVal_fx ), hDiracDecBin->processMtxDecRePrev_fx[chA][chB][bin] ), mult( interpVal_fx, hDiracDecBin->processMtxDecRe_fx[chA][chB][bin] ) ); + // interpVal * hDiracDecBin->processMtxDecRe[chA][chB][bin]; + outSlotRe_fx[bin] = L_add( outSlotRe_fx[bin], Mpy_32_16_1( decSlotRePointer_fx[bin], gain ) ); // q_inp_mix-4//q_result + outSlotIm_fx[bin] = L_add( outSlotIm_fx[bin], Mpy_32_16_1( decSlotImPointer_fx[bin], gain ) ); // q_inp_mix-4//q_result + + + gain = add( mult( sub( 32767, interpVal_fx ), hDiracDecBin->processMtxDecImPrev_fx[chA][chB][bin] ), mult( interpVal_fx, hDiracDecBin->processMtxDecIm_fx[chA][chB][bin] ) ); + outSlotRe_fx[bin] = L_sub( outSlotRe_fx[bin], Mpy_32_16_1( decSlotImPointer_fx[bin], gain ) ); // q_inp_mix-4//q_result + outSlotIm_fx[bin] = L_add( outSlotIm_fx[bin], Mpy_32_16_1( decSlotRePointer_fx[bin], gain ) ); // q_inp_mix-4//q_result + } + } + } + + + IF( processReverb ) + { + /* Combine second (reverb) part with the first (HRTF) part to obtain binaural output signal with room effect */ + v_add_fx( outSlotRe_fx, reverbRe_fx[chA][slot], outSlotRe_fx, CLDFB_NO_CHANNELS_MAX ); + v_add_fx( outSlotIm_fx, reverbIm_fx[chA][slot], outSlotIm_fx, CLDFB_NO_CHANNELS_MAX ); + } + + + outSlotRePr_fx = &( outSlotRe_fx[0] ); + outSlotImPr_fx = &( outSlotIm_fx[0] ); + + cldfbSynthesis_ivas_fx( &outSlotRePr_fx, &outSlotImPr_fx, &( output_fx[chA][nBins * slot + offsetSamples] ), nBins, cldfbSynDec[chA] ); + cldfbSynDec[chA]->Q_cldfb_state = sub( q_result, 1 ); + } + } + *q_out = sub( q_result, 1 ); + return; +} + +#else static void ivas_dirac_dec_binaural_process_output( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, @@ -2038,8 +2524,7 @@ static void ivas_dirac_dec_binaural_process_output( const int16_t max_band_decorr, const int16_t numInChannels, const int16_t processReverb, - const int16_t subframe -) + const int16_t subframe ) { int16_t slot, bin, chA, chB; int16_t nBins; @@ -2060,7 +2545,7 @@ static void ivas_dirac_dec_binaural_process_output( if ( processReverb ) { /* Process second / room effect part of binaural output when needed */ - ivas_binaural_reverb_processSubframe( hDiracDecBin->hReverb, numInChannels, nSlots, inRe, inIm, reverbRe, reverbIm ); + ivas_binaural_reverb_processSubframe( hDiracDecBin->hReverb, numInChannels, nSlots, inRe, inIm, reverbRe, reverbIm ); } interpVal = 0.0f; @@ -2069,35 +2554,7 @@ static void ivas_dirac_dec_binaural_process_output( interpVal += 1.0f / (float) nSlots; if ( !hDiracDecBin->useTdDecorr && max_band_decorr > 0 ) { -#ifdef IVAS_FLOAT_FIXED - Word16 q_inp; - //q_inp = Q6;// fixed Q6 giving high distortion in o/p// - Word32 decSlotRe_fx[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX], decSlotIm_fx[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; - Word32 inRe_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], inIm_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - Word16 q_inp_1 = s_min(Q_factor_arrL(inRe[0][slot], nBins), Q_factor_arrL(inIm[0][slot], nBins)); - Word16 q_inp_2 = s_min(Q_factor_arrL(inRe[1][slot], nBins), Q_factor_arrL(inIm[1][slot], nBins)); - q_inp = s_min(q_inp_1, q_inp_2); - FOR(Word16 cha = 0; cha < BINAURAL_CHANNELS; cha++) - { - FOR(Word16 ind = 0; ind < nBins; ind++) - { - inRe_fx[cha][slot][ind] = float_to_fix(inRe[cha][slot][ind], q_inp); - inIm_fx[cha][slot][ind] = float_to_fix(inIm[cha][slot][ind], q_inp); - } - } - ivas_dirac_dec_decorrelate_slot_fx( hDiracDecBin, nBins, slot, inRe_fx, inIm_fx, q_inp, decSlotRe_fx, decSlotIm_fx); - FOR (Word16 ch_t = 0; ch_t < BINAURAL_CHANNELS; ch_t++) - { - FOR (Word16 bin_t = 0; bin_t < nBins; bin_t++) - { - decSlotRe[ch_t][bin_t] = fix_to_float(decSlotRe_fx[ch_t][bin_t],q_inp); - decSlotIm[ch_t][bin_t] = fix_to_float(decSlotIm_fx[ch_t][bin_t], q_inp); - } - } - -#else - ivas_dirac_dec_decorrelate_slot(hDiracDecBin, nBins, slot, inRe, inIm, decSlotRe, decSlotIm); -#endif + ivas_dirac_dec_decorrelate_slot( hDiracDecBin, nBins, slot, inRe, inIm, decSlotRe, decSlotIm ); } for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) @@ -2182,7 +2639,7 @@ static void ivas_dirac_dec_binaural_process_output( return; } - +#endif static void adaptTransportSignalsHeadtracked( COMBINED_ORIENTATION_HANDLE hHeadTrackData, @@ -3015,6 +3472,345 @@ Word16 configure_reqularization_factor_fx( return reqularizationFactor; } #endif + +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * ivas_omasa_preProcessStereoTransportsForMovedObjects_fx() + * + * + *-------------------------------------------------------------------*/ + +void ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( + Decoder_Struct *st_ivas, + Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + Word16 *cldfb_buf_q, + const Word16 nBins, + const Word16 subframe ) +{ + Word16 bin, ch, inCh, outCh, ismDirIndex, slot; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + MASA_ISM_DATA_HANDLE hMasaIsmData; + UWord8 enableCentering; + Word16 dirac_read_idx; + Word16 nSlots; + + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + hMasaIsmData = st_ivas->hMasaIsmData; + + IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) + { + enableCentering = 0; + move16(); + } + ELSE + { + enableCentering = 1; + move16(); + } + + /* Bypass processing until first object is moved */ + IF( EQ_16( hMasaIsmData->objectsMoved, 0 ) ) + { + FOR( ismDirIndex = 0; ismDirIndex < hSpatParamRendCom->numIsmDirections; ismDirIndex++ ) + { + IF( hMasaIsmData->ism_is_edited[ismDirIndex] ) + { + hMasaIsmData->objectsMoved = 1; + move16(); + } + } + IF( EQ_16( hMasaIsmData->objectsMoved, 0 ) ) + { + /* No objects have moved so far */ + return; + } + } + + /* Perform object-movement based processing */ + nSlots = hSpatParamRendCom->subframe_nbslots[subframe]; + move16(); + dirac_read_idx = hSpatParamRendCom->render_to_md_map[subframe]; + move16(); + + FOR( bin = 0; bin < nBins; bin++ ) + { + Word16 ismPreprocMtxNew_fx[2][2]; + Word16 ismPreprocMtxIncrement_fx[2][2]; + Word16 eneMove_fx[2]; + Word16 enePreserve_fx[2]; + Word16 ismRatioAcc_fx; + Word32 subframeEne_fx; + Word32 Enes_fx[2]; + Word16 normEnes_fx[2]; + Word16 remainderNormEne_fx; + Word16 normEnes_q_fx[2], temp_q = 0, subframeEne_q_fx, ismRatioAcc_q_fx; + Word16 eneMove_q_fx[2], enePreserve_q_fx[2], temp1; + Word32 temp; + + set_s( ismPreprocMtxNew_fx[0], 0, 2 ); + set_s( ismPreprocMtxNew_fx[1], 0, 2 ); + set_s( ismPreprocMtxIncrement_fx[0], 0, 2 ); + set_s( ismPreprocMtxIncrement_fx[1], 0, 2 ); + set_s( eneMove_fx, 0, 2 ); + set_s( enePreserve_fx, 0, 2 ); + ismRatioAcc_fx = 0; + move16(); + subframeEne_fx = 0; + move32(); + set_s( normEnes_fx, 0, 2 ); + set_l( Enes_fx, 0, 2 ); + set_s( normEnes_q_fx, Q31, 2 ); + set_s( eneMove_q_fx, Q31, 2 ); + set_s( enePreserve_q_fx, Q31, 2 ); + + /* Determine transport normalized energies and subframe energy */ + FOR( slot = 0; slot < nSlots; slot++ ) + { + FOR( ch = 0; ch < 2; ch++ ) + { + Enes_fx[ch] = L_add( Enes_fx[ch], Mpy_32_32( inRe_fx[ch][slot][bin], inRe_fx[ch][slot][bin] ) ); + move32(); + Enes_fx[ch] = L_add( Enes_fx[ch], Mpy_32_32( inIm_fx[ch][slot][bin], inIm_fx[ch][slot][bin] ) ); // Q = *cldfb_buf_q + *cldfb_buf_q - 31 = -19 + move32(); + } + + subframeEne_fx = L_add( Enes_fx[0], Enes_fx[1] ); + subframeEne_q_fx = sub( add( *cldfb_buf_q, *cldfb_buf_q ), 31 ); // Q = -19 + + IF( NE_32( subframeEne_fx, 0 ) ) + { + normEnes_fx[0] = BASOP_Util_Divide3232_Scale( Enes_fx[0], subframeEne_fx, &temp_q ); + move32(); + normEnes_fx[0] = shr( normEnes_fx[0], sub( sub( 15, temp_q ), Q12 ) ); // Q12 + move32(); + normEnes_fx[1] = BASOP_Util_Divide3232_Scale( Enes_fx[1], subframeEne_fx, &temp_q ); + move32(); + normEnes_fx[1] = shr( normEnes_fx[1], sub( sub( 15, temp_q ), Q12 ) ); // Q12 + move32(); + } + ELSE + { + normEnes_fx[0] = BASOP_Util_Divide3232_Scale( Enes_fx[0], EPSILON_FX, &temp_q ); + move32(); + normEnes_fx[0] = shr( normEnes_fx[0], sub( sub( 15, temp_q ), Q12 ) ); // Q12 + move32(); + normEnes_fx[1] = BASOP_Util_Divide3232_Scale( Enes_fx[1], EPSILON_FX, &temp_q ); + move32(); + normEnes_fx[1] = shr( normEnes_fx[1], sub( sub( 15, temp_q ), Q12 ) ); // Q12 + move32(); + } + + + /* For each ismDir, formulate a mix-matrix that moves object audio signals between + * left and right channels when needed. Make a combined matrix by a ratio-weighted sum */ + FOR( ismDirIndex = 0; ismDirIndex < hSpatParamRendCom->numIsmDirections; ismDirIndex++ ) + { + Word16 panGainsOut_fx[2]; + Word16 panGainsIn_fx[2]; + Word16 ratio; + Word16 panEnesOut_fx[2]; + Word16 panEnesIn_fx[2]; + Word16 centeringFactor_fx; + + ratio = extract_l( hMasaIsmData->energy_ratio_ism_fx[ismDirIndex][dirac_read_idx][bin] ); // Q14 + ismRatioAcc_fx = add( ismRatioAcc_fx, ratio ); + ismRatioAcc_q_fx = Q14; + move16(); + + /* Get input and output panning gains */ + ivas_get_stereo_panning_gains_fx( hMasaIsmData->azimuth_ism[ismDirIndex][dirac_read_idx], + hMasaIsmData->elevation_ism[ismDirIndex][dirac_read_idx], + panGainsIn_fx ); + + IF( hMasaIsmData->ism_is_edited[ismDirIndex] ) + { + ivas_get_stereo_panning_gains_fx( hMasaIsmData->azimuth_ism_edited[ismDirIndex], + hMasaIsmData->elevation_ism_edited[ismDirIndex], + panGainsOut_fx ); + } + ELSE + { + /* When not edited, input and output pan gains are the same */ + FOR( ch = 0; ch < 2; ch++ ) + { + panGainsOut_fx[ch] = panGainsIn_fx[ch]; + move16(); + } + } + + /* Determine pan enes */ + FOR( ch = 0; ch < 2; ch++ ) + { + panEnesOut_fx[ch] = mult( panGainsOut_fx[ch], panGainsOut_fx[ch] ); // Q15 + move16(); + panEnesIn_fx[ch] = mult( panGainsIn_fx[ch], panGainsIn_fx[ch] ); // Q15 + move16(); + } + + IF( enableCentering ) + { + centeringFactor_fx = s_max( 0, sub( mult( shl( 2, 13 ), abs_s( sub( panEnesIn_fx[0], panEnesOut_fx[0] ) ) ), ONE_IN_Q13 ) ); // Q13 + FOR( ch = 0; ch < 2; ch++ ) + { + panEnesOut_fx[ch] = mult( panEnesOut_fx[ch], sub( ONE_IN_Q13, centeringFactor_fx ) ); // Q13 + move16(); + panEnesOut_fx[ch] = add( panEnesOut_fx[ch], shr( centeringFactor_fx, 1 ) ); // Q13 + move16(); + } + } + + FOR( ch = 0; ch < 2; ch++ ) + { + Word16 eneMoveThis_fx; + Word16 enePreserveThis_fx; + + eneMoveThis_fx = s_max( 0, sub( shr( panEnesIn_fx[ch], 2 ), panEnesOut_fx[ch] ) ); // Q13 + enePreserveThis_fx = sub( shr( panEnesIn_fx[ch], 2 ), eneMoveThis_fx ); // Q13 + + eneMove_fx[ch] = mult( ratio, eneMoveThis_fx ); // Q = 14 + 13 - 15 = 12 + move16(); + enePreserve_fx[ch] = mult( ratio, enePreserveThis_fx ); // Q = 14 + 13 - 15 = 12 + move16(); + + /* Subtract object parts from normEnes */ + normEnes_fx[ch] = sub( normEnes_fx[ch], shr( mult( panEnesIn_fx[ch], ratio ), 2 ) ); // Q12 + move16(); + } + } + + /* Any remaining (non-object) energy is set to be preserved at both channels */ + remainderNormEne_fx = s_max( 0, sub( sub( shr( sub( ONE_IN_Q14, ismRatioAcc_fx ), sub( Q14, Q12 ) ), normEnes_fx[0] ), normEnes_fx[1] ) ); // Q12 + + FOR( ch = 0; ch < 2; ch++ ) + { + enePreserve_fx[ch] = add( enePreserve_fx[ch], s_max( 0, add( enePreserve_fx[ch], shr( remainderNormEne_fx, 1 ) ) ) ); // Q12 + move16(); + } + + /* Temporally average energy moving and preserving, and generate the transport signal preprocessing matrix */ + FOR( ch = 0; ch < 2; ch++ ) + { + Word32 normVal_fx; + hMasaIsmData->eneMoveIIR_fx[ch][bin] = Mpy_32_16_1( hMasaIsmData->eneMoveIIR_fx[ch][bin], STEREO_PREPROCESS_IIR_FACTOR_Q15 ); + move32(); + temp = Mpy_32_16_1( subframeEne_fx, eneMove_fx[ch] ); + hMasaIsmData->eneMoveIIR_fx[ch][bin] = L_add( hMasaIsmData->eneMoveIIR_fx[ch][bin], temp ); // Q = subframeEne_q_fx - 3 + move32(); + + hMasaIsmData->enePreserveIIR_fx[ch][bin] = Mpy_32_16_1( hMasaIsmData->enePreserveIIR_fx[ch][bin], STEREO_PREPROCESS_IIR_FACTOR_Q15 ); + move32(); + temp = Mpy_32_16_1( subframeEne_fx, enePreserve_fx[ch] ); + hMasaIsmData->enePreserveIIR_fx[ch][bin] = L_add( hMasaIsmData->enePreserveIIR_fx[ch][bin], temp ); // Q = subframeEne_q_fx - 3 + move32(); + + normVal_fx = L_add( hMasaIsmData->eneMoveIIR_fx[ch][bin], hMasaIsmData->enePreserveIIR_fx[ch][bin] ); + IF( NE_32( normVal_fx, 0 ) ) + { + + temp1 = BASOP_Util_Divide3232_Scale( hMasaIsmData->enePreserveIIR_fx[ch][bin], normVal_fx, &temp_q ); + ismPreprocMtxNew_fx[ch][ch] = Sqrt16( temp1, &temp_q ); + move16(); + ismPreprocMtxNew_fx[ch][ch] = shl( ismPreprocMtxNew_fx[ch][ch], temp_q ); // Q15 + move16(); + temp1 = BASOP_Util_Divide3232_Scale( hMasaIsmData->eneMoveIIR_fx[ch][bin], normVal_fx, &temp_q ); + ismPreprocMtxNew_fx[sub( 1, ch )][ch] = Sqrt16( temp1, &temp_q ); + move16(); + ismPreprocMtxNew_fx[sub( 1, ch )][ch] = shl( ismPreprocMtxNew_fx[sub( 1, ch )][ch], temp_q ); // Q15 + move16(); + } + ELSE + { + ismPreprocMtxNew_fx[ch][ch] = 0; + move16(); + ismPreprocMtxNew_fx[sub( 1, ch )][ch] = 0; + move16(); + } + } + + /* Get increment value for temporal interpolation */ + FOR( inCh = 0; inCh < 2; inCh++ ) + { + FOR( outCh = 0; outCh < 2; outCh++ ) + ismPreprocMtxIncrement_fx[outCh][inCh] = BASOP_Util_Divide1616_Scale( sub( ismPreprocMtxNew_fx[outCh][inCh], hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][bin] ), nSlots, &temp_q ); + move16(); + ismPreprocMtxIncrement_fx[outCh][inCh] = shl( ismPreprocMtxIncrement_fx[outCh][inCh], temp_q ); // Q15 + move16(); + } + } + + /* Mix signals */ + FOR( slot = 0; slot < nSlots; slot++ ) + { + Word16 eqVal_fx = 0; + Word16 eqVal_q_fx = 0; + Word32 outSlotRe_fx[2]; + Word32 outSlotIm_fx[2]; + + set_zero_fx( outSlotRe_fx, 2 ); + set_zero_fx( outSlotIm_fx, 2 ); + + FOR( outCh = 0; outCh < 2; outCh++ ) + { + FOR( inCh = 0; inCh < 2; inCh++ ) + { + hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][bin] = add( hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][bin], ismPreprocMtxIncrement_fx[outCh][inCh] ); // Q = 15 + move16(); + outSlotRe_fx[outCh] = Mpy_32_16_1( inRe_fx[inCh][slot][bin], hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][bin] ); // Q = *cldfb_buf_q = 6; + move32(); + outSlotIm_fx[outCh] = Mpy_32_16_1( inIm_fx[inCh][slot][bin], hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][bin] ); // Q = *cldfb_buf_q = 6; + move32(); + } + } + + /* IIR average the energy measures and determine and apply energy-preserving equalizer */ + hMasaIsmData->preprocEneTarget_fx[bin] = Mpy_32_16_1( hMasaIsmData->preprocEneTarget_fx[bin], STEREO_PREPROCESS_IIR_FACTOR_Q15 ); + move32(); + hMasaIsmData->preprocEneRealized_fx[bin] = Mpy_32_16_1( hMasaIsmData->preprocEneRealized_fx[bin], STEREO_PREPROCESS_IIR_FACTOR_Q15 ); + move32(); + FOR( ch = 0; ch < 2; ch++ ) + { + hMasaIsmData->preprocEneTarget_fx[bin] = L_add( hMasaIsmData->preprocEneTarget_fx[bin], Madd_32_32( Mpy_32_32( inRe_fx[ch][slot][bin], inRe_fx[ch][slot][bin] ), inIm_fx[ch][slot][bin], inIm_fx[ch][slot][bin] ) ); // Q= *cldfb_buf_q + *cldfb_buf_q - 31 = -19 + move32(); + hMasaIsmData->preprocEneRealized_fx[bin] = L_add( hMasaIsmData->preprocEneRealized_fx[bin], Madd_32_32( Mpy_32_32( outSlotRe_fx[ch], outSlotRe_fx[ch] ), outSlotIm_fx[ch], outSlotIm_fx[ch] ) ); // Q= *cldfb_buf_q + *cldfb_buf_q - 31 = -19 + move32(); + } + temp1 = BASOP_Util_Divide3232_Scale( hMasaIsmData->preprocEneTarget_fx[bin], L_max( EPSILON_FX, hMasaIsmData->preprocEneRealized_fx[bin] ), &eqVal_q_fx ); + eqVal_fx = Sqrt16( temp1, &eqVal_q_fx ); + temp1 = shl( 4, Q12 ); + IF( LT_16( eqVal_q_fx, Q12 ) ) + { + IF( GT_16( eqVal_fx, shr( temp1, sub( Q12, eqVal_q_fx ) ) ) ) + { + eqVal_fx = temp1; + move16(); + eqVal_q_fx = Q12; + move16(); + } + } + ELSE + { + IF( GT_16( shr( eqVal_fx, sub( eqVal_q_fx, Q12 ) ), temp1 ) ) + { + eqVal_fx = temp1; + move16(); + } + } + + FOR( ch = 0; ch < 2; ch++ ) + { + inRe_fx[ch][slot][bin] = Mpy_32_16_1( outSlotRe_fx[ch], eqVal_fx ); + move32(); + inIm_fx[ch][slot][bin] = Mpy_32_16_1( outSlotIm_fx[ch], eqVal_fx ); + move32(); + } + *cldfb_buf_q = sub( add( *cldfb_buf_q, eqVal_q_fx ), 15 ); + } + } + + return; +} +#endif /*-------------------------------------------------------------------* * ivas_omasa_preProcessStereoTransportsForMovedObjects() * @@ -3368,7 +4164,60 @@ static void ivas_masa_ext_rend_parambin_internal( hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, 0, NULL ); + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef IVAS_FLOAT_FIXED + Word32 *output_fx[MAX_OUTPUT_CHANNELS]; + Word32 output_fx_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; + Word32 Cldfb_RealBuffer_in_fx[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word32 Cldfb_ImagBuffer_in_fx[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word16 q_out; + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + output_fx[ch] = output_fx_buff[ch]; + } + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + FOR( slot = 0; slot < BINAURAL_CHANNELS; slot++ ) + { + floatToFixed_arr16( hDiracDecBin->processMtxDecRe[ch][slot], hDiracDecBin->processMtxDecRe_fx[ch][slot], Q11, nBins ); + floatToFixed_arr16( hDiracDecBin->processMtxDecIm[ch][slot], hDiracDecBin->processMtxDecIm_fx[ch][slot], Q11, nBins ); + floatToFixed_arr16( hDiracDecBin->processMtxDecRePrev[ch][slot], hDiracDecBin->processMtxDecRePrev_fx[ch][slot], Q11, nBins ); + floatToFixed_arr16( hDiracDecBin->processMtxDecImPrev[ch][slot], hDiracDecBin->processMtxDecImPrev_fx[ch][slot], Q11, nBins ); + } + } + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + FOR( slot = 0; slot < 4; slot++ ) + { + floatToFixed_arr16( hDiracDecBin->processMtxRe[ch][slot], hDiracDecBin->processMtxRe_fx[ch][slot], Q11, nBins ); + floatToFixed_arr16( hDiracDecBin->processMtxIm[ch][slot], hDiracDecBin->processMtxIm_fx[ch][slot], Q11, nBins ); + floatToFixed_arr16( hDiracDecBin->processMtxRePrev[ch][slot], hDiracDecBin->processMtxRePrev_fx[ch][slot], Q11, nBins ); + floatToFixed_arr16( hDiracDecBin->processMtxImPrev[ch][slot], hDiracDecBin->processMtxImPrev_fx[ch][slot], Q11, nBins ); + } + floatToFixed_arrL( hMasaExtRend->cldfbSynRend[ch]->cldfb_state, hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, Q11, hMasaExtRend->cldfbSynRend[ch]->p_filter_length ); + hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; + } + FOR( Word16 cha = 0; cha < 6; cha++ ) + FOR( slot = 0; slot < 4; slot++ ) + FOR( Word16 ind = 0; ind < 60; ind++ ) + { + Cldfb_RealBuffer_in_fx[cha][slot][ind] = float_to_fix( Cldfb_RealBuffer_in[cha][slot][ind], Q6 ); + Cldfb_ImagBuffer_in_fx[cha][slot][ind] = float_to_fix( Cldfb_ImagBuffer_in[cha][slot][ind], Q6 ); + } + ivas_dirac_dec_binaural_process_output_fx( hDiracDecBin, hSpatParamRendCom, hMasaExtRend->cldfbSynRend, output_fx, &q_out, Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, max_band_decorr, numInChannels, config_data.processReverb, subframe ); + + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + fixedToFloat_arrL32( output_fx[ch], output_f[ch], q_out, nBins * hSpatParamRendCom->subframe_nbslots[subframe] ); + fixedToFloat_arrL32( hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[ch]->cldfb_state, hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state, hMasaExtRend->cldfbSynRend[ch]->p_filter_length ); + } +#else ivas_dirac_dec_binaural_process_output( hDiracDecBin, hSpatParamRendCom, hMasaExtRend->cldfbSynRend, output_f, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, max_band_decorr, numInChannels, config_data.processReverb, subframe ); +#endif + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + hDiracDecBin->hDiffuseDist = NULL; diff --git a/lib_rend/ivas_dirac_onsets_dec.c b/lib_rend/ivas_dirac_onsets_dec.c index 5142488a835fffec2b0b6cc489cbc4e0813f2db6..9a9dfe43d5f008bc2343aabda3f2b1d6dc1af53f 100644 --- a/lib_rend/ivas_dirac_onsets_dec.c +++ b/lib_rend/ivas_dirac_onsets_dec.c @@ -329,7 +329,8 @@ void ivas_dirac_dec_onset_detection_process_fx( DIRAC_ONSET_DETECTION_PARAMS h_dirac_onset_detection_params, DIRAC_ONSET_DETECTION_STATE h_dirac_onset_detection_state ) { - Word16 b, ch_idx, result; + + Word16 b, ch_idx; Word16 tmp_fx; Word32 tmp32_fx; Word32 *p_onset_detector_1_fx, *p_onset_detector_2_fx; @@ -345,6 +346,7 @@ void ivas_dirac_dec_onset_detection_process_fx( /*detector 1: envelope max*/ *p_onset_detector_1_fx = Mpy_32_16_1(*p_onset_detector_1_fx, DIRAC_ONSET_ALPHA_FX); //same Q0 //Word16 comp_flag = BASOP_Util_Cmp_Mant32Exp_sat( *p_onset_detector_1_fx, 31 - q_p_onset_detector_1, *input_power_f, 31- q_input_power); + UNUSED_PARAM(q_input_power); IF(GT_32(*p_onset_detector_1_fx, *input_power_f)) { *p_onset_detector_1_fx = *p_onset_detector_1_fx; diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index 7599eccbaf1ca0d9a8bec78331312f8d3678f0d9..2cbe69b21f2994b0940abe4b47fb41fda967e210 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -310,7 +310,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - IF( ( dirac_output_synthesis_state->gains_dir_prev_fx = (Word16 *) malloc( size * sizeof( Word16 ) ) ) == NULL ) + IF( ( dirac_output_synthesis_state->gains_dir_prev_fx = (Word32 *) malloc( size * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } @@ -322,9 +322,9 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - IF ((dirac_output_synthesis_state->gains_diff_prev_fx = (Word16 *)malloc(dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof(Word16))) == NULL) + IF( ( dirac_output_synthesis_state->gains_diff_prev_fx = (Word32 *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( Word32 ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } ELSE IF ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_MONO ) @@ -334,9 +334,9 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - IF ((dirac_output_synthesis_state->gains_diff_prev_fx = (Word16 *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof(Word16))) == NULL) + IF( ( dirac_output_synthesis_state->gains_diff_prev_fx = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof( Word32 ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } ELSE @@ -346,11 +346,10 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - IF ((dirac_output_synthesis_state->gains_diff_prev_fx = (Word16 *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof(Word16))) == NULL) + IF( ( dirac_output_synthesis_state->gains_diff_prev_fx = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( Word32 ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - } /*-----------------------------------------------------------------* @@ -936,6 +935,7 @@ void ivas_dirac_dec_output_synthesis_init_fx( { set32_fx( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx, 0, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); } + h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev = 0; IF( hodirac_flag ) { @@ -946,6 +946,7 @@ void ivas_dirac_dec_output_synthesis_init_fx( size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; } set32_fx( h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev_fx, 0, size ); + h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev = 0; IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { @@ -959,21 +960,24 @@ void ivas_dirac_dec_output_synthesis_init_fx( { set32_fx( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx, 0, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); } + h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev = 0; IF (h_dirac_output_synthesis_state->proto_power_smooth_prev_fx != NULL) { set16_fx(h_dirac_output_synthesis_state->proto_power_smooth_prev_fx, 0, hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir); } - set16_fx(h_dirac_output_synthesis_state->gains_dir_prev_fx, 0, size); + set32_fx( h_dirac_output_synthesis_state->gains_dir_prev_fx, 0, size ); + h_dirac_output_synthesis_state->gains_dir_prev_q = 0; - IF (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - set16_fx(h_dirac_output_synthesis_state->gains_diff_prev_fx, 0, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff); + set32_fx( h_dirac_output_synthesis_state->gains_diff_prev_fx, 0, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff ); } ELSE { - set16_fx(h_dirac_output_synthesis_state->gains_diff_prev_fx, 0, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir); + set32_fx( h_dirac_output_synthesis_state->gains_diff_prev_fx, 0, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); } + h_dirac_output_synthesis_state->gains_diff_prev_q = 0; IF (h_dirac_output_synthesis_state->proto_power_diff_smooth_prev_fx != NULL) { @@ -1590,6 +1594,644 @@ void ivas_dirac_dec_output_synthesis_process_slot( } +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx() + * + * + *------------------------------------------------------------------------*/ + +void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( + Word32 RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ + Word32 ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 nbslots, /* i : number of slots to process */ + const Word32 *onset_filter, // Q30 + Word32 *diffuseness, // Q30 + const Word16 hodirac_flag, /* i : flag to indicate HO-DirAC mode */ + const Word16 dec_param_estim, + Word16 *q_cy_cross_dir_smooth_prev, + Word16 *q_cy_auto_diff_smooth_prev ) +{ + Word16 buf_idx, ch_idx, i, l; + Word16 num_freq_bands, num_freq_bands_diff; + Word16 num_channels_dir, num_channels_diff; + Word32 g, g1, g2; + Word32 *p_gains_dir, *p_gains_diff; + Word32 *p_gains_dir_prev, *p_gains_diff_prev; + Word32 *p_cy_cross_dir_smooth; + Word32 *p_cy_auto_diff_smooth; + Word32 *p_proto, *p_out_real, *p_out_imag; + Word32 *p_proto_diff; + Word16 *proto_direct_index, num_protos_dir; + Word32 output_real[CLDFB_NO_CHANNELS_MAX * MAX_OUTPUT_CHANNELS]; + Word32 output_imag[CLDFB_NO_CHANNELS_MAX * MAX_OUTPUT_CHANNELS]; + DIRAC_OUTPUT_SYNTHESIS_PARAMS h_dirac_output_synthesis_params; + DIRAC_OUTPUT_SYNTHESIS_STATE h_dirac_output_synthesis_state; + Word16 nchan_transport_foa; + Word16 ch_idx_diff; + Word32 aux_buf[CLDFB_NO_CHANNELS_MAX]; + Word32 ratio_float[DIRAC_HO_NUMSECTORS * CLDFB_NO_CHANNELS_MAX]; + Word16 q_com = 0; + move16(); + Word16 exp = 0; + move16(); + + /* collect some often used parameters */ + h_dirac_output_synthesis_params = hDirACRend->h_output_synthesis_psd_params; + h_dirac_output_synthesis_state = hDirACRend->h_output_synthesis_psd_state; + proto_direct_index = hDirACRend->proto_index_dir; + + num_protos_dir = hDirACRend->num_protos_dir; + move16(); + num_freq_bands = hSpatParamRendCom->num_freq_bands; + move16(); + num_freq_bands_diff = h_dirac_output_synthesis_params.max_band_decorr; + move16(); + num_channels_dir = hDirACRend->num_outputs_dir; + move16(); + num_channels_diff = hDirACRend->num_outputs_diff; + move16(); + nchan_transport_foa = s_min( 4, nchan_transport ); + move16(); + + /*-----------------------------------------------------------------* + * comput target Gains + *-----------------------------------------------------------------*/ + + IF( hodirac_flag ) + { + /*Direct gain*/ + FOR( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) + { + v_multc_fixed( diffuseness, // Q30 + ONE_IN_Q31, // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q30 + num_freq_bands ); + v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q30 + L_sub( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, ONE_IN_Q27 ), // Q27 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q26 + num_freq_bands ); + + FOR( l = 0; l < num_freq_bands; l++ ) + { + exp = sub( Q31, Q26 ); + h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] = + Sqrt32( L_add( ONE_IN_Q26, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] ), + &exp ); // (Q31 - exp) + move32(); + } + + // Scale to bring in common Q-factor + q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, sub( Q31, exp ) ); + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], + num_freq_bands, + sub( q_com, sub( Q31, exp ) ) ); + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], + num_freq_bands, + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); + } + + /*Directional gain*/ + FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_dir; ch_idx++ ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + aux_buf[l] = L_sub( ONE_IN_Q30, diffuseness[l] ); // Q30 + move32(); + ratio_float[l] = L_sub( ONE_IN_Q31, h_dirac_output_synthesis_state.direct_power_factor_fx[num_freq_bands + l] ); // Q31 + move32(); + ratio_float[l + num_freq_bands] = L_sub( ONE_IN_Q31, ratio_float[l] ); // Q31 + move32(); + } + + v_mult_fixed( aux_buf, ratio_float, ratio_float, num_freq_bands ); //(Q30, Q31) -> Q30 + v_mult_fixed( aux_buf, &ratio_float[num_freq_bands], &ratio_float[num_freq_bands], num_freq_bands ); //(Q30, Q31) -> Q30 + + v_mult_fixed( ratio_float, // Q30 + &h_dirac_output_synthesis_state.direct_responses_fx[ch_idx * num_freq_bands], // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], //(Q30, Q31) -> Q30 + num_freq_bands ); + v_mult_fixed( &ratio_float[num_freq_bands], // Q30 + &h_dirac_output_synthesis_state.direct_responses_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], //(Q30, Q31) -> Q30 + num_freq_bands ); + + // Scale to bring in common Q-factor + q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q30 ); + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], + num_freq_bands, + sub( q_com, Q30 ) ); + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], + num_freq_bands, + sub( q_com, Q30 ) ); + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], + num_freq_bands, + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], + num_freq_bands, + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); + } + + h_dirac_output_synthesis_state.q_cy_cross_dir_smooth = q_com; + move16(); + h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev = q_com; + move16(); + + /*Diffuse gain*/ + FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) + { + v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 + &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], // Q31 + num_freq_bands_diff ); + + // Scale to bring in common Q-factor + q_com = s_min( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, Q31 ); + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], + num_freq_bands_diff, + sub( q_com, Q31 ) ); + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[ch_idx * num_freq_bands_diff], + num_freq_bands_diff, + sub( q_com, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ); + } + + h_dirac_output_synthesis_state.q_cy_auto_diff_smooth = q_com; + move16(); + h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev = q_com; + move16(); + } + ELSE IF( EQ_16( dec_param_estim, FALSE ) ) + { + /*Direct gain*/ + FOR( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) + { + v_mult_fixed( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q31 + num_freq_bands ); + v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q31 + L_sub( L_shr( h_dirac_output_synthesis_params.diffuse_compensation_factor_decorr_fx, Q3 ), ONE_IN_Q26 ), // Q26 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q26 + num_freq_bands_diff ); + v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands_diff], // Q31 + L_sub( L_shr( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, Q1 ), ONE_IN_Q26 ), // Q26 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands_diff], // Q26 + num_freq_bands - num_freq_bands_diff ); + + FOR( l = 0; l < num_freq_bands; l++ ) + { + exp = sub( Q31, Q26 ); + h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] = + Sqrt32( L_add( ONE_IN_Q26, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] ), + &exp ); // (Q31 - exp) + move32(); + } + + // Scale to bring in common Q-factor + q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, sub( Q31, exp ) ); + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], + num_freq_bands, + sub( q_com, sub( Q31, exp ) ) ); + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], + num_freq_bands, + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); + } + + /*Directional gain*/ + FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_dir; ch_idx++ ) + { + v_mult_fixed( h_dirac_output_synthesis_state.direct_power_factor_fx, // Q31 + &h_dirac_output_synthesis_state.direct_responses_fx[ch_idx * num_freq_bands], // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q31 + num_freq_bands ); + + // Scale to bring in common Q-factor + q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q31 ); + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], + num_freq_bands, + sub( q_com, Q31 ) ); + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], + num_freq_bands, + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); + } + + h_dirac_output_synthesis_state.q_cy_cross_dir_smooth = q_com; + move16(); + h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev = q_com; + move16(); + + /*Diffuse gain*/ + FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) + { + v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 + &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], // Q31 + num_freq_bands_diff ); + + // Scale to bring in common Q-factor + q_com = s_min( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, Q31 ); + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], + num_freq_bands_diff, + sub( q_com, Q31 ) ); + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[ch_idx * num_freq_bands_diff], + num_freq_bands_diff, + sub( q_com, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ); + } + + h_dirac_output_synthesis_state.q_cy_auto_diff_smooth = q_com; + move16(); + h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev = q_com; + move16(); + } + + /*-----------------------------------------------------------------* + * compute gains + *-----------------------------------------------------------------*/ + + p_cy_cross_dir_smooth = h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx; + p_gains_dir = h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx; + + /* Direct gains */ + IF( hodirac_flag ) + { + FOR( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + g1 = L_add( (Word32) ( 0.3679f * ONE_IN_Q30 ), + Mpy_32_32( onset_filter[l], + L_sub( (Word32) ( 0.1175f * ONE_IN_Q31 ), (Word32) ( 0.3679f * ONE_IN_Q31 ) ) ) ); // Q30, (Q30, Q31) -> Q30 + g2 = Mpy_32_32( L_sub( ONE_IN_Q30, g1 ), *( p_gains_dir ) ); //(Q30, p_gains_dir_q) -> (p_gains_dir_q - Q1) + g2 = L_add_sat( g2, Mpy_32_32( g1, ( *( p_cy_cross_dir_smooth++ ) ) ) ); // (p_gains_dir_q - Q1), (Q30, p_gains_dir_q) -> (p_gains_dir_q - Q1) + g2 = L_max( g2, (Word32) ( 0.99f * L_shl( 1, sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q1 ) ) ) ); //(p_gains_dir_q - Q1) + g2 = L_min( g2, (Word32) ( 2.0f * L_shl( 1, sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q1 ) ) ) ); //(p_gains_dir_q - Q1) + *( p_gains_dir++ ) = g2; //(p_gains_dir_q - Q1) + move32(); + } + } + } + ELSE + { + FOR( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + g1 = L_add( (Word32) ( 0.3679f * ONE_IN_Q30 ), + Mpy_32_32( onset_filter[l], + L_sub( (Word32) ( 0.1175f * ONE_IN_Q31 ), (Word32) ( 0.3679f * ONE_IN_Q31 ) ) ) ); // Q30, (Q30, Q31) -> Q30 + g2 = Mpy_32_32( L_sub( ONE_IN_Q30, g1 ), *( p_gains_dir ) ); //(Q30, p_gains_dir_q) -> (p_gains_dir_q - Q1) + g2 = L_add_sat( g2, Mpy_32_32( g1, ( *( p_cy_cross_dir_smooth++ ) ) ) ); // (p_gains_dir_q - Q1), (Q30, p_gains_dir_q) -> (p_gains_dir_q - Q1) + g2 = L_max( g2, (Word32) ( 0.85f * L_shl( 1, sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q1 ) ) ) ); //(p_gains_dir_q - Q1) + g2 = L_min( g2, (Word32) ( 1.15f * L_shl( 1, sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q1 ) ) ) ); //(p_gains_dir_q - Q1) + *( p_gains_dir++ ) = g2; //(p_gains_dir_q - Q1) + move32(); + } + } + } + + /*Directional gains*/ + FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_dir; ch_idx++ ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + g1 = L_add( (Word32) ( 0.3679f * ONE_IN_Q30 ), + Mpy_32_32( onset_filter[l], + L_sub( (Word32) ( 0.1175f * ONE_IN_Q31 ), (Word32) ( 0.3679f * ONE_IN_Q31 ) ) ) ); // Q30, (Q30, Q31) -> Q30 + g2 = Mpy_32_32( L_sub( ONE_IN_Q30, g1 ), *( p_gains_dir ) ); //(Q30, p_gains_dir_q) -> (p_gains_dir_q - Q1) + g2 = L_add_sat( g2, Mpy_32_32( g1, ( *( p_cy_cross_dir_smooth++ ) ) ) ); // (p_gains_dir_q - Q1), (Q30, p_gains_dir_q) -> (p_gains_dir_q - Q1) + g2 = L_max( g2, (Word32) ( -DIRAC_GAIN_LIMIT * L_shl( 1, sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q1 ) ) ) ); //(p_gains_dir_q - Q1) + g2 = L_min( g2, (Word32) ( DIRAC_GAIN_LIMIT * L_shl( 1, sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q1 ) ) ) ); //(p_gains_dir_q - Q1) + *( p_gains_dir++ ) = g2; //(p_gains_dir_q - Q1) + move32(); + } + } + + IF( hodirac_flag ) + { + p_cy_cross_dir_smooth = h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx + num_freq_bands * num_channels_dir; + p_gains_dir = h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx + num_freq_bands * num_channels_dir; + + /*Direct gains*/ + FOR( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + p_cy_cross_dir_smooth++; + p_gains_dir++; + } + } + + /*Directional gains*/ + FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_dir; ch_idx++ ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + g1 = L_add( (Word32) ( 0.3679f * ONE_IN_Q30 ), + Mpy_32_32( onset_filter[l], + L_sub( (Word32) ( 0.1175f * ONE_IN_Q31 ), (Word32) ( 0.3679f * ONE_IN_Q31 ) ) ) ); // Q30, (Q30, Q31) -> Q30 + g2 = Mpy_32_32( L_sub( ONE_IN_Q30, g1 ), *( p_gains_dir ) ); //(Q30, p_gains_dir_q) -> (p_gains_dir_q - Q1) + g2 = L_add_sat( g2, Mpy_32_32( g1, ( *( p_cy_cross_dir_smooth++ ) ) ) ); // (p_gains_dir_q - Q1), (Q30, p_gains_dir_q) -> (p_gains_dir_q - Q1) + g2 = L_max( g2, (Word32) ( -DIRAC_GAIN_LIMIT * L_shl( 1, sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q1 ) ) ) ); //(p_gains_dir_q - Q1) + g2 = L_min( g2, (Word32) ( DIRAC_GAIN_LIMIT * L_shl( 1, sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q1 ) ) ) ); //(p_gains_dir_q - Q1) + *( p_gains_dir++ ) = g2; //(p_gains_dir_q - Q1) + move32(); + } + } + } + + /*Diffuse gains*/ + p_cy_auto_diff_smooth = h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx + nchan_transport_foa * num_freq_bands_diff; + p_gains_diff = h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx + nchan_transport_foa * num_freq_bands_diff; + FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) + { + FOR( l = 0; l < num_freq_bands_diff; l++ ) + { + g1 = (Word32) ( 0.1175f * ONE_IN_Q31 ); // Q31 + g2 = Mpy_32_32( L_sub( ONE_IN_Q31, g1 ), *( p_gains_diff ) ); //(Q31, p_gains_diff_q) -> p_gains_diff_q + g2 = L_add_sat( g2, Mpy_32_32( g1, ( *( p_cy_auto_diff_smooth++ ) ) ) ); // p_gains_diff_q, (Q31, p_gains_diff_q) -> p_gains_diff_q + g2 = L_max( g2, 0 ); // p_gains_diff_q + g2 = L_min( g2, (Word32) ( DIRAC_GAIN_LIMIT * L_shl( 1, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ) ); // p_gains_diff_q + *( p_gains_diff++ ) = g2; // p_gains_diff_q + move32(); + } + } + + /*-----------------------------------------------------------------* + * gain interpolation and output streams + *-----------------------------------------------------------------*/ + + FOR( buf_idx = 0; buf_idx < nbslots; ++buf_idx ) + { + g1 = L_deposit_h( h_dirac_output_synthesis_params.interpolator_fx[buf_idx] ); // Q31 + g2 = L_sub( ONE_IN_Q31, g1 ); // Q31 + + /*Direct input->output*/ + p_gains_dir = h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx; // (p_gains_dir_q - 1) + p_gains_dir_prev = h_dirac_output_synthesis_state.gains_dir_prev_fx; + FOR( ch_idx = 0; ch_idx < num_channels_dir; ch_idx++ ) + { + Scale_sig32( &h_dirac_output_synthesis_state.gains_dir_prev_fx[ch_idx * num_freq_bands], + num_freq_bands, + sub( sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q1 ), h_dirac_output_synthesis_state.gains_dir_prev_q ) ); + } + h_dirac_output_synthesis_state.gains_dir_prev_q = sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q1 ); + + FOR( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) + { + p_proto_diff = h_dirac_output_synthesis_state.proto_diffuse_buffer_f_fx + + shl( i_mult( buf_idx, i_mult( num_freq_bands, num_channels_diff ) ), Q1 ) + + shl( i_mult( ch_idx, num_freq_bands ), Q1 ); + FOR( l = 0; l < num_freq_bands; l++ ) + { + g = L_add( Mpy_32_32( g1, ( *( p_gains_dir++ ) ) ), + Mpy_32_32( g2, ( *( p_gains_dir_prev++ ) ) ) ); // (Q31, p_gains_dir_q - 1) -> (p_gains_dir_q - 1) + + output_real[l * num_channels_dir + ch_idx] = Mpy_32_32( g, ( *( p_proto_diff++ ) ) ); // (p_gains_dir_q - 1, p_proto_diff_q) -> (p_gains_dir_q + p_proto_diff_q - 32) + move32(); + output_imag[l * num_channels_dir + ch_idx] = Mpy_32_32( g, ( *( p_proto_diff++ ) ) ); // (p_gains_dir_q - 1, p_proto_diff_q) -> (p_gains_dir_q + p_proto_diff_q - 32) + move32(); + } + } + + /*Directional stream*/ + FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_dir; ch_idx++ ) + { + IF( hodirac_flag ) + { + IF( EQ_16( proto_direct_index[ch_idx], 0 ) ) + { + Word32 *p_proto2; + Word32 gs1, gs2; + p_proto = h_dirac_output_synthesis_state.proto_direct_buffer_f_fx + + shl( i_mult( buf_idx, i_mult( num_freq_bands, num_protos_dir ) ), Q1 ) + + shl( i_mult( proto_direct_index[0], num_freq_bands ), Q1 ); + p_proto2 = h_dirac_output_synthesis_state.proto_direct_buffer_f_fx + + shl( i_mult( buf_idx, i_mult( num_freq_bands, num_protos_dir ) ), Q1 ) + + shl( i_mult( proto_direct_index[1], num_freq_bands ), Q1 ); + FOR( l = 0; l < num_freq_bands; l++ ) + { + gs1 = L_add( Mpy_32_32( g1, ( *( p_gains_dir ) ) ), + Mpy_32_32( g2, ( *( p_gains_dir_prev ) ) ) ); // (Q31, p_gains_dir_q - 1) -> (p_gains_dir_q - 1) + gs2 = L_add( Mpy_32_32( g1, ( *( p_gains_dir + num_freq_bands * num_channels_dir ) ) ), + Mpy_32_32( g2, ( *( p_gains_dir_prev + num_freq_bands * num_channels_dir ) ) ) ); // (Q31, p_gains_dir_q - 1) -> (p_gains_dir_q - 1) + p_gains_dir++; + p_gains_dir_prev++; + + // ((p_gains_dir_q - 1, p_proto_dir_q - 1) >> 1) -> (p_gains_dir_q + p_proto_dir_q - 32) + output_real[l * num_channels_dir + ch_idx] = + L_add( + Mpy_32_32( gs1, ( L_add( Mpy_32_32( (Word32) ( 1.772454e+00f * ONE_IN_Q30 ), ( *p_proto ) ), + Mpy_32_32( (Word32) ( 1.023327e+00f * ONE_IN_Q30 ), ( *p_proto2 ) ) ) ) ), /* s1 */ + Mpy_32_32( gs2, ( L_sub( Mpy_32_32( (Word32) ( 1.772454e+00f * ONE_IN_Q30 ), ( *p_proto ) ), + Mpy_32_32( (Word32) ( 1.023327e+00f * ONE_IN_Q30 ), ( *p_proto2 ) ) ) ) ) ); /* s2 */ + move32(); + p_proto++; + p_proto2++; + + // ((p_gains_dir_q - 1, p_proto_dir_q - 1) >> 1) -> (p_gains_dir_q + p_proto_dir_q - 32) + output_imag[l * num_channels_dir + ch_idx] = + L_add( + Mpy_32_32( gs1, ( L_add( Mpy_32_32( (Word32) ( 1.772454e+00f * ONE_IN_Q30 ), ( *p_proto ) ), + Mpy_32_32( (Word32) ( 1.023327e+00f * ONE_IN_Q30 ), ( *p_proto2 ) ) ) ) ), + Mpy_32_32( gs2, ( L_sub( Mpy_32_32( (Word32) ( 1.772454e+00f * ONE_IN_Q30 ), ( *p_proto ) ), + Mpy_32_32( (Word32) ( 1.023327e+00f * ONE_IN_Q30 ), ( *p_proto2 ) ) ) ) ) ); + move32(); + p_proto++; + p_proto2++; + } + } + ELSE + { + p_proto = h_dirac_output_synthesis_state.proto_direct_buffer_f_fx + + shl( i_mult( buf_idx, i_mult( num_freq_bands, num_protos_dir ) ), Q1 ) + + shl( i_mult( proto_direct_index[ch_idx], num_freq_bands ), Q1 ); + FOR( l = 0; l < num_freq_bands; l++ ) + { + p_gains_dir++; + p_gains_dir_prev++; + + output_real[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 32 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 32) + move32(); + output_imag[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 32 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 32) + move32(); + } + } + } + ELSE + { + p_proto = h_dirac_output_synthesis_state.proto_direct_buffer_f_fx + + shl( i_mult( buf_idx, i_mult( num_freq_bands, num_protos_dir ) ), Q1 ) + + shl( i_mult( proto_direct_index[ch_idx], num_freq_bands ), Q1 ); + IF( EQ_16( proto_direct_index[ch_idx], 0 ) ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + g = L_add( Mpy_32_32( g1, ( *( p_gains_dir++ ) ) ), + Mpy_32_32( g2, ( *( p_gains_dir_prev++ ) ) ) ); // (Q31, p_gains_dir_q - 1) -> (p_gains_dir_q - 1) + + output_real[l * num_channels_dir + ch_idx] = Mpy_32_32( g, ( *( p_proto++ ) ) ); // (p_gains_dir_q - 1, p_proto_dir_q) -> (p_gains_dir_q + p_proto_dir_q - 32) + move32(); + output_imag[l * num_channels_dir + ch_idx] = Mpy_32_32( g, ( *( p_proto++ ) ) ); // (p_gains_dir_q - 1, p_proto_dir_q) -> (p_gains_dir_q + p_proto_dir_q - 32) + move32(); + } + } + ELSE + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + p_gains_dir++; + p_gains_dir_prev++; + + output_real[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 32 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 32) + move32(); + output_imag[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 32 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 32) + move32(); + } + } + } + } + + /*Diffuse stream*/ + p_gains_diff = h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx + i_mult( nchan_transport_foa, num_freq_bands_diff ); + p_gains_diff_prev = h_dirac_output_synthesis_state.gains_diff_prev_fx + i_mult( nchan_transport_foa, num_freq_bands_diff ); + FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) + { + Scale_sig32( &h_dirac_output_synthesis_state.gains_diff_prev_fx[ch_idx * num_freq_bands_diff], + num_freq_bands_diff, + sub( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, h_dirac_output_synthesis_state.gains_diff_prev_q ) ); + } + h_dirac_output_synthesis_state.gains_diff_prev_q = h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev; + + ch_idx_diff = nchan_transport_foa; + move16(); + FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) + { + IF( EQ_16( proto_direct_index[ch_idx], 0 ) ) + { + p_proto = h_dirac_output_synthesis_state.proto_diffuse_buffer_f_fx + + shl( i_mult( buf_idx, i_mult( num_freq_bands, num_channels_diff ) ), Q1 ) + + shl( i_mult( ch_idx_diff, num_freq_bands ), Q1 ); + ch_idx_diff = add( ch_idx_diff, 1 ); + FOR( l = 0; l < num_freq_bands_diff; l++ ) + { + g = L_add( Mpy_32_32( g1, ( *( p_gains_diff++ ) ) ), + Mpy_32_32( g2, ( *( p_gains_diff_prev++ ) ) ) ); // (Q31, p_gains_diff_q) -> p_gains_diff_q + + // ((p_gains_diff_q, p_proto_diff_q) >> Q1) -> (p_gains_diff_q + p_proto_diff_q - 32) + output_real[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]] = + L_shr( L_add( output_real[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]], + Mpy_32_32( g, ( *( p_proto++ ) ) ) ), + Q1 ); + move32(); + + // ((p_gains_diff_q, p_proto_diff_q) >> Q1) -> (p_gains_diff_q + p_proto_diff_q - 32) + output_imag[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]] = + L_shr( L_add( output_imag[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]], + Mpy_32_32( g, ( *( p_proto++ ) ) ) ), + Q1 ); + move32(); + } + } + ELSE + { + FOR( l = 0; l < num_freq_bands_diff; l++ ) + { + p_gains_diff++; + p_gains_diff_prev++; + } + } + } + + /*-----------------------------------------------------------------* + * Copy output or HOA decoder + *-----------------------------------------------------------------*/ + + IF( hDirACRend->hOutSetup.is_loudspeaker_setup && hDirACRend->hoa_decoder != NULL ) + { + Word32 *p_real, *p_imag; + const Word32 *hoa_decoder; + + hoa_decoder = hDirACRend->hoa_decoder; + + FOR( ch_idx = 0; ch_idx < hDirACRend->hOutSetup.nchan_out_woLFE; ch_idx++ ) + { + p_real = RealBuffer[ch_idx][buf_idx]; + p_imag = ImagBuffer[ch_idx][buf_idx]; + + FOR( l = 0; l < num_freq_bands; l++ ) + { + p_out_real = output_real + i_mult( l, num_channels_dir ); + p_out_imag = output_imag + i_mult( l, num_channels_dir ); + p_real[l] = Mpy_32_32( *( p_out_real++ ), hoa_decoder[0] ); // (q, Q29) -> q - Q2 + move32(); + p_imag[l] = Mpy_32_32( *( p_out_imag++ ), hoa_decoder[0] ); // (q, Q29) -> q - Q2 + move32(); + FOR( i = 1; i < num_channels_dir; i++ ) + { + p_real[l] = L_add( p_real[l], Mpy_32_32( *( p_out_real++ ), hoa_decoder[i] ) ); // (q, Q29) -> q - Q2 + move32(); + p_imag[l] = L_add( p_imag[l], Mpy_32_32( *( p_out_imag++ ), hoa_decoder[i] ) ); // (q, Q29) -> q - Q2 + move32(); + } + } + hoa_decoder += 16; + } + } + ELSE + { + FOR( ch_idx = 0; ch_idx < num_channels_dir; ch_idx++ ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + RealBuffer[ch_idx][buf_idx][l] = L_shr( output_real[l * num_channels_dir + ch_idx], Q2 ); + move32(); + ImagBuffer[ch_idx][buf_idx][l] = L_shr( output_imag[l * num_channels_dir + ch_idx], Q2 ); + move32(); + } + } + } + } + + /*-----------------------------------------------------------------* + * update buffers + *-----------------------------------------------------------------*/ + + /* store estimates for next synthesis block */ + IF( hodirac_flag ) + { + mvl2l( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, num_freq_bands * num_channels_dir * DIRAC_HO_NUMSECTORS ); + } + ELSE + { + mvl2l( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, num_freq_bands * num_channels_dir ); + } + *q_cy_cross_dir_smooth_prev = sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q1 ); + move16(); + + mvl2l( h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx, h_dirac_output_synthesis_state.gains_diff_prev_fx, num_freq_bands_diff * num_channels_diff ); + *q_cy_auto_diff_smooth_prev = h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev; + move16(); + + /* reset values */ + IF( hodirac_flag ) + { + set_zero_fx( h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx, num_freq_bands * num_channels_dir * DIRAC_HO_NUMSECTORS ); + } + ELSE + { + set_zero_fx( h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx, num_freq_bands * num_channels_dir ); + } + + set_zero_fx( h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx, num_freq_bands_diff * num_channels_diff ); + + return; +} +#endif + + /*------------------------------------------------------------------------- * ivas_dirac_dec_output_synthesis_process_subframe_gain_shd() * @@ -2989,7 +3631,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( } } - IF( masa_band_mapping == NULL && EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + IF( masa_band_mapping == NULL && EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { mvr2r_inc_fixed( direct_response_hoa_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); @@ -3198,7 +3840,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( FOR( l = 1; l < num_channels_dir; l++ ) { exp = 0; - var_a = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( surCohRatio_fx[k] ), 31 - Q_surCohRatio, &exp ); + var_a = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( surCohRatio_fx[k] ), exp_surCohRatio, &exp ); var_b = Sqrt32( var_a, &exp ); direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], var_b ); move32(); diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index 9fa8f396023865638574d49e5fc261b9b3aae1de..5d2c2e3cef88ae694c986fab1b84791e8805b2aa 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -44,6 +44,7 @@ #include "prot_fx1.h" #include "prot_fx2.h" #include "ivas_prot_fx.h" +#include "ivas_rom_binaural_crend_head.h" /*------------------------------------------------------------------------- * ivas_dirac_allocate_parameters() @@ -1448,6 +1449,7 @@ ivas_error ivas_dirac_alloc_mem( hDirAC_mem->direct_responses_square = NULL; #ifdef IVAS_FLOAT_FIXED hDirAC_mem->direct_responses_square_fx = NULL; + hDirAC_mem->proto_power_smooth_fx = NULL; #endif hDirAC_mem->frame_dec_f = NULL; if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) @@ -1509,6 +1511,9 @@ ivas_error ivas_dirac_alloc_mem( hDirACRend->h_output_synthesis_psd_state.direct_responses_square = hDirAC_mem->direct_responses_square; #ifdef IVAS_FLOAT_FIXED hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx = hDirAC_mem->direct_responses_square_fx; + hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q = Q31; + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx = hDirAC_mem->proto_power_smooth_fx; + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = Q31; #endif /* Target and smoothed nrg factors/gains */ @@ -1586,17 +1591,28 @@ ivas_error ivas_dirac_alloc_mem( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx = hDirAC_mem->direct_responses_fx; + hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q31; #endif /* Prototypes */ hDirAC_mem->proto_direct_buffer_f = NULL; hDirAC_mem->proto_diffuse_buffer_f = NULL; +#ifdef IVAS_FLOAT_FIXED + hDirAC_mem->proto_direct_buffer_f_fx = NULL; + hDirAC_mem->proto_diffuse_buffer_f_fx = NULL; +#endif if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) { if ( ( hDirAC_mem->proto_direct_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } +#ifdef IVAS_FLOAT_FIXED + IF( ( hDirAC_mem->proto_direct_buffer_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } +#endif if ( hDirACRend->proto_signal_decorr_on ) { @@ -1606,6 +1622,12 @@ ivas_error ivas_dirac_alloc_mem( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } +#ifdef IVAS_FLOAT_FIXED + IF( ( hDirAC_mem->proto_diffuse_buffer_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } +#endif } else { @@ -1613,12 +1635,21 @@ ivas_error ivas_dirac_alloc_mem( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } +#ifdef IVAS_FLOAT_FIXED + IF( ( hDirAC_mem->proto_diffuse_buffer_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_outputs_diff * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } +#endif } } } hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f = hDirAC_mem->proto_direct_buffer_f; hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f = hDirAC_mem->proto_diffuse_buffer_f; - +#ifdef IVAS_FLOAT_FIXED + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx = hDirAC_mem->proto_direct_buffer_f_fx; + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx = hDirAC_mem->proto_diffuse_buffer_f_fx; +#endif /* Gains/power factors*/ hDirAC_mem->direct_power_factor = NULL; hDirAC_mem->diffuse_power_factor = NULL; @@ -1750,6 +1781,10 @@ void ivas_dirac_free_mem_fx( { free(hDirAC_mem->proto_power_smooth); } + IF( hDirAC_mem->proto_power_smooth_fx != NULL ) + { + free( hDirAC_mem->proto_power_smooth_fx ); + } IF (hDirAC_mem->proto_power_diff_smooth != NULL) { free(hDirAC_mem->proto_power_diff_smooth); @@ -1790,10 +1825,18 @@ void ivas_dirac_free_mem_fx( { free(hDirAC_mem->proto_direct_buffer_f); } + IF( hDirAC_mem->proto_direct_buffer_f_fx != NULL ) + { + free( hDirAC_mem->proto_direct_buffer_f_fx ); + } IF (hDirAC_mem->proto_diffuse_buffer_f != NULL) { free(hDirAC_mem->proto_diffuse_buffer_f); } + IF( hDirAC_mem->proto_diffuse_buffer_f_fx != NULL ) + { + free( hDirAC_mem->proto_diffuse_buffer_f_fx ); + } IF (hDirAC_mem->direct_power_factor != NULL) { free(hDirAC_mem->direct_power_factor); @@ -1842,6 +1885,12 @@ void ivas_dirac_free_mem( { free( hDirAC_mem->proto_power_smooth ); } +#ifdef IVAS_FLOAT_FIXED + if ( hDirAC_mem->proto_power_smooth_fx != NULL ) + { + free( hDirAC_mem->proto_power_smooth_fx ); + } +#endif if ( hDirAC_mem->proto_power_diff_smooth != NULL ) { free( hDirAC_mem->proto_power_diff_smooth ); @@ -1870,6 +1919,20 @@ void ivas_dirac_free_mem( { free( hDirAC_mem->proto_direct_buffer_f ); } +#ifdef IVAS_FLOAT_FIXED + if ( hDirAC_mem->proto_direct_buffer_f_fx != NULL ) + { + free( hDirAC_mem->proto_direct_buffer_f_fx ); + } + if ( hDirAC_mem->proto_diffuse_buffer_f_fx != NULL ) + { + free( hDirAC_mem->proto_diffuse_buffer_f_fx ); + } + if (hDirAC_mem->direct_responses_fx != NULL) + { + free(hDirAC_mem->direct_responses_fx); + } +#endif if ( hDirAC_mem->proto_diffuse_buffer_f != NULL ) { free( hDirAC_mem->proto_diffuse_buffer_f ); @@ -1890,6 +1953,16 @@ void ivas_dirac_free_mem( { free( hDirAC_mem->onset_filter ); } +#ifdef IVAS_FLOAT_FIXED + if ( hDirAC_mem->reference_power_fx != NULL ) + { + free( hDirAC_mem->reference_power_fx ); + } + if ( hDirAC_mem->onset_filter_fx != NULL ) + { + free( hDirAC_mem->onset_filter_fx ); + } +#endif return; } @@ -2227,6 +2300,261 @@ void initDiffuseResponses_fx( } #endif +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * protoSignalComputation_shd_fx() + * + * + *-------------------------------------------------------------------------*/ + +void protoSignalComputation_shd_fx( + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 *proto_direct_buffer_f_fx, + Word16 *proto_direct_buffer_f_q, + Word32 *proto_diffuse_buffer_f_fx, + Word16 *proto_diffuse_buffer_f_q, + Word32 *reference_power_fx, + Word16 *reference_power_q, + const Word16 slot_index, + const Word16 num_inputs, + const Word16 num_outputs_diff, + const Word16 num_freq_bands, + Word32 *p_Rmat_fx, /* Q29*/ + Word16 q_cldfb ) +{ + Word16 l, k; + Word16 Rmat_k[4]; + Word32 *p_proto_direct_buffer_fx; + Word32 *p_proto_diffuse_buffer_fx; + Word32 re1, im1; + Word32 re2, im2; + Word32 re3, im3; + Word32 *p_k_fx[4]; + Word16 min_q_shift, q_shift; + Word16 idx, idx1; + + k = 0; /* to avoid compilation warning */ + move16(); + + min_q_shift = Q31; + move16(); + q_shift = Q31; + move16(); + + p_proto_direct_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_inputs ) ); + p_proto_diffuse_buffer_fx = proto_diffuse_buffer_f_fx + i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_outputs_diff ) ); + + IF( EQ_16( num_inputs, 1 ) ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + p_proto_direct_buffer_fx[i_mult( 2, l )] = RealBuffer_fx[0][0][l]; + move32(); + p_proto_direct_buffer_fx[add( i_mult( 2, l ), 1 )] = ImagBuffer_fx[0][0][l]; + move32(); + } + *proto_direct_buffer_f_q = q_cldfb; + move16(); + } + ELSE IF( EQ_16( num_inputs, 2 ) ) + { + IF( p_Rmat_fx != 0 ) + { + assert( EQ_16( num_inputs, 4 ) && "This code block should never be run with num_inputs != 4!" ); + + FOR( l = 0; l < num_freq_bands; l++ ) + { + re1 = L_add( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); + im1 = L_add( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); + + re2 = L_sub( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); + im2 = L_sub( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); + + p_proto_direct_buffer_fx[i_mult( 2, l )] = re1; + move32(); + p_proto_direct_buffer_fx[add( i_mult( 2, l ), 1 )] = im1; + move32(); + p_proto_direct_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = L_shl( Mpy_32_32( p_Rmat_fx[0], re2 ), 2 ); // left shift is done to maintain constant Q factor for p_proto_direct_buffer_fx + move32(); + p_proto_direct_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = L_shl( Mpy_32_32( p_Rmat_fx[0], im2 ), 2 ); // left shift is done to maintain constant Q factor for p_proto_direct_buffer_fx + move32(); + } + *proto_direct_buffer_f_q = q_cldfb; + move16(); + } + ELSE + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + re1 = L_add( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); + im1 = L_add( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); + + p_proto_direct_buffer_fx[i_mult( 2, l )] = re1; + move32(); + p_proto_direct_buffer_fx[add( i_mult( 2, l ), 1 )] = im1; + move32(); + p_proto_direct_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = L_sub( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); + move32(); + p_proto_direct_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = L_sub( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); + move32(); + } + } + *proto_direct_buffer_f_q = q_cldfb; + move16(); + } + ELSE IF( GE_16( num_inputs, 4 ) ) + { + p_k_fx[0] = p_proto_direct_buffer_fx; + p_k_fx[1] = p_proto_direct_buffer_fx + i_mult( 2, num_freq_bands ); + p_k_fx[2] = p_proto_direct_buffer_fx + i_mult( 4, num_freq_bands ); + p_k_fx[3] = p_proto_direct_buffer_fx + i_mult( 6, num_freq_bands ); + + Rmat_k[0] = 0; + move16(); + Rmat_k[1] = 1; + move16(); + Rmat_k[2] = 2; + move16(); + Rmat_k[3] = 0; + move16(); + + /* calculate the minimum possible shift for the buffers RealBuffer_fx and ImagBuffer_fx */ + FOR( k = 0; k < 4; k++ ) + { + q_shift = L_norm_arr( RealBuffer_fx[k][0], num_freq_bands ); + min_q_shift = s_min( min_q_shift, q_shift ); + q_shift = L_norm_arr( ImagBuffer_fx[k][0], num_freq_bands ); + min_q_shift = s_min( min_q_shift, q_shift ); + } + + min_q_shift = sub( min_q_shift, 4 ); /* 4 is for guard bits*/ + + IF( p_Rmat_fx != 0 ) + { + assert( EQ_16( num_inputs, 4 ) && "This code block should never be run with num_inputs != 4!" ); + + FOR( l = 0; l < num_freq_bands; l++ ) + { + *p_k_fx[0] = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); + move32(); + reference_power_fx[add( l, num_freq_bands )] = Mpy_32_32( *p_k_fx[0], *p_k_fx[0] ); + move32(); + p_k_fx[0]++; + + *p_k_fx[0] = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); + move32(); + reference_power_fx[add( l, num_freq_bands )] = Madd_32_32( reference_power_fx[add( l, num_freq_bands )], *p_k_fx[0], *p_k_fx[0] ); + move32(); + p_k_fx[0]++; + + reference_power_fx[l] = L_shr( reference_power_fx[add( l, num_freq_bands )], 1 ); + move32(); + + FOR( k = 1; k < 4; k++ ) + { + re1 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); + re2 = L_shl( RealBuffer_fx[2][0][l], min_q_shift ); + re3 = L_shl( RealBuffer_fx[3][0][l], min_q_shift ); + im1 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); + im2 = L_shl( ImagBuffer_fx[2][0][l], min_q_shift ); + im3 = L_shl( ImagBuffer_fx[3][0][l], min_q_shift ); + + idx = i_mult( 3, Rmat_k[k] ); + idx1 = add( l, i_mult( add( k, 1 ), num_freq_bands ) ); + + *p_k_fx[k] = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[add( idx, 1 )], re1 ), p_Rmat_fx[add( idx, 2 )], re2 ), p_Rmat_fx[idx], re3 ); + move32(); + *p_k_fx[k] = L_shl( *p_k_fx[k], 2 ); // left shift is done to maintain constant Q factor for p_k_fx + move32(); + reference_power_fx[idx1] = Mpy_32_32( *p_k_fx[k], *p_k_fx[k] ); + move32(); + p_k_fx[k]++; + + *p_k_fx[k] = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[add( idx, 1 )], im1 ), p_Rmat_fx[add( idx, 2 )], im2 ), p_Rmat_fx[idx], im3 ); + move32(); + *p_k_fx[k] = L_shl( *p_k_fx[k], 2 ); // left shift is done to maintain constant Q factor + move32(); + reference_power_fx[idx1] = Mpy_32_32( *p_k_fx[k], *p_k_fx[k] ); + move32(); + p_k_fx[k]++; + + reference_power_fx[l] = L_add( reference_power_fx[l], L_shr( reference_power_fx[idx1], 1 ) ); + move32(); + } + + *proto_direct_buffer_f_q = add( q_cldfb, min_q_shift ); + *reference_power_q = sub( add( *proto_direct_buffer_f_q, *proto_direct_buffer_f_q ), 31 ); + + FOR( k = 1; k < 4; k++ ) + { + RealBuffer_fx[k][0][l] = L_shr( p_proto_direct_buffer_fx[i_mult( 2, add( i_mult( k, num_freq_bands ), l ) )], sub( *proto_direct_buffer_f_q, q_cldfb ) ); + move32(); + ImagBuffer_fx[k][0][l] = L_shr( p_proto_direct_buffer_fx[add( i_mult( 2, add( i_mult( k, num_freq_bands ), l ) ), 1 )], sub( *proto_direct_buffer_f_q, q_cldfb ) ); + move32(); + } + } + } + ELSE + { + set_zero_fx( reference_power_fx, num_freq_bands ); + FOR( k = 0; k < 4; k++ ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + p_proto_direct_buffer_fx[i_mult( 2, add( i_mult( k, num_freq_bands ), l ) )] = RealBuffer_fx[k][0][l]; + move32(); + p_proto_direct_buffer_fx[add( i_mult( 2, add( i_mult( k, num_freq_bands ), l ) ), 1 )] = ImagBuffer_fx[k][0][l]; + move32(); + + re1 = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); + im1 = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); + + reference_power_fx[add( l, i_mult( add( k, 1 ), num_freq_bands ) )] = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); + move32(); + reference_power_fx[l] = L_add( reference_power_fx[l], L_shr( reference_power_fx[add( l, i_mult( add( k, 1 ), num_freq_bands ) )], 1 ) ); + move32(); + } + } + *proto_direct_buffer_f_q = q_cldfb; + move16(); + *reference_power_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); + } + + /* Additional transport channels = planar SBA components of degree higher than 1*/ + FOR( ; k < num_inputs; k++ ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + p_proto_direct_buffer_fx[i_mult( 2, add( i_mult( k, num_freq_bands ), l ) )] = RealBuffer_fx[k][0][l]; + move32(); + p_proto_direct_buffer_fx[add( i_mult( 2, add( i_mult( k, num_freq_bands ), l ) ), 1 )] = ImagBuffer_fx[k][0][l]; + move32(); + } + } + } + + + /*Copy direct to diffuse proto*/ + Copy32( p_proto_direct_buffer_fx, p_proto_diffuse_buffer_fx, i_mult( i_mult( 2, num_freq_bands ), s_min( num_outputs_diff, num_inputs ) ) ); + *proto_diffuse_buffer_f_q = *proto_direct_buffer_f_q; + move16(); + + IF( EQ_16( num_inputs, 1 ) ) + { + /* Add comfort noise addition (CNA) to diffuse proto only*/ + FOR( l = 0; l < num_freq_bands; l++ ) + { + p_proto_diffuse_buffer_fx[i_mult( 2, l )] = L_add( p_proto_diffuse_buffer_fx[i_mult( 2, l )], RealBuffer_fx[1][0][l] ); + move32(); + p_proto_diffuse_buffer_fx[add( i_mult( 2, l ), 1 )] = L_add( p_proto_diffuse_buffer_fx[add( i_mult( 2, l ), 1 )], ImagBuffer_fx[1][0][l] ); + move32(); + } + } + + return; +} +#endif /*------------------------------------------------------------------------- * protoSignalComputation_shd() * @@ -2389,6 +2717,108 @@ void protoSignalComputation_shd( } +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * protoSignalComputation1_fx() + * + * + *-------------------------------------------------------------------------*/ + +void protoSignalComputation1_fx( + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 *proto_frame_f_fx, + Word16 *proto_frame_f_q, + Word32 *proto_direct_buffer_f_fx, + Word16 *proto_direct_buffer_f_q, + Word32 *reference_power_fx, + Word16 *reference_power_q, + Word32 *proto_power_smooth_fx, + Word16 *proto_power_smooth_q, + const Word16 slot_index, + const Word16 num_outputs_diff, + const Word16 num_freq_bands, + Word16 q_cldfb ) +{ + Word16 l, k, idx; + Word32 *p_proto_buffer_fx; + Word16 proto_power_smooth_fx_q, min_q_shift, q_shift; + Word32 re, im; + + min_q_shift = Q31; + move16(); + q_shift = Q31; + move16(); + + p_proto_buffer_fx = proto_direct_buffer_f_fx + i_mult( slot_index, i_mult( 2, num_freq_bands ) ); + + /* calculate the maximum shift possible for the bufferS RealBuffer_fx and ImagBuffer_fx*/ + q_shift = L_norm_arr( RealBuffer_fx[0][0], num_freq_bands ); + min_q_shift = s_min( q_shift, min_q_shift ); + q_shift = L_norm_arr( ImagBuffer_fx[0][0], num_freq_bands ); + min_q_shift = s_min( q_shift, min_q_shift ); + + min_q_shift = sub( min_q_shift, find_guarded_bits_fx( 2 ) ); + + /* calculate the maximum shift possible for the buffer proto_power_smooth_fx */ + q_shift = getScaleFactor32( proto_power_smooth_fx, num_freq_bands ); + q_shift = sub( q_shift, find_guarded_bits_fx( 2 ) ); + + Scale_sig32( proto_power_smooth_fx, num_freq_bands, q_shift ); + *proto_power_smooth_q = add( *proto_power_smooth_q, q_shift ); + proto_power_smooth_fx_q = *proto_power_smooth_q; + move16(); + + FOR( l = 0; l < num_freq_bands; l++ ) + { + re = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); + im = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); + + reference_power_fx[l] = Madd_32_32( Mpy_32_32( re, re ), im, im ); + move32(); + *reference_power_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); + + IF( LT_16( *reference_power_q, *proto_power_smooth_q ) ) + { + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *proto_power_smooth_q, *reference_power_q ) ), reference_power_fx[l] ); + move32(); + proto_power_smooth_fx_q = *reference_power_q; + move16(); + } + ELSE + { + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( reference_power_fx[l], sub( *reference_power_q, *proto_power_smooth_q ) ) ); + move32(); + proto_power_smooth_fx_q = *proto_power_smooth_q; + move16(); + } + + idx = i_mult( 2, l ); + p_proto_buffer_fx[idx] = RealBuffer_fx[0][0][l]; + move32(); + p_proto_buffer_fx[add( idx, 1 )] = ImagBuffer_fx[0][0][l]; + move32(); + + FOR( k = 0; k < num_outputs_diff; k++ ) + { + idx = add( i_mult( i_mult( 2, k ), num_freq_bands ), i_mult( 2, l ) ); + proto_frame_f_fx[idx] = RealBuffer_fx[0][0][l]; + move32(); + proto_frame_f_fx[add( idx, 1 )] = ImagBuffer_fx[0][0][l]; + move32(); + } + } + + *proto_frame_f_q = q_cldfb; + move16(); + *proto_direct_buffer_f_q = q_cldfb; + move16(); + *proto_power_smooth_q = proto_power_smooth_fx_q; + move16(); + + return; +} +#endif /*------------------------------------------------------------------------- * protoSignalComputation1() * @@ -2428,7 +2858,6 @@ void protoSignalComputation1( return; } - /*------------------------------------------------------------------------- * protoSignalComputation2() * @@ -2756,6 +3185,162 @@ void protoSignalComputation2( } +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * protoSignalComputation4_fx() + * + * + *-------------------------------------------------------------------------*/ + +void protoSignalComputation4_fx( + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 *proto_frame_f_fx, + Word16 *proto_frame_f_q, + Word32 *proto_direct_buffer_f_fx, + Word16 *proto_direct_buffer_f_q, + Word32 *reference_power_fx, + Word16 *reference_power_q, + Word32 *proto_power_smooth_fx, + Word16 *proto_power_smooth_q, + const Word16 slot_index, + const Word16 num_outputs_diff, + const Word16 num_freq_bands, + const Word32 *mtx_hoa_decoder, + const Word16 nchan_transport, + const Word16 *sba_map_tc_ind, + Word16 q_cldfb ) +{ + Word16 k, l, idx, idx2; + Word16 n, offset; + Word32 sq_tmp_fx; + Word32 *p_proto_buffer_fx; + Word16 min_q_shift, q_shift; + Word32 re, im; + Word16 proto_power_smooth_fx_q, sq_tmp_q; + + min_q_shift = Q31; + move16(); + q_shift = Q31; + move16(); + sq_tmp_q = 0; + move16(); + + set_zero_fx( reference_power_fx, num_freq_bands ); + + /* calculate the shift possible for both RealBuffer_fx and ImagBuffer_fx buffers*/ + FOR( k = 0; k < s_max( 4, nchan_transport ); k++ ) + { + q_shift = L_norm_arr( RealBuffer_fx[k][0], num_freq_bands ); + min_q_shift = s_min( q_shift, min_q_shift ); + q_shift = L_norm_arr( ImagBuffer_fx[k][0], num_freq_bands ); + min_q_shift = s_min( q_shift, min_q_shift ); + } + q_shift = min_q_shift; + min_q_shift = sub( min_q_shift, find_guarded_bits_fx( i_mult( 2, 4 ) ) ); + + FOR( k = 0; k < 4; k++ ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + re = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); + im = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); + + sq_tmp_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); + + reference_power_fx[l] = Madd_32_16( reference_power_fx[l], sq_tmp_fx, 16384 ); // 16384 = 0.5 in Q15 + move32(); + } + } + sq_tmp_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); + *reference_power_q = sub( add( sq_tmp_q, Q15 ), 15 ); + + min_q_shift = sub( q_shift, find_guarded_bits_fx( 2 ) ); + + /*For decorrelated diffuseness*/ + FOR( l = 0; l < num_outputs_diff; l++ ) + { + FOR( k = 0; k < num_freq_bands; k++ ) + { + idx = add( i_mult( i_mult( 2, l ), num_freq_bands ), i_mult( 2, k ) ); + proto_frame_f_fx[idx] = 0; + move32(); + proto_frame_f_fx[add( idx, 1 )] = 0; + move32(); + FOR( n = 0; n < nchan_transport; n++ ) + { + idx2 = add( i_mult( l, 16 ), sba_map_tc_ind[n] ); + + re = L_shl( RealBuffer_fx[n][0][k], min_q_shift ); + im = L_shl( ImagBuffer_fx[n][0][k], min_q_shift ); + + proto_frame_f_fx[idx] = Madd_32_32( proto_frame_f_fx[idx], re, mtx_hoa_decoder[idx2] ); + move32(); + proto_frame_f_fx[add( idx, 1 )] = Madd_32_32( proto_frame_f_fx[add( idx, 1 )], im, mtx_hoa_decoder[idx2] ); + move32(); + } + } + } + *proto_frame_f_q = sub( add( add( min_q_shift, q_cldfb ), Q29 ), 31 ); + + /* calculate the shift possible to up scale the buffer proto_power_smooth_fx*/ + min_q_shift = getScaleFactor32( proto_power_smooth_fx, i_mult( num_outputs_diff, num_freq_bands ) ); + min_q_shift = sub( min_q_shift, find_guarded_bits_fx( 2 ) ); + + Scale_sig32( proto_power_smooth_fx, i_mult( num_outputs_diff, num_freq_bands ), min_q_shift ); + *proto_power_smooth_q = add( *proto_power_smooth_q, min_q_shift ); + proto_power_smooth_fx_q = *proto_power_smooth_q; + move16(); + + /* calculate the shift possible to up scale the values of the buffer proto_frame_f_fx*/ + min_q_shift = getScaleFactor32( proto_frame_f_fx, i_mult( 2, i_mult( num_outputs_diff, num_freq_bands ) ) ); + min_q_shift = sub( min_q_shift, find_guarded_bits_fx( 2 ) ); + + Scale_sig32( proto_frame_f_fx, i_mult( 2, i_mult( num_outputs_diff, num_freq_bands ) ), min_q_shift ); + *proto_frame_f_q = add( *proto_frame_f_q, min_q_shift ); + + offset = i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_outputs_diff ) ); + p_proto_buffer_fx = proto_direct_buffer_f_fx + offset; + + FOR( k = 0; k < num_outputs_diff; k++ ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + idx = i_mult( 2, add( i_mult( k, num_freq_bands ), l ) ); + + sq_tmp_fx = Madd_32_32( Mpy_32_32( proto_frame_f_fx[idx], proto_frame_f_fx[idx] ), proto_frame_f_fx[add( idx, 1 )], proto_frame_f_fx[add( idx, 1 )] ); + sq_tmp_q = sub( add( *proto_frame_f_q, *proto_frame_f_q ), 31 ); + + IF( LT_16( *proto_power_smooth_q, sq_tmp_q ) ) + { + proto_power_smooth_fx[add( l, i_mult( k, num_freq_bands ) )] = L_add( proto_power_smooth_fx[add( l, i_mult( k, num_freq_bands ) )], L_shr( sq_tmp_fx, sub( sq_tmp_q, *proto_power_smooth_q ) ) ); + move32(); + proto_power_smooth_fx_q = *proto_power_smooth_q; + move16(); + } + ELSE + { + proto_power_smooth_fx[add( l, i_mult( k, num_freq_bands ) )] = L_add( L_shr( proto_power_smooth_fx[add( l, i_mult( k, num_freq_bands ) )], sub( *proto_power_smooth_q, sq_tmp_q ) ), sq_tmp_fx ); + move32(); + proto_power_smooth_fx_q = sq_tmp_q; + move16(); + } + + p_proto_buffer_fx[idx] = proto_frame_f_fx[idx]; + move32(); + p_proto_buffer_fx[add( idx, 1 )] = proto_frame_f_fx[add( idx, 1 )]; + move32(); + } + } + + *proto_direct_buffer_f_q = *proto_frame_f_q; + move16(); + *proto_power_smooth_q = proto_power_smooth_fx_q; + move16(); + + return; +} +#else /*------------------------------------------------------------------------- * protoSignalComputation4() * @@ -2829,7 +3414,7 @@ void protoSignalComputation4( return; } - +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_compute_diffuse_proto() @@ -3196,6 +3781,154 @@ void computeIntensityVector_dec( } +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * ivas_lfe_synth_with_cldfb_fx() + * + * + *------------------------------------------------------------------------*/ + +void ivas_lfe_synth_with_cldfb_fx( + MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 RealBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + const Word16 slot_index, + const Word16 subframe_index, + const Word16 nchan_transport, + Word16 q_cldfb ) +{ + Word16 i; + + Word16 lfeGain_fx, transportGain_fx; + Word32 protoLfeReal_fx, protoLfeImag_fx; + Word32 transportEne_fx, protoLfeEne_fx, targetEneLfe_fx, targetEneTrans_fx; + Word16 transportEne_q, protoLfeEne_q, targetEneLfe_q, targetEneTrans_q; + Word16 temp, temp_q = 0; + Word16 transportGain_q_fx, lfeGain_q_fx; + Word16 exp, min_q_shift; + Word32 re, im; + + exp = Q31; + move16(); + min_q_shift = Q31; + move16(); + + set_zero_fx( RealBufferLfe_fx[slot_index], CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( ImagBufferLfe_fx[slot_index], CLDFB_NO_CHANNELS_MAX ); + + FOR( i = 0; i < nchan_transport; i++ ) + { + IF( RealBuffer_fx[i][0][0] ) + { + exp = norm_l( RealBuffer_fx[i][0][0] ); + } + min_q_shift = s_min( min_q_shift, exp ); + IF( ImagBuffer_fx[i][0][0] ) + { + exp = norm_l( ImagBuffer_fx[i][0][0] ); + } + min_q_shift = s_min( min_q_shift, exp ); + } + min_q_shift = sub( sub( min_q_shift, find_guarded_bits_fx( nchan_transport ) ), 1 ); + + re = L_shl( RealBuffer_fx[0][0][0], min_q_shift ); + im = L_shl( ImagBuffer_fx[0][0][0], min_q_shift ); + + protoLfeReal_fx = re; + move32(); + protoLfeImag_fx = im; + move32(); + transportEne_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); + FOR( i = 1; i < nchan_transport; i++ ) + { + re = L_shl( RealBuffer_fx[i][0][0], min_q_shift ); + im = L_shl( ImagBuffer_fx[i][0][0], min_q_shift ); + + protoLfeReal_fx = L_add( protoLfeReal_fx, re ); + protoLfeImag_fx = L_add( protoLfeImag_fx, im ); + transportEne_fx = L_add( transportEne_fx, Madd_32_32( Mpy_32_32( re, re ), im, im ) ); + } + transportEne_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); + + protoLfeEne_fx = Madd_32_32( Mpy_32_32( protoLfeReal_fx, protoLfeReal_fx ), protoLfeImag_fx, protoLfeImag_fx ); + protoLfeEne_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); + + targetEneLfe_fx = Mpy_32_16_1( transportEne_fx, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ); + targetEneLfe_q = sub( add( transportEne_q, Q14 ), 15 ); + + temp = s_max( sub( ONE_IN_Q14, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ), 164 ); // 164 = 0.01 in Q14 + targetEneTrans_fx = Mpy_32_16_1( transportEne_fx, temp ); + targetEneTrans_q = sub( add( transportEne_q, Q14 ), 15 ); + + hMasaLfeSynth->transportEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->transportEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + hMasaLfeSynth->protoLfeEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->protoLfeEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + hMasaLfeSynth->targetEneLfeSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneLfeSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + hMasaLfeSynth->targetEneTransSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneTransSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + + hMasaLfeSynth->transportEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->transportEneSmooth_fx, sub( 31, hMasaLfeSynth->transportEneSmooth_q ), transportEne_fx, sub( 31, transportEne_q ), &temp_q ); + hMasaLfeSynth->transportEneSmooth_q = sub( 31, temp_q ); + + hMasaLfeSynth->protoLfeEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->protoLfeEneSmooth_fx, sub( 31, hMasaLfeSynth->protoLfeEneSmooth_q ), protoLfeEne_fx, sub( 31, protoLfeEne_q ), &temp_q ); + hMasaLfeSynth->protoLfeEneSmooth_q = sub( 31, temp_q ); + + hMasaLfeSynth->targetEneLfeSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneLfeSmooth_fx, sub( 31, hMasaLfeSynth->targetEneLfeSmooth_q ), targetEneLfe_fx, sub( 31, targetEneLfe_q ), &temp_q ); + hMasaLfeSynth->targetEneLfeSmooth_q = sub( 31, temp_q ); + + hMasaLfeSynth->targetEneTransSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneTransSmooth_fx, sub( 31, hMasaLfeSynth->targetEneTransSmooth_q ), targetEneTrans_fx, sub( 31, targetEneTrans_q ), &temp_q ); + hMasaLfeSynth->targetEneTransSmooth_q = sub( 31, temp_q ); + + temp = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneLfeSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->protoLfeEneSmooth_fx ), &temp_q ); + temp_q = add( sub( hMasaLfeSynth->targetEneLfeSmooth_q, hMasaLfeSynth->protoLfeEneSmooth_q ), sub( Q15, temp_q ) ); + + exp = sub( Q15, temp_q ); + lfeGain_fx = Sqrt16( temp, &exp ); + lfeGain_q_fx = sub( Q15, exp ); + + IF( GT_32( L_shr( lfeGain_fx, sub( lfeGain_q_fx, Q14 ) ), ONE_IN_Q14 ) ) + { + lfeGain_fx = ONE_IN_Q14; + move16(); + lfeGain_q_fx = Q14; + move16(); + } + + temp = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneTransSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->transportEneSmooth_fx ), &temp_q ); + temp_q = add( sub( hMasaLfeSynth->targetEneTransSmooth_q, hMasaLfeSynth->transportEneSmooth_q ), sub( Q15, temp_q ) ); + + exp = sub( Q15, temp_q ); + transportGain_fx = Sqrt16( temp, &exp ); + transportGain_q_fx = sub( Q15, exp ); + + IF( GT_32( L_shr( transportGain_fx, sub( transportGain_q_fx, Q14 ) ), ONE_IN_Q14 ) ) + { + transportGain_fx = ONE_IN_Q14; + move16(); + transportGain_q_fx = Q14; + move16(); + } + + RealBufferLfe_fx[slot_index][0] = L_shr( Mpy_32_16_1( protoLfeReal_fx, lfeGain_fx ), add( min_q_shift, sub( lfeGain_q_fx, Q15 ) ) ); // q_cldfb + move32(); + ImagBufferLfe_fx[slot_index][0] = L_shr( Mpy_32_16_1( protoLfeImag_fx, lfeGain_fx ), add( min_q_shift, sub( lfeGain_q_fx, Q15 ) ) ); // q_cldfb + move32(); + + RealBuffer_fx[0][0][0] = L_shr( Mpy_32_16_1( RealBuffer_fx[0][0][0], transportGain_fx ), sub( transportGain_q_fx, Q15 ) ); // Q = q_cldfb + move32(); + ImagBuffer_fx[0][0][0] = L_shr( Mpy_32_16_1( ImagBuffer_fx[0][0][0], transportGain_fx ), sub( transportGain_q_fx, Q15 ) ); // Q = q_cldfb + move32(); + FOR( i = 1; i < nchan_transport; i++ ) + { + RealBuffer_fx[i][0][0] = L_shr( Mpy_32_16_1( RealBuffer_fx[i][0][0], transportGain_fx ), sub( transportGain_q_fx, Q15 ) ); // Q = q_cldfb + move32(); + ImagBuffer_fx[i][0][0] = L_shr( Mpy_32_16_1( ImagBuffer_fx[i][0][0], transportGain_fx ), sub( transportGain_q_fx, Q15 ) ); // Q = q_cldfb + move32(); + } + + return; +} +#else /*------------------------------------------------------------------------- * ivas_lfe_synth_with_cldfb() * @@ -3261,8 +3994,123 @@ void ivas_lfe_synth_with_cldfb( return; } +#endif + +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * rotateAziEle_DirAC_fx() + * + * Apply rotation to DirAC DOAs + *------------------------------------------------------------------------*/ + +void rotateAziEle_DirAC_fx( + Word16 *azi, /* i/o: array of azimuth values */ + Word16 *ele, /* i/o: array of elevation values */ + const Word16 band1, /* i : bands to work on (lower limit) */ + const Word16 band2, /* i : bands to work on (upper bound) */ + const Word32 *p_Rmat_fx /* i : pointer to real-space rotation matrix */ +) +{ + Word16 b; + Word32 dv_0_fx, dv_1_fx, dv_2_fx; + Word32 dv_r_0_fx, dv_r_1_fx, dv_r_2_fx, tmp, w_fx; + Word16 exp, temp; + Word32 *ptr_sin, *ptr_cos; + + ptr_sin = &sine_table_Q31[180]; // sin[x] = sine_table_Q31[180 + x] + ptr_cos = cosine_table_Q31; + + push_wmops( "rotateAziEle_DirAC" ); + FOR( b = band1; b < band2; b++ ) + { + /*Conversion spherical to cartesian coordinates*/ + IF( GT_16( abs_s( ele[b] ), 180 ) ) + { + // cos(180 + x) = -cos(x) + w_fx = -ptr_cos[sub( abs_s( ele[b] ), 180 )]; // Q31 + move32(); + } + ELSE + { + w_fx = ptr_cos[abs_s( ele[b] )]; // Q31 + move32(); + } + IF( GT_16( abs_s( azi[b] ), 180 ) ) + { + // cos(180 + x) = -cos(x) + tmp = -ptr_cos[sub( abs_s( azi[b] ), 180 )]; // Q31 + move32(); + } + ELSE + { + tmp = ptr_cos[abs_s( azi[b] )]; // Q31 + move32(); + } + + dv_0_fx = Mpy_32_32( w_fx, tmp ); // Q31 + + + IF( GT_16( azi[b], 180 ) ) + { + // sin(180 + x) = -sin(x) + tmp = -ptr_sin[sub( azi[b], 180 )]; // Q31 + move32(); + } + ELSE IF( LT_16( azi[b], -180 ) ) + { + // sin(-(180 + x)) = sin(180 + x) = sinx + tmp = ptr_sin[sub( abs_s( azi[b] ), 180 )]; // Q31 + move32(); + } + ELSE + { + tmp = ptr_sin[azi[b]]; // Q31 + move32(); + } + dv_1_fx = Mpy_32_32( w_fx, tmp ); // Q31 + + IF( GT_16( ele[b], 180 ) ) + { + // sin(180 + x) = -sin(x) + dv_2_fx = -ptr_sin[sub( ele[b], 180 )]; // Q31 + move32(); + } + ELSE IF( LT_16( ele[b], -180 ) ) + { + // sin(-(180 + x)) = -sin(180 + x) = sinx + dv_2_fx = ptr_sin[sub( abs_s( ele[b] ), 180 )]; // Q31 + move32(); + } + ELSE + { + dv_2_fx = ptr_sin[ele[b]]; // Q31 + move32(); + } + + dv_r_0_fx = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[0], dv_0_fx ), p_Rmat_fx[1], dv_1_fx ), p_Rmat_fx[2], dv_2_fx ); // Q29 + dv_r_1_fx = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[3], dv_0_fx ), p_Rmat_fx[4], dv_1_fx ), p_Rmat_fx[5], dv_2_fx ); // Q29 + dv_r_2_fx = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[6], dv_0_fx ), p_Rmat_fx[7], dv_1_fx ), p_Rmat_fx[8], dv_2_fx ); // Q29 + + /*Conversion spherical to cartesian coordinates*/ + temp = BASOP_util_atan2( dv_r_1_fx, dv_r_0_fx, 0 ); // Q13 + azi[b] = shr( mult( temp, _180_OVER_PI_Q9 ), 7 ); // Q0; + move16(); + + tmp = L_add( Mpy_32_32( dv_r_0_fx, dv_r_0_fx ), Mpy_32_32( dv_r_1_fx, dv_r_1_fx ) ); // Q27 + exp = sub( 31, Q27 ); + tmp = Sqrt32( tmp, &exp ); + temp = BASOP_util_atan2( dv_r_2_fx, tmp, sub( sub( 31, 29 ), exp ) ); // Q13 + ele[b] = shr( mult( temp, _180_OVER_PI_Q9 ), 7 ); // Q0 + move16(); + } + + pop_wmops(); + + return; +} +#endif /*------------------------------------------------------------------------- * rotateAziEle_DirAC() * diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index 8e4dbe3f1fcca86a091c3045466edb4519751a67..03d3403b034c5a62eb231121acef15a65c5255ee 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -533,6 +533,7 @@ void efap_determine_gains_fixed( * Wrapper to free EFAP data structure *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void efap_free_data( EFAP_HANDLE *hEFAPdata /* i/o: EFAP handle to be freed */ ) @@ -559,15 +560,7 @@ void efap_free_data( free( ( *hEFAPdata )->vtxData.vtxOrder ); ( *hEFAPdata )->vtxData.vtxOrder = NULL; -#ifndef IVAS_FLOAT_FIXED - free( ( *hEFAPdata )->bufferLong ); - ( *hEFAPdata )->bufferLong = NULL; - free( ( *hEFAPdata )->bufferShort ); - ( *hEFAPdata )->bufferShort = NULL; - - p_dmTranspose = (void **) ( *hEFAPdata )->dmTranspose; -#else free( ( *hEFAPdata )->bufferLong_fx ); ( *hEFAPdata )->bufferLong_fx = NULL; @@ -575,7 +568,55 @@ void efap_free_data( ( *hEFAPdata )->bufferShort_fx = NULL; p_dmTranspose = (void **) ( *hEFAPdata )->dmTranspose_fx; -#endif + + FOR( i = 0; i < dim1; i++ ) + { + free( p_dmTranspose[i] ); + } + free( p_dmTranspose ); + + /* instance */ + free( *hEFAPdata ); + *hEFAPdata = NULL; + + return; +} +#else +void efap_free_data( + EFAP_HANDLE *hEFAPdata /* i/o: EFAP handle to be freed */ +) +{ + Word16 i, dim1; + void **p_dmTranspose; + + IF( hEFAPdata == NULL || *hEFAPdata == NULL ) + { + return; + } + + dim1 = ( *hEFAPdata )->numTot; + + /* instance buffer members */ + free( ( *hEFAPdata )->aziSpk ); + ( *hEFAPdata )->aziSpk = NULL; + + free( ( *hEFAPdata )->eleSpk ); + ( *hEFAPdata )->eleSpk = NULL; + + free( ( *hEFAPdata )->vtxData.vertexArray ); + ( *hEFAPdata )->vtxData.vertexArray = NULL; + + free( ( *hEFAPdata )->vtxData.vtxOrder ); + ( *hEFAPdata )->vtxData.vtxOrder = NULL; + + free( ( *hEFAPdata )->bufferLong ); + ( *hEFAPdata )->bufferLong = NULL; + + free( ( *hEFAPdata )->bufferShort ); + ( *hEFAPdata )->bufferShort = NULL; + + p_dmTranspose = (void **) ( *hEFAPdata )->dmTranspose; + FOR( i = 0; i < dim1; i++ ) { free( p_dmTranspose[i] ); @@ -588,6 +629,7 @@ void efap_free_data( return; } +#endif /*-----------------------------------------------------------------------* diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index ac3284302e5155fd8af06810332d650230767065..553b60a05e03de02002838eefaf3d8d7cf74ea6f 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -409,11 +409,23 @@ ivas_error ivas_td_binaural_open_unwrap( { return error; } +#ifdef IVAS_FLOAT_FIXED + // Can remove this once TDREND_MIX_SRC_SetPos_fx is integrated above. + pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p_fx[0] = float_to_fix(pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p[0], Q25); + pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p_fx[1] = float_to_fix(pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p[1], Q25); + pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p_fx[2] = float_to_fix(pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p[2], Q25); +#endif if ( ( error = TDREND_MIX_SRC_SetDir( pBinRendTd, nS, Dir ) ) != IVAS_ERR_OK ) { return error; } +#ifdef IVAS_FLOAT_FIXED + // Can remove this once TDREND_MIX_SRC_SetDir_fx is integrated above. + pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p_fx[0] = float_to_fix(pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p[0], Q30); + pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p_fx[1] = float_to_fix(pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p[1], Q30); + pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p_fx[2] = float_to_fix(pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p[2], Q30); +#endif if ( ( error = TDREND_MIX_SRC_SetPlayState( pBinRendTd, nS, TDREND_PLAYSTATUS_PLAYING ) ) != IVAS_ERR_OK ) { @@ -562,12 +574,29 @@ ivas_error ivas_td_binaural_renderer_unwrap( subframe_length = output_frame / num_subframes; +#ifdef IVAS_FLOAT_FIXED + Word32 output_fx_buf[MAX_OUTPUT_CHANNELS][L_FRAME48k]; + Word32 *output_fx[MAX_OUTPUT_CHANNELS]; + for (int i = 0; i < MAX_OUTPUT_CHANNELS; i++) + { + output_fx[i] = output_fx_buf[i]; + for (int j = 0; j < L_FRAME48k; j++) + { + output_fx[i][j] = floatToFixed(output[i][j], Q11); + } + } +#endif + c_indx = 0; for ( nS = 0; nS < num_src; nS++ ) { if ( !( ivas_format == MC_FORMAT && nS == lfe_idx ) ) /* Skip LFE for MC */ { hBinRendererTd->Sources[c_indx]->InputFrame_p = output[nS]; +#ifdef IVAS_FLOAT_FIXED + hBinRendererTd->Sources[c_indx]->InputFrame_p_fx = output_fx[nS]; + hBinRendererTd->Sources[c_indx]->InputFrame_p_q = Q11; +#endif hBinRendererTd->Sources[c_indx]->SrcRend_p->InputAvailable = TRUE; c_indx++; } @@ -585,10 +614,77 @@ ivas_error ivas_td_binaural_renderer_unwrap( } /* Update the listener's location/orientation */ +#ifdef IVAS_FLOAT_FIXED + Word16 tmp_headRotEnabled; + IVAS_QUATERNION* tmp_Quaternions; + IVAS_VECTOR3* tmp_Pos; + + tmp_headRotEnabled = 0; + move16(); + tmp_Quaternions = NULL; + tmp_Pos = NULL; + + IF(enableCombinedOrientation != NULL) + { + tmp_headRotEnabled = enableCombinedOrientation[hCombinedOrientationData->subframe_idx]; + move16(); + } + IF(Quaternions != NULL) + { + tmp_Quaternions = &Quaternions[hCombinedOrientationData->subframe_idx]; + } + IF(Pos != NULL) + { + tmp_Pos = &Pos[hCombinedOrientationData->subframe_idx]; + } + + // Float to fixed + float max_val = 0; + max_val = (float)max(max_val, fabs(tmp_Quaternions->w)); + max_val = (float)max(max_val, fabs(tmp_Quaternions->x)); + max_val = (float)max(max_val, fabs(tmp_Quaternions->y)); + max_val = (float)max(max_val, fabs(tmp_Quaternions->z)); + Word16 quat_q = Q_factor_L(max_val); + tmp_Quaternions->w_fx = float_to_fix(tmp_Quaternions->w, quat_q); + tmp_Quaternions->x_fx = float_to_fix(tmp_Quaternions->x, quat_q); + tmp_Quaternions->y_fx = float_to_fix(tmp_Quaternions->y, quat_q); + tmp_Quaternions->z_fx = float_to_fix(tmp_Quaternions->z, quat_q); + tmp_Quaternions->w_qfact = tmp_Quaternions->x_qfact = tmp_Quaternions->y_qfact = tmp_Quaternions->z_qfact = quat_q; + + Word16 pos_q = Q25; + tmp_Pos->x_fx = (Word32)float_to_fix(tmp_Pos->x, pos_q); + tmp_Pos->y_fx = (Word32)float_to_fix(tmp_Pos->y, pos_q); + tmp_Pos->z_fx = (Word32)float_to_fix(tmp_Pos->z, pos_q); + tmp_Pos->x_qfact = tmp_Pos->y_qfact = tmp_Pos->z_qfact = pos_q; + for (int i = 0; i < 3; i++) + { + hBinRendererTd->Listener_p->Front_fx[i] = float_to_fix(hBinRendererTd->Listener_p->Front[i], Q30); + hBinRendererTd->Listener_p->Up_fx[i] = float_to_fix(hBinRendererTd->Listener_p->Up[i], Q30); + hBinRendererTd->Listener_p->Right_fx[i] = float_to_fix(hBinRendererTd->Listener_p->Right[i], Q30); + hBinRendererTd->Listener_p->Pos_q = pos_q; + hBinRendererTd->Listener_p->Pos_fx[i] = float_to_fix(hBinRendererTd->Listener_p->Pos[i], hBinRendererTd->Listener_p->Pos_q); + } + // end float to fix + + IF ( ( error = TDREND_Update_listener_orientation_fx( hBinRendererTd, tmp_headRotEnabled, tmp_Quaternions, tmp_Pos ) ) != IVAS_ERR_OK ) + { + return error; + } + + // fix to float + for (int i = 0; i < 3; i++) + { + hBinRendererTd->Listener_p->Front[i] = fix_to_float(hBinRendererTd->Listener_p->Front_fx[i], Q30); + hBinRendererTd->Listener_p->Up[i] = fix_to_float(hBinRendererTd->Listener_p->Up_fx[i], Q30); + hBinRendererTd->Listener_p->Right[i] = fix_to_float(hBinRendererTd->Listener_p->Right_fx[i], Q30); + hBinRendererTd->Listener_p->Pos[i] = fix_to_float(hBinRendererTd->Listener_p->Pos_fx[i], hBinRendererTd->Listener_p->Pos_q); + } +#else if ( ( error = TDREND_Update_listener_orientation( hBinRendererTd, ( enableCombinedOrientation != NULL ) ? enableCombinedOrientation[hCombinedOrientationData->subframe_idx] : 0, ( Quaternions != NULL ) ? &Quaternions[hCombinedOrientationData->subframe_idx] : NULL, ( Pos != NULL ) ? &Pos[hCombinedOrientationData->subframe_idx] : NULL ) ) != IVAS_ERR_OK ) { return error; } +#endif if ( hReverb != NULL ) { @@ -647,10 +743,28 @@ ivas_error ivas_td_binaural_renderer_unwrap( } /* Render subframe */ +#ifdef IVAS_FLOAT_FIXED + ////// Float to fix ///// + FOR(Word16 i = 0; i < hBinRendererTd->NumOfSrcs; i++) + { + FOR (int j = 0; j < 3; j++) + { + hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p_fx[j] = float_to_fix(hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p[j], Q25); + } + } + IF ( ( error = TDREND_GetMix_fx( hBinRendererTd, output_fx, subframe_length, subframe_idx, ism_md_subframe_update ) ) != IVAS_ERR_OK ) + { + return error; + } + /////// Fix to float //////// + me2f_buf(output_fx[0], 31 - Q11, output[0], (subframe_idx + 1)*subframe_length); + me2f_buf(output_fx[1], 31 - Q11, output[1], (subframe_idx + 1)*subframe_length); +#else if ( ( error = TDREND_GetMix( hBinRendererTd, output, subframe_length, subframe_idx, ism_md_subframe_update ) ) != IVAS_ERR_OK ) { return error; } +#endif /* Advance subframe pointer */ c_indx = 0; @@ -659,6 +773,9 @@ ivas_error ivas_td_binaural_renderer_unwrap( if ( !( ivas_format == MC_FORMAT && nS == lfe_idx ) ) /* Skip LFE for MC */ { hBinRendererTd->Sources[c_indx]->InputFrame_p += subframe_length; +#ifdef IVAS_FLOAT_FIXED + hBinRendererTd->Sources[c_indx]->InputFrame_p_fx += subframe_length; +#endif c_indx++; } } @@ -672,6 +789,12 @@ ivas_error ivas_td_binaural_renderer_unwrap( /* add reverb to rendered signals */ v_add( reverb_signal[0], output[0], output[0], output_frame ); v_add( reverb_signal[1], output[1], output[1], output_frame ); +#ifdef IVAS_FLOAT_FIXED + for (int i = 0; i < output_frame; i++) + { + output_fx[0][i] = float_to_fix(output[0][i], Q11); + } +#endif } return IVAS_ERR_OK; diff --git a/lib_rend/ivas_objectRenderer_mix.c b/lib_rend/ivas_objectRenderer_mix.c index 97a64b3a3fa513dbb11594595345dc2503817f9b..c0750a26a3809815cd51c4dbed770a9a0949f452 100644 --- a/lib_rend/ivas_objectRenderer_mix.c +++ b/lib_rend/ivas_objectRenderer_mix.c @@ -351,6 +351,7 @@ ivas_error TDREND_MIX_Init_fx( move16(); /* Init virtual and rendering listeners for spatial mixers */ TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Pos_fx, 0, 0, 0 ); + hBinRendererTd->Listener_p->Pos_q = Q25; TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Vel_fx, 0, 0, 0 ); TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Front_fx, 0, 0, -ONE_IN_Q30 ); TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Up_fx, 0, ONE_IN_Q30, 0 ); @@ -417,6 +418,7 @@ ivas_error TDREND_MIX_Init( #ifdef IVAS_FLOAT_FIXED TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Pos_fx, 0, 0, 0 ); + hBinRendererTd->Listener_p->Pos_q = Q25; TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Vel_fx, 0, 0, 0 ); TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Front_fx, 0, 0, -ONE_IN_Q30 ); TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Up_fx, 0, ONE_IN_Q30, 0 ); @@ -873,16 +875,16 @@ static ivas_error DefaultBSplineModel_fx( modelITD->resamp_factor = 1.0f; } #endif - model->AlphaL_fx = defaultHRIR_rom_AlphaL48_fx; + model->AlphaL_fx = (const Word32 *)defaultHRIR_rom_AlphaL48_fx; model->AlphaL_e = 1; move16(); - model->AlphaR_fx = defaultHRIR_rom_AlphaR48_fx; + model->AlphaR_fx = (const Word32 *)defaultHRIR_rom_AlphaR48_fx; model->AlphaR_e = 1; move16(); - model->EL_fx = defaultHRIR_rom_EL48_fx; + model->EL_fx = (const Word32 *)defaultHRIR_rom_EL48_fx; model->EL_e = 3; move16(); - model->ER_fx = defaultHRIR_rom_ER48_fx; + model->ER_fx = (const Word32 *)defaultHRIR_rom_ER48_fx; model->ER_e = 3; move16(); model->K = 128; @@ -904,16 +906,16 @@ static ivas_error DefaultBSplineModel_fx( modelITD->resamp_factor = RESAMPLE_FACTOR_32_48; } #endif - model->AlphaL_fx = defaultHRIR_rom_AlphaL32_fx; + model->AlphaL_fx = (const Word32 *)defaultHRIR_rom_AlphaL32_fx; model->AlphaL_e = 1; move16(); - model->AlphaR_fx = defaultHRIR_rom_AlphaR32_fx; + model->AlphaR_fx = (const Word32 *)defaultHRIR_rom_AlphaR32_fx; model->AlphaR_e = 1; move16(); - model->EL_fx = defaultHRIR_rom_EL32_fx; + model->EL_fx = (const Word32 *)defaultHRIR_rom_EL32_fx; model->EL_e = 3; move16(); - model->ER_fx = defaultHRIR_rom_ER32_fx; + model->ER_fx = (const Word32 *)defaultHRIR_rom_ER32_fx; model->ER_e = 3; move16(); model->K = 86; @@ -935,16 +937,16 @@ static ivas_error DefaultBSplineModel_fx( modelITD->resamp_factor = RESAMPLE_FACTOR_16_48; } #endif - model->AlphaL_fx = defaultHRIR_rom_AlphaL16_fx; + model->AlphaL_fx = (const Word32 *)defaultHRIR_rom_AlphaL16_fx; model->AlphaL_e = 1; move16(); - model->AlphaR_fx = defaultHRIR_rom_AlphaR16_fx; + model->AlphaR_fx = (const Word32 *)defaultHRIR_rom_AlphaR16_fx; model->AlphaR_e = 1; move16(); - model->EL_fx = defaultHRIR_rom_EL16_fx; + model->EL_fx = (const Word32 *)defaultHRIR_rom_EL16_fx; model->EL_e = 3; move16(); - model->ER_fx = defaultHRIR_rom_ER16_fx; + model->ER_fx = (const Word32 *)defaultHRIR_rom_ER16_fx; model->ER_e = 3; move16(); model->K = 43; @@ -1018,7 +1020,7 @@ static ivas_error DefaultBSplineModel_fx( modelITD->elevBsShape = (const float *) defaultHRIR_rom_ITD_elevBsShape; #endif modelITD->azimKSeq_fx = defaultHRIR_rom_ITD_azimKSeq_fx; - modelITD->W_fx = defaultHRIR_rom_ITD_W_fx;//Q25 + modelITD->W_fx = (const Word32 *)defaultHRIR_rom_ITD_W_fx;//Q25 modelITD->W_e = 6; move16(); modelITD->azimBsShape_fx = defaultHRIR_rom_ITD_azimBsShape_fx; @@ -1194,16 +1196,16 @@ static ivas_error DefaultBSplineModel( model->EL = (const float *) defaultHRIR_rom_EL48; model->ER = (const float *) defaultHRIR_rom_ER48; #ifdef IVAS_FLOAT_FIXED - model->AlphaL_fx = defaultHRIR_rom_AlphaL48_fx; + model->AlphaL_fx = (const Word32 *)defaultHRIR_rom_AlphaL48_fx; model->AlphaL_e = 1; move16(); - model->AlphaR_fx = defaultHRIR_rom_AlphaR48_fx; + model->AlphaR_fx = (const Word32 *)defaultHRIR_rom_AlphaR48_fx; model->AlphaR_e = 1; move16(); - model->EL_fx = defaultHRIR_rom_EL48_fx; + model->EL_fx = (const Word32 *)defaultHRIR_rom_EL48_fx; model->EL_e = 3; move16(); - model->ER_fx = defaultHRIR_rom_ER48_fx; + model->ER_fx = (const Word32 *)defaultHRIR_rom_ER48_fx; model->ER_e = 3; move16(); #endif @@ -1222,16 +1224,16 @@ static ivas_error DefaultBSplineModel( model->EL = (const float *) defaultHRIR_rom_EL32; model->ER = (const float *) defaultHRIR_rom_ER32; #ifdef IVAS_FLOAT_FIXED - model->AlphaL_fx = defaultHRIR_rom_AlphaL32_fx; + model->AlphaL_fx = (const Word32 *)defaultHRIR_rom_AlphaL32_fx; model->AlphaL_e = 1; move16(); - model->AlphaR_fx = defaultHRIR_rom_AlphaR32_fx; + model->AlphaR_fx = (const Word32 *)defaultHRIR_rom_AlphaR32_fx; model->AlphaR_e = 1; move16(); - model->EL_fx = defaultHRIR_rom_EL32_fx; + model->EL_fx = (const Word32 *)defaultHRIR_rom_EL32_fx; model->EL_e = 3; move16(); - model->ER_fx = defaultHRIR_rom_ER32_fx; + model->ER_fx = (const Word32 *)defaultHRIR_rom_ER32_fx; model->ER_e = 3; move16(); #endif @@ -1250,16 +1252,16 @@ static ivas_error DefaultBSplineModel( model->EL = (const float *) defaultHRIR_rom_EL16; model->ER = (const float *) defaultHRIR_rom_ER16; #ifdef IVAS_FLOAT_FIXED - model->AlphaL_fx = defaultHRIR_rom_AlphaL16_fx; + model->AlphaL_fx = (const Word32 *)defaultHRIR_rom_AlphaL16_fx; model->AlphaL_e = 1; move16(); - model->AlphaR_fx = defaultHRIR_rom_AlphaR16_fx; + model->AlphaR_fx = (const Word32 *)defaultHRIR_rom_AlphaR16_fx; model->AlphaR_e = 1; move16(); - model->EL_fx = defaultHRIR_rom_EL16_fx; + model->EL_fx = (const Word32 *)defaultHRIR_rom_EL16_fx; model->EL_e = 3; move16(); - model->ER_fx = defaultHRIR_rom_ER16_fx; + model->ER_fx = (const Word32 *)defaultHRIR_rom_ER16_fx; model->ER_e = 3; move16(); #endif @@ -1315,7 +1317,7 @@ static ivas_error DefaultBSplineModel( modelITD->azimBsShape = (const float *) defaultHRIR_rom_ITD_azimBsShape; modelITD->elevBsShape = (const float *) defaultHRIR_rom_ITD_elevBsShape; #ifdef IVAS_FLOAT_FIXED - modelITD->W_fx = defaultHRIR_rom_ITD_W_fx;//Q25 + modelITD->W_fx = (const Word32 *)defaultHRIR_rom_ITD_W_fx;//Q25 modelITD->W_e = 6; move16(); modelITD->azimBsShape_fx = defaultHRIR_rom_ITD_azimBsShape_fx; diff --git a/lib_rend/ivas_objectRenderer_vec.c b/lib_rend/ivas_objectRenderer_vec.c index cd30ab368d4e29ac97cbf7489191c95a1a098cf4..243001e2630f05e9d16285c70b1dda6f5b2daafe 100644 --- a/lib_rend/ivas_objectRenderer_vec.c +++ b/lib_rend/ivas_objectRenderer_vec.c @@ -147,7 +147,7 @@ void TDREND_SPATIAL_VecNormalize_fx( Word16 exp, shift; sqrd_sum = L_add( Mpy_32_32( Vec_p_fx[0], Vec_p_fx[0] ), L_add( Mpy_32_32( Vec_p_fx[1], Vec_p_fx[1] ), Mpy_32_32( Vec_p_fx[2], Vec_p_fx[2] ) ) ); - exp = 62-2*q; + exp = shl( sub( 31, q ), 1 ); scaler_fx = ISqrt32( sqrd_sum, &exp ); VecNorm_p_fx[0] = Mpy_32_32( scaler_fx, Vec_p_fx[0] ); @@ -156,7 +156,7 @@ void TDREND_SPATIAL_VecNormalize_fx( move16(); VecNorm_p_fx[2] = Mpy_32_32( scaler_fx, Vec_p_fx[2] ); move16(); - exp = exp + (31 - q); + exp = add( exp, sub( 31, q ) ); // Since vector is normalised, all values will be <= 1. Hence making all values in Q30 shift = exp - 1; diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index af242aa45fa1237e6fea5188ade8a39616a3636b..0f8aa96338c3665999efe8db864dc043628b3108 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -1400,20 +1400,19 @@ ivas_error ivas_orient_trk_Process_fx( //===================Remove float code once caller function is converted to fixed=================// float alpha = pOTR->alpha; ivas_error result; - IVAS_QUATERNION absRot_fx = { 0 }; Word32 updateRate_fx; Word32 rateRange_fx; Word32 cutoffFrequency_fx, cutoff_prod; Word16 q_cutoff_prod = 0; Word32 alpha_fx = float_to_fix( alpha, Q30 ); pOTR->refRot.w_qfact = pOTR->refRot.x_qfact = pOTR->refRot.y_qfact = pOTR->refRot.z_qfact = Q29; - absRot_fx.w_qfact = absRot_fx.x_qfact = absRot_fx.y_qfact = absRot_fx.z_qfact = Q29; + absRot.w_qfact = absRot.x_qfact = absRot.y_qfact = absRot.z_qfact = Q29; pOTR->absAvgRot.w_qfact = pOTR->absAvgRot.x_qfact = pOTR->absAvgRot.y_qfact = pOTR->absAvgRot.z_qfact = Q29; updateRate_fx = float_to_fix( updateRate, Q23 ); // value is 200// - absRot_fx.w_fx = float_to_fix( absRot.w, absRot_fx.w_qfact ); - absRot_fx.x_fx = float_to_fix( absRot.x, absRot_fx.x_qfact ); - absRot_fx.y_fx = float_to_fix( absRot.y, absRot_fx.y_qfact ); - absRot_fx.z_fx = float_to_fix( absRot.z, absRot_fx.z_qfact ); + absRot.w_fx = float_to_fix( absRot.w, absRot.w_qfact ); + absRot.x_fx = float_to_fix( absRot.x, absRot.x_qfact ); + absRot.y_fx = float_to_fix( absRot.y, absRot.y_qfact ); + absRot.z_fx = float_to_fix( absRot.z, absRot.z_qfact ); pOTR->refRot.w_fx = float_to_fix( pOTR->refRot.w, pOTR->refRot.w_qfact ); pOTR->refRot.x_fx = float_to_fix( pOTR->refRot.x, pOTR->refRot.x_qfact ); pOTR->refRot.y_fx = float_to_fix( pOTR->refRot.y, pOTR->refRot.y_qfact ); @@ -1433,13 +1432,13 @@ ivas_error ivas_orient_trk_Process_fx( SWITCH ( pOTR->orientation_tracking ) { case IVAS_HEAD_ORIENT_TRK_NONE: - pOTR->trkRot = absRot_fx; + pOTR->trkRot = absRot; BREAK; case IVAS_HEAD_ORIENT_TRK_REF: case IVAS_HEAD_ORIENT_TRK_REF_VEC: case IVAS_HEAD_ORIENT_TRK_REF_VEC_LEV: /* Reset average orientation */ - pOTR->absAvgRot = absRot_fx; + pOTR->absAvgRot = absRot; Word16 scale_e; Word32 div; @@ -1456,13 +1455,13 @@ ivas_error ivas_orient_trk_Process_fx( case IVAS_HEAD_ORIENT_TRK_AVG: /* Compute average (low-pass filtered) absolute orientation */ - QuaternionSlerp_fx( pOTR->absAvgRot, absRot_fx, alpha_fx, &pOTR->absAvgRot ); + QuaternionSlerp_fx( pOTR->absAvgRot, absRot, alpha_fx, &pOTR->absAvgRot ); /* Compute relative orientation = (absolute orientation) - (average absolute orientation) */ QuaternionInverse_fx( pOTR->absAvgRot, &pOTR->trkRot ); Word32 angle_fx, relativeOrientationRate_fx = 0; - QuaternionProduct_fx( pOTR->trkRot, absRot_fx, &pOTR->trkRot ); - angle_fx = QuaternionAngle_fx( absRot_fx, pOTR->trkRot ); // Q29 + QuaternionProduct_fx( pOTR->trkRot, absRot, &pOTR->trkRot ); + angle_fx = QuaternionAngle_fx( absRot, pOTR->trkRot ); // Q29 Word16 result_e = 0; Word16 temp_result = BASOP_Util_Divide3232_Scale( angle_fx, PI_OVER_4_Q29, &result_e ); relativeOrientationRate_fx = L_deposit_h( temp_result ); diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 7371e258ceb5397afb75a741160b7741ef817376..122e8298f12bc8bd4f22366d27a8346c15b54e55 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -297,13 +297,21 @@ void vbap_free_data( * DirAC/MASA rendering *----------------------------------------------------------------------------------*/ -void ivas_sba_prototype_renderer( +void ivas_sba_prototype_renderer_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ - float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ - float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ + Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ + Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ + Word16 q_cldfb[6][CLDFB_SLOTS_PER_SUBFRAME], const int16_t subframe /* i : Subframe to render */ ); +void ivas_sba_prototype_renderer( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ + float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ + float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ + const int16_t subframe /* i : Subframe to render */ +); + #ifndef IVAS_FLOAT_FIXED ivas_error ivas_sba_get_hoa_dec_matrix( const IVAS_OUTPUT_SETUP hOutSetup, /* i : target output setup */ @@ -349,6 +357,12 @@ ivas_error ivas_dirac_dec_init_binaural_data( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i : HRTF structure for rendering */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_dirac_dec_init_binaural_data_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i : HRTF structure for rendering */ +); +#endif void ivas_dirac_dec_close_binaural_data( DIRAC_DEC_BIN_HANDLE *hBinaural /* i/o: decoder DirAC binaural data handle */ @@ -416,7 +430,24 @@ void computeIntensityVector_dec( float *intensity_real_y, float *intensity_real_z ); - +#ifdef IVAS_FLOAT_FIXED +void protoSignalComputation_shd_fx( + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 *proto_direct_buffer_f_fx, + Word16 *proto_direct_buffer_f_q, + Word32 *proto_diffuse_buffer_f_fx, + Word16 *proto_diffuse_buffer_f_q, + Word32 *reference_power_fx, + Word16 *reference_power_q, + const Word16 slot_index, + const Word16 num_inputs, + const Word16 num_outputs_diff, + const Word16 num_freq_bands, + Word32 *p_Rmat_fx, + Word16 q_cldfb +); +#endif void protoSignalComputation_shd( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -430,6 +461,24 @@ void protoSignalComputation_shd( float *p_Rmat ); +#ifdef IVAS_FLOAT_FIXED +void protoSignalComputation1_fx( + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 *proto_frame_f_fx, + Word16 *proto_frame_f_q, + Word32 *proto_direct_buffer_f_fx, + Word16 *proto_direct_buffer_f_q, + Word32 *reference_power_fx, + Word16 *reference_power_q, + Word32 *proto_power_smooth_fx, + Word16 *proto_power_smooth_q, + const Word16 slot_index, + const Word16 num_outputs_diff, + const Word16 num_freq_bands, + Word16 q_cldfb +); +#endif void protoSignalComputation1( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -455,6 +504,27 @@ void protoSignalComputation2( MASA_STEREO_TYPE_DETECT *stereo_type_detect ); +#ifdef IVAS_FLOAT_FIXED +void protoSignalComputation4_fx( + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 *proto_frame_f_fx, + Word16 *proto_frame_f_q, + Word32 *proto_direct_buffer_f_fx, + Word16 *proto_direct_buffer_f_q, + Word32 *reference_power_fx, + Word16 *reference_power_q, + Word32 *proto_power_smooth_fx, + Word16 *proto_power_smooth_q, + const Word16 slot_index, + const Word16 num_outputs_diff, + const Word16 num_freq_bands, + const Word32 *mtx_hoa_decoder, + const Word16 nchan_transport, + const Word16 *sba_map_tc_ind, + Word16 q_cldfb +); +#else void protoSignalComputation4( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -473,6 +543,7 @@ void protoSignalComputation4( const int16_t nchan_transport, const int16_t *sba_map_tc_ind ); +#endif void ivas_dirac_dec_compute_diffuse_proto( DIRAC_REND_HANDLE hDirACRend, @@ -503,6 +574,19 @@ void ivas_masa_stereotype_detection( MASA_STEREO_TYPE_DETECT *stereo_type_detect ); +#ifdef IVAS_FLOAT_FIXED +void ivas_lfe_synth_with_cldfb_fx( + MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 RealBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + const Word16 slot_index, + const Word16 subframe_index, + const Word16 nchan_transport, + Word16 q_cldfb +); +#else void ivas_lfe_synth_with_cldfb( MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -513,7 +597,17 @@ void ivas_lfe_synth_with_cldfb( const int16_t subframe_index, const int16_t nchan_transport ); +#endif +#ifdef IVAS_FLOAT_FIXED +void rotateAziEle_DirAC_fx( + Word16 *azi, + Word16 *ele, + const Word16 band1, + const Word16 band2, + const Word32 *p_Rmat_fx +); +#endif void rotateAziEle_DirAC( int16_t *azi, int16_t *ele, @@ -681,6 +775,23 @@ void ivas_dirac_dec_output_synthesis_process_slot( const int16_t dec_param_estim /* i : flag to indicate parameter estimation mode */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( + Word32 RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */ + Word32 ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 nbslots, /* i : number of slots to process */ + const Word32 *onset_filter, + Word32 *diffuseness, + const Word16 hodirac_flag, /* i : flag to indicate HO-DirAC mode */ + const Word16 dec_param_estim, /* i : flag to indicate parameter estimation mode */ + Word16 *q_cy_cross_dir_smooth_prev, + Word16 *q_cy_auto_diff_smooth_prev +); +#endif + void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */ float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */ @@ -1481,12 +1592,12 @@ void ivas_binaural_reverb_processSubframe( #ifdef IVAS_FLOAT_FIXED void ivas_binaural_reverb_processSubframe_fx( REVERB_STRUCT_HANDLE hReverb, /* i/o: binaural reverb handle */ - const int16_t numInChannels, /* i : num inputs to be processed */ - const int16_t numSlots, /* i : number of slots to be processed */ + const Word16 numInChannels, /* i : num inputs to be processed */ + const Word16 numSlots, /* i : number of slots to be processed */ Word32 inReal[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : input CLDFB data real, Comment: This change swaps two first dimensions as first dimension is not constant. */ Word32 inImag[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : input CLDFB data imag */ - Word64 outReal[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : output CLDFB data real */ - Word64 outImag[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX] /* o : output CLDFB data imag */ + Word32 outReal[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : output CLDFB data real */ + Word32 outImag[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX] /* o : output CLDFB data imag */ ); #endif @@ -1720,13 +1831,13 @@ void ivas_reverb_define_window_fft( const int16_t spectrumLength ); #endif -#if 0 +#ifdef IVAS_FLOAT_FIXED Word16 ivas_reverb_calc_color_filters_fx( const Word32 *pTargetL, const Word32 *pTargetR, const Word32 *pWindow, const Word16 fft_size, - const Word32 delay, + const Word16 delay, Word32 **pBeqL, Word32 **pBeqR, Word16 *q_pBeqL, diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index beb5277a3f699ac8dd37e63300830fe5e693cf23..92c7681eb27dca99893a87aff2588aa1ac3c4b84 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -46,6 +46,23 @@ #define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) ) #define float_to_fixQ31( n ) ( round( n * 0x7fffffff ) ) #define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) ) + +static Word16 wrap_rad_fixed( + Word32 angle /* Q13 */ ) +{ + Word32 L_tmp = angle; + /* Wrap azimuth value */ + while(L_tmp > EVS_PI_FX ) + { + L_tmp -= EVS_2PI_FX; + } + while (L_tmp <= -EVS_PI_FX) + { + L_tmp += EVS_2PI_FX; + } + + return extract_l(L_tmp); +} #endif /* The reverberator structure implemented here is described in detail in: @@ -117,12 +134,14 @@ typedef struct ivas_reverb_params_t /* In Matlab: FIR: [L x ] */ float *pFc; /* Center frequencies for FFT filter design */ float *pRt60; /* RT60 values at these frequencies */ + float *pDsr; /* DSR values at these frequencies */ #ifdef IVAS_FLOAT_FIXED Word32 *pFc_fx; /* Center frequencies for FFT filter design */ Word32 *pRt60_fx; /* RT60 values at these frequencies */ - Word16 *pRt60_e; /* exponents of RT60 values at these frequencies */ + Word16 *pRt60_e; /* exponents for RT60 values at these frequencies */ + Word32 *pDsr_fx; /* DSR values at these frequencies */ + Word16 *pDsr_e; /* DSR values at these frequencies */ #endif - float *pDsr; /* DSR values at these frequencies */ float *pHrtf_avg_pwr_response_l; /* The HRTF set's average left ear power response */ float *pHrtf_avg_pwr_response_r; /* The HRTF set's average right ear power response */ float *pHrtf_inter_aural_coherence; /* The HRTF set's inter-aural coherence for diffuse sound */ @@ -130,6 +149,14 @@ typedef struct ivas_reverb_params_t const float *pHrtf_avg_pwr_response_r_const; /* The HRTF set's average right ear power response */ const float *pHrtf_inter_aural_coherence_const; /* The HRTF set's inter-aural coherence for diffuse sound */ +#ifdef IVAS_FLOAT_FIXED + Word32 *pHrtf_avg_pwr_response_l_fx; /* The HRTF set's average left ear power response */ + Word32 *pHrtf_avg_pwr_response_r_fx; /* The HRTF set's average right ear power response */ + Word32 *pHrtf_inter_aural_coherence_fx; /* The HRTF set's inter-aural coherence for diffuse sound */ + const Word32 *pHrtf_avg_pwr_response_l_const_fx; /* The HRTF set's average left ear power response */ + const Word32 *pHrtf_avg_pwr_response_r_const_fx; /* The HRTF set's average right ear power response */ + const Word32 *pHrtf_inter_aural_coherence_const_fx; /* The HRTF set's inter-aural coherence for diffuse sound */ +#endif Word16 do_corr_filter; /* Flag indicating whether correlation filters should be used. */ /* Correlation only supported and needed for binaural playback (i.e. */ /* when nr_outputs != 2 correlation filtering is never supported). */ @@ -263,6 +290,7 @@ static void ivas_binaural_reverb_setPreDelay( * *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void ivas_binaural_reverb_setReverbTimes( REVERB_STRUCT_HANDLE hReverb, /* i/o: binaural reverb handle */ const int32_t output_Fs, /* i : sampling_rate */ @@ -305,17 +333,10 @@ static void ivas_binaural_reverb_setReverbTimes( hReverb->binauralCoherenceCrossmixGains[bin] = -sqrtf( fabsf( tmpVal ) ); } hReverb->binauralCoherenceDirectGains[bin] = sqrtf( 1.0f - fabsf( tmpVal ) ); -#ifdef IVAS_FLOAT_FIXED - hReverb->binauralCoherenceCrossmixGains_fx[bin] = (Word32) float_to_fixQ31( hReverb->binauralCoherenceCrossmixGains[bin] ); - hReverb->binauralCoherenceDirectGains_fx[bin] = (Word32) float_to_fixQ31( hReverb->binauralCoherenceDirectGains[bin] ); -#endif /* Determine attenuation factor that generates the appropriate energy decay according to reverberation time */ attenuationFactorPerSample = powf( 10.0f, -3.0f * ( 1.0f / ( (float) CLDFB_SLOTS_PER_SECOND * revTimes[bin] ) ) ); hReverb->loopAttenuationFactor[bin] = powf( attenuationFactorPerSample, hReverb->loopBufLength[bin] ); -#ifdef IVAS_FLOAT_FIXED - hReverb->loopAttenuationFactor_fx[bin] = (Word32) float_to_fixQ31( hReverb->loopAttenuationFactor[bin] ); -#endif attenuationFactorPerSampleSq = attenuationFactorPerSample * attenuationFactorPerSample; /* Design sparse decorrelation filters. The decorrelation filters, due to random procedures involved, @@ -343,10 +364,7 @@ static void ivas_binaural_reverb_setReverbTimes( /* Set the tapPointer to point to the determined sample at the loop buffer */ hReverb->tapPointersReal[bin][ch][tap] = &( hReverb->loopBufReal[bin][sample] ); hReverb->tapPointersImag[bin][ch][tap] = &( hReverb->loopBufImag[bin][sample] ); -#ifdef IVAS_FLOAT_FIXED - hReverb->tapPointersReal_fx[bin][ch][tap] = &( hReverb->loopBufReal_fx[bin][sample] ); - hReverb->tapPointersImag_fx[bin][ch][tap] = &( hReverb->loopBufImag_fx[bin][sample] ); -#endif + energyBuildup -= 1.0f; /* A tap is added, thus remove its energy from the buildup */ tap++; actualizedEnergy += 1.0f; @@ -360,13 +378,206 @@ static void ivas_binaural_reverb_setReverbTimes( hReverb->reverbEqGains[bin] = sqrtf( revEnes[bin] ); /* Determined reverb spectrum */ hReverb->reverbEqGains[bin] *= sqrtf( intendedEnergy / actualizedEnergy ); /* Correction of random effects at the decorrelator design */ hReverb->reverbEqGains[bin] *= sqrtf( 0.5f * ( 1.0f - attenuationFactorPerSampleSq ) ); /* Correction of IIR decay rate */ -#ifdef IVAS_FLOAT_FIXED - hReverb->reverbEqGains_fx[bin] = (Word32) float_to_fixQ31( hReverb->reverbEqGains[bin] ); -#endif } return; } +#endif + +#ifdef IVAS_FLOAT_FIXED +static void ivas_binaural_reverb_setReverbTimes_fx( + REVERB_STRUCT_HANDLE hReverb, /* i/o: binaural reverb handle */ + const Word32 output_Fs, /* i : sampling_rate */ + const Word32 *revTimes_fx, /* i : reverberation times T60 for each CLDFB bin in seconds */ + const Word32 *revEnes_fx /* i : spectrum for reverberated sound at each CLDFB bin */ +) +{ + int16_t bin, ch, tap, sample; + + Word32 binCenterFreq_fx, diffuseFieldICC_fx, tmpVal_fx, attenuationFactorPerSample_fx, L_tmp; + Word32 intendedEnergy_fx, actualizedEnergy_fx, energyBuildup_fx, currentEnergy_fx, attenuationFactorPerSampleSq_fx; + Word16 tmp, tmp_exp, diffuseFieldICC_exp, scale, tmpVal_exp, attenuationFactorPerSample_exp, attenuationFactorPerSampleSq_exp, energyBuildup_exp, currentEnergy_exp, intendedEnergy_exp, actualizedEnergy_exp; + Word16 sine_inp, norm, sub_res, sub_exp, div_exp1, div1, sine, binCenterFreq_exp; + Word16 reverb_exp = 0; + + hReverb->binRend_RandNext = (UWord16) BIN_REND_RANDOM_SEED; + hReverb->highestBinauralCoherenceBin = 0; + + FOR ( bin = 0; bin < hReverb->numBins; bin++ ) + { + /* Determine the diffuse field binaural coherence */ + Word16 exp; + tmp_exp = BASOP_Util_Add_MantExp(bin, 15, 1, 14, &tmp); + tmp = BASOP_Util_Divide3232_Scale(L_deposit_h(tmp), L_deposit_h(hReverb->numBins), &exp); + exp = exp + ( tmp_exp - 15); + L_tmp = Mpy_32_16_1(output_Fs, tmp); + binCenterFreq_exp = 31 + exp; + binCenterFreq_fx = L_shr(L_tmp, 1); // divide by 2 + IF ( bin == 0 ) + { + diffuseFieldICC_fx = 1073741824; // 2 ^ 30, Q30 + diffuseFieldICC_exp = 1; + } + ELSE IF ( BASOP_Util_Cmp_Mant32Exp(binCenterFreq_fx, binCenterFreq_exp, 2700, 31 ) == -1) + { + tmp = BASOP_Util_Divide3232_Scale(binCenterFreq_fx, 550, &scale); + exp = scale + ( binCenterFreq_exp - 31 ); + tmp = add(mult(EVS_PI_FX, tmp), EPSILLON_FX); // to avoid divide by 0 issue + tmp_exp = exp + 2; + + sine_inp = wrap_rad_fixed(L_shl(tmp, tmp_exp - 2)); + + sine = getSinWord16(sine_inp); // Q15 + div1 = BASOP_Util_Divide1616_Scale(sine, tmp, &scale); + div_exp1 = scale + ( 0 - tmp_exp); + + tmp = BASOP_Util_Divide3232_Scale(binCenterFreq_fx, 2700, &scale); + scale = scale + (binCenterFreq_exp - 31); + + L_tmp = L_sub(L_shl(1, (15 - scale)), tmp); + norm = norm_l(L_tmp); + + L_tmp = L_shl(L_tmp, norm); + sub_res = extract_h(L_tmp); + sub_exp = sub(scale, sub(norm, 16)); + + diffuseFieldICC_fx = L_deposit_h(mult(sub_res, div1)); + diffuseFieldICC_exp = div_exp1 + sub_exp; + + hReverb->highestBinauralCoherenceBin = bin; + } + ELSE + { + + diffuseFieldICC_fx = 0; + diffuseFieldICC_exp = 0; + } + + /* Mixing gains to generate a diffuse-binaural sound based on incoherent sound */ + + L_tmp = Mpy_32_32( diffuseFieldICC_fx, diffuseFieldICC_fx ); // square + L_tmp = BASOP_Util_Add_Mant32Exp(1073741824, 1, L_negate(L_tmp), diffuseFieldICC_exp + diffuseFieldICC_exp, &scale); + L_tmp = Sqrt32(L_tmp, &scale); + tmpVal_fx = L_shr( BASOP_Util_Add_Mant32Exp(1073741824, 1, L_negate(L_tmp), scale, &tmpVal_exp), 1 ); + + IF ( BASOP_Util_Cmp_Mant32Exp(diffuseFieldICC_fx, diffuseFieldICC_exp, 0, 0 ) == 1 ) + { + exp = tmpVal_exp; + L_tmp = Sqrt32( L_abs( tmpVal_fx ), &exp); + hReverb->binauralCoherenceCrossmixGains_fx[bin] = L_shl(L_tmp, exp); // Q31 + } + ELSE + { + exp = tmpVal_exp; + L_tmp = Sqrt32(L_abs(tmpVal_fx), &exp); + hReverb->binauralCoherenceCrossmixGains_fx[bin] = L_negate(L_shl(L_tmp, exp)); // Q31 + } + + exp = tmpVal_exp; + L_tmp = BASOP_Util_Add_Mant32Exp(1073741824, 1, L_negate(L_abs(tmpVal_fx)), tmpVal_exp, &exp); + L_tmp = Sqrt32(L_abs(L_tmp), &exp); + hReverb->binauralCoherenceDirectGains_fx[bin] = L_shl(L_tmp, exp); //making as Q31 + /* Determine attenuation factor that generates the appropriate energy decay according to reverberation time */ + + L_tmp = Mpy_32_32(1677721600, revTimes_fx[bin]); // e10 --> 800 * 2^21, + e0 + tmp = BASOP_Util_Divide3232_Scale(1073741824, L_tmp, &scale); + scale = scale + ( 1 - 10 ); + L_tmp = Mpy_32_16_1(-1610612736, tmp); // * -3 + scale = 2 + scale; + L_tmp = Mpy_32_32(1783446563, L_tmp); // scale + 2 + attenuationFactorPerSample_fx = BASOP_util_Pow2(L_tmp, scale + 2, &attenuationFactorPerSample_exp ); + + Word32 tmp_mul; + scale = norm_l(hReverb->loopBufLength[bin]); + tmp_mul = L_shl(hReverb->loopBufLength[bin], scale); + L_tmp = BASOP_Util_Log2( attenuationFactorPerSample_fx ); + L_tmp = L_add(L_tmp, attenuationFactorPerSample_exp * (1 << 25)); + L_tmp = Mpy_32_32(L_tmp, tmp_mul); + hReverb->loopAttenuationFactor_fx[bin] = BASOP_util_Pow2(L_tmp, 6 + 31 - scale, &exp); + hReverb->loopAttenuationFactor_fx[bin] = L_shl(hReverb->loopAttenuationFactor_fx[bin], exp); // making as Q31 + + attenuationFactorPerSampleSq_fx = Mpy_32_32( attenuationFactorPerSample_fx, attenuationFactorPerSample_fx ); + attenuationFactorPerSampleSq_exp = attenuationFactorPerSample_exp + attenuationFactorPerSample_exp; + + /* Design sparse decorrelation filters. The decorrelation filters, due to random procedures involved, + * may affect the spectrum of the output. The spectral effect is therefore monitored and compensated for. */ + + intendedEnergy_fx = 0; + intendedEnergy_exp = 0; + actualizedEnergy_fx = 0; + actualizedEnergy_exp = 0; + + FOR ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + + energyBuildup_fx = 0; + energyBuildup_exp = 0; + currentEnergy_fx = 1073741824; + currentEnergy_exp = 1; + + tap = 0; + + FOR ( sample = 0; sample < hReverb->loopBufLength[bin]; sample++ ) + { + intendedEnergy_fx = BASOP_Util_Add_Mant32Exp( intendedEnergy_fx, intendedEnergy_exp, currentEnergy_fx, currentEnergy_exp, &intendedEnergy_exp ); + /* The randomization at the energy build up affects where the sparse taps are located */ + + UWord16 ret_binRend = binRend_rand(hReverb); + + tmp = BASOP_Util_Divide3232_Scale(ret_binRend, PCM16_TO_FLT_FAC_FX, &tmp_exp); + L_tmp = BASOP_Util_Add_Mant32Exp(L_deposit_h(tmp), tmp_exp, L_negate(1073741824), 0, &exp); + L_tmp = Mpy_32_32(L_tmp, 214748364); // exp + 0 + L_tmp = BASOP_Util_Add_Mant32Exp(L_tmp, exp, currentEnergy_fx, currentEnergy_exp, &exp); + energyBuildup_fx = BASOP_Util_Add_Mant32Exp(energyBuildup_fx, energyBuildup_exp, L_tmp, exp, &energyBuildup_exp); + IF(BASOP_Util_Cmp_Mant32Exp(energyBuildup_fx, energyBuildup_exp, 0, 0) >= 0) /* A new filter tap is added at this condition */ + { + IF(BASOP_Util_Cmp_Mant32Exp(energyBuildup_fx, energyBuildup_exp, 1, 31) >= 0) { + /* Four efficient phase operations: n*pi/2, n=0,1,2,3 */ + hReverb->tapPhaseShiftType[bin][ch][tap] = (int16_t)(binRend_rand(hReverb) % 4); + /* Set the tapPointer to point to the determined sample at the loop buffer */ + + hReverb->tapPointersReal_fx[bin][ch][tap] = &(hReverb->loopBufReal_fx[bin][sample]); + hReverb->tapPointersImag_fx[bin][ch][tap] = &(hReverb->loopBufImag_fx[bin][sample]); + + energyBuildup_fx = BASOP_Util_Add_Mant32Exp(energyBuildup_fx, energyBuildup_exp, L_negate(1073741824), 1, &energyBuildup_exp); /* A tap is added, thus remove its energy from the buildup */ + + tap++; + + actualizedEnergy_fx = BASOP_Util_Add_Mant32Exp(actualizedEnergy_fx, actualizedEnergy_exp, 1073741824, 1, &actualizedEnergy_exp); + } + } + + currentEnergy_fx = BASOP_Util_Add_Mant32Exp(currentEnergy_fx, currentEnergy_exp, 0, 0, ¤tEnergy_exp); + currentEnergy_fx = Mpy_32_32(currentEnergy_fx, attenuationFactorPerSampleSq_fx ); + currentEnergy_exp = currentEnergy_exp + attenuationFactorPerSampleSq_exp; + + } + hReverb->taps[bin][ch] = tap; /* Number of taps determined at the above random procedure */ + } + + /* The decorrelator design and IIR attenuation rate affects the energy of reverb, which is compensated here */ + reverb_exp = 0; + hReverb->reverbEqGains_fx[bin] = Sqrt32(revEnes_fx[bin], &reverb_exp); /* Determined reverb spectrum */ + hReverb->reverbEqGains_fx[bin] = BASOP_Util_Add_Mant32Exp(hReverb->reverbEqGains_fx[bin], reverb_exp, 0, 0, &reverb_exp); + + tmp = BASOP_Util_Divide3232_Scale(intendedEnergy_fx, actualizedEnergy_fx, &tmp_exp); + tmp_exp = tmp_exp + (intendedEnergy_exp - actualizedEnergy_exp); + hReverb->reverbEqGains_fx[bin] = BASOP_Util_Add_Mant32Exp(hReverb->reverbEqGains_fx[bin], reverb_exp, 0, 0, &reverb_exp); + L_tmp = Sqrt32(L_deposit_h(tmp), &tmp_exp); + hReverb->reverbEqGains_fx[bin] = Mpy_32_32(hReverb->reverbEqGains_fx[bin], L_tmp); + reverb_exp = reverb_exp + tmp_exp; + + L_tmp = BASOP_Util_Add_Mant32Exp(1073741824, 1, L_negate(attenuationFactorPerSampleSq_fx), attenuationFactorPerSampleSq_exp, &tmp_exp); + L_tmp = Mpy_32_32(L_tmp, 1073741824); // tmp_exp + 1 + tmp_exp = tmp_exp + 0; + L_tmp = Sqrt32(L_tmp, &tmp_exp); + hReverb->reverbEqGains_fx[bin] = Mpy_32_32(L_tmp, hReverb->reverbEqGains_fx[bin]); + reverb_exp = reverb_exp + tmp_exp; + hReverb->reverbEqGains_fx[bin] = L_shl(hReverb->reverbEqGains_fx[bin], reverb_exp); // making as Q31 + } + return; +} +#endif #ifdef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* @@ -780,7 +991,6 @@ static ivas_error compute_t60_coeffs_fx( pFc_fx = pParams->pFc_fx; targetT60_fx = pParams->pRt60_fx; targetT60_e = pParams->pRt60_e; - Word16 pRt60_e; FOR (bin_idx = 0; bin_idx < tf_T60_len; bin_idx++) { @@ -804,7 +1014,7 @@ static ivas_error compute_t60_coeffs_fx( tmp = BASOP_Util_Cmp_Mant32Exp( L_deposit_h(target_gains_db_fx[bin_idx]), target_gains_db_exp[bin_idx], -2013265920, 7); IF (tmp < 0) { - target_gains_db_fx[bin_idx] = -2013265920; + target_gains_db_fx[bin_idx] = -30720; target_gains_db_exp[bin_idx] = 7; } } @@ -946,7 +1156,7 @@ static void calc_low_shelf_first_order_filter_fx( const Word16 lin_gain_hf ) { Word16 sine_val, shift; - Word16 cos_val, tmp, tan_val, tan_exp, gain_exp, exp, norm_num0, norm_num1, norm_den0, norm_den1, num0, num1, den0, den1; + Word16 cos_val, tmp, tan_val, tan_exp, gain_exp, exp, norm_num0, norm_num1, norm_den0, norm_den1; Word32 L_tmp; tmp = mult( EVS_PI_BY_2_FX, f0 ); @@ -1149,7 +1359,7 @@ static ivas_error calc_jot_t60_coeffs_fx( Word32 L_tmp; Word16 f0_fx, tmp_fx, lf_target_gain_dB_fx, hf_target_gain_dB_fx, mid_crossing_gain_dB_fx; - Word16 lin_gain_lf_fx, lin_gain_hf_fx, shift, expl, exph, addl; + Word16 lin_gain_lf_fx, lin_gain_hf_fx, shift, expl, exph; int16_t f_idx, minidx, e = pH_dB_exp; uint16_t n_points_lf, n_points_hf; @@ -1699,6 +1909,131 @@ static void set_fft_and_datablock_sizes( * Sets reverb acoustic data (room acoustics and HRTF), interpolating it to the filter grid *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void set_reverb_acoustic_data_fx( + ivas_reverb_params_t *pParams, + const AUDIO_CONFIG input_audio_config, + const HRTFS_HANDLE hHrtf, + IVAS_ROOM_ACOUSTICS_CONFIG_DATA *pRoomAcoustics, + const Word16 subframe_len, + const Word16 nr_fc_input, + const Word16 nr_fc_fft_filter ) +{ + Word16 nr_out_ch, hrtf_idx, offset, iter_idx, bin_idx; + Word32 *pHrtf_set_l_re_fx[MAX_INTERN_CHANNELS]; + Word32 *pHrtf_set_l_im_fx[MAX_INTERN_CHANNELS]; + Word32 *pHrtf_set_r_re_fx[MAX_INTERN_CHANNELS]; + Word32 *pHrtf_set_r_im_fx[MAX_INTERN_CHANNELS]; + Word32 ln_1e6_inverted_fx, delay_diff_fx, L_tmp; + Word16 exp_argument_fx, tmp, tmp_flag, exp_argument_e; + Word16 pow_exp; + + Word32* pFc_input_fx = pRoomAcoustics->pFc_input_fx; + Word32* pAcoustic_rt60_fx = pRoomAcoustics->pAcoustic_rt60_fx; + Word32* pAcoustic_dsr_fx = pRoomAcoustics->pAcoustic_dsr_fx; + + Word32* pFc_fx = pParams->pFc_fx; + Word32* pRt60_fx = pParams->pRt60_fx; + Word16* pRt60_e = pParams->pRt60_e; + Word32* pDsr_fx = pParams->pDsr_fx; + Word16* pDsr_e = pParams->pDsr_e; + + /* use crend hrtf filters */ + IF ( hHrtf != NULL ) + { + /* Compute HRTF set properties: average left/right energies, IA coherence */ + /* First, find the offset of the frequency-domain data for the 1st frame and assign HRTF pointers */ + FOR ( nr_out_ch = 0; nr_out_ch < BINAURAL_CHANNELS; nr_out_ch++ ) + { + FOR ( hrtf_idx = 0; hrtf_idx < hHrtf->max_num_ir; hrtf_idx++ ) + { + offset = 0; + move16(); + FOR ( iter_idx = 0; iter_idx < hHrtf->num_iterations[hrtf_idx][nr_out_ch] - 1; iter_idx++ ) + { + offset += hHrtf->pIndex_frequency_max[hrtf_idx][nr_out_ch][iter_idx]; + } + + IF ( EQ_16( nr_out_ch, 0 ) ) + { + pHrtf_set_l_re_fx[hrtf_idx] = &hHrtf->pOut_to_bin_re_fx[hrtf_idx][0][offset]; + pHrtf_set_l_im_fx[hrtf_idx] = &hHrtf->pOut_to_bin_im_fx[hrtf_idx][0][offset]; + } + ELSE + { + pHrtf_set_r_re_fx[hrtf_idx] = &hHrtf->pOut_to_bin_re_fx[hrtf_idx][1][offset]; + pHrtf_set_r_im_fx[hrtf_idx] = &hHrtf->pOut_to_bin_im_fx[hrtf_idx][1][offset]; + } + } + } + + /* Compute HRTF set properties using frequency-domain HRTF data */ + Word32 *pHrtf_avg_pwr_response_l_fx = pParams->pHrtf_avg_pwr_response_l_fx; + Word32 *pHrtf_avg_pwr_response_r_fx = pParams->pHrtf_avg_pwr_response_r_fx; + Word32 *pHrtf_inter_aural_coherence_fx = pParams->pHrtf_inter_aural_coherence_fx; + ivas_reverb_get_hrtf_set_properties_fx(pHrtf_set_l_re_fx, pHrtf_set_l_im_fx, pHrtf_set_r_re_fx, pHrtf_set_r_im_fx, input_audio_config, hHrtf->max_num_ir, subframe_len, + nr_fc_fft_filter, pHrtf_avg_pwr_response_l_fx, pHrtf_avg_pwr_response_r_fx, pHrtf_inter_aural_coherence_fx); + + pParams->pHrtf_avg_pwr_response_l_const_fx = (const Word32 *) pParams->pHrtf_avg_pwr_response_l_fx; + pParams->pHrtf_avg_pwr_response_r_const_fx = (const Word32 *) pParams->pHrtf_avg_pwr_response_r_fx; + pParams->pHrtf_inter_aural_coherence_const_fx = (const Word32 *) pParams->pHrtf_inter_aural_coherence_fx; + } + + /* interpolate input table data for T60 and DSR to the FFT filter grid */ + ivas_reverb_interpolate_acoustic_data_fx(nr_fc_input, pFc_input_fx, pAcoustic_rt60_fx, pAcoustic_dsr_fx, + nr_fc_fft_filter, pFc_fx, pRt60_fx, pDsr_fx, pRt60_e, pDsr_e); + + /* adjust DSR for the delay difference */ + + delay_diff_fx = L_sub(pRoomAcoustics->inputPreDelay_fx, pRoomAcoustics->acousticPreDelay_fx); + + ln_1e6_inverted_fx = 155440049; // Q31 /* 1.0f / logf( 1e06f ) */ + move32(); + + FOR ( bin_idx = 0; bin_idx < nr_fc_fft_filter; bin_idx++ ) + { + L_tmp = Mpy_32_32(pRt60_fx[bin_idx], ln_1e6_inverted_fx ); // exp = pRt60_e[bin_idx] + 0 + exp_argument_fx = BASOP_Util_Divide3232_Scale(delay_diff_fx, L_tmp, &exp_argument_e); + exp_argument_e = exp_argument_e + (4 - pRt60_e[bin_idx]); // Q27 -> e4 + /* Limit exponent to approx +/-100 dB in case of incoherent value of delay_diff, to prevent overflow */ + + // 23 in Q26 + tmp_flag = BASOP_Util_Cmp_Mant32Exp(L_deposit_h(exp_argument_fx), exp_argument_e, 1543503872, 5 ); + IF(tmp_flag > 0) { + exp_argument_fx = 23552; + move16(); + exp_argument_e = 5; + move16(); + } + + tmp_flag = BASOP_Util_Cmp_Mant32Exp(L_deposit_h(exp_argument_fx), exp_argument_e, 0, 31); + IF(tmp_flag < 0) { + tmp_flag = BASOP_Util_Cmp_Mant32Exp(L_deposit_h(negate( exp_argument_fx) ), exp_argument_e, 1543503872, 5); + IF (tmp_flag < 0) { + exp_argument_fx = -23552; + move16(); + exp_argument_e = 5; + move16(); + } + } + + Word16 tmp_exp; + /* expf(exp_argument) -> pow(2, log2(e) * exp_argument) */ + tmp = mult(23637, exp_argument_fx); // exp_argument_e + 1 + tmp_exp = exp_argument_e + 1; + L_tmp = BASOP_util_Pow2(L_deposit_h(tmp), tmp_exp, &pow_exp); + L_tmp = Mpy_32_32( L_tmp, pDsr_fx[bin_idx] ); + tmp_exp = tmp_exp + pDsr_e[bin_idx]; + + pDsr_fx[bin_idx] = L_tmp; + pDsr_e[bin_idx] = tmp_exp; + + } + return; +} +#endif + +#ifndef IVAS_FLOAT_FIXED static void set_reverb_acoustic_data( ivas_reverb_params_t *pParams, const AUDIO_CONFIG input_audio_config, @@ -1710,17 +2045,11 @@ static void set_reverb_acoustic_data( { int16_t nr_out_ch, hrtf_idx, offset, iter_idx, bin_idx; float ln_1e6_inverted, delay_diff, exp_argument; -#ifdef IVAS_FLOAT_FIXED - Word32 *pHrtf_set_l_re_fx[MAX_INTERN_CHANNELS]; - Word32 *pHrtf_set_l_im_fx[MAX_INTERN_CHANNELS]; - Word32 *pHrtf_set_r_re_fx[MAX_INTERN_CHANNELS]; - Word32 *pHrtf_set_r_im_fx[MAX_INTERN_CHANNELS]; -#else + float *pHrtf_set_l_re[MAX_INTERN_CHANNELS]; float *pHrtf_set_l_im[MAX_INTERN_CHANNELS]; float *pHrtf_set_r_re[MAX_INTERN_CHANNELS]; float *pHrtf_set_r_im[MAX_INTERN_CHANNELS]; -#endif /* use crend hrtf filters */ if ( hHrtf != NULL ) @@ -1739,110 +2068,47 @@ static void set_reverb_acoustic_data( if ( nr_out_ch == 0 ) { -#ifdef IVAS_FLOAT_FIXED - pHrtf_set_l_re_fx[hrtf_idx] = &hHrtf->pOut_to_bin_re_fx[hrtf_idx][0][offset]; - pHrtf_set_l_im_fx[hrtf_idx] = &hHrtf->pOut_to_bin_im_fx[hrtf_idx][0][offset]; -#else pHrtf_set_l_re[hrtf_idx] = &hHrtf->pOut_to_bin_re[hrtf_idx][0][offset]; pHrtf_set_l_im[hrtf_idx] = &hHrtf->pOut_to_bin_im[hrtf_idx][0][offset]; -#endif } else { -#ifdef IVAS_FLOAT_FIXED - pHrtf_set_r_re_fx[hrtf_idx] = &hHrtf->pOut_to_bin_re_fx[hrtf_idx][1][offset]; - pHrtf_set_r_im_fx[hrtf_idx] = &hHrtf->pOut_to_bin_im_fx[hrtf_idx][1][offset]; -#else pHrtf_set_r_re[hrtf_idx] = &hHrtf->pOut_to_bin_re[hrtf_idx][1][offset]; pHrtf_set_r_im[hrtf_idx] = &hHrtf->pOut_to_bin_im[hrtf_idx][1][offset]; -#endif } } } /* Compute HRTF set properties using frequency-domain HRTF data */ -#ifdef IVAS_FLOAT_FIXED - Word32 *pHrtf_avg_pwr_response_l_fx = (Word32*)malloc(nr_fc_fft_filter * sizeof(Word32*)); - Word32 *pHrtf_avg_pwr_response_r_fx = (Word32*)malloc(nr_fc_fft_filter * sizeof(Word32*)); - Word32 *pHrtf_inter_aural_coherence_fx = (Word32*)malloc(nr_fc_fft_filter * sizeof(Word32*)); - ivas_reverb_get_hrtf_set_properties_fx(pHrtf_set_l_re_fx, pHrtf_set_l_im_fx, pHrtf_set_r_re_fx, pHrtf_set_r_im_fx, input_audio_config, hHrtf->max_num_ir, subframe_len, - nr_fc_fft_filter, pHrtf_avg_pwr_response_l_fx, pHrtf_avg_pwr_response_r_fx, pHrtf_inter_aural_coherence_fx); - - for (int i = 0; i < nr_fc_fft_filter; i++) - { - pParams->pHrtf_avg_pwr_response_l[i] = (float)pHrtf_avg_pwr_response_l_fx[i] / (ONE_IN_Q23); - pParams->pHrtf_avg_pwr_response_r[i] = (float)pHrtf_avg_pwr_response_r_fx[i] / (ONE_IN_Q23); - pParams->pHrtf_inter_aural_coherence[i] = (float)pHrtf_inter_aural_coherence_fx[i] / (ONE_IN_Q27); - } - - free(pHrtf_avg_pwr_response_l_fx); - free(pHrtf_avg_pwr_response_r_fx); - free(pHrtf_inter_aural_coherence_fx); -#else ivas_reverb_get_hrtf_set_properties( pHrtf_set_l_re, pHrtf_set_l_im, pHrtf_set_r_re, pHrtf_set_r_im, input_audio_config, hHrtf->max_num_ir, subframe_len, nr_fc_fft_filter, pParams->pHrtf_avg_pwr_response_l, pParams->pHrtf_avg_pwr_response_r, pParams->pHrtf_inter_aural_coherence ); -#endif + pParams->pHrtf_avg_pwr_response_l_const = (const float *) pParams->pHrtf_avg_pwr_response_l; pParams->pHrtf_avg_pwr_response_r_const = (const float *) pParams->pHrtf_avg_pwr_response_r; pParams->pHrtf_inter_aural_coherence_const = (const float *) pParams->pHrtf_inter_aural_coherence; } /* interpolate input table data for T60 and DSR to the FFT filter grid */ -#ifdef IVAS_FLOAT_FIXED - Word32* pFc_input_fx = (Word32*)malloc(60 * sizeof(Word32*)); - Word32* pAcoustic_rt60_fx = (Word32*)malloc(60 * sizeof(Word32*)); - Word32* pAcoustic_dsr_fx = (Word32*)malloc(60 * sizeof(Word32*)); - - Word32* pFc_fx = (Word32*)malloc(nr_fc_fft_filter * sizeof(Word32*)); - Word32* pRt60_fx = (Word32*)malloc(nr_fc_fft_filter * sizeof(Word32*)); - Word16* pRt60_e = (Word16*)malloc(nr_fc_fft_filter * sizeof(Word16*)); - Word32* pDsr_fx = (Word32*)malloc(nr_fc_fft_filter * sizeof(Word32*)); - Word16* pDsr_e = (Word16*)malloc(nr_fc_fft_filter * sizeof(Word16*)); - - for (int i = 0; i < 60; i++) - { - pFc_input_fx[i] = (Word32)(pRoomAcoustics->pFc_input[i] * ONE_IN_Q16); - pAcoustic_rt60_fx[i] = (Word32)((pRoomAcoustics->pAcoustic_rt60[i]) * ONE_IN_Q26); - pAcoustic_dsr_fx[i] = (Word32)(pRoomAcoustics->pAcoustic_dsr[i] * ONE_IN_Q30); - } - - for (int i = 0; i < nr_fc_fft_filter; i++) - { - pFc_fx[i] = (Word32)(pParams->pFc[i] * ONE_IN_Q16); - } - - ivas_reverb_interpolate_acoustic_data_fx(nr_fc_input, pFc_input_fx, pAcoustic_rt60_fx, pAcoustic_dsr_fx, - nr_fc_fft_filter, pFc_fx, pRt60_fx, pDsr_fx, pRt60_e, pDsr_e); - for (int i = 0; i < nr_fc_fft_filter; i++) { - pParams->pRt60[i] = fabsf(me2f(pRt60_fx[i], pRt60_e[i])); - pParams->pDsr[i] = fabsf(me2f(pDsr_fx[i], pDsr_e[i])); - } - free(pFc_input_fx); - free(pAcoustic_rt60_fx); - free(pAcoustic_dsr_fx); - free(pFc_fx); - free(pRt60_fx); - free(pRt60_e); - free(pDsr_fx); - free(pDsr_e); -#else ivas_reverb_interpolate_acoustic_data( nr_fc_input, pRoomAcoustics->pFc_input, pRoomAcoustics->pAcoustic_rt60, pRoomAcoustics->pAcoustic_dsr, nr_fc_fft_filter, pParams->pFc, pParams->pRt60, pParams->pDsr ); -#endif /* adjust DSR for the delay difference */ + delay_diff = pRoomAcoustics->inputPreDelay - pRoomAcoustics->acousticPreDelay; - ln_1e6_inverted = 1.0f / logf( 1e06f ); + + ln_1e6_inverted = 1.0f / logf( 1e06f ); + for ( bin_idx = 0; bin_idx < nr_fc_fft_filter; bin_idx++ ) { exp_argument = delay_diff / ( pParams->pRt60[bin_idx] * ln_1e6_inverted ); /* Limit exponent to approx +/-100 dB in case of incoherent value of delay_diff, to prevent overflow */ + exp_argument = min( exp_argument, 23.0f ); - exp_argument = max( exp_argument, -23.0f ); + exp_argument = max(exp_argument, -23.0f); pParams->pDsr[bin_idx] *= expf( exp_argument ); } - return; } +#endif #ifdef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* @@ -2065,7 +2331,72 @@ ivas_error ivas_reverb_open( params.pHrtf_inter_aural_coherence_const = lr_energy_and_iac[2]; } /* set up reverb acoustic data on the basis of HRTF data and renderer config */ + +#ifdef IVAS_FLOAT_FIXED + Word32 *pRt60_fx = (Word32 *)malloc(sizeof(Word32) * nr_fc_fft_filter); + Word32 *pFc_fx = (Word32 *)malloc(sizeof(Word32) * nr_fc_fft_filter); + Word16 *pRt60_e = (Word16 *)malloc(sizeof(Word16) * nr_fc_fft_filter); + Word32 *pDsr_fx = (Word32 *)malloc(sizeof(Word32) * nr_fc_fft_filter); + Word16 *pDsr_e = (Word16 *)malloc(sizeof(Word16) * nr_fc_fft_filter); + Word32 *pHrtf_avg_pwr_response_l_fx = (Word32*)malloc(nr_fc_fft_filter * sizeof(Word32)); + Word32 *pHrtf_avg_pwr_response_r_fx = (Word32*)malloc(nr_fc_fft_filter * sizeof(Word32)); + Word32 *pHrtf_inter_aural_coherence_fx = (Word32*)malloc(nr_fc_fft_filter * sizeof(Word32)); + + params.pRt60_fx = pRt60_fx; + params.pFc_fx = pFc_fx; + params.pRt60_e = pRt60_e; + params.pDsr_fx = pDsr_fx; + params.pDsr_e = pDsr_e; + params.pHrtf_avg_pwr_response_l_fx = pHrtf_avg_pwr_response_l_fx; + params.pHrtf_avg_pwr_response_r_fx = pHrtf_avg_pwr_response_r_fx; + params.pHrtf_inter_aural_coherence_fx = pHrtf_inter_aural_coherence_fx; + + for (int i = 0; i < nr_fc_fft_filter; i++) + { + params.pFc_fx[i] = (Word32)(params.pFc[i] * ONE_IN_Q16); + } + + for (int i = 0; i < 60; i++) + { + hRenderConfig->roomAcoustics.pFc_input_fx[i] = (Word32)(hRenderConfig->roomAcoustics.pFc_input[i] * ONE_IN_Q16); + hRenderConfig->roomAcoustics.pAcoustic_rt60_fx[i] = (Word32)((hRenderConfig->roomAcoustics.pAcoustic_rt60[i]) * ONE_IN_Q26); + hRenderConfig->roomAcoustics.pAcoustic_dsr_fx[i] = (Word32)(hRenderConfig->roomAcoustics.pAcoustic_dsr[i] * ONE_IN_Q30); + } + + hRenderConfig->roomAcoustics.inputPreDelay_fx = (Word32) (hRenderConfig->roomAcoustics.inputPreDelay * ONE_IN_Q27 ); + hRenderConfig->roomAcoustics.acousticPreDelay_fx = (Word32) (hRenderConfig->roomAcoustics.acousticPreDelay * ONE_IN_Q27); + + set_reverb_acoustic_data_fx( ¶ms, input_audio_config, hHrtf, &hRenderConfig->roomAcoustics, subframe_len, nr_fc_input, nr_fc_fft_filter ); + + for (int i = 0; i < nr_fc_fft_filter; i++) { + params.pRt60[i] = fabsf(me2f(pRt60_fx[i], pRt60_e[i])); + params.pDsr[i] = fabsf(me2f(pDsr_fx[i], pDsr_e[i])); + } + + if (hHrtf != NULL) { + for (int i = 0; i < nr_fc_fft_filter; i++) + { + params.pHrtf_avg_pwr_response_l[i] = (float)params.pHrtf_avg_pwr_response_l_fx[i] / (ONE_IN_Q23); + params.pHrtf_avg_pwr_response_r[i] = (float)params.pHrtf_avg_pwr_response_r_fx[i] / (ONE_IN_Q23); + params.pHrtf_inter_aural_coherence[i] = (float)params.pHrtf_inter_aural_coherence_fx[i] / (ONE_IN_Q27); + } + + params.pHrtf_avg_pwr_response_l_const = (const float *)params.pHrtf_avg_pwr_response_l; + params.pHrtf_avg_pwr_response_r_const = (const float *)params.pHrtf_avg_pwr_response_r; + params.pHrtf_inter_aural_coherence_const = (const float *)params.pHrtf_inter_aural_coherence; + } + + free(pRt60_fx); + free(pFc_fx); + free(pRt60_e); + free(pDsr_fx); + free(pDsr_e); + free(pHrtf_avg_pwr_response_l_fx); + free(pHrtf_avg_pwr_response_r_fx); + free(pHrtf_inter_aural_coherence_fx); +#else set_reverb_acoustic_data( ¶ms, input_audio_config, hHrtf, &hRenderConfig->roomAcoustics, subframe_len, nr_fc_input, nr_fc_fft_filter ); +#endif /* set reverb acoustic configuration based on renderer config */ pState->pConfig.roomAcoustics.override = hRenderConfig->roomAcoustics.override; @@ -2157,8 +2488,6 @@ ivas_error ivas_reverb_open( free(pHrtf_avg_pwr_response_l_const); free(pHrtf_avg_pwr_response_r_const); free(pT60_filter_coeff); - free(pColor_target_l_fx); - free(pColor_target_r_fx); #else ivas_reverb_calc_color_levels( output_Fs, nr_fc_fft_filter, params.nr_loops, params.pFc, params.pDsr, params.pHrtf_avg_pwr_response_l_const, params.pHrtf_avg_pwr_response_r_const, params.pLoop_delays, params.pT60_filter_coeff, pColor_target_l, pColor_target_r ); @@ -2191,24 +2520,24 @@ ivas_error ivas_reverb_open( { return error; } +#ifdef IVAS_FLOAT_FIXED + Word32** pFft_wf_filter_ch0_fx = (Word32**)malloc(nr_fc_fft_filter * sizeof(Word32*)); + for (int i = 0; i < nr_fc_fft_filter; i++) { + pFft_wf_filter_ch0_fx[i] = (Word32*)malloc(2 * sizeof(Word32)); + } + + Word32** pFft_wf_filter_ch1_fx = (Word32**)malloc(nr_fc_fft_filter * sizeof(Word32*)); + + for (int i = 0; i < nr_fc_fft_filter; i++) { + pFft_wf_filter_ch1_fx[i] = (Word32*)malloc(2 * sizeof(Word32)); + } + Word32* pWindow_fx = (Word32*)malloc(512 * sizeof(Word32)); +#endif if ( pState->do_corr_filter ) { /* Computing correlation filters on the basis of target IA coherence */ #ifdef IVAS_FLOAT_FIXED - Word32** pFft_wf_filter_ch0_fx = (Word32**)malloc(nr_fc_fft_filter * sizeof(Word32*)); - - for (int i = 0; i < nr_fc_fft_filter; i++) { - pFft_wf_filter_ch0_fx[i] = (Word32*)malloc(2 * sizeof(Word32)); - } - - Word32** pFft_wf_filter_ch1_fx = (Word32**)malloc(nr_fc_fft_filter * sizeof(Word32*)); - - for (int i = 0; i < nr_fc_fft_filter; i++) { - pFft_wf_filter_ch1_fx[i] = (Word32*)malloc(2 * sizeof(Word32)); - } - Word32* pWindow_fx = (Word32*)malloc(512 * sizeof(Word32)); - Word16 q_pFft_wf_filter_ch0_fx, q_pFft_wf_filter_ch1_fx; for (int i = 0; i < nr_fc_fft_filter; i++) { @@ -2239,14 +2568,8 @@ ivas_error ivas_reverb_open( pFft_wf_filter_ch1[i][1] = (float)pFft_wf_filter_ch1_fx[i][1] / (1u << q_pFft_wf_filter_ch1_fx); } - for (int i = 0; i < nr_fc_fft_filter; i++) { - free(pFft_wf_filter_ch1_fx[i]); - free(pFft_wf_filter_ch0_fx[i]); - } - free(pFft_wf_filter_ch1_fx); - free(pFft_wf_filter_ch0_fx); - free(pWindow_fx); free(pHrtf_inter_aural_coherence_const); + #else ivas_reverb_calc_correl_filters( params.pHrtf_inter_aural_coherence_const, pTime_window, pState->fft_size, 0.0f, pFft_wf_filter_ch0, pFft_wf_filter_ch1 ); #endif @@ -2263,27 +2586,14 @@ ivas_error ivas_reverb_open( } /* Computing coloration filters on the basis of target responses */ -#if 0 - Word32** pFft_wf_filter_ch0_fx = (Word32**)malloc(257 * sizeof(Word32*)); - - for (int i = 0; i < 257; i++) { - pFft_wf_filter_ch0_fx[i] = (Word32*)malloc(2 * sizeof(Word32)); - } - - Word32** pFft_wf_filter_ch1_fx = (Word32**)malloc(257 * sizeof(Word32*)); - - for (int i = 0; i < 257; i++) { - pFft_wf_filter_ch1_fx[i] = (Word32*)malloc(2 * sizeof(Word32)); - } - Word32* pWindow_fx = (Word32*)malloc(RV_FILTER_MAX_FFT_SIZE * sizeof(Word32)); - +#if 1 Word16 q_pFft_wf_filter_ch0_fx, q_pFft_wf_filter_ch1_fx; - for (int i = 0; i < 257; i++) { + for (int i = 0; i < nr_fc_fft_filter; i++) { pFft_wf_filter_ch0_fx[i][0] = pFft_wf_filter_ch0[i][0] * 2147483648; pFft_wf_filter_ch0_fx[i][1] = pFft_wf_filter_ch0[i][1] * 2147483648; } - for (int i = 0; i < 257; i++) { + for (int i = 0; i < nr_fc_fft_filter; i++) { pFft_wf_filter_ch1_fx[i][0] = pFft_wf_filter_ch1_fx[i][0] * 2147483648; pFft_wf_filter_ch1_fx[i][1] = pFft_wf_filter_ch1_fx[i][1] * 2147483648; } @@ -2291,25 +2601,23 @@ ivas_error ivas_reverb_open( pWindow_fx[i] = pTime_window[i] * (1 << 30); } - Word32* pColor_target_l_fx = (Word32*)malloc(pState->fft_size * sizeof(Word32)); - Word32* pColor_target_r_fx = (Word32*)malloc(pState->fft_size * sizeof(Word32)); - for (int i = 0; i < RV_FILTER_MAX_FFT_SIZE; i++) { + for (int i = 0; i < nr_fc_fft_filter; i++) { pColor_target_l_fx[i] = pColor_target_l[i] * ONE_IN_Q30; pColor_target_r_fx[i] = pColor_target_r[i] * ONE_IN_Q30; } ivas_reverb_calc_color_filters_fx(pColor_target_l_fx, pColor_target_r_fx, pWindow_fx, pState->fft_size, 0, pFft_wf_filter_ch0_fx, pFft_wf_filter_ch1_fx, &q_pFft_wf_filter_ch0_fx, &q_pFft_wf_filter_ch1_fx); - for (int i = 0; i < 257; i++) { + for (int i = 0; i < nr_fc_fft_filter; i++) { pFft_wf_filter_ch0[i][0] = (float)pFft_wf_filter_ch0_fx[i][0] / (1u << q_pFft_wf_filter_ch0_fx); pFft_wf_filter_ch0[i][1] = (float)pFft_wf_filter_ch0_fx[i][1] / (1u << q_pFft_wf_filter_ch0_fx); } - for (int i = 0; i < 257; i++) { + for (int i = 0; i < nr_fc_fft_filter; i++) { pFft_wf_filter_ch1[i][0] = (float)pFft_wf_filter_ch1_fx[i][0] / (1u << q_pFft_wf_filter_ch1_fx); pFft_wf_filter_ch1[i][1] = (float)pFft_wf_filter_ch1_fx[i][1] / (1u << q_pFft_wf_filter_ch1_fx); } - for (int i = 0; i < 257; i++) { + for (int i = 0; i < nr_fc_fft_filter; i++) { free(pFft_wf_filter_ch1_fx[i]); free(pFft_wf_filter_ch0_fx[i]); } @@ -3236,6 +3544,7 @@ ivas_error ivas_reverb_process( * Compute the reverberation - room effect *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_binaural_reverb_processSubframe( REVERB_STRUCT_HANDLE hReverb, /* i/o: binaural reverb handle */ const int16_t numInChannels, /* i : num inputs to be processed */ @@ -3263,11 +3572,16 @@ void ivas_binaural_reverb_processSubframe( /* Add the data from the end of the loop to the beginning, with an attenuation factor * according to RT60. This procedure generates an IIR decaying response. The response * is decorrelated later on. */ + + //loopAttenuationFactor ->Q31 + v_multc( hReverb->loopBufReal[bin] + hReverb->loopBufLength[bin], hReverb->loopAttenuationFactor[bin], hReverb->loopBufReal[bin], numSlots ); v_multc( hReverb->loopBufImag[bin] + hReverb->loopBufLength[bin], hReverb->loopAttenuationFactor[bin], hReverb->loopBufImag[bin], numSlots ); } /* 2) Apply the determined pre-delay to the input audio, and add the delayed audio to the loop. */ + //hReverb->reverbEqGains[bin]; ->Q31// + idx = hReverb->preDelayBufferIndex; for ( sample = 0; sample < numSlots; sample++ ) { @@ -3389,6 +3703,7 @@ void ivas_binaural_reverb_processSubframe( pop_wmops(); return; } +#endif #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- @@ -3399,12 +3714,12 @@ void ivas_binaural_reverb_processSubframe( void ivas_binaural_reverb_processSubframe_fx( REVERB_STRUCT_HANDLE hReverb, /* i/o: binaural reverb handle */ - const int16_t numInChannels, /* i : num inputs to be processed */ - const int16_t numSlots, /* i : number of slots to be processed */ + const Word16 numInChannels, /* i : num inputs to be processed */ + const Word16 numSlots, /* i : number of slots to be processed */ Word32 inReal[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i (Q_in) : input CLDFB data real, Comment: This change swaps two first dimensions as first dimension is not constant. */ Word32 inImag[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i (Q_in) : input CLDFB data imag */ - Word64 outReal[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : output CLDFB data real */ - Word64 outImag[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX] /* o : output CLDFB data imag */ + Word32 outReal[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : output CLDFB data real */ + Word32 outImag[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX] /* o : output CLDFB data imag */ ) { /* Declare the required variables */ @@ -3439,12 +3754,12 @@ void ivas_binaural_reverb_processSubframe_fx( { /* Add from pre-delay buffer a sample to the loop buffer, in a time-inverted order. * Also apply the spectral gains determined for the reverberation */ - hReverb->loopBufReal_fx[bin][invertSampleIndex] = L_add( hReverb->loopBufReal_fx[bin][invertSampleIndex], - Mpy_32_32( hReverb->preDelayBufferReal_fx[idx][bin], hReverb->reverbEqGains_fx[bin] ) ); - hReverb->loopBufImag_fx[bin][invertSampleIndex] = L_add( hReverb->loopBufImag_fx[bin][invertSampleIndex], - Mpy_32_32( hReverb->preDelayBufferImag_fx[idx][bin], hReverb->reverbEqGains_fx[bin] ) ); - hReverb->preDelayBufferReal_fx[idx][bin] = 0; - hReverb->preDelayBufferImag_fx[idx][bin] = 0; + Word32 temp_1 = Mpy_32_32( hReverb->preDelayBufferReal_fx[idx][bin], hReverb->reverbEqGains_fx[bin] ); + Word32 temp_2 = Mpy_32_32( hReverb->preDelayBufferImag_fx[idx][bin], hReverb->reverbEqGains_fx[bin] ); + hReverb->loopBufReal_fx[bin][invertSampleIndex] = L_add( hReverb->loopBufReal_fx[bin][invertSampleIndex], temp_1 ); + hReverb->loopBufImag_fx[bin][invertSampleIndex] = L_add( hReverb->loopBufImag_fx[bin][invertSampleIndex], temp_2 ); + hReverb->preDelayBufferReal_fx[idx][bin] = 0; + hReverb->preDelayBufferImag_fx[idx][bin] = 0; } /* Add every second input channel as is to the pre-delay buffer, and every second input channel with @@ -3489,19 +3804,19 @@ void ivas_binaural_reverb_processSubframe_fx( case 0: /* 0 degrees phase */ v_add_fixed( hReverb->outputBufferReal_fx[bin][ch], tapRealPr_fx[tapIdx], hReverb->outputBufferReal_fx[bin][ch], numSlots, 0 ); v_add_fixed( hReverb->outputBufferImag_fx[bin][ch], tapImagPr_fx[tapIdx], hReverb->outputBufferImag_fx[bin][ch], numSlots, 0 ); - break; + BREAK; case 1: /* 90 degrees phase */ v_sub_fixed( hReverb->outputBufferReal_fx[bin][ch], tapImagPr_fx[tapIdx], hReverb->outputBufferReal_fx[bin][ch], numSlots, 0 ); v_add_fixed( hReverb->outputBufferImag_fx[bin][ch], tapRealPr_fx[tapIdx], hReverb->outputBufferImag_fx[bin][ch], numSlots, 0 ); - break; + BREAK; case 2: /* 180 degrees phase */ v_sub_fixed( hReverb->outputBufferReal_fx[bin][ch], tapRealPr_fx[tapIdx], hReverb->outputBufferReal_fx[bin][ch], numSlots, 0 ); v_sub_fixed( hReverb->outputBufferImag_fx[bin][ch], tapImagPr_fx[tapIdx], hReverb->outputBufferImag_fx[bin][ch], numSlots, 0 ); - break; + BREAK; default: /* 270 degrees phase */ v_add_fixed( hReverb->outputBufferReal_fx[bin][ch], tapImagPr_fx[tapIdx], hReverb->outputBufferReal_fx[bin][ch], numSlots, 0 ); v_sub_fixed( hReverb->outputBufferImag_fx[bin][ch], tapRealPr_fx[tapIdx], hReverb->outputBufferImag_fx[bin][ch], numSlots, 0 ); - break; + BREAK; } } } @@ -3544,8 +3859,8 @@ void ivas_binaural_reverb_processSubframe_fx( FOR( bin = 0; bin < hReverb->numBins; bin++ ) { - outReal[ch][sample][bin] = W_shl( hReverb->outputBufferReal_fx[bin][ch][invertSampleIndex], Q30 ); //Q_in + Q30 - outImag[ch][sample][bin] = W_shl( hReverb->outputBufferImag_fx[bin][ch][invertSampleIndex], Q30 ); //Q_in + Q30 + outReal[ch][sample][bin] = hReverb->outputBufferReal_fx[bin][ch][invertSampleIndex]; // Q_in + Q30 + outImag[ch][sample][bin] = hReverb->outputBufferImag_fx[bin][ch][invertSampleIndex]; // Q_in + Q30 } FOR( ; bin < CLDFB_NO_CHANNELS_MAX; bin++ ) { @@ -3558,6 +3873,7 @@ void ivas_binaural_reverb_processSubframe_fx( pop_wmops(); return; } + #endif /*------------------------------------------------------------------------- * ivas_binaural_reverb_open() @@ -3649,7 +3965,7 @@ static ivas_error ivas_binaural_reverb_open( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } set_s( hReverb->tapPhaseShiftType[bin][chIdx], 0, len ); - +#ifndef IVAS_FLOAT_FIXED if ( ( hReverb->tapPointersReal[bin][chIdx] = (float **) malloc( len * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); @@ -3659,6 +3975,7 @@ static ivas_error ivas_binaural_reverb_open( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } +#endif #ifdef IVAS_FLOAT_FIXED if ( ( hReverb->tapPointersReal_fx[bin][chIdx] = (Word32 **) malloc( len * sizeof( Word32 * ) ) ) == NULL ) { @@ -3672,35 +3989,56 @@ static ivas_error ivas_binaural_reverb_open( #endif len = hReverb->blockSize; - if ( ( hReverb->outputBufferReal[bin][chIdx] = (float *) malloc( len * sizeof( float ) ) ) == NULL ) +#ifdef IVAS_FLOAT_FIXED + if ( ( hReverb->outputBufferReal_fx[bin][chIdx] = (Word32 *) malloc( len * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } - if ( ( hReverb->outputBufferImag[bin][chIdx] = (float *) malloc( len * sizeof( float ) ) ) == NULL ) + if ( ( hReverb->outputBufferImag_fx[bin][chIdx] = (Word32 *) malloc( len * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } - - set_f( hReverb->outputBufferReal[bin][chIdx], 0.0f, len ); - set_f( hReverb->outputBufferImag[bin][chIdx], 0.0f, len ); -#ifdef IVAS_FLOAT_FIXED - if ( ( hReverb->outputBufferReal_fx[bin][chIdx] = (Word32 *) malloc( len * sizeof( Word32 ) ) ) == NULL ) + set_l( hReverb->outputBufferReal_fx[bin][chIdx], 0, len ); + set_l( hReverb->outputBufferImag_fx[bin][chIdx], 0, len ); +#else + if ( ( hReverb->outputBufferReal[bin][chIdx] = (float *) malloc( len * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } - if ( ( hReverb->outputBufferImag_fx[bin][chIdx] = (Word32 *) malloc( len * sizeof( Word32 ) ) ) == NULL ) + if ( ( hReverb->outputBufferImag[bin][chIdx] = (float *) malloc( len * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } - set_l( hReverb->outputBufferReal_fx[bin][chIdx], 0, len ); - set_l( hReverb->outputBufferImag_fx[bin][chIdx], 0, len ); + + set_f( hReverb->outputBufferReal[bin][chIdx], 0.0f, len ); + set_f( hReverb->outputBufferImag[bin][chIdx], 0.0f, len ); #endif } } +#ifdef IVAS_FLOAT_FIXED + Word32 *revTimes_fx = (Word32 *)malloc(sizeof(Word32) * hReverb->numBins); + Word32 *revEnes_fx = (Word32 *)malloc(sizeof(Word32) * hReverb->numBins); + FOR(int i = 0; i < hReverb->numBins; i++) { + revTimes_fx[i] = (Word32)(revTimes[i] * ONE_IN_Q31); + revEnes_fx[i] = (Word32)(revEnes[i] * ONE_IN_Q31); + } + ivas_binaural_reverb_setReverbTimes_fx( hReverb, sampling_rate, revTimes_fx, revEnes_fx ); + + FOR(Word16 bin = 0; bin < hReverb->numBins; bin++) + { + hReverb->binauralCoherenceDirectGains[bin] = (float)hReverb->binauralCoherenceDirectGains_fx[bin] / ONE_IN_Q31; + hReverb->binauralCoherenceCrossmixGains[bin] = (float)hReverb->binauralCoherenceCrossmixGains_fx[bin] / ONE_IN_Q31; + hReverb->loopAttenuationFactor[bin] = (float)hReverb->loopAttenuationFactor_fx[bin] / ONE_IN_Q31; + hReverb->reverbEqGains[bin] = (float)hReverb->reverbEqGains_fx[bin] / ONE_IN_Q31; + } + free(revTimes_fx); + free(revEnes_fx); +#else ivas_binaural_reverb_setReverbTimes( hReverb, sampling_rate, revTimes, revEnes ); +#endif ivas_binaural_reverb_setPreDelay( hReverb, preDelay ); @@ -3810,6 +4148,7 @@ ivas_error ivas_binaural_reverb_open_parambin( * Close binaural room reverberator handle *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void ivas_binaural_reverb_close( REVERB_STRUCT_HANDLE *hReverb /* i/o: binaural reverb handle */ ) @@ -3826,23 +4165,14 @@ void ivas_binaural_reverb_close( FOR( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) { free( ( *hReverb )->tapPhaseShiftType[bin][chIdx] ); - free( ( *hReverb )->tapPointersReal[bin][chIdx] ); - free( ( *hReverb )->tapPointersImag[bin][chIdx] ); - free( ( *hReverb )->outputBufferReal[bin][chIdx] ); - free( ( *hReverb )->outputBufferImag[bin][chIdx] ); -#ifdef IVAS_FLOAT_FIXED + free( ( *hReverb )->tapPointersReal_fx[bin][chIdx] ); free( ( *hReverb )->tapPointersImag_fx[bin][chIdx] ); free( ( *hReverb )->outputBufferReal_fx[bin][chIdx] ); free( ( *hReverb )->outputBufferImag_fx[bin][chIdx] ); -#endif } - free( ( *hReverb )->loopBufReal[bin] ); - free( ( *hReverb )->loopBufImag[bin] ); -#ifdef IVAS_FLOAT_FIXED free( ( *hReverb )->loopBufReal_fx[bin] ); free( ( *hReverb )->loopBufImag_fx[bin] ); -#endif } free( ( *hReverb ) ); @@ -3850,3 +4180,35 @@ void ivas_binaural_reverb_close( return; } +#else +void ivas_binaural_reverb_close( + REVERB_STRUCT_HANDLE *hReverb /* i/o: binaural reverb handle */ +) +{ + Word16 bin, chIdx; + + IF( hReverb == NULL || *hReverb == NULL ) + { + return; + } + + FOR( bin = 0; bin < ( *hReverb )->numBins; bin++ ) + { + FOR( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) + { + free( ( *hReverb )->tapPhaseShiftType[bin][chIdx] ); + free( ( *hReverb )->tapPointersReal[bin][chIdx] ); + free( ( *hReverb )->tapPointersImag[bin][chIdx] ); + free( ( *hReverb )->outputBufferReal[bin][chIdx] ); + free( ( *hReverb )->outputBufferImag[bin][chIdx] ); + } + free( ( *hReverb )->loopBufReal[bin] ); + free( ( *hReverb )->loopBufImag[bin] ); + } + + free( ( *hReverb ) ); + ( *hReverb ) = NULL; + + return; +} +#endif \ No newline at end of file diff --git a/lib_rend/ivas_reverb_filter_design.c b/lib_rend/ivas_reverb_filter_design.c index a65cca31deee9792628facb98b5f4a3a0a671818..e496e879c5d46c986dbce6a017c0de01b1e2757f 100644 --- a/lib_rend/ivas_reverb_filter_design.c +++ b/lib_rend/ivas_reverb_filter_design.c @@ -407,7 +407,7 @@ static void calc_min_phase_filter_fx( Word16 phase_increment; Word32 pMin_phase[RV_FILTER_MAX_FFT_SIZE]; - phase_increment = 0; // delay is 0.0, -PI2 * delay / (float)fft_size; + phase_increment = 0; UNUSED_PARAM(delay); // delay is 0.0, -PI2 * delay / (float)fft_size; move16(); Word16 q_pMin_phase; calc_min_phase_fx(pH_flt, fft_size, pMin_phase, &q_pMin_phase); @@ -629,9 +629,9 @@ static void response_step_limit_fx( const Word16 pivot_bin_idx) { Word16 i; - const Word32 positive_step_limit_lf = 1701766107; //powf(10.0f, 0.05f * step_limit_lf_dB) = 1.5848931924611134852; //q = 30 + const Word32 positive_step_limit_lf = 1701766107; UNUSED_PARAM(step_limit_lf_dB); //powf(10.0f, 0.05f * step_limit_lf_dB) = 1.5848931924611134852; //q = 30 const Word32 negative_step_limit_lf = 677485289; // 1.0f / positive_step_limit_lf = 0.63095734448019324;//q = 30 - const Word32 positive_step_limit_hf = 1276144549; // powf(10.0f, 0.05f * step_limit_hf_dB) = 1.188502227437018437; //q = 30 + const Word32 positive_step_limit_hf = 1276144549; UNUSED_PARAM(step_limit_hf_dB); // powf(10.0f, 0.05f * step_limit_hf_dB) = 1.188502227437018437; //q = 30 const Word32 negative_step_limit_hf = 903441154; // 1.0f / positive_step_limit_hf = 1.26209271246779263; //q = 30 /* Go up from pivot frequency and limit the slope to the maximum given by T. */ @@ -860,9 +860,9 @@ Word16 ivas_reverb_calc_color_filters_fx( half_fft_size = shr(fft_size, 1); FOR(idx = 0; idx <= half_fft_size; idx++) { - pBeqL[idx][0] = pTargetL[idx]; move32(); + pBeqL[idx][0] = L_shl(pTargetL[idx], 1); move32(); pBeqL[idx][1] = 0; move32(); - pBeqR[idx][0] = pTargetR[idx]; move32(); + pBeqR[idx][0] = L_shl(pTargetR[idx], 1); move32(); pBeqR[idx][1] = 0; move32(); } diff --git a/lib_rend/ivas_rom_TdBinauralRenderer.c b/lib_rend/ivas_rom_TdBinauralRenderer.c index 5c798e69729527cc4ecaf8471df42a34b84614ac..91f79fb63c3d7551cc26fb5d94af8192e9a7795f 100644 --- a/lib_rend/ivas_rom_TdBinauralRenderer.c +++ b/lib_rend/ivas_rom_TdBinauralRenderer.c @@ -90,7 +90,7 @@ const Word32 defaultHRIR_rom_azimBsShape_fx[21]/*Q30*/ = { #endif #ifdef IVAS_FLOAT_FIXED -const Word32 defaultHRIR_rom_AlphaL48_fx[470 * 128] = { +const UWord32 defaultHRIR_rom_AlphaL48_fx[470 * 128] = { 0x08946b90,0x01b51044,0x0a3be7e0,0x08059140,0x08956970,0x08977810,0x0902edf0,0x092d8070,0x09514fc0,0x09037030,0x08d22420,0x089c8890,0x086fde70,0x084b4aa0,0x0835ecf0,0x08249b70,0x08116dd0,0x08085020,0x07e77410,0x0773bf10,0x095b7f10,0x01583d2c,0xfee45aca,0xfbd573d8,0x02d72514, 0xff01b3a9,0xfc39200c,0xfc096278,0xfc3dc844,0xfd17e024,0xfc2228c0,0xfbd986e0,0xfc0bded8,0xff02a7ec,0x03e2cc90,0xfc372258,0xfe92ec80,0xfe04a288,0x08e19d20,0x0a0943f0,0x09fe5830,0x0a947bb0,0x0bc07e70,0x0c4e2300,0x0c63c590,0x0ba72080,0x0af61460,0x0a475af0,0x09bd4da0,0x09633a90, 0x0933ee10,0x0906f870,0x08c19050,0x08b9f000,0x08125690,0x0850f510,0x06f136a8,0xfecea9ee,0x041a5f78,0x0324e7d4,0x0320b0d8,0x02092f50,0x03aa0f60,0x0410f470,0x037ff800,0x01f8011c,0x03dc8dbc,0x05a77198,0x03c94958,0x04436480,0x0298d478,0x0237f498,0x068949c8,0x0242ea64,0x07d952a0, @@ -2499,7 +2499,7 @@ const Word32 defaultHRIR_rom_AlphaL48_fx[470 * 128] = { 0xffff05ed,0xffff0401,0xfffef94c,0xfffee868,0xfffedde9,0xfffedc62,0xfffeb004,0xfffe8b7f,0xfffe6cde,0xfffe4910,0xfffe30fb,0xfffe0fdf,0xfffe2852,0xfffe31ed,0xfffe3b22,0xfffe4b08,0xfffe4c27,0xfffe89e7,0xfffe14e1,0xfffe389c,0xfffd9736,0x0000caca,0x0000795b,0x000077ad,0x00007a6e, 0x000079db,0x000079d5,0x000079d9,0x00007a6c,0x000077c2,0x00007981,0x0000c58b,0xfffdc44c,0xfffe8035,0xfffe5828 }; -const Word32 defaultHRIR_rom_AlphaR48_fx[470 * 128] = { +const UWord32 defaultHRIR_rom_AlphaR48_fx[470 * 128] = { 0x08945950,0x08070b50,0x0a49d6a0,0x01bd7c0a,0xfe8e8ea8,0xfc2f2da0,0x03d9eadc,0xff0186c2,0xfc122c50,0xfbe0a0e8,0xfc206c28,0xfd11f02c,0xfc3abd38,0xfc07e728,0xfc3b9950,0xff036bd6,0x02d4bca0,0xfbdbc558,0xfef1f73c,0x015de0c6,0x095c18c0,0x0773d5b8,0x07e73000,0x080876d0,0x081163c0, 0x0824a330,0x0835f7f0,0x084b5f70,0x086feee0,0x089c88a0,0x08d20e60,0x090371e0,0x09517940,0x092d8530,0x09028ae0,0x08987f90,0x08931f20,0x0a0e8e20,0x08b90d00,0xfdf48fbc,0x0693d930,0x02488cdc,0x02b07554,0x04443188,0x03bbc4f4,0x0594cd00,0x03e35c18,0x0205e0c8,0x0385d814,0x04150620, 0x03a53d84,0x0201923c,0x032afa50,0x03171178,0x03f60448,0xfec67ca4,0x06ee54d8,0x0851b610,0x0812b5e0,0x08b99090,0x08c1d7a0,0x0906cf10,0x0933fa90,0x0962ff70,0x09bd4010,0x0a475770,0x0af66880,0x0ba70470,0x0c63a8e0,0x0c4da000,0x0bc22ab0,0x0a9207f0,0x0a00d410,0x0ba14f60,0x082f2360, @@ -4908,7 +4908,7 @@ const Word32 defaultHRIR_rom_AlphaR48_fx[470 * 128] = { 0xfffea403,0xfffe8046,0xfffdc451,0x0000c589,0x00007983,0x000077c3,0x00007a6d,0x000079da,0x000079d6,0x000079db,0x00007a70,0x000077ad,0x00007957,0x0000caeb,0xfffd96db,0xfffe38c4,0xfffe17ea,0xfffe8d40,0xfffe4caf,0xfffe4a9f,0xfffe3b3c,0xfffe31ec,0xfffe284d,0xfffe0fda,0xfffe30ff, 0xfffe4917,0xfffe6ce4,0xfffe8b83,0xfffeb014,0xfffedc7c,0xfffede07,0xfffee879,0xfffef944,0xffff0401,0xfffe5825, }; -const Word32 defaultHRIR_rom_AlphaL32_fx[470 * 86] = { +const UWord32 defaultHRIR_rom_AlphaL32_fx[470 * 86] = { 0x100cd6e0,0x03ada060,0x1363aec0,0x0eeb9f60,0x101f3420,0x0ffc18c0,0x10e4c040,0x113b8380,0x117faa40,0x10f36460,0x109615e0,0x1029fa80,0x0fd129a0,0x0f89b9a0,0x0f672bf0,0x0f4293d0,0x0f1fca20,0x0f0cc6c0,0x0edc4f60,0x0de07780,0x11af0240,0x02fb58f8,0xfd048398,0xf50b7dc0,0x06155418, 0xfd68e604,0xf5f7de90,0xf5a34550,0xf5febb10,0xf7c14d10,0xf5e3f200,0xf56df070,0xf5e14d60,0xfd7c6ae4,0x0836d5d0,0xf5ceff80,0xfc4e19a0,0xfa81c158,0x11195200,0x12a23f40,0x12b60200,0x13902ca0,0x1610a420,0x17304340,0x175cbae0,0x16139d80,0x14bec2c0,0x135466e0,0x123a1600,0x118c51c0, 0x1147b520,0x10ed2ba0,0x10739900,0x1066d060,0x0f427540,0x0f908120,0x0d5b2440,0xfc723054,0x07825ef8,0x05f29028,0x05698548,0x035f134c,0x06fd5468,0x07d6dce0,0x070d2a78,0x03aefedc,0x07bd4520,0x0acd1e20,0x06d3d4d0,0x07f90c48,0x04391780,0x03b60b90,0x0c5eb790,0x03ee4574,0x0ec7ef40, @@ -6527,7 +6527,7 @@ const Word32 defaultHRIR_rom_AlphaL32_fx[470 * 86] = { 0xffffc40c,0xffffc4b2,0xffffbada,0xffffcd42,0xffffd596,0xfffffcd9,0x00007843,0x0000740d,0xfffed1d5,0xffff4a9e,0xffff440e,0xffff3e6d,0xffff34fd,0xffff2752,0xffff1e63,0xffff18a6,0xffff01af,0xfffeeb5a,0xfffeda7f,0xfffec55c,0xfffeb9a5,0xfffea925,0xfffeb804,0xfffebd16,0xfffec275, 0xfffeca6b,0xfffec8a8,0xffff02a2,0xfffe5abf,0xfffe87fd,0xfffe61a0,0x00008947,0x00004c91,0x00009b73,0x00009b06,0x000097a3,0x00009869,0x00009728,0x00009918,0x000093ea,0x000056c5,0x0000849f,0xfffe9273,0xfffed20a,0xfffec5f7, }; -const Word32 defaultHRIR_rom_AlphaR32_fx[470 * 86] = { +const UWord32 defaultHRIR_rom_AlphaR32_fx[470 * 86] = { 0x100cb860,0x0eef8620,0x13822fa0,0x03bfbf7c,0xfc41efd4,0xf5ba68d0,0x0822d810,0xfd7a6134,0xf5eecc80,0xf57c62e0,0xf5e038f0,0xf7b60930,0xf5f98590,0xf5a102c0,0xf5fd0030,0xfd6bb708,0x060f7ee0,0xf515aa30,0xfd1b6c7c,0x030560c0,0x11b23540,0x0de148b0,0x0edb67d0,0x0f0d2c70,0x0f1faf20, 0x0f42a240,0x0f674600,0x0f89e680,0x0fd14ea0,0x1029fb20,0x1095f420,0x10f36760,0x117ff400,0x113b8180,0x10e3f6e0,0x0ffe4180,0x101a20a0,0x12abb7e0,0x10c05ec0,0xfa5f0c98,0x0c7b5470,0x03e36f60,0x046c52a0,0x07fa7bf8,0x06b65ea0,0x0aa712f0,0x07cc00b8,0x03c8cd8c,0x07173000,0x07dd44e8, 0x06f32888,0x03515f80,0x058072f8,0x05db9da8,0x0744ab60,0xfc64e6dc,0x0d4f09e0,0x0f91bbc0,0x0f43d870,0x1065b780,0x10745600,0x10ecc420,0x1147ca40,0x118bce20,0x1239ed60,0x13545de0,0x14bf5420,0x16135d00,0x175ca760,0x172f3020,0x16143f40,0x138ab280,0x12bc2cc0,0x15e153c0,0x0f8672c0, @@ -8146,7 +8146,7 @@ const Word32 defaultHRIR_rom_AlphaR32_fx[470 * 86] = { 0xfffeda4a,0xfffeea0d,0xfffeeb27,0xfffeeb7d,0xfffefb02,0xffff0ca9,0xffff0919,0xffff2b05,0xffff43fe,0xffff4afb,0xfffed1ec,0xfffed1af,0xfffe92a1,0x000084ec,0x000056b8,0x000093e9,0x0000991b,0x00009728,0x0000986b,0x000097a4,0x00009b07,0x00009b74,0x00004c8e,0x0000895e,0xfffe615a, 0xfffe87fe,0xfffe5cdc,0xffff0514,0xfffec90e,0xfffeca1c,0xfffec288,0xfffebd15,0xfffeb802,0xfffea922,0xfffeb9a9,0xfffec560,0xfffeda7f,0xfffeeb5e,0xffff01ba,0xffff18b4,0xffff1e73,0xffff275b,0xffff3500,0xffff3e52,0xfffec5f4, }; -const Word32 defaultHRIR_rom_AlphaL16_fx[470 * 43] = { +const UWord32 defaultHRIR_rom_AlphaL16_fx[470 * 43] = { 0x20bc6cc0,0x187d2c60,0x20d0fb40,0x1e5b58c0,0x1ff07300,0x208f6ec0,0x21e21e40,0x227fff40,0x231b98c0,0x22400500,0x21bce580,0x2129dc80,0x2085a440,0x1feba500,0x1f50d8e0,0x1ee88420,0x1e7a2340,0x1e1bc600,0x1dad7840,0x1c7fbbe0,0x1ee2e620,0x1708c780,0x121adb20,0x0748b300,0x18c877a0, 0x1233e240,0x080e9a60,0x081de920,0x086274f0,0x09c7ed60,0x08fd8b60,0x08f8e8d0,0x096fa820,0x12b862c0,0x1aa86160,0x091d3490,0x12a28f40,0x116ccd00,0x22d41740,0x23937f00,0x25cc5200,0x2848be40,0x2c640fc0,0x2e780f40,0x2f0c1840,0x2cc1b4c0,0x2aad3400,0x28b2fcc0,0x26c3ec40,0x25066fc0, 0x23681900,0x222a5040,0x20f05480,0x20256780,0x1e7ab1e0,0x1d7eaac0,0x1c6be460,0x0eca8780,0x167cc5c0,0x15e0e960,0x13f86880,0x11fb2fc0,0x1541d600,0x157fc3a0,0x15c64020,0x134c6ba0,0x16410020,0x18031d00,0x15a6af40,0x176efbc0,0x15265380,0x15a5b600,0x1c7263a0,0x169b7620,0x1ff14a80, @@ -8957,7 +8957,7 @@ const Word32 defaultHRIR_rom_AlphaL16_fx[470 * 43] = { 0xfff93aa6,0xfff92570,0xfff8f7a2,0xfff8848a,0xfff847dc,0xfff803e1,0xfff77ff2,0xfff6f7d2,0xfff6a07c,0xfff62c9c,0xfff5fd96,0xfff5ada6,0xfff63a65,0xfff685ba,0xfff6c4f9,0xfff72f17,0xfff756e1,0xfff8219c,0xfff7b122,0xfff7784f,0xfff68a1f,0xfffcae7b,0xfffcb53a,0xfffd35e7,0xfffd11bc, 0xfffd0522,0xfffcf930,0xfffcff01,0xfffcfd89,0xfffcff41,0xfffc9a53,0xfffceec8,0xfff60ae3,0xfff6eb5a,0xfff60a41, }; -const Word32 defaultHRIR_rom_AlphaR16_fx[470 * 43] = { +const UWord32 defaultHRIR_rom_AlphaR16_fx[470 * 43] = { 0x20bc5600,0x1e5ed260,0x20e8da40,0x188db140,0x12958b20,0x0906c690,0x1a999ee0,0x12ba4920,0x097dce40,0x0906b8e0,0x08f8ab10,0x09bc0990,0x085c3450,0x081bb920,0x08157b10,0x123510e0,0x18bd42a0,0x07506690,0x1230f920,0x1711f640,0x1ee77fa0,0x1c814cc0,0x1dac1bc0,0x1e1c44c0,0x1e7a0b40, 0x1ee88080,0x1f50d220,0x1febad40,0x2085ba80,0x2129d500,0x21bca140,0x22401bc0,0x231c2200,0x227fd880,0x21e17340,0x2090c740,0x1fec8d80,0x239775c0,0x22918780,0x1148e780,0x1c908300,0x15dcf3e0,0x1546c9e0,0x176b49a0,0x15864820,0x17de99a0,0x1652d300,0x13666440,0x15d3e660,0x15857380, 0x1533c000,0x11ef5f40,0x141e81e0,0x15ce7080,0x163fb3a0,0x0ec15720,0x1c5a3ce0,0x1d7f55c0,0x1e7d0be0,0x2023db80,0x20f12d40,0x2229f440,0x236884c0,0x25063640,0x26c3e400,0x28b2f780,0x2aae0480,0x2cc17d40,0x2f0af400,0x2e77cec0,0x2c671ec0,0x284489c0,0x25d28c00,0x25b2b200,0x207c4f40, @@ -19455,7 +19455,7 @@ const uint32_t defaultHRIR_rom_AlphaR16[470 * 43] = { }; #ifdef IVAS_FLOAT_FIXED -const Word32 defaultHRIR_rom_EL48_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { +const UWord32 defaultHRIR_rom_EL48_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { 0x047ee788,0x04713840,0x0529a410,0x03f0b798,0x047f3c18,0x04837bb8,0x04e6ef58,0x050a0848,0x0526d1d8,0x04dde4d0,0x04b03170,0x047a5f98,0x04557be8,0x0435aef8,0x04219f28,0x0409e930,0x03f53628,0x03e081f4,0x03d08964,0x0369480c,0x0461f8f8,0x03f57950,0x04942f18,0x079476f0,0x03dd0b88, 0x04674460,0x06ce48b8,0x06f8dec8,0x06d02058,0x05eebea0,0x06d4bdf8,0x070a0ab0,0x06c2bbc8,0x04869fb8,0x043c8778,0x07602090,0x05466bc8,0x06734928,0x0623ed08,0x05ecd400,0x06cb3718,0x073ef9f8,0x08a6b430,0x0950db10,0x0967f000,0x08730820,0x0790aa90,0x06a725e0,0x06043808,0x05971410, 0x055f9e40,0x051af2d8,0x04db0270,0x04a8cbc0,0x04471a50,0x03e65d80,0x03d55ac8,0x03f1c30c,0x0262b518,0x02aa95ac,0x020ed324,0x020401a0,0x02518068,0x024c6378,0x02ac6c04,0x028bd768,0x02a47034,0x029fb52c,0x023afb38,0x029aee10,0x02ab931c,0x03179200,0x03cc4100,0x04b6e170,0x05df2bb0, @@ -19515,7 +19515,7 @@ const Word32 defaultHRIR_rom_EL48_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { 0x0000bba0,0x0000a655,0x0000b00c,0x0000aaff,0x0000a4e6,0x00007d8e,0x00006765,0x00009e3e,0x00007e4b,0x00007037 };; -const Word32 defaultHRIR_rom_ER48_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { +const UWord32 defaultHRIR_rom_ER48_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { 0x047ee4d8,0x03f280b8,0x05386b98,0x0472fda0,0x0546eb40,0x076f6d78,0x04382528,0x0488aa00,0x06bd5348,0x0704d428,0x06d60568,0x05f157b8,0x06d09290,0x06f92248,0x06cc8e98,0x0466c600,0x03db67c4,0x07924390,0x048ebf48,0x03f41dd8,0x04657680,0x036a1ca0,0x03cfde2c,0x03e0ba68,0x03f52760, 0x0409ea10,0x0421a660,0x0435ba10,0x04558680,0x047a5fa8,0x04b01dc0,0x04dde948,0x0526fc60,0x0509efe8,0x04e6aa20,0x04840c20,0x047d6488,0x05ed4498,0x05ff8e50,0x068475b0,0x03d7760c,0x03201db0,0x02a62e40,0x02995154,0x02374fd0,0x029927f8,0x02a77ff0,0x028bc644,0x02ad3d58,0x024cb2e0, 0x0250460c,0x02047db0,0x0211f2bc,0x02acc4b0,0x02629f04,0x03f5ad90,0x03cb3008,0x03e67e74,0x044851e0,0x04a7fb88,0x04db7d40,0x051ab720,0x055faf70,0x0596e218,0x06042ac8,0x06a71b70,0x0790f2e0,0x0872dea0,0x09677860,0x0950aa80,0x08a8a570,0x073c5fd0,0x06cf9508,0x08c03920,0x061f64b0, @@ -19575,7 +19575,7 @@ const Word32 defaultHRIR_rom_ER48_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { 0x0000497d,0x00004a60,0x00004bf4,0x00004f03,0x00005602,0x0000510f,0x00004fbb,0x00004f07,0x00004f16,0x00007035 };; -const Word32 defaultHRIR_rom_EL32_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { +const UWord32 defaultHRIR_rom_EL32_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { 0x054a4eb8,0x04f4f0d8,0x05569b70,0x04b47630,0x052be930,0x0558ee78,0x05a21340,0x05c92f10,0x06092e60,0x05a367d8,0x056ef578,0x053967f0,0x050b7040,0x04e48198,0x04c1a078,0x04ab4c58,0x04922828,0x04796a68,0x045da820,0x040c93f8,0x048b76b0,0x046b48d0,0x04a92308,0x0663b628,0x04465358, 0x047a43a0,0x05ccc530,0x05e3ce48,0x05bf4e28,0x05441fe8,0x05c979c8,0x05fd7718,0x05df75e0,0x04a4ec80,0x04991e50,0x06641720,0x053f2f28,0x06b72af0,0x06f11a08,0x06feb018,0x080029f0,0x08c5c000,0x09cc9040,0x0a736fb0,0x0afda5f0,0x09a82a90,0x08b57570,0x07cbf1f8,0x070ce3d8,0x0679eea8, 0x060e5dc0,0x05bead00,0x056ee598,0x052b2f60,0x04bdb2c8,0x04516048,0x04425da8,0x043a2360,0x0330b688,0x03505144,0x02d20d84,0x02b7914c,0x02dfe2c8,0x02dd17b4,0x03220308,0x030ea8d8,0x031f84e0,0x03222f38,0x02fbd6b4,0x03604ce0,0x0392cba8,0x0403a5d0,0x04a83a30,0x05dbb268,0x074d2070, @@ -19635,7 +19635,7 @@ const Word32 defaultHRIR_rom_EL32_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { 0x00008f5e,0x00008abf,0x00008b73,0x0000896d,0x00008d88,0x00007df7,0x00007884,0x00007bdd,0x00007824,0x00008e1d }; -const Word32 defaultHRIR_rom_ER32_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { +const UWord32 defaultHRIR_rom_ER32_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { 0x054a4a90,0x04b59ef0,0x056004c0,0x04f624c8,0x05412248,0x06704ac8,0x0497dc00,0x04a6cb70,0x05db4030,0x05f962d0,0x05ca3a18,0x0545d3b0,0x05bf93a0,0x05e45250,0x05cc2d70,0x0479a490,0x0443aa10,0x06608268,0x04a79d68,0x046b7780,0x048cf9f0,0x040d0960,0x045d49a0,0x04798b10,0x049221d8, 0x04ab4a30,0x04c19e60,0x04e487e0,0x050b7560,0x05396118,0x056ed2e8,0x05a36f38,0x06096f58,0x05c92ae0,0x05a1f158,0x05593640,0x052acdc0,0x06fdff08,0x06daac48,0x06c51e00,0x04ae7998,0x04066aa0,0x038b0910,0x035dec1c,0x02f83044,0x031c4304,0x0322f880,0x03106168,0x0324368c,0x02dda158, 0x02dda124,0x02b7a97c,0x02d7a5cc,0x035008c8,0x032bd304,0x043cd348,0x043d7fa8,0x04516aa0,0x04be5bc8,0x052abe80,0x056f24d8,0x05be9088,0x060e7f78,0x0679cd48,0x070ce1f8,0x07cbfcf8,0x08b5d8f0,0x09a80d70,0x0afcb9c0,0x0a733f10,0x09cdcf00,0x08c3d910,0x0803aa60,0x09db3c80,0x07760478, @@ -19695,7 +19695,7 @@ const Word32 defaultHRIR_rom_ER32_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { 0x0000595c,0x00005638,0x000052f9,0x000052b0,0x00005261,0x0000562b,0x00005869,0x00005c08,0x00005f3c,0x00008e1b }; -const Word32 defaultHRIR_rom_EL16_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { +const UWord32 defaultHRIR_rom_EL16_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { 0x0624a2d8,0x0502a108,0x05b79728,0x056d4278,0x05b9bb98,0x05e5c5a0,0x06306120,0x0654ff78,0x067b1728,0x063a1c20,0x0613f848,0x05ee0980,0x05c33e88,0x059d3e18,0x057b0f90,0x05587a98,0x053bcb90,0x0523f068,0x050f7448,0x04db7478,0x0523f160,0x04961aa0,0x049bddb0,0x05a78478,0x046b85e0, 0x04637c28,0x05380080,0x054a5d90,0x05363028,0x050b2de0,0x05249788,0x0537d5d8,0x053265e8,0x047e3db8,0x04ac31f0,0x05954f50,0x04ef02d8,0x063a6220,0x071ba9b0,0x074d5100,0x07f8d530,0x08ad8a40,0x09c936d0,0x0a6c9e40,0x0abe03a0,0x09ec2c90,0x093fda60,0x089fee20,0x0805d110,0x078068a0, 0x07113e30,0x069a8fe0,0x063d24d0,0x05fd1120,0x05a84f60,0x0560f1b8,0x051edb20,0x04cd7c58,0x043a1788,0x04023720,0x03bcda18,0x039264e8,0x037f5924,0x03993a9c,0x03b1705c,0x03aa9534,0x03a49c58,0x03bc5730,0x03c748b4,0x0415fee8,0x044e85d8,0x0496d008,0x05614688,0x061778a8,0x07d401b8, @@ -19755,7 +19755,7 @@ const Word32 defaultHRIR_rom_EL16_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { 0x00012626,0x00011e5a,0x00012093,0x00011d2c,0x000127d3,0x0001087d,0x0000fe1f,0x0000ff1c,0x0000f85b,0x0001253d }; -const Word32 defaultHRIR_rom_ER16_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { +const UWord32 defaultHRIR_rom_ER16_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { 0x0624a0e0,0x056db600,0x05bb77a0,0x0503cb18,0x04ef0160,0x05965d08,0x04a9add8,0x047e1d30,0x05325de0,0x053790e8,0x052407d8,0x050a5ea0,0x05357c10,0x054a7a30,0x05383838,0x04636030,0x046979c8,0x05a5d650,0x049bd6d8,0x04969ab0,0x0524e510,0x04dbc5e8,0x050f3628,0x05240978,0x053bc720, 0x055879e8,0x057b1008,0x059d3f68,0x05c342b0,0x05ee07c0,0x0613ed00,0x063a23d0,0x067b3920,0x0654f4f0,0x06303e80,0x05e5f970,0x05b92728,0x074deba8,0x07120130,0x063be4a0,0x0563d9f8,0x049bfa40,0x04522128,0x04164b68,0x03c36a60,0x03b749dc,0x03a7aefc,0x03ae0df8,0x03b453fc,0x0399cf74, 0x037cd76c,0x03920410,0x03c1bb4c,0x04013088,0x0434eba8,0x04ceb318,0x051bd998,0x0560ef30,0x05a8bf70,0x05fcb978,0x063d5258,0x069a7b28,0x07114bf8,0x07805d60,0x0805cd20,0x089fed90,0x09400960,0x09ec13d0,0x0abd8370,0x0a6c94a0,0x09ca0b10,0x08aca8e0,0x07f9fac8,0x08dcef90,0x07e0f8c0, @@ -19814,7 +19814,7 @@ const Word32 defaultHRIR_rom_ER16_fx[HRTF_MODEL_N_SECTIONS * 470] /*Q28*/ = { 0x0000ec4c,0x0000f920,0x0001005c,0x0000fed4,0x000108c7,0x000127f9,0x00011d3d,0x0001207f,0x00011e63,0x00012629,0x000126c2,0x000130a5,0x000113de,0x00010d27,0x00010b98,0x000104d0,0x0000ff4e,0x00010050,0x0000f01d,0x0000e69c,0x0000ddd1,0x0000d629,0x0000ceee,0x0000c5ee,0x0000bd83, 0x0000b3fa,0x0000adb0,0x0000a713,0x0000a657,0x0000a53c,0x0000adce,0x0000b36a,0x0000bc7f,0x0000c4b0,0x0001253a }; -const Word32 defaultHRIR_rom_ITD_W_fx[658] /*Q25*/ = { +const UWord32 defaultHRIR_rom_ITD_W_fx[658] /*Q25*/ = { 0xffffffde,0x00037a90,0xff0ed1ae,0xffc52953,0x002ad399,0x01085cda,0xfe7ecf7e,0xff6e3fa1,0xffe757e7,0x00e4982c,0xff986595,0xfe86d766,0xfe417af0,0xff6c553e,0xff9f2374,0xfe9eb08a,0xfdf3707c,0x00be1f75,0xff4511a2,0xff8274f1,0xfefa67d6,0x00016276,0x010869dc,0x008240b5,0x00c41384, 0xff42893a,0x0205fee8,0x015e93cc,0x005e8d67,0x0095178f,0x01b7518e,0x016cd626,0x00661c05,0xff2e08f1,0x0028002f,0x008ed0a6,0x0178697a,0xfeee98ee,0xffd87cce,0x004284ad,0x00f1ac80,0x0029d91b,0xfff2fa8a,0x0083e76e,0x021c1194,0xfeced6a6,0xfe715f1a,0xfc1debf4,0xfa4b89a8,0xfa187350, 0xf86ebf30,0xfb447e68,0xfc7b82bc,0xfd708f04,0xfb1dd548,0xfa4fe7b0,0xfbd43f60,0xfd27e7c0,0xff0fc532,0x00482bc9,0x028a1508,0x009390c2,0xfffd7fcc,0xff660df9,0xfd717c98,0xffa6b230,0x00ef141d,0x02e58130,0x042c7870,0x05b75600,0x04dbc1a8,0x029d0fd8,0x039771a0,0x04c03ee0,0x0771a8a8, diff --git a/lib_rend/ivas_rom_TdBinauralRenderer.h b/lib_rend/ivas_rom_TdBinauralRenderer.h index f6a83388005e897d4dfd3d56e881562da3a67a8a..d34cff1e831b45a6359b65029387d46fe7cecca2 100644 --- a/lib_rend/ivas_rom_TdBinauralRenderer.h +++ b/lib_rend/ivas_rom_TdBinauralRenderer.h @@ -65,18 +65,18 @@ extern const uint32_t defaultHRIR_rom_EL16[HRTF_MODEL_N_SECTIONS * 470]; extern const uint32_t defaultHRIR_rom_ER16[HRTF_MODEL_N_SECTIONS * 470]; extern const uint32_t defaultHRIR_rom_elevBsShape[36]; #ifdef IVAS_FLOAT_FIXED -extern const Word32 defaultHRIR_rom_AlphaL48_fx[470 * 128]; /*Q30*/ -extern const Word32 defaultHRIR_rom_AlphaR48_fx[470 * 128]; /*Q30*/ -extern const Word32 defaultHRIR_rom_AlphaL32_fx[470 * 86]; /*Q30*/ -extern const Word32 defaultHRIR_rom_AlphaR32_fx[470 * 86]; /*Q30*/ -extern const Word32 defaultHRIR_rom_AlphaL16_fx[470 * 43]; /*Q30*/ -extern const Word32 defaultHRIR_rom_AlphaR16_fx[470 * 43]; /*Q30*/ -extern const Word32 defaultHRIR_rom_EL48_fx[HRTF_MODEL_N_SECTIONS * 470]; /*Q28*/ -extern const Word32 defaultHRIR_rom_ER48_fx[HRTF_MODEL_N_SECTIONS * 470]; /*Q28*/ -extern const Word32 defaultHRIR_rom_EL32_fx[HRTF_MODEL_N_SECTIONS * 470]; /*Q28*/ -extern const Word32 defaultHRIR_rom_ER32_fx[HRTF_MODEL_N_SECTIONS * 470]; /*Q28*/ -extern const Word32 defaultHRIR_rom_EL16_fx[HRTF_MODEL_N_SECTIONS * 470]; /*Q28*/ -extern const Word32 defaultHRIR_rom_ER16_fx[HRTF_MODEL_N_SECTIONS * 470]; /*Q28*/ +extern const UWord32 defaultHRIR_rom_AlphaL48_fx[470 * 128]; /*Q30*/ +extern const UWord32 defaultHRIR_rom_AlphaR48_fx[470 * 128]; /*Q30*/ +extern const UWord32 defaultHRIR_rom_AlphaL32_fx[470 * 86]; /*Q30*/ +extern const UWord32 defaultHRIR_rom_AlphaR32_fx[470 * 86]; /*Q30*/ +extern const UWord32 defaultHRIR_rom_AlphaL16_fx[470 * 43]; /*Q30*/ +extern const UWord32 defaultHRIR_rom_AlphaR16_fx[470 * 43]; /*Q30*/ +extern const UWord32 defaultHRIR_rom_EL48_fx[HRTF_MODEL_N_SECTIONS * 470]; /*Q28*/ +extern const UWord32 defaultHRIR_rom_ER48_fx[HRTF_MODEL_N_SECTIONS * 470]; /*Q28*/ +extern const UWord32 defaultHRIR_rom_EL32_fx[HRTF_MODEL_N_SECTIONS * 470]; /*Q28*/ +extern const UWord32 defaultHRIR_rom_ER32_fx[HRTF_MODEL_N_SECTIONS * 470]; /*Q28*/ +extern const UWord32 defaultHRIR_rom_EL16_fx[HRTF_MODEL_N_SECTIONS * 470]; /*Q28*/ +extern const UWord32 defaultHRIR_rom_ER16_fx[HRTF_MODEL_N_SECTIONS * 470]; /*Q28*/ #endif #ifdef IVAS_FLOAT_FIXED extern const Word32 defaultHRIR_rom_elevBsShape_fx[36];/*Q30*/ @@ -91,7 +91,7 @@ extern const float defaultHRIR_rom_ITD_azimKSeq[19]; extern const uint32_t defaultHRIR_rom_ITD_elevBsShape[28]; extern const float defaultHRIR_rom_ITD_elevKSeq[16]; #ifdef IVAS_FLOAT_FIXED -extern const Word32 defaultHRIR_rom_ITD_W_fx[658];/*Q25*/ +extern const UWord32 defaultHRIR_rom_ITD_W_fx[658];/*Q25*/ extern const Word32 defaultHRIR_rom_ITD_elevKSeq_fx[16];/*Q22*/ extern const Word32 defaultHRIR_rom_ITD_elevBsShape_fx[28];/*Q30*/ extern const Word32 defaultHRIR_rom_ITD_azimKSeq_fx[19];/*Q22*/ diff --git a/lib_rend/ivas_rom_binauralRenderer.c b/lib_rend/ivas_rom_binauralRenderer.c index 5310041caba0e49255ab9929e27f6c02b96423cb..7a84cc2d1561cd5c60637ac95263bee503c398fc 100644 --- a/lib_rend/ivas_rom_binauralRenderer.c +++ b/lib_rend/ivas_rom_binauralRenderer.c @@ -47741,9 +47741,9 @@ const float parametricReverberationEneCorrections[CLDFB_NO_CHANNELS_MAX] = #ifdef IVAS_FLOAT_FIXED const Word32 parametricEarlyPartEneCorrection_fx[CLDFB_NO_CHANNELS_MAX]/*Q-31*/ = { - -1278914560, -1469108608, -2147483648, -1890004608, -1560359424, -1136244352, -980880320, -822859904, -712393344, - -709882944, -937310016, -1272336768, -1647858688, -2147483648, -2147483648, -2147483648, -2147483648, -2147483648, - -2147483648, -2147483648, -2147483648, -2147483648, -808619904, -378908448, -321778944, -279832160, -294396384, + -1278914560, -1469108608, -2147483647 - 1, -1890004608, -1560359424, -1136244352, -980880320, -822859904, -712393344, + -709882944, -937310016, -1272336768, -1647858688, -2147483647 - 1, -2147483647 - 1, -2147483647 - 1, -2147483647 - 1, -2147483647 - 1, + -2147483647 - 1, -2147483647 - 1, -2147483647 - 1, -2147483647 - 1, -808619904, -378908448, -321778944, -279832160, -294396384, -628592064, -1246109568, -1574331008, -1577608064, -1642900096, -1631784832, -1183766016, -553299136, -195307200, -112115824, -117877528, -108836616, -76572824, -47888884, -34220152, -27120570, -22909356, -19503446, -16683800, -17248588, -23562190, -31726924, -36056252, -35111356, -91716880, -166079936, -142245024, -90293096, -42986180, diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 35d6b41bf9d72a517ea99d8316341a5042d8cc3c..030c503e09ce899a0aaa3785ca0bc5a1db932666 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -46,8 +46,7 @@ #include "prot_fx2.h" #include "debug.h" #include "ivas_rom_binaural_crend_head.h" -#define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) ) -#define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) ) +#define float_to_fixed( n, factor ) ( round( n * ( 1 << factor ) ) ) Word16 square_root16_table[] = { 0, 0x4000, 0x5A82 }; // Q14 Word16 square_root30_q12[31] = { @@ -1631,6 +1630,23 @@ ivas_error ivas_combined_orientation_open( identity.w = 1.0f; identity.x = identity.y = identity.z = 0.0f; origo.x = origo.y = origo.z = 0.0f; +#ifdef IVAS_FLOAT_FIXED + identity.w_fx = ONE_IN_Q30; + identity.w_qfact = 1; + identity.x_fx = 0; + identity.x_qfact = 1; + identity.y_fx = 0; + identity.y_qfact = 1; + identity.z_fx = 0; + identity.z_qfact = 1; + + origo.x_fx = 0; + origo.x_qfact = 0; + origo.y_fx = 0; + origo.y_qfact = 0; + origo.z_fx = 0; + origo.z_qfact = 0; +#endif /* Allocate handle */ if ( ( *hCombinedOrientationData = (COMBINED_ORIENTATION_HANDLE) malloc( sizeof( COMBINED_ORIENTATION_DATA ) ) ) == NULL ) @@ -2043,10 +2059,22 @@ ivas_error combine_external_and_head_orientations( { for ( j = 0; j < 3; j++ ) { - hCombinedOrientationData->Rmat_fx[k][i][j] = (Word32) float_to_fix( hCombinedOrientationData->Rmat[k][i][j], 30 ); + hCombinedOrientationData->Rmat_fx[k][i][j] = (Word32) float_to_fixed( hCombinedOrientationData->Rmat[k][i][j], 30 ); } } } + + for (i = 0; i < hCombinedOrientationData->num_subframes; i++) + { + hCombinedOrientationData->Quaternions[i].w_qfact = Q_factor_L(hCombinedOrientationData->Quaternions[i].w); + hCombinedOrientationData->Quaternions[i].w_fx = float_to_fix(hCombinedOrientationData->Quaternions[i].w, hCombinedOrientationData->Quaternions[i].w_qfact); + hCombinedOrientationData->Quaternions[i].x_qfact = Q_factor_L(hCombinedOrientationData->Quaternions[i].x); + hCombinedOrientationData->Quaternions[i].x_fx = float_to_fix(hCombinedOrientationData->Quaternions[i].x, hCombinedOrientationData->Quaternions[i].x_qfact); + hCombinedOrientationData->Quaternions[i].y_qfact = Q_factor_L(hCombinedOrientationData->Quaternions[i].y); + hCombinedOrientationData->Quaternions[i].y_fx = float_to_fix(hCombinedOrientationData->Quaternions[i].y, hCombinedOrientationData->Quaternions[i].y_qfact); + hCombinedOrientationData->Quaternions[i].z_qfact = Q_factor_L(hCombinedOrientationData->Quaternions[i].z); + hCombinedOrientationData->Quaternions[i].z_fx = float_to_fix(hCombinedOrientationData->Quaternions[i].z, hCombinedOrientationData->Quaternions[i].z_qfact); + } #endif return IVAS_ERR_OK; } @@ -2127,6 +2155,17 @@ static void external_target_interpolation( hCombinedOrientationData->interpolationIncrement = 1.0f; hCombinedOrientationData->Quaternions[i] = hExtOrientationData->Quaternions[i]; } +#ifdef IVAS_FLOAT_FIXED + /* Updating the fixed point values which will be used later */ + hCombinedOrientationData->Quaternions[i].w_qfact = Q_factor_L(hCombinedOrientationData->Quaternions[i].w); + hCombinedOrientationData->Quaternions[i].w_fx = float_to_fix(hCombinedOrientationData->Quaternions[i].w, hCombinedOrientationData->Quaternions[i].w_qfact); + hCombinedOrientationData->Quaternions[i].x_qfact = Q_factor_L(hCombinedOrientationData->Quaternions[i].x); + hCombinedOrientationData->Quaternions[i].x_fx = float_to_fix(hCombinedOrientationData->Quaternions[i].x, hCombinedOrientationData->Quaternions[i].x_qfact); + hCombinedOrientationData->Quaternions[i].y_qfact = Q_factor_L(hCombinedOrientationData->Quaternions[i].y); + hCombinedOrientationData->Quaternions[i].y_fx = float_to_fix(hCombinedOrientationData->Quaternions[i].y, hCombinedOrientationData->Quaternions[i].y_qfact); + hCombinedOrientationData->Quaternions[i].z_qfact = Q_factor_L(hCombinedOrientationData->Quaternions[i].z); + hCombinedOrientationData->Quaternions[i].z_fx = float_to_fix(hCombinedOrientationData->Quaternions[i].z, hCombinedOrientationData->Quaternions[i].z_qfact); +#endif return; } diff --git a/lib_rend/ivas_sba_rendering.c b/lib_rend/ivas_sba_rendering.c index c4b9891f886c40e8f9b4104e3e5cd371588b8582..bb2a94de2ab2f4e32431d8d4d41e62e6f922927c 100644 --- a/lib_rend/ivas_sba_rendering.c +++ b/lib_rend/ivas_sba_rendering.c @@ -33,6 +33,8 @@ #include #include "options.h" #include "prot.h" +#include "prot_fx1.h" +#include "prot_fx2.h" #include "ivas_prot.h" #include "ivas_prot_rend.h" #include "ivas_stat_dec.h" @@ -46,25 +48,25 @@ * * Render prototype audio signals using SBA mixing matrices *-------------------------------------------------------------------*/ - -void ivas_sba_prototype_renderer( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ - float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ - float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ - const int16_t subframe /* i : Subframe to render */ +void ivas_sba_prototype_renderer_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ + Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ + Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ + Word16 q_cldfb[6][CLDFB_SLOTS_PER_SUBFRAME], + const Word16 subframe /* i : Subframe to render */ ) { - float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + Word32 mixer_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; SPAR_DEC_HANDLE hSpar; DECODER_CONFIG_HANDLE hDecoderConfig; - int16_t num_spar_bands, spar_band; - int16_t b, ts; - int16_t num_cldfb_bands, numch_in, numch_out; - int16_t cldfb_band; - int16_t out_ch, in_ch; - int16_t firstInCh, inChEnd, firstOutCh, outChEnd; - int16_t slot_idx_start, md_idx; - int16_t num_md_sub_frames; + Word16 num_spar_bands, spar_band; + Word16 b, ts; + Word16 num_cldfb_bands, numch_in, numch_out; + Word16 cldfb_band; + Word16 out_ch, in_ch; + Word16 firstInCh, inChEnd, firstOutCh, outChEnd; + Word16 slot_idx_start, md_idx; + Word16 num_md_sub_frames; num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); @@ -79,14 +81,45 @@ void ivas_sba_prototype_renderer( numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; slot_idx_start = hSpar->slots_rendered; - if ( st_ivas->nchan_transport == 1 ) + ///////scaling////////////// + Word16 norm_q = 31; // to handle overflow + + FOR( Word16 i = 0; i < 6; i++ ) + { + FOR( Word16 j = 0; j < CLDFB_SLOTS_PER_SUBFRAME; j++ ) + { + norm_q = s_min( q_cldfb[i][j], norm_q ); + } + } + norm_q = 31 - norm_q - 2; // to handle overflow + Word16 q_inp[6][CLDFB_SLOTS_PER_SUBFRAME]; + FOR( Word16 i = 0; i < 6; i++ ) + { + FOR( Word16 j = 0; j < CLDFB_SLOTS_PER_SUBFRAME; j++ ) + { + q_inp[i][j] = s_min( L_norm_arr( inRe_fx[i][j], CLDFB_NO_CHANNELS_MAX ), L_norm_arr( inIm_fx[i][j], CLDFB_NO_CHANNELS_MAX ) ); + norm_q = s_min( q_inp[i][j], norm_q ); + } + } + FOR( Word16 i = 0; i < 6; i++ ) + { + FOR( Word16 j = 0; j < CLDFB_SLOTS_PER_SUBFRAME; j++ ) + { + // q_inp[i][j] = s_min(L_norm_arr(inRe_fx[i][j], CLDFB_NO_CHANNELS_MAX), L_norm_arr(inIm_fx[i][j], CLDFB_NO_CHANNELS_MAX)); + scale_sig32( inRe_fx[i][j], CLDFB_NO_CHANNELS_MAX, norm_q - 2 ); + scale_sig32( inIm_fx[i][j], CLDFB_NO_CHANNELS_MAX, norm_q - 2 ); + q_cldfb[i][j] = q_cldfb[i][j] + norm_q - 2; + } + } + /////////////////// + IF( st_ivas->nchan_transport == 1 ) { firstInCh = 0; inChEnd = 1; firstOutCh = 0; outChEnd = 1; } - else /* 2 TC */ + ELSE /* 2 TC */ { firstInCh = 0; inChEnd = 2; @@ -95,74 +128,82 @@ void ivas_sba_prototype_renderer( } /* Apply mixing matrix */ - for ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) + FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { - /* determine SPAR parameters for this time slot */ + /* determine SPAR parameters FOR this time slot */ md_idx = hSpar->render_to_md_map[ts + slot_idx_start]; - ivas_spar_get_parameters( hSpar, hDecoderConfig, md_idx, numch_out, numch_in, num_spar_bands, mixer_mat ); + // delete below + floatToFixed_arr( hSpar->hFbMixer->cldfb_cross_fade, hSpar->hFbMixer->cldfb_cross_fade_fx, Q15, CLDFB_NO_COL_MAX ); - for ( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ ) + ivas_spar_get_parameters_fx( hSpar, hDecoderConfig, md_idx, numch_out, numch_in, num_spar_bands, mixer_mat_fx ); + + FOR( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ ) { - float out_re[IVAS_SPAR_MAX_CH]; - float out_im[IVAS_SPAR_MAX_CH]; - float cldfb_par; + Word32 out_re_fx[IVAS_SPAR_MAX_CH]; + Word32 out_im_fx[IVAS_SPAR_MAX_CH]; + Word32 cldfb_par_fx; ivas_fb_bin_to_band_data_t *bin2band = &hSpar->hFbMixer->pFb->fb_bin_to_band; - for ( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ ) + // delete below + FOR( int idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) + { + floatToFixed_arrL( bin2band->pp_cldfb_weights_per_spar_band[idx], bin2band->pp_cldfb_weights_per_spar_band_fx[idx], Q31, IVAS_MAX_NUM_FB_BANDS ); + } + FOR( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ ) { - out_re[out_ch] = 0.0f; - out_im[out_ch] = 0.0f; + out_re_fx[out_ch] = 0; + out_im_fx[out_ch] = 0; - for ( in_ch = firstInCh; in_ch < inChEnd; in_ch++ ) + FOR( in_ch = firstInCh; in_ch < inChEnd; in_ch++ ) { - if ( cldfb_band < CLDFB_PAR_WEIGHT_START_BAND ) /* tuning parameter, depends on how much SPAR Filters overlap for the CLDFB bands */ + IF( cldfb_band < CLDFB_PAR_WEIGHT_START_BAND ) /* tuning parameter, depends on how much SPAR Filters overlap FOR the CLDFB bands */ { spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; - cldfb_par = mixer_mat[out_ch][in_ch][spar_band]; + cldfb_par_fx = mixer_mat_fx[out_ch][in_ch][spar_band]; // q30 } - else + ELSE { - cldfb_par = 0.0f; - for ( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) + cldfb_par_fx = 0; + FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ - cldfb_par += mixer_mat[out_ch][in_ch][spar_band] * bin2band->pp_cldfb_weights_per_spar_band[cldfb_band][spar_band]; + cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ) ); // q30 } } - out_re[out_ch] += inRe[in_ch][ts][cldfb_band] * cldfb_par; - out_im[out_ch] += inIm[in_ch][ts][cldfb_band] * cldfb_par; + out_re_fx[out_ch] = L_add_sat( out_re_fx[out_ch], Mpy_32_32( inRe_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // q30+q_cldfb[i][j]; + out_im_fx[out_ch] = L_add_sat( out_im_fx[out_ch], Mpy_32_32( inIm_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // q30+q_cldfb[i][j } } /*update CLDFB data with the parameter-modified data*/ - for ( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ ) + FOR( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ ) { - inRe[out_ch][ts][cldfb_band] = out_re[out_ch]; - inIm[out_ch][ts][cldfb_band] = out_im[out_ch]; + inRe_fx[out_ch][ts][cldfb_band] = L_shl_sat( out_re_fx[out_ch], 1 ); // q30+q_cldfb[i][j]; + q1 //to keep constat q to entire buffer + inIm_fx[out_ch][ts][cldfb_band] = L_shl_sat( out_im_fx[out_ch], 1 ); } } /* Update mixing matrices */ - if ( ( ( slot_idx_start + ts + 1 ) == hSpar->num_slots ) || ( ( md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME ) != ( hSpar->render_to_md_map[ts + slot_idx_start + 1] / JBM_CLDFB_SLOTS_IN_SUBFRAME ) ) ) + IF( ( ( slot_idx_start + ts + 1 ) == hSpar->num_slots ) || ( ( md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME ) != ( hSpar->render_to_md_map[ts + slot_idx_start + 1] / JBM_CLDFB_SLOTS_IN_SUBFRAME ) ) ) { /* we have crossed an unadapted parameter sf border, update previous mixing matrices */ - int16_t md_sf = md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME; + Word16 md_sf = md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME; md_sf = ( num_md_sub_frames == MAX_PARAM_SPATIAL_SUBFRAMES ) ? md_sf : 0; hSpar->i_subframe++; hSpar->i_subframe = min( hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES ); - mvr2r( hSpar->hMdDec->mixer_mat_prev[1][0][0], hSpar->hMdDec->mixer_mat_prev[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - mvr2r( hSpar->hMdDec->mixer_mat_prev[2][0][0], hSpar->hMdDec->mixer_mat_prev[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - mvr2r( hSpar->hMdDec->mixer_mat_prev[3][0][0], hSpar->hMdDec->mixer_mat_prev[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - mvr2r( hSpar->hMdDec->mixer_mat_prev[4][0][0], hSpar->hMdDec->mixer_mat_prev[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], hSpar->hMdDec->mixer_mat_prev_fx[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[4][0][0], hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - for ( out_ch = 0; out_ch < numch_out; out_ch++ ) + FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) { - for ( in_ch = 0; in_ch < numch_in; in_ch++ ) + FOR( in_ch = 0; in_ch < numch_in; in_ch++ ) { - for ( b = 0; b < num_spar_bands; b++ ) + FOR( b = 0; b < num_spar_bands; b++ ) { - hSpar->hMdDec->mixer_mat_prev[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][b + md_sf * IVAS_MAX_NUM_BANDS]; + hSpar->hMdDec->mixer_mat_prev_fx[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][b + md_sf * IVAS_MAX_NUM_BANDS]; } } } @@ -171,30 +212,31 @@ void ivas_sba_prototype_renderer( /* Create prototypes */ - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) + IF( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) { - for ( ts = 0; ts < hSpar->subframe_nbslots[subframe]; ts++ ) + FOR( ts = 0; ts < hSpar->subframe_nbslots[subframe]; ts++ ) { - if ( st_ivas->nchan_transport == 1 ) /* Dual mono */ + IF( st_ivas->nchan_transport == 1 ) /* Dual mono */ { - mvr2r( inRe[0][ts], inRe[1][ts], CLDFB_NO_CHANNELS_MAX ); - mvr2r( inIm[0][ts], inIm[1][ts], CLDFB_NO_CHANNELS_MAX ); + Copy32( inRe_fx[0][ts], inRe_fx[1][ts], CLDFB_NO_CHANNELS_MAX ); + Copy32( inIm_fx[0][ts], inIm_fx[1][ts], CLDFB_NO_CHANNELS_MAX ); } - else if ( st_ivas->nchan_transport == 2 ) /* Opposing cardioids */ + ELSE IF( st_ivas->nchan_transport == 2 ) /* Opposing cardioids */ { - float temp_signal[CLDFB_NO_CHANNELS_MAX]; - - v_add( inRe[0][ts], inRe[1][ts], temp_signal, CLDFB_NO_CHANNELS_MAX ); - v_sub( inRe[0][ts], inRe[1][ts], inRe[1][ts], CLDFB_NO_CHANNELS_MAX ); - mvr2r( temp_signal, inRe[0][ts], CLDFB_NO_CHANNELS_MAX ); - v_multc( inRe[0][ts], 0.5f, inRe[0][ts], CLDFB_NO_CHANNELS_MAX ); - v_multc( inRe[1][ts], 0.5f, inRe[1][ts], CLDFB_NO_CHANNELS_MAX ); - - v_add( inIm[0][ts], inIm[1][ts], temp_signal, CLDFB_NO_CHANNELS_MAX ); - v_sub( inIm[0][ts], inIm[1][ts], inIm[1][ts], CLDFB_NO_CHANNELS_MAX ); - mvr2r( temp_signal, inIm[0][ts], CLDFB_NO_CHANNELS_MAX ); - v_multc( inIm[0][ts], 0.5f, inIm[0][ts], CLDFB_NO_CHANNELS_MAX ); - v_multc( inIm[1][ts], 0.5f, inIm[1][ts], CLDFB_NO_CHANNELS_MAX ); + Word32 temp_signal_fx[CLDFB_NO_CHANNELS_MAX]; + FOR( int idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) + { + temp_signal_fx[idx] = L_add( L_shr( inRe_fx[0][ts][idx], 1 ), L_shr( inRe_fx[1][ts][idx], 1 ) ); + inRe_fx[1][ts][idx] = L_sub( L_shr( inRe_fx[0][ts][idx], 1 ), L_shr( inRe_fx[1][ts][idx], 1 ) ); + inRe_fx[0][ts][idx] = temp_signal_fx[idx]; + } + + FOR( int idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) + { + temp_signal_fx[idx] = L_add( L_shr( inIm_fx[0][ts][idx], 1 ), L_shr( inIm_fx[1][ts][idx], 1 ) ); + inIm_fx[1][ts][idx] = L_sub( L_shr( inIm_fx[0][ts][idx], 1 ), L_shr( inIm_fx[1][ts][idx], 1 ) ); + inIm_fx[0][ts][idx] = temp_signal_fx[idx]; + } } } } @@ -205,3 +247,163 @@ void ivas_sba_prototype_renderer( return; } + + +void ivas_sba_prototype_renderer( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ + float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ + float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ + const int16_t subframe /* i : Subframe to render */ +) +{ + float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + SPAR_DEC_HANDLE hSpar; + DECODER_CONFIG_HANDLE hDecoderConfig; + int16_t num_spar_bands, spar_band; + int16_t b, ts; + int16_t num_cldfb_bands, numch_in, numch_out; + int16_t cldfb_band; + int16_t out_ch, in_ch; + int16_t firstInCh, inChEnd, firstOutCh, outChEnd; + int16_t slot_idx_start, md_idx; + int16_t num_md_sub_frames; + + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes(st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate); + + push_wmops("ivas_sba_prototype_renderer"); + + hSpar = st_ivas->hSpar; + hDecoderConfig = st_ivas->hDecoderConfig; + num_spar_bands = hSpar->hFbMixer->pFb->filterbank_num_bands; + + num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; + numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + slot_idx_start = hSpar->slots_rendered; + + if (st_ivas->nchan_transport == 1) + { + firstInCh = 0; + inChEnd = 1; + firstOutCh = 0; + outChEnd = 1; + } + else /* 2 TC */ + { + firstInCh = 0; + inChEnd = 2; + firstOutCh = 1; + outChEnd = 2; + } + + /* Apply mixing matrix */ + for (ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++) + { + /* determine SPAR parameters for this time slot */ + md_idx = hSpar->render_to_md_map[ts + slot_idx_start]; + ivas_spar_get_parameters(hSpar, hDecoderConfig, md_idx, numch_out, numch_in, num_spar_bands, mixer_mat); + + for (cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++) + { + float out_re[IVAS_SPAR_MAX_CH]; + float out_im[IVAS_SPAR_MAX_CH]; + float cldfb_par; + ivas_fb_bin_to_band_data_t *bin2band = &hSpar->hFbMixer->pFb->fb_bin_to_band; + + for (out_ch = firstOutCh; out_ch < outChEnd; out_ch++) + { + out_re[out_ch] = 0.0f; + out_im[out_ch] = 0.0f; + + for (in_ch = firstInCh; in_ch < inChEnd; in_ch++) + { + if (cldfb_band < CLDFB_PAR_WEIGHT_START_BAND) /* tuning parameter, depends on how much SPAR Filters overlap for the CLDFB bands */ + { + spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; + cldfb_par = mixer_mat[out_ch][in_ch][spar_band]; + } + else + { + cldfb_par = 0.0f; + for (spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++) + { + /* accumulate contributions from all SPAR bands */ + cldfb_par += mixer_mat[out_ch][in_ch][spar_band] * bin2band->pp_cldfb_weights_per_spar_band[cldfb_band][spar_band]; + } + } + + out_re[out_ch] += inRe[in_ch][ts][cldfb_band] * cldfb_par; + out_im[out_ch] += inIm[in_ch][ts][cldfb_band] * cldfb_par; + } + } + + /*update CLDFB data with the parameter-modified data*/ + for (out_ch = firstOutCh; out_ch < outChEnd; out_ch++) + { + inRe[out_ch][ts][cldfb_band] = out_re[out_ch]; + inIm[out_ch][ts][cldfb_band] = out_im[out_ch]; + } + } + + /* Update mixing matrices */ + if (((slot_idx_start + ts + 1) == hSpar->num_slots) || ((md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME) != (hSpar->render_to_md_map[ts + slot_idx_start + 1] / JBM_CLDFB_SLOTS_IN_SUBFRAME))) + { + /* we have crossed an unadapted parameter sf border, update previous mixing matrices */ + int16_t md_sf = md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME; + md_sf = (num_md_sub_frames == MAX_PARAM_SPATIAL_SUBFRAMES) ? md_sf : 0; + hSpar->i_subframe++; + hSpar->i_subframe = min(hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES); + mvr2r(hSpar->hMdDec->mixer_mat_prev[1][0][0], hSpar->hMdDec->mixer_mat_prev[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS); + mvr2r(hSpar->hMdDec->mixer_mat_prev[2][0][0], hSpar->hMdDec->mixer_mat_prev[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS); + mvr2r(hSpar->hMdDec->mixer_mat_prev[3][0][0], hSpar->hMdDec->mixer_mat_prev[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS); + mvr2r(hSpar->hMdDec->mixer_mat_prev[4][0][0], hSpar->hMdDec->mixer_mat_prev[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS); + + for (out_ch = 0; out_ch < numch_out; out_ch++) + { + for (in_ch = 0; in_ch < numch_in; in_ch++) + { + for (b = 0; b < num_spar_bands; b++) + { + hSpar->hMdDec->mixer_mat_prev[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][b + md_sf * IVAS_MAX_NUM_BANDS]; + } + } + } + } + } + + + /* Create prototypes */ + if (st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM) + { + for (ts = 0; ts < hSpar->subframe_nbslots[subframe]; ts++) + { + if (st_ivas->nchan_transport == 1) /* Dual mono */ + { + mvr2r(inRe[0][ts], inRe[1][ts], CLDFB_NO_CHANNELS_MAX); + mvr2r(inIm[0][ts], inIm[1][ts], CLDFB_NO_CHANNELS_MAX); + } + else if (st_ivas->nchan_transport == 2) /* Opposing cardioids */ + { + float temp_signal[CLDFB_NO_CHANNELS_MAX]; + + v_add(inRe[0][ts], inRe[1][ts], temp_signal, CLDFB_NO_CHANNELS_MAX); + v_sub(inRe[0][ts], inRe[1][ts], inRe[1][ts], CLDFB_NO_CHANNELS_MAX); + mvr2r(temp_signal, inRe[0][ts], CLDFB_NO_CHANNELS_MAX); + v_multc(inRe[0][ts], 0.5f, inRe[0][ts], CLDFB_NO_CHANNELS_MAX); + v_multc(inRe[1][ts], 0.5f, inRe[1][ts], CLDFB_NO_CHANNELS_MAX); + + v_add(inIm[0][ts], inIm[1][ts], temp_signal, CLDFB_NO_CHANNELS_MAX); + v_sub(inIm[0][ts], inIm[1][ts], inIm[1][ts], CLDFB_NO_CHANNELS_MAX); + mvr2r(temp_signal, inIm[0][ts], CLDFB_NO_CHANNELS_MAX); + v_multc(inIm[0][ts], 0.5f, inIm[0][ts], CLDFB_NO_CHANNELS_MAX); + v_multc(inIm[1][ts], 0.5f, inIm[1][ts], CLDFB_NO_CHANNELS_MAX); + } + } + } + + hSpar->subframes_rendered++; + hSpar->slots_rendered += hSpar->subframe_nbslots[subframe]; + pop_wmops(); + + return; +} diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index cc584955c342e08bd9471038c15fdd9a3b8d0d72..3f0ee5e5ab17d2755b84ee04c41fc7e093519c0b 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -269,6 +269,15 @@ typedef struct dirac_dec_stack_mem float *diffuse_power_factor; #ifdef IVAS_FLOAT_FIXED + /*Prototypes*/ + Word32 *proto_direct_buffer_f_fx; + Word32 *proto_diffuse_buffer_f_fx; + + /*Prototype NRGs*/ + Word32 *proto_power_smooth_fx; + Word32 *proto_power_diff_smooth_fx; + + /*Gain or power factors for directional and diffuse streams*/ Word32 *direct_power_factor_fx; Word32 *diffuse_power_factor_fx; #endif @@ -294,6 +303,7 @@ typedef struct dirac_dec_stack_mem float *onset_filter; #ifdef IVAS_FLOAT_FIXED Word32 *reference_power_fx; + Word16 reference_power_q; Word32 *onset_filter_fx; #endif @@ -322,6 +332,7 @@ typedef struct dirac_output_synthesis_params_structure float diffuse_compensation_factor; float diffuse_compensation_factor_decorr; #ifdef IVAS_FLOAT_FIXED + Word32 *proto_matrix_fx; Word32 diffuse_compensation_factor_fx; // Q27 Word32 diffuse_compensation_factor_decorr_fx; // Q29 #endif @@ -385,19 +396,25 @@ typedef struct dirac_output_synthesis_state_structure Word16 direct_power_factor_q; Word16 diffuse_power_factor_q; - Word16 *proto_power_smooth_fx; /* Smoothed power of the prototype signals. Size: num_freq_bands*num_channels. */ + Word32 *proto_power_smooth_fx; /* Smoothed power of the prototype signals. Size: num_freq_bands*num_channels. */ + Word16 proto_power_smooth_q; Word16 *proto_power_smooth_prev_fx; /* Smoothed power of the prototype signals of the previous synthesis block. Size: num_freq_bands*num_channels. */ - Word16 *proto_power_diff_smooth_fx; + Word32 *proto_power_diff_smooth_fx; Word16 *proto_power_diff_smooth_prev_fx; /* only pointer to local buffers */ - Word16 *proto_direct_buffer_f_fx; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ - Word16 *proto_diffuse_buffer_f_fx; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ + Word32 *proto_direct_buffer_f_fx; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ + Word16 proto_direct_buffer_f_q; + Word32 *proto_diffuse_buffer_f_fx; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ + Word16 proto_diffuse_buffer_f_q; /* Output gain memories */ - Word16 *gains_dir_prev_fx; /* Direct sound gains of current synthesis block. Size: num_freq_bands*num_channel. */ - Word16 *gains_diff_prev_fx; /* Diffuse sound gains of previous synthesis block. Size: num_freq_bands*num_channel. */ + Word32 *gains_dir_prev_fx; /* Direct sound gains of current synthesis block. Size: num_freq_bands*num_channel. */ + Word32 *gains_diff_prev_fx; /* Diffuse sound gains of previous synthesis block. Size: num_freq_bands*num_channel. */ + + Word16 gains_dir_prev_q; + Word16 gains_diff_prev_q; /* only pointer to local buffers */ Word32 *cy_auto_dir_smooth_fx; /* Target auto PSD of direct sound. Size: num_freq_bands*num_channels. */ @@ -413,6 +430,10 @@ typedef struct dirac_output_synthesis_state_structure Word32 *cy_cross_dir_smooth_prev_fx; /* Target cross PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */ Word32 *cy_auto_diff_smooth_prev_fx; /* Target auto PSD of diffuse sound of previous synthesis block. Size: num_freq_bands*num_channels. */ + Word16 q_cy_auto_dir_smooth_prev; /* Target auto PSD of direct sound. Size: num_freq_bands*num_channels. */ + Word16 q_cy_cross_dir_smooth_prev; /* Target cross PSD of direct sound. Size: num_freq_bands*num_channels. */ + Word16 q_cy_auto_diff_smooth_prev; /* Target auto PSD of diffuse sound. Size: num_freq_bands*num_channels. */ + const Word16 *onset_filter_fx; /* Temporal smoothing memories */ @@ -491,10 +512,14 @@ typedef struct ivas_mcmasa_lfe_synth_struct float targetEneLfeSmooth; float targetEneTransSmooth; #ifdef IVAS_FLOAT_FIXED - Word16 transportEneSmooth_fx; - Word16 protoLfeEneSmooth_fx; - Word16 targetEneLfeSmooth_fx; - Word16 targetEneTransSmooth_fx; + Word32 transportEneSmooth_fx; + Word16 transportEneSmooth_q; + Word32 protoLfeEneSmooth_fx; + Word16 protoLfeEneSmooth_q; + Word32 targetEneLfeSmooth_fx; + Word16 targetEneLfeSmooth_q; + Word32 targetEneTransSmooth_fx; + Word16 targetEneTransSmooth_q; #endif float *lfeSynthRingBuffer; @@ -559,6 +584,7 @@ typedef struct ivas_dirac_rend_data_structure Word16 *buffer_intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; Word16 *buffer_energy_fx; Word16 *diffuse_response_function_fx; + Word16 diffuse_response_function_q; // Q15 Word16 *frequency_axis_fx; Word32 *hoa_encoder_fx; #endif @@ -590,6 +616,7 @@ typedef struct ivas_dirac_rend_data_structure float *proto_frame_dec_f; #ifdef IVAS_FLOAT_FIXED Word16 *proto_frame_f_fx; + Word16 proto_frame_f_q; Word16 *proto_frame_dec_f_fx; #endif @@ -677,8 +704,10 @@ typedef struct ivas_binaural_reverb_struct float *loopBufImag[CLDFB_NO_CHANNELS_MAX]; float preDelayBufferReal[REVERB_PREDELAY_MAX + 1][CLDFB_NO_CHANNELS_MAX]; float preDelayBufferImag[REVERB_PREDELAY_MAX + 1][CLDFB_NO_CHANNELS_MAX]; +#ifndef IVAS_FLOAT_FIXED float **tapPointersReal[CLDFB_NO_CHANNELS_MAX][BINAURAL_CHANNELS]; float **tapPointersImag[CLDFB_NO_CHANNELS_MAX][BINAURAL_CHANNELS]; +#endif float binauralCoherenceCrossmixGains[CLDFB_NO_CHANNELS_MAX]; float binauralCoherenceDirectGains[CLDFB_NO_CHANNELS_MAX]; @@ -737,6 +766,11 @@ typedef struct ivas_diffuse_distribution_data_structure float diffuseRatioY[CLDFB_NO_CHANNELS_MAX]; float diffuseRatioZ[CLDFB_NO_CHANNELS_MAX]; + Word32 diffuseRatioX_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 diffuseRatioY_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 diffuseRatioZ_fx[CLDFB_NO_CHANNELS_MAX]; + + } DIFFUSE_DISTRIBUTION_DATA, *DIFFUSE_DISTRIBUTION_HANDLE; @@ -771,9 +805,22 @@ typedef struct ivas_dirac_dec_binaural_data_structure float processMtxImPrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; float processMtxDecRePrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float processMtxDecImPrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; +#ifdef IVAS_FLOAT_FIXED + Word16 processMtxRe_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; + Word16 processMtxIm_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; + Word16 processMtxDecRe_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word16 processMtxDecIm_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word16 processMtxRePrev_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; + Word16 processMtxImPrev_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; + Word16 processMtxDecRePrev_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word16 processMtxDecImPrev_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; +#endif uint16_t useTdDecorr; ivas_td_decorr_state_t *hTdDecorr; float reqularizationFactor; +#ifdef IVAS_FLOAT_FIXED + Word16 reqularizationFactor_fx; +#endif DIFFUSE_DISTRIBUTION_HANDLE hDiffuseDist; @@ -993,9 +1040,6 @@ typedef struct ivas_external_orientation_struct int8_t enableRotationInterpolation[MAX_PARAM_SPATIAL_SUBFRAMES]; /* 0 - disable, 1 - enable */ int16_t numFramesToTargetOrientation[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Number of frames until target orientation is reached */ IVAS_QUATERNION Quaternions[MAX_PARAM_SPATIAL_SUBFRAMES]; /* External orientation in quaternions */ -#ifdef IVAS_FLOAT_FIXED - IVAS_QUATERNION Quaternions_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* External orientation in quaternions */ -#endif int16_t num_subframes; } EXTERNAL_ORIENTATION_DATA, *EXTERNAL_ORIENTATION_HANDLE; @@ -1015,7 +1059,6 @@ typedef struct ivas_combined_orientation_struct float lrSwitchInterpVal; bool isInterpolationOngoing; IVAS_QUATERNION Quaternions[MAX_PARAM_SPATIAL_SUBFRAMES]; - IVAS_QUATERNION Quaternions_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; IVAS_QUATERNION Quaternion_prev_extOrientation; IVAS_QUATERNION Quaternions_ext_interpolation_start; IVAS_QUATERNION Quaternions_ext_interpolation_target; @@ -1027,7 +1070,6 @@ typedef struct ivas_combined_orientation_struct float procChEneIIR[2][MASA_FREQUENCY_BANDS]; Word16 shd_rot_max_order; IVAS_VECTOR3 listenerPos[MAX_PARAM_SPATIAL_SUBFRAMES]; - IVAS_VECTOR3 listenerPos_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; IVAS_QUATERNION Quaternion_frozen_ext; IVAS_QUATERNION Quaternion_frozen_head; Word8 isExtOrientationFrozen; @@ -1561,7 +1603,7 @@ typedef struct #ifdef IVAS_FLOAT_FIXED Word32 Pos_fx[3]; - Word32 Pos_q; + Word16 Pos_q; Word32 Front_fx[3]; Word32 Up_fx[3]; Word32 Right_fx[3]; diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 4cfac7946701905681e7c5cd09019a29f4ab587a..c7eb4e35c0b4cf2d466ff8a51054bb921f788f44 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -10889,7 +10889,12 @@ static ivas_error ivas_masa_ext_rend_parambin_init( } #endif /* External renderer uses constant regularization factor */ +#ifdef IVAS_FLOAT_FIXED + hDiracDecBin->reqularizationFactor_fx = 6554; + move16(); +#else hDiracDecBin->reqularizationFactor = 0.4f; +#endif inputMasa->hMasaExtRend->hDiracDecBin = hDiracDecBin;