/*1* SpanDSP - a series of DSP components for telephony2*3* biquad.h - General telephony bi-quad section routines (currently this just4* handles canonic/type 2 form)5*6* Written by Steve Underwood <[email protected]>7*8* Copyright (C) 2001 Steve Underwood9*10* All rights reserved.11*12* This program is free software; you can redistribute it and/or modify13* it under the terms of the GNU General Public License as published by14* the Free Software Foundation; either version 2 of the License, or15* (at your option) any later version.16*17* This program is distributed in the hope that it will be useful,18* but WITHOUT ANY WARRANTY; without even the implied warranty of19* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the20* GNU General Public License for more details.21*22* You should have received a copy of the GNU General Public License23* along with this program; if not, write to the Free Software24* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.25*26*/2728struct biquad2_state {29int32_t gain;30int32_t a1;31int32_t a2;32int32_t b1;33int32_t b2;3435int32_t z1;36int32_t z2;37};3839static inline void biquad2_init(struct biquad2_state *bq,40int32_t gain, int32_t a1, int32_t a2, int32_t b1, int32_t b2)41{42bq->gain = gain;43bq->a1 = a1;44bq->a2 = a2;45bq->b1 = b1;46bq->b2 = b2;4748bq->z1 = 0;49bq->z2 = 0;50}5152static inline int16_t biquad2(struct biquad2_state *bq, int16_t sample)53{54int32_t y;55int32_t z0;5657z0 = sample*bq->gain + bq->z1*bq->a1 + bq->z2*bq->a2;58y = z0 + bq->z1*bq->b1 + bq->z2*bq->b2;5960bq->z2 = bq->z1;61bq->z1 = z0 >> 15;62y >>= 15;63return y;64}656667