Debian Codegraph @

src/objects/utilsmodule.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 #include "interpolation.h"
29
30 /************/
31 /* Print */
32 /************/
33 typedef struct
34 {
35 pyo_audio_HEAD
36 PyObject *input;
37 Stream *input_stream;
38 const char *message;
39 int method; // 0 -> interval, 1 -> change
40 MYFLT lastValue;
41 MYFLT time;
42 MYFLT currentTime;
43 MYFLT sampleToSec;
44 } Print;
45
46 static void
47 Print_process_time(Print *self)
48 {
49 int i;
50 MYFLT *in = Stream_getData((Stream *)self->input_stream);
51
52 for (i = 0; i < self->bufsize; i++)
53 {
54 if (self->currentTime >= self->time)
55 {
56 self->currentTime = 0.0;
57
58 if (self->message == NULL || self->message[0] == '\0')
59 PySys_WriteStdout("%f\n", in[i]);
60 else
61 PySys_WriteStdout("%s : %f\n", self->message, in[i]);
62 }
63
64 self->currentTime += self->sampleToSec;
65 }
66 }
67
68 static void
69 Print_process_change(Print *self)
70 {
71 int i;
72 MYFLT inval;
73 MYFLT *in = Stream_getData((Stream *)self->input_stream);
74
75 for (i = 0; i < self->bufsize; i++)
76 {
77 inval = in[i];
78
79 if (inval < (self->lastValue - 0.00001) || inval > (self->lastValue + 0.00001))
80 {
81 if (self->message == NULL || self->message[0] == '\0')
82 PySys_WriteStdout("%f\n", inval);
83 else
84 PySys_WriteStdout("%s : %f\n", self->message, inval);
85
86 self->lastValue = inval;
87 }
88 }
89 }
90
91 static void
92 Print_setProcMode(Print *self)
93 {
94 if (self->method < 0 || self->method > 1)
95 self->method = 0;
96
97 switch (self->method)
98 {
99 case 0:
100 self->proc_func_ptr = Print_process_time;
101 break;
102
103 case 1:
104 self->proc_func_ptr = Print_process_change;
105 break;
106 }
107 }
108
109 static void
110 Print_compute_next_data_frame(Print *self)
111 {
112 (*self->proc_func_ptr)(self);
113 }
114
115 static int
116 Print_traverse(Print *self, visitproc visit, void *arg)
117 {
118 pyo_VISIT
119 Py_VISIT(self->input);
120 return 0;
121 }
122
123 static int
124 Print_clear(Print *self)
125 {
126 pyo_CLEAR
127 Py_CLEAR(self->input);
128 return 0;
129 }
130
131 static void
132 Print_dealloc(Print* self)
133 {
134 pyo_DEALLOC
135 Print_clear(self);
136 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
137 Py_TYPE(self)->tp_free((PyObject*)self);
138 }
139
140 static PyObject *
141 Print_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
142 {
143 int i;
144 PyObject *inputtmp, *input_streamtmp;
145 Print *self;
146 self = (Print *)type->tp_alloc(type, 0);
147
148 self->method = 0;
149 self->time = 0.25;
150 self->lastValue = -99999.0;
151
152 INIT_OBJECT_COMMON
153 Stream_setFunctionPtr(self->stream, Print_compute_next_data_frame);
154 self->mode_func_ptr = Print_setProcMode;
155
156 self->sampleToSec = 1. / self->sr;
157 self->currentTime = 0.;
158
159 static char *kwlist[] = {"input", "method", "interval", "message", NULL};
160
161 if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_O_IFS, kwlist, &inputtmp, &self->method, &self->time, &self->message))
162 Py_RETURN_NONE;
163
164 INIT_INPUT_STREAM
165
166 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
167
168 (*self->mode_func_ptr)(self);
169
170 return (PyObject *)self;
171 }
172
173 static PyObject * Print_getServer(Print* self) { GET_SERVER };
174 static PyObject * Print_getStream(Print* self) { GET_STREAM };
175
176 static PyObject * Print_play(Print *self, PyObject *args, PyObject *kwds) { PLAY };
177 static PyObject * Print_stop(Print *self, PyObject *args, PyObject *kwds) { STOP };
178
179 static PyObject *
180 Print_setMethod(Print *self, PyObject *arg)
181 {
182 ASSERT_ARG_NOT_NULL
183
184 if (PyNumber_Check(arg) == 1)
185 {
186 self->method = PyLong_AsLong(arg);
187 (*self->mode_func_ptr)(self);
188 }
189
190 Py_RETURN_NONE;
191 }
192
193 static PyObject *
194 Print_setInterval(Print *self, PyObject *arg)
195 {
196 ASSERT_ARG_NOT_NULL
197
198 if (PyNumber_Check(arg) == 1)
199 self->time = PyFloat_AsDouble(arg);
200
201 Py_RETURN_NONE;
202 }
203
204 static PyObject *
205 Print_setMessage(Print *self, PyObject *arg)
206 {
207 ASSERT_ARG_NOT_NULL
208
209 if (PyUnicode_Check(arg))
210 self->message = PyUnicode_AsUTF8(arg);
211
212 Py_RETURN_NONE;
213 }
214
215 static PyMemberDef Print_members[] =
216 {
217 {"server", T_OBJECT_EX, offsetof(Print, server), 0, "Pyo server."},
218 {"stream", T_OBJECT_EX, offsetof(Print, stream), 0, "Stream object."},
219 {"input", T_OBJECT_EX, offsetof(Print, input), 0, "Input sound object."},
220 {NULL} /* Sentinel */
221 };
222
223 static PyMethodDef Print_methods[] =
224 {
225 {"getServer", (PyCFunction)Print_getServer, METH_NOARGS, "Returns server object."},
226 {"_getStream", (PyCFunction)Print_getStream, METH_NOARGS, "Returns stream object."},
227 {"play", (PyCFunction)Print_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
228 {"stop", (PyCFunction)Print_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
229 {"setMethod", (PyCFunction)Print_setMethod, METH_O, "Sets the printing method."},
230 {"setInterval", (PyCFunction)Print_setInterval, METH_O, "Sets the time interval."},
231 {"setMessage", (PyCFunction)Print_setMessage, METH_O, "Sets the prefix message to print."},
232 {NULL} /* Sentinel */
233 };
234
235 PyTypeObject PrintType =
236 {
237 PyVarObject_HEAD_INIT(NULL, 0)
238 "_pyo.Print_base", /*tp_name*/
239 sizeof(Print), /*tp_basicsize*/
240 0, /*tp_itemsize*/
241 (destructor)Print_dealloc, /*tp_dealloc*/
242 0, /*tp_print*/
243 0, /*tp_getattr*/
244 0, /*tp_setattr*/
245 0, /*tp_as_async (tp_compare in Python 2)*/
246 0, /*tp_repr*/
247 0, /*tp_as_number*/
248 0, /*tp_as_sequence*/
249 0, /*tp_as_mapping*/
250 0, /*tp_hash */
251 0, /*tp_call*/
252 0, /*tp_str*/
253 0, /*tp_getattro*/
254 0, /*tp_setattro*/
255 0, /*tp_as_buffer*/
256 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
257 "Print objects. Print the current value of the input object.", /* tp_doc */
258 (traverseproc)Print_traverse, /* tp_traverse */
259 (inquiry)Print_clear, /* tp_clear */
260 0, /* tp_richcompare */
261 0, /* tp_weaklistoffset */
262 0, /* tp_iter */
263 0, /* tp_iternext */
264 Print_methods, /* tp_methods */
265 Print_members, /* tp_members */
266 0, /* tp_getset */
267 0, /* tp_base */
268 0, /* tp_dict */
269 0, /* tp_descr_get */
270 0, /* tp_descr_set */
271 0, /* tp_dictoffset */
272 0, /* tp_init */
273 0, /* tp_alloc */
274 Print_new, /* tp_new */
275 };
276
277 /*********************************************************************************************/
278 /* Snap ********************************************************************************/
279 /*********************************************************************************************/
280 typedef struct
281 {
282 pyo_audio_HEAD
283 PyObject *input;
284 Stream *input_stream;
285 int scale; // 0 = Midi, 1 = frequency, 2 = transpo
286 int chSize;
287 int highbound;
288 MYFLT *choice;
289 MYFLT value;
290 MYFLT last_input;
291 int modebuffer[2]; // need at least 2 slots for mul & add
292 } Snap;
293
294 static MYFLT
295 Snap_convert(Snap *self)
296 {
297 int midival;
298 MYFLT val;
299
300 midival = self->value;
301
302 if (self->scale == 1)
303 val = 8.1757989156437 * MYPOW(1.0594630943593, midival);
304 else if (self->scale == 2)
305 val = MYPOW(1.0594630943593, midival - 60);
306 else
307 val = midival;
308
309 return val;
310 }
311
312 static void
313 Snap_generate(Snap *self)
314 {
315 int i, j, pos;
316 MYFLT intmp, diff, difftmp;
317 MYFLT *in = Stream_getData((Stream *)self->input_stream);
318
319 for (i = 0; i < self->bufsize; i++)
320 {
321 if (in[i] < (self->last_input - 0.001) || in[i] > (self->last_input + 0.001))
322 {
323 int oct = 0;
324 self->last_input = intmp = in[i];
325
326 while (intmp >= self->highbound)
327 {
328 oct++;
329 intmp -= self->highbound;
330 }
331
332 diff = MYFABS(self->choice[0] - intmp);
333 pos = 0;
334
335 for (j = 1; j < self->chSize; j++)
336 {
337 difftmp = MYFABS(self->choice[j] - intmp);
338
339 if (difftmp < diff)
340 {
341 diff = difftmp;
342 pos = j;
343 }
344 }
345
346 self->value = self->choice[pos] + (self->highbound * oct);
347 self->value = Snap_convert(self);
348 }
349
350 self->data[i] = self->value;
351 }
352 }
353
354 static void Snap_postprocessing_ii(Snap *self) { POST_PROCESSING_II };
355 static void Snap_postprocessing_ai(Snap *self) { POST_PROCESSING_AI };
356 static void Snap_postprocessing_ia(Snap *self) { POST_PROCESSING_IA };
357 static void Snap_postprocessing_aa(Snap *self) { POST_PROCESSING_AA };
358 static void Snap_postprocessing_ireva(Snap *self) { POST_PROCESSING_IREVA };
359 static void Snap_postprocessing_areva(Snap *self) { POST_PROCESSING_AREVA };
360 static void Snap_postprocessing_revai(Snap *self) { POST_PROCESSING_REVAI };
361 static void Snap_postprocessing_revaa(Snap *self) { POST_PROCESSING_REVAA };
362 static void Snap_postprocessing_revareva(Snap *self) { POST_PROCESSING_REVAREVA };
363
364 static void
365 Snap_setProcMode(Snap *self)
366 {
367 int muladdmode;
368 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
369
370 self->proc_func_ptr = Snap_generate;
371
372 switch (muladdmode)
373 {
374 case 0:
375 self->muladd_func_ptr = Snap_postprocessing_ii;
376 break;
377
378 case 1:
379 self->muladd_func_ptr = Snap_postprocessing_ai;
380 break;
381
382 case 2:
383 self->muladd_func_ptr = Snap_postprocessing_revai;
384 break;
385
386 case 10:
387 self->muladd_func_ptr = Snap_postprocessing_ia;
388 break;
389
390 case 11:
391 self->muladd_func_ptr = Snap_postprocessing_aa;
392 break;
393
394 case 12:
395 self->muladd_func_ptr = Snap_postprocessing_revaa;
396 break;
397
398 case 20:
399 self->muladd_func_ptr = Snap_postprocessing_ireva;
400 break;
401
402 case 21:
403 self->muladd_func_ptr = Snap_postprocessing_areva;
404 break;
405
406 case 22:
407 self->muladd_func_ptr = Snap_postprocessing_revareva;
408 break;
409 }
410 }
411
412 static void
413 Snap_compute_next_data_frame(Snap *self)
414 {
415 (*self->proc_func_ptr)(self);
416 (*self->muladd_func_ptr)(self);
417 }
418
419 static int
420 Snap_traverse(Snap *self, visitproc visit, void *arg)
421 {
422 pyo_VISIT
423 Py_VISIT(self->input);
424 return 0;
425 }
426
427 static int
428 Snap_clear(Snap *self)
429 {
430 pyo_CLEAR
431 Py_CLEAR(self->input);
432 return 0;
433 }
434
435 static void
436 Snap_dealloc(Snap* self)
437 {
438 pyo_DEALLOC
439 PyMem_RawFree(self->choice);
440 Snap_clear(self);
441 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
442 Py_TYPE(self)->tp_free((PyObject*)self);
443 }
444
445 static PyObject *
446 Snap_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
447 {
448 int i;
449 PyObject *inputtmp, *input_streamtmp, *choicetmp = NULL, *multmp = NULL, *addtmp = NULL;
450 Snap *self;
451 self = (Snap *)type->tp_alloc(type, 0);
452
453 self->value = self->last_input = 0.;
454 self->scale = 0;
455 self->highbound = 12;
456 self->modebuffer[0] = 0;
457 self->modebuffer[1] = 0;
458
459 INIT_OBJECT_COMMON
460 Stream_setFunctionPtr(self->stream, Snap_compute_next_data_frame);
461 self->mode_func_ptr = Snap_setProcMode;
462
463 static char *kwlist[] = {"input", "choice", "scale", "mul", "add", NULL};
464
465 if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|iOO", kwlist, &inputtmp, &choicetmp, &self->scale, &multmp, &addtmp))
466 Py_RETURN_NONE;
467
468 INIT_INPUT_STREAM
469
470 if (choicetmp)
471 {
472 PyObject_CallMethod((PyObject *)self, "setChoice", "O", choicetmp);
473 }
474
475 if (multmp)
476 {
477 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
478 }
479
480 if (addtmp)
481 {
482 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
483 }
484
485 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
486
487 (*self->mode_func_ptr)(self);
488
489 return (PyObject *)self;
490 }
491
492 static PyObject * Snap_getServer(Snap* self) { GET_SERVER };
493 static PyObject * Snap_getStream(Snap* self) { GET_STREAM };
494 static PyObject * Snap_setMul(Snap *self, PyObject *arg) { SET_MUL };
495 static PyObject * Snap_setAdd(Snap *self, PyObject *arg) { SET_ADD };
496 static PyObject * Snap_setSub(Snap *self, PyObject *arg) { SET_SUB };
497 static PyObject * Snap_setDiv(Snap *self, PyObject *arg) { SET_DIV };
498
499 static PyObject * Snap_play(Snap *self, PyObject *args, PyObject *kwds) { PLAY };
500 static PyObject * Snap_out(Snap *self, PyObject *args, PyObject *kwds) { OUT };
501 static PyObject * Snap_stop(Snap *self, PyObject *args, PyObject *kwds) { STOP };
502
503 static PyObject * Snap_multiply(Snap *self, PyObject *arg) { MULTIPLY };
504 static PyObject * Snap_inplace_multiply(Snap *self, PyObject *arg) { INPLACE_MULTIPLY };
505 static PyObject * Snap_add(Snap *self, PyObject *arg) { ADD };
506 static PyObject * Snap_inplace_add(Snap *self, PyObject *arg) { INPLACE_ADD };
507 static PyObject * Snap_sub(Snap *self, PyObject *arg) { SUB };
508 static PyObject * Snap_inplace_sub(Snap *self, PyObject *arg) { INPLACE_SUB };
509 static PyObject * Snap_div(Snap *self, PyObject *arg) { DIV };
510 static PyObject * Snap_inplace_div(Snap *self, PyObject *arg) { INPLACE_DIV };
511
512 static PyObject *
513 Snap_setChoice(Snap *self, PyObject *arg)
514 {
515 int i, oct;
516 MYFLT max;
517
518 if (! PyList_Check(arg))
519 {
520 PyErr_SetString(PyExc_TypeError, "The choice attribute must be a list.");
521 Py_RETURN_NONE;
522 }
523
524 self->chSize = PyList_Size(arg);
525 self->choice = (MYFLT *)PyMem_RawRealloc(self->choice, self->chSize * sizeof(MYFLT));
526
527 for (i = 0; i < self->chSize; i++)
528 {
529 self->choice[i] = PyFloat_AsDouble(PyList_GET_ITEM(arg, i));
530 }
531
532 max = self->choice[self->chSize - 1];
533
534 oct = 12;
535
536 while (max >= oct)
537 {
538 oct += 12;
539 }
540
541 self->highbound = oct;
542
543 (*self->mode_func_ptr)(self);
544
545 Py_RETURN_NONE;
546 }
547
548 static PyObject *
549 Snap_setScale(Snap *self, PyObject *arg)
550 {
551 int tmp;
552
553 ASSERT_ARG_NOT_NULL
554
555 if (PyLong_Check(arg))
556 {
557 tmp = PyLong_AsLong(arg);
558
559 if (tmp >= 0 && tmp <= 2)
560 self->scale = tmp;
561 else
562 PySys_WriteStdout("Snap: scale attribute must be an integer {0, 1, 2}\n");
563 }
564
565 Py_RETURN_NONE;
566 }
567
568 static PyMemberDef Snap_members[] =
569 {
570 {"server", T_OBJECT_EX, offsetof(Snap, server), 0, "Pyo server."},
571 {"stream", T_OBJECT_EX, offsetof(Snap, stream), 0, "Stream object."},
572 {"input", T_OBJECT_EX, offsetof(Snap, input), 0, "Input sound object."},
573 {"mul", T_OBJECT_EX, offsetof(Snap, mul), 0, "Mul factor."},
574 {"add", T_OBJECT_EX, offsetof(Snap, add), 0, "Add factor."},
575 {NULL} /* Sentinel */
576 };
577
578 static PyMethodDef Snap_methods[] =
579 {
580 {"getServer", (PyCFunction)Snap_getServer, METH_NOARGS, "Returns server object."},
581 {"_getStream", (PyCFunction)Snap_getStream, METH_NOARGS, "Returns stream object."},
582 {"play", (PyCFunction)Snap_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
583 {"out", (PyCFunction)Snap_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
584 {"stop", (PyCFunction)Snap_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
585 {"setChoice", (PyCFunction)Snap_setChoice, METH_O, "Sets output scale."},
586 {"setScale", (PyCFunction)Snap_setScale, METH_O, "Sets new portamento time."},
587 {"setMul", (PyCFunction)Snap_setMul, METH_O, "Sets oscillator mul factor."},
588 {"setAdd", (PyCFunction)Snap_setAdd, METH_O, "Sets oscillator add factor."},
589 {"setSub", (PyCFunction)Snap_setSub, METH_O, "Sets inverse add factor."},
590 {"setDiv", (PyCFunction)Snap_setDiv, METH_O, "Sets inverse mul factor."},
591 {NULL} /* Sentinel */
592 };
593
594 static PyNumberMethods Snap_as_number =
595 {
596 (binaryfunc)Snap_add, /*nb_add*/
597 (binaryfunc)Snap_sub, /*nb_subtract*/
598 (binaryfunc)Snap_multiply, /*nb_multiply*/
599 0, /*nb_remainder*/
600 0, /*nb_divmod*/
601 0, /*nb_power*/
602 0, /*nb_neg*/
603 0, /*nb_pos*/
604 0, /*(unaryfunc)array_abs,*/
605 0, /*nb_nonzero*/
606 0, /*nb_invert*/
607 0, /*nb_lshift*/
608 0, /*nb_rshift*/
609 0, /*nb_and*/
610 0, /*nb_xor*/
611 0, /*nb_or*/
612 0, /*nb_int*/
613 0, /*nb_long*/
614 0, /*nb_float*/
615 (binaryfunc)Snap_inplace_add, /*inplace_add*/
616 (binaryfunc)Snap_inplace_sub, /*inplace_subtract*/
617 (binaryfunc)Snap_inplace_multiply, /*inplace_multiply*/
618 0, /*inplace_remainder*/
619 0, /*inplace_power*/
620 0, /*inplace_lshift*/
621 0, /*inplace_rshift*/
622 0, /*inplace_and*/
623 0, /*inplace_xor*/
624 0, /*inplace_or*/
625 0, /*nb_floor_divide*/
626 (binaryfunc)Snap_div, /*nb_true_divide*/
627 0, /*nb_inplace_floor_divide*/
628 (binaryfunc)Snap_inplace_div, /*nb_inplace_true_divide*/
629 0, /* nb_index */
630 };
631
632 PyTypeObject SnapType =
633 {
634 PyVarObject_HEAD_INIT(NULL, 0)
635 "_pyo.Snap_base", /*tp_name*/
636 sizeof(Snap), /*tp_basicsize*/
637 0, /*tp_itemsize*/
638 (destructor)Snap_dealloc, /*tp_dealloc*/
639 0, /*tp_print*/
640 0, /*tp_getattr*/
641 0, /*tp_setattr*/
642 0, /*tp_as_async (tp_compare in Python 2)*/
643 0, /*tp_repr*/
644 &Snap_as_number, /*tp_as_number*/
645 0, /*tp_as_sequence*/
646 0, /*tp_as_mapping*/
647 0, /*tp_hash */
648 0, /*tp_call*/
649 0, /*tp_str*/
650 0, /*tp_getattro*/
651 0, /*tp_setattro*/
652 0, /*tp_as_buffer*/
653 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
654 "Snap objects. Snap input values on an arbitrary Midi scale.", /* tp_doc */
655 (traverseproc)Snap_traverse, /* tp_traverse */
656 (inquiry)Snap_clear, /* tp_clear */
657 0, /* tp_richcompare */
658 0, /* tp_weaklistoffset */
659 0, /* tp_iter */
660 0, /* tp_iternext */
661 Snap_methods, /* tp_methods */
662 Snap_members, /* tp_members */
663 0, /* tp_getset */
664 0, /* tp_base */
665 0, /* tp_dict */
666 0, /* tp_descr_get */
667 0, /* tp_descr_set */
668 0, /* tp_dictoffset */
669 0, /* tp_init */
670 0, /* tp_alloc */
671 Snap_new, /* tp_new */
672 };
673
674 /************/
675 /* Interp */
676 /************/
677 typedef struct
678 {
679 pyo_audio_HEAD
680 PyObject *input;
681 Stream *input_stream;
682 PyObject *input2;
683 Stream *input2_stream;
684 PyObject *interp;
685 Stream *interp_stream;
686 int modebuffer[3]; // need at least 2 slots for mul & add
687 } Interp;
688
689 static void
690 Interp_filters_i(Interp *self)
691 {
692 int i;
693 MYFLT *in = Stream_getData((Stream *)self->input_stream);
694 MYFLT *in2 = Stream_getData((Stream *)self->input2_stream);
695 MYFLT inter = PyFloat_AS_DOUBLE(self->interp);
696
697 if (inter < 0.0)
698 inter = 0.0;
699 else if (inter > 1.0)
700 inter = 1.0;
701
702 for (i = 0; i < self->bufsize; i++)
703 {
704 self->data[i] = in[i] + (in2[i] - in[i]) * inter;
705 }
706 }
707
708 static void
709 Interp_filters_a(Interp *self)
710 {
711 MYFLT amp1;
712 int i;
713 MYFLT *in = Stream_getData((Stream *)self->input_stream);
714 MYFLT *in2 = Stream_getData((Stream *)self->input2_stream);
715 MYFLT *inter = Stream_getData((Stream *)self->interp_stream);
716
717 for (i = 0; i < self->bufsize; i++)
718 {
719 amp1 = inter[i];
720
721 if (amp1 < 0.0)
722 amp1 = 0.0;
723 else if (amp1 > 1.0)
724 amp1 = 1.0;
725
726 self->data[i] = in[i] + (in2[i] - in[i]) * amp1;
727 }
728 }
729
730 static void Interp_postprocessing_ii(Interp *self) { POST_PROCESSING_II };
731 static void Interp_postprocessing_ai(Interp *self) { POST_PROCESSING_AI };
732 static void Interp_postprocessing_ia(Interp *self) { POST_PROCESSING_IA };
733 static void Interp_postprocessing_aa(Interp *self) { POST_PROCESSING_AA };
734 static void Interp_postprocessing_ireva(Interp *self) { POST_PROCESSING_IREVA };
735 static void Interp_postprocessing_areva(Interp *self) { POST_PROCESSING_AREVA };
736 static void Interp_postprocessing_revai(Interp *self) { POST_PROCESSING_REVAI };
737 static void Interp_postprocessing_revaa(Interp *self) { POST_PROCESSING_REVAA };
738 static void Interp_postprocessing_revareva(Interp *self) { POST_PROCESSING_REVAREVA };
739
740 static void
741 Interp_setProcMode(Interp *self)
742 {
743 int procmode, muladdmode;
744 procmode = self->modebuffer[2];
745 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
746
747 switch (procmode)
748 {
749 case 0:
750 self->proc_func_ptr = Interp_filters_i;
751 break;
752
753 case 1:
754 self->proc_func_ptr = Interp_filters_a;
755 break;
756 }
757
758 switch (muladdmode)
759 {
760 case 0:
761 self->muladd_func_ptr = Interp_postprocessing_ii;
762 break;
763
764 case 1:
765 self->muladd_func_ptr = Interp_postprocessing_ai;
766 break;
767
768 case 2:
769 self->muladd_func_ptr = Interp_postprocessing_revai;
770 break;
771
772 case 10:
773 self->muladd_func_ptr = Interp_postprocessing_ia;
774 break;
775
776 case 11:
777 self->muladd_func_ptr = Interp_postprocessing_aa;
778 break;
779
780 case 12:
781 self->muladd_func_ptr = Interp_postprocessing_revaa;
782 break;
783
784 case 20:
785 self->muladd_func_ptr = Interp_postprocessing_ireva;
786 break;
787
788 case 21:
789 self->muladd_func_ptr = Interp_postprocessing_areva;
790 break;
791
792 case 22:
793 self->muladd_func_ptr = Interp_postprocessing_revareva;
794 break;
795 }
796 }
797
798 static void
799 Interp_compute_next_data_frame(Interp *self)
800 {
801 (*self->proc_func_ptr)(self);
802 (*self->muladd_func_ptr)(self);
803 }
804
805 static int
806 Interp_traverse(Interp *self, visitproc visit, void *arg)
807 {
808 pyo_VISIT
809 Py_VISIT(self->input);
810 Py_VISIT(self->input2);
811 Py_VISIT(self->interp);
812 return 0;
813 }
814
815 static int
816 Interp_clear(Interp *self)
817 {
818 pyo_CLEAR
819 Py_CLEAR(self->input);
820 Py_CLEAR(self->input2);
821 Py_CLEAR(self->interp);
822 return 0;
823 }
824
825 static void
826 Interp_dealloc(Interp* self)
827 {
828 pyo_DEALLOC
829 Interp_clear(self);
830 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
831 Py_TYPE(self)->tp_free((PyObject*)self);
832 }
833
834 static PyObject *
835 Interp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
836 {
837 int i;
838 PyObject *inputtmp, *input_streamtmp, *input2tmp, *input2_streamtmp, *interptmp = NULL, *multmp = NULL, *addtmp = NULL;
839 Interp *self;
840 self = (Interp *)type->tp_alloc(type, 0);
841
842 self->interp = PyFloat_FromDouble(.5);
843 self->modebuffer[0] = 0;
844 self->modebuffer[1] = 0;
845 self->modebuffer[2] = 0;
846
847 INIT_OBJECT_COMMON
848 Stream_setFunctionPtr(self->stream, Interp_compute_next_data_frame);
849 self->mode_func_ptr = Interp_setProcMode;
850
851 static char *kwlist[] = {"input", "input2", "interp", "mul", "add", NULL};
852
853 if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|OOO", kwlist, &inputtmp, &input2tmp, &interptmp, &multmp, &addtmp))
854 Py_RETURN_NONE;
855
856 INIT_INPUT_STREAM
857
858 self->input2 = input2tmp;
859 Py_INCREF(self->input2);
860 input2_streamtmp = PyObject_CallMethod((PyObject *)self->input2, "_getStream", NULL);
861 self->input2_stream = (Stream *)input2_streamtmp;
862 Py_INCREF(self->input2_stream);
863
864 if (interptmp)
865 {
866 PyObject_CallMethod((PyObject *)self, "setInterp", "O", interptmp);
867 }
868
869 if (multmp)
870 {
871 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
872 }
873
874 if (addtmp)
875 {
876 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
877 }
878
879 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
880
881 (*self->mode_func_ptr)(self);
882
883 return (PyObject *)self;
884 }
885
886 static PyObject * Interp_getServer(Interp* self) { GET_SERVER };
887 static PyObject * Interp_getStream(Interp* self) { GET_STREAM };
888 static PyObject * Interp_setMul(Interp *self, PyObject *arg) { SET_MUL };
889 static PyObject * Interp_setAdd(Interp *self, PyObject *arg) { SET_ADD };
890 static PyObject * Interp_setSub(Interp *self, PyObject *arg) { SET_SUB };
891 static PyObject * Interp_setDiv(Interp *self, PyObject *arg) { SET_DIV };
892
893 static PyObject * Interp_play(Interp *self, PyObject *args, PyObject *kwds) { PLAY };
894 static PyObject * Interp_out(Interp *self, PyObject *args, PyObject *kwds) { OUT };
895 static PyObject * Interp_stop(Interp *self, PyObject *args, PyObject *kwds) { STOP };
896
897 static PyObject * Interp_multiply(Interp *self, PyObject *arg) { MULTIPLY };
898 static PyObject * Interp_inplace_multiply(Interp *self, PyObject *arg) { INPLACE_MULTIPLY };
899 static PyObject * Interp_add(Interp *self, PyObject *arg) { ADD };
900 static PyObject * Interp_inplace_add(Interp *self, PyObject *arg) { INPLACE_ADD };
901 static PyObject * Interp_sub(Interp *self, PyObject *arg) { SUB };
902 static PyObject * Interp_inplace_sub(Interp *self, PyObject *arg) { INPLACE_SUB };
903 static PyObject * Interp_div(Interp *self, PyObject *arg) { DIV };
904 static PyObject * Interp_inplace_div(Interp *self, PyObject *arg) { INPLACE_DIV };
905
906 static PyObject * Interp_setInterp(Interp *self, PyObject *arg) { SET_PARAM(self->interp, self->interp_stream, 2); }
907
908 static PyMemberDef Interp_members[] =
909 {
910 {"server", T_OBJECT_EX, offsetof(Interp, server), 0, "Pyo server."},
911 {"stream", T_OBJECT_EX, offsetof(Interp, stream), 0, "Stream object."},
912 {"input", T_OBJECT_EX, offsetof(Interp, input), 0, "Input sound object."},
913 {"input2", T_OBJECT_EX, offsetof(Interp, input2), 0, "Second input sound object."},
914 {"interp", T_OBJECT_EX, offsetof(Interp, interp), 0, "Cutoff interpuency in cycle per second."},
915 {"mul", T_OBJECT_EX, offsetof(Interp, mul), 0, "Mul factor."},
916 {"add", T_OBJECT_EX, offsetof(Interp, add), 0, "Add factor."},
917 {NULL} /* Sentinel */
918 };
919
920 static PyMethodDef Interp_methods[] =
921 {
922 {"getServer", (PyCFunction)Interp_getServer, METH_NOARGS, "Returns server object."},
923 {"_getStream", (PyCFunction)Interp_getStream, METH_NOARGS, "Returns stream object."},
924 {"play", (PyCFunction)Interp_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
925 {"out", (PyCFunction)Interp_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
926 {"stop", (PyCFunction)Interp_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
927 {"setInterp", (PyCFunction)Interp_setInterp, METH_O, "Sets filter cutoff interpuency in cycle per second."},
928 {"setMul", (PyCFunction)Interp_setMul, METH_O, "Sets oscillator mul factor."},
929 {"setAdd", (PyCFunction)Interp_setAdd, METH_O, "Sets oscillator add factor."},
930 {"setSub", (PyCFunction)Interp_setSub, METH_O, "Sets inverse add factor."},
931 {"setDiv", (PyCFunction)Interp_setDiv, METH_O, "Sets inverse mul factor."},
932 {NULL} /* Sentinel */
933 };
934
935 static PyNumberMethods Interp_as_number =
936 {
937 (binaryfunc)Interp_add, /*nb_add*/
938 (binaryfunc)Interp_sub, /*nb_subtract*/
939 (binaryfunc)Interp_multiply, /*nb_multiply*/
940 0, /*nb_remainder*/
941 0, /*nb_divmod*/
942 0, /*nb_power*/
943 0, /*nb_neg*/
944 0, /*nb_pos*/
945 0, /*(unaryfunc)array_abs,*/
946 0, /*nb_nonzero*/
947 0, /*nb_invert*/
948 0, /*nb_lshift*/
949 0, /*nb_rshift*/
950 0, /*nb_and*/
951 0, /*nb_xor*/
952 0, /*nb_or*/
953 0, /*nb_int*/
954 0, /*nb_long*/
955 0, /*nb_float*/
956 (binaryfunc)Interp_inplace_add, /*inplace_add*/
957 (binaryfunc)Interp_inplace_sub, /*inplace_subtract*/
958 (binaryfunc)Interp_inplace_multiply, /*inplace_multiply*/
959 0, /*inplace_remainder*/
960 0, /*inplace_power*/
961 0, /*inplace_lshift*/
962 0, /*inplace_rshift*/
963 0, /*inplace_and*/
964 0, /*inplace_xor*/
965 0, /*inplace_or*/
966 0, /*nb_floor_divide*/
967 (binaryfunc)Interp_div, /*nb_true_divide*/
968 0, /*nb_inplace_floor_divide*/
969 (binaryfunc)Interp_inplace_div, /*nb_inplace_true_divide*/
970 0, /* nb_index */
971 };
972
973 PyTypeObject InterpType =
974 {
975 PyVarObject_HEAD_INIT(NULL, 0)
976 "_pyo.Interp_base", /*tp_name*/
977 sizeof(Interp), /*tp_basicsize*/
978 0, /*tp_itemsize*/
979 (destructor)Interp_dealloc, /*tp_dealloc*/
980 0, /*tp_print*/
981 0, /*tp_getattr*/
982 0, /*tp_setattr*/
983 0, /*tp_as_async (tp_compare in Python 2)*/
984 0, /*tp_repr*/
985 &Interp_as_number, /*tp_as_number*/
986 0, /*tp_as_sequence*/
987 0, /*tp_as_mapping*/
988 0, /*tp_hash */
989 0, /*tp_call*/
990 0, /*tp_str*/
991 0, /*tp_getattro*/
992 0, /*tp_setattro*/
993 0, /*tp_as_buffer*/
994 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
995 "Interp objects. Interpolates between 2 audio streams.", /* tp_doc */
996 (traverseproc)Interp_traverse, /* tp_traverse */
997 (inquiry)Interp_clear, /* tp_clear */
998 0, /* tp_richcompare */
999 0, /* tp_weaklistoffset */
1000 0, /* tp_iter */
1001 0, /* tp_iternext */
1002 Interp_methods, /* tp_methods */
1003 Interp_members, /* tp_members */
1004 0, /* tp_getset */
1005 0, /* tp_base */
1006 0, /* tp_dict */
1007 0, /* tp_descr_get */
1008 0, /* tp_descr_set */
1009 0, /* tp_dictoffset */
1010 0, /* tp_init */
1011 0, /* tp_alloc */
1012 Interp_new, /* tp_new */
1013 };
1014
1015 /************/
1016 /* SampHold */
1017 /************/
1018 typedef struct
1019 {
1020 pyo_audio_HEAD
1021 PyObject *input;
1022 Stream *input_stream;
1023 PyObject *controlsig;
1024 Stream *controlsig_stream;
1025 PyObject *value;
1026 Stream *value_stream;
1027 MYFLT currentValue;
1028 int flag;
1029 int modebuffer[3]; // need at least 2 slots for mul & add
1030 } SampHold;
1031
1032 static void
1033 SampHold_filters_i(SampHold *self)
1034 {
1035 MYFLT ctrl;
1036 int i;
1037 MYFLT *in = Stream_getData((Stream *)self->input_stream);
1038 MYFLT *ctrlsig = Stream_getData((Stream *)self->controlsig_stream);
1039 MYFLT val = PyFloat_AS_DOUBLE(self->value);
1040
1041 for (i = 0; i < self->bufsize; i++)
1042 {
1043 ctrl = ctrlsig[i];
1044
1045 if (ctrl > (val - 0.001) && ctrl < (val + 0.001))
1046 {
1047 if (self->flag == 1)
1048 {
1049 self->currentValue = in[i];
1050 self->flag = 0;
1051 }
1052 }
1053 else
1054 self->flag = 1;
1055
1056 self->data[i] = self->currentValue;
1057 }
1058 }
1059
1060 static void
1061 SampHold_filters_a(SampHold *self)
1062 {
1063 MYFLT ctrl, val;
1064 int i;
1065 MYFLT *in = Stream_getData((Stream *)self->input_stream);
1066 MYFLT *ctrlsig = Stream_getData((Stream *)self->controlsig_stream);
1067 MYFLT *valsig = Stream_getData((Stream *)self->value_stream);
1068
1069 for (i = 0; i < self->bufsize; i++)
1070 {
1071 ctrl = ctrlsig[i];
1072 val = valsig[i];
1073
1074 if (ctrl > (val - 0.001) && ctrl < (val + 0.001))
1075 {
1076 if (self->flag == 1)
1077 {
1078 self->currentValue = in[i];
1079 self->flag = 0;
1080 }
1081 }
1082 else
1083 self->flag = 1;
1084
1085 self->data[i] = self->currentValue;
1086 }
1087 }
1088
1089 static void SampHold_postprocessing_ii(SampHold *self) { POST_PROCESSING_II };
1090 static void SampHold_postprocessing_ai(SampHold *self) { POST_PROCESSING_AI };
1091 static void SampHold_postprocessing_ia(SampHold *self) { POST_PROCESSING_IA };
1092 static void SampHold_postprocessing_aa(SampHold *self) { POST_PROCESSING_AA };
1093 static void SampHold_postprocessing_ireva(SampHold *self) { POST_PROCESSING_IREVA };
1094 static void SampHold_postprocessing_areva(SampHold *self) { POST_PROCESSING_AREVA };
1095 static void SampHold_postprocessing_revai(SampHold *self) { POST_PROCESSING_REVAI };
1096 static void SampHold_postprocessing_revaa(SampHold *self) { POST_PROCESSING_REVAA };
1097 static void SampHold_postprocessing_revareva(SampHold *self) { POST_PROCESSING_REVAREVA };
1098
1099 static void
1100 SampHold_setProcMode(SampHold *self)
1101 {
1102 int procmode, muladdmode;
1103 procmode = self->modebuffer[2];
1104 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
1105
1106 switch (procmode)
1107 {
1108 case 0:
1109 self->proc_func_ptr = SampHold_filters_i;
1110 break;
1111
1112 case 1:
1113 self->proc_func_ptr = SampHold_filters_a;
1114 break;
1115 }
1116
1117 switch (muladdmode)
1118 {
1119 case 0:
1120 self->muladd_func_ptr = SampHold_postprocessing_ii;
1121 break;
1122
1123 case 1:
1124 self->muladd_func_ptr = SampHold_postprocessing_ai;
1125 break;
1126
1127 case 2:
1128 self->muladd_func_ptr = SampHold_postprocessing_revai;
1129 break;
1130
1131 case 10:
1132 self->muladd_func_ptr = SampHold_postprocessing_ia;
1133 break;
1134
1135 case 11:
1136 self->muladd_func_ptr = SampHold_postprocessing_aa;
1137 break;
1138
1139 case 12:
1140 self->muladd_func_ptr = SampHold_postprocessing_revaa;
1141 break;
1142
1143 case 20:
1144 self->muladd_func_ptr = SampHold_postprocessing_ireva;
1145 break;
1146
1147 case 21:
1148 self->muladd_func_ptr = SampHold_postprocessing_areva;
1149 break;
1150
1151 case 22:
1152 self->muladd_func_ptr = SampHold_postprocessing_revareva;
1153 break;
1154 }
1155 }
1156
1157 static void
1158 SampHold_compute_next_data_frame(SampHold *self)
1159 {
1160 (*self->proc_func_ptr)(self);
1161 (*self->muladd_func_ptr)(self);
1162 }
1163
1164 static int
1165 SampHold_traverse(SampHold *self, visitproc visit, void *arg)
1166 {
1167 pyo_VISIT
1168 Py_VISIT(self->input);
1169 Py_VISIT(self->controlsig);
1170 Py_VISIT(self->value);
1171 return 0;
1172 }
1173
1174 static int
1175 SampHold_clear(SampHold *self)
1176 {
1177 pyo_CLEAR
1178 Py_CLEAR(self->input);
1179 Py_CLEAR(self->controlsig);
1180 Py_CLEAR(self->value);
1181 return 0;
1182 }
1183
1184 static void
1185 SampHold_dealloc(SampHold* self)
1186 {
1187 pyo_DEALLOC
1188 SampHold_clear(self);
1189 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
1190 Py_TYPE(self)->tp_free((PyObject*)self);
1191 }
1192
1193 static PyObject *
1194 SampHold_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1195 {
1196 int i;
1197 PyObject *inputtmp, *input_streamtmp, *controlsigtmp, *controlsig_streamtmp, *valuetmp = NULL, *multmp = NULL, *addtmp = NULL;
1198 SampHold *self;
1199 self = (SampHold *)type->tp_alloc(type, 0);
1200
1201 self->value = PyFloat_FromDouble(0.0);
1202 self->currentValue = 0.0;
1203 self->flag = 1;
1204 self->modebuffer[0] = 0;
1205 self->modebuffer[1] = 0;
1206 self->modebuffer[2] = 0;
1207
1208 INIT_OBJECT_COMMON
1209 Stream_setFunctionPtr(self->stream, SampHold_compute_next_data_frame);
1210 self->mode_func_ptr = SampHold_setProcMode;
1211
1212 static char *kwlist[] = {"input", "controlsig", "value", "mul", "add", NULL};
1213
1214 if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|OOO", kwlist, &inputtmp, &controlsigtmp, &valuetmp, &multmp, &addtmp))
1215 Py_RETURN_NONE;
1216
1217 INIT_INPUT_STREAM
1218
1219 self->controlsig = controlsigtmp;
1220 Py_INCREF(self->controlsig);
1221 controlsig_streamtmp = PyObject_CallMethod((PyObject *)self->controlsig, "_getStream", NULL);
1222 self->controlsig_stream = (Stream *)controlsig_streamtmp;
1223 Py_INCREF(self->controlsig_stream);
1224
1225 if (valuetmp)
1226 {
1227 PyObject_CallMethod((PyObject *)self, "setValue", "O", valuetmp);
1228 }
1229
1230 if (multmp)
1231 {
1232 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
1233 }
1234
1235 if (addtmp)
1236 {
1237 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
1238 }
1239
1240 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1241
1242 (*self->mode_func_ptr)(self);
1243
1244 return (PyObject *)self;
1245 }
1246
1247 static PyObject * SampHold_getServer(SampHold* self) { GET_SERVER };
1248 static PyObject * SampHold_getStream(SampHold* self) { GET_STREAM };
1249 static PyObject * SampHold_setMul(SampHold *self, PyObject *arg) { SET_MUL };
1250 static PyObject * SampHold_setAdd(SampHold *self, PyObject *arg) { SET_ADD };
1251 static PyObject * SampHold_setSub(SampHold *self, PyObject *arg) { SET_SUB };
1252 static PyObject * SampHold_setDiv(SampHold *self, PyObject *arg) { SET_DIV };
1253
1254 static PyObject * SampHold_play(SampHold *self, PyObject *args, PyObject *kwds) { PLAY };
1255 static PyObject * SampHold_out(SampHold *self, PyObject *args, PyObject *kwds) { OUT };
1256 static PyObject * SampHold_stop(SampHold *self, PyObject *args, PyObject *kwds) { STOP };
1257
1258 static PyObject * SampHold_multiply(SampHold *self, PyObject *arg) { MULTIPLY };
1259 static PyObject * SampHold_inplace_multiply(SampHold *self, PyObject *arg) { INPLACE_MULTIPLY };
1260 static PyObject * SampHold_add(SampHold *self, PyObject *arg) { ADD };
1261 static PyObject * SampHold_inplace_add(SampHold *self, PyObject *arg) { INPLACE_ADD };
1262 static PyObject * SampHold_sub(SampHold *self, PyObject *arg) { SUB };
1263 static PyObject * SampHold_inplace_sub(SampHold *self, PyObject *arg) { INPLACE_SUB };
1264 static PyObject * SampHold_div(SampHold *self, PyObject *arg) { DIV };
1265 static PyObject * SampHold_inplace_div(SampHold *self, PyObject *arg) { INPLACE_DIV };
1266
1267 static PyObject * SampHold_setValue(SampHold *self, PyObject *arg) { SET_PARAM(self->value, self->value_stream, 2); }
1268
1269 static PyMemberDef SampHold_members[] =
1270 {
1271 {"server", T_OBJECT_EX, offsetof(SampHold, server), 0, "Pyo server."},
1272 {"stream", T_OBJECT_EX, offsetof(SampHold, stream), 0, "Stream object."},
1273 {"input", T_OBJECT_EX, offsetof(SampHold, input), 0, "Input sound object."},
1274 {"controlsig", T_OBJECT_EX, offsetof(SampHold, controlsig), 0, "Control input object."},
1275 {"value", T_OBJECT_EX, offsetof(SampHold, value), 0, "Trigger value."},
1276 {"mul", T_OBJECT_EX, offsetof(SampHold, mul), 0, "Mul factor."},
1277 {"add", T_OBJECT_EX, offsetof(SampHold, add), 0, "Add factor."},
1278 {NULL} /* Sentinel */
1279 };
1280
1281 static PyMethodDef SampHold_methods[] =
1282 {
1283 {"getServer", (PyCFunction)SampHold_getServer, METH_NOARGS, "Returns server object."},
1284 {"_getStream", (PyCFunction)SampHold_getStream, METH_NOARGS, "Returns stream object."},
1285 {"play", (PyCFunction)SampHold_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1286 {"out", (PyCFunction)SampHold_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
1287 {"stop", (PyCFunction)SampHold_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
1288 {"setValue", (PyCFunction)SampHold_setValue, METH_O, "Sets trigger value."},
1289 {"setMul", (PyCFunction)SampHold_setMul, METH_O, "Sets oscillator mul factor."},
1290 {"setAdd", (PyCFunction)SampHold_setAdd, METH_O, "Sets oscillator add factor."},
1291 {"setSub", (PyCFunction)SampHold_setSub, METH_O, "Sets inverse add factor."},
1292 {"setDiv", (PyCFunction)SampHold_setDiv, METH_O, "Sets inverse mul factor."},
1293 {NULL} /* Sentinel */
1294 };
1295
1296 static PyNumberMethods SampHold_as_number =
1297 {
1298 (binaryfunc)SampHold_add, /*nb_add*/
1299 (binaryfunc)SampHold_sub, /*nb_subtract*/
1300 (binaryfunc)SampHold_multiply, /*nb_multiply*/
1301 0, /*nb_remainder*/
1302 0, /*nb_divmod*/
1303 0, /*nb_power*/
1304 0, /*nb_neg*/
1305 0, /*nb_pos*/
1306 0, /*(unaryfunc)array_abs,*/
1307 0, /*nb_nonzero*/
1308 0, /*nb_invert*/
1309 0, /*nb_lshift*/
1310 0, /*nb_rshift*/
1311 0, /*nb_and*/
1312 0, /*nb_xor*/
1313 0, /*nb_or*/
1314 0, /*nb_int*/
1315 0, /*nb_long*/
1316 0, /*nb_float*/
1317 (binaryfunc)SampHold_inplace_add, /*inplace_add*/
1318 (binaryfunc)SampHold_inplace_sub, /*inplace_subtract*/
1319 (binaryfunc)SampHold_inplace_multiply, /*inplace_multiply*/
1320 0, /*inplace_remainder*/
1321 0, /*inplace_power*/
1322 0, /*inplace_lshift*/
1323 0, /*inplace_rshift*/
1324 0, /*inplace_and*/
1325 0, /*inplace_xor*/
1326 0, /*inplace_or*/
1327 0, /*nb_floor_divide*/
1328 (binaryfunc)SampHold_div, /*nb_true_divide*/
1329 0, /*nb_inplace_floor_divide*/
1330 (binaryfunc)SampHold_inplace_div, /*nb_inplace_true_divide*/
1331 0, /* nb_index */
1332 };
1333
1334 PyTypeObject SampHoldType =
1335 {
1336 PyVarObject_HEAD_INIT(NULL, 0)
1337 "_pyo.SampHold_base", /*tp_name*/
1338 sizeof(SampHold), /*tp_basicsize*/
1339 0, /*tp_itemsize*/
1340 (destructor)SampHold_dealloc, /*tp_dealloc*/
1341 0, /*tp_print*/
1342 0, /*tp_getattr*/
1343 0, /*tp_setattr*/
1344 0, /*tp_as_async (tp_compare in Python 2)*/
1345 0, /*tp_repr*/
1346 &SampHold_as_number, /*tp_as_number*/
1347 0, /*tp_as_sequence*/
1348 0, /*tp_as_mapping*/
1349 0, /*tp_hash */
1350 0, /*tp_call*/
1351 0, /*tp_str*/
1352 0, /*tp_getattro*/
1353 0, /*tp_setattro*/
1354 0, /*tp_as_buffer*/
1355 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
1356 "SampHold objects. SampHoldolates between 2 audio streams.", /* tp_doc */
1357 (traverseproc)SampHold_traverse, /* tp_traverse */
1358 (inquiry)SampHold_clear, /* tp_clear */
1359 0, /* tp_richcompare */
1360 0, /* tp_weaklistoffset */
1361 0, /* tp_iter */
1362 0, /* tp_iternext */
1363 SampHold_methods, /* tp_methods */
1364 SampHold_members, /* tp_members */
1365 0, /* tp_getset */
1366 0, /* tp_base */
1367 0, /* tp_dict */
1368 0, /* tp_descr_get */
1369 0, /* tp_descr_set */
1370 0, /* tp_dictoffset */
1371 0, /* tp_init */
1372 0, /* tp_alloc */
1373 SampHold_new, /* tp_new */
1374 };
1375
1376 /************/
1377 /* TrackHold */
1378 /************/
1379 typedef struct
1380 {
1381 pyo_audio_HEAD
1382 PyObject *input;
1383 Stream *input_stream;
1384 PyObject *controlsig;
1385 Stream *controlsig_stream;
1386 PyObject *value;
1387 Stream *value_stream;
1388 MYFLT currentValue;
1389 int flag;
1390 int modebuffer[3]; // need at least 2 slots for mul & add
1391 } TrackHold;
1392
1393 static void
1394 TrackHold_filters_i(TrackHold *self)
1395 {
1396 MYFLT ctrl;
1397 int i;
1398 MYFLT *in = Stream_getData((Stream *)self->input_stream);
1399 MYFLT *ctrlsig = Stream_getData((Stream *)self->controlsig_stream);
1400 MYFLT val = PyFloat_AS_DOUBLE(self->value);
1401
1402 for (i = 0; i < self->bufsize; i++)
1403 {
1404 ctrl = ctrlsig[i];
1405
1406 if (ctrl > (val - 0.0001) && ctrl < (val + 0.0001))
1407 {
1408 if (self->flag == 1)
1409 {
1410 self->currentValue = in[i];
1411 self->flag = 0;
1412 }
1413 }
1414 else
1415 {
1416 self->currentValue = in[i];
1417 self->flag = 1;
1418 }
1419
1420 self->data[i] = self->currentValue;
1421 }
1422 }
1423
1424 static void
1425 TrackHold_filters_a(TrackHold *self)
1426 {
1427 MYFLT ctrl, val;
1428 int i;
1429 MYFLT *in = Stream_getData((Stream *)self->input_stream);
1430 MYFLT *ctrlsig = Stream_getData((Stream *)self->controlsig_stream);
1431 MYFLT *valsig = Stream_getData((Stream *)self->value_stream);
1432
1433 for (i = 0; i < self->bufsize; i++)
1434 {
1435 ctrl = ctrlsig[i];
1436 val = valsig[i];
1437
1438 if (ctrl > (val - 0.0001) && ctrl < (val + 0.0001))
1439 {
1440 if (self->flag == 1)
1441 {
1442 self->currentValue = in[i];
1443 self->flag = 0;
1444 }
1445 }
1446 else
1447 {
1448 self->currentValue = in[i];
1449 self->flag = 1;
1450 }
1451
1452 self->data[i] = self->currentValue;
1453 }
1454 }
1455
1456 static void TrackHold_postprocessing_ii(TrackHold *self) { POST_PROCESSING_II };
1457 static void TrackHold_postprocessing_ai(TrackHold *self) { POST_PROCESSING_AI };
1458 static void TrackHold_postprocessing_ia(TrackHold *self) { POST_PROCESSING_IA };
1459 static void TrackHold_postprocessing_aa(TrackHold *self) { POST_PROCESSING_AA };
1460 static void TrackHold_postprocessing_ireva(TrackHold *self) { POST_PROCESSING_IREVA };
1461 static void TrackHold_postprocessing_areva(TrackHold *self) { POST_PROCESSING_AREVA };
1462 static void TrackHold_postprocessing_revai(TrackHold *self) { POST_PROCESSING_REVAI };
1463 static void TrackHold_postprocessing_revaa(TrackHold *self) { POST_PROCESSING_REVAA };
1464 static void TrackHold_postprocessing_revareva(TrackHold *self) { POST_PROCESSING_REVAREVA };
1465
1466 static void
1467 TrackHold_setProcMode(TrackHold *self)
1468 {
1469 int procmode, muladdmode;
1470 procmode = self->modebuffer[2];
1471 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
1472
1473 switch (procmode)
1474 {
1475 case 0:
1476 self->proc_func_ptr = TrackHold_filters_i;
1477 break;
1478
1479 case 1:
1480 self->proc_func_ptr = TrackHold_filters_a;
1481 break;
1482 }
1483
1484 switch (muladdmode)
1485 {
1486 case 0:
1487 self->muladd_func_ptr = TrackHold_postprocessing_ii;
1488 break;
1489
1490 case 1:
1491 self->muladd_func_ptr = TrackHold_postprocessing_ai;
1492 break;
1493
1494 case 2:
1495 self->muladd_func_ptr = TrackHold_postprocessing_revai;
1496 break;
1497
1498 case 10:
1499 self->muladd_func_ptr = TrackHold_postprocessing_ia;
1500 break;
1501
1502 case 11:
1503 self->muladd_func_ptr = TrackHold_postprocessing_aa;
1504 break;
1505
1506 case 12:
1507 self->muladd_func_ptr = TrackHold_postprocessing_revaa;
1508 break;
1509
1510 case 20:
1511 self->muladd_func_ptr = TrackHold_postprocessing_ireva;
1512 break;
1513
1514 case 21:
1515 self->muladd_func_ptr = TrackHold_postprocessing_areva;
1516 break;
1517
1518 case 22:
1519 self->muladd_func_ptr = TrackHold_postprocessing_revareva;
1520 break;
1521 }
1522 }
1523
1524 static void
1525 TrackHold_compute_next_data_frame(TrackHold *self)
1526 {
1527 (*self->proc_func_ptr)(self);
1528 (*self->muladd_func_ptr)(self);
1529 }
1530
1531 static int
1532 TrackHold_traverse(TrackHold *self, visitproc visit, void *arg)
1533 {
1534 pyo_VISIT
1535 Py_VISIT(self->input);
1536 Py_VISIT(self->controlsig);
1537 Py_VISIT(self->value);
1538 return 0;
1539 }
1540
1541 static int
1542 TrackHold_clear(TrackHold *self)
1543 {
1544 pyo_CLEAR
1545 Py_CLEAR(self->input);
1546 Py_CLEAR(self->controlsig);
1547 Py_CLEAR(self->value);
1548 return 0;
1549 }
1550
1551 static void
1552 TrackHold_dealloc(TrackHold* self)
1553 {
1554 pyo_DEALLOC
1555 TrackHold_clear(self);
1556 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
1557 Py_TYPE(self)->tp_free((PyObject*)self);
1558 }
1559
1560 static PyObject *
1561 TrackHold_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1562 {
1563 int i;
1564 PyObject *inputtmp, *input_streamtmp, *controlsigtmp, *controlsig_streamtmp, *valuetmp = NULL, *multmp = NULL, *addtmp = NULL;
1565 TrackHold *self;
1566 self = (TrackHold *)type->tp_alloc(type, 0);
1567
1568 self->value = PyFloat_FromDouble(0.0);
1569 self->currentValue = 0.0;
1570 self->flag = 1;
1571 self->modebuffer[0] = 0;
1572 self->modebuffer[1] = 0;
1573 self->modebuffer[2] = 0;
1574
1575 INIT_OBJECT_COMMON
1576 Stream_setFunctionPtr(self->stream, TrackHold_compute_next_data_frame);
1577 self->mode_func_ptr = TrackHold_setProcMode;
1578
1579 static char *kwlist[] = {"input", "controlsig", "value", "mul", "add", NULL};
1580
1581 if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|OOO", kwlist, &inputtmp, &controlsigtmp, &valuetmp, &multmp, &addtmp))
1582 Py_RETURN_NONE;
1583
1584 INIT_INPUT_STREAM
1585
1586 self->controlsig = controlsigtmp;
1587 Py_INCREF(self->controlsig);
1588 controlsig_streamtmp = PyObject_CallMethod((PyObject *)self->controlsig, "_getStream", NULL);
1589 self->controlsig_stream = (Stream *)controlsig_streamtmp;
1590 Py_INCREF(self->controlsig_stream);
1591
1592 if (valuetmp)
1593 {
1594 PyObject_CallMethod((PyObject *)self, "setValue", "O", valuetmp);
1595 }
1596
1597 if (multmp)
1598 {
1599 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
1600 }
1601
1602 if (addtmp)
1603 {
1604 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
1605 }
1606
1607 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1608
1609 (*self->mode_func_ptr)(self);
1610
1611 return (PyObject *)self;
1612 }
1613
1614 static PyObject * TrackHold_getServer(TrackHold* self) { GET_SERVER };
1615 static PyObject * TrackHold_getStream(TrackHold* self) { GET_STREAM };
1616 static PyObject * TrackHold_setMul(TrackHold *self, PyObject *arg) { SET_MUL };
1617 static PyObject * TrackHold_setAdd(TrackHold *self, PyObject *arg) { SET_ADD };
1618 static PyObject * TrackHold_setSub(TrackHold *self, PyObject *arg) { SET_SUB };
1619 static PyObject * TrackHold_setDiv(TrackHold *self, PyObject *arg) { SET_DIV };
1620
1621 static PyObject * TrackHold_play(TrackHold *self, PyObject *args, PyObject *kwds) { PLAY };
1622 static PyObject * TrackHold_out(TrackHold *self, PyObject *args, PyObject *kwds) { OUT };
1623 static PyObject * TrackHold_stop(TrackHold *self, PyObject *args, PyObject *kwds) { STOP };
1624
1625 static PyObject * TrackHold_multiply(TrackHold *self, PyObject *arg) { MULTIPLY };
1626 static PyObject * TrackHold_inplace_multiply(TrackHold *self, PyObject *arg) { INPLACE_MULTIPLY };
1627 static PyObject * TrackHold_add(TrackHold *self, PyObject *arg) { ADD };
1628 static PyObject * TrackHold_inplace_add(TrackHold *self, PyObject *arg) { INPLACE_ADD };
1629 static PyObject * TrackHold_sub(TrackHold *self, PyObject *arg) { SUB };
1630 static PyObject * TrackHold_inplace_sub(TrackHold *self, PyObject *arg) { INPLACE_SUB };
1631 static PyObject * TrackHold_div(TrackHold *self, PyObject *arg) { DIV };
1632 static PyObject * TrackHold_inplace_div(TrackHold *self, PyObject *arg) { INPLACE_DIV };
1633
1634 static PyObject * TrackHold_setValue(TrackHold *self, PyObject *arg) { SET_PARAM(self->value, self->value_stream, 2); }
1635
1636 static PyMemberDef TrackHold_members[] =
1637 {
1638 {"server", T_OBJECT_EX, offsetof(TrackHold, server), 0, "Pyo server."},
1639 {"stream", T_OBJECT_EX, offsetof(TrackHold, stream), 0, "Stream object."},
1640 {"input", T_OBJECT_EX, offsetof(TrackHold, input), 0, "Input sound object."},
1641 {"controlsig", T_OBJECT_EX, offsetof(TrackHold, controlsig), 0, "Control input object."},
1642 {"value", T_OBJECT_EX, offsetof(TrackHold, value), 0, "Trigger value."},
1643 {"mul", T_OBJECT_EX, offsetof(TrackHold, mul), 0, "Mul factor."},
1644 {"add", T_OBJECT_EX, offsetof(TrackHold, add), 0, "Add factor."},
1645 {NULL} /* Sentinel */
1646 };
1647
1648 static PyMethodDef TrackHold_methods[] =
1649 {
1650 {"getServer", (PyCFunction)TrackHold_getServer, METH_NOARGS, "Returns server object."},
1651 {"_getStream", (PyCFunction)TrackHold_getStream, METH_NOARGS, "Returns stream object."},
1652 {"play", (PyCFunction)TrackHold_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1653 {"out", (PyCFunction)TrackHold_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
1654 {"stop", (PyCFunction)TrackHold_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
1655 {"setValue", (PyCFunction)TrackHold_setValue, METH_O, "Sets trigger value."},
1656 {"setMul", (PyCFunction)TrackHold_setMul, METH_O, "Sets oscillator mul factor."},
1657 {"setAdd", (PyCFunction)TrackHold_setAdd, METH_O, "Sets oscillator add factor."},
1658 {"setSub", (PyCFunction)TrackHold_setSub, METH_O, "Sets inverse add factor."},
1659 {"setDiv", (PyCFunction)TrackHold_setDiv, METH_O, "Sets inverse mul factor."},
1660 {NULL} /* Sentinel */
1661 };
1662
1663 static PyNumberMethods TrackHold_as_number =
1664 {
1665 (binaryfunc)TrackHold_add, /*nb_add*/
1666 (binaryfunc)TrackHold_sub, /*nb_subtract*/
1667 (binaryfunc)TrackHold_multiply, /*nb_multiply*/
1668 0, /*nb_remainder*/
1669 0, /*nb_divmod*/
1670 0, /*nb_power*/
1671 0, /*nb_neg*/
1672 0, /*nb_pos*/
1673 0, /*(unaryfunc)array_abs,*/
1674 0, /*nb_nonzero*/
1675 0, /*nb_invert*/
1676 0, /*nb_lshift*/
1677 0, /*nb_rshift*/
1678 0, /*nb_and*/
1679 0, /*nb_xor*/
1680 0, /*nb_or*/
1681 0, /*nb_int*/
1682 0, /*nb_long*/
1683 0, /*nb_float*/
1684 (binaryfunc)TrackHold_inplace_add, /*inplace_add*/
1685 (binaryfunc)TrackHold_inplace_sub, /*inplace_subtract*/
1686 (binaryfunc)TrackHold_inplace_multiply, /*inplace_multiply*/
1687 0, /*inplace_remainder*/
1688 0, /*inplace_power*/
1689 0, /*inplace_lshift*/
1690 0, /*inplace_rshift*/
1691 0, /*inplace_and*/
1692 0, /*inplace_xor*/
1693 0, /*inplace_or*/
1694 0, /*nb_floor_divide*/
1695 (binaryfunc)TrackHold_div, /*nb_true_divide*/
1696 0, /*nb_inplace_floor_divide*/
1697 (binaryfunc)TrackHold_inplace_div, /*nb_inplace_true_divide*/
1698 0, /* nb_index */
1699 };
1700
1701 PyTypeObject TrackHoldType =
1702 {
1703 PyVarObject_HEAD_INIT(NULL, 0)
1704 "_pyo.TrackHold_base", /*tp_name*/
1705 sizeof(TrackHold), /*tp_basicsize*/
1706 0, /*tp_itemsize*/
1707 (destructor)TrackHold_dealloc, /*tp_dealloc*/
1708 0, /*tp_print*/
1709 0, /*tp_getattr*/
1710 0, /*tp_setattr*/
1711 0, /*tp_as_async (tp_compare in Python 2)*/
1712 0, /*tp_repr*/
1713 &TrackHold_as_number, /*tp_as_number*/
1714 0, /*tp_as_sequence*/
1715 0, /*tp_as_mapping*/
1716 0, /*tp_hash */
1717 0, /*tp_call*/
1718 0, /*tp_str*/
1719 0, /*tp_getattro*/
1720 0, /*tp_setattro*/
1721 0, /*tp_as_buffer*/
1722 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
1723 "TrackHold objects. Let pass and freeze an audio stream.", /* tp_doc */
1724 (traverseproc)TrackHold_traverse, /* tp_traverse */
1725 (inquiry)TrackHold_clear, /* tp_clear */
1726 0, /* tp_richcompare */
1727 0, /* tp_weaklistoffset */
1728 0, /* tp_iter */
1729 0, /* tp_iternext */
1730 TrackHold_methods, /* tp_methods */
1731 TrackHold_members, /* tp_members */
1732 0, /* tp_getset */
1733 0, /* tp_base */
1734 0, /* tp_dict */
1735 0, /* tp_descr_get */
1736 0, /* tp_descr_set */
1737 0, /* tp_dictoffset */
1738 0, /* tp_init */
1739 0, /* tp_alloc */
1740 TrackHold_new, /* tp_new */
1741 };
1742
1743 /************/
1744 /* Compare */
1745 /************/
1746 typedef struct
1747 {
1748 pyo_audio_HEAD
1749 PyObject *input;
1750 Stream *input_stream;
1751 PyObject *comp;
1752 Stream *comp_stream;
1753 MYFLT (*compare_func_ptr)(MYFLT, MYFLT); // true = 1.0, false = 0.0
1754 int modebuffer[3]; // need at least 2 slots for mul & add
1755 } Compare;
1756
1757 static MYFLT
1758 Compare_lt(MYFLT in, MYFLT comp)
1759 {
1760 if (in < comp) { return 1.0; }
1761 else { return 0.0; }
1762 }
1763
1764 static MYFLT
1765 Compare_elt(MYFLT in, MYFLT comp)
1766 {
1767 if (in <= comp) { return 1.0; }
1768 else { return 0.0; }
1769 }
1770
1771 static MYFLT
1772 Compare_gt(MYFLT in, MYFLT comp)
1773 {
1774 if (in > comp) { return 1.0; }
1775 else { return 0.0; }
1776 }
1777
1778 static MYFLT
1779 Compare_egt(MYFLT in, MYFLT comp)
1780 {
1781 if (in >= comp) { return 1.0; }
1782 else { return 0.0; }
1783 }
1784
1785 static MYFLT
1786 Compare_eq(MYFLT in, MYFLT comp)
1787 {
1788 if (in >= (comp - 0.0001) && in <= (comp + 0.0001)) { return 1.0; }
1789 else { return 0.0; }
1790 }
1791
1792 static MYFLT
1793 Compare_neq(MYFLT in, MYFLT comp)
1794 {
1795 if (in <= (comp - 0.0001) || in >= (comp + 0.0001)) { return 1.0; }
1796 else { return 0.0; }
1797 }
1798
1799 static void
1800 Compare_process_i(Compare *self)
1801 {
1802 int i;
1803 MYFLT *in = Stream_getData((Stream *)self->input_stream);
1804 MYFLT comp = PyFloat_AS_DOUBLE(self->comp);
1805
1806 for (i = 0; i < self->bufsize; i++)
1807 {
1808 self->data[i] = (*self->compare_func_ptr)(in[i], comp);
1809 }
1810 }
1811
1812 static void
1813 Compare_process_a(Compare *self)
1814 {
1815 int i;
1816 MYFLT *in = Stream_getData((Stream *)self->input_stream);
1817 MYFLT *comp = Stream_getData((Stream *)self->comp_stream);
1818
1819 for (i = 0; i < self->bufsize; i++)
1820 {
1821 self->data[i] = (*self->compare_func_ptr)(in[i], comp[i]);
1822 }
1823 }
1824
1825 static void Compare_postprocessing_ii(Compare *self) { POST_PROCESSING_II };
1826 static void Compare_postprocessing_ai(Compare *self) { POST_PROCESSING_AI };
1827 static void Compare_postprocessing_ia(Compare *self) { POST_PROCESSING_IA };
1828 static void Compare_postprocessing_aa(Compare *self) { POST_PROCESSING_AA };
1829 static void Compare_postprocessing_ireva(Compare *self) { POST_PROCESSING_IREVA };
1830 static void Compare_postprocessing_areva(Compare *self) { POST_PROCESSING_AREVA };
1831 static void Compare_postprocessing_revai(Compare *self) { POST_PROCESSING_REVAI };
1832 static void Compare_postprocessing_revaa(Compare *self) { POST_PROCESSING_REVAA };
1833 static void Compare_postprocessing_revareva(Compare *self) { POST_PROCESSING_REVAREVA };
1834
1835 static void
1836 Compare_setProcMode(Compare *self)
1837 {
1838 int procmode, muladdmode;
1839 procmode = self->modebuffer[2];
1840 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
1841
1842 switch (procmode)
1843 {
1844 case 0:
1845 self->proc_func_ptr = Compare_process_i;
1846 break;
1847
1848 case 1:
1849 self->proc_func_ptr = Compare_process_a;
1850 break;
1851 }
1852
1853 switch (muladdmode)
1854 {
1855 case 0:
1856 self->muladd_func_ptr = Compare_postprocessing_ii;
1857 break;
1858
1859 case 1:
1860 self->muladd_func_ptr = Compare_postprocessing_ai;
1861 break;
1862
1863 case 2:
1864 self->muladd_func_ptr = Compare_postprocessing_revai;
1865 break;
1866
1867 case 10:
1868 self->muladd_func_ptr = Compare_postprocessing_ia;
1869 break;
1870
1871 case 11:
1872 self->muladd_func_ptr = Compare_postprocessing_aa;
1873 break;
1874
1875 case 12:
1876 self->muladd_func_ptr = Compare_postprocessing_revaa;
1877 break;
1878
1879 case 20:
1880 self->muladd_func_ptr = Compare_postprocessing_ireva;
1881 break;
1882
1883 case 21:
1884 self->muladd_func_ptr = Compare_postprocessing_areva;
1885 break;
1886
1887 case 22:
1888 self->muladd_func_ptr = Compare_postprocessing_revareva;
1889 break;
1890 }
1891 }
1892
1893 static void
1894 Compare_compute_next_data_frame(Compare *self)
1895 {
1896 (*self->proc_func_ptr)(self);
1897 (*self->muladd_func_ptr)(self);
1898 }
1899
1900 static int
1901 Compare_traverse(Compare *self, visitproc visit, void *arg)
1902 {
1903 pyo_VISIT
1904 Py_VISIT(self->input);
1905 Py_VISIT(self->comp);
1906 return 0;
1907 }
1908
1909 static int
1910 Compare_clear(Compare *self)
1911 {
1912 pyo_CLEAR
1913 Py_CLEAR(self->input);
1914 Py_CLEAR(self->comp);
1915 return 0;
1916 }
1917
1918 static void
1919 Compare_dealloc(Compare* self)
1920 {
1921 pyo_DEALLOC
1922 Compare_clear(self);
1923 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
1924 Py_TYPE(self)->tp_free((PyObject*)self);
1925 }
1926
1927 static PyObject *
1928 Compare_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1929 {
1930 int i;
1931 PyObject *inputtmp, *input_streamtmp, *comptmp, *modetmp = NULL, *multmp = NULL, *addtmp = NULL;
1932 Compare *self;
1933 self = (Compare *)type->tp_alloc(type, 0);
1934
1935 self->comp = PyFloat_FromDouble(0.0);
1936 self->modebuffer[0] = 0;
1937 self->modebuffer[1] = 0;
1938 self->modebuffer[2] = 0;
1939
1940 self->compare_func_ptr = Compare_lt;
1941
1942 INIT_OBJECT_COMMON
1943 Stream_setFunctionPtr(self->stream, Compare_compute_next_data_frame);
1944 self->mode_func_ptr = Compare_setProcMode;
1945
1946 static char *kwlist[] = {"input", "comp", "mode", "mul", "add", NULL};
1947
1948 if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|OOO", kwlist, &inputtmp, &comptmp, &modetmp, &multmp, &addtmp))
1949 Py_RETURN_NONE;
1950
1951 INIT_INPUT_STREAM
1952
1953 if (comptmp)
1954 {
1955 PyObject_CallMethod((PyObject *)self, "setComp", "O", comptmp);
1956 }
1957
1958 if (modetmp)
1959 {
1960 PyObject_CallMethod((PyObject *)self, "setMode", "O", modetmp);
1961 }
1962
1963 if (multmp)
1964 {
1965 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
1966 }
1967
1968 if (addtmp)
1969 {
1970 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
1971 }
1972
1973 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1974
1975 (*self->mode_func_ptr)(self);
1976
1977 return (PyObject *)self;
1978 }
1979
1980 static PyObject * Compare_getServer(Compare* self) { GET_SERVER };
1981 static PyObject * Compare_getStream(Compare* self) { GET_STREAM };
1982 static PyObject * Compare_setMul(Compare *self, PyObject *arg) { SET_MUL };
1983 static PyObject * Compare_setAdd(Compare *self, PyObject *arg) { SET_ADD };
1984 static PyObject * Compare_setSub(Compare *self, PyObject *arg) { SET_SUB };
1985 static PyObject * Compare_setDiv(Compare *self, PyObject *arg) { SET_DIV };
1986
1987 static PyObject * Compare_play(Compare *self, PyObject *args, PyObject *kwds) { PLAY };
1988 static PyObject * Compare_stop(Compare *self, PyObject *args, PyObject *kwds) { STOP };
1989
1990 static PyObject * Compare_multiply(Compare *self, PyObject *arg) { MULTIPLY };
1991 static PyObject * Compare_inplace_multiply(Compare *self, PyObject *arg) { INPLACE_MULTIPLY };
1992 static PyObject * Compare_add(Compare *self, PyObject *arg) { ADD };
1993 static PyObject * Compare_inplace_add(Compare *self, PyObject *arg) { INPLACE_ADD };
1994 static PyObject * Compare_sub(Compare *self, PyObject *arg) { SUB };
1995 static PyObject * Compare_inplace_sub(Compare *self, PyObject *arg) { INPLACE_SUB };
1996 static PyObject * Compare_div(Compare *self, PyObject *arg) { DIV };
1997 static PyObject * Compare_inplace_div(Compare *self, PyObject *arg) { INPLACE_DIV };
1998
1999 static PyObject * Compare_setComp(Compare *self, PyObject *arg) { SET_PARAM(self->comp, self->comp_stream, 2); }
2000
2001 static PyObject *
2002 Compare_setMode(Compare *self, PyObject *arg)
2003 {
2004 ASSERT_ARG_NOT_NULL
2005
2006 if (! PyLong_Check(arg))
2007 {
2008 PySys_WriteStdout("Compare: mode attribute should be a comparison operator as a string\n");
2009 Py_RETURN_NONE;
2010 }
2011
2012 int tmp = PyLong_AsLong(arg);
2013
2014 if (tmp == 0)
2015 self->compare_func_ptr = Compare_lt;
2016 else if (tmp == 1)
2017 self->compare_func_ptr = Compare_elt;
2018 else if (tmp == 2)
2019 self->compare_func_ptr = Compare_gt;
2020 else if (tmp == 3)
2021 self->compare_func_ptr = Compare_egt;
2022 else if (tmp == 4)
2023 self->compare_func_ptr = Compare_eq;
2024 else if (tmp == 5)
2025 self->compare_func_ptr = Compare_neq;
2026
2027 Py_RETURN_NONE;
2028 }
2029
2030 static PyMemberDef Compare_members[] =
2031 {
2032 {"server", T_OBJECT_EX, offsetof(Compare, server), 0, "Pyo server."},
2033 {"stream", T_OBJECT_EX, offsetof(Compare, stream), 0, "Stream object."},
2034 {"input", T_OBJECT_EX, offsetof(Compare, input), 0, "Input sound object."},
2035 {"comp", T_OBJECT_EX, offsetof(Compare, comp), 0, "Comparison object."},
2036 {"mul", T_OBJECT_EX, offsetof(Compare, mul), 0, "Mul factor."},
2037 {"add", T_OBJECT_EX, offsetof(Compare, add), 0, "Add factor."},
2038 {NULL} /* Sentinel */
2039 };
2040
2041 static PyMethodDef Compare_methods[] =
2042 {
2043 {"getServer", (PyCFunction)Compare_getServer, METH_NOARGS, "Returns server object."},
2044 {"_getStream", (PyCFunction)Compare_getStream, METH_NOARGS, "Returns stream object."},
2045 {"play", (PyCFunction)Compare_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
2046 {"stop", (PyCFunction)Compare_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
2047 {"setComp", (PyCFunction)Compare_setComp, METH_O, "Sets the comparison object."},
2048 {"setMode", (PyCFunction)Compare_setMode, METH_O, "Sets the comparison mode."},
2049 {"setMul", (PyCFunction)Compare_setMul, METH_O, "Sets mul factor."},
2050 {"setAdd", (PyCFunction)Compare_setAdd, METH_O, "Sets add factor."},
2051 {"setSub", (PyCFunction)Compare_setSub, METH_O, "Sets inverse add factor."},
2052 {"setDiv", (PyCFunction)Compare_setDiv, METH_O, "Sets inverse mul factor."},
2053 {NULL} /* Sentinel */
2054 };
2055
2056 static PyNumberMethods Compare_as_number =
2057 {
2058 (binaryfunc)Compare_add, /*nb_add*/
2059 (binaryfunc)Compare_sub, /*nb_subtract*/
2060 (binaryfunc)Compare_multiply, /*nb_multiply*/
2061 0, /*nb_remainder*/
2062 0, /*nb_divmod*/
2063 0, /*nb_power*/
2064 0, /*nb_neg*/
2065 0, /*nb_pos*/
2066 0, /*(unaryfunc)array_abs,*/
2067 0, /*nb_nonzero*/
2068 0, /*nb_invert*/
2069 0, /*nb_lshift*/
2070 0, /*nb_rshift*/
2071 0, /*nb_and*/
2072 0, /*nb_xor*/
2073 0, /*nb_or*/
2074 0, /*nb_int*/
2075 0, /*nb_long*/
2076 0, /*nb_float*/
2077 (binaryfunc)Compare_inplace_add, /*inplace_add*/
2078 (binaryfunc)Compare_inplace_sub, /*inplace_subtract*/
2079 (binaryfunc)Compare_inplace_multiply, /*inplace_multiply*/
2080 0, /*inplace_remainder*/
2081 0, /*inplace_power*/
2082 0, /*inplace_lshift*/
2083 0, /*inplace_rshift*/
2084 0, /*inplace_and*/
2085 0, /*inplace_xor*/
2086 0, /*inplace_or*/
2087 0, /*nb_floor_divide*/
2088 (binaryfunc)Compare_div, /*nb_true_divide*/
2089 0, /*nb_inplace_floor_divide*/
2090 (binaryfunc)Compare_inplace_div, /*nb_inplace_true_divide*/
2091 0, /* nb_index */
2092 };
2093
2094 PyTypeObject CompareType =
2095 {
2096 PyVarObject_HEAD_INIT(NULL, 0)
2097 "_pyo.Compare_base", /*tp_name*/
2098 sizeof(Compare), /*tp_basicsize*/
2099 0, /*tp_itemsize*/
2100 (destructor)Compare_dealloc, /*tp_dealloc*/
2101 0, /*tp_print*/
2102 0, /*tp_getattr*/
2103 0, /*tp_setattr*/
2104 0, /*tp_as_async (tp_compare in Python 2)*/
2105 0, /*tp_repr*/
2106 &Compare_as_number, /*tp_as_number*/
2107 0, /*tp_as_sequence*/
2108 0, /*tp_as_mapping*/
2109 0, /*tp_hash */
2110 0, /*tp_call*/
2111 0, /*tp_str*/
2112 0, /*tp_getattro*/
2113 0, /*tp_setattro*/
2114 0, /*tp_as_buffer*/
2115 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
2116 "Compare objects. Comparison between 2 audio streams.", /* tp_doc */
2117 (traverseproc)Compare_traverse, /* tp_traverse */
2118 (inquiry)Compare_clear, /* tp_clear */
2119 0, /* tp_richcompare */
2120 0, /* tp_weaklistoffset */
2121 0, /* tp_iter */
2122 0, /* tp_iternext */
2123 Compare_methods, /* tp_methods */
2124 Compare_members, /* tp_members */
2125 0, /* tp_getset */
2126 0, /* tp_base */
2127 0, /* tp_dict */
2128 0, /* tp_descr_get */
2129 0, /* tp_descr_set */
2130 0, /* tp_dictoffset */
2131 0, /* tp_init */
2132 0, /* tp_alloc */
2133 Compare_new, /* tp_new */
2134 };
2135
2136 /*****************/
2137 /** Between object **/
2138 /*****************/
2139
2140 typedef struct
2141 {
2142 pyo_audio_HEAD
2143 PyObject *input;
2144 Stream *input_stream;
2145 PyObject *min;
2146 Stream *min_stream;
2147 PyObject *max;
2148 Stream *max_stream;
2149 int modebuffer[4];
2150 } Between;
2151
2152 static void
2153 Between_transform_ii(Between *self)
2154 {
2155 MYFLT val;
2156 int i;
2157 MYFLT *in = Stream_getData((Stream *)self->input_stream);
2158 MYFLT mi = PyFloat_AS_DOUBLE(self->min);
2159 MYFLT ma = PyFloat_AS_DOUBLE(self->max);
2160
2161 for (i = 0; i < self->bufsize; i++)
2162 {
2163 val = in[i];
2164
2165 if(val >= mi && val < ma)
2166 self->data[i] = 1.0;
2167 else
2168 self->data[i] = 0.0;
2169 }
2170 }
2171
2172 static void
2173 Between_transform_ai(Between *self)
2174 {
2175 MYFLT val;
2176 int i;
2177 MYFLT *in = Stream_getData((Stream *)self->input_stream);
2178 MYFLT *mi = Stream_getData((Stream *)self->min_stream);
2179 MYFLT ma = PyFloat_AS_DOUBLE(self->max);
2180
2181 for (i = 0; i < self->bufsize; i++)
2182 {
2183 val = in[i];
2184
2185 if(val >= mi[i] && val < ma)
2186 self->data[i] = 1.0;
2187 else
2188 self->data[i] = 0.0;
2189 }
2190 }
2191
2192 static void
2193 Between_transform_ia(Between *self)
2194 {
2195 MYFLT val;
2196 int i;
2197 MYFLT *in = Stream_getData((Stream *)self->input_stream);
2198 MYFLT mi = PyFloat_AS_DOUBLE(self->min);
2199 MYFLT *ma = Stream_getData((Stream *)self->max_stream);
2200
2201 for (i = 0; i < self->bufsize; i++)
2202 {
2203 val = in[i];
2204
2205 if(val >= mi && val < ma[i])
2206 self->data[i] = 1.0;
2207 else
2208 self->data[i] = 0.0;
2209 }
2210 }
2211
2212 static void
2213 Between_transform_aa(Between *self)
2214 {
2215 MYFLT val;
2216 int i;
2217 MYFLT *in = Stream_getData((Stream *)self->input_stream);
2218 MYFLT *mi = Stream_getData((Stream *)self->min_stream);
2219 MYFLT *ma = Stream_getData((Stream *)self->max_stream);
2220
2221 for (i = 0; i < self->bufsize; i++)
2222 {
2223 val = in[i];
2224
2225 if(val >= mi[i] && val < ma[i])
2226 self->data[i] = 1.0;
2227 else
2228 self->data[i] = 0.0;
2229 }
2230 }
2231
2232 static void Between_postprocessing_ii(Between *self) { POST_PROCESSING_II };
2233 static void Between_postprocessing_ai(Between *self) { POST_PROCESSING_AI };
2234 static void Between_postprocessing_ia(Between *self) { POST_PROCESSING_IA };
2235 static void Between_postprocessing_aa(Between *self) { POST_PROCESSING_AA };
2236 static void Between_postprocessing_ireva(Between *self) { POST_PROCESSING_IREVA };
2237 static void Between_postprocessing_areva(Between *self) { POST_PROCESSING_AREVA };
2238 static void Between_postprocessing_revai(Between *self) { POST_PROCESSING_REVAI };
2239 static void Between_postprocessing_revaa(Between *self) { POST_PROCESSING_REVAA };
2240 static void Between_postprocessing_revareva(Between *self) { POST_PROCESSING_REVAREVA };
2241
2242 static void
2243 Between_setProcMode(Between *self)
2244 {
2245 int procmode, muladdmode;
2246 procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
2247 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
2248
2249 switch (procmode)
2250 {
2251 case 0:
2252 self->proc_func_ptr = Between_transform_ii;
2253 break;
2254
2255 case 1:
2256 self->proc_func_ptr = Between_transform_ai;
2257 break;
2258
2259 case 10:
2260 self->proc_func_ptr = Between_transform_ia;
2261 break;
2262
2263 case 11:
2264 self->proc_func_ptr = Between_transform_aa;
2265 break;
2266 }
2267
2268 switch (muladdmode)
2269 {
2270 case 0:
2271 self->muladd_func_ptr = Between_postprocessing_ii;
2272 break;
2273
2274 case 1:
2275 self->muladd_func_ptr = Between_postprocessing_ai;
2276 break;
2277
2278 case 2:
2279 self->muladd_func_ptr = Between_postprocessing_revai;
2280 break;
2281
2282 case 10:
2283 self->muladd_func_ptr = Between_postprocessing_ia;
2284 break;
2285
2286 case 11:
2287 self->muladd_func_ptr = Between_postprocessing_aa;
2288 break;
2289
2290 case 12:
2291 self->muladd_func_ptr = Between_postprocessing_revaa;
2292 break;
2293
2294 case 20:
2295 self->muladd_func_ptr = Between_postprocessing_ireva;
2296 break;
2297
2298 case 21:
2299 self->muladd_func_ptr = Between_postprocessing_areva;
2300 break;
2301
2302 case 22:
2303 self->muladd_func_ptr = Between_postprocessing_revareva;
2304 break;
2305 }
2306 }
2307
2308 static void
2309 Between_compute_next_data_frame(Between *self)
2310 {
2311 (*self->proc_func_ptr)(self);
2312 (*self->muladd_func_ptr)(self);
2313 }
2314
2315 static int
2316 Between_traverse(Between *self, visitproc visit, void *arg)
2317 {
2318 pyo_VISIT
2319 Py_VISIT(self->input);
2320 Py_VISIT(self->min);
2321 Py_VISIT(self->max);
2322 return 0;
2323 }
2324
2325 static int
2326 Between_clear(Between *self)
2327 {
2328 pyo_CLEAR
2329 Py_CLEAR(self->input);
2330 Py_CLEAR(self->min);
2331 Py_CLEAR(self->max);
2332 return 0;
2333 }
2334
2335 static void
2336 Between_dealloc(Between* self)
2337 {
2338 pyo_DEALLOC
2339 Between_clear(self);
2340 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
2341 Py_TYPE(self)->tp_free((PyObject*)self);
2342 }
2343
2344 static PyObject *
2345 Between_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2346 {
2347 int i;
2348 PyObject *inputtmp, *input_streamtmp, *mintmp = NULL, *maxtmp = NULL, *multmp = NULL, *addtmp = NULL;
2349 Between *self;
2350 self = (Between *)type->tp_alloc(type, 0);
2351
2352 self->min = PyFloat_FromDouble(0.0);
2353 self->max = PyFloat_FromDouble(1.0);
2354 self->modebuffer[0] = 0;
2355 self->modebuffer[1] = 0;
2356 self->modebuffer[2] = 0;
2357 self->modebuffer[3] = 0;
2358
2359 INIT_OBJECT_COMMON
2360 Stream_setFunctionPtr(self->stream, Between_compute_next_data_frame);
2361 self->mode_func_ptr = Between_setProcMode;
2362
2363 static char *kwlist[] = {"input", "min", "max", "mul", "add", NULL};
2364
2365 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OOOO", kwlist, &inputtmp, &mintmp, &maxtmp, &multmp, &addtmp))
2366 Py_RETURN_NONE;
2367
2368 INIT_INPUT_STREAM
2369
2370 if (mintmp)
2371 {
2372 PyObject_CallMethod((PyObject *)self, "setMin", "O", mintmp);
2373 }
2374
2375 if (maxtmp)
2376 {
2377 PyObject_CallMethod((PyObject *)self, "setMax", "O", maxtmp);
2378 }
2379
2380 if (multmp)
2381 {
2382 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
2383 }
2384
2385 if (addtmp)
2386 {
2387 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
2388 }
2389
2390 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
2391
2392 (*self->mode_func_ptr)(self);
2393
2394 return (PyObject *)self;
2395 }
2396
2397 static PyObject * Between_getServer(Between* self) { GET_SERVER };
2398 static PyObject * Between_getStream(Between* self) { GET_STREAM };
2399 static PyObject * Between_setMul(Between *self, PyObject *arg) { SET_MUL };
2400 static PyObject * Between_setAdd(Between *self, PyObject *arg) { SET_ADD };
2401 static PyObject * Between_setSub(Between *self, PyObject *arg) { SET_SUB };
2402 static PyObject * Between_setDiv(Between *self, PyObject *arg) { SET_DIV };
2403
2404 static PyObject * Between_play(Between *self, PyObject *args, PyObject *kwds) { PLAY };
2405 static PyObject * Between_out(Between *self, PyObject *args, PyObject *kwds) { OUT };
2406 static PyObject * Between_stop(Between *self, PyObject *args, PyObject *kwds) { STOP };
2407
2408 static PyObject * Between_multiply(Between *self, PyObject *arg) { MULTIPLY };
2409 static PyObject * Between_inplace_multiply(Between *self, PyObject *arg) { INPLACE_MULTIPLY };
2410 static PyObject * Between_add(Between *self, PyObject *arg) { ADD };
2411 static PyObject * Between_inplace_add(Between *self, PyObject *arg) { INPLACE_ADD };
2412 static PyObject * Between_sub(Between *self, PyObject *arg) { SUB };
2413 static PyObject * Between_inplace_sub(Between *self, PyObject *arg) { INPLACE_SUB };
2414 static PyObject * Between_div(Between *self, PyObject *arg) { DIV };
2415 static PyObject * Between_inplace_div(Between *self, PyObject *arg) { INPLACE_DIV };
2416
2417 static PyObject * Between_setMin(Between *self, PyObject *arg) { SET_PARAM(self->min, self->min_stream, 2); }
2418 static PyObject * Between_setMax(Between *self, PyObject *arg) { SET_PARAM(self->max, self->max_stream, 3); }
2419
2420 static PyMemberDef Between_members[] =
2421 {
2422 {"server", T_OBJECT_EX, offsetof(Between, server), 0, "Pyo server."},
2423 {"stream", T_OBJECT_EX, offsetof(Between, stream), 0, "Stream object."},
2424 {"input", T_OBJECT_EX, offsetof(Between, input), 0, "Input sound object."},
2425 {"min", T_OBJECT_EX, offsetof(Between, min), 0, "Minimum possible value."},
2426 {"max", T_OBJECT_EX, offsetof(Between, max), 0, "Maximum possible value."},
2427 {"mul", T_OBJECT_EX, offsetof(Between, mul), 0, "Mul factor."},
2428 {"add", T_OBJECT_EX, offsetof(Between, add), 0, "Add factor."},
2429 {NULL} /* Sentinel */
2430 };
2431
2432 static PyMethodDef Between_methods[] =
2433 {
2434 {"getServer", (PyCFunction)Between_getServer, METH_NOARGS, "Returns server object."},
2435 {"_getStream", (PyCFunction)Between_getStream, METH_NOARGS, "Returns stream object."},
2436 {"play", (PyCFunction)Between_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
2437 {"out", (PyCFunction)Between_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
2438 {"stop", (PyCFunction)Between_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
2439 {"setMin", (PyCFunction)Between_setMin, METH_O, "Sets the minimum value."},
2440 {"setMax", (PyCFunction)Between_setMax, METH_O, "Sets the maximum value."},
2441 {"setMul", (PyCFunction)Between_setMul, METH_O, "Sets oscillator mul factor."},
2442 {"setAdd", (PyCFunction)Between_setAdd, METH_O, "Sets oscillator add factor."},
2443 {"setSub", (PyCFunction)Between_setSub, METH_O, "Sets inverse add factor."},
2444 {"setDiv", (PyCFunction)Between_setDiv, METH_O, "Sets inverse mul factor."},
2445 {NULL} /* Sentinel */
2446 };
2447
2448 static PyNumberMethods Between_as_number =
2449 {
2450 (binaryfunc)Between_add, /*nb_add*/
2451 (binaryfunc)Between_sub, /*nb_subtract*/
2452 (binaryfunc)Between_multiply, /*nb_multiply*/
2453 0, /*nb_remainder*/
2454 0, /*nb_divmod*/
2455 0, /*nb_power*/
2456 0, /*nb_neg*/
2457 0, /*nb_pos*/
2458 0, /*(unaryfunc)array_abs,*/
2459 0, /*nb_nonzero*/
2460 0, /*nb_invert*/
2461 0, /*nb_lshift*/
2462 0, /*nb_rshift*/
2463 0, /*nb_and*/
2464 0, /*nb_xor*/
2465 0, /*nb_or*/
2466 0, /*nb_int*/
2467 0, /*nb_long*/
2468 0, /*nb_float*/
2469 (binaryfunc)Between_inplace_add, /*inplace_add*/
2470 (binaryfunc)Between_inplace_sub, /*inplace_subtract*/
2471 (binaryfunc)Between_inplace_multiply, /*inplace_multiply*/
2472 0, /*inplace_remainder*/
2473 0, /*inplace_power*/
2474 0, /*inplace_lshift*/
2475 0, /*inplace_rshift*/
2476 0, /*inplace_and*/
2477 0, /*inplace_xor*/
2478 0, /*inplace_or*/
2479 0, /*nb_floor_divide*/
2480 (binaryfunc)Between_div, /*nb_true_divide*/
2481 0, /*nb_inplace_floor_divide*/
2482 (binaryfunc)Between_inplace_div, /*nb_inplace_true_divide*/
2483 0, /* nb_index */
2484 };
2485
2486 PyTypeObject BetweenType =
2487 {
2488 PyVarObject_HEAD_INIT(NULL, 0)
2489 "_pyo.Between_base", /*tp_name*/
2490 sizeof(Between), /*tp_basicsize*/
2491 0, /*tp_itemsize*/
2492 (destructor)Between_dealloc, /*tp_dealloc*/
2493 0, /*tp_print*/
2494 0, /*tp_getattr*/
2495 0, /*tp_setattr*/
2496 0, /*tp_as_async (tp_compare in Python 2)*/
2497 0, /*tp_repr*/
2498 &Between_as_number, /*tp_as_number*/
2499 0, /*tp_as_sequence*/
2500 0, /*tp_as_mapping*/
2501 0, /*tp_hash */
2502 0, /*tp_call*/
2503 0, /*tp_str*/
2504 0, /*tp_getattro*/
2505 0, /*tp_setattro*/
2506 0, /*tp_as_buffer*/
2507 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
2508 "Between objects. Outputs a trig if signal is between min and max values.", /* tp_doc */
2509 (traverseproc)Between_traverse, /* tp_traverse */
2510 (inquiry)Between_clear, /* tp_clear */
2511 0, /* tp_richcompare */
2512 0, /* tp_weaklistoffset */
2513 0, /* tp_iter */
2514 0, /* tp_iternext */
2515 Between_methods, /* tp_methods */
2516 Between_members, /* tp_members */
2517 0, /* tp_getset */
2518 0, /* tp_base */
2519 0, /* tp_dict */
2520 0, /* tp_descr_get */
2521 0, /* tp_descr_set */
2522 0, /* tp_dictoffset */
2523 0, /* tp_init */
2524 0, /* tp_alloc */
2525 Between_new, /* tp_new */
2526 };
2527
2528
2529 /************/
2530 /* Denorm */
2531 /************/
2532 #ifndef USE_DOUBLE
2533 #define DENORM_RAND ((MYFLT) ((pyorand()/((MYFLT)(PYO_RAND_MAX)*0.5+1) - 1.0) * (MYFLT)(1.0e-24)))
2534 #else
2535 #define DENORM_RAND ((MYFLT) ((pyorand()/((MYFLT)(PYO_RAND_MAX)*0.5+1) - 1.0) * (MYFLT)(1.0e-60)))
2536 #endif
2537
2538 typedef struct
2539 {
2540 pyo_audio_HEAD
2541 PyObject *input;
2542 Stream *input_stream;
2543 int modebuffer[2]; // need at least 2 slots for mul & add
2544 } Denorm;
2545
2546 static void
2547 Denorm_filters(Denorm *self)
2548 {
2549 int i;
2550 MYFLT *in = Stream_getData((Stream *)self->input_stream);
2551
2552 for (i = 0; i < self->bufsize; i++)
2553 {
2554 self->data[i] = in[i] + DENORM_RAND;
2555 }
2556 }
2557
2558 static void Denorm_postprocessing_ii(Denorm *self) { POST_PROCESSING_II };
2559 static void Denorm_postprocessing_ai(Denorm *self) { POST_PROCESSING_AI };
2560 static void Denorm_postprocessing_ia(Denorm *self) { POST_PROCESSING_IA };
2561 static void Denorm_postprocessing_aa(Denorm *self) { POST_PROCESSING_AA };
2562 static void Denorm_postprocessing_ireva(Denorm *self) { POST_PROCESSING_IREVA };
2563 static void Denorm_postprocessing_areva(Denorm *self) { POST_PROCESSING_AREVA };
2564 static void Denorm_postprocessing_revai(Denorm *self) { POST_PROCESSING_REVAI };
2565 static void Denorm_postprocessing_revaa(Denorm *self) { POST_PROCESSING_REVAA };
2566 static void Denorm_postprocessing_revareva(Denorm *self) { POST_PROCESSING_REVAREVA };
2567
2568 static void
2569 Denorm_setProcMode(Denorm *self)
2570 {
2571 int muladdmode;
2572 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
2573
2574 self->proc_func_ptr = Denorm_filters;
2575
2576 switch (muladdmode)
2577 {
2578 case 0:
2579 self->muladd_func_ptr = Denorm_postprocessing_ii;
2580 break;
2581
2582 case 1:
2583 self->muladd_func_ptr = Denorm_postprocessing_ai;
2584 break;
2585
2586 case 2:
2587 self->muladd_func_ptr = Denorm_postprocessing_revai;
2588 break;
2589
2590 case 10:
2591 self->muladd_func_ptr = Denorm_postprocessing_ia;
2592 break;
2593
2594 case 11:
2595 self->muladd_func_ptr = Denorm_postprocessing_aa;
2596 break;
2597
2598 case 12:
2599 self->muladd_func_ptr = Denorm_postprocessing_revaa;
2600 break;
2601
2602 case 20:
2603 self->muladd_func_ptr = Denorm_postprocessing_ireva;
2604 break;
2605
2606 case 21:
2607 self->muladd_func_ptr = Denorm_postprocessing_areva;
2608 break;
2609
2610 case 22:
2611 self->muladd_func_ptr = Denorm_postprocessing_revareva;
2612 break;
2613 }
2614 }
2615
2616 static void
2617 Denorm_compute_next_data_frame(Denorm *self)
2618 {
2619 (*self->proc_func_ptr)(self);
2620 (*self->muladd_func_ptr)(self);
2621 }
2622
2623 static int
2624 Denorm_traverse(Denorm *self, visitproc visit, void *arg)
2625 {
2626 pyo_VISIT
2627 Py_VISIT(self->input);
2628 return 0;
2629 }
2630
2631 static int
2632 Denorm_clear(Denorm *self)
2633 {
2634 pyo_CLEAR
2635 Py_CLEAR(self->input);
2636 return 0;
2637 }
2638
2639 static void
2640 Denorm_dealloc(Denorm* self)
2641 {
2642 pyo_DEALLOC
2643 Denorm_clear(self);
2644 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
2645 Py_TYPE(self)->tp_free((PyObject*)self);
2646 }
2647
2648 static PyObject *
2649 Denorm_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2650 {
2651 int i;
2652 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
2653 Denorm *self;
2654 self = (Denorm *)type->tp_alloc(type, 0);
2655
2656 self->modebuffer[0] = 0;
2657 self->modebuffer[1] = 0;
2658
2659 INIT_OBJECT_COMMON
2660 Stream_setFunctionPtr(self->stream, Denorm_compute_next_data_frame);
2661 self->mode_func_ptr = Denorm_setProcMode;
2662
2663 static char *kwlist[] = {"input", "mul", "add", NULL};
2664
2665 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
2666 Py_RETURN_NONE;
2667
2668 INIT_INPUT_STREAM
2669
2670 if (multmp)
2671 {
2672 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
2673 }
2674
2675 if (addtmp)
2676 {
2677 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
2678 }
2679
2680 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
2681
2682 Server_generateSeed((Server *)self->server, DENORM_ID);
2683
2684 (*self->mode_func_ptr)(self);
2685
2686 return (PyObject *)self;
2687 }
2688
2689 static PyObject * Denorm_getServer(Denorm* self) { GET_SERVER };
2690 static PyObject * Denorm_getStream(Denorm* self) { GET_STREAM };
2691 static PyObject * Denorm_setMul(Denorm *self, PyObject *arg) { SET_MUL };
2692 static PyObject * Denorm_setAdd(Denorm *self, PyObject *arg) { SET_ADD };
2693 static PyObject * Denorm_setSub(Denorm *self, PyObject *arg) { SET_SUB };
2694 static PyObject * Denorm_setDiv(Denorm *self, PyObject *arg) { SET_DIV };
2695
2696 static PyObject * Denorm_play(Denorm *self, PyObject *args, PyObject *kwds) { PLAY };
2697 static PyObject * Denorm_out(Denorm *self, PyObject *args, PyObject *kwds) { OUT };
2698 static PyObject * Denorm_stop(Denorm *self, PyObject *args, PyObject *kwds) { STOP };
2699
2700 static PyObject * Denorm_multiply(Denorm *self, PyObject *arg) { MULTIPLY };
2701 static PyObject * Denorm_inplace_multiply(Denorm *self, PyObject *arg) { INPLACE_MULTIPLY };
2702 static PyObject * Denorm_add(Denorm *self, PyObject *arg) { ADD };
2703 static PyObject * Denorm_inplace_add(Denorm *self, PyObject *arg) { INPLACE_ADD };
2704 static PyObject * Denorm_sub(Denorm *self, PyObject *arg) { SUB };
2705 static PyObject * Denorm_inplace_sub(Denorm *self, PyObject *arg) { INPLACE_SUB };
2706 static PyObject * Denorm_div(Denorm *self, PyObject *arg) { DIV };
2707 static PyObject * Denorm_inplace_div(Denorm *self, PyObject *arg) { INPLACE_DIV };
2708
2709 static PyMemberDef Denorm_members[] =
2710 {
2711 {"server", T_OBJECT_EX, offsetof(Denorm, server), 0, "Pyo server."},
2712 {"stream", T_OBJECT_EX, offsetof(Denorm, stream), 0, "Stream object."},
2713 {"input", T_OBJECT_EX, offsetof(Denorm, input), 0, "Input sound object."},
2714 {"mul", T_OBJECT_EX, offsetof(Denorm, mul), 0, "Mul factor."},
2715 {"add", T_OBJECT_EX, offsetof(Denorm, add), 0, "Add factor."},
2716 {NULL} /* Sentinel */
2717 };
2718
2719 static PyMethodDef Denorm_methods[] =
2720 {
2721 {"getServer", (PyCFunction)Denorm_getServer, METH_NOARGS, "Returns server object."},
2722 {"_getStream", (PyCFunction)Denorm_getStream, METH_NOARGS, "Returns stream object."},
2723 {"play", (PyCFunction)Denorm_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
2724 {"out", (PyCFunction)Denorm_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
2725 {"stop", (PyCFunction)Denorm_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
2726 {"setMul", (PyCFunction)Denorm_setMul, METH_O, "Sets oscillator mul factor."},
2727 {"setAdd", (PyCFunction)Denorm_setAdd, METH_O, "Sets oscillator add factor."},
2728 {"setSub", (PyCFunction)Denorm_setSub, METH_O, "Sets inverse add factor."},
2729 {"setDiv", (PyCFunction)Denorm_setDiv, METH_O, "Sets inverse mul factor."},
2730 {NULL} /* Sentinel */
2731 };
2732
2733 static PyNumberMethods Denorm_as_number =
2734 {
2735 (binaryfunc)Denorm_add, /*nb_add*/
2736 (binaryfunc)Denorm_sub, /*nb_subtract*/
2737 (binaryfunc)Denorm_multiply, /*nb_multiply*/
2738 0, /*nb_remainder*/
2739 0, /*nb_divmod*/
2740 0, /*nb_power*/
2741 0, /*nb_neg*/
2742 0, /*nb_pos*/
2743 0, /*(unaryfunc)array_abs,*/
2744 0, /*nb_nonzero*/
2745 0, /*nb_invert*/
2746 0, /*nb_lshift*/
2747 0, /*nb_rshift*/
2748 0, /*nb_and*/
2749 0, /*nb_xor*/
2750 0, /*nb_or*/
2751 0, /*nb_int*/
2752 0, /*nb_long*/
2753 0, /*nb_float*/
2754 (binaryfunc)Denorm_inplace_add, /*inplace_add*/
2755 (binaryfunc)Denorm_inplace_sub, /*inplace_subtract*/
2756 (binaryfunc)Denorm_inplace_multiply, /*inplace_multiply*/
2757 0, /*inplace_remainder*/
2758 0, /*inplace_power*/
2759 0, /*inplace_lshift*/
2760 0, /*inplace_rshift*/
2761 0, /*inplace_and*/
2762 0, /*inplace_xor*/
2763 0, /*inplace_or*/
2764 0, /*nb_floor_divide*/
2765 (binaryfunc)Denorm_div, /*nb_true_divide*/
2766 0, /*nb_inplace_floor_divide*/
2767 (binaryfunc)Denorm_inplace_div, /*nb_inplace_true_divide*/
2768 0, /* nb_index */
2769 };
2770
2771 PyTypeObject DenormType =
2772 {
2773 PyVarObject_HEAD_INIT(NULL, 0)
2774 "_pyo.Denorm_base", /*tp_name*/
2775 sizeof(Denorm), /*tp_basicsize*/
2776 0, /*tp_itemsize*/
2777 (destructor)Denorm_dealloc, /*tp_dealloc*/
2778 0, /*tp_print*/
2779 0, /*tp_getattr*/
2780 0, /*tp_setattr*/
2781 0, /*tp_as_async (tp_compare in Python 2)*/
2782 0, /*tp_repr*/
2783 &Denorm_as_number, /*tp_as_number*/
2784 0, /*tp_as_sequence*/
2785 0, /*tp_as_mapping*/
2786 0, /*tp_hash */
2787 0, /*tp_call*/
2788 0, /*tp_str*/
2789 0, /*tp_getattro*/
2790 0, /*tp_setattro*/
2791 0, /*tp_as_buffer*/
2792 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
2793 "Denorm objects. Mixes low level noise to an input signal.", /* tp_doc */
2794 (traverseproc)Denorm_traverse, /* tp_traverse */
2795 (inquiry)Denorm_clear, /* tp_clear */
2796 0, /* tp_richcompare */
2797 0, /* tp_weaklistoffset */
2798 0, /* tp_iter */
2799 0, /* tp_iternext */
2800 Denorm_methods, /* tp_methods */
2801 Denorm_members, /* tp_members */
2802 0, /* tp_getset */
2803 0, /* tp_base */
2804 0, /* tp_dict */
2805 0, /* tp_descr_get */
2806 0, /* tp_descr_set */
2807 0, /* tp_dictoffset */
2808 0, /* tp_init */
2809 0, /* tp_alloc */
2810 Denorm_new, /* tp_new */
2811 };
2812
2813 /************/
2814 /* DBToA */
2815 /************/
2816 typedef struct
2817 {
2818 pyo_audio_HEAD
2819 PyObject *input;
2820 Stream *input_stream;
2821 MYFLT lastdb;
2822 MYFLT currentamp;
2823 int modebuffer[2]; // need at least 2 slots for mul & add
2824 } DBToA;
2825
2826 static void
2827 DBToA_process(DBToA *self)
2828 {
2829 int i;
2830 MYFLT db;
2831 MYFLT *in = Stream_getData((Stream *)self->input_stream);
2832
2833 for (i = 0; i < self->bufsize; i++)
2834 {
2835 db = in[i];
2836
2837 if (db <= -120.0)
2838 {
2839 self->data[i] = self->currentamp = 0.0;
2840 self->lastdb = -120.0;
2841 }
2842 else if (db != self->lastdb)
2843 {
2844 self->data[i] = self->currentamp = MYPOW(10.0, db * 0.05);
2845 self->lastdb = db;
2846 }
2847 else
2848 self->data[i] = self->currentamp;
2849 }
2850 }
2851
2852 static void DBToA_postprocessing_ii(DBToA *self) { POST_PROCESSING_II };
2853 static void DBToA_postprocessing_ai(DBToA *self) { POST_PROCESSING_AI };
2854 static void DBToA_postprocessing_ia(DBToA *self) { POST_PROCESSING_IA };
2855 static void DBToA_postprocessing_aa(DBToA *self) { POST_PROCESSING_AA };
2856 static void DBToA_postprocessing_ireva(DBToA *self) { POST_PROCESSING_IREVA };
2857 static void DBToA_postprocessing_areva(DBToA *self) { POST_PROCESSING_AREVA };
2858 static void DBToA_postprocessing_revai(DBToA *self) { POST_PROCESSING_REVAI };
2859 static void DBToA_postprocessing_revaa(DBToA *self) { POST_PROCESSING_REVAA };
2860 static void DBToA_postprocessing_revareva(DBToA *self) { POST_PROCESSING_REVAREVA };
2861
2862 static void
2863 DBToA_setProcMode(DBToA *self)
2864 {
2865 int muladdmode;
2866 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
2867
2868 self->proc_func_ptr = DBToA_process;
2869
2870 switch (muladdmode)
2871 {
2872 case 0:
2873 self->muladd_func_ptr = DBToA_postprocessing_ii;
2874 break;
2875
2876 case 1:
2877 self->muladd_func_ptr = DBToA_postprocessing_ai;
2878 break;
2879
2880 case 2:
2881 self->muladd_func_ptr = DBToA_postprocessing_revai;
2882 break;
2883
2884 case 10:
2885 self->muladd_func_ptr = DBToA_postprocessing_ia;
2886 break;
2887
2888 case 11:
2889 self->muladd_func_ptr = DBToA_postprocessing_aa;
2890 break;
2891
2892 case 12:
2893 self->muladd_func_ptr = DBToA_postprocessing_revaa;
2894 break;
2895
2896 case 20:
2897 self->muladd_func_ptr = DBToA_postprocessing_ireva;
2898 break;
2899
2900 case 21:
2901 self->muladd_func_ptr = DBToA_postprocessing_areva;
2902 break;
2903
2904 case 22:
2905 self->muladd_func_ptr = DBToA_postprocessing_revareva;
2906 break;
2907 }
2908 }
2909
2910 static void
2911 DBToA_compute_next_data_frame(DBToA *self)
2912 {
2913 (*self->proc_func_ptr)(self);
2914 (*self->muladd_func_ptr)(self);
2915 }
2916
2917 static int
2918 DBToA_traverse(DBToA *self, visitproc visit, void *arg)
2919 {
2920 pyo_VISIT
2921 Py_VISIT(self->input);
2922 return 0;
2923 }
2924
2925 static int
2926 DBToA_clear(DBToA *self)
2927 {
2928 pyo_CLEAR
2929 Py_CLEAR(self->input);
2930 return 0;
2931 }
2932
2933 static void
2934 DBToA_dealloc(DBToA* self)
2935 {
2936 pyo_DEALLOC
2937 DBToA_clear(self);
2938 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
2939 Py_TYPE(self)->tp_free((PyObject*)self);
2940 }
2941
2942 static PyObject *
2943 DBToA_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2944 {
2945 int i;
2946 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
2947 DBToA *self;
2948 self = (DBToA *)type->tp_alloc(type, 0);
2949
2950 self->lastdb = -120.0;
2951 self->currentamp = MYPOW(10.0, self->lastdb * 0.05);
2952 self->modebuffer[0] = 0;
2953 self->modebuffer[1] = 0;
2954
2955 INIT_OBJECT_COMMON
2956 Stream_setFunctionPtr(self->stream, DBToA_compute_next_data_frame);
2957 self->mode_func_ptr = DBToA_setProcMode;
2958
2959 static char *kwlist[] = {"input", "mul", "add", NULL};
2960
2961 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
2962 Py_RETURN_NONE;
2963
2964 INIT_INPUT_STREAM
2965
2966 if (multmp)
2967 {
2968 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
2969 }
2970
2971 if (addtmp)
2972 {
2973 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
2974 }
2975
2976 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
2977
2978 (*self->mode_func_ptr)(self);
2979
2980 return (PyObject *)self;
2981 }
2982
2983 static PyObject * DBToA_getServer(DBToA* self) { GET_SERVER };
2984 static PyObject * DBToA_getStream(DBToA* self) { GET_STREAM };
2985 static PyObject * DBToA_setMul(DBToA *self, PyObject *arg) { SET_MUL };
2986 static PyObject * DBToA_setAdd(DBToA *self, PyObject *arg) { SET_ADD };
2987 static PyObject * DBToA_setSub(DBToA *self, PyObject *arg) { SET_SUB };
2988 static PyObject * DBToA_setDiv(DBToA *self, PyObject *arg) { SET_DIV };
2989
2990 static PyObject * DBToA_play(DBToA *self, PyObject *args, PyObject *kwds) { PLAY };
2991 static PyObject * DBToA_out(DBToA *self, PyObject *args, PyObject *kwds) { OUT };
2992 static PyObject * DBToA_stop(DBToA *self, PyObject *args, PyObject *kwds) { STOP };
2993
2994 static PyObject * DBToA_multiply(DBToA *self, PyObject *arg) { MULTIPLY };
2995 static PyObject * DBToA_inplace_multiply(DBToA *self, PyObject *arg) { INPLACE_MULTIPLY };
2996 static PyObject * DBToA_add(DBToA *self, PyObject *arg) { ADD };
2997 static PyObject * DBToA_inplace_add(DBToA *self, PyObject *arg) { INPLACE_ADD };
2998 static PyObject * DBToA_sub(DBToA *self, PyObject *arg) { SUB };
2999 static PyObject * DBToA_inplace_sub(DBToA *self, PyObject *arg) { INPLACE_SUB };
3000 static PyObject * DBToA_div(DBToA *self, PyObject *arg) { DIV };
3001 static PyObject * DBToA_inplace_div(DBToA *self, PyObject *arg) { INPLACE_DIV };
3002
3003 static PyMemberDef DBToA_members[] =
3004 {
3005 {"server", T_OBJECT_EX, offsetof(DBToA, server), 0, "Pyo server."},
3006 {"stream", T_OBJECT_EX, offsetof(DBToA, stream), 0, "Stream object."},
3007 {"input", T_OBJECT_EX, offsetof(DBToA, input), 0, "Input sound object."},
3008 {"mul", T_OBJECT_EX, offsetof(DBToA, mul), 0, "Mul factor."},
3009 {"add", T_OBJECT_EX, offsetof(DBToA, add), 0, "Add factor."},
3010 {NULL} /* Sentinel */
3011 };
3012
3013 static PyMethodDef DBToA_methods[] =
3014 {
3015 {"getServer", (PyCFunction)DBToA_getServer, METH_NOARGS, "Returns server object."},
3016 {"_getStream", (PyCFunction)DBToA_getStream, METH_NOARGS, "Returns stream object."},
3017 {"play", (PyCFunction)DBToA_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
3018 {"stop", (PyCFunction)DBToA_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
3019 {"out", (PyCFunction)DBToA_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
3020 {"setMul", (PyCFunction)DBToA_setMul, METH_O, "Sets oscillator mul factor."},
3021 {"setAdd", (PyCFunction)DBToA_setAdd, METH_O, "Sets oscillator add factor."},
3022 {"setSub", (PyCFunction)DBToA_setSub, METH_O, "Sets inverse add factor."},
3023 {"setDiv", (PyCFunction)DBToA_setDiv, METH_O, "Sets inverse mul factor."},
3024 {NULL} /* Sentinel */
3025 };
3026
3027 static PyNumberMethods DBToA_as_number =
3028 {
3029 (binaryfunc)DBToA_add, /*nb_add*/
3030 (binaryfunc)DBToA_sub, /*nb_subtract*/
3031 (binaryfunc)DBToA_multiply, /*nb_multiply*/
3032 0, /*nb_remainder*/
3033 0, /*nb_divmod*/
3034 0, /*nb_power*/
3035 0, /*nb_neg*/
3036 0, /*nb_pos*/
3037 0, /*(unaryfunc)array_abs,*/
3038 0, /*nb_nonzero*/
3039 0, /*nb_invert*/
3040 0, /*nb_lshift*/
3041 0, /*nb_rshift*/
3042 0, /*nb_and*/
3043 0, /*nb_xor*/
3044 0, /*nb_or*/
3045 0, /*nb_int*/
3046 0, /*nb_long*/
3047 0, /*nb_float*/
3048 (binaryfunc)DBToA_inplace_add, /*inplace_add*/
3049 (binaryfunc)DBToA_inplace_sub, /*inplace_subtract*/
3050 (binaryfunc)DBToA_inplace_multiply, /*inplace_multiply*/
3051 0, /*inplace_remainder*/
3052 0, /*inplace_power*/
3053 0, /*inplace_lshift*/
3054 0, /*inplace_rshift*/
3055 0, /*inplace_and*/
3056 0, /*inplace_xor*/
3057 0, /*inplace_or*/
3058 0, /*nb_floor_divide*/
3059 (binaryfunc)DBToA_div, /*nb_true_divide*/
3060 0, /*nb_inplace_floor_divide*/
3061 (binaryfunc)DBToA_inplace_div, /*nb_inplace_true_divide*/
3062 0, /* nb_index */
3063 };
3064
3065 PyTypeObject DBToAType =
3066 {
3067 PyVarObject_HEAD_INIT(NULL, 0)
3068 "_pyo.DBToA_base", /*tp_name*/
3069 sizeof(DBToA), /*tp_basicsize*/
3070 0, /*tp_itemsize*/
3071 (destructor)DBToA_dealloc, /*tp_dealloc*/
3072 0, /*tp_print*/
3073 0, /*tp_getattr*/
3074 0, /*tp_setattr*/
3075 0, /*tp_as_async (tp_compare in Python 2)*/
3076 0, /*tp_repr*/
3077 &DBToA_as_number, /*tp_as_number*/
3078 0, /*tp_as_sequence*/
3079 0, /*tp_as_mapping*/
3080 0, /*tp_hash */
3081 0, /*tp_call*/
3082 0, /*tp_str*/
3083 0, /*tp_getattro*/
3084 0, /*tp_setattro*/
3085 0, /*tp_as_buffer*/
3086 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
3087 "DBToA objects. Converts dB value to amplitude value.", /* tp_doc */
3088 (traverseproc)DBToA_traverse, /* tp_traverse */
3089 (inquiry)DBToA_clear, /* tp_clear */
3090 0, /* tp_richcompare */
3091 0, /* tp_weaklistoffset */
3092 0, /* tp_iter */
3093 0, /* tp_iternext */
3094 DBToA_methods, /* tp_methods */
3095 DBToA_members, /* tp_members */
3096 0, /* tp_getset */
3097 0, /* tp_base */
3098 0, /* tp_dict */
3099 0, /* tp_descr_get */
3100 0, /* tp_descr_set */
3101 0, /* tp_dictoffset */
3102 0, /* tp_init */
3103 0, /* tp_alloc */
3104 DBToA_new, /* tp_new */
3105 };
3106
3107 /************/
3108 /* AToDB */
3109 /************/
3110 typedef struct
3111 {
3112 pyo_audio_HEAD
3113 PyObject *input;
3114 Stream *input_stream;
3115 MYFLT lastamp;
3116 MYFLT currentdb;
3117 int modebuffer[2]; // need at least 2 slots for mul & add
3118 } AToDB;
3119
3120 static void
3121 AToDB_process(AToDB *self)
3122 {
3123 int i;
3124 MYFLT amp;
3125 MYFLT *in = Stream_getData((Stream *)self->input_stream);
3126
3127 for (i = 0; i < self->bufsize; i++)
3128 {
3129 amp = in[i];
3130
3131 if (amp <= 0.000001)
3132 {
3133 self->data[i] = self->currentdb = -120.0;
3134 self->lastamp = 0.000001;
3135 }
3136 else if (amp != self->lastamp)
3137 {
3138 self->data[i] = self->currentdb = 20.0 * MYLOG10(amp);
3139 self->lastamp = amp;
3140 }
3141 else
3142 self->data[i] = self->currentdb;
3143 }
3144 }
3145
3146 static void AToDB_postprocessing_ii(AToDB *self) { POST_PROCESSING_II };
3147 static void AToDB_postprocessing_ai(AToDB *self) { POST_PROCESSING_AI };
3148 static void AToDB_postprocessing_ia(AToDB *self) { POST_PROCESSING_IA };
3149 static void AToDB_postprocessing_aa(AToDB *self) { POST_PROCESSING_AA };
3150 static void AToDB_postprocessing_ireva(AToDB *self) { POST_PROCESSING_IREVA };
3151 static void AToDB_postprocessing_areva(AToDB *self) { POST_PROCESSING_AREVA };
3152 static void AToDB_postprocessing_revai(AToDB *self) { POST_PROCESSING_REVAI };
3153 static void AToDB_postprocessing_revaa(AToDB *self) { POST_PROCESSING_REVAA };
3154 static void AToDB_postprocessing_revareva(AToDB *self) { POST_PROCESSING_REVAREVA };
3155
3156 static void
3157 AToDB_setProcMode(AToDB *self)
3158 {
3159 int muladdmode;
3160 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
3161
3162 self->proc_func_ptr = AToDB_process;
3163
3164 switch (muladdmode)
3165 {
3166 case 0:
3167 self->muladd_func_ptr = AToDB_postprocessing_ii;
3168 break;
3169
3170 case 1:
3171 self->muladd_func_ptr = AToDB_postprocessing_ai;
3172 break;
3173
3174 case 2:
3175 self->muladd_func_ptr = AToDB_postprocessing_revai;
3176 break;
3177
3178 case 10:
3179 self->muladd_func_ptr = AToDB_postprocessing_ia;
3180 break;
3181
3182 case 11:
3183 self->muladd_func_ptr = AToDB_postprocessing_aa;
3184 break;
3185
3186 case 12:
3187 self->muladd_func_ptr = AToDB_postprocessing_revaa;
3188 break;
3189
3190 case 20:
3191 self->muladd_func_ptr = AToDB_postprocessing_ireva;
3192 break;
3193
3194 case 21:
3195 self->muladd_func_ptr = AToDB_postprocessing_areva;
3196 break;
3197
3198 case 22:
3199 self->muladd_func_ptr = AToDB_postprocessing_revareva;
3200 break;
3201 }
3202 }
3203
3204 static void
3205 AToDB_compute_next_data_frame(AToDB *self)
3206 {
3207 (*self->proc_func_ptr)(self);
3208 (*self->muladd_func_ptr)(self);
3209 }
3210
3211 static int
3212 AToDB_traverse(AToDB *self, visitproc visit, void *arg)
3213 {
3214 pyo_VISIT
3215 Py_VISIT(self->input);
3216 return 0;
3217 }
3218
3219 static int
3220 AToDB_clear(AToDB *self)
3221 {
3222 pyo_CLEAR
3223 Py_CLEAR(self->input);
3224 return 0;
3225 }
3226
3227 static void
3228 AToDB_dealloc(AToDB* self)
3229 {
3230 pyo_DEALLOC
3231 AToDB_clear(self);
3232 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
3233 Py_TYPE(self)->tp_free((PyObject*)self);
3234 }
3235
3236 static PyObject *
3237 AToDB_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
3238 {
3239 int i;
3240 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
3241 AToDB *self;
3242 self = (AToDB *)type->tp_alloc(type, 0);
3243
3244 self->lastamp = 0.000001;
3245 self->currentdb = 20.0 * MYLOG10(self->lastamp);
3246 self->modebuffer[0] = 0;
3247 self->modebuffer[1] = 0;
3248
3249 INIT_OBJECT_COMMON
3250 Stream_setFunctionPtr(self->stream, AToDB_compute_next_data_frame);
3251 self->mode_func_ptr = AToDB_setProcMode;
3252
3253 static char *kwlist[] = {"input", "mul", "add", NULL};
3254
3255 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
3256 Py_RETURN_NONE;
3257
3258 INIT_INPUT_STREAM
3259
3260 if (multmp)
3261 {
3262 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
3263 }
3264
3265 if (addtmp)
3266 {
3267 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
3268 }
3269
3270 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
3271
3272 (*self->mode_func_ptr)(self);
3273
3274 return (PyObject *)self;
3275 }
3276
3277 static PyObject * AToDB_getServer(AToDB* self) { GET_SERVER };
3278 static PyObject * AToDB_getStream(AToDB* self) { GET_STREAM };
3279 static PyObject * AToDB_setMul(AToDB *self, PyObject *arg) { SET_MUL };
3280 static PyObject * AToDB_setAdd(AToDB *self, PyObject *arg) { SET_ADD };
3281 static PyObject * AToDB_setSub(AToDB *self, PyObject *arg) { SET_SUB };
3282 static PyObject * AToDB_setDiv(AToDB *self, PyObject *arg) { SET_DIV };
3283
3284 static PyObject * AToDB_play(AToDB *self, PyObject *args, PyObject *kwds) { PLAY };
3285 static PyObject * AToDB_out(AToDB *self, PyObject *args, PyObject *kwds) { OUT };
3286 static PyObject * AToDB_stop(AToDB *self, PyObject *args, PyObject *kwds) { STOP };
3287
3288 static PyObject * AToDB_multiply(AToDB *self, PyObject *arg) { MULTIPLY };
3289 static PyObject * AToDB_inplace_multiply(AToDB *self, PyObject *arg) { INPLACE_MULTIPLY };
3290 static PyObject * AToDB_add(AToDB *self, PyObject *arg) { ADD };
3291 static PyObject * AToDB_inplace_add(AToDB *self, PyObject *arg) { INPLACE_ADD };
3292 static PyObject * AToDB_sub(AToDB *self, PyObject *arg) { SUB };
3293 static PyObject * AToDB_inplace_sub(AToDB *self, PyObject *arg) { INPLACE_SUB };
3294 static PyObject * AToDB_div(AToDB *self, PyObject *arg) { DIV };
3295 static PyObject * AToDB_inplace_div(AToDB *self, PyObject *arg) { INPLACE_DIV };
3296
3297 static PyMemberDef AToDB_members[] =
3298 {
3299 {"server", T_OBJECT_EX, offsetof(AToDB, server), 0, "Pyo server."},
3300 {"stream", T_OBJECT_EX, offsetof(AToDB, stream), 0, "Stream object."},
3301 {"input", T_OBJECT_EX, offsetof(AToDB, input), 0, "Input sound object."},
3302 {"mul", T_OBJECT_EX, offsetof(AToDB, mul), 0, "Mul factor."},
3303 {"add", T_OBJECT_EX, offsetof(AToDB, add), 0, "Add factor."},
3304 {NULL} /* Sentinel */
3305 };
3306
3307 static PyMethodDef AToDB_methods[] =
3308 {
3309 {"getServer", (PyCFunction)AToDB_getServer, METH_NOARGS, "Returns server object."},
3310 {"_getStream", (PyCFunction)AToDB_getStream, METH_NOARGS, "Returns stream object."},
3311 {"play", (PyCFunction)AToDB_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
3312 {"stop", (PyCFunction)AToDB_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
3313 {"out", (PyCFunction)AToDB_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
3314 {"setMul", (PyCFunction)AToDB_setMul, METH_O, "Sets oscillator mul factor."},
3315 {"setAdd", (PyCFunction)AToDB_setAdd, METH_O, "Sets oscillator add factor."},
3316 {"setSub", (PyCFunction)AToDB_setSub, METH_O, "Sets inverse add factor."},
3317 {"setDiv", (PyCFunction)AToDB_setDiv, METH_O, "Sets inverse mul factor."},
3318 {NULL} /* Sentinel */
3319 };
3320
3321 static PyNumberMethods AToDB_as_number =
3322 {
3323 (binaryfunc)AToDB_add, /*nb_add*/
3324 (binaryfunc)AToDB_sub, /*nb_subtract*/
3325 (binaryfunc)AToDB_multiply, /*nb_multiply*/
3326 0, /*nb_remainder*/
3327 0, /*nb_divmod*/
3328 0, /*nb_power*/
3329 0, /*nb_neg*/
3330 0, /*nb_pos*/
3331 0, /*(unaryfunc)array_abs,*/
3332 0, /*nb_nonzero*/
3333 0, /*nb_invert*/
3334 0, /*nb_lshift*/
3335 0, /*nb_rshift*/
3336 0, /*nb_and*/
3337 0, /*nb_xor*/
3338 0, /*nb_or*/
3339 0, /*nb_int*/
3340 0, /*nb_long*/
3341 0, /*nb_float*/
3342 (binaryfunc)AToDB_inplace_add, /*inplace_add*/
3343 (binaryfunc)AToDB_inplace_sub, /*inplace_subtract*/
3344 (binaryfunc)AToDB_inplace_multiply, /*inplace_multiply*/
3345 0, /*inplace_remainder*/
3346 0, /*inplace_power*/
3347 0, /*inplace_lshift*/
3348 0, /*inplace_rshift*/
3349 0, /*inplace_and*/
3350 0, /*inplace_xor*/
3351 0, /*inplace_or*/
3352 0, /*nb_floor_divide*/
3353 (binaryfunc)AToDB_div, /*nb_true_divide*/
3354 0, /*nb_inplace_floor_divide*/
3355 (binaryfunc)AToDB_inplace_div, /*nb_inplace_true_divide*/
3356 0, /* nb_index */
3357 };
3358
3359 PyTypeObject AToDBType =
3360 {
3361 PyVarObject_HEAD_INIT(NULL, 0)
3362 "_pyo.AToDB_base", /*tp_name*/
3363 sizeof(AToDB), /*tp_basicsize*/
3364 0, /*tp_itemsize*/
3365 (destructor)AToDB_dealloc, /*tp_dealloc*/
3366 0, /*tp_print*/
3367 0, /*tp_getattr*/
3368 0, /*tp_setattr*/
3369 0, /*tp_as_async (tp_compare in Python 2)*/
3370 0, /*tp_repr*/
3371 &AToDB_as_number, /*tp_as_number*/
3372 0, /*tp_as_sequence*/
3373 0, /*tp_as_mapping*/
3374 0, /*tp_hash */
3375 0, /*tp_call*/
3376 0, /*tp_str*/
3377 0, /*tp_getattro*/
3378 0, /*tp_setattro*/
3379 0, /*tp_as_buffer*/
3380 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
3381 "AToDB objects. Converts dB value to amplitude value.", /* tp_doc */
3382 (traverseproc)AToDB_traverse, /* tp_traverse */
3383 (inquiry)AToDB_clear, /* tp_clear */
3384 0, /* tp_richcompare */
3385 0, /* tp_weaklistoffset */
3386 0, /* tp_iter */
3387 0, /* tp_iternext */
3388 AToDB_methods, /* tp_methods */
3389 AToDB_members, /* tp_members */
3390 0, /* tp_getset */
3391 0, /* tp_base */
3392 0, /* tp_dict */
3393 0, /* tp_descr_get */
3394 0, /* tp_descr_set */
3395 0, /* tp_dictoffset */
3396 0, /* tp_init */
3397 0, /* tp_alloc */
3398 AToDB_new, /* tp_new */
3399 };
3400
3401 /*********************************************************************************************/
3402 /* Scale ********************************************************************************/
3403 /*********************************************************************************************/
3404 typedef struct
3405 {
3406 pyo_audio_HEAD
3407 PyObject *input;
3408 Stream *input_stream;
3409 PyObject *inmin;
3410 Stream *inmin_stream;
3411 PyObject *inmax;
3412 Stream *inmax_stream;
3413 PyObject *outmin;
3414 Stream *outmin_stream;
3415 PyObject *outmax;
3416 Stream *outmax_stream;
3417 PyObject *exp;
3418 Stream *exp_stream;
3419 int modebuffer[7]; // need at least 2 slots for mul & add
3420 } Scale;
3421
3422 static MYFLT
3423 _scale_clip(MYFLT x, MYFLT min, MYFLT max)
3424 {
3425 if (x < min)
3426 return min;
3427 else if (x > max)
3428 return max;
3429 else
3430 return x;
3431 }
3432
3433 static void
3434 Scale_generate(Scale *self)
3435 {
3436 int i, inrev, outrev;
3437 MYFLT tmp, inrange, outrange, normin;
3438 MYFLT inmin, inmax, outmin, outmax, exp;
3439 MYFLT *in = Stream_getData((Stream *)self->input_stream);
3440
3441 if (self->modebuffer[2] == 0)
3442 inmin = PyFloat_AS_DOUBLE(self->inmin);
3443 else
3444 inmin = Stream_getData((Stream *)self->inmin_stream)[0];
3445
3446 if (self->modebuffer[3] == 0)
3447 inmax = PyFloat_AS_DOUBLE(self->inmax);
3448 else
3449 inmax = Stream_getData((Stream *)self->inmax_stream)[0];
3450
3451 if (inmin < inmax)
3452 {
3453 inrev = 0;
3454 }
3455 else
3456 {
3457 tmp = inmin;
3458 inmin = inmax;
3459 inmax = tmp;
3460 inrev = 1;
3461 }
3462
3463 inrange = inmax - inmin;
3464
3465 if (self->modebuffer[4] == 0)
3466 outmin = PyFloat_AS_DOUBLE(self->outmin);
3467 else
3468 outmin = Stream_getData((Stream *)self->outmin_stream)[0];
3469
3470 if (self->modebuffer[5] == 0)
3471 outmax = PyFloat_AS_DOUBLE(self->outmax);
3472 else
3473 outmax = Stream_getData((Stream *)self->outmax_stream)[0];
3474
3475 if (outmin < outmax)
3476 {
3477 outrev = 0;
3478 }
3479 else
3480 {
3481 tmp = outmin;
3482 outmin = outmax;
3483 outmax = tmp;
3484 outrev = 1;
3485 }
3486
3487 outrange = outmax - outmin;
3488
3489 if (self->modebuffer[6] == 0)
3490 exp = PyFloat_AS_DOUBLE(self->exp);
3491 else
3492 exp = Stream_getData((Stream *)self->exp_stream)[0];
3493
3494 if (exp < 0.0)
3495 exp = 0.0;
3496
3497 /* Handle case where input or output range equal 0 */
3498 if (inrange == 0.0 || outrange == 0.0)
3499 {
3500 for (i = 0; i < self->bufsize; i++)
3501 {
3502 self->data[i] = outmin;
3503 }
3504 }
3505 /* Linear scaling */
3506 else if (exp == 1.0)
3507 {
3508 if (inrev == 0 && outrev == 0)
3509 {
3510 for (i = 0; i < self->bufsize; i++)
3511 {
3512 normin = (_scale_clip(in[i], inmin, inmax) - inmin) / inrange;
3513 self->data[i] = normin * outrange + outmin;
3514 }
3515 }
3516 else if (inrev == 1 && outrev == 0)
3517 {
3518 for (i = 0; i < self->bufsize; i++)
3519 {
3520 normin = 1.0 - ((_scale_clip(in[i], inmin, inmax) - inmin) / inrange);
3521 self->data[i] = normin * outrange + outmin;
3522 }
3523 }
3524 else if (inrev == 0 && outrev == 1)
3525 {
3526 for (i = 0; i < self->bufsize; i++)
3527 {
3528 normin = (_scale_clip(in[i], inmin, inmax) - inmin) / inrange;
3529 self->data[i] = outmax - (normin * outrange);
3530 }
3531 }
3532 else if (inrev == 1 && outrev == 1)
3533 {
3534 for (i = 0; i < self->bufsize; i++)
3535 {
3536 normin = 1.0 - ((_scale_clip(in[i], inmin, inmax) - inmin) / inrange);
3537 self->data[i] = outmax - (normin * outrange);
3538 }
3539 }
3540 }
3541 /* Exponential scaling */
3542 else
3543 {
3544 if (inrev == 0 && outrev == 0)
3545 {
3546 for (i = 0; i < self->bufsize; i++)
3547 {
3548 normin = MYPOW((_scale_clip(in[i], inmin, inmax) - inmin) / inrange, exp);
3549 self->data[i] = normin * outrange + outmin;
3550 }
3551 }
3552 else if (inrev == 1 && outrev == 0)
3553 {
3554 for (i = 0; i < self->bufsize; i++)
3555 {
3556 normin = MYPOW(1.0 - ((_scale_clip(in[i], inmin, inmax) - inmin) / inrange), exp);
3557 self->data[i] = normin * outrange + outmin;
3558 }
3559 }
3560 else if (inrev == 0 && outrev == 1)
3561 {
3562 for (i = 0; i < self->bufsize; i++)
3563 {
3564 normin = MYPOW((_scale_clip(in[i], inmin, inmax) - inmin) / inrange, exp);
3565 self->data[i] = outmax - (normin * outrange);
3566 }
3567 }
3568 else if (inrev == 1 && outrev == 1)
3569 {
3570 for (i = 0; i < self->bufsize; i++)
3571 {
3572 normin = MYPOW(1.0 - ((_scale_clip(in[i], inmin, inmax) - inmin) / inrange), exp);
3573 self->data[i] = outmax - (normin * outrange);
3574 }
3575 }
3576 }
3577 }
3578
3579 static void Scale_postprocessing_ii(Scale *self) { POST_PROCESSING_II };
3580 static void Scale_postprocessing_ai(Scale *self) { POST_PROCESSING_AI };
3581 static void Scale_postprocessing_ia(Scale *self) { POST_PROCESSING_IA };
3582 static void Scale_postprocessing_aa(Scale *self) { POST_PROCESSING_AA };
3583 static void Scale_postprocessing_ireva(Scale *self) { POST_PROCESSING_IREVA };
3584 static void Scale_postprocessing_areva(Scale *self) { POST_PROCESSING_AREVA };
3585 static void Scale_postprocessing_revai(Scale *self) { POST_PROCESSING_REVAI };
3586 static void Scale_postprocessing_revaa(Scale *self) { POST_PROCESSING_REVAA };
3587 static void Scale_postprocessing_revareva(Scale *self) { POST_PROCESSING_REVAREVA };
3588
3589 static void
3590 Scale_setProcMode(Scale *self)
3591 {
3592 int muladdmode;
3593 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
3594
3595 self->proc_func_ptr = Scale_generate;
3596
3597 switch (muladdmode)
3598 {
3599 case 0:
3600 self->muladd_func_ptr = Scale_postprocessing_ii;
3601 break;
3602
3603 case 1:
3604 self->muladd_func_ptr = Scale_postprocessing_ai;
3605 break;
3606
3607 case 2:
3608 self->muladd_func_ptr = Scale_postprocessing_revai;
3609 break;
3610
3611 case 10:
3612 self->muladd_func_ptr = Scale_postprocessing_ia;
3613 break;
3614
3615 case 11:
3616 self->muladd_func_ptr = Scale_postprocessing_aa;
3617 break;
3618
3619 case 12:
3620 self->muladd_func_ptr = Scale_postprocessing_revaa;
3621 break;
3622
3623 case 20:
3624 self->muladd_func_ptr = Scale_postprocessing_ireva;
3625 break;
3626
3627 case 21:
3628 self->muladd_func_ptr = Scale_postprocessing_areva;
3629 break;
3630
3631 case 22:
3632 self->muladd_func_ptr = Scale_postprocessing_revareva;
3633 break;
3634 }
3635 }
3636
3637 static void
3638 Scale_compute_next_data_frame(Scale *self)
3639 {
3640 (*self->proc_func_ptr)(self);
3641 (*self->muladd_func_ptr)(self);
3642 }
3643
3644 static int
3645 Scale_traverse(Scale *self, visitproc visit, void *arg)
3646 {
3647 pyo_VISIT
3648 Py_VISIT(self->input);
3649 Py_VISIT(self->inmin);
3650 Py_VISIT(self->inmax);
3651 Py_VISIT(self->outmin);
3652 Py_VISIT(self->outmax);
3653 Py_VISIT(self->exp);
3654 return 0;
3655 }
3656
3657 static int
3658 Scale_clear(Scale *self)
3659 {
3660 pyo_CLEAR
3661 Py_CLEAR(self->input);
3662 Py_CLEAR(self->inmin);
3663 Py_CLEAR(self->inmax);
3664 Py_CLEAR(self->outmin);
3665 Py_CLEAR(self->outmax);
3666 Py_CLEAR(self->exp);
3667 return 0;
3668 }
3669
3670 static void
3671 Scale_dealloc(Scale* self)
3672 {
3673 pyo_DEALLOC
3674 Scale_clear(self);
3675 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
3676 Py_TYPE(self)->tp_free((PyObject*)self);
3677 }
3678
3679 static PyObject *
3680 Scale_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
3681 {
3682 int i;
3683 PyObject *inputtmp, *input_streamtmp, *inmintmp = NULL, *inmaxtmp = NULL, *outmintmp = NULL, *outmaxtmp = NULL, *exptmp = NULL, *multmp = NULL, *addtmp = NULL;
3684 Scale *self;
3685 self = (Scale *)type->tp_alloc(type, 0);
3686
3687 self->inmin = PyFloat_FromDouble(0.0);
3688 self->inmax = PyFloat_FromDouble(1.0);
3689 self->outmin = PyFloat_FromDouble(0.0);
3690 self->outmax = PyFloat_FromDouble(1.0);
3691 self->exp = PyFloat_FromDouble(1.0);
3692 self->modebuffer[0] = 0;
3693 self->modebuffer[1] = 0;
3694 self->modebuffer[2] = 0;
3695 self->modebuffer[3] = 0;
3696 self->modebuffer[4] = 0;
3697 self->modebuffer[5] = 0;
3698 self->modebuffer[6] = 0;
3699
3700 INIT_OBJECT_COMMON
3701 Stream_setFunctionPtr(self->stream, Scale_compute_next_data_frame);
3702 self->mode_func_ptr = Scale_setProcMode;
3703
3704 static char *kwlist[] = {"input", "inmin", "inmax", "outmin", "outmax", "exp", "mul", "add", NULL};
3705
3706 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OOOOOOO", kwlist, &inputtmp, &inmintmp, &inmaxtmp, &outmintmp, &outmaxtmp, &exptmp, &multmp, &addtmp))
3707 Py_RETURN_NONE;
3708
3709 INIT_INPUT_STREAM
3710
3711 if (inmintmp)
3712 {
3713 PyObject_CallMethod((PyObject *)self, "setInMin", "O", inmintmp);
3714 }
3715
3716 if (inmaxtmp)
3717 {
3718 PyObject_CallMethod((PyObject *)self, "setInMax", "O", inmaxtmp);
3719 }
3720
3721 if (outmintmp)
3722 {
3723 PyObject_CallMethod((PyObject *)self, "setOutMin", "O", outmintmp);
3724 }
3725
3726 if (outmaxtmp)
3727 {
3728 PyObject_CallMethod((PyObject *)self, "setOutMax", "O", outmaxtmp);
3729 }
3730
3731 if (exptmp)
3732 {
3733 PyObject_CallMethod((PyObject *)self, "setExp", "O", exptmp);
3734 }
3735
3736 if (multmp)
3737 {
3738 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
3739 }
3740
3741 if (addtmp)
3742 {
3743 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
3744 }
3745
3746 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
3747
3748 (*self->mode_func_ptr)(self);
3749
3750 return (PyObject *)self;
3751 }
3752
3753 static PyObject * Scale_getServer(Scale* self) { GET_SERVER };
3754 static PyObject * Scale_getStream(Scale* self) { GET_STREAM };
3755 static PyObject * Scale_setMul(Scale *self, PyObject *arg) { SET_MUL };
3756 static PyObject * Scale_setAdd(Scale *self, PyObject *arg) { SET_ADD };
3757 static PyObject * Scale_setSub(Scale *self, PyObject *arg) { SET_SUB };
3758 static PyObject * Scale_setDiv(Scale *self, PyObject *arg) { SET_DIV };
3759
3760 static PyObject * Scale_play(Scale *self, PyObject *args, PyObject *kwds) { PLAY };
3761 static PyObject * Scale_out(Scale *self, PyObject *args, PyObject *kwds) { OUT };
3762 static PyObject * Scale_stop(Scale *self, PyObject *args, PyObject *kwds) { STOP };
3763
3764 static PyObject * Scale_multiply(Scale *self, PyObject *arg) { MULTIPLY };
3765 static PyObject * Scale_inplace_multiply(Scale *self, PyObject *arg) { INPLACE_MULTIPLY };
3766 static PyObject * Scale_add(Scale *self, PyObject *arg) { ADD };
3767 static PyObject * Scale_inplace_add(Scale *self, PyObject *arg) { INPLACE_ADD };
3768 static PyObject * Scale_sub(Scale *self, PyObject *arg) { SUB };
3769 static PyObject * Scale_inplace_sub(Scale *self, PyObject *arg) { INPLACE_SUB };
3770 static PyObject * Scale_div(Scale *self, PyObject *arg) { DIV };
3771 static PyObject * Scale_inplace_div(Scale *self, PyObject *arg) { INPLACE_DIV };
3772
3773 static PyObject * Scale_setInMin(Scale *self, PyObject *arg) { SET_PARAM(self->inmin, self->inmin_stream, 2); }
3774 static PyObject * Scale_setInMax(Scale *self, PyObject *arg) { SET_PARAM(self->inmax, self->inmax_stream, 3); }
3775 static PyObject * Scale_setOutMin(Scale *self, PyObject *arg) { SET_PARAM(self->outmin, self->outmin_stream, 4); }
3776 static PyObject * Scale_setOutMax(Scale *self, PyObject *arg) { SET_PARAM(self->outmax, self->outmax_stream, 5); }
3777 static PyObject * Scale_setExp(Scale *self, PyObject *arg) { SET_PARAM(self->exp, self->exp_stream, 6); }
3778
3779 static PyMemberDef Scale_members[] =
3780 {
3781 {"server", T_OBJECT_EX, offsetof(Scale, server), 0, "Pyo server."},
3782 {"stream", T_OBJECT_EX, offsetof(Scale, stream), 0, "Stream object."},
3783 {"input", T_OBJECT_EX, offsetof(Scale, input), 0, "Input sound object."},
3784 {"mul", T_OBJECT_EX, offsetof(Scale, mul), 0, "Mul factor."},
3785 {"add", T_OBJECT_EX, offsetof(Scale, add), 0, "Add factor."},
3786 {NULL} /* Sentinel */
3787 };
3788
3789 static PyMethodDef Scale_methods[] =
3790 {
3791 {"getServer", (PyCFunction)Scale_getServer, METH_NOARGS, "Returns server object."},
3792 {"_getStream", (PyCFunction)Scale_getStream, METH_NOARGS, "Returns stream object."},
3793 {"play", (PyCFunction)Scale_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
3794 {"out", (PyCFunction)Scale_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
3795 {"stop", (PyCFunction)Scale_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
3796 {"setInMin", (PyCFunction)Scale_setInMin, METH_O, "Sets input minimum scaling value."},
3797 {"setInMax", (PyCFunction)Scale_setInMax, METH_O, "Sets input maximum scaling value."},
3798 {"setOutMin", (PyCFunction)Scale_setOutMin, METH_O, "Sets output minimum scaling value."},
3799 {"setOutMax", (PyCFunction)Scale_setOutMax, METH_O, "Sets output maximum scaling value."},
3800 {"setExp", (PyCFunction)Scale_setExp, METH_O, "Sets exponent factor."},
3801 {"setMul", (PyCFunction)Scale_setMul, METH_O, "Sets oscillator mul factor."},
3802 {"setAdd", (PyCFunction)Scale_setAdd, METH_O, "Sets oscillator add factor."},
3803 {"setSub", (PyCFunction)Scale_setSub, METH_O, "Sets inverse add factor."},
3804 {"setDiv", (PyCFunction)Scale_setDiv, METH_O, "Sets inverse mul factor."},
3805 {NULL} /* Sentinel */
3806 };
3807
3808 static PyNumberMethods Scale_as_number =
3809 {
3810 (binaryfunc)Scale_add, /*nb_add*/
3811 (binaryfunc)Scale_sub, /*nb_subtract*/
3812 (binaryfunc)Scale_multiply, /*nb_multiply*/
3813 0, /*nb_remainder*/
3814 0, /*nb_divmod*/
3815 0, /*nb_power*/
3816 0, /*nb_neg*/
3817 0, /*nb_pos*/
3818 0, /*(unaryfunc)array_abs,*/
3819 0, /*nb_nonzero*/
3820 0, /*nb_invert*/
3821 0, /*nb_lshift*/
3822 0, /*nb_rshift*/
3823 0, /*nb_and*/
3824 0, /*nb_xor*/
3825 0, /*nb_or*/
3826 0, /*nb_int*/
3827 0, /*nb_long*/
3828 0, /*nb_float*/
3829 (binaryfunc)Scale_inplace_add, /*inplace_add*/
3830 (binaryfunc)Scale_inplace_sub, /*inplace_subtract*/
3831 (binaryfunc)Scale_inplace_multiply, /*inplace_multiply*/
3832 0, /*inplace_remainder*/
3833 0, /*inplace_power*/
3834 0, /*inplace_lshift*/
3835 0, /*inplace_rshift*/
3836 0, /*inplace_and*/
3837 0, /*inplace_xor*/
3838 0, /*inplace_or*/
3839 0, /*nb_floor_divide*/
3840 (binaryfunc)Scale_div, /*nb_true_divide*/
3841 0, /*nb_inplace_floor_divide*/
3842 (binaryfunc)Scale_inplace_div, /*nb_inplace_true_divide*/
3843 0, /* nb_index */
3844 };
3845
3846 PyTypeObject ScaleType =
3847 {
3848 PyVarObject_HEAD_INIT(NULL, 0)
3849 "_pyo.Scale_base", /*tp_name*/
3850 sizeof(Scale), /*tp_basicsize*/
3851 0, /*tp_itemsize*/
3852 (destructor)Scale_dealloc, /*tp_dealloc*/
3853 0, /*tp_print*/
3854 0, /*tp_getattr*/
3855 0, /*tp_setattr*/
3856 0, /*tp_as_async (tp_compare in Python 2)*/
3857 0, /*tp_repr*/
3858 &Scale_as_number, /*tp_as_number*/
3859 0, /*tp_as_sequence*/
3860 0, /*tp_as_mapping*/
3861 0, /*tp_hash */
3862 0, /*tp_call*/
3863 0, /*tp_str*/
3864 0, /*tp_getattro*/
3865 0, /*tp_setattro*/
3866 0, /*tp_as_buffer*/
3867 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
3868 "Scale objects. Scale input values on an arbitrary output scaling range.", /* tp_doc */
3869 (traverseproc)Scale_traverse, /* tp_traverse */
3870 (inquiry)Scale_clear, /* tp_clear */
3871 0, /* tp_richcompare */
3872 0, /* tp_weaklistoffset */
3873 0, /* tp_iter */
3874 0, /* tp_iternext */
3875 Scale_methods, /* tp_methods */
3876 Scale_members, /* tp_members */
3877 0, /* tp_getset */
3878 0, /* tp_base */
3879 0, /* tp_dict */
3880 0, /* tp_descr_get */
3881 0, /* tp_descr_set */
3882 0, /* tp_dictoffset */
3883 0, /* tp_init */
3884 0, /* tp_alloc */
3885 Scale_new, /* tp_new */
3886 };
3887
3888 /************/
3889 /* CentsToTranspo */
3890 /************/
3891 typedef struct
3892 {
3893 pyo_audio_HEAD
3894 PyObject *input;
3895 Stream *input_stream;
3896 MYFLT lastcents;
3897 MYFLT curtranspo;
3898 int modebuffer[2]; // need at least 2 slots for mul & add
3899 } CentsToTranspo;
3900
3901 static void
3902 CentsToTranspo_process(CentsToTranspo *self)
3903 {
3904 int i;
3905 MYFLT cents;
3906 MYFLT *in = Stream_getData((Stream *)self->input_stream);
3907
3908 for (i = 0; i < self->bufsize; i++)
3909 {
3910 cents = in[i];
3911
3912 if (cents != self->lastcents)
3913 {
3914 self->data[i] = self->curtranspo = MYPOW(2.0, cents / 1200.);
3915 self->lastcents = cents;
3916 }
3917 else
3918 self->data[i] = self->curtranspo;
3919 }
3920 }
3921
3922 static void CentsToTranspo_postprocessing_ii(CentsToTranspo *self) { POST_PROCESSING_II };
3923 static void CentsToTranspo_postprocessing_ai(CentsToTranspo *self) { POST_PROCESSING_AI };
3924 static void CentsToTranspo_postprocessing_ia(CentsToTranspo *self) { POST_PROCESSING_IA };
3925 static void CentsToTranspo_postprocessing_aa(CentsToTranspo *self) { POST_PROCESSING_AA };
3926 static void CentsToTranspo_postprocessing_ireva(CentsToTranspo *self) { POST_PROCESSING_IREVA };
3927 static void CentsToTranspo_postprocessing_areva(CentsToTranspo *self) { POST_PROCESSING_AREVA };
3928 static void CentsToTranspo_postprocessing_revai(CentsToTranspo *self) { POST_PROCESSING_REVAI };
3929 static void CentsToTranspo_postprocessing_revaa(CentsToTranspo *self) { POST_PROCESSING_REVAA };
3930 static void CentsToTranspo_postprocessing_revareva(CentsToTranspo *self) { POST_PROCESSING_REVAREVA };
3931
3932 static void
3933 CentsToTranspo_setProcMode(CentsToTranspo *self)
3934 {
3935 int muladdmode;
3936 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
3937
3938 self->proc_func_ptr = CentsToTranspo_process;
3939
3940 switch (muladdmode)
3941 {
3942 case 0:
3943 self->muladd_func_ptr = CentsToTranspo_postprocessing_ii;
3944 break;
3945
3946 case 1:
3947 self->muladd_func_ptr = CentsToTranspo_postprocessing_ai;
3948 break;
3949
3950 case 2:
3951 self->muladd_func_ptr = CentsToTranspo_postprocessing_revai;
3952 break;
3953
3954 case 10:
3955 self->muladd_func_ptr = CentsToTranspo_postprocessing_ia;
3956 break;
3957
3958 case 11:
3959 self->muladd_func_ptr = CentsToTranspo_postprocessing_aa;
3960 break;
3961
3962 case 12:
3963 self->muladd_func_ptr = CentsToTranspo_postprocessing_revaa;
3964 break;
3965
3966 case 20:
3967 self->muladd_func_ptr = CentsToTranspo_postprocessing_ireva;
3968 break;
3969
3970 case 21:
3971 self->muladd_func_ptr = CentsToTranspo_postprocessing_areva;
3972 break;
3973
3974 case 22:
3975 self->muladd_func_ptr = CentsToTranspo_postprocessing_revareva;
3976 break;
3977 }
3978 }
3979
3980 static void
3981 CentsToTranspo_compute_next_data_frame(CentsToTranspo *self)
3982 {
3983 (*self->proc_func_ptr)(self);
3984 (*self->muladd_func_ptr)(self);
3985 }
3986
3987 static int
3988 CentsToTranspo_traverse(CentsToTranspo *self, visitproc visit, void *arg)
3989 {
3990 pyo_VISIT
3991 Py_VISIT(self->input);
3992 return 0;
3993 }
3994
3995 static int
3996 CentsToTranspo_clear(CentsToTranspo *self)
3997 {
3998 pyo_CLEAR
3999 Py_CLEAR(self->input);
4000 return 0;
4001 }
4002
4003 static void
4004 CentsToTranspo_dealloc(CentsToTranspo* self)
4005 {
4006 pyo_DEALLOC
4007 CentsToTranspo_clear(self);
4008 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
4009 Py_TYPE(self)->tp_free((PyObject*)self);
4010 }
4011
4012 static PyObject *
4013 CentsToTranspo_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4014 {
4015 int i;
4016 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
4017 CentsToTranspo *self;
4018 self = (CentsToTranspo *)type->tp_alloc(type, 0);
4019
4020 self->lastcents = 0.0;
4021 self->curtranspo = 1.0;
4022 self->modebuffer[0] = 0;
4023 self->modebuffer[1] = 0;
4024
4025 INIT_OBJECT_COMMON
4026 Stream_setFunctionPtr(self->stream, CentsToTranspo_compute_next_data_frame);
4027 self->mode_func_ptr = CentsToTranspo_setProcMode;
4028
4029 static char *kwlist[] = {"input", "mul", "add", NULL};
4030
4031 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
4032 Py_RETURN_NONE;
4033
4034 INIT_INPUT_STREAM
4035
4036 if (multmp)
4037 {
4038 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
4039 }
4040
4041 if (addtmp)
4042 {
4043 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
4044 }
4045
4046 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
4047
4048 (*self->mode_func_ptr)(self);
4049
4050 return (PyObject *)self;
4051 }
4052
4053 static PyObject * CentsToTranspo_getServer(CentsToTranspo* self) { GET_SERVER };
4054 static PyObject * CentsToTranspo_getStream(CentsToTranspo* self) { GET_STREAM };
4055 static PyObject * CentsToTranspo_setMul(CentsToTranspo *self, PyObject *arg) { SET_MUL };
4056 static PyObject * CentsToTranspo_setAdd(CentsToTranspo *self, PyObject *arg) { SET_ADD };
4057 static PyObject * CentsToTranspo_setSub(CentsToTranspo *self, PyObject *arg) { SET_SUB };
4058 static PyObject * CentsToTranspo_setDiv(CentsToTranspo *self, PyObject *arg) { SET_DIV };
4059
4060 static PyObject * CentsToTranspo_play(CentsToTranspo *self, PyObject *args, PyObject *kwds) { PLAY };
4061 static PyObject * CentsToTranspo_out(CentsToTranspo *self, PyObject *args, PyObject *kwds) { OUT };
4062 static PyObject * CentsToTranspo_stop(CentsToTranspo *self, PyObject *args, PyObject *kwds) { STOP };
4063
4064 static PyObject * CentsToTranspo_multiply(CentsToTranspo *self, PyObject *arg) { MULTIPLY };
4065 static PyObject * CentsToTranspo_inplace_multiply(CentsToTranspo *self, PyObject *arg) { INPLACE_MULTIPLY };
4066 static PyObject * CentsToTranspo_add(CentsToTranspo *self, PyObject *arg) { ADD };
4067 static PyObject * CentsToTranspo_inplace_add(CentsToTranspo *self, PyObject *arg) { INPLACE_ADD };
4068 static PyObject * CentsToTranspo_sub(CentsToTranspo *self, PyObject *arg) { SUB };
4069 static PyObject * CentsToTranspo_inplace_sub(CentsToTranspo *self, PyObject *arg) { INPLACE_SUB };
4070 static PyObject * CentsToTranspo_div(CentsToTranspo *self, PyObject *arg) { DIV };
4071 static PyObject * CentsToTranspo_inplace_div(CentsToTranspo *self, PyObject *arg) { INPLACE_DIV };
4072
4073 static PyMemberDef CentsToTranspo_members[] =
4074 {
4075 {"server", T_OBJECT_EX, offsetof(CentsToTranspo, server), 0, "Pyo server."},
4076 {"stream", T_OBJECT_EX, offsetof(CentsToTranspo, stream), 0, "Stream object."},
4077 {"input", T_OBJECT_EX, offsetof(CentsToTranspo, input), 0, "Input sound object."},
4078 {"mul", T_OBJECT_EX, offsetof(CentsToTranspo, mul), 0, "Mul factor."},
4079 {"add", T_OBJECT_EX, offsetof(CentsToTranspo, add), 0, "Add factor."},
4080 {NULL} /* Sentinel */
4081 };
4082
4083 static PyMethodDef CentsToTranspo_methods[] =
4084 {
4085 {"getServer", (PyCFunction)CentsToTranspo_getServer, METH_NOARGS, "Returns server object."},
4086 {"_getStream", (PyCFunction)CentsToTranspo_getStream, METH_NOARGS, "Returns stream object."},
4087 {"play", (PyCFunction)CentsToTranspo_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
4088 {"stop", (PyCFunction)CentsToTranspo_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
4089 {"out", (PyCFunction)CentsToTranspo_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
4090 {"setMul", (PyCFunction)CentsToTranspo_setMul, METH_O, "Sets oscillator mul factor."},
4091 {"setAdd", (PyCFunction)CentsToTranspo_setAdd, METH_O, "Sets oscillator add factor."},
4092 {"setSub", (PyCFunction)CentsToTranspo_setSub, METH_O, "Sets inverse add factor."},
4093 {"setDiv", (PyCFunction)CentsToTranspo_setDiv, METH_O, "Sets inverse mul factor."},
4094 {NULL} /* Sentinel */
4095 };
4096
4097 static PyNumberMethods CentsToTranspo_as_number =
4098 {
4099 (binaryfunc)CentsToTranspo_add, /*nb_add*/
4100 (binaryfunc)CentsToTranspo_sub, /*nb_subtract*/
4101 (binaryfunc)CentsToTranspo_multiply, /*nb_multiply*/
4102 0, /*nb_remainder*/
4103 0, /*nb_divmod*/
4104 0, /*nb_power*/
4105 0, /*nb_neg*/
4106 0, /*nb_pos*/
4107 0, /*(unaryfunc)array_abs,*/
4108 0, /*nb_nonzero*/
4109 0, /*nb_invert*/
4110 0, /*nb_lshift*/
4111 0, /*nb_rshift*/
4112 0, /*nb_and*/
4113 0, /*nb_xor*/
4114 0, /*nb_or*/
4115 0, /*nb_int*/
4116 0, /*nb_long*/
4117 0, /*nb_float*/
4118 (binaryfunc)CentsToTranspo_inplace_add, /*inplace_add*/
4119 (binaryfunc)CentsToTranspo_inplace_sub, /*inplace_subtract*/
4120 (binaryfunc)CentsToTranspo_inplace_multiply, /*inplace_multiply*/
4121 0, /*inplace_remainder*/
4122 0, /*inplace_power*/
4123 0, /*inplace_lshift*/
4124 0, /*inplace_rshift*/
4125 0, /*inplace_and*/
4126 0, /*inplace_xor*/
4127 0, /*inplace_or*/
4128 0, /*nb_floor_divide*/
4129 (binaryfunc)CentsToTranspo_div, /*nb_true_divide*/
4130 0, /*nb_inplace_floor_divide*/
4131 (binaryfunc)CentsToTranspo_inplace_div, /*nb_inplace_true_divide*/
4132 0, /* nb_index */
4133 };
4134
4135 PyTypeObject CentsToTranspoType =
4136 {
4137 PyVarObject_HEAD_INIT(NULL, 0)
4138 "_pyo.CentsToTranspo_base", /*tp_name*/
4139 sizeof(CentsToTranspo), /*tp_basicsize*/
4140 0, /*tp_itemsize*/
4141 (destructor)CentsToTranspo_dealloc, /*tp_dealloc*/
4142 0, /*tp_print*/
4143 0, /*tp_getattr*/
4144 0, /*tp_setattr*/
4145 0, /*tp_as_async (tp_compare in Python 2)*/
4146 0, /*tp_repr*/
4147 &CentsToTranspo_as_number, /*tp_as_number*/
4148 0, /*tp_as_sequence*/
4149 0, /*tp_as_mapping*/
4150 0, /*tp_hash */
4151 0, /*tp_call*/
4152 0, /*tp_str*/
4153 0, /*tp_getattro*/
4154 0, /*tp_setattro*/
4155 0, /*tp_as_buffer*/
4156 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
4157 "CentsToTranspo objects. Converts cents value to transposition factor.", /* tp_doc */
4158 (traverseproc)CentsToTranspo_traverse, /* tp_traverse */
4159 (inquiry)CentsToTranspo_clear, /* tp_clear */
4160 0, /* tp_richcompare */
4161 0, /* tp_weaklistoffset */
4162 0, /* tp_iter */
4163 0, /* tp_iternext */
4164 CentsToTranspo_methods, /* tp_methods */
4165 CentsToTranspo_members, /* tp_members */
4166 0, /* tp_getset */
4167 0, /* tp_base */
4168 0, /* tp_dict */
4169 0, /* tp_descr_get */
4170 0, /* tp_descr_set */
4171 0, /* tp_dictoffset */
4172 0, /* tp_init */
4173 0, /* tp_alloc */
4174 CentsToTranspo_new, /* tp_new */
4175 };
4176
4177 /************/
4178 /* TranspoToCents */
4179 /************/
4180 typedef struct
4181 {
4182 pyo_audio_HEAD
4183 PyObject *input;
4184 Stream *input_stream;
4185 MYFLT lasttranspo;
4186 MYFLT curcents;
4187 int modebuffer[2]; // need at least 2 slots for mul & add
4188 } TranspoToCents;
4189
4190 static void
4191 TranspoToCents_process(TranspoToCents *self)
4192 {
4193 int i;
4194 MYFLT transpo;
4195 MYFLT *in = Stream_getData((Stream *)self->input_stream);
4196
4197 for (i = 0; i < self->bufsize; i++)
4198 {
4199 transpo = in[i];
4200
4201 if (transpo != self->lasttranspo)
4202 {
4203 self->data[i] = self->curcents = 1200.0 * MYLOG2(transpo);
4204 self->lasttranspo = transpo;
4205 }
4206 else
4207 self->data[i] = self->curcents;
4208 }
4209 }
4210
4211 static void TranspoToCents_postprocessing_ii(TranspoToCents *self) { POST_PROCESSING_II };
4212 static void TranspoToCents_postprocessing_ai(TranspoToCents *self) { POST_PROCESSING_AI };
4213 static void TranspoToCents_postprocessing_ia(TranspoToCents *self) { POST_PROCESSING_IA };
4214 static void TranspoToCents_postprocessing_aa(TranspoToCents *self) { POST_PROCESSING_AA };
4215 static void TranspoToCents_postprocessing_ireva(TranspoToCents *self) { POST_PROCESSING_IREVA };
4216 static void TranspoToCents_postprocessing_areva(TranspoToCents *self) { POST_PROCESSING_AREVA };
4217 static void TranspoToCents_postprocessing_revai(TranspoToCents *self) { POST_PROCESSING_REVAI };
4218 static void TranspoToCents_postprocessing_revaa(TranspoToCents *self) { POST_PROCESSING_REVAA };
4219 static void TranspoToCents_postprocessing_revareva(TranspoToCents *self) { POST_PROCESSING_REVAREVA };
4220
4221 static void
4222 TranspoToCents_setProcMode(TranspoToCents *self)
4223 {
4224 int muladdmode;
4225 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
4226
4227 self->proc_func_ptr = TranspoToCents_process;
4228
4229 switch (muladdmode)
4230 {
4231 case 0:
4232 self->muladd_func_ptr = TranspoToCents_postprocessing_ii;
4233 break;
4234
4235 case 1:
4236 self->muladd_func_ptr = TranspoToCents_postprocessing_ai;
4237 break;
4238
4239 case 2:
4240 self->muladd_func_ptr = TranspoToCents_postprocessing_revai;
4241 break;
4242
4243 case 10:
4244 self->muladd_func_ptr = TranspoToCents_postprocessing_ia;
4245 break;
4246
4247 case 11:
4248 self->muladd_func_ptr = TranspoToCents_postprocessing_aa;
4249 break;
4250
4251 case 12:
4252 self->muladd_func_ptr = TranspoToCents_postprocessing_revaa;
4253 break;
4254
4255 case 20:
4256 self->muladd_func_ptr = TranspoToCents_postprocessing_ireva;
4257 break;
4258
4259 case 21:
4260 self->muladd_func_ptr = TranspoToCents_postprocessing_areva;
4261 break;
4262
4263 case 22:
4264 self->muladd_func_ptr = TranspoToCents_postprocessing_revareva;
4265 break;
4266 }
4267 }
4268
4269 static void
4270 TranspoToCents_compute_next_data_frame(TranspoToCents *self)
4271 {
4272 (*self->proc_func_ptr)(self);
4273 (*self->muladd_func_ptr)(self);
4274 }
4275
4276 static int
4277 TranspoToCents_traverse(TranspoToCents *self, visitproc visit, void *arg)
4278 {
4279 pyo_VISIT
4280 Py_VISIT(self->input);
4281 return 0;
4282 }
4283
4284 static int
4285 TranspoToCents_clear(TranspoToCents *self)
4286 {
4287 pyo_CLEAR
4288 Py_CLEAR(self->input);
4289 return 0;
4290 }
4291
4292 static void
4293 TranspoToCents_dealloc(TranspoToCents* self)
4294 {
4295 pyo_DEALLOC
4296 TranspoToCents_clear(self);
4297 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
4298 Py_TYPE(self)->tp_free((PyObject*)self);
4299 }
4300
4301 static PyObject *
4302 TranspoToCents_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4303 {
4304 int i;
4305 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
4306 TranspoToCents *self;
4307 self = (TranspoToCents *)type->tp_alloc(type, 0);
4308
4309 self->lasttranspo = 1.0;
4310 self->curcents = 0.0;
4311 self->modebuffer[0] = 0;
4312 self->modebuffer[1] = 0;
4313
4314 INIT_OBJECT_COMMON
4315 Stream_setFunctionPtr(self->stream, TranspoToCents_compute_next_data_frame);
4316 self->mode_func_ptr = TranspoToCents_setProcMode;
4317
4318 static char *kwlist[] = {"input", "mul", "add", NULL};
4319
4320 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
4321 Py_RETURN_NONE;
4322
4323 INIT_INPUT_STREAM
4324
4325 if (multmp)
4326 {
4327 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
4328 }
4329
4330 if (addtmp)
4331 {
4332 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
4333 }
4334
4335 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
4336
4337 (*self->mode_func_ptr)(self);
4338
4339 return (PyObject *)self;
4340 }
4341
4342 static PyObject * TranspoToCents_getServer(TranspoToCents* self) { GET_SERVER };
4343 static PyObject * TranspoToCents_getStream(TranspoToCents* self) { GET_STREAM };
4344 static PyObject * TranspoToCents_setMul(TranspoToCents *self, PyObject *arg) { SET_MUL };
4345 static PyObject * TranspoToCents_setAdd(TranspoToCents *self, PyObject *arg) { SET_ADD };
4346 static PyObject * TranspoToCents_setSub(TranspoToCents *self, PyObject *arg) { SET_SUB };
4347 static PyObject * TranspoToCents_setDiv(TranspoToCents *self, PyObject *arg) { SET_DIV };
4348
4349 static PyObject * TranspoToCents_play(TranspoToCents *self, PyObject *args, PyObject *kwds) { PLAY };
4350 static PyObject * TranspoToCents_out(TranspoToCents *self, PyObject *args, PyObject *kwds) { OUT };
4351 static PyObject * TranspoToCents_stop(TranspoToCents *self, PyObject *args, PyObject *kwds) { STOP };
4352
4353 static PyObject * TranspoToCents_multiply(TranspoToCents *self, PyObject *arg) { MULTIPLY };
4354 static PyObject * TranspoToCents_inplace_multiply(TranspoToCents *self, PyObject *arg) { INPLACE_MULTIPLY };
4355 static PyObject * TranspoToCents_add(TranspoToCents *self, PyObject *arg) { ADD };
4356 static PyObject * TranspoToCents_inplace_add(TranspoToCents *self, PyObject *arg) { INPLACE_ADD };
4357 static PyObject * TranspoToCents_sub(TranspoToCents *self, PyObject *arg) { SUB };
4358 static PyObject * TranspoToCents_inplace_sub(TranspoToCents *self, PyObject *arg) { INPLACE_SUB };
4359 static PyObject * TranspoToCents_div(TranspoToCents *self, PyObject *arg) { DIV };
4360 static PyObject * TranspoToCents_inplace_div(TranspoToCents *self, PyObject *arg) { INPLACE_DIV };
4361
4362 static PyMemberDef TranspoToCents_members[] =
4363 {
4364 {"server", T_OBJECT_EX, offsetof(TranspoToCents, server), 0, "Pyo server."},
4365 {"stream", T_OBJECT_EX, offsetof(TranspoToCents, stream), 0, "Stream object."},
4366 {"input", T_OBJECT_EX, offsetof(TranspoToCents, input), 0, "Input sound object."},
4367 {"mul", T_OBJECT_EX, offsetof(TranspoToCents, mul), 0, "Mul factor."},
4368 {"add", T_OBJECT_EX, offsetof(TranspoToCents, add), 0, "Add factor."},
4369 {NULL} /* Sentinel */
4370 };
4371
4372 static PyMethodDef TranspoToCents_methods[] =
4373 {
4374 {"getServer", (PyCFunction)TranspoToCents_getServer, METH_NOARGS, "Returns server object."},
4375 {"_getStream", (PyCFunction)TranspoToCents_getStream, METH_NOARGS, "Returns stream object."},
4376 {"play", (PyCFunction)TranspoToCents_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
4377 {"stop", (PyCFunction)TranspoToCents_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
4378 {"out", (PyCFunction)TranspoToCents_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
4379 {"setMul", (PyCFunction)TranspoToCents_setMul, METH_O, "Sets oscillator mul factor."},
4380 {"setAdd", (PyCFunction)TranspoToCents_setAdd, METH_O, "Sets oscillator add factor."},
4381 {"setSub", (PyCFunction)TranspoToCents_setSub, METH_O, "Sets inverse add factor."},
4382 {"setDiv", (PyCFunction)TranspoToCents_setDiv, METH_O, "Sets inverse mul factor."},
4383 {NULL} /* Sentinel */
4384 };
4385
4386 static PyNumberMethods TranspoToCents_as_number =
4387 {
4388 (binaryfunc)TranspoToCents_add, /*nb_add*/
4389 (binaryfunc)TranspoToCents_sub, /*nb_subtract*/
4390 (binaryfunc)TranspoToCents_multiply, /*nb_multiply*/
4391 0, /*nb_remainder*/
4392 0, /*nb_divmod*/
4393 0, /*nb_power*/
4394 0, /*nb_neg*/
4395 0, /*nb_pos*/
4396 0, /*(unaryfunc)array_abs,*/
4397 0, /*nb_nonzero*/
4398 0, /*nb_invert*/
4399 0, /*nb_lshift*/
4400 0, /*nb_rshift*/
4401 0, /*nb_and*/
4402 0, /*nb_xor*/
4403 0, /*nb_or*/
4404 0, /*nb_int*/
4405 0, /*nb_long*/
4406 0, /*nb_float*/
4407 (binaryfunc)TranspoToCents_inplace_add, /*inplace_add*/
4408 (binaryfunc)TranspoToCents_inplace_sub, /*inplace_subtract*/
4409 (binaryfunc)TranspoToCents_inplace_multiply, /*inplace_multiply*/
4410 0, /*inplace_remainder*/
4411 0, /*inplace_power*/
4412 0, /*inplace_lshift*/
4413 0, /*inplace_rshift*/
4414 0, /*inplace_and*/
4415 0, /*inplace_xor*/
4416 0, /*inplace_or*/
4417 0, /*nb_floor_divide*/
4418 (binaryfunc)TranspoToCents_div, /*nb_true_divide*/
4419 0, /*nb_inplace_floor_divide*/
4420 (binaryfunc)TranspoToCents_inplace_div, /*nb_inplace_true_divide*/
4421 0, /* nb_index */
4422 };
4423
4424 PyTypeObject TranspoToCentsType =
4425 {
4426 PyVarObject_HEAD_INIT(NULL, 0)
4427 "_pyo.TranspoToCents_base", /*tp_name*/
4428 sizeof(TranspoToCents), /*tp_basicsize*/
4429 0, /*tp_itemsize*/
4430 (destructor)TranspoToCents_dealloc, /*tp_dealloc*/
4431 0, /*tp_print*/
4432 0, /*tp_getattr*/
4433 0, /*tp_setattr*/
4434 0, /*tp_as_async (tp_compare in Python 2)*/
4435 0, /*tp_repr*/
4436 &TranspoToCents_as_number, /*tp_as_number*/
4437 0, /*tp_as_sequence*/
4438 0, /*tp_as_mapping*/
4439 0, /*tp_hash */
4440 0, /*tp_call*/
4441 0, /*tp_str*/
4442 0, /*tp_getattro*/
4443 0, /*tp_setattro*/
4444 0, /*tp_as_buffer*/
4445 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
4446 "TranspoToCents objects. Converts transposition factor to cents value.", /* tp_doc */
4447 (traverseproc)TranspoToCents_traverse, /* tp_traverse */
4448 (inquiry)TranspoToCents_clear, /* tp_clear */
4449 0, /* tp_richcompare */
4450 0, /* tp_weaklistoffset */
4451 0, /* tp_iter */
4452 0, /* tp_iternext */
4453 TranspoToCents_methods, /* tp_methods */
4454 TranspoToCents_members, /* tp_members */
4455 0, /* tp_getset */
4456 0, /* tp_base */
4457 0, /* tp_dict */
4458 0, /* tp_descr_get */
4459 0, /* tp_descr_set */
4460 0, /* tp_dictoffset */
4461 0, /* tp_init */
4462 0, /* tp_alloc */
4463 TranspoToCents_new, /* tp_new */
4464 };
4465
4466 /************/
4467 /* MToF */
4468 /************/
4469
4470 static MYFLT
4471 Midi_clip(MYFLT x)
4472 {
4473 static MYFLT max = 256.0;
4474 return x > max ? max : x < -max ? -max : x;
4475 }
4476
4477 typedef struct
4478 {
4479 pyo_audio_HEAD
4480 PyObject *input;
4481 Stream *input_stream;
4482 MYFLT lastmidi;
4483 MYFLT curfreq;
4484 int modebuffer[2]; // need at least 2 slots for mul & add
4485 } MToF;
4486
4487 static void
4488 MToF_process(MToF *self)
4489 {
4490 int i;
4491 MYFLT midi;
4492 MYFLT *in = Stream_getData((Stream *)self->input_stream);
4493
4494 for (i = 0; i < self->bufsize; i++)
4495 {
4496 midi = Midi_clip(in[i]);
4497
4498 if (midi != self->lastmidi)
4499 {
4500 self->data[i] = self->curfreq = 440.0 * MYPOW(2.0, (midi - 69) / 12.0);
4501 self->lastmidi = midi;
4502 }
4503 else
4504 self->data[i] = self->curfreq;
4505 }
4506 }
4507
4508 static void MToF_postprocessing_ii(MToF *self) { POST_PROCESSING_II };
4509 static void MToF_postprocessing_ai(MToF *self) { POST_PROCESSING_AI };
4510 static void MToF_postprocessing_ia(MToF *self) { POST_PROCESSING_IA };
4511 static void MToF_postprocessing_aa(MToF *self) { POST_PROCESSING_AA };
4512 static void MToF_postprocessing_ireva(MToF *self) { POST_PROCESSING_IREVA };
4513 static void MToF_postprocessing_areva(MToF *self) { POST_PROCESSING_AREVA };
4514 static void MToF_postprocessing_revai(MToF *self) { POST_PROCESSING_REVAI };
4515 static void MToF_postprocessing_revaa(MToF *self) { POST_PROCESSING_REVAA };
4516 static void MToF_postprocessing_revareva(MToF *self) { POST_PROCESSING_REVAREVA };
4517
4518 static void
4519 MToF_setProcMode(MToF *self)
4520 {
4521 int muladdmode;
4522 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
4523
4524 self->proc_func_ptr = MToF_process;
4525
4526 switch (muladdmode)
4527 {
4528 case 0:
4529 self->muladd_func_ptr = MToF_postprocessing_ii;
4530 break;
4531
4532 case 1:
4533 self->muladd_func_ptr = MToF_postprocessing_ai;
4534 break;
4535
4536 case 2:
4537 self->muladd_func_ptr = MToF_postprocessing_revai;
4538 break;
4539
4540 case 10:
4541 self->muladd_func_ptr = MToF_postprocessing_ia;
4542 break;
4543
4544 case 11:
4545 self->muladd_func_ptr = MToF_postprocessing_aa;
4546 break;
4547
4548 case 12:
4549 self->muladd_func_ptr = MToF_postprocessing_revaa;
4550 break;
4551
4552 case 20:
4553 self->muladd_func_ptr = MToF_postprocessing_ireva;
4554 break;
4555
4556 case 21:
4557 self->muladd_func_ptr = MToF_postprocessing_areva;
4558 break;
4559
4560 case 22:
4561 self->muladd_func_ptr = MToF_postprocessing_revareva;
4562 break;
4563 }
4564 }
4565
4566 static void
4567 MToF_compute_next_data_frame(MToF *self)
4568 {
4569 (*self->proc_func_ptr)(self);
4570 (*self->muladd_func_ptr)(self);
4571 }
4572
4573 static int
4574 MToF_traverse(MToF *self, visitproc visit, void *arg)
4575 {
4576 pyo_VISIT
4577 Py_VISIT(self->input);
4578 return 0;
4579 }
4580
4581 static int
4582 MToF_clear(MToF *self)
4583 {
4584 pyo_CLEAR
4585 Py_CLEAR(self->input);
4586 return 0;
4587 }
4588
4589 static void
4590 MToF_dealloc(MToF* self)
4591 {
4592 pyo_DEALLOC
4593 MToF_clear(self);
4594 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
4595 Py_TYPE(self)->tp_free((PyObject*)self);
4596 }
4597
4598 static PyObject *
4599 MToF_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4600 {
4601 int i;
4602 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
4603 MToF *self;
4604 self = (MToF *)type->tp_alloc(type, 0);
4605
4606 self->lastmidi = 0;
4607 self->curfreq = 8.1757989156437;
4608 self->modebuffer[0] = 0;
4609 self->modebuffer[1] = 0;
4610
4611 INIT_OBJECT_COMMON
4612 Stream_setFunctionPtr(self->stream, MToF_compute_next_data_frame);
4613 self->mode_func_ptr = MToF_setProcMode;
4614
4615 static char *kwlist[] = {"input", "mul", "add", NULL};
4616
4617 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
4618 Py_RETURN_NONE;
4619
4620 INIT_INPUT_STREAM
4621
4622 if (multmp)
4623 {
4624 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
4625 }
4626
4627 if (addtmp)
4628 {
4629 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
4630 }
4631
4632 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
4633
4634 (*self->mode_func_ptr)(self);
4635
4636 return (PyObject *)self;
4637 }
4638
4639 static PyObject * MToF_getServer(MToF* self) { GET_SERVER };
4640 static PyObject * MToF_getStream(MToF* self) { GET_STREAM };
4641 static PyObject * MToF_setMul(MToF *self, PyObject *arg) { SET_MUL };
4642 static PyObject * MToF_setAdd(MToF *self, PyObject *arg) { SET_ADD };
4643 static PyObject * MToF_setSub(MToF *self, PyObject *arg) { SET_SUB };
4644 static PyObject * MToF_setDiv(MToF *self, PyObject *arg) { SET_DIV };
4645
4646 static PyObject * MToF_play(MToF *self, PyObject *args, PyObject *kwds) { PLAY };
4647 static PyObject * MToF_out(MToF *self, PyObject *args, PyObject *kwds) { OUT };
4648 static PyObject * MToF_stop(MToF *self, PyObject *args, PyObject *kwds) { STOP };
4649
4650 static PyObject * MToF_multiply(MToF *self, PyObject *arg) { MULTIPLY };
4651 static PyObject * MToF_inplace_multiply(MToF *self, PyObject *arg) { INPLACE_MULTIPLY };
4652 static PyObject * MToF_add(MToF *self, PyObject *arg) { ADD };
4653 static PyObject * MToF_inplace_add(MToF *self, PyObject *arg) { INPLACE_ADD };
4654 static PyObject * MToF_sub(MToF *self, PyObject *arg) { SUB };
4655 static PyObject * MToF_inplace_sub(MToF *self, PyObject *arg) { INPLACE_SUB };
4656 static PyObject * MToF_div(MToF *self, PyObject *arg) { DIV };
4657 static PyObject * MToF_inplace_div(MToF *self, PyObject *arg) { INPLACE_DIV };
4658
4659 static PyMemberDef MToF_members[] =
4660 {
4661 {"server", T_OBJECT_EX, offsetof(MToF, server), 0, "Pyo server."},
4662 {"stream", T_OBJECT_EX, offsetof(MToF, stream), 0, "Stream object."},
4663 {"input", T_OBJECT_EX, offsetof(MToF, input), 0, "Input sound object."},
4664 {"mul", T_OBJECT_EX, offsetof(MToF, mul), 0, "Mul factor."},
4665 {"add", T_OBJECT_EX, offsetof(MToF, add), 0, "Add factor."},
4666 {NULL} /* Sentinel */
4667 };
4668
4669 static PyMethodDef MToF_methods[] =
4670 {
4671 {"getServer", (PyCFunction)MToF_getServer, METH_NOARGS, "Returns server object."},
4672 {"_getStream", (PyCFunction)MToF_getStream, METH_NOARGS, "Returns stream object."},
4673 {"play", (PyCFunction)MToF_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
4674 {"stop", (PyCFunction)MToF_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
4675 {"out", (PyCFunction)MToF_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
4676 {"setMul", (PyCFunction)MToF_setMul, METH_O, "Sets oscillator mul factor."},
4677 {"setAdd", (PyCFunction)MToF_setAdd, METH_O, "Sets oscillator add factor."},
4678 {"setSub", (PyCFunction)MToF_setSub, METH_O, "Sets inverse add factor."},
4679 {"setDiv", (PyCFunction)MToF_setDiv, METH_O, "Sets inverse mul factor."},
4680 {NULL} /* Sentinel */
4681 };
4682
4683 static PyNumberMethods MToF_as_number =
4684 {
4685 (binaryfunc)MToF_add, /*nb_add*/
4686 (binaryfunc)MToF_sub, /*nb_subtract*/
4687 (binaryfunc)MToF_multiply, /*nb_multiply*/
4688 0, /*nb_remainder*/
4689 0, /*nb_divmod*/
4690 0, /*nb_power*/
4691 0, /*nb_neg*/
4692 0, /*nb_pos*/
4693 0, /*(unaryfunc)array_abs,*/
4694 0, /*nb_nonzero*/
4695 0, /*nb_invert*/
4696 0, /*nb_lshift*/
4697 0, /*nb_rshift*/
4698 0, /*nb_and*/
4699 0, /*nb_xor*/
4700 0, /*nb_or*/
4701 0, /*nb_int*/
4702 0, /*nb_long*/
4703 0, /*nb_float*/
4704 (binaryfunc)MToF_inplace_add, /*inplace_add*/
4705 (binaryfunc)MToF_inplace_sub, /*inplace_subtract*/
4706 (binaryfunc)MToF_inplace_multiply, /*inplace_multiply*/
4707 0, /*inplace_remainder*/
4708 0, /*inplace_power*/
4709 0, /*inplace_lshift*/
4710 0, /*inplace_rshift*/
4711 0, /*inplace_and*/
4712 0, /*inplace_xor*/
4713 0, /*inplace_or*/
4714 0, /*nb_floor_divide*/
4715 (binaryfunc)MToF_div, /*nb_true_divide*/
4716 0, /*nb_inplace_floor_divide*/
4717 (binaryfunc)MToF_inplace_div, /*nb_inplace_true_divide*/
4718 0, /* nb_index */
4719 };
4720
4721 PyTypeObject MToFType =
4722 {
4723 PyVarObject_HEAD_INIT(NULL, 0)
4724 "_pyo.MToF_base", /*tp_name*/
4725 sizeof(MToF), /*tp_basicsize*/
4726 0, /*tp_itemsize*/
4727 (destructor)MToF_dealloc, /*tp_dealloc*/
4728 0, /*tp_print*/
4729 0, /*tp_getattr*/
4730 0, /*tp_setattr*/
4731 0, /*tp_as_async (tp_compare in Python 2)*/
4732 0, /*tp_repr*/
4733 &MToF_as_number, /*tp_as_number*/
4734 0, /*tp_as_sequence*/
4735 0, /*tp_as_mapping*/
4736 0, /*tp_hash */
4737 0, /*tp_call*/
4738 0, /*tp_str*/
4739 0, /*tp_getattro*/
4740 0, /*tp_setattro*/
4741 0, /*tp_as_buffer*/
4742 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
4743 "MToF objects. Converts midi notes to frequency.", /* tp_doc */
4744 (traverseproc)MToF_traverse, /* tp_traverse */
4745 (inquiry)MToF_clear, /* tp_clear */
4746 0, /* tp_richcompare */
4747 0, /* tp_weaklistoffset */
4748 0, /* tp_iter */
4749 0, /* tp_iternext */
4750 MToF_methods, /* tp_methods */
4751 MToF_members, /* tp_members */
4752 0, /* tp_getset */
4753 0, /* tp_base */
4754 0, /* tp_dict */
4755 0, /* tp_descr_get */
4756 0, /* tp_descr_set */
4757 0, /* tp_dictoffset */
4758 0, /* tp_init */
4759 0, /* tp_alloc */
4760 MToF_new, /* tp_new */
4761 };
4762
4763 /************/
4764 /* FToM */
4765 /************/
4766 typedef struct
4767 {
4768 pyo_audio_HEAD
4769 PyObject *input;
4770 Stream *input_stream;
4771 MYFLT lastfreq;
4772 MYFLT curmidi;
4773 int modebuffer[2]; // need at least 2 slots for mul & add
4774 } FToM;
4775
4776 static void
4777 FToM_process(FToM *self)
4778 {
4779 int i;
4780 MYFLT freq;
4781 MYFLT *in = Stream_getData((Stream *)self->input_stream);
4782
4783 for (i = 0; i < self->bufsize; i++)
4784 {
4785 freq = in[i];
4786
4787 if (freq != self->lastfreq)
4788 {
4789 if (freq < 8.1758)
4790 freq = 8.1578;
4791
4792 self->curmidi = 12.0 * MYLOG2(freq / 440.0) + 69;
4793 self->lastfreq = freq;
4794 }
4795 else
4796 self->data[i] = self->curmidi;
4797 }
4798 }
4799
4800 static void FToM_postprocessing_ii(FToM *self) { POST_PROCESSING_II };
4801 static void FToM_postprocessing_ai(FToM *self) { POST_PROCESSING_AI };
4802 static void FToM_postprocessing_ia(FToM *self) { POST_PROCESSING_IA };
4803 static void FToM_postprocessing_aa(FToM *self) { POST_PROCESSING_AA };
4804 static void FToM_postprocessing_ireva(FToM *self) { POST_PROCESSING_IREVA };
4805 static void FToM_postprocessing_areva(FToM *self) { POST_PROCESSING_AREVA };
4806 static void FToM_postprocessing_revai(FToM *self) { POST_PROCESSING_REVAI };
4807 static void FToM_postprocessing_revaa(FToM *self) { POST_PROCESSING_REVAA };
4808 static void FToM_postprocessing_revareva(FToM *self) { POST_PROCESSING_REVAREVA };
4809
4810 static void
4811 FToM_setProcMode(FToM *self)
4812 {
4813 int muladdmode;
4814 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
4815
4816 self->proc_func_ptr = FToM_process;
4817
4818 switch (muladdmode)
4819 {
4820 case 0:
4821 self->muladd_func_ptr = FToM_postprocessing_ii;
4822 break;
4823
4824 case 1:
4825 self->muladd_func_ptr = FToM_postprocessing_ai;
4826 break;
4827
4828 case 2:
4829 self->muladd_func_ptr = FToM_postprocessing_revai;
4830 break;
4831
4832 case 10:
4833 self->muladd_func_ptr = FToM_postprocessing_ia;
4834 break;
4835
4836 case 11:
4837 self->muladd_func_ptr = FToM_postprocessing_aa;
4838 break;
4839
4840 case 12:
4841 self->muladd_func_ptr = FToM_postprocessing_revaa;
4842 break;
4843
4844 case 20:
4845 self->muladd_func_ptr = FToM_postprocessing_ireva;
4846 break;
4847
4848 case 21:
4849 self->muladd_func_ptr = FToM_postprocessing_areva;
4850 break;
4851
4852 case 22:
4853 self->muladd_func_ptr = FToM_postprocessing_revareva;
4854 break;
4855 }
4856 }
4857
4858 static void
4859 FToM_compute_next_data_frame(FToM *self)
4860 {
4861 (*self->proc_func_ptr)(self);
4862 (*self->muladd_func_ptr)(self);
4863 }
4864
4865 static int
4866 FToM_traverse(FToM *self, visitproc visit, void *arg)
4867 {
4868 pyo_VISIT
4869 Py_VISIT(self->input);
4870 return 0;
4871 }
4872
4873 static int
4874 FToM_clear(FToM *self)
4875 {
4876 pyo_CLEAR
4877 Py_CLEAR(self->input);
4878 return 0;
4879 }
4880
4881 static void
4882 FToM_dealloc(FToM* self)
4883 {
4884 pyo_DEALLOC
4885 FToM_clear(self);
4886 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
4887 Py_TYPE(self)->tp_free((PyObject*)self);
4888 }
4889
4890 static PyObject *
4891 FToM_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4892 {
4893 int i;
4894 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
4895 FToM *self;
4896 self = (FToM *)type->tp_alloc(type, 0);
4897
4898 self->lastfreq = 8.1758;
4899 self->curmidi = 0.0;
4900 self->modebuffer[0] = 0;
4901 self->modebuffer[1] = 0;
4902
4903 INIT_OBJECT_COMMON
4904 Stream_setFunctionPtr(self->stream, FToM_compute_next_data_frame);
4905 self->mode_func_ptr = FToM_setProcMode;
4906
4907 static char *kwlist[] = {"input", "mul", "add", NULL};
4908
4909 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
4910 Py_RETURN_NONE;
4911
4912 INIT_INPUT_STREAM
4913
4914 if (multmp)
4915 {
4916 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
4917 }
4918
4919 if (addtmp)
4920 {
4921 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
4922 }
4923
4924 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
4925
4926 (*self->mode_func_ptr)(self);
4927
4928 return (PyObject *)self;
4929 }
4930
4931 static PyObject * FToM_getServer(FToM* self) { GET_SERVER };
4932 static PyObject * FToM_getStream(FToM* self) { GET_STREAM };
4933 static PyObject * FToM_setMul(FToM *self, PyObject *arg) { SET_MUL };
4934 static PyObject * FToM_setAdd(FToM *self, PyObject *arg) { SET_ADD };
4935 static PyObject * FToM_setSub(FToM *self, PyObject *arg) { SET_SUB };
4936 static PyObject * FToM_setDiv(FToM *self, PyObject *arg) { SET_DIV };
4937
4938 static PyObject * FToM_play(FToM *self, PyObject *args, PyObject *kwds) { PLAY };
4939 static PyObject * FToM_out(FToM *self, PyObject *args, PyObject *kwds) { OUT };
4940 static PyObject * FToM_stop(FToM *self, PyObject *args, PyObject *kwds) { STOP };
4941
4942 static PyObject * FToM_multiply(FToM *self, PyObject *arg) { MULTIPLY };
4943 static PyObject * FToM_inplace_multiply(FToM *self, PyObject *arg) { INPLACE_MULTIPLY };
4944 static PyObject * FToM_add(FToM *self, PyObject *arg) { ADD };
4945 static PyObject * FToM_inplace_add(FToM *self, PyObject *arg) { INPLACE_ADD };
4946 static PyObject * FToM_sub(FToM *self, PyObject *arg) { SUB };
4947 static PyObject * FToM_inplace_sub(FToM *self, PyObject *arg) { INPLACE_SUB };
4948 static PyObject * FToM_div(FToM *self, PyObject *arg) { DIV };
4949 static PyObject * FToM_inplace_div(FToM *self, PyObject *arg) { INPLACE_DIV };
4950
4951 static PyMemberDef FToM_members[] =
4952 {
4953 {"server", T_OBJECT_EX, offsetof(FToM, server), 0, "Pyo server."},
4954 {"stream", T_OBJECT_EX, offsetof(FToM, stream), 0, "Stream object."},
4955 {"input", T_OBJECT_EX, offsetof(FToM, input), 0, "Input sound object."},
4956 {"mul", T_OBJECT_EX, offsetof(FToM, mul), 0, "Mul factor."},
4957 {"add", T_OBJECT_EX, offsetof(FToM, add), 0, "Add factor."},
4958 {NULL} /* Sentinel */
4959 };
4960
4961 static PyMethodDef FToM_methods[] =
4962 {
4963 {"getServer", (PyCFunction)FToM_getServer, METH_NOARGS, "Returns server object."},
4964 {"_getStream", (PyCFunction)FToM_getStream, METH_NOARGS, "Returns stream object."},
4965 {"play", (PyCFunction)FToM_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
4966 {"stop", (PyCFunction)FToM_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
4967 {"out", (PyCFunction)FToM_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
4968 {"setMul", (PyCFunction)FToM_setMul, METH_O, "Sets oscillator mul factor."},
4969 {"setAdd", (PyCFunction)FToM_setAdd, METH_O, "Sets oscillator add factor."},
4970 {"setSub", (PyCFunction)FToM_setSub, METH_O, "Sets inverse add factor."},
4971 {"setDiv", (PyCFunction)FToM_setDiv, METH_O, "Sets inverse mul factor."},
4972 {NULL} /* Sentinel */
4973 };
4974
4975 static PyNumberMethods FToM_as_number =
4976 {
4977 (binaryfunc)FToM_add, /*nb_add*/
4978 (binaryfunc)FToM_sub, /*nb_subtract*/
4979 (binaryfunc)FToM_multiply, /*nb_multiply*/
4980 0, /*nb_remainder*/
4981 0, /*nb_divmod*/
4982 0, /*nb_power*/
4983 0, /*nb_neg*/
4984 0, /*nb_pos*/
4985 0, /*(unaryfunc)array_abs,*/
4986 0, /*nb_nonzero*/
4987 0, /*nb_invert*/
4988 0, /*nb_lshift*/
4989 0, /*nb_rshift*/
4990 0, /*nb_and*/
4991 0, /*nb_xor*/
4992 0, /*nb_or*/
4993 0, /*nb_int*/
4994 0, /*nb_long*/
4995 0, /*nb_float*/
4996 (binaryfunc)FToM_inplace_add, /*inplace_add*/
4997 (binaryfunc)FToM_inplace_sub, /*inplace_subtract*/
4998 (binaryfunc)FToM_inplace_multiply, /*inplace_multiply*/
4999 0, /*inplace_remainder*/
5000 0, /*inplace_power*/
5001 0, /*inplace_lshift*/
5002 0, /*inplace_rshift*/
5003 0, /*inplace_and*/
5004 0, /*inplace_xor*/
5005 0, /*inplace_or*/
5006 0, /*nb_floor_divide*/
5007 (binaryfunc)FToM_div, /*nb_true_divide*/
5008 0, /*nb_inplace_floor_divide*/
5009 (binaryfunc)FToM_inplace_div, /*nb_inplace_true_divide*/
5010 0, /* nb_index */
5011 };
5012
5013 PyTypeObject FToMType =
5014 {
5015 PyVarObject_HEAD_INIT(NULL, 0)
5016 "_pyo.FToM_base", /*tp_name*/
5017 sizeof(FToM), /*tp_basicsize*/
5018 0, /*tp_itemsize*/
5019 (destructor)FToM_dealloc, /*tp_dealloc*/
5020 0, /*tp_print*/
5021 0, /*tp_getattr*/
5022 0, /*tp_setattr*/
5023 0, /*tp_as_async (tp_compare in Python 2)*/
5024 0, /*tp_repr*/
5025 &FToM_as_number, /*tp_as_number*/
5026 0, /*tp_as_sequence*/
5027 0, /*tp_as_mapping*/
5028 0, /*tp_hash */
5029 0, /*tp_call*/
5030 0, /*tp_str*/
5031 0, /*tp_getattro*/
5032 0, /*tp_setattro*/
5033 0, /*tp_as_buffer*/
5034 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
5035 "FToM objects. Converts frequency to midi note.", /* tp_doc */
5036 (traverseproc)FToM_traverse, /* tp_traverse */
5037 (inquiry)FToM_clear, /* tp_clear */
5038 0, /* tp_richcompare */
5039 0, /* tp_weaklistoffset */
5040 0, /* tp_iter */
5041 0, /* tp_iternext */
5042 FToM_methods, /* tp_methods */
5043 FToM_members, /* tp_members */
5044 0, /* tp_getset */
5045 0, /* tp_base */
5046 0, /* tp_dict */
5047 0, /* tp_descr_get */
5048 0, /* tp_descr_set */
5049 0, /* tp_dictoffset */
5050 0, /* tp_init */
5051 0, /* tp_alloc */
5052 FToM_new, /* tp_new */
5053 };
5054
5055 /************/
5056 /* MToT */
5057 /************/
5058 typedef struct
5059 {
5060 pyo_audio_HEAD
5061 PyObject *input;
5062 Stream *input_stream;
5063 MYFLT centralkey;
5064 MYFLT lastmidi;
5065 MYFLT curfreq;
5066 int modebuffer[2]; // need at least 2 slots for mul & add
5067 } MToT;
5068
5069 static void
5070 MToT_process(MToT *self)
5071 {
5072 int i;
5073 MYFLT midi;
5074 MYFLT *in = Stream_getData((Stream *)self->input_stream);
5075
5076 for (i = 0; i < self->bufsize; i++)
5077 {
5078 midi = in[i];
5079
5080 if (midi != self->lastmidi)
5081 {
5082 self->data[i] = self->curfreq = MYPOW(1.0594630943593, midi - self->centralkey);
5083 self->lastmidi = midi;
5084 }
5085 else
5086 self->data[i] = self->curfreq;
5087 }
5088 }
5089
5090 static void MToT_postprocessing_ii(MToT *self) { POST_PROCESSING_II };
5091 static void MToT_postprocessing_ai(MToT *self) { POST_PROCESSING_AI };
5092 static void MToT_postprocessing_ia(MToT *self) { POST_PROCESSING_IA };
5093 static void MToT_postprocessing_aa(MToT *self) { POST_PROCESSING_AA };
5094 static void MToT_postprocessing_ireva(MToT *self) { POST_PROCESSING_IREVA };
5095 static void MToT_postprocessing_areva(MToT *self) { POST_PROCESSING_AREVA };
5096 static void MToT_postprocessing_revai(MToT *self) { POST_PROCESSING_REVAI };
5097 static void MToT_postprocessing_revaa(MToT *self) { POST_PROCESSING_REVAA };
5098 static void MToT_postprocessing_revareva(MToT *self) { POST_PROCESSING_REVAREVA };
5099
5100 static void
5101 MToT_setProcMode(MToT *self)
5102 {
5103 int muladdmode;
5104 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
5105
5106 self->proc_func_ptr = MToT_process;
5107
5108 switch (muladdmode)
5109 {
5110 case 0:
5111 self->muladd_func_ptr = MToT_postprocessing_ii;
5112 break;
5113
5114 case 1:
5115 self->muladd_func_ptr = MToT_postprocessing_ai;
5116 break;
5117
5118 case 2:
5119 self->muladd_func_ptr = MToT_postprocessing_revai;
5120 break;
5121
5122 case 10:
5123 self->muladd_func_ptr = MToT_postprocessing_ia;
5124 break;
5125
5126 case 11:
5127 self->muladd_func_ptr = MToT_postprocessing_aa;
5128 break;
5129
5130 case 12:
5131 self->muladd_func_ptr = MToT_postprocessing_revaa;
5132 break;
5133
5134 case 20:
5135 self->muladd_func_ptr = MToT_postprocessing_ireva;
5136 break;
5137
5138 case 21:
5139 self->muladd_func_ptr = MToT_postprocessing_areva;
5140 break;
5141
5142 case 22:
5143 self->muladd_func_ptr = MToT_postprocessing_revareva;
5144 break;
5145 }
5146 }
5147
5148 static void
5149 MToT_compute_next_data_frame(MToT *self)
5150 {
5151 (*self->proc_func_ptr)(self);
5152 (*self->muladd_func_ptr)(self);
5153 }
5154
5155 static int
5156 MToT_traverse(MToT *self, visitproc visit, void *arg)
5157 {
5158 pyo_VISIT
5159 Py_VISIT(self->input);
5160 return 0;
5161 }
5162
5163 static int
5164 MToT_clear(MToT *self)
5165 {
5166 pyo_CLEAR
5167 Py_CLEAR(self->input);
5168 return 0;
5169 }
5170
5171 static void
5172 MToT_dealloc(MToT* self)
5173 {
5174 pyo_DEALLOC
5175 MToT_clear(self);
5176 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
5177 Py_TYPE(self)->tp_free((PyObject*)self);
5178 }
5179
5180 static PyObject *
5181 MToT_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
5182 {
5183 int i;
5184 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
5185 MToT *self;
5186 self = (MToT *)type->tp_alloc(type, 0);
5187
5188 self->centralkey = 60.0;
5189 self->lastmidi = 0;
5190 self->curfreq = 8.1757989156437;
5191 self->modebuffer[0] = 0;
5192 self->modebuffer[1] = 0;
5193
5194 INIT_OBJECT_COMMON
5195 Stream_setFunctionPtr(self->stream, MToT_compute_next_data_frame);
5196 self->mode_func_ptr = MToT_setProcMode;
5197
5198 static char *kwlist[] = {"input", "centralkey", "mul", "add", NULL};
5199
5200 if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_O_FOO, kwlist, &inputtmp, &self->centralkey, &multmp, &addtmp))
5201 Py_RETURN_NONE;
5202
5203 INIT_INPUT_STREAM
5204
5205 if (multmp)
5206 {
5207 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
5208 }
5209
5210 if (addtmp)
5211 {
5212 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
5213 }
5214
5215 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
5216
5217 (*self->mode_func_ptr)(self);
5218
5219 return (PyObject *)self;
5220 }
5221
5222 static PyObject *
5223 MToT_setCentralKey(MToT *self, PyObject *arg)
5224 {
5225 ASSERT_ARG_NOT_NULL
5226
5227 if (PyNumber_Check(arg))
5228 {
5229 self->centralkey = PyFloat_AsDouble(arg);
5230 }
5231
5232 Py_RETURN_NONE;
5233 }
5234
5235 static PyObject * MToT_getServer(MToT* self) { GET_SERVER };
5236 static PyObject * MToT_getStream(MToT* self) { GET_STREAM };
5237 static PyObject * MToT_setMul(MToT *self, PyObject *arg) { SET_MUL };
5238 static PyObject * MToT_setAdd(MToT *self, PyObject *arg) { SET_ADD };
5239 static PyObject * MToT_setSub(MToT *self, PyObject *arg) { SET_SUB };
5240 static PyObject * MToT_setDiv(MToT *self, PyObject *arg) { SET_DIV };
5241
5242 static PyObject * MToT_play(MToT *self, PyObject *args, PyObject *kwds) { PLAY };
5243 static PyObject * MToT_out(MToT *self, PyObject *args, PyObject *kwds) { OUT };
5244 static PyObject * MToT_stop(MToT *self, PyObject *args, PyObject *kwds) { STOP };
5245
5246 static PyObject * MToT_multiply(MToT *self, PyObject *arg) { MULTIPLY };
5247 static PyObject * MToT_inplace_multiply(MToT *self, PyObject *arg) { INPLACE_MULTIPLY };
5248 static PyObject * MToT_add(MToT *self, PyObject *arg) { ADD };
5249 static PyObject * MToT_inplace_add(MToT *self, PyObject *arg) { INPLACE_ADD };
5250 static PyObject * MToT_sub(MToT *self, PyObject *arg) { SUB };
5251 static PyObject * MToT_inplace_sub(MToT *self, PyObject *arg) { INPLACE_SUB };
5252 static PyObject * MToT_div(MToT *self, PyObject *arg) { DIV };
5253 static PyObject * MToT_inplace_div(MToT *self, PyObject *arg) { INPLACE_DIV };
5254
5255 static PyMemberDef MToT_members[] =
5256 {
5257 {"server", T_OBJECT_EX, offsetof(MToT, server), 0, "Pyo server."},
5258 {"stream", T_OBJECT_EX, offsetof(MToT, stream), 0, "Stream object."},
5259 {"input", T_OBJECT_EX, offsetof(MToT, input), 0, "Input sound object."},
5260 {"mul", T_OBJECT_EX, offsetof(MToT, mul), 0, "Mul factor."},
5261 {"add", T_OBJECT_EX, offsetof(MToT, add), 0, "Add factor."},
5262 {NULL} /* Sentinel */
5263 };
5264
5265 static PyMethodDef MToT_methods[] =
5266 {
5267 {"getServer", (PyCFunction)MToT_getServer, METH_NOARGS, "Returns server object."},
5268 {"_getStream", (PyCFunction)MToT_getStream, METH_NOARGS, "Returns stream object."},
5269 {"play", (PyCFunction)MToT_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
5270 {"stop", (PyCFunction)MToT_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
5271 {"out", (PyCFunction)MToT_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
5272 {"setCentralKey", (PyCFunction)MToT_setCentralKey, METH_O, "Sets the central key."},
5273 {"setMul", (PyCFunction)MToT_setMul, METH_O, "Sets oscillator mul factor."},
5274 {"setAdd", (PyCFunction)MToT_setAdd, METH_O, "Sets oscillator add factor."},
5275 {"setSub", (PyCFunction)MToT_setSub, METH_O, "Sets inverse add factor."},
5276 {"setDiv", (PyCFunction)MToT_setDiv, METH_O, "Sets inverse mul factor."},
5277 {NULL} /* Sentinel */
5278 };
5279
5280 static PyNumberMethods MToT_as_number =
5281 {
5282 (binaryfunc)MToT_add, /*nb_add*/
5283 (binaryfunc)MToT_sub, /*nb_subtract*/
5284 (binaryfunc)MToT_multiply, /*nb_multiply*/
5285 0, /*nb_remainder*/
5286 0, /*nb_divmod*/
5287 0, /*nb_power*/
5288 0, /*nb_neg*/
5289 0, /*nb_pos*/
5290 0, /*(unaryfunc)array_abs,*/
5291 0, /*nb_nonzero*/
5292 0, /*nb_invert*/
5293 0, /*nb_lshift*/
5294 0, /*nb_rshift*/
5295 0, /*nb_and*/
5296 0, /*nb_xor*/
5297 0, /*nb_or*/
5298 0, /*nb_int*/
5299 0, /*nb_long*/
5300 0, /*nb_float*/
5301 (binaryfunc)MToT_inplace_add, /*inplace_add*/
5302 (binaryfunc)MToT_inplace_sub, /*inplace_subtract*/
5303 (binaryfunc)MToT_inplace_multiply, /*inplace_multiply*/
5304 0, /*inplace_remainder*/
5305 0, /*inplace_power*/
5306 0, /*inplace_lshift*/
5307 0, /*inplace_rshift*/
5308 0, /*inplace_and*/
5309 0, /*inplace_xor*/
5310 0, /*inplace_or*/
5311 0, /*nb_floor_divide*/
5312 (binaryfunc)MToT_div, /*nb_true_divide*/
5313 0, /*nb_inplace_floor_divide*/
5314 (binaryfunc)MToT_inplace_div, /*nb_inplace_true_divide*/
5315 0, /* nb_index */
5316 };
5317
5318 PyTypeObject MToTType =
5319 {
5320 PyVarObject_HEAD_INIT(NULL, 0)
5321 "_pyo.MToT_base", /*tp_name*/
5322 sizeof(MToT), /*tp_basicsize*/
5323 0, /*tp_itemsize*/
5324 (destructor)MToT_dealloc, /*tp_dealloc*/
5325 0, /*tp_print*/
5326 0, /*tp_getattr*/
5327 0, /*tp_setattr*/
5328 0, /*tp_as_async (tp_compare in Python 2)*/
5329 0, /*tp_repr*/
5330 &MToT_as_number, /*tp_as_number*/
5331 0, /*tp_as_sequence*/
5332 0, /*tp_as_mapping*/
5333 0, /*tp_hash */
5334 0, /*tp_call*/
5335 0, /*tp_str*/
5336 0, /*tp_getattro*/
5337 0, /*tp_setattro*/
5338 0, /*tp_as_buffer*/
5339 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
5340 "MToT objects. Converts midi notes to transposition factor.", /* tp_doc */
5341 (traverseproc)MToT_traverse, /* tp_traverse */
5342 (inquiry)MToT_clear, /* tp_clear */
5343 0, /* tp_richcompare */
5344 0, /* tp_weaklistoffset */
5345 0, /* tp_iter */
5346 0, /* tp_iternext */
5347 MToT_methods, /* tp_methods */
5348 MToT_members, /* tp_members */
5349 0, /* tp_getset */
5350 0, /* tp_base */
5351 0, /* tp_dict */
5352 0, /* tp_descr_get */
5353 0, /* tp_descr_set */
5354 0, /* tp_dictoffset */
5355 0, /* tp_init */
5356 0, /* tp_alloc */
5357 MToT_new, /* tp_new */
5358 };
5359
5360 /************/
5361 /* Resample */
5362 /************/
5363 typedef struct
5364 {
5365 pyo_audio_HEAD
5366 PyObject *input;
5367 Stream *input_stream;
5368 MYFLT **pimpulse;
5369 MYFLT **pinput;
5370 int factor;
5371 int last_factor;
5372 int count;
5373 int dir; // Up = 1, DOWN = 0
5374 int size; // UP: 0 = zero-padding, 1 = sample-and-hold, 2+ polyphase lowpass filtering
5375 // DOWN: <2 = discard extra samples, 2+ polyphase lowpass filtering
5376 int modebuffer[2]; // need at least 2 slots for mul & add
5377 int allocated;
5378 } Resample;
5379
5380 static void
5381 Resample_create_impulse(Resample *self)
5382 {
5383 int i, half;
5384 MYFLT val, scl, sum, invSum, env, w;
5385 MYFLT impulse[self->size];
5386
5387 half = self->size / 2;
5388 sum = 0.0;
5389 w = TWOPI * 0.49 / self->factor;
5390
5391 for (i = 0; i < half; i++)
5392 {
5393 env = 0.5 * (1.0 - MYCOS(TWOPI * i / self->size));
5394 scl = i - half;
5395 val = (MYSIN(w * scl) / scl) * env;
5396 sum += val;
5397 impulse[i] = val;
5398 }
5399
5400 sum *= 2.0;
5401 sum += w;
5402 invSum = 1.0 / sum;
5403 impulse[half] = w * invSum;
5404
5405 for (i = 0; i < half; i++)
5406 {
5407 impulse[i] *= invSum;
5408 }
5409
5410 for (i = half + 1; i < self->size; i++)
5411 {
5412 impulse[i] = impulse[self->size - i];
5413 }
5414
5415 /* Create sub-filters. */
5416 for (i = 0; i < self->size; i++)
5417 {
5418 self->pimpulse[i % self->factor][(int)(i / self->factor)] = impulse[i];
5419 }
5420 }
5421
5422 static void
5423 Resample_update_mode(Resample *self)
5424 {
5425 int i = 0, j = 0;
5426
5427 if (self->size > self->factor)
5428 {
5429 if (self->allocated)
5430 {
5431 for (j = 0; j < self->last_factor; j++)
5432 {
5433 PyMem_RawFree(self->pimpulse[j]);
5434 PyMem_RawFree(self->pinput[j]);
5435 }
5436 }
5437
5438 self->pimpulse = (MYFLT **)PyMem_RawRealloc(self->pimpulse, self->factor * sizeof(MYFLT *));
5439 self->pinput = (MYFLT **)PyMem_RawRealloc(self->pinput, self->factor * sizeof(MYFLT *));
5440
5441 for (j = 0; j < self->factor; j++)
5442 {
5443 self->pimpulse[j] = (MYFLT *)PyMem_RawMalloc(self->size / self->factor * sizeof(MYFLT));
5444 self->pinput[j] = (MYFLT *)PyMem_RawMalloc(self->size / self->factor * sizeof(MYFLT));
5445
5446 for (i = 0; i < self->size / self->factor; i++)
5447 {
5448 self->pinput[j][i] = 0.0;
5449 }
5450 }
5451
5452 self->last_factor = self->factor;
5453 self->allocated = 1;
5454
5455 Resample_create_impulse(self);
5456 }
5457 }
5458
5459 static void
5460 Resample_downsample(Resample *self)
5461 {
5462 int i, j, k, tmp_count, len;
5463 MYFLT filtout;
5464 MYFLT *in = Stream_getData((Stream *)self->input_stream);
5465
5466 len = self->size / self->factor;
5467
5468 if (self->size <= self->factor)
5469 {
5470 for (i = 0; i < self->bufsize; i++)
5471 {
5472 self->data[i] = in[i * self->factor];
5473 }
5474 }
5475 else
5476 {
5477 for (i = 0; i < self->bufsize; i++)
5478 {
5479 self->data[i] = 0.0;
5480
5481 for (j = 0; j < self->factor; j++) // for each polyphase sub-filter...
5482 {
5483 filtout = 0.0;
5484 tmp_count = self->count;
5485
5486 for (k = 0; k < len; k++) // ... apply filter...
5487 {
5488 if (tmp_count < 0)
5489 tmp_count += len;
5490
5491 filtout += self->pinput[j][tmp_count--] * self->pimpulse[j][k];
5492 }
5493
5494 self->data[i] += filtout; // ... and sum.
5495 }
5496
5497 // Input decomposition (input delay line in reverse order).
5498 self->count++;
5499
5500 if (self->count == len)
5501 self->count = 0;
5502
5503 for (j = 0; j < self->factor; j++)
5504 {
5505 self->pinput[self->factor - 1 - j][self->count] = in[i * self->factor + j];
5506 }
5507 }
5508 }
5509 }
5510
5511 static void
5512 Resample_upsample(Resample *self)
5513 {
5514 int i, j, k, tmp_count, len;
5515 MYFLT filtout;
5516 MYFLT *in = Stream_getData((Stream *)self->input_stream);
5517
5518 len = self->size / self->factor;
5519
5520 if (self->size == 0)
5521 {
5522 for (i = 0; i < (self->bufsize / self->factor); i++)
5523 {
5524 j = i * self->factor;
5525 self->data[j] = in[i];
5526
5527 for (k = 1; k < self->factor; k++)
5528 {
5529 self->data[j + k] = 0.0;
5530 }
5531 }
5532 }
5533 else if (self->size == self->factor)
5534 {
5535 for (i = 0; i < (self->bufsize / self->factor); i++)
5536 {
5537 for (k = 0; k < self->factor; k++)
5538 {
5539 self->data[i * self->factor + k] = in[i];
5540 }
5541 }
5542 }
5543 else
5544 {
5545 for (i = 0; i < self->bufsize / self->factor; i++)
5546 {
5547 for (j = 0; j < self->factor; j++) // for each polyphase sub-filter...
5548 {
5549 filtout = 0.0;
5550 tmp_count = self->count;
5551
5552 for (k = 0; k < len; k++) // ... apply filter...
5553 {
5554 if (tmp_count < 0)
5555 tmp_count += len;
5556
5557 filtout += self->pinput[j][tmp_count--] * self->pimpulse[j][k];
5558 }
5559
5560 self->data[i * self->factor + j] = filtout;
5561 }
5562
5563 self->count++;
5564
5565 if (self->count == len)
5566 self->count = 0;
5567
5568 for (j = 0; j < self->factor; j++)
5569 {
5570 self->pinput[self->factor - 1 - j][self->count] = in[i];
5571 }
5572 }
5573 }
5574 }
5575
5576 static void
5577 Resample_process(Resample *self)
5578 {
5579 if (self->dir == 0)
5580 Resample_downsample(self);
5581 else
5582 Resample_upsample(self);
5583 }
5584
5585 static void Resample_postprocessing_ii(Resample *self) { POST_PROCESSING_II };
5586 static void Resample_postprocessing_ai(Resample *self) { POST_PROCESSING_AI };
5587 static void Resample_postprocessing_ia(Resample *self) { POST_PROCESSING_IA };
5588 static void Resample_postprocessing_aa(Resample *self) { POST_PROCESSING_AA };
5589 static void Resample_postprocessing_ireva(Resample *self) { POST_PROCESSING_IREVA };
5590 static void Resample_postprocessing_areva(Resample *self) { POST_PROCESSING_AREVA };
5591 static void Resample_postprocessing_revai(Resample *self) { POST_PROCESSING_REVAI };
5592 static void Resample_postprocessing_revaa(Resample *self) { POST_PROCESSING_REVAA };
5593 static void Resample_postprocessing_revareva(Resample *self) { POST_PROCESSING_REVAREVA };
5594
5595 static void
5596 Resample_setProcMode(Resample *self)
5597 {
5598 int muladdmode;
5599 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
5600
5601 self->proc_func_ptr = Resample_process;
5602
5603 switch (muladdmode)
5604 {
5605 case 0:
5606 self->muladd_func_ptr = Resample_postprocessing_ii;
5607 break;
5608
5609 case 1:
5610 self->muladd_func_ptr = Resample_postprocessing_ai;
5611 break;
5612
5613 case 2:
5614 self->muladd_func_ptr = Resample_postprocessing_revai;
5615 break;
5616
5617 case 10:
5618 self->muladd_func_ptr = Resample_postprocessing_ia;
5619 break;
5620
5621 case 11:
5622 self->muladd_func_ptr = Resample_postprocessing_aa;
5623 break;
5624
5625 case 12:
5626 self->muladd_func_ptr = Resample_postprocessing_revaa;
5627 break;
5628
5629 case 20:
5630 self->muladd_func_ptr = Resample_postprocessing_ireva;
5631 break;
5632
5633 case 21:
5634 self->muladd_func_ptr = Resample_postprocessing_areva;
5635 break;
5636
5637 case 22:
5638 self->muladd_func_ptr = Resample_postprocessing_revareva;
5639 break;
5640 }
5641 }
5642
5643 static void
5644 Resample_compute_next_data_frame(Resample *self)
5645 {
5646 (*self->proc_func_ptr)(self);
5647 (*self->muladd_func_ptr)(self);
5648 }
5649
5650 static int
5651 Resample_traverse(Resample *self, visitproc visit, void *arg)
5652 {
5653 pyo_VISIT
5654 Py_VISIT(self->input);
5655 return 0;
5656 }
5657
5658 static int
5659 Resample_clear(Resample *self)
5660 {
5661 pyo_CLEAR
5662 Py_CLEAR(self->input);
5663 return 0;
5664 }
5665
5666 static void
5667 Resample_dealloc(Resample* self)
5668 {
5669 int i;
5670 pyo_DEALLOC
5671
5672 if (self->size > self->factor)
5673 {
5674 for (i = 0; i < self->factor; i++)
5675 {
5676 PyMem_RawFree(self->pimpulse[i]);
5677 PyMem_RawFree(self->pinput[i]);
5678 }
5679
5680 PyMem_RawFree(self->pimpulse);
5681 PyMem_RawFree(self->pinput);
5682 }
5683
5684 Resample_clear(self);
5685 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
5686 Py_TYPE(self)->tp_free((PyObject*)self);
5687 }
5688
5689 static PyObject *
5690 Resample_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
5691 {
5692 int i, lfac, cfac, mode;
5693 PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL;
5694 Resample *self;
5695 self = (Resample *)type->tp_alloc(type, 0);
5696
5697 self->last_factor = self->factor = 1;
5698 self->size = 0;
5699 self->count = 0;
5700 self->dir = 0;
5701 self->allocated = 0;
5702 self->modebuffer[0] = 0;
5703 self->modebuffer[1] = 0;
5704
5705 INIT_OBJECT_COMMON
5706 Stream_setFunctionPtr(self->stream, Resample_compute_next_data_frame);
5707 self->mode_func_ptr = Resample_setProcMode;
5708
5709 static char *kwlist[] = {"input", "mode", "mul", "add", NULL};
5710
5711 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|iOO", kwlist, &inputtmp, &mode, &multmp, &addtmp))
5712 Py_RETURN_NONE;
5713
5714 INIT_INPUT_STREAM
5715
5716 lfac = Server_getLastResamplingFactor((Server *)self->server);
5717 cfac = Server_getCurrentResamplingFactor((Server *)self->server);
5718
5719 if (lfac == 1)
5720 {
5721 if (cfac < 0)
5722 {
5723 self->dir = 0;
5724 cfac = -cfac;
5725 }
5726 else
5727 self->dir = 1;
5728
5729 self->factor = cfac;
5730 }
5731 else if (cfac == 1)
5732 {
5733 if (lfac < 0)
5734 {
5735 self->dir = 1;
5736 lfac = -lfac;
5737 }
5738 else
5739 self->dir = 0;
5740
5741 self->factor = lfac;
5742 }
5743
5744 self->size = self->factor * mode;
5745 Resample_update_mode(self);
5746
5747 if (multmp)
5748 {
5749 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
5750 }
5751
5752 if (addtmp)
5753 {
5754 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
5755 }
5756
5757 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
5758
5759 (*self->mode_func_ptr)(self);
5760
5761 return (PyObject *)self;
5762 }
5763
5764 static PyObject *
5765 Resample_setMode(Resample *self, PyObject *arg)
5766 {
5767 int mode = -1;
5768 ASSERT_ARG_NOT_NULL
5769
5770 if (PyLong_Check(arg) == 1)
5771 {
5772 mode = PyLong_AsLong(arg);
5773 }
5774
5775 if (mode >= 0)
5776 {
5777 self->size = self->factor * mode;
5778 Resample_update_mode(self);
5779 }
5780
5781 Py_RETURN_NONE;
5782 }
5783
5784 static PyObject * Resample_getServer(Resample* self) { GET_SERVER };
5785 static PyObject * Resample_getStream(Resample* self) { GET_STREAM };
5786 static PyObject * Resample_setMul(Resample *self, PyObject *arg) { SET_MUL };
5787 static PyObject * Resample_setAdd(Resample *self, PyObject *arg) { SET_ADD };
5788 static PyObject * Resample_setSub(Resample *self, PyObject *arg) { SET_SUB };
5789 static PyObject * Resample_setDiv(Resample *self, PyObject *arg) { SET_DIV };
5790
5791 static PyObject * Resample_play(Resample *self, PyObject *args, PyObject *kwds) { PLAY };
5792 static PyObject * Resample_out(Resample *self, PyObject *args, PyObject *kwds) { OUT };
5793 static PyObject * Resample_stop(Resample *self, PyObject *args, PyObject *kwds) { STOP };
5794
5795 static PyObject * Resample_multiply(Resample *self, PyObject *arg) { MULTIPLY };
5796 static PyObject * Resample_inplace_multiply(Resample *self, PyObject *arg) { INPLACE_MULTIPLY };
5797 static PyObject * Resample_add(Resample *self, PyObject *arg) { ADD };
5798 static PyObject * Resample_inplace_add(Resample *self, PyObject *arg) { INPLACE_ADD };
5799 static PyObject * Resample_sub(Resample *self, PyObject *arg) { SUB };
5800 static PyObject * Resample_inplace_sub(Resample *self, PyObject *arg) { INPLACE_SUB };
5801 static PyObject * Resample_div(Resample *self, PyObject *arg) { DIV };
5802 static PyObject * Resample_inplace_div(Resample *self, PyObject *arg) { INPLACE_DIV };
5803
5804 static PyMemberDef Resample_members[] =
5805 {
5806 {"server", T_OBJECT_EX, offsetof(Resample, server), 0, "Pyo server."},
5807 {"stream", T_OBJECT_EX, offsetof(Resample, stream), 0, "Stream object."},
5808 {"input", T_OBJECT_EX, offsetof(Resample, input), 0, "Input sound object."},
5809 {"mul", T_OBJECT_EX, offsetof(Resample, mul), 0, "Mul factor."},
5810 {"add", T_OBJECT_EX, offsetof(Resample, add), 0, "Add factor."},
5811 {NULL} /* Sentinel */
5812 };
5813
5814 static PyMethodDef Resample_methods[] =
5815 {
5816 {"getServer", (PyCFunction)Resample_getServer, METH_NOARGS, "Returns server object."},
5817 {"_getStream", (PyCFunction)Resample_getStream, METH_NOARGS, "Returns stream object."},
5818 {"play", (PyCFunction)Resample_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
5819 {"stop", (PyCFunction)Resample_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
5820 {"out", (PyCFunction)Resample_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
5821 {"setMode", (PyCFunction)Resample_setMode, METH_O, "Sets mode factor."},
5822 {"setMul", (PyCFunction)Resample_setMul, METH_O, "Sets oscillator mul factor."},
5823 {"setAdd", (PyCFunction)Resample_setAdd, METH_O, "Sets oscillator add factor."},
5824 {"setSub", (PyCFunction)Resample_setSub, METH_O, "Sets inverse add factor."},
5825 {"setDiv", (PyCFunction)Resample_setDiv, METH_O, "Sets inverse mul factor."},
5826 {NULL} /* Sentinel */
5827 };
5828
5829 static PyNumberMethods Resample_as_number =
5830 {
5831 (binaryfunc)Resample_add, /*nb_add*/
5832 (binaryfunc)Resample_sub, /*nb_subtract*/
5833 (binaryfunc)Resample_multiply, /*nb_multiply*/
5834 0, /*nb_remainder*/
5835 0, /*nb_divmod*/
5836 0, /*nb_power*/
5837 0, /*nb_neg*/
5838 0, /*nb_pos*/
5839 0, /*(unaryfunc)array_abs,*/
5840 0, /*nb_nonzero*/
5841 0, /*nb_invert*/
5842 0, /*nb_lshift*/
5843 0, /*nb_rshift*/
5844 0, /*nb_and*/
5845 0, /*nb_xor*/
5846 0, /*nb_or*/
5847 0, /*nb_int*/
5848 0, /*nb_long*/
5849 0, /*nb_float*/
5850 (binaryfunc)Resample_inplace_add, /*inplace_add*/
5851 (binaryfunc)Resample_inplace_sub, /*inplace_subtract*/
5852 (binaryfunc)Resample_inplace_multiply, /*inplace_multiply*/
5853 0, /*inplace_remainder*/
5854 0, /*inplace_power*/
5855 0, /*inplace_lshift*/
5856 0, /*inplace_rshift*/
5857 0, /*inplace_and*/
5858 0, /*inplace_xor*/
5859 0, /*inplace_or*/
5860 0, /*nb_floor_divide*/
5861 (binaryfunc)Resample_div, /*nb_true_divide*/
5862 0, /*nb_inplace_floor_divide*/
5863 (binaryfunc)Resample_inplace_div, /*nb_inplace_true_divide*/
5864 0, /* nb_index */
5865 };
5866
5867 PyTypeObject ResampleType =
5868 {
5869 PyVarObject_HEAD_INIT(NULL, 0)
5870 "_pyo.Resample_base", /*tp_name*/
5871 sizeof(Resample), /*tp_basicsize*/
5872 0, /*tp_itemsize*/
5873 (destructor)Resample_dealloc, /*tp_dealloc*/
5874 0, /*tp_print*/
5875 0, /*tp_getattr*/
5876 0, /*tp_setattr*/
5877 0, /*tp_as_async (tp_compare in Python 2)*/
5878 0, /*tp_repr*/
5879 &Resample_as_number, /*tp_as_number*/
5880 0, /*tp_as_sequence*/
5881 0, /*tp_as_mapping*/
5882 0, /*tp_hash */
5883 0, /*tp_call*/
5884 0, /*tp_str*/
5885 0, /*tp_getattro*/
5886 0, /*tp_setattro*/
5887 0, /*tp_as_buffer*/
5888 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
5889 "Resample objects. Performs resampling of an audio signal.", /* tp_doc */
5890 (traverseproc)Resample_traverse, /* tp_traverse */
5891 (inquiry)Resample_clear, /* tp_clear */
5892 0, /* tp_richcompare */
5893 0, /* tp_weaklistoffset */
5894 0, /* tp_iter */
5895 0, /* tp_iternext */
5896 Resample_methods, /* tp_methods */
5897 Resample_members, /* tp_members */
5898 0, /* tp_getset */
5899 0, /* tp_base */
5900 0, /* tp_dict */
5901 0, /* tp_descr_get */
5902 0, /* tp_descr_set */
5903 0, /* tp_dictoffset */
5904 0, /* tp_init */
5905 0, /* tp_alloc */
5906 Resample_new, /* tp_new */
5907 };