Coverage Report

Created: 2025-12-10 06:50

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