LMMS
Loading...
Searching...
No Matches
OnePole.h
Go to the documentation of this file.
1/*
2 dsp/OnePole.h
3
4 Copyright 2003-7 Tim Goetze <tim@quitte.de>
5
6 http://quitte.de/dsp/
7
8 one pole (or one zero, or one zero, one pole) hi- and lo-pass filters.
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 _ONE_POLE_H_
29#define _ONE_POLE_H_
30
31namespace DSP {
32
34{
35 public:
37
38 OnePoleLP (double d = 1.)
39 {
40 set (d);
41 y1 = 0.;
42 }
43
44 inline void reset()
45 {
46 y1 = 0.;
47 }
48
49 inline void set_f (double fc)
50 {
51 set (exp (-2 * M_PI * fc));
52 }
53
54 inline void set (double d)
55 {
56 a0 = (sample_t) d;
57 b1 = (sample_t) 1. - d;
58 }
59
61 {
62 return y1 = a0 * x + b1 * y1;
63 }
64
65 inline void decay (double d)
66 {
67 a0 *= d;
68 b1 = 1. - a0;
69 }
70
71 /* clear denormal numbers in history */
72 void flush_0()
73 {
74 if (is_denormal (y1))
75 y1 = 0;
76 }
77};
78
80{
81 public:
83
84 OnePoleHP (double d = 1.)
85 {
86 set (d);
87 x1 = y1 = 0.;
88 }
89
90 void set_f (double f)
91 {
92 set (exp (-2 * M_PI * f));
93 }
94
95 inline void set (double d)
96 {
97 a0 = (sample_t) ((1. + d) / 2.);
98 a1 = (sample_t) ((1. + d) / -2.);
99 b1 = d;
100 }
101
103 {
104 y1 = a0 * x + a1 * x1 + b1 * y1;
105 x1 = x;
106 return y1;
107 }
108
109 void reset()
110 {
111 x1 = y1 = 0;
112 }
113
114 /* clear denormal numbers in history */
115 void flush_0()
116 {
117 if (is_denormal (y1))
118 y1 = 0;
119 }
120};
121
122} /* namespace DSP */
123
124#endif /* _ONE_POLE_H_ */
LADSPA_Data sample_t
Definition basics.h:100
bool is_denormal(float &f)
Definition basics.h:150
void set(double d)
Definition OnePole.h:95
sample_t x1
Definition OnePole.h:82
sample_t b1
Definition OnePole.h:82
sample_t process(sample_t x)
Definition OnePole.h:102
OnePoleHP(double d=1.)
Definition OnePole.h:84
void set_f(double f)
Definition OnePole.h:90
sample_t a0
Definition OnePole.h:82
void reset()
Definition OnePole.h:109
void flush_0()
Definition OnePole.h:115
sample_t y1
Definition OnePole.h:82
sample_t a1
Definition OnePole.h:82
void flush_0()
Definition OnePole.h:72
sample_t b1
Definition OnePole.h:36
sample_t process(sample_t x)
Definition OnePole.h:60
void set_f(double fc)
Definition OnePole.h:49
sample_t a0
Definition OnePole.h:36
void decay(double d)
Definition OnePole.h:65
void reset()
Definition OnePole.h:44
void set(double d)
Definition OnePole.h:54
sample_t y1
Definition OnePole.h:36
OnePoleLP(double d=1.)
Definition OnePole.h:38
#define M_PI
Definition compat.h:149
unsigned d
Definition inflate.c:940
unsigned x[BMAX+1]
Definition inflate.c:1586
unsigned f
Definition inflate.c:1572
Definition BiQuad.h:31