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