From 5af7081222ef801b23857fb904c78d0798f5d0df Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 10 Jan 2011 06:03:02 +0000 Subject: build Pd's extra as a libdir svn path=/trunk/; revision=14694 --- externals/extra/lrshift~/lrshift~-help.pd | 33 ++++++++++++++ externals/extra/lrshift~/lrshift~.c | 76 +++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 externals/extra/lrshift~/lrshift~-help.pd create mode 100644 externals/extra/lrshift~/lrshift~.c (limited to 'externals/extra/lrshift~') diff --git a/externals/extra/lrshift~/lrshift~-help.pd b/externals/extra/lrshift~/lrshift~-help.pd new file mode 100644 index 00000000..fdf7b0c5 --- /dev/null +++ b/externals/extra/lrshift~/lrshift~-help.pd @@ -0,0 +1,33 @@ +#N canvas 143 0 673 325 12; +#X msg 268 277 bang; +#X obj 244 303 print~; +#X msg 185 278 bang; +#X obj 161 304 print~; +#X text 53 117 click here first; +#X msg 72 270 bang; +#X obj 48 296 print~; +#X text 162 222 shift left; +#X text 243 224 shift right; +#X obj 161 252 lrshift~ 1; +#X obj 244 251 lrshift~ -1; +#X text 39 37 Acting at whatever vector size the window is running +at \, lrshift~ shifts samples to the left (toward the beginning sample) +or to the right. The argument gives the direction and the amount of +the shift. The rightmost (or leftmost) samples are set to zero.; +#N canvas 0 0 450 300 (subpatch) 0; +#X array shiftin 64 float 0; +#X coords 0 1 63 0 200 140 1; +#X restore 448 118 graph; +#X text 115 11 -- shift signal vector elements left or right; +#X msg 54 138 \; pd dsp 1 \; shiftin 1 1; +#X obj 48 204 tabreceive~ shiftin; +#X text 525 308 Updated for Pd 0.31.; +#X obj 47 11 lrshift~; +#X connect 0 0 1 0; +#X connect 2 0 3 0; +#X connect 5 0 6 0; +#X connect 9 0 3 0; +#X connect 10 0 1 0; +#X connect 15 0 6 0; +#X connect 15 0 9 0; +#X connect 15 0 10 0; diff --git a/externals/extra/lrshift~/lrshift~.c b/externals/extra/lrshift~/lrshift~.c new file mode 100644 index 00000000..166facc1 --- /dev/null +++ b/externals/extra/lrshift~/lrshift~.c @@ -0,0 +1,76 @@ +#include "m_pd.h" + +/* ------------------------ lrshift~ ----------------------------- */ + +static t_class *lrshift_tilde_class; + +typedef struct _lrshift_tilde +{ + t_object x_obj; + int x_n; + float x_f; +} t_lrshift_tilde; + +static t_int *leftshift_perform(t_int *w) +{ + t_float *in = (t_float *)(w[1]); + t_float *out= (t_float *)(w[2]); + int n = (int)(w[3]); + int shift = (int)(w[4]); + in += shift; + n -= shift; + while (n--) + *out++ = *in++; + while (shift--) + *out++ = 0; + return (w+5); +} + +static t_int *rightshift_perform(t_int *w) +{ + t_float *in = (t_float *)(w[1]); + t_float *out= (t_float *)(w[2]); + int n = (int)(w[3]); + int shift = (int)(w[4]); + n -= shift; + in -= 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; + 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); +} + +static void *lrshift_tilde_new(t_floatarg f) +{ + t_lrshift_tilde *x = (t_lrshift_tilde *)pd_new(lrshift_tilde_class); + x->x_n = f; + x->x_f = 0; + outlet_new(&x->x_obj, gensym("signal")); + return (x); +} + +void lrshift_tilde_setup(void) +{ + lrshift_tilde_class = class_new(gensym("lrshift~"), + (t_newmethod)lrshift_tilde_new, 0, sizeof(t_lrshift_tilde), 0, + A_DEFFLOAT, 0); + CLASS_MAINSIGNALIN(lrshift_tilde_class, t_lrshift_tilde, x_f); + class_addmethod(lrshift_tilde_class, (t_method)lrshift_tilde_dsp, + gensym("dsp"), 0); +} -- cgit v1.2.1