diff options
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/highshelf.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/highshelf.c | 186 |
1 files changed, 97 insertions, 89 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/highshelf.c b/apps/plugins/pdbox/PDa/extra/highshelf.c index 74db29178a..b058a2a2e6 100644 --- a/apps/plugins/pdbox/PDa/extra/highshelf.c +++ b/apps/plugins/pdbox/PDa/extra/highshelf.c | |||
@@ -1,90 +1,98 @@ | |||
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 | /* ------------------- highshelf ----------------------------*/ | 22 | #pragma warning( disable : 4244 ) |
23 | 23 | #pragma warning( disable : 4305 ) | |
24 | static t_class *highshelf_class; | 24 | #endif |
25 | 25 | #include <math.h> | |
26 | void highshelf_bang(t_rbjfilter *x) | 26 | #include "filters.h" |
27 | { | 27 | #endif /* ROCKBOX */ |
28 | t_atom at[5]; | 28 | |
29 | t_float omega = e_omega(x->x_freq,x->x_rate); | 29 | |
30 | t_float A = e_A(x->x_gain); | 30 | /* ------------------- highshelf ----------------------------*/ |
31 | t_float cs = cos(omega); | 31 | |
32 | t_float sn = sin(omega); | 32 | static t_class *highshelf_class; |
33 | t_float beta = e_beta(A,x->x_bw* 0.01); | 33 | |
34 | 34 | void highshelf_bang(t_rbjfilter *x) | |
35 | t_float b0 = A*((A+1) + (A-1)*cs + beta*sn); | 35 | { |
36 | t_float b1 =-2.*A*((A-1) + (A+1)*cs); | 36 | t_atom at[5]; |
37 | t_float b2 = A*((A+1) + (A-1)*cs - beta*sn); | 37 | t_float omega = e_omega(x->x_freq,x->x_rate); |
38 | t_float a0 = ((A+1) - (A-1)*cs + beta*sn); | 38 | t_float A = e_A(x->x_gain); |
39 | t_float a1 = 2.*((A-1) - (A+1)*cs); | 39 | t_float cs = cos(omega); |
40 | t_float a2 = ((A+1) - (A-1)*cs - beta*sn); | 40 | t_float sn = sin(omega); |
41 | 41 | t_float beta = e_beta(A,x->x_bw* 0.01); | |
42 | /* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw);*/ | 42 | |
43 | 43 | t_float b0 = A*((A+1) + (A-1)*cs + beta*sn); | |
44 | if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) { | 44 | t_float b1 =-2.*A*((A-1) + (A+1)*cs); |
45 | post("highshelf: filter unstable -> resetting"); | 45 | t_float b2 = A*((A+1) + (A-1)*cs - beta*sn); |
46 | a0=1.;a1=0.;a2=0.; | 46 | t_float a0 = ((A+1) - (A-1)*cs + beta*sn); |
47 | b0=1.;b1=0.;b2=0.; | 47 | t_float a1 = 2.*((A-1) - (A+1)*cs); |
48 | } | 48 | t_float a2 = ((A+1) - (A-1)*cs - beta*sn); |
49 | 49 | ||
50 | SETFLOAT(at,-a1/a0); | 50 | /* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw);*/ |
51 | SETFLOAT(at+1,-a2/a0); | 51 | |
52 | SETFLOAT(at+2,b0/a0); | 52 | if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) { |
53 | SETFLOAT(at+3,b1/a0); | 53 | post("highshelf: filter unstable -> resetting"); |
54 | SETFLOAT(at+4,b2/a0); | 54 | a0=1.;a1=0.;a2=0.; |
55 | 55 | b0=1.;b1=0.;b2=0.; | |
56 | outlet_list(x->x_obj.ob_outlet,&s_list,5,at); | 56 | } |
57 | } | 57 | |
58 | 58 | SETFLOAT(at,-a1/a0); | |
59 | 59 | SETFLOAT(at+1,-a2/a0); | |
60 | void highshelf_float(t_rbjfilter *x,t_floatarg f) | 60 | SETFLOAT(at+2,b0/a0); |
61 | { | 61 | SETFLOAT(at+3,b1/a0); |
62 | x->x_freq = f; | 62 | SETFLOAT(at+4,b2/a0); |
63 | highshelf_bang(x); | 63 | |
64 | } | 64 | outlet_list(x->x_obj.ob_outlet,&s_list,5,at); |
65 | 65 | } | |
66 | 66 | ||
67 | static void *highshelf_new(t_floatarg f,t_floatarg g,t_floatarg bw) | 67 | |
68 | { | 68 | void highshelf_float(t_rbjfilter *x,t_floatarg f) |
69 | t_rbjfilter *x = (t_rbjfilter *)pd_new(highshelf_class); | 69 | { |
70 | 70 | x->x_freq = f; | |
71 | x->x_rate = 44100.0; | 71 | highshelf_bang(x); |
72 | outlet_new(&x->x_obj,&s_float); | 72 | } |
73 | floatinlet_new(&x->x_obj, &x->x_gain); | 73 | |
74 | floatinlet_new(&x->x_obj, &x->x_bw); | 74 | |
75 | if (f > 0.) x->x_freq = f; | 75 | static void *highshelf_new(t_floatarg f,t_floatarg g,t_floatarg bw) |
76 | if (bw > 0.) x->x_bw = bw; | 76 | { |
77 | if (g != 0.) x->x_gain = g; | 77 | t_rbjfilter *x = (t_rbjfilter *)pd_new(highshelf_class); |
78 | return (x); | 78 | |
79 | } | 79 | x->x_rate = 44100.0; |
80 | 80 | outlet_new(&x->x_obj,&s_float); | |
81 | 81 | floatinlet_new(&x->x_obj, &x->x_gain); | |
82 | void highshelf_setup(void) | 82 | floatinlet_new(&x->x_obj, &x->x_bw); |
83 | { | 83 | if (f > 0.) x->x_freq = f; |
84 | highshelf_class = class_new(gensym("highshelf"), (t_newmethod)highshelf_new, 0, | 84 | if (bw > 0.) x->x_bw = bw; |
85 | sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0); | 85 | if (g != 0.) x->x_gain = g; |
86 | class_addbang(highshelf_class,highshelf_bang); | 86 | return (x); |
87 | class_addfloat(highshelf_class,highshelf_float); | 87 | } |
88 | } | 88 | |
89 | 89 | ||
90 | void highshelf_setup(void) | ||
91 | { | ||
92 | highshelf_class = class_new(gensym("highshelf"), (t_newmethod)highshelf_new, 0, | ||
93 | sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0); | ||
94 | class_addbang(highshelf_class,highshelf_bang); | ||
95 | class_addfloat(highshelf_class,highshelf_float); | ||
96 | } | ||
97 | |||
90 | 98 | ||