FILTER.C
Upload User: meifeng08
Upload Date: 2013-06-18
Package Size: 5304k
Code Size: 4k
Category:

Voice Compress

Development Platform:

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  Convolve:                                               *
  10.  *           ~~~~~~~~~                                               *
  11.  *-------------------------------------------------------------------*
  12.  * Perform the convolution between two vectors x[] and h[] and       *
  13.  * write the result in the vector y[].                               *
  14.  * All vectors are of length N.                                      *
  15.  *-------------------------------------------------------------------*/
  16. #include "typedef.h"
  17. #include "basic_op.h"
  18. #include "ld8a.h"
  19. void Convolve(
  20.   Word16 x[],      /* (i)     : input vector                           */
  21.   Word16 h[],      /* (i) Q12 : impulse response                       */
  22.   Word16 y[],      /* (o)     : output vector                          */
  23.   Word16 L         /* (i)     : vector size                            */
  24. )
  25. {
  26.    Word16 i, n;
  27.    Word32 s;
  28.    for (n = 0; n < L; n++)
  29.    {
  30.      s = 0;
  31.      for (i = 0; i <= n; i++)
  32.        s = L_mac(s, x[i], h[n-i]);
  33.      s    = L_shl(s, 3);                   /* h is in Q12 and saturation */
  34.      y[n] = extract_h(s);
  35.    }
  36.    return;
  37. }
  38. /*-----------------------------------------------------*
  39.  * procedure Syn_filt:                                 *
  40.  *           ~~~~~~~~                                  *
  41.  * Do the synthesis filtering 1/A(z).                  *
  42.  *-----------------------------------------------------*/
  43. void Syn_filt(
  44.   Word16 a[],     /* (i) Q12 : a[m+1] prediction coefficients   (m=10)  */
  45.   Word16 x[],     /* (i)     : input signal                             */
  46.   Word16 y[],     /* (o)     : output signal                            */
  47.   Word16 lg,      /* (i)     : size of filtering                        */
  48.   Word16 mem[],   /* (i/o)   : memory associated with this filtering.   */
  49.   Word16 update   /* (i)     : 0=no update, 1=update of memory.         */
  50. )
  51. {
  52.   Word16 i, j;
  53.   Word32 s;
  54.   Word16 tmp[100];     /* This is usually done by memory allocation (lg+M) */
  55.   Word16 *yy;
  56.   /* Copy mem[] to yy[] */
  57.   yy = tmp;
  58.   for(i=0; i<M; i++)
  59.   {
  60.     *yy++ = mem[i];
  61.   }
  62.   /* Do the filtering. */
  63.   for (i = 0; i < lg; i++)
  64.   {
  65.     s = L_mult(x[i], a[0]);
  66.     for (j = 1; j <= M; j++)
  67.       s = L_msu(s, a[j], yy[-j]);
  68.     s = L_shl(s, 3);
  69.     *yy++ = round(s);
  70.   }
  71.   for(i=0; i<lg; i++)
  72.   {
  73.     y[i] = tmp[i+M];
  74.   }
  75.   /* Update of memory if update==1 */
  76.   if(update != 0)
  77.      for (i = 0; i < M; i++)
  78.      {
  79.        mem[i] = y[lg-M+i];
  80.      }
  81.  return;
  82. }
  83. /*-----------------------------------------------------------------------*
  84.  * procedure Residu:                                                     *
  85.  *           ~~~~~~                                                      *
  86.  * Compute the LPC residual  by filtering the input speech through A(z)  *
  87.  *-----------------------------------------------------------------------*/
  88. void Residu(
  89.   Word16 a[],    /* (i) Q12 : prediction coefficients                     */
  90.   Word16 x[],    /* (i)     : speech (values x[-m..-1] are needed         */
  91.   Word16 y[],    /* (o)     : residual signal                             */
  92.   Word16 lg      /* (i)     : size of filtering                           */
  93. )
  94. {
  95.   Word16 i, j;
  96.   Word32 s;
  97.   for (i = 0; i < lg; i++)
  98.   {
  99.     s = L_mult(x[i], a[0]);
  100.     for (j = 1; j <= M; j++)
  101.       s = L_mac(s, a[j], x[i-j]);
  102.     s = L_shl(s, 3);
  103.     y[i] = round(s);
  104.   }
  105.   return;
  106. }