diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
commit | 513389b4c1bc8afe4b2dc9947c534bfeb105e3da (patch) | |
tree | 10e673b35651ac567fed2eda0c679c7ade64cbc6 /apps/plugins/pdbox/PDa/intern/lop~.c | |
parent | 95fa7f6a2ef466444fbe3fe87efc6d5db6b77b36 (diff) | |
download | rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.gz rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.zip |
Add FS #10214. Initial commit of the original PDa code for the GSoC Pure Data plugin project of Wincent Balin. Stripped some non-sourcefiles and added a rockbox readme that needs a bit more info from Wincent. Is added to CATEGORIES and viewers, but not yet to SUBDIRS (ie doesn't build yet)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21044 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/lop~.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/intern/lop~.c | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/lop~.c b/apps/plugins/pdbox/PDa/intern/lop~.c new file mode 100644 index 0000000000..49a17a7c5f --- /dev/null +++ b/apps/plugins/pdbox/PDa/intern/lop~.c | |||
@@ -0,0 +1,180 @@ | |||
1 | #include <m_pd.h> | ||
2 | #include <m_fixed.h> | ||
3 | |||
4 | typedef struct lopctl | ||
5 | { | ||
6 | t_sample c_x; | ||
7 | t_sample c_coef; | ||
8 | } t_lopctl; | ||
9 | |||
10 | typedef struct siglop | ||
11 | { | ||
12 | t_object x_obj; | ||
13 | float x_sr; | ||
14 | float x_hz; | ||
15 | t_lopctl x_cspace; | ||
16 | t_lopctl *x_ctl; | ||
17 | float x_f; | ||
18 | } t_siglop; | ||
19 | |||
20 | t_class *siglop_class; | ||
21 | |||
22 | static void siglop_ft1(t_siglop *x, t_floatarg f); | ||
23 | |||
24 | static void *siglop_new(t_floatarg f) | ||
25 | { | ||
26 | t_siglop *x = (t_siglop *)pd_new(siglop_class); | ||
27 | inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1")); | ||
28 | outlet_new(&x->x_obj, gensym("signal")); | ||
29 | x->x_sr = 44100; | ||
30 | x->x_ctl = &x->x_cspace; | ||
31 | x->x_cspace.c_x = 0; | ||
32 | siglop_ft1(x, f); | ||
33 | x->x_f = 0; | ||
34 | return (x); | ||
35 | } | ||
36 | |||
37 | static void siglop_ft1(t_siglop *x, t_floatarg f) | ||
38 | { | ||
39 | t_float coeff; | ||
40 | if (f < 0.001) f = 10; | ||
41 | x->x_hz = f; | ||
42 | coeff = f * (2 * 3.14159) / x->x_sr; | ||
43 | if (coeff > 1) coeff = 1; | ||
44 | x->x_ctl->c_coef = ftofix(coeff); | ||
45 | } | ||
46 | |||
47 | static void siglop_clear(t_siglop *x, t_floatarg q) | ||
48 | { | ||
49 | x->x_cspace.c_x = 0; | ||
50 | } | ||
51 | |||
52 | |||
53 | static t_int *siglop_perform(t_int *w) | ||
54 | { | ||
55 | t_sample *in = (t_sample *)(w[1]); | ||
56 | t_sample *out = (t_sample *)(w[2]); | ||
57 | t_lopctl *c = (t_lopctl *)(w[3]); | ||
58 | int n = (t_int)(w[4]); | ||
59 | int i; | ||
60 | t_sample last = c->c_x; | ||
61 | t_sample coef = c->c_coef; | ||
62 | t_sample feedback = ftofix(1) - coef; | ||
63 | for (i = 0; i < n; i++) | ||
64 | last = *out++ = mult(coef, *in++) + mult(feedback,last); | ||
65 | if (PD_BADFLOAT(last)) | ||
66 | last = 0; | ||
67 | c->c_x = last; | ||
68 | return (w+5); | ||
69 | } | ||
70 | |||
71 | static void siglop_dsp(t_siglop *x, t_signal **sp) | ||
72 | { | ||
73 | x->x_sr = sp[0]->s_sr; | ||
74 | siglop_ft1(x, x->x_hz); | ||
75 | dsp_add(siglop_perform, 4, | ||
76 | sp[0]->s_vec, sp[1]->s_vec, | ||
77 | x->x_ctl, sp[0]->s_n); | ||
78 | |||
79 | } | ||
80 | |||
81 | void lop_tilde_setup(void) | ||
82 | { | ||
83 | siglop_class = class_new(gensym("lop~"), (t_newmethod)siglop_new, 0, | ||
84 | sizeof(t_siglop), 0, A_DEFFLOAT, 0); | ||
85 | CLASS_MAINSIGNALIN(siglop_class, t_siglop, x_f); | ||
86 | class_addmethod(siglop_class, (t_method)siglop_dsp, gensym("dsp"), 0); | ||
87 | class_addmethod(siglop_class, (t_method)siglop_ft1, | ||
88 | gensym("ft1"), A_FLOAT, 0); | ||
89 | class_addmethod(siglop_class, (t_method)siglop_clear, gensym("clear"), 0); | ||
90 | } | ||
91 | #include <m_pd.h> | ||
92 | #include <m_fixed.h> | ||
93 | |||
94 | typedef struct lopctl | ||
95 | { | ||
96 | t_sample c_x; | ||
97 | t_sample c_coef; | ||
98 | } t_lopctl; | ||
99 | |||
100 | typedef struct siglop | ||
101 | { | ||
102 | t_object x_obj; | ||
103 | float x_sr; | ||
104 | float x_hz; | ||
105 | t_lopctl x_cspace; | ||
106 | t_lopctl *x_ctl; | ||
107 | float x_f; | ||
108 | } t_siglop; | ||
109 | |||
110 | t_class *siglop_class; | ||
111 | |||
112 | static void siglop_ft1(t_siglop *x, t_floatarg f); | ||
113 | |||
114 | static void *siglop_new(t_floatarg f) | ||
115 | { | ||
116 | t_siglop *x = (t_siglop *)pd_new(siglop_class); | ||
117 | inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1")); | ||
118 | outlet_new(&x->x_obj, gensym("signal")); | ||
119 | x->x_sr = 44100; | ||
120 | x->x_ctl = &x->x_cspace; | ||
121 | x->x_cspace.c_x = 0; | ||
122 | siglop_ft1(x, f); | ||
123 | x->x_f = 0; | ||
124 | return (x); | ||
125 | } | ||
126 | |||
127 | static void siglop_ft1(t_siglop *x, t_floatarg f) | ||
128 | { | ||
129 | t_float coeff; | ||
130 | if (f < 0.001) f = 10; | ||
131 | x->x_hz = f; | ||
132 | coeff = f * (2 * 3.14159) / x->x_sr; | ||
133 | if (coeff > 1) coeff = 1; | ||
134 | x->x_ctl->c_coef = ftofix(coeff); | ||
135 | } | ||
136 | |||
137 | static void siglop_clear(t_siglop *x, t_floatarg q) | ||
138 | { | ||
139 | x->x_cspace.c_x = 0; | ||
140 | } | ||
141 | |||
142 | |||
143 | static t_int *siglop_perform(t_int *w) | ||
144 | { | ||
145 | t_sample *in = (t_sample *)(w[1]); | ||
146 | t_sample *out = (t_sample *)(w[2]); | ||
147 | t_lopctl *c = (t_lopctl *)(w[3]); | ||
148 | int n = (t_int)(w[4]); | ||
149 | int i; | ||
150 | t_sample last = c->c_x; | ||
151 | t_sample coef = c->c_coef; | ||
152 | t_sample feedback = ftofix(1) - coef; | ||
153 | for (i = 0; i < n; i++) | ||
154 | last = *out++ = mult(coef, *in++) + mult(feedback,last); | ||
155 | if (PD_BADFLOAT(last)) | ||
156 | last = 0; | ||
157 | c->c_x = last; | ||
158 | return (w+5); | ||
159 | } | ||
160 | |||
161 | static void siglop_dsp(t_siglop *x, t_signal **sp) | ||
162 | { | ||
163 | x->x_sr = sp[0]->s_sr; | ||
164 | siglop_ft1(x, x->x_hz); | ||
165 | dsp_add(siglop_perform, 4, | ||
166 | sp[0]->s_vec, sp[1]->s_vec, | ||
167 | x->x_ctl, sp[0]->s_n); | ||
168 | |||
169 | } | ||
170 | |||
171 | void lop_tilde_setup(void) | ||
172 | { | ||
173 | siglop_class = class_new(gensym("lop~"), (t_newmethod)siglop_new, 0, | ||
174 | sizeof(t_siglop), 0, A_DEFFLOAT, 0); | ||
175 | CLASS_MAINSIGNALIN(siglop_class, t_siglop, x_f); | ||
176 | class_addmethod(siglop_class, (t_method)siglop_dsp, gensym("dsp"), 0); | ||
177 | class_addmethod(siglop_class, (t_method)siglop_ft1, | ||
178 | gensym("ft1"), A_FLOAT, 0); | ||
179 | class_addmethod(siglop_class, (t_method)siglop_clear, gensym("clear"), 0); | ||
180 | } | ||