Coverage Report

Created: 2026-01-09 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
49.3M
                                                        WORD16 c) {
64
49.3M
  WORD32 acc;
65
66
49.3M
  acc = ixheaac_mult32x16in32_sat(b, c);
67
68
49.3M
  acc = ixheaac_add32_sat(a, acc);
69
70
49.3M
  return acc;
71
49.3M
}
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
4.58M
                             const UWORD32 *idx_table) {
78
4.58M
  UWORD32 temp = 0;
79
4.58M
  UWORD32 temp1 = 0;
80
4.58M
  WORD32 found = 0;
81
4.58M
  UWORD32 mask = 0x80000000;
82
83
4.58M
  WORD32 leading_ones;
84
4.58M
  WORD32 max_len;
85
4.58M
  WORD32 ixheaacd_drc_offset = 0;
86
4.58M
  WORD32 length;
87
4.58M
  UWORD32 code_word;
88
4.58M
  WORD32 len_end;
89
90
4.58M
  max_len = code_book_tbl[0];
91
4.58M
  mask = mask - (1 << (31 - max_len));
92
4.58M
  mask = mask << 1;
93
94
4.58M
  temp = (UWORD32)((it_bit_buff & mask));
95
96
4.58M
  len_end = code_book_tbl[0];
97
4.58M
  leading_ones = ixheaacd_cnt_leading_ones(temp);
98
7.39M
  do {
99
7.39M
    ixheaacd_drc_offset = (idx_table[leading_ones] >> 20) & 0x1ff;
100
7.39M
    length = code_book_tbl[ixheaacd_drc_offset + 1] & 0x1f;
101
7.39M
    code_word = idx_table[leading_ones] & 0xfffff;
102
7.39M
    temp1 = temp >> (32 - length);
103
7.39M
    if (temp1 <= code_word) {
104
4.58M
      ixheaacd_drc_offset = ixheaacd_drc_offset - (code_word - temp1);
105
4.58M
      found = 1;
106
4.58M
    } else {
107
2.80M
      len_end = len_end + ((idx_table[leading_ones] >> 29) & 0x7);
108
2.80M
      leading_ones = len_end;
109
2.80M
    }
110
7.39M
  } while (!found);
111
4.58M
  *huff_index = code_book_tbl[ixheaacd_drc_offset + 1] >> 5;
112
4.58M
  *len = length;
113
4.58M
}
114
115
VOID ixheaacd_inverse_quantize(WORD32 *x_invquant, WORD no_band,
116
                               WORD32 *ixheaacd_pow_table_Q13,
117
25.8k
                               WORD8 *scratch_in) {
118
25.8k
  WORD32 j;
119
25.8k
  WORD32 temp;
120
25.8k
  WORD32 q_abs;
121
122
1.90M
  for (j = no_band - 1; j >= 0; j--) {
123
1.87M
    q_abs = *scratch_in++;
124
1.87M
    temp = (ixheaacd_pow_table_Q13[q_abs]);
125
1.87M
    *x_invquant++ = -temp;
126
1.87M
  }
127
25.8k
}
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
43.3k
    WORD32 *ixheaacd_pow_table_Q13, const UWORD32 *idx_table, WORD32 maximum_bins_short) {
133
43.3k
  WORD32 sp1, sp2;
134
43.3k
  WORD32 flush_cw;
135
43.3k
  WORD32 i, value, norm_val, off;
136
43.3k
  WORD idx, grp_idx;
137
43.3k
  WORD32 out1, out2;
138
43.3k
  WORD32 err_code = 0;
139
43.3k
  WORD len_idx = 0;
140
43.3k
  UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next;
141
43.3k
  WORD32 bit_pos = it_bit_buff->bit_pos;
142
43.3k
  WORD16 index;
143
43.3k
  WORD32 length;
144
43.3k
  WORD32 read_word;
145
43.3k
  WORD32 increment;
146
147
43.3k
  read_word = ixheaacd_aac_showbits_32(ptr_read_next, it_bit_buff->cnt_bits,
148
43.3k
                                       &increment);
149
43.3k
  ptr_read_next += increment;
150
151
46.5k
  do {
152
46.5k
    len_idx = offsets[1] - offsets[0];
153
46.5k
    grp_idx = group_len;
154
155
107k
    do {
156
107k
      spec_coef = spec_coef + offsets[0];
157
107k
      idx = len_idx;
158
382k
      do {
159
382k
        {
160
382k
          UWORD32 read_word1;
161
162
382k
          read_word1 = read_word << bit_pos;
163
382k
          ixheaacd_huff_sfb_table(read_word1, &index, &length, code_book_tbl,
164
382k
                                  idx_table);
165
382k
          bit_pos += length;
166
382k
          ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
167
382k
                                      it_bit_buff->ptr_bit_buf_end);
168
382k
        }
169
170
382k
        out1 = index / 17;
171
382k
        out2 = index - out1 * 17;
172
382k
        flush_cw = read_word << bit_pos;
173
174
382k
        sp1 = out1;
175
382k
        sp2 = out2;
176
177
382k
        if (out1) {
178
205k
          if (flush_cw & 0x80000000) {
179
148k
            out1 = -out1;
180
148k
          }
181
205k
          bit_pos++;
182
205k
          flush_cw = (WORD32)flush_cw << 1;
183
205k
        }
184
185
382k
        if (out2) {
186
197k
          bit_pos++;
187
197k
          if (flush_cw & 0x80000000) {
188
112k
            out2 = -out2;
189
112k
          }
190
197k
        }
191
382k
        ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
192
382k
                                    it_bit_buff->ptr_bit_buf_end);
193
194
382k
        if (sp1 == 16) {
195
15.2k
          i = 4;
196
15.2k
          value = ixheaac_extu(read_word, bit_pos, 23);
197
15.2k
          value = value | 0xfffffe00;
198
15.2k
          norm_val = ixheaac_norm32(value);
199
200
15.2k
          i += (norm_val - 22);
201
15.2k
          bit_pos += (norm_val - 21);
202
15.2k
          ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
203
15.2k
                                      it_bit_buff->ptr_bit_buf_end);
204
205
15.2k
          off = ixheaac_extu(read_word, bit_pos, 32 - i);
206
207
15.2k
          bit_pos += i;
208
209
15.2k
          ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
210
15.2k
                                      it_bit_buff->ptr_bit_buf_end);
211
15.2k
          ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
212
15.2k
                                      it_bit_buff->ptr_bit_buf_end);
213
214
15.2k
          i = off + ((WORD32)1 << i);
215
216
15.2k
          if (i <= IQ_TABLE_SIZE_HALF)
217
14.3k
            i = ixheaacd_pow_table_Q13[i];
218
906
          else {
219
906
            err_code |= ixheaacd_inv_quant(&i, ixheaacd_pow_table_Q13);
220
906
          }
221
222
15.2k
          if (out1 < 0) {
223
5.41k
            out1 = -i;
224
9.87k
          } else {
225
9.87k
            out1 = i;
226
9.87k
          }
227
15.2k
          *spec_coef++ = out1;
