| Karsten Keil | 960366c | 2008-07-27 01:56:38 +0200 | [diff] [blame] | 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 |  * This program is free software; you can redistribute it and/or modify | 
 | 14 |  * it under the terms of the GNU General Public License as published by | 
 | 15 |  * the Free Software Foundation; either version 2 of the License, or | 
 | 16 |  * (at your option) any later version. | 
 | 17 |  * | 
 | 18 |  * This program is distributed in the hope that it will be useful, | 
 | 19 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 20 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 21 |  * GNU General Public License for more details. | 
 | 22 |  * | 
 | 23 |  * You should have received a copy of the GNU General Public License | 
 | 24 |  * along with this program; if not, write to the Free Software | 
 | 25 |  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 
 | 26 |  * | 
 | 27 |  */ | 
 | 28 |  | 
 | 29 | struct biquad2_state { | 
 | 30 | 	int32_t gain; | 
 | 31 | 	int32_t a1; | 
 | 32 | 	int32_t a2; | 
 | 33 | 	int32_t b1; | 
 | 34 | 	int32_t b2; | 
 | 35 |  | 
 | 36 | 	int32_t z1; | 
 | 37 | 	int32_t z2; | 
 | 38 | }; | 
 | 39 |  | 
 | 40 | static inline void biquad2_init(struct biquad2_state *bq, | 
| Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 41 | 				int32_t gain, int32_t a1, int32_t a2, int32_t b1, int32_t b2) | 
| Karsten Keil | 960366c | 2008-07-27 01:56:38 +0200 | [diff] [blame] | 42 | { | 
 | 43 | 	bq->gain = gain; | 
 | 44 | 	bq->a1 = a1; | 
 | 45 | 	bq->a2 = a2; | 
 | 46 | 	bq->b1 = b1; | 
 | 47 | 	bq->b2 = b2; | 
 | 48 |  | 
 | 49 | 	bq->z1 = 0; | 
 | 50 | 	bq->z2 = 0; | 
 | 51 | } | 
 | 52 |  | 
 | 53 | static inline int16_t biquad2(struct biquad2_state *bq, int16_t sample) | 
 | 54 | { | 
 | 55 | 	int32_t y; | 
 | 56 | 	int32_t z0; | 
 | 57 |  | 
| Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 58 | 	z0 = sample * bq->gain + bq->z1 * bq->a1 + bq->z2 * bq->a2; | 
 | 59 | 	y = z0 + bq->z1 * bq->b1 + bq->z2 * bq->b2; | 
| Karsten Keil | 960366c | 2008-07-27 01:56:38 +0200 | [diff] [blame] | 60 |  | 
 | 61 | 	bq->z2 = bq->z1; | 
 | 62 | 	bq->z1 = z0 >> 15; | 
 | 63 | 	y >>= 15; | 
 | 64 | 	return  y; | 
 | 65 | } |