static Ipp32s sbrCalcAliasDegree(Ipp32f *ref, Ipp32f *deg, Ipp32s k0)
{
  Ipp32s  sign = 0;
  Ipp32s  k;

  ippsZero_32f(deg, k0);
  ref[0] = 0.0f;
  deg[1] = 0.0f;

  for (k = 2; k < k0; k++) {
    if ((k % 2 == 0) && (ref[k] < 0.0f)) {
      sign = 1;
    } else if ((k % 2 == 1) && (ref[k] > 0.0f)) {
      sign = -1;
    } else {
      sign = 0;
      continue;
    }

    if (sign * ref[k - 1] < 0) {
      deg[k] = 1.0f;
      if (sign * ref[k - 2] > 0.0f) {
        deg[k - 1] = 1 - ref[k - 1] * ref[k - 1];
      }
    } else {
      if (sign * ref[k - 2] > 0.0f) {
        deg[k] = 1 - ref[k - 1] * ref[k - 1];
      }
    }
  }

  return 0;     // OK
}
Esempio n. 2
0
static USC_Status Reinit_VAD_G729FP(const USC_FilterModes *modes, USC_Handle handle )
{
    G729_Handle_Header *g729_header;
    VADmemory *VadObj;

    Ipp32s i;
    Ipp32s fltsize;
    void* pBuf;
    Ipp8s* oldMemBuff;

    USC_CHECK_PTR(modes);
    USC_CHECK_HANDLE(handle);
    USC_BADARG(modes->vad > 1, USC_UnsupportedVADType);
    USC_BADARG(modes->vad < 0, USC_UnsupportedVADType);

    g729_header = (G729_Handle_Header*)handle;

    g729_header->vad = modes->vad;
    VadObj = (VADmemory *)((Ipp8s*)handle + sizeof(G729_Handle_Header));
   if(NULL==VadObj)
      return USC_BadArgument;

   oldMemBuff = VadObj->Mem.base; /* if Reinit */
   ippsZero_32f(VadObj->OldSpeechBuffer, SPEECH_BUFF_LEN);

   ippsZero_16s((Ipp16s*)VadObj,sizeof(VADmemory)>>1) ;

   VadObj->objPrm.objSize = vadObjSize();
   VadObj->objPrm.mode = g729_header->vad;
   VadObj->objPrm.key = ENC_KEY;

   pBuf = (Ipp8s*)VadObj + sizeof(VADmemory);
   ippsIIRGetStateSize_32f(2,&fltsize);
   VadObj = (VADmemory *)((Ipp8s*)pBuf + fltsize);
   VADGetSize(&fltsize);

   /* Static vectors to zero */
   for(i=0; i<MOVING_AVER_ORDER; i++)
   VadObj->sFrameCounter = 0;
   /* For G.729B */
   /* Initialize VAD/DTX parameters */
   //if(mode == G729Encode_VAD_Enabled) {
      VadObj->prevVADDec = 1;
      VadObj->prevPrevVADDec = 1;
      VADInit((Ipp8s*)VadObj);
   //}

    if(oldMemBuff==NULL) return USC_BadArgument;
    if(VadObj==NULL) return USC_BadArgument;

    if(NULL==VadObj || NULL==oldMemBuff)
       return USC_BadArgument;

    VadObj->Mem.base = oldMemBuff;
    VadObj->Mem.CurPtr = VadObj->Mem.base;
    VadObj->Mem.VecPtr = (Ipp32s *)(VadObj->Mem.base+VAD_G729FP_LOCAL_MEMORY_SIZE);

    return USC_NoError;
}
Esempio n. 3
0
void IQSSBDemodulator::setFilter(Ipp64f lowFreq, Ipp64f highFreq)
{
	_lowFreq = lowFreq;
	_highFreq = highFreq;
	ippsZero_32f(_fir_taps_re, NFFT);
	ippsZero_32f(_fir_taps_im, NFFT);
	Ipp64f* fir_tmp = ippsMalloc_64f(_taps_len);
	ippsFIRGenBandpass_64f(_lowFreq, _highFreq, fir_tmp, _taps_len,
	                       ippWinHamming, ippTrue);
	ippsConvert_64f32f(fir_tmp, _fir_taps_re, _taps_len);
	ippsFree(fir_tmp);

	ippsFFTFwd_CToC_32f_I(_fir_taps_re, _fir_taps_im,
	                       _fft_specs, _fft_buf);
	ippsCartToPolar_32f(_fir_taps_re, _fir_taps_im,
	                    _fir_taps_m, _fir_taps_p,
	                    NFFT);
}
static Ipp32s
sbrencTotalDetectionSinEst(Ipp32f bufT[][64],
                           Ipp32f bufDiff[][64],
                           Ipp32s nBand,
                           Ipp32s* pFreqTab,
                           Ipp32f bufSfmOrig[][64],
                           Ipp32f bufSfmSBR[][64],
                           Ipp32s bufDetection[][64],

                           Ipp32s* prev_bs_add_harmonic,
                           sSBRGuideData* pGuideState,

                           Ipp32s noEstPerFrame,
                           Ipp32s totNoEst,
                           Ipp32s newDetectionAllowed,
                           Ipp32s* bs_add_harmonic)
{
  Ipp32s est = 0;
  Ipp32s start = (newDetectionAllowed) ? noEstPerFrame : 0;
  Ipp32s band;

  ippsZero_32s(bs_add_harmonic, nBand);

  /* ******************************
   * up-date buffers
   * ****************************** */

  if(newDetectionAllowed){

    ippsCopy_32f(pGuideState[0].bufGuideDiff, pGuideState[noEstPerFrame].bufGuideDiff, nBand);
    ippsCopy_32f(pGuideState[0].bufGuideOrig, pGuideState[noEstPerFrame].bufGuideOrig, nBand);

    ippsZero_32s(pGuideState[noEstPerFrame-1].bufGuideDetect, nBand);
  }

  for(est = start; est < totNoEst; est++){

    if(est > 0){
      ippsCopy_32s(bufDetection[est-1], pGuideState[est].bufGuideDetect, nBand);
    }

    ippsZero_32s(bufDetection[est], nBand);

    band = (est < totNoEst-1) ? est+1 : est;

    ippsZero_32f(pGuideState[band].bufGuideDiff,   nBand);
    ippsZero_32f(pGuideState[band].bufGuideOrig,   nBand);
    ippsZero_32s(pGuideState[band].bufGuideDetect, nBand);

    /* ******************************
     * main detection algorithm
     * ****************************** */

    sbrencDetectionSinEst(bufT[est],
                          bufDiff[est],
                          bufDetection[est],
                          pFreqTab,
                          nBand,
                          bufSfmOrig[est],
                          bufSfmSBR[est],
                          pGuideState[est],
                          pGuideState[band]);
  }

  /* *******************************************
   * additional step: because there is transient
   * ******************************************* */
  if(newDetectionAllowed){

      sbrencTransientCorrection(bufT,
                                bufDetection,
                                pFreqTab,
                                nBand,
                                pGuideState[noEstPerFrame],
                                start,
                                totNoEst);
  }

  /* *****************************************************
   * finally decision: merged
   * ***************************************************** */
  for(band = 0; band< nBand; band++){

    for(est = start; est < totNoEst; est++){

      bs_add_harmonic[band] = bs_add_harmonic[band] || bufDetection[est][band];
    }
  }

  /* *****************************************************
   * detections that were not present before are removed
   * ***************************************************** */
  if(!newDetectionAllowed){

    for(band=0; band < nBand; band++){

      if(bs_add_harmonic[band] - prev_bs_add_harmonic[band] > 0) {

        bs_add_harmonic[band] = 0;
      }
    }
  }

  return 0;//OK
}
static Ipp32s
sbrencCalcInDataSinEst(Ipp32f bufT[][64],
                       Ipp32f bufDiff[][64],
                       Ipp32f bufSfmOrig[][64],
                       Ipp32f bufSfmSBR[][64],
                       Ipp32s* indxMapTab,
                       Ipp32s* pFreqTab,
                       Ipp32s nBand)
{
#if !defined(ANDROID)
  IPP_ALIGNED_ARRAY(32, Ipp32f, tmpBuf, 64);
#else
  static IPP_ALIGNED_ARRAY(32, Ipp32f, tmpBuf, 64);
#endif
  Ipp32s est, k, idx;
//  Ipp32s p;
  Ipp32s i, iStart, iEnd;

  /* up-date buffer */
  for(est =  0 ; est < 2; est++){
    ippsCopy_32f(bufDiff[est + 2],    bufDiff[est],    64);
    ippsCopy_32f(bufSfmOrig[est + 2], bufSfmOrig[est], 64);
    ippsCopy_32f(bufSfmSBR[est + 2],  bufSfmSBR[est],  64);
  }

  /* AYA log */
#ifdef SBR_NEED_LOG
  fprintf(logFile, "\nSinesEstimation\n");
  fprintf(logFile, "\nDiff    origSfm    sbrSfm\n");
#endif

  /* detection input data */
  for(est = 2; est < 4; est++){
    /* AYA log */
#ifdef SBR_NEED_LOG
    fprintf(logFile, "band = %i\n", est);
#endif

    sbrencDiffEst( bufT[ est ], bufDiff[ est ], indxMapTab, pFreqTab, nBand );

    sbrencSfmEst( bufT[ est ], bufSfmOrig[ est ], pFreqTab, nBand );

    ippsZero_32f(tmpBuf, 64);
    for(k = 0; k < nBand; k++){
      iStart = pFreqTab[k];
      iEnd   = pFreqTab[k+1];
      for(i=iStart; i<iEnd; i++){

        idx = indxMapTab[i];
        if ( idx != EMPTY_MAPPING){
          tmpBuf[i] = bufT[est][ idx ];
        }
      }
    }

    sbrencSfmEst( tmpBuf, bufSfmSBR[ est ], pFreqTab, nBand );

    /* AYA */
#ifdef SBR_NEED_LOG
    for(p=0; p<nBand; p++){
      fprintf(logFile, "%15.10f %15.10f %15.10f\n", bufDiff[ est ][p], bufSfmOrig[ est ][p], bufSfmSBR[ est ][p]);
    }
#endif

  }

  return 0;//OK
}
void aac_MinMaxSF(sEnc_individual_channel_stream* pStream,
                  Ipp32f* mdct_scaled,
                  Ipp32s* startSF,
                  Ipp16s* scalefac,
                  Ipp16s* maxXQuant,
                  Ipp32s* minSf,
                  Ipp32s* maxSf,
                  Ipp32s  maxSfDelta)
{
  Ipp32s *sfb_offset = pStream->sfb_offset;
  Ipp32s *sfb_width = pStream->sfb_width;
  Ipp32s numSfb = pStream->num_window_groups * pStream->max_sfb;
  int sfb, update;

  minSf[0] = 100000;
  maxSf[0] = -100000;

  for (sfb = 0; sfb < numSfb; sfb++) {
    if (maxXQuant[sfb] != 0) {
      if (scalefac[sfb] > maxSf[0]) maxSf[0] = scalefac[sfb];
      if (scalefac[sfb] < minSf[0]) minSf[0] = scalefac[sfb];
    } else {
      ippsZero_32f(mdct_scaled + sfb_offset[sfb], sfb_width[sfb]);
    }
  }

  update = 0;
  if ((maxSf[0] - minSf[0]) > maxSfDelta) {
    for (sfb = 0; sfb < numSfb; sfb++) {
      if (maxXQuant[sfb] != 0) {
        /* very big difference */
        if ((minSf[0] + maxSfDelta) < startSF[sfb]) {
          minSf[0] = startSF[sfb] - maxSfDelta;
          update = 1;
        }
      }
    }
  }

  if (update == 1) {
    for (sfb = 0; sfb < numSfb; sfb++) {
      /* re quantization */
      if (scalefac[sfb] < minSf[0]) {
#if !defined(ANDROID)
        IPP_ALIGNED_ARRAY(32, Ipp32f, mdct_rqnt, N_LONG/2);
        IPP_ALIGNED_ARRAY(32, Ipp16s, x_quant_unsigned, N_LONG/2);
#else
        static IPP_ALIGNED_ARRAY(32, Ipp32f, mdct_rqnt, N_LONG/2);
        static IPP_ALIGNED_ARRAY(32, Ipp16s, x_quant_unsigned, N_LONG/2);
#endif
        Ipp32f sf = (Ipp32f)scalefac_pow[minSf[0] + SF_OFFSET];
        Ipp32f temp = (Ipp32f)(MAGIC_NUMBER - 0.5f)/sf;

        ippsAddC_32f(mdct_scaled + sfb_offset[sfb], temp, mdct_rqnt, sfb_width[sfb]);
        ippsMulC_Low_32f16s(mdct_rqnt, sf, x_quant_unsigned, sfb_width[sfb]);
        ippsMax_16s(x_quant_unsigned, sfb_width[sfb], maxXQuant + sfb);

        scalefac[sfb] = (Ipp16s)minSf[0];
      }
    }
  }

  if ((maxSf[0] - minSf[0]) > maxSfDelta) {
    for (sfb = 0; sfb < numSfb; sfb++) {
      if (maxXQuant[sfb] != 0) {
        if (scalefac[sfb] > minSf[0] + maxSfDelta)
          scalefac[sfb] = (Ipp16s)(minSf[0] + maxSfDelta);
      }
    }
    maxSf[0] = minSf[0] + maxSfDelta;
  }
}
static Ipp32s sbrHFGenerator(
                      /*
                       * in data
                       */
                              Ipp32f **XBuf,
                              Ipp32f *vbwArray,
                              Ipp32f *alpha_0,
                              Ipp32f *alpha_1,
                              sSBRDecComState* pSbr, Ipp32s ch,
                              Ipp32f *deg, Ipp32f *degPatched,
                      /*
                       * out data
                       */
                              Ipp32f **YBuf, Ipp32s mode)
{
  Ipp32s  i, x, q, k_0, k, p, g, l;

  Ipp32s  l_start = RATE * pSbr->sbrFIState[ch].bordersEnv[0];
  Ipp32s  l_end = RATE * pSbr->sbrFIState[ch].bordersEnv[pSbr->sbrFIState[ch].nEnv];

  Ipp32f  accYRe, accYIm;
  Ipp32f  bwArr, bwArr2;
  Ipp32f  cA0Re, cA0Im, cA1Re, cA1Im;

  Ipp32fc** pXcmp = (Ipp32fc**)XBuf;
  Ipp32fc** pYcmp = (Ipp32fc**)YBuf;

  Ipp32f** pXre = XBuf;
  Ipp32f** pYre = YBuf;

  sSBRFeqTabsState* pFTState = &(pSbr->sbrFreqTabsState);

  //------------------------

  Ipp32fc* pA0cmp = (Ipp32fc*)alpha_0 ;
  Ipp32fc* pA1cmp = (Ipp32fc*)alpha_1 ;

  Ipp32f* pA0re = alpha_0 ;
  Ipp32f* pA1re = alpha_1 ;

  /* CODE */
  if (mode == HEAAC_LP_MODE) {
    ippsZero_32f(degPatched, MAX_NUM_ENV_VAL);
    ippsCopy_32f(deg, degPatched, MAX_NUM_ENV_VAL);
  }

   for (i = 0; i < pFTState->numPatches; i++) {
    k_0 = 0;
    for (q = 0; q < i; q++) {
      k_0 += pFTState->patchNumSubbandsTab[q];
    }

    k_0 += pSbr->kx;
    for (x = 0; x < pFTState->patchNumSubbandsTab[i]; x++) {
      k = k_0 + x;
      p = pFTState->patchStartSubbandTab[i] + x;

      for (g = 0; g < pFTState->nNoiseBand; g++) {
        if ((k >= pFTState->fNoiseBandTab[g]) && (k < pFTState->fNoiseBandTab[g + 1]))
          break;
      }

      if (mode == HEAAC_LP_MODE) {
        if (x == 0)
          degPatched[k] = 0.0f;
        else
          degPatched[k] = deg[p];
      }

      bwArr    = vbwArray[g];
      /******************************************
       * code may be optimized because:
       * if ( 0 == bwArr )
       *   pY[ l ][ k ] = pX[ l ][ p ] ONLY!!!
       * else
       *  ippsPredictCoef_SBR_C_32f_D2L(...)
       *  and code is written below,
       *  but it is impossible because
       *  ipp function works only k = [0, k0)
       *
       ******************************************/
      bwArr2   = bwArr * bwArr;

      if (mode == HEAAC_HQ_MODE) {
        cA0Re = bwArr * pA0cmp[p].re ;
        cA0Im = bwArr * pA0cmp[p].im ;

        cA1Re = bwArr2 * pA1cmp[p].re;
        cA1Im = bwArr2 * pA1cmp[p].im;

        for (l = l_start; l < l_end; l++) {

            /*  bw * Alpha0 * XLow[l-1] */
            accYRe = pXcmp[l - 1 + 0][p].re * cA0Re  -
                     pXcmp[l - 1 + 0][p].im * cA0Im ;

            accYIm = pXcmp[l - 1 + 0][p].re * cA0Im  +
                     pXcmp[l - 1 + 0][p].im * cA0Re;

            /*  bw^2 * Alpha1 * XLow[l-2] */
            accYRe += pXcmp[l - 2 + 0][p].re * cA1Re -
                      pXcmp[l - 2 + 0][p].im * cA1Im;

            accYIm += pXcmp[l - 2 + 0][p].re * cA1Im +
                      pXcmp[l - 2 + 0][p].im * cA1Re;

            pYcmp[l + 0][k].re = pXcmp[l - 0 + 0][p].re + accYRe;
            pYcmp[l + 0][k].im = pXcmp[l - 0 + 0][p].im + accYIm;
        }// end for
      } else {// if (mode == HEAAC_HQ_MODE)

        //------------

        cA0Re = bwArr * pA0re[p];

        cA1Re = bwArr2 * pA1re[p];

        for (l = l_start; l < l_end; l++) {

            /*  bw * Alpha0 * XLow[l-1] */
            accYRe = pXre[l - 1 + 0][p] * cA0Re;

            /*  bw^2 * Alpha1 * XLow[l-2] */
            accYRe += pXre[l - 2 + 0][p] * cA1Re;

            pYre[l + 0][k] = pXre[l - 0 + 0][p] + accYRe;
        }
        //------------

      }

    }
  }

  if (mode == HEAAC_LP_MODE) {
    k_0 = 0;
    for (q = 0; q < pFTState->numPatches; q++)
      k_0 += pFTState->patchNumSubbandsTab[q];

    for (k = pSbr->kx + k_0; k < MAX_NUM_ENV_VAL; k++)
      degPatched[k] = 0;
  }

  return 0;     // OK
}
Esempio n. 8
0
static USC_Status Init_VAD_G729FP(const USC_FilterOption *options, const USC_MemBank *pBanks, USC_Handle *handle)
{
    G729_Handle_Header *g729_header;
    VADmemory *VadObj;

    Ipp32s i;
    Ipp32s fltsize;
    void* pBuf;

    USC_CHECK_PTR(options);
    USC_CHECK_PTR(pBanks);
    USC_CHECK_PTR(pBanks[0].pMem);
    USC_BADARG(pBanks[0].nbytes<=0, USC_NotInitialized);
    USC_CHECK_PTR(pBanks[1].pMem);
    USC_BADARG(pBanks[1].nbytes<=0, USC_NotInitialized);
    USC_CHECK_HANDLE(handle);

    USC_BADARG(options->modes.vad > 1, USC_UnsupportedVADType);
    USC_BADARG(options->modes.vad < 0, USC_UnsupportedVADType);

    USC_BADARG(options->pcmType.sample_frequency < 1, USC_UnsupportedPCMType);
    USC_BADARG(options->pcmType.bitPerSample < 1, USC_UnsupportedPCMType);

    *handle = (USC_Handle*)pBanks[0].pMem;
    g729_header = (G729_Handle_Header*)*handle;

    g729_header->vad = options->modes.vad;
    VadObj = (VADmemory *)((Ipp8s*)*handle + sizeof(G729_Handle_Header));
    ippsZero_16s((Ipp16s*)VadObj,sizeof(VADmemory)>>1) ;

    if(pBanks[1].pMem==NULL) return USC_BadArgument;
    if(VadObj==NULL) return USC_BadArgument;

    if(NULL==VadObj || NULL==pBanks[1].pMem)
       return USC_BadArgument;

    VadObj->Mem.base = pBanks[1].pMem;
    VadObj->Mem.CurPtr = VadObj->Mem.base;
    VadObj->Mem.VecPtr = (Ipp32s *)(VadObj->Mem.base+VAD_G729FP_LOCAL_MEMORY_SIZE);

   if(NULL==VadObj)
      return USC_BadArgument;

   ippsZero_32f(VadObj->OldSpeechBuffer, SPEECH_BUFF_LEN);

   VadObj->objPrm.objSize = vadObjSize();
   VadObj->objPrm.mode = g729_header->vad;
   VadObj->objPrm.key = ENC_KEY;

   pBuf = (Ipp8s*)VadObj + sizeof(VADmemory);
   ippsIIRGetStateSize_32f(2,&fltsize);
   VadObj = (VADmemory *)((Ipp8s*)pBuf + fltsize);
   VADGetSize(&fltsize);

   /* Static vectors to zero */
   for(i=0; i<MOVING_AVER_ORDER; i++)
   VadObj->sFrameCounter = 0;
   /* For G.729B */
   /* Initialize VAD/DTX parameters */
   //if(mode == G729Encode_VAD_Enabled) {
      VadObj->prevVADDec = 1;
      VadObj->prevPrevVADDec = 1;
      VADInit((Ipp8s*)VadObj);
   //}

    if(pBanks[1].pMem==NULL) return USC_BadArgument;
    if(VadObj==NULL) return USC_BadArgument;

    if(NULL==VadObj || NULL==pBanks[1].pMem)
       return USC_BadArgument;

    VadObj->Mem.base = pBanks[1].pMem;
    VadObj->Mem.CurPtr = VadObj->Mem.base;
    VadObj->Mem.VecPtr = (Ipp32s *)(VadObj->Mem.base+VAD_G729FP_LOCAL_MEMORY_SIZE);

    return USC_NoError;
}
Esempio n. 9
0
void IQSSBDemodulator::process_block(Ipp32f* iq_block, Ipp32f* out_block)
{
	static bool flip=false;
	// Deinterleave to real and imaginary (I and Q) buffers
	ippsDeinterleave_32f(iq_block, 2, BLKSIZE, _iq);
	ippsZero_32f(_in_re+BLKSIZE, NFFT-BLKSIZE);
	ippsZero_32f(_in_im+BLKSIZE, NFFT-BLKSIZE);
	// _in_re now contains the real/I part and 
	// _in_im now contains the imaginary/Q part
	
	ippsFFTFwd_CToC_32f_I(_in_re, _in_im,
	                       _fft_specs, _fft_buf);
	ippsCartToPolar_32f(_in_re, _in_im,
	                    _in_m, _in_p,
	                    NFFT);

	// layout of frequency bins is
	// NFFT/2 to NFFT-1 and then continues from 0 to NFFT/2-1

	// shift desired part to 0Hz
	int lo = _lo*NFFT;
	circshift(_in_m, NFFT, lo);	
	circshift(_in_p, NFFT, lo);	
	// zero out undesired sideband
	if(_sideband == USB)
	{
		// zero out LSB, that is NFFT/2 to NFFT-1
		ippsZero_32f(_in_m+NFFT/2, NFFT/2);
		ippsZero_32f(_in_p+NFFT/2, NFFT/2);
	}
	else // _sideband must be LSB
	{
		// zero out USB, that is 0 to NFFT/2-1
		ippsZero_32f(_in_m, NFFT/2);
		ippsZero_32f(_in_p, NFFT/2);
	}
	// filter the passband
	ippsMul_32f_I(_fir_taps_m, _in_m, NFFT);
	ippsAdd_32f_I(_fir_taps_p, _in_p, NFFT);
	// return to time domain
	ippsPolarToCart_32f(_in_m, _in_p,
	                    _in_re, _in_im,
	                    NFFT);
	ippsFFTInv_CToC_32f_I(_in_re, _in_im,
	                    _fft_specs, _fft_buf);
	// do overlap/add
	//
	// 1) add the residual from last round
	ippsAdd_32f_I(_residual_re, _in_re, _residual_length);
	ippsAdd_32f_I(_residual_im, _in_im, _residual_length);
	// 2) Store the new residual
	if(flip)
	{
		ippsMulC_32f_I(-1.0, _in_re, NFFT);
		ippsMulC_32f_I(-1.0, _in_im, NFFT);
		flip=!flip;
	}
	ippsCopy_32f(_in_re+BLKSIZE, _residual_re, _residual_length);
	ippsCopy_32f(_in_im+BLKSIZE, _residual_im, _residual_length);

	// agc
	agc(_in_re, BLKSIZE);
	
	// deliver the result
	ippsCopy_32f(_in_re, out_block, BLKSIZE);
}