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