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

📄 encg729fp.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 页
字号:
/*/////////////////////////////////////////////////////////////////////////////////                  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: encode API functions.//*/#include <math.h>#include "vadg729fp.h"#include "owng729fp.h"__ALIGN32 CONST Ipp32f InitLSP[LPC_ORDER] =     { 0.9595f,  0.8413f,  0.6549f,  0.4154f,  0.1423f,      -0.1423f, -0.4154f, -0.6549f, -0.8413f, -0.9595f};__ALIGN32 CONST Ipp32f InitFrequences[LPC_ORDER] = {  /* previous LSP vector(init) */ 0.285599f,  0.571199f,  0.856798f,  1.142397f,  1.427997f, 1.713596f,  1.999195f,  2.284795f,  2.570394f,  2.855993f};     /* IPP_PI*(j+1)/(LPC_ORDER+1) */static __ALIGN32 CONST Ipp32f b140[3] = {0.92727435E+00f, -0.18544941E+01f, 0.92727435E+00f};static __ALIGN32 CONST Ipp32f a140[3] = {1.00000000E+00f, 0.19059465E+01f, -0.91140240E+00f};static __ALIGN32 CONST Ipp32f lwindow[LPC_ORDER+2] = {   0.99879038f, 0.99546894f, 0.98995779f,   0.98229335f, 0.97252620f, 0.96072035f,   0.94695264f, 0.93131180f, 0.91389754f,   0.89481964f, 0.87419660f, 0.85215437f};__ALIGN32 CONST Ipp32f lagBwd[BWD_LPC_ORDER] = {   0.999892f,  0.999869f,  0.999831f,  0.999777f,  0.999707f,   0.999622f,  0.999522f,  0.999407f,  0.999276f,  0.999129f,   0.998968f,  0.998790f,  0.998598f,  0.998390f,  0.998167f,   0.997928f,  0.997674f,  0.997405f,  0.997121f,  0.996821f,   0.996506f,  0.996175f,  0.995830f,  0.995469f,  0.995093f,   0.994702f,  0.994295f,  0.993874f,  0.993437f,  0.992985f,};/* Quantization of SID gain */__ALIGN32 CONST Ipp32f SIDGainTbl[32] = {      0.502f,    1.262f,    2.000f,    3.170f,      5.024f,    7.962f,   12.619f,   15.887f,     20.000f,   25.179f,   31.698f,   39.905f,     50.238f,   63.246f,   79.621f,  100.237f,    126.191f,  158.866f,  200.000f,  251.785f,    316.979f,  399.052f,  502.377f,  632.456f,    796.214f, 1002.374f, 1261.915f, 1588.656f,   2000.000f, 2517.851f, 3169.786f, 3990.525f};#define         AVG(a,b,c,d) (Ipp32s)( ((a)+(b)+(c)+(d))/4.0f + 0.5f)static void UpdateVad_I(G729FPEncoder_Obj* encoderObj, Ipp32f *Excitation, Ipp32f *forwardLPC, Ipp32f *WeightedSpeech,                 Ipp32f *gamma1, Ipp32f *gamma2, Ipp32f *pSynth,                 Ipp32f *pError, Ipp32f *SpeechWnd, Ipp32s* dst,G729Codec_Type codecType);static void UpdateVad_A(G729FPEncoder_Obj* encoderObj, Ipp32f *Excitation,                        Ipp32f *WeightedSpeech, Ipp32f *SpeechWnd, Ipp32s* dst);static void UpdateCNG(Ipp32f *pSrcAutoCorr, Ipp32s Vad, Ipp8s *cngMem);static Ipp32s CodecType2Num(G729Codec_Type codecType){    switch(codecType) {    case G729D_CODEC:       return 0;    case G729_CODEC:       return 1;    case G729A_CODEC:       return 1;    case G729E_CODEC:       return 2;    }    return -1;}static Ipp32s ownEncoderObjSize(){   Ipp32s codecSize, fltsize;   codecSize = sizeof(G729FPEncoder_Obj);   ippsIIRGetStateSize_32f(2,&fltsize);   codecSize += fltsize;   VADGetSize(&fltsize);   codecSize += fltsize;   CNGGetSize(&fltsize);   codecSize += fltsize;   MSDGetSize(&fltsize);   codecSize += fltsize;   ippsWinHybridGetStateSize_G729E_32f(&fltsize);   codecSize += fltsize;   return codecSize;}G729_CODECFUN( APIG729_Status, apiG729FPEncoder_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 = ownEncoderObjSize();   return APIG729_StsNoErr;}G729_CODECFUN( APIG729_Status, apiG729FPCodec_ScratchMemoryAlloc,(Ipp32s *pCodecSize)){   if(NULL==pCodecSize)      return APIG729_StsBadArgErr;   *pCodecSize = G729FP_ENCODER_SCRATCH_MEMORY_SIZE;   return APIG729_StsNoErr;}G729_CODECFUN( APIG729_Status, apiG729FPEncoder_Mode,         (G729FPEncoder_Obj* encoderObj, G729Encode_Mode mode)){   if(G729Encode_VAD_Enabled != mode && G729Encode_VAD_Disabled != mode){      return APIG729_StsBadArgErr;   }   encoderObj->objPrm.mode = mode;   return APIG729_StsNoErr;}G729_CODECFUN( APIG729_Status, apiG729FPEncoder_InitBuff,         (G729FPEncoder_Obj* encoderObj, Ipp8s *buff)){    if(buff==NULL) return APIG729_StsBadArgErr;    if(encoderObj==NULL) return APIG729_StsBadArgErr;   if(NULL==encoderObj || NULL==buff)      return APIG729_StsBadArgErr;   encoderObj->Mem.base = buff;   encoderObj->Mem.CurPtr = encoderObj->Mem.base;   encoderObj->Mem.VecPtr = (Ipp32s *)(encoderObj->Mem.base+G729FP_ENCODER_SCRATCH_MEMORY_SIZE);   return APIG729_StsNoErr;}G729_CODECFUN( APIG729_Status, apiG729FPEncoder_Init,         (G729FPEncoder_Obj* encoderObj, G729Codec_Type codecType, G729Encode_Mode mode)){   Ipp32s i;   Ipp32s fltsize;   void* pBuf;   Ipp32f coeff[6];   Ipp8s* oldMemBuff;   if(NULL==encoderObj)      return APIG729_StsBadArgErr;   if ((codecType != G729_CODEC)&&(codecType != G729A_CODEC)      &&(codecType != G729D_CODEC)&&(codecType != G729E_CODEC)&&(codecType != G729I_CODEC)){      return APIG729_StsBadCodecType;   }   oldMemBuff = encoderObj->Mem.base; /* if Reinit */   ippsZero_16s((Ipp16s*)encoderObj,sizeof(G729FPEncoder_Obj)>>1) ;   encoderObj->objPrm.objSize = ownEncoderObjSize();   encoderObj->objPrm.mode = mode;   encoderObj->objPrm.key = ENC_KEY;   encoderObj->objPrm.codecType=codecType;   coeff[0] = b140[0];   coeff[1] = b140[1];   coeff[2] = b140[2];   coeff[3] = a140[0];   coeff[4] = -a140[1];   coeff[5] = -a140[2];   pBuf = (Ipp8s*)encoderObj + sizeof(G729FPEncoder_Obj);   ippsIIRInit_32f(&encoderObj->iirstate,coeff,2,NULL,pBuf);   ippsIIRGetStateSize_32f(2,&fltsize);   encoderObj->vadMem = (Ipp8s *)((Ipp8s*)pBuf + fltsize);   VADGetSize(&fltsize);   encoderObj->cngMem = (Ipp8s *)((Ipp8s*)encoderObj->vadMem + fltsize);   CNGGetSize(&fltsize);   encoderObj->msdMem = (Ipp8s *)((Ipp8s*)encoderObj->cngMem + fltsize);   MSDGetSize(&fltsize);   encoderObj->pHWState = (IppsWinHybridState_G729E_32f *)((Ipp8s*)encoderObj->msdMem + fltsize);   /* Static vectors to zero */   ippsZero_32f(encoderObj->OldSpeechBuffer, SPEECH_BUFF_LEN);   ippsZero_32f(encoderObj->OldExcitationBuffer, PITCH_LAG_MAX+INTERPOL_LEN);   ippsZero_32f(encoderObj->OldWeightedSpeechBuffer, PITCH_LAG_MAX);   ippsZero_32f(encoderObj->WeightedFilterMemory,  BWD_LPC_ORDER);   ippsZero_32f(encoderObj->FltMem,   BWD_LPC_ORDER);   encoderObj->fBetaPreFilter = PITCH_SHARPMIN;   ippsCopy_32f(InitLSP, encoderObj->OldLSP, LPC_ORDER);   ippsCopy_32f(InitLSP, encoderObj->OldQuantLSP, LPC_ORDER);   for(i=0; i<4; i++) encoderObj->ExcitationError[i] = 1.f;   encoderObj->PastQuantEnergy[0]=encoderObj->PastQuantEnergy[1]=encoderObj->PastQuantEnergy[2]=encoderObj->PastQuantEnergy[3]=-14.0;   for(i=0; i<MOVING_AVER_ORDER; i++)     ippsCopy_32f (&InitFrequences[0], &encoderObj->PrevFreq[i][0], LPC_ORDER );   ippsZero_32f(encoderObj->OldForwardLPC, LPC_ORDERP1);   encoderObj->OldForwardLPC[0]= 1.f;   ippsZero_32f(encoderObj->OldForwardRC, 2);   encoderObj->sFrameCounter = 0;   /* For G.729B */   /* Initialize VAD/DTX parameters */   //if(mode == G729Encode_VAD_Enabled) {      encoderObj->prevVADDec = 1;      encoderObj->prevPrevVADDec = 1;      encoderObj->sCNGSeed = INIT_SEED_VAL;      VADInit(encoderObj->vadMem);      CNGInit(encoderObj->cngMem);      MSDInit(encoderObj->msdMem);   //}   encoderObj->prevLPCMode = 0;   if(codecType==G729A_CODEC) {      ippsZero_32f(encoderObj->ZeroMemory, LPC_ORDER);   } else {      ippsZero_32f(encoderObj->SynFltMemory,  BWD_LPC_ORDER);      ippsZero_32f(encoderObj->ErrFltMemory, BWD_LPC_ORDER);      ippsZero_32f(&encoderObj->UnitImpulse[BWD_LPC_ORDERP1], SUBFR_LEN);      ippsZero_32f(encoderObj->PrevFlt, BWD_LPC_ORDERP1);      encoderObj->PrevFlt[0] = 1.f;      ippsWinHybridInit_G729E_32f(encoderObj->pHWState);      ippsZero_32f(encoderObj->SynthBuffer, BWD_ANALISIS_WND_LEN);      ippsZero_32f(encoderObj->BackwardLPCMemory, BWD_LPC_ORDERP1);      encoderObj->BackwardLPCMemory[0] = 1.f;      encoderObj->isBWDDominant = 0;      encoderObj->fInterpolationCoeff = 1.1f;       /* Filter interpolation parameter */      encoderObj->sGlobalStatInd = 10000;  /* Mesure of global stationnarity */      encoderObj->sBWDStatInd = 0;       /* Nbre of consecutive backward frames */      encoderObj->sValBWDStatInd = 0;   /* Value associated with stat_bwd */      ippsZero_32f(encoderObj->OldBackwardLPC, BWD_LPC_ORDERP1);      encoderObj->OldBackwardLPC[0]= 1.f;      ippsZero_32f(encoderObj->OldBackwardRC, 2);      ippsSet_32s(20,encoderObj->LagBuffer,5);      ippsSet_32f(0.7f,encoderObj->PitchGainBuffer,5);      encoderObj->sBWDFrmCounter = 0;      encoderObj->sFWDFrmCounter = 0;      encoderObj->isSmooth = 1;      encoderObj->LogAreaRatioCoeff[0] = encoderObj->LogAreaRatioCoeff[1] = 0.f;      encoderObj->sSearchTimes = 30;   }   apiG729FPEncoder_InitBuff(encoderObj,oldMemBuff);   return APIG729_StsNoErr;}G729_CODECFUN( APIG729_Status, apiG729FPEncode,         (G729FPEncoder_Obj* encoderObj,const Ipp16s* src, Ipp8u *dst,G729Codec_Type codecType, Ipp32s *frametype)){    /* LPC analysis */    LOCAL_ALIGN_ARRAY(32, Ipp32f, forwardAutoCorr, (LPC_ORDERP2+1),encoderObj);       /* Autocorrelations (forward) */    LOCAL_ALIGN_ARRAY(32, Ipp32f, backwardAutoCorr, BWD_LPC_ORDERP1,encoderObj);      /* Autocorrelations (backward) */    LOCAL_ALIGN_ARRAY(32, Ipp32f, backwardReflectCoeff, BWD_LPC_ORDER,encoderObj);       /* Reflection coefficients : backward analysis */    LOCAL_ALIGN_ARRAY(32, Ipp32f, forwardLPC, LPC_ORDERP1*2,encoderObj);      /* A(z) forward unquantized for the 2 subframes */

⌨️ 快捷键说明

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