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

📄 decg729fp.c

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 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-2005 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 ipplic.htm 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, float *pSynth, float *pLPC, int pitchDelay, int dominant,
                          int Vad, int pstLPCOrder, float *dst,int rate);
static void Post_G729A(G729FPDecoder_Obj *decoderObj, float *pSrcDstSynthSpeech, float *pSrcLPC,
                        int *pSrcDecodedPitch, int Vad);

/* filter coefficients (fc = 100 Hz ) */

static __ALIGN32 CONST float b100[3] = {0.93980581E+00f, -0.18795834E+01f,  0.93980581E+00f};
static __ALIGN32 CONST float a100[3] = {1.00000000E+00f,  0.19330735E+01f, -0.93589199E+00f};
/* tables of positions for each track */
static __ALIGN32 CONST short 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 short 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 int ownDecoderSize(G729Codec_Type codecType)
{
   int 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, int *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))
{
   int i,fltsize;
   void* pBuf;
   Ipp32f coeff[6];

   if ((codecType != G729_CODEC)&&(codecType != G729A_CODEC)
      &&(codecType != G729D_CODEC)&&(codecType != G729E_CODEC)&&(codecType != G729I_CODEC)){
      return APIG729_StsBadCodecType;
   }

   ippsZero_16s((short*)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 = (char*)decoderObj + sizeof(G729FPDecoder_Obj);
   ippsIIRInit_32f(&decoderObj->iirstate,coeff,2,NULL,pBuf);

   ippsIIRGetStateSize_32f(2,&fltsize);
   decoderObj->phdMem = (char *)((char*)pBuf + fltsize);
   PHDGetSize(&fltsize);
   decoderObj->pHWState = (IppsWinHybridState_G729E_32f *)((char*)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.;
   decoderObj->fCurrGain = 0.f;
   ownCOS_G729_32f((float*)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 = (char *)((char*)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);
   }
   return APIG729_StsNoErr;
}

G729_CODECFUN( APIG729_Status, apiG729FPDecoder_InitBuff,
         (G729FPDecoder_Obj* decoderObj, char *buff))
{
#if !defined (NO_SCRATCH_MEMORY_USED)

   if(NULL==decoderObj || NULL==buff)
      return APIG729_StsBadArgErr;

   decoderObj->Mem.base = buff;
   decoderObj->Mem.CurPtr = decoderObj->Mem.base;
   decoderObj->Mem.VecPtr = (int *)(decoderObj->Mem.base+G729FP_ENCODER_SCRATCH_MEMORY_SIZE);
#endif /*SCRATCH_IDAIS*/
   return APIG729_StsNoErr;
}

G729_CODECFUN( APIG729_Status, apiG729FPDecode,
         (G729FPDecoder_Obj* decoderObj,const unsigned char* src, int frametype, short* dst))
{
   LOCAL_ALIGN_ARRAY(32, float, backwardLPC, 2*BWD_LPC_ORDERP1, decoderObj);   /* LPC Backward filter */
   LOCAL_ALIGN_ARRAY(32, float, forwardLPC, 2*LPC_ORDERP1, decoderObj);       /* LPC Forward filter */
   LOCAL_ALIGN_ARRAY(32, float, backwardReflectCoeff, BWD_LPC_ORDER, decoderObj);        /* LPC backward reflection coefficients */
   LOCAL_ALIGN_ARRAY(32, float, forwardAutoCorr, BWD_LPC_ORDERP1, decoderObj);       /* Autocorrelations (backward) */
   LOCAL_ALIGN_ARRAY(32, float, CurrLSP, LPC_ORDER, decoderObj);           /* LSPs             */
   LOCAL_ALIGN_ARRAY(32, float, ACELPCodeVec, SUBFR_LEN, decoderObj);        /* ACELP codevector */
   LOCAL_ALIGN_ARRAY(32, float, PhaseDispExc, SUBFR_LEN, decoderObj);  /* excitation after phase dispersion */
   LOCAL_ALIGN_ARRAY(32, float, flDst, FRM_LEN, decoderObj);
   LOCAL_ALIGN_ARRAY(32, float, TmpAlignVec, WINDOW_LEN,decoderObj);
   LOCAL_ARRAY(float, tmpLSP, LPC_ORDER, decoderObj);
   LOCAL_ARRAY(int, decPrm, 20, decoderObj);
   LOCAL_ARRAY(int, T2, 2, decoderObj);          /* Decoded Pitch              */
   LOCAL_ARRAY(int, delayLine, 2, decoderObj);

   float *Excitation,*pSynth;
   int    i, j, NSbfr;
   int    PitchDelay, index;
   int    bfi;                      /* Bad frame indicator */
   int    badPitch;                 /* bad pitch indicator */
   int    LPCMode;                  /* Backward / Forward mode indication */
   float  PitchGain, CodeGain;      /* fixed and adaptive codebook gain */
   float  tmp, energy;
   float *pLPC;
   int    rate, highStatIndicator, aqLen, isSaturateAZ;
   int    FrameType, pstLPCOrder, isBWDDominant, Vad, parm2;
   float  tmp_lev;

   int    nsubfr;
   IppStatus sts;
   int   *pDecPrm;
   const  unsigned char *pParm;
   float  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);
      decPrm[7] = ExtractBitsG729FP(&pParm,&i,6);
      decPrm[8] = ExtractBitsG729FP(&pParm,&i,4);
      decPrm[9] = ExtractBitsG729FP(&pParm,&i,9);
      decPrm[10] = ExtractBitsG729FP(&pParm,&i,2);
      decPrm[11] = ExtractBitsG729FP(&pParm,&i,6);

⌨️ 快捷键说明

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