228
367k
        } else {
229
367k
          if (out1 <= 0) {
230
320k
            out1 = -out1;
231
320k
            out1 = ixheaacd_pow_table_Q13[out1];
232
320k
            *spec_coef++ = -out1;
233
320k
          } else {
234
47.3k
            out1 = ixheaacd_pow_table_Q13[out1];
235
47.3k
            *spec_coef++ = out1;
236
47.3k
          }
237
367k
        }
238
239
382k
        if (sp2 == 16) {
240
13.0k
          i = 4;
241
13.0k
          value = ixheaac_extu(read_word, bit_pos, 23);
242
13.0k
          value = value | 0xfffffe00;
243
13.0k
          norm_val = ixheaac_norm32(value);
244
245
13.0k
          i += (norm_val - 22);
246
247
13.0k
          bit_pos += (norm_val - 21);
248
13.0k
          ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
249
13.0k
                                      it_bit_buff->ptr_bit_buf_end);
250
251
13.0k
          off = ixheaac_extu(read_word, bit_pos, 32 - i);
252
253
13.0k
          bit_pos += i;
254
255
13.0k
          ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
256
13.0k
                                      it_bit_buff->ptr_bit_buf_end);
257
13.0k
          ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
258
13.0k
                                      it_bit_buff->ptr_bit_buf_end);
259
260
13.0k
          i = off + ((WORD32)1 << i);
261
262
13.0k
          if (i <= IQ_TABLE_SIZE_HALF)
263
12.4k
            i = ixheaacd_pow_table_Q13[i];
264
664
          else {
265
664
            err_code |= ixheaacd_inv_quant(&i, ixheaacd_pow_table_Q13);
266
664
          }
267
268
13.0k
          if (out2 < 0) {
269
1.90k
            out2 = -i;
270
11.1k
          } else {
271
11.1k
            out2 = i;
272
11.1k
          }
273
13.0k
          *spec_coef++ = out2;
274
369k
        } else {
275
369k
          if (out2 <= 0) {
276
295k
            out2 = -out2;
277
295k
            out2 = ixheaacd_pow_table_Q13[out2];
278
295k
            *spec_coef++ = -out2;
279
295k
          } else {
280
74.0k
            out2 = ixheaacd_pow_table_Q13[out2];
281
74.0k
            *spec_coef++ = out2;
282
74.0k
          }
283
369k
        }
284
285
382k
        idx -= 2;
286
382k
      } while (idx != 0);
287
288
107k
      if (maximum_bins_short == 120) {
289
89.1k
        spec_coef += (maximum_bins_short - offsets[1]);
290
89.1k
      } else {
291
18.2k
        spec_coef += (MAX_BINS_SHORT - offsets[1]);
292
18.2k
      }
293
294
107k
      grp_idx--;
295
107k
    } while (grp_idx != 0);
296
297
46.5k
    offsets++;
298
299
46.5k
    if (maximum_bins_short == 120) {
300
39.5k
      spec_coef -= (maximum_bins_short * group_len);
301
39.5k
    } else {
302
7.06k
      spec_coef -= (MAX_BINS_SHORT * group_len);
303
7.06k
    }
304
305
46.5k
    no_bands--;
306
46.5k
  } while (no_bands >= 0);
307
308
43.3k
  ptr_read_next = ptr_read_next - increment;
309
43.3k
  ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word,
310
43.3k
                               it_bit_buff->ptr_bit_buf_end);
311
312
43.3k
  it_bit_buff->bit_pos = bit_pos;
313
43.3k
  it_bit_buff->ptr_read_next = ptr_read_next;
314
315
43.3k
  return err_code;
316
43.3k
}
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
67.2k
    const UWORD32 *idx_table) {
322
67.2k
  WORD32 sp1, sp2;
323
67.2k
  WORD32 flush_cw;
324
67.2k
  WORD32 i, value, norm_val, off;
325
67.2k
  WORD idx;
326
67.2k
  WORD32 out1, out2;
327
67.2k
  WORD32 err_code = 0;
328
67.2k
  WORD16 index;
329
67.2k
  WORD32 length;
330
67.2k
  UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next;
331
67.2k
  WORD32 bit_pos = it_bit_buff->bit_pos;
332
67.2k
  WORD32 read_word;
333
67.2k
  WORD32 increment;
334
335
67.2k
  read_word = ixheaacd_aac_showbits_32(ptr_read_next, it_bit_buff->cnt_bits,
336
67.2k
                                       &increment);
337
67.2k
  ptr_read_next += increment;
338
339
1.92M
  for (idx = width; idx != 0; idx -= 2) {
340
1.85M
    {
341
1.85M
      UWORD32 read_word1;
342
343
1.85M
      read_word1 = read_word << bit_pos;
344
1.85M
      ixheaacd_huff_sfb_table(read_word1, &index, &length, code_book_tbl,
345
1.85M
                              idx_table);
346
1.85M
      bit_pos += length;
347
1.85M
      ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
348
1.85M
                                  it_bit_buff->ptr_bit_buf_end);
349
1.85M
    }
350
351
1.85M
    flush_cw = read_word << bit_pos;
352
1.85M
    out1 = index / 17;
353
1.85M
    out2 = index - out1 * 17;
354
1.85M
    sp1 = out1;
355
356
1.85M
    if (out1) {
357
1.09M
      if (flush_cw & 0x80000000) {
358
681k
        out1 = -out1;
359
681k
      }
360
361
1.09M
      bit_pos++;
362
1.09M
      flush_cw = (WORD32)flush_cw << 1;
363
1.09M
    }
364
365
1.85M
    sp2 = out2;
366
1.85M
    if (out2) {
367
1.06M
      bit_pos++;
368
1.06M
      if (flush_cw & 0x80000000) {
369
488k
        out2 = -out2;
370
488k
      }
371
1.06M
    }
372
373
1.85M
    ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
374
1.85M
                                it_bit_buff->ptr_bit_buf_end);
375
376
1.85M
    if (sp1 == 16) {
377
104k
      i = 4;
378
104k
      value = ixheaac_extu(read_word, bit_pos, 23);
379
104k
      value = value | 0xfffffe00;
380
104k
      norm_val = ixheaac_norm32(value);
381
104k
      i += (norm_val - 22);
382
104k
      bit_pos += (norm_val - 21);
383
384
104k
      ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
385
104k
                                  it_bit_buff->ptr_bit_buf_end);
386
387
104k
      off = ixheaac_extu(read_word, bit_pos, 32 - i);
388
389
104k
      bit_pos += i;
390
104k
      ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
391
104k
                                  it_bit_buff->ptr_bit_buf_end);
392
393
104k
      value = *ptr_scratch++;
394
395
104k
      ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
396
104k
                                  it_bit_buff->ptr_bit_buf_end);
397
104k
      i = off + ((WORD32)1 << i);
398
104k
      i += value;
399
400
104k
      if (i <= IQ_TABLE_SIZE_HALF)
401
101k
        i = ixheaacd_pow_table_Q13[i];
402
3.40k
      else {
403
3.40k
        err_code |= ixheaacd_inv_quant(&i, ixheaacd_pow_table_Q13);
404
3.40k
      }
405
104k
      if (out1 < 0) {
406
49.7k
        i = -i;
407
49.7k
      }
408
104k
      *x_invquant++ = i;
