diff options
author | IOhannes m zmölnig <zmoelnig@users.sourceforge.net> | 2007-10-30 09:21:52 +0000 |
---|---|---|
committer | IOhannes m zmölnig <zmoelnig@users.sourceforge.net> | 2007-10-30 09:21:52 +0000 |
commit | 5e869f7a0cef88be3b03272303a6084b8bd1a7e3 (patch) | |
tree | 8d5e0dfc39eb696f5b457b3376dd6eb7de17b538 /src/sigzero~.c | |
parent | 6d61e2a46722b75c1a3734e3419ee2886b11b2b3 (diff) |
use t_float and t_sample when possible
svn path=/trunk/externals/zexy/; revision=8907
Diffstat (limited to 'src/sigzero~.c')
-rw-r--r-- | src/sigzero~.c | 89 |
1 files changed, 44 insertions, 45 deletions
diff --git a/src/sigzero~.c b/src/sigzero~.c index bbedc9e..85012d7 100644 --- a/src/sigzero~.c +++ b/src/sigzero~.c @@ -15,8 +15,8 @@ /* ------------------------ sigzero~ ----------------------------- */ /* - a very useful function, which detects, whether a signal is zeroes-only this block or not - this is really great together with the "switch~"-object + a very useful function, which detects, whether a signal is zeroes-only this block or not + this is really great together with the "switch~"-object */ #include "zexy.h" @@ -26,65 +26,64 @@ static t_class *sigzero_class; typedef struct _sigzero { - t_object x_obj; - int activate; - int current; /* 0 == (signalblock == 0); 1==(signalblock != 0) */ + t_object x_obj; + int activate; + int current; /* 0 == (signalblock == 0); 1==(signalblock != 0) */ } t_sigzero; static void sigzero_activate(t_sigzero *x, t_floatarg activate) { - x->activate = (activate)?1:0; + x->activate = (activate)?1:0; } static void sigzero_banged(t_sigzero *x) { - x->activate = 1; + x->activate = 1; } static void sigzero_off(t_sigzero *x) { - x->activate = 0; + x->activate = 0; } static t_int *sigzero_perform(t_int *w) { - t_float *in = (t_float *)w[1]; - t_sigzero *x = (t_sigzero *)w[2]; - int n = (int)w[3]; - - int non_zero = 0; - - if (x->activate) { - while (n--) - { - if (*in++ != 0.) { - non_zero = 1; - break; - } - } - if (non_zero != x->current) { - outlet_float(x->x_obj.ob_outlet, x->current = non_zero); - } -// else post("non_zero=%d\tcurrent=%d", non_zero, x->current); - } - - return (w+4); + t_sample *in = (t_sample *)w[1]; + t_sigzero *x = (t_sigzero *)w[2]; + int n = (int)w[3]; + + int non_zero = 0; + + if (x->activate) { + while (n--) + { + if (*in++ != 0.) { + non_zero = 1; + break; + } + } + if (non_zero != x->current) { + outlet_float(x->x_obj.ob_outlet, x->current = non_zero); + } + } + + return (w+4); } static void sigzero_dsp(t_sigzero *x, t_signal **sp) { - dsp_add(sigzero_perform, 3, sp[0]->s_vec, x, sp[0]->s_n); + dsp_add(sigzero_perform, 3, sp[0]->s_vec, x, sp[0]->s_n); } static void sigzero_tilde_helper(void) { - post("\n%c sigzero~-object :: for detecting whether a signal is currently zero or not", HEARTSYMBOL); - post("'bang'\t: turn the detector on\n" - "'off'\t: turn it off\n" - "<1/0>\t: turn it on/off\n" - "'help'\t: view this\n" - "signal~"); - post("outlet :: 1/0\t: signal turned to non-zero/zero\n"); + post("\n%c sigzero~-object :: for detecting whether a signal is currently zero or not", HEARTSYMBOL); + post("'bang'\t: turn the detector on\n" + "'off'\t: turn it off\n" + "<1/0>\t: turn it on/off\n" + "'help'\t: view this\n" + "signal~"); + post("outlet :: 1/0\t: signal turned to non-zero/zero\n"); } static void *sigzero_new(void) @@ -96,15 +95,15 @@ static void *sigzero_new(void) void sigzero_tilde_setup(void) { - sigzero_class = class_new(gensym("sigzero~"), (t_newmethod)sigzero_new, 0, - sizeof(t_sigzero), 0, 0); - class_addfloat(sigzero_class, sigzero_activate); - class_addbang(sigzero_class, sigzero_banged); - class_addmethod(sigzero_class, (t_method)sigzero_off, gensym("off"), 0); + sigzero_class = class_new(gensym("sigzero~"), (t_newmethod)sigzero_new, 0, + sizeof(t_sigzero), 0, 0); + class_addfloat(sigzero_class, sigzero_activate); + class_addbang(sigzero_class, sigzero_banged); + class_addmethod(sigzero_class, (t_method)sigzero_off, gensym("off"), 0); - class_addmethod(sigzero_class, nullfn, gensym("signal"), 0); - class_addmethod(sigzero_class, (t_method)sigzero_dsp, gensym("dsp"), 0); + class_addmethod(sigzero_class, nullfn, gensym("signal"), 0); + class_addmethod(sigzero_class, (t_method)sigzero_dsp, gensym("dsp"), 0); - class_addmethod(sigzero_class, (t_method)sigzero_tilde_helper, gensym("help"), 0); + class_addmethod(sigzero_class, (t_method)sigzero_tilde_helper, gensym("help"), 0); zexy_register("sigzero~"); } |