From d449d31030cfc4a3e06858bf877dcbfacad59f74 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 9 Jan 2006 21:24:28 +0000 Subject: checked in code from sIgpAck0.03.ZIP; cleaned up comment warnings and changed #ifdef NT to #ifdef _MSC_VER; removed sp. prefix and set up for namespaces svn path=/trunk/externals/sigpack/; revision=4381 --- source/foldback~.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 source/foldback~.c (limited to 'source/foldback~.c') diff --git a/source/foldback~.c b/source/foldback~.c new file mode 100644 index 0000000..4101a5a --- /dev/null +++ b/source/foldback~.c @@ -0,0 +1,70 @@ +/* sIgpAck + * for + * pure-data + * www.weiss-archiv.de */ + +#include "m_pd.h" +#ifdef _MSC_VER +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +/* ------------------------ sp.foldback~ ----------------------------- */ +/* signal mirror */ + +static t_class *foldback_tilde_class; + +typedef struct _foldback_tilde +{ + t_object x_obj; + t_sample x_low; + t_sample x_high; + float x_f; +} t_foldback_tilde; + +static void *foldback_tilde_new(t_floatarg low, t_floatarg high) +{ + t_foldback_tilde *x = (t_foldback_tilde *)pd_new(foldback_tilde_class); + x->x_low = low; + x->x_high = high; + outlet_new(&x->x_obj, gensym("signal")); + floatinlet_new(&x->x_obj, &x->x_low); + floatinlet_new(&x->x_obj, &x->x_high); + x->x_f = 0; + if(low) x->x_low = low; + else x->x_low = -1; + if(high) x->x_high = high; + else x->x_high = 1; + return (x); +} + +static t_int *foldback_tilde_perform(t_int *w) +{ + t_foldback_tilde *x = (t_foldback_tilde *)(w[1]); + t_float *in = (t_float *)(w[2]); + t_float *out = (t_float *)(w[3]); + int n = (int)(w[4]); + float f, value; + while (n--) + { + f = *in++; + if(f < x->x_low) value = (f - ((f - x->x_low) * 2)); + else if(f > x->x_high) value = (f - ((f - x->x_high) * 2)); + else value = f; + *out++ = value; + } + return (w+5); +} + +static void foldback_tilde_dsp(t_foldback_tilde *x, t_signal **sp) +{ + dsp_add(foldback_tilde_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); +} + +void foldback_tilde_setup(void) +{ + foldback_tilde_class = class_new(gensym("sp.foldback~"), (t_newmethod)foldback_tilde_new, 0, + sizeof(t_foldback_tilde), 0, A_DEFFLOAT, A_DEFFLOAT, 0); + CLASS_MAINSIGNALIN(foldback_tilde_class, t_foldback_tilde, x_f); + class_addmethod(foldback_tilde_class, (t_method)foldback_tilde_dsp, gensym("dsp"), 0); +} -- cgit v1.2.1