409
1.74M
    } else {
410
1.74M
      WORD8 temp = *ptr_scratch++;
411
1.74M
      if (out1 <= 0) {
412
1.39M
        out1 = temp - out1;
413
1.39M
        out1 = ixheaacd_pow_table_Q13[out1];
414
1.39M
        *x_invquant++ = -out1;
415
1.39M
      } else {
416
353k
        out1 += temp;
417
353k
        out1 = ixheaacd_pow_table_Q13[out1];
418
353k
        *x_invquant++ = out1;
419
353k
      }
420
1.74M
    }
421
422
1.85M
    if (sp2 == 16) {
423
99.6k
      i = 4;
424
99.6k
      value = ixheaac_extu(read_word, bit_pos, 23);
425
99.6k
      value = value | 0xfffffe00;
426
99.6k
      norm_val = ixheaac_norm32(value);
427
428
99.6k
      i += (norm_val - 22);
429
430
99.6k
      bit_pos += (norm_val - 21);
431
99.6k
      ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
432
99.6k
                                  it_bit_buff->ptr_bit_buf_end);
433
434
99.6k
      off = ixheaac_extu(read_word, bit_pos, 32 - i);
435
436
99.6k
      bit_pos += i;
437
99.6k
      ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
438
99.6k
                                  it_bit_buff->ptr_bit_buf_end);
439
99.6k
      value = *ptr_scratch++;
440
99.6k
      ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
441
99.6k
                                  it_bit_buff->ptr_bit_buf_end);
442
443
99.6k
      i = off + ((WORD32)1 << i);
444
99.6k
      i += value;
445
99.6k
      if (i <= IQ_TABLE_SIZE_HALF)
446
88.7k
        i = ixheaacd_pow_table_Q13[i];
447
10.9k
      else {
448
10.9k
        err_code |= ixheaacd_inv_quant(&i, ixheaacd_pow_table_Q13);
449
10.9k
      }
450
451
99.6k
      if (out2 < 0) {
452
31.1k
        i = -i;
453
31.1k
      }
454
99.6k
      *x_invquant++ = i;
455
456
1.75M
    } else {
457
1.75M
      WORD8 temp = *ptr_scratch++;
458
1.75M
      if (out2 <= 0) {
459
1.24M
        out2 = temp - out2;
460
1.24M
        out2 = ixheaacd_pow_table_Q13[out2];
461
1.24M
        *x_invquant++ = -out2;
462
1.24M
      } else {
463
508k
        out2 += temp;
464
508k
        out2 = ixheaacd_pow_table_Q13[out2];
465
508k
        *x_invquant++ = out2;
466
508k
      }
467
1.75M
    }
468
1.85M
  }
469
67.2k
  ptr_read_next = ptr_read_next - increment;
470
67.2k
  ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word,
471
67.2k
                               it_bit_buff->ptr_bit_buf_end);
472
473
67.2k
  it_bit_buff->ptr_read_next = ptr_read_next;
474
67.2k
  it_bit_buff->bit_pos = bit_pos;
475
476
67.2k
  return err_code;
477
67.2k
}
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
4.30k
    WORD32 maximum_bins_short) {
484
4.30k
  WORD idx, grp_idx;
485
4.30k
  WORD idx_len;
486
4.30k
  WORD32 *spec_orig;
487
4.30k
  WORD16 index, length;
488
4.30k
  UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next;
489
4.30k
  WORD32 bit_pos = it_bit_buff->bit_pos;
490
4.30k
  WORD32 read_word;
491
4.30k
  WORD32 increment;
492
493
4.30k
  read_word = ixheaacd_aac_showbits_32(ptr_read_next, it_bit_buff->cnt_bits,
494
4.30k
                                       &increment);
495
4.30k
  ptr_read_next += increment;
496
4.30k
  spec_orig = spec_coef;
497
13.9k
  do {
498
13.9k
    idx_len = offsets[1] - offsets[0];
499
13.9k
    grp_idx = group_len;
500
501
22.0k
    do {
502
22.0k
      spec_coef = spec_coef + offsets[0];
503
22.0k
      idx = idx_len;
504
41.1k
      do {
505
41.1k
        UWORD32 read_word1;
506
507
41.1k
        read_word1 = read_word << bit_pos;
508
41.1k
        ixheaacd_huffman_decode(read_word1, &index, &length, code_book_tbl,
509
41.1k
                                idx_table);
510
41.1k
        bit_pos += length;
511
41.1k
        ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
512
41.1k
                                    it_bit_buff->ptr_bit_buf_end);
513
41.1k
        if (tbl_sign) {
514
29.1k
          WORD32 temp_word;
515
29.1k
          WORD32 w, x, y, z;
516
29.1k
          temp_word = read_word << bit_pos;
517
29.1k
          w = index / 27;
518
29.1k
          index = index - w * 27;
519
29.1k
          x = index / 9;
520
29.1k
          index = index - x * 9;
521
29.1k
          y = index / 3;
522
29.1k
          z = index - y * 3;
523
29.1k
          if (w) {
524
19.0k
            w = ixheaacd_pow_table_Q13[w];
525
19.0k
            if (temp_word & 0x80000000) w = -w;
526
19.0k
            temp_word <<= 1;
527
19.0k
            bit_pos++;
528
19.0k
          }
529
29.1k
          *spec_coef++ = w;
530
531
29.1k
          if (x) {
532
20.4k
            x = ixheaacd_pow_table_Q13[x];
533
20.4k
            if (temp_word & 0x80000000) x = -x;
534
20.4k
            temp_word <<= 1;
535
20.4k
            bit_pos++;
536
20.4k
          }
537
29.1k
          *spec_coef++ = x;
538
29.1k
          if (y) {
539
20.9k
            y = ixheaacd_pow_table_Q13[y];
540
20.9k
            if (temp_word & 0x80000000) y = -y;
541
20.9k
            temp_word <<= 1;
542
20.9k
            bit_pos++;
543
20.9k
          }
544
29.1k
          *spec_coef++ = y;
545
29.1k
          if (z) {
546
21.5k
            z = ixheaacd_pow_table_Q13[z];
547
21.5k
            if (temp_word & 0x80000000) z = -z;
548
21.5k
            temp_word <<= 1;
549
21.5k
            bit_pos++;
550
21.5k
          }
551
29.1k
          *spec_coef++ = z;
552
553
29.1k
        }
554
555
12.0k
        else {
556
12.0k
          WORD32 w, x, y, z;
557
558
12.0k
          w = index / 27 - 1;
559
12.0k
          index = index - (w + 1) * 27;
560
12.0k
          x = index / 9 - 1;
561
12.0k
          index = index - (x + 1) * 9;
562
12.0k
          y = index / 3 - 1;
563
12.0k
          z = index - ((y + 1) * 3) - 1;
564
12.0k
          if (w < 0) {
565
871
            w = -w;
566
871
            w = ixheaacd_pow_table_Q13[w];
567
871
            w = -w;
568
871
          } else
569
11.1k
            w = ixheaacd_pow_table_Q13[w];
570
571
12.0k
          *spec_coef++ = w;
572
573
12.0k
          if (x < 0) {
574
770
            x = -x;
575
770
            x = ixheaacd_pow_table_Q13[x];
576
770
            x = -x;
577
770
          } else
578
11.2k
            x = ixheaacd_pow_table_Q13[x];
579
580
12.0k
          *spec_coef++ = x;
581
582
12.0k
          if (y < 0) {
583
924
            y = -y;
584
924
            y = ixheaacd_pow_table_Q13[y];
585
924
            y = -y;
586
924
          } else
587
11.0k
            y = ixheaacd_pow_table_Q13[y];
588
589
12.0k
          *spec_coef++ = y;
590
591
12.0k
          if (z < 0) {
592
1.28k
            z = -z;
593
1.28k
            z = ixheaacd_pow_table_Q13[z];
594
1.28k
            z = -z;
595
1.28k
          } else
596
10.7k
            z = ixheaacd_pow_table_Q13[z];
597
598
12.0k
          *spec_coef++ = z;
599
12.0k
        }
600
601
41.1k
        ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
602
41.1k
                                    it_bit_buff->ptr_bit_buf_end);
603
41.1k
        idx -= 4;
604
41.1k
      } while (idx != 0);
605
606
22.0k
      if (maximum_bins_short == 120) {
607
13.0k
        spec_coef += (maximum_bins_short - offsets[1]);
608
13.0k
      } else {
609
8.99k
        spec_coef += (MAX_BINS_SHORT - offsets[1]);
610
8.99k
      }
611
612
22.0k
      grp_idx--;
613
22.0k
    } while (grp_idx != 0);
