1
/******************************************************
3
* zexy - implementation file
5
* copyleft (c) IOhannes m zm�lnig
7
* 1999:forum::f�r::uml�ute:2004
9
* institute of electronic music and acoustics (iem)
11
******************************************************
13
* license: GNU General Public License v.2
15
******************************************************/
19
/* ------------------------------------------------------------------------------ */
21
/* demux~ : demultiplex a signal to a specified output */
23
static t_class *demux_class;
25
typedef struct _demux {
35
static void demux_output(t_demux *x, t_floatarg f)
37
if ((f>=0)&&(f<x->n_out)){
40
error("demultiplex: %d is channel out of range (0..%d)", (int)f, x->n_out);
44
static t_int *demux_perform(t_int *w)
46
t_demux *x = (t_demux *)(w[1]);
47
t_sample *in = (t_sample *)(w[2]);
54
t_sample*out=x->out[channel];
56
if(x->output==channel){
57
while(n--)*out++=*in++;
64
static void demux_dsp(t_demux *x, t_signal **sp)
67
t_sample **dummy=x->out;
68
while(n--)*dummy++=sp[x->n_out-n]->s_vec;
69
dsp_add(demux_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
73
static void demux_helper(void)
75
post("\n%c demux~\t:: demultiplex a signal to one of various outlets", HEARTSYMBOL);
76
post("<#out>\t : the outlet-number (counting from 0) to witch the inlet is routed"
77
"'help'\t : view this");
78
post("creation : \"demux~ [arg1 [arg2...]]\"\t: the number of arguments equals the number of outlets\n");
81
static void demux_free(t_demux *x)
83
freebytes(x->out, x->n_out * sizeof(t_sample *));
86
static void *demux_new(t_symbol *s, int argc, t_atom *argv)
88
t_demux *x = (t_demux *)pd_new(demux_class);
97
while(argc--)outlet_new(&x->x_obj, gensym("signal"));
99
x->out = (t_sample **)getbytes(x->n_out * sizeof(t_sample *));
101
while(i--)x->out[i]=0;
106
void demultiplex_tilde_setup(void)
108
demux_class = class_new(gensym("demultiplex~"), (t_newmethod)demux_new, (t_method)demux_free, sizeof(t_demux), 0, A_GIMME, 0);
109
class_addcreator((t_newmethod)demux_new, gensym("demux~"), A_GIMME, 0);
111
class_addfloat(demux_class, demux_output);
112
class_addmethod(demux_class, (t_method)demux_dsp, gensym("dsp"), 0);
113
class_addmethod(demux_class, nullfn, gensym("signal"), 0);
115
class_addmethod(demux_class, (t_method)demux_helper, gensym("help"), 0);
117
zexy_register("demultiplex~");
119
void demux_tilde_setup(void)
121
demultiplex_tilde_setup();