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"
23
#include "pyomodule.h"
24
#include "streammodule.h"
25
#include "servermodule.h"
26
#include "dummymodule.h"
36
Noise_generate(Noise *self) {
39
for (i=0; i<self->bufsize; i++) {
40
self->data[i] = rand()/((MYFLT)(RAND_MAX)+1)*1.98-0.99;
45
Noise_generate_cheap(Noise *self) {
48
for (i=0; i<self->bufsize; i++) {
49
self->seed = (self->seed * 15625 + 1) & 0xFFFF;
50
self->data[i] = (self->seed - 0x8000) * 3.0517578125e-05;
54
static void Noise_postprocessing_ii(Noise *self) { POST_PROCESSING_II };
55
static void Noise_postprocessing_ai(Noise *self) { POST_PROCESSING_AI };
56
static void Noise_postprocessing_ia(Noise *self) { POST_PROCESSING_IA };
57
static void Noise_postprocessing_aa(Noise *self) { POST_PROCESSING_AA };
58
static void Noise_postprocessing_ireva(Noise *self) { POST_PROCESSING_IREVA };
59
static void Noise_postprocessing_areva(Noise *self) { POST_PROCESSING_AREVA };
60
static void Noise_postprocessing_revai(Noise *self) { POST_PROCESSING_REVAI };
61
static void Noise_postprocessing_revaa(Noise *self) { POST_PROCESSING_REVAA };
62
static void Noise_postprocessing_revareva(Noise *self) { POST_PROCESSING_REVAREVA };
65
Noise_setProcMode(Noise *self)
68
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
72
self->proc_func_ptr = Noise_generate;
75
self->proc_func_ptr = Noise_generate_cheap;
80
self->muladd_func_ptr = Noise_postprocessing_ii;
83
self->muladd_func_ptr = Noise_postprocessing_ai;
86
self->muladd_func_ptr = Noise_postprocessing_revai;
89
self->muladd_func_ptr = Noise_postprocessing_ia;
92
self->muladd_func_ptr = Noise_postprocessing_aa;
95
self->muladd_func_ptr = Noise_postprocessing_revaa;
98
self->muladd_func_ptr = Noise_postprocessing_ireva;
101
self->muladd_func_ptr = Noise_postprocessing_areva;
104
self->muladd_func_ptr = Noise_postprocessing_revareva;
110
Noise_compute_next_data_frame(Noise *self)
112
(*self->proc_func_ptr)(self);
113
(*self->muladd_func_ptr)(self);
117
Noise_traverse(Noise *self, visitproc visit, void *arg)
124
Noise_clear(Noise *self)
131
Noise_dealloc(Noise* self)
135
self->ob_type->tp_free((PyObject*)self);
138
static PyObject * Noise_deleteStream(Noise *self) { DELETE_STREAM };
141
Noise_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
145
self = (Noise *)type->tp_alloc(type, 0);
148
self->modebuffer[0] = 0;
149
self->modebuffer[1] = 0;
152
Stream_setFunctionPtr(self->stream, Noise_compute_next_data_frame);
153
self->mode_func_ptr = Noise_setProcMode;
155
return (PyObject *)self;
159
Noise_init(Noise *self, PyObject *args, PyObject *kwds)
161
PyObject *multmp=NULL, *addtmp=NULL;
163
static char *kwlist[] = {"mul", "add", NULL};
165
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, &multmp, &addtmp))
169
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
173
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
176
Py_INCREF(self->stream);
177
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
179
Server_generateSeed((Server *)self->server, NOISE_ID);
183
(*self->mode_func_ptr)(self);
189
static PyObject * Noise_getServer(Noise* self) { GET_SERVER };
190
static PyObject * Noise_getStream(Noise* self) { GET_STREAM };
191
static PyObject * Noise_setMul(Noise *self, PyObject *arg) { SET_MUL };
192
static PyObject * Noise_setAdd(Noise *self, PyObject *arg) { SET_ADD };
193
static PyObject * Noise_setSub(Noise *self, PyObject *arg) { SET_SUB };
194
static PyObject * Noise_setDiv(Noise *self, PyObject *arg) { SET_DIV };
196
static PyObject * Noise_play(Noise *self, PyObject *args, PyObject *kwds) { PLAY };
197
static PyObject * Noise_out(Noise *self, PyObject *args, PyObject *kwds) { OUT };
198
static PyObject * Noise_stop(Noise *self) { STOP };
200
static PyObject * Noise_multiply(Noise *self, PyObject *arg) { MULTIPLY };
201
static PyObject * Noise_inplace_multiply(Noise *self, PyObject *arg) { INPLACE_MULTIPLY };
202
static PyObject * Noise_add(Noise *self, PyObject *arg) { ADD };
203
static PyObject * Noise_inplace_add(Noise *self, PyObject *arg) { INPLACE_ADD };
204
static PyObject * Noise_sub(Noise *self, PyObject *arg) { SUB };
205
static PyObject * Noise_inplace_sub(Noise *self, PyObject *arg) { INPLACE_SUB };
206
static PyObject * Noise_div(Noise *self, PyObject *arg) { DIV };
207
static PyObject * Noise_inplace_div(Noise *self, PyObject *arg) { INPLACE_DIV };
210
Noise_setType(Noise *self, PyObject *arg)
217
if (PyInt_AS_LONG(arg) == 0)
219
else if (PyInt_AS_LONG(arg) == 1)
222
(*self->mode_func_ptr)(self);
228
static PyMemberDef Noise_members[] = {
229
{"server", T_OBJECT_EX, offsetof(Noise, server), 0, "Pyo server."},
230
{"stream", T_OBJECT_EX, offsetof(Noise, stream), 0, "Stream object."},
231
{"mul", T_OBJECT_EX, offsetof(Noise, mul), 0, "Mul factor."},
232
{"add", T_OBJECT_EX, offsetof(Noise, add), 0, "Add factor."},
233
{NULL} /* Sentinel */
236
static PyMethodDef Noise_methods[] = {
237
{"getServer", (PyCFunction)Noise_getServer, METH_NOARGS, "Returns server object."},
238
{"_getStream", (PyCFunction)Noise_getStream, METH_NOARGS, "Returns stream object."},
239
{"deleteStream", (PyCFunction)Noise_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
240
{"play", (PyCFunction)Noise_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
241
{"out", (PyCFunction)Noise_out, METH_VARARGS|METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
242
{"stop", (PyCFunction)Noise_stop, METH_NOARGS, "Stops computing."},
243
{"setType", (PyCFunction)Noise_setType, METH_O, "Sets Noise generation algorithm."},
244
{"setMul", (PyCFunction)Noise_setMul, METH_O, "Sets Noise mul factor."},
245
{"setAdd", (PyCFunction)Noise_setAdd, METH_O, "Sets Noise add factor."},
246
{"setSub", (PyCFunction)Noise_setSub, METH_O, "Sets inverse add factor."},
247
{"setDiv", (PyCFunction)Noise_setDiv, METH_O, "Sets inverse mul factor."},
248
{NULL} /* Sentinel */
251
static PyNumberMethods Noise_as_number = {
252
(binaryfunc)Noise_add, /*nb_add*/
253
(binaryfunc)Noise_sub, /*nb_subtract*/
254
(binaryfunc)Noise_multiply, /*nb_multiply*/
255
(binaryfunc)Noise_div, /*nb_divide*/
261
0, /*(unaryfunc)array_abs,*/
275
(binaryfunc)Noise_inplace_add, /*inplace_add*/
276
(binaryfunc)Noise_inplace_sub, /*inplace_subtract*/
277
(binaryfunc)Noise_inplace_multiply, /*inplace_multiply*/
278
(binaryfunc)Noise_inplace_div, /*inplace_divide*/
279
0, /*inplace_remainder*/
281
0, /*inplace_lshift*/
282
0, /*inplace_rshift*/
286
0, /*nb_floor_divide*/
287
0, /*nb_true_divide*/
288
0, /*nb_inplace_floor_divide*/
289
0, /*nb_inplace_true_divide*/
293
PyTypeObject NoiseType = {
294
PyObject_HEAD_INIT(NULL)
296
"_pyo.Noise_base", /*tp_name*/
297
sizeof(Noise), /*tp_basicsize*/
299
(destructor)Noise_dealloc, /*tp_dealloc*/
305
&Noise_as_number, /*tp_as_number*/
306
0, /*tp_as_sequence*/
314
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
315
"Noise objects. White noise generator.", /* tp_doc */
316
(traverseproc)Noise_traverse, /* tp_traverse */
317
(inquiry)Noise_clear, /* tp_clear */
318
0, /* tp_richcompare */
319
0, /* tp_weaklistoffset */
322
Noise_methods, /* tp_methods */
323
Noise_members, /* tp_members */
327
0, /* tp_descr_get */
328
0, /* tp_descr_set */
329
0, /* tp_dictoffset */
330
(initproc)Noise_init, /* tp_init */
332
Noise_new, /* tp_new */
348
PinkNoise_generate(PinkNoise *self) {
352
for (i=0; i<self->bufsize; i++) {
353
in = rand()/((MYFLT)(RAND_MAX)+1)*1.98-0.99;
354
self->c0 = self->c0 * 0.99886 + in * 0.0555179;
355
self->c1 = self->c1 * 0.99332 + in * 0.0750759;
356
self->c2 = self->c2 * 0.96900 + in * 0.1538520;
357
self->c3 = self->c3 * 0.86650 + in * 0.3104856;
358
self->c4 = self->c4 * 0.55000 + in * 0.5329522;
359
self->c5 = self->c5 * -0.7616 - in * 0.0168980;
360
val = self->c0 + self->c1 + self->c2 + self->c3 + self->c4 + self->c5 + self->c6 + in * 0.5362;
361
self->data[i] = val * 0.2;
362
self->c6 = in * 0.115926;
366
static void PinkNoise_postprocessing_ii(PinkNoise *self) { POST_PROCESSING_II };
367
static void PinkNoise_postprocessing_ai(PinkNoise *self) { POST_PROCESSING_AI };
368
static void PinkNoise_postprocessing_ia(PinkNoise *self) { POST_PROCESSING_IA };
369
static void PinkNoise_postprocessing_aa(PinkNoise *self) { POST_PROCESSING_AA };
370
static void PinkNoise_postprocessing_ireva(PinkNoise *self) { POST_PROCESSING_IREVA };
371
static void PinkNoise_postprocessing_areva(PinkNoise *self) { POST_PROCESSING_AREVA };
372
static void PinkNoise_postprocessing_revai(PinkNoise *self) { POST_PROCESSING_REVAI };
373
static void PinkNoise_postprocessing_revaa(PinkNoise *self) { POST_PROCESSING_REVAA };
374
static void PinkNoise_postprocessing_revareva(PinkNoise *self) { POST_PROCESSING_REVAREVA };
377
PinkNoise_setProcMode(PinkNoise *self)
380
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
382
switch (muladdmode) {
384
self->muladd_func_ptr = PinkNoise_postprocessing_ii;
387
self->muladd_func_ptr = PinkNoise_postprocessing_ai;
390
self->muladd_func_ptr = PinkNoise_postprocessing_revai;
393
self->muladd_func_ptr = PinkNoise_postprocessing_ia;
396
self->muladd_func_ptr = PinkNoise_postprocessing_aa;
399
self->muladd_func_ptr = PinkNoise_postprocessing_revaa;
402
self->muladd_func_ptr = PinkNoise_postprocessing_ireva;
405
self->muladd_func_ptr = PinkNoise_postprocessing_areva;
408
self->muladd_func_ptr = PinkNoise_postprocessing_revareva;
414
PinkNoise_compute_next_data_frame(PinkNoise *self)
416
PinkNoise_generate(self);
417
(*self->muladd_func_ptr)(self);
421
PinkNoise_traverse(PinkNoise *self, visitproc visit, void *arg)
428
PinkNoise_clear(PinkNoise *self)
435
PinkNoise_dealloc(PinkNoise* self)
438
PinkNoise_clear(self);
439
self->ob_type->tp_free((PyObject*)self);
442
static PyObject * PinkNoise_deleteStream(PinkNoise *self) { DELETE_STREAM };
445
PinkNoise_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
449
self = (PinkNoise *)type->tp_alloc(type, 0);
451
self->c0 = self->c1 = self->c2 = self->c3 = self->c4 = self->c5 = self->c6 = 0.0;
452
self->modebuffer[0] = 0;
453
self->modebuffer[1] = 0;
456
Stream_setFunctionPtr(self->stream, PinkNoise_compute_next_data_frame);
457
self->mode_func_ptr = PinkNoise_setProcMode;
459
return (PyObject *)self;
463
PinkNoise_init(PinkNoise *self, PyObject *args, PyObject *kwds)
465
PyObject *multmp=NULL, *addtmp=NULL;
467
static char *kwlist[] = {"mul", "add", NULL};
469
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, &multmp, &addtmp))
473
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
477
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
480
Py_INCREF(self->stream);
481
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
483
(*self->mode_func_ptr)(self);
485
Server_generateSeed((Server *)self->server, PINKNOISE_ID);
491
static PyObject * PinkNoise_getServer(PinkNoise* self) { GET_SERVER };
492
static PyObject * PinkNoise_getStream(PinkNoise* self) { GET_STREAM };
493
static PyObject * PinkNoise_setMul(PinkNoise *self, PyObject *arg) { SET_MUL };
494
static PyObject * PinkNoise_setAdd(PinkNoise *self, PyObject *arg) { SET_ADD };
495
static PyObject * PinkNoise_setSub(PinkNoise *self, PyObject *arg) { SET_SUB };
496
static PyObject * PinkNoise_setDiv(PinkNoise *self, PyObject *arg) { SET_DIV };
498
static PyObject * PinkNoise_play(PinkNoise *self, PyObject *args, PyObject *kwds) { PLAY };
499
static PyObject * PinkNoise_out(PinkNoise *self, PyObject *args, PyObject *kwds) { OUT };
500
static PyObject * PinkNoise_stop(PinkNoise *self) { STOP };
502
static PyObject * PinkNoise_multiply(PinkNoise *self, PyObject *arg) { MULTIPLY };
503
static PyObject * PinkNoise_inplace_multiply(PinkNoise *self, PyObject *arg) { INPLACE_MULTIPLY };
504
static PyObject * PinkNoise_add(PinkNoise *self, PyObject *arg) { ADD };
505
static PyObject * PinkNoise_inplace_add(PinkNoise *self, PyObject *arg) { INPLACE_ADD };
506
static PyObject * PinkNoise_sub(PinkNoise *self, PyObject *arg) { SUB };
507
static PyObject * PinkNoise_inplace_sub(PinkNoise *self, PyObject *arg) { INPLACE_SUB };
508
static PyObject * PinkNoise_div(PinkNoise *self, PyObject *arg) { DIV };
509
static PyObject * PinkNoise_inplace_div(PinkNoise *self, PyObject *arg) { INPLACE_DIV };
511
static PyMemberDef PinkNoise_members[] = {
512
{"server", T_OBJECT_EX, offsetof(PinkNoise, server), 0, "Pyo server."},
513
{"stream", T_OBJECT_EX, offsetof(PinkNoise, stream), 0, "Stream object."},
514
{"mul", T_OBJECT_EX, offsetof(PinkNoise, mul), 0, "Mul factor."},
515
{"add", T_OBJECT_EX, offsetof(PinkNoise, add), 0, "Add factor."},
516
{NULL} /* Sentinel */
519
static PyMethodDef PinkNoise_methods[] = {
520
{"getServer", (PyCFunction)PinkNoise_getServer, METH_NOARGS, "Returns server object."},
521
{"_getStream", (PyCFunction)PinkNoise_getStream, METH_NOARGS, "Returns stream object."},
522
{"deleteStream", (PyCFunction)PinkNoise_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
523
{"play", (PyCFunction)PinkNoise_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
524
{"out", (PyCFunction)PinkNoise_out, METH_VARARGS|METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
525
{"stop", (PyCFunction)PinkNoise_stop, METH_NOARGS, "Stops computing."},
526
{"setMul", (PyCFunction)PinkNoise_setMul, METH_O, "Sets PinkNoise mul factor."},
527
{"setAdd", (PyCFunction)PinkNoise_setAdd, METH_O, "Sets PinkNoise add factor."},
528
{"setSub", (PyCFunction)PinkNoise_setSub, METH_O, "Sets inverse add factor."},
529
{"setDiv", (PyCFunction)PinkNoise_setDiv, METH_O, "Sets inverse mul factor."},
530
{NULL} /* Sentinel */
533
static PyNumberMethods PinkNoise_as_number = {
534
(binaryfunc)PinkNoise_add, /*nb_add*/
535
(binaryfunc)PinkNoise_sub, /*nb_subtract*/
536
(binaryfunc)PinkNoise_multiply, /*nb_multiply*/
537
(binaryfunc)PinkNoise_div, /*nb_divide*/
543
0, /*(unaryfunc)array_abs,*/
557
(binaryfunc)PinkNoise_inplace_add, /*inplace_add*/
558
(binaryfunc)PinkNoise_inplace_sub, /*inplace_subtract*/
559
(binaryfunc)PinkNoise_inplace_multiply, /*inplace_multiply*/
560
(binaryfunc)PinkNoise_inplace_div, /*inplace_divide*/
561
0, /*inplace_remainder*/
563
0, /*inplace_lshift*/
564
0, /*inplace_rshift*/
568
0, /*nb_floor_divide*/
569
0, /*nb_true_divide*/
570
0, /*nb_inplace_floor_divide*/
571
0, /*nb_inplace_true_divide*/
575
PyTypeObject PinkNoiseType = {
576
PyObject_HEAD_INIT(NULL)
578
"_pyo.PinkNoise_base", /*tp_name*/
579
sizeof(PinkNoise), /*tp_basicsize*/
581
(destructor)PinkNoise_dealloc, /*tp_dealloc*/
587
&PinkNoise_as_number, /*tp_as_number*/
588
0, /*tp_as_sequence*/
596
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
597
"PinkNoise objects. Pink noise generator.", /* tp_doc */
598
(traverseproc)PinkNoise_traverse, /* tp_traverse */
599
(inquiry)PinkNoise_clear, /* tp_clear */
600
0, /* tp_richcompare */
601
0, /* tp_weaklistoffset */
604
PinkNoise_methods, /* tp_methods */
605
PinkNoise_members, /* tp_members */
609
0, /* tp_descr_get */
610
0, /* tp_descr_set */
611
0, /* tp_dictoffset */
612
(initproc)PinkNoise_init, /* tp_init */
614
PinkNoise_new, /* tp_new */
626
BrownNoise_generate(BrownNoise *self) {
630
for (i=0; i<self->bufsize; i++) {
631
rnd = rand()/((MYFLT)(RAND_MAX)+1)*1.98-0.99;
632
val = self->c1 * rnd + self->c2 * self->y1;
634
self->data[i] = val * 20.0; /* gain compensation */
638
static void BrownNoise_postprocessing_ii(BrownNoise *self) { POST_PROCESSING_II };
639
static void BrownNoise_postprocessing_ai(BrownNoise *self) { POST_PROCESSING_AI };
640
static void BrownNoise_postprocessing_ia(BrownNoise *self) { POST_PROCESSING_IA };
641
static void BrownNoise_postprocessing_aa(BrownNoise *self) { POST_PROCESSING_AA };
642
static void BrownNoise_postprocessing_ireva(BrownNoise *self) { POST_PROCESSING_IREVA };
643
static void BrownNoise_postprocessing_areva(BrownNoise *self) { POST_PROCESSING_AREVA };
644
static void BrownNoise_postprocessing_revai(BrownNoise *self) { POST_PROCESSING_REVAI };
645
static void BrownNoise_postprocessing_revaa(BrownNoise *self) { POST_PROCESSING_REVAA };
646
static void BrownNoise_postprocessing_revareva(BrownNoise *self) { POST_PROCESSING_REVAREVA };
649
BrownNoise_setProcMode(BrownNoise *self)
652
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
654
switch (muladdmode) {
656
self->muladd_func_ptr = BrownNoise_postprocessing_ii;
659
self->muladd_func_ptr = BrownNoise_postprocessing_ai;
662
self->muladd_func_ptr = BrownNoise_postprocessing_revai;
665
self->muladd_func_ptr = BrownNoise_postprocessing_ia;
668
self->muladd_func_ptr = BrownNoise_postprocessing_aa;
671
self->muladd_func_ptr = BrownNoise_postprocessing_revaa;
674
self->muladd_func_ptr = BrownNoise_postprocessing_ireva;
677
self->muladd_func_ptr = BrownNoise_postprocessing_areva;
680
self->muladd_func_ptr = BrownNoise_postprocessing_revareva;
686
BrownNoise_compute_next_data_frame(BrownNoise *self)
688
BrownNoise_generate(self);
689
(*self->muladd_func_ptr)(self);
693
BrownNoise_traverse(BrownNoise *self, visitproc visit, void *arg)
700
BrownNoise_clear(BrownNoise *self)
707
BrownNoise_dealloc(BrownNoise* self)
710
BrownNoise_clear(self);
711
self->ob_type->tp_free((PyObject*)self);
714
static PyObject * BrownNoise_deleteStream(BrownNoise *self) { DELETE_STREAM };
717
BrownNoise_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
721
self = (BrownNoise *)type->tp_alloc(type, 0);
723
self->modebuffer[0] = 0;
724
self->modebuffer[1] = 0;
725
self->y1 = self->c1 = self->c2 = 0.0;
728
Stream_setFunctionPtr(self->stream, BrownNoise_compute_next_data_frame);
729
self->mode_func_ptr = BrownNoise_setProcMode;
731
return (PyObject *)self;
735
BrownNoise_init(BrownNoise *self, PyObject *args, PyObject *kwds)
738
PyObject *multmp=NULL, *addtmp=NULL;
740
static char *kwlist[] = {"mul", "add", NULL};
742
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, &multmp, &addtmp))
746
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
750
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
753
Py_INCREF(self->stream);
754
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
756
b = 2.0 - MYCOS(TWOPI * 20.0 / self->sr);
757
self->c2 = (b - MYSQRT(b * b - 1.0));
758
self->c1 = 1.0 - self->c2;
760
(*self->mode_func_ptr)(self);
762
Server_generateSeed((Server *)self->server, BROWNNOISE_ID);
768
static PyObject * BrownNoise_getServer(BrownNoise* self) { GET_SERVER };
769
static PyObject * BrownNoise_getStream(BrownNoise* self) { GET_STREAM };
770
static PyObject * BrownNoise_setMul(BrownNoise *self, PyObject *arg) { SET_MUL };
771
static PyObject * BrownNoise_setAdd(BrownNoise *self, PyObject *arg) { SET_ADD };
772
static PyObject * BrownNoise_setSub(BrownNoise *self, PyObject *arg) { SET_SUB };
773
static PyObject * BrownNoise_setDiv(BrownNoise *self, PyObject *arg) { SET_DIV };
775
static PyObject * BrownNoise_play(BrownNoise *self, PyObject *args, PyObject *kwds) { PLAY };
776
static PyObject * BrownNoise_out(BrownNoise *self, PyObject *args, PyObject *kwds) { OUT };
777
static PyObject * BrownNoise_stop(BrownNoise *self) { STOP };
779
static PyObject * BrownNoise_multiply(BrownNoise *self, PyObject *arg) { MULTIPLY };
780
static PyObject * BrownNoise_inplace_multiply(BrownNoise *self, PyObject *arg) { INPLACE_MULTIPLY };
781
static PyObject * BrownNoise_add(BrownNoise *self, PyObject *arg) { ADD };
782
static PyObject * BrownNoise_inplace_add(BrownNoise *self, PyObject *arg) { INPLACE_ADD };
783
static PyObject * BrownNoise_sub(BrownNoise *self, PyObject *arg) { SUB };
784
static PyObject * BrownNoise_inplace_sub(BrownNoise *self, PyObject *arg) { INPLACE_SUB };
785
static PyObject * BrownNoise_div(BrownNoise *self, PyObject *arg) { DIV };
786
static PyObject * BrownNoise_inplace_div(BrownNoise *self, PyObject *arg) { INPLACE_DIV };
788
static PyMemberDef BrownNoise_members[] = {
789
{"server", T_OBJECT_EX, offsetof(BrownNoise, server), 0, "Pyo server."},
790
{"stream", T_OBJECT_EX, offsetof(BrownNoise, stream), 0, "Stream object."},
791
{"mul", T_OBJECT_EX, offsetof(BrownNoise, mul), 0, "Mul factor."},
792
{"add", T_OBJECT_EX, offsetof(BrownNoise, add), 0, "Add factor."},
793
{NULL} /* Sentinel */
796
static PyMethodDef BrownNoise_methods[] = {
797
{"getServer", (PyCFunction)BrownNoise_getServer, METH_NOARGS, "Returns server object."},
798
{"_getStream", (PyCFunction)BrownNoise_getStream, METH_NOARGS, "Returns stream object."},
799
{"deleteStream", (PyCFunction)BrownNoise_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
800
{"play", (PyCFunction)BrownNoise_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
801
{"out", (PyCFunction)BrownNoise_out, METH_VARARGS|METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
802
{"stop", (PyCFunction)BrownNoise_stop, METH_NOARGS, "Stops computing."},
803
{"setMul", (PyCFunction)BrownNoise_setMul, METH_O, "Sets BrownNoise mul factor."},
804
{"setAdd", (PyCFunction)BrownNoise_setAdd, METH_O, "Sets BrownNoise add factor."},
805
{"setSub", (PyCFunction)BrownNoise_setSub, METH_O, "Sets inverse add factor."},
806
{"setDiv", (PyCFunction)BrownNoise_setDiv, METH_O, "Sets inverse mul factor."},
807
{NULL} /* Sentinel */
810
static PyNumberMethods BrownNoise_as_number = {
811
(binaryfunc)BrownNoise_add, /*nb_add*/
812
(binaryfunc)BrownNoise_sub, /*nb_subtract*/
813
(binaryfunc)BrownNoise_multiply, /*nb_multiply*/
814
(binaryfunc)BrownNoise_div, /*nb_divide*/
820
0, /*(unaryfunc)array_abs,*/
834
(binaryfunc)BrownNoise_inplace_add, /*inplace_add*/
835
(binaryfunc)BrownNoise_inplace_sub, /*inplace_subtract*/
836
(binaryfunc)BrownNoise_inplace_multiply, /*inplace_multiply*/
837
(binaryfunc)BrownNoise_inplace_div, /*inplace_divide*/
838
0, /*inplace_remainder*/
840
0, /*inplace_lshift*/
841
0, /*inplace_rshift*/
845
0, /*nb_floor_divide*/
846
0, /*nb_true_divide*/
847
0, /*nb_inplace_floor_divide*/
848
0, /*nb_inplace_true_divide*/
852
PyTypeObject BrownNoiseType = {
853
PyObject_HEAD_INIT(NULL)
855
"_pyo.BrownNoise_base", /*tp_name*/
856
sizeof(BrownNoise), /*tp_basicsize*/
858
(destructor)BrownNoise_dealloc, /*tp_dealloc*/
864
&BrownNoise_as_number, /*tp_as_number*/
865
0, /*tp_as_sequence*/
873
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
874
"BrownNoise objects. Brown noise generator (-6dB/octave rolloff).", /* tp_doc */
875
(traverseproc)BrownNoise_traverse, /* tp_traverse */
876
(inquiry)BrownNoise_clear, /* tp_clear */
877
0, /* tp_richcompare */
878
0, /* tp_weaklistoffset */
881
BrownNoise_methods, /* tp_methods */
882
BrownNoise_members, /* tp_members */
886
0, /* tp_descr_get */
887
0, /* tp_descr_set */
888
0, /* tp_dictoffset */
889
(initproc)BrownNoise_init, /* tp_init */
891
BrownNoise_new, /* tp_new */