Coverage Report

Created: 2024-06-21 06:40

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