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

« back to all changes in this revision

Viewing changes to src/0x3e0x7e.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
        finally :: some of the missing binops for signals :: >~
 
19
 
 
20
        1302:forum::f�r::uml�ute:2000
 
21
*/
 
22
 
 
23
#include "zexySIMD.h"
 
24
 
 
25
/* ------------------------ relational~ ----------------------------- */
 
26
 
 
27
/* ----------------------------- gt_tilde ----------------------------- */
 
28
static t_class *gt_tilde_class, *scalargt_tilde_class;
 
29
 
 
30
typedef struct _gt_tilde
 
31
{
 
32
  t_object x_obj;
 
33
  t_float x_f;
 
34
} t_gt_tilde;
 
35
 
 
36
typedef struct _scalargt_tilde
 
37
{
 
38
  t_object x_obj;
 
39
  t_float x_f;
 
40
  t_float x_g;              /* inlet value */
 
41
} t_scalargt_tilde;
 
42
 
 
43
static void *gt_tilde_new(t_symbol *s, int argc, t_atom *argv)
 
44
{
 
45
  ZEXY_USEVAR(s);
 
46
  if (argc > 1) post(">~: extra arguments ignored");
 
47
  if (argc) 
 
48
    {
 
49
      t_scalargt_tilde *x = (t_scalargt_tilde *)pd_new(scalargt_tilde_class);
 
50
      floatinlet_new(&x->x_obj, &x->x_g);
 
51
      x->x_g = atom_getfloatarg(0, argc, argv);
 
52
      outlet_new(&x->x_obj, &s_signal);
 
53
      x->x_f = 0;
 
54
      return (x);
 
55
    }
 
56
  else
 
57
    {
 
58
      t_gt_tilde *x = (t_gt_tilde *)pd_new(gt_tilde_class);
 
59
      inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
 
60
      outlet_new(&x->x_obj, &s_signal);
 
61
      x->x_f = 0;
 
62
      return (x);
 
63
    }
 
64
}
 
65
 
 
66
static t_int *gt_tilde_perform(t_int *w)
 
67
{
 
68
  t_sample *in1 = (t_sample *)(w[1]);
 
69
  t_sample *in2 = (t_sample *)(w[2]);
 
70
  t_sample *out = (t_sample *)(w[3]);
 
71
  int n = (int)(w[4]);
 
72
  while (n--) *out++ = *in1++ > *in2++; 
 
73
  return (w+5);
 
74
}
 
75
 
 
76
static t_int *gt_tilde_perf8(t_int *w)
 
77
{
 
78
  t_sample *in1 = (t_sample *)(w[1]);
 
79
  t_sample *in2 = (t_sample *)(w[2]);
 
80
  t_sample *out = (t_sample *)(w[3]);
 
81
  int n = (int)(w[4]);
 
82
  for (; n; n -= 8, in1 += 8, in2 += 8, out += 8)
 
83
    {
 
84
      t_sample f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3];
 
85
      t_sample f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7];
 
86
      
 
87
      t_sample g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3];
 
88
      t_sample g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7];
 
89
      
 
90
      out[0] = f0 > g0; out[1] = f1 > g1; out[2] = f2 > g2; out[3] = f3 > g3;
 
91
      out[4] = f4 > g4; out[5] = f5 > g5; out[6] = f6 > g6; out[7] = f7 > g7;
 
92
    }
 
93
  return (w+5);
 
94
}
 
95
 
 
96
static t_int *scalargt_tilde_perform(t_int *w)
 
97
{
 
98
  t_sample *in = (t_sample *)(w[1]);
 
99
  t_sample f = *(t_float *)(w[2]);
 
100
  t_sample *out = (t_sample *)(w[3]);
 
101
  int n = (int)(w[4]);
 
102
  while (n--) *out++ = *in++ > f; 
 
103
  return (w+5);
 
104
}
 
