Debian Codegraph @

src/objects/arithmeticmodule.c

raw
1 /**************************************************************************
2 * Copyright 2009-2015 Olivier Belanger *
3 * *
4 * This file is part of pyo, a python module to help digital signal *
5 * processing script creation. *
6 * *
7 * pyo is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU Lesser General Public License as *
9 * published by the Free Software Foundation, either version 3 of the *
10 * License, or (at your option) any later version. *
11 * *
12 * pyo is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Lesser General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with pyo. If not, see <http://www.gnu.org/licenses/>. *
19 *************************************************************************/
20
21 #include <Python.h>
22 #include "structmember.h"
23 #include <math.h>
24 #include "pyomodule.h"
25 #include "streammodule.h"
26 #include "servermodule.h"
27 #include "dummymodule.h"
28
29 /************/
30 /* M_Sin */
31 /************/
32 typedef struct
33 {
34 pyo_audio_HEAD
35 PyObject *input;
36 Stream *input_stream;
37 int modebuffer[2]; // need at least 2 slots for mul & add
38 } M_Sin;
39
40 static void
41 M_Sin_process(M_Sin *self)
42 {
43 int i;
44 MYFLT *in = Stream_getData((Stream *)self->input_stream);
45
46 for (i = 0; i < self->bufsize; i++)
47 {
48 self->data[i] = MYSIN(in[i]);
49 }
50 }
51
52 static void M_Sin_postprocessing_ii(M_Sin *self) { POST_PROCESSING_II };
53 static void M_Sin_postprocessing_ai(M_Sin *self) { POST_PROCESSING_AI };
54 static void M_Sin_postprocessing_ia(M_Sin *self) { POST_PROCESSING_IA };
55 static void M_Sin_postprocessing_aa(M_Sin *self) { POST_PROCESSING_AA };
56 static void M_Sin_postprocessing_ireva(M_Sin *self) { POST_PROCESSING_IREVA };
57 static void M_Sin_postprocessing_areva(M_Sin *self) { POST_PROCESSING_AREVA };
58 static void M_Sin_postprocessing_revai(M_Sin *self) { POST_PROCESSING_REVAI };
59 static void M_Sin_postprocessing_revaa(M_Sin *self) { POST_PROCESSING_REVAA };
60 static void M_Sin_postprocessing_revareva(M_Sin *self) { POST_PROCESSING_REVAREVA };
61
62 static void
63 M_Sin_setProcMode(M_Sin *self)
64 {
65 int muladdmode;
66 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
67
68 self->proc_func_ptr = M_Sin_process;
69
70 switch (muladdmode)
71 {
72 case 0:
73 self->muladd_func_ptr = M_Sin_postprocessing_ii;
74 break;
75
76 case 1:
77 self->muladd_func_ptr = M_Sin_postprocessing_ai;
78 break;
79
80 case 2:
81 self->muladd_func_ptr = M_Sin_postprocessing_revai;
82 break;
83
84 case 10:
85 self->muladd_func_ptr = M_Sin_postprocessing_ia;
86 break;
87
88 case 11:
89 self->muladd_func_ptr = M_Sin_postprocessing_aa;
90 break;
91
92 case 12:
93 self->muladd_func_ptr = M_Sin_postprocessing_revaa;
94 break;
95
96 case 20:
97 self->muladd_func_ptr = M_Sin_postprocessing_ireva;
98 break;
99
100 case 21:
101 self->muladd_func_ptr = M_Sin_postprocessing_areva;
102 break;
103
104 case 22:
105 self->muladd_func_ptr = M_Sin_postprocessing_revareva;
106 break;
107 }
108 }
109
110 static void
111 M_Sin_compute_next_data_frame(M_Sin *self)
112 {
113 (*self->proc_func_ptr)(self);
114 (*self->muladd_func_ptr)(self);
115 }
116
117 static int
118 M_Sin_traverse(M_Sin *self, visitproc visit, void *arg)
119 {
120 pyo_VISIT
121 Py_VISIT(self->input);
122 return 0;
123 }
124
125 static int
126 M_Sin_clear(M_Sin *self)
127 {
128 pyo_CLEAR
129 Py_CLEAR(self->input);
130 return 0;
131 }
132
133 static void
134 M_Sin_dealloc(M_Sin* self)
135 {
136 pyo_DEALLOC
137 M_Sin_clear(self);
138 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
139 Py_TYPE(self)->tp_free((PyObject*)self);
140 }
141
142 static PyObject *
143 M_Sin_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
144 {
145 int i;
146 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
147 M_Sin *self;
148 self = (M_Sin *)type->tp_alloc(type, 0);
149
150 self->modebuffer[0] = 0;
151 self->modebuffer[1] = 0;
152
153 INIT_OBJECT_COMMON
154 Stream_setFunctionPtr(self->stream, M_Sin_compute_next_data_frame);
155 self->mode_func_ptr = M_Sin_setProcMode;
156
157 static char *kwlist[] = {"input", "mul", "add", NULL};
158
159 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
160 Py_RETURN_NONE;
161
162 INIT_INPUT_STREAM
163
164 if (multmp)
165 {
166 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
167 }
168
169 if (addtmp)
170 {
171 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
172 }
173
174 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
175
176 (*self->mode_func_ptr)(self);
177
178 return (PyObject *)self;
179 }
180
181 static PyObject * M_Sin_getServer(M_Sin* self) { GET_SERVER };
182 static PyObject * M_Sin_getStream(M_Sin* self) { GET_STREAM };
183 static PyObject * M_Sin_setMul(M_Sin *self, PyObject *arg) { SET_MUL };
184 static PyObject * M_Sin_setAdd(M_Sin *self, PyObject *arg) { SET_ADD };
185 static PyObject * M_Sin_setSub(M_Sin *self, PyObject *arg) { SET_SUB };
186 static PyObject * M_Sin_setDiv(M_Sin *self, PyObject *arg) { SET_DIV };
187
188 static PyObject * M_Sin_play(M_Sin *self, PyObject *args, PyObject *kwds) { PLAY };
189 static PyObject * M_Sin_out(M_Sin *self, PyObject *args, PyObject *kwds) { OUT };
190 static PyObject * M_Sin_stop(M_Sin *self, PyObject *args, PyObject *kwds) { STOP };
191
192 static PyObject * M_Sin_multiply(M_Sin *self, PyObject *arg) { MULTIPLY };
193 static PyObject * M_Sin_inplace_multiply(M_Sin *self, PyObject *arg) { INPLACE_MULTIPLY };
194 static PyObject * M_Sin_add(M_Sin *self, PyObject *arg) { ADD };
195 static PyObject * M_Sin_inplace_add(M_Sin *self, PyObject *arg) { INPLACE_ADD };
196 static PyObject * M_Sin_sub(M_Sin *self, PyObject *arg) { SUB };
197 static PyObject * M_Sin_inplace_sub(M_Sin *self, PyObject *arg) { INPLACE_SUB };
198 static PyObject * M_Sin_div(M_Sin *self, PyObject *arg) { DIV };
199 static PyObject * M_Sin_inplace_div(M_Sin *self, PyObject *arg) { INPLACE_DIV };
200
201 static PyMemberDef M_Sin_members[] =
202 {
203 {"server", T_OBJECT_EX, offsetof(M_Sin, server), 0, "Pyo server."},
204 {"stream", T_OBJECT_EX, offsetof(M_Sin, stream), 0, "Stream object."},
205 {"input", T_OBJECT_EX, offsetof(M_Sin, input), 0, "Input sound object."},
206 {"mul", T_OBJECT_EX, offsetof(M_Sin, mul), 0, "Mul factor."},
207 {"add", T_OBJECT_EX, offsetof(M_Sin, add), 0, "Add factor."},
208 {NULL} /* Sentinel */
209 };
210
211 static PyMethodDef M_Sin_methods[] =
212 {
213 {"getServer", (PyCFunction)M_Sin_getServer, METH_NOARGS, "Returns server object."},
214 {"_getStream", (PyCFunction)M_Sin_getStream, METH_NOARGS, "Returns stream object."},
215 {"play", (PyCFunction)M_Sin_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
216 {"stop", (PyCFunction)M_Sin_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
217 {"out", (PyCFunction)M_Sin_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
218 {"setMul", (PyCFunction)M_Sin_setMul, METH_O, "Sets oscillator mul factor."},
219 {"setAdd", (PyCFunction)M_Sin_setAdd, METH_O, "Sets oscillator add factor."},
220 {"setSub", (PyCFunction)M_Sin_setSub, METH_O, "Sets inverse add factor."},
221 {"setDiv", (PyCFunction)M_Sin_setDiv, METH_O, "Sets inverse mul factor."},
222 {NULL} /* Sentinel */
223 };
224
225 static PyNumberMethods M_Sin_as_number =
226 {
227 (binaryfunc)M_Sin_add, /*nb_add*/
228 (binaryfunc)M_Sin_sub, /*nb_subtract*/
229 (binaryfunc)M_Sin_multiply, /*nb_multiply*/
230 0, /*nb_remainder*/
231 0, /*nb_divmod*/
232 0, /*nb_power*/
233 0, /*nb_neg*/
234 0, /*nb_pos*/
235 0, /*(unaryfunc)array_abs,*/
236 0, /*nb_nonzero*/
237 0, /*nb_invert*/
238 0, /*nb_lshift*/
239 0, /*nb_rshift*/
240 0, /*nb_and*/
241 0, /*nb_xor*/
242 0, /*nb_or*/
243 0, /*nb_int*/
244 0, /*nb_long*/
245 0, /*nb_float*/
246 (binaryfunc)M_Sin_inplace_add, /*inplace_add*/
247 (binaryfunc)M_Sin_inplace_sub, /*inplace_subtract*/
248 (binaryfunc)M_Sin_inplace_multiply, /*inplace_multiply*/
249 0, /*inplace_remainder*/
250 0, /*inplace_power*/
251 0, /*inplace_lshift*/
252 0, /*inplace_rshift*/
253 0, /*inplace_and*/
254 0, /*inplace_xor*/
255 0, /*inplace_or*/
256 0, /*nb_floor_divide*/
257 (binaryfunc)M_Sin_div, /*nb_true_divide*/
258 0, /*nb_inplace_floor_divide*/
259 (binaryfunc)M_Sin_inplace_div, /*nb_inplace_true_divide*/
260 0, /* nb_index */
261 };
262
263 PyTypeObject M_SinType =
264 {
265 PyVarObject_HEAD_INIT(NULL, 0)
266 "_pyo.M_Sin_base", /*tp_name*/
267 sizeof(M_Sin), /*tp_basicsize*/
268 0, /*tp_itemsize*/
269 (destructor)M_Sin_dealloc, /*tp_dealloc*/
270 0, /*tp_print*/
271 0, /*tp_getattr*/
272 0, /*tp_setattr*/
273 0, /*tp_as_async (tp_compare in Python 2)*/
274 0, /*tp_repr*/
275 &M_Sin_as_number, /*tp_as_number*/
276 0, /*tp_as_sequence*/
277 0, /*tp_as_mapping*/
278 0, /*tp_hash */
279 0, /*tp_call*/
280 0, /*tp_str*/
281 0, /*tp_getattro*/
282 0, /*tp_setattro*/
283 0, /*tp_as_buffer*/
284 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
285 "M_Sin objects. Performs sin function on audio samples.", /* tp_doc */
286 (traverseproc)M_Sin_traverse, /* tp_traverse */
287 (inquiry)M_Sin_clear, /* tp_clear */
288 0, /* tp_richcompare */
289 0, /* tp_weaklistoffset */
290 0, /* tp_iter */
291 0, /* tp_iternext */
292 M_Sin_methods, /* tp_methods */
293 M_Sin_members, /* tp_members */
294 0, /* tp_getset */
295 0, /* tp_base */
296 0, /* tp_dict */
297 0, /* tp_descr_get */
298 0, /* tp_descr_set */
299 0, /* tp_dictoffset */
300 0, /* tp_init */
301 0, /* tp_alloc */
302 M_Sin_new, /* tp_new */
303 };
304
305 /************/
306 /* M_Cos */
307 /************/
308 typedef struct
309 {
310 pyo_audio_HEAD
311 PyObject *input;
312 Stream *input_stream;
313 int modebuffer[2]; // need at least 2 slots for mul & add
314 } M_Cos;
315
316 static void
317 M_Cos_process(M_Cos *self)
318 {
319 int i;
320 MYFLT *in = Stream_getData((Stream *)self->input_stream);
321
322 for (i = 0; i < self->bufsize; i++)
323 {
324 self->data[i] = MYCOS(in[i]);
325 }
326 }
327
328 static void M_Cos_postprocessing_ii(M_Cos *self) { POST_PROCESSING_II };
329 static void M_Cos_postprocessing_ai(M_Cos *self) { POST_PROCESSING_AI };
330 static void M_Cos_postprocessing_ia(M_Cos *self) { POST_PROCESSING_IA };
331 static void M_Cos_postprocessing_aa(M_Cos *self) { POST_PROCESSING_AA };
332 static void M_Cos_postprocessing_ireva(M_Cos *self) { POST_PROCESSING_IREVA };
333 static void M_Cos_postprocessing_areva(M_Cos *self) { POST_PROCESSING_AREVA };
334 static void M_Cos_postprocessing_revai(M_Cos *self) { POST_PROCESSING_REVAI };
335 static void M_Cos_postprocessing_revaa(M_Cos *self) { POST_PROCESSING_REVAA };
336 static void M_Cos_postprocessing_revareva(M_Cos *self) { POST_PROCESSING_REVAREVA };
337
338 static void
339 M_Cos_setProcMode(M_Cos *self)
340 {
341 int muladdmode;
342 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
343
344 self->proc_func_ptr = M_Cos_process;
345
346 switch (muladdmode)
347 {
348 case 0:
349 self->muladd_func_ptr = M_Cos_postprocessing_ii;
350 break;
351
352 case 1:
353 self->muladd_func_ptr = M_Cos_postprocessing_ai;
354 break;
355
356 case 2:
357 self->muladd_func_ptr = M_Cos_postprocessing_revai;
358 break;
359
360 case 10:
361 self->muladd_func_ptr = M_Cos_postprocessing_ia;
362 break;
363
364 case 11:
365 self->muladd_func_ptr = M_Cos_postprocessing_aa;
366 break;
367
368 case 12:
369 self->muladd_func_ptr = M_Cos_postprocessing_revaa;
370 break;
371
372 case 20:
373 self->muladd_func_ptr = M_Cos_postprocessing_ireva;
374 break;
375
376 case 21:
377 self->muladd_func_ptr = M_Cos_postprocessing_areva;
378 break;
379
380 case 22:
381 self->muladd_func_ptr = M_Cos_postprocessing_revareva;
382 break;
383 }
384 }
385
386 static void
387 M_Cos_compute_next_data_frame(M_Cos *self)
388 {
389 (*self->proc_func_ptr)(self);
390 (*self->muladd_func_ptr)(self);
391 }
392
393 static int
394 M_Cos_traverse(M_Cos *self, visitproc visit, void *arg)
395 {
396 pyo_VISIT
397 Py_VISIT(self->input);
398 return 0;
399 }
400
401 static int
402 M_Cos_clear(M_Cos *self)
403 {
404 pyo_CLEAR
405 Py_CLEAR(self->input);
406 return 0;
407 }
408
409 static void
410 M_Cos_dealloc(M_Cos* self)
411 {
412 pyo_DEALLOC
413 M_Cos_clear(self);
414 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
415 Py_TYPE(self)->tp_free((PyObject*)self);
416 }
417
418 static PyObject *
419 M_Cos_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
420 {
421 int i;
422 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
423 M_Cos *self;
424 self = (M_Cos *)type->tp_alloc(type, 0);
425
426 self->modebuffer[0] = 0;
427 self->modebuffer[1] = 0;
428
429 INIT_OBJECT_COMMON
430 Stream_setFunctionPtr(self->stream, M_Cos_compute_next_data_frame);
431 self->mode_func_ptr = M_Cos_setProcMode;
432
433 static char *kwlist[] = {"input", "mul", "add", NULL};
434
435 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
436 Py_RETURN_NONE;
437
438 INIT_INPUT_STREAM
439
440 if (multmp)
441 {
442 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
443 }
444
445 if (addtmp)
446 {
447 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
448 }
449
450 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
451
452 (*self->mode_func_ptr)(self);
453
454 return (PyObject *)self;
455 }
456
457 static PyObject * M_Cos_getServer(M_Cos* self) { GET_SERVER };
458 static PyObject * M_Cos_getStream(M_Cos* self) { GET_STREAM };
459 static PyObject * M_Cos_setMul(M_Cos *self, PyObject *arg) { SET_MUL };
460 static PyObject * M_Cos_setAdd(M_Cos *self, PyObject *arg) { SET_ADD };
461 static PyObject * M_Cos_setSub(M_Cos *self, PyObject *arg) { SET_SUB };
462 static PyObject * M_Cos_setDiv(M_Cos *self, PyObject *arg) { SET_DIV };
463
464 static PyObject * M_Cos_play(M_Cos *self, PyObject *args, PyObject *kwds) { PLAY };
465 static PyObject * M_Cos_out(M_Cos *self, PyObject *args, PyObject *kwds) { OUT };
466 static PyObject * M_Cos_stop(M_Cos *self, PyObject *args, PyObject *kwds) { STOP };
467
468 static PyObject * M_Cos_multiply(M_Cos *self, PyObject *arg) { MULTIPLY };
469 static PyObject * M_Cos_inplace_multiply(M_Cos *self, PyObject *arg) { INPLACE_MULTIPLY };
470 static PyObject * M_Cos_add(M_Cos *self, PyObject *arg) { ADD };
471 static PyObject * M_Cos_inplace_add(M_Cos *self, PyObject *arg) { INPLACE_ADD };
472 static PyObject * M_Cos_sub(M_Cos *self, PyObject *arg) { SUB };
473 static PyObject * M_Cos_inplace_sub(M_Cos *self, PyObject *arg) { INPLACE_SUB };
474 static PyObject * M_Cos_div(M_Cos *self, PyObject *arg) { DIV };
475 static PyObject * M_Cos_inplace_div(M_Cos *self, PyObject *arg) { INPLACE_DIV };
476
477 static PyMemberDef M_Cos_members[] =
478 {
479 {"server", T_OBJECT_EX, offsetof(M_Cos, server), 0, "Pyo server."},
480 {"stream", T_OBJECT_EX, offsetof(M_Cos, stream), 0, "Stream object."},
481 {"input", T_OBJECT_EX, offsetof(M_Cos, input), 0, "Input sound object."},
482 {"mul", T_OBJECT_EX, offsetof(M_Cos, mul), 0, "Mul factor."},
483 {"add", T_OBJECT_EX, offsetof(M_Cos, add), 0, "Add factor."},
484 {NULL} /* Sentinel */
485 };
486
487 static PyMethodDef M_Cos_methods[] =
488 {
489 {"getServer", (PyCFunction)M_Cos_getServer, METH_NOARGS, "Returns server object."},
490 {"_getStream", (PyCFunction)M_Cos_getStream, METH_NOARGS, "Returns stream object."},
491 {"play", (PyCFunction)M_Cos_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
492 {"stop", (PyCFunction)M_Cos_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
493 {"out", (PyCFunction)M_Cos_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
494 {"setMul", (PyCFunction)M_Cos_setMul, METH_O, "Sets oscillator mul factor."},
495 {"setAdd", (PyCFunction)M_Cos_setAdd, METH_O, "Sets oscillator add factor."},
496 {"setSub", (PyCFunction)M_Cos_setSub, METH_O, "Sets inverse add factor."},
497 {"setDiv", (PyCFunction)M_Cos_setDiv, METH_O, "Sets inverse mul factor."},
498 {NULL} /* Sentinel */
499 };
500
501 static PyNumberMethods M_Cos_as_number =
502 {
503 (binaryfunc)M_Cos_add, /*nb_add*/
504 (binaryfunc)M_Cos_sub, /*nb_subtract*/
505 (binaryfunc)M_Cos_multiply, /*nb_multiply*/
506 0, /*nb_remainder*/
507 0, /*nb_divmod*/
508 0, /*nb_power*/
509 0, /*nb_neg*/
510 0, /*nb_pos*/
511 0, /*(unaryfunc)array_abs,*/
512 0, /*nb_nonzero*/
513 0, /*nb_invert*/
514 0, /*nb_lshift*/
515 0, /*nb_rshift*/
516 0, /*nb_and*/
517 0, /*nb_xor*/
518 0, /*nb_or*/
519 0, /*nb_int*/
520 0, /*nb_long*/
521 0, /*nb_float*/
522 (binaryfunc)M_Cos_inplace_add, /*inplace_add*/
523 (binaryfunc)M_Cos_inplace_sub, /*inplace_subtract*/
524 (binaryfunc)M_Cos_inplace_multiply, /*inplace_multiply*/
525 0, /*inplace_remainder*/
526 0, /*inplace_power*/
527 0, /*inplace_lshift*/
528 0, /*inplace_rshift*/
529 0, /*inplace_and*/
530 0, /*inplace_xor*/
531 0, /*inplace_or*/
532 0, /*nb_floor_divide*/
533 (binaryfunc)M_Cos_div, /*nb_true_divide*/
534 0, /*nb_inplace_floor_divide*/
535 (binaryfunc)M_Cos_inplace_div, /*nb_inplace_true_divide*/
536 0, /* nb_index */
537 };
538
539 PyTypeObject M_CosType =
540 {
541 PyVarObject_HEAD_INIT(NULL, 0)
542 "_pyo.M_Cos_base", /*tp_name*/
543 sizeof(M_Cos), /*tp_basicsize*/
544 0, /*tp_itemsize*/
545 (destructor)M_Cos_dealloc, /*tp_dealloc*/
546 0, /*tp_print*/
547 0, /*tp_getattr*/
548 0, /*tp_setattr*/
549 0, /*tp_as_async (tp_compare in Python 2)*/
550 0, /*tp_repr*/
551 &M_Cos_as_number, /*tp_as_number*/
552 0, /*tp_as_sequence*/
553 0, /*tp_as_mapping*/
554 0, /*tp_hash */
555 0, /*tp_call*/
556 0, /*tp_str*/
557 0, /*tp_getattro*/
558 0, /*tp_setattro*/
559 0, /*tp_as_buffer*/
560 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
561 "M_Cos objects. Performs sin function on audio samples.", /* tp_doc */
562 (traverseproc)M_Cos_traverse, /* tp_traverse */
563 (inquiry)M_Cos_clear, /* tp_clear */
564 0, /* tp_richcompare */
565 0, /* tp_weaklistoffset */
566 0, /* tp_iter */
567 0, /* tp_iternext */
568 M_Cos_methods, /* tp_methods */
569 M_Cos_members, /* tp_members */
570 0, /* tp_getset */
571 0, /* tp_base */
572 0, /* tp_dict */
573 0, /* tp_descr_get */
574 0, /* tp_descr_set */
575 0, /* tp_dictoffset */
576 0, /* tp_init */
577 0, /* tp_alloc */
578 M_Cos_new, /* tp_new */
579 };
580
581 /************/
582 /* M_Tan */
583 /************/
584 typedef struct
585 {
586 pyo_audio_HEAD
587 PyObject *input;
588 Stream *input_stream;
589 int modebuffer[2]; // need at least 2 slots for mul & add
590 } M_Tan;
591
592 static void
593 M_Tan_process(M_Tan *self)
594 {
595 int i;
596 MYFLT *in = Stream_getData((Stream *)self->input_stream);
597
598 for (i = 0; i < self->bufsize; i++)
599 {
600 self->data[i] = MYTAN(in[i]);
601 }
602 }
603
604 static void M_Tan_postprocessing_ii(M_Tan *self) { POST_PROCESSING_II };
605 static void M_Tan_postprocessing_ai(M_Tan *self) { POST_PROCESSING_AI };
606 static void M_Tan_postprocessing_ia(M_Tan *self) { POST_PROCESSING_IA };
607 static void M_Tan_postprocessing_aa(M_Tan *self) { POST_PROCESSING_AA };
608 static void M_Tan_postprocessing_ireva(M_Tan *self) { POST_PROCESSING_IREVA };
609 static void M_Tan_postprocessing_areva(M_Tan *self) { POST_PROCESSING_AREVA };
610 static void M_Tan_postprocessing_revai(M_Tan *self) { POST_PROCESSING_REVAI };
611 static void M_Tan_postprocessing_revaa(M_Tan *self) { POST_PROCESSING_REVAA };
612 static void M_Tan_postprocessing_revareva(M_Tan *self) { POST_PROCESSING_REVAREVA };
613
614 static void
615 M_Tan_setProcMode(M_Tan *self)
616 {
617 int muladdmode;
618 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
619
620 self->proc_func_ptr = M_Tan_process;
621
622 switch (muladdmode)
623 {
624 case 0:
625 self->muladd_func_ptr = M_Tan_postprocessing_ii;
626 break;
627
628 case 1:
629 self->muladd_func_ptr = M_Tan_postprocessing_ai;
630 break;
631
632 case 2:
633 self->muladd_func_ptr = M_Tan_postprocessing_revai;
634 break;
635
636 case 10:
637 self->muladd_func_ptr = M_Tan_postprocessing_ia;
638 break;
639
640 case 11:
641 self->muladd_func_ptr = M_Tan_postprocessing_aa;
642 break;
643
644 case 12:
645 self->muladd_func_ptr = M_Tan_postprocessing_revaa;
646 break;
647
648 case 20:
649 self->muladd_func_ptr = M_Tan_postprocessing_ireva;
650 break;
651
652 case 21:
653 self->muladd_func_ptr = M_Tan_postprocessing_areva;
654 break;
655
656 case 22:
657 self->muladd_func_ptr = M_Tan_postprocessing_revareva;
658 break;
659 }
660 }
661
662 static void
663 M_Tan_compute_next_data_frame(M_Tan *self)
664 {
665 (*self->proc_func_ptr)(self);
666 (*self->muladd_func_ptr)(self);
667 }
668
669 static int
670 M_Tan_traverse(M_Tan *self, visitproc visit, void *arg)
671 {
672 pyo_VISIT
673 Py_VISIT(self->input);
674 return 0;
675 }
676
677 static int
678 M_Tan_clear(M_Tan *self)
679 {
680 pyo_CLEAR
681 Py_CLEAR(self->input);
682 return 0;
683 }
684
685 static void
686 M_Tan_dealloc(M_Tan* self)
687 {
688 pyo_DEALLOC
689 M_Tan_clear(self);
690 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
691 Py_TYPE(self)->tp_free((PyObject*)self);
692 }
693
694 static PyObject *
695 M_Tan_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
696 {
697 int i;
698 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
699 M_Tan *self;
700 self = (M_Tan *)type->tp_alloc(type, 0);
701
702 self->modebuffer[0] = 0;
703 self->modebuffer[1] = 0;
704
705 INIT_OBJECT_COMMON
706 Stream_setFunctionPtr(self->stream, M_Tan_compute_next_data_frame);
707 self->mode_func_ptr = M_Tan_setProcMode;
708
709 static char *kwlist[] = {"input", "mul", "add", NULL};
710
711 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
712 Py_RETURN_NONE;
713
714 INIT_INPUT_STREAM
715
716 if (multmp)
717 {
718 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
719 }
720
721 if (addtmp)
722 {
723 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
724 }
725
726 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
727
728 (*self->mode_func_ptr)(self);
729
730 return (PyObject *)self;
731 }
732
733 static PyObject * M_Tan_getServer(M_Tan* self) { GET_SERVER };
734 static PyObject * M_Tan_getStream(M_Tan* self) { GET_STREAM };
735 static PyObject * M_Tan_setMul(M_Tan *self, PyObject *arg) { SET_MUL };
736 static PyObject * M_Tan_setAdd(M_Tan *self, PyObject *arg) { SET_ADD };
737 static PyObject * M_Tan_setSub(M_Tan *self, PyObject *arg) { SET_SUB };
738 static PyObject * M_Tan_setDiv(M_Tan *self, PyObject *arg) { SET_DIV };
739
740 static PyObject * M_Tan_play(M_Tan *self, PyObject *args, PyObject *kwds) { PLAY };
741 static PyObject * M_Tan_out(M_Tan *self, PyObject *args, PyObject *kwds) { OUT };
742 static PyObject * M_Tan_stop(M_Tan *self, PyObject *args, PyObject *kwds) { STOP };
743
744 static PyObject * M_Tan_multiply(M_Tan *self, PyObject *arg) { MULTIPLY };
745 static PyObject * M_Tan_inplace_multiply(M_Tan *self, PyObject *arg) { INPLACE_MULTIPLY };
746 static PyObject * M_Tan_add(M_Tan *self, PyObject *arg) { ADD };
747 static PyObject * M_Tan_inplace_add(M_Tan *self, PyObject *arg) { INPLACE_ADD };
748 static PyObject * M_Tan_sub(M_Tan *self, PyObject *arg) { SUB };
749 static PyObject * M_Tan_inplace_sub(M_Tan *self, PyObject *arg) { INPLACE_SUB };
750 static PyObject * M_Tan_div(M_Tan *self, PyObject *arg) { DIV };
751 static PyObject * M_Tan_inplace_div(M_Tan *self, PyObject *arg) { INPLACE_DIV };
752
753 static PyMemberDef M_Tan_members[] =
754 {
755 {"server", T_OBJECT_EX, offsetof(M_Tan, server), 0, "Pyo server."},
756 {"stream", T_OBJECT_EX, offsetof(M_Tan, stream), 0, "Stream object."},
757 {"input", T_OBJECT_EX, offsetof(M_Tan, input), 0, "Input sound object."},
758 {"mul", T_OBJECT_EX, offsetof(M_Tan, mul), 0, "Mul factor."},
759 {"add", T_OBJECT_EX, offsetof(M_Tan, add), 0, "Add factor."},
760 {NULL} /* Sentinel */
761 };
762
763 static PyMethodDef M_Tan_methods[] =
764 {
765 {"getServer", (PyCFunction)M_Tan_getServer, METH_NOARGS, "Returns server object."},
766 {"_getStream", (PyCFunction)M_Tan_getStream, METH_NOARGS, "Returns stream object."},
767 {"play", (PyCFunction)M_Tan_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
768 {"stop", (PyCFunction)M_Tan_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
769 {"out", (PyCFunction)M_Tan_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
770 {"setMul", (PyCFunction)M_Tan_setMul, METH_O, "Sets oscillator mul factor."},
771 {"setAdd", (PyCFunction)M_Tan_setAdd, METH_O, "Sets oscillator add factor."},
772 {"setSub", (PyCFunction)M_Tan_setSub, METH_O, "Sets inverse add factor."},
773 {"setDiv", (PyCFunction)M_Tan_setDiv, METH_O, "Sets inverse mul factor."},
774 {NULL} /* Sentinel */
775 };
776
777 static PyNumberMethods M_Tan_as_number =
778 {
779 (binaryfunc)M_Tan_add, /*nb_add*/
780 (binaryfunc)M_Tan_sub, /*nb_subtract*/
781 (binaryfunc)M_Tan_multiply, /*nb_multiply*/
782 0, /*nb_remainder*/
783 0, /*nb_divmod*/
784 0, /*nb_power*/
785 0, /*nb_neg*/
786 0, /*nb_pos*/
787 0, /*(unaryfunc)array_abs,*/
788 0, /*nb_nonzero*/
789 0, /*nb_invert*/
790 0, /*nb_lshift*/
791 0, /*nb_rshift*/
792 0, /*nb_and*/
793 0, /*nb_xor*/
794 0, /*nb_or*/
795 0, /*nb_int*/
796 0, /*nb_long*/
797 0, /*nb_float*/
798 (binaryfunc)M_Tan_inplace_add, /*inplace_add*/
799 (binaryfunc)M_Tan_inplace_sub, /*inplace_subtract*/
800 (binaryfunc)M_Tan_inplace_multiply, /*inplace_multiply*/
801 0, /*inplace_remainder*/
802 0, /*inplace_power*/
803 0, /*inplace_lshift*/
804 0, /*inplace_rshift*/
805 0, /*inplace_and*/
806 0, /*inplace_xor*/
807 0, /*inplace_or*/
808 0, /*nb_floor_divide*/
809 (binaryfunc)M_Tan_div, /*nb_true_divide*/
810 0, /*nb_inplace_floor_divide*/
811 (binaryfunc)M_Tan_inplace_div, /*nb_inplace_true_divide*/
812 0, /* nb_index */
813 };
814
815 PyTypeObject M_TanType =
816 {
817 PyVarObject_HEAD_INIT(NULL, 0)
818 "_pyo.M_Tan_base", /*tp_name*/
819 sizeof(M_Tan), /*tp_basicsize*/
820 0, /*tp_itemsize*/
821 (destructor)M_Tan_dealloc, /*tp_dealloc*/
822 0, /*tp_print*/
823 0, /*tp_getattr*/
824 0, /*tp_setattr*/
825 0, /*tp_as_async (tp_compare in Python 2)*/
826 0, /*tp_repr*/
827 &M_Tan_as_number, /*tp_as_number*/
828 0, /*tp_as_sequence*/
829 0, /*tp_as_mapping*/
830 0, /*tp_hash */
831 0, /*tp_call*/
832 0, /*tp_str*/
833 0, /*tp_getattro*/
834 0, /*tp_setattro*/
835 0, /*tp_as_buffer*/
836 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
837 "M_Tan objects. Performs sin function on audio samples.", /* tp_doc */
838 (traverseproc)M_Tan_traverse, /* tp_traverse */
839 (inquiry)M_Tan_clear, /* tp_clear */
840 0, /* tp_richcompare */
841 0, /* tp_weaklistoffset */
842 0, /* tp_iter */
843 0, /* tp_iternext */
844 M_Tan_methods, /* tp_methods */
845 M_Tan_members, /* tp_members */
846 0, /* tp_getset */
847 0, /* tp_base */
848 0, /* tp_dict */
849 0, /* tp_descr_get */
850 0, /* tp_descr_set */
851 0, /* tp_dictoffset */
852 0, /* tp_init */
853 0, /* tp_alloc */
854 M_Tan_new, /* tp_new */
855 };
856
857 /************/
858 /* M_Abs */
859 /************/
860 typedef struct
861 {
862 pyo_audio_HEAD
863 PyObject *input;
864 Stream *input_stream;
865 int modebuffer[2]; // need at least 2 slots for mul & add
866 } M_Abs;
867
868 static void
869 M_Abs_process(M_Abs *self)
870 {
871 int i;
872 MYFLT inval;
873 MYFLT *in = Stream_getData((Stream *)self->input_stream);
874
875 for (i = 0; i < self->bufsize; i++)
876 {
877 inval = in[i];
878
879 if (inval < 0.0)
880 self->data[i] = -inval;
881 else
882 self->data[i] = inval;
883 }
884 }
885
886 static void M_Abs_postprocessing_ii(M_Abs *self) { POST_PROCESSING_II };
887 static void M_Abs_postprocessing_ai(M_Abs *self) { POST_PROCESSING_AI };
888 static void M_Abs_postprocessing_ia(M_Abs *self) { POST_PROCESSING_IA };
889 static void M_Abs_postprocessing_aa(M_Abs *self) { POST_PROCESSING_AA };
890 static void M_Abs_postprocessing_ireva(M_Abs *self) { POST_PROCESSING_IREVA };
891 static void M_Abs_postprocessing_areva(M_Abs *self) { POST_PROCESSING_AREVA };
892 static void M_Abs_postprocessing_revai(M_Abs *self) { POST_PROCESSING_REVAI };
893 static void M_Abs_postprocessing_revaa(M_Abs *self) { POST_PROCESSING_REVAA };
894 static void M_Abs_postprocessing_revareva(M_Abs *self) { POST_PROCESSING_REVAREVA };
895
896 static void
897 M_Abs_setProcMode(M_Abs *self)
898 {
899 int muladdmode;
900 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
901
902 self->proc_func_ptr = M_Abs_process;
903
904 switch (muladdmode)
905 {
906 case 0:
907 self->muladd_func_ptr = M_Abs_postprocessing_ii;
908 break;
909
910 case 1:
911 self->muladd_func_ptr = M_Abs_postprocessing_ai;
912 break;
913
914 case 2:
915 self->muladd_func_ptr = M_Abs_postprocessing_revai;
916 break;
917
918 case 10:
919 self->muladd_func_ptr = M_Abs_postprocessing_ia;
920 break;
921
922 case 11:
923 self->muladd_func_ptr = M_Abs_postprocessing_aa;
924 break;
925
926 case 12:
927 self->muladd_func_ptr = M_Abs_postprocessing_revaa;
928 break;
929
930 case 20:
931 self->muladd_func_ptr = M_Abs_postprocessing_ireva;
932 break;
933
934 case 21:
935 self->muladd_func_ptr = M_Abs_postprocessing_areva;
936 break;
937
938 case 22:
939 self->muladd_func_ptr = M_Abs_postprocessing_revareva;
940 break;
941 }
942 }
943
944 static void
945 M_Abs_compute_next_data_frame(M_Abs *self)
946 {
947 (*self->proc_func_ptr)(self);
948 (*self->muladd_func_ptr)(self);
949 }
950
951 static int
952 M_Abs_traverse(M_Abs *self, visitproc visit, void *arg)
953 {
954 pyo_VISIT
955 Py_VISIT(self->input);
956 return 0;
957 }
958
959 static int
960 M_Abs_clear(M_Abs *self)
961 {
962 pyo_CLEAR
963 Py_CLEAR(self->input);
964 return 0;
965 }
966
967 static void
968 M_Abs_dealloc(M_Abs* self)
969 {
970 pyo_DEALLOC
971 M_Abs_clear(self);
972 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
973 Py_TYPE(self)->tp_free((PyObject*)self);
974 }
975
976 static PyObject *
977 M_Abs_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
978 {
979 int i;
980 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
981 M_Abs *self;
982 self = (M_Abs *)type->tp_alloc(type, 0);
983
984 self->modebuffer[0] = 0;
985 self->modebuffer[1] = 0;
986
987 INIT_OBJECT_COMMON
988 Stream_setFunctionPtr(self->stream, M_Abs_compute_next_data_frame);
989 self->mode_func_ptr = M_Abs_setProcMode;
990
991 static char *kwlist[] = {"input", "mul", "add", NULL};
992
993 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
994 Py_RETURN_NONE;
995
996 INIT_INPUT_STREAM
997
998 if (multmp)
999 {
1000 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
1001 }
1002
1003 if (addtmp)
1004 {
1005 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
1006 }
1007
1008 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1009
1010 (*self->mode_func_ptr)(self);
1011
1012 return (PyObject *)self;
1013 }
1014
1015 static PyObject * M_Abs_getServer(M_Abs* self) { GET_SERVER };
1016 static PyObject * M_Abs_getStream(M_Abs* self) { GET_STREAM };
1017 static PyObject * M_Abs_setMul(M_Abs *self, PyObject *arg) { SET_MUL };
1018 static PyObject * M_Abs_setAdd(M_Abs *self, PyObject *arg) { SET_ADD };
1019 static PyObject * M_Abs_setSub(M_Abs *self, PyObject *arg) { SET_SUB };
1020 static PyObject * M_Abs_setDiv(M_Abs *self, PyObject *arg) { SET_DIV };
1021
1022 static PyObject * M_Abs_play(M_Abs *self, PyObject *args, PyObject *kwds) { PLAY };
1023 static PyObject * M_Abs_out(M_Abs *self, PyObject *args, PyObject *kwds) { OUT };
1024 static PyObject * M_Abs_stop(M_Abs *self, PyObject *args, PyObject *kwds) { STOP };
1025
1026 static PyObject * M_Abs_multiply(M_Abs *self, PyObject *arg) { MULTIPLY };
1027 static PyObject * M_Abs_inplace_multiply(M_Abs *self, PyObject *arg) { INPLACE_MULTIPLY };
1028 static PyObject * M_Abs_add(M_Abs *self, PyObject *arg) { ADD };
1029 static PyObject * M_Abs_inplace_add(M_Abs *self, PyObject *arg) { INPLACE_ADD };
1030 static PyObject * M_Abs_sub(M_Abs *self, PyObject *arg) { SUB };
1031 static PyObject * M_Abs_inplace_sub(M_Abs *self, PyObject *arg) { INPLACE_SUB };
1032 static PyObject * M_Abs_div(M_Abs *self, PyObject *arg) { DIV };
1033 static PyObject * M_Abs_inplace_div(M_Abs *self, PyObject *arg) { INPLACE_DIV };
1034
1035 static PyMemberDef M_Abs_members[] =
1036 {
1037 {"server", T_OBJECT_EX, offsetof(M_Abs, server), 0, "Pyo server."},
1038 {"stream", T_OBJECT_EX, offsetof(M_Abs, stream), 0, "Stream object."},
1039 {"input", T_OBJECT_EX, offsetof(M_Abs, input), 0, "Input sound object."},
1040 {"mul", T_OBJECT_EX, offsetof(M_Abs, mul), 0, "Mul factor."},
1041 {"add", T_OBJECT_EX, offsetof(M_Abs, add), 0, "Add factor."},
1042 {NULL} /* Sentinel */
1043 };
1044
1045 static PyMethodDef M_Abs_methods[] =
1046 {
1047 {"getServer", (PyCFunction)M_Abs_getServer, METH_NOARGS, "Returns server object."},
1048 {"_getStream", (PyCFunction)M_Abs_getStream, METH_NOARGS, "Returns stream object."},
1049 {"play", (PyCFunction)M_Abs_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1050 {"stop", (PyCFunction)M_Abs_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
1051 {"out", (PyCFunction)M_Abs_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
1052 {"setMul", (PyCFunction)M_Abs_setMul, METH_O, "Sets oscillator mul factor."},
1053 {"setAdd", (PyCFunction)M_Abs_setAdd, METH_O, "Sets oscillator add factor."},
1054 {"setSub", (PyCFunction)M_Abs_setSub, METH_O, "Sets inverse add factor."},
1055 {"setDiv", (PyCFunction)M_Abs_setDiv, METH_O, "Sets inverse mul factor."},
1056 {NULL} /* Sentinel */
1057 };
1058
1059 static PyNumberMethods M_Abs_as_number =
1060 {
1061 (binaryfunc)M_Abs_add, /*nb_add*/
1062 (binaryfunc)M_Abs_sub, /*nb_subtract*/
1063 (binaryfunc)M_Abs_multiply, /*nb_multiply*/
1064 0, /*nb_remainder*/
1065 0, /*nb_divmod*/
1066 0, /*nb_power*/
1067 0, /*nb_neg*/
1068 0, /*nb_pos*/
1069 0, /*(unaryfunc)array_abs,*/
1070 0, /*nb_nonzero*/
1071 0, /*nb_invert*/
1072 0, /*nb_lshift*/
1073 0, /*nb_rshift*/
1074 0, /*nb_and*/
1075 0, /*nb_xor*/
1076 0, /*nb_or*/
1077 0, /*nb_int*/
1078 0, /*nb_long*/
1079 0, /*nb_float*/
1080 (binaryfunc)M_Abs_inplace_add, /*inplace_add*/
1081 (binaryfunc)M_Abs_inplace_sub, /*inplace_subtract*/
1082 (binaryfunc)M_Abs_inplace_multiply, /*inplace_multiply*/
1083 0, /*inplace_remainder*/
1084 0, /*inplace_power*/
1085 0, /*inplace_lshift*/
1086 0, /*inplace_rshift*/
1087 0, /*inplace_and*/
1088 0, /*inplace_xor*/
1089 0, /*inplace_or*/
1090 0, /*nb_floor_divide*/
1091 (binaryfunc)M_Abs_div, /*nb_true_divide*/
1092 0, /*nb_inplace_floor_divide*/
1093 (binaryfunc)M_Abs_inplace_div, /*nb_inplace_true_divide*/
1094 0, /* nb_index */
1095 };
1096
1097 PyTypeObject M_AbsType =
1098 {
1099 PyVarObject_HEAD_INIT(NULL, 0)
1100 "_pyo.M_Abs_base", /*tp_name*/
1101 sizeof(M_Abs), /*tp_basicsize*/
1102 0, /*tp_itemsize*/
1103 (destructor)M_Abs_dealloc, /*tp_dealloc*/
1104 0, /*tp_print*/
1105 0, /*tp_getattr*/
1106 0, /*tp_setattr*/
1107 0, /*tp_as_async (tp_compare in Python 2)*/
1108 0, /*tp_repr*/
1109 &M_Abs_as_number, /*tp_as_number*/
1110 0, /*tp_as_sequence*/
1111 0, /*tp_as_mapping*/
1112 0, /*tp_hash */
1113 0, /*tp_call*/
1114 0, /*tp_str*/
1115 0, /*tp_getattro*/
1116 0, /*tp_setattro*/
1117 0, /*tp_as_buffer*/
1118 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
1119 "M_Abs objects. Performs abs function on audio samples.", /* tp_doc */
1120 (traverseproc)M_Abs_traverse, /* tp_traverse */
1121 (inquiry)M_Abs_clear, /* tp_clear */
1122 0, /* tp_richcompare */
1123 0, /* tp_weaklistoffset */
1124 0, /* tp_iter */
1125 0, /* tp_iternext */
1126 M_Abs_methods, /* tp_methods */
1127 M_Abs_members, /* tp_members */
1128 0, /* tp_getset */
1129 0, /* tp_base */
1130 0, /* tp_dict */
1131 0, /* tp_descr_get */
1132 0, /* tp_descr_set */
1133 0, /* tp_dictoffset */
1134 0, /* tp_init */
1135 0, /* tp_alloc */
1136 M_Abs_new, /* tp_new */
1137 };
1138
1139 /************/
1140 /* M_Sqrt */
1141 /************/
1142 typedef struct
1143 {
1144 pyo_audio_HEAD
1145 PyObject *input;
1146 Stream *input_stream;
1147 int modebuffer[2]; // need at least 2 slots for mul & add
1148 } M_Sqrt;
1149
1150 static void
1151 M_Sqrt_process(M_Sqrt *self)
1152 {
1153 int i;
1154 MYFLT inval;
1155 MYFLT *in = Stream_getData((Stream *)self->input_stream);
1156
1157 for (i = 0; i < self->bufsize; i++)
1158 {
1159 inval = in[i];
1160
1161 if (inval < 0.0)
1162 self->data[i] = 0.0;
1163 else
1164 self->data[i] = MYSQRT(inval);
1165 }
1166 }
1167
1168 static void M_Sqrt_postprocessing_ii(M_Sqrt *self) { POST_PROCESSING_II };
1169 static void M_Sqrt_postprocessing_ai(M_Sqrt *self) { POST_PROCESSING_AI };
1170 static void M_Sqrt_postprocessing_ia(M_Sqrt *self) { POST_PROCESSING_IA };
1171 static void M_Sqrt_postprocessing_aa(M_Sqrt *self) { POST_PROCESSING_AA };
1172 static void M_Sqrt_postprocessing_ireva(M_Sqrt *self) { POST_PROCESSING_IREVA };
1173 static void M_Sqrt_postprocessing_areva(M_Sqrt *self) { POST_PROCESSING_AREVA };
1174 static void M_Sqrt_postprocessing_revai(M_Sqrt *self) { POST_PROCESSING_REVAI };
1175 static void M_Sqrt_postprocessing_revaa(M_Sqrt *self) { POST_PROCESSING_REVAA };
1176 static void M_Sqrt_postprocessing_revareva(M_Sqrt *self) { POST_PROCESSING_REVAREVA };
1177
1178 static void
1179 M_Sqrt_setProcMode(M_Sqrt *self)
1180 {
1181 int muladdmode;
1182 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
1183
1184 self->proc_func_ptr = M_Sqrt_process;
1185
1186 switch (muladdmode)
1187 {
1188 case 0:
1189 self->muladd_func_ptr = M_Sqrt_postprocessing_ii;
1190 break;
1191
1192 case 1:
1193 self->muladd_func_ptr = M_Sqrt_postprocessing_ai;
1194 break;
1195
1196 case 2:
1197 self->muladd_func_ptr = M_Sqrt_postprocessing_revai;
1198 break;
1199
1200 case 10:
1201 self->muladd_func_ptr = M_Sqrt_postprocessing_ia;
1202 break;
1203
1204 case 11:
1205 self->muladd_func_ptr = M_Sqrt_postprocessing_aa;
1206 break;
1207
1208 case 12:
1209 self->muladd_func_ptr = M_Sqrt_postprocessing_revaa;
1210 break;
1211
1212 case 20:
1213 self->muladd_func_ptr = M_Sqrt_postprocessing_ireva;
1214 break;
1215
1216 case 21:
1217 self->muladd_func_ptr = M_Sqrt_postprocessing_areva;
1218 break;
1219
1220 case 22:
1221 self->muladd_func_ptr = M_Sqrt_postprocessing_revareva;
1222 break;
1223 }
1224 }
1225
1226 static void
1227 M_Sqrt_compute_next_data_frame(M_Sqrt *self)
1228 {
1229 (*self->proc_func_ptr)(self);
1230 (*self->muladd_func_ptr)(self);
1231 }
1232
1233 static int
1234 M_Sqrt_traverse(M_Sqrt *self, visitproc visit, void *arg)
1235 {
1236 pyo_VISIT
1237 Py_VISIT(self->input);
1238 return 0;
1239 }
1240
1241 static int
1242 M_Sqrt_clear(M_Sqrt *self)
1243 {
1244 pyo_CLEAR
1245 Py_CLEAR(self->input);
1246 return 0;
1247 }
1248
1249 static void
1250 M_Sqrt_dealloc(M_Sqrt* self)
1251 {
1252 pyo_DEALLOC
1253 M_Sqrt_clear(self);
1254 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
1255 Py_TYPE(self)->tp_free((PyObject*)self);
1256 }
1257
1258 static PyObject *
1259 M_Sqrt_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1260 {
1261 int i;
1262 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
1263 M_Sqrt *self;
1264 self = (M_Sqrt *)type->tp_alloc(type, 0);
1265
1266 self->modebuffer[0] = 0;
1267 self->modebuffer[1] = 0;
1268
1269 INIT_OBJECT_COMMON
1270 Stream_setFunctionPtr(self->stream, M_Sqrt_compute_next_data_frame);
1271 self->mode_func_ptr = M_Sqrt_setProcMode;
1272
1273 static char *kwlist[] = {"input", "mul", "add", NULL};
1274
1275 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
1276 Py_RETURN_NONE;
1277
1278 INIT_INPUT_STREAM
1279
1280 if (multmp)
1281 {
1282 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
1283 }
1284
1285 if (addtmp)
1286 {
1287 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
1288 }
1289
1290 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1291
1292 (*self->mode_func_ptr)(self);
1293
1294 return (PyObject *)self;
1295 }
1296
1297 static PyObject * M_Sqrt_getServer(M_Sqrt* self) { GET_SERVER };
1298 static PyObject * M_Sqrt_getStream(M_Sqrt* self) { GET_STREAM };
1299 static PyObject * M_Sqrt_setMul(M_Sqrt *self, PyObject *arg) { SET_MUL };
1300 static PyObject * M_Sqrt_setAdd(M_Sqrt *self, PyObject *arg) { SET_ADD };
1301 static PyObject * M_Sqrt_setSub(M_Sqrt *self, PyObject *arg) { SET_SUB };
1302 static PyObject * M_Sqrt_setDiv(M_Sqrt *self, PyObject *arg) { SET_DIV };
1303
1304 static PyObject * M_Sqrt_play(M_Sqrt *self, PyObject *args, PyObject *kwds) { PLAY };
1305 static PyObject * M_Sqrt_out(M_Sqrt *self, PyObject *args, PyObject *kwds) { OUT };
1306 static PyObject * M_Sqrt_stop(M_Sqrt *self, PyObject *args, PyObject *kwds) { STOP };
1307
1308 static PyObject * M_Sqrt_multiply(M_Sqrt *self, PyObject *arg) { MULTIPLY };
1309 static PyObject * M_Sqrt_inplace_multiply(M_Sqrt *self, PyObject *arg) { INPLACE_MULTIPLY };
1310 static PyObject * M_Sqrt_add(M_Sqrt *self, PyObject *arg) { ADD };
1311 static PyObject * M_Sqrt_inplace_add(M_Sqrt *self, PyObject *arg) { INPLACE_ADD };
1312 static PyObject * M_Sqrt_sub(M_Sqrt *self, PyObject *arg) { SUB };
1313 static PyObject * M_Sqrt_inplace_sub(M_Sqrt *self, PyObject *arg) { INPLACE_SUB };
1314 static PyObject * M_Sqrt_div(M_Sqrt *self, PyObject *arg) { DIV };
1315 static PyObject * M_Sqrt_inplace_div(M_Sqrt *self, PyObject *arg) { INPLACE_DIV };
1316
1317 static PyMemberDef M_Sqrt_members[] =
1318 {
1319 {"server", T_OBJECT_EX, offsetof(M_Sqrt, server), 0, "Pyo server."},
1320 {"stream", T_OBJECT_EX, offsetof(M_Sqrt, stream), 0, "Stream object."},
1321 {"input", T_OBJECT_EX, offsetof(M_Sqrt, input), 0, "Input sound object."},
1322 {"mul", T_OBJECT_EX, offsetof(M_Sqrt, mul), 0, "Mul factor."},
1323 {"add", T_OBJECT_EX, offsetof(M_Sqrt, add), 0, "Add factor."},
1324 {NULL} /* Sentinel */
1325 };
1326
1327 static PyMethodDef M_Sqrt_methods[] =
1328 {
1329 {"getServer", (PyCFunction)M_Sqrt_getServer, METH_NOARGS, "Returns server object."},
1330 {"_getStream", (PyCFunction)M_Sqrt_getStream, METH_NOARGS, "Returns stream object."},
1331 {"play", (PyCFunction)M_Sqrt_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1332 {"stop", (PyCFunction)M_Sqrt_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
1333 {"out", (PyCFunction)M_Sqrt_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
1334 {"setMul", (PyCFunction)M_Sqrt_setMul, METH_O, "Sets oscillator mul factor."},
1335 {"setAdd", (PyCFunction)M_Sqrt_setAdd, METH_O, "Sets oscillator add factor."},
1336 {"setSub", (PyCFunction)M_Sqrt_setSub, METH_O, "Sets inverse add factor."},
1337 {"setDiv", (PyCFunction)M_Sqrt_setDiv, METH_O, "Sets inverse mul factor."},
1338 {NULL} /* Sentinel */
1339 };
1340
1341 static PyNumberMethods M_Sqrt_as_number =
1342 {
1343 (binaryfunc)M_Sqrt_add, /*nb_add*/
1344 (binaryfunc)M_Sqrt_sub, /*nb_subtract*/
1345 (binaryfunc)M_Sqrt_multiply, /*nb_multiply*/
1346 0, /*nb_remainder*/
1347 0, /*nb_divmod*/
1348 0, /*nb_power*/
1349 0, /*nb_neg*/
1350 0, /*nb_pos*/
1351 0, /*(unaryfunc)array_abs,*/
1352 0, /*nb_nonzero*/
1353 0, /*nb_invert*/
1354 0, /*nb_lshift*/
1355 0, /*nb_rshift*/
1356 0, /*nb_and*/
1357 0, /*nb_xor*/
1358 0, /*nb_or*/
1359 0, /*nb_int*/
1360 0, /*nb_long*/
1361 0, /*nb_float*/
1362 (binaryfunc)M_Sqrt_inplace_add, /*inplace_add*/
1363 (binaryfunc)M_Sqrt_inplace_sub, /*inplace_subtract*/
1364 (binaryfunc)M_Sqrt_inplace_multiply, /*inplace_multiply*/
1365 0, /*inplace_remainder*/
1366 0, /*inplace_power*/
1367 0, /*inplace_lshift*/
1368 0, /*inplace_rshift*/
1369 0, /*inplace_and*/
1370 0, /*inplace_xor*/
1371 0, /*inplace_or*/
1372 0, /*nb_floor_divide*/
1373 (binaryfunc)M_Sqrt_div, /*nb_true_divide*/
1374 0, /*nb_inplace_floor_divide*/
1375 (binaryfunc)M_Sqrt_inplace_div, /*nb_inplace_true_divide*/
1376 0, /* nb_index */
1377 };
1378
1379 PyTypeObject M_SqrtType =
1380 {
1381 PyVarObject_HEAD_INIT(NULL, 0)
1382 "_pyo.M_Sqrt_base", /*tp_name*/
1383 sizeof(M_Sqrt), /*tp_basicsize*/
1384 0, /*tp_itemsize*/
1385 (destructor)M_Sqrt_dealloc, /*tp_dealloc*/
1386 0, /*tp_print*/
1387 0, /*tp_getattr*/
1388 0, /*tp_setattr*/
1389 0, /*tp_as_async (tp_compare in Python 2)*/
1390 0, /*tp_repr*/
1391 &M_Sqrt_as_number, /*tp_as_number*/
1392 0, /*tp_as_sequence*/
1393 0, /*tp_as_mapping*/
1394 0, /*tp_hash */
1395 0, /*tp_call*/
1396 0, /*tp_str*/
1397 0, /*tp_getattro*/
1398 0, /*tp_setattro*/
1399 0, /*tp_as_buffer*/
1400 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
1401 "M_Sqrt objects. Performs sqrt function on audio samples.", /* tp_doc */
1402 (traverseproc)M_Sqrt_traverse, /* tp_traverse */
1403 (inquiry)M_Sqrt_clear, /* tp_clear */
1404 0, /* tp_richcompare */
1405 0, /* tp_weaklistoffset */
1406 0, /* tp_iter */
1407 0, /* tp_iternext */
1408 M_Sqrt_methods, /* tp_methods */
1409 M_Sqrt_members, /* tp_members */
1410 0, /* tp_getset */
1411 0, /* tp_base */
1412 0, /* tp_dict */
1413 0, /* tp_descr_get */
1414 0, /* tp_descr_set */
1415 0, /* tp_dictoffset */
1416 0, /* tp_init */
1417 0, /* tp_alloc */
1418 M_Sqrt_new, /* tp_new */
1419 };
1420
1421 /************/
1422 /* M_Log */
1423 /************/
1424 typedef struct
1425 {
1426 pyo_audio_HEAD
1427 PyObject *input;
1428 Stream *input_stream;
1429 int modebuffer[2]; // need at least 2 slots for mul & add
1430 } M_Log;
1431
1432 static void
1433 M_Log_process(M_Log *self)
1434 {
1435 int i;
1436 MYFLT inval;
1437 MYFLT *in = Stream_getData((Stream *)self->input_stream);
1438
1439 for (i = 0; i < self->bufsize; i++)
1440 {
1441 inval = in[i];
1442
1443 if (inval <= 0.0)
1444 self->data[i] = 0.0;
1445 else
1446 self->data[i] = MYLOG(inval);
1447 }
1448 }
1449
1450 static void M_Log_postprocessing_ii(M_Log *self) { POST_PROCESSING_II };
1451 static void M_Log_postprocessing_ai(M_Log *self) { POST_PROCESSING_AI };
1452 static void M_Log_postprocessing_ia(M_Log *self) { POST_PROCESSING_IA };
1453 static void M_Log_postprocessing_aa(M_Log *self) { POST_PROCESSING_AA };
1454 static void M_Log_postprocessing_ireva(M_Log *self) { POST_PROCESSING_IREVA };
1455 static void M_Log_postprocessing_areva(M_Log *self) { POST_PROCESSING_AREVA };
1456 static void M_Log_postprocessing_revai(M_Log *self) { POST_PROCESSING_REVAI };
1457 static void M_Log_postprocessing_revaa(M_Log *self) { POST_PROCESSING_REVAA };
1458 static void M_Log_postprocessing_revareva(M_Log *self) { POST_PROCESSING_REVAREVA };
1459
1460 static void
1461 M_Log_setProcMode(M_Log *self)
1462 {
1463 int muladdmode;
1464 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
1465
1466 self->proc_func_ptr = M_Log_process;
1467
1468 switch (muladdmode)
1469 {
1470 case 0:
1471 self->muladd_func_ptr = M_Log_postprocessing_ii;
1472 break;
1473
1474 case 1:
1475 self->muladd_func_ptr = M_Log_postprocessing_ai;
1476 break;
1477
1478 case 2:
1479 self->muladd_func_ptr = M_Log_postprocessing_revai;
1480 break;
1481
1482 case 10:
1483 self->muladd_func_ptr = M_Log_postprocessing_ia;
1484 break;
1485
1486 case 11:
1487 self->muladd_func_ptr = M_Log_postprocessing_aa;
1488 break;
1489
1490 case 12:
1491 self->muladd_func_ptr = M_Log_postprocessing_revaa;
1492 break;
1493
1494 case 20:
1495 self->muladd_func_ptr = M_Log_postprocessing_ireva;
1496 break;
1497
1498 case 21:
1499 self->muladd_func_ptr = M_Log_postprocessing_areva;
1500 break;
1501
1502 case 22:
1503 self->muladd_func_ptr = M_Log_postprocessing_revareva;
1504 break;
1505 }
1506 }
1507
1508 static void
1509 M_Log_compute_next_data_frame(M_Log *self)
1510 {
1511 (*self->proc_func_ptr)(self);
1512 (*self->muladd_func_ptr)(self);
1513 }
1514
1515 static int
1516 M_Log_traverse(M_Log *self, visitproc visit, void *arg)
1517 {
1518 pyo_VISIT
1519 Py_VISIT(self->input);
1520 return 0;
1521 }
1522
1523 static int
1524 M_Log_clear(M_Log *self)
1525 {
1526 pyo_CLEAR
1527 Py_CLEAR(self->input);
1528 return 0;
1529 }
1530
1531 static void
1532 M_Log_dealloc(M_Log* self)
1533 {
1534 pyo_DEALLOC
1535 M_Log_clear(self);
1536 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
1537 Py_TYPE(self)->tp_free((PyObject*)self);
1538 }
1539
1540 static PyObject *
1541 M_Log_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1542 {
1543 int i;
1544 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
1545 M_Log *self;
1546 self = (M_Log *)type->tp_alloc(type, 0);
1547
1548 self->modebuffer[0] = 0;
1549 self->modebuffer[1] = 0;
1550
1551 INIT_OBJECT_COMMON
1552 Stream_setFunctionPtr(self->stream, M_Log_compute_next_data_frame);
1553 self->mode_func_ptr = M_Log_setProcMode;
1554
1555 static char *kwlist[] = {"input", "mul", "add", NULL};
1556
1557 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
1558 Py_RETURN_NONE;
1559
1560 INIT_INPUT_STREAM
1561
1562 if (multmp)
1563 {
1564 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
1565 }
1566
1567 if (addtmp)
1568 {
1569 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
1570 }
1571
1572 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1573
1574 (*self->mode_func_ptr)(self);
1575
1576 return (PyObject *)self;
1577 }
1578
1579 static PyObject * M_Log_getServer(M_Log* self) { GET_SERVER };
1580 static PyObject * M_Log_getStream(M_Log* self) { GET_STREAM };
1581 static PyObject * M_Log_setMul(M_Log *self, PyObject *arg) { SET_MUL };
1582 static PyObject * M_Log_setAdd(M_Log *self, PyObject *arg) { SET_ADD };
1583 static PyObject * M_Log_setSub(M_Log *self, PyObject *arg) { SET_SUB };
1584 static PyObject * M_Log_setDiv(M_Log *self, PyObject *arg) { SET_DIV };
1585
1586 static PyObject * M_Log_play(M_Log *self, PyObject *args, PyObject *kwds) { PLAY };
1587 static PyObject * M_Log_out(M_Log *self, PyObject *args, PyObject *kwds) { OUT };
1588 static PyObject * M_Log_stop(M_Log *self, PyObject *args, PyObject *kwds) { STOP };
1589
1590 static PyObject * M_Log_multiply(M_Log *self, PyObject *arg) { MULTIPLY };
1591 static PyObject * M_Log_inplace_multiply(M_Log *self, PyObject *arg) { INPLACE_MULTIPLY };
1592 static PyObject * M_Log_add(M_Log *self, PyObject *arg) { ADD };
1593 static PyObject * M_Log_inplace_add(M_Log *self, PyObject *arg) { INPLACE_ADD };
1594 static PyObject * M_Log_sub(M_Log *self, PyObject *arg) { SUB };
1595 static PyObject * M_Log_inplace_sub(M_Log *self, PyObject *arg) { INPLACE_SUB };
1596 static PyObject * M_Log_div(M_Log *self, PyObject *arg) { DIV };
1597 static PyObject * M_Log_inplace_div(M_Log *self, PyObject *arg) { INPLACE_DIV };
1598
1599 static PyMemberDef M_Log_members[] =
1600 {
1601 {"server", T_OBJECT_EX, offsetof(M_Log, server), 0, "Pyo server."},
1602 {"stream", T_OBJECT_EX, offsetof(M_Log, stream), 0, "Stream object."},
1603 {"input", T_OBJECT_EX, offsetof(M_Log, input), 0, "Input sound object."},
1604 {"mul", T_OBJECT_EX, offsetof(M_Log, mul), 0, "Mul factor."},
1605 {"add", T_OBJECT_EX, offsetof(M_Log, add), 0, "Add factor."},
1606 {NULL} /* Sentinel */
1607 };
1608
1609 static PyMethodDef M_Log_methods[] =
1610 {
1611 {"getServer", (PyCFunction)M_Log_getServer, METH_NOARGS, "Returns server object."},
1612 {"_getStream", (PyCFunction)M_Log_getStream, METH_NOARGS, "Returns stream object."},
1613 {"play", (PyCFunction)M_Log_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1614 {"stop", (PyCFunction)M_Log_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
1615 {"out", (PyCFunction)M_Log_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
1616 {"setMul", (PyCFunction)M_Log_setMul, METH_O, "Sets oscillator mul factor."},
1617 {"setAdd", (PyCFunction)M_Log_setAdd, METH_O, "Sets oscillator add factor."},
1618 {"setSub", (PyCFunction)M_Log_setSub, METH_O, "Sets inverse add factor."},
1619 {"setDiv", (PyCFunction)M_Log_setDiv, METH_O, "Sets inverse mul factor."},
1620 {NULL} /* Sentinel */
1621 };
1622
1623 static PyNumberMethods M_Log_as_number =
1624 {
1625 (binaryfunc)M_Log_add, /*nb_add*/
1626 (binaryfunc)M_Log_sub, /*nb_subtract*/
1627 (binaryfunc)M_Log_multiply, /*nb_multiply*/
1628 0, /*nb_remainder*/
1629 0, /*nb_divmod*/
1630 0, /*nb_power*/
1631 0, /*nb_neg*/
1632 0, /*nb_pos*/
1633 0, /*(unaryfunc)array_abs,*/
1634 0, /*nb_nonzero*/
1635 0, /*nb_invert*/
1636 0, /*nb_lshift*/
1637 0, /*nb_rshift*/
1638 0, /*nb_and*/
1639 0, /*nb_xor*/
1640 0, /*nb_or*/
1641 0, /*nb_int*/
1642 0, /*nb_long*/
1643 0, /*nb_float*/
1644 (binaryfunc)M_Log_inplace_add, /*inplace_add*/
1645 (binaryfunc)M_Log_inplace_sub, /*inplace_subtract*/
1646 (binaryfunc)M_Log_inplace_multiply, /*inplace_multiply*/
1647 0, /*inplace_remainder*/
1648 0, /*inplace_power*/
1649 0, /*inplace_lshift*/
1650 0, /*inplace_rshift*/
1651 0, /*inplace_and*/
1652 0, /*inplace_xor*/
1653 0, /*inplace_or*/
1654 0, /*nb_floor_divide*/
1655 (binaryfunc)M_Log_div, /*nb_true_divide*/
1656 0, /*nb_inplace_floor_divide*/
1657 (binaryfunc)M_Log_inplace_div, /*nb_inplace_true_divide*/
1658 0, /* nb_index */
1659 };
1660
1661 PyTypeObject M_LogType =
1662 {
1663 PyVarObject_HEAD_INIT(NULL, 0)
1664 "_pyo.M_Log_base", /*tp_name*/
1665 sizeof(M_Log), /*tp_basicsize*/
1666 0, /*tp_itemsize*/
1667 (destructor)M_Log_dealloc, /*tp_dealloc*/
1668 0, /*tp_print*/
1669 0, /*tp_getattr*/
1670 0, /*tp_setattr*/
1671 0, /*tp_as_async (tp_compare in Python 2)*/
1672 0, /*tp_repr*/
1673 &M_Log_as_number, /*tp_as_number*/
1674 0, /*tp_as_sequence*/
1675 0, /*tp_as_mapping*/
1676 0, /*tp_hash */
1677 0, /*tp_call*/
1678 0, /*tp_str*/
1679 0, /*tp_getattro*/
1680 0, /*tp_setattro*/
1681 0, /*tp_as_buffer*/
1682 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
1683 "M_Log objects. Performs natural log function on audio samples.", /* tp_doc */
1684 (traverseproc)M_Log_traverse, /* tp_traverse */
1685 (inquiry)M_Log_clear, /* tp_clear */
1686 0, /* tp_richcompare */
1687 0, /* tp_weaklistoffset */
1688 0, /* tp_iter */
1689 0, /* tp_iternext */
1690 M_Log_methods, /* tp_methods */
1691 M_Log_members, /* tp_members */
1692 0, /* tp_getset */
1693 0, /* tp_base */
1694 0, /* tp_dict */
1695 0, /* tp_descr_get */
1696 0, /* tp_descr_set */
1697 0, /* tp_dictoffset */
1698 0, /* tp_init */
1699 0, /* tp_alloc */
1700 M_Log_new, /* tp_new */
1701 };
1702
1703 /************/
1704 /* M_Log10 */
1705 /************/
1706 typedef struct
1707 {
1708 pyo_audio_HEAD
1709 PyObject *input;
1710 Stream *input_stream;
1711 int modebuffer[2]; // need at least 2 slots for mul & add
1712 } M_Log10;
1713
1714 static void
1715 M_Log10_process(M_Log10 *self)
1716 {
1717 int i;
1718 MYFLT inval;
1719 MYFLT *in = Stream_getData((Stream *)self->input_stream);
1720
1721 for (i = 0; i < self->bufsize; i++)
1722 {
1723 inval = in[i];
1724
1725 if (inval <= 0.0)
1726 self->data[i] = 0.0;
1727 else
1728 self->data[i] = MYLOG10(inval);
1729 }
1730 }
1731
1732 static void M_Log10_postprocessing_ii(M_Log10 *self) { POST_PROCESSING_II };
1733 static void M_Log10_postprocessing_ai(M_Log10 *self) { POST_PROCESSING_AI };
1734 static void M_Log10_postprocessing_ia(M_Log10 *self) { POST_PROCESSING_IA };
1735 static void M_Log10_postprocessing_aa(M_Log10 *self) { POST_PROCESSING_AA };
1736 static void M_Log10_postprocessing_ireva(M_Log10 *self) { POST_PROCESSING_IREVA };
1737 static void M_Log10_postprocessing_areva(M_Log10 *self) { POST_PROCESSING_AREVA };
1738 static void M_Log10_postprocessing_revai(M_Log10 *self) { POST_PROCESSING_REVAI };
1739 static void M_Log10_postprocessing_revaa(M_Log10 *self) { POST_PROCESSING_REVAA };
1740 static void M_Log10_postprocessing_revareva(M_Log10 *self) { POST_PROCESSING_REVAREVA };
1741
1742 static void
1743 M_Log10_setProcMode(M_Log10 *self)
1744 {
1745 int muladdmode;
1746 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
1747
1748 self->proc_func_ptr = M_Log10_process;
1749
1750 switch (muladdmode)
1751 {
1752 case 0:
1753 self->muladd_func_ptr = M_Log10_postprocessing_ii;
1754 break;
1755
1756 case 1:
1757 self->muladd_func_ptr = M_Log10_postprocessing_ai;
1758 break;
1759
1760 case 2:
1761 self->muladd_func_ptr = M_Log10_postprocessing_revai;
1762 break;
1763
1764 case 10:
1765 self->muladd_func_ptr = M_Log10_postprocessing_ia;
1766 break;
1767
1768 case 11:
1769 self->muladd_func_ptr = M_Log10_postprocessing_aa;
1770 break;
1771
1772 case 12:
1773 self->muladd_func_ptr = M_Log10_postprocessing_revaa;
1774 break;
1775
1776 case 20:
1777 self->muladd_func_ptr = M_Log10_postprocessing_ireva;
1778 break;
1779
1780 case 21:
1781 self->muladd_func_ptr = M_Log10_postprocessing_areva;
1782 break;
1783
1784 case 22:
1785 self->muladd_func_ptr = M_Log10_postprocessing_revareva;
1786 break;
1787 }
1788 }
1789
1790 static void
1791 M_Log10_compute_next_data_frame(M_Log10 *self)
1792 {
1793 (*self->proc_func_ptr)(self);
1794 (*self->muladd_func_ptr)(self);
1795 }
1796
1797 static int
1798 M_Log10_traverse(M_Log10 *self, visitproc visit, void *arg)
1799 {
1800 pyo_VISIT
1801 Py_VISIT(self->input);
1802 return 0;
1803 }
1804
1805 static int
1806 M_Log10_clear(M_Log10 *self)
1807 {
1808 pyo_CLEAR
1809 Py_CLEAR(self->input);
1810 return 0;
1811 }
1812
1813 static void
1814 M_Log10_dealloc(M_Log10* self)
1815 {
1816 pyo_DEALLOC
1817 M_Log10_clear(self);
1818 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
1819 Py_TYPE(self)->tp_free((PyObject*)self);
1820 }
1821
1822 static PyObject *
1823 M_Log10_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1824 {
1825 int i;
1826 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
1827 M_Log10 *self;
1828 self = (M_Log10 *)type->tp_alloc(type, 0);
1829
1830 self->modebuffer[0] = 0;
1831 self->modebuffer[1] = 0;
1832
1833 INIT_OBJECT_COMMON
1834 Stream_setFunctionPtr(self->stream, M_Log10_compute_next_data_frame);
1835 self->mode_func_ptr = M_Log10_setProcMode;
1836
1837 static char *kwlist[] = {"input", "mul", "add", NULL};
1838
1839 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
1840 Py_RETURN_NONE;
1841
1842 INIT_INPUT_STREAM
1843
1844 if (multmp)
1845 {
1846 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
1847 }
1848
1849 if (addtmp)
1850 {
1851 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
1852 }
1853
1854 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1855
1856 (*self->mode_func_ptr)(self);
1857
1858 return (PyObject *)self;
1859 }
1860
1861 static PyObject * M_Log10_getServer(M_Log10* self) { GET_SERVER };
1862 static PyObject * M_Log10_getStream(M_Log10* self) { GET_STREAM };
1863 static PyObject * M_Log10_setMul(M_Log10 *self, PyObject *arg) { SET_MUL };
1864 static PyObject * M_Log10_setAdd(M_Log10 *self, PyObject *arg) { SET_ADD };
1865 static PyObject * M_Log10_setSub(M_Log10 *self, PyObject *arg) { SET_SUB };
1866 static PyObject * M_Log10_setDiv(M_Log10 *self, PyObject *arg) { SET_DIV };
1867
1868 static PyObject * M_Log10_play(M_Log10 *self, PyObject *args, PyObject *kwds) { PLAY };
1869 static PyObject * M_Log10_out(M_Log10 *self, PyObject *args, PyObject *kwds) { OUT };
1870 static PyObject * M_Log10_stop(M_Log10 *self, PyObject *args, PyObject *kwds) { STOP };
1871
1872 static PyObject * M_Log10_multiply(M_Log10 *self, PyObject *arg) { MULTIPLY };
1873 static PyObject * M_Log10_inplace_multiply(M_Log10 *self, PyObject *arg) { INPLACE_MULTIPLY };
1874 static PyObject * M_Log10_add(M_Log10 *self, PyObject *arg) { ADD };
1875 static PyObject * M_Log10_inplace_add(M_Log10 *self, PyObject *arg) { INPLACE_ADD };
1876 static PyObject * M_Log10_sub(M_Log10 *self, PyObject *arg) { SUB };
1877 static PyObject * M_Log10_inplace_sub(M_Log10 *self, PyObject *arg) { INPLACE_SUB };
1878 static PyObject * M_Log10_div(M_Log10 *self, PyObject *arg) { DIV };
1879 static PyObject * M_Log10_inplace_div(M_Log10 *self, PyObject *arg) { INPLACE_DIV };
1880
1881 static PyMemberDef M_Log10_members[] =
1882 {
1883 {"server", T_OBJECT_EX, offsetof(M_Log10, server), 0, "Pyo server."},
1884 {"stream", T_OBJECT_EX, offsetof(M_Log10, stream), 0, "Stream object."},
1885 {"input", T_OBJECT_EX, offsetof(M_Log10, input), 0, "Input sound object."},
1886 {"mul", T_OBJECT_EX, offsetof(M_Log10, mul), 0, "Mul factor."},
1887 {"add", T_OBJECT_EX, offsetof(M_Log10, add), 0, "Add factor."},
1888 {NULL} /* Sentinel */
1889 };
1890
1891 static PyMethodDef M_Log10_methods[] =
1892 {
1893 {"getServer", (PyCFunction)M_Log10_getServer, METH_NOARGS, "Returns server object."},
1894 {"_getStream", (PyCFunction)M_Log10_getStream, METH_NOARGS, "Returns stream object."},
1895 {"play", (PyCFunction)M_Log10_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1896 {"stop", (PyCFunction)M_Log10_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
1897 {"out", (PyCFunction)M_Log10_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
1898 {"setMul", (PyCFunction)M_Log10_setMul, METH_O, "Sets oscillator mul factor."},
1899 {"setAdd", (PyCFunction)M_Log10_setAdd, METH_O, "Sets oscillator add factor."},
1900 {"setSub", (PyCFunction)M_Log10_setSub, METH_O, "Sets inverse add factor."},
1901 {"setDiv", (PyCFunction)M_Log10_setDiv, METH_O, "Sets inverse mul factor."},
1902 {NULL} /* Sentinel */
1903 };
1904
1905 static PyNumberMethods M_Log10_as_number =
1906 {
1907 (binaryfunc)M_Log10_add, /*nb_add*/
1908 (binaryfunc)M_Log10_sub, /*nb_subtract*/
1909 (binaryfunc)M_Log10_multiply, /*nb_multiply*/
1910 0, /*nb_remainder*/
1911 0, /*nb_divmod*/
1912 0, /*nb_power*/
1913 0, /*nb_neg*/
1914 0, /*nb_pos*/
1915 0, /*(unaryfunc)array_abs,*/
1916 0, /*nb_nonzero*/
1917 0, /*nb_invert*/
1918 0, /*nb_lshift*/
1919 0, /*nb_rshift*/
1920 0, /*nb_and*/
1921 0, /*nb_xor*/
1922 0, /*nb_or*/
1923 0, /*nb_int*/
1924 0, /*nb_long*/
1925 0, /*nb_float*/
1926 (binaryfunc)M_Log10_inplace_add, /*inplace_add*/
1927 (binaryfunc)M_Log10_inplace_sub, /*inplace_subtract*/
1928 (binaryfunc)M_Log10_inplace_multiply, /*inplace_multiply*/
1929 0, /*inplace_remainder*/
1930 0, /*inplace_power*/
1931 0, /*inplace_lshift*/
1932 0, /*inplace_rshift*/
1933 0, /*inplace_and*/
1934 0, /*inplace_xor*/
1935 0, /*inplace_or*/
1936 0, /*nb_floor_divide*/
1937 (binaryfunc)M_Log10_div, /*nb_true_divide*/
1938 0, /*nb_inplace_floor_divide*/
1939 (binaryfunc)M_Log10_inplace_div, /*nb_inplace_true_divide*/
1940 0, /* nb_index */
1941 };
1942
1943 PyTypeObject M_Log10Type =
1944 {
1945 PyVarObject_HEAD_INIT(NULL, 0)
1946 "_pyo.M_Log10_base", /*tp_name*/
1947 sizeof(M_Log10), /*tp_basicsize*/
1948 0, /*tp_itemsize*/
1949 (destructor)M_Log10_dealloc, /*tp_dealloc*/
1950 0, /*tp_print*/
1951 0, /*tp_getattr*/
1952 0, /*tp_setattr*/
1953 0, /*tp_as_async (tp_compare in Python 2)*/
1954 0, /*tp_repr*/
1955 &M_Log10_as_number, /*tp_as_number*/
1956 0, /*tp_as_sequence*/
1957 0, /*tp_as_mapping*/
1958 0, /*tp_hash */
1959 0, /*tp_call*/
1960 0, /*tp_str*/
1961 0, /*tp_getattro*/
1962 0, /*tp_setattro*/
1963 0, /*tp_as_buffer*/
1964 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
1965 "M_Log10 objects. Performs base 10 log function on audio samples.", /* tp_doc */
1966 (traverseproc)M_Log10_traverse, /* tp_traverse */
1967 (inquiry)M_Log10_clear, /* tp_clear */
1968 0, /* tp_richcompare */
1969 0, /* tp_weaklistoffset */
1970 0, /* tp_iter */
1971 0, /* tp_iternext */
1972 M_Log10_methods, /* tp_methods */
1973 M_Log10_members, /* tp_members */
1974 0, /* tp_getset */
1975 0, /* tp_base */
1976 0, /* tp_dict */
1977 0, /* tp_descr_get */
1978 0, /* tp_descr_set */
1979 0, /* tp_dictoffset */
1980 0, /* tp_init */
1981 0, /* tp_alloc */
1982 M_Log10_new, /* tp_new */
1983 };
1984
1985 /************/
1986 /* M_Log2 */
1987 /************/
1988 typedef struct
1989 {
1990 pyo_audio_HEAD
1991 PyObject *input;
1992 Stream *input_stream;
1993 int modebuffer[2]; // need at least 2 slots for mul & add
1994 } M_Log2;
1995
1996 static void
1997 M_Log2_process(M_Log2 *self)
1998 {
1999 int i;
2000 MYFLT inval;
2001 MYFLT *in = Stream_getData((Stream *)self->input_stream);
2002
2003 for (i = 0; i < self->bufsize; i++)
2004 {
2005 inval = in[i];
2006
2007 if (inval <= 0.0)
2008 self->data[i] = 0.0;
2009 else
2010 self->data[i] = MYLOG2(inval);
2011 }
2012 }
2013
2014 static void M_Log2_postprocessing_ii(M_Log2 *self) { POST_PROCESSING_II };
2015 static void M_Log2_postprocessing_ai(M_Log2 *self) { POST_PROCESSING_AI };
2016 static void M_Log2_postprocessing_ia(M_Log2 *self) { POST_PROCESSING_IA };
2017 static void M_Log2_postprocessing_aa(M_Log2 *self) { POST_PROCESSING_AA };
2018 static void M_Log2_postprocessing_ireva(M_Log2 *self) { POST_PROCESSING_IREVA };
2019 static void M_Log2_postprocessing_areva(M_Log2 *self) { POST_PROCESSING_AREVA };
2020 static void M_Log2_postprocessing_revai(M_Log2 *self) { POST_PROCESSING_REVAI };
2021 static void M_Log2_postprocessing_revaa(M_Log2 *self) { POST_PROCESSING_REVAA };
2022 static void M_Log2_postprocessing_revareva(M_Log2 *self) { POST_PROCESSING_REVAREVA };
2023
2024 static void
2025 M_Log2_setProcMode(M_Log2 *self)
2026 {
2027 int muladdmode;
2028 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
2029
2030 self->proc_func_ptr = M_Log2_process;
2031
2032 switch (muladdmode)
2033 {
2034 case 0:
2035 self->muladd_func_ptr = M_Log2_postprocessing_ii;
2036 break;
2037
2038 case 1:
2039 self->muladd_func_ptr = M_Log2_postprocessing_ai;
2040 break;
2041
2042 case 2:
2043 self->muladd_func_ptr = M_Log2_postprocessing_revai;
2044 break;
2045
2046 case 10:
2047 self->muladd_func_ptr = M_Log2_postprocessing_ia;
2048 break;
2049
2050 case 11:
2051 self->muladd_func_ptr = M_Log2_postprocessing_aa;
2052 break;
2053
2054 case 12:
2055 self->muladd_func_ptr = M_Log2_postprocessing_revaa;
2056 break;
2057
2058 case 20:
2059 self->muladd_func_ptr = M_Log2_postprocessing_ireva;
2060 break;
2061
2062 case 21:
2063 self->muladd_func_ptr = M_Log2_postprocessing_areva;
2064 break;
2065
2066 case 22:
2067 self->muladd_func_ptr = M_Log2_postprocessing_revareva;
2068 break;
2069 }
2070 }
2071
2072 static void
2073 M_Log2_compute_next_data_frame(M_Log2 *self)
2074 {
2075 (*self->proc_func_ptr)(self);
2076 (*self->muladd_func_ptr)(self);
2077 }
2078
2079 static int
2080 M_Log2_traverse(M_Log2 *self, visitproc visit, void *arg)
2081 {
2082 pyo_VISIT
2083 Py_VISIT(self->input);
2084 return 0;
2085 }
2086
2087 static int
2088 M_Log2_clear(M_Log2 *self)
2089 {
2090 pyo_CLEAR
2091 Py_CLEAR(self->input);
2092 return 0;
2093 }
2094
2095 static void
2096 M_Log2_dealloc(M_Log2* self)
2097 {
2098 pyo_DEALLOC
2099 M_Log2_clear(self);
2100 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
2101 Py_TYPE(self)->tp_free((PyObject*)self);
2102 }
2103
2104 static PyObject *
2105 M_Log2_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2106 {
2107 int i;
2108 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
2109 M_Log2 *self;
2110 self = (M_Log2 *)type->tp_alloc(type, 0);
2111
2112 self->modebuffer[0] = 0;
2113 self->modebuffer[1] = 0;
2114
2115 INIT_OBJECT_COMMON
2116 Stream_setFunctionPtr(self->stream, M_Log2_compute_next_data_frame);
2117 self->mode_func_ptr = M_Log2_setProcMode;
2118
2119 static char *kwlist[] = {"input", "mul", "add", NULL};
2120
2121 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
2122 Py_RETURN_NONE;
2123
2124 INIT_INPUT_STREAM
2125
2126 if (multmp)
2127 {
2128 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
2129 }
2130
2131 if (addtmp)
2132 {
2133 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
2134 }
2135
2136 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
2137
2138 (*self->mode_func_ptr)(self);
2139
2140 return (PyObject *)self;
2141 }
2142
2143 static PyObject * M_Log2_getServer(M_Log2* self) { GET_SERVER };
2144 static PyObject * M_Log2_getStream(M_Log2* self) { GET_STREAM };
2145 static PyObject * M_Log2_setMul(M_Log2 *self, PyObject *arg) { SET_MUL };
2146 static PyObject * M_Log2_setAdd(M_Log2 *self, PyObject *arg) { SET_ADD };
2147 static PyObject * M_Log2_setSub(M_Log2 *self, PyObject *arg) { SET_SUB };
2148 static PyObject * M_Log2_setDiv(M_Log2 *self, PyObject *arg) { SET_DIV };
2149
2150 static PyObject * M_Log2_play(M_Log2 *self, PyObject *args, PyObject *kwds) { PLAY };
2151 static PyObject * M_Log2_out(M_Log2 *self, PyObject *args, PyObject *kwds) { OUT };
2152 static PyObject * M_Log2_stop(M_Log2 *self, PyObject *args, PyObject *kwds) { STOP };
2153
2154 static PyObject * M_Log2_multiply(M_Log2 *self, PyObject *arg) { MULTIPLY };
2155 static PyObject * M_Log2_inplace_multiply(M_Log2 *self, PyObject *arg) { INPLACE_MULTIPLY };
2156 static PyObject * M_Log2_add(M_Log2 *self, PyObject *arg) { ADD };
2157 static PyObject * M_Log2_inplace_add(M_Log2 *self, PyObject *arg) { INPLACE_ADD };
2158 static PyObject * M_Log2_sub(M_Log2 *self, PyObject *arg) { SUB };
2159 static PyObject * M_Log2_inplace_sub(M_Log2 *self, PyObject *arg) { INPLACE_SUB };
2160 static PyObject * M_Log2_div(M_Log2 *self, PyObject *arg) { DIV };
2161 static PyObject * M_Log2_inplace_div(M_Log2 *self, PyObject *arg) { INPLACE_DIV };
2162
2163 static PyMemberDef M_Log2_members[] =
2164 {
2165 {"server", T_OBJECT_EX, offsetof(M_Log2, server), 0, "Pyo server."},
2166 {"stream", T_OBJECT_EX, offsetof(M_Log2, stream), 0, "Stream object."},
2167 {"input", T_OBJECT_EX, offsetof(M_Log2, input), 0, "Input sound object."},
2168 {"mul", T_OBJECT_EX, offsetof(M_Log2, mul), 0, "Mul factor."},
2169 {"add", T_OBJECT_EX, offsetof(M_Log2, add), 0, "Add factor."},
2170 {NULL} /* Sentinel */
2171 };
2172
2173 static PyMethodDef M_Log2_methods[] =
2174 {
2175 {"getServer", (PyCFunction)M_Log2_getServer, METH_NOARGS, "Returns server object."},
2176 {"_getStream", (PyCFunction)M_Log2_getStream, METH_NOARGS, "Returns stream object."},
2177 {"play", (PyCFunction)M_Log2_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
2178 {"stop", (PyCFunction)M_Log2_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
2179 {"out", (PyCFunction)M_Log2_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
2180 {"setMul", (PyCFunction)M_Log2_setMul, METH_O, "Sets oscillator mul factor."},
2181 {"setAdd", (PyCFunction)M_Log2_setAdd, METH_O, "Sets oscillator add factor."},
2182 {"setSub", (PyCFunction)M_Log2_setSub, METH_O, "Sets inverse add factor."},
2183 {"setDiv", (PyCFunction)M_Log2_setDiv, METH_O, "Sets inverse mul factor."},
2184 {NULL} /* Sentinel */
2185 };
2186
2187 static PyNumberMethods M_Log2_as_number =
2188 {
2189 (binaryfunc)M_Log2_add, /*nb_add*/
2190 (binaryfunc)M_Log2_sub, /*nb_subtract*/
2191 (binaryfunc)M_Log2_multiply, /*nb_multiply*/
2192 0, /*nb_remainder*/
2193 0, /*nb_divmod*/
2194 0, /*nb_power*/
2195 0, /*nb_neg*/
2196 0, /*nb_pos*/
2197 0, /*(unaryfunc)array_abs,*/
2198 0, /*nb_nonzero*/
2199 0, /*nb_invert*/
2200 0, /*nb_lshift*/
2201 0, /*nb_rshift*/
2202 0, /*nb_and*/
2203 0, /*nb_xor*/
2204 0, /*nb_or*/
2205 0, /*nb_int*/
2206 0, /*nb_long*/
2207 0, /*nb_float*/
2208 (binaryfunc)M_Log2_inplace_add, /*inplace_add*/
2209 (binaryfunc)M_Log2_inplace_sub, /*inplace_subtract*/
2210 (binaryfunc)M_Log2_inplace_multiply, /*inplace_multiply*/
2211 0, /*inplace_remainder*/
2212 0, /*inplace_power*/
2213 0, /*inplace_lshift*/
2214 0, /*inplace_rshift*/
2215 0, /*inplace_and*/
2216 0, /*inplace_xor*/
2217 0, /*inplace_or*/
2218 0, /*nb_floor_divide*/
2219 (binaryfunc)M_Log2_div, /*nb_true_divide*/
2220 0, /*nb_inplace_floor_divide*/
2221 (binaryfunc)M_Log2_inplace_div, /*nb_inplace_true_divide*/
2222 0, /* nb_index */
2223 };
2224
2225 PyTypeObject M_Log2Type =
2226 {
2227 PyVarObject_HEAD_INIT(NULL, 0)
2228 "_pyo.M_Log2_base", /*tp_name*/
2229 sizeof(M_Log2), /*tp_basicsize*/
2230 0, /*tp_itemsize*/
2231 (destructor)M_Log2_dealloc, /*tp_dealloc*/
2232 0, /*tp_print*/
2233 0, /*tp_getattr*/
2234 0, /*tp_setattr*/
2235 0, /*tp_as_async (tp_compare in Python 2)*/
2236 0, /*tp_repr*/
2237 &M_Log2_as_number, /*tp_as_number*/
2238 0, /*tp_as_sequence*/
2239 0, /*tp_as_mapping*/
2240 0, /*tp_hash */
2241 0, /*tp_call*/
2242 0, /*tp_str*/
2243 0, /*tp_getattro*/
2244 0, /*tp_setattro*/
2245 0, /*tp_as_buffer*/
2246 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
2247 "M_Log2 objects. Performs base 2 log function on audio samples.", /* tp_doc */
2248 (traverseproc)M_Log2_traverse, /* tp_traverse */
2249 (inquiry)M_Log2_clear, /* tp_clear */
2250 0, /* tp_richcompare */
2251 0, /* tp_weaklistoffset */
2252 0, /* tp_iter */
2253 0, /* tp_iternext */
2254 M_Log2_methods, /* tp_methods */
2255 M_Log2_members, /* tp_members */
2256 0, /* tp_getset */
2257 0, /* tp_base */
2258 0, /* tp_dict */
2259 0, /* tp_descr_get */
2260 0, /* tp_descr_set */
2261 0, /* tp_dictoffset */
2262 0, /* tp_init */
2263 0, /* tp_alloc */
2264 M_Log2_new, /* tp_new */
2265 };
2266
2267 /**************/
2268 /* M_Pow object */
2269 /**************/
2270 typedef struct
2271 {
2272 pyo_audio_HEAD
2273 PyObject *base;
2274 Stream *base_stream;
2275 PyObject *exponent;
2276 Stream *exponent_stream;
2277 int modebuffer[4];
2278 } M_Pow;
2279
2280 static void
2281 M_Pow_readframes_ii(M_Pow *self)
2282 {
2283 int i;
2284
2285 MYFLT base = PyFloat_AS_DOUBLE(self->base);
2286 MYFLT exp = PyFloat_AS_DOUBLE(self->exponent);
2287
2288 for (i = 0; i < self->bufsize; i++)
2289 {
2290 self->data[i] = MYPOW(base, exp);
2291 }
2292 }
2293
2294 static void
2295 M_Pow_readframes_ai(M_Pow *self)
2296 {
2297 int i;
2298
2299 MYFLT *base = Stream_getData((Stream *)self->base_stream);
2300 MYFLT exp = PyFloat_AS_DOUBLE(self->exponent);
2301
2302 for (i = 0; i < self->bufsize; i++)
2303 {
2304 self->data[i] = MYPOW(base[i], exp);
2305 }
2306 }
2307
2308 static void
2309 M_Pow_readframes_ia(M_Pow *self)
2310 {
2311 int i;
2312
2313 MYFLT base = PyFloat_AS_DOUBLE(self->base);
2314 MYFLT *exp = Stream_getData((Stream *)self->exponent_stream);
2315
2316 for (i = 0; i < self->bufsize; i++)
2317 {
2318 self->data[i] = MYPOW(base, exp[i]);
2319 }
2320 }
2321
2322 static void
2323 M_Pow_readframes_aa(M_Pow *self)
2324 {
2325 int i;
2326
2327 MYFLT *base = Stream_getData((Stream *)self->base_stream);
2328 MYFLT *exp = Stream_getData((Stream *)self->exponent_stream);
2329
2330 for (i = 0; i < self->bufsize; i++)
2331 {
2332 self->data[i] = MYPOW(base[i], exp[i]);
2333 }
2334 }
2335
2336 static void M_Pow_postprocessing_ii(M_Pow *self) { POST_PROCESSING_II };
2337 static void M_Pow_postprocessing_ai(M_Pow *self) { POST_PROCESSING_AI };
2338 static void M_Pow_postprocessing_ia(M_Pow *self) { POST_PROCESSING_IA };
2339 static void M_Pow_postprocessing_aa(M_Pow *self) { POST_PROCESSING_AA };
2340 static void M_Pow_postprocessing_ireva(M_Pow *self) { POST_PROCESSING_IREVA };
2341 static void M_Pow_postprocessing_areva(M_Pow *self) { POST_PROCESSING_AREVA };
2342 static void M_Pow_postprocessing_revai(M_Pow *self) { POST_PROCESSING_REVAI };
2343 static void M_Pow_postprocessing_revaa(M_Pow *self) { POST_PROCESSING_REVAA };
2344 static void M_Pow_postprocessing_revareva(M_Pow *self) { POST_PROCESSING_REVAREVA };
2345
2346 static void
2347 M_Pow_setProcMode(M_Pow *self)
2348 {
2349 int procmode, muladdmode;
2350 procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
2351 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
2352
2353 switch (procmode)
2354 {
2355 case 0:
2356 self->proc_func_ptr = M_Pow_readframes_ii;
2357 break;
2358
2359 case 1:
2360 self->proc_func_ptr = M_Pow_readframes_ai;
2361 break;
2362
2363 case 10:
2364 self->proc_func_ptr = M_Pow_readframes_ia;
2365 break;
2366
2367 case 11:
2368 self->proc_func_ptr = M_Pow_readframes_aa;
2369 break;
2370 }
2371
2372 switch (muladdmode)
2373 {
2374 case 0:
2375 self->muladd_func_ptr = M_Pow_postprocessing_ii;
2376 break;
2377
2378 case 1:
2379 self->muladd_func_ptr = M_Pow_postprocessing_ai;
2380 break;
2381
2382 case 2:
2383 self->muladd_func_ptr = M_Pow_postprocessing_revai;
2384 break;
2385
2386 case 10:
2387 self->muladd_func_ptr = M_Pow_postprocessing_ia;
2388 break;
2389
2390 case 11:
2391 self->muladd_func_ptr = M_Pow_postprocessing_aa;
2392 break;
2393
2394 case 12:
2395 self->muladd_func_ptr = M_Pow_postprocessing_revaa;
2396 break;
2397
2398 case 20:
2399 self->muladd_func_ptr = M_Pow_postprocessing_ireva;
2400 break;
2401
2402 case 21:
2403 self->muladd_func_ptr = M_Pow_postprocessing_areva;
2404 break;
2405
2406 case 22:
2407 self->muladd_func_ptr = M_Pow_postprocessing_revareva;
2408 break;
2409 }
2410 }
2411
2412 static void
2413 M_Pow_compute_next_data_frame(M_Pow *self)
2414 {
2415 (*self->proc_func_ptr)(self);
2416 (*self->muladd_func_ptr)(self);
2417 }
2418
2419 static int
2420 M_Pow_traverse(M_Pow *self, visitproc visit, void *arg)
2421 {
2422 pyo_VISIT
2423 Py_VISIT(self->exponent);
2424 Py_VISIT(self->base);
2425 return 0;
2426 }
2427
2428 static int
2429 M_Pow_clear(M_Pow *self)
2430 {
2431 pyo_CLEAR
2432 Py_CLEAR(self->exponent);
2433 Py_CLEAR(self->base);
2434 return 0;
2435 }
2436
2437 static void
2438 M_Pow_dealloc(M_Pow* self)
2439 {
2440 pyo_DEALLOC
2441 M_Pow_clear(self);
2442 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
2443 Py_TYPE(self)->tp_free((PyObject*)self);
2444 }
2445
2446 static PyObject *
2447 M_Pow_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2448 {
2449 int i;
2450 PyObject *basetmp = NULL, *exponenttmp = NULL, *multmp = NULL, *addtmp = NULL;
2451 M_Pow *self;
2452 self = (M_Pow *)type->tp_alloc(type, 0);
2453
2454 self->base = PyFloat_FromDouble(10);
2455 self->exponent = PyFloat_FromDouble(1);
2456 self->modebuffer[0] = 0;
2457 self->modebuffer[1] = 0;
2458 self->modebuffer[2] = 0;
2459 self->modebuffer[3] = 0;
2460
2461 INIT_OBJECT_COMMON
2462 Stream_setFunctionPtr(self->stream, M_Pow_compute_next_data_frame);
2463 self->mode_func_ptr = M_Pow_setProcMode;
2464
2465 static char *kwlist[] = {"base", "exponent", "mul", "add", NULL};
2466
2467 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", kwlist, &basetmp, &exponenttmp, &multmp, &addtmp))
2468 Py_RETURN_NONE;
2469
2470 if (basetmp)
2471 {
2472 PyObject_CallMethod((PyObject *)self, "setBase", "O", basetmp);
2473 }
2474
2475 if (exponenttmp)
2476 {
2477 PyObject_CallMethod((PyObject *)self, "setExponent", "O", exponenttmp);
2478 }
2479
2480 if (multmp)
2481 {
2482 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
2483 }
2484
2485 if (addtmp)
2486 {
2487 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
2488 }
2489
2490 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
2491
2492 (*self->mode_func_ptr)(self);
2493
2494 return (PyObject *)self;
2495 }
2496
2497 static PyObject * M_Pow_getServer(M_Pow* self) { GET_SERVER };
2498 static PyObject * M_Pow_getStream(M_Pow* self) { GET_STREAM };
2499 static PyObject * M_Pow_setMul(M_Pow *self, PyObject *arg) { SET_MUL };
2500 static PyObject * M_Pow_setAdd(M_Pow *self, PyObject *arg) { SET_ADD };
2501 static PyObject * M_Pow_setSub(M_Pow *self, PyObject *arg) { SET_SUB };
2502 static PyObject * M_Pow_setDiv(M_Pow *self, PyObject *arg) { SET_DIV };
2503
2504 static PyObject * M_Pow_play(M_Pow *self, PyObject *args, PyObject *kwds) { PLAY };
2505 static PyObject * M_Pow_out(M_Pow *self, PyObject *args, PyObject *kwds) { OUT };
2506 static PyObject * M_Pow_stop(M_Pow *self, PyObject *args, PyObject *kwds) { STOP };
2507
2508 static PyObject * M_Pow_multiply(M_Pow *self, PyObject *arg) { MULTIPLY };
2509 static PyObject * M_Pow_inplace_multiply(M_Pow *self, PyObject *arg) { INPLACE_MULTIPLY };
2510 static PyObject * M_Pow_add(M_Pow *self, PyObject *arg) { ADD };
2511 static PyObject * M_Pow_inplace_add(M_Pow *self, PyObject *arg) { INPLACE_ADD };
2512 static PyObject * M_Pow_sub(M_Pow *self, PyObject *arg) { SUB };
2513 static PyObject * M_Pow_inplace_sub(M_Pow *self, PyObject *arg) { INPLACE_SUB };
2514 static PyObject * M_Pow_div(M_Pow *self, PyObject *arg) { DIV };
2515 static PyObject * M_Pow_inplace_div(M_Pow *self, PyObject *arg) { INPLACE_DIV };
2516
2517 static PyObject * M_Pow_setBase(M_Pow *self, PyObject *arg) { SET_PARAM(self->base, self->base_stream, 2); }
2518 static PyObject * M_Pow_setExponent(M_Pow *self, PyObject *arg) { SET_PARAM(self->exponent, self->exponent_stream, 3); }
2519
2520 static PyMemberDef M_Pow_members[] =
2521 {
2522 {"server", T_OBJECT_EX, offsetof(M_Pow, server), 0, "Pyo server."},
2523 {"stream", T_OBJECT_EX, offsetof(M_Pow, stream), 0, "Stream object."},
2524 {"base", T_OBJECT_EX, offsetof(M_Pow, base), 0, "base composant."},
2525 {"exponent", T_OBJECT_EX, offsetof(M_Pow, exponent), 0, "exponent composant."},
2526 {"mul", T_OBJECT_EX, offsetof(M_Pow, mul), 0, "Mul factor."},
2527 {"add", T_OBJECT_EX, offsetof(M_Pow, add), 0, "Add factor."},
2528 {NULL} /* Sentinel */
2529 };
2530
2531 static PyMethodDef M_Pow_methods[] =
2532 {
2533 {"getServer", (PyCFunction)M_Pow_getServer, METH_NOARGS, "Returns server object."},
2534 {"_getStream", (PyCFunction)M_Pow_getStream, METH_NOARGS, "Returns stream object."},
2535 {"play", (PyCFunction)M_Pow_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
2536 {"out", (PyCFunction)M_Pow_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
2537 {"stop", (PyCFunction)M_Pow_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
2538 {"setBase", (PyCFunction)M_Pow_setBase, METH_O, "Sets base."},
2539 {"setExponent", (PyCFunction)M_Pow_setExponent, METH_O, "Sets exponent."},
2540 {"setMul", (PyCFunction)M_Pow_setMul, METH_O, "Sets mul factor."},
2541 {"setAdd", (PyCFunction)M_Pow_setAdd, METH_O, "Sets add factor."},
2542 {"setSub", (PyCFunction)M_Pow_setSub, METH_O, "Sets inverse add factor."},
2543 {"setDiv", (PyCFunction)M_Pow_setDiv, METH_O, "Sets inverse mul factor."},
2544 {NULL} /* Sentinel */
2545 };
2546
2547 static PyNumberMethods M_Pow_as_number =
2548 {
2549 (binaryfunc)M_Pow_add, /*nb_add*/
2550 (binaryfunc)M_Pow_sub, /*nb_subtract*/
2551 (binaryfunc)M_Pow_multiply, /*nb_multiply*/
2552 0, /*nb_remainder*/
2553 0, /*nb_divmod*/
2554 0, /*nb_power*/
2555 0, /*nb_neg*/
2556 0, /*nb_pos*/
2557 0, /*(unaryfunc)array_abs,*/
2558 0, /*nb_nonzero*/
2559 0, /*nb_invert*/
2560 0, /*nb_lshift*/
2561 0, /*nb_rshift*/
2562 0, /*nb_and*/
2563 0, /*nb_xor*/
2564 0, /*nb_or*/
2565 0, /*nb_int*/
2566 0, /*nb_long*/
2567 0, /*nb_float*/
2568 (binaryfunc)M_Pow_inplace_add, /*inplace_add*/
2569 (binaryfunc)M_Pow_inplace_sub, /*inplace_subtract*/
2570 (binaryfunc)M_Pow_inplace_multiply, /*inplace_multiply*/
2571 0, /*inplace_remainder*/
2572 0, /*inplace_power*/
2573 0, /*inplace_lshift*/
2574 0, /*inplace_rshift*/
2575 0, /*inplace_and*/
2576 0, /*inplace_xor*/
2577 0, /*inplace_or*/
2578 0, /*nb_floor_divide*/
2579 (binaryfunc)M_Pow_div, /*nb_true_divide*/
2580 0, /*nb_inplace_floor_divide*/
2581 (binaryfunc)M_Pow_inplace_div, /*nb_inplace_true_divide*/
2582 0, /* nb_index */
2583 };
2584
2585 PyTypeObject M_PowType =
2586 {
2587 PyVarObject_HEAD_INIT(NULL, 0)
2588 "_pyo.M_Pow_base", /*tp_name*/
2589 sizeof(M_Pow), /*tp_basicsize*/
2590 0, /*tp_itemsize*/
2591 (destructor)M_Pow_dealloc, /*tp_dealloc*/
2592 0, /*tp_print*/
2593 0, /*tp_getattr*/
2594 0, /*tp_setattr*/
2595 0, /*tp_as_async (tp_compare in Python 2)*/
2596 0, /*tp_repr*/
2597 &M_Pow_as_number, /*tp_as_number*/
2598 0, /*tp_as_sequence*/
2599 0, /*tp_as_mapping*/
2600 0, /*tp_hash */
2601 0, /*tp_call*/
2602 0, /*tp_str*/
2603 0, /*tp_getattro*/
2604 0, /*tp_setattro*/
2605 0, /*tp_as_buffer*/
2606 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
2607 "M_Pow objects. Power function.", /* tp_doc */
2608 (traverseproc)M_Pow_traverse, /* tp_traverse */
2609 (inquiry)M_Pow_clear, /* tp_clear */
2610 0, /* tp_richcompare */
2611 0, /* tp_weaklistoffset */
2612 0, /* tp_iter */
2613 0, /* tp_iternext */
2614 M_Pow_methods, /* tp_methods */
2615 M_Pow_members, /* tp_members */
2616 0, /* tp_getset */
2617 0, /* tp_base */
2618 0, /* tp_dict */
2619 0, /* tp_descr_get */
2620 0, /* tp_descr_set */
2621 0, /* tp_dictoffset */
2622 0, /* tp_init */
2623 0, /* tp_alloc */
2624 M_Pow_new, /* tp_new */
2625 };
2626
2627 /**************/
2628 /* M_Atan2 object */
2629 /**************/
2630 typedef struct
2631 {
2632 pyo_audio_HEAD
2633 PyObject *b;
2634 Stream *b_stream;
2635 PyObject *a;
2636 Stream *a_stream;
2637 int modebuffer[4];
2638 } M_Atan2;
2639
2640 static void
2641 M_Atan2_readframes_ii(M_Atan2 *self)
2642 {
2643 int i;
2644
2645 MYFLT b = PyFloat_AS_DOUBLE(self->b);
2646 MYFLT a = PyFloat_AS_DOUBLE(self->a);
2647
2648 for (i = 0; i < self->bufsize; i++)
2649 {
2650 self->data[i] = MYATAN2(b, a);
2651 }
2652 }
2653
2654 static void
2655 M_Atan2_readframes_ai(M_Atan2 *self)
2656 {
2657 int i;
2658
2659 MYFLT *b = Stream_getData((Stream *)self->b_stream);
2660 MYFLT a = PyFloat_AS_DOUBLE(self->a);
2661
2662 for (i = 0; i < self->bufsize; i++)
2663 {
2664 self->data[i] = MYATAN2(b[i], a);
2665 }
2666 }
2667
2668 static void
2669 M_Atan2_readframes_ia(M_Atan2 *self)
2670 {
2671 int i;
2672
2673 MYFLT b = PyFloat_AS_DOUBLE(self->b);
2674 MYFLT *a = Stream_getData((Stream *)self->a_stream);
2675
2676 for (i = 0; i < self->bufsize; i++)
2677 {
2678 self->data[i] = MYATAN2(b, a[i]);
2679 }
2680 }
2681
2682 static void
2683 M_Atan2_readframes_aa(M_Atan2 *self)
2684 {
2685 int i;
2686
2687 MYFLT *b = Stream_getData((Stream *)self->b_stream);
2688 MYFLT *a = Stream_getData((Stream *)self->a_stream);
2689
2690 for (i = 0; i < self->bufsize; i++)
2691 {
2692 self->data[i] = MYATAN2(b[i], a[i]);
2693 }
2694 }
2695
2696 static void M_Atan2_postprocessing_ii(M_Atan2 *self) { POST_PROCESSING_II };
2697 static void M_Atan2_postprocessing_ai(M_Atan2 *self) { POST_PROCESSING_AI };
2698 static void M_Atan2_postprocessing_ia(M_Atan2 *self) { POST_PROCESSING_IA };
2699 static void M_Atan2_postprocessing_aa(M_Atan2 *self) { POST_PROCESSING_AA };
2700 static void M_Atan2_postprocessing_ireva(M_Atan2 *self) { POST_PROCESSING_IREVA };
2701 static void M_Atan2_postprocessing_areva(M_Atan2 *self) { POST_PROCESSING_AREVA };
2702 static void M_Atan2_postprocessing_revai(M_Atan2 *self) { POST_PROCESSING_REVAI };
2703 static void M_Atan2_postprocessing_revaa(M_Atan2 *self) { POST_PROCESSING_REVAA };
2704 static void M_Atan2_postprocessing_revareva(M_Atan2 *self) { POST_PROCESSING_REVAREVA };
2705
2706 static void
2707 M_Atan2_setProcMode(M_Atan2 *self)
2708 {
2709 int procmode, muladdmode;
2710 procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
2711 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
2712
2713 switch (procmode)
2714 {
2715 case 0:
2716 self->proc_func_ptr = M_Atan2_readframes_ii;
2717 break;
2718
2719 case 1:
2720 self->proc_func_ptr = M_Atan2_readframes_ai;
2721 break;
2722
2723 case 10:
2724 self->proc_func_ptr = M_Atan2_readframes_ia;
2725 break;
2726
2727 case 11:
2728 self->proc_func_ptr = M_Atan2_readframes_aa;
2729 break;
2730 }
2731
2732 switch (muladdmode)
2733 {
2734 case 0:
2735 self->muladd_func_ptr = M_Atan2_postprocessing_ii;
2736 break;
2737
2738 case 1:
2739 self->muladd_func_ptr = M_Atan2_postprocessing_ai;
2740 break;
2741
2742 case 2:
2743 self->muladd_func_ptr = M_Atan2_postprocessing_revai;
2744 break;
2745
2746 case 10:
2747 self->muladd_func_ptr = M_Atan2_postprocessing_ia;
2748 break;
2749
2750 case 11:
2751 self->muladd_func_ptr = M_Atan2_postprocessing_aa;
2752 break;
2753
2754 case 12:
2755 self->muladd_func_ptr = M_Atan2_postprocessing_revaa;
2756 break;
2757
2758 case 20:
2759 self->muladd_func_ptr = M_Atan2_postprocessing_ireva;
2760 break;
2761
2762 case 21:
2763 self->muladd_func_ptr = M_Atan2_postprocessing_areva;
2764 break;
2765
2766 case 22:
2767 self->muladd_func_ptr = M_Atan2_postprocessing_revareva;
2768 break;
2769 }
2770 }
2771
2772 static void
2773 M_Atan2_compute_next_data_frame(M_Atan2 *self)
2774 {
2775 (*self->proc_func_ptr)(self);
2776 (*self->muladd_func_ptr)(self);
2777 }
2778
2779 static int
2780 M_Atan2_traverse(M_Atan2 *self, visitproc visit, void *arg)
2781 {
2782 pyo_VISIT
2783 Py_VISIT(self->b);
2784 Py_VISIT(self->a);
2785 return 0;
2786 }
2787
2788 static int
2789 M_Atan2_clear(M_Atan2 *self)
2790 {
2791 pyo_CLEAR
2792 Py_CLEAR(self->b);
2793 Py_CLEAR(self->a);
2794 return 0;
2795 }
2796
2797 static void
2798 M_Atan2_dealloc(M_Atan2* self)
2799 {
2800 pyo_DEALLOC
2801 M_Atan2_clear(self);
2802 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
2803 Py_TYPE(self)->tp_free((PyObject*)self);
2804 }
2805
2806 static PyObject *
2807 M_Atan2_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2808 {
2809 int i;
2810 PyObject *btmp = NULL, *atmp = NULL, *multmp = NULL, *addtmp = NULL;
2811 M_Atan2 *self;
2812 self = (M_Atan2 *)type->tp_alloc(type, 0);
2813
2814 self->a = PyFloat_FromDouble(1);
2815 self->b = PyFloat_FromDouble(1);
2816 self->modebuffer[0] = 0;
2817 self->modebuffer[1] = 0;
2818 self->modebuffer[2] = 0;
2819 self->modebuffer[3] = 0;
2820
2821 INIT_OBJECT_COMMON
2822 Stream_setFunctionPtr(self->stream, M_Atan2_compute_next_data_frame);
2823 self->mode_func_ptr = M_Atan2_setProcMode;
2824
2825 static char *kwlist[] = {"b", "a", "mul", "add", NULL};
2826
2827 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", kwlist, &btmp, &atmp, &multmp, &addtmp))
2828 Py_RETURN_NONE;
2829
2830 if (btmp)
2831 {
2832 PyObject_CallMethod((PyObject *)self, "setB", "O", btmp);
2833 }
2834
2835 if (atmp)
2836 {
2837 PyObject_CallMethod((PyObject *)self, "setA", "O", atmp);
2838 }
2839
2840 if (multmp)
2841 {
2842 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
2843 }
2844
2845 if (addtmp)
2846 {
2847 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
2848 }
2849
2850 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
2851
2852 (*self->mode_func_ptr)(self);
2853
2854 return (PyObject *)self;
2855 }
2856
2857 static PyObject * M_Atan2_getServer(M_Atan2* self) { GET_SERVER };
2858 static PyObject * M_Atan2_getStream(M_Atan2* self) { GET_STREAM };
2859 static PyObject * M_Atan2_setMul(M_Atan2 *self, PyObject *arg) { SET_MUL };
2860 static PyObject * M_Atan2_setAdd(M_Atan2 *self, PyObject *arg) { SET_ADD };
2861 static PyObject * M_Atan2_setSub(M_Atan2 *self, PyObject *arg) { SET_SUB };
2862 static PyObject * M_Atan2_setDiv(M_Atan2 *self, PyObject *arg) { SET_DIV };
2863
2864 static PyObject * M_Atan2_play(M_Atan2 *self, PyObject *args, PyObject *kwds) { PLAY };
2865 static PyObject * M_Atan2_out(M_Atan2 *self, PyObject *args, PyObject *kwds) { OUT };
2866 static PyObject * M_Atan2_stop(M_Atan2 *self, PyObject *args, PyObject *kwds) { STOP };
2867
2868 static PyObject * M_Atan2_multiply(M_Atan2 *self, PyObject *arg) { MULTIPLY };
2869 static PyObject * M_Atan2_inplace_multiply(M_Atan2 *self, PyObject *arg) { INPLACE_MULTIPLY };
2870 static PyObject * M_Atan2_add(M_Atan2 *self, PyObject *arg) { ADD };
2871 static PyObject * M_Atan2_inplace_add(M_Atan2 *self, PyObject *arg) { INPLACE_ADD };
2872 static PyObject * M_Atan2_sub(M_Atan2 *self, PyObject *arg) { SUB };
2873 static PyObject * M_Atan2_inplace_sub(M_Atan2 *self, PyObject *arg) { INPLACE_SUB };
2874 static PyObject * M_Atan2_div(M_Atan2 *self, PyObject *arg) { DIV };
2875 static PyObject * M_Atan2_inplace_div(M_Atan2 *self, PyObject *arg) { INPLACE_DIV };
2876
2877 static PyObject * M_Atan2_setB(M_Atan2 *self, PyObject *arg) { SET_PARAM(self->b, self->b_stream, 2); }
2878 static PyObject * M_Atan2_setA(M_Atan2 *self, PyObject *arg) { SET_PARAM(self->a, self->a_stream, 3); }
2879
2880 static PyMemberDef M_Atan2_members[] =
2881 {
2882 {"server", T_OBJECT_EX, offsetof(M_Atan2, server), 0, "Pyo server."},
2883 {"stream", T_OBJECT_EX, offsetof(M_Atan2, stream), 0, "Stream object."},
2884 {"b", T_OBJECT_EX, offsetof(M_Atan2, b), 0, "b composant."},
2885 {"a", T_OBJECT_EX, offsetof(M_Atan2, a), 0, "a composant."},
2886 {"mul", T_OBJECT_EX, offsetof(M_Atan2, mul), 0, "Mul factor."},
2887 {"add", T_OBJECT_EX, offsetof(M_Atan2, add), 0, "Add factor."},
2888 {NULL} /* Sentinel */
2889 };
2890
2891 static PyMethodDef M_Atan2_methods[] =
2892 {
2893 {"getServer", (PyCFunction)M_Atan2_getServer, METH_NOARGS, "Returns server object."},
2894 {"_getStream", (PyCFunction)M_Atan2_getStream, METH_NOARGS, "Returns stream object."},
2895 {"play", (PyCFunction)M_Atan2_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
2896 {"out", (PyCFunction)M_Atan2_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
2897 {"stop", (PyCFunction)M_Atan2_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
2898 {"setB", (PyCFunction)M_Atan2_setB, METH_O, "Sets b."},
2899 {"setA", (PyCFunction)M_Atan2_setA, METH_O, "Sets a."},
2900 {"setMul", (PyCFunction)M_Atan2_setMul, METH_O, "Sets mul factor."},
2901 {"setAdd", (PyCFunction)M_Atan2_setAdd, METH_O, "Sets add factor."},
2902 {"setSub", (PyCFunction)M_Atan2_setSub, METH_O, "Sets inverse add factor."},
2903 {"setDiv", (PyCFunction)M_Atan2_setDiv, METH_O, "Sets inverse mul factor."},
2904 {NULL} /* Sentinel */
2905 };
2906
2907 static PyNumberMethods M_Atan2_as_number =
2908 {
2909 (binaryfunc)M_Atan2_add, /*nb_add*/
2910 (binaryfunc)M_Atan2_sub, /*nb_subtract*/
2911 (binaryfunc)M_Atan2_multiply, /*nb_multiply*/
2912 0, /*nb_remainder*/
2913 0, /*nb_divmod*/
2914 0, /*nb_power*/
2915 0, /*nb_neg*/
2916 0, /*nb_pos*/
2917 0, /*(unaryfunc)array_abs,*/
2918 0, /*nb_nonzero*/
2919 0, /*nb_invert*/
2920 0, /*nb_lshift*/
2921 0, /*nb_rshift*/
2922 0, /*nb_and*/
2923 0, /*nb_xor*/
2924 0, /*nb_or*/
2925 0, /*nb_int*/
2926 0, /*nb_long*/
2927 0, /*nb_float*/
2928 (binaryfunc)M_Atan2_inplace_add, /*inplace_add*/
2929 (binaryfunc)M_Atan2_inplace_sub, /*inplace_subtract*/
2930 (binaryfunc)M_Atan2_inplace_multiply, /*inplace_multiply*/
2931 0, /*inplace_remainder*/
2932 0, /*inplace_power*/
2933 0, /*inplace_lshift*/
2934 0, /*inplace_rshift*/
2935 0, /*inplace_and*/
2936 0, /*inplace_xor*/
2937 0, /*inplace_or*/
2938 0, /*nb_floor_divide*/
2939 (binaryfunc)M_Atan2_div, /*nb_true_divide*/
2940 0, /*nb_inplace_floor_divide*/
2941 (binaryfunc)M_Atan2_inplace_div, /*nb_inplace_true_divide*/
2942 0, /* nb_index */
2943 };
2944
2945 PyTypeObject M_Atan2Type =
2946 {
2947 PyVarObject_HEAD_INIT(NULL, 0)
2948 "_pyo.M_Atan2_base", /*tp_name*/
2949 sizeof(M_Atan2), /*tp_basicsize*/
2950 0, /*tp_itemsize*/
2951 (destructor)M_Atan2_dealloc, /*tp_dealloc*/
2952 0, /*tp_print*/
2953 0, /*tp_getattr*/
2954 0, /*tp_setattr*/
2955 0, /*tp_as_async (tp_compare in Python 2)*/
2956 0, /*tp_repr*/
2957 &M_Atan2_as_number, /*tp_as_number*/
2958 0, /*tp_as_sequence*/
2959 0, /*tp_as_mapping*/
2960 0, /*tp_hash */
2961 0, /*tp_call*/
2962 0, /*tp_str*/
2963 0, /*tp_getattro*/
2964 0, /*tp_setattro*/
2965 0, /*tp_as_buffer*/
2966 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
2967 "M_Atan2 objects. Atan2er function.", /* tp_doc */
2968 (traverseproc)M_Atan2_traverse, /* tp_traverse */
2969 (inquiry)M_Atan2_clear, /* tp_clear */
2970 0, /* tp_richcompare */
2971 0, /* tp_weaklistoffset */
2972 0, /* tp_iter */
2973 0, /* tp_iternext */
2974 M_Atan2_methods, /* tp_methods */
2975 M_Atan2_members, /* tp_members */
2976 0, /* tp_getset */
2977 0, /* tp_base */
2978 0, /* tp_dict */
2979 0, /* tp_descr_get */
2980 0, /* tp_descr_set */
2981 0, /* tp_dictoffset */
2982 0, /* tp_init */
2983 0, /* tp_alloc */
2984 M_Atan2_new, /* tp_new */
2985 };
2986
2987 /************/
2988 /* M_Floor */
2989 /************/
2990 typedef struct
2991 {
2992 pyo_audio_HEAD
2993 PyObject *input;
2994 Stream *input_stream;
2995 int modebuffer[2]; // need at least 2 slots for mul & add
2996 } M_Floor;
2997
2998 static void
2999 M_Floor_process(M_Floor *self)
3000 {
3001 int i;
3002 MYFLT *in = Stream_getData((Stream *)self->input_stream);
3003
3004 for (i = 0; i < self->bufsize; i++)
3005 {
3006 self->data[i] = MYFLOOR(in[i]);
3007 }
3008 }
3009
3010 static void M_Floor_postprocessing_ii(M_Floor *self) { POST_PROCESSING_II };
3011 static void M_Floor_postprocessing_ai(M_Floor *self) { POST_PROCESSING_AI };
3012 static void M_Floor_postprocessing_ia(M_Floor *self) { POST_PROCESSING_IA };
3013 static void M_Floor_postprocessing_aa(M_Floor *self) { POST_PROCESSING_AA };
3014 static void M_Floor_postprocessing_ireva(M_Floor *self) { POST_PROCESSING_IREVA };
3015 static void M_Floor_postprocessing_areva(M_Floor *self) { POST_PROCESSING_AREVA };
3016 static void M_Floor_postprocessing_revai(M_Floor *self) { POST_PROCESSING_REVAI };
3017 static void M_Floor_postprocessing_revaa(M_Floor *self) { POST_PROCESSING_REVAA };
3018 static void M_Floor_postprocessing_revareva(M_Floor *self) { POST_PROCESSING_REVAREVA };
3019
3020 static void
3021 M_Floor_setProcMode(M_Floor *self)
3022 {
3023 int muladdmode;
3024 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
3025
3026 self->proc_func_ptr = M_Floor_process;
3027
3028 switch (muladdmode)
3029 {
3030 case 0:
3031 self->muladd_func_ptr = M_Floor_postprocessing_ii;
3032 break;
3033
3034 case 1:
3035 self->muladd_func_ptr = M_Floor_postprocessing_ai;
3036 break;
3037
3038 case 2:
3039 self->muladd_func_ptr = M_Floor_postprocessing_revai;
3040 break;
3041
3042 case 10:
3043 self->muladd_func_ptr = M_Floor_postprocessing_ia;
3044 break;
3045
3046 case 11:
3047 self->muladd_func_ptr = M_Floor_postprocessing_aa;
3048 break;
3049
3050 case 12:
3051 self->muladd_func_ptr = M_Floor_postprocessing_revaa;
3052 break;
3053
3054 case 20:
3055 self->muladd_func_ptr = M_Floor_postprocessing_ireva;
3056 break;
3057
3058 case 21:
3059 self->muladd_func_ptr = M_Floor_postprocessing_areva;
3060 break;
3061
3062 case 22:
3063 self->muladd_func_ptr = M_Floor_postprocessing_revareva;
3064 break;
3065 }
3066 }
3067
3068 static void
3069 M_Floor_compute_next_data_frame(M_Floor *self)
3070 {
3071 (*self->proc_func_ptr)(self);
3072 (*self->muladd_func_ptr)(self);
3073 }
3074
3075 static int
3076 M_Floor_traverse(M_Floor *self, visitproc visit, void *arg)
3077 {
3078 pyo_VISIT
3079 Py_VISIT(self->input);
3080 return 0;
3081 }
3082
3083 static int
3084 M_Floor_clear(M_Floor *self)
3085 {
3086 pyo_CLEAR
3087 Py_CLEAR(self->input);
3088 return 0;
3089 }
3090
3091 static void
3092 M_Floor_dealloc(M_Floor* self)
3093 {
3094 pyo_DEALLOC
3095 M_Floor_clear(self);
3096 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
3097 Py_TYPE(self)->tp_free((PyObject*)self);
3098 }
3099
3100 static PyObject *
3101 M_Floor_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
3102 {
3103 int i;
3104 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
3105 M_Floor *self;
3106 self = (M_Floor *)type->tp_alloc(type, 0);
3107
3108 self->modebuffer[0] = 0;
3109 self->modebuffer[1] = 0;
3110
3111 INIT_OBJECT_COMMON
3112 Stream_setFunctionPtr(self->stream, M_Floor_compute_next_data_frame);
3113 self->mode_func_ptr = M_Floor_setProcMode;
3114
3115 static char *kwlist[] = {"input", "mul", "add", NULL};
3116
3117 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
3118 Py_RETURN_NONE;
3119
3120 INIT_INPUT_STREAM
3121
3122 if (multmp)
3123 {
3124 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
3125 }
3126
3127 if (addtmp)
3128 {
3129 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
3130 }
3131
3132 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
3133
3134 (*self->mode_func_ptr)(self);
3135
3136 return (PyObject *)self;
3137 }
3138
3139 static PyObject * M_Floor_getServer(M_Floor* self) { GET_SERVER };
3140 static PyObject * M_Floor_getStream(M_Floor* self) { GET_STREAM };
3141 static PyObject * M_Floor_setMul(M_Floor *self, PyObject *arg) { SET_MUL };
3142 static PyObject * M_Floor_setAdd(M_Floor *self, PyObject *arg) { SET_ADD };
3143 static PyObject * M_Floor_setSub(M_Floor *self, PyObject *arg) { SET_SUB };
3144 static PyObject * M_Floor_setDiv(M_Floor *self, PyObject *arg) { SET_DIV };
3145
3146 static PyObject * M_Floor_play(M_Floor *self, PyObject *args, PyObject *kwds) { PLAY };
3147 static PyObject * M_Floor_out(M_Floor *self, PyObject *args, PyObject *kwds) { OUT };
3148 static PyObject * M_Floor_stop(M_Floor *self, PyObject *args, PyObject *kwds) { STOP };
3149
3150 static PyObject * M_Floor_multiply(M_Floor *self, PyObject *arg) { MULTIPLY };
3151 static PyObject * M_Floor_inplace_multiply(M_Floor *self, PyObject *arg) { INPLACE_MULTIPLY };
3152 static PyObject * M_Floor_add(M_Floor *self, PyObject *arg) { ADD };
3153 static PyObject * M_Floor_inplace_add(M_Floor *self, PyObject *arg) { INPLACE_ADD };
3154 static PyObject * M_Floor_sub(M_Floor *self, PyObject *arg) { SUB };
3155 static PyObject * M_Floor_inplace_sub(M_Floor *self, PyObject *arg) { INPLACE_SUB };
3156 static PyObject * M_Floor_div(M_Floor *self, PyObject *arg) { DIV };
3157 static PyObject * M_Floor_inplace_div(M_Floor *self, PyObject *arg) { INPLACE_DIV };
3158
3159 static PyMemberDef M_Floor_members[] =
3160 {
3161 {"server", T_OBJECT_EX, offsetof(M_Floor, server), 0, "Pyo server."},
3162 {"stream", T_OBJECT_EX, offsetof(M_Floor, stream), 0, "Stream object."},
3163 {"input", T_OBJECT_EX, offsetof(M_Floor, input), 0, "Input sound object."},
3164 {"mul", T_OBJECT_EX, offsetof(M_Floor, mul), 0, "Mul factor."},
3165 {"add", T_OBJECT_EX, offsetof(M_Floor, add), 0, "Add factor."},
3166 {NULL} /* Sentinel */
3167 };
3168
3169 static PyMethodDef M_Floor_methods[] =
3170 {
3171 {"getServer", (PyCFunction)M_Floor_getServer, METH_NOARGS, "Returns server object."},
3172 {"_getStream", (PyCFunction)M_Floor_getStream, METH_NOARGS, "Returns stream object."},
3173 {"play", (PyCFunction)M_Floor_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
3174 {"stop", (PyCFunction)M_Floor_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
3175 {"out", (PyCFunction)M_Floor_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
3176 {"setMul", (PyCFunction)M_Floor_setMul, METH_O, "Sets oscillator mul factor."},
3177 {"setAdd", (PyCFunction)M_Floor_setAdd, METH_O, "Sets oscillator add factor."},
3178 {"setSub", (PyCFunction)M_Floor_setSub, METH_O, "Sets inverse add factor."},
3179 {"setDiv", (PyCFunction)M_Floor_setDiv, METH_O, "Sets inverse mul factor."},
3180 {NULL} /* Sentinel */
3181 };
3182
3183 static PyNumberMethods M_Floor_as_number =
3184 {
3185 (binaryfunc)M_Floor_add, /*nb_add*/
3186 (binaryfunc)M_Floor_sub, /*nb_subtract*/
3187 (binaryfunc)M_Floor_multiply, /*nb_multiply*/
3188 0, /*nb_remainder*/
3189 0, /*nb_divmod*/
3190 0, /*nb_power*/
3191 0, /*nb_neg*/
3192 0, /*nb_pos*/
3193 0, /*(unaryfunc)array_abs,*/
3194 0, /*nb_nonzero*/
3195 0, /*nb_invert*/
3196 0, /*nb_lshift*/
3197 0, /*nb_rshift*/
3198 0, /*nb_and*/
3199 0, /*nb_xor*/
3200 0, /*nb_or*/
3201 0, /*nb_int*/
3202 0, /*nb_long*/
3203 0, /*nb_float*/
3204 (binaryfunc)M_Floor_inplace_add, /*inplace_add*/
3205 (binaryfunc)M_Floor_inplace_sub, /*inplace_subtract*/
3206 (binaryfunc)M_Floor_inplace_multiply, /*inplace_multiply*/
3207 0, /*inplace_remainder*/
3208 0, /*inplace_power*/
3209 0, /*inplace_lshift*/
3210 0, /*inplace_rshift*/
3211 0, /*inplace_and*/
3212 0, /*inplace_xor*/
3213 0, /*inplace_or*/
3214 0, /*nb_floor_divide*/
3215 (binaryfunc)M_Floor_div, /*nb_true_divide*/
3216 0, /*nb_inplace_floor_divide*/
3217 (binaryfunc)M_Floor_inplace_div, /*nb_inplace_true_divide*/
3218 0, /* nb_index */
3219 };
3220
3221 PyTypeObject M_FloorType =
3222 {
3223 PyVarObject_HEAD_INIT(NULL, 0)
3224 "_pyo.M_Floor_base", /*tp_name*/
3225 sizeof(M_Floor), /*tp_basicsize*/
3226 0, /*tp_itemsize*/
3227 (destructor)M_Floor_dealloc, /*tp_dealloc*/
3228 0, /*tp_print*/
3229 0, /*tp_getattr*/
3230 0, /*tp_setattr*/
3231 0, /*tp_as_async (tp_compare in Python 2)*/
3232 0, /*tp_repr*/
3233 &M_Floor_as_number, /*tp_as_number*/
3234 0, /*tp_as_sequence*/
3235 0, /*tp_as_mapping*/
3236 0, /*tp_hash */
3237 0, /*tp_call*/
3238 0, /*tp_str*/
3239 0, /*tp_getattro*/
3240 0, /*tp_setattro*/
3241 0, /*tp_as_buffer*/
3242 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
3243 "M_Floor objects. Performs sqrt function on audio samples.", /* tp_doc */
3244 (traverseproc)M_Floor_traverse, /* tp_traverse */
3245 (inquiry)M_Floor_clear, /* tp_clear */
3246 0, /* tp_richcompare */
3247 0, /* tp_weaklistoffset */
3248 0, /* tp_iter */
3249 0, /* tp_iternext */
3250 M_Floor_methods, /* tp_methods */
3251 M_Floor_members, /* tp_members */
3252 0, /* tp_getset */
3253 0, /* tp_base */
3254 0, /* tp_dict */
3255 0, /* tp_descr_get */
3256 0, /* tp_descr_set */
3257 0, /* tp_dictoffset */
3258 0, /* tp_init */
3259 0, /* tp_alloc */
3260 M_Floor_new, /* tp_new */
3261 };
3262
3263 /************/
3264 /* M_Ceil */
3265 /************/
3266 typedef struct
3267 {
3268 pyo_audio_HEAD
3269 PyObject *input;
3270 Stream *input_stream;
3271 int modebuffer[2]; // need at least 2 slots for mul & add
3272 } M_Ceil;
3273
3274 static void
3275 M_Ceil_process(M_Ceil *self)
3276 {
3277 int i;
3278 MYFLT *in = Stream_getData((Stream *)self->input_stream);
3279
3280 for (i = 0; i < self->bufsize; i++)
3281 {
3282 self->data[i] = MYCEIL(in[i]);
3283 }
3284 }
3285
3286 static void M_Ceil_postprocessing_ii(M_Ceil *self) { POST_PROCESSING_II };
3287 static void M_Ceil_postprocessing_ai(M_Ceil *self) { POST_PROCESSING_AI };
3288 static void M_Ceil_postprocessing_ia(M_Ceil *self) { POST_PROCESSING_IA };
3289 static void M_Ceil_postprocessing_aa(M_Ceil *self) { POST_PROCESSING_AA };
3290 static void M_Ceil_postprocessing_ireva(M_Ceil *self) { POST_PROCESSING_IREVA };
3291 static void M_Ceil_postprocessing_areva(M_Ceil *self) { POST_PROCESSING_AREVA };
3292 static void M_Ceil_postprocessing_revai(M_Ceil *self) { POST_PROCESSING_REVAI };
3293 static void M_Ceil_postprocessing_revaa(M_Ceil *self) { POST_PROCESSING_REVAA };
3294 static void M_Ceil_postprocessing_revareva(M_Ceil *self) { POST_PROCESSING_REVAREVA };
3295
3296 static void
3297 M_Ceil_setProcMode(M_Ceil *self)
3298 {
3299 int muladdmode;
3300 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
3301
3302 self->proc_func_ptr = M_Ceil_process;
3303
3304 switch (muladdmode)
3305 {
3306 case 0:
3307 self->muladd_func_ptr = M_Ceil_postprocessing_ii;
3308 break;
3309
3310 case 1:
3311 self->muladd_func_ptr = M_Ceil_postprocessing_ai;
3312 break;
3313
3314 case 2:
3315 self->muladd_func_ptr = M_Ceil_postprocessing_revai;
3316 break;
3317
3318 case 10:
3319 self->muladd_func_ptr = M_Ceil_postprocessing_ia;
3320 break;
3321
3322 case 11:
3323 self->muladd_func_ptr = M_Ceil_postprocessing_aa;
3324 break;
3325
3326 case 12:
3327 self->muladd_func_ptr = M_Ceil_postprocessing_revaa;
3328 break;
3329
3330 case 20:
3331 self->muladd_func_ptr = M_Ceil_postprocessing_ireva;
3332 break;
3333
3334 case 21:
3335 self->muladd_func_ptr = M_Ceil_postprocessing_areva;
3336 break;
3337
3338 case 22:
3339 self->muladd_func_ptr = M_Ceil_postprocessing_revareva;
3340 break;
3341 }
3342 }
3343
3344 static void
3345 M_Ceil_compute_next_data_frame(M_Ceil *self)
3346 {
3347 (*self->proc_func_ptr)(self);
3348 (*self->muladd_func_ptr)(self);
3349 }
3350
3351 static int
3352 M_Ceil_traverse(M_Ceil *self, visitproc visit, void *arg)
3353 {
3354 pyo_VISIT
3355 Py_VISIT(self->input);
3356 return 0;
3357 }
3358
3359 static int
3360 M_Ceil_clear(M_Ceil *self)
3361 {
3362 pyo_CLEAR
3363 Py_CLEAR(self->input);
3364 return 0;
3365 }
3366
3367 static void
3368 M_Ceil_dealloc(M_Ceil* self)
3369 {
3370 pyo_DEALLOC
3371 M_Ceil_clear(self);
3372 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
3373 Py_TYPE(self)->tp_free((PyObject*)self);
3374 }
3375
3376 static PyObject *
3377 M_Ceil_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
3378 {
3379 int i;
3380 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
3381 M_Ceil *self;
3382 self = (M_Ceil *)type->tp_alloc(type, 0);
3383
3384 self->modebuffer[0] = 0;
3385 self->modebuffer[1] = 0;
3386
3387 INIT_OBJECT_COMMON
3388 Stream_setFunctionPtr(self->stream, M_Ceil_compute_next_data_frame);
3389 self->mode_func_ptr = M_Ceil_setProcMode;
3390
3391 static char *kwlist[] = {"input", "mul", "add", NULL};
3392
3393 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
3394 Py_RETURN_NONE;
3395
3396 INIT_INPUT_STREAM
3397
3398 if (multmp)
3399 {
3400 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
3401 }
3402
3403 if (addtmp)
3404 {
3405 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
3406 }
3407
3408 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
3409
3410 (*self->mode_func_ptr)(self);
3411
3412 return (PyObject *)self;
3413 }
3414
3415 static PyObject * M_Ceil_getServer(M_Ceil* self) { GET_SERVER };
3416 static PyObject * M_Ceil_getStream(M_Ceil* self) { GET_STREAM };
3417 static PyObject * M_Ceil_setMul(M_Ceil *self, PyObject *arg) { SET_MUL };
3418 static PyObject * M_Ceil_setAdd(M_Ceil *self, PyObject *arg) { SET_ADD };
3419 static PyObject * M_Ceil_setSub(M_Ceil *self, PyObject *arg) { SET_SUB };
3420 static PyObject * M_Ceil_setDiv(M_Ceil *self, PyObject *arg) { SET_DIV };
3421
3422 static PyObject * M_Ceil_play(M_Ceil *self, PyObject *args, PyObject *kwds) { PLAY };
3423 static PyObject * M_Ceil_out(M_Ceil *self, PyObject *args, PyObject *kwds) { OUT };
3424 static PyObject * M_Ceil_stop(M_Ceil *self, PyObject *args, PyObject *kwds) { STOP };
3425
3426 static PyObject * M_Ceil_multiply(M_Ceil *self, PyObject *arg) { MULTIPLY };
3427 static PyObject * M_Ceil_inplace_multiply(M_Ceil *self, PyObject *arg) { INPLACE_MULTIPLY };
3428 static PyObject * M_Ceil_add(M_Ceil *self, PyObject *arg) { ADD };
3429 static PyObject * M_Ceil_inplace_add(M_Ceil *self, PyObject *arg) { INPLACE_ADD };
3430 static PyObject * M_Ceil_sub(M_Ceil *self, PyObject *arg) { SUB };
3431 static PyObject * M_Ceil_inplace_sub(M_Ceil *self, PyObject *arg) { INPLACE_SUB };
3432 static PyObject * M_Ceil_div(M_Ceil *self, PyObject *arg) { DIV };
3433 static PyObject * M_Ceil_inplace_div(M_Ceil *self, PyObject *arg) { INPLACE_DIV };
3434
3435 static PyMemberDef M_Ceil_members[] =
3436 {
3437 {"server", T_OBJECT_EX, offsetof(M_Ceil, server), 0, "Pyo server."},
3438 {"stream", T_OBJECT_EX, offsetof(M_Ceil, stream), 0, "Stream object."},
3439 {"input", T_OBJECT_EX, offsetof(M_Ceil, input), 0, "Input sound object."},
3440 {"mul", T_OBJECT_EX, offsetof(M_Ceil, mul), 0, "Mul factor."},
3441 {"add", T_OBJECT_EX, offsetof(M_Ceil, add), 0, "Add factor."},
3442 {NULL} /* Sentinel */
3443 };
3444
3445 static PyMethodDef M_Ceil_methods[] =
3446 {
3447 {"getServer", (PyCFunction)M_Ceil_getServer, METH_NOARGS, "Returns server object."},
3448 {"_getStream", (PyCFunction)M_Ceil_getStream, METH_NOARGS, "Returns stream object."},
3449 {"play", (PyCFunction)M_Ceil_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
3450 {"stop", (PyCFunction)M_Ceil_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
3451 {"out", (PyCFunction)M_Ceil_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
3452 {"setMul", (PyCFunction)M_Ceil_setMul, METH_O, "Sets oscillator mul factor."},
3453 {"setAdd", (PyCFunction)M_Ceil_setAdd, METH_O, "Sets oscillator add factor."},
3454 {"setSub", (PyCFunction)M_Ceil_setSub, METH_O, "Sets inverse add factor."},
3455 {"setDiv", (PyCFunction)M_Ceil_setDiv, METH_O, "Sets inverse mul factor."},
3456 {NULL} /* Sentinel */
3457 };
3458
3459 static PyNumberMethods M_Ceil_as_number =
3460 {
3461 (binaryfunc)M_Ceil_add, /*nb_add*/
3462 (binaryfunc)M_Ceil_sub, /*nb_subtract*/
3463 (binaryfunc)M_Ceil_multiply, /*nb_multiply*/
3464 0, /*nb_remainder*/
3465 0, /*nb_divmod*/
3466 0, /*nb_power*/
3467 0, /*nb_neg*/
3468 0, /*nb_pos*/
3469 0, /*(unaryfunc)array_abs,*/
3470 0, /*nb_nonzero*/
3471 0, /*nb_invert*/
3472 0, /*nb_lshift*/
3473 0, /*nb_rshift*/
3474 0, /*nb_and*/
3475 0, /*nb_xor*/
3476 0, /*nb_or*/
3477 0, /*nb_int*/
3478 0, /*nb_long*/
3479 0, /*nb_float*/
3480 (binaryfunc)M_Ceil_inplace_add, /*inplace_add*/
3481 (binaryfunc)M_Ceil_inplace_sub, /*inplace_subtract*/
3482 (binaryfunc)M_Ceil_inplace_multiply, /*inplace_multiply*/
3483 0, /*inplace_remainder*/
3484 0, /*inplace_power*/
3485 0, /*inplace_lshift*/
3486 0, /*inplace_rshift*/
3487 0, /*inplace_and*/
3488 0, /*inplace_xor*/
3489 0, /*inplace_or*/
3490 0, /*nb_floor_divide*/
3491 (binaryfunc)M_Ceil_div, /*nb_true_divide*/
3492 0, /*nb_inplace_floor_divide*/
3493 (binaryfunc)M_Ceil_inplace_div, /*nb_inplace_true_divide*/
3494 0, /* nb_index */
3495 };
3496
3497 PyTypeObject M_CeilType =
3498 {
3499 PyVarObject_HEAD_INIT(NULL, 0)
3500 "_pyo.M_Ceil_base", /*tp_name*/
3501 sizeof(M_Ceil), /*tp_basicsize*/
3502 0, /*tp_itemsize*/
3503 (destructor)M_Ceil_dealloc, /*tp_dealloc*/
3504 0, /*tp_print*/
3505 0, /*tp_getattr*/
3506 0, /*tp_setattr*/
3507 0, /*tp_as_async (tp_compare in Python 2)*/
3508 0, /*tp_repr*/
3509 &M_Ceil_as_number, /*tp_as_number*/
3510 0, /*tp_as_sequence*/
3511 0, /*tp_as_mapping*/
3512 0, /*tp_hash */
3513 0, /*tp_call*/
3514 0, /*tp_str*/
3515 0, /*tp_getattro*/
3516 0, /*tp_setattro*/
3517 0, /*tp_as_buffer*/
3518 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
3519 "M_Ceil objects. Performs ceil function on audio samples.", /* tp_doc */
3520 (traverseproc)M_Ceil_traverse, /* tp_traverse */
3521 (inquiry)M_Ceil_clear, /* tp_clear */
3522 0, /* tp_richcompare */
3523 0, /* tp_weaklistoffset */
3524 0, /* tp_iter */
3525 0, /* tp_iternext */
3526 M_Ceil_methods, /* tp_methods */
3527 M_Ceil_members, /* tp_members */
3528 0, /* tp_getset */
3529 0, /* tp_base */
3530 0, /* tp_dict */
3531 0, /* tp_descr_get */
3532 0, /* tp_descr_set */
3533 0, /* tp_dictoffset */
3534 0, /* tp_init */
3535 0, /* tp_alloc */
3536 M_Ceil_new, /* tp_new */
3537 };
3538
3539 /************/
3540 /* M_Round */
3541 /************/
3542 typedef struct
3543 {
3544 pyo_audio_HEAD
3545 PyObject *input;
3546 Stream *input_stream;
3547 int modebuffer[2]; // need at least 2 slots for mul & add
3548 } M_Round;
3549
3550 static void
3551 M_Round_process(M_Round *self)
3552 {
3553 int i;
3554 MYFLT *in = Stream_getData((Stream *)self->input_stream);
3555
3556 for (i = 0; i < self->bufsize; i++)
3557 {
3558 self->data[i] = MYROUND(in[i]);
3559 }
3560 }
3561
3562 static void M_Round_postprocessing_ii(M_Round *self) { POST_PROCESSING_II };
3563 static void M_Round_postprocessing_ai(M_Round *self) { POST_PROCESSING_AI };
3564 static void M_Round_postprocessing_ia(M_Round *self) { POST_PROCESSING_IA };
3565 static void M_Round_postprocessing_aa(M_Round *self) { POST_PROCESSING_AA };
3566 static void M_Round_postprocessing_ireva(M_Round *self) { POST_PROCESSING_IREVA };
3567 static void M_Round_postprocessing_areva(M_Round *self) { POST_PROCESSING_AREVA };
3568 static void M_Round_postprocessing_revai(M_Round *self) { POST_PROCESSING_REVAI };
3569 static void M_Round_postprocessing_revaa(M_Round *self) { POST_PROCESSING_REVAA };
3570 static void M_Round_postprocessing_revareva(M_Round *self) { POST_PROCESSING_REVAREVA };
3571
3572 static void
3573 M_Round_setProcMode(M_Round *self)
3574 {
3575 int muladdmode;
3576 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
3577
3578 self->proc_func_ptr = M_Round_process;
3579
3580 switch (muladdmode)
3581 {
3582 case 0:
3583 self->muladd_func_ptr = M_Round_postprocessing_ii;
3584 break;
3585
3586 case 1:
3587 self->muladd_func_ptr = M_Round_postprocessing_ai;
3588 break;
3589
3590 case 2:
3591 self->muladd_func_ptr = M_Round_postprocessing_revai;
3592 break;
3593
3594 case 10:
3595 self->muladd_func_ptr = M_Round_postprocessing_ia;
3596 break;
3597
3598 case 11:
3599 self->muladd_func_ptr = M_Round_postprocessing_aa;
3600 break;
3601
3602 case 12:
3603 self->muladd_func_ptr = M_Round_postprocessing_revaa;
3604 break;
3605
3606 case 20:
3607 self->muladd_func_ptr = M_Round_postprocessing_ireva;
3608 break;
3609
3610 case 21:
3611 self->muladd_func_ptr = M_Round_postprocessing_areva;
3612 break;
3613
3614 case 22:
3615 self->muladd_func_ptr = M_Round_postprocessing_revareva;
3616 break;
3617 }
3618 }
3619
3620 static void
3621 M_Round_compute_next_data_frame(M_Round *self)
3622 {
3623 (*self->proc_func_ptr)(self);
3624 (*self->muladd_func_ptr)(self);
3625 }
3626
3627 static int
3628 M_Round_traverse(M_Round *self, visitproc visit, void *arg)
3629 {
3630 pyo_VISIT
3631 Py_VISIT(self->input);
3632 return 0;
3633 }
3634
3635 static int
3636 M_Round_clear(M_Round *self)
3637 {
3638 pyo_CLEAR
3639 Py_CLEAR(self->input);
3640 return 0;
3641 }
3642
3643 static void
3644 M_Round_dealloc(M_Round* self)
3645 {
3646 pyo_DEALLOC
3647 M_Round_clear(self);
3648 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
3649 Py_TYPE(self)->tp_free((PyObject*)self);
3650 }
3651
3652 static PyObject *
3653 M_Round_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
3654 {
3655 int i;
3656 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
3657 M_Round *self;
3658 self = (M_Round *)type->tp_alloc(type, 0);
3659
3660 self->modebuffer[0] = 0;
3661 self->modebuffer[1] = 0;
3662
3663 INIT_OBJECT_COMMON
3664 Stream_setFunctionPtr(self->stream, M_Round_compute_next_data_frame);
3665 self->mode_func_ptr = M_Round_setProcMode;
3666
3667 static char *kwlist[] = {"input", "mul", "add", NULL};
3668
3669 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
3670 Py_RETURN_NONE;
3671
3672 INIT_INPUT_STREAM
3673
3674 if (multmp)
3675 {
3676 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
3677 }
3678
3679 if (addtmp)
3680 {
3681 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
3682 }
3683
3684 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
3685
3686 (*self->mode_func_ptr)(self);
3687
3688 return (PyObject *)self;
3689 }
3690
3691 static PyObject * M_Round_getServer(M_Round* self) { GET_SERVER };
3692 static PyObject * M_Round_getStream(M_Round* self) { GET_STREAM };
3693 static PyObject * M_Round_setMul(M_Round *self, PyObject *arg) { SET_MUL };
3694 static PyObject * M_Round_setAdd(M_Round *self, PyObject *arg) { SET_ADD };
3695 static PyObject * M_Round_setSub(M_Round *self, PyObject *arg) { SET_SUB };
3696 static PyObject * M_Round_setDiv(M_Round *self, PyObject *arg) { SET_DIV };
3697
3698 static PyObject * M_Round_play(M_Round *self, PyObject *args, PyObject *kwds) { PLAY };
3699 static PyObject * M_Round_out(M_Round *self, PyObject *args, PyObject *kwds) { OUT };
3700 static PyObject * M_Round_stop(M_Round *self, PyObject *args, PyObject *kwds) { STOP };
3701
3702 static PyObject * M_Round_multiply(M_Round *self, PyObject *arg) { MULTIPLY };
3703 static PyObject * M_Round_inplace_multiply(M_Round *self, PyObject *arg) { INPLACE_MULTIPLY };
3704 static PyObject * M_Round_add(M_Round *self, PyObject *arg) { ADD };
3705 static PyObject * M_Round_inplace_add(M_Round *self, PyObject *arg) { INPLACE_ADD };
3706 static PyObject * M_Round_sub(M_Round *self, PyObject *arg) { SUB };
3707 static PyObject * M_Round_inplace_sub(M_Round *self, PyObject *arg) { INPLACE_SUB };
3708 static PyObject * M_Round_div(M_Round *self, PyObject *arg) { DIV };
3709 static PyObject * M_Round_inplace_div(M_Round *self, PyObject *arg) { INPLACE_DIV };
3710
3711 static PyMemberDef M_Round_members[] =
3712 {
3713 {"server", T_OBJECT_EX, offsetof(M_Round, server), 0, "Pyo server."},
3714 {"stream", T_OBJECT_EX, offsetof(M_Round, stream), 0, "Stream object."},
3715 {"input", T_OBJECT_EX, offsetof(M_Round, input), 0, "Input sound object."},
3716 {"mul", T_OBJECT_EX, offsetof(M_Round, mul), 0, "Mul factor."},
3717 {"add", T_OBJECT_EX, offsetof(M_Round, add), 0, "Add factor."},
3718 {NULL} /* Sentinel */
3719 };
3720
3721 static PyMethodDef M_Round_methods[] =
3722 {
3723 {"getServer", (PyCFunction)M_Round_getServer, METH_NOARGS, "Returns server object."},
3724 {"_getStream", (PyCFunction)M_Round_getStream, METH_NOARGS, "Returns stream object."},
3725 {"play", (PyCFunction)M_Round_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
3726 {"stop", (PyCFunction)M_Round_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
3727 {"out", (PyCFunction)M_Round_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
3728 {"setMul", (PyCFunction)M_Round_setMul, METH_O, "Sets oscillator mul factor."},
3729 {"setAdd", (PyCFunction)M_Round_setAdd, METH_O, "Sets oscillator add factor."},
3730 {"setSub", (PyCFunction)M_Round_setSub, METH_O, "Sets inverse add factor."},
3731 {"setDiv", (PyCFunction)M_Round_setDiv, METH_O, "Sets inverse mul factor."},
3732 {NULL} /* Sentinel */
3733 };
3734
3735 static PyNumberMethods M_Round_as_number =
3736 {
3737 (binaryfunc)M_Round_add, /*nb_add*/
3738 (binaryfunc)M_Round_sub, /*nb_subtract*/
3739 (binaryfunc)M_Round_multiply, /*nb_multiply*/
3740 0, /*nb_remainder*/
3741 0, /*nb_divmod*/
3742 0, /*nb_power*/
3743 0, /*nb_neg*/
3744 0, /*nb_pos*/
3745 0, /*(unaryfunc)array_abs,*/
3746 0, /*nb_nonzero*/
3747 0, /*nb_invert*/
3748 0, /*nb_lshift*/
3749 0, /*nb_rshift*/
3750 0, /*nb_and*/
3751 0, /*nb_xor*/
3752 0, /*nb_or*/
3753 0, /*nb_int*/
3754 0, /*nb_long*/
3755 0, /*nb_float*/
3756 (binaryfunc)M_Round_inplace_add, /*inplace_add*/
3757 (binaryfunc)M_Round_inplace_sub, /*inplace_subtract*/
3758 (binaryfunc)M_Round_inplace_multiply, /*inplace_multiply*/
3759 0, /*inplace_remainder*/
3760 0, /*inplace_power*/
3761 0, /*inplace_lshift*/
3762 0, /*inplace_rshift*/
3763 0, /*inplace_and*/
3764 0, /*inplace_xor*/
3765 0, /*inplace_or*/
3766 0, /*nb_floor_divide*/
3767 (binaryfunc)M_Round_div, /*nb_true_divide*/
3768 0, /*nb_inplace_floor_divide*/
3769 (binaryfunc)M_Round_inplace_div, /*nb_inplace_true_divide*/
3770 0, /* nb_index */
3771 };
3772
3773 PyTypeObject M_RoundType =
3774 {
3775 PyVarObject_HEAD_INIT(NULL, 0)
3776 "_pyo.M_Round_base", /*tp_name*/
3777 sizeof(M_Round), /*tp_basicsize*/
3778 0, /*tp_itemsize*/
3779 (destructor)M_Round_dealloc, /*tp_dealloc*/
3780 0, /*tp_print*/
3781 0, /*tp_getattr*/
3782 0, /*tp_setattr*/
3783 0, /*tp_as_async (tp_compare in Python 2)*/
3784 0, /*tp_repr*/
3785 &M_Round_as_number, /*tp_as_number*/
3786 0, /*tp_as_sequence*/
3787 0, /*tp_as_mapping*/
3788 0, /*tp_hash */
3789 0, /*tp_call*/
3790 0, /*tp_str*/
3791 0, /*tp_getattro*/
3792 0, /*tp_setattro*/
3793 0, /*tp_as_buffer*/
3794 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
3795 "M_Round objects. Performs sqrt function on audio samples.", /* tp_doc */
3796 (traverseproc)M_Round_traverse, /* tp_traverse */
3797 (inquiry)M_Round_clear, /* tp_clear */
3798 0, /* tp_richcompare */
3799 0, /* tp_weaklistoffset */
3800 0, /* tp_iter */
3801 0, /* tp_iternext */
3802 M_Round_methods, /* tp_methods */
3803 M_Round_members, /* tp_members */
3804 0, /* tp_getset */
3805 0, /* tp_base */
3806 0, /* tp_dict */
3807 0, /* tp_descr_get */
3808 0, /* tp_descr_set */
3809 0, /* tp_dictoffset */
3810 0, /* tp_init */
3811 0, /* tp_alloc */
3812 M_Round_new, /* tp_new */
3813 };
3814
3815 /************/
3816 /* M_Tanh */
3817 /************/
3818 typedef struct
3819 {
3820 pyo_audio_HEAD
3821 PyObject *input;
3822 Stream *input_stream;
3823 int modebuffer[2]; // need at least 2 slots for mul & add
3824 } M_Tanh;
3825
3826 static void
3827 M_Tanh_process(M_Tanh *self)
3828 {
3829 int i;
3830 MYFLT *in = Stream_getData((Stream *)self->input_stream);
3831
3832 for (i = 0; i < self->bufsize; i++)
3833 {
3834 self->data[i] = MYTANH(in[i]);
3835 }
3836 }
3837
3838 static void M_Tanh_postprocessing_ii(M_Tanh *self) { POST_PROCESSING_II };
3839 static void M_Tanh_postprocessing_ai(M_Tanh *self) { POST_PROCESSING_AI };
3840 static void M_Tanh_postprocessing_ia(M_Tanh *self) { POST_PROCESSING_IA };
3841 static void M_Tanh_postprocessing_aa(M_Tanh *self) { POST_PROCESSING_AA };
3842 static void M_Tanh_postprocessing_ireva(M_Tanh *self) { POST_PROCESSING_IREVA };
3843 static void M_Tanh_postprocessing_areva(M_Tanh *self) { POST_PROCESSING_AREVA };
3844 static void M_Tanh_postprocessing_revai(M_Tanh *self) { POST_PROCESSING_REVAI };
3845 static void M_Tanh_postprocessing_revaa(M_Tanh *self) { POST_PROCESSING_REVAA };
3846 static void M_Tanh_postprocessing_revareva(M_Tanh *self) { POST_PROCESSING_REVAREVA };
3847
3848 static void
3849 M_Tanh_setProcMode(M_Tanh *self)
3850 {
3851 int muladdmode;
3852 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
3853
3854 self->proc_func_ptr = M_Tanh_process;
3855
3856 switch (muladdmode)
3857 {
3858 case 0:
3859 self->muladd_func_ptr = M_Tanh_postprocessing_ii;
3860 break;
3861
3862 case 1:
3863 self->muladd_func_ptr = M_Tanh_postprocessing_ai;
3864 break;
3865
3866 case 2:
3867 self->muladd_func_ptr = M_Tanh_postprocessing_revai;
3868 break;
3869
3870 case 10:
3871 self->muladd_func_ptr = M_Tanh_postprocessing_ia;
3872 break;
3873
3874 case 11:
3875 self->muladd_func_ptr = M_Tanh_postprocessing_aa;
3876 break;
3877
3878 case 12:
3879 self->muladd_func_ptr = M_Tanh_postprocessing_revaa;
3880 break;
3881
3882 case 20:
3883 self->muladd_func_ptr = M_Tanh_postprocessing_ireva;
3884 break;
3885
3886 case 21:
3887 self->muladd_func_ptr = M_Tanh_postprocessing_areva;
3888 break;
3889
3890 case 22:
3891 self->muladd_func_ptr = M_Tanh_postprocessing_revareva;
3892 break;
3893 }
3894 }
3895
3896 static void
3897 M_Tanh_compute_next_data_frame(M_Tanh *self)
3898 {
3899 (*self->proc_func_ptr)(self);
3900 (*self->muladd_func_ptr)(self);
3901 }
3902
3903 static int
3904 M_Tanh_traverse(M_Tanh *self, visitproc visit, void *arg)
3905 {
3906 pyo_VISIT
3907 Py_VISIT(self->input);
3908 return 0;
3909 }
3910
3911 static int
3912 M_Tanh_clear(M_Tanh *self)
3913 {
3914 pyo_CLEAR
3915 Py_CLEAR(self->input);
3916 return 0;
3917 }
3918
3919 static void
3920 M_Tanh_dealloc(M_Tanh* self)
3921 {
3922 pyo_DEALLOC
3923 M_Tanh_clear(self);
3924 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
3925 Py_TYPE(self)->tp_free((PyObject*)self);
3926 }
3927
3928 static PyObject *
3929 M_Tanh_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
3930 {
3931 int i;
3932 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
3933 M_Tanh *self;
3934 self = (M_Tanh *)type->tp_alloc(type, 0);
3935
3936 self->modebuffer[0] = 0;
3937 self->modebuffer[1] = 0;
3938
3939 INIT_OBJECT_COMMON
3940 Stream_setFunctionPtr(self->stream, M_Tanh_compute_next_data_frame);
3941 self->mode_func_ptr = M_Tanh_setProcMode;
3942
3943 static char *kwlist[] = {"input", "mul", "add", NULL};
3944
3945 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
3946 Py_RETURN_NONE;
3947
3948 INIT_INPUT_STREAM
3949
3950 if (multmp)
3951 {
3952 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
3953 }
3954
3955 if (addtmp)
3956 {
3957 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
3958 }
3959
3960 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
3961
3962 (*self->mode_func_ptr)(self);
3963
3964 return (PyObject *)self;
3965 }
3966
3967 static PyObject * M_Tanh_getServer(M_Tanh* self) { GET_SERVER };
3968 static PyObject * M_Tanh_getStream(M_Tanh* self) { GET_STREAM };
3969 static PyObject * M_Tanh_setMul(M_Tanh *self, PyObject *arg) { SET_MUL };
3970 static PyObject * M_Tanh_setAdd(M_Tanh *self, PyObject *arg) { SET_ADD };
3971 static PyObject * M_Tanh_setSub(M_Tanh *self, PyObject *arg) { SET_SUB };
3972 static PyObject * M_Tanh_setDiv(M_Tanh *self, PyObject *arg) { SET_DIV };
3973
3974 static PyObject * M_Tanh_play(M_Tanh *self, PyObject *args, PyObject *kwds) { PLAY };
3975 static PyObject * M_Tanh_out(M_Tanh *self, PyObject *args, PyObject *kwds) { OUT };
3976 static PyObject * M_Tanh_stop(M_Tanh *self, PyObject *args, PyObject *kwds) { STOP };
3977
3978 static PyObject * M_Tanh_multiply(M_Tanh *self, PyObject *arg) { MULTIPLY };
3979 static PyObject * M_Tanh_inplace_multiply(M_Tanh *self, PyObject *arg) { INPLACE_MULTIPLY };
3980 static PyObject * M_Tanh_add(M_Tanh *self, PyObject *arg) { ADD };
3981 static PyObject * M_Tanh_inplace_add(M_Tanh *self, PyObject *arg) { INPLACE_ADD };
3982 static PyObject * M_Tanh_sub(M_Tanh *self, PyObject *arg) { SUB };
3983 static PyObject * M_Tanh_inplace_sub(M_Tanh *self, PyObject *arg) { INPLACE_SUB };
3984 static PyObject * M_Tanh_div(M_Tanh *self, PyObject *arg) { DIV };
3985 static PyObject * M_Tanh_inplace_div(M_Tanh *self, PyObject *arg) { INPLACE_DIV };
3986
3987 static PyMemberDef M_Tanh_members[] =
3988 {
3989 {"server", T_OBJECT_EX, offsetof(M_Tanh, server), 0, "Pyo server."},
3990 {"stream", T_OBJECT_EX, offsetof(M_Tanh, stream), 0, "Stream object."},
3991 {"input", T_OBJECT_EX, offsetof(M_Tanh, input), 0, "Input sound object."},
3992 {"mul", T_OBJECT_EX, offsetof(M_Tanh, mul), 0, "Mul factor."},
3993 {"add", T_OBJECT_EX, offsetof(M_Tanh, add), 0, "Add factor."},
3994 {NULL} /* Sentinel */
3995 };
3996
3997 static PyMethodDef M_Tanh_methods[] =
3998 {
3999 {"getServer", (PyCFunction)M_Tanh_getServer, METH_NOARGS, "Returns server object."},
4000 {"_getStream", (PyCFunction)M_Tanh_getStream, METH_NOARGS, "Returns stream object."},
4001 {"play", (PyCFunction)M_Tanh_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
4002 {"stop", (PyCFunction)M_Tanh_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
4003 {"out", (PyCFunction)M_Tanh_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
4004 {"setMul", (PyCFunction)M_Tanh_setMul, METH_O, "Sets oscillator mul factor."},
4005 {"setAdd", (PyCFunction)M_Tanh_setAdd, METH_O, "Sets oscillator add factor."},
4006 {"setSub", (PyCFunction)M_Tanh_setSub, METH_O, "Sets inverse add factor."},
4007 {"setDiv", (PyCFunction)M_Tanh_setDiv, METH_O, "Sets inverse mul factor."},
4008 {NULL} /* Sentinel */
4009 };
4010
4011 static PyNumberMethods M_Tanh_as_number =
4012 {
4013 (binaryfunc)M_Tanh_add, /*nb_add*/
4014 (binaryfunc)M_Tanh_sub, /*nb_subtract*/
4015 (binaryfunc)M_Tanh_multiply, /*nb_multiply*/
4016 0, /*nb_remainder*/
4017 0, /*nb_divmod*/
4018 0, /*nb_power*/
4019 0, /*nb_neg*/
4020 0, /*nb_pos*/
4021 0, /*(unaryfunc)array_abs,*/
4022 0, /*nb_nonzero*/
4023 0, /*nb_invert*/
4024 0, /*nb_lshift*/
4025 0, /*nb_rshift*/
4026 0, /*nb_and*/
4027 0, /*nb_xor*/
4028 0, /*nb_or*/
4029 0, /*nb_int*/
4030 0, /*nb_long*/
4031 0, /*nb_float*/
4032 (binaryfunc)M_Tanh_inplace_add, /*inplace_add*/
4033 (binaryfunc)M_Tanh_inplace_sub, /*inplace_subtract*/
4034 (binaryfunc)M_Tanh_inplace_multiply, /*inplace_multiply*/
4035 0, /*inplace_remainder*/
4036 0, /*inplace_power*/
4037 0, /*inplace_lshift*/
4038 0, /*inplace_rshift*/
4039 0, /*inplace_and*/
4040 0, /*inplace_xor*/
4041 0, /*inplace_or*/
4042 0, /*nb_floor_divide*/
4043 (binaryfunc)M_Tanh_div, /*nb_true_divide*/
4044 0, /*nb_inplace_floor_divide*/
4045 (binaryfunc)M_Tanh_inplace_div, /*nb_inplace_true_divide*/
4046 0, /* nb_index */
4047 };
4048
4049 PyTypeObject M_TanhType =
4050 {
4051 PyVarObject_HEAD_INIT(NULL, 0)
4052 "_pyo.M_Tanh_base", /*tp_name*/
4053 sizeof(M_Tanh), /*tp_basicsize*/
4054 0, /*tp_itemsize*/
4055 (destructor)M_Tanh_dealloc, /*tp_dealloc*/
4056 0, /*tp_print*/
4057 0, /*tp_getattr*/
4058 0, /*tp_setattr*/
4059 0, /*tp_as_async (tp_compare in Python 2)*/
4060 0, /*tp_repr*/
4061 &M_Tanh_as_number, /*tp_as_number*/
4062 0, /*tp_as_sequence*/
4063 0, /*tp_as_mapping*/
4064 0, /*tp_hash */
4065 0, /*tp_call*/
4066 0, /*tp_str*/
4067 0, /*tp_getattro*/
4068 0, /*tp_setattro*/
4069 0, /*tp_as_buffer*/
4070 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
4071 "M_Tanh objects. Performs tanh function on audio samples.", /* tp_doc */
4072 (traverseproc)M_Tanh_traverse, /* tp_traverse */
4073 (inquiry)M_Tanh_clear, /* tp_clear */
4074 0, /* tp_richcompare */
4075 0, /* tp_weaklistoffset */
4076 0, /* tp_iter */
4077 0, /* tp_iternext */
4078 M_Tanh_methods, /* tp_methods */
4079 M_Tanh_members, /* tp_members */
4080 0, /* tp_getset */
4081 0, /* tp_base */
4082 0, /* tp_dict */
4083 0, /* tp_descr_get */
4084 0, /* tp_descr_set */
4085 0, /* tp_dictoffset */
4086 0, /* tp_init */
4087 0, /* tp_alloc */
4088 M_Tanh_new, /* tp_new */
4089 };
4090
4091 /************/
4092 /* M_Exp */
4093 /************/
4094 typedef struct
4095 {
4096 pyo_audio_HEAD
4097 PyObject *input;
4098 Stream *input_stream;
4099 int modebuffer[2]; // need at least 2 slots for mul & add
4100 } M_Exp;
4101
4102 static void
4103 M_Exp_process(M_Exp *self)
4104 {
4105 int i;
4106 MYFLT *in = Stream_getData((Stream *)self->input_stream);
4107
4108 for (i = 0; i < self->bufsize; i++)
4109 {
4110 self->data[i] = MYEXP(in[i]);
4111 }
4112 }
4113
4114 static void M_Exp_postprocessing_ii(M_Exp *self) { POST_PROCESSING_II };
4115 static void M_Exp_postprocessing_ai(M_Exp *self) { POST_PROCESSING_AI };
4116 static void M_Exp_postprocessing_ia(M_Exp *self) { POST_PROCESSING_IA };
4117 static void M_Exp_postprocessing_aa(M_Exp *self) { POST_PROCESSING_AA };
4118 static void M_Exp_postprocessing_ireva(M_Exp *self) { POST_PROCESSING_IREVA };
4119 static void M_Exp_postprocessing_areva(M_Exp *self) { POST_PROCESSING_AREVA };
4120 static void M_Exp_postprocessing_revai(M_Exp *self) { POST_PROCESSING_REVAI };
4121 static void M_Exp_postprocessing_revaa(M_Exp *self) { POST_PROCESSING_REVAA };
4122 static void M_Exp_postprocessing_revareva(M_Exp *self) { POST_PROCESSING_REVAREVA };
4123
4124 static void
4125 M_Exp_setProcMode(M_Exp *self)
4126 {
4127 int muladdmode;
4128 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
4129
4130 self->proc_func_ptr = M_Exp_process;
4131
4132 switch (muladdmode)
4133 {
4134 case 0:
4135 self->muladd_func_ptr = M_Exp_postprocessing_ii;
4136 break;
4137
4138 case 1:
4139 self->muladd_func_ptr = M_Exp_postprocessing_ai;
4140 break;
4141
4142 case 2:
4143 self->muladd_func_ptr = M_Exp_postprocessing_revai;
4144 break;
4145
4146 case 10:
4147 self->muladd_func_ptr = M_Exp_postprocessing_ia;
4148 break;
4149
4150 case 11:
4151 self->muladd_func_ptr = M_Exp_postprocessing_aa;
4152 break;
4153
4154 case 12:
4155 self->muladd_func_ptr = M_Exp_postprocessing_revaa;
4156 break;
4157
4158 case 20:
4159 self->muladd_func_ptr = M_Exp_postprocessing_ireva;
4160 break;
4161
4162 case 21:
4163 self->muladd_func_ptr = M_Exp_postprocessing_areva;
4164 break;
4165
4166 case 22:
4167 self->muladd_func_ptr = M_Exp_postprocessing_revareva;
4168 break;
4169 }
4170 }
4171
4172 static void
4173 M_Exp_compute_next_data_frame(M_Exp *self)
4174 {
4175 (*self->proc_func_ptr)(self);
4176 (*self->muladd_func_ptr)(self);
4177 }
4178
4179 static int
4180 M_Exp_traverse(M_Exp *self, visitproc visit, void *arg)
4181 {
4182 pyo_VISIT
4183 Py_VISIT(self->input);
4184 return 0;
4185 }
4186
4187 static int
4188 M_Exp_clear(M_Exp *self)
4189 {
4190 pyo_CLEAR
4191 Py_CLEAR(self->input);
4192 return 0;
4193 }
4194
4195 static void
4196 M_Exp_dealloc(M_Exp* self)
4197 {
4198 pyo_DEALLOC
4199 M_Exp_clear(self);
4200 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
4201 Py_TYPE(self)->tp_free((PyObject*)self);
4202 }
4203
4204 static PyObject *
4205 M_Exp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4206 {
4207 int i;
4208 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
4209 M_Exp *self;
4210 self = (M_Exp *)type->tp_alloc(type, 0);
4211
4212 self->modebuffer[0] = 0;
4213 self->modebuffer[1] = 0;
4214
4215 INIT_OBJECT_COMMON
4216 Stream_setFunctionPtr(self->stream, M_Exp_compute_next_data_frame);
4217 self->mode_func_ptr = M_Exp_setProcMode;
4218
4219 static char *kwlist[] = {"input", "mul", "add", NULL};
4220
4221 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
4222 Py_RETURN_NONE;
4223
4224 INIT_INPUT_STREAM
4225
4226 if (multmp)
4227 {
4228 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
4229 }
4230
4231 if (addtmp)
4232 {
4233 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
4234 }
4235
4236 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
4237
4238 (*self->mode_func_ptr)(self);
4239
4240 return (PyObject *)self;
4241 }
4242
4243 static PyObject * M_Exp_getServer(M_Exp* self) { GET_SERVER };
4244 static PyObject * M_Exp_getStream(M_Exp* self) { GET_STREAM };
4245 static PyObject * M_Exp_setMul(M_Exp *self, PyObject *arg) { SET_MUL };
4246 static PyObject * M_Exp_setAdd(M_Exp *self, PyObject *arg) { SET_ADD };
4247 static PyObject * M_Exp_setSub(M_Exp *self, PyObject *arg) { SET_SUB };
4248 static PyObject * M_Exp_setDiv(M_Exp *self, PyObject *arg) { SET_DIV };
4249
4250 static PyObject * M_Exp_play(M_Exp *self, PyObject *args, PyObject *kwds) { PLAY };
4251 static PyObject * M_Exp_out(M_Exp *self, PyObject *args, PyObject *kwds) { OUT };
4252 static PyObject * M_Exp_stop(M_Exp *self, PyObject *args, PyObject *kwds) { STOP };
4253
4254 static PyObject * M_Exp_multiply(M_Exp *self, PyObject *arg) { MULTIPLY };
4255 static PyObject * M_Exp_inplace_multiply(M_Exp *self, PyObject *arg) { INPLACE_MULTIPLY };
4256 static PyObject * M_Exp_add(M_Exp *self, PyObject *arg) { ADD };
4257 static PyObject * M_Exp_inplace_add(M_Exp *self, PyObject *arg) { INPLACE_ADD };
4258 static PyObject * M_Exp_sub(M_Exp *self, PyObject *arg) { SUB };
4259 static PyObject * M_Exp_inplace_sub(M_Exp *self, PyObject *arg) { INPLACE_SUB };
4260 static PyObject * M_Exp_div(M_Exp *self, PyObject *arg) { DIV };
4261 static PyObject * M_Exp_inplace_div(M_Exp *self, PyObject *arg) { INPLACE_DIV };
4262
4263 static PyMemberDef M_Exp_members[] =
4264 {
4265 {"server", T_OBJECT_EX, offsetof(M_Exp, server), 0, "Pyo server."},
4266 {"stream", T_OBJECT_EX, offsetof(M_Exp, stream), 0, "Stream object."},
4267 {"input", T_OBJECT_EX, offsetof(M_Exp, input), 0, "Input sound object."},
4268 {"mul", T_OBJECT_EX, offsetof(M_Exp, mul), 0, "Mul factor."},
4269 {"add", T_OBJECT_EX, offsetof(M_Exp, add), 0, "Add factor."},
4270 {NULL} /* Sentinel */
4271 };
4272
4273 static PyMethodDef M_Exp_methods[] =
4274 {
4275 {"getServer", (PyCFunction)M_Exp_getServer, METH_NOARGS, "Returns server object."},
4276 {"_getStream", (PyCFunction)M_Exp_getStream, METH_NOARGS, "Returns stream object."},
4277 {"play", (PyCFunction)M_Exp_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
4278 {"stop", (PyCFunction)M_Exp_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
4279 {"out", (PyCFunction)M_Exp_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
4280 {"setMul", (PyCFunction)M_Exp_setMul, METH_O, "Sets oscillator mul factor."},
4281 {"setAdd", (PyCFunction)M_Exp_setAdd, METH_O, "Sets oscillator add factor."},
4282 {"setSub", (PyCFunction)M_Exp_setSub, METH_O, "Sets inverse add factor."},
4283 {"setDiv", (PyCFunction)M_Exp_setDiv, METH_O, "Sets inverse mul factor."},
4284 {NULL} /* Sentinel */
4285 };
4286
4287 static PyNumberMethods M_Exp_as_number =
4288 {
4289 (binaryfunc)M_Exp_add, /*nb_add*/
4290 (binaryfunc)M_Exp_sub, /*nb_subtract*/
4291 (binaryfunc)M_Exp_multiply, /*nb_multiply*/
4292 0, /*nb_remainder*/
4293 0, /*nb_divmod*/
4294 0, /*nb_power*/
4295 0, /*nb_neg*/
4296 0, /*nb_pos*/
4297 0, /*(unaryfunc)array_abs,*/
4298 0, /*nb_nonzero*/
4299 0, /*nb_invert*/
4300 0, /*nb_lshift*/
4301 0, /*nb_rshift*/
4302 0, /*nb_and*/
4303 0, /*nb_xor*/
4304 0, /*nb_or*/
4305 0, /*nb_int*/
4306 0, /*nb_long*/
4307 0, /*nb_float*/
4308 (binaryfunc)M_Exp_inplace_add, /*inplace_add*/
4309 (binaryfunc)M_Exp_inplace_sub, /*inplace_subtract*/
4310 (binaryfunc)M_Exp_inplace_multiply, /*inplace_multiply*/
4311 0, /*inplace_remainder*/
4312 0, /*inplace_power*/
4313 0, /*inplace_lshift*/
4314 0, /*inplace_rshift*/
4315 0, /*inplace_and*/
4316 0, /*inplace_xor*/
4317 0, /*inplace_or*/
4318 0, /*nb_floor_divide*/
4319 (binaryfunc)M_Exp_div, /*nb_true_divide*/
4320 0, /*nb_inplace_floor_divide*/
4321 (binaryfunc)M_Exp_inplace_div, /*nb_inplace_true_divide*/
4322 0, /* nb_index */
4323 };
4324
4325 PyTypeObject M_ExpType =
4326 {
4327 PyVarObject_HEAD_INIT(NULL, 0)
4328 "_pyo.M_Exp_base", /*tp_name*/
4329 sizeof(M_Exp), /*tp_basicsize*/
4330 0, /*tp_itemsize*/
4331 (destructor)M_Exp_dealloc, /*tp_dealloc*/
4332 0, /*tp_print*/
4333 0, /*tp_getattr*/
4334 0, /*tp_setattr*/
4335 0, /*tp_as_async (tp_compare in Python 2)*/
4336 0, /*tp_repr*/
4337 &M_Exp_as_number, /*tp_as_number*/
4338 0, /*tp_as_sequence*/
4339 0, /*tp_as_mapping*/
4340 0, /*tp_hash */
4341 0, /*tp_call*/
4342 0, /*tp_str*/
4343 0, /*tp_getattro*/
4344 0, /*tp_setattro*/
4345 0, /*tp_as_buffer*/
4346 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
4347 "M_Exp objects. Performs exp function on audio samples.", /* tp_doc */
4348 (traverseproc)M_Exp_traverse, /* tp_traverse */
4349 (inquiry)M_Exp_clear, /* tp_clear */
4350 0, /* tp_richcompare */
4351 0, /* tp_weaklistoffset */
4352 0, /* tp_iter */
4353 0, /* tp_iternext */
4354 M_Exp_methods, /* tp_methods */
4355 M_Exp_members, /* tp_members */
4356 0, /* tp_getset */
4357 0, /* tp_base */
4358 0, /* tp_dict */
4359 0, /* tp_descr_get */
4360 0, /* tp_descr_set */
4361 0, /* tp_dictoffset */
4362 0, /* tp_init */
4363 0, /* tp_alloc */
4364 M_Exp_new, /* tp_new */
4365 };
4366
4367 /**************/
4368 /* M_Div object */
4369 /**************/
4370 typedef struct
4371 {
4372 pyo_audio_HEAD
4373 PyObject *a;
4374 Stream *a_stream;
4375 PyObject *b;
4376 Stream *b_stream;
4377 int modebuffer[4];
4378 } M_Div;
4379
4380 static void
4381 M_Div_readframes_ii(M_Div *self)
4382 {
4383 int i;
4384
4385 MYFLT a = PyFloat_AS_DOUBLE(self->a);
4386 MYFLT b = PyFloat_AS_DOUBLE(self->b);
4387
4388 if (b < 0.0000000001 && b > -0.0000000001)
4389 {
4390 b = 0.0000000001;
4391 }
4392
4393 for (i = 0; i < self->bufsize; i++)
4394 {
4395 self->data[i] = a / b;
4396 }
4397 }
4398
4399 static void
4400 M_Div_readframes_ai(M_Div *self)
4401 {
4402 int i;
4403
4404 MYFLT *a = Stream_getData((Stream *)self->a_stream);
4405 MYFLT b = PyFloat_AS_DOUBLE(self->b);
4406
4407 if (b < 0.0000000001 && b > -0.0000000001)
4408 {
4409 b = 0.0000000001;
4410 }
4411
4412 for (i = 0; i < self->bufsize; i++)
4413 {
4414 self->data[i] = a[i] / b;
4415 }
4416 }
4417
4418 static void
4419 M_Div_readframes_ia(M_Div *self)
4420 {
4421 int i;
4422 MYFLT b;
4423
4424 MYFLT a = PyFloat_AS_DOUBLE(self->a);
4425 MYFLT *bs = Stream_getData((Stream *)self->b_stream);
4426
4427 for (i = 0; i < self->bufsize; i++)
4428 {
4429 b = bs[i];
4430
4431 if (b < 0.0000000001 && b > -0.0000000001)
4432 {
4433 b = 0.0000000001;
4434 }
4435
4436 self->data[i] = a / b;
4437 }
4438 }
4439
4440 static void
4441 M_Div_readframes_aa(M_Div *self)
4442 {
4443 int i;
4444 MYFLT a, b;
4445
4446 MYFLT *as = Stream_getData((Stream *)self->a_stream);
4447 MYFLT *bs = Stream_getData((Stream *)self->b_stream);
4448
4449 for (i = 0; i < self->bufsize; i++)
4450 {
4451 a = as[i];
4452 b = bs[i];
4453
4454 if (b < 0.0000000001 && b > -0.0000000001)
4455 {
4456 b = 0.0000000001;
4457 }
4458
4459 self->data[i] = a / b;
4460 }
4461 }
4462
4463 static void M_Div_postprocessing_ii(M_Div *self) { POST_PROCESSING_II };
4464 static void M_Div_postprocessing_ai(M_Div *self) { POST_PROCESSING_AI };
4465 static void M_Div_postprocessing_ia(M_Div *self) { POST_PROCESSING_IA };
4466 static void M_Div_postprocessing_aa(M_Div *self) { POST_PROCESSING_AA };
4467 static void M_Div_postprocessing_ireva(M_Div *self) { POST_PROCESSING_IREVA };
4468 static void M_Div_postprocessing_areva(M_Div *self) { POST_PROCESSING_AREVA };
4469 static void M_Div_postprocessing_revai(M_Div *self) { POST_PROCESSING_REVAI };
4470 static void M_Div_postprocessing_revaa(M_Div *self) { POST_PROCESSING_REVAA };
4471 static void M_Div_postprocessing_revareva(M_Div *self) { POST_PROCESSING_REVAREVA };
4472
4473 static void
4474 M_Div_setProcMode(M_Div *self)
4475 {
4476 int procmode, muladdmode;
4477 procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
4478 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
4479
4480 switch (procmode)
4481 {
4482 case 0:
4483 self->proc_func_ptr = M_Div_readframes_ii;
4484 break;
4485
4486 case 1:
4487 self->proc_func_ptr = M_Div_readframes_ai;
4488 break;
4489
4490 case 10:
4491 self->proc_func_ptr = M_Div_readframes_ia;
4492 break;
4493
4494 case 11:
4495 self->proc_func_ptr = M_Div_readframes_aa;
4496 break;
4497 }
4498
4499 switch (muladdmode)
4500 {
4501 case 0:
4502 self->muladd_func_ptr = M_Div_postprocessing_ii;
4503 break;
4504
4505 case 1:
4506 self->muladd_func_ptr = M_Div_postprocessing_ai;
4507 break;
4508
4509 case 2:
4510 self->muladd_func_ptr = M_Div_postprocessing_revai;
4511 break;
4512
4513 case 10:
4514 self->muladd_func_ptr = M_Div_postprocessing_ia;
4515 break;
4516
4517 case 11:
4518 self->muladd_func_ptr = M_Div_postprocessing_aa;
4519 break;
4520
4521 case 12:
4522 self->muladd_func_ptr = M_Div_postprocessing_revaa;
4523 break;
4524
4525 case 20:
4526 self->muladd_func_ptr = M_Div_postprocessing_ireva;
4527 break;
4528
4529 case 21:
4530 self->muladd_func_ptr = M_Div_postprocessing_areva;
4531 break;
4532
4533 case 22:
4534 self->muladd_func_ptr = M_Div_postprocessing_revareva;
4535 break;
4536 }
4537 }
4538
4539 static void
4540 M_Div_compute_next_data_frame(M_Div *self)
4541 {
4542 (*self->proc_func_ptr)(self);
4543 (*self->muladd_func_ptr)(self);
4544 }
4545
4546 static int
4547 M_Div_traverse(M_Div *self, visitproc visit, void *arg)
4548 {
4549 pyo_VISIT
4550 Py_VISIT(self->a);
4551 Py_VISIT(self->b);
4552 return 0;
4553 }
4554
4555 static int
4556 M_Div_clear(M_Div *self)
4557 {
4558 pyo_CLEAR
4559 Py_CLEAR(self->a);
4560 Py_CLEAR(self->b);
4561 return 0;
4562 }
4563
4564 static void
4565 M_Div_dealloc(M_Div* self)
4566 {
4567 pyo_DEALLOC
4568 M_Div_clear(self);
4569 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
4570 Py_TYPE(self)->tp_free((PyObject*)self);
4571 }
4572
4573 static PyObject *
4574 M_Div_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4575 {
4576 int i;
4577 PyObject *atmp = NULL, *btmp = NULL, *multmp = NULL, *addtmp = NULL;
4578 M_Div *self;
4579 self = (M_Div *)type->tp_alloc(type, 0);
4580
4581 self->a = PyFloat_FromDouble(1);
4582 self->b = PyFloat_FromDouble(1);
4583 self->modebuffer[0] = 0;
4584 self->modebuffer[1] = 0;
4585 self->modebuffer[2] = 0;
4586 self->modebuffer[3] = 0;
4587
4588 INIT_OBJECT_COMMON
4589 Stream_setFunctionPtr(self->stream, M_Div_compute_next_data_frame);
4590 self->mode_func_ptr = M_Div_setProcMode;
4591
4592 static char *kwlist[] = {"a", "b", "mul", "add", NULL};
4593
4594 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", kwlist, &atmp, &btmp, &multmp, &addtmp))
4595 Py_RETURN_NONE;
4596
4597 if (atmp)
4598 {
4599 PyObject_CallMethod((PyObject *)self, "setA", "O", atmp);
4600 }
4601
4602 if (btmp)
4603 {
4604 PyObject_CallMethod((PyObject *)self, "setB", "O", btmp);
4605 }
4606
4607 if (multmp)
4608 {
4609 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
4610 }
4611
4612 if (addtmp)
4613 {
4614 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
4615 }
4616
4617 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
4618
4619 (*self->mode_func_ptr)(self);
4620
4621 return (PyObject *)self;
4622 }
4623
4624 static PyObject * M_Div_getServer(M_Div* self) { GET_SERVER };
4625 static PyObject * M_Div_getStream(M_Div* self) { GET_STREAM };
4626 static PyObject * M_Div_setMul(M_Div *self, PyObject *arg) { SET_MUL };
4627 static PyObject * M_Div_setAdd(M_Div *self, PyObject *arg) { SET_ADD };
4628 static PyObject * M_Div_setSub(M_Div *self, PyObject *arg) { SET_SUB };
4629 static PyObject * M_Div_setDiv(M_Div *self, PyObject *arg) { SET_DIV };
4630
4631 static PyObject * M_Div_play(M_Div *self, PyObject *args, PyObject *kwds) { PLAY };
4632 static PyObject * M_Div_out(M_Div *self, PyObject *args, PyObject *kwds) { OUT };
4633 static PyObject * M_Div_stop(M_Div *self, PyObject *args, PyObject *kwds) { STOP };
4634
4635 static PyObject * M_Div_multiply(M_Div *self, PyObject *arg) { MULTIPLY };
4636 static PyObject * M_Div_inplace_multiply(M_Div *self, PyObject *arg) { INPLACE_MULTIPLY };
4637 static PyObject * M_Div_add(M_Div *self, PyObject *arg) { ADD };
4638 static PyObject * M_Div_inplace_add(M_Div *self, PyObject *arg) { INPLACE_ADD };
4639 static PyObject * M_Div_sub(M_Div *self, PyObject *arg) { SUB };
4640 static PyObject * M_Div_inplace_sub(M_Div *self, PyObject *arg) { INPLACE_SUB };
4641 static PyObject * M_Div_div(M_Div *self, PyObject *arg) { DIV };
4642 static PyObject * M_Div_inplace_div(M_Div *self, PyObject *arg) { INPLACE_DIV };
4643
4644 static PyObject * M_Div_setA(M_Div *self, PyObject *arg) { SET_PARAM(self->a, self->a_stream, 2); }
4645 static PyObject * M_Div_setB(M_Div *self, PyObject *arg) { SET_PARAM(self->b, self->b_stream, 3); }
4646
4647 static PyMemberDef M_Div_members[] =
4648 {
4649 {"server", T_OBJECT_EX, offsetof(M_Div, server), 0, "Pyo server."},
4650 {"stream", T_OBJECT_EX, offsetof(M_Div, stream), 0, "Stream object."},
4651 {"a", T_OBJECT_EX, offsetof(M_Div, a), 0, "a composant."},
4652 {"b", T_OBJECT_EX, offsetof(M_Div, b), 0, "b composant."},
4653 {"mul", T_OBJECT_EX, offsetof(M_Div, mul), 0, "Mul factor."},
4654 {"add", T_OBJECT_EX, offsetof(M_Div, add), 0, "Add factor."},
4655 {NULL} /* Sentinel */
4656 };
4657
4658 static PyMethodDef M_Div_methods[] =
4659 {
4660 {"getServer", (PyCFunction)M_Div_getServer, METH_NOARGS, "Returns server object."},
4661 {"_getStream", (PyCFunction)M_Div_getStream, METH_NOARGS, "Returns stream object."},
4662 {"play", (PyCFunction)M_Div_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
4663 {"out", (PyCFunction)M_Div_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
4664 {"stop", (PyCFunction)M_Div_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
4665 {"setA", (PyCFunction)M_Div_setA, METH_O, "Sets a."},
4666 {"setB", (PyCFunction)M_Div_setB, METH_O, "Sets b."},
4667 {"setMul", (PyCFunction)M_Div_setMul, METH_O, "Sets mul factor."},
4668 {"setAdd", (PyCFunction)M_Div_setAdd, METH_O, "Sets add factor."},
4669 {"setSub", (PyCFunction)M_Div_setSub, METH_O, "Sets inverse add factor."},
4670 {"setDiv", (PyCFunction)M_Div_setDiv, METH_O, "Sets inverse mul factor."},
4671 {NULL} /* Sentinel */
4672 };
4673
4674 static PyNumberMethods M_Div_as_number =
4675 {
4676 (binaryfunc)M_Div_add, /*nb_add*/
4677 (binaryfunc)M_Div_sub, /*nb_subtract*/
4678 (binaryfunc)M_Div_multiply, /*nb_multiply*/
4679 0, /*nb_remainder*/
4680 0, /*nb_divmod*/
4681 0, /*nb_power*/
4682 0, /*nb_neg*/
4683 0, /*nb_pos*/
4684 0, /*(unaryfunc)array_abs,*/
4685 0, /*nb_nonzero*/
4686 0, /*nb_invert*/
4687 0, /*nb_lshift*/
4688 0, /*nb_rshift*/
4689 0, /*nb_and*/
4690 0, /*nb_xor*/
4691 0, /*nb_or*/
4692 0, /*nb_int*/
4693 0, /*nb_long*/
4694 0, /*nb_float*/
4695 (binaryfunc)M_Div_inplace_add, /*inplace_add*/
4696 (binaryfunc)M_Div_inplace_sub, /*inplace_subtract*/
4697 (binaryfunc)M_Div_inplace_multiply, /*inplace_multiply*/
4698 0, /*inplace_remainder*/
4699 0, /*inplace_power*/
4700 0, /*inplace_lshift*/
4701 0, /*inplace_rshift*/
4702 0, /*inplace_and*/
4703 0, /*inplace_xor*/
4704 0, /*inplace_or*/
4705 0, /*nb_floor_divide*/
4706 (binaryfunc)M_Div_div, /*nb_true_divide*/
4707 0, /*nb_inplace_floor_divide*/
4708 (binaryfunc)M_Div_inplace_div, /*nb_inplace_true_divide*/
4709 0, /* nb_index */
4710 };
4711
4712 PyTypeObject M_DivType =
4713 {
4714 PyVarObject_HEAD_INIT(NULL, 0)
4715 "_pyo.M_Div_base", /*tp_name*/
4716 sizeof(M_Div), /*tp_basicsize*/
4717 0, /*tp_itemsize*/
4718 (destructor)M_Div_dealloc, /*tp_dealloc*/
4719 0, /*tp_print*/
4720 0, /*tp_getattr*/
4721 0, /*tp_setattr*/
4722 0, /*tp_as_async (tp_compare in Python 2)*/
4723 0, /*tp_repr*/
4724 &M_Div_as_number, /*tp_as_number*/
4725 0, /*tp_as_sequence*/
4726 0, /*tp_as_mapping*/
4727 0, /*tp_hash */
4728 0, /*tp_call*/
4729 0, /*tp_str*/
4730 0, /*tp_getattro*/
4731 0, /*tp_setattro*/
4732 0, /*tp_as_buffer*/
4733 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
4734 "M_Div objects. Divide function.", /* tp_doc */
4735 (traverseproc)M_Div_traverse, /* tp_traverse */
4736 (inquiry)M_Div_clear, /* tp_clear */
4737 0, /* tp_richcompare */
4738 0, /* tp_weaklistoffset */
4739 0, /* tp_iter */
4740 0, /* tp_iternext */
4741 M_Div_methods, /* tp_methods */
4742 M_Div_members, /* tp_members */
4743 0, /* tp_getset */
4744 0, /* tp_base */
4745 0, /* tp_dict */
4746 0, /* tp_descr_get */
4747 0, /* tp_descr_set */
4748 0, /* tp_dictoffset */
4749 0, /* tp_init */
4750 0, /* tp_alloc */
4751 M_Div_new, /* tp_new */
4752 };
4753
4754 /**************/
4755 /* M_Sub object */
4756 /**************/
4757 typedef struct
4758 {
4759 pyo_audio_HEAD
4760 PyObject *a;
4761 Stream *a_stream;
4762 PyObject *b;
4763 Stream *b_stream;
4764 int modebuffer[4];
4765 } M_Sub;
4766
4767 static void
4768 M_Sub_readframes_ii(M_Sub *self)
4769 {
4770 int i;
4771
4772 MYFLT a = PyFloat_AS_DOUBLE(self->a);
4773 MYFLT b = PyFloat_AS_DOUBLE(self->b);
4774
4775 for (i = 0; i < self->bufsize; i++)
4776 {
4777 self->data[i] = a - b;
4778 }
4779 }
4780
4781 static void
4782 M_Sub_readframes_ai(M_Sub *self)
4783 {
4784 int i;
4785
4786 MYFLT *a = Stream_getData((Stream *)self->a_stream);
4787 MYFLT b = PyFloat_AS_DOUBLE(self->b);
4788
4789 for (i = 0; i < self->bufsize; i++)
4790 {
4791 self->data[i] = a[i] - b;
4792 }
4793 }
4794
4795 static void
4796 M_Sub_readframes_ia(M_Sub *self)
4797 {
4798 int i;
4799
4800 MYFLT a = PyFloat_AS_DOUBLE(self->a);
4801 MYFLT *b = Stream_getData((Stream *)self->b_stream);
4802
4803 for (i = 0; i < self->bufsize; i++)
4804 {
4805 self->data[i] = a - b[i];
4806 }
4807 }
4808
4809 static void
4810 M_Sub_readframes_aa(M_Sub *self)
4811 {
4812 int i;
4813
4814 MYFLT *a = Stream_getData((Stream *)self->a_stream);
4815 MYFLT *b = Stream_getData((Stream *)self->b_stream);
4816
4817 for (i = 0; i < self->bufsize; i++)
4818 {
4819 self->data[i] = a[i] - b[i];
4820 }
4821 }
4822
4823 static void M_Sub_postprocessing_ii(M_Sub *self) { POST_PROCESSING_II };
4824 static void M_Sub_postprocessing_ai(M_Sub *self) { POST_PROCESSING_AI };
4825 static void M_Sub_postprocessing_ia(M_Sub *self) { POST_PROCESSING_IA };
4826 static void M_Sub_postprocessing_aa(M_Sub *self) { POST_PROCESSING_AA };
4827 static void M_Sub_postprocessing_ireva(M_Sub *self) { POST_PROCESSING_IREVA };
4828 static void M_Sub_postprocessing_areva(M_Sub *self) { POST_PROCESSING_AREVA };
4829 static void M_Sub_postprocessing_revai(M_Sub *self) { POST_PROCESSING_REVAI };
4830 static void M_Sub_postprocessing_revaa(M_Sub *self) { POST_PROCESSING_REVAA };
4831 static void M_Sub_postprocessing_revareva(M_Sub *self) { POST_PROCESSING_REVAREVA };
4832
4833 static void
4834 M_Sub_setProcMode(M_Sub *self)
4835 {
4836 int procmode, muladdmode;
4837 procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
4838 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
4839
4840 switch (procmode)
4841 {
4842 case 0:
4843 self->proc_func_ptr = M_Sub_readframes_ii;
4844 break;
4845
4846 case 1:
4847 self->proc_func_ptr = M_Sub_readframes_ai;
4848 break;
4849
4850 case 10:
4851 self->proc_func_ptr = M_Sub_readframes_ia;
4852 break;
4853
4854 case 11:
4855 self->proc_func_ptr = M_Sub_readframes_aa;
4856 break;
4857 }
4858
4859 switch (muladdmode)
4860 {
4861 case 0:
4862 self->muladd_func_ptr = M_Sub_postprocessing_ii;
4863 break;
4864
4865 case 1:
4866 self->muladd_func_ptr = M_Sub_postprocessing_ai;
4867 break;
4868
4869 case 2:
4870 self->muladd_func_ptr = M_Sub_postprocessing_revai;
4871 break;
4872
4873 case 10:
4874 self->muladd_func_ptr = M_Sub_postprocessing_ia;
4875 break;
4876
4877 case 11:
4878 self->muladd_func_ptr = M_Sub_postprocessing_aa;
4879 break;
4880
4881 case 12:
4882 self->muladd_func_ptr = M_Sub_postprocessing_revaa;
4883 break;
4884
4885 case 20:
4886 self->muladd_func_ptr = M_Sub_postprocessing_ireva;
4887 break;
4888
4889 case 21:
4890 self->muladd_func_ptr = M_Sub_postprocessing_areva;
4891 break;
4892
4893 case 22:
4894 self->muladd_func_ptr = M_Sub_postprocessing_revareva;
4895 break;
4896 }
4897 }
4898
4899 static void
4900 M_Sub_compute_next_data_frame(M_Sub *self)
4901 {
4902 (*self->proc_func_ptr)(self);
4903 (*self->muladd_func_ptr)(self);
4904 }
4905
4906 static int
4907 M_Sub_traverse(M_Sub *self, visitproc visit, void *arg)
4908 {
4909 pyo_VISIT
4910 Py_VISIT(self->a);
4911 Py_VISIT(self->b);
4912 return 0;
4913 }
4914
4915 static int
4916 M_Sub_clear(M_Sub *self)
4917 {
4918 pyo_CLEAR
4919 Py_CLEAR(self->a);
4920 Py_CLEAR(self->b);
4921 return 0;
4922 }
4923
4924 static void
4925 M_Sub_dealloc(M_Sub* self)
4926 {
4927 pyo_DEALLOC
4928 M_Sub_clear(self);
4929 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
4930 Py_TYPE(self)->tp_free((PyObject*)self);
4931 }
4932
4933 static PyObject *
4934 M_Sub_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4935 {
4936 int i;
4937 PyObject *atmp = NULL, *btmp = NULL, *multmp = NULL, *addtmp = NULL;
4938 M_Sub *self;
4939 self = (M_Sub *)type->tp_alloc(type, 0);
4940
4941 self->a = PyFloat_FromDouble(1);
4942 self->b = PyFloat_FromDouble(1);
4943 self->modebuffer[0] = 0;
4944 self->modebuffer[1] = 0;
4945 self->modebuffer[2] = 0;
4946 self->modebuffer[3] = 0;
4947
4948 INIT_OBJECT_COMMON
4949 Stream_setFunctionPtr(self->stream, M_Sub_compute_next_data_frame);
4950 self->mode_func_ptr = M_Sub_setProcMode;
4951
4952 static char *kwlist[] = {"a", "b", "mul", "add", NULL};
4953
4954 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", kwlist, &atmp, &btmp, &multmp, &addtmp))
4955 Py_RETURN_NONE;
4956
4957 if (atmp)
4958 {
4959 PyObject_CallMethod((PyObject *)self, "setA", "O", atmp);
4960 }
4961
4962 if (btmp)
4963 {
4964 PyObject_CallMethod((PyObject *)self, "setB", "O", btmp);
4965 }
4966
4967 if (multmp)
4968 {
4969 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
4970 }
4971
4972 if (addtmp)
4973 {
4974 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
4975 }
4976
4977 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
4978
4979 (*self->mode_func_ptr)(self);
4980
4981 return (PyObject *)self;
4982 }
4983
4984 static PyObject * M_Sub_getServer(M_Sub* self) { GET_SERVER };
4985 static PyObject * M_Sub_getStream(M_Sub* self) { GET_STREAM };
4986 static PyObject * M_Sub_setMul(M_Sub *self, PyObject *arg) { SET_MUL };
4987 static PyObject * M_Sub_setAdd(M_Sub *self, PyObject *arg) { SET_ADD };
4988 static PyObject * M_Sub_setSub(M_Sub *self, PyObject *arg) { SET_SUB };
4989 static PyObject * M_Sub_setDiv(M_Sub *self, PyObject *arg) { SET_DIV };
4990
4991 static PyObject * M_Sub_play(M_Sub *self, PyObject *args, PyObject *kwds) { PLAY };
4992 static PyObject * M_Sub_out(M_Sub *self, PyObject *args, PyObject *kwds) { OUT };
4993 static PyObject * M_Sub_stop(M_Sub *self, PyObject *args, PyObject *kwds) { STOP };
4994
4995 static PyObject * M_Sub_multiply(M_Sub *self, PyObject *arg) { MULTIPLY };
4996 static PyObject * M_Sub_inplace_multiply(M_Sub *self, PyObject *arg) { INPLACE_MULTIPLY };
4997 static PyObject * M_Sub_add(M_Sub *self, PyObject *arg) { ADD };
4998 static PyObject * M_Sub_inplace_add(M_Sub *self, PyObject *arg) { INPLACE_ADD };
4999 static PyObject * M_Sub_sub(M_Sub *self, PyObject *arg) { SUB };
5000 static PyObject * M_Sub_inplace_sub(M_Sub *self, PyObject *arg) { INPLACE_SUB };
5001 static PyObject * M_Sub_div(M_Sub *self, PyObject *arg) { DIV };
5002 static PyObject * M_Sub_inplace_div(M_Sub *self, PyObject *arg) { INPLACE_DIV };
5003
5004 static PyObject * M_Sub_setA(M_Sub *self, PyObject *arg) { SET_PARAM(self->a, self->a_stream, 2); }
5005 static PyObject * M_Sub_setB(M_Sub *self, PyObject *arg) { SET_PARAM(self->b, self->b_stream, 3); }
5006
5007 static PyMemberDef M_Sub_members[] =
5008 {
5009 {"server", T_OBJECT_EX, offsetof(M_Sub, server), 0, "Pyo server."},
5010 {"stream", T_OBJECT_EX, offsetof(M_Sub, stream), 0, "Stream object."},
5011 {"a", T_OBJECT_EX, offsetof(M_Sub, a), 0, "a composant."},
5012 {"b", T_OBJECT_EX, offsetof(M_Sub, b), 0, "b composant."},
5013 {"mul", T_OBJECT_EX, offsetof(M_Sub, mul), 0, "Mul factor."},
5014 {"add", T_OBJECT_EX, offsetof(M_Sub, add), 0, "Add factor."},
5015 {NULL} /* Sentinel */
5016 };
5017
5018 static PyMethodDef M_Sub_methods[] =
5019 {
5020 {"getServer", (PyCFunction)M_Sub_getServer, METH_NOARGS, "Returns server object."},
5021 {"_getStream", (PyCFunction)M_Sub_getStream, METH_NOARGS, "Returns stream object."},
5022 {"play", (PyCFunction)M_Sub_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
5023 {"out", (PyCFunction)M_Sub_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
5024 {"stop", (PyCFunction)M_Sub_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
5025 {"setA", (PyCFunction)M_Sub_setA, METH_O, "Sets a."},
5026 {"setB", (PyCFunction)M_Sub_setB, METH_O, "Sets b."},
5027 {"setMul", (PyCFunction)M_Sub_setMul, METH_O, "Sets mul factor."},
5028 {"setAdd", (PyCFunction)M_Sub_setAdd, METH_O, "Sets add factor."},
5029 {"setSub", (PyCFunction)M_Sub_setSub, METH_O, "Sets inverse add factor."},
5030 {"setDiv", (PyCFunction)M_Sub_setDiv, METH_O, "Sets inverse mul factor."},
5031 {NULL} /* Sentinel */
5032 };
5033
5034 static PyNumberMethods M_Sub_as_number =
5035 {
5036 (binaryfunc)M_Sub_add, /*nb_add*/
5037 (binaryfunc)M_Sub_sub, /*nb_subtract*/
5038 (binaryfunc)M_Sub_multiply, /*nb_multiply*/
5039 0, /*nb_remainder*/
5040 0, /*nb_divmod*/
5041 0, /*nb_power*/
5042 0, /*nb_neg*/
5043 0, /*nb_pos*/
5044 0, /*(unaryfunc)array_abs,*/
5045 0, /*nb_nonzero*/
5046 0, /*nb_invert*/
5047 0, /*nb_lshift*/
5048 0, /*nb_rshift*/
5049 0, /*nb_and*/
5050 0, /*nb_xor*/
5051 0, /*nb_or*/
5052 0, /*nb_int*/
5053 0, /*nb_long*/
5054 0, /*nb_float*/
5055 (binaryfunc)M_Sub_inplace_add, /*inplace_add*/
5056 (binaryfunc)M_Sub_inplace_sub, /*inplace_subtract*/
5057 (binaryfunc)M_Sub_inplace_multiply, /*inplace_multiply*/
5058 0, /*inplace_remainder*/
5059 0, /*inplace_power*/
5060 0, /*inplace_lshift*/
5061 0, /*inplace_rshift*/
5062 0, /*inplace_and*/
5063 0, /*inplace_xor*/
5064 0, /*inplace_or*/
5065 0, /*nb_floor_divide*/
5066 (binaryfunc)M_Sub_div, /*nb_true_divide*/
5067 0, /*nb_inplace_floor_divide*/
5068 (binaryfunc)M_Sub_inplace_div, /*nb_inplace_true_divide*/
5069 0, /* nb_index */
5070 };
5071
5072 PyTypeObject M_SubType =
5073 {
5074 PyVarObject_HEAD_INIT(NULL, 0)
5075 "_pyo.M_Sub_base", /*tp_name*/
5076 sizeof(M_Sub), /*tp_basicsize*/
5077 0, /*tp_itemsize*/
5078 (destructor)M_Sub_dealloc, /*tp_dealloc*/
5079 0, /*tp_print*/
5080 0, /*tp_getattr*/
5081 0, /*tp_setattr*/
5082 0, /*tp_as_async (tp_compare in Python 2)*/
5083 0, /*tp_repr*/
5084 &M_Sub_as_number, /*tp_as_number*/
5085 0, /*tp_as_sequence*/
5086 0, /*tp_as_mapping*/
5087 0, /*tp_hash */
5088 0, /*tp_call*/
5089 0, /*tp_str*/
5090 0, /*tp_getattro*/
5091 0, /*tp_setattro*/
5092 0, /*tp_as_buffer*/
5093 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
5094 "M_Sub objects. Substract function.", /* tp_doc */
5095 (traverseproc)M_Sub_traverse, /* tp_traverse */
5096 (inquiry)M_Sub_clear, /* tp_clear */
5097 0, /* tp_richcompare */
5098 0, /* tp_weaklistoffset */
5099 0, /* tp_iter */
5100 0, /* tp_iternext */
5101 M_Sub_methods, /* tp_methods */
5102 M_Sub_members, /* tp_members */
5103 0, /* tp_getset */
5104 0, /* tp_base */
5105 0, /* tp_dict */
5106 0, /* tp_descr_get */
5107 0, /* tp_descr_set */
5108 0, /* tp_dictoffset */
5109 0, /* tp_init */
5110 0, /* tp_alloc */
5111 M_Sub_new, /* tp_new */
5112 };