1 /******************************************************************************
2 * *
3 * Copyright (C) 2018 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 "ixheaacd_sbr_common.h"
21 #include <ixheaacd_type_def.h>
22
23 #include "ixheaacd_constants.h"
24 #include <ixheaacd_basic_ops32.h>
25 #include <ixheaacd_basic_ops16.h>
26 #include <ixheaacd_basic_ops40.h>
27 #include "ixheaacd_basic_ops.h"
28 #include "ixheaacd_common_rom.h"
29 #include "ixheaacd_basic_funcs.h"
30 #include "ixheaacd_defines.h"
31 #include <ixheaacd_aac_rom.h>
32 #include "ixheaacd_bitbuffer.h"
33 #include "ixheaacd_intrinsics.h"
34 #include "ixheaacd_pulsedata.h"
35
36 #include "ixheaacd_pns.h"
37 #include "ixheaacd_drc_data_struct.h"
38
39 #include "ixheaacd_lt_predict.h"
40
41 #include "ixheaacd_channelinfo.h"
42 #include "ixheaacd_drc_dec.h"
43
44 #include "ixheaacd_block.h"
45 #include "ixheaacd_channel.h"
46
47 #include <ixheaacd_basic_op.h>
48
49 #include "ixheaacd_tns.h"
50 #include "ixheaacd_sbrdecoder.h"
51 #include "ixheaacd_error_codes.h"
52
53 #include "ixheaacd_audioobjtypes.h"
54 #include "ixheaacd_latmdemux.h"
55
56 #include "ixheaacd_aacdec.h"
57
ixheaacd_shr32_drc(WORD32 a,WORD32 b)58 static PLATFORM_INLINE WORD32 ixheaacd_shr32_drc(WORD32 a, WORD32 b) {
59 WORD32 out_val;
60
61 b = ((UWORD32)(b << 24) >> 24);
62 if (b >= 31) {
63 if (a < 0)
64 out_val = -1;
65 else
66 out_val = 0;
67 } else {
68 a += (1 << (b - 1));
69 out_val = (WORD32)a >> b;
70 }
71
72 return out_val;
73 }
74
ixheaacd_mult32x16in32_drc(WORD32 a,WORD16 b)75 static PLATFORM_INLINE WORD32 ixheaacd_mult32x16in32_drc(WORD32 a, WORD16 b) {
76 WORD32 result;
77 WORD64 temp_result;
78
79 temp_result = (WORD64)a * (WORD64)b;
80
81 if (temp_result < (WORD64)MIN_32)
82 result = MIN_32;
83
84 else if (temp_result > (WORD64)MAX_32)
85 result = MAX_32;
86
87 else
88 result = (WORD32)(temp_result);
89
90 return (result);
91 }
ixheaacd_mac32x16in32_drc(WORD32 a,WORD32 b,WORD16 c)92 static PLATFORM_INLINE WORD32 ixheaacd_mac32x16in32_drc(WORD32 a, WORD32 b,
93 WORD16 c) {
94 WORD32 acc;
95
96 acc = ixheaacd_mult32x16in32_drc(b, c);
97
98 acc = ixheaacd_add32_sat(a, acc);
99
100 return acc;
101 }
102
103 WORD32 ixheaacd_cnt_leading_ones(WORD32 a);
104
ixheaacd_huff_sfb_table(WORD32 it_bit_buff,WORD16 * huff_index,WORD16 * len,const UWORD16 * code_book_tbl,const UWORD32 * idx_table)105 VOID ixheaacd_huff_sfb_table(WORD32 it_bit_buff, WORD16 *huff_index,
106 WORD16 *len, const UWORD16 *code_book_tbl,
107 const UWORD32 *idx_table) {
108 UWORD32 temp = 0;
109 UWORD32 temp1 = 0;
110 WORD32 found = 0;
111 UWORD32 mask = 0x80000000;
112
113 WORD32 leading_ones;
114 WORD32 max_len;
115 WORD32 ixheaacd_drc_offset = 0;
116 WORD32 length;
117 UWORD32 code_word;
118 WORD32 len_end;
119
120 max_len = code_book_tbl[0];
121 mask = mask - (1 << (31 - max_len));
122 mask = mask << 1;
123
124 temp = (UWORD32)((it_bit_buff & mask));
125
126 len_end = code_book_tbl[0];
127 leading_ones = ixheaacd_cnt_leading_ones(temp);
128 do {
129 ixheaacd_drc_offset = (idx_table[leading_ones] >> 20) & 0x1ff;
130 length = code_book_tbl[ixheaacd_drc_offset + 1] & 0x1f;
131 code_word = idx_table[leading_ones] & 0xfffff;
132 temp1 = temp >> (32 - length);
133 if (temp1 <= code_word) {
134 ixheaacd_drc_offset = ixheaacd_drc_offset - (code_word - temp1);
135 found = 1;
136 } else {
137 len_end = len_end + ((idx_table[leading_ones] >> 29) & 0x7);
138 leading_ones = len_end;
139 }
140 } while (!found);
141 *huff_index = code_book_tbl[ixheaacd_drc_offset + 1] >> 5;
142 *len = length;
143 }
144
ixheaacd_inverse_quantize(WORD32 * x_invquant,WORD no_band,WORD32 * ixheaacd_pow_table_Q13,WORD8 * scratch_in)145 VOID ixheaacd_inverse_quantize(WORD32 *x_invquant, WORD no_band,
146 WORD32 *ixheaacd_pow_table_Q13,
147 WORD8 *scratch_in) {
148 WORD32 j;
149 WORD32 temp;
150 WORD32 q_abs;
151
152 for (j = no_band - 1; j >= 0; j--) {
153 q_abs = *scratch_in++;
154 temp = (ixheaacd_pow_table_Q13[q_abs]);
155 *x_invquant++ = -temp;
156 }
157 }
158
ixheaacd_huffman_dec_word1(ia_bit_buf_struct * it_bit_buff,WORD32 * spec_coef,WORD16 * offsets,WORD no_bands,WORD group_len,const UWORD16 * code_book_tbl,WORD32 * ixheaacd_pow_table_Q13,const UWORD32 * idx_table)159 static PLATFORM_INLINE WORD ixheaacd_huffman_dec_word1(
160 ia_bit_buf_struct *it_bit_buff, WORD32 *spec_coef, WORD16 *offsets,
161 WORD no_bands, WORD group_len, const UWORD16 *code_book_tbl,
162 WORD32 *ixheaacd_pow_table_Q13, const UWORD32 *idx_table) {
163 WORD32 sp1, sp2;
164 WORD32 flush_cw;
165 WORD32 i, value, norm_val, off;
166 WORD idx, grp_idx;
167 WORD32 out1, out2;
168 WORD32 err_code = 0;
169 WORD len_idx = 0;
170 UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next;
171 WORD32 bit_pos = it_bit_buff->bit_pos;
172 WORD32 read_word = ixheaacd_aac_showbits_32(ptr_read_next);
173 WORD16 index, length;
174 ptr_read_next += 4;
175
176 do {
177 len_idx = offsets[1] - offsets[0];
178 grp_idx = group_len;
179
180 do {
181 spec_coef = spec_coef + offsets[0];
182 idx = len_idx;
183 do {
184 {
185 UWORD32 read_word1;
186
187 read_word1 = read_word << bit_pos;
188 ixheaacd_huff_sfb_table(read_word1, &index, &length, code_book_tbl,
189 idx_table);
190 bit_pos += length;
191 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
192 it_bit_buff->ptr_bit_buf_end);
193 }
194
195 out1 = index / 17;
196 out2 = index - out1 * 17;
197 flush_cw = read_word << bit_pos;
198
199 sp1 = out1;
200 sp2 = out2;
201
202 if (out1) {
203 if (flush_cw & 0x80000000) {
204 out1 = -out1;
205 }
206 bit_pos++;
207 flush_cw = (WORD32)flush_cw << 1;
208 }
209
210 if (out2) {
211 bit_pos++;
212 if (flush_cw & 0x80000000) {
213 out2 = -out2;
214 }
215 }
216 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
217 it_bit_buff->ptr_bit_buf_end);
218
219 if (sp1 == 16) {
220 i = 4;
221 value = ixheaacd_extu(read_word, bit_pos, 23);
222 value = value | 0xfffffe00;
223 norm_val = ixheaacd_norm32(value);
224
225 i += (norm_val - 22);
226 bit_pos += (norm_val - 21);
227 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
228 it_bit_buff->ptr_bit_buf_end);
229
230 off = ixheaacd_extu(read_word, bit_pos, 32 - i);
231
232 bit_pos += i;
233
234 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
235 it_bit_buff->ptr_bit_buf_end);
236 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
237 it_bit_buff->ptr_bit_buf_end);
238
239 i = off + ((WORD32)1 << i);
240
241 if (i <= IQ_TABLE_SIZE_HALF)
242 i = ixheaacd_pow_table_Q13[i];
243 else {
244 err_code |= ixheaacd_inv_quant(&i, ixheaacd_pow_table_Q13);
245 }
246
247 if (out1 < 0) {
248 out1 = -i;
249 } else {
250 out1 = i;
251 }
252 *spec_coef++ = out1;
253 } else {
254 if (out1 <= 0) {
255 out1 = -out1;
256 out1 = ixheaacd_pow_table_Q13[out1];
257 *spec_coef++ = -out1;
258 } else {
259 out1 = ixheaacd_pow_table_Q13[out1];
260 *spec_coef++ = out1;
261 }
262 }
263
264 if (sp2 == 16) {
265 i = 4;
266 value = ixheaacd_extu(read_word, bit_pos, 23);
267 value = value | 0xfffffe00;
268 norm_val = ixheaacd_norm32(value);
269
270 i += (norm_val - 22);
271
272 bit_pos += (norm_val - 21);
273 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
274 it_bit_buff->ptr_bit_buf_end);
275
276 off = ixheaacd_extu(read_word, bit_pos, 32 - i);
277
278 bit_pos += i;
279
280 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
281 it_bit_buff->ptr_bit_buf_end);
282 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
283 it_bit_buff->ptr_bit_buf_end);
284
285 i = off + ((WORD32)1 << i);
286
287 if (i <= IQ_TABLE_SIZE_HALF)
288 i = ixheaacd_pow_table_Q13[i];
289 else {
290 err_code |= ixheaacd_inv_quant(&i, ixheaacd_pow_table_Q13);
291 }
292
293 if (out2 < 0) {
294 out2 = -i;
295 } else {
296 out2 = i;
297 }
298 *spec_coef++ = out2;
299 } else {
300 if (out2 <= 0) {
301 out2 = -out2;
302 out2 = ixheaacd_pow_table_Q13[out2];
303 *spec_coef++ = -out2;
304 } else {
305 out2 = ixheaacd_pow_table_Q13[out2];
306 *spec_coef++ = out2;
307 }
308 }
309
310 idx -= 2;
311 } while (idx != 0);
312
313 spec_coef += (MAX_BINS_SHORT - offsets[1]);
314 grp_idx--;
315 } while (grp_idx != 0);
316
317 offsets++;
318 spec_coef -= (MAX_BINS_SHORT * group_len);
319 no_bands--;
320 } while (no_bands >= 0);
321
322 it_bit_buff->bit_pos = bit_pos;
323 it_bit_buff->ptr_read_next = ptr_read_next - 4;
324
325 return err_code;
326 }
327
ixheaacd_huffman_dec_word2_11(ia_bit_buf_struct * it_bit_buff,WORD32 width,const UWORD16 * code_book_tbl,WORD32 * x_invquant,WORD32 * ixheaacd_pow_table_Q13,WORD8 * ptr_scratch,const UWORD32 * idx_table)328 static PLATFORM_INLINE WORD ixheaacd_huffman_dec_word2_11(
329 ia_bit_buf_struct *it_bit_buff, WORD32 width, const UWORD16 *code_book_tbl,
330 WORD32 *x_invquant, WORD32 *ixheaacd_pow_table_Q13, WORD8 *ptr_scratch,
331 const UWORD32 *idx_table) {
332 WORD32 sp1, sp2;
333 WORD32 flush_cw;
334 WORD32 i, value, norm_val, off;
335 WORD idx;
336 WORD32 out1, out2;
337 WORD32 err_code = 0;
338 WORD16 index, length;
339 UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next;
340 WORD32 bit_pos = it_bit_buff->bit_pos;
341 WORD32 read_word = ixheaacd_aac_showbits_32(ptr_read_next);
342 ptr_read_next += 4;
343
344 for (idx = width; idx != 0; idx -= 2) {
345 {
346 UWORD32 read_word1;
347
348 read_word1 = read_word << bit_pos;
349 ixheaacd_huff_sfb_table(read_word1, &index, &length, code_book_tbl,
350 idx_table);
351 bit_pos += length;
352 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
353 it_bit_buff->ptr_bit_buf_end);
354 }
355
356 flush_cw = read_word << bit_pos;
357 out1 = index / 17;
358 out2 = index - out1 * 17;
359 sp1 = out1;
360
361 if (out1) {
362 if (flush_cw & 0x80000000) {
363 out1 = -out1;
364 }
365
366 bit_pos++;
367 flush_cw = (WORD32)flush_cw << 1;
368 }
369
370 sp2 = out2;
371 if (out2) {
372 bit_pos++;
373 if (flush_cw & 0x80000000) {
374 out2 = -out2;
375 }
376 }
377
378 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
379 it_bit_buff->ptr_bit_buf_end);
380
381 if (sp1 == 16) {
382 i = 4;
383 value = ixheaacd_extu(read_word, bit_pos, 23);
384 value = value | 0xfffffe00;
385 norm_val = ixheaacd_norm32(value);
386 i += (norm_val - 22);
387 bit_pos += (norm_val - 21);
388
389 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
390 it_bit_buff->ptr_bit_buf_end);
391
392 off = ixheaacd_extu(read_word, bit_pos, 32 - i);
393
394 bit_pos += i;
395 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
396 it_bit_buff->ptr_bit_buf_end);
397
398 value = *ptr_scratch++;
399
400 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
401 it_bit_buff->ptr_bit_buf_end);
402 i = off + ((WORD32)1 << i);
403 i += value;
404
405 if (i <= IQ_TABLE_SIZE_HALF)
406 i = ixheaacd_pow_table_Q13[i];
407 else {
408 err_code |= ixheaacd_inv_quant(&i, ixheaacd_pow_table_Q13);
409 }
410 if (out1 < 0) {
411 i = -i;
412 }
413 *x_invquant++ = i;
414 } else {
415 WORD8 temp = *ptr_scratch++;
416 if (out1 <= 0) {
417 out1 = temp - out1;
418 out1 = ixheaacd_pow_table_Q13[out1];
419 *x_invquant++ = -out1;
420 } else {
421 out1 += temp;
422 out1 = ixheaacd_pow_table_Q13[out1];
423 *x_invquant++ = out1;
424 }
425 }
426
427 if (sp2 == 16) {
428 i = 4;
429 value = ixheaacd_extu(read_word, bit_pos, 23);
430 value = value | 0xfffffe00;
431 norm_val = ixheaacd_norm32(value);
432
433 i += (norm_val - 22);
434
435 bit_pos += (norm_val - 21);
436 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
437 it_bit_buff->ptr_bit_buf_end);
438
439 off = ixheaacd_extu(read_word, bit_pos, 32 - i);
440
441 bit_pos += i;
442 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
443 it_bit_buff->ptr_bit_buf_end);
444 value = *ptr_scratch++;
445 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
446 it_bit_buff->ptr_bit_buf_end);
447
448 i = off + ((WORD32)1 << i);
449 i += value;
450 if (i <= IQ_TABLE_SIZE_HALF)
451 i = ixheaacd_pow_table_Q13[i];
452 else {
453 err_code |= ixheaacd_inv_quant(&i, ixheaacd_pow_table_Q13);
454 }
455
456 if (out2 < 0) {
457 i = -i;
458 }
459 *x_invquant++ = i;
460
461 } else {
462 WORD8 temp = *ptr_scratch++;
463 if (out2 <= 0) {
464 out2 = temp - out2;
465 out2 = ixheaacd_pow_table_Q13[out2];
466 *x_invquant++ = -out2;
467 } else {
468 out2 += temp;
469 out2 = ixheaacd_pow_table_Q13[out2];
470 *x_invquant++ = out2;
471 }
472 }
473 }
474
475 it_bit_buff->ptr_read_next = ptr_read_next - 4;
476 it_bit_buff->bit_pos = bit_pos;
477
478 return err_code;
479 }
480
ixheaacd_huffman_dec_quad(ia_bit_buf_struct * it_bit_buff,WORD32 * spec_coef,WORD16 * offsets,WORD no_bands,WORD group_len,const UWORD16 * code_book_tbl,WORD32 * ixheaacd_pow_table_Q13,WORD32 tbl_sign,const UWORD32 * idx_table)481 static PLATFORM_INLINE WORD ixheaacd_huffman_dec_quad(
482 ia_bit_buf_struct *it_bit_buff, WORD32 *spec_coef, WORD16 *offsets,
483 WORD no_bands, WORD group_len, const UWORD16 *code_book_tbl,
484 WORD32 *ixheaacd_pow_table_Q13, WORD32 tbl_sign, const UWORD32 *idx_table) {
485 WORD idx, grp_idx;
486 WORD idx_len;
487 WORD32 *spec_orig;
488 WORD16 index, length;
489 UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next;
490 WORD32 bit_pos = it_bit_buff->bit_pos;
491 WORD32 read_word = ixheaacd_aac_showbits_32(ptr_read_next);
492 ptr_read_next += 4;
493 spec_orig = spec_coef;
494 do {
495 idx_len = offsets[1] - offsets[0];
496 grp_idx = group_len;
497
498 do {
499 spec_coef = spec_coef + offsets[0];
500 idx = idx_len;
501 do {
502 UWORD32 read_word1;
503
504 read_word1 = read_word << bit_pos;
505 ixheaacd_huffman_decode(read_word1, &index, &length, code_book_tbl,
506 idx_table);
507 bit_pos += length;
508 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
509 it_bit_buff->ptr_bit_buf_end);
510 if (tbl_sign) {
511 WORD32 temp_word;
512 WORD32 w, x, y, z;
513 temp_word = read_word << bit_pos;
514 w = index / 27;
515 index = index - w * 27;
516 x = index / 9;
517 index = index - x * 9;
518 y = index / 3;
519 z = index - y * 3;
520 if (w) {
521 w = ixheaacd_pow_table_Q13[w];
522 if (temp_word & 0x80000000) w = -w;
523 temp_word <<= 1;
524 bit_pos++;
525 }
526 *spec_coef++ = w;
527
528 if (x) {
529 x = ixheaacd_pow_table_Q13[x];
530 if (temp_word & 0x80000000) x = -x;
531 temp_word <<= 1;
532 bit_pos++;
533 }
534 *spec_coef++ = x;
535 if (y) {
536 y = ixheaacd_pow_table_Q13[y];
537 if (temp_word & 0x80000000) y = -y;
538 temp_word <<= 1;
539 bit_pos++;
540 }
541 *spec_coef++ = y;
542 if (z) {
543 z = ixheaacd_pow_table_Q13[z];
544 if (temp_word & 0x80000000) z = -z;
545 temp_word <<= 1;
546 bit_pos++;
547 }
548 *spec_coef++ = z;
549
550 }
551
552 else {
553 WORD32 w, x, y, z;
554
555 w = index / 27 - 1;
556 index = index - (w + 1) * 27;
557 x = index / 9 - 1;
558 index = index - (x + 1) * 9;
559 y = index / 3 - 1;
560 z = index - ((y + 1) * 3) - 1;
561 if (w < 0) {
562 w = -w;
563 w = ixheaacd_pow_table_Q13[w];
564 w = -w;
565 } else
566 w = ixheaacd_pow_table_Q13[w];
567
568 *spec_coef++ = w;
569
570 if (x < 0) {
571 x = -x;
572 x = ixheaacd_pow_table_Q13[x];
573 x = -x;
574 } else
575 x = ixheaacd_pow_table_Q13[x];
576
577 *spec_coef++ = x;
578
579 if (y < 0) {
580 y = -y;
581 y = ixheaacd_pow_table_Q13[y];
582 y = -y;
583 } else
584 y = ixheaacd_pow_table_Q13[y];
585
586 *spec_coef++ = y;
587
588 if (z < 0) {
589 z = -z;
590 z = ixheaacd_pow_table_Q13[z];
591 z = -z;
592 } else
593 z = ixheaacd_pow_table_Q13[z];
594
595 *spec_coef++ = z;
596 }
597
598 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
599 it_bit_buff->ptr_bit_buf_end);
600 idx -= 4;
601 } while (idx != 0);
602
603 spec_coef += (MAX_BINS_SHORT - offsets[1]);
604 grp_idx--;
605 } while (grp_idx != 0);
606 offsets++;
607 spec_coef = spec_orig;
608 no_bands--;
609 } while (no_bands >= 0);
610
611 it_bit_buff->ptr_read_next = ptr_read_next - 4;
612 it_bit_buff->bit_pos = bit_pos;
613
614 return 0;
615 }
616
ixheaacd_huffman_dec_word2_quad(ia_bit_buf_struct * it_bit_buff,WORD32 width,const UWORD16 * code_book_tbl,WORD32 * x_invquant,WORD32 * ixheaacd_pow_table_Q13,WORD8 * ptr_scratch,WORD32 tbl_sign,const UWORD32 * idx_table)617 static PLATFORM_INLINE WORD ixheaacd_huffman_dec_word2_quad(
618 ia_bit_buf_struct *it_bit_buff, WORD32 width, const UWORD16 *code_book_tbl,
619 WORD32 *x_invquant, WORD32 *ixheaacd_pow_table_Q13, WORD8 *ptr_scratch,
620 WORD32 tbl_sign, const UWORD32 *idx_table) {
621 WORD idx;
622 WORD16 index, length;
623 UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next;
624 WORD32 bit_pos = it_bit_buff->bit_pos;
625 WORD32 read_word = ixheaacd_aac_showbits_32(ptr_read_next);
626 ptr_read_next += 4;
627
628 for (idx = width; idx != 0; idx -= 4) {
629 WORD32 ampres, ampres1;
630 WORD32 ampres2, ampres3;
631 UWORD32 read_word1;
632
633 read_word1 = read_word << bit_pos;
634 ixheaacd_huffman_decode(read_word1, &index, &length, code_book_tbl,
635 idx_table);
636 bit_pos += length;
637 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
638 it_bit_buff->ptr_bit_buf_end);
639 if (tbl_sign) {
640 WORD32 w, x, y, z;
641 WORD32 ampout0, ampout1, ampout2, ampout3;
642 WORD32 temp_word;
643 temp_word = read_word << bit_pos;
644
645 w = index / 27;
646 index = index - w * 27;
647 x = index / 9;
648 index = index - x * 9;
649 y = index / 3;
650 z = index - y * 3;
651
652 ampout0 = w + *ptr_scratch++;
653 ampout0 = ixheaacd_pow_table_Q13[ampout0];
654
655 if (w) {
656 if (temp_word & 0x80000000) {
657 ampout0 = -ampout0;
658 }
659 temp_word = temp_word << 1;
660 bit_pos++;
661 } else {
662 ampout0 = -ampout0;
663 }
664
665 ampout1 = x + *ptr_scratch++;
666 ampout1 = ixheaacd_pow_table_Q13[ampout1];
667
668 if (x) {
669 if (temp_word & 0x80000000) {
670 ampout1 = -ampout1;
671 }
672 temp_word = temp_word << 1;
673 bit_pos++;
674 } else {
675 ampout1 = -ampout1;
676 }
677
678 ampout2 = y + *ptr_scratch++;
679 ampout2 = ixheaacd_pow_table_Q13[ampout2];
680
681 if (y) {
682 if (temp_word & 0x80000000) {
683 ampout2 = -ampout2;
684 }
685 temp_word = temp_word << 1;
686 bit_pos++;
687 } else {
688 ampout2 = -ampout2;
689 }
690
691 ampout3 = z + *ptr_scratch++;
692 ampout3 = ixheaacd_pow_table_Q13[ampout3];
693
694 if (z) {
695 if (temp_word & 0x80000000) {
696 ampout3 = -ampout3;
697 }
698 temp_word = temp_word << 1;
699 bit_pos++;
700 } else {
701 ampout3 = -ampout3;
702 }
703 *x_invquant++ = ampout0;
704 *x_invquant++ = ampout1;
705 *x_invquant++ = ampout2;
706 *x_invquant++ = ampout3;
707 } else {
708 WORD32 w, x, y, z;
709 ampres = *ptr_scratch++;
710 ampres1 = *ptr_scratch++;
711 ampres2 = *ptr_scratch++;
712 ampres3 = *ptr_scratch++;
713
714 w = index / 27 - 1;
715 index = index - (w + 1) * 27;
716 x = index / 9 - 1;
717 index = index - (x + 1) * 9;
718 y = index / 3 - 1;
719 z = index - ((y + 1) * 3) - 1;
720 if (w <= 0) {
721 ampres = ampres - w;
722 ampres = ixheaacd_pow_table_Q13[ampres];
723 ampres = -ampres;
724 } else {
725 ampres += w;
726 ampres = ixheaacd_pow_table_Q13[ampres];
727 }
728
729 if (x <= 0) {
730 ampres1 = ampres1 - x;
731 ampres1 = ixheaacd_pow_table_Q13[ampres1];
732 ampres1 = -ampres1;
733 } else {
734 ampres1 += x;
735 ampres1 = ixheaacd_pow_table_Q13[ampres1];
736 }
737
738 if (y <= 0) {
739 ampres2 = ampres2 - y;
740 ampres2 = ixheaacd_pow_table_Q13[ampres2];
741 ampres2 = -ampres2;
742 } else {
743 ampres2 += y;
744 ampres2 = ixheaacd_pow_table_Q13[ampres2];
745 }
746
747 if (z <= 0) {
748 ampres3 = ampres3 - z;
749 ampres3 = ixheaacd_pow_table_Q13[ampres3];
750 ampres3 = -ampres3;
751 } else {
752 ampres3 += z;
753 ampres3 = ixheaacd_pow_table_Q13[ampres3];
754 }
755
756 *x_invquant++ = ampres;
757 *x_invquant++ = ampres1;
758 *x_invquant++ = ampres2;
759 *x_invquant++ = ampres3;
760 }
761
762 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
763 it_bit_buff->ptr_bit_buf_end);
764 }
765
766 it_bit_buff->ptr_read_next = ptr_read_next - 4;
767 it_bit_buff->bit_pos = bit_pos;
768
769 return 0;
770 }
771
ixheaacd_huffman_dec_pair(ia_bit_buf_struct * it_bit_buff,WORD32 * spec_coef,WORD16 * offsets,WORD no_bands,WORD group_len,const UWORD16 * code_book_tbl,WORD32 * ixheaacd_pow_table_Q13,WORD32 tbl_sign,const UWORD32 * idx_table,WORD32 huff_mode)772 static PLATFORM_INLINE WORD ixheaacd_huffman_dec_pair(
773 ia_bit_buf_struct *it_bit_buff, WORD32 *spec_coef, WORD16 *offsets,
774 WORD no_bands, WORD group_len, const UWORD16 *code_book_tbl,
775 WORD32 *ixheaacd_pow_table_Q13, WORD32 tbl_sign, const UWORD32 *idx_table,
776 WORD32 huff_mode)
777
778 {
779 WORD idx, grp_idx;
780 WORD len_idx;
781 WORD16 index, length;
782 WORD32 y, z;
783 WORD32 *spec_orig = spec_coef;
784
785 UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next;
786 WORD32 bit_pos = it_bit_buff->bit_pos;
787 WORD32 read_word = ixheaacd_aac_showbits_32(ptr_read_next);
788 ptr_read_next += 4;
789
790 do {
791 len_idx = offsets[1] - offsets[0];
792 grp_idx = group_len;
793 do {
794 spec_coef += offsets[0];
795 idx = len_idx;
796 do {
797 UWORD32 read_word1;
798 read_word1 = read_word << bit_pos;
799 ixheaacd_huffman_decode(read_word1, &index, &length, code_book_tbl,
800 idx_table);
801 bit_pos += length;
802 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
803 it_bit_buff->ptr_bit_buf_end);
804 if (tbl_sign) {
805 WORD32 temp_word;
806 temp_word = read_word << bit_pos;
807 y = index / huff_mode;
808 z = index - huff_mode * y;
809 if (y) {
810 y = ixheaacd_pow_table_Q13[y];
811 if (temp_word & 0x80000000) y = -y;
812
813 temp_word = temp_word << 1;
814 bit_pos++;
815 }
816 *spec_coef++ = y;
817
818 if (z) {
819 z = ixheaacd_pow_table_Q13[z];
820 if (temp_word & 0x80000000) {
821 z = -z;
822 }
823 temp_word <<= 1;
824 bit_pos++;
825 }
826 *spec_coef++ = z;
827 } else {
828 y = (index / huff_mode) - 4;
829 z = index - ((y + 4) * huff_mode) - 4;
830 if (y < 0) {
831 y = -y;
832 y = ixheaacd_pow_table_Q13[y];
833 y = -y;
834 } else
835 y = ixheaacd_pow_table_Q13[y];
836
837 if (z < 0) {
838 z = -z;
839 z = ixheaacd_pow_table_Q13[z];
840 z = -z;
841 } else
842 z = ixheaacd_pow_table_Q13[z];
843
844 *spec_coef++ = y;
845 *spec_coef++ = z;
846 }
847 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
848 it_bit_buff->ptr_bit_buf_end);
849 idx -= 2;
850 } while (idx != 0);
851
852 spec_coef += (MAX_BINS_SHORT - offsets[1]);
853 grp_idx--;
854 } while (grp_idx != 0);
855
856 offsets++;
857 spec_coef = spec_orig;
858 no_bands--;
859 } while (no_bands >= 0);
860
861 it_bit_buff->ptr_read_next = ptr_read_next - 4;
862 it_bit_buff->bit_pos = bit_pos;
863
864 return 0;
865 }
866
ixheaacd_huffman_dec_word2_pair(ia_bit_buf_struct * it_bit_buff,WORD32 width,const UWORD16 * code_book_tbl,WORD32 * x_invquant,WORD32 * ixheaacd_pow_table_Q13,WORD8 * ptr_scratch,WORD32 tbl_sign,const UWORD32 * idx_table,WORD32 huff_mode)867 static PLATFORM_INLINE WORD ixheaacd_huffman_dec_word2_pair(
868 ia_bit_buf_struct *it_bit_buff, WORD32 width, const UWORD16 *code_book_tbl,
869 WORD32 *x_invquant, WORD32 *ixheaacd_pow_table_Q13, WORD8 *ptr_scratch,
870 WORD32 tbl_sign, const UWORD32 *idx_table, WORD32 huff_mode)
871
872 {
873 WORD32 ampres;
874 WORD idx;
875 WORD16 index, length;
876 UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next;
877 WORD32 bit_pos = it_bit_buff->bit_pos;
878 WORD32 read_word = ixheaacd_aac_showbits_32(ptr_read_next);
879 ptr_read_next += 4;
880
881 for (idx = width; idx != 0; idx -= 2) {
882 {
883 UWORD32 read_word1;
884 read_word1 = read_word << bit_pos;
885 ixheaacd_huffman_decode(read_word1, &index, &length, code_book_tbl,
886 idx_table);
887 bit_pos += length;
888 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
889 it_bit_buff->ptr_bit_buf_end);
890 }
891
892 if (tbl_sign) {
893 WORD32 out0, out1, temp_word;
894 WORD32 ampout0, ampout1;
895
896 ampout0 = *ptr_scratch++;
897 ampout1 = *ptr_scratch++;
898 out0 = index / huff_mode;
899 out1 = index - huff_mode * out0;
900 ampout0 += out0;
901 ampout0 = ixheaacd_pow_table_Q13[ampout0];
902
903 ampout1 += out1;
904 ampout1 = ixheaacd_pow_table_Q13[ampout1];
905 temp_word = read_word << bit_pos;
906 if (out0) {
907 if (temp_word & 0x80000000) {
908 ampout0 = -(ampout0);
909 }
910
911 bit_pos++;
912 temp_word = temp_word << 1;
913 } else {
914 ampout0 = -(ampout0);
915 }
916
917 if (out1) {
918 if (temp_word & 0x80000000) {
919 ampout1 = -(ampout1);
920 }
921 bit_pos++;
922 } else {
923 ampout1 = -(ampout1);
924 }
925
926 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
927 it_bit_buff->ptr_bit_buf_end);
928 *x_invquant++ = ampout0;
929 *x_invquant++ = ampout1;
930 } else {
931 WORD32 y, z;
932 y = (index / huff_mode) - 4;
933 z = index - ((y + 4) * huff_mode) - 4;
934
935 ampres = *ptr_scratch++;
936 if (y <= 0) {
937 ampres = ampres - y;
938 ampres = ixheaacd_pow_table_Q13[ampres];
939 *x_invquant++ = -ampres;
940 } else {
941 ampres += y;
942 *x_invquant++ = ixheaacd_pow_table_Q13[ampres];
943 }
944 ampres = *ptr_scratch++;
945 if (z <= 0) {
946 ampres = ampres - z;
947 ampres = ixheaacd_pow_table_Q13[ampres];
948 *x_invquant++ = -ampres;
949 } else {
950 ampres += z;
951 *x_invquant++ = ixheaacd_pow_table_Q13[ampres];
952 }
953 }
954 ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
955 it_bit_buff->ptr_bit_buf_end);
956 }
957
958 it_bit_buff->ptr_read_next = ptr_read_next - 4;
959 it_bit_buff->bit_pos = bit_pos;
960
961 return 0;
962 }
963
ixheaacd_decode_huffman(ia_bit_buf_struct * it_bit_buff,WORD32 cb_no,WORD32 * spec_coef,WORD16 * sfb_offset,WORD start,WORD sfb,WORD group_len,ia_aac_dec_tables_struct * ptr_aac_tables)964 WORD ixheaacd_decode_huffman(ia_bit_buf_struct *it_bit_buff, WORD32 cb_no,
965 WORD32 *spec_coef, WORD16 *sfb_offset, WORD start,
966 WORD sfb, WORD group_len,
967 ia_aac_dec_tables_struct *ptr_aac_tables) {
968 WORD ret_val = 0;
969 WORD start_bit_pos = it_bit_buff->bit_pos;
970 UWORD8 *start_read_pos = it_bit_buff->ptr_read_next;
971 const UWORD16 *cb_table = (UWORD16 *)(ptr_aac_tables->code_book[cb_no]);
972 WORD32 huff_mode;
973 const UWORD32 *idx_table = (UWORD32 *)(ptr_aac_tables->index_table[cb_no]);
974 WORD32 *pow_table =
975 (WORD32 *)ptr_aac_tables->pstr_block_tables->ixheaacd_pow_table_Q13;
976 WORD32 no_bands = sfb - start - 1;
977 WORD16 *band_offset = sfb_offset + start;
978
979 if (cb_no == 11) {
980 const UWORD32 *idx_table =
981 ptr_aac_tables->pstr_huffmann_tables->idx_table_hf11;
982 const UWORD16 *cb_table =
983 ptr_aac_tables->pstr_huffmann_tables->input_table_cb11;
984
985 ret_val = ixheaacd_huffman_dec_word1(it_bit_buff, spec_coef, band_offset,
986 no_bands, group_len, cb_table,
987 pow_table, idx_table);
988
989 } else if (cb_no <= 4) {
990 WORD32 tbl_sign = 0;
991
992 if (cb_no > 2) {
993 tbl_sign = 1;
994 }
995 ret_val = ixheaacd_huffman_dec_quad(it_bit_buff, spec_coef, band_offset,
996 no_bands, group_len, cb_table,
997 pow_table, tbl_sign, idx_table);
998 }
999
1000 else if (cb_no <= 10) {
1001 WORD32 tbl_sign = 0;
1002 huff_mode = 9;
1003 if (cb_no > 6) {
1004 if (cb_no > 8)
1005 huff_mode = 13;
1006 else
1007 huff_mode = 8;
1008 tbl_sign = 1;
1009 }
1010 ret_val = ixheaacd_huffman_dec_pair(
1011 it_bit_buff, spec_coef, band_offset, no_bands, group_len, cb_table,
1012 pow_table, tbl_sign, idx_table, huff_mode);
1013 }
1014
1015 {
1016 WORD bits_cons;
1017 bits_cons = ((it_bit_buff->ptr_read_next - start_read_pos) << 3) +
1018 (it_bit_buff->bit_pos - start_bit_pos);
1019 it_bit_buff->cnt_bits -= bits_cons;
1020 }
1021 return ret_val;
1022 }
1023
ixheaacd_huffman_dec_word2(ia_bit_buf_struct * it_bit_buff,WORD32 cb_no,WORD32 width,ia_aac_dec_tables_struct * ptr_aac_tables,WORD32 * x_invquant,WORD8 * scratch_ptr)1024 WORD ixheaacd_huffman_dec_word2(ia_bit_buf_struct *it_bit_buff, WORD32 cb_no,
1025 WORD32 width,
1026 ia_aac_dec_tables_struct *ptr_aac_tables,
1027 WORD32 *x_invquant, WORD8 *scratch_ptr) {
1028 WORD ret_val = 0;
1029 WORD32 huff_mode;
1030 WORD start_bit_pos = it_bit_buff->bit_pos;
1031 WORD32 *pow_table =
1032 (WORD32 *)ptr_aac_tables->pstr_block_tables->ixheaacd_pow_table_Q13;
1033 UWORD8 *start_read_pos = it_bit_buff->ptr_read_next;
1034
1035 const UWORD16 *cb_table = (UWORD16 *)(ptr_aac_tables->code_book[cb_no]);
1036 const UWORD32 *idx_table = (UWORD32 *)(ptr_aac_tables->index_table[cb_no]);
1037
1038 if (cb_no == 11) {
1039 const UWORD16 *cb_table =
1040 ptr_aac_tables->pstr_huffmann_tables->input_table_cb11;
1041
1042 ret_val = ixheaacd_huffman_dec_word2_11(
1043 it_bit_buff, width, cb_table, x_invquant, pow_table, scratch_ptr,
1044 ptr_aac_tables->pstr_huffmann_tables->idx_table_hf11);
1045 } else if (cb_no <= 4) {
1046 WORD32 tbl_sign = 0;
1047 if (cb_no > 2) tbl_sign = 1;
1048 ret_val = ixheaacd_huffman_dec_word2_quad(it_bit_buff, width, cb_table,
1049 x_invquant, pow_table,
1050 scratch_ptr, tbl_sign, idx_table);
1051 } else if (cb_no <= 10) {
1052 WORD32 tbl_sign = 0;
1053 huff_mode = 9;
1054 if (cb_no > 6) {
1055 if (cb_no > 8) {
1056 huff_mode = 13;
1057 } else {
1058 huff_mode = 8;
1059 }
1060
1061 tbl_sign = 1;
1062 }
1063 ret_val = ixheaacd_huffman_dec_word2_pair(
1064 it_bit_buff, width, cb_table, x_invquant, pow_table, scratch_ptr,
1065 tbl_sign, idx_table, huff_mode);
1066 }
1067
1068 {
1069 WORD bits_cons;
1070 if (it_bit_buff->bit_pos <= 7) {
1071 bits_cons = ((it_bit_buff->ptr_read_next - start_read_pos) << 3) +
1072 (it_bit_buff->bit_pos - start_bit_pos);
1073 it_bit_buff->cnt_bits -= bits_cons;
1074 } else {
1075 it_bit_buff->ptr_read_next += (it_bit_buff->bit_pos) >> 3;
1076 it_bit_buff->bit_pos = it_bit_buff->bit_pos & 0x7;
1077
1078 bits_cons = ((it_bit_buff->ptr_read_next - start_read_pos) << 3) +
1079 ((it_bit_buff->bit_pos - start_bit_pos));
1080 it_bit_buff->cnt_bits -= bits_cons;
1081 }
1082 }
1083 return ret_val;
1084 }
1085
ixheaacd_lap1_512_480(WORD32 * coef,WORD32 * prev,WORD16 * out,const WORD16 * window,WORD16 q_shift,WORD16 size,WORD16 stride)1086 void ixheaacd_lap1_512_480(WORD32 *coef, WORD32 *prev, WORD16 *out,
1087 const WORD16 *window, WORD16 q_shift, WORD16 size,
1088 WORD16 stride) {
1089 WORD32 accu;
1090 WORD32 i;
1091 WORD16 rounding_fac = -0x2000;
1092
1093 WORD32 *window_i = (WORD32 *)window;
1094
1095 WORD16 *ptr_out1, *ptr_out2;
1096
1097 WORD32 *pwin1, *pwin2;
1098 WORD32 *pCoef = &coef[size * 2 - 1 - 0];
1099
1100 pwin1 = &window_i[size - 1 - 0];
1101 pwin2 = &window_i[size + 0];
1102
1103 ptr_out1 = &out[stride * (size - 1 - 0)];
1104 ptr_out2 = &out[stride * (size + 0)];
1105
1106 for (i = 0; i < size; i++) {
1107 WORD32 win1, win2, coeff;
1108 WORD32 prev_data = *prev++;
1109
1110 win1 = *pwin1--;
1111 coeff = *pCoef--;
1112 win2 = *pwin2++;
1113
1114 accu = ixheaacd_sub32_sat(
1115 ixheaacd_shl32_dir_sat_limit(ixheaacd_mult32_shl(coeff, win1), q_shift),
1116 ixheaacd_mac32x16in32_shl(rounding_fac, win2, (WORD16)(prev_data)));
1117
1118 accu = ixheaacd_add32_sat(accu, accu);
1119 accu = ixheaacd_add32_sat(accu, accu);
1120
1121 *ptr_out1 = ixheaacd_shr32(accu, 16);
1122 ptr_out1 -= stride;
1123
1124 accu = ixheaacd_sub32_sat(
1125 ixheaacd_shl32_dir_sat_limit(
1126 ixheaacd_mult32_shl(ixheaacd_negate32(coeff), win2), q_shift),
1127 ixheaacd_mac32x16in32_shl(rounding_fac, win1, (WORD16)(prev_data)));
1128
1129 accu = ixheaacd_add32_sat(accu, accu);
1130 accu = ixheaacd_add32_sat(accu, accu);
1131
1132 *ptr_out2 = ixheaacd_shr32(accu, 16);
1133 ptr_out2 += stride;
1134 }
1135 }
1136
ixheaacd_over_lap_add1_dec(WORD32 * coef,WORD32 * prev,WORD16 * out,const WORD16 * window,WORD16 q_shift,WORD16 size,WORD16 ch_fac)1137 VOID ixheaacd_over_lap_add1_dec(WORD32 *coef, WORD32 *prev, WORD16 *out,
1138 const WORD16 *window, WORD16 q_shift,
1139 WORD16 size, WORD16 ch_fac) {
1140 WORD32 accu;
1141 WORD32 i;
1142 WORD16 rounding_fac = -0x2000;
1143
1144 for (i = 0; i < size; i++) {
1145 WORD16 window1, window2;
1146
1147 window1 = window[2 * size - 2 * i - 1];
1148 window2 = window[2 * size - 2 * i - 2];
1149 accu = ixheaacd_sub32_sat(
1150 ixheaacd_shl32_dir_sat_limit(
1151 ixheaacd_mult32x16in32(coef[size * 2 - 1 - i], window2), q_shift),
1152 ixheaacd_mac32x16in32_drc(rounding_fac, prev[i], window1));
1153 out[ch_fac * (size - i - 1)] =
1154 ixheaacd_shr32(ixheaacd_shl32_dir_sat_limit(accu, 2), 16);
1155 accu = ixheaacd_sub32_sat(
1156 ixheaacd_shl32_dir_sat_limit(
1157 ixheaacd_mult32x16in32(ixheaacd_negate32(coef[size * 2 - 1 - i]),
1158 window1),
1159 q_shift),
1160 ixheaacd_mac32x16in32_drc(rounding_fac, prev[i], window2));
1161 out[ch_fac * (size + i)] =
1162 ixheaacd_shr32(ixheaacd_shl32_dir_sat_limit(accu, 2), 16);
1163 }
1164 }
1165
ixheaacd_over_lap_add2_dec(WORD32 * coef,WORD32 * prev,WORD32 * out,const WORD16 * window,WORD16 q_shift,WORD16 size,WORD16 ch_fac)1166 VOID ixheaacd_over_lap_add2_dec(WORD32 *coef, WORD32 *prev, WORD32 *out,
1167 const WORD16 *window, WORD16 q_shift,
1168 WORD16 size, WORD16 ch_fac) {
1169 WORD32 accu;
1170 WORD32 i;
1171
1172 for (i = 0; i < size; i++) {
1173 accu = ixheaacd_sub32_sat(
1174 ixheaacd_mult32x16in32(coef[size + i], window[2 * i]),
1175 ixheaacd_mult32x16in32(prev[size - 1 - i], window[2 * i + 1]));
1176 out[ch_fac * i] = ixheaacd_shr32_drc(accu, 16 - (q_shift + 1));
1177 }
1178
1179 for (i = 0; i < size; i++) {
1180 accu = ixheaacd_sub32_sat(
1181 ixheaacd_mult32x16in32(ixheaacd_negate32_sat(coef[size * 2 - 1 - i]),
1182 window[2 * size - 2 * i - 1]),
1183 ixheaacd_mult32x16in32(prev[i], window[2 * size - 2 * i - 2]));
1184 out[ch_fac * (i + size)] = ixheaacd_shr32_drc(accu, 16 - (q_shift + 1));
1185 }
1186 }
1187
ixheaacd_process_single_scf(WORD32 scale_factor,WORD32 * x_invquant,WORD32 width,WORD32 * ptr_scale_table,WORD32 total_channels,WORD32 object_type,WORD32 aac_sf_data_resil_flag)1188 VOID ixheaacd_process_single_scf(WORD32 scale_factor, WORD32 *x_invquant,
1189 WORD32 width, WORD32 *ptr_scale_table,
1190 WORD32 total_channels, WORD32 object_type,
1191 WORD32 aac_sf_data_resil_flag) {
1192 WORD32 j;
1193
1194 WORD32 temp1;
1195 WORD32 q_factor;
1196 WORD32 buffer1;
1197 WORD16 scale_short;
1198
1199 object_type = 0;
1200 aac_sf_data_resil_flag = 0;
1201
1202 if (scale_factor < 24) {
1203 for (j = width; j > 0; j--) {
1204 *x_invquant++ = 0;
1205 }
1206 } else {
1207 WORD32 shift;
1208
1209 if (total_channels > 2)
1210 q_factor = 34 - (scale_factor >> 2);
1211 else
1212 q_factor = 37 - (scale_factor >> 2);
1213
1214 scale_short = ptr_scale_table[(scale_factor & 0x0003)];
1215 shift = q_factor;
1216 if (shift > 0) {
1217 if (scale_short == (WORD16)0x8000) {
1218 for (j = width; j > 0; j--) {
1219 temp1 = *x_invquant;
1220 buffer1 = ixheaacd_mult32x16in32_shl_sat(temp1, scale_short);
1221 buffer1 = ixheaacd_shr32(buffer1, shift);
1222 *x_invquant++ = buffer1;
1223 }
1224 } else {
1225 for (j = width; j > 0; j--) {
1226 temp1 = *x_invquant;
1227 buffer1 = ixheaacd_mult32x16in32_shl(temp1, scale_short);
1228 buffer1 = ixheaacd_shr32(buffer1, shift);
1229 *x_invquant++ = buffer1;
1230 }
1231 }
1232 } else {
1233 shift = -shift;
1234 if (shift > 0) {
1235 if (scale_short == (WORD16)0x8000) {
1236 for (j = width; j > 0; j--) {
1237 temp1 = *x_invquant;
1238 temp1 = ixheaacd_shl32(temp1, shift - 1);
1239 buffer1 = ixheaacd_mult32x16in32_shl_sat(temp1, scale_short);
1240 buffer1 = ixheaacd_shl32(buffer1, 1);
1241 *x_invquant++ = buffer1;
1242 }
1243 } else {
1244 for (j = width; j > 0; j--) {
1245 temp1 = *x_invquant;
1246 temp1 = ixheaacd_shl32(temp1, shift - 1);
1247 buffer1 = ixheaacd_mult32x16in32_shl(temp1, scale_short);
1248 buffer1 = ixheaacd_shl32(buffer1, 1);
1249 *x_invquant++ = buffer1;
1250 }
1251 }
1252
1253 } else {
1254 if (scale_short == (WORD16)0x8000) {
1255 for (j = width; j > 0; j--) {
1256 temp1 = *x_invquant;
1257 buffer1 = ixheaacd_mult32x16in32_shl_sat(temp1, scale_short);
1258 *x_invquant++ = buffer1;
1259 }
1260 } else {
1261 for (j = width; j > 0; j--) {
1262 temp1 = *x_invquant;
1263 buffer1 = ixheaacd_mult32x16in32_shl(temp1, scale_short);
1264 *x_invquant++ = buffer1;
1265 }
1266 }
1267 }
1268 }
1269 }
1270 }
1271
ixheaacd_scale_factor_process_dec(WORD32 * x_invquant,WORD16 * scale_fact,WORD no_band,WORD8 * width,WORD32 * ptr_scale_table,WORD32 total_channels,WORD32 object_type,WORD32 aac_sf_data_resil_flag)1272 VOID ixheaacd_scale_factor_process_dec(WORD32 *x_invquant, WORD16 *scale_fact,
1273 WORD no_band, WORD8 *width,
1274 WORD32 *ptr_scale_table,
1275 WORD32 total_channels,
1276 WORD32 object_type,
1277 WORD32 aac_sf_data_resil_flag) {
1278 WORD32 i;
1279 WORD16 scale_factor;
1280
1281 for (i = no_band - 1; i >= 0; i--) {
1282 scale_factor = *scale_fact++;
1283 ixheaacd_process_single_scf(scale_factor, x_invquant, *width,
1284 ptr_scale_table, total_channels, object_type,
1285 aac_sf_data_resil_flag);
1286
1287 x_invquant += *width;
1288 width++;
1289 }
1290 }
1291
ixheaacd_right_shift_block(WORD32 * p_spectrum,WORD32 length,WORD32 shift_val)1292 void ixheaacd_right_shift_block(WORD32 *p_spectrum, WORD32 length,
1293 WORD32 shift_val) {
1294 WORD32 i;
1295 WORD32 temp1, temp2;
1296 WORD32 *temp_ptr = &p_spectrum[0];
1297 length = length >> 2;
1298
1299 for (i = length - 1; i >= 0; i--) {
1300 temp1 = *temp_ptr;
1301 temp2 = *(temp_ptr + 1);
1302 *temp_ptr++ = temp1 >> shift_val;
1303 temp1 = *(temp_ptr + 1);
1304 *temp_ptr++ = temp2 >> shift_val;
1305 temp2 = *(temp_ptr + 1);
1306 *temp_ptr++ = temp1 >> shift_val;
1307 *temp_ptr++ = temp2 >> shift_val;
1308 }
1309 }
1310