Coverage Report

Created: 2026-04-12 06:44

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