Coverage Report

Created: 2026-03-21 07:02

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
47.0k
#define RVLC_ERROR_FORBIDDEN_CW_DETECTED_FWD 0x08000000
84
47.0k
#define RVLC_ERROR_FORBIDDEN_CW_DETECTED_BWD 0x04000000
85
86
3.11M
#define FWD 0
87
#define BWD 1
88
89
1.56M
#define MAX_LEN_RVLC_CODE_WORD 9
90
2.02M
#define MAX_LEN_RVLC_ESCAPE_WORD 20
91
92
249k
#define CONCEAL_MAX_INIT 1311
93
233k
#define CONCEAL_MIN_INIT -1311
94
95
6.07M
#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
47.0k
  (saved_bit_buf) = (it_bit_buf)
104
#define ixheaacd_bitbuf_restore(it_bit_buf, saved_bit_buf) \
105
47.0k
  (it_bit_buf) = (saved_bit_buf)
106
107
1.95M
static WORD32 ixheaacd_rvlc_decode(WORD16 cw, WORD32 len, WORD32 *found) {
108
1.95M
  WORD16 indx = 0;
109
1.95M
  *found = 0;
110
1.95M
  switch (len) {
111
793k
    case 1:
112
793k
      if (cw == 0)
113
468k
        indx = 0;
114
325k
      else
115
325k
        return 3;
116
468k
      break;
117
468k
    case 3:
118
325k
      switch (cw) {
119
55.8k
        case 5:
120
55.8k
          indx = -1;
121
55.8k
          break;
122
137k
        case 7:
123
137k
          indx = 1;
124
137k
          break;
125
131k
        default:
126
131k
          return 4;
127
325k
      }
128
193k
      break;
129
193k
    case 4:
130
131k
      if (cw == 9)
131
14.3k
        indx = -2;
132
117k
      else
133
117k
        return 5;
134
14.3k
      break;
135
117k
    case 5:
136
117k
      switch (cw) {
137
17.2k
        case 17:
138
17.2k
          indx = -3;
139
17.2k
          break;
140
13.2k
        case 27:
141
13.2k
          indx = 2;
142
13.2k
          break;
143
87.1k
        default:
144
87.1k
          return 6;
145
117k
      }
146
30.4k
      break;
147
87.1k
    case 6:
148
87.1k
      switch (cw) {
149
4.45k
        case 33:
150
4.45k
          indx = -4;
151
4.45k
          break;
152
1.65k
        case 51:
153
1.65k
          indx = 3;
154
1.65k
          break;
155
81.0k
        default:
156
81.0k
          return 7;
157
87.1k
      }
158
6.10k
      break;
159
81.0k
    case 7:
160
81.0k
      switch (cw) {
161
12.9k
        case 65:
162
12.9k
          indx = -7;
163
12.9k
          break;
164
13.0k
        case 107:
165
13.0k
          indx = 4;
166
13.0k
          break;
167
10.3k
        case 99:
168
10.3k
          indx = 7;
169
10.3k
          break;
170
44.7k
        default:
171
44.7k
          return 8;
172
81.0k
      }
173
36.2k
      break;
174
44.7k
    case 8:
175
44.7k
      switch (cw) {
176
656
        case 129:
177
656
          indx = -5;
178
656
          break;
179
712
        case 195:
180
712
          indx = 5;
181
712
          break;
182
43.4k
        default:
183
43.4k
          return 9;
184
44.7k
      }
185
1.36k
      break;
186
43.4k
    case 9:
187
43.4k
      switch (cw) {
188
6.35k
        case 257:
189
6.35k
          indx = -6;
190
6.35k
          break;
191
12.2k
        case 427:
192
12.2k
          indx = 6;
193
12.2k
          break;
194
24.7k
        default:
195
24.7k
          return -1;
196
43.4k
      }
197
18.6k
      break;
198
325k
    default:
199
325k
      return -1;
200
1.95M
  }
201
769k
  *found = 1;
202
769k
  return indx;
203
1.95M
}
204
205
3.11M
static WORD32 ixheaacd_rvlc_decode_esc(WORD32 cw, WORD32 len, WORD32 *found) {
206
3.11M
  WORD16 indx = 0;
207
3.11M
  *found = 0;
208
3.11M
  switch (len) {
209
1.01M
    case 2:
210
1.01M
      switch (cw) {
211
168k
        case 2:
212
168k
          indx = 0;
213
168k
          break;
214
388k
        case 0:
215
388k
          indx = 1;
216
388k
          break;
217
456k
        default:
218
456k
          return 3;
219
1.01M
      }
220
556k
      break;
221
556k
    case 3:
222
456k
      switch (cw) {
223
99.0k
        case 6:
224
99.0k
          indx = 2;
225
99.0k
          break;
226
62.8k
        case 2:
227
62.8k
          indx = 3;
228
62.8k
          break;
229
294k
        default:
230
294k
          return 4;
231
456k
      }
232
161k
      break;
233
294k
    case 4:
234
294k
      if (cw == 14)
235
51.0k
        indx = 4;
236
243k
      else
237
243k
        return 5;
238
51.0k
      break;
239
243k
    case 5:
240
243k
      switch (cw) {
241
161k
        case 31:
242
161k
          indx = 5;
243
161k
          break;
244
22.5k
        case 15:
245
22.5k
          indx = 6;
246
22.5k
          break;
247
11.3k
        case 13:
248
11.3k
          indx = 7;
249
11.3k
          break;
250
47.9k
        default:
251
47.9k
          return 6;
252
243k
      }
253
195k
      break;
254
195k
    case 6:
255
47.9k
      switch (cw) {
256
8.13k
        case 61:
257
8.13k
          indx = 8;
258
8.13k
          break;
259
7.16k
        case 29:
260
7.16k
          indx = 9;
261
7.16k
          break;
262
4.46k
        case 25:
263
4.46k
          indx = 10;
264
4.46k
          break;
265
4.92k
        case 24:
266
4.92k
          indx = 11;
267
4.92k
          break;
268
23.2k
        default:
269
23.2k
          return 7;
270
47.9k
      }
271
24.6k
      break;
272
24.6k
    case 7:
273
23.2k
      switch (cw) {
274
9.70k
        case 120:
275
9.70k
          indx = 12;
276
9.70k
          break;
277
4.97k
        case 56:
278
4.97k
          indx = 13;
279
4.97k
          break;
280
8.59k
        default:
281
8.59k
          return 8;
282
23.2k
      }
283
14.6k
      break;
284
14.6k
    case 8:
285
8.59k
      switch (cw) {
286
2.68k
        case 242:
287
2.68k
          indx = 14;
288
2.68k
          break;
289
1.48k
        case 114:
290
1.48k
          indx = 15;
291
1.48k
          break;
292
4.42k
        default:
293
4.42k
          return 9;
294
8.59k
      }
295
4.16k
      break;
296
4.42k
    case 9:
297
4.42k
      switch (cw) {
298
160
        case 486:
299
160
          indx = 16;
300
160
          break;
301
1.24k
        case 230:
302
1.24k
          indx = 17;
303
1.24k
          break;
304
3.02k
        default:
305
3.02k
          return 10;
306
4.42k
      }
307
1.40k
      break;
308
3.02k
    case 10:
309
3.02k
      switch (cw) {
310
224
        case 974:
311
224
          indx = 18;
312
224
          break;
313
57
        case 463:
314
57
          indx = 19;
315
57
          break;
316
2.73k
        default:
317
2.73k
          return 11;
318
3.02k
      }
319
281
      break;
320
2.73k
    case 11:
321
2.73k
      switch (cw) {
322
176
        case 1950:
323
176
          indx = 20;
324
176
          break;
325
231
        case 1951:
326
231
          indx = 21;
327
231
          break;
328
905
        case 925:
329
905
          indx = 22;
330
905
          break;
331
1.42k
        default:
332
1.42k
          return 12;
333
2.73k
      }
334
1.31k
      break;
335
1.42k
    case 12:
336
1.42k
      if (cw == 1848)
337
232
        indx = 23;
338
1.19k
      else
339
1.19k
        return 13;
340
232
      break;
341
1.19k
    case 13:
342
1.19k
      if (cw == 3698)
343
295
        indx = 25;
344
900
      else
345
900
        return 14;
346
295
      break;
347
900
    case 14:
348
900
      if (cw == 7399)
349
24
        indx = 24;
350
876
      else
351
876
        return 15;
352
24
      break;
353
876
    case 15:
354
876
      if (cw == 14797)
355
99
        indx = 26;
356
777
      else
357
777
        return 19;
358
99
      break;
359
777
    case 19:
360
777
      if ((cw >= 236736) && (cw <= 236740))
361
306
        indx = 53 - (236740 - cw);
362
471
      else
363
471
        return 20;
364
306
      break;
365
471
    case 20:
366
471
      if ((cw >= 473482) && (cw <= 473503))
367
471
        indx = 48 - (473503 - cw);
368
0
      else
369
0
        return -1;
370
471
      break;
371
1.01M
    default:
372
1.01M
      return -1;
373
3.11M
  }
374
1.01M
  *found = 1;
375
1.01M
  return indx;
376
3.11M
}
377
static VOID ixheaacd_rvlc_check_intensity_cb(
378
    ia_rvlc_info_struct *ptr_rvlc,
379
47.0k
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info) {
380
47.0k
  WORD32 group, band, bnds;
381
382
47.0k
  ptr_rvlc->intensity_used = 0;
383
384
105k
  for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
385
424k
    for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
386
381k
      bnds = 16 * group + band;
387
381k
      if ((ptr_aac_dec_channel_info->ptr_code_book[bnds] == INTENSITY_HCB) ||
388
373k
          (ptr_aac_dec_channel_info->ptr_code_book[bnds] == INTENSITY_HCB2)) {
389
15.8k
        ptr_rvlc->intensity_used = 1;
390
15.8k
        break;
391
15.8k
      }
392
381k
    }
