📄 ld8k.h
字号:
/*
ITU-T G.729 Speech Coder with Annex B ANSI-C Source Code
Version 1.3 Last modified: August 1997
Copyright (c) 1996,
AT&T, France Telecom, NTT, Universite de Sherbrooke, Lucent Technologies,
Rockwell International
All rights reserved.
*/
/*--------------------------------------------------------------*
* LD8K.H *
* ~~~~~~ *
* Function prototypes and constants use in G.729 *
* *
*--------------------------------------------------------------*/
/*--------------------------------------------------------------------------*
* Codec constant parameters (coder, decoder, and postfilter) *
*--------------------------------------------------------------------------*/
#define L_TOTAL 240 /* Total size of speech buffer. */
#define L_WINDOW 240 /* Window size in LP analysis. */
#define L_NEXT 40 /* Lookahead in LP analysis. */
#define L_FRAME 80 /* Frame size. */
#define L_SUBFR 40 /* Subframe size. */
#define M 10 /* Order of LP filter. */
#define MP1 (M+1) /* Order of LP filter + 1 */
#define MM1 (M-1) /* Order of LP filter - 1 */
#define PIT_MIN 20 /* Minimum pitch lag. */
#define PIT_MAX 143 /* Maximum pitch lag. */
#define L_INTERPOL (10+1) /* Length of filter for interpolation. */
#define PRM_SIZE 11 /* Size of vector of analysis parameters. */
#define SERIAL_SIZE (80+2) /* Bits/frame + bfi+ number of speech bits */
#define SHARPMAX 13017 /* Maximum value of pitch sharpening 0.8 Q14 */
#define SHARPMIN 3277 /* Minimum value of pitch sharpening 0.2 Q14 */
#define L_SUBFRP1 (L_SUBFR + 1)
#define GPCLIP 15564 /* Maximum pitch gain if taming is needed Q14*/
#define GPCLIP2 481 /* Maximum pitch gain if taming is needed Q9 */
#define GP0999 16383 /* Maximum pitch gain if taming is needed */
#define L_THRESH_ERR 983040000L /* Error threshold taming 16384. * 60000. */
/*--------------------------------------------------------------------------*
* Mathematic functions. *
*--------------------------------------------------------------------------*/
Word32 Inv_sqrt( /* (o) Q30 : output value (range: 0<=val<1) */
Word32 L_x /* (i) Q0 : input value (range: 0<=val<=7fffffff) */
);
void Log2(
Word32 L_x, /* (i) Q0 : input value */
Word16 *exponent, /* (o) Q0 : integer part of Log2. (range: 0<=val<=30)*/
Word16 *fraction /* (o) Q15 : fractional part of Log2. (range: 0<=val<1) */
);
Word32 Pow2( /* (o) Q0 : result (range: 0<=val<=0x7fffffff) */
Word16 exponent, /* (i) Q0 : integer part. (range: 0<=val<=30) */
Word16 fraction /* (i) Q15 : fractional part. (range: 0.0<=val<1.0) */
);
/*--------------------------------------------------------------------------*
* Pre and post-process. *
*--------------------------------------------------------------------------*/
void Init_Pre_Process(void);
void Init_Post_Process(void);
void Pre_Process(
Word16 signal[], /* (i/o) : input/output signal */
Word16 lg /* (i) : length of signal */
);
void Post_Process(
Word16 signal[], /* (i/o) : input/output signal */
Word16 lg /* (i) : length of signal */
);
/*--------------------------------------------------------------------------*
* Main coder and decoder functions *
*--------------------------------------------------------------------------*/
void Init_Coder_ld8k(void);
void Coder_ld8k(
Word16 ana[], /* (o) : analysis parameters */
Word16 synth[], /* (o) : local synthesis */
Word16 frame, /* (i) : frame counter */
Word16 vad_enable /* (i) : VAD enable flag */
);
void Init_Decod_ld8k(void);
void Decod_ld8k(
Word16 parm[], /* (i) : vector of synthesis parameters
parm[0] = bad frame indicator (bfi) */
Word16 voicing, /* (i) : voicing decision from previous frame */
Word16 synth[], /* (o) : synthesized speech */
Word16 A_t[], /* (o) : decoded LP filter for 2 subframes */
Word16 *T0_first,/* (o) : decoded pitch lag in first subframe */
Word16 *Vad /* (o) : frame type */
);
/*--------------------------------------------------------------------------*
* taming functions *
*--------------------------------------------------------------------------*/
void Init_exc_err(void);
Word16 test_err(Word16 t0, Word16 t0_frac);
void update_exc_err(Word16 gain_pit, Word16 t0);
/*--------------------------------------------------------------------------*
* LPC analysis and filtering *
*--------------------------------------------------------------------------*/
void Autocorr(
Word16 x[], /* (i) : input signal */
Word16 m, /* (i) : LPC order */
Word16 r_h[], /* (o) : autocorrelations (msb) */
Word16 r_l[], /* (o) : autocorrelations (lsb) */
Word16 *exp_R0
);
void Lag_window(
Word16 m, /* (i) : LPC order */
Word16 r_h[], /* (i/o) : autocorrelations (msb) */
Word16 r_l[] /* (i/o) : autocorrelations (lsb) */
);
void Levinson(
Word16 Rh[], /* (i) : Rh[m+1] autocorrelation coefficients (msb) */
Word16 Rl[], /* (i) : Rl[m+1] autocorrelation coefficients (lsb) */
Word16 A[], /* (o) Q12 : A[m] LPC coefficients (m = 10) */
Word16 rc[], /* (o) Q15 : rc[M] Reflection coefficients. */
Word16 *Err /* (o) : Residual energy */
);
void Az_lsp(
Word16 a[], /* (i) Q12 : predictor coefficients */
Word16 lsp[], /* (o) Q15 : line spectral pairs */
Word16 old_lsp[] /* (i) : old lsp[] (in case not found 10 roots) */
);
void Lsp_Az(
Word16 lsp[], /* (i) Q15 : line spectral frequencies */
Word16 a[] /* (o) Q12 : predictor coefficients (order = 10) */
);
void Lsf_lsp(
Word16 lsf[], /* (i) Q15 : lsf[m] normalized (range: 0.0<=val<=0.5) */
Word16 lsp[], /* (o) Q15 : lsp[m] (range: -1<=val<1) */
Word16 m /* (i) : LPC order */
);
void Lsp_lsf(
Word16 lsp[], /* (i) Q15 : lsp[m] (range: -1<=val<1) */
Word16 lsf[], /* (o) Q15 : lsf[m] normalized (range: 0.0<=val<=0.5) */
Word16 m /* (i) : LPC order */
);
void Int_lpc(
Word16 lsp_old[], /* (i) : LSP vector of past frame */
Word16 lsp_new[], /* (i) : LSP vector of present frame */
Word16 lsf_int[], /* (o) : interpolated lsf coefficients */
Word16 lsf_new[], /* (o) : new lsf coefficients */
Word16 Az[] /* (o) : interpolated Az() for the 2 subframes */
);
void Int_qlpc(
Word16 lsp_old[], /* (i) : LSP vector of past frame */
Word16 lsp_new[], /* (i) : LSP vector of present frame */
Word16 Az[] /* (o) : interpolated Az() for the 2 subframes */
);
/*--------------------------------------------------------------------------*
* PWF constant parameters *
*--------------------------------------------------------------------------*/
#define A1 4567 /* 2.23 in Q11 */
#define L_B1 3271557L /* 0.78 in Q22 */
#define A2 11776 /* 5.75 in Q11 */
#define L_B2 16357786L /* 3.90 in Q22 */
#define A3 27443 /* 13.40 in Q11 */
#define L_B3 46808433L /* 11.16 in Q22 */
#define SEG1 1299 /* 0.6341 in Q11 */
#define SEG2 1815 /* 0.8864 in Q11 */
#define SEG3 1944 /* 0.9490 in Q11 */
#define THRESH_L1 -3562 /* -1.74 in Q11 */
#define THRESH_L2 -3116 /* -1.52 in Q11 */
#define THRESH_H1 1336 /* 0.65 in Q11 */
#define THRESH_H2 890 /* 0.43 in Q11 */
#define GAMMA1_0 32113 /* 0.98 in Q15 */
#define GAMMA1_1 30802 /* 0.94 in Q15 */
#define GAMMA2_0_L 13107 /* 0.40 in Q15 */
#define GAMMA2_0_H 22938 /* 0.70 in Q15 */
#define GAMMA2_1 19661 /* 0.60 in Q15 */
#define ALPHA 19302 /* 6*pi in Q10 */
#define BETA 1024 /* 1 in Q10 */
void perc_var (
Word16 *gamma1, /* bandwidth expansion parameter */
Word16 *gamma2, /* bandwidth expansion parameter */
Word16 *lsfint, /* Interpolated LSP vector : 1st subframe */
Word16 *lsfnew, /* New LSP vector : 2nd subframe */
Word16 *r_c /* Reflection coefficients */
);
void Weight_Az(
Word16 a[], /* (i) Q12 : a[m+1] LPC coefficients */
Word16 gamma, /* (i) Q15 : Spectral expansion factor. */
Word16 m, /* (i) : LPC order. */
Word16 ap[] /* (o) Q12 : Spectral expanded LPC coefficients */
);
void Residu(
Word16 a[], /* (i) Q12 : prediction coefficients */
Word16 x[], /* (i) : speech (values x[-m..-1] are needed (m=10) */
Word16 y[], /* (o) : residual signal */
Word16 lg /* (i) : frame size */
);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -