dsp_biquad.h 977 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * SpanDSP - a series of DSP components for telephony
  4. *
  5. * biquad.h - General telephony bi-quad section routines (currently this just
  6. * handles canonic/type 2 form)
  7. *
  8. * Written by Steve Underwood <[email protected]>
  9. *
  10. * Copyright (C) 2001 Steve Underwood
  11. *
  12. * All rights reserved.
  13. */
  14. struct biquad2_state {
  15. int32_t gain;
  16. int32_t a1;
  17. int32_t a2;
  18. int32_t b1;
  19. int32_t b2;
  20. int32_t z1;
  21. int32_t z2;
  22. };
  23. static inline void biquad2_init(struct biquad2_state *bq,
  24. int32_t gain, int32_t a1, int32_t a2, int32_t b1, int32_t b2)
  25. {
  26. bq->gain = gain;
  27. bq->a1 = a1;
  28. bq->a2 = a2;
  29. bq->b1 = b1;
  30. bq->b2 = b2;
  31. bq->z1 = 0;
  32. bq->z2 = 0;
  33. }
  34. static inline int16_t biquad2(struct biquad2_state *bq, int16_t sample)
  35. {
  36. int32_t y;
  37. int32_t z0;
  38. z0 = sample * bq->gain + bq->z1 * bq->a1 + bq->z2 * bq->a2;
  39. y = z0 + bq->z1 * bq->b1 + bq->z2 * bq->b2;
  40. bq->z2 = bq->z1;
  41. bq->z1 = z0 >> 15;
  42. y >>= 15;
  43. return y;
  44. }