614
13.9k
    offsets++;
615
13.9k
    spec_coef = spec_orig;
616
13.9k
    no_bands--;
617
13.9k
  } while (no_bands >= 0);
618
619
4.30k
  ptr_read_next = ptr_read_next - increment;
620
4.30k
  ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word,
621
4.30k
                               it_bit_buff->ptr_bit_buf_end);
622
4.30k
  it_bit_buff->ptr_read_next = ptr_read_next;
623
4.30k
  it_bit_buff->bit_pos = bit_pos;
624
625
4.30k
  return 0;
626
4.30k
}
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
36.5k
    WORD32 tbl_sign, const UWORD32 *idx_table) {
632
36.5k
  WORD idx;
633
36.5k
  WORD16 index, length;
634
36.5k
  UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next;
635
36.5k
  WORD32 bit_pos = it_bit_buff->bit_pos;
636
36.5k
  WORD32 read_word;
637
36.5k
  WORD32 increment;
638
639
36.5k
  read_word = ixheaacd_aac_showbits_32(ptr_read_next, it_bit_buff->cnt_bits,
640
36.5k
                                       &increment);
641
36.5k
  ptr_read_next += increment;
642
643
1.81M
  for (idx = width; idx != 0; idx -= 4) {
644
1.77M
    WORD32 ampres, ampres1;
645
1.77M
    WORD32 ampres2, ampres3;
646
1.77M
    UWORD32 read_word1;
647
648
1.77M
    read_word1 = read_word << bit_pos;
649
1.77M
    ixheaacd_huffman_decode(read_word1, &index, &length, code_book_tbl,
650
1.77M
                            idx_table);
651
1.77M
    bit_pos += length;
652
1.77M
    ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
653
1.77M
                                it_bit_buff->ptr_bit_buf_end);
654
1.77M
    if (tbl_sign) {
655
1.27M
      WORD32 w, x, y, z;
656
1.27M
      WORD32 ampout0, ampout1, ampout2, ampout3;
657
1.27M
      WORD32 temp_word;
658
1.27M
      temp_word = read_word << bit_pos;
659
660
1.27M
      w = index / 27;
661
1.27M
      index = index - w * 27;
662
1.27M
      x = index / 9;
663
1.27M
      index = index - x * 9;
664
1.27M
      y = index / 3;
665
1.27M
      z = index - y * 3;
666
667
1.27M
      ampout0 = w + *ptr_scratch++;
668
1.27M
      ampout0 = ixheaacd_pow_table_Q13[ampout0];
669
670
1.27M
      if (w) {
671
586k
        if (temp_word & 0x80000000) {
672
282k
          ampout0 = -ampout0;
673
282k
        }
674
586k
        temp_word = temp_word << 1;
675
586k
        bit_pos++;
676
690k
      } else {
677
690k
        ampout0 = -ampout0;
678
690k
      }
679
680
1.27M
      ampout1 = x + *ptr_scratch++;
681
1.27M
      ampout1 = ixheaacd_pow_table_Q13[ampout1];
682
683
1.27M
      if (x) {
684
442k
        if (temp_word & 0x80000000) {
685
187k
          ampout1 = -ampout1;
686
187k
        }
687
442k
        temp_word = temp_word << 1;
688
442k
        bit_pos++;
689
834k
      } else {
690
834k
        ampout1 = -ampout1;
691
834k
      }
692
693
1.27M
      ampout2 = y + *ptr_scratch++;
694
1.27M
      ampout2 = ixheaacd_pow_table_Q13[ampout2];
695
696
1.27M
      if (y) {
697
574k
        if (temp_word & 0x80000000) {
698
297k
          ampout2 = -ampout2;
699
297k
        }
700
574k
        temp_word = temp_word << 1;
701
574k
        bit_pos++;
702
701k
      } else {
703
701k
        ampout2 = -ampout2;
704
701k
      }
705
706
1.27M
      ampout3 = z + *ptr_scratch++;
707
1.27M
      ampout3 = ixheaacd_pow_table_Q13[ampout3];
708
709
1.27M
      if (z) {
710
561k
        if (temp_word & 0x80000000) {
711
264k
          ampout3 = -ampout3;
712
264k
        }
713
561k
        temp_word = temp_word << 1;
714
561k
        bit_pos++;
715
715k
      } else {
716
715k
        ampout3 = -ampout3;
717
715k
      }
718
1.27M
      *x_invquant++ = ampout0;
719
1.27M
      *x_invquant++ = ampout1;
720
1.27M
      *x_invquant++ = ampout2;
721
1.27M
      *x_invquant++ = ampout3;
722
1.27M
    } else {
723
501k
      WORD32 w, x, y, z;
724
501k
      ampres = *ptr_scratch++;
725
501k
      ampres1 = *ptr_scratch++;
726
501k
      ampres2 = *ptr_scratch++;
727
501k
      ampres3 = *ptr_scratch++;
728
729
501k
      w = index / 27 - 1;
730
501k
      index = index - (w + 1) * 27;
731
501k
      x = index / 9 - 1;
732
501k
      index = index - (x + 1) * 9;
733
501k
      y = index / 3 - 1;
734
501k
      z = index - ((y + 1) * 3) - 1;
735
501k
      if (w <= 0) {
736
460k
        ampres = ampres - w;
737
460k
        ampres = ixheaacd_pow_table_Q13[ampres];
738
460k
        ampres = -ampres;
739
460k
      } else {
740
41.6k
        ampres += w;
741
41.6k
        ampres = ixheaacd_pow_table_Q13[ampres];
742
41.6k
      }
743
744
501k
      if (x <= 0) {
745
444k
        ampres1 = ampres1 - x;
746
444k
        ampres1 = ixheaacd_pow_table_Q13[ampres1];
747
444k
        ampres1 = -ampres1;
748
444k
      } else {
749
57.0k
        ampres1 += x;
750
57.0k
        ampres1 = ixheaacd_pow_table_Q13[ampres1];
751
57.0k
      }
752
753
501k
      if (y <= 0) {
754
461k
        ampres2 = ampres2 - y;
755
461k
        ampres2 = ixheaacd_pow_table_Q13[ampres2];
756
461k
        ampres2 = -ampres2;
757
461k
      } else {
758
40.5k
        ampres2 += y;
759
40.5k
        ampres2 = ixheaacd_pow_table_Q13[ampres2];
760
40.5k
      }
761
762
501k
      if (z <= 0) {
763
491k
        ampres3 = ampres3 - z;
764
491k
        ampres3 = ixheaacd_pow_table_Q13[ampres3];
765
491k
        ampres3 = -ampres3;
766
491k
      } else {
767
10.2k
        ampres3 += z;
768
10.2k
        ampres3 = ixheaacd_pow_table_Q13[ampres3];
769
10.2k
      }
770
771
501k
      *x_invquant++ = ampres;
772
501k
      *x_invquant++ = ampres1;
773
501k
      *x_invquant++ = ampres2;
774
501k
      *x_invquant++ = ampres3;
775
501k
    }
776
777
1.77M
    ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
778
1.77M
                                it_bit_buff->ptr_bit_buf_end);
