~ubuntu-branches/ubuntu/natty/pd-zexy/natty

« back to all changes in this revision

Viewing changes to src/blockshuffle~.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard, IOhannes m zmölnig, Jonas Smedegaard
  • Date: 2010-08-20 12:17:41 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100820121741-4kxozn8b9rhee9fr
Tags: 2.2.3-1
* New upstream version

[ IOhannes m zmölnig ]
* Adopt package, on behalf of Multimedia Team.
  Closes: #546964
* Simply debian/rules with CDBS, and don't unconditionally strip
  binaries.
  Closes: #437763
* Install into /usr/lib/pd/extra/zexy/. Document usage in REAME.Debian
  and warn about change in NEWS.
* git'ify package. Add Vcs-* stanzas to control file.
* Use dpkg source format 3.0 (quilt). Drop build-dependency on quilt.

[ Jonas Smedegaard ]
* Enable CDBS copyright-check routine.
* Add copyright and licensing header to debian/rules.
* Add myself as uploader.
* Rewrite debian/copyright using rev. 135 of draft DEP5 format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
 *
 
3
 * zexy - implementation file
 
4
 *
 
5
 * copyleft (c) IOhannes m zm�lnig
 
6
 *
 
7
 *   1999:forum::f�r::uml�ute:2004
 
8
 *
 
9
 *   institute of electronic music and acoustics (iem)
 
10
 *
 
11
 ******************************************************
 
12
 *
 
13
 * license: GNU General Public License v.2
 
14
 *
 
15
 ******************************************************/
 
16
 
 
17
/*
 
18
  1110:forum::f�r::uml�ute:1999
 
19
*/
 
20
 
 
21
#include "zexy.h"
 
22
 
 
23
/* ------------------------ blockshuffle~ ----------------------------- */
 
24
 
 
25
/* mirrors a signalblock around it's center:
 
26
   {x[0], x[1], ... x[n-1]} --> {x[n-1], x[n-2], ... x[0]}
 
27
*/
 
28
 
 
29
static t_class *blockshuffle_class;
 
30
 
 
31
typedef struct _blockshuffle
 
32
{  t_object x_obj;
 
33
 
 
34
  t_sample*blockbuf;
 
35
  t_int*   indices;
 
36
  int      size;
 
37
 
 
38
  t_float *shuffle;
 
39
  int shufflesize;
 
40
} t_blockshuffle;
 
41
 
 
42
static void blockshuffle_buildindex(t_blockshuffle *x, int blocksize){
 
43
  int i=0;
 
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);
 
49
    x->size=blocksize;
 
50
  }
 
51
  for(i=0;i<x->shufflesize&&i<blocksize; i++){
 
52
    int idx=x->shuffle[i];
 
53
    if(idx>=blocksize)idx=blocksize-1;
 
54
    if(idx<0)idx=0;
 
55
    x->indices[i]=idx;
 
56
  }
 
57
  for(;i<blocksize; i++){
 
58
    x->indices[i]=i;
 
59
  }
 
60
}
 
61
 
 
62
static void blockshuffle_list(t_blockshuffle *x, t_symbol*s, int argc, t_atom*argv)
 
63
{
 
64
  int i;
 
65
  if(x->shuffle){
 
66
    freebytes(x->shuffle, x->shufflesize);
 
67
    x->shuffle=0;
 
68
  }
 
69
  x->shufflesize=argc;
 
70
  x->shuffle=getbytes(sizeof(*x->shuffle)*argc);
 
71
 
 
72
  for(i=0; i<argc; i++){
 
73
    x->shuffle[i]=atom_getfloat(argv++);
 
74
  }
 
75
  blockshuffle_buildindex(x, x->size);
 
76
}
 
77
 
 
78
static t_int *blockshuffle_perform(t_int *w)
 
79
{
 
80
  t_blockshuffle*x = (t_blockshuffle *)(w[1]);
 
81
  t_sample *in = (t_sample *)(w[2]);
 
82
  t_sample *out = (t_sample *)(w[3]);
 
83
  int n = (int)(w[4]);
 
84
  int i=0;
 
85
  t_sample *temp=x->blockbuf;
 
86
  t_int    *idx =x->indices;
 
87
 
 
88
  if(idx){
 
89
    for(i=0; i<n; i++){
 
90
      temp[i]=in[idx[i]];
 
91
    }
 
92
    temp=x->blockbuf;
 
93
    for(i=0; i<n; i++){
 
94
      *out++=*temp++;
 
95
    }
 
96
  } else
 
97
    while(n--)*out++=*in++;
 
98
 
 
99
  return (w+5);
 
100
}
 
101
 
 
102
static void blockshuffle_dsp(t_blockshuffle *x, t_signal **sp)
 
103
{
 
104
  blockshuffle_buildindex(x, sp[0]->s_n);
 
105
 
 
106
  dsp_add(blockshuffle_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
 
107
}
 
108
 
 
109
static void blockshuffle_helper(void)
 
110
{
 
111
  post("\n%c blockshuffle~-object for shuffling the samples within a signal-block", HEARTSYMBOL);
 
112
  post("'help' : view this\n"
 
113
       "signal~");
 
114
  post("outlet : signal~");
 
115
}
 
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);
 
120
}
 
121
 
 
122
static void *blockshuffle_new(void)
 
123
{
 
124
  t_blockshuffle *x = (t_blockshuffle *)pd_new(blockshuffle_class);
 
125
  outlet_new(&x->x_obj, gensym("signal"));
 
126
  x->size=0;
 
127
  x->blockbuf=0;
 
128
  x->indices=0;
 
129
  x->shuffle=0;
 
130
  x->shufflesize=0;
 
131
  return (x);
 
132
}
 
133
 
 
134
void blockshuffle_tilde_setup(void)
 
135
{
 
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);
 
141
  
 
142
  class_addlist(blockshuffle_class, blockshuffle_list);
 
143
  
 
144
  class_addmethod(blockshuffle_class, (t_method)blockshuffle_helper, gensym("help"), 0);
 
145
  zexy_register("blockshuffle~");
 
146
}