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

« back to all changes in this revision

Viewing changes to src/tabread4~~.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-b�lnig-A
 
6
 *
 
7
 *   1999:forum::f-b�r::uml�ute:2007-A
 
8
 *
 
9
 *   institute of electronic music and acoustics (iem)
 
10
 *
 
11
 ******************************************************
 
12
 *
 
13
 * license: GNU General Public License v.2
 
14
 *
 
15
 ******************************************************/
 
16
 
 
17
/* based on tabread4~ which is part of pd */
 
18
 
 
19
#include "zexy.h"
 
20
 
 
21
/******************** tabread4~~ ***********************/
 
22
 
 
23
 
 
24
static t_class *tabread4_tilde_class;
 
25
 
 
26
typedef struct _tabread4_tilde
 
27
{
 
28
  t_object x_obj;
 
29
  int x_npoints;
 
30
  zarray_t *x_vec;
 
31
  t_symbol *x_arrayname;
 
32
  t_float x_f;
 
33
} t_tabread4_tilde;
 
34
 
 
35
static void *tabread4_tilde_new(t_symbol *s)
 
36
{
 
37
  t_tabread4_tilde *x = (t_tabread4_tilde *)pd_new(tabread4_tilde_class);
 
38
  x->x_arrayname = s;
 
39
  x->x_vec = 0;
 
40
  x->x_npoints=0;
 
41
 
 
42
  inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
 
43
  outlet_new(&x->x_obj, &s_signal);
 
44
  x->x_f = 0;
 
45
  return (x);
 
46
}
 
47
 
 
48
static t_int *tabread4_tilde_perform(t_int *w)
 
49
{
 
50
  t_tabread4_tilde *x = (t_tabread4_tilde *)(w[1]);
 
51
  t_sample *in = (t_sample *)(w[2]);
 
52
  t_sample *in1 = (t_sample *)(w[3]);
 
53
  t_sample *out = (t_sample *)(w[4]);
 
54
  int n = (int)(w[5]);    
 
55
  int maxindex;
 
56
  zarray_t *buf = x->x_vec, *wp;
 
57
  int i;
 
58
    
 
59
  maxindex = x->x_npoints - 3;
 
60
  if (!buf){
 
61
    while (n--) *out++ = 0;
 
62
    return (w+6);
 
63
  }
 
64
  for (i = 0; i < n; i++)
 
65
    {
 
66
      t_sample in0_s=*in++;
 
67
      t_sample in1_s=*in1++;
 
68
      double findex = (double)in0_s + (double)in1_s;
 
69
      long int index = findex;
 
70
      double frac;
 
71
      t_sample a,  b,  c,  d, cminusb;
 
72
      if (index < 1)
 
73
        index = 1, frac = 0;
 
74
      else if (index > maxindex)
 
75
        index = maxindex, frac = 1;
 
76
      else frac = findex - index;
 
77
 
 
78
      wp = buf + index;
 
79
 
 
80
      a = zarray_getfloat(wp,-1);
 
81
      b = zarray_getfloat(wp, 0);
 
82
      c = zarray_getfloat(wp, 1);
 
83
      d = zarray_getfloat(wp, 2);
 
84
 
 
85
      cminusb = c-b;
 
86
      *out++ = b + frac * (
 
87
                           cminusb - 0.1666667f * (1.-frac) * (
 
88
                                                               (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b)
 
89
                                                               )
 
90
                           );
 
91
    }
 
92
  return (w+6);
 
93
}
 
94
 
 
95
static void tabread4_tilde_set(t_tabread4_tilde *x, t_symbol *s)
 
96
{
 
97
  t_garray *a;
 
98
    
 
99
  x->x_arrayname = s;
 
100
  if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
 
101
    {
 
102
      if (*s->s_name)
 
103
        pd_error(x, "tabread4~~: %s: no such array", x->x_arrayname->s_name);
 
104
      x->x_vec = 0;
 
105
    }
 
106
  else if (!zarray_getarray(a, &x->x_npoints, &x->x_vec))
 
107
    {
 
108
      pd_error(x, "%s: bad template for tabread4~~", x->x_arrayname->s_name);
 
109
      x->x_vec = 0;
 
110
    }
 
111
  else garray_usedindsp(a);
 
112
}
 
113
 
 
114
static void tabread4_tilde_dsp(t_tabread4_tilde *x, t_signal **sp)
 
115
{
 
116
  tabread4_tilde_set(x, x->x_arrayname);
 
117
 
 
118
  dsp_add(tabread4_tilde_perform, 5, x,
 
119
          sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
 
120
 
 
121
}
 
122
 
 
123
static void tabread4_tilde_free(t_tabread4_tilde *x)
 
124
{
 
125
}
 
126
 
 
127
void tabread4_tilde_tilde_setup(void)
 
128
{
 
129
  tabread4_tilde_class = class_new(gensym("tabread4~~"),
 
130
                                   (t_newmethod)tabread4_tilde_new, (t_method)tabread4_tilde_free,
 
131
                                   sizeof(t_tabread4_tilde), 0, A_DEFSYM, 0);
 
132
  CLASS_MAINSIGNALIN(tabread4_tilde_class, t_tabread4_tilde, x_f);
 
133
  class_addmethod(tabread4_tilde_class, (t_method)tabread4_tilde_dsp,
 
134
                  gensym("dsp"), 0);
 
135
  class_addmethod(tabread4_tilde_class, (t_method)tabread4_tilde_set,
 
136
                  gensym("set"), A_SYMBOL, 0);
 
137
 
 
138
  zexy_register("tabread4~~");
 
139
}
 
140
 
 
141
void setup_tabread40x7e_tilde(void)
 
142
{
 
143
  tabread4_tilde_tilde_setup();
 
144
}
 
145
 
 
146
void setup_tabread40x7e0x7e(void)
 
147
{
 
148
  tabread4_tilde_tilde_setup();
 
149
}