1
/*************************************************************************
2
* Copyright 2010 Olivier Belanger *
4
* This file is part of pyo, a python module to help digital signal *
5
* processing script creation. *
7
* pyo is free software: you can redistribute it and/or modify *
8
* it under the terms of the GNU General Public License as published by *
9
* the Free Software Foundation, either version 3 of the License, or *
10
* (at your option) any later version. *
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 General Public License for more details. *
17
* You should have received a copy of the GNU General Public License *
18
* along with pyo. If not, see <http://www.gnu.org/licenses/>. *
19
*************************************************************************/
22
#include "structmember.h"
24
#include "pyomodule.h"
25
#include "streammodule.h"
26
#include "servermodule.h"
27
#include "dummymodule.h"
37
int method; // 0 -> interval, 1 -> change
45
Print_process_time(Print *self) {
47
MYFLT *in = Stream_getData((Stream *)self->input_stream);
49
for (i=0; i<self->bufsize; i++) {
50
if (self->currentTime >= self->time) {
51
self->currentTime = 0.0;
52
if (self->message == NULL || self->message[0] == '\0')
53
printf("%f\n", in[i]);
55
printf("%s : %f\n", self->message, in[i]);
57
self->currentTime += self->sampleToSec;
62
Print_process_change(Print *self) {
65
MYFLT *in = Stream_getData((Stream *)self->input_stream);
67
for (i=0; i<self->bufsize; i++) {
69
if (inval < (self->lastValue-0.00001) || inval > (self->lastValue+0.00001)) {
70
if (self->message == NULL || self->message[0] == '\0')
71
printf("%f\n", inval);
73
printf("%s : %f\n", self->message, inval);
74
self->lastValue = inval;
80
Print_setProcMode(Print *self)
82
if (self->method < 0 || self->method > 1)
85
switch (self->method) {
87
self->proc_func_ptr = Print_process_time;
90
self->proc_func_ptr = Print_process_change;
96
Print_compute_next_data_frame(Print *self)
98
(*self->proc_func_ptr)(self);
102
Print_traverse(Print *self, visitproc visit, void *arg)
105
Py_VISIT(self->input);
106
Py_VISIT(self->input_stream);
111
Print_clear(Print *self)
114
Py_CLEAR(self->input);
115
Py_CLEAR(self->input_stream);
120
Print_dealloc(Print* self)
124
self->ob_type->tp_free((PyObject*)self);
127
static PyObject * Print_deleteStream(Print *self) { DELETE_STREAM };
130
Print_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
134
self = (Print *)type->tp_alloc(type, 0);
138
self->lastValue = -99999.0;
141
Stream_setFunctionPtr(self->stream, Print_compute_next_data_frame);
142
self->mode_func_ptr = Print_setProcMode;
144
self->sampleToSec = 1. / self->sr;
145
self->currentTime = 0.;
147
return (PyObject *)self;
151
Print_init(Print *self, PyObject *args, PyObject *kwds)
153
PyObject *inputtmp, *input_streamtmp;
155
static char *kwlist[] = {"input", "method", "interval", "message", NULL};
157
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_O_IFS, kwlist, &inputtmp, &self->method, &self->time, &self->message))
162
Py_INCREF(self->stream);
163
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
165
(*self->mode_func_ptr)(self);
171
static PyObject * Print_getServer(Print* self) { GET_SERVER };
172
static PyObject * Print_getStream(Print* self) { GET_STREAM };
174
static PyObject * Print_play(Print *self, PyObject *args, PyObject *kwds) { PLAY };
175
static PyObject * Print_stop(Print *self) { STOP };
178
Print_setMethod(Print *self, PyObject *arg)
185
int isNumber = PyNumber_Check(arg);
188
self->method = PyInt_AsLong(arg);
189
(*self->mode_func_ptr)(self);
197
Print_setInterval(Print *self, PyObject *arg)
204
int isNumber = PyNumber_Check(arg);
207
self->time = PyFloat_AS_DOUBLE(PyNumber_Float(arg));
215
Print_setMessage(Print *self, PyObject *arg)
222
int isString = PyString_Check(arg);
225
self->message = PyString_AsString(arg);
232
static PyMemberDef Print_members[] = {
233
{"server", T_OBJECT_EX, offsetof(Print, server), 0, "Pyo server."},
234
{"stream", T_OBJECT_EX, offsetof(Print, stream), 0, "Stream object."},
235
{"input", T_OBJECT_EX, offsetof(Print, input), 0, "Input sound object."},
236
{NULL} /* Sentinel */
239
static PyMethodDef Print_methods[] = {
240
{"getServer", (PyCFunction)Print_getServer, METH_NOARGS, "Returns server object."},
241
{"_getStream", (PyCFunction)Print_getStream, METH_NOARGS, "Returns stream object."},
242
{"deleteStream", (PyCFunction)Print_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
243
{"play", (PyCFunction)Print_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
244
{"stop", (PyCFunction)Print_stop, METH_NOARGS, "Stops computing."},
245
{"setMethod", (PyCFunction)Print_setMethod, METH_O, "Sets the printing method."},
246
{"setInterval", (PyCFunction)Print_setInterval, METH_O, "Sets the time interval."},
247
{"setMessage", (PyCFunction)Print_setMessage, METH_O, "Sets the prefix message to print."},
248
{NULL} /* Sentinel */
251
PyTypeObject PrintType = {
252
PyObject_HEAD_INIT(NULL)
254
"_pyo.Print_base", /*tp_name*/
255
sizeof(Print), /*tp_basicsize*/
257
(destructor)Print_dealloc, /*tp_dealloc*/
264
0, /*tp_as_sequence*/
272
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
273
"Print objects. Print the current value of the input object.", /* tp_doc */
274
(traverseproc)Print_traverse, /* tp_traverse */
275
(inquiry)Print_clear, /* tp_clear */
276
0, /* tp_richcompare */
277
0, /* tp_weaklistoffset */
280
Print_methods, /* tp_methods */
281
Print_members, /* tp_members */
285
0, /* tp_descr_get */
286
0, /* tp_descr_set */
287
0, /* tp_dictoffset */
288
(initproc)Print_init, /* tp_init */
290
Print_new, /* tp_new */
293
/*********************************************************************************************/
294
/* Snap ********************************************************************************/
295
/*********************************************************************************************/
299
Stream *input_stream;
300
int scale; // 0 = Midi, 1 = frequency, 2 = transpo
306
int modebuffer[2]; // need at least 2 slots for mul & add
310
Snap_convert(Snap *self) {
314
midival = self->value;
316
if (self->scale == 1)
317
val = 8.1757989156437 * MYPOW(1.0594630943593, midival);
318
else if (self->scale == 2)
319
val = MYPOW(1.0594630943593, midival - 60);
327
Snap_generate(Snap *self) {
329
MYFLT intmp, diff, difftmp;
330
MYFLT *in = Stream_getData((Stream *)self->input_stream);
332
for (i=0; i<self->bufsize; i++) {
333
if (in[i] < (self->last_input-0.001) || in[i] > (self->last_input + 0.001)) {
335
self->last_input = intmp = in[i];
336
while (intmp >= self->highbound) {
338
intmp -= self->highbound;
340
diff = MYFABS(self->choice[0]-intmp);
342
for (j=1; j<self->chSize; j++) {
343
difftmp = MYFABS(self->choice[j]-intmp);
344
if (difftmp < diff) {
349
self->value = self->choice[pos] + (self->highbound * oct);
350
self->value = Snap_convert(self);
353
self->data[i] = self->value;
357
static void Snap_postprocessing_ii(Snap *self) { POST_PROCESSING_II };
358
static void Snap_postprocessing_ai(Snap *self) { POST_PROCESSING_AI };
359
static void Snap_postprocessing_ia(Snap *self) { POST_PROCESSING_IA };
360
static void Snap_postprocessing_aa(Snap *self) { POST_PROCESSING_AA };
361
static void Snap_postprocessing_ireva(Snap *self) { POST_PROCESSING_IREVA };
362
static void Snap_postprocessing_areva(Snap *self) { POST_PROCESSING_AREVA };
363
static void Snap_postprocessing_revai(Snap *self) { POST_PROCESSING_REVAI };
364
static void Snap_postprocessing_revaa(Snap *self) { POST_PROCESSING_REVAA };
365
static void Snap_postprocessing_revareva(Snap *self) { POST_PROCESSING_REVAREVA };
368
Snap_setProcMode(Snap *self)
371
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
373
self->proc_func_ptr = Snap_generate;
375
switch (muladdmode) {
377
self->muladd_func_ptr = Snap_postprocessing_ii;
380
self->muladd_func_ptr = Snap_postprocessing_ai;
383
self->muladd_func_ptr = Snap_postprocessing_revai;
386
self->muladd_func_ptr = Snap_postprocessing_ia;
389
self->muladd_func_ptr = Snap_postprocessing_aa;
392
self->muladd_func_ptr = Snap_postprocessing_revaa;
395
self->muladd_func_ptr = Snap_postprocessing_ireva;
398
self->muladd_func_ptr = Snap_postprocessing_areva;
401
self->muladd_func_ptr = Snap_postprocessing_revareva;
407
Snap_compute_next_data_frame(Snap *self)
409
(*self->proc_func_ptr)(self);
410
(*self->muladd_func_ptr)(self);
414
Snap_traverse(Snap *self, visitproc visit, void *arg)
417
Py_VISIT(self->input);
418
Py_VISIT(self->input_stream);
423
Snap_clear(Snap *self)
426
Py_CLEAR(self->input);
427
Py_CLEAR(self->input_stream);
432
Snap_dealloc(Snap* self)
437
self->ob_type->tp_free((PyObject*)self);
440
static PyObject * Snap_deleteStream(Snap *self) { DELETE_STREAM };
443
Snap_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
447
self = (Snap *)type->tp_alloc(type, 0);
449
self->value = self->last_input = 0.;
451
self->highbound = 12;
452
self->modebuffer[0] = 0;
453
self->modebuffer[1] = 0;
456
Stream_setFunctionPtr(self->stream, Snap_compute_next_data_frame);
457
self->mode_func_ptr = Snap_setProcMode;
458
return (PyObject *)self;
462
Snap_init(Snap *self, PyObject *args, PyObject *kwds)
464
PyObject *inputtmp, *input_streamtmp, *choicetmp=NULL, *multmp=NULL, *addtmp=NULL;
466
static char *kwlist[] = {"input", "choice", "scale", "mul", "add", NULL};
468
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|iOO", kwlist, &inputtmp, &choicetmp, &self->scale, &multmp, &addtmp))
474
PyObject_CallMethod((PyObject *)self, "setChoice", "O", choicetmp);
478
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
482
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
485
Py_INCREF(self->stream);
486
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
488
(*self->mode_func_ptr)(self);
494
static PyObject * Snap_getServer(Snap* self) { GET_SERVER };
495
static PyObject * Snap_getStream(Snap* self) { GET_STREAM };
496
static PyObject * Snap_setMul(Snap *self, PyObject *arg) { SET_MUL };
497
static PyObject * Snap_setAdd(Snap *self, PyObject *arg) { SET_ADD };
498
static PyObject * Snap_setSub(Snap *self, PyObject *arg) { SET_SUB };
499
static PyObject * Snap_setDiv(Snap *self, PyObject *arg) { SET_DIV };
501
static PyObject * Snap_play(Snap *self, PyObject *args, PyObject *kwds) { PLAY };
502
static PyObject * Snap_out(Snap *self, PyObject *args, PyObject *kwds) { OUT };
503
static PyObject * Snap_stop(Snap *self) { STOP };
505
static PyObject * Snap_multiply(Snap *self, PyObject *arg) { MULTIPLY };
506
static PyObject * Snap_inplace_multiply(Snap *self, PyObject *arg) { INPLACE_MULTIPLY };
507
static PyObject * Snap_add(Snap *self, PyObject *arg) { ADD };
508
static PyObject * Snap_inplace_add(Snap *self, PyObject *arg) { INPLACE_ADD };
509
static PyObject * Snap_sub(Snap *self, PyObject *arg) { SUB };
510
static PyObject * Snap_inplace_sub(Snap *self, PyObject *arg) { INPLACE_SUB };
511
static PyObject * Snap_div(Snap *self, PyObject *arg) { DIV };
512
static PyObject * Snap_inplace_div(Snap *self, PyObject *arg) { INPLACE_DIV };
515
Snap_setChoice(Snap *self, PyObject *arg)
521
if (! PyList_Check(arg)) {
522
PyErr_SetString(PyExc_TypeError, "The choice attribute must be a list.");
528
self->chSize = PyList_Size(tmp);
529
self->choice = (MYFLT *)realloc(self->choice, self->chSize * sizeof(MYFLT));
531
for (i=0; i<self->chSize; i++) {
532
self->choice[i] = PyFloat_AS_DOUBLE(PyNumber_Float(PyList_GET_ITEM(tmp, i)));
535
max = self->choice[self->chSize-1];
542
self->highbound = oct;
544
(*self->mode_func_ptr)(self);
551
Snap_setScale(Snap *self, PyObject *arg)
559
int isNumber = PyInt_Check(arg);
562
tmp = PyInt_AsLong(arg);
563
if (tmp >= 0 && tmp <= 2)
566
printf("scale attribute must be an integer {0, 1, 2}\n");
573
static PyMemberDef Snap_members[] = {
574
{"server", T_OBJECT_EX, offsetof(Snap, server), 0, "Pyo server."},
575
{"stream", T_OBJECT_EX, offsetof(Snap, stream), 0, "Stream object."},
576
{"input", T_OBJECT_EX, offsetof(Snap, input), 0, "Input sound object."},
577
{"mul", T_OBJECT_EX, offsetof(Snap, mul), 0, "Mul factor."},
578
{"add", T_OBJECT_EX, offsetof(Snap, add), 0, "Add factor."},
579
{NULL} /* Sentinel */
582
static PyMethodDef Snap_methods[] = {
583
{"getServer", (PyCFunction)Snap_getServer, METH_NOARGS, "Returns server object."},
584
{"_getStream", (PyCFunction)Snap_getStream, METH_NOARGS, "Returns stream object."},
585
{"deleteStream", (PyCFunction)Snap_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
586
{"play", (PyCFunction)Snap_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
587
{"out", (PyCFunction)Snap_out, METH_VARARGS|METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
588
{"stop", (PyCFunction)Snap_stop, METH_NOARGS, "Stops computing."},
589
{"setChoice", (PyCFunction)Snap_setChoice, METH_O, "Sets output scale."},
590
{"setScale", (PyCFunction)Snap_setScale, METH_O, "Sets new portamento time."},
591
{"setMul", (PyCFunction)Snap_setMul, METH_O, "Sets oscillator mul factor."},
592
{"setAdd", (PyCFunction)Snap_setAdd, METH_O, "Sets oscillator add factor."},
593
{"setSub", (PyCFunction)Snap_setSub, METH_O, "Sets inverse add factor."},
594
{"setDiv", (PyCFunction)Snap_setDiv, METH_O, "Sets inverse mul factor."},
595
{NULL} /* Sentinel */
598
static PyNumberMethods Snap_as_number = {
599
(binaryfunc)Snap_add, /*nb_add*/
600
(binaryfunc)Snap_sub, /*nb_subtract*/
601
(binaryfunc)Snap_multiply, /*nb_multiply*/
602
(binaryfunc)Snap_div, /*nb_divide*/
608
0, /*(unaryfunc)array_abs,*/
622
(binaryfunc)Snap_inplace_add, /*inplace_add*/
623
(binaryfunc)Snap_inplace_sub, /*inplace_subtract*/
624
(binaryfunc)Snap_inplace_multiply, /*inplace_multiply*/
625
(binaryfunc)Snap_inplace_div, /*inplace_divide*/
626
0, /*inplace_remainder*/
628
0, /*inplace_lshift*/
629
0, /*inplace_rshift*/
633
0, /*nb_floor_divide*/
634
0, /*nb_true_divide*/
635
0, /*nb_inplace_floor_divide*/
636
0, /*nb_inplace_true_divide*/
640
PyTypeObject SnapType = {
641
PyObject_HEAD_INIT(NULL)
643
"_pyo.Snap_base", /*tp_name*/
644
sizeof(Snap), /*tp_basicsize*/
646
(destructor)Snap_dealloc, /*tp_dealloc*/
652
&Snap_as_number, /*tp_as_number*/
653
0, /*tp_as_sequence*/
661
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
662
"Snap objects. Snap input values on an arbitrary Midi scale.", /* tp_doc */
663
(traverseproc)Snap_traverse, /* tp_traverse */
664
(inquiry)Snap_clear, /* tp_clear */
665
0, /* tp_richcompare */
666
0, /* tp_weaklistoffset */
669
Snap_methods, /* tp_methods */
670
Snap_members, /* tp_members */
674
0, /* tp_descr_get */
675
0, /* tp_descr_set */
676
0, /* tp_dictoffset */
677
(initproc)Snap_init, /* tp_init */
679
Snap_new, /* tp_new */
688
Stream *input_stream;
690
Stream *input2_stream;
692
Stream *interp_stream;
693
int modebuffer[3]; // need at least 2 slots for mul & add
697
Interp_filters_i(Interp *self) {
700
MYFLT *in = Stream_getData((Stream *)self->input_stream);
701
MYFLT *in2 = Stream_getData((Stream *)self->input2_stream);
702
MYFLT inter = PyFloat_AS_DOUBLE(self->interp);
706
else if (inter > 1.0)
710
for (i=0; i<self->bufsize; i++) {
711
self->data[i] = in[i] * amp2 + in2[i] * inter;
716
Interp_filters_a(Interp *self) {
719
MYFLT *in = Stream_getData((Stream *)self->input_stream);
720
MYFLT *in2 = Stream_getData((Stream *)self->input2_stream);
721
MYFLT *inter = Stream_getData((Stream *)self->interp_stream);
723
for (i=0; i<self->bufsize; i++) {
731
self->data[i] = in[i] * amp2 + in2[i] * amp1;
735
static void Interp_postprocessing_ii(Interp *self) { POST_PROCESSING_II };
736
static void Interp_postprocessing_ai(Interp *self) { POST_PROCESSING_AI };
737
static void Interp_postprocessing_ia(Interp *self) { POST_PROCESSING_IA };
738
static void Interp_postprocessing_aa(Interp *self) { POST_PROCESSING_AA };
739
static void Interp_postprocessing_ireva(Interp *self) { POST_PROCESSING_IREVA };
740
static void Interp_postprocessing_areva(Interp *self) { POST_PROCESSING_AREVA };
741
static void Interp_postprocessing_revai(Interp *self) { POST_PROCESSING_REVAI };
742
static void Interp_postprocessing_revaa(Interp *self) { POST_PROCESSING_REVAA };
743
static void Interp_postprocessing_revareva(Interp *self) { POST_PROCESSING_REVAREVA };
746
Interp_setProcMode(Interp *self)
748
int procmode, muladdmode;
749
procmode = self->modebuffer[2];
750
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
754
self->proc_func_ptr = Interp_filters_i;
757
self->proc_func_ptr = Interp_filters_a;
760
switch (muladdmode) {
762
self->muladd_func_ptr = Interp_postprocessing_ii;
765
self->muladd_func_ptr = Interp_postprocessing_ai;
768
self->muladd_func_ptr = Interp_postprocessing_revai;
771
self->muladd_func_ptr = Interp_postprocessing_ia;
774
self->muladd_func_ptr = Interp_postprocessing_aa;
777
self->muladd_func_ptr = Interp_postprocessing_revaa;
780
self->muladd_func_ptr = Interp_postprocessing_ireva;
783
self->muladd_func_ptr = Interp_postprocessing_areva;
786
self->muladd_func_ptr = Interp_postprocessing_revareva;
792
Interp_compute_next_data_frame(Interp *self)
794
(*self->proc_func_ptr)(self);
795
(*self->muladd_func_ptr)(self);
799
Interp_traverse(Interp *self, visitproc visit, void *arg)
802
Py_VISIT(self->input);
803
Py_VISIT(self->input_stream);
804
Py_VISIT(self->input2);
805
Py_VISIT(self->input2_stream);
806
Py_VISIT(self->interp);
807
Py_VISIT(self->interp_stream);
812
Interp_clear(Interp *self)
815
Py_CLEAR(self->input);
816
Py_CLEAR(self->input_stream);
817
Py_CLEAR(self->input2);
818
Py_CLEAR(self->input2_stream);
819
Py_CLEAR(self->interp);
820
Py_CLEAR(self->interp_stream);
825
Interp_dealloc(Interp* self)
829
self->ob_type->tp_free((PyObject*)self);
832
static PyObject * Interp_deleteStream(Interp *self) { DELETE_STREAM };
835
Interp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
839
self = (Interp *)type->tp_alloc(type, 0);
841
self->interp = PyFloat_FromDouble(.5);
842
self->modebuffer[0] = 0;
843
self->modebuffer[1] = 0;
844
self->modebuffer[2] = 0;
847
Stream_setFunctionPtr(self->stream, Interp_compute_next_data_frame);
848
self->mode_func_ptr = Interp_setProcMode;
849
return (PyObject *)self;
853
Interp_init(Interp *self, PyObject *args, PyObject *kwds)
855
PyObject *inputtmp, *input_streamtmp, *input2tmp, *input2_streamtmp, *interptmp=NULL, *multmp=NULL, *addtmp=NULL;
857
static char *kwlist[] = {"input", "input2", "interp", "mul", "add", NULL};
859
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|OOO", kwlist, &inputtmp, &input2tmp, &interptmp, &multmp, &addtmp))
864
Py_XDECREF(self->input2);
865
self->input2 = input2tmp;
866
input2_streamtmp = PyObject_CallMethod((PyObject *)self->input2, "_getStream", NULL);
867
Py_INCREF(input2_streamtmp);
868
Py_XDECREF(self->input2_stream);
869
self->input2_stream = (Stream *)input2_streamtmp;
872
PyObject_CallMethod((PyObject *)self, "setInterp", "O", interptmp);
876
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
880
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
883
Py_INCREF(self->stream);
884
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
886
(*self->mode_func_ptr)(self);
892
static PyObject * Interp_getServer(Interp* self) { GET_SERVER };
893
static PyObject * Interp_getStream(Interp* self) { GET_STREAM };
894
static PyObject * Interp_setMul(Interp *self, PyObject *arg) { SET_MUL };
895
static PyObject * Interp_setAdd(Interp *self, PyObject *arg) { SET_ADD };
896
static PyObject * Interp_setSub(Interp *self, PyObject *arg) { SET_SUB };
897
static PyObject * Interp_setDiv(Interp *self, PyObject *arg) { SET_DIV };
899
static PyObject * Interp_play(Interp *self, PyObject *args, PyObject *kwds) { PLAY };
900
static PyObject * Interp_out(Interp *self, PyObject *args, PyObject *kwds) { OUT };
901
static PyObject * Interp_stop(Interp *self) { STOP };
903
static PyObject * Interp_multiply(Interp *self, PyObject *arg) { MULTIPLY };
904
static PyObject * Interp_inplace_multiply(Interp *self, PyObject *arg) { INPLACE_MULTIPLY };
905
static PyObject * Interp_add(Interp *self, PyObject *arg) { ADD };
906
static PyObject * Interp_inplace_add(Interp *self, PyObject *arg) { INPLACE_ADD };
907
static PyObject * Interp_sub(Interp *self, PyObject *arg) { SUB };
908
static PyObject * Interp_inplace_sub(Interp *self, PyObject *arg) { INPLACE_SUB };
909
static PyObject * Interp_div(Interp *self, PyObject *arg) { DIV };
910
static PyObject * Interp_inplace_div(Interp *self, PyObject *arg) { INPLACE_DIV };
913
Interp_setInterp(Interp *self, PyObject *arg)
915
PyObject *tmp, *streamtmp;
922
int isNumber = PyNumber_Check(arg);
926
Py_DECREF(self->interp);
928
self->interp = PyNumber_Float(tmp);
929
self->modebuffer[2] = 0;
933
streamtmp = PyObject_CallMethod((PyObject *)self->interp, "_getStream", NULL);
934
Py_INCREF(streamtmp);
935
Py_XDECREF(self->interp_stream);
936
self->interp_stream = (Stream *)streamtmp;
937
self->modebuffer[2] = 1;
940
(*self->mode_func_ptr)(self);
946
static PyMemberDef Interp_members[] = {
947
{"server", T_OBJECT_EX, offsetof(Interp, server), 0, "Pyo server."},
948
{"stream", T_OBJECT_EX, offsetof(Interp, stream), 0, "Stream object."},
949
{"input", T_OBJECT_EX, offsetof(Interp, input), 0, "Input sound object."},
950
{"input2", T_OBJECT_EX, offsetof(Interp, input2), 0, "Second input sound object."},
951
{"interp", T_OBJECT_EX, offsetof(Interp, interp), 0, "Cutoff interpuency in cycle per second."},
952
{"mul", T_OBJECT_EX, offsetof(Interp, mul), 0, "Mul factor."},
953
{"add", T_OBJECT_EX, offsetof(Interp, add), 0, "Add factor."},
954
{NULL} /* Sentinel */
957
static PyMethodDef Interp_methods[] = {
958
{"getServer", (PyCFunction)Interp_getServer, METH_NOARGS, "Returns server object."},
959
{"_getStream", (PyCFunction)Interp_getStream, METH_NOARGS, "Returns stream object."},
960
{"deleteStream", (PyCFunction)Interp_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
961
{"play", (PyCFunction)Interp_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
962
{"out", (PyCFunction)Interp_out, METH_VARARGS|METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
963
{"stop", (PyCFunction)Interp_stop, METH_NOARGS, "Stops computing."},
964
{"setInterp", (PyCFunction)Interp_setInterp, METH_O, "Sets filter cutoff interpuency in cycle per second."},
965
{"setMul", (PyCFunction)Interp_setMul, METH_O, "Sets oscillator mul factor."},
966
{"setAdd", (PyCFunction)Interp_setAdd, METH_O, "Sets oscillator add factor."},
967
{"setSub", (PyCFunction)Interp_setSub, METH_O, "Sets inverse add factor."},
968
{"setDiv", (PyCFunction)Interp_setDiv, METH_O, "Sets inverse mul factor."},
969
{NULL} /* Sentinel */
972
static PyNumberMethods Interp_as_number = {
973
(binaryfunc)Interp_add, /*nb_add*/
974
(binaryfunc)Interp_sub, /*nb_subtract*/
975
(binaryfunc)Interp_multiply, /*nb_multiply*/
976
(binaryfunc)Interp_div, /*nb_divide*/
982
0, /*(unaryfunc)array_abs,*/
996
(binaryfunc)Interp_inplace_add, /*inplace_add*/
997
(binaryfunc)Interp_inplace_sub, /*inplace_subtract*/
998
(binaryfunc)Interp_inplace_multiply, /*inplace_multiply*/
999
(binaryfunc)Interp_inplace_div, /*inplace_divide*/
1000
0, /*inplace_remainder*/
1001
0, /*inplace_power*/
1002
0, /*inplace_lshift*/
1003
0, /*inplace_rshift*/
1007
0, /*nb_floor_divide*/
1008
0, /*nb_true_divide*/
1009
0, /*nb_inplace_floor_divide*/
1010
0, /*nb_inplace_true_divide*/
1014
PyTypeObject InterpType = {
1015
PyObject_HEAD_INIT(NULL)
1017
"_pyo.Interp_base", /*tp_name*/
1018
sizeof(Interp), /*tp_basicsize*/
1020
(destructor)Interp_dealloc, /*tp_dealloc*/
1026
&Interp_as_number, /*tp_as_number*/
1027
0, /*tp_as_sequence*/
1028
0, /*tp_as_mapping*/
1035
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
1036
"Interp objects. Interpolates between 2 audio streams.", /* tp_doc */
1037
(traverseproc)Interp_traverse, /* tp_traverse */
1038
(inquiry)Interp_clear, /* tp_clear */
1039
0, /* tp_richcompare */
1040
0, /* tp_weaklistoffset */
1042
0, /* tp_iternext */
1043
Interp_methods, /* tp_methods */
1044
Interp_members, /* tp_members */
1048
0, /* tp_descr_get */
1049
0, /* tp_descr_set */
1050
0, /* tp_dictoffset */
1051
(initproc)Interp_init, /* tp_init */
1053
Interp_new, /* tp_new */
1062
Stream *input_stream;
1063
PyObject *controlsig;
1064
Stream *controlsig_stream;
1066
Stream *value_stream;
1069
int modebuffer[3]; // need at least 2 slots for mul & add
1073
SampHold_filters_i(SampHold *self) {
1076
MYFLT *in = Stream_getData((Stream *)self->input_stream);
1077
MYFLT *ctrlsig = Stream_getData((Stream *)self->controlsig_stream);
1078
MYFLT val = PyFloat_AS_DOUBLE(self->value);
1080
for (i=0; i<self->bufsize; i++) {
1082
if (ctrl > (val - 0.001) && ctrl < (val + 0.001)) {
1083
if (self->flag == 1) {
1084
self->currentValue = in[i];
1090
self->data[i] = self->currentValue;
1095
SampHold_filters_a(SampHold *self) {
1098
MYFLT *in = Stream_getData((Stream *)self->input_stream);
1099
MYFLT *ctrlsig = Stream_getData((Stream *)self->controlsig_stream);
1100
MYFLT *valsig = Stream_getData((Stream *)self->value_stream);
1102
for (i=0; i<self->bufsize; i++) {
1105
if (ctrl > (val - 0.001) && ctrl < (val + 0.001)) {
1106
if (self->flag == 1) {
1107
self->currentValue = in[i];
1113
self->data[i] = self->currentValue;
1117
static void SampHold_postprocessing_ii(SampHold *self) { POST_PROCESSING_II };
1118
static void SampHold_postprocessing_ai(SampHold *self) { POST_PROCESSING_AI };
1119
static void SampHold_postprocessing_ia(SampHold *self) { POST_PROCESSING_IA };
1120
static void SampHold_postprocessing_aa(SampHold *self) { POST_PROCESSING_AA };
1121
static void SampHold_postprocessing_ireva(SampHold *self) { POST_PROCESSING_IREVA };
1122
static void SampHold_postprocessing_areva(SampHold *self) { POST_PROCESSING_AREVA };
1123
static void SampHold_postprocessing_revai(SampHold *self) { POST_PROCESSING_REVAI };
1124
static void SampHold_postprocessing_revaa(SampHold *self) { POST_PROCESSING_REVAA };
1125
static void SampHold_postprocessing_revareva(SampHold *self) { POST_PROCESSING_REVAREVA };
1128
SampHold_setProcMode(SampHold *self)
1130
int procmode, muladdmode;
1131
procmode = self->modebuffer[2];
1132
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
1136
self->proc_func_ptr = SampHold_filters_i;
1139
self->proc_func_ptr = SampHold_filters_a;
1142
switch (muladdmode) {
1144
self->muladd_func_ptr = SampHold_postprocessing_ii;
1147
self->muladd_func_ptr = SampHold_postprocessing_ai;
1150
self->muladd_func_ptr = SampHold_postprocessing_revai;
1153
self->muladd_func_ptr = SampHold_postprocessing_ia;
1156
self->muladd_func_ptr = SampHold_postprocessing_aa;
1159
self->muladd_func_ptr = SampHold_postprocessing_revaa;
1162
self->muladd_func_ptr = SampHold_postprocessing_ireva;
1165
self->muladd_func_ptr = SampHold_postprocessing_areva;
1168
self->muladd_func_ptr = SampHold_postprocessing_revareva;
1174
SampHold_compute_next_data_frame(SampHold *self)
1176
(*self->proc_func_ptr)(self);
1177
(*self->muladd_func_ptr)(self);
1181
SampHold_traverse(SampHold *self, visitproc visit, void *arg)
1184
Py_VISIT(self->input);
1185
Py_VISIT(self->input_stream);
1186
Py_VISIT(self->controlsig);
1187
Py_VISIT(self->controlsig_stream);
1188
Py_VISIT(self->value);
1189
Py_VISIT(self->value_stream);
1194
SampHold_clear(SampHold *self)
1197
Py_CLEAR(self->input);
1198
Py_CLEAR(self->input_stream);
1199
Py_CLEAR(self->controlsig);
1200
Py_CLEAR(self->controlsig_stream);
1201
Py_CLEAR(self->value);
1202
Py_CLEAR(self->value_stream);
1207
SampHold_dealloc(SampHold* self)
1210
SampHold_clear(self);
1211
self->ob_type->tp_free((PyObject*)self);
1214
static PyObject * SampHold_deleteStream(SampHold *self) { DELETE_STREAM };
1217
SampHold_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1221
self = (SampHold *)type->tp_alloc(type, 0);
1223
self->value = PyFloat_FromDouble(0.0);
1224
self->currentValue = 0.0;
1226
self->modebuffer[0] = 0;
1227
self->modebuffer[1] = 0;
1228
self->modebuffer[2] = 0;
1231
Stream_setFunctionPtr(self->stream, SampHold_compute_next_data_frame);
1232
self->mode_func_ptr = SampHold_setProcMode;
1233
return (PyObject *)self;
1237
SampHold_init(SampHold *self, PyObject *args, PyObject *kwds)
1239
PyObject *inputtmp, *input_streamtmp, *controlsigtmp, *controlsig_streamtmp, *valuetmp=NULL, *multmp=NULL, *addtmp=NULL;
1241
static char *kwlist[] = {"input", "controlsig", "value", "mul", "add", NULL};
1243
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|OOO", kwlist, &inputtmp, &controlsigtmp, &valuetmp, &multmp, &addtmp))
1248
Py_XDECREF(self->controlsig); \
1249
self->controlsig = controlsigtmp; \
1250
controlsig_streamtmp = PyObject_CallMethod((PyObject *)self->controlsig, "_getStream", NULL); \
1251
Py_INCREF(controlsig_streamtmp); \
1252
Py_XDECREF(self->controlsig_stream); \
1253
self->controlsig_stream = (Stream *)controlsig_streamtmp;
1256
PyObject_CallMethod((PyObject *)self, "setValue", "O", valuetmp);
1260
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
1264
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
1267
Py_INCREF(self->stream);
1268
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1270
(*self->mode_func_ptr)(self);
1276
static PyObject * SampHold_getServer(SampHold* self) { GET_SERVER };
1277
static PyObject * SampHold_getStream(SampHold* self) { GET_STREAM };
1278
static PyObject * SampHold_setMul(SampHold *self, PyObject *arg) { SET_MUL };
1279
static PyObject * SampHold_setAdd(SampHold *self, PyObject *arg) { SET_ADD };
1280
static PyObject * SampHold_setSub(SampHold *self, PyObject *arg) { SET_SUB };
1281
static PyObject * SampHold_setDiv(SampHold *self, PyObject *arg) { SET_DIV };
1283
static PyObject * SampHold_play(SampHold *self, PyObject *args, PyObject *kwds) { PLAY };
1284
static PyObject * SampHold_out(SampHold *self, PyObject *args, PyObject *kwds) { OUT };
1285
static PyObject * SampHold_stop(SampHold *self) { STOP };
1287
static PyObject * SampHold_multiply(SampHold *self, PyObject *arg) { MULTIPLY };
1288
static PyObject * SampHold_inplace_multiply(SampHold *self, PyObject *arg) { INPLACE_MULTIPLY };
1289
static PyObject * SampHold_add(SampHold *self, PyObject *arg) { ADD };
1290
static PyObject * SampHold_inplace_add(SampHold *self, PyObject *arg) { INPLACE_ADD };
1291
static PyObject * SampHold_sub(SampHold *self, PyObject *arg) { SUB };
1292
static PyObject * SampHold_inplace_sub(SampHold *self, PyObject *arg) { INPLACE_SUB };
1293
static PyObject * SampHold_div(SampHold *self, PyObject *arg) { DIV };
1294
static PyObject * SampHold_inplace_div(SampHold *self, PyObject *arg) { INPLACE_DIV };
1297
SampHold_setValue(SampHold *self, PyObject *arg)
1299
PyObject *tmp, *streamtmp;
1306
int isNumber = PyNumber_Check(arg);
1310
Py_DECREF(self->value);
1311
if (isNumber == 1) {
1312
self->value = PyNumber_Float(tmp);
1313
self->modebuffer[2] = 0;
1317
streamtmp = PyObject_CallMethod((PyObject *)self->value, "_getStream", NULL);
1318
Py_INCREF(streamtmp);
1319
Py_XDECREF(self->value_stream);
1320
self->value_stream = (Stream *)streamtmp;
1321
self->modebuffer[2] = 1;
1324
(*self->mode_func_ptr)(self);
1330
static PyMemberDef SampHold_members[] = {
1331
{"server", T_OBJECT_EX, offsetof(SampHold, server), 0, "Pyo server."},
1332
{"stream", T_OBJECT_EX, offsetof(SampHold, stream), 0, "Stream object."},
1333
{"input", T_OBJECT_EX, offsetof(SampHold, input), 0, "Input sound object."},
1334
{"controlsig", T_OBJECT_EX, offsetof(SampHold, controlsig), 0, "Control input object."},
1335
{"value", T_OBJECT_EX, offsetof(SampHold, value), 0, "Trigger value."},
1336
{"mul", T_OBJECT_EX, offsetof(SampHold, mul), 0, "Mul factor."},
1337
{"add", T_OBJECT_EX, offsetof(SampHold, add), 0, "Add factor."},
1338
{NULL} /* Sentinel */
1341
static PyMethodDef SampHold_methods[] = {
1342
{"getServer", (PyCFunction)SampHold_getServer, METH_NOARGS, "Returns server object."},
1343
{"_getStream", (PyCFunction)SampHold_getStream, METH_NOARGS, "Returns stream object."},
1344
{"deleteStream", (PyCFunction)SampHold_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
1345
{"play", (PyCFunction)SampHold_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1346
{"out", (PyCFunction)SampHold_out, METH_VARARGS|METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
1347
{"stop", (PyCFunction)SampHold_stop, METH_NOARGS, "Stops computing."},
1348
{"setValue", (PyCFunction)SampHold_setValue, METH_O, "Sets trigger value."},
1349
{"setMul", (PyCFunction)SampHold_setMul, METH_O, "Sets oscillator mul factor."},
1350
{"setAdd", (PyCFunction)SampHold_setAdd, METH_O, "Sets oscillator add factor."},
1351
{"setSub", (PyCFunction)SampHold_setSub, METH_O, "Sets inverse add factor."},
1352
{"setDiv", (PyCFunction)SampHold_setDiv, METH_O, "Sets inverse mul factor."},
1353
{NULL} /* Sentinel */
1356
static PyNumberMethods SampHold_as_number = {
1357
(binaryfunc)SampHold_add, /*nb_add*/
1358
(binaryfunc)SampHold_sub, /*nb_subtract*/
1359
(binaryfunc)SampHold_multiply, /*nb_multiply*/
1360
(binaryfunc)SampHold_div, /*nb_divide*/
1366
0, /*(unaryfunc)array_abs,*/
1380
(binaryfunc)SampHold_inplace_add, /*inplace_add*/
1381
(binaryfunc)SampHold_inplace_sub, /*inplace_subtract*/
1382
(binaryfunc)SampHold_inplace_multiply, /*inplace_multiply*/
1383
(binaryfunc)SampHold_inplace_div, /*inplace_divide*/
1384
0, /*inplace_remainder*/
1385
0, /*inplace_power*/
1386
0, /*inplace_lshift*/
1387
0, /*inplace_rshift*/
1391
0, /*nb_floor_divide*/
1392
0, /*nb_true_divide*/
1393
0, /*nb_inplace_floor_divide*/
1394
0, /*nb_inplace_true_divide*/
1398
PyTypeObject SampHoldType = {
1399
PyObject_HEAD_INIT(NULL)
1401
"_pyo.SampHold_base", /*tp_name*/
1402
sizeof(SampHold), /*tp_basicsize*/
1404
(destructor)SampHold_dealloc, /*tp_dealloc*/
1410
&SampHold_as_number, /*tp_as_number*/
1411
0, /*tp_as_sequence*/
1412
0, /*tp_as_mapping*/
1419
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
1420
"SampHold objects. SampHoldolates between 2 audio streams.", /* tp_doc */
1421
(traverseproc)SampHold_traverse, /* tp_traverse */
1422
(inquiry)SampHold_clear, /* tp_clear */
1423
0, /* tp_richcompare */
1424
0, /* tp_weaklistoffset */
1426
0, /* tp_iternext */
1427
SampHold_methods, /* tp_methods */
1428
SampHold_members, /* tp_members */
1432
0, /* tp_descr_get */
1433
0, /* tp_descr_set */
1434
0, /* tp_dictoffset */
1435
(initproc)SampHold_init, /* tp_init */
1437
SampHold_new, /* tp_new */
1446
Stream *input_stream;
1448
Stream *comp_stream;
1449
MYFLT (*compare_func_ptr)(MYFLT, MYFLT); // true = 1.0, false = 0.0
1450
int modebuffer[3]; // need at least 2 slots for mul & add
1454
Compare_lt(MYFLT in, MYFLT comp) {
1455
if (in < comp) { return 1.0; }
1456
else { return 0.0; }
1460
Compare_elt(MYFLT in, MYFLT comp) {
1461
if (in <= comp) { return 1.0; }
1462
else { return 0.0; }
1466
Compare_gt(MYFLT in, MYFLT comp) {
1467
if (in > comp) { return 1.0; }
1468
else { return 0.0; }
1472
Compare_egt(MYFLT in, MYFLT comp) {
1473
if (in >= comp) { return 1.0; }
1474
else { return 0.0; }
1478
Compare_eq(MYFLT in, MYFLT comp) {
1479
if (in >= (comp - 0.0001) && in <= (comp + 0.0001)) { return 1.0; }
1480
else { return 0.0; }
1484
Compare_neq(MYFLT in, MYFLT comp) {
1485
if (in <= (comp - 0.0001) || in >= (comp + 0.0001)) { return 1.0; }
1486
else { return 0.0; }
1490
Compare_process_i(Compare *self) {
1492
MYFLT *in = Stream_getData((Stream *)self->input_stream);
1493
MYFLT comp = PyFloat_AS_DOUBLE(self->comp);
1495
for (i=0; i<self->bufsize; i++) {
1496
self->data[i] = (*self->compare_func_ptr)(in[i], comp);
1501
Compare_process_a(Compare *self) {
1503
MYFLT *in = Stream_getData((Stream *)self->input_stream);
1504
MYFLT *comp = Stream_getData((Stream *)self->comp_stream);
1506
for (i=0; i<self->bufsize; i++) {
1507
self->data[i] = (*self->compare_func_ptr)(in[i], comp[i]);
1511
static void Compare_postprocessing_ii(Compare *self) { POST_PROCESSING_II };
1512
static void Compare_postprocessing_ai(Compare *self) { POST_PROCESSING_AI };
1513
static void Compare_postprocessing_ia(Compare *self) { POST_PROCESSING_IA };
1514
static void Compare_postprocessing_aa(Compare *self) { POST_PROCESSING_AA };
1515
static void Compare_postprocessing_ireva(Compare *self) { POST_PROCESSING_IREVA };
1516
static void Compare_postprocessing_areva(Compare *self) { POST_PROCESSING_AREVA };
1517
static void Compare_postprocessing_revai(Compare *self) { POST_PROCESSING_REVAI };
1518
static void Compare_postprocessing_revaa(Compare *self) { POST_PROCESSING_REVAA };
1519
static void Compare_postprocessing_revareva(Compare *self) { POST_PROCESSING_REVAREVA };
1522
Compare_setProcMode(Compare *self)
1524
int procmode, muladdmode;
1525
procmode = self->modebuffer[2];
1526
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
1530
self->proc_func_ptr = Compare_process_i;
1533
self->proc_func_ptr = Compare_process_a;
1536
switch (muladdmode) {
1538
self->muladd_func_ptr = Compare_postprocessing_ii;
1541
self->muladd_func_ptr = Compare_postprocessing_ai;
1544
self->muladd_func_ptr = Compare_postprocessing_revai;
1547
self->muladd_func_ptr = Compare_postprocessing_ia;
1550
self->muladd_func_ptr = Compare_postprocessing_aa;
1553
self->muladd_func_ptr = Compare_postprocessing_revaa;
1556
self->muladd_func_ptr = Compare_postprocessing_ireva;
1559
self->muladd_func_ptr = Compare_postprocessing_areva;
1562
self->muladd_func_ptr = Compare_postprocessing_revareva;
1568
Compare_compute_next_data_frame(Compare *self)
1570
(*self->proc_func_ptr)(self);
1571
(*self->muladd_func_ptr)(self);
1575
Compare_traverse(Compare *self, visitproc visit, void *arg)
1578
Py_VISIT(self->input);
1579
Py_VISIT(self->input_stream);
1580
Py_VISIT(self->comp);
1581
Py_VISIT(self->comp_stream);
1586
Compare_clear(Compare *self)
1589
Py_CLEAR(self->input);
1590
Py_CLEAR(self->input_stream);
1591
Py_CLEAR(self->comp);
1592
Py_CLEAR(self->comp_stream);
1597
Compare_dealloc(Compare* self)
1600
Compare_clear(self);
1601
self->ob_type->tp_free((PyObject*)self);
1604
static PyObject * Compare_deleteStream(Compare *self) { DELETE_STREAM };
1607
Compare_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1611
self = (Compare *)type->tp_alloc(type, 0);
1613
self->modebuffer[0] = 0;
1614
self->modebuffer[1] = 0;
1615
self->modebuffer[2] = 0;
1617
self->compare_func_ptr = Compare_lt;
1620
Stream_setFunctionPtr(self->stream, Compare_compute_next_data_frame);
1621
self->mode_func_ptr = Compare_setProcMode;
1622
return (PyObject *)self;
1626
Compare_init(Compare *self, PyObject *args, PyObject *kwds)
1628
PyObject *inputtmp, *input_streamtmp, *comptmp, *modetmp=NULL, *multmp=NULL, *addtmp=NULL;
1630
static char *kwlist[] = {"input", "comp", "mode", "mul", "add", NULL};
1632
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|OOO", kwlist, &inputtmp, &comptmp, &modetmp, &multmp, &addtmp))
1638
PyObject_CallMethod((PyObject *)self, "setComp", "O", comptmp);
1642
PyObject_CallMethod((PyObject *)self, "setMode", "O", modetmp);
1646
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
1650
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
1653
Py_INCREF(self->stream);
1654
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1656
(*self->mode_func_ptr)(self);
1662
static PyObject * Compare_getServer(Compare* self) { GET_SERVER };
1663
static PyObject * Compare_getStream(Compare* self) { GET_STREAM };
1664
static PyObject * Compare_setMul(Compare *self, PyObject *arg) { SET_MUL };
1665
static PyObject * Compare_setAdd(Compare *self, PyObject *arg) { SET_ADD };
1666
static PyObject * Compare_setSub(Compare *self, PyObject *arg) { SET_SUB };
1667
static PyObject * Compare_setDiv(Compare *self, PyObject *arg) { SET_DIV };
1669
static PyObject * Compare_play(Compare *self, PyObject *args, PyObject *kwds) { PLAY };
1670
static PyObject * Compare_stop(Compare *self) { STOP };
1672
static PyObject * Compare_multiply(Compare *self, PyObject *arg) { MULTIPLY };
1673
static PyObject * Compare_inplace_multiply(Compare *self, PyObject *arg) { INPLACE_MULTIPLY };
1674
static PyObject * Compare_add(Compare *self, PyObject *arg) { ADD };
1675
static PyObject * Compare_inplace_add(Compare *self, PyObject *arg) { INPLACE_ADD };
1676
static PyObject * Compare_sub(Compare *self, PyObject *arg) { SUB };
1677
static PyObject * Compare_inplace_sub(Compare *self, PyObject *arg) { INPLACE_SUB };
1678
static PyObject * Compare_div(Compare *self, PyObject *arg) { DIV };
1679
static PyObject * Compare_inplace_div(Compare *self, PyObject *arg) { INPLACE_DIV };
1682
Compare_setComp(Compare *self, PyObject *arg)
1684
PyObject *tmp, *streamtmp;
1690
int isNumber = PyNumber_Check(arg);
1694
Py_XDECREF(self->comp);
1695
if (isNumber == 1) {
1696
self->comp = PyNumber_Float(tmp);
1697
self->modebuffer[2] = 0;
1701
streamtmp = PyObject_CallMethod((PyObject *)self->comp, "_getStream", NULL);
1702
Py_INCREF(streamtmp);
1703
Py_XDECREF(self->comp_stream);
1704
self->comp_stream = (Stream *)streamtmp;
1705
self->modebuffer[2] = 1;
1708
(*self->mode_func_ptr)(self);
1715
Compare_setMode(Compare *self, PyObject *arg)
1721
if (! PyInt_Check(arg)) {
1722
printf("mode should be a comparison operator as a string\n");
1726
int tmp = PyInt_AsLong(arg);
1729
self->compare_func_ptr = Compare_lt;
1731
self->compare_func_ptr = Compare_elt;
1733
self->compare_func_ptr = Compare_gt;
1735
self->compare_func_ptr = Compare_egt;
1737
self->compare_func_ptr = Compare_eq;
1739
self->compare_func_ptr = Compare_neq;
1744
static PyMemberDef Compare_members[] = {
1745
{"server", T_OBJECT_EX, offsetof(Compare, server), 0, "Pyo server."},
1746
{"stream", T_OBJECT_EX, offsetof(Compare, stream), 0, "Stream object."},
1747
{"input", T_OBJECT_EX, offsetof(Compare, input), 0, "Input sound object."},
1748
{"comp", T_OBJECT_EX, offsetof(Compare, comp), 0, "Comparison object."},
1749
{"mul", T_OBJECT_EX, offsetof(Compare, mul), 0, "Mul factor."},
1750
{"add", T_OBJECT_EX, offsetof(Compare, add), 0, "Add factor."},
1751
{NULL} /* Sentinel */
1754
static PyMethodDef Compare_methods[] = {
1755
{"getServer", (PyCFunction)Compare_getServer, METH_NOARGS, "Returns server object."},
1756
{"_getStream", (PyCFunction)Compare_getStream, METH_NOARGS, "Returns stream object."},
1757
{"deleteStream", (PyCFunction)Compare_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
1758
{"play", (PyCFunction)Compare_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1759
{"stop", (PyCFunction)Compare_stop, METH_NOARGS, "Stops computing."},
1760
{"setComp", (PyCFunction)Compare_setComp, METH_O, "Sets the comparison object."},
1761
{"setMode", (PyCFunction)Compare_setMode, METH_O, "Sets the comparison mode."},
1762
{"setMul", (PyCFunction)Compare_setMul, METH_O, "Sets mul factor."},
1763
{"setAdd", (PyCFunction)Compare_setAdd, METH_O, "Sets add factor."},
1764
{"setSub", (PyCFunction)Compare_setSub, METH_O, "Sets inverse add factor."},
1765
{"setDiv", (PyCFunction)Compare_setDiv, METH_O, "Sets inverse mul factor."},
1766
{NULL} /* Sentinel */
1769
static PyNumberMethods Compare_as_number = {
1770
(binaryfunc)Compare_add, /*nb_add*/
1771
(binaryfunc)Compare_sub, /*nb_subtract*/
1772
(binaryfunc)Compare_multiply, /*nb_multiply*/
1773
(binaryfunc)Compare_div, /*nb_divide*/
1779
0, /*(unaryfunc)array_abs,*/
1793
(binaryfunc)Compare_inplace_add, /*inplace_add*/
1794
(binaryfunc)Compare_inplace_sub, /*inplace_subtract*/
1795
(binaryfunc)Compare_inplace_multiply, /*inplace_multiply*/
1796
(binaryfunc)Compare_inplace_div, /*inplace_divide*/
1797
0, /*inplace_remainder*/
1798
0, /*inplace_power*/
1799
0, /*inplace_lshift*/
1800
0, /*inplace_rshift*/
1804
0, /*nb_floor_divide*/
1805
0, /*nb_true_divide*/
1806
0, /*nb_inplace_floor_divide*/
1807
0, /*nb_inplace_true_divide*/
1811
PyTypeObject CompareType = {
1812
PyObject_HEAD_INIT(NULL)
1814
"_pyo.Compare_base", /*tp_name*/
1815
sizeof(Compare), /*tp_basicsize*/
1817
(destructor)Compare_dealloc, /*tp_dealloc*/
1823
&Compare_as_number, /*tp_as_number*/
1824
0, /*tp_as_sequence*/
1825
0, /*tp_as_mapping*/
1832
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
1833
"Compare objects. Comparison between 2 audio streams.", /* tp_doc */
1834
(traverseproc)Compare_traverse, /* tp_traverse */
1835
(inquiry)Compare_clear, /* tp_clear */
1836
0, /* tp_richcompare */
1837
0, /* tp_weaklistoffset */
1839
0, /* tp_iternext */
1840
Compare_methods, /* tp_methods */
1841
Compare_members, /* tp_members */
1845
0, /* tp_descr_get */
1846
0, /* tp_descr_set */
1847
0, /* tp_dictoffset */
1848
(initproc)Compare_init, /* tp_init */
1850
Compare_new, /* tp_new */
1854
/** Between object **/
1860
Stream *input_stream;
1869
Between_transform_ii(Between *self) {
1872
MYFLT *in = Stream_getData((Stream *)self->input_stream);
1873
MYFLT mi = PyFloat_AS_DOUBLE(self->min);
1874
MYFLT ma = PyFloat_AS_DOUBLE(self->max);
1876
for (i=0; i<self->bufsize; i++) {
1878
if(val >= mi && val < ma)
1879
self->data[i] = 1.0;
1881
self->data[i] = 0.0;
1886
Between_transform_ai(Between *self) {
1889
MYFLT *in = Stream_getData((Stream *)self->input_stream);
1890
MYFLT *mi = Stream_getData((Stream *)self->min_stream);
1891
MYFLT ma = PyFloat_AS_DOUBLE(self->max);
1893
for (i=0; i<self->bufsize; i++) {
1895
if(val >= mi[i] && val < ma)
1896
self->data[i] = 1.0;
1898
self->data[i] = 0.0;
1903
Between_transform_ia(Between *self) {
1906
MYFLT *in = Stream_getData((Stream *)self->input_stream);
1907
MYFLT mi = PyFloat_AS_DOUBLE(self->min);
1908
MYFLT *ma = Stream_getData((Stream *)self->max_stream);
1910
for (i=0; i<self->bufsize; i++) {
1912
if(val >= mi && val < ma[i])
1913
self->data[i] = 1.0;
1915
self->data[i] = 0.0;
1920
Between_transform_aa(Between *self) {
1923
MYFLT *in = Stream_getData((Stream *)self->input_stream);
1924
MYFLT *mi = Stream_getData((Stream *)self->min_stream);
1925
MYFLT *ma = Stream_getData((Stream *)self->max_stream);
1927
for (i=0; i<self->bufsize; i++) {
1929
if(val >= mi[i] && val < ma[i])
1930
self->data[i] = 1.0;
1932
self->data[i] = 0.0;
1936
static void Between_postprocessing_ii(Between *self) { POST_PROCESSING_II };
1937
static void Between_postprocessing_ai(Between *self) { POST_PROCESSING_AI };
1938
static void Between_postprocessing_ia(Between *self) { POST_PROCESSING_IA };
1939
static void Between_postprocessing_aa(Between *self) { POST_PROCESSING_AA };
1940
static void Between_postprocessing_ireva(Between *self) { POST_PROCESSING_IREVA };
1941
static void Between_postprocessing_areva(Between *self) { POST_PROCESSING_AREVA };
1942
static void Between_postprocessing_revai(Between *self) { POST_PROCESSING_REVAI };
1943
static void Between_postprocessing_revaa(Between *self) { POST_PROCESSING_REVAA };
1944
static void Between_postprocessing_revareva(Between *self) { POST_PROCESSING_REVAREVA };
1947
Between_setProcMode(Between *self)
1949
int procmode, muladdmode;
1950
procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
1951
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
1955
self->proc_func_ptr = Between_transform_ii;
1958
self->proc_func_ptr = Between_transform_ai;
1961
self->proc_func_ptr = Between_transform_ia;
1964
self->proc_func_ptr = Between_transform_aa;
1967
switch (muladdmode) {
1969
self->muladd_func_ptr = Between_postprocessing_ii;
1972
self->muladd_func_ptr = Between_postprocessing_ai;
1975
self->muladd_func_ptr = Between_postprocessing_revai;
1978
self->muladd_func_ptr = Between_postprocessing_ia;
1981
self->muladd_func_ptr = Between_postprocessing_aa;
1984
self->muladd_func_ptr = Between_postprocessing_revaa;
1987
self->muladd_func_ptr = Between_postprocessing_ireva;
1990
self->muladd_func_ptr = Between_postprocessing_areva;
1993
self->muladd_func_ptr = Between_postprocessing_revareva;
1999
Between_compute_next_data_frame(Between *self)
2001
(*self->proc_func_ptr)(self);
2002
(*self->muladd_func_ptr)(self);
2006
Between_traverse(Between *self, visitproc visit, void *arg)
2009
Py_VISIT(self->input);
2010
Py_VISIT(self->input_stream);
2011
Py_VISIT(self->min);
2012
Py_VISIT(self->min_stream);
2013
Py_VISIT(self->max);
2014
Py_VISIT(self->max_stream);
2019
Between_clear(Between *self)
2022
Py_CLEAR(self->input);
2023
Py_CLEAR(self->input_stream);
2024
Py_CLEAR(self->min);
2025
Py_CLEAR(self->min_stream);
2026
Py_CLEAR(self->max);
2027
Py_CLEAR(self->max_stream);
2032
Between_dealloc(Between* self)
2035
Between_clear(self);
2036
self->ob_type->tp_free((PyObject*)self);
2039
static PyObject * Between_deleteStream(Between *self) { DELETE_STREAM };
2042
Between_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2046
self = (Between *)type->tp_alloc(type, 0);
2048
self->min = PyFloat_FromDouble(0.0);
2049
self->max = PyFloat_FromDouble(1.0);
2050
self->modebuffer[0] = 0;
2051
self->modebuffer[1] = 0;
2052
self->modebuffer[2] = 0;
2053
self->modebuffer[3] = 0;
2056
Stream_setFunctionPtr(self->stream, Between_compute_next_data_frame);
2057
self->mode_func_ptr = Between_setProcMode;
2059
return (PyObject *)self;
2063
Between_init(Between *self, PyObject *args, PyObject *kwds)
2065
PyObject *inputtmp, *input_streamtmp, *mintmp=NULL, *maxtmp=NULL, *multmp=NULL, *addtmp=NULL;
2067
static char *kwlist[] = {"input", "min", "max", "mul", "add", NULL};
2069
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OOOO", kwlist, &inputtmp, &mintmp, &maxtmp, &multmp, &addtmp))
2075
PyObject_CallMethod((PyObject *)self, "setMin", "O", mintmp);
2079
PyObject_CallMethod((PyObject *)self, "setMax", "O", maxtmp);
2083
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
2087
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
2090
Py_INCREF(self->stream);
2091
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
2093
(*self->mode_func_ptr)(self);
2099
static PyObject * Between_getServer(Between* self) { GET_SERVER };
2100
static PyObject * Between_getStream(Between* self) { GET_STREAM };
2101
static PyObject * Between_setMul(Between *self, PyObject *arg) { SET_MUL };
2102
static PyObject * Between_setAdd(Between *self, PyObject *arg) { SET_ADD };
2103
static PyObject * Between_setSub(Between *self, PyObject *arg) { SET_SUB };
2104
static PyObject * Between_setDiv(Between *self, PyObject *arg) { SET_DIV };
2106
static PyObject * Between_play(Between *self, PyObject *args, PyObject *kwds) { PLAY };
2107
static PyObject * Between_out(Between *self, PyObject *args, PyObject *kwds) { OUT };
2108
static PyObject * Between_stop(Between *self) { STOP };
2110
static PyObject * Between_multiply(Between *self, PyObject *arg) { MULTIPLY };
2111
static PyObject * Between_inplace_multiply(Between *self, PyObject *arg) { INPLACE_MULTIPLY };
2112
static PyObject * Between_add(Between *self, PyObject *arg) { ADD };
2113
static PyObject * Between_inplace_add(Between *self, PyObject *arg) { INPLACE_ADD };
2114
static PyObject * Between_sub(Between *self, PyObject *arg) { SUB };
2115
static PyObject * Between_inplace_sub(Between *self, PyObject *arg) { INPLACE_SUB };
2116
static PyObject * Between_div(Between *self, PyObject *arg) { DIV };
2117
static PyObject * Between_inplace_div(Between *self, PyObject *arg) { INPLACE_DIV };
2120
Between_setMin(Between *self, PyObject *arg)
2122
PyObject *tmp, *streamtmp;
2129
int isNumber = PyNumber_Check(arg);
2133
Py_DECREF(self->min);
2134
if (isNumber == 1) {
2135
self->min = PyNumber_Float(tmp);
2136
self->modebuffer[2] = 0;
2140
streamtmp = PyObject_CallMethod((PyObject *)self->min, "_getStream", NULL);
2141
Py_INCREF(streamtmp);
2142
Py_XDECREF(self->min_stream);
2143
self->min_stream = (Stream *)streamtmp;
2144
self->modebuffer[2] = 1;
2147
(*self->mode_func_ptr)(self);
2154
Between_setMax(Between *self, PyObject *arg)
2156
PyObject *tmp, *streamtmp;
2163
int isNumber = PyNumber_Check(arg);
2167
Py_DECREF(self->max);
2168
if (isNumber == 1) {
2169
self->max = PyNumber_Float(tmp);
2170
self->modebuffer[3] = 0;
2174
streamtmp = PyObject_CallMethod((PyObject *)self->max, "_getStream", NULL);
2175
Py_INCREF(streamtmp);
2176
Py_XDECREF(self->max_stream);
2177
self->max_stream = (Stream *)streamtmp;
2178
self->modebuffer[3] = 1;
2181
(*self->mode_func_ptr)(self);
2187
static PyMemberDef Between_members[] = {
2188
{"server", T_OBJECT_EX, offsetof(Between, server), 0, "Pyo server."},
2189
{"stream", T_OBJECT_EX, offsetof(Between, stream), 0, "Stream object."},
2190
{"input", T_OBJECT_EX, offsetof(Between, input), 0, "Input sound object."},
2191
{"min", T_OBJECT_EX, offsetof(Between, min), 0, "Minimum possible value."},
2192
{"max", T_OBJECT_EX, offsetof(Between, max), 0, "Maximum possible value."},
2193
{"mul", T_OBJECT_EX, offsetof(Between, mul), 0, "Mul factor."},
2194
{"add", T_OBJECT_EX, offsetof(Between, add), 0, "Add factor."},
2195
{NULL} /* Sentinel */
2198
static PyMethodDef Between_methods[] = {
2199
{"getServer", (PyCFunction)Between_getServer, METH_NOARGS, "Returns server object."},
2200
{"_getStream", (PyCFunction)Between_getStream, METH_NOARGS, "Returns stream object."},
2201
{"deleteStream", (PyCFunction)Between_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
2202
{"play", (PyCFunction)Between_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
2203
{"out", (PyCFunction)Between_out, METH_VARARGS|METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
2204
{"stop", (PyCFunction)Between_stop, METH_NOARGS, "Stops computing."},
2205
{"setMin", (PyCFunction)Between_setMin, METH_O, "Sets the minimum value."},
2206
{"setMax", (PyCFunction)Between_setMax, METH_O, "Sets the maximum value."},
2207
{"setMul", (PyCFunction)Between_setMul, METH_O, "Sets oscillator mul factor."},
2208
{"setAdd", (PyCFunction)Between_setAdd, METH_O, "Sets oscillator add factor."},
2209
{"setSub", (PyCFunction)Between_setSub, METH_O, "Sets inverse add factor."},
2210
{"setDiv", (PyCFunction)Between_setDiv, METH_O, "Sets inverse mul factor."},
2211
{NULL} /* Sentinel */
2214
static PyNumberMethods Between_as_number = {
2215
(binaryfunc)Between_add, /*nb_add*/
2216
(binaryfunc)Between_sub, /*nb_subtract*/
2217
(binaryfunc)Between_multiply, /*nb_multiply*/
2218
(binaryfunc)Between_div, /*nb_divide*/
2224
0, /*(unaryfunc)array_abs,*/
2238
(binaryfunc)Between_inplace_add, /*inplace_add*/
2239
(binaryfunc)Between_inplace_sub, /*inplace_subtract*/
2240
(binaryfunc)Between_inplace_multiply, /*inplace_multiply*/
2241
(binaryfunc)Between_inplace_div, /*inplace_divide*/
2242
0, /*inplace_remainder*/
2243
0, /*inplace_power*/
2244
0, /*inplace_lshift*/
2245
0, /*inplace_rshift*/
2249
0, /*nb_floor_divide*/
2250
0, /*nb_true_divide*/
2251
0, /*nb_inplace_floor_divide*/
2252
0, /*nb_inplace_true_divide*/
2256
PyTypeObject BetweenType = {
2257
PyObject_HEAD_INIT(NULL)
2259
"_pyo.Between_base", /*tp_name*/
2260
sizeof(Between), /*tp_basicsize*/
2262
(destructor)Between_dealloc, /*tp_dealloc*/
2268
&Between_as_number, /*tp_as_number*/
2269
0, /*tp_as_sequence*/
2270
0, /*tp_as_mapping*/
2277
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
2278
"Between objects. Outputs a trig if signal is between min and max values.", /* tp_doc */
2279
(traverseproc)Between_traverse, /* tp_traverse */
2280
(inquiry)Between_clear, /* tp_clear */
2281
0, /* tp_richcompare */
2282
0, /* tp_weaklistoffset */
2284
0, /* tp_iternext */
2285
Between_methods, /* tp_methods */
2286
Between_members, /* tp_members */
2290
0, /* tp_descr_get */
2291
0, /* tp_descr_set */
2292
0, /* tp_dictoffset */
2293
(initproc)Between_init, /* tp_init */
2295
Between_new, /* tp_new */
2303
#define DENORM_RAND ((MYFLT) ((rand()/((MYFLT)(RAND_MAX)*0.5+1) - 1.0) * (MYFLT)(1.0e-24)))
2305
#define DENORM_RAND ((MYFLT) ((rand()/((MYFLT)(RAND_MAX)*0.5+1) - 1.0) * (MYFLT)(1.0e-60)))
2311
Stream *input_stream;
2312
int modebuffer[2]; // need at least 2 slots for mul & add
2316
Denorm_filters(Denorm *self) {
2318
MYFLT *in = Stream_getData((Stream *)self->input_stream);
2320
for (i=0; i<self->bufsize; i++) {
2321
self->data[i] = in[i] + DENORM_RAND;
2325
static void Denorm_postprocessing_ii(Denorm *self) { POST_PROCESSING_II };
2326
static void Denorm_postprocessing_ai(Denorm *self) { POST_PROCESSING_AI };
2327
static void Denorm_postprocessing_ia(Denorm *self) { POST_PROCESSING_IA };
2328
static void Denorm_postprocessing_aa(Denorm *self) { POST_PROCESSING_AA };
2329
static void Denorm_postprocessing_ireva(Denorm *self) { POST_PROCESSING_IREVA };
2330
static void Denorm_postprocessing_areva(Denorm *self) { POST_PROCESSING_AREVA };
2331
static void Denorm_postprocessing_revai(Denorm *self) { POST_PROCESSING_REVAI };
2332
static void Denorm_postprocessing_revaa(Denorm *self) { POST_PROCESSING_REVAA };
2333
static void Denorm_postprocessing_revareva(Denorm *self) { POST_PROCESSING_REVAREVA };
2336
Denorm_setProcMode(Denorm *self)
2339
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
2341
self->proc_func_ptr = Denorm_filters;
2343
switch (muladdmode) {
2345
self->muladd_func_ptr = Denorm_postprocessing_ii;
2348
self->muladd_func_ptr = Denorm_postprocessing_ai;
2351
self->muladd_func_ptr = Denorm_postprocessing_revai;
2354
self->muladd_func_ptr = Denorm_postprocessing_ia;
2357
self->muladd_func_ptr = Denorm_postprocessing_aa;
2360
self->muladd_func_ptr = Denorm_postprocessing_revaa;
2363
self->muladd_func_ptr = Denorm_postprocessing_ireva;
2366
self->muladd_func_ptr = Denorm_postprocessing_areva;
2369
self->muladd_func_ptr = Denorm_postprocessing_revareva;
2375
Denorm_compute_next_data_frame(Denorm *self)
2377
(*self->proc_func_ptr)(self);
2378
(*self->muladd_func_ptr)(self);
2382
Denorm_traverse(Denorm *self, visitproc visit, void *arg)
2385
Py_VISIT(self->input);
2386
Py_VISIT(self->input_stream);
2391
Denorm_clear(Denorm *self)
2394
Py_CLEAR(self->input);
2395
Py_CLEAR(self->input_stream);
2400
Denorm_dealloc(Denorm* self)
2404
self->ob_type->tp_free((PyObject*)self);
2407
static PyObject * Denorm_deleteStream(Denorm *self) { DELETE_STREAM };
2410
Denorm_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2414
self = (Denorm *)type->tp_alloc(type, 0);
2416
self->modebuffer[0] = 0;
2417
self->modebuffer[1] = 0;
2420
Stream_setFunctionPtr(self->stream, Denorm_compute_next_data_frame);
2421
self->mode_func_ptr = Denorm_setProcMode;
2422
return (PyObject *)self;
2426
Denorm_init(Denorm *self, PyObject *args, PyObject *kwds)
2428
PyObject *inputtmp, *input_streamtmp, *multmp=NULL, *addtmp=NULL;
2430
static char *kwlist[] = {"input", "mul", "add", NULL};
2432
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
2438
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
2442
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
2445
Py_INCREF(self->stream);
2446
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
2448
Server_generateSeed((Server *)self->server, DENORM_ID);
2450
(*self->mode_func_ptr)(self);
2456
static PyObject * Denorm_getServer(Denorm* self) { GET_SERVER };
2457
static PyObject * Denorm_getStream(Denorm* self) { GET_STREAM };
2458
static PyObject * Denorm_setMul(Denorm *self, PyObject *arg) { SET_MUL };
2459
static PyObject * Denorm_setAdd(Denorm *self, PyObject *arg) { SET_ADD };
2460
static PyObject * Denorm_setSub(Denorm *self, PyObject *arg) { SET_SUB };
2461
static PyObject * Denorm_setDiv(Denorm *self, PyObject *arg) { SET_DIV };
2463
static PyObject * Denorm_play(Denorm *self, PyObject *args, PyObject *kwds) { PLAY };
2464
static PyObject * Denorm_out(Denorm *self, PyObject *args, PyObject *kwds) { OUT };
2465
static PyObject * Denorm_stop(Denorm *self) { STOP };
2467
static PyObject * Denorm_multiply(Denorm *self, PyObject *arg) { MULTIPLY };
2468
static PyObject * Denorm_inplace_multiply(Denorm *self, PyObject *arg) { INPLACE_MULTIPLY };
2469
static PyObject * Denorm_add(Denorm *self, PyObject *arg) { ADD };
2470
static PyObject * Denorm_inplace_add(Denorm *self, PyObject *arg) { INPLACE_ADD };
2471
static PyObject * Denorm_sub(Denorm *self, PyObject *arg) { SUB };
2472
static PyObject * Denorm_inplace_sub(Denorm *self, PyObject *arg) { INPLACE_SUB };
2473
static PyObject * Denorm_div(Denorm *self, PyObject *arg) { DIV };
2474
static PyObject * Denorm_inplace_div(Denorm *self, PyObject *arg) { INPLACE_DIV };
2476
static PyMemberDef Denorm_members[] = {
2477
{"server", T_OBJECT_EX, offsetof(Denorm, server), 0, "Pyo server."},
2478
{"stream", T_OBJECT_EX, offsetof(Denorm, stream), 0, "Stream object."},
2479
{"input", T_OBJECT_EX, offsetof(Denorm, input), 0, "Input sound object."},
2480
{"mul", T_OBJECT_EX, offsetof(Denorm, mul), 0, "Mul factor."},
2481
{"add", T_OBJECT_EX, offsetof(Denorm, add), 0, "Add factor."},
2482
{NULL} /* Sentinel */
2485
static PyMethodDef Denorm_methods[] = {
2486
{"getServer", (PyCFunction)Denorm_getServer, METH_NOARGS, "Returns server object."},
2487
{"_getStream", (PyCFunction)Denorm_getStream, METH_NOARGS, "Returns stream object."},
2488
{"deleteStream", (PyCFunction)Denorm_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
2489
{"play", (PyCFunction)Denorm_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
2490
{"out", (PyCFunction)Denorm_out, METH_VARARGS|METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
2491
{"stop", (PyCFunction)Denorm_stop, METH_NOARGS, "Stops computing."},
2492
{"setMul", (PyCFunction)Denorm_setMul, METH_O, "Sets oscillator mul factor."},
2493
{"setAdd", (PyCFunction)Denorm_setAdd, METH_O, "Sets oscillator add factor."},
2494
{"setSub", (PyCFunction)Denorm_setSub, METH_O, "Sets inverse add factor."},
2495
{"setDiv", (PyCFunction)Denorm_setDiv, METH_O, "Sets inverse mul factor."},
2496
{NULL} /* Sentinel */
2499
static PyNumberMethods Denorm_as_number = {
2500
(binaryfunc)Denorm_add, /*nb_add*/
2501
(binaryfunc)Denorm_sub, /*nb_subtract*/
2502
(binaryfunc)Denorm_multiply, /*nb_multiply*/
2503
(binaryfunc)Denorm_div, /*nb_divide*/
2509
0, /*(unaryfunc)array_abs,*/
2523
(binaryfunc)Denorm_inplace_add, /*inplace_add*/
2524
(binaryfunc)Denorm_inplace_sub, /*inplace_subtract*/
2525
(binaryfunc)Denorm_inplace_multiply, /*inplace_multiply*/
2526
(binaryfunc)Denorm_inplace_div, /*inplace_divide*/
2527
0, /*inplace_remainder*/
2528
0, /*inplace_power*/
2529
0, /*inplace_lshift*/
2530
0, /*inplace_rshift*/
2534
0, /*nb_floor_divide*/
2535
0, /*nb_true_divide*/
2536
0, /*nb_inplace_floor_divide*/
2537
0, /*nb_inplace_true_divide*/
2541
PyTypeObject DenormType = {
2542
PyObject_HEAD_INIT(NULL)
2544
"_pyo.Denorm_base", /*tp_name*/
2545
sizeof(Denorm), /*tp_basicsize*/
2547
(destructor)Denorm_dealloc, /*tp_dealloc*/
2553
&Denorm_as_number, /*tp_as_number*/
2554
0, /*tp_as_sequence*/
2555
0, /*tp_as_mapping*/
2562
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
2563
"Denorm objects. Mixes low level noise to an input signal.", /* tp_doc */
2564
(traverseproc)Denorm_traverse, /* tp_traverse */
2565
(inquiry)Denorm_clear, /* tp_clear */
2566
0, /* tp_richcompare */
2567
0, /* tp_weaklistoffset */
2569
0, /* tp_iternext */
2570
Denorm_methods, /* tp_methods */
2571
Denorm_members, /* tp_members */
2575
0, /* tp_descr_get */
2576
0, /* tp_descr_set */
2577
0, /* tp_dictoffset */
2578
(initproc)Denorm_init, /* tp_init */
2580
Denorm_new, /* tp_new */
2589
Stream *input_stream;
2592
int modebuffer[2]; // need at least 2 slots for mul & add
2596
DBToA_process(DBToA *self) {
2599
MYFLT *in = Stream_getData((Stream *)self->input_stream);
2601
for (i=0; i<self->bufsize; i++) {
2604
self->data[i] = self->currentamp = 0.0;
2605
self->lastdb = -120.0;
2607
else if (db != self->lastdb) {
2608
self->data[i] = self->currentamp = MYPOW(10.0, db * 0.05);
2612
self->data[i] = self->currentamp;
2616
static void DBToA_postprocessing_ii(DBToA *self) { POST_PROCESSING_II };
2617
static void DBToA_postprocessing_ai(DBToA *self) { POST_PROCESSING_AI };
2618
static void DBToA_postprocessing_ia(DBToA *self) { POST_PROCESSING_IA };
2619
static void DBToA_postprocessing_aa(DBToA *self) { POST_PROCESSING_AA };
2620
static void DBToA_postprocessing_ireva(DBToA *self) { POST_PROCESSING_IREVA };
2621
static void DBToA_postprocessing_areva(DBToA *self) { POST_PROCESSING_AREVA };
2622
static void DBToA_postprocessing_revai(DBToA *self) { POST_PROCESSING_REVAI };
2623
static void DBToA_postprocessing_revaa(DBToA *self) { POST_PROCESSING_REVAA };
2624
static void DBToA_postprocessing_revareva(DBToA *self) { POST_PROCESSING_REVAREVA };
2627
DBToA_setProcMode(DBToA *self)
2630
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
2632
self->proc_func_ptr = DBToA_process;
2634
switch (muladdmode) {
2636
self->muladd_func_ptr = DBToA_postprocessing_ii;
2639
self->muladd_func_ptr = DBToA_postprocessing_ai;
2642
self->muladd_func_ptr = DBToA_postprocessing_revai;
2645
self->muladd_func_ptr = DBToA_postprocessing_ia;
2648
self->muladd_func_ptr = DBToA_postprocessing_aa;
2651
self->muladd_func_ptr = DBToA_postprocessing_revaa;
2654
self->muladd_func_ptr = DBToA_postprocessing_ireva;
2657
self->muladd_func_ptr = DBToA_postprocessing_areva;
2660
self->muladd_func_ptr = DBToA_postprocessing_revareva;
2666
DBToA_compute_next_data_frame(DBToA *self)
2668
(*self->proc_func_ptr)(self);
2669
(*self->muladd_func_ptr)(self);
2673
DBToA_traverse(DBToA *self, visitproc visit, void *arg)
2676
Py_VISIT(self->input);
2677
Py_VISIT(self->input_stream);
2682
DBToA_clear(DBToA *self)
2685
Py_CLEAR(self->input);
2686
Py_CLEAR(self->input_stream);
2691
DBToA_dealloc(DBToA* self)
2695
self->ob_type->tp_free((PyObject*)self);
2698
static PyObject * DBToA_deleteStream(DBToA *self) { DELETE_STREAM };
2701
DBToA_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2705
self = (DBToA *)type->tp_alloc(type, 0);
2707
self->lastdb = -120.0;
2708
self->currentamp = MYPOW(10.0, self->lastdb * 0.05);
2709
self->modebuffer[0] = 0;
2710
self->modebuffer[1] = 0;
2713
Stream_setFunctionPtr(self->stream, DBToA_compute_next_data_frame);
2714
self->mode_func_ptr = DBToA_setProcMode;
2715
return (PyObject *)self;
2719
DBToA_init(DBToA *self, PyObject *args, PyObject *kwds)
2721
PyObject *inputtmp, *input_streamtmp, *multmp=NULL, *addtmp=NULL;
2723
static char *kwlist[] = {"input", "mul", "add", NULL};
2725
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
2731
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
2735
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
2738
Py_INCREF(self->stream);
2739
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
2741
(*self->mode_func_ptr)(self);
2748
static PyObject * DBToA_getServer(DBToA* self) { GET_SERVER };
2749
static PyObject * DBToA_getStream(DBToA* self) { GET_STREAM };
2750
static PyObject * DBToA_setMul(DBToA *self, PyObject *arg) { SET_MUL };
2751
static PyObject * DBToA_setAdd(DBToA *self, PyObject *arg) { SET_ADD };
2752
static PyObject * DBToA_setSub(DBToA *self, PyObject *arg) { SET_SUB };
2753
static PyObject * DBToA_setDiv(DBToA *self, PyObject *arg) { SET_DIV };
2755
static PyObject * DBToA_play(DBToA *self, PyObject *args, PyObject *kwds) { PLAY };
2756
static PyObject * DBToA_out(DBToA *self, PyObject *args, PyObject *kwds) { OUT };
2757
static PyObject * DBToA_stop(DBToA *self) { STOP };
2759
static PyObject * DBToA_multiply(DBToA *self, PyObject *arg) { MULTIPLY };
2760
static PyObject * DBToA_inplace_multiply(DBToA *self, PyObject *arg) { INPLACE_MULTIPLY };
2761
static PyObject * DBToA_add(DBToA *self, PyObject *arg) { ADD };
2762
static PyObject * DBToA_inplace_add(DBToA *self, PyObject *arg) { INPLACE_ADD };
2763
static PyObject * DBToA_sub(DBToA *self, PyObject *arg) { SUB };
2764
static PyObject * DBToA_inplace_sub(DBToA *self, PyObject *arg) { INPLACE_SUB };
2765
static PyObject * DBToA_div(DBToA *self, PyObject *arg) { DIV };
2766
static PyObject * DBToA_inplace_div(DBToA *self, PyObject *arg) { INPLACE_DIV };
2768
static PyMemberDef DBToA_members[] = {
2769
{"server", T_OBJECT_EX, offsetof(DBToA, server), 0, "Pyo server."},
2770
{"stream", T_OBJECT_EX, offsetof(DBToA, stream), 0, "Stream object."},
2771
{"input", T_OBJECT_EX, offsetof(DBToA, input), 0, "Input sound object."},
2772
{"mul", T_OBJECT_EX, offsetof(DBToA, mul), 0, "Mul factor."},
2773
{"add", T_OBJECT_EX, offsetof(DBToA, add), 0, "Add factor."},
2774
{NULL} /* Sentinel */
2777
static PyMethodDef DBToA_methods[] = {
2778
{"getServer", (PyCFunction)DBToA_getServer, METH_NOARGS, "Returns server object."},
2779
{"_getStream", (PyCFunction)DBToA_getStream, METH_NOARGS, "Returns stream object."},
2780
{"deleteStream", (PyCFunction)DBToA_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
2781
{"play", (PyCFunction)DBToA_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
2782
{"stop", (PyCFunction)DBToA_stop, METH_NOARGS, "Stops computing."},
2783
{"out", (PyCFunction)DBToA_out, METH_VARARGS|METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
2784
{"setMul", (PyCFunction)DBToA_setMul, METH_O, "Sets oscillator mul factor."},
2785
{"setAdd", (PyCFunction)DBToA_setAdd, METH_O, "Sets oscillator add factor."},
2786
{"setSub", (PyCFunction)DBToA_setSub, METH_O, "Sets inverse add factor."},
2787
{"setDiv", (PyCFunction)DBToA_setDiv, METH_O, "Sets inverse mul factor."},
2788
{NULL} /* Sentinel */
2791
static PyNumberMethods DBToA_as_number = {
2792
(binaryfunc)DBToA_add, /*nb_add*/
2793
(binaryfunc)DBToA_sub, /*nb_subtract*/
2794
(binaryfunc)DBToA_multiply, /*nb_multiply*/
2795
(binaryfunc)DBToA_div, /*nb_divide*/
2801
0, /*(unaryfunc)array_abs,*/
2815
(binaryfunc)DBToA_inplace_add, /*inplace_add*/
2816
(binaryfunc)DBToA_inplace_sub, /*inplace_subtract*/
2817
(binaryfunc)DBToA_inplace_multiply, /*inplace_multiply*/
2818
(binaryfunc)DBToA_inplace_div, /*inplace_divide*/
2819
0, /*inplace_remainder*/
2820
0, /*inplace_power*/
2821
0, /*inplace_lshift*/
2822
0, /*inplace_rshift*/
2826
0, /*nb_floor_divide*/
2827
0, /*nb_true_divide*/
2828
0, /*nb_inplace_floor_divide*/
2829
0, /*nb_inplace_true_divide*/
2833
PyTypeObject DBToAType = {
2834
PyObject_HEAD_INIT(NULL)
2836
"_pyo.DBToA_base", /*tp_name*/
2837
sizeof(DBToA), /*tp_basicsize*/
2839
(destructor)DBToA_dealloc, /*tp_dealloc*/
2845
&DBToA_as_number, /*tp_as_number*/
2846
0, /*tp_as_sequence*/
2847
0, /*tp_as_mapping*/
2854
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
2855
"DBToA objects. Converts dB value to amplitude value.", /* tp_doc */
2856
(traverseproc)DBToA_traverse, /* tp_traverse */
2857
(inquiry)DBToA_clear, /* tp_clear */
2858
0, /* tp_richcompare */
2859
0, /* tp_weaklistoffset */
2861
0, /* tp_iternext */
2862
DBToA_methods, /* tp_methods */
2863
DBToA_members, /* tp_members */
2867
0, /* tp_descr_get */
2868
0, /* tp_descr_set */
2869
0, /* tp_dictoffset */
2870
(initproc)DBToA_init, /* tp_init */
2872
DBToA_new, /* tp_new */
2881
Stream *input_stream;
2884
int modebuffer[2]; // need at least 2 slots for mul & add
2888
AToDB_process(AToDB *self) {
2891
MYFLT *in = Stream_getData((Stream *)self->input_stream);
2893
for (i=0; i<self->bufsize; i++) {
2895
if (amp <= 0.000001) {
2896
self->data[i] = self->currentdb = -120.0;
2897
self->lastamp = 0.000001;
2899
else if (amp != self->lastamp) {
2900
self->data[i] = self->currentdb = 20.0 * MYLOG10(amp);
2901
self->lastamp = amp;
2904
self->data[i] = self->currentdb;
2908
static void AToDB_postprocessing_ii(AToDB *self) { POST_PROCESSING_II };
2909
static void AToDB_postprocessing_ai(AToDB *self) { POST_PROCESSING_AI };
2910
static void AToDB_postprocessing_ia(AToDB *self) { POST_PROCESSING_IA };
2911
static void AToDB_postprocessing_aa(AToDB *self) { POST_PROCESSING_AA };
2912
static void AToDB_postprocessing_ireva(AToDB *self) { POST_PROCESSING_IREVA };
2913
static void AToDB_postprocessing_areva(AToDB *self) { POST_PROCESSING_AREVA };
2914
static void AToDB_postprocessing_revai(AToDB *self) { POST_PROCESSING_REVAI };
2915
static void AToDB_postprocessing_revaa(AToDB *self) { POST_PROCESSING_REVAA };
2916
static void AToDB_postprocessing_revareva(AToDB *self) { POST_PROCESSING_REVAREVA };
2919
AToDB_setProcMode(AToDB *self)
2922
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
2924
self->proc_func_ptr = AToDB_process;
2926
switch (muladdmode) {
2928
self->muladd_func_ptr = AToDB_postprocessing_ii;
2931
self->muladd_func_ptr = AToDB_postprocessing_ai;
2934
self->muladd_func_ptr = AToDB_postprocessing_revai;
2937
self->muladd_func_ptr = AToDB_postprocessing_ia;
2940
self->muladd_func_ptr = AToDB_postprocessing_aa;
2943
self->muladd_func_ptr = AToDB_postprocessing_revaa;
2946
self->muladd_func_ptr = AToDB_postprocessing_ireva;
2949
self->muladd_func_ptr = AToDB_postprocessing_areva;
2952
self->muladd_func_ptr = AToDB_postprocessing_revareva;
2958
AToDB_compute_next_data_frame(AToDB *self)
2960
(*self->proc_func_ptr)(self);
2961
(*self->muladd_func_ptr)(self);
2965
AToDB_traverse(AToDB *self, visitproc visit, void *arg)
2968
Py_VISIT(self->input);
2969
Py_VISIT(self->input_stream);
2974
AToDB_clear(AToDB *self)
2977
Py_CLEAR(self->input);
2978
Py_CLEAR(self->input_stream);
2983
AToDB_dealloc(AToDB* self)
2987
self->ob_type->tp_free((PyObject*)self);
2990
static PyObject * AToDB_deleteStream(AToDB *self) { DELETE_STREAM };
2993
AToDB_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2997
self = (AToDB *)type->tp_alloc(type, 0);
2999
self->lastamp = 0.000001;
3000
self->currentdb = 20.0 * MYLOG10(self->lastamp);
3001
self->modebuffer[0] = 0;
3002
self->modebuffer[1] = 0;
3005
Stream_setFunctionPtr(self->stream, AToDB_compute_next_data_frame);
3006
self->mode_func_ptr = AToDB_setProcMode;
3007
return (PyObject *)self;
3011
AToDB_init(AToDB *self, PyObject *args, PyObject *kwds)
3013
PyObject *inputtmp, *input_streamtmp, *multmp=NULL, *addtmp=NULL;
3015
static char *kwlist[] = {"input", "mul", "add", NULL};
3017
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
3023
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
3027
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
3030
Py_INCREF(self->stream);
3031
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
3033
(*self->mode_func_ptr)(self);
3040
static PyObject * AToDB_getServer(AToDB* self) { GET_SERVER };
3041
static PyObject * AToDB_getStream(AToDB* self) { GET_STREAM };
3042
static PyObject * AToDB_setMul(AToDB *self, PyObject *arg) { SET_MUL };
3043
static PyObject * AToDB_setAdd(AToDB *self, PyObject *arg) { SET_ADD };
3044
static PyObject * AToDB_setSub(AToDB *self, PyObject *arg) { SET_SUB };
3045
static PyObject * AToDB_setDiv(AToDB *self, PyObject *arg) { SET_DIV };
3047
static PyObject * AToDB_play(AToDB *self, PyObject *args, PyObject *kwds) { PLAY };
3048
static PyObject * AToDB_out(AToDB *self, PyObject *args, PyObject *kwds) { OUT };
3049
static PyObject * AToDB_stop(AToDB *self) { STOP };
3051
static PyObject * AToDB_multiply(AToDB *self, PyObject *arg) { MULTIPLY };
3052
static PyObject * AToDB_inplace_multiply(AToDB *self, PyObject *arg) { INPLACE_MULTIPLY };
3053
static PyObject * AToDB_add(AToDB *self, PyObject *arg) { ADD };
3054
static PyObject * AToDB_inplace_add(AToDB *self, PyObject *arg) { INPLACE_ADD };
3055
static PyObject * AToDB_sub(AToDB *self, PyObject *arg) { SUB };
3056
static PyObject * AToDB_inplace_sub(AToDB *self, PyObject *arg) { INPLACE_SUB };
3057
static PyObject * AToDB_div(AToDB *self, PyObject *arg) { DIV };
3058
static PyObject * AToDB_inplace_div(AToDB *self, PyObject *arg) { INPLACE_DIV };
3060
static PyMemberDef AToDB_members[] = {
3061
{"server", T_OBJECT_EX, offsetof(AToDB, server), 0, "Pyo server."},
3062
{"stream", T_OBJECT_EX, offsetof(AToDB, stream), 0, "Stream object."},
3063
{"input", T_OBJECT_EX, offsetof(AToDB, input), 0, "Input sound object."},
3064
{"mul", T_OBJECT_EX, offsetof(AToDB, mul), 0, "Mul factor."},
3065
{"add", T_OBJECT_EX, offsetof(AToDB, add), 0, "Add factor."},
3066
{NULL} /* Sentinel */
3069
static PyMethodDef AToDB_methods[] = {
3070
{"getServer", (PyCFunction)AToDB_getServer, METH_NOARGS, "Returns server object."},
3071
{"_getStream", (PyCFunction)AToDB_getStream, METH_NOARGS, "Returns stream object."},
3072
{"deleteStream", (PyCFunction)AToDB_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
3073
{"play", (PyCFunction)AToDB_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
3074
{"stop", (PyCFunction)AToDB_stop, METH_NOARGS, "Stops computing."},
3075
{"out", (PyCFunction)AToDB_out, METH_VARARGS|METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
3076
{"setMul", (PyCFunction)AToDB_setMul, METH_O, "Sets oscillator mul factor."},
3077
{"setAdd", (PyCFunction)AToDB_setAdd, METH_O, "Sets oscillator add factor."},
3078
{"setSub", (PyCFunction)AToDB_setSub, METH_O, "Sets inverse add factor."},
3079
{"setDiv", (PyCFunction)AToDB_setDiv, METH_O, "Sets inverse mul factor."},
3080
{NULL} /* Sentinel */
3083
static PyNumberMethods AToDB_as_number = {
3084
(binaryfunc)AToDB_add, /*nb_add*/
3085
(binaryfunc)AToDB_sub, /*nb_subtract*/
3086
(binaryfunc)AToDB_multiply, /*nb_multiply*/
3087
(binaryfunc)AToDB_div, /*nb_divide*/
3093
0, /*(unaryfunc)array_abs,*/
3107
(binaryfunc)AToDB_inplace_add, /*inplace_add*/
3108
(binaryfunc)AToDB_inplace_sub, /*inplace_subtract*/
3109
(binaryfunc)AToDB_inplace_multiply, /*inplace_multiply*/
3110
(binaryfunc)AToDB_inplace_div, /*inplace_divide*/
3111
0, /*inplace_remainder*/
3112
0, /*inplace_power*/
3113
0, /*inplace_lshift*/
3114
0, /*inplace_rshift*/
3118
0, /*nb_floor_divide*/
3119
0, /*nb_true_divide*/
3120
0, /*nb_inplace_floor_divide*/
3121
0, /*nb_inplace_true_divide*/
3125
PyTypeObject AToDBType = {
3126
PyObject_HEAD_INIT(NULL)
3128
"_pyo.AToDB_base", /*tp_name*/
3129
sizeof(AToDB), /*tp_basicsize*/
3131
(destructor)AToDB_dealloc, /*tp_dealloc*/
3137
&AToDB_as_number, /*tp_as_number*/
3138
0, /*tp_as_sequence*/
3139
0, /*tp_as_mapping*/
3146
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
3147
"AToDB objects. Converts dB value to amplitude value.", /* tp_doc */
3148
(traverseproc)AToDB_traverse, /* tp_traverse */
3149
(inquiry)AToDB_clear, /* tp_clear */
3150
0, /* tp_richcompare */
3151
0, /* tp_weaklistoffset */
3153
0, /* tp_iternext */
3154
AToDB_methods, /* tp_methods */
3155
AToDB_members, /* tp_members */
3159
0, /* tp_descr_get */
3160
0, /* tp_descr_set */
3161
0, /* tp_dictoffset */
3162
(initproc)AToDB_init, /* tp_init */
3164
AToDB_new, /* tp_new */
3167
/*********************************************************************************************/
3168
/* Scale ********************************************************************************/
3169
/*********************************************************************************************/
3173
Stream *input_stream;
3175
Stream *inmin_stream;
3177
Stream *inmax_stream;
3179
Stream *outmin_stream;
3181
Stream *outmax_stream;
3184
int modebuffer[7]; // need at least 2 slots for mul & add
3188
_scale_clip(MYFLT x, MYFLT min, MYFLT max) {
3198
Scale_generate(Scale *self) {
3199
int i, inrev, outrev;
3200
MYFLT tmp, inrange, outrange, normin;
3201
MYFLT inmin, inmax, outmin, outmax, exp;
3202
MYFLT *in = Stream_getData((Stream *)self->input_stream);
3204
if (self->modebuffer[2] == 0)
3205
inmin = PyFloat_AS_DOUBLE(self->inmin);
3207
inmin = Stream_getData((Stream *)self->inmin_stream)[0];
3208
if (self->modebuffer[3] == 0)
3209
inmax = PyFloat_AS_DOUBLE(self->inmax);
3211
inmax = Stream_getData((Stream *)self->inmax_stream)[0];
3213
if (inmin < inmax) {
3222
inrange = inmax - inmin;
3224
if (self->modebuffer[4] == 0)
3225
outmin = PyFloat_AS_DOUBLE(self->outmin);
3227
outmin = Stream_getData((Stream *)self->outmin_stream)[0];
3228
if (self->modebuffer[5] == 0)
3229
outmax = PyFloat_AS_DOUBLE(self->outmax);
3231
outmax = Stream_getData((Stream *)self->outmax_stream)[0];
3233
if (outmin < outmax) {
3242
outrange = outmax - outmin;
3244
if (self->modebuffer[6] == 0)
3245
exp = PyFloat_AS_DOUBLE(self->exp);
3247
exp = Stream_getData((Stream *)self->exp_stream)[0];
3251
/* Handle case where input or output range equal 0 */
3252
if (inrange == 0.0 || outrange == 0.0) {
3253
for (i=0; i<self->bufsize; i++) {
3254
self->data[i] = outmin;
3257
/* Linear scaling */
3258
else if (exp == 1.0) {
3259
if (inrev == 0 && outrev == 0) {
3260
for (i=0; i<self->bufsize; i++) {
3261
normin = (_scale_clip(in[i], inmin, inmax) - inmin) / inrange;
3262
self->data[i] = normin * outrange + outmin;
3265
else if (inrev == 1 && outrev == 0) {
3266
for (i=0; i<self->bufsize; i++) {
3267
normin = 1.0 - ((_scale_clip(in[i], inmin, inmax) - inmin) / inrange);
3268
self->data[i] = normin * outrange + outmin;
3271
else if (inrev == 0 && outrev == 1) {
3272
for (i=0; i<self->bufsize; i++) {
3273
normin = (_scale_clip(in[i], inmin, inmax) - inmin) / inrange;
3274
self->data[i] = outmax - (normin * outrange);
3277
else if (inrev == 1 && outrev == 1) {
3278
for (i=0; i<self->bufsize; i++) {
3279
normin = 1.0 - ((_scale_clip(in[i], inmin, inmax) - inmin) / inrange);
3280
self->data[i] = outmax - (normin * outrange);
3284
/* Exponential scaling */
3286
if (inrev == 0 && outrev == 0) {
3287
for (i=0; i<self->bufsize; i++) {
3288
normin = MYPOW((_scale_clip(in[i], inmin, inmax) - inmin) / inrange, exp);
3289
self->data[i] = normin * outrange + outmin;
3292
else if (inrev == 1 && outrev == 0) {
3293
for (i=0; i<self->bufsize; i++) {
3294
normin = MYPOW(1.0 - ((_scale_clip(in[i], inmin, inmax) - inmin) / inrange), exp);
3295
self->data[i] = normin * outrange + outmin;
3298
else if (inrev == 0 && outrev == 1) {
3299
for (i=0; i<self->bufsize; i++) {
3300
normin = MYPOW((_scale_clip(in[i], inmin, inmax) - inmin) / inrange, exp);
3301
self->data[i] = outmax - (normin * outrange);
3304
else if (inrev == 1 && outrev == 1) {
3305
for (i=0; i<self->bufsize; i++) {
3306
normin = MYPOW(1.0 - ((_scale_clip(in[i], inmin, inmax) - inmin) / inrange), exp);
3307
self->data[i] = outmax - (normin * outrange);
3313
static void Scale_postprocessing_ii(Scale *self) { POST_PROCESSING_II };
3314
static void Scale_postprocessing_ai(Scale *self) { POST_PROCESSING_AI };
3315
static void Scale_postprocessing_ia(Scale *self) { POST_PROCESSING_IA };
3316
static void Scale_postprocessing_aa(Scale *self) { POST_PROCESSING_AA };
3317
static void Scale_postprocessing_ireva(Scale *self) { POST_PROCESSING_IREVA };
3318
static void Scale_postprocessing_areva(Scale *self) { POST_PROCESSING_AREVA };
3319
static void Scale_postprocessing_revai(Scale *self) { POST_PROCESSING_REVAI };
3320
static void Scale_postprocessing_revaa(Scale *self) { POST_PROCESSING_REVAA };
3321
static void Scale_postprocessing_revareva(Scale *self) { POST_PROCESSING_REVAREVA };
3324
Scale_setProcMode(Scale *self)
3327
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
3329
self->proc_func_ptr = Scale_generate;
3331
switch (muladdmode) {
3333
self->muladd_func_ptr = Scale_postprocessing_ii;
3336
self->muladd_func_ptr = Scale_postprocessing_ai;
3339
self->muladd_func_ptr = Scale_postprocessing_revai;
3342
self->muladd_func_ptr = Scale_postprocessing_ia;
3345
self->muladd_func_ptr = Scale_postprocessing_aa;
3348
self->muladd_func_ptr = Scale_postprocessing_revaa;
3351
self->muladd_func_ptr = Scale_postprocessing_ireva;
3354
self->muladd_func_ptr = Scale_postprocessing_areva;
3357
self->muladd_func_ptr = Scale_postprocessing_revareva;
3363
Scale_compute_next_data_frame(Scale *self)
3365
(*self->proc_func_ptr)(self);
3366
(*self->muladd_func_ptr)(self);
3370
Scale_traverse(Scale *self, visitproc visit, void *arg)
3373
Py_VISIT(self->input);
3374
Py_VISIT(self->input_stream);
3375
Py_VISIT(self->inmin);
3376
Py_VISIT(self->inmin_stream);
3377
Py_VISIT(self->inmax);
3378
Py_VISIT(self->inmax_stream);
3379
Py_VISIT(self->outmin);
3380
Py_VISIT(self->outmin_stream);
3381
Py_VISIT(self->outmax);
3382
Py_VISIT(self->outmax_stream);
3383
Py_VISIT(self->exp);
3384
Py_VISIT(self->exp_stream);
3389
Scale_clear(Scale *self)
3392
Py_CLEAR(self->input);
3393
Py_CLEAR(self->input_stream);
3394
Py_CLEAR(self->inmin);
3395
Py_CLEAR(self->inmin_stream);
3396
Py_CLEAR(self->inmax);
3397
Py_CLEAR(self->inmax_stream);
3398
Py_CLEAR(self->outmin);
3399
Py_CLEAR(self->outmin_stream);
3400
Py_CLEAR(self->outmax);
3401
Py_CLEAR(self->outmax_stream);
3402
Py_CLEAR(self->exp);
3403
Py_CLEAR(self->exp_stream);
3408
Scale_dealloc(Scale* self)
3412
self->ob_type->tp_free((PyObject*)self);
3415
static PyObject * Scale_deleteStream(Scale *self) { DELETE_STREAM };
3418
Scale_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
3422
self = (Scale *)type->tp_alloc(type, 0);
3424
self->inmin = PyFloat_FromDouble(0.0);
3425
self->inmax = PyFloat_FromDouble(1.0);
3426
self->outmin = PyFloat_FromDouble(0.0);
3427
self->outmax = PyFloat_FromDouble(1.0);
3428
self->exp = PyFloat_FromDouble(1.0);
3429
self->modebuffer[0] = 0;
3430
self->modebuffer[1] = 0;
3431
self->modebuffer[2] = 0;
3432
self->modebuffer[3] = 0;
3433
self->modebuffer[4] = 0;
3434
self->modebuffer[5] = 0;
3435
self->modebuffer[6] = 0;
3438
Stream_setFunctionPtr(self->stream, Scale_compute_next_data_frame);
3439
self->mode_func_ptr = Scale_setProcMode;
3440
return (PyObject *)self;
3444
Scale_init(Scale *self, PyObject *args, PyObject *kwds)
3446
PyObject *inputtmp, *input_streamtmp, *inmintmp=NULL, *inmaxtmp=NULL, *outmintmp=NULL, *outmaxtmp=NULL, *exptmp=NULL, *multmp=NULL, *addtmp=NULL;
3448
static char *kwlist[] = {"input", "inmin", "inmax", "outmin", "outmax", "exp", "mul", "add", NULL};
3450
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OOOOOOO", kwlist, &inputtmp, &inmintmp, &inmaxtmp, &outmintmp, &outmaxtmp, &exptmp, &multmp, &addtmp))
3456
PyObject_CallMethod((PyObject *)self, "setInMin", "O", inmintmp);
3460
PyObject_CallMethod((PyObject *)self, "setInMax", "O", inmaxtmp);
3464
PyObject_CallMethod((PyObject *)self, "setOutMin", "O", outmintmp);
3468
PyObject_CallMethod((PyObject *)self, "setOutMax", "O", outmaxtmp);
3472
PyObject_CallMethod((PyObject *)self, "setExp", "O", exptmp);
3476
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
3480
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
3483
Py_INCREF(self->stream);
3484
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
3486
(*self->mode_func_ptr)(self);
3492
static PyObject * Scale_getServer(Scale* self) { GET_SERVER };
3493
static PyObject * Scale_getStream(Scale* self) { GET_STREAM };
3494
static PyObject * Scale_setMul(Scale *self, PyObject *arg) { SET_MUL };
3495
static PyObject * Scale_setAdd(Scale *self, PyObject *arg) { SET_ADD };
3496
static PyObject * Scale_setSub(Scale *self, PyObject *arg) { SET_SUB };
3497
static PyObject * Scale_setDiv(Scale *self, PyObject *arg) { SET_DIV };
3499
static PyObject * Scale_play(Scale *self, PyObject *args, PyObject *kwds) { PLAY };
3500
static PyObject * Scale_out(Scale *self, PyObject *args, PyObject *kwds) { OUT };
3501
static PyObject * Scale_stop(Scale *self) { STOP };
3503
static PyObject * Scale_multiply(Scale *self, PyObject *arg) { MULTIPLY };
3504
static PyObject * Scale_inplace_multiply(Scale *self, PyObject *arg) { INPLACE_MULTIPLY };
3505
static PyObject * Scale_add(Scale *self, PyObject *arg) { ADD };
3506
static PyObject * Scale_inplace_add(Scale *self, PyObject *arg) { INPLACE_ADD };
3507
static PyObject * Scale_sub(Scale *self, PyObject *arg) { SUB };
3508
static PyObject * Scale_inplace_sub(Scale *self, PyObject *arg) { INPLACE_SUB };
3509
static PyObject * Scale_div(Scale *self, PyObject *arg) { DIV };
3510
static PyObject * Scale_inplace_div(Scale *self, PyObject *arg) { INPLACE_DIV };
3513
Scale_setInMin(Scale *self, PyObject *arg)
3515
PyObject *tmp, *streamtmp;
3522
int isNumber = PyNumber_Check(arg);
3526
Py_DECREF(self->inmin);
3527
if (isNumber == 1) {
3528
self->inmin = PyNumber_Float(tmp);
3529
self->modebuffer[2] = 0;
3533
streamtmp = PyObject_CallMethod((PyObject *)self->inmin, "_getStream", NULL);
3534
Py_INCREF(streamtmp);
3535
Py_XDECREF(self->inmin_stream);
3536
self->inmin_stream = (Stream *)streamtmp;
3537
self->modebuffer[2] = 1;
3540
(*self->mode_func_ptr)(self);
3547
Scale_setInMax(Scale *self, PyObject *arg)
3549
PyObject *tmp, *streamtmp;
3556
int isNumber = PyNumber_Check(arg);
3560
Py_DECREF(self->inmax);
3561
if (isNumber == 1) {
3562
self->inmax = PyNumber_Float(tmp);
3563
self->modebuffer[3] = 0;
3567
streamtmp = PyObject_CallMethod((PyObject *)self->inmax, "_getStream", NULL);
3568
Py_INCREF(streamtmp);
3569
Py_XDECREF(self->inmax_stream);
3570
self->inmax_stream = (Stream *)streamtmp;
3571
self->modebuffer[3] = 1;
3574
(*self->mode_func_ptr)(self);
3581
Scale_setOutMin(Scale *self, PyObject *arg)
3583
PyObject *tmp, *streamtmp;
3590
int isNumber = PyNumber_Check(arg);
3594
Py_DECREF(self->outmin);
3595
if (isNumber == 1) {
3596
self->outmin = PyNumber_Float(tmp);
3597
self->modebuffer[4] = 0;
3601
streamtmp = PyObject_CallMethod((PyObject *)self->outmin, "_getStream", NULL);
3602
Py_INCREF(streamtmp);
3603
Py_XDECREF(self->outmin_stream);
3604
self->outmin_stream = (Stream *)streamtmp;
3605
self->modebuffer[4] = 1;
3608
(*self->mode_func_ptr)(self);
3615
Scale_setOutMax(Scale *self, PyObject *arg)
3617
PyObject *tmp, *streamtmp;
3624
int isNumber = PyNumber_Check(arg);
3628
Py_DECREF(self->outmax);
3629
if (isNumber == 1) {
3630
self->outmax = PyNumber_Float(tmp);
3631
self->modebuffer[5] = 0;
3635
streamtmp = PyObject_CallMethod((PyObject *)self->outmax, "_getStream", NULL);
3636
Py_INCREF(streamtmp);
3637
Py_XDECREF(self->outmax_stream);
3638
self->outmax_stream = (Stream *)streamtmp;
3639
self->modebuffer[5] = 1;
3642
(*self->mode_func_ptr)(self);
3649
Scale_setExp(Scale *self, PyObject *arg)
3651
PyObject *tmp, *streamtmp;
3658
int isNumber = PyNumber_Check(arg);
3662
Py_DECREF(self->exp);
3663
if (isNumber == 1) {
3664
self->exp = PyNumber_Float(tmp);
3665
self->modebuffer[6] = 0;
3669
streamtmp = PyObject_CallMethod((PyObject *)self->exp, "_getStream", NULL);
3670
Py_INCREF(streamtmp);
3671
Py_XDECREF(self->exp_stream);
3672
self->exp_stream = (Stream *)streamtmp;
3673
self->modebuffer[6] = 1;
3676
(*self->mode_func_ptr)(self);
3682
static PyMemberDef Scale_members[] = {
3683
{"server", T_OBJECT_EX, offsetof(Scale, server), 0, "Pyo server."},
3684
{"stream", T_OBJECT_EX, offsetof(Scale, stream), 0, "Stream object."},
3685
{"input", T_OBJECT_EX, offsetof(Scale, input), 0, "Input sound object."},
3686
{"mul", T_OBJECT_EX, offsetof(Scale, mul), 0, "Mul factor."},
3687
{"add", T_OBJECT_EX, offsetof(Scale, add), 0, "Add factor."},
3688
{NULL} /* Sentinel */
3691
static PyMethodDef Scale_methods[] = {
3692
{"getServer", (PyCFunction)Scale_getServer, METH_NOARGS, "Returns server object."},
3693
{"_getStream", (PyCFunction)Scale_getStream, METH_NOARGS, "Returns stream object."},
3694
{"deleteStream", (PyCFunction)Scale_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
3695
{"play", (PyCFunction)Scale_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
3696
{"out", (PyCFunction)Scale_out, METH_VARARGS|METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
3697
{"stop", (PyCFunction)Scale_stop, METH_NOARGS, "Stops computing."},
3698
{"setInMin", (PyCFunction)Scale_setInMin, METH_O, "Sets input minimum scaling value."},
3699
{"setInMax", (PyCFunction)Scale_setInMax, METH_O, "Sets input maximum scaling value."},
3700
{"setOutMin", (PyCFunction)Scale_setOutMin, METH_O, "Sets output minimum scaling value."},
3701
{"setOutMax", (PyCFunction)Scale_setOutMax, METH_O, "Sets output maximum scaling value."},
3702
{"setExp", (PyCFunction)Scale_setExp, METH_O, "Sets exponent factor."},
3703
{"setMul", (PyCFunction)Scale_setMul, METH_O, "Sets oscillator mul factor."},
3704
{"setAdd", (PyCFunction)Scale_setAdd, METH_O, "Sets oscillator add factor."},
3705
{"setSub", (PyCFunction)Scale_setSub, METH_O, "Sets inverse add factor."},
3706
{"setDiv", (PyCFunction)Scale_setDiv, METH_O, "Sets inverse mul factor."},
3707
{NULL} /* Sentinel */
3710
static PyNumberMethods Scale_as_number = {
3711
(binaryfunc)Scale_add, /*nb_add*/
3712
(binaryfunc)Scale_sub, /*nb_subtract*/
3713
(binaryfunc)Scale_multiply, /*nb_multiply*/
3714
(binaryfunc)Scale_div, /*nb_divide*/
3720
0, /*(unaryfunc)array_abs,*/
3734
(binaryfunc)Scale_inplace_add, /*inplace_add*/
3735
(binaryfunc)Scale_inplace_sub, /*inplace_subtract*/
3736
(binaryfunc)Scale_inplace_multiply, /*inplace_multiply*/
3737
(binaryfunc)Scale_inplace_div, /*inplace_divide*/
3738
0, /*inplace_remainder*/
3739
0, /*inplace_power*/
3740
0, /*inplace_lshift*/
3741
0, /*inplace_rshift*/
3745
0, /*nb_floor_divide*/
3746
0, /*nb_true_divide*/
3747
0, /*nb_inplace_floor_divide*/
3748
0, /*nb_inplace_true_divide*/
3752
PyTypeObject ScaleType = {
3753
PyObject_HEAD_INIT(NULL)
3755
"_pyo.Scale_base", /*tp_name*/
3756
sizeof(Scale), /*tp_basicsize*/
3758
(destructor)Scale_dealloc, /*tp_dealloc*/
3764
&Scale_as_number, /*tp_as_number*/
3765
0, /*tp_as_sequence*/
3766
0, /*tp_as_mapping*/
3773
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
3774
"Scale objects. Scale input values on an arbitrary output scaling range.", /* tp_doc */
3775
(traverseproc)Scale_traverse, /* tp_traverse */
3776
(inquiry)Scale_clear, /* tp_clear */
3777
0, /* tp_richcompare */
3778
0, /* tp_weaklistoffset */
3780
0, /* tp_iternext */
3781
Scale_methods, /* tp_methods */
3782
Scale_members, /* tp_members */
3786
0, /* tp_descr_get */
3787
0, /* tp_descr_set */
3788
0, /* tp_dictoffset */
3789
(initproc)Scale_init, /* tp_init */
3791
Scale_new, /* tp_new */
3795
/* CentsToTranspo */
3800
Stream *input_stream;
3803
int modebuffer[2]; // need at least 2 slots for mul & add
3807
CentsToTranspo_process(CentsToTranspo *self) {
3810
MYFLT *in = Stream_getData((Stream *)self->input_stream);
3812
for (i=0; i<self->bufsize; i++) {
3814
if (cents != self->lastcents) {
3815
self->data[i] = self->curtranspo = MYPOW(2.0, cents / 1200.);
3816
self->lastcents = cents;
3819
self->data[i] = self->curtranspo;
3823
static void CentsToTranspo_postprocessing_ii(CentsToTranspo *self) { POST_PROCESSING_II };
3824
static void CentsToTranspo_postprocessing_ai(CentsToTranspo *self) { POST_PROCESSING_AI };
3825
static void CentsToTranspo_postprocessing_ia(CentsToTranspo *self) { POST_PROCESSING_IA };
3826
static void CentsToTranspo_postprocessing_aa(CentsToTranspo *self) { POST_PROCESSING_AA };
3827
static void CentsToTranspo_postprocessing_ireva(CentsToTranspo *self) { POST_PROCESSING_IREVA };
3828
static void CentsToTranspo_postprocessing_areva(CentsToTranspo *self) { POST_PROCESSING_AREVA };
3829
static void CentsToTranspo_postprocessing_revai(CentsToTranspo *self) { POST_PROCESSING_REVAI };
3830
static void CentsToTranspo_postprocessing_revaa(CentsToTranspo *self) { POST_PROCESSING_REVAA };
3831
static void CentsToTranspo_postprocessing_revareva(CentsToTranspo *self) { POST_PROCESSING_REVAREVA };
3834
CentsToTranspo_setProcMode(CentsToTranspo *self)
3837
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
3839
self->proc_func_ptr = CentsToTranspo_process;
3841
switch (muladdmode) {
3843
self->muladd_func_ptr = CentsToTranspo_postprocessing_ii;
3846
self->muladd_func_ptr = CentsToTranspo_postprocessing_ai;
3849
self->muladd_func_ptr = CentsToTranspo_postprocessing_revai;
3852
self->muladd_func_ptr = CentsToTranspo_postprocessing_ia;
3855
self->muladd_func_ptr = CentsToTranspo_postprocessing_aa;
3858
self->muladd_func_ptr = CentsToTranspo_postprocessing_revaa;
3861
self->muladd_func_ptr = CentsToTranspo_postprocessing_ireva;
3864
self->muladd_func_ptr = CentsToTranspo_postprocessing_areva;
3867
self->muladd_func_ptr = CentsToTranspo_postprocessing_revareva;
3873
CentsToTranspo_compute_next_data_frame(CentsToTranspo *self)
3875
(*self->proc_func_ptr)(self);
3876
(*self->muladd_func_ptr)(self);
3880
CentsToTranspo_traverse(CentsToTranspo *self, visitproc visit, void *arg)
3883
Py_VISIT(self->input);
3884
Py_VISIT(self->input_stream);
3889
CentsToTranspo_clear(CentsToTranspo *self)
3892
Py_CLEAR(self->input);
3893
Py_CLEAR(self->input_stream);
3898
CentsToTranspo_dealloc(CentsToTranspo* self)
3901
CentsToTranspo_clear(self);
3902
self->ob_type->tp_free((PyObject*)self);
3905
static PyObject * CentsToTranspo_deleteStream(CentsToTranspo *self) { DELETE_STREAM };
3908
CentsToTranspo_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
3911
CentsToTranspo *self;
3912
self = (CentsToTranspo *)type->tp_alloc(type, 0);
3914
self->lastcents = 0.0;
3915
self->curtranspo = 1.0;
3916
self->modebuffer[0] = 0;
3917
self->modebuffer[1] = 0;
3920
Stream_setFunctionPtr(self->stream, CentsToTranspo_compute_next_data_frame);
3921
self->mode_func_ptr = CentsToTranspo_setProcMode;
3922
return (PyObject *)self;
3926
CentsToTranspo_init(CentsToTranspo *self, PyObject *args, PyObject *kwds)
3928
PyObject *inputtmp, *input_streamtmp, *multmp=NULL, *addtmp=NULL;
3930
static char *kwlist[] = {"input", "mul", "add", NULL};
3932
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
3938
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
3942
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
3945
Py_INCREF(self->stream);
3946
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
3948
(*self->mode_func_ptr)(self);
3955
static PyObject * CentsToTranspo_getServer(CentsToTranspo* self) { GET_SERVER };
3956
static PyObject * CentsToTranspo_getStream(CentsToTranspo* self) { GET_STREAM };
3957
static PyObject * CentsToTranspo_setMul(CentsToTranspo *self, PyObject *arg) { SET_MUL };
3958
static PyObject * CentsToTranspo_setAdd(CentsToTranspo *self, PyObject *arg) { SET_ADD };
3959
static PyObject * CentsToTranspo_setSub(CentsToTranspo *self, PyObject *arg) { SET_SUB };
3960
static PyObject * CentsToTranspo_setDiv(CentsToTranspo *self, PyObject *arg) { SET_DIV };
3962
static PyObject * CentsToTranspo_play(CentsToTranspo *self, PyObject *args, PyObject *kwds) { PLAY };
3963
static PyObject * CentsToTranspo_out(CentsToTranspo *self, PyObject *args, PyObject *kwds) { OUT };
3964
static PyObject * CentsToTranspo_stop(CentsToTranspo *self) { STOP };
3966
static PyObject * CentsToTranspo_multiply(CentsToTranspo *self, PyObject *arg) { MULTIPLY };
3967
static PyObject * CentsToTranspo_inplace_multiply(CentsToTranspo *self, PyObject *arg) { INPLACE_MULTIPLY };
3968
static PyObject * CentsToTranspo_add(CentsToTranspo *self, PyObject *arg) { ADD };
3969
static PyObject * CentsToTranspo_inplace_add(CentsToTranspo *self, PyObject *arg) { INPLACE_ADD };
3970
static PyObject * CentsToTranspo_sub(CentsToTranspo *self, PyObject *arg) { SUB };
3971
static PyObject * CentsToTranspo_inplace_sub(CentsToTranspo *self, PyObject *arg) { INPLACE_SUB };
3972
static PyObject * CentsToTranspo_div(CentsToTranspo *self, PyObject *arg) { DIV };
3973
static PyObject * CentsToTranspo_inplace_div(CentsToTranspo *self, PyObject *arg) { INPLACE_DIV };
3975
static PyMemberDef CentsToTranspo_members[] = {
3976
{"server", T_OBJECT_EX, offsetof(CentsToTranspo, server), 0, "Pyo server."},
3977
{"stream", T_OBJECT_EX, offsetof(CentsToTranspo, stream), 0, "Stream object."},
3978
{"input", T_OBJECT_EX, offsetof(CentsToTranspo, input), 0, "Input sound object."},
3979
{"mul", T_OBJECT_EX, offsetof(CentsToTranspo, mul), 0, "Mul factor."},
3980
{"add", T_OBJECT_EX, offsetof(CentsToTranspo, add), 0, "Add factor."},
3981
{NULL} /* Sentinel */
3984
static PyMethodDef CentsToTranspo_methods[] = {
3985
{"getServer", (PyCFunction)CentsToTranspo_getServer, METH_NOARGS, "Returns server object."},
3986
{"_getStream", (PyCFunction)CentsToTranspo_getStream, METH_NOARGS, "Returns stream object."},
3987
{"deleteStream", (PyCFunction)CentsToTranspo_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
3988
{"play", (PyCFunction)CentsToTranspo_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
3989
{"stop", (PyCFunction)CentsToTranspo_stop, METH_NOARGS, "Stops computing."},
3990
{"out", (PyCFunction)CentsToTranspo_out, METH_VARARGS|METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
3991
{"setMul", (PyCFunction)CentsToTranspo_setMul, METH_O, "Sets oscillator mul factor."},
3992
{"setAdd", (PyCFunction)CentsToTranspo_setAdd, METH_O, "Sets oscillator add factor."},
3993
{"setSub", (PyCFunction)CentsToTranspo_setSub, METH_O, "Sets inverse add factor."},
3994
{"setDiv", (PyCFunction)CentsToTranspo_setDiv, METH_O, "Sets inverse mul factor."},
3995
{NULL} /* Sentinel */
3998
static PyNumberMethods CentsToTranspo_as_number = {
3999
(binaryfunc)CentsToTranspo_add, /*nb_add*/
4000
(binaryfunc)CentsToTranspo_sub, /*nb_subtract*/
4001
(binaryfunc)CentsToTranspo_multiply, /*nb_multiply*/
4002
(binaryfunc)CentsToTranspo_div, /*nb_divide*/
4008
0, /*(unaryfunc)array_abs,*/
4022
(binaryfunc)CentsToTranspo_inplace_add, /*inplace_add*/
4023
(binaryfunc)CentsToTranspo_inplace_sub, /*inplace_subtract*/
4024
(binaryfunc)CentsToTranspo_inplace_multiply, /*inplace_multiply*/
4025
(binaryfunc)CentsToTranspo_inplace_div, /*inplace_divide*/
4026
0, /*inplace_remainder*/
4027
0, /*inplace_power*/
4028
0, /*inplace_lshift*/
4029
0, /*inplace_rshift*/
4033
0, /*nb_floor_divide*/
4034
0, /*nb_true_divide*/
4035
0, /*nb_inplace_floor_divide*/
4036
0, /*nb_inplace_true_divide*/
4040
PyTypeObject CentsToTranspoType = {
4041
PyObject_HEAD_INIT(NULL)
4043
"_pyo.CentsToTranspo_base", /*tp_name*/
4044
sizeof(CentsToTranspo), /*tp_basicsize*/
4046
(destructor)CentsToTranspo_dealloc, /*tp_dealloc*/
4052
&CentsToTranspo_as_number, /*tp_as_number*/
4053
0, /*tp_as_sequence*/
4054
0, /*tp_as_mapping*/
4061
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
4062
"CentsToTranspo objects. Converts cents value to transposition factor.", /* tp_doc */
4063
(traverseproc)CentsToTranspo_traverse, /* tp_traverse */
4064
(inquiry)CentsToTranspo_clear, /* tp_clear */
4065
0, /* tp_richcompare */
4066
0, /* tp_weaklistoffset */
4068
0, /* tp_iternext */
4069
CentsToTranspo_methods, /* tp_methods */
4070
CentsToTranspo_members, /* tp_members */
4074
0, /* tp_descr_get */
4075
0, /* tp_descr_set */
4076
0, /* tp_dictoffset */
4077
(initproc)CentsToTranspo_init, /* tp_init */
4079
CentsToTranspo_new, /* tp_new */
4083
/* TranspoToCents */
4088
Stream *input_stream;
4091
int modebuffer[2]; // need at least 2 slots for mul & add
4095
TranspoToCents_process(TranspoToCents *self) {
4098
MYFLT *in = Stream_getData((Stream *)self->input_stream);
4100
for (i=0; i<self->bufsize; i++) {
4102
if (transpo != self->lasttranspo) {
4103
self->data[i] = self->curcents = 1200.0 * MYLOG2(transpo);
4104
self->lasttranspo = transpo;
4107
self->data[i] = self->curcents;
4111
static void TranspoToCents_postprocessing_ii(TranspoToCents *self) { POST_PROCESSING_II };
4112
static void TranspoToCents_postprocessing_ai(TranspoToCents *self) { POST_PROCESSING_AI };
4113
static void TranspoToCents_postprocessing_ia(TranspoToCents *self) { POST_PROCESSING_IA };
4114
static void TranspoToCents_postprocessing_aa(TranspoToCents *self) { POST_PROCESSING_AA };
4115
static void TranspoToCents_postprocessing_ireva(TranspoToCents *self) { POST_PROCESSING_IREVA };
4116
static void TranspoToCents_postprocessing_areva(TranspoToCents *self) { POST_PROCESSING_AREVA };
4117
static void TranspoToCents_postprocessing_revai(TranspoToCents *self) { POST_PROCESSING_REVAI };
4118
static void TranspoToCents_postprocessing_revaa(TranspoToCents *self) { POST_PROCESSING_REVAA };
4119
static void TranspoToCents_postprocessing_revareva(TranspoToCents *self) { POST_PROCESSING_REVAREVA };
4122
TranspoToCents_setProcMode(TranspoToCents *self)
4125
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
4127
self->proc_func_ptr = TranspoToCents_process;
4129
switch (muladdmode) {
4131
self->muladd_func_ptr = TranspoToCents_postprocessing_ii;
4134
self->muladd_func_ptr = TranspoToCents_postprocessing_ai;
4137
self->muladd_func_ptr = TranspoToCents_postprocessing_revai;
4140
self->muladd_func_ptr = TranspoToCents_postprocessing_ia;
4143
self->muladd_func_ptr = TranspoToCents_postprocessing_aa;
4146
self->muladd_func_ptr = TranspoToCents_postprocessing_revaa;
4149
self->muladd_func_ptr = TranspoToCents_postprocessing_ireva;
4152
self->muladd_func_ptr = TranspoToCents_postprocessing_areva;
4155
self->muladd_func_ptr = TranspoToCents_postprocessing_revareva;
4161
TranspoToCents_compute_next_data_frame(TranspoToCents *self)
4163
(*self->proc_func_ptr)(self);
4164
(*self->muladd_func_ptr)(self);
4168
TranspoToCents_traverse(TranspoToCents *self, visitproc visit, void *arg)
4171
Py_VISIT(self->input);
4172
Py_VISIT(self->input_stream);
4177
TranspoToCents_clear(TranspoToCents *self)
4180
Py_CLEAR(self->input);
4181
Py_CLEAR(self->input_stream);
4186
TranspoToCents_dealloc(TranspoToCents* self)
4189
TranspoToCents_clear(self);
4190
self->ob_type->tp_free((PyObject*)self);
4193
static PyObject * TranspoToCents_deleteStream(TranspoToCents *self) { DELETE_STREAM };
4196
TranspoToCents_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4199
TranspoToCents *self;
4200
self = (TranspoToCents *)type->tp_alloc(type, 0);
4202
self->lasttranspo = 1.0;
4203
self->curcents = 0.0;
4204
self->modebuffer[0] = 0;
4205
self->modebuffer[1] = 0;
4208
Stream_setFunctionPtr(self->stream, TranspoToCents_compute_next_data_frame);
4209
self->mode_func_ptr = TranspoToCents_setProcMode;
4210
return (PyObject *)self;
4214
TranspoToCents_init(TranspoToCents *self, PyObject *args, PyObject *kwds)
4216
PyObject *inputtmp, *input_streamtmp, *multmp=NULL, *addtmp=NULL;
4218
static char *kwlist[] = {"input", "mul", "add", NULL};
4220
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
4226
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
4230
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
4233
Py_INCREF(self->stream);
4234
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
4236
(*self->mode_func_ptr)(self);
4243
static PyObject * TranspoToCents_getServer(TranspoToCents* self) { GET_SERVER };
4244
static PyObject * TranspoToCents_getStream(TranspoToCents* self) { GET_STREAM };
4245
static PyObject * TranspoToCents_setMul(TranspoToCents *self, PyObject *arg) { SET_MUL };
4246
static PyObject * TranspoToCents_setAdd(TranspoToCents *self, PyObject *arg) { SET_ADD };
4247
static PyObject * TranspoToCents_setSub(TranspoToCents *self, PyObject *arg) { SET_SUB };
4248
static PyObject * TranspoToCents_setDiv(TranspoToCents *self, PyObject *arg) { SET_DIV };
4250
static PyObject * TranspoToCents_play(TranspoToCents *self, PyObject *args, PyObject *kwds) { PLAY };
4251
static PyObject * TranspoToCents_out(TranspoToCents *self, PyObject *args, PyObject *kwds) { OUT };
4252
static PyObject * TranspoToCents_stop(TranspoToCents *self) { STOP };
4254
static PyObject * TranspoToCents_multiply(TranspoToCents *self, PyObject *arg) { MULTIPLY };
4255
static PyObject * TranspoToCents_inplace_multiply(TranspoToCents *self, PyObject *arg) { INPLACE_MULTIPLY };
4256
static PyObject * TranspoToCents_add(TranspoToCents *self, PyObject *arg) { ADD };
4257
static PyObject * TranspoToCents_inplace_add(TranspoToCents *self, PyObject *arg) { INPLACE_ADD };
4258
static PyObject * TranspoToCents_sub(TranspoToCents *self, PyObject *arg) { SUB };
4259
static PyObject * TranspoToCents_inplace_sub(TranspoToCents *self, PyObject *arg) { INPLACE_SUB };
4260
static PyObject * TranspoToCents_div(TranspoToCents *self, PyObject *arg) { DIV };
4261
static PyObject * TranspoToCents_inplace_div(TranspoToCents *self, PyObject *arg) { INPLACE_DIV };
4263
static PyMemberDef TranspoToCents_members[] = {
4264
{"server", T_OBJECT_EX, offsetof(TranspoToCents, server), 0, "Pyo server."},
4265
{"stream", T_OBJECT_EX, offsetof(TranspoToCents, stream), 0, "Stream object."},
4266
{"input", T_OBJECT_EX, offsetof(TranspoToCents, input), 0, "Input sound object."},
4267
{"mul", T_OBJECT_EX, offsetof(TranspoToCents, mul), 0, "Mul factor."},
4268
{"add", T_OBJECT_EX, offsetof(TranspoToCents, add), 0, "Add factor."},
4269
{NULL} /* Sentinel */
4272
static PyMethodDef TranspoToCents_methods[] = {
4273
{"getServer", (PyCFunction)TranspoToCents_getServer, METH_NOARGS, "Returns server object."},
4274
{"_getStream", (PyCFunction)TranspoToCents_getStream, METH_NOARGS, "Returns stream object."},
4275
{"deleteStream", (PyCFunction)TranspoToCents_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
4276
{"play", (PyCFunction)TranspoToCents_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
4277
{"stop", (PyCFunction)TranspoToCents_stop, METH_NOARGS, "Stops computing."},
4278
{"out", (PyCFunction)TranspoToCents_out, METH_VARARGS|METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
4279
{"setMul", (PyCFunction)TranspoToCents_setMul, METH_O, "Sets oscillator mul factor."},
4280
{"setAdd", (PyCFunction)TranspoToCents_setAdd, METH_O, "Sets oscillator add factor."},
4281
{"setSub", (PyCFunction)TranspoToCents_setSub, METH_O, "Sets inverse add factor."},
4282
{"setDiv", (PyCFunction)TranspoToCents_setDiv, METH_O, "Sets inverse mul factor."},
4283
{NULL} /* Sentinel */
4286
static PyNumberMethods TranspoToCents_as_number = {
4287
(binaryfunc)TranspoToCents_add, /*nb_add*/
4288
(binaryfunc)TranspoToCents_sub, /*nb_subtract*/
4289
(binaryfunc)TranspoToCents_multiply, /*nb_multiply*/
4290
(binaryfunc)TranspoToCents_div, /*nb_divide*/
4296
0, /*(unaryfunc)array_abs,*/
4310
(binaryfunc)TranspoToCents_inplace_add, /*inplace_add*/
4311
(binaryfunc)TranspoToCents_inplace_sub, /*inplace_subtract*/
4312
(binaryfunc)TranspoToCents_inplace_multiply, /*inplace_multiply*/
4313
(binaryfunc)TranspoToCents_inplace_div, /*inplace_divide*/
4314
0, /*inplace_remainder*/
4315
0, /*inplace_power*/
4316
0, /*inplace_lshift*/
4317
0, /*inplace_rshift*/
4321
0, /*nb_floor_divide*/
4322
0, /*nb_true_divide*/
4323
0, /*nb_inplace_floor_divide*/
4324
0, /*nb_inplace_true_divide*/
4328
PyTypeObject TranspoToCentsType = {
4329
PyObject_HEAD_INIT(NULL)
4331
"_pyo.TranspoToCents_base", /*tp_name*/
4332
sizeof(TranspoToCents), /*tp_basicsize*/
4334
(destructor)TranspoToCents_dealloc, /*tp_dealloc*/
4340
&TranspoToCents_as_number, /*tp_as_number*/
4341
0, /*tp_as_sequence*/
4342
0, /*tp_as_mapping*/
4349
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
4350
"TranspoToCents objects. Converts transposition factor to cents value.", /* tp_doc */
4351
(traverseproc)TranspoToCents_traverse, /* tp_traverse */
4352
(inquiry)TranspoToCents_clear, /* tp_clear */
4353
0, /* tp_richcompare */
4354
0, /* tp_weaklistoffset */
4356
0, /* tp_iternext */
4357
TranspoToCents_methods, /* tp_methods */
4358
TranspoToCents_members, /* tp_members */
4362
0, /* tp_descr_get */
4363
0, /* tp_descr_set */
4364
0, /* tp_dictoffset */
4365
(initproc)TranspoToCents_init, /* tp_init */
4367
TranspoToCents_new, /* tp_new */
4376
Stream *input_stream;
4379
int modebuffer[2]; // need at least 2 slots for mul & add
4383
MToF_process(MToF *self) {
4386
MYFLT *in = Stream_getData((Stream *)self->input_stream);
4388
for (i=0; i<self->bufsize; i++) {
4390
if (midi != self->lastmidi) {
4391
self->data[i] = self->curfreq = 8.1757989156437 * MYPOW(1.0594630943593, midi);
4392
self->lastmidi = midi;
4395
self->data[i] = self->curfreq;
4399
static void MToF_postprocessing_ii(MToF *self) { POST_PROCESSING_II };
4400
static void MToF_postprocessing_ai(MToF *self) { POST_PROCESSING_AI };
4401
static void MToF_postprocessing_ia(MToF *self) { POST_PROCESSING_IA };
4402
static void MToF_postprocessing_aa(MToF *self) { POST_PROCESSING_AA };
4403
static void MToF_postprocessing_ireva(MToF *self) { POST_PROCESSING_IREVA };
4404
static void MToF_postprocessing_areva(MToF *self) { POST_PROCESSING_AREVA };
4405
static void MToF_postprocessing_revai(MToF *self) { POST_PROCESSING_REVAI };
4406
static void MToF_postprocessing_revaa(MToF *self) { POST_PROCESSING_REVAA };
4407
static void MToF_postprocessing_revareva(MToF *self) { POST_PROCESSING_REVAREVA };
4410
MToF_setProcMode(MToF *self)
4413
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
4415
self->proc_func_ptr = MToF_process;
4417
switch (muladdmode) {
4419
self->muladd_func_ptr = MToF_postprocessing_ii;
4422
self->muladd_func_ptr = MToF_postprocessing_ai;
4425
self->muladd_func_ptr = MToF_postprocessing_revai;
4428
self->muladd_func_ptr = MToF_postprocessing_ia;
4431
self->muladd_func_ptr = MToF_postprocessing_aa;
4434
self->muladd_func_ptr = MToF_postprocessing_revaa;
4437
self->muladd_func_ptr = MToF_postprocessing_ireva;
4440
self->muladd_func_ptr = MToF_postprocessing_areva;
4443
self->muladd_func_ptr = MToF_postprocessing_revareva;
4449
MToF_compute_next_data_frame(MToF *self)
4451
(*self->proc_func_ptr)(self);
4452
(*self->muladd_func_ptr)(self);
4456
MToF_traverse(MToF *self, visitproc visit, void *arg)
4459
Py_VISIT(self->input);
4460
Py_VISIT(self->input_stream);
4465
MToF_clear(MToF *self)
4468
Py_CLEAR(self->input);
4469
Py_CLEAR(self->input_stream);
4474
MToF_dealloc(MToF* self)
4478
self->ob_type->tp_free((PyObject*)self);
4481
static PyObject * MToF_deleteStream(MToF *self) { DELETE_STREAM };
4484
MToF_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4488
self = (MToF *)type->tp_alloc(type, 0);
4491
self->curfreq = 8.1757989156437;
4492
self->modebuffer[0] = 0;
4493
self->modebuffer[1] = 0;
4496
Stream_setFunctionPtr(self->stream, MToF_compute_next_data_frame);
4497
self->mode_func_ptr = MToF_setProcMode;
4498
return (PyObject *)self;
4502
MToF_init(MToF *self, PyObject *args, PyObject *kwds)
4504
PyObject *inputtmp, *input_streamtmp, *multmp=NULL, *addtmp=NULL;
4506
static char *kwlist[] = {"input", "mul", "add", NULL};
4508
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
4514
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
4518
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
4521
Py_INCREF(self->stream);
4522
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
4524
(*self->mode_func_ptr)(self);
4531
static PyObject * MToF_getServer(MToF* self) { GET_SERVER };
4532
static PyObject * MToF_getStream(MToF* self) { GET_STREAM };
4533
static PyObject * MToF_setMul(MToF *self, PyObject *arg) { SET_MUL };
4534
static PyObject * MToF_setAdd(MToF *self, PyObject *arg) { SET_ADD };
4535
static PyObject * MToF_setSub(MToF *self, PyObject *arg) { SET_SUB };
4536
static PyObject * MToF_setDiv(MToF *self, PyObject *arg) { SET_DIV };
4538
static PyObject * MToF_play(MToF *self, PyObject *args, PyObject *kwds) { PLAY };
4539
static PyObject * MToF_out(MToF *self, PyObject *args, PyObject *kwds) { OUT };
4540
static PyObject * MToF_stop(MToF *self) { STOP };
4542
static PyObject * MToF_multiply(MToF *self, PyObject *arg) { MULTIPLY };
4543
static PyObject * MToF_inplace_multiply(MToF *self, PyObject *arg) { INPLACE_MULTIPLY };
4544
static PyObject * MToF_add(MToF *self, PyObject *arg) { ADD };
4545
static PyObject * MToF_inplace_add(MToF *self, PyObject *arg) { INPLACE_ADD };
4546
static PyObject * MToF_sub(MToF *self, PyObject *arg) { SUB };
4547
static PyObject * MToF_inplace_sub(MToF *self, PyObject *arg) { INPLACE_SUB };
4548
static PyObject * MToF_div(MToF *self, PyObject *arg) { DIV };
4549
static PyObject * MToF_inplace_div(MToF *self, PyObject *arg) { INPLACE_DIV };
4551
static PyMemberDef MToF_members[] = {
4552
{"server", T_OBJECT_EX, offsetof(MToF, server), 0, "Pyo server."},
4553
{"stream", T_OBJECT_EX, offsetof(MToF, stream), 0, "Stream object."},
4554
{"input", T_OBJECT_EX, offsetof(MToF, input), 0, "Input sound object."},
4555
{"mul", T_OBJECT_EX, offsetof(MToF, mul), 0, "Mul factor."},
4556
{"add", T_OBJECT_EX, offsetof(MToF, add), 0, "Add factor."},
4557
{NULL} /* Sentinel */
4560
static PyMethodDef MToF_methods[] = {
4561
{"getServer", (PyCFunction)MToF_getServer, METH_NOARGS, "Returns server object."},
4562
{"_getStream", (PyCFunction)MToF_getStream, METH_NOARGS, "Returns stream object."},
4563
{"deleteStream", (PyCFunction)MToF_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
4564
{"play", (PyCFunction)MToF_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
4565
{"stop", (PyCFunction)MToF_stop, METH_NOARGS, "Stops computing."},
4566
{"out", (PyCFunction)MToF_out, METH_VARARGS|METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
4567
{"setMul", (PyCFunction)MToF_setMul, METH_O, "Sets oscillator mul factor."},
4568
{"setAdd", (PyCFunction)MToF_setAdd, METH_O, "Sets oscillator add factor."},
4569
{"setSub", (PyCFunction)MToF_setSub, METH_O, "Sets inverse add factor."},
4570
{"setDiv", (PyCFunction)MToF_setDiv, METH_O, "Sets inverse mul factor."},
4571
{NULL} /* Sentinel */
4574
static PyNumberMethods MToF_as_number = {
4575
(binaryfunc)MToF_add, /*nb_add*/
4576
(binaryfunc)MToF_sub, /*nb_subtract*/
4577
(binaryfunc)MToF_multiply, /*nb_multiply*/
4578
(binaryfunc)MToF_div, /*nb_divide*/
4584
0, /*(unaryfunc)array_abs,*/
4598
(binaryfunc)MToF_inplace_add, /*inplace_add*/
4599
(binaryfunc)MToF_inplace_sub, /*inplace_subtract*/
4600
(binaryfunc)MToF_inplace_multiply, /*inplace_multiply*/
4601
(binaryfunc)MToF_inplace_div, /*inplace_divide*/
4602
0, /*inplace_remainder*/
4603
0, /*inplace_power*/
4604
0, /*inplace_lshift*/
4605
0, /*inplace_rshift*/
4609
0, /*nb_floor_divide*/
4610
0, /*nb_true_divide*/
4611
0, /*nb_inplace_floor_divide*/
4612
0, /*nb_inplace_true_divide*/
4616
PyTypeObject MToFType = {
4617
PyObject_HEAD_INIT(NULL)
4619
"_pyo.MToF_base", /*tp_name*/
4620
sizeof(MToF), /*tp_basicsize*/
4622
(destructor)MToF_dealloc, /*tp_dealloc*/
4628
&MToF_as_number, /*tp_as_number*/
4629
0, /*tp_as_sequence*/
4630
0, /*tp_as_mapping*/
4637
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
4638
"MToF objects. Converts midi notes to frequency.", /* tp_doc */
4639
(traverseproc)MToF_traverse, /* tp_traverse */
4640
(inquiry)MToF_clear, /* tp_clear */
4641
0, /* tp_richcompare */
4642
0, /* tp_weaklistoffset */
4644
0, /* tp_iternext */
4645
MToF_methods, /* tp_methods */
4646
MToF_members, /* tp_members */
4650
0, /* tp_descr_get */
4651
0, /* tp_descr_set */
4652
0, /* tp_dictoffset */
4653
(initproc)MToF_init, /* tp_init */
4655
MToF_new, /* tp_new */
4664
Stream *input_stream;
4668
int modebuffer[2]; // need at least 2 slots for mul & add
4672
MToT_process(MToT *self) {
4675
MYFLT *in = Stream_getData((Stream *)self->input_stream);
4677
for (i=0; i<self->bufsize; i++) {
4679
if (midi != self->lastmidi) {
4680
self->data[i] = self->curfreq = MYPOW(1.0594630943593, midi - self->centralkey);
4681
self->lastmidi = midi;
4684
self->data[i] = self->curfreq;
4688
static void MToT_postprocessing_ii(MToT *self) { POST_PROCESSING_II };
4689
static void MToT_postprocessing_ai(MToT *self) { POST_PROCESSING_AI };
4690
static void MToT_postprocessing_ia(MToT *self) { POST_PROCESSING_IA };
4691
static void MToT_postprocessing_aa(MToT *self) { POST_PROCESSING_AA };
4692
static void MToT_postprocessing_ireva(MToT *self) { POST_PROCESSING_IREVA };
4693
static void MToT_postprocessing_areva(MToT *self) { POST_PROCESSING_AREVA };
4694
static void MToT_postprocessing_revai(MToT *self) { POST_PROCESSING_REVAI };
4695
static void MToT_postprocessing_revaa(MToT *self) { POST_PROCESSING_REVAA };
4696
static void MToT_postprocessing_revareva(MToT *self) { POST_PROCESSING_REVAREVA };
4699
MToT_setProcMode(MToT *self)
4702
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
4704
self->proc_func_ptr = MToT_process;
4706
switch (muladdmode) {
4708
self->muladd_func_ptr = MToT_postprocessing_ii;
4711
self->muladd_func_ptr = MToT_postprocessing_ai;
4714
self->muladd_func_ptr = MToT_postprocessing_revai;
4717
self->muladd_func_ptr = MToT_postprocessing_ia;
4720
self->muladd_func_ptr = MToT_postprocessing_aa;
4723
self->muladd_func_ptr = MToT_postprocessing_revaa;
4726
self->muladd_func_ptr = MToT_postprocessing_ireva;
4729
self->muladd_func_ptr = MToT_postprocessing_areva;
4732
self->muladd_func_ptr = MToT_postprocessing_revareva;
4738
MToT_compute_next_data_frame(MToT *self)
4740
(*self->proc_func_ptr)(self);
4741
(*self->muladd_func_ptr)(self);
4745
MToT_traverse(MToT *self, visitproc visit, void *arg)
4748
Py_VISIT(self->input);
4749
Py_VISIT(self->input_stream);
4754
MToT_clear(MToT *self)
4757
Py_CLEAR(self->input);
4758
Py_CLEAR(self->input_stream);
4763
MToT_dealloc(MToT* self)
4767
self->ob_type->tp_free((PyObject*)self);
4770
static PyObject * MToT_deleteStream(MToT *self) { DELETE_STREAM };
4773
MToT_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4777
self = (MToT *)type->tp_alloc(type, 0);
4779
self->centralkey = 60.0;
4781
self->curfreq = 8.1757989156437;
4782
self->modebuffer[0] = 0;
4783
self->modebuffer[1] = 0;
4786
Stream_setFunctionPtr(self->stream, MToT_compute_next_data_frame);
4787
self->mode_func_ptr = MToT_setProcMode;
4788
return (PyObject *)self;
4792
MToT_init(MToT *self, PyObject *args, PyObject *kwds)
4794
PyObject *inputtmp, *input_streamtmp, *multmp=NULL, *addtmp=NULL;
4796
static char *kwlist[] = {"input", "centralkey", "mul", "add", NULL};
4798
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_O_FOO, kwlist, &inputtmp, &self->centralkey, &multmp, &addtmp))
4804
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
4808
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
4811
Py_INCREF(self->stream);
4812
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
4814
(*self->mode_func_ptr)(self);
4822
MToT_setCentralKey(MToT *self, PyObject *arg)
4829
int isNumber = PyNumber_Check(arg);
4831
if (isNumber == 1) {
4832
self->centralkey = PyFloat_AS_DOUBLE(PyNumber_Float(arg));
4839
static PyObject * MToT_getServer(MToT* self) { GET_SERVER };
4840
static PyObject * MToT_getStream(MToT* self) { GET_STREAM };
4841
static PyObject * MToT_setMul(MToT *self, PyObject *arg) { SET_MUL };
4842
static PyObject * MToT_setAdd(MToT *self, PyObject *arg) { SET_ADD };
4843
static PyObject * MToT_setSub(MToT *self, PyObject *arg) { SET_SUB };
4844
static PyObject * MToT_setDiv(MToT *self, PyObject *arg) { SET_DIV };
4846
static PyObject * MToT_play(MToT *self, PyObject *args, PyObject *kwds) { PLAY };
4847
static PyObject * MToT_out(MToT *self, PyObject *args, PyObject *kwds) { OUT };
4848
static PyObject * MToT_stop(MToT *self) { STOP };
4850
static PyObject * MToT_multiply(MToT *self, PyObject *arg) { MULTIPLY };
4851
static PyObject * MToT_inplace_multiply(MToT *self, PyObject *arg) { INPLACE_MULTIPLY };
4852
static PyObject * MToT_add(MToT *self, PyObject *arg) { ADD };
4853
static PyObject * MToT_inplace_add(MToT *self, PyObject *arg) { INPLACE_ADD };
4854
static PyObject * MToT_sub(MToT *self, PyObject *arg) { SUB };
4855
static PyObject * MToT_inplace_sub(MToT *self, PyObject *arg) { INPLACE_SUB };
4856
static PyObject * MToT_div(MToT *self, PyObject *arg) { DIV };
4857
static PyObject * MToT_inplace_div(MToT *self, PyObject *arg) { INPLACE_DIV };
4859
static PyMemberDef MToT_members[] = {
4860
{"server", T_OBJECT_EX, offsetof(MToT, server), 0, "Pyo server."},
4861
{"stream", T_OBJECT_EX, offsetof(MToT, stream), 0, "Stream object."},
4862
{"input", T_OBJECT_EX, offsetof(MToT, input), 0, "Input sound object."},
4863
{"mul", T_OBJECT_EX, offsetof(MToT, mul), 0, "Mul factor."},
4864
{"add", T_OBJECT_EX, offsetof(MToT, add), 0, "Add factor."},
4865
{NULL} /* Sentinel */
4868
static PyMethodDef MToT_methods[] = {
4869
{"getServer", (PyCFunction)MToT_getServer, METH_NOARGS, "Returns server object."},
4870
{"_getStream", (PyCFunction)MToT_getStream, METH_NOARGS, "Returns stream object."},
4871
{"deleteStream", (PyCFunction)MToT_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
4872
{"play", (PyCFunction)MToT_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
4873
{"stop", (PyCFunction)MToT_stop, METH_NOARGS, "Stops computing."},
4874
{"out", (PyCFunction)MToT_out, METH_VARARGS|METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
4875
{"setCentralKey", (PyCFunction)MToT_setCentralKey, METH_O, "Sets the central key."},
4876
{"setMul", (PyCFunction)MToT_setMul, METH_O, "Sets oscillator mul factor."},
4877
{"setAdd", (PyCFunction)MToT_setAdd, METH_O, "Sets oscillator add factor."},
4878
{"setSub", (PyCFunction)MToT_setSub, METH_O, "Sets inverse add factor."},
4879
{"setDiv", (PyCFunction)MToT_setDiv, METH_O, "Sets inverse mul factor."},
4880
{NULL} /* Sentinel */
4883
static PyNumberMethods MToT_as_number = {
4884
(binaryfunc)MToT_add, /*nb_add*/
4885
(binaryfunc)MToT_sub, /*nb_subtract*/
4886
(binaryfunc)MToT_multiply, /*nb_multiply*/
4887
(binaryfunc)MToT_div, /*nb_divide*/
4893
0, /*(unaryfunc)array_abs,*/
4907
(binaryfunc)MToT_inplace_add, /*inplace_add*/
4908
(binaryfunc)MToT_inplace_sub, /*inplace_subtract*/
4909
(binaryfunc)MToT_inplace_multiply, /*inplace_multiply*/
4910
(binaryfunc)MToT_inplace_div, /*inplace_divide*/
4911
0, /*inplace_remainder*/
4912
0, /*inplace_power*/
4913
0, /*inplace_lshift*/
4914
0, /*inplace_rshift*/
4918
0, /*nb_floor_divide*/
4919
0, /*nb_true_divide*/
4920
0, /*nb_inplace_floor_divide*/
4921
0, /*nb_inplace_true_divide*/
4925
PyTypeObject MToTType = {
4926
PyObject_HEAD_INIT(NULL)
4928
"_pyo.MToT_base", /*tp_name*/
4929
sizeof(MToT), /*tp_basicsize*/
4931
(destructor)MToT_dealloc, /*tp_dealloc*/
4937
&MToT_as_number, /*tp_as_number*/
4938
0, /*tp_as_sequence*/
4939
0, /*tp_as_mapping*/
4946
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
4947
"MToT objects. Converts midi notes to transposition factor.", /* tp_doc */
4948
(traverseproc)MToT_traverse, /* tp_traverse */
4949
(inquiry)MToT_clear, /* tp_clear */
4950
0, /* tp_richcompare */
4951
0, /* tp_weaklistoffset */
4953
0, /* tp_iternext */
4954
MToT_methods, /* tp_methods */
4955
MToT_members, /* tp_members */
4959
0, /* tp_descr_get */
4960
0, /* tp_descr_set */
4961
0, /* tp_dictoffset */
4962
(initproc)MToT_init, /* tp_init */
4964
MToT_new, /* tp_new */