779
1.77M
  }
780
781
36.5k
  ptr_read_next = ptr_read_next - increment;
782
36.5k
  ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word,
783
36.5k
                               it_bit_buff->ptr_bit_buf_end);
784
36.5k
  it_bit_buff->ptr_read_next = ptr_read_next;
785
36.5k
  it_bit_buff->bit_pos = bit_pos;
786
787
36.5k
  return 0;
788
36.5k
}
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
7.61k
    WORD32 huff_mode, WORD32 maximum_bins_short) {
795
7.61k
  WORD idx, grp_idx;
796
7.61k
  WORD len_idx;
797
7.61k
  WORD16 index, length;
798
7.61k
  WORD32 y, z;
799
7.61k
  WORD32 *spec_orig = spec_coef;
800
801
7.61k
  UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next;
802
7.61k
  WORD32 bit_pos = it_bit_buff->bit_pos;
803
7.61k
  WORD32 read_word;
804
7.61k
  WORD32 increment;
805
806
7.61k
  read_word = ixheaacd_aac_showbits_32(ptr_read_next, it_bit_buff->cnt_bits,
807
7.61k
                                       &increment);
808
7.61k
  ptr_read_next += increment;
809
810
32.3k
  do {
811
32.3k
    len_idx = offsets[1] - offsets[0];
812
32.3k
    grp_idx = group_len;
813
131k
    do {
814
131k
      spec_coef += offsets[0];
815
131k
      idx = len_idx;
816
371k
      do {
817
371k
        UWORD32 read_word1;
818
371k
        read_word1 = read_word << bit_pos;
819
371k
        ixheaacd_huffman_decode(read_word1, &index, &length, code_book_tbl,
820
371k
                                idx_table);
821
371k
        bit_pos += length;
822
371k
        ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
823
371k
                                    it_bit_buff->ptr_bit_buf_end);
824
371k
        if (tbl_sign) {
825
127k
          WORD32 temp_word;
826
127k
          temp_word = read_word << bit_pos;
827
127k
          y = index / huff_mode;
828
127k
          z = index - huff_mode * y;
829
127k
          if (y) {
830
26.2k
            y = ixheaacd_pow_table_Q13[y];
831
26.2k
            if (temp_word & 0x80000000) y = -y;
832
833
26.2k
            temp_word = temp_word << 1;
834
26.2k
            bit_pos++;
835
26.2k
          }
836
127k
          *spec_coef++ = y;
837
838
127k
          if (z) {
839
21.8k
            z = ixheaacd_pow_table_Q13[z];
840
21.8k
            if (temp_word & 0x80000000) {
841
10.4k
              z = -z;
842
10.4k
            }
843
21.8k
            temp_word <<= 1;
844
21.8k
            bit_pos++;
845
21.8k
          }
846
127k
          *spec_coef++ = z;
847
243k
        } else {
848
243k
          y = (index / huff_mode) - 4;
849
243k
          z = index - ((y + 4) * huff_mode) - 4;
850
243k
          if (y < 0) {
851
27.9k
            y = -y;
852
27.9k
            y = ixheaacd_pow_table_Q13[y];
853
27.9k
            y = -y;
854
27.9k
          } else
855
215k
            y = ixheaacd_pow_table_Q13[y];
856
857
243k
          if (z < 0) {
858
17.6k
            z = -z;
859
17.6k
            z = ixheaacd_pow_table_Q13[z];
860
17.6k
            z = -z;
861
17.6k
          } else
862
226k
            z = ixheaacd_pow_table_Q13[z];
863
864
243k
          *spec_coef++ = y;
865
243k
          *spec_coef++ = z;
866
243k
        }
867
371k
        ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
868
371k
                                    it_bit_buff->ptr_bit_buf_end);
869
371k
        idx -= 2;
870
371k
      } while (idx != 0);
871
872
131k
      if (maximum_bins_short == 120)
873
29.3k
        spec_coef += (maximum_bins_short - offsets[1]);
874
102k
      else
875
102k
        spec_coef += (MAX_BINS_SHORT - offsets[1]);
876
877
131k
      grp_idx--;
878
131k
    } while (grp_idx != 0);
879
880
32.3k
    offsets++;
881
32.3k
    spec_coef = spec_orig;
882
32.3k
    no_bands--;
883
32.3k
  } while (no_bands >= 0);
884
885
7.61k
  ptr_read_next = ptr_read_next - increment;
886
7.61k
  ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word,
887
7.61k
                               it_bit_buff->ptr_bit_buf_end);
888
7.61k
  it_bit_buff->ptr_read_next = ptr_read_next;
889
7.61k
  it_bit_buff->bit_pos = bit_pos;
890
891
7.61k
  return 0;
