From 494a07a361fe4ee0e54f77468a976b1a77818770 Mon Sep 17 00:00:00 2001 From: Tom Schouten Date: Fri, 12 Sep 2003 22:26:57 +0000 Subject: creb 0.9.0 svn path=/trunk/externals/creb/; revision=956 --- modules/eadsr.c | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'modules/eadsr.c') diff --git a/modules/eadsr.c b/modules/eadsr.c index bba96cd..332ddf4 100644 --- a/modules/eadsr.c +++ b/modules/eadsr.c @@ -63,6 +63,7 @@ void eadsr_release(t_eadsr *x, t_floatarg f) void eadsr_start(t_eadsr *x) { x->x_ctl.c_target = 1; + x->x_ctl.c_state = 0.0f; } @@ -72,6 +73,12 @@ void eadsr_stop(t_eadsr *x) } +void eadsr_float(t_eadsr *x, t_floatarg f) +{ + if (f == 0.0f) eadsr_stop(x); + else eadsr_start(x); +} + static t_int *eadsr_perform(t_int *w) { t_float *out = (float *)(w[3]); @@ -87,35 +94,28 @@ static t_int *eadsr_perform(t_int *w) t_int i; - if (target == 1) - /* attack phase */ - { - for (i = 0; i < n; i++) - { + for (i = 0; i < n; i++){ + if (target == 1.0f){ + /* attack */ *out++ = state; state += attack*(1 - state); - } - if (state > ENVELOPE_MAX) - ctl->c_target = sustain; - } - - else if (target == 0) - /* release phase */ - for (i = 0; i < n; i++) - { - *out++ = state; - state -= release*state; + target = (state > ENVELOPE_MAX) ? sustain : 1.0f; } - - else - /* decay phase */ - for (i = 0; i < n; i++) - { - *out++ = state; - state -= decay*(state-sustain); + else if (target == 0.0f){ + /* release */ + *out++ = state; + state -= release*state; + } + else{ + /* decay */ + *out++ = state; + state -= decay*(state-sustain); } + } + /* save state */ ctl->c_state = IS_DENORMAL(state) ? 0 : state; + ctl->c_target = target; return (w+4); } @@ -157,6 +157,7 @@ void eadsr_tilde_setup(void) //post("eadsr~ v0.1"); eadsr_class = class_new(gensym("eadsr~"), (t_newmethod)eadsr_new, (t_method)eadsr_free, sizeof(t_eadsr), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0); + class_addmethod(eadsr_class, (t_method)eadsr_float, gensym("float"), A_FLOAT, 0); class_addmethod(eadsr_class, (t_method)eadsr_start, gensym("start"), 0); class_addmethod(eadsr_class, (t_method)eadsr_start, gensym("bang"), 0); class_addmethod(eadsr_class, (t_method)eadsr_stop, gensym("stop"), 0); -- cgit v1.2.1