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

语音压缩

开发平台:

C/C++

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