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 #include <stdlib.h>
21 #include <math.h>
22 #include "filter1.h"
23
24
25 #define P2F 6.283185f
26
27
init(float fsam,float f3db)28 void Lowpass1::init (float fsam, float f3db)
29 {
30 float w, c, s, d;
31
32 w = P2F * f3db / fsam;
33 c = cosf (w);
34 s = sinf (w);
35 d = (c < 1e-3f) ? (-0.5f * c) : ((s - 1) / c);
36 _a = 0.5f * (1 + d);
37 }
38
39
init(float fsam,float fmid)40 void Allpass1::init (float fsam, float fmid)
41 {
42 float w, c, s;
43
44 w = P2F * fmid / fsam;
45 c = cosf (w);
46 s = sinf (w);
47 _d = (c < 1e-3f) ? (-0.5f * c) : ((s - 1) / c);
48 }
49
50
init(float fsam,float fmid,float glf,float ghf)51 void Pcshelf1::init (float fsam, float fmid, float glf, float ghf)
52 {
53 float w, c, s, g, v;
54
55 w = P2F * fmid / fsam;
56 c = cosf (w);
57 s = sinf (w);
58 g = -glf / ghf;
59 g = (g - 1) / (g + 1);
60 v = s * sqrt (1 - g * g) - 1;
61 _d1 = (fabs (c - g) < 1e-3f) ? 0 : ((v + c * g) / (c - g));
62 _d2 = (fabs (c + g) < 1e-3f) ? 0 : ((v - c * g) / (c + g));
63 _g = glf * (1 + _d2) / (1 + _d1);
64 }
65
66
67