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
******************************************************/
17
/* get the ProbabilityDensityFunction of a signal */
21
/* ------------------------ pdf~ ----------------------------- */
23
static t_class *pdf_class;
34
static void clear_pdfbuf(t_pdf *x)
37
t_float *buf = x->buf;
39
while (n--) *buf++=0.;
42
static void pdf_bang(t_pdf *x)
45
t_float *buf = x->buf, max = 0;
48
while (n--) if (max < *buf++) max = buf[-1];
58
SETFLOAT(a, *buf++*max);
59
SETFLOAT(a+1,x->size-n-1);
60
outlet_list(x->x_obj.ob_outlet, &s_list, 2, (t_atom*)&a);
64
static void pdf_float(t_pdf *x, t_floatarg f)
66
if (f) pdf_bang(x); else clear_pdfbuf(x);
69
static t_int *pdf_perform(t_int *w)
71
t_sample *in = (t_sample *)(w[1]);
72
t_pdf *x = (t_pdf *)(w[2]);
75
t_float *buf = x->buf;
76
t_float halfsize = x->halfsize;
81
int iindex = ((f + 1.0) * halfsize)+0.5;
82
buf[(iindex<0)?0:((iindex>=x->size)?x->size-1:iindex)]+=1.;
87
static void pdf_dsp(t_pdf *x, t_signal **sp)
89
x->halfsize = (x->size - 1) / 2.0;
91
dsp_add(pdf_perform, 3, sp[0]->s_vec, x, sp[0]->s_n);
94
static void *pdf_new(t_floatarg f)
97
t_pdf *x = (t_pdf *)pd_new(pdf_class);
101
x->buf = (t_float *)getbytes(x->size * sizeof(*x->buf));
105
outlet_new(&x->x_obj, &s_list);
110
static void pdf_free(t_pdf *x)
113
freebytes(x->buf, x->size*sizeof(*x->buf));
116
static void pdf_tilde_helper(void)
118
post("\n%c pdf~\t:: get the probability density function of a signal (-1.0 to +1.0)", HEARTSYMBOL);
119
post("'bang'\t : output a list of the probabilities of 'n' function values"
120
"\n'clear'\t : clear the buffer (set all probabilities to zero)"
121
"\n<1/0>\t : short for 'bang' and 'clear'"
122
"\n'help'\t : view this");
123
post("creation :: 'pdf~ [<n>]':: get the pdf for <n> (default: 64) values");
126
void pdf_tilde_setup(void)
128
pdf_class = class_new(gensym("pdf~"), (t_newmethod)pdf_new, (t_method)pdf_free,
129
sizeof(t_pdf), 0, A_DEFFLOAT, 0);
131
class_addmethod(pdf_class, nullfn, gensym("signal"), 0);
132
class_addmethod(pdf_class, (t_method)pdf_dsp, gensym("dsp"), 0);
134
class_addmethod(pdf_class, (t_method)pdf_bang, gensym("bang"), 0);
135
class_addmethod(pdf_class, (t_method)clear_pdfbuf, gensym("clear"), 0);
136
class_addfloat(pdf_class, pdf_float);
138
class_addmethod(pdf_class, (t_method)pdf_tilde_helper, gensym("help"), 0);
139
zexy_register("pdf~");