393
58.3k
  }
394
47.0k
}
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
5.07M
                               UWORD16 *ptr_position, UWORD8 read_direction) {
409
5.07M
  UWORD32 bit;
410
5.07M
  WORD32 read_bit_offset =
411
5.07M
      *ptr_position - (it_bit_buff->size - it_bit_buff->cnt_bits);
412
413
5.07M
  if (read_bit_offset) it_bit_buff->cnt_bits -= read_bit_offset;
414
415
5.07M
  it_bit_buff->ptr_read_next =
416
5.07M
      it_bit_buff->ptr_bit_buf_base +
417
5.07M
      ((it_bit_buff->size - it_bit_buff->cnt_bits) >> 3);
418
5.07M
  it_bit_buff->bit_pos = ((it_bit_buff->size - it_bit_buff->cnt_bits) & 7);
419
420
5.07M
  if (read_direction == 0) {
421
4.18M
    bit = ixheaacd_aac_read_bit_rev(it_bit_buff);
422
423
4.18M
    *ptr_position += 1;
424
4.18M
  } else {
425
888k
    bit = ixheaacd_aac_read_bit(it_bit_buff);
426
427
888k
    *ptr_position -= 1;
428
888k
  }
429
430
5.07M
  return (bit);
431
5.07M
}
432
433
static WORD8 ixheaacd_rvlc_decode_escape_word(ia_rvlc_info_struct *ptr_rvlc,
434
1.01M
                                              ia_bit_buf_struct *it_bit_buff) {
435
1.01M
  WORD32 i;
436
437
1.01M
  UWORD8 carry_bit;
438
439
1.01M
  UWORD16 *ptr_bitstream_index_esc;
440
441
1.01M
  int len = 0;
442
1.01M
  int codeword = 0;
443
1.01M
  int found = 0;
444
1.01M
  int indx;
445
446
1.01M
  ptr_bitstream_index_esc = &(ptr_rvlc->esc_bit_str_idx);
447
448
3.11M
  for (i = MAX_LEN_RVLC_ESCAPE_WORD - 1; i >= 0; i--) {
449
3.11M
    carry_bit =
450
3.11M
        ixheaacd_rvlc_read_bits(it_bit_buff, ptr_bitstream_index_esc, FWD);
451
452
3.11M
    len++;
453
3.11M
    codeword = codeword << 1 | carry_bit;
454
3.11M
    indx = ixheaacd_rvlc_decode_esc(codeword, len, &found);
455
456
3.11M
    if (found) {
457
1.01M
      ptr_rvlc->rvlc_esc_len -= (MAX_LEN_RVLC_ESCAPE_WORD - i);
458
1.01M
      return indx;
459
1.01M
    }
460
3.11M
  }
461
462
0
  ptr_rvlc->rvlc_err_log |= RVLC_ERROR_ALL_ESCAPE_WORDS_INVALID;
463
464
0
  return -1;
465
1.01M
}
466
467
static VOID ixheaacd_rvlc_decode_escape(ia_rvlc_info_struct *ptr_rvlc,
468
                                        WORD16 *ptr_escape,
469
23.0k
                                        ia_bit_buf_struct *it_bit_buff) {
470
23.0k
  WORD8 esc_word;
471
23.0k
  WORD8 esc_cnt = 0;
472
23.0k
  WORD16 *ptr_esc_bit_cnt_sum;
473
474
23.0k
  ptr_esc_bit_cnt_sum = &(ptr_rvlc->rvlc_esc_len);
475
476
1.03M
  while (*ptr_esc_bit_cnt_sum > 0) {
477
1.01M
    esc_word = ixheaacd_rvlc_decode_escape_word(ptr_rvlc, it_bit_buff);
478
479
1.01M
    if (esc_word >= 0) {
480
1.01M
      ptr_escape[esc_cnt] = esc_word;
481
1.01M
      esc_cnt++;
482
1.01M
    } 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.01M
  }
489
490
23.0k
  ptr_rvlc->num_esc_words_decoded = esc_cnt;
491
23.0k
}
492
493
WORD8 ixheaacd_decode_rvlc_code_word(ia_bit_buf_struct *it_bit_buff,
494
793k
                                     ia_rvlc_info_struct *ptr_rvlc) {
495
793k
  WORD32 i;
496
497
793k
  UWORD8 carry_bit;
498
499
793k
  UWORD8 direction = ptr_rvlc->direction;
500
793k
  UWORD16 *ptr_bit_str_idx_rvl = ptr_rvlc->ptr_rvl_bit_str_idx;
501
502
793k
  int len = 0;
503
793k
  short codeword = 0;
504
793k
  int found = 0;
505
793k
  int indx;
506
507
1.97M
  for (i = MAX_LEN_RVLC_CODE_WORD - 1; i >= 0; i--) {
508
1.95M
    carry_bit =
509
1.95M
        ixheaacd_rvlc_read_bits(it_bit_buff, ptr_bit_str_idx_rvl, direction);
510
511
1.95M
    len++;
512
1.95M
    codeword = codeword << 1 | carry_bit;
513
1.95M
    indx = ixheaacd_rvlc_decode(codeword, len, &found);
514
1.95M
    if (found) {
515
769k
      indx = indx + 7;
516
769k
      *ptr_rvlc->ptr_rvl_bit_cnt -= (MAX_LEN_RVLC_CODE_WORD - i);
517
769k
      return indx;
518
769k
    }
519
1.95M
  }
520
521
24.7k
  return -1;
522
793k
}
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
47.0k
    ia_bit_buf_struct *it_bit_buff) {
528
47.0k
  WORD32 band = 0;
529
47.0k
  WORD32 group = 0;
530
47.0k
  WORD32 bnds = 0;
531
532
47.0k
  WORD16 dpcm;
533
534
47.0k
  ia_bit_buf_struct temp_buf = {0};
535
536
47.0k
  WORD16 factor = ptr_aac_dec_channel_info->global_gain;
537
47.0k
  WORD16 position = 0;
538
47.0k
  WORD16 noise_energy = ptr_aac_dec_channel_info->global_gain - 90 - 256;
539
540
47.0k
  WORD16 *ptr_scf_fwd = ptr_aac_dec_channel_info->rvlc_scf_fwd_arr;
541
47.0k
  WORD16 *ptr_scf_esc = ptr_aac_dec_channel_info->rvlc_scf_esc_arr;
542
47.0k
  UWORD8 *ptr_esc_fwd_cnt = &(ptr_rvlc->num_fwd_esc_words_decoded);
543
544
47.0k
  ptr_rvlc->ptr_rvl_bit_cnt = &(ptr_rvlc->rvlc_sf_fwd_len);
545
47.0k
  ptr_rvlc->ptr_rvl_bit_str_idx = &(ptr_rvlc->rvl_fwd_bit_str_idx);
546
547
47.0k
  *ptr_esc_fwd_cnt = 0;
548
47.0k
  ptr_rvlc->direction = 0;
549
47.0k
  ptr_rvlc->noise_used = 0;
550
47.0k
  ptr_rvlc->sf_used = 0;
551
47.0k
  ptr_rvlc->last_scale_fac = 0;
552
47.0k
  ptr_rvlc->last_nrg = 0;
553
47.0k
  ptr_rvlc->is_last = 0;
554
555
47.0k
  ixheaacd_rvlc_check_intensity_cb(ptr_rvlc, ptr_aac_dec_channel_info);
556
557
93.2k
  for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
558
591k
    for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
559
544k
      bnds = 16 * group + band;
560
561
544k
      switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
562
70.3k
        case ZERO_HCB:
563
70.3k
          ptr_scf_fwd[bnds] = 0;
564
70.3k
          break;
565
566
45.8k
        case INTENSITY_HCB2:
567
149k
        case INTENSITY_HCB:
568
569
149k
        {
570
149k
          dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
571
149k
          if (dpcm < 0) {
572
3.80k
            ptr_rvlc->conceal_max = bnds;
573
3.80k
            return;
574
3.80k
          }
575
145k
          dpcm -= 7;
576
145k
        }
577
145k
          if ((dpcm == -7) || (dpcm == 7)) {
578
4.52k
            if (ptr_rvlc->rvlc_esc_len) {
579
920
              ptr_rvlc->conceal_max = bnds;
580
920
              return;
581
3.60k
            } else {
582
3.60k
              if (dpcm == -7) {
583
2.26k
                dpcm -= *ptr_scf_esc++;
584
2.26k
              } else {
585
1.34k
                dpcm += *ptr_scf_esc++;
586
1.34k
              }
587
3.60k
              (*ptr_esc_fwd_cnt)++;
588
3.60k
              if (ptr_rvlc->conceal_max_esc == 1311) {
589
642
                ptr_rvlc->conceal_max_esc = bnds;
590
642
              }
591
3.60k
            }
592
4.52k
          }
593
144k
          position += dpcm;
594
144k
          ptr_scf_fwd[bnds] = position;
595
144k
          ptr_rvlc->is_last = position;
596
144k
          break;
597
598
217k
        case NOISE_HCB:
599
217k
          if (ptr_rvlc->noise_used == 0) {
600
17.3k
            ptr_rvlc->noise_used = 1;
601
17.3k
            ptr_rvlc->first_noise_band = bnds;
602
17.3k
            noise_energy += ptr_rvlc->dpcm_noise_nrg;
603
17.3k
            ptr_scf_fwd[bnds] = noise_energy;
604
17.3k
            ptr_rvlc->last_nrg = noise_energy;
605
200k
          } else {
606
200k
            dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
607
200k
            if (dpcm < 0) {
608
2.55k
              ptr_rvlc->conceal_max = bnds;
609
2.55k
              return;
610
2.55k
            }
611
197k
            dpcm -= 7;
612
197k
            if ((dpcm == -7) || (dpcm == 7)) {
613
3.45k
              if (ptr_rvlc->rvlc_esc_len) {
614
1.30k
                ptr_rvlc->conceal_max = bnds;
615
1.30k
                return;
616
2.14k
              } else {
617
2.14k
                if (dpcm == -7) {
618
1.09k
                  dpcm -= *ptr_scf_esc++;
619
1.09k
                } else {
620
1.05k
                  dpcm += *ptr_scf_esc++;
621
1.05k
                }
622
2.14k
                (*ptr_esc_fwd_cnt)++;
623
2.14k
                if (ptr_rvlc->conceal_max_esc == 1311) {
624
1.09k
                  ptr_rvlc->conceal_max_esc = bnds;
625
1.09k
                }
626
2.14k
              }
627
3.45k
            }
628
196k
            noise_energy += dpcm;
629
196k
            ptr_scf_fwd[bnds] = noise_energy;
630
196k
            ptr_rvlc->last_nrg = noise_energy;
631
196k
          }
632
213k
          ptr_aac_dec_channel_info->str_pns_info.pns_used[bnds] = 1;
633
213k
          break;
634
635
107k
        default:
636
107k
          ptr_rvlc->sf_used = 1;
637
107k
          {
638
107k
            memcpy(&temp_buf, it_bit_buff, sizeof(ia_bit_buf_struct));
639
640
107k
            dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
641
107k
            if (dpcm < 0) {
642
1.90k
              ptr_rvlc->conceal_max = bnds;
643
1.90k
              return;
644
1.90k
            }
645
105k
            dpcm -= 7;
646
105k
          }
647
105k
          if ((dpcm == -7) || (dpcm == 7)) {
648
3.17k
            if (ptr_rvlc->rvlc_esc_len) {
649
1.57k
              ptr_rvlc->conceal_max = bnds;
650
1.57k
              return;
651
1.59k
            } else {
652
1.59k
              if (dpcm == -7) {
653
1.38k
                dpcm -= *ptr_scf_esc++;
654
1.38k
              } else {
655
216
                dpcm += *ptr_scf_esc++;
656
216
              }
657
1.59k
              (*ptr_esc_fwd_cnt)++;
658
1.59k
              if (ptr_rvlc->conceal_max_esc == 1311) {
659
1.48k
                ptr_rvlc->conceal_max_esc = bnds;
660
1.48k
              }
661
1.59k
            }
662
3.17k
          }
663
104k
          factor += dpcm;
664
104k
          ptr_scf_fwd[bnds] = factor;
665
104k
          ptr_rvlc->last_scale_fac = factor;
666
104k
          break;
667
544k
      }
668
544k
    }
669
58.3k
  }
670
671
34.9k
  if (ptr_rvlc->intensity_used) {
672
8.92k
    dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
673
8.92k
    if (dpcm < 0) {
674
222
      ptr_rvlc->conceal_max = bnds;
675
222
      return;
676
222
    }
677
8.69k
    dpcm -= 7;
678
8.69k
    if ((dpcm == -7) || (dpcm == 7)) {
679
381
      if (ptr_rvlc->rvlc_esc_len) {
680
49
        ptr_rvlc->conceal_max = bnds;
681
49
        return;
682
332
      } else {
683
332
        if (dpcm == -7) {
684
73
          dpcm -= *ptr_scf_esc++;
685
259
        } else {
686
259
          dpcm += *ptr_scf_esc++;
687
259
        }
688
332
        (*ptr_esc_fwd_cnt)++;
689
332
        if (ptr_rvlc->conceal_max_esc == 1311) {
690
218
          ptr_rvlc->conceal_max_esc = bnds;
691
218
        }
692
332
      }
693
381
    }
694
8.64k
    ptr_rvlc->dpcm_is_last_pos = dpcm;
695
8.64k
  }
696
34.9k
}
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
47.0k
    ia_bit_buf_struct *it_bit_buff) {
702
47.0k
  WORD16 band, group, dpcm;
703
47.0k
  WORD16 bnds = ptr_rvlc->max_sfb_transmitted - 1;
704
705
47.0k
  WORD16 factor = ptr_rvlc->rev_global_gain;
706
47.0k
  WORD16 position = ptr_rvlc->dpcm_is_last_pos;
707
47.0k
  WORD16 noise_energy =
708
47.0k
      ptr_rvlc->rev_global_gain + ptr_rvlc->dpcm_noise_last_pos - 90 - 256;
709
710
47.0k
  WORD16 *ptr_scf_bwd = ptr_aac_dec_channel_info->rvlc_scf_bwd_arr;
711
47.0k
  WORD16 *ptr_scf_esc = ptr_aac_dec_channel_info->rvlc_scf_esc_arr;
712
47.0k
  UWORD8 *ptr_esc_cnt = &(ptr_rvlc->num_esc_words_decoded);
713
47.0k
  UWORD8 *ptr_esc_bwd_cnt = &(ptr_rvlc->num_bwd_esc_words_decoded);
714
715
47.0k
  ptr_rvlc->ptr_rvl_bit_cnt = &(ptr_rvlc->rvlc_sf_bwd_len);
716
47.0k
  ptr_rvlc->ptr_rvl_bit_str_idx = &(ptr_rvlc->rvl_bwd_bit_str_idx);
717
718
47.0k
  *ptr_esc_bwd_cnt = 0;
719
47.0k
  ptr_rvlc->direction = 1;
720
47.0k
  ptr_scf_esc += *ptr_esc_cnt - 1;
721
47.0k
  ptr_rvlc->firt_scale_fac = 0;
722
47.0k
  ptr_rvlc->first_nrg = 0;
723
47.0k
  ptr_rvlc->is_first = 0;
724
725
47.0k
  if (ptr_rvlc->intensity_used) {
726
15.8k
    dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
727
15.8k
    if (dpcm < 0) {
728
3.14k
      ptr_rvlc->dpcm_is_last_pos = 0;
729
3.14k
      ptr_rvlc->conceal_min = bnds;
730
3.14k
      return;
731
3.14k
    }
732
12.7k
    dpcm -= 7;
733
12.7k
    if ((dpcm == -7) || (dpcm == 7)) {
734
1.01k
      if (ptr_rvlc->rvlc_esc_len) {
735
947
        ptr_rvlc->conceal_min = bnds;
736
947
        return;
737
947
      } else {
738
69
        if (dpcm == -7) {
739
14
          dpcm -= *ptr_scf_esc--;
740
55
        } else {
741
55
          dpcm += *ptr_scf_esc--;
742
55
        }
743
69
        (*ptr_esc_bwd_cnt)++;
744
69
        if (ptr_rvlc->conceal_min_esc == -1311) {
745
69
          ptr_rvlc->conceal_min_esc = bnds;
746
69
        }
747
69
      }
748
1.01k
    }
749
11.7k
    ptr_rvlc->dpcm_is_last_pos = dpcm;
750
11.7k
  }
751
752
80.3k
  for (group = ptr_rvlc->num_wind_grps - 1; group >= 0; group--) {
753
386k
    for (band = ptr_rvlc->max_sfb_transmitted - 1; band >= 0; band--) {
754
348k
      bnds = 16 * group + band;
755
756
348k
      switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
757
29.7k
        case ZERO_HCB:
758
29.7k
          ptr_scf_bwd[bnds] = 0;
759
29.7k
          break;
760
761
46.5k
        case INTENSITY_HCB2:
762
107k
        case INTENSITY_HCB:
763
764
107k
          dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
765
107k
          if (dpcm < 0) {
766
3.25k
            ptr_scf_bwd[bnds] = position;
767
768
3.25k
            return;
769
3.25k
          }
770
104k
          dpcm -= 7;
771
104k
          if ((dpcm == -7) || (dpcm == 7)) {
772
3.11k
            if (ptr_rvlc->rvlc_esc_len) {
773
1.20k
              ptr_scf_bwd[bnds] = position;
774
775
1.20k
              return;
776
1.90k
            } else {
777
1.90k
              if (dpcm == -7) {
778
288
                dpcm -= *ptr_scf_esc--;
779
1.61k
              } else {
780
1.61k
                dpcm += *ptr_scf_esc--;
781
1.61k
              }
782
1.90k
              (*ptr_esc_bwd_cnt)++;
783
1.90k
              if (ptr_rvlc->conceal_min_esc == -1311) {
784
1.53k
              }
785
1.90k
            }
786
3.11k
          }
787
103k
          ptr_scf_bwd[bnds] = position;
788
103k
          position -= dpcm;
789
103k
          ptr_rvlc->is_first = position;
790
103k
          break;
791
792
145k
        case NOISE_HCB:
793
145k
          if (bnds == ptr_rvlc->first_noise_band) {
794
7.34k
            ptr_scf_bwd[bnds] = ptr_rvlc->dpcm_noise_nrg +
795
7.34k
                                ptr_aac_dec_channel_info->global_gain - 90 -
796
7.34k
                                256;
797
7.34k
            ptr_rvlc->first_nrg = ptr_scf_bwd[bnds];
798
138k
          } else {
799
138k
            dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
800
138k
            if (dpcm < 0) {
801
7.95k
              ptr_scf_bwd[bnds] = noise_energy;
802
7.95k
              return;
803
7.95k
            }
804
130k
            dpcm -= 7;
805
130k
            if ((dpcm == -7) || (dpcm == 7)) {
806
3.67k
              if (ptr_rvlc->rvlc_esc_len) {
807
334
                ptr_scf_bwd[bnds] = noise_energy;
808
334
                return;
809
3.34k
              } else {
810
3.34k
                if (dpcm == -7) {
811
2.24k
                  dpcm -= *ptr_scf_esc--;
812
2.24k
                } else {
813
1.09k
                  dpcm += *ptr_scf_esc--;
814
1.09k
                }
815
3.34k
                (*ptr_esc_bwd_cnt)++;
816
3.34k
                if (ptr_rvlc->conceal_min_esc == -1311) {
817
3.34k
                }
818
3.34k
              }
819
3.67k
            }
820
129k
            ptr_scf_bwd[bnds] = noise_energy;
821
129k
            noise_energy -= dpcm;
822
129k
            ptr_rvlc->first_nrg = noise_energy;
823
129k
          }
824
137k
          break;
825
826
137k
        default:
827
65.9k
          dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
828
65.9k
          if (dpcm < 0) {
829
1.93k
            ptr_scf_bwd[bnds] = factor;
830
831
1.93k
            return;
832
1.93k
          }
833
64.0k
          dpcm -= 7;
834
64.0k
          if ((dpcm == -7) || (dpcm == 7)) {
835
3.87k
            if (ptr_rvlc->rvlc_esc_len) {
836
2.07k
              ptr_scf_bwd[bnds] = factor;
837
838
2.07k
              return;
839
2.07k
            } else {
840
1.79k
              if (dpcm == -7) {
841
950
                dpcm -= *ptr_scf_esc--;
842
950
              } else {
843
845
                dpcm += *ptr_scf_esc--;
844
845
              }
845
1.79k
              (*ptr_esc_bwd_cnt)++;
846
1.79k
              if (ptr_rvlc->conceal_min_esc == -1311) {
847
1.79k
              }
848
1.79k
            }
849
3.87k
          }
850
61.9k
          ptr_scf_bwd[bnds] = factor;
851
61.9k
          factor -= dpcm;
852
61.9k
          ptr_rvlc->firt_scale_fac = factor;
853
61.9k
          break;
854
348k
      }
855
348k
    }
856
54.2k
  }
