Example #1
0
static void calcPeCorrection(float *correctionFac,
                             const float peAct,
                             const float peLast, 
                             const int bitsLast) 
{
  COUNT_sub_start("calcPeCorrection");

  ADD(4); FUNC(1); FUNC(1); MULT(4); LOGIC(4); BRANCH(1);
  if ((bitsLast > 0) && (peAct < (float)1.5f*peLast) && (peAct > (float)0.7f*peLast) &&
      ((float)1.2f*bits2pe((float)bitsLast) > peLast) && 
      ((float)0.65f*bits2pe((float)bitsLast) < peLast))
  {
    float newFac = peLast / bits2pe((float)bitsLast);

    FUNC(1); DIV(1); /* counting previous operation */

    /* dead zone */
    ADD(1); BRANCH(1);
    if (newFac < (float)1.0f) {

      MULT(1); ADD(1); BRANCH(1); MOVE(1);
      newFac = min((float)1.1f*newFac, (float)1.0f);

      ADD(1); BRANCH(1); MOVE(1);
      newFac = max(newFac, (float)0.85f);
    }
    else {
      MULT(1); ADD(1); BRANCH(1); MOVE(1);
      newFac = max((float)0.9f*newFac, (float)1.0f);

      ADD(1); BRANCH(1); MOVE(1);
      newFac = min(newFac, (float)1.15f);
    }
    ADD(4); LOGIC(3); BRANCH(1);
    if (((newFac > (float)1.0f) && (*correctionFac < (float)1.0f)) ||
        ((newFac < (float)1.0f) && (*correctionFac > (float)1.0f))) {

      MOVE(1);
      *correctionFac = (float)1.0f;
    }

    /* faster adaptation towards 1.0, slower in the other direction */
    ADD(3); LOGIC(3); BRANCH(1); /* if() */ MULT(1); MAC(1); STORE(1);
    if ((*correctionFac < (float)1.0f && newFac < *correctionFac) ||
        (*correctionFac > (float)1.0f && newFac > *correctionFac))
      *correctionFac = (float)0.85f * (*correctionFac) + (float)0.15f * newFac;
    else
      *correctionFac = (float)0.7f * (*correctionFac) + (float)0.3f * newFac;

    ADD(2); BRANCH(2); MOVE(2);
    *correctionFac = min(*correctionFac, (float)1.15f);
    *correctionFac = max(*correctionFac, (float)0.85f);
  }
  else {
    MOVE(1);
    *correctionFac = (float)1.0f;
  }

  COUNT_sub_end();
}
Example #2
0
/*
  \brief     crc calculation
*/
static unsigned long
calcCRC (HANDLE_CRC hCrcBuf, unsigned long bValue, int nBits)
{
  int i;
  unsigned long bMask = (1UL << (nBits - 1));

  FLC_sub_start("calcCRC");

  ADD(1); SHIFT(1); /* counting previous operations */

  LOOP(1);
  for (i = 0; i < nBits; i++, bMask >>= 1) {
    unsigned short flag = (hCrcBuf->crcState & hCrcBuf->crcMask) ? 1 : 0;
    unsigned short flag1 = (bMask & bValue) ? 1 : 0;

    INDIRECT(2); ADD(2); LOGIC(2); BRANCH(2); MOVE(2); /* counting previous operations */

    LOGIC(1);
    flag ^= flag1;

    SHIFT(1); STORE(1);
    hCrcBuf->crcState <<= 1;

    BRANCH(1);
    if (flag)
    {
      INDIRECT(1); LOGIC(1); STORE(1);
      hCrcBuf->crcState ^= hCrcBuf->crcPoly;
    }
  }

  FLC_sub_end();

  return (hCrcBuf->crcState);
}
Example #3
0
/*!

  \brief  Selects the SBR tuning.
  \return Index

****************************************************************************/
static int
getSbrTuningTableIndex(unsigned int bitrate,
                       unsigned int numChannels,
                       unsigned int sampleRate
                       )
{
  int i, paramSets = sizeof (tuningTable) / sizeof (tuningTable [0]);

  COUNT_sub_start("getSbrTuningTableIndex");

  MOVE(1); /* counting previous operation */

  PTR_INIT(1); /* tuningTable[] */
  LOOP(1);
  for (i = 0 ; i < paramSets ; i++)  {
    ADD(1); BRANCH(1);
    if (numChannels == tuningTable [i].numChannels) {

      ADD(3); LOGIC(2); BRANCH(1);
      if ((sampleRate == tuningTable [i].sampleRate) &&
          (bitrate >= tuningTable [i].bitrateFrom) &&
          (bitrate < tuningTable [i].bitrateTo)) {
        COUNT_sub_end();
        return i ;
      }
    }
  }

  COUNT_sub_end();

  return INVALID_TABLE_IDX;
}
Example #4
0
/* apply reduction formula */
static void reduceThresholds(PSY_OUT_CHANNEL  psyOutChannel[MAX_CHANNELS],
                             int ahFlag[MAX_CHANNELS][MAX_GROUPED_SFB],
                             float thrExp[MAX_CHANNELS][MAX_GROUPED_SFB],
                             const int nChannels,
                             const float redVal)
{
   int ch, sfb,sfbGrp;
   float sfbEn, sfbThr,sfbThrReduced;

   COUNT_sub_start("reduceThresholds");

   LOOP(1);
   for(ch=0; ch<nChannels; ch++) {
      PSY_OUT_CHANNEL *psyOutChan = &psyOutChannel[ch];

      PTR_INIT(1); /* counting previous operation */

      INDIRECT(2); LOOP(1);
      for(sfbGrp = 0;sfbGrp < psyOutChan->sfbCnt;sfbGrp+= psyOutChan->sfbPerGroup){

        PTR_INIT(5); /* pointers for psyOutChan->sfbMinSnr[sfbGrp+sfb],
                                     psyOutChan->sfbEnergy[sfbGrp+sfb],
                                     psyOutChan->sfbThreshold[sfbGrp+sfb],
                                     thrExp[ch][sfbGrp+sfb],
                                     ahFlag[ch][sfbGrp+sfb]
                     */
        INDIRECT(1); LOOP(1);
        for (sfb=0; sfb<psyOutChan->maxSfbPerGroup; sfb++) {

         MOVE(2);
         sfbEn  = psyOutChan->sfbEnergy[sfbGrp+sfb];
         sfbThr = psyOutChan->sfbThreshold[sfbGrp+sfb];

         ADD(1); BRANCH(1);
         if (sfbEn > sfbThr) {
            /* threshold reduction formula */

            ADD(1); TRANS(1);
            sfbThrReduced = (float) pow(thrExp[ch][sfbGrp+sfb]+redVal, invRedExp);

            /* avoid holes */
            MULT(1); ADD(2); LOGIC(1); BRANCH(1);
            if ((sfbThrReduced > psyOutChan->sfbMinSnr[sfbGrp+sfb] * sfbEn) && (ahFlag[ch][sfbGrp+sfb] != NO_AH)){

              ADD(1); BRANCH(1); MOVE(1);
              sfbThrReduced = max(psyOutChan->sfbMinSnr[sfbGrp+sfb] * sfbEn, sfbThr);

              MOVE(1);
              ahFlag[ch][sfbGrp+sfb] = AH_ACTIVE;
            }

            MOVE(1);
            psyOutChan->sfbThreshold[sfbGrp+sfb] = sfbThrReduced;
         }
        }
      }
   }

   COUNT_sub_end();
}
Example #5
0
/*
 \brief     Reads n bits from Bitbuffer

 \return    bits
*/
unsigned long
getbits (HANDLE_BIT_BUFFER hBitBuf,
         int n)
{
  unsigned long ret_value = 0;

  assert(n <= 32);

  FLC_sub_start("getbits");

  MOVE(1); /* counting previous operation */

  LOOP(1);
  while (n>8) {

    ADD(1);
    n -= 8;

    FUNC(2); SHIFT(1); ADD(1);
    ret_value += getbits(hBitBuf,8) << n;
  }

  INDIRECT(1); ADD(1); BRANCH(1);
  if (hBitBuf->buffered_bits <= 8) {

    INDIRECT(2); SHIFT(1); LOGIC(1); STORE(1);
    hBitBuf->buffer_word = (hBitBuf->buffer_word << 8) | *hBitBuf->char_ptr++;

    ADD(1); STORE(1);
    hBitBuf->buffered_bits += 8;
  }

  ADD(1); STORE(1);
  hBitBuf->buffered_bits -= n;

  SHIFT(2); ADD(2); LOGIC(1);
  ret_value +=
    (hBitBuf->buffer_word >> hBitBuf->buffered_bits) & ((1 << n) - 1);


  INDIRECT(1); ADD(1); STORE(1);
  hBitBuf->nrBitsRead += n;

  FLC_sub_end();

  return (ret_value);
}
Example #6
0
JNIEXPORT void Java_com_rx201_apkmon_APIHook_saveDecisions( JNIEnv* env, jobject thiz, jstring path, jbyteArray data )
{
	char file[1024];
	const char *path_ptr = env->GetStringUTFChars(path, NULL);
	snprintf(file, sizeof(file), "%s/"AurasiumPolicyFile, path_ptr);
	env->ReleaseStringUTFChars(path, path_ptr);
	FILE* f = fopen(file, "w");
	LOGIC("file: %p<n", file);
	if (f)
	{
		int length = env->GetArrayLength(data);
		jbyte* array = (jbyte*)env->GetPrimitiveArrayCritical(data, 0);
		fwrite(array, 1, length, f);
		env->ReleasePrimitiveArrayCritical(data, array, 0);
		fclose(f);
	}
	else
		LOGIC("Saving decisions to %s failed.", AurasiumPolicyFile);
}
Example #7
0
/*
  \brief     crc
*/
static int
getCrc (HANDLE_BIT_BUFFER hBitBuf, unsigned long NrBits)
{

  int i;
  int CrcStep = NrBits / MAXCRCSTEP;
  int CrcNrBitsRest = (NrBits - CrcStep * MAXCRCSTEP);
  unsigned long bValue;

  CRC_BUFFER CrcBuf;

  FLC_sub_start("getCrc");

  DIV(1); MULT(1); ADD(1); /* counting previous operations */

  MOVE(3);
  CrcBuf.crcState = SBR_CRC_START;
  CrcBuf.crcPoly  = SBR_CRC_POLY;
  CrcBuf.crcMask  = SBR_CRC_MASK;

  LOOP(1);
  for (i = 0; i < CrcStep; i++) {

    FUNC(2);
    bValue = getbits (hBitBuf, MAXCRCSTEP);

    PTR_INIT(1); FUNC(3);
    calcCRC (&CrcBuf, bValue, MAXCRCSTEP);
  }

  FUNC(2);
  bValue = getbits (hBitBuf, CrcNrBitsRest);

  PTR_INIT(1); FUNC(3);
  calcCRC (&CrcBuf, bValue, CrcNrBitsRest);

  LOGIC(1); /* counting post operation */

  FLC_sub_end();

  return (CrcBuf.crcState & SBR_CRC_RANGE);

}
Example #8
0
static int
findRegion(float currVal,
           const float* borders,
           const int numBorders,
           int prevRegion
           )
{
  int i;

  COUNT_sub_start("findRegion");

  ADD(1); BRANCH(1);
  if(currVal < borders[0])
  {
    COUNT_sub_end();
    return 0;
  }

  PTR_INIT(1); /* borders[] */
  LOOP(1);
  for(i = 1; i < numBorders; i++){

    ADD(2); LOGIC(1); BRANCH(1);
    if( currVal >= borders[i-1] && currVal < borders[i])
    {
      COUNT_sub_end();
      return i;
    }
  }

  ADD(1); BRANCH(1);
  if(currVal > borders[numBorders-1])
  {
    COUNT_sub_end();
    return numBorders;
  }

  COUNT_sub_end();
  return 0;
}
Example #9
0
static void adaptThresholdsToPe(PSY_OUT_CHANNEL  psyOutChannel[MAX_CHANNELS],
                                PSY_OUT_ELEMENT* psyOutElement,
                                PE_DATA *peData,
                                const int nChannels,
                                const float desiredPe,
                                AH_PARAM *ahParam,
                                MINSNR_ADAPT_PARAM *msaParam)
{
   float noRedPe, redPe, redPeNoAH;
   float constPart, constPartNoAH;
   float nActiveLines, nActiveLinesNoAH;
   float desiredPeNoAH;
   float avgThrExp, redVal;
   int   ahFlag[MAX_CHANNELS][MAX_GROUPED_SFB];
   float thrExp[MAX_CHANNELS][MAX_GROUPED_SFB];
   int iter;

   COUNT_sub_start("adaptThresholdsToPe");

   FUNC(3);
   calcThreshExp(thrExp, psyOutChannel, nChannels);

   FUNC(3);
   adaptMinSnr(psyOutChannel, msaParam, nChannels);

   FUNC(5);
   initAvoidHoleFlag(ahFlag, psyOutChannel, psyOutElement, nChannels, ahParam);

   INDIRECT(3); MOVE(3);
   noRedPe = peData->pe;
   constPart = peData->constPart;
   nActiveLines = peData->nActiveLines;

   MULT(1); ADD(1); DIV(1); TRANS(1);
   avgThrExp = (float)pow(2.0f, (constPart - noRedPe)/(invRedExp*nActiveLines));

   /* MULT(1); calculated above */ ADD(2); DIV(1); TRANS(1);
   redVal = (float)pow(2.0f, (constPart - desiredPe)/(invRedExp*nActiveLines)) -
            avgThrExp;

   BRANCH(1); MOVE(1);
   redVal = max(0.0f, redVal);

   FUNC(5);
   reduceThresholds(psyOutChannel, ahFlag, thrExp, nChannels, redVal);

   FUNC(3);
   calcPe(peData, psyOutChannel, nChannels);

   INDIRECT(1); MOVE(1);
   redPe = peData->pe;

   MOVE(1);
   iter = 0;

   LOOP(1);
   do {

     PTR_INIT(3); FUNC(7);
     calcPeNoAH(&redPeNoAH, &constPartNoAH, &nActiveLinesNoAH,
                peData, ahFlag, psyOutChannel, nChannels);

     ADD(2); BRANCH(1); MOVE(1);
     desiredPeNoAH = max(desiredPe - (redPe - redPeNoAH), 0);

     BRANCH(1);
     if (nActiveLinesNoAH > 0) {

       MULT(1); ADD(1); DIV(1); TRANS(1);
       avgThrExp = (float)pow(2.0f, (constPartNoAH - redPeNoAH) / (invRedExp*nActiveLinesNoAH));

       /* MULT(1); calculated above */ ADD(3); DIV(1); TRANS(1);
       redVal   += (float)pow(2.0f, (constPartNoAH - desiredPeNoAH) / (invRedExp*nActiveLinesNoAH))
                   - avgThrExp;

       BRANCH(1); MOVE(1);
       redVal = max(0.0f, redVal);

       FUNC(5);
       reduceThresholds(psyOutChannel, ahFlag, thrExp, nChannels, redVal);
     }

     FUNC(3);
     calcPe(peData, psyOutChannel, nChannels);

     INDIRECT(1); MOVE(1);
     redPe = peData->pe;

     ADD(1);
     iter++;

     ADD(3); MISC(1); MULT(1); LOGIC(1); /* while() condition */
   } while ((fabs(redPe - desiredPe) > (0.05f)*desiredPe) && (iter < 2));


   MULT(1); ADD(1); BRANCH(1);
   if (redPe < 1.15f*desiredPe) {

     ADD(1); FUNC(7);
     correctThresh(psyOutChannel, ahFlag, peData, thrExp, redVal,
                   nChannels, desiredPe - redPe);
   }
   else {

     MULT(1); FUNC(5);
     reduceMinSnr(psyOutChannel, peData, ahFlag, nChannels, 1.05f*desiredPe);

     MULT(1); FUNC(7);
     allowMoreHoles(psyOutChannel, psyOutElement, peData, ahFlag,
                    ahParam, nChannels, 1.05f*desiredPe);
   }

   COUNT_sub_end();
}
Example #10
0
/*!
  The function decodes one aac frame. The decoding of coupling channel
  elements are not supported. The transport layer might signal, that the
  data of the current frame is invalid, e.g. as a result of a packet
  loss in streaming mode.
*/
int CAacDecoder_DecodeFrame(AACDECODER self,            /*!< pointer to aacdecoder structure */
                            int *frameSize,             /*!< pointer to frame size */
                            int *sampleRate,            /*!< pointer to sample rate */
                            int *numChannels,           /*!< pointer to number of channels */
                            char *channelMode,          /*!< mode: 0=mono, 1=stereo */
                            char frameOK                /*!< indicates if current frame data is valid */
                            )
{
  unsigned char aacChannels=0;
  long tmp;
  unsigned char ch;
  int type = 0;
  int ErrorStatus = frameOK;
  static int BlockNumber = 0;
  HANDLE_BIT_BUF bs = self->pBs;
  int previous_element;
  int channel;

  COUNT_sub_start("CAacDecoder_DecodeFrame");

  MOVE(7); INDIRECT(1); PTR_INIT(1); /* counting previous operations */

  /* initialize pointer to CAacDecoderChannelInfo for each channel */
  PTR_INIT(4); /* self->pAacDecoderChannelInfo[ch]
                  pAacDecoderChannelInfoInit[ch];
                  pAacDecoderDynamicDataInit[ch]
                  WorkBufferCore[ch*MaximumBinsLong];
               */
  LOOP(1);
  for (ch=0; ch<Channels; ch++)
  {
    INDIRECT(1); PTR_INIT(5);
    self->pAacDecoderChannelInfo[ch] = pAacDecoderChannelInfoInit[ch];
    self->pAacDecoderChannelInfo[ch]->pCodeBook = pAacDecoderDynamicDataInit[ch]->aCodeBook;
    self->pAacDecoderChannelInfo[ch]->pScaleFactor = pAacDecoderDynamicDataInit[ch]->aScaleFactor;
    self->pAacDecoderChannelInfo[ch]->pSpectralCoefficient = &WorkBufferCore[ch*MaximumBinsLong];
    self->pAacDecoderChannelInfo[ch]->pJointStereoData = &pAacDecoderDynamicCommonDataInit->JointStereoData;
    self->pAacDecoderChannelInfo[ch]->pPnsInterChannelData = &pAacDecoderDynamicCommonDataInit->PnsInterChannelData;
    self->pAacDecoderChannelInfo[ch]->pPnsStaticInterChannelData = &PnsStaticInterChannelData;
  }

  INDIRECT(1); MOVE(1);
  self->frameOK = 1;

  PTR_INIT(1); /* self->pAacDecoderChannelInfo[channel] */
  LOOP(1);
  for (channel=0; channel < Channels; channel++)
  {
    FUNC(1);
    CPns_InitPns(self->pAacDecoderChannelInfo[channel]);
  }

  INDIRECT(1); FUNC(1);
  CPns_InitInterChannelData(self->pAacDecoderChannelInfo[0]);

  MOVE(1);
  aacChannels = 0;

  INDIRECT(1); PTR_INIT(1); FUNC(2);
  ByteAlign(bs,&self->byteAlignBits);

  MOVE(1);
  previous_element = ID_END;

  LOOP(1);
  while ( (type != ID_END) && self->frameOK )
  {
    ADD(1); LOGIC(1); /* while() condition */

    FUNC(2);
    type = GetBits(bs,3);

    INDIRECT(1); BRANCH(1);
    if (bs->cntBits < 0)
    {
      INDIRECT(1); MOVE(1);
      self->frameOK = 0;
    }

    BRANCH(1);
    switch (type)
    {
      case ID_SCE:
      
        /*
          Consistency check
        */

        ADD(1); BRANCH(1);
        if(aacChannels >= Channels){

          INDIRECT(1); MOVE(1);
          self->frameOK = 0;
          break;
        }
          
        INDIRECT(1); MOVE(1);
        self->pStreamSbr->sbrElement[self->pStreamSbr->NrElements].ElementID = SBR_ID_SCE;

        INDIRECT(1); BRANCH(1); 
        if(self->frameOK) {

          INDIRECT(3); PTR_INIT(1); FUNC(3);
          ErrorStatus = CSingleChannelElement_Read(bs,self->pAacDecoderChannelInfo,self->pStreamInfo);

          BRANCH(1);
          if (ErrorStatus) {

            INDIRECT(1); MOVE(1);
            self->frameOK = 0;
          }
        }

        INDIRECT(1); BRANCH(1);
        if ( self->frameOK )
        {
          INDIRECT(1); FUNC(1);
          CSingleChannelElement_Decode(self->pAacDecoderChannelInfo);

          ADD(1);
          aacChannels += 1;
        }

        break;
      
      case ID_CPE:
       
        /*
          Consistency check
        */
        ADD(1); BRANCH(1);
        if(aacChannels >= Channels){

          INDIRECT(1); MOVE(1);
          self->frameOK = 0;
          break;
        }
          
        INDIRECT(1); MOVE(1);
        self->pStreamSbr->sbrElement[self->pStreamSbr->NrElements].ElementID = SBR_ID_CPE;


        INDIRECT(1); BRANCH(1);
        if (self->frameOK) {

          INDIRECT(3); PTR_INIT(1); FUNC(3);
          ErrorStatus = CChannelPairElement_Read(bs,self->pAacDecoderChannelInfo,self->pStreamInfo);

          BRANCH(1);
          if (ErrorStatus) {

            INDIRECT(1); MOVE(1);
            self->frameOK = 0;
          }
        }

        INDIRECT(1); BRANCH(1);
        if ( self->frameOK ){

          INDIRECT(1); FUNC(1);
          CChannelPairElement_Decode(self->pAacDecoderChannelInfo);

          ADD(1);
          aacChannels += 2;
        }

        break;
      
      case ID_CCE:
      
        INDIRECT(1); MOVE(2);
        ErrorStatus = AAC_DEC_UNIMPLEMENTED_CCE;
        self->frameOK = 0;
        break;

      case ID_LFE:

        INDIRECT(1); MOVE(2);
        ErrorStatus = AAC_DEC_UNIMPLEMENTED_LFE;
        self->frameOK = 0;
        break;
      
      case ID_DSE:

        INDIRECT(1); PTR_INIT(1); FUNC(2);
        CDse_Read(bs, &self->byteAlignBits);
        break;

      case ID_PCE:

        INDIRECT(1); MOVE(2);
        ErrorStatus = AAC_DEC_UNIMPLEMENTED_PCE;
        self->frameOK = 0;

        break;
      
      case ID_FIL:

        INDIRECT(1); MOVE(1);
        tmp = bs->cntBits;

        FFRaacplus_checkForPayload(bs,self->pStreamSbr,previous_element);
        break;
      
      case ID_END:
        break;
    }

    MOVE(1);
    previous_element = type;
  }


  /* Update number of channels (if valid) */
  INDIRECT(1); BRANCH(1);
  if (self->frameOK) {

    INDIRECT(1); MOVE(1);
    self->pStreamInfo->Channels = aacChannels;
  }

  INDIRECT(1); LOGIC(1); STORE(1);
  self->frameOK = self->frameOK && frameOK;

  /*
    Inverse transform
  */
  PTR_INIT(3); /* self->pAacDecoderStaticChannelInfo[ch]
                  self->pAacDecoderChannelInfo[ch]
                  self->pTimeData[ch*MaximumBinsLong]
               */
  INDIRECT(1); LOOP(1);
  for (ch=0; ch<self->pStreamInfo->Channels; ch++) {

    /*
      Conceal erred spectral data 
    */
    FUNC(3);
    CConcealment_Apply(self->pAacDecoderStaticChannelInfo[ch],
                       self->pAacDecoderChannelInfo[ch],
                       self->frameOK);
  
  
    PTR_INIT(1); FUNC(1); BRANCH(1);
    if (IsLongBlock(&self->pAacDecoderChannelInfo[ch]->IcsInfo))
    {
      PTR_INIT(1); FUNC(4);
      CLongBlock_FrequencyToTime(self->pAacDecoderStaticChannelInfo[ch],
                                 self->pAacDecoderChannelInfo[ch],
                                 &self->pTimeData[ch*MaximumBinsLong],
                                 1);
    }
    else
    {
      PTR_INIT(1); FUNC(4);
      CShortBlock_FrequencyToTime(self->pAacDecoderStaticChannelInfo[ch],
                                  self->pAacDecoderChannelInfo[ch],
                                  &self->pTimeData[ch*MaximumBinsLong],
                                  1);
    }
  }


  INDIRECT(1); PTR_INIT(1); FUNC(2);
  ByteAlign(bs,&self->byteAlignBits);

  INDIRECT(3); MOVE(3);
  *frameSize = self->pStreamInfo->SamplesPerFrame;
  *sampleRate = self->pStreamInfo->SamplingRate;
  *numChannels = self->pStreamInfo->Channels;

  ADD(1); BRANCH(1);
  if (*numChannels == 1)
  {
    MOVE(1);
    *channelMode = 0;
  }
  else {
    BRANCH(1); MOVE(1);
    if (*numChannels == 2)
      *channelMode = 1;
    else
      *channelMode = 2;
  }

  ADD(1);
  BlockNumber++;

  COUNT_sub_end();

  return ErrorStatus;
}
Example #11
0
int
WritePsData (HANDLE_PS_ENC h_ps_e,
             int           bHeaderActive)
{
  int temp, gr;
  const int *aaHuffBookIidC;
  const short *aaHuffBookIccC;
  const char *aaHuffBookIidL;
  const char *aaHuffBookIccL;
  int *aaDeltaIid;
  int *aaDeltaIcc;

  int index, lastIndex;
  int noBitsF = 0;
  int noBitsT = 0;

  int aaDeltaIidT[NO_IID_BINS];
  int aaDeltaIccT[NO_ICC_BINS];

  int aaDeltaIidF[NO_IID_BINS];
  int aaDeltaIccF[NO_ICC_BINS];

  int abDtFlagIid;
  int abDtFlagIcc;

  int bSendHeader;

  unsigned int bZeroIid = 1;
  unsigned int bZeroIcc = 1;
  unsigned int bKeepParams = 1;

  HANDLE_BIT_BUF bb = &h_ps_e->psBitBuf;

  COUNT_sub_start("WritePsData");

  INDIRECT(1); MOVE(6); PTR_INIT(1); /* counting previous operations */

  FUNC(1);
  temp = GetBitsAvail(bb);

  /* bit buffer shall be empty */
  BRANCH(1);
  if (temp != 0)
  {
    COUNT_sub_end();
    return -1;
  }

  BRANCH(1);
  if (bHeaderActive) {

    MOVE(1);
    bKeepParams = 0;
  }

  MOVE(1);
  lastIndex = 0;

  PTR_INIT(3); /* h_ps_e->aaaIIDDataBuffer[][]
                  h_ps_e->aaaICCDataBuffer[][]
                  h_ps_e->aLastIidIndex[]
               */
  INDIRECT(1); LOOP(1);
  for (gr = 0; gr < h_ps_e->iidIccBins; gr++) {
    float panValue = h_ps_e->aaaIIDDataBuffer[gr][SYSTEMLOOKAHEAD];

    MOVE(1); /* counting previous operation */

    ADD(2); BRANCH(1);
    if (panValue >= -panClass[0] &&
        panValue <=  panClass[0]) {

      MOVE(1);
      index = 0;
    }
    else  {

      BRANCH(1);
      if (panValue < 0) {

        PTR_INIT(1); /* panClass[] */
        LOOP(1);
        for (index = NO_IID_STEPS-1; panValue > -panClass[index]; index--) {
          ADD(1); /* for() condition */
        }

        ADD(1);
        index = -index - 1;
      }
      else  {
        PTR_INIT(1); /* panClass[] */
        LOOP(1);
        for (index = NO_IID_STEPS-1; panValue <  panClass[index]; index--) {
          ADD(1); /* for() condition */
        }

        ADD(1);
        index++;
      }

      MOVE(1);
      bZeroIid = 0;
    }

    BRANCH(1);
    if (gr == 0) {

      MOVE(2);
      aaDeltaIidF[gr] = index;
      noBitsT = 0;

      INDIRECT(1); MOVE(1);
      noBitsF = aBookPsIidFreqLength[index + CODE_BOOK_LAV_IID];
    }
    else {

      ADD(1); STORE(1);
      aaDeltaIidF[gr] = index - lastIndex;

      INDIRECT(1); ADD(1);
      noBitsF += aBookPsIidFreqLength[aaDeltaIidF[gr] + CODE_BOOK_LAV_IID];
    }

    MOVE(1);
    lastIndex = index;

    ADD(1); STORE(1);
    aaDeltaIidT[gr] = index - h_ps_e->aLastIidIndex[gr];

    MOVE(1);
    h_ps_e->aLastIidIndex[gr] = index;

    INDIRECT(1); ADD(1);
    noBitsT += aBookPsIidTimeLength[aaDeltaIidT[gr] + CODE_BOOK_LAV_IID];

    BRANCH(1);
    if (aaDeltaIidT[gr] != 0) {

      MOVE(1);
      bKeepParams = 0;
    }
  } /* gr */

  ADD(1); LOGIC(1); BRANCH(1);
  if (noBitsT < noBitsF && !bHeaderActive) {

    MOVE(4);
    abDtFlagIid    = 1;
    aaDeltaIid     = aaDeltaIidT;
    aaHuffBookIidC = aBookPsIidTimeCode;
    aaHuffBookIidL = aBookPsIidTimeLength;
  }
  else  {

    MOVE(4);
    abDtFlagIid    = 0;
    aaDeltaIid     = aaDeltaIidF;
    aaHuffBookIidC = aBookPsIidFreqCode;
    aaHuffBookIidL = aBookPsIidFreqLength;
  }

  MOVE(1);
  lastIndex = 0;

  PTR_INIT(4); /* h_ps_e->aaaICCDataBuffer[][]
                  h_ps_e->aLastIccIndex[]
                  aaDeltaIccF[]
                  aaDeltaIccT[]
               */
  INDIRECT(1); LOOP(1);
  for (gr = 0; gr < h_ps_e->iidIccBins; gr++) {

    float saValue = h_ps_e->aaaICCDataBuffer[gr][SYSTEMLOOKAHEAD];

    MOVE(1); /* counting previous operation */

    ADD(1); BRANCH(1);
    if (saValue <= saClass[0]) {

      MOVE(1);
      index = 0;
    }
    else  {
      PTR_INIT(1); /* saClass[] */
      LOOP(1);
      for (index = NO_ICC_STEPS-2;  saValue < saClass[index]; index--) {
        ADD(1); /* for() condition */
      }

      ADD(1);
      index++;

      MOVE(1);
      bZeroIcc = 0;
    }

    BRANCH(1);
    if (gr == 0) {

      MOVE(1);
      aaDeltaIccF[gr] = index;

      INDIRECT(1); MOVE(1);
      noBitsF = aBookPsIccFreqLength[index + CODE_BOOK_LAV_ICC];

      MOVE(1);
      noBitsT = 0;
    }
    else  {
      ADD(1); STORE(1);
      aaDeltaIccF[gr] = index - lastIndex;

      INDIRECT(1); ADD(1);
      noBitsF += aBookPsIccFreqLength[aaDeltaIccF[gr] + CODE_BOOK_LAV_ICC];
    }

    MOVE(1);
    lastIndex = index;

    ADD(1); STORE(1);
    aaDeltaIccT[gr] = index - h_ps_e->aLastIccIndex[gr];

    MOVE(1);
    h_ps_e->aLastIccIndex[gr] = index;

    INDIRECT(1); ADD(1);
    noBitsT += aBookPsIccTimeLength[aaDeltaIccT[gr] + CODE_BOOK_LAV_ICC];

    BRANCH(1);
    if (aaDeltaIccT[gr] != 0) {

      MOVE(1);
      bKeepParams = 0;
    }
  } /* gr */

  ADD(1); LOGIC(1); BRANCH(1);
  if (noBitsT < noBitsF && !bHeaderActive) {

    MOVE(4);
    abDtFlagIcc    = 1;
    aaDeltaIcc     = aaDeltaIccT;
    aaHuffBookIccC = aBookPsIccTimeCode;
    aaHuffBookIccL = aBookPsIccTimeLength;
  }
  else {

    MOVE(4);
    abDtFlagIcc    = 0;
    aaDeltaIcc     = aaDeltaIccF;
    aaHuffBookIccC = aBookPsIccFreqCode;
    aaHuffBookIccL = aBookPsIccFreqLength;
  }

  {
    static __thread int initheader = 0;

    MOVE(1); /* counting previous operation */

    LOGIC(1); BRANCH(1);
    if (!initheader || bHeaderActive) {

      INDIRECT(1); MOVE(2);
      initheader = 1;
      h_ps_e->bEnableHeader = 1;
    }
    else {

      INDIRECT(1); MOVE(1);
      h_ps_e->bEnableHeader = 0;
    }
  }

  INDIRECT(3); ADD(2); LOGIC(2);
  bSendHeader = h_ps_e->bEnableHeader            ||
                h_ps_e->bPrevZeroIid != bZeroIid ||
                h_ps_e->bPrevZeroIcc != bZeroIcc;

  FUNC(3);
  WriteBits (bb, bSendHeader, 1);

  BRANCH(1);
  if (bSendHeader) {

    LOGIC(1); FUNC(3);
    WriteBits (bb, !bZeroIid, 1);

    BRANCH(1);
    if (!bZeroIid)
    {
      BRANCH(1); FUNC(3);
      WriteBits (bb, (h_ps_e->bHiFreqResIidIcc)?1:0, 3);
    }

    LOGIC(1); FUNC(3);
    WriteBits (bb, !bZeroIcc, 1);

    BRANCH(1);
    if (!bZeroIcc)
    {
      BRANCH(1); FUNC(3);
      WriteBits (bb, (h_ps_e->bHiFreqResIidIcc)?1:0, 3);
    }

    FUNC(3);
    WriteBits (bb, 0, 1);
  }

  FUNC(3);
  WriteBits (bb, 0, 1);

  ADD(1); FUNC(3);
  WriteBits (bb, 1-bKeepParams, 2);

  PTR_INIT(1); /* h_ps_e->iidIccBins
                */
  BRANCH(1);
  if (!bKeepParams) {

    LOGIC(1); BRANCH(1);
    if (!bZeroIid) {

      FUNC(3);
      WriteBits (bb, abDtFlagIid, 1);

      LOOP(1);
      for (gr = 0; gr < h_ps_e->iidIccBins; gr++) {

        INDIRECT(2); FUNC(3);
        WriteBits (bb,
                   aaHuffBookIidC[aaDeltaIid[gr] + CODE_BOOK_LAV_IID],
                   aaHuffBookIidL[aaDeltaIid[gr] + CODE_BOOK_LAV_IID]);
      } /* gr */
    }  /* if (!bZeroIid) */
  }

  PTR_INIT(1); /* h_ps_e->iidIccBins
               */
  BRANCH(1);
  if (!bKeepParams) {

    LOGIC(1); BRANCH(1);
    if (!bZeroIcc) {

      FUNC(3);
      WriteBits (bb, abDtFlagIcc, 1);

      LOOP(1);
      for (gr = 0; gr < h_ps_e->iidIccBins; gr++) {

        INDIRECT(2); FUNC(3);
        WriteBits (bb,
                   aaHuffBookIccC[aaDeltaIcc[gr] + CODE_BOOK_LAV_ICC],
                   aaHuffBookIccL[aaDeltaIcc[gr] + CODE_BOOK_LAV_ICC]);
      } /* gr */
    }  /* if (!bZeroIcc) */
  }

  INDIRECT(2); MOVE(2);
  h_ps_e->bPrevZeroIid = bZeroIid;
  h_ps_e->bPrevZeroIcc = bZeroIcc;

  FUNC(1); /* counting post-operation */

  COUNT_sub_end();

  return  GetBitsAvail(bb);

} /* writePsData */
Example #12
0
static void allowMoreHoles(PSY_OUT_CHANNEL  psyOutChannel[MAX_CHANNELS], 
                           PSY_OUT_ELEMENT *psyOutElement,
                           PE_DATA *peData, 
                           int ahFlag[MAX_CHANNELS][MAX_GROUPED_SFB],
                           const AH_PARAM *ahParam,
                           const int nChannels,
                           const float desiredPe)
{
  int ch, sfb;
  float actPe;

  COUNT_sub_start("allowMoreHoles");

  INDIRECT(1); MOVE(1);
  actPe = peData->pe;

  ADD(2); LOGIC(1); BRANCH(1);
  if (nChannels==2 &&
      psyOutChannel[0].windowSequence==psyOutChannel[1].windowSequence) {
    PSY_OUT_CHANNEL *psyOutChanL = &psyOutChannel[0];
    PSY_OUT_CHANNEL *psyOutChanR = &psyOutChannel[1];

    PTR_INIT(2); /* counting previous operations */

    PTR_INIT(11); /* pointers for ahFlag[0][sfb],
                                  ahFlag[1][sfb],
                                  psyOutElement->toolsInfo.msMask[sfb],
                                  psyOutChanL->sfbMinSnr[sfb],
                                  psyOutChanR->sfbMinSnr[sfb],
                                  psyOutChanL->sfbEnergy[sfb],
                                  psyOutChanR->sfbEnergy[sfb],
                                  psyOutChanL->sfbThreshold[sfb],
                                  psyOutChanR->sfbThreshold[sfb],
                                  peData->peChannelData[0].sfbPe[sfb],
                                  peData->peChannelData[1].sfbPe[sfb]
                  */
    INDIRECT(1); LOOP(1);
    for (sfb=0; sfb<psyOutChanL->sfbCnt; sfb++) {

      BRANCH(1);
      if (psyOutElement->toolsInfo.msMask[sfb]) {

        ADD(2); MULT(2); LOGIC(1); BRANCH(1);
        if (ahFlag[1][sfb] != NO_AH &&
            0.4f*psyOutChanL->sfbMinSnr[sfb]*psyOutChanL->sfbEnergy[sfb] >
            psyOutChanR->sfbEnergy[sfb]) {

          MOVE(1);
          ahFlag[1][sfb] = NO_AH;

          MULT(1); STORE(1);
          psyOutChanR->sfbThreshold[sfb] = 2.0f * psyOutChanR->sfbEnergy[sfb];

          ADD(1);
          actPe -= peData->peChannelData[1].sfbPe[sfb];
        }
        else {
          ADD(2); MULT(2); LOGIC(1); BRANCH(1);
          if (ahFlag[0][sfb] != NO_AH &&
            0.4f*psyOutChanR->sfbMinSnr[sfb]*psyOutChanR->sfbEnergy[sfb] >
            psyOutChanL->sfbEnergy[sfb]) {

          MOVE(1);
          ahFlag[0][sfb] = NO_AH;

          MULT(1); STORE(1);
          psyOutChanL->sfbThreshold[sfb] = 2.0f * psyOutChanL->sfbEnergy[sfb];

          ADD(1);
          actPe -= peData->peChannelData[0].sfbPe[sfb];
          }
        }
        ADD(1); BRANCH(1);
        if (actPe < desiredPe)
          break;
      }
    }
  }

  ADD(1); BRANCH(1);
  if (actPe > desiredPe) {
    int startSfb[2];
    float avgEn, minEn;
    int ahCnt;
    int enIdx;
    float en[4];
    int minSfb, maxSfb;
    int done;

    PTR_INIT(2); /* pointers for psyOutChannel[ch].windowSequence,
                                 startSfb[ch]
                 */
    LOOP(1);
    for (ch=0; ch<nChannels; ch++) {

      ADD(1); BRANCH(1); INDIRECT(1); MOVE(1);
      if (psyOutChannel[ch].windowSequence != SHORT_WINDOW)
        startSfb[ch] = ahParam->startSfbL;
      else
        startSfb[ch] = ahParam->startSfbS;
    }

    MOVE(3);
    avgEn = 0.0f;
    minEn = FLT_MAX;
    ahCnt = 0;

    PTR_INIT(1); /* pointers for startSfb[ch] */
    LOOP(1);
    for (ch=0; ch<nChannels; ch++) {
      PSY_OUT_CHANNEL *psyOutChan = &psyOutChannel[ch];

      PTR_INIT(1); /* counting previous operation */

      PTR_INIT(4); /* pointers for ahFlag[ch][sfb],
                                   psyOutChan->sfbMinSnr[sfb],
                                   psyOutChan->sfbEnergy[sfb],
                                   psyOutChan->sfbThreshold[sfb],
                   */
      INDIRECT(1); LOOP(1);
      for (sfb=startSfb[ch]; sfb<psyOutChan->sfbCnt; sfb++){

        ADD(2); LOGIC(1); BRANCH(1);
        if ((ahFlag[ch][sfb]!=NO_AH) &&
            (psyOutChan->sfbEnergy[sfb] > psyOutChan->sfbThreshold[sfb])){

          ADD(1); BRANCH(1); MOVE(1);
          minEn = min(minEn, psyOutChan->sfbEnergy[sfb]);

          ADD(1);
          avgEn += psyOutChan->sfbEnergy[sfb];

          ADD(1);
          ahCnt++;
        }
      }
    }
    ADD(1); BRANCH(1); MOVE(1); /* min() */ ADD(1); DIV(1);
    avgEn = min ( FLT_MAX , avgEn /(ahCnt+FLT_MIN));

    /* calc some energy borders between minEn and avgEn */
    PTR_INIT(1); /* pointers for en[enIdx] */
    LOOP(1);
    for (enIdx=0; enIdx<4; enIdx++) {
      ADD(2); MULT(2); DIV(2); TRANS(1); STORE(1);
      en[enIdx] = minEn * (float)pow(avgEn/(minEn+FLT_MIN), (2*enIdx+1)/7.0f);
    }

    ADD(1);
    maxSfb = psyOutChannel[0].sfbCnt - 1;

    MOVE(1);
    minSfb = startSfb[0];

    ADD(1); BRANCH(1);
    if (nChannels==2) {

      ADD(2); BRANCH(1); MOVE(1);
      maxSfb = max(maxSfb, psyOutChannel[1].sfbCnt-1);

      ADD(1); BRANCH(1); MOVE(1);
      minSfb = min(minSfb, startSfb[1]);
    }

    MOVE(3);
    sfb = maxSfb;
    enIdx = 0;
    done = 0;

    LOOP(1);
    while (!done) {

      PTR_INIT(1); /* pointer for en[enIdx] */

      LOOP(1);
      for (ch=0; ch<nChannels; ch++) {
        PSY_OUT_CHANNEL *psyOutChan = &psyOutChannel[ch];

        PTR_INIT(1); /* counting previous operation */

        PTR_INIT(4); /* pointers for startSfb[ch]
                                     ahFlag[ch][sfb],
                                     psyOutChan->sfbEnergy[sfb],
                                     psyOutChan->sfbThreshold[sfb]
                     */

        INDIRECT(1); ADD(2); LOGIC(1); BRANCH(1);
        if (sfb>=startSfb[ch] && sfb < psyOutChan->sfbCnt) {

          ADD(2); LOGIC(1); BRANCH(1);
          if (ahFlag[ch][sfb] != NO_AH && psyOutChan->sfbEnergy[sfb] < en[enIdx]){
            
            MOVE(1);
            ahFlag[ch][sfb] = NO_AH;
            
            MULT(1); STORE(1);
            psyOutChan->sfbThreshold[sfb] = 2.0f * psyOutChan->sfbEnergy[sfb];
            
            ADD(1);
            actPe -= peData->peChannelData[ch].sfbPe[sfb];
          }

          ADD(1); BRANCH(1);
          if (actPe < desiredPe) {
            
            MOVE(1);
            done = 1;
            break;
          }
        }
      }
      ADD(1);
      sfb--;

      ADD(1); BRANCH(1);
      if (sfb < minSfb) {
        MOVE(1);
        sfb = maxSfb;

        ADD(1);
        enIdx++;

        ADD(1); BRANCH(1);
        if (enIdx >= 4) {

          MOVE(1);
          done = 1;
        }
      }
    }
  }

  COUNT_sub_end();
}
Example #13
0
static void correctThresh(PSY_OUT_CHANNEL  psyOutChannel[MAX_CHANNELS],
                          int ahFlag[MAX_CHANNELS][MAX_GROUPED_SFB],
                          PE_DATA *peData,
                          float thrExp[MAX_CHANNELS][MAX_GROUPED_SFB],
                          const float redVal,
                          const int nChannels,
                          const float deltaPe)
{
   int ch, sfb,sfbGrp;
   PSY_OUT_CHANNEL *psyOutChan;
   PE_CHANNEL_DATA *peChanData;
   float deltaSfbPe;
   float thrFactor;
   float sfbPeFactors[MAX_CHANNELS][MAX_GROUPED_SFB], normFactor;
   float sfbEn, sfbThr, sfbThrReduced;

   COUNT_sub_start("correctThresh");

   /* for each sfb calc relative factors for pe changes */
   MOVE(1);
   normFactor = FLT_MIN; /* to avoid division by zero */

   LOOP(1);
   for(ch=0; ch<nChannels; ch++) {
      psyOutChan = &psyOutChannel[ch];
      peChanData = &peData->peChannelData[ch];

      INDIRECT(1); PTR_INIT(2); /* counting previous operations */

      INDIRECT(2); LOOP(1);
      for(sfbGrp = 0;sfbGrp < psyOutChan->sfbCnt;sfbGrp+= psyOutChan->sfbPerGroup){

        PTR_INIT(4); /* pointers for ahFlag[ch][sfbGrp+sfb],
                                     thrExp[ch][sfbGrp+sfb],
                                     sfbPeFactors[ch][sfbGrp+sfb],
                                     peChanData->sfbNActiveLines[sfbGrp+sfb]
                     */
        INDIRECT(1); LOOP(1);
        for (sfb=0; sfb<psyOutChan->maxSfbPerGroup; sfb++) {

         ADD(1); LOGIC(1); BRANCH(1);
         if ((ahFlag[ch][sfbGrp+sfb] < AH_ACTIVE) || (deltaPe > 0)) {

            ADD(1); DIV(1); STORE(1);
            sfbPeFactors[ch][sfbGrp+sfb] = peChanData->sfbNActiveLines[sfbGrp+sfb] /
                                              (thrExp[ch][sfbGrp+sfb] + redVal);

            ADD(1);
            normFactor += sfbPeFactors[ch][sfbGrp+sfb];
         }
         else {
            MOVE(1);
            sfbPeFactors[ch][sfbGrp+sfb] = 0.0f;
         }
        }
      }
   }

   DIV(1);
   normFactor = 1.0f/normFactor;

   LOOP(1);
   for(ch=0; ch<nChannels; ch++) {
      psyOutChan = &psyOutChannel[ch];
      peChanData = &peData->peChannelData[ch];

      INDIRECT(1); PTR_INIT(2); /* counting previous operations */

      INDIRECT(2); LOOP(1);
      for(sfbGrp = 0;sfbGrp < psyOutChan->sfbCnt;sfbGrp+= psyOutChan->sfbPerGroup){

        PTR_INIT(6); /* pointers for ahFlag[ch][sfbGrp+sfb],
                                     sfbPeFactors[ch][sfbGrp+sfb],
                                     psyOutChan->sfbMinSnr[sfbGrp+sfb],
                                     peChanData->sfbNActiveLines[sfbGrp+sfb],
                                     psyOutChan->sfbEnergy[sfbGrp+sfb],
                                     psyOutChan->sfbThreshold[sfbGrp+sfb]
                     */
        INDIRECT(1); LOOP(1);
        for (sfb=0; sfb<psyOutChan->maxSfbPerGroup; sfb++) {

         /* pe difference for this sfb */
         MULT(2);
         deltaSfbPe = sfbPeFactors[ch][sfbGrp+sfb] * normFactor * deltaPe;

         ADD(1); BRANCH(1);
         if (peChanData->sfbNActiveLines[sfbGrp+sfb] > (float)0.5f) {

            /* new threshold */
            MOVE(2);
            sfbEn  = psyOutChan->sfbEnergy[sfbGrp+sfb];
            sfbThr = psyOutChan->sfbThreshold[sfbGrp+sfb];

            MULT(1); DIV(1); ADD(1); BRANCH(1); MOVE(1);
            thrFactor = min(-deltaSfbPe/peChanData->sfbNActiveLines[sfbGrp+sfb],20.f);

            TRANS(1);
            thrFactor = (float) pow(2.0f,thrFactor);

            MULT(1);
            sfbThrReduced = sfbThr * thrFactor;
            /* avoid hole */

            MULT(1); ADD(2); BRANCH(1);
            if ((sfbThrReduced > psyOutChan->sfbMinSnr[sfbGrp+sfb] * sfbEn) &&
                (ahFlag[ch][sfbGrp+sfb] == AH_INACTIVE)) {

               ADD(1); BRANCH(1); MOVE(1);
               sfbThrReduced = max(psyOutChan->sfbMinSnr[sfbGrp+sfb] * sfbEn, sfbThr);

               MOVE(1);
               ahFlag[ch][sfbGrp+sfb] = AH_ACTIVE;
            }

            MOVE(1);
            psyOutChan->sfbThreshold[sfbGrp+sfb] = sfbThrReduced;
         }
        }
      }
   }

   COUNT_sub_end();
}
Example #14
0
/* determine bands where avoid hole is not necessary resp. possible */
static void initAvoidHoleFlag(int ahFlag[MAX_CHANNELS][MAX_GROUPED_SFB],
                              PSY_OUT_CHANNEL  psyOutChannel[MAX_CHANNELS],
                              PSY_OUT_ELEMENT* psyOutElement,
                              const int nChannels,
                              AH_PARAM *ahParam)
{
  int ch, sfb,sfbGrp;
  float sfbEn;
  float scaleSprEn;

  COUNT_sub_start("initAvoidHoleFlag");
  
  /* decrease spreaded energy by 3dB for long blocks, resp. 2dB for shorts
     (avoid more holes in long blocks) */
  LOOP(1);
  for (ch=0; ch<nChannels; ch++) {
    PSY_OUT_CHANNEL *psyOutChan = &psyOutChannel[ch];
    
    PTR_INIT(1); /* counting operation above */
    
    INDIRECT(1); ADD(1); BRANCH(1);
    if (psyOutChan->windowSequence != SHORT_WINDOW) {
      
      MOVE(1);
      scaleSprEn = 0.5f;
    }
    else {
      
      MOVE(1);
      scaleSprEn = 0.63f;
    }
    
    INDIRECT(2); LOOP(1);
    for(sfbGrp = 0;sfbGrp < psyOutChan->sfbCnt;sfbGrp+= psyOutChan->sfbPerGroup){
      
      PTR_INIT(1); /* pointer for psyOutChan->sfbSpreadedEnergy[] */
      LOOP(1);
      for (sfb=0; sfb<psyOutChan->maxSfbPerGroup; sfb++) {

        MULT(1); STORE(1);
        psyOutChan->sfbSpreadedEnergy[sfbGrp+sfb] *= scaleSprEn;
      }
    }
  }


  /* increase minSnr for local peaks, decrease it for valleys */
  
  INDIRECT(1); BRANCH(1);
  if (ahParam->modifyMinSnr) {
    
    LOOP(1);
    for(ch=0; ch<nChannels; ch++) {
      PSY_OUT_CHANNEL *psyOutChan = &psyOutChannel[ch];
      
      PTR_INIT(1); /* counting operation above */
      
      INDIRECT(2); LOOP(1);
      for(sfbGrp = 0;sfbGrp < psyOutChan->sfbCnt;sfbGrp+= psyOutChan->sfbPerGroup){
        
        PTR_INIT(3); /* pointers for psyOutChan->sfbEnergy[sfbGrp],
                        psyOutChan->sfbEnergy[sfbGrp+sfb],
                        psyOutChan->sfbMinSnr[]
                     */
        INDIRECT(1); LOOP(1);
        for (sfb=0; sfb<psyOutChan->maxSfbPerGroup; sfb++) {
          float sfbEnm1, sfbEnp1, avgEn;
          
          BRANCH(1); MOVE(1);
          if (sfb > 0)
            sfbEnm1 = psyOutChan->sfbEnergy[sfbGrp+sfb-1];
          else
            sfbEnm1 = psyOutChan->sfbEnergy[sfbGrp];
          
          INDIRECT(1); ADD(2); BRANCH(1); MOVE(1);
          if (sfb < psyOutChan->maxSfbPerGroup-1)
            sfbEnp1 = psyOutChan->sfbEnergy[sfbGrp+sfb+1];
          else
            sfbEnp1 = psyOutChan->sfbEnergy[sfbGrp+sfb];
          
          ADD(1); MULT(1);
          avgEn = (sfbEnm1 + sfbEnp1)/(float)2.0f;
          
          MOVE(1);
          sfbEn = psyOutChan->sfbEnergy[sfbGrp+sfb];
          
          /* peak ? */
          ADD(1); BRANCH(1);
          if (sfbEn > avgEn) {
            float tmpMinSnr = max((float)0.8f*avgEn/sfbEn,
                                  (float)0.316f);
            
            MULT(1); DIV(1); ADD(1); BRANCH(1); MOVE(1); /* counting previous operation */
            
            INDIRECT(1); ADD(1); BRANCH(1); /* if() */ ADD(1); BRANCH(1); MOVE(1); /* max() */
            if (psyOutChan->windowSequence!=SHORT_WINDOW)
              tmpMinSnr = max(tmpMinSnr, (float)0.316f);
            else
              tmpMinSnr = max(tmpMinSnr, (float)0.5f);
            
            ADD(1); BRANCH(1); MOVE(1);
            psyOutChan->sfbMinSnr[sfbGrp+sfb] =
              min(psyOutChan->sfbMinSnr[sfbGrp+sfb], tmpMinSnr);
          }
          
          /* valley ? */
          MULT(1); ADD(1); LOGIC(1); BRANCH(1);
          if (((float)2.0f*sfbEn < avgEn) && (sfbEn > (float)0.0f)) {
            float tmpMinSnr = avgEn/((float)2.0f*sfbEn) *
              psyOutChan->sfbMinSnr[sfbGrp+sfb];
            
            MULT(2); DIV(1); /* counting previous operation */
            
            ADD(1); BRANCH(1); MOVE(1);
            tmpMinSnr = min((float)0.8f, tmpMinSnr);
            
            MULT(1); ADD(1); BRANCH(1); MOVE(1);
            psyOutChan->sfbMinSnr[sfbGrp+sfb] = min(tmpMinSnr,
                                                    psyOutChan->sfbMinSnr[sfbGrp+sfb]*(float)3.16f);
          }
        }
      }
    }
  }
  
  ADD(1); BRANCH(1);
  if (nChannels == 2) {
    PSY_OUT_CHANNEL *psyOutChanM = &psyOutChannel[0];
    PSY_OUT_CHANNEL *psyOutChanS = &psyOutChannel[1];
    
    PTR_INIT(2); /* counting previous operation */
    
    PTR_INIT(7); /* pointers for psyOutElement->toolsInfo.msMask[],
                    psyOutChanM->sfbEnergy[],
                    psyOutChanS->sfbEnergy[],
                    psyOutChanM->sfbMinSnr[],
                    psyOutChanS->sfbMinSnr[],
                    psyOutChanM->sfbSpreadedEnergy[],
                    psyOutChanS->sfbSpreadedEnergy[]
                 */
    INDIRECT(1); LOOP(1);
    for (sfb=0; sfb<psyOutChanM->sfbCnt; sfb++) {
      
      BRANCH(1);
      if (psyOutElement->toolsInfo.msMask[sfb]) {
        float sfbEnM = psyOutChanM->sfbEnergy[sfb];
        float sfbEnS = psyOutChanS->sfbEnergy[sfb];
        float maxSfbEn = max(sfbEnM, sfbEnS);
        float maxThr = 0.25f * psyOutChanM->sfbMinSnr[sfb] * maxSfbEn;
        
        ADD(1); BRANCH(1); MOVE(1); /* max() */ MOVE(2); MULT(2); /* counting previous operations */
        
        ADD(1); DIV(1); ADD(1); BRANCH(1); MOVE(1); /* min() */ ADD(1); BRANCH(1); MOVE(1); /* max() */
        psyOutChanM->sfbMinSnr[sfb] = (float)max(psyOutChanM->sfbMinSnr[sfb],
                                                 min ( FLT_MAX, ((double)maxThr/(FLT_MIN+(double)sfbEnM))));
        
        ADD(1); BRANCH(1);
        if (psyOutChanM->sfbMinSnr[sfb] <= 1.0f) {
          
          ADD(1); BRANCH(1); MOVE(1);
          psyOutChanM->sfbMinSnr[sfb] = min(psyOutChanM->sfbMinSnr[sfb], 0.8f);
        }
        
        ADD(1); DIV(1); ADD(1); BRANCH(1); MOVE(1); /* min() */ ADD(1); BRANCH(1); MOVE(1); /* max() */       
        psyOutChanS->sfbMinSnr[sfb] = (float)max(psyOutChanS->sfbMinSnr[sfb],
                                                 min ( FLT_MAX, ((double)maxThr/(FLT_MIN+(double)sfbEnS))));
        
        ADD(1); BRANCH(1);
        if (psyOutChanS->sfbMinSnr[sfb] <= 1.0f) {
          
          ADD(1); BRANCH(1); MOVE(1);
          psyOutChanS->sfbMinSnr[sfb] = min(psyOutChanS->sfbMinSnr[sfb], 0.8f);
        }
        
        ADD(1); BRANCH(1);
        if (sfbEnM > psyOutChanM->sfbSpreadedEnergy[sfb]) {
          
          MULT(1); STORE(1);
          psyOutChanS->sfbSpreadedEnergy[sfb] = 0.9f * sfbEnS;
        }
        
        ADD(1); BRANCH(1);
        if (sfbEnS > psyOutChanS->sfbSpreadedEnergy[sfb]) {
          
          MULT(1); STORE(1);
          psyOutChanM->sfbSpreadedEnergy[sfb] = 0.9f * sfbEnM;
        }
      }
    }
  }
  
  
  /* init ahFlag (0: no ah necessary, 1: ah possible, 2: ah active */
  LOOP(1);
  for(ch=0; ch<nChannels; ch++) {
    PSY_OUT_CHANNEL *psyOutChan = &psyOutChannel[ch];
    
    PTR_INIT(1); /* counting previous operation */
    
    INDIRECT(2); LOOP(1);
    for(sfbGrp = 0;sfbGrp < psyOutChan->sfbCnt;sfbGrp+= psyOutChan->sfbPerGroup){
      
      PTR_INIT(4); /* pointers for psyOutChan->sfbEnergy[],
                      psyOutChan->sfbMinSnr[],
                      psyOutChan->sfbSpreadedEnergy[],
                      ahFlag[][]
                   */
      INDIRECT(1); LOOP(1);
      for (sfb=0; sfb<psyOutChan->maxSfbPerGroup; sfb++) {
        
        ADD(2); LOGIC(1); BRANCH(1);
        if (psyOutChan->sfbSpreadedEnergy[sfbGrp+sfb] > psyOutChan->sfbEnergy[sfbGrp+sfb] ||
            psyOutChan->sfbMinSnr[sfbGrp+sfb] > (float)1.0) {
          
          MOVE(1);
          ahFlag[ch][sfbGrp+sfb] = NO_AH;
        }
        else {
          
          MOVE(1);
          ahFlag[ch][sfbGrp+sfb] = AH_INACTIVE;
        }
      }
      
      PTR_INIT(1); /* pointer for ahFlag[][] */
      INDIRECT(2); LOOP(1);
      for (sfb=psyOutChan->maxSfbPerGroup; sfb<psyOutChan->sfbPerGroup; sfb++) {
        
        MOVE(1);
        ahFlag[ch][sfbGrp+sfb] = NO_AH;
      }
    }
  }
  
  COUNT_sub_end();
}
Example #15
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);
}
Example #16
0
int
CreateHybridFilterBank_dec ( HANDLE_HYBRID *phHybrid,
                         int noBands,
                         const int *pResolution,
                         float **pPtr)
{
  int i;
  int maxNoChannels = 0;
  HANDLE_HYBRID hs;
  float *ptr = *pPtr;

  FLC_sub_start("CreateHybridFilterBank_dec");

  MOVE(1); PTR_INIT(1); /* counting previous operations */

  PTR_INIT(1);
  *phHybrid = NULL;

  PTR_INIT(1); ADD(1);
  hs = (HANDLE_HYBRID)ptr;ptr+=sizeof(HYBRID)/sizeof(float);

  INDIRECT(1); PTR_INIT(1); MULT(1); ADD(1);
  hs->pResolution = (int*)ptr;ptr+=noBands * sizeof (int)/sizeof(float);

  PTR_INIT(2); /* hs->pResolution[i]
                  pResolution[i]
               */
  LOOP(1);
  for (i = 0; i < noBands; i++) {

    MOVE(1);
    hs->pResolution[i] = pResolution[i];

    ADD(3); LOGIC(2); BRANCH(1);
    if( pResolution[i] != HYBRID_8_CPLX &&
        pResolution[i] != HYBRID_2_REAL &&
        pResolution[i] != HYBRID_4_CPLX )
    {
      FLC_sub_end();
      return 1;
    }

    ADD(1); BRANCH(1);
    if(pResolution[i] > maxNoChannels)
    {
      MOVE(1);
      maxNoChannels = pResolution[i];
    }
  }

  INDIRECT(2); MOVE(2);
  hs->nQmfBands     = noBands;
  hs->qmfBufferMove = HYBRID_FILTER_LENGTH - 1;

  INDIRECT(3); PTR_INIT(2); ADD(4);
  hs->pWorkReal = ptr;ptr+= 1 + hs->qmfBufferMove;
  hs->pWorkImag = ptr;ptr+= 1 + hs->qmfBufferMove;

  INDIRECT(2); PTR_INIT(2); MULT(2); ADD(2);
  hs->mQmfBufferReal = (float **)ptr;ptr+= noBands * sizeof (float *)/sizeof(float);
  hs->mQmfBufferImag = (float **)ptr;ptr+= noBands * sizeof (float *)/sizeof(float);

  PTR_INIT(2); /* hs->mQmfBufferReal[i]
                  hs->mQmfBufferImag[i]
               */
  INDIRECT(1);
  LOOP(1);
  for (i = 0; i < noBands; i++) {

    PTR_INIT(1); ADD(1);
    hs->mQmfBufferReal[i] = ptr;ptr+= hs->qmfBufferMove;

    FUNC(3); LOOP(1); INDIRECT(2); PTR_INIT(1); MOVE(1); STORE(hs->qmfBufferMove);
    memset(hs->mQmfBufferReal[i],0,hs->qmfBufferMove*sizeof(float));

    PTR_INIT(1); ADD(1);
    hs->mQmfBufferImag[i] = ptr;ptr+= hs->qmfBufferMove;

    FUNC(3); LOOP(1); INDIRECT(2); PTR_INIT(1); MOVE(1); STORE(hs->qmfBufferMove);
    memset(hs->mQmfBufferImag[i],0,hs->qmfBufferMove*sizeof(float));
  }

  PTR_INIT(1); ADD(1);
  hs->mTempReal = ptr;ptr+= maxNoChannels;

  FUNC(3); LOOP(1); INDIRECT(2); PTR_INIT(1); MOVE(1); STORE(maxNoChannels);
  memset(hs->mTempReal,0,maxNoChannels*sizeof(float));

  PTR_INIT(1); ADD(1);
  hs->mTempImag = ptr;ptr+= maxNoChannels;

  FUNC(3); LOOP(1); INDIRECT(2); PTR_INIT(1); MOVE(1); STORE(maxNoChannels);
  memset(hs->mTempImag,0,maxNoChannels*sizeof(float));

  PTR_INIT(2);
  *phHybrid = hs;
  *pPtr = ptr;

  FLC_sub_end();

  return 0;
}
Example #17
0
void
HybridAnalysis_dec ( const float **mQmfReal,
                 const float **mQmfImag,
                 float **mHybridReal,
                 float **mHybridImag,
                 HANDLE_HYBRID hHybrid )

