From 5e869f7a0cef88be3b03272303a6084b8bd1a7e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Tue, 30 Oct 2007 09:21:52 +0000 Subject: use t_float and t_sample when possible svn path=/trunk/externals/zexy/; revision=8907 --- src/step~.c | 122 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 61 insertions(+), 61 deletions(-) (limited to 'src/step~.c') diff --git a/src/step~.c b/src/step~.c index fbc15d2..9b6fed1 100644 --- a/src/step~.c +++ b/src/step~.c @@ -14,15 +14,15 @@ ******************************************************/ /* -step~ : will make a unity step at a desired point in the signal-vector; the second input specifies a - length: after the so-specified time has elapsed, the step will toggle back to the previous - value; - the length can be passed as an argument when creating the object - with length==1 you might do the dirac~ thing a little bit more complicated - with length==0 the output just toggles between 0 and 1 every time you bang the object - -NOTE : the inlets do NOT specify any times but sample-NUMBERS; there are 64 samples in a signal-vector, - each "lasting" for 1/44100 secs. + step~ : will make a unity step at a desired point in the signal-vector; the second input specifies a + length: after the so-specified time has elapsed, the step will toggle back to the previous + value; + the length can be passed as an argument when creating the object + with length==1 you might do the dirac~ thing a little bit more complicated + with length==0 the output just toggles between 0 and 1 every time you bang the object + + NOTE : the inlets do NOT specify any times but sample-NUMBERS; there are 64 samples in a signal-vector, + each "lasting" for 1/44100 secs. */ #include "zexy.h" @@ -33,108 +33,108 @@ static t_class *step_class; typedef struct _step { - t_object x_obj; - int position; - int length; + t_object x_obj; + int position; + int length; - int toggle; + int toggle; - int wait4start; - int wait4stop; + int wait4start; + int wait4stop; } t_step; static void step_bang(t_step *x) { - x->wait4stop = x->length + (x->wait4start = x->position); + x->wait4stop = x->length + (x->wait4start = x->position); } static void step_float(t_step *x, t_float where) { - x->wait4stop = x->length + - (x->wait4start = - (x->position = (where>0)*where) - ); + x->wait4stop = x->length + + (x->wait4start = + (x->position = (where>0)*where) + ); } static void step_setlength(t_step *x, t_float arg) { - x->length = 1 + (arg>0)*arg; + x->length = 1 + (arg>0)*arg; } static t_int *step_perform(t_int *w) { - t_step *x = (t_step *)(w[1]); - t_float *out = (t_float *)(w[2]); - int n = (int)(w[3]); + t_step *x = (t_step *)(w[1]); + t_sample *out = (t_sample *)(w[2]); + int n = (int)(w[3]); - int toggle = x->toggle; + int toggle = x->toggle; - int wait4start = x->wait4start, wait4stop = x->wait4stop; + int wait4start = x->wait4start, wait4stop = x->wait4stop; - while (n--) - { - wait4stop--; - if (!wait4start--) toggle ^= 1; - else if (!wait4stop) toggle ^= 1; + while (n--) + { + wait4stop--; + if (!wait4start--) toggle ^= 1; + else if (!wait4stop) toggle ^= 1; - *out++ = toggle; - } + *out++ = toggle; + } - x->wait4start = wait4start; - x->wait4stop = wait4stop; + x->wait4start = wait4start; + x->wait4stop = wait4stop; - x->toggle = toggle; - return (w+4); + x->toggle = toggle; + return (w+4); } static void step_dsp(t_step *x, t_signal **sp) { - dsp_add(step_perform, 3, x, sp[0]->s_vec, sp[0]->s_n); + dsp_add(step_perform, 3, x, sp[0]->s_vec, sp[0]->s_n); } static void step_helper(void) { - post("%c step~-object :: generates a unity-step", HEARTSYMBOL); - post("creation : \"dirac~ [ []]\" : create a rectangular window\n" - "\t\t\tat specified position and with specified length (in samples)\n" - "inlet1\t: \t: create a rectangular window at new position\n" - "\t 'bang'\t: create a rectangular window at specified position\n" - "\t 'help'\t: view this\n" - "inlet2\t: \t: define new window length ('0' will make a unity-step)\n" - "outlet\t: signal~"); + post("%c step~-object :: generates a unity-step", HEARTSYMBOL); + post("creation : \"dirac~ [ []]\" : create a rectangular window\n" + "\t\t\tat specified position and with specified length (in samples)\n" + "inlet1\t: \t: create a rectangular window at new position\n" + "\t 'bang'\t: create a rectangular window at specified position\n" + "\t 'help'\t: view this\n" + "inlet2\t: \t: define new window length ('0' will make a unity-step)\n" + "outlet\t: signal~"); } static void *step_new(t_floatarg farg) { - t_step *x = (t_step *)pd_new(step_class); + t_step *x = (t_step *)pd_new(step_class); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1")); - outlet_new(&x->x_obj, gensym("signal")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1")); + outlet_new(&x->x_obj, &s_signal); - x->position = 0; - x->wait4start = x->wait4stop = 0; - x->toggle = 1; + x->position = 0; + x->wait4start = x->wait4stop = 0; + x->toggle = 1; - step_setlength(x, farg); + step_setlength(x, farg); - return (x); + return (x); } void step_tilde_setup(void) { - step_class = class_new(gensym("step~"), (t_newmethod)step_new, 0, - sizeof(t_step), 0, A_DEFFLOAT, 0); + step_class = class_new(gensym("step~"), (t_newmethod)step_new, 0, + sizeof(t_step), 0, A_DEFFLOAT, 0); - class_addfloat(step_class, step_float); - class_addbang(step_class, step_bang); - class_addmethod(step_class, (t_method)step_setlength, gensym("ft1"), A_FLOAT, 0); - class_addmethod(step_class, (t_method)step_dsp, gensym("dsp"), 0); + class_addfloat(step_class, step_float); + class_addbang(step_class, step_bang); + class_addmethod(step_class, (t_method)step_setlength, gensym("ft1"), A_FLOAT, 0); + class_addmethod(step_class, (t_method)step_dsp, gensym("dsp"), 0); - class_addmethod(step_class, (t_method)step_helper, gensym("help"), 0); + class_addmethod(step_class, (t_method)step_helper, gensym("help"), 0); zexy_register("step~"); } -- cgit v1.2.1