• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   FLOAT32 real[64][128];
27   FLOAT32 imag[64][128];
28 } ia_dft_hbe_anal_coeff;
29 
30 typedef struct {
31   WORD32 x_over_qmf[MAX_NUM_PATCHES];
32   WORD32 max_stretch;
33   WORD32 core_frame_length;
34   WORD32 hbe_qmf_in_len;
35   WORD32 hbe_qmf_out_len;
36   WORD32 no_bins;
37   WORD32 start_band;
38   WORD32 end_band;
39   WORD32 upsamp_4_flag;
40   WORD32 synth_buf_offset;
41 
42   FLOAT32 *ptr_input_buf;
43 
44   FLOAT32 **qmf_in_buf;
45   FLOAT32 **qmf_out_buf;
46 
47   WORD32 k_start;
48   WORD32 synth_size;
49   FLOAT32 synth_buf[1280];
50   FLOAT32 analy_buf[640];
51   FLOAT32 *synth_wind_coeff;
52   FLOAT32 *analy_wind_coeff;
53 
54   FLOAT32 *synth_cos_tab;
55   FLOAT32 *analy_cos_sin_tab;
56 
57   FLOAT32 norm_qmf_in_buf[46][128];
58   VOID (*ixheaacd_real_synth_fft)(FLOAT32 *inp, FLOAT32 *out, WORD32 n_points);
59 
60   VOID (*ixheaacd_cmplx_anal_fft)(FLOAT32 *inp, FLOAT32 *out, WORD32 n_points);
61 
62   WORD32 esbr_hq;
63   WORD32 in_hop_size;
64   WORD32 fft_size[2];
65 
66   FLOAT32 *anal_window;
67   FLOAT32 *synth_window;
68 
69   FLOAT32 *ptr_spectrum;
70   FLOAT32 *ptr_spectrum_tx;
71   FLOAT32 *mag;
72   FLOAT32 *phase;
73   FLOAT32 *ptr_output_buf;
74   WORD32 ana_fft_size[2];
75   WORD32 syn_fft_size[2];
76   WORD32 out_hop_size;
77   WORD32 analy_size;
78   WORD32 x_over_bin[MAX_STRETCH][2];
79   WORD32 a_start;
80 
81   FLOAT32 spectrum_buf[1536];
82   FLOAT32 spectrum_transposed_buf[1536];
83   FLOAT32 mag_buf[1536];
84   FLOAT32 phase_buf[1536];
85   FLOAT32 output_buf[4096];
86   FLOAT32 fd_win_buf[3][3][1536];
87 
88   FLOAT32 analysis_window_buf[1024];
89   FLOAT32 synthesis_window_buf[1024];
90 
91   WORD32 oversampling_flag;
92   ia_dft_hbe_anal_coeff str_dft_hbe_anal_coeff;
93   VOID (*ixheaacd_hbe_anal_fft)(FLOAT32 *inp, FLOAT32 *scratch, WORD32 len, WORD32 sign);
94   VOID (*ixheaacd_hbe_synth_ifft)(FLOAT32 *inp, FLOAT32 *scratch, WORD32 len, WORD32 sign);
95   FLOAT32 *syn_cos_sin_tab;
96   FLOAT32 *ana_cos_sin_tab;
97 
98 } ia_esbr_hbe_txposer_struct;
99 
100 typedef struct {
101   WORD32 *ptr_sbr_overlap_buf;
102   WORD32 **drc_factors_sbr;
103   ia_sbr_qmf_filter_bank_struct str_codec_qmf_bank;
104   ia_sbr_qmf_filter_bank_struct str_synthesis_qmf_bank;
105   ia_sbr_calc_env_struct str_sbr_calc_env;
106   ia_sbr_hf_generator_struct str_hf_generator;
107 
108   ia_sbr_scale_fact_struct str_sbr_scale_fact;
109 
110   WORD32 max_samp_val;
111   WORD32 band_count;
112   ia_esbr_hbe_txposer_struct *p_hbe_txposer;
113 
114   FLOAT32 core_sample_buf[2624];
115   FLOAT32 ph_vocod_qmf_real[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS];
116   FLOAT32 ph_vocod_qmf_imag[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS];
117   FLOAT32 sbr_qmf_out_real[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS];
118   FLOAT32 sbr_qmf_out_imag[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS];
119   FLOAT32 qmf_buf_real[TIMESLOT_BUFFER_SIZE + 2 * 32][NO_QMF_SYNTH_CHANNELS];
120   FLOAT32 qmf_buf_imag[TIMESLOT_BUFFER_SIZE + 2 * 32][NO_QMF_SYNTH_CHANNELS];
121 
122   FLOAT32 mps_qmf_buf_real[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS];
123   FLOAT32 mps_qmf_buf_imag[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS];
124   FLOAT32 mps_sbr_qmf_buf_real[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS];
125   FLOAT32 mps_sbr_qmf_buf_imag[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS];
126 
127   WORD32 sbr_scratch_local[256];
128   FLOAT32 scratch_buff[320];
129 
130   FLOAT32 qmf_energy_buf[64][32];
131   FLOAT32 pvc_qmf_enrg_arr[16 * 32];
132 
133   FLOAT32 **pp_qmf_buf_real;
134   FLOAT32 **pp_qmf_buf_imag;
135 
136   FLOAT32 *time_sample_buf;
137 } ia_sbr_dec_struct;
138 
139 typedef struct {
140   ia_sbr_prev_frame_data_struct *pstr_prev_frame_data;
141   ia_sbr_dec_struct str_sbr_dec;
142   WORD32 output_frame_size;
143   WORD32 sync_state;
144 } ia_sbr_channel_struct;
145 
146 struct ia_sbr_dec_inst_struct {
147   ia_ps_dec_struct *pstr_ps_stereo_dec;
148   ia_ps_dec_config_struct str_ps_config_prev;
149   FLAG ps_present;
150   ia_sbr_channel_struct *pstr_sbr_channel[MAXNRSBRCHANNELS];
151   ia_sbr_header_data_struct *pstr_sbr_header[MAXNRSBRCHANNELS];
152   ia_freq_band_data_struct *pstr_freq_band_data[MAXNRSBRCHANNELS];
153   ia_sbr_tables_struct *pstr_sbr_tables;
154   ixheaacd_misc_tables *pstr_common_tables;
155   ia_pvc_data_struct *ptr_pvc_data_str;
156   VOID *hbe_txposer_buffers;
157   FLOAT32 *time_sample_buf[MAXNRSBRCHANNELS];
158   VOID *scratch_mem_v;
159   VOID *frame_buffer[2];
160   ia_sbr_header_data_struct str_sbr_dflt_header;
161   FLAG stereo_config_idx;
162   FLAG usac_independency_flag;
163   FLAG pvc_flag;
164   FLAG hbe_flag;
165   FLAG sbr_mode;
166   FLAG prev_sbr_mode;
167   FLAG inter_tes_flag;
168   FLAG aot_usac_flag;
169   WORD32 band_count[MAXNRSBRCHANNELS];
170   jmp_buf *xaac_jmp_buf;
171   WORD8 *ptr_mps_data;
172   WORD32 left_mps_bits;
173   WORD32 mps_bits_pos;
174   FLAG esbr_hq;
175   FLAG enh_sbr;
176   FLAG enh_sbr_ps;
177   FLAG eld_sbr;
178   WORD32 num_delay_frames;
179   FLAG sbr_parse_err_flag;
180   FLAG frame_ok;
181   FLAG ec_flag;
182   FLAG first_frame;
183   FLAG prev_usac_independency_flag;
184   FLAG sbr_parse_complete;
185 };
186 
187 typedef struct ia_sbr_pers_struct {
188   WORD16 *sbr_qmf_analy_states;
189 
190   WORD32 *sbr_qmf_analy_states_32;
191 
192   WORD16 *sbr_qmf_synth_states;
193 
194   WORD32 *sbr_qmf_synth_states_32;
195 
196   WORD32 **sbr_lpc_filter_states_real[MAXNRSBRCHANNELS];
197 
198   WORD32 **sbr_lpc_filter_states_imag[MAXNRSBRCHANNELS];
199 
200   WORD32 *ptr_sbr_overlap_buf[MAXNRSBRCHANNELS];
201 
202   struct ia_sbr_dec_inst_struct str_sbr_dec_inst;
203 
204   ia_transposer_settings_struct str_sbr_tran_settings;
205 
206   WORD16 *sbr_smooth_gain_buf[MAXNRSBRCHANNELS];
207 
208   WORD16 *sbr_smooth_noise_buf[MAXNRSBRCHANNELS];
209 
210   ia_sbr_prev_frame_data_struct *pstr_prev_frame_data[MAXNRSBRCHANNELS];
211 
212 } ia_sbr_pers_struct;
213 
214 WORD32 ixheaacd_sbr_dec(
215     ia_sbr_dec_struct *ptr_sbr_dec, WORD16 *ptr_time_data,
216     ia_sbr_header_data_struct *ptr_header_data, ia_sbr_frame_info_data_struct *ptr_frame_data,
217     ia_sbr_prev_frame_data_struct *ptr_frame_data_prev, ia_ps_dec_struct *ptr_ps_dec,
218     ia_sbr_qmf_filter_bank_struct *ptr_qmf_synth_bank_r, ia_sbr_scale_fact_struct *ptr_sbr_sf_r,
219     FLAG apply_processing, FLAG low_pow_flag, WORD32 *ptr_work_buf_core,
220     ia_sbr_tables_struct *sbr_tables_ptr, ixheaacd_misc_tables *pstr_common_tables, WORD ch_fac,
221     ia_pvc_data_struct *ptr_pvc_data_str, FLAG drc_on, WORD32 drc_sbr_factors[][64],
222     WORD32 audio_object_type, WORD32 ldmps_present, VOID *self, WORD32 heaac_mps_present,
223     WORD32 ec_flag);
224 
225 WORD16 ixheaacd_create_sbrdec(ixheaacd_misc_tables *pstr_common_table,
226                               ia_sbr_channel_struct *ptr_sbr_channel,
227                               ia_sbr_header_data_struct *ptr_header_data,
228                               WORD16 chan, FLAG down_sample_flag,
229                               VOID *sbr_persistent_mem_v, WORD ps_enable,
230                               WORD audio_object_type, WORD32 ldmps_present,
231                               WORD32 ldsbr_present);
232 
233 #define MAX_NUM_QMF_BANDS_ESBR 128
234 
235 WORD32 ixheaacd_sbr_dec_from_mps(FLOAT32 *p_mps_qmf_output, VOID *p_sbr_dec, VOID *p_sbr_frame,
236                                  VOID *p_sbr_header, WORD32 ec_flag);
237 
238 WORD32 ixheaacd_qmf_hbe_apply(ia_esbr_hbe_txposer_struct *h_hbe_txposer,
239                               FLOAT32 qmf_buf_real[][64],
240                               FLOAT32 qmf_buf_imag[][64], WORD32 num_columns,
241                               FLOAT32 pv_qmf_buf_real[][64],
242                               FLOAT32 pv_qmf_buf_imag[][64],
243                               WORD32 pitch_in_bins,
244                               ia_sbr_header_data_struct *ptr_header_data);
245 
246 VOID ixheaacd_hbe_apply_cfftn(FLOAT32 re[], FLOAT32 *scratch, WORD32 n_pass, WORD32 i_sign);
247 
248 VOID ixheaacd_hbe_apply_cfftn_gen(FLOAT32 re[], FLOAT32 *scratch, WORD32 n_pass,
249                                   WORD32 i_sign);
250 
251 VOID ixheaacd_hbe_apply_fft_288(FLOAT32 *inp, FLOAT32 *scratch, WORD32 len, WORD32 i_sign);
252 
253 VOID ixheaacd_hbe_apply_ifft_224(FLOAT32 *inp, FLOAT32 *scratch, WORD32 len, WORD32 i_sign);
254 
255 VOID ixheaacd_hbe_apply_fft_3(FLOAT32 *inp, FLOAT32 *op, WORD32 i_sign);
256 
257 VOID ixheaacd_hbe_apply_ifft_7(FLOAT32 *inp, FLOAT32 *op);
258 
259 VOID ixheaacd_hbe_apply_ifft_336(FLOAT32 *inp, FLOAT32 *ptr_scratch, WORD32 len,
260                                  WORD32 i_sign);
261 
262 WORD32 ixheaacd_dft_hbe_apply(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer,
263                               FLOAT32 qmf_buf_real[][64],
264                               FLOAT32 qmf_buf_imag[][64], WORD32 num_columns,
265                               FLOAT32 pv_qmf_buf_real[][64],
266                               FLOAT32 pv_qmf_buf_imag[][64],
267                               WORD32 pitch_in_bins,
268                               FLOAT32 *dft_hbe_scratch_buf);
269 
270 WORD32 ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data, FLOAT32 input_real[][64],
271                              FLOAT32 input_imag[][64], FLOAT32 input_real1[][64],
272                              FLOAT32 input_imag1[][64], WORD32 x_over_qmf[MAX_NUM_PATCHES],
273                              FLOAT32 *scratch_buff, FLOAT32 *env_out, WORD32 ldmps_present,
274                              WORD32 ec_flag);
275 
276 WORD32 ixheaacd_generate_hf(FLOAT32 ptr_src_buf_real[][64], FLOAT32 ptr_src_buf_imag[][64],
277                             FLOAT32 ptr_ph_vocod_buf_real[][64],
278                             FLOAT32 ptr_ph_vocod_buf_imag[][64], FLOAT32 ptr_dst_buf_real[][64],
279                             FLOAT32 ptr_dst_buf_imag[][64],
280                             ia_sbr_frame_info_data_struct *ptr_frame_data,
281                             ia_sbr_header_data_struct *ptr_header_data, WORD32 audio_object_type,
282                             WORD32 time_slots, WORD32 ec_flag);
283 
284 VOID ixheaacd_clr_subsamples(WORD32 *ptr_qmf_buf, WORD32 num, WORD32 size);
285 
286 VOID ixheaacd_rescale_x_overlap(
287     ia_sbr_dec_struct *ptr_sbr_dec, ia_sbr_header_data_struct *ptr_header_data,
288     ia_sbr_frame_info_data_struct *ptr_frame_data,
289     ia_sbr_prev_frame_data_struct *ptr_frame_data_prev,
290     WORD32 **pp_overlap_buffer_real, WORD32 **pp_overlap_buffer_imag,
291     FLAG low_pow_flag);
292 
293 WORD32 ixheaacd_qmf_hbe_data_reinit(
294     ia_esbr_hbe_txposer_struct *ptr_hbe_transposer_str,
295     WORD16 *ptr_freq_band_tbl[MAX_FREQ_COEFFS + 1], WORD16 *ptr_num_sf_bands,
296     WORD32 upsamp_4_flag);
297 
298 WORD32 ixheaacd_dft_hbe_data_reinit(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer,
299                                     WORD16 *p_freq_band_tab[2], WORD16 *p_num_sfb);
300 
301 WORD32 ixheaacd_sbr_read_pvc_sce(ia_sbr_frame_info_data_struct *ptr_frame_data,
302                                  ia_bit_buf_struct *it_bit_buff,
303                                  WORD32 hbe_flag,
304                                  ia_pvc_data_struct *ptr_pvc_data,
305                                  ia_sbr_tables_struct *sbr_tables_ptr,
306                                  ia_sbr_header_data_struct *ptr_header_data);
307 
308 WORD32 ixheaacd_esbr_dec(ia_sbr_dec_struct *ptr_sbr_dec,
309                          ia_sbr_header_data_struct *ptr_header_data,
310                          ia_sbr_frame_info_data_struct *ptr_frame_data,
311                          FLAG apply_processing, FLAG low_pow_flag,
312                          ia_sbr_tables_struct *sbr_tables_ptr, WORD32 ch_fac);
313 
314 VOID ixheaacd_hbe_repl_spec(WORD32 x_over_qmf[MAX_NUM_PATCHES],
315                             FLOAT32 qmf_buf_real[][64],
316                             FLOAT32 qmf_buf_imag[][64], WORD32 no_bins,
317                             WORD32 max_stretch);
318 
319 #endif
320