Coverage Report

Created: 2025-11-09 07:01

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
10.0M
                                                    WORD32 invalid_bitcnt) {
50
10.0M
  WORD32 i;
51
10.0M
  WORD32 bits1_2, bits3_4, bits5_6, bits7_8, bits9_10, bit11, sc;
52
10.0M
  WORD32 temp_0, temp_1, temp_2, temp_3;
53
10.0M
  (VOID) invalid_bitcnt;
54
10.0M
  bits1_2 = 0;
55
10.0M
  bits3_4 = 0;
56
10.0M
  bits5_6 = 0;
57
10.0M
  bits7_8 = 0;
58
10.0M
  bits9_10 = 0;
59
10.0M
  bit11 = 0;
60
10.0M
  sc = 0;
61
62
46.5M
  for (i = 0; i < width; i += 4) {
63
36.4M
    temp_0 = values[i + 0];
64
36.4M
    temp_1 = values[i + 1];
65
36.4M
    temp_2 = values[i + 2];
66
36.4M
    temp_3 = values[i + 3];
67
68
36.4M
    bits1_2 +=
69
36.4M
        EXPAND(pstr_huffman_tbl->huff_ltab1_2[temp_0 + 1][temp_1 + 1][temp_2 + 1][temp_3 + 1]);
70
71
36.4M
    bits5_6 += EXPAND(pstr_huffman_tbl->huff_ltab5_6[temp_0 + 4][temp_1 + 4]);
72
73
36.4M
    bits5_6 += EXPAND(pstr_huffman_tbl->huff_ltab5_6[temp_2 + 4][temp_3 + 4]);
74
75
36.4M
    sc += (temp_0 != 0) + (temp_1 != 0) + (temp_2 != 0) + (temp_3 != 0);
76
77
36.4M
    temp_0 = abs32(temp_0);
78
36.4M
    temp_1 = abs32(temp_1);
79
36.4M
    temp_2 = abs32(temp_2);
80
36.4M
    temp_3 = abs32(temp_3);
81
82
36.4M
    bits3_4 += EXPAND(pstr_huffman_tbl->huff_ltab3_4[temp_0][temp_1][temp_2][temp_3]);
83
84
36.4M
    bits7_8 += EXPAND(pstr_huffman_tbl->huff_ltab7_8[temp_0][temp_1]);
85
86
36.4M
    bits7_8 += EXPAND(pstr_huffman_tbl->huff_ltab7_8[temp_2][temp_3]);
87
88
36.4M
    bits9_10 += EXPAND(pstr_huffman_tbl->huff_ltab9_10[temp_0][temp_1]);
89
90
36.4M
    bits9_10 += EXPAND(pstr_huffman_tbl->huff_ltab9_10[temp_2][temp_3]);
91
92
36.4M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[temp_0][temp_1]);
93
94
36.4M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[temp_2][temp_3]);
95
36.4M
  }
96
97
10.0M
  bitcnt[1] = HI_EXPLTAB(bits1_2);
98
99
10.0M
  bitcnt[2] = LO_EXPLTAB(bits1_2);
100
101
10.0M
  bitcnt[3] = HI_EXPLTAB(bits3_4) + sc;
102
103
10.0M
  bitcnt[4] = LO_EXPLTAB(bits3_4) + sc;
104
105
10.0M
  bitcnt[5] = HI_EXPLTAB(bits5_6);
106
107
10.0M
  bitcnt[6] = LO_EXPLTAB(bits5_6);
108
109
10.0M
  bitcnt[7] = HI_EXPLTAB(bits7_8) + sc;
110
111
10.0M
  bitcnt[8] = LO_EXPLTAB(bits7_8) + sc;
112
113
10.0M
  bitcnt[9] = HI_EXPLTAB(bits9_10) + sc;
114
115
10.0M
  bitcnt[10] = LO_EXPLTAB(bits9_10) + sc;
116
117
10.0M
  bitcnt[11] = bit11 + sc;
118
10.0M
}
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
645k
                                                       WORD32 invalid_bitcnt) {
124
645k
  WORD32 i;
125
645k
  WORD32 bits3_4, bits5_6, bits7_8, bits9_10, bit11, sc;
126
645k
  WORD32 temp_0, temp_1, temp_2, temp_3;
127
128
645k
  bits3_4 = 0;
129
645k
  bits5_6 = 0;
130
645k
  bits7_8 = 0;
131
645k
  bits9_10 = 0;
132
645k
  bit11 = 0;
133
645k
  sc = 0;
134
135
2.83M
  for (i = 0; i < width; i += 4) {
136
2.18M
    temp_0 = values[i + 0];
137
2.18M
    temp_1 = values[i + 1];
138
2.18M
    temp_2 = values[i + 2];
139
2.18M
    temp_3 = values[i + 3];
140
141
2.18M
    bits5_6 += EXPAND(pstr_huffman_tbl->huff_ltab5_6[temp_0 + 4][temp_1 + 4]);
142
143
2.18M
    bits5_6 += EXPAND(pstr_huffman_tbl->huff_ltab5_6[temp_2 + 4][temp_3 + 4]);
144
145
2.18M
    temp_0 = abs32(temp_0);
146
2.18M
    temp_1 = abs32(temp_1);
147
2.18M
    temp_2 = abs32(temp_2);
148
2.18M
    temp_3 = abs32(temp_3);
149
150
2.18M
    bits3_4 += EXPAND(pstr_huffman_tbl->huff_ltab3_4[temp_0][temp_1][temp_2][temp_3]);
151
152
2.18M
    bits7_8 += EXPAND(pstr_huffman_tbl->huff_ltab7_8[temp_0][temp_1]);
153
154
2.18M
    bits7_8 += EXPAND(pstr_huffman_tbl->huff_ltab7_8[temp_2][temp_3]);
155
156
2.18M
    bits9_10 += EXPAND(pstr_huffman_tbl->huff_ltab9_10[temp_0][temp_1]);
157
158
2.18M
    bits9_10 += EXPAND(pstr_huffman_tbl->huff_ltab9_10[temp_2][temp_3]);
159
160
2.18M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[temp_0][temp_1]);
161
162
2.18M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[temp_2][temp_3]);
163
164
2.18M
    sc += (temp_0 > 0) + (temp_1 > 0) + (temp_2 > 0) + (temp_3 > 0);
165
2.18M
  }
166
167
645k
  bitcnt[1] = invalid_bitcnt;
168
645k
  bitcnt[2] = invalid_bitcnt;
169
170
645k
  bitcnt[3] = HI_EXPLTAB(bits3_4) + sc;
171
172
645k
  bitcnt[4] = LO_EXPLTAB(bits3_4) + sc;
173
174
645k
  bitcnt[5] = HI_EXPLTAB(bits5_6);
175
176
645k
  bitcnt[6] = LO_EXPLTAB(bits5_6);
177
178
645k
  bitcnt[7] = HI_EXPLTAB(bits7_8) + sc;
179
180
645k
  bitcnt[8] = LO_EXPLTAB(bits7_8) + sc;
181
182
645k
  bitcnt[9] = HI_EXPLTAB(bits9_10) + sc;
183
184
645k
  bitcnt[10] = LO_EXPLTAB(bits9_10) + sc;
185
186
645k
  bitcnt[11] = bit11 + sc;
187
645k
}
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
581k
                                                   WORD32 invalid_bitcnt) {
193
581k
  WORD32 i;
194
581k
  WORD32 bits5_6, bits7_8, bits9_10, bit11, sc;
195
581k
  WORD32 temp_0, temp_1;
196
197
581k
  bits5_6 = 0;
198
581k
  bits7_8 = 0;
199
581k
  bits9_10 = 0;
200
581k
  bit11 = 0;
201
581k
  sc = 0;
202
203
4.38M
  for (i = 0; i < width; i += 2) {
204
3.80M
    temp_0 = values[i + 0];
205
3.80M
    temp_1 = values[i + 1];
206
207
3.80M
    bits5_6 += EXPAND(pstr_huffman_tbl->huff_ltab5_6[temp_0 + 4][temp_1 + 4]);
208
209
3.80M
    temp_0 = abs32(temp_0);
210
3.80M
    temp_1 = abs32(temp_1);
211
212
3.80M
    bits7_8 += EXPAND(pstr_huffman_tbl->huff_ltab7_8[temp_0][temp_1]);
213
214
3.80M
    bits9_10 += EXPAND(pstr_huffman_tbl->huff_ltab9_10[temp_0][temp_1]);
215
216
3.80M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[temp_0][temp_1]);
217
218
3.80M
    sc += (temp_0 > 0) + (temp_1 > 0);
219
3.80M
  }
220
221
581k
  bitcnt[1] = invalid_bitcnt;
222
581k
  bitcnt[2] = invalid_bitcnt;
223
581k
  bitcnt[3] = invalid_bitcnt;
224
581k
  bitcnt[4] = invalid_bitcnt;
225
226
581k
  bitcnt[5] = HI_EXPLTAB(bits5_6);
227
228
581k
  bitcnt[6] = LO_EXPLTAB(bits5_6);
229
230
581k
  bitcnt[7] = HI_EXPLTAB(bits7_8) + sc;
231
232
581k
  bitcnt[8] = LO_EXPLTAB(bits7_8) + sc;
233
234
581k
  bitcnt[9] = HI_EXPLTAB(bits9_10) + sc;
235
236
581k
  bitcnt[10] = LO_EXPLTAB(bits9_10) + sc;
237
238
581k
  bitcnt[11] = bit11 + sc;
239
581k
}
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
446k
                                               WORD32 invalid_bitcnt) {
245
446k
  WORD32 i;
246
446k
  WORD32 bits7_8, bits9_10, bit11, sc;
247
446k
  WORD32 temp_0, temp_1;
248
249
446k
  bits7_8 = 0;
250
446k
  bits9_10 = 0;
251
446k
  bit11 = 0;
252
446k
  sc = 0;
253
254
3.22M
  for (i = 0; i < width; i += 2) {
255
2.77M
    temp_0 = abs32(values[i + 0]);
256
2.77M
    temp_1 = abs32(values[i + 1]);
257
258
2.77M
    bits7_8 += EXPAND(pstr_huffman_tbl->huff_ltab7_8[temp_0][temp_1]);
259
260
2.77M
    bits9_10 += EXPAND(pstr_huffman_tbl->huff_ltab9_10[temp_0][temp_1]);
261
262
2.77M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[temp_0][temp_1]);
263
264
2.77M
    sc += (temp_0 > 0) + (temp_1 > 0);
265
2.77M
  }
266
267
446k
  bitcnt[1] = invalid_bitcnt;
268
446k
  bitcnt[2] = invalid_bitcnt;
269
446k
  bitcnt[3] = invalid_bitcnt;
270
446k
  bitcnt[4] = invalid_bitcnt;
271
446k
  bitcnt[5] = invalid_bitcnt;
272
446k
  bitcnt[6] = invalid_bitcnt;
273
274
446k
  bitcnt[7] = HI_EXPLTAB(bits7_8) + sc;
275
276
446k
  bitcnt[8] = LO_EXPLTAB(bits7_8) + sc;
277
278
446k
  bitcnt[9] = HI_EXPLTAB(bits9_10) + sc;
279
280
446k
  bitcnt[10] = LO_EXPLTAB(bits9_10) + sc;
281
282
446k
  bitcnt[11] = bit11 + sc;
283
446k
}
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
400k
                                           WORD32 invalid_bitcnt) {
289
400k
  WORD32 i;
290
400k
  WORD32 bits9_10, bit11, sc;
291
400k
  WORD32 temp_0, temp_1;
292
293
400k
  bits9_10 = 0;
294
400k
  bit11 = 0;
295
400k
  sc = 0;
296
297
2.51M
  for (i = 0; i < width; i += 2) {
298
2.11M
    temp_0 = abs32(values[i + 0]);
299
2.11M
    temp_1 = abs32(values[i + 1]);
300
301
2.11M
    bits9_10 += EXPAND(pstr_huffman_tbl->huff_ltab9_10[temp_0][temp_1]);
302
303
2.11M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[temp_0][temp_1]);
304
305
2.11M
    sc += (temp_0 > 0) + (temp_1 > 0);
306
2.11M
  }
307
308
400k
  bitcnt[1] = invalid_bitcnt;
309
400k
  bitcnt[2] = invalid_bitcnt;
310
400k
  bitcnt[3] = invalid_bitcnt;
311
400k
  bitcnt[4] = invalid_bitcnt;
312
400k
  bitcnt[5] = invalid_bitcnt;
313
400k
  bitcnt[6] = invalid_bitcnt;
314
400k
  bitcnt[7] = invalid_bitcnt;
315
400k
  bitcnt[8] = invalid_bitcnt;
316
317
400k
  bitcnt[9] = HI_EXPLTAB(bits9_10) + sc;
318
319
400k
  bitcnt[10] = LO_EXPLTAB(bits9_10) + sc;
320
321
400k
  bitcnt[11] = bit11 + sc;
322
400k
}
323
324
static VOID ia_enhaacplus_enc_count11(const WORD16 *values, const WORD32 width, WORD32 *bitcnt,
325
                                      ixheaace_huffman_tables *pstr_huffman_tbl,
326
220k
                                      WORD32 invalid_bitcnt) {
327
220k
  WORD32 i;
328
220k
  WORD32 bit11, sc;
329
220k
  WORD32 temp_0, temp_1;
330
331
220k
  bit11 = 0;
332
220k
  sc = 0;
333
334
1.27M
  for (i = 0; i < width; i += 2) {
335
1.05M
    temp_0 = abs32(values[i + 0]);
336
1.05M
    temp_1 = abs32(values[i + 1]);
337
338
1.05M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[temp_0][temp_1]);
339
340
1.05M
    sc += (temp_0 > 0) + (temp_1 > 0);
341
1.05M
  }
342
343
220k
  bitcnt[1] = invalid_bitcnt;
344
220k
  bitcnt[2] = invalid_bitcnt;
345
220k
  bitcnt[3] = invalid_bitcnt;
346
220k
  bitcnt[4] = invalid_bitcnt;
347
220k
  bitcnt[5] = invalid_bitcnt;
348
220k
  bitcnt[6] = invalid_bitcnt;
349
220k
  bitcnt[7] = invalid_bitcnt;
350
220k
  bitcnt[8] = invalid_bitcnt;
351
220k
  bitcnt[9] = invalid_bitcnt;
352
220k
  bitcnt[10] = invalid_bitcnt;
353
354
220k
  bitcnt[11] = bit11 + sc;
