dsp_biquad.h (977B)
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 <steveu@coppice.org> 9 * 10 * Copyright (C) 2001 Steve Underwood 11 * 12 * All rights reserved. 13 */ 14 15struct biquad2_state { 16 int32_t gain; 17 int32_t a1; 18 int32_t a2; 19 int32_t b1; 20 int32_t b2; 21 22 int32_t z1; 23 int32_t z2; 24}; 25 26static inline void biquad2_init(struct biquad2_state *bq, 27 int32_t gain, int32_t a1, int32_t a2, int32_t b1, int32_t b2) 28{ 29 bq->gain = gain; 30 bq->a1 = a1; 31 bq->a2 = a2; 32 bq->b1 = b1; 33 bq->b2 = b2; 34 35 bq->z1 = 0; 36 bq->z2 = 0; 37} 38 39static inline int16_t biquad2(struct biquad2_state *bq, int16_t sample) 40{ 41 int32_t y; 42 int32_t z0; 43 44 z0 = sample * bq->gain + bq->z1 * bq->a1 + bq->z2 * bq->a2; 45 y = z0 + bq->z1 * bq->b1 + bq->z2 * bq->b2; 46 47 bq->z2 = bq->z1; 48 bq->z1 = z0 >> 15; 49 y >>= 15; 50 return y; 51}