Esempio n. 1
0
void CBlock_ScaleSpectralData(CAacDecoderChannelInfo *pAacDecoderChannelInfo, SamplingRateInfo *pSamplingRateInfo)
{
  int band;
  int window;
  const SHORT * RESTRICT pSfbScale  = pAacDecoderChannelInfo->pDynData->aSfbScale;
  SHORT * RESTRICT pSpecScale = pAacDecoderChannelInfo->specScale;
  int groupwin,group;
  const SHORT * RESTRICT BandOffsets = GetScaleFactorBandOffsets(&pAacDecoderChannelInfo->icsInfo, pSamplingRateInfo);
  SPECTRAL_PTR RESTRICT pSpectralCoefficient = pAacDecoderChannelInfo->pSpectralCoefficient;


  FDKmemclear(pSpecScale, 8*sizeof(SHORT));

  int max_band = GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->icsInfo);
  for (window=0, group=0; group < GetWindowGroups(&pAacDecoderChannelInfo->icsInfo); group++)
  {
    for (groupwin=0; groupwin < GetWindowGroupLength(&pAacDecoderChannelInfo->icsInfo,group); groupwin++, window++)
    {
      int SpecScale_window = pSpecScale[window];
      FIXP_DBL *pSpectrum = SPEC(pSpectralCoefficient, window,  pAacDecoderChannelInfo->granuleLength);

      /* find scaling for current window */
      for (band=0; band < max_band; band++)
      {
        SpecScale_window = fMax(SpecScale_window, (int)pSfbScale[window*16+band]);
      }

      if (pAacDecoderChannelInfo->pDynData->TnsData.Active) {
        SpecScale_window += TNS_SCALE;
      }

      /* store scaling of current window */
      pSpecScale[window] = SpecScale_window;

#ifdef FUNCTION_CBlock_ScaleSpectralData_func1

      CBlock_ScaleSpectralData_func1(pSpectrum, max_band, BandOffsets, SpecScale_window, pSfbScale, window);

#else /* FUNCTION_CBlock_ScaleSpectralData_func1 */
      for (band=0; band < max_band; band++)
      {
        int scale = SpecScale_window - pSfbScale[window*16+band];
        if (scale)
        {
          /* following relation can be used for optimizations: (BandOffsets[i]%4) == 0 for all i */
          int max_index = BandOffsets[band+1];
          for (int index = BandOffsets[band]; index < max_index; index++)
          {
            pSpectrum[index] >>= scale;
          }
        }
      }
#endif  /* FUNCTION_CBlock_ScaleSpectralData_func1 */
    }
  }

}
Esempio n. 2
0
int  CShortBlock_ReadSpectralData(HANDLE_BIT_BUF bs,
                                  CAacDecoderChannelInfo *pAacDecoderChannelInfo)
{
  int i,index,step;
  int window,group,groupwin,groupoffset,band;
  int scfExp,scfMod;
  int *QuantizedCoef;
  char *pCodeBook = pAacDecoderChannelInfo->pCodeBook;
  short *pScaleFactor = pAacDecoderChannelInfo->pScaleFactor;
  float *pSpectralCoefficient = pAacDecoderChannelInfo->pSpectralCoefficient;
  const short *BandOffsets = GetScaleFactorBandOffsets(&pAacDecoderChannelInfo->IcsInfo);
  const CodeBookDescription *hcb;

  COUNT_sub_start("CShortBlock_ReadSpectralData");

  QuantizedCoef = (int*)pSpectralCoefficient;
  PTR_INIT(5); INDIRECT(4); FUNC(1); /* counting previous operations */

  LOOP(1);
  for (window=0; window < MaximumWindows; window++)
  {
    PTR_INIT(1); /* pointer for QuantizedCoef[] */
    LOOP(1);
    for (index=0; index < MaximumBinsShort; index++) {
      MOVE(1);
      QuantizedCoef[window*MaximumBinsShort+index] = 0;
    }
  }


  MOVE(1);
  groupoffset = 0;

  INDIRECT(1); FUNC(1); LOOP(1);
  for (group=0; group < GetWindowGroups(&pAacDecoderChannelInfo->IcsInfo); group++)
  {
    PTR_INIT(1); /* pointer for pCodeBook[] */
    INDIRECT(1); FUNC(1); LOOP(1);
    for (band=0; band < GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->IcsInfo); band++)
    {
      PTR_INIT(1);
      hcb = &HuffmanCodeBooks[pCodeBook[group*MaximumScaleFactorBandsShort+band]];

      INDIRECT(1); FUNC(1); LOOP(1);
      for (groupwin=0; groupwin < GetWindowGroupLength(&pAacDecoderChannelInfo->IcsInfo,group); groupwin++)
      {
        ADD(1);
        window = groupoffset + groupwin;

        ADD(4); LOGIC(3); BRANCH(1);
        if (  (pCodeBook[group*MaximumScaleFactorBandsShort+band] == ZERO_HCB)
            ||(pCodeBook[group*MaximumScaleFactorBandsShort+band] == INTENSITY_HCB)
            ||(pCodeBook[group*MaximumScaleFactorBandsShort+band] == INTENSITY_HCB2)
            ||(pCodeBook[group*MaximumScaleFactorBandsShort+band] == NOISE_HCB))
          continue;

        MOVE(1);
        step = 0 ;

        PTR_INIT(2); /* pointer for BandOffsets[],
                                    QuantizedCoef[] */
        LOOP(1);
        for (index=BandOffsets[band]; index < BandOffsets[band+1]; index+=step)
        {
          INDIRECT(1); FUNC(2); PTR_INIT(1); FUNC(3);
          step = CBlock_UnpackIndex(CBlock_DecodeHuffmanWord(bs,hcb->CodeBook),&QuantizedCoef[window*MaximumBinsShort+index],hcb);

          INDIRECT(1); BRANCH(1);
          if (hcb->Offset == 0)
          {
            PTR_INIT(1); /* pointer for QuantizedCoef[] */
            LOOP(1);
            for (i=0; i < step; i++)
            {
              BRANCH(1);
              if (QuantizedCoef[window*MaximumBinsShort+index+i])
              {
                FUNC(2);
                if (GetBits(bs,1)) /* sign bit */
                {
                  MULT(1); STORE(1);
                  QuantizedCoef [window*MaximumBinsShort+index+i] = -QuantizedCoef [window*MaximumBinsShort+index+i];
                }
              }
            }
          }

          ADD(1); BRANCH(1);
          if (pCodeBook[group*MaximumScaleFactorBandsShort+band] == ESCBOOK)
          {
            FUNC(2); STORE(1);
            QuantizedCoef[window*MaximumBinsShort+index] = CBlock_GetEscape(bs,QuantizedCoef[window*MaximumBinsShort+index]);

            FUNC(2); STORE(1);
            QuantizedCoef[window*MaximumBinsShort+index+1] = CBlock_GetEscape(bs,QuantizedCoef[window*MaximumBinsShort+index+1]);
  
            FUNC(1); FUNC(1); ADD(2); LOGIC(1); BRANCH(1);
            if (abs(QuantizedCoef[window*MaximumBinsShort+index]) > MAX_QUANTIZED_VALUE || abs(QuantizedCoef[window*MaximumBinsShort+index+1]) > MAX_QUANTIZED_VALUE) {
              COUNT_sub_end();
              return (AAC_DEC_DECODE_FRAME_ERROR);
            }
          }
        }
      }
    }

    INDIRECT(1); ADD(1);
    groupoffset += GetWindowGroupLength(&pAacDecoderChannelInfo->IcsInfo,group);
  }



  INDIRECT(1); FUNC(1); LOOP(1);
  for (window=0, group=0; group < GetWindowGroups(&pAacDecoderChannelInfo->IcsInfo); group++)
  {
    INDIRECT(1); FUNC(1); LOOP(1);
    for (groupwin=0; groupwin < GetWindowGroupLength(&pAacDecoderChannelInfo->IcsInfo,group); groupwin++, window++)
    {
      MOVE(1);
      index = 0;

      PTR_INIT(2); /* pointer for BandOffsets[],
                                  pScaleFactor     */
      INDIRECT(1); FUNC(1); LOOP(1) ;
      /* quantize & apply scalefactors */
      for (band=0; band < GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->IcsInfo); band++)
      {
        /* scalefactor exponents and scalefactor mantissa for current band */
        SHIFT(1);
        scfExp = pScaleFactor[group*MaximumScaleFactorBandsShort+band] >> 2;

        LOGIC(1);
        scfMod = pScaleFactor[group*MaximumScaleFactorBandsShort+band] & 3;

        PTR_INIT(2); /* pointer for QuantizedCoef[], 
                                    pSpectralCoefficient */
        LOOP(1);
        for (index=BandOffsets[band]; index < BandOffsets[band+1] ;index++)
        {
          ADD(1); FUNC(3); STORE(1);
          pSpectralCoefficient[window*MaximumBinsShort+index] = CBlock_Quantize(QuantizedCoef[window*MaximumBinsShort+index],scfMod,scfExp-6);
        }
      }

      PTR_INIT(1); /* pointer for pSpectralCoefficient */
      LOOP(1);
      for (; index < MaximumBinsShort; index++) {
        MOVE(1);
        pSpectralCoefficient[window*MaximumBinsShort+index] = 0.0;
      }
    }
  }


  COUNT_sub_end();
  return (AAC_DEC_OK);
}