www.pudn.com > p_voice.rar > LD8CP.H
/*
ITU-T G.729 Annex C+ - Reference C code for floating point
implementation of G.729 Annex C+
(integration of Annexes B, D and E)
Version 2.1 of October 1999
*/
/*
File : LD8CP.H
*/
/*--------------------------------------------------------------*
* LD8CP.H *
* ~~~~~~ *
*--------------------------------------------------------------*/
/*---------------------------------------------------------------------------*
* constants for bitstream packing *
*---------------------------------------------------------------------------*/
#define PRM_SIZE_E_fwd 18 /* Size of vector of analysis parameters. */
#define PRM_SIZE_E_bwd 16 /* Size of vector of analysis parameters. */
#define PRM_SIZE_E 18 /* Size of vector of analysis parameters. */
#define PRM_SIZE_D 10 /* Size of vector of analysis parameters. */
#define PRM_SIZE_SID 4 /* Size of vector of analysis parameters. */
#define SERIAL_SIZE_E (116+4) /* Bits/frame + bfi+ number of speech bits
+ bit for mode + protection */
#define RATE_6400 64 /* Low rate (6400 bit/s) */
#define RATE_8000 80 /* Full rate (8000 bit/s) */
#define RATE_11800 118 /* High rate (11800 bit/s) */
#define RATE_SID 15 /* SID */
#define RATE_0 0 /* 0 bit/s rate */
#define G729D 0 /* Low rate (6400 bit/s) */
#define G729 1 /* Full rate (8000 bit/s) */
#define G729E 2 /* High rate (11800 bit/s) */
/*--------------------------------------------------------------*
* Function prototypes and constants use in G.729E *
* *
*--------------------------------------------------------------*/
/* backward LPC analysis parameters */
#define M_BWD 30 /* Order of Backward LP filter. */
#define M_BWDP1 (M_BWD+1) /* Order of Backward LP filter + 1 */
#define NRP 35
#define MEM_SYN_BWD (M_BWD + NRP)
#define N1 (M_BWD + L_FRAME)
#define L_ANA_BWD (L_FRAME + MEM_SYN_BWD)
#define L_ANA_BWD_M1 (L_ANA_BWD - 1)
#define W_FACT (FLOAT)0.31640625 /* 10368 */
#define GAMMA_BWD (FLOAT)0.98 /* 32113 */
/* short term pst parameters : */
#define GAMMA1_PST_E (FLOAT)0.7 /* denominator weighting factor */
#define GAMMA2_PST_E (FLOAT)0.65 /* numerator weighting factor */
#define LONG_H_ST_E 32 /* impulse response length */
#define GAMMA_HARM_E (FLOAT)0.25
#define GAMMA_HARM (FLOAT)0.5
/* ACELP codebooks parameters */
#define NB_TRACK 5
#define Q15_1_5 (FLOAT)0.2
/* Bw / Fw constants */
#define THRES_ENERGY (FLOAT)40.
#define TH1 (FLOAT)1.
#define TH2 (FLOAT)2.
#define TH3 (FLOAT)3.
#define TH4 (FLOAT)4.
#define TH5 (FLOAT)4.7
#define GAP_FACT (FLOAT)0.000114375
#define INV_LOG2 (FLOAT) (1./log10(2.))
/*--------------------------------------------------------------------------*
* 6.4kbps *
*--------------------------------------------------------------------------*/
#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif
#define BPS_8K 0 /* Indicates 8kbps mode */
#define BPS_6K 1 /* Indicates 6.4kbps mode */
#define SIZE_WORD_6K (short)64 /* number of speech bits */
#define PRM_SIZE_6K 10 /* Size of vector of analysis parameters. */
#define SERIAL_SIZE_6K (64+2) /* Bits/frame + bfi+ number of speech bits */
#define NB_PULSES_6K 2 /* number of pulses */
#define NC1_B_6K 4 /* number of second stage bits higher */
#define NC1_6K (1< 0 delay */
FLOAT gamma1, /* input: short term postfilt. den. weighting factor*/
FLOAT gamma2, /* input: short term postfilt. num. weighting factor*/
FLOAT gamma_harm, /* input: long term postfilter weighting factor*/
int long_h_st, /* input: impulse response length*/
int m_pst, /* input: LPC order */
int Vad /* input : VAD information (frame type) */
);
/*--------------------------------------------------------------------------*
* protypes of functions containing G729 source code + specific G729E code *
*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*
* gain VQ functions. *
*--------------------------------------------------------------------------*/
void dec_gaine(
int index, /* (i) :Index of quantization. */
FLOAT code[], /* (i) :Innovative vector. */
int L_subfr, /* (i) :Subframe length. */
int bfi, /* (i) :Bad frame indicator */
FLOAT *gain_pit, /* (o) :Pitch gain. */
FLOAT *gain_cod, /* (o) :Code gain. */
int rate, /* input : rate selector/frame =0 8kbps,= 1 11.8 kbps*/
FLOAT gain_pit_mem,
FLOAT gain_cod_mem,
FLOAT *c_muting,
int count_bfi,
int stationnary
);
/*--------------------------------------------------------------------------*
* functions specific to G729E *
*--------------------------------------------------------------------------*/
/* backward LPC analysis and switch forward/backward */
void autocorr_hyb_window(
FLOAT *x, /* Input speech signal */
FLOAT *r_bwd, /* (out) Autocorrelations */
FLOAT *rexp /* (in/out) */
);
void lag_window_bwd(FLOAT *r_bwd);
void int_bwd(FLOAT *a_bwd, FLOAT *prev_filter, FLOAT *C_int );
void set_lpc_mode(FLOAT *signal_ptr, FLOAT *a_fwd, FLOAT *a_bwd,
int *mode, FLOAT *lsp_new, FLOAT *lsp_old, int *bwd_dominant,
int prev_mode, FLOAT *prev_filter, FLOAT *C_int,
INT16 *glob_stat, INT16 *stat_bwd, INT16 *val_stat_bwd);
void update_bwd(int *mode, /* O Backward / forward Indication */
int *bwd_dominant,/* O Bwd dominant mode indication */
FLOAT *C_int, /*I/O filter interpolation parameter */
INT16 *glob_stat /* I/O Mre of global stationnarity */
);
FLOAT ener_dB(FLOAT *synth, int L);
void tst_bwd_dominant(int *high_stat, int mode);
void perc_vare (
FLOAT *gamma1, /* Bandwidth expansion parameter */
FLOAT *gamma2, /* Bandwidth expansion parameter */
int high_stat /* high_stat indication (see file bwfw.c) */
);
/*--------------------------------------------------------------------------*
* G729E fixed (ACELP) codebook excitation. *
*--------------------------------------------------------------------------*/
void ACELP_12i40_44bits(
FLOAT x[], /* (i) : target vector */
FLOAT cn[], /* (i) : residual after long term prediction */
FLOAT H[], /* (i) : impulse response of weighted synthesis filter */
FLOAT code[], /* (o) : algebraic (fixed) codebook excitation */
FLOAT y[], /* (o) : filtered fixed codebook excitation */
int indx[] /* (o) : index 5 words: 13,10,7,7,7 = 44 bits */
);
void ACELP_10i40_35bits(
FLOAT x[], /* (i) : target vector */
FLOAT cn[], /* (i) : residual after long term prediction */
FLOAT H[], /* (i) : impulse response of weighted synthesis filter */
FLOAT code[], /* (o) : algebraic (fixed) codebook excitation */
FLOAT y[], /* (o) : filtered fixed codebook excitation */
int indx[] /* (o) : index 5 words: 7,7,7,7,7 = 35 bits */
);
void dec_ACELP_12i40_44bits(
int *index, /* (i) : 5 words index (positions & sign) */
FLOAT cod[] /* (o) : algebraic (fixed) codebook excitation */
);
void dec_ACELP_10i40_35bits(
int *index, /* (i) : 5 words index (positions & sign) */
FLOAT cod[] /* (o) : algebraic (fixed) codebook excitation */
);
/* pitch tracking routine */
void track_pit(int *T0, int *T0_frac, int *prev_pitch,
int *stat_pitch, int *pitch_sta, int *frac_sta);
/*--------------------------------------------------------------------------*
* G729D fixed (ACELP) codebook excitation. *
*--------------------------------------------------------------------------*/
int ACELP_codebook64( /* (o) :Index of pulses positions */
FLOAT x[], /* (i) :Target vector */
FLOAT h[], /* (i) :Impulse response of filters */
int t0, /* (i) :Pitch lag */
FLOAT pitch_sharp, /* (i) :Last quantized pitch gain */
FLOAT code[], /* (o) :Innovative codebook */
FLOAT y[], /* (o) :Filtered innovative codebook */
int *sign /* (o) :Signs of 4 pulses */
);
void decod_ACELP64(
int sign, /* input : signs of 2 pulses */
int index, /* input : positions of 2 pulses */
FLOAT cod[] /* output: innovative codevector */
);
/*--------------------------------------------------------------------------*
* G729D gain *
*--------------------------------------------------------------------------*/
int qua_gain_6k( /* output: quantizer index */
FLOAT code[], /* input : fixed codebook vector */
FLOAT *g_coeff, /* input : correlation factors */
int l_subfr, /* input : fcb vector length */
FLOAT *gain_pit, /* output: quantized acb gain */
FLOAT *gain_code, /* output: quantized fcb gain */
int tameflag /* input : flag set to 1 if taming is needed */
);
void dec_gain_6k(
int index, /* input : quantizer index */
FLOAT code[], /* input : fixed code book vector */
int l_subfr, /* input : subframe size */
int bfi, /* input : bad frame indicator good = 0 */
FLOAT *gain_pit, /* output: quantized acb gain */
FLOAT *gain_code /* output: quantized fcb gain */
);
/*--------------------------------------------------------------------------*
* G729D gain phase dispersion *
*--------------------------------------------------------------------------*/
void Update_PhDisp(
FLOAT ltpGain, /* (i) : pitch gain */
FLOAT cbGain /* (i) : codebook gain */
);
void PhDisp(
FLOAT x[], /* input : excitation signal */
FLOAT x_phdisp[],/* output : excitation signal after phase dispersion */
FLOAT cbGain,
FLOAT ltpGainQ,
FLOAT inno[]
);
/*--------------------------------------------------------------------------*
* Prototypes for auxiliary functions *
*--------------------------------------------------------------------------*/
void fwrite16( FLOAT *data, int length, FILE *fp);
INT16 random_g729c(INT16 *seed);
void dvsub(FLOAT *in1, FLOAT *in2, FLOAT *out, INT16 npts);
FLOAT dvdot(FLOAT *in1, FLOAT *in2, INT16 npts);
void dvwadd(FLOAT *in1, FLOAT scalar1, FLOAT *in2, FLOAT scalar2,
FLOAT *out, INT16 npts);
void dvsmul(FLOAT *in, FLOAT scalar, FLOAT *out, INT16 npts);
void musdetect( int rate, FLOAT Energy, FLOAT *rc, int *lags, FLOAT *pgains,
int stat_flg, int frm_count, int prev_vad, int *Vad,
FLOAT Energy_db);