📄 g723codec.h
字号:
#ifndef __G723CODEC_H__#define __G723CODEC_H__#include<stdlib.h>/* ipp library interface */#include<ippdefs.h>#include<ipp.h>#include<ippSC.h>#include "coder_arm.h"#include "decod_arm.h"#if defined(__ICL ) || defined ( __ECL )/* Intel C/C++ compiler bug for __declspec(align(8)) !!! */ #define __ALIGN(n) __declspec(align(16)) #define __ALIGN32 __declspec(align(32))#else #define __ALIGN(n) #define __ALIGN32#endif#if defined(__ICC) || defined( __ICL ) || defined ( __ECL ) #define __INLINE static __inline#elif defined( __GNUC__ ) #define __INLINE static __inline__#else #define __INLINE static#endif#define fsize 240#define sfsize 60#define autocorrlen 11#define lpclen 10#define pitchmin 18#define pitchmax (pitchmin+127)#define toepsize 416#define FixedCodeGainLev 24#define MaxPulseNum 6#define Gexc_Max 5000 // the largest excitation#define NbAvAcf 3 /* N frames for ACF averaging */#define NbAvGain 3 /* N frames for gain averaging */#define SizAcf ((NbAvAcf+1)*(lpclen+1)) /* size of ACF array */#define NbPulsBlk 11#define NbFilt 50#define InvNbPulsBlk 2979 /* 1/NbPulsBlk */#define InvQuanB_Crc0 12288 // b=12/32#define InvQuanB_Crc1 23552 // b=23/32#define InvQuanDelta_Crc0 256 // delta_f=31.25HZ,#define InvQuanDelta_Crc1 512 // delta_f=62.5HZ#define LspCbSize 256#define ComfortNoiseExcitation_G723_16s_Buff_Size (2*NbPulsBlk+2*NbPulsBlk+sfsize/2+4+2*sfsize)*sizeof(short)typedef struct _G723_VADmemory{ int Penr ; int Nlev ; short Hcnt ; short Vcnt ; short Aen ; short Polp[4] ;}G723_VADmemory;typedef struct { int MaxErr ; short GridId ; short MampId ; short UseTrn ; short Ploc[MaxPulseNum] ; short Pamp[MaxPulseNum] ; } BESTDEF ;struct _Line{ int lspID; short Crc; short olp[2]; short closelag[4]; short adptgid[4]; short ampindex[4]; int pos[4]; short sign[4]; short grid[4]; short traindrt[4]; };extern short Band0Tb8[LspCbSize*3];extern short Band1Tb8[LspCbSize*3]; extern short Band2Tb8[LspCbSize*4];extern short LspDcTable[lpclen] ;extern short PerFiltZeroTable[lpclen] ;extern short PerFiltPoleTable[lpclen] ;extern short PostFiltTable[2*lpclen] ;extern short Nb_puls[4];extern short FcbkGainTable[FixedCodeGainLev] ;extern int MaxPosTable[4] ;extern int CombinatorialTable[MaxPulseNum][sfsize/2] ;extern short epsi170[170] ;extern short gain170[170] ;extern short tabgain170[170];extern short tabgain85[85];extern short fact[4];extern int L_bseg[3];extern short base[3];extern IppSpchBitRate rate_vec[2];typedef struct _Line Line;void VoiceActivityDetectSize_G723(int* pVADsize);void VoiceActivityDetect_G723(const Ipp16s *pSrc, const Ipp16s *pNoiseLPC, const Ipp16s *pOlp, int SinDet, int *pVad, int *pAen, char* pVADmem);void LSFQuantInv_G723_32s16s(Ipp32s valQLsfIndex, Ipp16s * pSrcPrevLsf, Ipp16s * pDstLsf, Ipp16s Crc);void LspInterpolation_G723(short *lsp,short *prelsp,short *lpc);void UpdateSineDetector(short *SinDet);void Update_Acf(g723enc_obj *g723enc,short *Acf_sf, const short *ShAcf_sf);void PackLine(Line *line,short rate,char *out_bytes,int *out_len,short Ftyp);void AddToBitstream(int data,char **bs,char *bit_offset,int num);void UpdateErr(int *preErr,short olp,short closelag,short gain_id,short rate);void FixcdbkSearch_G723(short olp,short Aclag,short AcGainIndex,short *i_resp,short *src,short *fixedvec,short *grid,short *diract,short *gain_index,int *pos,short *sign,short *times,short rate,int i);void CodeWordImpConv_G723(short *src,short *dst,short *src_sign,short *src_pos,short *dst_sign,int *dst_pos);void GetGain_G723(short *residual,short *src,short *gain,short *index);void ExcitationResidual_G723_16s(Ipp16s *pSrc1,Ipp16s *pSrc2, Ipp16s *pSrcDst);void HarmonicFilter(short *src,short delay,short gain,short *dst,int len);void HarmonicFilter2_I(short *srcDst,short delay,short gain,int len);void WeightFilter_G723(short *src,short *lpc,short *dst,int len,short *DelayLine);void Mem_Shift(short *preData, short *curData ); void HighPassFilter_G723_I(short *psrcDst,int len,int *DelayLine);void QuantSIDGain_G723_16s(const Ipp16s *pSrc, const Ipp16s *pSrcSfs, int len, int *pIndx);void DecodeSIDGain_G723_16s (int pIndx, Ipp16s *pGain);void ComfortNoiseExcitation_G723_16s (Ipp16s gain, Ipp16s *pPrevExc, Ipp16s *pExc, Ipp16s *pSeed, Ipp16s *pOlp, Ipp16s *pLags, Ipp16s *pGains, int rat, char *buff);void C2omfortNoiseExcitation_G723_16s (Ipp16s gain, Ipp16s *pPrevExc, Ipp16s *pExc, Ipp16s *pSeed, Ipp16s *pOlp, Ipp16s *pLags, Ipp16s *pGains, int rat, char *buff);void Comp_Info( short *Buff, short Olp, short *Gain, short *ShGain, short *Vdelay);void ResidualInterpolation_G723_16s_I(Ipp16s *pSrcDst, Ipp16s *pDst, int lag, Ipp16s gain, Ipp16s *pSeed);void PitchPost_G723_Sfs(short *src,short *dst,short delay,short gain,short scaleGain,int sfs);void GainControl_G723_I(short *srcDst,int ener,short *gain);void FormantPostFilter_G723_I(short *srcDst,int *Ener,short *lpc,int *k_old,short *DelayLine);void FixedCodebookVector_G723_16s( int pos, int amp, int ampindex, int grid, int gain, int subfr, int rate, Ipp16s *pDst, int *pLag, Ipp16s *pGain );void Unpack(char *bitstream,Line *dst_line,short *rate,short *Ftyp);void ReadFromBitstream(char **bstr,int *bits,int *dst,int len);void Encoder_Alloc(int *size);void Init_Cod_Cng(g723enc_obj *g723enc);void VoiceActivityDetectInit_G723(char* pVADmem);void Cod_Cng(g723enc_obj *g723enc, short *DataExc, short *Ftyp,Line *line, short *lpc, char rate);void CalcRC(short *Coeff, short *RC, short *ShRC);int LpcDiff(short *RC, short ShRC, short *ptrAcf, short alpha);void ComputePastAvFilter(g723enc_obj *g723enc,short *SidLpc);void Decoder_Alloc(int *size);void Init_Dec_Cng(g723dec_obj *g723dec);void Dec_Cng(g723dec_obj *g723dec, short Ftyp, Line *line, short *Vout, short *lpc);__INLINE short Cnvrt_NR_32s16s(int x){ short s = IPP_MAX_16S; if(x<=(int)0x7fff8000) s = (x+(int)0x8000)>>16; //get the upper 16 bits using 5-carries-4-discasts method return s;}__INLINE short Cnvrt_32s16s(int x){ if (IPP_MAX_16S < x) return IPP_MAX_16S; //get the lower 16 bits from an int else if (IPP_MIN_16S > x) return IPP_MIN_16S; else return (short)(x);}__INLINE short Norm_16s(short *src){ short i; if(*src==0) return 0; for(i=0;abs(*src)<(short)0x4000;i++) (*src)<<=1; return i;}__INLINE short Norm_32s(int *src){ short i; if(*src==0) return 0; for(i=0;abs(*src)<(int)0x40000000;i++) (*src)<<=1; return i;}__INLINE void ArrNorm_16s_I(short *src,int len,int *offset){ int k; short tmp,max; ippsMax_16s(src,len,&max); tmp=Norm_16s(&max); tmp-=*offset; *offset=tmp; if(tmp<0) { tmp=-tmp; for(k=0;k<len;k++) src[k]>>=tmp; }else for(k=0;k<len;k++) src[k]<<=tmp; return;} __INLINE short Exp_16s(short x){ short i; if (x == 0) return 0; if ((short)0xffff == x) return 15; if (x < 0) x = ~x; for(i = 0; x < (short)0x4000; i++) x <<= 1; return i;}__INLINE int ShiftL_32s(int n, unsigned short x) //left shifting n by x bits{ int z = n; for(;x>0;x--) { if (z > IPP_MAX_32S/2) { z = IPP_MAX_32S; break; } else { if (z < IPP_MIN_32S/2) { z = IPP_MIN_32S; break; } } z *= 2; } return z;}__INLINE void ArrShiftL_32s(int *buf,int sfs,int *dst,int len){ int k; Ipp64s tmp; for(k=0;k<len;k++) { tmp=dst[k]<<sfs; if(tmp>IPP_MAX_32S) dst[k]=IPP_MAX_32S; else if(tmp<IPP_MIN_32S) dst[k]=IPP_MIN_32S; else dst[k]=(int)tmp; } } __INLINE void ArrShiftR_32s(int *buf,int sfs,short *dst,int len){ int k; int tmp; for(k=0;k<len;k++) { tmp=(buf[k]+(1<<(sfs-1)))>>sfs; if(tmp>IPP_MAX_16S) dst[k]=IPP_MAX_16S; else if(tmp<IPP_MIN_16S) dst[k]=IPP_MIN_16S; else dst[k]=(short)tmp; }} __INLINE short Exp_32s_Pos(int x){ short i; if (x == 0) return 0; for(i = 0; x < (int)0x40000000; i++) x <<= 1; return i;}__INLINE void ShiftL_16s(short *buf,int sfs,short *dst,int len){ int k,tmp; for(k=0;k<len;k++) { tmp=dst[k]<<sfs; if(tmp>IPP_MAX_16S) dst[k]=IPP_MAX_16S; else if(tmp<IPP_MIN_16S) dst[k]=IPP_MIN_16S; else dst[k]=(short)tmp; } } __INLINE void ShiftR_16s(short *buf,int sfs,short *dst,int len){ int k; for(k=0;k<len;k++) dst[k]=buf[k]>>sfs;} __INLINE short ownSqrt_32s( int n ) //compute the square root{ int i ; short x = 0 ; short y = 0x4000 ; int z ; for ( i = 0 ; i < 15 ; i ++ ) { z = (x + y) * (x + y ) ; if ( n >= z ) x += y ; y >>= 1 ; } return x;}__INLINE int Add32s(int a,int b){ Ipp64s tmp; tmp=a+b; if(tmp>IPP_MAX_32S) return IPP_MAX_32S; else if(tmp<IPP_MIN_32S) return IPP_MIN_32S; else return (int)tmp;}__INLINE int L_mac(int val,short x,short y){ int s; s=x*y; if(s>IPP_MAX_32S/2) s=IPP_MAX_32S; else if(s<IPP_MIN_32S/2) s=IPP_MIN_32S; else s=2*s; return Add32s(val,s);} __INLINE int MulC_32s(short val, int x) { // val*x/(2^15) Ipp64s z ; int xh, xl; xh = x >> 16; xl = x & 0xffff; z = 2*val*xh; z+=(xl*val)>>15; if(z>IPP_MAX_32S) z=IPP_MAX_32S; else if(z<IPP_MIN_32S) z=IPP_MIN_32S; else z=(int)z; return (int)z;}__INLINE short Random_16s(short *seed){ *seed=*seed*521+259; return *seed; } __INLINE short Random_number(short val,short *seed){ short x; x=Random_16s(seed)&0x7fff; x=(val*x)>>15; return x;}__INLINE void AutoCorrLagMax_16s(short *src,int srclen,short begin,short end,short *dst,short *num){ short *tmp; int k; tmp=(short *)malloc((end+1)*sizeof(short)); if(begin<=end) { ippsAutoCorr_16s_Sfs(src,srclen,tmp,end+1,16); ippsMax_16s(&tmp[begin],end-begin+1,dst); for(k=begin;k<=end;k++) { if(*dst==tmp[k]) { *num=k; break; } } }else printf("Wrong input arguments!\n"); return;} #endif //__G723_CODEC_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -