Home | History | Annotate | Download | only in src
      1 
      2 /* -----------------------------------------------------------------------------------------------------------
      3 Software License for The Fraunhofer FDK AAC Codec Library for Android
      4 
      5  Copyright  1995 - 2013 Fraunhofer-Gesellschaft zur Frderung der angewandten Forschung e.V.
      6   All rights reserved.
      7 
      8  1.    INTRODUCTION
      9 The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
     10 the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
     11 This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
     12 
     13 AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
     14 audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
     15 independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
     16 of the MPEG specifications.
     17 
     18 Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
     19 may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
     20 individually for the purpose of encoding or decoding bit streams in products that are compliant with
     21 the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
     22 these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
     23 software may already be covered under those patent licenses when it is used for those licensed purposes only.
     24 
     25 Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
     26 are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
     27 applications information and documentation.
     28 
     29 2.    COPYRIGHT LICENSE
     30 
     31 Redistribution and use in source and binary forms, with or without modification, are permitted without
     32 payment of copyright license fees provided that you satisfy the following conditions:
     33 
     34 You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
     35 your modifications thereto in source code form.
     36 
     37 You must retain the complete text of this software license in the documentation and/or other materials
     38 provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
     39 You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
     40 modifications thereto to recipients of copies in binary form.
     41 
     42 The name of Fraunhofer may not be used to endorse or promote products derived from this library without
     43 prior written permission.
     44 
     45 You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
     46 software or your modifications thereto.
     47 
     48 Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
     49 and the date of any change. For modified versions of the FDK AAC Codec, the term
     50 "Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
     51 "Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
     52 
     53 3.    NO PATENT LICENSE
     54 
     55 NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
     56 ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
     57 respect to this software.
     58 
     59 You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
     60 by appropriate patent licenses.
     61 
     62 4.    DISCLAIMER
     63 
     64 This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
     65 "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
     66 of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
     67 CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
     68 including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
     69 or business interruption, however caused and on any theory of liability, whether in contract, strict
     70 liability, or tort (including negligence), arising in any way out of the use of this software, even if
     71 advised of the possibility of such damage.
     72 
     73 5.    CONTACT INFORMATION
     74 
     75 Fraunhofer Institute for Integrated Circuits IIS
     76 Attention: Audio and Multimedia Departments - FDK AAC LL
     77 Am Wolfsmantel 33
     78 91058 Erlangen, Germany
     79 
     80 www.iis.fraunhofer.de/amm
     81 amm-info (at) iis.fraunhofer.de
     82 ----------------------------------------------------------------------------------------------------------- */
     83 
     84 /*!
     85   \file
     86   \brief  rvlc concealment
     87   \author Josef Hoepfl
     88 */
     89 
     90 #include "rvlcconceal.h"
     91 
     92 
     93 #include "block.h"
     94 #include "rvlc.h"
     95 
     96 /*---------------------------------------------------------------------------------------------
     97   function:      calcRefValFwd
     98 
     99   description:   The function determines the scalefactor which is closed to the scalefactorband
    100                  conceal_min. The same is done for intensity data and noise energies.
    101 -----------------------------------------------------------------------------------------------
    102   output:        - reference value scf
    103                  - reference value internsity data
    104                  - reference value noise energy
    105 -----------------------------------------------------------------------------------------------
    106   return:        -
    107 -------------------------------------------------------------------------------------------- */
    108 
    109 static
    110 void calcRefValFwd (CErRvlcInfo *pRvlc,
    111                     CAacDecoderChannelInfo *pAacDecoderChannelInfo,
    112                     int *refIsFwd,
    113                     int *refNrgFwd,
    114                     int *refScfFwd)
    115 {
    116   int band,bnds,group,startBand;
    117   int idIs,idNrg,idScf;
    118   int conceal_min,conceal_group_min;
    119   int MaximumScaleFactorBands;
    120 
    121 
    122   if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == EightShortSequence)
    123     MaximumScaleFactorBands = 16;
    124   else
    125     MaximumScaleFactorBands = 64;
    126 
    127   conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
    128   conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
    129 
    130   /* calculate first reference value for approach in forward direction */
    131   idIs = idNrg = idScf = 1;
    132 
    133   /* set reference values */
    134   *refIsFwd = - SF_OFFSET;
    135   *refNrgFwd = pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain - SF_OFFSET - 90 - 256;
    136   *refScfFwd = pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain - SF_OFFSET;
    137 
    138   startBand = conceal_min-1;
    139   for (group=conceal_group_min; group >= 0; group--) {
    140     for (band=startBand; band >= 0; band--) {
    141       bnds = 16*group+band;
    142       switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
    143         case ZERO_HCB:
    144           break;
    145         case INTENSITY_HCB:
    146         case INTENSITY_HCB2:
    147           if (idIs) {
    148             *refIsFwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
    149             idIs=0; /* reference value has been set */
    150           }
    151           break;
    152         case NOISE_HCB:
    153           if (idNrg) {
    154             *refNrgFwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
    155             idNrg=0; /* reference value has been set */
    156           }
    157           break ;
    158         default:
    159           if (idScf) {
    160             *refScfFwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
    161             idScf=0; /* reference value has been set */
    162           }
    163           break;
    164       }
    165     }
    166     startBand = pRvlc->maxSfbTransmitted-1;
    167   }
    168 
    169 }
    170 
    171 /*---------------------------------------------------------------------------------------------
    172   function:      calcRefValBwd
    173 
    174   description:   The function determines the scalefactor which is closed to the scalefactorband
    175                  conceal_max. The same is done for intensity data and noise energies.
    176 -----------------------------------------------------------------------------------------------
    177   output:        - reference value scf
    178                  - reference value internsity data
    179                  - reference value noise energy
    180 -----------------------------------------------------------------------------------------------
    181   return:        -
    182 -------------------------------------------------------------------------------------------- */
    183 
    184 static
    185 void calcRefValBwd (CErRvlcInfo *pRvlc,
    186                     CAacDecoderChannelInfo *pAacDecoderChannelInfo,
    187                     int *refIsBwd,
    188                     int *refNrgBwd,
    189                     int *refScfBwd)
    190 {
    191   int band,bnds,group,startBand;
    192   int idIs,idNrg,idScf;
    193   int conceal_max,conceal_group_max;
    194   int MaximumScaleFactorBands;
    195 
    196   if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == EightShortSequence)
    197     MaximumScaleFactorBands = 16;
    198   else
    199     MaximumScaleFactorBands = 64;
    200 
    201   conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
    202   conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
    203 
    204   /* calculate first reference value for approach in backward direction */
    205   idIs = idNrg = idScf = 1;
    206 
    207   /* set reference values */
    208   *refIsBwd = pRvlc->dpcm_is_last_position - SF_OFFSET;
    209   *refNrgBwd = pRvlc->rev_global_gain + pRvlc->dpcm_noise_last_position - SF_OFFSET - 90 - 256 + pRvlc->dpcm_noise_nrg;
    210   *refScfBwd = pRvlc->rev_global_gain - SF_OFFSET;
    211 
    212   startBand=conceal_max+1;
    213 
    214   /* if needed, re-set reference values */
    215   for (group=conceal_group_max; group < pRvlc->numWindowGroups; group++) {
    216     for (band=startBand; band < pRvlc->maxSfbTransmitted; band++) {
    217       bnds = 16*group+band;
    218       switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
    219         case ZERO_HCB:
    220           break;
    221         case INTENSITY_HCB:
    222         case INTENSITY_HCB2:
    223           if (idIs) {
    224             *refIsBwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
    225             idIs=0; /* reference value has been set */
    226           }
    227           break;
    228         case NOISE_HCB:
    229           if (idNrg) {
    230             *refNrgBwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
    231             idNrg=0;  /* reference value has been set */
    232           }
    233           break ;
    234         default:
    235           if (idScf) {
    236             *refScfBwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
    237             idScf=0; /* reference value has been set */
    238           }
    239           break;
    240       }
    241     }
    242     startBand=0;
    243   }
    244 
    245 }
    246 
    247 
    248 /*---------------------------------------------------------------------------------------------
    249   function:      BidirectionalEstimation_UseLowerScfOfCurrentFrame
    250 
    251   description:   This approach by means of bidirectional estimation is generally performed when
    252                  a single bit error has been detected, the bit error can be isolated between
    253                  'conceal_min' and 'conceal_max' and the 'sf_concealment' flag is not set. The
    254                  sets of scalefactors decoded in forward and backward direction are compared
    255                  with each other. The smaller scalefactor will be considered as the correct one
    256                  respectively. The reconstruction of the scalefactors with this approach archieve
    257                  good results in audio quality. The strategy must be applied to scalefactors,
    258                  intensity data and noise energy seperately.
    259 -----------------------------------------------------------------------------------------------
    260   output:        Concealed scalefactor, noise energy and intensity data between conceal_min and
    261                  conceal_max
    262 -----------------------------------------------------------------------------------------------
    263   return:        -
    264 -------------------------------------------------------------------------------------------- */
    265 
    266 void BidirectionalEstimation_UseLowerScfOfCurrentFrame (CAacDecoderChannelInfo *pAacDecoderChannelInfo)
    267 {
    268   CErRvlcInfo *pRvlc = &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
    269   int band,bnds,startBand,endBand,group;
    270   int conceal_min,conceal_max;
    271   int conceal_group_min,conceal_group_max;
    272   int MaximumScaleFactorBands;
    273 
    274   if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == EightShortSequence) {
    275     MaximumScaleFactorBands = 16;
    276   }
    277   else {
    278     MaximumScaleFactorBands = 64;
    279   }
    280 
    281   /* If an error was detected just in forward or backward direction, set the corresponding border for concealment to a
    282      appropriate scalefactor band. The border is set to first or last sfb respectively, because the error will possibly
    283      not follow directly after the corrupt bit but just after decoding some more (wrong) scalefactors. */
    284   if (pRvlc->conceal_min == CONCEAL_MIN_INIT)
    285     pRvlc->conceal_min = 0;
    286 
    287   if (pRvlc->conceal_max == CONCEAL_MAX_INIT)
    288     pRvlc->conceal_max = (pRvlc->numWindowGroups-1)*16+pRvlc->maxSfbTransmitted-1;
    289 
    290   conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
    291   conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
    292   conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
    293   conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
    294 
    295   if (pRvlc->conceal_min == pRvlc->conceal_max) {
    296 
    297     int refIsFwd,refNrgFwd,refScfFwd;
    298     int refIsBwd,refNrgBwd,refScfBwd;
    299 
    300     bnds = pRvlc->conceal_min;
    301     calcRefValFwd(pRvlc,pAacDecoderChannelInfo,&refIsFwd,&refNrgFwd,&refScfFwd);
    302     calcRefValBwd(pRvlc,pAacDecoderChannelInfo,&refIsBwd,&refNrgBwd,&refScfBwd);
    303 
    304     switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
    305       case ZERO_HCB:
    306         break;
    307       case INTENSITY_HCB:
    308       case INTENSITY_HCB2:
    309         if (refIsFwd < refIsBwd)
    310           pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refIsFwd;
    311         else
    312           pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refIsBwd;
    313         break;
    314       case NOISE_HCB:
    315         if (refNrgFwd < refNrgBwd)
    316           pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refNrgFwd;
    317         else
    318           pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refNrgBwd;
    319         break;
    320       default:
    321         if (refScfFwd < refScfBwd)
    322           pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refScfFwd;
    323         else
    324           pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refScfBwd;
    325         break;
    326     }
    327   }
    328   else {
    329     pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[pRvlc->conceal_max] = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[pRvlc->conceal_max];
    330     pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[pRvlc->conceal_min] = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[pRvlc->conceal_min];
    331 
    332     /* consider the smaller of the forward and backward decoded value as the correct one */
    333     startBand = conceal_min;
    334     if (conceal_group_min == conceal_group_max)
    335       endBand = conceal_max;
    336     else
    337       endBand = pRvlc->maxSfbTransmitted-1;
    338 
    339     for (group=conceal_group_min; group <= conceal_group_max; group++) {
    340       for (band=startBand; band <= endBand; band++) {
    341         bnds = 16*group+band;
    342         if (pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds] < pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds])
    343           pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
    344         else
    345           pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
    346       }
    347       startBand = 0;
    348       if ((group+1) == conceal_group_max)
    349         endBand = conceal_max;
    350     }
    351   }
    352 
    353   /* now copy all data to the output buffer which needs not to be concealed */
    354   if (conceal_group_min == 0)
    355     endBand = conceal_min;
    356   else
    357     endBand = pRvlc->maxSfbTransmitted;
    358   for (group=0; group <= conceal_group_min; group++) {
    359     for (band=0; band < endBand; band++) {
    360       bnds = 16*group+band;
    361       pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
    362     }
    363     if ((group+1) == conceal_group_min)
    364       endBand = conceal_min;
    365   }
    366 
    367   startBand = conceal_max+1;
    368   for (group=conceal_group_max; group < pRvlc->numWindowGroups; group++) {
    369     for (band=startBand; band < pRvlc->maxSfbTransmitted; band++) {
    370       bnds = 16*group+band;
    371       pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
    372     }
    373     startBand = 0;
    374   }
    375 }
    376 
    377 /*---------------------------------------------------------------------------------------------
    378   function:      BidirectionalEstimation_UseScfOfPrevFrameAsReference
    379 
    380   description:   This approach by means of bidirectional estimation is generally performed when
    381                  a single bit error has been detected, the bit error can be isolated between
    382                  'conceal_min' and 'conceal_max', the 'sf_concealment' flag is set and the
    383                  previous frame has the same block type as the current frame. The scalefactor
    384                  decoded in forward and backward direction and the scalefactor of the previous
    385                  frame are compared with each other. The smaller scalefactor will be considered
    386                  as the correct one. At this the codebook of the previous and current frame must
    387                  be of the same set (scf, nrg, is) in each scalefactorband. Otherwise the
    388                  scalefactor of the previous frame is not considered in the minimum calculation.
    389                  The reconstruction of the scalefactors with this approach archieve good results
    390                  in audio quality. The strategy must be applied to scalefactors, intensity data
    391                  and noise energy seperately.
    392 -----------------------------------------------------------------------------------------------
    393   output:        Concealed scalefactor, noise energy and intensity data between conceal_min and
    394                  conceal_max
    395 -----------------------------------------------------------------------------------------------
    396   return:        -
    397 -------------------------------------------------------------------------------------------- */
    398 
    399 void BidirectionalEstimation_UseScfOfPrevFrameAsReference (
    400         CAacDecoderChannelInfo *pAacDecoderChannelInfo,
    401         CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo
    402         )
    403 {
    404   CErRvlcInfo *pRvlc = &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
    405   int band,bnds,startBand,endBand,group;
    406   int conceal_min,conceal_max;
    407   int conceal_group_min,conceal_group_max;
    408   int MaximumScaleFactorBands;
    409   int commonMin;
    410 
    411   if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == EightShortSequence) {
    412     MaximumScaleFactorBands = 16;
    413   }
    414   else {
    415     MaximumScaleFactorBands = 64;
    416   }
    417 
    418   /* If an error was detected just in forward or backward direction, set the corresponding border for concealment to a
    419      appropriate scalefactor band. The border is set to first or last sfb respectively, because the error will possibly
    420      not follow directly after the corrupt bit but just after decoding some more (wrong) scalefactors. */
    421   if (pRvlc->conceal_min == CONCEAL_MIN_INIT)
    422     pRvlc->conceal_min = 0;
    423 
    424   if (pRvlc->conceal_max == CONCEAL_MAX_INIT)
    425     pRvlc->conceal_max = (pRvlc->numWindowGroups-1)*16+pRvlc->maxSfbTransmitted-1;
    426 
    427   conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
    428   conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
    429   conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
    430   conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
    431 
    432   pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[pRvlc->conceal_max] = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[pRvlc->conceal_max];
    433   pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[pRvlc->conceal_min] = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[pRvlc->conceal_min];
    434 
    435   /* consider the smaller of the forward and backward decoded value as the correct one */
    436   startBand = conceal_min;
    437   if (conceal_group_min == conceal_group_max)
    438     endBand = conceal_max;
    439   else
    440     endBand = pRvlc->maxSfbTransmitted-1;
    441 
    442   for (group=conceal_group_min; group <= conceal_group_max; group++) {
    443     for (band=startBand; band <= endBand; band++) {
    444       bnds = 16*group+band;
    445       switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
    446         case ZERO_HCB:
    447           pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
    448           break;
    449 
    450         case INTENSITY_HCB:
    451         case INTENSITY_HCB2:
    452           if ( (pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousCodebook[bnds]==INTENSITY_HCB) || (pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousCodebook[bnds]==INTENSITY_HCB2) ) {
    453             commonMin = FDKmin(pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds]);
    454             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = FDKmin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousScaleFactor[bnds]);
    455           }
    456           else {
    457             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = FDKmin(pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds]);
    458           }
    459           break;
    460 
    461         case NOISE_HCB:
    462           if ( (pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousCodebook[bnds]==NOISE_HCB) ) {
    463             commonMin = FDKmin(pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds]);
    464             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = FDKmin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousScaleFactor[bnds]);
    465           } else {
    466             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = FDKmin(pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds]);
    467           }
    468           break;
    469 
    470         default:
    471           if (   (pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousCodebook[bnds]!=ZERO_HCB)
    472               && (pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousCodebook[bnds]!=NOISE_HCB)
    473               && (pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousCodebook[bnds]!=INTENSITY_HCB)
    474               && (pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousCodebook[bnds]!=INTENSITY_HCB2) )
    475           {
    476             commonMin = FDKmin(pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds], pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds]);
    477             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = FDKmin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousScaleFactor[bnds]);
    478           } else {
    479             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = FDKmin(pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds]);
    480           }
    481           break;
    482       }
    483     }
    484     startBand = 0;
    485     if ((group+1) == conceal_group_max)
    486       endBand = conceal_max;
    487   }
    488 
    489   /* now copy all data to the output buffer which needs not to be concealed */
    490   if (conceal_group_min == 0)
    491     endBand = conceal_min;
    492   else
    493     endBand = pRvlc->maxSfbTransmitted;
    494   for (group=0; group <= conceal_group_min; group++) {
    495     for (band=0; band < endBand; band++) {
    496       bnds = 16*group+band;
    497       pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
    498     }
    499     if ((group+1) == conceal_group_min)
    500       endBand = conceal_min;
    501   }
    502 
    503   startBand = conceal_max+1;
    504   for (group=conceal_group_max; group < pRvlc->numWindowGroups; group++) {
    505     for (band=startBand; band < pRvlc->maxSfbTransmitted; band++) {
    506       bnds = 16*group+band;
    507       pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
    508     }
    509     startBand = 0;
    510   }
    511 }
    512 
    513 /*---------------------------------------------------------------------------------------------
    514   function:      StatisticalEstimation
    515 
    516   description:   This approach by means of statistical estimation is generally performed when
    517                  both the start value and the end value are different and no further errors have
    518                  been detected. Considering the forward and backward decoded scalefactors, the
    519                  set with the lower scalefactors in sum will be considered as the correct one.
    520                  The scalefactors are differentially encoded. Normally it would reach to compare
    521                  one pair of the forward and backward decoded scalefactors to specify the lower
    522                  set. But having detected no further errors does not necessarily mean the absence
    523                  of errors. Therefore all scalefactors decoded in forward and backward direction
    524                  are summed up seperately. The set with the lower sum will be used. The strategy
    525                  must be applied to scalefactors, intensity data and noise energy seperately.
    526 -----------------------------------------------------------------------------------------------
    527   output:        Concealed scalefactor, noise energy and intensity data
    528 -----------------------------------------------------------------------------------------------
    529   return:        -
    530 -------------------------------------------------------------------------------------------- */
    531 
    532 void StatisticalEstimation (CAacDecoderChannelInfo *pAacDecoderChannelInfo)
    533 {
    534   CErRvlcInfo *pRvlc = &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
    535   int band,bnds,group;
    536   int sumIsFwd,sumIsBwd;            /* sum of intensity data forward/backward */
    537   int sumNrgFwd,sumNrgBwd;          /* sum of noise energy data forward/backward */
    538   int sumScfFwd,sumScfBwd;          /* sum of scalefactor data forward/backward */
    539   int useIsFwd,useNrgFwd,useScfFwd; /* the flags signals the elements which are used for the final result */
    540   int MaximumScaleFactorBands;
    541 
    542   if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == EightShortSequence)
    543     MaximumScaleFactorBands = 16;
    544   else
    545     MaximumScaleFactorBands = 64;
    546 
    547   sumIsFwd = sumIsBwd = sumNrgFwd = sumNrgBwd = sumScfFwd = sumScfBwd = 0;
    548   useIsFwd = useNrgFwd = useScfFwd = 0;
    549 
    550   /* calculate sum of each group (scf,nrg,is) of forward and backward direction */
    551   for (group=0; group<pRvlc->numWindowGroups; group++) {
    552     for (band=0; band < pRvlc->maxSfbTransmitted; band++) {
    553       bnds = 16*group+band;
    554       switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
    555         case ZERO_HCB:
    556           break;
    557 
    558         case INTENSITY_HCB:
    559         case INTENSITY_HCB2:
    560           sumIsFwd += pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
    561           sumIsBwd += pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
    562           break;
    563 
    564         case NOISE_HCB:
    565           sumNrgFwd += pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
    566           sumNrgBwd += pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
    567           break ;
    568 
    569         default:
    570           sumScfFwd += pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
    571           sumScfBwd += pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
    572           break;
    573       }
    574     }
    575   }
    576 
    577   /* find for each group (scf,nrg,is) the correct direction */
    578   if ( sumIsFwd < sumIsBwd )
    579     useIsFwd = 1;
    580 
    581   if ( sumNrgFwd < sumNrgBwd )
    582     useNrgFwd = 1;
    583 
    584   if ( sumScfFwd < sumScfBwd )
    585     useScfFwd = 1;
    586 
    587   /* conceal each group (scf,nrg,is) */
    588   for (group=0; group<pRvlc->numWindowGroups; group++) {
    589     for (band=0; band < pRvlc->maxSfbTransmitted; band++) {
    590       bnds = 16*group+band;
    591       switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
    592         case ZERO_HCB:
    593           break;
    594 
    595         case INTENSITY_HCB:
    596         case INTENSITY_HCB2:
    597           if (useIsFwd)
    598             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
    599           else
    600             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
    601           break;
    602 
    603         case NOISE_HCB:
    604           if (useNrgFwd)
    605             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
    606           else
    607             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
    608           break ;
    609 
    610         default:
    611           if (useScfFwd)
    612             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
    613           else
    614             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
    615           break;
    616       }
    617     }
    618   }
    619 }
    620 
    621 
    622 /*---------------------------------------------------------------------------------------------
    623   description:   Approach by means of predictive interpolation
    624                  This approach by means of predictive estimation is generally performed when
    625                  the error cannot be isolated between 'conceal_min' and 'conceal_max', the
    626                  'sf_concealment' flag is set and the previous frame has the same block type
    627                  as the current frame. Check for each scalefactorband if the same type of data
    628                  (scalefactor, internsity data, noise energies) is transmitted. If so use the
    629                  scalefactor (intensity data, noise energy) in the current frame. Otherwise set
    630                  the scalefactor (intensity data, noise energy) for this scalefactorband to zero.
    631 -----------------------------------------------------------------------------------------------
    632   output:        Concealed scalefactor, noise energy and intensity data
    633 -----------------------------------------------------------------------------------------------
    634   return:        -
    635 -------------------------------------------------------------------------------------------- */
    636 
    637 void PredictiveInterpolation (
    638         CAacDecoderChannelInfo *pAacDecoderChannelInfo,
    639         CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo
    640         )
    641 {
    642   CErRvlcInfo *pRvlc = &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
    643   int band,bnds,group;
    644   int MaximumScaleFactorBands;
    645   int commonMin;
    646 
    647   if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == EightShortSequence)
    648     MaximumScaleFactorBands = 16;
    649   else
    650     MaximumScaleFactorBands = 64;
    651 
    652   for (group=0; group<pRvlc->numWindowGroups; group++) {
    653     for (band=0; band < pRvlc->maxSfbTransmitted; band++) {
    654       bnds = 16*group+band;
    655       switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
    656         case ZERO_HCB:
    657           pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
    658           break;
    659 
    660         case INTENSITY_HCB:
    661         case INTENSITY_HCB2:
    662           if ( (pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousCodebook[bnds]==INTENSITY_HCB) || (pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousCodebook[bnds]==INTENSITY_HCB2) ) {
    663             commonMin = FDKmin(pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds]);
    664             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = FDKmin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousScaleFactor[bnds]);
    665           }
    666           else {
    667             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = -110;
    668           }
    669           break;
    670 
    671         case NOISE_HCB:
    672           if ( (pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousCodebook[bnds]==NOISE_HCB) ) {
    673             commonMin = FDKmin(pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds]);
    674             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = FDKmin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousScaleFactor[bnds]);
    675           }
    676           else {
    677             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = -110;
    678           }
    679           break;
    680 
    681         default:
    682           if (   (pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousCodebook[bnds]!=ZERO_HCB)
    683               && (pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousCodebook[bnds]!=NOISE_HCB)
    684               && (pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousCodebook[bnds]!=INTENSITY_HCB)
    685               && (pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousCodebook[bnds]!=INTENSITY_HCB2) ) {
    686             commonMin = FDKmin(pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds]);
    687             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = FDKmin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo.aRvlcPreviousScaleFactor[bnds]);
    688           }
    689           else {
    690             pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
    691           }
    692           break;
    693       }
    694     }
    695   }
    696 }
    697 
    698