void IQSSBDemodulator::fftshift(Ipp32f* b, int len) { static Ipp32f* tmp = ippsMalloc_32f(len/2); ippsCopy_32f(b, tmp, len/2); ippsCopy_32f(b+len/2, b, len/2); ippsCopy_32f(tmp, b+len/2, len/2); }
void IQSSBDemodulator::circshift(Ipp32f* b, int len, int lo) { fftshift(b, len); static Ipp32f* tmp = ippsMalloc_32f(len); if(lo>=0) { ippsCopy_32f(b, tmp, lo); ippsMove_32f(b+lo, b, len-lo); ippsCopy_32f(tmp, b+len-lo, lo); } else { int abs_lo = -lo; ippsCopy_32f(b+len-abs_lo, tmp, abs_lo); ippsMove_32f(b, b+abs_lo, len-abs_lo); ippsCopy_32f(tmp, b, abs_lo); } fftshift(b, len); }
Ipp32f* CRunDeconvFFT::createKernel(CImage* pImg) { IppiSize size = pImg->GetActualSize(); int channels = pImg->Channels(); int kernelSize = GetKernelSize(pImg); if ((kernelSize == size.width) && (kernelSize*4*channels == pImg->Step())) return (Ipp32f*)pImg->GetRoiPtr(); Ipp32f* pKernel = ippsMalloc_32f(kernelSize*kernelSize*channels); Ipp8u* pSrc = (Ipp8u*)pImg->GetRoiPtr(); Ipp32f* pDst = pKernel; for (int y=0; y < size.height; y++) { ippsCopy_32f((Ipp32f*)pSrc, pDst, kernelSize*channels); pSrc += pImg->Step(); pDst += kernelSize*channels; } return pKernel; }
Ipp32s sbrencSinEstimation(sSBREnc_SCE_State* pState, sSBRFeqTabsState* pFreqTabsState) { //sSBRFeqTabsState* pFreqTabsState = (pState->sbrFreqTabsState); sSBRSinEst* pSinEst = &( pState->sbrSinEst ); Ipp32s* bufComp = pSinEst->bufCompensation; Ipp32s* bufCompPrev = pSinEst->bufCompensationPrev; Ipp32s* harmonicFlag = &(pState->sbrEDState.bs_add_harmonic_flag); Ipp32s* prevTranFrame = &(pState->sbrTransientState.prevTranFrame); Ipp32s* prevTranPos = &(pState->sbrTransientState.prevTranPos); Ipp32s* prevTranFlag = &(pState->sbrTransientState.prevTranFlag); Ipp32s nBand = pFreqTabsState->nHiBand; Ipp32s tranFlag = pState->sbrTransientState.tranFlag; Ipp32s tranPos = pState->sbrTransientState.tranPos; Ipp32s tranPosOffset = 4; Ipp32s isDetectNewTone = 0; Ipp32s band; Ipp32s criterion1, criterion2, criterion3; /* sbrencCalcInDataSinEst( pState->bufT, pSinEst->bufDiff, pSinEst->bufSfmOrig, pSinEst->bufSfmSBR, pState->tabPatchMap, pState->fHiBandTab, pState->nHiBand ); */ isDetectNewTone = sbrencIsDetectNewToneAllow(&(pState->sbrFIState), prevTranFrame, prevTranPos, prevTranFlag, tranPosOffset, tranFlag, tranPos); /* AYA log */ #ifdef SBR_NEED_LOG fprintf(logFile, "\isDetection\nprevTranFlag = %i, prevTranFrame = %i, prevTranPos = %i\n", *prevTranFlag, *prevTranFrame, *prevTranPos); fprintf(logFile, "newDetection = %i\n", isDetectNewTone); #endif sbrencCalcInDataSinEst(pState->bufT, pSinEst->bufDiff, pSinEst->bufSfmOrig, pSinEst->bufSfmSBR, pState->tabPatchMap, pFreqTabsState->fHiBandTab, nBand); sbrencTotalDetectionSinEst(pState->bufT, pSinEst->bufDiff, nBand, pFreqTabsState->fHiBandTab, pSinEst->bufSfmOrig, pSinEst->bufSfmSBR, pSinEst->bufDetection, pSinEst->guideScfb, pSinEst->sbrGuideState, 2, //Ipp32s noEstPerFrame, 4, //Ipp32s totNoEst, isDetectNewTone, pState->sbrEDState.bs_add_harmonic); /* AYA log */ #ifdef SBR_NEED_LOG { Ipp32s i; fprintf(logFile, "\naddHarmonic\n"); for(i=0; i<pFreqTabsState->nHiBand; i++){ fprintf(logFile, "%i\n", pState->sbrEDState.bs_add_harmonic[i]); } } #endif sbrencCalcCompensation(pState->bufT, pSinEst->bufDiff, pFreqTabsState->fHiBandTab, nBand, pState->sbrEDState.bs_add_harmonic, bufComp, 4); /* patch */ if( !isDetectNewTone ){ sbrencCompensationCorrect(bufComp, bufCompPrev, nBand); } *harmonicFlag = sbrencIsHarmonicAddition( pState->sbrEDState.bs_add_harmonic, nBand ); /* buffer up-date */ ippsCopy_32s(bufComp, bufCompPrev, nBand); ippsCopy_32s(pState->sbrEDState.bs_add_harmonic, pSinEst->guideScfb, nBand); ippsCopy_32s(pState->sbrEDState.bs_add_harmonic, pSinEst->sbrGuideState[0].bufGuideDetect, nBand); ippsCopy_32f(pSinEst->sbrGuideState[2].bufGuideDiff, pSinEst->sbrGuideState[0].bufGuideDiff, nBand); ippsCopy_32f(pSinEst->sbrGuideState[2].bufGuideOrig, pSinEst->sbrGuideState[0].bufGuideOrig, nBand); for(band = 0; band < nBand; band++){ criterion1 = (Ipp32s)pSinEst->sbrGuideState[0].bufGuideDiff[band]; criterion2 = (Ipp32s)pSinEst->sbrGuideState[0].bufGuideOrig[band]; criterion3 = (Ipp32s)pState->sbrEDState.bs_add_harmonic[band]; if((criterion1 || criterion2) && !criterion3){ pSinEst->sbrGuideState[0].bufGuideDiff[band] = 0; pSinEst->sbrGuideState[0].bufGuideOrig[band] = 0; } } /* AYA log */ #ifdef SBR_NEED_LOG { Ipp32s i; fprintf(logFile, "\nCompensation\n"); for(i=0; i<nBand; i++){ fprintf(logFile, "%i\n", pSinEst->bufCompensation[i]); } } #endif return 0; //OK }
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 }
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 }
int G729FPVAD(VADmemory* vadObj,const Ipp16s* src, Ipp16s* dst, Ipp32s *frametype ){ LOCAL_ALIGN_ARRAY(32, Ipp32f, forwardAutoCorr, (LPC_ORDERP2+1),vadObj); /* Autocorrelations (forward) */ LOCAL_ALIGN_ARRAY(32, Ipp32f, forwardLPC, LPC_ORDERP1*2,vadObj); /* A(z) forward unquantized for the 2 subframes */ LOCAL_ALIGN_ARRAY(32, Ipp32f, TmpAlignVec, WINDOW_LEN,vadObj); LOCAL_ARRAY(Ipp32f, forwardReflectCoeff, LPC_ORDER,vadObj); LOCAL_ARRAY(Ipp32f, CurrLSP, LPC_ORDER,vadObj); LOCAL_ARRAY(Ipp32f, CurrLSF, LPC_ORDER,vadObj); Ipp32f *pWindow; Ipp32f *newSpeech; /* Excitation vector */ Ipp16s isVAD; Ipp32f tmp_lev; Ipp32s VADDecision; Ipp32f EnergydB; IppStatus sts; *frametype = 3; if(NULL==vadObj || NULL==src || NULL ==dst) return -10; if(vadObj->objPrm.objSize <= 0) return -8; if(ENC_KEY != vadObj->objPrm.key) return -5; isVAD = (Ipp16s)(vadObj->objPrm.mode == G729Encode_VAD_Enabled); if(!isVAD) return 0; newSpeech = vadObj->OldSpeechBuffer + SPEECH_BUFF_LEN - FRM_LEN; /* New speech */ pWindow = vadObj->OldSpeechBuffer + SPEECH_BUFF_LEN - WINDOW_LEN; /* For LPC window */ if (vadObj->sFrameCounter == 32767) vadObj->sFrameCounter = 256; else vadObj->sFrameCounter++; ippsConvert_16s32f(src,newSpeech,FRM_LEN); ownAutoCorr_G729_32f(pWindow, LPC_ORDERP2, forwardAutoCorr,TmpAlignVec); /* Autocorrelations */ /* Lag windowing */ ippsMul_32f_I(lwindow, &forwardAutoCorr[1], LPC_ORDERP2); /* Levinson Durbin */ tmp_lev = 0; sts = ippsLevinsonDurbin_G729_32f(forwardAutoCorr, LPC_ORDER, &forwardLPC[LPC_ORDERP1], forwardReflectCoeff, &tmp_lev); if(sts == ippStsOverflow) { ippsCopy_32f(vadObj->OldForwardLPC,&forwardLPC[LPC_ORDERP1],LPC_ORDER+1); forwardReflectCoeff[0] = vadObj->OldForwardRC[0]; forwardReflectCoeff[1] = vadObj->OldForwardRC[1]; } else { ippsCopy_32f(&forwardLPC[LPC_ORDERP1],vadObj->OldForwardLPC,LPC_ORDER+1); vadObj->OldForwardRC[0] = forwardReflectCoeff[0]; vadObj->OldForwardRC[1] = forwardReflectCoeff[1]; } /* Convert A(z) to lsp */ ippsLPCToLSP_G729_32f(&forwardLPC[LPC_ORDERP1], vadObj->OldLSP, CurrLSP); if (vadObj->objPrm.mode == G729Encode_VAD_Enabled) { ownACOS_G729_32f(CurrLSP, CurrLSF, LPC_ORDER); VoiceActivityDetect_G729_32f(forwardReflectCoeff[1], CurrLSF, forwardAutoCorr, pWindow, vadObj->sFrameCounter, vadObj->prevVADDec, vadObj->prevPrevVADDec, &VADDecision, &EnergydB,(Ipp8s *)vadObj,TmpAlignVec); } else VADDecision = 1; if(VADDecision == 0) { /* Inactive frame */ vadObj->prevVADDec = 0; *frametype=1; /* SID*/ } else vadObj->prevVADDec = VADDecision; vadObj->prevPrevVADDec = vadObj->prevVADDec; ippsMove_32f(&vadObj->OldSpeechBuffer[FRM_LEN], &vadObj->OldSpeechBuffer[0], SPEECH_BUFF_LEN-FRM_LEN); CLEAR_SCRATCH_MEMORY(vadObj); return 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); }