diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h new file mode 100644 index 0000000000000000000000000000000000000000..9ee17fed6baebe335659ce5631a2ce4c1d7adf9f --- /dev/null +++ b/lib_com/ivas_prot.h @@ -0,0 +1,4068 @@ +/****************************************************************************************************** + + (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#ifndef IVAS_PROT_H +#define IVAS_PROT_H + +#include +#include "options.h" +#include +#include "typedef.h" +#include "stat_enc.h" +#include "stat_dec.h" +#include "stat_com.h" +#include "ivas_stat_enc.h" +#include "ivas_stat_dec.h" +#include "ivas_stat_rend.h" +#include "ivas_stat_com.h" +#include "ivas_error_utils.h" + +#define IVAS_FLOAT_FIXED_TO_BE_REMOVED + +/* clang-format off */ + +/*----------------------------------------------------------------------------------* + * General IVAS prototypes + *----------------------------------------------------------------------------------*/ + +ivas_error ivas_enc( + Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ + const int16_t *data, /* i : input signal */ + const int16_t n_samples /* i : number of input samples */ +); + +void stereo_dmx_evs_enc( + STEREO_DMX_EVS_ENC_HANDLE hStereoDmxEVS, /* i/o: Stereo downmix for EVS encoder handle */ + const int32_t input_Fs, /* i : input sampling rate */ + int16_t data[CPE_CHANNELS * L_FRAME48k], /* i/o: input signal */ + const int16_t n_samples, /* i : number of input samples */ + const bool is_binaural /* i : indication that input is binaural audio */ +); + +/*! r: number of channels to be analysed */ + +void copy_encoder_config_ivas_fx( + Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ + Encoder_State *st, /* o : encoder state structure */ + const Word16 flag_all /* i : flag 1==update all, 0=partial update Q0*/ +); + + + +ivas_error create_sce_enc( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const int16_t sce_id, /* i : SCE # identifier */ + const int32_t element_brate /* i : element bitrate */ +); + +ivas_error create_cpe_enc( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const int16_t cpe_id, /* i : CPE # identifier */ + const int32_t element_brate /* i : element bitrate */ +); + +ivas_error create_mct_enc_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +void destroy_cpe_enc( + CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ +); + +void ivas_mct_enc_close_fx( + MCT_ENC_HANDLE *hMCT /* i/o: MCT encoder structure */ +); + +ivas_error ivas_corecoder_enc_reconfig( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const int16_t nSCE_old, /* i : number of SCEs in previous frame */ + const int16_t nCPE_old, /* i : number of CPEs in previous frame */ + const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ + const int32_t brate_SCE, /* i : bitrate to be set for the SCEs */ + const int32_t brate_CPE, /* i : bitrate to be set for the CPEs */ + const MC_MODE last_mc_mode /* i : switching between MC modes: last mode */ +); + +ivas_error ivas_sce_enc( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const int16_t sce_id, /* i : SCE # identifier */ + const float data_f[], /* i : input signal for single channel */ + const int16_t input_frame, /* i : input frame length per channel */ + const int16_t nb_bits_metadata /* i : number of metadata bits */ +); + + +ivas_error ivas_cpe_enc( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 cpe_id, /* i : CPE # identifier */ + float data_f_ch0[], /* i : input signal for channel 0 */ + float data_f_ch1[], /* i : input signal for channel 1 */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +); + +ivas_error ivas_mct_enc( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + float *data[MCT_MAX_CHANNELS], /* i : input signal buffers */ + const int16_t input_frame, /* i : input frame length per channel */ + const int16_t nb_bits_metadata /* i : number of metadata bits */ +); + +ivas_error pre_proc_front_ivas( + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const int32_t element_brate, /* i : SCE/CPE element bitrate */ + const int16_t nb_bits_metadata, /* i : number of metadata bits */ + const int16_t input_frame, /* i : frame length */ + const int16_t n, /* i : channel number */ + float old_inp_12k8[], /* o : buffer of old input signal */ + float old_inp_16k[], /* o : buffer of old input signal @16kHz */ + float *ener, /* o : residual energy from Levinson-Durbin */ + float *relE, /* o : frame relative energy */ + float A[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ + float Aw[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ + float epsP[M + 1], /* o : LP prediction errors */ + float lsp_new[M], /* o : LSPs at the end of the frame */ + float lsp_mid[M], /* o : LSPs in the middle of the frame */ + int16_t *vad_hover_flag, /* o : VAD hangover flag */ + int16_t *attack_flag, /* o : flag signaling attack */ + float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ + float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ + float old_wsp[], /* o : weighted input signal buffer */ + float pitch_fr[NB_SUBFR], /* o : fractional pitch values */ + float voicing_fr[NB_SUBFR], /* o : fractional pitch gains */ + int16_t *loc_harm, /* o : harmonicity flag */ + float *cor_map_sum, /* o : speech/music clasif. parameter */ + int16_t *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */ + float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ + float fft_buff[2 * L_FFT], /* o : FFT buffer */ + const float tdm_A_PCh[M + 1], /* i : unq. LP coeff. of primary channel */ + const float tdm_lsp_new_PCh[M], /* i : unq. LSPs of primary channel */ + const float currFlatness, /* i : flatness parameter */ + const int16_t tdm_ratio_idx, /* i : Current Ratio_L index */ + float fr_bands_LR[][2 * NB_BANDS], /* i : energy in frequency bands */ + const float Etot_LR[], /* i : total energy Left & Right channel */ + float lf_E_LR[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */ + const int16_t localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels */ + float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */ + const int16_t flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ + const int16_t front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ + const int16_t force_front_vad, /* i : flag to force VAD decision */ + const int16_t front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const int32_t ivas_total_brate /* i : IVAS total bitrate */ +); + +ivas_error pre_proc_front_ivas_fx( + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word32 element_brate, /* i : SCE/CPE element bitrate Q0*/ + const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ + const Word16 input_frame, /* i : frame length Q0*/ + const Word16 n, /* i : channel number Q0*/ + Word16 old_inp_12k8_fx[], /* o : buffer of old input signal Q_new-1*/ + Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q_new-1*/ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ + Word16 *relE_fx, /* o : frame relative energy Q8*/ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes Q12*/ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes Q12*/ + Word32 epsP_fx[M + 1], /* o : LP prediction errors epsP_fx_q*/ + Word16 *epsP_fx_q, + Word16 lsp_new_fx[M], /* o : LSPs at the end of the frame Q15*/ + Word16 lsp_mid_fx[M], /* o : LSPs in the middle of the frame Q15*/ + Word16 *vad_hover_flag, /* o : VAD hangover flag Q0*/ + Word16 *attack_flag, /* o : flag signaling attack Q0*/ + Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf)*/ + Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf)*/ + Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ + Word16 old_wsp_fx[], /* o : weighted input signal buffer q_old_wsp*/ + Word16 *q_old_wsp, + Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6*/ + Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15*/ + Word16 *loc_harm, /* o : harmonicity flag Q0*/ + Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8*/ + Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO Q0*/ + Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer enerBuffer_fx_exp*/ + Word16 *enerBuffer_fx_exp, /* o : energy buffer */ + Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer fft_buff_fx_q*/ + Word16 *fft_buff_fx_q, /* o : FFT buffer */ + const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12*/ + const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15*/ + const Word16 currFlatness_fx, /* i : flatness parameter Q7*/ + const Word16 tdm_ratio_idx, /* i : Current Ratio_L index Q0*/ + Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands (fr_bands_LR_fx_q) fr_bands_LR_fx_q*/ + Word16 fr_bands_LR_fx_q[CPE_CHANNELS], + const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ + Word32 lf_E_LR_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels (lf_E_LR_fx_q)*/ + Word16 lf_E_LR_fx_q, + const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels Q0*/ + Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN (band_energies_LR_fx_q)*/ + Word16 band_energies_LR_fx_q, + const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ + const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision Q0*/ + const Word16 force_front_vad, /* i : flag to force VAD decision Q0*/ + const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision Q0*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ +#ifdef NONBE_1211_DTX_BR_SWITCHING + const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate Q0*/ +#endif + const Word32 ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX Q0*/ + Word16 *Q_new +#ifdef DEBUG_MODE_INFO + , + const Word16 ch_idx +#endif +); +ivas_error pre_proc_ivas_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 last_element_mode, /* i : last element mode Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word32 last_element_brate, /* i : last element bitrate Q0*/ + const Word16 input_frame, /* i : frame length Q0*/ + Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal Q_new-1 */ + Word16 old_inp_16k_fx[], /* i/o: buffer of old input signal @ 16kHz Q_new-1 */ + Word16 **inp_fx, /* o : ptr. to inp. signal in the current frame Q_new*/ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes Q12*/ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes Q14*/ + Word32 epsP_fx[M + 1], /* i : LP prediction errors epsP_fx_q*/ + Word16 *epsP_fx_q, /* i : LP prediction errors */ + Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame Q15*/ + Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame Q15*/ + Word16 *new_inp_resamp16k_fx, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE Q_new-1*/ + Word16 *Voicing_flag, /* o : voicing flag for HQ FEC Q0*/ + Word16 old_wsp_fx[], /* i : weighted input signal buffer e_old_wsp*/ + Word16 e_old_wsp, + const Word16 loc_harm, /* i : harmonicity flag Q0*/ + const Word16 vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO Q0*/ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ + const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ + Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* e_enerBuffer */ + Word16 e_enerBuffer, + Word16 fft_buff_fx[2 * L_FFT], /* Qx */ + Word16 cor_map_sum_fx, /* Q8 */ + Word16 *Q_new +); +/*! r: number of clipped samples */ +void ivas_initialize_handles_enc_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +ivas_error ivas_init_encoder( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +void ivas_destroy_enc_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +ivas_error ivas_initialize_MD_bstr_enc_fx( + BSTR_ENC_HANDLE *hBstr, /* o : encoder MD bitstream handle */ + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +void ivas_destroy_MD_bstr_enc_fx( + BSTR_ENC_HANDLE *hMetaData /* i/o: encoder MD bitstream handle */ +); + +ivas_error ivas_init_decoder_front( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +ivas_error ivas_init_decoder( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +ivas_error ivas_output_buff_dec( + float *p_output_f[], /* i/o: output audio buffers */ + const int16_t nchan_out_buff_old, /* i : previous frame number of output channels*/ + const int16_t nchan_out_buff /* i : number of output channels */ +); +#endif + +ivas_error stereo_dmx_evs_init_encoder( + STEREO_DMX_EVS_ENC_HANDLE *hStereoDmxEVS, /* o : Stereo downmix for EVS encoder handle */ + const int32_t input_Fs /* i : input sampling rate */ +); + +void stereo_dmx_evs_close_encoder( + STEREO_DMX_EVS_ENC_HANDLE *hStereoDmxEVS /* i/o: Stereo downmix for EVS encoder handle */ +); + +ivas_error ivas_dec( + Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ + int16_t *data /* o : output synthesis signal */ +); + + +ivas_error mct_dec_reconfigure( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const uint16_t b_nchan_change /* i : flag indicating different channel count */ +); + + +void ivas_mct_dec_close( + MCT_DEC_HANDLE *hMCT /* i/o: MCT decoder structure */ +); + +ivas_error ivas_corecoder_dec_reconfig( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t nSCE_old, /* i : number of SCEs in previous frame */ + int16_t nCPE_old, /* i : number of CPEs in previous frame */ + const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ + const int16_t sba_dirac_stereo_flag_old, /* i : signal stereo rendering using DFT upmix in previous frame */ + const int32_t brate_SCE, /* i : bitrate to be set for the SCEs */ + const int32_t brate_CPE /* i : bitrate to be set for the CPEs */ +); + +ivas_error ivas_hp20_dec_reconfig( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t nchan_hp20_old /* i : number of HP20 filters in previous frame*/ +); + +ivas_error ivas_sce_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t sce_id, /* i : SCE # identifier */ + float *output[1], /* 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 */ +); + +ivas_error ivas_cpe_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t cpe_id, /* i : CPE # identifier */ + float *output[CPE_CHANNELS], /* 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 */ +); + +ivas_error ivas_mct_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + 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 */ +); + +/*! r: number of channels to be synthesised */ + +void copy_decoder_config( + Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ + Decoder_State *st /* o : decoder state structure */ +); + +void destroy_core_dec( + DEC_CORE_HANDLE hCoreCoder /* i/o: core decoder structure */ +); + + +void ivas_initialize_handles_dec( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +ivas_error ivas_core_enc_fx( + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + const Word16 n_CoreChannels, /* i : number of core channels to be coded Q0*/ + Word16 old_inp_12k8_fx[][L_INP_12k8], /* i : buffer of old input signal Q_new-1*/ + Word16 old_inp_16k_fx[][L_INP], /* i : buffer of old input signal Q_new-1*/ + Word16 Q_new[], + Word32 ener_fx[], /* i : residual energy from Levinson-Durbin epsP_fx_q*/ + Word16 A_fx[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ + Word16 Aw_fx[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes Q12*/ + Word32 epsP_fx[][M + 1], /* i : LP prediction errors epsP_fx_q*/ + Word16 epsP_fx_q[], /* i : LP prediction errors */ + Word16 lsp_new_fx[][M], /* i : LSPs at the end of the frame Q15*/ + Word16 lsp_mid_fx[][M], /* i : LSPs in the middle of the frame Q15*/ + const Word16 vad_hover_flag[], /* i : VAD hanglover flag Q0*/ + Word16 attack_flag[], /* i : attack flag (GSC or TC) Q0*/ + Word32 realBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer q_re_im_buf*/ + Word32 imagBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer q_re_im_buf*/ + Word16 *q_re_im_buf, + Word16 old_wsp_fx[][L_WSP], /* i : weighted input signal buffer e_old_wsp*/ + Word16 e_old_wsp[], + const Word16 loc_harm[], /* i : harmonicity flag Q0*/ + const Word16 cor_map_sum_fx[], /* i : speech/music clasif. parameter Q8*/ + const Word16 vad_flag_dtx[], /* i : HE-SAD flag with additional DTX HO Q0*/ + Word32 enerBuffer_fx[][CLDFB_NO_CHANNELS_MAX], /* o : energy buffer enerBuffer_fx_exp*/ + Word16 enerBuffer_fx_exp[], /* o : energy buffer */ + Word16 fft_buff_fx[][2 * L_FFT], /* i : FFT buffer Qx*/ + const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag Q0*/ + const Word16 ivas_format, /* i : IVAS format Q0*/ + const Word16 flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ +); + + + +void decod_gen_2sbfr( + Decoder_State *st, /* i/o: decoder static memory */ + const int16_t sharpFlag, /* i : formant sharpening flag */ + const float *Aq, /* i : LP filter coefficient */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *exc, /* i/o: adapt. excitation exc */ + float *exc2, /* i/o: adapt. excitation/total exc */ + float *bwe_exc, /* o : excitation for SWB TBE */ + float *gain_buf, /* o : floating pitch gain for each subframe */ + const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const float tdm_Pri_pitch_buf[] /* i : pitch values for primary channel */ +); + +void synchro_synthesis( + const int32_t 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 int16_t output_frame, /* i : Number of samples */ + const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ +); + +void synchro_synthesis_fixed( + const int32_t 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 int16_t output_frame, /* i : Number of samples */ + const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ +); + +void stereo_tcx_init_enc( + Encoder_State *st /* i/o: encoder state structure */ +); + + + + +void stereo_tcx_init_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const int16_t last_element_mode /* i : element mode of previous frame */ +); + +/*! r: S/M decision (0 = speech or noise, 1 = unclear, 2 = music) */ +int16_t ivas_smc_gmm( + Encoder_State *st, /* i/o: encoder state structure */ + STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ + const int16_t localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + const float Etot, /* i : total frame energy */ + const float lsp_new[M], /* i : LSPs in current frame */ + const float cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.) */ + const float epsP[M + 1], /* i : LP prediciton error */ + const float PS[], /* i : energy spectrum */ + const float non_sta, /* i : unbound non-stationarity */ + const float relE, /* i : relative frame energy */ + int16_t *high_lpn_flag, /* i/o: sp/mus LPN flag */ + const int16_t flag_spitch /* i : flag to indicate very short stable pitch */ +); + +void ivas_smc_mode_selection( + Encoder_State *st, /* i/o: encoder state structure */ + const int32_t element_brate, /* i : element bitrate */ + int16_t smc_dec, /* i : raw decision of the 1st stage classifier */ + const float relE, /* i : relative frame energy */ + const float Etot, /* i : total frame energy */ + int16_t *attack_flag, /* i/o: attack flag (GSC or TC) */ + const float *inp, /* i : input signal */ + const float S_map[], /* i : short-term correlation map */ + const int16_t flag_spitch /* i : flag to indicate very short stable pitch */ +); + +/*! r: S/M decision (0=speech or noise,1=unclear,2=music) */ +int16_t ivas_acelp_tcx20_switching( + Encoder_State *st, /* i/o: encoder state structure */ + const float *inp, /* i : new input signal */ + const float *wsp, /* i : input weighted signal */ + const float non_staX, /* i : unbound non-stationarity for sp/mu clas */ + const float *pitch_fr, /* i : fraction pitch values */ + const float *voicing_fr, /* i : fractional voicing values */ + const float currFlatness, /* i : flatness */ + const float lsp_mid[M], /* i : LSPs at the middle of the frame */ + const float stab_fac, /* i : LP filter stability */ + float *res_cod_SNR_M, + const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ +); + + + +void ivas_decision_matrix_dec( + Decoder_State *st, /* i/o: decoder state structure */ + int16_t *sharpFlag, /* o : formant sharpening flag */ + int16_t *core_switching_flag, /* o : ACELP->HQ switching frame flag */ + const int32_t element_brate, /* i : element bitrate */ + const int16_t nchan_out /* i : Number of output channels */ +); + +void set_bw_stereo( + CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structures */ +); + +/*! r: flag indicating whether the coded BW has changed */ +int16_t set_bw_mct( + CPE_ENC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE encoder structures */ + const int16_t nCPE /* i : number of CPEs */ +); +void dec_acelp_fast( + Decoder_State *st, /* i/o: decoder state structure */ + const int16_t cdk_index, /* i : codebook index */ + float code[], /* o : algebraic (fixed) codebook excitation */ + const int16_t L_subfr /* i : subframe length */ +); + +void set_transient_stereo( + CPE_ENC_HANDLE hCPE, /* i : CPE structure */ + float currFlatness[] /* i/o: current flatness */ +); + +/*! r: preliminary flag to force ACELP */ +int16_t transient_analysis( + TRAN_DET_HANDLE hTranDet, /* i : handle transient detection */ + const float cor_map_LT[], /* i : LT correlation map */ + const float multi_harm_limit /* i : multi harminic threshold */ +); + +void ivas_post_proc( + SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const int16_t n, /* i : channel number */ + float synth[], /* i/o: output synthesis signal */ + float *output[CPE_CHANNELS], /* i/o: output synthesis signal */ + const int16_t output_frame, /* i : output frame length */ + const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ +); + +void ivas_renderer_select( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +ivas_error ivas_mc_enc_config_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +ivas_error ivas_mc_dec_config( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t idx, /* i : LS config. index */ + uint16_t *nSamplesRendered, /* o : samples flushed from last frame (JBM) */ + int16_t *data /* o : output synthesis signal */ +); + +/*! r: MC format mode (MCT, McMASA, ParamMC) */ +MC_MODE ivas_mc_mode_select( + const MC_LS_SETUP mc_ls_setup, /* i : MC loudspeaker setup */ + const int32_t total_brate /* i : IVAS total bitrate */ +); + +/*! r: number of loudspeaker channels */ +int16_t ivas_mc_ls_setup_get_num_channels( + const MC_LS_SETUP mc_ls_setup /* i : loudspeaker setup (CICP) */ +); + +/*! r: output configuration*/ +AUDIO_CONFIG ivas_mc_map_ls_setup_to_output_config( + const MC_LS_SETUP mc_ls_setup /* i : multi channel loudspeaker setup */ +); + +/*! r: multi channel loudspeaker setup */ +MC_LS_SETUP ivas_mc_map_output_config_to_mc_ls_setup( + const AUDIO_CONFIG output_config /* i : output audio configuration */ +); + +void smooth_dft2td_transition( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + float *output[CPE_CHANNELS], /* i/o: synthesis @external Fs */ + const int16_t output_frame /* i : output frame length */ +); + + +/*! r: flag indicating a valid bitrate */ +Word16 is_IVAS_bitrate_fx( + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +); + +int16_t is_DTXrate( + const int32_t ivas_total_brate /* i : IVAS total bitrate */ +); + + +void TonalMdctConceal_create_concealment_noise_ivas( + float concealment_noise[L_FRAME48k], + CPE_DEC_HANDLE hCPE, + const int16_t L_frameTCX, + const int16_t L_frame, + const int16_t idchan, + const int16_t subframe_idx, + const int16_t core, + const float crossfade_gain, + const TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode +); + +void TonalMdctConceal_whiten_noise_shape_ivas( + Decoder_State *st, + const int16_t L_frame, + const TONALMDCTCONC_NOISE_SHAPE_WHITENING_MODE +); + +void dtx_read_padding_bits( + DEC_CORE_HANDLE st, + const int16_t num_bits +); + + + +/*----------------------------------------------------------------------------------* + * JBM prototypes + *----------------------------------------------------------------------------------*/ + + + +ivas_error ivas_jbm_dec_flush_renderer( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t 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 */ + uint16_t *nSamplesRendered, /* o : number of samples flushed */ + int16_t *data /* o : output synthesis signal */ +); + +void ivas_jbm_dec_feed_tc_to_renderer( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t nSamplesForRendering, /* i : number of TC samples available for rendering */ + int16_t *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ + float *data /* i/o: transport channels/output synthesis signal */ +); + +ivas_error ivas_jbm_dec_set_discard_samples( + Decoder_Struct *st_ivas /* i/o: main IVAS decoder structre */ +); + +void ivas_jbm_dec_get_adapted_linear_interpolator( + const int16_t default_interp_length, /* i : default length of the (full-frame) interpolator */ + const int16_t interp_length, /* i : length of the interpolator to be created */ + float *interpolator /* o : the interpolator */ +); + + + +int16_t ivas_jbm_dec_get_num_tc_channels( + Decoder_Struct *st_ivas /* i : IVAS decoder handle */ +); + +void ivas_jbm_dec_copy_tc_no_tsm( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + float *tc[], /* i : transport channels */ + const int16_t output_frame /* i : output frame size */ +); + + +TC_BUFFER_MODE ivas_jbm_dec_get_tc_buffer_mode( + Decoder_Struct *st_ivas /* i : IVAS decoder handle */ +); + +/*! r: render granularity */ +int16_t ivas_jbm_dec_get_render_granularity_flt( + const RENDERER_TYPE rendererType, /* i : renderer type */ + const IVAS_FORMAT ivas_format, /* i : ivas format */ + const MC_MODE mc_mode, /* i : MC mode */ + const int32_t output_Fs /* i : sampling rate */ +); + +ivas_error ivas_jbm_dec_tc_buffer_open( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const TC_BUFFER_MODE tc_buffer_mode, /* i : buffer mode */ + const int16_t nchan_transport_jbm, /* i : number of real transport channels */ + const int16_t nchan_transport_internal, /* i : number of totally buffered channels */ + const int16_t nchan_full, /* i : number of channels to fully store */ + const int16_t n_samples_granularity /* i : granularity of the renderer/buffer */ +); + +ivas_error ivas_jbm_dec_tc_buffer_reconfigure( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const TC_BUFFER_MODE tc_buffer_mode, /* i : new buffer mode */ + const int16_t nchan_transport_jbm, /* i : new number of real transport channels */ + const int16_t nchan_transport_internal, /* i : new number of totally buffered channels */ + const int16_t nchan_full, /* i : new number of channels to fully store */ + const int16_t n_samples_granularity /* i : new granularity of the renderer/buffer */ +); + +void ivas_jbm_dec_tc_buffer_close( + DECODER_TC_BUFFER_HANDLE *phTcBuffer /* i/o: TC buffer handle */ +); + +void ivas_jbm_dec_td_renderers_adapt_subframes( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +ivas_error ivas_jbm_dec_metadata_open( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +void ivas_jbm_masa_sf_to_sf_map( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + + +/*----------------------------------------------------------------------------------* + * ISM prototypes + *----------------------------------------------------------------------------------*/ + +void bitbudget_to_brate( + const Word16 x[], /* i : bitbudgets Q0 */ + Word32 y[], /* o : bitrates Q0 */ + const Word16 N /* i : number of entries to be converted */ +); + +void ivas_ism_reset_metadata( + ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handles */ +); + +void ivas_ism_reset_metadata_enc( + ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle */ +); +void ivas_ism_reset_metadata_API( + ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handles */ +); + +/*! r: index of the winning codeword */ +Word16 ism_quant_meta_fx( + const Word32 val, /* i : scalar value to quantize Q22 */ + Word32 *valQ, /* o : quantized value Q22 */ + const Word32 borders_fx[], /* i : level borders Q22 */ + const Word32 q_step_fx, /* i : quantization step Q22 */ + const Word32 q_step_border_fx, /* i : quantization step at the border Q22 */ + const Word16 cbsize /* i : codebook size */ +); + +ivas_error ivas_ism_metadata_enc_create_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const int16_t n_ISms, /* i : number of objects */ + int32_t element_brate_tmp[] /* o : element bitrate per object */ +); + +ivas_error ivas_ism_metadata_dec_create( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t n_ISms, /* i : number of objects */ + int32_t element_brate_tmp[] /* o : element bitrate per object */ +); + +ivas_error ivas_ism_enc( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + float *data[], /* i : input signal [channels][samples] */ + const int16_t input_frame, /* i : input frame length per channel */ + int16_t *nb_bits_metadata, /* i : number of metadata bits */ + const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ +); + +ivas_error ivas_ism_metadata_dec( + const int32_t ism_total_brate, /* i : ISM total bitrate */ + const int16_t nchan_ism, /* i : number of ISM channels */ + int16_t *nchan_transport, /* o : number of transport channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_DEC_HANDLE hSCE[], /* i/o: SCE decoder handles */ + const int16_t bfi, /* i : bfi flag */ + int16_t nb_bits_metadata[], /* o : number of metadata bits */ + ISM_MODE ism_mode, /* i : ISM mode */ + ISM_DTX_DATA_DEC hISMDTX, /* i/o: ISM DTX structure */ + const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Config Handle */ + int16_t *ism_extended_metadata_flag, /* i/o: Extended metadata active in renderer */ + int16_t *ism_extmeta_cnt, /* i/o: Number of change frames observed */ + DEC_CORE_HANDLE st0 /* i : core-coder handle */ +); + + +/*----------------------------------------------------------------------------------* + * Parametric ISM prototypes + *----------------------------------------------------------------------------------*/ + +/*! r: ISM format mode */ + +ivas_error ivas_param_ism_enc_open_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +void ivas_param_ism_enc_close_fx( + PARAM_ISM_CONFIG_HANDLE *hParamIsm, /* i/o: ParamISM handle */ + const int32_t input_Fs /* i : input sampling_rate */ +); + +void ivas_ism_metadata_close( + ISM_METADATA_HANDLE hIsmMetaData[], /* i/o : object metadata handles */ + const int16_t first_idx /* i : index of first handle to deallocate */ +); + + +ivas_error ivas_ism_enc_config( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + + + + +void ivas_param_ism_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output_f[] /* i/o: synthesized core-coder transport channels/DirAC output */ +); + +void ivas_ism_dec_digest_tc( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + + + +void ivas_param_ism_dec_render( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ + uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */ + uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + float *output_f[] /* o : rendered time signal */ +); + +void ivas_param_ism_params_to_masa_param_mapping( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + + +/*----------------------------------------------------------------------------------* + * ISM DTX prototypes + *----------------------------------------------------------------------------------*/ + +ivas_error ivas_ism_dtx_open( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +/*! r: indication of DTX frame */ +int16_t ivas_ism_dtx_enc( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t nchan_ism, /* i : number of objects */ + const int16_t nchan_transport, /* i : number of transport channels */ + int16_t vad_flag[MAX_NUM_OBJECTS], /* i : VAD flag */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + int16_t md_diff_flag[], /* o : metadata differential flag */ + int16_t *sid_flag /* o : indication of SID frame */ +); + +void ivas_ism_dtx_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + int16_t *nb_bits_metadata /* o : number of metadata bits */ +); + +void ivas_ism_metadata_sid_enc_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + const int16_t flag_noisy_speech, /* i : noisy speech flag */ + const int16_t nchan_ism, /* i : number of objects */ + const int16_t nchan_transport, /* i : number of transport channels */ + const ISM_MODE ism_mode, /* i : ISM mode */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + const int16_t sid_flag, /* i : indication of SID frame */ + const int16_t md_diff_flag[], /* i : metadata differental flag */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + int16_t nb_bits_metadata[] /* o : number of metadata bits */ +); + +void ivas_ism_metadata_sid_dec( + SCE_DEC_HANDLE hSCE[MAX_SCE], /* i/o: SCE decoder structure */ + const int32_t ism_total_brate, /* i : ISM total bitrate */ + const int16_t bfi, /* i : bfi flag */ + const int16_t nchan_ism, /* i : number of objects */ + const int16_t nchan_transport, /* i : number of transport channels */ + const ISM_MODE ism_mode, /* i : ISM mode */ + int16_t *flag_noisy_speech, /* o : noisy speech flag */ + int16_t *sce_id_dtx, /* o : SCE DTX ID */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + int16_t nb_bits_metadata[] /* o : number of metadata bits */ +); + + +void ivas_param_ism_compute_noisy_speech_flag_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + + +void update_last_metadata( + const int16_t nchan_ism, /* i : number of objects */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + const int16_t updt_flag[] /* i : last metadata update flag */ +); + +void ivas_ism_dtx_limit_noise_energy_for_near_silence( + SCE_DEC_HANDLE hSCE[], /* i/o: SCE decoder structures */ + const int16_t sce_id_dtx, /* i : SCE DTX ID */ + const int16_t nchan_transport /* i : number of transport channels */ +); + +/*----------------------------------------------------------------------------------* + * DFT Stereo prototypes + *----------------------------------------------------------------------------------*/ + + +void stereo_dft_enc_analyze( + Encoder_State **sts, /* i/o: encoder state structure */ + const int16_t n_channels, /* i : number of input channels */ + const int16_t input_frame, /* i : input frame length */ + STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder DFT stereo handle */ + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: encoder MDCT stereo handle */ + float DFT[CPE_CHANNELS][STEREO_DFT_N_MAX_ENC], /* o : DFT buffers */ + float *input_mem[CPE_CHANNELS] /* i/o: input buffer memory */ +); + +float stereo_dft_enc_synthesize( + STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder DFT stereo handle */ + float *output, /* o : output synthesis */ + const int16_t chan, /* i : channel number */ + const int32_t input_Fs, /* i : input sampling rate */ + const int32_t output_sampling_rate, /* i : output sampling rate */ + const int16_t L_frame /* i : frame length at internal Fs */ +); + + + + +void stereo_dtf_cng( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + float DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ + const int16_t output_frame /* i : output frame size */ +); + +void stereo_dft_cng_side_gain( + STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: DFT stereo encoder handle */ + STEREO_CNG_ENC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ + const int32_t core_brate, /* i : core bitrate */ + const int32_t last_core_brate, /* i : last core bitrate */ + const int16_t bwidth /* i : audio band-width */ +); + + +void stereo_dft_dequantize_itd( + int16_t *ind, + float *out, + const int32_t output_Fs +); + + + +void stereo_dft_dec_sid_coh( + Decoder_State *st, /* i/o: decoder state structure */ + const int16_t nbands, /* i : number of DFT stereo bands */ + float *coh, /* i/o: coherence */ + int16_t *nb_bits /* i/o: number of bits read */ +); + +ivas_error stereo_dft_dec_create( + STEREO_DFT_DEC_DATA_HANDLE *hStereoDft, /* i/o: decoder DFT stereo handle */ + const int32_t element_brate, /* i : element bitrate */ + const int32_t output_Fs, /* i : output sampling rate */ + const int16_t sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ + const int16_t nchan_transport /* i : number of transport channels */ +); + +void stereo_dft_dec_reset( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: decoder DFT stereo handle */ +); + +void stereo_dft_dec_update( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const int16_t output_frame, /* i : output frame length */ + const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ +); + +void stereo_dft_dec_destroy( + STEREO_DFT_DEC_DATA_HANDLE *hStereoDft /* i/o: decoder DFT stereo handle */ +); + +void stereo_dft_dec_analyze( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const float *input, /* i : input signal */ + float out_DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ + const int16_t chan, /* i : channel number */ + const int16_t input_frame, /* i : input frame size */ + const int16_t output_frame, /* i : output frame size */ + const DFT_STEREO_DEC_ANA_TYPE ana_type, /* i : signal type to analyze */ + const int16_t k_offset, /* i : offset of DFT */ + const int16_t delay /* i : delay in samples for input signal */ +); + +void stereo_dft_dec_synthesize( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + float DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i : DFT buffers */ + const int16_t chan, /* i : channel number */ + float output[L_FRAME48k], /* o : output synthesis signal */ + const int16_t output_frame /* i : output frame length */ +); + + +void stereo_dft_res_ecu( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ + float *pDFT_RES, /* i/o: residual signal */ + float *const DFT_PRED_RES, /* i/o: residual prediction signal */ + const int16_t k, /* i : Subframe index */ + const int16_t output_frame, /* i : Output frame length */ + const int16_t prev_bfi, /* i : Previous BFI */ + const float dmx_nrg, /* i : Down-mix energy */ + int16_t *num_plocs, /* i/o: Number of peak locations */ + int16_t *plocs, /* i/o: Peak locations (bin) */ + float *plocsi, /* i/o: Peak locations (fractional) */ + float *input_mem /* o : Residual DFT buffer input mem */ +); + +void stereo_dft_res_subst_spec( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ + float *pDFT_RES, /* i/o: residual signal */ + const float *const DFT_PRED_RES, /* i : residual prediction signal */ + const int16_t time_offs, /* i : Time offset for phase adjustm. */ + const int16_t L_res, /* i : bandwidth of residual signal */ + const int16_t L_ana, /* i : Length of FFT analysis */ + const int16_t k, /* i : Subframe index */ + int16_t *num_plocs, /* i/o: Number of peak locations */ + int16_t *plocs, /* i/o: Peak locations (bin) */ + float *plocsi, /* i/o: Peak locations (fractional) */ + const int16_t analysis_flag /* i : Flag for running peak analysis */ +); + +void stereo_dft_res_ecu_burst_att( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ + float *pDFT_RES, /* i/o: residual signal /att. residual */ + const float dmx_nrg, /* i : dmx energy of current frame */ + const int16_t L_res, /* i : Bandwidth of residual */ + const int16_t L_ana /* i : Length of FFT analysis */ +); + +/*! r: total energy of downmix with maximum swb bandwidth max */ +float stereo_dft_dmx_swb_nrg( + const float *dmx_k0, /* i : first subframe spectrum */ + const float *dmx_k1, /* i : second subframe spectrum */ + const int16_t frame_length /* i : frame lanegth */ +); + +int16_t stereo_dft_sg_recovery( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: Decoder DFT stereo handle */ +); + +void stereo_dft_dec_res( + CPE_DEC_HANDLE hCPE, /* i/o: decoder CPE handle */ + float res_buf[STEREO_DFT_N_8k], /* i : residual buffer */ + float *output /* o : output frame */ +); + +/*! r: Decision to enable or disable BPF on DFT stereo residual */ + +void bpf_pitch_coherence( + Decoder_State *st, /* i/o: decoder state structure */ + const float pitch_buf[] /* i : pitch for each subframe [0,1,2,3] */ +); + +void stereo_dft_dec_read_BS( + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int32_t element_brate, /* i : element bitrate */ + int32_t *total_brate, /* o : total bitrate */ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const int16_t bwidth, /* i : bandwidth */ + const int16_t output_frame, /* i : output frame length */ + float res_buf[STEREO_DFT_N_8k], /* o : residual buffer */ + int16_t *nb_bits, /* o : number of bits read */ + float *coh, /* i/o: Coherence */ + const int16_t ivas_format /* i : ivas format */ +); + +void stereo_dft_dec_smooth_parameters( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const int16_t prev_sid_nodata, /* i : Previous SID/No data indicator */ + const int16_t active_frame_counter, /* i : Active frame counter */ + const int32_t element_brate /* i : Element bitrate */ +); + +void stereo_dft_generate_res_pred( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const float samp_ratio, /* i : sampling ratio */ + float *pDFT_DMX, /* i : downmix signal */ + float *DFT_PRED_RES, /* o : residual prediction signal */ + float *pPredGain, /* i : residual prediction gains */ + const int16_t k, /* i : subframe index */ + float *ap_filt_DMX, /* i : enhanced stereo filling signal */ + int16_t *stop, /* o : last FD stereo filling bin */ + const int16_t bfi /* i : BFI flag */ +); + +void stereo_dft_dec_core_switching( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + float output[], /* i/o: synthesis @internal Fs */ + float synth[], /* i : synthesis @output Fs */ + float hb_synth[], /* i/o: hb synthesis */ + float DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ + const int16_t output_frame, /* i : output frame length */ + const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const int16_t sba_dirac_stereo_dtx_flag /* i : DTX indicator for SBA DirAC stereo */ +); + +void init_basic_allpass( + basic_allpass_t *ap, /* i/o: basic allpass structure */ + const float *gains, /* i : allpass filter gains */ + const int16_t *delays /* i : allpass filter delays */ +); + +void filter_with_allpass( + const float *sig, /* i : allpass input signal */ + float *out, /* o : filtered output */ + const int16_t len, /* i : length of input */ + basic_allpass_t *ap /* i/o: basic allpass structure */ +); + +/*! r: used GR order */ + +/*! r: used GR order */ + + +/*! r: number of bits written */ + +/*! r: number of bits written */ + + +void stereo_dft_enc_compute_itd( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + float *DFT_L, + float *DFT_R, + const int16_t k_offset, + const int16_t input_frame, + const int16_t vad_flag_dtx[], + const int16_t vad_hover_flag[], + float *bin_nrgL, + float *bin_nrgR +); + +void stereo_dft_config( + STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */ + const int32_t brate, /* i : IVAS/CPE/nominal total bitrate */ + int16_t *bits_frame_nominal, /* o : primary channel nominal bits per frame */ + int16_t *bits_frame_nominal_2 /* o : secondary channel nominal bits per frame*/ +); + +int16_t stereo_dft_band_config( + int16_t *band_limits, /* o : DFT band limits */ + const int16_t band_res, /* i : DFT band resolution */ + const int16_t NFFT, /* i : analysis/synthesis window length */ + const int16_t enc_dec /* i : flag to indicate enc vs dec */ +); + +void stereo_dft_dmx_out_reset( + STEREO_DFT_DMX_DATA_HANDLE hStereoDftDmx /* i/o: DFT stereo DMX decoder */ +); + +void stereo_dft_unify_dmx( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ + Decoder_State *st0, /* i/o: decoder state structure */ + float DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ + float *input_mem, /* i/o: mem of buffer DFT analysis */ + const int16_t prev_sid_nodata /* i : Previous SID/No data indicator */ +); + +void add_HB_to_mono_dmx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + float output[L_FRAME48k], /* i/o: output synthesis */ + float outputHB[L_FRAME48k], /* i : HB synthesis */ + const int16_t last_core, /* i : last core, primary channel */ + const int16_t output_frame /* i : frame length */ +); + +/*----------------------------------------------------------------------------------* + * Range Coder prototypes + *----------------------------------------------------------------------------------*/ + +void rc_uni_dec_init( + RangeUniDecState *rc_st_dec, /* i/o: RC state handle */ + uint16_t *bit_buffer, /* i : Bit buffer */ + const int16_t max_available_bits /* i : Total maximum bits available */ +); + +/*! r: Read symbol */ +uint16_t rc_uni_dec_read_symbol_fastS( + RangeUniDecState *rc_st_dec, /* i/o: Decoder State */ + const uint16_t cum_freq_table[], /* i : Cumulative frequency up to symbol */ + const uint16_t sym_freq_table[], /* i : Symbol frequency */ + const uint16_t alphabet_size, /* i : Number of symbols in the alphabet */ + const uint16_t tot_shift /* i : Total frequency as a power of 2 */ +); + +/*! r: Read bit */ +uint16_t rc_uni_dec_read_bit( + RangeUniDecState *rc_st_dec /* i/o: RC state handle */ +); + +/*! r: Read bit */ +uint16_t rc_uni_dec_read_bit_prob_fast( + RangeUniDecState *rc_st_dec, /* i/o: RC state handle */ + const int16_t freq0, /* i : Frequency for symbol 0 */ + const uint16_t tot_shift /* i : Total frequency as a power of 2 */ +); + +/*! r: Read bits */ +uint16_t rc_uni_dec_read_bits( + RangeUniDecState *rc_st_dec, /* i/o: RC state handle */ + const int16_t bits /* i : Number of bits */ +); + +/*! r: Total number of bits consumed */ +int16_t rc_uni_dec_virtual_finish( + RangeUniDecState *rc_st_dec /* i/o: RC state handle */ +); + +/*! r: Total number of bits consumed */ +int16_t rc_uni_dec_finish( + RangeUniDecState *rc_st_dec /* i/o: RC state handle */ +); + + +/*----------------------------------------------------------------------------------* + * ECLVQ Stereo prototypes + *----------------------------------------------------------------------------------*/ + +float ECSQ_dequantize_gain( + const int16_t index +); + + + +void ECSQ_init_instance( + ECSQ_instance *ecsq_inst, + const int16_t config_index, + void *ac_handle +); + + + +void ECSQ_dequantize_vector( + const int16_t *input, + const float global_gain, + const int16_t N, + float *output +); + + +/*----------------------------------------------------------------------------------* + * ICA Stereo prototypes + *----------------------------------------------------------------------------------*/ + +void stereo_tca_init_enc( + STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: Stereo TCA encoder handle */ + const int32_t input_Fs /* i : input sampling frequency */ +); + +void stereo_tca_enc( + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + const int16_t input_frame /* i : length of a frame per channel */ +); + +void stereo_tca_init_dec( + STEREO_TCA_DEC_HANDLE hStereoTCA /* i/o: Stereo TCA handle */ +); + +void stereo_tca_dec( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + float *synth[CPE_CHANNELS], /* i/o: output synth */ + const int16_t output_frame /* i : length of a frame per channel */ +); + +void stereo_tca_scale_R_channel( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + float *output, /* i/o: output synthesis, R channel */ + const int16_t output_frame /* i : frame length */ +); + +void adjustTargetSignal( + float *target, + const int16_t prevShift, + const int16_t currShift, + const int16_t L_shift_adapt, + const int16_t method +); + +/*----------------------------------------------------------------------------------* + * IC-BWE Stereo prototypes + *----------------------------------------------------------------------------------*/ + + +void stereo_icBWE_preproc( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const int16_t input_frame, /* i : input frame length */ + float shb_speech_nonref[] /* o : SHB speech non-ref channel */ +); + +void stereo_icBWE_enc( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const float shb_speech_ref[], /* i : SHB speech ref channel */ + float shb_speech_nonref[], /* i/o: SHB speech non-ref channel */ + const float *voice_factors /* i : voicing factors */ +); + +void stereo_icBWE_init_dec( + STEREO_ICBWE_DEC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */ +); + +void stereo_icBWE_dec( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + float *synthRef, /* i/o: Reference channel HB synthesis at output Fs */ + float *synth, /* o : Non reference channel HB synthesis at output Fs */ + const float *fb_synth_ref, /* i : ref. high-band synthesis 16-20 kHz */ + const float *voice_factors, /* i : voicing factors */ + const int16_t output_frame /* i : frame length */ +); + +void stereo_icBWE_decproc( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + float *output[CPE_CHANNELS], /* i/o: output symthesis */ + float outputHB[CPE_CHANNELS][L_FRAME48k], /* i : HB synthesis */ + const int16_t last_core, /* i : last core, primary channel */ + const int16_t last_bwidth, /* i : last bandwidth */ + const int16_t output_frame /* i : frame length */ +); + + +/*----------------------------------------------------------------------------------* + * Stereo classifiers prototypes + *----------------------------------------------------------------------------------*/ + +void stereo_classifier_features( + STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ + const int16_t idchan, /* i : channel ID */ + const int16_t element_mode, /* i : element mode */ + const int16_t vad_flag, /* i : VAD flag */ + const float lsf_new[], /* i : LSFs at the end of the frame */ + const float epsP[], /* i : LP analysis residual energies for each iteration*/ + const int16_t pitch[], /* i : open-loop pitch values for quantiz. */ + const float voicing[], /* i : OL maximum normalized correlation */ + const float cor_map_sum, /* i : speech/music clasif. parameter */ + const float non_staX, /* i : unbound non-stationarity for sp/mu clas. */ + const float sp_div, /* i : spectral diversity feature */ + const int16_t clas /* i : signal class */ +); + + +void xtalk_classifier_dft( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const int16_t itd, /* i : ITD from DFT stereo - used as a feature */ + const float gcc_phat[] /* i : GPHAT cross-channel correlation function */ +); + +/*----------------------------------------------------------------------------------* + * TD Stereo prototypes + *----------------------------------------------------------------------------------*/ + +void stereo_td_init_enc( + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ + const int16_t last_element_mode /* i : last element mode */ +); + + + +void stereo_tdm_downmix( + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i : TD stereo IVAS encoder structure */ + float *Left_in, /* i/o: Left channel -> Primary channel */ + float *Right_in, /* i/o: Right channel -> Secondary channel */ + const int16_t input_frame, /* i : Number of samples */ + const int16_t tdm_ratio_idx, /* i : TDM ratio index */ + const int16_t tdm_SM_flag, /* i : channel combination scheme flag */ + const int16_t tdm_ratio_idx_SM /* i : TDM ratio index for SM mode */ +); + +void stereo_td_init_dec( + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ + const int16_t last_element_mode /* i : last element mode */ +); + +void tdm_configure_dec( + const int16_t ivas_format, /* i : IVAS format */ + const int16_t ism_mode, /* i : ISM mode in combined format */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + int16_t *tdm_ratio_idx, /* o : ratio index */ + const int16_t nb_bits_metadata /* i : number of metadata bits */ +); + +void tdm_upmix_plain( + float Left[], /* o : left channel */ + float Right[], /* o : right channel */ + const float PCh_2_L[], /* i : primary channel */ + const float SCh_2_R[], /* i : secondary channel */ + const float LR_ratio, /* i : mixing ratio */ + const float inv_den_LR_ratio, /* i : inverse mixing ration */ + const int16_t start_index, /* i : start index */ + const int16_t end_index, /* i : end index */ + const int16_t plus_minus_flag /* i : plus/minus flag */ +); + +void stereo_tdm_combine( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + float *PCh_2_L, /* i/o: Primary channel -> output as L channel */ + float *SCh_2_R, /* i/o: Seconday channel -> output as R channel */ + const int16_t output_frame, /* i : Number of samples */ + const int16_t flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis */ + const int16_t tdm_ratio_idx /* i : TDM ratio index */ +); + +/*! r: replication decision; 1 = Use old LP */ +void tdm_ol_pitch_comparison( + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + float pitch_fr[CPE_CHANNELS][NB_SUBFR], /* i/o: fractional pitch values */ + float voicing_fr[CPE_CHANNELS][NB_SUBFR] /* i/o: fractional pitch gains */ +); + +void tdm_configure_enc( + const int16_t ivas_format, /* i : IVAS format */ + const int16_t ism_mode, /* i : ISM mode in combined format */ + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + const float Etot_last[CPE_CHANNELS], /* i/o: Energy of last frame */ + const int16_t tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */ + const int16_t tdm_ratio_idx, /* i : ratio index */ + const int16_t tdm_ratio_idx_SM, /* i : ratio index in SM mode */ + const int16_t attack_flag, /* i : Primary channel attack flag */ + const int16_t nb_bits_metadata /* i : number of metadata bits */ +); + + +void tdm_bit_alloc( + const int16_t ivas_format, /* i : IVAS format */ + const int16_t ism_mode, /* i : ISM mode in combined format */ + const int32_t element_brate_wo_meta, /* i : element bitrate without metadata */ + const int16_t tdm_lp_reuse_flag, /* i : LPC reusage flag */ + int32_t *total_brate_pri, /* o : Allocated primary channel bitrate */ + int32_t *total_brate_sec, /* o : Allocated secondary channel bitrate */ + int16_t *tdm_low_rate_mode, /* o : secondary channel low rate mode flag */ + const int16_t coder_type, /* i : secondary channel coder type */ + const int16_t ener_ratio_idx, /* i : correlation ratio indexe */ + const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const int16_t bwidth_pri, /* i : bandwidth of the primary channel */ + const int16_t bwidth_sec, /* i : bandwidth of the secondary channel */ + const int16_t flag_ACELP16k_pri, /* i : ACELP@16kHz core flag, primary chan. */ + const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */ + const int16_t coder_type0, /* i : coder type (temporary in the encoder, from bitstream in decoder) */ + const int16_t tdm_inst_ratio_idx /* i : instantaneous correlation ratio index */ +); + + +/*! r: value of the indice */ +uint16_t get_indice_st( + Decoder_State *st, /* i/o: decoder state structure */ + const int32_t element_brate, /* i : element bitrate */ + const int16_t pos, /* i : absolute position in the bitstream */ + const int16_t nb_bits /* i : number of bits to quantize the indice */ +); + +void tdm_low_rate_dec( + Decoder_State *st, /* i/o: decoder static memory */ + float dct_epit[], /* o : GSC excitation in DCT domain */ + float *tmp_noise, /* o : long term temporary noise energy */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *exc, /* i/o: adapt. excitation exc */ + float *exc2, /* i/o: adapt. excitation/total exc */ + float *bwe_exc, /* o : excitation for SWB TBE */ + const float *lsf_new /* i : ISFs at the end of the frame */ +); + +void tdm_SCh_LSF_intra_pred( + const int32_t element_brate, /* i : element bitrate */ + const float *tdm_lsfQ_PCh, /* i : primary channel LSFs */ + float *pred_lsf_SCh /* o : predicted secondary channel LSFs */ +); + + +void first_VQstages( + const float *const *cb, + const float u[], /* i : vector to be encoded (prediction and mean removed) */ + const int16_t *levels, /* i : number of levels in each stage */ + const int16_t stagesVQ, /* i : number of stages */ + const float w[], /* i : weights */ + const int16_t N, /* i : vector dimension */ + const int16_t max_inner, /* i : maximum number of swaps in inner loop */ + int16_t indices_VQstage[] +); + + +void deindex_lvq_SHB( + UWord32 index, + float *out, + const int16_t nbits, + const int16_t mode +); + +/*----------------------------------------------------------------------------------* + * MDCT Stereo prototypes + *----------------------------------------------------------------------------------*/ + +void stereo_td_itd_mdct_stereo( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder handle */ + const int16_t vad_flag_dtx[], /* i : VAD dtx flags */ + const int16_t vad_hover_flag[], /* i : VAD hangover flags */ + const int16_t input_frame /* i : frame length */ +); + +void QuantizeTCXSpectrum( + Encoder_State *st, /* i : state handle */ + const int16_t frame_cnt, /* i : frame counter in the super_frame */ + const float *x_orig, /* i : shaped MDCT spectrum */ + const float *gainlpc, /* i : FDNS gains */ + const Word16 *Aqind, /* i : frame-independent quantized coefficients (M+1) */ + const int16_t tnsSize, /* i : number of tns parameters put into prm */ + const int16_t nb_bits, /* i : bit budget */ + const int16_t vad_hover_flag, /* i : VAD hangover flag */ + int16_t *pL_frameTCX, /* o : full frame length */ + int16_t *pL_frame, /* o : frame length */ + int16_t *pL_spec, /* o : length of the coded spectrum */ + int16_t *ptcx_offset, /* o : folding point offset relative to the end of the previous frame */ + int16_t *pnoiseFillingBorder, /* o : noise filling border */ + float spectrum[], /* o : quantized MDCT spectrum */ + CONTEXT_HM_CONFIG *hm_cfg, /* o : Context-based harmonic model configuration */ + int16_t *hm_active, /* o : flag indicating if the harmonic model is active */ + float lf_deemph_fact[], /* o : low frequency deemphasis factors */ + int16_t *nf_seed, /* o : noise filling random seed */ + float *ener, /* o : energy of the quantized spectrum */ + float *gain_tcx, /* o : global gain */ + int16_t prm[] /* o : tcx parameters */ +); + +void EstimateStereoTCXNoiseLevel( + Encoder_State **sts, /* i : state handle */ + float *q_spectrum[CPE_CHANNELS][NB_DIV], /* i : quantized MDCT spectrum */ + float gain_tcx[][NB_DIV], /* i : global gain */ + int16_t L_frame[][NB_DIV], /* i : frame length */ + int16_t noiseFillingBorder[][NB_DIV], /* i : noise filling border */ + int16_t hm_active[][NB_DIV], /* i : flag indicating if the harmonic model is active */ + const int16_t ignore_chan[], /* i : flag indicating whether the channel should be ignored */ + float fac_ns[][NB_DIV], /* o : noise filling level */ + int16_t param_core[][NB_DIV * NPRM_DIV], /* o : quantized noise filling level */ + const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */ +); + +void TNSAnalysisStereo( + Encoder_State **sts, /* i : state handle */ + float *mdst_spectrum[CPE_CHANNELS][NB_DIV], /* o : MDST spectrum */ + const int16_t bWhitenedDomain, /* i : whitened domain flag */ + int16_t tnsSize[CPE_CHANNELS][NB_DIV], /* i : number of tns parameters put into prm */ + int16_t tnsBits[CPE_CHANNELS][NB_DIV], /* i : number of tns bits in the frame */ + int16_t param_core[][NB_DIV * NPRM_DIV], /* o : quantized noise filling level */ + const int16_t mct_on /* i : flag mct block (1) or stereo (0) */ +); + +void InternalTCXDecoder( + Encoder_State *st, /* i/o: state handle */ + const int16_t frame_cnt, /* i : frame counter in the super_frame */ + const int16_t L_frameTCX, /* i : full frame length */ + const int16_t L_frame, /* i : frame length */ + const int16_t L_spec, /* i : length of the coded spectrum */ + const int16_t tcx_offset, /* i : folding point offset relative to the end of the previous frame */ + const int16_t noiseFillingBorder, /* i : noise filling border */ + const float *x_quant, /* i : quantized spectrum */ + const float ener, /* i : energy of the quantized spectrum */ + float lf_deemph_fact[], /* i/o: low frequency deemphasis factors */ + const float fac_ns, /* i : noise filling level */ + const int16_t nf_seed, /* i : noise filling random seed */ + const float *A, /* i : LPC representation of the FDNS gains */ + float *gainlpc, /* i/o: FDNS gains */ + const int16_t hm_active, /* i : flag indicating if the harmonic model is active */ + float gain_tcx, /* i/o: global gain / quantized global gain */ + float spectrum[], /* o : dequantized spectrum */ + float synth[], /* o : time domain signal */ + int16_t *gain_tcx_q /* o : quantized global gain (at low bitrates) */ +); + +void stereo_mdct_core_enc_fx( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + Word16 new_samples[CPE_CHANNELS][L_INP], /* i : new samples Q0*/ + Word16 old_wsp[CPE_CHANNELS][L_WSP], /* i : 12.8kHz weighted speech (for LTP Qx*/ + Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k] /* o : floating pitch for each subframe Q6*/ +); + +void initMdctStereoEncData( + STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int16_t element_mode, /* i : element mode */ + const int32_t element_brate, /* i : element bitrate */ + const int16_t bwidth, /* i : bandwidth */ + const int16_t igf, /* i : flag indicating IGF activity */ + const H_IGF_GRID hIgfGrid, /* i : IGF grid setup */ + const int16_t mem_init /* i : initialize memory after malloc */ +); + +ivas_error initMdctItdHandling( + STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ + const int32_t input_Fs /* i : input sampling rate */ +); + +void stereo_mdct_enc_destroy( + STEREO_MDCT_ENC_DATA_HANDLE *hStereoMdct /* i/o: encoder MDCT stereo handle */ +); + +void initMdctStereoDecData( + STEREO_MDCT_DEC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ + const int16_t igf, /* i : flag indicating IGF activity */ + const H_IGF_GRID igfGrid, /* i : IGF grid configuration */ + const int32_t element_brate, /* i : element bitrate */ + const int16_t bwidth /* i : audio bandwidth */ +); + +void stereo_mdct_init_bands( + const int16_t L_frame, /* i : frame length */ + const int16_t tmp_tcx_mode, /* i : tcx mode (TCX10, TCX 20), -1 if transition frame */ + const int32_t element_brate, /* i : element bitrate */ + const int16_t igf, /* i : flag indicating if IGF is used */ + const H_IGF_GRID hIgfGrid, /* i : IGF grid setup */ + int16_t *sfbOffset, /* o : sfb offset table */ + int16_t *sfbCnt /* o : number of sfbs */ +); + +void stereo_mdct_init_igf_start_band( + STEREO_MDCT_BAND_PARAMETERS *stbParams, /* i/o: stereo frequency band parameters */ + const float transFac, /* i : transform factor */ + const int16_t bwidth, /* i : audio bandwidth */ + const int32_t element_brate /* i : element bitrate */ +); + +void init_tcx_enc_info( + Encoder_State *st, /* i : coder memory state */ + int16_t *L_frame, + int16_t *L_frameTCX, + int16_t *L_spec +); + +void decoder_tcx_invQ( + Decoder_State *st, /* i/o: coder memory state */ + int16_t prm[], /* i : parameters */ + float A[], /* i : coefficients NxAz[M+1] */ + Word16 Aind[], /* i : frame-independent coefficients Az[M+1] */ + const int16_t L_spec, + const int16_t L_frame, + const int16_t L_frameTCX, + float x[], + float gainlpc2[], + float xn_buf[], + int16_t *fUseTns, /* o : flag that is set if TNS data is present */ + STnsData *tnsData, + float *gain_tcx, + const int16_t **prm_sqQ, + int16_t *nf_seed, + const int16_t bfi, /* i : Bad frame indicator */ + const int16_t frame_cnt /* i : frame counter in the super frame */ +); + +void decoder_tcx_noisefilling( + Decoder_State *st, /* i/o: coder memory state */ + float concealment_noise[L_FRAME48k], + const float A[], /* i : coefficients NxAz[M+1] */ + const int16_t L_frameTCX_glob, + const int16_t L_spec, + const int16_t L_frame, + const int16_t L_frameTCX, + float x[], + float gainlpc2[], + int16_t *temp_concealment_method, + const float gain_tcx, + const int16_t *prm_sqQ, + int16_t nf_seed, + const int16_t bfi, /* i : Bad frame indicator */ + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const int16_t frame_cnt /* i : frame counter in the super frame */ +); + +void decoder_tcx_noiseshaping_igf( + Decoder_State *st, /* i/o: coder memory state */ + const int16_t L_spec, + const int16_t L_frame, + const int16_t L_frameTCX, + const int16_t left_rect, + float x[], + const float gainlpc2[], + int16_t *temp_concealment_method, + const int16_t bfi /* i : Bad frame indicator */ +); + +void decoder_tcx_tns( + Decoder_State *st, /* i/o: coder memory state */ + const int16_t L_frame_glob, + const int16_t L_spec, + const int16_t L_frame, + const int16_t L_frameTCX, + float x[N_MAX], + const int16_t fUseTns, /* i : flag that is set if TNS data is present */ + STnsData *tnsData, + const int16_t bfi, /* i : Bad frame indicator */ + const int16_t frame_cnt, /* i : frame counter in the super frame */ + const int16_t whitenedDomain +); + +void decoder_tcx_imdct( + Decoder_State *st, /* i/o: coder memory state */ + const int16_t L_frame_glob, /* i : frame length */ + const int16_t L_frameTCX_glob, + const int16_t L_spec, + const int16_t tcx_offset, + const int16_t tcx_offsetFB, + const int16_t L_frame, + const int16_t L_frameTCX, + const int16_t left_rect, + float x[N_MAX], + float xn_buf[], + const uint16_t kernelType, /* i : TCX transform kernel type */ + const int16_t fUseTns, /* i : flag that is set if TNS data is present */ + float synth[], /* i/o: synth[-M..L_frame] */ + float synthFB[], + const int16_t bfi, /* i : Bad frame indicator */ + const int16_t frame_cnt, /* i : frame counter in the super frame */ + const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ +); + +void init_tcx_info( + Decoder_State *st, /* i/o: coder memory state */ + const int16_t L_frame_glob, /* i : global frame length */ + const int16_t L_frameTCX_glob, /* i : FB global frame length */ + const int16_t frame_cnt, /* i : frame counter in the super_frame */ + const int16_t bfi, /* i : bad frame indicator */ + int16_t *tcx_offset, /* o : folding point offset relative to the end of the previous frame */ + int16_t *tcx_offsetFB, /* o : FB folding point offset relative to the end of the previous frame*/ + int16_t *L_frame, /* o : frame length */ + int16_t *L_frameTCX, /* o : TCX frame length */ + int16_t *left_rect, /* o : left part is rectangular */ + int16_t *L_spec /* o : spectrum length */ +); + +void decoder_tcx_IGF_mono( + Decoder_State *st, /* i/o: coder memory state */ + float x[], /* o : de-quatized coefficients */ + const int16_t L_frame, /* i : frame length */ + const int16_t left_rect, /* i : left part is rectangular */ + const int16_t bfi, /* i : bad frame indicator */ + const int16_t frame_cnt /* i : frame counter in the super_frame */ +); + +void decoder_tcx_IGF_stereo( + Decoder_State **sts, /* i/o: coder memory states */ + STEREO_MDCT_DEC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo structure */ + int16_t ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ + float *x[CPE_CHANNELS][NB_DIV], /* o : de-quatized coefficients */ + const int16_t L_frame, /* i : frame length */ + const int16_t left_rect, /* i : left part is rectangular */ + const int16_t k, /* i : Subframe index */ + const int16_t bfi, /* i : bad frame indicator */ + const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */ +); + +void ms_processing( + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT encoder structure */ + Encoder_State **sts, /* i/o: Encoder state structure */ + int16_t ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ + const int16_t iSubframe, /* i : subframe number */ + float x_0[], /* i/o: spectrum 1 */ + float x_1[], /* i/o: spectrum 2 */ + int16_t maxSfb /* i : number of stereo frequency bands */ +); + +void ms_inv_mask_processing( + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT encoder structure */ + Encoder_State **sts, /* i/o: Encoder state structure */ + int16_t ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ + const int16_t iSubframe, /* i : subframe number */ + const float x_0[], /* i : spectrum 1 */ + const float x_1[], /* i : spectrum 2 */ + float x_inv_0[], /* o : inverse spectrum 1 */ + float x_inv_1[], /* o : inverse spectrum 2 */ + int16_t maxSfb /* i : number of stereo frequency bands */ +); + +void IGFDecApplyStereo_flt( + const IGF_DEC_INSTANCE_HANDLE hIGFDecL, /* i : instance handle of IGF Decoder */ + const IGF_DEC_INSTANCE_HANDLE hIGFDecR, /* i : instance handle of IGF Decoder */ + float *spectrumL, /* i/o: L MDCT spectrum */ + float *spectrumR, /* i/o: R MDCT spectrum */ + const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */ + const int16_t *coreMsMask, + const int16_t restrict_hopsize, + const int16_t bfi, /* i : frame loss == 1, frame good == 0 */ + const int16_t bfi_apply_damping /* i : decoder element mode */ +); + +void IGFEncStereoEncoder( + STEREO_MDCT_BAND_PARAMETERS *sfbParam, /* i/o: sfb parameters for the right channel */ + const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : IGF handle */ + const float *mdctSpectrumL, /* i : left spectrum */ + const float *mdctSpectrumR, /* i : right spectrum */ + int16_t *msMask, /* i/o: MS mask */ + int16_t *igfStereoMode, /* o : IGF stereo mode */ + const int16_t mdct_stereo_mode, /* i : MDCT stereo mode */ + const int16_t isTCX20, /* i : flag for indicating TCX20 */ + const int16_t isTransition /* i : flag for transtition */ +); + +void IGFDecReplicateTCX10State_flt( + IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: instance handle of IGF Decoder */ +); + + +void InitPsychLPC( + const int32_t sr_core, /* i : sampling rate of core-coder */ + const int16_t L_frame, /* i : frame length */ + const TCX_CONFIG_HANDLE hTcxCfg /* i : TCX configuration handle */ +); + + +void stereo_coder_tcx( + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT encoder structure */ + Encoder_State **sts, /* i/o: encoder state structure */ + int16_t ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ + float *mdst_spectrum[CPE_CHANNELS][NB_DIV], /* i/o: MDST spectrum */ + float *inv_spectrum[CPE_CHANNELS][NB_DIV], /* i/o: inverse spectrum */ + float *inv_mdst_spectrum[CPE_CHANNELS][NB_DIV], /* i/o: inverse MDST spectrum */ + const int16_t mct_on /* i : flag mct block (1) or stereo (0) */ +); + +void stereo_decoder_tcx( + STEREO_MDCT_DEC_DATA *hStereoMdct, /* i/o: MDCT stereo decoder structure */ + int16_t ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ + float *spec_r_0[NB_DIV], /* i/o: spectrum right channel */ + float *spec_l[], /* i/o: spectrum left channel [NB_DIV][N] */ + float *spec_r[], /* i/o: spectrum right channel [NB_DIV][N] */ + const int16_t mdct_stereo_mode[], /* i : stereo mode (FB/band wise MS, dual mono */ + const int16_t core_l, /* i : core for left channel (TCX20/TCX10) */ + const int16_t core_r, /* i : core for right channel (TCX20/TCX10) */ + const int16_t igf, /* i : flag for IGF activity */ + const int16_t L_frameTCX_l, /* i : TCX frame length of left channel */ + const int16_t L_frameTCX_r, /* i : TCX frame length of right channel */ + const int16_t mct_on, /* i : flag mct block (1) or stereo (0) */ + const int16_t last_core_l, /* i : last core for left channel */ + const int16_t last_core_r, /* i : last core for right channel */ + const int16_t tmp_plc_upmix /* i : indicates temp upmix for PLC decision */ +); + +void stereo_mdct_core_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + float *signal_out[CPE_CHANNELS], /* o : synthesis @internal_FS */ + float signal_outFB[CPE_CHANNELS][L_FRAME48k] /* o : synthesis @output_FS */ +); + +void splitAvailableBits( + const int16_t total_bits, /* i : total available bits for TCX coding */ + const int16_t split_ratio, /* i : split ratio */ + const int16_t isSBAStereoMode, /* i : signal core coding for SBA */ + int16_t *bits_ch0, /* o : bits for channel 0 */ + int16_t *bits_ch1 /* o : bits for channel 1 */ +); + +Word16 write_stereo_to_bitstream_fx +( + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ + Encoder_State **sts, /* i/o: Encoder state structure */ + Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask Q0*/ + const Word16 mct_on, /* i : flag mct block (1) or stereo (0) Q0*/ + BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ +); + + + +void ComputeSpectrumNoiseMeasure( + const float *powerSpec, + const int16_t L_frame, + const int16_t startLine, + const int16_t resetMemory, + int8_t *noiseFlags, + const int16_t lowpassLine +); + +void IGFSaveSpectrumForITF( + IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ + const int16_t igfGridIdx, /* i : IGF grid index */ + const float *pITFSpectrum /* i : MDCT spectrum */ +); + +void convert_coeffs_to_higher_res( + const float *in1, /* i : first subframe input */ + const float *in2, /* i : second subframe input */ + float *out, /* o : converted output */ + const int16_t len /* i : length of subframes */ +); + +int16_t quantize_sns( + float sns_in[CPE_CHANNELS][NB_DIV][M], + float snsQ_out[CPE_CHANNELS][NB_DIV][M], + Encoder_State **sts, + int16_t *indices, + int16_t *zero_side_flag, + int16_t *sns_stereo_mode +); + +void dequantize_sns( + int16_t indices[CPE_CHANNELS][NPRM_LPC_NEW], + float snsQ_out[CPE_CHANNELS][NB_DIV][M], + Decoder_State **sts +); + +void sns_avq_dec( + int16_t *index, /* i : Quantization indices */ + float SNS_Q[NB_DIV][M], /* o : Quantized SNS vectors */ + const int16_t L_frame, /* i : frame length */ + const int16_t numlpc /* i : Number of sets of lpc */ +); + +void sns_avq_dec_stereo( + int16_t *indexl, /* i : Quantization indices (left channel) */ + int16_t *indexr, /* i : Quantization indices (right channe) */ + const int16_t L_frame, /* i : frame length */ + float *SNS_Ql, /* o : Quantized SNS vectors (left channel) */ + float *SNS_Qr /* o : Quantized SNS vectors (right channe) */ +); + +void convertToMS( + const int16_t L_frame, /* i : frame length */ + float x0[], /* i/o: mid/left channel coefficients */ + float x1[], /* i/o: side/right channel coefficients */ + const float norm_fac /* i : normalization factor */ +); + +void inverseMS( + const int16_t L_frame, /* i : frame length */ + float x0[], /* i/o: mid/left channel coefficients */ + float x1[], /* i/o: side/right channel coefficients */ + const float norm_fac /* i : normalization factor */ +); + +void stereoFdCngCoherence( + Encoder_State **sts, /* i/o: core encoder structures */ + const int16_t last_element_mode, /* i : last element mode */ + float fft_buff[CPE_CHANNELS][2 * L_FFT] /* i : fft buffers for L and R channels */ +); + +void FdCngEncodeMDCTStereoSID( + CPE_ENC_HANDLE hCPE /* i/o: CPE encoder state structure */ +); + +void FdCngDecodeMDCTStereoSID( + CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */ +); + +ivas_error initMdctStereoDtxData( + CPE_DEC_HANDLE hCPE /* i/o: CPE decoder handle */ +); + +void synchonize_channels_mdct_sid( + Decoder_State *sts[CPE_CHANNELS], /* i/o: decoder state structure */ + const int16_t n /* i : channel number */ +); + +void updateBuffersForDmxMdctStereo( + CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ + const int16_t output_frame, /* i : output frame length */ + float *output[CPE_CHANNELS], /* i/o: decoder output */ + float synth[CPE_CHANNELS][L_FRAME48k] /* i/o: decoder synthesis */ +); + +void applyDmxMdctStereo( + const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ + float *output[CPE_CHANNELS], /* o : output from core decoder */ + const int16_t output_frame /* i : output frame length */ +); + +/*----------------------------------------------------------------------------------* + * Front-VAD prototypes + *----------------------------------------------------------------------------------*/ + +ivas_error front_vad_create( + FRONT_VAD_ENC_HANDLE *hFrontVad, /* i/o: front-VAD handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ +); + +void front_vad_destroy( + FRONT_VAD_ENC_HANDLE *hFrontVad /* i/o: front-VAD handle */ +); + +ivas_error front_vad( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure, nullable */ + Encoder_State *st, /* i/o: encoder state structure */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + FRONT_VAD_ENC_HANDLE *hFrontVads, /* i/o: front-VAD handles */ + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const int16_t input_frame, /* i : frame length */ + int16_t vad_flag_dtx[], /* o : HE-SAD flag with additional DTX HO */ + float fr_bands[][2 * NB_BANDS], /* i : energy in frequency bands */ + float Etot_LR[], /* o : total energy Left & Right channel */ + float lf_E[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */ + int16_t localVAD_HE_SAD[], /* o : HE-SAD flag without hangover, LR channels */ + int16_t vad_hover_flag[], /* o : VAD hangover flag */ + float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */ + float *PS_out, /* o : energy spectrum */ + float *Bin_E_out /* o : log-energy spectrum of the current frame*/ +); + +ivas_error front_vad_spar( + SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder structure */ + const float *omni_in, /* i : omnidirectional input signal */ + ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : encoder configuration handle */ + const int16_t input_frame /* i : input frame length */ +); + + +/*----------------------------------------------------------------------------------* + * Stereo CNG prototypes + *----------------------------------------------------------------------------------*/ + +void stereo_enc_cng_init( + STEREO_CNG_ENC_HANDLE hStereoCng /* i/o: stereo CNG encoder structure */ +); + +void stereo_cng_upd_counters( + STEREO_CNG_ENC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ + const int32_t element_mode, /* i : element mode */ + const int16_t nbands, /* i : Number of bands in active */ + const float sidSideGain[], /* i : SID side gains */ + const int16_t burst_ho_count, /* i : Hang-over count */ + int16_t *coh_fade_counter /* i : Coherence fade counter */ +); + +void stereo_cng_init_dec( + STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: stereo CNG decoder structure */ + const int16_t *frameSize /* i : pointer to frameSize of channel 0 to be used for channel 1 */ +); + +void stereo_cng_compute_PScorr( + float *output[CPE_CHANNELS], /* i : Output signal */ + float *c_PS_LT, /* i/o: Correlation */ + const int16_t L_frame_0, /* i : L_frame channel 0 */ + const int16_t L_frame_1 /* i : L_frame channel 1 */ +); + +void stereo_cng_dec_update( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const int32_t ivas_total_brate /* i : IVAS total bitrate Q0*/ +); + +void stereo_cna_update_params( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + float *output[CPE_CHANNELS], /* i : Output signal */ + const int16_t output_frame, /* i : Output frame length */ + const int16_t tdm_ratio_idx /* i : TDM ratio index */ +); + +void dtx_enc_init( + Encoder_State *st, /* i : Encoder state handle */ + const int16_t var_SID_rate_flag, /* i : flag for variable SID update rate */ + const int16_t interval_SID /* i : interval for SID update */ +); + + +/*----------------------------------------------------------------------------------* + * Framework general prototypes + *----------------------------------------------------------------------------------*/ + +void mvc2c( + const uint8_t x[], /* i : input vector */ + uint8_t y[], /* o : output vector */ + const int16_t n /* i : vector size */ +); + +/*! r: Adjusted value */ +ivas_error stereo_memory_dec( + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + CPE_DEC_HANDLE hCPE, /* i : CPE decoder structure */ + const int16_t nb_bits_metadata, /* i : number of metadata bits */ + const int32_t output_Fs, /* i : output sampling rate */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const MC_MODE mc_mode, /* i : MC mode */ + const int16_t nchan_transport /* i : number of transport channels */ +); + +void stereo_switching_dec( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ +); + +void stereo_td2dft_update( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const int16_t n, /* i : channel number */ + float output[], /* i/o: synthesis @internal Fs */ + float synth[], /* i/o: synthesis @output Fs */ + float hb_synth[], /* i/o: hb synthesis */ + const int16_t output_frame /* i : frame length */ +); + +void stereo_mdct2dft_update( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + float output0[], /* i/o: synthesis @internal Fs, ch0 */ + float synth0[] /* i/o: synthesis @output Fs, ch0 */ +); + + +/*! r: number of bits written */ + + + +/*----------------------------------------------------------------------------------* + * MCT prototypes + *----------------------------------------------------------------------------------*/ +void ivas_mdct_core_whitening_enc_fx( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + Word16 new_samples_fx[CPE_CHANNELS][L_INP], /* i : new samples */ + Word16 old_wsp_fx[CPE_CHANNELS][L_WSP], /* i : 12.8kHz weighted speech (for LTP */ + Word16 pitch_buf[CPE_CHANNELS][NB_SUBFR16k], /* o : floating pitch for each subframe */ + Word32 *mdst_spectrum_long[CPE_CHANNELS], /* o : buffer for MDST spectrum */ + int16_t tnsBits[CPE_CHANNELS][NB_DIV], /* o : buffer TNS bits */ + Word32 *orig_spectrum_long[CPE_CHANNELS], /* o : origingal spectrum w/o whitening */ + int16_t tnsSize[CPE_CHANNELS][NB_DIV], /* o : size of TNS */ + int16_t p_param[CPE_CHANNELS][NB_DIV], /* o : pointer to parameter array */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const int16_t mct_on, /* i : flag mct block (1) or stereo (0) */ + const int16_t nChannels, /* i : total number of coded channels */ +Word16 mdst_spectrum_e[CPE_CHANNELS][NB_DIV], +Word16 orig_spectrum_e[CPE_CHANNELS][NB_DIV] +); +void ivas_mct_core_enc( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + CPE_ENC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE encoder structures */ + const int16_t nChannels, /* i : number of channels to be coded */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t switch_bw, /* i : flag bandwidth switch occurance */ + const int16_t lfe_bits, /* i : bits spent for LFE */ + const int16_t sba_order /* i : Ambisonic (SBA) order */ +); + +void ivas_mdct_quant_coder( + CPE_ENC_HANDLE hCPE, /* i/o: Encoder CPE handle */ + int16_t tnsBits[CPE_CHANNELS][NB_DIV], /* i : bits needed for TNS parameters */ + int16_t tnsSize[CPE_CHANNELS][NB_DIV], /* i : size of TNS */ + int16_t p_param[CPE_CHANNELS][NB_DIV], /* i : pointer to parameter array */ + const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */ +); + +void apply_MCT_enc( + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + Encoder_State **sts, /* i/o: encoder state structure */ + float *mdst_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: MDST spectrum */ + float *inv_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: inverse spectrum */ + float *inv_mdst_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: inverse MDST spectrum */ + const int16_t nchan /* i : number of channels */ +); + +void write_mct_bitstream( + Encoder_State **sts, /* i/o: encoder state structure */ + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + const int16_t nchan /* i : number of channels */ +); + +void splitAvailableBitsMCT_fx( + void **sts, /* i/o: encoder/decoder state structure */ + const Word16 total_bits, /* i : total number of available bits */ + const Word16 split_ratio[MCT_MAX_CHANNELS], /* i : ratio for splitting the bits Q0 */ + const Word16 enc_dec, /* i : encoder or decoder flag */ + const Word16 nchan /* i : number of channels */ +); + +void getChannelEnergies( + Encoder_State **sts, /* i : Encoder state structure */ + float nrg[MCT_MAX_CHANNELS], /* o : energies */ + const int16_t nchan /* i : number of channels */ +); + +void mctStereoIGF_enc( + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + Encoder_State **sts, /* i/o: encoder state structure */ + float *orig_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i : MDCT spectrum for ITF */ + float powerSpec[MCT_MAX_CHANNELS][L_FRAME48k], /* i/o: MDCT^2 + MDST^2 spectrum,or estimate */ + float *powerSpecMsInv[MCT_MAX_CHANNELS][NB_DIV], /* i : same as above but for inverse spect. */ + float *inv_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i : inverse spectrum */ + const int16_t sp_aud_decision0[MCT_MAX_CHANNELS] /* i : speech audio decision */ +); + +void ivas_mdct_dec_side_bits_frame_channel( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + int16_t param_lpc[CPE_CHANNELS][NPRM_LPC_NEW], /* o : lpc_parameters */ + int16_t p_param[CPE_CHANNELS][NB_DIV], /* o : pointer to param buffer */ + Decoder_State *st0, /* i : pointer to bitstream handle */ + int16_t nTnsBitsTCX10[CPE_CHANNELS][NB_DIV], /* o : number of bits for TNS */ + int16_t param[CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV], /* i/o: parameters buffer */ + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const int16_t odd_channel_cpe /* i : flag cpe with odd nb of tc channels */ +); + +void ivas_mct_side_bits( + MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ + CPE_DEC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE decoder structure */ + const int16_t nCPE, /* i : number of CPEs */ + Decoder_State *st0, /* i : decoder handle for Bstr */ + const int16_t bfi, /* i : BFI flag */ + uint16_t *bitstream, /* o : bitstream indices */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t nb_bits_metadata /* i : number of metadata bits */ +); + +void ivas_mdct_core_invQ( + CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ + int16_t nTnsBitsTCX10[CPE_CHANNELS][NB_DIV], /* i : number of TNS bits */ + int16_t p_param[CPE_CHANNELS][NB_DIV], /* i : pointer to param buffer */ + int16_t param_lpc[CPE_CHANNELS][NPRM_LPC_NEW], /* i : lpc parameters */ + int16_t param[CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV], /* i : param buffer */ + int16_t fUseTns[CPE_CHANNELS][NB_DIV], /* i : flag TNS enabled */ + STnsData tnsData[CPE_CHANNELS][NB_DIV], /* i : TNS parameter */ + float *x_0[CPE_CHANNELS][NB_DIV], /* i/o: signal buffer */ + float *x[CPE_CHANNELS][NB_DIV], /* i/o: signal buffer */ + float Aq[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* i : LP coefficients */ + int16_t ms_mask[NB_DIV][MAX_SFB], /* i : M/S mask */ + const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */ +); + +void ivas_mdct_core_reconstruct( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + float *x[][NB_DIV], /* i/o: pointers to synthesis @internal_FS */ + float signal_outFB[CPE_CHANNELS][L_FRAME_PLUS], /* o : synthesis @output_FS */ + int16_t fUseTns[CPE_CHANNELS][NB_DIV], /* i : flage TNS enabled */ + const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */ +); + +void ivas_mdct_core_tns_ns( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + int16_t fUseTns[CPE_CHANNELS][NB_DIV], /* i : two entries for each channel in TCX10 */ + STnsData tnsData[CPE_CHANNELS][NB_DIV], /* o : TNS parameter */ + float *x[CPE_CHANNELS][NB_DIV], /* o : synthesis @internal_FS */ + float Aq[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* o : LP coefficients */ + const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */ +); + + +void ivas_mct_dec_mct( + MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ + Decoder_State **sts, /* i/o: decoder state structure */ + const int16_t nchan /* i : number of channels */ +); + +void apply_MCT_dec( + MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ + Decoder_State **sts, /* i/o: decoder state structure */ + float *x[MCT_MAX_CHANNELS][NB_DIV] /* i/o: decoded and dequan. spect. input to MCT */ +); + +void mctStereoIGF_dec( + MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ + Decoder_State **sts, /* i/o: decoder state structure */ + float *x[MCT_MAX_CHANNELS][NB_DIV], /* i/o: decoded and dequantized spectrum */ + const int16_t bfi /* i : bad frame flag */ +); + +void enc_prm_igf_mdct( + Encoder_State *st, /* i : Encoder state handle */ + BSTR_ENC_HANDLE hBstr /* i/o: Bitstream handle */ +); + +void mdct_read_IGF_bits( + Decoder_State *st, /* i/o: Encoder state handle */ + Decoder_State *st0 /* i : pointer to handle where bstr is read */ +); + + +/*----------------------------------------------------------------------------------* + * Q Metadata prototypes for DirAC and MASA + *----------------------------------------------------------------------------------*/ + +ivas_error ivas_qmetadata_enc_encode( + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + IVAS_QMETADATA *hQMetaData, /* i/o: q_metadata handle */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ +); + +ivas_error ivas_qmetadata_enc_encode_hr_384_512( + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + IVAS_QMETADATA *hQMetaData, /* i/o: metadata handle */ + const int16_t bits_sph_idx, + const int16_t bits_sp_coh +); + +void deindex_sph_idx( + const uint16_t sphIndex, /* i : Spherical index */ + const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */ + float *theta, /* o : Elevation */ + float *phi /* o : Azimuth */ +); + +/*! r: output index for direction */ +uint16_t index_theta_phi_16( + float * p_theta, /* i/o: input elevation to be indexed */ + float * p_phi, /* i/o: input azimuth to be indexed */ + const SPHERICAL_GRID_DATA *gridData /* i : generated grid data */ +); + +void reset_metadata_spatial( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + const int32_t element_brate, /* i : element bitrate */ + int32_t *total_brate, /* o : total bitrate */ + const int32_t core_brate, /* i : core bitrate */ + const int16_t nb_bits_metadata /* i : number of meatdata bits */ +); + +/*! r: number of bits written */ + +/*! r: number of bits read */ +int16_t ivas_qmetadata_dec_decode( + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + uint16_t *bitstream, /* i : bitstream */ + int16_t *index, /* i/o: bitstream position */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ +); + +/*! r: number of bits read */ +int16_t ivas_qmetadata_dec_decode_hr_384_512( + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: hQMetaData handle */ + uint16_t *bitstream, /* i : bitstream */ + int16_t *index, /* i/o: bitstream position */ + const SPHERICAL_GRID_DATA *sph_grid16, /* i : spherical grid for deindexing */ + const int16_t bits_sph_idx, + const int16_t bits_sp_coh, + const uint8_t ncoding_bands_config +); + +/*! r: number of bits read */ +int16_t ivas_qmetadata_dec_sid_decode( + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + uint16_t *bitstream, /* i : bitstream */ + int16_t *index, /* i/o: bitstream position */ + const int16_t nchan_transport, /* i : number of transport channels */ + int16_t *element_mode, /* o : element mode */ + const int16_t ivas_format /* i : IVAS format */ +); + + + + +void restore_metadata_buffer( + BSTR_ENC_HANDLE hMetaData, + const int16_t next_ind_start, + const int16_t bit_pos_start +); + +/*! r: codeword index */ +int16_t masa_sq( + const float in, /* i : input value */ + const float *threshold, /* i : partition */ + const int16_t cb_sz /* i : codebook size */ +); + +void ivas_qmetadata_azimuth_elevation_to_direction_vector( + const float az, /* i : azimuth */ + const float el, /* i : elevation */ + float *dv /* o : direction vector */ +); + +ivas_error only_reduce_bits_direction( + int16_t *reduce_bits_out, + IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ + int16_t reduce_bits, + const int16_t coding_subbands, + const int16_t no_subframes, + int16_t *ind_order +); + +void quantize_direction_frame( + IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ + float azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], + float elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], + const int16_t hrmasa_flag /* i : flag indicating high-rate MASA MD coding*/ +); + +/*! r: quantized spherical index */ +uint16_t quantize_direction( + const float theta, /* i : input elevation value */ + float phi, /* i : input azimuth value */ + const int16_t no_bits, /* i : number of bits */ + float *theta_q, /* o : quantized elevation */ + float *phi_q, /* o : quantized azimuth */ + uint16_t *index_theta, /* o : quantized elevation index */ + uint16_t *index_phi, /* o : quantized azimuth index */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ +); + +int16_t quantize_direction2D( + float phi, /* i : input azimuth value */ + const int16_t no_cw, /* i : number of bits */ + float *phi_q, /* o : quantized azimuth value */ + uint16_t *index_phi, /* o : quantized azimuth index */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ +); + +void quantize_direction_frame2D( + IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ + float azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], /* i : input azimuth values */ + float elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES] /* i : input elevation values */ +); + +void small_requantize_direction_frame( + IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ + float azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], /* i : input azimuth values */ + float elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], /* i : input elevation values */ + const int16_t raw_flag[MASA_MAXIMUM_CODING_SUBBANDS], /* i : raw/EC encoding mode for each subband */ + int16_t bits_dir_bands[MASA_MAXIMUM_CODING_SUBBANDS], /* i/o: number of bits per subband */ + int16_t *diff /* i/o: number of bits to be reduced */ +); + +/*! r: index azimuth */ +int16_t quantize_phi( + float phi, /* i : azimuth value */ + const int16_t flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + float *phi_hat, /* o : quantized azimuth */ + const int16_t n /* i : azimuth codebook size */ +); + +/*! r: decoded elevation value */ +float deindex_elevation( + uint16_t *id_th, /* i : input index */ + const int16_t no_bits, /* i : number of bits for the spherical grid */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ +); + +float deindex_azimuth( + int16_t id_phi, /* i : index */ + const int16_t no_bits, /* i : number of bits for the spherical grid */ + const int16_t id_th, /* i : elevation index */ + const int16_t remap, /* i : remapping flag */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ +); + +UWord16 ivas_qmetadata_reorder_generic_fx( + const Word16 signed_value +); + +void ivas_sba_config( + const int32_t sba_total_brate, /* i : SBA total bitrate */ + int16_t sba_order, /* i : Ambisonic (SBA) order */ + int16_t nb_channels, /* i : Number of Ambisonic (SBA) channels */ + int16_t *nchan_transport, /* o : number of transport channels */ + const int16_t sba_planar, /* i : SBA planar flag */ + int16_t *nSCE, /* o : number of SCEs */ + int16_t *nCPE, /* o : number of CPEs */ + int16_t *element_mode /* o : element mode of the core coder */ +); + +void ivas_sba_set_cna_cng_flag( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +ivas_error ivas_sba_dec_reconfigure( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + uint16_t *nSamplesFlushed, /* o : number of samples flushed */ + int16_t *data /* o : output synthesis signal */ +); + +ivas_error ivas_sba_digest_tc( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const int16_t nchan_transport, /* i : number of transport channels */ + const int16_t nCldfbSlots, /* i : number of CLDFB slots */ + const int16_t nSamplesForRendering, /* i : number of samples provided */ + float *data[] /* i : transport channel samples */ +); + + + +/*! r: Ambisonic (SBA) order */ +int16_t ivas_sba_get_order( + const int16_t nb_channels, /* i : Number of ambisonic channels */ + const int16_t sba_planar /* i : SBA planar flag */ +); + +/*! r: number of Ambisonic channels */ +int16_t ivas_sba_get_nchan( + const int16_t sba_order, /* i : Ambisonic (SBA) order */ + const int16_t sba_planar /* i : SBA planar flag */ +); + +/*! r: number of ambisonics metadata channels */ + +void ivas_sba_getTCs( + float *sba_data[], /* i : SBA signals */ + Encoder_Struct *st_ivas, /* i/o: Encoder struct */ + const int16_t input_frame /* i : frame length */ +); + +int16_t ivas_sba_remapTCs( + float *sba_data[], /* i/o: SBA signals */ + Decoder_Struct *st_ivas, /* i/o: decoder struct */ + const int16_t output_frame /* i : frame length */ +); + +void ivas_sba_dirac_stereo_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output[CPE_CHANNELS], /* o : output synthesis signal */ + const int16_t output_frame, /* i : output frame length per channel */ + const int16_t mcmasa /* i : McMASA flag */ +); + +void ivas_sba_dirac_stereo_config( + STEREO_DFT_CONFIG_DATA_HANDLE hConfig /* o : DFT stereo configuration */ +); + + +Word16 ivas_get_sba_dirac_stereo_flag( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +void ivas_sba_dirac_stereo_smooth_parameters( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: encoder DFT stereo handle */ + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD handle for upmixing */ + const int16_t cross_fade_start_offset, /* i : SPAR mixer delay compensation */ + const int32_t output_Fs, /* i : Fs for delay calculation */ + const int16_t num_md_sub_frames /* i : number of subframes in mixing matrix */ +); + + +/*----------------------------------------------------------------------------------* + * DirAC prototypes + *----------------------------------------------------------------------------------*/ + + +ivas_error ivas_dirac_enc_reconfigure( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +); + + + +ivas_error ivas_dirac_config( + void *st_ivas, /* i/o: IVAS encoder/decoder state structure */ + const int16_t enc_dec /* i : encoder or decoder flag */ +); + +void ivas_dirac_config_bands( + int16_t *band_grouping, /* o : band grouping */ + const int16_t nbands, /* i : number of bands */ + const int16_t max_band, /* i : maximal band index +1 */ + int16_t *dirac_to_spar_md_bands, /* o : mapping of DirAC parameter band index to SPAR FB band index */ + const int8_t useLowerBandRes, /* i : flag indicating lower band resolution for DirAC */ + const int16_t enc_param_start_band, /* i : band index of first DirAC parameter band */ + IVAS_FB_MIXER_HANDLE hFbMdft +); + +void ivas_get_dirac_sba_max_md_bits( + const int32_t sba_total_brate, + int16_t *bits_frame_nominal, + int16_t *metadata_max_bits, + int16_t *qmetadata_max_bit_req, + const int16_t nbands + , + IVAS_FORMAT ivas_format +); + +ivas_error ivas_dirac_sba_config( + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + int16_t *element_mode, /* o : element mode of the core coder */ + int32_t sba_total_brate, /* i : SBA total bitrate */ + const int16_t sba_order, /* i : Ambisonic (SBA) order */ + const int16_t nbands /* i : number of frequency bands */ + , + IVAS_FORMAT ivas_format +); + +ivas_error ivas_dirac_dec_config( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const DIRAC_CONFIG_FLAG flag_configopen /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ +); + +void ivas_dirac_dec_close( + DIRAC_DEC_HANDLE *hDirAC_out +); + +void ivas_dirac_dec_read_BS( + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + Decoder_State *st, /* i/o: decoder Core state structure */ + DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial rendering data handle */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q metadata */ + int16_t *nb_bits, /* o : number of bits read */ + const int16_t last_bit_pos, /* i : last read bitstream position */ + const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ + int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ +); + +void generate_masking_noise_lb_dirac( + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + float *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */ + const int16_t nCldfbTs, /* i : number of CLDFB slots that will be rendered */ + const int16_t cna_flag /* i : CNA flag for LB and HB */ +); + + +void ivas_dirac_dec_render( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const int16_t nchan_transport, /* i : number of transport channels */ + const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ + uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */ + uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + float *output_f[] /* o : rendered time signal */ +); + +void ivas_dirac_dec_render_sf( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ + const int16_t nchan_transport, /* i : number of transport channels */ + float *pppQMfFrame_ts_re[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], + float *pppQMfFrame_ts_im[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] +); + + +void computeDirectionVectors( + float *intensity_real_x, + float *intensity_real_y, + float *intensity_real_z, + const int16_t enc_param_start_band, + const int16_t num_frequency_bands, + float *direction_vector_x, + float *direction_vector_y, + float *direction_vector_z +); + +void computeDiffuseness( + float *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], + const float *buffer_energy, + const int16_t num_freq_bands, + float *diffuseness +); + +void ivas_dirac_dec_get_response( + const int16_t azimuth, + const int16_t elevation, + float *response, + const int16_t ambisonics_order +); + + + +ivas_error ivas_mc_paramupmix_enc_open_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +); + +void ivas_mc_paramupmix_enc_close_fx( + MC_PARAMUPMIX_ENC_HANDLE *hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ + const int32_t input_Fs /* i : input sampling rate */ +); + +ivas_error ivas_mc_paramupmix_dec_open( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +void ivas_mc_paramupmix_dec_close( + MC_PARAMUPMIX_DEC_HANDLE *hMCParamUpmix_out /* i/o: Parametric MC decoder handle */ +); + +void ivas_mc_paramupmix_dec_read_BS( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_State *st, /* i/o: decoder state structure */ + MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle */ + int16_t *nb_bits /* o : number of bits written */ +); + +void ivas_mc_paramupmix_dec_digest_tc( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ + const int16_t nSamplesForRendering /* i : number of samples provided */ +); + +void ivas_param_mc_set_coded_bands_fx( + HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* i/o: handle for the Parametric MC parameter coding state */ +); + +/*! r: number of IVAS transport channels */ + +ivas_error ivas_param_mc_enc_open( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +); + +ivas_error ivas_param_mc_enc_reconfig( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +); + +void ivas_param_mc_enc_close( + PARAM_MC_ENC_HANDLE *hParamMC, /* i/o: Parametric MC encoder handle */ + const int32_t input_Fs /* i : input sampling rate */ +); + +void ivas_param_mc_enc( + Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */ + float *data_f[], /* i/o: input/transport MC data */ + const int16_t input_frame /* i : input frame length */ +); + +ivas_error ivas_param_mc_dec_open( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +ivas_error ivas_param_mc_dec_reconfig( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + + + +void ivas_param_mc_dec_digest_tc( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ + float *transport_channels_f[] /* i : synthesized core-coder transport channels/DirAC output*/ +); + +void ivas_param_mc_dec_render( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ + uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */ + uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + float *output_f[] /* o : rendered time signal */ +); + +void ivas_param_mc_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + float *output_f[] /* i/o: synthesized core-coder transport channels/DirAC output */ +); + +/*! r: number of cldfb synthesis instances */ +int16_t param_mc_get_num_cldfb_syntheses( + Decoder_Struct *st_ivas /* i : IVAS decoder structure */ +); + +UWord16 ivas_param_mc_get_configuration_index_fx( + const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +); + +ivas_error ivas_dirac_dec_output_synthesis_cov_open( + DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ + DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: handle for the covariance synthesis state */ + const int16_t max_band_decorr, /* i : uppermost frequency band where decorrelation is applied */ + const int16_t interp_length, /* i : length for interpolating the mixing matrices in time slots */ + const int16_t num_param_bands, /* i : number of parameter bands */ + const int16_t num_param_bands_residual, /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ + const int16_t nchan_in, /* i : number of input (transport) channels */ + const int16_t nchan_out, /* i : number of output channels */ + const float *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) */ +); + +void ivas_dirac_dec_output_synthesis_get_interpolator( + DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ + const uint16_t interp_length /* i : interpolator length */ +); + +void ivas_dirac_dec_output_synthesis_cov_init( + DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: pointer to the state of the covariance synthesis */ + const int16_t nchan_in, /* i : number of input (tranport) channels */ + const int16_t nchan_out, /* i : number of output channels */ + const int16_t n_param_bands, /* i : number of total parameter bands */ + const int16_t n_param_bands_res /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ +); + +void ivas_dirac_dec_output_synthesis_cov_close( + DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i : handle for the covariance synthesis parameters */ + DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state /* i/o: handle for the covariance synthesis state */ +); + + +void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot( + float *Cldfb_RealBuffer_in, /* i : input channel filter bank samples (real part) */ + float *Cldfb_ImagBuffer_in, /* i : input channel filter bank samples (imaginary part) */ + float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (real part) */ + float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (imaginary part) */ + float *mixing_matrix[], /* i : parameter band wise mixing matrices (direct part) */ + float *mixing_matrix_res[], /* i : parameter band wise mixing matrices (residual part) */ + const uint16_t slot_idx_sfr, /* i : time slot index for the current slot within the current subframe */ + const uint16_t slot_idx_tot, /* i : time slot index for the current slot within the frame */ + const int16_t nX, /* i : number of input channels */ + const int16_t nY, /* i : number of output channels */ + PARAM_MC_DEC_HANDLE hParamMC /* i : handle to the Parametric MC decoder state */ +); + + +void FdCngEncodeDiracMDCTStereoSID( + CPE_ENC_HANDLE hCPE /* i/o: CPE encoder state structure */ +); + +void FdCngDecodeDiracMDCTStereoSID( + CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */ +); + + +/*----------------------------------------------------------------------------------* + * SPAR prototypes + *----------------------------------------------------------------------------------*/ + +ivas_error ivas_spar_enc_open( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder handle */ + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +); + +ivas_error ivas_spar_enc( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + float *data_f[], /* i/o: input/transport audio channels */ + const int16_t input_frame, /* i : input frame length */ + int16_t *nb_bits_metadata, /* i : number of MD bits written */ + BSTR_ENC_HANDLE hMetaData /* o : MetaData handle */ +); + +ivas_error ivas_spar_dec_open( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +); + + +ivas_error ivas_spar_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ + int16_t *nb_bits_read /* o : number of MD bits read */ +); + +void ivas_spar_config( + int32_t ivas_total_brate, /* i : codec total bitrate */ + const int16_t sba_order, /* i : Ambisonic (SBA) order */ + int16_t *nchan_transport, /* o : number of transport channels */ + int16_t *nSCE, /* o : number of SCEs */ + int16_t *nCPE, /* o : number of CPEs */ + int32_t *core_nominal_brate, /* o : core-coding nominal bitrate */ + const int16_t sid_format /* i : IVAS format indicator from SID frame */ +); + +ivas_error ivas_sba_linear_renderer( + float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ + const int16_t output_frame, /* i : output frame length per channel */ + const int16_t nchan_in, /* i : number of input ambisonics channels */ + const int16_t 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 */ +); + +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 */ +); + +/* AGC */ +/*! r: AGC enable flag */ + +ivas_error ivas_spar_agc_enc_open( + ivas_agc_enc_state_t **hAgcEnc, /* i/o: AGC decoder handle */ + const int32_t input_Fs, /* i : input sampling rate */ + const int16_t nchan_inp /* i : number of input channels */ +); + +void ivas_spar_agc_enc_close( + ivas_agc_enc_state_t **hAgcEnc /* i/o: AGC encoder handle */ +); + +void ivas_agc_enc_process( + ivas_agc_enc_state_t *hAgcEnc, /* i/o: AGC encoder handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ + float **ppPcm_in, /* i : input audio channels */ + float **ppPcm_out, /* o : output audio channels */ + const int16_t n_channels, /* i : number of channels */ + const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ +); + +ivas_error ivas_spar_agc_dec_open( + ivas_agc_dec_state_t **hAgcDec, /* i/o: AGC decoder handle */ + const int32_t output_Fs /* i : output sampling rate */ +); + +void ivas_spar_agc_dec_close( + ivas_agc_dec_state_t **hAgcDec /* i/o: AGC decoder handle */ +); + + +void ivas_agc_dec_process( + ivas_agc_dec_state_t *hAgcDec, /* i/o: AGC decoder handle */ + float *pcm_in[], /* i : input audio channels */ + float *pcm_out[], /* o : output audio channels */ + const int16_t n_channels, /* i : number of channels */ + const int16_t output_Fs /* i : output sampling rate */ +); + +void ivas_agc_read_bits( + ivas_agc_dec_state_t *hAgcDec, /* i/o: AGC decoder handle */ + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ + const int16_t n_channels, /* i : number of channels */ + const int16_t AGC_flag /* i : AGC on/off flag */ +); + +void ivas_agc_initWindowFunc( + float *pWinFunc, + const int16_t length +); + +void ivas_agc_calcGainParams( + uint16_t *absEmin, + uint16_t *betaE, + uint16_t *maxAttExp, + const int16_t numCoeffs +); + +float ivas_get_mdct_scaling_gain( + const int16_t dct_len_by_2 +); + +void ivas_get_twid_factors( + const int16_t length, + const float **pTwid_re, + const float **pTwid_im +); + +int16_t ivas_get_bw_idx_from_sample_rate( + const int32_t sampling_rate /* i : sampling rate */ +); + +/*! r: config. table index */ +int16_t ivas_get_spar_table_idx( + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t sba_order, /* i : IVAS SBA order */ + const int16_t bwidth, /* i : audio bandwidth */ + int16_t *bitlen, /* o : number of bits */ + int16_t *ind /* o : indice */ +); + +/*! r: number of transport channels */ +int16_t ivas_get_sba_num_TCs( + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t sba_order /* i : IVAS SBA order */ +); + + +void ivas_spar_bitrate_dist( + int32_t core_brates_act[], /* o : bitrates per core-coder */ + const int16_t nAvailBits, /* i : number of available bits */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t sba_order, /* i : Ambisonic (SBA) order */ + const int16_t bwidth /* i : audio bandwidth */ +); + +void ivas_mdct( + const float *pIn, + float *pOut, + const int16_t length +); + +void ivas_dct_windowing( + const int16_t fade_len, + const int16_t full_len, + const int16_t dct_len, + const int16_t zero_pad_len, + const float *pWindow_coeffs, + const int16_t frame_len, + float *pOut_buf, + float *pBuffer_prev, + float *pTemp_lfe +); + +void ivas_tda( + const float *pIn, + float *pOut, + const int16_t length +); + +void ivas_imdct( + const float *pIn, + float *pOut, + const int16_t length +); + +void ivas_itda( + const float *re, + float *pOut, + const int16_t length +); + +void ivas_spar_get_cldfb_gains( + SPAR_DEC_HANDLE hSpar, + HANDLE_CLDFB_FILTER_BANK cldfbAnaDec0, + HANDLE_CLDFB_FILTER_BANK cldfbSynDec0, + const DECODER_CONFIG_HANDLE hDecoderConfig +); + +/*! r: 1 if prediction residual channel */ + +void ivas_spar_dec_agc_pca( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + float *output[], /* i/o: input/output audio channels */ + const Word16 output_frame /* i : output frame length */ +); + +void ivas_spar_dec_set_render_map( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t nCldfbTs /* i : number of CLDFB time slots */ +); + +void ivas_spar_dec_set_render_params( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const int16_t n_cldfb_slots /* i : number of cldfb slots in this frame */ +); + +void ivas_spar_dec_digest_tc( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const int16_t nchan_transport, /* i : number of transport channels */ + const int16_t nCldfbSlots, /* i : number of CLDFB slots */ + const int16_t nSamplesForRendering /* i : number of samples provided */ +); + +void ivas_sba_dec_digest_tc( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const int16_t nCldfbSlots, /* i : number of CLDFB slots */ + const int16_t nSamplesForRendering /* i : number of samples provided */ +); + +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 */ + uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */ + uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + float *output_f[] /* o : rendered time signal */ +); + +void ivas_spar_dec_upmixer_sf( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + float *output[], /* o : output audio channels */ + const int16_t nchan_internal /* i : number of internal channels */ +); + +void ivas_spar_dec_upmixer( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + float *output[], /* i/o: input/output audio channels */ + const int16_t nchan_internal, /* i : number of internal channels */ + const int16_t output_frame /* i : output frame length */ +); + +/* MD module */ + +void ivas_spar_md_enc_close( + ivas_spar_md_enc_state_t **hMdEnc /* i/o: SPAR MD encoder handle */ +); + +void ivas_compute_spar_params( + float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + const int16_t i_ts, + float ***mixer_mat, + const int16_t start_band, + const int16_t end_band, + const int16_t dtx_vad, + const int16_t num_ch, + const int16_t bands_bw, + const int16_t active_w, + const int16_t active_w_vlbr, + ivas_spar_md_com_cfg *hSparCfg, + ivas_spar_md_t *hSparMd, + float *pWscale, + const int16_t from_dirac, + const int16_t dyn_active_w_flag +); + +void ivas_create_fullr_dmx_mat( + float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + float ***mixer_mat, + const int16_t in_chans, + const int16_t start_band, + const int16_t end_band, + const int16_t active_w, + ivas_spar_md_com_cfg *hMdCfg +); + +void ivas_calc_c_p_coeffs( + ivas_spar_md_t *pSparMd, + float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + const int16_t i_ts, + float ***mixer_mat, + const int16_t num_ch, + const int16_t num_dmx, + const int16_t band_idx, + const int16_t dtx_vad, + const int16_t compute_p_flag, + const int16_t dyn_active_w_flag +); + +void ivas_get_spar_md_from_dirac( + float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], + float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], + float diffuseness[IVAS_MAX_NUM_BANDS], + const int16_t n_ts, + float ***mixer_mat, + ivas_spar_md_t *hSpar_md, + ivas_spar_md_com_cfg *hSpar_md_cfg, + const int16_t start_band, + const int16_t end_band, + const int16_t order, + const int16_t dtx_vad, + float Wscale_d[IVAS_MAX_NUM_BANDS], + const uint8_t useLowerRes, + const int16_t active_w_vlbr, + const int16_t dyn_active_w_flag +); + +/*! r: number of MD subframes */ + +ivas_error ivas_spar_md_dec_matrix_open( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t num_channels, /* i : number of internal channels */ + const int16_t num_md_sub_frames +); + +void ivas_spar_md_dec_matrix_close( + ivas_spar_md_dec_state_t *hMdDecoder, /* i/o: SPAR MD decoder handle */ + const int16_t num_channels /* i : number of internal channels */ +); + +ivas_error ivas_spar_md_dec_open( + ivas_spar_md_dec_state_t **hMdDec_out, /* i/o: SPAR MD decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t num_channels, /* i : number of internal channels */ + const int16_t sba_order, /* i : SBA order */ + const int16_t sid_format, /* i : SID format */ + const int32_t last_active_ivas_total_brate /* i : IVAS last active bitrate */ +); + +void ivas_spar_md_dec_close( + ivas_spar_md_dec_state_t **hMdDec /* i/o: SPAR MD decoder handle */ +); + +void ivas_spar_get_parameters( + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t ts, /* i : time slot index */ + const int16_t num_ch_out, /* i : number of channels out */ + const int16_t num_ch_in, /* i : number of channels in */ + const int16_t num_spar_bands, /* i : number of SPAR bands */ + float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */ +); + +ivas_error ivas_spar_md_dec_init( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t num_channels, /* i : number of internal channels */ + const int16_t sba_order /* i : SBA order */ +); + +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 : SBA order */ +); + +void ivas_spar_to_dirac( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t dtx_vad, /* i : DTX frame flag */ + const int16_t num_bands_out, /* i : number of output bands */ + const int16_t bw, /* i : band joining factor */ + const int16_t dyn_active_w_flag /* i : dynamic active W flag */ +); + +void ivas_spar_update_md_hist( + ivas_spar_md_dec_state_t *hMdDec /* i/o: SPAR MD decoder handle */ +); + +int16_t ivas_spar_chk_zero_coefs( + Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ +); + +void ivas_spar_smooth_md_dtx( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t num_bands_out, /* i : number of output bands */ + const int16_t num_md_sub_frames /* i : number of metadata subframes */ +); + +void ivas_spar_setup_md_smoothing( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t num_bands_out, /* i : number of output bands */ + const int16_t num_md_sub_frames /* i : number of metadata subframes */ +); + +void ivas_spar_dec_gen_umx_mat( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t nchan_transport, /* i : number of transport channels */ + const int16_t num_bands_out, /* i : number of output bands */ + const int16_t bfi, /* i : bad frame indicator */ + const int16_t num_md_sub_frames +); + + + + + +/* Transient detector module */ +ivas_error ivas_transient_det_open_fx( + ivas_trans_det_state_t **hTranDet, /* i/o: Transient detector handle */ + const Word32 sampling_rate /* i : sampling rate */ +); + +void ivas_transient_det_close_fx( + ivas_trans_det_state_t **hTranDet /* i/o: Transient detector handle */ +); + +void ivas_transient_det_process( + ivas_trans_det_state_t *hTranDet, /* i/o: SPAR TD handle */ + float *pIn_pcm, /* i : input audio channels */ + const int16_t frame_len, /* i : frame length in samples */ + int16_t transient_det[2] /* o : transient det outputs */ +); + +void ivas_td_decorr_get_ducking_gains( + ivas_trans_det_state_t *hTranDet, /* i/o: Transient detector handle */ + float *pIn_pcm, + float *pIn_duck_gains, + float *pOut_duck_gains, + const int16_t frame_len, + const int16_t tdet_flag +); + +#define IVAS_CMULT_FLOAT( in1_re, in1_im, in2_re, in2_im, out1_re, out1_im ) \ + out1_re = ( in1_re * in2_re ) - ( in1_im * in2_im ); \ + out1_im = ( in1_re * in2_im ) + ( in2_re * in1_im ); + +#define IVAS_CALCULATE_ABS( re, im, out ) \ + out = sqrtf( ( re * re ) + ( im * im ) ); + +#define IVAS_CALCULATE_RABS( re, out ) \ + out = sqrtf( re * re ); + +#define IVAS_CALCULATE_SQ_ABS( re, im, out ) \ + out = (float) ( ( re * re ) + ( im * im ) ); + +#define IVAS_RMULT_DOUBLE( in1_re, in2_re, out1_re ) \ + out1_re = ( in1_re * in2_re ); \ + +#define IVAS_CALCULATE_SQ_ABS_N( re, out ) \ + out = (float) ( re * re ); + +#define IVAS_RMULT_FLOAT( in1_re, in2_re, out1_re ) \ + out1_re = ( in1_re * in2_re ); + + +/* PCA */ +void ivas_pca_enc_init( + PCA_ENC_STATE *hPCA /* i/o: PCA encoder structure */ +); + +void ivas_pca_read_bits( + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ + PCA_DEC_STATE *hPCA /* i/o: PCA encoder structure */ +); + +void ivas_pca_dec_init( + PCA_DEC_STATE *hPCA /* i/o: PCA decoder structure */ +); + +void ivas_pca_dec( + PCA_DEC_STATE *hPCA, /* i/o: PCA decoder structure */ + const int16_t n_samples, /* i : output frame length */ + const int16_t n_channels, /* i : number of channels */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int32_t last_ivas_total_brate, /* i : last IVAS total bitrate */ + const int16_t bfi, /* i : bad frame indicator */ + float *pcm_out[] /* o : output audio channels */ +); + +void pca_dec_s3( + const int32_t index, + float *q +); + + +void ivas_huffman_encode_fx( + ivas_huffman_cfg_t *huff_cfg, + Word16 in, + Word16 *hcode, + Word16 *hlen +); + + + +ivas_error ivas_huffman_decode( + ivas_huffman_cfg_t *huff_cfg, + Decoder_State *st0, + int16_t *dec_out +); + +void ivas_arith_decode_cmplx_cell_array( + ivas_arith_t *pArith_re, + ivas_arith_t *pArith_re_diff, + Decoder_State *st0, + ivas_cell_dim_t *pCell_dims, + int16_t *pDo_diff, const int16_t nB, + int16_t *pSymbol_re, + int16_t *pSymbol_re_old +); + + + + +void ivas_ari_done_encoding_14bits( + BSTR_ENC_HANDLE hBstr, Tastat *s +); + + +void ivas_wrap_arround( + int16_t *pArr, + const int16_t min_val, + const int16_t max_val, + const int16_t length +); + +void ivas_get_cum_freq_model( + const int16_t *pFreq_model, + const int16_t length, + int16_t *pCum_freq_model +); + +int16_t ivas_map_num_pred_r_to_idx( + const int16_t num_quant_points_pred_r, + const int16_t active_w_flag +); + +int16_t ivas_map_num_drct_r_to_idx( + const int16_t num_quant_points_drct_r +); + +int16_t ivas_map_num_decd_r_to_idx( + const int16_t num_quant_points_decd_r +); + +/* Quantization utilities */ +void ivas_quantise_real_values( + const float *values, + const int16_t q_levels, + const float min_value, + const float max_value, + int16_t *index, + float *quant, + const int16_t dim +); + + +void ivas_spar_quant_dtx_init( + ivas_spar_md_t *spar_md, + float *min_max +); + +void ivas_map_prior_coeffs_quant( + ivas_spar_md_prev_t *pSpar_md_prior, + ivas_spar_md_com_cfg *pSpar_md_cfg, + const int16_t qsi, + const int16_t nB +); + + +void ivas_clear_band_coeffs( + ivas_band_coeffs_t *pband_coeffs, + const uint16_t num_bands +); + +void ivas_clear_band_coeff_idx( + ivas_band_coeffs_ind_t *pband_coeff_idx, + const uint16_t num_bands +); + + +/*----------------------------------------------------------------------------------* + * MASA prototypes + *----------------------------------------------------------------------------------*/ + +ivas_error ivas_masa_decode( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ + Decoder_State *st, /* i/o: decoder state structure */ + int16_t *nb_bits_read /* o : number of bits read */ +); + +void generate_gridEq( + SPHERICAL_GRID_DATA *data /* o : data structure for grid */ +); + +ivas_error ivas_masa_enc_open_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +); + +void ivas_masa_enc_close_fx( + MASA_ENCODER_HANDLE *hMasa /* i/o: MASA metadata structure */ +); + +void ivas_masa_enc_reconfigure( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +ivas_error ivas_masa_dec_reconfigure( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ + int16_t *data /* o : output synthesis signal */ +); + +ivas_error ivas_masa_encode( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + int16_t *nb_bits_metadata, /* o : number of metadata bits written */ + const int16_t nchan_transport, /* i : number of MASA input/transport channels */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t Opt_DTX_ON, /* i : DTX on flag */ + const int16_t element_mode, /* i : element mode */ + const ISM_MODE ism_mode, /* i : ISM format mode */ + const int16_t nchan_ism, /* i : number of ISM channels */ + ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ + const int16_t idx_separated_object, /* i : index of the separated object */ + OMASA_ENC_HANDLE hOMasa, /* i : OMASA encoder handle */ + const int16_t ism_imp, /* i : importance of separated object */ + const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ +); + +void ivas_masa_estimate_energy( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ + float *data_f[], /* i : Input audio channels */ + const int16_t input_frame, /* i : frame length */ + const int16_t nchan_transport /* i : number of MASA input/transport channels */ +); + + +void ivas_masa_set_elements( + const int32_t ivas_total_brate, /* i : codec total bitrate */ + const int16_t mc_mode, /* i : MC format mode */ + const int16_t nchan_transport, /* i : number of MASA input/transport channels */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + int16_t *element_mode, /* o : element mode */ + int16_t *nSCE, /* o : number of SCEs */ + int16_t *nCPE, /* o : number of CPEs */ + const int16_t ivas_format, /* i : IVAS format */ + const ISM_MODE ism_mode, /* i : ISM mode */ + const int32_t ism_total_brate /* i : initial ISM total bitrate */ +); + +/*! r: valid or not 1/0 */ +int16_t valid_ratio_index( + int16_t index, /* i : index to be checked */ + const int16_t K, /* i : L1 norm to check against */ + const int16_t len /* i : vector length */ +); + +void reconstruct_ism_ratios( + int16_t *ratio_ism_idx, + const int16_t nchan_ism, + const float step, + float *q_energy_ratio_ism +); + +void distribute_evenly_ism( + int16_t *idx, + const int16_t K, + const int16_t nchan_ism +); + + +int16_t ivas_qmetadata_encode_extended_gr_length_fx( + const uint16_t value, + const uint16_t alphabet_size, + const int16_t gr_param); + +void ivas_qmetadata_encode_extended_gr_fx( + BSTR_ENC_HANDLE hMetaData, /* i/o: q_metadata handle */ + const uint16_t value, /* i : value to be encoded */ + const uint16_t alphabet_size, /* i : alphabet size */ + const int16_t gr_param); /* i : GR order */ + +/*! r: CPE bitrate value */ +int32_t calculate_cpe_brate_MASA_ISM( + const ISM_MODE ism_mode, /* i : ism mode */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t nchan_ism /* i : number of objects */ +); + +void ivas_merge_masa_metadata( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA enc handle. source for MASA metadata and combined metadata will be here */ + OMASA_SPATIAL_META_HANDLE hOMasaMeta /* i : ISM-object metadata to be merged with the MASA metadata */ +); + + +/*!r : number of bits for ISM ratio index */ +int16_t bits_index_ism_ratio( + const int16_t nchan_ism /* i : number of objects */ +); + +void calculate_nbits_meta( + const int16_t nchan_ism, + float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + const int16_t numSf, + const int16_t numCodingBands, + int16_t* bits_ism, + const int16_t idx_sep_obj, + const int16_t ism_imp +); + +/*! r: limitation flag */ +int16_t calculate_brate_limit_flag( + const int16_t ism_imp[], /* i : ISM importance flags */ + const int16_t nchan_ism /* i : number of objects */ +); + +void ivas_masa_set_coding_config( + MASA_CODEC_CONFIG* config, /* i/o: MASA coding config structure */ + int16_t* band_mapping, /* o : Band mapping used */ + const int32_t ivas_total_brate, /* i : codec total bitrate */ + const int16_t nchan_transport, /* i : number of transport channel (mono/stereo) */ + const uint8_t isMcMasa /* i : toggle for selecting McMASA specific config */ +); + +/*! r: Surround coherence significant flag */ +uint8_t ivas_masa_surrcoh_signicant( + float surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence */ + float diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio */ + const int16_t nSubFrames, /* i : Number of sub frames */ + const int16_t nBands /* i : Number of frequency bands */ +); + +void masa_compensate_two_dir_energy_ratio_index( + const int16_t ratio_index_1, /* i : Input ratio for direction 1 */ + const int16_t ratio_index_2, /* i : Input ratio for direction 2 */ + int16_t *ratio_index_mod1, /* o : Output modified ratio for direction 1 */ + int16_t *ratio_index_mod2, /* o : Output modified ratio for direction 2 */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ +); + +void ivas_set_qmetadata_maxbit_req_fx( + IVAS_QMETADATA_HANDLE hQMetaData, /* o : qmetadata structure where the requirement value is set */ + const IVAS_FORMAT ivas_format /* i : IVAS format */ +); + +void masa_sample_rate_band_correction( + MASA_CODEC_CONFIG *config, /* i/o: MASA codec config */ + int16_t *band_mapping, /* i/o: Band mapping used and modified */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: QMetadata structure for modification */ + const uint8_t maxBand, /* i : max band */ + uint8_t is_encoder, /* i : signals if called at encoder */ + MASA_DECODER_EXT_OUT_META_HANDLE hExtOutMeta /* i/o: MASA decoder metadata ext out buffer */ +); + +void invdct4_transform( + float *v, /* i : input vector */ + uint8_t *invdct_v /* o : transformed vector */ +); + + +void ivas_spar_param_to_masa_param_mapping( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ + float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ + float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ + const int16_t subframe /* i : Subframe to map */ +); + +/*---------------------------------------------------------------------------------* + * Binaural FastConv Renderer Prototypes +*-----------------------------------------------------------------------------------*/ + + +void ivas_binaural_hrtf_close( + HRTFS_FASTCONV_HANDLE *hHrtfFastConv /* i/o: decoder binaural hrtf handle */ +); + +void ivas_binRenderer( + BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: binaural renderer handle */ + COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined head and external orientation handle */ + const int16_t numTimeSlots, /* i : number of time slots to process */ + float Cldfb_RealBuffer_Binaural[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ + float Cldfb_ImagBuffer_Binaural[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ + float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ + float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX] /* i : LS signals */ +); + +void ivas_binaural_add_LFE( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + int16_t output_frame, /* i : length of input frame */ + float *input_f[], /* i : transport channels */ + float *output_f[] /* o : synthesized core-coder transport channels/DirAC output */ +); + +/*----------------------------------------------------------------------------------* + * renderer prototypes + *----------------------------------------------------------------------------------*/ + +ivas_error ivas_ism_renderer_open( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +void ivas_ism_renderer_close( + ISM_RENDERER_HANDLE *hIsmRendererData /* i/o: ISM renderer handle */ +); + +void ivas_ism_render_sf( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output_f[], /* i/o: core-coder transport channels/object output */ + const int16_t n_samples_to_render /* i : output frame length per channel */ +); + + +void ivas_mc2sba( + IVAS_OUTPUT_SETUP hIntSetup, /* i : Format of decoder output */ + float *in_buffer_td[], /* i : MC signals (on input) and the HOA3 (on output) */ + float *buffer_td[], /* o : MC signals (on input) and the HOA3 (on output) */ + const int16_t output_frame, /* i : output frame length per channel */ + const int16_t sba_order, /* i : SBA order */ + const float gain_lfe /* i : gain for LFE, 0=ignore LFE */ +); + +void ivas_param_mc_mc2sba_cldfb( + IVAS_OUTPUT_SETUP hTransSetup, /* i : transported MC Format */ + float *hoa_encoder, /* i : HOA3 encoder for the transported MC format */ + const int16_t slot_idx, /* i : current slot in the subframe */ + float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) */ + float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) */ + const int16_t nBands, /* i : number of synth CLDFB bands */ + const float gain_lfe /* i : gain applied to LFE */ +); + + +/*----------------------------------------------------------------------------------* + * Amplitude Panning VBAP prototypes + *----------------------------------------------------------------------------------*/ + +void panning_wrap_angles( + const float azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ + const float ele_deg, /* i : elevation in degrees for panning direction (positive up) */ + float *azi_wrapped, /* o : wrapped azimuth component */ + float *ele_wrapped /* o : wrapped elevation component */ +); + +/*----------------------------------------------------------------------------------* + * LS Renderer prototypes + *----------------------------------------------------------------------------------*/ + +ivas_error ivas_ls_setup_conversion_open( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +void ivas_ls_setup_conversion_close( + LSSETUP_CONVERSION_HANDLE *hLsSetUpConversion /* i/o: LS converter handle */ +); + + +void ivas_ls_setup_conversion( + Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ + const int16_t input_chans, /* i : number of input channels to the renderer */ + const int16_t output_frame, /* i : frame length */ + float *input[], /* i : LS input/output synthesis signal */ + float *output[] /* i/o: LS input/output synthesis signal */ +); + +void ivas_ls_setup_conversion_process_mdct( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output[] /* i/o: output synthesis signal */ +); + +void ivas_ls_setup_conversion_process_mdct_param_mc( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *x[][NB_DIV] /* i/o: output synthesis signal */ +); + +void ivas_lssetupconversion_process_param_mc( + Decoder_Struct *st_ivas, /* i/o: LS setup conversion renderer handle */ + const int16_t num_timeslots, /* i : number of time slots to process */ + float Cldfb_RealBuffer_InOut[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i/o: LS signals */ + float Cldfb_ImagBuffer_InOut[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i/o: LS signals */ + int16_t channel_active[MAX_CICP_CHANNELS] /* i : bitmap indicating which output channels are active */ +); + + +/*----------------------------------------------------------------------------------* + * Custom loudspeaker setup prototypes + *----------------------------------------------------------------------------------*/ + +ivas_error ivas_ls_custom_open( + LSSETUP_CUSTOM_HANDLE *hLsSetupCustom /* o : Custom loudspeaker setup handle */ +); + + + +/*----------------------------------------------------------------------------------* + * McMASA prototypes + *----------------------------------------------------------------------------------*/ + + +ivas_error ivas_mcmasa_dec_reconfig( + Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ +); + +void ivas_mcmasa_setNumTransportChannels( + int16_t* nchan_transport, /* o : Pointer to number of transport channels to be set */ + int16_t* element_mode, /* o : Pointer to element mode to be set */ + const int32_t ivas_total_brate /* i : Total bitrate of IVAS */ +); + +void ivas_mcmasa_set_separate_channel_mode( + uint8_t *separateChannelEnabled, /* o : Pointer to separate channel toggle */ + int16_t *separateChannelIndex, /* o : Pointer to separate channel index */ + const int32_t ivas_total_brate /* i : Total bitrate of IVAS */ +); + +void ivas_mcmasa_split_brate( + const uint8_t separateChannelEnabled, /* i : Transport running in "separate channel" mode */ + const int32_t ivas_total_brate, /* i : Total bitrate available to be split */ + const int16_t nSCE, /* i : Number of SCEs in use (0 or 1) */ + const int16_t nCPE, /* i : Number of CPEs in use (0 or 1) */ + int32_t *brate_sce, /* o : Pointer to SCE element bitrate */ + int32_t *brate_cpe /* o : Pointer to CPE element bitrate */ +); + + +void ivas_mcmasa_dmx_modify_fx( + const Word16 n_samples, /* i : input frame length in samples */ + Word32 dmx_fx[][L_FRAME48k + NS2SA(48000, IVAS_FB_ENC_DELAY_NS)], /* i/o: downmix signal to be transformed into another format Qx*/ + Word16 dmx_Q[], /* i/o : Q of the intput signal which is being transformed*/ + const Word16 n_chnls_dmx_old, /* i : number of downmix channels in the old format Q0 */ + const Word16 n_chnls_dmx_new /* i : number of downmix channels in the target format Q0*/ +); + +ivas_error ivas_mono_dmx_renderer_open( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + + +void ivas_mono_dmx_renderer_close( + MONO_DOWNMIX_RENDERER_HANDLE *hMonoDmxRenderer /* i/ i/o: Mono downmix structure */ +); + +void ivas_mono_downmix_render_passive( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output_f[], /* i/o: synthesized core-coder transport channels/mono output */ + const int16_t output_frame /* i : output frame length */ +); + + +/*----------------------------------------------------------------------------------* + * LFE encoder low pass filter prototypes + *----------------------------------------------------------------------------------*/ + +ivas_error ivas_create_lfe_lpf_enc( + ivas_filters_process_state_t **hLfeLpf, /* o : LFE LPF handle */ + const int32_t input_Fs /* i : input sampling rate */ +); + +void ivas_lfe_lpf_enc_close_fx( + ivas_filters_process_state_t **hLfeLpf /* i/o: LFE LPF handle */ +); + +void ivas_lfe_lpf_enc_apply( + ivas_filters_process_state_t *hLfeLpf, /* i/o: LFE LPF handle */ + float data_lfe_ch[], /* i/o: LFE signal */ + const int16_t input_frame /* i : input frame length per channel */ +); + + +/*----------------------------------------------------------------------------------* + * LFE Coding prototypes + *----------------------------------------------------------------------------------*/ + +ivas_error ivas_create_lfe_enc_fx( + LFE_ENC_HANDLE *hLFE, /* o : IVAS LFE encoder structure */ + const int32_t input_Fs /* i : input sampling rate */ +); + +void ivas_lfe_enc_close_fx( + LFE_ENC_HANDLE *hLFE /* i/o: LFE encoder handle */ +); + +void ivas_lfe_enc( + LFE_ENC_HANDLE hLFE, /* i/o: LFE encoder handle */ + float data_lfe_ch[], /* i : input LFE signal */ + const int16_t input_frame, /* i : input frame length per channel */ + BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ +); + +void ivas_lfe_tdplc( + LFE_DEC_HANDLE hLFE, /* i/o: LFE decoder handle */ + float *prevsynth, /* i : previous frame synthesis */ + float *ytda, /* o : output time-domain buffer */ + const int16_t output_frame /* i : output frame length */ +); +void ivas_lfe_window_init( + LFE_WINDOW_HANDLE hLFEWindow, /* i/o: LFE window handle */ + const int32_t sampling_rate, /* i : sampling rate */ + const int16_t frame_len /* i : frame length in samples */ +); + +void ivas_lfe_lpf_select_filt_coeff( + const int32_t sampling_rate, /* i : sampling rate */ + const int16_t order, /* i : filter order */ + const float **ppFilt_coeff /* o : filter coefficients */ +); + +void ivas_filters_init( + ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ + const float *filt_coeff, /* i : filter coefficients */ + const int16_t order /* i : filter order */ +); + +void ivas_filters_init_fx( + ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ + const Word32 *filt_coeff_fx, /* i : filter coefficients Q31- *filt_coeff_e */ + const Word16 *filt_coeff_e, /* i : exponents of filter coefficients */ + const Word16 order ) ; + +void ivas_filter_process( + ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ + float *pIn_Out, /* i : signal subject to filtering */ + const int16_t length /* i : filter order */ +); + +void ivas_filter_process_fx( + ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ + Word32 *pIn_Out_fx, /* i/o: signal subject to filtering Q(q_factor) */ + const Word16 length, /* i : filter order */ + Word16 q_factor ); + +/*----------------------------------------------------------------------------------* + * OSBA prototypes + *----------------------------------------------------------------------------------*/ +ivas_error ivas_osba_enc_reconfig( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); +ivas_error ivas_osba_data_open( + Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ +); + +ivas_error ivas_osba_dirac_td_binaural_jbm( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ + uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */ + uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + float *output_f[] /* o : rendered time signal */ +); + + +void ivas_osba_data_close( + SBA_ISM_DATA_HANDLE *hSbaIsmData /* i/o: OSBA rendering handle */ +); + + +/*----------------------------------------------------------------------------------* +* OMASA prototypes +*---------------------------------------------------------------------------------*/ + +ivas_error ivas_omasa_enc_open( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +); + +void ivas_omasa_enc_close( + OMASA_ENC_HANDLE *hOMasa /* i/o: encoder OMASA handle */ +); + + +ivas_error ivas_omasa_dec_config( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ + int16_t *data /* o : output synthesis signal */ +); + + + + +void ivas_set_surplus_brate_enc( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +#ifdef DEBUG_MODE_INFO + , + const int16_t *nb_bits_metadata /* i : number of metadata bits */ +#endif +); + +void ivas_set_surplus_brate_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + int32_t *ism_total_brate /* i : ISM total bitrate */ +); + + +void ivas_set_ism_importance_interformat( + const int32_t ism_total_brate, /* i/o: ISms total bitrate */ + const int16_t nchan_transport, /* i : number of transported channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + const float lp_noise_CPE, /* i : LP filtered total noise estimation */ + int16_t ism_imp[] /* o : ISM importance flags */ +); + + +/*! r: adjusted bitrate */ +int32_t ivas_interformat_brate( + const ISM_MODE ism_mode, /* i : ISM mode */ + const int16_t nchan_ism, /* i : number of ISM channels */ + const int32_t element_brate, /* i : element bitrate */ + const int16_t ism_imp, /* i : ISM importance flag */ + const int16_t limit_flag /* i : flag to limit the bitrate increase */ +); + +void ivas_combined_format_brate_sanity( + const int32_t element_brate, /* i : element bitrate */ + const int16_t core, /* i : core */ + const int32_t total_brate, /* i : total bitrate */ + int32_t *core_brate, /* i/o: core bitrate */ + int16_t *inactive_coder_type_flag, /* o : inactive coder_type flag */ + int16_t *diff_nBits /* o : number of differential bits */ +); + +ISM_MODE ivas_omasa_ism_mode_select( + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t nchan_ism /* i : number of input ISM's */ +); + +void ivas_set_omasa_TC( + const ISM_MODE ism_mode, /* i : ISM mode */ + const int16_t nchan_ism, /* i : number of input ISMs */ + int16_t *nSCE, /* o : number of SCEs */ + int16_t *nCPE /* o : number of CPEs */ +); + +void ivas_merge_masa_transports( + float data_in_f1[][L_FRAME48k], /* i : Transport audio signals 1 */ + float *data_in_f2[], /* i : Transport audio signals 2 */ + float *data_out_f[], /* o : Merged transport audio signals */ + const int16_t input_frame, /* i : Input frame size */ + const int16_t num_transport_channels /* i : Number of transport audio signals */ +); + + +ivas_error ivas_omasa_ism_metadata_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int32_t ism_total_brate, /* i : ISM total bitrate */ + int16_t *nchan_ism, /* o : number of ISM separated channels */ + int16_t *nchan_transport_ism, /* o : number of ISM TCs */ + const int16_t dirac_bs_md_write_idx, /* i : DirAC bitstream write index */ + int16_t nb_bits_metadata[] /* o : number of ISM metadata bits */ +); + +void ivas_omasa_preProcessStereoTransportsForMovedObjects( + Decoder_Struct *st_ivas, + float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + const int16_t nBins, + const int16_t subframe +); + +ivas_error ivas_omasa_separate_object_renderer_open( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +void ivas_omasa_separate_object_renderer_close( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +void ivas_omasa_separate_object_render_jbm( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const uint16_t nSamplesRendered, /* i : number of samples rendered */ + float input_f[][L_FRAME48k], /* i : separated object signal */ + float *output_f[], /* o : rendered time signal */ + const int16_t subframes_rendered, /* i : number of subframes rendered */ + const int16_t slots_rendered /* i : number of CLDFB slots rendered */ +); + +void ivas_omasa_encode_masa_to_total( + float masa_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + BSTR_ENC_HANDLE hMetaData, + const int16_t low_bitrate_mode, + const int16_t nbands, + const int16_t nblocks +); + +void ivas_omasa_decode_masa_to_total( + uint16_t *bit_stream, + int16_t *index, + float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + const int16_t nbands, + const int16_t nblocks +); + +void ivas_omasa_modify_masa_energy_ratios( + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_MAXIMUM_CODING_SUBBANDS] +); + + +/*----------------------------------------------------------------------------------* + * TD Binaural Object renderer + *----------------------------------------------------------------------------------*/ + +#ifndef FIX_910_REMOVE_DUPLICATION_TD_REND +ivas_error ivas_td_binaural_renderer( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output[], /* i/o: SCE channels / Binaural synthesis */ + const int16_t output_frame /* i : output frame length */ +); +#endif +ivas_error ivas_td_binaural_renderer_sf( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output[], /* i/o: SCE channels / Binaural synthesis */ + const int16_t n_samples_granularity /* i : granularity of the renderer/buffer */ +); + +/*----------------------------------------------------------------------------------* + * Filter-bank (FB) Mixer + *----------------------------------------------------------------------------------*/ + +ivas_error ivas_fb_set_cfg( + IVAS_FB_CFG **pFb_cfg_out, /* o : FB config. handle */ + const int16_t ivas_format, /* i : IVAS format */ + const int16_t num_in_chans, /* i : number of FB input channels */ + const int16_t num_out_chans, /* i : number of FB output channels */ + const int16_t active_w_mixing, /* i : active_w_mixing flag */ + const int32_t sampling_Fs, /* i : sampling rate */ + const int16_t nachan_dirac_ana /* i : number of DirAR analysis channels */ +); + +void ivas_fb_mixer_pcm_ingest( + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + float *pcm_in[], /* i : input audio channels */ + float **ppOut_pcm, /* o : output audio channels */ + const int16_t frame_length, /* i : frame length */ + const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] +); + +void ivas_fb_mixer_update_prior_input( + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + float *pcm_in[], /* i : input audio channels */ + const int16_t length, /* i : length of time slot */ + const int16_t nchan_fb_in /* i : number of analysis channels */ +); + +void ivas_fb_mixer_get_windowed_fr( + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + float *pcm_in[], /* i : input audio channels */ + float *frame_f_real[], /* o : real freq domain values */ + float *frame_f_imag[], /* o : imag freq domain values */ + const int16_t length, /* i : number of new samples in time slot */ + const int16_t mdft_len, /* i : MDFT frame length */ + const int16_t nchan_fb_in /* i : number of analysis channels */ +); + +/*! r: number of spectral bands */ + +/* clang-format on */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index cf488d043701b0aa2f69a79231be11c84ef02129..e02b5a4de447e03645e0540fbb98f6b6a7b1389d 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -46,6 +46,12 @@ #include "ivas_stat_com.h" #include "ivas_error_utils.h" +/* clang-format off */ + +/*----------------------------------------------------------------------------------* + * General IVAS prototypes + *----------------------------------------------------------------------------------*/ + ivas_error ivas_masa_dec_open_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ); @@ -165,11 +171,6 @@ ivas_error ivas_omasa_dec_config_fx( Word16 SrcInd[MAX_NUM_TDREND_CHANNELS], Word16 *data /* o : output synthesis signal */ ); -ivas_error ivas_td_binaural_renderer_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis */ - const Word16 n_samples_granularity /* i : granularity of the renderer/buffer */ -); void ivas_omasa_modify_masa_energy_ratios_fx( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ @@ -3893,16 +3894,33 @@ void ivas_omasa_decode_masa_to_total_fx( const Word16 nblocks ); -ivas_error ivas_td_binaural_open_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word16 *SrcInd, /*Temporarily used to store the updated value of SrcInd*/ - Word16 *num_src ); +/*----------------------------------------------------------------------------------* + * TD Binaural Object renderer + *----------------------------------------------------------------------------------*/ +ivas_error ivas_td_binaural_open_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word16 *SrcInd, /*Temporarily used to store the updated value of SrcInd*/ + Word16 *num_src +); +#ifndef FIX_910_REMOVE_DUPLICATION_TD_REND ivas_error ivas_td_binaural_renderer_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ Word32 *output[], /* i/o: SCE channels / Binaural synthesis */ const Word16 output_frame /* i : output frame length */ ); +#endif + +ivas_error ivas_td_binaural_renderer_sf_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis */ + const Word16 n_samples_granularity /* i : granularity of the renderer/buffer */ +); + + +/*----------------------------------------------------------------------------------* + * Filter-bank (FB) Mixer + *----------------------------------------------------------------------------------*/ void ivas_FB_mixer_close_fx( IVAS_FB_MIXER_HANDLE *hFbMixer, /* i/o: FB mixer handle */ diff --git a/lib_com/options.h b/lib_com/options.h old mode 100755 new mode 100644 index 8848cb0872e0d84d55577f924c31b776c4876b8b..82f5d7c6c0876b57d1051da0207000cb1e73efb0 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -191,6 +191,7 @@ #define NONBE_FIX_1058_DECODER_ERROR_WITH_REVERB_ROOM /* FhG: issue 1058: do not initialize EFAP when IntSetup is HOA3 */ #define NONBE_FIX_907_VLBR_DIRAC_BAND_MAPPING /* Dlb: issue 907: fix for band mapping at VLBR */ #define NONBE_FIX_869_MASA_PREREND_MERGE /* Nokia: issue: #869: MASA pre-rend not updating energy */ +#define FIX_910_REMOVE_DUPLICATION_TD_REND /* VA: issue 910: remove duplication of function ivas_td_binaural_renderer() */ /* #################### End BASOP porting switches ############################ */ diff --git a/lib_dec/ivas_jbm_dec_fx.c b/lib_dec/ivas_jbm_dec_fx.c index e62ff3fdde88cd5f4a27b5d46f3fe412c83f3a88..119f0aacedfac05b9431707fc58ced7f202dfc13 100644 --- a/lib_dec/ivas_jbm_dec_fx.c +++ b/lib_dec/ivas_jbm_dec_fx.c @@ -2495,6 +2495,7 @@ ivas_error ivas_jbm_dec_render_fx( { ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 ); } +#ifndef FIX_910_REMOVE_DUPLICATION_TD_REND ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) { IF( NE_32( ( error = ivas_td_binaural_renderer_fx( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) ) @@ -2504,6 +2505,7 @@ ivas_error ivas_jbm_dec_render_fx( ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_output_fx, p_output_fx ); } +#endif } ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { @@ -3417,11 +3419,11 @@ Word16 ivas_jbm_dec_get_num_tc_channels_fx( move16(); } - test(); - test(); #ifdef NONBE_FIX_926_OSBA_DECODER_CRASH_PLANAR_SBA if ( EQ_16( num_tc, 3 ) ) #else + test(); + test(); if ( ( st_ivas->sba_planar && GE_16( num_tc, 3 ) ) || EQ_16( num_tc, 3 ) ) #endif { diff --git a/lib_dec/ivas_objectRenderer_internal_fx.c b/lib_dec/ivas_objectRenderer_internal_fx.c index 9a836574ab7c1cacdb3466dc65b70e99c31869e9..a13358597d6ca6ab6b678c34eea8bf4a5de23dc3 100644 --- a/lib_dec/ivas_objectRenderer_internal_fx.c +++ b/lib_dec/ivas_objectRenderer_internal_fx.c @@ -62,7 +62,7 @@ ivas_error ivas_td_binaural_open_fx( return ivas_td_binaural_open_unwrap_fx( &st_ivas->hHrtfTD, st_ivas->hDecoderConfig->output_Fs, *num_src, st_ivas->ivas_format, st_ivas->transport_config, st_ivas->hRenderConfig->directivity_fx, st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns, SrcInd ); } - +#ifndef FIX_910_REMOVE_DUPLICATION_TD_REND /*---------------------------------------------------------------------* * ivas_td_binaural_renderer() * @@ -106,7 +106,7 @@ ivas_error ivas_td_binaural_renderer_fx( } return ivas_td_binaural_renderer_unwrap_fx( st_ivas->hReverb, st_ivas->transport_config, st_ivas->hBinRendererTd, nchan_transport, LFE_CHANNEL, st_ivas->ivas_format, st_ivas->hIsmMetaData, st_ivas->hCombinedOrientationData, ism_md_subframe_update, output, output_frame, MAX_PARAM_SPATIAL_SUBFRAMES ); } - +#endif /*---------------------------------------------------------------------* * ivas_td_binaural_renderer_sf() diff --git a/lib_dec/ivas_output_config_fx.c b/lib_dec/ivas_output_config_fx.c index c98a9514e805c562381b02b911cabe68665652c4..ca6a9a700cb86b655c3a57be42c7127b6da6fb4d 100644 --- a/lib_dec/ivas_output_config_fx.c +++ b/lib_dec/ivas_output_config_fx.c @@ -247,8 +247,12 @@ void ivas_renderer_select( test(); test(); test(); +#ifdef FIX_910_REMOVE_DUPLICATION_TD_REND + IF( ( EQ_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_7_1 ) ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) +#else test(); IF( ( EQ_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_7_1 ) ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && ( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) ) +#endif { *renderer_type = RENDERER_BINAURAL_OBJECTS_TD; move16();