diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index f8b27dd6115b81f66449d008e1d08ba8dd04eac4..8859370e3f1f899c3c862c9303e76685defd3323 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -1614,7 +1614,7 @@ void configureCldfb_ivas_fx( * * open and configures a CLDFB handle *--------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED ivas_error openCldfb_ivas( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ @@ -1667,7 +1667,50 @@ ivas_error openCldfb_ivas( return IVAS_ERR_OK; } +#else +ivas_error openCldfb_ivas( + HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ + CLDFB_TYPE type, /* i : analysis or synthesis */ + const int32_t sampling_rate, /* i : sampling rate */ + CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ +) +{ + HANDLE_CLDFB_FILTER_BANK hs; + int16_t buf_len; + + if ((hs = (HANDLE_CLDFB_FILTER_BANK)malloc(sizeof(CLDFB_FILTER_BANK))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB"); + } + + hs->type = type; + hs->prototype = prototype; + configureCldfb_ivas(hs, sampling_rate); + hs->memory_flt = NULL; + hs->memory_length = 0; + + if (type == CLDFB_ANALYSIS) + { + buf_len = hs->p_filter_length - hs->no_channels; + } + else + { + buf_len = hs->p_filter_length; + } + + if ((hs->cldfb_state = (float *)malloc(buf_len * sizeof(float))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB"); + } + + set_f(hs->cldfb_state, 0.0f, buf_len); + + *h_cldfb = hs; + + return IVAS_ERR_OK; +} +#endif #ifdef IVAS_FLOAT_FIXED ivas_error openCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ diff --git a/lib_dec/LD_music_post_filter.c b/lib_dec/LD_music_post_filter.c index d6a64ad796487daaa2d2c53cb1909bab0ff6dbb4..a17dcdfb6e8c45fa457b001fdc05939275d8ad24 100644 --- a/lib_dec/LD_music_post_filter.c +++ b/lib_dec/LD_music_post_filter.c @@ -727,6 +727,7 @@ void Post_music_postP( * * Initialize LD music postfilter state structure *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void music_postfilt_init_flt( MUSIC_POSTFILT_HANDLE hMusicPF /* i/o: LD music postfilter handle */ @@ -801,3 +802,40 @@ void music_postfilt_init_flt( #endif return; } +#else + void music_postfilt_init_flt( + MUSIC_POSTFILT_HANDLE hMusicPF /* i/o: LD music postfilter handle */ + ) + { + int16_t i; + + set_f(hMusicPF->dct_post_old_exc, 0, DCT_L_POST - OFFSET2); + + hMusicPF->LDm_enh_min_ns_gain = (float)pow(10.0f, -12 / 20.0f); + hMusicPF->LDm_last_music_flag = 0; + 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; + hMusicPF->LDm_nb_thr_1 = 0; + hMusicPF->LDm_nb_thr_3 = 0; + hMusicPF->LDm_mem_etot = 0.0f; + + for (i = 0; i < VOIC_BINS_HR; i++) + { + hMusicPF->LDm_enh_lp_gbin[i] = 1.0f; + hMusicPF->LDm_enh_lf_EO[i] = 0.01f; + } + + for (i = 0; i < MBANDS_GN_LD; i++) + { + hMusicPF->LDm_bckr_noise[i] = E_MIN; + } + + set_f(hMusicPF->filt_lfE, 1.0f, DCT_L_POST); + hMusicPF->last_nonfull_music = 0; + + return; + } +#endif \ No newline at end of file diff --git a/lib_dec/core_dec_init.c b/lib_dec/core_dec_init.c index 112074bcc71404cb3bee6ad8768a90a492325471..458f82feb7aab3496758de7b71af34668b355587 100644 --- a/lib_dec/core_dec_init.c +++ b/lib_dec/core_dec_init.c @@ -1449,7 +1449,7 @@ void open_decoder_LPD( * * Initialization TCX-LTP handle *-----------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void tcxltp_dec_init( TCX_LTP_DEC_HANDLE hTcxLtpDec, const int16_t ini_frame, @@ -1489,7 +1489,39 @@ void tcxltp_dec_init( return; } +#else +void tcxltp_dec_init( + TCX_LTP_DEC_HANDLE hTcxLtpDec, + const int16_t ini_frame, + const int16_t last_codec_mode, + const int16_t element_mode, + const int16_t pit_max, + const int32_t sr_core) +{ + hTcxLtpDec->tcxltp_gain_float = 0.0f; + + hTcxLtpDec->tcxltp = getTcxLtp(sr_core); + + if (ini_frame == 0 || (last_codec_mode == MODE1 && element_mode == EVS_MONO)) + { + hTcxLtpDec->tcxltp_pitch_int = pit_max; + hTcxLtpDec->tcxltp_pitch_fr = 0; + + if (ini_frame == 0) + { + set_f(hTcxLtpDec->tcxltp_mem_in_float, 0.0f, TCXLTP_MAX_DELAY); + set_f(hTcxLtpDec->tcxltp_mem_out_float, 0.0f, L_FRAME48k); + hTcxLtpDec->tcxltp_pitch_int_post_prev = 0; + hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0; + hTcxLtpDec->tcxltp_gain_post_prev_float = 0.f; + hTcxLtpDec->tcxltp_filt_idx_prev = -1; + } + } + + return; +} +#endif /*-----------------------------------------------------------------------* * reset_tcx_overl_buf() * diff --git a/lib_dec/hq_core_dec.c b/lib_dec/hq_core_dec.c index 5c4b16a5625ea72020226985128b09a337da2734..839d6b299d6e6d1babd598e8c2471242229d1b55 100644 --- a/lib_dec/hq_core_dec.c +++ b/lib_dec/hq_core_dec.c @@ -649,7 +649,7 @@ void hq_core_dec( * * Initialize HQ core state structure *-------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void HQ_core_dec_init_flt( HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ ) @@ -745,6 +745,80 @@ void HQ_core_dec_init_flt( return; } +#else +void HQ_core_dec_init_flt( + HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ +) +{ + + set_f(hHQ_core->old_out, 0, L_FRAME48k); + set_f(hHQ_core->old_outLB, 0, L_FRAME32k); + set_s(hHQ_core->old_is_transient, 0, 3); + + hHQ_core->oldHqVoicing = 0; + + set_f(hHQ_core->prev_noise_level, 0.0f, 2); + hHQ_core->prev_R = 0; + set_f(hHQ_core->prev_coeff_out, 0, L_HQ_WB_BWE); + set_s(hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM); + + /* HQ GENERIC */ + hHQ_core->hq_generic_seed = RANDOM_INITSEED; + + hHQ_core->mem_norm[0] = 31; + set_s(hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1); + hHQ_core->mem_env_delta = 0; + hHQ_core->no_att_hangover = 0; + hHQ_core->energy_lt = 300.0f; + + hHQ_core->HqVoicing = 0; + set_f(hHQ_core->fer_samples, 0, L_FRAME48k); + set_f(hHQ_core->prev_env, 0, SFM_N_WB); + set_f(hHQ_core->prev_normq, 0, SFM_N_WB); + hHQ_core->prev_hqswb_clas = HQ_NORMAL; + + set_f(hHQ_core->last_ni_gain, 0, BANDS_MAX); + set_f(hHQ_core->last_env, 0, BANDS_MAX); + hHQ_core->last_max_pos_pulse = 0; + hHQ_core->prev_frm_hfe2 = 0; + hHQ_core->prev_stab_hfe2 = 0; + hHQ_core->prev_ni_ratio = 0.5f; + set_f(hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS); + + + /*----------------------------------------------------------------------------------* + * HQ FEC + *----------------------------------------------------------------------------------*/ + + set_f(hHQ_core->X_sav, 0.0f, PH_ECU_SPEC_SIZE); + hHQ_core->num_p = 0; + hHQ_core->ph_ecu_active = 0; + hHQ_core->ni_seed_forfec = 0; + hHQ_core->last_fec = 0; + hHQ_core->ph_ecu_HqVoicing = 0; + set_f(hHQ_core->oldgapsynth, 0.0f, L_FRAME48k); + hHQ_core->env_stab = 0.75f; + hHQ_core->mem_norm_hqfec[0] = 31; + set_s(hHQ_core->mem_norm_hqfec + 1, 39, SFM_N_ENV_STAB - 1); + hHQ_core->mem_env_delta_hqfec = 0; + hHQ_core->env_stab_plc = 0.0f; + set_f(hHQ_core->env_stab_state_p, 1.0f / NUM_ENV_STAB_PLC_STATES, NUM_ENV_STAB_PLC_STATES); + hHQ_core->envstabplc_hocnt = 0; + + set_f(hHQ_core->mag_chg_1st, 1.0f, LGW_MAX); + set_f(hHQ_core->Xavg, 0.0f, LGW_MAX); + hHQ_core->beta_mute = BETA_MUTE_FAC_INI_FLT; + + hHQ_core->time_offs = 0; + hHQ_core->ber_occured_in_pvq = 0; + + hHQ_core->last_hq_core_type = -1; + + reset_preecho_dec(hHQ_core); + + return; +} +#endif #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* diff --git a/lib_dec/igf_dec.c b/lib_dec/igf_dec.c index 621ea8546a00be298dffed20047e0497c2df9d46..c9251d4d68b5e48f6bb881ab2f48d00b7c8d8dea 100644 --- a/lib_dec/igf_dec.c +++ b/lib_dec/igf_dec.c @@ -1603,7 +1603,7 @@ void IGFDecRestoreTCX10SubFrameData_flt( * * Initialize IGF decoder parameters *-----------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void init_igf_dec_flt( IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: IGF decoder handle */ ) @@ -1625,8 +1625,24 @@ void init_igf_dec_flt( #endif return; } - - +#else +void init_igf_dec_flt( + IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: IGF decoder handle */ +) +{ + set_c((int8_t *)(hIGFDec->infoTCXNoiseBuf), 0, IGF_START_MX); + set_f(hIGFDec->igfData.pSpecFlatBuf, 0, IGF_START_MX); + hIGFDec->igfData.igfInfo.nfSeedBuf[0] = 9733; + hIGFDec->igfData.igfInfo.nfSeedBuf[1] = 9733; + hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0]; + hIGFDec->igfData.pSpecFlat_float = &hIGFDec->igfData.pSpecFlatBuf[0]; + hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; + hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0]; + hIGFDec->virtualSpec_float = &hIGFDec->virtualSpecBuf[0]; + + return; +} +#endif /*-----------------------------------------------------------------------* * get_igf_startline_flt() * diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 3b06fadda2c9c23cde3d1403f051c5be0d3efee6..32aa6f4a47a79d397ef1617bbd4d848992033d88 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -3298,6 +3298,7 @@ ivas_error ivas_jbm_dec_tc( st_ivas->hCPE[0]->element_brate = ivas_total_brate; } + /* core-decoding of transport channels */ if ( st_ivas->nSCE == 1 ) { @@ -5772,11 +5773,29 @@ ivas_error ivas_jbm_dec_render( { mvr2r( st_ivas->hTcBuffer->tc[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output[n], *nSamplesRendered ); } - +#ifdef IVAS_FLOAT_FIXED +#if 1//To Be removed + for ( n = 0; n < st_ivas->p_out_len; n++ ) + { + floatToFixed_arr32( p_output[n], p_output_fx[n], Q11, 960 ); + } +#endif + IF ( ( error = ivas_sba_linear_renderer_fx( p_output_fx, *nSamplesRendered, nchan_remapped, 0, output_config, st_ivas->hOutSetup ) ) != IVAS_ERR_OK ) + { + return error; + } +#if 1//To Be removed + for ( n = 0; n < st_ivas->p_out_len; n++ ) + { + fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); + } +#endif +#else if ( ( error = ivas_sba_linear_renderer( p_output, *nSamplesRendered, nchan_remapped, 0, output_config, st_ivas->hOutSetup ) ) != IVAS_ERR_OK ) { return error; } +#endif } else if ( st_ivas->renderer_type == RENDERER_DIRAC ) { diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 47bb00816b8928d53dc751324f6861028ca8f965..29294304c1aa40864c91436bcfe79e170099c7d7 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -64,639 +64,228 @@ static ivas_error ivas_mc_dec_reconfig( Decoder_Struct *st_ivas, uint16_t *nSamp #ifndef IVAS_FLOAT_FIXED ivas_error ivas_mct_dec( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - float *output[], /* o : output synthesis signal */ - const int16_t output_frame, /* i : output frame length per channel */ - const int16_t nb_bits_metadata /* i : number of metadata bits */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output[], /* o : output synthesis signal */ + const int16_t output_frame, /* i : output frame length per channel */ + const int16_t nb_bits_metadata /* i : number of metadata bits */ ) { - int16_t n, nCPE, cpe_id; - MCT_DEC_HANDLE hMCT; - CPE_DEC_HANDLE hCPE; - float *x[CPE_CHANNELS][NB_DIV]; - int16_t param[MCT_MAX_BLOCKS][CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV]; - int16_t param_lpc[MCT_MAX_BLOCKS][CPE_CHANNELS][NPRM_LPC_NEW]; - int16_t p_param[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; - int16_t nTnsBitsTCX10[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; - float Aq[MCT_MAX_BLOCKS][CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; - int16_t fUseTns[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; - STnsData tnsData[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; - Decoder_State **sts; - float synth[CPE_CHANNELS][L_FRAME_PLUS]; - float output_lfe_ch[L_FRAME48k]; - int32_t ivas_total_brate; - ivas_error error; + int16_t n, nCPE, cpe_id; + MCT_DEC_HANDLE hMCT; + CPE_DEC_HANDLE hCPE; + float *x[CPE_CHANNELS][NB_DIV]; + int16_t param[MCT_MAX_BLOCKS][CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV]; + int16_t param_lpc[MCT_MAX_BLOCKS][CPE_CHANNELS][NPRM_LPC_NEW]; + int16_t p_param[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + int16_t nTnsBitsTCX10[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + float Aq[MCT_MAX_BLOCKS][CPE_CHANNELS][(NB_SUBFR16k + 1) * (M + 1)]; + int16_t fUseTns[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + STnsData tnsData[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + Decoder_State **sts; + float synth[CPE_CHANNELS][L_FRAME_PLUS]; + float output_lfe_ch[L_FRAME48k]; + int32_t ivas_total_brate; + ivas_error error; -#ifdef IVAS_FLOAT_FIXED - /* TODO: Temporary fix to avoid garbage values while calculating its q-factor - when not initialised. */ - set_zero((float *)Aq, MCT_MAX_BLOCKS*CPE_CHANNELS*(NB_SUBFR16k + 1) * (M + 1)); -#endif + push_wmops("ivas_mct_dec"); - push_wmops( "ivas_mct_dec" ); + error = IVAS_ERR_OK; + nCPE = st_ivas->nCPE; + hMCT = st_ivas->hMCT; - error = IVAS_ERR_OK; - nCPE = st_ivas->nCPE; - hMCT = st_ivas->hMCT; + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + if (st_ivas->ivas_format == MC_FORMAT && (st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX)) + { + /* save LFE channel */ + mvr2r(output[LFE_CHANNEL], output_lfe_ch, output_frame); + } - if ( st_ivas->ivas_format == MC_FORMAT && ( st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) ) - { - /* save LFE channel */ - mvr2r( output[LFE_CHANNEL], output_lfe_ch, output_frame ); - } + if (st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCT && !st_ivas->bfi) + { + /* get the number of channels from the signalled MC LS setup */ + n = ivas_mc_ls_setup_get_num_channels(ivas_mc_map_output_config_to_mc_ls_setup(st_ivas->transport_config)); - if ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCT && !st_ivas->bfi ) + if (n != st_ivas->nchan_transport) { - /* get the number of channels from the signalled MC LS setup */ - n = ivas_mc_ls_setup_get_num_channels( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ) ); - - if ( n != st_ivas->nchan_transport ) - { - /* IVAS_fmToDo: more work needed for switching the number of transport channels */ - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: wrong number of transport channels signalled in MC format!" ); - } + /* IVAS_fmToDo: more work needed for switching the number of transport channels */ + return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "Error: wrong number of transport channels signalled in MC format!"); } + } - for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + /*initialize param_lpc buffer*/ + for (n = 0; n < CPE_CHANNELS; n++) { - /*initialize param_lpc buffer*/ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - set_s( param_lpc[cpe_id][n], 0, NPRM_LPC_NEW ); - } - -#ifdef IVAS_FLOAT_FIXED - Word32 *output_fx[2]; - Word16 q_output = 11; - output_fx[0] = malloc( sizeof( Word32 ) * L_FRAME48k ); - output_fx[1] = malloc( sizeof( Word32 ) * L_FRAME48k ); - set32_fx( &output_fx[0][0], 0, L_FRAME48k ); - set32_fx( &output_fx[1][0], 0, L_FRAME48k ); - - IF( ( error = ivas_cpe_dec_fx( st_ivas, cpe_id, &output_fx[0], output_frame, 0, &q_output ) ) != IVAS_ERR_OK ) - { - return error; - } - - for ( int k = 0; k < L_FRAME48k; k++ ) - { - output[0][k] = (float) output_fx[0][k] / ( 1 << q_output ); - output[1][k] = (float) output_fx[1][k] / ( 1 << q_output ); - } - free( output_fx[0] ); - free( output_fx[1] ); -#else - if ( ( error = ivas_cpe_dec( st_ivas, cpe_id, output, output_frame, 0 ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif // IVAS_FLOAT_FIXED - - if ( cpe_id == 0 ) - { - st_ivas->hCPE[0]->hCoreCoder[0]->total_brate = ivas_total_brate; /* set high enough to read the whole side-info; total_brate is rewritten later in ivas_mdct_core_invQ() */ - } - - if ( !st_ivas->bfi ) - { - ivas_mdct_dec_side_bits_frame_channel( st_ivas->hCPE[cpe_id], param_lpc[cpe_id], p_param[cpe_id], st_ivas->hCPE[0]->hCoreCoder[0], nTnsBitsTCX10[cpe_id], param[cpe_id], 1, - ( ( cpe_id + 1 ) * CPE_CHANNELS > hMCT->nchan_out_woLFE ) ); - - st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect; - st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect; - } + set_s(param_lpc[cpe_id][n], 0, NPRM_LPC_NEW); } - /* MCT side bits decoder */ - ivas_mct_side_bits( hMCT, st_ivas->hCPE, nCPE, st_ivas->hCPE[0]->hCoreCoder[0], st_ivas->bfi, st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream, ivas_total_brate, nb_bits_metadata ); - - for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + if ((error = ivas_cpe_dec(st_ivas, cpe_id, output, output_frame, 0)) != IVAS_ERR_OK) { - st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect |= st_ivas->BER_detect; - st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect |= st_ivas->BER_detect; - - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - x[n][0] = output[n + cpe_id * CPE_CHANNELS]; - x[n][1] = output[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); - set_zero( x[n][0], L_FRAME48k / 2 ); - set_zero( x[n][1], L_FRAME48k / 2 ); - } - -#ifdef IVAS_FLOAT_FIXED -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - hCPE = st_ivas->hCPE[cpe_id]; - sts = hCPE->hCoreCoder; - - Word16 Aq_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; - Word16 ch, k, l, i, j; - - Word32 *x_fx[CPE_CHANNELS][NB_DIV]; - Word16 x_e[CPE_CHANNELS][NB_DIV]; - Word16 x_len[CPE_CHANNELS][NB_DIV] = { 0 }; - - FOR( i = 0; i < CPE_CHANNELS; ++i ) - { - x_fx[i][0] = malloc( L_FRAME48k * sizeof( Word32 ) ); - x_fx[i][1] = x_fx[i][0] + L_FRAME48k / 2; - floatToFixed_arrL( x[i][0], x_fx[i][0], 0, L_FRAME48k / 2 ); - floatToFixed_arrL( x[i][1], x_fx[i][1], 0, L_FRAME48k / 2 ); - - FOR( j = 0; j < NB_DIV; ++j ) - { - x_e[i][j] = 31; - } - } - - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) - { - sts[ch]->gamma = float_to_fix16( sts[ch]->gamma_float, Q15 ); - sts[ch]->preemph_fac = float_to_fix16( sts[ch]->preemph_fac_float, Q15 ); - sts[ch]->Mode2_lp_gainp = float_to_fix( sts[ch]->lp_gainp, Q16 ); - sts[ch]->hTcxLtpDec->tcxltp_gain = float_to_fix16( sts[ch]->hTcxLtpDec->tcxltp_gain_float, Q15 ); - sts[ch]->inv_gamma = float_to_fix16( 1 / sts[ch]->gamma_float, Q14 ); - f2me_16( sts[ch]->last_gain_syn_deemph_float, &sts[ch]->last_gain_syn_deemph, &sts[ch]->last_gain_syn_deemph_e ); - f2me_16( sts[ch]->last_concealed_gain_syn_deemph_float, &sts[ch]->last_concealed_gain_syn_deemph, &sts[ch]->last_concealed_gain_syn_deemph_e ); - f2me_16( sts[ch]->hTcxDec->old_gaintcx_bfi_float, &sts[ch]->hTcxDec->old_gaintcx_bfi, &sts[ch]->hTcxDec->old_gaintcx_bfi_e ); - floatToFixed_arr( Aq[cpe_id][ch], Aq_fx[cpe_id][ch], Q12, ( NB_SUBFR16k + 1 ) * ( M + 1 ) ); - - sts[ch]->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( sts[ch]->hTcxDec->tcxltp_last_gain_unmodified_float, Q15 ); - sts[ch]->old_fpitch = float_to_fix( sts[ch]->old_fpitch_float, Q16 ); - //sts[ch]->hTonalMDCTConc->lastPitchLag = float_to_fix( sts[ch]->hTonalMDCTConc->lastPitchLag_float, Q16 ); - // u8bit to 16bit - FOR( l = 0; l < IGF_START_MX; l++ ) - { - sts[ch]->hIGFDec->infoTCXNoise_evs[l] = (Word16) sts[ch]->hIGFDec->infoTCXNoise[l]; - } - FOR( l = 0; l < N_LTP_GAIN_MEMS; l++ ) - { - sts[ch]->hTcxDec->ltpGainMemory_fx[l] = float_to_fix16( sts[ch]->hTcxDec->ltpGainMemory[l], Q15 ); - } - sts[ch]->hTcxDec->cummulative_damping_tcx = float_to_fix16( sts[ch]->hTcxDec->cummulative_damping_tcx_float, Q15 ); - } - } - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - IF( sts[ch]->rate_switching_reset ) - { - floatToFixed_arr( sts[ch]->lsp_old, sts[ch]->lsp_old_fx, Q15, M ); - } - } -#endif - ivas_mdct_core_invQ_fx( st_ivas->hCPE[cpe_id], nTnsBitsTCX10[cpe_id], p_param[cpe_id], param_lpc[cpe_id], param[cpe_id], - fUseTns[cpe_id], tnsData[cpe_id], x_fx, x_e, x_fx, x_e, x_len, Aq_fx[cpe_id], NULL, 1 ); -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - IF( sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) - { - me2f_buf( x_fx[ch][0], x_e[ch][0], x[ch][0], sts[ch]->hTcxCfg->tcx_coded_lines ); - sts[ch]->hTcxDec->damping_float = fix16_to_float( sts[ch]->hTcxDec->damping, Q14 ); - sts[ch]->hTcxDec->gainHelper_float = me2f_16( sts[ch]->hTcxDec->gainHelper, sts[ch]->hTcxDec->gainHelper_e ); - sts[ch]->hTcxDec->stepCompensate_float = me2f_16( sts[ch]->hTcxDec->stepCompensate, sts[ch]->hTcxDec->stepCompensate_e ); - } - IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) - { - sts[ch]->lp_gainp = fix_to_float( sts[ch]->Mode2_lp_gainp, Q16 ); - //sts[ch]->hTonalMDCTConc->lastPitchLag_float = fix_to_float( sts[ch]->hTonalMDCTConc->lastPitchLag, Q16 ); - sts[ch]->hTonalMDCTConc->nFramesLost_float = fix16_to_float( sts[ch]->hTonalMDCTConc->nFramesLost, Q1 ); - sts[ch]->hTcxDec->damping_float = fix16_to_float( sts[ch]->hTcxDec->damping, Q14 ); - sts[ch]->hTcxDec->stepCompensate_float = me2f_16( sts[ch]->hTcxDec->stepCompensate, sts[ch]->hTcxDec->stepCompensate_e ); - sts[ch]->hTcxDec->gainHelper_float = me2f_16( sts[ch]->hTcxDec->gainHelper, sts[ch]->hTcxDec->gainHelper_e ); - sts[ch]->last_concealed_gain_syn_deemph_float = me2f_16( sts[ch]->last_concealed_gain_syn_deemph, sts[ch]->last_concealed_gain_syn_deemph_e ); - sts[ch]->last_gain_syn_deemph_float = me2f_16( sts[ch]->last_gain_syn_deemph, sts[ch]->last_gain_syn_deemph_e ); - sts[ch]->hTcxDec->old_gaintcx_bfi_float = me2f_16( sts[ch]->hTcxDec->old_gaintcx_bfi, sts[ch]->hTcxDec->old_gaintcx_bfi_e ); - fixedToFloat_arr( Aq_fx[cpe_id][ch], Aq[cpe_id][ch], Q12, ( NB_SUBFR16k + 1 ) * ( M + 1 ) ); - // 16bit to u8bit - FOR( Word16 l = 0; l < IGF_START_MX; l++ ) - { - sts[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t) sts[ch]->hIGFDec->infoTCXNoise_evs[l]; - } - FOR( Word16 l = 0; l < N_LTP_GAIN_MEMS; l++ ) - { - sts[ch]->hTcxDec->ltpGainMemory[l] = fix16_to_float( sts[ch]->hTcxDec->ltpGainMemory_fx[l], Q15 ); - } - - Word16 subFrames = ( sts[ch]->core == TCX_10_CORE ) ? NB_DIV : 1; - FOR( k = 0; k < subFrames; ++k ) - { - me2f_buf( x_fx[ch][k], x_e[ch][k], x[ch][k], x_len[ch][k] ); - // To be made into Q11 - // me2f_buf(x_fx[ch][k], x_e[ch][k], x[ch][k], L_FRAME48k / 2); - } - IF( !sts[0]->bfi || ( sts[0]->bfi && sts[ch]->core != ACELP_CORE ) ) - { - me2f_buf( sts[ch]->hIGFDec->virtualSpec, sts[ch]->hIGFDec->virtualSpec_e, sts[ch]->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); - } - sts[ch]->hTcxDec->cummulative_damping_tcx_float = fix16_to_float( sts[ch]->hTcxDec->cummulative_damping_tcx, Q15 ); - } - } - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - IF( sts[ch]->rate_switching_reset ) - { - Word16 old_Aq_12_8_e = norm_s( sts[ch]->old_Aq_12_8_fx[0] ); - fixedToFloat_arr( sts[ch]->old_Aq_12_8_fx, sts[ch]->old_Aq_12_8, ( 15 - old_Aq_12_8_e ), M + 1 ); - } - } - - FOR( i = 0; i < CPE_CHANNELS; ++i ) - { - free( x_fx[i][0] ); - } - -#endif -#else - ivas_mdct_core_invQ( st_ivas->hCPE[cpe_id], nTnsBitsTCX10[cpe_id], p_param[cpe_id], param_lpc[cpe_id], param[cpe_id], - fUseTns[cpe_id], tnsData[cpe_id], x, x, Aq[cpe_id], NULL, 1 ); -#endif - - st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect; - st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect; + return error; } - /* MCT core decoder */ -#ifdef IVAS_FLOAT_FIXED -#if 1 - Word32 *signal_out_fx[MAX_TRANSPORT_CHANNELS]; - Decoder_State *st, *sts_tmp[MAX_TRANSPORT_CHANNELS]; - int i = 0; - for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + if (cpe_id == 0) { - for (int ch = 0; ch < CPE_CHANNELS; ch++) - { - sts_tmp[i] = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]; - i++; - } + st_ivas->hCPE[0]->hCoreCoder[0]->total_brate = ivas_total_brate; /* set high enough to read the whole side-info; total_brate is rewritten later in ivas_mdct_core_invQ() */ } - i = 0; - for (int ch = 0; ch < hMCT->nchan_out_woLFE; ch++) + if (!st_ivas->bfi) { - if (sts_tmp[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE) - { - continue; - } - i++; - } + ivas_mdct_dec_side_bits_frame_channel(st_ivas->hCPE[cpe_id], param_lpc[cpe_id], p_param[cpe_id], st_ivas->hCPE[0]->hCoreCoder[0], nTnsBitsTCX10[cpe_id], param[cpe_id], 1, + ((cpe_id + 1) * CPE_CHANNELS > hMCT->nchan_out_woLFE)); - for (int i = 0; i < hMCT->nchan_out_woLFE; ++i) - { - signal_out_fx[i] = malloc(L_FRAME48k * sizeof(Word32)); - floatToFixed_arrL(output[i], signal_out_fx[i], Q12, L_FRAME48k); + st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect; + st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect; } - Word16 q_x[MAX_TRANSPORT_CHANNELS]; - set16_fx(q_x, Q12, MAX_TRANSPORT_CHANNELS); -#endif + } - ivas_mct_core_dec(hMCT, st_ivas->hCPE, nCPE, signal_out_fx, q_x); - - for (int ch = 0; ch < hMCT->nchan_out_woLFE; ch++) - { - fixedToFloat_arrL(signal_out_fx[ch], output[ch], q_x[ch], L_FRAME48k); - free(signal_out_fx[ch]); - } - /*for (int ch = 0; ch < hMCT->nchan_out_woLFE; ch++) - { - dbgwrite_txt(output[ch] , L_FRAME48k, "Fixed_code_mct_core.txt", NULL); - for (int k = 0; k < L_FRAME48k; k++) - { - k = k; - } - }*/ -#if 1 - if (sts_tmp[0]->igf) - { - if (!hMCT->currBlockDataCnt) - { - for (int ch = 0; ch < hMCT->nchan_out_woLFE; ch++) - { - st = sts_tmp[ch]; + /* MCT side bits decoder */ + ivas_mct_side_bits(hMCT, st_ivas->hCPE, nCPE, st_ivas->hCPE[0]->hCoreCoder[0], st_ivas->bfi, st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream, ivas_total_brate, nb_bits_metadata); - IF(st->igf) - { - me2f_buf(st->hIGFDec->virtualSpec, st->hIGFDec->virtualSpec_e, st->hIGFDec->virtualSpec_float, (N_MAX_TCX - IGF_START_MN)); - FOR(Word16 l = 0; l < IGF_START_MX; l++) - { - st->hIGFDec->infoTCXNoise[l] = (uint8_t)st->hIGFDec->infoTCXNoise_evs[l]; - } - } - } - } - } -#endif -#else - ivas_mct_core_dec( hMCT, st_ivas->hCPE, nCPE, output ); - /*for (int ch = 0; ch < hMCT->nchan_out_woLFE; ch++) - { - dbgwrite_txt(output[ch], L_FRAME48k, "Float_code_mct_core.txt", NULL); - }*/ -#endif + for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect |= st_ivas->BER_detect; + st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect |= st_ivas->BER_detect; - /* for sba to stereo output disable any further processing for TCs > 2 as it is not needed*/ - if ( st_ivas->sba_dirac_stereo_flag && st_ivas->ivas_format != SBA_ISM_FORMAT ) + for (n = 0; n < CPE_CHANNELS; n++) { - for ( cpe_id = 1; cpe_id < nCPE; cpe_id++ ) - { - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; - } - } + x[n][0] = output[n + cpe_id * CPE_CHANNELS]; + x[n][1] = output[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); + set_zero(x[n][0], L_FRAME48k / 2); + set_zero(x[n][1], L_FRAME48k / 2); } - /* MCT reconstruction and CoreCoder updates */ - for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) - { - hCPE = st_ivas->hCPE[cpe_id]; + ivas_mdct_core_invQ(st_ivas->hCPE[cpe_id], nTnsBitsTCX10[cpe_id], p_param[cpe_id], param_lpc[cpe_id], param[cpe_id], + fUseTns[cpe_id], tnsData[cpe_id], x, x, Aq[cpe_id], NULL, 1); - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - x[n][0] = output[n + cpe_id * CPE_CHANNELS]; - x[n][1] = output[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); - } + st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect; + st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect; + } - ivas_mdct_core_tns_ns( hCPE, fUseTns[cpe_id], tnsData[cpe_id], x, Aq[cpe_id], 1 ); - } + /* MCT core decoder */ + ivas_mct_core_dec(hMCT, st_ivas->hCPE, nCPE, output); - if ( st_ivas->renderer_type == RENDERER_MC ) + /* for sba to stereo output disable any further processing for TCs > 2 as it is not needed*/ + if (st_ivas->sba_dirac_stereo_flag && st_ivas->ivas_format != SBA_ISM_FORMAT) + { + for (cpe_id = 1; cpe_id < nCPE; cpe_id++) { - /* Equalization in MDCT Domain */ -#ifdef IVAS_FLOAT_FIXED - Word32 *output_fx[MAX_TRANSPORT_CHANNELS]; - for ( int i = 0; i < st_ivas->nchan_transport; ++i ) - { - output_fx[i] = malloc( L_FRAME48k * sizeof( Word32 ) ); - floatToFixed_arrL( output[i], output_fx[i], Q11, L_FRAME48k ); - } - ivas_ls_setup_conversion_process_mdct_fx( st_ivas, output_fx); - for ( int i = 0; i < st_ivas->nchan_transport; ++i ) - { - fixedToFloat_arrL( output_fx[i], output[i], Q11, L_FRAME48k ); - free(output_fx[i]); - } -#else - ivas_ls_setup_conversion_process_mdct( st_ivas, output ); -#endif + for (n = 0; n < CPE_CHANNELS; n++) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + } } + } - else if ( st_ivas->renderer_type == RENDERER_MC_PARAMMC && ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO ) ) - { - float *x_all[MAX_CICP_CHANNELS][NB_DIV]; - - for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) - { - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - x_all[n + cpe_id * CPE_CHANNELS][0] = output[n + cpe_id * CPE_CHANNELS]; - x_all[n + cpe_id * CPE_CHANNELS][1] = output[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); - } - } - -#ifdef IVAS_FLOAT_FIXED - Word32 **output_fx; - Word16 x_all_e[MAX_CICP_CHANNELS][NB_DIV] = { 0 }; - Word32 *x_all_fx[MAX_CICP_CHANNELS][NB_DIV]; - IF( ( output_fx = (Word32 **) malloc( MAX_CICP_CHANNELS * sizeof( Word32 * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) - { - FOR( n = 0; n < CPE_CHANNELS; n++ ) - { - IF( ( output_fx[n + cpe_id * CPE_CHANNELS] = (Word32 *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); - } - f2me_buf( output[n + cpe_id * CPE_CHANNELS], output_fx[n + cpe_id * CPE_CHANNELS], &x_all_e[n + cpe_id * CPE_CHANNELS][0], 960 ); - Scale_sig32( output_fx[n + cpe_id * CPE_CHANNELS], L_FRAME48k, -1 ); /*Scaling the signal down by 1 because of overflow*/ - x_all_e[n + cpe_id * CPE_CHANNELS][0]++; - x_all_fx[n + cpe_id * CPE_CHANNELS][0] = output_fx[n + cpe_id * CPE_CHANNELS]; - x_all_fx[n + cpe_id * CPE_CHANNELS][1] = output_fx[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); - x_all_e[n + cpe_id * CPE_CHANNELS][1] = x_all_e[n + cpe_id * CPE_CHANNELS][0]; - } - } - f2me_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); - f2me_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt ); - PARAM_MC_DEC_HANDLE hParamMC; - hParamMC = st_ivas->hParamMC; - floatToFixed_arr16( hParamMC->icld_q, hParamMC->icld_q_fx, 8, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); - floatToFixed_arr32( hParamMC->ls_conv_dmx_matrix, hParamMC->ls_conv_dmx_matrix_fx, 15, st_ivas->hDecoderConfig->nchan_out * ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) ); - FOR(Word16 chOutIdx = 0; chOutIdx < st_ivas->hDecoderConfig->nchan_out; chOutIdx++) - { - FOR(Word16 chInIdx = 0; chInIdx < st_ivas->nchan_transport; chInIdx++) - { - st_ivas->hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx] = float_to_fix(st_ivas->hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx], 30); /*Q30*/ - } - } - ivas_ls_setup_conversion_process_mdct_param_mc_fx( st_ivas, x_all_fx, x_all_e ); - FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) - { - FOR( n = 0; n < CPE_CHANNELS; n++ ) - { - me2f_buf( &x_all_fx[n + cpe_id * CPE_CHANNELS][0][0], x_all_e[n + cpe_id * CPE_CHANNELS][0], &x_all[n + cpe_id * CPE_CHANNELS][0][0], L_FRAME48k / 2 ); - me2f_buf( &x_all_fx[n + cpe_id * CPE_CHANNELS][1][0], x_all_e[n + cpe_id * CPE_CHANNELS][1], &x_all[n + cpe_id * CPE_CHANNELS][1][0], L_FRAME48k / 2 ); - } - } - me2f_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); - me2f_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt ); - - FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) - { - FOR( n = 0; n < CPE_CHANNELS; n++ ) - { - free( output_fx[n + cpe_id * CPE_CHANNELS] ); - } - } -#else - ivas_ls_setup_conversion_process_mdct_param_mc( st_ivas, x_all ); -#endif // - } + /* MCT reconstruction and CoreCoder updates */ + for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + hCPE = st_ivas->hCPE[cpe_id]; - for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + for (n = 0; n < CPE_CHANNELS; n++) { - hCPE = st_ivas->hCPE[cpe_id]; - sts = hCPE->hCoreCoder; - - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - x[n][0] = output[n + cpe_id * CPE_CHANNELS]; - x[n][1] = output[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); - } - - ivas_mdct_core_reconstruct( hCPE, x, synth, fUseTns[cpe_id], 1 ); - - /*----------------------------------------------------------------* - * CoreCoder Post-processing and updates - *----------------------------------------------------------------*/ - - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - if ( st_ivas->sba_dirac_stereo_flag && ( st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2 ) ) - { - ivas_post_proc( NULL, hCPE, n, synth[n], NULL, output_frame, 1 ); - } - - /* Postprocessing for ACELP/MDCT core switching and synchronization */ - if ( ( error = core_switching_post_dec( sts[n], synth[n], output[cpe_id * CPE_CHANNELS + n], hCPE->output_mem[1], st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, ( st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2 ) ? st_ivas->sba_dirac_stereo_flag : 0, -1, hCPE->last_element_mode ) ) != IVAS_ERR_OK ) - { - return error; - } + x[n][0] = output[n + cpe_id * CPE_CHANNELS]; + x[n][1] = output[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); + } - /* final output of synthesis signal */ - mvr2r( synth[n], output[cpe_id * CPE_CHANNELS + n], output_frame ); + ivas_mdct_core_tns_ns(hCPE, fUseTns[cpe_id], tnsData[cpe_id], x, Aq[cpe_id], 1); + } - /* Save synthesis for HQ FEC */ -#ifdef IVAS_FLOAT_FIXED - Word32 exp_max = 0, i; - Word32 output_fx[L_FRAME48k]; - if ( ( sts[n]->codec_mode == MODE1 && sts[n]->hTcxDec != NULL ) && ( ( sts[n]->core == ACELP_CORE && !( sts[n]->bfi == 1 && sts[n]->con_tcx == 1 ) ) || sts[n]->core == HQ_CORE ) ) - { - double max_prev_synth_buffer = 0.0f, max_old_out = 0.0f, max_delay_buf_out = 0.0f, max_ouput = 0.0f, max_synth_history = 0.0f; - Word32 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0; + if (st_ivas->renderer_type == RENDERER_MC) + { + /* Equalization in MDCT Domain */ + ivas_ls_setup_conversion_process_mdct(st_ivas, output); + } - /*Find maximum values for all the buffers*/ - for ( i = 0; i < NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); i++ ) - { - max_prev_synth_buffer = max( max_prev_synth_buffer, fabs( sts[n]->prev_synth_buffer[i] ) ); - } - if ( (Word16) max_prev_synth_buffer != 0 ) - { - frexp( max_prev_synth_buffer, &exp_prev_synth_buffer ); - } + else if (st_ivas->renderer_type == RENDERER_MC_PARAMMC && (st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO)) + { + float *x_all[MAX_CICP_CHANNELS][NB_DIV]; - for ( i = NS2SA( sts[n]->output_Fs, N_ZERO_MDCT_NS ); i < NS2SA( sts[n]->output_Fs, N_ZERO_MDCT_NS ) + NS2SA( sts[n]->output_Fs, PH_ECU_LOOKAHEAD_NS ); i++ ) - { - max_old_out = max( max_old_out, fabs( sts[n]->hHQ_core->old_out[i] ) ); - } - if ( (Word16) max_old_out != 0 ) - { - frexp( max_old_out, &exp_old_out ); - } + for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + for (n = 0; n < CPE_CHANNELS; n++) + { + x_all[n + cpe_id * CPE_CHANNELS][0] = output[n + cpe_id * CPE_CHANNELS]; + x_all[n + cpe_id * CPE_CHANNELS][1] = output[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); + } + } - for ( i = 0; i < NS2SA( sts[n]->output_Fs, DELAY_CLDFB_NS ); i++ ) - { - max_delay_buf_out = max( max_delay_buf_out, fabs( sts[n]->delay_buf_out[i] ) ); - } - if ( (Word16) max_delay_buf_out != 0 ) - { - frexp( max_delay_buf_out, &exp_delay_buf_out ); - } + ivas_ls_setup_conversion_process_mdct_param_mc(st_ivas, x_all); + } - for ( i = 0; i < output_frame; i++ ) - { - max_ouput = max( max_ouput, fabs( output[cpe_id * CPE_CHANNELS + n][i] ) ); - } - if ( (Word16) max_ouput != 0 ) - { - frexp( max_ouput, &exp_ouput ); - } + for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + hCPE = st_ivas->hCPE[cpe_id]; + sts = hCPE->hCoreCoder; - for ( i = output_frame; i < 2 * output_frame - NS2SA( sts[n]->output_Fs, DELAY_CLDFB_NS ) + NS2SA( sts[n]->output_Fs, PH_ECU_MEM_NS ); i++ ) - { - max_synth_history = max( max_synth_history, fabs( sts[n]->hTcxDec->synth_history[i] ) ); - } + for (n = 0; n < CPE_CHANNELS; n++) + { + x[n][0] = output[n + cpe_id * CPE_CHANNELS]; + x[n][1] = output[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); + } - if ( (Word16) max_synth_history != 0 ) - { - frexp( max_synth_history, &exp_synth_history ); - } + ivas_mdct_core_reconstruct(hCPE, x, synth, fUseTns[cpe_id], 1); - /*Find a commen maximum exp*/ - exp_max = max( exp_synth_history, exp_ouput ); - exp_max = max( exp_max, exp_prev_synth_buffer ); - exp_max = max( exp_max, exp_old_out ); - exp_max = max( exp_max, exp_delay_buf_out ); + /*----------------------------------------------------------------* + * CoreCoder Post-processing and updates + *----------------------------------------------------------------*/ - for ( i = 0; i < NS2SA( sts[n]->output_Fs, DELAY_CLDFB_NS ); i++ ) - { - f2fix_16( &sts[n]->delay_buf_out[i], &sts[n]->delay_buf_out_fx[i], exp_max ); - } - for ( i = NS2SA( sts[n]->output_Fs, N_ZERO_MDCT_NS ); i < NS2SA( sts[n]->output_Fs, PH_ECU_LOOKAHEAD_NS ); i++ ) - { - f2fix_16( &sts[n]->hHQ_core->old_out[i], &sts[n]->hHQ_core->old_out_fx[i], exp_max ); - } - for ( i = 0; i < NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); i++ ) - { - f2fix_16( &sts[n]->prev_synth_buffer[i], &sts[n]->prev_synth_buffer_fx[i], exp_max ); - } - for ( i = output_frame; i < 2 * output_frame - NS2SA( sts[n]->output_Fs, DELAY_CLDFB_NS ) + NS2SA( sts[n]->output_Fs, PH_ECU_MEM_NS ); i++ ) - { - f2fix_16( &sts[n]->hTcxDec->synth_history[i], &sts[n]->hTcxDec->synth_history_fx[i], exp_max ); - } - for ( i = 0; i < output_frame; i++ ) - { - f2fix( &output[cpe_id * CPE_CHANNELS + n][i], &output_fx[i], exp_max ); - } - } + for (n = 0; n < CPE_CHANNELS; n++) + { + if (st_ivas->sba_dirac_stereo_flag && (st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2)) + { + ivas_post_proc(NULL, hCPE, n, synth[n], NULL, output_frame, 1); + } - save_synthesis_hq_fec_fx( sts[n], output_fx, output_frame, hCPE ); - save_synthesis_hq_fec(sts[n], output[cpe_id * CPE_CHANNELS + n], output_frame, hCPE); - if ( ( sts[n]->codec_mode == MODE1 && sts[n]->hTcxDec != NULL ) && ( ( sts[n]->core == ACELP_CORE && !( sts[n]->bfi == 1 && sts[n]->con_tcx == 1 ) ) || sts[n]->core == HQ_CORE ) ) - { - /*dumps*/ - float track = 0; - for ( i = 0; i < 2 * output_frame; i++ ) - { - fix2f_16( &sts[n]->hTcxDec->synth_history_fx[i], &track, exp_max ); - fix2f_16( &sts[n]->hTcxDec->synth_history_fx[i], &sts[n]->hTcxDec->synth_history[i], exp_max ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( &track, 1, "Fixed_code_synth_history_fx.txt", NULL ); - dbgwrite_txt( &sts[n]->hTcxDec->synth_history[i], 1, "Float_code_synth_history_fx.txt", NULL ); -#endif - } - } -#else - save_synthesis_hq_fec( sts[n], output[cpe_id * CPE_CHANNELS + n], output_frame, hCPE ); -#endif + /* Postprocessing for ACELP/MDCT core switching and synchronization */ + if ((error = core_switching_post_dec(sts[n], synth[n], output[cpe_id * CPE_CHANNELS + n], hCPE->output_mem[1], st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, (st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2) ? st_ivas->sba_dirac_stereo_flag : 0, -1, hCPE->last_element_mode)) != IVAS_ERR_OK) + { + return error; + } - /* CoreCoder common updates */ - updt_dec_common( sts[n], NORMAL_HQ_CORE, -1, output[cpe_id * CPE_CHANNELS + n] ); + /* final output of synthesis signal */ + mvr2r(synth[n], output[cpe_id * CPE_CHANNELS + n], output_frame); - } /* n_channels loop */ + /* Save synthesis for HQ FEC */ + save_synthesis_hq_fec(sts[n], output[cpe_id * CPE_CHANNELS + n], output_frame, hCPE); + /* CoreCoder common updates */ + updt_dec_common(sts[n], NORMAL_HQ_CORE, -1, output[cpe_id * CPE_CHANNELS + n]); - /* synthesis synchronization between stereo modes */ - if ( !st_ivas->sba_dirac_stereo_flag || ( st_ivas->ivas_format == SBA_ISM_FORMAT && cpe_id < nCPE - 2 ) ) - { -#ifdef IVAS_FLOAT_FIXED - synchro_synthesis_fixed( ivas_total_brate, hCPE, output + cpe_id * CPE_CHANNELS, output_frame, 0 ); -#else - synchro_synthesis( ivas_total_brate, hCPE, output + cpe_id * CPE_CHANNELS, output_frame, 0 ); -#endif + } /* n_channels loop */ - //Todo use below once input is fixed not done due to complication in pointer - //synchro_synthesis_fixed_clean( ivas_total_brate, hCPE, output + cpe_id * CPE_CHANNELS, output_frame, 0 ); - } + /* synthesis synchronization between stereo modes */ + if (!st_ivas->sba_dirac_stereo_flag || (st_ivas->ivas_format == SBA_ISM_FORMAT && cpe_id < nCPE - 2)) + { + synchro_synthesis(ivas_total_brate, hCPE, output + cpe_id * CPE_CHANNELS, output_frame, 0); } - /* move channels after LFE to correct output for multi-channel MCT */ - if ( st_ivas->ivas_format == MC_FORMAT && ( st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) ) - { - float tmp[L_FRAME48k]; + } - /*save center channel output*/ - mvr2r( output[hMCT->nchan_out_woLFE - 1], tmp, output_frame ); + /* move channels after LFE to correct output for multi-channel MCT */ + if (st_ivas->ivas_format == MC_FORMAT && (st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX)) + { + float tmp[L_FRAME48k]; - for ( n = hMCT->nchan_out_woLFE - 1; n >= LFE_CHANNEL; n-- ) - { - mvr2r( output[n - 1], output[n + 1], output_frame ); - } - mvr2r( tmp, output[LFE_CHANNEL - 1], output_frame ); + /*save center channel output*/ + mvr2r(output[hMCT->nchan_out_woLFE - 1], tmp, output_frame); - /* save LFE channel */ - mvr2r( output_lfe_ch, output[LFE_CHANNEL], output_frame ); + for (n = hMCT->nchan_out_woLFE - 1; n >= LFE_CHANNEL; n--) + { + mvr2r(output[n - 1], output[n + 1], output_frame); } + mvr2r(tmp, output[LFE_CHANNEL - 1], output_frame); + /* save LFE channel */ + mvr2r(output_lfe_ch, output[LFE_CHANNEL], output_frame); + } - pop_wmops(); - return error; + + pop_wmops(); + return error; } #else ivas_error ivas_mct_dec_fx( diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal.c index 3829a92132e7668b56169ed4c542aaf043714cda..ec9da41ac0a132d6f73a1951e033d8869db06873 100644 --- a/lib_dec/ivas_sba_rendering_internal.c +++ b/lib_dec/ivas_sba_rendering_internal.c @@ -903,6 +903,8 @@ void ivas_sba_mix_matrix_determiner_fx( } #endif // IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED + void ivas_sba_mix_matrix_determiner( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ float *output[], /* i/o: transport/output audio channels */ @@ -1092,4 +1094,60 @@ void ivas_sba_mix_matrix_determiner( return; } +#else + +void ivas_sba_mix_matrix_determiner( + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + float *output[], /* i/o: transport/output audio channels */ + const int16_t bfi, /* i : BFI flag */ + const int16_t nchan_remapped, /* i : num channels after remapping of TCs */ + const int16_t output_frame, /* i : output frame length */ + const int16_t num_md_sub_frames /* i : number of subframes in mixing matrix*/ +) +{ + int16_t i, ch; + float temp; + int16_t num_bands_out, nchan_transport, nchan_out; + + /* Convert numeric range */ + for (ch = 0; ch < nchan_remapped; ch++) + { + for (i = 0; i < output_frame; i++) + { + temp = output[ch][i]; + temp = floorf(temp + 0.5f); + + if (temp > MAX16B_FLT) + { + temp = MAX16B_FLT; + } + else if (temp < (-1.0f * PCM16_TO_FLT_FAC)) + { + temp = (-1.0f * PCM16_TO_FLT_FAC); + } + temp *= (1.0f / PCM16_TO_FLT_FAC); + output[ch][i] = temp; + } + } + + /* AGC */ + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + nchan_out = nchan_transport; + ivas_agc_dec_process(hSpar->hAgcDec, output, output, nchan_transport, output_frame); + + /* Convert numeric range back */ + for (ch = 0; ch < nchan_out; ch++) + { + for (i = 0; i < output_frame; i++) + { + output[ch][i] = output[ch][i] * PCM16_TO_FLT_FAC; + } + } + + /* Mixing matrix determiner */ + num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; + ivas_spar_dec_gen_umx_mat(hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames); + return; +} +#endif diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 2bd011811bd79b0f3abd36dcb79ab64bf1a8cfff..695c72ec4637ac4116343963fd90f6d72151cc00 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -1208,7 +1208,7 @@ static void ivas_dec_mono_sba_handling( * * SPAR Meta Data decoder process *-----------------------------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void ivas_spar_md_dec_process( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ @@ -1360,7 +1360,127 @@ void ivas_spar_md_dec_process( return; } +#else +void ivas_spar_md_dec_process( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ + const int16_t num_bands_out, /* i : number of output bands */ + const int16_t sba_order /* i : Ambisonic (SBA) order */ +) +{ + int16_t j, k, b, bw, dtx_vad, nB, i_ts; + ivas_spar_md_dec_state_t *hMdDec; + int16_t num_md_chs; + int16_t num_md_sub_frames; + int16_t dyn_active_w_flag; + int16_t active_w_vlbr; + + hMdDec = st_ivas->hSpar->hMdDec; + + active_w_vlbr = (st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4) ? 1 : 0; + + num_md_chs = ivas_sba_get_nchan_metadata(sba_order, st_ivas->hDecoderConfig->ivas_total_brate); + + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes(sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate); + + if (hMdDec->spar_md_cfg.nchan_transport > 1 && hMdDec->spar_md_cfg.nchan_transport <= 3) + { + hMdDec->spar_md.res_ind = 0; + dyn_active_w_flag = get_next_indice(st0, 1); + if (dyn_active_w_flag == 1) + { + if (hMdDec->spar_md_cfg.nchan_transport == 2) + { + hMdDec->spar_md.res_ind = get_next_indice(st0, 1); + hMdDec->spar_md.res_ind += hMdDec->spar_md_cfg.nchan_transport; + } + else if (hMdDec->spar_md_cfg.nchan_transport == 3) + { + hMdDec->spar_md.res_ind = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order][hMdDec->spar_md_cfg.nchan_transport]; + } + } + } + else + { + dyn_active_w_flag = 0; + if (hMdDec->spar_md_cfg.nchan_transport == FOA_CHANNELS) + { + get_next_indice(st0, 1); + } + } + + ivas_spar_dec_parse_md_bs(hMdDec, st0, &nB, &bw, &dtx_vad, st_ivas->hDecoderConfig->ivas_total_brate, + st_ivas->hQMetaData->sba_inactive_mode + ); + assert(nB == hMdDec->spar_md.num_bands); + assert(bw == 1); + ivas_spar_md_fill_invalid_bandcoeffs( + hMdDec->spar_md.band_coeffs, + hMdDec->band_coeffs_prev, + &hMdDec->valid_bands[0], + &hMdDec->base_band_coeffs_age[0], + &hMdDec->first_valid_frame, + nB); + + ivas_dec_mono_sba_handling(st_ivas); + + /* SPAR to DirAC conversion */ + if (hMdDec->spar_hoa_dirac2spar_md_flag == 1) + { + ivas_spar_to_dirac(st_ivas, hMdDec, dtx_vad, num_bands_out, bw, dyn_active_w_flag); + } + + /* set correct number of bands*/ + nB = IVAS_MAX_NUM_BANDS; + + /* expand DirAC MD to all time slots */ + for (i_ts = 1; i_ts < num_md_sub_frames; i_ts++) + { + for (b = 0; b < hMdDec->spar_md.num_bands; b++) + { + for (j = 0; j < IVAS_SPAR_MAX_CH - 1; j++) + { + hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[j] = hMdDec->spar_md.band_coeffs[b].pred_re[j]; + } + + for (j = 0; j < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; j++) + { + for (k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++) + { + hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re[j][k] = hMdDec->spar_md.band_coeffs[b].C_re[j][k]; + } + } + + for (j = 0; j < IVAS_SPAR_MAX_CH - 1; j++) + { + hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re[j] = hMdDec->spar_md.band_coeffs[b].P_re[j]; + } + } + } + + ivas_get_spar_matrices(hMdDec, num_bands_out, num_md_sub_frames, bw, dtx_vad, nB, num_md_chs, active_w_vlbr, dyn_active_w_flag); + +#ifdef DEBUG_SPAR_DIRAC_WRITE_OUT_PRED_PARS + { + static FILE *fid = 0; + int16_t band = 9; + if (!fid) + { + fid = fopen("pred_coeffs_dec.txt", "wt"); + } + fprintf(fid, "%.6f\n", hMdDec->mixer_mat[1][0][band]); + } +#endif + ivas_spar_md_fill_invalid_bands(&hMdDec->spar_coeffs, &hMdDec->spar_coeffs_prev, &hMdDec->valid_bands[0], &hMdDec->base_band_age[0], num_bands_out, num_md_chs, num_md_sub_frames); + + + hMdDec->dtx_md_smoothing_cntr = 1; + + return; +} + +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_spar_chk_zero_coefs() * diff --git a/lib_dec/ivas_stereo_dft_dec.c b/lib_dec/ivas_stereo_dft_dec.c index d0381d674e9b0f28edeb1111f3cda6e6620271c4..d178c08fc0eb0919bb59ae55fa012116c2570821 100644 --- a/lib_dec/ivas_stereo_dft_dec.c +++ b/lib_dec/ivas_stereo_dft_dec.c @@ -546,6 +546,7 @@ void stereo_dft_dec_open( * Reset DFT stereo memories *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void stereo_dft_dec_reset( STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: decoder DFT stereo handle */ ) @@ -847,7 +848,135 @@ void stereo_dft_dec_reset( return; } +#else + +void stereo_dft_dec_reset( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: decoder DFT stereo handle */ +) +{ + int16_t i; + int16_t j, b; + + /*Configuration*/ + set_s( hStereoDft->prm_res, hStereoDft->hConfig->prm_res, STEREO_DFT_DEC_DFT_NB ); + + /* SIDE_GAIN */ + set_s( hStereoDft->side_gain_index, 15, STEREO_DFT_BAND_MAX ); + set_s( hStereoDft->side_gain_index_previous, 15, STEREO_DFT_BAND_MAX ); + + /*residual prediction*/ + set_s( hStereoDft->res_pred_mode, hStereoDft->hConfig->res_pred_mode, STEREO_DFT_DEC_DFT_NB ); + for ( i = 0; i < STEREO_DFT_PAST_MAX; i++ ) + { + set_zero( hStereoDft->DFT_past_DMX[i], STEREO_DFT32MS_N_32k ); + set_zero( hStereoDft->past_res_pred_gain[i], STEREO_DFT_BAND_MAX ); + } + + hStereoDft->past_DMX_pos = 0; + + set_s( hStereoDft->res_pred_index_previous, 0, STEREO_DFT_BAND_MAX ); + + for ( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) + { + hStereoDft->res_gains_ind[0][i] = 15.f; + } + + set_zero( hStereoDft->res_gains_ind[1], STEREO_DFT_BAND_MAX ); + + /*residual coding*/ + set_s( hStereoDft->res_cod_mode, hStereoDft->hConfig->res_cod_mode, STEREO_DFT_DEC_DFT_NB ); + hStereoDft->res_cod_band_max = dft_band_res_cod[hStereoDft->hConfig->band_res][hStereoDft->hConfig->res_cod_mode]; + set_zero( hStereoDft->res_cod_mem, STEREO_DFT_OVL_8k ); + + hStereoDft->res_pred_band_min = max( STEREO_DFT_RES_PRED_BAND_MIN, hStereoDft->res_cod_band_max ); + + hStereoDft->stab_fac_smooth_res = 0.f; + bass_psfilter_init( hStereoDft->hBpf ); + + tcxltp_dec_init( hStereoDft->hTcxLtpDec, 0, MODE1, IVAS_CPE_DFT, PIT_MAX, 12800 ); + + hStereoDft->reverb_flag = 0; + + hStereoDft->bpf_error_signal_last = 0.0f; + hStereoDft->bpf_error_ratio_mem = 1.0f; + hStereoDft->res_hb_nrg_mem = 0.0f; + + /*reset parameters*/ + set_zero( hStereoDft->side_gain, STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX ); + set_zero( hStereoDft->gipd, STEREO_DFT_DEC_DFT_NB ); + set_zero( hStereoDft->itd, STEREO_DFT_DEC_DFT_NB ); + set_zero( hStereoDft->res_pred_gain, STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX ); + + hStereoDft->wasTransient = 0; + hStereoDft->attackPresent = 0; + + hStereoDft->lt_pred_gain = 0.0f; + hStereoDft->lt_pred_gain_variation = 0.0f; + hStereoDft->lt_var_mean_ratio = STEREO_DFT_RES_RATIO_LIMIT; + hStereoDft->stefi_short_gain = 1.0f; + hStereoDft->stefi_long_gain = 0.0f; + + set_zero( hStereoDft->g_state, STEREO_DFT_BAND_MAX ); + + init_basic_allpass( &hStereoDft->ap1, dft_ap_gains[0], dft_ap_delays[0] ); + init_basic_allpass( &hStereoDft->ap2, dft_ap_gains[1], dft_ap_delays[1] ); + init_basic_allpass( &hStereoDft->ap3, dft_ap_gains[2], dft_ap_delays[2] ); + + set_zero( hStereoDft->ap_delay_mem, NS2SA( 16000, DELAY_BWE_TOTAL_NS ) ); + set_zero( hStereoDft->ap_fade_mem, STEREO_DFT_ALLPASS_FADELEN_16k ); + hStereoDft->ap_wasTransient = 0; + set_zero( hStereoDft->smooth_dmx_nrg, STEREO_DFT_BAND_MAX ); + set_zero( hStereoDft->smooth_res_nrg, STEREO_DFT_BAND_MAX ); + + set_s( hStereoDft->core_hist, ACELP_CORE, STEREO_DFT_CORE_HIST_MAX ); + + set_zero( hStereoDft->hb_stefi_sig, L_FRAME48k + NS2SA( 48000, STEREO_DFT_TD_STEFI_DELAY_NS ) ); + set_zero( hStereoDft->hb_nrg, STEREO_DFT_CORE_HIST_MAX ); + set_zero( hStereoDft->td_gain, STEREO_DFT_CORE_HIST_MAX ); + + /* PLC parameters */ + set_zero( hStereoDft->res_mem, STEREO_DFT_RES_BW_MAX ); + hStereoDft->time_offs = 0; + hStereoDft->past_dmx_nrg = 0; + hStereoDft->sg_mean = 0.0f; + hStereoDft->sg_mem_corrupt = 0; + hStereoDft->recovery_flg = 0; + for ( i = 0; i < SBA_DIRAC_STEREO_NUM_BANDS; i++ ) + { + set_zero( hStereoDft->smooth_buf[i], SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + set_zero( hStereoDft->smooth_fac[0], SBA_DIRAC_STEREO_NUM_BANDS ); + set_zero( hStereoDft->smooth_fac[1], SBA_DIRAC_STEREO_NUM_BANDS ); + + hStereoDft->itd_xfade_target = 0.0f; + hStereoDft->itd_xfade_step = 0.0f; + hStereoDft->itd_xfade_counter = 0; + hStereoDft->itd_xfade_prev = 0.0f; + hStereoDft->last_active_element_brate = 0; + hStereoDft->ipd_xfade_target = 0.0f; + hStereoDft->ipd_xfade_step = 0.0f; + hStereoDft->ipd_xfade_counter = 0; + hStereoDft->ipd_xfade_prev = 0.0f; + + for ( b = 0; b < hStereoDft->nbands; b++ ) + { + for ( i = 0; i < 2; i++ ) + { + for ( j = 0; j < 4; j++ ) + { + hStereoDft->mixer_mat_smooth[i][j][b] = 0.0f; + } + } + } + hStereoDft->first_frame = 1; + hStereoDft->g_L_prev = 0.f; + hStereoDft->g_R_prev = 0.f; + + return; +} + +#endif /*------------------------------------------------------------------------- * stereo_dft_dec_update() * diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index d930ea19add1f90ae9d4eb7d54d423a6a537307f..c427203d2082b54029a7707c2a0b65ac08ca919b 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -3346,7 +3346,7 @@ void swb_tbe_dec( else { /* individual sqrt to avoid infinite (nan) value due to acelp_core_dec changes */ - scale = (float) (sqrt( curr_pow ) /sqrt( prev_pow )); + scale = (float)sqrt(curr_pow / prev_pow); } for ( i = 0; i < L_SHB_LAHEAD; i++ ) @@ -4744,12 +4744,13 @@ void TBEreset_dec( * * Initialize TD BWE state structure at the decoder *-------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void td_bwe_dec_init( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ const int16_t extl, /* i : BWE extension layer */ const int32_t output_Fs /* i : output sampling rate */ ) + { int16_t i; @@ -4885,4 +4886,78 @@ void td_bwe_dec_init( #endif return; -} \ No newline at end of file +} + +#else + +void td_bwe_dec_init( + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + const int16_t extl, /* i : BWE extension layer */ + const int32_t output_Fs /* i : output sampling rate */ +) +{ + int16_t i; + + /* init. SHB buffers */; + set_f(hBWE_TD->old_bwe_exc, 0.0f, (PIT16k_MAX * 2)); + hBWE_TD->bwe_seed[0] = 23; /* 1; */ + hBWE_TD->bwe_seed[1] = 59; /* 10000; */ + set_f(hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET); + hBWE_TD->bwe_non_lin_prev_scale = 0; + + set_f(hBWE_TD->genSHBsynth_Hilbert_Mem, 0.0f, HILBERT_MEM_SIZE); + set_f(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 0.0f, 2 * ALLPASSSECTIONS_STEEP); + + hBWE_TD->syn_dm_phase = 0; + hBWE_TD->prev_fbbwe_ratio = 1.0f; + hBWE_TD->prev_wb_bwe_frame_pow = 0.001f; + hBWE_TD->prev_swb_bwe_frame_pow = 0.001f; + + /* reset SHB buffers */ + ResetSHBbuffer_Dec(hBWE_TD, extl); + + if (output_Fs == 48000) + { + set_f(hBWE_TD->fbbwe_hpf_mem[0], 0, 4); + set_f(hBWE_TD->fbbwe_hpf_mem[1], 0, 4); + set_f(hBWE_TD->fbbwe_hpf_mem[2], 0, 4); + set_f(hBWE_TD->fbbwe_hpf_mem[3], 0, 4); + } + + set_f(hBWE_TD->mem_resamp_HB, 0, INTERP_3_1_MEM_LEN); + set_f(hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1); + + hBWE_TD->tilt_mem = 0.0f; + set_f(hBWE_TD->prev_lsf_diff, 0.5f, LPC_SHB_ORDER - 2); + hBWE_TD->prev_tilt_para = 0.0f; + set_f(hBWE_TD->cur_sub_Aq, 0.0f, M + 1); + set_f(hBWE_TD->int_3_over_2_tbemem_dec, 0.0f, INTERP_3_2_MEM_LEN); + + /* TD BWE post-processing */ + hBWE_TD->ptr_mem_stp_swb = hBWE_TD->mem_stp_swb + LPC_SHB_ORDER - 1; + set_f(hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER); + + for (i = 0; i < LPC_SHB_ORDER; i++) + { + hBWE_TD->swb_lsp_prev_interp[i] = (float)cos((float)i * EVS_PI / (float) 10.0f); + } + + hBWE_TD->prev1_shb_ener_sf = 1.0f; + hBWE_TD->prev2_shb_ener_sf = 1.0f; + hBWE_TD->prev3_shb_ener_sf = 1.0f; + hBWE_TD->prev_res_shb_gshape = 0.125f; + hBWE_TD->prev_mixFactors = 0.5f; + hBWE_TD->prev_GainShape = 0.0f; + set_f(hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER); + hBWE_TD->fb_tbe_demph = 0.0f; + + set_f(hBWE_TD->old_hb_synth, 0, L_FRAME48k); + + hBWE_TD->GainFrame_prevfrm = 0.0f; + + hBWE_TD->prev_ener = 0.0f; + + return; +} + +#endif \ No newline at end of file