{
  int band, oddQmf;
  HYBRID_RES hybridRes;
  int  chOffset = 0;

  FLC_sub_start("HybridAnalysis");

  INDIRECT(1); MOVE(1);
  MOVE(1);

  INDIRECT(1); LOOP(1);
  for(band = 0; band < hHybrid->nQmfBands; band++) {

    LOGIC(1);
    oddQmf = (band & 1);

    INDIRECT(1); MOVE(1);
    hybridRes = (HYBRID_RES)hHybrid->pResolution[band];

    INDIRECT(1); MULT(1);
    FUNC(3); LOOP(1); INDIRECT(2); PTR_INIT(2); MOVE(1); STORE(hHybrid->qmfBufferMove - 1);
    memcpy(hHybrid->pWorkReal, hHybrid->mQmfBufferReal[band],
           hHybrid->qmfBufferMove * sizeof(float));

    FUNC(3); LOOP(1); INDIRECT(2); PTR_INIT(2); MOVE(1); STORE(hHybrid->qmfBufferMove - 1);
    memcpy(hHybrid->pWorkImag, hHybrid->mQmfBufferImag[band],
           hHybrid->qmfBufferMove * sizeof(float));

    PTR_INIT(4);MOVE(2);
    hHybrid->pWorkReal [hHybrid->qmfBufferMove] = mQmfReal [HYBRID_FILTER_DELAY] [band];
    hHybrid->pWorkImag [hHybrid->qmfBufferMove] = mQmfImag [HYBRID_FILTER_DELAY] [band];

    FUNC(3); LOOP(1); INDIRECT(2); PTR_INIT(2); MOVE(1); STORE(hHybrid->qmfBufferMove - 1);
    memcpy(hHybrid->mQmfBufferReal[band], hHybrid->pWorkReal + 1,
           hHybrid->qmfBufferMove * sizeof(float));

    FUNC(3); LOOP(1); INDIRECT(2); PTR_INIT(2); MOVE(1); STORE(hHybrid->qmfBufferMove - 1);
    memcpy(hHybrid->mQmfBufferImag[band], hHybrid->pWorkImag + 1,
           hHybrid->qmfBufferMove * sizeof(float));

    switch(hybridRes) {
    case HYBRID_2_REAL:
      ADD(1); BRANCH(1);

      FUNC(2);
      twoChannelFiltering( hHybrid->pWorkReal,
                           hHybrid->mTempReal );

      FUNC(2);
      twoChannelFiltering( hHybrid->pWorkImag,
                           hHybrid->mTempImag );

      PTR_INIT(4);
      MOVE(4);
      mHybridReal [0] [chOffset] = hHybrid->mTempReal [0];
      mHybridImag [0] [chOffset] = hHybrid->mTempImag [0];
      mHybridReal [0] [chOffset + 1] = hHybrid->mTempReal [1];
      mHybridImag [0] [chOffset + 1] = hHybrid->mTempImag [1];

      ADD(1);
      chOffset += 2;

      break;
    case HYBRID_8_CPLX:
      ADD(1); BRANCH(1);

      FUNC(4);
      eightChannelFiltering( hHybrid->pWorkReal,
                             hHybrid->pWorkImag,
                             hHybrid->mTempReal,
                             hHybrid->mTempImag );

      PTR_INIT(4);
      MOVE(12); ADD(4);
      mHybridReal [0] [chOffset + 0] = hHybrid->mTempReal [0];
      mHybridImag [0] [chOffset + 0] = hHybrid->mTempImag [0];
      mHybridReal [0] [chOffset + 1] = hHybrid->mTempReal [1];
      mHybridImag [0] [chOffset + 1] = hHybrid->mTempImag [1];
      mHybridReal [0] [chOffset + 2] = hHybrid->mTempReal [2] + hHybrid->mTempReal [5];
      mHybridImag [0] [chOffset + 2] = hHybrid->mTempImag [2] + hHybrid->mTempImag [5];
      mHybridReal [0] [chOffset + 3] = hHybrid->mTempReal [3] + hHybrid->mTempReal [4];
      mHybridImag [0] [chOffset + 3] = hHybrid->mTempImag [3] + hHybrid->mTempImag [4];
      mHybridReal [0] [chOffset + 4] = hHybrid->mTempReal [6];
      mHybridImag [0] [chOffset + 4] = hHybrid->mTempImag [6];
      mHybridReal [0] [chOffset + 5] = hHybrid->mTempReal [7];
      mHybridImag [0] [chOffset + 5] = hHybrid->mTempImag [7];

      ADD(1);
      chOffset += 6;

      break;
    default:
      assert(0);
    }
  }

  FLC_sub_end();
}
Example #18
0
/*!

  \brief  appends the parametric stereo bitstream portion to the output
          bitstream

  \return Number of bits needed for parametric stereo coding
          of 0 if no EXTENSION_ID_PS_CODING element should be transmitted

****************************************************************************/
int
AppendPsBS (HANDLE_PS_ENC h_ps_e,
            HANDLE_BIT_BUF   hBitStream,
            HANDLE_BIT_BUF   hBitStreamPrev,
            int*             sbrHdrBits)
{
  struct BIT_BUF bitbufTmp;
  unsigned char tmp[MAX_PAYLOAD_SIZE];

  COUNT_sub_start("AppendPsBS");

  BRANCH(1);
  if (!h_ps_e)
  {
    COUNT_sub_end();
    return 0;
  }

  BRANCH(1);
  if (!hBitStream) {

    INDIRECT(1); PTR_INIT(1); FUNC(1); /* counting post-operation */
    COUNT_sub_end();

    return GetBitsAvail (&h_ps_e->psBitBuf);
  }
  else {
    int writtenNoBits = 0;
    int maxExtSize = (1<<SI_SBR_EXTENSION_SIZE_BITS) - 1;
    int numBits = GetBitsAvail (&h_ps_e->psBitBuf);
    int extDataSize = (numBits+SI_SBR_EXTENSION_ID_BITS+7)>>3;

    MOVE(2); INDIRECT(1); PTR_INIT(1); FUNC(1); ADD(1); SHIFT(1); /* counting previous operations */

    FUNC(1); BRANCH(1);
    if ( GetBitsAvail(hBitStreamPrev) == 0) {

      INDIRECT(1); MOVE(1);
      h_ps_e->hdrBitsPrevFrame = *sbrHdrBits;

      FUNC(2);
      CopyBitBuf(hBitStream, hBitStreamPrev);
    }
    else {

      int tmpBits;

      PTR_INIT(1); FUNC(3);
      CreateBitBuffer (&bitbufTmp, tmp, sizeof(tmp));

      MOVE(1);
      tmpBits = *sbrHdrBits;

      INDIRECT(1); MOVE(2);
      *sbrHdrBits = h_ps_e->hdrBitsPrevFrame;
      h_ps_e->hdrBitsPrevFrame = tmpBits;

      FUNC(2);
      CopyBitBuf (hBitStreamPrev, &bitbufTmp);

      FUNC(2);
      CopyBitBuf (hBitStream,  hBitStreamPrev);

      FUNC(2);
      CopyBitBuf (&bitbufTmp,  hBitStream);
    }

    FUNC(3);
    WriteBits (hBitStream, 1, SI_SBR_EXTENDED_DATA_BITS);

    ADD(1); BRANCH(1);
    if (extDataSize < maxExtSize) {

      FUNC(3);
      WriteBits (hBitStream, extDataSize, SI_SBR_EXTENSION_SIZE_BITS);
    } else {
      FUNC(3);
      WriteBits (hBitStream, maxExtSize, SI_SBR_EXTENSION_SIZE_BITS);

      ADD(1); FUNC(3);
      WriteBits (hBitStream, extDataSize - maxExtSize, SI_SBR_EXTENSION_ESC_COUNT_BITS);
    }

    FUNC(3); ADD(1);
    writtenNoBits += WriteBits (hBitStream, EXTENSION_ID_PS_CODING, SI_SBR_EXTENSION_ID_BITS);

    INDIRECT(1); PTR_INIT(1); FUNC(3); ADD(1);
    writtenNoBits += appendBitstream( hBitStream, &h_ps_e->psBitBuf, numBits );

    LOGIC(1);
    writtenNoBits = writtenNoBits%8;

    BRANCH(1);
    if(writtenNoBits)
    {
      ADD(1); FUNC(3);
      WriteBits(hBitStream, 0, (8 - writtenNoBits));
    }

    FUNC(1); ADD(2); /* counting post-operation */
    COUNT_sub_end();

    return GetBitsAvail(hBitStream)-(*sbrHdrBits)-SI_FILL_EXTENTION_BITS;
  }

  COUNT_sub_end();
}
Example #19
0
void AdjustThresholds(ADJ_THR_STATE     *adjThrState,
                      ATS_ELEMENT       *AdjThrStateElement,
                      PSY_OUT_CHANNEL   psyOutChannel[MAX_CHANNELS],
                      PSY_OUT_ELEMENT   *psyOutElement,
                      float             *chBitDistribution,
                      float            sfbFormFactor[MAX_CHANNELS][MAX_GROUPED_SFB],
                      const int         nChannels,
                      QC_OUT_ELEMENT    *qcOE,
                      const int         avgBits,
                      const int         bitresBits,
                      const int         maxBitresBits,
                      const float       maxBitFac,
                      const int         sideInfoBits)
{
   float noRedPe, grantedPe, grantedPeCorr;
   int curWindowSequence;
   PE_DATA peData;
   float bitFactor;
   int ch;

   COUNT_sub_start("AdjustThresholds");

   INDIRECT(1); PTR_INIT(1); FUNC(5);
   preparePe(&peData, psyOutChannel, sfbFormFactor, nChannels, AdjThrStateElement->peOffset);

   PTR_INIT(1); FUNC(3);
   calcPe(&peData, psyOutChannel, nChannels);

   MOVE(1);
   noRedPe = peData.pe;

   MOVE(1);
   curWindowSequence = LONG_WINDOW;

   ADD(1); BRANCH(1);
   if (nChannels==2) {

     ADD(2); LOGIC(1);
     if ((psyOutChannel[0].windowSequence == SHORT_WINDOW) ||
         (psyOutChannel[1].windowSequence == SHORT_WINDOW)) {

       MOVE(1);
       curWindowSequence = SHORT_WINDOW;
     }
   }
   else {

     MOVE(1);
     curWindowSequence = psyOutChannel[0].windowSequence;
   }


   MULT(1); ADD(1); FUNC(8);
   bitFactor = bitresCalcBitFac(bitresBits, maxBitresBits,
                                noRedPe+5.0f*sideInfoBits,
                                curWindowSequence, avgBits, maxBitFac,
                                adjThrState,
                                AdjThrStateElement);

   FUNC(1); MULT(1);
   grantedPe = bitFactor * bits2pe((float)avgBits);

   INDIRECT(3); ADD(1); BRANCH(1); MOVE(1); /* min() */ PTR_INIT(1); FUNC(4);
   calcPeCorrection(&(AdjThrStateElement->peCorrectionFactor), 
                    min(grantedPe, noRedPe),
                    AdjThrStateElement->peLast, 
                    AdjThrStateElement->dynBitsLast);

   INDIRECT(1); MULT(1);
   grantedPeCorr = grantedPe * AdjThrStateElement->peCorrectionFactor;

   ADD(1); BRANCH(1);
   if (grantedPeCorr < noRedPe) {

      INDIRECT(2); PTR_INIT(3); FUNC(7);
      adaptThresholdsToPe(psyOutChannel,
                          psyOutElement,
                          &peData,
                          nChannels,
                          grantedPeCorr,
                          &AdjThrStateElement->ahParam,
                          &AdjThrStateElement->minSnrAdaptParam);
   }

   PTR_INIT(2); /* pointers for chBitDistribution[],
                                peData.peChannelData[]
                */
   LOOP(1);
   for (ch=0; ch<nChannels; ch++) {

     BRANCH(1);
     if (peData.pe) {

       DIV(1); MULT(2); ADD(2); STORE(1);
       chBitDistribution[ch] = 0.2f + (float)(1.0f-nChannels*0.2f) * (peData.peChannelData[ch].pe/peData.pe);
     } else {

       MOVE(1);
       chBitDistribution[ch] = 0.2f;
     }
   }

   INDIRECT(1); MOVE(1);
   qcOE->pe= noRedPe;

   INDIRECT(1); MOVE(1);
   AdjThrStateElement->peLast = grantedPe;

   COUNT_sub_end();
}
Example #20
0
static int tnsCount(TNS_INFO *tnsInfo, int blockType)
{

  int i,k;
  int tnsPresent;
  int numOfWindows;
  int count;
  int coefBits;

  COUNT_sub_start("tnsCount");

  MOVE(1);
  count = 0;

  ADD(1); BRANCH(1); MOVE(1);
  numOfWindows=(blockType==2?8:1);

  MOVE(1);
  tnsPresent=0;

  PTR_INIT(1); /* tnsInfo->numOfFilters[] */
  LOOP(1);
  for (i=0; i<numOfWindows; i++) {

    ADD(1); BRANCH(1);
    if (tnsInfo->tnsActive[i]==1) {

      MOVE(1);
      tnsPresent=1;
    }
  }

  BRANCH(1);
  if (tnsPresent==0) {
    /* count+=1; */
  }
  else{ /* there is data to be written*/
    /*count += 1; */

    PTR_INIT(2); /* tnsInfo->tnsActive[]
                    tnsInfo->coefRes[]
                 */
    LOOP(1);
    for (i=0; i<numOfWindows; i++) {

      ADD(1); BRANCH(1); /* .. == .. ? */ ADD(1);
      count +=(blockType==SHORT_WINDOW?1:2);

      BRANCH(1);
      if (tnsInfo->tnsActive[i]) {

        ADD(1);
        count += 1;

        ADD(1); BRANCH(1); /* .. == .. ? */ ADD(2);
        count +=(blockType==SHORT_WINDOW?4:6);
        count +=(blockType==SHORT_WINDOW?3:5);
        
        BRANCH(1);
        if (tnsInfo->order[i]){

          ADD(2);
          count +=1; /*direction*/
          count +=1; /*coef_compression */
          
          ADD(1); BRANCH(1);
          if(tnsInfo->coefRes[i] == 4) {

            MOVE(1);
            coefBits=3;
            
            PTR_INIT(1); /* tnsInfo->coef[]*/
            LOOP(1);
            for(k=0; k<tnsInfo->order[i]; k++) {
              
              ADD(2); LOGIC(1); BRANCH(1);
              if (tnsInfo->coef[i*TNS_MAX_ORDER_SHORT+k]> 3 ||
                  tnsInfo->coef[i*TNS_MAX_ORDER_SHORT+k]< -4) {
                
                MOVE(1);
                coefBits = 4;
                break;
              }
            }
          }
          else {
            
            MOVE(1);
            coefBits = 2;
            
            PTR_INIT(1); /* tnsInfo->coef[]*/
            LOOP(1);
            for(k=0; k<tnsInfo->order[i]; k++) {
              
              ADD(2); LOGIC(1); BRANCH(1);
              if (tnsInfo->coef[i*TNS_MAX_ORDER_SHORT+k]> 1 ||
                  tnsInfo->coef[i*TNS_MAX_ORDER_SHORT+k]< -2) {
                
                MOVE(1);
                coefBits = 3;
                break;
              }
            }
          }
          
          LOOP(1);
          for (k=0; k<tnsInfo->order[i]; k++ ) {
            
            ADD(1);
            count +=coefBits;
          }
        }
      }
    }
  }

  COUNT_sub_end();

  return count;
}
Example #21
0
int IcsRead(HANDLE_BIT_BUF bs,
             CIcsInfo *pIcsInfo)
{
  int i;
  char mask;
  char PredictorDataPresent;
  int ErrorStatus = AAC_DEC_OK;
  
  COUNT_sub_start("IcsRead");

  MOVE(1); /* counting previous operation */

  INDIRECT(1); FUNC(2); STORE(1);
  pIcsInfo->IcsReservedBit = (char) GetBits(bs,1);

  INDIRECT(1); FUNC(2); STORE(1);
  pIcsInfo->WindowSequence = (char) GetBits(bs,2);

  INDIRECT(1); FUNC(2); STORE(1);
  pIcsInfo->WindowShape = (char) GetBits(bs,1);

  FUNC(1); BRANCH(1);
  if (IsLongBlock(pIcsInfo))
  {
    INDIRECT(2); MOVE(1);
    pIcsInfo->TotalSfBands = SamplingRateInfoTable[pIcsInfo->SamplingRateIndex].NumberOfScaleFactorBands_Long;

    INDIRECT(1); FUNC(2); STORE(1);
    pIcsInfo->MaxSfBands = (char) GetBits(bs,6);
    
    FUNC(2); BRANCH(1);
    if ((PredictorDataPresent = (char) GetBits(bs,1)))
    {
      COUNT_sub_end();
      return (AAC_DEC_PREDICTION_NOT_SUPPORTED_IN_LC_AAC);
    }

    INDIRECT(2); MOVE(2);
    pIcsInfo->WindowGroups = 1;
    pIcsInfo->WindowGroupLength[0] = 1;
  }
  else
  {
    INDIRECT(2); MOVE(1);
    pIcsInfo->TotalSfBands = SamplingRateInfoTable[pIcsInfo->SamplingRateIndex].NumberOfScaleFactorBands_Short;

    INDIRECT(1); FUNC(2); STORE(1);
    pIcsInfo->MaxSfBands = (char) GetBits(bs,4);

    INDIRECT(1); FUNC(2); STORE(1);
    pIcsInfo->ScaleFactorGrouping = (char) GetBits(bs,7);

    INDIRECT(1); MOVE(1);
    pIcsInfo->WindowGroups = 0 ;

    PTR_INIT(1); /* pIcsInfo->WindowGroupLength[] */
    LOOP(1);
    for (i=0; i < 7; i++)
    {
      ADD(1); SHIFT(1);
      mask = 1 << (6 - i);

      MOVE(1);
      pIcsInfo->WindowGroupLength[i] = 1;

      INDIRECT(1); LOGIC(1); BRANCH(1);
      if (pIcsInfo->ScaleFactorGrouping & mask)
      {
        INDIRECT(1); ADD(1); STORE(1);
        pIcsInfo->WindowGroupLength[pIcsInfo->WindowGroups]++;
      }
      else
      {
        INDIRECT(1); ADD(1); STORE(1);
        pIcsInfo->WindowGroups++;
      }
    }

    /* loop runs to i < 7 only */
    INDIRECT(1); MOVE(1);
    pIcsInfo->WindowGroupLength[7] = 1;

    INDIRECT(1); ADD(1); STORE(1);
    pIcsInfo->WindowGroups++;
  }

  INDIRECT(1); MOVE(1);
  pIcsInfo->Valid = 1;

  COUNT_sub_end();

  return ErrorStatus;
}
Example #22
0
/*
 *
 * \brief Reset memory for one lpp transposer instance
 *
 *
 */
