diff options
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/d_dac.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/src/d_dac.c | 368 |
1 files changed, 368 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/src/d_dac.c b/apps/plugins/pdbox/PDa/src/d_dac.c new file mode 100644 index 0000000000..ce7c7127f0 --- /dev/null +++ b/apps/plugins/pdbox/PDa/src/d_dac.c | |||
@@ -0,0 +1,368 @@ | |||
1 | /* Copyright (c) 1997-1999 Miller Puckette. | ||
2 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL | ||
3 | * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | ||
4 | |||
5 | /* The dac~ and adc~ routines. | ||
6 | */ | ||
7 | |||
8 | #include "m_pd.h" | ||
9 | #include "s_stuff.h" | ||
10 | |||
11 | /* ----------------------------- dac~ --------------------------- */ | ||
12 | static t_class *dac_class; | ||
13 | |||
14 | typedef struct _dac | ||
15 | { | ||
16 | t_object x_obj; | ||
17 | t_int x_n; | ||
18 | t_int *x_vec; | ||
19 | float x_f; | ||
20 | } t_dac; | ||
21 | |||
22 | static void *dac_new(t_symbol *s, int argc, t_atom *argv) | ||
23 | { | ||
24 | t_dac *x = (t_dac *)pd_new(dac_class); | ||
25 | t_atom defarg[2], *ap; | ||
26 | int i; | ||
27 | if (!argc) | ||
28 | { | ||
29 | argv = defarg; | ||
30 | argc = 2; | ||
31 | SETFLOAT(&defarg[0], 1); | ||
32 | SETFLOAT(&defarg[1], 2); | ||
33 | } | ||
34 | x->x_n = argc; | ||
35 | x->x_vec = (t_int *)getbytes(argc * sizeof(*x->x_vec)); | ||
36 | for (i = 0; i < argc; i++) | ||
37 | x->x_vec[i] = atom_getintarg(i, argc, argv); | ||
38 | for (i = 1; i < argc; i++) | ||
39 | inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); | ||
40 | x->x_f = 0; | ||
41 | return (x); | ||
42 | } | ||
43 | |||
44 | static void dac_dsp(t_dac *x, t_signal **sp) | ||
45 | { | ||
46 | t_int i, *ip; | ||
47 | t_signal **sp2; | ||
48 | for (i = x->x_n, ip = x->x_vec, sp2 = sp; i--; ip++, sp2++) | ||
49 | { | ||
50 | int ch = *ip - 1; | ||
51 | if ((*sp2)->s_n != DEFDACBLKSIZE) | ||
52 | error("dac~: bad vector size"); | ||
53 | else if (ch >= 0 && ch < sys_get_outchannels()) | ||
54 | dsp_add(plus_perform, 4, sys_soundout + DEFDACBLKSIZE*ch, | ||
55 | (*sp2)->s_vec, sys_soundout + DEFDACBLKSIZE*ch, DEFDACBLKSIZE); | ||
56 | } | ||
57 | } | ||
58 | |||
59 | static void dac_free(t_dac *x) | ||
60 | { | ||
61 | freebytes(x->x_vec, x->x_n * sizeof(*x->x_vec)); | ||
62 | } | ||
63 | |||
64 | static void dac_setup(void) | ||
65 | { | ||
66 | dac_class = class_new(gensym("dac~"), (t_newmethod)dac_new, | ||
67 | (t_method)dac_free, sizeof(t_dac), 0, A_GIMME, 0); | ||
68 | CLASS_MAINSIGNALIN(dac_class, t_dac, x_f); | ||
69 | class_addmethod(dac_class, (t_method)dac_dsp, gensym("dsp"), A_CANT, 0); | ||
70 | class_sethelpsymbol(dac_class, gensym("adc~_dac~")); | ||
71 | } | ||
72 | |||
73 | /* ----------------------------- adc~ --------------------------- */ | ||
74 | static t_class *adc_class; | ||
75 | |||
76 | typedef struct _adc | ||
77 | { | ||
78 | t_object x_obj; | ||
79 | t_int x_n; | ||
80 | t_int *x_vec; | ||
81 | } t_adc; | ||
82 | |||
83 | static void *adc_new(t_symbol *s, int argc, t_atom *argv) | ||
84 | { | ||
85 | t_adc *x = (t_adc *)pd_new(adc_class); | ||
86 | t_atom defarg[2], *ap; | ||
87 | int i; | ||
88 | if (!argc) | ||
89 | { | ||
90 | argv = defarg; | ||
91 | argc = 2; | ||
92 | SETFLOAT(&defarg[0], 1); | ||
93 | SETFLOAT(&defarg[1], 2); | ||
94 | } | ||
95 | x->x_n = argc; | ||
96 | x->x_vec = (t_int *)getbytes(argc * sizeof(*x->x_vec)); | ||
97 | for (i = 0; i < argc; i++) | ||
98 | x->x_vec[i] = atom_getintarg(i, argc, argv); | ||
99 | for (i = 0; i < argc; i++) | ||
100 | outlet_new(&x->x_obj, &s_signal); | ||
101 | return (x); | ||
102 | } | ||
103 | |||
104 | t_int *copy_perform(t_int *w) | ||
105 | { | ||
106 | t_float *in1 = (t_float *)(w[1]); | ||
107 | t_float *out = (t_float *)(w[2]); | ||
108 | int n = (int)(w[3]); | ||
109 | while (n--) *out++ = *in1++; | ||
110 | return (w+4); | ||
111 | } | ||
112 | |||
113 | t_int *copy_perf8(t_int *w) | ||
114 | { | ||
115 | t_float *in1 = (t_float *)(w[1]); | ||
116 | t_float *out = (t_float *)(w[2]); | ||
117 | int n = (int)(w[3]); | ||
118 | |||
119 | for (; n; n -= 8, in1 += 8, out += 8) | ||
120 | { | ||
121 | float f0 = in1[0]; | ||
122 | float f1 = in1[1]; | ||
123 | float f2 = in1[2]; | ||
124 | float f3 = in1[3]; | ||
125 | float f4 = in1[4]; | ||
126 | float f5 = in1[5]; | ||
127 | float f6 = in1[6]; | ||
128 | float f7 = in1[7]; | ||
129 | |||
130 | out[0] = f0; | ||
131 | out[1] = f1; | ||
132 | out[2] = f2; | ||
133 | out[3] = f3; | ||
134 | out[4] = f4; | ||
135 | out[5] = f5; | ||
136 | out[6] = f6; | ||
137 | out[7] = f7; | ||
138 | } | ||
139 | return (w+4); | ||
140 | } | ||
141 | |||
142 | void dsp_add_copy(t_sample *in, t_sample *out, int n) | ||
143 | { | ||
144 | if (n&7) | ||
145 | dsp_add(copy_perform, 3, in, out, n); | ||
146 | else | ||
147 | dsp_add(copy_perf8, 3, in, out, n); | ||
148 | } | ||
149 | |||
150 | static void adc_dsp(t_adc *x, t_signal **sp) | ||
151 | { | ||
152 | t_int i, *ip; | ||
153 | t_signal **sp2; | ||
154 | for (i = x->x_n, ip = x->x_vec, sp2 = sp; i--; ip++, sp2++) | ||
155 | { | ||
156 | int ch = *ip - 1; | ||
157 | if ((*sp2)->s_n != DEFDACBLKSIZE) | ||
158 | error("adc~: bad vector size"); | ||
159 | else if (ch >= 0 && ch < sys_get_inchannels()) | ||
160 | dsp_add_copy(sys_soundin + DEFDACBLKSIZE*ch, | ||
161 | (*sp2)->s_vec, DEFDACBLKSIZE); | ||
162 | else dsp_add_zero((*sp2)->s_vec, DEFDACBLKSIZE); | ||
163 | } | ||
164 | } | ||
165 | |||
166 | static void adc_free(t_adc *x) | ||
167 | { | ||
168 | freebytes(x->x_vec, x->x_n * sizeof(*x->x_vec)); | ||
169 | } | ||
170 | |||
171 | static void adc_setup(void) | ||
172 | { | ||
173 | adc_class = class_new(gensym("adc~"), (t_newmethod)adc_new, | ||
174 | (t_method)adc_free, sizeof(t_adc), 0, A_GIMME, 0); | ||
175 | class_addmethod(adc_class, (t_method)adc_dsp, gensym("dsp"), A_CANT, 0); | ||
176 | class_sethelpsymbol(adc_class, gensym("adc~_dac~")); | ||
177 | } | ||
178 | |||
179 | void d_dac_setup(void) | ||
180 | { | ||
181 | dac_setup(); | ||
182 | adc_setup(); | ||
183 | } | ||
184 | |||
185 | /* Copyright (c) 1997-1999 Miller Puckette. | ||
186 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL | ||
187 | * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | ||
188 | |||
189 | /* The dac~ and adc~ routines. | ||
190 | */ | ||
191 | |||
192 | #include "m_pd.h" | ||
193 | #include "s_stuff.h" | ||
194 | |||
195 | /* ----------------------------- dac~ --------------------------- */ | ||
196 | static t_class *dac_class; | ||
197 | |||
198 | typedef struct _dac | ||
199 | { | ||
200 | t_object x_obj; | ||
201 | t_int x_n; | ||
202 | t_int *x_vec; | ||
203 | float x_f; | ||
204 | } t_dac; | ||
205 | |||
206 | static void *dac_new(t_symbol *s, int argc, t_atom *argv) | ||
207 | { | ||
208 | t_dac *x = (t_dac *)pd_new(dac_class); | ||
209 | t_atom defarg[2], *ap; | ||
210 | int i; | ||
211 | if (!argc) | ||
212 | { | ||
213 | argv = defarg; | ||
214 | argc = 2; | ||
215 | SETFLOAT(&defarg[0], 1); | ||
216 | SETFLOAT(&defarg[1], 2); | ||
217 | } | ||
218 | x->x_n = argc; | ||
219 | x->x_vec = (t_int *)getbytes(argc * sizeof(*x->x_vec)); | ||
220 | for (i = 0; i < argc; i++) | ||
221 | x->x_vec[i] = atom_getintarg(i, argc, argv); | ||
222 | for (i = 1; i < argc; i++) | ||
223 | inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); | ||
224 | x->x_f = 0; | ||
225 | return (x); | ||
226 | } | ||
227 | |||
228 | static void dac_dsp(t_dac *x, t_signal **sp) | ||
229 | { | ||
230 | t_int i, *ip; | ||
231 | t_signal **sp2; | ||
232 | for (i = x->x_n, ip = x->x_vec, sp2 = sp; i--; ip++, sp2++) | ||
233 | { | ||
234 | int ch = *ip - 1; | ||
235 | if ((*sp2)->s_n != DEFDACBLKSIZE) | ||
236 | error("dac~: bad vector size"); | ||
237 | else if (ch >= 0 && ch < sys_get_outchannels()) | ||
238 | dsp_add(plus_perform, 4, sys_soundout + DEFDACBLKSIZE*ch, | ||
239 | (*sp2)->s_vec, sys_soundout + DEFDACBLKSIZE*ch, DEFDACBLKSIZE); | ||
240 | } | ||
241 | } | ||
242 | |||
243 | static void dac_free(t_dac *x) | ||
244 | { | ||
245 | freebytes(x->x_vec, x->x_n * sizeof(*x->x_vec)); | ||
246 | } | ||
247 | |||
248 | static void dac_setup(void) | ||
249 | { | ||
250 | dac_class = class_new(gensym("dac~"), (t_newmethod)dac_new, | ||
251 | (t_method)dac_free, sizeof(t_dac), 0, A_GIMME, 0); | ||
252 | CLASS_MAINSIGNALIN(dac_class, t_dac, x_f); | ||
253 | class_addmethod(dac_class, (t_method)dac_dsp, gensym("dsp"), A_CANT, 0); | ||
254 | class_sethelpsymbol(dac_class, gensym("adc~_dac~")); | ||
255 | } | ||
256 | |||
257 | /* ----------------------------- adc~ --------------------------- */ | ||
258 | static t_class *adc_class; | ||
259 | |||
260 | typedef struct _adc | ||
261 | { | ||
262 | t_object x_obj; | ||
263 | t_int x_n; | ||
264 | t_int *x_vec; | ||
265 | } t_adc; | ||
266 | |||
267 | static void *adc_new(t_symbol *s, int argc, t_atom *argv) | ||
268 | { | ||
269 | t_adc *x = (t_adc *)pd_new(adc_class); | ||
270 | t_atom defarg[2], *ap; | ||
271 | int i; | ||
272 | if (!argc) | ||
273 | { | ||
274 | argv = defarg; | ||
275 | argc = 2; | ||
276 | SETFLOAT(&defarg[0], 1); | ||
277 | SETFLOAT(&defarg[1], 2); | ||
278 | } | ||
279 | x->x_n = argc; | ||
280 | x->x_vec = (t_int *)getbytes(argc * sizeof(*x->x_vec)); | ||
281 | for (i = 0; i < argc; i++) | ||
282 | x->x_vec[i] = atom_getintarg(i, argc, argv); | ||
283 | for (i = 0; i < argc; i++) | ||
284 | outlet_new(&x->x_obj, &s_signal); | ||
285 | return (x); | ||
286 | } | ||
287 | |||
288 | t_int *copy_perform(t_int *w) | ||
289 | { | ||
290 | t_float *in1 = (t_float *)(w[1]); | ||
291 | t_float *out = (t_float *)(w[2]); | ||
292 | int n = (int)(w[3]); | ||
293 | while (n--) *out++ = *in1++; | ||
294 | return (w+4); | ||
295 | } | ||
296 | |||
297 | t_int *copy_perf8(t_int *w) | ||
298 | { | ||
299 | t_float *in1 = (t_float *)(w[1]); | ||
300 | t_float *out = (t_float *)(w[2]); | ||
301 | int n = (int)(w[3]); | ||
302 | |||
303 | for (; n; n -= 8, in1 += 8, out += 8) | ||
304 | { | ||
305 | float f0 = in1[0]; | ||
306 | float f1 = in1[1]; | ||
307 | float f2 = in1[2]; | ||
308 | float f3 = in1[3]; | ||
309 | float f4 = in1[4]; | ||
310 | float f5 = in1[5]; | ||
311 | float f6 = in1[6]; | ||
312 | float f7 = in1[7]; | ||
313 | |||
314 | out[0] = f0; | ||
315 | out[1] = f1; | ||
316 | out[2] = f2; | ||
317 | out[3] = f3; | ||
318 | out[4] = f4; | ||
319 | out[5] = f5; | ||
320 | out[6] = f6; | ||
321 | out[7] = f7; | ||
322 | } | ||
323 | return (w+4); | ||
324 | } | ||
325 | |||
326 | void dsp_add_copy(t_sample *in, t_sample *out, int n) | ||
327 | { | ||
328 | if (n&7) | ||
329 | dsp_add(copy_perform, 3, in, out, n); | ||
330 | else | ||
331 | dsp_add(copy_perf8, 3, in, out, n); | ||
332 | } | ||
333 | |||
334 | static void adc_dsp(t_adc *x, t_signal **sp) | ||
335 | { | ||
336 | t_int i, *ip; | ||
337 | t_signal **sp2; | ||
338 | for (i = x->x_n, ip = x->x_vec, sp2 = sp; i--; ip++, sp2++) | ||
339 | { | ||
340 | int ch = *ip - 1; | ||
341 | if ((*sp2)->s_n != DEFDACBLKSIZE) | ||
342 | error("adc~: bad vector size"); | ||
343 | else if (ch >= 0 && ch < sys_get_inchannels()) | ||
344 | dsp_add_copy(sys_soundin + DEFDACBLKSIZE*ch, | ||
345 | (*sp2)->s_vec, DEFDACBLKSIZE); | ||
346 | else dsp_add_zero((*sp2)->s_vec, DEFDACBLKSIZE); | ||
347 | } | ||
348 | } | ||
349 | |||
350 | static void adc_free(t_adc *x) | ||
351 | { | ||
352 | freebytes(x->x_vec, x->x_n * sizeof(*x->x_vec)); | ||
353 | } | ||
354 | |||
355 | static void adc_setup(void) | ||
356 | { | ||
357 | adc_class = class_new(gensym("adc~"), (t_newmethod)adc_new, | ||
358 | (t_method)adc_free, sizeof(t_adc), 0, A_GIMME, 0); | ||
359 | class_addmethod(adc_class, (t_method)adc_dsp, gensym("dsp"), A_CANT, 0); | ||
360 | class_sethelpsymbol(adc_class, gensym("adc~_dac~")); | ||
361 | } | ||
362 | |||
363 | void d_dac_setup(void) | ||
364 | { | ||
365 | dac_setup(); | ||
366 | adc_setup(); | ||
367 | } | ||
368 | |||