857
42.9k
}
858
859
VOID ixheaacd_rvlc_read(
860
    ia_bit_buf_struct *it_bit_buff,
861
47.1k
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info) {
862
47.1k
  ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
863
864
47.1k
  WORD32 group, band;
865
866
47.1k
  ptr_rvlc->num_wind_grps =
867
47.1k
      ptr_aac_dec_channel_info->str_ics_info.num_window_groups;
868
47.1k
  ptr_rvlc->max_sfb_transmitted =
869
47.1k
      ptr_aac_dec_channel_info->str_ics_info.max_sfb;
870
47.1k
  ptr_rvlc->noise_used = 0;
871
47.1k
  ptr_rvlc->dpcm_noise_nrg = 0;
872
47.1k
  ptr_rvlc->dpcm_noise_last_pos = 0;
873
47.1k
  ptr_rvlc->rvlc_esc_len = -1;
874
47.1k
  ptr_rvlc->dpcm_is_last_pos = 0;
875
876
47.1k
  ptr_rvlc->sf_concealment = ixheaacd_read_bits_buf(it_bit_buff, 1);
877
47.1k
  ptr_rvlc->rev_global_gain = ixheaacd_read_bits_buf(it_bit_buff, 8);
878
879
47.1k
  if (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
880
47.1k
      EIGHT_SHORT_SEQUENCE) {
881
2.71k
    ptr_rvlc->rvlc_sf_len = ixheaacd_read_bits_buf(it_bit_buff, 11);
882
44.4k
  } else {
883
44.4k
    ptr_rvlc->rvlc_sf_len = ixheaacd_read_bits_buf(it_bit_buff, 9);
884
44.4k
  }
885
886
105k
  for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
887
450k
    for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
888
411k
      if (ptr_aac_dec_channel_info->ptr_code_book[16 * group + band] ==
889
411k
          NOISE_HCB) {
890
19.8k
        ptr_rvlc->noise_used = 1;
891
19.8k
        break;
892
19.8k
      }
893
411k
    }
894
58.4k
  }
895
896
47.1k
  if (ptr_rvlc->noise_used)
897
19.8k
    ptr_rvlc->dpcm_noise_nrg = ixheaacd_read_bits_buf(it_bit_buff, 9);
898
899
47.1k
  ptr_rvlc->sf_esc_present = ixheaacd_read_bits_buf(it_bit_buff, 1);
900
901
47.1k
  if (ptr_rvlc->sf_esc_present) {
902
23.1k
    ptr_rvlc->rvlc_esc_len = ixheaacd_read_bits_buf(it_bit_buff, 8);
903
23.1k
  }
