xref: /aosp_15_r20/external/libxaac/decoder/ixheaacd_mps_calc_m1m2_tree_52xx.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_5227(ia_heaac_mps_state_struct * pstr_mps_state)45 VOID ixheaacd_calc_m1m2_5227(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_m1_param_struct *m1_param = pstr_mps_state->array_struct->m1_param;
48   WORD32 ps, pb, i;
49   WORD32 row, col, ch;
50   WORD32 *a_prediction_mode;
51 
52   WORD32 *m_real;
53   WORD32 *m_imag;
54 
55   WORD32 *lf;
56   WORD32 *ls;
57   WORD32 *rf;
58   WORD32 *rs;
59   WORD32 *a_c1;
60   WORD32 *a_c2;
61   WORD32 *a_icc_c;
62 
63   WORD64 acc;
64   WORD32 num_parameter_sets = pstr_mps_state->num_parameter_sets;
65   WORD32 num_parameter_bands = pstr_mps_state->num_parameter_bands;
66   WORD32 arbitrary_downmix = pstr_mps_state->arbitrary_downmix;
67   WORD32 arbdmx_residual_bands = pstr_mps_state->arbdmx_residual_bands;
68   WORD32 in_ch = pstr_mps_state->num_input_channels;
69 
70   const WORD32 *cld_tab_1 = pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr->cld_tab_1;
71 
72   lf = pstr_mps_state->mps_scratch_mem_v;
73   ls = lf + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*ls), BYTE_ALIGN_8);
74   rf = ls + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*rf), BYTE_ALIGN_8);
75   rs = rf + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*rs), BYTE_ALIGN_8);
76   a_c1 = rs + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*a_c1), BYTE_ALIGN_8);
77   a_c2 = a_c1 + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*a_c2), BYTE_ALIGN_8);
78   a_icc_c =
79       a_c2 + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*a_icc_c), BYTE_ALIGN_8);
80   a_prediction_mode =
81       a_icc_c + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*a_prediction_mode),
82                                               BYTE_ALIGN_8);
83   m_real = a_prediction_mode +
84            IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*m_real), BYTE_ALIGN_8);
85   m_imag =
86       m_real + IXHEAAC_GET_SIZE_ALIGNED_TYPE(PARAMETER_BANDSX15, sizeof(*m_imag), BYTE_ALIGN_8);
87 
88   for (i = 0; i < PARAMETER_BANDSX15; i++) {
89     m_real[i] = 0;
90     m_imag[i] = 0;
91   }
92 
93   for (ps = 0; ps < num_parameter_sets; ps++) {
94     for (i = 0; i < 2; i++) {
95       for (pb = p_aux_struct->ttt_config[i][0].start_band;
96            pb < p_aux_struct->ttt_config[i][0].stop_band; pb++) {
97         WORD32 m_pre[3][5];
98         WORD32 m_ttt[3][3];
99         WORD32 mtx_inversion = pstr_mps_state->mtx_inversion;
100 
101         memset(m_pre, 0, sizeof(m_pre));
102 
103         if (p_aux_struct->ttt_config[i][0].mode >= 2) {
104           mtx_inversion = mtx_inversion && (p_aux_struct->ttt_config[i][0].mode == 2 ||
105                                             p_aux_struct->ttt_config[i][0].mode == 4);
106         }
107 
108         ixheaacd_calculate_ttt(pstr_mps_state, ps, pb, p_aux_struct->ttt_config[i][0].mode,
109                                m_ttt);
110 
111         for (row = 0; row < 3; row++) {
112           for (col = 0; col < 3; col++) {
113             m_pre[row][col] = m_ttt[row][col];
114           }
115         }
116 
117         if (arbitrary_downmix != 0) {
118           WORD32 g_real[2];
119           ixheaacd_calculate_arb_dmx_mtx(pstr_mps_state, ps, pb, g_real);
120 
121           if (arbitrary_downmix == 2 && pb < arbdmx_residual_bands) {
122             for (ch = 0; ch < in_ch; ch++) {
123               for (row = 0; row < 3; row++) {
124                 m_pre[row][ch] = ixheaacd_mps_mult32_shr_15(m_pre[row][ch], g_real[ch]);
125 
126                 m_pre[row][3 + ch] = m_ttt[row][ch];
127               }
128             }
129           } else {
130             for (ch = 0; ch < in_ch; ch++) {
131               for (row = 0; row < 3; row++) {
132                 m_pre[row][ch] = ixheaacd_mps_mult32_shr_15(m_pre[row][ch], g_real[ch]);
133               }
134             }
135           }
136         }
137 
138         if (mtx_inversion) {
139           WORD32 h_real[2][2];
140           WORD32 h_imag[2][2];
141 
142           ixheaacd_calculate_mtx_inv(pstr_mps_state, ps, pb, p_aux_struct->ttt_config[i][0].mode,
143                                      h_real, h_imag);
144 
145           acc = (WORD64)((WORD64)m_pre[0][0] * (WORD64)h_real[0][0] +
146                          (WORD64)m_pre[0][1] * (WORD64)h_real[1][0]);
147           acc >>= 15;
148           m_real[0] = (WORD32)acc;
149 
150           acc = (WORD64)((WORD64)m_pre[0][0] * (WORD64)h_real[0][1] +
151                          (WORD64)m_pre[0][1] * (WORD64)h_real[1][1]);
152           acc >>= 15;
153           m_real[1] = (WORD32)acc;
154 
155           acc = (WORD64)((WORD64)m_pre[1][0] * (WORD64)h_real[0][0] +
156                          (WORD64)m_pre[1][1] * (WORD64)h_real[1][0]);
157           acc >>= 15;
158           m_real[5] = (WORD32)acc;
159 
160           acc = (WORD64)((WORD64)m_pre[1][0] * (WORD64)h_real[0][1] +
161                          (WORD64)m_pre[1][1] * (WORD64)h_real[1][1]);
162           acc >>= 15;
163           m_real[6] = (WORD32)acc;
164 
165           acc = (WORD64)((WORD64)m_pre[2][0] * (WORD64)h_real[0][0] +
166                          (WORD64)m_pre[2][1] * (WORD64)h_real[1][0]);
167           acc >>= 15;
168           m_real[10] = (WORD32)acc;
169 
170           acc = (WORD64)((WORD64)m_pre[2][0] * (WORD64)h_real[0][1] +
171                          (WORD64)m_pre[2][1] * (WORD64)h_real[1][1]);
172           acc >>= 15;
173           m_real[11] = (WORD32)acc;
174 
175           acc = (WORD64)((WORD64)m_pre[0][0] * (WORD64)h_imag[0][0] +
176                          (WORD64)m_pre[0][1] * (WORD64)h_imag[1][0]);
177           acc >>= 15;
178           m_imag[0] = (WORD32)acc;
179 
180           acc = (WORD64)((WORD64)m_pre[0][0] * (WORD64)h_imag[0][1] +
181                          (WORD64)m_pre[0][1] * (WORD64)h_imag[1][1]);
182           acc >>= 15;
183           m_imag[1] = (WORD32)acc;
184 
185           acc = (WORD64)((WORD64)m_pre[1][0] * (WORD64)h_imag[0][0] +
186                          (WORD64)m_pre[1][1] * (WORD64)h_imag[1][0]);
187           acc >>= 15;
188           m_imag[5] = (WORD32)acc;
189 
190           acc = (WORD64)((WORD64)m_pre[1][0] * (WORD64)h_imag[0][1] +
191                          (WORD64)m_pre[1][1] * (WORD64)h_imag[1][1]);
192           acc >>= 15;
193           m_imag[6] = (WORD32)acc;
194 
195           acc = (WORD64)((WORD64)m_pre[2][0] * (WORD64)h_imag[0][0] +
196                          (WORD64)m_pre[2][1] * (WORD64)h_imag[1][0]);
197           acc >>= 15;
198           m_imag[10] = (WORD32)acc;
199 
200           acc = (WORD64)((WORD64)m_pre[2][0] * (WORD64)h_imag[0][1] +
201                          (WORD64)m_pre[2][1] * (WORD64)h_imag[1][1]);
202           acc >>= 15;
203           m_imag[11] = (WORD32)acc;
204         } else if (pstr_mps_state->_3d_stereo_inversion) {
205         } else {
206           m_real[0] = m_pre[0][0];
207           m_real[1] = m_pre[0][1];
208           m_real[5] = m_pre[1][0];
209           m_real[6] = m_pre[1][1];
210           m_real[10] = m_pre[2][0];
211           m_real[11] = m_pre[2][1];
212 
213           m_imag[0] = 0;
214           m_imag[1] = 0;
215           m_imag[5] = 0;
216           m_imag[6] = 0;
217           m_imag[10] = 0;
218           m_imag[11] = 0;
219         }
220 
221         m_real[2] = m_pre[0][3];
222         m_real[3] = m_pre[0][4];
223         m_real[4] = m_pre[0][2];
224         m_real[7] = m_pre[1][3];
225         m_real[8] = m_pre[1][4];
226         m_real[9] = m_pre[1][2];
227         m_real[12] = m_pre[2][3];
228         m_real[13] = m_pre[2][4];
229         m_real[14] = m_pre[2][2];
230       }
231     }
232 
233     for (i = 0; i < 2; i++) {
234       for (pb = p_aux_struct->ttt_config[i][0].start_band;
235            pb < p_aux_struct->ttt_config[i][0].stop_band; pb++) {
236         ia_mps_dec_spatial_bs_frame_struct *p_cur_bs = pstr_mps_state->bs_frame;
237         if (p_aux_struct->ttt_config[i][0].mode < 2) {
238           a_prediction_mode[pb] = 1;
239           a_c1[pb] = p_aux_struct->ttt_cpc_1[0][ps][pb];
240           a_c2[pb] = p_aux_struct->ttt_cpc_2[0][ps][pb];
241           a_icc_c[pb] = p_aux_struct->ttt_icc[0][ps][pb];
242         } else {
243           a_prediction_mode[pb] = 0;
244           a_c1[pb] = p_aux_struct->ttt_cld_1[0][ps][pb];
245           a_c2[pb] = p_aux_struct->ttt_cld_2[0][ps][pb];
246           a_icc_c[pb] = 0;
247         }
248         lf[pb] = cld_tab_1[p_cur_bs->ott_cld_idx[1][ps][pb] + 15];
249         ls[pb] = cld_tab_1[15 - p_cur_bs->ott_cld_idx[1][ps][pb]];
250 
251         rf[pb] = cld_tab_1[p_cur_bs->ott_cld_idx[1][ps][pb] + 15];
252         rs[pb] = cld_tab_1[15 - p_cur_bs->ott_cld_idx[2][ps][pb]];
253       }
254     }
255 
256     for (pb = 0; pb < num_parameter_bands; pb++) {
257       m1_param->m1_param_real[0][0][ps][pb] = ONE_IN_Q15;
258       m1_param->m1_param_real[0][1][ps][pb] = 0;
259       m1_param->m1_param_real[1][0][ps][pb] = 0;
260       m1_param->m1_param_real[1][1][ps][pb] = ONE_IN_Q15;
261 
262       m1_param->m1_param_real[2][3][ps][pb] = ONE_IN_Q15;
263       m1_param->m1_param_real[2][4][ps][pb] = 0;
264       m1_param->m1_param_real[3][3][ps][pb] = 0;
265       m1_param->m1_param_real[3][4][ps][pb] = ONE_IN_Q15;
266     }
267   }
268 }
269 
ixheaacd_calc_m1m2_5251(ia_heaac_mps_state_struct * pstr_mps_state)270 VOID ixheaacd_calc_m1m2_5251(ia_heaac_mps_state_struct *pstr_mps_state) {
271   ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct;
272   ia_mps_dec_m2_param_struct *m2_param = p_aux_struct->m2_param;
273   ia_mps_dec_m1_param_struct *m1_param = pstr_mps_state->array_struct->m1_param;
274   WORD32 ch, ps, pb, col, row, i;
275 
276   WORD32 temp_1;
277   WORD32 *h11_l, *h11_r, *h12_l, *h12_r, *h21_l, *h21_r, *h22_l, *h22_r, *h12_res_l, *h12_res_r,
278       *h22_res_l, *h22_res_r;
279   WORD32 *c_l_clfe, *c_r_clfe, *kappa, *g_dd;
280   WORD16 *c_f_l, *c_f_r, *dummy1, *dummy2;
281 
282   WORD32 idx, index2 = 0, index3 = 0;
283   WORD32 mode_0 = p_aux_struct->ttt_config[0][0].mode;
284   WORD32 mode_1 = p_aux_struct->ttt_config[1][0].mode;
285   WORD32 enable_additionals = ((mode_0 == 0) || (mode_1 == 0));
286 
287   WORD32 num_decor_signals = pstr_mps_state->num_decor_signals;
288   WORD32 residual_coding = pstr_mps_state->residual_coding;
289   WORD32 num_parameter_sets = pstr_mps_state->num_parameter_sets;
290   WORD32 num_parameter_bands = pstr_mps_state->num_parameter_bands;
291   WORD32 m1_param_imag_present = pstr_mps_state->m1_param_imag_present;
292   WORD32 num_x_channels = pstr_mps_state->num_x_channels;
293   WORD32 arbitrary_downmix = pstr_mps_state->arbitrary_downmix;
294   WORD32 arbdmx_residual_bands = pstr_mps_state->arbdmx_residual_bands;
295   WORD32 in_ch = pstr_mps_state->num_input_channels;
296   WORD32 res_bands = pstr_mps_state->res_bands[3];
297 
298   WORD32 decorr_present;
299   WORD32 pos[3];
300   WORD64 acc;
301 
302   h11_l = pstr_mps_state->mps_scratch_mem_v;
303   h11_r =
304       h11_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h11_r), BYTE_ALIGN_8);
305   h12_l =
306       h11_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_l), BYTE_ALIGN_8);
307   h12_r =
308       h12_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_r), BYTE_ALIGN_8);
309   h21_l =
310       h12_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h21_l), BYTE_ALIGN_8);
311   h21_r =
312       h21_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h21_r), BYTE_ALIGN_8);
313   h22_l =
314       h21_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_l), BYTE_ALIGN_8);
315   h22_r =
316       h22_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_r), BYTE_ALIGN_8);
317   h12_res_l = h22_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_res_l),
318                                                     BYTE_ALIGN_8);
319   h12_res_r = h12_res_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_res_r),
320                                                         BYTE_ALIGN_8);
321   h22_res_l = h12_res_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_res_l),
322                                                         BYTE_ALIGN_8);
323   h22_res_r = h22_res_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_res_r),
324                                                         BYTE_ALIGN_8);
325   c_l_clfe = h22_res_r +
326              IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*c_l_clfe), BYTE_ALIGN_8);
327   c_r_clfe = c_l_clfe +
328              IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*c_r_clfe), BYTE_ALIGN_8);
329   kappa =
330       c_r_clfe + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*kappa), BYTE_ALIGN_8);
331   g_dd = kappa + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*g_dd), BYTE_ALIGN_8);
332 
333   c_f_l = (WORD16 *)pstr_mps_state->mps_scratch_mem_v +
334           IXHEAAC_GET_SIZE_ALIGNED_TYPE(PARAMETER_BANDSX32, sizeof(*c_f_l), BYTE_ALIGN_8);
335   c_f_r =
336       c_f_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*c_f_r), BYTE_ALIGN_8);
337   dummy1 =
338       c_f_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*dummy1), BYTE_ALIGN_8);
339   dummy2 =
340       dummy1 + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*dummy2), BYTE_ALIGN_8);
341 
342   if (enable_additionals) {
343     if (mode_1 == 0 &&
344         (p_aux_struct->ttt_config[1][0].start_band >= p_aux_struct->ttt_config[1][0].stop_band))
345       enable_additionals = 0;
346     else if (mode_0 == 0 && (p_aux_struct->ttt_config[0][0].start_band >=
347                              p_aux_struct->ttt_config[0][0].stop_band))
348       enable_additionals = 0;
349   }
350 
351   decorr_present = enable_additionals && num_decor_signals == 3;
352 
353   pstr_mps_state->num_decor_signals = 2;
354 
355   for (ps = 0; ps < num_parameter_sets; ps++) {
356     for (i = 0; i < 2; i++) {
357       for (pb = p_aux_struct->ttt_config[i][0].start_band;
358            pb < p_aux_struct->ttt_config[i][0].stop_band; pb++) {
359         WORD32 m_ttt[3][3];
360         WORD32 m_pre[3][5];
361         WORD32 mtx_inversion = pstr_mps_state->mtx_inversion;
362 
363         memset(m_pre, 0, sizeof(m_pre));
364 
365         if (p_aux_struct->ttt_config[i][0].mode >= 2) {
366           mtx_inversion = mtx_inversion && (p_aux_struct->ttt_config[i][0].mode == 2 ||
367                                             p_aux_struct->ttt_config[i][0].mode == 4);
368         }
369 
370         ixheaacd_calculate_ttt(pstr_mps_state, ps, pb, p_aux_struct->ttt_config[i][0].mode,
371                                m_ttt);
372 
373         for (row = 0; row < 3; row++) {
374           for (col = 0; col < 3; col++) {
375             m_pre[row][col] = m_ttt[row][col];
376           }
377         }
378 
379         if (arbitrary_downmix != 0) {
380           WORD32 g_real[2];
381           ixheaacd_calculate_arb_dmx_mtx(pstr_mps_state, ps, pb, g_real);
382 
383           if (arbitrary_downmix == 2 && pb < arbdmx_residual_bands) {
384             for (ch = 0; ch < in_ch; ch++) {
385               for (row = 0; row < 3; row++) {
386                 m_pre[row][ch] = ixheaacd_mps_mult32_shr_15(m_pre[row][ch], g_real[ch]);
387                 m_pre[row][3 + ch] = m_ttt[row][ch];
388               }
389             }
390           } else {
391             for (ch = 0; ch < in_ch; ch++) {
392               for (row = 0; row < 3; row++) {
393                 m_pre[row][ch] = ixheaacd_mps_mult32_shr_15(m_pre[row][ch], g_real[ch]);
394               }
395             }
396           }
397         }
398 
399         if (mtx_inversion) {
400           WORD32 h_real[2][2], h_imag[2][2];
401 
402           ixheaacd_calculate_mtx_inv(pstr_mps_state, ps, pb, p_aux_struct->ttt_config[i][0].mode,
403                                      h_real, h_imag);
404 
405           acc = (WORD64)((WORD64)m_pre[0][0] * (WORD64)h_real[0][0] +
406                          (WORD64)m_pre[0][1] * (WORD64)h_real[1][0]);
407           acc >>= 15;
408           m1_param->m1_param_real[0][0][ps][pb] = (WORD32)acc;
409 
410           acc = (WORD64)((WORD64)m_pre[0][0] * (WORD64)h_real[0][1] +
411                          (WORD64)m_pre[0][1] * (WORD64)h_real[1][1]);
412           acc >>= 15;
413           m1_param->m1_param_real[0][1][ps][pb] = (WORD32)acc;
414 
415           acc = (WORD64)((WORD64)m_pre[1][0] * (WORD64)h_real[0][0] +
416                          (WORD64)m_pre[1][1] * (WORD64)h_real[1][0]);
417           acc >>= 15;
418           m1_param->m1_param_real[1][0][ps][pb] = (WORD32)acc;
419 
420           acc = (WORD64)((WORD64)m_pre[1][0] * (WORD64)h_real[0][1] +
421                          (WORD64)m_pre[1][1] * (WORD64)h_real[1][1]);
422           acc >>= 15;
423           m1_param->m1_param_real[1][1][ps][pb] = (WORD32)acc;
424 
425           acc = (WORD64)((WORD64)m_pre[2][0] * (WORD64)h_real[0][0] +
426                          (WORD64)m_pre[2][1] * (WORD64)h_real[1][0]);
427           acc >>= 15;
428           m1_param->m1_param_real[2][0][ps][pb] = (WORD32)acc;
429 
430           acc = (WORD64)((WORD64)m_pre[2][0] * (WORD64)h_real[0][1] +
431                          (WORD64)m_pre[2][1] * (WORD64)h_real[1][1]);
432           acc >>= 15;
433           m1_param->m1_param_real[2][1][ps][pb] = (WORD32)acc;
434 
435           acc = (WORD64)((WORD64)m_pre[0][0] * (WORD64)h_imag[0][0] +
436                          (WORD64)m_pre[0][1] * (WORD64)h_imag[1][0]);
437           acc >>= 15;
438           m1_param->m1_param_imag[0][0][ps][pb] = (WORD32)acc;
439 
440           acc = (WORD64)((WORD64)m_pre[0][0] * (WORD64)h_imag[0][1] +
441                          (WORD64)m_pre[0][1] * (WORD64)h_imag[1][1]);
442           acc >>= 15;
443           m1_param->m1_param_imag[0][1][ps][pb] = (WORD32)acc;
444 
445           acc = (WORD64)((WORD64)m_pre[1][0] * (WORD64)h_imag[0][0] +
446                          (WORD64)m_pre[1][1] * (WORD64)h_imag[1][0]);
447           acc >>= 15;
448           m1_param->m1_param_imag[1][0][ps][pb] = (WORD32)acc;
449 
450           acc = (WORD64)((WORD64)m_pre[1][0] * (WORD64)h_imag[0][1] +
451                          (WORD64)m_pre[1][1] * (WORD64)h_imag[1][1]);
452           acc >>= 15;
453           m1_param->m1_param_imag[1][1][ps][pb] = (WORD32)acc;
454 
455           acc = (WORD64)((WORD64)m_pre[2][0] * (WORD64)h_imag[0][0] +
456                          (WORD64)m_pre[2][1] * (WORD64)h_imag[1][0]);
457           acc >>= 15;
458           m1_param->m1_param_imag[2][0][ps][pb] = (WORD32)acc;
459 
460           acc = (WORD64)((WORD64)m_pre[2][0] * (WORD64)h_imag[0][1] +
461                          (WORD64)m_pre[2][1] * (WORD64)h_imag[1][1]);
462           acc >>= 15;
463           m1_param->m1_param_imag[2][1][ps][pb] = (WORD32)acc;
464         } else if (pstr_mps_state->_3d_stereo_inversion) {
465         } else {
466           m1_param->m1_param_real[0][0][ps][pb] = m_pre[0][0];
467           m1_param->m1_param_real[0][1][ps][pb] = m_pre[0][1];
468           m1_param->m1_param_real[1][0][ps][pb] = m_pre[1][0];
469           m1_param->m1_param_real[1][1][ps][pb] = m_pre[1][1];
470           m1_param->m1_param_real[2][0][ps][pb] = m_pre[2][0];
471           m1_param->m1_param_real[2][1][ps][pb] = m_pre[2][1];
472           m1_param->m1_param_imag[0][0][ps][pb] = 0;
473           m1_param->m1_param_imag[0][1][ps][pb] = 0;
474           m1_param->m1_param_imag[1][0][ps][pb] = 0;
475           m1_param->m1_param_imag[1][1][ps][pb] = 0;
476           m1_param->m1_param_imag[2][0][ps][pb] = 0;
477           m1_param->m1_param_imag[2][1][ps][pb] = 0;
478         }
479 
480         m1_param->m1_param_real[0][2][ps][pb] = m_pre[0][2];
481         m1_param->m1_param_real[0][3][ps][pb] = m_pre[0][3];
482         m1_param->m1_param_real[0][4][ps][pb] = m_pre[0][4];
483         m1_param->m1_param_real[1][2][ps][pb] = m_pre[1][2];
484         m1_param->m1_param_real[1][3][ps][pb] = m_pre[1][3];
485         m1_param->m1_param_real[1][4][ps][pb] = m_pre[1][4];
486         m1_param->m1_param_real[2][2][ps][pb] = m_pre[2][2];
487         m1_param->m1_param_real[2][3][ps][pb] = m_pre[2][3];
488         m1_param->m1_param_real[2][4][ps][pb] = m_pre[2][4];
489 
490         m1_param->m1_param_imag[0][2][ps][pb] = 0;
491         m1_param->m1_param_imag[0][3][ps][pb] = 0;
492         m1_param->m1_param_imag[0][4][ps][pb] = 0;
493         m1_param->m1_param_imag[1][2][ps][pb] = 0;
494         m1_param->m1_param_imag[1][3][ps][pb] = 0;
495         m1_param->m1_param_imag[1][4][ps][pb] = 0;
496         m1_param->m1_param_imag[2][2][ps][pb] = 0;
497         m1_param->m1_param_imag[2][3][ps][pb] = 0;
498         m1_param->m1_param_imag[2][4][ps][pb] = 0;
499 
500         for (col = 0; col < num_x_channels; col++) {
501           m1_param->m1_param_real[3][col][ps][pb] = m1_param->m1_param_real[0][col][ps][pb];
502           m1_param->m1_param_real[4][col][ps][pb] = m1_param->m1_param_real[1][col][ps][pb];
503 
504           if (m1_param_imag_present) {
505             m1_param->m1_param_imag[3][col][ps][pb] = m1_param->m1_param_imag[0][col][ps][pb];
506             m1_param->m1_param_imag[4][col][ps][pb] = m1_param->m1_param_imag[1][col][ps][pb];
507           }
508           pstr_mps_state->m1_param_present[3][col] = 1;
509           pstr_mps_state->m1_param_present[4][col] = 1;
510 
511           if (p_aux_struct->ttt_config[i][0].use_ttt_decorr) {
512             m1_param->m1_param_real[5][col][ps][pb] = m1_param->m1_param_real[2][col][ps][pb];
513             if (m1_param_imag_present)
514               m1_param->m1_param_imag[5][col][ps][pb] = m1_param->m1_param_imag[2][col][ps][pb];
515 
516             pstr_mps_state->m1_param_present[5][col] = 1;
517           }
518         }
519       }
520     }
521   }
522 
523   for (ps = 0; ps < num_parameter_sets; ps++) {
524     ixheaacd_param_2_umx_ps(pstr_mps_state, h11_l, h12_l, h21_l, h22_l, h12_res_l, h22_res_l,
525                             c_f_l, dummy1, 1, ps, pstr_mps_state->res_bands[1]);
526 
527     ixheaacd_param_2_umx_ps(pstr_mps_state, h11_r, h12_r, h21_r, h22_r, h12_res_r, h22_res_r,
528                             c_f_r, dummy2, 2, ps, pstr_mps_state->res_bands[2]);
529 
530     for (pb = 0; pb < p_aux_struct->num_ott_bands[0]; pb++) {
531       WORD32 temp = ixheaacd_quantize((p_aux_struct->ott_cld[0][ps][pb]) >> 15);
532 
533       c_l_clfe[pb] = pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr->r1_matrix_l[temp + 15];
534       c_r_clfe[pb] = pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr->r1_matrix_l[15 - temp];
535     }
536 
537     for (pb = p_aux_struct->num_ott_bands[0]; pb < num_parameter_bands; pb++) {
538       c_l_clfe[pb] = ONE_IN_Q15;
539       c_r_clfe[pb] = 0;
540     }
541 
542     for (pb = 0; pb < num_parameter_bands; pb++) {
543       idx = 0;
544 
545       m2_param->m2_decor_real[idx++][ps][pb] = h12_l[pb];
546       if (enable_additionals) {
547         pos[0] = idx++;
548       }
549       m2_param->m2_decor_real[idx++][ps][pb] = h22_l[pb];
550       m2_param->m2_decor_real[idx++][ps][pb] = h12_r[pb];
551       if (enable_additionals) {
552         pos[1] = idx++;
553       }
554       m2_param->m2_decor_real[idx++][ps][pb] = h22_r[pb];
555       if (enable_additionals) {
556         pos[2] = idx++;
557       }
558     }
559 
560     for (pb = 0; pb < num_parameter_bands; pb++) {
561       idx = 1;
562 
563       m2_param->m2_resid_real[0][ps][pb] = h11_l[pb];
564 
565       if (residual_coding) m2_param->m2_resid_real[idx++][ps][pb] = h12_res_l[pb];
566 
567       if (decorr_present) idx++;
568 
569       m2_param->m2_resid_real[idx++][ps][pb] = h21_l[pb];
570 
571       if (residual_coding) m2_param->m2_resid_real[idx++][ps][pb] = h22_res_l[pb];
572 
573       m2_param->m2_resid_real[idx][ps][pb] = h11_r[pb];
574       index2 = idx++;
575 
576       if (residual_coding) m2_param->m2_resid_real[idx++][ps][pb] = h12_res_r[pb];
577 
578       if (decorr_present) idx++;
579 
580       m2_param->m2_resid_real[idx++][ps][pb] = h21_r[pb];
581 
582       if (residual_coding) m2_param->m2_resid_real[idx++][ps][pb] = h22_res_r[pb];
583 
584       m2_param->m2_resid_real[idx][ps][pb] = c_l_clfe[pb];
585       index3 = idx++;
586 
587       if (decorr_present) idx++;
588 
589       m2_param->m2_resid_real[idx++][ps][pb] = c_r_clfe[pb];
590     }
591 
592     for (pb = 0; pb < num_parameter_bands; pb++) {
593       ia_mps_dec_spatial_bs_frame_struct *p_cur_bs = pstr_mps_state->bs_frame;
594 
595       kappa[pb] = p_aux_struct->ttt_icc[0][ps][pb];
596       g_dd[pb] = pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr
597                      ->table_kappa[p_cur_bs->ttt_icc_idx[0][ps][pb]];
598     }
599 
600     for (i = 0; i < 2; i++) {
601       if (p_aux_struct->ttt_config[i][0].use_ttt_decorr) {
602         for (pb = p_aux_struct->ttt_config[i][0].start_band;
603              pb < p_aux_struct->ttt_config[i][0].stop_band; pb++) {
604           if (p_aux_struct->ttt_config[i][0].mode == 0 && pb >= res_bands) {
605             if (p_aux_struct->ttt_config[i][0].use_ttt_decorr && enable_additionals) {
606               WORD32 temp;
607               pstr_mps_state->num_decor_signals = 3;
608 
609               temp_1 = MINUS_SQRT_2_Q30;
610               m2_param->m2_decor_real[pos[0]][ps][pb] =
611                   ixheaacd_mps_mult32_shr_15(g_dd[pb], c_f_l[pb]);
612               m2_param->m2_decor_real[pos[1]][ps][pb] =
613                   ixheaacd_mps_mult32_shr_15(g_dd[pb], c_f_r[pb]);
614 
615               temp = ixheaacd_mps_mult32_shr_15(g_dd[pb], c_l_clfe[pb]);
616               m2_param->m2_decor_real[pos[2]][ps][pb] = ixheaacd_mps_mult32_shr_30(temp, temp_1);
617 
618               pstr_mps_state->m2_param_present[0][5] = 3;
619               pstr_mps_state->m2_param_present[2][5] = 3;
620               pstr_mps_state->m2_param_present[4][5] = 3;
621 
622               m2_param->m2_resid_real[0][ps][pb] =
623                   ixheaacd_mps_mult32_shr_15(m2_param->m2_resid_real[0][ps][pb], kappa[pb]);
624               m2_param->m2_resid_real[index2][ps][pb] =
625                   ixheaacd_mps_mult32_shr_15(m2_param->m2_resid_real[index2][ps][pb], kappa[pb]);
626               m2_param->m2_resid_real[index3][ps][pb] =
627                   ixheaacd_mps_mult32_shr_15(m2_param->m2_resid_real[index3][ps][pb], kappa[pb]);
628 
629               m2_param->m2_resid_real[pos[0]][ps][pb] =
630                   ixheaacd_mps_mult32_shr_15(g_dd[pb], c_f_l[pb]);
631               m2_param->m2_resid_real[pos[1]][ps][pb] =
632                   ixheaacd_mps_mult32_shr_15(g_dd[pb], c_f_r[pb]);
633 
634               temp = ixheaacd_mps_mult32_shr_15(g_dd[pb], c_l_clfe[pb]);
635               m2_param->m2_resid_real[pos[2]][ps][pb] = ixheaacd_mps_mult32_shr_30(temp, temp_1);
636             }
637           }
638         }
639       }
640     }
641   }
642   return;
643 }
644