📄 decg729.c
字号:
/*///////////////////////////////////////////////////////////////////////////////// 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-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/A/B/D/E speech codec: decoder API functions.//*/#include <ippsc.h>#include "owng729.h"/* HPF coefficients */static __ALIGN32 CONST Ipp16s tab1[3] = { 7699, -15398, 7699};static __ALIGN32 CONST Ipp16s tab2[3] = {BWF_HARMONIC_E, 15836, -7667};static __ALIGN32 CONST Ipp16s lspSID_init[LPF_DIM] = {31441, 27566, 21458, 13612, 4663, -4663, -13612, -21458, -27566, -31441};static __ALIGN32 CONST Ipp16s 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 Ipp16s 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 Ipp32s DecoderObjSize(void) { Ipp32s fltSize; Ipp32s 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, Ipp32s *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)) { Ipp32s i,fltSize; Ipp16s abDec[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(*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 = (Ipp8s*)decoderObj + sizeof(G729Decoder_Obj); decoderObj->postProc = IPP_ALIGNED_PTR(decoderObj->postProc, 16); ippsHighPassFilterSize_G729(&fltSize); decoderObj->synFltw = (Ipp8s*)decoderObj->postProc + fltSize; decoderObj->synFltw = IPP_ALIGNED_PTR(decoderObj->synFltw, 16); SynthesisFilterSize_G729(&fltSize); decoderObj->synFltw0 = (Ipp8s*)decoderObj->synFltw + fltSize; decoderObj->synFltw0 = IPP_ALIGNED_PTR(decoderObj->synFltw0, 16); decoderObj->PhDispMem = (Ipp8s*)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 ); ippsCopy_16s(resetPrevLSP, decoderObj->prevSubfrLSPquant, 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(Ipp32s)*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]; } apiG729Decoder_InitBuff(decoderObj,oldMemBuff); return APIG729_StsNoErr;}G729_CODECFUN( APIG729_Status, apiG729Decoder_InitBuff, (G729Decoder_Obj* decoderObj, Ipp8s *buff)) { 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+G729_ENCODER_SCRATCH_MEMORY_SIZE); return APIG729_StsNoErr;}G729_CODECFUN( APIG729_Status, apiG729Decoder_Mode, (G729Decoder_Obj* decoderObj, Ipp32s mode)){ if(NULL==decoderObj) return APIG729_StsBadArgErr; decoderObj->pstFltMode = mode; return APIG729_StsNoErr;}static APIG729_Status G729Decode(G729Decoder_Obj* decoderObj,const Ipp8u* src, Ipp32s frametype, Ipp16s* dst);static APIG729_Status G729ADecode(G729Decoder_Obj* decoderObj,const Ipp8u* src, Ipp32s frametype, Ipp16s* dst);static APIG729_Status G729BaseDecode(G729Decoder_Obj* decoderObj,const Ipp8u* src, Ipp32s frametype, Ipp16s* dst);G729_CODECFUN( APIG729_Status, apiG729Decode, (G729Decoder_Obj* decoderObj,const Ipp8u* src, Ipp32s frametype, Ipp16s* 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 Ipp8u* src, Ipp32s frametype, Ipp16s* dst) { LOCAL_ALIGN_ARRAY(32, Ipp16s, AzDec, BWLPCF1_DIM*2,decoderObj); LOCAL_ALIGN_ARRAY(32, Ipp16s, newLSP,LPF_DIM,decoderObj); LOCAL_ALIGN_ARRAY(32, Ipp16s, ACELPcodeVec, LP_SUBFRAME_DIM,decoderObj); LOCAL_ALIGN_ARRAY(32, Ipp16s, BWDfiltLPC, 2*BWLPCF1_DIM,decoderObj); LOCAL_ALIGN_ARRAY(32, Ipp16s, FWDfiltLPC, 2*LPF_DIM+2,decoderObj); LOCAL_ALIGN_ARRAY(32, Ipp16s, BWDrc,BWLPCF_DIM,decoderObj); LOCAL_ALIGN_ARRAY(32, Ipp32s, BWDacf,BWLPCF1_DIM,decoderObj); LOCAL_ALIGN_ARRAY(32, Ipp32s, BWDhighAcf,BWLPCF1_DIM,decoderObj); LOCAL_ALIGN_ARRAY(32, Ipp16s, phaseDispExcit,LP_SUBFRAME_DIM,decoderObj); LOCAL_ARRAY(Ipp16s, idx,4,decoderObj); LOCAL_ARRAY(Ipp16s, delayVal,2,decoderObj); LOCAL_ARRAY(Ipp16s, tmp_parm,5,decoderObj); Ipp16s prevFrameDelay1=0; /* 1-st subframe pitch lag*/ Ipp16s subfrVoiceFlag, *pAz, *pA; Ipp8s *synFltw = decoderObj->synFltw; Ipp16s *prevExcitat = decoderObj->prevExcitat; Ipp16s *excitation = prevExcitat + L_prevExcitat; Ipp16s *synth = decoderObj->LTPostFilt+SYNTH_BWD_DIM; Ipp16s *prevSubfrLSP = decoderObj->prevSubfrLSP; const Ipp8u *pParm; const Ipp16s *parm; Ipp16s *ppAz, temp, badFrameIndicator, badPitch, index, pulseSign, gPl, gC; Ipp16s voiceFlag = decoderObj->voiceFlag; Ipp16s sidGain = decoderObj->sidGain; Ipp16s gainNow = decoderObj->gainNow; Ipp16s *lspSID = decoderObj->lspSID; Ipp32s i, j, subfrIdx, index2, fType, gpVal=0, LPmode = 0; Ipp16s satFilter, statStat, mAq, prevM, dominantBWDmode = 0, 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)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -