📄 g723_codec.h
字号:
/********************************************************************************
// 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) 2002 Intel Corporation. All Rights Reserved.
//
// Description:
// G.723.1 codec API
//
********************************************************************************/
#include "ippdefs.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Audio */
typedef struct
{
char *pId; /* stream identifier */
void *pStream; /* stream pointer */
Ipp16s *pBuf; /* buffer */
int len; /* audio buffer length, in bytes */
int numChan; /* number of channels */
int sampleRate; /* sample rate */
} IppPcmStream;
/* Bitstream */
typedef struct _IppBitstream
{
char *pId; /* stream identifier */
void *pStream; /* stream pointer */
Ipp8u *pBuf; /* stream buffer */
int len; /* stream buffer length, in bytes */
int numFrames; /* number of frames */
char *pCurByte; /* pointer to the current bitstream byte */
int curBitOffset; /* index of the current bit in *pCurByte */
} IppBitstream;
/********************
G.723.1/A constants
********************/
#define IPP_G723_FRAME_LEN 240 /* G.723.1/A frame length, in terms of PCM samples */
#define IPP_G723_SUBFRAME_LEN 60 /* G.723.1/A subframe length, in terms of PCM samples */
#define IPP_G723_LPC_ORDER 10 /* G.723.1/A LPC analysis order */
#define IPP_G723_LPCWIN_LEN 180 /* G.723.1/A LPC analysis Hamming window length */
#define IPP_G723_NUM_SUBFRAME 4 /* G.723.1/A number of subframes contained in one frame */
#define IPP_G723_MAXLAG 145 /* G.723.1/A longest possible pitch lag (55 Hz) */
#define IPP_G723_TAMING_PARAMS 5 /* G.723.1/A error taming parameter vector length */
#define IPP_G723_COVMATDIM 416 /* G.723.1/A size of Toepliz covariance matrix for ACELP CB search */
#define IPP_G723_GSU_INIT 0x1000 /* G.723.1/A decoder gain scaling unit history initialization constant */
#define IPP_G723_HPF_ENABLE 1 /* G.723.1/A encoder highpass filter enable (on) */
#define IPP_G723_HPF_DISABLE 0 /* G.723.1/A encoder highpass filter disable (off) */
#define IPP_G723_POSTFILT_ENABLE 1 /* G.723.1/A decoder postfilter enable (on) */
#define IPP_G723_POSTFILT_DISABLE 0 /* G.723.1/A decoder postfilter disable (off) */
#define IPP_G723_ERASURE_FRAME 1 /* G.723.1/A decoder erasure frame detected (invalid frame) */
#define IPP_G723_NON_ERASURE_FRAME 0 /* G.723.1/A decoder non-erasure frame (valid frame) */
#define IPP_G723_FRAMETYPE_NONTX 0 /* G.723.1/A non-transmitted silence frame (nonTX SID) */
#define IPP_G723_FRAMETYPE_VOICE 1 /* G.723.1/A active speech frame (5.3 or 6.3 kbps) */
#define IPP_G723_FRAMETYPE_SID 2 /* G.723.1/A SID (silence interval description) frame */
//***************************************
// IPP G723.1/A bitstream buffer lengths
//***************************************
#define IPP_G723_BITSTREAM_LEN_5300 20 /* G.723.1/A 5.3 kbps minimum packed frame buffer byte allocation */
#define IPP_G723_BITSTREAM_LEN_6300 24 /* G.723.1/A 5.3 kbps minimum packed frame buffer byte allocation */
#define IPP_G723_BITSTREAM_LEN_SID 4 /* G.723.1/A SID frame length, in bytes */
#define IPP_G723_BITSTREAM_LEN_NONTX 1 /* G.723.1/A non-transmitted frame length, in bytes */
/************************
G.723.1 encoder state
************************/
typedef struct
{
Ipp16s highpassFilterZfir; /* preprocesser HPF nonrecursive memory */
Ipp32s highpassFilterZiir; /* preprocesser HPF recursive memory */
Ipp16s prevSpch[2*IPP_G723_SUBFRAME_LEN]; /* half-frame (2 subframes) speech history buffer for LP analysis */
Ipp16s sineDtct; /* sinusoidal input detection parameter */
Ipp16s prevLsf[IPP_G723_LPC_ORDER]; /* previous frame LSP history buffer */
Ipp16s perceptualWeightFilterZfir[IPP_G723_LPC_ORDER]; /* perceptual weighting filter nonrecursive memory */
Ipp16s perceptualWeightFilterZiir[IPP_G723_LPC_ORDER]; /* perceptual weighting filter recursive memory */
Ipp16s prevWgtSpch[IPP_G723_MAXLAG]; /* perceptually weighted speech history buffer for OLPS */
Ipp16s combinedFilterZfir[IPP_G723_LPC_ORDER]; /* combined filter (LPC synthesis+HNS+PWF) nonrecursive memory */
Ipp16s combinedFilterZiir[IPP_G723_MAXLAG]; /* combined filter (LPC synthesis+HNS+PWF) recursive memory */
Ipp16s prevExcitation[IPP_G723_MAXLAG]; /* previous frame excitation sequence history */
Ipp32s errorTamingParams[IPP_G723_TAMING_PARAMS]; /* error "taming" parameters for adaptive codebook search constraint */
Ipp16s openLoopPitchLag[IPP_G723_NUM_SUBFRAME]; /* VAD OL pitch lag history for voicing classification */
Ipp16s vadLpc[IPP_G723_LPC_ORDER]; /* VAD LPC inverse filter coefficients */
Ipp16s randomSeedCNG; /* CNG excitation generator random seed */
Ipp16s prevDTXFrameType; /* DTX frame type history */
Ipp16s sidGain; /* quantized CNG excitation gain (G~sid, [3], p. 9) */
Ipp16s targetExcitationGain; /* CNG target excitation gain (G~t, [3], p. 10) */
Ipp16s frameAutoCorr[(IPP_G723_LPC_ORDER+1)*IPP_G723_NUM_SUBFRAME]; /* VAD frame (summation) autocorrelation histories */
Ipp16s frameAutoCorrExp[IPP_G723_NUM_SUBFRAME]; /* VAD frame (summation) autocorrelation exponent histories */
Ipp16s sidLsf[IPP_G723_LPC_ORDER]; /* CNG SID LSF vector (p~t associated with Asid(z)) */
IppG723AVadState vadState; /* VAD state */
IppG723ADtxState dtxState; /* DTX state */
} IppG723EncoderState;
/************************
G.723.1 decoder state
************************/
typedef struct
{
Ipp16s consecutiveFrameErasures; /* consective frame erasure count */
Ipp16s prevLsf[IPP_G723_LPC_ORDER]; /* previous frame LSP history buffer */
Ipp16s interpolationGain; /* interpolation frame excitation gain */
Ipp16s interpolationIndex; /* interpolation frame adaptive codebook index */
Ipp16s prevExcitation[IPP_G723_MAXLAG]; /* previous frame excitation sequence history */
Ipp16s randomSeed; /* random seed for interplation frame unvoiced excitation synthesis */
Ipp16s synthesisFilterZiir[IPP_G723_LPC_ORDER]; /* speech synthesis filter recursive memory */
Ipp16s formantPostfilterZfir[IPP_G723_LPC_ORDER]; /* formant postfilter nonrecursive memory */
Ipp16s formantPostfilterZiir[IPP_G723_LPC_ORDER]; /* formant postfilter recursive memory */
Ipp16s autoCorr; /* formant postfilter correlation coefficient (k) */
Ipp16s prevGain; /* gain scaling unit gain history (previous frame gain) */
Ipp16s randomSeedCNG; /* CNG excitation generator random seed */
Ipp16s prevDTXFrameType; /* DTX frame type history */
Ipp16s sidGain; /* quantized CNG excitation gain (G~sid, [3], p. 9) */
Ipp16s targetExcitationGain; /* CNG target excitation gain (G~t, [3], p. 10) */
Ipp16s sidLsf[IPP_G723_LPC_ORDER]; /* CNG SID LSF vector (p~t associated with Asid(z)) */
IppSpchBitRate bitRate; /* bitrate history */
Ipp16s tst[240];
} IppG723DecoderState;
/*********************
G.723.1 codec tables
*********************/
/* Formant postfilter exponential weighting series (numerator)
affects radial shift towards unit circle center for
postfilter zeros [1]. */
extern Ipp16s lambda1[];
/* Formant postfilter exponential weighting series (denominator)
affects radial shift towards unit circle center for
postfilter poles [1]. */
extern Ipp16s lambda2[];
/* Perceptual weighting filter exponential weighting series (numerator)
affects radial shift towards unit circle center for
PWF zeros [1]. */
extern Ipp16s gamma1[];
/* Perceptual weighting filter exponential weighting series (denominator)
affects radial shift towards unit circle center for
PWF poles [1]. */
extern Ipp16s gamma2[];
/* Pitch synchronous filer lag table for ACELP codebook search [2]. */
extern Ipp16s pitchSyncFiltLagTable[];
/* Pitch synchronous filer gain table for ACELP codebook search [2]. */
extern Ipp16s pitchSyncFiltGainTable[];
/* Error taming adaptive codebook gain bounding table, 6.3 kbps with short pitch lags */
extern Ipp16s errorTamingGainTable1[];
/* Error taming adaptive codebook gain bounding table,
5.3 kbps + 6.3 kbps with long pitch lags */
extern Ipp16s errorTamingGainTable2[];
/* LSF split VQ, codebook 1 (LSF0,1,2)
Codebook dimension is 256 x 3, i.e. 3 elements x 8-bits */
extern Ipp16s lsfSplitVQ_Cb012[];
/* LSF split VQ, codebook 2 (LSF3,4,5)
Codebook dimension is 256 x 3, i.e. 3 elements x 8-bits */
extern Ipp16s lsfSplitVQ_Cb345[];
/* LSF split VQ, codebook 3 (LSF6,7,8,9).
Codebook dimension is 256 x 4, i.e. 4 elements x 8-bits */
extern Ipp16s lsfSplitVQ_Cb6789[];
/* Fixed (ACELP, MPMLQ) codebook gain quantization table */
extern Ipp16s fixedCodebookGainQuant[];
/* MPMLQ codebook pulse position table */
extern Ipp32s pulsePosTableMPMLQ[6][30];
/* VAD decision noise power threshold */
extern Ipp16s vadNoisePwrThreshold[];
/* SID gain quantization table, used for comfort noise synthesis */
extern Ipp16s sidGainQuant[];
/* LSF DC init table */
extern Ipp16s lsfDcInitTable[];
/************************
G.723.1 codec functions
************************/
IppStatus EncoderInit_G723 (IppG723EncoderState *pDstEncoderState);
IppStatus Encode_G723_16s8u (IppPcmStream *pSrcSpeech,
IppBitstream *pDstBitstream,
IppSpchBitRate bitRate,
int enableVad,
int enableHighpassFilter,
IppG723EncoderState *pEncoderState);
void EncodeBlock_G723_16s8u (IppPcmStream *speech, IppBitstream *bitstream,
Ipp16s dtxEnable, IppSpchBitRate rate,
IppG723EncoderState *state);
IppStatus DecoderInit_G723 (IppG723DecoderState *pDstDecoderState);
IppStatus Decode_G723_8u16s (IppBitstream *pSrcBits,
IppPcmStream *pDstSpeech,
Ipp16s erasureFrame,
int enablePostFilter,
IppG723DecoderState *pDecoderState);
void DecodeBlock_G723_8u16s (IppBitstream *bitstream,
IppPcmStream *speech,
IppG723DecoderState *state);
/******************
Codec constants
******************/
#define FRAMES_PER_WAVEBUF 50
#define BLOCK_LEN (FRAMES_PER_WAVEBUF*IPP_G723_FRAME_LEN)
#define WAVEBUF_LEN (sizeof(Ipp16s)*BLOCK_LEN)
#ifdef __cplusplus
}
#endif
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -