Coverage Report

Created: 2025-12-14 07:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/decoder/ixheaacd_rev_vlc.c
Line
Count
Source
1
/******************************************************************************
2
 *                                                                            *
3
 * Copyright (C) 2018 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
#include <string.h>
22
#include "ixheaacd_sbr_common.h"
23
#include "ixheaac_type_def.h"
24
25
#include "ixheaac_constants.h"
26
#include "ixheaac_basic_ops32.h"
27
#include "ixheaac_basic_ops16.h"
28
#include "ixheaac_basic_ops40.h"
29
#include "ixheaac_basic_ops.h"
30
31
#include "ixheaacd_bitbuffer.h"
32
#include "ixheaacd_error_codes.h"
33
#include "ixheaacd_defines.h"
34
#include "ixheaacd_aac_rom.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
#include "ixheaacd_cnst.h"
42
#include "ixheaacd_ec_defines.h"
43
#include "ixheaacd_ec_struct_def.h"
44
#include "ixheaacd_channelinfo.h"
45
46
#include "ixheaacd_drc_dec.h"
47
48
#include "ixheaacd_sbrdecoder.h"
49
50
#include "ixheaacd_block.h"
51
#include "ixheaacd_channel.h"
52
53
#include "ixheaacd_common_rom.h"
54
#include "ixheaacd_basic_funcs.h"
55
#include "ixheaac_basic_op.h"
56
57
#include "ixheaacd_aacdec.h"
58
59
#include "ixheaacd_sbrdecsettings.h"
60
#include "ixheaacd_sbr_scale.h"
61
#include "ixheaacd_env_extr_part.h"
62
#include "ixheaacd_sbr_rom.h"
63
#include "ixheaacd_audioobjtypes.h"
64
#include "ixheaacd_sbrdecoder.h"
65
#include "ixheaacd_memory_standards.h"
66
#include "ixheaacd_latmdemux.h"
67
#include "ixheaacd_mps_polyphase.h"
68
#include "ixheaacd_config.h"
69
#include "ixheaacd_hybrid.h"
70
#include "ixheaacd_ps_dec.h"
71
#include "ixheaacd_qmf_dec.h"
72
#include "ixheaacd_mps_macro_def.h"
73
#include "ixheaacd_mps_struct_def.h"
74
#include "ixheaacd_mps_res_rom.h"
75
#include "ixheaacd_mps_aac_struct.h"
76
#include "ixheaacd_mps_dec.h"
77
#include "ixheaacd_mps_interface.h"
78
#include "ixheaacd_struct_def.h"
79
#include "ixheaacd_cnst.h"
80
#include "ixheaac_error_standards.h"
81
82
0
#define RVLC_ERROR_ALL_ESCAPE_WORDS_INVALID 0x80000000
83
66.7k
#define RVLC_ERROR_FORBIDDEN_CW_DETECTED_FWD 0x08000000
84
66.7k
#define RVLC_ERROR_FORBIDDEN_CW_DETECTED_BWD 0x04000000
85
86
4.14M
#define FWD 0
87
#define BWD 1
88
89
2.14M
#define MAX_LEN_RVLC_CODE_WORD 9
90
2.76M
#define MAX_LEN_RVLC_ESCAPE_WORD 20
91
92
354k
#define CONCEAL_MAX_INIT 1311
93
330k
#define CONCEAL_MIN_INIT -1311
94
95
8.62M
#define RVLC_MAX_SFB ((8) * (16))
96
97
0
#define MASK_LEFT 0xFFF000
98
0
#define MASK_RIGHT 0xFFF
99
0
#define CLR_BIT_10 0x3FF
100
0
#define LEFT_OFFSET 12
101
102
#define ixheaacd_bitbuf_checkpoint(it_bit_buf, saved_bit_buf) \
103
66.7k
  (saved_bit_buf) = (it_bit_buf)
104
#define ixheaacd_bitbuf_restore(it_bit_buf, saved_bit_buf) \
105
66.7k
  (it_bit_buf) = (saved_bit_buf)
106
107
2.59M
static WORD32 ixheaacd_rvlc_decode(WORD16 cw, WORD32 len, WORD32 *found) {
108
2.59M
  WORD16 indx = 0;
109
2.59M
  *found = 0;
110
2.59M
  switch (len) {
111
1.08M
    case 1:
112
1.08M
      if (cw == 0)
113
678k
        indx = 0;
114
410k
      else
115
410k
        return 3;
116
678k
      break;
117
678k
    case 3:
118
410k
      switch (cw) {
119
72.5k
        case 5:
120
72.5k
          indx = -1;
121
72.5k
          break;
122
155k
        case 7:
123
155k
          indx = 1;
124
155k
          break;
125
182k
        default:
126
182k
          return 4;
127
410k
      }
128
227k
      break;
129
227k
    case 4:
130
182k
      if (cw == 9)
131
21.1k
        indx = -2;
132
161k
      else
133
161k
        return 5;
134
21.1k
      break;
135
161k
    case 5:
136
161k
      switch (cw) {
137
27.9k
        case 17:
138
27.9k
          indx = -3;
139
27.9k
          break;
140
17.1k
        case 27:
141
17.1k
          indx = 2;
142
17.1k
          break;
143
116k
        default:
144
116k
          return 6;
145
161k
      }
146
45.1k
      break;
147
116k
    case 6:
148
116k
      switch (cw) {
149
4.67k
        case 33:
150
4.67k
          indx = -4;
151
4.67k
          break;
152
1.36k
        case 51:
153
1.36k
          indx = 3;
154
1.36k
          break;
155
110k
        default:
156
110k
          return 7;
157
116k
      }
158
6.03k
      break;
159
110k
    case 7:
160
110k
      switch (cw) {
161
16.8k
        case 65:
162
16.8k
          indx = -7;
163
16.8k
          break;
164
15.3k
        case 107:
165
15.3k
          indx = 4;
166
15.3k
          break;
167
18.3k
        case 99:
168
18.3k
          indx = 7;
169
18.3k
          break;
170
59.8k
        default:
171
59.8k
          return 8;
172
110k
      }
173
50.5k
      break;
174
59.8k
    case 8:
175
59.8k
      switch (cw) {
176
1.72k
        case 129:
177
1.72k
          indx = -5;
178
1.72k
          break;
179
972
        case 195:
180
972
          indx = 5;
181
972
          break;
182
57.1k
        default:
183
57.1k
          return 9;
184
59.8k
      }
185
2.69k
      break;
186
57.1k
    case 9:
187
57.1k
      switch (cw) {
188
8.72k
        case 257:
189
8.72k
          indx = -6;
190
8.72k
          break;
191
16.6k
        case 427:
192
16.6k
          indx = 6;
193
16.6k
          break;
194
31.7k
        default:
195
31.7k
          return -1;
196
57.1k
      }
197
25.3k
      break;
198
410k
    default:
199
410k
      return -1;
200
2.59M
  }
201
1.05M
  *found = 1;
202
1.05M
  return indx;
203
2.59M
}
204
205
4.14M
static WORD32 ixheaacd_rvlc_decode_esc(WORD32 cw, WORD32 len, WORD32 *found) {
206
4.14M
  WORD16 indx = 0;
207
4.14M
  *found = 0;
208
4.14M
  switch (len) {
209
1.38M
    case 2:
210
1.38M
      switch (cw) {
211
216k
        case 2:
212
216k
          indx = 0;
213
216k
          break;
214
590k
        case 0:
215
590k
          indx = 1;
216
590k
          break;
217
577k
        default:
218
577k
          return 3;
219
1.38M
      }
220
806k
      break;
221
806k
    case 3:
222
577k
      switch (cw) {
223
127k
        case 6:
224
127k
          indx = 2;
225
127k
          break;
226
88.6k
        case 2:
227
88.6k
          indx = 3;
228
88.6k
          break;
229
361k
        default:
230
361k
          return 4;
231
577k
      }
232
215k
      break;
233
361k
    case 4:
234
361k
      if (cw == 14)
235
63.7k
        indx = 4;
236
298k
      else
237
298k
        return 5;
238
63.7k
      break;
239
298k
    case 5:
240
298k
      switch (cw) {
241
185k
        case 31:
242
185k
          indx = 5;
243
185k
          break;
244
31.4k
        case 15:
245
31.4k
          indx = 6;
246
31.4k
          break;
247
14.4k
        case 13:
248
14.4k
          indx = 7;
249
14.4k
          break;
250
66.8k
        default:
251
66.8k
          return 6;
252
298k
      }
253
231k
      break;
254
231k
    case 6:
255
66.8k
      switch (cw) {
256
10.4k
        case 61:
257
10.4k
          indx = 8;
258
10.4k
          break;
259
8.61k
        case 29:
260
8.61k
          indx = 9;
261
8.61k
          break;
262
6.31k
        case 25:
263
6.31k
          indx = 10;
264
6.31k
          break;
265
8.84k
        case 24:
266
8.84k
          indx = 11;
267
8.84k
          break;
268
32.5k
        default:
269
32.5k
          return 7;
270
66.8k
      }
271
34.2k
      break;
272
34.2k
    case 7:
273
32.5k
      switch (cw) {
274
14.1k
        case 120:
275
14.1k
          indx = 12;
276
14.1k
          break;
277
7.23k
        case 56:
278
7.23k
          indx = 13;
279
7.23k
          break;
280
11.1k
        default:
281
11.1k
          return 8;
282
32.5k
      }
283
21.4k
      break;
284
21.4k
    case 8:
285
11.1k
      switch (cw) {
286
2.02k
        case 242:
287
2.02k
          indx = 14;
288
2.02k
          break;
289
4.08k
        case 114:
290
4.08k
          indx = 15;
291
4.08k
          break;
292
5.06k
        default:
293
5.06k
          return 9;
294
11.1k
      }
295
6.10k
      break;
296
6.10k
    case 9:
297
5.06k
      switch (cw) {
298
453
        case 486:
299
453
          indx = 16;
300
453
          break;
301
992
        case 230:
302
992
          indx = 17;
303
992
          break;
304
3.61k
        default:
305
3.61k
          return 10;
306
5.06k
      }
307
1.44k
      break;
308
3.61k
    case 10:
309
3.61k
      switch (cw) {
310
39
        case 974:
311
39
          indx = 18;
312
39
          break;
313
158
        case 463:
314
158
          indx = 19;
315
158
          break;
316
3.41k
        default:
317
3.41k
          return 11;
318
3.61k
      }
319
197
      break;
320
3.41k
    case 11:
321
3.41k
      switch (cw) {
322
626
        case 1950:
323
626
          indx = 20;
324
626
          break;
325
140
        case 1951:
326
140
          indx = 21;
327
140
          break;
328
782
        case 925:
329
782
          indx = 22;
330
782
          break;
331
1.87k
        default:
332
1.87k
          return 12;
333
3.41k
      }
334
1.54k
      break;
335
1.87k
    case 12:
336
1.87k
      if (cw == 1848)
337
191
        indx = 23;
338
1.67k
      else
339
1.67k
        return 13;
340
191
      break;
341
1.67k
    case 13:
342
1.67k
      if (cw == 3698)
343
48
        indx = 25;
344
1.63k
      else
345
1.63k
        return 14;
346
48
      break;
347
1.63k
    case 14:
348
1.63k
      if (cw == 7399)
349
46
        indx = 24;
350
1.58k
      else
351
1.58k
        return 15;
352
46
      break;
353
1.58k
    case 15:
354
1.58k
      if (cw == 14797)
355
211
        indx = 26;
356
1.37k
      else
357
1.37k
        return 19;
358
211
      break;
359
1.37k
    case 19:
360
1.37k
      if ((cw >= 236736) && (cw <= 236740))
361
660
        indx = 53 - (236740 - cw);
362
714
      else
363
714
        return 20;
364
660
      break;
365
714
    case 20:
366
714
      if ((cw >= 473482) && (cw <= 473503))
367
714
        indx = 48 - (473503 - cw);
368
0
      else
369
0
        return -1;
370
714
      break;
371
1.38M
    default:
372
1.38M
      return -1;
373
4.14M
  }
374
1.38M
  *found = 1;
375
1.38M
  return indx;
376
4.14M
}
377
static VOID ixheaacd_rvlc_check_intensity_cb(
378
    ia_rvlc_info_struct *ptr_rvlc,
379
66.7k
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info) {
380
66.7k
  WORD32 group, band, bnds;
381
382
66.7k
  ptr_rvlc->intensity_used = 0;
383
384
142k
  for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
385
550k
    for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
386
495k
      bnds = 16 * group + band;
387
495k
      if ((ptr_aac_dec_channel_info->ptr_code_book[bnds] == INTENSITY_HCB) ||
388
484k
          (ptr_aac_dec_channel_info->ptr_code_book[bnds] == INTENSITY_HCB2)) {
389
20.8k
        ptr_rvlc->intensity_used = 1;
390
20.8k
        break;
391
20.8k
      }
392
495k
    }
393
76.2k
  }
394
66.7k
}
395
396
VOID ixheaacd_carry_bit_branch_val(UWORD8 carry_bit, UWORD32 tree_node,
397
0
                                   UWORD32 *branch_val, UWORD32 *branch_node) {
398
0
  if (carry_bit == 0) {
399
0
    *branch_node = (tree_node & MASK_LEFT) >> LEFT_OFFSET;
400
0
  } else {
401
0
    *branch_node = tree_node & MASK_RIGHT;
402
0
  }
403
404
0
  *branch_val = *branch_node & CLR_BIT_10;
405
0
}
406
407
UWORD8 ixheaacd_rvlc_read_bits(ia_bit_buf_struct *it_bit_buff,
408
6.73M
                               UWORD16 *ptr_position, UWORD8 read_direction) {
409
6.73M
  UWORD32 bit;
410
6.73M
  WORD32 read_bit_offset =
411
6.73M
      *ptr_position - (it_bit_buff->size - it_bit_buff->cnt_bits);
412
413
6.73M
  if (read_bit_offset) it_bit_buff->cnt_bits -= read_bit_offset;
414
415
6.73M
  it_bit_buff->ptr_read_next =
416
6.73M
      it_bit_buff->ptr_bit_buf_base +
417
6.73M
      ((it_bit_buff->size - it_bit_buff->cnt_bits) >> 3);
418
6.73M
  it_bit_buff->bit_pos = ((it_bit_buff->size - it_bit_buff->cnt_bits) & 7);
419
420
6.73M
  if (read_direction == 0) {
421
5.58M
    bit = ixheaacd_aac_read_bit_rev(it_bit_buff);
422
423
5.58M
    *ptr_position += 1;
424
5.58M
  } else {
425
1.15M
    bit = ixheaacd_aac_read_bit(it_bit_buff);
426
427
1.15M
    *ptr_position -= 1;
428
1.15M
  }
429
430
6.73M
  return (bit);
431
6.73M
}
432
433
static WORD8 ixheaacd_rvlc_decode_escape_word(ia_rvlc_info_struct *ptr_rvlc,
434
1.38M
                                              ia_bit_buf_struct *it_bit_buff) {
435
1.38M
  WORD32 i;
436
437
1.38M
  UWORD8 carry_bit;
438
439
1.38M
  UWORD16 *ptr_bitstream_index_esc;
440
441
1.38M
  int len = 0;
442
1.38M
  int codeword = 0;
443
1.38M
  int found = 0;
444
1.38M
  int indx;
445
446
1.38M
  ptr_bitstream_index_esc = &(ptr_rvlc->esc_bit_str_idx);
447
448
4.14M
  for (i = MAX_LEN_RVLC_ESCAPE_WORD - 1; i >= 0; i--) {
449
4.14M
    carry_bit =
450
4.14M
        ixheaacd_rvlc_read_bits(it_bit_buff, ptr_bitstream_index_esc, FWD);
451
452
4.14M
    len++;
453
4.14M
    codeword = codeword << 1 | carry_bit;
454
4.14M
    indx = ixheaacd_rvlc_decode_esc(codeword, len, &found);
455
456
4.14M
    if (found) {
457
1.38M
      ptr_rvlc->rvlc_esc_len -= (MAX_LEN_RVLC_ESCAPE_WORD - i);
458
1.38M
      return indx;
459
1.38M
    }
460
4.14M
  }
461
462
0
  ptr_rvlc->rvlc_err_log |= RVLC_ERROR_ALL_ESCAPE_WORDS_INVALID;
463
464
0
  return -1;
465
1.38M
}
466
467
static VOID ixheaacd_rvlc_decode_escape(ia_rvlc_info_struct *ptr_rvlc,
468
                                        WORD16 *ptr_escape,
469
32.0k
                                        ia_bit_buf_struct *it_bit_buff) {
470
32.0k
  WORD8 esc_word;
471
32.0k
  WORD8 esc_cnt = 0;
472
32.0k
  WORD16 *ptr_esc_bit_cnt_sum;
473
474
32.0k
  ptr_esc_bit_cnt_sum = &(ptr_rvlc->rvlc_esc_len);
475
476
1.41M
  while (*ptr_esc_bit_cnt_sum > 0) {
477
1.38M
    esc_word = ixheaacd_rvlc_decode_escape_word(ptr_rvlc, it_bit_buff);
478
479
1.38M
    if (esc_word >= 0) {
480
1.38M
      ptr_escape[esc_cnt] = esc_word;
481
1.38M
      esc_cnt++;
482
1.38M
    } else {
483
0
      ptr_rvlc->rvlc_err_log |= RVLC_ERROR_ALL_ESCAPE_WORDS_INVALID;
484
0
      ptr_rvlc->num_esc_words_decoded = esc_cnt;
485
486
0
      return;
487
0
    }
488
1.38M
  }
489
490
32.0k
  ptr_rvlc->num_esc_words_decoded = esc_cnt;
491
32.0k
}
492
493
WORD8 ixheaacd_decode_rvlc_code_word(ia_bit_buf_struct *it_bit_buff,
494
1.08M
                                     ia_rvlc_info_struct *ptr_rvlc) {
495
1.08M
  WORD32 i;
496
497
1.08M
  UWORD8 carry_bit;
498
499
1.08M
  UWORD8 direction = ptr_rvlc->direction;
500
1.08M
  UWORD16 *ptr_bit_str_idx_rvl = ptr_rvlc->ptr_rvl_bit_str_idx;
501
502
1.08M
  int len = 0;
503
1.08M
  short codeword = 0;
504
1.08M
  int found = 0;
505
1.08M
  int indx;
506
507
2.62M
  for (i = MAX_LEN_RVLC_CODE_WORD - 1; i >= 0; i--) {
508
2.59M
    carry_bit =
509
2.59M
        ixheaacd_rvlc_read_bits(it_bit_buff, ptr_bit_str_idx_rvl, direction);
510
511
2.59M
    len++;
512
2.59M
    codeword = codeword << 1 | carry_bit;
513
2.59M
    indx = ixheaacd_rvlc_decode(codeword, len, &found);
514
2.59M
    if (found) {
515
1.05M
      indx = indx + 7;
516
1.05M
      *ptr_rvlc->ptr_rvl_bit_cnt -= (MAX_LEN_RVLC_CODE_WORD - i);
517
1.05M
      return indx;
518
1.05M
    }
519
2.59M
  }
520
521
31.7k
  return -1;
522
1.08M
}
523
524
static VOID ixheaacd_rvlc_decode_forward(
525
    ia_rvlc_info_struct *ptr_rvlc,
526
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info,
527
66.7k
    ia_bit_buf_struct *it_bit_buff) {
528
66.7k
  WORD32 band = 0;
529
66.7k
  WORD32 group = 0;
530
66.7k
  WORD32 bnds = 0;
531
532
66.7k
  WORD16 dpcm;
533
534
66.7k
  ia_bit_buf_struct temp_buf = {0};
535
536
66.7k
  WORD16 factor = ptr_aac_dec_channel_info->global_gain;
537
66.7k
  WORD16 position = 0;
538
66.7k
  WORD16 noise_energy = ptr_aac_dec_channel_info->global_gain - 90 - 256;
539
540
66.7k
  WORD16 *ptr_scf_fwd = ptr_aac_dec_channel_info->rvlc_scf_fwd_arr;
541
66.7k
  WORD16 *ptr_scf_esc = ptr_aac_dec_channel_info->rvlc_scf_esc_arr;
542
66.7k
  UWORD8 *ptr_esc_fwd_cnt = &(ptr_rvlc->num_fwd_esc_words_decoded);
543
544
66.7k
  ptr_rvlc->ptr_rvl_bit_cnt = &(ptr_rvlc->rvlc_sf_fwd_len);
545
66.7k
  ptr_rvlc->ptr_rvl_bit_str_idx = &(ptr_rvlc->rvl_fwd_bit_str_idx);
546
547
66.7k
  *ptr_esc_fwd_cnt = 0;
548
66.7k
  ptr_rvlc->direction = 0;
549
66.7k
  ptr_rvlc->noise_used = 0;
550
66.7k
  ptr_rvlc->sf_used = 0;
551
66.7k
  ptr_rvlc->last_scale_fac = 0;
552
66.7k
  ptr_rvlc->last_nrg = 0;
553
66.7k
  ptr_rvlc->is_last = 0;
554
555
66.7k
  ixheaacd_rvlc_check_intensity_cb(ptr_rvlc, ptr_aac_dec_channel_info);
556
557
126k
  for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
558
800k
    for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
559
740k
      bnds = 16 * group + band;
560
561
740k
      switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
562
91.4k
        case ZERO_HCB:
563
91.4k
          ptr_scf_fwd[bnds] = 0;
564
91.4k
          break;
565
566
51.2k
        case INTENSITY_HCB2:
567
204k
        case INTENSITY_HCB:
568
569
204k
        {
570
204k
          dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
571
204k
          if (dpcm < 0) {
572
5.32k
            ptr_rvlc->conceal_max = bnds;
573
5.32k
            return;
574
5.32k
          }
575
198k
          dpcm -= 7;
576
198k
        }
577
198k
          if ((dpcm == -7) || (dpcm == 7)) {
578
7.68k
            if (ptr_rvlc->rvlc_esc_len) {
579
1.68k
              ptr_rvlc->conceal_max = bnds;
580
1.68k
              return;
581
5.99k
            } else {
582
5.99k
              if (dpcm == -7) {
583
4.01k
                dpcm -= *ptr_scf_esc++;
584
4.01k
              } else {
585
1.97k
                dpcm += *ptr_scf_esc++;
586
1.97k
              }
587
5.99k
              (*ptr_esc_fwd_cnt)++;
588
5.99k
              if (ptr_rvlc->conceal_max_esc == 1311) {
589
1.05k
                ptr_rvlc->conceal_max_esc = bnds;
590
1.05k
              }
591
5.99k
            }
592
7.68k
          }
593
197k
          position += dpcm;
594
197k
          ptr_scf_fwd[bnds] = position;
595
197k
          ptr_rvlc->is_last = position;
596
197k
          break;
597
598
281k
        case NOISE_HCB:
599
281k
          if (ptr_rvlc->noise_used == 0) {
600
21.4k
            ptr_rvlc->noise_used = 1;
601
21.4k
            ptr_rvlc->first_noise_band = bnds;
602
21.4k
            noise_energy += ptr_rvlc->dpcm_noise_nrg;
603
21.4k
            ptr_scf_fwd[bnds] = noise_energy;
604
21.4k
            ptr_rvlc->last_nrg = noise_energy;
605
260k
          } else {
606
260k
            dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
607
260k
            if (dpcm < 0) {
608
2.97k
              ptr_rvlc->conceal_max = bnds;
609
2.97k
              return;
610
2.97k
            }
611
257k
            dpcm -= 7;
612
257k
            if ((dpcm == -7) || (dpcm == 7)) {
613
3.85k
              if (ptr_rvlc->rvlc_esc_len) {
614
925
                ptr_rvlc->conceal_max = bnds;
615
925
                return;
616
2.93k
              } else {
617
2.93k
                if (dpcm == -7) {
618
1.50k
                  dpcm -= *ptr_scf_esc++;
619
1.50k
                } else {
620
1.42k
                  dpcm += *ptr_scf_esc++;
621
1.42k
                }
622
2.93k
                (*ptr_esc_fwd_cnt)++;
623
2.93k
                if (ptr_rvlc->conceal_max_esc == 1311) {
624
1.50k
                  ptr_rvlc->conceal_max_esc = bnds;
625
1.50k
                }
626
2.93k
              }
627
3.85k
            }
628
256k
            noise_energy += dpcm;
629
256k
            ptr_scf_fwd[bnds] = noise_energy;
630
256k
            ptr_rvlc->last_nrg = noise_energy;
631
256k
          }
632
277k
          ptr_aac_dec_channel_info->str_pns_info.pns_used[bnds] = 1;
633
277k
          break;
634
635
163k
        default:
636
163k
          ptr_rvlc->sf_used = 1;
637
163k
          {
638
163k
            memcpy(&temp_buf, it_bit_buff, sizeof(ia_bit_buf_struct));
639
640
163k
            dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
641
163k
            if (dpcm < 0) {
642
2.96k
              ptr_rvlc->conceal_max = bnds;
643
2.96k
              return;
644
2.96k
            }
645
160k
            dpcm -= 7;
646
160k
          }
647
160k
          if ((dpcm == -7) || (dpcm == 7)) {
648
5.85k
            if (ptr_rvlc->rvlc_esc_len) {
649
2.39k
              ptr_rvlc->conceal_max = bnds;
650
2.39k
              return;
651
3.46k
            } else {
652
3.46k
              if (dpcm == -7) {
653
1.45k
                dpcm -= *ptr_scf_esc++;
654
2.00k
              } else {
655
2.00k
                dpcm += *ptr_scf_esc++;
656
2.00k
              }
657
3.46k
              (*ptr_esc_fwd_cnt)++;
658
3.46k
              if (ptr_rvlc->conceal_max_esc == 1311) {
659
2.09k
                ptr_rvlc->conceal_max_esc = bnds;
660
2.09k
              }
661
3.46k
            }
662
5.85k
          }
663
158k
          factor += dpcm;
664
158k
          ptr_scf_fwd[bnds] = factor;
665
158k
          ptr_rvlc->last_scale_fac = factor;
666
158k
          break;
667
740k
      }
668
740k
    }
669
76.2k
  }
670
671
50.5k
  if (ptr_rvlc->intensity_used) {
672
11.5k
    dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
673
11.5k
    if (dpcm < 0) {
674
530
      ptr_rvlc->conceal_max = bnds;
675
530
      return;
676
530
    }
677
11.0k
    dpcm -= 7;
678
11.0k
    if ((dpcm == -7) || (dpcm == 7)) {
679
714
      if (ptr_rvlc->rvlc_esc_len) {
680
166
        ptr_rvlc->conceal_max = bnds;
681
166
        return;
682
548
      } else {
683
548
        if (dpcm == -7) {
684
97
          dpcm -= *ptr_scf_esc++;
685
451
        } else {
686
451
          dpcm += *ptr_scf_esc++;
687
451
        }
688
548
        (*ptr_esc_fwd_cnt)++;
689
548
        if (ptr_rvlc->conceal_max_esc == 1311) {
690
346
          ptr_rvlc->conceal_max_esc = bnds;
691
346
        }
692
548
      }
693
714
    }
694
10.8k
    ptr_rvlc->dpcm_is_last_pos = dpcm;
695
10.8k
  }
696
50.5k
}
697
698
static VOID ixheaacd_rvlc_decode_backward(
699
    ia_rvlc_info_struct *ptr_rvlc,
700
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info,
701
66.7k
    ia_bit_buf_struct *it_bit_buff) {
702
66.7k
  WORD16 band, group, dpcm;
703
66.7k
  WORD16 bnds = ptr_rvlc->max_sfb_transmitted - 1;
704
705
66.7k
  WORD16 factor = ptr_rvlc->rev_global_gain;
706
66.7k
  WORD16 position = ptr_rvlc->dpcm_is_last_pos;
707
66.7k
  WORD16 noise_energy =
708
66.7k
      ptr_rvlc->rev_global_gain + ptr_rvlc->dpcm_noise_last_pos - 90 - 256;
709
710
66.7k
  WORD16 *ptr_scf_bwd = ptr_aac_dec_channel_info->rvlc_scf_bwd_arr;
711
66.7k
  WORD16 *ptr_scf_esc = ptr_aac_dec_channel_info->rvlc_scf_esc_arr;
712
66.7k
  UWORD8 *ptr_esc_cnt = &(ptr_rvlc->num_esc_words_decoded);
713
66.7k
  UWORD8 *ptr_esc_bwd_cnt = &(ptr_rvlc->num_bwd_esc_words_decoded);
714
715
66.7k
  ptr_rvlc->ptr_rvl_bit_cnt = &(ptr_rvlc->rvlc_sf_bwd_len);
716
66.7k
  ptr_rvlc->ptr_rvl_bit_str_idx = &(ptr_rvlc->rvl_bwd_bit_str_idx);
717
718
66.7k
  *ptr_esc_bwd_cnt = 0;
719
66.7k
  ptr_rvlc->direction = 1;
720
66.7k
  ptr_scf_esc += *ptr_esc_cnt - 1;
721
66.7k
  ptr_rvlc->firt_scale_fac = 0;
722
66.7k
  ptr_rvlc->first_nrg = 0;
723
66.7k
  ptr_rvlc->is_first = 0;
724
725
66.7k
  if (ptr_rvlc->intensity_used) {
726
20.8k
    dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
727
20.8k
    if (dpcm < 0) {
728
3.17k
      ptr_rvlc->dpcm_is_last_pos = 0;
729
3.17k
      ptr_rvlc->conceal_min = bnds;
730
3.17k
      return;
731
3.17k
    }
732
17.6k
    dpcm -= 7;
733
17.6k
    if ((dpcm == -7) || (dpcm == 7)) {
734
1.38k
      if (ptr_rvlc->rvlc_esc_len) {
735
1.26k
        ptr_rvlc->conceal_min = bnds;
736
1.26k
        return;
737
1.26k
      } else {
738
120
        if (dpcm == -7) {
739
29
          dpcm -= *ptr_scf_esc--;
740
91
        } else {
741
91
          dpcm += *ptr_scf_esc--;
742
91
        }
743
120
        (*ptr_esc_bwd_cnt)++;
744
120
        if (ptr_rvlc->conceal_min_esc == -1311) {
745
120
          ptr_rvlc->conceal_min_esc = bnds;
746
120
        }
747
120
      }
748
1.38k
    }
749
16.4k
    ptr_rvlc->dpcm_is_last_pos = dpcm;
750
16.4k
  }
751
752
112k
  for (group = ptr_rvlc->num_wind_grps - 1; group >= 0; group--) {
753
526k
    for (band = ptr_rvlc->max_sfb_transmitted - 1; band >= 0; band--) {
754
477k
      bnds = 16 * group + band;
755
756
477k
      switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
757
37.5k
        case ZERO_HCB:
758
37.5k
          ptr_scf_bwd[bnds] = 0;
759
37.5k
          break;
760
761
66.2k
        case INTENSITY_HCB2:
762
160k
        case INTENSITY_HCB:
763
764
160k
          dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
765
160k
          if (dpcm < 0) {
766
4.07k
            ptr_scf_bwd[bnds] = position;
767
768
4.07k
            return;
769
4.07k
          }
770
156k
          dpcm -= 7;
771
156k
          if ((dpcm == -7) || (dpcm == 7)) {
772
4.86k
            if (ptr_rvlc->rvlc_esc_len) {
773
1.64k
              ptr_scf_bwd[bnds] = position;
774
775
1.64k
              return;
776
3.21k
            } else {
777
3.21k
              if (dpcm == -7) {
778
593
                dpcm -= *ptr_scf_esc--;
779
2.62k
              } else {
780
2.62k
                dpcm += *ptr_scf_esc--;
781
2.62k
              }
782
3.21k
              (*ptr_esc_bwd_cnt)++;
783
3.21k
              if (ptr_rvlc->conceal_min_esc == -1311) {
784
2.60k
              }
785
3.21k
            }
786
4.86k
          }
787
154k
          ptr_scf_bwd[bnds] = position;
788
154k
          position -= dpcm;
789
154k
          ptr_rvlc->is_first = position;
790
154k
          break;
791
792
176k
        case NOISE_HCB:
793
176k
          if (bnds == ptr_rvlc->first_noise_band) {
794
10.9k
            ptr_scf_bwd[bnds] = ptr_rvlc->dpcm_noise_nrg +
795
10.9k
                                ptr_aac_dec_channel_info->global_gain - 90 -
796
10.9k
                                256;
797
10.9k
            ptr_rvlc->first_nrg = ptr_scf_bwd[bnds];
798
165k
          } else {
799
165k
            dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
800
165k
            if (dpcm < 0) {
801
9.23k
              ptr_scf_bwd[bnds] = noise_energy;
802
9.23k
              return;
803
9.23k
            }
804
156k
            dpcm -= 7;
805
156k
            if ((dpcm == -7) || (dpcm == 7)) {
806
5.37k
              if (ptr_rvlc->rvlc_esc_len) {
807
734
                ptr_scf_bwd[bnds] = noise_energy;
808
734
                return;
809
4.64k
              } else {
810
4.64k
                if (dpcm == -7) {
811
3.18k
                  dpcm -= *ptr_scf_esc--;
812
3.18k
                } else {
813
1.46k
                  dpcm += *ptr_scf_esc--;
814
1.46k
                }
815
4.64k
                (*ptr_esc_bwd_cnt)++;
816
4.64k
                if (ptr_rvlc->conceal_min_esc == -1311) {
817
4.64k
                }
818
4.64k
              }
819
5.37k
            }
820
155k
            ptr_scf_bwd[bnds] = noise_energy;
821
155k
            noise_energy -= dpcm;
822
155k
            ptr_rvlc->first_nrg = noise_energy;
823
155k
          }
824
166k
          break;
825
826
166k
        default:
827
102k
          dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
828
102k
          if (dpcm < 0) {
829
3.48k
            ptr_scf_bwd[bnds] = factor;
830
831
3.48k
            return;
832
3.48k
          }
833
99.1k
          dpcm -= 7;
834
99.1k
          if ((dpcm == -7) || (dpcm == 7)) {
835
5.45k
            if (ptr_rvlc->rvlc_esc_len) {
836
2.92k
              ptr_scf_bwd[bnds] = factor;
837
838
2.92k
              return;
839
2.92k
            } else {
840
2.53k
              if (dpcm == -7) {
841
861
                dpcm -= *ptr_scf_esc--;
842
1.67k
              } else {
843
1.67k
                dpcm += *ptr_scf_esc--;
844
1.67k
              }
845
2.53k
              (*ptr_esc_bwd_cnt)++;
846
2.53k
              if (ptr_rvlc->conceal_min_esc == -1311) {
847
2.53k
              }
848
2.53k
            }
849
5.45k
          }
850
96.1k
          ptr_scf_bwd[bnds] = factor;
851
96.1k
          factor -= dpcm;
852
96.1k
          ptr_rvlc->firt_scale_fac = factor;
853
96.1k
          break;
854
477k
      }
855
477k
    }
856
71.7k
  }
857
62.3k
}
858
859
VOID ixheaacd_rvlc_read(
860
    ia_bit_buf_struct *it_bit_buff,
861
67.0k
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info) {
862
67.0k
  ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
863
864
67.0k
  WORD32 group, band;
865
866
67.0k
  ptr_rvlc->num_wind_grps =
867
67.0k
      ptr_aac_dec_channel_info->str_ics_info.num_window_groups;
868
67.0k
  ptr_rvlc->max_sfb_transmitted =
869
67.0k
      ptr_aac_dec_channel_info->str_ics_info.max_sfb;
870
67.0k
  ptr_rvlc->noise_used = 0;
871
67.0k
  ptr_rvlc->dpcm_noise_nrg = 0;
872
67.0k
  ptr_rvlc->dpcm_noise_last_pos = 0;
873
67.0k
  ptr_rvlc->rvlc_esc_len = -1;
874
67.0k
  ptr_rvlc->dpcm_is_last_pos = 0;
875
876
67.0k
  ptr_rvlc->sf_concealment = ixheaacd_read_bits_buf(it_bit_buff, 1);
877
67.0k
  ptr_rvlc->rev_global_gain = ixheaacd_read_bits_buf(it_bit_buff, 8);
878
879
67.0k
  if (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
880
67.0k
      EIGHT_SHORT_SEQUENCE) {
881
2.65k
    ptr_rvlc->rvlc_sf_len = ixheaacd_read_bits_buf(it_bit_buff, 11);
882
64.3k
  } else {
883
64.3k
    ptr_rvlc->rvlc_sf_len = ixheaacd_read_bits_buf(it_bit_buff, 9);
884
64.3k
  }
885
886
143k
  for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
887
659k
    for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
888
608k
      if (ptr_aac_dec_channel_info->ptr_code_book[16 * group + band] ==
889
608k
          NOISE_HCB) {
890
24.7k
        ptr_rvlc->noise_used = 1;
891
24.7k
        break;
892
24.7k
      }
893
608k
    }
894
76.4k
  }
895
896
67.0k
  if (ptr_rvlc->noise_used)
897
24.7k
    ptr_rvlc->dpcm_noise_nrg = ixheaacd_read_bits_buf(it_bit_buff, 9);
898
899
67.0k
  ptr_rvlc->sf_esc_present = ixheaacd_read_bits_buf(it_bit_buff, 1);
900
901
67.0k
  if (ptr_rvlc->sf_esc_present) {
902
32.1k
    ptr_rvlc->rvlc_esc_len = ixheaacd_read_bits_buf(it_bit_buff, 8);
903
32.1k
  }
904
905
67.0k
  if (ptr_rvlc->noise_used) {
906
24.7k
    ptr_rvlc->dpcm_noise_last_pos = ixheaacd_read_bits_buf(it_bit_buff, 9);
907
24.7k
    ptr_rvlc->rvlc_sf_len -= 9;
908
24.7k
  }
909
910
67.0k
  ptr_rvlc->rvlc_sf_fwd_len = ptr_rvlc->rvlc_sf_len;
911
67.0k
  ptr_rvlc->rvlc_sf_bwd_len = ptr_rvlc->rvlc_sf_len;
912
67.0k
}
913
914
VOID ixheaacd_hcr_read(ia_bit_buf_struct *it_bit_buff,
915
                       ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info,
916
55.3k
                       WORD32 ele_type) {
917
55.3k
  WORD16 len_reordered_spec_data;
918
55.3k
  WORD8 len_longest_code_word;
919
920
55.3k
  ptr_aac_dec_channel_info->reorder_spect_data_len = 0;
921
55.3k
  ptr_aac_dec_channel_info->longest_cw_len = 0;
922
923
55.3k
  len_reordered_spec_data = ixheaacd_read_bits_buf(it_bit_buff, 14);
924
55.3k
  if (ele_type == ID_CPE) {
925
512
    if ((len_reordered_spec_data >= 0) && (len_reordered_spec_data <= 12288)) {
926
499
      ptr_aac_dec_channel_info->reorder_spect_data_len =
927
499
          len_reordered_spec_data;
928
499
    } else {
929
13
      if (len_reordered_spec_data > 12288) {
930
13
        ptr_aac_dec_channel_info->reorder_spect_data_len = 12288;
931
13
      }
932
13
    }
933
54.8k
  } else if (ele_type == ID_SCE || ele_type == ID_LFE || ele_type == ID_CCE) {
934
54.8k
    if ((len_reordered_spec_data >= 0) && (len_reordered_spec_data <= 6144)) {
935
50.4k
      ptr_aac_dec_channel_info->reorder_spect_data_len =
936
50.4k
          len_reordered_spec_data;
937
50.4k
    } else {
938
4.38k
      if (len_reordered_spec_data > 6144) {
939
4.38k
        ptr_aac_dec_channel_info->reorder_spect_data_len = 6144;
940
4.38k
      }
941
4.38k
    }
942
54.8k
  }
943
944
55.3k
  len_longest_code_word = ixheaacd_read_bits_buf(it_bit_buff, 6);
945
55.3k
  if ((len_longest_code_word >= 0) && (len_longest_code_word <= 49)) {
946
46.6k
    ptr_aac_dec_channel_info->longest_cw_len = len_longest_code_word;
947
46.6k
  } else {
948
8.68k
    if (len_longest_code_word > 49) {
949
8.68k
      ptr_aac_dec_channel_info->longest_cw_len = 49;
950
8.68k
    }
951
8.68k
  }
952
55.3k
}
953
954
static IA_ERRORCODE ixheaacd_rvlc_init(
955
    ia_rvlc_info_struct *ptr_rvlc,
956
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info,
957
66.8k
    ia_bit_buf_struct *it_bit_buff) {
958
66.8k
  WORD16 *ptr_scf_esc = ptr_aac_dec_channel_info->rvlc_scf_esc_arr;
959
66.8k
  WORD16 *ptr_scf_fwd = ptr_aac_dec_channel_info->rvlc_scf_fwd_arr;
960
66.8k
  WORD16 *ptr_scf_bwd = ptr_aac_dec_channel_info->rvlc_scf_bwd_arr;
961
66.8k
  WORD16 *ptr_scale_factor = ptr_aac_dec_channel_info->ptr_scale_factor;
962
66.8k
  WORD32 bnds;
963
964
66.8k
  ptr_aac_dec_channel_info->rvlc_intensity_used = 0;
965
966
66.8k
  ptr_rvlc->num_esc_words_decoded = 0;
967
66.8k
  ptr_rvlc->num_fwd_esc_words_decoded = 0;
968
66.8k
  ptr_rvlc->num_bwd_esc_words_decoded = 0;
969
970
66.8k
  ptr_rvlc->intensity_used = 0;
971
66.8k
  ptr_rvlc->rvlc_err_log = 0;
972
973
66.8k
  ptr_rvlc->conceal_max = CONCEAL_MAX_INIT;
974
66.8k
  ptr_rvlc->conceal_min = CONCEAL_MIN_INIT;
975
976
66.8k
  ptr_rvlc->conceal_max_esc = CONCEAL_MAX_INIT;
977
66.8k
  ptr_rvlc->conceal_min_esc = CONCEAL_MIN_INIT;
978
979
8.62M
  for (bnds = 0; bnds < RVLC_MAX_SFB; bnds++) {
980
8.56M
    ptr_scf_fwd[bnds] = 0;
981
8.56M
    ptr_scf_bwd[bnds] = 0;
982
8.56M
    ptr_scf_esc[bnds] = 0;
983
8.56M
    ptr_scale_factor[bnds] = 0;
984
8.56M
  }
985
986
66.8k
  ptr_rvlc->rvl_fwd_bit_str_idx = it_bit_buff->size - it_bit_buff->cnt_bits;
987
66.8k
  ptr_rvlc->rvl_bwd_bit_str_idx =
988
66.8k
      it_bit_buff->size - it_bit_buff->cnt_bits + ptr_rvlc->rvlc_sf_len - 1;
989
990
66.8k
  it_bit_buff->cnt_bits -= ptr_rvlc->rvlc_sf_len;
991
66.8k
  it_bit_buff->ptr_read_next =
992
66.8k
      it_bit_buff->ptr_bit_buf_base +
993
66.8k
      ((it_bit_buff->size - it_bit_buff->cnt_bits) >> 3);
994
66.8k
  it_bit_buff->bit_pos = ((it_bit_buff->size - it_bit_buff->cnt_bits) & 7);
995
996
66.8k
  if (ptr_rvlc->sf_esc_present != 0) {
997
32.1k
    ptr_rvlc->esc_bit_str_idx = it_bit_buff->size - it_bit_buff->cnt_bits;
998
999
32.1k
    it_bit_buff->cnt_bits -= ptr_rvlc->rvlc_esc_len;
1000
32.1k
    it_bit_buff->ptr_read_next =
1001
32.1k
        it_bit_buff->ptr_bit_buf_base +
1002
32.1k
        ((it_bit_buff->size - it_bit_buff->cnt_bits) >> 3);
1003
32.1k
    it_bit_buff->bit_pos = ((it_bit_buff->size - it_bit_buff->cnt_bits) & 7);
1004
32.1k
  }
1005
66.8k
  if (it_bit_buff->cnt_bits < 0) {
1006
92
    return IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES;
1007
92
  } else
1008
66.7k
    return IA_NO_ERROR;
1009
66.8k
}
1010
1011
VOID ixheaacd_bi_dir_est_scf_prev_frame_reference(
1012
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info,
1013
0
    ia_aac_dec_overlap_info *ptr_aac_dec_static_channel_info) {
1014
0
  ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
1015
0
  WORD32 band, bnds, start_band, end_band, group;
1016
0
  WORD32 conceal_min, conceal_max;
1017
0
  WORD32 conceal_group_min, conceal_group_max;
1018
0
  WORD32 max_scf_bands;
1019
0
  WORD32 common_min;
1020
1021
0
  if (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
1022
0
      EIGHT_SHORT_SEQUENCE) {
1023
0
    max_scf_bands = 16;
1024
0
  } else {
1025
0
    max_scf_bands = 64;
1026
0
  }
1027
1028
0
  if (ptr_rvlc->conceal_min == CONCEAL_MIN_INIT) ptr_rvlc->conceal_min = 0;
1029
1030
0
  if (ptr_rvlc->conceal_max == CONCEAL_MAX_INIT)
1031
0
    ptr_rvlc->conceal_max =
1032
0
        (ptr_rvlc->num_wind_grps - 1) * 16 + ptr_rvlc->max_sfb_transmitted - 1;
1033
1034
0
  conceal_min = ptr_rvlc->conceal_min % max_scf_bands;
1035
0
  conceal_group_min = ptr_rvlc->conceal_min / max_scf_bands;
1036
0
  conceal_max = ptr_rvlc->conceal_max % max_scf_bands;
1037
0
  conceal_group_max = ptr_rvlc->conceal_max / max_scf_bands;
1038
1039
0
  ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[ptr_rvlc->conceal_max] =
1040
0
      ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[ptr_rvlc->conceal_max];
1041
0
  ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[ptr_rvlc->conceal_min] =
1042
0
      ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[ptr_rvlc->conceal_min];
1043
1044
0
  start_band = conceal_min;
1045
0
  if (conceal_group_min == conceal_group_max)
1046
0
    end_band = conceal_max;
1047
0
  else
1048
0
    end_band = ptr_rvlc->max_sfb_transmitted - 1;
1049
1050
0
  for (group = conceal_group_min; group <= conceal_group_max; group++) {
1051
0
    for (band = start_band; band <= end_band; band++) {
1052
0
      bnds = 16 * group + band;
1053
0
      switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
1054
0
        case ZERO_HCB:
1055
0
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = 0;
1056
0
          break;
1057
1058
0
        case INTENSITY_HCB:
1059
0
        case INTENSITY_HCB2:
1060
0
          if ((ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] ==
1061
0
               INTENSITY_HCB) ||
1062
0
              (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] ==
1063
0
               INTENSITY_HCB2)) {
1064
0
            common_min = ixheaac_min32(
1065
0
                ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds],
1066
0
                ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds]);
1067
0
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ixheaac_min32(
1068
0
                common_min,
1069
0
                ptr_aac_dec_static_channel_info->rvlc_prev_sf[bnds]);
1070
0
          } else {
1071
0
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ixheaac_min32(
1072
0
                ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds],
1073
0
                ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds]);
1074
0
          }
1075
0
          break;
1076
1077
0
        case NOISE_HCB:
1078
0
          if (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] ==
1079
0
              NOISE_HCB) {
1080
0
            common_min = ixheaac_min32(
1081
0
                ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds],
1082
0
                ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds]);
1083
0
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ixheaac_min32(
1084
0
                common_min,
1085
0
                ptr_aac_dec_static_channel_info->rvlc_prev_sf[bnds]);
1086
0
          } else {
1087
0
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ixheaac_min32(
1088
0
                ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds],
1089
0
                ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds]);
1090
0
          }
1091
0
          break;
1092
1093
0
        default:
1094
0
          if ((ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] !=
1095
0
               ZERO_HCB) &&
1096
0
              (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] !=
1097
0
               NOISE_HCB) &&
1098
0
              (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] !=
1099
0
               INTENSITY_HCB) &&
1100
0
              (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] !=
1101
0
               INTENSITY_HCB2)) {
1102
0
            common_min = ixheaac_min32(
1103
0
                ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds],
1104
0
                ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds]);
1105
0
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ixheaac_min32(
1106
0
                common_min,
1107
0
                ptr_aac_dec_static_channel_info->rvlc_prev_sf[bnds]);
1108
0
          } else {
1109
0
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ixheaac_min32(
1110
0
                ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds],
1111
0
                ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds]);
1112
0
          }
1113
0
          break;
1114
0
      }
1115
0
    }
1116
0
    start_band = 0;
1117
0
    if ((group + 1) == conceal_group_max) end_band = conceal_max;
1118
0
  }
1119
1120
0
  if (conceal_group_min == 0)
1121
0
    end_band = conceal_min;
1122
0
  else
1123
0
    end_band = ptr_rvlc->max_sfb_transmitted;
1124
0
  for (group = 0; group <= conceal_group_min; group++) {
1125
0
    for (band = 0; band < end_band; band++) {
1126
0
      bnds = 16 * group + band;
1127
0
      ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1128
0
          ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1129
0
    }
1130
0
    if ((group + 1) == conceal_group_min) end_band = conceal_min;
1131
0
  }
1132
1133
0
  start_band = conceal_max + 1;
1134
0
  for (group = conceal_group_max; group < ptr_rvlc->num_wind_grps; group++) {
1135
0
    for (band = start_band; band < ptr_rvlc->max_sfb_transmitted; band++) {
1136
0
      bnds = 16 * group + band;
1137
0
      ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1138
0
          ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1139
0
    }
1140
0
    start_band = 0;
1141
0
  }
1142
0
}
1143
1144
static VOID ixheaacd_calc_ref_val_fwd(
1145
    ia_rvlc_info_struct *ptr_rvlc,
1146
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, WORD32 *ref_fwd,
1147
11.4k
    WORD32 *ref_nrg_fwd, WORD32 *ref_scf_fwd) {
1148
11.4k
  WORD32 band, bnds, group, start_band;
1149
11.4k
  WORD32 id_is, id_nrg, id_scf;
1150
11.4k
  WORD32 conceal_min, conceal_group_min;
1151
11.4k
  WORD32 max_scf_bands;
1152
1153
11.4k
  if (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
1154
11.4k
      EIGHT_SHORT_SEQUENCE)
1155
114
    max_scf_bands = 16;
1156
11.3k
  else
1157
11.3k
    max_scf_bands = 64;
1158
1159
11.4k
  conceal_min = ptr_rvlc->conceal_min % max_scf_bands;
1160
11.4k
  conceal_group_min = ptr_rvlc->conceal_min / max_scf_bands;
1161
1162
11.4k
  id_is = id_nrg = id_scf = 1;
1163
1164
11.4k
  *ref_nrg_fwd = ptr_aac_dec_channel_info->global_gain - 90 - 256;
1165
11.4k
  *ref_scf_fwd = ptr_aac_dec_channel_info->global_gain;
1166
1167
11.4k
  start_band = conceal_min - 1;
1168
22.8k
  for (group = conceal_group_min; group >= 0; group--) {
1169
72.7k
    for (band = start_band; band >= 0; band--) {
1170
61.2k
      bnds = 16 * group + band;
1171
61.2k
      switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
1172
3.04k
        case ZERO_HCB:
1173
3.04k
          break;
1174
17.0k
        case INTENSITY_HCB:
1175
34.7k
        case INTENSITY_HCB2:
1176
34.7k
          if (id_is) {
1177
2.78k
            *ref_fwd = ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1178
2.78k
            id_is = 0;
1179
2.78k
          }
1180
34.7k
          break;
1181
20.2k
        case NOISE_HCB:
1182
20.2k
          if (id_nrg) {
1183
2.59k
            *ref_nrg_fwd = ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1184
2.59k
            id_nrg = 0;
1185
2.59k
          }
1186
20.2k
          break;
1187
3.22k
        default:
1188
3.22k
          if (id_scf) {
1189
1.17k
            *ref_scf_fwd = ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1190
1.17k
            id_scf = 0;
1191
1.17k
          }
1192
3.22k
          break;
1193
61.2k
      }
1194
61.2k
    }
1195
11.4k
    start_band = ptr_rvlc->max_sfb_transmitted - 1;
1196
11.4k
  }
1197
11.4k
}
1198
1199
static VOID ixheaacd_calc_ref_val_bwd(
1200
    ia_rvlc_info_struct *ptr_rvlc,
1201
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, WORD32 *ref_bwd,
1202
11.4k
    WORD32 *ref_nrg_bwd, WORD32 *ref_scf_bwd) {
1203
11.4k
  WORD32 band, bnds, group, start_band;
1204
11.4k
  WORD32 id_is, id_nrg, id_scf;
1205
11.4k
  WORD32 conceal_max, conceal_group_max;
1206
11.4k
  WORD32 max_scf_bands;
1207
1208
11.4k
  if (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
1209
11.4k
      EIGHT_SHORT_SEQUENCE)
1210
114
    max_scf_bands = 16;
1211
11.3k
  else
1212
11.3k
    max_scf_bands = 64;
1213
1214
11.4k
  conceal_max = ptr_rvlc->conceal_max % max_scf_bands;
1215
11.4k
  conceal_group_max = ptr_rvlc->conceal_max / max_scf_bands;
1216
1217
11.4k
  id_is = id_nrg = id_scf = 1;
1218
1219
11.4k
  *ref_bwd = ptr_rvlc->dpcm_is_last_pos;
1220
11.4k
  *ref_nrg_bwd = ptr_rvlc->rev_global_gain + ptr_rvlc->dpcm_noise_last_pos -
1221
11.4k
                 90 - 256 + ptr_rvlc->dpcm_noise_nrg;
1222
11.4k
  *ref_scf_bwd = ptr_rvlc->rev_global_gain;
1223
1224
11.4k
  start_band = conceal_max + 1;
1225
1226
22.8k
  for (group = conceal_group_max; group < ptr_rvlc->num_wind_grps; group++) {
1227
71.5k
    for (band = start_band; band < ptr_rvlc->max_sfb_transmitted; band++) {
1228
60.1k
      bnds = 16 * group + band;
1229
60.1k
      switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
1230
425
        case ZERO_HCB:
1231
425
          break;
1232
5.88k
        case INTENSITY_HCB:
1233
55.9k
        case INTENSITY_HCB2:
1234
55.9k
          if (id_is) {
1235
3.15k
            *ref_bwd = ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1236
3.15k
            id_is = 0;
1237
3.15k
          }
1238
55.9k
          break;
1239
2.45k
        case NOISE_HCB:
1240
2.45k
          if (id_nrg) {
1241
467
            *ref_nrg_bwd = ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1242
467
            id_nrg = 0;
1243
467
          }
1244
2.45k
          break;
1245
1.38k
        default:
1246
1.38k
          if (id_scf) {
1247
415
            *ref_scf_bwd = ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1248
415
            id_scf = 0;
1249
415
          }
1250
1.38k
          break;
1251
60.1k
      }
1252
60.1k
    }
1253
11.4k
    start_band = 0;
1254
11.4k
  }
1255
11.4k
}
1256
1257
VOID ixheaacd_bi_dir_est_lower_scf_cur_frame(
1258
15.3k
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info) {
1259
15.3k
  ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
1260
15.3k
  WORD32 band, bnds, start_band, end_band, group;
1261
15.3k
  WORD32 conceal_min, conceal_max;
1262
15.3k
  WORD32 conceal_group_min, conceal_group_max;
1263
15.3k
  WORD32 max_scf_bands;
1264
1265
15.3k
  if (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
1266
15.3k
      EIGHT_SHORT_SEQUENCE) {
1267
114
    max_scf_bands = 16;
1268
15.2k
  } else {
1269
15.2k
    max_scf_bands = 64;
1270
15.2k
  }
1271
1272
15.3k
  if (ptr_rvlc->conceal_min == CONCEAL_MIN_INIT) ptr_rvlc->conceal_min = 0;
1273
1274
15.3k
  if (ptr_rvlc->conceal_max == CONCEAL_MAX_INIT)
1275
2.06k
    ptr_rvlc->conceal_max =
1276
2.06k
        (ptr_rvlc->num_wind_grps - 1) * 16 + ptr_rvlc->max_sfb_transmitted - 1;
1277
1278
15.3k
  conceal_min = ptr_rvlc->conceal_min % max_scf_bands;
1279
15.3k
  conceal_group_min = ptr_rvlc->conceal_min / max_scf_bands;
1280
15.3k
  conceal_max = ptr_rvlc->conceal_max % max_scf_bands;
1281
15.3k
  conceal_group_max = ptr_rvlc->conceal_max / max_scf_bands;
1282
1283
15.3k
  if (ptr_rvlc->conceal_min == ptr_rvlc->conceal_max) {
1284
11.4k
    WORD32 ref_fwd = 0, ref_nrg_fwd = 0, ref_scf_fwd = 0;
1285
11.4k
    WORD32 ref_bwd = 0, ref_nrg_bwd = 0, ref_scf_bwd = 0;
1286
1287
11.4k
    bnds = ptr_rvlc->conceal_min;
1288
11.4k
    ixheaacd_calc_ref_val_fwd(ptr_rvlc, ptr_aac_dec_channel_info, &ref_fwd,
1289
11.4k
                              &ref_nrg_fwd, &ref_scf_fwd);
1290
11.4k
    ixheaacd_calc_ref_val_bwd(ptr_rvlc, ptr_aac_dec_channel_info, &ref_bwd,
1291
11.4k
                              &ref_nrg_bwd, &ref_scf_bwd);
1292
1293
11.4k
    switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
1294
2.81k
      case ZERO_HCB:
1295
2.81k
        break;
1296
279
      case INTENSITY_HCB:
1297
2.90k
      case INTENSITY_HCB2:
1298
2.90k
        if (ref_fwd < ref_bwd)
1299
1.24k
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_fwd;
1300
1.65k
        else
1301
1.65k
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_bwd;
1302
2.90k
        break;
1303
2.27k
      case NOISE_HCB:
1304
2.27k
        if (ref_nrg_fwd < ref_nrg_bwd)
1305
861
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_nrg_fwd;
1306
1.41k
        else
1307
1.41k
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_nrg_bwd;
1308
2.27k
        break;
1309
3.43k
      default:
1310
3.43k
        if (ref_scf_fwd < ref_scf_bwd)
1311
947
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_scf_fwd;
1312
2.49k
        else
1313
2.49k
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_scf_bwd;
1314
3.43k
        break;
1315
11.4k
    }
1316
11.4k
  } else {
1317
3.92k
    ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[ptr_rvlc->conceal_max] =
1318
3.92k
        ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[ptr_rvlc->conceal_max];
1319
3.92k
    ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[ptr_rvlc->conceal_min] =
1320
3.92k
        ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[ptr_rvlc->conceal_min];
1321
1322
3.92k
    start_band = conceal_min;
1323
3.92k
    if (conceal_group_min == conceal_group_max)
1324
3.92k
      end_band = conceal_max;
1325
0
    else
1326
0
      end_band = ptr_rvlc->max_sfb_transmitted - 1;
1327
1328
7.85k
    for (group = conceal_group_min; group <= conceal_group_max; group++) {
1329
71.4k
      for (band = start_band; band <= end_band; band++) {
1330
67.5k
        bnds = 16 * group + band;
1331
67.5k
        if (ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds] <
1332
67.5k
            ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds])
1333
13.3k
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1334
13.3k
              ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1335
54.1k
        else
1336
54.1k
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1337
54.1k
              ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1338
67.5k
      }
1339
3.92k
      start_band = 0;
1340
3.92k
      if ((group + 1) == conceal_group_max) end_band = conceal_max;
1341
3.92k
    }
1342
3.92k
  }
1343
1344
15.3k
  if (conceal_group_min == 0)
1345
15.3k
    end_band = conceal_min;
1346
0
  else
1347
0
    end_band = ptr_rvlc->max_sfb_transmitted;
1348
30.7k
  for (group = 0; group <= conceal_group_min; group++) {
1349
76.6k
    for (band = 0; band < end_band; band++) {
1350
61.2k
      bnds = 16 * group + band;
1351
61.2k
      ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1352
61.2k
          ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1353
61.2k
    }
1354
15.3k
    if ((group + 1) == conceal_group_min) end_band = conceal_min;
1355
15.3k
  }
1356
1357
15.3k
  start_band = conceal_max + 1;
1358
30.7k
  for (group = conceal_group_max; group < ptr_rvlc->num_wind_grps; group++) {
1359
116k
    for (band = start_band; band < ptr_rvlc->max_sfb_transmitted; band++) {
1360
101k
      bnds = 16 * group + band;
1361
101k
      ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1362
101k
          ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1363
101k
    }
1364
15.3k
    start_band = 0;
1365
15.3k
  }
1366
15.3k
}
1367
1368
VOID ixheaacd_statistical_estimation(
1369
6.60k
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info) {
1370
6.60k
  ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
1371
6.60k
  WORD32 band, bnds, group;
1372
6.60k
  WORD32 sum_fwd, sum_bwd;
1373
6.60k
  WORD32 sum_nrg_fwd, sum_nrg_bwd;
1374
6.60k
  WORD32 sum_scf_fwd, sum_scf_bwd;
1375
6.60k
  WORD32 use_fwd, use_nrg_fwd, use_scf_fwd;
1376
1377
6.60k
  sum_fwd = sum_bwd = sum_nrg_fwd = sum_nrg_bwd = sum_scf_fwd = sum_scf_bwd = 0;
1378
6.60k
  use_fwd = use_nrg_fwd = use_scf_fwd = 0;
1379
1380
13.2k
  for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
1381
181k
    for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
1382
175k
      bnds = 16 * group + band;
1383
175k
      switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
1384
22.2k
        case ZERO_HCB:
1385
22.2k
          break;
1386
1387
66.3k
        case INTENSITY_HCB:
1388
69.8k
        case INTENSITY_HCB2:
1389
69.8k
          sum_fwd += ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1390
69.8k
          sum_bwd += ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1391
69.8k
          break;
1392
1393
70.3k
        case NOISE_HCB:
1394
70.3k
          sum_nrg_fwd += ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1395
70.3k
          sum_nrg_bwd += ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1396
70.3k
          break;
1397
1398
12.8k
        default:
1399
12.8k
          sum_scf_fwd += ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1400
12.8k
          sum_scf_bwd += ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1401
12.8k
          break;
1402
175k
      }
1403
175k
    }
1404
6.60k
  }
1405
1406
6.60k
  if (sum_fwd < sum_bwd) use_fwd = 1;
1407
1408
6.60k
  if (sum_nrg_fwd < sum_nrg_bwd) use_nrg_fwd = 1;
1409
1410
6.60k
  if (sum_scf_fwd < sum_scf_bwd) use_scf_fwd = 1;
1411
1412
13.2k
  for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
1413
181k
    for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
1414
175k
      bnds = 16 * group + band;
1415
175k
      switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
1416
22.2k
        case ZERO_HCB:
1417
22.2k
          break;
1418
1419
66.3k
        case INTENSITY_HCB:
1420
69.8k
        case INTENSITY_HCB2:
1421
69.8k
          if (use_fwd)
1422
21.3k
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1423
21.3k
                ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1424
48.5k
          else
1425
48.5k
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1426
48.5k
                ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1427
69.8k
          break;
1428
1429
70.3k
        case NOISE_HCB:
1430
70.3k
          if (use_nrg_fwd)
1431
18.3k
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1432
18.3k
                ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1433
51.9k
          else
1434
51.9k
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1435
51.9k
                ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1436
70.3k
          break;
1437
1438
12.8k
        default:
1439
12.8k
          if (use_scf_fwd)
1440
1.28k
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1441
1.28k
                ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1442
11.5k
          else
1443
11.5k
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1444
11.5k
                ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1445
12.8k
          break;
1446
175k
      }
1447
175k
    }
1448
6.60k
  }
1449
6.60k
}
1450
1451
VOID ixheaacd_predictive_interpolation(
1452
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info,
1453
0
    ia_aac_dec_overlap_info *ptr_aac_dec_static_channel_info) {
1454
0
  ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
1455
0
  WORD32 band, bnds, group;
1456
0
  WORD32 common_min;
1457
1458
0
  for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
1459
0
    for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
1460
0
      bnds = 16 * group + band;
1461
0
      switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
1462
0
        case ZERO_HCB:
1463
0
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = 0;
1464
0
          break;
1465
1466
0
        case INTENSITY_HCB:
1467
0
        case INTENSITY_HCB2:
1468
0
          if ((ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] ==
1469
0
               INTENSITY_HCB) ||
1470
0
              (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] ==
1471
0
               INTENSITY_HCB2)) {
1472
0
            common_min = ixheaac_min32(
1473
0
                ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds],
1474
0
                ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds]);
1475
0
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ixheaac_min32(
1476
0
                common_min,
1477
0
                ptr_aac_dec_static_channel_info->rvlc_prev_sf[bnds]);
1478
0
          } else {
1479
0
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = -110;
1480
0
          }
1481
0
          break;
1482
1483
0
        case NOISE_HCB:
1484
0
          if (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] ==
1485
0
              NOISE_HCB) {
1486
0
            common_min = ixheaac_min32(
1487
0
                ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds],
1488
0
                ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds]);
1489
0
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ixheaac_min32(
1490
0
                common_min,
1491
0
                ptr_aac_dec_static_channel_info->rvlc_prev_sf[bnds]);
1492
0
          } else {
1493
0
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = -110;
1494
0
          }
1495
0
          break;
1496
1497
0
        default:
1498
0
          if ((ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] !=
1499
0
               ZERO_HCB) &&
1500
0
              (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] !=
1501
0
               NOISE_HCB) &&
1502
0
              (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] !=
1503
0
               INTENSITY_HCB) &&
1504
0
              (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] !=
1505
0
               INTENSITY_HCB2)) {
1506
0
            common_min = ixheaac_min32(
1507
0
                ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds],
1508
0
                ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds]);
1509
0
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ixheaac_min32(
1510
0
                common_min,
1511
0
                ptr_aac_dec_static_channel_info->rvlc_prev_sf[bnds]);
1512
0
          } else {
1513
0
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = 0;
1514
0
          }
1515
0
          break;
1516
0
      }
1517
0
    }
1518
0
  }
1519
0
}
1520
static VOID ixheaacd_rvlc_final_error_detection(
1521
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info,
1522
66.7k
    ia_aac_dec_overlap_info *ptr_aac_dec_static_channel_info) {
1523
66.7k
  ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
1524
66.7k
  UWORD8 err_status_complete = 0;
1525
66.7k
  UWORD8 err_status_length_fwd = 0;
1526
66.7k
  UWORD8 err_status_length_bwd = 0;
1527
66.7k
  UWORD8 err_status_length_escape = 0;
1528
66.7k
  UWORD8 err_status_first_scf = 0;
1529
66.7k
  UWORD8 err_status_last_scf = 0;
1530
66.7k
  UWORD8 err_status_first_nrg = 0;
1531
66.7k
  UWORD8 err_status_last_nrg = 0;
1532
66.7k
  UWORD8 err_status_first_is = 0;
1533
66.7k
  UWORD8 err_status_last_is = 0;
1534
66.7k
  UWORD8 err_status_forbidden_cw_fwd = 0;
1535
66.7k
  UWORD8 err_status_forbidden_cw_bwd = 0;
1536
66.7k
  UWORD8 err_status_num_escapes_fwd = 0;
1537
66.7k
  UWORD8 err_status_num_escapes_bwd = 0;
1538
66.7k
  UWORD8 conceal_status = 1;
1539
66.7k
  UWORD8 current_block_type;
1540
1541
66.7k
  ptr_aac_dec_channel_info->rvlc_curr_sf_flag = 1;
1542
1543
66.7k
  if (ptr_rvlc->rvlc_err_log & RVLC_ERROR_FORBIDDEN_CW_DETECTED_FWD)
1544
0
    err_status_forbidden_cw_fwd = 1;
1545
1546
66.7k
  if (ptr_rvlc->rvlc_err_log & RVLC_ERROR_FORBIDDEN_CW_DETECTED_BWD)
1547
0
    err_status_forbidden_cw_bwd = 1;
1548
1549
66.7k
  if (ptr_rvlc->rvlc_sf_fwd_len) err_status_length_fwd = 1;
1550
1551
66.7k
  if (ptr_rvlc->rvlc_sf_bwd_len) err_status_length_bwd = 1;
1552
1553
66.7k
  if (ptr_rvlc->sf_esc_present)
1554
32.0k
    if (ptr_rvlc->rvlc_esc_len) err_status_length_escape = 1;
1555
1556
66.7k
  if (ptr_rvlc->sf_used) {
1557
25.7k
    if (ptr_rvlc->firt_scale_fac != (ptr_aac_dec_channel_info->global_gain))
1558
25.5k
      err_status_first_scf = 1;
1559
1560
25.7k
    if (ptr_rvlc->last_scale_fac != (ptr_rvlc->rev_global_gain))
1561
24.9k
      err_status_last_scf = 1;
1562
25.7k
  }
1563
1564
66.7k
  if (ptr_rvlc->noise_used) {
1565
21.4k
    if (ptr_rvlc->first_nrg != (ptr_aac_dec_channel_info->global_gain +
1566
21.4k
                                ptr_rvlc->dpcm_noise_nrg - 90 - 256))
1567
13.0k
      err_status_first_nrg = 1;
1568
1569
21.4k
    if (ptr_rvlc->last_nrg !=
1570
21.4k
        (ptr_rvlc->rev_global_gain + ptr_rvlc->dpcm_noise_last_pos - 90 - 256))
1571
21.1k
      err_status_last_nrg = 1;
1572
21.4k
  }
1573
1574
66.7k
  if (ptr_rvlc->intensity_used) {
1575
20.8k
    if (ptr_rvlc->is_first != 0) err_status_first_is = 1;
1576
1577
20.8k
    if (ptr_rvlc->is_last != (ptr_rvlc->dpcm_is_last_pos))
1578
12.0k
      err_status_last_is = 1;
1579
20.8k
  }
1580
1581
66.7k
  if ((ptr_rvlc->num_fwd_esc_words_decoded !=
1582
66.7k
       ptr_rvlc->num_esc_words_decoded) &&
1583
30.0k
      (ptr_rvlc->conceal_max == CONCEAL_MAX_INIT)) {
1584
22.3k
    err_status_num_escapes_fwd = 1;
1585
22.3k
  }
1586
1587
66.7k
  if ((ptr_rvlc->num_bwd_esc_words_decoded !=
1588
66.7k
       ptr_rvlc->num_esc_words_decoded) &&
1589
29.0k
      (ptr_rvlc->conceal_min == CONCEAL_MIN_INIT)) {
1590
25.7k
    err_status_num_escapes_bwd = 1;
1591
25.7k
  }
1592
1593
66.7k
  if (err_status_length_escape ||
1594
49.8k
      (((ptr_rvlc->conceal_max == CONCEAL_MAX_INIT) &&
1595
39.3k
        (ptr_rvlc->num_fwd_esc_words_decoded !=
1596
39.3k
         ptr_rvlc->num_esc_words_decoded) &&
1597
11.9k
        (err_status_last_scf || err_status_last_nrg || err_status_last_is))
1598
1599
8.01k
       &&
1600
1601
8.01k
       ((ptr_rvlc->conceal_min == CONCEAL_MIN_INIT) &&
1602
6.58k
        (ptr_rvlc->num_bwd_esc_words_decoded !=
1603
6.58k
         ptr_rvlc->num_esc_words_decoded) &&
1604
5.64k
        (err_status_first_scf || err_status_first_nrg ||
1605
756
         err_status_first_is))) ||
1606
44.4k
      ((ptr_rvlc->conceal_max == CONCEAL_MAX_INIT) &&
1607
33.9k
       ((ptr_rvlc->rev_global_gain - ptr_rvlc->last_scale_fac) < -15)) ||
1608
42.9k
      ((ptr_rvlc->conceal_min == CONCEAL_MIN_INIT) &&
1609
39.9k
       ((ptr_aac_dec_channel_info->global_gain - ptr_rvlc->firt_scale_fac) <
1610
39.9k
        -15))) {
1611
30.2k
    if ((ptr_rvlc->conceal_max == CONCEAL_MAX_INIT) ||
1612
29.1k
        (ptr_rvlc->conceal_min == CONCEAL_MIN_INIT)) {
1613
29.1k
      ptr_rvlc->conceal_max = 0;
1614
29.1k
      ptr_rvlc->conceal_min =
1615
29.1k
          ixheaac_max32(0, (ptr_rvlc->num_wind_grps - 1) * 16 +
1616
29.1k
                                ptr_rvlc->max_sfb_transmitted - 1);
1617
29.1k
    } else {
1618
1.06k
      ptr_rvlc->conceal_max =
1619
1.06k
          ixheaac_min32(ptr_rvlc->conceal_max, ptr_rvlc->conceal_max_esc);
1620
1.06k
      ptr_rvlc->conceal_min =
1621
1.06k
          ixheaac_max32(ptr_rvlc->conceal_min, ptr_rvlc->conceal_min_esc);
1622
1.06k
    }
1623
30.2k
  }
1624
1625
66.7k
  err_status_complete =
1626
66.7k
      err_status_last_scf || err_status_first_scf || err_status_last_nrg ||
1627
31.6k
      err_status_first_nrg || err_status_last_is || err_status_first_is ||
1628
25.8k
      err_status_forbidden_cw_fwd || err_status_forbidden_cw_bwd ||
1629
25.8k
      err_status_length_fwd || err_status_length_bwd ||
1630
8.30k
      err_status_length_escape || err_status_num_escapes_fwd ||
1631
8.17k
      err_status_num_escapes_bwd;
1632
1633
66.7k
  current_block_type =
1634
66.7k
      (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
1635
66.7k
       EIGHT_SHORT_SEQUENCE)
1636
66.7k
          ? 0
1637
66.7k
          : 1;
1638
1639
66.7k
  if (!err_status_complete) {
1640
8.17k
    WORD32 band;
1641
8.17k
    WORD32 group;
1642
8.17k
    WORD32 bnds;
1643
8.17k
    WORD32 last_sfb_idx;
1644
1645
8.17k
    last_sfb_idx = (ptr_rvlc->num_wind_grps > 1) ? 16 : 64;
1646
1647
16.9k
    for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
1648
18.5k
      for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
1649
9.75k
        bnds = 16 * group + band;
1650
9.75k
        ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1651
9.75k
            ptr_aac_dec_static_channel_info->rvlc_prev_sf[bnds] =
1652
9.75k
                ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1653
9.75k
      }
1654
8.74k
    }
1655
1656
16.9k
    for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
1657
18.5k
      for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
1658
9.75k
        bnds = 16 * group + band;
1659
9.75k
        ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] =
1660
9.75k
            ptr_aac_dec_channel_info->ptr_code_book[bnds];
1661
9.75k
      }
1662
521k
      for (; band < last_sfb_idx; band++) {
1663
512k
        bnds = 16 * group + band;
1664
512k
        ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] = ZERO_HCB;
1665
512k
      }
1666
8.74k
    }
1667
58.6k
  } else {
1668
58.6k
    WORD32 band;
1669
58.6k
    WORD32 group;
1670
1671
58.6k
    if (((ptr_rvlc->conceal_min != CONCEAL_MIN_INIT) ||
1672
25.4k
         (ptr_rvlc->conceal_max != CONCEAL_MAX_INIT)) &&
1673
40.2k
        (ptr_rvlc->conceal_min <= ptr_rvlc->conceal_max) &&
1674
15.3k
        (ptr_aac_dec_static_channel_info->rvlc_prev_blk_type ==
1675
15.3k
         current_block_type) &&
1676
114
        ptr_aac_dec_static_channel_info->rvlc_prev_sf_ok &&
1677
0
        ptr_rvlc->sf_concealment && conceal_status) {
1678
0
      ixheaacd_bi_dir_est_scf_prev_frame_reference(
1679
0
          ptr_aac_dec_channel_info, ptr_aac_dec_static_channel_info);
1680
0
      conceal_status = 0;
1681
0
    }
1682
1683
58.6k
    if ((ptr_rvlc->conceal_min <= ptr_rvlc->conceal_max) &&
1684
33.7k
        ((ptr_rvlc->conceal_min != CONCEAL_MIN_INIT) ||
1685
25.4k
         (ptr_rvlc->conceal_max != CONCEAL_MAX_INIT)) &&
1686
15.3k
        !(ptr_aac_dec_static_channel_info->rvlc_prev_sf_ok &&
1687
0
          ptr_rvlc->sf_concealment &&
1688
0
          (ptr_aac_dec_static_channel_info->rvlc_prev_blk_type ==
1689
0
           current_block_type)) &&
1690
15.3k
        conceal_status) {
1691
15.3k
      ixheaacd_bi_dir_est_lower_scf_cur_frame(ptr_aac_dec_channel_info);
1692
15.3k
      conceal_status = 0;
1693
15.3k
    }
1694
1695
58.6k
    if ((ptr_rvlc->conceal_min <= ptr_rvlc->conceal_max) &&
1696
33.7k
        ((err_status_last_scf && err_status_first_scf) ||
1697
26.1k
         (err_status_last_nrg && err_status_first_nrg) ||
1698
22.2k
         (err_status_last_is && err_status_first_is)) &&
1699
13.8k
        !(err_status_forbidden_cw_fwd || err_status_forbidden_cw_bwd ||
1700
13.8k
          err_status_length_escape) &&
1701
13.5k
        conceal_status) {
1702
6.60k
      ixheaacd_statistical_estimation(ptr_aac_dec_channel_info);
1703
6.60k
      conceal_status = 0;
1704
6.60k
    }
1705
1706
58.6k
    if ((ptr_rvlc->conceal_min <= ptr_rvlc->conceal_max) &&
1707
33.7k
        ptr_aac_dec_static_channel_info->rvlc_prev_sf_ok &&
1708
0
        ptr_rvlc->sf_concealment &&
1709
0
        (ptr_aac_dec_static_channel_info->rvlc_prev_blk_type ==
1710
0
         current_block_type) &&
1711
0
        conceal_status) {
1712
0
      ixheaacd_predictive_interpolation(ptr_aac_dec_channel_info,
1713
0
                                        ptr_aac_dec_static_channel_info);
1714
0
      conceal_status = 0;
1715
0
    }
1716
1717
58.6k
    if (conceal_status) {
1718
82.1k
      for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
1719
541k
        for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
1720
496k
          ptr_aac_dec_channel_info->ptr_scale_factor[16 * group + band] = 0;
1721
496k
        }
1722
45.4k
      }
1723
36.6k
      ptr_aac_dec_channel_info->rvlc_curr_sf_flag = 0;
1724
36.6k
    }
1725
58.6k
  }
1726
66.7k
}
1727
1728
IA_ERRORCODE ixheaacd_rvlc_dec(
1729
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info,
1730
    ia_aac_dec_overlap_info *ptr_aac_dec_static_channel_info,
1731
66.8k
    ia_bit_buf_struct *it_bit_buff) {
1732
66.8k
  ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
1733
66.8k
  ia_bit_buf_struct saved_it_bit_buff;
1734
66.8k
  IA_ERRORCODE error_code = 0;
1735
66.8k
  error_code =
1736
66.8k
      ixheaacd_rvlc_init(ptr_rvlc, ptr_aac_dec_channel_info, it_bit_buff);
1737
66.8k
  if (error_code) return error_code;
1738
1739
66.7k
  ixheaacd_bitbuf_checkpoint(*it_bit_buff, saved_it_bit_buff);
1740
66.7k
  if (ptr_rvlc->sf_esc_present)
1741
32.0k
    ixheaacd_rvlc_decode_escape(
1742
32.0k
        ptr_rvlc, ptr_aac_dec_channel_info->rvlc_scf_esc_arr, it_bit_buff);
1743
1744
66.7k
  ixheaacd_rvlc_decode_forward(ptr_rvlc, ptr_aac_dec_channel_info, it_bit_buff);
1745
66.7k
  ixheaacd_rvlc_decode_backward(ptr_rvlc, ptr_aac_dec_channel_info,
1746
66.7k
                                it_bit_buff);
1747
66.7k
  ixheaacd_rvlc_final_error_detection(ptr_aac_dec_channel_info,
1748
66.7k
                                      ptr_aac_dec_static_channel_info);
1749
1750
66.7k
  ptr_aac_dec_channel_info->rvlc_intensity_used = ptr_rvlc->intensity_used;
1751
66.7k
  ptr_aac_dec_channel_info->str_pns_info.pns_active = ptr_rvlc->noise_used;
1752
1753
66.7k
  ixheaacd_bitbuf_restore(*it_bit_buff, saved_it_bit_buff);
1754
66.7k
  return error_code;
1755
66.8k
}