xref: /aosp_15_r20/external/libxaac/decoder/ixheaacd_mps_calc_m1m2_tree_757x.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_7571(ia_heaac_mps_state_struct * pstr_mps_state)45 VOID ixheaacd_calc_m1m2_7571(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   WORD32 ps, pb;
50 
51   WORD32 *h11_l, *h11_r, *h12_l, *h12_r, *h21_l, *h21_r, *h22_l, *h22_r, *h12_res_l, *h12_res_r,
52       *h22_res_l, *h22_res_r;
53   WORD16 *c_f_l, *c_f_r, *dummy;
54 
55   WORD32 idx;
56   WORD32 residual_coding = pstr_mps_state->residual_coding;
57   WORD32 num_parameter_sets = pstr_mps_state->num_parameter_sets;
58   WORD32 num_parameter_bands = pstr_mps_state->num_parameter_bands;
59 
60   h11_l = pstr_mps_state->mps_scratch_mem_v;
61   h11_r =
62       h11_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h11_r), BYTE_ALIGN_8);
63   h12_l =
64       h11_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_l), BYTE_ALIGN_8);
65   h12_r =
66       h12_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_r), BYTE_ALIGN_8);
67   h21_l =
68       h12_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h21_l), BYTE_ALIGN_8);
69   h21_r =
70       h21_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h21_r), BYTE_ALIGN_8);
71   h22_l =
72       h21_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_l), BYTE_ALIGN_8);
73   h22_r =
74       h22_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_r), BYTE_ALIGN_8);
75   h12_res_l = h22_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_res_l),
76                                                     BYTE_ALIGN_8);
77   h12_res_r = h12_res_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_res_r),
78                                                         BYTE_ALIGN_8);
79   h22_res_l = h12_res_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_res_l),
80                                                         BYTE_ALIGN_8);
81   h22_res_r = h22_res_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_res_r),
82                                                         BYTE_ALIGN_8);
83 
84   c_f_l = (WORD16 *)pstr_mps_state->mps_scratch_mem_v +
85           IXHEAAC_GET_SIZE_ALIGNED_TYPE(PARAMETER_BANDSX24, sizeof(*c_f_l), BYTE_ALIGN_8);
86   c_f_r =
87       c_f_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*c_f_r), BYTE_ALIGN_8);
88   dummy =
89       c_f_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*dummy), BYTE_ALIGN_8);
90 
91   for (ps = 0; ps < num_parameter_sets; ps++) {
92     ixheaacd_param_2_umx_ps(pstr_mps_state, h11_l, h12_l, h21_l, h22_l, h12_res_l, h22_res_l,
93                             c_f_l, dummy, 0, ps, pstr_mps_state->res_bands[0]);
94     ixheaacd_param_2_umx_ps(pstr_mps_state, h11_r, h12_r, h21_r, h22_r, h12_res_r, h22_res_r,
95                             c_f_r, dummy, 1, ps, pstr_mps_state->res_bands[1]);
96 
97     for (pb = 0; pb < num_parameter_bands; pb++) {
98       m1_param->m1_param_real[0][0][ps][pb] = ONE_IN_Q15;
99       m1_param->m1_param_real[1][1][ps][pb] = ONE_IN_Q15;
100       m1_param->m1_param_real[2][2][ps][pb] = ONE_IN_Q15;
101       m1_param->m1_param_real[3][3][ps][pb] = ONE_IN_Q15;
102       m1_param->m1_param_real[4][4][ps][pb] = ONE_IN_Q15;
103       m1_param->m1_param_real[5][5][ps][pb] = ONE_IN_Q15;
104       m1_param->m1_param_real[6][0][ps][pb] = ONE_IN_Q15;
105       m1_param->m1_param_real[7][1][ps][pb] = ONE_IN_Q15;
106     }
107 
108     memcpy(m2_param->m2_decor_real[0][ps], h12_l, num_parameter_bands * sizeof(h12_l[0]));
109     memcpy(m2_param->m2_decor_real[1][ps], h22_l, num_parameter_bands * sizeof(h22_l[0]));
110     memcpy(m2_param->m2_decor_real[2][ps], h12_r, num_parameter_bands * sizeof(h12_r[0]));
111     memcpy(m2_param->m2_decor_real[3][ps], h22_r, num_parameter_bands * sizeof(h22_r[0]));
112 
113     for (pb = 0; pb < num_parameter_bands; pb++) {
114       idx = 0;
115 
116       m2_param->m2_resid_real[idx++][ps][pb] = h11_l[pb];
117 
118       if (residual_coding) m2_param->m2_resid_real[idx++][ps][pb] = h12_res_l[pb];
119 
120       m2_param->m2_resid_real[idx++][ps][pb] = h21_l[pb];
121 
122       if (residual_coding) m2_param->m2_resid_real[idx++][ps][pb] = h22_res_l[pb];
123 
124       m2_param->m2_resid_real[idx++][ps][pb] = ONE_IN_Q15;
125 
126       m2_param->m2_resid_real[idx++][ps][pb] = h11_r[pb];
127 
128       if (residual_coding) m2_param->m2_resid_real[idx++][ps][pb] = h12_res_r[pb];
129 
130       m2_param->m2_resid_real[idx++][ps][pb] = h21_r[pb];
131 
132       if (residual_coding) m2_param->m2_resid_real[idx++][ps][pb] = h22_res_r[pb];
133 
134       m2_param->m2_resid_real[idx++][ps][pb] = ONE_IN_Q15;
135 
136       m2_param->m2_resid_real[idx++][ps][pb] = ONE_IN_Q15;
137 
138       m2_param->m2_resid_real[idx++][ps][pb] = ONE_IN_Q15;
139     }
140   }
141   return;
142 }
143 
ixheaacd_calc_m1m2_7572(ia_heaac_mps_state_struct * pstr_mps_state)144 VOID ixheaacd_calc_m1m2_7572(ia_heaac_mps_state_struct *pstr_mps_state) {
145   ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct;
146   ia_mps_dec_m2_param_struct *m2_param = p_aux_struct->m2_param;
147   ia_mps_dec_m1_param_struct *m1_param = pstr_mps_state->array_struct->m1_param;
148   WORD32 ps, pb;
149   WORD32 *h11_l, *h11_r, *h12_l, *h12_r, *h21_l, *h21_r, *h22_l, *h22_r, *h12_res_l, *h12_res_r,
150       *h22_res_l, *h22_res_r;
151   WORD16 *c_f_l, *c_f_r, *dummy;
152 
153   WORD32 idx;
154   WORD32 residual_coding = pstr_mps_state->residual_coding;
155   WORD32 num_parameter_sets = pstr_mps_state->num_parameter_sets;
156   WORD32 num_parameter_bands = pstr_mps_state->num_parameter_bands;
157 
158   h11_l = pstr_mps_state->mps_scratch_mem_v;
159   h11_r =
160       h11_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h11_r), BYTE_ALIGN_8);
161   h12_l =
162       h11_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_l), BYTE_ALIGN_8);
163   h12_r =
164       h12_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_r), BYTE_ALIGN_8);
165   h21_l =
166       h12_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h21_l), BYTE_ALIGN_8);
167   h21_r =
168       h21_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h21_r), BYTE_ALIGN_8);
169   h22_l =
170       h21_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_l), BYTE_ALIGN_8);
171   h22_r =
172       h22_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_r), BYTE_ALIGN_8);
173   h12_res_l = h22_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_res_l),
174                                                     BYTE_ALIGN_8);
175   h12_res_r = h12_res_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12_res_r),
176                                                         BYTE_ALIGN_8);
177   h22_res_l = h12_res_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_res_l),
178                                                         BYTE_ALIGN_8);
179   h22_res_r = h22_res_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22_res_r),
180                                                         BYTE_ALIGN_8);
181 
182   c_f_l = (WORD16 *)pstr_mps_state->mps_scratch_mem_v +
183           IXHEAAC_GET_SIZE_ALIGNED_TYPE(PARAMETER_BANDSX24, sizeof(*c_f_l), BYTE_ALIGN_8);
184   c_f_r =
185       c_f_l + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*c_f_r), BYTE_ALIGN_8);
186   dummy =
187       c_f_r + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*dummy), BYTE_ALIGN_8);
188 
189   for (ps = 0; ps < num_parameter_sets; ps++) {
190     ixheaacd_param_2_umx_ps(pstr_mps_state, h11_l, h12_l, h21_l, h22_l, h12_res_l, h22_res_l,
191                             c_f_l, dummy, 0, ps, pstr_mps_state->res_bands[0]);
192     ixheaacd_param_2_umx_ps(pstr_mps_state, h11_r, h12_r, h21_r, h22_r, h12_res_r, h22_res_r,
193                             c_f_r, dummy, 1, ps, pstr_mps_state->res_bands[1]);
194 
195     for (pb = 0; pb < num_parameter_bands; pb++) {
196       m1_param->m1_param_real[0][0][ps][pb] = ONE_IN_Q15;
197       m1_param->m1_param_real[1][1][ps][pb] = ONE_IN_Q15;
198       m1_param->m1_param_real[2][2][ps][pb] = ONE_IN_Q15;
199       m1_param->m1_param_real[3][3][ps][pb] = ONE_IN_Q15;
200       m1_param->m1_param_real[4][4][ps][pb] = ONE_IN_Q15;
201       m1_param->m1_param_real[5][5][ps][pb] = ONE_IN_Q15;
202       m1_param->m1_param_real[6][4][ps][pb] = ONE_IN_Q15;
203       m1_param->m1_param_real[7][5][ps][pb] = ONE_IN_Q15;
204     }
205 
206     memcpy(m2_param->m2_decor_real[0][ps], h22_l, num_parameter_bands * sizeof(h22_l[0]));
207     memcpy(m2_param->m2_decor_real[1][ps], h12_l, num_parameter_bands * sizeof(h12_l[0]));
208     memcpy(m2_param->m2_decor_real[2][ps], h22_r, num_parameter_bands * sizeof(h22_r[0]));
209     memcpy(m2_param->m2_decor_real[3][ps], h12_r, num_parameter_bands * sizeof(h12_r[0]));
210 
211     for (pb = 0; pb < num_parameter_bands; pb++) {
212       idx = 0;
213 
214       m2_param->m2_resid_real[idx++][ps][pb] = ONE_IN_Q15;
215 
216       m2_param->m2_resid_real[idx++][ps][pb] = h21_l[pb];
217 
218       if (residual_coding) m2_param->m2_resid_real[idx++][ps][pb] = h22_res_l[pb];
219 
220       m2_param->m2_resid_real[idx++][ps][pb] = h11_l[pb];
221 
222       if (residual_coding) m2_param->m2_resid_real[idx++][ps][pb] = h12_res_l[pb];
223 
224       m2_param->m2_resid_real[idx++][ps][pb] = ONE_IN_Q15;
225 
226       m2_param->m2_resid_real[idx++][ps][pb] = h21_r[pb];
227 
228       if (residual_coding) m2_param->m2_resid_real[idx++][ps][pb] = h22_res_r[pb];
229 
230       m2_param->m2_resid_real[idx++][ps][pb] = h11_r[pb];
231 
232       if (residual_coding) m2_param->m2_resid_real[idx++][ps][pb] = h12_res_r[pb];
233 
234       m2_param->m2_resid_real[idx++][ps][pb] = ONE_IN_Q15;
235 
236       m2_param->m2_resid_real[idx++][ps][pb] = ONE_IN_Q15;
237     }
238   }
239   return;
240 }
241