📄 ld8a.h
字号:
/*
ITU-T G.729 Annex C - Reference C code for floating point
implementation of G.729 Annex A
Version 1.01 of 15.September.98
*/
/*
----------------------------------------------------------------------
COPYRIGHT NOTICE
----------------------------------------------------------------------
ITU-T G.729 Annex C ANSI C source code
Copyright (C) 1998, AT&T, France Telecom, NTT, University of
Sherbrooke. All rights reserved.
----------------------------------------------------------------------
*/
/*-----------------------------------------------------------*
* ld8a.h - include file for G.729a 8.0 kb/s codec *
*-----------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#ifdef PI
#undef PI
#endif
#ifdef PI2
#undef PI2
#endif
#define PI (F)3.141592654
#define PI2 (F)6.283185307
#define FLT_MAX_G729 (F)1.0e38 /* largest floating point number */
#define FLT_MIN_G729 (F)-1.0e38 /* largest floating point number */
/*--------------------------------------------------------------------------*
* Codec constant parameters (coder, decoder, and postfilter) *
*--------------------------------------------------------------------------*/
#define L_TOTAL 240 /* Total size of speech buffer */
#define L_WINDOW 240 /* LPC analysis window size */
#define L_NEXT 40 /* Samples of next frame needed for LPC ana.*/
#define L_FRAME 80 /* LPC update frame size */
#define L_SUBFR 40 /* Sub-frame size */
#define PIT_MIN 20 /* Minimum pitch lag in samples */
#define PIT_MAX 143 /* Maximum pitch lag in samples */
#define L_INTERPOL (10+1) /* Length of filter for interpolation. */
#define GAMMA1 (F)0.75 /* Bandwitdh expansion for W(z) */
/*--------------------------------------------------------------------------*
* constants for lpc analysis and lsp quantizer *
*--------------------------------------------------------------------------*/
#define M 10 /* LPC order */
#define MP1 (M+1) /* LPC order+1 */
#define NC (M/2) /* LPC order / 2 */
#define WNC (F)1.0001 /* white noise correction factor */
#define GRID_POINTS 50 /* resolution of lsp search */
#define MA_NP 4 /* MA prediction order for LSP */
#define MODE 2 /* number of modes for MA prediction */
#define NC0_B 7 /* number of bits in first stage */
#define NC0 (1<<NC0_B) /* number of entries in first stage */
#define NC1_B 5 /* number of bits in second stage */
#define NC1 (1<<NC1_B) /* number of entries in second stage */
#define L_LIMIT (F)0.005 /* */
#define M_LIMIT (F)3.135 /* */
#define GAP1 (F)0.0012 /* */
#define GAP2 (F)0.0006 /* */
#define GAP3 (F)0.0392 /* */
#define PI04 PI*(F)0.04 /* pi*0.04 */
#define PI92 PI*(F)0.92 /* pi*0.92 */
#define CONST12 (F)1.2
/*------------------------------------------------------------------*
* Constants for long-term predictor *
*------------------------------------------------------------------*/
#define SHARPMAX (F)0.7945 /* Maximum value of pitch sharpening */
#define SHARPMIN (F)0.2 /* Minimum value of pitch sharpening */
#define GAIN_PIT_MAX (F)1.2 /* Maximum adaptive codebook gain */
#define UP_SAMP 3 /* Resolution of fractional delays */
#define L_INTER10 10 /* Length for pitch interpolation */
#define FIR_SIZE_SYN (UP_SAMP*L_INTER10+1)
/*-----------------------*
* Innovative codebook. *
*-----------------------*/
#define DIM_RR 616 /* size of correlation matrix */
#define NB_POS 8 /* Number of positions for each pulse */
#define STEP 5 /* Step betweem position of the same pulse. */
#define MSIZE 64 /* Size of vectors for cross-correlation between 2 pulses*/
/*------------------------------------------------------------------*
* gain quantizer *
*------------------------------------------------------------------*/
#define MEAN_ENER (F)36.0 /* Average innovation energy */
#define NCODE1 8 /* Codebook 1 size */
#define NCODE2 16 /* Codebook 2 size */
#define NCAN1 4 /* Pre-selecting order for #1 */
#define NCAN2 8 /* Pre-selecting order for #2 */
#define INV_COEF (F)-0.032623
/*------------------------------------------------------------------*
* Constant for postfilter *
*------------------------------------------------------------------*/
#define GAMMA2_PST (F)0.55 /* Formant postfilt factor (numerator) */
#define GAMMA1_PST (F)0.70 /* Formant postfilt factor (denominator) */
#define GAMMAP (F)0.50 /* Harmonic postfilt factor */
#define INV_GAMMAP ((F)1.0/((F)1.0+GAMMAP))
#define GAMMAP_2 (GAMMAP/((F)1.0+GAMMAP))
#define MU (F)0.8 /* Factor for tilt compensation filter */
#define AGC_FAC (F)0.9 /* Factor for automatic gain control */
#define AGC_FAC1 ((F)1.-AGC_FAC)
#define L_H 22 /* size of truncated impulse response of A(z/g1)/A(z/g2) */
/*--------------------------------------------------------------------------*
* Constants for taming procedure. *
*--------------------------------------------------------------------------*/
#define GPCLIP (F)0.95 /* Maximum pitch gain if taming is needed */
#define GPCLIP2 (F)0.94 /* Maximum pitch gain if taming is needed */
#define GP0999 (F)0.9999 /* Maximum pitch gain if taming is needed */
#define THRESH_ERR (F)60000. /* Error threshold taming */
#define INV_L_SUBFR (FLOAT) ((F)1./(FLOAT)L_SUBFR) /* =0.025 */
/*-----------------------*
* Bitstream constants *
*-----------------------*/
#define BIT_0 (short)0x007f /* definition of zero-bit in bit-stream */
#define BIT_1 (short)0x0081 /* definition of one-bit in bit-stream */
#define SYNC_WORD (short)0x6b21 /* definition of frame erasure flag */
#define PRM_SIZE 11 /* number of parameters per 10 ms frame */
#define SERIAL_SIZE 82 /* bits per frame */
#define SIZE_WORD (short)80 /* number of speech bits */
/*-------------------------------*
* Pre and post-process functions*
*-------------------------------*/
void init_post_process( void
);
void post_process(
FLOAT signal[], /* (i/o) : signal */
int lg /* (i) : lenght of signal */
);
void init_pre_process( void
);
void pre_process(
FLOAT signal[], /* (i/o) : signal */
int lg /* (i) : lenght of signal */
);
/*----------------------------------*
* Main coder and decoder functions *
*----------------------------------*/
void init_coder_ld8a(void);
void coder_ld8a(
int ana[] /* output: analysis parameters */
);
void init_decod_ld8a(void);
void decod_ld8a(
int parm[], /* (i) : vector of synthesis parameters
parm[0] = bad frame indicator (bfi) */
FLOAT synth[], /* (o) : synthesis speech */
FLOAT A_t[], /* (o) : decoded LP filter in 2 subframes */
int *T2, /* (o) : decoded pitch lag in 2 subframes */
int bfi /* (i) :bad frame indicator (bfi) */
);
/*-------------------------------*
* LPC analysis and filtering. *
*-------------------------------*/
void autocorr(FLOAT *x, int m, FLOAT *r);
void lag_window(int m, FLOAT r[]);
FLOAT levinson(FLOAT *a, FLOAT *r, FLOAT *r_c);
void az_lsp(FLOAT *a, FLOAT *lsp, FLOAT *old_lsp);
void int_qlpc(FLOAT lsp_new[], FLOAT lsp_old[], FLOAT a[]);
void weight_az(FLOAT *a, FLOAT gamma, int m, FLOAT *ap);
void residu( /* filter A(z) */
FLOAT *a, /* input : prediction coefficients a[0:m+1], a[0]=1. */
FLOAT *x, /* input : input signal x[0:l-1], x[-1:m] are needed */
FLOAT *y, /* output: output signal y[0:l-1] NOTE: x[] and y[]
cannot point to same array */
int l /* input : dimension of x and y */
);
void syn_filt(
FLOAT a[], /* input : predictor coefficients a[0:m] */
FLOAT x[], /* input : excitation signal */
FLOAT y[], /* output: filtered output signal */
int l, /* input : vector dimension */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -