biquad.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * SpanDSP - a series of DSP components for telephony
  3. *
  4. * biquad.h - General telephony bi-quad section routines (currently this just
  5. * handles canonic/type 2 form)
  6. *
  7. * Written by Steve Underwood <steveu@coppice.org>
  8. *
  9. * Copyright (C) 2001 Steve Underwood
  10. *
  11. * All rights reserved.
  12. *
  13. */
  14. /*
  15. * See http://www.asterisk.org for more information about
  16. * the Asterisk project. Please do not directly contact
  17. * any of the maintainers of this project for assistance;
  18. * the project provides a web site, mailing lists and IRC
  19. * channels for your use.
  20. *
  21. * This program is free software, distributed under the terms of
  22. * the GNU General Public License Version 2 as published by the
  23. * Free Software Foundation. See the LICENSE file included with
  24. * this program for more details.
  25. */
  26. static inline void biquad2_init (biquad2_state_t *bq,
  27. int32_t gain,
  28. int32_t a1,
  29. int32_t a2,
  30. int32_t b1,
  31. int32_t b2)
  32. {
  33. bq->gain = gain;
  34. bq->a1 = a1;
  35. bq->a2 = a2;
  36. bq->b1 = b1;
  37. bq->b2 = b2;
  38. bq->z1 = 0;
  39. bq->z2 = 0;
  40. }
  41. /*- End of function --------------------------------------------------------*/
  42. static inline int16_t biquad2 (biquad2_state_t *bq, int16_t sample)
  43. {
  44. int32_t y;
  45. int32_t z0;
  46. z0 = sample*bq->gain + bq->z1*bq->a1 + bq->z2*bq->a2;
  47. y = z0 + bq->z1*bq->b1 + bq->z2*bq->b2;
  48. bq->z2 = bq->z1;
  49. bq->z1 = z0 >> 15;
  50. y >>= 15;
  51. return y;
  52. }
  53. /*- End of function --------------------------------------------------------*/
  54. /*- End of file ------------------------------------------------------------*/