/src/libxaac/decoder/ixheaacd_mps_res_block.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 "ixheaac_constants.h" |
22 | | #include "ixheaac_basic_ops32.h" |
23 | | #include "ixheaac_basic_ops40.h" |
24 | | #include "ixheaac_basic_ops.h" |
25 | | #include "ixheaacd_bitbuffer.h" |
26 | | #include "ixheaac_basic_op.h" |
27 | | #include "ixheaacd_mps_aac_struct.h" |
28 | | #include "ixheaacd_mps_res_rom.h" |
29 | | #include "ixheaacd_mps_res_block.h" |
30 | | #include "ixheaacd_mps_res_huffman.h" |
31 | | |
32 | | static PLATFORM_INLINE WORD32 ixheaacd_res_extract_symbol(WORD32 value, WORD32 l_shift, |
33 | 40.6k | WORD32 r_shift, WORD32 *pow_table_q17) { |
34 | 40.6k | WORD32 out; |
35 | 40.6k | out = (WORD16)((value << l_shift) >> r_shift); |
36 | | |
37 | 40.6k | if (out < 0) { |
38 | 15.8k | out = -out; |
39 | 15.8k | out = pow_table_q17[out]; |
40 | 15.8k | out = -out; |
41 | 15.8k | } else |
42 | 24.8k | out = pow_table_q17[out]; |
43 | | |
44 | 40.6k | return out; |
45 | 40.6k | } |
46 | | |
47 | | static PLATFORM_INLINE WORD32 ixheaacd_res_extract_signed_symbol(WORD32 value, WORD32 l_shift, |
48 | | WORD32 r_shift, |
49 | | WORD32 *pow_table_q17, |
50 | | WORD32 *temp_word, |
51 | 131k | WORD32 *pr_bit_pos) { |
52 | 131k | WORD32 out; |
53 | 131k | out = ixheaac_extu(value, l_shift, r_shift); |
54 | 131k | if (out) { |
55 | 46.1k | WORD32 bit_pos = *pr_bit_pos; |
56 | 46.1k | out = pow_table_q17[out]; |
57 | 46.1k | if (*temp_word & 0x80000000) { |
58 | 29.5k | out = -out; |
59 | 29.5k | } |
60 | 46.1k | *temp_word = *temp_word << 1; |
61 | 46.1k | bit_pos++; |
62 | 46.1k | *pr_bit_pos = bit_pos; |
63 | 46.1k | } |
64 | 131k | return out; |
65 | 131k | } |
66 | | |
67 | | VOID ixheaacd_res_inverse_quant_lb(WORD32 *x_invquant, WORD t_bands, WORD32 *pow_table_q17, |
68 | 65 | WORD8 *pulse_data) { |
69 | 65 | WORD32 j; |
70 | 65 | WORD32 temp; |
71 | 65 | WORD32 q_abs; |
72 | | |
73 | 7.80k | for (j = t_bands - 1; j >= 0; j--) { |
74 | 7.74k | q_abs = *pulse_data++; |
75 | 7.74k | temp = (pow_table_q17[q_abs]); |
76 | 7.74k | *x_invquant++ = -temp; |
77 | 7.74k | } |
78 | 65 | } |
79 | | |
80 | | static PLATFORM_INLINE WORD ixheaacd_res_c_block_decode_huff_word1( |
81 | | ia_bit_buf_struct *it_bit_buf, WORD32 *qp, WORD16 *offsets, WORD no_bands, WORD group_no, |
82 | 107 | const UWORD16 *h_ori, WORD32 *pow_table_q17, WORD32 maximum_bins_short) { |
83 | 107 | WORD32 sp1, sp2; |
84 | 107 | WORD32 flush_cw; |
85 | 107 | WORD32 i, value, norm_val, off; |
86 | 107 | WORD idx, grp_idx; |
87 | 107 | WORD32 out1, out2; |
88 | 107 | WORD32 err_code = 0; |
89 | 107 | WORD len_idx = 0; |
90 | 107 | UWORD8 *ptr_read_next = it_bit_buf->ptr_read_next; |
91 | 107 | WORD32 bit_pos = it_bit_buf->bit_pos; |
92 | 107 | WORD32 read_word = ixheaacd_res_aac_showbits_32(ptr_read_next); |
93 | 107 | ptr_read_next += 4; |
94 | | |
95 | 354 | do { |
96 | 354 | len_idx = offsets[1] - offsets[0]; |
97 | 354 | grp_idx = group_no; |
98 | 2.10k | do { |
99 | 2.10k | qp = qp + offsets[0]; |
100 | 2.10k | idx = len_idx; |
101 | 13.1k | do { |
102 | 13.1k | { |
103 | 13.1k | UWORD16 first_offset; |
104 | 13.1k | WORD16 sign_ret_val; |
105 | 13.1k | UWORD32 read_word1; |
106 | 13.1k | UWORD16 *h; |
107 | | |
108 | 13.1k | read_word1 = read_word << bit_pos; |
109 | | |
110 | 13.1k | h = (UWORD16 *)h_ori; |
111 | 13.1k | h += (read_word1) >> (27); |
112 | 13.1k | sign_ret_val = *h; |
113 | | |
114 | 13.1k | first_offset = 5; |
115 | 25.1k | while (sign_ret_val > 0) { |
116 | 11.9k | bit_pos += first_offset; |
117 | 11.9k | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
118 | 11.9k | it_bit_buf->ptr_bit_buf_end); |
119 | 11.9k | read_word1 = (read_word1) << (first_offset); |
120 | 11.9k | first_offset = (sign_ret_val >> 11); |
121 | 11.9k | h += sign_ret_val & (0x07FF); |
122 | 11.9k | h += (read_word1) >> (32 - first_offset); |
123 | 11.9k | sign_ret_val = *h; |
124 | 11.9k | } |
125 | 13.1k | bit_pos += ((sign_ret_val & 0x7fff) >> 11); |
126 | 13.1k | bit_pos = min(bit_pos, 31); |
127 | 13.1k | value = sign_ret_val & (0x07FF); |
128 | 13.1k | } |
129 | 13.1k | out1 = (value & 0x3E0) >> 5; |
130 | 13.1k | out2 = value & 0x1F; |
131 | | |
132 | 13.1k | flush_cw = read_word << bit_pos; |
133 | | |
134 | 13.1k | sp1 = out1; |
135 | 13.1k | sp2 = out2; |
136 | | |
137 | 13.1k | if (out1) { |
138 | 11.8k | if (flush_cw & 0x80000000) { |
139 | 11.0k | out1 = -out1; |
140 | 11.0k | } |
141 | 11.8k | bit_pos++; |
142 | 11.8k | flush_cw = (WORD32)flush_cw << 1; |
143 | 11.8k | } |
144 | | |
145 | 13.1k | if (out2) { |
146 | 11.7k | bit_pos++; |
147 | 11.7k | if (flush_cw & 0x80000000) { |
148 | 696 | out2 = -out2; |
149 | 696 | } |
150 | 11.7k | } |
151 | | |
152 | 13.1k | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
153 | 13.1k | it_bit_buf->ptr_bit_buf_end); |
154 | 13.1k | if (sp1 == 16) { |
155 | 303 | i = 4; |
156 | 303 | value = ixheaac_extu(read_word, bit_pos, 23); |
157 | 303 | value = value | 0xfffffe00; |
158 | 303 | norm_val = ixheaac_norm32(value); |
159 | | |
160 | 303 | i += (norm_val - 22); |
161 | 303 | bit_pos += (norm_val - 21); |
162 | | |
163 | 303 | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
164 | 303 | it_bit_buf->ptr_bit_buf_end); |
165 | | |
166 | 303 | off = ixheaac_extu(read_word, bit_pos, 32 - i); |
167 | | |
168 | 303 | bit_pos += i; |
169 | | |
170 | 303 | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
171 | 303 | it_bit_buf->ptr_bit_buf_end); |
172 | | |
173 | 303 | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
174 | 303 | it_bit_buf->ptr_bit_buf_end); |
175 | | |
176 | 303 | i = off + ((WORD32)1 << i); |
177 | | |
178 | 303 | if (i <= IQ_TABLE_SIZE_HALF) |
179 | 249 | i = pow_table_q17[i]; |
180 | 54 | else { |
181 | 54 | err_code |= ixheaacd_res_inv_quant(&i, pow_table_q17); |
182 | 54 | } |
183 | | |
184 | 303 | if (out1 < 0) { |
185 | 97 | out1 = -i; |
186 | 206 | } else { |
187 | 206 | out1 = i; |
188 | 206 | } |
189 | 303 | *qp++ = out1; |
190 | 12.8k | } else { |
191 | 12.8k | if (out1 <= 0) { |
192 | 12.2k | out1 = -out1; |
193 | 12.2k | out1 = pow_table_q17[out1]; |
194 | 12.2k | *qp++ = -out1; |
195 | 12.2k | } else { |
196 | 594 | out1 = pow_table_q17[out1]; |
197 | 594 | *qp++ = out1; |
198 | 594 | } |
199 | 12.8k | } |
200 | 13.1k | if (sp2 == 16) { |
201 | 300 | i = 4; |
202 | 300 | value = ixheaac_extu(read_word, bit_pos, 23); |
203 | 300 | value = value | 0xfffffe00; |
204 | 300 | norm_val = ixheaac_norm32(value); |
205 | | |
206 | 300 | i += (norm_val - 22); |
207 | | |
208 | 300 | bit_pos += (norm_val - 21); |
209 | | |
210 | 300 | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
211 | 300 | it_bit_buf->ptr_bit_buf_end); |
212 | | |
213 | 300 | off = ixheaac_extu(read_word, bit_pos, 32 - i); |
214 | | |
215 | 300 | bit_pos += i; |
216 | | |
217 | 300 | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
218 | 300 | it_bit_buf->ptr_bit_buf_end); |
219 | | |
220 | 300 | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
221 | 300 | it_bit_buf->ptr_bit_buf_end); |
222 | | |
223 | 300 | i = off + ((WORD32)1 << i); |
224 | | |
225 | 300 | if (i <= IQ_TABLE_SIZE_HALF) |
226 | 226 | i = pow_table_q17[i]; |
227 | 74 | else { |
228 | 74 | err_code |= ixheaacd_res_inv_quant(&i, pow_table_q17); |
229 | 74 | } |
230 | | |
231 | 300 | if (out2 < 0) { |
232 | 132 | out2 = -i; |
233 | 168 | } else { |
234 | 168 | out2 = i; |
235 | 168 | } |
236 | 300 | *qp++ = out2; |
237 | 12.8k | } else { |
238 | 12.8k | if (out2 <= 0) { |
239 | 1.90k | out2 = -out2; |
240 | 1.90k | out2 = pow_table_q17[out2]; |
241 | 1.90k | *qp++ = -out2; |
242 | 10.9k | } else { |
243 | 10.9k | out2 = pow_table_q17[out2]; |
244 | 10.9k | *qp++ = out2; |
245 | 10.9k | } |
246 | 12.8k | } |
247 | | |
248 | 13.1k | idx -= 2; |
249 | 13.1k | } while (idx != 0); |
250 | | |
251 | 2.10k | qp += (maximum_bins_short - offsets[1]); |
252 | 2.10k | grp_idx--; |
253 | 2.10k | } while (grp_idx != 0); |
254 | | |
255 | 354 | offsets++; |
256 | 354 | qp -= (maximum_bins_short * group_no); |
257 | 354 | no_bands--; |
258 | 354 | } while (no_bands >= 0); |
259 | | |
260 | 107 | it_bit_buf->bit_pos = bit_pos; |
261 | 107 | it_bit_buf->ptr_read_next = ptr_read_next - 4; |
262 | | |
263 | 107 | return err_code; |
264 | 107 | } |
265 | | |
266 | | static PLATFORM_INLINE WORD ixheaacd_res_c_block_decode_huff_word1_lb( |
267 | | ia_bit_buf_struct *it_bif_buf, WORD32 len, const UWORD16 *h_ori, WORD32 *x_invquant, |
268 | 85 | WORD32 *pow_table_q17, WORD8 *p_pul_arr) { |
269 | 85 | WORD32 sp1, sp2; |
270 | 85 | WORD32 flush_cw; |
271 | 85 | WORD32 i, value, norm_val, off; |
272 | 85 | WORD idx; |
273 | 85 | WORD32 out1, out2; |
274 | 85 | WORD32 err_code = 0; |
275 | 85 | UWORD8 *ptr_read_next = it_bif_buf->ptr_read_next; |
276 | 85 | WORD32 bit_pos = it_bif_buf->bit_pos; |
277 | 85 | WORD32 read_word = ixheaacd_res_aac_showbits_32(ptr_read_next); |
278 | 85 | ptr_read_next += 4; |
279 | | |
280 | 9.28k | for (idx = len; idx != 0; idx -= 2) { |
281 | 9.19k | { |
282 | 9.19k | UWORD16 first_offset; |
283 | 9.19k | WORD16 sign_ret_val; |
284 | 9.19k | UWORD32 read_word1; |
285 | 9.19k | UWORD16 *h; |
286 | | |
287 | 9.19k | read_word1 = read_word << bit_pos; |
288 | | |
289 | 9.19k | h = (UWORD16 *)h_ori; |
290 | 9.19k | h += (read_word1) >> (27); |
291 | 9.19k | sign_ret_val = *h; |
292 | | |
293 | 9.19k | first_offset = 5; |
294 | 14.8k | while (sign_ret_val > 0) { |
295 | 5.67k | bit_pos += first_offset; |
296 | 5.67k | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
297 | 5.67k | it_bif_buf->ptr_bit_buf_end); |
298 | 5.67k | read_word1 = (read_word1) << (first_offset); |
299 | | |
300 | 5.67k | first_offset = (sign_ret_val >> 11); |
301 | 5.67k | h += sign_ret_val & (0x07FF); |
302 | | |
303 | 5.67k | h += (read_word1) >> (32 - first_offset); |
304 | 5.67k | sign_ret_val = *h; |
305 | 5.67k | } |
306 | 9.19k | bit_pos += ((sign_ret_val & 0x7fff) >> 11); |
307 | 9.19k | bit_pos = min(bit_pos, 31); |
308 | 9.19k | value = sign_ret_val & (0x07FF); |
309 | 9.19k | } |
310 | | |
311 | 9.19k | flush_cw = read_word << bit_pos; |
312 | | |
313 | 9.19k | out1 = (value & 0x3E0) >> 5; |
314 | 9.19k | out2 = value & 0x1F; |
315 | | |
316 | 9.19k | sp1 = out1; |
317 | | |
318 | 9.19k | if (out1) { |
319 | 5.39k | if (flush_cw & 0x80000000) { |
320 | 4.32k | out1 = -out1; |
321 | 4.32k | } |
322 | | |
323 | 5.39k | bit_pos++; |
324 | 5.39k | flush_cw = (WORD32)flush_cw << 1; |
325 | 5.39k | } |
326 | | |
327 | 9.19k | sp2 = out2; |
328 | 9.19k | if (out2) { |
329 | 5.24k | bit_pos++; |
330 | 5.24k | if (flush_cw & 0x80000000) { |
331 | 962 | out2 = -out2; |
332 | 962 | } |
333 | 5.24k | } |
334 | | |
335 | 9.19k | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
336 | 9.19k | it_bif_buf->ptr_bit_buf_end); |
337 | | |
338 | 9.19k | if (sp1 == 16) { |
339 | 442 | i = 4; |
340 | 442 | value = ixheaac_extu(read_word, bit_pos, 23); |
341 | 442 | value = value | 0xfffffe00; |
342 | 442 | norm_val = ixheaac_norm32(value); |
343 | 442 | i += (norm_val - 22); |
344 | 442 | bit_pos += (norm_val - 21); |
345 | | |
346 | 442 | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
347 | 442 | it_bif_buf->ptr_bit_buf_end); |
348 | | |
349 | 442 | off = ixheaac_extu(read_word, bit_pos, 32 - i); |
350 | | |
351 | 442 | bit_pos += i; |
352 | | |
353 | 442 | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
354 | 442 | it_bif_buf->ptr_bit_buf_end); |
355 | 442 | value = *p_pul_arr++; |
356 | 442 | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
357 | 442 | it_bif_buf->ptr_bit_buf_end); |
358 | 442 | i = off + ((WORD32)1 << i); |
359 | 442 | i = add_d(i, value); |
360 | | |
361 | 442 | if (i <= IQ_TABLE_SIZE_HALF) |
362 | 355 | i = pow_table_q17[i]; |
363 | 87 | else { |
364 | 87 | err_code |= ixheaacd_res_inv_quant(&i, pow_table_q17); |
365 | 87 | } |
366 | 442 | if (out1 < 0) { |
367 | 212 | i = -i; |
368 | 212 | } |
369 | 442 | *x_invquant++ = i; |
370 | 8.75k | } else { |
371 | 8.75k | WORD8 temp = *p_pul_arr++; |
372 | 8.75k | if (out1 <= 0) { |
373 | 7.91k | out1 = sub_d(temp, out1); |
374 | 7.91k | out1 = pow_table_q17[out1]; |
375 | 7.91k | *x_invquant++ = -out1; |
376 | 7.91k | } else { |
377 | 837 | out1 = add_d(out1, temp); |
378 | 837 | out1 = pow_table_q17[out1]; |
379 | 837 | *x_invquant++ = out1; |
380 | 837 | } |
381 | 8.75k | } |
382 | | |
383 | 9.19k | if (sp2 == 16) { |
384 | 513 | i = 4; |
385 | 513 | value = ixheaac_extu(read_word, bit_pos, 23); |
386 | 513 | value = value | 0xfffffe00; |
387 | 513 | norm_val = ixheaac_norm32(value); |
388 | | |
389 | 513 | i += (norm_val - 22); |
390 | | |
391 | 513 | bit_pos += (norm_val - 21); |
392 | | |
393 | 513 | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
394 | 513 | it_bif_buf->ptr_bit_buf_end); |
395 | | |
396 | 513 | off = ixheaac_extu(read_word, bit_pos, 32 - i); |
397 | | |
398 | 513 | bit_pos += i; |
399 | | |
400 | 513 | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
401 | 513 | it_bif_buf->ptr_bit_buf_end); |
402 | 513 | value = *p_pul_arr++; |
403 | 513 | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
404 | 513 | it_bif_buf->ptr_bit_buf_end); |
405 | | |
406 | 513 | i = off + ((WORD32)1 << i); |
407 | 513 | i = add_d(i, value); |
408 | 513 | if (i <= IQ_TABLE_SIZE_HALF) |
409 | 350 | i = pow_table_q17[i]; |
410 | 163 | else { |
411 | 163 | err_code |= ixheaacd_res_inv_quant(&i, pow_table_q17); |
412 | 163 | } |
413 | | |
414 | 513 | if (out2 < 0) { |
415 | 185 | i = -i; |
416 | 185 | } |
417 | 513 | *x_invquant++ = i; |
418 | 8.68k | } else { |
419 | 8.68k | WORD8 temp = *p_pul_arr++; |
420 | 8.68k | if (out2 <= 0) { |
421 | 4.72k | out2 = sub_d(temp, out2); |
422 | 4.72k | out2 = pow_table_q17[out2]; |
423 | 4.72k | *x_invquant++ = -out2; |
424 | 4.72k | } else { |
425 | 3.95k | out2 = add_d(out2, temp); |
426 | 3.95k | out2 = pow_table_q17[out2]; |
427 | 3.95k | *x_invquant++ = out2; |
428 | 3.95k | } |
429 | 8.68k | } |
430 | 9.19k | } |
431 | | |
432 | 85 | it_bif_buf->ptr_read_next = ptr_read_next - 4; |
433 | 85 | it_bif_buf->bit_pos = bit_pos; |
434 | | |
435 | 85 | return err_code; |
436 | 85 | } |
437 | | |
438 | | static PLATFORM_INLINE WORD ixheaacd_res_c_block_decode_huff_word2_4( |
439 | | ia_bit_buf_struct *it_bit_buf, WORD32 *qp, WORD16 *offsets, WORD no_bands, WORD group_no, |
440 | 439 | const UWORD16 *h_ori, WORD32 *pow_table_q17, WORD32 sign, WORD32 maximum_bins_short) { |
441 | 439 | WORD32 value; |
442 | 439 | WORD idx, grp_idx; |
443 | 439 | WORD idx_len; |
444 | 439 | WORD32 *qp_org; |
445 | | |
446 | 439 | UWORD8 *ptr_read_next = it_bit_buf->ptr_read_next; |
447 | 439 | WORD32 bit_pos = it_bit_buf->bit_pos; |
448 | 439 | WORD32 read_word = ixheaacd_res_aac_showbits_32(ptr_read_next); |
449 | 439 | ptr_read_next += 4; |
450 | 439 | qp_org = qp; |
451 | 2.39k | do { |
452 | 2.39k | idx_len = offsets[1] - offsets[0]; |
453 | 2.39k | grp_idx = group_no; |
454 | | |
455 | 16.0k | do { |
456 | 16.0k | qp = qp + offsets[0]; |
457 | 16.0k | idx = idx_len; |
458 | 27.9k | do { |
459 | 27.9k | UWORD16 first_offset; |
460 | 27.9k | WORD16 sign_ret_val; |
461 | 27.9k | UWORD32 read_word1; |
462 | 27.9k | UWORD16 *h; |
463 | | |
464 | 27.9k | read_word1 = read_word << bit_pos; |
465 | | |
466 | 27.9k | h = (UWORD16 *)h_ori; |
467 | 27.9k | h += (read_word1) >> (27); |
468 | 27.9k | sign_ret_val = *h; |
469 | | |
470 | 27.9k | first_offset = 5; |
471 | 31.5k | while (sign_ret_val > 0) { |
472 | 3.60k | bit_pos += first_offset; |
473 | 3.60k | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
474 | 3.60k | it_bit_buf->ptr_bit_buf_end); |
475 | 3.60k | read_word1 = (read_word1) << (first_offset); |
476 | | |
477 | 3.60k | first_offset = (sign_ret_val >> 11); |
478 | 3.60k | h += sign_ret_val & (0x07FF); |
479 | | |
480 | 3.60k | h += (read_word1) >> (32 - first_offset); |
481 | 3.60k | sign_ret_val = *h; |
482 | 3.60k | } |
483 | 27.9k | bit_pos += ((sign_ret_val & 0x7fff) >> 11); |
484 | 27.9k | bit_pos = min(bit_pos, 31); |
485 | 27.9k | value = sign_ret_val & (0x07FF); |
486 | | |
487 | 27.9k | if (sign) { |
488 | 23.9k | WORD32 temp_word; |
489 | 23.9k | temp_word = read_word << bit_pos; |
490 | | |
491 | 23.9k | *qp++ = ixheaacd_res_extract_signed_symbol(value, 24, 30, pow_table_q17, &temp_word, |
492 | 23.9k | &bit_pos); |
493 | 23.9k | *qp++ = ixheaacd_res_extract_signed_symbol(value, 26, 30, pow_table_q17, &temp_word, |
494 | 23.9k | &bit_pos); |
495 | 23.9k | *qp++ = ixheaacd_res_extract_signed_symbol(value, 28, 30, pow_table_q17, &temp_word, |
496 | 23.9k | &bit_pos); |
497 | 23.9k | *qp++ = ixheaacd_res_extract_signed_symbol(value, 30, 30, pow_table_q17, &temp_word, |
498 | 23.9k | &bit_pos); |
499 | 23.9k | } else { |
500 | 4.02k | *qp++ = ixheaacd_res_extract_symbol(value, 24, 30, pow_table_q17); |
501 | 4.02k | *qp++ = ixheaacd_res_extract_symbol(value, 26, 30, pow_table_q17); |
502 | 4.02k | *qp++ = ixheaacd_res_extract_symbol(value, 28, 30, pow_table_q17); |
503 | 4.02k | *qp++ = ixheaacd_res_extract_symbol(value, 30, 30, pow_table_q17); |
504 | 4.02k | } |
505 | | |
506 | 27.9k | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
507 | 27.9k | it_bit_buf->ptr_bit_buf_end); |
508 | 27.9k | idx -= 4; |
509 | 27.9k | } while (idx != 0); |
510 | | |
511 | 16.0k | qp += (maximum_bins_short - offsets[1]); |
512 | 16.0k | grp_idx--; |
513 | 16.0k | } while (grp_idx != 0); |
514 | 2.39k | offsets++; |
515 | 2.39k | qp = qp_org; |
516 | 2.39k | no_bands--; |
517 | 2.39k | } while (no_bands >= 0); |
518 | | |
519 | 439 | it_bit_buf->ptr_read_next = ptr_read_next - 4; |
520 | 439 | it_bit_buf->bit_pos = bit_pos; |
521 | | |
522 | 439 | return 0; |
523 | 439 | } |
524 | | |
525 | | static PLATFORM_INLINE WORD ixheaacd_res_c_block_decode_huff_word2_4_lb( |
526 | | ia_bit_buf_struct *it_bit_buf, WORD32 len, const UWORD16 *h_ori, WORD32 *x_invquant, |
527 | 364 | WORD32 *pow_table_q17, WORD8 *p_pul_arr, WORD32 sign) { |
528 | 364 | WORD32 value; |
529 | 364 | WORD idx; |
530 | | |
531 | 364 | UWORD8 *ptr_read_next = it_bit_buf->ptr_read_next; |
532 | 364 | WORD32 bit_pos = it_bit_buf->bit_pos; |
533 | 364 | WORD32 read_word = ixheaacd_res_aac_showbits_32(ptr_read_next); |
534 | 364 | ptr_read_next += 4; |
535 | | |
536 | 11.1k | for (idx = len; idx != 0; idx -= 4) { |
537 | 10.7k | WORD32 res; |
538 | 10.7k | WORD32 ampres, ampres1; |
539 | 10.7k | WORD32 ampres2, ampres3; |
540 | 10.7k | UWORD16 first_offset; |
541 | 10.7k | WORD16 sign_ret_val; |
542 | 10.7k | UWORD32 read_word1; |
543 | 10.7k | UWORD16 *h; |
544 | | |
545 | 10.7k | read_word1 = read_word << bit_pos; |
546 | | |
547 | 10.7k | h = (UWORD16 *)h_ori; |
548 | 10.7k | h += (read_word1) >> (27); |
549 | 10.7k | sign_ret_val = *h; |
550 | | |
551 | 10.7k | first_offset = 5; |
552 | 13.4k | while (sign_ret_val > 0) { |
553 | 2.66k | bit_pos += first_offset; |
554 | 2.66k | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
555 | 2.66k | it_bit_buf->ptr_bit_buf_end); |
556 | 2.66k | read_word1 = (read_word1) << (first_offset); |
557 | | |
558 | 2.66k | first_offset = (sign_ret_val >> 11); |
559 | 2.66k | h += sign_ret_val & (0x07FF); |
560 | | |
561 | 2.66k | h += (read_word1) >> (32 - first_offset); |
562 | 2.66k | sign_ret_val = *h; |
563 | 2.66k | } |
564 | 10.7k | bit_pos += ((sign_ret_val & 0x7fff) >> 11); |
565 | 10.7k | bit_pos = min(bit_pos, 31); |
566 | | |
567 | 10.7k | value = sign_ret_val & (0x07FF); |
568 | | |
569 | 10.7k | if (sign) { |
570 | 6.29k | WORD32 out0, out1, out2, out3; |
571 | 6.29k | WORD32 ampout0, ampout1, ampout2, ampout3; |
572 | 6.29k | WORD32 temp_word; |
573 | 6.29k | temp_word = read_word << bit_pos; |
574 | | |
575 | 6.29k | out0 = (ixheaac_extu(value, 24, 30)); |
576 | 6.29k | ampout0 = add_d(out0, *p_pul_arr++); |
577 | 6.29k | ampout0 = pow_table_q17[ampout0]; |
578 | | |
579 | 6.29k | if (out0) { |
580 | 3.61k | if (temp_word & 0x80000000) { |
581 | 975 | ampout0 = -ampout0; |
582 | 975 | } |
583 | 3.61k | temp_word = temp_word << 1; |
584 | 3.61k | bit_pos++; |
585 | 3.61k | } else { |
586 | 2.67k | ampout0 = -ampout0; |
587 | 2.67k | } |
588 | | |
589 | 6.29k | out1 = (ixheaac_extu(value, 26, 30)); |
590 | 6.29k | ampout1 = add_d(out1, *p_pul_arr++); |
591 | 6.29k | ampout1 = pow_table_q17[ampout1]; |
592 | 6.29k | if (out1) { |
593 | 2.89k | if (temp_word & 0x80000000) { |
594 | 326 | ampout1 = -(ampout1); |
595 | 326 | } |
596 | 2.89k | temp_word = temp_word << 1; |
597 | 2.89k | bit_pos++; |
598 | 3.39k | } else { |
599 | 3.39k | ampout1 = -ampout1; |
600 | 3.39k | } |
601 | 6.29k | out2 = (ixheaac_extu(value, 28, 30)); |
602 | 6.29k | ampout2 = add_d(out2, *p_pul_arr++); |
603 | 6.29k | ampout2 = pow_table_q17[ampout2]; |
604 | 6.29k | if (out2) { |
605 | 3.51k | if (temp_word & 0x80000000) { |
606 | 863 | ampout2 = -(ampout2); |
607 | 863 | } |
608 | 3.51k | temp_word = temp_word << 1; |
609 | 3.51k | bit_pos++; |
610 | 3.51k | } else { |
611 | 2.77k | ampout2 = -ampout2; |
612 | 2.77k | } |
613 | | |
614 | 6.29k | *x_invquant++ = ampout0; |
615 | 6.29k | *x_invquant++ = ampout1; |
616 | 6.29k | *x_invquant++ = ampout2; |
617 | | |
618 | 6.29k | out3 = (ixheaac_extu(value, 30, 30)); |
619 | 6.29k | ampout3 = add_d(out3, *p_pul_arr++); |
620 | 6.29k | ampout3 = pow_table_q17[ampout3]; |
621 | 6.29k | if (out3) { |
622 | 3.46k | if (temp_word & 0x80000000) { |
623 | 384 | ampout3 = -(ampout3); |
624 | 384 | } |
625 | 3.46k | temp_word = temp_word << 1; |
626 | 3.46k | bit_pos++; |
627 | 3.46k | } else { |
628 | 2.82k | ampout3 = -ampout3; |
629 | 2.82k | } |
630 | | |
631 | 6.29k | *x_invquant++ = ampout3; |
632 | 6.29k | } else { |
633 | 4.46k | ampres = *p_pul_arr++; |
634 | 4.46k | res = (ixheaacd_res_exts(value, 24, 30)); |
635 | 4.46k | if (res > 0) { |
636 | 407 | ampres = add_d(res, ampres); |
637 | 407 | ampres = pow_table_q17[ampres]; |
638 | 4.05k | } else { |
639 | 4.05k | ampres = sub_d(ampres, res); |
640 | 4.05k | ampres = pow_table_q17[ampres]; |
641 | 4.05k | ampres = -ampres; |
642 | 4.05k | } |
643 | 4.46k | res = (ixheaacd_res_exts(value, 26, 30)); |
644 | 4.46k | ampres1 = *p_pul_arr++; |
645 | 4.46k | if (res > 0) { |
646 | 190 | ampres1 = add_d(res, ampres1); |
647 | 190 | ampres1 = pow_table_q17[ampres1]; |
648 | 4.27k | } else { |
649 | 4.27k | ampres1 = sub_d(ampres1, res); |
650 | 4.27k | ampres1 = pow_table_q17[ampres1]; |
651 | 4.27k | ampres1 = -ampres1; |
652 | 4.27k | } |
653 | 4.46k | res = (ixheaacd_res_exts(value, 28, 30)); |
654 | 4.46k | ampres2 = *p_pul_arr++; |
655 | 4.46k | if (res > 0) { |
656 | 169 | ampres2 = add_d(res, ampres2); |
657 | 169 | ampres2 = pow_table_q17[ampres2]; |
658 | 4.29k | } else { |
659 | 4.29k | ampres2 = sub_d(ampres2, res); |
660 | 4.29k | ampres2 = pow_table_q17[ampres2]; |
661 | 4.29k | ampres2 = -ampres2; |
662 | 4.29k | } |
663 | 4.46k | res = (ixheaacd_res_exts(value, 30, 30)); |
664 | 4.46k | ampres3 = *p_pul_arr++; |
665 | 4.46k | if (res > 0) { |
666 | 115 | ampres3 = add_d(res, ampres3); |
667 | 115 | ampres3 = pow_table_q17[ampres3]; |
668 | 4.34k | } else { |
669 | 4.34k | ampres3 = sub_d(ampres3, res); |
670 | 4.34k | ampres3 = pow_table_q17[ampres3]; |
671 | 4.34k | ampres3 = -ampres3; |
672 | 4.34k | } |
673 | 4.46k | *x_invquant++ = ampres; |
674 | 4.46k | *x_invquant++ = ampres1; |
675 | 4.46k | *x_invquant++ = ampres2; |
676 | 4.46k | *x_invquant++ = ampres3; |
677 | 4.46k | } |
678 | 10.7k | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
679 | 10.7k | it_bit_buf->ptr_bit_buf_end); |
680 | 10.7k | } |
681 | | |
682 | 364 | it_bit_buf->ptr_read_next = ptr_read_next - 4; |
683 | 364 | it_bit_buf->bit_pos = bit_pos; |
684 | | |
685 | 364 | return 0; |
686 | 364 | } |
687 | | |
688 | | static PLATFORM_INLINE WORD ixheaacd_res_c_block_decode_huff_word2_2( |
689 | | ia_bit_buf_struct *it_bif_buf, WORD32 *qp, WORD16 *offsets, WORD no_bands, WORD group_no, |
690 | | const UWORD16 *h_ori, WORD32 *pow_table_q17, WORD32 sign, WORD32 maximum_bins_short) |
691 | | |
692 | 281 | { |
693 | 281 | WORD32 value; |
694 | 281 | WORD idx, grp_idx; |
695 | 281 | WORD len_idx; |
696 | | |
697 | 281 | WORD32 *qp_org = qp; |
698 | | |
699 | 281 | UWORD8 *ptr_read_next = it_bif_buf->ptr_read_next; |
700 | 281 | WORD32 bit_pos = it_bif_buf->bit_pos; |
701 | 281 | WORD32 read_word = ixheaacd_res_aac_showbits_32(ptr_read_next); |
702 | 281 | ptr_read_next += 4; |
703 | | |
704 | 1.04k | do { |
705 | 1.04k | len_idx = offsets[1] - offsets[0]; |
706 | 1.04k | grp_idx = group_no; |
707 | 7.12k | do { |
708 | 7.12k | qp += offsets[0]; |
709 | 7.12k | idx = len_idx; |
710 | 30.3k | do { |
711 | 30.3k | UWORD16 first_offset; |
712 | 30.3k | WORD16 sign_ret_val; |
713 | 30.3k | UWORD32 read_word1; |
714 | 30.3k | UWORD16 *h; |
715 | | |
716 | 30.3k | read_word1 = read_word << bit_pos; |
717 | | |
718 | 30.3k | h = (UWORD16 *)h_ori; |
719 | 30.3k | h += (read_word1) >> (27); |
720 | 30.3k | sign_ret_val = *h; |
721 | | |
722 | 30.3k | first_offset = 5; |
723 | 35.1k | while (sign_ret_val > 0) { |
724 | 4.82k | bit_pos += first_offset; |
725 | 4.82k | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
726 | 4.82k | it_bif_buf->ptr_bit_buf_end); |
727 | 4.82k | read_word1 = (read_word1) << (first_offset); |
728 | | |
729 | 4.82k | first_offset = (sign_ret_val >> 11); |
730 | 4.82k | h += sign_ret_val & (0x07FF); |
731 | | |
732 | 4.82k | h += (read_word1) >> (32 - first_offset); |
733 | 4.82k | sign_ret_val = *h; |
734 | 4.82k | } |
735 | 30.3k | bit_pos += ((sign_ret_val & 0x7fff) >> 11); |
736 | 30.3k | bit_pos = min(bit_pos, 31); |
737 | 30.3k | value = sign_ret_val & (0x07FF); |
738 | | |
739 | 30.3k | if (sign) { |
740 | 18.0k | WORD32 temp_word; |
741 | 18.0k | temp_word = read_word << bit_pos; |
742 | | |
743 | 18.0k | *qp++ = ixheaacd_res_extract_signed_symbol(value, 24, 28, pow_table_q17, &temp_word, |
744 | 18.0k | &bit_pos); |
745 | 18.0k | *qp++ = ixheaacd_res_extract_signed_symbol(value, 28, 28, pow_table_q17, &temp_word, |
746 | 18.0k | &bit_pos); |
747 | 18.0k | } else { |
748 | 12.2k | *qp++ = ixheaacd_res_extract_symbol(value, 24, 28, pow_table_q17); |
749 | 12.2k | *qp++ = ixheaacd_res_extract_symbol(value, 28, 28, pow_table_q17); |
750 | 12.2k | } |
751 | | |
752 | 30.3k | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
753 | 30.3k | it_bif_buf->ptr_bit_buf_end); |
754 | 30.3k | idx -= 2; |
755 | 30.3k | } while (idx != 0); |
756 | | |
757 | 7.12k | qp += (maximum_bins_short - offsets[1]); |
758 | 7.12k | grp_idx--; |
759 | 7.12k | } while (grp_idx != 0); |
760 | | |
761 | 1.04k | offsets++; |
762 | 1.04k | qp = qp_org; |
763 | 1.04k | no_bands--; |
764 | 1.04k | } while (no_bands >= 0); |
765 | | |
766 | 281 | it_bif_buf->ptr_read_next = ptr_read_next - 4; |
767 | 281 | it_bif_buf->bit_pos = bit_pos; |
768 | | |
769 | 281 | return 0; |
770 | 281 | } |
771 | | |
772 | | static PLATFORM_INLINE WORD ixheaacd_res_c_block_decode_huff_word2_2_lb( |
773 | | ia_bit_buf_struct *it_bit_buf, WORD32 len, const UWORD16 *h_ori, WORD32 *x_invquant, |
774 | 387 | WORD32 *pow_table_q17, WORD8 *p_pul_arr, WORD32 sign) { |
775 | 387 | WORD32 value, res, ampres; |
776 | 387 | WORD idx; |
777 | | |
778 | 387 | UWORD8 *ptr_read_next = it_bit_buf->ptr_read_next; |
779 | 387 | WORD32 bit_pos = it_bit_buf->bit_pos; |
780 | 387 | WORD32 read_word = ixheaacd_res_aac_showbits_32(ptr_read_next); |
781 | 387 | ptr_read_next += 4; |
782 | | |
783 | 15.5k | for (idx = len; idx != 0; idx -= 2) { |
784 | 15.1k | { |
785 | 15.1k | UWORD16 first_offset; |
786 | 15.1k | WORD16 sign_ret_val; |
787 | 15.1k | UWORD32 read_word1; |
788 | 15.1k | UWORD16 *h; |
789 | | |
790 | 15.1k | read_word1 = read_word << bit_pos; |
791 | | |
792 | 15.1k | h = (UWORD16 *)h_ori; |
793 | 15.1k | h += (read_word1) >> (27); |
794 | 15.1k | sign_ret_val = *h; |
795 | | |
796 | 15.1k | first_offset = 5; |
797 | 17.6k | while (sign_ret_val > 0) { |
798 | 2.46k | bit_pos += first_offset; |
799 | 2.46k | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
800 | 2.46k | it_bit_buf->ptr_bit_buf_end); |
801 | 2.46k | read_word1 = (read_word1) << (first_offset); |
802 | | |
803 | 2.46k | first_offset = (sign_ret_val >> 11); |
804 | 2.46k | h += sign_ret_val & (0x07FF); |
805 | | |
806 | 2.46k | h += (read_word1) >> (32 - first_offset); |
807 | 2.46k | sign_ret_val = *h; |
808 | 2.46k | } |
809 | 15.1k | bit_pos += ((sign_ret_val & 0x7fff) >> 11); |
810 | 15.1k | bit_pos = min(bit_pos, 31); |
811 | | |
812 | 15.1k | value = sign_ret_val & (0x07FF); |
813 | 15.1k | } |
814 | | |
815 | 15.1k | if (sign) { |
816 | 11.2k | WORD32 out0, out1, temp_word; |
817 | 11.2k | WORD32 ampout0, ampout1; |
818 | | |
819 | 11.2k | ampout0 = *p_pul_arr++; |
820 | 11.2k | ampout1 = *p_pul_arr++; |
821 | | |
822 | 11.2k | out0 = value & 0xf0; |
823 | | |
824 | 11.2k | ampout0 = add_d(ampout0, (UWORD32)out0 >> 4); |
825 | 11.2k | ampout0 = pow_table_q17[ampout0]; |
826 | | |
827 | 11.2k | out1 = value & 0xf; |
828 | 11.2k | ampout1 = add_d(out1, ampout1); |
829 | 11.2k | ampout1 = pow_table_q17[ampout1]; |
830 | | |
831 | 11.2k | temp_word = read_word << bit_pos; |
832 | 11.2k | if (out0) { |
833 | 7.96k | if (temp_word & 0x80000000) { |
834 | 2.45k | ampout0 = -(ampout0); |
835 | 2.45k | } |
836 | 7.96k | bit_pos++; |
837 | 7.96k | temp_word = temp_word << 1; |
838 | 7.96k | } else { |
839 | 3.29k | ampout0 = -(ampout0); |
840 | 3.29k | } |
841 | 11.2k | if (out1) { |
842 | 8.24k | if (temp_word & 0x80000000) { |
843 | 2.06k | ampout1 = -(ampout1); |
844 | 2.06k | } |
845 | 8.24k | bit_pos++; |
846 | 8.24k | } else { |
847 | 3.01k | ampout1 = -(ampout1); |
848 | 3.01k | } |
849 | 11.2k | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
850 | 11.2k | it_bit_buf->ptr_bit_buf_end); |
851 | 11.2k | *x_invquant++ = ampout0; |
852 | 11.2k | *x_invquant++ = ampout1; |
853 | 11.2k | } else { |
854 | 3.91k | res = ((value << 24) >> 28); |
855 | 3.91k | ampres = *p_pul_arr++; |
856 | 3.91k | if (res > 0) { |
857 | 213 | ampres = add_d(res, ampres); |
858 | 213 | *x_invquant++ = pow_table_q17[ampres]; |
859 | 3.70k | } else { |
860 | 3.70k | ampres = sub_d(ampres, res); |
861 | 3.70k | ampres = pow_table_q17[ampres]; |
862 | 3.70k | *x_invquant++ = -ampres; |
863 | 3.70k | } |
864 | | |
865 | 3.91k | res = ((value << 28) >> 28); |
866 | 3.91k | value = *p_pul_arr++; |
867 | 3.91k | if (res > 0) { |
868 | 248 | ampres = add_d(res, value); |
869 | 248 | *x_invquant++ = pow_table_q17[ampres]; |
870 | 3.67k | } else { |
871 | 3.67k | ampres = sub_d(value, res); |
872 | 3.67k | ampres = pow_table_q17[ampres]; |
873 | 3.67k | *x_invquant++ = -ampres; |
874 | 3.67k | } |
875 | 3.91k | } |
876 | 15.1k | ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, |
877 | 15.1k | it_bit_buf->ptr_bit_buf_end); |
878 | 15.1k | } |
879 | 387 | it_bit_buf->ptr_read_next = ptr_read_next - 4; |
880 | 387 | it_bit_buf->bit_pos = bit_pos; |
881 | | |
882 | 387 | return 0; |
883 | 387 | } |
884 | | |
885 | | WORD ixheaacd_res_c_block_decode_huff_word_all( |
886 | | ia_bit_buf_struct *it_bit_buf, WORD32 code_no, WORD32 *quantized_coef, WORD16 *band_offsets, |
887 | | WORD start, WORD band, WORD group_no, ia_mps_dec_residual_aac_tables_struct *aac_tables_ptr, |
888 | 827 | WORD32 maximum_bins_short) { |
889 | 827 | WORD ret_val = 0; |
890 | 827 | WORD start_bit_pos = it_bit_buf->bit_pos; |
891 | 827 | UWORD8 *start_read_pos = it_bit_buf->ptr_read_next; |
892 | 827 | const UWORD16 *h_ori = (UWORD16 *)(aac_tables_ptr->code_book[code_no]); |
893 | 827 | WORD32 *pow_table = (WORD32 *)aac_tables_ptr->res_block_tables_ptr->pow_table_q17; |
894 | 827 | WORD32 no_bands = band - start - 1; |
895 | 827 | WORD16 *p_band_off = band_offsets + start; |
896 | | |
897 | 827 | if (code_no == 11) { |
898 | 107 | const UWORD16 *h_ori = aac_tables_ptr->res_huffmann_tables_ptr->huffman_codebook_11; |
899 | 107 | ret_val = |
900 | 107 | ixheaacd_res_c_block_decode_huff_word1(it_bit_buf, quantized_coef, p_band_off, no_bands, |
901 | 107 | group_no, h_ori, pow_table, maximum_bins_short); |
902 | 720 | } else if (code_no <= 4) { |
903 | 439 | WORD32 sign = 0; |
904 | | |
905 | 439 | if (code_no > 2) sign = 1; |
906 | 439 | ret_val = ixheaacd_res_c_block_decode_huff_word2_4(it_bit_buf, quantized_coef, p_band_off, |
907 | 439 | no_bands, group_no, h_ori, pow_table, sign, |
908 | 439 | maximum_bins_short); |
909 | 439 | } |
910 | | |
911 | 281 | else if (code_no <= 10) { |
912 | 281 | WORD32 sign = 0; |
913 | | |
914 | 281 | if (code_no > 6) sign = 1; |
915 | 281 | ret_val = ixheaacd_res_c_block_decode_huff_word2_2(it_bit_buf, quantized_coef, p_band_off, |
916 | 281 | no_bands, group_no, h_ori, pow_table, sign, |
917 | 281 | maximum_bins_short); |
918 | 281 | } |
919 | 827 | { |
920 | 827 | WORD bits_cons; |
921 | 827 | bits_cons = (WORD)(((it_bit_buf->ptr_read_next - start_read_pos) << 3) + |
922 | 827 | (it_bit_buf->bit_pos - start_bit_pos)); |
923 | 827 | it_bit_buf->cnt_bits -= bits_cons; |
924 | 827 | } |
925 | 827 | return ret_val; |
926 | 827 | } |
927 | | |
928 | | WORD ixheaacd_res_c_block_decode_huff_word_all_lb( |
929 | | ia_bit_buf_struct *it_bit_buf, WORD32 code_no, WORD32 len, |
930 | 836 | ia_mps_dec_residual_aac_tables_struct *aac_tables_ptr, WORD32 *x_invquant, WORD8 *p_pul_arr) { |
931 | 836 | WORD ret_val = 0; |
932 | 836 | WORD start_bit_pos = it_bit_buf->bit_pos; |
933 | 836 | WORD32 *pow_table = (WORD32 *)aac_tables_ptr->res_block_tables_ptr->pow_table_q17; |
934 | 836 | UWORD8 *start_read_pos = it_bit_buf->ptr_read_next; |
935 | | |
936 | 836 | const UWORD16 *h_ori = (UWORD16 *)(aac_tables_ptr->code_book[code_no]); |
937 | | |
938 | 836 | if (code_no == 11) { |
939 | 85 | const UWORD16 *h_ori = aac_tables_ptr->res_huffmann_tables_ptr->huffman_codebook_11; |
940 | 85 | ret_val = ixheaacd_res_c_block_decode_huff_word1_lb(it_bit_buf, len, h_ori, x_invquant, |
941 | 85 | pow_table, p_pul_arr); |
942 | 751 | } else if (code_no <= 4) { |
943 | 364 | WORD32 sign = 0; |
944 | 364 | if (code_no > 2) sign = 1; |
945 | 364 | ret_val = ixheaacd_res_c_block_decode_huff_word2_4_lb(it_bit_buf, len, h_ori, x_invquant, |
946 | 364 | pow_table, p_pul_arr, sign); |
947 | 387 | } else if (code_no <= 10) { |
948 | 387 | WORD32 sign = 0; |
949 | 387 | if (code_no > 6) sign = 1; |
950 | 387 | ret_val = ixheaacd_res_c_block_decode_huff_word2_2_lb(it_bit_buf, len, h_ori, x_invquant, |
951 | 387 | pow_table, p_pul_arr, sign); |
952 | 387 | } |
953 | | |
954 | 836 | { |
955 | 836 | WORD bits_cons; |
956 | 836 | if (it_bit_buf->bit_pos <= 7) { |
957 | 332 | bits_cons = (WORD)(((it_bit_buf->ptr_read_next - start_read_pos) << 3) + |
958 | 332 | (it_bit_buf->bit_pos - start_bit_pos)); |
959 | 332 | it_bit_buf->cnt_bits -= bits_cons; |
960 | 504 | } else { |
961 | 504 | it_bit_buf->ptr_read_next += (it_bit_buf->bit_pos) >> 3; |
962 | 504 | it_bit_buf->bit_pos = it_bit_buf->bit_pos & 0x7; |
963 | | |
964 | 504 | bits_cons = (WORD)(((it_bit_buf->ptr_read_next - start_read_pos) << 3) + |
965 | 504 | ((it_bit_buf->bit_pos - start_bit_pos))); |
966 | 504 | it_bit_buf->cnt_bits -= bits_cons; |
967 | 504 | } |
968 | 836 | } |
969 | 836 | return ret_val; |
970 | 836 | } |
971 | | |
972 | | static VOID ixheaacd_res_apply_one_scf(WORD32 scale_factor, WORD32 *x_invquant, WORD32 end, |
973 | 39.4k | WORD32 *scale_table_ptr) { |
974 | 39.4k | WORD32 j; |
975 | | |
976 | 39.4k | WORD32 temp_1; |
977 | 39.4k | WORD32 q_factor; |
978 | 39.4k | WORD32 buffer1; |
979 | 39.4k | WORD16 scale_short; |
980 | | |
981 | 39.4k | if (scale_factor < 24) { |
982 | 91.2k | for (j = end; j > 0; j--) { |
983 | 82.1k | *x_invquant++ = 0; |
984 | 82.1k | } |
985 | 30.4k | } else { |
986 | 30.4k | WORD32 shift; |
987 | 30.4k | q_factor = 37 - (scale_factor >> 2); |
988 | | |
989 | 30.4k | scale_short = scale_table_ptr[(scale_factor & 0x0003)]; |
990 | | |
991 | 30.4k | shift = q_factor; |
992 | | |
993 | 30.4k | if (shift > 0) { |
994 | 4.23k | if (scale_short == (WORD16)0x8000) { |
995 | 0 | for (j = end; j > 0; j--) { |
996 | 0 | temp_1 = *x_invquant; |
997 | |
|
998 | 0 | buffer1 = ixheaac_mult32x16in32_shl_sat(temp_1, scale_short); |
999 | 0 | buffer1 = ixheaac_shr32(buffer1, shift); |
1000 | 0 | *x_invquant++ = buffer1; |
1001 | 0 | } |
1002 | 4.23k | } else { |
1003 | 52.9k | for (j = end; j > 0; j--) { |
1004 | 48.6k | temp_1 = *x_invquant; |
1005 | | |
1006 | 48.6k | buffer1 = ixheaac_mult32x16in32_shl(temp_1, scale_short); |
1007 | | |
1008 | 48.6k | buffer1 = ixheaac_shr32(buffer1, shift); |
1009 | 48.6k | *x_invquant++ = buffer1; |
1010 | 48.6k | } |
1011 | 4.23k | } |
1012 | 26.2k | } else { |
1013 | 26.2k | shift = -shift; |
1014 | 26.2k | if (shift > 0) { |
1015 | 25.8k | if (scale_short == (WORD16)0x8000) { |
1016 | 0 | for (j = end; j > 0; j--) { |
1017 | 0 | temp_1 = *x_invquant; |
1018 | 0 | temp_1 = ixheaac_shl32(temp_1, shift - 1); |
1019 | |
|
1020 | 0 | buffer1 = ixheaac_mult32x16in32_shl_sat(temp_1, scale_short); |
1021 | |
|
1022 | 0 | buffer1 = ixheaac_shl32(buffer1, 1); |
1023 | 0 | *x_invquant++ = buffer1; |
1024 | 0 | } |
1025 | 25.8k | } else { |
1026 | 242k | for (j = end; j > 0; j--) { |
1027 | 216k | temp_1 = *x_invquant; |
1028 | 216k | temp_1 = ixheaac_shl32(temp_1, shift - 1); |
1029 | | |
1030 | 216k | buffer1 = ixheaac_mult32x16in32_shl(temp_1, scale_short); |
1031 | | |
1032 | 216k | buffer1 = ixheaac_shl32(buffer1, 1); |
1033 | 216k | *x_invquant++ = buffer1; |
1034 | 216k | } |
1035 | 25.8k | } |
1036 | 25.8k | } else { |
1037 | 351 | if (scale_short == (WORD16)0x8000) { |
1038 | 0 | for (j = end; j > 0; j--) { |
1039 | 0 | temp_1 = *x_invquant; |
1040 | |
|
1041 | 0 | buffer1 = ixheaac_mult32x16in32_shl_sat(temp_1, scale_short); |
1042 | |
|
1043 | 0 | *x_invquant++ = buffer1; |
1044 | 0 | } |
1045 | 351 | } else { |
1046 | 4.61k | for (j = end; j > 0; j--) { |
1047 | 4.26k | temp_1 = *x_invquant; |
1048 | | |
1049 | 4.26k | buffer1 = ixheaac_mult32x16in32_shl(temp_1, scale_short); |
1050 | | |
1051 | 4.26k | *x_invquant++ = buffer1; |
1052 | 4.26k | } |
1053 | 351 | } |
1054 | 351 | } |
1055 | 26.2k | } |
1056 | 30.4k | } |
1057 | 39.4k | } |
1058 | | |
1059 | | VOID ixheaacd_res_apply_scfs(WORD32 *x_invquant, WORD16 *sc_factor, WORD t_bands, WORD8 *offset, |
1060 | 4.68k | WORD32 *scale_table_ptr) { |
1061 | 4.68k | WORD32 i; |
1062 | 4.68k | WORD16 scale_factor; |
1063 | | |
1064 | 44.1k | for (i = t_bands - 1; i >= 0; i--) { |
1065 | 39.4k | scale_factor = *sc_factor++; |
1066 | 39.4k | ixheaacd_res_apply_one_scf(scale_factor, x_invquant, *offset, scale_table_ptr); |
1067 | 39.4k | x_invquant += *offset; |
1068 | 39.4k | offset++; |
1069 | 39.4k | } |
1070 | 4.68k | } |