PRE_PROC.C
上传用户:meifeng08
上传日期:2013-06-18
资源大小:5304k
文件大小:3k
源码类别:

语音压缩

开发平台:

C/C++

  1. /*
  2.    ITU-T G.729A Speech Coder    ANSI-C Source Code
  3.    Version 1.1    Last modified: September 1996
  4.    Copyright (c) 1996,
  5.    AT&T, France Telecom, NTT, Universite de Sherbrooke
  6.    All rights reserved.
  7. */
  8. /*------------------------------------------------------------------------*
  9.  * Function Pre_Process()                                                 *
  10.  *                                                                        *
  11.  * Preprocessing of input speech.                                         *
  12.  *   - 2nd order high pass filter with cut off frequency at 140 Hz.       *
  13.  *   - Divide input by two.                                               *
  14.  *-----------------------------------------------------------------------*/
  15. #include "typedef.h"
  16. #include "basic_op.h"
  17. #include "oper_32b.h"
  18. #include "ld8a.h"
  19. #include "tab_ld8a.h"
  20. /*------------------------------------------------------------------------*
  21.  * 2nd order high pass filter with cut off frequency at 140 Hz.           *
  22.  * Designed with SPPACK efi command -40 dB att, 0.25 ri.                  *
  23.  *                                                                        *
  24.  * Algorithm:                                                             *
  25.  *                                                                        *
  26.  *  y[i] = b[0]*x[i]/2 + b[1]*x[i-1]/2 + b[2]*x[i-2]/2                    *
  27.  *                     + a[1]*y[i-1]   + a[2]*y[i-2];                     *
  28.  *                                                                        *
  29.  *     b[3] = {0.92727435E+00, -0.18544941E+01, 0.92727435E+00};          *
  30.  *     a[3] = {0.10000000E+01, 0.19059465E+01, -0.91140240E+00};          *
  31.  *                                                                        *
  32.  *  Input are divided by two in the filtering process.                    *
  33.  *-----------------------------------------------------------------------*/
  34. /* Static values to be preserved between calls */
  35. /* y[] values is keep in double precision      */
  36. static Word16 y2_hi, y2_lo, y1_hi, y1_lo, x0, x1;
  37. /* Initialization of static values */
  38. void Init_Pre_Process(void)
  39. {
  40.   y2_hi = 0;
  41.   y2_lo = 0;
  42.   y1_hi = 0;
  43.   y1_lo = 0;
  44.   x0   = 0;
  45.   x1   = 0;
  46. }
  47. void Pre_Process(
  48.   Word16 signal[],    /* input/output signal */
  49.   Word16 lg)          /* length of signal    */
  50. {
  51.   Word16 i, x2;
  52.   Word32 L_tmp;
  53.   for(i=0; i<lg; i++)
  54.   {
  55.      x2 = x1;
  56.      x1 = x0;
  57.      x0 = signal[i];
  58.      /*  y[i] = b[0]*x[i]/2 + b[1]*x[i-1]/2 + b140[2]*x[i-2]/2  */
  59.      /*                     + a[1]*y[i-1] + a[2] * y[i-2];      */
  60.      L_tmp     = Mpy_32_16(y1_hi, y1_lo, a140[1]);
  61.      L_tmp     = L_add(L_tmp, Mpy_32_16(y2_hi, y2_lo, a140[2]));
  62.      L_tmp     = L_mac(L_tmp, x0, b140[0]);
  63.      L_tmp     = L_mac(L_tmp, x1, b140[1]);
  64.      L_tmp     = L_mac(L_tmp, x2, b140[2]);
  65.      L_tmp     = L_shl(L_tmp, 3);      /* Q28 --> Q31 (Q12 --> Q15) */
  66.      signal[i] = round(L_tmp);
  67.      y2_hi = y1_hi;
  68.      y2_lo = y1_lo;
  69.      L_Extract(L_tmp, &y1_hi, &y1_lo);
  70.   }
  71.   return;
  72. }