/src/libxaac/decoder/ixheaacd_mps_m1m2_common.c
Line | Count | Source (jump to first uncovered line) |
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 "ixheaac_type_def.h" |
21 | | #include "ixheaacd_mps_struct_def.h" |
22 | | #include "ixheaacd_error_codes.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_bitdec.h" |
43 | | #include "ixheaacd_mps_calc_m1m2_tree_config.h" |
44 | | |
45 | 14.7k | VOID ixheaacd_buffer_m1(ia_heaac_mps_state_struct *pstr_mps_state) { |
46 | 14.7k | ia_mps_dec_m1_param_struct *m1_param = pstr_mps_state->array_struct->m1_param; |
47 | 14.7k | WORD32 pb, row, col; |
48 | | |
49 | 14.7k | ia_mps_persistent_mem *persistent_mem = &pstr_mps_state->mps_persistent_mem; |
50 | 14.7k | WORD32 *m1_param_real_prev = persistent_mem->m1_param_real_prev; |
51 | 14.7k | WORD32 *m1_param_imag_prev = persistent_mem->m1_param_imag_prev; |
52 | | |
53 | 14.7k | WORD32 *m1_param_real, *m1_param_imag; |
54 | | |
55 | 14.7k | WORD32 *p_m1_param_real, *p_m1_param_re; |
56 | | |
57 | 14.7k | WORD32 num_parameter_bands = pstr_mps_state->num_parameter_bands; |
58 | 14.7k | WORD32 num_v_channels = pstr_mps_state->num_v_channels; |
59 | 14.7k | WORD32 num_x_channels = pstr_mps_state->num_x_channels; |
60 | 14.7k | WORD32 m1_param_imag_present = pstr_mps_state->m1_param_imag_present; |
61 | | |
62 | 14.7k | WORD32 num_parameter_sets_prev; |
63 | | |
64 | 14.7k | pstr_mps_state->num_parameter_sets_prev = pstr_mps_state->num_parameter_sets; |
65 | 14.7k | num_parameter_sets_prev = pstr_mps_state->num_parameter_sets_prev; |
66 | | |
67 | 14.7k | if (m1_param_imag_present) { |
68 | 12.1k | WORD32 *p_m1_param_imag = &m1_param->m1_param_imag[0][0][0][0]; |
69 | 12.1k | p_m1_param_real = &m1_param->m1_param_real[0][0][0][0]; |
70 | 107k | for (row = 0; row < num_v_channels; row++) { |
71 | 95.6k | WORD32 *p_m1_param_im = p_m1_param_imag; |
72 | 95.6k | p_m1_param_re = p_m1_param_real; |
73 | | |
74 | 646k | for (col = 0; col < num_x_channels; col++) { |
75 | 550k | m1_param_real = p_m1_param_re + (num_parameter_sets_prev - 1) * MAX_PARAMETER_BANDS; |
76 | 550k | m1_param_imag = p_m1_param_im + (num_parameter_sets_prev - 1) * MAX_PARAMETER_BANDS; |
77 | | |
78 | 10.9M | for (pb = 0; pb < num_parameter_bands; pb++) { |
79 | 10.4M | *m1_param_real_prev++ = *m1_param_real++; |
80 | 10.4M | *m1_param_imag_prev++ = *m1_param_imag++; |
81 | 10.4M | } |
82 | 550k | p_m1_param_re += PBXPS; |
83 | 550k | p_m1_param_im += PBXPS; |
84 | 550k | } |
85 | 95.6k | p_m1_param_real += MAX_INPUT_CHANNELS_MPS * PBXPS; |
86 | 95.6k | p_m1_param_imag += MAX_INPUT_CHANNELS_MPS * PBXPS; |
87 | 95.6k | } |
88 | 12.1k | } else { |
89 | 2.64k | p_m1_param_real = &m1_param->m1_param_real[0][0][0][0]; |
90 | 19.9k | for (row = 0; row < num_v_channels; row++) { |
91 | 17.2k | p_m1_param_re = p_m1_param_real; |
92 | 71.3k | for (col = 0; col < num_x_channels; col++) { |
93 | 54.1k | m1_param_real = p_m1_param_re + (num_parameter_sets_prev - 1) * MAX_PARAMETER_BANDS; |
94 | 992k | for (pb = 0; pb < num_parameter_bands; pb++) *m1_param_real_prev++ = *m1_param_real++; |
95 | | |
96 | 54.1k | p_m1_param_re += PBXPS; |
97 | 54.1k | } |
98 | 17.2k | p_m1_param_real += MAX_INPUT_CHANNELS_MPS * PBXPS; |
99 | 17.2k | } |
100 | 2.64k | } |
101 | 14.7k | } |
102 | | |
103 | 14.7k | VOID ixheaacd_buffer_m2(ia_heaac_mps_state_struct *pstr_mps_state) { |
104 | 14.7k | WORD32 num_direct_signals = pstr_mps_state->num_direct_signals; |
105 | 14.7k | WORD32 pb, row, col, col_counter = num_direct_signals + pstr_mps_state->num_decor_signals; |
106 | | |
107 | 14.7k | ia_mps_persistent_mem *persistent_mem = &pstr_mps_state->mps_persistent_mem; |
108 | 14.7k | ia_mps_dec_m2_param_struct *m2_param = pstr_mps_state->aux_struct->m2_param; |
109 | | |
110 | 14.7k | WORD32 *m2_decor_real_prev = persistent_mem->m2_decor_real_prev; |
111 | 14.7k | WORD32 *m2_decor_imag_prev = persistent_mem->m2_decor_imag_prev; |
112 | | |
113 | 14.7k | WORD32 *m2_resid_real_prev = persistent_mem->m2_resid_real_prev; |
114 | 14.7k | WORD32 *m2_resid_imag_prev = persistent_mem->m2_resid_imag_prev; |
115 | | |
116 | 14.7k | WORD32 *m2_decor_real, *m2_decor_imag, *m2_resid_real, *m2_resid_imag; |
117 | 14.7k | WORD32 idx = -1; |
118 | | |
119 | 14.7k | WORD32 resid_col_counter; |
120 | | |
121 | 14.7k | WORD32 num_parameter_bands = pstr_mps_state->num_parameter_bands; |
122 | 14.7k | WORD32 num_output_channels = pstr_mps_state->num_output_channels; |
123 | 14.7k | WORD32 num_parameter_sets_prev = pstr_mps_state->num_parameter_sets_prev; |
124 | | |
125 | 14.7k | if (pstr_mps_state->residual_coding) |
126 | 188 | resid_col_counter = col_counter; |
127 | 14.5k | else |
128 | 14.5k | resid_col_counter = num_direct_signals; |
129 | | |
130 | 14.7k | if (pstr_mps_state->m2_param_imag_present) { |
131 | 0 | for (row = 0; row < num_output_channels; row++) { |
132 | 0 | for (col = num_direct_signals; col < col_counter; col++) { |
133 | 0 | if (pstr_mps_state->m2_param_present[row][col] & 1) { |
134 | 0 | idx++; |
135 | 0 | m2_decor_real = &m2_param->m2_decor_real[idx][num_parameter_sets_prev - 1][0]; |
136 | |
|
137 | 0 | for (pb = 0; pb < num_parameter_bands; pb++) *m2_decor_real_prev++ = *m2_decor_real++; |
138 | |
|
139 | 0 | m2_decor_imag = &m2_param->m2_decor_imag[idx][num_parameter_sets_prev - 1][0]; |
140 | |
|
141 | 0 | for (pb = 0; pb < num_parameter_bands; pb++) *m2_decor_imag_prev++ = *m2_decor_imag++; |
142 | 0 | } |
143 | 0 | } |
144 | 0 | } |
145 | |
|
146 | 0 | idx = -1; |
147 | 0 | for (row = 0; row < num_output_channels; row++) { |
148 | 0 | for (col = 0; col < resid_col_counter; col++) { |
149 | 0 | if (pstr_mps_state->m2_param_present[row][col] & 2) { |
150 | 0 | idx++; |
151 | 0 | m2_resid_real = &m2_param->m2_resid_real[idx][num_parameter_sets_prev - 1][0]; |
152 | |
|
153 | 0 | for (pb = 0; pb < num_parameter_bands; pb++) *m2_resid_real_prev++ = *m2_resid_real++; |
154 | 0 | m2_resid_imag = &m2_param->m2_resid_imag[idx][num_parameter_sets_prev - 1][0]; |
155 | 0 | for (pb = 0; pb < num_parameter_bands; pb++) *m2_resid_imag_prev++ = *m2_resid_imag++; |
156 | 0 | } |
157 | 0 | } |
158 | 0 | } |
159 | 14.7k | } else { |
160 | 129k | for (row = 0; row < num_output_channels; row++) { |
161 | 378k | for (col = num_direct_signals; col < col_counter; col++) { |
162 | 264k | if (pstr_mps_state->m2_param_present[row][col] & 1) { |
163 | 76.6k | idx++; |
164 | 76.6k | m2_decor_real = &m2_param->m2_decor_real[idx][num_parameter_sets_prev - 1][0]; |
165 | | |
166 | 1.39M | for (pb = 0; pb < num_parameter_bands; pb++) *m2_decor_real_prev++ = *m2_decor_real++; |
167 | 76.6k | } |
168 | 264k | } |
169 | 114k | } |
170 | | |
171 | 14.7k | idx = -1; |
172 | 129k | for (row = 0; row < num_output_channels; row++) { |
173 | 735k | for (col = 0; col < resid_col_counter; col++) { |
174 | 621k | if (pstr_mps_state->m2_param_present[row][col] & 2) { |
175 | 115k | idx++; |
176 | 115k | m2_resid_real = &m2_param->m2_resid_real[idx][num_parameter_sets_prev - 1][0]; |
177 | | |
178 | 2.22M | for (pb = 0; pb < num_parameter_bands; pb++) *m2_resid_real_prev++ = *m2_resid_real++; |
179 | 115k | } |
180 | 621k | } |
181 | 114k | } |
182 | 14.7k | } |
183 | 14.7k | } |
184 | | |
185 | 1.45k | static VOID ixheaacd_update_alpha(ia_heaac_mps_state_struct *pstr_mps_state) { |
186 | 1.45k | WORD32 alpha; |
187 | | |
188 | 1.45k | WORD32 *arbdmx_alpha_prev = pstr_mps_state->mps_persistent_mem.arbdmx_alpha_prev; |
189 | 1.45k | ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct; |
190 | 1.45k | WORD32 *arbdmx_alpha = p_aux_struct->arbdmx_alpha; |
191 | | |
192 | 1.45k | WORD32 n_ch_in = pstr_mps_state->num_input_channels; |
193 | 1.45k | WORD32 ch; |
194 | | |
195 | 3.55k | for (ch = 0; ch < n_ch_in; ch++) { |
196 | 2.10k | *arbdmx_alpha_prev++ = arbdmx_alpha[ch]; |
197 | | |
198 | 2.10k | if (pstr_mps_state->arbitrary_downmix == 2) { |
199 | 158 | alpha = arbdmx_alpha[ch]; |
200 | | |
201 | 158 | if (p_aux_struct->arbdmx_residual_abs[ch]) { |
202 | 76 | alpha -= POINT_THREE_THREE_Q15; |
203 | | |
204 | 76 | if (alpha < 0) alpha = 0; |
205 | 82 | } else { |
206 | 82 | alpha += POINT_THREE_THREE_Q15; |
207 | | |
208 | 82 | if (alpha > ONE_IN_Q15) alpha = ONE_IN_Q15; |
209 | 82 | } |
210 | 1.94k | } else { |
211 | 1.94k | alpha = ONE_IN_Q15; |
212 | 1.94k | } |
213 | | |
214 | 2.10k | arbdmx_alpha[ch] = alpha; |
215 | 2.10k | } |
216 | 1.45k | } |
217 | | |
218 | 14.7k | VOID ixheaacd_calc_m1m2(ia_heaac_mps_state_struct *pstr_mps_state) { |
219 | 14.7k | WORD32 up_mix_type = pstr_mps_state->up_mix_type; |
220 | 14.7k | WORD32 binaural_quality = pstr_mps_state->binaural_quality; |
221 | | |
222 | 14.7k | if (pstr_mps_state->arbitrary_downmix != 0) { |
223 | 1.45k | ixheaacd_update_alpha(pstr_mps_state); |
224 | 1.45k | } |
225 | | |
226 | 14.7k | switch (pstr_mps_state->tree_config) { |
227 | 348 | case TREE_5151: { |
228 | 348 | if (up_mix_type == 3) { |
229 | 0 | ixheaacd_calc_m1m2_51s1(pstr_mps_state); |
230 | 348 | } else { |
231 | 348 | ixheaacd_calc_m1m2_5151(pstr_mps_state); |
232 | 348 | } |
233 | 348 | } break; |
234 | 692 | case TREE_5152: { |
235 | 692 | if (up_mix_type == 3) { |
236 | 0 | ixheaacd_calc_m1m2_51s2(pstr_mps_state); |
237 | 692 | } else { |
238 | 692 | ixheaacd_calc_m1m2_5152(pstr_mps_state); |
239 | 692 | } |
240 | 692 | } break; |
241 | 795 | case TREE_525: |
242 | 795 | if (up_mix_type == 1) { |
243 | 0 | ixheaacd_calc_m1m2_emm(pstr_mps_state); |
244 | 795 | } else if (up_mix_type == 2) { |
245 | 0 | if (binaural_quality == 1) { |
246 | 0 | ixheaacd_calc_m1m2_5227(pstr_mps_state); |
247 | 0 | } |
248 | 795 | } else { |
249 | 795 | ixheaacd_calc_m1m2_5251(pstr_mps_state); |
250 | 795 | } |
251 | 795 | break; |
252 | 713 | case TREE_7271: |
253 | 713 | if (up_mix_type == 0) { |
254 | 713 | ixheaacd_calc_m1m2_7271(pstr_mps_state); |
255 | 713 | } else if (up_mix_type == 2) { |
256 | 0 | if (binaural_quality == 1) { |
257 | 0 | ixheaacd_calc_m1m2_5227(pstr_mps_state); |
258 | 0 | } |
259 | 0 | } |
260 | 713 | break; |
261 | 262 | case TREE_7272: |
262 | 262 | if (up_mix_type == 0) { |
263 | 262 | ixheaacd_calc_m1m2_7272(pstr_mps_state); |
264 | 262 | } else if (up_mix_type == 2) { |
265 | 0 | if (binaural_quality == 1) { |
266 | 0 | ixheaacd_calc_m1m2_5227(pstr_mps_state); |
267 | 0 | } |
268 | 0 | } |
269 | 262 | break; |
270 | 105 | case TREE_7571: |
271 | 105 | ixheaacd_calc_m1m2_7571(pstr_mps_state); |
272 | 105 | break; |
273 | 11.8k | case TREE_7572: |
274 | 11.8k | ixheaacd_calc_m1m2_7572(pstr_mps_state); |
275 | 11.8k | break; |
276 | 0 | default: |
277 | 0 | break; |
278 | 14.7k | }; |
279 | | |
280 | 14.7k | return; |
281 | 14.7k | } |