0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 struct biquad2_state {
0016 int32_t gain;
0017 int32_t a1;
0018 int32_t a2;
0019 int32_t b1;
0020 int32_t b2;
0021
0022 int32_t z1;
0023 int32_t z2;
0024 };
0025
0026 static inline void biquad2_init(struct biquad2_state *bq,
0027 int32_t gain, int32_t a1, int32_t a2, int32_t b1, int32_t b2)
0028 {
0029 bq->gain = gain;
0030 bq->a1 = a1;
0031 bq->a2 = a2;
0032 bq->b1 = b1;
0033 bq->b2 = b2;
0034
0035 bq->z1 = 0;
0036 bq->z2 = 0;
0037 }
0038
0039 static inline int16_t biquad2(struct biquad2_state *bq, int16_t sample)
0040 {
0041 int32_t y;
0042 int32_t z0;
0043
0044 z0 = sample * bq->gain + bq->z1 * bq->a1 + bq->z2 * bq->a2;
0045 y = z0 + bq->z1 * bq->b1 + bq->z2 * bq->b2;
0046
0047 bq->z2 = bq->z1;
0048 bq->z1 = z0 >> 15;
0049 y >>= 15;
0050 return y;
0051 }