Coverage Report

Created: 2026-09-03 07:01

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