Home | History | Annotate | Download | only in decoder
      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 
    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 
    107 static int ixheaacd_rvlc_decode(short cw, int len, int *found) {
    108   short 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 
    205 static int ixheaacd_rvlc_decode_esc(int cw, int len, int *found) {
    206   short 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 }
    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 
    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 
    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 
    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 
    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 
    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 
    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 
    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, ixheaacd_drc_offset;
    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       if ((band == 0) && (ptr_rvlc->num_wind_grps != 1))
    756         ixheaacd_drc_offset = 16 - ptr_rvlc->max_sfb_transmitted + 1;
    757       else
    758         ixheaacd_drc_offset = 1;
    759 
    760       switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
    761         case ZERO_HCB:
    762           ptr_scf_bwd[bnds] = 0;
    763           break;
    764 
    765         case INTENSITY_HCB2:
    766         case INTENSITY_HCB:
    767 
    768           dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
    769           if (dpcm < 0) {
    770             ptr_scf_bwd[bnds] = position;
    771 
    772             return;
    773           }
    774           dpcm -= 7;
    775           if ((dpcm == -7) || (dpcm == 7)) {
    776             if (ptr_rvlc->rvlc_esc_len) {
    777               ptr_scf_bwd[bnds] = position;
    778 
    779               return;
    780             } else {
    781               if (dpcm == -7) {
    782                 dpcm -= *ptr_scf_esc--;
    783               } else {
    784                 dpcm += *ptr_scf_esc--;
    785               }
    786               (*ptr_esc_bwd_cnt)++;
    787               if (ptr_rvlc->conceal_min_esc == -1311) {
    788               }
    789             }
    790           }
    791           ptr_scf_bwd[bnds] = position;
    792           position -= dpcm;
    793           ptr_rvlc->is_first = position;
    794           break;
    795 
    796         case NOISE_HCB:
    797           if (bnds == ptr_rvlc->first_noise_band) {
    798             ptr_scf_bwd[bnds] = ptr_rvlc->dpcm_noise_nrg +
    799                                 ptr_aac_dec_channel_info->global_gain - 90 -
    800                                 256;
    801             ptr_rvlc->first_nrg = ptr_scf_bwd[bnds];
    802           } else {
    803             dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
    804             if (dpcm < 0) {
    805               ptr_scf_bwd[bnds] = noise_energy;
    806               return;
    807             }
    808             dpcm -= 7;
    809             if ((dpcm == -7) || (dpcm == 7)) {
    810               if (ptr_rvlc->rvlc_esc_len) {
    811                 ptr_scf_bwd[bnds] = noise_energy;
    812                 return;
    813               } else {
    814                 if (dpcm == -7) {
    815                   dpcm -= *ptr_scf_esc--;
    816                 } else {
    817                   dpcm += *ptr_scf_esc--;
    818                 }
    819                 (*ptr_esc_bwd_cnt)++;
    820                 if (ptr_rvlc->conceal_min_esc == -1311) {
    821                 }
    822               }
    823             }
    824             ptr_scf_bwd[bnds] = noise_energy;
    825             noise_energy -= dpcm;
    826             ptr_rvlc->first_nrg = noise_energy;
    827           }
    828           break;
    829 
    830         default:
    831           dpcm = ixheaacd_decode_rvlc_code_word(it_bit_buff, ptr_rvlc);
    832           if (dpcm < 0) {
    833             ptr_scf_bwd[bnds] = factor;
    834 
    835             return;
    836           }
    837           dpcm -= 7;
    838           if ((dpcm == -7) || (dpcm == 7)) {
    839             if (ptr_rvlc->rvlc_esc_len) {
    840               ptr_scf_bwd[bnds] = factor;
    841 
    842               return;
    843             } else {
    844               if (dpcm == -7) {
    845                 dpcm -= *ptr_scf_esc--;
    846               } else {
    847                 dpcm += *ptr_scf_esc--;
    848               }
    849               (*ptr_esc_bwd_cnt)++;
    850               if (ptr_rvlc->conceal_min_esc == -1311) {
    851               }
    852             }
    853           }
    854           ptr_scf_bwd[bnds] = factor;
    855           factor -= dpcm;
    856           ptr_rvlc->firt_scale_fac = factor;
    857           break;
    858       }
    859     }
    860   }
    861 }
    862 
    863 VOID ixheaacd_rvlc_read(
    864     ia_bit_buf_struct *it_bit_buff,
    865     ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info) {
    866   ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
    867 
    868   WORD32 group, band;
    869 
    870   ptr_rvlc->num_wind_grps =
    871       ptr_aac_dec_channel_info->str_ics_info.num_window_groups;
    872   ptr_rvlc->max_sfb_transmitted =
    873       ptr_aac_dec_channel_info->str_ics_info.max_sfb;
    874   ptr_rvlc->noise_used = 0;
    875   ptr_rvlc->dpcm_noise_nrg = 0;
    876   ptr_rvlc->dpcm_noise_last_pos = 0;
    877   ptr_rvlc->rvlc_esc_len = -1;
    878   ptr_rvlc->dpcm_is_last_pos = 0;
    879 
    880   ptr_rvlc->sf_concealment = ixheaacd_read_bits_buf(it_bit_buff, 1);
    881   ptr_rvlc->rev_global_gain = ixheaacd_read_bits_buf(it_bit_buff, 8);
    882 
    883   if (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
    884       EIGHT_SHORT_SEQUENCE) {
    885     ptr_rvlc->rvlc_sf_len = ixheaacd_read_bits_buf(it_bit_buff, 11);
    886   } else {
    887     ptr_rvlc->rvlc_sf_len = ixheaacd_read_bits_buf(it_bit_buff, 9);
    888   }
    889 
    890   for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
    891     for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
    892       if (ptr_aac_dec_channel_info->ptr_code_book[16 * group + band] ==
    893           NOISE_HCB) {
    894         ptr_rvlc->noise_used = 1;
    895         break;
    896       }
    897     }
    898   }
    899 
    900   if (ptr_rvlc->noise_used)
    901     ptr_rvlc->dpcm_noise_nrg = ixheaacd_read_bits_buf(it_bit_buff, 9);
    902 
    903   ptr_rvlc->sf_esc_present = ixheaacd_read_bits_buf(it_bit_buff, 1);
    904 
    905   if (ptr_rvlc->sf_esc_present) {
    906     ptr_rvlc->rvlc_esc_len = ixheaacd_read_bits_buf(it_bit_buff, 8);
    907   }
    908 
    909   if (ptr_rvlc->noise_used) {
    910     ptr_rvlc->dpcm_noise_last_pos = ixheaacd_read_bits_buf(it_bit_buff, 9);
    911     ptr_rvlc->rvlc_sf_len -= 9;
    912   }
    913 
    914   ptr_rvlc->rvlc_sf_fwd_len = ptr_rvlc->rvlc_sf_len;
    915   ptr_rvlc->rvlc_sf_bwd_len = ptr_rvlc->rvlc_sf_len;
    916 }
    917 
    918 VOID ixheaacd_hcr_read(ia_bit_buf_struct *it_bit_buff,
    919                        ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info,
    920                        WORD32 ele_type) {
    921   WORD16 len_reordered_spec_data;
    922   WORD8 len_longest_code_word;
    923 
    924   ptr_aac_dec_channel_info->reorder_spect_data_len = 0;
    925   ptr_aac_dec_channel_info->longest_cw_len = 0;
    926 
    927   len_reordered_spec_data = ixheaacd_read_bits_buf(it_bit_buff, 14);
    928   if (ele_type == ID_CPE) {
    929     if ((len_reordered_spec_data >= 0) && (len_reordered_spec_data <= 12288)) {
    930       ptr_aac_dec_channel_info->reorder_spect_data_len =
    931           len_reordered_spec_data;
    932     } else {
    933       if (len_reordered_spec_data > 12288) {
    934         ptr_aac_dec_channel_info->reorder_spect_data_len = 12288;
    935       }
    936     }
    937   } else if (ele_type == ID_SCE || ele_type == ID_LFE || ele_type == ID_CCE) {
    938     if ((len_reordered_spec_data >= 0) && (len_reordered_spec_data <= 6144)) {
    939       ptr_aac_dec_channel_info->reorder_spect_data_len =
    940           len_reordered_spec_data;
    941     } else {
    942       if (len_reordered_spec_data > 6144) {
    943         ptr_aac_dec_channel_info->reorder_spect_data_len = 6144;
    944       }
    945     }
    946   }
    947 
    948   len_longest_code_word = ixheaacd_read_bits_buf(it_bit_buff, 6);
    949   if ((len_longest_code_word >= 0) && (len_longest_code_word <= 49)) {
    950     ptr_aac_dec_channel_info->longest_cw_len = len_longest_code_word;
    951   } else {
    952     if (len_longest_code_word > 49) {
    953       ptr_aac_dec_channel_info->longest_cw_len = 49;
    954     }
    955   }
    956 }
    957 
    958 static WORD32 ixheaacd_rvlc_init(
    959     ia_rvlc_info_struct *ptr_rvlc,
    960     ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info,
    961     ia_bit_buf_struct *it_bit_buff) {
    962   WORD16 *ptr_scf_esc = ptr_aac_dec_channel_info->rvlc_scf_esc_arr;
    963   WORD16 *ptr_scf_fwd = ptr_aac_dec_channel_info->rvlc_scf_fwd_arr;
    964   WORD16 *ptr_scf_bwd = ptr_aac_dec_channel_info->rvlc_scf_bwd_arr;
    965   WORD16 *ptr_scale_factor = ptr_aac_dec_channel_info->ptr_scale_factor;
    966   WORD32 bnds;
    967 
    968   ptr_aac_dec_channel_info->rvlc_intensity_used = 0;
    969 
    970   ptr_rvlc->num_esc_words_decoded = 0;
    971   ptr_rvlc->num_fwd_esc_words_decoded = 0;
    972   ptr_rvlc->num_bwd_esc_words_decoded = 0;
    973 
    974   ptr_rvlc->intensity_used = 0;
    975   ptr_rvlc->rvlc_err_log = 0;
    976 
    977   ptr_rvlc->conceal_max = CONCEAL_MAX_INIT;
    978   ptr_rvlc->conceal_min = CONCEAL_MIN_INIT;
    979 
    980   ptr_rvlc->conceal_max_esc = CONCEAL_MAX_INIT;
    981   ptr_rvlc->conceal_min_esc = CONCEAL_MIN_INIT;
    982 
    983   for (bnds = 0; bnds < RVLC_MAX_SFB; bnds++) {
    984     ptr_scf_fwd[bnds] = 0;
    985     ptr_scf_bwd[bnds] = 0;
    986     ptr_scf_esc[bnds] = 0;
    987     ptr_scale_factor[bnds] = 0;
    988   }
    989 
    990   ptr_rvlc->rvl_fwd_bit_str_idx = it_bit_buff->size - it_bit_buff->cnt_bits;
    991   ptr_rvlc->rvl_bwd_bit_str_idx =
    992       it_bit_buff->size - it_bit_buff->cnt_bits + ptr_rvlc->rvlc_sf_len - 1;
    993 
    994   it_bit_buff->cnt_bits -= ptr_rvlc->rvlc_sf_len;
    995   it_bit_buff->ptr_read_next =
    996       it_bit_buff->ptr_bit_buf_base +
    997       ((it_bit_buff->size - it_bit_buff->cnt_bits) >> 3);
    998   it_bit_buff->bit_pos = ((it_bit_buff->size - it_bit_buff->cnt_bits) & 7);
    999 
   1000   if (ptr_rvlc->sf_esc_present != 0) {
   1001     ptr_rvlc->esc_bit_str_idx = it_bit_buff->size - it_bit_buff->cnt_bits;
   1002 
   1003     it_bit_buff->cnt_bits -= ptr_rvlc->rvlc_esc_len;
   1004     it_bit_buff->ptr_read_next =
   1005         it_bit_buff->ptr_bit_buf_base +
   1006         ((it_bit_buff->size - it_bit_buff->cnt_bits) >> 3);
   1007     it_bit_buff->bit_pos = ((it_bit_buff->size - it_bit_buff->cnt_bits) & 7);
   1008   }
   1009   if (it_bit_buff->cnt_bits < 0) {
   1010     return IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES;
   1011   } else
   1012     return 0;
   1013 }
   1014 
   1015 VOID ixheaacd_bi_dir_est_scf_prev_frame_reference(
   1016     ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info,
   1017     ia_aac_dec_overlap_info *ptr_aac_dec_static_channel_info) {
   1018   ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
   1019   WORD32 band, bnds, start_band, end_band, group;
   1020   WORD32 conceal_min, conceal_max;
   1021   WORD32 conceal_group_min, conceal_group_max;
   1022   WORD32 max_scf_bands;
   1023   WORD32 common_min;
   1024 
   1025   if (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
   1026       EIGHT_SHORT_SEQUENCE) {
   1027     max_scf_bands = 16;
   1028   } else {
   1029     max_scf_bands = 64;
   1030   }
   1031 
   1032   if (ptr_rvlc->conceal_min == CONCEAL_MIN_INIT) ptr_rvlc->conceal_min = 0;
   1033 
   1034   if (ptr_rvlc->conceal_max == CONCEAL_MAX_INIT)
   1035     ptr_rvlc->conceal_max =
   1036         (ptr_rvlc->num_wind_grps - 1) * 16 + ptr_rvlc->max_sfb_transmitted - 1;
   1037 
   1038   conceal_min = ptr_rvlc->conceal_min % max_scf_bands;
   1039   conceal_group_min = ptr_rvlc->conceal_min / max_scf_bands;
   1040   conceal_max = ptr_rvlc->conceal_max % max_scf_bands;
   1041   conceal_group_max = ptr_rvlc->conceal_max / max_scf_bands;
   1042 
   1043   ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[ptr_rvlc->conceal_max] =
   1044       ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[ptr_rvlc->conceal_max];
   1045   ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[ptr_rvlc->conceal_min] =
   1046       ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[ptr_rvlc->conceal_min];
   1047 
   1048   start_band = conceal_min;
   1049   if (conceal_group_min == conceal_group_max)
   1050     end_band = conceal_max;
   1051   else
   1052     end_band = ptr_rvlc->max_sfb_transmitted - 1;
   1053 
   1054   for (group = conceal_group_min; group <= conceal_group_max; group++) {
   1055     for (band = start_band; band <= end_band; band++) {
   1056       bnds = 16 * group + band;
   1057       switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
   1058         case ZERO_HCB:
   1059           ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = 0;
   1060           break;
   1061 
   1062         case INTENSITY_HCB:
   1063         case INTENSITY_HCB2:
   1064           if ((ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] ==
   1065                INTENSITY_HCB) ||
   1066               (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] ==
   1067                INTENSITY_HCB2)) {
   1068             common_min = ixheaacd_min32(
   1069                 ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds],
   1070                 ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds]);
   1071             ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ixheaacd_min32(
   1072                 common_min,
   1073                 ptr_aac_dec_static_channel_info->rvlc_prev_sf[bnds]);
   1074           } else {
   1075             ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = 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           }
   1079           break;
   1080 
   1081         case NOISE_HCB:
   1082           if (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] ==
   1083               NOISE_HCB) {
   1084             common_min = ixheaacd_min32(
   1085                 ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds],
   1086                 ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds]);
   1087             ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ixheaacd_min32(
   1088                 common_min,
   1089                 ptr_aac_dec_static_channel_info->rvlc_prev_sf[bnds]);
   1090           } else {
   1091             ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ixheaacd_min32(
   1092                 ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds],
   1093                 ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds]);
   1094           }
   1095           break;
   1096 
   1097         default:
   1098           if ((ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] !=
   1099                ZERO_HCB) &&
   1100               (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] !=
   1101                NOISE_HCB) &&
   1102               (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] !=
   1103                INTENSITY_HCB) &&
   1104               (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] !=
   1105                INTENSITY_HCB2)) {
   1106             common_min = ixheaacd_min32(
   1107                 ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds],
   1108                 ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds]);
   1109             ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ixheaacd_min32(
   1110                 common_min,
   1111                 ptr_aac_dec_static_channel_info->rvlc_prev_sf[bnds]);
   1112           } else {
   1113             ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ixheaacd_min32(
   1114                 ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds],
   1115                 ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds]);
   1116           }
   1117           break;
   1118       }
   1119     }
   1120     start_band = 0;
   1121     if ((group + 1) == conceal_group_max) end_band = conceal_max;
   1122   }
   1123 
   1124   if (conceal_group_min == 0)
   1125     end_band = conceal_min;
   1126   else
   1127     end_band = ptr_rvlc->max_sfb_transmitted;
   1128   for (group = 0; group <= conceal_group_min; group++) {
   1129     for (band = 0; band < end_band; band++) {
   1130       bnds = 16 * group + band;
   1131       ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
   1132           ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
   1133     }
   1134     if ((group + 1) == conceal_group_min) end_band = conceal_min;
   1135   }
   1136 
   1137   start_band = conceal_max + 1;
   1138   for (group = conceal_group_max; group < ptr_rvlc->num_wind_grps; group++) {
   1139     for (band = start_band; band < ptr_rvlc->max_sfb_transmitted; band++) {
   1140       bnds = 16 * group + band;
   1141       ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
   1142           ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
   1143     }
   1144     start_band = 0;
   1145   }
   1146 }
   1147 
   1148 static VOID ixheaacd_calc_ref_val_fwd(
   1149     ia_rvlc_info_struct *ptr_rvlc,
   1150     ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, WORD32 *ref_fwd,
   1151     WORD32 *ref_nrg_fwd, WORD32 *ref_scf_fwd) {
   1152   WORD32 band, bnds, group, start_band;
   1153   WORD32 id_is, id_nrg, id_scf;
   1154   WORD32 conceal_min, conceal_group_min;
   1155   WORD32 max_scf_bands;
   1156 
   1157   if (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
   1158       EIGHT_SHORT_SEQUENCE)
   1159     max_scf_bands = 16;
   1160   else
   1161     max_scf_bands = 64;
   1162 
   1163   conceal_min = ptr_rvlc->conceal_min % max_scf_bands;
   1164   conceal_group_min = ptr_rvlc->conceal_min / max_scf_bands;
   1165 
   1166   id_is = id_nrg = id_scf = 1;
   1167 
   1168   *ref_nrg_fwd = ptr_aac_dec_channel_info->global_gain - 90 - 256;
   1169   *ref_scf_fwd = ptr_aac_dec_channel_info->global_gain;
   1170 
   1171   start_band = conceal_min - 1;
   1172   for (group = conceal_group_min; group >= 0; group--) {
   1173     for (band = start_band; band >= 0; band--) {
   1174       bnds = 16 * group + band;
   1175       switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
   1176         case ZERO_HCB:
   1177           break;
   1178         case INTENSITY_HCB:
   1179         case INTENSITY_HCB2:
   1180           if (id_is) {
   1181             *ref_fwd = ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
   1182             id_is = 0;
   1183           }
   1184           break;
   1185         case NOISE_HCB:
   1186           if (id_nrg) {
   1187             *ref_nrg_fwd = ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
   1188             id_nrg = 0;
   1189           }
   1190           break;
   1191         default:
   1192           if (id_scf) {
   1193             *ref_scf_fwd = ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
   1194             id_scf = 0;
   1195           }
   1196           break;
   1197       }
   1198     }
   1199     start_band = ptr_rvlc->max_sfb_transmitted - 1;
   1200   }
   1201 }
   1202 
   1203 static VOID ixheaacd_calc_ref_val_bwd(
   1204     ia_rvlc_info_struct *ptr_rvlc,
   1205     ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, WORD32 *ref_bwd,
   1206     WORD32 *ref_nrg_bwd, WORD32 *ref_scf_bwd) {
   1207   WORD32 band, bnds, group, start_band;
   1208   WORD32 id_is, id_nrg, id_scf;
   1209   WORD32 conceal_max, conceal_group_max;
   1210   WORD32 max_scf_bands;
   1211 
   1212   if (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
   1213       EIGHT_SHORT_SEQUENCE)
   1214     max_scf_bands = 16;
   1215   else
   1216     max_scf_bands = 64;
   1217 
   1218   conceal_max = ptr_rvlc->conceal_max % max_scf_bands;
   1219   conceal_group_max = ptr_rvlc->conceal_max / max_scf_bands;
   1220 
   1221   id_is = id_nrg = id_scf = 1;
   1222 
   1223   *ref_bwd = ptr_rvlc->dpcm_is_last_pos;
   1224   *ref_nrg_bwd = ptr_rvlc->rev_global_gain + ptr_rvlc->dpcm_noise_last_pos -
   1225                  90 - 256 + ptr_rvlc->dpcm_noise_nrg;
   1226   *ref_scf_bwd = ptr_rvlc->rev_global_gain;
   1227 
   1228   start_band = conceal_max + 1;
   1229 
   1230   for (group = conceal_group_max; group < ptr_rvlc->num_wind_grps; group++) {
   1231     for (band = start_band; band < ptr_rvlc->max_sfb_transmitted; band++) {
   1232       bnds = 16 * group + band;
   1233       switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
   1234         case ZERO_HCB:
   1235           break;
   1236         case INTENSITY_HCB:
   1237         case INTENSITY_HCB2:
   1238           if (id_is) {
   1239             *ref_bwd = ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
   1240             id_is = 0;
   1241           }
   1242           break;
   1243         case NOISE_HCB:
   1244           if (id_nrg) {
   1245             *ref_nrg_bwd = ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
   1246             id_nrg = 0;
   1247           }
   1248           break;
   1249         default:
   1250           if (id_scf) {
   1251             *ref_scf_bwd = ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
   1252             id_scf = 0;
   1253           }
   1254           break;
   1255       }
   1256     }
   1257     start_band = 0;
   1258   }
   1259 }
   1260 
   1261 VOID ixheaacd_bi_dir_est_lower_scf_cur_frame(
   1262     ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info) {
   1263   ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
   1264   WORD32 band, bnds, start_band, end_band, group;
   1265   WORD32 conceal_min, conceal_max;
   1266   WORD32 conceal_group_min, conceal_group_max;
   1267   WORD32 max_scf_bands;
   1268 
   1269   if (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
   1270       EIGHT_SHORT_SEQUENCE) {
   1271     max_scf_bands = 16;
   1272   } else {
   1273     max_scf_bands = 64;
   1274   }
   1275 
   1276   if (ptr_rvlc->conceal_min == CONCEAL_MIN_INIT) ptr_rvlc->conceal_min = 0;
   1277 
   1278   if (ptr_rvlc->conceal_max == CONCEAL_MAX_INIT)
   1279     ptr_rvlc->conceal_max =
   1280         (ptr_rvlc->num_wind_grps - 1) * 16 + ptr_rvlc->max_sfb_transmitted - 1;
   1281 
   1282   conceal_min = ptr_rvlc->conceal_min % max_scf_bands;
   1283   conceal_group_min = ptr_rvlc->conceal_min / max_scf_bands;
   1284   conceal_max = ptr_rvlc->conceal_max % max_scf_bands;
   1285   conceal_group_max = ptr_rvlc->conceal_max / max_scf_bands;
   1286 
   1287   if (ptr_rvlc->conceal_min == ptr_rvlc->conceal_max) {
   1288     WORD32 ref_fwd = 0, ref_nrg_fwd = 0, ref_scf_fwd = 0;
   1289     WORD32 ref_bwd = 0, ref_nrg_bwd = 0, ref_scf_bwd = 0;
   1290 
   1291     bnds = ptr_rvlc->conceal_min;
   1292     ixheaacd_calc_ref_val_fwd(ptr_rvlc, ptr_aac_dec_channel_info, &ref_fwd,
   1293                               &ref_nrg_fwd, &ref_scf_fwd);
   1294     ixheaacd_calc_ref_val_bwd(ptr_rvlc, ptr_aac_dec_channel_info, &ref_bwd,
   1295                               &ref_nrg_bwd, &ref_scf_bwd);
   1296 
   1297     switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
   1298       case ZERO_HCB:
   1299         break;
   1300       case INTENSITY_HCB:
   1301       case INTENSITY_HCB2:
   1302         if (ref_fwd < ref_bwd)
   1303           ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_fwd;
   1304         else
   1305           ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_bwd;
   1306         break;
   1307       case NOISE_HCB:
   1308         if (ref_nrg_fwd < ref_nrg_bwd)
   1309           ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_nrg_fwd;
   1310         else
   1311           ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_nrg_bwd;
   1312         break;
   1313       default:
   1314         if (ref_scf_fwd < ref_scf_bwd)
   1315           ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_scf_fwd;
   1316         else
   1317           ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ref_scf_bwd;
   1318         break;
   1319     }
   1320   } else {
   1321     ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[ptr_rvlc->conceal_max] =
   1322         ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[ptr_rvlc->conceal_max];
   1323     ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[ptr_rvlc->conceal_min] =
   1324         ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[ptr_rvlc->conceal_min];
   1325 
   1326     start_band = conceal_min;
   1327     if (conceal_group_min == conceal_group_max)
   1328       end_band = conceal_max;
   1329     else
   1330       end_band = ptr_rvlc->max_sfb_transmitted - 1;
   1331 
   1332     for (group = conceal_group_min; group <= conceal_group_max; group++) {
   1333       for (band = start_band; band <= end_band; band++) {
   1334         bnds = 16 * group + band;
   1335         if (ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds] <
   1336             ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds])
   1337           ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
   1338               ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
   1339         else
   1340           ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
   1341               ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
   1342       }
   1343       start_band = 0;
   1344       if ((group + 1) == conceal_group_max) end_band = conceal_max;
   1345     }
   1346   }
   1347 
   1348   if (conceal_group_min == 0)
   1349     end_band = conceal_min;
   1350   else
   1351     end_band = ptr_rvlc->max_sfb_transmitted;
   1352   for (group = 0; group <= conceal_group_min; group++) {
   1353     for (band = 0; band < end_band; band++) {
   1354       bnds = 16 * group + band;
   1355       ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
   1356           ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
   1357     }
   1358     if ((group + 1) == conceal_group_min) end_band = conceal_min;
   1359   }
   1360 
   1361   start_band = conceal_max + 1;
   1362   for (group = conceal_group_max; group < ptr_rvlc->num_wind_grps; group++) {
   1363     for (band = start_band; band < ptr_rvlc->max_sfb_transmitted; band++) {
   1364       bnds = 16 * group + band;
   1365       ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
   1366           ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
   1367     }
   1368     start_band = 0;
   1369   }
   1370 }
   1371 
   1372 VOID ixheaacd_statistical_estimation(
   1373     ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info) {
   1374   ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
   1375   WORD32 band, bnds, group;
   1376   WORD32 sum_fwd, sum_bwd;
   1377   WORD32 sum_nrg_fwd, sum_nrg_bwd;
   1378   WORD32 sum_scf_fwd, sum_scf_bwd;
   1379   WORD32 use_fwd, use_nrg_fwd, use_scf_fwd;
   1380   WORD32 max_scf_bands;
   1381 
   1382   if (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
   1383       EIGHT_SHORT_SEQUENCE)
   1384     max_scf_bands = 16;
   1385   else
   1386     max_scf_bands = 64;
   1387 
   1388   sum_fwd = sum_bwd = sum_nrg_fwd = sum_nrg_bwd = sum_scf_fwd = sum_scf_bwd = 0;
   1389   use_fwd = use_nrg_fwd = use_scf_fwd = 0;
   1390 
   1391   for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
   1392     for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
   1393       bnds = 16 * group + band;
   1394       switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
   1395         case ZERO_HCB:
   1396           break;
   1397 
   1398         case INTENSITY_HCB:
   1399         case INTENSITY_HCB2:
   1400           sum_fwd += ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
   1401           sum_bwd += ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
   1402           break;
   1403 
   1404         case NOISE_HCB:
   1405           sum_nrg_fwd += ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
   1406           sum_nrg_bwd += ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
   1407           break;
   1408 
   1409         default:
   1410           sum_scf_fwd += ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
   1411           sum_scf_bwd += ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
   1412           break;
   1413       }
   1414     }
   1415   }
   1416 
   1417   if (sum_fwd < sum_bwd) use_fwd = 1;
   1418 
   1419   if (sum_nrg_fwd < sum_nrg_bwd) use_nrg_fwd = 1;
   1420 
   1421   if (sum_scf_fwd < sum_scf_bwd) use_scf_fwd = 1;
   1422 
   1423   for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
   1424     for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
   1425       bnds = 16 * group + band;
   1426       switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
   1427         case ZERO_HCB:
   1428           break;
   1429 
   1430         case INTENSITY_HCB:
   1431         case INTENSITY_HCB2:
   1432           if (use_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         case NOISE_HCB:
   1441           if (use_nrg_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         default:
   1450           if (use_scf_fwd)
   1451             ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
   1452                 ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
   1453           else
   1454             ptr_aac_dec_channel_info->ptr_scale_factor[bnds] =
   1455                 ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds];
   1456           break;
   1457       }
   1458     }
   1459   }
   1460 }
   1461 
   1462 VOID ixheaacd_predictive_interpolation(
   1463     ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info,
   1464     ia_aac_dec_overlap_info *ptr_aac_dec_static_channel_info) {
   1465   ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
   1466   WORD32 band, bnds, group;
   1467   WORD32 max_scf_bands;
   1468   WORD32 common_min;
   1469 
   1470   if (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
   1471       EIGHT_SHORT_SEQUENCE)
   1472     max_scf_bands = 16;
   1473   else
   1474     max_scf_bands = 64;
   1475 
   1476   for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
   1477     for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
   1478       bnds = 16 * group + band;
   1479       switch (ptr_aac_dec_channel_info->ptr_code_book[bnds]) {
   1480         case ZERO_HCB:
   1481           ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = 0;
   1482           break;
   1483 
   1484         case INTENSITY_HCB:
   1485         case INTENSITY_HCB2:
   1486           if ((ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] ==
   1487                INTENSITY_HCB) ||
   1488               (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] ==
   1489                INTENSITY_HCB2)) {
   1490             common_min = ixheaacd_min32(
   1491                 ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds],
   1492                 ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds]);
   1493             ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ixheaacd_min32(
   1494                 common_min,
   1495                 ptr_aac_dec_static_channel_info->rvlc_prev_sf[bnds]);
   1496           } else {
   1497             ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = -110;
   1498           }
   1499           break;
   1500 
   1501         case NOISE_HCB:
   1502           if (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] ==
   1503               NOISE_HCB) {
   1504             common_min = ixheaacd_min32(
   1505                 ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds],
   1506                 ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds]);
   1507             ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ixheaacd_min32(
   1508                 common_min,
   1509                 ptr_aac_dec_static_channel_info->rvlc_prev_sf[bnds]);
   1510           } else {
   1511             ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = -110;
   1512           }
   1513           break;
   1514 
   1515         default:
   1516           if ((ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] !=
   1517                ZERO_HCB) &&
   1518               (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] !=
   1519                NOISE_HCB) &&
   1520               (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] !=
   1521                INTENSITY_HCB) &&
   1522               (ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] !=
   1523                INTENSITY_HCB2)) {
   1524             common_min = ixheaacd_min32(
   1525                 ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds],
   1526                 ptr_aac_dec_channel_info->rvlc_scf_bwd_arr[bnds]);
   1527             ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = ixheaacd_min32(
   1528                 common_min,
   1529                 ptr_aac_dec_static_channel_info->rvlc_prev_sf[bnds]);
   1530           } else {
   1531             ptr_aac_dec_channel_info->ptr_scale_factor[bnds] = 0;
   1532           }
   1533           break;
   1534       }
   1535     }
   1536   }
   1537 }
   1538 static VOID ixheaacd_rvlc_final_error_detection(
   1539     ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info,
   1540     ia_aac_dec_overlap_info *ptr_aac_dec_static_channel_info) {
   1541   ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
   1542   UWORD8 err_status_complete = 0;
   1543   UWORD8 err_status_length_fwd = 0;
   1544   UWORD8 err_status_length_bwd = 0;
   1545   UWORD8 err_status_length_escape = 0;
   1546   UWORD8 err_status_first_scf = 0;
   1547   UWORD8 err_status_last_scf = 0;
   1548   UWORD8 err_status_first_nrg = 0;
   1549   UWORD8 err_status_last_nrg = 0;
   1550   UWORD8 err_status_first_is = 0;
   1551   UWORD8 err_status_last_is = 0;
   1552   UWORD8 err_status_forbidden_cw_fwd = 0;
   1553   UWORD8 err_status_forbidden_cw_bwd = 0;
   1554   UWORD8 err_status_num_escapes_fwd = 0;
   1555   UWORD8 err_status_num_escapes_bwd = 0;
   1556   UWORD8 conceal_status = 1;
   1557   UWORD8 current_block_type;
   1558 
   1559   ptr_aac_dec_channel_info->rvlc_curr_sf_flag = 1;
   1560 
   1561   if (ptr_rvlc->rvlc_err_log & RVLC_ERROR_FORBIDDEN_CW_DETECTED_FWD)
   1562     err_status_forbidden_cw_fwd = 1;
   1563 
   1564   if (ptr_rvlc->rvlc_err_log & RVLC_ERROR_FORBIDDEN_CW_DETECTED_BWD)
   1565     err_status_forbidden_cw_bwd = 1;
   1566 
   1567   if (ptr_rvlc->rvlc_sf_fwd_len) err_status_length_fwd = 1;
   1568 
   1569   if (ptr_rvlc->rvlc_sf_bwd_len) err_status_length_bwd = 1;
   1570 
   1571   if (ptr_rvlc->sf_esc_present)
   1572     if (ptr_rvlc->rvlc_esc_len) err_status_length_escape = 1;
   1573 
   1574   if (ptr_rvlc->sf_used) {
   1575     if (ptr_rvlc->firt_scale_fac != (ptr_aac_dec_channel_info->global_gain))
   1576       err_status_first_scf = 1;
   1577 
   1578     if (ptr_rvlc->last_scale_fac != (ptr_rvlc->rev_global_gain))
   1579       err_status_last_scf = 1;
   1580   }
   1581 
   1582   if (ptr_rvlc->noise_used) {
   1583     if (ptr_rvlc->first_nrg != (ptr_aac_dec_channel_info->global_gain +
   1584                                 ptr_rvlc->dpcm_noise_nrg - 90 - 256))
   1585       err_status_first_nrg = 1;
   1586 
   1587     if (ptr_rvlc->last_nrg !=
   1588         (ptr_rvlc->rev_global_gain + ptr_rvlc->dpcm_noise_last_pos - 90 - 256))
   1589       err_status_last_nrg = 1;
   1590   }
   1591 
   1592   if (ptr_rvlc->intensity_used) {
   1593     if (ptr_rvlc->is_first != 0) err_status_first_is = 1;
   1594 
   1595     if (ptr_rvlc->is_last != (ptr_rvlc->dpcm_is_last_pos))
   1596       err_status_last_is = 1;
   1597   }
   1598 
   1599   if ((ptr_rvlc->num_fwd_esc_words_decoded !=
   1600        ptr_rvlc->num_esc_words_decoded) &&
   1601       (ptr_rvlc->conceal_max == CONCEAL_MAX_INIT)) {
   1602     err_status_num_escapes_fwd = 1;
   1603   }
   1604 
   1605   if ((ptr_rvlc->num_bwd_esc_words_decoded !=
   1606        ptr_rvlc->num_esc_words_decoded) &&
   1607       (ptr_rvlc->conceal_min == CONCEAL_MIN_INIT)) {
   1608     err_status_num_escapes_bwd = 1;
   1609   }
   1610 
   1611   if (err_status_length_escape ||
   1612       (((ptr_rvlc->conceal_max == CONCEAL_MAX_INIT) &&
   1613         (ptr_rvlc->num_fwd_esc_words_decoded !=
   1614          ptr_rvlc->num_esc_words_decoded) &&
   1615         (err_status_last_scf || err_status_last_nrg || err_status_last_is))
   1616 
   1617        &&
   1618 
   1619        ((ptr_rvlc->conceal_min == CONCEAL_MIN_INIT) &&
   1620         (ptr_rvlc->num_bwd_esc_words_decoded !=
   1621          ptr_rvlc->num_esc_words_decoded) &&
   1622         (err_status_first_scf || err_status_first_nrg ||
   1623          err_status_first_is))) ||
   1624       ((ptr_rvlc->conceal_max == CONCEAL_MAX_INIT) &&
   1625        ((ptr_rvlc->rev_global_gain - ptr_rvlc->last_scale_fac) < -15)) ||
   1626       ((ptr_rvlc->conceal_min == CONCEAL_MIN_INIT) &&
   1627        ((ptr_aac_dec_channel_info->global_gain - ptr_rvlc->firt_scale_fac) <
   1628         -15))) {
   1629     if ((ptr_rvlc->conceal_max == CONCEAL_MAX_INIT) ||
   1630         (ptr_rvlc->conceal_min == CONCEAL_MIN_INIT)) {
   1631       ptr_rvlc->conceal_max = 0;
   1632       ptr_rvlc->conceal_min =
   1633           ixheaacd_max32(0, (ptr_rvlc->num_wind_grps - 1) * 16 +
   1634                                 ptr_rvlc->max_sfb_transmitted - 1);
   1635     } else {
   1636       ptr_rvlc->conceal_max =
   1637           ixheaacd_min32(ptr_rvlc->conceal_max, ptr_rvlc->conceal_max_esc);
   1638       ptr_rvlc->conceal_min =
   1639           ixheaacd_max32(ptr_rvlc->conceal_min, ptr_rvlc->conceal_min_esc);
   1640     }
   1641   }
   1642 
   1643   err_status_complete =
   1644       err_status_last_scf || err_status_first_scf || err_status_last_nrg ||
   1645       err_status_first_nrg || err_status_last_is || err_status_first_is ||
   1646       err_status_forbidden_cw_fwd || err_status_forbidden_cw_bwd ||
   1647       err_status_length_fwd || err_status_length_bwd ||
   1648       err_status_length_escape || err_status_num_escapes_fwd ||
   1649       err_status_num_escapes_bwd;
   1650 
   1651   current_block_type =
   1652       (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
   1653        EIGHT_SHORT_SEQUENCE)
   1654           ? 0
   1655           : 1;
   1656 
   1657   if (!err_status_complete) {
   1658     WORD32 band;
   1659     WORD32 group;
   1660     WORD32 bnds;
   1661     WORD32 last_sfb_idx;
   1662 
   1663     last_sfb_idx = (ptr_rvlc->num_wind_grps > 1) ? 16 : 64;
   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_channel_info->ptr_scale_factor[bnds] =
   1669             ptr_aac_dec_static_channel_info->rvlc_prev_sf[bnds] =
   1670                 ptr_aac_dec_channel_info->rvlc_scf_fwd_arr[bnds];
   1671       }
   1672     }
   1673 
   1674     for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
   1675       for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
   1676         bnds = 16 * group + band;
   1677         ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] =
   1678             ptr_aac_dec_channel_info->ptr_code_book[bnds];
   1679       }
   1680       for (; band < last_sfb_idx; band++) {
   1681         bnds = 16 * group + band;
   1682         ptr_aac_dec_static_channel_info->rvlc_prev_cb[bnds] = ZERO_HCB;
   1683       }
   1684     }
   1685   } else {
   1686     WORD32 band;
   1687     WORD32 group;
   1688 
   1689     if (((ptr_rvlc->conceal_min != CONCEAL_MIN_INIT) ||
   1690          (ptr_rvlc->conceal_max != CONCEAL_MAX_INIT)) &&
   1691         (ptr_rvlc->conceal_min <= ptr_rvlc->conceal_max) &&
   1692         (ptr_aac_dec_static_channel_info->rvlc_prev_blk_type ==
   1693          current_block_type) &&
   1694         ptr_aac_dec_static_channel_info->rvlc_prev_sf_ok &&
   1695         ptr_rvlc->sf_concealment && conceal_status) {
   1696       ixheaacd_bi_dir_est_scf_prev_frame_reference(
   1697           ptr_aac_dec_channel_info, ptr_aac_dec_static_channel_info);
   1698       conceal_status = 0;
   1699     }
   1700 
   1701     if ((ptr_rvlc->conceal_min <= ptr_rvlc->conceal_max) &&
   1702         ((ptr_rvlc->conceal_min != CONCEAL_MIN_INIT) ||
   1703          (ptr_rvlc->conceal_max != CONCEAL_MAX_INIT)) &&
   1704         !(ptr_aac_dec_static_channel_info->rvlc_prev_sf_ok &&
   1705           ptr_rvlc->sf_concealment &&
   1706           (ptr_aac_dec_static_channel_info->rvlc_prev_blk_type ==
   1707            current_block_type)) &&
   1708         conceal_status) {
   1709       ixheaacd_bi_dir_est_lower_scf_cur_frame(ptr_aac_dec_channel_info);
   1710       conceal_status = 0;
   1711     }
   1712 
   1713     if ((ptr_rvlc->conceal_min <= ptr_rvlc->conceal_max) &&
   1714         ((err_status_last_scf && err_status_first_scf) ||
   1715          (err_status_last_nrg && err_status_first_nrg) ||
   1716          (err_status_last_is && err_status_first_is)) &&
   1717         !(err_status_forbidden_cw_fwd || err_status_forbidden_cw_bwd ||
   1718           err_status_length_escape) &&
   1719         conceal_status) {
   1720       ixheaacd_statistical_estimation(ptr_aac_dec_channel_info);
   1721       conceal_status = 0;
   1722     }
   1723 
   1724     if ((ptr_rvlc->conceal_min <= ptr_rvlc->conceal_max) &&
   1725         ptr_aac_dec_static_channel_info->rvlc_prev_sf_ok &&
   1726         ptr_rvlc->sf_concealment &&
   1727         (ptr_aac_dec_static_channel_info->rvlc_prev_blk_type ==
   1728          current_block_type) &&
   1729         conceal_status) {
   1730       ixheaacd_predictive_interpolation(ptr_aac_dec_channel_info,
   1731                                         ptr_aac_dec_static_channel_info);
   1732       conceal_status = 0;
   1733     }
   1734 
   1735     if (conceal_status) {
   1736       for (group = 0; group < ptr_rvlc->num_wind_grps; group++) {
   1737         for (band = 0; band < ptr_rvlc->max_sfb_transmitted; band++) {
   1738           ptr_aac_dec_channel_info->ptr_scale_factor[16 * group + band] = 0;
   1739         }
   1740       }
   1741       ptr_aac_dec_channel_info->rvlc_curr_sf_flag = 0;
   1742     }
   1743   }
   1744 }
   1745 
   1746 IA_ERRORCODE ixheaacd_rvlc_dec(
   1747     ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info,
   1748     ia_aac_dec_overlap_info *ptr_aac_dec_static_channel_info,
   1749     ia_bit_buf_struct *it_bit_buff) {
   1750   ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info;
   1751   ia_bit_buf_struct saved_it_bit_buff;
   1752   IA_ERRORCODE error_code = 0;
   1753   error_code =
   1754       ixheaacd_rvlc_init(ptr_rvlc, ptr_aac_dec_channel_info, it_bit_buff);
   1755   if (error_code) return error_code;
   1756 
   1757   ixheaacd_bitbuf_checkpoint(*it_bit_buff, saved_it_bit_buff);
   1758   if (ptr_rvlc->sf_esc_present)
   1759     ixheaacd_rvlc_decode_escape(
   1760         ptr_rvlc, ptr_aac_dec_channel_info->rvlc_scf_esc_arr, it_bit_buff);
   1761 
   1762   ixheaacd_rvlc_decode_forward(ptr_rvlc, ptr_aac_dec_channel_info, it_bit_buff);
   1763   ixheaacd_rvlc_decode_backward(ptr_rvlc, ptr_aac_dec_channel_info,
   1764                                 it_bit_buff);
   1765   ixheaacd_rvlc_final_error_detection(ptr_aac_dec_channel_info,
   1766                                       ptr_aac_dec_static_channel_info);
   1767 
   1768   ptr_aac_dec_channel_info->rvlc_intensity_used = ptr_rvlc->intensity_used;
   1769   ptr_aac_dec_channel_info->str_pns_info.pns_active = ptr_rvlc->noise_used;
   1770 
   1771   ixheaacd_bitbuf_restore(*it_bit_buff, saved_it_bit_buff);
   1772   return error_code;
   1773 }
   1774