Coverage Report

Created: 2026-06-13 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/encoder/ixheaace_bits_count.c
Line
Count
Source
1
/******************************************************************************
2
 *                                                                            *
3
 * Copyright (C) 2023 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 <limits.h>
21
#include <stdlib.h>
22
#include "ixheaac_type_def.h"
23
#include "ixheaac_constants.h"
24
#include "impd_drc_common_enc.h"
25
#include "impd_drc_uni_drc.h"
26
#include "impd_drc_tables.h"
27
#include "impd_drc_api.h"
28
#include "ixheaace_api.h"
29
#include "ixheaace_aac_constants.h"
30
31
#include "ixheaac_basic_ops32.h"
32
#include "ixheaac_basic_ops16.h"
33
#include "ixheaac_basic_ops40.h"
34
#include "ixheaac_basic_ops.h"
35
36
#include "ixheaace_bitbuffer.h"
37
#include "ixheaace_psy_const.h"
38
#include "ixheaace_tns.h"
39
#include "ixheaace_tns_params.h"
40
#include "ixheaace_rom.h"
41
#include "ixheaace_bits_count.h"
42
43
#include "ixheaace_common_rom.h"
44
#include "ixheaace_common_utils.h"
45
46
VOID ia_enhaacplus_enc_count1_2_3_4_5_6_7_8_9_10_11(const WORD16 *values, const WORD32 width,
47
                                                    WORD32 *bitcnt,
48
                                                    ixheaace_huffman_tables *pstr_huffman_tbl,
49
9.38M
                                                    WORD32 invalid_bitcnt) {
50
9.38M
  WORD32 i;
51
9.38M
  WORD32 bits1_2, bits3_4, bits5_6, bits7_8, bits9_10, bit11, sc;
52
9.38M
  WORD32 temp_0, temp_1, temp_2, temp_3;
53
9.38M
  (VOID) invalid_bitcnt;
54
9.38M
  bits1_2 = 0;
55
9.38M
  bits3_4 = 0;
56
9.38M
  bits5_6 = 0;
57
9.38M
  bits7_8 = 0;
58
9.38M
  bits9_10 = 0;
59
9.38M
  bit11 = 0;
60
9.38M
  sc = 0;
61
62
44.2M
  for (i = 0; i < width; i += 4) {
63
34.8M
    temp_0 = values[i + 0];
64
34.8M
    temp_1 = values[i + 1];
65
34.8M
    temp_2 = values[i + 2];
66
34.8M
    temp_3 = values[i + 3];
67
68
34.8M
    bits1_2 +=
69
34.8M
        EXPAND(pstr_huffman_tbl->huff_ltab1_2[temp_0 + 1][temp_1 + 1][temp_2 + 1][temp_3 + 1]);
70
71
34.8M
    bits5_6 += EXPAND(pstr_huffman_tbl->huff_ltab5_6[temp_0 + 4][temp_1 + 4]);
72
73
34.8M
    bits5_6 += EXPAND(pstr_huffman_tbl->huff_ltab5_6[temp_2 + 4][temp_3 + 4]);
74
75
34.8M
    sc += (temp_0 != 0) + (temp_1 != 0) + (temp_2 != 0) + (temp_3 != 0);
76
77
34.8M
    temp_0 = abs32(temp_0);
78
34.8M
    temp_1 = abs32(temp_1);
79
34.8M
    temp_2 = abs32(temp_2);
80
34.8M
    temp_3 = abs32(temp_3);
81
82
34.8M
    bits3_4 += EXPAND(pstr_huffman_tbl->huff_ltab3_4[temp_0][temp_1][temp_2][temp_3]);
83
84
34.8M
    bits7_8 += EXPAND(pstr_huffman_tbl->huff_ltab7_8[temp_0][temp_1]);
85
86
34.8M
    bits7_8 += EXPAND(pstr_huffman_tbl->huff_ltab7_8[temp_2][temp_3]);
87
88
34.8M
    bits9_10 += EXPAND(pstr_huffman_tbl->huff_ltab9_10[temp_0][temp_1]);
89
90
34.8M
    bits9_10 += EXPAND(pstr_huffman_tbl->huff_ltab9_10[temp_2][temp_3]);
91
92
34.8M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[temp_0][temp_1]);
93
94
34.8M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[temp_2][temp_3]);
95
34.8M
  }
96
97
9.38M
  bitcnt[1] = HI_EXPLTAB(bits1_2);
98
99
9.38M
  bitcnt[2] = LO_EXPLTAB(bits1_2);
100
101
9.38M
  bitcnt[3] = HI_EXPLTAB(bits3_4) + sc;
102
103
9.38M
  bitcnt[4] = LO_EXPLTAB(bits3_4) + sc;
104
105
9.38M
  bitcnt[5] = HI_EXPLTAB(bits5_6);
106
107
9.38M
  bitcnt[6] = LO_EXPLTAB(bits5_6);
108
109
9.38M
  bitcnt[7] = HI_EXPLTAB(bits7_8) + sc;
110
111
9.38M
  bitcnt[8] = LO_EXPLTAB(bits7_8) + sc;
112
113
9.38M
  bitcnt[9] = HI_EXPLTAB(bits9_10) + sc;
114
115
9.38M
  bitcnt[10] = LO_EXPLTAB(bits9_10) + sc;
116
117
9.38M
  bitcnt[11] = bit11 + sc;
118
9.38M
}
119
120
static VOID ia_enhaacplus_enc_count3_4_5_6_7_8_9_10_11(const WORD16 *values, const WORD32 width,
121
                                                       WORD32 *bitcnt,
122
                                                       ixheaace_huffman_tables *pstr_huffman_tbl,
123
681k
                                                       WORD32 invalid_bitcnt) {
124
681k
  WORD32 i;
125
681k
  WORD32 bits3_4, bits5_6, bits7_8, bits9_10, bit11, sc;
126
681k
  WORD32 temp_0, temp_1, temp_2, temp_3;
127
128
681k
  bits3_4 = 0;
129
681k
  bits5_6 = 0;
130
681k
  bits7_8 = 0;
131
681k
  bits9_10 = 0;
132
681k
  bit11 = 0;
133
681k
  sc = 0;
134
135
2.89M
  for (i = 0; i < width; i += 4) {
136
2.21M
    temp_0 = values[i + 0];
137
2.21M
    temp_1 = values[i + 1];
138
2.21M
    temp_2 = values[i + 2];
139
2.21M
    temp_3 = values[i + 3];
140
141
2.21M
    bits5_6 += EXPAND(pstr_huffman_tbl->huff_ltab5_6[temp_0 + 4][temp_1 + 4]);
142
143
2.21M
    bits5_6 += EXPAND(pstr_huffman_tbl->huff_ltab5_6[temp_2 + 4][temp_3 + 4]);
144
145
2.21M
    temp_0 = abs32(temp_0);
146
2.21M
    temp_1 = abs32(temp_1);
147
2.21M
    temp_2 = abs32(temp_2);
148
2.21M
    temp_3 = abs32(temp_3);
149
150
2.21M
    bits3_4 += EXPAND(pstr_huffman_tbl->huff_ltab3_4[temp_0][temp_1][temp_2][temp_3]);
151
152
2.21M
    bits7_8 += EXPAND(pstr_huffman_tbl->huff_ltab7_8[temp_0][temp_1]);
153
154
2.21M
    bits7_8 += EXPAND(pstr_huffman_tbl->huff_ltab7_8[temp_2][temp_3]);
155
156
2.21M
    bits9_10 += EXPAND(pstr_huffman_tbl->huff_ltab9_10[temp_0][temp_1]);
157
158
2.21M
    bits9_10 += EXPAND(pstr_huffman_tbl->huff_ltab9_10[temp_2][temp_3]);
159
160
2.21M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[temp_0][temp_1]);
161
162
2.21M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[temp_2][temp_3]);
163
164
2.21M
    sc += (temp_0 > 0) + (temp_1 > 0) + (temp_2 > 0) + (temp_3 > 0);
165
2.21M
  }
166
167
681k
  bitcnt[1] = invalid_bitcnt;
168
681k
  bitcnt[2] = invalid_bitcnt;
169
170
681k
  bitcnt[3] = HI_EXPLTAB(bits3_4) + sc;
171
172
681k
  bitcnt[4] = LO_EXPLTAB(bits3_4) + sc;
173
174
681k
  bitcnt[5] = HI_EXPLTAB(bits5_6);
175
176
681k
  bitcnt[6] = LO_EXPLTAB(bits5_6);
177
178
681k
  bitcnt[7] = HI_EXPLTAB(bits7_8) + sc;
179
180
681k
  bitcnt[8] = LO_EXPLTAB(bits7_8) + sc;
181
182
681k
  bitcnt[9] = HI_EXPLTAB(bits9_10) + sc;
183
184
681k
  bitcnt[10] = LO_EXPLTAB(bits9_10) + sc;
185
186
681k
  bitcnt[11] = bit11 + sc;
187
681k
}
188
189
static VOID ia_enhaacplus_enc_count5_6_7_8_9_10_11(const WORD16 *values, const WORD32 width,
190
                                                   WORD32 *bitcnt,
191
                                                   ixheaace_huffman_tables *pstr_huffman_tbl,
192
623k
                                                   WORD32 invalid_bitcnt) {
193
623k
  WORD32 i;
194
623k
  WORD32 bits5_6, bits7_8, bits9_10, bit11, sc;
195
623k
  WORD32 temp_0, temp_1;
196
197
623k
  bits5_6 = 0;
198
623k
  bits7_8 = 0;
199
623k
  bits9_10 = 0;
200
623k
  bit11 = 0;
201
623k
  sc = 0;
202
203
4.83M
  for (i = 0; i < width; i += 2) {
204
4.21M
    temp_0 = values[i + 0];
205
4.21M
    temp_1 = values[i + 1];
206
207
4.21M
    bits5_6 += EXPAND(pstr_huffman_tbl->huff_ltab5_6[temp_0 + 4][temp_1 + 4]);
208
209
4.21M
    temp_0 = abs32(temp_0);
210
4.21M
    temp_1 = abs32(temp_1);
211
212
4.21M
    bits7_8 += EXPAND(pstr_huffman_tbl->huff_ltab7_8[temp_0][temp_1]);
213
214
4.21M
    bits9_10 += EXPAND(pstr_huffman_tbl->huff_ltab9_10[temp_0][temp_1]);
215
216
4.21M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[temp_0][temp_1]);
217
218
4.21M
    sc += (temp_0 > 0) + (temp_1 > 0);
219
4.21M
  }
220
221
623k
  bitcnt[1] = invalid_bitcnt;
222
623k
  bitcnt[2] = invalid_bitcnt;
223
623k
  bitcnt[3] = invalid_bitcnt;
224
623k
  bitcnt[4] = invalid_bitcnt;
225
226
623k
  bitcnt[5] = HI_EXPLTAB(bits5_6);
227
228
623k
  bitcnt[6] = LO_EXPLTAB(bits5_6);
229
230
623k
  bitcnt[7] = HI_EXPLTAB(bits7_8) + sc;
231
232
623k
  bitcnt[8] = LO_EXPLTAB(bits7_8) + sc;
233
234
623k
  bitcnt[9] = HI_EXPLTAB(bits9_10) + sc;
235
236
623k
  bitcnt[10] = LO_EXPLTAB(bits9_10) + sc;
237
238
623k
  bitcnt[11] = bit11 + sc;
239
623k
}
240
241
static VOID ia_enhaacplus_enc_count7_8_9_10_11(const WORD16 *values, const WORD32 width,
242
                                               WORD32 *bitcnt,
243
                                               ixheaace_huffman_tables *pstr_huffman_tbl,
244
568k
                                               WORD32 invalid_bitcnt) {
245
568k
  WORD32 i;
246
568k
  WORD32 bits7_8, bits9_10, bit11, sc;
247
568k
  WORD32 temp_0, temp_1;
248
249
568k
  bits7_8 = 0;
250
568k
  bits9_10 = 0;
251
568k
  bit11 = 0;
252
568k
  sc = 0;
253
254
4.57M
  for (i = 0; i < width; i += 2) {
255
4.00M
    temp_0 = abs32(values[i + 0]);
256
4.00M
    temp_1 = abs32(values[i + 1]);
257
258
4.00M
    bits7_8 += EXPAND(pstr_huffman_tbl->huff_ltab7_8[temp_0][temp_1]);
259
260
4.00M
    bits9_10 += EXPAND(pstr_huffman_tbl->huff_ltab9_10[temp_0][temp_1]);
261
262
4.00M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[temp_0][temp_1]);
263
264
4.00M
    sc += (temp_0 > 0) + (temp_1 > 0);
265
4.00M
  }
266
267
568k
  bitcnt[1] = invalid_bitcnt;
268
568k
  bitcnt[2] = invalid_bitcnt;
269
568k
  bitcnt[3] = invalid_bitcnt;
270
568k
  bitcnt[4] = invalid_bitcnt;
271
568k
  bitcnt[5] = invalid_bitcnt;
272
568k
  bitcnt[6] = invalid_bitcnt;
273
274
568k
  bitcnt[7] = HI_EXPLTAB(bits7_8) + sc;
275
276
568k
  bitcnt[8] = LO_EXPLTAB(bits7_8) + sc;
277
278
568k
  bitcnt[9] = HI_EXPLTAB(bits9_10) + sc;
279
280
568k
  bitcnt[10] = LO_EXPLTAB(bits9_10) + sc;
281
282
568k
  bitcnt[11] = bit11 + sc;
283
568k
}
284
285
static VOID ia_enhaacplus_enc_count9_10_11(const WORD16 *values, const WORD32 width,
286
                                           WORD32 *bitcnt,
287
                                           ixheaace_huffman_tables *pstr_huffman_tbl,
288
532k
                                           WORD32 invalid_bitcnt) {
289
532k
  WORD32 i;
290
532k
  WORD32 bits9_10, bit11, sc;
291
532k
  WORD32 temp_0, temp_1;
292
293
532k
  bits9_10 = 0;
294
532k
  bit11 = 0;
295
532k
  sc = 0;
296
297
4.66M
  for (i = 0; i < width; i += 2) {
298
4.13M
    temp_0 = abs32(values[i + 0]);
299
4.13M
    temp_1 = abs32(values[i + 1]);
300
301
4.13M
    bits9_10 += EXPAND(pstr_huffman_tbl->huff_ltab9_10[temp_0][temp_1]);
302
303
4.13M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[temp_0][temp_1]);
304
305
4.13M
    sc += (temp_0 > 0) + (temp_1 > 0);
306
4.13M
  }
307
308
532k
  bitcnt[1] = invalid_bitcnt;
309
532k
  bitcnt[2] = invalid_bitcnt;
310
532k
  bitcnt[3] = invalid_bitcnt;
311
532k
  bitcnt[4] = invalid_bitcnt;
312
532k
  bitcnt[5] = invalid_bitcnt;
313
532k
  bitcnt[6] = invalid_bitcnt;
314
532k
  bitcnt[7] = invalid_bitcnt;
315
532k
  bitcnt[8] = invalid_bitcnt;
316
317
532k
  bitcnt[9] = HI_EXPLTAB(bits9_10) + sc;
318
319
532k
  bitcnt[10] = LO_EXPLTAB(bits9_10) + sc;
320
321
532k
  bitcnt[11] = bit11 + sc;
322
532k
}
323
324
static VOID ia_enhaacplus_enc_count11(const WORD16 *values, const WORD32 width, WORD32 *bitcnt,
325
                                      ixheaace_huffman_tables *pstr_huffman_tbl,
326
200k
                                      WORD32 invalid_bitcnt) {
327
200k
  WORD32 i;
328
200k
  WORD32 bit11, sc;
329
200k
  WORD32 temp_0, temp_1;
330
331
200k
  bit11 = 0;
332
200k
  sc = 0;
333
334
1.50M
  for (i = 0; i < width; i += 2) {
335
1.30M
    temp_0 = abs32(values[i + 0]);
336
1.30M
    temp_1 = abs32(values[i + 1]);
337
338
1.30M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[temp_0][temp_1]);
339
340
1.30M
    sc += (temp_0 > 0) + (temp_1 > 0);
341
1.30M
  }
342
343
200k
  bitcnt[1] = invalid_bitcnt;
344
200k
  bitcnt[2] = invalid_bitcnt;
345
200k
  bitcnt[3] = invalid_bitcnt;
346
200k
  bitcnt[4] = invalid_bitcnt;
347
200k
  bitcnt[5] = invalid_bitcnt;
348
200k
  bitcnt[6] = invalid_bitcnt;
349
200k
  bitcnt[7] = invalid_bitcnt;
350
200k
  bitcnt[8] = invalid_bitcnt;
351
200k
  bitcnt[9] = invalid_bitcnt;
352
200k
  bitcnt[10] = invalid_bitcnt;
353
354
200k
  bitcnt[11] = bit11 + sc;
355
200k
}
356
357
static VOID ia_enhaacplus_enc_count_esc(const WORD16 *values, const WORD32 width, WORD32 *bitcnt,
358
                                        ixheaace_huffman_tables *pstr_huffman_tbl,
359
1.47M
                                        WORD32 invalid_bitcnt) {
360
1.47M
  WORD32 i;
361
1.47M
  WORD32 bit11, ec, sc;
362
1.47M
  WORD32 temp_0, temp_1, t00, t01;
363
364
1.47M
  bit11 = 0;
365
1.47M
  sc = 0;
366
1.47M
  ec = 0;
367
368
8.71M
  for (i = 0; i < width; i += 2) {
369
7.24M
    temp_0 = abs32(values[i + 0]);
370
7.24M
    temp_1 = abs32(values[i + 1]);
371
372
7.24M
    sc += (temp_0 > 0) + (temp_1 > 0);
373
7.24M
    t00 = MIN(temp_0, 16);
374
7.24M
    t01 = MIN(temp_1, 16);
375
376
7.24M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[t00][t01]);
377
378
7.24M
    if (temp_0 >= 16) {
379
3.57M
      ec += 5;
380
381
8.14M
      while ((temp_0 >>= 1) >= 16) {
382
4.56M
        ec += 2;
383
4.56M
      }
384
3.57M
    }
385
386
7.24M
    if (temp_1 >= 16) {
387
3.09M
      ec += 5;
388
389
6.02M
      while ((temp_1 >>= 1) >= 16) {
390
2.92M
        ec += 2;
391
2.92M
      }
392
3.09M
    }
393
7.24M
  }
394
395
1.47M
  bitcnt[1] = invalid_bitcnt;
396
1.47M
  bitcnt[2] = invalid_bitcnt;
397
1.47M
  bitcnt[3] = invalid_bitcnt;
398
1.47M
  bitcnt[4] = invalid_bitcnt;
399
1.47M
  bitcnt[5] = invalid_bitcnt;
400
1.47M
  bitcnt[6] = invalid_bitcnt;
401
1.47M
  bitcnt[7] = invalid_bitcnt;
402
1.47M
  bitcnt[8] = invalid_bitcnt;
403
1.47M
  bitcnt[9] = invalid_bitcnt;
404
1.47M
  bitcnt[10] = invalid_bitcnt;
405
406
1.47M
  bitcnt[11] = bit11 + sc + ec;
407
1.47M
}
408
409
typedef VOID (*COUNT_FUNCTION)(const WORD16 *values, const WORD32 width, WORD32 *bitcnt,
410
                               ixheaace_huffman_tables *pstr_huffman_tbl, WORD32 invalid_bitcnt);
411
412
static COUNT_FUNCTION ia_enhaacplus_enc_count_func_tab[CODE_BCK_ESC_LAV + 1] = {
413
414
    ia_enhaacplus_enc_count1_2_3_4_5_6_7_8_9_10_11, /* 0  */
415
    ia_enhaacplus_enc_count1_2_3_4_5_6_7_8_9_10_11, /* 1  */
416
    ia_enhaacplus_enc_count3_4_5_6_7_8_9_10_11,     /* 2  */
417
    ia_enhaacplus_enc_count5_6_7_8_9_10_11,         /* 3  */
418
    ia_enhaacplus_enc_count5_6_7_8_9_10_11,         /* 4  */
419
    ia_enhaacplus_enc_count7_8_9_10_11,             /* 5  */
420
    ia_enhaacplus_enc_count7_8_9_10_11,             /* 6  */
421
    ia_enhaacplus_enc_count7_8_9_10_11,             /* 7  */
422
    ia_enhaacplus_enc_count9_10_11,                 /* 8  */
423
    ia_enhaacplus_enc_count9_10_11,                 /* 9  */
424
    ia_enhaacplus_enc_count9_10_11,                 /* 10 */
425
    ia_enhaacplus_enc_count9_10_11,                 /* 11 */
426
    ia_enhaacplus_enc_count9_10_11,                 /* 12 */
427
    ia_enhaacplus_enc_count11,                      /* 13 */
428
    ia_enhaacplus_enc_count11,                      /* 14 */
429
    ia_enhaacplus_enc_count11,                      /* 15 */
430
    ia_enhaacplus_enc_count_esc                     /* 16 */
431
};
432
433
VOID ia_enhaacplus_enc_bitcount(const WORD16 *ptr_values, const WORD32 width, WORD32 max_val,
434
                                WORD32 *bit_cnt, ixheaace_huffman_tables *pstr_huffman_tbl,
435
13.4M
                                WORD32 aot) {
436
13.4M
  WORD32 invalid_bitcnt;
437
438
13.4M
  if (max_val == 0) {
439
6.81M
    *bit_cnt = 0;
440
6.81M
  } else {
441
6.64M
    switch (aot) {
442
1.08M
      case AOT_AAC_LC:
443
4.11M
      case AOT_SBR:
444
4.98M
      case AOT_PS:
445
4.98M
        *bit_cnt = INVALID_BITCOUNT_LC;
446
4.98M
        break;
447
448
337k
      case AOT_AAC_LD:
449
1.66M
      case AOT_AAC_ELD:
450
1.66M
        *bit_cnt = INVALID_BITCOUNT_LD;
451
1.66M
        break;
452
6.64M
    }
453
6.64M
  }
454
13.4M
  invalid_bitcnt = *bit_cnt;
455
13.4M
  max_val = MIN(max_val, CODE_BCK_ESC_LAV);
456
457
13.4M
  ia_enhaacplus_enc_count_func_tab[max_val](ptr_values, width, bit_cnt, pstr_huffman_tbl,
458
13.4M
                                            invalid_bitcnt);
459
13.4M
}
460
461
VOID ia_enhaacplus_enc_code_values(WORD16 *ptr_values, WORD32 width, WORD32 code_book,
462
                                   ixheaace_bit_buf_handle pstr_bitstream,
463
12.4M
                                   ixheaace_huffman_tables *pstr_huffman_tbl) {
464
12.4M
  WORD32 i, temp_0, temp_1, temp_2, temp_3, t00, t01;
465
12.4M
  WORD32 code_word, code_length;
466
12.4M
  WORD32 sign, sign_length;
467
12.4M
  WORD16 *ptr_temp_values = ptr_values;
468
469
12.4M
  switch (code_book) {
470
5.84M
    case CODE_BCK_ZERO_NO:
471
5.84M
      break;
472
473
1.11M
    case CODE_BCK_1_NO:
474
1.11M
      width = width >> 2;
475
476
5.66M
      for (i = width - 1; i >= 0; i--) {
477
4.55M
        temp_0 = *ptr_temp_values++;
478
4.55M
        temp_1 = *ptr_temp_values++;
479
4.55M
        temp_2 = *ptr_temp_values++;
480
4.55M
        temp_3 = *ptr_temp_values++;
481
482
4.55M
        code_word = pstr_huffman_tbl->huff_ctab1[temp_0 + 1][temp_1 + 1][temp_2 + 1][temp_3 + 1];
483
484
4.55M
        code_length = HI_LTAB(
485
4.55M
            pstr_huffman_tbl->huff_ltab1_2[temp_0 + 1][temp_1 + 1][temp_2 + 1][temp_3 + 1]);
486
487
4.55M
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
488
4.55M
      }
489
1.11M
      break;
490
491
550k
    case CODE_BCK_2_NO:
492
493
550k
      width = width >> 2;
494
495
2.28M
      for (i = width - 1; i >= 0; i--) {
496
1.73M
        temp_0 = *ptr_temp_values++;
497
1.73M
        temp_1 = *ptr_temp_values++;
498
1.73M
        temp_2 = *ptr_temp_values++;
499
1.73M
        temp_3 = *ptr_temp_values++;
500
501
1.73M
        code_word = pstr_huffman_tbl->huff_ctab2[temp_0 + 1][temp_1 + 1][temp_2 + 1][temp_3 + 1];
502
503
1.73M
        code_length = LO_LTAB(
504
1.73M
            pstr_huffman_tbl->huff_ltab1_2[temp_0 + 1][temp_1 + 1][temp_2 + 1][temp_3 + 1]);
505
506
1.73M
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
507
1.73M
      }
508
550k
      break;
509
510
250k
    case CODE_BCK_3_NO:
511
512
1.14M
      for (i = 0; i < width; i += 4) {
513
889k
        sign = 0;
514
889k
        sign_length = 0;
515
889k
        temp_0 = ptr_values[i + 0];
516
517
889k
        if (temp_0 != 0) {
518
187k
          sign_length++;
519
520
187k
          sign <<= 1;
521
522
187k
          if (temp_0 < 0) {
523
93.7k
            sign |= 1;
524
525
93.7k
            temp_0 = abs32(temp_0);
526
93.7k
          }
527
187k
        }
528
529
889k
        temp_1 = ptr_values[i + 1];
530
531
889k
        if (temp_1 != 0) {
532
196k
          sign_length++;
533
534
196k
          sign <<= 1;
535
536
196k
          if (temp_1 < 0) {
537
85.3k
            sign |= 1;
538
539
85.3k
            temp_1 = abs32(temp_1);
540
85.3k
          }
541
196k
        }
542
543
889k
        temp_2 = ptr_values[i + 2];
544
545
889k
        if (temp_2 != 0) {
546
199k
          sign_length++;
547
548
199k
          sign <<= 1;
549
550
199k
          if (temp_2 < 0) {
551
94.6k
            sign |= 1;
552
553
94.6k
            temp_2 = abs32(temp_2);
554
94.6k
          }
555
199k
        }
556
557
889k
        temp_3 = ptr_values[i + 3];
558
559
889k
        if (temp_3 != 0) {
560
174k
          sign_length++;
561
562
174k
          sign <<= 1;
563
564
174k
          if (temp_3 < 0) {
565
95.2k
            sign |= 1;
566
567
95.2k
            temp_3 = abs32(temp_3);
568
95.2k
          }
569
174k
        }
570
571
889k
        code_word = pstr_huffman_tbl->huff_ctab3[temp_0][temp_1][temp_2][temp_3];
572
573
889k
        code_length = HI_LTAB(pstr_huffman_tbl->huff_ltab3_4[temp_0][temp_1][temp_2][temp_3]);
574
575
889k
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
576
577
889k
        ixheaace_write_bits(pstr_bitstream, sign, (UWORD8)sign_length);
578
889k
      }
579
250k
      break;
580
581
630k
    case CODE_BCK_4_NO:
582
583
2.18M
      for (i = 0; i < width; i += 4) {
584
1.55M
        sign = 0;
585
1.55M
        sign_length = 0;
586
1.55M
        temp_0 = ptr_values[i + 0];
587
588
1.55M
        if (temp_0 != 0) {
589
1.09M
          sign_length++;
590
591
1.09M
          sign <<= 1;
592
593
1.09M
          if (temp_0 < 0) {
594
592k
            sign |= 1;
595
596
592k
            temp_0 = abs32(temp_0);
597
592k
          }
598
1.09M
        }
599
600
1.55M
        temp_1 = ptr_values[i + 1];
601
602
1.55M
        if (temp_1 != 0) {
603
1.03M
          sign_length++;
604
605
1.03M
          sign <<= 1;
606
607
1.03M
          if (temp_1 < 0) {
608
553k
            sign |= 1;
609
610
553k
            temp_1 = abs32(temp_1);
611
553k
          }
612
1.03M
        }
613
614
1.55M
        temp_2 = ptr_values[i + 2];
615
616
1.55M
        if (temp_2 != 0) {
617
1.07M
          sign_length++;
618
619
1.07M
          sign <<= 1;
620
621
1.07M
          if (temp_2 < 0) {
622
503k
            sign |= 1;
623
624
503k
            temp_2 = abs32(temp_2);
625
503k
          }
626
1.07M
        }
627
628
1.55M
        temp_3 = ptr_values[i + 3];
629
630
1.55M
        if (temp_3 != 0) {
631
1.04M
          sign_length++;
632
633
1.04M
          sign <<= 1;
634
635
1.04M
          if (temp_3 < 0) {
636
491k
            sign |= 1;
637
638
491k
            temp_3 = abs32(temp_3);
639
491k
          }
640
1.04M
        }
641
642
1.55M
        code_word = pstr_huffman_tbl->huff_ctab4[temp_0][temp_1][temp_2][temp_3];
643
644
1.55M
        code_length = LO_LTAB(pstr_huffman_tbl->huff_ltab3_4[temp_0][temp_1][temp_2][temp_3]);
645
646
1.55M
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
647
648
1.55M
        ixheaace_write_bits(pstr_bitstream, sign, (UWORD8)sign_length);
649
1.55M
      }
650
630k
      break;
651
652
282k
    case CODE_BCK_5_NO:
653
654
282k
      width = width >> 1;
655
656
2.71M
      for (i = width - 1; i >= 0; i--) {
657
2.42M
        temp_0 = *ptr_temp_values++;
658
2.42M
        temp_1 = *ptr_temp_values++;
659
660
2.42M
        code_word = pstr_huffman_tbl->huff_ctab5[temp_0 + 4][temp_1 + 4];
661
662
2.42M
        code_length = HI_LTAB(pstr_huffman_tbl->huff_ltab5_6[temp_0 + 4][temp_1 + 4]);
663
664
2.42M
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
665
2.42M
      }
666
282k
      break;
667
668
537k
    case CODE_BCK_6_NO:
669
670
537k
      width = width >> 1;
671
672
3.87M
      for (i = width - 1; i >= 0; i--) {
673
3.33M
        temp_0 = *ptr_temp_values++;
674
3.33M
        temp_1 = *ptr_temp_values++;
675
676
3.33M
        code_word = pstr_huffman_tbl->huff_ctab6[temp_0 + 4][temp_1 + 4];
677
678
3.33M
        code_length = LO_LTAB(pstr_huffman_tbl->huff_ltab5_6[temp_0 + 4][temp_1 + 4]);
679
680
3.33M
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
681
3.33M
      }
682
537k
      break;
683
684
79.8k
    case CODE_BCK_7_NO:
685
686
925k
      for (i = 0; i < width; i += 2) {
687
846k
        sign = 0;
688
846k
        sign_length = 0;
689
846k
        temp_0 = ptr_values[i + 0];
690
691
846k
        if (temp_0 != 0) {
692
326k
          sign_length++;
693
694
326k
          sign <<= 1;
695
696
326k
          if (temp_0 < 0) {
697
168k
            sign |= 1;
698
699
168k
            temp_0 = abs32(temp_0);
700
168k
          }
701
326k
        }
702
703
846k
        temp_1 = ptr_values[i + 1];
704
705
846k
        if (temp_1 != 0) {
706
291k
          sign_length++;
707
708
291k
          sign <<= 1;
709
710
291k
          if (temp_1 < 0) {
711
147k
            sign |= 1;
712
713
147k
            temp_1 = abs32(temp_1);
714
147k
          }
715
291k
        }
716
717
846k
        code_word = pstr_huffman_tbl->huff_ctab7[temp_0][temp_1];
718
719
846k
        code_length = HI_LTAB(pstr_huffman_tbl->huff_ltab7_8[temp_0][temp_1]);
720
721
846k
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
722
723
846k
        ixheaace_write_bits(pstr_bitstream, sign, (UWORD8)sign_length);
724
846k
      }
725
79.8k
      break;
726
727
279k
    case CODE_BCK_8_NO:
728
729
2.23M
      for (i = 0; i < width; i += 2) {
730
1.95M
        sign = 0;
731
1.95M
        sign_length = 0;
732
1.95M
        temp_0 = ptr_values[i + 0];
733
734
1.95M
        if (temp_0 != 0) {
735
1.67M
          sign_length++;
736
737
1.67M
          sign <<= 1;
738
739
1.67M
          if (temp_0 < 0) {
740
826k
            sign |= 1;
741
742
826k
            temp_0 = abs32(temp_0);
743
826k
          }
744
1.67M
        }
745
746
1.95M
        temp_1 = ptr_values[i + 1];
747
748
1.95M
        if (temp_1 != 0) {
749
1.70M
          sign_length++;
750
751
1.70M
          sign <<= 1;
752
753
1.70M
          if (temp_1 < 0) {
754
861k
            sign |= 1;
755
756
861k
            temp_1 = abs32(temp_1);
757
861k
          }
758
1.70M
        }
759
760
1.95M
        code_word = pstr_huffman_tbl->huff_ctab8[temp_0][temp_1];
761
762
1.95M
        code_length = LO_LTAB(pstr_huffman_tbl->huff_ltab7_8[temp_0][temp_1]);
763
764
1.95M
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
765
766
1.95M
        ixheaace_write_bits(pstr_bitstream, sign, (UWORD8)sign_length);
767
1.95M
      }
768
279k
      break;
769
770
87.4k
    case CODE_BCK_9_NO:
771
772
946k
      for (i = 0; i < width; i += 2) {
773
859k
        sign = 0;
774
859k
        sign_length = 0;
775
859k
        temp_0 = ptr_values[i + 0];
776
777
859k
        if (temp_0 != 0) {
778
298k
          sign_length++;
779
780
298k
          sign <<= 1;
781
782
298k
          if (temp_0 < 0) {
783
147k
            sign |= 1;
784
785
147k
            temp_0 = abs32(temp_0);
786
147k
          }
787
298k
        }
788
789
859k
        temp_1 = ptr_values[i + 1];
790
791
859k
        if (temp_1 != 0) {
792
288k
          sign_length++;
793
794
288k
          sign <<= 1;
795
796
288k
          if (temp_1 < 0) {
797
144k
            sign |= 1;
798
799
144k
            temp_1 = abs32(temp_1);
800
144k
          }
801
288k
        }
802
803
859k
        code_word = pstr_huffman_tbl->huff_ctab9[temp_0][temp_1];
804
805
859k
        code_length = HI_LTAB(pstr_huffman_tbl->huff_ltab9_10[temp_0][temp_1]);
806
807
859k
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
808
809
859k
        ixheaace_write_bits(pstr_bitstream, sign, (UWORD8)sign_length);
810
859k
      }
811
87.4k
      break;
812
813
759k
    case CODE_BCK_10_NO:
814
815
5.90M
      for (i = 0; i < width; i += 2) {
816
5.14M
        sign = 0;
817
5.14M
        sign_length = 0;
818
5.14M
        temp_0 = ptr_values[i + 0];
819
820
5.14M
        if (temp_0 != 0) {
821
4.86M
          sign_length++;
822
823
4.86M
          sign <<= 1;
824
825
4.86M
          if (temp_0 < 0) {
826
2.42M
            sign |= 1;
827
828
2.42M
            temp_0 = abs32(temp_0);
829
2.42M
          }
830
4.86M
        }
831
832
5.14M
        temp_1 = ptr_values[i + 1];
833
834
5.14M
        if (temp_1 != 0) {
835
4.84M
          sign_length++;
836
837
4.84M
          sign <<= 1;
838
839
4.84M
          if (temp_1 < 0) {
840
2.44M
            sign |= 1;
841
842
2.44M
            temp_1 = abs32(temp_1);
843
2.44M
          }
844
4.84M
        }
845
846
5.14M
        code_word = pstr_huffman_tbl->huff_ctab10[temp_0][temp_1];
847
848
5.14M
        code_length = LO_LTAB(pstr_huffman_tbl->huff_ltab9_10[temp_0][temp_1]);
849
850
5.14M
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
851
852
5.14M
        ixheaace_write_bits(pstr_bitstream, sign, (UWORD8)sign_length);
853
5.14M
      }
854
759k
      break;
855
856
2.04M
    case CODE_BCK_ESC_NO:
857
858
12.3M
      for (i = 0; i < width; i += 2) {
859
10.3M
        sign = 0;
860
10.3M
        sign_length = 0;
861
10.3M
        temp_0 = ptr_values[i + 0];
862
863
10.3M
        if (temp_0 != 0) {
864
9.07M
          sign_length++;
865
866
9.07M
          sign <<= 1;
867
868
9.07M
          if (temp_0 < 0) {
869
4.36M
            sign |= 1;
870
871
4.36M
            temp_0 = abs32(temp_0);
872
4.36M
          }
873
9.07M
        }
874
875
10.3M
        temp_1 = ptr_values[i + 1];
876
877
10.3M
        if (temp_1 != 0) {
878
8.86M
          sign_length++;
879
880
8.86M
          sign <<= 1;
881
882
8.86M
          if (temp_1 < 0) {
883
4.45M
            sign |= 1;
884
885
4.45M
            temp_1 = abs32(temp_1);
886
4.45M
          }
887
8.86M
        }
888
889
10.3M
        t00 = MIN(temp_0, 16);
890
10.3M
        t01 = MIN(temp_1, 16);
891
892
10.3M
        code_word = pstr_huffman_tbl->huff_ctab11[t00][t01];
893
10.3M
        code_length = pstr_huffman_tbl->huff_ltab11[t00][t01];
894
895
10.3M
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
896
897
10.3M
        ixheaace_write_bits(pstr_bitstream, sign, (UWORD8)sign_length);
898
899
10.3M
        if (temp_0 >= 16) {
900
3.47M
          WORD32 n, p;
901
902
3.47M
          n = 0;
903
3.47M
          p = temp_0;
904
905
7.76M
          while ((p >>= 1) >= 16) {
906
4.29M
            ixheaace_write_bits(pstr_bitstream, 1, 1);
907
908
4.29M
            n++;
909
4.29M
          }
910
911
3.47M
          ixheaace_write_bits(pstr_bitstream, 0, 1);
912
913
3.47M
          ixheaace_write_bits(pstr_bitstream, temp_0 - (1 << (n + 4)), (UWORD8)(n + 4));
914
3.47M
        }
915
10.3M
        if (temp_1 >= 16) {
916
3.01M
          WORD32 n, p;
917
918
3.01M
          n = 0;
919
3.01M
          p = temp_1;
920
921
5.77M
          while ((p >>= 1) >= 16) {
922
2.76M
            ixheaace_write_bits(pstr_bitstream, 1, 1);
923
924
2.76M
            n++;
925
2.76M
          }
926
927
3.01M
          ixheaace_write_bits(pstr_bitstream, 0, 1);
928
929
3.01M
          ixheaace_write_bits(pstr_bitstream, temp_1 - (1 << (n + 4)), (UWORD8)(n + 4));
930
3.01M
        }
931
10.3M
      }
932
2.04M
      break;
933
934
0
    default:
935
0
      break;
936
12.4M
  }
937
12.4M
}
938
939
VOID ia_enhaacplus_enc_code_scale_factor_delta(WORD32 delta,
940
                                               ixheaace_bit_buf_handle h_bitstream,
941
0
                                               ixheaace_huffman_tables *pstr_huffman_tbl) {
942
0
  WORD32 code_word, code_length;
943
944
0
  code_word = pstr_huffman_tbl->huff_ctabscf[delta + CODE_BCK_SCF_LAV];
945
0
  code_length = pstr_huffman_tbl->huff_ltabscf[delta + CODE_BCK_SCF_LAV];
946
947
0
  ixheaace_write_bits(h_bitstream, code_word, (UWORD8)code_length);
948
0
}