Coverage Report

Created: 2025-09-17 06:59

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