892
7.61k
}
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
56.5k
{
900
56.5k
  WORD32 ampres;
901
56.5k
  WORD idx;
902
56.5k
  WORD16 index, length;
903
56.5k
  UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next;
904
56.5k
  WORD32 bit_pos = it_bit_buff->bit_pos;
905
56.5k
  WORD32 read_word;
906
56.5k
  WORD32 increment;
907
908
56.5k
  read_word = ixheaacd_aac_showbits_32(ptr_read_next, it_bit_buff->cnt_bits,
909
56.5k
                                       &increment);
910
56.5k
  ptr_read_next += increment;
911
912
1.15M
  for (idx = width; idx != 0; idx -= 2) {
913
1.10M
    {
914
1.10M
      UWORD32 read_word1;
915
1.10M
      read_word1 = read_word << bit_pos;
916
1.10M
      ixheaacd_huffman_decode(read_word1, &index, &length, code_book_tbl,
917
1.10M
                              idx_table);
918
1.10M
      bit_pos += length;
919
1.10M
      ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
920
1.10M
                                  it_bit_buff->ptr_bit_buf_end);
921
1.10M
    }
922
923
1.10M
    if (tbl_sign) {
924
556k
      WORD32 out0, out1, temp_word;
925
556k
      WORD32 ampout0, ampout1;
926
927
556k
      ampout0 = *ptr_scratch++;
928
556k
      ampout1 = *ptr_scratch++;
929
556k
      out0 = index / huff_mode;
930
556k
      out1 = index - huff_mode * out0;
931
556k
      ampout0 += out0;
932
556k
      ampout0 = ixheaacd_pow_table_Q13[ampout0];
933
934
556k
      ampout1 += out1;
935
556k
      ampout1 = ixheaacd_pow_table_Q13[ampout1];
936
556k
      temp_word = read_word << bit_pos;
937
556k
      if (out0) {
938
331k
        if (temp_word & 0x80000000) {
939
117k
          ampout0 = -(ampout0);
940
117k
        }
941
942
331k
        bit_pos++;
943
331k
        temp_word = temp_word << 1;
944
331k
      } else {
945
224k
        ampout0 = -(ampout0);
946
224k
      }
947
948
556k
      if (out1) {
949
348k
        if (temp_word & 0x80000000) {
950
154k
          ampout1 = -(ampout1);
951
154k
        }
952
348k
        bit_pos++;
953
348k
      } else {
954
207k
        ampout1 = -(ampout1);
955
207k
      }
956
957
556k
      ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
958
556k
                                  it_bit_buff->ptr_bit_buf_end);
959
556k
      *x_invquant++ = ampout0;
960
556k
      *x_invquant++ = ampout1;
961
556k
    } else {
962
545k
      WORD32 y, z;
963
545k
      y = (index / huff_mode) - 4;
964
545k
      z = index - ((y + 4) * huff_mode) - 4;
965
966
545k
      ampres = *ptr_scratch++;
967
545k
      if (y <= 0) {
968
382k
        ampres = ampres - y;
969
382k
        ampres = ixheaacd_pow_table_Q13[ampres];
970
382k
        *x_invquant++ = -ampres;
971
382k
      } else {
972
162k
        ampres += y;
973
162k
        *x_invquant++ = ixheaacd_pow_table_Q13[ampres];
974
162k
      }
975
545k
      ampres = *ptr_scratch++;
976
545k
      if (z <= 0) {
977
392k
        ampres = ampres - z;
978
392k
        ampres = ixheaacd_pow_table_Q13[ampres];
979
392k
        *x_invquant++ = -ampres;
980
392k
      } else {
981
152k
        ampres += z;
982
152k
        *x_invquant++ = ixheaacd_pow_table_Q13[ampres];
983
152k
      }
984
545k
    }
985
1.10M
    ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
986
1.10M
                                it_bit_buff->ptr_bit_buf_end);
987
1.10M
  }
988
989
56.5k
  ptr_read_next = ptr_read_next - increment;
990
56.5k
  ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word,
991
56.5k
                               it_bit_buff->ptr_bit_buf_end);
992
56.5k
  it_bit_buff->ptr_read_next = ptr_read_next;
993
56.5k
  it_bit_buff->bit_pos = bit_pos;
994
995
56.5k
  return 0;
