⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 owng729fp.c

📁 G.729 and G.723.1 codecs x86 (and x86_64) Linux and FreeBSD source code for Asterisk open source PBX
💻 C
📖 第 1 页 / 共 5 页
字号:
   msdState->fMeanPFlagCounter=0.0;   msdState->lConscPFlagCounter=0;   msdState->lRCCounter=0;   msdState->fMeanFullBandEnergy =0.0f;   return;}void MusicDetection_G729E_32f(G729FPEncoder_Obj *encoderObj, G729Codec_Type codecType, Ipp32f Energy,                              Ipp32f *ReflectCoeff, Ipp32s *VadDecision, Ipp32f LLenergy, Ipp8s *msdMem,Ipp32f *pExtBuff){    Ipp32s i;    Ipp32f fSum1, fSum2,fStandartDeviation;    Ipp16s VoicingStrenght1, VoicingStrenght2, VoicingStrenght;    Ipp32f fError, fEnergy , fSpectralDifference, *pTmpVec;    Ipp32f fThreshold;    MusDetectMemory *msdState = (MusDetectMemory *)msdMem;    pTmpVec = &pExtBuff[0]; /*10 elements*/    fError = 1.0f;    for (i=0; i< 4; i++) fError *= (1.0f - ReflectCoeff[i]*ReflectCoeff[i]);    ippsSub_32f(msdState->MeanRC, ReflectCoeff, pTmpVec, 10);    ippsDotProd_32f(pTmpVec, pTmpVec, 10, &fSpectralDifference);    fEnergy = 10.0f*(Ipp32f)log10(fError*Energy/240.0f +IPP_MINABS_32F);    if( *VadDecision == VAD_NOISE ){       ippsInterpolateC_G729_32f(msdState->MeanRC, 0.9f, ReflectCoeff, 0.1f, msdState->MeanRC, 10);       msdState->fMeanFullBandEnergy = 0.9f * msdState->fMeanFullBandEnergy + 0.1f * fEnergy;    }    fSum1 = 0.0f;    fSum2 = 0.0f;    for(i=0; i<5; i++){        fSum1 += (Ipp32f) encoderObj->LagBuffer[i];        fSum2 +=  encoderObj->PitchGainBuffer[i];    }    fSum1 = fSum1/5.0f;    fSum2 = fSum2/5.0f;    fStandartDeviation =0.0f;    for(i=0; i<5; i++) fStandartDeviation += sqr(((Ipp32f) encoderObj->LagBuffer[i] - fSum1));    fStandartDeviation = (Ipp32f)sqrt(fStandartDeviation/4.0f);    msdState->fMeanPitchGain = 0.8f * msdState->fMeanPitchGain + 0.2f * fSum2;    /* See I.5.1.1 Pitch lag smoothness and voicing strenght indicator.*/    if ( codecType == G729D_CODEC)        fThreshold = 0.73f;    else        fThreshold = 0.63f;    if ( msdState->fMeanPitchGain > fThreshold)        VoicingStrenght2 = 1;    else        VoicingStrenght2 = 0;    if ( fStandartDeviation < 1.30f && msdState->fMeanPitchGain > 0.45f )        VoicingStrenght1 = 1;    else        VoicingStrenght1 = 0;    VoicingStrenght= (Ipp16s)( ((Ipp16s)encoderObj->prevVADDec & (Ipp16s)(VoicingStrenght1 | VoicingStrenght2))| (Ipp16s)(VoicingStrenght2));    if( ReflectCoeff[1] <= 0.45f && ReflectCoeff[1] >= 0.0f && msdState->fMeanPitchGain < 0.5f)        msdState->lRCCounter++;    else        msdState->lRCCounter =0;    if( encoderObj->prevLPCMode== 1 && (*VadDecision == VAD_VOICE))        msdState->lMusicCounter++;    if ((encoderObj->sFrameCounter%64) == 0 ){        if( encoderObj->sFrameCounter == 64)            msdState->fMusicCounter = (Ipp32f)msdState->lMusicCounter;        else            msdState->fMusicCounter = 0.9f*msdState->fMusicCounter + 0.1f*(Ipp32f)msdState->lMusicCounter;    }    if( msdState->lMusicCounter == 0)        msdState->lZeroMusicCounter++;    else        msdState->lZeroMusicCounter = 0;    if( msdState->lZeroMusicCounter > 500 || msdState->lRCCounter > 150) msdState->fMusicCounter = 0.0f;    if ((encoderObj->sFrameCounter%64) == 0)        msdState->lMusicCounter = 0;    if( VoicingStrenght== 1 )        msdState->lPFlagCounter++;    if ((encoderObj->sFrameCounter%64) == 0 ){        if( encoderObj->sFrameCounter == 64)            msdState->fMeanPFlagCounter = (Ipp32f)msdState->lPFlagCounter;        else{            if( msdState->lPFlagCounter > 25)                msdState->fMeanPFlagCounter = 0.98f * msdState->fMeanPFlagCounter + 0.02f * msdState->lPFlagCounter;            else if( msdState->lPFlagCounter > 20)                msdState->fMeanPFlagCounter = 0.95f * msdState->fMeanPFlagCounter + 0.05f * msdState->lPFlagCounter;            else                msdState->fMeanPFlagCounter = 0.90f * msdState->fMeanPFlagCounter + 0.10f * msdState->lPFlagCounter;        }    }    if( msdState->lPFlagCounter == 0)        msdState->lConscPFlagCounter++;    else        msdState->lConscPFlagCounter = 0;    if( msdState->lConscPFlagCounter > 100 || msdState->lRCCounter > 150) msdState->fMeanPFlagCounter = 0.0f;    if ((encoderObj->sFrameCounter%64) == 0)        msdState->lPFlagCounter = 0;    if (codecType == G729E_CODEC){        if( fSpectralDifference > 0.15f && (fEnergy -msdState->fMeanFullBandEnergy)> 4.0f && (LLenergy> 50.0) )            *VadDecision =VAD_VOICE;        else if( (fSpectralDifference > 0.38f || (fEnergy -msdState->fMeanFullBandEnergy)> 4.0f  ) && (LLenergy> 50.0f))            *VadDecision =VAD_VOICE;        else if( (msdState->fMeanPFlagCounter >= 10.0f || msdState->fMusicCounter >= 5.0f || encoderObj->sFrameCounter < 64)&& (LLenergy> 7.0))            *VadDecision =VAD_VOICE;    }    return;}void PitchTracking_G729FPE(Ipp32s *pitchDelay, Ipp32s *fracPitchDelay, Ipp32s *prevPitchDelay, Ipp32s *stat_N,                         Ipp32s *lStatPitch2PT, Ipp32s *lStatFracPT){    Ipp32s pitchDistance, minDist, lPitchMult;    Ipp32s j, distSign;    pitchDistance = (*pitchDelay) - (*prevPitchDelay);    if(pitchDistance < 0) {        distSign = 0;        pitchDistance = - pitchDistance;    } else {        distSign = 1;    }    /* Test pitch stationnarity */    if (pitchDistance < 5) {        (*stat_N)++;        if (*stat_N > 7) *stat_N = 7 ;        *lStatPitch2PT = *pitchDelay;        *lStatFracPT = *fracPitchDelay;    } else {        /* Find multiples or sub-multiples */        minDist =  pitchDistance;        if( distSign == 0) {            lPitchMult = 2 * (*pitchDelay);            for (j=2; j<5; j++) {                pitchDistance = abs(lPitchMult - (*prevPitchDelay));                if (pitchDistance <= minDist) {                    minDist = pitchDistance;                }                lPitchMult += (*pitchDelay);            }        } else {            lPitchMult = 2 * (*prevPitchDelay);            for (j=2; j<5; j++) {                pitchDistance = abs(lPitchMult - (*pitchDelay));                if (pitchDistance <= minDist) {                    minDist = pitchDistance;                }                lPitchMult += (*prevPitchDelay);            }        }        if (minDist < 5) {   /* Multiple or sub-multiple detected */            if (*stat_N > 0) {                *pitchDelay      = *lStatPitch2PT;                *fracPitchDelay = *lStatFracPT;            }            *stat_N -= 1;            if (*stat_N < 0) *stat_N = 0 ;        } else {            *stat_N = 0;    /* No (sub-)multiple detected  => Pitch transition */            *lStatPitch2PT = *pitchDelay;            *lStatFracPT = *fracPitchDelay;        }    }    *prevPitchDelay = *pitchDelay;    return;}void OpenLoopPitchSearch_G729_32f(const Ipp32f *pSrc, Ipp32s* lBestLag){   Ipp32f fTmp;   Ipp64f dTmp;   Ipp32f fMax1, fMax2, fMax3;   Ipp32s max1Idx, max2Idx, max3Idx;   /*  Find a maximum for three sections and compare the maxima       of each section by favoring small lag.      */   /*  First section:  lag delay = PITCH_LAG_MAX to 80                   */   ippsAutoCorrLagMax_32f(pSrc, FRM_LEN, 80,PITCH_LAG_MAX+1, &fMax1, &max1Idx);   /*  Second section: lag delay = 79 to 40                              */   ippsAutoCorrLagMax_32f(pSrc, FRM_LEN, 40,80, &fMax2, &max2Idx);   /*  Third section:  lag delay = 39 to 20                              */   ippsAutoCorrLagMax_32f(pSrc, FRM_LEN, PITCH_LAG_MIN,40, &fMax3, &max3Idx);   ippsDotProd_32f64f(&pSrc[-max1Idx], &pSrc[-max1Idx], FRM_LEN, &dTmp);   fTmp = (Ipp32f) (1.0f / sqrt(dTmp+0.01f));   fMax1 = (Ipp32f)(fMax1) * fTmp;        /* max/sqrt(energy)  */   ippsDotProd_32f64f(&pSrc[-max2Idx], &pSrc[-max2Idx], FRM_LEN, &dTmp);   fTmp = (Ipp32f) (1.0f / sqrt(dTmp+0.01));   fMax2 = (Ipp32f)(fMax2) * fTmp; /* max/sqrt(energy)  */   /* Calc energy */   ippsDotProd_32f64f(&pSrc[-max3Idx], &pSrc[-max3Idx], FRM_LEN, &dTmp);   /* 1/sqrt(energy)    */   fTmp = 1.0f / (Ipp32f)sqrt(dTmp+0.01);   fMax3 = (Ipp32f)(fMax3) * fTmp;        /* max/sqrt(energy)  */   /* Compare the 3 sections maxima and choose the small one. */   if ( fMax1 * PITCH_THRESH < fMax2 ) {      fMax1 = fMax2;      max1Idx = max2Idx;   }   if ( fMax1 * PITCH_THRESH < fMax3 )  max1Idx = max3Idx;   *lBestLag = max1Idx;   return;}Ipp32s TestErrorContribution_G729(Ipp32s valPitchDelay, Ipp32s valFracPitchDelay, Ipp32f *ExcErr){    Ipp32s j, lTmp, l1, l2, lTaming;    Ipp32f maxErrExc;    lTmp = (valFracPitchDelay > 0) ? (valPitchDelay+1) : valPitchDelay;    j = lTmp - SUBFR_LEN - INTER_PITCH_LEN;    if(j < 0) j = 0;    l1 =  (Ipp32s) (j * INV_SUBFR_LEN);    j = lTmp + INTER_PITCH_LEN - 2;    l2 =  (Ipp32s) (j * INV_SUBFR_LEN);    maxErrExc = -1.f;    lTaming = 0 ;    for(j=l2; j>=l1; j--) {        if(ExcErr[j] > maxErrExc) maxErrExc = ExcErr[j];    }    if(maxErrExc > THRESH_ERR) {        lTaming = 1;    }    return(lTaming);}void UpdateExcErr_G729(Ipp32f valPitchGain, Ipp32s valPitchDelay, Ipp32f *pExcErr){    Ipp32s i, l1, l2, n;    Ipp32f fMax, fTmp;    fMax = -1.f;    n = valPitchDelay- SUBFR_LEN;    if(n < 0) {        fTmp = 1.f + valPitchGain * pExcErr[0];        if(fTmp > fMax) fMax = fTmp;        fTmp = 1.f + valPitchGain * fTmp;        if(fTmp > fMax) fMax = fTmp;    } else {        l1 = (Ipp32s) (n * INV_SUBFR_LEN);        i = valPitchDelay - 1;        l2 = (Ipp32s) (i * INV_SUBFR_LEN);        for(i = l1; i <= l2; i++) {            fTmp = 1.f + valPitchGain * pExcErr[i];            if(fTmp > fMax) fMax = fTmp;        }    }    for(i=3; i>=1; i--) pExcErr[i] = pExcErr[i-1];    pExcErr[0] = fMax;    return;}void isBackwardModeDominant_G729(Ipp32s *isBackwardModeDominant, Ipp32s LPCMode, Ipp32s *pCounterBackward, Ipp32s *pCounterForward){    Ipp32s lTmp, lCounter;    if (LPCMode == 0) (*pCounterForward)++;    else (*pCounterBackward)++;    lCounter = *pCounterBackward + *pCounterForward;    if (lCounter == 100) {        lCounter = lCounter >> 1;        *pCounterBackward = (*pCounterBackward) >> 1;        *pCounterForward = (*pCounterForward) >> 1;    }    *isBackwardModeDominant = 0;    if (lCounter >= 10) {        lTmp = (*pCounterForward) << 2;        if (*pCounterBackward > lTmp) *isBackwardModeDominant = 1;    }    return;}Ipp32f CalcEnergy_dB_G729(Ipp32f *pSrc, Ipp32s len){   Ipp64f  dEnergy;   Ipp32f fEnergydB;   Ipp32s n, k, lTmp;   ippsDotProd_32f64f(pSrc, pSrc, len, &dEnergy);   dEnergy += 0.0001;   fEnergydB = (Ipp32f)log10(dEnergy);   n = (Ipp32s) (fEnergydB * INVERSE_LOG2);   if(n >= 4) {      if(dEnergy > 2147483647.) dEnergy = 93.1814;      else {         k = (Ipp32s)dEnergy;         lTmp = -(1 << (n-4));         k &= lTmp;         dEnergy = 10. * log10((Ipp32f)k);      }   }   else dEnergy = 0.005;   return (Ipp32f)dEnergy;}void InterpolatedBackwardFilter_G729(Ipp32f *pSrcDstLPCBackwardFlt, Ipp32f *pSrcPrevFilter, Ipp32f *pSrcDstIntCoeff){    Ipp32s i;    Ipp32f s1, s2;    Ipp32f *pBwdLPC;    Ipp32f fIntFactor;    pBwdLPC = pSrcDstLPCBackwardFlt + BWD_LPC_ORDERP1;    /* Calculate the interpolated filters  */    fIntFactor = *pSrcDstIntCoeff - 0.1f;    if( fIntFactor < 0) fIntFactor = 0;    for (i=0; i<BWD_LPC_ORDERP1; i++) {        s1 = pBwdLPC[i] * (1.f - fIntFactor);        s2 = pSrcPrevFilter[i] * fIntFactor;        pBwdLPC[i] = s1 + s2;    }    //ippsInterpolateC_G729_32f(pBwdLPC, (1.f - fIntFactor), pSrcPrevFilter, fIntFactor, pBwdLPC, BWD_LPC_ORDERP1);    for (i=0; i<BWD_LPC_ORDERP1; i++) {        pSrcDstLPCBackwardFlt[i] = 0.5f * (pBwdLPC[i] + pSrcPrevFilter[i]);    }    //ippsInterpolateC_G729_32f(pBwdLPC, 0.5f, pSrcPrevFilter, 0.5f, pBwdLPC, BWD_LPC_ORDERP1);    *pSrcDstIntCoeff = fIntFactor;    return;}/* anti-sparseness post-processing */static __ALIGN32 CONST Ipp32f ImpLow[SUBFR_LEN]={   0.4483f, 0.3515f, 0.0387f,-0.0843f,-0.1731f, 0.2293f,-0.0011f,   -0.0857f,-0.0928f, 0.1472f, 0.0901f,-0.2571f, 0.1155f, 0.0444f,   0.0665f,-0.2636f, 0.2457f,-0.0642f,-0.0444f, 0.0237f, 0.0338f,   -0.0728f, 0.0688f,-0.0111f,-0.0206f,-0.0642f, 0.1845f,-0.1734f,   0.0327f, 0.0953f,-0.1544f, 0.1621f,-0.0711f,-0.1138f, 0.2113f,   -0.1187f, 0.0206f,-0.0542f, 0.0009f,0.3096f};static __ALIGN32 CONST Ipp32f ImpMiddle[SUBFR_LEN]={   0.9239f, 0.1169f, -0.1232f, 0.0907f, -0.0320f, -0.0306f, 0.0756f,   -0.0929f, 0.0859f, -0.0681f, 0.0535f, -0.0492f, 0.0523f, -0.0542f,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -