From 754a971e9fcd0799c1c7f26dabc93f10dbaf5a61 Mon Sep 17 00:00:00 2001 From: Martin Peach Date: Tue, 7 Nov 2006 22:00:41 +0000 Subject: added float input to dynamically change shift amount svn path=/trunk/; revision=6227 --- externals/signal/lrshift~/lrshift~.c | 50 +++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 7 deletions(-) (limited to 'externals') diff --git a/externals/signal/lrshift~/lrshift~.c b/externals/signal/lrshift~/lrshift~.c index c0fc4c1f..87ac1029 100644 --- a/externals/signal/lrshift~/lrshift~.c +++ b/externals/signal/lrshift~/lrshift~.c @@ -10,6 +10,7 @@ typedef struct _lrshift_tilde int x_n; } t_lrshift_tilde; +#ifdef OBSOLETE static t_int *leftshift_perform(t_int *w) { t_float *in = (t_float *)(w[1]); @@ -39,20 +40,49 @@ static t_int *rightshift_perform(t_int *w) *--out = 0; return (w+5); } +#endif -static void lrshift_tilde_dsp(t_lrshift_tilde *x, t_signal **sp) +static t_int *lrshift_perform(t_int *w) { - int n = sp[0]->s_n; - int shift = x->x_n; + t_float *in = (t_float *)(w[1]); + t_float *out= (t_float *)(w[2]); + int n = (int)(w[3]); + t_lrshift_tilde *x = (t_lrshift_tilde *)w[4]; + int shift = x->x_n; + if (shift > n) shift = n; if (shift < -n) shift = -n; if (shift < 0) - dsp_add(rightshift_perform, 4, - sp[0]->s_vec + n, sp[1]->s_vec + n, n, -shift); - else dsp_add(leftshift_perform, 4, - sp[0]->s_vec, sp[1]->s_vec, n, shift); + { + shift = -shift; + out += n; + in += n; + n -= shift; + in -= shift; + while (n--) + *--out = *--in; + while (shift--) + *--out = 0; + } + else + { + in += shift; + n -= shift; + while (n--) + *out++ = *in++; + while (shift--) + *out++ = 0; + } + return (w+5); +} + +static void lrshift_tilde_dsp(t_lrshift_tilde *x, t_signal **sp) +{ + int n = sp[0]->s_n; + dsp_add(lrshift_perform, 4, sp[0]->s_vec, sp[1]->s_vec, n, x); + } static void *lrshift_tilde_new(t_floatarg f) @@ -63,6 +93,11 @@ static void *lrshift_tilde_new(t_floatarg f) return (x); } +static void lrshift_tilde_float(t_lrshift_tilde *x, t_floatarg f) +{ + x->x_n = f; +} + void lrshift_tilde_setup(void) { lrshift_tilde_class = class_new(gensym("lrshift~"), @@ -71,4 +106,5 @@ void lrshift_tilde_setup(void) class_addmethod(lrshift_tilde_class, nullfn, gensym("signal"), 0); class_addmethod(lrshift_tilde_class, (t_method)lrshift_tilde_dsp, gensym("dsp"), 0); + class_addfloat(lrshift_tilde_class, (t_method)lrshift_tilde_float); } -- cgit v1.2.1