aboutsummaryrefslogtreecommitdiff
path: root/src/blockmirror~.c
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-05-17 16:50:28 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-05-17 16:50:28 +0000
commit6b378329aa20ec2caa3f06968c2ac71d41dca7f9 (patch)
tree849bbfb62e3b5842252a3920e3a0b0bdf3617ac8 /src/blockmirror~.c
parentc3a32b31057a7f805382154403ddb6d68424a6dd (diff)
renamed *_tilde.c-files to *~.c
svn path=/trunk/externals/zexy/; revision=2998
Diffstat (limited to 'src/blockmirror~.c')
-rw-r--r--src/blockmirror~.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/blockmirror~.c b/src/blockmirror~.c
new file mode 100644
index 0000000..1dd3659
--- /dev/null
+++ b/src/blockmirror~.c
@@ -0,0 +1,104 @@
+/******************************************************
+ *
+ * zexy - implementation file
+ *
+ * copyleft (c) IOhannes m zmölnig
+ *
+ * 1999:forum::für::umläute:2004
+ *
+ * institute of electronic music and acoustics (iem)
+ *
+ ******************************************************
+ *
+ * license: GNU General Public License v.2
+ *
+ ******************************************************/
+
+/*
+ 1110:forum::für::umläute:1999
+*/
+
+#include "zexy.h"
+
+/* ------------------------ blockmirror~ ----------------------------- */
+
+/* mirrors a signalblock around it's center:
+ {x[0], x[1], ... x[n-1]} --> {x[n-1], x[n-2], ... x[0]}
+*/
+
+static t_class *blockmirror_class;
+
+typedef struct _blockmirror
+{
+ t_object x_obj;
+ int doit;
+ int blocksize;
+ t_float *blockbuffer;
+} t_blockmirror;
+
+static void blockmirror_float(t_blockmirror *x, t_floatarg f)
+{
+ x->doit = (f != 0);
+}
+
+static t_int *blockmirror_perform(t_int *w)
+{
+ t_blockmirror *x = (t_blockmirror *)(w[1]);
+ t_float *in = (t_float *)(w[2]);
+ t_float *out = (t_float *)(w[3]);
+ int n = (int)(w[4]);
+ if (x->doit) {
+ if (in==out){
+ int N=n;
+ t_float *dummy=x->blockbuffer;
+ while(n--)*dummy++=*in++;
+ dummy--;
+ while(N--)*out++=*dummy--;
+ } else {
+ in+=n-1;
+ while(n--)*out++=*in--;
+ }
+ } else while (n--) *out++ = *in++;
+ return (w+5);
+}
+
+static void blockmirror_dsp(t_blockmirror *x, t_signal **sp)
+{
+ if (x->blocksize<sp[0]->s_n){
+ if(x->blockbuffer)freebytes(x->blockbuffer, sizeof(t_float)*x->blocksize);
+ x->blocksize = sp[0]->s_n;
+ x->blockbuffer = getbytes(sizeof(t_float)*x->blocksize);
+ }
+ dsp_add(blockmirror_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
+}
+
+static void blockmirror_helper(void)
+{
+ post("\n%c blockmirror~-object for reverting a signal", HEARTSYMBOL);
+ post("'help' : view this\n"
+ "signal~");
+ post("outlet : signal~");
+}
+
+static void *blockmirror_new(void)
+{
+ t_blockmirror *x = (t_blockmirror *)pd_new(blockmirror_class);
+ outlet_new(&x->x_obj, gensym("signal"));
+ x->doit = 1;
+ x->blocksize=0;
+ return (x);
+}
+
+void blockmirror_tilde_setup(void)
+{
+ blockmirror_class = class_new(gensym("blockmirror~"), (t_newmethod)blockmirror_new, 0,
+ sizeof(t_blockmirror), 0, A_NULL);
+ class_addmethod(blockmirror_class, nullfn, gensym("signal"), 0);
+ class_addmethod(blockmirror_class, (t_method)blockmirror_dsp, gensym("dsp"), 0);
+
+ class_addfloat(blockmirror_class, blockmirror_float);
+
+ class_addmethod(blockmirror_class, (t_method)blockmirror_helper, gensym("help"), 0);
+ class_sethelpsymbol(blockmirror_class, gensym("zexy/blockmirror~"));
+ zexy_register("blockmirror~");
+}