904
905
47.1k
  if (ptr_rvlc->noise_used) {
906
19.8k
    ptr_rvlc->dpcm_noise_last_pos = ixheaacd_read_bits_buf(it_bit_buff, 9);
907
19.8k
    ptr_rvlc->rvlc_sf_len -= 9;
908
19.8k
  }
909
910
47.1k
  ptr_rvlc->rvlc_sf_fwd_len = ptr_rvlc->rvlc_sf_len;
911
47.1k
  ptr_rvlc->rvlc_sf_bwd_len = ptr_rvlc->rvlc_sf_len;
912
47.1k
}
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
40.1k
                       WORD32 ele_type) {
917
40.1k
  WORD16 len_reordered_spec_data;
918
40.1k
  WORD8 len_longest_code_word;
919
920
40.1k
  ptr_aac_dec_channel_info->reorder_spect_data_len = 0;
921
40.1k
  ptr_aac_dec_channel_info->longest_cw_len = 0;
922
923
40.1k
  len_reordered_spec_data = ixheaacd_read_bits_buf(it_bit_buff, 14);
924
40.1k
  if (ele_type == ID_CPE) {
925
331
    if ((len_reordered_spec_data >= 0) && (len_reordered_spec_data <= 12288)) {
926
312
      ptr_aac_dec_channel_info->reorder_spect_data_len =
927
312
          len_reordered_spec_data;
928
312
    } else {
929
19
      if (len_reordered_spec_data > 12288) {
930
19
        ptr_aac_dec_channel_info->reorder_spect_data_len = 12288;
931
19
      }
932
19
    }
933
39.8k
  } else if (ele_type == ID_SCE || ele_type == ID_LFE || ele_type == ID_CCE) {
934
39.7k
    if ((len_reordered_spec_data >= 0) && (len_reordered_spec_data <= 6144)) {
935
36.3k
      ptr_aac_dec_channel_info->reorder_spect_data_len =
936
36.3k
          len_reordered_spec_data;
937
36.3k
    } else {
938
3.43k
      if (len_reordered_spec_data > 6144) {
939
3.43k
        ptr_aac_dec_channel_info->reorder_spect_data_len = 6144;
940
3.43k
      }
941
3.43k
    }
942
39.7k
  }
943
944
40.1k
  len_longest_code_word = ixheaacd_read_bits_buf(it_bit_buff, 6);
945
40.1k
  if ((len_longest_code_word >= 0) && (len_longest_code_word <= 49)) {
946
32.1k
    ptr_aac_dec_channel_info->longest_cw_len = len_longest_code_word;
947
32.1k
  } else {
948
7.94k
    if (len_longest_code_word > 49) {
949
7.93k
      ptr_aac_dec_channel_info->longest_cw_len = 49;
950
7.93k
    }
951
7.94k
  }
952
40.1k
}
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
47.0k
    ia_bit_buf_struct *it_bit_buff) {
958
47.0k
  WORD16 *ptr_scf_esc = ptr_aac_dec_channel_info->rvlc_scf_esc_arr;
959
47.0k
  WORD16 *ptr_scf_fwd = ptr_aac_dec_channel_info->rvlc_scf_fwd_arr;
960
47.0k
  WORD16 *ptr_scf_bwd = ptr_aac_dec_channel_info->rvlc_scf_bwd_arr;
961
47.0k
  WORD16 *ptr_scale_factor = ptr_aac_dec_channel_info->ptr_scale_factor;
962
47.0k
  WORD32 bnds;
963
964
47.0k
  ptr_aac_dec_channel_info->rvlc_intensity_used = 0;
965
966
47.0k
  ptr_rvlc->num_esc_words_decoded = 0;
967
47.0k
  ptr_rvlc->num_fwd_esc_words_decoded = 0;
968
47.0k
  ptr_rvlc->num_bwd_esc_words_decoded = 0;
969
970
47.0k
  ptr_rvlc->intensity_used = 0;
971
47.0k
  ptr_rvlc->rvlc_err_log = 0;
972
973
47.0k
  ptr_rvlc->conceal_max = CONCEAL_MAX_INIT;
974
47.0k
  ptr_rvlc->conceal_min = CONCEAL_MIN_INIT;
975
976
47.0k
  ptr_rvlc->conceal_max_esc = CONCEAL_MAX_INIT;
977
47.0k
  ptr_rvlc->conceal_min_esc = CONCEAL_MIN_INIT;
978
979
6.07M
  for (bnds = 0; bnds < RVLC_MAX_SFB; bnds++) {
980
6.02M
    ptr_scf_fwd[bnds] = 0;
981
6.02M
    ptr_scf_bwd[bnds] = 0;
982
6.02M
    ptr_scf_esc[bnds] = 0;
983
6.02M
    ptr_scale_factor[bnds] = 0;
984
6.02M
  }
985
986
47.0k
  ptr_rvlc->rvl_fwd_bit_str_idx = it_bit_buff->size - it_bit_buff->cnt_bits;
987
47.0k
  ptr_rvlc->rvl_bwd_bit_str_idx =
988
47.0k
      it_bit_buff->size - it_bit_buff->cnt_bits + ptr_rvlc->rvlc_sf_len - 1;
989
990
47.0k
  it_bit_buff->cnt_bits -= ptr_rvlc->rvlc_sf_len;
991
47.0k
  it_bit_buff->ptr_read_next =
992
47.0k
      it_bit_buff->ptr_bit_buf_base +
993
47.0k
      ((it_bit_buff->size - it_bit_buff->cnt_bits) >> 3);
994
47.0k
  it_bit_buff->bit_pos = ((it_bit_buff->size - it_bit_buff->cnt_bits) & 7);
995
996
47.0k
  if (ptr_rvlc->sf_esc_present != 0) {
997
23.0k
    ptr_rvlc->esc_bit_str_idx = it_bit_buff->size - it_bit_buff->cnt_bits;
998
999
23.0k
    it_bit_buff->cnt_bits -= ptr_rvlc->rvlc_esc_len;
1000
23.0k
    it_bit_buff->ptr_read_next =
1001
23.0k
        it_bit_buff->ptr_bit_buf_base +
1002
23.0k
        ((it_bit_buff->size - it_bit_buff->cnt_bits) >> 3);
1003
23.0k
    it_bit_buff->bit_pos = ((it_bit_buff->size - it_bit_buff->cnt_bits) & 7);
1004
23.0k
  }
1005
47.0k
  if (it_bit_buff->cnt_bits < 0) {
1006
56
    return IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES;
1007
56
  } else
1008
47.0k
    return IA_NO_ERROR;
1009
47.0k
}
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
8.28k
    WORD32 *ref_nrg_fwd, WORD32 *ref_scf_fwd) {
1148
8.28k
  WORD32 band, bnds, group, start_band;
1149
8.28k
  WORD32 id_is, id_nrg, id_scf;
1150
8.28k
  WORD32 conceal_min, conceal_group_min;
1151
8.28k
  WORD32 max_scf_bands;
1152
1153
8.28k
  if (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
1154
8.28k
      EIGHT_SHORT_SEQUENCE)
1155
76
    max_scf_bands = 16;
1156
8.21k
  else
1157
8.21k
    max_scf_bands = 64;
1158
1159
8.28k
  conceal_min = ptr_rvlc->conceal_min % max_scf_bands;
1160
8.28k
  conceal_group_min = ptr_rvlc->conceal_min / max_scf_bands;
1161
1162
8.28k
  id_is = id_nrg = id_scf = 1;
1163
1164
8.28k
  *ref_nrg_fwd = ptr_aac_dec_channel_info->global_gain - 90 - 256;
1165
8.28k
  *ref_scf_fwd = ptr_aac_dec_channel_info->global_gain;
1166
1167
8.28k
  start_band = conceal_min - 1;
1168
16.5k
  for (group = conceal_group_min; group >= 0; group--) {
1169
62.3k
    for (band = start_band; band >= 0; band--) {
1170
54.0k
      bnds = 16 * group + band;
1171
54.0k
      switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
1172
2.20k
        case ZERO_HCB:
1173
2.20k
          break;
1174
13.1k
        case INTENSITY_HCB:
1175
33.0k
        case INTENSITY_HCB2:
1176
33.0k
          if (id_is) {
1177
2.84k
            *ref_fwd = ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1178
2.84k
            id_is = 0;
1179
2.84k
          }
1180
33.0k
          break;
1181
15.9k
        case NOISE_HCB:
1182
15.9k
          if (id_nrg) {
1183
2.44k
            *ref_nrg_fwd = ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1184
2.44k
            id_nrg = 0;
1185
2.44k
          }
1186
15.9k
          break;
1187
2.82k
        default:
1188
2.82k
          if (id_scf) {
1189
848
            *ref_scf_fwd = ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1190
848
            id_scf = 0;
1191
848
          }
1192
2.82k
          break;
1193
54.0k
      }
1194
54.0k
    }
1195
8.28k
    start_band = ptr_rvlc->max_sfb_transmitted - 1;
1196
8.28k
  }
