1 /*
2     Copyright (C) 2004-2006 Fons Adriaensen <fons@kokkinizita.net>
3 
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18 
19 
20 #ifndef __FILTER1_H
21 #define __FILTER1_H
22 
23 
24 /* ---------------------------------------------------------------
25 
26 Lowpass1
27 
28 First order lowpass, -3dB at f3dB.
29 
30 --------------------------------------------------------------- */
31 
32 class Lowpass1
33 {
34 public:
35 
Lowpass1(void)36     Lowpass1 (void) : _a (0), _z (0) {}
~Lowpass1(void)37     ~Lowpass1 (void) {}
38 
39     void init (float fsam, float f3db);
reset(void)40     void reset (void) { _z = 0; }
process(float x)41     float process (float x)
42     {
43         float d;
44         d = _a * (x - _z);
45         x  = _z + d;
46         _z =  x + d + 1e-20f;
47         return x;
48     }
49 
50     float    _a;
51     float    _z;
52 };
53 
54 
55 /* ---------------------------------------------------------------
56 
57 Allpass1
58 
59 First order allpass having 0, 90, 180 degrees phase shift at
60 resp. LF, fmid, HF.
61 
62 --------------------------------------------------------------- */
63 
64 class Allpass1
65 {
66 public:
67 
Allpass1(void)68     Allpass1 (void) : _d (0), _z (0) {}
~Allpass1(void)69     ~Allpass1 (void) {}
70 
71     void init (float fsam, float fmid);
reset(void)72     void reset (void) { _z = 0; }
process(float x)73     float process (float x)
74     {
75         float y;
76         x =  x - _d * _z;
77         y = _z + _d *  x;
78         _z = x + 1e-20f;
79         return y;
80     }
81 
82     float    _d;
83     float    _z;
84 };
85 
86 
87 /* ---------------------------------------------------------------
88 
89 Pcshelf1
90 
91 First order shelf filter having the same phase response as a
92 first order allpass set for 90 degrees at fmid.
93 Useful for phase aligned shelfs for Ambisonics decoders etc.
94 See shelf1-plot.cc for tests.
95 
96 --------------------------------------------------------------- */
97 
98 class Pcshelf1
99 {
100 public:
101 
Pcshelf1(void)102     Pcshelf1 (void) : _d1 (0), _d2 (0), _g (0), _z (0) {}
~Pcshelf1(void)103     ~Pcshelf1 (void) {}
104 
105     void init (float fsam, float fmid, float glf, float ghf);
reset(void)106     void reset (void) { _z = 0; }
process(float x)107     float process (float x)
108     {
109  	float y;
110         x =  x - _d2 * _z;
111         y = _z + _d1 *  x;
112         _z = x + 1e-20f;
113         return _g * y;
114     }
115 
116     float    _d1;
117     float    _d2;
118     float    _g;
119     float    _z;
120 };
121 
122 
123 
124 #endif
125 
126