diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-07-03 22:16:11 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-07-03 22:16:11 +0000 |
commit | 0d4560cb0305029fa5f0739670286176ab47cb65 (patch) | |
tree | 9899f4324664a77e6a5884fdd1541818a28a2172 /apps/plugins/pdbox/PDa/extra/notch.c | |
parent | eabeb928ddfdbe5fc6379efb87d9522803310649 (diff) | |
download | rockbox-0d4560cb0305029fa5f0739670286176ab47cb65.tar.gz rockbox-0d4560cb0305029fa5f0739670286176ab47cb65.zip |
Accept FS #10244 by Wincent Balin: more pdbox work done for GSoC; also some keyword and line-ending fixes by me
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21626 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/notch.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/notch.c | 176 |
1 files changed, 92 insertions, 84 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/notch.c b/apps/plugins/pdbox/PDa/extra/notch.c index 0ab4332166..44f029988c 100644 --- a/apps/plugins/pdbox/PDa/extra/notch.c +++ b/apps/plugins/pdbox/PDa/extra/notch.c | |||
@@ -1,85 +1,93 @@ | |||
1 | /* (C) Guenter Geiger <geiger@epy.co.at> */ | 1 | /* (C) Guenter Geiger <geiger@epy.co.at> */ |
2 | 2 | ||
3 | 3 | ||
4 | /* | 4 | /* |
5 | 5 | ||
6 | These filter coefficients computations are taken from | 6 | These filter coefficients computations are taken from |
7 | http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt | 7 | http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt |
8 | 8 | ||
9 | written by Robert Bristow-Johnson | 9 | written by Robert Bristow-Johnson |
10 | 10 | ||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include "m_pd.h" | 13 | #ifdef ROCKBOX |
14 | #ifdef NT | 14 | #include "plugin.h" |
15 | #pragma warning( disable : 4244 ) | 15 | #include "pdbox.h" |
16 | #pragma warning( disable : 4305 ) | 16 | #include "m_pd.h" |
17 | #endif | 17 | #include "math.h" |
18 | #include <math.h> | 18 | #include "filters.h" |
19 | #include "filters.h" | 19 | #else /* ROCKBOX */ |
20 | 20 | #include "m_pd.h" | |
21 | 21 | #ifdef NT | |
22 | 22 | #pragma warning( disable : 4244 ) | |
23 | /* ------------------- notch ----------------------------*/ | 23 | #pragma warning( disable : 4305 ) |
24 | 24 | #endif | |
25 | static t_class *notch_class; | 25 | #include <math.h> |
26 | 26 | #include "filters.h" | |
27 | void notch_bang(t_rbjfilter *x) | 27 | #endif /* ROCKBOX */ |
28 | { | 28 | |
29 | t_atom at[5]; | 29 | |
30 | t_float omega = e_omega(x->x_freq,x->x_rate); | 30 | |
31 | t_float alpha = e_alpha(x->x_bw* 0.01,omega); | 31 | /* ------------------- notch ----------------------------*/ |
32 | t_float b1 = -2.*cos(omega); | 32 | |
33 | t_float b0 = 1; | 33 | static t_class *notch_class; |
34 | t_float b2 = b0; | 34 | |
35 | t_float a0 = 1 + alpha; | 35 | void notch_bang(t_rbjfilter *x) |
36 | t_float a1 = -2.*cos(omega); | 36 | { |
37 | t_float a2 = 1 - alpha; | 37 | t_atom at[5]; |
38 | 38 | t_float omega = e_omega(x->x_freq,x->x_rate); | |
39 | /* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */ | 39 | t_float alpha = e_alpha(x->x_bw* 0.01,omega); |
40 | 40 | t_float b1 = -2.*cos(omega); | |
41 | if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) { | 41 | t_float b0 = 1; |
42 | post("notch: filter unstable -> resetting"); | 42 | t_float b2 = b0; |
43 | a0=1.;a1=0.;a2=0.; | 43 | t_float a0 = 1 + alpha; |
44 | b0=1.;b1=0.;b2=0.; | 44 | t_float a1 = -2.*cos(omega); |
45 | } | 45 | t_float a2 = 1 - alpha; |
46 | 46 | ||
47 | SETFLOAT(at,-a1/a0); | 47 | /* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */ |
48 | SETFLOAT(at+1,-a2/a0); | 48 | |
49 | SETFLOAT(at+2,b0/a0); | 49 | if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) { |
50 | SETFLOAT(at+3,b1/a0); | 50 | post("notch: filter unstable -> resetting"); |
51 | SETFLOAT(at+4,b2/a0); | 51 | a0=1.;a1=0.;a2=0.; |
52 | 52 | b0=1.;b1=0.;b2=0.; | |
53 | outlet_list(x->x_obj.ob_outlet,&s_list,5,at); | 53 | } |
54 | } | 54 | |
55 | 55 | SETFLOAT(at,-a1/a0); | |
56 | 56 | SETFLOAT(at+1,-a2/a0); | |
57 | void notch_float(t_rbjfilter *x,t_floatarg f) | 57 | SETFLOAT(at+2,b0/a0); |
58 | { | 58 | SETFLOAT(at+3,b1/a0); |
59 | x->x_freq = f; | 59 | SETFLOAT(at+4,b2/a0); |
60 | notch_bang(x); | 60 | |
61 | } | 61 | outlet_list(x->x_obj.ob_outlet,&s_list,5,at); |
62 | 62 | } | |
63 | 63 | ||
64 | static void *notch_new(t_floatarg f,t_floatarg bw) | 64 | |
65 | { | 65 | void notch_float(t_rbjfilter *x,t_floatarg f) |
66 | t_rbjfilter *x = (t_rbjfilter *)pd_new(notch_class); | 66 | { |
67 | 67 | x->x_freq = f; | |
68 | x->x_rate = 44100.0; | 68 | notch_bang(x); |
69 | outlet_new(&x->x_obj,&s_float); | 69 | } |
70 | /* floatinlet_new(&x->x_obj, &x->x_gain); */ | 70 | |
71 | floatinlet_new(&x->x_obj, &x->x_bw); | 71 | |
72 | if (f > 0.) x->x_freq = f; | 72 | static void *notch_new(t_floatarg f,t_floatarg bw) |
73 | if (bw > 0.) x->x_bw = bw; | 73 | { |
74 | return (x); | 74 | t_rbjfilter *x = (t_rbjfilter *)pd_new(notch_class); |
75 | } | 75 | |
76 | 76 | x->x_rate = 44100.0; | |
77 | 77 | outlet_new(&x->x_obj,&s_float); | |
78 | void notch_setup(void) | 78 | /* floatinlet_new(&x->x_obj, &x->x_gain); */ |
79 | { | 79 | floatinlet_new(&x->x_obj, &x->x_bw); |
80 | notch_class = class_new(gensym("notch"), (t_newmethod)notch_new, 0, | 80 | if (f > 0.) x->x_freq = f; |
81 | sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0); | 81 | if (bw > 0.) x->x_bw = bw; |
82 | class_addbang(notch_class,notch_bang); | 82 | return (x); |
83 | class_addfloat(notch_class,notch_float); | 83 | } |
84 | } | 84 | |
85 | |||
86 | void notch_setup(void) | ||
87 | { | ||
88 | notch_class = class_new(gensym("notch"), (t_newmethod)notch_new, 0, | ||
89 | sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0); | ||
90 | class_addbang(notch_class,notch_bang); | ||
91 | class_addfloat(notch_class,notch_float); | ||
92 | } | ||
85 | 93 | ||