| 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 <[email protected]> |
| 8 | * |
| 9 | * Copyright (C) 2001 Steve Underwood |
| 10 | * |
| 11 | * All rights reserved. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | /* |
| 16 | * See http://www.asterisk.org for more information about |
| 17 | * the Asterisk project. Please do not directly contact |
| 18 | * any of the maintainers of this project for assistance; |
| 19 | * the project provides a web site, mailing lists and IRC |
| 20 | * channels for your use. |
| 21 | * |
| 22 | * This program is free software, distributed under the terms of |
| 23 | * the GNU General Public License Version 2 as published by the |
| 24 | * Free Software Foundation. See the LICENSE file included with |
| 25 | * this program for more details. |
| 26 | */ |
| 27 | |
| 28 | static inline void biquad2_init (biquad2_state_t *bq, |
| 29 | int32_t gain, |
| 30 | int32_t a1, |
| 31 | int32_t a2, |
| 32 | int32_t b1, |
| 33 | int32_t b2) |
| 34 | { |
| 35 | bq->gain = gain; |
| 36 | bq->a1 = a1; |
| 37 | bq->a2 = a2; |
| 38 | bq->b1 = b1; |
| 39 | bq->b2 = b2; |
| 40 | |
| 41 | bq->z1 = 0; |
| 42 | bq->z2 = 0; |
| 43 | } |
| 44 | /*- End of function --------------------------------------------------------*/ |
| 45 | |
| 46 | static inline int16_t biquad2 (biquad2_state_t *bq, int16_t sample) |
| 47 | { |
| 48 | int32_t y; |
| 49 | int32_t z0; |
| 50 | |
| 51 | z0 = sample*bq->gain + bq->z1*bq->a1 + bq->z2*bq->a2; |
| 52 | y = z0 + bq->z1*bq->b1 + bq->z2*bq->b2; |
| 53 | |
| 54 | bq->z2 = bq->z1; |
| 55 | bq->z1 = z0 >> 15; |
| 56 | y >>= 15; |
| 57 | return y; |
| 58 | } |
| 59 | /*- End of function --------------------------------------------------------*/ |
| 60 | /*- End of file ------------------------------------------------------------*/ |