105
 
 
106
static t_int *scalargt_tilde_perf8(t_int *w)
 
107
{
 
108
  t_sample *in = (t_sample *)(w[1]);
 
109
  t_sample g = *(t_float *)(w[2]);
 
110
  t_sample *out = (t_sample *)(w[3]);
 
111
  int n = (int)(w[4]);
 
112
  for (; n; n -= 8, in += 8, out += 8)
 
113
    {
 
114
      t_sample f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3];
 
115
      t_sample f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7];
 
116
      
 
117
      out[0] = f0 > g; out[1] = f1 > g; out[2] = f2 > g; out[3] = f3 > g;
 
118
      out[4] = f4 > g; out[5] = f5 > g; out[6] = f6 > g; out[7] = f7 > g;
 
119
    }
 
120
  return (w+5);
 
121
}
 
122
#ifdef __SSE__
 
123
static t_int *gt_tilde_performSSE(t_int *w)
 
124
{
 
125
  __m128 *in1 = (__m128 *)(w[1]);
 
126
  __m128 *in2 = (__m128 *)(w[2]);
 
127
  __m128 *out = (__m128 *)(w[3]);
 
128
  int n = (int)(w[4])>>4;
 
129
  const __m128 one    = _mm_set1_ps(1.f);
 
130
 
 
131
  while (n--) {
 
132
    __m128 xmm0, xmm1;
 
133
    xmm0   = _mm_cmpgt_ps(in1[0], in2[0]);
 
134
    out[0] = _mm_and_ps  (xmm0 , one);
 
135
 
 
136
    xmm1   = _mm_cmpgt_ps(in1[1], in2[1]);
 
137
    out[1] = _mm_and_ps  (xmm1 , one);
 
138
 
 
139
    xmm0   = _mm_cmpgt_ps(in1[2], in2[2]);
 
140
    out[2] = _mm_and_ps  (xmm0 , one);
 
141
 
 
142
    xmm1   = _mm_cmpgt_ps(in1[3], in2[3]);
 
143
    out[3] = _mm_and_ps  (xmm1 , one);
 
144
 
 
145
    in1+=4;
 
146
    in2+=4;
 
147
    out+=4;
 
148
  }  
 
149
 
 
150
  return (w+5);
 
151
}
 
152
static t_int *scalargt_tilde_performSSE(t_int *w)
 
153
{
 
154
  __m128 *in = (__m128 *)(w[1]);
 
155
  __m128 *out = (__m128 *)(w[3]);
 
156
  float f = *(t_float *)(w[2]);
 
157
  __m128 scalar = _mm_set1_ps(f);
 
158
  int n = (int)(w[4])>>4;
 
159
  const __m128 one    = _mm_set1_ps(1.f);
 
160
 
 
161
  while (n--) {
 
162
    __m128 xmm0, xmm1;
 
163
    xmm0   = _mm_cmpgt_ps (in[0], scalar);
 
164
    out[0] = _mm_and_ps   (xmm0,  one);
 
165
 
 
166
    xmm1   = _mm_cmpgt_ps (in[1], scalar);
 
167
    out[1] = _mm_and_ps   (xmm1,  one);
 
168
 
 
169
    xmm0   = _mm_cmpgt_ps (in[2], scalar);
 
170
    out[2] = _mm_and_ps   (xmm0,  one);
 
171
 
 
172
    xmm1   = _mm_cmpgt_ps (in[3], scalar);
 
173
    out[3] = _mm_and_ps   (xmm1,  one);
 
174
 
 
175
    in +=4;
 
176
    out+=4;
 
177
  }
 
178
  return (w+5);
 
179
}
 
180
#endif /* __SSE__ */
 
181
 
 
182
 
 
183
static void gt_tilde_dsp(t_gt_tilde *x, t_signal **sp)
 
