1
/******************************************************
3
* zexy - implementation file
5
* copyleft (c) IOhannes m zm�lnig
7
* 1999:forum::f�r::uml�ute:2004
9
* institute of electronic music and acoustics (iem)
11
******************************************************
13
* license: GNU General Public License v.2
15
******************************************************/
18
1110:forum::f�r::uml�ute:1999
23
/* ------------------------ blockshuffle~ ----------------------------- */
25
/* mirrors a signalblock around it's center:
26
{x[0], x[1], ... x[n-1]} --> {x[n-1], x[n-2], ... x[0]}
29
static t_class *blockshuffle_class;
31
typedef struct _blockshuffle
42
static void blockshuffle_buildindex(t_blockshuffle *x, int blocksize){
44
if(blocksize!=x->size){
45
if(x->indices)freebytes(x->indices, x->size);
46
if(x->blockbuf)freebytes(x->blockbuf, x->size);
47
x->indices=getbytes (sizeof(t_int)*blocksize);
48
x->blockbuf=getbytes(sizeof(t_sample)*blocksize);
51
for(i=0;i<x->shufflesize&&i<blocksize; i++){
52
int idx=x->shuffle[i];
53
if(idx>=blocksize)idx=blocksize-1;
57
for(;i<blocksize; i++){
62
static void blockshuffle_list(t_blockshuffle *x, t_symbol*s, int argc, t_atom*argv)
66
freebytes(x->shuffle, x->shufflesize);
70
x->shuffle=getbytes(sizeof(*x->shuffle)*argc);
72
for(i=0; i<argc; i++){
73
x->shuffle[i]=atom_getfloat(argv++);
75
blockshuffle_buildindex(x, x->size);
78
static t_int *blockshuffle_perform(t_int *w)
80
t_blockshuffle*x = (t_blockshuffle *)(w[1]);
81
t_sample *in = (t_sample *)(w[2]);
82
t_sample *out = (t_sample *)(w[3]);
85
t_sample *temp=x->blockbuf;
86
t_int *idx =x->indices;
97
while(n--)*out++=*in++;
102
static void blockshuffle_dsp(t_blockshuffle *x, t_signal **sp)
104
blockshuffle_buildindex(x, sp[0]->s_n);
106
dsp_add(blockshuffle_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
109
static void blockshuffle_helper(void)
111
post("\n%c blockshuffle~-object for shuffling the samples within a signal-block", HEARTSYMBOL);
112
post("'help' : view this\n"
114
post("outlet : signal~");
116
static void blockshuffle_free(t_blockshuffle *x){
117
if(x->indices) freebytes(x->indices, sizeof(*x->indices) *x->size);
118
if(x->blockbuf)freebytes(x->blockbuf, sizeof(*x->blockbuf)*x->size);
119
if(x->shuffle) freebytes(x->shuffle, sizeof(*x->shuffle) *x->shufflesize);
122
static void *blockshuffle_new(void)
124
t_blockshuffle *x = (t_blockshuffle *)pd_new(blockshuffle_class);
125
outlet_new(&x->x_obj, gensym("signal"));
134
void blockshuffle_tilde_setup(void)
136
blockshuffle_class = class_new(gensym("blockshuffle~"), (t_newmethod)blockshuffle_new,
137
(t_method)blockshuffle_free,
138
sizeof(t_blockshuffle), 0, A_NULL);
139
class_addmethod(blockshuffle_class, nullfn, gensym("signal"), 0);
140
class_addmethod(blockshuffle_class, (t_method)blockshuffle_dsp, gensym("dsp"), 0);
142
class_addlist(blockshuffle_class, blockshuffle_list);
144
class_addmethod(blockshuffle_class, (t_method)blockshuffle_helper, gensym("help"), 0);
145
zexy_register("blockshuffle~");