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/ead.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'modules/ead.c') diff --git a/modules/ead.c b/modules/ead.c index 4d301b8..88fc6ec 100644 --- a/modules/ead.c +++ b/modules/ead.c @@ -29,7 +29,7 @@ typedef struct eadctl t_float c_attack; t_float c_decay; t_float c_state; - t_float c_target; + t_int c_target; } t_eadctl; @@ -54,7 +54,13 @@ static void ead_decay(t_ead *x, t_floatarg f) static void ead_start(t_ead *x) { - x->x_ctl.c_target = 1; + /* reset state if necessary to prevent skipping */ + + // always reset, seems to be safest + //if (x->x_ctl.c_target == 1) + + x->x_ctl.c_state = 0.0f; + x->x_ctl.c_target = 1; } @@ -68,7 +74,6 @@ static t_int *ead_perform(t_int *w) t_float attack = ctl->c_attack; t_float decay = ctl->c_decay; t_float state = ctl->c_state; - t_float target = ctl->c_target; t_int n = (t_int)(w[2]); t_int i; @@ -76,29 +81,27 @@ static t_int *ead_perform(t_int *w) /* A/D code */ - if (target == 1) - /* attack phase */ - { - for (i = 0; i < n; i++) - { + for (i = 0; i < n; i++){ + switch(ctl->c_target){ + case 1: + /* attack phase */ *out++ = state; state += attack*(1 - state); - } - if (state > ENVELOPE_MAX) - ctl->c_target = 0; - } - - else - /* decay phase */ - for (i = 0; i < n; i++) - { - *out++ = state; - state -= decay*state; + ctl->c_target = (state <= ENVELOPE_MAX); + break; + default: + /* decay phase */ + *out++ = state; + state -= decay*state; + break; } + + } + /* save state */ ctl->c_state = IS_DENORMAL(state) ? 0 : state; - return (w+4); /* pd quirk: pointer for sequencer */ + return (w+4); } -- cgit v1.2.1