convolve.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. ********************************************************************************
  3. *
  4. * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
  5. * R99 Version 3.3.0
  6. * REL-4 Version 4.1.0
  7. *
  8. ********************************************************************************
  9. *
  10. * File : convolve.c
  11. * Purpose : Perform the convolution between two vectors x[]
  12. * : and h[] and write the result in the vector y[].
  13. * : All vectors are of length L and only the first
  14. * : L samples of the convolution are computed.
  15. *
  16. ********************************************************************************
  17. */
  18. /*
  19. ********************************************************************************
  20. * MODULE INCLUDE FILE AND VERSION ID
  21. ********************************************************************************
  22. */
  23. #include "convolve.h"
  24. const char convolve_id[] = "@(#)$Id $" convolve_h;
  25. /*
  26. ********************************************************************************
  27. * INCLUDE FILES
  28. ********************************************************************************
  29. */
  30. #include "typedef.h"
  31. #include "basic_op.h"
  32. #include "count.h"
  33. /*
  34. ********************************************************************************
  35. * LOCAL VARIABLES AND TABLES
  36. ********************************************************************************
  37. */
  38. /*
  39. ********************************************************************************
  40. * PUBLIC PROGRAM CODE
  41. ********************************************************************************
  42. */
  43. /*************************************************************************
  44. *
  45. * FUNCTION: Convolve
  46. *
  47. * PURPOSE:
  48. * Perform the convolution between two vectors x[] and h[] and
  49. * write the result in the vector y[]. All vectors are of length L
  50. * and only the first L samples of the convolution are computed.
  51. *
  52. * DESCRIPTION:
  53. * The convolution is given by
  54. *
  55. * y[n] = sum_{i=0}^{n} x[i] h[n-i], n=0,...,L-1
  56. *
  57. *************************************************************************/
  58. void Convolve (
  59. Word16 x[], /* (i) : input vector */
  60. Word16 h[], /* (i) : impulse response */
  61. Word16 y[], /* (o) : output vector */
  62. Word16 L /* (i) : vector size */
  63. )
  64. {
  65. Word16 i, n;
  66. Word32 s;
  67. for (n = 0; n < L; n++)
  68. {
  69. s = 0; move32 ();
  70. for (i = 0; i <= n; i++)
  71. {
  72. s = L_mac_ex (s, x[i], h[n - i]);
  73. }
  74. s = L_shl_ex (s, 3);
  75. y[n] = extract_h_ex (s); move16 ();
  76. }
  77. return;
  78. }