From a4b29ce82b15dd5ef14a7374abc49f269223108f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Tue, 20 Jun 2006 18:07:24 +0000 Subject: [blockshuffle~] for shuffling samples in a block svn path=/trunk/externals/zexy/; revision=5271 --- src/blockshuffle~.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/z_zexy.c | 1 + src/z_zexy.h | 1 + 3 files changed, 150 insertions(+) create mode 100644 src/blockshuffle~.c diff --git a/src/blockshuffle~.c b/src/blockshuffle~.c new file mode 100644 index 0000000..772c792 --- /dev/null +++ b/src/blockshuffle~.c @@ -0,0 +1,148 @@ +/****************************************************** + * + * 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" + +/* ------------------------ blockshuffle~ ----------------------------- */ + +/* 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 *blockshuffle_class; + +typedef struct _blockshuffle +{ + t_object x_obj; + + t_sample*blockbuf; + t_int* indices; + int size; + + t_float *shuffle; + int shufflesize; +} t_blockshuffle; + +static void blockshuffle_buildindex(t_blockshuffle *x, int blocksize){ + int i=0; + if(blocksize!=x->size){ + if(x->indices)freebytes(x->indices, x->size); + if(x->blockbuf)freebytes(x->blockbuf, x->size); + x->indices=getbytes (sizeof(t_int)*blocksize); + x->blockbuf=getbytes(sizeof(t_sample)*blocksize); + x->size=blocksize; + } + for(i=0;ishufflesize&&ishuffle[i]; + if(idx>=blocksize)idx=blocksize-1; + if(idx<0)idx=0; + x->indices[i]=idx; + } + for(;iindices[i]=i; + } +} + +static void blockshuffle_list(t_blockshuffle *x, t_symbol*s, int argc, t_atom*argv) +{ + int i; + if(x->shuffle){ + freebytes(x->shuffle, x->shufflesize); + x->shuffle=0; + } + x->shufflesize=argc; + x->shuffle=getbytes(sizeof(t_float)*argc); + + for(i=0; ishuffle[i]=atom_getfloat(argv++); + } + blockshuffle_buildindex(x, x->size); +} + +static t_int *blockshuffle_perform(t_int *w) +{ + t_blockshuffle*x = (t_blockshuffle *)(w[1]); + t_sample *in = (t_sample *)(w[2]); + t_sample *out = (t_sample *)(w[3]); + int n = (int)(w[4]); + int i=0; + t_sample *temp=x->blockbuf; + t_int *idx =x->indices; + + if(idx){ + for(i=0; iblockbuf; + for(i=0; is_n); + + dsp_add(blockshuffle_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); +} + +static void blockshuffle_helper(void) +{ + post("\n%c blockshuffle~-object for shuffling the samples within a signal-block", HEARTSYMBOL); + post("'help' : view this\n" + "signal~"); + post("outlet : signal~"); +} +static void blockshuffle_free(t_blockshuffle *x){ + if(x->indices)freebytes(x->indices, x->size); + if(x->blockbuf)freebytes(x->blockbuf, x->size); + if(x->shuffle)freebytes(x->shuffle, x->shufflesize); +} + +static void *blockshuffle_new(void) +{ + t_blockshuffle *x = (t_blockshuffle *)pd_new(blockshuffle_class); + outlet_new(&x->x_obj, gensym("signal")); + x->size=0; + x->blockbuf=0; + x->indices=0; + x->shuffle=0; + x->shufflesize=0; + return (x); +} + +void blockshuffle_tilde_setup(void) +{ + blockshuffle_class = class_new(gensym("blockshuffle~"), (t_newmethod)blockshuffle_new, + (t_method)blockshuffle_free, + sizeof(t_blockshuffle), 0, A_NULL); + class_addmethod(blockshuffle_class, nullfn, gensym("signal"), 0); + class_addmethod(blockshuffle_class, (t_method)blockshuffle_dsp, gensym("dsp"), 0); + + class_addlist(blockshuffle_class, blockshuffle_list); + + class_addmethod(blockshuffle_class, (t_method)blockshuffle_helper, gensym("help"), 0); + class_sethelpsymbol(blockshuffle_class, gensym("zexy/blockshuffle~")); + zexy_register("blockshuffle~"); +} diff --git a/src/z_zexy.c b/src/z_zexy.c index 915c1e1..fd3b86c 100644 --- a/src/z_zexy.c +++ b/src/z_zexy.c @@ -19,6 +19,7 @@ void z_zexy_setup(void) atoi_setup(); /* atoi */ avg_tilde_setup(); /* avg~ */ blockmirror_tilde_setup(); /* blockmirror~ */ + blockshuffle_tilde_setup(); /* blockshuffle~ */ blockswap_tilde_setup(); /* blockswap~ */ date_setup(); /* date */ demultiplex_tilde_setup(); /* demultiplex~ */ diff --git a/src/z_zexy.h b/src/z_zexy.h index ea00729..8b9fcdf 100644 --- a/src/z_zexy.h +++ b/src/z_zexy.h @@ -17,6 +17,7 @@ void absgn_tilde_setup(void); /* absgn~ */ void atoi_setup(void); /* atoi */ void avg_tilde_setup(void); /* avg~ */ void blockmirror_tilde_setup(void); /* blockmirror~ */ +void blockshuffle_tilde_setup(void); /* blockshuffle~ */ void blockswap_tilde_setup(void); /* blockswap~ */ void date_setup(void); /* date */ void demultiplex_tilde_setup(void); /* demultiplex~ */ -- cgit v1.2.1