int
resetLppTransposer (HANDLE_SBR_LPP_TRANS hLppTrans,
                    unsigned char xposctrl,
                    unsigned char highBandStartSb,
                    unsigned char *v_k_master,
                    unsigned char numMaster,
                    unsigned char* noiseBandTable,
                    unsigned char noNoiseBands,
                    unsigned char usb,
                    unsigned short fs
                    )
{
  int    i, patch;
  int    targetStopBand;

  TRANSPOSER_SETTINGS *pSettings;
  PATCH_PARAM  *patchParam;

  int sourceStartBand;
  int patchDistance;
  int numBandsInPatch;

  int lsb;

  int xoverOffset;

  int goalSb;

  COUNT_sub_start("resetLppTransposer");

  PTR_INIT(2);
  pSettings = hLppTrans->pSettings;
  patchParam = pSettings->patchParam;

  MOVE(1);
  lsb = v_k_master[0];

  ADD(1);
  xoverOffset = highBandStartSb - lsb;


  ADD(2); BRANCH(1);
  if ( lsb - SHIFT_START_SB < 4 ) {
    COUNT_sub_end();
    return (1);
  }



  ADD(1); BRANCH(1);
  if (xposctrl == 1) {

    ADD(1);
    lsb += xoverOffset;
    MOVE(1);
    xoverOffset = 0;
  }

  BRANCH(2); MOVE(1); /* worst case */
  switch(fs){
  case 16000:
  case 22050:
  case 24000:
  case 32000:
    goalSb=64;
    break;
  case 44100:
    goalSb=46;
    break;
  case 48000:
    goalSb=43;
    break;
  default:
    COUNT_sub_end();
    return(0);
  }

  FUNC(4);
  goalSb = findClosestEntry(goalSb, v_k_master, numMaster, 1);

  ADD(2); FUNC(1);
  if ( abs(goalSb - usb) < 4 ) {
    MOVE(1);
    goalSb = usb;
  }


  ADD(1);
  sourceStartBand = SHIFT_START_SB + xoverOffset;
  ADD(1);
  targetStopBand = lsb + xoverOffset;

  MOVE(1);
  patch = 0;

  PTR_INIT(1); /* pointer for patchParam[patch] */
  LOOP(1);
  while(targetStopBand < usb) {

    ADD(1); BRANCH(1);
    if (patch > MAX_NUM_PATCHES) {
      COUNT_sub_end();
      return -1;
    }

    MOVE(1);
    patchParam[patch].guardStartBand = targetStopBand;

    ADD(1);
    targetStopBand += GUARDBANDS;

    MOVE(1);
    patchParam[patch].targetStartBand = targetStopBand;

    ADD(1);
    numBandsInPatch = goalSb - targetStopBand;

    ADD(2); BRANCH(1);
    if ( numBandsInPatch >= lsb - sourceStartBand ) {
      ADD(1);
      patchDistance   = targetStopBand - sourceStartBand;

      LOGIC(1);
      patchDistance   = patchDistance & ~1;

      ADD(2);
      numBandsInPatch = lsb - (targetStopBand - patchDistance);

      ADD(2); FUNC(4);
      numBandsInPatch = findClosestEntry(targetStopBand + numBandsInPatch, v_k_master, numMaster, 0) -
                        targetStopBand;
    }


    ADD(2);
    patchDistance   = numBandsInPatch + targetStopBand - lsb;

    ADD(1); LOGIC(1);
    patchDistance   = (patchDistance + 1) & ~1;

    BRANCH(1);
    if (numBandsInPatch > 0) {

      ADD(1); STORE(1);
      patchParam[patch].sourceStartBand = targetStopBand - patchDistance;

      MOVE(2);
      patchParam[patch].targetBandOffs  = patchDistance;
      patchParam[patch].numBandsInPatch = numBandsInPatch;

      ADD(1); STORE(1);
      patchParam[patch].sourceStopBand  = patchParam[patch].sourceStartBand + numBandsInPatch;

      ADD(1);
      targetStopBand += patchParam[patch].numBandsInPatch;

      patch++;
    }

    MOVE(1);
    sourceStartBand = SHIFT_START_SB;


    FUNC(1); ADD(1); BRANCH(1);
    if( abs(targetStopBand - goalSb) < 3) {
      MOVE(1);
      goalSb = usb;
    }

  }

  ADD(1);
  patch--;

  ADD(1); LOGIC(1); BRANCH(1);
  if ( (patch>0) && (patchParam[patch].numBandsInPatch < 3) ) {
    ADD(1);
    patch--;

    ADD(1);
    targetStopBand = patchParam[patch].targetStartBand + patchParam[patch].numBandsInPatch;
  }

  ADD(1); BRANCH(1);
  if (patch >= MAX_NUM_PATCHES) {
    COUNT_sub_end();
    return -1;
  }

  ADD(1); STORE(1);
  pSettings->noOfPatches = patch + 1;

  MOVE(1);
  pSettings->lbStartPatching = targetStopBand;

  MOVE(1);
  pSettings->lbStopPatching  = 0;

  PTR_INIT(1); /* pointer for patchParam[patch] */
  LOOP(1);
  for ( patch = 0; patch < pSettings->noOfPatches; patch++ ) {

    INDIRECT(1); ADD(1); BRANCH(1); MOVE(1);
    pSettings->lbStartPatching = min( pSettings->lbStartPatching, patchParam[patch].sourceStartBand );

    INDIRECT(1); ADD(1); BRANCH(1); MOVE(1);
    pSettings->lbStopPatching  = max( pSettings->lbStopPatching, patchParam[patch].sourceStopBand );
  }

  PTR_INIT(2); /* pointer for bwBorders[i],
                              noiseBandTable[i+1]  */
  LOOP(1);
  for(i = 0 ; i < noNoiseBands; i++){
    MOVE(1);
    hLppTrans->pSettings->bwBorders[i] = noiseBandTable[i+1];
  }


  COUNT_sub_end();
  return 0;
}
Example #23
0
static void reduceMinSnr(PSY_OUT_CHANNEL  psyOutChannel[MAX_CHANNELS],
                         PE_DATA *peData, 
                         int ahFlag[MAX_CHANNELS][MAX_GROUPED_SFB],
                         const int nChannels,
                         const float desiredPe)
{
  int ch, sfb, sfbSubWin;
  float deltaPe;

  COUNT_sub_start("reduceMinSnr");

  /* start at highest freq down to 0 */
  MOVE(1);
  sfbSubWin = psyOutChannel[0].maxSfbPerGroup;
  
  PTR_INIT(7); /* pointer for ahFlag[ch][sfb],
                  psyOutChannel[ch].sfbMinSnr[sfb],
                  psyOutChannel[ch].sfbThreshold[sfb],
                  psyOutChannel[ch].sfbEnergy[sfb],
                  peData->peChannelData[ch].sfbNLines[sfb],
                  peData->peChannelData[ch].sfbPe[sfb],
                  peData->peChannelData[ch].pe
               */
  INDIRECT(1); LOOP(1);
  while (peData->pe > desiredPe && sfbSubWin > 0) {
    ADD(1); LOGIC(1); /* while() condition */
    
    ADD(1);
    sfbSubWin--;
    
    /* loop over all subwindows */
    LOOP(1);
    for (sfb=sfbSubWin; sfb<psyOutChannel[0].sfbCnt;
         sfb+=psyOutChannel[0].sfbPerGroup) {
      
      /* loop over all channels */
      LOOP(1);
      for (ch=0; ch<nChannels; ch++) {
        
        ADD(2); BRANCH(1);
        if (ahFlag[ch][sfb] != NO_AH &&
            psyOutChannel[ch].sfbMinSnr[sfb] < minSnrLimit) {
          
          MOVE(1);
          psyOutChannel[ch].sfbMinSnr[sfb] = minSnrLimit;
          
          MULT(1); STORE(1);
          psyOutChannel[ch].sfbThreshold[sfb] =
            psyOutChannel[ch].sfbEnergy[sfb] * psyOutChannel[ch].sfbMinSnr[sfb];
          
          MULT(1); ADD(1);
          deltaPe = peData->peChannelData[ch].sfbNLines[sfb] * 1.5f -
            peData->peChannelData[ch].sfbPe[sfb];
          
          INDIRECT(1); ADD(1); STORE(1);
          peData->pe += deltaPe;
          
          ADD(1); STORE(1);
          peData->peChannelData[ch].pe += deltaPe;
        }
      }
      
      INDIRECT(1); ADD(1); BRANCH(1);
      if (peData->pe <= desiredPe)
        break;
    }
  }
  
  COUNT_sub_end();
}
Example #24
0
static void scfCount(const short *scalefacGain,
                     const unsigned short *maxValueInSfb,
                     SECTION_DATA * sectionData)

