From 5b7a154e9f916415128efe21ab0db6da0fd156cf Mon Sep 17 00:00:00 2001 From: Martin Peach Date: Tue, 11 Jun 2013 21:48:23 +0000 Subject: Add an optional value to the clear method. The current running mean will be written to the entire array if the length changes, avoiding glitches. svn path=/trunk/externals/mrpeach/; revision=17151 --- runningmean/runningmean.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'runningmean/runningmean.c') diff --git a/runningmean/runningmean.c b/runningmean/runningmean.c index 96cc157..a92f309 100644 --- a/runningmean/runningmean.c +++ b/runningmean/runningmean.c @@ -31,7 +31,7 @@ static void runningmean_free(t_runningmean *x); static void runningmean_bang(t_runningmean *x); static void runningmean_float(t_runningmean *x, t_float f); static void runningmean_length(t_runningmean *x, t_float f); -static void runningmean_zero(t_runningmean *x); +static void runningmean_zero(t_runningmean *x, t_float f); static void runningmean_float(t_runningmean *x, t_float f) { @@ -63,20 +63,20 @@ static void runningmean_length(t_runningmean *x, t_float f) if ((f >= 1) && ((int)f == f) && (f <= x->x_originalsize)) { x->x_n = (int)f; - runningmean_zero(x); + runningmean_zero(x, x->x_mean); // set the entire new array to the old mean } else post("runningmean length must be an integer between 1 and %d.", x->x_originalsize); return; } -static void runningmean_zero(t_runningmean *x) +static void runningmean_zero(t_runningmean *x, t_float f) { float *p = x->x_data; int i; - /* zero the entire array */ - for (i = 0; i < x->x_n; ++i) *p++ = 0; - x->x_mean = 0; + /* set the entire array to f */ + for (i = 0; i < x->x_n; ++i) *p++ = f; + x->x_mean = f; x->x_pointer = 0; return; } @@ -118,7 +118,7 @@ static void *runningmean_new(t_floatarg f) } } x->x_originalsize = x->x_n; - runningmean_zero(x); + runningmean_zero(x, 0); } return (x); } @@ -138,7 +138,7 @@ void runningmean_setup(void) class_addbang(runningmean_class, runningmean_bang); class_addfloat(runningmean_class, runningmean_float); class_addmethod(runningmean_class, (t_method)runningmean_length, gensym("length"), A_FLOAT, 0); - class_addmethod(runningmean_class, (t_method)runningmean_zero, gensym("clear"), 0); + class_addmethod(runningmean_class, (t_method)runningmean_zero, gensym("clear"), A_DEFFLOAT, 0); } /* end runningmean.c */ -- cgit v1.2.1