1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/* Copyright (c) 1997-1999 Miller Puckette.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
/* The dac~ and adc~ routines.
*/
#include "m_pd.h"
#include "s_stuff.h"
static t_class *adc_class;
typedef struct _adc
{
t_object x_obj;
t_int x_n;
t_int *x_vec;
} t_adc;
static void *adc_new(t_symbol *s, int argc, t_atom *argv)
{
t_adc *x = (t_adc *)pd_new(adc_class);
t_atom defarg[2], *ap;
int i;
if (!argc)
{
argv = defarg;
argc = 2;
SETFLOAT(&defarg[0], 1);
SETFLOAT(&defarg[1], 2);
}
x->x_n = argc;
x->x_vec = (t_int *)getbytes(argc * sizeof(*x->x_vec));
for (i = 0; i < argc; i++)
x->x_vec[i] = atom_getintarg(i, argc, argv);
for (i = 0; i < argc; i++)
outlet_new(&x->x_obj, &s_signal);
return (x);
}
static void adc_dsp(t_adc *x, t_signal **sp)
{
t_int i, *ip;
t_signal **sp2;
for (i = x->x_n, ip = x->x_vec, sp2 = sp; i--; ip++, sp2++)
{
int ch = *ip - 1;
if ((*sp2)->s_n != DEFDACBLKSIZE)
error("adc~: bad vector size");
else if (ch >= 0 && ch < sys_get_inchannels())
dsp_add_copy(sys_soundin + DEFDACBLKSIZE*ch,
(*sp2)->s_vec, DEFDACBLKSIZE);
else dsp_add_zero((*sp2)->s_vec, DEFDACBLKSIZE);
}
}
static void adc_free(t_adc *x)
{
freebytes(x->x_vec, x->x_n * sizeof(*x->x_vec));
}
void adc_tilde_setup(void)
{
adc_class = class_new(gensym("adc~"), (t_newmethod)adc_new,
(t_method)adc_free, sizeof(t_adc), 0, A_GIMME, 0);
class_addmethod(adc_class, (t_method)adc_dsp, gensym("dsp"), A_CANT, 0);
class_sethelpsymbol(adc_class, gensym("adc~_dac~"));
}
|