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