/src/libxaac/decoder/ixheaacd_mps_calc_m1m2_common.c
Line | Count | Source |
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_mps_res_rom.h" |
23 | | #include "ixheaacd_mps_aac_struct.h" |
24 | | #include "ixheaac_constants.h" |
25 | | #include "ixheaac_basic_ops32.h" |
26 | | #include "ixheaac_basic_ops40.h" |
27 | | #include "ixheaacd_bitbuffer.h" |
28 | | #include "ixheaacd_common_rom.h" |
29 | | #include "ixheaacd_sbrdecsettings.h" |
30 | | #include "ixheaacd_sbr_scale.h" |
31 | | #include "ixheaacd_env_extr_part.h" |
32 | | #include "ixheaacd_sbr_rom.h" |
33 | | #include "ixheaacd_hybrid.h" |
34 | | #include "ixheaacd_ps_dec.h" |
35 | | #include "ixheaac_error_standards.h" |
36 | | #include "ixheaacd_mps_polyphase.h" |
37 | | #include "ixheaacd_config.h" |
38 | | #include "ixheaacd_qmf_dec.h" |
39 | | #include "ixheaacd_mps_dec.h" |
40 | | #include "ixheaacd_mps_macro_def.h" |
41 | | #include "ixheaacd_mps_basic_op.h" |
42 | | |
43 | | VOID ixheaacd_get_matrix_inversion_weights( |
44 | | WORD32 iid_lf_ls_idx, WORD32 iid_rf_rs_idx, WORD32 prediction_mode, WORD32 c1, WORD32 c2, |
45 | 23.8k | WORD32 *weight1, WORD32 *weight2, ia_mps_dec_mps_tables_struct *ia_mps_dec_mps_table_ptr) { |
46 | 23.8k | WORD32 temp, temp_1, temp_2, temp_one; |
47 | 23.8k | WORD16 qtemp; |
48 | 23.8k | WORD32 w1 = ia_mps_dec_mps_table_ptr->m1_m2_table_ptr->cld_tab_2[iid_lf_ls_idx + 15]; |
49 | 23.8k | WORD32 w2 = ia_mps_dec_mps_table_ptr->m1_m2_table_ptr->cld_tab_2[iid_rf_rs_idx + 15]; |
50 | | |
51 | 23.8k | if (prediction_mode == 1) { |
52 | 13.7k | if (abs(c1) >= ONE_IN_Q15) { |
53 | 7.26k | c1 = ONE_IN_Q15; |
54 | 7.26k | } else if ((c1 < MINUS_ONE_IN_Q14) && (c1 > MINUS_ONE_IN_Q15)) { |
55 | 0 | c1 = MINUS_ONE_IN_Q15 - (c1 << 1); |
56 | 1.55k | } else { |
57 | 1.55k | qtemp = 15; |
58 | 1.55k | temp = ixheaacd_mps_mult32(TWO_BY_THREE_Q15, c1, &qtemp, 15); |
59 | 1.55k | temp = ixheaacd_mps_convert_to_qn(temp, qtemp, 15); |
60 | 1.55k | c1 = ONE_BY_THREE_Q15 + temp; |
61 | 1.55k | } |
62 | | |
63 | 13.8k | if (abs(c2) >= ONE_IN_Q15) { |
64 | 7.75k | c2 = ONE_IN_Q15; |
65 | 7.75k | } else if ((c2 < MINUS_ONE_IN_Q14) && (c2 > MINUS_ONE_IN_Q15)) { |
66 | 0 | c2 = MINUS_ONE_IN_Q15 - (c2 << 1); |
67 | 1.06k | } else { |
68 | 1.06k | qtemp = 15; |
69 | 1.06k | temp = ixheaacd_mps_mult32(TWO_BY_THREE_Q15, c2, &qtemp, 15); |
70 | 1.06k | temp = ixheaacd_mps_convert_to_qn(temp, qtemp, 15); |
71 | 1.06k | qtemp = 15; |
72 | 1.06k | temp = ixheaacd_mps_add32(temp, ONE_BY_THREE_Q15, &qtemp, 15); |
73 | 1.06k | c2 = ixheaacd_mps_convert_to_qn(temp, qtemp, 15); |
74 | 1.06k | } |
75 | 14.9k | } else { |
76 | 14.9k | WORD32 c1p, c2p; |
77 | 14.9k | WORD64 acc; |
78 | 14.9k | const WORD32 *cld_tab_3 = ia_mps_dec_mps_table_ptr->m1_m2_table_ptr->cld_tab_3; |
79 | 14.9k | const WORD32 *sqrt_tab = ia_mps_dec_mps_table_ptr->common_table_ptr->sqrt_tab; |
80 | | |
81 | 14.9k | c1p = cld_tab_3[c1 + 15]; |
82 | 14.9k | c2p = cld_tab_3[c2 + 15]; |
83 | | |
84 | 14.9k | acc = (WORD64)((WORD64)c1p * (WORD64)c2p); |
85 | 14.9k | acc >>= 15; |
86 | 14.9k | temp = (WORD32)acc; |
87 | 14.9k | temp_1 = (ONE_IN_Q15 + c2p) << 1; |
88 | 14.9k | acc += temp_1; |
89 | 14.9k | temp_2 = (WORD32)acc; |
90 | | |
91 | 14.9k | temp = ixheaacd_mps_div_32(temp, temp_2, &qtemp); |
92 | | |
93 | 14.9k | c1 = ixheaacd_mps_sqrt(temp, &qtemp, sqrt_tab); |
94 | 14.9k | c1 = ixheaacd_mps_convert_to_qn(c1, qtemp, 15); |
95 | | |
96 | 14.9k | temp_2 = ixheaac_add32_sat(c1p, temp_1); |
97 | 14.9k | temp = ixheaacd_mps_div_32(c1p, temp_2, &qtemp); |
98 | 14.9k | c2 = ixheaacd_mps_sqrt(temp, &qtemp, sqrt_tab); |
99 | 14.9k | c2 = ixheaacd_mps_convert_to_qn(c2, qtemp, 15); |
100 | 14.9k | } |
101 | 23.8k | temp_one = ONE_IN_Q15; |
102 | 23.8k | if (ixheaac_norm32(w1) == 0) { |
103 | 463 | temp_one = ONE_IN_Q14; |
104 | 463 | w1 = w1 >> 1; |
105 | 463 | } |
106 | 23.8k | temp_1 = temp_one + w1; |
107 | 23.8k | temp_2 = ixheaacd_mps_mult32_shr_15(c1, w1); |
108 | 23.8k | *weight1 = ixheaacd_mps_div32_in_q15(temp_2, temp_1); |
109 | | |
110 | 23.8k | if (ixheaac_norm32(w2) == 0) { |
111 | 980 | temp_one = ONE_IN_Q14; |
112 | 980 | w2 = w2 >> 1; |
113 | 980 | } |
114 | 23.8k | temp_1 = temp_one + w2; |
115 | 23.8k | temp_2 = ixheaacd_mps_mult32_shr_15(c2, w2); |
116 | 23.8k | *weight2 = ixheaacd_mps_div32_in_q15(temp_2, temp_1); |
117 | 23.8k | } |
118 | | |
119 | | VOID ixheaacd_invert_matrix(WORD32 weight1, WORD32 weight2, WORD32 h_real[][2], |
120 | | WORD32 h_imag[][2], |
121 | 23.8k | const ia_mps_dec_common_tables_struct *common_tab_ptr) { |
122 | 23.8k | WORD32 h11_f_real, h12_f_real, h21_f_real, h22_f_real; |
123 | 23.8k | WORD32 h11_f_imag, h12_f_imag, h21_f_imag, h22_f_imag; |
124 | | |
125 | 23.8k | WORD32 inv_norm_real, inv_norm_imag, inv_norm; |
126 | | |
127 | 23.8k | WORD32 len1, len2; |
128 | 23.8k | WORD16 q_len1 = 0, q_len2 = 0; |
129 | | |
130 | 23.8k | WORD64 acc1, acc2; |
131 | | |
132 | 23.8k | len1 = ixheaacd_mps_sqrt((ONE_IN_Q15 - (weight1 << 1) + ((weight1 * weight1) >> 14)), &q_len1, |
133 | 23.8k | common_tab_ptr->sqrt_tab); |
134 | | |
135 | 23.8k | len2 = ixheaacd_mps_sqrt((ONE_IN_Q15 - (weight2 << 1) + ((weight2 * weight2) >> 14)), &q_len2, |
136 | 23.8k | common_tab_ptr->sqrt_tab); |
137 | | |
138 | 23.8k | len1 = ixheaacd_mps_convert_to_qn(len1, q_len1, 15); |
139 | 23.8k | len2 = ixheaacd_mps_convert_to_qn(len2, q_len2, 15); |
140 | | |
141 | 23.8k | h11_f_real = ixheaacd_mps_div32_in_q15((ONE_IN_Q15 - weight1), len1); |
142 | | |
143 | 23.8k | h11_f_imag = ixheaacd_mps_div32_in_q15(weight1, len1); |
144 | | |
145 | 23.8k | h22_f_imag = -(ixheaacd_mps_div32_in_q15(weight2, len2)); |
146 | | |
147 | 23.8k | h12_f_real = 0; |
148 | | |
149 | 23.8k | h12_f_imag = ixheaacd_mps_mult32_shr_15(h22_f_imag, ONE_BY_SQRT_3_Q15); |
150 | | |
151 | 23.8k | h21_f_real = 0; |
152 | | |
153 | 23.8k | h21_f_imag = ixheaacd_mps_mult32_shr_15(h11_f_imag, -(ONE_BY_SQRT_3_Q15)); |
154 | | |
155 | 23.8k | h22_f_real = ixheaacd_mps_div32_in_q15((ONE_IN_Q15 - weight2), len2); |
156 | | |
157 | 23.8k | acc1 = |
158 | 23.8k | (WORD64)((WORD64)h11_f_real * (WORD64)h22_f_real - (WORD64)h11_f_imag * (WORD64)h22_f_imag); |
159 | 23.8k | acc1 >>= 15; |
160 | | |
161 | 23.8k | acc2 = |
162 | 23.8k | (WORD64)((WORD64)h12_f_real * (WORD64)h21_f_real - (WORD64)h12_f_imag * (WORD64)h21_f_imag); |
163 | 23.8k | acc2 >>= 15; |
164 | 23.8k | inv_norm_real = (WORD32)(acc1 - acc2); |
165 | | |
166 | 23.8k | acc1 = |
167 | 23.8k | (WORD64)((WORD64)h11_f_real * (WORD64)h22_f_imag + (WORD64)h11_f_imag * (WORD64)h22_f_real); |
168 | 23.8k | acc1 >>= 15; |
169 | | |
170 | 23.8k | acc2 = |
171 | 23.8k | (WORD64)((WORD64)h12_f_real * (WORD64)h21_f_imag + (WORD64)h12_f_imag * (WORD64)h21_f_real); |
172 | 23.8k | acc2 >>= 15; |
173 | 23.8k | inv_norm_imag = (WORD32)(acc1 + acc2); |
174 | | |
175 | 23.8k | acc1 = (WORD64)((WORD64)inv_norm_real * (WORD64)inv_norm_real + |
176 | 23.8k | (WORD64)inv_norm_imag * (WORD64)inv_norm_imag); |
177 | 23.8k | acc1 >>= 15; |
178 | 23.8k | inv_norm = (WORD32)acc1; |
179 | | |
180 | 23.8k | inv_norm_real = ixheaacd_mps_div32_in_q15(inv_norm_real, inv_norm); |
181 | 23.8k | inv_norm_imag = -(ixheaacd_mps_div32_in_q15(inv_norm_imag, inv_norm)); |
182 | | |
183 | 23.8k | acc1 = (WORD64)((WORD64)h22_f_real * (WORD64)inv_norm_real - |
184 | 23.8k | (WORD64)h22_f_imag * (WORD64)inv_norm_imag); |
185 | 23.8k | acc1 >>= 15; |
186 | 23.8k | h_real[0][0] = (WORD32)acc1; |
187 | | |
188 | 23.8k | acc1 = (WORD64)((WORD64)h22_f_real * (WORD64)inv_norm_imag + |
189 | 23.8k | (WORD64)h22_f_imag * (WORD64)inv_norm_real); |
190 | 23.8k | acc1 >>= 15; |
191 | 23.8k | h_imag[0][0] = (WORD32)acc1; |
192 | | |
193 | 23.8k | acc1 = (WORD64)((WORD64)h12_f_imag * (WORD64)inv_norm_imag - |
194 | 23.8k | (WORD64)h12_f_real * (WORD64)inv_norm_real); |
195 | 23.8k | acc1 >>= 15; |
196 | 23.8k | h_real[0][1] = (WORD32)acc1; |
197 | | |
198 | 23.8k | acc1 = (WORD64)((WORD64)h12_f_real * (WORD64)inv_norm_imag + |
199 | 23.8k | (WORD64)h12_f_imag * (WORD64)inv_norm_real); |
200 | 23.8k | acc1 = -(acc1 >> 15); |
201 | 23.8k | h_imag[0][1] = (WORD32)acc1; |
202 | | |
203 | 23.8k | acc1 = (WORD64)((WORD64)h21_f_imag * (WORD64)inv_norm_imag - |
204 | 23.8k | (WORD64)h21_f_real * (WORD64)inv_norm_real); |
205 | 23.8k | acc1 >>= 15; |
206 | 23.8k | h_real[1][0] = (WORD32)acc1; |
207 | | |
208 | 23.8k | acc1 = (WORD64)((WORD64)h21_f_real * (WORD64)inv_norm_imag + |
209 | 23.8k | (WORD64)h21_f_imag * (WORD64)inv_norm_real); |
210 | 23.8k | acc1 = -(acc1 >> 15); |
211 | 23.8k | h_imag[1][0] = (WORD32)acc1; |
212 | | |
213 | 23.8k | acc1 = (WORD64)((WORD64)h11_f_real * (WORD64)inv_norm_real - |
214 | 23.8k | (WORD64)h11_f_imag * (WORD64)inv_norm_imag); |
215 | 23.8k | acc1 >>= 15; |
216 | 23.8k | h_real[1][1] = (WORD32)acc1; |
217 | | |
218 | 23.8k | acc1 = (WORD64)((WORD64)h11_f_real * (WORD64)inv_norm_imag + |
219 | 23.8k | (WORD64)h11_f_imag * (WORD64)inv_norm_real); |
220 | 23.8k | acc1 >>= 15; |
221 | 23.8k | h_imag[1][1] = (WORD32)acc1; |
222 | 23.8k | } |
223 | | |
224 | 14.7k | WORD32 ixheaacd_dequant_icc_band(WORD32 iccband, WORD32 cldband) { |
225 | 14.7k | if (iccband < 6) { |
226 | 12.0k | return iccband; |
227 | 12.0k | } |
228 | 2.73k | if (iccband == 6) { |
229 | 908 | if (cldband > 9 && cldband < 21) { |
230 | 332 | switch (cldband) { |
231 | 34 | case 10: |
232 | 65 | case 20: |
233 | 65 | return 10; |
234 | 23 | case 11: |
235 | 50 | case 19: |
236 | 50 | return 11; |
237 | 21 | case 12: |
238 | 41 | case 18: |
239 | 41 | return 12; |
240 | 15 | case 13: |
241 | 43 | case 17: |
242 | 43 | return 13; |
243 | 23 | case 14: |
244 | 46 | case 16: |
245 | 46 | return 14; |
246 | 87 | case 15: |
247 | 87 | return 15; |
248 | 0 | default: |
249 | 0 | return iccband; |
250 | 332 | } |
251 | 576 | } else { |
252 | 576 | return iccband; |
253 | 576 | } |
254 | 908 | } |
255 | 1.82k | if (7 == iccband) { |
256 | 1.82k | if (cldband > 7 && cldband < 23) { |
257 | 885 | switch (cldband) { |
258 | 44 | case 8: |
259 | 133 | case 22: |
260 | 133 | return 8; |
261 | 20 | case 9: |
262 | 85 | case 21: |
263 | 85 | return 9; |
264 | 75 | case 10: |
265 | 256 | case 20: |
266 | 256 | return 10; |
267 | 21 | case 11: |
268 | 71 | case 19: |
269 | 71 | return 11; |
270 | 26 | case 12: |
271 | 75 | case 18: |
272 | 75 | return 12; |
273 | 27 | case 13: |
274 | 74 | case 17: |
275 | 74 | return 13; |
276 | 31 | case 14: |
277 | 47 | case 16: |
278 | 47 | return 14; |
279 | 144 | case 15: |
280 | 144 | return 15; |
281 | 0 | default: |
282 | 0 | return iccband; |
283 | 885 | } |
284 | 941 | } else { |
285 | 941 | return iccband; |
286 | 941 | } |
287 | 1.82k | } else { |
288 | 0 | return iccband; |
289 | 0 | } |
290 | 1.82k | } |
291 | | |
292 | 2.15M | WORD32 ixheaacd_dequant_cld_band(WORD32 cld) { |
293 | 2.15M | switch (cld) { |
294 | 41.4k | case -4915200: |
295 | 41.4k | return 0; |
296 | 1.05k | case -1474560: |
297 | 1.05k | return 1; |
298 | 774 | case -1310720: |
299 | 774 | return 2; |
300 | 2.20k | case -1146880: |
301 | 2.20k | return 3; |
302 | 1.12k | case -983040: |
303 | 1.12k | return 4; |
304 | 5.22k | case -819200: |
305 | 5.22k | return 5; |
306 | 1.40k | case -720896: |
307 | 1.40k | return 6; |
308 | 3.70k | case -622592: |
309 | 3.70k | return 7; |
310 | 1.35k | case -524288: |
311 | 1.35k | return 8; |
312 | 3.98k | case -425984: |
313 | 3.98k | return 9; |
314 | 19.2k | case -327680: |
315 | 19.2k | return 10; |
316 | 128k | case -262144: |
317 | 128k | return 11; |
318 | 23.8k | case -196608: |
319 | 23.8k | return 12; |
320 | 5.23k | case -131072: |
321 | 5.23k | return 13; |
322 | 12.2k | case -65536: |
323 | 12.2k | return 14; |
324 | 255k | case 0: |
325 | 255k | return 15; |
326 | 11.5k | case 65536: |
327 | 11.5k | return 16; |
328 | 32.6k | case 131072: |
329 | 32.6k | return 17; |
330 | 14.5k | case 196608: |
331 | 14.5k | return 18; |
332 | 6.53k | case 262144: |
333 | 6.53k | return 19; |
334 | 46.6k | case 327680: |
335 | 46.6k | return 20; |
336 | 13.8k | case 425984: |
337 | 13.8k | return 21; |
338 | 7.71k | case 524288: |
339 | 7.71k | return 22; |
340 | 2.99k | case 622592: |
341 | 2.99k | return 23; |
342 | 2.90k | case 720896: |
343 | 2.90k | return 24; |
344 | 4.17k | case 819200: |
345 | 4.17k | return 25; |
346 | 1.73k | case 983040: |
347 | 1.73k | return 26; |
348 | 5.12k | case 1146880: |
349 | 5.12k | return 27; |
350 | 1.78k | case 1310720: |
351 | 1.78k | return 28; |
352 | 1.67k | case 1474560: |
353 | 1.67k | return 29; |
354 | 1.49M | case 4915200: |
355 | 1.49M | return 30; |
356 | 0 | default: |
357 | 0 | return 0; |
358 | 2.15M | } |
359 | 2.15M | } |
360 | | |
361 | | VOID ixheaacd_param_2_umx_ps_core_tables( |
362 | | WORD32 cld[MAX_PARAMETER_BANDS], WORD32 icc[MAX_PARAMETER_BANDS], WORD32 num_ott_bands, |
363 | | WORD32 res_bands, WORD32 h11[MAX_PARAMETER_BANDS], WORD32 h12[MAX_PARAMETER_BANDS], |
364 | | WORD32 h21[MAX_PARAMETER_BANDS], WORD32 h22[MAX_PARAMETER_BANDS], |
365 | | WORD32 h12_res[MAX_PARAMETER_BANDS], WORD32 h22_res[MAX_PARAMETER_BANDS], |
366 | | WORD16 c_l[MAX_PARAMETER_BANDS], WORD16 c_r[MAX_PARAMETER_BANDS], |
367 | 65.9k | const ia_mps_dec_m1_m2_tables_struct *ixheaacd_mps_dec_m1_m2_tables) { |
368 | 65.9k | WORD32 band; |
369 | 65.9k | WORD32 quant_band_cld, quant_band_icc; |
370 | | |
371 | 1.14M | for (band = 0; band < num_ott_bands; band++) { |
372 | 1.07M | quant_band_cld = ixheaacd_dequant_cld_band(cld[band]); |
373 | | |
374 | 1.07M | c_l[band] = (WORD16)ixheaacd_mps_dec_m1_m2_tables->c_l_table[quant_band_cld]; |
375 | 1.07M | c_r[band] = (WORD16)ixheaacd_mps_dec_m1_m2_tables->c_l_table[30 - quant_band_cld]; |
376 | 1.07M | } |
377 | | |
378 | 1.14M | for (band = 0; band < num_ott_bands; band++) { |
379 | 1.07M | if (band < res_bands) { |
380 | 14.7k | quant_band_cld = ixheaacd_dequant_cld_band(cld[band]); |
381 | 14.7k | quant_band_icc = ixheaacd_dequant_icc_band(icc[band], quant_band_cld); |
382 | | |
383 | 14.7k | h11[band] = ixheaacd_mps_dec_m1_m2_tables->cos_table[quant_band_icc][quant_band_cld]; |
384 | 14.7k | h11[band] = ixheaacd_mps_mult32_shr_15(h11[band], c_l[band]); |
385 | 14.7k | h21[band] = ixheaacd_mps_dec_m1_m2_tables->cos_table[quant_band_icc][30 - quant_band_cld]; |
386 | 14.7k | h21[band] = ixheaacd_mps_mult32_shr_15(h21[band], c_r[band]); |
387 | | |
388 | 14.7k | h12[band] = 0; |
389 | 14.7k | h22[band] = 0; |
390 | 14.7k | h12_res[band] = ONE_IN_Q15; |
391 | 14.7k | h22_res[band] = MINUS_ONE_IN_Q15; |
392 | 1.06M | } else { |
393 | 1.06M | quant_band_cld = ixheaacd_dequant_cld_band(cld[band]); |
394 | 1.06M | if (quant_band_cld < 0 || quant_band_cld >= 31) { |
395 | 0 | quant_band_cld = 30; |
396 | 0 | } |
397 | | |
398 | 1.06M | quant_band_icc = icc[band]; |
399 | | |
400 | 1.06M | if (quant_band_icc < 0 || quant_band_icc >= 8) { |
401 | 0 | quant_band_icc = 7; |
402 | 0 | } |
403 | 1.06M | h11[band] = ixheaacd_mps_dec_m1_m2_tables->cos_table[quant_band_icc][quant_band_cld]; |
404 | 1.06M | h11[band] = ixheaacd_mps_mult32_shr_15(h11[band], c_l[band]); |
405 | 1.06M | h21[band] = ixheaacd_mps_dec_m1_m2_tables->cos_table[quant_band_icc][30 - quant_band_cld]; |
406 | 1.06M | h21[band] = ixheaacd_mps_mult32_shr_15(h21[band], c_r[band]); |
407 | 1.06M | h12[band] = ixheaacd_mps_dec_m1_m2_tables->sin_table[quant_band_icc][quant_band_cld]; |
408 | 1.06M | h12[band] = ixheaacd_mps_mult32_shr_15(h12[band], c_l[band]); |
409 | 1.06M | h22[band] = -ixheaacd_mps_dec_m1_m2_tables->sin_table[quant_band_icc][30 - quant_band_cld]; |
410 | 1.06M | h22[band] = ixheaacd_mps_mult32_shr_15(h22[band], c_r[band]); |
411 | | |
412 | 1.06M | h12_res[band] = 0; |
413 | 1.06M | h22_res[band] = 0; |
414 | 1.06M | } |
415 | 1.07M | } |
416 | 65.9k | return; |
417 | 65.9k | } |
418 | | |
419 | | VOID ixheaacd_param_2_umx_ps(ia_heaac_mps_state_struct *pstr_mps_state, WORD32 *h11, WORD32 *h12, |
420 | | WORD32 *h21, WORD32 *h22, WORD32 *h12_res, WORD32 *h22_res, |
421 | | WORD16 *c_l, WORD16 *c_r, WORD32 ott_box_indx, |
422 | 65.9k | WORD32 parameter_set_indx, WORD32 res_bands) { |
423 | 65.9k | WORD32 band; |
424 | 65.9k | ia_mps_dec_spatial_bs_frame_struct *p_cur_bs = pstr_mps_state->bs_frame; |
425 | 65.9k | ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct; |
426 | 65.9k | WORD32 num_parameter_bands = pstr_mps_state->num_parameter_bands; |
427 | | |
428 | 65.9k | ixheaacd_param_2_umx_ps_core_tables(p_aux_struct->ott_cld[ott_box_indx][parameter_set_indx], |
429 | 65.9k | p_cur_bs->ott_icc_idx[ott_box_indx][parameter_set_indx], |
430 | 65.9k | p_aux_struct->num_ott_bands[ott_box_indx], res_bands, h11, |
431 | 65.9k | h12, h21, h22, h12_res, h22_res, c_l, c_r, |
432 | 65.9k | pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr); |
433 | | |
434 | 65.9k | for (band = p_aux_struct->num_ott_bands[ott_box_indx]; band < num_parameter_bands; band++) { |
435 | 0 | h11[band] = h21[band] = h12[band] = h22[band] = h12_res[band] = h22_res[band] = 0; |
436 | 0 | } |
437 | 65.9k | return; |
438 | 65.9k | } |
439 | | |
440 | 46.7k | static WORD32 ixheaacd_dequant_one_by_icc(WORD32 icc) { |
441 | 46.7k | switch (icc) { |
442 | 24.7k | case 32768: |
443 | 24.7k | return 32768; |
444 | 708 | case 30704: |
445 | 708 | return 34971; |
446 | 2.23k | case 27564: |
447 | 2.23k | return 38955; |
448 | 6.85k | case 19691: |
449 | 6.85k | return 54530; |
450 | 2.07k | case 12047: |
451 | 2.07k | return 89131; |
452 | 7.09k | case 0: |
453 | 7.09k | return 0; |
454 | 1.25k | case -19300: |
455 | 1.25k | return -55633; |
456 | 1.82k | case -32440: |
457 | 1.82k | return -33099; |
458 | 0 | default: |
459 | 0 | return 0; |
460 | 46.7k | } |
461 | 46.7k | } |
462 | | |
463 | 158k | static WORD16 ixheaacd_map_cld_index(WORD32 cld_val) { |
464 | 158k | WORD32 temp = cld_val; |
465 | 158k | WORD16 idx = 0; |
466 | 158k | if (cld_val == 0) { |
467 | 62.4k | return 15; |
468 | 95.5k | } else { |
469 | 95.5k | if (cld_val < 0) { |
470 | 28.8k | temp = -cld_val; |
471 | 28.8k | } |
472 | 95.5k | switch (temp) { |
473 | 70.5k | case 150: |
474 | 70.5k | idx = 15; |
475 | 70.5k | break; |
476 | 1.49k | case 45: |
477 | 1.49k | idx = 14; |
478 | 1.49k | break; |
479 | 930 | case 40: |
480 | 930 | idx = 13; |
481 | 930 | break; |
482 | 3.49k | case 35: |
483 | 3.49k | idx = 12; |
484 | 3.49k | break; |
485 | 1.04k | case 30: |
486 | 1.04k | idx = 11; |
487 | 1.04k | break; |
488 | 2.29k | case 25: |
489 | 2.29k | idx = 10; |
490 | 2.29k | break; |
491 | 711 | case 22: |
492 | 711 | idx = 9; |
493 | 711 | break; |
494 | 1.58k | case 19: |
495 | 1.58k | idx = 8; |
496 | 1.58k | break; |
497 | 846 | case 16: |
498 | 846 | idx = 7; |
499 | 846 | break; |
500 | 2.46k | case 13: |
501 | 2.46k | idx = 6; |
502 | 2.46k | break; |
503 | 1.45k | case 10: |
504 | 1.45k | idx = 5; |
505 | 1.45k | break; |
506 | 1.33k | case 8: |
507 | 1.33k | idx = 4; |
508 | 1.33k | break; |
509 | 1.09k | case 6: |
510 | 1.09k | idx = 3; |
511 | 1.09k | break; |
512 | 1.80k | case 4: |
513 | 1.80k | idx = 2; |
514 | 1.80k | break; |
515 | 4.41k | case 2: |
516 | 4.41k | idx = 1; |
517 | 4.41k | break; |
518 | 0 | default: |
519 | 0 | idx = 0; |
520 | 0 | break; |
521 | 95.5k | } |
522 | 95.5k | } |
523 | | |
524 | 95.5k | return (cld_val >= 0) ? idx + 15 : 15 - idx; |
525 | 158k | } |
526 | | |
527 | | VOID ixheaacd_calculate_ttt(ia_heaac_mps_state_struct *pstr_mps_state, WORD32 ps, WORD32 pb, |
528 | 126k | WORD32 ttt_mode, WORD32 m_ttt[][3]) { |
529 | 126k | ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct; |
530 | 126k | WORD32 col; |
531 | | |
532 | 126k | if (ttt_mode < 2) { |
533 | 47.2k | m_ttt[0][0] = (p_aux_struct->ttt_cpc_1[0][ps][pb] + ONE_IN_Q16); |
534 | 47.2k | m_ttt[0][1] = (p_aux_struct->ttt_cpc_2[0][ps][pb] - ONE_IN_Q15); |
535 | 47.2k | m_ttt[1][0] = (p_aux_struct->ttt_cpc_1[0][ps][pb] - ONE_IN_Q15); |
536 | 47.2k | m_ttt[1][1] = (p_aux_struct->ttt_cpc_2[0][ps][pb] + ONE_IN_Q16); |
537 | 47.2k | m_ttt[2][0] = (ONE_IN_Q15 - p_aux_struct->ttt_cpc_1[0][ps][pb]); |
538 | 47.2k | m_ttt[2][1] = (ONE_IN_Q15 - p_aux_struct->ttt_cpc_2[0][ps][pb]); |
539 | | |
540 | 47.2k | if (pb >= pstr_mps_state->res_bands[3]) { |
541 | 46.7k | WORD32 one_by_icc; |
542 | 46.7k | one_by_icc = ixheaacd_dequant_one_by_icc(p_aux_struct->ttt_icc[0][ps][pb]); |
543 | | |
544 | 46.7k | m_ttt[0][0] = ixheaacd_mps_mult32_shr_15(m_ttt[0][0], one_by_icc); |
545 | 46.7k | m_ttt[0][1] = ixheaacd_mps_mult32_shr_15(m_ttt[0][1], one_by_icc); |
546 | 46.7k | m_ttt[1][0] = ixheaacd_mps_mult32_shr_15(m_ttt[1][0], one_by_icc); |
547 | 46.7k | m_ttt[1][1] = ixheaacd_mps_mult32_shr_15(m_ttt[1][1], one_by_icc); |
548 | 46.7k | m_ttt[2][0] = ixheaacd_mps_mult32_shr_15(m_ttt[2][0], one_by_icc); |
549 | 46.7k | m_ttt[2][1] = ixheaacd_mps_mult32_shr_15(m_ttt[2][1], one_by_icc); |
550 | 46.7k | } |
551 | | |
552 | 47.2k | m_ttt[0][0] = ixheaac_mult32x16in32(m_ttt[0][0], TWO_BY_THREE_Q15); |
553 | 47.2k | m_ttt[0][1] = ixheaac_mult32x16in32(m_ttt[0][1], TWO_BY_THREE_Q15); |
554 | 47.2k | m_ttt[1][0] = ixheaac_mult32x16in32(m_ttt[1][0], TWO_BY_THREE_Q15); |
555 | 47.2k | m_ttt[1][1] = ixheaac_mult32x16in32(m_ttt[1][1], TWO_BY_THREE_Q15); |
556 | 47.2k | m_ttt[2][0] = ixheaac_mult32x16in32(m_ttt[2][0], TWO_BY_THREE_Q15); |
557 | 47.2k | m_ttt[2][1] = ixheaac_mult32x16in32(m_ttt[2][1], TWO_BY_THREE_Q15); |
558 | 79.0k | } else { |
559 | 79.0k | WORD32 center_wiener; |
560 | 79.0k | WORD32 center_subtraction; |
561 | 79.0k | WORD32 c1d, c2d; |
562 | 79.0k | WORD64 prod; |
563 | 79.0k | WORD32 w11, w00, w20, w21; |
564 | 79.0k | WORD16 q_w11, q_w00, q_w20, q_w21; |
565 | | |
566 | 79.0k | const WORD32 *ten_cld_by_10 = |
567 | 79.0k | pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr->ten_cld_by_10; |
568 | | |
569 | 79.0k | ia_mps_dec_spatial_bs_frame_struct *p_cur_bs = pstr_mps_state->bs_frame; |
570 | 79.0k | WORD16 index = ixheaacd_map_cld_index(p_aux_struct->ttt_cld_1[0][ps][pb] >> 15); |
571 | | |
572 | 79.0k | c1d = ten_cld_by_10[index]; |
573 | | |
574 | 79.0k | index = ixheaacd_map_cld_index(p_aux_struct->ttt_cld_2[0][ps][pb] >> 15); |
575 | 79.0k | c2d = ten_cld_by_10[index]; |
576 | | |
577 | 79.0k | if (p_cur_bs->cmp_ttt_cld_1_idx[0][ps][pb] == 15 || |
578 | 78.7k | p_cur_bs->cmp_ttt_cld_2_idx[0][ps][pb] == 15) { |
579 | 368 | if (p_cur_bs->cmp_ttt_cld_1_idx[0][ps][pb] == 15) { |
580 | 204 | if (p_cur_bs->cmp_ttt_cld_2_idx[0][ps][pb] == -15) { |
581 | 7 | w00 = ONE_BY_SQRT_2_Q15; |
582 | 7 | w20 = ONE_BY_SQRT_8_Q15; |
583 | 197 | } else { |
584 | 197 | w00 = ONE_IN_Q15; |
585 | 197 | w20 = 0; |
586 | 197 | } |
587 | | |
588 | 204 | if (p_cur_bs->cmp_ttt_cld_2_idx[0][ps][pb] == 15) { |
589 | 4 | w11 = ONE_BY_SQRT_2_Q15; |
590 | 4 | w21 = ONE_BY_SQRT_8_Q15; |
591 | 200 | } else { |
592 | 200 | w11 = ONE_IN_Q15; |
593 | 200 | w21 = 0; |
594 | 200 | } |
595 | | |
596 | 204 | m_ttt[0][0] = w00; |
597 | 204 | m_ttt[2][0] = w20; |
598 | 204 | m_ttt[2][1] = w21; |
599 | 204 | m_ttt[1][1] = w11; |
600 | 204 | } |
601 | | |
602 | 368 | if (p_cur_bs->cmp_ttt_cld_2_idx[0][ps][pb] == 15) { |
603 | 168 | const WORD32 *w00_cld2_15 = |
604 | 168 | pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr->w00_cld2_15; |
605 | | |
606 | 168 | if (p_cur_bs->cmp_ttt_cld_1_idx[0][ps][pb] == 15) { |
607 | 4 | w11 = ONE_BY_SQRT_2_Q15; |
608 | 4 | w21 = ONE_BY_SQRT_8_Q15; |
609 | 164 | } else { |
610 | 164 | w11 = 0; |
611 | 164 | w21 = ONE_IN_Q14; |
612 | 164 | } |
613 | | |
614 | 168 | w00 = w00_cld2_15[p_cur_bs->cmp_ttt_cld_1_idx[0][ps][pb] + 15]; |
615 | 168 | w20 = w00_cld2_15[15 - p_cur_bs->cmp_ttt_cld_1_idx[0][ps][pb]] / 2; |
616 | 168 | m_ttt[0][0] = w00; |
617 | 168 | m_ttt[2][0] = w20; |
618 | 168 | m_ttt[2][1] = w21; |
619 | 168 | m_ttt[1][1] = w11; |
620 | 168 | } |
621 | | |
622 | 368 | m_ttt[0][1] = 0; |
623 | 368 | m_ttt[1][0] = 0; |
624 | 78.6k | } else { |
625 | 78.6k | WORD32 temporary; |
626 | 78.6k | const WORD32 *sqrt_tab = pstr_mps_state->ia_mps_dec_mps_table.common_table_ptr->sqrt_tab; |
627 | 78.6k | prod = ixheaacd_mps_mult32_shr_15(c1d, c2d); |
628 | | |
629 | 78.6k | temporary = ixheaac_add32_sat(ONE_IN_Q15, c2d); |
630 | 78.6k | temporary = ixheaac_add32_sat(temporary, (WORD32)prod); |
631 | 78.6k | w00 = ixheaacd_mps_div_32((WORD32)prod, temporary, &q_w00); |
632 | | |
633 | 78.6k | w11 = ixheaacd_mps_div_32(c1d, (ixheaac_add32_sat3(c1d, c2d, ONE_IN_Q15)), &q_w11); |
634 | | |
635 | 78.6k | w20 = ixheaacd_mps_div_32((ixheaac_add32_sat(c2d, ONE_IN_Q15)), |
636 | 78.6k | ixheaac_add32_sat3(ONE_IN_Q15, (WORD32)prod, c2d), &q_w20); |
637 | | |
638 | 78.6k | w21 = ixheaacd_mps_div_32(ixheaac_add32_sat(c2d, ONE_IN_Q15), |
639 | 78.6k | (ixheaac_add32_sat3(c1d, c2d, ONE_IN_Q15)), &q_w21); |
640 | | |
641 | 78.6k | m_ttt[0][0] = ixheaacd_mps_sqrt(w00, &q_w00, sqrt_tab); |
642 | 78.6k | m_ttt[0][0] = ixheaacd_mps_convert_to_qn(m_ttt[0][0], q_w00, 15); |
643 | | |
644 | 78.6k | m_ttt[0][1] = 0; |
645 | 78.6k | m_ttt[1][0] = 0; |
646 | | |
647 | 78.6k | m_ttt[1][1] = ixheaacd_mps_sqrt(w11, &q_w11, sqrt_tab); |
648 | 78.6k | m_ttt[1][1] = ixheaacd_mps_convert_to_qn(m_ttt[1][1], q_w11, 15); |
649 | | |
650 | 78.6k | m_ttt[2][0] = ixheaacd_mps_sqrt(w20, &q_w20, sqrt_tab) >> 1; |
651 | | |
652 | 78.6k | m_ttt[2][0] = ixheaacd_mps_convert_to_qn(m_ttt[2][0], q_w20, 15); |
653 | | |
654 | 78.6k | m_ttt[2][1] = ixheaacd_mps_sqrt(w21, &q_w21, sqrt_tab) >> 1; |
655 | | |
656 | 78.6k | m_ttt[2][1] = ixheaacd_mps_convert_to_qn(m_ttt[2][1], q_w21, 15); |
657 | 78.6k | if (p_aux_struct->ttt_cld_1[0][ps][pb] == 4915200) { |
658 | 51.9k | m_ttt[0][0] = 32767; |
659 | 51.9k | m_ttt[1][1] = 32767; |
660 | 51.9k | m_ttt[2][0] = 0; |
661 | 51.9k | m_ttt[2][1] = 0; |
662 | 51.9k | } |
663 | 78.6k | } |
664 | | |
665 | 79.0k | center_wiener = 0; |
666 | 79.0k | center_subtraction = (ttt_mode == 2 || ttt_mode == 3); |
667 | | |
668 | 79.0k | if (center_wiener) { |
669 | 0 | WORD32 cld_1_idx = p_cur_bs->cmp_ttt_cld_1_idx[0][ps][pb]; |
670 | 0 | WORD32 cld_2_idx = p_cur_bs->cmp_ttt_cld_2_idx[0][ps][pb]; |
671 | |
|
672 | 0 | if (cld_1_idx == 15 && cld_2_idx == 15) { |
673 | 0 | m_ttt[2][0] = 0; |
674 | 0 | m_ttt[2][1] = ONE_BY_SQRT_2_Q15; |
675 | 0 | } else if (cld_1_idx == 15) { |
676 | 0 | if (cld_2_idx == -15) |
677 | 0 | m_ttt[2][0] = ONE_BY_SQRT_2_Q15; |
678 | 0 | else |
679 | 0 | m_ttt[2][0] = 0; |
680 | 0 | m_ttt[2][1] = 0; |
681 | 0 | } else if (cld_2_idx == 15) { |
682 | 0 | m_ttt[2][0] = 0; |
683 | 0 | m_ttt[2][1] = ONE_IN_Q15; |
684 | 0 | } else { |
685 | 0 | WORD32 temp; |
686 | 0 | WORD16 q_temp; |
687 | 0 | const WORD32 *sqrt_tab = pstr_mps_state->ia_mps_dec_mps_table.common_table_ptr->sqrt_tab; |
688 | |
|
689 | 0 | prod = ixheaacd_mps_mult32_shr_15(c2d, (c2d + c1d + ONE_IN_Q16)) + ONE_IN_Q15; |
690 | |
|
691 | 0 | temp = ixheaacd_mps_div_32((WORD32)ONE_IN_Q15, (WORD32)prod, &q_temp); |
692 | |
|
693 | 0 | m_ttt[2][0] = ixheaacd_mps_sqrt(temp, &q_temp, sqrt_tab); |
694 | 0 | m_ttt[2][0] = ixheaacd_mps_convert_to_qn(m_ttt[2][0], q_temp, 15); |
695 | |
|
696 | 0 | m_ttt[2][1] = ixheaacd_mps_mult32_shr_15(c2d, m_ttt[2][0]); |
697 | 0 | } |
698 | 0 | } |
699 | | |
700 | 79.0k | if (center_subtraction) { |
701 | 24.6k | WORD32 wl1, wl2, wr1, wr2; |
702 | 24.6k | WORD16 q_wl1, q_wr1; |
703 | 24.6k | WORD32 cld_1_idx = p_cur_bs->cmp_ttt_cld_1_idx[0][ps][pb]; |
704 | 24.6k | WORD32 cld_2_idx = p_cur_bs->cmp_ttt_cld_2_idx[0][ps][pb]; |
705 | | |
706 | 24.6k | if (cld_1_idx == 15 && cld_2_idx == 15) { |
707 | 4 | m_ttt[0][0] = ONE_IN_Q15; |
708 | 4 | m_ttt[0][1] = MINUS_ONE_IN_Q14; |
709 | 4 | m_ttt[1][1] = ONE_BY_SQRT_2_Q15; |
710 | 4 | m_ttt[1][0] = 0; |
711 | 24.6k | } else if (cld_1_idx == 15) { |
712 | 149 | if (cld_2_idx == -15) { |
713 | 7 | m_ttt[0][0] = ONE_BY_SQRT_2_Q15; |
714 | 7 | m_ttt[1][0] = MINUS_ONE_IN_Q14; |
715 | 142 | } else { |
716 | 142 | m_ttt[0][0] = ONE_IN_Q15; |
717 | 142 | m_ttt[1][0] = 0; |
718 | 142 | } |
719 | | |
720 | 149 | m_ttt[0][1] = 0; |
721 | 149 | m_ttt[1][1] = ONE_IN_Q15; |
722 | 24.4k | } else if (cld_2_idx == 15) { |
723 | 121 | m_ttt[0][0] = ONE_IN_Q15; |
724 | 121 | m_ttt[0][1] = MINUS_ONE_IN_Q15; |
725 | 121 | m_ttt[1][1] = 0; |
726 | 121 | m_ttt[1][0] = 0; |
727 | 24.3k | } else { |
728 | 24.3k | WORD32 temp, temp_1, q_a; |
729 | 24.3k | WORD16 q_c, q_l, q_r, q_temp, q_temp1; |
730 | 24.3k | WORD32 c; |
731 | 24.3k | WORD32 r; |
732 | 24.3k | WORD32 l; |
733 | 24.3k | const WORD32 *sqrt_tab = pstr_mps_state->ia_mps_dec_mps_table.common_table_ptr->sqrt_tab; |
734 | | |
735 | 24.3k | c = ixheaacd_mps_div_32(ONE_IN_Q15, (ixheaac_add32_sat(c1d, ONE_IN_Q15)), &q_c); |
736 | 24.3k | r = ixheaacd_mps_div_32(c1d, (ixheaac_add32_sat(c2d, ONE_IN_Q15)), &q_r); |
737 | 24.3k | r = ixheaacd_mps_mult32_shr_30(r, c); |
738 | 24.3k | q_r = q_r + q_c - 30; |
739 | | |
740 | 24.3k | l = ixheaacd_mps_mult32_shr_30(c2d, r); |
741 | 24.3k | q_l = q_r - 15; |
742 | | |
743 | 24.3k | temp = ixheaacd_mps_div_32(r, l, &q_temp); |
744 | 24.3k | q_temp += (q_r - q_l); |
745 | | |
746 | 24.3k | if (q_temp > 28) { |
747 | 13.9k | temp = temp >> (q_temp - 28); |
748 | 13.9k | q_temp = 28; |
749 | 13.9k | } |
750 | | |
751 | 24.3k | temp += ((1 << q_temp) - 1); |
752 | | |
753 | 24.3k | temp = ixheaac_add32_sat( |
754 | 24.3k | ixheaacd_mps_mult32_shr_n(c, temp, (WORD16)(q_c + q_temp - q_r)), r); |
755 | 24.3k | q_temp = q_r; |
756 | | |
757 | 24.3k | if (q_c > q_r) { |
758 | 9.63k | temp_1 = r + (c >> (q_c - q_r)); |
759 | 9.63k | q_temp1 = q_r; |
760 | 14.7k | } else { |
761 | 14.7k | temp_1 = ixheaac_add32_sat((r >> (q_r - q_c)), c); |
762 | 14.7k | q_temp1 = q_c; |
763 | 14.7k | } |
764 | | |
765 | 24.3k | temp = ixheaac_div32(temp_1, temp, &q_a); |
766 | 24.3k | q_wl1 = q_a + q_temp1 - q_temp; |
767 | 24.3k | wl1 = ixheaacd_mps_sqrt(temp, &q_wl1, sqrt_tab); |
768 | 24.3k | m_ttt[0][0] = ixheaacd_mps_convert_to_qn(wl1, q_wl1, 15); |
769 | | |
770 | 24.3k | temp = ixheaac_div32(wl1, temp_1, &q_a); |
771 | 24.3k | q_temp = q_a + (q_wl1 - q_temp1); |
772 | 24.3k | wl2 = ixheaacd_mps_mult32_shr_n(c, temp, (WORD16)(q_c + q_temp - 15)); |
773 | 24.3k | m_ttt[0][1] = ixheaac_negate32_sat(wl2); |
774 | | |
775 | 24.3k | temp = ixheaacd_mps_div_32(l, r, &q_temp); |
776 | 24.3k | q_temp += (q_l - q_r); |
777 | | |
778 | 24.3k | if (q_temp > 28) { |
779 | 13.7k | temp = temp >> (q_temp - 28); |
780 | 13.7k | q_temp = 28; |
781 | 13.7k | } |
782 | | |
783 | 24.3k | temp = ixheaac_add32_sat((1 << q_temp) - 1, temp); |
784 | | |
785 | 24.3k | temp = ixheaac_add32_sat( |
786 | 24.3k | ixheaacd_mps_mult32_shr_n(c, temp, (WORD16)(q_c + q_temp - q_l)), l); |
787 | | |
788 | 24.3k | q_temp = q_l; |
789 | | |
790 | 24.3k | if (q_c > q_l) { |
791 | 15.4k | temp_1 = l + (c >> (q_c - q_l)); |
792 | 15.4k | q_temp1 = q_l; |
793 | 15.4k | } else { |
794 | 8.84k | temp_1 = ixheaac_add32_sat((l >> (q_l - q_c)), c); |
795 | 8.84k | q_temp1 = q_c; |
796 | 8.84k | } |
797 | | |
798 | 24.3k | temp = ixheaac_div32(temp_1, temp, &q_a); |
799 | 24.3k | q_wr1 = q_a + q_temp1 - q_temp; |
800 | 24.3k | wr1 = ixheaacd_mps_sqrt(temp, &q_wr1, sqrt_tab); |
801 | 24.3k | m_ttt[1][1] = ixheaacd_mps_convert_to_qn(wr1, q_wr1, 15); |
802 | | |
803 | 24.3k | temp = ixheaac_div32(wr1, temp_1, &q_a); |
804 | 24.3k | q_temp = q_a + (q_wl1 - q_temp1); |
805 | 24.3k | wr2 = ixheaacd_mps_mult32_shr_n(c, temp, (WORD16)(q_c + q_temp - 15)); |
806 | 24.3k | m_ttt[1][0] = ixheaac_negate32_sat(wr2); |
807 | 24.3k | } |
808 | 24.6k | } |
809 | 79.0k | } |
810 | | |
811 | 126k | m_ttt[0][2] = ONE_BY_THREE_Q15; |
812 | 126k | m_ttt[1][2] = ONE_BY_THREE_Q15; |
813 | 126k | m_ttt[2][2] = MINUS_ONE_BY_THREE_Q15; |
814 | | |
815 | 505k | for (col = 0; col < 3; col++) { |
816 | 378k | m_ttt[2][col] = ixheaacd_mps_mult32_shr_15(m_ttt[2][col], SQRT_TWO_Q15); |
817 | 378k | } |
818 | 126k | } |
819 | | |
820 | | VOID ixheaacd_calculate_mtx_inv(ia_heaac_mps_state_struct *pstr_mps_state, WORD32 ps, WORD32 pb, |
821 | 23.8k | WORD32 mode, WORD32 h_real[][2], WORD32 h_imag[][2]) { |
822 | 23.8k | ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct; |
823 | | |
824 | 23.8k | WORD32 weight1; |
825 | 23.8k | WORD32 weight2; |
826 | 23.8k | ia_mps_dec_spatial_bs_frame_struct *p_cur_bs = pstr_mps_state->bs_frame; |
827 | | |
828 | 23.8k | if (mode < 2) { |
829 | 8.81k | ixheaacd_get_matrix_inversion_weights( |
830 | 8.81k | p_cur_bs->ott_cld_idx[1][ps][pb], p_cur_bs->ott_cld_idx[2][ps][pb], 1, |
831 | 8.81k | p_aux_struct->ttt_cpc_1[0][ps][pb], p_aux_struct->ttt_cpc_2[0][ps][pb], &weight1, |
832 | 8.81k | &weight2, &(pstr_mps_state->ia_mps_dec_mps_table)); |
833 | 14.9k | } else { |
834 | 14.9k | ixheaacd_get_matrix_inversion_weights( |
835 | 14.9k | p_cur_bs->ott_cld_idx[1][ps][pb], p_cur_bs->ott_cld_idx[2][ps][pb], 0, |
836 | 14.9k | p_cur_bs->cmp_ttt_cld_1_idx[0][ps][pb], p_cur_bs->cmp_ttt_cld_2_idx[0][ps][pb], &weight1, |
837 | 14.9k | &weight2, &(pstr_mps_state->ia_mps_dec_mps_table)); |
838 | 14.9k | } |
839 | | |
840 | 23.8k | ixheaacd_invert_matrix(weight1, weight2, h_real, h_imag, |
841 | 23.8k | pstr_mps_state->ia_mps_dec_mps_table.common_table_ptr); |
842 | 23.8k | } |
843 | | |
844 | | VOID ixheaacd_calculate_arb_dmx_mtx(ia_heaac_mps_state_struct *pstr_mps_state, WORD32 ps, |
845 | 59.0k | WORD32 pb, WORD32 g_real[]) { |
846 | 59.0k | WORD32 ch; |
847 | 59.0k | WORD32 gain; |
848 | | |
849 | 59.0k | WORD32 *arbdmx_alpha_prev = pstr_mps_state->mps_persistent_mem.arbdmx_alpha_prev; |
850 | 59.0k | WORD32 *arbdmx_alpha_upd_set = pstr_mps_state->aux_struct->arbdmx_alpha_upd_set; |
851 | 59.0k | WORD32 *arbdmx_alpha = pstr_mps_state->aux_struct->arbdmx_alpha; |
852 | | |
853 | 59.0k | WORD32 n_ch_in = pstr_mps_state->num_input_channels; |
854 | 59.0k | WORD32 temp_1; |
855 | 148k | for (ch = 0; ch < n_ch_in; ch++) { |
856 | 89.2k | temp_1 = pstr_mps_state->bs_frame->arbdmx_gain_idx[ch][ps][pb] + 15; |
857 | 89.2k | gain = pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr->dec_pow[temp_1]; |
858 | | |
859 | 89.2k | if (pb < pstr_mps_state->arbdmx_residual_bands) { |
860 | 3.12k | if ((ps == 0) && (arbdmx_alpha_upd_set[ch] == 1)) { |
861 | 273 | g_real[ch] = ixheaacd_mps_mult32_shr_15(*arbdmx_alpha_prev, gain); |
862 | 2.84k | } else { |
863 | 2.84k | g_real[ch] = ixheaacd_mps_mult32_shr_15(arbdmx_alpha[ch], gain); |
864 | 2.84k | } |
865 | 86.1k | } else { |
866 | 86.1k | g_real[ch] = gain; |
867 | 86.1k | } |
868 | 89.2k | arbdmx_alpha_prev++; |
869 | 89.2k | } |
870 | 59.0k | } |
871 | | |
872 | 47.8k | WORD32 ixheaacd_quantize(WORD32 cld) { |
873 | 47.8k | switch (cld) { |
874 | 1.50k | case -150: |
875 | 1.50k | return -15; |
876 | 192 | case -45: |
877 | 192 | return -14; |
878 | 79 | case -40: |
879 | 79 | return -13; |
880 | 243 | case -35: |
881 | 243 | return -12; |
882 | 242 | case -30: |
883 | 242 | return -11; |
884 | 83 | case -25: |
885 | 83 | return -10; |
886 | 278 | case -22: |
887 | 278 | return -9; |
888 | 7.92k | case -19: |
889 | 7.92k | return -8; |
890 | 235 | case -16: |
891 | 235 | return -7; |
892 | 421 | case -13: |
893 | 421 | return -6; |
894 | 1.37k | case -10: |
895 | 1.37k | return -5; |
896 | 1.99k | case -8: |
897 | 1.99k | return -4; |
898 | 397 | case -6: |
899 | 397 | return -3; |
900 | 437 | case -4: |
901 | 437 | return -2; |
902 | 1.66k | case -2: |
903 | 1.66k | return -1; |
904 | 2.10k | case 0: |
905 | 2.10k | return 0; |
906 | 356 | case 2: |
907 | 356 | return 1; |
908 | 596 | case 4: |
909 | 596 | return 2; |
910 | 744 | case 6: |
911 | 744 | return 3; |
912 | 1.60k | case 8: |
913 | 1.60k | return 4; |
914 | 421 | case 10: |
915 | 421 | return 5; |
916 | 1.39k | case 13: |
917 | 1.39k | return 6; |
918 | 243 | case 16: |
919 | 243 | return 7; |
920 | 365 | case 19: |
921 | 365 | return 8; |
922 | 351 | case 22: |
923 | 351 | return 9; |
924 | 339 | case 25: |
925 | 339 | return 10; |
926 | 132 | case 30: |
927 | 132 | return 11; |
928 | 265 | case 35: |
929 | 265 | return 12; |
930 | 113 | case 40: |
931 | 113 | return 13; |
932 | 738 | case 45: |
933 | 738 | return 14; |
934 | 20.9k | case 150: |
935 | 20.9k | return 15; |
936 | 0 | default: |
937 | 0 | return 0; |
938 | 47.8k | } |
939 | 47.8k | } |