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

📄 decg729.c

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 C
📖 第 1 页 / 共 5 页
字号:
                    if(badFrameIndicator) {
                        ippsDecodeGain_G729_16s(0, decoderObj->prevFrameQuantEn, NULL, decoderObj->gains);
                    } else {
                        LOCAL_ARRAY(short, gIngx, 2, decoderObj);
                        short foo = 1;
                        gIngx[0] =  (short)(pitchIndx >> CDBK2_BIT_NUM_6K) ;
                        gIngx[1] =  (short)(pitchIndx & (CDBK2_DIM_6K-1)) ;
                        ippsDecodeGain_G729I_16s(energy, foo, decoderObj->prevFrameQuantEn, gIngx, decoderObj->gains );
                        LOCAL_ARRAY_FREE(short, gIngx, 2, decoderObj);
                    }
                } else { /* G729E_CODEC*/
                    if(!badFrameIndicator) {
                        LOCAL_ARRAY(short, gIngx, 2, decoderObj);
                        gIngx[0] = (short)(pitchIndx >> CDBK2_BIT_NUM) ;
                        gIngx[1] = (short)(pitchIndx & (CDBK2_DIM-1));
                        ippsDecodeGain_G729_16s(energy, decoderObj->prevFrameQuantEn, gIngx, decoderObj->gains);
                        LOCAL_ARRAY_FREE(short, gIngx, 2, decoderObj);
                    } else { /* erasure*/
                        short oldCodebookGain = decoderObj->gains[1];

                        ippsDecodeGain_G729I_16s(0, decoderObj->valGainAttenuation, decoderObj->prevFrameQuantEn, NULL, decoderObj->gains );
                        if(decoderObj->BFIcount < 2) {
                            decoderObj->gains[0] = (statStat)? BWF_HARMONIC : PITCH_GAIN_MAX;
                            decoderObj->gains[1] = oldCodebookGain;
                        } else {
                            if(statStat) {
                                if(decoderObj->BFIcount > 10) decoderObj->valGainAttenuation = ( decoderObj->valGainAttenuation * 32604)>>15;
                            } else decoderObj->valGainAttenuation = ( decoderObj->valGainAttenuation * 32112)>>15;
                        }
                    }
                }
            }

            /* update pitch sharpening  with quantized gain pitch */
            decoderObj->betaPreFilter = decoderObj->gains[0];
            if(decoderObj->betaPreFilter > PITCH_SHARP_MAX)
                decoderObj->betaPreFilter = PITCH_SHARP_MAX;
            if(decoderObj->betaPreFilter < PITCH_SHARP_MIN)
                decoderObj->betaPreFilter = PITCH_SHARP_MIN;

            /* synthesis of speech corresponding to excitation*/
            if(badFrameIndicator) {
                decoderObj->BFIcount++;
                if(voiceFlag == 0 ) {
                    gC = decoderObj->gains[1];
                    gPl = 0;
                } else {
                    gC = 0;
                    gPl = decoderObj->gains[0];
                }
            } else {
                gC = decoderObj->gains[1];
                gPl = decoderObj->gains[0];
            }
            ippsInterpolateC_NR_G729_16s_Sfs(&excitation[subfrIdx],gPl,ACELPcodeVec,gC,&excitation[subfrIdx],LP_SUBFRAME_DIM,14);
            if(decoderObj->codecType == G729D_CODEC)
                status = SynthesisFilter_G729_16s_update(ppAz,&excitation[subfrIdx],&synth[subfrIdx],LP_SUBFRAME_DIM,synFltw,BWLPCF_DIM-mAq,0);
            else
                status = SynthesisFilter_G729_16s(ppAz,&excitation[subfrIdx],&synth[subfrIdx],LP_SUBFRAME_DIM,synFltw,BWLPCF_DIM-mAq);
            if(status == ippStsOverflow) {

                ippsRShiftC_16s_I(2,prevExcitat,L_prevExcitat+LP_FRAME_DIM);
                SynthesisFilterOvf_G729_16s(ppAz,&excitation[subfrIdx],&synth[subfrIdx],LP_SUBFRAME_DIM,synFltw,BWLPCF_DIM-mAq);
            }
            if(decoderObj->codecType == G729D_CODEC) {
                ippsPhaseDispersion_G729D_16s(&excitation[subfrIdx], phaseDispExcit, decoderObj->gains[1],
                                              decoderObj->gains[0], ACELPcodeVec, (IppsPhaseDispersion_State_G729D*)decoderObj->PhDispMem);
                SynthesisFilter_G729_16s(ppAz,phaseDispExcit,&synth[subfrIdx],LP_SUBFRAME_DIM,synFltw,BWLPCF_DIM-mAq);
            } else {
                ippsPhaseDispersionUpdate_G729D_16s(decoderObj->gains[0], decoderObj->gains[1],
                                                    (IppsPhaseDispersion_State_G729D*)decoderObj->PhDispMem);
            }
            ppAz += mAq+1;
        }
    }

    if(badFrameIndicator == 0) {
        ippsDotProd_16s32s_Sfs(excitation,excitation,LP_FRAME_DIM,&i,-1);
        decoderObj->SIDflag1 = Norm_32s16s(i);
        decoderObj->SIDflag0 = ((i << decoderObj->SIDflag1)+0x8000)>>16;
        decoderObj->SIDflag1 = 16 - decoderObj->SIDflag1;
    }
    decoderObj->CNGvar = fType;

    if(enerDB(synth, LP_FRAME_DIM) >= BWF_HARMONIC_E) tstDominantBWDmode(&decoderObj->BWDcounter2,&decoderObj->FWDcounter2,&dominantBWDmode, LPmode);

    ippsCopy_16s(&prevExcitat[LP_FRAME_DIM], &prevExcitat[0], L_prevExcitat);

    if( LPmode == 0) {
        ippsCopy_16s(FWDfiltLPC, AzDec, 2*LPF_DIM+2);
        prevM = LPF_DIM;
    } else {
        ippsCopy_16s(BWDfiltLPC, AzDec, 2*BWLPCF1_DIM);
        prevM = BWLPCF_DIM;
    }

    decoderObj->prevBFI = badFrameIndicator;
    decoderObj->prevLPmode = LPmode;
    decoderObj->prevVoiceFlag = voiceFlag;

    if(badFrameIndicator != 0)
        decoderObj->interpCoeff2 = (1<<12);
    else {
        if(LPmode == 0)
            decoderObj->interpCoeff2 = 0;
        else {
            if(dominantBWDmode == 1)
                decoderObj->interpCoeff2 -= 410;
            else decoderObj->interpCoeff2 -= 2048;
                if(decoderObj->interpCoeff2 < 0)
                    decoderObj->interpCoeff2= 0;
        }
    }
    decoderObj->voiceFlag = 0;
    pAz = AzDec;

    if (decoderObj->pstFltMode) {
      if((decoderObj->codecType == G729_CODEC)&&(fType>2)) {
        for(subfrIdx=0; subfrIdx<LP_FRAME_DIM; subfrIdx+=LP_SUBFRAME_DIM) {
            Post_G729(prevFrameDelay1,(short)subfrIdx,pAz,&dst[subfrIdx],&subfrVoiceFlag,decoderObj);
            if(subfrVoiceFlag != 0) {
                decoderObj->voiceFlag = subfrVoiceFlag;
            }
            pAz += LPF_DIM+1;
        }
      } else {
        parm = decoderObj->decPrm;
        if(fType<4) {
            L_hSt = IMP_RESP_LEN;
            decoderObj->gammaPost1 = BWF1_PST;
            decoderObj->gammaPost2 = BWF2_PST;
            decoderObj->gammaHarm = BWF_HARMONIC;
        } else {
            L_hSt = IMP_RESP_LEN_E;
            /* reduce postfiltering */
            if((parm[2] == 1) && (dominantBWDmode == 1)) {
                decoderObj->gammaHarm -= 410;
                if(decoderObj->gammaHarm < 0)
                    decoderObj->gammaHarm = 0;
                decoderObj->gammaPost1 -= 1147;
                if(decoderObj->gammaPost1 < 0)
                    decoderObj->gammaPost1 = 0;
                decoderObj->gammaPost2 -= 1065;
                if(decoderObj->gammaPost2 < 0)
                    decoderObj->gammaPost2 = 0;
            } else {
                decoderObj->gammaHarm += 410;
                if(decoderObj->gammaHarm > BWF_HARMONIC_E)
                    decoderObj->gammaHarm = BWF_HARMONIC_E;
                decoderObj->gammaPost1 += 1147;
                if(decoderObj->gammaPost1 > BWF1_PST_E)
                    decoderObj->gammaPost1 = BWF1_PST_E;
                decoderObj->gammaPost2 += 1065;
                if(decoderObj->gammaPost2 > BWF2_PST_E)
                    decoderObj->gammaPost2 = BWF2_PST_E;
            }
        }

        for(i=0; i<LP_FRAME_DIM; i+=LP_SUBFRAME_DIM) {
            Post_G729I(prevFrameDelay1, (short)i, pAz, &dst[i],
                       &subfrVoiceFlag, L_hSt, prevM, fType, decoderObj);
            if(subfrVoiceFlag != 0)
                decoderObj->voiceFlag = subfrVoiceFlag;
            pAz += prevM+1;
        }
      }
      ippsHighPassFilter_G729_16s_ISfs(dst,LP_FRAME_DIM,13,decoderObj->postProc);
    } else {
      ippsAdd_16s(synth, synth, dst, LP_FRAME_DIM);
    }

    CLEAR_SCRATCH_MEMORY(decoderObj);

    return APIG729_StsNoErr;
}

void Post_G729Base(
                  short delayVal,          /* pitch delayVal given by coder */
                  short subfrIdx,
                  const short *srcLPC,     /* LPC coefficients for current subframe */
                  short *dstSignal,        /* postfiltered output */
                  short *voiceFlag,        /* voiceFlag decision 0 = uv,  > 0 delayVal */
                  short fType,
                  G729Decoder_Obj *decoderObj
                  ) {
    short bwf1 = decoderObj->gammaPost1;
    short bwf2 = decoderObj->gammaPost2;
    short gamma_harm = decoderObj->gammaHarm;
    LOCAL_ARRAY(int,irACF,2, decoderObj);
    LOCAL_ALIGN_ARRAY(32, short,y, IMP_RESP_LEN_E, decoderObj);
    LOCAL_ALIGN_ARRAY(32,short, LTPsignal, LP_SUBFRAME_DIM+1, decoderObj);
    LOCAL_ALIGN_ARRAY(32,short, LPCdenom, LPF_DIM+1, decoderObj);  /* denominator srcLPC */
    LOCAL_ALIGN_ARRAY(32,short, LPCnum, IMP_RESP_LEN_E, decoderObj); /* numerator srcLPC */
    short tmp, g0Val, temp, ACFval0, ACFval1;
    short *iirdl = ((SynthesisFilterState*)decoderObj->synFltw0)->buffer;
    int   L_g0Val, normVal = 0, status = 0;
    const short *signal_ptr = &decoderObj->LTPostFilt[SYNTH_BWD_DIM+subfrIdx];
    irACF[0] = irACF[1] = 0;
    ippsZero_16s(LPCnum, IMP_RESP_LEN_E);

    ippsMulPowerC_NR_16s_Sfs(srcLPC,bwf1, LPCdenom,LPF_DIM+1,15);
    ippsMulPowerC_NR_16s_Sfs(srcLPC,bwf2, LPCnum,LPF_DIM+1,15);

    ippsResidualFilter_G729_16s((short *)signal_ptr, LPCnum, &decoderObj->resFilBuf1[RES_FIL_DIM]);

    if(fType > 1)
        ippsLongTermPostFilter_G729_16s(gamma_harm,delayVal, &decoderObj->resFilBuf1[RES_FIL_DIM],
                                        LTPsignal + 1, voiceFlag);
    else {
        *voiceFlag = 0;
        ippsCopy_16s(&decoderObj->resFilBuf1[RES_FIL_DIM], LTPsignal + 1, LP_SUBFRAME_DIM);
    }
    LTPsignal[0] = decoderObj->preemphFilt;
    ippsSynthesisFilter_NR_16s_Sfs(LPCdenom, LPCnum,y,IMP_RESP_LEN, 12, &decoderObj->zeroPostFiltVec1[LPF_DIM+1]);

    status = ippsAutoCorr_NormE_16s32s(y,IMP_RESP_LEN,irACF,2,&normVal);
    ACFval0 = irACF[0]>>16;
    ACFval1 = irACF[1]>>16;
    if( ACFval0 < Abs_16s(ACFval1) || status) {
        tmp = 0;
    } else {
        tmp = (Abs_16s(ACFval1)<<15)/ACFval0;
        if(ACFval1 > 0) {
            tmp = -tmp;
        }
    }

    ippsAbs_16s_I(y,IMP_RESP_LEN);
    ippsSum_16s32s_Sfs(y,IMP_RESP_LEN,&L_g0Val,0);
    g0Val = ShiftL_32s(L_g0Val, 14)>>16;

    if(g0Val > 1024) {
        temp = (1024<<15)/g0Val;
        ippsMulC_NR_16s_ISfs(temp,LTPsignal + 1,LP_SUBFRAME_DIM,15);
    }
    ippsSynthesisFilter_NR_16s_ISfs(LPCdenom, LTPsignal + 1, LP_SUBFRAME_DIM, 12, &iirdl[BWLPCF_DIM-LPF_DIM]);
    decoderObj->preemphFilt = LTPsignal[LP_SUBFRAME_DIM];
    ippsCopy_16s(&LTPsignal[LP_SUBFRAME_DIM-LPF_DIM+1], &iirdl[BWLPCF_DIM-LPF_DIM], LPF_DIM );
    ippsTiltCompensation_G729E_16s(tmp,LTPsignal, dstSignal);
    ippsGainControl_G729_16s_I(signal_ptr, dstSignal, &decoderObj->gainExact);
    ippsCopy_16s(&decoderObj->resFilBuf1[LP_SUBFRAME_DIM], &decoderObj->resFilBuf1[0], RES_FIL_DIM);

    LOCAL_ALIGN_ARRAY_FREE(32,short, LPCnum, IMP_RESP_LEN_E, decoderObj); /* numerator srcLPC  */
    LOCAL_ALIGN_ARRAY_FREE(32,short, LPCdenom, LPF_DIM+1, decoderObj);  /* denominator srcLPC  */
    LOCAL_ALIGN_ARRAY_FREE(32, short, LTPsignal,LP_SUBFRAME_DIM+1,decoderObj);
    LOCAL_ALIGN_ARRAY_FREE(32, short,y, IMP_RESP_LEN_E,decoderObj);
    LOCAL_ARRAY_FREE(int, irACF, 2,decoderObj);
    return;
}

void Post_G729( short delayVal, short subfrIdx, const short *srcLPC, short *dstSignal,
              short *voiceFlag, G729Decoder_Obj *decoderObj) {
    short *gainExact = &decoderObj->gainExact;
    short *iirdl = ((SynthesisFilterState*)decoderObj->synFltw0)->buffer;
    LOCAL_ALIGN_ARRAY(32, short,y, IMP_RESP_LEN, decoderObj);
    LOCAL_ALIGN_ARRAY(32, short, LTPsignalBuf, LP_SUBFRAME_DIM+1+LPF_DIM, decoderObj);
    LOCAL_ALIGN_ARRAY(32, short, LPCnum, LPF_DIM+1, decoderObj);
    short tmp;
    const short *res = &decoderObj->LTPostFilt[SYNTH_BWD_DIM+subfrIdx];
    short *LTPsignal = LTPsignalBuf+LPF_DIM+1;

    ippsMul_NR_16s_Sfs(g729gammaFac2_pst,srcLPC, LPCnum,LPF_DIM+1,15);
    ippsResidualFilter_G729_16s(res, LPCnum, decoderObj->resFilBuf1 + RES_FIL_DIM);
    ippsLongTermPostFilter_G729_16s(BWF_HARMONIC,delayVal, decoderObj->resFilBuf1 + RES_FIL_DIM, LTPsignal+1, &tmp);
    *voiceFlag = (tmp != 0);

    ippsCopy_16s(&decoderObj->resFilBuf1[LP_SUBFRAME_DIM], &decoderObj->resFilBuf1[0], RES_FIL_DIM);
    ippsCopy_16s(iirdl+20,LTPsignal+1-LPF_DIM, LPF_DIM );
    ippsShortTermPostFilter_G729_16s(srcLPC, LTPsignal+1,LTPsignal+1,y);
    ippsCopy_16s((LTPsignal+1+LP_SUBFRAME_DIM-BWLPCF_DIM), iirdl, BWLPCF_DIM);

    LTPsignal[0] = decoderObj->preemphFilt;
    decoderObj->preemphFilt = LTPsignal[LP_SUBFRAME_DIM];

    ippsTiltCompensation_G729_16s(y, LTPsignal+1);
    ippsCopy_16s(LTPsignal+1, dstSignal,LP_SUBFRAME_DIM);
    ippsGainControl_G729_16s_I(res, dstSignal, gainExact);

    LOCAL_ALIGN_ARRAY_FREE(32, short, LPCnum, LPF_DIM+1,decoderObj);
    LOCAL_ALIGN_ARRAY_FREE(32, short, LTPsignalBuf,LP_SUBFRAME_DIM+1+LPF_DIM,decoderObj);
    LOCAL_ALIGN_ARRAY_FREE(32, short,y, IMP_RESP_LEN,decoderObj);

    return;
}

⌨️ 快捷键说明

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