1 /****************************************************************************** 2 * * 3 * Copyright (C) 2018 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ***************************************************************************** 18 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore 19 */ 20 #ifndef IXHEAACD_SBR_DEC_H 21 #define IXHEAACD_SBR_DEC_H 22 23 #include <setjmp.h> 24 25 typedef struct { 26 WORD32 x_over_qmf[MAX_NUM_PATCHES]; 27 WORD32 max_stretch; 28 WORD32 core_frame_length; 29 WORD32 hbe_qmf_in_len; 30 WORD32 hbe_qmf_out_len; 31 WORD32 no_bins; 32 WORD32 start_band; 33 WORD32 end_band; 34 WORD32 upsamp_4_flag; 35 WORD32 synth_buf_offset; 36 37 FLOAT32 *ptr_input_buf; 38 39 FLOAT32 **qmf_in_buf; 40 FLOAT32 **qmf_out_buf; 41 42 WORD32 k_start; 43 WORD32 synth_size; 44 FLOAT32 synth_buf[1280]; 45 FLOAT32 analy_buf[640]; 46 FLOAT32 *synth_wind_coeff; 47 FLOAT32 *analy_wind_coeff; 48 49 FLOAT32 *synth_cos_tab; 50 FLOAT32 *analy_cos_sin_tab; 51 52 FLOAT32 norm_qmf_in_buf[46][128]; 53 VOID (*ixheaacd_real_synth_fft)(FLOAT32 *inp, FLOAT32 *out, WORD32 n_points); 54 55 VOID (*ixheaacd_cmplx_anal_fft)(FLOAT32 *inp, FLOAT32 *out, WORD32 n_points); 56 57 } ia_esbr_hbe_txposer_struct; 58 59 typedef struct { 60 WORD32 *ptr_sbr_overlap_buf; 61 WORD32 **drc_factors_sbr; 62 ia_sbr_qmf_filter_bank_struct str_codec_qmf_bank; 63 ia_sbr_qmf_filter_bank_struct str_synthesis_qmf_bank; 64 ia_sbr_calc_env_struct str_sbr_calc_env; 65 ia_sbr_hf_generator_struct str_hf_generator; 66 67 ia_sbr_scale_fact_struct str_sbr_scale_fact; 68 69 WORD32 max_samp_val; 70 ia_esbr_hbe_txposer_struct *p_hbe_txposer; 71 72 FLOAT32 core_sample_buf[2624]; 73 FLOAT32 ph_vocod_qmf_real[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS]; 74 FLOAT32 ph_vocod_qmf_imag[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS]; 75 FLOAT32 sbr_qmf_out_real[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS]; 76 FLOAT32 sbr_qmf_out_imag[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS]; 77 FLOAT32 qmf_buf_real[TIMESLOT_BUFFER_SIZE + 2 * 32][NO_QMF_SYNTH_CHANNELS]; 78 FLOAT32 qmf_buf_imag[TIMESLOT_BUFFER_SIZE + 2 * 32][NO_QMF_SYNTH_CHANNELS]; 79 80 FLOAT32 mps_qmf_buf_real[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS]; 81 FLOAT32 mps_qmf_buf_imag[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS]; 82 FLOAT32 mps_sbr_qmf_buf_real[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS]; 83 FLOAT32 mps_sbr_qmf_buf_imag[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS]; 84 85 WORD32 sbr_scratch_local[256]; 86 FLOAT32 scratch_buff[320]; 87 88 FLOAT32 qmf_energy_buf[64][32]; 89 FLOAT32 pvc_qmf_enrg_arr[16 * 32]; 90 91 FLOAT32 **pp_qmf_buf_real; 92 FLOAT32 **pp_qmf_buf_imag; 93 94 FLOAT32 *time_sample_buf; 95 } ia_sbr_dec_struct; 96 97 typedef struct { 98 ia_sbr_prev_frame_data_struct *pstr_prev_frame_data; 99 ia_sbr_dec_struct str_sbr_dec; 100 WORD32 output_frame_size; 101 WORD32 sync_state; 102 } ia_sbr_channel_struct; 103 104 struct ia_sbr_dec_inst_struct { 105 ia_ps_dec_struct *pstr_ps_stereo_dec; 106 FLAG ps_present; 107 ia_sbr_channel_struct *pstr_sbr_channel[MAXNRSBRCHANNELS]; 108 ia_sbr_header_data_struct *pstr_sbr_header[MAXNRSBRCHANNELS]; 109 ia_freq_band_data_struct *pstr_freq_band_data[MAXNRSBRCHANNELS]; 110 ia_sbr_tables_struct *pstr_sbr_tables; 111 ixheaacd_misc_tables *pstr_common_tables; 112 ia_pvc_data_struct *ptr_pvc_data_str; 113 VOID *hbe_txposer_buffers; 114 FLOAT32 *time_sample_buf[MAXNRSBRCHANNELS]; 115 VOID *scratch_mem_v; 116 VOID *frame_buffer[2]; 117 ia_sbr_header_data_struct str_sbr_dflt_header; 118 FLAG stereo_config_idx; 119 FLAG usac_independency_flag; 120 FLAG pvc_flag; 121 FLAG hbe_flag; 122 FLAG sbr_mode; 123 FLAG prev_sbr_mode; 124 FLAG inter_tes_flag; 125 FLAG aot_usac_flag; 126 jmp_buf *xaac_jmp_buf; 127 }; 128 129 typedef struct ia_sbr_pers_struct { 130 WORD16 *sbr_qmf_analy_states; 131 132 WORD32 *sbr_qmf_analy_states_32; 133 134 WORD16 *sbr_qmf_synth_states; 135 136 WORD32 *sbr_qmf_synth_states_32; 137 138 WORD32 **sbr_lpc_filter_states_real[MAXNRSBRCHANNELS]; 139 140 WORD32 **sbr_lpc_filter_states_imag[MAXNRSBRCHANNELS]; 141 142 WORD32 *ptr_sbr_overlap_buf[MAXNRSBRCHANNELS]; 143 144 struct ia_sbr_dec_inst_struct str_sbr_dec_inst; 145 146 ia_transposer_settings_struct str_sbr_tran_settings; 147 148 WORD16 *sbr_smooth_gain_buf[MAXNRSBRCHANNELS]; 149 150 WORD16 *sbr_smooth_noise_buf[MAXNRSBRCHANNELS]; 151 152 ia_sbr_prev_frame_data_struct *pstr_prev_frame_data[MAXNRSBRCHANNELS]; 153 154 } ia_sbr_pers_struct; 155 156 WORD32 ixheaacd_sbr_dec(ia_sbr_dec_struct *ptr_sbr_dec, WORD16 *ptr_time_data, 157 ia_sbr_header_data_struct *ptr_header_data, 158 ia_sbr_frame_info_data_struct *ptr_frame_data, 159 ia_sbr_prev_frame_data_struct *ptr_frame_data_prev, 160 ia_ps_dec_struct *ptr_ps_dec, 161 ia_sbr_qmf_filter_bank_struct *ptr_qmf_synth_bank_r, 162 ia_sbr_scale_fact_struct *ptr_sbr_sf_r, 163 FLAG apply_processing, FLAG low_pow_flag, 164 WORD32 *ptr_work_buf_core, 165 ia_sbr_tables_struct *sbr_tables_ptr, 166 ixheaacd_misc_tables *pstr_common_tables, WORD ch_fac, 167 ia_pvc_data_struct *ptr_pvc_data_str, FLAG drc_on, 168 WORD32 drc_sbr_factors[][64], WORD32 audio_object_type); 169 170 WORD16 ixheaacd_create_sbrdec(ixheaacd_misc_tables *pstr_common_table, 171 ia_sbr_channel_struct *ptr_sbr_channel, 172 ia_sbr_header_data_struct *ptr_header_data, 173 WORD16 chan, FLAG down_sample_flag, 174 VOID *sbr_persistent_mem_v, WORD ps_enable, 175 WORD audio_object_type); 176 177 #define MAX_NUM_QMF_BANDS_ESBR 128 178 179 WORD32 ixheaacd_sbr_dec_from_mps(FLOAT32 *p_mps_qmf_output, VOID *p_sbr_dec, 180 VOID *p_sbr_frame, VOID *p_sbr_header); 181 182 WORD32 ixheaacd_qmf_hbe_apply(ia_esbr_hbe_txposer_struct *h_hbe_txposer, 183 FLOAT32 qmf_buf_real[][64], 184 FLOAT32 qmf_buf_imag[][64], WORD32 num_columns, 185 FLOAT32 pv_qmf_buf_real[][64], 186 FLOAT32 pv_qmf_buf_imag[][64], 187 WORD32 pitch_in_bins); 188 189 WORD32 ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data, 190 FLOAT32 input_real[][64], FLOAT32 input_imag[][64], 191 FLOAT32 input_real1[][64], 192 FLOAT32 input_imag1[][64], 193 WORD32 x_over_qmf[MAX_NUM_PATCHES], 194 FLOAT32 *scratch_buff, FLOAT32 *env_out); 195 196 WORD32 ixheaacd_generate_hf(FLOAT32 ptr_src_buf_real[][64], 197 FLOAT32 ptr_src_buf_imag[][64], 198 FLOAT32 ptr_ph_vocod_buf_real[][64], 199 FLOAT32 ptr_ph_vocod_buf_imag[][64], 200 FLOAT32 ptr_dst_buf_real[][64], 201 FLOAT32 ptr_dst_buf_imag[][64], 202 ia_sbr_frame_info_data_struct *ptr_frame_data, 203 ia_sbr_header_data_struct *ptr_header_data); 204 205 VOID ixheaacd_clr_subsamples(WORD32 *ptr_qmf_buf, WORD32 num, WORD32 size); 206 207 VOID ixheaacd_rescale_x_overlap( 208 ia_sbr_dec_struct *ptr_sbr_dec, ia_sbr_header_data_struct *ptr_header_data, 209 ia_sbr_frame_info_data_struct *ptr_frame_data, 210 ia_sbr_prev_frame_data_struct *ptr_frame_data_prev, 211 WORD32 **pp_overlap_buffer_real, WORD32 **pp_overlap_buffer_imag, 212 FLAG low_pow_flag); 213 214 WORD32 ixheaacd_qmf_hbe_data_reinit( 215 ia_esbr_hbe_txposer_struct *ptr_hbe_transposer_str, 216 WORD16 *ptr_freq_band_tbl[MAX_FREQ_COEFFS + 1], WORD16 *ptr_num_sf_bands, 217 WORD32 upsamp_4_flag); 218 219 WORD32 ixheaacd_sbr_read_pvc_sce(ia_sbr_frame_info_data_struct *ptr_frame_data, 220 ia_bit_buf_struct *it_bit_buff, 221 WORD32 hbe_flag, 222 ia_pvc_data_struct *ptr_pvc_data, 223 ia_sbr_tables_struct *sbr_tables_ptr, 224 ia_sbr_header_data_struct *ptr_header_data); 225 226 WORD32 ixheaacd_qmf_hbe_apply(ia_esbr_hbe_txposer_struct *h_hbe_txposer, 227 FLOAT32 qmf_buf_real[][64], 228 FLOAT32 qmf_buf_imag[][64], WORD32 num_columns, 229 FLOAT32 pv_qmf_buf_real[][64], 230 FLOAT32 pv_qmf_buf_imag[][64], 231 WORD32 pitch_in_bins); 232 233 WORD32 ixheaacd_esbr_dec(ia_sbr_dec_struct *ptr_sbr_dec, 234 ia_sbr_header_data_struct *ptr_header_data, 235 ia_sbr_frame_info_data_struct *ptr_frame_data, 236 FLAG apply_processing, FLAG low_pow_flag, 237 ia_sbr_tables_struct *sbr_tables_ptr, WORD32 ch_fac); 238 239 VOID ixheaacd_hbe_repl_spec(WORD32 x_over_qmf[MAX_NUM_PATCHES], 240 FLOAT32 qmf_buf_real[][64], 241 FLOAT32 qmf_buf_imag[][64], WORD32 no_bins, 242 WORD32 max_stretch); 243 244 #endif 245