996
56.5k
}
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
55.2k
                             WORD32 maximum_bins_short) {
1003
55.2k
  WORD ret_val = 0;
1004
55.2k
  WORD start_bit_pos = it_bit_buff->bit_pos;
1005
55.2k
  UWORD8 *start_read_pos = it_bit_buff->ptr_read_next;
1006
55.2k
  const UWORD16 *cb_table = (UWORD16 *)(ptr_aac_tables->code_book[cb_no]);
1007
55.2k
  WORD32 huff_mode;
1008
55.2k
  const UWORD32 *idx_table = (UWORD32 *)(ptr_aac_tables->index_table[cb_no]);
1009
55.2k
  WORD32 *pow_table =
1010
55.2k
      (WORD32 *)ptr_aac_tables->pstr_block_tables->ixheaacd_pow_table_Q13;
1011
55.2k
  WORD32 no_bands = sfb - start - 1;
1012
55.2k
  WORD16 *band_offset = sfb_offset + start;
1013
1014
55.2k
  if (cb_no == 11) {
1015
43.3k
    const UWORD32 *idx_table =
1016
43.3k
        ptr_aac_tables->pstr_huffmann_tables->idx_table_hf11;
1017
43.3k
    const UWORD16 *cb_table =
1018
43.3k
        ptr_aac_tables->pstr_huffmann_tables->input_table_cb11;
1019
1020
43.3k
    ret_val = ixheaacd_huffman_dec_word1(it_bit_buff, spec_coef, band_offset,
1021
43.3k
                                         no_bands, group_len, cb_table,
1022
43.3k
                                         pow_table, idx_table, maximum_bins_short);
1023
1024
43.3k
  } else if (cb_no <= 4) {
1025
4.30k
    WORD32 tbl_sign = 0;
1026
1027
4.30k
    if (cb_no > 2) {
1028
3.77k
      tbl_sign = 1;
1029
3.77k
    }
1030
4.30k
    ret_val = ixheaacd_huffman_dec_quad(it_bit_buff, spec_coef, band_offset,
1031
4.30k
                                        no_bands, group_len, cb_table,
1032
4.30k
                                        pow_table, tbl_sign, idx_table, maximum_bins_short);
1033
4.30k
  }
1034
1035
7.61k
  else if (cb_no <= 10) {
1036
7.61k
    WORD32 tbl_sign = 0;
1037
7.61k
    huff_mode = 9;
1038
7.61k
    if (cb_no > 6) {
1039
4.97k
      if (cb_no > 8)
1040
3.48k
        huff_mode = 13;
1041
1.49k
      else
1042
1.49k
        huff_mode = 8;
1043
4.97k
      tbl_sign = 1;
1044
4.97k
    }
1045
7.61k
    ret_val = ixheaacd_huffman_dec_pair(
1046
7.61k
        it_bit_buff, spec_coef, band_offset, no_bands, group_len, cb_table,
1047
7.61k
        pow_table, tbl_sign, idx_table, huff_mode, maximum_bins_short);
1048
7.61k
  }
1049
1050
55.2k
  {
1051
55.2k
    WORD bits_cons;
1052
55.2k
    bits_cons = (WORD)(((it_bit_buff->ptr_read_next - start_read_pos) << 3) +
1053
55.2k
                       (it_bit_buff->bit_pos - start_bit_pos));
1054
55.2k
    it_bit_buff->cnt_bits -= bits_cons;
1055
55.2k
  }
1056
55.2k
  return ret_val;
1057
55.2k
}
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
160k
                                WORD32 *x_invquant, WORD8 *scratch_ptr) {
1063
160k
  WORD ret_val = 0;
1064
160k
  WORD32 huff_mode;
1065
160k
  WORD start_bit_pos = it_bit_buff->bit_pos;
1066
160k
  WORD32 cnt_bits = it_bit_buff->cnt_bits;
1067
160k
  WORD32 *pow_table =
1068
160k
      (WORD32 *)ptr_aac_tables->pstr_block_tables->ixheaacd_pow_table_Q13;
1069
160k
  UWORD8 *start_read_pos = it_bit_buff->ptr_read_next;
1070
1071
160k
  const UWORD16 *cb_table = (UWORD16 *)(ptr_aac_tables->code_book[cb_no]);
1072
160k
  const UWORD32 *idx_table = (UWORD32 *)(ptr_aac_tables->index_table[cb_no]);
1073
1074
160k
  if (cb_no == 11) {
1075
67.2k
    const UWORD16 *cb_table =
1076
67.2k
        ptr_aac_tables->pstr_huffmann_tables->input_table_cb11;
1077
1078
67.2k
    ret_val = ixheaacd_huffman_dec_word2_11(
1079
67.2k
        it_bit_buff, width, cb_table, x_invquant, pow_table, scratch_ptr,
1080
67.2k
        ptr_aac_tables->pstr_huffmann_tables->idx_table_hf11);
1081
93.0k
  } else if (cb_no <= 4) {
1082
36.5k
    WORD32 tbl_sign = 0;
1083
36.5k
    if (cb_no > 2) tbl_sign = 1;
1084
36.5k
    ret_val = ixheaacd_huffman_dec_word2_quad(it_bit_buff, width, cb_table,
1085
36.5k
                                              x_invquant, pow_table,
1086
36.5k
                                              scratch_ptr, tbl_sign, idx_table);
1087
56.5k
  } else if (cb_no <= 10) {
1088
56.5k
    WORD32 tbl_sign = 0;
1089
56.5k
    huff_mode = 9;
1090
56.5k
    if (cb_no > 6) {
1091
51.2k
      if (cb_no > 8) {
1092
2.86k
        huff_mode = 13;
1093
48.4k
      } else {
1094
48.4k
        huff_mode = 8;
1095
48.4k
      }
1096
1097
51.2k
      tbl_sign = 1;
1098
51.2k
    }
1099
56.5k
    ret_val = ixheaacd_huffman_dec_word2_pair(
1100
56.5k
        it_bit_buff, width, cb_table, x_invquant, pow_table, scratch_ptr,
1101
56.5k
        tbl_sign, idx_table, huff_mode);
1102
56.5k
  }
1103
1104
160k
  {
1105
160k
    WORD bits_cons;
1106
160k
    if (it_bit_buff->bit_pos <= 7) {
1107
160k
      bits_cons = (WORD)(((it_bit_buff->ptr_read_next - start_read_pos) << 3) +
1108
160k
                         (it_bit_buff->bit_pos - start_bit_pos));
1109
160k
      if (bits_cons > cnt_bits)
1110
28
      {
1111
28
        return IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES;
1112
28
      }
1113
160k
      it_bit_buff->cnt_bits = cnt_bits - bits_cons;
1114
160k
    } else {
1115
70
      it_bit_buff->ptr_read_next += (it_bit_buff->bit_pos) >> 3;
1116
70
      it_bit_buff->bit_pos = it_bit_buff->bit_pos & 0x7;
1117
70
      if ((SIZE_T)(it_bit_buff->ptr_read_next) > (SIZE_T)(it_bit_buff->ptr_bit_buf_end + 1))
1118
70
      {
1119
70
        it_bit_buff->ptr_read_next = it_bit_buff->ptr_bit_buf_end + 1;
1120
70
        return IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES;
1121
70
      }
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
160k
  }
1128
160k
  return ret_val;
1129
160k
}
1130
1131
VOID ixheaacd_dec_copy_outsample(WORD32 *out_samples, WORD32 *p_overlap_buffer,
1132
2.74k
                                 WORD32 size, WORD16 stride) {
1133
2.74k
  WORD32 i;
1134
1135
1.15M
  for (i = 0; i < size; i++) {
1136
1.15M
    out_samples[stride*i] = (ixheaac_shl16_sat((WORD16)(p_overlap_buffer[i]), 1) << 14);
1137
1.15M
  }
1138
2.74k
}
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.1k
                           WORD16 stride , WORD slot_element) {
1143
21.1k
  WORD32 accu;
1144
21.1k
  WORD32 i;
1145
21.1k
  WORD16 rounding_fac = -0x2000;
1146
1147
21.1k
  WORD32 *window_i = (WORD32 *)window;
1148
1149
21.1k
  WORD16 *ptr_out1, *ptr_out2;
1150
1151
21.1k
  WORD32 *pwin1, *pwin2;
1152
21.1k
  WORD32 *pCoef = &coef[size * 2 - 1 - 0];
1153
1154
21.1k
  WORD16 * out  = (WORD16*)out_tmp - slot_element;
1155
1156
21.1k
  pwin1 = &window_i[size - 1 - 0];
1157
21.1k
  pwin2 = &window_i[size + 0];
1158
1159
21.1k
  ptr_out1 = &out[stride * (size - 1 - 0)];
1160
21.1k
  ptr_out2 = &out[stride * (size + 0)];
1161
1162
5.37M
  for (i = 0; i < size; i++) {
1163
5.35M
    WORD32 win1, win2, coeff;
1164
5.35M
    WORD32 prev_data = *prev++;
1165
1166
5.35M
    win1 = *pwin1--;
1167
5.35M
    coeff = *pCoef--;
1168
5.35M
    win2 = *pwin2++;
1169
1170
5.35M
    accu = ixheaac_sub32_sat(
1171
5.35M
        ixheaac_shl32_dir_sat_limit(ixheaac_mult32_shl(coeff, win1), q_shift),
1172
5.35M
        ixheaac_mac32x16in32_shl(rounding_fac, win2, (WORD16)(prev_data)));
1173
1174
5.35M
    accu = ixheaac_add32_sat(accu, accu);
1175
5.35M
    accu = ixheaac_add32_sat(accu, accu);
1176
1177
5.35M
    *ptr_out1 = ixheaac_shr32(accu, 16);
1178
5.35M
    ptr_out1 -= stride;
1179
1180
5.35M
    accu = ixheaac_sub32_sat(
1181
5.35M
        ixheaac_shl32_dir_sat_limit(
1182
5.35M
            ixheaac_mult32_shl(ixheaac_negate32_sat(coeff), win2), q_shift),
1183
5.35M
        ixheaac_mac32x16in32_shl(rounding_fac, win1, (WORD16)(prev_data)));
1184
1185
5.35M
    accu = ixheaac_add32_sat(accu, accu);
1186
5.35M
    accu = ixheaac_add32_sat(accu, accu);
1187
1188
5.35M
    *ptr_out2 = ixheaac_shr32(accu, 16);
1189
5.35M
    ptr_out2 += stride;
1190
5.35M
  }
1191
21.1k
}
1192
1193
VOID ixheaacd_over_lap_add1_dec(WORD32 *coef, WORD32 *prev, WORD32 *out,
1194
                                const WORD16 *window, WORD16 q_shift,
1195
158k
                                WORD16 size, WORD16 ch_fac) {
1196
158k
  WORD32 accu;
1197
158k
  WORD32 i;
1198
158k
  WORD16 rounding_fac = 0;
1199
1200
24.8M
  for (i = 0; i < size; i++) {
1201
24.6M
    WORD16 window1, window2;
1202
1203
24.6M
    window1 = window[2 * size - 2 * i - 1];
1204
24.6M
    window2 = window[2 * size - 2 * i - 2];
1205
24.6M
    accu = ixheaac_sub32_sat(
1206
24.6M
        ixheaac_shl32_dir_sat_limit(
1207
24.6M
            ixheaac_mult32x16in32(coef[size * 2 - 1 - i], window2), q_shift),
1208
24.6M
        ixheaacd_mac32x16in32_sat(rounding_fac, prev[i], window1));
1209
24.6M
    out[ch_fac * (size - i - 1)] = accu;
1210
24.6M
    accu = ixheaac_sub32_sat(
1211
24.6M
        ixheaac_shl32_dir_sat_limit(
1212
24.6M
            ixheaac_mult32x16in32(ixheaac_negate32_sat(coef[size * 2 - 1 - i]),
1213
24.6M
                                   window1),
1214
24.6M
            q_shift),
1215
24.6M
        ixheaacd_mac32x16in32_sat(rounding_fac, prev[i], window2));
1216
24.6M
    out[ch_fac * (size + i)] = accu;
1217
24.6M
  }
1218
158k
}
1219
1220
VOID ixheaacd_over_lap_add2_dec(WORD32 *coef, WORD32 *prev, WORD32 *out,
1221
                                const WORD16 *window, WORD16 q_shift,
1222
167k
                                WORD16 size, WORD16 ch_fac) {
1223
167k
  WORD32 accu;
1224
167k
  WORD32 i;
1225
1226
10.6M
  for (i = 0; i < size; i++) {
1227
10.5M
    accu = ixheaac_sub32_sat(
1228
10.5M
        ixheaac_mult32x16in32(coef[size + i], window[2 * i]),
1229
10.5M
        ixheaac_mult32x16in32(prev[size - 1 - i], window[2 * i + 1]));
1230
10.5M
    out[ch_fac * i] = ixheaac_shr32_sat(accu, 16 - (q_shift + 1));
1231
10.5M
  }
1232
1233
10.6M
  for (i = 0; i < size; i++) {
1234
10.5M
    accu = ixheaac_sub32_sat(
1235
10.5M
        ixheaac_mult32x16in32(ixheaac_negate32_sat(coef[size * 2 - 1 - i]),
1236
10.5M
                               window[2 * size - 2 * i - 1]),
1237
10.5M
        ixheaac_mult32x16in32(prev[i], window[2 * size - 2 * i - 2]));
1238
10.5M
    out[ch_fac * (i + size)] = ixheaac_shr32_sat(accu, 16 - (q_shift + 1));
1239
10.5M
  }
1240
167k
}
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.70M
                                 WORD32 aac_sf_data_resil_flag) {
1246
4.70M
  WORD32 j;
1247
1248
4.70M
  WORD32 temp1;
1249
4.70M
  WORD32 q_factor;
1250
4.70M
  WORD32 buffer1;
1251
4.70M
  WORD16 scale_short;
1252
1253
4.70M
  object_type = 0;
1254
4.70M
  aac_sf_data_resil_flag = 0;
1255
1256
4.70M
  if (scale_factor < 24) {
1257
21.9M
    for (j = width; j > 0; j--) {
1258
19.8M
      *x_invquant++ = 0;
1259
19.8M
    }
1260
2.58M
  } else {
1261
2.58M
    WORD32 shift;
1262
1263
2.58M
    if (total_channels > 2)
1264
148k
      q_factor = 34 - (scale_factor >> 2);
1265
2.43M
    else
1266
2.43M
      q_factor = 37 - (scale_factor >> 2);
1267
1268
2.58M
    scale_short = ptr_scale_table[(scale_factor & 0x0003)];
1269
2.58M
    shift = q_factor;
1270
2.58M
    if (shift > 0) {
1271
947k
      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
947k
      } else {
1279
15.2M
        for (j = width; j > 0; j--) {
1280
14.2M
          temp1 = *x_invquant;
1281
14.2M
          buffer1 = ixheaac_mult32x16in32_shl(temp1, scale_short);
1282
14.2M
          buffer1 = ixheaac_shr32(buffer1, shift);
1283
14.2M
          *x_invquant++ = buffer1;
1284
14.2M
        }
1285
947k
      }
1286
1.63M
    } else {
1287
1.63M
      shift = -shift;
1288
1.63M
      if (shift > 0) {
1289
1.63M
        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.63M
        } else {
1298
17.7M
          for (j = width; j > 0; j--) {
1299
16.0M
            temp1 = *x_invquant;
1300
16.0M
            temp1 = ixheaac_shl32(temp1, shift - 1);
1301
16.0M
            buffer1 = ixheaac_mult32x16in32_shl(temp1, scale_short);
1302
16.0M
            buffer1 = ixheaac_shl32(buffer1, 1);
1303
16.0M
            *x_invquant++ = buffer1;
1304
16.0M
          }
1305
1.63M
        }
1306
1307
1.63M
      } else {
1308
2.26k
        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
2.26k
        } else {
1315
31.4k
          for (j = width; j > 0; j--) {
1316
29.2k
            temp1 = *x_invquant;
1317
29.2k
            buffer1 = ixheaac_mult32x16in32_shl(temp1, scale_short);
1318
29.2k
            *x_invquant++ = buffer1;
1319
29.2k
          }
1320
2.26k
        }
1321
2.26k
      }
