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

« back to all changes in this revision

Viewing changes to src/blockmirror~.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
/* ------------------------ blockmirror~ ----------------------------- */
 
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 *blockmirror_class;
 
30
 
 
31
typedef struct _blockmirror
 
32
{
 
33
  t_object x_obj;
 
34
  int doit;
 
35
  int blocksize;
 
36
  t_sample *blockbuffer;
 
37
} t_blockmirror;
 
38
 
 
39
static void blockmirror_float(t_blockmirror *x, t_floatarg f)
 
40
{
 
41
  x->doit = (f != 0);
 
42
}
 
43
 
 
44
static t_int *blockmirror_perform(t_int *w)
 
45
{
 
46
  t_blockmirror *x = (t_blockmirror *)(w[1]);
 
47
  t_sample *in = (t_sample *)(w[2]);
 
48
  t_sample *out = (t_sample *)(w[3]);
 
49
  int n = (int)(w[4]);
 
50
  if (x->doit) {
 
51
    if (in==out){
 
52
      int N=n;
 
53
      t_sample *dummy=x->blockbuffer;
 
54
      while(n--)*dummy++=*in++;
 
55
      dummy--;
 
56
      while(N--)*out++=*dummy--;
 
57
    } else {
 
58
      in+=n-1;
 
59
      while(n--)*out++=*in--;
 
60
    }
 
61
  } else while (n--) *out++ = *in++;
 
62
  return (w+5);
 
63
}
 
64
 
 
65
static void blockmirror_dsp(t_blockmirror *x, t_signal **sp)
 
66
{
 
67
  if (x->blocksize<sp[0]->s_n){
 
68
    if(x->blockbuffer)freebytes(x->blockbuffer, sizeof(*x->blockbuffer)*x->blocksize);
 
69
    x->blocksize = sp[0]->s_n;
 
70
    x->blockbuffer = getbytes(sizeof(*x->blockbuffer)*x->blocksize);
 
71
  }
 
72
  dsp_add(blockmirror_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
 
73
}
 
74
 
 
75
static void blockmirror_helper(t_blockmirror*x)
 
76
{
 
77
  post("\n%c blockmirror~-object for reverting a signal", HEARTSYMBOL);
 
78
  post("'help' : view this\n"
 
79
       "signal~");
 
80
  post("outlet : signal~");
 
81
}
 
82
static void blockmirror_free(t_blockmirror*x)
 
83
{
 
84
  if(x->blockbuffer)
 
85
    freebytes(x->blockbuffer, sizeof(*x->blockbuffer)*x->blocksize);
 
86
  x->blockbuffer=0;
 
87
}
 
88
static void *blockmirror_new(void)
 
89
{
 
90
  t_blockmirror *x = (t_blockmirror *)pd_new(blockmirror_class);
 
91
  outlet_new(&x->x_obj, gensym("signal"));
 
92
  x->doit = 1;
 
93
  x->blocksize=0;
 
94
  return (x);
 
95
}
 
96
 
 
97
void blockmirror_tilde_setup(void)
 
98
{
 
99
  blockmirror_class = class_new(gensym("blockmirror~"), (t_newmethod)blockmirror_new, 
 
100
                                (t_method)blockmirror_free,
 
101
                                sizeof(t_blockmirror), 0, A_NULL);
 
102
  class_addmethod(blockmirror_class, nullfn, gensym("signal"), 0);
 
103
  class_addmethod(blockmirror_class, (t_method)blockmirror_dsp, gensym("dsp"), 0);
 
104
  
 
105
  class_addfloat(blockmirror_class, blockmirror_float);
 
106
  
 
107
  class_addmethod(blockmirror_class, (t_method)blockmirror_helper, gensym("help"), 0);
 
108
  zexy_register("blockmirror~");
 
109
}