1197
8.28k
}
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
8.28k
    WORD32 *ref_nrg_bwd, WORD32 *ref_scf_bwd) {
1203
8.28k
  WORD32 band, bnds, group, start_band;
1204
8.28k
  WORD32 id_is, id_nrg, id_scf;
1205
8.28k
  WORD32 conceal_max, conceal_group_max;
1206
8.28k
  WORD32 max_scf_bands;
1207
1208
8.28k
  if (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
1209
8.28k
      EIGHT_SHORT_SEQUENCE)
1210
76
    max_scf_bands = 16;
1211
8.21k
  else
1212
8.21k
    max_scf_bands = 64;
1213
1214
8.28k
  conceal_max = ptr_rvlc->conceal_max % max_scf_bands;
1215
8.28k
  conceal_group_max = ptr_rvlc->conceal_max / max_scf_bands;
1216
1217
8.28k
  id_is = id_nrg = id_scf = 1;
1218
1219
8.28k
  *ref_bwd = ptr_rvlc->dpcm_is_last_pos;
1220
8.28k
  *ref_nrg_bwd = ptr_rvlc->rev_global_gain + ptr_rvlc->dpcm_noise_last_pos -
1221
8.28k
                 90 - 256 + ptr_rvlc->dpcm_noise_nrg;
1222
8.28k
  *ref_scf_bwd = ptr_rvlc->rev_global_gain;
1223
1224
8.28k
  start_band = conceal_max + 1;
1225
1226
16.5k
  for (group = conceal_group_max; group < ptr_rvlc->num_wind_grps; group++) {
1227
55.2k
    for (band = start_band; band < ptr_rvlc->max_sfb_transmitted; band++) {
1228
46.9k
      bnds = 16 * group + band;
1229
46.9k
      switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
1230
77
        case ZERO_HCB:
1231
77
          break;
1232
3.48k
        case INTENSITY_HCB:
1233
36.2k
        case INTENSITY_HCB2:
1234
36.2k
          if (id_is) {
1235
2.76k
            *ref_bwd = ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1236
2.76k
            id_is = 0;
1237
2.76k
          }
1238
36.2k
          break;
1239
10.4k
        case NOISE_HCB:
1240
10.4k
          if (id_nrg) {
1241
716
            *ref_nrg_bwd = ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1242
716
            id_nrg = 0;
1243
716
          }
1244
10.4k
          break;
1245
190
        default:
1246
190
          if (id_scf) {
1247
31
            *ref_scf_bwd = ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1248
31
            id_scf = 0;
1249
31
          }
1250
190
          break;
1251
46.9k
      }
1252
46.9k
    }
1253
8.28k
    start_band = 0;
1254
8.28k
  }
1255
8.28k
}
1256
1257
VOID ixheaacd_bi_dir_est_lower_scf_cur_frame(
1258
11.3k
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info) {
1259
11.3k
  ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
1260
11.3k
  WORD32 band, bnds, start_band, end_band, group;
1261
11.3k
  WORD32 conceal_min, conceal_max;
1262
11.3k
  WORD32 conceal_group_min, conceal_group_max;
1263
11.3k
  WORD32 max_scf_bands;
1264
1265
11.3k
  if (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
1266
11.3k
      EIGHT_SHORT_SEQUENCE) {
1267
76
    max_scf_bands = 16;
1268
11.2k
  } else {
1269
11.2k
    max_scf_bands = 64;
1270
11.2k
  }
1271
1272
11.3k
  if (ptr_rvlc->conceal_min == CONCEAL_MIN_INIT) ptr_rvlc->conceal_min = 0;
1273
1274
11.3k
  if (ptr_rvlc->conceal_max == CONCEAL_MAX_INIT)
1275
2.49k
    ptr_rvlc->conceal_max =
1276
2.49k
        (ptr_rvlc->num_wind_grps - 1) * 16 + ptr_rvlc->max_sfb_transmitted - 1;
1277
1278
11.3k
  conceal_min = ptr_rvlc->conceal_min % max_scf_bands;
1279
11.3k
  conceal_group_min = ptr_rvlc->conceal_min / max_scf_bands;
1280
11.3k
  conceal_max = ptr_rvlc->conceal_max % max_scf_bands;
1281
11.3k
  conceal_group_max = ptr_rvlc->conceal_max / max_scf_bands;
1282
1283
11.3k
  if (ptr_rvlc->conceal_min == ptr_rvlc->conceal_max) {
1284
8.28k
    WORD32 ref_fwd = 0, ref_nrg_fwd = 0, ref_scf_fwd = 0;
1285
8.28k
    WORD32 ref_bwd = 0, ref_nrg_bwd = 0, ref_scf_bwd = 0;
1286
1287
8.28k
    bnds = ptr_rvlc->conceal_min;
1288
8.28k
    ixheaacd_calc_ref_val_fwd(ptr_rvlc, ptr_aac_dec_channel_info, &ref_fwd,
1289
8.28k
                              &ref_nrg_fwd, &ref_scf_fwd);
1290
8.28k
    ixheaacd_calc_ref_val_bwd(ptr_rvlc, ptr_aac_dec_channel_info, &ref_bwd,
1291
8.28k
                              &ref_nrg_bwd, &ref_scf_bwd);
1292
1293
8.28k
    switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
1294
1.65k
      case ZERO_HCB:
1295
1.65k
        break;
1296
737
      case INTENSITY_HCB:
1297
2.47k
      case INTENSITY_HCB2:
1298
2.47k
        if (ref_fwd < ref_bwd)
1299
808
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_fwd;
1300
1.66k
        else
1301
1.66k
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_bwd;
1302
2.47k
        break;
1303
2.38k
      case NOISE_HCB:
1304
2.38k
        if (ref_nrg_fwd < ref_nrg_bwd)
1305
836
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_nrg_fwd;
1306
1.54k
        else
1307
1.54k
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_nrg_bwd;
1308
2.38k
        break;
1309
1.78k
      default:
1310
1.78k
        if (ref_scf_fwd < ref_scf_bwd)
1311
1.00k
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_scf_fwd;
1312
777
        else
1313
777
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_scf_bwd;
1314
1.78k
        break;
1315
8.28k
    }
1316
8.28k
  } else {
1317
3.05k
    ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[ptr_rvlc->conceal_max] =
1318
3.05k
        ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[ptr_rvlc->conceal_max];
1319
3.05k
    ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[ptr_rvlc->conceal_min] =
1320
3.05k
        ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[ptr_rvlc->conceal_min];
1321
1322
3.05k
    start_band = conceal_min;
1323
3.05k
    if (conceal_group_min == conceal_group_max)
1324
3.05k
      end_band = conceal_max;
1325
0
    else
1326
0
      end_band = ptr_rvlc->max_sfb_transmitted - 1;
1327
1328
6.11k
    for (group = conceal_group_min; group <= conceal_group_max; group++) {
1329
53.4k
      for (band = start_band; band <= end_band; band++) {
1330
50.3k
        bnds = 16 * group + band;
1331
50.3k
        if (ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds] <
1332
50.3k
            ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds])
1333
15.7k
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1334
15.7k
              ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1335
34.6k
        else
1336
34.6k
          ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1337
34.6k
              ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1338
50.3k
      }
1339
3.05k
      start_band = 0;
1340
3.05k
      if ((group + 1) == conceal_group_max) end_band = conceal_max;
1341
3.05k
    }
1342
3.05k
  }
1343
1344
11.3k
  if (conceal_group_min == 0)
1345
11.3k
    end_band = conceal_min;
1346
0
  else
1347
0
    end_band = ptr_rvlc->max_sfb_transmitted;
1348
22.6k
  for (group = 0; group <= conceal_group_min; group++) {
1349
65.3k
    for (band = 0; band < end_band; band++) {
1350
54.0k
      bnds = 16 * group + band;
1351
54.0k
      ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1352
54.0k
          ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1353
54.0k
    }
1354
11.3k
    if ((group + 1) == conceal_group_min) end_band = conceal_min;
1355
11.3k
  }