184
{
 
185
  t_sample*in1=sp[0]->s_vec;
 
186
  t_sample*in2=sp[1]->s_vec;
 
187
  t_sample*out=sp[2]->s_vec;
 
188
 
 
189
  int n=sp[0]->s_n;
 
190
 
 
191
  ZEXY_USEVAR(x);
 
192
 
 
193
#ifdef __SSE__
 
194
  if(
 
195
     Z_SIMD_CHKBLOCKSIZE(n)&&
 
196
     Z_SIMD_CHKALIGN(in1)&&
 
197
     Z_SIMD_CHKALIGN(in2)&&
 
198
     Z_SIMD_CHKALIGN(out)&&
 
199
     ZEXY_TYPE_EQUAL(t_sample, float)
 
200
     )
 
201
    {
 
202
      dsp_add(gt_tilde_performSSE, 4, in1, in2, out, n);
 
203
    } else
 
204
#endif
 
205
  if (n&7)
 
206
    dsp_add(gt_tilde_perform, 4, in1, in2, out, n);
 
207
  else  
 
208
    dsp_add(gt_tilde_perf8, 4, in1, in2, out, n);
 
209
}
 
210
 
 
211
static void scalargt_tilde_dsp(t_scalargt_tilde *x, t_signal **sp)
 
212
{
 
213
  t_sample*in =sp[0]->s_vec;
 
214
  t_sample*out=sp[1]->s_vec;
 
215
  int n       =sp[0]->s_n;
 
216
 
 
217
#ifdef __SSE__
 
218
  if(
 
219
     Z_SIMD_CHKBLOCKSIZE(n)&&
 
220
     Z_SIMD_CHKALIGN(in)&&
 
221
     Z_SIMD_CHKALIGN(out)&&
 
222
     ZEXY_TYPE_EQUAL(t_sample, float)
 
223
     )
 
224
    {
 
225
      dsp_add(scalargt_tilde_performSSE, 4, in, &x->x_g, out, n);
 
226
    } else
 
227
#endif
 
228
  if (n&7)
 
229
    dsp_add(scalargt_tilde_perform, 4, in, &x->x_g, out, n);
 
230
  else  
 
231
    dsp_add(scalargt_tilde_perf8,   4, in, &x->x_g, out, n);
 
232
}
 
233
 
 
234
static void gt_tilde_help(t_object*x)
 
235
{
 
236
  post("\n%c >~\t\t:: compare 2 signals", HEARTSYMBOL);
 
237
}
 
238
 
 
239
void setup_0x3e0x7e(void)
 
240
{
 
241
  gt_tilde_class = class_new(gensym(">~"), (t_newmethod)gt_tilde_new, 0,
 
242
                           sizeof(t_gt_tilde), 0, A_GIMME, 0);
 
243
  class_addmethod(gt_tilde_class, (t_method)gt_tilde_dsp, gensym("dsp"), 0);
 
244
  CLASS_MAINSIGNALIN(gt_tilde_class, t_gt_tilde, x_f);
 
245
  class_addmethod  (gt_tilde_class, (t_method)gt_tilde_help, gensym("help"), A_NULL);
 
246
  class_sethelpsymbol(gt_tilde_class, gensym("zigbinops"));
 
247
 
 
248
  scalargt_tilde_class = class_new(gensym(">~"), 0, 0,
 
249
                                 sizeof(t_scalargt_tilde), 0, 0);
 
250
  CLASS_MAINSIGNALIN(scalargt_tilde_class, t_scalargt_tilde, x_f);
 
251
  class_addmethod(scalargt_tilde_class, (t_method)scalargt_tilde_dsp, gensym("dsp"),
 
252
                  0);
 
253
  class_addmethod  (scalargt_tilde_class, (t_method)gt_tilde_help, gensym("help"), A_NULL);
 
254
  class_sethelpsymbol(scalargt_tilde_class, gensym("zigbinops"));
 
255
 
 
256
  zexy_register(">~");
 
257
}