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/tabread4~.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/tabread4~.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/intern/tabread4~.c | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/tabread4~.c b/apps/plugins/pdbox/PDa/intern/tabread4~.c new file mode 100644 index 0000000000..e530a9fce8 --- /dev/null +++ b/apps/plugins/pdbox/PDa/intern/tabread4~.c | |||
@@ -0,0 +1,210 @@ | |||
1 | |||
2 | #include <m_pd.h> | ||
3 | #include <m_fixed.h> | ||
4 | |||
5 | |||
6 | static t_class *tabread4_tilde_class; | ||
7 | |||
8 | typedef struct _tabread4_tilde | ||
9 | { | ||
10 | t_object x_obj; | ||
11 | int x_npoints; | ||
12 | t_sample *x_vec; | ||
13 | t_symbol *x_arrayname; | ||
14 | float x_f; | ||
15 | } t_tabread4_tilde; | ||
16 | |||
17 | static void *tabread4_tilde_new(t_symbol *s) | ||
18 | { | ||
19 | t_tabread4_tilde *x = (t_tabread4_tilde *)pd_new(tabread4_tilde_class); | ||
20 | x->x_arrayname = s; | ||
21 | x->x_vec = 0; | ||
22 | outlet_new(&x->x_obj, gensym("signal")); | ||
23 | x->x_f = 0; | ||
24 | return (x); | ||
25 | } | ||
26 | |||
27 | static t_int *tabread4_tilde_perform(t_int *w) | ||
28 | { | ||
29 | t_tabread4_tilde *x = (t_tabread4_tilde *)(w[1]); | ||
30 | t_sample *in = (t_sample *)(w[2]); | ||
31 | t_sample *out = (t_sample *)(w[3]); | ||
32 | int n = (int)(w[4]); | ||
33 | int maxindex; | ||
34 | t_sample *buf = x->x_vec, *fp; | ||
35 | int i; | ||
36 | |||
37 | maxindex = x->x_npoints - 3; | ||
38 | |||
39 | if (!buf) goto zero; | ||
40 | |||
41 | for (i = 0; i < n; i++) | ||
42 | { | ||
43 | t_time findex = ((long long) mult((*in++),ftofix(44.1))); | ||
44 | int index = fixtoi(findex); | ||
45 | t_sample frac; | ||
46 | // post("%d: index %d f %lld",index,findex,*in); | ||
47 | |||
48 | if (index < 1) | ||
49 | index = 1, frac = 0; | ||
50 | else if (index > maxindex) | ||
51 | index = maxindex, frac = 1; | ||
52 | else frac = findex - itofix(index); | ||
53 | fp = buf + index; | ||
54 | *out++ = fp[0] + mult(frac,fp[1]-fp[0]); | ||
55 | } | ||
56 | return (w+5); | ||
57 | zero: | ||
58 | while (n--) *out++ = 0; | ||
59 | |||
60 | return (w+5); | ||
61 | } | ||
62 | |||
63 | void tabread4_tilde_set(t_tabread4_tilde *x, t_symbol *s) | ||
64 | { | ||
65 | t_garray *a; | ||
66 | |||
67 | x->x_arrayname = s; | ||
68 | if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) | ||
69 | { | ||
70 | if (*s->s_name) | ||
71 | error("tabread4~: %s: no such array", x->x_arrayname->s_name); | ||
72 | x->x_vec = 0; | ||
73 | } | ||
74 | else if (!garray_getfloatarray(a, &x->x_npoints, &x->x_vec)) | ||
75 | { | ||
76 | error("%s: bad template for tabread4~", x->x_arrayname->s_name); | ||
77 | x->x_vec = 0; | ||
78 | } | ||
79 | else garray_usedindsp(a); | ||
80 | } | ||
81 | |||
82 | static void tabread4_tilde_dsp(t_tabread4_tilde *x, t_signal **sp) | ||
83 | { | ||
84 | tabread4_tilde_set(x, x->x_arrayname); | ||
85 | |||
86 | dsp_add(tabread4_tilde_perform, 4, x, | ||
87 | sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); | ||
88 | |||
89 | } | ||
90 | |||
91 | static void tabread4_tilde_free(t_tabread4_tilde *x) | ||
92 | { | ||
93 | } | ||
94 | |||
95 | void tabread4_tilde_setup(void) | ||
96 | { | ||
97 | tabread4_tilde_class = class_new(gensym("tabread4~"), | ||
98 | (t_newmethod)tabread4_tilde_new, (t_method)tabread4_tilde_free, | ||
99 | sizeof(t_tabread4_tilde), 0, A_DEFSYM, 0); | ||
100 | CLASS_MAINSIGNALIN(tabread4_tilde_class, t_tabread4_tilde, x_f); | ||
101 | class_addmethod(tabread4_tilde_class, (t_method)tabread4_tilde_dsp, | ||
102 | gensym("dsp"), 0); | ||
103 | class_addmethod(tabread4_tilde_class, (t_method)tabread4_tilde_set, | ||
104 | gensym("set"), A_SYMBOL, 0); | ||
105 | } | ||
106 | |||
107 | #include <m_pd.h> | ||
108 | #include <m_fixed.h> | ||
109 | |||
110 | |||
111 | static t_class *tabread4_tilde_class; | ||
112 | |||
113 | typedef struct _tabread4_tilde | ||
114 | { | ||
115 | t_object x_obj; | ||
116 | int x_npoints; | ||
117 | t_sample *x_vec; | ||
118 | t_symbol *x_arrayname; | ||
119 | float x_f; | ||
120 | } t_tabread4_tilde; | ||
121 | |||
122 | static void *tabread4_tilde_new(t_symbol *s) | ||
123 | { | ||
124 | t_tabread4_tilde *x = (t_tabread4_tilde *)pd_new(tabread4_tilde_class); | ||
125 | x->x_arrayname = s; | ||
126 | x->x_vec = 0; | ||
127 | outlet_new(&x->x_obj, gensym("signal")); | ||
128 | x->x_f = 0; | ||
129 | return (x); | ||
130 | } | ||
131 | |||
132 | static t_int *tabread4_tilde_perform(t_int *w) | ||
133 | { | ||
134 | t_tabread4_tilde *x = (t_tabread4_tilde *)(w[1]); | ||
135 | t_sample *in = (t_sample *)(w[2]); | ||
136 | t_sample *out = (t_sample *)(w[3]); | ||
137 | int n = (int)(w[4]); | ||
138 | int maxindex; | ||
139 | t_sample *buf = x->x_vec, *fp; | ||
140 | int i; | ||
141 | |||
142 | maxindex = x->x_npoints - 3; | ||
143 | |||
144 | if (!buf) goto zero; | ||
145 | |||
146 | for (i = 0; i < n; i++) | ||
147 | { | ||
148 | t_time findex = ((long long) mult((*in++),ftofix(44.1))); | ||
149 | int index = fixtoi(findex); | ||
150 | t_sample frac; | ||
151 | // post("%d: index %d f %lld",index,findex,*in); | ||
152 | |||
153 | if (index < 1) | ||
154 | index = 1, frac = 0; | ||
155 | else if (index > maxindex) | ||
156 | index = maxindex, frac = 1; | ||
157 | else frac = findex - itofix(index); | ||
158 | fp = buf + index; | ||
159 | *out++ = fp[0] + mult(frac,fp[1]-fp[0]); | ||
160 | } | ||
161 | return (w+5); | ||
162 | zero: | ||
163 | while (n--) *out++ = 0; | ||
164 | |||
165 | return (w+5); | ||
166 | } | ||
167 | |||
168 | void tabread4_tilde_set(t_tabread4_tilde *x, t_symbol *s) | ||
169 | { | ||
170 | t_garray *a; | ||
171 | |||
172 | x->x_arrayname = s; | ||
173 | if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) | ||
174 | { | ||
175 | if (*s->s_name) | ||
176 | error("tabread4~: %s: no such array", x->x_arrayname->s_name); | ||
177 | x->x_vec = 0; | ||
178 | } | ||
179 | else if (!garray_getfloatarray(a, &x->x_npoints, &x->x_vec)) | ||
180 | { | ||
181 | error("%s: bad template for tabread4~", x->x_arrayname->s_name); | ||
182 | x->x_vec = 0; | ||
183 | } | ||
184 | else garray_usedindsp(a); | ||
185 | } | ||
186 | |||
187 | static void tabread4_tilde_dsp(t_tabread4_tilde *x, t_signal **sp) | ||
188 | { | ||
189 | tabread4_tilde_set(x, x->x_arrayname); | ||
190 | |||
191 | dsp_add(tabread4_tilde_perform, 4, x, | ||
192 | sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); | ||
193 | |||
194 | } | ||
195 | |||
196 | static void tabread4_tilde_free(t_tabread4_tilde *x) | ||
197 | { | ||
198 | } | ||
199 | |||
200 | void tabread4_tilde_setup(void) | ||
201 | { | ||
202 | tabread4_tilde_class = class_new(gensym("tabread4~"), | ||
203 | (t_newmethod)tabread4_tilde_new, (t_method)tabread4_tilde_free, | ||
204 | sizeof(t_tabread4_tilde), 0, A_DEFSYM, 0); | ||
205 | CLASS_MAINSIGNALIN(tabread4_tilde_class, t_tabread4_tilde, x_f); | ||
206 | class_addmethod(tabread4_tilde_class, (t_method)tabread4_tilde_dsp, | ||
207 | gensym("dsp"), 0); | ||
208 | class_addmethod(tabread4_tilde_class, (t_method)tabread4_tilde_set, | ||
209 | gensym("set"), A_SYMBOL, 0); | ||
210 | } | ||