1356
1357
11.3k
  start_band = conceal_max + 1;
1358
22.6k
  for (group = conceal_group_max; group < ptr_rvlc->num_wind_grps; group++) {
1359
91.2k
    for (band = start_band; band < ptr_rvlc->max_sfb_transmitted; band++) {
1360
79.9k
      bnds = 16 * group + band;
1361
79.9k
      ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1362
79.9k
          ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1363
79.9k
    }
1364
11.3k
    start_band = 0;
1365
11.3k
  }
1366
11.3k
}
1367
1368
VOID ixheaacd_statistical_estimation(
1369
4.70k
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info) {
1370
4.70k
  ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
1371
4.70k
  WORD32 band, bnds, group;
1372
4.70k
  WORD32 sum_fwd, sum_bwd;
1373
4.70k
  WORD32 sum_nrg_fwd, sum_nrg_bwd;
1374
4.70k
  WORD32 sum_scf_fwd, sum_scf_bwd;
1375
4.70k
  WORD32 use_fwd, use_nrg_fwd, use_scf_fwd;
1376
1377
4.70k
  sum_fwd = sum_bwd = sum_nrg_fwd = sum_nrg_bwd = sum_scf_fwd = sum_scf_bwd = 0;
1378
4.70k
  use_fwd = use_nrg_fwd = use_scf_fwd = 0;
1379
1380
9.41k
  for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
1381
118k
    for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
1382
114k
      bnds = 16 * group + band;
1383
114k
      switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
1384
15.5k
        case ZERO_HCB:
1385
15.5k
          break;
1386
1387
42.2k
        case INTENSITY_HCB:
1388
44.8k
        case INTENSITY_HCB2:
1389
44.8k
          sum_fwd += ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1390
44.8k
          sum_bwd += ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1391
44.8k
          break;
1392
1393
45.2k
        case NOISE_HCB:
1394
45.2k
          sum_nrg_fwd += ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1395
45.2k
          sum_nrg_bwd += ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1396
45.2k
          break;
1397
1398
8.53k
        default:
1399
8.53k
          sum_scf_fwd += ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1400
8.53k
          sum_scf_bwd += ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1401
8.53k
          break;
1402
114k
      }
1403
114k
    }
1404
4.70k
  }
1405
1406
4.70k
  if (sum_fwd < sum_bwd) use_fwd = 1;
1407
1408
4.70k
  if (sum_nrg_fwd < sum_nrg_bwd) use_nrg_fwd = 1;
1409
1410
4.70k
  if (sum_scf_fwd < sum_scf_bwd) use_scf_fwd = 1;
1411
1412
9.41k
  for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
1413
118k
    for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
1414
114k
      bnds = 16 * group + band;
1415
114k
      switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
1416
15.5k
        case ZERO_HCB:
1417
15.5k
          break;
1418
1419
42.2k
        case INTENSITY_HCB:
1420
44.8k
        case INTENSITY_HCB2:
1421
44.8k
          if (use_fwd)
1422
19.1k
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1423
19.1k
                ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1424
25.7k
          else
1425
25.7k
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1426
25.7k
                ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1427
44.8k
          break;
1428
1429
45.2k
        case NOISE_HCB:
1430
45.2k
          if (use_nrg_fwd)
1431
11.8k
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1432
11.8k
                ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1433
33.4k
          else
1434
33.4k
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1435
33.4k
                ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1436
45.2k
          break;
1437
1438
8.53k
        default:
1439
8.53k
          if (use_scf_fwd)
1440
762
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1441
762
                ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1442
7.77k
          else
1443
7.77k
            ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1444
7.77k
                ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
1445
8.53k
          break;
1446
114k
      }
1447
114k
    }
1448
4.70k
  }
1449
4.70k
}
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
47.0k
    ia_aac_dec_overlap_info *ptr_aac_dec_static_channel_info) {
1523
47.0k
  ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
1524
47.0k
  UWORD8 err_status_complete = 0;
1525
47.0k
  UWORD8 err_status_length_fwd = 0;
1526
47.0k
  UWORD8 err_status_length_bwd = 0;
1527
47.0k
  UWORD8 err_status_length_escape = 0;
1528
47.0k
  UWORD8 err_status_first_scf = 0;
1529
47.0k
  UWORD8 err_status_last_scf = 0;
1530
47.0k
  UWORD8 err_status_first_nrg = 0;
1531
47.0k
  UWORD8 err_status_last_nrg = 0;
1532
47.0k
  UWORD8 err_status_first_is = 0;
1533
47.0k
  UWORD8 err_status_last_is = 0;
1534
47.0k
  UWORD8 err_status_forbidden_cw_fwd = 0;
1535
47.0k
  UWORD8 err_status_forbidden_cw_bwd = 0;
1536
47.0k
  UWORD8 err_status_num_escapes_fwd = 0;
1537
47.0k
  UWORD8 err_status_num_escapes_bwd = 0;
1538
47.0k
  UWORD8 conceal_status = 1;
1539
47.0k
  UWORD8 current_block_type;
1540
1541
47.0k
  ptr_aac_dec_channel_info->rvlc_curr_sf_flag = 1;
1542
1543
47.0k
  if (ptr_rvlc->rvlc_err_log & RVLC_ERROR_FORBIDDEN_CW_DETECTED_FWD)
1544
0
    err_status_forbidden_cw_fwd = 1;
1545
1546
47.0k
  if (ptr_rvlc->rvlc_err_log & RVLC_ERROR_FORBIDDEN_CW_DETECTED_BWD)
1547
0
    err_status_forbidden_cw_bwd = 1;
1548
1549
47.0k
  if (ptr_rvlc->rvlc_sf_fwd_len) err_status_length_fwd = 1;
1550
1551
47.0k
  if (ptr_rvlc->rvlc_sf_bwd_len) err_status_length_bwd = 1;
1552
1553
47.0k
  if (ptr_rvlc->sf_esc_present)
1554
23.0k
    if (ptr_rvlc->rvlc_esc_len) err_status_length_escape = 1;
1555
1556
47.0k
  if (ptr_rvlc->sf_used) {
1557
17.1k
    if (ptr_rvlc->firt_scale_fac != (ptr_aac_dec_channel_info->global_gain))
1558
16.9k
      err_status_first_scf = 1;
1559
1560
17.1k
    if (ptr_rvlc->last_scale_fac != (ptr_rvlc->rev_global_gain))
1561
16.8k
      err_status_last_scf = 1;
1562
17.1k
  }
1563
1564
47.0k
  if (ptr_rvlc->noise_used) {
1565
17.3k
    if (ptr_rvlc->first_nrg != (ptr_aac_dec_channel_info->global_gain +
1566
17.3k
                                ptr_rvlc->dpcm_noise_nrg - 90 - 256))
1567
11.1k
      err_status_first_nrg = 1;
1568
1569
17.3k
    if (ptr_rvlc->last_nrg !=
1570
17.3k
        (ptr_rvlc->rev_global_gain + ptr_rvlc->dpcm_noise_last_pos - 90 - 256))
1571
16.8k
      err_status_last_nrg = 1;
1572
17.3k
  }
1573
1574
47.0k
  if (ptr_rvlc->intensity_used) {
1575
15.8k
    if (ptr_rvlc->is_first != 0) err_status_first_is = 1;
1576
1577
15.8k
    if (ptr_rvlc->is_last != (ptr_rvlc->dpcm_is_last_pos))
1578
10.7k
      err_status_last_is = 1;
1579
15.8k
  }
1580
1581
47.0k
  if ((ptr_rvlc->num_fwd_esc_words_decoded !=
1582
47.0k
       ptr_rvlc->num_esc_words_decoded) &&
1583
21.3k
      (ptr_rvlc->conceal_max == CONCEAL_MAX_INIT)) {
1584
16.2k
    err_status_num_escapes_fwd = 1;
1585
16.2k
  }
1586
1587
47.0k
  if ((ptr_rvlc->num_bwd_esc_words_decoded !=
1588
47.0k
       ptr_rvlc->num_esc_words_decoded) &&
1589
20.7k
      (ptr_rvlc->conceal_min == CONCEAL_MIN_INIT)) {
1590
18.0k
    err_status_num_escapes_bwd = 1;
1591
18.0k
  }
1592
1593
47.0k
  if (err_status_length_escape ||
1594
35.6k
      (((ptr_rvlc->conceal_max == CONCEAL_MAX_INIT) &&
1595
27.5k
        (ptr_rvlc->num_fwd_esc_words_decoded !=
1596
27.5k
         ptr_rvlc->num_esc_words_decoded) &&
1597
9.15k
        (err_status_last_scf || err_status_last_nrg || err_status_last_is))
1598
1599
7.04k
       &&
1600
1601
7.04k
       ((ptr_rvlc->conceal_min == CONCEAL_MIN_INIT) &&
1602
5.47k
        (ptr_rvlc->num_bwd_esc_words_decoded !=
1603
5.47k
         ptr_rvlc->num_esc_words_decoded) &&
1604
4.87k
        (err_status_first_scf || err_status_first_nrg ||
1605
524
         err_status_first_is))) ||
1606
30.9k
      ((ptr_rvlc->conceal_max == CONCEAL_MAX_INIT) &&
1607
22.9k
       ((ptr_rvlc->rev_global_gain - ptr_rvlc->last_scale_fac) < -15)) ||
1608
29.5k
      ((ptr_rvlc->conceal_min == CONCEAL_MIN_INIT) &&
1609
26.3k
       ((ptr_aac_dec_channel_info->global_gain - ptr_rvlc->firt_scale_fac) <
1610
26.3k
        -15))) {
1611
21.2k
    if ((ptr_rvlc->conceal_max == CONCEAL_MAX_INIT) ||
1612
20.8k
        (ptr_rvlc->conceal_min == CONCEAL_MIN_INIT)) {
1613
20.8k
      ptr_rvlc->conceal_max = 0;
1614
20.8k
      ptr_rvlc->conceal_min =
1615
20.8k
          ixheaac_max32(0, (ptr_rvlc->num_wind_grps - 1) * 16 +
1616
20.8k
                                ptr_rvlc->max_sfb_transmitted - 1);
1617
20.8k
    } else {
1618
449
      ptr_rvlc->conceal_max =
1619
449
          ixheaac_min32(ptr_rvlc->conceal_max, ptr_rvlc->conceal_max_esc);
1620
449
      ptr_rvlc->conceal_min =
1621
449
          ixheaac_max32(ptr_rvlc->conceal_min, ptr_rvlc->conceal_min_esc);
1622
449
    }
1623
21.2k
  }
1624
1625
47.0k
  err_status_complete =
1626
47.0k
      err_status_last_scf || err_status_first_scf || err_status_last_nrg ||
1627
21.0k
      err_status_first_nrg || err_status_last_is || err_status_first_is ||
1628
16.1k
      err_status_forbidden_cw_fwd || err_status_forbidden_cw_bwd ||
1629
16.1k
      err_status_length_fwd || err_status_length_bwd ||
1630
5.09k
      err_status_length_escape || err_status_num_escapes_fwd ||
1631
5.02k
      err_status_num_escapes_bwd;
1632
1633
47.0k
  current_block_type =
1634
47.0k
      (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
1635
47.0k
       EIGHT_SHORT_SEQUENCE)
1636
47.0k
          ? 0
1637
47.0k
          : 1;
1638
1639
47.0k
  if (!err_status_complete) {
1640
5.02k
    WORD32 band;
1641
5.02k
    WORD32 group;
1642
5.02k
    WORD32 bnds;
1643
5.02k
    WORD32 last_sfb_idx;
1644
1645
5.02k
    last_sfb_idx = (ptr_rvlc->num_wind_grps > 1) ? 16 : 64;
1646
1647
10.6k
    for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
1648
15.1k
      for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
1649
9.53k
        bnds = 16 * group + band;
1650
9.53k
        ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
1651
9.53k
            ptr_aac_dec_static_channel_info->rvlc_prev_sf[bnds] =
1652
9.53k
                ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
1653
9.53k
      }
1654
5.66k
    }
