• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *                                                                            *
3  * Copyright (C) 2018 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 #ifndef IXHEAACD_MPS_DEC_H
21 #define IXHEAACD_MPS_DEC_H
22 
23 #include "stddef.h"
24 
25 #define ABS_THR (1e-9f * 32768 * 32768)
26 
27 #define MAX_NUM_QMF_BANDS_MPS (128)
28 #define MAX_NUM_QMF_BANDS_MPS_NEW (64)
29 
30 #define MAX_PARAMETER_SETS_MPS (9)
31 #define BUFFER_LEN_HF_MPS ((QMF_HYBRID_FILT_ORDER - 1) / 2 + MAX_TIME_SLOTS)
32 
33 #define DECORR_FILTER_ORDER_BAND_0 (20)
34 #define DECORR_FILTER_ORDER_BAND_1 (15)
35 #define DECORR_FILTER_ORDER_BAND_2 (6)
36 #define DECORR_FILTER_ORDER_BAND_3 (3)
37 
38 #define MAX_DECORR_FILTER_ORDER (DECORR_FILTER_ORDER_BAND_0)
39 
40 #define DECORR_FILT_0_ORD (10)
41 #define DECORR_FILT_1_ORD (8)
42 #define DECORR_FILT_2_ORD (3)
43 #define DECORR_FILT_3_ORD (2)
44 
45 #define NO_RES_BANDS -1
46 
47 #define MAX_HYBRID_BANDS_MPS (MAX_NUM_QMF_BANDS_MPS_NEW - 3 + 10)
48 #define MAX_TIME_SLOTS (72)
49 
50 #define QMF_HYBRID_FILT_ORDER (13)
51 #define BUFFER_LEN_LF_MPS (QMF_HYBRID_FILT_ORDER - 1 + MAX_TIME_SLOTS)
52 #define MAX_NO_TIME_SLOTS_DELAY (14)
53 
54 #define MAXNRSBRCHANNELS 2
55 #define abs(x) (x < 0) ? -x : x
56 
57 #define PC_FILTERLENGTH (11)
58 #define PC_FILTERDELAY ((PC_FILTERLENGTH - 1) / 2)
59 #define ABS_THR_FIX (35184)
60 
61 #ifndef MAX_NUM_QMF_BANDS
62 #define MAX_NUM_QMF_BANDS (64)
63 #endif
64 
65 #define MAX_HYBRID_BANDS (MAX_NUM_QMF_BANDS - 3 + 10)
66 #define MAX_INPUT_CHANNELS_MPS (6)
67 
68 #define MAX_RESIDUAL_CHANNELS_MPS (10)
69 #define MAX_RESIDUAL_FRAMES (4)
70 
71 #define MAX_OUTPUT_CHANNELS_MPS (8)
72 #define MAX_NUM_PARAMS (MAX_NUM_OTT + 4 * MAX_NUM_TTT + MAX_INPUT_CHANNELS_MPS)
73 
74 #define MAX_PARAMETER_SETS (8)
75 
76 #define MAX_M1_OUTPUT (8)
77 #define MAX_M2_INPUT (8)
78 #define MAX_M2_OUTPUT (8)
79 
80 #define PROTO_LEN (13)
81 #define BUFFER_LEN_LF (PROTO_LEN - 1 + MAX_TIME_SLOTS)
82 #define BUFFER_LEN_HF ((PROTO_LEN - 1) / 2 + MAX_TIME_SLOTS)
83 
84 #define MAX_NO_DECORR_CHANNELS (5)
85 
86 #define MAX_OUTPUT_CHANNELS_AT_MPS (8)
87 
88 #define QMF_FILTER_STATE_SYN_SIZE_MPS (576)
89 
90 #define QMF_FILTER_STATE_ANA_SIZE_MPS (640)
91 
92 #define MAX_NUM_POAT max(MAX_NUM_PARAMS, MAX_NUM_OTT + MAX_OUTPUT_CHANNELS_AT)
93 
94 #define BP_SIZE 25
95 
96 typedef struct {
97   FLOAT32 re;
98   FLOAT32 im;
99 
100 } ia_cmplx_flt_struct;
101 
102 typedef struct {
103   WORD32 re;
104   WORD32 im;
105 } ia_cmplx_w32_struct;
106 
107 typedef struct {
108   FLOAT32 *re;
109   FLOAT32 *im;
110 } ia_cmplx_fltp_struct;
111 
112 typedef struct ia_mps_decor_filt_struct {
113   WORD32 state_len;
114   WORD32 num_len;
115   WORD32 den_len;
116 
117   ia_cmplx_flt_struct state[MAX_DECORR_FILTER_ORDER + 1];
118   const FLOAT32 *num;
119   const FLOAT32 *den;
120 
121 } ia_mps_decor_filt_struct;
122 
123 typedef struct ixheaacd_mps_decor_energy_adjust_filt_struct {
124   WORD32 num_bins;
125   FLOAT32 smooth_in_energy[MAX_PARAMETER_BANDS];
126   FLOAT32 smooth_out_energy[MAX_PARAMETER_BANDS];
127 
128 } ixheaacd_mps_decor_energy_adjust_filt_struct;
129 
130 typedef struct ia_mps_decor_struct {
131   WORD32 num_bins;
132   ia_mps_decor_filt_struct filter[MAX_HYBRID_BANDS_MPS];
133   ixheaacd_mps_decor_energy_adjust_filt_struct decor_nrg_smooth;
134 
135   WORD32 delay_sample_count[MAX_HYBRID_BANDS_MPS];
136 
137   ia_cmplx_flt_struct
138       decor_delay_buffer[71][MAX_TIME_SLOTS + MAX_NO_TIME_SLOTS_DELAY];
139 
140 } ia_mps_decor_struct;
141 
142 typedef struct ia_mps_hybrid_filt_struct {
143   ia_cmplx_flt_struct hf_buffer[MAX_NUM_QMF_BANDS_MPS][BUFFER_LEN_HF_MPS];
144   ia_cmplx_flt_struct lf_buffer[QMF_BANDS_TO_HYBRID][BUFFER_LEN_LF_MPS];
145 } ia_mps_hybrid_filt_struct;
146 
147 typedef struct ia_mps_data_struct {
148   WORD32 bs_xxx_data_mode[MAX_PARAMETER_SETS_MPS];
149   WORD32 quant_coarse_xxx_flag[MAX_PARAMETER_SETS_MPS];
150   WORD32 bs_freq_res_stride_xxx[MAX_PARAMETER_SETS_MPS];
151   WORD8 bs_quant_coarse_xxx[MAX_PARAMETER_SETS_MPS];
152   WORD8 bs_quant_coarse_xxx_prev;
153 } ia_mps_data_struct;
154 
155 typedef struct ia_mps_bs_frame {
156   WORD8 independency_flag;
157 
158   WORD32 cld_idx[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS];
159   WORD32 icc_idx[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS];
160 
161   WORD32 cld_idx_pre[MAX_PARAMETER_BANDS];
162   WORD32 icc_idx_pre[MAX_PARAMETER_BANDS];
163 
164   WORD32 cmp_cld_idx[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS];
165   WORD32 cmp_icc_idx[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS];
166 
167   WORD32 cmp_cld_idx_prev[MAX_PARAMETER_BANDS];
168   WORD32 cmp_icc_idx_prev[MAX_PARAMETER_BANDS];
169 
170   ia_mps_data_struct cld_data;
171   ia_mps_data_struct icc_data;
172   ia_mps_data_struct ipd_data;
173 
174   WORD32 ipd_idx_data[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS];
175   WORD32 ipd_idx_data_prev[MAX_PARAMETER_BANDS];
176   WORD32 ipd_idx[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS];
177   WORD32 ipd_idx_prev[MAX_PARAMETER_BANDS];
178 
179   WORD32 bs_smooth_mode[MAX_PARAMETER_SETS_MPS];
180   WORD32 bs_smooth_time[MAX_PARAMETER_SETS_MPS];
181   WORD32 bs_freq_res_stride_smg[MAX_PARAMETER_SETS_MPS];
182   WORD32 bs_smg_data[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS];
183 
184 } ia_mps_bs_frame;
185 
186 typedef struct ia_mps_smoothing_struct {
187   WORD32 prev_smg_time;
188   FLOAT32 inv_prev_smg_time;
189   WORD32 prev_smg_data[MAX_PARAMETER_BANDS];
190 } ia_mps_smoothing_struct;
191 
192 typedef struct ia_mps_env_reshape_struct {
193   FLOAT32 pb_energy_prev[3][MAX_PARAMETER_BANDS];
194   FLOAT32 avg_energy_prev[3];
195   FLOAT32 frame_energy_prev[3];
196 } ia_mps_env_reshape_struct;
197 
198 typedef struct ia_mps_stp_struct {
199   FLOAT32 nrg_dir;
200   FLOAT32 nrg_diff[2];
201   FLOAT32 nrg_dir_prev;
202   FLOAT32 nrg_diff_prev[2];
203   FLOAT32 tp_scale_last[2];
204   WORD32 init_flag;
205   WORD32 update_old_ener;
206 } ia_mps_stp_struct;
207 
208 typedef struct ia_mps_opd_smooth_struct {
209   WORD32 smooth_l_phase[MAX_PARAMETER_BANDS];
210   WORD32 smooth_r_phase[MAX_PARAMETER_BANDS];
211 } ia_mps_opd_smooth_struct;
212 
213 typedef struct ia_mps_dec_state_struct {
214   WORD32 in_ch_count;
215   WORD32 out_ch_count;
216 
217   FLOAT32 input_gain;
218   WORD32 dir_sig_count;
219 
220   WORD32 decor_sig_count;
221 
222   WORD32 time_slots;
223   WORD32 pre_mix_req;
224   WORD32 temp_shape_enable_ch_stp[2];
225   WORD32 temp_shape_enable_ch_ges[2];
226 
227   FLOAT32 env_shape_data[2][MAX_TIME_SLOTS];
228 
229   WORD8 parse_nxt_frame;
230   WORD32 band_count[MAX_M_INPUT];
231   WORD32 synth_count;
232   WORD32 qmf_band_count;
233   WORD32 hyb_band_count[MAX_M_INPUT];
234   WORD32 hyb_band_count_max;
235   const WORD32 *hyb_band_to_processing_band_table;
236 
237   WORD32 res_ch_count;
238 
239   WORD32 res_bands;
240   WORD32 max_res_bands;
241   WORD32 bs_param_bands;
242 
243   WORD32 ext_frame_flag;
244   WORD32 num_parameter_sets;
245   WORD32 num_parameter_sets_prev;
246   WORD32 param_slots[MAX_PARAMETER_SETS_MPS];
247   WORD32 param_slot_diff[MAX_PARAMETER_SETS_MPS];
248   FLOAT32 inv_param_slot_diff[MAX_PARAMETER_SETS_MPS];
249   WORD32 inv_param_slot_diff_Q30[MAX_PARAMETER_SETS_MPS];
250 
251   WORD32 frame_length;
252   WORD32 residual_coding;
253   WORD32 bs_residual_present;
254 
255   WORD32 bs_residual_bands;
256 
257   ia_usac_dec_mps_config_struct *config;
258   ia_usac_dec_mps_config_struct ldmps_config;
259   ia_mps_bs_frame bs_frame;
260 
261   WORD32 smoothing_time[MAX_PARAMETER_SETS_MPS];
262   FLOAT32 inv_smoothing_time[MAX_PARAMETER_SETS_MPS];
263   WORD32 smoothing_data[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS];
264 
265   WORD32 bs_tsd_enable;
266   WORD32 bs_tsd_sep_data[MAX_TIME_SLOTS];
267   WORD32 bs_tsd_tr_phase_data[MAX_TIME_SLOTS];
268   WORD32 tsd_num_tr_slots;
269   WORD32 tsd_codeword_len;
270 
271   FLOAT32 cld_data[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS];
272   FLOAT32 icc_data[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS];
273   FLOAT32 ipd_data[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS];
274 
275   WORD32 bs_phase_mode;
276   WORD32 opd_smoothing_mode;
277   WORD32 num_bands_ipd;
278 
279   FLOAT32 phase_l[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS];
280   FLOAT32 phase_r[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS];
281   FLOAT32 phase_l_prev[MAX_PARAMETER_BANDS];
282   FLOAT32 phase_r_prev[MAX_PARAMETER_BANDS];
283 
284   FLOAT32 m1_param_re[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
285                      [MAX_M_INPUT];
286   FLOAT32 m1_param_im[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
287                      [MAX_M_INPUT];
288   FLOAT32 m2_decor_re[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
289                      [MAX_M_INPUT];
290   FLOAT32 m2_decor_im[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
291                      [MAX_M_INPUT];
292   FLOAT32 m2_resid_re[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
293                      [MAX_M_INPUT];
294   FLOAT32 m2_resid_im[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
295                      [MAX_M_INPUT];
296 
297   FLOAT32 m1_param_re_prev[MAX_PARAMETER_BANDS][MAX_M_OUTPUT][MAX_M_INPUT];
298   FLOAT32 m1_param_im_prev[MAX_PARAMETER_BANDS][MAX_M_OUTPUT][MAX_M_INPUT];
299   FLOAT32 m2_decor_re_prev[MAX_PARAMETER_BANDS][MAX_M_OUTPUT][MAX_M_INPUT];
300   FLOAT32 m2_decor_im_prev[MAX_PARAMETER_BANDS][MAX_M_OUTPUT][MAX_M_INPUT];
301   FLOAT32 m2_resid_re_prev[MAX_PARAMETER_BANDS][MAX_M_OUTPUT][MAX_M_INPUT];
302   FLOAT32 m2_resid_im_prev[MAX_PARAMETER_BANDS][MAX_M_OUTPUT][MAX_M_INPUT];
303 
304   ia_cmplx_flt_struct qmf_in[2][MAX_NUM_QMF_BANDS_MPS_NEW][MAX_TIME_SLOTS];
305   ia_cmplx_flt_struct hyb_in[2][MAX_HYBRID_BANDS_MPS][MAX_TIME_SLOTS];
306   ia_cmplx_flt_struct hyb_res[MAX_HYBRID_BANDS_MPS][MAX_TIME_SLOTS];
307   ia_cmplx_flt_struct v[MAX_M_OUTPUT][MAX_TIME_SLOTS][MAX_HYBRID_BANDS_MPS];
308   ia_cmplx_flt_struct w_diff[MAX_M_INPUT][MAX_TIME_SLOTS][MAX_HYBRID_BANDS_MPS];
309   ia_cmplx_flt_struct w_dir[MAX_M_INPUT][MAX_TIME_SLOTS][MAX_HYBRID_BANDS_MPS];
310   ia_cmplx_flt_struct hyb_dir_out[2][MAX_TIME_SLOTS][MAX_HYBRID_BANDS_MPS];
311   ia_cmplx_flt_struct hyb_diff_out[2][MAX_TIME_SLOTS][MAX_HYBRID_BANDS_MPS];
312 
313   ia_cmplx_flt_struct qmf_out_dir[2][MAX_TIME_SLOTS][MAX_NUM_QMF_BANDS_MPS];
314   ia_cmplx_flt_struct scratch[MAX_TIME_SLOTS][MAX_HYBRID_BANDS_MPS];
315 
316   FLOAT32 (*output_buffer)[4096];
317 
318   ia_mps_hybrid_filt_struct hyb_filt_state[2];
319   FLOAT32 qmf_filt_state[2][POLY_PHASE_SYNTH_SIZE];
320 
321   ia_mps_decor_struct mps_decor;
322 
323   ia_mps_smoothing_struct smoothing_filt_state;
324 
325   ia_mps_env_reshape_struct guided_env_shaping;
326 
327   WORD32 bs_high_rate_mode;
328 
329   FLOAT32 tmp_buf[84 * MAX_NUM_QMF_BANDS_SAC];
330 
331   FLOAT32 r_out_re_in_m1[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
332                         [MAX_M_INPUT];
333   FLOAT32 r_out_im_in_m1[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
334                         [MAX_M_INPUT];
335   WORD32 r_out_re_scratch_m1[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
336                             [MAX_M_INPUT];
337   WORD32 r_out_im_scratch_m1[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
338                             [MAX_M_INPUT];
339 
340   FLOAT32 r_out_re_in_m2[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
341                         [MAX_M_INPUT];
342   FLOAT32 r_out_im_in_m2[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
343                         [MAX_M_INPUT];
344   FLOAT32 r_out_diff_re_in_m2[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
345                              [MAX_M_INPUT];
346   FLOAT32 r_out_diff_im_in_m2[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
347                              [MAX_M_INPUT];
348 
349   WORD32 r_out_re_fix_in_m2[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
350                            [MAX_M_INPUT];
351   WORD32 r_out_im_fix_in_m2[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
352                            [MAX_M_INPUT];
353   WORD32 r_diff_out_re_fix_in_m2[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS]
354                                 [MAX_M_OUTPUT][MAX_M_INPUT];
355   WORD32 r_diff_out_im_fix_in_m2[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS]
356                                 [MAX_M_OUTPUT][MAX_M_INPUT];
357 
358   FLOAT32 r_out_ph_re_in_m2[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS][2];
359   FLOAT32 r_out_ph_im_in_m2[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS][2];
360 
361   ia_mps_stp_struct subband_var;
362   ia_mps_opd_smooth_struct opd_smooth;
363   WORD32 resolution;
364   VOID *p_sbr_dec[MAXNRSBRCHANNELS];
365   VOID *p_sbr_frame[MAXNRSBRCHANNELS];
366   VOID *p_sbr_header[MAXNRSBRCHANNELS];
367 
368   WORD32 object_type;
369   WORD32 mps_init_done;
370   ia_sbr_qmf_filter_bank_struct str_mps_qmf_bank;
371   ia_qmf_dec_tables_struct *qmf_dec_tables_ptr;
372   ia_sbr_tables_struct *sbr_tables_ptr;
373   ia_sbr_scale_fact_struct *str_sbr_scale_fact;
374   WORD8 ec_flag;
375   WORD8 frame_ok;
376 } ia_mps_dec_state_struct;
377 
378 VOID ixheaacd_mps_init_pre_and_post_matrix(ia_mps_dec_state_struct *self);
379 VOID ixheaacd_pre_and_mix_matrix_calculation(ia_mps_dec_state_struct *self);
380 VOID ixheaacd_mps_apply_pre_matrix(ia_mps_dec_state_struct *self);
381 VOID ixheaacd_mps_apply_mix_matrix(ia_mps_dec_state_struct *self);
382 VOID ixheaacd_mps_apply_mix_matrix_type1(ia_mps_dec_state_struct *self);
383 VOID ixheaacd_mps_apply_mix_matrix_type2(ia_mps_dec_state_struct *self);
384 VOID ixheaacd_mps_apply_mix_matrix_type3(ia_mps_dec_state_struct *self);
385 
386 VOID ixheaacd_samples_sat(WORD8 *outbuffer, WORD32 num_samples_out,
387                           WORD32 pcmsize, FLOAT32 (*out_samples)[4096],
388                           WORD32 *out_bytes, WORD32 num_channel_out);
389 
390 VOID ixheaacd_samples_sat_mc(WORD8* outbuffer, WORD32 num_samples_out,
391                              FLOAT32(*out_samples)[4096], WORD32* out_bytes,
392                              WORD32 num_channel_out, WORD32 ch_fac);
393 
394 IA_ERRORCODE ixheaacd_mps_frame_decode(ia_mps_dec_state_struct *self);
395 
396 WORD32 ixheaacd_mps_header_decode(ia_mps_dec_state_struct *self);
397 
398 VOID ixheaacd_mps_env_init(ia_mps_dec_state_struct *self);
399 VOID ixheaacd_mps_time_env_shaping(ia_mps_dec_state_struct *self);
400 
401 VOID ixheaacd_mps_pre_matrix_mix_matrix_smoothing(
402     ia_mps_dec_state_struct *self);
403 VOID ixheaacd_mps_smoothing_opd(ia_mps_dec_state_struct *self);
404 WORD32 ixheaacd_mps_temp_process(ia_mps_dec_state_struct *self);
405 
406 VOID ixheaacd_mps_par2umx_ps(ia_mps_dec_state_struct *self,
407                              ia_mps_bs_frame *curr_bit_stream, FLOAT32 *h_real,
408                              WORD32 param_set_idx);
409 VOID ixheaacd_mps_par2umx_ps_ipd_opd(ia_mps_dec_state_struct *self,
410                                      ia_mps_bs_frame *curr_bit_stream,
411                                      FLOAT32 *h_real, WORD32 param_set_idx);
412 
413 VOID ixheaacd_mps_par2umx_pred(ia_mps_dec_state_struct *self,
414                                ia_mps_bs_frame *curr_bit_stream, FLOAT32 *h_imag,
415                                FLOAT32 *h_real, WORD32 param_set_idx,
416                                WORD32 res_bands);
417 
418 VOID ixheaacd_mps_upmix_interp(
419     FLOAT32 m_matrix[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
420                    [MAX_M_INPUT],
421     FLOAT32 r_matrix[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
422                    [MAX_M_INPUT],
423     FLOAT32 m_matrix_prev[MAX_PARAMETER_BANDS][MAX_M_OUTPUT][MAX_M_INPUT],
424     WORD32 num_rows, WORD32 num_cols, ia_mps_dec_state_struct *self, WORD32 bs_high_rate_mode);
425 
426 VOID ixheaacd_mps_upmix_interp_type1(
427     FLOAT32 m_matrix[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
428                     [MAX_M_INPUT],
429     FLOAT32 r_matrix[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
430                     [MAX_M_INPUT],
431     FLOAT32 m_matrix_prev[MAX_PARAMETER_BANDS][MAX_M_OUTPUT][MAX_M_INPUT],
432     WORD32 num_rows, WORD32 num_cols, ia_mps_dec_state_struct *self,
433     WORD32 bs_high_rate_mode);
434 
435 VOID ixheaacd_mps_upmix_interp_type2(
436     FLOAT32 m_matrix[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
437                     [MAX_M_INPUT],
438     FLOAT32 r_matrix[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS][MAX_M_OUTPUT]
439                     [MAX_M_INPUT],
440     FLOAT32 m_matrix_prev[MAX_PARAMETER_BANDS][MAX_M_OUTPUT][MAX_M_INPUT],
441     WORD32 num_rows, ia_mps_dec_state_struct *self, WORD32 col);
442 
443 VOID ixheaacd_mps_phase_interpolation(
444     FLOAT32 pl[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS],
445     FLOAT32 pr[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS],
446     FLOAT32 pl_prev[MAX_PARAMETER_BANDS], FLOAT32 pr_prev[MAX_PARAMETER_BANDS],
447     FLOAT32 r_re[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS][2],
448     FLOAT32 r_im[MAX_TIME_SLOTS][MAX_PARAMETER_BANDS][2],
449     ia_mps_dec_state_struct *self);
450 
451 VOID ixheaacd_mps_complex_fft(FLOAT32 *xr, FLOAT32 *xi, WORD32 nlength);
452 
453 typedef struct {
454   WORD32 state_length;
455   WORD32 num_length;
456   WORD32 den_length;
457   WORD32 complex;
458 
459   WORD32 *state_real;
460   WORD32 *state_imag;
461 
462   WORD32 *numerator_real;
463   WORD32 *numerator_imag;
464 
465   WORD32 *denominator_real;
466   WORD32 *denominator_imag;
467 } ia_mps_dec_decorr_filter_instance_struct;
468 
469 typedef struct ia_mps_dec_ducker_interface ia_mps_dec_ducker_interface;
470 
471 typedef struct {
472   WORD32 decorr_seed;
473   WORD32 numbins;
474 
475   ia_mps_dec_decorr_filter_instance_struct *filter[MAX_HYBRID_BANDS];
476 
477   ia_mps_dec_ducker_interface *ducker;
478 
479   WORD32 no_sample_delay[MAX_HYBRID_BANDS];
480   WORD32 **delay_buffer_real;
481   WORD32 **delay_buffer_imag;
482 } ia_mps_dec_decorr_dec_struct, *ia_mps_dec_decorr_dec_handle;
483 
484 typedef struct {
485   WORD32 buffer_lf_real[QMF_BANDS_TO_HYBRID][BUFFER_LEN_LF];
486   WORD32 buffer_lf_imag[QMF_BANDS_TO_HYBRID][BUFFER_LEN_LF];
487   WORD32 qmf_lf_real[QMF_BANDS_TO_HYBRID][BUFFER_LEN_LF];
488   WORD32 qmf_lf_imag[QMF_BANDS_TO_HYBRID][BUFFER_LEN_LF];
489   WORD32 buffer_hf_real[MAX_NUM_QMF_BANDS][BUFFER_LEN_HF];
490   WORD32 buffer_hf_imag[MAX_NUM_QMF_BANDS][BUFFER_LEN_HF];
491 } ia_mps_dec_thyb_filter_state_struct;
492 
493 typedef struct {
494   WORD32 re;
495   WORD32 im;
496 } complex;
497 
498 typedef struct {
499   UWORD32 ui_pcm_wdsz;
500   UWORD32 ui_samp_freq;
501   UWORD32 ui_in_channels;
502   UWORD32 ui_out_channels;
503   WORD32 ui_channel_mask;
504 
505   WORD32 frame_ok;
506   UWORD32 ui_bs_is_buried;
507   WORD32 ui_dec_type;
508   WORD32 ui_upmix_type;
509   WORD32 ui_binaural_quality;
510   WORD32 ui_hrtf_model;
511   UWORD32 ui_qmf_bands;
512 
513   WORD32 bs_frame_length;
514   WORD32 bs_sampling_freq_index;
515   WORD32 bs_sampling_frequency;
516   WORD32 bs_freq_res;
517   WORD32 bs_tree_config;
518   WORD32 bs_quant_mode;
519   WORD32 bs_one_icc;
520   WORD32 bs_arbitrary_downmix;
521   WORD32 bs_residual_coding;
522   WORD32 bs_smooth_config;
523   WORD32 bs_fixed_gain_sur;
524   WORD32 bs_fixed_gain_lfe;
525   WORD32 bs_fixed_gain_dmx;
526   WORD32 bs_matrix_mode;
527   WORD32 bs_temp_shape_config;
528 
529   WORD32 bs_decorr_config;
530 
531   WORD32 bs_3d_audio_mode;
532   WORD32 bs_3d_audio_hrtf_set;
533   WORD32 bs_hrtf_freq_res;
534   WORD32 hrtf_num_band;
535   WORD32 bs_hrtf_num_chan;
536   WORD32 bs_hrtf_asymmetric;
537   WORD32 bs_hrtf_level_left[MAX_OUTPUT_CHANNELS_MPS][MAX_PARAMETER_BANDS];
538   WORD32 bs_hrtf_level_right[MAX_OUTPUT_CHANNELS_MPS][MAX_PARAMETER_BANDS];
539   WORD32 bs_hrtf_phase[MAX_OUTPUT_CHANNELS_MPS];
540   WORD32 bs_hrtf_phase_lr[MAX_OUTPUT_CHANNELS_MPS][MAX_PARAMETER_BANDS];
541 
542   WORD32 bs_ott_bands[MAX_NUM_OTT];
543   WORD32 bs_ttt_dual_mode[MAX_NUM_TTT];
544   WORD32 bs_ttt_mode_low[MAX_NUM_TTT];
545   WORD32 bs_ttt_mode_high[MAX_NUM_TTT];
546   WORD32 bs_ttt_bands_low[MAX_NUM_TTT];
547 
548   WORD32 bs_sac_ext_type[MAX_NUM_EXT_TYPES];
549   WORD32 sac_ext_cnt;
550 
551   WORD32 bs_residual_present[MAX_RESIDUAL_CHANNELS_MPS];
552   WORD32 bs_residual_sampling_freq_index;
553   WORD32 bs_residual_frames_per_spatial_frame;
554 
555   WORD32 bs_residual_bands[MAX_RESIDUAL_CHANNELS_MPS];
556 
557   WORD32 bs_arbitrary_downmix_residual_sampling_freq_index;
558   WORD32 bs_arbitrary_downmix_residual_frames_per_spatial_frame;
559   WORD32 bs_arbitrary_downmix_residual_bands;
560 
561   WORD32 bs_env_quant_mode;
562 
563   WORD32 arbitrary_tree;
564   WORD32 num_out_chan_at;
565   WORD32 num_ott_boxes_at;
566   WORD32 bs_output_channel_pos_at[MAX_OUTPUT_CHANNELS_AT_MPS];
567   WORD32 bs_ott_box_present_at[MAX_OUTPUT_CHANNELS_AT_MPS]
568                               [MAX_ARBITRARY_TREE_INDEX];
569   WORD32 bs_ott_default_cld_at[MAX_OUTPUT_CHANNELS_AT_MPS *
570                                MAX_ARBITRARY_TREE_INDEX];
571   WORD32
572   bs_ott_mode_lfe_at[MAX_OUTPUT_CHANNELS_AT_MPS * MAX_ARBITRARY_TREE_INDEX];
573   WORD32 bs_ott_bands_at[MAX_OUTPUT_CHANNELS_AT_MPS * MAX_ARBITRARY_TREE_INDEX];
574 } ia_mps_spatial_bs_config_struct;
575 
576 typedef struct {
577   WORD32
578   bs_xxx_data_mode[MAX_NUM_POAT][MAX_PARAMETER_SETS];
579   WORD32
580   bs_quant_coarse_xxx[MAX_NUM_POAT][MAX_PARAMETER_SETS];
581   WORD32
582   bs_freq_res_stride_xxx[MAX_NUM_POAT][MAX_PARAMETER_SETS];
583 
584   WORD32 bs_quant_coarse_xxx_prev[MAX_NUM_POAT];
585   WORD32
586   no_cmp_quant_coarse_xxx[MAX_NUM_POAT][MAX_PARAMETER_SETS];
587 
588 } ia_mps_dec_lossless_data_struct;
589 
590 typedef struct {
591   WORD32 bs_icc_diff_present[MAX_RESIDUAL_CHANNELS_MPS][MAX_PARAMETER_SETS];
592   WORD32
593   bs_icc_diff[MAX_RESIDUAL_CHANNELS_MPS][MAX_PARAMETER_SETS]
594              [MAX_PARAMETER_BANDS];
595 
596 } RESIDUAL_FRAME_DATA;
597 
598 typedef struct {
599   WORD32 bs_independency_flag;
600   WORD32
601   ott_cld_idx[MAX_NUM_OTT + MAX_OUTPUT_CHANNELS_AT][MAX_PARAMETER_SETS]
602              [MAX_PARAMETER_BANDS];
603   WORD32 ott_icc_idx[MAX_NUM_OTT][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS];
604   WORD32 ttt_cpc_1_idx[MAX_NUM_TTT][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS];
605   WORD32 ttt_cpc_2_idx[MAX_NUM_TTT][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS];
606   WORD32 ttt_cld_1_idx[MAX_NUM_TTT][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS];
607   WORD32 ttt_cld_2_idx[MAX_NUM_TTT][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS];
608   WORD32 ttt_icc_idx[MAX_NUM_TTT][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS];
609 
610   WORD32 ott_cld_idx_prev[MAX_NUM_OTT + MAX_OUTPUT_CHANNELS_AT][MAX_PARAMETER_BANDS];
611   WORD32 ott_icc_idx_prev[MAX_NUM_OTT][MAX_PARAMETER_BANDS];
612   WORD32 ttt_cpc_1_idx_prev[MAX_NUM_TTT][MAX_PARAMETER_BANDS];
613   WORD32 ttt_cpc_2_idx_prev[MAX_NUM_TTT][MAX_PARAMETER_BANDS];
614   WORD32 ttt_cld_1_idx_prev[MAX_NUM_TTT][MAX_PARAMETER_BANDS];
615   WORD32 ttt_cld_2_idx_prev[MAX_NUM_TTT][MAX_PARAMETER_BANDS];
616   WORD32 ttt_icc_idx_prev[MAX_NUM_TTT][MAX_PARAMETER_BANDS];
617 
618   WORD32
619   cmp_ott_cld_idx[MAX_NUM_OTT + MAX_OUTPUT_CHANNELS_AT][MAX_PARAMETER_SETS]
620                  [MAX_PARAMETER_BANDS];
621   WORD32 cmp_ott_icc_idx[MAX_NUM_OTT][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS];
622   WORD32 ott_icc_diff_idx[MAX_NUM_OTT][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS];
623   WORD32 cmp_ttt_cpc_1_idx[MAX_NUM_TTT][MAX_PARAMETER_SETS]
624                           [MAX_PARAMETER_BANDS];
625   WORD32 cmp_ttt_cpc_2_idx[MAX_NUM_TTT][MAX_PARAMETER_SETS]
626                           [MAX_PARAMETER_BANDS];
627   WORD32 cmp_ttt_cld_1_idx[MAX_NUM_TTT][MAX_PARAMETER_SETS]
628                           [MAX_PARAMETER_BANDS];
629   WORD32 cmp_ttt_cld_2_idx[MAX_NUM_TTT][MAX_PARAMETER_SETS]
630                           [MAX_PARAMETER_BANDS];
631   WORD32 cmp_ttt_icc_idx[MAX_NUM_TTT][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS];
632   WORD32 cmp_ott_cld_idx_prev[MAX_NUM_OTT + MAX_OUTPUT_CHANNELS_AT]
633                              [MAX_PARAMETER_BANDS];
634   WORD32 cmp_ott_icc_idx_prev[MAX_NUM_OTT][MAX_PARAMETER_BANDS];
635   WORD32 cmp_ttt_cpc_1_idx_prev[MAX_NUM_TTT][MAX_PARAMETER_BANDS];
636   WORD32 cmp_ttt_cpc_2_idx_prev[MAX_NUM_TTT][MAX_PARAMETER_BANDS];
637   WORD32 cmp_ttt_cld_1_idx_prev[MAX_NUM_TTT][MAX_PARAMETER_BANDS];
638   WORD32 cmp_ttt_cld_2_idx_prev[MAX_NUM_TTT][MAX_PARAMETER_BANDS];
639   WORD32 cmp_ttt_icc_idx_prev[MAX_NUM_TTT][MAX_PARAMETER_BANDS];
640 
641   ia_mps_dec_lossless_data_struct cld_lossless_data;
642   ia_mps_dec_lossless_data_struct icc_lossless_data;
643   ia_mps_dec_lossless_data_struct cpc_lossless_data;
644 
645   WORD32 bs_smooth_control;
646   WORD32 bs_smooth_mode[MAX_PARAMETER_SETS];
647   WORD32 bs_smooth_time[MAX_PARAMETER_SETS];
648   WORD32 bs_freq_res_stride_smg[MAX_PARAMETER_SETS];
649   WORD32 bs_smg_data[MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS];
650 
651   RESIDUAL_FRAME_DATA res_data;
652 
653   WORD32
654   arbdmx_gain_idx[MAX_INPUT_CHANNELS_MPS][MAX_PARAMETER_SETS]
655                  [MAX_PARAMETER_BANDS];
656   WORD32 arbdmx_gain_idx_prev[MAX_INPUT_CHANNELS_MPS][MAX_PARAMETER_BANDS];
657   WORD32
658   cmp_arbdmx_gain_idx[MAX_INPUT_CHANNELS_MPS][MAX_PARAMETER_SETS]
659                      [MAX_PARAMETER_BANDS];
660   WORD32 cmp_arbdmx_gain_idx_prev[MAX_INPUT_CHANNELS_MPS][MAX_PARAMETER_BANDS];
661   WORD32 bs_arbitrary_downmix_residual_abs[MAX_INPUT_CHANNELS_MPS];
662   WORD32 bs_arbitrary_downmix_residual_alpha_update_set[MAX_INPUT_CHANNELS_MPS];
663 
664 } ia_mps_dec_spatial_bs_frame_struct;
665 
666 typedef struct {
667   WORD32 spec_prev_real[MAX_NUM_QMF_BANDS * 8];
668   WORD32 spec_prev_imag[MAX_NUM_QMF_BANDS * 8];
669   WORD32 p_cross_real[MAX_NUM_QMF_BANDS * 8];
670   WORD32 p_cross_imag[MAX_NUM_QMF_BANDS * 8];
671 
672   WORD32 p_sum[MAX_NUM_QMF_BANDS * 8];
673   WORD32 p_sum_prev[MAX_NUM_QMF_BANDS * 8];
674 
675   WORD32 buf_real[MAX_NUM_QMF_BANDS][6];
676   WORD32 buf_imag[MAX_NUM_QMF_BANDS][6];
677 
678   WORD32 win_buf_real[MAX_NUM_QMF_BANDS][16];
679   WORD32 win_buf_imag[MAX_NUM_QMF_BANDS][16];
680 } ia_mps_dec_tonality_state_struct;
681 
682 typedef struct {
683   WORD32 prev_smg_time;
684   WORD32 prev_smg_data[MAX_PARAMETER_BANDS];
685 } ia_mps_dec_smoothing_state_struct;
686 
687 typedef struct {
688   WORD32
689   part_nrg_prev[2 * MAX_OUTPUT_CHANNELS_MPS + MAX_INPUT_CHANNELS_MPS]
690                [MAX_PARAMETER_BANDS];
691   WORD32 norm_nrg_prev[2 * MAX_OUTPUT_CHANNELS_MPS + MAX_INPUT_CHANNELS_MPS];
692   WORD32 frame_nrg_prev[2 * MAX_OUTPUT_CHANNELS_MPS + MAX_INPUT_CHANNELS_MPS];
693 
694   WORD16
695   q_part_nrg_prev[2 * MAX_OUTPUT_CHANNELS_MPS + MAX_INPUT_CHANNELS_MPS]
696                  [MAX_PARAMETER_BANDS];
697   WORD16 q_norm_nrg_prev[2 * MAX_OUTPUT_CHANNELS_MPS + MAX_INPUT_CHANNELS_MPS];
698   WORD16 q_frame_nrg_prev[2 * MAX_OUTPUT_CHANNELS_MPS + MAX_INPUT_CHANNELS_MPS];
699 
700 } ia_mps_dec_reshape_bb_env_state_struct;
701 
702 typedef struct {
703   WORD32 use_ttt_decorr;
704   WORD32 mode;
705   WORD32 start_band;
706   WORD32 stop_band;
707   WORD32 bitstream_start_band;
708   WORD32 bitstream_stop_band;
709 } ia_mps_dec_ttt_config_struct;
710 
711 typedef struct {
712   WORD32 excitation[3][MAX_PARAMETER_BANDS];
713   WORD32 filter_coeff;
714   WORD16 q_excitation[3][MAX_PARAMETER_BANDS];
715 } ia_mps_dec_blind_decoder_struct;
716 
717 typedef struct {
718   WORD32 run_dry_ener[MAX_INPUT_CHANNELS_MPS];
719   WORD32 run_wet_ener[MAX_OUTPUT_CHANNELS_MPS];
720   WORD32 old_dry_ener[MAX_INPUT_CHANNELS_MPS];
721   WORD32 old_wet_ener[MAX_OUTPUT_CHANNELS_MPS];
722 
723   WORD16 q_run_dry_ener[MAX_INPUT_CHANNELS_MPS];
724   WORD16 q_run_wet_ener[MAX_OUTPUT_CHANNELS_MPS];
725   WORD16 q_old_dry_ener[MAX_INPUT_CHANNELS_MPS];
726   WORD16 q_old_wet_ener[MAX_OUTPUT_CHANNELS_MPS];
727   WORD32 update_old_ener;
728 
729   WORD32 prev_tp_scale[MAX_OUTPUT_CHANNELS_MPS];
730   WORD16 q_prev_tp_scale[MAX_OUTPUT_CHANNELS_MPS];
731 } ia_mps_dec_subband_tp_params_struct;
732 
733 typedef struct ia_mps_persistent_mem {
734   WORD32 *prev_gain_at;
735   WORD32 *arbdmx_alpha_prev;
736   WORD32 *m1_param_real_prev;
737   WORD32 *m1_param_imag_prev;
738   WORD32 *m2_decor_real_prev;
739   WORD32 *m2_decor_imag_prev;
740   WORD32 *m2_resid_real_prev;
741   WORD32 *m2_resid_imag_prev;
742   WORD32 *qmf_input_delay_real;
743   WORD32 *qmf_input_delay_imag;
744   WORD32 *ana_qmf_states_buffer;
745   WORD32 *syn_qmf_states_buffer;
746   VOID *decorr_ptr;
747 
748   ia_mps_dec_thyb_filter_state_struct *hyb_filter_state;
749   ia_mps_dec_tonality_state_struct *ton_state;
750   ia_mps_dec_smoothing_state_struct *smooth_state;
751   ia_mps_dec_reshape_bb_env_state_struct *reshape_bb_env_state;
752   ia_mps_dec_subband_tp_params_struct *sub_band_params;
753   ia_mps_dec_blind_decoder_struct *blind_decoder;
754   ia_mps_dec_spatial_bs_frame_struct *p_bs_frame;
755 } ia_mps_persistent_mem;
756 
757 typedef struct {
758   ia_mps_dec_qmf_tables_struct *qmf_table_ptr;
759   ia_mps_dec_common_tables_struct *common_table_ptr;
760   ia_mps_dec_hybrid_tables_struct *hybrid_table_ptr;
761   ia_mps_dec_m1_m2_tables_struct *m1_m2_table_ptr;
762   ia_mps_dec_decorr_tables_struct *decor_table_ptr;
763   ia_mps_dec_tp_process_tables_struct *tp_process_table_ptr;
764   ia_mps_dec_mdct2qmf_table_struct *mdct2qmf_table_ptr;
765   ia_mps_dec_tonality_tables_struct *tonality_table_ptr;
766   ia_mps_dec_bitdec_tables_struct *bitdec_table_ptr;
767   ia_mps_dec_blind_tables_struct *blind_table_ptr;
768   ia_mps_dec_mdct2qmf_tables_struct *mdct2qmfcos_table_ptr;
769   ia_mps_dec_mdct2qmf_cos_table_struct *mdct2qmfcos_tab_ptr;
770   VOID *aac_tab;
771   ia_mps_dec_wf_ptr_table_struct *wf_tab_ptr;
772 
773 } ia_mps_dec_mps_tables_struct;
774 
775 typedef struct {
776   VOID(*syn_filter_bank)
777   (ia_mps_dec_qmf_syn_filter_bank *syn, WORD32 *sr, WORD32 *si,
778    WORD32 *time_sig, WORD32 channel, WORD32 resolution, WORD32 nr_samples,
779    ia_mps_dec_qmf_tables_struct *qmf_table_ptr);
780 } ia_mps_dec_synthesis_interface, *ia_mps_dec_synthesis_interface_handle;
781 
782 typedef struct {
783   WORD32
784   m1_param_real[MAX_M1_OUTPUT][MAX_INPUT_CHANNELS_MPS][MAX_PARAMETER_SETS]
785                [MAX_PARAMETER_BANDS];
786   WORD32
787   m1_param_imag[MAX_M1_OUTPUT][MAX_INPUT_CHANNELS_MPS][MAX_PARAMETER_SETS]
788                [MAX_PARAMETER_BANDS];
789 } ia_mps_dec_m1_param_struct;
790 
791 typedef struct {
792   WORD32 *qmf_residual_real;
793   WORD32 *qmf_residual_imag;
794   WORD32 *qmf_residual_real_pre, *qmf_residual_real_post;
795   WORD32 *qmf_residual_imag_pre, *qmf_residual_imag_post;
796   WORD32 *res_mdct;
797   WORD32 *time_out;
798   WORD32 *x_real;
799   WORD32 *x_imag;
800   WORD32 *hyb_output_real_dry;
801   WORD32 *hyb_output_imag_dry;
802   WORD32 *env_dmx_0;
803   WORD32 *env_dmx_1;
804   WORD32 *m_qmf_real;
805   WORD32 *m_qmf_imag;
806   WORD32 *w_dry_real;
807   WORD32 *w_dry_imag;
808   WORD32 *buf_real;
809   WORD32 *buf_imag;
810   WORD32 *buffer_real;
811   WORD32 *buffer_imag;
812   ia_mps_dec_m1_param_struct *m1_param;
813 } ia_mps_dec_reuse_array_struct;
814 
815 typedef struct {
816   WORD32 m2_decor_real[15][MAX_PARAMETER_SETS]
817                       [MAX_PARAMETER_BANDS];
818   WORD32 m2_decor_imag[15][MAX_PARAMETER_SETS]
819                       [MAX_PARAMETER_BANDS];
820 
821   WORD32 m2_resid_real[19][MAX_PARAMETER_SETS]
822                       [MAX_PARAMETER_BANDS];
823   WORD32 m2_resid_imag[19][MAX_PARAMETER_SETS]
824                       [MAX_PARAMETER_BANDS];
825 } ia_mps_dec_m2_param_struct;
826 
827 typedef struct {
828   ia_mps_dec_m2_param_struct *m2_param;
829 
830   WORD32 temp_shape_enable_channel_stp[MAX_OUTPUT_CHANNELS_MPS];
831   WORD32 temp_shape_enable_channel_ges[MAX_OUTPUT_CHANNELS_MPS];
832 
833   WORD32 env_shape_data[MAX_OUTPUT_CHANNELS_MPS][MAX_TIME_SLOTS];
834 
835   WORD32 num_ott_bands[MAX_NUM_OTT];
836 
837   ia_mps_dec_ttt_config_struct ttt_config[2][MAX_NUM_TTT];
838   WORD32 param_slot[MAX_PARAMETER_SETS];
839 
840   WORD32 smg_time[MAX_PARAMETER_SETS];
841   WORD32 smg_data[MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS];
842 
843   WORD32
844   ott_cld[MAX_NUM_OTT + MAX_OUTPUT_CHANNELS_AT][MAX_PARAMETER_SETS]
845          [MAX_PARAMETER_BANDS];
846   WORD32 ott_icc[MAX_NUM_OTT][MAX_PARAMETER_SETS]
847                 [MAX_PARAMETER_BANDS];
848 
849   WORD32 ttt_cpc_1[MAX_NUM_TTT][MAX_PARAMETER_SETS]
850                   [MAX_PARAMETER_BANDS];
851   WORD32 ttt_cpc_2[MAX_NUM_TTT][MAX_PARAMETER_SETS]
852                   [MAX_PARAMETER_BANDS];
853   WORD32 ttt_cld_1[MAX_NUM_TTT][MAX_PARAMETER_SETS]
854                   [MAX_PARAMETER_BANDS];
855   WORD32 ttt_cld_2[MAX_NUM_TTT][MAX_PARAMETER_SETS]
856                   [MAX_PARAMETER_BANDS];
857   WORD32 ttt_icc[MAX_NUM_TTT][MAX_PARAMETER_SETS]
858                 [MAX_PARAMETER_BANDS];
859 
860   WORD32
861   arbdmx_gain[MAX_INPUT_CHANNELS_MPS][MAX_PARAMETER_SETS]
862              [MAX_PARAMETER_BANDS];
863 
864   WORD32 arbdmx_residual_abs[MAX_INPUT_CHANNELS_MPS];
865   WORD32 arbdmx_alpha_upd_set[MAX_INPUT_CHANNELS_MPS];
866   WORD32 arbdmx_alpha[MAX_INPUT_CHANNELS_MPS];
867 } ia_mps_dec_auxilary_struct;
868 
869 typedef struct ia_heaac_mps_state_struct {
870   WORD32 sac_time_align_flag;
871   WORD32 sac_time_align;
872   WORD32 sampling_freq;
873 
874   WORD32 tree_config;
875   WORD32 num_input_channels;
876   WORD32 num_output_channels;
877   WORD32 num_ott_boxes;
878   WORD32 num_ttt_boxes;
879 
880   WORD32 num_output_channels_at;
881 
882   WORD32 quant_mode;
883   WORD32 one_icc;
884   WORD32 arbitrary_downmix;
885   WORD32 residual_coding;
886   WORD32 smooth_config;
887   WORD32 temp_shape_config;
888   WORD32 decorr_config;
889   WORD32 mtx_inversion;
890   WORD32 _3d_stereo_inversion;
891   WORD32 env_quant_mode;
892 
893   WORD32 clip_protect_gain;
894   WORD32 surround_gain;
895   WORD32 lfe_gain;
896   WORD32 cpc_default;
897   WORD32 icc_default;
898   WORD32 arbdmx_gain_default;
899 
900   WORD32 num_direct_signals;
901   WORD32 num_residual_signals;
902   WORD32 num_decor_signals;
903   WORD32 num_v_channels;
904   WORD32 num_w_channels;
905   WORD32 w_start_residual_idx;
906   WORD32 num_x_channels;
907 
908   WORD32 time_slots;
909   WORD32 cur_time_slot;
910   WORD32 frame_length;
911   WORD32 dec_type;
912   WORD32 up_mix_type;
913   WORD32 binaural_quality;
914   WORD32 hrtf_model;
915 
916   WORD32 tp_hyb_band_border;
917 
918   WORD32 parse_next_bitstream_frame;
919 
920   WORD32 qmf_bands;
921   WORD32 hybrid_bands;
922 
923   WORD32 residual_frames_per_spatial_frame;
924   WORD32 upd_qmf;
925 
926   WORD32 arbdmx_residual_bands;
927   WORD32 arbdmx_frames_per_spatial_frame;
928   WORD32 arbdmx_upd_qmf;
929 
930   WORD32 bitstream_parameter_bands;
931   WORD32 num_parameter_bands;
932 
933   WORD32 extend_frame;
934   WORD32 num_parameter_sets;
935   WORD32 num_parameter_sets_prev;
936 
937   WORD32 smooth_control;
938 
939   WORD32 i_bytes_consumed_mps;
940   WORD32 bytes_remaining;
941   WORD32 ui_mps_in_bytes;
942   WORD32 is_sbr_present;
943 
944   WORD32 bits_per_sample;
945   WORD32 qmf_input_delay_index;
946 
947   WORD32 m1_param_imag_present;
948   WORD32 m2_param_imag_present;
949 
950   WORD32 m1_param_present[MAX_M1_OUTPUT][MAX_INPUT_CHANNELS_MPS];
951   WORD32 m2_param_present[MAX_M2_OUTPUT][MAX_M2_INPUT];
952 
953   WORD32 index[MAX_RESIDUAL_CHANNELS_MPS];
954 
955   WORD32 ott_cld_default[MAX_NUM_OTT];
956   WORD32 ttt_cld_1_default[MAX_NUM_TTT];
957   WORD32 ttt_cld_2_default[MAX_NUM_TTT];
958 
959   SIZE_T kernels[MAX_HYBRID_BANDS];
960 
961   WORD32 res_bands[MAX_RESIDUAL_CHANNELS_MPS];
962   WORD32 ott_mode_lfe[MAX_NUM_OTT];
963   WORD32 bitstream_ott_bands[MAX_NUM_OTT];
964 
965   WORD32 scaling_enable;
966 
967   WORD32 is_buried_flag;
968 
969   ia_mps_dec_residual_sfband_info_struct sfband_info_tab;
970   WORD16 *pcm_out_buf;
971 
972   WORD32 res_block_type[MAX_RESIDUAL_CHANNELS_MPS][MAX_RESIDUAL_FRAMES];
973 
974   ia_mps_spatial_bs_config_struct bs_config;
975   ia_mps_dec_decorr_dec_handle ap_decor[MAX_NO_DECORR_CHANNELS];
976   ia_mps_dec_qmf_ana_filter_bank qmf_bank[6];
977   ia_mps_dec_qmf_syn_filter_bank syn_qmf_bank;
978   struct ia_bit_buf_struct mps_bit_buf, *ptr_mps_bit_buff;
979 
980   ia_mps_dec_spatial_bs_frame_struct *bs_frame;
981   ia_mps_dec_reuse_array_struct *array_struct;
982   ia_mps_dec_auxilary_struct *aux_struct;
983   VOID *mps_scratch_mem_v;
984   ia_mps_persistent_mem mps_persistent_mem;
985   VOID *mps_persistent_mem_v;
986 
987   ia_mps_dec_synthesis_interface *syn;
988   ia_mps_dec_residual_channel_info_struct *p_aac_decoder_channel_info[2];
989   ia_mps_dec_residual_dynamic_data_struct *p_aac_decoder_dynamic_data_init[2];
990   WORD8 tot_sf_bands_ls[2];
991 
992   ia_mps_dec_mps_tables_struct ia_mps_dec_mps_table;
993   ia_mps_dec_residual_aac_tables_struct aac_table;
994   ia_mps_dec_mdct2qmf_cos_table_struct ia_mps_dec_mdct2qmfcos_table;
995   ia_mps_dec_wf_ptr_table_struct wf_tab;
996   WORD32 is_first;
997   WORD32 mps_decode;
998   UWORD8 temp_buf[1024];
999   WORD32 heaac_mps_present;
1000   WORD32 mps_with_sbr;
1001   WORD32 mps_init_done;
1002   WORD32 ec_flag;
1003   WORD32 frame_ok;
1004   WORD32 first_frame;
1005 
1006 } ia_heaac_mps_state_struct;
1007 
1008 WORD32 ixheaacd_mps_persistent_buffer_sizes();
1009 
1010 WORD32 ixheaacd_getsize_mps_persistent();
1011 
1012 VOID ixheaacd_set_mps_persistent_buffers(ia_heaac_mps_state_struct *pstr_mps_state,
1013                                          WORD32 *persistent_used,
1014                                          WORD32 num_channel,
1015                                          VOID *persistent_mem);
1016 
1017 VOID ixheaacd_set_scratch_buffers(ia_heaac_mps_state_struct *pstr_mps_state,
1018                                   VOID *scratch_mem);
1019 
1020 VOID ixheaacd_calc_ana_filt_bank(ia_heaac_mps_state_struct *pstr_mps_state,
1021                                  WORD16 *time_in, WORD32 *p_qmf_real,
1022                                  WORD32 *p_qmf_imag, WORD32 channel);
1023 
1024 IA_ERRORCODE
1025 ixheaacd_syn_filt_bank_init(ia_mps_dec_synthesis_interface_handle self,
1026                             WORD32 resolution);
1027 #endif /* IXHEAACD_MPS_DEC_H */
1028