1322
1.63M
    }
1323
2.58M
  }
1324
4.70M
}
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
583k
                                       WORD32 aac_sf_data_resil_flag) {
1332
583k
  WORD32 i;
1333
583k
  WORD16 scale_factor;
1334
1335
5.29M
  for (i = no_band - 1; i >= 0; i--) {
1336
4.70M
    scale_factor = *scale_fact++;
1337
4.70M
    ixheaacd_process_single_scf(scale_factor, x_invquant, *width,
1338
4.70M
                                ptr_scale_table, total_channels, object_type,
1339
4.70M
                                aac_sf_data_resil_flag);
1340
1341
4.70M
    x_invquant += *width;
1342
4.70M
    width++;
1343
4.70M
  }
1344
583k
}
1345
1346
VOID ixheaacd_right_shift_block(WORD32 *p_spectrum, WORD32 length,
1347
10.5k
                                WORD32 shift_val) {
1348
10.5k
  WORD32 i;
1349
10.5k
  WORD32 temp1, temp2;
1350
10.5k
  WORD32 *temp_ptr = &p_spectrum[0];
1351
10.5k
  length = length >> 2;
1352
1353
745k
  for (i = length - 1; i >= 0; i--) {
1354
734k
    temp1 = *temp_ptr;
1355
734k
    temp2 = *(temp_ptr + 1);
1356
734k
    *temp_ptr++ = temp1 >> shift_val;
1357
734k
    temp1 = *(temp_ptr + 1);
1358
734k
    *temp_ptr++ = temp2 >> shift_val;
1359
734k
    temp2 = *(temp_ptr + 1);
1360
734k
    *temp_ptr++ = temp1 >> shift_val;
1361
734k
    *temp_ptr++ = temp2 >> shift_val;
1362
734k
  }
1363
10.5k
}