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. */
5
/* The dac~ and adc~ routines.
11
/* T.Grill - include SIMD functionality */
14
/* ----------------------------- dac~ --------------------------- */
15
static t_class *dac_class;
25
static void *dac_new(t_symbol *s, int argc, t_atom *argv)
27
t_dac *x = (t_dac *)pd_new(dac_class);
28
t_atom defarg[2], *ap;
34
SETFLOAT(&defarg[0], 1);
35
SETFLOAT(&defarg[1], 2);
38
x->x_vec = (t_int *)getbytes(argc * sizeof(*x->x_vec));
39
for (i = 0; i < argc; i++)
40
x->x_vec[i] = atom_getintarg(i, argc, argv);
41
for (i = 1; i < argc; i++)
42
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
47
static void dac_dsp(t_dac *x, t_signal **sp)
51
for (i = x->x_n, ip = x->x_vec, sp2 = sp; i--; ip++, sp2++)
54
if ((*sp2)->s_n != DEFDACBLKSIZE)
55
error("dac~: bad vector size");
56
else if (ch >= 0 && ch < sys_get_outchannels())
57
dsp_add(plus_perform, 4, sys_soundout + DEFDACBLKSIZE*ch,
58
(*sp2)->s_vec, sys_soundout + DEFDACBLKSIZE*ch, DEFDACBLKSIZE);
62
static void dac_free(t_dac *x)
64
freebytes(x->x_vec, x->x_n * sizeof(*x->x_vec));
67
static void dac_setup(void)
69
dac_class = class_new(gensym("dac~"), (t_newmethod)dac_new,
70
(t_method)dac_free, sizeof(t_dac), 0, A_GIMME, 0);
71
CLASS_MAINSIGNALIN(dac_class, t_dac, x_f);
72
class_addmethod(dac_class, (t_method)dac_dsp, gensym("dsp"), A_CANT, 0);
73
class_sethelpsymbol(dac_class, gensym("adc~_dac~"));
76
/* ----------------------------- adc~ --------------------------- */
77
static t_class *adc_class;
86
static void *adc_new(t_symbol *s, int argc, t_atom *argv)
88
t_adc *x = (t_adc *)pd_new(adc_class);
89
t_atom defarg[2], *ap;
95
SETFLOAT(&defarg[0], 1);
96
SETFLOAT(&defarg[1], 2);
99
x->x_vec = (t_int *)getbytes(argc * sizeof(*x->x_vec));
100
for (i = 0; i < argc; i++)
101
x->x_vec[i] = atom_getintarg(i, argc, argv);
102
for (i = 0; i < argc; i++)
103
outlet_new(&x->x_obj, &s_signal);
107
t_int *copy_perform(t_int *w)
109
t_float *in1 = (t_float *)(w[1]);
110
t_float *out = (t_float *)(w[2]);
112
while (n--) *out++ = *in1++;
116
t_int *copy_perf8(t_int *w)
118
t_float *in1 = (t_float *)(w[1]);
119
t_float *out = (t_float *)(w[2]);
122
for (; n; n -= 8, in1 += 8, out += 8)
145
void dsp_add_copy(t_sample *in, t_sample *out, int n)
148
dsp_add(copy_perform, 3, in, out, n);
149
else if(SIMD_CHECK2(n,in,out))
150
dsp_add(copy_perf_simd, 3, in, out, n);
152
dsp_add(copy_perf8, 3, in, out, n);
155
static void adc_dsp(t_adc *x, t_signal **sp)
159
for (i = x->x_n, ip = x->x_vec, sp2 = sp; i--; ip++, sp2++)
162
if ((*sp2)->s_n != DEFDACBLKSIZE)
163
error("adc~: bad vector size");
164
else if (ch >= 0 && ch < sys_get_inchannels())
165
dsp_add_copy(sys_soundin + DEFDACBLKSIZE*ch,
166
(*sp2)->s_vec, DEFDACBLKSIZE);
167
else dsp_add_zero((*sp2)->s_vec, DEFDACBLKSIZE);
171
static void adc_free(t_adc *x)
173
freebytes(x->x_vec, x->x_n * sizeof(*x->x_vec));
176
static void adc_setup(void)
178
adc_class = class_new(gensym("adc~"), (t_newmethod)adc_new,
179
(t_method)adc_free, sizeof(t_adc), 0, A_GIMME, 0);
180
class_addmethod(adc_class, (t_method)adc_dsp, gensym("dsp"), A_CANT, 0);
181
class_sethelpsymbol(adc_class, gensym("adc~_dac~"));
184
void d_dac_setup(void)