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