{
  /* counter */
  int i = 0; /* section counter */
  int j = 0; /* sfb counter */
  int k = 0; /* current section auxiliary counter */
  int m = 0; /* other section auxiliary counter */
  int n = 0; /* other sfb auxiliary counter */

  /* further variables */
  int lastValScf     = 0;
  int deltaScf       = 0;
  int found          = 0;
  int scfSkipCounter = 0;

  COUNT_sub_start("scfCount");

  MOVE(9); /* counting previous operations */

  INDIRECT(1); MOVE(1);
  sectionData->scalefacBits = 0;

  BRANCH(1);
  if (scalefacGain == NULL) {
    COUNT_sub_end();
    return;
  }

  INDIRECT(1); MOVE(2);
  lastValScf = 0;
  sectionData->firstScf = 0;

  PTR_INIT(1); /* sectionData->section[] */
  INDIRECT(1); LOOP(1);
  for (i = 0; i < sectionData->noOfSections; i++) {

    ADD(1); BRANCH(1);
    if (sectionData->section[i].codeBook != CODE_BOOK_ZERO_NO) {

      INDIRECT(1); MOVE(1);
      sectionData->firstScf = sectionData->section[i].sfbStart;

      INDIRECT(1); MOVE(1);
      lastValScf = scalefacGain[sectionData->firstScf];
      break;
    }
  }

  PTR_INIT(1); /* sectionData->section[] */
  INDIRECT(1); LOOP(1);
  for (i = 0; i < sectionData->noOfSections; i++) {

    ADD(2); LOGIC(1); BRANCH(1);
    if ((sectionData->section[i].codeBook != CODE_BOOK_ZERO_NO) &&
        (sectionData->section[i].codeBook != CODE_BOOK_PNS_NO)) {

      PTR_INIT(2); /* maxValueInSfb[]
                      scalefacGain[]
                   */
      ADD(1); LOOP(1);
      for (j = sectionData->section[i].sfbStart;
           j < sectionData->section[i].sfbStart + sectionData->section[i].sfbCnt;
           j++) {

        BRANCH(1);
        if (maxValueInSfb[j] == 0) {

          MOVE(1);
          found = 0;

          BRANCH(1);
          if (scfSkipCounter == 0) {

            ADD(3); BRANCH(1);
            if (j == (sectionData->section[i].sfbStart + sectionData->section[i].sfbCnt - 1) ) {

              MOVE(1);
              found = 0;
            }
            else {

              PTR_INIT(2); /* maxValueInSfb[]
                              scalefacGain[]
                           */
              LOOP(1);
              for (k = (j+1); k < sectionData->section[i].sfbStart + sectionData->section[i].sfbCnt; k++) {
                BRANCH(1);
                if (maxValueInSfb[k] != 0) {
                  MOVE(1);
                  found = 1;

                  ADD(2); MISC(1); BRANCH(1);
                  if ( (abs(scalefacGain[k] - lastValScf)) < CODE_BOOK_SCF_LAV) {
                    MOVE(1);
                    deltaScf = 0;
                  }
                  else {
                    ADD(1); MULT(1);
                    deltaScf = -(scalefacGain[j] - lastValScf);

                    MOVE(2);
                    lastValScf = scalefacGain[j];
                    scfSkipCounter = 0;
                  }
                  break;
                }
                /* count scalefactor skip */
                ADD(1);
                scfSkipCounter = scfSkipCounter + 1;
              }
            }

            /* search for the next maxValueInSfb[] != 0 in all other sections */
            PTR_INIT(1); /* sectionData->section[] */
            INDIRECT(1); LOOP(1);
            for (m = (i+1); (m < sectionData->noOfSections) && (found == 0); m++) {

              ADD(2); LOGIC(1); BRANCH(1);
              if ((sectionData->section[m].codeBook != CODE_BOOK_ZERO_NO) &&
                  (sectionData->section[m].codeBook != CODE_BOOK_PNS_NO)) {
                PTR_INIT(2); /* maxValueInSfb[]
                                scalefacGain[]
                             */
                LOOP(1);
                for (n = sectionData->section[m].sfbStart;
                     n < sectionData->section[m].sfbStart + sectionData->section[m].sfbCnt;
                     n++) {
                  BRANCH(1);
                  if (maxValueInSfb[n] != 0) {
                    MOVE(1);
                    found = 1;

                    ADD(2); MISC(1); BRANCH(1);
                    if ( (abs(scalefacGain[n] - lastValScf)) < CODE_BOOK_SCF_LAV) {
                      MOVE(1);
                      deltaScf = 0;
                    }
                    else {

                      ADD(1); MULT(1);
                      deltaScf = -(scalefacGain[j] - lastValScf);

                      MOVE(2);
                      lastValScf = scalefacGain[j];
                      scfSkipCounter = 0;
                    }
                    break;
                  }

                  ADD(1);
                  scfSkipCounter = scfSkipCounter + 1;
                }
              }
            }

            BRANCH(1);
            if (found == 0)   {
              MOVE(2);
              deltaScf = 0;
              scfSkipCounter = 0;
            }
          }
          else {

            MOVE(1);
            deltaScf = 0;

            ADD(1);
            scfSkipCounter = scfSkipCounter - 1;
          }
        }
        else {
          ADD(1); MULT(1);
          deltaScf = -(scalefacGain[j] - lastValScf);

          MOVE(1);
          lastValScf = scalefacGain[j];
        }

        INDIRECT(1); FUNC(1); ADD(1); STORE(1);
        sectionData->scalefacBits += bitCountScalefactorDelta(deltaScf);
      }
    }
  }

  COUNT_sub_end();
}
Example #25
0
/*!
 
  \brief  do an appropriate attenuation on the side channel of a stereo
          signal
 
  \return nothing
 
****************************************************************************/
void ApplyStereoPreProcess(HANDLE_STEREO_PREPRO hStPrePro, /*!st.-preproc handle */
                           int                 nChannels, /*! total number of channels */              
                           ELEMENT_INFO        *elemInfo,
                           float *timeData,     /*! lr time data (modified) */
                           int granuleLen) /*! num. samples to be processed */
{
  /* inplace operation on inData ! */

  float SMRatio, StoM;
  float LRRatio, LtoR, deltaLtoR, deltaNrg;
  float EnImpact, PeImpact, PeNorm;
  float Att, AttAimed;
  float maxInc, maxDec, swiftfactor;
  float DELTA=0.1f;
  
  float fac = hStPrePro->stereoAttFac;
  float mPart, upper, div;
  float lFac,rFac;

  int i;

  COUNT_sub_start("ApplyStereoPreProcess");

  INDIRECT(1); MOVE(2); /* counting previous operations */

  INDIRECT(1); BRANCH(1);
  if (!hStPrePro->stereoAttenuationFlag) {
    COUNT_sub_end();
    return;
  }

  
  /* calc L/R ratio */
  INDIRECT(1); MULT(3); ADD(1);
  mPart = 2.0f * hStPrePro->avrgFreqEnergyM * (1.0f - fac*fac);

  INDIRECT(2); ADD(4); MULT(2); MAC(2);
  upper = hStPrePro->avrgFreqEnergyL * (1.0f+fac) + hStPrePro->avrgFreqEnergyR * (1.0f-fac) - mPart;
  div   = hStPrePro->avrgFreqEnergyR * (1.0f+fac) + hStPrePro->avrgFreqEnergyL * (1.0f-fac) - mPart;
  
  LOGIC(1); BRANCH(1);
  if (div == 0.0f || upper == 0.0f) {

    INDIRECT(1); MOVE(1);
    LtoR = hStPrePro->LRMax;
  }
  else {

    DIV(1); MISC(1);
    LRRatio = (float) fabs ( upper / div ) ;

    TRANS(1); MULT(1); MISC(1);
    LtoR = (float) fabs(10.0 * log10(LRRatio));
  }
  

  /* calc delta energy to previous frame */
  INDIRECT(3); ADD(3); DIV(1);
  deltaNrg = ( hStPrePro->avrgFreqEnergyL + hStPrePro->avrgFreqEnergyR + 1.0f) / 
             ( hStPrePro->lastNrgLR + 1.0f );

  TRANS(1); MULT(1); MISC(1);
  deltaNrg = (float) (fabs(10.0 * log10(deltaNrg)));
  
  

  /* Smooth S/M over time */
  INDIRECT(2); ADD(2); DIV(1);
  SMRatio = (hStPrePro->avrgFreqEnergyS + 1.0f) / (hStPrePro->avrgFreqEnergyM + 1.0f);

  TRANS(1); MULT(1);
  StoM = (float) (10.0 * log10(SMRatio));

  INDIRECT(2); MULT(1); MAC(1); STORE(1);
  hStPrePro->avgStoM = DELTA * StoM + (1-DELTA) * hStPrePro->avgStoM;
  
  

  MOVE(1);
  EnImpact = 1.0f;
  
  INDIRECT(2); ADD(1); BRANCH(1);
  if (hStPrePro->avgStoM > hStPrePro->SMMin) {

    INDIRECT(1); ADD(1); BRANCH(1);
    if (hStPrePro->avgStoM > hStPrePro->SMMax) {

      MOVE(1);
      EnImpact = 0.0f;
    }
    else {

      ADD(2); DIV(1);
      EnImpact = (hStPrePro->SMMax - hStPrePro->avgStoM) / (hStPrePro->SMMax - hStPrePro->SMMin);
    }
  }
  
  INDIRECT(1); ADD(1); BRANCH(1);
  if (LtoR > hStPrePro->LRMin) {

    INDIRECT(1); ADD(1); BRANCH(1);
    if ( LtoR > hStPrePro->LRMax) {

      MOVE(1);
      EnImpact = 0.0f;
    }
    else {

      ADD(2); DIV(1); MULT(1);
      EnImpact *= (hStPrePro->LRMax - LtoR) / (hStPrePro->LRMax - hStPrePro->LRMin);
    }
  }
  
  
  MOVE(1);
  PeImpact = 0.0f;
  
  INDIRECT(2); MULT(1);
  PeNorm = hStPrePro->smoothedPeSumSum * hStPrePro->normPeFac;
  
  INDIRECT(1); ADD(1); BRANCH(1);
  if ( PeNorm > hStPrePro->PeMin )  {

    INDIRECT(1); ADD(2); DIV(1);
    PeImpact= ((PeNorm - hStPrePro->PeMin) / (hStPrePro->PeCrit - hStPrePro->PeMin));
  }
  
  INDIRECT(1); ADD(1); BRANCH(1);
  if (PeImpact > hStPrePro->PeImpactMax) {

    MOVE(1);
    PeImpact = hStPrePro->PeImpactMax;
  }
  
  
  INDIRECT(1); MULT(2);
  AttAimed = EnImpact * PeImpact * hStPrePro->ImpactFactor;
  
  
  INDIRECT(1); ADD(1); BRANCH(1);
  if (AttAimed > hStPrePro->stereoAttMax) {

    MOVE(1);
    AttAimed = hStPrePro->stereoAttMax;
  }
  
  /* only accept changes if they are large enough */

  INDIRECT(1); ADD(2); MISC(1); LOGIC(1); BRANCH(1);
  if ( fabs(AttAimed - hStPrePro->stereoAttenuation) < 1.0f && AttAimed != 0.0f) {

    MOVE(1);
    AttAimed = hStPrePro->stereoAttenuation;
  }
  
  MOVE(1);
  Att = AttAimed;


  INDIRECT(1); ADD(1); MULT(1); BRANCH(1); /* max() */ ADD(2); DIV(1); MULT(1);
  swiftfactor = (6.0f + hStPrePro->stereoAttenuation) / (10.0f + LtoR) * max(1.0f, 0.2f * deltaNrg );
  
  INDIRECT(1); ADD(2); BRANCH(1); MOVE(1);
  deltaLtoR = max(3.0f, LtoR - hStPrePro->lastLtoR );
  
  MULT(2); DIV(1);
  maxDec = deltaLtoR * deltaLtoR / 9.0f * swiftfactor;
  
  ADD(1); BRANCH(1); MOVE(1);
  maxDec = min( maxDec, 5.0f );
  
  INDIRECT(1); MULT(1);
  maxDec *= hStPrePro->stereoAttenuationDec;
  
  
  INDIRECT(1); MULT(1); ADD(1); BRANCH(1);
  if (maxDec > hStPrePro->stereoAttenuation * 0.8f) {
    
    MOVE(1);
    maxDec = hStPrePro->stereoAttenuation * 0.8f;
  }
  
  INDIRECT(1); ADD(2); BRANCH(1); MOVE(1);
  deltaLtoR = max(3.0f, hStPrePro->lastLtoR - LtoR );
  
  MULT(2); DIV(1);
  maxInc = deltaLtoR * deltaLtoR / 9.0f * swiftfactor;
  
  ADD(1); BRANCH(1); MOVE(1);
  maxInc = min( maxInc, 5.0f );
  
  INDIRECT(1); MULT(1);
  maxInc *= hStPrePro->stereoAttenuationInc;
  
  
  INDIRECT(1); MULT(1); ADD(1); BRANCH(1);
  if (maxDec > hStPrePro->stereoAttenuation * 0.8f) {
    
    MOVE(1);
    maxDec = hStPrePro->stereoAttenuation * 0.8f;
  }
  
  INDIRECT(1); ADD(2); BRANCH(1); MOVE(1);
  deltaLtoR = max(3.0f, hStPrePro->lastLtoR - LtoR );
  
  MULT(2); DIV(1);
  maxInc = deltaLtoR * deltaLtoR / 9.0f * swiftfactor;
  
  ADD(1); BRANCH(1); MOVE(1);
  maxInc = min( maxInc, 5.0f );
  
  INDIRECT(1); MULT(1);
  maxInc *= hStPrePro->stereoAttenuationInc;
  
  
  INDIRECT(1); ADD(2); BRANCH(1);
  if (Att > hStPrePro->stereoAttenuation + maxInc) {

    MOVE(1);
    Att = hStPrePro->stereoAttenuation + maxInc;
  }

  INDIRECT(1); ADD(2); BRANCH(1);
  if (Att < hStPrePro->stereoAttenuation - maxDec) {

    MOVE(1);
    Att = hStPrePro->stereoAttenuation - maxDec;
  }
  
  INDIRECT(2); BRANCH(1); MOVE(1);
  if (hStPrePro->ConstAtt == 0) hStPrePro->stereoAttenuation = Att;
  else                          hStPrePro->stereoAttenuation = hStPrePro->ConstAtt;
  

  /* perform attenuation of Side Channel */
  
  INDIRECT(2); MULT(1); TRANS(1); STORE(1);
  hStPrePro->stereoAttFac = (float) pow(10.0f, 0.05f*(-hStPrePro->stereoAttenuation ));
  
  INDIRECT(1); ADD(2); MULT(2);
  lFac = 0.5f * (1.0f + hStPrePro->stereoAttFac);
  rFac = 0.5f * (1.0f - hStPrePro->stereoAttFac);
  
  PTR_INIT(2); /* pointer for timeData[nChannels * i + elemInfo->ChannelIndex[0]], 
                              timeData[nChannels * i + elemInfo->ChannelIndex[1]]
               */
  LOOP(1);
  for (i = 0; i < granuleLen; i++){
    float L = lFac * timeData[nChannels * i+elemInfo->ChannelIndex[0]] + rFac * timeData[nChannels * i + elemInfo->ChannelIndex[1]];
    float R = rFac * timeData[nChannels * i+elemInfo->ChannelIndex[0]] + lFac * timeData[nChannels * i + elemInfo->ChannelIndex[1]];

    MULT(2); MAC(2); /* counting operations above */
    
    MOVE(2);
    timeData[nChannels * i + elemInfo->ChannelIndex[0]]= L;
    timeData[nChannels * i + elemInfo->ChannelIndex[1]]= R;
  }
  
  INDIRECT(1); MOVE(1);
  hStPrePro->lastLtoR = LtoR;

  INDIRECT(3); ADD(1); STORE(1);
  hStPrePro->lastNrgLR = hStPrePro->avrgFreqEnergyL + hStPrePro->avrgFreqEnergyR;
  
  COUNT_sub_end();
}
Example #26
0
static int
resetPatch(HANDLE_SBR_TON_CORR_EST hTonCorr,
           int xposctrl,
           int highBandStartSb,
           int channelOffset,
           unsigned char *v_k_master,
           int numMaster,
           int fs,
           int noChannels)
{
  int patch,k,i;
  int targetStopBand;

  PATCH_PARAM  *patchParam = hTonCorr->patchParam;

  int sbGuard = hTonCorr->guard;
  int sourceStartBand;
  int patchDistance;
  int numBandsInPatch;

  int lsb = v_k_master[0];
  int usb = v_k_master[numMaster];
  int xoverOffset = highBandStartSb - v_k_master[0];

  int goalSb;

  COUNT_sub_start("resetPatch");

  INDIRECT(3); PTR_INIT(1); MOVE(3); ADD(1); /* counting previous operations */


  ADD(1); BRANCH(1);
  if (xposctrl == 1) {

    ADD(1);
    lsb += xoverOffset;

    MOVE(1);
    xoverOffset = 0;
  }

  MULT(2); DIV(1); ADD(1);
  goalSb = (int)( 2 * noChannels * 16000.0f / fs  + 0.5f );

  FUNC(4);
  goalSb = findClosestEntry(goalSb, v_k_master, numMaster, 1);

  INDIRECT(1); ADD(1);
  sourceStartBand = hTonCorr->shiftStartSb + xoverOffset;

  ADD(1);
  targetStopBand = lsb + xoverOffset;

  MOVE(1);
  patch = 0;

  PTR_INIT(1); /* patchParam[patch] */
  LOOP(1);
  while(targetStopBand < usb) {

    ADD(1); BRANCH(1);
    if (patch >= MAX_NUM_PATCHES)
    {
      COUNT_sub_end();
      return(1);
    }

    MOVE(1);
    patchParam[patch].guardStartBand = targetStopBand;

    ADD(1);
    targetStopBand += sbGuard;

    MOVE(1);
    patchParam[patch].targetStartBand = targetStopBand;

    ADD(1);
    numBandsInPatch = goalSb - targetStopBand;

    ADD(2); BRANCH(1);
    if ( numBandsInPatch >= lsb - sourceStartBand ) {
      ADD(1);
      patchDistance   = targetStopBand - sourceStartBand;

      LOGIC(1);
      patchDistance   = patchDistance & ~1;

      ADD(2);
      numBandsInPatch = lsb - (targetStopBand - patchDistance);

      ADD(2); FUNC(4);
      numBandsInPatch = findClosestEntry(targetStopBand + numBandsInPatch, v_k_master, numMaster, 0) -
                        targetStopBand;
    }


    ADD(2);
    patchDistance   = numBandsInPatch + targetStopBand - lsb;

    ADD(1); LOGIC(1);
    patchDistance   = (patchDistance + 1) & ~1;

    BRANCH(1);
    if (numBandsInPatch <= 0) {

      ADD(1);
      patch--;
    } else {

      ADD(1); STORE(1);
      patchParam[patch].sourceStartBand = targetStopBand - patchDistance;

      MOVE(2);
      patchParam[patch].targetBandOffs  = patchDistance;
      patchParam[patch].numBandsInPatch = numBandsInPatch;

      ADD(1); STORE(1);
      patchParam[patch].sourceStopBand  = patchParam[patch].sourceStartBand + numBandsInPatch;

      ADD(1);
      targetStopBand += patchParam[patch].numBandsInPatch;
    }

    INDIRECT(1); MOVE(1);
    sourceStartBand = hTonCorr->shiftStartSb;

    ADD(2); MISC(1); BRANCH(1);
    if( abs(targetStopBand - goalSb) < 3) {
      MOVE(1);
      goalSb = usb;
    }

    ADD(1);
    patch++;

  }

  ADD(1);
  patch--;


  ADD(1); LOGIC(1); BRANCH(1);
  if ( patchParam[patch].numBandsInPatch < 3 && patch > 0 ) {
    ADD(1);
    patch--;

    ADD(1);
    targetStopBand = patchParam[patch].targetStartBand + patchParam[patch].numBandsInPatch;
  }

  INDIRECT(1); ADD(1); STORE(1);
  hTonCorr->noOfPatches = patch + 1;

  PTR_INIT(1); /* hTonCorr->indexVector[] */
  INDIRECT(1); LOOP(1);
  for(k = 0; k < hTonCorr->patchParam[0].guardStartBand; k++)
  {
    MOVE(1);
    hTonCorr->indexVector[k] = k;
  }

  PTR_INIT(1); /* hTonCorr->patchParam[] */
  INDIRECT(1); LOOP(1);
  for(i = 0; i < hTonCorr->noOfPatches; i++)
  {
    int sourceStart    = hTonCorr->patchParam[i].sourceStartBand;
    int targetStart    = hTonCorr->patchParam[i].targetStartBand;
    int numberOfBands  = hTonCorr->patchParam[i].numBandsInPatch;
    int startGuardBand = hTonCorr->patchParam[i].guardStartBand;

    MOVE(4); /* counting previous operations */

    PTR_INIT(1); /* hTonCorr->indexVector[] */
    ADD(1); LOOP(1);
    for(k = 0; k < (targetStart- startGuardBand); k++)
    {
      MULT(1); STORE(1);
      hTonCorr->indexVector[startGuardBand+k] = -1;
    }

    PTR_INIT(1); /* hTonCorr->indexVector[] */
    LOOP(1);
    for(k = 0; k < numberOfBands; k++)
    {
      ADD(1); STORE(1);
      hTonCorr->indexVector[targetStart+k] = sourceStart+k;
    }
  }

  COUNT_sub_end();

  return (0);
}
Example #27
0
/*
 * \brief Perform transposition by patching of subband samples.
 */
void lppTransposer (HANDLE_SBR_LPP_TRANS hLppTrans,
                    float **qmfBufferReal,
#ifndef LP_SBR_ONLY
                    float **qmfBufferImag,
#endif
                    float *degreeAlias,
                    int timeStep,
                    int firstSlotOffs,
                    int lastSlotOffs,
                    unsigned char nInvfBands,
                    INVF_MODE *sbr_invf_mode,
                    INVF_MODE *sbr_invf_mode_prev,
                    int   bUseLP
                    )
{
  int    bwIndex[MAX_NUM_PATCHES];
  float  bwVector[MAX_NUM_PATCHES];

  int    i,j;
  int    loBand, hiBand;

  PATCH_PARAM *patchParam;

  int    patch;

  float  alphar[LPC_ORDER], a0r, a1r;
  float  alphai[LPC_ORDER], a0i, a1i;

  float  bw;

  int    autoCorrLength;

  float k1, k1_below, k1_below2;

  ACORR_COEFS ac;
  int    startSample;
  int    stopSample;
  int    stopSampleClear;
  int    lb, hb;

  int targetStopBand;

  COUNT_sub_start("lppTransposer");

  INDIRECT(1); PTR_INIT(1);
  patchParam = hLppTrans->pSettings->patchParam;

  MOVE(1);
  bw = 0.0f;

  MOVE(2);
  k1_below=0, k1_below2=0;

  MULT(1);
  startSample = firstSlotOffs * timeStep;

  INDIRECT(1); MULT(1); ADD(1);
  stopSample  = hLppTrans->pSettings->nCols + lastSlotOffs * timeStep;

  FUNC(5);
  inverseFilteringLevelEmphasis(hLppTrans, nInvfBands, sbr_invf_mode, sbr_invf_mode_prev, bwVector);


  MOVE(1);
  stopSampleClear = stopSample;

  PTR_INIT(2); /* pointers for qmfBufferReal[],
                               qmfBufferImag[]  */
  INDIRECT(1); LOOP(1);
  for ( patch = 0; patch < hLppTrans->pSettings->noOfPatches; patch++ ) {
    LOOP(1);
    for (i = startSample; i < stopSampleClear; i++) {
      INDIRECT(1); ADD(1); LOOP(1);
      for(j=patchParam[patch].guardStartBand; j<patchParam[patch].guardStartBand+GUARDBANDS; j++){
        MOVE(1);
        qmfBufferReal[i][j] = 0.0;
#ifndef LP_SBR_ONLY
        BRANCH(1);
        if (!bUseLP) {
          MOVE(1);
          qmfBufferImag[i][j] = 0.0;
        }
#endif
      }
    }
  }

  INDIRECT(4); ADD(1);
  targetStopBand = patchParam[hLppTrans->pSettings->noOfPatches-1].targetStartBand +
    patchParam[hLppTrans->pSettings->noOfPatches-1].numBandsInPatch;

  PTR_INIT(2); /* pointers for qmfBufferReal[],
                               qmfBufferImag[]  */
  LOOP(1);
  for (i = startSample; i < stopSampleClear; i++) {
    LOOP(1);
    for (j=targetStopBand; j<NO_SYNTHESIS_CHANNELS; j++) {
      MOVE(1);
      qmfBufferReal[i][j] = 0.0;
#ifndef LP_SBR_ONLY
      BRANCH(1);
      if (!bUseLP) {
        MOVE(1);
        qmfBufferImag[i][j] = 0.0;
      }
#endif
    }
  }

  INDIRECT(1); ADD(1);
  autoCorrLength = hLppTrans->pSettings->nCols + 6;

  PTR_INIT(1); /* pointer for bwIndex[patch] */
  INDIRECT(1); LOOP(1);
  for ( patch=0; patch<hLppTrans->pSettings->noOfPatches; patch++ ) {
    MOVE(1);
    bwIndex[patch] = 0;
  }



  BRANCH(1);
  if (bUseLP) {

    INDIRECT(1); ADD(1); BRANCH(1); MOVE(1);
    lb = max(1, hLppTrans->pSettings->lbStartPatching - 2);

    INDIRECT(1);
    hb = patchParam[0].targetStartBand;
  }
#ifndef LP_SBR_ONLY
  else {

    INDIRECT(2); MOVE(2);
    lb = hLppTrans->pSettings->lbStartPatching;
    hb = hLppTrans->pSettings->lbStopPatching;
  }
#endif


  PTR_INIT(2); /* pointers for qmfBufferReal[],
                               qmfBufferImag[]  */
  INDIRECT(1); LOOP(1);
  for ( loBand = lb; loBand < hb; loBand++ ) {

    float  lowBandReal[MAX_ENV_COLS+LPC_ORDER];
#ifndef LP_SBR_ONLY
    float  lowBandImag[MAX_ENV_COLS+LPC_ORDER];
#endif
    int lowBandPtr =0;
    int resetLPCCoeffs=0;

    PTR_INIT(4); /* pointers for lowBandReal[],
                                 lowBandImag[],
                                 lpcFilterStatesReal,
                                 lpcFilterStatesImag  */
    LOOP(1);
    for(i=0;i<LPC_ORDER;i++){
      MOVE(1);
      lowBandReal[lowBandPtr] = hLppTrans->lpcFilterStatesReal[i][loBand];

#ifndef LP_SBR_ONLY
      if (!bUseLP) {
        MOVE(1);
        lowBandImag[lowBandPtr] = hLppTrans->lpcFilterStatesImag[i][loBand];
      }
#endif
      lowBandPtr++;
    }

    LOOP(1);
    for(i=0;i< 6;i++){

      MOVE(1);
      lowBandReal[lowBandPtr] = (float) qmfBufferReal[i][loBand];

#ifndef LP_SBR_ONLY
      BRANCH(1);
      if (!bUseLP) {
        MOVE(1);
        lowBandImag[lowBandPtr] = (float) qmfBufferImag[i][loBand];
      }
#endif
      lowBandPtr++;
    }


    INDIRECT(1); ADD(1); LOOP(1);
    for(i=6;i<hLppTrans->pSettings->nCols+6;i++){

        MOVE(1);
        lowBandReal[lowBandPtr] = (float) qmfBufferReal[i][loBand];

#ifndef LP_SBR_ONLY
        BRANCH(1);
        if (!bUseLP) {
          MOVE(1);
          lowBandImag[lowBandPtr] = (float) qmfBufferImag[i][loBand];
        }
#endif
        lowBandPtr++;
    }


    BRANCH(1);
    if (bUseLP) {
      PTR_INIT(1); ADD(1); FUNC(3);
      autoCorrelation2ndLP(&ac,
                           lowBandReal+LPC_ORDER,
                           autoCorrLength);
    }
#ifndef LP_SBR_ONLY
    else {
      PTR_INIT(1); ADD(2); FUNC(3);
      autoCorrelation2nd(&ac,
                         lowBandReal+LPC_ORDER,
                         lowBandImag+LPC_ORDER,
                         autoCorrLength);
    }
#endif

    MOVE(2);
    alphar[1] = 0;
    alphai[1] = 0;

    INDIRECT(1); BRANCH(1);
    if (ac.det != 0.0f) {
      float fac;

      DIV(1);
      fac = 1.0f / ac.det;

      MULT(4); ADD(2); STORE(1);
      alphar[1] = ( ac.r01r * ac.r12r - ac.r01i * ac.r12i - ac.r02r * ac.r11r ) * fac;

#ifndef LP_SBR_ONLY
      BRANCH(1);
      if (!bUseLP) {
        MULT(3); MAC(1); ADD(1); STORE(1);
        alphai[1] = ( ac.r01i * ac.r12r + ac.r01r * ac.r12i - ac.r02i * ac.r11r ) * fac;
      }
#endif
    }

    MOVE(2);
    alphar[0] = 0;
    alphai[0] = 0;


    INDIRECT(1); BRANCH(1);
    if ( ac.r11r != 0.0f ) {
      float fac;

      DIV(1);
      fac = 1.0f / ac.r11r;

      MULT(3); MAC(1); ADD(1); STORE(1);
      alphar[0] = - ( ac.r01r + alphar[1] * ac.r12r + alphai[1] * ac.r12i ) * fac;

#ifndef LP_SBR_ONLY
      BRANCH(1);
      if (!bUseLP) {
        MULT(4); ADD(2); STORE(1);
        alphai[0] = - ( ac.r01i + alphai[1] * ac.r12r - alphar[1] * ac.r12i ) * fac;
      }
#endif

    }
    
    MULT(1); MAC(1); ADD(1); BRANCH(1);
    if(alphar[0]*alphar[0] + alphai[0]*alphai[0] >= 16.0f) {
      MOVE(1);
      resetLPCCoeffs=1;
    }
    MULT(1); MAC(1); ADD(1); BRANCH(1);
    if(alphar[1]*alphar[1] + alphai[1]*alphai[1] >= 16.0f) {
      MOVE(1);
      resetLPCCoeffs=1;
    }

    BRANCH(1);
    if(resetLPCCoeffs){
      MOVE(4);
      alphar[0] = alphar[1] = 0;
      alphai[0] = alphai[1] = 0;
    }

    BRANCH(1);
    if (bUseLP) {

      INDIRECT(1); BRANCH(1);
      if(ac.r11r==0.0f) {
        MOVE(1);
        k1 = 0.0f;
      }
      else {
        INDIRECT(2); DIV(1); MULT(1);
        k1 = -(ac.r01r/ac.r11r);

        ADD(1); BRANCH(1); MOVE(1);
        k1 = min(k1, 1.0f);
        ADD(1); BRANCH(1); MOVE(1);
        k1 = max(k1,-1.0f);
      }

      ADD(1); BRANCH(1);
      if(loBand > 1){
        float deg;

        MULT(1); ADD(1);
        deg = 1.0f - (k1_below * k1_below);

        MOVE(1);
        degreeAlias[loBand] = 0;

        PTR_INIT(1); /* pointer for degreeAlias[] */

        LOGIC(2); BRANCH(1);
        if (((loBand & 1) == 0) && (k1 < 0)){

          BRANCH(1);
          if (k1_below < 0) {

            MOVE(1);
            degreeAlias[loBand] = 1.0f;

            BRANCH(1);
            if ( k1_below2 > 0 ) {

              MOVE(1);
              degreeAlias[loBand-1] = deg;
            }
          }
          else {
            BRANCH(1);
            if ( k1_below2 > 0 ) {
              MOVE(1);
              degreeAlias[loBand] = deg;
            }
          }
        }

        LOGIC(2); BRANCH(1);
        if (((loBand & 1) == 1) && (k1 > 0)){

          BRANCH(1);
          if (k1_below > 0) {

            MOVE(1);
            degreeAlias[loBand] = 1.0f;

            BRANCH(1);
            if ( k1_below2 < 0 ) {

              MOVE(1);
              degreeAlias[loBand-1] = deg;
            }
          }
          else {
            BRANCH(1);
            if ( k1_below2 < 0 ) {
              MOVE(1);
              degreeAlias[loBand] = deg;
            }
          }
        }
      }
      MOVE(2);
      k1_below2 = k1_below;
      k1_below = k1;
    }

    MOVE(1);
    patch = 0;

    PTR_INIT(1); /* pointer for patchParam[patch] */
    INDIRECT(1); LOOP(1);
    while ( patch < hLppTrans->pSettings->noOfPatches ) {

      ADD(1);
      hiBand = loBand + patchParam[patch].targetBandOffs;

      ADD(2); LOGIC(1); BRANCH(1);
      if ( loBand < patchParam[patch].sourceStartBand || loBand >= patchParam[patch].sourceStopBand ) {
        ADD(1);
        patch++;
        continue;
      }
      assert( hiBand < NO_SYNTHESIS_CHANNELS );

      LOOP(1);
      while (hiBand >= hLppTrans->pSettings->bwBorders[bwIndex[patch]]) {
        INDIRECT(1); /* while() condition */

        ADD(1); STORE(1);
        bwIndex[patch]++;
      }

      INDIRECT(1);
      bw = bwVector[bwIndex[patch]];

      INDIRECT(4); MULT(5);
      a0r = bw * alphar[0];
      a0i = bw * alphai[0];
      bw =  bw*bw;
      a1r = bw * alphar[1];
      a1i = bw * alphai[1];


      PTR_INIT(4); /* pointers for lowBandReal[],
                                   lowBandImag[],
                                   qmfBufferReal[],
                                   qmfBufferImag[]  */
      LOOP(1);
      for(i = startSample; i < stopSample; i++ ) {

        MOVE(1);
        qmfBufferReal[i][hiBand] = lowBandReal[LPC_ORDER+i];

        BRANCH(1);
        if (bUseLP) {

          BRANCH(1);
          if ( bw > 0 ) {

            MAC(2); STORE(1);
            qmfBufferReal[i][hiBand] = qmfBufferReal[i][hiBand] +
              a0r * lowBandReal[LPC_ORDER+i-1] +
              a1r * lowBandReal[LPC_ORDER+i-2];
          }
        }
#ifndef LP_SBR_ONLY
        else {

          MOVE(1);
          qmfBufferImag[i][hiBand] = lowBandImag[LPC_ORDER+i];

          BRANCH(1);
          if ( bw > 0 ) {
            float accu;

            MULT(4); ADD(3);
            accu = a0r * lowBandReal[LPC_ORDER+i-1] -  a0i * lowBandImag[LPC_ORDER+i-1]+
              a1r * lowBandReal[LPC_ORDER+i-2] -  a1i * lowBandImag[LPC_ORDER+i-2];

            ADD(1); STORE(1);
            qmfBufferReal[i][hiBand] = qmfBufferReal[i][hiBand] + accu;

            MAC(4);
            accu = a0i * lowBandReal[LPC_ORDER+i-1] +  a0r * lowBandImag[LPC_ORDER+i-1]+
              a1i * lowBandReal[LPC_ORDER+i-2] +  a1r * lowBandImag[LPC_ORDER+i-2];

            ADD(1); STORE(1);
            qmfBufferImag[i][hiBand] = qmfBufferImag[i][hiBand] + accu;
          }
        }
#endif

      }


      patch++;

    }  /* Patch */

  }  /* loBand (band) */


  PTR_INIT(4); /* pointers for lpcFilterStatesReal[][loBand],
                               lpcFilterStatesImag[][loBand],
                               qmfBufferReal[],
                               qmfBufferImag[]  */
  LOOP(1);
  for(i=0;i<LPC_ORDER;i++){
    INDIRECT(1); LOOP(1);
    for (loBand=0; loBand<patchParam[0].targetStartBand; loBand++) {
      MOVE(1);
      hLppTrans->lpcFilterStatesReal[i][loBand] = qmfBufferReal[hLppTrans->pSettings->nCols-LPC_ORDER+i][loBand];
#ifndef LP_SBR_ONLY
      BRANCH(1);
      if (!bUseLP) {
        MOVE(1);
        hLppTrans->lpcFilterStatesImag[i][loBand] = qmfBufferImag[hLppTrans->pSettings->nCols-LPC_ORDER+i][loBand];
      }
#endif
    }
  }

  BRANCH(1);
  if (bUseLP) {

    PTR_INIT(2); /* pointers for degreeAlias[loBand],
                                 degreeAlias[hiBand]  */
    INDIRECT(2); LOOP(1);
    for ( loBand = hLppTrans->pSettings->lbStartPatching; loBand <  hLppTrans->pSettings->lbStopPatching; loBand++ ) {

      MOVE(1);
      patch = 0;

      INDIRECT(1); LOOP(1);
      while ( patch < hLppTrans->pSettings->noOfPatches ) {

        INDIRECT(1); ADD(1);
        hiBand = loBand + patchParam[patch].targetBandOffs;

        LOGIC(2); ADD(3); BRANCH(1);
        if ( loBand < patchParam[patch].sourceStartBand
             || loBand >= patchParam[patch].sourceStopBand
             || hiBand >= NO_SYNTHESIS_CHANNELS
             ) {
          ADD(1);
          patch++;
          continue;
        }

        INDIRECT(1); ADD(1); BRANCH(1);
        if(hiBand != patchParam[patch].targetStartBand) {
          MOVE(1);
          degreeAlias[hiBand] = degreeAlias[loBand];
        }
        else {
          MOVE(1);
          degreeAlias[hiBand] = 0;
        }

        patch++;
      }
    }/* end  for loop */
  }

  PTR_INIT(2); /* pointers for bwVectorOld[],
                               bwVector[]     */
  LOOP(1);
  for (i = 0; i < nInvfBands; i++ ) {
    MOVE(1);
    hLppTrans->bwVectorOld[i] = bwVector[i];
  }

  COUNT_sub_end();
}
Example #28
0
/*****************************************************************************

 description:  initializes parameters and allocates memory
 returns:      error status

*****************************************************************************/
int
EnvOpen (HANDLE_SBR_ENCODER * hEnvEncoder,
         float *pCoreBuffer,
         sbrConfigurationPtr params,
         int      *coreBandWith)
{
  HANDLE_SBR_ENCODER hEnvEnc ;
  int ch;

  COUNT_sub_start("EnvOpen");

  MOVE(1);
  *hEnvEncoder=0;

  PTR_INIT(1);
  hEnvEnc = &sbrEncoder;

  PTR_INIT(2); /* hEnvEnc->hEnvChannel[]
                  EnvChannel[]
               */
  LOOP(1);
  for (ch=0; ch<MAX_CHANNELS; ch++)
  {
    PTR_INIT(1);
    hEnvEnc->hEnvChannel[ch] = &EnvChannel[ch];
  }

  INDIRECT(2); ADD(2); LOGIC(1); BRANCH(1);
  if ((params->codecSettings.nChannels < 1) || (params->codecSettings.nChannels > MAX_CHANNELS)){

    FUNC(1);
    EnvClose (hEnvEnc);

    COUNT_sub_end();
    return(1);
  }


  INDIRECT(1); PTR_INIT(1);
  hEnvEnc->sbrConfigData.freqBandTable[LO] =  sbr_freqBandTableLO;

  FUNC(2); LOOP(1); PTR_INIT(1); MOVE(1); STORE(MAX_FREQ_COEFFS/2+1);
  memset(hEnvEnc->sbrConfigData.freqBandTable[LO],0,sizeof(unsigned char)*MAX_FREQ_COEFFS/2+1);

  INDIRECT(1); PTR_INIT(1);
  hEnvEnc->sbrConfigData.freqBandTable[HI] =  sbr_freqBandTableHI;

  FUNC(2); LOOP(1); PTR_INIT(1); MOVE(1); STORE(MAX_FREQ_COEFFS+1);
  memset(hEnvEnc->sbrConfigData.freqBandTable[HI],0,sizeof(unsigned char)*MAX_FREQ_COEFFS+1);

  INDIRECT(1); PTR_INIT(1);
  hEnvEnc->sbrConfigData.v_k_master =  sbr_v_k_master;

  FUNC(2); LOOP(1); PTR_INIT(1); MOVE(1); STORE(MAX_FREQ_COEFFS+1);
  memset(hEnvEnc->sbrConfigData.v_k_master,0,sizeof(unsigned char)*MAX_FREQ_COEFFS+1);

  INDIRECT(1); BRANCH(1);
  if (hEnvEnc->CmonData.sbrBitbuf.isValid == 0) {

    INDIRECT(2); PTR_INIT(1); FUNC(3);
    CreateBitBuffer(&hEnvEnc->CmonData.sbrBitbuf,
                    (unsigned char*) hEnvEnc->sbrPayload,
                    sizeof(hEnvEnc->sbrPayload));
  }

  INDIRECT(1); BRANCH(1);
  if (hEnvEnc->CmonData.sbrBitbufPrev.isValid == 0) {

    INDIRECT(2); PTR_INIT(1); FUNC(3);
    CreateBitBuffer(&hEnvEnc->CmonData.sbrBitbufPrev,
                    (unsigned char*) hEnvEnc->sbrPayloadPrevious,
                    sizeof(hEnvEnc->sbrPayload));
  }

  INDIRECT(2); MOVE(1);
  hEnvEnc->sbrConfigData.nChannels = params->codecSettings.nChannels;

  INDIRECT(1); ADD(1); BRANCH(1);
  if(params->codecSettings.nChannels == 2)
  {
     INDIRECT(2); MOVE(1);
     hEnvEnc->sbrConfigData.stereoMode = params->stereoMode;
  }
  else
  {
     INDIRECT(1); MOVE(1);
     hEnvEnc->sbrConfigData.stereoMode = SBR_MONO;
  }






  INDIRECT(1); ADD(1); BRANCH(1);
  if (params->codecSettings.sampleFreq <= 24000) {

    INDIRECT(1); MOVE(1);
    hEnvEnc->sbrHeaderData.sampleRateMode = DUAL_RATE;

    INDIRECT(1); MULT(1); STORE(1);
    hEnvEnc->sbrConfigData.sampleFreq = 2 * params->codecSettings.sampleFreq;
  }
  else {

    INDIRECT(2); MOVE(2);
    hEnvEnc->sbrHeaderData.sampleRateMode = SINGLE_RATE;
    hEnvEnc->sbrConfigData.sampleFreq = params->codecSettings.sampleFreq;
  }


  INDIRECT(1); MOVE(1);
  hEnvEnc->sbrBitstreamData.CountSendHeaderData = 0;

  INDIRECT(1); BRANCH(1);
  if (params->SendHeaderDataTime > 0 ) {

    INDIRECT(2); MULT(2); DIV(1); STORE(1);
    hEnvEnc->sbrBitstreamData.NrSendHeaderData = (int)(params->SendHeaderDataTime * 0.001*
                                             hEnvEnc->sbrConfigData.sampleFreq / 2048
                                             );

    ADD(1); BRANCH(1); MOVE(1);
    hEnvEnc->sbrBitstreamData.NrSendHeaderData = max(hEnvEnc->sbrBitstreamData.NrSendHeaderData,1);
  }
  else {

   INDIRECT(1); MOVE(1);
   hEnvEnc->sbrBitstreamData.NrSendHeaderData = 0;
  }

  INDIRECT(10); MOVE(6);
  hEnvEnc->sbrHeaderData.sbr_data_extra = params->sbr_data_extra;
  hEnvEnc->sbrBitstreamData.CRCActive = params->crcSbr;
  hEnvEnc->sbrBitstreamData.HeaderActive = 0;
  hEnvEnc->sbrHeaderData.sbr_start_frequency = params->startFreq;
  hEnvEnc->sbrHeaderData.sbr_stop_frequency  = params->stopFreq;
  hEnvEnc->sbrHeaderData.sbr_xover_band = 0;

    INDIRECT(1); ADD(1); BRANCH(1);
    if (params->sbr_xpos_ctrl!= SBR_XPOS_CTRL_DEFAULT)
    {
       INDIRECT(1); MOVE(1);
       hEnvEnc->sbrHeaderData.sbr_data_extra = 1;
    }

   INDIRECT(1); MOVE(1);
   hEnvEnc->sbrHeaderData.protocol_version = SI_SBR_PROTOCOL_VERSION_ID;

   INDIRECT(2); MOVE(2);
   hEnvEnc->sbrHeaderData.sbr_amp_res = (AMP_RES)params->amp_res;



  INDIRECT(7); MOVE(4);
  hEnvEnc->sbrHeaderData.freqScale  = params->freqScale;
  hEnvEnc->sbrHeaderData.alterScale = params->alterScale;
  hEnvEnc->sbrHeaderData.sbr_noise_bands = params->sbr_noise_bands;
  hEnvEnc->sbrHeaderData.header_extra_1 = 0;

  ADD(3); LOGIC(2); BRANCH(1);
  if ((params->freqScale != SBR_FREQ_SCALE_DEFAULT) ||
      (params->alterScale != SBR_ALTER_SCALE_DEFAULT) ||
      (params->sbr_noise_bands != SBR_NOISE_BANDS_DEFAULT)) {

   MOVE(1);
   hEnvEnc->sbrHeaderData.header_extra_1 = 1;
  }

  INDIRECT(9); MOVE(5);
  hEnvEnc->sbrHeaderData.sbr_limiter_bands = params->sbr_limiter_bands;
  hEnvEnc->sbrHeaderData.sbr_limiter_gains = params->sbr_limiter_gains;
  hEnvEnc->sbrHeaderData.sbr_interpol_freq = params->sbr_interpol_freq;
  hEnvEnc->sbrHeaderData.sbr_smoothing_length = params->sbr_smoothing_length;
  hEnvEnc->sbrHeaderData.header_extra_2 = 0;

  ADD(4); LOGIC(3); BRANCH(1);
  if ((params->sbr_limiter_bands != SBR_LIMITER_BANDS_DEFAULT) ||
      (params->sbr_limiter_gains != SBR_LIMITER_GAINS_DEFAULT) ||
      (params->sbr_interpol_freq != SBR_INTERPOL_FREQ_DEFAULT) ||
      (params->sbr_smoothing_length != SBR_SMOOTHING_LENGTH_DEFAULT)) {

     MOVE(1);
     hEnvEnc->sbrHeaderData.header_extra_2 = 1;
  }

  INDIRECT(4); MOVE(2);
  hEnvEnc->sbrConfigData.detectMissingHarmonics    = params->detectMissingHarmonics;
  hEnvEnc->sbrConfigData.useParametricCoding       = params->parametricCoding;


  INDIRECT(2); PTR_INIT(2); FUNC(3); BRANCH(1);
  if(updateFreqBandTable(&hEnvEnc->sbrConfigData,
                         &hEnvEnc->sbrHeaderData,
                         QMF_CHANNELS)){
    FUNC(1);
    EnvClose (hEnvEnc);

    COUNT_sub_end();
    return(1);
  }


  PTR_INIT(1); /* hEnvEnc->hEnvChannel[] */
  INDIRECT(3); PTR_INIT(2); LOOP(1);
  for ( ch = 0; ch < hEnvEnc->sbrConfigData.nChannels; ch++ ) {

    FUNC(5); BRANCH(1);
    if(createEnvChannel(ch,
                        &hEnvEnc->sbrConfigData,
                        &hEnvEnc->sbrHeaderData,
                        hEnvEnc->hEnvChannel[ch],
                        params)){

      FUNC(1);
      EnvClose (hEnvEnc);

      COUNT_sub_end();
      return(1);
    }
  }


  INDIRECT(1); PTR_INIT(1);
  hEnvEnc->hPsEnc = NULL;


#ifndef MONO_ONLY

  INDIRECT(1); BRANCH(1);
  if (params->usePs)
  {
    INDIRECT(2); PTR_INIT(1); FUNC(2); BRANCH(1);
    if(createQmfBank (1, &hEnvEnc->hEnvChannel[1]->sbrQmf)){
      COUNT_sub_end();
      return (1);
    }
    INDIRECT(1); PTR_INIT(1); FUNC(3); BRANCH(1);
    if(CreateExtractSbrEnvelope (1,
                                 &hEnvEnc->hEnvChannel[1]->sbrExtractEnvelope,
                                 576
                                 )) {
      COUNT_sub_end();
      return(1);
    }

    INDIRECT(1); MOVE(1);
    hEnvEnc->hSynthesisQmfBank = &SynthesisQmfBank;

    INDIRECT(1); PTR_INIT(1); FUNC(1); BRANCH(1);
    if(CreateSynthesisQmfBank (hEnvEnc->hSynthesisQmfBank)){

      FUNC(1);
      DeleteSynthesisQmfBank ((HANDLE_SBR_QMF_FILTER_BANK*)&hEnvEnc->hSynthesisQmfBank);

      COUNT_sub_end();
      return 1;
    }

    INDIRECT(1); MOVE(1);
    hEnvEnc->hPsEnc = &psEncoder;

    INDIRECT(2); PTR_INIT(1); FUNC(2); BRANCH(1);
    if(CreatePsEnc (hEnvEnc->hPsEnc,
                    params->psMode)){

      FUNC(1);
      DeletePsEnc(&hEnvEnc->hPsEnc);

      COUNT_sub_end();
      return 1;
    }
  }
#endif /* #ifndef MONO_ONLY */

  INDIRECT(2); MOVE(1);
  hEnvEnc->CmonData.sbrNumChannels  = hEnvEnc->sbrConfigData.nChannels;

  INDIRECT(1); MOVE(1);
  hEnvEnc->sbrPayloadSize = 0;

  INDIRECT(1); MOVE(2);
  *hEnvEncoder = hEnvEnc;
  *coreBandWith = hEnvEnc->sbrConfigData.xOverFreq;

  COUNT_sub_end();

  return 0;
}
Example #29
0
void FFRaacplus_checkForPayload(HANDLE_BIT_BUF bs,
                                SBRBITSTREAM *streamSBR,
                                int prev_element)
{
  int i;
  int count=0;
  int esc_count=0;

  FLC_sub_start("FFRaacplus_checkForPayload");

  MOVE(2); /* counting previous operations */


  FUNC(2);
  count = ReadBits(bs,4);

  ADD(1); BRANCH(1);
  if (count == 15)
  {
    FUNC(2);
    esc_count = ReadBits(bs,8);

    ADD(1);
    count =  esc_count + 14;
  }

  BRANCH(1);
  if (count)
  {
     unsigned char extension_type;

    FUNC(2);
    extension_type = (unsigned char) ReadBits(bs,4);


    ADD(8); LOGIC(7); BRANCH(1);
    if (   (prev_element == SBR_ID_SCE || prev_element == SBR_ID_CPE)
        && ((extension_type == SBR_EXTENSION) || (extension_type == SBR_EXTENSION_CRC) || (extension_type == SBR_EXTENSION_MPEG) || (extension_type == SBR_EXTENSION_CRC_MPEG))
        && (count < MAXSBRBYTES) && (streamSBR->NrElements < MAXNRELEMENTS)    )
    {
      FUNC(2); INDIRECT(1); STORE(1);
      streamSBR->sbrElement [streamSBR->NrElements].Data[0] = (unsigned char) ReadBits(bs,4);

      PTR_INIT(1); /* streamSBR->sbrElement [streamSBR->NrElements].Data[i] */
      LOOP(1);
      for (i=1; i<count; i++)
      {
        FUNC(2); STORE(1);
        streamSBR->sbrElement [streamSBR->NrElements].Data[i] = (unsigned char) ReadBits(bs,8);
      }

      MOVE(2);
      streamSBR->sbrElement[streamSBR->NrElements].ExtensionType = extension_type;
      streamSBR->sbrElement[streamSBR->NrElements].Payload = count;

      ADD(1); INDIRECT(1); STORE(1);
      streamSBR->NrElements += 1;
    }
    else
    {
      FUNC(2);
      ReadBits(bs,4);

      LOOP(1);
      for (i=1; i<count; i++)
      {
        FUNC(2);
        ReadBits(bs,8);
      }
    }
  }

  FLC_sub_end();
}
Example #30
0
/*!
  \brief     SBR decoder processing

 \return SBRDEC_OK if successfull, else error code
*/
SBR_ERROR
applySBR (SBRDECODER self,
          SBRBITSTREAM * Bitstr,
          float *timeData,
          float *workBufferCore,
		  int *numChannels,
          int SbrFrameOK,
          int bDownSample,
          int bBitstreamDownMix
          )
{
  unsigned char i;
  unsigned char dualMono = 0;
  int stereo = 0;
  int CRCLen = 0;
  int crcEnable = 0;
  int readHeader = 0;
  int err = 0;


  SBR_CHANNEL *SbrChannel = &self->SbrChannel[0];
  BIT_BUFFER bitBuf;
  HANDLE_SBR_HEADER_DATA_DEC hHeaderData = &self->sbr_header;
  SBR_HEADER_STATUS headerStatus = HEADER_NOT_INITIALIZED;
  int codecFrameSize = hHeaderData->codecFrameSize;
  SBR_SYNC_STATE initialSyncState = hHeaderData->syncState;
  HANDLE_SBR_CONCEAL_DATA hConcealData = &self->SbrConcealData;

  float * pWorkBuffer1 = &timeData[2*codecFrameSize];

  SBR_FRAME_DATA *hFrameDataLeft  = (SBR_FRAME_DATA*) pWorkBuffer1;
  SBR_FRAME_DATA *hFrameDataRight = (SBR_FRAME_DATA*) self->InterimResult;
  assert( sizeof(SBR_FRAME_DATA) <= MAX_FRAME_SIZE*sizeof(float));

  self->SbrChannel->SbrDec.workBuffer2 = workBufferCore;
  FLC_sub_start("applySBR");

  INDIRECT(5); MOVE(9); PTR_INIT(6); /* counting previous operations */

  PTR_INIT(1); FUNC(3);
  DelaySbrBitstr(hConcealData, Bitstr, &SbrFrameOK);


  INDIRECT(1); BRANCH(1);
  if (Bitstr->NrElements) {

    PTR_INIT(6); /* Bitstr->sbrElement[]
                    SbrChannel[]
                    hHeaderData
                    hFrameDataLeft
                    hFrameDataRight
                    bitBuf
                 */
    INDIRECT(1); LOOP(1);
    for (i=0; i<Bitstr->NrElements; i++) {

      /* Save last error flag */
      MOVE(1);
      hHeaderData->prevFrameErrorFlag = hHeaderData->frameErrorFlag;

      ADD(1); BRANCH(1);
      if (Bitstr->NrElements == 2) {
        MOVE(1);
        dualMono = 1;
      }
      else {
        BRANCH(2);
        switch (Bitstr->sbrElement[i].ElementID) {
          case SBR_ID_SCE:
            MOVE(1);
            stereo = 0;
            break;

          case SBR_ID_CPE:
            MOVE(1);
            stereo = 1;
            break;

          default:
            MOVE(1);
            SbrFrameOK = 0;
        }
      }

      MULT(1); FUNC(3);
      initBitBuffer (&bitBuf,
                     Bitstr->sbrElement[i].Data,
                     Bitstr->sbrElement[i].Payload * 8) ;

      FUNC(2);
      getbits (&bitBuf, LEN_NIBBLE);


      BRANCH(1);
      if (SbrFrameOK) {

        ADD(1); BRANCH(1);
        if (Bitstr->sbrElement[i].ExtensionType == SBR_EXTENSION_CRC) {

          MOVE(1);
          crcEnable = 1;

          ADD(2); MULT(1);
          CRCLen = 8*(Bitstr->sbrElement[i].Payload-1)+4 - SI_SBR_CRC_BITS;

          BRANCH(1);
          if (CRCLen < 0) {

            MOVE(2);
            crcEnable = 0;
            SbrFrameOK = 0;
          }
        }


        BRANCH(1);
        if (crcEnable)
        {
          FUNC(2);
          SbrFrameOK = SbrCrcCheck (&bitBuf,
                                    CRCLen);
        }

        FUNC(2);
        readHeader = getbits (&bitBuf, 1);

        BRANCH(1);
        if (SbrFrameOK){
          int lr;

          FUNC(1);
          if (readHeader) {

            FUNC(3);
            headerStatus = sbrGetHeaderData (hHeaderData,
                                             &bitBuf,
                                             (SBR_ELEMENT_ID)Bitstr->sbrElement[i].ElementID);

            ADD(1); BRANCH(1);
            if (headerStatus == HEADER_NOT_INITIALIZED) {
              FLC_sub_end();
              return SBRDEC_NOT_INITIALIZED;
            }

            ADD(1); BRANCH(1);
            if (headerStatus == HEADER_RESET) {
              FUNC(1);
              err = resetFreqBandTables(hHeaderData);

              PTR_INIT(1); /* SbrChannel[] */
              LOOP(1);
              for (lr = 0 ; lr < MAXNRSBRCHANNELS; lr++) {
                INDIRECT(1); PTR_INIT(1); FUNC(1);
                resetSbrEnvelopeCalc (&(SbrChannel[lr].SbrDec.SbrCalculateEnvelope));
              }

 PTR_INIT(1); /* SbrChannel[] */
              LOOP(1);
              for (lr = 0 ; lr < MAXNRQMFCHANNELS; lr++) {
#ifdef NON_BE_BUGFIX
                PTR_INIT(1); FUNC(5);
#else
                PTR_INIT(1); FUNC(4);
#endif
                err |= resetSbrQMF (&(SbrChannel[lr].SbrDec),
                                    hHeaderData,
                                    lr,
#ifdef NON_BE_BUGFIX
                                    *numChannels,
#endif
                                    SbrChannel[lr].hPrevFrameData);
              }

              BRANCH(1);
              if (err==0) {

                MOVE(1);
                hHeaderData->syncState = SBR_ACTIVE;
              }
            }
          } // if (readHeader)

          ADD(1); LOGIC(1); BRANCH(1);
          if (err || hHeaderData->syncState == SBR_NOT_INITIALIZED) {

            ADD(1); LOGIC(1); BRANCH(1);
            if (err && hHeaderData->syncState == SBR_NOT_INITIALIZED) {
              FLC_sub_end();
              return SBRDEC_NOT_INITIALIZED;
            }

            SHIFT(1); FUNC(3);
            initHeaderData( hHeaderData,
                            hHeaderData->outSampleRate >> 1,
                            codecFrameSize);

            FUNC(1);
            err = resetFreqBandTables(hHeaderData);

            MOVE(2);
            hHeaderData->FreqBandData.lowSubband = NO_ANALYSIS_CHANNELS;
            hHeaderData->FreqBandData.highSubband = NO_ANALYSIS_CHANNELS;

            PTR_INIT(1); /* SbrChannel[lr] */
            LOOP(1);
            for (lr = 0 ; lr < MAXNRSBRCHANNELS; lr++) {
              INDIRECT(1); PTR_INIT(1); FUNC(1);
              resetSbrEnvelopeCalc (&(SbrChannel[lr].SbrDec.SbrCalculateEnvelope));
            }

            PTR_INIT(1); /* SbrChannel[lr] */
            LOOP(1);
            for (lr = 0 ; lr < MAXNRQMFCHANNELS; lr++) {
#ifdef NON_BE_BUGFIX
              PTR_INIT(1); FUNC(5);
#else
              PTR_INIT(1); FUNC(4);
#endif
              err |= resetSbrQMF (&(SbrChannel[lr].SbrDec),
                                  hHeaderData,
                                  lr,
#ifdef NON_BE_BUGFIX
                                  *numChannels,
#endif
                                  SbrChannel[lr].hPrevFrameData);
            }

            MOVE(1);
            hHeaderData->syncState = UPSAMPLING;
          }


          ADD(1); BRANCH(1);
          if (hHeaderData->syncState == SBR_ACTIVE) {


            BRANCH(1);
            if (dualMono) {

              BRANCH(1);
              if (i == 0) {

                BRANCH(1); MOVE(1);
                hFrameDataLeft->xposCtrl = max(0, SbrChannel[i].hPrevFrameData->xposCtrl);

                FUNC(4);
                SbrFrameOK = sbrGetSingleChannelElement(hHeaderData,
                                                        hFrameDataLeft,
                                                        NULL,
                                                        &bitBuf);
              }
              else {

                BRANCH(1); MOVE(1);
                hFrameDataRight->xposCtrl = max(0, SbrChannel[i].hPrevFrameData->xposCtrl);

                FUNC(4);
                SbrFrameOK = sbrGetSingleChannelElement(hHeaderData,
                                                        hFrameDataRight,
                                                        NULL,
                                                        &bitBuf);
              }
            }
            else {
              BRANCH(1); MOVE(1);
              hFrameDataLeft->xposCtrl = max(0, SbrChannel[i].hPrevFrameData->xposCtrl);

              BRANCH(1);
              if (stereo) {

                BRANCH(1); MOVE(1);
                hFrameDataRight->xposCtrl = max(0, SbrChannel[i+1].hPrevFrameData->xposCtrl);

                FUNC(4);
                SbrFrameOK = sbrGetChannelPairElement(hHeaderData,
                                                      hFrameDataLeft,
                                                      hFrameDataRight,
                                                      &bitBuf);
              }
              else
              {


                BRANCH(1);
                if (bBitstreamDownMix)
                {
                  MOVE(1);
                  self->ParametricStereoDec.bForceMono = 1;
                }
                else
                {
                  MOVE(1);
                  self->ParametricStereoDec.bForceMono = 0;
                }

                FUNC(4);
                SbrFrameOK = sbrGetSingleChannelElement(hHeaderData,
                                                        hFrameDataLeft,
                                                        &self->ParametricStereoDec,
                                                        &bitBuf);
              }
            }
            {
              int payloadbits = GetNrBitsRead (&bitBuf);
              int fillbits = (8 - (payloadbits & 7)) & 7;

              FUNC(1); ADD(1); LOGIC(2); /* counting previous operations */

              ADD(2); MULT(1); BRANCH(1);
              if ((payloadbits + fillbits) != 8 * Bitstr->sbrElement[i].Payload)
              {
                MOVE(1);
                SbrFrameOK = 0;
              }
            }
           }
        }
      }

      ADD(1); LOGIC(1); BRANCH(1);
      if (!SbrFrameOK || headerStatus == CONCEALMENT) {

        MOVE(1);
        hHeaderData->frameErrorFlag = 1;
      }
    }