1655
1656
10.6k
    for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
1657
15.1k
      for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
1658
9.53k
        bnds = 16 * group + band;
1659
9.53k
        ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] =
1660
9.53k
            ptr_aac_dec_channel_info->ptr_code_book[bnds];
1661
9.53k
      }
1662
322k
      for (; band < last_sfb_idx; band++) {
1663
316k
        bnds = 16 * group + band;
1664
316k
        ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] = ZERO_HCB;
1665
316k
      }
1666
5.66k
    }
1667
42.0k
  } else {
1668
42.0k
    WORD32 band;
1669
42.0k
    WORD32 group;
1670
1671
42.0k
    if (((ptr_rvlc->conceal_min != CONCEAL_MIN_INIT) ||
1672
17.5k
         (ptr_rvlc->conceal_max != CONCEAL_MAX_INIT)) &&
1673
30.3k
        (ptr_rvlc->conceal_min <= ptr_rvlc->conceal_max) &&
1674
11.3k
        (ptr_aac_dec_static_channel_info->rvlc_prev_blk_type ==
1675
11.3k
         current_block_type) &&
1676
76
        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
42.0k
    if ((ptr_rvlc->conceal_min <= ptr_rvlc->conceal_max) &&
1684
23.0k
        ((ptr_rvlc->conceal_min != CONCEAL_MIN_INIT) ||
1685
17.5k
         (ptr_rvlc->conceal_max != CONCEAL_MAX_INIT)) &&
1686
11.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
11.3k
        conceal_status) {
1691
11.3k
      ixheaacd_bi_dir_est_lower_scf_cur_frame(ptr_aac_dec_channel_info);
1692
11.3k
      conceal_status = 0;
1693
11.3k
    }
1694
1695
42.0k
    if ((ptr_rvlc->conceal_min <= ptr_rvlc->conceal_max) &&
1696
23.0k
        ((err_status_last_scf && err_status_first_scf) ||
1697
17.8k
         (err_status_last_nrg && err_status_first_nrg) ||
1698
14.7k
         (err_status_last_is && err_status_first_is)) &&
1699
10.8k
        !(err_status_forbidden_cw_fwd || err_status_forbidden_cw_bwd ||
1700
10.8k
          err_status_length_escape) &&
1701
10.7k
        conceal_status) {
1702
4.70k
      ixheaacd_statistical_estimation(ptr_aac_dec_channel_info);
1703
4.70k
      conceal_status = 0;
1704
4.70k
    }
1705
1706
42.0k
    if ((ptr_rvlc->conceal_min <= ptr_rvlc->conceal_max) &&
1707
23.0k
        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
42.0k
    if (conceal_status) {
1718
62.5k
      for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
1719
401k
        for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
1720
364k
          ptr_aac_dec_channel_info->ptr_scale_factor[16 * group + band] = 0;
1721
364k
        }
1722
36.6k
      }
1723
25.9k
      ptr_aac_dec_channel_info->rvlc_curr_sf_flag = 0;
1724
25.9k
    }
1725
42.0k
  }
1726
47.0k
}
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
47.0k
    ia_bit_buf_struct *it_bit_buff) {
1732
47.0k
  ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
1733
47.0k
  ia_bit_buf_struct saved_it_bit_buff;
1734
47.0k
  IA_ERRORCODE error_code = 0;
1735
47.0k
  error_code =
1736
47.0k
      ixheaacd_rvlc_init(ptr_rvlc, ptr_aac_dec_channel_info, it_bit_buff);
1737
47.0k
  if (error_code) return error_code;
1738
1739
47.0k
  ixheaacd_bitbuf_checkpoint(*it_bit_buff, saved_it_bit_buff);
1740
47.0k
  if (ptr_rvlc->sf_esc_present)
1741
23.0k
    ixheaacd_rvlc_decode_escape(
1742
23.0k
        ptr_rvlc, ptr_aac_dec_channel_info->rvlc_scf_esc_arr, it_bit_buff);
1743
1744
47.0k
  ixheaacd_rvlc_decode_forward(ptr_rvlc, ptr_aac_dec_channel_info, it_bit_buff);
1745
47.0k
  ixheaacd_rvlc_decode_backward(ptr_rvlc, ptr_aac_dec_channel_info,
1746
47.0k
                                it_bit_buff);
1747
47.0k
  ixheaacd_rvlc_final_error_detection(ptr_aac_dec_channel_info,
1748
47.0k
                                      ptr_aac_dec_static_channel_info);
1749
1750
47.0k
  ptr_aac_dec_channel_info->rvlc_intensity_used = ptr_rvlc->intensity_used;
1751
47.0k
  ptr_aac_dec_channel_info->str_pns_info.pns_active = ptr_rvlc->noise_used;
1752
1753
47.0k
  ixheaacd_bitbuf_restore(*it_bit_buff, saved_it_bit_buff);
1754
47.0k
  return error_code;
1755
47.0k
}