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