LMMS
Loading...
Searching...
No Matches
BiQuad.h
Go to the documentation of this file.
1/*
2 dsp/BiQuad.h
3
4 Copyright 2003-7 Tim Goetze <tim@quitte.de>
5
6 http://quitte.de/dsp/
7
8 Bi-quad IIR filter.
9
10*/
11/*
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 as published by the Free Software Foundation; either version 2
15 of the License, or (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 of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA or point your web browser to http://www.gnu.org.
26*/
27
28#ifndef _DSP_BI_QUAD_H_
29#define _DSP_BI_QUAD_H_
30
31namespace DSP {
32
33class BiQuad
34{
35 public:
36 /* coefficients */
37 sample_t a[3], b[3];
38
39 /* history */
40 int h;
41 sample_t x[2], y[2];
42
44 {
45 unity();
46 reset();
47 }
48
49 void unity()
50 {
51 a[0] = 1;
52 a[1] = a[2] = b[0] = b[1] = b[2] = 0;
53 }
54
55 void copy (BiQuad & bq)
56 {
57 for (int i = 0; i < 3; ++i)
58 a[i] = bq.a[i],
59 b[i] = bq.b[i];
60 }
61
62 void reset()
63 {
64 h = 0;
65
66 x[0] = x[1] =
67 y[0] = y[1] = 0.;
68 }
69
70 /* denormal zapping */
71 void flush_0()
72 {
73 for (int i = 0; i < 2; ++i)
74 if (is_denormal (y[i]))
75 y[i] = 0;
76 }
77
79 {
80 int z = h;
81
82 sample_t r = s * a[0];
83
84 r += a[1] * x[z];
85 r += b[1] * y[z];
86
87 z ^= 1;
88 r += a[2] * x[z];
89 r += b[2] * y[z];
90
91 y[z] = r;
92 x[z] = s;
93
94 h = z;
95
96 return r;
97 }
98
99 /* Following are additional methods for using the biquad to filter an
100 * upsampled signal with 0 padding -- some terms reduce to 0 in this
101 * case */
103 {
104 int z = h;
105
106 sample_t r = 0;
107
108 r += a[1] * x[z];
109 r += b[1] * y[z];
110
111 z ^= 1;
112 r += a[2] * x[z];
113 r += b[2] * y[z];
114
115 y[z] = r;
116 x[z] = 0;
117
118 h = z;
119
120 return r;
121 }
122
124 {
125 int z = h;
126
127 sample_t r = 0;
128
129 r += b[1] * y[z];
130
131 z ^= 1;
132 r += a[2] * x[z];
133 r += b[2] * y[z];
134
135 y[z] = r;
136 x[z] = 0;
137
138 h = z;
139
140 return r;
141 }
142
144 {
145 int z = h;
146
147 sample_t r = 0;
148
149 r += b[1] * y[z];
150
151 z ^= 1;
152 r += b[2] * y[z];
153
154 y[z] = r;
155 x[z] = 0;
156
157 h = z;
158
159 return r;
160 }
161};
162
163} /* namespace DSP */
164
165#endif /* _DSP_BI_QUAD_H_ */
LADSPA_Data sample_t
Definition basics.h:100
bool is_denormal(float &f)
Definition basics.h:150
sample_t process_0_1()
Definition BiQuad.h:102
int h
Definition BiQuad.h:40
BiQuad()
Definition BiQuad.h:43
void reset()
Definition BiQuad.h:62
sample_t process(sample_t s)
Definition BiQuad.h:78
sample_t a[3]
Definition BiQuad.h:37
sample_t y[2]
Definition BiQuad.h:41
void copy(BiQuad &bq)
Definition BiQuad.h:55
sample_t process_0_2()
Definition BiQuad.h:123
sample_t x[2]
Definition BiQuad.h:41
sample_t process_0_3()
Definition BiQuad.h:143
void flush_0()
Definition BiQuad.h:71
sample_t b[3]
Definition BiQuad.h:37
void unity()
Definition BiQuad.h:49
unsigned z
Definition inflate.c:1589
register unsigned i
Definition inflate.c:1575
unsigned s
Definition inflate.c:1555
Definition BiQuad.h:31
int r
Definition crypt.c:458