xref: /aosp_15_r20/external/libxaac/decoder/ixheaacd_mps_calc_m1m2_tree_727x.c (revision 15dc779a375ca8b5125643b829a8aa4b70d7f451)
1 /******************************************************************************
2  *
3  * Copyright (C) 2023 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 #include <string.h>
21 #include "ixheaac_type_def.h"
22 #include "ixheaacd_mps_struct_def.h"
23 #include "ixheaacd_mps_res_rom.h"
24 #include "ixheaacd_mps_aac_struct.h"
25 #include "ixheaac_constants.h"
26 #include "ixheaac_basic_ops32.h"
27 #include "ixheaac_basic_ops40.h"
28 #include "ixheaacd_bitbuffer.h"
29 #include "ixheaacd_common_rom.h"
30 #include "ixheaacd_sbrdecsettings.h"
31 #include "ixheaacd_sbr_scale.h"
32 #include "ixheaacd_env_extr_part.h"
33 #include "ixheaacd_sbr_rom.h"
34 #include "ixheaacd_hybrid.h"
35 #include "ixheaacd_ps_dec.h"
36 #include "ixheaac_error_standards.h"
37 #include "ixheaacd_mps_polyphase.h"
38 #include "ixheaacd_config.h"
39 #include "ixheaacd_qmf_dec.h"
40 #include "ixheaacd_mps_dec.h"
41 #include "ixheaacd_mps_macro_def.h"
42 #include "ixheaacd_mps_basic_op.h"
43 #include "ixheaacd_mps_calc_m1m2_common.h"
44 
ixheaacd_calc_m1m2_7271(ia_heaac_mps_state_struct * pstr_mps_state)45 VOID ixheaacd_calc_m1m2_7271(ia_heaac_mps_state_struct *pstr_mps_state) {
46   ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct;
47   ia_mps_dec_m2_param_struct *m2_param = p_aux_struct->m2_param;
48   ia_mps_dec_m1_param_struct *m1_param = pstr_mps_state->array_struct->m1_param;
49   ia_heaac_mps_state_struct *curr_state = pstr_mps_state;
50   WORD32 ps, pb, col, row, i;
51 
52   WORD32 m_pre[3][5];
53   WORD32 m_ttt[3][3];
54 
55   WORD32 g_real[2];
56 
57   WORD32 temp_1, temp_2;
58   WORD64 acc;
59 
60   WORD32 *h11_l, *h11_r, *h12_l, *h12_r, *h21_l, *h21_r, *h22_l, *h22_r, *h12_res_l, *h12_res_r,
61       *h22_res_l, *h22_res_r;
62   WORD32 *c_l_clfe, *c_r_clfe, *kappa, *g_dd;
63   WORD16 *c_f_l, *c_f_r, *dummy;
64 
65   WORD32 *h11_lc, *h11_rc, *h12_lc, *h12_rc, *h21_lc, *h21_rc, *h22_lc, *h22_rc, *h12_res_lc,
66       *h12_res_rc, *h22_res_lc, *h22_res_rc;
67   WORD16 *c_f_lc, *c_f_rc;
68 
69   WORD32 idx;
70   WORD32 residual_coding = pstr_mps_state->residual_coding;
71   WORD32 *res_bands = pstr_mps_state->res_bands;
72   WORD32 num_parameter_bands = pstr_mps_state->num_parameter_bands;
73   WORD32 m1_param_imag_present = pstr_mps_state->m1_param_imag_present;
74   WORD32 num_input_channels = pstr_mps_state->num_input_channels;
75   WORD32 num_parameter_sets = pstr_mps_state->num_parameter_sets;
76   WORD32 arbitrary_downmix = pstr_mps_state->arbitrary_downmix;
77   WORD32 mode_0 = p_aux_struct->ttt_config[0][0].mode;
78   WORD32 mode_1 = p_aux_struct->ttt_config[1][0].mode;
79   WORD32 enable_additionals = ((mode_0 == 0) || (mode_1 == 0));
80   WORD32 pos[5] = {0};
81   WORD32 pos_resid[5] = {0};
82 
83   h11_l = pstr_mps_state->mps_scratch_mem_v;
84   h11_r =
85       h11_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h11_r), BYTE_ALIGN_8);
86   h12_l =
87       h11_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_l), BYTE_ALIGN_8);
88   h12_r =
89       h12_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_r), BYTE_ALIGN_8);
90   h21_l =
91       h12_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h21_l), BYTE_ALIGN_8);
92   h21_r =
93       h21_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h21_r), BYTE_ALIGN_8);
94   h22_l =
95       h21_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_l), BYTE_ALIGN_8);
96   h22_r =
97       h22_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_r), BYTE_ALIGN_8);
98   h12_res_l = h22_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_res_l),
99                                                     BYTE_ALIGN_8);
100   h12_res_r = h12_res_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_res_r),
101                                                         BYTE_ALIGN_8);
102   h22_res_l = h12_res_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_res_l),
103                                                         BYTE_ALIGN_8);
104   h22_res_r = h22_res_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_res_r),
105                                                         BYTE_ALIGN_8);
106   c_l_clfe = h22_res_r +
107              IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*c_l_clfe), BYTE_ALIGN_8);
108   c_r_clfe = c_l_clfe +
109              IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*c_r_clfe), BYTE_ALIGN_8);
110   kappa =
111       c_r_clfe + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*kappa), BYTE_ALIGN_8);
112   g_dd = kappa + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*g_dd), BYTE_ALIGN_8);
113 
114   h11_lc =
115       g_dd + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h11_lc), BYTE_ALIGN_8);
116   h11_rc =
117       h11_lc + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h11_rc), BYTE_ALIGN_8);
118   h12_lc =
119       h11_rc + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_lc), BYTE_ALIGN_8);
120   h12_rc =
121       h12_lc + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_rc), BYTE_ALIGN_8);
122   h21_lc =
123       h12_rc + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h21_lc), BYTE_ALIGN_8);
124   h21_rc =
125       h21_lc + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h21_rc), BYTE_ALIGN_8);
126   h22_lc =
127       h21_rc + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_lc), BYTE_ALIGN_8);
128   h22_rc =
129       h22_lc + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_rc), BYTE_ALIGN_8);
130   h12_res_lc = h22_rc + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_res_lc),
131                                                       BYTE_ALIGN_8);
132   h12_res_rc = h12_res_lc + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS,
133                                                           sizeof(*h12_res_rc), BYTE_ALIGN_8);
134   h22_res_lc = h12_res_rc + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS,
135                                                           sizeof(*h22_res_lc), BYTE_ALIGN_8);
136   h22_res_rc = h22_res_lc + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS,
137                                                           sizeof(*h22_res_rc), BYTE_ALIGN_8);
138 
139   c_f_l = (WORD16 *)pstr_mps_state->mps_scratch_mem_v +
140           IXHEAAC_GET_SIZE_ALIGNED_TYPE(PARAMETER_BANDSX56, sizeof(*c_f_l), BYTE_ALIGN_8);
141   c_f_r =
142       c_f_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*c_f_r), BYTE_ALIGN_8);
143   dummy =
144       c_f_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*dummy), BYTE_ALIGN_8);
145   c_f_lc =
146       dummy + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*c_f_lc), BYTE_ALIGN_8);
147   c_f_rc =
148       c_f_lc + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*c_f_rc), BYTE_ALIGN_8);
149 
150   if (enable_additionals) {
151     if (mode_1 == 0 &&
152         (p_aux_struct->ttt_config[1][0].start_band >= p_aux_struct->ttt_config[1][0].stop_band))
153       enable_additionals = 0;
154     else if (mode_0 == 0 && (p_aux_struct->ttt_config[0][0].start_band >=
155                              p_aux_struct->ttt_config[0][0].stop_band))
156       enable_additionals = 0;
157   }
158 
159   for (ps = 0; ps < num_parameter_sets; ps++) {
160     ixheaacd_param_2_umx_ps(pstr_mps_state, h11_l, h12_l, h21_l, h22_l, h12_res_l, h22_res_l,
161                             c_f_l, dummy, 1, ps, res_bands[1]);
162     ixheaacd_param_2_umx_ps(pstr_mps_state, h11_r, h12_r, h21_r, h22_r, h12_res_r, h22_res_r,
163                             c_f_r, dummy, 2, ps, res_bands[2]);
164     ixheaacd_param_2_umx_ps(pstr_mps_state, h11_lc, h12_lc, h21_lc, h22_lc, h12_res_lc,
165                             h22_res_lc, c_f_lc, dummy, 3, ps, res_bands[3]);
166     ixheaacd_param_2_umx_ps(pstr_mps_state, h11_rc, h12_rc, h21_rc, h22_rc, h12_res_rc,
167                             h22_res_rc, c_f_rc, dummy, 4, ps, res_bands[4]);
168 
169     for (i = 0; i < 2; i++) {
170       for (pb = p_aux_struct->ttt_config[i][0].start_band;
171            pb < p_aux_struct->ttt_config[i][0].stop_band; pb++) {
172         WORD32 mtx_inversion = pstr_mps_state->mtx_inversion;
173 
174         memset(m_pre, 0, sizeof(m_pre));
175 
176         if (p_aux_struct->ttt_config[i][0].mode >= 2) {
177           mtx_inversion = mtx_inversion && (p_aux_struct->ttt_config[i][0].mode == 2 ||
178                                             p_aux_struct->ttt_config[i][0].mode == 4);
179         }
180 
181         ixheaacd_calculate_ttt(pstr_mps_state, ps, pb, p_aux_struct->ttt_config[i][0].mode,
182                                m_ttt);
183 
184         for (row = 0; row < 3; row++) {
185           for (col = 0; col < 3; col++) {
186             m_pre[row][col] = m_ttt[row][col];
187           }
188         }
189 
190         if (arbitrary_downmix != 0) {
191           WORD32 ch;
192           ixheaacd_calculate_arb_dmx_mtx(pstr_mps_state, ps, pb, g_real);
193 
194           for (ch = 0; ch < num_input_channels; ch++) {
195             for (row = 0; row < 3; row++) {
196               m_pre[row][col] = ixheaacd_mps_mult32_shr_15(m_pre[row][col], g_real[ch]);
197 
198               if (arbitrary_downmix == 2 && pb < pstr_mps_state->arbdmx_residual_bands) {
199                 m_pre[row][3 + ch] = m_ttt[row][ch];
200               }
201             }
202           }
203         }
204 
205         if (mtx_inversion) {
206           WORD32 h_real[2][2], h_imag[2][2];
207 
208           ixheaacd_calculate_mtx_inv(pstr_mps_state, ps, pb, p_aux_struct->ttt_config[i][0].mode,
209                                      h_real, h_imag);
210 
211           acc = (WORD64)((WORD64)m_pre[0][0] * (WORD64)h_real[0][0] +
212                          (WORD64)m_pre[0][1] * (WORD64)h_real[1][0]);
213           acc >>= 15;
214           m1_param->m1_param_real[0][0][ps][pb] = (WORD32)acc;
215 
216           acc = (WORD64)((WORD64)m_pre[0][0] * (WORD64)h_real[0][1] +
217                          (WORD64)m_pre[0][1] * (WORD64)h_real[1][1]);
218           acc >>= 15;
219           m1_param->m1_param_real[0][1][ps][pb] = (WORD32)acc;
220 
221           acc = (WORD64)((WORD64)m_pre[1][0] * (WORD64)h_real[0][0] +
222                          (WORD64)m_pre[1][1] * (WORD64)h_real[1][0]);
223           acc >>= 15;
224           m1_param->m1_param_real[1][0][ps][pb] = (WORD32)acc;
225 
226           acc = (WORD64)((WORD64)m_pre[1][0] * (WORD64)h_real[0][1] +
227                          (WORD64)m_pre[1][1] * (WORD64)h_real[1][1]);
228           acc >>= 15;
229           m1_param->m1_param_real[1][1][ps][pb] = (WORD32)acc;
230 
231           acc = (WORD64)((WORD64)m_pre[2][0] * (WORD64)h_real[0][0] +
232                          (WORD64)m_pre[2][1] * (WORD64)h_real[1][0]);
233           acc >>= 15;
234           m1_param->m1_param_real[2][0][ps][pb] = (WORD32)acc;
235 
236           acc = (WORD64)((WORD64)m_pre[2][0] * (WORD64)h_real[0][1] +
237                          (WORD64)m_pre[2][1] * (WORD64)h_real[1][1]);
238           acc >>= 15;
239           m1_param->m1_param_real[2][1][ps][pb] = (WORD32)acc;
240 
241           acc = (WORD64)((WORD64)m_pre[0][0] * (WORD64)h_imag[0][0] +
242                          (WORD64)m_pre[0][1] * (WORD64)h_imag[1][0]);
243           acc >>= 15;
244           m1_param->m1_param_imag[0][0][ps][pb] = (WORD32)acc;
245 
246           acc = (WORD64)((WORD64)m_pre[0][0] * (WORD64)h_imag[0][1] +
247                          (WORD64)m_pre[0][1] * (WORD64)h_imag[1][1]);
248           acc >>= 15;
249           m1_param->m1_param_imag[0][1][ps][pb] = (WORD32)acc;
250 
251           acc = (WORD64)((WORD64)m_pre[1][0] * (WORD64)h_imag[0][0] +
252                          (WORD64)m_pre[1][1] * (WORD64)h_imag[1][0]);
253           acc >>= 15;
254           m1_param->m1_param_imag[1][0][ps][pb] = (WORD32)acc;
255 
256           acc = (WORD64)((WORD64)m_pre[1][0] * (WORD64)h_imag[0][1] +
257                          (WORD64)m_pre[1][1] * (WORD64)h_imag[1][1]);
258           acc >>= 15;
259           m1_param->m1_param_imag[1][1][ps][pb] = (WORD32)acc;
260 
261           acc = (WORD64)((WORD64)m_pre[2][0] * (WORD64)h_imag[0][0] +
262                          (WORD64)m_pre[2][1] * (WORD64)h_imag[1][0]);
263           acc >>= 15;
264           m1_param->m1_param_imag[2][0][ps][pb] = (WORD32)acc;
265 
266           acc = (WORD64)((WORD64)m_pre[2][0] * (WORD64)h_imag[0][1] +
267                          (WORD64)m_pre[2][1] * (WORD64)h_imag[1][1]);
268           acc >>= 15;
269           m1_param->m1_param_imag[2][1][ps][pb] = (WORD32)acc;
270         } else if (pstr_mps_state->_3d_stereo_inversion) {
271         } else {
272           m1_param->m1_param_real[0][0][ps][pb] = m_pre[0][0];
273           m1_param->m1_param_real[0][1][ps][pb] = m_pre[0][1];
274           m1_param->m1_param_real[1][0][ps][pb] = m_pre[1][0];
275           m1_param->m1_param_real[1][1][ps][pb] = m_pre[1][1];
276           m1_param->m1_param_real[2][0][ps][pb] = m_pre[2][0];
277           m1_param->m1_param_real[2][1][ps][pb] = m_pre[2][1];
278         }
279 
280         m1_param->m1_param_real[0][2][ps][pb] = m_pre[0][2];
281         m1_param->m1_param_real[0][3][ps][pb] = m_pre[0][3];
282         m1_param->m1_param_real[0][4][ps][pb] = m_pre[0][4];
283         m1_param->m1_param_real[1][2][ps][pb] = m_pre[1][2];
284         m1_param->m1_param_real[1][3][ps][pb] = m_pre[1][3];
285         m1_param->m1_param_real[1][4][ps][pb] = m_pre[1][4];
286         m1_param->m1_param_real[2][2][ps][pb] = m_pre[2][2];
287         m1_param->m1_param_real[2][3][ps][pb] = m_pre[2][3];
288         m1_param->m1_param_real[2][4][ps][pb] = m_pre[2][4];
289 
290         for (col = 0; col < pstr_mps_state->num_x_channels; col++) {
291           m1_param->m1_param_real[3][col][ps][pb] = m1_param->m1_param_real[0][col][ps][pb];
292           m1_param->m1_param_real[4][col][ps][pb] = m1_param->m1_param_real[1][col][ps][pb];
293 
294           curr_state->m1_param_present[3][col] = 1;
295           curr_state->m1_param_present[4][col] = 1;
296 
297           if (m1_param_imag_present) {
298             m1_param->m1_param_imag[3][col][ps][pb] = m1_param->m1_param_imag[0][col][ps][pb];
299             m1_param->m1_param_imag[4][col][ps][pb] = m1_param->m1_param_imag[1][col][ps][pb];
300           }
301 
302           if (p_aux_struct->ttt_config[i][0].use_ttt_decorr) {
303             m1_param->m1_param_real[5][col][ps][pb] = m1_param->m1_param_real[2][col][ps][pb];
304             if (m1_param_imag_present)
305               m1_param->m1_param_imag[5][col][ps][pb] = m1_param->m1_param_imag[2][col][ps][pb];
306 
307             curr_state->m1_param_present[5][col] = 1;
308           } else {
309             m1_param->m1_param_real[5][col][ps][pb] = 0;
310             if (m1_param_imag_present) m1_param->m1_param_imag[5][col][ps][pb] = 0;
311           }
312 
313           m1_param->m1_param_real[6][col][ps][pb] =
314               ixheaacd_mps_mult32_shr_15(c_f_l[pb], m1_param->m1_param_real[0][col][ps][pb]);
315           m1_param->m1_param_real[7][col][ps][pb] =
316               ixheaacd_mps_mult32_shr_15(c_f_r[pb], m1_param->m1_param_real[1][col][ps][pb]);
317 
318           if (m1_param_imag_present) {
319             m1_param->m1_param_imag[6][col][ps][pb] =
320                 ixheaacd_mps_mult32_shr_15(c_f_l[pb], m1_param->m1_param_imag[0][col][ps][pb]);
321             m1_param->m1_param_imag[7][col][ps][pb] =
322                 ixheaacd_mps_mult32_shr_15(c_f_r[pb], m1_param->m1_param_imag[1][col][ps][pb]);
323           }
324 
325           curr_state->m1_param_present[6][col] = 1;
326           curr_state->m1_param_present[7][col] = 1;
327         }
328       }
329     }
330 
331     for (pb = 0; pb < p_aux_struct->num_ott_bands[0]; pb++) {
332       ia_mps_dec_spatial_bs_frame_struct *p_cur_bs = pstr_mps_state->bs_frame;
333       c_l_clfe[pb] = pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr
334                          ->r1_matrix_l[p_cur_bs->ott_cld_idx[0][ps][pb] + 15];
335       c_r_clfe[pb] = pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr
336                          ->r1_matrix_l[15 - p_cur_bs->ott_cld_idx[0][ps][pb]];
337     }
338     for (pb = p_aux_struct->num_ott_bands[0]; pb < num_parameter_bands; pb++) {
339       c_l_clfe[pb] = ONE_IN_Q15;
340       c_r_clfe[pb] = 0;
341     }
342 
343     for (pb = 0; pb < num_parameter_bands; pb++) {
344       idx = 0;
345 
346       m2_param->m2_decor_real[idx++][ps][pb] = ixheaacd_mps_mult32_shr_15(h11_lc[pb], h12_l[pb]);
347       if (enable_additionals) {
348         pos[0] = idx++;
349       }
350       m2_param->m2_decor_real[idx++][ps][pb] = h12_lc[pb];
351       m2_param->m2_decor_real[idx++][ps][pb] = ixheaacd_mps_mult32_shr_15(h21_lc[pb], h12_l[pb]);
352       if (enable_additionals) {
353         pos[1] = idx++;
354       }
355       m2_param->m2_decor_real[idx++][ps][pb] = h22_lc[pb];
356       m2_param->m2_decor_real[idx++][ps][pb] = h22_l[pb];
357       m2_param->m2_decor_real[idx++][ps][pb] = ixheaacd_mps_mult32_shr_15(h11_rc[pb], h12_r[pb]);
358       if (enable_additionals) {
359         pos[2] = idx++;
360       }
361       m2_param->m2_decor_real[idx++][ps][pb] = h12_rc[pb];
362       m2_param->m2_decor_real[idx++][ps][pb] = ixheaacd_mps_mult32_shr_15(h21_rc[pb], h12_r[pb]);
363       if (enable_additionals) {
364         pos[3] = idx++;
365       }
366       m2_param->m2_decor_real[idx++][ps][pb] = h22_rc[pb];
367       m2_param->m2_decor_real[idx++][ps][pb] = h22_r[pb];
368       if (enable_additionals) {
369         pos[4] = idx++;
370       }
371     }
372 
373     for (pb = 0; pb < num_parameter_bands; pb++) {
374       idx = 0;
375 
376       m2_param->m2_resid_real[idx][ps][pb] = ixheaacd_mps_mult32_shr_15(h11_lc[pb], h11_l[pb]);
377       pos_resid[0] = idx++;
378 
379       if (residual_coding) {
380         m2_param->m2_resid_real[idx++][ps][pb] =
381             ixheaacd_mps_mult32_shr_15(h11_lc[pb], h12_res_l[pb]);
382         m2_param->m2_resid_real[idx++][ps][pb] = h12_res_lc[pb];
383       }
384 
385       m2_param->m2_resid_real[idx][ps][pb] = ixheaacd_mps_mult32_shr_15(h21_lc[pb], h11_l[pb]);
386       pos_resid[1] = idx++;
387 
388       if (residual_coding) {
389         m2_param->m2_resid_real[idx++][ps][pb] =
390             ixheaacd_mps_mult32_shr_15(h21_lc[pb], h12_res_l[pb]);
391         m2_param->m2_resid_real[idx++][ps][pb] = h22_res_lc[pb];
392       }
393 
394       m2_param->m2_resid_real[idx++][ps][pb] = h21_l[pb];
395 
396       if (residual_coding) m2_param->m2_resid_real[idx++][ps][pb] = h22_res_l[pb];
397 
398       m2_param->m2_resid_real[idx][ps][pb] = ixheaacd_mps_mult32_shr_15(h11_rc[pb], h11_r[pb]);
399       pos_resid[2] = idx++;
400 
401       if (residual_coding) {
402         m2_param->m2_resid_real[idx++][ps][pb] =
403             ixheaacd_mps_mult32_shr_15(h11_rc[pb], h12_res_r[pb]);
404         m2_param->m2_resid_real[idx++][ps][pb] = h12_res_rc[pb];
405       }
406 
407       m2_param->m2_resid_real[idx][ps][pb] = ixheaacd_mps_mult32_shr_15(h21_rc[pb], h11_r[pb]);
408       pos_resid[3] = idx++;
409 
410       if (residual_coding) {
411         m2_param->m2_resid_real[idx++][ps][pb] =
412             ixheaacd_mps_mult32_shr_15(h21_rc[pb], h12_res_r[pb]);
413         m2_param->m2_resid_real[idx++][ps][pb] = h22_res_rc[pb];
414       }
415 
416       m2_param->m2_resid_real[idx++][ps][pb] = h21_r[pb];
417 
418       if (residual_coding) m2_param->m2_resid_real[idx++][ps][pb] = h22_res_r[pb];
419 
420       m2_param->m2_resid_real[idx][ps][pb] = c_l_clfe[pb];
421       pos_resid[4] = idx++;
422 
423       m2_param->m2_resid_real[idx][ps][pb] = c_r_clfe[pb];
424     }
425 
426     for (pb = 0; pb < num_parameter_bands; pb++) {
427       ia_mps_dec_spatial_bs_frame_struct *p_cur_bs = pstr_mps_state->bs_frame;
428 
429       kappa[pb] = p_aux_struct->ttt_icc[0][ps][pb];
430       g_dd[pb] = pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr
431                      ->table_kappa[p_cur_bs->ttt_icc_idx[0][ps][pb]];
432     }
433 
434     for (i = 0; i < 2; i++) {
435       for (pb = p_aux_struct->ttt_config[i][0].start_band;
436            pb < p_aux_struct->ttt_config[i][0].stop_band; pb++) {
437         if (p_aux_struct->ttt_config[i][0].mode == 0 && pb >= pstr_mps_state->res_bands[5]) {
438           if (p_aux_struct->ttt_config[i][0].use_ttt_decorr) {
439             temp_1 = ixheaacd_mps_mult32_shr_15(g_dd[pb], c_f_l[pb]);
440             m2_param->m2_decor_real[pos[0]][ps][pb] =
441                 ixheaacd_mps_mult32_shr_15(temp_1, h11_lc[pb]);
442 
443             temp_1 = ixheaacd_mps_mult32_shr_15(g_dd[pb], c_f_l[pb]);
444             m2_param->m2_decor_real[pos[1]][ps][pb] =
445                 ixheaacd_mps_mult32_shr_15(temp_1, h21_lc[pb]);
446 
447             temp_1 = ixheaacd_mps_mult32_shr_15(g_dd[pb], c_f_r[pb]);
448             m2_param->m2_decor_real[pos[2]][ps][pb] =
449                 ixheaacd_mps_mult32_shr_15(temp_1, h11_rc[pb]);
450 
451             temp_1 = ixheaacd_mps_mult32_shr_15(g_dd[pb], c_f_r[pb]);
452             m2_param->m2_decor_real[pos[3]][ps][pb] =
453                 ixheaacd_mps_mult32_shr_15(temp_1, h21_rc[pb]);
454 
455             temp_1 = ixheaacd_mps_mult32_shr_15(g_dd[pb], c_l_clfe[pb]);
456             temp_2 = MINUS_SQRT_2_Q30;
457             m2_param->m2_decor_real[pos[4]][ps][pb] = ixheaacd_mps_mult32_shr_30(temp_1, temp_2);
458 
459             pstr_mps_state->m2_param_present[0][5] = 1;
460             pstr_mps_state->m2_param_present[1][5] = 1;
461             pstr_mps_state->m2_param_present[3][5] = 1;
462             pstr_mps_state->m2_param_present[4][5] = 1;
463             pstr_mps_state->m2_param_present[6][5] = 1;
464 
465             m2_param->m2_resid_real[pos_resid[0]][ps][pb] = ixheaacd_mps_mult32_shr_15(
466                 m2_param->m2_resid_real[pos_resid[0]][ps][pb], kappa[pb]);
467             m2_param->m2_resid_real[pos_resid[1]][ps][pb] = ixheaacd_mps_mult32_shr_15(
468                 m2_param->m2_resid_real[pos_resid[1]][ps][pb], kappa[pb]);
469             m2_param->m2_resid_real[pos_resid[2]][ps][pb] = ixheaacd_mps_mult32_shr_15(
470                 m2_param->m2_resid_real[pos_resid[2]][ps][pb], kappa[pb]);
471             m2_param->m2_resid_real[pos_resid[3]][ps][pb] = ixheaacd_mps_mult32_shr_15(
472                 m2_param->m2_resid_real[pos_resid[3]][ps][pb], kappa[pb]);
473             m2_param->m2_resid_real[pos_resid[4]][ps][pb] = ixheaacd_mps_mult32_shr_15(
474                 m2_param->m2_resid_real[pos_resid[4]][ps][pb], kappa[pb]);
475           }
476         }
477       }
478     }
479   }
480   return;
481 }
482 
ixheaacd_calc_m1m2_7272(ia_heaac_mps_state_struct * pstr_mps_state)483 VOID ixheaacd_calc_m1m2_7272(ia_heaac_mps_state_struct *pstr_mps_state) {
484   ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct;
485   ia_mps_dec_m2_param_struct *m2_param = p_aux_struct->m2_param;
486   ia_mps_dec_m1_param_struct *m1_param = pstr_mps_state->array_struct->m1_param;
487   ia_heaac_mps_state_struct *curr_state = pstr_mps_state;
488   WORD32 ps, pb, col, row, i;
489 
490   WORD32 m_pre[3][5];
491   WORD32 m_ttt[3][3];
492 
493   WORD32 g_real[2];
494 
495   WORD32 temp_1, temp_2;
496   WORD64 acc;
497 
498   WORD32 *h11_l, *h11_r, *h12_l, *h12_r, *h21_l, *h21_r, *h22_l, *h22_r, *h12_res_l, *h12_res_r,
499       *h22_res_l, *h22_res_r;
500   WORD32 *c_l_clfe, *c_r_clfe, *kappa, *g_dd;
501   WORD16 *c_1_L, *c_1_R, *c_2_L, *c_2_R;
502   WORD32 *h11_ls, *h11_rs, *h12_ls, *h12_rs, *h21_ls, *h21_rs, *h22_ls, *h22_rs, *h12_res_ls,
503       *h12_res_rs, *h22_res_ls, *h22_res_rs;
504   WORD16 *c_f_ls, *c_f_rs, *dummy;
505 
506   WORD32 idx;
507   WORD32 mode_0 = p_aux_struct->ttt_config[0][0].mode;
508   WORD32 mode_1 = p_aux_struct->ttt_config[1][0].mode;
509   WORD32 num_parameter_bands = pstr_mps_state->num_parameter_bands;
510   WORD32 m1_param_imag_present = pstr_mps_state->m1_param_imag_present;
511   WORD32 num_parameter_sets = pstr_mps_state->num_parameter_sets;
512   WORD32 arbitrary_downmix = pstr_mps_state->arbitrary_downmix;
513 
514   WORD32 enable_additionals = ((mode_0 == 0) || (mode_1 == 0));
515   WORD32 pos[3] = {0};
516   WORD32 pos_resid[3] = {0};
517 
518   WORD32 residual_coding = pstr_mps_state->residual_coding;
519 
520   h11_l = pstr_mps_state->mps_scratch_mem_v;
521   h11_r =
522       h11_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h11_r), BYTE_ALIGN_8);
523   h12_l =
524       h11_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_l), BYTE_ALIGN_8);
525   h12_r =
526       h12_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_r), BYTE_ALIGN_8);
527   h21_l =
528       h12_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h21_l), BYTE_ALIGN_8);
529   h21_r =
530       h21_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h21_r), BYTE_ALIGN_8);
531   h22_l =
532       h21_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_l), BYTE_ALIGN_8);
533   h22_r =
534       h22_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_r), BYTE_ALIGN_8);
535   h12_res_l = h22_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_res_l),
536                                                     BYTE_ALIGN_8);
537   h12_res_r = h12_res_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_res_r),
538                                                         BYTE_ALIGN_8);
539   h22_res_l = h12_res_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_res_l),
540                                                         BYTE_ALIGN_8);
541   h22_res_r = h22_res_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_res_r),
542                                                         BYTE_ALIGN_8);
543   c_l_clfe = h22_res_r +
544              IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*c_l_clfe), BYTE_ALIGN_8);
545   c_r_clfe = c_l_clfe +
546              IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*c_r_clfe), BYTE_ALIGN_8);
547   kappa =
548       c_r_clfe + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*kappa), BYTE_ALIGN_8);
549   g_dd = kappa + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*g_dd), BYTE_ALIGN_8);
550 
551   h11_ls =
552       g_dd + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h11_ls), BYTE_ALIGN_8);
553   h11_rs =
554       h11_ls + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h11_rs), BYTE_ALIGN_8);
555   h12_ls =
556       h11_rs + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_ls), BYTE_ALIGN_8);
557   h12_rs =
558       h12_ls + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_rs), BYTE_ALIGN_8);
559   h21_ls =
560       h12_rs + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h21_ls), BYTE_ALIGN_8);
561   h21_rs =
562       h21_ls + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h21_rs), BYTE_ALIGN_8);
563   h22_ls =
564       h21_rs + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_ls), BYTE_ALIGN_8);
565   h22_rs =
566       h22_ls + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_rs), BYTE_ALIGN_8);
567   h12_res_ls = h22_rs + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_res_ls),
568                                                       BYTE_ALIGN_8);
569   h12_res_rs = h12_res_ls + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS,
570                                                           sizeof(*h12_res_rs), BYTE_ALIGN_8);
571   h22_res_ls = h12_res_rs + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS,
572                                                           sizeof(*h22_res_ls), BYTE_ALIGN_8);
573   h22_res_rs = h22_res_ls + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS,
574                                                           sizeof(*h22_res_rs), BYTE_ALIGN_8);
575 
576   c_1_L = (WORD16 *)pstr_mps_state->mps_scratch_mem_v +
577           IXHEAAC_GET_SIZE_ALIGNED_TYPE(PARAMETER_BANDSX56, sizeof(*c_1_L), BYTE_ALIGN_8);
578   c_1_R =
579       c_1_L + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*c_1_R), BYTE_ALIGN_8);
580   c_2_L =
581       c_1_R + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*c_2_L), BYTE_ALIGN_8);
582   c_2_R =
583       c_2_L + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*c_2_R), BYTE_ALIGN_8);
584   c_f_ls =
585       c_2_R + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*c_f_ls), BYTE_ALIGN_8);
586   c_f_rs =
587       c_f_ls + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*c_f_rs), BYTE_ALIGN_8);
588   dummy =
589       c_f_rs + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*dummy), BYTE_ALIGN_8);
590 
591   if (enable_additionals) {
592     if (mode_1 == 0 &&
593         (p_aux_struct->ttt_config[1][0].start_band >= p_aux_struct->ttt_config[1][0].stop_band))
594       enable_additionals = 0;
595     else if (mode_0 == 0 && (p_aux_struct->ttt_config[0][0].start_band >=
596                              p_aux_struct->ttt_config[0][0].stop_band))
597       enable_additionals = 0;
598   }
599 
600   for (ps = 0; ps < num_parameter_sets; ps++) {
601     ixheaacd_param_2_umx_ps(pstr_mps_state, h11_l, h12_l, h21_l, h22_l, h12_res_l, h22_res_l,
602                             c_1_L, c_2_L, 1, ps, pstr_mps_state->res_bands[1]);
603     ixheaacd_param_2_umx_ps(pstr_mps_state, h11_r, h12_r, h21_r, h22_r, h12_res_r, h22_res_r,
604                             c_1_R, c_2_R, 2, ps, pstr_mps_state->res_bands[2]);
605     ixheaacd_param_2_umx_ps(pstr_mps_state, h11_ls, h12_ls, h21_ls, h22_ls, h12_res_ls,
606                             h22_res_ls, dummy, c_f_ls, 3, ps, pstr_mps_state->res_bands[3]);
607     ixheaacd_param_2_umx_ps(pstr_mps_state, h11_rs, h12_rs, h21_rs, h22_rs, h12_res_rs,
608                             h22_res_rs, dummy, c_f_rs, 4, ps, pstr_mps_state->res_bands[4]);
609 
610     for (i = 0; i < 2; i++) {
611       for (pb = p_aux_struct->ttt_config[i][0].start_band;
612            pb < p_aux_struct->ttt_config[i][0].stop_band; pb++) {
613         WORD32 mtx_inversion = pstr_mps_state->mtx_inversion;
614 
615         memset(m_pre, 0, sizeof(m_pre));
616 
617         if (p_aux_struct->ttt_config[i][0].mode >= 2) {
618           mtx_inversion = mtx_inversion && (p_aux_struct->ttt_config[i][0].mode == 2 ||
619                                             p_aux_struct->ttt_config[i][0].mode == 4);
620         }
621 
622         ixheaacd_calculate_ttt(pstr_mps_state, ps, pb, p_aux_struct->ttt_config[i][0].mode,
623                                m_ttt);
624 
625         for (row = 0; row < 3; row++) {
626           for (col = 0; col < 3; col++) {
627             m_pre[row][col] = m_ttt[row][col];
628           }
629         }
630 
631         if (arbitrary_downmix != 0) {
632           WORD32 ch;
633           ixheaacd_calculate_arb_dmx_mtx(pstr_mps_state, ps, pb, g_real);
634 
635           for (ch = 0; ch < pstr_mps_state->num_input_channels; ch++) {
636             for (row = 0; row < 3; row++) {
637               m_pre[row][col] = ixheaacd_mps_mult32_shr_15(m_pre[row][col], g_real[ch]);
638 
639               if (arbitrary_downmix == 2 && pb < pstr_mps_state->arbdmx_residual_bands) {
640                 m_pre[row][3 + ch] = m_ttt[row][ch];
641               }
642             }
643           }
644         }
645 
646         if (mtx_inversion) {
647           WORD32 h_real[2][2], h_imag[2][2];
648 
649           ixheaacd_calculate_mtx_inv(pstr_mps_state, ps, pb, p_aux_struct->ttt_config[i][0].mode,
650                                      h_real, h_imag);
651 
652           acc = (WORD64)((WORD64)m_pre[0][0] * (WORD64)h_real[0][0] +
653                          (WORD64)m_pre[0][1] * (WORD64)h_real[1][0]);
654           acc >>= 15;
655           m1_param->m1_param_real[0][0][ps][pb] = (WORD32)acc;
656 
657           acc = (WORD64)((WORD64)m_pre[0][0] * (WORD64)h_real[0][1] +
658                          (WORD64)m_pre[0][1] * (WORD64)h_real[1][1]);
659           acc >>= 15;
660           m1_param->m1_param_real[0][1][ps][pb] = (WORD32)acc;
661 
662           acc = (WORD64)((WORD64)m_pre[1][0] * (WORD64)h_real[0][0] +
663                          (WORD64)m_pre[1][1] * (WORD64)h_real[1][0]);
664           acc >>= 15;
665           m1_param->m1_param_real[1][0][ps][pb] = (WORD32)acc;
666 
667           acc = (WORD64)((WORD64)m_pre[1][0] * (WORD64)h_real[0][1] +
668                          (WORD64)m_pre[1][1] * (WORD64)h_real[1][1]);
669           acc >>= 15;
670           m1_param->m1_param_real[1][1][ps][pb] = (WORD32)acc;
671 
672           acc = (WORD64)((WORD64)m_pre[2][0] * (WORD64)h_real[0][0] +
673                          (WORD64)m_pre[2][1] * (WORD64)h_real[1][0]);
674           acc >>= 15;
675           m1_param->m1_param_real[2][0][ps][pb] = (WORD32)acc;
676 
677           acc = (WORD64)((WORD64)m_pre[2][0] * (WORD64)h_real[0][1] +
678                          (WORD64)m_pre[2][1] * (WORD64)h_real[1][1]);
679           acc >>= 15;
680           m1_param->m1_param_real[2][1][ps][pb] = (WORD32)acc;
681 
682           acc = (WORD64)((WORD64)m_pre[0][0] * (WORD64)h_imag[0][0] +
683                          (WORD64)m_pre[0][1] * (WORD64)h_imag[1][0]);
684           acc >>= 15;
685           m1_param->m1_param_imag[0][0][ps][pb] = (WORD32)acc;
686 
687           acc = (WORD64)((WORD64)m_pre[0][0] * (WORD64)h_imag[0][1] +
688                          (WORD64)m_pre[0][1] * (WORD64)h_imag[1][1]);
689           acc >>= 15;
690           m1_param->m1_param_imag[0][1][ps][pb] = (WORD32)acc;
691 
692           acc = (WORD64)((WORD64)m_pre[1][0] * (WORD64)h_imag[0][0] +
693                          (WORD64)m_pre[1][1] * (WORD64)h_imag[1][0]);
694           acc >>= 15;
695           m1_param->m1_param_imag[1][0][ps][pb] = (WORD32)acc;
696 
697           acc = (WORD64)((WORD64)m_pre[1][0] * (WORD64)h_imag[0][1] +
698                          (WORD64)m_pre[1][1] * (WORD64)h_imag[1][1]);
699           acc >>= 15;
700           m1_param->m1_param_imag[1][1][ps][pb] = (WORD32)acc;
701 
702           acc = (WORD64)((WORD64)m_pre[2][0] * (WORD64)h_imag[0][0] +
703                          (WORD64)m_pre[2][1] * (WORD64)h_imag[1][0]);
704           acc >>= 15;
705           m1_param->m1_param_imag[2][0][ps][pb] = (WORD32)acc;
706 
707           acc = (WORD64)((WORD64)m_pre[2][0] * (WORD64)h_imag[0][1] +
708                          (WORD64)m_pre[2][1] * (WORD64)h_imag[1][1]);
709           acc >>= 15;
710           m1_param->m1_param_imag[2][1][ps][pb] = (WORD32)acc;
711         } else if (pstr_mps_state->_3d_stereo_inversion) {
712         } else {
713           m1_param->m1_param_real[0][0][ps][pb] = m_pre[0][0];
714           m1_param->m1_param_real[0][1][ps][pb] = m_pre[0][1];
715           m1_param->m1_param_real[1][0][ps][pb] = m_pre[1][0];
716           m1_param->m1_param_real[1][1][ps][pb] = m_pre[1][1];
717           m1_param->m1_param_real[2][0][ps][pb] = m_pre[2][0];
718           m1_param->m1_param_real[2][1][ps][pb] = m_pre[2][1];
719         }
720 
721         m1_param->m1_param_real[0][2][ps][pb] = m_pre[0][2];
722         m1_param->m1_param_real[0][3][ps][pb] = m_pre[0][3];
723         m1_param->m1_param_real[0][4][ps][pb] = m_pre[0][4];
724         m1_param->m1_param_real[1][2][ps][pb] = m_pre[1][2];
725         m1_param->m1_param_real[1][3][ps][pb] = m_pre[1][3];
726         m1_param->m1_param_real[1][4][ps][pb] = m_pre[1][4];
727         m1_param->m1_param_real[2][2][ps][pb] = m_pre[2][2];
728         m1_param->m1_param_real[2][3][ps][pb] = m_pre[2][3];
729         m1_param->m1_param_real[2][4][ps][pb] = m_pre[2][4];
730 
731         for (col = 0; col < pstr_mps_state->num_x_channels; col++) {
732           m1_param->m1_param_real[3][col][ps][pb] = m1_param->m1_param_real[0][col][ps][pb];
733           m1_param->m1_param_real[4][col][ps][pb] = m1_param->m1_param_real[1][col][ps][pb];
734 
735           if (m1_param_imag_present) {
736             m1_param->m1_param_imag[3][col][ps][pb] = m1_param->m1_param_imag[0][col][ps][pb];
737             m1_param->m1_param_imag[4][col][ps][pb] = m1_param->m1_param_imag[1][col][ps][pb];
738           }
739 
740           curr_state->m1_param_present[3][col] = 1;
741           curr_state->m1_param_present[4][col] = 1;
742 
743           if (p_aux_struct->ttt_config[i][0].use_ttt_decorr) {
744             m1_param->m1_param_real[5][col][ps][pb] = m1_param->m1_param_real[2][col][ps][pb];
745             if (m1_param_imag_present)
746               m1_param->m1_param_imag[5][col][ps][pb] = m1_param->m1_param_imag[2][col][ps][pb];
747 
748             curr_state->m1_param_present[5][col] = 1;
749           } else {
750             m1_param->m1_param_real[5][col][ps][pb] = 0;
751             if (m1_param_imag_present) m1_param->m1_param_imag[5][col][ps][pb] = 0;
752           }
753 
754           m1_param->m1_param_real[6][col][ps][pb] =
755               ixheaacd_mps_mult32_shr_15(m1_param->m1_param_real[0][col][ps][pb], c_2_L[pb]);
756           m1_param->m1_param_real[7][col][ps][pb] =
757               ixheaacd_mps_mult32_shr_15(m1_param->m1_param_real[1][col][ps][pb], c_2_R[pb]);
758 
759           if (m1_param_imag_present) {
760             m1_param->m1_param_imag[6][col][ps][pb] =
761                 ixheaacd_mps_mult32_shr_15(m1_param->m1_param_imag[0][col][ps][pb], c_2_L[pb]);
762             m1_param->m1_param_imag[7][col][ps][pb] =
763                 ixheaacd_mps_mult32_shr_15(m1_param->m1_param_imag[1][col][ps][pb], c_2_R[pb]);
764           }
765 
766           curr_state->m1_param_present[6][col] = 1;
767           curr_state->m1_param_present[7][col] = 1;
768         }
769       }
770     }
771 
772     for (pb = 0; pb < p_aux_struct->num_ott_bands[0]; pb++) {
773       ia_mps_dec_spatial_bs_frame_struct *p_cur_bs = pstr_mps_state->bs_frame;
774       c_l_clfe[pb] = pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr
775                          ->r1_matrix_l[p_cur_bs->ott_cld_idx[0][ps][pb] + 15];
776       c_r_clfe[pb] = pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr
777                          ->r1_matrix_l[15 - p_cur_bs->ott_cld_idx[0][ps][pb]];
778     }
779     for (pb = p_aux_struct->num_ott_bands[0]; pb < num_parameter_bands; pb++) {
780       c_l_clfe[pb] = ONE_IN_Q15;
781       c_r_clfe[pb] = 0;
782     }
783 
784     for (pb = 0; pb < num_parameter_bands; pb++) {
785       idx = 0;
786 
787       m2_param->m2_decor_real[idx++][ps][pb] = h12_l[pb];
788       if (enable_additionals) {
789         pos[0] = idx++;
790       }
791       m2_param->m2_decor_real[idx++][ps][pb] = ixheaacd_mps_mult32_shr_15(h11_ls[pb], h22_l[pb]);
792       m2_param->m2_decor_real[idx++][ps][pb] = h12_ls[pb];
793       m2_param->m2_decor_real[idx++][ps][pb] = ixheaacd_mps_mult32_shr_15(h21_ls[pb], h22_l[pb]);
794       m2_param->m2_decor_real[idx++][ps][pb] = h22_ls[pb];
795       m2_param->m2_decor_real[idx++][ps][pb] = h12_r[pb];
796       if (enable_additionals) {
797         pos[1] = idx++;
798       }
799       m2_param->m2_decor_real[idx++][ps][pb] = ixheaacd_mps_mult32_shr_15(h11_rs[pb], h22_r[pb]);
800       m2_param->m2_decor_real[idx++][ps][pb] = h12_rs[pb];
801       m2_param->m2_decor_real[idx++][ps][pb] = ixheaacd_mps_mult32_shr_15(h21_rs[pb], h22_r[pb]);
802       m2_param->m2_decor_real[idx++][ps][pb] = h22_rs[pb];
803       if (enable_additionals) {
804         pos[2] = idx++;
805       }
806     }
807 
808     for (pb = 0; pb < num_parameter_bands; pb++) {
809       idx = 0;
810       m2_param->m2_resid_real[idx][ps][pb] = h11_l[pb];
811       pos_resid[0] = idx++;
812 
813       if (residual_coding) m2_param->m2_resid_real[idx++][ps][pb] = h12_res_l[pb];
814 
815       m2_param->m2_resid_real[idx++][ps][pb] = ixheaacd_mps_mult32_shr_15(h11_ls[pb], h21_l[pb]);
816 
817       if (residual_coding) {
818         m2_param->m2_resid_real[idx++][ps][pb] =
819             ixheaacd_mps_mult32_shr_15(h11_ls[pb], h22_res_l[pb]);
820         m2_param->m2_resid_real[idx++][ps][pb] = h12_res_ls[pb];
821       }
822 
823       m2_param->m2_resid_real[idx++][ps][pb] = ixheaacd_mps_mult32_shr_15(h21_ls[pb], h21_l[pb]);
824 
825       if (residual_coding) {
826         m2_param->m2_resid_real[idx++][ps][pb] =
827             ixheaacd_mps_mult32_shr_15(h21_ls[pb], h22_res_l[pb]);
828         m2_param->m2_resid_real[idx++][ps][pb] = h22_res_ls[pb];
829       }
830 
831       m2_param->m2_resid_real[idx][ps][pb] = h11_r[pb];
832       pos_resid[1] = idx++;
833 
834       if (residual_coding) m2_param->m2_resid_real[idx++][ps][pb] = h12_res_r[pb];
835 
836       m2_param->m2_resid_real[idx++][ps][pb] = ixheaacd_mps_mult32_shr_15(h11_rs[pb], h21_r[pb]);
837 
838       if (residual_coding) {
839         m2_param->m2_resid_real[idx++][ps][pb] =
840             ixheaacd_mps_mult32_shr_15(h11_rs[pb], h22_res_r[pb]);
841         m2_param->m2_resid_real[idx++][ps][pb] = h12_res_rs[pb];
842       }
843 
844       m2_param->m2_resid_real[idx++][ps][pb] = ixheaacd_mps_mult32_shr_15(h21_rs[pb], h21_r[pb]);
845 
846       if (residual_coding) {
847         m2_param->m2_resid_real[idx++][ps][pb] =
848             ixheaacd_mps_mult32_shr_15(h21_rs[pb], h22_res_r[pb]);
849         m2_param->m2_resid_real[idx++][ps][pb] = h22_res_rs[pb];
850       }
851 
852       m2_param->m2_resid_real[idx][ps][pb] = c_l_clfe[pb];
853       pos_resid[2] = idx++;
854 
855       m2_param->m2_resid_real[idx++][ps][pb] = c_r_clfe[pb];
856     }
857 
858     for (pb = 0; pb < num_parameter_bands; pb++) {
859       ia_mps_dec_spatial_bs_frame_struct *p_cur_bs = pstr_mps_state->bs_frame;
860 
861       kappa[pb] = p_aux_struct->ttt_icc[0][ps][pb];
862       g_dd[pb] = pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr
863                      ->table_kappa[p_cur_bs->ttt_icc_idx[0][ps][pb]];
864     }
865 
866     for (i = 0; i < 2; i++) {
867       for (pb = p_aux_struct->ttt_config[i][0].start_band;
868            pb < p_aux_struct->ttt_config[i][0].stop_band; pb++) {
869         if (p_aux_struct->ttt_config[i][0].mode == 0 && pb >= pstr_mps_state->res_bands[5]) {
870           if (p_aux_struct->ttt_config[i][0].use_ttt_decorr) {
871             m2_param->m2_decor_real[pos[0]][ps][pb] =
872                 ixheaacd_mps_mult32_shr_15(g_dd[pb], c_1_L[pb]);
873 
874             m2_param->m2_decor_real[pos[1]][ps][pb] =
875                 ixheaacd_mps_mult32_shr_15(g_dd[pb], c_1_R[pb]);
876 
877             temp_1 = ixheaacd_mps_mult32_shr_15(g_dd[pb], c_l_clfe[pb]);
878             temp_2 = MINUS_SQRT_2_Q30;
879             m2_param->m2_decor_real[pos[2]][ps][pb] = ixheaacd_mps_mult32_shr_30(temp_1, temp_2);
880 
881             pstr_mps_state->m2_param_present[0][5] = 1;
882             pstr_mps_state->m2_param_present[3][5] = 1;
883             pstr_mps_state->m2_param_present[6][5] = 1;
884 
885             m2_param->m2_resid_real[pos_resid[0]][ps][pb] = ixheaacd_mps_mult32_shr_15(
886                 m2_param->m2_resid_real[pos_resid[0]][ps][pb], kappa[pb]);
887             m2_param->m2_resid_real[pos_resid[1]][ps][pb] = ixheaacd_mps_mult32_shr_15(
888                 m2_param->m2_resid_real[pos_resid[1]][ps][pb], kappa[pb]);
889             m2_param->m2_resid_real[pos_resid[2]][ps][pb] = ixheaacd_mps_mult32_shr_15(
890                 m2_param->m2_resid_real[pos_resid[2]][ps][pb], kappa[pb]);
891           }
892         }
893       }
894     }
895   }
896   return;
897 }
898