LD8K.H
Upload User: meifeng08
Upload Date: 2013-06-18
Package Size: 5304k
Code Size: 31k
Category:

Voice Compress

Development Platform:

C/C++

  1. /* Version 3.3    Last modified: December 26, 1995 */
  2. /*--------------------------------------------------------------*
  3.  * LD8K.H                                                       *
  4.  * ~~~~~~                                                       *
  5.  * Function prototypes and constants use in G.729               *
  6.  *                                                              *
  7.  *--------------------------------------------------------------*/
  8. /*--------------------------------------------------------------------------*
  9.  *       Codec constant parameters (coder, decoder, and postfilter)         *
  10.  *--------------------------------------------------------------------------*/
  11. #define L_TOTAL     240        /* Total size of speech buffer.              */
  12. #define L_WINDOW    240        /* Window size in LP analysis.               */
  13. #define L_NEXT      40         /* Lookahead in LP analysis.                 */
  14. #define L_FRAME     80         /* Frame size.                               */
  15. #define L_SUBFR     40         /* Subframe size.                            */
  16. #define M           10         /* Order of LP filter.                       */
  17. #define MP1         (M+1)      /* Order of LP filter + 1                    */
  18. #define MM1         (M-1)      /* Order of LP filter - 1                    */
  19. #define PIT_MIN     20         /* Minimum pitch lag.                        */
  20. #define PIT_MAX     143        /* Maximum pitch lag.                        */
  21. #define L_INTERPOL  (10+1)     /* Length of filter for interpolation.       */
  22. #define PRM_SIZE    11         /* Size of vector of analysis parameters.    */
  23. #define SERIAL_SIZE (80+2)     /* Bits/frame + bfi+ number of speech bits   */
  24. #define SHARPMAX    13017      /* Maximum value of pitch sharpening 0.8 Q14 */
  25. #define SHARPMIN    3277       /* Minimum value of pitch sharpening 0.2 Q14 */
  26. #define L_SUBFRP1 (L_SUBFR + 1)
  27. #define GPCLIP      15564      /* Maximum pitch gain if taming is needed Q14*/
  28. #define GPCLIP2     481        /* Maximum pitch gain if taming is needed Q9 */
  29. #define GP0999      16383      /* Maximum pitch gain if taming is needed    */
  30. #define L_THRESH_ERR 983040000L /* Error threshold taming 16384. * 60000.   */
  31. /*--------------------------------------------------------------------------*
  32.  * Mathematic functions.                                                    *
  33.  *--------------------------------------------------------------------------*/
  34. Word32 Inv_sqrt(    /* (o) Q30 : output value   (range: 0<=val<1)           */
  35.   Word32 L_x        /* (i) Q0  : input value    (range: 0<=val<=7fffffff)   */
  36. );
  37. void Log2(
  38.   Word32 L_x,       /* (i) Q0  : input value                                */
  39.   Word16 *exponent, /* (o) Q0  : integer part of Log2.   (range: 0<=val<=30)*/
  40.   Word16 *fraction  /* (o) Q15 : fractional part of Log2. (range: 0<=val<1) */
  41. );
  42. Word32 Pow2(        /* (o) Q0  : result       (range: 0<=val<=0x7fffffff)   */
  43.   Word16 exponent,  /* (i) Q0  : integer part.      (range: 0<=val<=30)     */
  44.   Word16 fraction   /* (i) Q15 : fractional part.  (range: 0.0<=val<1.0)    */
  45. );
  46. /*--------------------------------------------------------------------------*
  47.  * Pre and post-process.                                                    *
  48.  *--------------------------------------------------------------------------*/
  49. void Init_Pre_Process(void);
  50. void Init_Post_Process(void);
  51. void Pre_Process(
  52.   Word16 signal[],  /* (i/o)   : input/output signal                        */
  53.   Word16 lg         /* (i)     : length of signal                           */
  54. );
  55. void Post_Process(
  56.   Word16 signal[],  /* (i/o)   : input/output signal                        */
  57.   Word16 lg         /* (i)     : length of signal                           */
  58. );
  59. /*--------------------------------------------------------------------------*
  60.  * Main coder and decoder functions                                         *
  61.  *--------------------------------------------------------------------------*/
  62. void Init_Coder_ld8k(void);
  63. void Coder_ld8k(
  64.   Word16 ana[],     /* (o)     : analysis parameters                        */
  65.   Word16 synth[]    /* (o)     : local synthesis                            */
  66. );
  67. void Init_Decod_ld8k(void);
  68. void Decod_ld8k(
  69.   Word16 parm[],   /* (i)     : vector of synthesis parameters
  70.                                   parm[0] = bad frame indicator (bfi)       */
  71.   Word16 voicing,  /* (i)     : voicing decision from previous frame       */
  72.   Word16 synth[],  /* (o)     : synthesized speech                         */
  73.   Word16 A_t[],    /* (o)     : decoded LP filter for 2 subframes          */
  74.   Word16 *T0_first /* (o)     : decoded pitch lag in first subframe        */
  75. );
  76. /*--------------------------------------------------------------------------*
  77.  * LPC analysis and filtering                                               *
  78.  *--------------------------------------------------------------------------*/
  79. void Autocorr(
  80.   Word16 x[],       /* (i)     : input signal                               */
  81.   Word16 m,         /* (i)     : LPC order                                  */
  82.   Word16 r_h[],     /* (o)     : autocorrelations  (msb)                    */
  83.   Word16 r_l[]      /* (o)     : autocorrelations  (lsb)                    */
  84. );
  85. void Lag_window(
  86.   Word16 m,         /* (i)     : LPC order                                  */
  87.   Word16 r_h[],     /* (i/o)   : autocorrelations  (msb)                    */
  88.   Word16 r_l[]      /* (i/o)   : autocorrelations  (lsb)                    */
  89. );
  90. void Levinson(
  91.   Word16 Rh[],      /* (i)     : Rh[m+1] autocorrelation coefficients (msb) */
  92.   Word16 Rl[],      /* (i)     : Rl[m+1] autocorrelation coefficients (lsb) */
  93.   Word16 A[],       /* (o) Q12 : A[m]    LPC coefficients  (m = 10)         */
  94.   Word16 rc[]       /* (o) Q15 : rc[M]   Reflection coefficients.           */
  95. );
  96. void Az_lsp(
  97.   Word16 a[],       /* (i) Q12 : predictor coefficients                     */
  98.   Word16 lsp[],     /* (o) Q15 : line spectral pairs                        */
  99.   Word16 old_lsp[]  /* (i)     : old lsp[] (in case not found 10 roots)     */
  100. );
  101. void Lsp_Az(
  102.   Word16 lsp[],     /* (i) Q15 : line spectral frequencies                  */
  103.   Word16 a[]        /* (o) Q12 : predictor coefficients (order = 10)        */
  104. );
  105. void Lsf_lsp(
  106.   Word16 lsf[],     /* (i) Q15 : lsf[m] normalized (range: 0.0<=val<=0.5)   */
  107.   Word16 lsp[],     /* (o) Q15 : lsp[m] (range: -1<=val<1)                  */
  108.   Word16 m          /* (i)     : LPC order                                  */
  109. );
  110. void Lsp_lsf(
  111.   Word16 lsp[],     /* (i) Q15 : lsp[m] (range: -1<=val<1)                  */
  112.   Word16 lsf[],     /* (o) Q15 : lsf[m] normalized (range: 0.0<=val<=0.5)   */
  113.   Word16 m          /* (i)     : LPC order                                  */
  114. );
  115. void Int_lpc(
  116.   Word16 lsp_old[],  /* (i)    : LSP vector of past frame                   */
  117.   Word16 lsp_new[],  /* (i)    : LSP vector of present frame                */
  118.   Word16 lsf_int[],  /* (o)    : interpolated lsf coefficients              */
  119.   Word16 lsf_new[],  /* (o)    : new lsf coefficients                       */
  120.   Word16 Az[]        /* (o)    : interpolated Az() for the 2 subframes      */
  121. );
  122. void Int_qlpc(
  123.   Word16 lsp_old[],  /* (i)    : LSP vector of past frame                   */
  124.   Word16 lsp_new[],  /* (i)    : LSP vector of present frame                */
  125.   Word16 Az[]        /* (o)    : interpolated Az() for the 2 subframes      */
  126. );
  127. /*--------------------------------------------------------------------------*
  128.  *       PWF constant parameters                                            *
  129.  *--------------------------------------------------------------------------*/
  130. #define A1          4567       /*  2.23   in Q11                            */
  131. #define L_B1        3271557L   /*  0.78   in Q22                            */
  132. #define A2          11776      /*  5.75   in Q11                            */
  133. #define L_B2        16357786L  /*  3.90   in Q22                            */
  134. #define A3          27443      /* 13.40   in Q11                            */
  135. #define L_B3        46808433L  /* 11.16   in Q22                            */
  136. #define SEG1        1299       /*  0.6341 in Q11                            */
  137. #define SEG2        1815       /*  0.8864 in Q11                            */
  138. #define SEG3        1944       /*  0.9490 in Q11                            */
  139. #define THRESH_L1   -3562      /* -1.74   in Q11                            */
  140. #define THRESH_L2   -3116      /* -1.52   in Q11                            */
  141. #define THRESH_H1   1336       /*  0.65   in Q11                            */
  142. #define THRESH_H2   890        /*  0.43   in Q11                            */
  143. #define GAMMA1_0    32113      /*  0.98   in Q15                            */
  144. #define GAMMA1_1    30802      /*  0.94   in Q15                            */
  145. #define GAMMA2_0_L  13107      /*  0.40   in Q15                            */
  146. #define GAMMA2_0_H  22938      /*  0.70   in Q15                            */
  147. #define GAMMA2_1    19661      /*  0.60   in Q15                            */
  148. #define ALPHA       19302      /*  6*pi   in Q10                            */
  149. #define BETA        1024       /*     1   in Q10                            */
  150. void perc_var (
  151.   Word16 *gamma1,   /* bandwidth expansion parameter                        */
  152.   Word16 *gamma2,   /* bandwidth expansion parameter                        */
  153.   Word16 *lsfint,   /* Interpolated LSP vector : 1st subframe               */
  154.   Word16 *lsfnew,   /* New LSP vector : 2nd subframe                        */
  155.   Word16 *r_c       /* Reflection coefficients                              */
  156. );
  157. void Weight_Az(
  158.   Word16 a[],       /* (i) Q12 : a[m+1]  LPC coefficients                   */
  159.   Word16 gamma,     /* (i) Q15 : Spectral expansion factor.                 */
  160.   Word16 m,         /* (i)     : LPC order.                                 */
  161.   Word16 ap[]       /* (o) Q12 : Spectral expanded LPC coefficients         */
  162. );
  163. void Residu(
  164.   Word16 a[],       /* (i) Q12 : prediction coefficients                    */
  165.   Word16 x[],       /* (i)     : speech (values x[-m..-1] are needed (m=10) */
  166.   Word16 y[],       /* (o)     : residual signal                            */
  167.   Word16 lg         /* (i)     : frame size                                 */
  168. );
  169. void Syn_filt(
  170.   Word16 a[],       /* (i) Q12 : a[m+1] prediction coefficients   (m=10)    */
  171.   Word16 x[],       /* (i)     : input signal                               */
  172.   Word16 y[],       /* (o)     : output signal                              */
  173.   Word16 lg,        /* (i)     : size of filtering                          */
  174.   Word16 mem[],     /* (i/o)   : memory associated with this filtering.     */
  175.   Word16 update     /* (i)     : 0=no update, 1=update of memory.           */
  176. );
  177. void Convolve(
  178.   Word16 x[],       /* (i)     : input vector                               */
  179.   Word16 h[],       /* (i) Q12 : impulse response                           */
  180.   Word16 y[],       /* (o)     : output vector                              */
  181.   Word16 L          /* (i)     : vector size                                */
  182. );
  183. /*--------------------------------------------------------------------------*
  184.  *       LTP constant parameters                                            *
  185.  *--------------------------------------------------------------------------*/
  186. #define THRESHPIT   27853      /* Threshold to favor small pitch 0.85  Q15  */
  187. #define UP_SAMP     3          /* upsampling factor for fractional pitch    */
  188. #define L_INTER4    4          /* length/2 for interpolation filter         */
  189. #define FIR_SIZE_ANA (UP_SAMP*L_INTER4+1)
  190. #define L_INTER10   10         /* length/2 for interpolation filter         */
  191. #define FIR_SIZE_SYN (UP_SAMP*L_INTER10+1)
  192. /*--------------------------------------------------------------------------*
  193.  * Pitch functions.                                                         *
  194.  *--------------------------------------------------------------------------*/
  195.   Word16 Pitch_ol(  /* (o)     : open loop pitch lag                        */
  196.   Word16 signal[],  /* (i)     : signal used to compute the open loop pitch */
  197.                     /*       signal[-pit_max] to signal[-1] should be known */
  198.   Word16 pit_min,   /* (i)     : minimum pitch lag                          */
  199.   Word16 pit_max,   /* (i)     : maximum pitch lag                          */
  200.   Word16 L_frame    /* (i)     : length of frame to compute pitch           */
  201. );
  202.   Word16 Pitch_fr3( /* (o)     : pitch period.                              */
  203.   Word16 exc[],     /* (i)     : excitation buffer                          */
  204.   Word16 xn[],      /* (i)     : target vector                              */
  205.   Word16 h[],       /* (i) Q12 : impulse response of filters.               */
  206.   Word16 L_subfr,   /* (i)     : length of subframe                         */
  207.   Word16 t0_min,    /* (i)     : minimum value in the searched range.       */
  208.   Word16 t0_max,    /* (i)     : maximum value in the searched range.       */
  209.   Word16 i_subfr,   /* (i)     : indicator for first subframe.              */
  210.   Word16 *pit_frac  /* (o)     : chosen fraction.                           */
  211. );
  212. Word16 G_pitch(     /* (o) Q14 : Gain of pitch lag saturated to 1.2         */
  213.   Word16 xn[],      /* (i)     : Pitch target.                              */
  214.   Word16 y1[],      /* (i)     : Filtered adaptive codebook.                */
  215.   Word16 g_coeff[], /* (i)     : Correlations need for gain quantization.   */
  216.   Word16 L_subfr    /* (i)     : Length of subframe.                        */
  217. );
  218. Word16 Enc_lag3(    /* (o)     : Return index of encoding                   */
  219.   Word16 T0,        /* (i)     : Pitch delay                                */
  220.   Word16 T0_frac,   /* (i)     : Fractional pitch delay                     */
  221.   Word16 *T0_min,   /* (i/o)   : Minimum search delay                       */
  222.   Word16 *T0_max,   /* (i/o)   : Maximum search delay                       */
  223.   Word16 pit_min,   /* (i)     : Minimum pitch delay                        */
  224.   Word16 pit_max,   /* (i)     : Maximum pitch delay                        */
  225.   Word16 pit_flag   /* (i)     : Flag for 1st subframe                      */
  226. );
  227. void Dec_lag3(      /* (o)     : return integer pitch lag                   */
  228.   Word16 index,     /* (i)     : received pitch index                       */
  229.   Word16 pit_min,   /* (i)     : minimum pitch lag                          */
  230.   Word16 pit_max,   /* (i)     : maximum pitch lag                          */
  231.   Word16 i_subfr,   /* (i)     : subframe flag                              */
  232.   Word16 *T0,       /* (o)     : integer part of pitch lag                  */
  233.   Word16 *T0_frac   /* (o)     : fractional part of pitch lag               */
  234. );
  235. Word16 Interpol_3(  /* (o)     : interpolated value                         */
  236.   Word16 *x,        /* (i)     : input vector                               */
  237.   Word16 frac       /* (i)     : fraction                                   */
  238. );
  239. void Pred_lt_3(
  240.   Word16 exc[],     /* (i/o)   : excitation buffer                          */
  241.   Word16 T0,        /* (i)     : integer pitch lag                          */
  242.   Word16 frac,      /* (i)     : fraction of lag                            */
  243.   Word16 L_subfr    /* (i)     : subframe size                              */
  244. );
  245. Word16 Parity_Pitch( /* (o)    : parity bit (XOR of 6 MSB bits)             */
  246.   Word16 pitch_index /* (i)    : index for which parity to compute          */
  247. );
  248. Word16 Check_Parity_Pitch( /* (o) : 0 = no error, 1= error                  */
  249.   Word16 pitch_index, /* (i)   : index of parameter                         */
  250.   Word16 parity       /* (i)   : parity bit                                 */
  251. );
  252. /*--------------------------------------------------------------------------*
  253.  * fixed codebook excitation.                                               *
  254.  *--------------------------------------------------------------------------*/
  255. /*--------------------------------------------------------------------------*
  256.  *       FCB constant parameters                                            *
  257.  *--------------------------------------------------------------------------*/
  258. #define DIM_RR      616        /* size of correlation matrix                */
  259. #define NB_POS      8          /*                                           */
  260. #define STEP        5          /* spacing for individual pulse              */
  261. #define MSIZE       64
  262. #define THRESHFCB   13107      /* 0.4 in Q15                                */
  263. #define MAX_TIME    75         /* maximum number of iterations              */
  264. /*--------------------------------------------------------------------------*
  265.  * FCB functions.                                                           *
  266.  *--------------------------------------------------------------------------*/
  267. Word16 ACELP_Codebook( /* (o)  : index of pulses positions                  */
  268.   Word16 x[],       /* (i)     : Target vector                              */
  269.   Word16 h[],       /* (i) Q12 : Impulse response of filters                */
  270.   Word16 T0,        /* (i)     : Pitch lag                                  */
  271.   Word16 pitch_sharp,/* (i) Q14: Last quantized pitch gain                  */
  272.   Word16 i_subfr,   /* (i)     : Indicator of 1st subframe,                 */
  273.   Word16 code[],    /* (o) Q13 : Innovative codebook                        */
  274.   Word16 y[],       /* (o) Q12 : Filtered innovative codebook               */
  275.   Word16 *sign      /* (o)     : Signs of 4 pulses                          */
  276. );
  277. void Decod_ACELP(
  278.   Word16 sign,      /* (i)     : signs of 4 pulses.                         */
  279.   Word16 index,     /* (i)     : Positions of the 4 pulses.                 */
  280.   Word16 cod[]      /* (o) Q13 : algebraic (fixed) codebook excitation      */
  281. );
  282. /*--------------------------------------------------------------------------*
  283.  *       LSP quantizer constant parameters                                  *
  284.  *--------------------------------------------------------------------------*/
  285. #define NC          5          /*  NC = M/2                                 */
  286. #define MA_NP       4          /* MA prediction order for LSP               */
  287. #define MODE        2          /* number of modes for MA prediction         */
  288. #define NC0_B       7          /* number of first stage bits                */
  289. #define NC1_B       5          /* number of second stage bits               */
  290. #define NC0         (1<<NC0_B) /* number of entries in first stage          */
  291. #define NC1         (1<<NC1_B) /* number of entries in second stage         */
  292. #define L_LIMIT     40         /* minimum lsf value Q13:0.005               */
  293. #define M_LIMIT     25681      /* maximum lsf value Q13:3.135               */
  294. #define GAP1        10         /* bandwidth expansion factor Q13            */
  295. #define GAP2        5          /* bandwidth expansion factor Q13            */
  296. #define GAP3        321        /* bandwidth expansion factor Q13            */
  297. #define GRID_POINTS 60         /* search grid                               */
  298. #define PI04        ((Word16)1029)       /* Q13  pi*0.04                    */
  299. #define PI92        ((Word16)23677)      /* Q13  pi*0.92                    */
  300. #define CONST10     ((Word16)10*(1<<11)) /* Q11  10.0                       */
  301. #define CONST12     ((Word16)19661)      /* Q14  1.2                        */
  302. /*--------------------------------------------------------------------------*
  303.  * LSP VQ functions.                                                        *
  304.  *--------------------------------------------------------------------------*/
  305. void Lsf_lsp2(
  306.   Word16 lsf[],     /* (i) Q13 : lsf[m] (range: 0.0<=val<PI)                */
  307.   Word16 lsp[],     /* (o) Q15 : lsp[m] (range: -1<=val<1)                  */
  308.   Word16 m          /* (i)     : LPC order                                  */
  309. );
  310. void Lsp_lsf2(
  311.   Word16 lsp[],     /* (i) Q15 : lsp[m] (range: -1<=val<1)                  */
  312.   Word16 lsf[],     /* (o) Q13 : lsf[m] (range: 0.0<=val<PI)                */
  313.   Word16 m          /* (i)     : LPC order                                  */
  314. );
  315. void Qua_lsp(
  316.   Word16 lsp[],     /* (i) Q15 : Unquantized LSP                            */
  317.   Word16 lsp_q[],   /* (o) Q15 : Quantized LSP                              */
  318.   Word16 ana[]      /* (o)     : indexes                                    */
  319. );
  320. void Get_wegt(
  321.   Word16 flsp[],    /* (i) Q13 :                                            */
  322.   Word16 wegt[]     /* (o) Q11 :  normalized                                */
  323. );
  324. void Lsp_encw_reset( void);
  325. void Lsp_qua_cs(
  326.   Word16 flsp_in[M],  /* Q13 */
  327.   Word16 lspq_out[M], /* Q13 */
  328.   Word16 *code
  329. );
  330. void Lsp_expand_1(
  331.   Word16 buf[],     /* Q13 */
  332.   Word16 gap        /* Q13 */
  333. );
  334. void Lsp_expand_2(
  335.   Word16 buf[],     /* Q13 */
  336.   Word16 gap        /* Q13 */
  337. );
  338. void Lsp_expand_1_2(
  339.   Word16 buf[],     /* Q13 */
  340.   Word16 gap        /* Q13 */
  341. );
  342. void Lsp_get_quant(
  343.   Word16 lspcb1[][M],    /* Q13 */
  344.   Word16 lspcb2[][M],    /* Q13 */
  345.   Word16 code0,
  346.   Word16 code1,
  347.   Word16 code2,
  348.   Word16 fg[][M],        /* Q15 */
  349.   Word16 freq_prev[][M], /* Q13 */
  350.   Word16 lspq[],            /* Q13 */
  351.   Word16 fg_sum[]           /* Q15 */
  352. );
  353. void Lsp_get_tdist(
  354.   Word16 wegt[],    /* normalized */
  355.   Word16 buf[],     /* Q13 */
  356.   Word32 *L_tdist,  /* Q27 */
  357.   Word16 rbuf[],    /* Q13 */
  358.   Word16 fg_sum[]   /* Q15 */
  359. );
  360. void Lsp_last_select(
  361.   Word32 L_tdist[], /* Q27 */
  362.   Word16 *mode_index
  363. );
  364. void Lsp_pre_select(
  365.   Word16 rbuf[],         /* Q13 */
  366.   Word16 lspcb1[][M], /* Q13 */
  367.   Word16 *cand
  368. );
  369. void Lsp_select_1(
  370.   Word16 rbuf[],         /* Q13 */
  371.   Word16 lspcb1[],       /* Q13 */
  372.   Word16 wegt[],         /* normalized */
  373.   Word16 lspcb2[][M], /* Q13 */
  374.   Word16 *index
  375. );
  376. void Lsp_select_2(
  377.   Word16 rbuf[],         /* Q13 */
  378.   Word16 lspcb1[],       /* Q13 */
  379.   Word16 wegt[],         /* normalized */
  380.   Word16 lspcb2[][M], /* Q13 */
  381.   Word16 *index
  382. );
  383. void Lsp_stability(
  384.   Word16 buf[]     /* Q13 */
  385. );
  386. void Relspwed(
  387.   Word16 lsp[],                          /* Q13 */
  388.   Word16 wegt[],                         /* normalized */
  389.   Word16 lspq[],                         /* Q13 */
  390.   Word16 lspcb1[][M],                 /* Q13 */
  391.   Word16 lspcb2[][M],                 /* Q13 */
  392.   Word16 fg[MODE][MA_NP][M],          /* Q15 */
  393.   Word16 freq_prev[MA_NP][M],         /* Q13 */
  394.   Word16 fg_sum[MODE][M],             /* Q15 */
  395.   Word16 fg_sum_inv[MODE][M],         /* Q12 */
  396.   Word16 code_ana[]
  397. );
  398. void D_lsp(
  399.   Word16 prm[],     /* (i)     : indexes of the selected LSP                */
  400.   Word16 lsp_q[],   /* (o) Q15 : Quantized LSP parameters                   */
  401.   Word16 erase      /* (i)     : frame erase information                    */
  402. );
  403. void Lsp_decw_reset( void);
  404. void Lsp_iqua_cs(
  405.   Word16 prm[],     /* (i)     : codes of the selected LSP                  */
  406.   Word16 lsp_q[],   /* (o)     : Quantized LSP parameters                   */
  407.   Word16 erase      /* (i)     : frame erase information                    */
  408. );
  409. void Lsp_prev_compose(
  410.   Word16 lsp_ele[], /* Q13 */
  411.   Word16 lsp[],     /* Q13 */
  412.   Word16 fg[][M],/* Q15 */
  413.   Word16 freq_prev[][M],     /* Q13 */
  414.   Word16 fg_sum[]   /* Q15 */
  415. );
  416. void Lsp_prev_extract(
  417.   Word16 lsp[M],                 /* Q13 */
  418.   Word16 lsp_ele[M],             /* Q13 */
  419.   Word16 fg[MA_NP][M],           /* Q15 */
  420.   Word16 freq_prev[MA_NP][M],    /* Q13 */
  421.   Word16 fg_sum_inv[M]           /* Q12 */
  422. );
  423. void Lsp_prev_update(
  424.   Word16 lsp_ele[M],             /* Q13 */
  425.   Word16 freq_prev[MA_NP][M]     /* Q13 */
  426. );
  427. /*--------------------------------------------------------------------------*
  428.  * gain VQ constants.                                                       *
  429.  *--------------------------------------------------------------------------*/
  430. #define NCODE1_B  3                /* number of Codebook-bit                */
  431. #define NCODE2_B  4                /* number of Codebook-bit                */
  432. #define NCODE1    (1<<NCODE1_B)    /* Codebook 1 size                       */
  433. #define NCODE2    (1<<NCODE2_B)    /* Codebook 2 size                       */
  434. #define NCAN1     4                /* Pre-selecting order for #1            */
  435. #define NCAN2     8                /* Pre-selecting order for #2            */
  436. #define INV_COEF  -17103           /* Q19                                   */
  437. /*--------------------------------------------------------------------------*
  438.  * gain VQ functions.                                                       *
  439.  *--------------------------------------------------------------------------*/
  440. Word16 Qua_gain(
  441.   Word16 code[],    /* (i) Q13 : Innovative vector.                         */
  442.   Word16 g_coeff[], /* (i)     : Correlations <xn y1> -2<y1 y1>             */
  443.                     /*            <y2,y2>, -2<xn,y2>, 2<y1,y2>              */
  444.   Word16 exp_coeff[],/* (i)    : Q-Format g_coeff[]                         */
  445.   Word16 L_subfr,   /* (i)     : Subframe length.                           */
  446.   Word16 *gain_pit, /* (o) Q14 : Pitch gain.                                */
  447.   Word16 *gain_cod, /* (o) Q1  : Code gain.                                 */
  448.   Word16 tameflag   /* (i)     : flag set to 1 if taming is needed          */
  449. );
  450. void Dec_gain(
  451.   Word16 index,     /* (i)     : Index of quantization.                     */
  452.   Word16 code[],    /* (i) Q13 : Innovative vector.                         */
  453.   Word16 L_subfr,   /* (i)     : Subframe length.                           */
  454.   Word16 bfi,       /* (i)     : Bad frame indicator                        */
  455.   Word16 *gain_pit, /* (o) Q14 : Pitch gain.                                */
  456.   Word16 *gain_cod  /* (o) Q1  : Code gain.                                 */
  457. );
  458. void Gain_predict(
  459.   Word16 past_qua_en[],/* (i) Q10 :Past quantized energies                  */
  460.   Word16 code[],    /* (i) Q13 : Innovative vector.                         */
  461.   Word16 L_subfr,   /* (i)     : Subframe length.                           */
  462.   Word16 *gcode0,   /* (o) Qxx : Predicted codebook gain                    */
  463.   Word16 *exp_gcode0 /* (o)    : Q-Format(gcode0)                           */
  464. );
  465. void Gain_update(
  466.   Word16 past_qua_en[],/* (i) Q10 :Past quantized energies                  */
  467.   Word32 L_gbk12    /* (i) Q13 : gbk1[indice1][1]+gbk2[indice2][1]          */
  468. );
  469. void Gain_update_erasure(
  470.   Word16 past_qua_en[]/* (i) Q10 :Past quantized energies                   */
  471. );
  472. void Corr_xy2(
  473.   Word16 xn[],      /* (i) Q0  :Target vector.                              */
  474.   Word16 y1[],      /* (i) Q0  :Adaptive codebook.                          */
  475.   Word16 y2[],      /* (i) Q12 :Filtered innovative vector.                 */
  476.   Word16 g_coeff[], /* (o) Q[exp]:Correlations between xn,y1,y2             */
  477.   Word16 exp_g_coeff[]  /* (o)  :Q-format of g_coeff[]                      */
  478. );
  479. /*--------------------------------------------------------------------------*
  480.  * Postfilter constants and functions                                       *
  481.  *--------------------------------------------------------------------------*/
  482. /* short term pst parameters :                                              */
  483. #define GAMMA1_PST  22938      /* denominator weighting factor   (Q15)      */
  484. #define GAMMA2_PST  18022      /* numerator  weighting factor (Q15)         */
  485. #define LONG_H_ST   20         /* impulse response length                   */
  486. #define GAMMA3_PLUS 6554       /* tilt weighting factor when k1>0 (Q15)     */
  487. #define GAMMA3_MINUS 29491     /* tilt weighting factor when k1<0 (Q15)     */
  488. /* long term pst parameters :                                               */
  489. #define F_UP_PST    8          /* resolution for fractional delay           */
  490. #define LH2_S       4          /* length of short interp. subfilters        */
  491. #define L2_LH2_L    4          /* log2(LH2_L)                               */
  492. #define LH2_L       (1 << L2_LH2_L)
  493. #define MIN_GPLT    21845      /* LT gain minimum (Q15)                     */
  494. #define LH_UP_S     (LH2_S/2)
  495. #define LH_UP_SM1   (LH_UP_S-1)
  496. #define LH_UP_L     (LH2_L/2)
  497. #define LH2_L_P1    (LH2_L + 1)
  498. /* gain adjustment parameters                                               */
  499. #define AGC_FAC     32358     /* gain adjustment factor  0.9875 (Q15)       */
  500. #define AGC_FAC1    (Word16)(32768L - AGC_FAC)
  501. /* Array sizes */
  502. #define MEM_RES2    (PIT_MAX + 1 + LH_UP_L)
  503. #define SIZ_RES2    (MEM_RES2 + L_SUBFR)
  504. #define SIZ_Y_UP    ((F_UP_PST-1) * L_SUBFRP1)
  505. #define SIZ_TAB_HUP_L ((F_UP_PST-1) * LH2_L)
  506. #define SIZ_TAB_HUP_S ((F_UP_PST-1) * LH2_S)
  507. void  Init_Post_Filter( void);
  508. void Post(
  509.   Word16 t0,        /* (i) : 1st subframe delay given by coder              */
  510.   Word16 *signal_ptr, /* (i) : input signal (pointer to current subframe    */
  511.   Word16 *coeff,    /* (i) : LPC coefficients for current subframe          */
  512.   Word16 *sig_out,  /* (o) : postfiltered output                            */
  513.   Word16 *vo        /* (o) : voicing decision 0 = uv,  > 0 delay            */
  514. );
  515. /*--------------------------------------------------------------------------*
  516.  * Bitstream constants and functions                                        *
  517.  *--------------------------------------------------------------------------*/
  518. #define BIT_0    (short)0x007f /* definition of zero-bit in bit-stream      */
  519. #define BIT_1    (short)0x0081 /* definition of one-bit in bit-stream       */
  520. #define SYNC_WORD (short)0x6b21 /* definition of frame erasure flag         */
  521. #define SIZE_WORD (short)80     /* number of speech bits                    */
  522. void  prm2bits_ld8k(
  523.   Word16 prm[],     /* (i)     : coder parameters                           */
  524.   Word16 bits[]     /* (o)     : bit stream                                 */
  525. );
  526. void  bits2prm_ld8k(
  527.   Word16 bits[],    /* (i)     : bit stream                                 */
  528.   Word16 prm[]      /* (o)     : coder parameters                           */
  529. );
  530. /*--------------------------------------------------------------------------*
  531.  * Prototypes for auxiliary functions.                                      *
  532.  *--------------------------------------------------------------------------*/
  533. void Copy(
  534.   Word16 x[],       /* (i)     : input vector                               */
  535.   Word16 y[],       /* (o)     : output vector                              */
  536.   Word16 L          /* (i)     : vector length                              */
  537. );
  538. void Set_zero(
  539.   Word16 x[],       /* (o)     : vector to clear                            */
  540.   Word16 L          /* (i)     : length of vector                           */
  541. );
  542. Word16 Random(void);