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

📄 owng729.c

📁 G.729 and G.723.1 codecs x86 (and x86_64) Linux and FreeBSD source code for Asterisk open source PBX
💻 C
📖 第 1 页 / 共 3 页
字号:
    SynthesisFilterState *SynFltSt;    IppStatus sts=ippStsNoErr;    SynFltSt=(SynthesisFilterState*)pMemUpdated;    nTaps = SynFltSt->nTaps;    if(histLen==0)        ippsSynthesisFilter_G729E_16s(pLPC, 30,pSrc, pDst, len, SynFltSt->buffer);    else        sts = ippsSynthesisFilter_NR_16s_Sfs(pLPC,pSrc,pDst, len, 12, SynFltSt->buffer+histLen);    if(sts != ippStsOverflow)        ippsCopy_16s((pDst+len-nTaps), SynFltSt->buffer, nTaps);    return sts;}IppStatus SynthesisFilter_G729_16s_update (const Ipp16s * pLPC, const Ipp16s * pSrc,                                           Ipp16s * pDst, Ipp32s len, Ipp8s * pMemUpdated,Ipp32s histLen, Ipp32s update) {    Ipp32s nTaps;    SynthesisFilterState *SynFltSt;    IppStatus sts=ippStsNoErr;    SynFltSt=(SynthesisFilterState*)pMemUpdated;    nTaps = SynFltSt->nTaps;    if(histLen==0) ippsSynthesisFilter_G729E_16s(pLPC, 30,pSrc, pDst, len, SynFltSt->buffer);    else        sts = ippsSynthesisFilter_NR_16s_Sfs(pLPC,pSrc,pDst, len, 12, SynFltSt->buffer+histLen);    if((sts != ippStsOverflow)&&(update==1))        ippsCopy_16s((pDst+len-nTaps), SynFltSt->buffer, nTaps);    return sts;}void SynthesisFilterOvf_G729_16s (const Ipp16s * pLPC, const Ipp16s * pSrc,                                  Ipp16s * pDst, Ipp32s len, Ipp8s * pMemUpdated,Ipp32s histLen) {    Ipp32s nTaps;    SynthesisFilterState *SynFltSt;    SynFltSt=(SynthesisFilterState*)pMemUpdated;    nTaps = SynFltSt->nTaps;    if(histLen==0) ippsSynthesisFilter_G729E_16s(pLPC, 30, pSrc, pDst, len, SynFltSt->buffer);    else        ippsSynthesisFilter_NR_16s_Sfs(pLPC,pSrc,pDst, len, 12, SynFltSt->buffer+histLen);    ippsCopy_16s((pDst+len-nTaps), SynFltSt->buffer, nTaps);}void SynthesisFilterSize_G729 (Ipp32s *pSize) {    *pSize = sizeof(SynthesisFilterState)+BWLPCF_DIM*sizeof(Ipp16s);    *pSize += 32;}void SynthesisFilterInit_G729 (Ipp8s * pMemUpdated) {    SynthesisFilterState *SynFltSt;    Ipp32s size;    SynFltSt=(SynthesisFilterState*)pMemUpdated;    size = sizeof(SynthesisFilterState);    SynFltSt->buffer = (Ipp16s*)((Ipp8s*)SynFltSt + size);    //SynFltSt->buffer = (Ipp16s*)(((((Ipp8s*)SynFltSt->buffer + 7) - (Ipp8s*)NULL)&~7));    SynFltSt->buffer = IPP_ALIGNED_PTR(SynFltSt->buffer, 32);    SynFltSt->nTaps = BWLPCF_DIM;    ippsZero_16s(SynFltSt->buffer,BWLPCF_DIM);}void CodewordImpConv_G729(Ipp32s index, const Ipp16s *pSrc1,const Ipp16s *pSrc2,Ipp16s *pDst) {    Ipp32s i;    Ipp32s sign0, sign1, sign2, sign3;     /* 1, -1 */    Ipp32s idx0, idx1, idx2, idx3;         /* position*/    idx0 = index & 0x7;    idx1 = (index>>3) & 0x7;    idx2 = (index>>6) & 0x7;    idx3 = index>>9;    idx0 = (idx0<<2)+idx0;    idx1 = (idx1<<2)+idx1+1;    idx2 = (idx2<<2)+idx2+2;    idx3 = ((idx3>>1)<<2)+(idx3>>1)+(idx3&1)+3;    if(idx0>idx1) {        i=idx0; idx0=idx1; idx1=i;    }    if(idx2>idx3) {        i=idx2; idx2=idx3; idx3=i;    }    if(idx0>idx2) {        i=idx0; idx0=idx2; idx2=i;    }    if(idx1>idx3) {        i=idx1; idx1=idx3; idx3=i;    }    if(idx1>idx2) {        i=idx1; idx1=idx2; idx2=i;    }    sign0 = ((pSrc1[idx0] >> 15)<<1)+1;    sign1 = ((pSrc1[idx1] >> 15)<<1)+1;    sign2 = ((pSrc1[idx2] >> 15)<<1)+1;    sign3 = ((pSrc1[idx3] >> 15)<<1)+1;    for(i=0; i<idx0; i++)        pDst[i]=0;    for(; i<idx1; i++)        pDst[i]=(Ipp16s)(sign0*pSrc2[i-idx0]);    for(; i<idx2; i++)        pDst[i]=Cnvrt_32s16s(sign0*pSrc2[i-idx0]+sign1*pSrc2[i-idx1]);    for(; i<idx3; i++)        pDst[i]=Cnvrt_32s16s(sign0*pSrc2[i-idx0]+sign1*pSrc2[i-idx1]+sign2*pSrc2[i-idx2]);    for(; i<LP_SUBFRAME_DIM; i++)        pDst[i]=Cnvrt_32s16s(sign0*pSrc2[i-idx0]+sign1*pSrc2[i-idx1]+sign2*pSrc2[i-idx2]+sign3*pSrc2[i-idx3]);}/*=============================================================// pSrc - reflection coefficients// pDst - log area ratio coefficients*/void _ippsRCToLAR_G729_16s (const Ipp16s* pSrc, Ipp16s* pDst, Ipp32s len) {    Ipp16s refC, Ax;    Ipp32s   i, L_tmp, L_Bx;    for(i=0; i<len; i++) {        refC = Abs_16s(pSrc[i]);        refC >>= 4;        if(refC <= 1299  /* 0.6341 */) {            pDst[i] = refC;        } else {            if(refC <= 1815 /* 0.8864 */) {                Ax = 4567;                L_Bx = 3271557L/* 0.78 */;            } else if(refC <= 1944 /* 0.9490 */) {                Ax = 11776               /* 5.75 */;                L_Bx = 16357786L           /* 3.90 */;            } else {                Ax = 27443               /* 13.40 */;                L_Bx = 46808433L           /* 11.16 */;            }            refC >>= 1;            L_tmp = (refC * Ax)<<1;            L_tmp=Sub_32s(L_tmp,L_Bx);            pDst[i] = (Ipp16s)(L_tmp >> 11);        }        if(pSrc[i] < 0) {            pDst[i]=Cnvrt_32s16s(-pDst[i]);        }    }}/* /////////////////////////////////////////////////////////////////////////////////////////  Name:    ownMakeDecision//  Purpose://  Parameters://  bwf1    - banwidth expansion parameter//  bwf2    - bandwidth expansion parameter//  intLSF  - interpolated LSF//  newLSF  - new LSF vector for 2nd subframe//  pRc     - reflection coefficients*/void _ippsPWGammaFactor_G729_16s ( const Ipp16s *pLAR, const Ipp16s *pLSF,                                   Ipp16s *flat, Ipp16s *pGamma1, Ipp16s *pGamma2, Ipp16s *pMem ) {    Ipp16s  lar0, lar1, bwf1,bwf2;    Ipp32s  i, L_tmp, L_min;    lar0 = pLAR[0];    lar1 = pLAR[1];    if(*flat != 0) {        if((lar0 < -3562 /* -1.74 */)&&(lar1 > 1336 /* 0.65 */)) {            *flat = 0;        }    } else {        if((lar0 > -3116 /* -1.52 */) || (lar1 < 890 /* 0.43 */) ) {            *flat = 1;        }    }    if(*flat == 0) {        ippsLShiftC_16s(pLSF,1,pMem,LPF_DIM);        bwf1 = N0_98 /* 0.98 */;        L_min = pMem[1] - pMem[0];        for(i=1; i<LPF_DIM-1; i++) {            L_tmp = pMem[i+1] - pMem[i];            if(L_tmp < L_min) {                L_min = L_tmp;            }        }        L_tmp = SIX_PI * L_min;        L_tmp >>= 15;        L_tmp = 1024 /* 1 */ - L_tmp;        L_tmp = L_tmp << 5;        if(L_tmp > BWF2 /* 0.70 */) {            bwf2 = BWF2;        } else if(L_tmp < 13107 /* 0.40 */) {            bwf2 = 13107;        } else {            bwf2 = (Ipp16s)L_tmp;        }    } else {        bwf1 = 30802 /* 0.94 */;        bwf2 = 19661 /* 0.60 */;    }    *pGamma1 = bwf1;    *pGamma2 = bwf2;}void PitchTracking_G729E( Ipp16s *delay,Ipp16s *delay_frac, Ipp16s *prevDelay, Ipp16s *stat_N,                          Ipp16s *pitchStatDelayt, Ipp16s *pitchStatFractiont){    Ipp16s dist, dist_min, pitch_mult;    Ipp16s i, is_mult;    dist = (Ipp16s)(delay[0] - prevDelay[0]);    if(dist < 0) {        dist = (Ipp16s)(-dist);        is_mult = 0;    } else {        is_mult = 1;    }    if(dist < 5) {        *stat_N += 1;        if(*stat_N > 7) *stat_N = 7 ;        *pitchStatDelayt = delay[0];        *pitchStatFractiont = delay_frac[0];    } else {        dist_min =  dist;        if( is_mult == 0) {            pitch_mult = (Ipp16s)(delay[0] + delay[0]);            for(i=2; i<5; i++) {                dist = Abs_16s((Ipp16s)(pitch_mult - prevDelay[0]));                if(dist <= dist_min) dist_min = dist;                pitch_mult = (Ipp16s)(pitch_mult + delay[0]);            }        } else {            pitch_mult = (Ipp16s)(prevDelay[0] + prevDelay[0]);            for(i=2; i<5; i++) {                dist = Abs_16s((Ipp16s)(pitch_mult - delay[0]));                if(dist <= dist_min) dist_min = dist;                pitch_mult = (Ipp16s)(pitch_mult + prevDelay[0]);            }        }        if(dist_min < 5) {            if(*stat_N > 0) {                delay[0] = *pitchStatDelayt;                delay_frac[0] = *pitchStatFractiont;            }            *stat_N -= 1;            if(*stat_N < 0) *stat_N = 0 ;        } else {            *stat_N = 0;            *pitchStatDelayt = delay[0];            *pitchStatFractiont = delay_frac[0];        }    }    prevDelay[0] = delay[0];    return;}static void stat( Ipp16s prevB, Ipp16s prevF, Ipp16s mode, Ipp16s prevMode,                       Ipp16s *statGlobal, Ipp16s *BWDFrameCounter, Ipp16s *val_BWDFrameCounter  ) {    Ipp32s  i;    if(mode == 1) {        *BWDFrameCounter += 1;        *val_BWDFrameCounter += 250;        if(*BWDFrameCounter == 20)            statGlobal[0] = Add_16s(statGlobal[0], 2500);        else            if(*BWDFrameCounter > 20)            statGlobal[0] += 500;    }else        if((mode == 0)&&(prevMode == 1)) {            if(*BWDFrameCounter < 20) {                statGlobal[0] = (Ipp16s)(statGlobal[0] - 5000 + *val_BWDFrameCounter);            }        *BWDFrameCounter = *val_BWDFrameCounter = 0;        }    if(statGlobal[0] < 13000) {        for(i=1; i<6;i++)            if(prevB > prevF + gThrs[i]) {                statGlobal[0] = (Ipp16s)(statGlobal[0] + gStats[i]);                break;            }    }    for(i=0; i<5;i++)        if(prevB < prevF - gThrs[i]) {            statGlobal[0] = (Ipp16s)(statGlobal[0] - gStats1[i]);            break;        }    if( statGlobal[0] > 32000)        statGlobal[0] = 32000;    else        if(statGlobal[0] < 0)            statGlobal[0] = 0;    return;}void SetLPCMode_G729E ( Ipp16s *pSignal,  Ipp16s *fwdA, Ipp16s *pBwdLPC, Ipp16s *mode,                        Ipp16s *newLSP, Ipp16s *oldLSP, G729Encoder_Obj *encoderObj){    Ipp16s i,gap,prevF,prevB,gpredB,temp;    Ipp32s   L_threshLPC,LSPdist,sigEnergy;    LOCAL_ALIGN_ARRAY(32, Ipp16s, res, LP_FRAME_DIM, encoderObj);    sigEnergy = enerDB(pSignal, LP_FRAME_DIM);    ippsResidualFilter_G729E_16s(&pBwdLPC[BWLPCF1_DIM], BWLPCF_DIM,pSignal, res, LP_FRAME_DIM);    prevB = (Ipp16s)(sigEnergy - enerDB(res, LP_FRAME_DIM));    encoderObj->interpCoeff2_2 -= 410;    if( encoderObj->interpCoeff2_2 < 0) encoderObj->interpCoeff2_2 = 0;    temp = (Ipp16s)((1<<12) - encoderObj->interpCoeff2_2);    ippsInterpolateC_G729_16s_Sfs(pBwdLPC + BWLPCF1_DIM, temp,                                  encoderObj->pPrevFilt, encoderObj->interpCoeff2_2, pBwdLPC + BWLPCF1_DIM, BWLPCF1_DIM, 12);    ippsInterpolate_G729_16s    (pBwdLPC + BWLPCF1_DIM, encoderObj->pPrevFilt, pBwdLPC, BWLPCF1_DIM);    ippsResidualFilter_G729E_16s(pBwdLPC, BWLPCF_DIM,pSignal, res, LP_SUBFRAME_DIM);    ippsResidualFilter_G729E_16s(&pBwdLPC[BWLPCF1_DIM], BWLPCF_DIM,&pSignal[LP_SUBFRAME_DIM], &res[LP_SUBFRAME_DIM], LP_SUBFRAME_DIM);    gpredB = (Ipp16s)(sigEnergy - enerDB(res, LP_FRAME_DIM));    ippsResidualFilter_G729E_16s(fwdA,LPF_DIM, pSignal, res, LP_SUBFRAME_DIM);    ippsResidualFilter_G729E_16s(&fwdA[LPF_DIM+1], LPF_DIM,&pSignal[LP_SUBFRAME_DIM], &res[LP_SUBFRAME_DIM], LP_SUBFRAME_DIM);    prevF = (Ipp16s)(sigEnergy - enerDB(res, LP_FRAME_DIM));    temp = (Ipp16s)(encoderObj->statGlobal>>7);    temp = (Ipp16s)(temp * 3);    gap = (Ipp16s)(temp + 205);    if( (gpredB > prevF - gap) &&        (prevB > prevF - gap) && (prevB > 0) && (gpredB > 0) )        mode[0] = 1;    else        mode[0] = 0;    for(LSPdist=i=0; i<LPF_DIM; i++) {        temp = (Ipp16s)(oldLSP[i] - newLSP[i]);        LSPdist += temp * temp;    }    if(encoderObj->statGlobal < 13000)        mode[0] = 0;    if(encoderObj->statGlobal < 32000) {        L_threshLPC = 0;    } else {        L_threshLPC = 32212255;    }    if((LSPdist < L_threshLPC)&&(mode[0] == 0)&&(encoderObj->prevLPmode == 1)&&(prevB > 0)&&(gpredB > 0)) {        mode[0] = 1;    }    if(sigEnergy < BWF_HARMONIC_E) {        mode[0] = 0;        if(encoderObj->statGlobal > 13000)            encoderObj->statGlobal = 13000;    } else {        tstDominantBWDmode(&encoderObj->BWDcounter2,&encoderObj->FWDcounter2,&encoderObj->dominantBWDmode, mode[0]);        stat(prevB, prevF, mode[0], encoderObj->prevLPmode,                  &encoderObj->statGlobal, &encoderObj->BWDFrameCounter, &encoderObj->val_BWDFrameCounter);    }    if(mode[0] == 0)        encoderObj->interpCoeff2_2 = 4506;    LOCAL_ALIGN_ARRAY_FREE(32, Ipp16s, res, LP_FRAME_DIM, encoderObj);    return;}void tstDominantBWDmode(   Ipp16s *BWDcounter2,   Ipp16s *FWDcounter2,   Ipp16s *dominantBWDmode,  Ipp16s mode) {    Ipp16s tmp, count_all;    if(mode == 0)        *FWDcounter2+=1;    else *BWDcounter2+=1;    count_all = (Ipp16s)(*BWDcounter2 + *FWDcounter2);    if(count_all == 100) {        count_all >>= 1;        *BWDcounter2 >>= 1;        *FWDcounter2 >>= 1;    }    *dominantBWDmode = 0; if(count_all >= 10) {        tmp = (Ipp16s)(*FWDcounter2<<2);        if(*BWDcounter2 > tmp) *dominantBWDmode = 1;    }    return;}Ipp16s enerDB(Ipp16s *synth, Ipp16s L) {    Ipp16s i,energyLog,index;    Ipp32s L_energy;    ippsDotProd_16s32s_Sfs(synth,synth,L,&L_energy,0);    if(L_energy > (IPP_MAX_32S>>1))        L_energy = (IPP_MAX_32S>>1);    for(i = 0; L_energy > 32; i++)        L_energy >>= 1;    index = (Ipp16s)(L_energy - (1<<4));    energyLog = 617;    if(index < 0)        energyLog = 1;    else {        if(i > 1)            energyLog = (Ipp16s)(i*617);        energyLog = (Ipp16s)(energyLog + energyLogTable[index]);    }    return(energyLog);}static void NormBy0_32s(Ipp32s *src, Ipp32s *dst,Ipp32s len) {    Ipp32s i, sum, norm;    sum = src[0] + 1;    norm = Norm_32s_I(&sum);    dst[0] = sum;    for(i = 1; i <len; i++) {        sum = src[i] + 1;        dst[i] = sum << norm;    }    return;}void BWDLagWindow(Ipp32s *pSrc, Ipp32s *pDst) {    Ipp16s i;    for(i=0; i<BWLPCF_DIM; i++) {        pSrc[i+1] = Mul_32s(pSrc[i+1]>>1,wlag_bwd[i]>>1);    }    NormBy0_32s(pSrc,pDst,BWLPCF_DIM+1);}Ipp16s ExtractBitsG729( const Ipp8u **pBits, Ipp32s *nBit, Ipp32s Count) {    Ipp32s i;    Ipp16s temp, bits = 0;    for( i = 0 ; i < Count ; i ++ ) {        temp   = (Ipp16s)(((pBits[0])[(i + nBit[0])>>3] >> (7 - ((i + nBit[0]) & 7)) ) & 1);        bits <<= 1 ;        bits  = (Ipp16s)(bits + temp);    }    pBits[0] += (Count + nBit[0])>>3;    nBit[0]   = (Count + nBit[0]) & 7;    return bits;}

⌨️ 快捷键说明

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