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

📄 decg729fp.c

📁 G.729 and G.723.1 codecs x86 (and x86_64) Linux and FreeBSD source code for Asterisk open source PBX
💻 C
📖 第 1 页 / 共 4 页
字号:
/*/////////////////////////////////////////////////////////////////////////////////                  INTEL CORPORATION PROPRIETARY INFORMATION//     This software is supplied under the terms of a license agreement or//     nondisclosure agreement with Intel Corporation and may not be copied//     or disclosed except in accordance with the terms of that agreement.//          Copyright(c) 2004-2007 Intel Corporation. All Rights Reserved.////     Intel(R) Integrated Performance Primitives//     USC - Unified Speech Codec interface library//// By downloading and installing USC codec, you hereby agree that the// accompanying Materials are being provided to you under the terms and// conditions of the End User License Agreement for the Intel(R) Integrated// Performance Primitives product previously accepted by you. Please refer// to the file ippEULA.rtf or ippEULA.txt located in the root directory of your Intel(R) IPP// product installation for more information.//// A speech coding standards promoted by ITU, ETSI, 3GPP and other// organizations. Implementations of these standards, or the standard enabled// platforms may require licenses from various entities, including// Intel Corporation.////// Purpose: G.729 floating-point speech codec: decode API functions.//*/#include <math.h>#include "owng729fp.h"static void post_filter_I(G729FPDecoder_Obj* decoderObj, Ipp32f *pSynth, Ipp32f *pLPC, Ipp32s pitchDelay, Ipp32s dominant,                          Ipp32s Vad, Ipp32s pstLPCOrder, Ipp32f *dst,Ipp32s rate);static void Post_G729A(G729FPDecoder_Obj *decoderObj, Ipp32f *pSrcDstSynthSpeech, Ipp32f *pSrcLPC,                        Ipp32s *pSrcDecodedPitch, Ipp32s Vad);/* filter coefficients (fc = 100 Hz ) */static __ALIGN32 CONST Ipp32f b100[3] = {0.93980581E+00f, -0.18795834E+01f,  0.93980581E+00f};static __ALIGN32 CONST Ipp32f a100[3] = {1.00000000E+00f,  0.19330735E+01f, -0.93589199E+00f};/* tables of positions for each track */static __ALIGN32 CONST Ipp16s trackTbl0[32] = { 1, 3, 8, 6, 18, 16, 11, 13, 38, 36, 31, 33, 21, 23, 28, 26, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};static __ALIGN32 CONST Ipp16s trackTbl1[32] = {0, 2, 5, 4, 12, 10, 7, 9, 25, 24, 20, 22, 14, 15, 19, 17,36, 31, 21, 26, 1, 6, 16, 11, 27, 29, 32, 30, 39, 37, 34, 35};static Ipp32s ownDecoderSize(G729Codec_Type codecType){   Ipp32s codecSize, fltsize;   codecSize = sizeof(G729FPDecoder_Obj);   ippsIIRGetStateSize_32f(2,&fltsize);   codecSize += fltsize;   PHDGetSize(&fltsize);   codecSize += fltsize;   ippsWinHybridGetStateSize_G729E_32f(&fltsize);   codecSize += fltsize;   if(codecType!=G729A_CODEC) {      PSTGetSize(&fltsize);      codecSize += fltsize;   }   return codecSize;}G729_CODECFUN( APIG729_Status, apiG729FPDecoder_Alloc,         (G729Codec_Type codecType, Ipp32s *pCodecSize)){   if ((codecType != G729_CODEC)&&(codecType != G729A_CODEC)      &&(codecType != G729D_CODEC)&&(codecType != G729E_CODEC)&&(codecType != G729I_CODEC)){      return APIG729_StsBadCodecType;   }   *pCodecSize = ownDecoderSize(codecType);   return APIG729_StsNoErr;}G729_CODECFUN( APIG729_Status, apiG729FPDecoder_Init,         (G729FPDecoder_Obj* decoderObj, G729Codec_Type codecType)){   Ipp32s i,fltsize;   void* pBuf;   Ipp32f coeff[6];   Ipp8s* oldMemBuff;   if ((codecType != G729_CODEC)&&(codecType != G729A_CODEC)      &&(codecType != G729D_CODEC)&&(codecType != G729E_CODEC)&&(codecType != G729I_CODEC)){      return APIG729_StsBadCodecType;   }   oldMemBuff = decoderObj->Mem.base; /* if Reinit */   ippsZero_16s((Ipp16s*)decoderObj,sizeof(G729FPDecoder_Obj)>>1) ;   decoderObj->objPrm.objSize = ownDecoderSize(codecType);   decoderObj->objPrm.key = DEC_KEY;   decoderObj->objPrm.codecType = codecType;   coeff[0] = b100[0];   coeff[1] = b100[1];   coeff[2] = b100[2];   coeff[3] = a100[0];   coeff[4] = -a100[1];   coeff[5] = -a100[2];   pBuf = (Ipp8s*)decoderObj + sizeof(G729FPDecoder_Obj);   ippsIIRInit_32f(&decoderObj->iirstate,coeff,2,NULL,pBuf);   ippsIIRGetStateSize_32f(2,&fltsize);   decoderObj->phdMem = (Ipp8s *)((Ipp8s*)pBuf + fltsize);   PHDGetSize(&fltsize);   decoderObj->pHWState = (IppsWinHybridState_G729E_32f *)((Ipp8s*)decoderObj->phdMem + fltsize);   ippsZero_32f(decoderObj->OldExcitationBuffer, PITCH_LAG_MAX+INTERPOL_LEN);   decoderObj->fBetaPreFilter        = PITCH_SHARPMIN;   decoderObj->prevPitchDelay      = 60;   decoderObj->fCodeGain    = 0.;   decoderObj->fPitchGain   = 0.;   ippsCopy_32f(InitLSP, decoderObj->OldLSP, LPC_ORDER);   decoderObj->PastQuantEnergy[0]=decoderObj->PastQuantEnergy[1]=decoderObj->PastQuantEnergy[2]=decoderObj->PastQuantEnergy[3]=-14.0;   for(i=0; i<MOVING_AVER_ORDER; i++)     ippsCopy_32f (InitFrequences, &decoderObj->PrevFreq[i][0], LPC_ORDER );   decoderObj->prevMA = 0;   ippsCopy_32f (InitFrequences, decoderObj->prevLSF, LPC_ORDER );   /* for G.729B */   decoderObj->sFESeed = 21845;   /* CNG variables */   decoderObj->prevFrameType = 3;   decoderObj->sCNGSeed = INIT_SEED_VAL;   decoderObj-> SID = 0.f;   decoderObj->fCurrGain = 0.f;   ownCOS_G729_32f((Ipp32f*)InitFrequences, decoderObj->SIDLSP, LPC_ORDER);   decoderObj->fSIDGain = SIDGainTbl[0];   ippsZero_32f(decoderObj->SynFltMemory, BWD_LPC_ORDER);   PHDInit(decoderObj->phdMem);   if(codecType==G729A_CODEC) {      ippsZero_32f(decoderObj->PstFltMemoryA, LPC_ORDER);      decoderObj->fPastGain = 1.0;      ippsZero_32f(decoderObj->ResidualBufferA, PITCH_LAG_MAX+SUBFR_LEN);      decoderObj->ResidualMemory  = decoderObj->ResidualBufferA + PITCH_LAG_MAX;      ippsZero_32f(decoderObj->PstSynMemoryA, LPC_ORDER);      decoderObj->fPreemphMemoryA = 0.f;   } else {      //PHDGetSize(&fltsize);      ippsWinHybridGetStateSize_G729E_32f(&fltsize);      decoderObj->pstMem = (Ipp8s *)((Ipp8s*)decoderObj->pHWState + fltsize);      ippsZero_32f(decoderObj->SynthBuffer, BWD_ANALISIS_WND_LEN);      decoderObj->prevFracPitchDelay = 0;      ippsWinHybridInit_G729E_32f(decoderObj->pHWState);      ippsZero_32f(decoderObj->BackwardUnqLPC, BWD_LPC_ORDERP1);      decoderObj->BackwardUnqLPC[0]   = 1.;      ippsZero_32f(decoderObj->BackwardLPCMemory, BWD_LPC_ORDERP1);      decoderObj->BackwardLPCMemory[0] = 1.;      decoderObj->lPrevVoicing = 0;      decoderObj->lPrevBFI     = 0;      decoderObj->prevLPCMode    = 0;      decoderObj->fFEInterpolationCoeff     = 0.;      decoderObj->fInterpolationCoeff        = 1.1f;       /* Filter interpolation parameter */      ippsZero_32f(decoderObj->PrevFlt, BWD_LPC_ORDERP1);      decoderObj->PrevFlt[0] = 1.;      decoderObj->lPrevPitchPT     = 30;      decoderObj->lStatPitchPT     = 0;      decoderObj->lStatPitch2PT     = 0;      decoderObj->lStatFracPT     = 0;      ippsZero_32f(decoderObj->OldBackwardLPC, BWD_LPC_ORDERP1);      decoderObj->OldBackwardLPC[0]   = 1.;      decoderObj->OldBackwardRC[0] = decoderObj->OldBackwardRC[1] = 0.f;      decoderObj->fPitchGainMemory   = 0.;      decoderObj->fCodeGainMemory   = 0.;      decoderObj->fGainMuting       = 1.;      decoderObj->lBFICounter      = 0;      decoderObj->sBWDStatInd       = 0;      decoderObj->lVoicing = 60;      decoderObj->g1PST = GAMMA1_POSTFLT_E;      decoderObj->g2PST = GAMMA2_POSTFLT_E;      decoderObj->gHarmPST  = GAMMA_HARM_POSTFLT_E;      decoderObj->sBWDFrmCounter = 0;      decoderObj->sFWDFrmCounter = 0;      PSTInit(decoderObj->pstMem);   }   apiG729FPDecoder_InitBuff(decoderObj,oldMemBuff);   return APIG729_StsNoErr;}G729_CODECFUN( APIG729_Status, apiG729FPDecoder_InitBuff,         (G729FPDecoder_Obj* decoderObj, Ipp8s *buff)){    if(buff==NULL) return APIG729_StsBadArgErr;    if(decoderObj==NULL) return APIG729_StsBadArgErr;   if(NULL==decoderObj || NULL==buff)      return APIG729_StsBadArgErr;   decoderObj->Mem.base = buff;   decoderObj->Mem.CurPtr = decoderObj->Mem.base;   decoderObj->Mem.VecPtr = (Ipp32s *)(decoderObj->Mem.base+G729FP_ENCODER_SCRATCH_MEMORY_SIZE);   return APIG729_StsNoErr;}G729_CODECFUN( APIG729_Status, apiG729FPDecode,         (G729FPDecoder_Obj* decoderObj,const Ipp8u* src, Ipp32s frametype, Ipp16s* dst)){   LOCAL_ALIGN_ARRAY(32, Ipp32f, backwardLPC, 2*BWD_LPC_ORDERP1, decoderObj);   /* LPC Backward filter */   LOCAL_ALIGN_ARRAY(32, Ipp32f, forwardLPC, 2*LPC_ORDERP1, decoderObj);       /* LPC Forward filter */   LOCAL_ALIGN_ARRAY(32, Ipp32f, backwardReflectCoeff, BWD_LPC_ORDER, decoderObj);        /* LPC backward reflection coefficients */   LOCAL_ALIGN_ARRAY(32, Ipp32f, forwardAutoCorr, BWD_LPC_ORDERP1, decoderObj);       /* Autocorrelations (backward) */   LOCAL_ALIGN_ARRAY(32, Ipp32f, CurrLSP, LPC_ORDER, decoderObj);           /* LSPs             */   LOCAL_ALIGN_ARRAY(32, Ipp32f, ACELPCodeVec, SUBFR_LEN, decoderObj);        /* ACELP codevector */   LOCAL_ALIGN_ARRAY(32, Ipp32f, PhaseDispExc, SUBFR_LEN, decoderObj);  /* excitation after phase dispersion */   LOCAL_ALIGN_ARRAY(32, Ipp32f, flDst, FRM_LEN, decoderObj);   LOCAL_ALIGN_ARRAY(32, Ipp32f, TmpAlignVec, WINDOW_LEN,decoderObj);   LOCAL_ARRAY(Ipp32f, tmpLSP, LPC_ORDER, decoderObj);   LOCAL_ARRAY(Ipp32s, decPrm, 20, decoderObj);   LOCAL_ARRAY(Ipp32s, T2, 2, decoderObj);          /* Decoded Pitch              */   LOCAL_ARRAY(Ipp32s, delayLine, 2, decoderObj);   Ipp32f *Excitation,*pSynth;   Ipp32s i, j, NSbfr;   Ipp32s PitchDelay, index;   Ipp32s bfi;                      /* Bad frame indicator */   Ipp32s badPitch=0;                 /* bad pitch indicator */   Ipp32s LPCMode;                  /* Backward / Forward mode indication */   Ipp32f PitchGain, CodeGain;      /* fixed and adaptive codebook gain */   Ipp32f tmp, energy;   Ipp32f *pLPC;   Ipp32s rate, highStatIndicator=0, aqLen, isSaturateAZ;   Ipp32s FrameType, pstLPCOrder, isBWDDominant=0, Vad, parm2;   Ipp32f tmp_lev;   Ipp32s nsubfr;   IppStatus sts;   Ipp32s   *pDecPrm;   const  Ipp8u *pParm;   Ipp32f fTmp;   if(NULL==decoderObj || NULL==src || NULL ==dst)      return APIG729_StsBadArgErr;   if(decoderObj->objPrm.objSize <= 0)      return APIG729_StsNotInitialized;   if(DEC_KEY != decoderObj->objPrm.key)      return APIG729_StsBadCodecType;   Excitation = decoderObj->OldExcitationBuffer + PITCH_LAG_MAX + INTERPOL_LEN;   pSynth = decoderObj->SynthBuffer + BWD_SYNTH_MEM;   pParm = src;   if(frametype == -1){ /* erased*/      decPrm[1] = 0; /* FrameType =sil ???*/      decPrm[0] = 1; /* bfi = 1, corrupted*/      ippsCopy_32f ((Ipp32f*)decoderObj->prevSID, (Ipp32f*)&decPrm[2], 4);   }else if(frametype == 0){ /* untransmitted sil*/      decPrm[1] = 0; /* FrameType =sil */      decPrm[0] = 0; /* bfi = 0, */      ippsCopy_32f ((Ipp32f*)decoderObj->prevSID, (Ipp32f*)&decPrm[2], 4);   }else if(frametype == 1){ /* SID*/      decPrm[1] = 1; /* FrameType=sid */      decPrm[0] = 0; /* bfi = 0*/      i=0;      decPrm[1+1] = ExtractBitsG729FP(&pParm,&i,1);      decPrm[1+2] = ExtractBitsG729FP(&pParm,&i,5);      decPrm[1+3] = ExtractBitsG729FP(&pParm,&i,4);      decPrm[1+4] = ExtractBitsG729FP(&pParm,&i,5);      ippsCopy_32f ((Ipp32f*)&decPrm[2], (Ipp32f*)decoderObj->prevSID, 4);   }else if(frametype == 2){ /* active frame D*/      decPrm[0] = 0; /* bfi = 0*/      decPrm[1] = 2; /* FrameType=voice d */      i=0;      decPrm[2] = ExtractBitsG729FP(&pParm,&i,1+N_BITS_1ST_STAGE);      decPrm[3] = ExtractBitsG729FP(&pParm,&i,N_BITS_2ND_STAGE*2);      decPrm[4] = ExtractBitsG729FP(&pParm,&i,8);      decPrm[5] = ExtractBitsG729FP(&pParm,&i,9);      decPrm[6] = ExtractBitsG729FP(&pParm,&i,2);

⌨️ 快捷键说明

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