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

📄 decg729.c

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 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) 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/A/B/D/E speech codec: decoder API functions.
//
*/

#include <stdio.h>
#include <stdlib.h>
#include <ippsc.h>
#include "owng729.h"

/* HPF coefficients */

static __ALIGN32 CONST short tab1[3] = {
 7699,
 -15398,
 7699};
static __ALIGN32 CONST short tab2[3] = {BWF_HARMONIC_E, 15836, -7667};
static __ALIGN32 CONST short lspSID_init[LPF_DIM] = {31441,  27566,  21458, 13612,
 4663, -4663, -13612,
 -21458, -27566, -31441};

static __ALIGN32 CONST short tab3[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 tab4[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 DecoderObjSize(void) {
    int fltSize;
    int objSize = sizeof(G729Decoder_Obj);
    ippsHighPassFilterSize_G729(&fltSize);
    objSize += fltSize; /* provide memory for postprocessing high pass filter with upscaling */
    SynthesisFilterSize_G729(&fltSize);
    objSize += 2 * fltSize;/* provide memory for two synthesis filters */
    ippsPhaseDispersionGetStateSize_G729D_16s(&fltSize);
    objSize += fltSize; /* provide memory for phase dispersion */
    objSize += 4*32;
    return objSize;
}

G729_CODECFUN( APIG729_Status, apiG729Decoder_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 =  DecoderObjSize();
    return APIG729_StsNoErr;
}

G729_CODECFUN( APIG729_Status, apiG729Decoder_Init,
               (G729Decoder_Obj* decoderObj, G729Codec_Type codecType)) {
    int i,fltSize;
    Ipp16s abDec[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(*decoderObj)>>1) ;

    decoderObj->objPrm.objSize = DecoderObjSize();
    decoderObj->objPrm.key = DEC_KEY;
    decoderObj->objPrm.codecType=codecType;

    decoderObj->codecType=codecType;
    decoderObj->synFltw=NULL;
    decoderObj->synFltw0=NULL;
    decoderObj->PhDispMem=NULL;

    decoderObj->postProc = (char*)decoderObj + sizeof(G729Decoder_Obj);
    decoderObj->postProc = IPP_ALIGNED_PTR(decoderObj->postProc, 16);
    ippsHighPassFilterSize_G729(&fltSize);
    decoderObj->synFltw = (char*)decoderObj->postProc + fltSize;
    decoderObj->synFltw = IPP_ALIGNED_PTR(decoderObj->synFltw, 16);
    SynthesisFilterSize_G729(&fltSize);
    decoderObj->synFltw0 = (char*)decoderObj->synFltw + fltSize;
    decoderObj->synFltw0 = IPP_ALIGNED_PTR(decoderObj->synFltw0, 16);
    decoderObj->PhDispMem = (char*)decoderObj->synFltw0 + fltSize;
    decoderObj->PhDispMem = IPP_ALIGNED_PTR(decoderObj->PhDispMem, 16);
    abDec[0] = tab2[0];
    abDec[1] = tab2[1];
    abDec[2] = tab2[2];
    abDec[3] = tab1[0];
    abDec[4] = tab1[1];
    abDec[5] = tab1[2];
    for(i=0;i<4;i++) decoderObj->prevFrameQuantEn[i]=-14336;
    ippsHighPassFilterInit_G729(abDec,decoderObj->postProc);
    SynthesisFilterInit_G729(decoderObj->synFltw);
    SynthesisFilterInit_G729(decoderObj->synFltw0);
    ippsPhaseDispersionInit_G729D_16s((IppsPhaseDispersion_State_G729D *)decoderObj->PhDispMem);

    /* synthesis speech buffer*/
    ippsZero_16s(decoderObj->LTPostFilt,TBWD_DIM);
    decoderObj->voiceFlag=60;
    ippsZero_16s(decoderObj->prevExcitat, L_prevExcitat);
    decoderObj->betaPreFilter = PITCH_SHARP_MIN;
    decoderObj->prevFrameDelay = 60;
    decoderObj->gains[0] = 0;
    decoderObj->gains[1] = 0;
    for(i=0; i<LSP_MA_ORDER; i++)
        ippsCopy_16s( &resetPrevLSP[0], &decoderObj->prevLSPfreq[i][0], LPF_DIM );
    ippsCopy_16s(presetLSP, decoderObj->prevSubfrLSP, LPF_DIM );
    decoderObj->preemphFilt = 0;
    ippsZero_16s(decoderObj->resFilBuf1, MAX_PITCH_LAG+LP_SUBFRAME_DIM);
    ippsZero_16s(decoderObj->zeroPostFiltVec1 + LPF_DIM+1, BWLPCF1_DIM/*IMP_RESP_LEN*/);
    decoderObj->seedSavage = 21845;
    decoderObj->seed = SEED_INIT;
    decoderObj->CNGvar = 3;

    decoderObj->pstFltMode = 1;

    if(decoderObj->codecType == G729_CODEC ) {
        decoderObj->gainExact = BWF_HARMONIC;
    } else if( decoderObj->codecType == G729A_CODEC) {
        decoderObj->gainExact = (1<<12);
        decoderObj->CNGidx = 0;
        decoderObj->SIDflag0 = 0;
        decoderObj->SIDflag1 = 1;
        ippsCopy_16s( lspSID_init, decoderObj->lspSID, LPF_DIM );
    } else {
        decoderObj->prevMA = 0;
        decoderObj->gammaPost1 = BWF1_PST_E;
        decoderObj->gammaPost2 = BWF2_PST_E;
        decoderObj->gammaHarm = BWF_HARMONIC_E;
        decoderObj->BWDcounter2 = 0;
        decoderObj->FWDcounter2 = 0;

        ippsZero_16s(decoderObj->pBwdLPC, BWLPCF1_DIM);
        ippsZero_16s(decoderObj->pBwdLPC2, BWLPCF1_DIM);
        decoderObj->pBwdLPC[0] = (1<<12);
        decoderObj->pBwdLPC2[0] = (1<<12);

        decoderObj->prevVoiceFlag = 0;
        decoderObj->prevBFI = 0;
        decoderObj->prevLPmode = 0;
        decoderObj->interpCoeff2 = 0;
        decoderObj->interpCoeff2_2 = 4506;
        ippsZero_16s(decoderObj->pPrevFilt, BWLPCF1_DIM);
        decoderObj->pPrevFilt[0] = (1<<12);
        decoderObj->prevPitch = 30;
        decoderObj->stat_pitch = 0;
        ippsZero_16s(decoderObj->pPrevBwdLPC, BWLPCF1_DIM);
        decoderObj->pPrevBwdLPC[0]= (1<<12);
        ippsZero_16s(decoderObj->pPrevBwdRC, 2);
        decoderObj->valGainAttenuation = IPP_MAX_16S;
        decoderObj->BFIcount = 0;
        decoderObj->BWDFrameCounter = 0;

        decoderObj->gainExact = BWF_HARMONIC;
        ippsWinHybridGetStateSize_G729E_16s(&fltSize);
        if(fltSize > sizeof(int)*BWLPCF1_DIM) {
            return APIG729_StsNotInitialized;
        }
        ippsWinHybridInit_G729E_16s((IppsWinHybridState_G729E_16s*)&decoderObj->hwState);

        decoderObj->SIDflag0 = 0;
        decoderObj->SIDflag1 = 1;
        decoderObj->CNGidx = 0;
        ippsCopy_16s( lspSID_init, decoderObj->lspSID, LPF_DIM );
        decoderObj->sidGain = SIDgain[0];
    }
    return APIG729_StsNoErr;
}

G729_CODECFUN( APIG729_Status, apiG729Decoder_InitBuff,
               (G729Decoder_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+G729_ENCODER_SCRATCH_MEMORY_SIZE);
#endif /*SCRATCH_IDAIS*/
    return APIG729_StsNoErr;
}

G729_CODECFUN( APIG729_Status, apiG729Decoder_Mode,
               (G729Decoder_Obj* decoderObj, int mode))
{
   if(NULL==decoderObj)
        return APIG729_StsBadArgErr;
   decoderObj->pstFltMode = mode;
   return APIG729_StsNoErr;
}
static APIG729_Status G729Decode
(G729Decoder_Obj* decoderObj,const unsigned char* src, int frametype, short* dst);
static APIG729_Status G729ADecode
(G729Decoder_Obj* decoderObj,const unsigned char* src, int frametype, short* dst);
static APIG729_Status G729BaseDecode
(G729Decoder_Obj* decoderObj,const unsigned char* src, int frametype, short* dst);

G729_CODECFUN( APIG729_Status, apiG729Decode,
               (G729Decoder_Obj* decoderObj,const unsigned char* src, int frametype, short* dst)) {
    if(decoderObj->codecType == G729A_CODEC) {
        if(G729ADecode(decoderObj,src,frametype,dst) != APIG729_StsNoErr) {
            return APIG729_StsErr;
        }
    } else if(decoderObj->codecType == G729_CODEC && frametype != 2 && frametype != 4) {
        if(G729BaseDecode(decoderObj,src,frametype,dst) != APIG729_StsNoErr) {
            return APIG729_StsErr;
        }
    } else {
        if(G729Decode(decoderObj,src,frametype,dst) != APIG729_StsNoErr) {
            return APIG729_StsErr;
        }
    }
    return APIG729_StsNoErr;
}

APIG729_Status G729Decode
(G729Decoder_Obj* decoderObj,const unsigned char* src, int frametype, short* dst) {

    LOCAL_ALIGN_ARRAY(32, short, AzDec, BWLPCF1_DIM*2,decoderObj);
    LOCAL_ALIGN_ARRAY(32, short, newLSP,LPF_DIM,decoderObj);
    LOCAL_ALIGN_ARRAY(32, short, ACELPcodeVec, LP_SUBFRAME_DIM,decoderObj);
    LOCAL_ALIGN_ARRAY(32, short, BWDfiltLPC, 2*BWLPCF1_DIM,decoderObj);
    LOCAL_ALIGN_ARRAY(32, short, FWDfiltLPC, 2*LPF_DIM+2,decoderObj);
    LOCAL_ALIGN_ARRAY(32, short, BWDrc,BWLPCF_DIM,decoderObj);
    LOCAL_ALIGN_ARRAY(32, int,   BWDacf,BWLPCF1_DIM,decoderObj);
    LOCAL_ALIGN_ARRAY(32, int,   BWDhighAcf,BWLPCF1_DIM,decoderObj);
    LOCAL_ALIGN_ARRAY(32, short, phaseDispExcit,LP_SUBFRAME_DIM,decoderObj);
    LOCAL_ARRAY(short, prevFrameDelay,2,decoderObj);
    LOCAL_ARRAY(short, idx,4,decoderObj);
    LOCAL_ARRAY(short, delayVal,2,decoderObj);
    LOCAL_ARRAY(short, tmp_parm,5,decoderObj);
    short  prevFrameDelay1=0;  /* 1-st subframe pitch lag*/
    short  subfrVoiceFlag, *pAz, *pA;
    char  *synFltw = decoderObj->synFltw;
    short *prevExcitat = decoderObj->prevExcitat;
    short *excitation = prevExcitat + L_prevExcitat;
    short *synth = decoderObj->LTPostFilt+SYNTH_BWD_DIM;
    short *prevSubfrLSP = decoderObj->prevSubfrLSP;
    const  unsigned char *pParm;
    const  short *parm;
    short  *ppAz, temp, badFrameIndicator, badPitch, index, pulseSign, gPl, gC;
    short  voiceFlag = decoderObj->voiceFlag;
    short  sidGain = decoderObj->sidGain;
    short  gainNow = decoderObj->gainNow;
    short *lspSID = decoderObj->lspSID;
    int    i, j, subfrIdx, index2, fType, gpVal=0, LPmode = 0;
    short  satFilter, statStat, mAq, prevM, dominantBWDmode, L_hSt;
    IppStatus status;

    if(NULL==decoderObj || NULL==src || NULL ==dst)
        return APIG729_StsBadArgErr;
    if((decoderObj->codecType != G729_CODEC)
       &&(decoderObj->codecType != G729D_CODEC)&&(decoderObj->codecType != G729E_CODEC)&&(decoderObj->codecType != G729I_CODEC)) {
        return APIG729_StsBadCodecType;
    }
    if(decoderObj->objPrm.objSize <= 0)
        return APIG729_StsNotInitialized;

⌨️ 快捷键说明

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