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