From 15dd824db4a2644ce2bfc398c61a75ffbd7aabca Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sat, 13 Apr 2024 20:42:56 +0530 Subject: [PATCH 1/3] Float buffer/structure element cleanup and EVS/IVAS crash fixes [x] Few float buffer cleanup [x] ivas_td_binaural_renderer_sf converted to fixed point [x] ivas_jbm_dec_flush_renderer intermediate conv cleanup [x] Issue#728: Fixes crash issue due to incorrect scaling of shaped_shb_excitation_fx [x] TonalMdctConceal_create_concealment_noise_ivas converted to fixed point. --- lib_com/float_to_fix_ops.c | 41 +- lib_com/ivas_cnst.h | 2 +- lib_com/ivas_prot.h | 62 +- lib_com/ivas_prot_fx.h | 2 +- lib_com/tools_fx.c | 2 + lib_dec/LD_music_post_filter.c | 39 +- lib_dec/acelp_core_dec.c | 2 + lib_dec/acelp_core_dec_ivas_fx.c | 65 +- lib_dec/amr_wb_dec.c | 4 +- lib_dec/core_dec_init_fx.c | 3 + lib_dec/core_switching_dec.c | 19 +- lib_dec/dec_tcx.c | 19 +- lib_dec/dec_tcx_fx.c | 5 +- lib_dec/igf_dec.c | 18 +- lib_dec/igf_dec_fx.c | 2 +- lib_dec/init_dec_fx.c | 1 - lib_dec/ivas_core_dec.c | 180 +---- lib_dec/ivas_cpe_dec_fx.c | 18 +- lib_dec/ivas_init_dec.c | 3 + lib_dec/ivas_ism_dec.c | 190 +++++ lib_dec/ivas_ism_renderer.c | 7 + lib_dec/ivas_jbm_dec.c | 961 ++++++++++++++++++++++++- lib_dec/ivas_masa_dec.c | 381 ++++++++++ lib_dec/ivas_mct_dec.c | 228 +++++- lib_dec/ivas_mct_dec_mct.c | 2 + lib_dec/ivas_mdct_core_dec.c | 17 +- lib_dec/ivas_objectRenderer_internal.c | 20 +- lib_dec/ivas_osba_dec.c | 74 ++ lib_dec/ivas_sba_dec.c | 280 ++++++- lib_dec/ivas_sba_dirac_stereo_dec_fx.c | 2 +- lib_dec/ivas_sba_rendering_internal.c | 62 ++ lib_dec/ivas_spar_decoder.c | 96 ++- lib_dec/ivas_stat_dec.h | 6 + lib_dec/ivas_stereo_mdct_core_dec.c | 4 +- lib_dec/ivas_stereo_mdct_core_dec_fx.c | 6 +- lib_dec/ivas_stereo_mdct_stereo_dec.c | 46 +- lib_dec/ivas_stereo_switching_dec.c | 733 +------------------ lib_dec/ivas_td_low_rate_dec.c | 24 - lib_dec/stat_dec.h | 22 +- lib_dec/swb_tbe_dec.c | 2 +- lib_dec/tonalMDCTconcealment.c | 217 ++++++ lib_dec/tonalMDCTconcealment_fx.c | 2 +- lib_rend/ivas_objectRenderer.c | 50 +- lib_rend/ivas_objectRenderer_hrFilt.c | 50 ++ lib_rend/ivas_objectRenderer_mix.c | 9 +- lib_rend/ivas_objectRenderer_sfx.c | 277 ++++++- lib_rend/ivas_objectRenderer_sources.c | 18 + lib_rend/ivas_prot_rend.h | 40 +- lib_rend/ivas_rom_rend.c | 45 ++ lib_rend/ivas_rom_rend.h | 3 + lib_rend/ivas_stat_rend.h | 3 + 51 files changed, 3191 insertions(+), 1173 deletions(-) diff --git a/lib_com/float_to_fix_ops.c b/lib_com/float_to_fix_ops.c index 264f1cd68..74c2cd642 100644 --- a/lib_com/float_to_fix_ops.c +++ b/lib_com/float_to_fix_ops.c @@ -411,21 +411,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( } st->preemph_fac_float = fixedToFloat( st->preemph_fac, 15 ); st->TcxBandwidth_float = fixedToFloat( st->TcxBandwidth, 15 ); - IF( EQ_32( st->sr_core, INT_FS_16k ) ) - { - st->gamma_float = GAMMA16k_FLT; - move16(); - } - ELSE IF( GT_32( st->sr_core, INT_FS_16k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - st->gamma_float = GAMMA16k_FLT; - move16(); - } - ELSE - { - st->gamma_float = GAMMA1_FLT; - move16(); - } + IF( st->hBWE_TD != NULL ) { Q_state_lsyn_filt_shb = Q_factor_arr( hBWE_TD->state_lsyn_filt_shb, 6 ); @@ -870,21 +856,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( } st->preemph_fac_float = fixedToFloat( st->preemph_fac, 15 ); st->TcxBandwidth_float = fixedToFloat( st->TcxBandwidth, 15 ); - IF( EQ_32( st->sr_core, INT_FS_16k ) ) - { - st->gamma_float = GAMMA16k_FLT; - move16(); - } - ELSE IF( GT_32( st->sr_core, INT_FS_16k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - st->gamma_float = GAMMA16k_FLT; - move16(); - } - ELSE - { - st->gamma_float = GAMMA1_FLT; - move16(); - } IF( st->hBWE_TD != NULL ) { Q_state_lsyn_filt_shb = Q_factor_arr( hBWE_TD->state_lsyn_filt_shb, 6 ); @@ -1120,14 +1091,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( st->mem_MA_fx[p] = (Word16) ( st->mem_MA[p] * 2.56 ); st->mem_AR_fx[p] = (Word16) ( st->mem_AR[p] * 2.56 ); } - if ( st->gamma_float == GAMMA1_FLT ) - { - st->inv_gamma = GAMMA1_INV; - } - else if ( st->gamma_float == GAMMA16k_FLT ) - { - st->inv_gamma = GAMMA16k_INV; - } for ( int p = 0; p < 2 * NB_SUBFR16k + 2; p++ ) { @@ -1234,7 +1197,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( } } - st->gamma = float_to_fix16( st->gamma_float, Q15 ); + //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 ); diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index dd9fd1662..fb40d7303 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -71,7 +71,7 @@ #define INV_SQRT2 7.071067811865475e-1f /* 1/sqrt(2) */ #define INV_SQRT3 0.577350269189626f /* 1/sqrt(3) */ -#define INV_SQRT2_FX 1518500224 /* 1/sqrt(2) */ +#define INV_SQRT2_FX 1518500224 /* 1/sqrt(2) in Q31 */ #ifdef IVAS_FLOAT_FIXED #define INV_SQRT2_FX_Q15 23170 /* 1/sqrt(2) Q15*/ diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 557f29054..dbcf4d4b8 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -820,6 +820,19 @@ void ivas_imdft_fx( const Word16 length /* i : signal length */ ); #endif +#ifdef IVAS_FLOAT_FIXED +void TonalMdctConceal_create_concealment_noise_ivas_fx( + Word32 concealment_noise[L_FRAME48k], + Word16 *concealment_noise_exp, + CPE_DEC_HANDLE hCPE, + const Word16 L_frameTCX, + const Word16 L_frame, + const Word16 idchan, + const Word16 subframe_idx, + const Word16 core, + const Word16 crossfade_gain, + const TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode); +#endif void TonalMdctConceal_create_concealment_noise_ivas( float concealment_noise[L_FRAME48k], CPE_DEC_HANDLE hCPE, @@ -887,6 +900,19 @@ ivas_error ivas_jbm_dec_render( uint16_t *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ int16_t *data /* o : output synthesis signal */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_jbm_dec_flush_renderer_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 tc_granularity_new, /* i : new renderer granularity */ + const RENDERER_TYPE renderer_type_old, /* i : old renderer type */ + const AUDIO_CONFIG intern_config_old, /* i : old internal config */ + const IVAS_OUTPUT_SETUP_HANDLE hIntSetupOld, /* i : old internal output setup */ + const MC_MODE mc_mode_old, /* i : old MC mode */ + const ISM_MODE ism_mode_old, /* i : old ISM mode */ + UWord16 *nSamplesRendered, /* o : number of samples flushed */ + Word16 *data /* o : output synthesis signal */ +); +#endif // IVAS_FLOAT_FIXED ivas_error ivas_jbm_dec_flush_renderer( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -4862,6 +4888,16 @@ void ivas_spar_config( int32_t *core_nominal_brate, /* o : core-coding nominal bitrate */ const int16_t sid_format /* i : IVAS format indicator from SID frame */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_sba_linear_renderer_fx( + Word32 *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 nchan_in, /* i : number of input ambisonics channels */ + const Word16 nchan_ism, /* i : number of objects */ + const AUDIO_CONFIG output_config, /* i : output audio configuration */ + const IVAS_OUTPUT_SETUP output_setup /* i : output format setup */ +); +#endif // IVAS_FLOAT_FIXED ivas_error ivas_sba_linear_renderer( float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ @@ -5164,7 +5200,16 @@ void ivas_sba_dec_digest_tc_fx( const Word16 nCldfbSlots, /* i : number of CLDFB slots */ const Word16 nSamplesForRendering /* i : number of samples provided */ ); -#endif +ivas_error ivas_sba_dec_render_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ + Word32 *output_fx[], /* o : rendered time signal */ + Word16 out_len/*Store the length of values in each channel*/ +); +#endif // IVAS_FLOAT_FIXED + ivas_error ivas_sba_dec_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ @@ -5175,8 +5220,9 @@ ivas_error ivas_sba_dec_render( #ifdef IVAS_FLOAT_FIXED void ivas_spar_dec_upmixer_sf_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - float *output[], /* o : output audio channels */ - const Word16 nchan_internal /* i : number of internal channels */ + Word32 *output_fx[], /* o : output audio channels */ + const Word16 nchan_internal, /* i : number of internal channels */ + Word16 out_len ); #endif // IVAS_FLOAT_FIXED @@ -6700,6 +6746,16 @@ void ivas_osba_enc( ivas_error ivas_osba_data_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_osba_dirac_td_binaural_jbm_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + Word32 *output_fx[], /* o : rendered time signal */ + Word16 out_len/*Store the length of values in each channel*/ +); +#endif // IVAS_FLOAT_FIXED ivas_error ivas_osba_dirac_td_binaural_jbm( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index f466200a8..f8a66b487 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1596,7 +1596,7 @@ void ivas_hq_pred_hb_bws_fx( const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ ); -void synchro_synthesis_fixed_clean( +void synchro_synthesis_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *output_fx[CPE_CHANNELS], /* i/o: output synthesis signal */ diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 0b58ff40d..f2cabeb97 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -62,6 +62,8 @@ const Word16 a_hp400_ivas_fx[3] = { 4096, 7320, -3540 };/*Q12*/ Word32 float_to_fix( float number, Word32 Q ) { assert( Q >= 0 ); + if (number == 1.0f && Q == Q31) + return ONE_IN_Q31; assert( fabs( number ) < pow( 2, 31 - Q ) ); Word32 ret = (Word32) ( number * ( (UWord32) 1 << Q ) ); return ret; diff --git a/lib_dec/LD_music_post_filter.c b/lib_dec/LD_music_post_filter.c index 70905877d..19d867a5e 100644 --- a/lib_dec/LD_music_post_filter.c +++ b/lib_dec/LD_music_post_filter.c @@ -70,7 +70,7 @@ static void analy_sp_dct( const float dct_in[], float dct_buf[], float *fr_bands static void find_enr_dct( const float data[], float band[], float *ptE, float *Etot, const int16_t min_band, const int16_t max_band, float *Bin_E, const float bin_freq ); - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*------------------------------------------------------------------------* * LD_music_post_filter() * @@ -358,6 +358,7 @@ void LD_music_post_filter( /* reconstruction of the enhanced synthesis */ mvr2r( DCT_buf, dtc_out, DCT_L_POST ); } +#endif /*---------------------------------------------------------------------------* * spectrum_mod_dct() @@ -733,28 +734,64 @@ void music_postfilt_init_flt( { int16_t i; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( hMusicPF->dct_post_old_exc, 0, DCT_L_POST - OFFSET2 ); +#endif +#ifdef IVAS_FLOAT_FIXED + set_val_Word16( hMusicPF->dct_post_old_exc_fx, 0, DCT_L_POST - OFFSET2 ); +#endif +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hMusicPF->LDm_enh_min_ns_gain = (float) pow( 10.0f, -12 / 20.0f ); +#endif +#ifdef IVAS_FLOAT_FIXED + hMusicPF->LDm_enh_min_ns_gain_fx = (Word16)(0x2027); +#endif hMusicPF->LDm_last_music_flag = 0; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) set_f( hMusicPF->LDm_lt_diff_etot, 0, MAX_LT ); hMusicPF->LDm_thres[0] = TH_0_MIN; hMusicPF->LDm_thres[1] = TH_1_MIN; hMusicPF->LDm_thres[2] = TH_2_MIN; hMusicPF->LDm_thres[3] = TH_3_MIN; +#endif +#ifdef IVAS_FLOAT_FIXED + set_val_Word16( hMusicPF->LDm_lt_diff_etot_fx, 0, MAX_LT ); + hMusicPF->LDm_thres_fx[0] = TH_0_MIN_FX << 1; + hMusicPF->LDm_thres_fx[1] = TH_1_MIN_FX << 1; + hMusicPF->LDm_thres_fx[2] = TH_2_MIN_FX << 1; + hMusicPF->LDm_thres_fx[3] = TH_3_MIN_FX << 1; + +#endif hMusicPF->LDm_nb_thr_1 = 0; hMusicPF->LDm_nb_thr_3 = 0; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hMusicPF->LDm_mem_etot = 0.0f; +#endif +#ifdef IVAS_FLOAT_FIXED + hMusicPF->LDm_mem_etot_fx = 0.0f; +#endif for ( i = 0; i < VOIC_BINS_HR; i++ ) { +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hMusicPF->LDm_enh_lp_gbin[i] = 1.0f; hMusicPF->LDm_enh_lf_EO[i] = 0.01f; +#endif +#ifdef IVAS_FLOAT_FIXED + hMusicPF->LDm_enh_lp_gbin_fx[i] = ONE_IN_Q14; + hMusicPF->LDm_enh_lf_EO_fx[i] = 10; +#endif } for ( i = 0; i < MBANDS_GN_LD; i++ ) { +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) hMusicPF->LDm_bckr_noise[i] = E_MIN; +#endif +#ifdef IVAS_FLOAT_FIXED + hMusicPF->LDm_bckr_noise_fx[i] = E_MIN_Q15; +#endif } set_f( hMusicPF->filt_lfE, 1.0f, DCT_L_POST ); diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index f4de32ffd..053904fdd 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -49,6 +49,7 @@ #include "ivas_rom_com.h" #include "wmc_auto.h" +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * acelp_core_dec() * @@ -1439,3 +1440,4 @@ ivas_error acelp_core_dec( pop_wmops(); return error; } +#endif \ No newline at end of file diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 5ccf31132..d97fcd0c5 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -344,7 +344,6 @@ ivas_error acelp_core_dec_ivas_fx( if ( st->hGSCDec != NULL ) { /* reset the GSC pre echo energy threshold in case of switching */ - //st->hGSCDec->Last_frame_ener = (float) MAX_32; st->hGSCDec->Last_frame_ener_fx = MAX_32; } } @@ -352,7 +351,6 @@ ivas_error acelp_core_dec_ivas_fx( if ( st->hGSCDec != NULL && st->prev_bfi > 0 ) { /* reset the GSC pre echo energy threshold in case of FEC */ - //st->hGSCDec->Last_frame_ener = (float) MAX_32; st->hGSCDec->Last_frame_ener_fx = MAX_32; } @@ -415,16 +413,16 @@ ivas_error acelp_core_dec_ivas_fx( if ( st->L_frame == L_FRAME ) { - st->gamma_float = GAMMA1_FLT; 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; } else { - st->gamma_float = GAMMA16k_FLT; 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; @@ -1222,7 +1220,6 @@ ivas_error acelp_core_dec_ivas_fx( * Apply energy matching when switching to inactive frames *-----------------------------------------------------------------*/ - //inact_switch_ematch( exc2, dct_exc_tmp, st->hGSCDec->lt_ener_per_band, st->coder_type, st->L_frame, st->total_brate, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); Inac_switch_ematch_ivas_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->L_frame, st->total_brate, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); /*------------------------------------------------------------* @@ -1433,7 +1430,6 @@ ivas_error acelp_core_dec_ivas_fx( } /* Apply energy matching when switching to inactive frames */ - //inact_switch_ematch( exc2, dct_exc_tmp, st->hGSCDec->lt_ener_per_band, st->coder_type, st->L_frame, st->total_brate, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); Inac_switch_ematch_ivas_fx(exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->L_frame, st->total_brate, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode); /* update past excitation signals for LD music post-filter */ @@ -3142,21 +3138,6 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte floatToFixed_arr(st->hBWE_TD->old_bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET); } - /*GSC_DEC_HANDLE*/ - if (st->hGSCDec) { - if (st->hGSCDec->Last_frame_ener >= (float)MAX_32) { - st->hGSCDec->Last_frame_ener_fx = MAX_32; - } - else { - st->hGSCDec->Last_frame_ener_fx = floatToFixed(st->hGSCDec->Last_frame_ener, 0); - } - floatToFixed_arr(st->hGSCDec->old_y_gain, st->hGSCDec->old_y_gain_fx, Q12, MBANDS_GN16k); - floatToFixed_arr(st->hGSCDec->lt_ener_per_band, st->hGSCDec->lt_ener_per_band_fx, Q12, MBANDS_GN16k); - floatToFixed_arr(st->hGSCDec->Last_GSC_spectrum, st->hGSCDec->Last_GSC_spectrum_fx, Q10, L_FRAME16k); - floatToFixed_arr(st->hGSCDec->last_exc_dct_in, st->hGSCDec->last_exc_dct_in_fx, st->Q_exc, L_FRAME16k); - // st->hGSCDec->last_ener_fx = float_to_fix16(st->hGSCDec->last_ener, 0); - } - /*TCX_DEC_HANDLE*/ if (st->hTcxDec) { floatToFixed_arr(st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_Overl, 0, L_FRAME32k / 2); @@ -3165,15 +3146,15 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte /*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->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); + //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*/ @@ -3399,16 +3380,6 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte fixedToFloat_arr(st->hBWE_TD->old_bwe_exc_extended_fx, st->hBWE_TD->old_bwe_exc_extended, 0, NL_BUFF_OFFSET); } - /*GSC_DEC_HANDLE*/ - if (st->hGSCDec) { - st->hGSCDec->Last_frame_ener = fixedToFloat(st->hGSCDec->Last_frame_ener_fx, 0); - fixedToFloat_arr(st->hGSCDec->old_y_gain_fx, st->hGSCDec->old_y_gain, Q12, MBANDS_GN16k); - fixedToFloat_arr(st->hGSCDec->lt_ener_per_band_fx, st->hGSCDec->lt_ener_per_band, Q12, MBANDS_GN16k); - fixedToFloat_arr(st->hGSCDec->Last_GSC_spectrum_fx, st->hGSCDec->Last_GSC_spectrum, Q10, L_FRAME16k); - fixedToFloat_arr(st->hGSCDec->last_exc_dct_in_fx, st->hGSCDec->last_exc_dct_in, st->Q_exc, L_FRAME16k); - st->hGSCDec->last_ener = fixedToFloat(st->hGSCDec->last_ener_fx, 0); - } - /*TCX_DEC_HANDLE*/ if (st->hTcxDec) { fixedToFloat_arr(st->hTcxDec->syn_Overl, st->hTcxDec->syn_Overl_float, 0, L_FRAME32k / 2); @@ -3417,15 +3388,15 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte /*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->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); + //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*/ diff --git a/lib_dec/amr_wb_dec.c b/lib_dec/amr_wb_dec.c index 0b046f119..11d7372f0 100644 --- a/lib_dec/amr_wb_dec.c +++ b/lib_dec/amr_wb_dec.c @@ -45,6 +45,8 @@ #ifdef IVAS_FLOAT_FIXED #include "prot_fx2.h" #endif + +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*------------------------------------------------------------------* * amr_wb_dec_flt() * @@ -814,7 +816,7 @@ ivas_error amr_wb_dec_flt( return error; } - +#endif /*------------------------------------------------------------------* * amr_wb_dec_init_flt() diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index 79717cbbc..e4c253c92 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -1217,17 +1217,20 @@ void open_decoder_LPD_ivas_fx( // gamma_float to be removed later st->inv_gamma = GAMMA1_INV; + move16(); IF( EQ_32( st->sr_core, INT_FS_16k ) ) { st->gamma = GAMMA16k; move16(); st->inv_gamma = GAMMA16k_INV; + move16(); } ELSE IF( GT_32( st->sr_core, INT_FS_16k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { st->gamma = GAMMA16k; move16(); st->inv_gamma = GAMMA16k_INV; + move16(); } ELSE { diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c index 0d05192ac..bc4167608 100644 --- a/lib_dec/core_switching_dec.c +++ b/lib_dec/core_switching_dec.c @@ -53,10 +53,11 @@ * Local prototypes *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED +#if !(defined IVAS_FLOAT_FIXED) || (defined EVS_FLOAT) static void core_switch_lb_upsamp( Decoder_State *st, float *output ); static void smoothTransitionDtxToTcx( float synth[], const int16_t output_frame, const int16_t delay_comp ); -#else +#endif +#ifdef IVAS_FLOAT_FIXED static void core_switch_lb_upsamp_fx( Decoder_State *st, Word32 *output ); static void smoothTransitionDtxToTcx_fx( Word32 synth[], const int16_t output_frame, const int16_t delay_comp ); #endif @@ -1207,7 +1208,6 @@ ivas_error core_switching_pre_dec( * * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ - ivas_error core_switching_post_dec( Decoder_State *st, /* i/o: decoder state structure */ float *synth, /* i/o: output synthesis */ @@ -1674,7 +1674,6 @@ ivas_error core_switching_post_dec( return error; } - /*---------------------------------------------------------------------* * core_switching_hq_prepare_dec() * @@ -2171,7 +2170,6 @@ void ivas_bw_switching_pre_proc_fx( } ELSE IF ( ( ( EQ_16( st->core, ACELP_CORE ) && ( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st->core, st->last_core ) && NE_16( st->extl, st->last_extl ) ) ) && GE_16( st->last_bwidth, SWB ) ) { - st->attenu1 = 0.1f; st->attenu_fx = 3277; } @@ -2190,7 +2188,8 @@ void ivas_bw_switching_pre_proc_fx( * Resample HQ/TCX-LB to the output sampling rate (8/16/32/48 kHz) *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED +//#ifdef EVS_FLOAT +#if !(defined IVAS_FLOAT_FIXED) || (defined EVS_FLOAT) static void core_switch_lb_upsamp( Decoder_State *st, /* i/o: Decoder state */ float *output /* i/o: LB synth/upsampled LB synth */ @@ -2258,7 +2257,8 @@ static void core_switch_lb_upsamp( return; } -#else +#endif +#ifdef IVAS_FLOAT_FIXED static void core_switch_lb_upsamp_fx( Decoder_State *st, /* i/o: Decoder state */ Word32 *output /* i/o: LB synth/upsampled LB synth */ @@ -2340,7 +2340,7 @@ static void core_switch_lb_upsamp_fx( #define TRANSITION_SMOOTHING_LEN_32k 31 #define TRANSITION_SMOOTHING_LEN_48k 47 -#ifndef IVAS_FLOAT_FIXED +#if !(defined IVAS_FLOAT_FIXED) || (defined EVS_FLOAT) static void smoothTransitionDtxToTcx( float synth[], /* i/o: synthesis */ const int16_t output_frame, /* i : output frame length */ @@ -2396,7 +2396,8 @@ static void smoothTransitionDtxToTcx( return; } -#else +#endif +#ifdef IVAS_FLOAT_FIXED static void smoothTransitionDtxToTcx_fx( Word32 synth[], /* i/o: synthesis */ const Word16 output_frame, /* i : output frame length */ diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index e8818feac..8c9a9958a 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -51,7 +51,7 @@ #include "debug.h" #endif // !IVAS_FLOAT_FIXED_UNIT_TESTING - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-----------------------------------------------------------------* * decoder_tcx_flt() * @@ -112,7 +112,7 @@ void decoder_tcx_flt( return; } - +#endif /*-------------------------------------------------------------------* * decoder_tcx_post_flt() * @@ -884,7 +884,7 @@ void decoder_tcx_invQ( Word32 x_fx[N_MAX]; Word16 x_e; //st->hTcxCfg->preemph_fac = FL2WORD16(st->hTcxCfg->preemph_fac_flt); - st->inv_gamma = FL2WORD16_SCALE(1 / st->gamma_float, 1); + //st->inv_gamma = FL2WORD16_SCALE(1 / st->gamma_float, 1); tcx_arith_decode_envelope_fx( st, x_fx, &x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, st->last_core_from_bs != ACELP_CORE, prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, ( st->bwidth > WB ) ? 1 : 0 ); for (int k = 0; k < N_MAX; ++k) { @@ -1152,7 +1152,7 @@ void decoder_tcx_invQ( return; } - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * decoder_tcx_noisefilling() * @@ -1452,8 +1452,10 @@ void decoder_tcx_noisefilling( return; } +#endif +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * decoder_tcx_noiseshaping_igf() * @@ -1549,6 +1551,7 @@ void decoder_tcx_noiseshaping_igf( return; } +#endif /*-------------------------------------------------------------------* * decoder_tcx_tns() @@ -1745,7 +1748,7 @@ void decoder_tcx_tns_fx( } #endif - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * decoder_tcx_imdct() * @@ -1990,6 +1993,7 @@ void decoder_tcx_imdct( return; } +#endif #ifdef IVAS_FLOAT_FIXED void decoder_tcx_imdct_fx( @@ -2355,6 +2359,7 @@ void init_tcx_info( } +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * decoder_tcx_IGF_mono() * @@ -2389,8 +2394,9 @@ void decoder_tcx_IGF_mono( return; } +#endif - +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * decoder_tcx_IGF_stereo() * @@ -2457,3 +2463,4 @@ void decoder_tcx_IGF_stereo( return; } +#endif \ No newline at end of file diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index f7390efb4..5c744fd7e 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3498,7 +3498,7 @@ void decoder_tcx_IGF_stereo_fx( } - +#ifdef IVAS_FLOAT_FIXED void decoder_tcx_fx( Decoder_State *st, Word16 prm[], @@ -3603,6 +3603,7 @@ void decoder_tcx_fx( Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, ( st->hHQ_core->Q_old_wtda + 2 ) ); Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, ( st->hHQ_core->Q_old_wtda + 2 ) ); } +#endif /*-------------------------------------------------------------------* * decoder_tcx_invQ_fx @@ -4460,7 +4461,7 @@ void decoder_tcx_noisefilling_fx( tcxGetNoiseFillingTilt( A, M, L_frame, tmp, &noiseTiltFactor ); f2me( hTcxDec->CngLevelBackgroundTrace_bfi, &hTcxDec->CngLevelBackgroundTrace_bfi_fx, &hTcxDec->CngLevelBackgroundTrace_bfi_exp ); - f2me( st->hTonalMDCTConc->curr_noise_nrg_flt, &st->hTonalMDCTConc->curr_noise_nrg, &st->hTonalMDCTConc->curr_noise_nrg_exp ); + //f2me( st->hTonalMDCTConc->curr_noise_nrg_flt, &st->hTonalMDCTConc->curr_noise_nrg, &st->hTonalMDCTConc->curr_noise_nrg_exp ); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && MCT_flag == 0 ) { diff --git a/lib_dec/igf_dec.c b/lib_dec/igf_dec.c index 7428d2260..8a9032b80 100644 --- a/lib_dec/igf_dec.c +++ b/lib_dec/igf_dec.c @@ -1121,7 +1121,7 @@ int16_t IGFDecReadLevel_flt( return IGFAllZero; } - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * IGFDecApplyMono_flt() * @@ -1156,7 +1156,11 @@ void IGFDecApplyMono_flt( nShift = igfGridIdx == IGF_GRID_LB_SHORT ? 2 : 1; set_s( hIGFDec->flag_sparse, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift ); +#ifndef IVAS_FLOAT_FIXED set_f( hIGFDec->virtualSpec_float, 0.f, ( N_MAX_TCX - IGF_START_MN ) / nShift ); +#else + set_val_Word32( hIGFDec->virtualSpec, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift ); +#endif hPrivateData = &hIGFDec->igfData; hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; @@ -1219,8 +1223,9 @@ void IGFDecApplyMono_flt( return; } +#endif - +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * IGFDecApplyStereo_flt() * @@ -1253,8 +1258,13 @@ void IGFDecApplyStereo_flt( nShift = igfGridIdx == IGF_GRID_LB_SHORT ? 2 : 1; set_s( hIGFDecL->flag_sparse, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift ); set_s( hIGFDecR->flag_sparse, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift ); +#ifndef IVAS_FLOAT_FIXED set_f( hIGFDecL->virtualSpec_float, 0.f, ( N_MAX_TCX - IGF_START_MN ) / nShift ); set_f( hIGFDecR->virtualSpec_float, 0.f, ( N_MAX_TCX - IGF_START_MN ) / nShift ); +#else + set_val_Word32( hIGFDecL->virtualSpec, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift ); + set_val_Word32( hIGFDecR->virtualSpec, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift ); +#endif hPrivateDataL = &hIGFDecL->igfData; hGrid = &hPrivateDataL->igfInfo.grid[igfGridIdx]; @@ -1344,7 +1354,7 @@ void IGFDecApplyStereo_flt( return; } - +#endif /*-------------------------------------------------------------------* * IGFDecSetMode_flt() @@ -1459,6 +1469,7 @@ void IGFDecUpdateInfo_flt( } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * IGFDecReplicateTCX10State_flt() * @@ -1481,6 +1492,7 @@ void IGFDecReplicateTCX10State_flt( return; } +#endif /*-------------------------------------------------------------------* diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 3bc13fae3..938e3b780 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -4071,7 +4071,7 @@ void IGFDecReplicateTCX10State_fx( mvc2c( &hIGFDec->infoTCXNoiseBuf[( IGF_START_MX ) / 2], &hIGFDec->infoTCXNoiseBuf[0], ( IGF_START_MX ) / 2 ); /* TODO: remove float dependency */ - mvr2r( &hIGFDec->virtualSpecBuf[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->virtualSpecBuf[0], ( N_MAX_TCX - IGF_START_MN ) / 2 ); + //mvr2r( &hIGFDec->virtualSpecBuf[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->virtualSpecBuf[0], ( N_MAX_TCX - IGF_START_MN ) / 2 ); mvr2r( &hIGFDec->igfData.pSpecFlatBuf[IGF_START_MX / 2], &hIGFDec->igfData.pSpecFlatBuf[0], IGF_START_MX / 2 ); Copy32( &hIGFDec->virtualSpec[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->virtualSpec[0], ( N_MAX_TCX - IGF_START_MN ) / 2 ); diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index b4fcc5591..d5bf467b1 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -1491,7 +1491,6 @@ ivas_error init_decoder_ivas_fx( st_fx->prev_bws_cnt = 0; st_fx->bws_cnt = N_WS2N_FRAMES; st_fx->bws_cnt1 = N_NS2W_FRAMES; - st_fx->attenu1 = 0.1f; } #endif st_fx->tilt_swb_fx = 0; diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 06acc068b..c82783971 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -137,7 +137,6 @@ ivas_error ivas_core_dec( int16_t unbits[CPE_CHANNELS]; int16_t sid_bw[CPE_CHANNELS]; FRAME_MODE frameMode[CPE_CHANNELS]; - float tdm_lspQ_PCh[M], tdm_lsfQ_PCh[M]; int16_t tdm_LRTD_flag; int32_t element_brate, output_Fs; int32_t last_element_brate; @@ -159,6 +158,7 @@ ivas_error ivas_core_dec( Word16 output_16fx[CPE_CHANNELS][L_FRAME48k]; Word16 synth_16fx[CPE_CHANNELS][L_FRAME48k]; Word32 pitch_buf_32fx[CPE_CHANNELS][NB_SUBFR16k]; + Word16 tdm_lsfQ_PCh_fx[M], tdm_lspQ_PCh_fx[M]; #endif #ifdef BASOP_NOGLOB Flag Overflow; @@ -573,10 +573,6 @@ ivas_error ivas_core_dec( 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->hGSCDec ) - { - st->hGSCDec->Last_frame_ener_fx = floatToFixed( st->hGSCDec->Last_frame_ener, 0 ); /*Q-0*/ - } IF( st->hTcxDec ) { Q_FBTCXdelayBuf = Q_factor_arr( st->hTcxDec->FBTCXdelayBuf_float, 111 ); @@ -675,10 +671,6 @@ ivas_error ivas_core_dec( 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->hGSCDec ) - { - st->hGSCDec->Last_frame_ener = fixedToFloat( st->hGSCDec->Last_frame_ener_fx, 0 ); /*Q-0*/ - } IF( st->hTcxDec ) { fixedToFloat_arr( st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl_float, Q_old_syn_Overl, L_FRAME32k / 2 ); @@ -744,7 +736,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], tdm_lspQ_PCh_fx[M], tdm_lsfQ_PCh_fx[M]; + Word16 output_fx[L_FRAME48k], synth_fx[L_FRAME48k], old_syn_12k8_16k_fx[L_FRAME16k], pitch_buf_fx[NB_SUBFR16k]; set_s(output_fx, 0, L_FRAME48k); Word16 save_hb_synth_fx_arr[L_FRAME48k], *save_hb_synth_fx; if (save_hb_synth) { @@ -754,11 +746,7 @@ ivas_error ivas_core_dec( save_hb_synth_fx = NULL; } Word32 bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]; - floatToFixed_arrL(bwe_exc_extended[n], bwe_exc_extended_fx, 0, L_FRAME32k + NL_BUFF_OFFSET); - floatToFixed_arr((float *)tdm_lspQ_PCh, tdm_lspQ_PCh_fx, Q15, M); - for ( i = 0; i < M; i++) { - tdm_lsfQ_PCh_fx[i] = (Word16)(tdm_lsfQ_PCh[i] * 2.56f); - } + /* float2fix, to be removed */ acelp_decoder_state_float2fix(st, hCPE == NULL ? NULL : hCPE->hStereoCng); if (hStereoTD) { @@ -779,11 +767,6 @@ ivas_error ivas_core_dec( 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_arr(tdm_lspQ_PCh_fx, (float *)tdm_lspQ_PCh, Q15, M); - for (i = 0; i < M; i++) - { - tdm_lsfQ_PCh[i] = tdm_lsfQ_PCh_fx[i] / 2.56f; - } #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) { @@ -845,26 +828,12 @@ ivas_error ivas_core_dec( 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_arr( hHQ_core->oldgapsynth, hHQ_core->oldgapsynth_fx, 0, L_FRAME32k ); - //floatToFixed_arr( st->old_Aq_12_8, st->old_Aq_12_8_fx, Q12, M + 1 ); floatToFixed_arrL( st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2 ); - //floatToFixed_arrL( hHQ_core->prev_normq, hHQ_core->prev_normq_fx, Q14, SFM_N_WB ); - //FOR( i = 0; i < SFM_N_WB; ++i ) - //{ - // hHQ_core->prev_env_fx[i] = floatToFixed( hHQ_core->prev_env[i], hHQ_core->prev_env_Q[i] ); - //} - //hHQ_core->energy_lt_fx = floatToFixed( hHQ_core->energy_lt, Q13 ); - //floatToFixed_arr( hHQ_core->prev_noise_level, hHQ_core->prev_noise_level_fx, Q15, 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->prev_ni_ratio_fx = (Word16) floatToFixed( hHQ_core->prev_ni_ratio, Q15 ); - //hHQ_core->mean_prev_nc_fx = floatToFixed( hHQ_core->mean_prev_nc, 0 ); - //hHQ_core->wmold_hb_fx = (Word16) floatToFixed( hHQ_core->wmold_hb, Q15 ); - //hHQ_core->mean_prev_hb_fx = floatToFixed( hHQ_core->mean_prev_hb, 0 ); - //hHQ_core->memfilt_lb_fx = (Word16) floatToFixed( hHQ_core->memfilt_lb, 0 ); 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; @@ -878,27 +847,17 @@ ivas_error ivas_core_dec( 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; - //floatToFixed_arr( hHQ_core->env_stab_state_p, hHQ_core->env_stab_state_p_fx, Q15, NUM_ENV_STAB_PLC_STATES ); 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; - //floatToFixed_arr( hHQ_core->X_sav, hHQ_core->X_sav_fx, hHQ_core->Q_X_sav, PH_ECU_SPEC_SIZE ); hHQ_core->num_p = hHQ_core->num_p; FOR( i = 0; i < MAX_PLOCS; ++i ) { hHQ_core->plocs[i] = hHQ_core->plocs[i]; } - //floatToFixed_arrL( hHQ_core->plocsi, hHQ_core->plocsi_fx, Q16, MAX_PLOCS ); - //hHQ_core->env_stab_fx = (Word16) floatToFixed( hHQ_core->env_stab, 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; - //floatToFixed_arr( hHQ_core->mag_chg_1st, hHQ_core->mag_chg_1st_fx, Q15, LGW_MAX ); - //floatToFixed_arr( hHQ_core->Xavg, hHQ_core->Xavg_fx, 0, LGW_MAX ); - //hHQ_core->mean_prev_fx = floatToFixed(hHQ_core->mean_prev, 0); - //hHQ_core->beta_mute_fx = (Word16) floatToFixed( hHQ_core->beta_mute, Q15 ); - //hHQ_core->env_stab_plc_fx = (Word16) floatToFixed( hHQ_core->env_stab_plc, Q15 ); - floatToFixed_arr( st->t_audio_q, st->t_audio_q_fx, -1, L_FRAME ); #endif ivas_hq_core_dec_fx( st, synth_fx, &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_fx, &Q_output ); @@ -907,30 +866,15 @@ ivas_error ivas_core_dec( fixedToFloat_arr( output_fx, output[n], Q_output, L_FRAME48k ); #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - //hHQ_core->mean_prev = fixedToFloat(hHQ_core->mean_prev_fx, 0); 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_arr( hHQ_core->oldgapsynth_fx, hHQ_core->oldgapsynth, 0, L_FRAME32k ); // Check - //fixedToFloat_arr( st->old_Aq_12_8_fx, st->old_Aq_12_8, Q12, M + 1 ); // Check fixedToFloat_arrL( st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2 ); - //fixedToFloat_arrL( hHQ_core->prev_normq_fx, hHQ_core->prev_normq, Q14, SFM_N_WB ); - //FOR( i = 0; i < SFM_N_WB; ++i ) - //{ - // hHQ_core->prev_env[i] = fixedToFloat( hHQ_core->prev_env_fx[i], hHQ_core->prev_env_Q[i] ); - //} - //hHQ_core->energy_lt = fixedToFloat( hHQ_core->energy_lt_fx, Q13 ); - //fixedToFloat_arr( hHQ_core->prev_noise_level_fx, hHQ_core->prev_noise_level, Q15, 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->prev_ni_ratio = fixedToFloat( hHQ_core->prev_ni_ratio_fx, Q15 ); - //hHQ_core->mean_prev_nc = fixedToFloat( hHQ_core->mean_prev_nc_fx, 0 ); - //hHQ_core->wmold_hb = fixedToFloat( hHQ_core->wmold_hb_fx, Q15 ); - //hHQ_core->mean_prev_hb = fixedToFloat( hHQ_core->mean_prev_hb_fx, 0 ); - //hHQ_core->memfilt_lb = fixedToFloat( hHQ_core->memfilt_lb_fx, 0 ); 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; @@ -944,11 +888,9 @@ ivas_error ivas_core_dec( 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; - //fixedToFloat_arr( hHQ_core->env_stab_state_p_fx, hHQ_core->env_stab_state_p, Q15, NUM_ENV_STAB_PLC_STATES ); 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; - //fixedToFloat_arr( hHQ_core->X_sav_fx, hHQ_core->X_sav, hHQ_core->Q_X_sav, PH_ECU_SPEC_SIZE ); hHQ_core->num_p = hHQ_core->num_p; FOR( i = 0; i < MAX_PLOCS; ++i ) { @@ -959,11 +901,6 @@ ivas_error ivas_core_dec( 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; - //fixedToFloat_arr( hHQ_core->mag_chg_1st_fx, hHQ_core->mag_chg_1st, Q15, LGW_MAX ); - //fixedToFloat_arr( hHQ_core->Xavg_fx, hHQ_core->Xavg, 0, LGW_MAX ); - //hHQ_core->beta_mute = fixedToFloat( hHQ_core->beta_mute_fx, Q15 ); - //hHQ_core->env_stab_plc = fixedToFloat( hHQ_core->env_stab_plc_fx, Q15 ); - fixedToFloat_arr( st->t_audio_q_fx, st->t_audio_q, -1, L_FRAME ); #endif #else hq_core_dec( st, synth[n], output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output[n] ); @@ -978,15 +915,6 @@ 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 */ - Word16 /*lsp_old_PCh_fx[M], */tdm_lspQ_PCh_fx[M]; - Word16 tdm_lsfQ_PCh_fx[M]/*, lsf_old_PCh_fx[M]*/; - FOR( i = 0; i < M; i++ ) - { - //lsp_old_PCh_fx[i] = float_to_fix16( st->lsp_old[i], 15 ); - //lsf_old_PCh_fx[i] = (Word16) ( st->lsf_old[i] * 2.56f ); - tdm_lsfQ_PCh_fx[i] = (Word16) ( tdm_lsfQ_PCh[i] * 2.56f ); - } - float max_val = 0; Word16 tdm_Pri_pitch_buf_fx[NB_SUBFR], old_pitch_buf_fx[2 * NB_SUBFR16k + 2]; @@ -1002,28 +930,14 @@ ivas_error ivas_core_dec( } 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 ); - for ( i = 0; i < M; i++ ) - { - tdm_lspQ_PCh[i] = fix16_to_float( tdm_lspQ_PCh_fx[i], 15 ); - tdm_lsfQ_PCh[i] = (float) tdm_lsfQ_PCh_fx[i] / 2.56f; - } + for ( i = 0; i < NB_SUBFR; i++ ) { hStereoTD->tdm_Pri_pitch_buf[i] = fix16_to_float( tdm_Pri_pitch_buf_fx[i], Q_var ); } -#ifdef DUMPS_ENABLED - dbgwrite_txt( tdm_lspQ_PCh, M, "Fixed_code_tdm_lspQ_PCh.txt", NULL ); - dbgwrite_txt( tdm_lsfQ_PCh, M, "Fixed_code_tdm_lsfQ_PCh.txt", NULL ); - dbgwrite_txt( hStereoTD->tdm_Pri_pitch_buf, NB_SUBFR, "Fixed_code_tdm_Pri_pitch_buf.txt", NULL ); -#endif #else td_stereo_param_updt( st->lsp_old, st->lsf_old, st->old_pitch_buf + st->nb_subfr, tdm_lspQ_PCh, tdm_lsfQ_PCh, hStereoTD->tdm_Pri_pitch_buf, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( tdm_lspQ_PCh, M, "Float_code_tdm_lspQ_PCh.txt", NULL ); - dbgwrite_txt( tdm_lsfQ_PCh, M, "Float_code_tdm_lsfQ_PCh.txt", NULL ); - dbgwrite_txt( hStereoTD->tdm_Pri_pitch_buf, NB_SUBFR, "Float_code_tdm_Pri_pitch_buf.txt", NULL ); -#endif #endif } @@ -1108,8 +1022,8 @@ ivas_error ivas_core_dec( f2me_buf_16( sts[0]->hTcxLtpDec->tcxltp_mem_out_float, sts[0]->hTcxLtpDec->tcxltp_mem_out, &sts[0]->hTcxLtpDec->exp_tcxltp_mem_out, L_FRAME48k ); f2me_buf_16( sts[1]->hTcxLtpDec->tcxltp_mem_out_float, sts[1]->hTcxLtpDec->tcxltp_mem_out, &sts[1]->hTcxLtpDec->exp_tcxltp_mem_out, L_FRAME48k ); - f2me_buf_16( sts[0]->delay_buf_out, sts[0]->delay_buf_out_fx, &sts[0]->exp_delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP ); /*To remove exp component Q0*/ - f2me_buf_16( sts[1]->delay_buf_out, sts[1]->delay_buf_out_fx, &sts[1]->exp_delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP ); + //f2me_buf_16( sts[0]->delay_buf_out, sts[0]->delay_buf_out_fx, &sts[0]->exp_delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP ); /*To remove exp component Q0*/ + //f2me_buf_16( sts[1]->delay_buf_out, sts[1]->delay_buf_out_fx, &sts[1]->exp_delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP ); 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 ); } @@ -1121,7 +1035,7 @@ ivas_error ivas_core_dec( { 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 ); me2f_buf_16( sts[0]->hTcxLtpDec->tcxltp_mem_out, sts[0]->hTcxLtpDec->exp_tcxltp_mem_out, sts[0]->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k ); - me2f_buf_16( sts[0]->delay_buf_out_fx, sts[0]->exp_delay_buf_out, sts[0]->delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP ); /*To remove exp component Q0*/ + //me2f_buf_16( sts[0]->delay_buf_out_fx, sts[0]->exp_delay_buf_out, sts[0]->delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP ); /*To remove exp component Q0*/ me2f_buf_16( sts[0]->hHQ_core->old_out_fx, sts[0]->hHQ_core->exp_old_out, sts[0]->hHQ_core->old_out, L_FRAME48k ); me2f_buf_16( sts[1]->hHQ_core->old_out_fx, sts[1]->hHQ_core->exp_old_out, sts[1]->hHQ_core->old_out, L_FRAME48k ); } @@ -1141,23 +1055,8 @@ ivas_error ivas_core_dec( synth[i][j] = fix16_to_float( synth_fx[i][j], Q_syn ); } } -#ifdef DUMPS_ENABLED - dbgwrite_txt( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, NPART, "sidNoiseEst_FIXED.txt", NULL ); - dbgwrite_txt( sts[0]->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY, "tcxltp_mem_in_FIXED.txt", NULL ); - dbgwrite_txt( sts[0]->delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP, "delay_buf_out_FIXED.txt", NULL ); - dbgwrite_txt( sts[0]->hHQ_core->old_out, L_FRAME48k, "old_out_FIXED.txt", NULL ); - dbgwrite_txt( sts[0]->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k, "tcxltp_mem_out_FIXED.txt", NULL ); -#endif - #else updateBuffersForDmxMdctStereo( hCPE, output_frame, output, synth ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, NPART, "sidNoiseEst_FLOAT.txt", NULL ); - dbgwrite_txt( sts[0]->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY, "tcxltp_mem_in_FLOAT.txt", NULL ); - dbgwrite_txt( sts[0]->delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP, "delay_buf_out_FLOAT.txt", NULL ); - dbgwrite_txt( sts[0]->hHQ_core->old_out, L_FRAME48k, "old_out_FLOAT.txt", NULL ); - dbgwrite_txt( sts[0]->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k, "tcxltp_mem_out_FLOAT.txt", NULL ); -#endif #endif } @@ -1376,7 +1275,7 @@ ivas_error ivas_core_dec( //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); + //floatToFixed_arr(st->delay_buf_out, st->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP); if (st->hTcxDec != NULL) { @@ -1415,7 +1314,7 @@ ivas_error ivas_core_dec( } 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); + //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); @@ -1425,13 +1324,10 @@ ivas_error ivas_core_dec( } Word32 old_syn_12k8_16k_fx[L_FRAME16k]; - Word16 gb, norm, q_audio, old_syn_fx; + 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); - norm = norm_arr_s(st->t_audio_q, L_FRAME); - gb = find_guarded_bits_fx(L_FRAME); - floatToFixed_arr(st->t_audio_q, st->t_audio_q_fx, norm - gb, L_FRAME); - q_audio = norm - gb; + q_audio = Q12; #endif test(); test(); test(); test(); @@ -1485,6 +1381,8 @@ ivas_error ivas_core_dec( ivas_bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx, 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); + #ifdef IVAS_FLOAT_FIXED if (st->last_core == ACELP_CORE && (st->core == TCX_20_CORE || st->core == TCX_10_CORE || st->core == HQ_CORE) && st->hBWE_TD != NULL) { @@ -1516,7 +1414,7 @@ ivas_error ivas_core_dec( //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); + //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); @@ -1546,7 +1444,7 @@ 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); + //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); @@ -1573,10 +1471,6 @@ ivas_error ivas_core_dec( st->hBWE_FD->mem_deemph_old_syn = fixedToFloat(st->hBWE_FD->mem_deemph_old_syn_fx, 0); } - IF(st->bws_cnt == 0 || (st->bws_cnt > 0 && NE_16(st->coder_type, INACTIVE) && NE_16(st->coder_type, AUDIO))) - { - st->attenu1 = fixedToFloat(st->attenu_fx, 15); - } 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)) { @@ -1737,7 +1631,6 @@ ivas_error ivas_core_dec( 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->attenu_fx = (Word16) ( st->attenu1 * ( 1 << 15 ) ); 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 @@ -1968,7 +1861,6 @@ ivas_error ivas_core_dec( 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->attenu1 = (float)st->attenu_fx / (1 << 15); 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); @@ -2389,10 +2281,10 @@ 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)); - } + //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++) @@ -2492,10 +2384,10 @@ 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)); - } + //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++) @@ -2583,10 +2475,10 @@ ivas_error ivas_core_dec( exp_synth_history = Find_Max_Norm16(st->hTcxDec->synth_history_fx + output_frame, 2 * output_frame - NS2SA(st->output_Fs, DELAY_CLDFB_NS) + NS2SA(st->output_Fs, PH_ECU_MEM_NS) - output_frame); exp_synth_history += st->hTcxDec->q_synth_history_fx; - exp_max = min(exp_synth_history, exp_ouput); - exp_max = min(exp_max, exp_prev_synth_buffer); move16(); - exp_max = min(exp_max, exp_old_out); move16(); - exp_max = min(exp_max, exp_delay_buf_out); move16(); + exp_max = s_min(exp_synth_history, exp_ouput); + exp_max = s_min(exp_max, exp_prev_synth_buffer); move16(); + exp_max = s_min(exp_max, exp_old_out); move16(); + exp_max = s_min(exp_max, exp_delay_buf_out); move16(); Copy32(output_fx[n], output_fx_loc, output_frame); @@ -2607,6 +2499,8 @@ ivas_error ivas_core_dec( ivas_updt_dec_common_fx( st, NORMAL_HQ_CORE, -1, output_fx[n], 11 ); + Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), -exp_max ); + #ifdef IVAS_FLOAT_FIXED // TO DO delete below FOR( int ch_ind = 0; ch_ind < n_channels; ch_ind++ ) @@ -2646,10 +2540,10 @@ 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 ); - } + //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++ ) @@ -2747,10 +2641,10 @@ 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 ); - } + //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++) diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index ae246cf6a..8f8c7fee1 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -1037,10 +1037,10 @@ ivas_error ivas_cpe_dec_fx( { hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->prev_synth_buffer[k] * ( 1 << output_q ) ); } - FOR( Word32 k = 0; k < HQ_DELTA_MAX * HQ_DELAY_COMP; k++ ) - { - hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->delay_buf_out[k] * ( 1 << output_q ) ); - } + //FOR( Word32 k = 0; k < HQ_DELTA_MAX * HQ_DELAY_COMP; k++ ) + //{ + // hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->delay_buf_out[k] * ( 1 << output_q ) ); + //} IF( hCPE->hCoreCoder[n]->hTcxDec != NULL ) { FOR( Word32 k = 0; k < 111; k++ ) @@ -1076,7 +1076,7 @@ ivas_error ivas_cpe_dec_fx( } //till here - synchro_synthesis_fixed_clean( ivas_total_brate, hCPE, output, output_frame, 0 ); + synchro_synthesis_fx( ivas_total_brate, hCPE, output, output_frame, 0 ); // delete the below IF( hCPE->hStereoDft != NULL ) @@ -1123,10 +1123,10 @@ ivas_error ivas_cpe_dec_fx( { hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << output_q ); } - FOR( Word32 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 ); - } + //FOR( Word32 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->hCoreCoder[n]->hTcxDec != NULL ) { FOR( Word32 k = 0; k < 111; k++ ) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index e1722348f..f11071055 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -2325,6 +2325,9 @@ ivas_error ivas_init_decoder( /*-----------------------------------------------------------------* * Allocate floating-point output audio buffers *-----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED + st_ivas->p_out_len = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); +#endif // IVAS_FLOAT_FIXED FOR ( n = 0; n < ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ ) { diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index a2ec22d23..6da160102 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -164,10 +164,200 @@ static ivas_error ivas_ism_bitrate_switching_dec( if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) { +#ifdef IVAS_FLOAT_FIXED +#if 1 /*Float to fixed conversion*/ + DECODER_TC_BUFFER_HANDLE hTcBuffer; + hTcBuffer = st_ivas->hTcBuffer; + floatToFixed_arrL( hTcBuffer->tc_buffer, hTcBuffer->tc_buffer_fx, Q11, hTcBuffer->tc_buff_len ); + 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] ) + { + st_ivas->hIsmMetaData[ind1]->azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->azimuth * ( 1 << 22 ) ); + st_ivas->hIsmMetaData[ind1]->elevation_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->elevation * ( 1 << 22 ) ); + } + } + IF( st_ivas->hCombinedOrientationData ) + FOR( Word16 ind1 = 0; ind1 < 3; ind1++ ) + { + FOR( Word16 ind2 = 0; ind2 < 3; ind2++ ) + { + st_ivas->hCombinedOrientationData->Rmat_fx[0][ind1][ind2] = (Word32) ( st_ivas->hCombinedOrientationData->Rmat[0][ind1][ind2] * ( 1 << 15 ) ); + } + } + if ( st_ivas->hMasaIsmData ) + { + for ( Word16 ch_idx = 0; ch_idx < st_ivas->hMasaIsmData->delayBuffer_nchan; ch_idx++ ) + { + floatToFixed_arr32( st_ivas->hMasaIsmData->delayBuffer[ch_idx], st_ivas->hMasaIsmData->delayBuffer_fx[ch_idx], Q11, st_ivas->hMasaIsmData->delayBuffer_size ); + } + } + if ( st_ivas->hSbaIsmData ) + { + for ( Word16 ch_idx = 0; ch_idx < st_ivas->hSbaIsmData->delayBuffer_nchan; ch_idx++ ) + { + floatToFixed_arr32( st_ivas->hSbaIsmData->delayBuffer[ch_idx], st_ivas->hSbaIsmData->delayBuffer_fx[ch_idx], Q11, st_ivas->hSbaIsmData->delayBuffer_size ); + } + } + SPAR_DEC_HANDLE hSpar; + hSpar = st_ivas->hSpar; + uint16_t nchan_internal; + nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + DECODER_CONFIG_HANDLE hDecoderConfig; + hDecoderConfig = st_ivas->hDecoderConfig; + Word16 numch_in, numch_out, num_md_sub_frames, q1 = 30, q2 = 30; + ; + Word16 numch_out_dirac = hDecoderConfig->nchan_out; + IF( hSpar ) + { + numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + + for ( int l = 0; l < numch_out; l++ ) + { + for ( int j = 0; j < numch_in; j++ ) + { + for ( int k = 0; k < num_md_sub_frames * IVAS_MAX_NUM_BANDS; k++ ) + { + hSpar->hMdDec->mixer_mat_fx[l][j][k] = floatToFixed( hSpar->hMdDec->mixer_mat[l][j][k], q1 ); + } + } + } + for ( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + for ( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + for ( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + for ( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] = floatToFixed( hSpar->hMdDec->mixer_mat_prev[m][j][k][l], q2 ); + } + } + } + } + for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] = (Word32) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] * ( 1LL << ( Q11 ) ) ); + } + } + if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) ) + { + for ( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + floatToFixed_arrL( hSpar->hMdDec->smooth_buf[i], hSpar->hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + floatToFixed_arr( hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_fac_fx, Q15, IVAS_MAX_NUM_BANDS ); + } + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] = float_to_fix( st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] ,Q11 ); + } + } + } + } +#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 */ + 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++ ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); /*Rounding off*/ + } + } + FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + FOR( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + FOR( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev[m][j][k][l] = ( (float) hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] / ( 1 << q2 ) ); + } + } + } + } + // fix2float (to be cleaned) + IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) + { + fixedToFloat_arr( hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_fac, Q15, IVAS_MAX_NUM_BANDS ); + FOR( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + fixedToFloat_arrL( hSpar->hMdDec->smooth_buf_fx[i], hSpar->hMdDec->smooth_buf[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + } + // fix2float end + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] ) / (float) ( 1LL << ( Q11 ) ) ); + } + } + } + } + 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] ) + { + st_ivas->hIsmMetaData[ind1]->azimuth = (float) ( st_ivas->hIsmMetaData[ind1]->azimuth_fx ) / (float) ( 1 << 22 ); + st_ivas->hIsmMetaData[ind1]->elevation = (float) ( st_ivas->hIsmMetaData[ind1]->elevation_fx ) / (float) ( 1 << 22 ); + } + } +#endif +#else if ( ( error = ivas_jbm_dec_flush_renderer( 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; } +#endif // IVAS_FLOAT_FIXED } /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ else if ( tc_granularity_new > st_ivas->hTcBuffer->n_samples_granularity ) diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index 67fd9f582..e28b36a69 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -100,6 +100,7 @@ ivas_error ivas_ism_renderer_open( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM renderer interpolator\n" ) ); } + st_ivas->hIsmRendererData->interpolator_len = init_interpolator_length; #endif for ( i = 0; i < interpolator_length; i++ ) @@ -158,6 +159,9 @@ 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 FOR ( i = 0; i < interpolator_length - 1; i++ ) { st_ivas->hIsmRendererData->interpolator_fx[i] = div_s( i, interpolator_length - 1 ); @@ -667,6 +671,9 @@ ivas_error ivas_omasa_separate_object_renderer_open( st_ivas->hIsmRendererData->interpolator_fx = (Word16 *) malloc( sizeof( Word16 ) * init_interpolator_length ); +#if 1 /*TODO: To be removed later: Stores length of interpolator_fx*/ + st_ivas->hIsmRendererData->interpolator_len = init_interpolator_length; +#endif FOR ( i = 0; i < interpolator_length; i++ ) { st_ivas->hIsmRendererData->interpolator_fx[i] = div_s(i, interpolator_length); diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 865f62712..eb93e7a7f 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -4716,10 +4716,134 @@ ivas_error ivas_jbm_dec_render( } else { +#ifdef IVAS_FLOAT_FIXED + for ( n = 0; n < st_ivas->p_out_len; n++ ) + { + floatToFixed_arr32( p_output[n], p_output_fx[n], Q11, 960 ); + } +#if 1 /*Float to fixed conversion*/ + SPAR_DEC_HANDLE hSpar; + hSpar = st_ivas->hSpar; + uint16_t nchan_internal; + nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + Word16 numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + Word16 numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + DECODER_CONFIG_HANDLE hDecoderConfig; + hDecoderConfig = st_ivas->hDecoderConfig; + Word16 numch_out_dirac = hDecoderConfig->nchan_out; + + Word16 num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + + for ( int i = 0; i < s_max( st_ivas->nchan_ism, 0 ) + nchan_internal; i++ ) + { + floatToFixed_arr32( st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->tc_fx[i], Q11, st_ivas->hTcBuffer->n_samples_available ); + } + Word16 q1 = 30, q2 = 30; + for ( int l = 0; l < numch_out; l++ ) + { + for ( int j = 0; j < numch_in; j++ ) + { + for ( int k = 0; k < num_md_sub_frames * IVAS_MAX_NUM_BANDS; k++ ) + { + hSpar->hMdDec->mixer_mat_fx[l][j][k] = floatToFixed( hSpar->hMdDec->mixer_mat[l][j][k], q1 ); + } + } + } + for ( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + for ( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + for ( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + for ( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] = floatToFixed( hSpar->hMdDec->mixer_mat_prev[m][j][k][l], q2 ); + } + } + } + } + for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] = (Word32) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] * ( 1LL << ( Q11 ) ) ); + } + } + if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) ) + { + for ( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + floatToFixed_arrL( hSpar->hMdDec->smooth_buf[i], hSpar->hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + floatToFixed_arr( hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_fac_fx, Q15, IVAS_MAX_NUM_BANDS ); + } + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] = float_to_fix( st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] ,Q11); + } + } + } +#endif // + if ( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx,960) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef IVAS_FLOAT_FIXED /*Fixed to float */ + for ( n = 0; n < st_ivas->p_out_len; n++ ) + { + fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); + } + FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); /*Rounding off*/ + } + } + FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + FOR( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + FOR( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev[m][j][k][l] = ( (float) hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] / ( 1 << q2 ) ); + } + } + } + } + // fix2float (to be cleaned) + IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) + { + fixedToFloat_arr( hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_fac, Q15, IVAS_MAX_NUM_BANDS ); + FOR( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + fixedToFloat_arrL( hSpar->hMdDec->smooth_buf_fx[i], hSpar->hMdDec->smooth_buf[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + } + // fix2float end + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] ) / (float) ( 1LL << ( Q11 ) ) ); + } + } + } +#endif +#else if ( ( error = ivas_sba_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK ) { return error; } +#endif // IVAS_FLOAT_FIXED } } else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) @@ -4754,10 +4878,134 @@ ivas_error ivas_jbm_dec_render( { if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) { +#ifdef IVAS_FLOAT_FIXED + for ( n = 0; n < st_ivas->p_out_len; n++ ) + { + floatToFixed_arr32( p_output[n], p_output_fx[n], 11, 960 ); + } +#if 1 /*Float to fixed conversion*/ + SPAR_DEC_HANDLE hSpar; + hSpar = st_ivas->hSpar; + uint16_t nchan_internal; + nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + Word16 numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + Word16 numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + DECODER_CONFIG_HANDLE hDecoderConfig; + hDecoderConfig = st_ivas->hDecoderConfig; + Word16 numch_out_dirac = hDecoderConfig->nchan_out; + + Word16 num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + + for ( int i = 0; i < s_max( st_ivas->nchan_ism, 0 ) + nchan_internal; i++ ) + { + floatToFixed_arr32( st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->tc_fx[i], Q11, st_ivas->hTcBuffer->n_samples_available ); + } + Word16 q1 = 30, q2 = 30; + for ( int l = 0; l < numch_out; l++ ) + { + for ( int j = 0; j < numch_in; j++ ) + { + for ( int k = 0; k < num_md_sub_frames * IVAS_MAX_NUM_BANDS; k++ ) + { + hSpar->hMdDec->mixer_mat_fx[l][j][k] = floatToFixed( hSpar->hMdDec->mixer_mat[l][j][k], q1 ); + } + } + } + for ( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + for ( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + for ( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + for ( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] = floatToFixed( hSpar->hMdDec->mixer_mat_prev[m][j][k][l], q2 ); + } + } + } + } + for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] = (Word32) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] * ( 1LL << ( Q11 ) ) ); + } + } + if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) ) + { + for ( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + floatToFixed_arrL( hSpar->hMdDec->smooth_buf[i], hSpar->hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + floatToFixed_arr( hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_fac_fx, Q15, IVAS_MAX_NUM_BANDS ); + } + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] = float_to_fix( st_ivas->cldfbSynDec[out_ch]->cldfb_state[i],Q11 ); + } + } + } +#endif // + if ( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx,960) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef IVAS_FLOAT_FIXED /*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 ); + } + FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); + } + } + FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + FOR( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + FOR( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev[m][j][k][l] = ( (float) hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] / ( 1 << q2 ) ); + } + } + } + } + // fix2float (to be cleaned) + IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) + { + fixedToFloat_arr( hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_fac, Q15, IVAS_MAX_NUM_BANDS ); + FOR( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + fixedToFloat_arrL( hSpar->hMdDec->smooth_buf_fx[i], hSpar->hMdDec->smooth_buf[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + } + // fix2float end + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] ) / (float) ( 1LL << ( Q11 ) ) ); + } + } + } +#endif +#else if ( ( error = ivas_osba_dirac_td_binaural_jbm( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK ) { return error; } +#endif } else if ( st_ivas->renderer_type == RENDERER_OSBA_STEREO ) { @@ -4853,46 +5101,416 @@ ivas_error ivas_jbm_dec_render( /* add already rendered SBA part */ for ( n = 0; n < nchan_out; n++ ) { - v_add( p_output[n], p_tc[n + st_ivas->nchan_ism], p_output[n], *nSamplesRendered ); + v_add( p_output[n], p_tc[n + st_ivas->nchan_ism], p_output[n], *nSamplesRendered ); + } + } + else if ( st_ivas->renderer_type == RENDERER_OSBA_AMBI || st_ivas->renderer_type == RENDERER_OSBA_LS || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + { + if ( ( error = ivas_osba_render_sf( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) /*EXT output = individual objects + HOA3*/ + { +#ifdef IVAS_FLOAT_FIXED + for ( n = 0; n < st_ivas->p_out_len; n++ ) + { + floatToFixed_arr32( p_output[n], p_output_fx[n], Q11, 960 ); + } +#if 1 /*Float to fixed conversion*/ + SPAR_DEC_HANDLE hSpar; + hSpar = st_ivas->hSpar; + uint16_t nchan_internal; + nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + Word16 numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + Word16 numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + DECODER_CONFIG_HANDLE hDecoderConfig; + hDecoderConfig = st_ivas->hDecoderConfig; + Word16 numch_out_dirac = hDecoderConfig->nchan_out; + + Word16 num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + + for ( int i = 0; i < s_max( st_ivas->nchan_ism, 0 ) + nchan_internal; i++ ) + { + floatToFixed_arr32( st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->tc_fx[i], Q11, st_ivas->hTcBuffer->n_samples_available ); + } + Word16 q1 = 30, q2 = 30; + for ( int l = 0; l < numch_out; l++ ) + { + for ( int j = 0; j < numch_in; j++ ) + { + for ( int k = 0; k < num_md_sub_frames * IVAS_MAX_NUM_BANDS; k++ ) + { + hSpar->hMdDec->mixer_mat_fx[l][j][k] = floatToFixed( hSpar->hMdDec->mixer_mat[l][j][k], q1 ); + } + } + } + for ( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + for ( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + for ( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + for ( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] = floatToFixed( hSpar->hMdDec->mixer_mat_prev[m][j][k][l], q2 ); + } + } + } + } + for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] = (Word32) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] * ( 1LL << ( Q11 ) ) ); + } + } + if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) ) + { + for ( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + floatToFixed_arrL( hSpar->hMdDec->smooth_buf[i], hSpar->hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + floatToFixed_arr( hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_fac_fx, Q15, IVAS_MAX_NUM_BANDS ); + } + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] = float_to_fix(st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] , Q11 ); + } + } + } +#endif // + if ( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output_fx[st_ivas->nchan_ism], 960) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef IVAS_FLOAT_FIXED /*Fixed to float */ + for ( n = 0; n < st_ivas->p_out_len; n++ ) + { + fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); + } + FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); + } + } + FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + FOR( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + FOR( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev[m][j][k][l] = ( (float) hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] / ( 1 << q2 ) ); + } + } + } + } + // fix2float (to be cleaned) + IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) + { + fixedToFloat_arr( hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_fac, Q15, IVAS_MAX_NUM_BANDS ); + FOR( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + fixedToFloat_arrL( hSpar->hMdDec->smooth_buf_fx[i], hSpar->hMdDec->smooth_buf[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + } + // fix2float end + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] ) / (float) ( 1LL << ( Q11 ) ) ); + } + } + } +#endif +#else + if ( ( error = ivas_sba_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output[st_ivas->nchan_ism] ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif // IVAS_FLOAT_FIXED + + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + mvr2r( st_ivas->hTcBuffer->tc[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output[n], *nSamplesRendered ); + } + } + else + { +#ifdef IVAS_FLOAT_FIXED + for ( n = 0; n < st_ivas->p_out_len; n++ ) + { + floatToFixed_arr32( p_output[n], p_output_fx[n], Q11, 960 ); + } +#if 1 /*Float to fixed conversion*/ + SPAR_DEC_HANDLE hSpar; + hSpar = st_ivas->hSpar; + uint16_t nchan_internal; + nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + Word16 numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + Word16 numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + DECODER_CONFIG_HANDLE hDecoderConfig; + hDecoderConfig = st_ivas->hDecoderConfig; + Word16 numch_out_dirac = hDecoderConfig->nchan_out; + + Word16 num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + + for ( int i = 0; i < s_max( st_ivas->nchan_ism, 0 ) + nchan_internal; i++ ) + { + floatToFixed_arr32( st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->tc_fx[i], Q11, st_ivas->hTcBuffer->n_samples_available ); + } + Word16 q1 = 30, q2 = 30; + for ( int l = 0; l < numch_out; l++ ) + { + for ( int j = 0; j < numch_in; j++ ) + { + for ( int k = 0; k < num_md_sub_frames * IVAS_MAX_NUM_BANDS; k++ ) + { + hSpar->hMdDec->mixer_mat_fx[l][j][k] = floatToFixed( hSpar->hMdDec->mixer_mat[l][j][k], q1 ); + } + } + } + for ( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + for ( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + for ( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + for ( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] = floatToFixed( hSpar->hMdDec->mixer_mat_prev[m][j][k][l], q2 ); + } + } + } + } + for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] = (Word32) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] * ( 1LL << ( Q11 ) ) ); + } + } + if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) ) + { + for ( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + floatToFixed_arrL( hSpar->hMdDec->smooth_buf[i], hSpar->hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + floatToFixed_arr( hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_fac_fx, Q15, IVAS_MAX_NUM_BANDS ); + } + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] = float_to_fix( st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] , Q11 ); + } + } + } +#endif // + if ( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx,960) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef IVAS_FLOAT_FIXED /*Fixed to float */ + for ( n = 0; n < st_ivas->p_out_len; n++ ) + { + fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); + } + FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); /*Rounding off*/ + } + } + FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + FOR( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + FOR( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev[m][j][k][l] = ( (float) hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] / ( 1 << q2 ) ); + } + } + } + } + // fix2float (to be cleaned) + IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) + { + fixedToFloat_arr( hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_fac, Q15, IVAS_MAX_NUM_BANDS ); + FOR( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + fixedToFloat_arrL( hSpar->hMdDec->smooth_buf_fx[i], hSpar->hMdDec->smooth_buf[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + } + // fix2float end + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] ) / (float) ( 1LL << ( Q11 ) ) ); + } + } + } +#endif +#else + if ( ( error = ivas_sba_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif // IVAS_FLOAT_FIXED + } + } + else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) + { + ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); + } + else + { +#ifdef IVAS_FLOAT_FIXED + for ( n = 0; n < st_ivas->p_out_len; n++ ) + { + floatToFixed_arr32( p_output[n], p_output_fx[n], Q11, 960 ); + } +#if 1 /*Float to fixed conversion*/ + SPAR_DEC_HANDLE hSpar; + hSpar = st_ivas->hSpar; + uint16_t nchan_internal; + nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + Word16 numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + Word16 numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + DECODER_CONFIG_HANDLE hDecoderConfig; + hDecoderConfig = st_ivas->hDecoderConfig; + Word16 numch_out_dirac = hDecoderConfig->nchan_out; + + Word16 num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + + for ( int i = 0; i < s_max( st_ivas->nchan_ism, 0 ) + nchan_internal; i++ ) + { + floatToFixed_arr32( st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->tc_fx[i], Q11, st_ivas->hTcBuffer->n_samples_available ); + } + Word16 q1 = 30, q2 = 30; + for ( int l = 0; l < numch_out; l++ ) + { + for ( int j = 0; j < numch_in; j++ ) + { + for ( int k = 0; k < num_md_sub_frames * IVAS_MAX_NUM_BANDS; k++ ) + { + hSpar->hMdDec->mixer_mat_fx[l][j][k] = floatToFixed( hSpar->hMdDec->mixer_mat[l][j][k], q1 ); + } + } + } + for ( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + for ( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + for ( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + for ( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] = floatToFixed( hSpar->hMdDec->mixer_mat_prev[m][j][k][l], q2 ); + } + } + } + } + for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] = (Word32) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] * ( 1LL << ( Q11 ) ) ); + } + } + if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) ) + { + for ( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + floatToFixed_arrL( hSpar->hMdDec->smooth_buf[i], hSpar->hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); } + floatToFixed_arr( hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_fac_fx, Q15, IVAS_MAX_NUM_BANDS ); } - else if ( st_ivas->renderer_type == RENDERER_OSBA_AMBI || st_ivas->renderer_type == RENDERER_OSBA_LS || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) { - if ( ( error = ivas_osba_render_sf( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK ) + IF( st_ivas->cldfbSynDec[out_ch] ) { - return error; + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] = float_to_fix( st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] ,Q11); + } } } - else if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) /*EXT output = individual objects + HOA3*/ +#endif // + if ( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx , 960) ) != IVAS_ERR_OK ) { - if ( ( error = ivas_sba_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output[st_ivas->nchan_ism] ) ) != IVAS_ERR_OK ) + return error; + } +#ifdef IVAS_FLOAT_FIXED /*Fixed to float */ + for ( n = 0; n < st_ivas->p_out_len; n++ ) + { + fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); + } + FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) { - return error; + st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); /*Rounding off*/ } - - for ( n = 0; n < st_ivas->nchan_ism; n++ ) + } + FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) { - mvr2r( st_ivas->hTcBuffer->tc[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output[n], *nSamplesRendered ); + FOR( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + FOR( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev[m][j][k][l] = ( (float) hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] / ( 1 << q2 ) ); + } + } } } - else + IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) { - if ( ( error = ivas_sba_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK ) + fixedToFloat_arr( hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_fac, Q15, IVAS_MAX_NUM_BANDS ); + FOR( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) { - return error; + fixedToFloat_arrL( hSpar->hMdDec->smooth_buf_fx[i], hSpar->hMdDec->smooth_buf[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); } } - } - else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) - { - ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); - } - else - { + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] ) / (float) ( 1LL << ( Q11 ) ) ); + } + } + } +#endif +#else if ( ( error = ivas_sba_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK ) { return error; } +#endif if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) { @@ -5291,6 +5909,305 @@ ivas_error ivas_jbm_dec_render( * * Flush samples if renderer granularity changes on a bitrate change *--------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_jbm_dec_flush_renderer_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 tc_granularity_new, /* i : new renderer granularity */ + const RENDERER_TYPE renderer_type_old, /* i : old renderer type */ + const AUDIO_CONFIG intern_config_old, /* i : old internal config */ + const IVAS_OUTPUT_SETUP_HANDLE hIntSetupOld, /* i : old internal output setup */ + const MC_MODE mc_mode_old, /* i : old MC mode */ + const ISM_MODE ism_mode_old, /* i : old ISM mode */ + UWord16 *nSamplesRendered, /* o : number of samples flushed */ + Word16 *data /* o : output synthesis signal */ +) +{ + ivas_error error; + Word16 n_samples_still_available; + 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; + IF ( !st_ivas->hDecoderConfig->Opt_tsm ) + { + return IVAS_ERR_OK; + } + + *nSamplesRendered = 0; + move16(); + hTcBuffer = st_ivas->hTcBuffer; + + /* get number of possible slots in new granularity */ + n_samples_still_available = sub(hTcBuffer->n_samples_buffered , hTcBuffer->n_samples_rendered); + n_slots_still_available = n_samples_still_available / tc_granularity_new; + *nSamplesRendered = imult1616(n_slots_still_available , tc_granularity_new); + n_samples_to_render = *nSamplesRendered; + move16(); + n_samples_still_available = sub(n_samples_still_available,n_samples_to_render); + assert( n_samples_still_available < tc_granularity_new ); + + /* update combined orientation access index */ + ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData ); + + IF ( n_slots_still_available ) + { + Word16 ch_idx; + + /* render what is still there with zero padding */ + FOR ( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ ) + { + /* move it at the beginning of the TC buffer with zero padding */ + Copy32( hTcBuffer->tc_fx[ch_idx] + hTcBuffer->n_samples_rendered, hTcBuffer->tc_fx[ch_idx], n_samples_to_render ); + set_zero_fx( hTcBuffer->tc_fx[ch_idx] + n_samples_to_render, hTcBuffer->n_samples_granularity - n_samples_to_render ); + Copy32( hTcBuffer->tc_fx[ch_idx] + hTcBuffer->n_samples_rendered + n_samples_to_render, hTcBuffer->tc_fx[ch_idx] + hTcBuffer->n_samples_granularity, n_samples_still_available ); + } + /* simple change of the slot info */ + hTcBuffer->num_slots = 1; + hTcBuffer->nb_subframes = 1; + hTcBuffer->subframes_rendered = 0; + hTcBuffer->slots_rendered = 0; + hTcBuffer->subframe_nbslots[0] = 1; + hTcBuffer->n_samples_buffered = add(hTcBuffer->n_samples_granularity , n_samples_still_available); + hTcBuffer->n_samples_available = 0; + hTcBuffer->n_samples_flushed = n_samples_to_render; +#ifdef CR_FIX_JBM_FLUSH_OFFSET + hTcBuffer->n_samples_rendered = 0; +#else + hTcBuffer->n_samples_rendered = hTcBuffer->n_samples_granularity; +#endif + move16();move16();move16();move16();move16();move16();move16();move16(); + + 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]; + } + + IF ( EQ_16(st_ivas->ivas_format , ISM_FORMAT) ) + { + IF ( EQ_16(ism_mode_old , ISM_MODE_DISC) ) + { + /* 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 + { + return error; + } + } + ELSE IF ( EQ_16(renderer_type_old , RENDERER_BINAURAL_MIXER_CONV_ROOM) ) + { + /*TODO :To be tested : no stream entering---------------------------------------*/ + /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */ + set16_fx( st_ivas->hIsmRendererData->interpolator_fx, 32767, hTcBuffer->n_samples_granularity ); + +#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(); + IF ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, + NULL, NULL, st_ivas->hTcBuffer, p_output_fx, p_output_fx, hTcBuffer->n_samples_granularity, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + ELSE + { + return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong ISM_MODE in VoIP renderer flushing!" ); + } + } + ELSE IF ( EQ_16(st_ivas->ivas_format , MC_FORMAT) ) + { + IF ( EQ_16(mc_mode_old , MC_MODE_MCT) ) + { + IF ( EQ_16(renderer_type_old , RENDERER_BINAURAL_MIXER_CONV) || EQ_16(renderer_type_old , RENDERER_BINAURAL_MIXER_CONV_ROOM) ) + { + /*TODO :To be tested : no stream entering*/ + st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; + IF ( ( error = getAudioConfigNumChannels( intern_config_old, &nchan_in ) ) != IVAS_ERR_OK ) + { + return error; + } + IF ( ( error = getAudioConfigNumChannels( st_ivas->hOutSetup.output_config, &nchan_out ) ) != IVAS_ERR_OK ) + { + return error; + } + *st_ivas->hCrendWrapper->p_io_qfactor = 11; + move16(); + IF ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, intern_config_old, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, + hIntSetupOld, st_ivas->hEFAPdata, st_ivas->hTcBuffer, hTcBuffer->tc_fx, p_output_fx, hTcBuffer->n_samples_granularity, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + + ivas_binaural_add_LFE_fix( st_ivas, hTcBuffer->n_samples_granularity, st_ivas->hTcBuffer->tc_fx, p_output_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 + { + 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 ); + } + } + ELSE + { + return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong MC_MODE in VoIP renderer flushing!" ); + } + } + ELSE IF ( EQ_16(st_ivas->ivas_format , MASA_ISM_FORMAT) || EQ_16(st_ivas->ivas_format , MASA_FORMAT) ) + { + IF ( EQ_16(ism_mode_old , ISM_MASA_MODE_DISC) ) + { + Word32 *tc_local_fx[MAX_TRANSPORT_CHANNELS]; + + Word16 q = Q11; + move16(); + FOR ( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ ) + { + tc_local_fx[ch_idx] = &st_ivas->hTcBuffer->tc_fx[ch_idx + 2][hTcBuffer->n_samples_rendered]; + Copy32( st_ivas->hMasaIsmData->delayBuffer_fx[ch_idx], tc_local_fx[ch_idx], st_ivas->hMasaIsmData->delayBuffer_size );/*Q11*/ + } + + 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 + { + 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 + { + FOR ( ch_idx = 0; ch_idx < st_ivas->hDecoderConfig->nchan_out; ch_idx++ ) + { + set_zero_fx( p_output_fx[ch_idx], (Word16) ( *nSamplesRendered ) ); + } + st_ivas->hTcBuffer->slots_rendered = add(st_ivas->hTcBuffer->slots_rendered,1); + st_ivas->hTcBuffer->subframes_rendered = add(st_ivas->hTcBuffer->subframes_rendered,1); + } + } + } + ELSE IF ( EQ_16(st_ivas->ivas_format , SBA_ISM_FORMAT) ) + { + Word32 *tc_local_fx[MAX_TRANSPORT_CHANNELS]; + Word16 last_spar_md_idx; + Word16 last_dirac_md_idx; + UWord16 nSamplesAvailableNext; + + last_spar_md_idx = st_ivas->hSpar->render_to_md_map[st_ivas->hSpar->slots_rendered - 1]; + last_dirac_md_idx = st_ivas->hSpatParamRendCom->render_to_md_map[st_ivas->hSpatParamRendCom->slots_rendered - 1]; + move16(); + move16(); + /* copy from ISM delay buffer to the correct place in tcs */ + FOR ( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ ) + { + tc_local_fx[ch_idx] = &st_ivas->hTcBuffer->tc_fx[ch_idx + 2][hTcBuffer->n_samples_rendered]; + Copy32( st_ivas->hSbaIsmData->delayBuffer_fx[ch_idx], tc_local_fx[ch_idx], st_ivas->hSbaIsmData->delayBuffer_size ); + } + + /* transfer adapted sf info from hTcBuffer to SPAR and DirAC */ + st_ivas->hSpar->nb_subframes = 1; + st_ivas->hSpar->subframes_rendered = 0; + st_ivas->hSpar->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME; + st_ivas->hSpar->slots_rendered = 0; + st_ivas->hSpar->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME; + st_ivas->hSpatParamRendCom->nb_subframes = 1; + st_ivas->hSpatParamRendCom->subframes_rendered = 0; + st_ivas->hSpatParamRendCom->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME; + st_ivas->hSpatParamRendCom->slots_rendered = 0; + st_ivas->hSpatParamRendCom->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME; + move16();move16();move16();move16();move16();move16();move16();move16();move16();move16(); + + /* also adapt md maps, just use the last index */ + set16_fx( st_ivas->hSpar->render_to_md_map, last_spar_md_idx, n_slots_still_available ); + 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 ) + { + return error; + } + } + ELSE + { + return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong IVAS format in VoIP renderer flushing!" ); + } +#ifdef CR_FIX_JBM_FLUSH_OFFSET + hTcBuffer->n_samples_rendered = hTcBuffer->n_samples_granularity; +#endif + } + + /* update global combined orientation start index */ + ivas_combined_orientation_update_start_index( st_ivas->hCombinedOrientationData, *nSamplesRendered ); + + *nSamplesRendered = n_samples_to_render; + move16(); + /* Only write out the valid data*/ + { + IF ( NE_16(st_ivas->ivas_format , MONO_FORMAT) ) + { +#ifndef DISABLE_LIMITER + Word16 ch_idx,exp=11; + FOR ( ch_idx = 0; ch_idx < MAX_CICP_CHANNELS; ch_idx++ ) + { + p_output_fx[ch_idx] = output_fx[ch_idx]; + } + ivas_limiter_dec_fx( st_ivas->hLimiter, p_output_fx, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered, st_ivas->BER_detect, exp ); +#endif + } + } + + ivas_syn_output_fx( p_output_fx,Q11, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out,data); + return IVAS_ERR_OK; +} +#endif // IVAS_FLOAT_FIXED ivas_error ivas_jbm_dec_flush_renderer( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -6739,6 +7656,7 @@ ivas_error ivas_jbm_dec_tc_buffer_open( } set_zero( hTcBuffer->tc_buffer, nsamp_to_allocate ); #ifdef IVAS_FLOAT_FIXED + hTcBuffer->tc_buff_len = nsamp_to_allocate; IF( ( hTcBuffer->tc_buffer_fx = (Word32 *) malloc( nsamp_to_allocate * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM TC Buffer\n" ) ); @@ -6914,6 +7832,7 @@ ivas_error ivas_jbm_dec_tc_buffer_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM TC Buffer\n" ) ); } + hTcBuffer->tc_buff_len = nsamp_to_allocate; set_zero( hTcBuffer->tc_buffer, nsamp_to_allocate ); #endif IF( ( hTcBuffer->tc_buffer_fx = (Word32 *) malloc( nsamp_to_allocate * sizeof( Word32 ) ) ) == NULL ) @@ -7064,6 +7983,7 @@ ivas_error ivas_jbm_dec_tc_buffer_reconfigure( } set_zero( hTcBuffer->tc_buffer, nsamp_to_allocate ); #ifdef IVAS_FLOAT_FIXED + hTcBuffer->tc_buff_len = nsamp_to_allocate; if ( ( hTcBuffer->tc_buffer_fx = (Word32 *) malloc( nsamp_to_allocate * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM TC Buffer\n" ) ); @@ -7219,6 +8139,7 @@ ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory FOR JBM TC Buffer\n" ) ); } + hTcBuffer->tc_buff_len = nsamp_to_allocate; set_zero( hTcBuffer->tc_buffer, nsamp_to_allocate ); offset = 0; diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 7e505ea3a..c1fd0e2d9 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -3245,10 +3245,200 @@ ivas_error ivas_masa_dec_reconfigure( { if ( n_samples_granularity < st_ivas->hTcBuffer->n_samples_granularity ) { +#ifdef IVAS_FLOAT_FIXED +#if 1 /*Float to fixed conversion*/ + DECODER_TC_BUFFER_HANDLE hTcBuffer; + hTcBuffer = st_ivas->hTcBuffer; + floatToFixed_arrL( hTcBuffer->tc_buffer, hTcBuffer->tc_buffer_fx, Q11, hTcBuffer->tc_buff_len ); + 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] ) + { + st_ivas->hIsmMetaData[ind1]->azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->azimuth * ( 1 << 22 ) ); + st_ivas->hIsmMetaData[ind1]->elevation_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->elevation * ( 1 << 22 ) ); + } + } + IF( st_ivas->hCombinedOrientationData ) + FOR( Word16 ind1 = 0; ind1 < 3; ind1++ ) + { + FOR( Word16 ind2 = 0; ind2 < 3; ind2++ ) + { + st_ivas->hCombinedOrientationData->Rmat_fx[0][ind1][ind2] = (Word32) ( st_ivas->hCombinedOrientationData->Rmat[0][ind1][ind2] * ( 1 << 15 ) ); + } + } + if ( st_ivas->hMasaIsmData ) + { + for ( Word16 ch_idx = 0; ch_idx < st_ivas->hMasaIsmData->delayBuffer_nchan; ch_idx++ ) + { + floatToFixed_arr32( st_ivas->hMasaIsmData->delayBuffer[ch_idx], st_ivas->hMasaIsmData->delayBuffer_fx[ch_idx], Q11, st_ivas->hMasaIsmData->delayBuffer_size ); + } + } + if ( st_ivas->hSbaIsmData ) + { + for ( Word16 ch_idx = 0; ch_idx < st_ivas->hSbaIsmData->delayBuffer_nchan; ch_idx++ ) + { + floatToFixed_arr32( st_ivas->hSbaIsmData->delayBuffer[ch_idx], st_ivas->hSbaIsmData->delayBuffer_fx[ch_idx], Q11, st_ivas->hSbaIsmData->delayBuffer_size ); + } + } + SPAR_DEC_HANDLE hSpar; + hSpar = st_ivas->hSpar; + uint16_t nchan_internal; + nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + DECODER_CONFIG_HANDLE hDecoderConfig; + hDecoderConfig = st_ivas->hDecoderConfig; + Word16 numch_in, numch_out, num_md_sub_frames, q1 = 30, q2 = 30; + ; + Word16 numch_out_dirac = hDecoderConfig->nchan_out; + IF( hSpar ) + { + numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + + for ( int l = 0; l < numch_out; l++ ) + { + for ( int j = 0; j < numch_in; j++ ) + { + for ( int k = 0; k < num_md_sub_frames * IVAS_MAX_NUM_BANDS; k++ ) + { + hSpar->hMdDec->mixer_mat_fx[l][j][k] = floatToFixed( hSpar->hMdDec->mixer_mat[l][j][k], q1 ); + } + } + } + for ( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + for ( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + for ( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + for ( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] = floatToFixed( hSpar->hMdDec->mixer_mat_prev[m][j][k][l], q2 ); + } + } + } + } + for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] = (Word32) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] * ( 1LL << ( Q11 ) ) ); + } + } + if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) ) + { + for ( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + floatToFixed_arrL( hSpar->hMdDec->smooth_buf[i], hSpar->hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + floatToFixed_arr( hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_fac_fx, Q15, IVAS_MAX_NUM_BANDS ); + } + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] = float_to_fix( st_ivas->cldfbSynDec[out_ch]->cldfb_state[i], Q11 ); + } + } + } + } +#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 */ + 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++ ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); + } + } + FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + FOR( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + FOR( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev[m][j][k][l] = ( (float) hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] / ( 1 << q2 ) ); + } + } + } + } + // fix2float (to be cleaned) + IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) + { + fixedToFloat_arr( hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_fac, Q15, IVAS_MAX_NUM_BANDS ); + FOR( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + fixedToFloat_arrL( hSpar->hMdDec->smooth_buf_fx[i], hSpar->hMdDec->smooth_buf[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + } + // fix2float end + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] ) / (float) ( 1LL << ( Q11 ) ) ); /*Rounding off*/ + } + } + } + } + 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] ) + { + st_ivas->hIsmMetaData[ind1]->azimuth = (float) ( st_ivas->hIsmMetaData[ind1]->azimuth_fx ) / (float) ( 1 << 22 ); + st_ivas->hIsmMetaData[ind1]->elevation = (float) ( st_ivas->hIsmMetaData[ind1]->elevation_fx ) / (float) ( 1 << 22 ); + } + } +#endif +#else if ( ( error = ivas_jbm_dec_flush_renderer( 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; } +#endif // IVAS_FLOAT_FIXED } } } @@ -3590,10 +3780,201 @@ ivas_error ivas_masa_dec_reconfigure_fx( { IF( LT_16( n_samples_granularity, st_ivas->hTcBuffer->n_samples_granularity ) ) { +#ifdef IVAS_FLOAT_FIXED +#if 1 /*Float to fixed conversion*/ + DECODER_TC_BUFFER_HANDLE hTcBuffer; + hTcBuffer = st_ivas->hTcBuffer; + floatToFixed_arrL( hTcBuffer->tc_buffer, hTcBuffer->tc_buffer_fx, Q11, hTcBuffer->tc_buff_len ); + 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] ) + { + st_ivas->hIsmMetaData[ind1]->azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->azimuth * ( 1 << 22 ) ); + st_ivas->hIsmMetaData[ind1]->elevation_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->elevation * ( 1 << 22 ) ); + } + } + IF( st_ivas->hCombinedOrientationData ) + FOR( Word16 ind1 = 0; ind1 < 3; ind1++ ) + { + FOR( Word16 ind2 = 0; ind2 < 3; ind2++ ) + { + st_ivas->hCombinedOrientationData->Rmat_fx[0][ind1][ind2] = (Word32) ( st_ivas->hCombinedOrientationData->Rmat[0][ind1][ind2] * ( 1 << 15 ) ); + } + } + if ( st_ivas->hMasaIsmData ) + { + for ( Word16 ch_idx = 0; ch_idx < st_ivas->hMasaIsmData->delayBuffer_nchan; ch_idx++ ) + { + floatToFixed_arr32( st_ivas->hMasaIsmData->delayBuffer[ch_idx], st_ivas->hMasaIsmData->delayBuffer_fx[ch_idx], Q11, st_ivas->hMasaIsmData->delayBuffer_size ); + } + } + if ( st_ivas->hSbaIsmData ) + { + for ( Word16 ch_idx = 0; ch_idx < st_ivas->hSbaIsmData->delayBuffer_nchan; ch_idx++ ) + { + floatToFixed_arr32( st_ivas->hSbaIsmData->delayBuffer[ch_idx], st_ivas->hSbaIsmData->delayBuffer_fx[ch_idx], Q11, st_ivas->hSbaIsmData->delayBuffer_size ); + } + } + SPAR_DEC_HANDLE hSpar; + hSpar = st_ivas->hSpar; + uint16_t nchan_internal; + nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + DECODER_CONFIG_HANDLE hDecoderConfig; + hDecoderConfig = st_ivas->hDecoderConfig; + Word16 numch_in, numch_out, num_md_sub_frames, q1 = 30, q2 = 30; + ; + Word16 numch_out_dirac = hDecoderConfig->nchan_out; + IF( hSpar ) + { + numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + + for ( int l = 0; l < numch_out; l++ ) + { + for ( int j = 0; j < numch_in; j++ ) + { + for ( int k = 0; k < num_md_sub_frames * IVAS_MAX_NUM_BANDS; k++ ) + { + hSpar->hMdDec->mixer_mat_fx[l][j][k] = floatToFixed( hSpar->hMdDec->mixer_mat[l][j][k], q1 ); + } + } + } + for ( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + for ( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + for ( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + for ( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] = floatToFixed( hSpar->hMdDec->mixer_mat_prev[m][j][k][l], q2 ); + } + } + } + } + for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] = (Word32) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] * ( 1LL << ( Q11 ) ) ); + } + } + if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) ) + { + for ( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + floatToFixed_arrL( hSpar->hMdDec->smooth_buf[i], hSpar->hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + floatToFixed_arr( hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_fac_fx, Q15, IVAS_MAX_NUM_BANDS ); + } + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] = float_to_fix ( st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] ,Q11 ); + } + } + } + } +#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 */ + 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++ ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); /*Rounding off*/ + } + } + FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + FOR( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + FOR( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev[m][j][k][l] = ( (float) hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] / ( 1 << q2 ) ); + } + } + } + } + // fix2float (to be cleaned) + IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) + { + fixedToFloat_arr( hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_fac, Q15, IVAS_MAX_NUM_BANDS ); + FOR( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + fixedToFloat_arrL( hSpar->hMdDec->smooth_buf_fx[i], hSpar->hMdDec->smooth_buf[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + } + // fix2float end + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] ) / (float) ( 1LL << ( Q11 ) ) ); + } + } + } + } + + 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] ) + { + st_ivas->hIsmMetaData[ind1]->azimuth = (float) ( st_ivas->hIsmMetaData[ind1]->azimuth_fx ) / (float) ( 1 << 22 ); + st_ivas->hIsmMetaData[ind1]->elevation = (float) ( st_ivas->hIsmMetaData[ind1]->elevation_fx ) / (float) ( 1 << 22 ); + } + } +#endif +#else IF( ( error = ivas_jbm_dec_flush_renderer( 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; } +#endif } } } diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 0d365e837..82e87a314 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -886,14 +886,11 @@ ivas_error ivas_mct_dec( IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) { - sts[ch]->gamma = (Word16)floatToFixed( sts[ch]->gamma_float, Q15 ); + //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]->stab_fac_fx = (Word16)floatToFixed( sts[ch]->stab_fac, Q15 ); - //sts[ch]->hTcxCfg->na_scale = (Word16)floatToFixed( sts[ch]->hTcxCfg->na_scale_flt, Q15 ); - //sts[ch]->hTcxCfg->sq_rounding = (Word16)floatToFixed( sts[ch]->hTcxCfg->sq_rounding_flt, Q15 ); 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]->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 ); @@ -1155,7 +1152,7 @@ ivas_error ivas_mct_dec( 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 ); + //sts[ch]->stab_fac = fix16_to_float( sts[ch]->stab_fac_fx, Q15 ); // 16bit to u8bit FOR( l = 0; l < IGF_START_MX; l++ ) { @@ -1251,7 +1248,7 @@ ivas_error ivas_mct_dec( 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); + //floatToFixed_arrL(hCPE->hCoreCoder[n]->delay_buf_out, hCPE->hCoreCoder[n]->delay_buf_out32_fx, Q11, HQ_DELTA_MAX * HQ_DELAY_COMP); @@ -1304,7 +1301,7 @@ ivas_error ivas_mct_dec( //floatToFixed_arrL(sts[n]->hHQ_core->prev_normq, sts[n]->hHQ_core->prev_normq_fx, 14, SFM_N_WB); } 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); + //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) { @@ -1334,16 +1331,18 @@ ivas_error ivas_mct_dec( /*-------------------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); + //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) { floatToFixed_arr(sts[n]->hWIDec->old_exc2, sts[n]->hWIDec->old_exc2_fx, sts[n]->Q_exc, L_EXC_MEM); } +#ifndef IVAS_FLOAT_FIXED if (sts[n]->hMusicPF != NULL) { 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); @@ -1456,7 +1455,7 @@ ivas_error ivas_mct_dec( /* synthesis synchronization between stereo modes */ IF ( EQ_16(st_ivas->sba_dirac_stereo_flag, 0) || ( EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT) && LE_16(cpe_id, sub(nCPE, 2)) ) ) { - synchro_synthesis_fixed_clean( ivas_total_brate, hCPE, output_fx + cpe_id * CPE_CHANNELS, output_frame, 0 ); + synchro_synthesis_fx( ivas_total_brate, hCPE, output_fx + cpe_id * CPE_CHANNELS, output_frame, 0 ); } #ifndef IVAS_CODE_TO_BE_REMOVED @@ -1467,11 +1466,13 @@ ivas_error ivas_mct_dec( 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); + //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); @@ -1526,10 +1527,6 @@ ivas_error ivas_mct_dec( sts[n]->hBWE_FD->mem_deemph_old_syn = fixedToFloat(sts[n]->hBWE_FD->mem_deemph_old_syn_fx, 0); } - IF(sts[n]->bws_cnt == 0 || (sts[n]->bws_cnt > 0 && NE_16(sts[n]->coder_type, INACTIVE) && NE_16(sts[n]->coder_type, AUDIO))) - { - sts[n]->attenu1 = fixedToFloat(sts[n]->attenu_fx, 15); - } 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)) { @@ -1714,10 +1711,10 @@ ivas_error ivas_mct_dec( { 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 ); - } + //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 ) { @@ -2468,10 +2465,201 @@ static ivas_error ivas_mc_dec_reconfig( #endif if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) { +#ifdef IVAS_FLOAT_FIXED +#if 1 /*Float to fixed conversion*/ + DECODER_TC_BUFFER_HANDLE hTcBuffer; + hTcBuffer = st_ivas->hTcBuffer; + floatToFixed_arrL( hTcBuffer->tc_buffer, hTcBuffer->tc_buffer_fx, Q11, hTcBuffer->tc_buff_len ); + 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] ) + { + st_ivas->hIsmMetaData[ind1]->azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->azimuth * ( 1 << 22 ) ); + st_ivas->hIsmMetaData[ind1]->elevation_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->elevation * ( 1 << 22 ) ); + } + } + IF( st_ivas->hCombinedOrientationData ) + FOR( Word16 ind1 = 0; ind1 < 3; ind1++ ) + { + FOR( Word16 ind2 = 0; ind2 < 3; ind2++ ) + { + st_ivas->hCombinedOrientationData->Rmat_fx[0][ind1][ind2] = (Word32) ( st_ivas->hCombinedOrientationData->Rmat[0][ind1][ind2] * ( 1 << 15 ) ); + } + } + if ( st_ivas->hMasaIsmData ) + { + for ( Word16 ch_idx = 0; ch_idx < st_ivas->hMasaIsmData->delayBuffer_nchan; ch_idx++ ) + { + floatToFixed_arr32( st_ivas->hMasaIsmData->delayBuffer[ch_idx], st_ivas->hMasaIsmData->delayBuffer_fx[ch_idx], Q11, st_ivas->hMasaIsmData->delayBuffer_size ); + } + } + if ( st_ivas->hSbaIsmData ) + { + for ( Word16 ch_idx = 0; ch_idx < st_ivas->hSbaIsmData->delayBuffer_nchan; ch_idx++ ) + { + floatToFixed_arr32( st_ivas->hSbaIsmData->delayBuffer[ch_idx], st_ivas->hSbaIsmData->delayBuffer_fx[ch_idx], Q11, st_ivas->hSbaIsmData->delayBuffer_size ); + } + } + SPAR_DEC_HANDLE hSpar; + hSpar = st_ivas->hSpar; + uint16_t nchan_internal; + nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + DECODER_CONFIG_HANDLE hDecoderConfig; + hDecoderConfig = st_ivas->hDecoderConfig; + Word16 numch_in, numch_out, num_md_sub_frames, q1 = 30, q2 = 30; + ; + Word16 numch_out_dirac = hDecoderConfig->nchan_out; + IF( hSpar ) + { + numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + + for ( int l = 0; l < numch_out; l++ ) + { + for ( int j = 0; j < numch_in; j++ ) + { + for ( int k = 0; k < num_md_sub_frames * IVAS_MAX_NUM_BANDS; k++ ) + { + hSpar->hMdDec->mixer_mat_fx[l][j][k] = floatToFixed( hSpar->hMdDec->mixer_mat[l][j][k], q1 ); + } + } + } + for ( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + for ( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + for ( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + for ( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] = floatToFixed( hSpar->hMdDec->mixer_mat_prev[m][j][k][l], q2 ); + } + } + } + } + for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] = (Word32) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] * ( 1LL << ( Q11 ) ) ); + } + } + if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) ) + { + for ( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + floatToFixed_arrL( hSpar->hMdDec->smooth_buf[i], hSpar->hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + floatToFixed_arr( hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_fac_fx, Q15, IVAS_MAX_NUM_BANDS ); + } + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] = float_to_fix( st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] , Q11 ); + } + } + } + } +#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 */ + 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++ ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); + } + } + FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + FOR( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + FOR( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev[m][j][k][l] = ( (float) hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] / ( 1 << q2 ) ); + } + } + } + } + // fix2float (to be cleaned) + IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) + { + fixedToFloat_arr( hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_fac, Q15, IVAS_MAX_NUM_BANDS ); + FOR( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + fixedToFloat_arrL( hSpar->hMdDec->smooth_buf_fx[i], hSpar->hMdDec->smooth_buf[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + } + // fix2float end + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] ) / (float) ( 1LL << ( Q11 ) ) ); + } + } + } + } + + 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] ) + { + st_ivas->hIsmMetaData[ind1]->azimuth = (float) ( st_ivas->hIsmMetaData[ind1]->azimuth_fx ) / (float) ( 1 << 22 ); + st_ivas->hIsmMetaData[ind1]->elevation = (float) ( st_ivas->hIsmMetaData[ind1]->elevation_fx ) / (float) ( 1 << 22 ); + } + } +#endif +#else if ( ( error = ivas_jbm_dec_flush_renderer( 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; } +#endif // IVAS_FLOAT_FIXED } /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ else if ( tc_granularity_new > st_ivas->hTcBuffer->n_samples_granularity ) diff --git a/lib_dec/ivas_mct_dec_mct.c b/lib_dec/ivas_mct_dec_mct.c index da2510c6f..6b503420a 100644 --- a/lib_dec/ivas_mct_dec_mct.c +++ b/lib_dec/ivas_mct_dec_mct.c @@ -227,6 +227,7 @@ void apply_MCT_dec( return; } +#ifndef IVAS_FLOAT_FIXED /*----------------------------------------------------------* * mctStereoIGF_dec() * @@ -336,3 +337,4 @@ void mctStereoIGF_dec( return; } +#endif diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 5805a819b..0101c5e49 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -1320,16 +1320,7 @@ void ivas_mdct_core_invQ_fx( test(); IF( bfi && !MCT_flag ) { -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - st->hTcxDec->cummulative_damping_tcx_float = fix16_to_float( st->hTcxDec->cummulative_damping_tcx, Q15 ); -#endif - 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 ); -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - // Float to fix. Temp or PLC - concealment_noise_len[ch] = get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ); - f2me_buf( concealment_noise[ch], concealment_noise_fx[ch], &concealment_noise_e[ch], concealment_noise_len[ch] ); - st->hTcxDec->cummulative_damping_tcx = float_to_fix16( st->hTcxDec->cummulative_damping_tcx_float, Q15 ); -#endif + TonalMdctConceal_create_concealment_noise_ivas_fx( concealment_noise_fx[ch], &concealment_noise_e[ch], hCPE, L_frameTCX[ch], L_frame[ch], ch, k, st->core, st->hTcxDec->cummulative_damping_tcx, noise_gen_mode_bfi ); } decoder_tcx_noisefilling_fx( st, concealment_noise_fx[ch], concealment_noise_e[ch], Aq[ch], L_frameTCX_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x[ch][k], &x_e[ch][k], NULL, NULL, &tmp_concealment_method, gain_tcx, gain_tcx_e, prm_sqQ, nf_seed, bfi, MCT_flag, k ); @@ -1736,12 +1727,12 @@ void ivas_mdct_core_invQ( 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->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); + //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); @@ -1976,10 +1967,12 @@ void ivas_mdct_core_reconstruct( } 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++ ) { diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index fc1e6de4e..5430837c0 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -683,10 +683,28 @@ ivas_error ivas_td_binaural_renderer_sf_fx( /* 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 - if ( ( error = TDREND_GetMix_fx( st_ivas->hBinRendererTd, output_f_local, output_frame, 0, ism_md_subframe_update_jbm != subframe_idx ) ) != IVAS_ERR_OK ) + ////// 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 ) { diff --git a/lib_dec/ivas_osba_dec.c b/lib_dec/ivas_osba_dec.c index 9e1b817a9..98f3beee0 100644 --- a/lib_dec/ivas_osba_dec.c +++ b/lib_dec/ivas_osba_dec.c @@ -39,6 +39,9 @@ #include "ivas_rom_com.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx2.h" +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -62,6 +65,12 @@ ivas_error ivas_osba_data_open( hSbaIsmData->delayBuffer_nchan = st_ivas->nchan_ism; hSbaIsmData->delayBuffer_size = (int16_t) ( ( st_ivas->hDecoderConfig->output_Fs / 50 ) / MAX_PARAM_SPATIAL_SUBFRAMES ); +#ifdef IVAS_FLOAT_FIXED + if ( ( hSbaIsmData->delayBuffer_fx = (Word32 **) malloc( hSbaIsmData->delayBuffer_nchan * sizeof(Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for OSBA delay buffer \n" ) ); + } +#endif if ( ( hSbaIsmData->delayBuffer = (float **) malloc( hSbaIsmData->delayBuffer_nchan * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for OSBA delay buffer \n" ) ); @@ -69,6 +78,13 @@ ivas_error ivas_osba_data_open( for ( i = 0; i < hSbaIsmData->delayBuffer_nchan; i++ ) { +#ifdef IVAS_FLOAT_FIXED + if ( ( hSbaIsmData->delayBuffer_fx[i] = (Word32 *) malloc( hSbaIsmData->delayBuffer_size * sizeof(Word32) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for OSBA delay buffer \n" ) ); + } + set_zero_fx( hSbaIsmData->delayBuffer_fx[i], hSbaIsmData->delayBuffer_size ); +#endif // IVAS_FLOAT_FIXED if ( ( hSbaIsmData->delayBuffer[i] = (float *) malloc( hSbaIsmData->delayBuffer_size * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for OSBA delay buffer \n" ) ); @@ -121,6 +137,64 @@ void ivas_osba_data_close( * * Binaural rendering in JBM OSBA format *--------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_osba_dirac_td_binaural_jbm_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + Word32 *output_fx[], /* o : rendered time signal */ + 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]; + } + + channel_offset = st_ivas->nchan_ism; + move16(); + + IF ( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailable, &output_fx[channel_offset], out_len) ) != IVAS_ERR_OK ) + { + return error; + } + + IF ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_sepobj, *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; + FOR ( i = 0; i < nSamplesAsked; i++ ) + { + output_fx[n][i] = L_add(L_shr(output_fx[channel_offset + n][i],1) , L_shr(p_sepobj_fx[n][i],1)); + } + } + return IVAS_ERR_OK; +} + +#endif // IVAS_FLOAT_FIXED ivas_error ivas_osba_dirac_td_binaural_jbm( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 38063766d..d7d4f807b 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -249,10 +249,201 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->sba_analysis_order = sba_analysis_order_old_flush; st_ivas->hDecoderConfig->ivas_total_brate = last_ivas_total_brate; +#ifdef IVAS_FLOAT_FIXED +#if 1 /*Float to fixed conversion*/ + DECODER_TC_BUFFER_HANDLE hTcBuffer; + hTcBuffer = st_ivas->hTcBuffer; + floatToFixed_arrL( hTcBuffer->tc_buffer, hTcBuffer->tc_buffer_fx, Q11, hTcBuffer->tc_buff_len ); + 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] ) + { + st_ivas->hIsmMetaData[ind1]->azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->azimuth * ( 1 << 22 ) ); + st_ivas->hIsmMetaData[ind1]->elevation_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->elevation * ( 1 << 22 ) ); + } + } + IF( st_ivas->hCombinedOrientationData ) + FOR( Word16 ind1 = 0; ind1 < 3; ind1++ ) + { + FOR( Word16 ind2 = 0; ind2 < 3; ind2++ ) + { + st_ivas->hCombinedOrientationData->Rmat_fx[0][ind1][ind2] = (Word32) ( st_ivas->hCombinedOrientationData->Rmat[0][ind1][ind2] * ( 1 << 15 ) ); + } + } + if ( st_ivas->hMasaIsmData ) + { + for ( Word16 ch_idx = 0; ch_idx < st_ivas->hMasaIsmData->delayBuffer_nchan; ch_idx++ ) + { + floatToFixed_arr32( st_ivas->hMasaIsmData->delayBuffer[ch_idx], st_ivas->hMasaIsmData->delayBuffer_fx[ch_idx], Q11, st_ivas->hMasaIsmData->delayBuffer_size ); + } + } + if ( st_ivas->hSbaIsmData ) + { + for ( Word16 ch_idx = 0; ch_idx < st_ivas->hSbaIsmData->delayBuffer_nchan; ch_idx++ ) + { + floatToFixed_arr32( st_ivas->hSbaIsmData->delayBuffer[ch_idx], st_ivas->hSbaIsmData->delayBuffer_fx[ch_idx], Q11, st_ivas->hSbaIsmData->delayBuffer_size ); + } + } + SPAR_DEC_HANDLE hSpar; + hSpar = st_ivas->hSpar; + uint16_t nchan_internal; + nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + DECODER_CONFIG_HANDLE hDecoderConfig; + hDecoderConfig = st_ivas->hDecoderConfig; + Word16 numch_in, numch_out, num_md_sub_frames, q1 = 30, q2 = 30; + ; + Word16 numch_out_dirac = hDecoderConfig->nchan_out; + IF( hSpar ) + { + numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + + for ( int l = 0; l < numch_out; l++ ) + { + for ( int j = 0; j < numch_in; j++ ) + { + for ( int k = 0; k < num_md_sub_frames * IVAS_MAX_NUM_BANDS; k++ ) + { + hSpar->hMdDec->mixer_mat_fx[l][j][k] = floatToFixed( hSpar->hMdDec->mixer_mat[l][j][k], q1 ); + } + } + } + for ( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + for ( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + for ( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + for ( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] = floatToFixed( hSpar->hMdDec->mixer_mat_prev[m][j][k][l], q2 ); + } + } + } + } + for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] = (Word32) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] * ( 1LL << ( Q11 ) ) ); + } + } + if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) ) + { + for ( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + floatToFixed_arrL( hSpar->hMdDec->smooth_buf[i], hSpar->hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + floatToFixed_arr( hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_fac_fx, Q15, IVAS_MAX_NUM_BANDS ); + } + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] = float_to_fix( st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] , Q11 ); + } + } + } + } +#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 */ + 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++ ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); + } + } + FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + FOR( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + FOR( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev[m][j][k][l] = ( (float) hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] / ( 1 << q2 ) ); + } + } + } + } + // fix2float (to be cleaned) + IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) + { + fixedToFloat_arr( hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_fac, Q15, IVAS_MAX_NUM_BANDS ); + FOR( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + fixedToFloat_arrL( hSpar->hMdDec->smooth_buf_fx[i], hSpar->hMdDec->smooth_buf[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + } + // fix2float end + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] ) / (float) ( 1LL << ( Q11 ) ) ); + } + } + } + } + + 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] ) + { + st_ivas->hIsmMetaData[ind1]->azimuth = (float) ( st_ivas->hIsmMetaData[ind1]->azimuth_fx ) / (float) ( 1 << 22 ); + st_ivas->hIsmMetaData[ind1]->elevation = (float) ( st_ivas->hIsmMetaData[ind1]->elevation_fx ) / (float) ( 1 << 22 ); + } + } +#endif +#else if ( ( error = ivas_jbm_dec_flush_renderer( 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; } +#endif // IVAS_FLOAT_FIXED /* restore correct values for the current frame*/ st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); @@ -1106,6 +1297,93 @@ void ivas_sba_dec_digest_tc_fx( * * *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_sba_dec_render_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ + Word32 *output_fx[], /* o : rendered time signal */ + Word16 out_len /*Store the length of values in each channel*/ +) +{ + Word16 slots_to_render, first_sf, last_sf, subframe_idx; + UWord16 slot_size, ch; + UWord16 nchan_internal, nchan_out; + SPAR_DEC_HANDLE hSpar; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + Word32 *output_f_local_fx[MAX_OUTPUT_CHANNELS]; + Word16 output_f_local_len; + ivas_error error; + + output_f_local_len = out_len; + move16(); + hSpar = st_ivas->hSpar; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + nchan_out = add(st_ivas->hIntSetup.nchan_out_woLFE , st_ivas->hIntSetup.num_lfe); + + FOR ( ch = 0; ch < nchan_out; ch++ ) + { + output_f_local_fx[ch] = output_fx[ch]; + } + + slot_size = NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + + /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ + slots_to_render = s_min( sub(hSpar->num_slots , hSpar->slots_rendered), nSamplesAsked / slot_size ); + *nSamplesRendered = imult1616(slots_to_render , slot_size); + first_sf = hSpar->subframes_rendered; + last_sf = first_sf; + move16(); + move16(); + WHILE ( GT_16(slots_to_render , 0) ) + { + slots_to_render = sub(slots_to_render,hSpar->subframe_nbslots[last_sf]); + last_sf++; + } + + FOR ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) + { + Word16 n_samples_sf = imult1616(slot_size , hSpar->subframe_nbslots[subframe_idx]); + + ivas_spar_dec_upmixer_sf_fx( st_ivas, output_f_local_fx, nchan_internal,output_f_local_len ); + FOR ( ch = 0; ch < nchan_out; ch++ ) + { + output_f_local_fx[ch] = output_f_local_fx[ch]+n_samples_sf; + } + + output_f_local_len = sub(output_f_local_len,n_samples_sf); + /* update combined orientation access index */ + ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf ); + } + + IF ( EQ_16(st_ivas->renderer_type , RENDERER_SBA_LINEAR_DEC) ) + { + IF ( ( error = ivas_sba_linear_renderer_fx( output_fx, *nSamplesRendered, st_ivas->hIntSetup.nchan_out_woLFE, 0, st_ivas->hDecoderConfig->output_config, st_ivas->hOutSetup ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + IF ( st_ivas->hDirAC != NULL && EQ_16(hSpar->slots_rendered , hSpar->num_slots) ) + { + IF ( EQ_16(st_ivas->hDirAC->hConfig->dec_param_estim , 1) ) + { + hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx , DEFAULT_JBM_CLDFB_TIMESLOTS ) % hSpatParamRendCom->dirac_md_buffer_length; + } + ELSE + { + hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx , DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length; + } + move16(); + } + + *nSamplesAvailableNext = imult1616(sub( hSpar->num_slots , hSpar->slots_rendered ) , slot_size); + + return IVAS_ERR_OK; +} +#endif // IVAS_FLOAT_FIXED ivas_error ivas_sba_dec_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ @@ -1151,7 +1429,7 @@ ivas_error ivas_sba_dec_render( { int16_t n_samples_sf = slot_size * hSpar->subframe_nbslots[subframe_idx]; -#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED1 #if 1 /*Float to fixed conversion*/ Word16 numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; Word16 numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; diff --git a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c index aefa51ac7..f5d9b1442 100644 --- a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c +++ b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c @@ -1320,7 +1320,7 @@ void ivas_sba_dirac_stereo_dec_fx( stereo_dft_dec_synthesize_fx( hCPE, DFT, 1, output[1], output_frame ); } - synchro_synthesis_fixed_clean( st_ivas->hDecoderConfig->ivas_total_brate, hCPE, output, output_frame, 1 /*st_ivas->sba_dirac_stereo_flag*/ ); + synchro_synthesis_fx( st_ivas->hDecoderConfig->ivas_total_brate, hCPE, output, output_frame, 1 /*st_ivas->sba_dirac_stereo_flag*/ ); /* output scaling */ IF ( EQ_16(sba_mono_flag, 0) ) diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal.c index 196c3de1b..f67ea1874 100644 --- a/lib_dec/ivas_sba_rendering_internal.c +++ b/lib_dec/ivas_sba_rendering_internal.c @@ -710,6 +710,68 @@ void ivas_ism2sba_sf( * * Linear rendering for SBA format *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +/*TODO: To be tested*/ +/************************ +Float to fixed conversion required for:output_f +*************************/ +ivas_error ivas_sba_linear_renderer_fx( + Word32 *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 nchan_in, /* i : number of input ambisonics channels */ + const Word16 nchan_ism, /* i : number of objects */ + const AUDIO_CONFIG output_config, /* i : output audio configuration */ + const IVAS_OUTPUT_SETUP output_setup /* i : output format setup */ +) +{ + Word16 i; + Word16 nchan_hoa; + ivas_error error; + + error = IVAS_ERR_OK; + + /* Number of channels of HOA depends of transport format which is mixed order xH1V*/ + nchan_hoa = nchan_in; + move16(); + + IF ( EQ_16(nchan_in , 6) ) /*2H1V*/ + { + nchan_hoa = 9; + move16(); + } + ELSE IF ( EQ_16(nchan_in , 8) ) /*3H1V*/ + { + nchan_hoa = 16; + move16(); + } + + SWITCH ( output_config ) + { + case IVAS_AUDIO_CONFIG_FOA: /* Ambisonics output, order: 1 */ + case IVAS_AUDIO_CONFIG_HOA2: /* Ambisonics output, order: 2 */ + case IVAS_AUDIO_CONFIG_HOA3: /* Ambisonics output, order: 3 */ + FOR ( i = nchan_hoa; i < output_setup.nchan_out_woLFE; i++ ) + { + set_zero_fx( output_f[i], output_frame ); + } + BREAK; + case IVAS_AUDIO_CONFIG_EXTERNAL: + FOR ( i = output_setup.nchan_out_woLFE - 1; i >= nchan_ism; i-- ) + { + Copy32( output_f[i - nchan_ism], output_f[i], output_frame ); + } + FOR ( ; i >= 0; i-- ) + { + set_zero_fx( output_f[i], output_frame ); + } + BREAK; + default: + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: illegal output configuration, Exiting.\n" ); + } + + return error; +} +#endif // IVAS_FLOAT_FIXED ivas_error ivas_sba_linear_renderer( float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 05d490f16..12bf3e499 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -2736,7 +2736,7 @@ void ivas_spar_dec_upmixer( for ( subframe_idx = 0; subframe_idx < MAX_PARAM_SPATIAL_SUBFRAMES; subframe_idx++ ) { -#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED1 #if 1 /*Float to fixed conversion*/ Word16 numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; Word16 numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; @@ -2829,7 +2829,7 @@ void ivas_spar_dec_upmixer( { FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) { - st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] ) / (float) ( 1LL << ( Q7 ) ) ); /*Rounding off*/ + st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] ) / (float) ( 1LL << ( Q11 ) ) ); /*Rounding off*/ } } } @@ -2877,8 +2877,9 @@ void ivas_spar_dec_upmixer( #ifdef IVAS_FLOAT_FIXED void ivas_spar_dec_upmixer_sf_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - float *output[], /* o : output audio channels */ - const Word16 nchan_internal /* i : number of internal channels */ + Word32 *output_fx[], /* o : output audio channels */ + const Word16 nchan_internal, /* i : number of internal channels */ + Word16 out_len ) { /*TODO: To be removed later--------------------------------------------------------*/ @@ -2886,11 +2887,13 @@ void ivas_spar_dec_upmixer_sf_fx( float *cldfb_in_ts_im[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX]; float Pcm_tmp[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + float output[MAX_OUTPUT_CHANNELS][L_FRAME48k]; + float *p_output[MAX_OUTPUT_CHANNELS]; /*---------------------------------------------------------------------------*/ Word16 cldfb_band, num_cldfb_bands, numch_in, numch_out; Word32 *cldfb_in_ts_re_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX]; Word32 *cldfb_in_ts_im_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX]; - Word32 output_fx[16][960]; + //Word32 output_fx[16][960]; Word16 i, b, ts, out_ch, in_ch; Word16 num_spar_bands, spar_band, nchan_transport; Word16 num_in_ingest, split_band; @@ -3059,6 +3062,38 @@ void ivas_spar_dec_upmixer_sf_fx( FOR ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { md_idx = hSpar->render_to_md_map[ts + slot_idx_start]; +#if 1 /*TODO: To be removed later when ivas_spar_get_parameters is integerated*/ + FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); /*Rounding off*/ + } + } + FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + FOR( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + FOR( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev[m][j][k][l] = ( (float) hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] / ( 1 << q2 ) ); + } + } + } + } + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] ) / (float) ( 1LL << ( Q11 ) ) ); + } + } + } +#endif ivas_spar_get_parameters( hSpar, hDecoderConfig, md_idx, numch_out, numch_in, num_spar_bands, mixer_mat ); FOR ( int i = 0; i < numch_out; i++ ) { @@ -3186,29 +3221,36 @@ void ivas_spar_dec_upmixer_sf_fx( #endif IF ( NE_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_FOA) && NE_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_STEREO) && NE_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_MONO) ) { - ivas_dirac_dec_render_sf( st_ivas, output, nchan_internal, cldfb_in_ts_re, cldfb_in_ts_im ); - } - - /*TODO: To be removed later when ivas_dirac_dec_render_sf is integerated*/ - FOR( out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) - { - IF( st_ivas->cldfbSynDec[out_ch] ) + FOR( Word16 ch = 0; ch < add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); ch++ ) + { + fixedToFloat_arrL( output_fx[ch], output[ch], Q11, out_len ); + p_output[ch] = output[ch]; + } + ivas_dirac_dec_render_sf( st_ivas, p_output, nchan_internal, cldfb_in_ts_re, cldfb_in_ts_im ); + FOR( Word16 ch = 0; ch < add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); ch++ ) + { + floatToFixed_arrL( output[ch], output_fx[ch], Q11, out_len ); + } + /*TODO: To be removed later when ivas_dirac_dec_render_sf is integerated*/ + FOR( out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) { - FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + IF( st_ivas->cldfbSynDec[out_ch] ) { - st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] = (Word32) ( st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] * ( 1LL << ( Q7 ) ) ); + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] = float_to_fix( st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] ,Q11); + } } } + } + FOR( out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { - floatToFixed_arrL( cldfb_in_ts_re[out_ch][ts], cldfb_in_ts_re_fx[out_ch][ts], Q8, 60 );/*Q scaled from 6 to 8*/ - floatToFixed_arrL( cldfb_in_ts_im[out_ch][ts], cldfb_in_ts_im_fx[out_ch][ts], Q8, 60 );/*Q scaled from 6 to 8*/ + floatToFixed_arrL( cldfb_in_ts_re[out_ch][ts], cldfb_in_ts_re_fx[out_ch][ts], Q6, 60 ); + floatToFixed_arrL( cldfb_in_ts_im[out_ch][ts], cldfb_in_ts_im_fx[out_ch][ts], Q6, 60 ); } } - FOR( Word16 ch = 0; ch < add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); ch++ ) - { - floatToFixed_arrL( output[ch], output_fx[ch], Q7, hSpar->subframe_nbslots[hSpar->subframes_rendered] * num_cldfb_bands ); - } /*------------------------------------------------------------------ends*/ IF ( st_ivas->hDirAC != NULL ) { @@ -3233,10 +3275,14 @@ void ivas_spar_dec_upmixer_sf_fx( IF ( ( EQ_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_FOA) || !( EQ_16(st_ivas->hOutSetup.output_config , IVAS_AUDIO_CONFIG_BINAURAL) || EQ_16(st_ivas->hOutSetup.output_config , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR) || EQ_16(st_ivas->hOutSetup.output_config , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB) ) ) && !( EQ_16(st_ivas->ivas_format , SBA_ISM_FORMAT) && EQ_16(st_ivas->ism_mode , ISM_SBA_MODE_DISC) && EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_FASTCONV_ROOM) ) ) { + Scale_sig32(st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, -6 ); + Scale_sig32( output_fx[ch], out_len, -6 ); FOR ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { cldfbSynthesis_ivas_fx( &cldfb_in_ts_re_fx[idx_in][ts], &cldfb_in_ts_im_fx[idx_in][ts], &output_fx[ch][ts * num_cldfb_bands], num_cldfb_bands, st_ivas->cldfbSynDec[idx_in] ); } + Scale_sig32( output_fx[ch], out_len, 6 ); + Scale_sig32(st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, 6 ); } idx_in++; @@ -3248,22 +3294,20 @@ void ivas_spar_dec_upmixer_sf_fx( /* CLDFB to time synthesis (overwrite mixer output) */ FOR ( out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) { + Scale_sig32( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx, st_ivas->cldfbSynDec[out_ch]->p_filter_length, -6 ); + Scale_sig32( output_fx[out_ch], out_len, -6 ); FOR ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { cldfbSynthesis_ivas_fx( &cldfb_in_ts_re_fx[out_ch][ts], &cldfb_in_ts_im_fx[out_ch][ts], &output_fx[out_ch][ts * num_cldfb_bands], num_cldfb_bands, st_ivas->cldfbSynDec[out_ch] ); } + Scale_sig32( output_fx[out_ch], out_len, 6 ); + Scale_sig32( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx, st_ivas->cldfbSynDec[out_ch]->p_filter_length, 6 ); } } hSpar->slots_rendered = add(hSpar->slots_rendered,hSpar->subframe_nbslots[hSpar->subframes_rendered]); hSpar->subframes_rendered++; -#if 1/*TODO: To be removed when ivas_dirac_dec_render_sf is added(length of output_fx cannot be determined)*/ - FOR( Word16 ch = 0; ch < add(st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe); ch++ ) - { - fixedToFloat_arrL( output_fx[ch], output[ch], Q7, hSpar->subframe_nbslots[hSpar->subframes_rendered-1] * num_cldfb_bands); - } -#endif pop_wmops(); return; diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index e18204ec1..bcca73613 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -934,6 +934,9 @@ typedef struct ivas_spar_dec_lib_t /* Data structure for SBA_ISM rendering */ typedef struct ivas_osba_data { +#ifdef IVAS_FLOAT_FIXED + Word32 **delayBuffer_fx; +#endif // IVAS_FLOAT_FIXED float **delayBuffer; int16_t delayBuffer_size; int16_t delayBuffer_nchan; @@ -1107,6 +1110,7 @@ typedef struct renderer_struct #ifdef IVAS_FLOAT_FIXED Word32 prev_gains_fx[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; Word16 *interpolator_fx; + Word16 interpolator_len; Word32 gains_fx[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; #endif int16_t interpolator_length; @@ -1246,6 +1250,7 @@ typedef struct decoder_tc_buffer_structure float *tc[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; /* pointers into the buffer to the beginning of each tc */ // VE2SB: TBV #ifdef IVAS_FLOAT_FIXED Word32 *tc_buffer_fx; /* the buffer itself */ + Word16 tc_buff_len;/*stores memory length of tc buffer*/ Word32 *tc_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; /* pointers into the buffer to the beginning of each tc Q11 for ivas */ // VE2SB: TBV Word16 q_tc_fx; #endif @@ -1431,6 +1436,7 @@ typedef struct Decoder_Struct #ifdef IVAS_FLOAT_FIXED Word32 **mem_hp20_out_fx; Word32 *p_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; /* floating-point output audio buffers */ + Word16 p_out_len;/*Stores the total no of channels for which memory is allocated to p_output_fx*/ #endif } Decoder_Struct; diff --git a/lib_dec/ivas_stereo_mdct_core_dec.c b/lib_dec/ivas_stereo_mdct_core_dec.c index d294cbead..ef6046c6f 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec.c +++ b/lib_dec/ivas_stereo_mdct_core_dec.c @@ -173,7 +173,7 @@ static void stereo_mdct_dec_stereo( return; } - +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * stereo_mdct_core_dec() * @@ -485,7 +485,7 @@ void stereo_mdct_core_dec( pop_wmops(); return; } - +#endif /*-------------------------------------------------------------------* * apply_dmx_weights() diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 93ff84bb6..c573e023b 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -258,11 +258,11 @@ 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]->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 ); + //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 ); @@ -810,10 +810,12 @@ void stereo_mdct_core_dec_fx( 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); diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec.c b/lib_dec/ivas_stereo_mdct_stereo_dec.c index 5c98bad9b..b9bf4a9fe 100644 --- a/lib_dec/ivas_stereo_mdct_stereo_dec.c +++ b/lib_dec/ivas_stereo_mdct_stereo_dec.c @@ -1110,8 +1110,8 @@ void updateBuffersForDmxMdctStereo_fx( delta = 6; } - delay_buf_out_len = delta * HQ_DELAY_COMP; - tcxltp_mem_in_len = NS2SA( sts[0]->output_Fs, TCXLTP_DELAY_NS ); + delay_buf_out_len = i_mult( delta, HQ_DELAY_COMP ); + tcxltp_mem_in_len = NS2SA_fx2( sts[0]->output_Fs, TCXLTP_DELAY_NS ); assert( delay_buf_out_len > tcxltp_mem_in_len ); @@ -1120,8 +1120,8 @@ void updateBuffersForDmxMdctStereo_fx( update_exp( &sts[0]->hTcxLtpDec->exp_tcxltp_mem_in, &sts[1]->hTcxLtpDec->exp_tcxltp_mem_in, sts[0]->hTcxLtpDec->tcxltp_mem_in, sts[1]->hTcxLtpDec->tcxltp_mem_in, TCXLTP_MAX_DELAY ); - update_exp( &sts[1]->exp_delay_buf_out, &sts[1]->exp_delay_buf_out, - sts[0]->delay_buf_out_fx, sts[1]->delay_buf_out_fx, HQ_DELTA_MAX * HQ_DELAY_COMP ); + //update_exp( &sts[1]->exp_delay_buf_out, &sts[1]->exp_delay_buf_out, + // sts[0]->delay_buf_out_fx, sts[1]->delay_buf_out_fx, HQ_DELTA_MAX * HQ_DELAY_COMP ); update_exp( &sts[0]->hHQ_core->exp_old_out, &sts[1]->hHQ_core->exp_old_out, sts[0]->hHQ_core->old_out_fx, sts[1]->hHQ_core->old_out_fx, L_FRAME48k ); @@ -1131,43 +1131,43 @@ void updateBuffersForDmxMdctStereo_fx( FOR( i = 0; i < tcxltp_mem_in_len; i++ ) { - sum_tcx_ltp = add( sts[0]->hTcxLtpDec->tcxltp_mem_in[i] >> 1, sts[1]->hTcxLtpDec->tcxltp_mem_in[i] >> 1 ); // exp_tcxltp_mem_in + 1 - sts[0]->hTcxLtpDec->tcxltp_mem_in[i] = mult( float_to_fix16( INV_SQRT2, 15 ), sum_tcx_ltp ); // 14 - exp_tcxltp_mem_in - 1 + sum_tcx_ltp = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_in[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_in[i], 1 ) ); // exp_tcxltp_mem_in + 1 + sts[0]->hTcxLtpDec->tcxltp_mem_in[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp ); // 14 - exp_tcxltp_mem_in - 1 sum_delay_buf = add( sts[0]->delay_buf_out_fx[i], sts[1]->delay_buf_out_fx[i] ); - sts[0]->delay_buf_out_fx[i] = mult( float_to_fix16( INV_SQRT2, 15 ), sum_delay_buf ); // exp_delay_buf_sum + sts[0]->delay_buf_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_delay_buf ); // exp_delay_buf_sum - sum_old_out = add( sts[0]->hHQ_core->old_out_fx[i] >> 1, sts[1]->hHQ_core->old_out_fx[i] >> 1 ); - sts[0]->hHQ_core->old_out_fx[i] = mult( float_to_fix16( INV_SQRT2, 15 ), sum_old_out ); // exp_old_out_sum + sum_old_out = add( shr( sts[0]->hHQ_core->old_out_fx[i], 1 ), shr( sts[1]->hHQ_core->old_out_fx[i], 1 ) ); + sts[0]->hHQ_core->old_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_old_out ); // exp_old_out_sum - sum_tcx_ltp_out = add( sts[0]->hTcxLtpDec->tcxltp_mem_out[i] >> 1, sts[1]->hTcxLtpDec->tcxltp_mem_out[i] >> 1 ); - sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( float_to_fix16( INV_SQRT2, 15 ), sum_tcx_ltp_out ); // exp_tcs_ltp_out_sm + sum_tcx_ltp_out = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_out[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_out[i], 1 ) ); + sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp_out ); // exp_tcs_ltp_out_sm } FOR( ; i < delay_buf_out_len; i++ ) { sum_delay_buf = add( sts[0]->delay_buf_out_fx[i], sts[1]->delay_buf_out_fx[i] ); - sts[0]->delay_buf_out_fx[i] = mult( float_to_fix16( INV_SQRT2, 15 ), sum_delay_buf ); // exp_delay_buf_sum + sts[0]->delay_buf_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_delay_buf ); // exp_delay_buf_sum - sum_old_out = add( sts[0]->hHQ_core->old_out_fx[i] >> 1, sts[1]->hHQ_core->old_out_fx[i] >> 1 ); - sts[0]->hHQ_core->old_out_fx[i] = mult( float_to_fix16( INV_SQRT2, 15 ), sum_old_out ); + sum_old_out = add( shr( sts[0]->hHQ_core->old_out_fx[i], 1 ), shr( sts[1]->hHQ_core->old_out_fx[i], 1 ) ); + sts[0]->hHQ_core->old_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_old_out ); - sum_tcx_ltp_out = add( sts[0]->hTcxLtpDec->tcxltp_mem_out[i] >> 1, sts[1]->hTcxLtpDec->tcxltp_mem_out[i] >> 1 ); - sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( float_to_fix16( INV_SQRT2, 15 ), sum_tcx_ltp_out ); // exp_tcs_ltp_out_sm + sum_tcx_ltp_out = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_out[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_out[i], 1 ) ); + sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp_out ); // exp_tcs_ltp_out_sm } FOR( ; i < output_frame; i++ ) { - sum_old_out = add( sts[0]->hHQ_core->old_out_fx[i] >> 1, sts[1]->hHQ_core->old_out_fx[i] >> 1 ); - sts[0]->hHQ_core->old_out_fx[i] = mult( float_to_fix16( INV_SQRT2, 15 ), sum_old_out ); // exp_old_out_sum + sum_old_out = add( shr( sts[0]->hHQ_core->old_out_fx[i], 1 ), shr( sts[1]->hHQ_core->old_out_fx[i], 1 ) ); + sts[0]->hHQ_core->old_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_old_out ); // exp_old_out_sum - sum_tcx_ltp_out = add( sts[0]->hTcxLtpDec->tcxltp_mem_out[i] >> 1, sts[1]->hTcxLtpDec->tcxltp_mem_out[i] >> 1 ); - sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( float_to_fix16( INV_SQRT2, 15 ), sum_tcx_ltp_out ); // 15 + exp_tcs_ltp_out_sm - 15 + sum_tcx_ltp_out = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_out[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_out[i], 1 ) ); + sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp_out ); // 15 + exp_tcs_ltp_out_sm - 15 } - sts[0]->hTcxLtpDec->exp_tcxltp_mem_in += 1; - sts[0]->hHQ_core->exp_old_out += 1; - sts[0]->hTcxLtpDec->exp_tcxltp_mem_out += 1; + sts[0]->hTcxLtpDec->exp_tcxltp_mem_in = add( sts[0]->hTcxLtpDec->exp_tcxltp_mem_in, 1 ); + sts[0]->hHQ_core->exp_old_out = add( sts[0]->hHQ_core->exp_old_out, 1 ); + sts[0]->hTcxLtpDec->exp_tcxltp_mem_out = add( sts[0]->hTcxLtpDec->exp_tcxltp_mem_out, 1 ); } return; diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index c570e8abd..f588aa1c0 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -2631,730 +2631,7 @@ void synchro_synthesis( #ifdef IVAS_FLOAT_FIXED -void synchro_synthesis_fixed( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - float *output[CPE_CHANNELS], /* i/o: output synthesis signal */ - const Word16 output_frame, /* i : Number of samples */ - const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ -) -{ - - Word32 *output_fx[2]; - Word32 op[2][L_FRAME48k]; - Word16 output_q = OUTPUT_Q; - output_fx[0] = op[0]; - output_fx[1] = op[1]; - - FOR( Word32 n = 0; n < CPE_CHANNELS; n++ ) - { - FOR( Word32 k = 0; k < L_FRAME48k; k++ ) - { - output_fx[n][k] = (Word32) ( output[n][k] * ( 1 << output_q ) ); - } - 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->hCoreCoder[n] != NULL ) - { - IF( hCPE->hCoreCoder[n]->hTcxLtpDec != NULL ) - { - FOR( Word32 p = 0; p < L_FRAME48k; p++ ) - { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << output_q ) ); - } - FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) - { - 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++ ) - { - hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->prev_synth_buffer[k] * ( 1 << output_q ) ); - } - FOR( Word32 k = 0; k < HQ_DELTA_MAX * HQ_DELAY_COMP; k++ ) - { - hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->delay_buf_out[k] * ( 1 << output_q ) ); - } - IF( hCPE->hCoreCoder[n]->hTcxDec != NULL ) - { - FOR( Word32 k = 0; k < 111; k++ ) - { - hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] = (Word32) ( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] * ( 1 << output_q ) ); - } - } - } - - IF( hCPE->output_mem[n] != NULL ) - { - FOR( Word32 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( 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 ) ); - } - } - - Word16 n, delay_comp_TD, delay_comp_DFT; - Word32 output_Fs; - Decoder_State **sts; - Word16 i, delay_cldfb, dft32ms_ovl; - - Word32 *p_output_mem_fx[CPE_CHANNELS]; - Word32 tmp_out_fx[CPE_CHANNELS][NS2SA( 48000, DELAY_CLDFB_NS )]; - Word32 tmp_out_TD_fx[CPE_CHANNELS][STEREO_DFT32MS_OVL_MAX]; - Word32 tmp_out_TD2_fx[CPE_CHANNELS][STEREO_DFT32MS_OVL_MAX]; - - Word16 use_cldfb_for_last_dft; - Word16 dft_mono_brate_switch; - Word16 delay_diff; - Word32 tmpF_fx = 0; - Word16 nChannels; - - sts = hCPE->hCoreCoder; - output_Fs = sts[0]->output_Fs; - - 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 ) ) - { - use_cldfb_for_last_dft = 1; - } - - dft_mono_brate_switch = 0; - IF( hCPE->element_mode == IVAS_CPE_DFT && ( hCPE->last_element_mode == IVAS_CPE_DFT || hCPE->last_element_mode == IVAS_CPE_MDCT ) && hCPE->nchan_out == 1 && hCPE->element_brate != hCPE->last_element_brate ) - { - IF( hCPE->last_element_brate >= IVAS_32k && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) - { - dft_mono_brate_switch = -1; /* switch from residual coding mode or MDCT Stereo */ - } - ELSE IF( hCPE->last_element_brate <= IVAS_24k4 && hCPE->hStereoDft->hConfig->res_cod_mode > STEREO_DFT_RES_COD_OFF ) - { - dft_mono_brate_switch = 1; /* switch to residual coding mode*/ - } - } - - IF( use_cldfb_for_last_dft ) - { - IF( hCPE->element_mode == IVAS_CPE_DFT && hCPE->last_element_mode == IVAS_CPE_TD && ( ivas_total_brate > IVAS_SID_5k2 || hCPE->nchan_out == 2 ) ) - { - stereo_tca_scale_R_channel_fx( hCPE, output_fx[0], output_frame ); - } - } - - /* set delays */ - delay_comp_DFT = NS2SA( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); - delay_comp_TD = NS2SA( output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); - delay_diff = delay_comp_TD - delay_comp_DFT; - - dft32ms_ovl = (Word16) ( ( STEREO_DFT32MS_OVL_MAX * output_Fs ) / 48000 ); - delay_cldfb = NS2SA( output_Fs, DELAY_CLDFB_NS ); - - /* initialize pointers */ - IF( hCPE->element_mode >= IVAS_CPE_DFT && hCPE->output_mem_fx[0] != NULL ) - { - FOR( n = 0; n < CPE_CHANNELS; n++ ) - { - p_output_mem_fx[n] = hCPE->output_mem_fx[n]; - } - } - - /*----------------------------------------------------------------* - * DFT stereo synchro - *----------------------------------------------------------------*/ - - IF( hCPE->element_mode == IVAS_CPE_DFT || sba_dirac_stereo_flag ) - { - /* handling of bitrate switching from residual (using DFT) to non-residual mode (using CLDFB) FOR mono output - as in DFT->TD switching */ - IF( dft_mono_brate_switch == -1 ) - { - FOR( i = delay_comp_DFT; i < delay_comp_TD; i++ ) - { - sts[0]->prev_synth_buffer32_fx[i] = p_output_mem_fx[0][i - delay_comp_DFT]; - } - - FOR( i = delay_comp_TD; i < delay_comp_TD + delay_cldfb; i++ ) - { - tmp_out_fx[0][i - delay_comp_TD] = p_output_mem_fx[0][i - delay_comp_DFT]; - } - } - - IF( hCPE->nchan_out == 1 && hCPE->last_element_mode == IVAS_CPE_MDCT ) - { - FOR( Word32 ind = 0; ind < delay_comp_DFT; ind++ ) - { - Word32 temp = sts[0]->prev_synth_buffer32_fx[ind] + sts[1]->prev_synth_buffer32_fx[ind]; - sts[0]->prev_synth_buffer32_fx[ind] = Mpy_32_32( temp, INV_SQRT2_FX ); - } - } - - IF( use_cldfb_for_last_dft ) - { - /* delay CLDFB-based mono output (<= 24.4 kbps) to be aligned with DFT-based mono output (32 kbps), needed to avoid discontinuities with TCX-LTP. */ - Copy32( sts[0]->prev_synth_buffer32_fx + delay_comp_DFT, hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); - delay_signal_fx( output_fx[0], output_frame, hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); - } - - IF( hCPE->element_mode != IVAS_CPE_MDCT ) - { - ivas_post_proc_fx( NULL, hCPE, 0, output_fx[0], output_fx, output_frame, sba_dirac_stereo_flag ); - } - - /* zero padding in order to synchronize the upmixed DFT stereo synthesis with the TD/MDCT stereo synthesis */ - FOR( n = 0; n < hCPE->nchan_out; n++ ) - { - IF( sba_dirac_stereo_flag ) - { - delay_signal_fx( output_fx[n], output_frame, hCPE->prev_synth_fx[n], delay_comp_DFT ); - } - ELSE - { - delay_signal_fx( output_fx[n], output_frame, sts[n]->prev_synth_buffer32_fx, delay_comp_DFT ); - } - } - IF( use_cldfb_for_last_dft ) - { - Copy32( hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32, sts[0]->prev_synth_buffer32_fx + delay_comp_DFT, delay_diff ); - } - - /* handling of TD->DFT switching */ - FOR( n = 0; n < hCPE->nchan_out; n++ ) - { - IF( ( hCPE->last_element_mode != IVAS_CPE_DFT && !sba_dirac_stereo_flag && dft_mono_brate_switch != -1 ) || dft_mono_brate_switch == 1 ) - { - Word32 *pPrev_synth_fx; - Word32 inv_fade_len_fx = 0; - switch ( output_Fs ) - { - case 16000: - inv_fade_len_fx = 71582792; - break; - case 32000: - inv_fade_len_fx = 35791396; - break; - case 48000: - inv_fade_len_fx = 23860930; - break; - default: - assert( 0 ); - } - - /* cross-fading between TD synchro memory and the DFT output */ - IF( sba_dirac_stereo_flag ) - { - pPrev_synth_fx = hCPE->prev_synth_fx[n]; - } - ELSE - { - pPrev_synth_fx = sts[n]->prev_synth_buffer32_fx; - } - - IF( hCPE->last_element_mode != IVAS_CPE_MDCT ) - { - FOR( i = delay_comp_DFT; i < delay_comp_TD; i++ ) - { - Word64 res1 = (Word64) pPrev_synth_fx[i] * ( delay_comp_TD - i ); - Word64 res2 = (Word64) output_fx[n][i] * ( i - delay_comp_DFT ); - Word64 res = W_shr( res1, 6 ) + W_shr( res2, 6 ); - res = res * inv_fade_len_fx; - output_fx[n][i] = (Word32) W_shr( res, 31 - 6 ); - // change 6 to less number to get better precision - } - } - } - ELSE IF( dft_mono_brate_switch == -1 ) - { - Word32 inv_fade_len_1_fx = 0; - Word32 inv_fade_len_2_fx = 0; - - switch ( output_Fs ) - { - case 16000: - inv_fade_len_1_fx = 71582792; - inv_fade_len_2_fx = 107374184; - break; - case 32000: - inv_fade_len_1_fx = 35791396; - inv_fade_len_2_fx = 53687092; - break; - case 48000: - inv_fade_len_1_fx = 23860930; - inv_fade_len_2_fx = 35791396; - break; - default: - assert( 0 ); - } - FOR( i = 0; i < delay_diff; i++ ) - { - Word64 res1 = (Word64) output_fx[0][i + delay_comp_DFT] * ( delay_diff - i ); - Word64 res2 = (Word64) p_output_mem_fx[0][i] * i; - Word64 res = W_shr( res1, 6 ) + W_shr( res2, 6 ); - res = res * inv_fade_len_1_fx; - output_fx[0][i + delay_comp_DFT] = (Word32) W_shr( res, 31 - 6 ); - } - - FOR( i = 0; i < delay_cldfb; i++ ) - { - Word64 res1 = (Word64) tmp_out_fx[0][i] * ( delay_cldfb - i ); - Word64 res2 = (Word64) output_fx[0][i + delay_comp_TD] * i; - Word64 res = W_shr( res1, 6 ) + W_shr( res2, 6 ); - res = res * inv_fade_len_2_fx; - output_fx[0][i + delay_comp_TD] = (Word32) W_shr( res, 31 - 6 ); - } - } - } - } - - /*----------------------------------------------------------------* - * TD/MDCT stereo synchro - *----------------------------------------------------------------*/ - - IF( sba_dirac_stereo_flag ) - { - // delete the below -#if 1 - 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++ ) - { - FOR( Word32 p = 0; p < L_FRAME48k; p++ ) - { - output[n][p] = (float) output_fx[n][p] / ( 1u << 11 ); - } - IF( hCPE->output_mem[n] != NULL ) - { - FOR( Word32 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 ) - { - IF( hCPE->hCoreCoder[n]->hTcxLtpDec != NULL ) - { - FOR( Word32 p = 0; p < L_FRAME48k; p++ ) - { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << output_q ); - } - FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) - { - 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++ ) - { - hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << output_q ); - } - FOR( Word32 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->hCoreCoder[n]->hTcxDec != NULL ) - { - FOR( Word32 k = 0; k < 111; k++ ) - { - hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[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( 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 ); - } - } -#endif - - // keep return - return; - } - - IF( hCPE->element_mode == IVAS_CPE_TD || hCPE->element_mode == IVAS_CPE_MDCT ) - { - /* handling of DFT->TD switching */ - IF( hCPE->last_element_mode == IVAS_CPE_DFT && !use_cldfb_for_last_dft && hCPE->output_mem_fx[0] != NULL ) - { - /* use redressed DFT stereo OLA part to reconstruct the TD stereo synchro memory */ - FOR( n = 0; n < hCPE->nchan_out; n++ ) - { - FOR( i = delay_comp_DFT; i < delay_comp_TD; i++ ) - { - sts[n]->prev_synth_buffer32_fx[i] = p_output_mem_fx[n][i - delay_comp_DFT]; - } - - FOR( i = delay_comp_TD; i < delay_comp_TD + delay_cldfb; i++ ) - { - tmp_out_fx[n][i - delay_comp_TD] = p_output_mem_fx[n][i - delay_comp_DFT]; - } - } - } - - /* IF previous frame had only one channel copy buffers to other channel */ - IF( hCPE->nchan_out == 1 && hCPE->element_mode == IVAS_CPE_MDCT && hCPE->last_element_mode == IVAS_CPE_DFT ) - { - Copy32( sts[0]->prev_synth_buffer32_fx, sts[1]->prev_synth_buffer32_fx, delay_comp_TD ); - Copy32( tmp_out_fx[0], tmp_out_fx[1], delay_cldfb ); - Copy32( p_output_mem_fx[0], p_output_mem_fx[1], delay_diff ); - } - - /*----------------------------------------------------------------* - * update DFT synthesis overlap memory @output_Fs; needed FOR TD->DFT stereo switching - *----------------------------------------------------------------*/ - - /* resample LB synthesis to output_Fs */ - IF( hCPE->element_mode != IVAS_CPE_MDCT && !use_cldfb_for_last_dft ) - { - FOR( n = 0; n < hCPE->nchan_out; n++ ) - { - IF( sts[n]->core == ACELP_CORE ) - { - L_lerp_fx_q11( hCPE->input_mem_LB_fx[n], tmp_out_TD_fx[n], dft32ms_ovl, NS2SA( sts[n]->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) ); - } - ELSE /* TCX/HQ core */ - { - L_lerp_fx_q11( hCPE->input_mem_LB_fx[n], tmp_out_TD_fx[n], dft32ms_ovl, NS2SA( sts[n]->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) ); - - /* use TCX synchro memory (perfect signal is available) */ - FOR( i = delay_diff; i < dft32ms_ovl; i++ ) - { - tmp_out_TD_fx[n][i] = sts[n]->delay_buf_out32_fx[i - delay_diff]; - } - } - } - - IF( hCPE->nchan_out == CPE_CHANNELS ) - { - /* upmix the resampled LB / the TCX synchro memory */ - tdm_upmix_plain_fx( tmp_out_TD2_fx[0], tmp_out_TD2_fx[1], tmp_out_TD_fx[0], tmp_out_TD_fx[1], tdm_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx], tdm_den_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx], 0, dft32ms_ovl, 1 ); - } - ELSE - { - Copy32( tmp_out_TD_fx[0], tmp_out_TD2_fx[0], dft32ms_ovl ); - } - - FOR( n = 0; n < hCPE->nchan_out; n++ ) - { - IF( sts[0]->core == ACELP_CORE ) /* ACELP core in primary channel */ - { - switch ( output_Fs ) - { - case 16000: - tmpF_fx = 71582792; - break; - case 32000: - tmpF_fx = 35791396; - break; - case 48000: - tmpF_fx = 23860930; - break; - default: - assert( 0 ); - } - /* cross-fading between regular output synthesis and lerp_flt() resampled synthesis in 3.125 - 1.25 ms OLA part */ - FOR( i = 0; i < delay_diff; i++ ) - { - - Word64 res1 = (Word64) output_fx[n][output_frame - dft32ms_ovl + delay_cldfb + i] * ( delay_diff - i ); - Word64 res2 = (Word64) tmp_out_TD2_fx[n][i] * i; - Word64 res = W_shr( res1, 6 ) + W_shr( res2, 6 ); - res = res * tmpF_fx; - p_output_mem_fx[n][i] = (Word32) W_shr( res, 31 - 6 ); - } - } - ELSE /* TCX core */ - { - /* reconstruct the 3.125 - 1.25 ms OLA part */ - FOR( i = 0; i < delay_diff; i++ ) - { - p_output_mem_fx[n][i] = output_fx[n][output_frame - dft32ms_ovl + delay_cldfb + i]; - } - } - - /* reconstruct the last 1.25 ms part of OLA window */ - FOR( i = delay_diff; i < dft32ms_ovl; i++ ) - { - p_output_mem_fx[n][i] = tmp_out_TD2_fx[n][i]; - } - } - } - - /*----------------------------------------------------------------* - * zero padding TD/MDCT synthesis in order to synchronize - * the upmixed TD/MDCT stereo synthesis with the DFT stereo synthesis - *----------------------------------------------------------------*/ - - IF( hCPE->element_mode == IVAS_CPE_TD && hCPE->stereo_switching_counter == 0 && hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_24k4 ) - { - Word32 step_fx = 0; - tmpF_fx = ONE_IN_Q31; - switch ( output_Fs ) - { - case 16000: - step_fx = 33554432; - break; - case 32000: - step_fx = 16777216; - break; - case 48000: - step_fx = 11184811; - break; - default: - assert( 0 ); - } - /* FOR the first switching frame from DFT to TD, downmix memory too */ - FOR( n = 0; n < delay_comp_TD; n++ ) - { - sts[0]->prev_synth_buffer32_fx[n] = Mpy_32_32( sts[0]->prev_synth_buffer32_fx[n], tmpF_fx ); - tmpF_fx = L_sub_sat( tmpF_fx, step_fx ); - } - } - - IF( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->nchan_out == 1 && !is_DTXrate( hCPE->element_brate ) && is_DTXrate( hCPE->last_element_brate ) ) - { - Copy32( sts[0]->prev_synth_buffer32_fx, sts[1]->prev_synth_buffer32_fx, delay_comp_TD ); - } - - nChannels = ( hCPE->element_mode == IVAS_CPE_MDCT ) ? 2 : hCPE->nchan_out; - FOR( n = 0; n < nChannels; n++ ) - { - IF( hCPE->element_mode == IVAS_CPE_MDCT ) - { - Copy32( sts[n]->prev_synth_buffer32_fx + delay_comp_DFT, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); - delay_signal_fx( output_fx[n], output_frame, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); - ivas_post_proc_fx( NULL, hCPE, n, output_fx[n], output_fx, output_frame, 0 ); - - delay_signal_fx( output_fx[n], output_frame, sts[n]->prev_synth_buffer32_fx, delay_comp_DFT ); - Copy32( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, sts[n]->prev_synth_buffer32_fx + delay_comp_DFT, delay_diff ); - } - ELSE - { - delay_signal_fx( output_fx[n], output_frame, sts[n]->prev_synth_buffer32_fx, delay_comp_TD ); - } - } - - /* handling of DFT->TD switching */ - IF( hCPE->last_element_mode == IVAS_CPE_DFT && !use_cldfb_for_last_dft ) - { - IF( hCPE->element_mode == IVAS_CPE_TD && hCPE->hStereoCng->prev_sid_nodata ) - { - FOR( n = 0; n < hCPE->nchan_out; n++ ) - { - switch ( output_Fs ) - { - case 16000: - tmpF_fx = 107374184; - break; - case 32000: - tmpF_fx = 53687092; - break; - case 48000: - tmpF_fx = 35791396; - break; - default: - assert( 0 ); - } - FOR( i = 0; i < delay_cldfb; i++ ) - { - tmp_out_fx[n][i] = Mpy_32_32( tmp_out_fx[n][i], tmpF_fx ) * ( delay_cldfb - i ); - } - } - } - - /* cross-fading between DFT OLA memory and TD output */ - FOR( n = 0; n < nChannels; n++ ) - { - IF( hCPE->element_mode == IVAS_CPE_MDCT ) - { - switch ( output_Fs ) - { - case 16000: - tmpF_fx = 71582792; - break; - case 32000: - tmpF_fx = 35791396; - break; - case 48000: - tmpF_fx = 23860930; - break; - default: - assert( 0 ); - } - FOR( i = 0; i < delay_diff; i++ ) - { - - Word64 res1 = (Word64) output_fx[n][i + delay_comp_DFT] * ( delay_diff - i ); - Word64 res2 = (Word64) p_output_mem_fx[n][i] * i; - Word64 res = W_shr( res1, 6 ) + W_shr( res2, 6 ); - res = res * tmpF_fx; - output_fx[n][i + delay_comp_DFT] = (Word32) W_shr( res, 31 - 6 ); - } - } - switch ( output_Fs ) - { - case 16000: - tmpF_fx = 107374184; - break; - case 32000: - tmpF_fx = 53687092; - break; - case 48000: - tmpF_fx = 35791396; - break; - default: - assert( 0 ); - } - FOR( i = 0; i < delay_cldfb; i++ ) - { - Word64 res1 = (Word64) tmp_out_fx[n][i] * ( delay_cldfb - i ); - Word64 res2 = (Word64) output_fx[n][i + delay_comp_TD] * i; - Word64 res = W_shr( res1, 6 ) + W_shr( res2, 6 ); - res = res * tmpF_fx; - output_fx[n][i + delay_comp_TD] = (Word32) W_shr( res, 31 - 6 ); - } - } - } - } - - - 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++ ) - { - FOR( Word32 p = 0; p < L_FRAME48k; p++ ) - { - output[n][p] = (float) output_fx[n][p] / ( 1u << 11 ); - } - IF( hCPE->output_mem[n] != NULL ) - { - FOR( Word32 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 ) - { - IF( hCPE->hCoreCoder[n]->hTcxLtpDec != NULL ) - { - FOR( Word32 p = 0; p < L_FRAME48k; p++ ) - { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << output_q ); - } - FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) - { - 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++ ) - { - hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << output_q ); - } - FOR( Word32 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->hCoreCoder[n]->hTcxDec != NULL ) - { - FOR( Word32 k = 0; k < 111; k++ ) - { - hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[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( 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 ); - } - } - - - return; -} - -void synchro_synthesis_fixed_clean( +void synchro_synthesis_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *output_fx[CPE_CHANNELS], /* i/o: output synthesis signal */ @@ -3883,10 +3160,10 @@ void synchro_synthesis_fixed_clean( { hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << output_q ); } - FOR( Word32 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 ); - } + //FOR( Word32 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->hCoreCoder[n]->hTcxDec != NULL ) { FOR( Word32 k = 0; k < 111; k++ ) diff --git a/lib_dec/ivas_td_low_rate_dec.c b/lib_dec/ivas_td_low_rate_dec.c index 0ceb967a1..2b1d358d7 100644 --- a/lib_dec/ivas_td_low_rate_dec.c +++ b/lib_dec/ivas_td_low_rate_dec.c @@ -172,12 +172,6 @@ void tdm_low_rate_dec( st->Q_exc = 0; /*hGSCDec float2fix*/ - floatToFixed_arr(st->hGSCDec->old_y_gain, st->hGSCDec->old_y_gain_fx, Q12, MBANDS_GN); - floatToFixed_arr(st->hGSCDec->lt_ener_per_band, st->hGSCDec->lt_ener_per_band_fx, Q12, MBANDS_GN); - st->hGSCDec->Last_frame_ener_fx = st->hGSCDec->Last_frame_ener < MAX_32 ? floatToFixed(st->hGSCDec->Last_frame_ener, Q3) : MAX_32; - floatToFixed_arr(st->hGSCDec->Last_GSC_spectrum, st->hGSCDec->Last_GSC_spectrum_fx, Q10, L_FRAME); - floatToFixed_arr(st->hGSCDec->last_exc_dct_in, st->hGSCDec->last_exc_dct_in_fx, st->Q_exc, L_FRAME); - //st->hGSCDec->last_ener_fx = float_to_fix16(st->hGSCDec->last_ener, 0); st->GSC_noisy_speech = st->GSC_noisy_speech; st->lp_gainc_fx = float_to_fix16(st->lp_gainc, Q3); st->last_good = st->last_good; @@ -214,12 +208,6 @@ void tdm_low_rate_dec( } /*hGSCDec fix2float*/ - fixedToFloat_arr(st->hGSCDec->old_y_gain_fx, st->hGSCDec->old_y_gain, Q12, MBANDS_GN); - fixedToFloat_arr(st->hGSCDec->lt_ener_per_band_fx, st->hGSCDec->lt_ener_per_band, Q12, MBANDS_GN); - st->hGSCDec->Last_frame_ener = fixedToFloat(st->hGSCDec->Last_frame_ener_fx, Q3); - fixedToFloat_arr(st->hGSCDec->Last_GSC_spectrum_fx, st->hGSCDec->Last_GSC_spectrum, Q10, L_FRAME); - fixedToFloat_arr(st->hGSCDec->last_exc_dct_in_fx, st->hGSCDec->last_exc_dct_in, st->Q_exc, L_FRAME); - st->hGSCDec->last_ener = fixedToFloat(st->hGSCDec->last_ener_fx, 0); st->GSC_noisy_speech = st->GSC_noisy_speech; st->lp_gainc = fixedToFloat(st->lp_gainc_fx, Q3); /*hGSCDec end*/ @@ -504,12 +492,6 @@ void decod_gen_2sbfr( st->Q_exc = 0; /*hGSCDec float2fix*/ - floatToFixed_arr( st->hGSCDec->old_y_gain, st->hGSCDec->old_y_gain_fx, Q12, MBANDS_GN ); - floatToFixed_arr( st->hGSCDec->lt_ener_per_band, st->hGSCDec->lt_ener_per_band_fx, Q12, MBANDS_GN ); - st->hGSCDec->Last_frame_ener_fx = st->hGSCDec->Last_frame_ener < MAX_32 ? floatToFixed( st->hGSCDec->Last_frame_ener, Q3 ) : MAX_32; - floatToFixed_arr( st->hGSCDec->Last_GSC_spectrum, st->hGSCDec->Last_GSC_spectrum_fx, Q10, L_FRAME ); - floatToFixed_arr( st->hGSCDec->last_exc_dct_in, st->hGSCDec->last_exc_dct_in_fx, st->Q_exc, L_FRAME ); - // st->hGSCDec->last_ener_fx = float_to_fix16(st->hGSCDec->last_ener, 0); st->GSC_noisy_speech = st->GSC_noisy_speech; st->lp_gainc_fx = float_to_fix16( st->lp_gainc, Q3 ); st->dm_fx.prev_state = float_to_fix16(st->dispMem[0], 0); @@ -553,12 +535,6 @@ void decod_gen_2sbfr( } /*hGSCDec fix2float*/ - fixedToFloat_arr( st->hGSCDec->old_y_gain_fx, st->hGSCDec->old_y_gain, Q12, MBANDS_GN ); - fixedToFloat_arr( st->hGSCDec->lt_ener_per_band_fx, st->hGSCDec->lt_ener_per_band, Q12, MBANDS_GN ); - st->hGSCDec->Last_frame_ener = fixedToFloat( st->hGSCDec->Last_frame_ener_fx, Q3 ); - fixedToFloat_arr( st->hGSCDec->Last_GSC_spectrum_fx, st->hGSCDec->Last_GSC_spectrum, Q10, L_FRAME ); - fixedToFloat_arr( st->hGSCDec->last_exc_dct_in_fx, st->hGSCDec->last_exc_dct_in, st->Q_exc, L_FRAME ); - st->hGSCDec->last_ener = fixedToFloat( st->hGSCDec->last_ener_fx, 0 ); st->GSC_noisy_speech = st->GSC_noisy_speech; st->lp_gainc = fixedToFloat( st->lp_gainc_fx, Q3 ); st->dispMem[0] = fixedToFloat(st->dm_fx.prev_state, 0); diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index b176dc455..27a60c3cc 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -496,7 +496,7 @@ typedef struct igfdec_instance_struct int16_t *flag_sparse; int16_t flag_sparseBuf[N_MAX_TCX - IGF_START_MN]; - float *virtualSpec_float; + float *virtualSpec_float; // needed in MCT path float virtualSpecBuf[N_MAX_TCX - IGF_START_MN]; Word32 *virtualSpec_fx; Word32 virtualSpec[N_MAX_TCX - IGF_START_MN]; /* Q31 | buffer for temp flattening */ @@ -765,7 +765,9 @@ typedef struct WI_dec_structure typedef struct ld_music_postfilt_structure { +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float LDm_mem_etot; /* LD music post-filter - total energy memory */ +#endif Word16 LDm_mem_etot_fx; /* LD music post-filter - total energy memory */ int16_t LDm_last_music_flag; /* LD music post-filter - last music flag */ @@ -777,25 +779,39 @@ typedef struct ld_music_postfilt_structure int16_t LDm_nb_thr_3; //Word16 LDm_nb_thr_3; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float dct_post_old_exc[DCT_L_POST - OFFSET2]; +#endif Word16 dct_post_old_exc_fx[DCT_L_POST - OFFSET2]; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float LDm_thres[4]; /* LD music post-filter - Classification threshold */ +#endif Word16 LDm_thres_fx[4]; /* LD music post-filter - Classification threshold */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float LDm_lt_diff_etot[MAX_LT]; /* LD music post-filter - long-term total energy variation */ +#endif Word16 LDm_lt_diff_etot_fx[MAX_LT]; /* LD music post-filter - long-term total energy variation */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float LDm_enh_lp_gbin[VOIC_BINS_HR]; /* LD music post-filter - smoothed suppression gain, per bin FFT */ +#endif Word16 LDm_enh_lp_gbin_fx[VOIC_BINS_HR]; /* LD music post-filter - smoothed suppression gain, per bin FFT */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float LDm_enh_lf_EO[VOIC_BINS_HR]; /* LD music post-filter - old per bin E for previous half frame */ +#endif Word32 LDm_enh_lf_EO_fx[VOIC_BINS_HR]; /* LD music post-filter - old per bin E for previous half frame */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float LDm_enh_min_ns_gain; /* LD music post-filter - minimum suppression gain */ +#endif Word16 LDm_enh_min_ns_gain_fx; /* LD music post-filter - minimum suppression gain */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float LDm_bckr_noise[MBANDS_GN_LD]; /* LD music post-filter - background noise estimation per critical band */ +#endif Word32 LDm_bckr_noise_fx[MBANDS_GN_LD]; /* LD music post-filter - background noise estimation per critical band */ float filt_lfE[DCT_L_POST]; @@ -2249,9 +2265,9 @@ typedef struct Decoder_State 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]; /*Q0*/ + Word32 delay_buf_out32_fx[HQ_DELTA_MAX * HQ_DELAY_COMP]; /*Q11*/ #ifdef IVAS_FLOAT_FIXED - Word16 exp_delay_buf_out; + //Word16 exp_delay_buf_out; #endif float old_Aq_12_8[M + 1]; /* old Aq[] for core switching */ diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index dacab808e..2a6858056 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -2494,7 +2494,7 @@ void ivas_swb_tbe_dec_fx( set16_fx( st->prev_SWB_fenv_fx, tmp, SWB_FENV ); /* Q1 */ } - FOR( i = 0; i < L_FRAME16k + L_SHB_LAHEAD; i++ ) + FOR( i = 0; i < L_FRAME16k; i++ ) { shaped_shb_excitation_fx_32[i] = L_shl( shaped_shb_excitation_fx[i], Q11 - Q_bwe_exc ); move32(); diff --git a/lib_dec/tonalMDCTconcealment.c b/lib_dec/tonalMDCTconcealment.c index 5e019bb22..0d488de88 100644 --- a/lib_dec/tonalMDCTconcealment.c +++ b/lib_dec/tonalMDCTconcealment.c @@ -1087,7 +1087,224 @@ void TonalMDCTConceal_SaveTimeSignal_ivas( return; } +#ifdef IVAS_FLOAT_FIXED +void TonalMdctConceal_create_concealment_noise_ivas_fx( + Word32 concealment_noise[L_FRAME48k], + Word16 *concealment_noise_exp, + CPE_DEC_HANDLE hCPE, + const Word16 L_frameTCX, + const Word16 L_frame, + const Word16 idchan, + const Word16 subframe_idx, + const Word16 core, + const Word16 crossfade_gain, + const TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode ) +{ + STEREO_MDCT_DEC_DATA_HANDLE hStereoMdct; + TonalMDCTConcealPtr hTonalMDCTConc; + Decoder_State *st; + 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 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; + push_wmops( "create_conc_noise" ); + + hStereoMdct = hCPE->hStereoMdct; + st = hCPE->hCoreCoder[idchan]; + hTonalMDCTConc = st->hTonalMDCTConc; + hFdCngCom = st->hFdCngDec->hFdCngCom; + rnd = &hStereoMdct->noise_seeds_channels[idchan]; + rnd_c = &hStereoMdct->noise_seed_common; + + /* determine start bin for IGF */ + IF ( EQ_16(st->igf, 0 )) + { + IF ( EQ_16(st->narrowBand, 0 )) + { + /* minimum needed for output with sampling rates lower then the + nominal sampling rate */ + crossOverFreq = s_min( L_frameTCX, L_frame ); + } + ELSE + { + crossOverFreq = L_frameTCX; move16(); + } + } + ELSE + { + crossOverFreq = s_min( st->hIGFDec->infoIGFStartLine, L_frameTCX ); + } + + /* 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 = s_max( max_noise_line, hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] + 1 ); + } + + /* first lost frame is handled separately */ + IF ( !hTonalMDCTConc->lastBlockData.blockIsConcealed ) + { + *rnd = add(1977, idchan); + /* will be set twice when looping over two channels, but does not matter */ + *rnd_c = 1979; + } + + 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++ ) + { + *rnd = own_random( rnd ); + concealment_noise[i] = *rnd; + } + *concealment_noise_exp = 31; + pop_wmops(); + + return; + } + + save_rnd_c = *rnd_c; + + Word16 c_e = 1; + Word16 c_inv_e = 1; + + 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(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)); + } + } + + /* pre-compute the noise shape for later weighting of the noise spectra */ + cngNoiseLevelPtr = &hFdCngCom->cngNoiseLevel[0]; + last_scf_e = hFdCngCom->cngNoiseLevelExp; + + inc = ( st->core > TCX_20_CORE ) ? 2 : 1; + start_idx = idiv1616(hFdCngCom->startBand, inc); + stop_idx = idiv1616(hFdCngCom->stopFFTbin, inc); + + FOR ( i = 0; i < start_idx; i++ ) + { + noise_shape_buffer[i] = 0; + noise_shape_buffer_e[i] = 0; + } + 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); + } + + 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])); + } + + last_scf = Sqrt32( *( cngNoiseLevelPtr - inc ), &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)); + + noise_shape_buffer_common_exp = last_scf_e; + } + ELSE + { + last_scf = L_shl(last_scf, sub(last_scf_e, noise_shape_buffer_common_exp)); + } + + FOR ( ; i < max_noise_line; i++ ) + { + noise_shape_buffer[i] = last_scf; + } + + /* 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) ) ) ) + { + /* current channel is TCX20 -> generate noise for "full-length" spectrum */ + + 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)) + { + 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; + } + + } + 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++ ) + { + *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)) + { + 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; + + *rnd_c = own_random( rnd_c ); + } + } + + IF ( st->tonal_mdct_plc_active ) + { + FOR ( i = crossOverFreq; i < s_max( crossOverFreq, hTonalMDCTConc->pTCI_float->lowerIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] ); ++i ) + { + concealment_noise[i] = 0; + } + } + + /* restore common seed + - 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) ) ) + { + *rnd_c = save_rnd_c; + } + + st->seed_tcx_plc = *rnd; + + pop_wmops(); + + return; +} +#endif void TonalMdctConceal_create_concealment_noise_ivas( float concealment_noise[L_FRAME48k], CPE_DEC_HANDLE hCPE, diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index be2aace7d..3f4368467 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -180,7 +180,7 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( move16(); //hTonalMDCTConc->pTCI_float = (TonalComponentsInfo_fix *) hTonalMDCTConc->timeDataBuffer; - //hTonalMDCTConc->pTCI_float = &hTonalMDCTConc->pTCI_fix1; + hTonalMDCTConc->pTCI_float = &hTonalMDCTConc->pTCI_float1; move16(); hTonalMDCTConc->lastPitchLag = L_deposit_l( 0 ); diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index fab2ad08c..ac3284302 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -752,41 +752,35 @@ ivas_error TDREND_GetMix( #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_GetMix_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - float *output_flt[], /* i/o: ISM object synth / rendered output in 0,1 */ + Word32 *output[], /* i/o: ISM object synth / rendered output in 0,1 */ const Word16 subframe_length, /* i/o: subframe length */ const Word16 subframe_idx, /* i : Subframe index to 5 ms subframe */ const Word16 ism_md_subframe_update /* i : Number of subframes to delay ism metadata to sync with audio */ ) { - int16_t i; + Word16 i; TDREND_SRC_t *Src_p; TDREND_SRC_SPATIAL_t *SrcSpatial_p; TDREND_SRC_REND_t *SrcRend_p; ivas_error error; - float output_buf_flt[2][L_SPATIAL_SUBFR_48k]; /* Temp buffer for left/right rendered signal */ - float hrf_left_delta_flt[SFX_SPAT_BIN_MAX_FILTER_LENGTH]; - float hrf_right_delta_flt[SFX_SPAT_BIN_MAX_FILTER_LENGTH]; Word32 output_buf[2][L_SPATIAL_SUBFR_48k]; /* Temp buffer for left/right rendered signal */ Word32 hrf_left_delta[SFX_SPAT_BIN_MAX_FILTER_LENGTH]; Word32 hrf_right_delta[SFX_SPAT_BIN_MAX_FILTER_LENGTH]; Word16 intp_count; Word16 subframe_update_flag; + Word16 hrf_left_delta_e = 0, hrf_right_delta_e = 0; subframe_update_flag = (Word16)EQ_16( subframe_idx, ism_md_subframe_update ); error = IVAS_ERR_OK; /* Clear the output buffer to accumulate rendered sources */ - set_f( output_buf_flt[0], 0.0f, subframe_length ); - set_f( output_buf_flt[1], 0.0f, subframe_length ); set32_fx( output_buf[0], 0, subframe_length ); set32_fx( output_buf[1], 0, subframe_length ); - /* Clear interpolation buffers and counter */ - set_f( hrf_left_delta_flt, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); - set_f( hrf_right_delta_flt, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); set32_fx( hrf_left_delta, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); set32_fx( hrf_right_delta, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); + intp_count = 0; move16(); @@ -802,49 +796,29 @@ ivas_error TDREND_GetMix_fx( test(); test(); IF ( ( SrcRend_p->PlayStatus == TDREND_PLAYSTATUS_PLAYING ) && ( hBinRendererTd->Listener_p->PoseUpdated || SrcSpatial_p->Updated ) ) { - // Float to fixed conversions - Word16 hrf_left_prev_e, hrf_right_prev_e; - Word16 hrf_left_delta_e = 0, hrf_right_delta_e = 0; - Word16 hrf_len = s_min(hBinRendererTd->HrFiltSet_p->FiltLength, SFX_SPAT_BIN_MAX_FILTER_LENGTH); - f2me_buf(Src_p->hrf_left_prev, Src_p->hrf_left_prev_fx, &hrf_left_prev_e, hrf_len); - f2me_buf(Src_p->hrf_right_prev, Src_p->hrf_right_prev_fx, &hrf_right_prev_e, hrf_len); - for (int j = 0; j < 3; j++) - { - SrcSpatial_p->Pos_p_fx[j] = float_to_fix(SrcSpatial_p->Pos_p[j], Q25); - } - TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( hBinRendererTd, SrcRend_p, SrcSpatial_p, - Src_p->hrf_left_prev_fx, &hrf_left_prev_e, Src_p->hrf_right_prev_fx, &hrf_right_prev_e, + Src_p->hrf_left_prev_fx, &Src_p->hrf_left_prev_e, Src_p->hrf_right_prev_fx, &Src_p->hrf_right_prev_e, hrf_left_delta, &hrf_left_delta_e, hrf_right_delta, &hrf_right_delta_e, &intp_count, &Src_p->filterlength, &Src_p->itd, &Src_p->Gain_fx, Src_p, subframe_update_flag ); - - // Fix to float conversions - *SrcRend_p->DirGain_p = me2f_16(*SrcRend_p->DirGain_p_fx, 1); - *SrcRend_p->DistGain_p = me2f_16(*SrcRend_p->DistGain_p_fx, 1); - Src_p->Gain = fix16_to_float(Src_p->Gain_fx, Q14); - Src_p->azim_prev = fix_to_float(Src_p->azim_prev_fx, Q22); - Src_p->elev_prev = fix_to_float(Src_p->elev_prev_fx, Q22); - me2f_buf(Src_p->hrf_left_prev_fx, hrf_left_prev_e, Src_p->hrf_left_prev, hrf_len); - me2f_buf(hrf_left_delta, hrf_left_delta_e, hrf_left_delta_flt, hrf_len); - me2f_buf(Src_p->hrf_right_prev_fx, hrf_right_prev_e, Src_p->hrf_right_prev, hrf_len); - me2f_buf(hrf_right_delta, hrf_right_delta_e, hrf_right_delta_flt, hrf_len); } /* Render source if needed */ - if ( ( SrcRend_p->InputAvailable == TRUE ) && ( SrcRend_p->PlayStatus == TDREND_PLAYSTATUS_PLAYING ) ) + IF ( ( SrcRend_p->InputAvailable == TRUE ) && ( SrcRend_p->PlayStatus == TDREND_PLAYSTATUS_PLAYING ) ) { - error = TDREND_REND_RenderSourceHRFilt( Src_p, hrf_left_delta_flt, hrf_right_delta_flt, intp_count, output_buf_flt, subframe_length ); + error = TDREND_REND_RenderSourceHRFilt_fx( Src_p, hrf_left_delta, &hrf_left_delta_e, + hrf_right_delta, &hrf_right_delta_e, intp_count, output_buf, subframe_length ); } } + /* Populate output variable */ - mvr2r( output_buf_flt[0], output_flt[0] + subframe_idx * subframe_length, subframe_length ); /* Left */ - mvr2r( output_buf_flt[1], output_flt[1] + subframe_idx * subframe_length, subframe_length ); /* Right */ + Copy32( output_buf[0], output[0] + imult1616(subframe_idx, subframe_length), subframe_length ); /* Left */ + Copy32( output_buf[1], output[1] + imult1616(subframe_idx, subframe_length), subframe_length ); /* Right */ /* Clear the PoseUpdated and Source position update flags */ - TDREND_Clear_Update_flags( hBinRendererTd ); + TDREND_Clear_Update_flags_fx( hBinRendererTd ); return error; } diff --git a/lib_rend/ivas_objectRenderer_hrFilt.c b/lib_rend/ivas_objectRenderer_hrFilt.c index e4ba82ce4..856a74a3b 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt.c +++ b/lib_rend/ivas_objectRenderer_hrFilt.c @@ -92,6 +92,56 @@ ivas_error TDREND_REND_RenderSourceHRFilt( return IVAS_ERR_OK; } +#ifdef IVAS_FLOAT_FIXED +ivas_error TDREND_REND_RenderSourceHRFilt_fx( + TDREND_SRC_t *Src_p, /* i/o: The source to be rendered */ + Word32 *hrf_left_delta_fx, /* i/o: Left filter interpolation delta */ + Word16 *hrf_left_delta_e, /* i/o: Left filter interpolation delta exp */ + Word32 *hrf_right_delta_fx, /* i/o: Right filter interpolation delta */ + Word16 *hrf_right_delta_e, /* i/o: Right filter interpolation delta exp */ + const Word16 intp_count, /* i : Interpolation count */ + Word32 output_buf_fx[][L_SPATIAL_SUBFR_48k], /* o : Output buffer */ + const Word16 subframe_length /* i : Subframe length in use */ +) +{ + Word32 LeftOutputFrame_fx[L_SPATIAL_SUBFR_48k]; // will have same Q as Src_p->InputFrame_p_fx + Word32 RightOutputFrame_fx[L_SPATIAL_SUBFR_48k]; // will have same Q as Src_p->InputFrame_p_fx + Word16 left_filter_e; + Word16 right_filter_e; + + TDREND_Apply_ITD_fx( Src_p->InputFrame_p_fx, LeftOutputFrame_fx, RightOutputFrame_fx, + &Src_p->previtd, Src_p->itd, Src_p->mem_itd_fx, subframe_length ); + + left_filter_e = s_max( Src_p->hrf_left_prev_e, *hrf_left_delta_e ); + right_filter_e = s_max( Src_p->hrf_right_prev_e, *hrf_right_delta_e ); + + /* Scaling prev and delta HRF filter values to common Q-factor */ + Scale_sig32( Src_p->hrf_left_prev_fx, Src_p->filterlength, sub( Src_p->hrf_left_prev_e, left_filter_e ) ); + Scale_sig32( hrf_left_delta_fx, Src_p->filterlength, sub( *hrf_left_delta_e, left_filter_e ) ); + Scale_sig32( Src_p->hrf_right_prev_fx, Src_p->filterlength, sub( Src_p->hrf_right_prev_e, right_filter_e ) ); + Scale_sig32( hrf_right_delta_fx, Src_p->filterlength, sub( *hrf_right_delta_e, left_filter_e ) ); + Src_p->hrf_left_prev_e = left_filter_e; + move16(); + *hrf_left_delta_e = left_filter_e; + move16(); + Src_p->hrf_right_prev_e = right_filter_e; + move16(); + *hrf_right_delta_e = right_filter_e; + move16(); + + TDREND_firfilt_fx( LeftOutputFrame_fx, Src_p->hrf_left_prev_fx, left_filter_e, hrf_left_delta_fx, intp_count, Src_p->mem_hrf_left_fx, subframe_length, Src_p->filterlength, Src_p->Gain_fx, Src_p->prevGain_fx ); + TDREND_firfilt_fx( RightOutputFrame_fx, Src_p->hrf_right_prev_fx, right_filter_e, hrf_right_delta_fx, intp_count, Src_p->mem_hrf_right_fx, subframe_length, Src_p->filterlength, Src_p->Gain_fx, Src_p->prevGain_fx ); + + Src_p->prevGain_fx = Src_p->Gain_fx; + move16(); + + /* Copy to accumulative output frame */ + v_add_32( LeftOutputFrame_fx, output_buf_fx[0], output_buf_fx[0], subframe_length ); // Same Q as Src_p->InputFrame_p_fx + v_add_32( RightOutputFrame_fx, output_buf_fx[1], output_buf_fx[1], subframe_length ); // Same Q as Src_p->InputFrame_p_fx + + return IVAS_ERR_OK; +} +#endif /*-------------------------------------------------------------------* * GetFilterFromAngle() diff --git a/lib_rend/ivas_objectRenderer_mix.c b/lib_rend/ivas_objectRenderer_mix.c index 0505ac163..97a64b3a3 100644 --- a/lib_rend/ivas_objectRenderer_mix.c +++ b/lib_rend/ivas_objectRenderer_mix.c @@ -414,7 +414,14 @@ ivas_error TDREND_MIX_Init( TDREND_SPATIAL_VecInit( hBinRendererTd->Listener_p->Front, 0.0f, 0.0f, -1.0f ); TDREND_SPATIAL_VecInit( hBinRendererTd->Listener_p->Up, 0.0f, 1.0f, 0.0f ); TDREND_SPATIAL_VecInit( hBinRendererTd->Listener_p->Right, 1.0f, 0.0f, 0.0f ); - + +#ifdef IVAS_FLOAT_FIXED + TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Pos_fx, 0, 0, 0 ); + 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 ); + TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Right_fx, ONE_IN_Q30, 0, 0 ); +#endif /* Init HR filter set */ if ( *hHrtfTD == NULL ) { diff --git a/lib_rend/ivas_objectRenderer_sfx.c b/lib_rend/ivas_objectRenderer_sfx.c index f0c24ef84..456e8367c 100644 --- a/lib_rend/ivas_objectRenderer_sfx.c +++ b/lib_rend/ivas_objectRenderer_sfx.c @@ -37,6 +37,9 @@ #include "ivas_rom_rend.h" #include "prot.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx2.h" +#endif /*---------------------------------------------------------------------* @@ -49,7 +52,9 @@ *---------------------------------------------------------------------*/ static void sincResample( const float *input, float *output, const int16_t length_in, const int16_t length_out ); - +#ifdef IVAS_FLOAT_FIXED +static void sincResample_fx( const Word32 *input_fx, Word32 *output_fx, const Word16 length_in, const Word16 length_out ); +#endif /*---------------------------------------------------------------------* * TDREND_Apply_ITD() @@ -156,6 +161,121 @@ void TDREND_Apply_ITD( return; } +#ifdef IVAS_FLOAT_FIXED +void TDREND_Apply_ITD_fx( + Word32 *input_fx, /* i : Input subframe to be time adjusted Qx */ + Word32 *out_left_fx, /* o : Output left channel with ITD applied Qx */ + Word32 *out_right_fx, /* o : Output right channel with ITD applied Qx */ + Word16 *previtd, /* i/o: Previous ITD value */ + const Word16 itd, /* i : Current subframe ITD value */ + Word32 *mem_itd_fx, /* i/o: ITD buffer memory Qx */ + const Word16 length /* i : Subframe length */ +) +{ + Word16 transition_len; + Word16 tlen1, tlen2, tlen3; + Word16 length_in1; + Word16 length_in2; + Word16 currShift; + Word16 prevShift; + Word32 *pstart1_fx; + Word32 *pstart2_fx; + Word32 *pstart3_fx; + Word32 buffer_fx[ITD_MEM_LEN + L_SUBFRAME5MS_48k]; + Word32 *p_input_fx; + Word32 *out_buf_A_fx, *out_buf_B_fx; + + push_wmops( "TDREND_Apply_ITD" ); + + /* Prepare resampling buffer */ + Copy32( mem_itd_fx, buffer_fx, ITD_MEM_LEN ); /* Retrieve memory */ + p_input_fx = buffer_fx + ITD_MEM_LEN; /* pointer to the current subframe */ + Copy32( input_fx, p_input_fx, length ); /* input current subframe */ + Copy32( buffer_fx + length, mem_itd_fx, ITD_MEM_LEN ); /* update memory for next frame */ + + currShift = abs_s( itd ); + prevShift = abs_s( *previtd ); + tlen3 = s_max( 0, sub( SFX_SPAT_BIN_SINC_M, currShift ) ); /* Make sure there is enough look-ahead for the sinc resampling */ + transition_len = sub( length, tlen3 ); + + IF ( ( ( *previtd ) * itd ) < 0 ) + { + /* ITD sign change - apply shift on both channels */ + Word16 tmp1 = imult1616( transition_len, prevShift ); + Word16 tmp2 = add( prevShift, currShift ); + Word16 tmp_e; + Word16 tmp3 = BASOP_Util_Divide1616_Scale( tmp1, tmp2, &tmp_e ); + Word16 tmp4; + Word16 tmp_e2 = BASOP_Util_Add_MantExp( tmp3, tmp_e, ONE_IN_Q14, 0, &tmp4 ); + tmp4 = shr( tmp4, sub( 15, tmp_e2 ) ); // Q0 + tlen1 = tmp4; + + tlen2 = sub( transition_len, tlen1 ); + pstart1_fx = p_input_fx - prevShift; + length_in1 = add( tlen1, prevShift ); + pstart2_fx = pstart1_fx + length_in1; + length_in2 = sub( tlen2, currShift ); + pstart3_fx = pstart2_fx + length_in2; + } + ELSE + { + /* ITD sign stays the same, or one of them is zero */ + tlen1 = transition_len; + move16(); + tlen2 = 0; + move16(); + pstart1_fx = p_input_fx - prevShift; + length_in1 = sub( add( transition_len, prevShift ), currShift ); + pstart2_fx = pstart1_fx + length_in1; + length_in2 = 0; + move16(); + pstart3_fx = pstart2_fx + add( length_in2, currShift ); + } + + IF ( *previtd == 0 ) + { + IF ( itd > 0 ) + { + out_buf_A_fx = out_right_fx; + out_buf_B_fx = out_left_fx; + } + ELSE + { + out_buf_A_fx = out_left_fx; + out_buf_B_fx = out_right_fx; + } + } + ELSE + { + IF ( *previtd > 0 ) + { + out_buf_A_fx = out_right_fx; + out_buf_B_fx = out_left_fx; + } + ELSE + { + out_buf_A_fx = out_left_fx; + out_buf_B_fx = out_right_fx; + } + } + + /* Output buffer A */ + sincResample_fx( pstart1_fx, out_buf_A_fx, length_in1, tlen1 ); + Copy32( pstart2_fx, out_buf_A_fx + tlen1, sub( length, tlen1 ) ); + + /* Output buffer B */ + Copy32( p_input_fx, out_buf_B_fx, tlen1 ); + sincResample_fx( pstart2_fx, out_buf_B_fx + tlen1, length_in2, tlen2 ); + Copy32( pstart3_fx, out_buf_B_fx + transition_len, tlen3 ); + + *previtd = itd; + move16(); + + pop_wmops(); + return; +} +#endif + /*---------------------------------------------------------------------* * sincResample() * @@ -227,6 +347,91 @@ static void sincResample( return; } +#ifdef IVAS_FLOAT_FIXED +static void sincResample_fx( + const Word32 *input_fx, /*i : Input signal Qx */ + Word32 *output_fx, /*o : Output signal Qx */ + const Word16 length_in, /*i : Input length */ + const Word16 length_out /*i : Output length */ +) +{ + Word16 snc0; + Word16 i, j; + Word16 t; + Word32 t_step_fx; + Word16 t_step_e; + Word32 t_frac_fx; + Word16 t_frac_e; + Word32 tmp_fx; + const Word32 *p_mid_fx; + const Word32 *p_forward_fx; + const Word32 *p_backward_fx; + const Word32 *p_sinc_forward_fx; + const Word32 *p_sinc_backward_fx; + + // epsilon: 1e-15f + const Word32 eps = 1208925824; + const Word16 eps_e = -49; + + /* avoid division by 0 */ + IF( 0 == length_out ) + { + return; + } + + /* Compute fractional time step */ + t_step_fx = L_deposit_h( BASOP_Util_Divide1616_Scale( length_in, length_out, &t_step_e ) ); + t_frac_fx = 0; + move32(); + t_frac_e = 0; + move16(); + + FOR( i = 0; i < length_out; i++ ) + { + Word16 t_frac_plus_eps_e; + Word32 t_frac_plus_eps = BASOP_Util_Add_Mant32Exp( t_frac_fx, t_frac_e, eps, eps_e, &t_frac_plus_eps_e ); + t = extract_l( L_shr( t_frac_plus_eps, sub( 31, t_frac_plus_eps_e ) ) ); // Q0 + + /* Calculate the sinc-index for the center value of the sinc */ + Word32 center_val; + Word16 center_val_e; + center_val = BASOP_Util_Add_Mant32Exp( t_frac_plus_eps, t_frac_plus_eps_e, L_negate( L_deposit_h( t ) ), 15, ¢er_val_e ); + center_val_e = add( center_val_e, 6 ); // center_val * SFX_SPAT_BIN_NUM_SUBSAMPLES (i.e. 64) + center_val = BASOP_Util_Add_Mant32Exp( center_val, center_val_e, ONE_IN_Q29, 1, ¢er_val_e ); + snc0 = extract_l( L_shr( center_val, sub( 31, center_val_e ) ) ); + + /* Run convolution forward and backward from mid point */ + p_mid_fx = input_fx + t; + p_forward_fx = p_mid_fx + 1; + p_backward_fx = p_mid_fx - 1; + p_sinc_forward_fx = SincTable_fx + SFX_SPAT_BIN_NUM_SUBSAMPLES - snc0; + p_sinc_backward_fx = SincTable_fx + SFX_SPAT_BIN_NUM_SUBSAMPLES + snc0; + + tmp_fx = Mpy_32_32( *p_mid_fx, SincTable_fx[snc0] ); /* Middle point */ + + FOR( j = 0; j < SFX_SPAT_BIN_SINC_M - 1; j++ ) + { + tmp_fx = L_add( tmp_fx, L_add( Mpy_32_32( *p_forward_fx, *p_sinc_forward_fx ), Mpy_32_32( *p_backward_fx, *p_sinc_backward_fx ) ) ); + p_sinc_forward_fx += SFX_SPAT_BIN_NUM_SUBSAMPLES; + p_sinc_backward_fx += SFX_SPAT_BIN_NUM_SUBSAMPLES; + p_forward_fx++; + p_backward_fx--; + } + + tmp_fx = L_add( tmp_fx, Mpy_32_32( *p_forward_fx, *p_sinc_forward_fx ) ); /* Integer index always rounded down --> 4 steps backward, 5 steps forward */ + + output_fx[i] = tmp_fx; + move32(); + + /* Advance fractional time */ + t_frac_fx = BASOP_Util_Add_Mant32Exp( t_frac_fx, t_frac_e, t_step_fx, t_step_e, &t_frac_e ); + } + + return; +} + +#endif + /*-------------------------------------------------------------------* * TDREND_firfilt() * @@ -286,3 +491,73 @@ void TDREND_firfilt( return; } + +#ifdef IVAS_FLOAT_FIXED +void TDREND_firfilt_fx( + Word32 *signal_fx, /* i/o: Input signal / Filtered signal Qx */ + Word32 *filter_fx, /* i/o: FIR filter Qy */ + const Word16 filter_e, /* i : FIR filter exp */ + const Word32 *filter_delta_fx, /* i : FIR filter delta Qy */ + const Word16 intp_count, /* i : interpolation count */ + Word32 *mem_fx, /* i/o: filter memory Qx */ + const Word16 subframe_length, /* i : Length of signal */ + const Word16 filterlength, /* i : Filter length */ + const Word16 Gain_fx, /* i : Gain Q14 */ + const Word16 prevGain_fx /* i : Previous gain Q14 */ +) +{ + /* NOTE: this function is implemented with the assumption that the exponent/Q-factor of input signal will not change. */ + Word32 buffer_fx[SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 + L_SUBFRAME5MS_48k]; + Word32 *p_signal_fx; + Word32 *p_tmp_fx; + Word32 *p_filter_fx; + Word16 i, j; + Word32 tmp_fx; + Word16 step_fx, gain_tmp_fx, gain_delta_fx; + Word16 tmp_e; + + gain_delta_fx = sub( Gain_fx, prevGain_fx ); // Q14 + step_fx = BASOP_Util_Divide1616_Scale( gain_delta_fx, subframe_length, &tmp_e ); + tmp_e = sub( tmp_e, Q14 ); + step_fx = shl_sat( step_fx, tmp_e ); // Q15 + gain_tmp_fx = shl_sat( prevGain_fx, 1 ); // Q15 + + /* Handle memory */ + p_signal_fx = buffer_fx + sub( filterlength, 1 ); + Copy32( mem_fx, buffer_fx, sub( filterlength, 1 ) ); /* Insert memory */ + Copy32( signal_fx, buffer_fx + sub( filterlength, 1 ), subframe_length ); /* Insert current frame */ + Copy32( signal_fx + add( sub( subframe_length, filterlength ), 1 ), mem_fx, sub( filterlength, 1 ) ); /* Update memory for next frame */ + + /* Convolution */ + FOR( i = 0; i < subframe_length; i++ ) + { + tmp_fx = 0; + move32(); + tmp_e = 0; + move16(); + p_tmp_fx = p_signal_fx + i; + p_filter_fx = filter_fx; + + + FOR( j = 0; j < filterlength; j++ ) + { + tmp_fx = L_add( tmp_fx, Mpy_32_32( *p_filter_fx, *p_tmp_fx ) ); + p_filter_fx++; + p_tmp_fx--; + } + + tmp_fx = L_shl( tmp_fx, filter_e ); // This is done to keep the output Q same as input Q for signal + + /* Apply linear gain interpolation in case of abrupt gain changes */ + gain_tmp_fx = add( gain_tmp_fx, step_fx ); + signal_fx[i] = Mpy_32_16_1( tmp_fx, gain_tmp_fx ); + + IF( i < intp_count ) + { + v_add_fx( filter_fx, filter_delta_fx, filter_fx, filterlength ); + } + } + + return; +} +#endif diff --git a/lib_rend/ivas_objectRenderer_sources.c b/lib_rend/ivas_objectRenderer_sources.c index 82cbb77c4..130a1faa6 100644 --- a/lib_rend/ivas_objectRenderer_sources.c +++ b/lib_rend/ivas_objectRenderer_sources.c @@ -870,6 +870,9 @@ static void TDREND_SRC_SPATIAL_Init( { /* Source position */ TDREND_SPATIAL_VecInit( SrcSpatial_p->Pos_p + nC * 3, 0.0f, 0.0f, 0.0f ); +#ifdef IVAS_FLOAT_FIXED + TDREND_SPATIAL_VecInit_fx( SrcSpatial_p->Pos_p_fx + nC * 3, 0, 0, 0 ); +#endif /* Source direction */ TDREND_SPATIAL_VecInit( SrcSpatial_p->Front_p + nC * 3, 0.0f, 0.0f, 1.0f ); @@ -1321,8 +1324,12 @@ void TDREND_SRC_Init_fx( set32_fx( Src_p->hrf_right_prev_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); Src_p->hrf_left_prev_fx[0] = ONE_IN_Q30; move32(); + Src_p->hrf_left_prev_e = 1; + move16(); Src_p->hrf_right_prev_fx[0] = ONE_IN_Q30; move32(); + Src_p->hrf_right_prev_e = 1; + move16(); Src_p->azim_prev_fx = 0; move32(); Src_p->elev_prev_fx = 0; @@ -1356,6 +1363,11 @@ void TDREND_SRC_Init( set_f( Src_p->mem_itd, 0.0f, ITD_MEM_LEN ); set_f( Src_p->mem_hrf_left, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 ); set_f( Src_p->mem_hrf_right, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 ); +#ifdef IVAS_FLOAT_FIXED + set32_fx( Src_p->mem_itd_fx, 0, ITD_MEM_LEN ); + set32_fx( Src_p->mem_hrf_left_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 ); + set32_fx( Src_p->mem_hrf_right_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 ); +#endif set_f( Src_p->hrf_left_prev, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); set_f( Src_p->hrf_right_prev, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); @@ -1366,6 +1378,12 @@ void TDREND_SRC_Init( Src_p->Gain = 1; Src_p->prevGain = 1.0f; #ifdef IVAS_FLOAT_FIXED + set32_fx(Src_p->hrf_left_prev_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH); + set32_fx(Src_p->hrf_right_prev_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH); + Src_p->hrf_left_prev_fx[0] = ONE_IN_Q30; + Src_p->hrf_left_prev_e = 1; + Src_p->hrf_right_prev_fx[0] = ONE_IN_Q30; + Src_p->hrf_right_prev_e = 1; Src_p->azim_prev_fx = 0; Src_p->elev_prev_fx = 0; Src_p->Gain_fx = ONE_IN_Q14; diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 52d0340eb..7371e258c 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -996,7 +996,7 @@ ivas_error TDREND_GetMix( #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_GetMix_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - float *output_flt[], /* i/o: ISM object synth / rendered output in 0,1 */ + Word32 *output[], /* i/o: ISM object synth / rendered output in 0,1 */ const Word16 subframe_length, /* i/o: subframe length */ const Word16 subframe_idx, /* i : Subframe index to 5 ms subframe */ const Word16 ism_md_subframe_update /* i : Number of subframes to delay ism metadata to sync with audio */ @@ -1066,6 +1066,18 @@ ivas_error TDREND_REND_RenderSourceHRFilt( float output_buf[][L_SPATIAL_SUBFR_48k], /* o : Output buffer */ const int16_t subframe_length /* i : Subframe length in use */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error TDREND_REND_RenderSourceHRFilt_fx( + TDREND_SRC_t *Src_p, /* i/o: The source to be rendered */ + Word32 *hrf_left_delta_fx, /* i/o: Left filter interpolation delta */ + Word16 *hrf_left_delta_e, /* i/o: Left filter interpolation delta exp */ + Word32 *hrf_right_delta_fx, /* i/o: Right filter interpolation delta */ + Word16 *hrf_right_delta_e, /* i/o: Right filter interpolation delta exp */ + const Word16 intp_count, /* i : Interpolation count */ + Word32 output_buf_fx[][L_SPATIAL_SUBFR_48k], /* o : Output buffer */ + const Word16 subframe_length /* i : Subframe length in use */ +); +#endif /* ----- Object renderer - sources ----- */ @@ -1305,6 +1317,18 @@ void TDREND_Apply_ITD( const int16_t length /* i : Subframe length */ ); +#ifdef IVAS_FLOAT_FIXED +void TDREND_Apply_ITD_fx( + Word32 *input_fx, /* i : Input subframe to be time adjusted Qx */ + Word32 *out_left_fx, /* o : Output left channel with ITD applied Qx */ + Word32 *out_right_fx, /* o : Output right channel with ITD applied Qx */ + Word16 *previtd, /* i/o: Previous ITD value */ + const Word16 itd, /* i : Current subframe ITD value */ + Word32 *mem_itd_fx, /* i/o: ITD buffer memory Qx */ + const Word16 length /* i : Subframe length */ +); +#endif + void TDREND_firfilt( float *signal, /* i/o: Input signal / Filtered signal */ float *filter, /* i/o: FIR filter */ @@ -1316,6 +1340,20 @@ void TDREND_firfilt( const float Gain, /* i : Gain */ const float prevGain /* i : Previous gain */ ); +#ifdef IVAS_FLOAT_FIXED +void TDREND_firfilt_fx( + Word32 *signal_fx, /* i/o: Input signal / Filtered signal Qx */ + Word32 *filter_fx, /* i/o: FIR filter Qy */ + const Word16 filter_e, /* i : FIR filter exp */ + const Word32 *filter_delta_fx, /* i : FIR filter delta Qy */ + const Word16 intp_count, /* i : interpolation count */ + Word32 *mem_fx, /* i/o: filter memory Qx */ + const Word16 subframe_length, /* i : Length of signal */ + const Word16 filterlength, /* i : Filter length */ + const Word16 Gain_fx, /* i : Gain Q14 */ + const Word16 prevGain_fx /* i : Previous gain Q14 */ +); +#endif /*----------------------------------------------------------------------------------* diff --git a/lib_rend/ivas_rom_rend.c b/lib_rend/ivas_rom_rend.c index 2c3c43cf4..539d9acb3 100644 --- a/lib_rend/ivas_rom_rend.c +++ b/lib_rend/ivas_rom_rend.c @@ -354,6 +354,51 @@ const float SincTable[321] = 0.00000000f }; +#ifdef IVAS_FLOAT_FIXED +const Word32 SincTable_fx[321] /*Q31*/ = { + 2147483647, 2146573696, 2143845504, 2139303424, 2132954752, 2124809984, 2114882304, 2103187712, + 2089745280, 2074576896, 2057706880, 2039162624, 2018973952, 1997173632, 1973796608, 1948880384, + 1922464896, 1894592512, 1865307520, 1834656640, 1802688384, 1769453440, 1735004160, 1699394688, + 1662680832, 1624919808, 1586170496, 1546492672, 1505947520, 1464597248, 1422505088, 1379734784, + 1336350976, 1292418816, 1248003968, 1203172224, 1157989504, 1112521984, 1066835776, 1020996544, + 975069760, 929120576, 883213312, 837411776, 791778944, 746376896, 701266624, 656507968, + 612159680, 568278912, 524921632, 482142144, 439993120, 398525536, 357788576, 317829568, + 278693888, 240424880, 203063792, 166649792, 131219840, 96808624, 63448564, 31169780, + 0, -30035372, -58913380, -86613488, -113117560, -138409920, -162477328, -185308960, + -206896448, -227233840, -246317488, -264146240, -280721152, -296045696, -310125536, -322968512, + -334584768, -344986496, -354187904, -362205280, -369056800, -374762592, -379344480, -382826080, + -385232704, -386591168, -386929792, -386278336, -384667872, -382130688, -378700320, -374411264, + -369298976, -363399872, -356751072, -349390464, -341356448, -332688000, -323424448, -313605536, + -303271104, -292461216, -281215968, -269575360, -257579344, -245267600, -232679504, -219854112, + -206829968, -193645040, -180336784, -166941904, -153496352, -140035312, -126593000, -113202776, + -99896968, -86706824, -73662536, -60793156, -48126460, -35689116, -23506464, -11602511, + 0, 11279679, 22216534, 32791924, 42988628, 52790860, 62184168, 71155600, + 79693568, 87787904, 95429856, 102612048, 109328456, 115574480, 121346784, 126643384, + 131463560, 135807872, 139678096, 143077152, 146009200, 148479424, 150494144, 152060704, + 153187376, 153883424, 154159008, 154025088, 153493440, 152576608, 151287776, 149640800, + 147650112, 145330640, 142697840, 139767584, 136556080, 133079880, 129355800, 125400848, + 121232192, 116867152, 112323056, 107617280, 102767096, 97789792, 92702424, 87521944, + 82265048, 76948224, 71587592, 66198976, 60797860, 55399280, 50017836, 44667724, + 39362580, 34115548, 28939254, 23845722, 18846466, 13952309, 9173513, 4519744, + 0, -4377366, -8604666, -12674792, -16581387, -20318674, -23881564, -27265612, + -30467016, -33482620, -36309868, -38946872, -41392276, -43645372, -45706012, -47574624, + -49252152, -50740076, -52040356, -53155480, -54088368, -54842372, -55421272, -55829248, + -56070800, -56150856, -56074556, -55847396, -55475128, -54963748, -54319440, -53548580, + -52657716, -51653552, -50542876, -49332552, -48029524, -46640788, -45173328, -43634160, + -42030228, -40368440, -38655628, -36898600, -35103948, -33278222, -31427800, -29558888, + -27677586, -25789732, -23901000, -22016882, -20142580, -18283160, -16443390, -14627800, + -12840707, -11086127, -9367861, -7689451, -6054121, -4464919, -2924550, -1435506, + 0, 1379973, 2702737, 3966788, 5170926, 6314160, 7395719, 8415065, + 9371898, 10266067, 11097680, 11866995, 12574462, 13220704, 13806494, 14332735, + 14800522, 15211013, 15565541, 15865502, 16112419, 16307883, 16453547, 16551150, + 16602497, 16609390, 16573720, 16497356, 16382229, 16230230, 16043313, 15823325, + 15572220, 15291845, 14984024, 14650584, 14293308, 13913890, 13514007, 13095291, + 12659287, 12207543, 11741453, 11262435, 10771778, 10270770, 9760549, 9242276, + 8716980, 8185692, 7649294, 7108665, 6564643, 6017979, 5469361, 4919434, + 4368840, 3818118, 3267783, 2718370, 2170290, 1624034, 1079948, 538481, +}; +#endif + const float defaultHRIR_coherence_48kHz[LR_IAC_LENGTH_NR_FC] = { 0.983003f, 0.933450f, 0.789276f, 0.574420f, 0.340710f, 0.144220f, 0.018803f, 0.000000f, 0.000000f, 0.000000f, 0.011939f, 0.035489f, 0.043188f, 0.042460f, 0.041788f, 0.038562f, 0.028911f, 0.017162f, diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index 807fe1931..9418f2e62 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -104,6 +104,9 @@ extern const float diffuseFieldCoherenceDifferenceZ[BINAURAL_COHERENCE_DIFFERENC extern const int16_t HRTF_MODEL_N_CPTS_VAR[HRTF_MODEL_N_SECTIONS]; extern const float SincTable[321]; +#ifdef IVAS_FLOAT_FIXED +extern const Word32 SincTable_fx[321]; +#endif extern const float defaultHRIR_coherence_48kHz[LR_IAC_LENGTH_NR_FC]; extern const float defaultHRIR_left_avg_power_48kHz[LR_IAC_LENGTH_NR_FC]; diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 3de047271..cc584955c 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1688,11 +1688,14 @@ typedef struct int16_t filterlength; #ifdef IVAS_FLOAT_FIXED Word32 *InputFrame_p_fx; /* Input frame pointer */ + Word16 InputFrame_p_q; Word32 mem_itd_fx[ITD_MEM_LEN]; Word32 mem_hrf_left_fx[SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1]; Word32 mem_hrf_right_fx[SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1]; Word32 hrf_left_prev_fx[SFX_SPAT_BIN_MAX_FILTER_LENGTH]; + Word16 hrf_left_prev_e; Word32 hrf_right_prev_fx[SFX_SPAT_BIN_MAX_FILTER_LENGTH]; + Word16 hrf_right_prev_e; Word32 azim_prev_fx; Word32 elev_prev_fx; Word16 Gain_fx; // Q14 -- GitLab From 9c6f2ad04f9c9008fa13a661c4a944739fba0f1d Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sun, 14 Apr 2024 16:56:51 +0530 Subject: [PATCH 2/3] Few intermediate conversions cleared up. --- lib_dec/ivas_ism_dec.c | 4 ++-- lib_dec/ivas_masa_dec.c | 2 -- lib_dec/ivas_mct_dec.c | 1 - lib_dec/ivas_sba_dec.c | 1 - 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 6da160102..433a97192 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -168,7 +168,6 @@ static ivas_error ivas_ism_bitrate_switching_dec( #if 1 /*Float to fixed conversion*/ DECODER_TC_BUFFER_HANDLE hTcBuffer; hTcBuffer = st_ivas->hTcBuffer; - floatToFixed_arrL( hTcBuffer->tc_buffer, hTcBuffer->tc_buffer_fx, Q11, hTcBuffer->tc_buff_len ); if ( st_ivas->hIsmRendererData ) { FOR( Word16 ind1 = 0; ind1 < st_ivas->hIsmRendererData->interpolator_len; ind1++ ) @@ -284,7 +283,8 @@ static ivas_error ivas_ism_bitrate_switching_dec( return error; } #if 1 /*Fixed to float */ - 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++ ) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index c1fd0e2d9..f3f4798b4 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -3249,7 +3249,6 @@ ivas_error ivas_masa_dec_reconfigure( #if 1 /*Float to fixed conversion*/ DECODER_TC_BUFFER_HANDLE hTcBuffer; hTcBuffer = st_ivas->hTcBuffer; - floatToFixed_arrL( hTcBuffer->tc_buffer, hTcBuffer->tc_buffer_fx, Q11, hTcBuffer->tc_buff_len ); if ( st_ivas->hIsmRendererData ) { FOR( Word16 ind1 = 0; ind1 < st_ivas->hIsmRendererData->interpolator_len; ind1++ ) @@ -3784,7 +3783,6 @@ ivas_error ivas_masa_dec_reconfigure_fx( #if 1 /*Float to fixed conversion*/ DECODER_TC_BUFFER_HANDLE hTcBuffer; hTcBuffer = st_ivas->hTcBuffer; - floatToFixed_arrL( hTcBuffer->tc_buffer, hTcBuffer->tc_buffer_fx, Q11, hTcBuffer->tc_buff_len ); if ( st_ivas->hIsmRendererData ) { FOR( Word16 ind1 = 0; ind1 < st_ivas->hIsmRendererData->interpolator_len; ind1++ ) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 82e87a314..019716bc1 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -2469,7 +2469,6 @@ static ivas_error ivas_mc_dec_reconfig( #if 1 /*Float to fixed conversion*/ DECODER_TC_BUFFER_HANDLE hTcBuffer; hTcBuffer = st_ivas->hTcBuffer; - floatToFixed_arrL( hTcBuffer->tc_buffer, hTcBuffer->tc_buffer_fx, Q11, hTcBuffer->tc_buff_len ); if ( st_ivas->hIsmRendererData ) { FOR( Word16 ind1 = 0; ind1 < st_ivas->hIsmRendererData->interpolator_len; ind1++ ) diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index d7d4f807b..ec48f6b8b 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -253,7 +253,6 @@ ivas_error ivas_sba_dec_reconfigure( #if 1 /*Float to fixed conversion*/ DECODER_TC_BUFFER_HANDLE hTcBuffer; hTcBuffer = st_ivas->hTcBuffer; - floatToFixed_arrL( hTcBuffer->tc_buffer, hTcBuffer->tc_buffer_fx, Q11, hTcBuffer->tc_buff_len ); if ( st_ivas->hIsmRendererData ) { FOR( Word16 ind1 = 0; ind1 < st_ivas->hIsmRendererData->interpolator_len; ind1++ ) -- GitLab From 883aa83fc839a9c81f88bd570874864598013a8f Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sun, 14 Apr 2024 20:31:34 +0530 Subject: [PATCH 3/3] MC case crash fix --- lib_dec/ivas_masa_dec.c | 6 ++++-- lib_dec/ivas_mct_dec.c | 3 ++- lib_dec/ivas_sba_dec.c | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index f3f4798b4..77f838d98 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -3364,7 +3364,8 @@ ivas_error ivas_masa_dec_reconfigure( return error; } #if 1 /*Fixed to float */ - 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++ ) @@ -3898,7 +3899,8 @@ ivas_error ivas_masa_dec_reconfigure_fx( return error; } #if 1 /*Fixed to float */ - 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++ ) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 019716bc1..9c519146c 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -2584,7 +2584,8 @@ static ivas_error ivas_mc_dec_reconfig( return error; } #if 1 /*Fixed to float */ - 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++ ) diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index ec48f6b8b..9fd193f19 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -368,7 +368,8 @@ ivas_error ivas_sba_dec_reconfigure( return error; } #if 1 /*Fixed to float */ - 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++ ) -- GitLab