355
220k
}
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.20M
                                        WORD32 invalid_bitcnt) {
360
1.20M
  WORD32 i;
361
1.20M
  WORD32 bit11, ec, sc;
362
1.20M
  WORD32 temp_0, temp_1, t00, t01;
363
364
1.20M
  bit11 = 0;
365
1.20M
  sc = 0;
366
1.20M
  ec = 0;
367
368
5.89M
  for (i = 0; i < width; i += 2) {
369
4.68M
    temp_0 = abs32(values[i + 0]);
370
4.68M
    temp_1 = abs32(values[i + 1]);
371
372
4.68M
    sc += (temp_0 > 0) + (temp_1 > 0);
373
4.68M
    t00 = MIN(temp_0, 16);
374
4.68M
    t01 = MIN(temp_1, 16);
375
376
4.68M
    bit11 += EXPAND(pstr_huffman_tbl->huff_ltab11[t00][t01]);
377
378
4.68M
    if (temp_0 >= 16) {
379
2.68M
      ec += 5;
380
381
6.63M
      while ((temp_0 >>= 1) >= 16) {
382
3.95M
        ec += 2;
383
3.95M
      }
384
2.68M
    }
385
386
4.68M
    if (temp_1 >= 16) {
387
2.26M
      ec += 5;
388
389
4.69M
      while ((temp_1 >>= 1) >= 16) {
390
2.43M
        ec += 2;
391
2.43M
      }
392
2.26M
    }
393
4.68M
  }
394
395
1.20M
  bitcnt[1] = invalid_bitcnt;
396
1.20M
  bitcnt[2] = invalid_bitcnt;
397
1.20M
  bitcnt[3] = invalid_bitcnt;
398
1.20M
  bitcnt[4] = invalid_bitcnt;
399
1.20M
  bitcnt[5] = invalid_bitcnt;
400
1.20M
  bitcnt[6] = invalid_bitcnt;
401
1.20M
  bitcnt[7] = invalid_bitcnt;
402
1.20M
  bitcnt[8] = invalid_bitcnt;
403
1.20M
  bitcnt[9] = invalid_bitcnt;
404
1.20M
  bitcnt[10] = invalid_bitcnt;
405
406
1.20M
  bitcnt[11] = bit11 + sc + ec;
407
1.20M
}
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.5M
                                WORD32 aot) {
436
13.5M
  WORD32 invalid_bitcnt;
437
438
13.5M
  if (max_val == 0) {
439
7.20M
    *bit_cnt = 0;
440
7.20M
  } else {
441
6.31M
    switch (aot) {
442
1.18M
      case AOT_AAC_LC:
443
3.06M
      case AOT_SBR:
444
4.00M
      case AOT_PS:
445
4.00M
        *bit_cnt = INVALID_BITCOUNT_LC;
446
4.00M
        break;
447
448
197k
      case AOT_AAC_LD:
449
2.31M
      case AOT_AAC_ELD:
450
2.31M
        *bit_cnt = INVALID_BITCOUNT_LD;
451
2.31M
        break;
452
6.31M
    }
453
6.31M
  }
454
13.5M
  invalid_bitcnt = *bit_cnt;
455
13.5M
  max_val = MIN(max_val, CODE_BCK_ESC_LAV);
456
457
13.5M
  ia_enhaacplus_enc_count_func_tab[max_val](ptr_values, width, bit_cnt, pstr_huffman_tbl,
458
13.5M
                                            invalid_bitcnt);
459
13.5M
}
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.8M
                                   ixheaace_huffman_tables *pstr_huffman_tbl) {
464
12.8M
  WORD32 i, temp_0, temp_1, temp_2, temp_3, t00, t01;
465
12.8M
  WORD32 code_word, code_length;
466
12.8M
  WORD32 sign, sign_length;
467
12.8M
  WORD16 *ptr_temp_values = ptr_values;
468
469
12.8M
  switch (code_book) {
470
6.38M
    case CODE_BCK_ZERO_NO:
471
6.38M
      break;
472
473
1.36M
    case CODE_BCK_1_NO:
474
1.36M
      width = width >> 2;
475
476
6.88M
      for (i = width - 1; i >= 0; i--) {
477
5.52M
        temp_0 = *ptr_temp_values++;
478
5.52M
        temp_1 = *ptr_temp_values++;
479
5.52M
        temp_2 = *ptr_temp_values++;
480
5.52M
        temp_3 = *ptr_temp_values++;
481
482
5.52M
        code_word = pstr_huffman_tbl->huff_ctab1[temp_0 + 1][temp_1 + 1][temp_2 + 1][temp_3 + 1];
483
484
5.52M
        code_length = HI_LTAB(
485
5.52M
            pstr_huffman_tbl->huff_ltab1_2[temp_0 + 1][temp_1 + 1][temp_2 + 1][temp_3 + 1]);
486
487
5.52M
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
488
5.52M
      }
489
1.36M
      break;
490
491
588k
    case CODE_BCK_2_NO:
492
493
588k
      width = width >> 2;
494
495
2.28M
      for (i = width - 1; i >= 0; i--) {
496
1.69M
        temp_0 = *ptr_temp_values++;
497
1.69M
        temp_1 = *ptr_temp_values++;
498
1.69M
        temp_2 = *ptr_temp_values++;
499
1.69M
        temp_3 = *ptr_temp_values++;
500
501
1.69M
        code_word = pstr_huffman_tbl->huff_ctab2[temp_0 + 1][temp_1 + 1][temp_2 + 1][temp_3 + 1];
502
503
1.69M
        code_length = LO_LTAB(
504
1.69M
            pstr_huffman_tbl->huff_ltab1_2[temp_0 + 1][temp_1 + 1][temp_2 + 1][temp_3 + 1]);
505
506
1.69M
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
507
1.69M
      }
508
588k
      break;
509
510
365k
    case CODE_BCK_3_NO:
511
512
1.61M
      for (i = 0; i < width; i += 4) {
513
1.24M
        sign = 0;
514
1.24M
        sign_length = 0;
515
1.24M
        temp_0 = ptr_values[i + 0];
516
517
1.24M
        if (temp_0 != 0) {
518
275k
          sign_length++;
519
520
275k
          sign <<= 1;
521
522
275k
          if (temp_0 < 0) {
523
125k
            sign |= 1;
524
525
125k
            temp_0 = abs32(temp_0);
526
125k
          }
527
275k
        }
528
529
1.24M
        temp_1 = ptr_values[i + 1];
530
531
1.24M
        if (temp_1 != 0) {
532
267k
          sign_length++;
533
534
267k
          sign <<= 1;
535
536
267k
          if (temp_1 < 0) {
537
110k
            sign |= 1;
538
539
110k
            temp_1 = abs32(temp_1);
540
110k
          }
541
267k
        }
542
543
1.24M
        temp_2 = ptr_values[i + 2];
544
545
1.24M
        if (temp_2 != 0) {
546
235k
          sign_length++;
547
548
235k
          sign <<= 1;
549
550
235k
          if (temp_2 < 0) {
551
108k
            sign |= 1;
552
553
108k
            temp_2 = abs32(temp_2);
554
108k
          }
555
235k
        }
556
557
1.24M
        temp_3 = ptr_values[i + 3];
558
559
1.24M
        if (temp_3 != 0) {
560
221k
          sign_length++;
561
562
221k
          sign <<= 1;
563
564
221k
          if (temp_3 < 0) {
565
133k
            sign |= 1;
566
567
133k
            temp_3 = abs32(temp_3);
568
133k
          }
569
221k
        }
570
571
1.24M
        code_word = pstr_huffman_tbl->huff_ctab3[temp_0][temp_1][temp_2][temp_3];
572
573
1.24M
        code_length = HI_LTAB(pstr_huffman_tbl->huff_ltab3_4[temp_0][temp_1][temp_2][temp_3]);
574
575
1.24M
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
576
577
1.24M
        ixheaace_write_bits(pstr_bitstream, sign, (UWORD8)sign_length);
578
1.24M
      }
579
365k
      break;
580
581
693k
    case CODE_BCK_4_NO:
582
583
2.80M
      for (i = 0; i < width; i += 4) {
584
2.11M
        sign = 0;
585
2.11M
        sign_length = 0;
586
2.11M
        temp_0 = ptr_values[i + 0];
587
588
2.11M
        if (temp_0 != 0) {
589
1.48M
          sign_length++;
590
591
1.48M
          sign <<= 1;
592
593
1.48M
          if (temp_0 < 0) {
594
712k
            sign |= 1;
595
596
712k
            temp_0 = abs32(temp_0);
597
712k
          }
598
1.48M
        }
599
600
2.11M
        temp_1 = ptr_values[i + 1];
601
602
2.11M
        if (temp_1 != 0) {
603
1.29M
          sign_length++;
604
605
1.29M
          sign <<= 1;
606
607
1.29M
          if (temp_1 < 0) {
608
548k
            sign |= 1;
609
610
548k
            temp_1 = abs32(temp_1);
611
548k
          }
612
1.29M
        }
613
614
2.11M
        temp_2 = ptr_values[i + 2];
615
616
2.11M
        if (temp_2 != 0) {
617
1.35M
          sign_length++;
618
619
1.35M
          sign <<= 1;
620
621
1.35M
          if (temp_2 < 0) {
622
698k
            sign |= 1;
623
624
698k
            temp_2 = abs32(temp_2);
625
698k
          }
626
1.35M
        }
627
628
2.11M
        temp_3 = ptr_values[i + 3];
629
630
2.11M
        if (temp_3 != 0) {
631
1.41M
          sign_length++;
632
633
1.41M
          sign <<= 1;
634
635
1.41M
          if (temp_3 < 0) {
636
885k
            sign |= 1;
637
638
885k
            temp_3 = abs32(temp_3);
639
885k
          }
640
1.41M
        }
641
642
2.11M
        code_word = pstr_huffman_tbl->huff_ctab4[temp_0][temp_1][temp_2][temp_3];
643
644
2.11M
        code_length = LO_LTAB(pstr_huffman_tbl->huff_ltab3_4[temp_0][temp_1][temp_2][temp_3]);
645
646
2.11M
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
647
648
2.11M
        ixheaace_write_bits(pstr_bitstream, sign, (UWORD8)sign_length);
649
2.11M
      }
650
693k
      break;
651
652
142k
    case CODE_BCK_5_NO:
653
654
142k
      width = width >> 1;
655
656
1.10M
      for (i = width - 1; i >= 0; i--) {
657
965k
        temp_0 = *ptr_temp_values++;
658
965k
        temp_1 = *ptr_temp_values++;
659
660
965k
        code_word = pstr_huffman_tbl->huff_ctab5[temp_0 + 4][temp_1 + 4];
661
662
965k
        code_length = HI_LTAB(pstr_huffman_tbl->huff_ltab5_6[temp_0 + 4][temp_1 + 4]);
663
664
965k
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
665
965k
      }
666
142k
      break;
667
668
489k
    case CODE_BCK_6_NO:
669
670
489k
      width = width >> 1;
671
672
3.71M
      for (i = width - 1; i >= 0; i--) {
673
3.22M
        temp_0 = *ptr_temp_values++;
674
3.22M
        temp_1 = *ptr_temp_values++;
675
676
3.22M
        code_word = pstr_huffman_tbl->huff_ctab6[temp_0 + 4][temp_1 + 4];
677
678
3.22M
        code_length = LO_LTAB(pstr_huffman_tbl->huff_ltab5_6[temp_0 + 4][temp_1 + 4]);
679
680
3.22M
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
681
3.22M
      }
682
489k
      break;
683
684
77.3k
    case CODE_BCK_7_NO:
685
686
797k
      for (i = 0; i < width; i += 2) {
687
720k
        sign = 0;
688
720k
        sign_length = 0;
689
720k
        temp_0 = ptr_values[i + 0];
690
691
720k
        if (temp_0 != 0) {
692
257k
          sign_length++;
693
694
257k
          sign <<= 1;
695
696
257k
          if (temp_0 < 0) {
697
122k
            sign |= 1;
698
699
122k
            temp_0 = abs32(temp_0);
700
122k
          }
701
257k
        }
702
703
720k
        temp_1 = ptr_values[i + 1];
704
705
720k
        if (temp_1 != 0) {
706
224k
          sign_length++;
707
708
224k
          sign <<= 1;
709
710
224k
          if (temp_1 < 0) {
711
116k
            sign |= 1;
712
713
116k
            temp_1 = abs32(temp_1);
714
116k
          }
715
224k
        }
716
717
720k
        code_word = pstr_huffman_tbl->huff_ctab7[temp_0][temp_1];
718
719
720k
        code_length = HI_LTAB(pstr_huffman_tbl->huff_ltab7_8[temp_0][temp_1]);
720
721
720k
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
722
723
720k
        ixheaace_write_bits(pstr_bitstream, sign, (UWORD8)sign_length);
724
720k
      }
725
77.3k
      break;
726
727
291k
    case CODE_BCK_8_NO:
728
729
2.09M
      for (i = 0; i < width; i += 2) {
730
1.80M
        sign = 0;
731
1.80M
        sign_length = 0;
732
1.80M
        temp_0 = ptr_values[i + 0];
733
734
1.80M
        if (temp_0 != 0) {
735
1.61M
          sign_length++;
736
737
1.61M
          sign <<= 1;
738
739
1.61M
          if (temp_0 < 0) {
740
758k
            sign |= 1;
741
742
758k
            temp_0 = abs32(temp_0);
743
758k
          }
744
1.61M
        }
745
746
1.80M
        temp_1 = ptr_values[i + 1];
747
748
1.80M
        if (temp_1 != 0) {
749
1.59M
          sign_length++;
750
751
1.59M
          sign <<= 1;
752
753
1.59M
          if (temp_1 < 0) {
754
847k
            sign |= 1;
755
756
847k
            temp_1 = abs32(temp_1);
757
847k
          }
758
1.59M
        }
759
760
1.80M
        code_word = pstr_huffman_tbl->huff_ctab8[temp_0][temp_1];
761
762
1.80M
        code_length = LO_LTAB(pstr_huffman_tbl->huff_ltab7_8[temp_0][temp_1]);
763
764
1.80M
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
765
766
1.80M
        ixheaace_write_bits(pstr_bitstream, sign, (UWORD8)sign_length);
767
1.80M
      }
768
291k
      break;
769
770
72.7k
    case CODE_BCK_9_NO:
771
772
812k
      for (i = 0; i < width; i += 2) {
773
739k
        sign = 0;
774
739k
        sign_length = 0;
775
739k
        temp_0 = ptr_values[i + 0];
776
777
739k
        if (temp_0 != 0) {
778
232k
          sign_length++;
779
780
232k
          sign <<= 1;
781
782
232k
          if (temp_0 < 0) {
783
120k
            sign |= 1;
784
785
120k
            temp_0 = abs32(temp_0);
786
120k
          }
787
232k
        }
788
789
739k
        temp_1 = ptr_values[i + 1];
790
791
739k
        if (temp_1 != 0) {
792
219k
          sign_length++;
793
794
219k
          sign <<= 1;
795
796
219k
          if (temp_1 < 0) {
797
109k
            sign |= 1;
798
799
109k
            temp_1 = abs32(temp_1);
800
109k
          }
801
219k
        }
802
803
739k
        code_word = pstr_huffman_tbl->huff_ctab9[temp_0][temp_1];
804
805
739k
        code_length = HI_LTAB(pstr_huffman_tbl->huff_ltab9_10[temp_0][temp_1]);
806
807
739k
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
808
809
739k
        ixheaace_write_bits(pstr_bitstream, sign, (UWORD8)sign_length);
810
739k
      }
811
72.7k
      break;
812
813
538k
    case CODE_BCK_10_NO:
814
815
3.61M
      for (i = 0; i < width; i += 2) {
816
3.07M
        sign = 0;
817
3.07M
        sign_length = 0;
818
3.07M
        temp_0 = ptr_values[i + 0];
819
820
3.07M
        if (temp_0 != 0) {
821
2.96M
          sign_length++;
822
823
2.96M
          sign <<= 1;
824
825
2.96M
          if (temp_0 < 0) {
826
1.41M
            sign |= 1;
827
828
1.41M
            temp_0 = abs32(temp_0);
829
1.41M
          }
830
2.96M
        }
831
832
3.07M
        temp_1 = ptr_values[i + 1];
833
834
3.07M
        if (temp_1 != 0) {
835
2.95M
          sign_length++;
836
837
2.95M
          sign <<= 1;
838
839
2.95M
          if (temp_1 < 0) {
840
1.49M
            sign |= 1;
841
842
1.49M
            temp_1 = abs32(temp_1);
843
1.49M
          }
844
2.95M
        }
845
846
3.07M
        code_word = pstr_huffman_tbl->huff_ctab10[temp_0][temp_1];
847
848
3.07M
        code_length = LO_LTAB(pstr_huffman_tbl->huff_ltab9_10[temp_0][temp_1]);
849
850
3.07M
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
851
852
3.07M
        ixheaace_write_bits(pstr_bitstream, sign, (UWORD8)sign_length);
853
3.07M
      }
854
538k
      break;
855
856
1.82M
    case CODE_BCK_ESC_NO:
857
858
8.86M
      for (i = 0; i < width; i += 2) {
859
7.03M
        sign = 0;
860
7.03M
        sign_length = 0;
861
7.03M
        temp_0 = ptr_values[i + 0];
862
863
7.03M
        if (temp_0 != 0) {
864
6.32M
          sign_length++;
865
866
6.32M
          sign <<= 1;
867
868
6.32M
          if (temp_0 < 0) {
869
2.89M
            sign |= 1;
870
871
2.89M
            temp_0 = abs32(temp_0);
872
2.89M
          }
873
6.32M
        }
874
875
7.03M
        temp_1 = ptr_values[i + 1];
876
877
7.03M
        if (temp_1 != 0) {
878
6.14M
          sign_length++;
879
880
6.14M
          sign <<= 1;
881
882
6.14M
          if (temp_1 < 0) {
883
3.10M
            sign |= 1;
884
885
3.10M
            temp_1 = abs32(temp_1);
886
3.10M
          }
887
6.14M
        }
888
889
7.03M
        t00 = MIN(temp_0, 16);
890
7.03M
        t01 = MIN(temp_1, 16);
891
892
7.03M
        code_word = pstr_huffman_tbl->huff_ctab11[t00][t01];
893
7.03M
        code_length = pstr_huffman_tbl->huff_ltab11[t00][t01];
894
895
7.03M
        ixheaace_write_bits(pstr_bitstream, code_word, (UWORD8)code_length);
896
897
7.03M
        ixheaace_write_bits(pstr_bitstream, sign, (UWORD8)sign_length);
898
899
7.03M
        if (temp_0 >= 16) {
900
2.59M
          WORD32 n, p;
901
902
2.59M
          n = 0;
903
2.59M
          p = temp_0;
904
905
6.32M
          while ((p >>= 1) >= 16) {
906
3.73M
            ixheaace_write_bits(pstr_bitstream, 1, 1);
907
908
3.73M
            n++;
909
3.73M
          }
910
911
2.59M
          ixheaace_write_bits(pstr_bitstream, 0, 1);
912
913
2.59M
          ixheaace_write_bits(pstr_bitstream, temp_0 - (1 << (n + 4)), (UWORD8)(n + 4));
914
2.59M
        }
915
7.03M
        if (temp_1 >= 16) {
916
2.19M
          WORD32 n, p;
917
918
2.19M
          n = 0;
919
2.19M
          p = temp_1;
920
921
4.49M
          while ((p >>= 1) >= 16) {
922
2.30M
            ixheaace_write_bits(pstr_bitstream, 1, 1);
923
924
2.30M
            n++;
925
2.30M
          }
926
927
2.19M
          ixheaace_write_bits(pstr_bitstream, 0, 1);
928
929
2.19M
          ixheaace_write_bits(pstr_bitstream, temp_1 - (1 << (n + 4)), (UWORD8)(n + 4));
930
2.19M
        }
931
7.03M
      }
932
1.82M
      break;
933
934
0
    default:
935
0
      break;
936
12.8M
  }
937
12.8M
}
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
}