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 #include <string.h>
21 #include "ixheaacd_sbr_common.h"
22 #include "ixheaacd_type_def.h"
23
24 #include "ixheaacd_constants.h"
25 #include "ixheaacd_basic_ops32.h"
26 #include "ixheaacd_basic_ops16.h"
27 #include "ixheaacd_basic_ops40.h"
28 #include "ixheaacd_basic_ops.h"
29 #include "ixheaacd_defines.h"
30
31 #include "ixheaacd_intrinsics.h"
32 #include "ixheaacd_sbr_const.h"
33 #include "ixheaacd_basic_op.h"
34 #include "ixheaacd_defines.h"
35 #include "ixheaacd_bitbuffer.h"
36 #include "ixheaacd_pns.h"
37
38 #include "ixheaacd_aac_rom.h"
39 #include "ixheaacd_pulsedata.h"
40
41 #include "ixheaacd_drc_data_struct.h"
42 #include "ixheaacd_lt_predict.h"
43 #include "ixheaacd_cnst.h"
44 #include "ixheaacd_ec_defines.h"
45 #include "ixheaacd_ec_struct_def.h"
46 #include "ixheaacd_channelinfo.h"
47 #include "ixheaacd_drc_dec.h"
48
49 #include "ixheaacd_sbrdecoder.h"
50
51 #include "ixheaacd_sbrdecsettings.h"
52 #include "ixheaacd_sbr_scale.h"
53 #include "ixheaacd_lpp_tran.h"
54 #include "ixheaacd_env_extr_part.h"
55 #include "ixheaacd_sbr_rom.h"
56 #include "ixheaacd_hybrid.h"
57 #include "ixheaacd_ps_dec.h"
58 #include "ixheaacd_ps_bitdec.h"
59 #include "ixheaacd_env_extr.h"
60 #include "ixheaacd_common_rom.h"
61 #include "ixheaacd_freq_sca.h"
62
63 #include "ixheaacd_qmf_dec.h"
64
65 #include "ixheaacd_env_calc.h"
66
67 #include "ixheaacd_pvc_dec.h"
68 #include "ixheaacd_sbr_dec.h"
69 #include "ixheaacd_env_dec.h"
70 #include "ixheaacd_basic_funcs.h"
71 #include "ixheaacd_sbr_crc.h"
72
73 #include "ixheaacd_sbrqmftrans.h"
74
75 #include "ixheaacd_audioobjtypes.h"
76
77 extern const WORD32 ixheaacd_ldmps_polyphase_filter_coeff_fix[1280];
78
79 #define ALIGN_SIZE64(x) ((((x) + 7) >> 3) << 3)
80
81 #define FD_OVERSAMPLING_FAC (1.5f)
82
ixheaacd_getsize_sbr_persistent()83 WORD32 ixheaacd_getsize_sbr_persistent() {
84 return (ALIGN_SIZE64(sizeof(ia_sbr_pers_struct)));
85 }
86
ixheaacd_esbr_hbe_data_init(ia_esbr_hbe_txposer_struct * pstr_esbr_hbe_txposer,const WORD32 num_aac_samples,WORD32 samp_fac_4_flag,const WORD32 num_out_samples,VOID * persistent_hbe_mem,WORD32 * total_persistant)87 VOID ixheaacd_esbr_hbe_data_init(
88 ia_esbr_hbe_txposer_struct *pstr_esbr_hbe_txposer,
89 const WORD32 num_aac_samples, WORD32 samp_fac_4_flag,
90 const WORD32 num_out_samples, VOID *persistent_hbe_mem,
91 WORD32 *total_persistant) {
92 WORD32 i;
93 WORD32 used_persistent = 0;
94
95 if (pstr_esbr_hbe_txposer) {
96 memset(pstr_esbr_hbe_txposer, 0, sizeof(ia_esbr_hbe_txposer_struct));
97
98 pstr_esbr_hbe_txposer->core_frame_length = num_aac_samples;
99
100 pstr_esbr_hbe_txposer->no_bins = num_out_samples / NO_QMF_SYNTH_CHANNELS;
101 pstr_esbr_hbe_txposer->hbe_qmf_in_len =
102 pstr_esbr_hbe_txposer->no_bins;
103 pstr_esbr_hbe_txposer->hbe_qmf_out_len =
104 2 * pstr_esbr_hbe_txposer->hbe_qmf_in_len;
105
106 pstr_esbr_hbe_txposer->ptr_input_buf =
107 (FLOAT32 *)((WORD8 *)persistent_hbe_mem);
108 used_persistent +=
109 (num_aac_samples + NO_QMF_SYNTH_CHANNELS) * sizeof(FLOAT32);
110
111 pstr_esbr_hbe_txposer->qmf_in_buf =
112 (FLOAT32 **)((WORD8 *)persistent_hbe_mem + used_persistent);
113 used_persistent +=
114 pstr_esbr_hbe_txposer->hbe_qmf_in_len * sizeof(FLOAT32 *);
115
116 for (i = 0; i < pstr_esbr_hbe_txposer->hbe_qmf_in_len; i++) {
117 pstr_esbr_hbe_txposer->qmf_in_buf[i] =
118 (FLOAT32 *)((WORD8 *)persistent_hbe_mem + used_persistent);
119
120 used_persistent += (TWICE_QMF_SYNTH_CHANNELS_NUM * sizeof(FLOAT32));
121 }
122
123 pstr_esbr_hbe_txposer->qmf_out_buf =
124 (FLOAT32 **)((WORD8 *)persistent_hbe_mem + used_persistent);
125 used_persistent +=
126 (pstr_esbr_hbe_txposer->hbe_qmf_out_len * sizeof(FLOAT32 *));
127
128 for (i = 0; i < pstr_esbr_hbe_txposer->hbe_qmf_out_len; i++) {
129 pstr_esbr_hbe_txposer->qmf_out_buf[i] =
130 (FLOAT32 *)((WORD8 *)persistent_hbe_mem + used_persistent);
131 used_persistent += (TWICE_QMF_SYNTH_CHANNELS_NUM * sizeof(FLOAT32));
132 }
133 pstr_esbr_hbe_txposer->upsamp_4_flag = samp_fac_4_flag;
134 if (pstr_esbr_hbe_txposer) {
135 pstr_esbr_hbe_txposer->fft_size[0] = num_aac_samples;
136 pstr_esbr_hbe_txposer->fft_size[1] = (WORD32)(FD_OVERSAMPLING_FAC * num_aac_samples);
137
138 pstr_esbr_hbe_txposer->ptr_spectrum = &pstr_esbr_hbe_txposer->spectrum_buf[0];
139 pstr_esbr_hbe_txposer->ptr_spectrum_tx =
140 &pstr_esbr_hbe_txposer->spectrum_transposed_buf[0];
141 pstr_esbr_hbe_txposer->mag = &pstr_esbr_hbe_txposer->mag_buf[0];
142 pstr_esbr_hbe_txposer->phase = &pstr_esbr_hbe_txposer->phase_buf[0];
143 pstr_esbr_hbe_txposer->ptr_output_buf = &pstr_esbr_hbe_txposer->output_buf[0];
144 }
145 }
146 *total_persistant = used_persistent;
147 return;
148 }
149
ixheaacd_set_sbr_persistent_table_pointer(VOID * sbr_persistent_mem_v,ia_sbr_tables_struct * sbr_tables_ptr,ixheaacd_misc_tables * pstr_common_tables)150 VOID ixheaacd_set_sbr_persistent_table_pointer(
151 VOID *sbr_persistent_mem_v, ia_sbr_tables_struct *sbr_tables_ptr,
152 ixheaacd_misc_tables *pstr_common_tables) {
153 ia_sbr_pers_struct *sbr_persistent_mem =
154 (ia_sbr_pers_struct *)sbr_persistent_mem_v;
155 sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_tables = sbr_tables_ptr;
156 sbr_persistent_mem->str_sbr_dec_inst.pstr_common_tables = pstr_common_tables;
157 }
158
ixheaacd_set_sbr_persistent_buffers(VOID * sbr_persistent_mem_v,WORD32 * persistent_used,WORD32 num_channel,WORD ps_enable)159 VOID ixheaacd_set_sbr_persistent_buffers(VOID *sbr_persistent_mem_v,
160 WORD32 *persistent_used,
161 WORD32 num_channel, WORD ps_enable) {
162 WORD32 i = 0;
163 WORD32 used_persistent = *persistent_used;
164 WORD32 temp, temp1, temp2, temp3;
165 struct ia_sbr_pers_struct *sbr_persistent_mem =
166 (struct ia_sbr_pers_struct *)sbr_persistent_mem_v;
167
168 struct ia_sbr_dec_inst_struct *p_str_sbr_dec_inst =
169 &sbr_persistent_mem->str_sbr_dec_inst;
170
171 num_channel = max(2, num_channel);
172 memset(sbr_persistent_mem, 0, sizeof(struct ia_sbr_pers_struct));
173
174 sbr_persistent_mem->sbr_qmf_analy_states =
175 (WORD16 *)((WORD8 *)sbr_persistent_mem_v + used_persistent);
176 temp = num_channel * ((QMF_FILTER_STATE_ANA_SIZE + 2 * NO_ANALYSIS_CHANNELS) *
177 sizeof(WORD16));
178 used_persistent += temp;
179
180 sbr_persistent_mem->sbr_qmf_analy_states_32 =
181 (WORD32 *)((WORD8 *)sbr_persistent_mem_v + used_persistent);
182 temp1 =
183 num_channel *
184 ((QMF_FILTER_STATE_ANA_SIZE + 2 * NO_ANALYSIS_CHANNELS) * sizeof(WORD32));
185 used_persistent += temp1;
186
187 sbr_persistent_mem->sbr_qmf_synth_states =
188 (WORD16 *)((WORD8 *)sbr_persistent_mem_v + used_persistent);
189
190 temp2 =
191 (num_channel * ((QMF_FILTER_STATE_SYN_SIZE + 2 * NO_SYNTHESIS_CHANNELS) *
192 sizeof(WORD16)));
193 used_persistent += temp2;
194
195 sbr_persistent_mem->sbr_qmf_synth_states_32 =
196 (WORD32 *)((WORD8 *)sbr_persistent_mem_v + used_persistent);
197
198 temp3 =
199 (num_channel * ((QMF_FILTER_STATE_SYN_SIZE + 2 * NO_SYNTHESIS_CHANNELS) *
200 sizeof(WORD32)));
201 used_persistent += temp3;
202
203 memset(sbr_persistent_mem->sbr_qmf_analy_states, 0,
204 (temp + temp1 + temp2 + temp3));
205
206 for (i = 0; i < num_channel; i++) {
207 sbr_persistent_mem->ptr_sbr_overlap_buf[i] =
208 (WORD32 *)((WORD8 *)sbr_persistent_mem_v + used_persistent);
209
210 if (ps_enable) {
211 memset(sbr_persistent_mem->ptr_sbr_overlap_buf[i], 0,
212 2 * MAX_OV_COLS * NO_SYNTHESIS_CHANNELS * sizeof(WORD32));
213 used_persistent +=
214 2 * MAX_OV_COLS * NO_SYNTHESIS_CHANNELS * sizeof(WORD32);
215 } else {
216 memset(sbr_persistent_mem->ptr_sbr_overlap_buf[i], 0,
217 MAX_OV_COLS * NO_SYNTHESIS_CHANNELS * sizeof(WORD32));
218 used_persistent += MAX_OV_COLS * NO_SYNTHESIS_CHANNELS * sizeof(WORD32);
219 }
220 }
221
222 for (i = 0; i < num_channel; i++) {
223 WORD32 j;
224 sbr_persistent_mem->sbr_lpc_filter_states_real[i] =
225 (WORD32 **)((WORD8 *)sbr_persistent_mem_v + used_persistent);
226 used_persistent += LPC_ORDER * sizeof(WORD32 *);
227 for (j = 0; j < LPC_ORDER; j++) {
228 sbr_persistent_mem->sbr_lpc_filter_states_real[i][j] =
229 (WORD32 *)((WORD8 *)sbr_persistent_mem_v + used_persistent);
230
231 used_persistent += NO_ANALYSIS_CHANNELS * sizeof(WORD32);
232
233 memset(sbr_persistent_mem->sbr_lpc_filter_states_real[i][j], 0,
234 NO_ANALYSIS_CHANNELS * sizeof(WORD32));
235 }
236 }
237
238 if (ps_enable) {
239 for (i = 0; i < num_channel; i++) {
240 WORD32 j;
241
242 sbr_persistent_mem->sbr_lpc_filter_states_imag[i] =
243 (WORD32 **)((WORD8 *)sbr_persistent_mem_v + used_persistent);
244 used_persistent += LPC_ORDER * sizeof(WORD32 *);
245 for (j = 0; j < LPC_ORDER; j++) {
246 sbr_persistent_mem->sbr_lpc_filter_states_imag[i][j] =
247 (WORD32 *)((WORD8 *)sbr_persistent_mem_v + used_persistent);
248
249 used_persistent += NO_ANALYSIS_CHANNELS * sizeof(WORD32);
250
251 memset(sbr_persistent_mem->sbr_lpc_filter_states_imag[i][j], 0,
252 NO_ANALYSIS_CHANNELS * sizeof(WORD32));
253 }
254 }
255 }
256 for (i = 0; i < num_channel; i++) {
257 WORD32 initial_used = used_persistent;
258 WORD32 temp_used = used_persistent;
259
260 sbr_persistent_mem->sbr_smooth_gain_buf[i] =
261 (WORD16 *)((WORD8 *)sbr_persistent_mem_v + temp_used);
262 temp_used += 2 * MAX_FREQ_COEFFS * sizeof(WORD16);
263
264 sbr_persistent_mem->sbr_smooth_noise_buf[i] =
265 (WORD16 *)((WORD8 *)sbr_persistent_mem_v + temp_used);
266
267 temp_used += MAX_FREQ_COEFFS * sizeof(WORD16);
268
269 p_str_sbr_dec_inst->pstr_freq_band_data[i] =
270 (VOID *)((WORD8 *)sbr_persistent_mem_v + temp_used);
271
272 temp_used += ALIGN_SIZE64(sizeof(ia_freq_band_data_struct));
273
274 sbr_persistent_mem->pstr_prev_frame_data[i] =
275 (VOID *)((WORD8 *)sbr_persistent_mem_v + temp_used);
276
277 temp_used += ALIGN_SIZE64(sizeof(ia_sbr_prev_frame_data_struct));
278
279 p_str_sbr_dec_inst->pstr_sbr_channel[i] =
280 (VOID *)((WORD8 *)sbr_persistent_mem_v + temp_used);
281
282 temp_used += ALIGN_SIZE64(sizeof(ia_sbr_channel_struct));
283
284 p_str_sbr_dec_inst->pstr_sbr_header[i] =
285 (VOID *)((WORD8 *)sbr_persistent_mem_v + temp_used);
286
287 temp_used += ALIGN_SIZE64(sizeof(ia_sbr_header_data_struct));
288
289 memset(sbr_persistent_mem->sbr_smooth_gain_buf[i], 0,
290 temp_used - initial_used);
291
292 used_persistent = temp_used;
293 }
294
295 if (ps_enable) {
296 p_str_sbr_dec_inst->pstr_ps_stereo_dec =
297 (ia_ps_dec_struct *)((WORD8 *)sbr_persistent_mem_v + used_persistent);
298
299 memset(p_str_sbr_dec_inst->pstr_ps_stereo_dec, 0, sizeof(ia_ps_dec_struct));
300
301 used_persistent += sizeof(ia_ps_dec_struct);
302 }
303
304 p_str_sbr_dec_inst->frame_buffer[0] =
305 (VOID *)((WORD8 *)sbr_persistent_mem_v + used_persistent);
306 memset(p_str_sbr_dec_inst->frame_buffer[0], 0,
307 (sizeof(ia_sbr_frame_info_data_struct) +
308 MAX_FREQ_COEFFS * sizeof(WORD32) * 2 + 8));
309 used_persistent = used_persistent + (sizeof(ia_sbr_frame_info_data_struct) +
310 MAX_FREQ_COEFFS * sizeof(WORD32) + 8);
311
312 p_str_sbr_dec_inst->frame_buffer[1] =
313 (VOID *)((WORD8 *)sbr_persistent_mem_v + used_persistent);
314 memset(p_str_sbr_dec_inst->frame_buffer[1], 0,
315 (sizeof(ia_sbr_frame_info_data_struct) +
316 MAX_FREQ_COEFFS * sizeof(WORD32) * 2 + 8));
317 used_persistent = used_persistent + (sizeof(ia_sbr_frame_info_data_struct) +
318 MAX_FREQ_COEFFS * sizeof(WORD32) + 8);
319
320 {
321 WORD32 index = 0;
322 p_str_sbr_dec_inst->ptr_pvc_data_str =
323 (ia_pvc_data_struct *)((WORD8 *)sbr_persistent_mem_v + used_persistent);
324 memset(p_str_sbr_dec_inst->ptr_pvc_data_str, 0, sizeof(ia_pvc_data_struct));
325 used_persistent += sizeof(ia_pvc_data_struct);
326
327 p_str_sbr_dec_inst->pstr_sbr_channel[0]->str_sbr_dec.p_hbe_txposer =
328 (ia_esbr_hbe_txposer_struct *)((WORD8 *)sbr_persistent_mem_v +
329 used_persistent);
330 memset(p_str_sbr_dec_inst->pstr_sbr_channel[0]->str_sbr_dec.p_hbe_txposer,
331 0, sizeof(ia_esbr_hbe_txposer_struct));
332 used_persistent += sizeof(ia_esbr_hbe_txposer_struct);
333
334 if (num_channel == 2) {
335 p_str_sbr_dec_inst->pstr_sbr_channel[1]->str_sbr_dec.p_hbe_txposer =
336 (ia_esbr_hbe_txposer_struct *)((WORD8 *)sbr_persistent_mem_v +
337 used_persistent);
338 memset(p_str_sbr_dec_inst->pstr_sbr_channel[1]->str_sbr_dec.p_hbe_txposer,
339 0, sizeof(ia_esbr_hbe_txposer_struct));
340 used_persistent += sizeof(ia_esbr_hbe_txposer_struct);
341 }
342
343 p_str_sbr_dec_inst->hbe_txposer_buffers =
344 (VOID *)((WORD8 *)sbr_persistent_mem_v + used_persistent);
345 memset(p_str_sbr_dec_inst->hbe_txposer_buffers, 0,
346 num_channel * MAX_HBE_PERSISTENT_SIZE);
347 used_persistent += num_channel * MAX_HBE_PERSISTENT_SIZE;
348
349 p_str_sbr_dec_inst->pstr_sbr_channel[0]->str_sbr_dec.pp_qmf_buf_real =
350 (FLOAT32 **)((WORD8 *)sbr_persistent_mem_v + used_persistent);
351 memset(p_str_sbr_dec_inst->pstr_sbr_channel[0]->str_sbr_dec.pp_qmf_buf_real,
352 0, MAX_QMF_BUF_LEN * sizeof(FLOAT32 *));
353 used_persistent += MAX_QMF_BUF_LEN * sizeof(FLOAT32 *);
354
355 p_str_sbr_dec_inst->pstr_sbr_channel[0]->str_sbr_dec.pp_qmf_buf_imag =
356 (FLOAT32 **)((WORD8 *)sbr_persistent_mem_v + used_persistent);
357 memset(p_str_sbr_dec_inst->pstr_sbr_channel[0]->str_sbr_dec.pp_qmf_buf_imag,
358 0, MAX_QMF_BUF_LEN);
359 used_persistent += MAX_QMF_BUF_LEN * sizeof(FLOAT32 *);
360
361 if (num_channel == 2) {
362 p_str_sbr_dec_inst->pstr_sbr_channel[1]->str_sbr_dec.pp_qmf_buf_real =
363 (FLOAT32 **)((WORD8 *)sbr_persistent_mem_v + used_persistent);
364 memset(
365 p_str_sbr_dec_inst->pstr_sbr_channel[1]->str_sbr_dec.pp_qmf_buf_real,
366 0, MAX_QMF_BUF_LEN * sizeof(FLOAT32 *));
367 used_persistent += MAX_QMF_BUF_LEN * sizeof(FLOAT32 *);
368
369 p_str_sbr_dec_inst->pstr_sbr_channel[1]->str_sbr_dec.pp_qmf_buf_imag =
370 (FLOAT32 **)((WORD8 *)sbr_persistent_mem_v + used_persistent);
371 memset(
372 p_str_sbr_dec_inst->pstr_sbr_channel[1]->str_sbr_dec.pp_qmf_buf_imag,
373 0, MAX_QMF_BUF_LEN * sizeof(FLOAT32 *));
374 used_persistent += MAX_QMF_BUF_LEN * sizeof(FLOAT32 *);
375 }
376
377 for (index = 0; index < MAX_QMF_BUF_LEN; index++) {
378 p_str_sbr_dec_inst->pstr_sbr_channel[0]
379 ->str_sbr_dec.pp_qmf_buf_real[index] =
380 (FLOAT32 *)((WORD8 *)sbr_persistent_mem_v + used_persistent);
381 used_persistent += MAX_QMF_BUF_LEN * sizeof(FLOAT32);
382 }
383
384 for (index = 0; index < MAX_QMF_BUF_LEN; index++) {
385 p_str_sbr_dec_inst->pstr_sbr_channel[0]
386 ->str_sbr_dec.pp_qmf_buf_imag[index] =
387 (FLOAT32 *)((WORD8 *)sbr_persistent_mem_v + used_persistent);
388 used_persistent += MAX_QMF_BUF_LEN * sizeof(FLOAT32);
389 }
390
391 if (num_channel == 2) {
392 for (index = 0; index < MAX_QMF_BUF_LEN; index++) {
393 p_str_sbr_dec_inst->pstr_sbr_channel[1]
394 ->str_sbr_dec.pp_qmf_buf_real[index] =
395 (FLOAT32 *)((WORD8 *)sbr_persistent_mem_v + used_persistent);
396 used_persistent += MAX_QMF_BUF_LEN * sizeof(FLOAT32);
397 }
398
399 for (index = 0; index < MAX_QMF_BUF_LEN; index++) {
400 p_str_sbr_dec_inst->pstr_sbr_channel[1]
401 ->str_sbr_dec.pp_qmf_buf_imag[index] =
402 (FLOAT32 *)((WORD8 *)sbr_persistent_mem_v + used_persistent);
403 used_persistent += MAX_QMF_BUF_LEN * sizeof(FLOAT32);
404 }
405 }
406 }
407
408 *persistent_used = used_persistent;
409 }
410
ixheaacd_init_headerdata(ia_sbr_header_data_struct * ptr_header_data,WORD32 sample_rate_dec,WORD32 samp_per_frame,ia_freq_band_data_struct * freq_band_data,ia_sbr_tables_struct * sbr_tables,WORD audio_obj_type)411 static PLATFORM_INLINE VOID ixheaacd_init_headerdata(
412 ia_sbr_header_data_struct *ptr_header_data, WORD32 sample_rate_dec,
413 WORD32 samp_per_frame, ia_freq_band_data_struct *freq_band_data,
414 ia_sbr_tables_struct *sbr_tables, WORD audio_obj_type) {
415 ia_freq_band_data_struct *pstr_freq_band_data = freq_band_data;
416 WORD32 tmp;
417
418 if (audio_obj_type != AOT_ER_AAC_ELD) {
419 memcpy(ptr_header_data,
420 &sbr_tables->env_extr_tables_ptr->str_sbr_default_header,
421 sizeof(ia_sbr_header_data_struct));
422 }
423
424 if (audio_obj_type == AOT_ER_AAC_ELD) ptr_header_data->time_step -= 1;
425
426 pstr_freq_band_data->freq_band_table[LOW] =
427 pstr_freq_band_data->freq_band_tbl_lo;
428 pstr_freq_band_data->freq_band_table[HIGH] =
429 pstr_freq_band_data->freq_band_tbl_hi;
430 ptr_header_data->pstr_freq_band_data = pstr_freq_band_data;
431
432 ptr_header_data->core_frame_size = samp_per_frame;
433 ptr_header_data->out_sampling_freq = sample_rate_dec << 1;
434
435 if (audio_obj_type != AOT_ER_AAC_ELD) {
436 tmp = ptr_header_data->time_step + 4;
437
438 if (tmp < 0)
439 ptr_header_data->num_time_slots =
440 ixheaacd_extract16l(samp_per_frame << (-tmp));
441 else
442 ptr_header_data->num_time_slots =
443 ixheaacd_extract16l(samp_per_frame >> tmp);
444 } else {
445 ptr_header_data->time_step = 1;
446
447 ptr_header_data->num_time_slots =
448 (samp_per_frame / 32 >> (ptr_header_data->time_step - 1));
449 }
450 }
451
ixheaacd_setesbr_flags(VOID * sbr_persistent_mem_v,FLAG pvc_flag,FLAG hbe_flag,FLAG inter_tes_flag)452 VOID ixheaacd_setesbr_flags(VOID *sbr_persistent_mem_v, FLAG pvc_flag,
453 FLAG hbe_flag, FLAG inter_tes_flag) {
454 ia_sbr_pers_struct *sbr_persistent_mem;
455 sbr_persistent_mem = (ia_sbr_pers_struct *)sbr_persistent_mem_v;
456 sbr_persistent_mem->str_sbr_dec_inst.hbe_flag = hbe_flag;
457 sbr_persistent_mem->str_sbr_dec_inst.pvc_flag = pvc_flag;
458 sbr_persistent_mem->str_sbr_dec_inst.inter_tes_flag = inter_tes_flag;
459 return;
460 }
461
ixheaacd_init_sbr(WORD32 sample_rate_dec,WORD32 samp_per_frame,FLAG * down_sample_flag,VOID * sbr_persistent_mem_v,WORD32 * ptr_overlap_buf,WORD32 channel,WORD32 ps_enable,WORD32 sbr_ratio_idx,WORD32 output_frame_size,WORD32 * use_hbe,VOID * p_usac_dflt_header,ia_sbr_header_data_struct str_sbr_config,WORD32 audio_object_type,WORD32 ldmps_present,WORD32 ldsbr_present)462 ia_handle_sbr_dec_inst_struct ixheaacd_init_sbr(
463 WORD32 sample_rate_dec, WORD32 samp_per_frame, FLAG *down_sample_flag,
464 VOID *sbr_persistent_mem_v, WORD32 *ptr_overlap_buf, WORD32 channel,
465 WORD32 ps_enable, WORD32 sbr_ratio_idx, WORD32 output_frame_size,
466 WORD32 *use_hbe, VOID *p_usac_dflt_header,
467 ia_sbr_header_data_struct str_sbr_config, WORD32 audio_object_type,
468 WORD32 ldmps_present, WORD32 ldsbr_present) {
469 WORD16 i;
470 WORD16 err;
471 ia_sbr_header_data_struct *ptr_header_data[MAXNRSBRCHANNELS];
472 ia_sbr_dec_struct *ptr_sbr_dec[2];
473 ia_qmf_dec_tables_struct *qmf_dec_tables_ptr;
474 ia_sbr_pers_struct *sbr_persistent_mem;
475
476 sbr_persistent_mem = (ia_sbr_pers_struct *)sbr_persistent_mem_v;
477 ptr_sbr_dec[0] =
478 &sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_channel[0]->str_sbr_dec;
479 ptr_sbr_dec[1] =
480 &sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_channel[1]->str_sbr_dec;
481
482 qmf_dec_tables_ptr =
483 sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_tables->qmf_dec_tables_ptr;
484
485 if (sample_rate_dec > 48000) {
486 *down_sample_flag = 1;
487 }
488
489 for (i = 0; i < channel; i++) {
490 if (audio_object_type == AOT_ER_AAC_ELD) {
491 memcpy(sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_header[i],
492 &str_sbr_config, sizeof(ia_sbr_header_data_struct));
493 }
494 ptr_header_data[i] =
495 sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_header[i];
496
497 ixheaacd_init_headerdata(
498 ptr_header_data[i], sample_rate_dec, samp_per_frame,
499 sbr_persistent_mem->str_sbr_dec_inst.pstr_freq_band_data[i],
500 sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_tables,
501 audio_object_type);
502
503 err = ixheaacd_create_sbrdec(
504
505 sbr_persistent_mem->str_sbr_dec_inst.pstr_common_tables,
506 sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_channel[i],
507 ptr_header_data[i], i, *down_sample_flag, sbr_persistent_mem, ps_enable,
508 audio_object_type, ldmps_present, ldsbr_present);
509
510 ptr_header_data[i]->status = 1;
511 ptr_sbr_dec[i]->band_count = 64;
512 ptr_header_data[i]->pstr_freq_band_data[0].qmf_sb_prev = 64;
513 ptr_header_data[i]->pstr_freq_band_data[1].qmf_sb_prev = 64;
514
515 if (err) {
516 return NULL;
517 }
518 }
519
520 if (channel != 1) {
521 if (ps_enable) {
522 if (audio_object_type == AOT_ER_AAC_ELD)
523 ixheaacd_create_psdec(
524 sbr_persistent_mem->str_sbr_dec_inst.pstr_ps_stereo_dec,
525 sbr_persistent_mem, &ptr_overlap_buf[512 * 4], samp_per_frame);
526 else
527 ixheaacd_create_psdec(
528 sbr_persistent_mem->str_sbr_dec_inst.pstr_ps_stereo_dec,
529 sbr_persistent_mem, ptr_overlap_buf, samp_per_frame);
530 }
531 }
532
533 if ((use_hbe != NULL) && !((audio_object_type == AOT_ER_AAC_ELD) ||
534 (audio_object_type == AOT_ER_AAC_LD))) {
535 ia_sbr_header_data_struct *ptr_sbr_dflt_header =
536 &sbr_persistent_mem->str_sbr_dec_inst.str_sbr_dflt_header;
537 ia_sbr_header_data_struct *ptr_usac_dflt_header =
538 (ia_sbr_header_data_struct *)p_usac_dflt_header;
539 struct ia_sbr_dec_inst_struct *p_str_sbr_dec_inst =
540 &sbr_persistent_mem->str_sbr_dec_inst;
541 VOID *hbe_txposer_buffers = p_str_sbr_dec_inst->hbe_txposer_buffers;
542
543 ptr_header_data[0] = p_str_sbr_dec_inst->pstr_sbr_header[0];
544 ptr_header_data[1] = p_str_sbr_dec_inst->pstr_sbr_header[1];
545
546 ptr_header_data[0]->sbr_ratio_idx = sbr_ratio_idx;
547 ptr_header_data[0]->output_framesize = output_frame_size;
548 ptr_header_data[0]->pstr_freq_band_data->sub_band_start = 64;
549 ptr_header_data[0]->esbr_start_up = 1;
550 ptr_header_data[0]->esbr_start_up_pvc = 1;
551
552 if (channel > 1) {
553 ptr_header_data[1]->sbr_ratio_idx = sbr_ratio_idx;
554 ptr_header_data[1]->output_framesize = output_frame_size;
555 ptr_header_data[1]->pstr_freq_band_data->sub_band_start = 64;
556 ptr_header_data[1]->esbr_start_up = 1;
557 ptr_header_data[1]->esbr_start_up_pvc = 1;
558 }
559 if (hbe_txposer_buffers != NULL) {
560 WORD32 persistant_used = 0;
561 ixheaacd_esbr_hbe_data_init(ptr_sbr_dec[0]->p_hbe_txposer, samp_per_frame,
562 sbr_ratio_idx == SBR_UPSAMPLE_IDX_4_1 ? 1 : 0,
563 output_frame_size, hbe_txposer_buffers, &persistant_used);
564
565 hbe_txposer_buffers =
566 (WORD8 *)hbe_txposer_buffers + MAX_HBE_PERSISTENT_SIZE;
567
568 ixheaacd_esbr_hbe_data_init(ptr_sbr_dec[1]->p_hbe_txposer, samp_per_frame,
569 sbr_ratio_idx == SBR_UPSAMPLE_IDX_4_1 ? 1 : 0,
570 output_frame_size, hbe_txposer_buffers, &persistant_used);
571 }
572
573 p_str_sbr_dec_inst->ptr_pvc_data_str->prev_first_bnd_idx = -1;
574 p_str_sbr_dec_inst->ptr_pvc_data_str->prev_pvc_rate = -1;
575 p_str_sbr_dec_inst->ptr_pvc_data_str->prev_sbr_mode = UNKNOWN_SBR;
576
577 p_str_sbr_dec_inst->pstr_sbr_channel[0]
578 ->str_sbr_dec.str_codec_qmf_bank.num_time_slots =
579 output_frame_size / 64;
580 p_str_sbr_dec_inst->pstr_sbr_channel[1]
581 ->str_sbr_dec.str_codec_qmf_bank.num_time_slots =
582 output_frame_size / 64;
583
584 ptr_header_data[0]->core_frame_size = samp_per_frame;
585 ptr_header_data[1]->core_frame_size = samp_per_frame;
586
587 switch (sbr_ratio_idx) {
588 case SBR_UPSAMPLE_IDX_0_0:
589 ptr_sbr_dec[0]->str_codec_qmf_bank.no_channels = 32;
590 ptr_sbr_dec[0]->str_codec_qmf_bank.esbr_cos_twiddle =
591 (WORD32 *)qmf_dec_tables_ptr->esbr_sin_cos_twiddle_l32;
592 ptr_sbr_dec[0]->str_codec_qmf_bank.esbr_alt_sin_twiddle =
593 (WORD32 *)qmf_dec_tables_ptr->esbr_alt_sin_twiddle_l32;
594 ptr_sbr_dec[0]->str_codec_qmf_bank.esbr_t_cos =
595 (WORD32 *)qmf_dec_tables_ptr->esbr_t_cos_sin_l32;
596 ptr_header_data[0]->is_usf_4 = 0;
597 ptr_header_data[0]->upsamp_fac = 1;
598
599 ptr_sbr_dec[1]->str_codec_qmf_bank.no_channels = 32;
600 ptr_sbr_dec[1]->str_codec_qmf_bank.esbr_cos_twiddle =
601 (WORD32 *)qmf_dec_tables_ptr->esbr_sin_cos_twiddle_l32;
602 ptr_sbr_dec[1]->str_codec_qmf_bank.esbr_alt_sin_twiddle =
603 (WORD32 *)qmf_dec_tables_ptr->esbr_alt_sin_twiddle_l32;
604 ptr_sbr_dec[1]->str_codec_qmf_bank.esbr_t_cos =
605 (WORD32 *)qmf_dec_tables_ptr->esbr_t_cos_sin_l32;
606 ptr_header_data[1]->is_usf_4 = 0;
607 ptr_header_data[1]->upsamp_fac = 1;
608 break;
609 case SBR_UPSAMPLE_IDX_2_1:
610 ptr_sbr_dec[0]->str_codec_qmf_bank.no_channels = 32;
611 ptr_sbr_dec[0]->str_codec_qmf_bank.esbr_cos_twiddle =
612 (WORD32 *)qmf_dec_tables_ptr->esbr_sin_cos_twiddle_l32;
613 ptr_sbr_dec[0]->str_codec_qmf_bank.esbr_alt_sin_twiddle =
614 (WORD32 *)qmf_dec_tables_ptr->esbr_alt_sin_twiddle_l32;
615 ptr_sbr_dec[0]->str_codec_qmf_bank.esbr_t_cos =
616 (WORD32 *)qmf_dec_tables_ptr->esbr_t_cos_sin_l32;
617 ptr_header_data[0]->is_usf_4 = 0;
618 ptr_header_data[0]->upsamp_fac = 2;
619
620 ptr_sbr_dec[1]->str_codec_qmf_bank.no_channels = 32;
621 ptr_sbr_dec[1]->str_codec_qmf_bank.esbr_cos_twiddle =
622 (WORD32 *)qmf_dec_tables_ptr->esbr_sin_cos_twiddle_l32;
623 ptr_sbr_dec[1]->str_codec_qmf_bank.esbr_alt_sin_twiddle =
624 (WORD32 *)qmf_dec_tables_ptr->esbr_alt_sin_twiddle_l32;
625 ptr_sbr_dec[1]->str_codec_qmf_bank.esbr_t_cos =
626 (WORD32 *)qmf_dec_tables_ptr->esbr_t_cos_sin_l32;
627 ptr_header_data[1]->is_usf_4 = 0;
628 ptr_header_data[1]->upsamp_fac = 2;
629 break;
630 case SBR_UPSAMPLE_IDX_8_3:
631 ptr_sbr_dec[0]->str_codec_qmf_bank.no_channels = 24;
632 ptr_sbr_dec[0]->str_codec_qmf_bank.filter_pos_32 =
633 qmf_dec_tables_ptr->esbr_qmf_c_24;
634 ptr_sbr_dec[0]->str_codec_qmf_bank.analy_win_coeff_32 =
635 qmf_dec_tables_ptr->esbr_qmf_c_24;
636 ptr_sbr_dec[0]->str_codec_qmf_bank.esbr_cos_twiddle =
637 (WORD32 *)qmf_dec_tables_ptr->esbr_sin_cos_twiddle_l24;
638 ptr_sbr_dec[0]->str_codec_qmf_bank.esbr_alt_sin_twiddle =
639 (WORD32 *)qmf_dec_tables_ptr->esbr_alt_sin_twiddle_l24;
640 ptr_sbr_dec[0]->str_codec_qmf_bank.esbr_t_cos =
641 (WORD32 *)qmf_dec_tables_ptr->esbr_t_cos_sin_l24;
642
643 ptr_header_data[0]->is_usf_4 = 0;
644 ptr_header_data[0]->upsamp_fac = 2;
645
646 ptr_sbr_dec[1]->str_codec_qmf_bank.no_channels = 24;
647 ptr_sbr_dec[1]->str_codec_qmf_bank.filter_pos_32 =
648 qmf_dec_tables_ptr->esbr_qmf_c_24;
649 ptr_sbr_dec[1]->str_codec_qmf_bank.analy_win_coeff_32 =
650 qmf_dec_tables_ptr->esbr_qmf_c_24;
651 ptr_sbr_dec[1]->str_codec_qmf_bank.esbr_cos_twiddle =
652 (WORD32 *)qmf_dec_tables_ptr->esbr_sin_cos_twiddle_l24;
653 ptr_sbr_dec[1]->str_codec_qmf_bank.esbr_alt_sin_twiddle =
654 (WORD32 *)qmf_dec_tables_ptr->esbr_alt_sin_twiddle_l24;
655 ptr_sbr_dec[1]->str_codec_qmf_bank.esbr_t_cos =
656 (WORD32 *)qmf_dec_tables_ptr->esbr_t_cos_sin_l24;
657
658 ptr_header_data[1]->is_usf_4 = 0;
659 ptr_header_data[1]->upsamp_fac = 2;
660 break;
661 case SBR_UPSAMPLE_IDX_4_1:
662 ptr_sbr_dec[0]->str_codec_qmf_bank.no_channels = 16;
663 ptr_sbr_dec[0]->str_codec_qmf_bank.esbr_cos_twiddle =
664 (WORD32 *)qmf_dec_tables_ptr->esbr_sin_cos_twiddle_l16;
665 ptr_sbr_dec[0]->str_codec_qmf_bank.esbr_alt_sin_twiddle =
666 (WORD32 *)qmf_dec_tables_ptr->esbr_alt_sin_twiddle_l16;
667 ptr_sbr_dec[0]->str_codec_qmf_bank.esbr_t_cos =
668 (WORD32 *)qmf_dec_tables_ptr->esbr_t_cos_sin_l16;
669 ptr_header_data[0]->is_usf_4 = 1;
670 ptr_header_data[0]->upsamp_fac = 4;
671 ptr_header_data[0]->out_sampling_freq =
672 ptr_header_data[0]->out_sampling_freq * 2;
673
674 ptr_sbr_dec[1]->str_codec_qmf_bank.no_channels = 16;
675 ptr_sbr_dec[1]->str_codec_qmf_bank.esbr_cos_twiddle =
676 (WORD32 *)qmf_dec_tables_ptr->esbr_sin_cos_twiddle_l16;
677 ptr_sbr_dec[1]->str_codec_qmf_bank.esbr_alt_sin_twiddle =
678 (WORD32 *)qmf_dec_tables_ptr->esbr_alt_sin_twiddle_l16;
679 ptr_sbr_dec[1]->str_codec_qmf_bank.esbr_t_cos =
680 (WORD32 *)qmf_dec_tables_ptr->esbr_t_cos_sin_l16;
681 ptr_header_data[1]->is_usf_4 = 1;
682 ptr_header_data[1]->upsamp_fac = 4;
683 ptr_header_data[1]->out_sampling_freq =
684 ptr_header_data[1]->out_sampling_freq * 2;
685 break;
686 }
687
688 if (ptr_usac_dflt_header != NULL) {
689 ptr_sbr_dflt_header->start_freq = ptr_usac_dflt_header->start_freq;
690 ptr_sbr_dflt_header->stop_freq = ptr_usac_dflt_header->stop_freq;
691
692 if (ptr_usac_dflt_header->header_extra_1) {
693 ptr_sbr_dflt_header->freq_scale = ptr_usac_dflt_header->freq_scale;
694 ptr_sbr_dflt_header->alter_scale = ptr_usac_dflt_header->alter_scale;
695 ptr_sbr_dflt_header->noise_bands = ptr_usac_dflt_header->noise_bands;
696 } else {
697 ptr_sbr_dflt_header->freq_scale = SBR_FREQ_SCALE_DEFAULT;
698 ptr_sbr_dflt_header->alter_scale = SBR_ALTER_SCALE_DEFAULT;
699 ptr_sbr_dflt_header->noise_bands = SBR_NOISE_BANDS_DEFAULT;
700 }
701
702 if (ptr_usac_dflt_header->header_extra_2) {
703 ptr_sbr_dflt_header->limiter_bands = ptr_usac_dflt_header->limiter_bands;
704 ptr_sbr_dflt_header->limiter_gains = ptr_usac_dflt_header->limiter_gains;
705 ptr_sbr_dflt_header->interpol_freq = ptr_usac_dflt_header->interpol_freq;
706 ptr_sbr_dflt_header->smoothing_mode =
707 ptr_usac_dflt_header->smoothing_mode;
708 } else {
709 ptr_sbr_dflt_header->limiter_bands = SBR_LIMITER_BANDS_DEFAULT;
710 ptr_sbr_dflt_header->limiter_gains = SBR_LIMITER_GAINS_DEFAULT;
711 ptr_sbr_dflt_header->interpol_freq = SBR_INTERPOL_FREQ_DEFAULT;
712 ptr_sbr_dflt_header->smoothing_mode = SBR_SMOOTHING_LENGTH_DEFAULT;
713 }
714 }
715 }
716 return &(sbr_persistent_mem->str_sbr_dec_inst);
717 }
718
ixheaacd_create_sbr_env_calc(ixheaacd_misc_tables * pstr_common_table,ia_sbr_calc_env_struct * hs,WORD16 chan,VOID * sbr_persistent_mem_v,ia_sbr_header_data_struct * ptr_header_data,WORD audio_object_type)719 static PLATFORM_INLINE WORD16 ixheaacd_create_sbr_env_calc(
720
721 ixheaacd_misc_tables *pstr_common_table, ia_sbr_calc_env_struct *hs,
722 WORD16 chan, VOID *sbr_persistent_mem_v,
723 ia_sbr_header_data_struct *ptr_header_data, WORD audio_object_type) {
724 WORD16 err;
725 ia_sbr_pers_struct *sbr_persistent_mem =
726 (ia_sbr_pers_struct *)sbr_persistent_mem_v;
727
728 err = 0;
729 memset(&hs->harm_flags_prev[0], 0, sizeof(WORD8) * MAX_FREQ_COEFFS);
730
731 hs->harm_index = 0;
732
733 hs->filt_buf_me = sbr_persistent_mem->sbr_smooth_gain_buf[chan];
734 hs->filt_buf_noise_m = sbr_persistent_mem->sbr_smooth_noise_buf[chan];
735 hs->tansient_env_prev = -1;
736
737 ixheaacd_reset_sbrenvelope_calc(hs);
738
739 if ((chan == 0) && (audio_object_type == AOT_ER_AAC_ELD)) {
740 err = ixheaacd_calc_frq_bnd_tbls(ptr_header_data, pstr_common_table);
741 }
742
743 return err;
744 }
745
ixheaacd_init_sbr_prev_framedata(ia_sbr_prev_frame_data_struct * ptr_prev_data,WORD16 time_slots)746 static PLATFORM_INLINE VOID ixheaacd_init_sbr_prev_framedata(
747 ia_sbr_prev_frame_data_struct *ptr_prev_data, WORD16 time_slots) {
748 WORD16 *psfb_nrg_prev = ptr_prev_data->sfb_nrg_prev;
749 WORD16 *psfb_noise_level = ptr_prev_data->prev_noise_level;
750 WORD32 *ppsbr_invf_mode = ptr_prev_data->sbr_invf_mode;
751
752 memset(psfb_nrg_prev, 0, sizeof(WORD16) * (MAX_FREQ_COEFFS));
753 memset(psfb_noise_level, 0, sizeof(WORD16) * (MAX_NOISE_COEFFS));
754
755 memset(ppsbr_invf_mode, 0, sizeof(WORD32) * MAX_INVF_BANDS);
756
757 ptr_prev_data->end_position = time_slots;
758 ptr_prev_data->coupling_mode = COUPLING_OFF;
759 ptr_prev_data->amp_res = 0;
760 ptr_prev_data->max_qmf_subband_aac = 0;
761 }
762
763 static PLATFORM_INLINE VOID
ixheaacd_create_hyb_filterbank(ia_hybrid_struct * ptr_hybrid,WORD32 ** p_ptr,ia_sbr_tables_struct * sbr_tables_ptr)764 ixheaacd_create_hyb_filterbank(ia_hybrid_struct *ptr_hybrid, WORD32 **p_ptr,
765 ia_sbr_tables_struct *sbr_tables_ptr) {
766 WORD16 i;
767 WORD32 *ptr = (WORD32 *)*p_ptr;
768
769 ptr_hybrid->ptr_resol = sbr_tables_ptr->ps_tables_ptr->hyb_resol;
770 ptr_hybrid->ptr_qmf_buf = HYBRID_FILTER_LENGTH - 1;
771
772 ptr_hybrid->ptr_temp_re = ptr;
773 ptr += NO_HYBRID_CHANNELS_HIGH;
774 ptr_hybrid->ptr_temp_im = ptr;
775 ptr += NO_HYBRID_CHANNELS_HIGH;
776
777 memset(ptr_hybrid->ptr_temp_re, 0,
778 2 * NO_HYBRID_CHANNELS_HIGH * sizeof(WORD32));
779
780 ptr_hybrid->ptr_work_re = ptr;
781 ptr += 16;
782 ptr_hybrid->ptr_work_im = ptr;
783 ptr += 16;
784
785 for (i = 0; i < NO_QMF_CHANNELS_IN_HYBRID; i++) {
786 ptr_hybrid->ptr_qmf_buf_re[i] = ptr;
787 ptr += ptr_hybrid->ptr_qmf_buf;
788
789 ptr_hybrid->ptr_qmf_buf_im[i] = ptr;
790 ptr += ptr_hybrid->ptr_qmf_buf;
791
792 memset(ptr_hybrid->ptr_qmf_buf_re[i], 0,
793 2 * ptr_hybrid->ptr_qmf_buf * sizeof(WORD32));
794 }
795
796 *p_ptr = ptr;
797
798 return;
799 }
800
ixheaacd_create_hf_generator(ia_sbr_hf_generator_struct * ptr_hf_gen_str,WORD16 num_columns,WORD16 chan,VOID * sbr_persistent_mem_v,WORD32 ps_enable)801 static PLATFORM_INLINE VOID ixheaacd_create_hf_generator(
802 ia_sbr_hf_generator_struct *ptr_hf_gen_str, WORD16 num_columns, WORD16 chan,
803 VOID *sbr_persistent_mem_v, WORD32 ps_enable) {
804 WORD16 i;
805 ia_sbr_pers_struct *sbr_persistent_mem =
806 (ia_sbr_pers_struct *)sbr_persistent_mem_v;
807
808 ptr_hf_gen_str->pstr_settings = &sbr_persistent_mem->str_sbr_tran_settings;
809
810 ptr_hf_gen_str->lpc_filt_states_real[0] =
811 sbr_persistent_mem->sbr_lpc_filter_states_real[chan][0];
812 ptr_hf_gen_str->lpc_filt_states_real[1] =
813 sbr_persistent_mem->sbr_lpc_filter_states_real[chan][1];
814
815 if (ps_enable) {
816 ptr_hf_gen_str->lpc_filt_states_imag[0] =
817 sbr_persistent_mem->sbr_lpc_filter_states_imag[chan][0];
818 ptr_hf_gen_str->lpc_filt_states_imag[1] =
819 sbr_persistent_mem->sbr_lpc_filter_states_imag[chan][1];
820 }
821
822 for (i = 0; i < LPC_ORDER; i++) {
823 if (ptr_hf_gen_str->lpc_filt_states_real[i] != NULL) {
824 memset(ptr_hf_gen_str->lpc_filt_states_real[i], 0,
825 NO_ANALYSIS_CHANNELS * sizeof(WORD32));
826 }
827
828 if (ps_enable)
829 memset(ptr_hf_gen_str->lpc_filt_states_imag[i], 0,
830 NO_ANALYSIS_CHANNELS * sizeof(WORD32));
831 }
832
833 if (chan == 0) {
834 ptr_hf_gen_str->pstr_settings->num_columns = num_columns;
835 }
836 return;
837 }
838
ixheaacd_create_psdec(ia_ps_dec_struct * ptr_ps_dec,VOID * sbr_persistent_mem_v,WORD32 * ptr_overlap_buf,WORD32 frame_size)839 VOID ixheaacd_create_psdec(ia_ps_dec_struct *ptr_ps_dec,
840 VOID *sbr_persistent_mem_v,
841 WORD32 *ptr_overlap_buf, WORD32 frame_size) {
842 ia_sbr_pers_struct *sbr_persistent_mem =
843 (ia_sbr_pers_struct *)sbr_persistent_mem_v;
844
845 WORD16 *ptr1 = (WORD16 *)&(
846 sbr_persistent_mem->ptr_sbr_overlap_buf[MAXNRSBRCHANNELS - 1][0]);
847 WORD32 *ptr2 = (WORD32 *)&ptr_overlap_buf[512];
848 WORD16 *initial_ptr;
849 WORD16 delay;
850 WORD32 temp;
851
852 ia_sbr_tables_struct *sbr_tables_ptr =
853 sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_tables;
854
855 memset(ptr_ps_dec, 0, sizeof(ia_ps_dec_struct));
856
857 ptr_ps_dec->ps_data_present = 0;
858 ptr_ps_dec->enable_iid = 0;
859 ptr_ps_dec->enable_icc = 0;
860 ptr_ps_dec->enable_ext = 0;
861 ptr_ps_dec->iid_mode = 0;
862 ptr_ps_dec->icc_mode = 0;
863
864 ptr_ps_dec->ptr_hyb_left_re = ptr2;
865 ptr2 += 16;
866 ptr_ps_dec->ptr_hyb_left_im = ptr2;
867 ptr2 += 16;
868 ptr_ps_dec->ptr_hyb_right_re = ptr2;
869 ptr2 += 16;
870 ptr_ps_dec->ptr_hyb_right_im = ptr2;
871 ptr2 += 16;
872
873 memset(ptr_ps_dec->ptr_hyb_left_re, 0, sizeof(WORD32) * 16 * 4);
874
875 ixheaacd_create_hyb_filterbank(&ptr_ps_dec->str_hybrid, &ptr2,
876 sbr_tables_ptr);
877
878 ptr_ps_dec->peak_decay_diff = ptr2;
879 ptr2 += NUM_OF_BINS;
880 ptr_ps_dec->energy_prev = ptr2;
881 ptr2 += NUM_OF_BINS;
882 ptr_ps_dec->peak_decay_diff_prev = ptr2;
883 ptr2 += NUM_OF_BINS;
884
885 memset(ptr_ps_dec->peak_decay_diff, 0, 3 * sizeof(WORD32) * NUM_OF_BINS);
886
887 ptr_ps_dec->delay_buf_idx = 0;
888 ptr_ps_dec->delay_buf_idx_long = 0;
889
890 memset(ptr_ps_dec->delay_buf_qmf_sub_re_im, 0,
891 2 * 16 * DEL_ALL_PASS * sizeof(WORD16));
892 memset(ptr_ps_dec->delay_buf_qmf_sub_ser_re_im, 0,
893 2 * 16 * NUM_SER_AP_LINKS * 5 * sizeof(WORD16));
894
895 initial_ptr = ptr1;
896 ptr_ps_dec->delay_buf_qmf_ser_re_im = (VOID *)ptr1;
897 ptr1 += 2 * NUM_SER_AP_LINKS * 32 * 5;
898
899 delay = 2;
900 ptr_ps_dec->delay_buf_qmf_ap_re_im = (VOID *)ptr1;
901 ptr1 += 2 * delay * 32;
902
903 delay = HIGH_DEL;
904 ptr_ps_dec->delay_buf_qmf_ld_re_im = (VOID *)ptr1;
905 ptr1 += 2 * delay * SMALL_DEL_STRT;
906
907 delay = SMALL_DEL;
908 ptr_ps_dec->delay_buf_qmf_sd_re_im = (VOID *)ptr1;
909 ptr1 +=
910 2 * delay * (NUM_OF_QUAD_MIRROR_FILTER_ICC_CHNLS -
911 (NUM_OF_QUAD_MIRROR_FILTER_ALL_PASS_CHNLS + SMALL_DEL_STRT));
912
913 temp = ptr1 - initial_ptr;
914 memset(ptr_ps_dec->delay_buf_qmf_ser_re_im, 0, temp * sizeof(WORD16));
915
916 memset(ptr_ps_dec->delay_buf_idx_ser, 0, NUM_SER_AP_LINKS * sizeof(WORD16));
917 memcpy(ptr_ps_dec->delay_sample_ser,
918 sbr_tables_ptr->ps_tables_ptr->rev_link_delay_ser,
919 NUM_SER_AP_LINKS * sizeof(WORD16));
920
921 memset(ptr_ps_dec->h11_h12_vec, 0xff,
922 (NO_IID_GROUPS + 2) * 2 * sizeof(WORD16));
923 memset(ptr_ps_dec->h21_h22_vec, 0, sizeof(ptr_ps_dec->h21_h22_vec));
924
925 if (frame_size == 960)
926 ptr_ps_dec->num_sub_samples = NUM_SUB_SAMPLES_960;
927 else
928 ptr_ps_dec->num_sub_samples = NUM_SUB_SAMPLES;
929
930
931 ixheaacd_create_ps_esbr_dec(ptr_ps_dec, sbr_tables_ptr->ps_tables_ptr,
932 64, ptr_ps_dec->num_sub_samples, 0);
933
934 return;
935 }
936
ixheaacd_create_cplx_anal_qmfbank(ia_sbr_qmf_filter_bank_struct * ptr_sbr_qmf,ia_sbr_scale_fact_struct * sbr_scale_factor,WORD16 no_bins,WORD16 usb,WORD16 chan,WORD16 * sbr_qmf_analy_states,WORD32 * sbr_qmf_analy_states_32,ia_qmf_dec_tables_struct * qmf_dec_tables_ptr,WORD32 audio_object_type,WORD32 ldmps_present,WORD32 no_ldsbr)937 static PLATFORM_INLINE VOID ixheaacd_create_cplx_anal_qmfbank(
938 ia_sbr_qmf_filter_bank_struct *ptr_sbr_qmf,
939 ia_sbr_scale_fact_struct *sbr_scale_factor, WORD16 no_bins, WORD16 usb,
940 WORD16 chan, WORD16 *sbr_qmf_analy_states, WORD32 *sbr_qmf_analy_states_32,
941 ia_qmf_dec_tables_struct *qmf_dec_tables_ptr, WORD32 audio_object_type,
942 WORD32 ldmps_present, WORD32 no_ldsbr) {
943 memset(ptr_sbr_qmf, 0, sizeof(ia_sbr_qmf_filter_bank_struct));
944
945 ptr_sbr_qmf->analy_win_coeff_32 = qmf_dec_tables_ptr->esbr_qmf_c;
946 if (audio_object_type != AOT_ER_AAC_ELD &&
947 audio_object_type != AOT_ER_AAC_LD) {
948 ptr_sbr_qmf->analy_win_coeff = qmf_dec_tables_ptr->qmf_c;
949 } else {
950 ptr_sbr_qmf->analy_win_coeff = qmf_dec_tables_ptr->qmf_c_eld3;
951 if (ldmps_present == 1)
952 ptr_sbr_qmf->analy_win_coeff_32 = qmf_dec_tables_ptr->qmf_c_ldsbr_mps;
953 if (no_ldsbr == 1)
954 ptr_sbr_qmf->analy_win_coeff_32 =
955 (WORD32 *)ixheaacd_ldmps_polyphase_filter_coeff_fix;
956 }
957
958 ptr_sbr_qmf->no_channels = NO_ANALYSIS_CHANNELS;
959 if (no_ldsbr) ptr_sbr_qmf->no_channels = 64;
960 ptr_sbr_qmf->num_time_slots = no_bins;
961
962 ptr_sbr_qmf->lsb = 0;
963 ptr_sbr_qmf->usb = usb;
964
965 ptr_sbr_qmf->anal_filter_states =
966 &(sbr_qmf_analy_states[chan ? QMF_FILTER_STATE_ANA_SIZE : 0]);
967
968 memset(ptr_sbr_qmf->anal_filter_states, 0,
969 sizeof(WORD16) * QMF_FILTER_STATE_ANA_SIZE);
970
971 ptr_sbr_qmf->anal_filter_states_32 =
972 &(sbr_qmf_analy_states_32[chan ? QMF_FILTER_STATE_ANA_SIZE : 0]);
973
974 memset(ptr_sbr_qmf->anal_filter_states_32, 0,
975 sizeof(WORD32) * QMF_FILTER_STATE_ANA_SIZE);
976
977 ptr_sbr_qmf->core_samples_buffer = ptr_sbr_qmf->anal_filter_states;
978 ptr_sbr_qmf->core_samples_buffer_32 = ptr_sbr_qmf->anal_filter_states_32;
979
980 ptr_sbr_qmf->filter_pos_32 = (WORD32 *)qmf_dec_tables_ptr->esbr_qmf_c;
981 ptr_sbr_qmf->state_new_samples_pos_low_32 =
982 ptr_sbr_qmf->anal_filter_states_32;
983 if (audio_object_type != AOT_ER_AAC_ELD &&
984 audio_object_type != AOT_ER_AAC_LD) {
985 ptr_sbr_qmf->filter_pos = (WORD16 *)qmf_dec_tables_ptr->qmf_c;
986 } else {
987 ptr_sbr_qmf->filter_pos = (WORD16 *)qmf_dec_tables_ptr->qmf_c_eld3;
988 if (ldmps_present == 1)
989 ptr_sbr_qmf->filter_pos_32 =
990 (WORD32 *)qmf_dec_tables_ptr->qmf_c_ldsbr_mps;
991 if (no_ldsbr == 1)
992 ptr_sbr_qmf->filter_pos_32 =
993 (WORD32 *)ixheaacd_ldmps_polyphase_filter_coeff_fix;
994 }
995
996 sbr_scale_factor->st_lb_scale = 0;
997
998 sbr_scale_factor->st_syn_scale = -6;
999
1000 if (audio_object_type == AOT_ER_AAC_ELD ||
1001 audio_object_type == AOT_ER_AAC_LD) {
1002 ptr_sbr_qmf->filter_2_32 =
1003 ptr_sbr_qmf->filter_pos_32 + ptr_sbr_qmf->no_channels;
1004 ptr_sbr_qmf->fp1_anal_32 = ptr_sbr_qmf->anal_filter_states_32;
1005 ptr_sbr_qmf->fp2_anal_32 =
1006 ptr_sbr_qmf->anal_filter_states_32 + ptr_sbr_qmf->no_channels;
1007
1008 ptr_sbr_qmf->filter_2 = ptr_sbr_qmf->filter_pos + ptr_sbr_qmf->no_channels;
1009 ptr_sbr_qmf->fp1_anal = ptr_sbr_qmf->anal_filter_states;
1010 ptr_sbr_qmf->fp2_anal =
1011 ptr_sbr_qmf->anal_filter_states + ptr_sbr_qmf->no_channels;
1012 }
1013
1014 return;
1015 }
1016
ixheaacd_create_cplx_synt_qmfbank(ia_sbr_qmf_filter_bank_struct * ptr_sbr_qmf,WORD16 no_bins,WORD16 lsb,WORD16 usb,WORD16 chan,FLAG down_sample_flag,WORD16 * sbr_qmf_synth_states,WORD32 * sbr_qmf_synth_states_32,ia_qmf_dec_tables_struct * qmf_dec_tables_ptr,WORD32 audio_object_type)1017 static PLATFORM_INLINE VOID ixheaacd_create_cplx_synt_qmfbank(
1018 ia_sbr_qmf_filter_bank_struct *ptr_sbr_qmf, WORD16 no_bins, WORD16 lsb,
1019 WORD16 usb, WORD16 chan, FLAG down_sample_flag,
1020 WORD16 *sbr_qmf_synth_states, WORD32 *sbr_qmf_synth_states_32,
1021 ia_qmf_dec_tables_struct *qmf_dec_tables_ptr, WORD32 audio_object_type) {
1022 WORD32 L;
1023
1024 WORD32 qmf_filter_state_size;
1025
1026 memset(ptr_sbr_qmf, 0, sizeof(ia_sbr_qmf_filter_bank_struct));
1027
1028 if (down_sample_flag) {
1029 L = NO_SYNTHESIS_CHANNELS_DOWN_SAMPLED;
1030 qmf_filter_state_size = QMF_FILTER_STATE_SYN_SIZE_DOWN_SAMPLED;
1031 ptr_sbr_qmf->usb = NO_SYNTHESIS_CHANNELS_DOWN_SAMPLED;
1032 } else {
1033 L = NO_SYNTHESIS_CHANNELS;
1034 qmf_filter_state_size = QMF_FILTER_STATE_SYN_SIZE;
1035 ptr_sbr_qmf->usb = usb;
1036 }
1037
1038 ptr_sbr_qmf->ixheaacd_drc_offset = 0;
1039 if (audio_object_type != AOT_ER_AAC_ELD &&
1040 audio_object_type != AOT_ER_AAC_LD) {
1041 ptr_sbr_qmf->filter_pos_syn = (WORD16 *)qmf_dec_tables_ptr->qmf_c;
1042 ptr_sbr_qmf->p_filter = qmf_dec_tables_ptr->qmf_c;
1043 } else {
1044 ptr_sbr_qmf->filter_pos_syn = (WORD16 *)qmf_dec_tables_ptr->qmf_c_eld;
1045 ptr_sbr_qmf->p_filter = qmf_dec_tables_ptr->qmf_c_eld;
1046 }
1047
1048 ptr_sbr_qmf->filter_pos_syn_32 = (WORD32 *)qmf_dec_tables_ptr->esbr_qmf_c;
1049 ptr_sbr_qmf->p_filter_32 = qmf_dec_tables_ptr->esbr_qmf_c;
1050
1051 ptr_sbr_qmf->no_channels = L;
1052 ptr_sbr_qmf->qmf_filter_state_size = qmf_filter_state_size;
1053 ptr_sbr_qmf->num_time_slots = no_bins;
1054 ptr_sbr_qmf->lsb = lsb;
1055
1056 ptr_sbr_qmf->filter_states =
1057 &sbr_qmf_synth_states[chan ? qmf_filter_state_size : 0];
1058
1059 memset(ptr_sbr_qmf->filter_states, 0, sizeof(WORD16) * qmf_filter_state_size);
1060
1061 ptr_sbr_qmf->filter_states_32 =
1062 &sbr_qmf_synth_states_32[chan ? qmf_filter_state_size : 0];
1063
1064 memset(ptr_sbr_qmf->filter_states_32, 0,
1065 sizeof(WORD32) * qmf_filter_state_size);
1066
1067 if (audio_object_type == AOT_ER_AAC_ELD ||
1068 audio_object_type == AOT_ER_AAC_LD) {
1069 ptr_sbr_qmf->fp1_syn = ptr_sbr_qmf->filter_states;
1070 ptr_sbr_qmf->fp2_syn =
1071 ptr_sbr_qmf->filter_states + ptr_sbr_qmf->no_channels;
1072 ptr_sbr_qmf->sixty4 = NO_SYNTHESIS_CHANNELS;
1073 }
1074
1075 return;
1076 }
1077
ixheaacd_create_sbrdec(ixheaacd_misc_tables * pstr_common_table,ia_sbr_channel_struct * ptr_sbr_channel,ia_sbr_header_data_struct * ptr_header_data,WORD16 chan,FLAG down_sample_flag,VOID * sbr_persistent_mem_v,WORD ps_enable,WORD audio_object_type,WORD32 ldmps_present,WORD32 ldsbr_present)1078 WORD16 ixheaacd_create_sbrdec(ixheaacd_misc_tables *pstr_common_table,
1079 ia_sbr_channel_struct *ptr_sbr_channel,
1080 ia_sbr_header_data_struct *ptr_header_data,
1081 WORD16 chan, FLAG down_sample_flag,
1082 VOID *sbr_persistent_mem_v, WORD ps_enable,
1083 WORD audio_object_type, WORD32 ldmps_present,
1084 WORD32 ldsbr_present)
1085
1086 {
1087 WORD16 err;
1088 WORD16 time_slots;
1089 WORD16 no_bins;
1090 ia_sbr_pers_struct *sbr_persistent_mem =
1091 (ia_sbr_pers_struct *)sbr_persistent_mem_v;
1092 ia_sbr_dec_struct *hs = &(ptr_sbr_channel->str_sbr_dec);
1093
1094 time_slots = ptr_header_data->num_time_slots;
1095
1096 no_bins = (WORD16)(time_slots * ptr_header_data->time_step);
1097
1098 hs->str_sbr_scale_fact.ov_lb_scale = INT_BITS - 1;
1099 hs->str_sbr_scale_fact.hb_scale = INT_BITS - 1;
1100 hs->str_sbr_scale_fact.ov_hb_scale = INT_BITS - 1;
1101 hs->str_sbr_scale_fact.st_syn_scale = INT_BITS - 1;
1102
1103 ptr_sbr_channel->pstr_prev_frame_data =
1104 sbr_persistent_mem->pstr_prev_frame_data[chan];
1105
1106 err = ixheaacd_create_sbr_env_calc(pstr_common_table, &hs->str_sbr_calc_env,
1107 chan, sbr_persistent_mem, ptr_header_data,
1108 audio_object_type);
1109
1110 if (err) {
1111 return (-1);
1112 }
1113
1114 ixheaacd_create_cplx_anal_qmfbank(
1115 &hs->str_codec_qmf_bank, &hs->str_sbr_scale_fact, no_bins,
1116 ptr_header_data->pstr_freq_band_data->sub_band_start, chan,
1117 sbr_persistent_mem->sbr_qmf_analy_states,
1118 sbr_persistent_mem->sbr_qmf_analy_states_32,
1119 sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_tables->qmf_dec_tables_ptr,
1120 audio_object_type, ldmps_present, ldsbr_present);
1121
1122 ixheaacd_create_cplx_synt_qmfbank(
1123 &hs->str_synthesis_qmf_bank, no_bins,
1124 ptr_header_data->pstr_freq_band_data->sub_band_start,
1125 ptr_header_data->pstr_freq_band_data->sub_band_end, chan,
1126 down_sample_flag, sbr_persistent_mem->sbr_qmf_synth_states,
1127 sbr_persistent_mem->sbr_qmf_synth_states_32,
1128 sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_tables->qmf_dec_tables_ptr,
1129 audio_object_type);
1130
1131 ixheaacd_init_sbr_prev_framedata(ptr_sbr_channel->pstr_prev_frame_data,
1132 time_slots);
1133
1134 ixheaacd_create_hf_generator(&hs->str_hf_generator,
1135 hs->str_codec_qmf_bank.num_time_slots, chan,
1136 sbr_persistent_mem, ps_enable);
1137
1138 hs->ptr_sbr_overlap_buf = sbr_persistent_mem->ptr_sbr_overlap_buf[chan];
1139
1140 return 0;
1141 }
1142