1 /******************************************************************************
2 *
3 * Copyright (C) 2023 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 "ixheaac_type_def.h"
22 #include "ixheaacd_mps_struct_def.h"
23 #include "ixheaacd_mps_res_rom.h"
24 #include "ixheaacd_mps_aac_struct.h"
25 #include "ixheaacd_sbr_common.h"
26 #include "ixheaac_constants.h"
27 #include "ixheaacd_bitbuffer.h"
28 #include "ixheaacd_aac_rom.h"
29 #include "ixheaacd_error_codes.h"
30 #include "ixheaacd_pulsedata.h"
31 #include "ixheaacd_pns.h"
32 #include "ixheaacd_drc_data_struct.h"
33 #include "ixheaacd_cnst.h"
34 #include "ixheaacd_ec_defines.h"
35 #include "ixheaacd_ec_struct_def.h"
36 #include "ixheaacd_channelinfo.h"
37 #include "ixheaacd_sbrdecoder.h"
38 #include "ixheaacd_common_rom.h"
39 #include "ixheaacd_sbrdecsettings.h"
40 #include "ixheaacd_sbr_scale.h"
41 #include "ixheaacd_env_extr_part.h"
42 #include "ixheaacd_sbr_rom.h"
43 #include "ixheaacd_lpp_tran.h"
44 #include "ixheaacd_hybrid.h"
45 #include "ixheaacd_ps_dec.h"
46 #include "ixheaacd_env_extr.h"
47 #include "ixheaacd_audioobjtypes.h"
48 #include "ixheaacd_memory_standards.h"
49 #include "ixheaacd_latmdemux.h"
50 #include "ixheaacd_aacdec.h"
51 #include "ixheaacd_mps_polyphase.h"
52 #include "ixheaacd_config.h"
53 #include "ixheaacd_qmf_dec.h"
54 #include "ixheaacd_mps_dec.h"
55 #include "ixheaacd_struct_def.h"
56 #include "ixheaacd_mps_decor.h"
57 #include "ixheaacd_mps_bitdec.h"
58 #include "ixheaacd_mps_mdct_2_qmf.h"
59 #include "ixheaacd_mps_tonality.h"
60 #include "ixheaacd_mps_reshape_bb_env.h"
61 #include "ixheaacd_mps_hybfilter.h"
62 #include "ixheaacd_mps_blind.h"
63 #include "ixheaacd_mps_macro_def.h"
64 #include "ixheaacd_mps_tables.h"
65
66 #define ALIGN_SIZE64(x) ((((x) + 7) >> 3) << 3)
67
68 #define ALIGN_SIZE32(x) ((((x) + 3) >> 2) << 2)
69
ixheaacd_getsize_mps_persistent()70 WORD32 ixheaacd_getsize_mps_persistent() {
71 return (IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_persistent_mem), BYTE_ALIGN_8));
72 }
73
ixheaacd_calc_decorr_size()74 static WORD32 ixheaacd_calc_decorr_size() {
75 WORD32 matrix_alloc_size, decorr_filter_size, num_den_size;
76 WORD32 fraction_alloc_size, ducker_create_size, decor_dec_size;
77 WORD32 state_alloc_size, alloc_size, dec_type = 0;
78
79 matrix_alloc_size =
80 MAX_NO_DECORR_CHANNELS * 2 *
81 (MAX_HYBRID_BANDS *
82 IXHEAAC_GET_SIZE_ALIGNED((MAX_TIME_SLOTS + MAX_NO_TIME_SLOTS_DELAY) * sizeof(WORD32),
83 BYTE_ALIGN_8) +
84 IXHEAAC_GET_SIZE_ALIGNED(MAX_HYBRID_BANDS * sizeof(WORD32 *), BYTE_ALIGN_8));
85 decorr_filter_size =
86 MAX_NO_DECORR_CHANNELS * MAX_HYBRID_BANDS *
87 IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_decorr_filter_instance_struct), BYTE_ALIGN_8);
88 num_den_size = MAX_NO_DECORR_CHANNELS * MAX_HYBRID_BANDS *
89 IXHEAAC_GET_SIZE_ALIGNED(MAX_NUM_DEN_LENGTH * sizeof(WORD32), BYTE_ALIGN_8);
90
91 if (dec_type == 1)
92 fraction_alloc_size = 4 * num_den_size;
93 else
94 fraction_alloc_size = 2 * num_den_size;
95
96 state_alloc_size = MAX_NO_DECORR_CHANNELS * MAX_HYBRID_BANDS * 2 *
97 IXHEAAC_GET_SIZE_ALIGNED(MAX_NUM_DEN_LENGTH * sizeof(WORD32), BYTE_ALIGN_8);
98
99 ducker_create_size =
100 MAX_NO_DECORR_CHANNELS *
101 (IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_ducker_interface), BYTE_ALIGN_8) +
102 IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_duck_instance_struct), BYTE_ALIGN_8));
103 decor_dec_size = MAX_NO_DECORR_CHANNELS *
104 IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_decorr_dec_struct), BYTE_ALIGN_8);
105
106 alloc_size = matrix_alloc_size + decorr_filter_size + fraction_alloc_size + ducker_create_size +
107 decor_dec_size + state_alloc_size;
108
109 return (2 * alloc_size);
110 }
111
ixheaacd_mps_persistent_buffer_sizes()112 WORD32 ixheaacd_mps_persistent_buffer_sizes() {
113 WORD32 buffer_size;
114
115 buffer_size = ixheaacd_getsize_mps_persistent();
116
117 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(PREV_GAINAT, BYTE_ALIGN_8);
118
119 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(ARBDMX_ALPHA, BYTE_ALIGN_8);
120
121 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(M1_PREV, BYTE_ALIGN_8);
122
123 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(M1_PREV, BYTE_ALIGN_8);
124
125 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(M2_PREV_DECOR, BYTE_ALIGN_8);
126
127 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(M2_PREV_DECOR, BYTE_ALIGN_8);
128
129 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(M2_PREV_RESID, BYTE_ALIGN_8);
130
131 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(M2_PREV_RESID, BYTE_ALIGN_8);
132
133 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(QMF_DELAY_INPUT, BYTE_ALIGN_8);
134
135 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(QMF_DELAY_INPUT, BYTE_ALIGN_8);
136
137 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(ANA_BUF_SIZE, BYTE_ALIGN_8);
138
139 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(SYN_BUF_SIZE, BYTE_ALIGN_8);
140
141 buffer_size += ixheaacd_calc_decorr_size();
142
143 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(HYB_FILTER_STATE_SIZE, BYTE_ALIGN_8);
144
145 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(TONALITY_STATE_SIZE, BYTE_ALIGN_8);
146
147 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(SMOOTHING_STATE_SIZE, BYTE_ALIGN_8);
148
149 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(RESHAPE_STATE_SIZE, BYTE_ALIGN_8);
150
151 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(SUBBAND_TP_SIZE, BYTE_ALIGN_8);
152
153 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(BLIND_DECODER_SIZE, BYTE_ALIGN_8);
154
155 buffer_size +=
156 IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_spatial_bs_frame_struct), BYTE_ALIGN_8);
157
158 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(ARRAY_STRUCT_SIZE, BYTE_ALIGN_8);
159
160 // Add buffer sizes for pstr_mps_state->array_struct
161 // res_mdct
162 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(MDCT_RES_BUF_SIZE, BYTE_ALIGN_8);
163 // qmf_residual_real
164 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(QMF_RES_BUF_SIZE, BYTE_ALIGN_8);
165 // qmf_residual_imag
166 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(QMF_RES_BUF_SIZE, BYTE_ALIGN_8);
167 // m_qmf_real
168 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(QMF_BUF_SIZE, BYTE_ALIGN_8);
169 // m_qmf_imag
170 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(QMF_BUF_SIZE, BYTE_ALIGN_8);
171 // buf_real
172 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(BUF_SIZE, BYTE_ALIGN_8);
173 // buf_imag
174 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(BUF_SIZE, BYTE_ALIGN_8);
175 // aux_struct
176 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_auxilary_struct), BYTE_ALIGN_8);
177 // aux_struct->m2_param
178 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_m2_param_struct), BYTE_ALIGN_8);
179
180 return buffer_size;
181 }
182
ixheaacd_set_mps_persistent_buffers(ia_heaac_mps_state_struct * pstr_mps_state,WORD32 * persistent_used,WORD32 num_channel,VOID * persistent_mem)183 VOID ixheaacd_set_mps_persistent_buffers(ia_heaac_mps_state_struct *pstr_mps_state,
184 WORD32 *persistent_used, WORD32 num_channel,
185 VOID *persistent_mem) {
186 WORD32 used_persistent = *persistent_used;
187
188 struct ia_mps_persistent_mem *mps_persistent_mem = &(pstr_mps_state->mps_persistent_mem);
189
190 WORD32 decorr_size;
191
192 num_channel = max(2, num_channel);
193
194 mps_persistent_mem->prev_gain_at = (WORD32 *)((WORD8 *)persistent_mem);
195
196 memset(mps_persistent_mem->prev_gain_at, 0,
197 IXHEAAC_GET_SIZE_ALIGNED(PREV_GAINAT, BYTE_ALIGN_8));
198
199 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(PREV_GAINAT, BYTE_ALIGN_8);
200
201 mps_persistent_mem->arbdmx_alpha_prev = (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
202 memset(mps_persistent_mem->arbdmx_alpha_prev, 0,
203 IXHEAAC_GET_SIZE_ALIGNED(ARBDMX_ALPHA, BYTE_ALIGN_8));
204 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(ARBDMX_ALPHA, BYTE_ALIGN_8);
205
206 mps_persistent_mem->m1_param_real_prev = (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
207 memset(mps_persistent_mem->m1_param_real_prev, 0,
208 IXHEAAC_GET_SIZE_ALIGNED(M1_PREV, BYTE_ALIGN_8));
209 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(M1_PREV, BYTE_ALIGN_8);
210
211 mps_persistent_mem->m1_param_imag_prev = (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
212 memset(mps_persistent_mem->m1_param_imag_prev, 0,
213 IXHEAAC_GET_SIZE_ALIGNED(M1_PREV, BYTE_ALIGN_8));
214 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(M1_PREV, BYTE_ALIGN_8);
215
216 mps_persistent_mem->m2_decor_real_prev = (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
217 memset(mps_persistent_mem->m2_decor_real_prev, 0,
218 IXHEAAC_GET_SIZE_ALIGNED(M2_PREV_DECOR, BYTE_ALIGN_8));
219 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(M2_PREV_DECOR, BYTE_ALIGN_8);
220
221 mps_persistent_mem->m2_decor_imag_prev = (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
222 memset(mps_persistent_mem->m2_decor_imag_prev, 0,
223 IXHEAAC_GET_SIZE_ALIGNED(M2_PREV_DECOR, BYTE_ALIGN_8));
224 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(M2_PREV_DECOR, BYTE_ALIGN_8);
225
226 mps_persistent_mem->m2_resid_real_prev = (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
227 memset(mps_persistent_mem->m2_resid_real_prev, 0,
228 IXHEAAC_GET_SIZE_ALIGNED(M2_PREV_RESID, BYTE_ALIGN_8));
229 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(M2_PREV_RESID, BYTE_ALIGN_8);
230
231 mps_persistent_mem->m2_resid_imag_prev = (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
232 memset(mps_persistent_mem->m2_resid_imag_prev, 0,
233 IXHEAAC_GET_SIZE_ALIGNED(M2_PREV_RESID, BYTE_ALIGN_8));
234 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(M2_PREV_RESID, BYTE_ALIGN_8);
235
236 mps_persistent_mem->qmf_input_delay_real =
237 (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
238 memset(mps_persistent_mem->qmf_input_delay_real, 0,
239 IXHEAAC_GET_SIZE_ALIGNED(QMF_DELAY_INPUT, BYTE_ALIGN_8));
240 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(QMF_DELAY_INPUT, BYTE_ALIGN_8);
241
242 mps_persistent_mem->qmf_input_delay_imag =
243 (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
244 memset(mps_persistent_mem->qmf_input_delay_imag, 0,
245 IXHEAAC_GET_SIZE_ALIGNED(QMF_DELAY_INPUT, BYTE_ALIGN_8));
246 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(QMF_DELAY_INPUT, BYTE_ALIGN_8);
247
248 mps_persistent_mem->syn_qmf_states_buffer =
249 (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
250 memset(mps_persistent_mem->syn_qmf_states_buffer, 0,
251 IXHEAAC_GET_SIZE_ALIGNED(SYN_BUF_SIZE, BYTE_ALIGN_8));
252 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(SYN_BUF_SIZE, BYTE_ALIGN_8);
253
254 mps_persistent_mem->ana_qmf_states_buffer =
255 (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
256 memset(mps_persistent_mem->ana_qmf_states_buffer, 0,
257 IXHEAAC_GET_SIZE_ALIGNED(ANA_BUF_SIZE, BYTE_ALIGN_8));
258 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(ANA_BUF_SIZE, BYTE_ALIGN_8);
259
260 decorr_size = ixheaacd_calc_decorr_size();
261
262 mps_persistent_mem->decorr_ptr = (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
263 memset(mps_persistent_mem->decorr_ptr, 0, decorr_size);
264 used_persistent += decorr_size;
265
266 mps_persistent_mem->hyb_filter_state =
267 (ia_mps_dec_thyb_filter_state_struct *)((WORD8 *)persistent_mem + used_persistent);
268 memset(mps_persistent_mem->hyb_filter_state, 0,
269 IXHEAAC_GET_SIZE_ALIGNED(HYB_FILTER_STATE_SIZE, BYTE_ALIGN_8));
270 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(HYB_FILTER_STATE_SIZE, BYTE_ALIGN_8);
271
272 mps_persistent_mem->ton_state =
273 (ia_mps_dec_tonality_state_struct *)((WORD8 *)persistent_mem + used_persistent);
274 memset(mps_persistent_mem->ton_state, 0,
275 IXHEAAC_GET_SIZE_ALIGNED(TONALITY_STATE_SIZE, BYTE_ALIGN_8));
276 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(TONALITY_STATE_SIZE, BYTE_ALIGN_8);
277
278 mps_persistent_mem->smooth_state =
279 (ia_mps_dec_smoothing_state_struct *)((WORD8 *)persistent_mem + used_persistent);
280 memset(mps_persistent_mem->smooth_state, 0,
281 IXHEAAC_GET_SIZE_ALIGNED(SMOOTHING_STATE_SIZE, BYTE_ALIGN_8));
282 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(SMOOTHING_STATE_SIZE, BYTE_ALIGN_8);
283
284 mps_persistent_mem->reshape_bb_env_state =
285 (ia_mps_dec_reshape_bb_env_state_struct *)((WORD8 *)persistent_mem + used_persistent);
286 memset(mps_persistent_mem->reshape_bb_env_state, 0,
287 IXHEAAC_GET_SIZE_ALIGNED(RESHAPE_STATE_SIZE, BYTE_ALIGN_8));
288 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(RESHAPE_STATE_SIZE, BYTE_ALIGN_8);
289
290 mps_persistent_mem->sub_band_params =
291 (ia_mps_dec_subband_tp_params_struct *)((WORD8 *)persistent_mem + used_persistent);
292 memset(mps_persistent_mem->sub_band_params, 0,
293 IXHEAAC_GET_SIZE_ALIGNED(SUBBAND_TP_SIZE, BYTE_ALIGN_8));
294 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(SUBBAND_TP_SIZE, BYTE_ALIGN_8);
295
296 mps_persistent_mem->blind_decoder =
297 (ia_mps_dec_blind_decoder_struct *)((WORD8 *)persistent_mem + used_persistent);
298 memset(mps_persistent_mem->blind_decoder, 0,
299 IXHEAAC_GET_SIZE_ALIGNED(BLIND_DECODER_SIZE, BYTE_ALIGN_8));
300 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(BLIND_DECODER_SIZE, BYTE_ALIGN_8);
301
302 mps_persistent_mem->p_bs_frame =
303 (ia_mps_dec_spatial_bs_frame_struct *)((WORD8 *)persistent_mem + used_persistent);
304 memset(mps_persistent_mem->p_bs_frame, 0,
305 IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_spatial_bs_frame_struct), BYTE_ALIGN_8));
306 used_persistent +=
307 IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_spatial_bs_frame_struct), BYTE_ALIGN_8);
308
309 pstr_mps_state->array_struct =
310 (ia_mps_dec_reuse_array_struct *)((WORD8 *)persistent_mem + used_persistent);
311 memset(pstr_mps_state->array_struct, 0,
312 IXHEAAC_GET_SIZE_ALIGNED(ARRAY_STRUCT_SIZE, BYTE_ALIGN_8));
313 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(ARRAY_STRUCT_SIZE, BYTE_ALIGN_8);
314
315 // Set buffers pointers of pstr_mps_state->array_struct
316 ia_mps_dec_reuse_array_struct *p_array_struct = pstr_mps_state->array_struct;
317
318 p_array_struct->res_mdct = (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
319 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(MDCT_RES_BUF_SIZE, BYTE_ALIGN_8);
320
321 p_array_struct->qmf_residual_real = (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
322 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(QMF_RES_BUF_SIZE, BYTE_ALIGN_8);
323 p_array_struct->qmf_residual_imag = (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
324 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(QMF_RES_BUF_SIZE, BYTE_ALIGN_8);
325
326 p_array_struct->m_qmf_real = (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
327 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(QMF_BUF_SIZE, BYTE_ALIGN_8);
328 p_array_struct->m_qmf_imag = (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
329 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(QMF_BUF_SIZE, BYTE_ALIGN_8);
330
331 p_array_struct->buf_real = (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
332 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(BUF_SIZE, BYTE_ALIGN_8);
333 p_array_struct->buf_imag = (WORD32 *)((WORD8 *)persistent_mem + used_persistent);
334 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(BUF_SIZE, BYTE_ALIGN_8);
335
336 p_array_struct->hyb_output_real_dry = p_array_struct->res_mdct;
337 p_array_struct->hyb_output_imag_dry =
338 p_array_struct->res_mdct +
339 IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_OUTPUT_CHANNELS_AT_MPS * TSXHB,
340 sizeof(*p_array_struct->hyb_output_imag_dry), BYTE_ALIGN_8);
341
342 p_array_struct->x_real = p_array_struct->hyb_output_real_dry;
343 p_array_struct->x_imag = p_array_struct->hyb_output_imag_dry;
344
345 p_array_struct->time_out = p_array_struct->hyb_output_real_dry;
346
347 p_array_struct->w_dry_real = p_array_struct->m_qmf_real;
348 p_array_struct->w_dry_imag = p_array_struct->m_qmf_imag;
349
350 p_array_struct->env_dmx_0 =
351 p_array_struct->m_qmf_real +
352 IXHEAAC_GET_SIZE_ALIGNED_TYPE(TSXHBX5, sizeof(*p_array_struct->env_dmx_0), BYTE_ALIGN_8);
353 p_array_struct->env_dmx_1 =
354 p_array_struct->env_dmx_0 +
355 IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_TIME_SLOTS, sizeof(*p_array_struct->env_dmx_1),
356 BYTE_ALIGN_8);
357
358 p_array_struct->qmf_residual_real_pre = p_array_struct->qmf_residual_real;
359 p_array_struct->qmf_residual_real_post =
360 p_array_struct->qmf_residual_real +
361 IXHEAAC_GET_SIZE_ALIGNED_TYPE(
362 RES_CHXQMFXTS, sizeof(*p_array_struct->qmf_residual_real_post), BYTE_ALIGN_8);
363
364 p_array_struct->qmf_residual_imag_pre = p_array_struct->qmf_residual_imag;
365 p_array_struct->qmf_residual_imag_post =
366 p_array_struct->qmf_residual_imag +
367 IXHEAAC_GET_SIZE_ALIGNED_TYPE(
368 RES_CHXQMFXTS, sizeof(*p_array_struct->qmf_residual_imag_post), BYTE_ALIGN_8);
369
370 p_array_struct->buffer_real = p_array_struct->qmf_residual_real_post;
371 p_array_struct->buffer_imag = p_array_struct->qmf_residual_imag_post;
372
373 p_array_struct->m1_param = (ia_mps_dec_m1_param_struct *)p_array_struct->buffer_real;
374
375 pstr_mps_state->aux_struct =
376 (ia_mps_dec_auxilary_struct *)((WORD8 *)persistent_mem + used_persistent);
377 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_auxilary_struct), BYTE_ALIGN_8);
378
379 pstr_mps_state->aux_struct->m2_param =
380 (ia_mps_dec_m2_param_struct *)((WORD8 *)persistent_mem + used_persistent);
381 used_persistent += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_m2_param_struct), BYTE_ALIGN_8);
382
383 *persistent_used = used_persistent;
384 }
385
ixheaacd_scratch_buffer_sizes()386 WORD32 ixheaacd_scratch_buffer_sizes() {
387 WORD32 buffer_size;
388
389 buffer_size = IXHEAAC_GET_SIZE_ALIGNED(MDCT_RES_BUF_SIZE, BYTE_ALIGN_8);
390
391 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(QMF_RES_BUF_SIZE, BYTE_ALIGN_8);
392
393 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(QMF_RES_BUF_SIZE, BYTE_ALIGN_8);
394
395 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(QMF_BUF_SIZE, BYTE_ALIGN_8);
396
397 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(QMF_BUF_SIZE, BYTE_ALIGN_8);
398
399 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(BUF_SIZE, BYTE_ALIGN_8);
400
401 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(BUF_SIZE, BYTE_ALIGN_8);
402
403 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_auxilary_struct), BYTE_ALIGN_8);
404
405 buffer_size += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_m2_param_struct), BYTE_ALIGN_8);
406
407 return buffer_size;
408 }
409
ixheaacd_set_scratch_buffers(ia_heaac_mps_state_struct * pstr_mps_state,VOID * scratch_mem)410 VOID ixheaacd_set_scratch_buffers(ia_heaac_mps_state_struct *pstr_mps_state, VOID *scratch_mem) {
411 WORD32 scratch_used = 0;
412
413 pstr_mps_state->mps_scratch_mem_v = (VOID *)((WORD8 *)scratch_mem + scratch_used);
414 }
ixheaacd_ana_filter_bank_init(ia_heaac_mps_state_struct * pstr_mps_state,ia_mps_dec_qmf_ana_filter_bank * qmf_bank)415 VOID ixheaacd_ana_filter_bank_init(ia_heaac_mps_state_struct *pstr_mps_state,
416 ia_mps_dec_qmf_ana_filter_bank *qmf_bank) {
417 memset(qmf_bank->qmf_states_buffer, 0,
418 QMF_FILTER_STATE_ANA_SIZE_MPS * sizeof(qmf_bank->qmf_states_buffer[0]));
419 qmf_bank->p_filter_ana =
420 pstr_mps_state->ia_mps_dec_mps_table.qmf_table_ptr->ia_mps_enc_qmf_64_640;
421 qmf_bank->flag = 0;
422 qmf_bank->offset = 0;
423 qmf_bank->ref_co_eff_ptr_l = qmf_bank->p_filter_ana + 10;
424 qmf_bank->ref_co_eff_ptr_r = qmf_bank->p_filter_ana + QMF_FILTER_STATE_ANA_SIZE_MPS;
425 qmf_bank->offset_l = 5;
426 qmf_bank->offset_r = 5;
427 }
428
ixheaacd_syn_filter_bank_create(ia_heaac_mps_state_struct * pstr_mps_state)429 VOID ixheaacd_syn_filter_bank_create(ia_heaac_mps_state_struct *pstr_mps_state) {
430 ia_mps_dec_qmf_syn_filter_bank *qmf_bank = &(pstr_mps_state->syn_qmf_bank);
431
432 memset(qmf_bank->sbr_qmf_states_synthesis, 0, SYN_BUFFER_SIZE);
433 qmf_bank->p_filter_syn =
434 pstr_mps_state->ia_mps_dec_mps_table.tp_process_table_ptr->ia_mps_dec_qmf_64_640;
435 }
436
ixheaacd_set_m2_params(ia_heaac_mps_state_struct * pstr_mps_state)437 static IA_ERRORCODE ixheaacd_set_m2_params(ia_heaac_mps_state_struct *pstr_mps_state) {
438 ia_heaac_mps_state_struct *curr_state = pstr_mps_state;
439 WORD32 up_mix_type = curr_state->up_mix_type;
440
441 switch (curr_state->tree_config) {
442 case TREE_5151:
443 if (up_mix_type == 2) {
444 curr_state->m2_param_imag_present = 1;
445
446 curr_state->m2_param_present[0][1] = 1;
447 curr_state->m2_param_present[1][1] = 1;
448 curr_state->m2_param_present[0][0] = 2;
449 curr_state->m2_param_present[1][0] = 2;
450
451 curr_state->m1_param_present[0][0] = 1;
452 curr_state->m1_param_present[1][0] = 1;
453 } else {
454 if (up_mix_type == 3) {
455 curr_state->m2_param_present[0][3] = 1;
456 curr_state->m2_param_present[1][3] = 1;
457 curr_state->m2_param_present[0][0] = 2;
458 curr_state->m2_param_present[1][0] = 2;
459
460 curr_state->m1_param_present[0][0] = 1;
461 curr_state->m1_param_present[3][0] = 1;
462 } else {
463 curr_state->m2_param_present[0][0] = 3;
464 curr_state->m2_param_present[0][1] = 3;
465 curr_state->m2_param_present[0][2] = 3;
466 curr_state->m2_param_present[0][3] = 3;
467 curr_state->m2_param_present[1][0] = 3;
468 curr_state->m2_param_present[1][1] = 3;
469 curr_state->m2_param_present[1][2] = 3;
470 curr_state->m2_param_present[1][3] = 3;
471 curr_state->m2_param_present[2][0] = 3;
472 curr_state->m2_param_present[2][1] = 3;
473 curr_state->m2_param_present[2][2] = 3;
474 curr_state->m2_param_present[3][0] = 3;
475 curr_state->m2_param_present[4][0] = 3;
476 curr_state->m2_param_present[4][1] = 3;
477 curr_state->m2_param_present[4][4] = 3;
478 curr_state->m2_param_present[5][0] = 3;
479 curr_state->m2_param_present[5][1] = 3;
480 curr_state->m2_param_present[5][4] = 3;
481
482 curr_state->m1_param_present[0][0] = 1;
483 curr_state->m1_param_present[1][0] = 1;
484 curr_state->m1_param_present[2][0] = 1;
485 curr_state->m1_param_present[3][0] = 1;
486 curr_state->m1_param_present[4][0] = 1;
487 }
488 }
489 break;
490 case TREE_5152:
491 if (up_mix_type == 2) {
492 curr_state->m2_param_imag_present = 1;
493
494 curr_state->m2_param_present[0][1] = 1;
495 curr_state->m2_param_present[1][1] = 1;
496 curr_state->m2_param_present[0][0] = 2;
497 curr_state->m2_param_present[1][0] = 2;
498
499 curr_state->m1_param_present[0][0] = 1;
500 curr_state->m1_param_present[1][0] = 1;
501 } else {
502 if (up_mix_type == 3) {
503 curr_state->m2_param_present[0][2] = 1;
504 curr_state->m2_param_present[1][2] = 1;
505 curr_state->m2_param_present[0][0] = 2;
506 curr_state->m2_param_present[1][0] = 2;
507
508 curr_state->m1_param_present[0][0] = 1;
509 curr_state->m1_param_present[2][0] = 1;
510 } else {
511 curr_state->m2_param_present[0][0] = 3;
512 curr_state->m2_param_present[0][1] = 3;
513 curr_state->m2_param_present[0][2] = 3;
514 curr_state->m2_param_present[0][3] = 3;
515 curr_state->m2_param_present[1][0] = 3;
516 curr_state->m2_param_present[1][1] = 3;
517 curr_state->m2_param_present[1][2] = 3;
518 curr_state->m2_param_present[1][3] = 3;
519 curr_state->m2_param_present[2][0] = 3;
520 curr_state->m2_param_present[2][1] = 3;
521 curr_state->m2_param_present[2][2] = 3;
522 curr_state->m2_param_present[2][4] = 3;
523 curr_state->m2_param_present[3][0] = 3;
524 curr_state->m2_param_present[3][1] = 3;
525 curr_state->m2_param_present[3][2] = 3;
526 curr_state->m2_param_present[3][4] = 3;
527 curr_state->m2_param_present[4][0] = 3;
528 curr_state->m2_param_present[4][1] = 3;
529 curr_state->m2_param_present[5][0] = 3;
530
531 curr_state->m1_param_present[0][0] = 1;
532 curr_state->m1_param_present[1][0] = 1;
533 curr_state->m1_param_present[2][0] = 1;
534 curr_state->m1_param_present[3][0] = 1;
535 curr_state->m1_param_present[4][0] = 1;
536 }
537 }
538 break;
539 case TREE_525:
540 if (up_mix_type == 1) {
541 curr_state->m2_param_present[0][3] = 1;
542 curr_state->m2_param_present[1][3] = 1;
543 curr_state->m2_param_present[2][4] = 1;
544 curr_state->m2_param_present[3][4] = 1;
545
546 curr_state->m2_param_present[0][0] = 2;
547 curr_state->m2_param_present[1][0] = 2;
548 curr_state->m2_param_present[2][1] = 2;
549 curr_state->m2_param_present[3][1] = 2;
550 curr_state->m2_param_present[4][2] = 2;
551
552 curr_state->m1_param_present[0][0] = 1;
553 curr_state->m1_param_present[0][1] = 1;
554 curr_state->m1_param_present[0][2] = 1;
555 curr_state->m1_param_present[1][0] = 1;
556 curr_state->m1_param_present[1][1] = 1;
557 curr_state->m1_param_present[1][2] = 1;
558 curr_state->m1_param_present[2][0] = 1;
559 curr_state->m1_param_present[2][1] = 1;
560 curr_state->m1_param_present[2][2] = 1;
561 } else if (up_mix_type == 2) {
562 if (curr_state->binaural_quality == 1) {
563 } else {
564 curr_state->m2_param_imag_present = 1;
565
566 curr_state->m2_param_present[0][0] = 2;
567 curr_state->m2_param_present[0][1] = 2;
568 curr_state->m2_param_present[1][0] = 2;
569 curr_state->m2_param_present[1][1] = 2;
570 if (curr_state->arbitrary_downmix == 2) {
571 curr_state->m2_param_present[0][2] = 2;
572 curr_state->m2_param_present[0][3] = 2;
573 curr_state->m2_param_present[1][2] = 2;
574 curr_state->m2_param_present[1][3] = 2;
575 }
576
577 curr_state->m1_param_present[0][0] = 1;
578 curr_state->m1_param_present[1][1] = 1;
579 curr_state->m1_param_present[2][3] = 1;
580 curr_state->m1_param_present[3][4] = 1;
581 }
582 } else {
583 curr_state->m2_param_present[0][0] = 3;
584 curr_state->m2_param_present[0][3] = 3;
585 curr_state->m2_param_present[1][0] = 3;
586 curr_state->m2_param_present[1][3] = 3;
587 curr_state->m2_param_present[2][1] = 3;
588 curr_state->m2_param_present[2][4] = 3;
589 curr_state->m2_param_present[3][1] = 3;
590 curr_state->m2_param_present[3][4] = 3;
591 curr_state->m2_param_present[4][2] = 3;
592 curr_state->m2_param_present[5][2] = 3;
593
594 curr_state->m1_param_present[0][0] = 1;
595 curr_state->m1_param_present[0][1] = 1;
596 curr_state->m1_param_present[0][2] = 1;
597 curr_state->m1_param_present[0][3] = 1;
598 curr_state->m1_param_present[0][4] = 1;
599 curr_state->m1_param_present[1][0] = 1;
600 curr_state->m1_param_present[1][1] = 1;
601 curr_state->m1_param_present[1][2] = 1;
602 curr_state->m1_param_present[1][3] = 1;
603 curr_state->m1_param_present[1][4] = 1;
604 curr_state->m1_param_present[2][0] = 1;
605 curr_state->m1_param_present[2][1] = 1;
606 curr_state->m1_param_present[2][2] = 1;
607 curr_state->m1_param_present[2][3] = 1;
608 curr_state->m1_param_present[2][4] = 1;
609 }
610 break;
611 case TREE_7271:
612 if (up_mix_type == 0) {
613 curr_state->m2_param_present[0][3] = 3;
614 curr_state->m2_param_present[0][6] = 3;
615 curr_state->m2_param_present[1][3] = 3;
616 curr_state->m2_param_present[1][6] = 3;
617 curr_state->m2_param_present[2][3] = 3;
618 curr_state->m2_param_present[3][4] = 3;
619 curr_state->m2_param_present[3][7] = 3;
620 curr_state->m2_param_present[4][4] = 3;
621 curr_state->m2_param_present[4][7] = 3;
622 curr_state->m2_param_present[5][4] = 3;
623
624 curr_state->m2_param_present[0][0] = 2;
625 curr_state->m2_param_present[1][0] = 2;
626 curr_state->m2_param_present[2][0] = 2;
627 curr_state->m2_param_present[3][1] = 2;
628 curr_state->m2_param_present[4][1] = 2;
629 curr_state->m2_param_present[5][1] = 2;
630 curr_state->m2_param_present[6][2] = 2;
631 curr_state->m2_param_present[7][2] = 2;
632
633 curr_state->m1_param_present[0][0] = 1;
634 curr_state->m1_param_present[0][1] = 1;
635 curr_state->m1_param_present[0][2] = 1;
636 curr_state->m1_param_present[0][3] = 1;
637 curr_state->m1_param_present[0][4] = 1;
638 curr_state->m1_param_present[1][0] = 1;
639 curr_state->m1_param_present[1][1] = 1;
640 curr_state->m1_param_present[1][2] = 1;
641 curr_state->m1_param_present[1][3] = 1;
642 curr_state->m1_param_present[1][4] = 1;
643 curr_state->m1_param_present[2][0] = 1;
644 curr_state->m1_param_present[2][1] = 1;
645 curr_state->m1_param_present[2][2] = 1;
646 curr_state->m1_param_present[2][3] = 1;
647 curr_state->m1_param_present[2][4] = 1;
648 } else if (up_mix_type == 2) {
649 if (curr_state->binaural_quality == 1) {
650 } else {
651 curr_state->m2_param_imag_present = 1;
652
653 curr_state->m2_param_present[0][0] = 2;
654 curr_state->m2_param_present[0][1] = 2;
655 curr_state->m2_param_present[1][0] = 2;
656 curr_state->m2_param_present[1][1] = 2;
657 if (curr_state->arbitrary_downmix == 2) {
658 curr_state->m2_param_present[0][2] = 2;
659 curr_state->m2_param_present[0][3] = 2;
660 curr_state->m2_param_present[1][2] = 2;
661 curr_state->m2_param_present[1][3] = 2;
662 }
663
664 curr_state->m1_param_present[0][0] = 1;
665 curr_state->m1_param_present[1][1] = 1;
666 curr_state->m1_param_present[2][3] = 1;
667 curr_state->m1_param_present[3][4] = 1;
668 }
669 }
670 break;
671 case TREE_7272:
672 if (up_mix_type == 0) {
673 curr_state->m2_param_present[0][3] = 3;
674 curr_state->m2_param_present[1][3] = 3;
675 curr_state->m2_param_present[1][6] = 3;
676 curr_state->m2_param_present[2][3] = 3;
677 curr_state->m2_param_present[2][6] = 3;
678 curr_state->m2_param_present[3][4] = 3;
679 curr_state->m2_param_present[4][4] = 3;
680 curr_state->m2_param_present[4][7] = 3;
681 curr_state->m2_param_present[5][4] = 3;
682 curr_state->m2_param_present[5][7] = 3;
683
684 curr_state->m2_param_present[0][0] = 2;
685 curr_state->m2_param_present[1][0] = 2;
686 curr_state->m2_param_present[2][0] = 2;
687 curr_state->m2_param_present[3][1] = 2;
688 curr_state->m2_param_present[4][1] = 2;
689 curr_state->m2_param_present[5][1] = 2;
690 curr_state->m2_param_present[6][2] = 2;
691 curr_state->m2_param_present[7][2] = 2;
692
693 curr_state->m1_param_present[0][0] = 1;
694 curr_state->m1_param_present[0][1] = 1;
695 curr_state->m1_param_present[0][2] = 1;
696 curr_state->m1_param_present[0][3] = 1;
697 curr_state->m1_param_present[0][4] = 1;
698 curr_state->m1_param_present[1][0] = 1;
699 curr_state->m1_param_present[1][1] = 1;
700 curr_state->m1_param_present[1][2] = 1;
701 curr_state->m1_param_present[1][3] = 1;
702 curr_state->m1_param_present[1][4] = 1;
703 curr_state->m1_param_present[2][0] = 1;
704 curr_state->m1_param_present[2][1] = 1;
705 curr_state->m1_param_present[2][2] = 1;
706 curr_state->m1_param_present[2][3] = 1;
707 curr_state->m1_param_present[2][4] = 1;
708 } else if (up_mix_type == 2) {
709 if (curr_state->binaural_quality == 1) {
710 } else {
711 curr_state->m2_param_imag_present = 1;
712
713 curr_state->m2_param_present[0][0] = 2;
714 curr_state->m2_param_present[0][1] = 2;
715 curr_state->m2_param_present[1][0] = 2;
716 curr_state->m2_param_present[1][1] = 2;
717 if (curr_state->arbitrary_downmix == 2) {
718 curr_state->m2_param_present[0][2] = 2;
719 curr_state->m2_param_present[0][3] = 2;
720 curr_state->m2_param_present[1][2] = 2;
721 curr_state->m2_param_present[1][3] = 2;
722 }
723
724 curr_state->m1_param_present[0][0] = 1;
725 curr_state->m1_param_present[1][1] = 1;
726 curr_state->m1_param_present[2][3] = 1;
727 curr_state->m1_param_present[3][4] = 1;
728 }
729 }
730 break;
731 case TREE_7571:
732 curr_state->m2_param_present[0][6] = 3;
733 curr_state->m2_param_present[1][6] = 3;
734 curr_state->m2_param_present[3][7] = 3;
735 curr_state->m2_param_present[4][7] = 3;
736
737 curr_state->m2_param_present[0][0] = 2;
738 curr_state->m2_param_present[1][0] = 2;
739 curr_state->m2_param_present[2][4] = 2;
740 curr_state->m2_param_present[3][1] = 2;
741 curr_state->m2_param_present[4][1] = 2;
742 curr_state->m2_param_present[5][5] = 2;
743 curr_state->m2_param_present[6][2] = 2;
744 curr_state->m2_param_present[7][3] = 2;
745
746 curr_state->m1_param_present[0][0] = 1;
747 curr_state->m1_param_present[1][1] = 1;
748 curr_state->m1_param_present[2][2] = 1;
749 curr_state->m1_param_present[3][3] = 1;
750 curr_state->m1_param_present[4][4] = 1;
751 curr_state->m1_param_present[5][5] = 1;
752 curr_state->m1_param_present[6][0] = 1;
753 curr_state->m1_param_present[7][1] = 1;
754 break;
755 case TREE_7572:
756 curr_state->m2_param_present[1][6] = 3;
757 curr_state->m2_param_present[2][6] = 3;
758 curr_state->m2_param_present[4][7] = 3;
759 curr_state->m2_param_present[5][7] = 3;
760
761 curr_state->m2_param_present[0][0] = 2;
762 curr_state->m2_param_present[1][4] = 2;
763 curr_state->m2_param_present[2][4] = 2;
764 curr_state->m2_param_present[3][1] = 2;
765 curr_state->m2_param_present[4][5] = 2;
766 curr_state->m2_param_present[5][5] = 2;
767 curr_state->m2_param_present[6][2] = 2;
768 curr_state->m2_param_present[7][3] = 2;
769
770 curr_state->m1_param_present[0][0] = 1;
771 curr_state->m1_param_present[1][1] = 1;
772 curr_state->m1_param_present[2][2] = 1;
773 curr_state->m1_param_present[3][3] = 1;
774 curr_state->m1_param_present[4][4] = 1;
775 curr_state->m1_param_present[5][5] = 1;
776 curr_state->m1_param_present[6][4] = 1;
777 curr_state->m1_param_present[7][5] = 1;
778 break;
779 default:
780 return IA_XHEAAC_MPS_DEC_EXE_FATAL_UNSUPPRORTED_TREE_CONFIG;
781 break;
782 };
783
784 return IA_NO_ERROR;
785 }
786
ixheaacd_sb_tp_init(ia_heaac_mps_state_struct * pstr_mps_state)787 VOID ixheaacd_sb_tp_init(ia_heaac_mps_state_struct *pstr_mps_state) {
788 WORD32 ch;
789 ia_mps_dec_subband_tp_params_struct *sub_band_tp =
790 pstr_mps_state->mps_persistent_mem.sub_band_params;
791 WORD32 *prev_tp_scale = sub_band_tp->prev_tp_scale;
792 WORD16 *q_prev_tp_scale = sub_band_tp->q_prev_tp_scale;
793
794 WORD32 *old_wet_ener = sub_band_tp->old_wet_ener;
795 WORD16 *q_old_wet_ener = sub_band_tp->q_old_wet_ener;
796
797 WORD32 *run_wet_ener = sub_band_tp->run_wet_ener;
798 WORD16 *q_run_wet_ener = sub_band_tp->q_run_wet_ener;
799
800 for (ch = 0; ch < MAX_OUTPUT_CHANNELS_MPS; ch++) {
801 prev_tp_scale[ch] = ONE_IN_Q15;
802 q_prev_tp_scale[ch] = 15;
803
804 old_wet_ener[ch] = ONE_IN_Q30;
805 q_old_wet_ener[ch] = 0;
806 run_wet_ener[ch] = 0;
807 q_run_wet_ener[ch] = 0;
808 }
809 for (ch = 0; ch < MAX_INPUT_CHANNELS_MPS; ch++) {
810 sub_band_tp->old_dry_ener[ch] = ONE_IN_Q30;
811 sub_band_tp->q_old_dry_ener[ch] = 0;
812 sub_band_tp->run_dry_ener[ch] = 0;
813 sub_band_tp->q_run_dry_ener[ch] = 0;
814 }
815 }
816
ixheaacd_decorr_init(ia_heaac_mps_state_struct * pstr_mps_state)817 VOID ixheaacd_decorr_init(ia_heaac_mps_state_struct *pstr_mps_state) {
818 VOID *decorr_persistent = pstr_mps_state->mps_persistent_mem.decorr_ptr;
819 WORD32 i, k;
820 WORD32 hybrid_bands = pstr_mps_state->hybrid_bands;
821 WORD32 dec_type = pstr_mps_state->dec_type;
822
823 for (k = 0; k < MAX_NO_DECORR_CHANNELS; k++) {
824 pstr_mps_state->ap_decor[k] = decorr_persistent;
825 decorr_persistent =
826 (WORD8 *)decorr_persistent +
827 IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_decorr_dec_struct), BYTE_ALIGN_8);
828 }
829 for (k = 0; k < MAX_NO_DECORR_CHANNELS; k++) {
830 pstr_mps_state->ap_decor[k]->ducker = decorr_persistent;
831 decorr_persistent =
832 (WORD8 *)decorr_persistent +
833 IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_ducker_interface), BYTE_ALIGN_8) +
834 IXHEAAC_GET_SIZE_ALIGNED(sizeof(ia_mps_dec_duck_instance_struct), BYTE_ALIGN_8);
835 }
836
837 for (k = 0; k < MAX_NO_DECORR_CHANNELS; k++) {
838 for (i = 0; i < hybrid_bands; i++) {
839 pstr_mps_state->ap_decor[k]->filter[i] = decorr_persistent;
840 decorr_persistent = (WORD8 *)decorr_persistent +
841 IXHEAAC_GET_SIZE_ALIGNED(
842 sizeof(ia_mps_dec_decorr_filter_instance_struct), BYTE_ALIGN_8);
843 }
844 }
845
846 if (dec_type == 1) {
847 for (k = 0; k < MAX_NO_DECORR_CHANNELS; k++) {
848 for (i = 0; i < hybrid_bands; i++) {
849 pstr_mps_state->ap_decor[k]->filter[i]->numerator_real = decorr_persistent;
850 decorr_persistent =
851 (WORD8 *)decorr_persistent +
852 IXHEAAC_GET_SIZE_ALIGNED(
853 MAX_NUM_DEN_LENGTH *
854 sizeof(pstr_mps_state->ap_decor[k]->filter[i]->numerator_real[0]),
855 BYTE_ALIGN_8);
856 pstr_mps_state->ap_decor[k]->filter[i]->denominator_real = decorr_persistent;
857 decorr_persistent =
858 (WORD8 *)decorr_persistent +
859 IXHEAAC_GET_SIZE_ALIGNED(
860 MAX_NUM_DEN_LENGTH *
861 sizeof(pstr_mps_state->ap_decor[k]->filter[i]->denominator_real[0]),
862 BYTE_ALIGN_8);
863 pstr_mps_state->ap_decor[k]->filter[i]->numerator_imag = decorr_persistent;
864 decorr_persistent =
865 (WORD8 *)decorr_persistent +
866 IXHEAAC_GET_SIZE_ALIGNED(
867 MAX_NUM_DEN_LENGTH *
868 sizeof(pstr_mps_state->ap_decor[k]->filter[i]->numerator_imag[0]),
869 BYTE_ALIGN_8);
870 pstr_mps_state->ap_decor[k]->filter[i]->denominator_imag = decorr_persistent;
871 decorr_persistent =
872 (WORD8 *)decorr_persistent +
873 IXHEAAC_GET_SIZE_ALIGNED(
874 MAX_NUM_DEN_LENGTH *
875 sizeof(pstr_mps_state->ap_decor[k]->filter[i]->denominator_imag[0]),
876 BYTE_ALIGN_8);
877 }
878 }
879 } else {
880 for (k = 0; k < MAX_NO_DECORR_CHANNELS; k++) {
881 for (i = 0; i < hybrid_bands; i++) {
882 pstr_mps_state->ap_decor[k]->filter[i]->numerator_real = decorr_persistent;
883 decorr_persistent =
884 (WORD8 *)decorr_persistent +
885 IXHEAAC_GET_SIZE_ALIGNED(
886 MAX_NUM_DEN_LENGTH *
887 sizeof(pstr_mps_state->ap_decor[k]->filter[i]->numerator_real[0]),
888 BYTE_ALIGN_8);
889 pstr_mps_state->ap_decor[k]->filter[i]->denominator_real = decorr_persistent;
890 decorr_persistent =
891 (WORD8 *)decorr_persistent +
892 IXHEAAC_GET_SIZE_ALIGNED(
893 MAX_NUM_DEN_LENGTH *
894 sizeof(pstr_mps_state->ap_decor[k]->filter[i]->denominator_real[0]),
895 BYTE_ALIGN_8);
896 }
897 }
898 }
899
900 for (k = 0; k < MAX_NO_DECORR_CHANNELS; k++) {
901 for (i = 0; i < hybrid_bands; i++) {
902 pstr_mps_state->ap_decor[k]->filter[i]->state_real = decorr_persistent;
903 decorr_persistent =
904 (WORD8 *)decorr_persistent +
905 IXHEAAC_GET_SIZE_ALIGNED(
906 MAX_NUM_DEN_LENGTH * sizeof(pstr_mps_state->ap_decor[k]->filter[i]->state_real[0]),
907 BYTE_ALIGN_8);
908 pstr_mps_state->ap_decor[k]->filter[i]->state_imag = decorr_persistent;
909 decorr_persistent =
910 (WORD8 *)decorr_persistent +
911 IXHEAAC_GET_SIZE_ALIGNED(
912 MAX_NUM_DEN_LENGTH * sizeof(pstr_mps_state->ap_decor[k]->filter[i]->state_imag[0]),
913 BYTE_ALIGN_8);
914 }
915 }
916
917 for (k = 0; k < MAX_NO_DECORR_CHANNELS; k++) {
918 pstr_mps_state->ap_decor[k]->delay_buffer_real = (WORD32 **)decorr_persistent;
919 decorr_persistent =
920 (WORD8 *)decorr_persistent +
921 IXHEAAC_GET_SIZE_ALIGNED(
922 hybrid_bands * sizeof(pstr_mps_state->ap_decor[k]->delay_buffer_real[0]),
923 BYTE_ALIGN_8);
924 for (i = 0; i < hybrid_bands; i++) {
925 pstr_mps_state->ap_decor[k]->delay_buffer_real[i] = (WORD32 *)decorr_persistent;
926
927 decorr_persistent = (WORD8 *)decorr_persistent +
928 IXHEAAC_GET_SIZE_ALIGNED(
929 (MAX_TIME_SLOTS + MAX_NO_TIME_SLOTS_DELAY) *
930 sizeof(pstr_mps_state->ap_decor[k]->delay_buffer_real[i][0]),
931 BYTE_ALIGN_8);
932 }
933
934 pstr_mps_state->ap_decor[k]->delay_buffer_imag =
935 (WORD32 **)ALIGN_SIZE64((SIZE_T)(decorr_persistent));
936 decorr_persistent =
937 (WORD8 *)decorr_persistent +
938 IXHEAAC_GET_SIZE_ALIGNED(
939 hybrid_bands * sizeof(pstr_mps_state->ap_decor[k]->delay_buffer_imag[0]),
940 BYTE_ALIGN_8);
941
942 for (i = 0; i < hybrid_bands; i++) {
943 pstr_mps_state->ap_decor[k]->delay_buffer_imag[i] =
944 (WORD32 *)ALIGN_SIZE64((SIZE_T)(decorr_persistent));
945
946 decorr_persistent = (WORD8 *)decorr_persistent +
947 IXHEAAC_GET_SIZE_ALIGNED(
948 (MAX_TIME_SLOTS + MAX_NO_TIME_SLOTS_DELAY) *
949 sizeof(pstr_mps_state->ap_decor[k]->delay_buffer_imag[i][0]),
950 BYTE_ALIGN_8);
951 }
952 }
953 }
954
ixheaacd_bs_frame_init(ia_heaac_mps_state_struct * pstr_mps_state)955 VOID ixheaacd_bs_frame_init(ia_heaac_mps_state_struct *pstr_mps_state) {
956 ia_mps_dec_spatial_bs_frame_struct *bs_frame = pstr_mps_state->bs_frame;
957
958 memset(bs_frame->ott_cld_idx_prev, 0,
959 MAX_NUM_OTT * MAX_PARAMETER_BANDS * sizeof(bs_frame->ott_cld_idx_prev[0][0]));
960 memset(bs_frame->ott_icc_idx_prev, 0,
961 MAX_NUM_OTT * MAX_PARAMETER_BANDS * sizeof(bs_frame->ott_icc_idx_prev[0][0]));
962 memset(bs_frame->cmp_ott_cld_idx_prev, 0,
963 MAX_NUM_OTT * MAX_PARAMETER_BANDS * sizeof(bs_frame->cmp_ott_cld_idx_prev[0][0]));
964 memset(bs_frame->cmp_ott_icc_idx_prev, 0,
965 MAX_NUM_OTT * MAX_PARAMETER_BANDS * sizeof(bs_frame->cmp_ott_icc_idx_prev[0][0]));
966
967 memset(bs_frame->ttt_cpc_1_idx_prev, 0,
968 MAX_NUM_TTT * MAX_PARAMETER_BANDS * sizeof(bs_frame->ttt_cpc_1_idx_prev[0][0]));
969 memset(bs_frame->ttt_cpc_2_idx_prev, 0,
970 MAX_NUM_TTT * MAX_PARAMETER_BANDS * sizeof(bs_frame->ttt_cpc_2_idx_prev[0][0]));
971 memset(bs_frame->ttt_cld_1_idx_prev, 0,
972 MAX_NUM_TTT * MAX_PARAMETER_BANDS * sizeof(bs_frame->ttt_cld_1_idx_prev[0][0]));
973 memset(bs_frame->ttt_cld_2_idx_prev, 0,
974 MAX_NUM_TTT * MAX_PARAMETER_BANDS * sizeof(bs_frame->ttt_cld_2_idx_prev[0][0]));
975 memset(bs_frame->ttt_icc_idx_prev, 0,
976 MAX_NUM_TTT * MAX_PARAMETER_BANDS * sizeof(bs_frame->ttt_icc_idx_prev[0][0]));
977 memset(bs_frame->cmp_ttt_cpc_1_idx_prev, 0,
978 MAX_NUM_TTT * MAX_PARAMETER_BANDS * sizeof(bs_frame->cmp_ttt_cpc_1_idx_prev[0][0]));
979 memset(bs_frame->cmp_ttt_cpc_2_idx_prev, 0,
980 MAX_NUM_TTT * MAX_PARAMETER_BANDS * sizeof(bs_frame->cmp_ttt_cpc_2_idx_prev[0][0]));
981 memset(bs_frame->cmp_ttt_cld_1_idx_prev, 0,
982 MAX_NUM_TTT * MAX_PARAMETER_BANDS * sizeof(bs_frame->cmp_ttt_cld_1_idx_prev[0][0]));
983 memset(bs_frame->cmp_ttt_cld_2_idx_prev, 0,
984 MAX_NUM_TTT * MAX_PARAMETER_BANDS * sizeof(bs_frame->cmp_ttt_cld_2_idx_prev[0][0]));
985 memset(bs_frame->cmp_ttt_icc_idx_prev, 0,
986 MAX_NUM_TTT * MAX_PARAMETER_BANDS * sizeof(bs_frame->cmp_ttt_icc_idx_prev[0][0]));
987
988 memset(bs_frame->arbdmx_gain_idx_prev, 0,
989 MAX_INPUT_CHANNELS_MPS * MAX_PARAMETER_BANDS *
990 sizeof(bs_frame->arbdmx_gain_idx_prev[0][0]));
991 memset(bs_frame->cmp_arbdmx_gain_idx_prev, 0,
992 MAX_INPUT_CHANNELS_MPS * MAX_PARAMETER_BANDS *
993 sizeof(bs_frame->cmp_arbdmx_gain_idx_prev[0][0]));
994 }
995
ixheaacd_modules_init(ia_heaac_mps_state_struct * pstr_mps_state)996 IA_ERRORCODE ixheaacd_modules_init(ia_heaac_mps_state_struct *pstr_mps_state) {
997 IA_ERRORCODE err_code = IA_NO_ERROR;
998 ia_mps_dec_thyb_filter_state_struct *hyb_filter_state =
999 pstr_mps_state->mps_persistent_mem.hyb_filter_state;
1000 WORD32 up_mix_type = pstr_mps_state->up_mix_type;
1001 WORD32 in_channels = pstr_mps_state->num_input_channels;
1002 WORD32 n_ch;
1003 if (pstr_mps_state->smooth_config) ixheaacd_init_tonality(pstr_mps_state);
1004
1005 if (up_mix_type != 2) {
1006 if (pstr_mps_state->temp_shape_config == 2) {
1007 ixheaacd_init_bb_env(pstr_mps_state);
1008 }
1009 }
1010
1011 if (pstr_mps_state->scaling_enable == 1) ixheaacd_sb_tp_init(pstr_mps_state);
1012
1013 err_code = ixheaacd_syn_filt_bank_init(pstr_mps_state->syn, pstr_mps_state->qmf_bands);
1014
1015 if (err_code != IA_NO_ERROR) return err_code;
1016
1017 for (n_ch = 0; n_ch < in_channels; n_ch++) {
1018 ixheaacd_init_ana_hyb_filt_bank(&hyb_filter_state[n_ch]);
1019 }
1020
1021 for (n_ch = 0; n_ch < in_channels; n_ch++) {
1022 pstr_mps_state->aux_struct->arbdmx_alpha[n_ch] = 0;
1023 }
1024
1025 memset(&pstr_mps_state->aux_struct->ttt_cld_1[0], 0, 8 * 28 * sizeof(WORD32));
1026
1027 if (pstr_mps_state->residual_coding) {
1028 WORD32 offset = in_channels;
1029 for (n_ch = 0; n_ch < pstr_mps_state->num_ott_boxes + pstr_mps_state->num_ttt_boxes; n_ch++) {
1030 if (pstr_mps_state->res_bands[n_ch] > 0) {
1031 ixheaacd_init_ana_hyb_filt_bank(&hyb_filter_state[offset + n_ch]);
1032 }
1033 }
1034 }
1035
1036 if (pstr_mps_state->arbitrary_downmix == 2) {
1037 WORD32 offset = in_channels + pstr_mps_state->num_ott_boxes + pstr_mps_state->num_ttt_boxes;
1038 for (n_ch = 0; n_ch < in_channels; n_ch++) {
1039 ixheaacd_init_ana_hyb_filt_bank(&hyb_filter_state[offset + n_ch]);
1040 }
1041 }
1042 if (up_mix_type == 1) {
1043 ixheaacd_init_blind(pstr_mps_state);
1044 }
1045
1046 pstr_mps_state->parse_next_bitstream_frame = 1;
1047
1048 ixheaacd_bs_frame_init(pstr_mps_state);
1049
1050 return err_code;
1051 }
1052
ixheaacd_header_parse(ia_heaac_mps_state_struct * pstr_mps_state)1053 IA_ERRORCODE ixheaacd_header_parse(ia_heaac_mps_state_struct *pstr_mps_state) {
1054 IA_ERRORCODE err_code = IA_NO_ERROR;
1055 WORD32 up_mix_type = pstr_mps_state->up_mix_type;
1056 WORD32 sac_header_len, alignment_bits = 0;
1057 ia_bit_buf_struct *mps_bit_buf = pstr_mps_state->ptr_mps_bit_buff;
1058
1059 if (up_mix_type != 1) {
1060 pstr_mps_state->sac_time_align_flag = ixheaacd_read_bits_buf(mps_bit_buf, 1);
1061
1062 sac_header_len = ixheaacd_read_bits_buf(mps_bit_buf, 7);
1063 if (sac_header_len == 127) {
1064 sac_header_len += ixheaacd_read_bits_buf(mps_bit_buf, 16);
1065 }
1066
1067 err_code = ixheaacd_parse_specific_config(pstr_mps_state, sac_header_len);
1068 if (err_code != IA_NO_ERROR) return err_code;
1069
1070 if (pstr_mps_state->bs_config.bs_temp_shape_config == 1) pstr_mps_state->scaling_enable = 1;
1071
1072 ixheaacd_byte_align(mps_bit_buf, &alignment_bits);
1073 } else {
1074 err_code = ixheaacd_default_specific_config(pstr_mps_state, pstr_mps_state->sampling_freq);
1075 if (err_code != IA_NO_ERROR) return err_code;
1076 }
1077 return err_code;
1078 }
1079
ixheaacd_aac_mps_create(ia_heaac_mps_state_struct * pstr_mps_state)1080 IA_ERRORCODE ixheaacd_aac_mps_create(ia_heaac_mps_state_struct *pstr_mps_state) {
1081 WORD32 i, j, k;
1082 WORD32 *prev_gain_at = pstr_mps_state->mps_persistent_mem.prev_gain_at;
1083 IA_ERRORCODE err_code = IA_NO_ERROR;
1084 WORD32 dec_type = pstr_mps_state->dec_type;
1085 WORD32 up_mix_type = pstr_mps_state->up_mix_type;
1086 WORD32 in_channels = pstr_mps_state->num_input_channels;
1087
1088 if (pstr_mps_state == 0) return IA_XHEAAC_DEC_INIT_FATAL_DEC_INIT_FAIL;
1089
1090 pstr_mps_state->num_parameter_sets = 1;
1091
1092 for (i = 0; i < MAX_OUTPUT_CHANNELS_AT_MPS; i++) {
1093 for (j = 0; j < MAX_PARAMETER_BANDS; j++) {
1094 *prev_gain_at++ = ONE_IN_Q15;
1095 }
1096 }
1097
1098 for (i = 0; i < in_channels; i++) {
1099 ixheaacd_ana_filter_bank_init(pstr_mps_state, &(pstr_mps_state->qmf_bank[i]));
1100 }
1101
1102 ixheaacd_syn_filter_bank_create(pstr_mps_state);
1103
1104 err_code = ixheaacd_set_current_state_parameters(pstr_mps_state);
1105 if (err_code != IA_NO_ERROR) return err_code;
1106
1107 err_code = ixheaacd_set_m2_params(pstr_mps_state);
1108 if (err_code != IA_NO_ERROR) return err_code;
1109
1110 err_code = ixheaacd_mdct2qmf_create(pstr_mps_state);
1111 if (err_code != IA_NO_ERROR) return err_code;
1112
1113 ixheaacd_decorr_init(pstr_mps_state);
1114
1115 for (k = 0; k < MAX_NO_DECORR_CHANNELS; k++) {
1116 WORD32 idec;
1117
1118 if (up_mix_type == 3) {
1119 idec = 0;
1120 } else {
1121 idec = k;
1122 }
1123
1124 err_code = ixheaacd_decorr_create((pstr_mps_state->ap_decor[k]), pstr_mps_state->hybrid_bands,
1125 idec, dec_type, pstr_mps_state->decorr_config,
1126 &(pstr_mps_state->ia_mps_dec_mps_table));
1127 if (err_code != IA_NO_ERROR) return err_code;
1128 }
1129
1130 err_code = ixheaacd_modules_init(pstr_mps_state);
1131
1132 return err_code;
1133 }
1134
ixheaacd_wf_table_init(ia_heaac_mps_state_struct * pstr_mps_state)1135 VOID ixheaacd_wf_table_init(ia_heaac_mps_state_struct *pstr_mps_state) {
1136 WORD32 const **wf = pstr_mps_state->wf_tab.wf;
1137 ia_mps_dec_mps_tables_struct *mps_table_ptr = &pstr_mps_state->ia_mps_dec_mps_table;
1138
1139 wf[0] = NULL;
1140 wf[1] = ixheaacd_mps_dec_wf_tables.wf_02;
1141 wf[2] = ixheaacd_mps_dec_wf_tables.wf_03;
1142 wf[3] = ixheaacd_mps_dec_wf_tables.wf_04;
1143 wf[4] = NULL;
1144 wf[5] = NULL;
1145 wf[6] = NULL;
1146 wf[7] = NULL;
1147 wf[8] = NULL;
1148 wf[9] = NULL;
1149 wf[10] = NULL;
1150 wf[11] = NULL;
1151 wf[12] = NULL;
1152 wf[13] = NULL;
1153 wf[14] = ixheaacd_mps_dec_wf_tables.wf_15;
1154 wf[15] = ixheaacd_mps_dec_wf_tables.wf_16;
1155 wf[16] = NULL;
1156 wf[17] = ixheaacd_mps_dec_wf_tables.wf_18;
1157 wf[18] = NULL;
1158 wf[19] = NULL;
1159 wf[20] = NULL;
1160 wf[21] = NULL;
1161 wf[22] = NULL;
1162 wf[23] = ixheaacd_mps_dec_wf_tables.wf_24;
1163 wf[24] = NULL;
1164 wf[25] = NULL;
1165 wf[26] = NULL;
1166 wf[27] = NULL;
1167 wf[28] = NULL;
1168 wf[29] = ixheaacd_mps_dec_wf_tables.wf_30;
1169 wf[30] = NULL;
1170 wf[31] = ixheaacd_mps_dec_wf_tables.wf_32;
1171
1172 mps_table_ptr->wf_tab_ptr = &(pstr_mps_state->wf_tab);
1173 }
1174
ixheaacd_res_huff_tables_init(ia_mps_dec_residual_aac_tables_struct * aac_tables_ptr)1175 VOID ixheaacd_res_huff_tables_init(ia_mps_dec_residual_aac_tables_struct *aac_tables_ptr) {
1176 aac_tables_ptr->code_book[0] = 0;
1177 aac_tables_ptr->code_book[1] = aac_tables_ptr->res_huffmann_tables_ptr->huffman_code_book_1;
1178 aac_tables_ptr->code_book[2] = aac_tables_ptr->res_huffmann_tables_ptr->huffman_code_book_2;
1179 aac_tables_ptr->code_book[3] = aac_tables_ptr->res_huffmann_tables_ptr->huffman_code_book_3;
1180 aac_tables_ptr->code_book[4] = aac_tables_ptr->res_huffmann_tables_ptr->huffman_code_book_4;
1181 aac_tables_ptr->code_book[5] = aac_tables_ptr->res_huffmann_tables_ptr->huffman_code_book_5;
1182 aac_tables_ptr->code_book[6] = aac_tables_ptr->res_huffmann_tables_ptr->huffman_code_book_6;
1183 aac_tables_ptr->code_book[7] = aac_tables_ptr->res_huffmann_tables_ptr->huffman_code_book_7;
1184 aac_tables_ptr->code_book[8] = aac_tables_ptr->res_huffmann_tables_ptr->huffman_code_book_8;
1185 aac_tables_ptr->code_book[9] = aac_tables_ptr->res_huffmann_tables_ptr->huffman_code_book_9;
1186 aac_tables_ptr->code_book[10] = aac_tables_ptr->res_huffmann_tables_ptr->huffman_code_book_10;
1187 aac_tables_ptr->code_book[11] = aac_tables_ptr->res_huffmann_tables_ptr->huffman_code_book_10;
1188 aac_tables_ptr->code_book[12] = aac_tables_ptr->res_huffmann_tables_ptr->huffman_code_book_10;
1189
1190 aac_tables_ptr->scale_factor_bands_short[0] =
1191 aac_tables_ptr->res_huffmann_tables_ptr->sfb_96_128;
1192 aac_tables_ptr->scale_factor_bands_short[1] =
1193 aac_tables_ptr->res_huffmann_tables_ptr->sfb_96_128;
1194 aac_tables_ptr->scale_factor_bands_short[2] =
1195 aac_tables_ptr->res_huffmann_tables_ptr->sfb_96_128;
1196 aac_tables_ptr->scale_factor_bands_short[3] =
1197 aac_tables_ptr->res_huffmann_tables_ptr->sfb_48_128;
1198 aac_tables_ptr->scale_factor_bands_short[4] =
1199 aac_tables_ptr->res_huffmann_tables_ptr->sfb_48_128;
1200 aac_tables_ptr->scale_factor_bands_short[5] =
1201 aac_tables_ptr->res_huffmann_tables_ptr->sfb_48_128;
1202 aac_tables_ptr->scale_factor_bands_short[6] =
1203 aac_tables_ptr->res_huffmann_tables_ptr->sfb_24_128;
1204 aac_tables_ptr->scale_factor_bands_short[7] =
1205 aac_tables_ptr->res_huffmann_tables_ptr->sfb_24_128;
1206 aac_tables_ptr->scale_factor_bands_short[8] =
1207 aac_tables_ptr->res_huffmann_tables_ptr->sfb_16_128;
1208 aac_tables_ptr->scale_factor_bands_short[9] =
1209 aac_tables_ptr->res_huffmann_tables_ptr->sfb_16_128;
1210 aac_tables_ptr->scale_factor_bands_short[10] =
1211 aac_tables_ptr->res_huffmann_tables_ptr->sfb_16_128;
1212 aac_tables_ptr->scale_factor_bands_short[11] =
1213 aac_tables_ptr->res_huffmann_tables_ptr->sfb_8_128;
1214 aac_tables_ptr->scale_factor_bands_short[12] =
1215 aac_tables_ptr->res_huffmann_tables_ptr->sfb_96_120;
1216 aac_tables_ptr->scale_factor_bands_short[13] =
1217 aac_tables_ptr->res_huffmann_tables_ptr->sfb_96_120;
1218 aac_tables_ptr->scale_factor_bands_short[14] =
1219 aac_tables_ptr->res_huffmann_tables_ptr->sfb_96_120;
1220 aac_tables_ptr->scale_factor_bands_short[15] =
1221 aac_tables_ptr->res_huffmann_tables_ptr->sfb_48_120;
1222 aac_tables_ptr->scale_factor_bands_short[16] =
1223 aac_tables_ptr->res_huffmann_tables_ptr->sfb_48_120;
1224 aac_tables_ptr->scale_factor_bands_short[17] =
1225 aac_tables_ptr->res_huffmann_tables_ptr->sfb_48_120;
1226 aac_tables_ptr->scale_factor_bands_short[18] =
1227 aac_tables_ptr->res_huffmann_tables_ptr->sfb_24_120;
1228 aac_tables_ptr->scale_factor_bands_short[19] =
1229 aac_tables_ptr->res_huffmann_tables_ptr->sfb_24_120;
1230 aac_tables_ptr->scale_factor_bands_short[20] =
1231 aac_tables_ptr->res_huffmann_tables_ptr->sfb_16_120;
1232 aac_tables_ptr->scale_factor_bands_short[21] =
1233 aac_tables_ptr->res_huffmann_tables_ptr->sfb_16_120;
1234 aac_tables_ptr->scale_factor_bands_short[22] =
1235 aac_tables_ptr->res_huffmann_tables_ptr->sfb_16_120;
1236 aac_tables_ptr->scale_factor_bands_short[23] =
1237 aac_tables_ptr->res_huffmann_tables_ptr->sfb_8_120;
1238
1239 aac_tables_ptr->scale_factor_bands_long[0] =
1240 aac_tables_ptr->res_huffmann_tables_ptr->sfb_96_1024;
1241 aac_tables_ptr->scale_factor_bands_long[1] =
1242 aac_tables_ptr->res_huffmann_tables_ptr->sfb_96_1024;
1243 aac_tables_ptr->scale_factor_bands_long[2] =
1244 aac_tables_ptr->res_huffmann_tables_ptr->sfb_64_1024;
1245 aac_tables_ptr->scale_factor_bands_long[3] =
1246 aac_tables_ptr->res_huffmann_tables_ptr->sfb_48_1024;
1247 aac_tables_ptr->scale_factor_bands_long[4] =
1248 aac_tables_ptr->res_huffmann_tables_ptr->sfb_48_1024;
1249 aac_tables_ptr->scale_factor_bands_long[5] =
1250 aac_tables_ptr->res_huffmann_tables_ptr->sfb_32_1024;
1251 aac_tables_ptr->scale_factor_bands_long[6] =
1252 aac_tables_ptr->res_huffmann_tables_ptr->sfb_24_1024;
1253 aac_tables_ptr->scale_factor_bands_long[7] =
1254 aac_tables_ptr->res_huffmann_tables_ptr->sfb_24_1024;
1255 aac_tables_ptr->scale_factor_bands_long[8] =
1256 aac_tables_ptr->res_huffmann_tables_ptr->sfb_16_1024;
1257 aac_tables_ptr->scale_factor_bands_long[9] =
1258 aac_tables_ptr->res_huffmann_tables_ptr->sfb_16_1024;
1259 aac_tables_ptr->scale_factor_bands_long[10] =
1260 aac_tables_ptr->res_huffmann_tables_ptr->sfb_16_1024;
1261 aac_tables_ptr->scale_factor_bands_long[11] =
1262 aac_tables_ptr->res_huffmann_tables_ptr->sfb_8_1024;
1263 aac_tables_ptr->scale_factor_bands_long[12] =
1264 aac_tables_ptr->res_huffmann_tables_ptr->sfb_96_960;
1265 aac_tables_ptr->scale_factor_bands_long[13] =
1266 aac_tables_ptr->res_huffmann_tables_ptr->sfb_96_960;
1267 aac_tables_ptr->scale_factor_bands_long[14] =
1268 aac_tables_ptr->res_huffmann_tables_ptr->sfb_64_960;
1269 aac_tables_ptr->scale_factor_bands_long[15] =
1270 aac_tables_ptr->res_huffmann_tables_ptr->sfb_48_960;
1271 aac_tables_ptr->scale_factor_bands_long[16] =
1272 aac_tables_ptr->res_huffmann_tables_ptr->sfb_48_960;
1273 aac_tables_ptr->scale_factor_bands_long[17] =
1274 aac_tables_ptr->res_huffmann_tables_ptr->sfb_48_960;
1275 aac_tables_ptr->scale_factor_bands_long[18] =
1276 aac_tables_ptr->res_huffmann_tables_ptr->sfb_24_960;
1277 aac_tables_ptr->scale_factor_bands_long[19] =
1278 aac_tables_ptr->res_huffmann_tables_ptr->sfb_24_960;
1279 aac_tables_ptr->scale_factor_bands_long[20] =
1280 aac_tables_ptr->res_huffmann_tables_ptr->sfb_16_960;
1281 aac_tables_ptr->scale_factor_bands_long[21] =
1282 aac_tables_ptr->res_huffmann_tables_ptr->sfb_16_960;
1283 aac_tables_ptr->scale_factor_bands_long[22] =
1284 aac_tables_ptr->res_huffmann_tables_ptr->sfb_16_960;
1285 aac_tables_ptr->scale_factor_bands_long[23] =
1286 aac_tables_ptr->res_huffmann_tables_ptr->sfb_8_960;
1287 }
1288
ixheaacd_table_ptr_init(ia_heaac_mps_state_struct * pstr_mps_state)1289 static VOID ixheaacd_table_ptr_init(ia_heaac_mps_state_struct *pstr_mps_state) {
1290 ia_mps_dec_mps_tables_struct *mps_table_ptr = &pstr_mps_state->ia_mps_dec_mps_table;
1291 ia_mps_dec_residual_aac_tables_struct *aac_table_ptr = &pstr_mps_state->aac_table;
1292
1293 mps_table_ptr->qmf_table_ptr = (ia_mps_dec_qmf_tables_struct *)&ixheaacd_mps_dec_qmf_tables;
1294 mps_table_ptr->common_table_ptr =
1295 (ia_mps_dec_common_tables_struct *)&ixheaacd_mps_dec_common_tables;
1296 mps_table_ptr->hybrid_table_ptr =
1297 (ia_mps_dec_hybrid_tables_struct *)&ixheaacd_mps_dec_hybrid_tables;
1298 mps_table_ptr->m1_m2_table_ptr =
1299 (ia_mps_dec_m1_m2_tables_struct *)&ixheaacd_mps_dec_m1_m2_tables;
1300 mps_table_ptr->decor_table_ptr =
1301 (ia_mps_dec_decorr_tables_struct *)&ixheaacd_mps_dec_decorr_tables;
1302 mps_table_ptr->tp_process_table_ptr =
1303 (ia_mps_dec_tp_process_tables_struct *)&ixheaacd_mps_dec_tp_process_tables;
1304
1305 mps_table_ptr->mdct2qmf_table_ptr =
1306 (ia_mps_dec_mdct2qmf_table_struct *)&ixheaacd_mps_dec_mdct2qmf_table;
1307
1308 mps_table_ptr->tonality_table_ptr =
1309 (ia_mps_dec_tonality_tables_struct *)&ixheaacd_mps_dec_tonality_tables;
1310
1311 mps_table_ptr->bitdec_table_ptr =
1312 (ia_mps_dec_bitdec_tables_struct *)&ixheaacd_mps_dec_bitdec_tables;
1313 mps_table_ptr->blind_table_ptr =
1314 (ia_mps_dec_blind_tables_struct *)&ixheaacd_mps_dec_blind_tables;
1315
1316 mps_table_ptr->mdct2qmfcos_table_ptr =
1317 (ia_mps_dec_mdct2qmf_tables_struct *)&ixheaacd_mps_dec_mdct2qmf_tables;
1318 mps_table_ptr->mdct2qmfcos_tab_ptr =
1319 (ia_mps_dec_mdct2qmf_cos_table_struct *)&pstr_mps_state->ia_mps_dec_mdct2qmfcos_table;
1320 aac_table_ptr->res_huffmann_tables_ptr =
1321 (ia_mps_dec_res_huffmann_tables_struct *)&ixheaacd_mps_dec_res_huffmann_tables;
1322 aac_table_ptr->res_block_tables_ptr =
1323 (ia_mps_dec_res_block_tables_struct *)&ixheaacd_mps_dec_res_block_tables;
1324
1325 ixheaacd_res_huff_tables_init(aac_table_ptr);
1326
1327 mps_table_ptr->aac_tab = aac_table_ptr;
1328
1329 ixheaacd_wf_table_init(pstr_mps_state);
1330 }
1331
ixheaacd_aac_mps_init(ia_exhaacplus_dec_api_struct * p_obj_mps_dec,UWORD8 * databuf,WORD32 buffer_size,WORD32 sample_rate)1332 IA_ERRORCODE ixheaacd_aac_mps_init(ia_exhaacplus_dec_api_struct *p_obj_mps_dec, UWORD8 *databuf,
1333 WORD32 buffer_size, WORD32 sample_rate) {
1334 WORD32 i;
1335
1336 VOID *buf_ptr;
1337 ia_mps_persistent_mem *persistent_mem =
1338 &p_obj_mps_dec->p_state_aac->heaac_mps_handle.mps_persistent_mem;
1339
1340 IA_ERRORCODE err_code = IA_NO_ERROR;
1341 ia_heaac_mps_state_struct *curr_state = &p_obj_mps_dec->p_state_aac->heaac_mps_handle;
1342 ia_mps_spatial_bs_config_struct *p_bs_config = &curr_state->bs_config;
1343 curr_state->ec_flag = p_obj_mps_dec->p_state_aac->ec_enable;
1344 ixheaacd_table_ptr_init(curr_state);
1345
1346 curr_state->ptr_mps_bit_buff =
1347 ixheaacd_create_bit_buf(&curr_state->mps_bit_buf, (UWORD8 *)databuf, buffer_size);
1348 curr_state->ptr_mps_bit_buff->cnt_bits += (8 * buffer_size);
1349
1350 curr_state->ptr_mps_bit_buff->xaac_jmp_buf = &p_obj_mps_dec->p_state_aac->xaac_jmp_buf;
1351
1352 if (sample_rate < 27713) {
1353 curr_state->qmf_bands = 32;
1354 } else if (sample_rate >= 55426) {
1355 curr_state->qmf_bands = 128;
1356 } else {
1357 curr_state->qmf_bands = 64;
1358 }
1359
1360 curr_state->sampling_freq = sample_rate;
1361 curr_state->num_input_channels = p_obj_mps_dec->p_state_aac->p_config->ui_n_channels;
1362 curr_state->bits_per_sample = p_obj_mps_dec->p_state_aac->p_config->ui_pcm_wdsz;
1363 curr_state->dec_type = p_bs_config->ui_dec_type;
1364 curr_state->up_mix_type = p_bs_config->ui_upmix_type;
1365 curr_state->binaural_quality = p_bs_config->ui_binaural_quality;
1366 curr_state->hrtf_model = p_bs_config->ui_hrtf_model;
1367 curr_state->is_buried_flag = p_bs_config->ui_bs_is_buried;
1368
1369 curr_state->bs_frame = persistent_mem->p_bs_frame;
1370
1371 buf_ptr = persistent_mem->syn_qmf_states_buffer;
1372 curr_state->syn = buf_ptr;
1373
1374 curr_state->syn_qmf_bank.sbr_qmf_states_synthesis =
1375 (WORD32 *)((WORD8 *)buf_ptr + sizeof(ia_mps_dec_synthesis_interface));
1376
1377 buf_ptr = persistent_mem->ana_qmf_states_buffer;
1378
1379 memset(curr_state->m2_param_present, 0,
1380 MAX_M2_OUTPUT * MAX_M2_INPUT * sizeof(curr_state->m2_param_present[0][0]));
1381 memset(&(curr_state->bs_config), 0, sizeof(ia_mps_spatial_bs_config_struct));
1382 memset(&(curr_state->res_block_type), 0,
1383 sizeof(WORD32) * MAX_RESIDUAL_CHANNELS_MPS * MAX_RESIDUAL_FRAMES);
1384
1385 curr_state->bs_config.ui_pcm_wdsz = 16;
1386 curr_state->bs_config.ui_samp_freq = 48000;
1387 curr_state->bs_config.ui_in_channels = 2;
1388 curr_state->bs_config.ui_qmf_bands = 64;
1389
1390 err_code = ixheaacd_header_parse(curr_state);
1391 if (err_code != IA_NO_ERROR) return err_code;
1392
1393 for (i = 0; i < curr_state->num_input_channels; i++) {
1394 curr_state->qmf_bank[i].qmf_states_buffer = buf_ptr;
1395 buf_ptr = (WORD8 *)buf_ptr + QMF_FILTER_STATE_ANA_SIZE_MPS * sizeof(WORD32);
1396 }
1397
1398 curr_state->i_bytes_consumed_mps = (WORD32)(curr_state->ptr_mps_bit_buff->ptr_read_next -
1399 curr_state->ptr_mps_bit_buff->ptr_bit_buf_base);
1400
1401 curr_state->bytes_remaining = buffer_size - curr_state->i_bytes_consumed_mps;
1402
1403 if (curr_state->bytes_remaining != 0) {
1404 for (WORD32 ii = 0; ii < curr_state->bytes_remaining; ii++) {
1405 curr_state->temp_buf[ii] = databuf[ii + curr_state->i_bytes_consumed_mps];
1406 }
1407 }
1408
1409 err_code = ixheaacd_aac_mps_create(curr_state);
1410 if (err_code != IA_NO_ERROR) return err_code;
1411
1412 curr_state->mps_init_done = 1;
1413 curr_state->first_frame = 1;
1414
1415 return err_code;
1416 }
1417