~ubuntu-branches/ubuntu/saucy/python-pyo/saucy-proposed

« back to all changes in this revision

Viewing changes to src/objects/utilsmodule.c

  • Committer: Package Import Robot
  • Author(s): Tiago Bortoletto Vaz
  • Date: 2012-06-08 20:35:45 UTC
  • Revision ID: package-import@ubuntu.com-20120608203545-4z7kcf2lgvpsk18y
Tags: upstream-0.6.1
ImportĀ upstreamĀ versionĀ 0.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*************************************************************************
 
2
 * Copyright 2010 Olivier Belanger                                        *                  
 
3
 *                                                                        * 
 
4
 * This file is part of pyo, a python module to help digital signal       *
 
5
 * processing script creation.                                            *  
 
6
 *                                                                        * 
 
7
 * pyo is free software: you can redistribute it and/or modify            *
 
8
 * it under the terms of the GNU 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.                                    * 
 
11
 *                                                                        *
 
12
 * pyo is distributed in the hope that it will be useful,                 *
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of         *    
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 
15
 * GNU General Public License for more details.                           *
 
16
 *                                                                        *
 
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
 *************************************************************************/
 
20
 
 
21
#include <Python.h>
 
22
#include "structmember.h"
 
23
#include <math.h>
 
24
#include "pyomodule.h"
 
25
#include "streammodule.h"
 
26
#include "servermodule.h"
 
27
#include "dummymodule.h"
 
28
 
 
29
/************/
 
30
/* Print */
 
31
/************/
 
32
typedef struct {
 
33
    pyo_audio_HEAD
 
34
    PyObject *input;
 
35
    Stream *input_stream;
 
36
    char *message;
 
37
    int method; // 0 -> interval, 1 -> change
 
38
    MYFLT lastValue;
 
39
    MYFLT time;
 
40
    MYFLT currentTime;
 
41
    MYFLT sampleToSec;
 
42
} Print;
 
43
 
 
44
static void
 
45
Print_process_time(Print *self) {
 
46
    int i;
 
47
    MYFLT *in = Stream_getData((Stream *)self->input_stream);
 
48
    
 
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]);
 
54
            else
 
55
                printf("%s : %f\n", self->message, in[i]);
 
56
        }
 
57
        self->currentTime += self->sampleToSec;
 
58
    }
 
59
}
 
60
 
 
61
static void
 
62
Print_process_change(Print *self) {
 
63
    int i;
 
64
    MYFLT inval;
 
65
    MYFLT *in = Stream_getData((Stream *)self->input_stream);
 
66
 
 
67
    for (i=0; i<self->bufsize; i++) {
 
68
        inval = in[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);
 
72
            else
 
73
                printf("%s : %f\n", self->message, inval);
 
74
            self->lastValue = inval;
 
75
        }
 
76
    }    
 
77
}
 
78
 
 
79
static void
 
80
Print_setProcMode(Print *self)
 
81
{    
 
82
    if (self->method < 0 || self->method > 1)
 
83
        self->method = 0;
 
84
        
 
85
    switch (self->method) {
 
86
        case 0:
 
87
            self->proc_func_ptr = Print_process_time;
 
88
            break;
 
89
        case 1:
 
90
            self->proc_func_ptr = Print_process_change;
 
91
            break;
 
92
    }        
 
93
}
 
94
 
 
95
static void
 
96
Print_compute_next_data_frame(Print *self)
 
97
{
 
98
    (*self->proc_func_ptr)(self); 
 
99
}
 
100
 
 
101
static int
 
102
Print_traverse(Print *self, visitproc visit, void *arg)
 
103
{
 
104
    pyo_VISIT
 
105
    Py_VISIT(self->input);
 
106
    Py_VISIT(self->input_stream);
 
107
    return 0;
 
108
}
 
109
 
 
110
static int 
 
111
Print_clear(Print *self)
 
112
{
 
113
    pyo_CLEAR
 
114
    Py_CLEAR(self->input);
 
115
    Py_CLEAR(self->input_stream);
 
116
    return 0;
 
117
}
 
118
 
 
119
static void
 
120
Print_dealloc(Print* self)
 
121
{
 
122
    free(self->data);
 
123
    Print_clear(self);
 
124
    self->ob_type->tp_free((PyObject*)self);
 
125
}
 
126
 
 
127
static PyObject * Print_deleteStream(Print *self) { DELETE_STREAM };
 
128
 
 
129
static PyObject *
 
130
Print_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
131
{
 
132
    int i;
 
133
    Print *self;
 
134
    self = (Print *)type->tp_alloc(type, 0);
 
135
 
 
136
    self->method = 0;
 
137
    self->time = 0.25;
 
138
    self->lastValue = -99999.0;
 
139
    
 
140
    INIT_OBJECT_COMMON
 
141
    Stream_setFunctionPtr(self->stream, Print_compute_next_data_frame);
 
142
    self->mode_func_ptr = Print_setProcMode;
 
143
 
 
144
    self->sampleToSec = 1. / self->sr;
 
145
    self->currentTime = 0.;
 
146
    
 
147
    return (PyObject *)self;
 
148
}
 
149
 
 
150
static int
 
151
Print_init(Print *self, PyObject *args, PyObject *kwds)
 
152
{
 
153
    PyObject *inputtmp, *input_streamtmp;
 
154
    
 
155
    static char *kwlist[] = {"input", "method", "interval", "message", NULL};
 
156
    
 
157
    if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_O_IFS, kwlist, &inputtmp, &self->method, &self->time, &self->message))
 
158
        return -1; 
 
159
    
 
160
    INIT_INPUT_STREAM
 
161
 
 
162
    Py_INCREF(self->stream);
 
163
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
 
164
    
 
165
    (*self->mode_func_ptr)(self);
 
166
        
 
167
    Py_INCREF(self);
 
168
    return 0;
 
169
}
 
170
 
 
171
static PyObject * Print_getServer(Print* self) { GET_SERVER };
 
172
static PyObject * Print_getStream(Print* self) { GET_STREAM };
 
173
 
 
174
static PyObject * Print_play(Print *self, PyObject *args, PyObject *kwds) { PLAY };
 
175
static PyObject * Print_stop(Print *self) { STOP };
 
176
 
 
177
static PyObject *
 
178
Print_setMethod(Print *self, PyObject *arg)
 
179
{
 
180
        if (arg == NULL) {
 
181
                Py_INCREF(Py_None);
 
182
                return Py_None;
 
183
        }
 
184
    
 
185
        int isNumber = PyNumber_Check(arg);
 
186
        
 
187
        if (isNumber == 1) {
 
188
                self->method = PyInt_AsLong(arg);
 
189
        (*self->mode_func_ptr)(self);
 
190
        }
 
191
    
 
192
        Py_INCREF(Py_None);
 
193
        return Py_None;
 
194
}
 
195
 
 
196
static PyObject *
 
197
Print_setInterval(Print *self, PyObject *arg)
 
198
{
 
199
        if (arg == NULL) {
 
200
                Py_INCREF(Py_None);
 
201
                return Py_None;
 
202
        }
 
203
    
 
204
        int isNumber = PyNumber_Check(arg);
 
205
        
 
206
        if (isNumber == 1) {
 
207
                self->time = PyFloat_AS_DOUBLE(PyNumber_Float(arg));
 
208
        }
 
209
    
 
210
        Py_INCREF(Py_None);
 
211
        return Py_None;
 
212
}
 
213
 
 
214
static PyObject *
 
215
Print_setMessage(Print *self, PyObject *arg)
 
216
{
 
217
        if (arg == NULL) {
 
218
                Py_INCREF(Py_None);
 
219
                return Py_None;
 
220
        }
 
221
    
 
222
        int isString = PyString_Check(arg);
 
223
        
 
224
        if (isString == 1) {
 
225
                self->message = PyString_AsString(arg);
 
226
        }
 
227
    
 
228
        Py_INCREF(Py_None);
 
229
        return Py_None;
 
230
}
 
231
 
 
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 */
 
237
};
 
238
 
 
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 */
 
249
};
 
250
 
 
251
PyTypeObject PrintType = {
 
252
PyObject_HEAD_INIT(NULL)
 
253
0,                                              /*ob_size*/
 
254
"_pyo.Print_base",                                   /*tp_name*/
 
255
sizeof(Print),                                 /*tp_basicsize*/
 
256
0,                                              /*tp_itemsize*/
 
257
(destructor)Print_dealloc,                     /*tp_dealloc*/
 
258
0,                                              /*tp_print*/
 
259
0,                                              /*tp_getattr*/
 
260
0,                                              /*tp_setattr*/
 
261
0,                                              /*tp_compare*/
 
262
0,                                              /*tp_repr*/
 
263
0,                                              /*tp_as_number*/
 
264
0,                                              /*tp_as_sequence*/
 
265
0,                                              /*tp_as_mapping*/
 
266
0,                                              /*tp_hash */
 
267
0,                                              /*tp_call*/
 
268
0,                                              /*tp_str*/
 
269
0,                                              /*tp_getattro*/
 
270
0,                                              /*tp_setattro*/
 
271
0,                                              /*tp_as_buffer*/
 
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 */
 
278
0,                                              /* tp_iter */
 
279
0,                                              /* tp_iternext */
 
280
Print_methods,                                 /* tp_methods */
 
281
Print_members,                                 /* tp_members */
 
282
0,                                              /* tp_getset */
 
283
0,                                              /* tp_base */
 
284
0,                                              /* tp_dict */
 
285
0,                                              /* tp_descr_get */
 
286
0,                                              /* tp_descr_set */
 
287
0,                                              /* tp_dictoffset */
 
288
(initproc)Print_init,                          /* tp_init */
 
289
0,                                              /* tp_alloc */
 
290
Print_new,                                     /* tp_new */
 
291
};
 
292
 
 
293
/*********************************************************************************************/
 
294
/* Snap ********************************************************************************/
 
295
/*********************************************************************************************/
 
296
typedef struct {
 
297
    pyo_audio_HEAD
 
298
    PyObject *input;
 
299
    Stream *input_stream;
 
300
    int scale; // 0 = Midi, 1 = frequency, 2 = transpo
 
301
    int chSize;
 
302
    int highbound;
 
303
    MYFLT *choice;
 
304
    MYFLT value;
 
305
    MYFLT last_input;
 
306
    int modebuffer[2]; // need at least 2 slots for mul & add 
 
307
} Snap;
 
308
 
 
309
static MYFLT
 
310
Snap_convert(Snap *self) {
 
311
    int midival;
 
312
    MYFLT val;
 
313
    
 
314
    midival = self->value;
 
315
 
 
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);
 
320
    else
 
321
        val = midival;
 
322
    
 
323
    return val;
 
324
}
 
325
 
 
326
static void
 
327
Snap_generate(Snap *self) {
 
328
    int i, j, pos;
 
329
    MYFLT intmp, diff, difftmp;
 
330
    MYFLT *in = Stream_getData((Stream *)self->input_stream);
 
331
    
 
332
    for (i=0; i<self->bufsize; i++) {
 
333
        if (in[i] < (self->last_input-0.001) || in[i] > (self->last_input + 0.001)) {
 
334
            int oct = 0;
 
335
            self->last_input = intmp = in[i];
 
336
            while (intmp >= self->highbound) {
 
337
                oct++;
 
338
                intmp -= self->highbound;
 
339
            }
 
340
            diff = MYFABS(self->choice[0]-intmp);
 
341
            pos = 0;
 
342
            for (j=1; j<self->chSize; j++) {
 
343
                difftmp = MYFABS(self->choice[j]-intmp);
 
344
                if (difftmp < diff) {
 
345
                    diff = difftmp;
 
346
                    pos = j;
 
347
                }    
 
348
            }
 
349
            self->value = self->choice[pos] + (self->highbound * oct);
 
350
            self->value = Snap_convert(self);  
 
351
        }
 
352
     
 
353
        self->data[i] = self->value;
 
354
    }
 
355
}
 
356
 
 
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 };
 
366
 
 
367
static void
 
368
Snap_setProcMode(Snap *self)
 
369
{
 
370
    int muladdmode;
 
371
    muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
 
372
    
 
373
    self->proc_func_ptr = Snap_generate;
 
374
    
 
375
        switch (muladdmode) {
 
376
        case 0:        
 
377
            self->muladd_func_ptr = Snap_postprocessing_ii;
 
378
            break;
 
379
        case 1:    
 
380
            self->muladd_func_ptr = Snap_postprocessing_ai;
 
381
            break;
 
382
        case 2:    
 
383
            self->muladd_func_ptr = Snap_postprocessing_revai;
 
384
            break;
 
385
        case 10:        
 
386
            self->muladd_func_ptr = Snap_postprocessing_ia;
 
387
            break;
 
388
        case 11:    
 
389
            self->muladd_func_ptr = Snap_postprocessing_aa;
 
390
            break;
 
391
        case 12:    
 
392
            self->muladd_func_ptr = Snap_postprocessing_revaa;
 
393
            break;
 
394
        case 20:        
 
395
            self->muladd_func_ptr = Snap_postprocessing_ireva;
 
396
            break;
 
397
        case 21:    
 
398
            self->muladd_func_ptr = Snap_postprocessing_areva;
 
399
            break;
 
400
        case 22:    
 
401
            self->muladd_func_ptr = Snap_postprocessing_revareva;
 
402
            break;
 
403
    }  
 
404
}
 
405
 
 
406
static void
 
407
Snap_compute_next_data_frame(Snap *self)
 
408
{
 
409
    (*self->proc_func_ptr)(self); 
 
410
    (*self->muladd_func_ptr)(self);
 
411
}
 
412
 
 
413
static int
 
414
Snap_traverse(Snap *self, visitproc visit, void *arg)
 
415
{
 
416
    pyo_VISIT
 
417
    Py_VISIT(self->input);
 
418
    Py_VISIT(self->input_stream);
 
419
    return 0;
 
420
}
 
421
 
 
422
static int 
 
423
Snap_clear(Snap *self)
 
424
{
 
425
    pyo_CLEAR
 
426
    Py_CLEAR(self->input);
 
427
    Py_CLEAR(self->input_stream);
 
428
    return 0;
 
429
}
 
430
 
 
431
static void
 
432
Snap_dealloc(Snap* self)
 
433
{
 
434
    free(self->data);
 
435
    free(self->choice);
 
436
    Snap_clear(self);
 
437
    self->ob_type->tp_free((PyObject*)self);
 
438
}
 
439
 
 
440
static PyObject * Snap_deleteStream(Snap *self) { DELETE_STREAM };
 
441
 
 
442
static PyObject *
 
443
Snap_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
444
{
 
445
    int i;
 
446
    Snap *self;
 
447
    self = (Snap *)type->tp_alloc(type, 0);
 
448
    
 
449
    self->value = self->last_input = 0.;
 
450
    self->scale = 0;
 
451
    self->highbound = 12;
 
452
    self->modebuffer[0] = 0;
 
453
    self->modebuffer[1] = 0;
 
454
    
 
455
    INIT_OBJECT_COMMON
 
456
    Stream_setFunctionPtr(self->stream, Snap_compute_next_data_frame);
 
457
    self->mode_func_ptr = Snap_setProcMode;
 
458
    return (PyObject *)self;
 
459
}
 
460
 
 
461
static int
 
462
Snap_init(Snap *self, PyObject *args, PyObject *kwds)
 
463
{
 
464
    PyObject *inputtmp, *input_streamtmp, *choicetmp=NULL, *multmp=NULL, *addtmp=NULL;
 
465
    
 
466
    static char *kwlist[] = {"input", "choice", "scale", "mul", "add", NULL};
 
467
    
 
468
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|iOO", kwlist, &inputtmp, &choicetmp, &self->scale, &multmp, &addtmp))
 
469
        return -1; 
 
470
    
 
471
    INIT_INPUT_STREAM
 
472
    
 
473
    if (choicetmp) {
 
474
        PyObject_CallMethod((PyObject *)self, "setChoice", "O", choicetmp);
 
475
    }
 
476
    
 
477
    if (multmp) {
 
478
        PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
 
479
    }
 
480
    
 
481
    if (addtmp) {
 
482
        PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
 
483
    }
 
484
    
 
485
    Py_INCREF(self->stream);
 
486
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
 
487
 
 
488
    (*self->mode_func_ptr)(self);
 
489
        
 
490
    Py_INCREF(self);
 
491
    return 0;
 
492
}
 
493
 
 
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 };   
 
500
 
 
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 };
 
504
 
 
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 };
 
513
 
 
514
static PyObject *
 
515
Snap_setChoice(Snap *self, PyObject *arg)
 
516
{
 
517
    int i, oct;
 
518
    MYFLT max;
 
519
        PyObject *tmp;
 
520
        
 
521
        if (! PyList_Check(arg)) {
 
522
        PyErr_SetString(PyExc_TypeError, "The choice attribute must be a list.");
 
523
                Py_INCREF(Py_None);
 
524
                return Py_None;
 
525
        }
 
526
    
 
527
    tmp = arg;
 
528
    self->chSize = PyList_Size(tmp);
 
529
    self->choice = (MYFLT *)realloc(self->choice, self->chSize * sizeof(MYFLT));
 
530
    
 
531
    for (i=0; i<self->chSize; i++) {
 
532
        self->choice[i] = PyFloat_AS_DOUBLE(PyNumber_Float(PyList_GET_ITEM(tmp, i)));
 
533
    }
 
534
    
 
535
    max = self->choice[self->chSize-1];
 
536
    
 
537
    oct = 12;
 
538
    while (max >= oct) {
 
539
        oct += 12;
 
540
    }
 
541
    
 
542
    self->highbound = oct;
 
543
    
 
544
    (*self->mode_func_ptr)(self);
 
545
    
 
546
        Py_INCREF(Py_None);
 
547
        return Py_None;
 
548
}       
 
549
 
 
550
static PyObject *
 
551
Snap_setScale(Snap *self, PyObject *arg)
 
552
{       
 
553
    int tmp;
 
554
        if (arg == NULL) {
 
555
                Py_INCREF(Py_None);
 
556
                return Py_None;
 
557
        }
 
558
    
 
559
        int isNumber = PyInt_Check(arg);
 
560
        
 
561
        if (isNumber == 1) {
 
562
                tmp = PyInt_AsLong(arg);
 
563
        if (tmp >= 0 && tmp <= 2)
 
564
            self->scale = tmp;
 
565
        else
 
566
            printf("scale attribute must be an integer {0, 1, 2}\n");
 
567
        }
 
568
    
 
569
        Py_INCREF(Py_None);
 
570
        return Py_None;
 
571
}       
 
572
 
 
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 */
 
580
};
 
581
 
 
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 */
 
596
};
 
597
 
 
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*/
 
603
    0,                                              /*nb_remainder*/
 
604
    0,                                              /*nb_divmod*/
 
605
    0,                                              /*nb_power*/
 
606
    0,                                              /*nb_neg*/
 
607
    0,                                              /*nb_pos*/
 
608
    0,                                              /*(unaryfunc)array_abs,*/
 
609
    0,                                              /*nb_nonzero*/
 
610
    0,                                              /*nb_invert*/
 
611
    0,                                              /*nb_lshift*/
 
612
    0,                                              /*nb_rshift*/
 
613
    0,                                              /*nb_and*/
 
614
    0,                                              /*nb_xor*/
 
615
    0,                                              /*nb_or*/
 
616
    0,                                              /*nb_coerce*/
 
617
    0,                                              /*nb_int*/
 
618
    0,                                              /*nb_long*/
 
619
    0,                                              /*nb_float*/
 
620
    0,                                              /*nb_oct*/
 
621
    0,                                              /*nb_hex*/
 
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*/
 
627
    0,                                              /*inplace_power*/
 
628
    0,                                              /*inplace_lshift*/
 
629
    0,                                              /*inplace_rshift*/
 
630
    0,                                              /*inplace_and*/
 
631
    0,                                              /*inplace_xor*/
 
632
    0,                                              /*inplace_or*/
 
633
    0,                                              /*nb_floor_divide*/
 
634
    0,                                              /*nb_true_divide*/
 
635
    0,                                              /*nb_inplace_floor_divide*/
 
636
    0,                                              /*nb_inplace_true_divide*/
 
637
    0,                                              /* nb_index */
 
638
};
 
639
 
 
640
PyTypeObject SnapType = {
 
641
    PyObject_HEAD_INIT(NULL)
 
642
    0,                                              /*ob_size*/
 
643
    "_pyo.Snap_base",                                   /*tp_name*/
 
644
    sizeof(Snap),                                 /*tp_basicsize*/
 
645
    0,                                              /*tp_itemsize*/
 
646
    (destructor)Snap_dealloc,                     /*tp_dealloc*/
 
647
    0,                                              /*tp_print*/
 
648
    0,                                              /*tp_getattr*/
 
649
    0,                                              /*tp_setattr*/
 
650
    0,                                              /*tp_compare*/
 
651
    0,                                              /*tp_repr*/
 
652
    &Snap_as_number,                              /*tp_as_number*/
 
653
    0,                                              /*tp_as_sequence*/
 
654
    0,                                              /*tp_as_mapping*/
 
655
    0,                                              /*tp_hash */
 
656
    0,                                              /*tp_call*/
 
657
    0,                                              /*tp_str*/
 
658
    0,                                              /*tp_getattro*/
 
659
    0,                                              /*tp_setattro*/
 
660
    0,                                              /*tp_as_buffer*/
 
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 */
 
667
    0,                                              /* tp_iter */
 
668
    0,                                              /* tp_iternext */
 
669
    Snap_methods,                                 /* tp_methods */
 
670
    Snap_members,                                 /* tp_members */
 
671
    0,                                              /* tp_getset */
 
672
    0,                                              /* tp_base */
 
673
    0,                                              /* tp_dict */
 
674
    0,                                              /* tp_descr_get */
 
675
    0,                                              /* tp_descr_set */
 
676
    0,                                              /* tp_dictoffset */
 
677
    (initproc)Snap_init,                          /* tp_init */
 
678
    0,                                              /* tp_alloc */
 
679
    Snap_new,                                     /* tp_new */
 
680
};
 
681
 
 
682
/************/
 
683
/* Interp */
 
684
/************/
 
685
typedef struct {
 
686
    pyo_audio_HEAD
 
687
    PyObject *input;
 
688
    Stream *input_stream;
 
689
    PyObject *input2;
 
690
    Stream *input2_stream;
 
691
    PyObject *interp;
 
692
    Stream *interp_stream;
 
693
    int modebuffer[3]; // need at least 2 slots for mul & add 
 
694
} Interp;
 
695
 
 
696
static void
 
697
Interp_filters_i(Interp *self) {
 
698
    MYFLT amp2;
 
699
    int i;
 
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);
 
703
 
 
704
    if (inter < 0.0)
 
705
        inter = 0.0;
 
706
    else if (inter > 1.0)
 
707
        inter = 1.0;
 
708
    
 
709
    amp2 = 1.0 - inter; 
 
710
    for (i=0; i<self->bufsize; i++) {
 
711
        self->data[i] = in[i] * amp2 + in2[i] * inter;
 
712
    }
 
713
}
 
714
 
 
715
static void
 
716
Interp_filters_a(Interp *self) {
 
717
    MYFLT amp1, amp2;
 
718
    int i;
 
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);
 
722
    
 
723
    for (i=0; i<self->bufsize; i++) {
 
724
        amp1 = inter[i];
 
725
        if (amp1 < 0.0)
 
726
            amp1 = 0.0;
 
727
        else if (amp1 > 1.0)
 
728
            amp1 = 1.0;
 
729
        
 
730
        amp2 = 1.0 - amp1; 
 
731
        self->data[i] = in[i] * amp2 + in2[i] * amp1;
 
732
    }
 
733
}
 
734
 
 
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 };
 
744
 
 
745
static void
 
746
Interp_setProcMode(Interp *self)
 
747
{
 
748
    int procmode, muladdmode;
 
749
    procmode = self->modebuffer[2];
 
750
    muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
 
751
    
 
752
        switch (procmode) {
 
753
        case 0:    
 
754
            self->proc_func_ptr = Interp_filters_i;
 
755
            break;
 
756
        case 1:    
 
757
            self->proc_func_ptr = Interp_filters_a;
 
758
            break;
 
759
    } 
 
760
        switch (muladdmode) {
 
761
        case 0:        
 
762
            self->muladd_func_ptr = Interp_postprocessing_ii;
 
763
            break;
 
764
        case 1:    
 
765
            self->muladd_func_ptr = Interp_postprocessing_ai;
 
766
            break;
 
767
        case 2:    
 
768
            self->muladd_func_ptr = Interp_postprocessing_revai;
 
769
            break;
 
770
        case 10:        
 
771
            self->muladd_func_ptr = Interp_postprocessing_ia;
 
772
            break;
 
773
        case 11:    
 
774
            self->muladd_func_ptr = Interp_postprocessing_aa;
 
775
            break;
 
776
        case 12:    
 
777
            self->muladd_func_ptr = Interp_postprocessing_revaa;
 
778
            break;
 
779
        case 20:        
 
780
            self->muladd_func_ptr = Interp_postprocessing_ireva;
 
781
            break;
 
782
        case 21:    
 
783
            self->muladd_func_ptr = Interp_postprocessing_areva;
 
784
            break;
 
785
        case 22:    
 
786
            self->muladd_func_ptr = Interp_postprocessing_revareva;
 
787
            break;
 
788
    }   
 
789
}
 
790
 
 
791
static void
 
792
Interp_compute_next_data_frame(Interp *self)
 
793
{
 
794
    (*self->proc_func_ptr)(self); 
 
795
    (*self->muladd_func_ptr)(self);
 
796
}
 
797
 
 
798
static int
 
799
Interp_traverse(Interp *self, visitproc visit, void *arg)
 
800
{
 
801
    pyo_VISIT
 
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);    
 
808
    return 0;
 
809
}
 
810
 
 
811
static int 
 
812
Interp_clear(Interp *self)
 
813
{
 
814
    pyo_CLEAR
 
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);    
 
821
    return 0;
 
822
}
 
823
 
 
824
static void
 
825
Interp_dealloc(Interp* self)
 
826
{
 
827
    free(self->data);
 
828
    Interp_clear(self);
 
829
    self->ob_type->tp_free((PyObject*)self);
 
830
}
 
831
 
 
832
static PyObject * Interp_deleteStream(Interp *self) { DELETE_STREAM };
 
833
 
 
834
static PyObject *
 
835
Interp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
836
{
 
837
    int i;
 
838
    Interp *self;
 
839
    self = (Interp *)type->tp_alloc(type, 0);
 
840
    
 
841
    self->interp = PyFloat_FromDouble(.5);
 
842
        self->modebuffer[0] = 0;
 
843
        self->modebuffer[1] = 0;
 
844
        self->modebuffer[2] = 0;
 
845
    
 
846
    INIT_OBJECT_COMMON
 
847
    Stream_setFunctionPtr(self->stream, Interp_compute_next_data_frame);
 
848
    self->mode_func_ptr = Interp_setProcMode;
 
849
    return (PyObject *)self;
 
850
}
 
851
 
 
852
static int
 
853
Interp_init(Interp *self, PyObject *args, PyObject *kwds)
 
854
{
 
855
    PyObject *inputtmp, *input_streamtmp, *input2tmp, *input2_streamtmp, *interptmp=NULL, *multmp=NULL, *addtmp=NULL;
 
856
    
 
857
    static char *kwlist[] = {"input", "input2", "interp", "mul", "add", NULL};
 
858
    
 
859
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|OOO", kwlist, &inputtmp, &input2tmp, &interptmp, &multmp, &addtmp))
 
860
        return -1; 
 
861
    
 
862
    INIT_INPUT_STREAM
 
863
 
 
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;
 
870
    
 
871
    if (interptmp) {
 
872
        PyObject_CallMethod((PyObject *)self, "setInterp", "O", interptmp);
 
873
    }
 
874
    
 
875
    if (multmp) {
 
876
        PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
 
877
    }
 
878
    
 
879
    if (addtmp) {
 
880
        PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
 
881
    }
 
882
    
 
883
    Py_INCREF(self->stream);
 
884
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
 
885
    
 
886
    (*self->mode_func_ptr)(self);
 
887
        
 
888
    Py_INCREF(self);
 
889
    return 0;
 
890
}
 
891
 
 
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 };       
 
898
 
 
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 };
 
902
 
 
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 };
 
911
 
 
912
static PyObject *
 
913
Interp_setInterp(Interp *self, PyObject *arg)
 
914
{
 
915
        PyObject *tmp, *streamtmp;
 
916
        
 
917
        if (arg == NULL) {
 
918
                Py_INCREF(Py_None);
 
919
                return Py_None;
 
920
        }
 
921
    
 
922
        int isNumber = PyNumber_Check(arg);
 
923
        
 
924
        tmp = arg;
 
925
        Py_INCREF(tmp);
 
926
        Py_DECREF(self->interp);
 
927
        if (isNumber == 1) {
 
928
                self->interp = PyNumber_Float(tmp);
 
929
        self->modebuffer[2] = 0;
 
930
        }
 
931
        else {
 
932
                self->interp = tmp;
 
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;
 
938
        }
 
939
    
 
940
    (*self->mode_func_ptr)(self);
 
941
    
 
942
        Py_INCREF(Py_None);
 
943
        return Py_None;
 
944
}
 
945
 
 
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 */
 
955
};
 
956
 
 
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 */
 
970
};
 
971
 
 
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*/
 
977
0,                                              /*nb_remainder*/
 
978
0,                                              /*nb_divmod*/
 
979
0,                                              /*nb_power*/
 
980
0,                                              /*nb_neg*/
 
981
0,                                              /*nb_pos*/
 
982
0,                                              /*(unaryfunc)array_abs,*/
 
983
0,                                              /*nb_nonzero*/
 
984
0,                                              /*nb_invert*/
 
985
0,                                              /*nb_lshift*/
 
986
0,                                              /*nb_rshift*/
 
987
0,                                              /*nb_and*/
 
988
0,                                              /*nb_xor*/
 
989
0,                                              /*nb_or*/
 
990
0,                                              /*nb_coerce*/
 
991
0,                                              /*nb_int*/
 
992
0,                                              /*nb_long*/
 
993
0,                                              /*nb_float*/
 
994
0,                                              /*nb_oct*/
 
995
0,                                              /*nb_hex*/
 
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*/
 
1004
0,                                              /*inplace_and*/
 
1005
0,                                              /*inplace_xor*/
 
1006
0,                                              /*inplace_or*/
 
1007
0,                                              /*nb_floor_divide*/
 
1008
0,                                              /*nb_true_divide*/
 
1009
0,                                              /*nb_inplace_floor_divide*/
 
1010
0,                                              /*nb_inplace_true_divide*/
 
1011
0,                                              /* nb_index */
 
1012
};
 
1013
 
 
1014
PyTypeObject InterpType = {
 
1015
PyObject_HEAD_INIT(NULL)
 
1016
0,                                              /*ob_size*/
 
1017
"_pyo.Interp_base",                                   /*tp_name*/
 
1018
sizeof(Interp),                                 /*tp_basicsize*/
 
1019
0,                                              /*tp_itemsize*/
 
1020
(destructor)Interp_dealloc,                     /*tp_dealloc*/
 
1021
0,                                              /*tp_print*/
 
1022
0,                                              /*tp_getattr*/
 
1023
0,                                              /*tp_setattr*/
 
1024
0,                                              /*tp_compare*/
 
1025
0,                                              /*tp_repr*/
 
1026
&Interp_as_number,                              /*tp_as_number*/
 
1027
0,                                              /*tp_as_sequence*/
 
1028
0,                                              /*tp_as_mapping*/
 
1029
0,                                              /*tp_hash */
 
1030
0,                                              /*tp_call*/
 
1031
0,                                              /*tp_str*/
 
1032
0,                                              /*tp_getattro*/
 
1033
0,                                              /*tp_setattro*/
 
1034
0,                                              /*tp_as_buffer*/
 
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 */
 
1041
0,                                              /* tp_iter */
 
1042
0,                                              /* tp_iternext */
 
1043
Interp_methods,                                 /* tp_methods */
 
1044
Interp_members,                                 /* tp_members */
 
1045
0,                                              /* tp_getset */
 
1046
0,                                              /* tp_base */
 
1047
0,                                              /* tp_dict */
 
1048
0,                                              /* tp_descr_get */
 
1049
0,                                              /* tp_descr_set */
 
1050
0,                                              /* tp_dictoffset */
 
1051
(initproc)Interp_init,                          /* tp_init */
 
1052
0,                                              /* tp_alloc */
 
1053
Interp_new,                                     /* tp_new */
 
1054
};
 
1055
 
 
1056
/************/
 
1057
/* SampHold */
 
1058
/************/
 
1059
typedef struct {
 
1060
    pyo_audio_HEAD
 
1061
    PyObject *input;
 
1062
    Stream *input_stream;
 
1063
    PyObject *controlsig;
 
1064
    Stream *controlsig_stream;
 
1065
    PyObject *value;
 
1066
    Stream *value_stream;
 
1067
    MYFLT currentValue;
 
1068
    int flag;
 
1069
    int modebuffer[3]; // need at least 2 slots for mul & add 
 
1070
} SampHold;
 
1071
 
 
1072
static void
 
1073
SampHold_filters_i(SampHold *self) {
 
1074
    MYFLT ctrl;
 
1075
    int i;
 
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);
 
1079
 
 
1080
    for (i=0; i<self->bufsize; i++) {
 
1081
        ctrl = ctrlsig[i];
 
1082
        if (ctrl > (val - 0.001) && ctrl < (val + 0.001)) {
 
1083
            if (self->flag == 1) {
 
1084
                self->currentValue = in[i];
 
1085
                self->flag = 0;
 
1086
            }    
 
1087
        }
 
1088
        else
 
1089
            self->flag = 1;
 
1090
        self->data[i] = self->currentValue;
 
1091
    }
 
1092
}
 
1093
 
 
1094
static void
 
1095
SampHold_filters_a(SampHold *self) {
 
1096
    MYFLT ctrl, val;
 
1097
    int i;
 
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);
 
1101
    
 
1102
    for (i=0; i<self->bufsize; i++) {
 
1103
        ctrl = ctrlsig[i];
 
1104
        val = valsig[i];
 
1105
        if (ctrl > (val - 0.001) && ctrl < (val + 0.001)) {
 
1106
            if (self->flag == 1) {
 
1107
                self->currentValue = in[i];
 
1108
                self->flag = 0;
 
1109
            }    
 
1110
        }
 
1111
        else
 
1112
            self->flag = 1;
 
1113
        self->data[i] = self->currentValue;
 
1114
    }
 
1115
}
 
1116
 
 
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 };
 
1126
 
 
1127
static void
 
1128
SampHold_setProcMode(SampHold *self)
 
1129
{
 
1130
    int procmode, muladdmode;
 
1131
    procmode = self->modebuffer[2];
 
1132
    muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
 
1133
    
 
1134
        switch (procmode) {
 
1135
        case 0:    
 
1136
            self->proc_func_ptr = SampHold_filters_i;
 
1137
            break;
 
1138
        case 1:    
 
1139
            self->proc_func_ptr = SampHold_filters_a;
 
1140
            break;
 
1141
    } 
 
1142
        switch (muladdmode) {
 
1143
        case 0:        
 
1144
            self->muladd_func_ptr = SampHold_postprocessing_ii;
 
1145
            break;
 
1146
        case 1:    
 
1147
            self->muladd_func_ptr = SampHold_postprocessing_ai;
 
1148
            break;
 
1149
        case 2:    
 
1150
            self->muladd_func_ptr = SampHold_postprocessing_revai;
 
1151
            break;
 
1152
        case 10:        
 
1153
            self->muladd_func_ptr = SampHold_postprocessing_ia;
 
1154
            break;
 
1155
        case 11:    
 
1156
            self->muladd_func_ptr = SampHold_postprocessing_aa;
 
1157
            break;
 
1158
        case 12:    
 
1159
            self->muladd_func_ptr = SampHold_postprocessing_revaa;
 
1160
            break;
 
1161
        case 20:        
 
1162
            self->muladd_func_ptr = SampHold_postprocessing_ireva;
 
1163
            break;
 
1164
        case 21:    
 
1165
            self->muladd_func_ptr = SampHold_postprocessing_areva;
 
1166
            break;
 
1167
        case 22:    
 
1168
            self->muladd_func_ptr = SampHold_postprocessing_revareva;
 
1169
            break;
 
1170
    }   
 
1171
}
 
1172
 
 
1173
static void
 
1174
SampHold_compute_next_data_frame(SampHold *self)
 
1175
{
 
1176
    (*self->proc_func_ptr)(self); 
 
1177
    (*self->muladd_func_ptr)(self);
 
1178
}
 
1179
 
 
1180
static int
 
1181
SampHold_traverse(SampHold *self, visitproc visit, void *arg)
 
1182
{
 
1183
    pyo_VISIT
 
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);    
 
1190
    return 0;
 
1191
}
 
1192
 
 
1193
static int 
 
1194
SampHold_clear(SampHold *self)
 
1195
{
 
1196
    pyo_CLEAR
 
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);    
 
1203
    return 0;
 
1204
}
 
1205
 
 
1206
static void
 
1207
SampHold_dealloc(SampHold* self)
 
1208
{
 
1209
    free(self->data);
 
1210
    SampHold_clear(self);
 
1211
    self->ob_type->tp_free((PyObject*)self);
 
1212
}
 
1213
 
 
1214
static PyObject * SampHold_deleteStream(SampHold *self) { DELETE_STREAM };
 
1215
 
 
1216
static PyObject *
 
1217
SampHold_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
1218
{
 
1219
    int i;
 
1220
    SampHold *self;
 
1221
    self = (SampHold *)type->tp_alloc(type, 0);
 
1222
    
 
1223
    self->value = PyFloat_FromDouble(0.0);
 
1224
    self->currentValue = 0.0;
 
1225
    self->flag = 1;
 
1226
        self->modebuffer[0] = 0;
 
1227
        self->modebuffer[1] = 0;
 
1228
        self->modebuffer[2] = 0;
 
1229
    
 
1230
    INIT_OBJECT_COMMON
 
1231
    Stream_setFunctionPtr(self->stream, SampHold_compute_next_data_frame);
 
1232
    self->mode_func_ptr = SampHold_setProcMode;
 
1233
    return (PyObject *)self;
 
1234
}
 
1235
 
 
1236
static int
 
1237
SampHold_init(SampHold *self, PyObject *args, PyObject *kwds)
 
1238
{
 
1239
    PyObject *inputtmp, *input_streamtmp, *controlsigtmp, *controlsig_streamtmp, *valuetmp=NULL, *multmp=NULL, *addtmp=NULL;
 
1240
    
 
1241
    static char *kwlist[] = {"input", "controlsig", "value", "mul", "add", NULL};
 
1242
    
 
1243
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|OOO", kwlist, &inputtmp, &controlsigtmp, &valuetmp, &multmp, &addtmp))
 
1244
        return -1; 
 
1245
    
 
1246
    INIT_INPUT_STREAM
 
1247
    
 
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;
 
1254
    
 
1255
    if (valuetmp) {
 
1256
        PyObject_CallMethod((PyObject *)self, "setValue", "O", valuetmp);
 
1257
    }
 
1258
    
 
1259
    if (multmp) {
 
1260
        PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
 
1261
    }
 
1262
    
 
1263
    if (addtmp) {
 
1264
        PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
 
1265
    }
 
1266
    
 
1267
    Py_INCREF(self->stream);
 
1268
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
 
1269
    
 
1270
    (*self->mode_func_ptr)(self);
 
1271
        
 
1272
    Py_INCREF(self);
 
1273
    return 0;
 
1274
}
 
1275
 
 
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 };   
 
1282
 
 
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 };
 
1286
 
 
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 };
 
1295
 
 
1296
static PyObject *
 
1297
SampHold_setValue(SampHold *self, PyObject *arg)
 
1298
{
 
1299
        PyObject *tmp, *streamtmp;
 
1300
        
 
1301
        if (arg == NULL) {
 
1302
                Py_INCREF(Py_None);
 
1303
                return Py_None;
 
1304
        }
 
1305
    
 
1306
        int isNumber = PyNumber_Check(arg);
 
1307
        
 
1308
        tmp = arg;
 
1309
        Py_INCREF(tmp);
 
1310
        Py_DECREF(self->value);
 
1311
        if (isNumber == 1) {
 
1312
                self->value = PyNumber_Float(tmp);
 
1313
        self->modebuffer[2] = 0;
 
1314
        }
 
1315
        else {
 
1316
                self->value = tmp;
 
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;
 
1322
        }
 
1323
    
 
1324
    (*self->mode_func_ptr)(self);
 
1325
    
 
1326
        Py_INCREF(Py_None);
 
1327
        return Py_None;
 
1328
}
 
1329
 
 
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 */
 
1339
};
 
1340
 
 
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 */
 
1354
};
 
1355
 
 
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*/
 
1361
0,                                              /*nb_remainder*/
 
1362
0,                                              /*nb_divmod*/
 
1363
0,                                              /*nb_power*/
 
1364
0,                                              /*nb_neg*/
 
1365
0,                                              /*nb_pos*/
 
1366
0,                                              /*(unaryfunc)array_abs,*/
 
1367
0,                                              /*nb_nonzero*/
 
1368
0,                                              /*nb_invert*/
 
1369
0,                                              /*nb_lshift*/
 
1370
0,                                              /*nb_rshift*/
 
1371
0,                                              /*nb_and*/
 
1372
0,                                              /*nb_xor*/
 
1373
0,                                              /*nb_or*/
 
1374
0,                                              /*nb_coerce*/
 
1375
0,                                              /*nb_int*/
 
1376
0,                                              /*nb_long*/
 
1377
0,                                              /*nb_float*/
 
1378
0,                                              /*nb_oct*/
 
1379
0,                                              /*nb_hex*/
 
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*/
 
1388
0,                                              /*inplace_and*/
 
1389
0,                                              /*inplace_xor*/
 
1390
0,                                              /*inplace_or*/
 
1391
0,                                              /*nb_floor_divide*/
 
1392
0,                                              /*nb_true_divide*/
 
1393
0,                                              /*nb_inplace_floor_divide*/
 
1394
0,                                              /*nb_inplace_true_divide*/
 
1395
0,                                              /* nb_index */
 
1396
};
 
1397
 
 
1398
PyTypeObject SampHoldType = {
 
1399
PyObject_HEAD_INIT(NULL)
 
1400
0,                                              /*ob_size*/
 
1401
"_pyo.SampHold_base",                                   /*tp_name*/
 
1402
sizeof(SampHold),                                 /*tp_basicsize*/
 
1403
0,                                              /*tp_itemsize*/
 
1404
(destructor)SampHold_dealloc,                     /*tp_dealloc*/
 
1405
0,                                              /*tp_print*/
 
1406
0,                                              /*tp_getattr*/
 
1407
0,                                              /*tp_setattr*/
 
1408
0,                                              /*tp_compare*/
 
1409
0,                                              /*tp_repr*/
 
1410
&SampHold_as_number,                              /*tp_as_number*/
 
1411
0,                                              /*tp_as_sequence*/
 
1412
0,                                              /*tp_as_mapping*/
 
1413
0,                                              /*tp_hash */
 
1414
0,                                              /*tp_call*/
 
1415
0,                                              /*tp_str*/
 
1416
0,                                              /*tp_getattro*/
 
1417
0,                                              /*tp_setattro*/
 
1418
0,                                              /*tp_as_buffer*/
 
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 */
 
1425
0,                                              /* tp_iter */
 
1426
0,                                              /* tp_iternext */
 
1427
SampHold_methods,                                 /* tp_methods */
 
1428
SampHold_members,                                 /* tp_members */
 
1429
0,                                              /* tp_getset */
 
1430
0,                                              /* tp_base */
 
1431
0,                                              /* tp_dict */
 
1432
0,                                              /* tp_descr_get */
 
1433
0,                                              /* tp_descr_set */
 
1434
0,                                              /* tp_dictoffset */
 
1435
(initproc)SampHold_init,                          /* tp_init */
 
1436
0,                                              /* tp_alloc */
 
1437
SampHold_new,                                     /* tp_new */
 
1438
};
 
1439
 
 
1440
/************/
 
1441
/* Compare */
 
1442
/************/
 
1443
typedef struct {
 
1444
    pyo_audio_HEAD
 
1445
    PyObject *input;
 
1446
    Stream *input_stream;
 
1447
    PyObject *comp;
 
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 
 
1451
} Compare;
 
1452
 
 
1453
static MYFLT
 
1454
Compare_lt(MYFLT in, MYFLT comp) {
 
1455
    if (in < comp) { return 1.0; }
 
1456
    else { return 0.0; }
 
1457
}
 
1458
 
 
1459
static MYFLT
 
1460
Compare_elt(MYFLT in, MYFLT comp) {
 
1461
    if (in <= comp) { return 1.0; }
 
1462
    else { return 0.0; }
 
1463
}
 
1464
 
 
1465
static MYFLT
 
1466
Compare_gt(MYFLT in, MYFLT comp) {
 
1467
    if (in > comp) { return 1.0; }
 
1468
    else { return 0.0; }
 
1469
}
 
1470
 
 
1471
static MYFLT
 
1472
Compare_egt(MYFLT in, MYFLT comp) {
 
1473
    if (in >= comp) { return 1.0; }
 
1474
    else { return 0.0; }
 
1475
}
 
1476
 
 
1477
static MYFLT
 
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; }
 
1481
}
 
1482
 
 
1483
static MYFLT
 
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; }
 
1487
}
 
1488
 
 
1489
static void
 
1490
Compare_process_i(Compare *self) {
 
1491
    int i;
 
1492
    MYFLT *in = Stream_getData((Stream *)self->input_stream);
 
1493
    MYFLT comp = PyFloat_AS_DOUBLE(self->comp);
 
1494
    
 
1495
    for (i=0; i<self->bufsize; i++) {
 
1496
        self->data[i] = (*self->compare_func_ptr)(in[i], comp);
 
1497
    }
 
1498
}
 
1499
 
 
1500
static void
 
1501
Compare_process_a(Compare *self) {
 
1502
    int i;
 
1503
    MYFLT *in = Stream_getData((Stream *)self->input_stream);
 
1504
    MYFLT *comp = Stream_getData((Stream *)self->comp_stream);
 
1505
    
 
1506
    for (i=0; i<self->bufsize; i++) {
 
1507
        self->data[i] = (*self->compare_func_ptr)(in[i], comp[i]);
 
1508
    }
 
1509
}
 
1510
 
 
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 };
 
1520
 
 
1521
static void
 
1522
Compare_setProcMode(Compare *self)
 
1523
{
 
1524
    int procmode, muladdmode;
 
1525
    procmode = self->modebuffer[2];
 
1526
    muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
 
1527
    
 
1528
        switch (procmode) {
 
1529
        case 0:    
 
1530
            self->proc_func_ptr = Compare_process_i;
 
1531
            break;
 
1532
        case 1:    
 
1533
            self->proc_func_ptr = Compare_process_a;
 
1534
            break;
 
1535
    } 
 
1536
        switch (muladdmode) {
 
1537
        case 0:        
 
1538
            self->muladd_func_ptr = Compare_postprocessing_ii;
 
1539
            break;
 
1540
        case 1:    
 
1541
            self->muladd_func_ptr = Compare_postprocessing_ai;
 
1542
            break;
 
1543
        case 2:    
 
1544
            self->muladd_func_ptr = Compare_postprocessing_revai;
 
1545
            break;
 
1546
        case 10:        
 
1547
            self->muladd_func_ptr = Compare_postprocessing_ia;
 
1548
            break;
 
1549
        case 11:    
 
1550
            self->muladd_func_ptr = Compare_postprocessing_aa;
 
1551
            break;
 
1552
        case 12:    
 
1553
            self->muladd_func_ptr = Compare_postprocessing_revaa;
 
1554
            break;
 
1555
        case 20:        
 
1556
            self->muladd_func_ptr = Compare_postprocessing_ireva;
 
1557
            break;
 
1558
        case 21:    
 
1559
            self->muladd_func_ptr = Compare_postprocessing_areva;
 
1560
            break;
 
1561
        case 22:    
 
1562
            self->muladd_func_ptr = Compare_postprocessing_revareva;
 
1563
            break;
 
1564
    }   
 
1565
}
 
1566
 
 
1567
static void
 
1568
Compare_compute_next_data_frame(Compare *self)
 
1569
{
 
1570
    (*self->proc_func_ptr)(self); 
 
1571
    (*self->muladd_func_ptr)(self);
 
1572
}
 
1573
 
 
1574
static int
 
1575
Compare_traverse(Compare *self, visitproc visit, void *arg)
 
1576
{
 
1577
    pyo_VISIT
 
1578
    Py_VISIT(self->input);
 
1579
    Py_VISIT(self->input_stream);
 
1580
    Py_VISIT(self->comp);
 
1581
    Py_VISIT(self->comp_stream);
 
1582
    return 0;
 
1583
}
 
1584
 
 
1585
static int 
 
1586
Compare_clear(Compare *self)
 
1587
{
 
1588
    pyo_CLEAR
 
1589
    Py_CLEAR(self->input);
 
1590
    Py_CLEAR(self->input_stream);
 
1591
    Py_CLEAR(self->comp);
 
1592
    Py_CLEAR(self->comp_stream);
 
1593
    return 0;
 
1594
}
 
1595
 
 
1596
static void
 
1597
Compare_dealloc(Compare* self)
 
1598
{
 
1599
    free(self->data);
 
1600
    Compare_clear(self);
 
1601
    self->ob_type->tp_free((PyObject*)self);
 
1602
}
 
1603
 
 
1604
static PyObject * Compare_deleteStream(Compare *self) { DELETE_STREAM };
 
1605
 
 
1606
static PyObject *
 
1607
Compare_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
1608
{
 
1609
    int i;
 
1610
    Compare *self;
 
1611
    self = (Compare *)type->tp_alloc(type, 0);
 
1612
    
 
1613
        self->modebuffer[0] = 0;
 
1614
        self->modebuffer[1] = 0;
 
1615
        self->modebuffer[2] = 0;
 
1616
    
 
1617
    self->compare_func_ptr = Compare_lt;
 
1618
    
 
1619
    INIT_OBJECT_COMMON
 
1620
    Stream_setFunctionPtr(self->stream, Compare_compute_next_data_frame);
 
1621
    self->mode_func_ptr = Compare_setProcMode;
 
1622
    return (PyObject *)self;
 
1623
}
 
1624
 
 
1625
static int
 
1626
Compare_init(Compare *self, PyObject *args, PyObject *kwds)
 
1627
{
 
1628
    PyObject *inputtmp, *input_streamtmp, *comptmp, *modetmp=NULL, *multmp=NULL, *addtmp=NULL;
 
1629
    
 
1630
    static char *kwlist[] = {"input", "comp", "mode", "mul", "add", NULL};
 
1631
    
 
1632
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|OOO", kwlist, &inputtmp, &comptmp, &modetmp, &multmp, &addtmp))
 
1633
        return -1; 
 
1634
    
 
1635
    INIT_INPUT_STREAM
 
1636
    
 
1637
    if (comptmp) {
 
1638
        PyObject_CallMethod((PyObject *)self, "setComp", "O", comptmp);
 
1639
    }
 
1640
    
 
1641
    if (modetmp) {
 
1642
        PyObject_CallMethod((PyObject *)self, "setMode", "O", modetmp);
 
1643
    }
 
1644
    
 
1645
    if (multmp) {
 
1646
        PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
 
1647
    }
 
1648
    
 
1649
    if (addtmp) {
 
1650
        PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
 
1651
    }
 
1652
    
 
1653
    Py_INCREF(self->stream);
 
1654
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
 
1655
    
 
1656
    (*self->mode_func_ptr)(self);
 
1657
        
 
1658
    Py_INCREF(self);
 
1659
    return 0;
 
1660
}
 
1661
 
 
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 };     
 
1668
 
 
1669
static PyObject * Compare_play(Compare *self, PyObject *args, PyObject *kwds) { PLAY };
 
1670
static PyObject * Compare_stop(Compare *self) { STOP };
 
1671
 
 
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 };
 
1680
 
 
1681
static PyObject *
 
1682
Compare_setComp(Compare *self, PyObject *arg)
 
1683
{
 
1684
        PyObject *tmp, *streamtmp;
 
1685
    
 
1686
        if (arg == NULL) {
 
1687
                Py_RETURN_NONE;
 
1688
        }
 
1689
    
 
1690
        int isNumber = PyNumber_Check(arg);
 
1691
        
 
1692
        tmp = arg;
 
1693
        Py_INCREF(tmp);
 
1694
        Py_XDECREF(self->comp);
 
1695
        if (isNumber == 1) {
 
1696
                self->comp = PyNumber_Float(tmp);
 
1697
        self->modebuffer[2] = 0;
 
1698
        }
 
1699
        else {
 
1700
                self->comp = tmp;
 
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;
 
1706
        }
 
1707
    
 
1708
    (*self->mode_func_ptr)(self);
 
1709
    
 
1710
        Py_INCREF(Py_None);
 
1711
        return Py_None;
 
1712
}
 
1713
 
 
1714
static PyObject *
 
1715
Compare_setMode(Compare *self, PyObject *arg)
 
1716
{       
 
1717
        if (arg == NULL) {
 
1718
                Py_RETURN_NONE;
 
1719
        }
 
1720
    
 
1721
        if (! PyInt_Check(arg)) {
 
1722
        printf("mode should be a comparison operator as a string\n");
 
1723
                Py_RETURN_NONE;
 
1724
    }
 
1725
 
 
1726
    int tmp = PyInt_AsLong(arg);
 
1727
    
 
1728
    if (tmp == 0)
 
1729
        self->compare_func_ptr = Compare_lt;
 
1730
    else if (tmp == 1)
 
1731
        self->compare_func_ptr = Compare_elt;
 
1732
    else if (tmp == 2)
 
1733
        self->compare_func_ptr = Compare_gt;
 
1734
    else if (tmp == 3)
 
1735
        self->compare_func_ptr = Compare_egt;
 
1736
    else if (tmp == 4)
 
1737
        self->compare_func_ptr = Compare_eq;
 
1738
    else if (tmp == 5)
 
1739
        self->compare_func_ptr = Compare_neq;
 
1740
    
 
1741
    Py_RETURN_NONE;
 
1742
}
 
1743
 
 
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 */
 
1752
};
 
1753
 
 
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 */
 
1767
};
 
1768
 
 
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*/
 
1774
0,                                              /*nb_remainder*/
 
1775
0,                                              /*nb_divmod*/
 
1776
0,                                              /*nb_power*/
 
1777
0,                                              /*nb_neg*/
 
1778
0,                                              /*nb_pos*/
 
1779
0,                                              /*(unaryfunc)array_abs,*/
 
1780
0,                                              /*nb_nonzero*/
 
1781
0,                                              /*nb_invert*/
 
1782
0,                                              /*nb_lshift*/
 
1783
0,                                              /*nb_rshift*/
 
1784
0,                                              /*nb_and*/
 
1785
0,                                              /*nb_xor*/
 
1786
0,                                              /*nb_or*/
 
1787
0,                                              /*nb_coerce*/
 
1788
0,                                              /*nb_int*/
 
1789
0,                                              /*nb_long*/
 
1790
0,                                              /*nb_float*/
 
1791
0,                                              /*nb_oct*/
 
1792
0,                                              /*nb_hex*/
 
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*/
 
1801
0,                                              /*inplace_and*/
 
1802
0,                                              /*inplace_xor*/
 
1803
0,                                              /*inplace_or*/
 
1804
0,                                              /*nb_floor_divide*/
 
1805
0,                                              /*nb_true_divide*/
 
1806
0,                                              /*nb_inplace_floor_divide*/
 
1807
0,                                              /*nb_inplace_true_divide*/
 
1808
0,                                              /* nb_index */
 
1809
};
 
1810
 
 
1811
PyTypeObject CompareType = {
 
1812
PyObject_HEAD_INIT(NULL)
 
1813
0,                                              /*ob_size*/
 
1814
"_pyo.Compare_base",                                   /*tp_name*/
 
1815
sizeof(Compare),                                 /*tp_basicsize*/
 
1816
0,                                              /*tp_itemsize*/
 
1817
(destructor)Compare_dealloc,                     /*tp_dealloc*/
 
1818
0,                                              /*tp_print*/
 
1819
0,                                              /*tp_getattr*/
 
1820
0,                                              /*tp_setattr*/
 
1821
0,                                              /*tp_compare*/
 
1822
0,                                              /*tp_repr*/
 
1823
&Compare_as_number,                              /*tp_as_number*/
 
1824
0,                                              /*tp_as_sequence*/
 
1825
0,                                              /*tp_as_mapping*/
 
1826
0,                                              /*tp_hash */
 
1827
0,                                              /*tp_call*/
 
1828
0,                                              /*tp_str*/
 
1829
0,                                              /*tp_getattro*/
 
1830
0,                                              /*tp_setattro*/
 
1831
0,                                              /*tp_as_buffer*/
 
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 */
 
1838
0,                                              /* tp_iter */
 
1839
0,                                              /* tp_iternext */
 
1840
Compare_methods,                                 /* tp_methods */
 
1841
Compare_members,                                 /* tp_members */
 
1842
0,                                              /* tp_getset */
 
1843
0,                                              /* tp_base */
 
1844
0,                                              /* tp_dict */
 
1845
0,                                              /* tp_descr_get */
 
1846
0,                                              /* tp_descr_set */
 
1847
0,                                              /* tp_dictoffset */
 
1848
(initproc)Compare_init,                          /* tp_init */
 
1849
0,                                              /* tp_alloc */
 
1850
Compare_new,                                     /* tp_new */
 
1851
};
 
1852
 
 
1853
/*****************/
 
1854
/** Between object **/
 
1855
/*****************/
 
1856
 
 
1857
typedef struct {
 
1858
    pyo_audio_HEAD
 
1859
    PyObject *input;
 
1860
    Stream *input_stream;
 
1861
    PyObject *min;
 
1862
    Stream *min_stream;
 
1863
    PyObject *max;
 
1864
    Stream *max_stream;
 
1865
    int modebuffer[4];
 
1866
} Between;
 
1867
 
 
1868
static void
 
1869
Between_transform_ii(Between *self) {
 
1870
    MYFLT val;
 
1871
    int i;
 
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);
 
1875
    
 
1876
    for (i=0; i<self->bufsize; i++) {
 
1877
        val = in[i];
 
1878
        if(val >= mi && val < ma)
 
1879
            self->data[i] = 1.0;
 
1880
        else
 
1881
            self->data[i] = 0.0;
 
1882
    }
 
1883
}
 
1884
 
 
1885
static void
 
1886
Between_transform_ai(Between *self) {
 
1887
    MYFLT val;
 
1888
    int i;
 
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);
 
1892
    
 
1893
    for (i=0; i<self->bufsize; i++) {
 
1894
        val = in[i];
 
1895
        if(val >= mi[i] && val < ma)
 
1896
            self->data[i] = 1.0;
 
1897
        else
 
1898
            self->data[i] = 0.0;
 
1899
    }
 
1900
}
 
1901
 
 
1902
static void
 
1903
Between_transform_ia(Between *self) {
 
1904
    MYFLT val;
 
1905
    int i;
 
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);
 
1909
    
 
1910
    for (i=0; i<self->bufsize; i++) {
 
1911
        val = in[i];
 
1912
        if(val >= mi && val < ma[i])
 
1913
            self->data[i] = 1.0;
 
1914
        else
 
1915
            self->data[i] = 0.0;
 
1916
    }
 
1917
}
 
1918
 
 
1919
static void
 
1920
Between_transform_aa(Between *self) {
 
1921
    MYFLT val;
 
1922
    int i;
 
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);
 
1926
    
 
1927
    for (i=0; i<self->bufsize; i++) {
 
1928
        val = in[i];
 
1929
        if(val >= mi[i] && val < ma[i])
 
1930
            self->data[i] = 1.0;
 
1931
        else
 
1932
            self->data[i] = 0.0;
 
1933
    }
 
1934
}
 
1935
 
 
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 };
 
1945
 
 
1946
static void
 
1947
Between_setProcMode(Between *self)
 
1948
{
 
1949
    int procmode, muladdmode;
 
1950
    procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
 
1951
    muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
 
1952
    
 
1953
        switch (procmode) {
 
1954
        case 0:    
 
1955
            self->proc_func_ptr = Between_transform_ii;
 
1956
            break;
 
1957
        case 1:    
 
1958
            self->proc_func_ptr = Between_transform_ai;
 
1959
            break;
 
1960
        case 10:        
 
1961
            self->proc_func_ptr = Between_transform_ia;
 
1962
            break;
 
1963
        case 11:    
 
1964
            self->proc_func_ptr = Between_transform_aa;
 
1965
            break;
 
1966
    } 
 
1967
        switch (muladdmode) {
 
1968
        case 0:        
 
1969
            self->muladd_func_ptr = Between_postprocessing_ii;
 
1970
            break;
 
1971
        case 1:    
 
1972
            self->muladd_func_ptr = Between_postprocessing_ai;
 
1973
            break;
 
1974
        case 2:    
 
1975
            self->muladd_func_ptr = Between_postprocessing_revai;
 
1976
            break;
 
1977
        case 10:        
 
1978
            self->muladd_func_ptr = Between_postprocessing_ia;
 
1979
            break;
 
1980
        case 11:    
 
1981
            self->muladd_func_ptr = Between_postprocessing_aa;
 
1982
            break;
 
1983
        case 12:    
 
1984
            self->muladd_func_ptr = Between_postprocessing_revaa;
 
1985
            break;
 
1986
        case 20:        
 
1987
            self->muladd_func_ptr = Between_postprocessing_ireva;
 
1988
            break;
 
1989
        case 21:    
 
1990
            self->muladd_func_ptr = Between_postprocessing_areva;
 
1991
            break;
 
1992
        case 22:    
 
1993
            self->muladd_func_ptr = Between_postprocessing_revareva;
 
1994
            break;
 
1995
    }   
 
1996
}
 
1997
 
 
1998
static void
 
1999
Between_compute_next_data_frame(Between *self)
 
2000
{
 
2001
    (*self->proc_func_ptr)(self); 
 
2002
    (*self->muladd_func_ptr)(self);
 
2003
}
 
2004
 
 
2005
static int
 
2006
Between_traverse(Between *self, visitproc visit, void *arg)
 
2007
{
 
2008
    pyo_VISIT
 
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);    
 
2015
    return 0;
 
2016
}
 
2017
 
 
2018
static int 
 
2019
Between_clear(Between *self)
 
2020
{
 
2021
    pyo_CLEAR
 
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);    
 
2028
    return 0;
 
2029
}
 
2030
 
 
2031
static void
 
2032
Between_dealloc(Between* self)
 
2033
{
 
2034
    free(self->data);
 
2035
    Between_clear(self);
 
2036
    self->ob_type->tp_free((PyObject*)self);
 
2037
}
 
2038
 
 
2039
static PyObject * Between_deleteStream(Between *self) { DELETE_STREAM };
 
2040
 
 
2041
static PyObject *
 
2042
Between_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
2043
{
 
2044
    int i;
 
2045
    Between *self;
 
2046
    self = (Between *)type->tp_alloc(type, 0);
 
2047
    
 
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;
 
2054
    
 
2055
    INIT_OBJECT_COMMON
 
2056
    Stream_setFunctionPtr(self->stream, Between_compute_next_data_frame);
 
2057
    self->mode_func_ptr = Between_setProcMode;
 
2058
    
 
2059
    return (PyObject *)self;
 
2060
}
 
2061
 
 
2062
static int
 
2063
Between_init(Between *self, PyObject *args, PyObject *kwds)
 
2064
{
 
2065
    PyObject *inputtmp, *input_streamtmp, *mintmp=NULL, *maxtmp=NULL, *multmp=NULL, *addtmp=NULL;
 
2066
    
 
2067
    static char *kwlist[] = {"input", "min", "max", "mul", "add", NULL};
 
2068
    
 
2069
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OOOO", kwlist, &inputtmp, &mintmp, &maxtmp, &multmp, &addtmp))
 
2070
        return -1; 
 
2071
    
 
2072
    INIT_INPUT_STREAM
 
2073
    
 
2074
    if (mintmp) {
 
2075
        PyObject_CallMethod((PyObject *)self, "setMin", "O", mintmp);
 
2076
    }
 
2077
    
 
2078
    if (maxtmp) {
 
2079
        PyObject_CallMethod((PyObject *)self, "setMax", "O", maxtmp);
 
2080
    }
 
2081
    
 
2082
    if (multmp) {
 
2083
        PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
 
2084
    }
 
2085
    
 
2086
    if (addtmp) {
 
2087
        PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
 
2088
    }
 
2089
    
 
2090
    Py_INCREF(self->stream);
 
2091
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
 
2092
    
 
2093
    (*self->mode_func_ptr)(self);
 
2094
    
 
2095
    Py_INCREF(self);
 
2096
    return 0;
 
2097
}
 
2098
 
 
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 };     
 
2105
 
 
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 };
 
2109
 
 
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 };
 
2118
 
 
2119
static PyObject *
 
2120
Between_setMin(Between *self, PyObject *arg)
 
2121
{
 
2122
        PyObject *tmp, *streamtmp;
 
2123
        
 
2124
        if (arg == NULL) {
 
2125
                Py_INCREF(Py_None);
 
2126
                return Py_None;
 
2127
        }
 
2128
    
 
2129
        int isNumber = PyNumber_Check(arg);
 
2130
        
 
2131
        tmp = arg;
 
2132
        Py_INCREF(tmp);
 
2133
        Py_DECREF(self->min);
 
2134
        if (isNumber == 1) {
 
2135
                self->min = PyNumber_Float(tmp);
 
2136
        self->modebuffer[2] = 0;
 
2137
        }
 
2138
        else {
 
2139
                self->min = tmp;
 
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;
 
2145
        }
 
2146
    
 
2147
    (*self->mode_func_ptr)(self);
 
2148
    
 
2149
        Py_INCREF(Py_None);
 
2150
        return Py_None;
 
2151
}       
 
2152
 
 
2153
static PyObject *
 
2154
Between_setMax(Between *self, PyObject *arg)
 
2155
{
 
2156
        PyObject *tmp, *streamtmp;
 
2157
        
 
2158
        if (arg == NULL) {
 
2159
                Py_INCREF(Py_None);
 
2160
                return Py_None;
 
2161
        }
 
2162
    
 
2163
        int isNumber = PyNumber_Check(arg);
 
2164
        
 
2165
        tmp = arg;
 
2166
        Py_INCREF(tmp);
 
2167
        Py_DECREF(self->max);
 
2168
        if (isNumber == 1) {
 
2169
                self->max = PyNumber_Float(tmp);
 
2170
        self->modebuffer[3] = 0;
 
2171
        }
 
2172
        else {
 
2173
                self->max = tmp;
 
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;
 
2179
        }
 
2180
    
 
2181
    (*self->mode_func_ptr)(self);
 
2182
    
 
2183
        Py_INCREF(Py_None);
 
2184
        return Py_None;
 
2185
}       
 
2186
 
 
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 */
 
2196
};
 
2197
 
 
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 */
 
2212
};
 
2213
 
 
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*/
 
2219
    0,                /*nb_remainder*/
 
2220
    0,                   /*nb_divmod*/
 
2221
    0,                   /*nb_power*/
 
2222
    0,                  /*nb_neg*/
 
2223
    0,                /*nb_pos*/
 
2224
    0,                  /*(unaryfunc)array_abs,*/
 
2225
    0,                    /*nb_nonzero*/
 
2226
    0,                    /*nb_invert*/
 
2227
    0,               /*nb_lshift*/
 
2228
    0,              /*nb_rshift*/
 
2229
    0,              /*nb_and*/
 
2230
    0,              /*nb_xor*/
 
2231
    0,               /*nb_or*/
 
2232
    0,                                          /*nb_coerce*/
 
2233
    0,                       /*nb_int*/
 
2234
    0,                      /*nb_long*/
 
2235
    0,                     /*nb_float*/
 
2236
    0,                       /*nb_oct*/
 
2237
    0,                       /*nb_hex*/
 
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*/
 
2246
    0,      /*inplace_and*/
 
2247
    0,      /*inplace_xor*/
 
2248
    0,       /*inplace_or*/
 
2249
    0,             /*nb_floor_divide*/
 
2250
    0,              /*nb_true_divide*/
 
2251
    0,     /*nb_inplace_floor_divide*/
 
2252
    0,      /*nb_inplace_true_divide*/
 
2253
    0,                     /* nb_index */
 
2254
};
 
2255
 
 
2256
PyTypeObject BetweenType = {
 
2257
    PyObject_HEAD_INIT(NULL)
 
2258
    0,                         /*ob_size*/
 
2259
    "_pyo.Between_base",         /*tp_name*/
 
2260
    sizeof(Between),         /*tp_basicsize*/
 
2261
    0,                         /*tp_itemsize*/
 
2262
    (destructor)Between_dealloc, /*tp_dealloc*/
 
2263
    0,                         /*tp_print*/
 
2264
    0,                         /*tp_getattr*/
 
2265
    0,                         /*tp_setattr*/
 
2266
    0,                         /*tp_compare*/
 
2267
    0,                         /*tp_repr*/
 
2268
    &Between_as_number,             /*tp_as_number*/
 
2269
    0,                         /*tp_as_sequence*/
 
2270
    0,                         /*tp_as_mapping*/
 
2271
    0,                         /*tp_hash */
 
2272
    0,                         /*tp_call*/
 
2273
    0,                         /*tp_str*/
 
2274
    0,                         /*tp_getattro*/
 
2275
    0,                         /*tp_setattro*/
 
2276
    0,                         /*tp_as_buffer*/
 
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 */
 
2283
    0,                         /* tp_iter */
 
2284
    0,                         /* tp_iternext */
 
2285
    Between_methods,             /* tp_methods */
 
2286
    Between_members,             /* tp_members */
 
2287
    0,                      /* tp_getset */
 
2288
    0,                         /* tp_base */
 
2289
    0,                         /* tp_dict */
 
2290
    0,                         /* tp_descr_get */
 
2291
    0,                         /* tp_descr_set */
 
2292
    0,                         /* tp_dictoffset */
 
2293
    (initproc)Between_init,      /* tp_init */
 
2294
    0,                         /* tp_alloc */
 
2295
    Between_new,                 /* tp_new */
 
2296
};
 
2297
 
 
2298
 
 
2299
/************/
 
2300
/* Denorm */
 
2301
/************/
 
2302
#ifndef USE_DOUBLE
 
2303
#define DENORM_RAND  ((MYFLT) ((rand()/((MYFLT)(RAND_MAX)*0.5+1) - 1.0) * (MYFLT)(1.0e-24)))
 
2304
#else
 
2305
#define DENORM_RAND  ((MYFLT) ((rand()/((MYFLT)(RAND_MAX)*0.5+1) - 1.0) * (MYFLT)(1.0e-60)))
 
2306
#endif
 
2307
 
 
2308
typedef struct {
 
2309
    pyo_audio_HEAD
 
2310
    PyObject *input;
 
2311
    Stream *input_stream;
 
2312
    int modebuffer[2]; // need at least 2 slots for mul & add 
 
2313
} Denorm;
 
2314
 
 
2315
static void
 
2316
Denorm_filters(Denorm *self) {
 
2317
    int i;
 
2318
    MYFLT *in = Stream_getData((Stream *)self->input_stream);
 
2319
    
 
2320
    for (i=0; i<self->bufsize; i++) {
 
2321
        self->data[i] = in[i] + DENORM_RAND;
 
2322
    }
 
2323
}
 
2324
 
 
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 };
 
2334
 
 
2335
static void
 
2336
Denorm_setProcMode(Denorm *self)
 
2337
{
 
2338
    int muladdmode;
 
2339
    muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
 
2340
    
 
2341
    self->proc_func_ptr = Denorm_filters;
 
2342
    
 
2343
        switch (muladdmode) {
 
2344
        case 0:        
 
2345
            self->muladd_func_ptr = Denorm_postprocessing_ii;
 
2346
            break;
 
2347
        case 1:    
 
2348
            self->muladd_func_ptr = Denorm_postprocessing_ai;
 
2349
            break;
 
2350
        case 2:    
 
2351
            self->muladd_func_ptr = Denorm_postprocessing_revai;
 
2352
            break;
 
2353
        case 10:        
 
2354
            self->muladd_func_ptr = Denorm_postprocessing_ia;
 
2355
            break;
 
2356
        case 11:    
 
2357
            self->muladd_func_ptr = Denorm_postprocessing_aa;
 
2358
            break;
 
2359
        case 12:    
 
2360
            self->muladd_func_ptr = Denorm_postprocessing_revaa;
 
2361
            break;
 
2362
        case 20:        
 
2363
            self->muladd_func_ptr = Denorm_postprocessing_ireva;
 
2364
            break;
 
2365
        case 21:    
 
2366
            self->muladd_func_ptr = Denorm_postprocessing_areva;
 
2367
            break;
 
2368
        case 22:    
 
2369
            self->muladd_func_ptr = Denorm_postprocessing_revareva;
 
2370
            break;
 
2371
    }   
 
2372
}
 
2373
 
 
2374
static void
 
2375
Denorm_compute_next_data_frame(Denorm *self)
 
2376
{
 
2377
    (*self->proc_func_ptr)(self); 
 
2378
    (*self->muladd_func_ptr)(self);
 
2379
}
 
2380
 
 
2381
static int
 
2382
Denorm_traverse(Denorm *self, visitproc visit, void *arg)
 
2383
{
 
2384
    pyo_VISIT
 
2385
    Py_VISIT(self->input);
 
2386
    Py_VISIT(self->input_stream);
 
2387
    return 0;
 
2388
}
 
2389
 
 
2390
static int 
 
2391
Denorm_clear(Denorm *self)
 
2392
{
 
2393
    pyo_CLEAR
 
2394
    Py_CLEAR(self->input);
 
2395
    Py_CLEAR(self->input_stream);
 
2396
    return 0;
 
2397
}
 
2398
 
 
2399
static void
 
2400
Denorm_dealloc(Denorm* self)
 
2401
{
 
2402
    free(self->data);
 
2403
    Denorm_clear(self);
 
2404
    self->ob_type->tp_free((PyObject*)self);
 
2405
}
 
2406
 
 
2407
static PyObject * Denorm_deleteStream(Denorm *self) { DELETE_STREAM };
 
2408
 
 
2409
static PyObject *
 
2410
Denorm_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
2411
{
 
2412
    int i;
 
2413
    Denorm *self;
 
2414
    self = (Denorm *)type->tp_alloc(type, 0);
 
2415
    
 
2416
        self->modebuffer[0] = 0;
 
2417
        self->modebuffer[1] = 0;
 
2418
    
 
2419
    INIT_OBJECT_COMMON
 
2420
    Stream_setFunctionPtr(self->stream, Denorm_compute_next_data_frame);
 
2421
    self->mode_func_ptr = Denorm_setProcMode;
 
2422
    return (PyObject *)self;
 
2423
}
 
2424
 
 
2425
static int
 
2426
Denorm_init(Denorm *self, PyObject *args, PyObject *kwds)
 
2427
{
 
2428
    PyObject *inputtmp, *input_streamtmp, *multmp=NULL, *addtmp=NULL;
 
2429
    
 
2430
    static char *kwlist[] = {"input", "mul", "add", NULL};
 
2431
    
 
2432
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
 
2433
        return -1; 
 
2434
    
 
2435
    INIT_INPUT_STREAM
 
2436
    
 
2437
    if (multmp) {
 
2438
        PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
 
2439
    }
 
2440
    
 
2441
    if (addtmp) {
 
2442
        PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
 
2443
    }
 
2444
    
 
2445
    Py_INCREF(self->stream);
 
2446
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
 
2447
    
 
2448
    Server_generateSeed((Server *)self->server, DENORM_ID);
 
2449
 
 
2450
    (*self->mode_func_ptr)(self);
 
2451
    
 
2452
    Py_INCREF(self);
 
2453
    return 0;
 
2454
}
 
2455
 
 
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 };       
 
2462
 
 
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 };
 
2466
 
 
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 };
 
2475
 
 
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 */
 
2483
};
 
2484
 
 
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 */
 
2497
};
 
2498
 
 
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*/
 
2504
    0,                                              /*nb_remainder*/
 
2505
    0,                                              /*nb_divmod*/
 
2506
    0,                                              /*nb_power*/
 
2507
    0,                                              /*nb_neg*/
 
2508
    0,                                              /*nb_pos*/
 
2509
    0,                                              /*(unaryfunc)array_abs,*/
 
2510
    0,                                              /*nb_nonzero*/
 
2511
    0,                                              /*nb_invert*/
 
2512
    0,                                              /*nb_lshift*/
 
2513
    0,                                              /*nb_rshift*/
 
2514
    0,                                              /*nb_and*/
 
2515
    0,                                              /*nb_xor*/
 
2516
    0,                                              /*nb_or*/
 
2517
    0,                                              /*nb_coerce*/
 
2518
    0,                                              /*nb_int*/
 
2519
    0,                                              /*nb_long*/
 
2520
    0,                                              /*nb_float*/
 
2521
    0,                                              /*nb_oct*/
 
2522
    0,                                              /*nb_hex*/
 
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*/
 
2531
    0,                                              /*inplace_and*/
 
2532
    0,                                              /*inplace_xor*/
 
2533
    0,                                              /*inplace_or*/
 
2534
    0,                                              /*nb_floor_divide*/
 
2535
    0,                                              /*nb_true_divide*/
 
2536
    0,                                              /*nb_inplace_floor_divide*/
 
2537
    0,                                              /*nb_inplace_true_divide*/
 
2538
    0,                                              /* nb_index */
 
2539
};
 
2540
 
 
2541
PyTypeObject DenormType = {
 
2542
    PyObject_HEAD_INIT(NULL)
 
2543
    0,                                              /*ob_size*/
 
2544
    "_pyo.Denorm_base",                                   /*tp_name*/
 
2545
    sizeof(Denorm),                                 /*tp_basicsize*/
 
2546
    0,                                              /*tp_itemsize*/
 
2547
    (destructor)Denorm_dealloc,                     /*tp_dealloc*/
 
2548
    0,                                              /*tp_print*/
 
2549
    0,                                              /*tp_getattr*/
 
2550
    0,                                              /*tp_setattr*/
 
2551
    0,                                              /*tp_compare*/
 
2552
    0,                                              /*tp_repr*/
 
2553
    &Denorm_as_number,                              /*tp_as_number*/
 
2554
    0,                                              /*tp_as_sequence*/
 
2555
    0,                                              /*tp_as_mapping*/
 
2556
    0,                                              /*tp_hash */
 
2557
    0,                                              /*tp_call*/
 
2558
    0,                                              /*tp_str*/
 
2559
    0,                                              /*tp_getattro*/
 
2560
    0,                                              /*tp_setattro*/
 
2561
    0,                                              /*tp_as_buffer*/
 
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 */
 
2568
    0,                                              /* tp_iter */
 
2569
    0,                                              /* tp_iternext */
 
2570
    Denorm_methods,                                 /* tp_methods */
 
2571
    Denorm_members,                                 /* tp_members */
 
2572
    0,                                              /* tp_getset */
 
2573
    0,                                              /* tp_base */
 
2574
    0,                                              /* tp_dict */
 
2575
    0,                                              /* tp_descr_get */
 
2576
    0,                                              /* tp_descr_set */
 
2577
    0,                                              /* tp_dictoffset */
 
2578
    (initproc)Denorm_init,                          /* tp_init */
 
2579
    0,                                              /* tp_alloc */
 
2580
    Denorm_new,                                     /* tp_new */
 
2581
};
 
2582
 
 
2583
/************/
 
2584
/* DBToA */
 
2585
/************/
 
2586
typedef struct {
 
2587
    pyo_audio_HEAD
 
2588
    PyObject *input;
 
2589
    Stream *input_stream;
 
2590
    MYFLT lastdb;
 
2591
    MYFLT currentamp;
 
2592
    int modebuffer[2]; // need at least 2 slots for mul & add
 
2593
} DBToA;
 
2594
 
 
2595
static void
 
2596
DBToA_process(DBToA *self) {
 
2597
    int i;
 
2598
    MYFLT db;
 
2599
    MYFLT *in = Stream_getData((Stream *)self->input_stream);
 
2600
    
 
2601
    for (i=0; i<self->bufsize; i++) {
 
2602
        db = in[i];
 
2603
        if (db <= -120.0) {
 
2604
            self->data[i] = self->currentamp = 0.0;
 
2605
            self->lastdb = -120.0;
 
2606
        }
 
2607
        else if (db != self->lastdb) {
 
2608
            self->data[i] = self->currentamp = MYPOW(10.0, db * 0.05);
 
2609
            self->lastdb = db;
 
2610
        }
 
2611
        else
 
2612
            self->data[i] = self->currentamp;
 
2613
    }
 
2614
}
 
2615
 
 
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 };
 
2625
 
 
2626
static void
 
2627
DBToA_setProcMode(DBToA *self)
 
2628
{
 
2629
    int muladdmode;
 
2630
    muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
 
2631
    
 
2632
    self->proc_func_ptr = DBToA_process;
 
2633
    
 
2634
        switch (muladdmode) {
 
2635
        case 0:        
 
2636
            self->muladd_func_ptr = DBToA_postprocessing_ii;
 
2637
            break;
 
2638
        case 1:    
 
2639
            self->muladd_func_ptr = DBToA_postprocessing_ai;
 
2640
            break;
 
2641
        case 2:    
 
2642
            self->muladd_func_ptr = DBToA_postprocessing_revai;
 
2643
            break;
 
2644
        case 10:        
 
2645
            self->muladd_func_ptr = DBToA_postprocessing_ia;
 
2646
            break;
 
2647
        case 11:    
 
2648
            self->muladd_func_ptr = DBToA_postprocessing_aa;
 
2649
            break;
 
2650
        case 12:    
 
2651
            self->muladd_func_ptr = DBToA_postprocessing_revaa;
 
2652
            break;
 
2653
        case 20:        
 
2654
            self->muladd_func_ptr = DBToA_postprocessing_ireva;
 
2655
            break;
 
2656
        case 21:    
 
2657
            self->muladd_func_ptr = DBToA_postprocessing_areva;
 
2658
            break;
 
2659
        case 22:    
 
2660
            self->muladd_func_ptr = DBToA_postprocessing_revareva;
 
2661
            break;
 
2662
    }   
 
2663
}
 
2664
 
 
2665
static void
 
2666
DBToA_compute_next_data_frame(DBToA *self)
 
2667
{
 
2668
    (*self->proc_func_ptr)(self); 
 
2669
    (*self->muladd_func_ptr)(self);
 
2670
}
 
2671
 
 
2672
static int
 
2673
DBToA_traverse(DBToA *self, visitproc visit, void *arg)
 
2674
{
 
2675
    pyo_VISIT
 
2676
    Py_VISIT(self->input);
 
2677
    Py_VISIT(self->input_stream);
 
2678
    return 0;
 
2679
}
 
2680
 
 
2681
static int 
 
2682
DBToA_clear(DBToA *self)
 
2683
{
 
2684
    pyo_CLEAR
 
2685
    Py_CLEAR(self->input);
 
2686
    Py_CLEAR(self->input_stream);
 
2687
    return 0;
 
2688
}
 
2689
 
 
2690
static void
 
2691
DBToA_dealloc(DBToA* self)
 
2692
{
 
2693
    free(self->data);
 
2694
    DBToA_clear(self);
 
2695
    self->ob_type->tp_free((PyObject*)self);
 
2696
}
 
2697
 
 
2698
static PyObject * DBToA_deleteStream(DBToA *self) { DELETE_STREAM };
 
2699
 
 
2700
static PyObject *
 
2701
DBToA_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
2702
{
 
2703
    int i;
 
2704
    DBToA *self;
 
2705
    self = (DBToA *)type->tp_alloc(type, 0);
 
2706
    
 
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;
 
2711
    
 
2712
    INIT_OBJECT_COMMON
 
2713
    Stream_setFunctionPtr(self->stream, DBToA_compute_next_data_frame);
 
2714
    self->mode_func_ptr = DBToA_setProcMode;
 
2715
    return (PyObject *)self;
 
2716
}
 
2717
 
 
2718
static int
 
2719
DBToA_init(DBToA *self, PyObject *args, PyObject *kwds)
 
2720
{
 
2721
    PyObject *inputtmp, *input_streamtmp, *multmp=NULL, *addtmp=NULL;
 
2722
    
 
2723
    static char *kwlist[] = {"input", "mul", "add", NULL};
 
2724
    
 
2725
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
 
2726
        return -1; 
 
2727
    
 
2728
    INIT_INPUT_STREAM
 
2729
    
 
2730
    if (multmp) {
 
2731
        PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
 
2732
    }
 
2733
    
 
2734
    if (addtmp) {
 
2735
        PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
 
2736
    }
 
2737
    
 
2738
    Py_INCREF(self->stream);
 
2739
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
 
2740
    
 
2741
    (*self->mode_func_ptr)(self);
 
2742
    
 
2743
    
 
2744
    Py_INCREF(self);
 
2745
    return 0;
 
2746
}
 
2747
 
 
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 }; 
 
2754
 
 
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 };
 
2758
 
 
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 };
 
2767
 
 
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 */
 
2775
};
 
2776
 
 
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 */
 
2789
};
 
2790
 
 
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*/
 
2796
    0,                                              /*nb_remainder*/
 
2797
    0,                                              /*nb_divmod*/
 
2798
    0,                                              /*nb_power*/
 
2799
    0,                                              /*nb_neg*/
 
2800
    0,                                              /*nb_pos*/
 
2801
    0,                                              /*(unaryfunc)array_abs,*/
 
2802
    0,                                              /*nb_nonzero*/
 
2803
    0,                                              /*nb_invert*/
 
2804
    0,                                              /*nb_lshift*/
 
2805
    0,                                              /*nb_rshift*/
 
2806
    0,                                              /*nb_and*/
 
2807
    0,                                              /*nb_xor*/
 
2808
    0,                                              /*nb_or*/
 
2809
    0,                                              /*nb_coerce*/
 
2810
    0,                                              /*nb_int*/
 
2811
    0,                                              /*nb_long*/
 
2812
    0,                                              /*nb_float*/
 
2813
    0,                                              /*nb_oct*/
 
2814
    0,                                              /*nb_hex*/
 
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*/
 
2823
    0,                                              /*inplace_and*/
 
2824
    0,                                              /*inplace_xor*/
 
2825
    0,                                              /*inplace_or*/
 
2826
    0,                                              /*nb_floor_divide*/
 
2827
    0,                                              /*nb_true_divide*/
 
2828
    0,                                              /*nb_inplace_floor_divide*/
 
2829
    0,                                              /*nb_inplace_true_divide*/
 
2830
    0,                                              /* nb_index */
 
2831
};
 
2832
 
 
2833
PyTypeObject DBToAType = {
 
2834
    PyObject_HEAD_INIT(NULL)
 
2835
    0,                                              /*ob_size*/
 
2836
    "_pyo.DBToA_base",                                   /*tp_name*/
 
2837
    sizeof(DBToA),                                 /*tp_basicsize*/
 
2838
    0,                                              /*tp_itemsize*/
 
2839
    (destructor)DBToA_dealloc,                     /*tp_dealloc*/
 
2840
    0,                                              /*tp_print*/
 
2841
    0,                                              /*tp_getattr*/
 
2842
    0,                                              /*tp_setattr*/
 
2843
    0,                                              /*tp_compare*/
 
2844
    0,                                              /*tp_repr*/
 
2845
    &DBToA_as_number,                              /*tp_as_number*/
 
2846
    0,                                              /*tp_as_sequence*/
 
2847
    0,                                              /*tp_as_mapping*/
 
2848
    0,                                              /*tp_hash */
 
2849
    0,                                              /*tp_call*/
 
2850
    0,                                              /*tp_str*/
 
2851
    0,                                              /*tp_getattro*/
 
2852
    0,                                              /*tp_setattro*/
 
2853
    0,                                              /*tp_as_buffer*/
 
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 */
 
2860
    0,                                              /* tp_iter */
 
2861
    0,                                              /* tp_iternext */
 
2862
    DBToA_methods,                                 /* tp_methods */
 
2863
    DBToA_members,                                 /* tp_members */
 
2864
    0,                                              /* tp_getset */
 
2865
    0,                                              /* tp_base */
 
2866
    0,                                              /* tp_dict */
 
2867
    0,                                              /* tp_descr_get */
 
2868
    0,                                              /* tp_descr_set */
 
2869
    0,                                              /* tp_dictoffset */
 
2870
    (initproc)DBToA_init,                          /* tp_init */
 
2871
    0,                                              /* tp_alloc */
 
2872
    DBToA_new,                                     /* tp_new */
 
2873
};
 
2874
 
 
2875
/************/
 
2876
/* AToDB */
 
2877
/************/
 
2878
typedef struct {
 
2879
    pyo_audio_HEAD
 
2880
    PyObject *input;
 
2881
    Stream *input_stream;
 
2882
    MYFLT lastamp;
 
2883
    MYFLT currentdb;
 
2884
    int modebuffer[2]; // need at least 2 slots for mul & add
 
2885
} AToDB;
 
2886
 
 
2887
static void
 
2888
AToDB_process(AToDB *self) {
 
2889
    int i;
 
2890
    MYFLT amp;
 
2891
    MYFLT *in = Stream_getData((Stream *)self->input_stream);
 
2892
    
 
2893
    for (i=0; i<self->bufsize; i++) {
 
2894
        amp = in[i];
 
2895
        if (amp <= 0.000001) {
 
2896
            self->data[i] = self->currentdb = -120.0;
 
2897
            self->lastamp = 0.000001;
 
2898
        }
 
2899
        else if (amp != self->lastamp) {
 
2900
            self->data[i] = self->currentdb = 20.0 * MYLOG10(amp);
 
2901
            self->lastamp = amp;
 
2902
        }
 
2903
        else
 
2904
            self->data[i] = self->currentdb;
 
2905
    }
 
2906
}
 
2907
 
 
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 };
 
2917
 
 
2918
static void
 
2919
AToDB_setProcMode(AToDB *self)
 
2920
{
 
2921
    int muladdmode;
 
2922
    muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
 
2923
    
 
2924
    self->proc_func_ptr = AToDB_process;
 
2925
    
 
2926
        switch (muladdmode) {
 
2927
        case 0:        
 
2928
            self->muladd_func_ptr = AToDB_postprocessing_ii;
 
2929
            break;
 
2930
        case 1:    
 
2931
            self->muladd_func_ptr = AToDB_postprocessing_ai;
 
2932
            break;
 
2933
        case 2:    
 
2934
            self->muladd_func_ptr = AToDB_postprocessing_revai;
 
2935
            break;
 
2936
        case 10:        
 
2937
            self->muladd_func_ptr = AToDB_postprocessing_ia;
 
2938
            break;
 
2939
        case 11:    
 
2940
            self->muladd_func_ptr = AToDB_postprocessing_aa;
 
2941
            break;
 
2942
        case 12:    
 
2943
            self->muladd_func_ptr = AToDB_postprocessing_revaa;
 
2944
            break;
 
2945
        case 20:        
 
2946
            self->muladd_func_ptr = AToDB_postprocessing_ireva;
 
2947
            break;
 
2948
        case 21:    
 
2949
            self->muladd_func_ptr = AToDB_postprocessing_areva;
 
2950
            break;
 
2951
        case 22:    
 
2952
            self->muladd_func_ptr = AToDB_postprocessing_revareva;
 
2953
            break;
 
2954
    }   
 
2955
}
 
2956
 
 
2957
static void
 
2958
AToDB_compute_next_data_frame(AToDB *self)
 
2959
{
 
2960
    (*self->proc_func_ptr)(self); 
 
2961
    (*self->muladd_func_ptr)(self);
 
2962
}
 
2963
 
 
2964
static int
 
2965
AToDB_traverse(AToDB *self, visitproc visit, void *arg)
 
2966
{
 
2967
    pyo_VISIT
 
2968
    Py_VISIT(self->input);
 
2969
    Py_VISIT(self->input_stream);
 
2970
    return 0;
 
2971
}
 
2972
 
 
2973
static int 
 
2974
AToDB_clear(AToDB *self)
 
2975
{
 
2976
    pyo_CLEAR
 
2977
    Py_CLEAR(self->input);
 
2978
    Py_CLEAR(self->input_stream);
 
2979
    return 0;
 
2980
}
 
2981
 
 
2982
static void
 
2983
AToDB_dealloc(AToDB* self)
 
2984
{
 
2985
    free(self->data);
 
2986
    AToDB_clear(self);
 
2987
    self->ob_type->tp_free((PyObject*)self);
 
2988
}
 
2989
 
 
2990
static PyObject * AToDB_deleteStream(AToDB *self) { DELETE_STREAM };
 
2991
 
 
2992
static PyObject *
 
2993
AToDB_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
2994
{
 
2995
    int i;
 
2996
    AToDB *self;
 
2997
    self = (AToDB *)type->tp_alloc(type, 0);
 
2998
    
 
2999
    self->lastamp = 0.000001;
 
3000
    self->currentdb = 20.0 * MYLOG10(self->lastamp);
 
3001
        self->modebuffer[0] = 0;
 
3002
        self->modebuffer[1] = 0;
 
3003
    
 
3004
    INIT_OBJECT_COMMON
 
3005
    Stream_setFunctionPtr(self->stream, AToDB_compute_next_data_frame);
 
3006
    self->mode_func_ptr = AToDB_setProcMode;
 
3007
    return (PyObject *)self;
 
3008
}
 
3009
 
 
3010
static int
 
3011
AToDB_init(AToDB *self, PyObject *args, PyObject *kwds)
 
3012
{
 
3013
    PyObject *inputtmp, *input_streamtmp, *multmp=NULL, *addtmp=NULL;
 
3014
    
 
3015
    static char *kwlist[] = {"input", "mul", "add", NULL};
 
3016
    
 
3017
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
 
3018
        return -1; 
 
3019
    
 
3020
    INIT_INPUT_STREAM
 
3021
    
 
3022
    if (multmp) {
 
3023
        PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
 
3024
    }
 
3025
    
 
3026
    if (addtmp) {
 
3027
        PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
 
3028
    }
 
3029
    
 
3030
    Py_INCREF(self->stream);
 
3031
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
 
3032
    
 
3033
    (*self->mode_func_ptr)(self);
 
3034
    
 
3035
    
 
3036
    Py_INCREF(self);
 
3037
    return 0;
 
3038
}
 
3039
 
 
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 }; 
 
3046
 
 
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 };
 
3050
 
 
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 };
 
3059
 
 
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 */
 
3067
};
 
3068
 
 
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 */
 
3081
};
 
3082
 
 
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*/
 
3088
    0,                                              /*nb_remainder*/
 
3089
    0,                                              /*nb_divmod*/
 
3090
    0,                                              /*nb_power*/
 
3091
    0,                                              /*nb_neg*/
 
3092
    0,                                              /*nb_pos*/
 
3093
    0,                                              /*(unaryfunc)array_abs,*/
 
3094
    0,                                              /*nb_nonzero*/
 
3095
    0,                                              /*nb_invert*/
 
3096
    0,                                              /*nb_lshift*/
 
3097
    0,                                              /*nb_rshift*/
 
3098
    0,                                              /*nb_and*/
 
3099
    0,                                              /*nb_xor*/
 
3100
    0,                                              /*nb_or*/
 
3101
    0,                                              /*nb_coerce*/
 
3102
    0,                                              /*nb_int*/
 
3103
    0,                                              /*nb_long*/
 
3104
    0,                                              /*nb_float*/
 
3105
    0,                                              /*nb_oct*/
 
3106
    0,                                              /*nb_hex*/
 
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*/
 
3115
    0,                                              /*inplace_and*/
 
3116
    0,                                              /*inplace_xor*/
 
3117
    0,                                              /*inplace_or*/
 
3118
    0,                                              /*nb_floor_divide*/
 
3119
    0,                                              /*nb_true_divide*/
 
3120
    0,                                              /*nb_inplace_floor_divide*/
 
3121
    0,                                              /*nb_inplace_true_divide*/
 
3122
    0,                                              /* nb_index */
 
3123
};
 
3124
 
 
3125
PyTypeObject AToDBType = {
 
3126
    PyObject_HEAD_INIT(NULL)
 
3127
    0,                                              /*ob_size*/
 
3128
    "_pyo.AToDB_base",                                   /*tp_name*/
 
3129
    sizeof(AToDB),                                 /*tp_basicsize*/
 
3130
    0,                                              /*tp_itemsize*/
 
3131
    (destructor)AToDB_dealloc,                     /*tp_dealloc*/
 
3132
    0,                                              /*tp_print*/
 
3133
    0,                                              /*tp_getattr*/
 
3134
    0,                                              /*tp_setattr*/
 
3135
    0,                                              /*tp_compare*/
 
3136
    0,                                              /*tp_repr*/
 
3137
    &AToDB_as_number,                              /*tp_as_number*/
 
3138
    0,                                              /*tp_as_sequence*/
 
3139
    0,                                              /*tp_as_mapping*/
 
3140
    0,                                              /*tp_hash */
 
3141
    0,                                              /*tp_call*/
 
3142
    0,                                              /*tp_str*/
 
3143
    0,                                              /*tp_getattro*/
 
3144
    0,                                              /*tp_setattro*/
 
3145
    0,                                              /*tp_as_buffer*/
 
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 */
 
3152
    0,                                              /* tp_iter */
 
3153
    0,                                              /* tp_iternext */
 
3154
    AToDB_methods,                                 /* tp_methods */
 
3155
    AToDB_members,                                 /* tp_members */
 
3156
    0,                                              /* tp_getset */
 
3157
    0,                                              /* tp_base */
 
3158
    0,                                              /* tp_dict */
 
3159
    0,                                              /* tp_descr_get */
 
3160
    0,                                              /* tp_descr_set */
 
3161
    0,                                              /* tp_dictoffset */
 
3162
    (initproc)AToDB_init,                          /* tp_init */
 
3163
    0,                                              /* tp_alloc */
 
3164
    AToDB_new,                                     /* tp_new */
 
3165
};
 
3166
 
 
3167
/*********************************************************************************************/
 
3168
/* Scale ********************************************************************************/
 
3169
/*********************************************************************************************/
 
3170
typedef struct {
 
3171
    pyo_audio_HEAD
 
3172
    PyObject *input;
 
3173
    Stream *input_stream;
 
3174
    PyObject *inmin;
 
3175
    Stream *inmin_stream;
 
3176
    PyObject *inmax;
 
3177
    Stream *inmax_stream;
 
3178
    PyObject *outmin;
 
3179
    Stream *outmin_stream;
 
3180
    PyObject *outmax;
 
3181
    Stream *outmax_stream;
 
3182
    PyObject *exp;
 
3183
    Stream *exp_stream;
 
3184
    int modebuffer[7]; // need at least 2 slots for mul & add 
 
3185
} Scale;
 
3186
 
 
3187
static MYFLT
 
3188
_scale_clip(MYFLT x, MYFLT min, MYFLT max) {
 
3189
    if (x < min)
 
3190
        return min;
 
3191
    else if (x > max)
 
3192
        return max;
 
3193
    else
 
3194
        return x;
 
3195
}
 
3196
 
 
3197
static void
 
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);
 
3203
    
 
3204
    if (self->modebuffer[2] == 0)
 
3205
        inmin = PyFloat_AS_DOUBLE(self->inmin);
 
3206
    else
 
3207
        inmin = Stream_getData((Stream *)self->inmin_stream)[0];
 
3208
    if (self->modebuffer[3] == 0)
 
3209
        inmax = PyFloat_AS_DOUBLE(self->inmax);
 
3210
    else
 
3211
        inmax = Stream_getData((Stream *)self->inmax_stream)[0];
 
3212
    
 
3213
    if (inmin < inmax) {
 
3214
        inrev = 0;
 
3215
    }
 
3216
    else {
 
3217
        tmp = inmin;
 
3218
        inmin = inmax;
 
3219
        inmax = tmp;
 
3220
        inrev = 1;
 
3221
    }
 
3222
    inrange = inmax - inmin;
 
3223
 
 
3224
    if (self->modebuffer[4] == 0)
 
3225
        outmin = PyFloat_AS_DOUBLE(self->outmin);
 
3226
    else
 
3227
        outmin = Stream_getData((Stream *)self->outmin_stream)[0];
 
3228
    if (self->modebuffer[5] == 0)
 
3229
        outmax = PyFloat_AS_DOUBLE(self->outmax);
 
3230
    else
 
3231
        outmax = Stream_getData((Stream *)self->outmax_stream)[0];
 
3232
    
 
3233
    if (outmin < outmax) {
 
3234
        outrev = 0;
 
3235
    }
 
3236
    else {
 
3237
        tmp = outmin;
 
3238
        outmin = outmax;
 
3239
        outmax = tmp;
 
3240
        outrev = 1;
 
3241
    }
 
3242
    outrange = outmax - outmin;
 
3243
    
 
3244
    if (self->modebuffer[6] == 0)
 
3245
        exp = PyFloat_AS_DOUBLE(self->exp);
 
3246
    else
 
3247
        exp = Stream_getData((Stream *)self->exp_stream)[0];
 
3248
    if (exp < 0.0)
 
3249
        exp = 0.0;
 
3250
 
 
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;
 
3255
        }
 
3256
    }
 
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;
 
3263
            }            
 
3264
        }
 
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;
 
3269
            }
 
3270
        }
 
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);
 
3275
            }
 
3276
        }
 
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);
 
3281
            }
 
3282
        }
 
3283
    }
 
3284
    /* Exponential scaling */
 
3285
    else {
 
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;
 
3290
            }            
 
3291
        }
 
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;
 
3296
            }
 
3297
        }
 
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);
 
3302
            }
 
3303
        }
 
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);
 
3308
            }
 
3309
        }
 
3310
    }
 
3311
}
 
3312
 
 
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 };
 
3322
 
 
3323
static void
 
3324
Scale_setProcMode(Scale *self)
 
3325
{
 
3326
    int muladdmode;
 
3327
    muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
 
3328
    
 
3329
    self->proc_func_ptr = Scale_generate;
 
3330
    
 
3331
        switch (muladdmode) {
 
3332
        case 0:        
 
3333
            self->muladd_func_ptr = Scale_postprocessing_ii;
 
3334
            break;
 
3335
        case 1:    
 
3336
            self->muladd_func_ptr = Scale_postprocessing_ai;
 
3337
            break;
 
3338
        case 2:    
 
3339
            self->muladd_func_ptr = Scale_postprocessing_revai;
 
3340
            break;
 
3341
        case 10:        
 
3342
            self->muladd_func_ptr = Scale_postprocessing_ia;
 
3343
            break;
 
3344
        case 11:    
 
3345
            self->muladd_func_ptr = Scale_postprocessing_aa;
 
3346
            break;
 
3347
        case 12:    
 
3348
            self->muladd_func_ptr = Scale_postprocessing_revaa;
 
3349
            break;
 
3350
        case 20:        
 
3351
            self->muladd_func_ptr = Scale_postprocessing_ireva;
 
3352
            break;
 
3353
        case 21:    
 
3354
            self->muladd_func_ptr = Scale_postprocessing_areva;
 
3355
            break;
 
3356
        case 22:    
 
3357
            self->muladd_func_ptr = Scale_postprocessing_revareva;
 
3358
            break;
 
3359
    }  
 
3360
}
 
3361
 
 
3362
static void
 
3363
Scale_compute_next_data_frame(Scale *self)
 
3364
{
 
3365
    (*self->proc_func_ptr)(self); 
 
3366
    (*self->muladd_func_ptr)(self);
 
3367
}
 
3368
 
 
3369
static int
 
3370
Scale_traverse(Scale *self, visitproc visit, void *arg)
 
3371
{
 
3372
    pyo_VISIT
 
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);
 
3385
    return 0;
 
3386
}
 
3387
 
 
3388
static int 
 
3389
Scale_clear(Scale *self)
 
3390
{
 
3391
    pyo_CLEAR
 
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);
 
3404
    return 0;
 
3405
}
 
3406
 
 
3407
static void
 
3408
Scale_dealloc(Scale* self)
 
3409
{
 
3410
    free(self->data);
 
3411
    Scale_clear(self);
 
3412
    self->ob_type->tp_free((PyObject*)self);
 
3413
}
 
3414
 
 
3415
static PyObject * Scale_deleteStream(Scale *self) { DELETE_STREAM };
 
3416
 
 
3417
static PyObject *
 
3418
Scale_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
3419
{
 
3420
    int i;
 
3421
    Scale *self;
 
3422
    self = (Scale *)type->tp_alloc(type, 0);
 
3423
    
 
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;
 
3436
    
 
3437
    INIT_OBJECT_COMMON
 
3438
    Stream_setFunctionPtr(self->stream, Scale_compute_next_data_frame);
 
3439
    self->mode_func_ptr = Scale_setProcMode;
 
3440
    return (PyObject *)self;
 
3441
}
 
3442
 
 
3443
static int
 
3444
Scale_init(Scale *self, PyObject *args, PyObject *kwds)
 
3445
{
 
3446
    PyObject *inputtmp, *input_streamtmp, *inmintmp=NULL, *inmaxtmp=NULL, *outmintmp=NULL, *outmaxtmp=NULL, *exptmp=NULL, *multmp=NULL, *addtmp=NULL;
 
3447
    
 
3448
    static char *kwlist[] = {"input", "inmin", "inmax", "outmin", "outmax", "exp", "mul", "add", NULL};
 
3449
    
 
3450
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OOOOOOO", kwlist, &inputtmp, &inmintmp, &inmaxtmp, &outmintmp, &outmaxtmp, &exptmp, &multmp, &addtmp))
 
3451
        return -1; 
 
3452
    
 
3453
    INIT_INPUT_STREAM
 
3454
    
 
3455
    if (inmintmp) {
 
3456
        PyObject_CallMethod((PyObject *)self, "setInMin", "O", inmintmp);
 
3457
    }
 
3458
 
 
3459
    if (inmaxtmp) {
 
3460
        PyObject_CallMethod((PyObject *)self, "setInMax", "O", inmaxtmp);
 
3461
    }
 
3462
 
 
3463
    if (outmintmp) {
 
3464
        PyObject_CallMethod((PyObject *)self, "setOutMin", "O", outmintmp);
 
3465
    }
 
3466
 
 
3467
    if (outmaxtmp) {
 
3468
        PyObject_CallMethod((PyObject *)self, "setOutMax", "O", outmaxtmp);
 
3469
    }
 
3470
 
 
3471
    if (exptmp) {
 
3472
        PyObject_CallMethod((PyObject *)self, "setExp", "O", exptmp);
 
3473
    }
 
3474
    
 
3475
    if (multmp) {
 
3476
        PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
 
3477
    }
 
3478
    
 
3479
    if (addtmp) {
 
3480
        PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
 
3481
    }
 
3482
    
 
3483
    Py_INCREF(self->stream);
 
3484
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
 
3485
    
 
3486
    (*self->mode_func_ptr)(self);
 
3487
    
 
3488
    Py_INCREF(self);
 
3489
    return 0;
 
3490
}
 
3491
 
 
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 }; 
 
3498
 
 
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 };
 
3502
 
 
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 };
 
3511
 
 
3512
static PyObject *
 
3513
Scale_setInMin(Scale *self, PyObject *arg)
 
3514
{
 
3515
        PyObject *tmp, *streamtmp;
 
3516
        
 
3517
        if (arg == NULL) {
 
3518
                Py_INCREF(Py_None);
 
3519
                return Py_None;
 
3520
        }
 
3521
    
 
3522
        int isNumber = PyNumber_Check(arg);
 
3523
        
 
3524
        tmp = arg;
 
3525
        Py_INCREF(tmp);
 
3526
        Py_DECREF(self->inmin);
 
3527
        if (isNumber == 1) {
 
3528
                self->inmin = PyNumber_Float(tmp);
 
3529
        self->modebuffer[2] = 0;
 
3530
        }
 
3531
        else {
 
3532
                self->inmin = tmp;
 
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;
 
3538
        }
 
3539
    
 
3540
    (*self->mode_func_ptr)(self);
 
3541
    
 
3542
        Py_INCREF(Py_None);
 
3543
        return Py_None;
 
3544
}       
 
3545
 
 
3546
static PyObject *
 
3547
Scale_setInMax(Scale *self, PyObject *arg)
 
3548
{
 
3549
        PyObject *tmp, *streamtmp;
 
3550
        
 
3551
        if (arg == NULL) {
 
3552
                Py_INCREF(Py_None);
 
3553
                return Py_None;
 
3554
        }
 
3555
    
 
3556
        int isNumber = PyNumber_Check(arg);
 
3557
        
 
3558
        tmp = arg;
 
3559
        Py_INCREF(tmp);
 
3560
        Py_DECREF(self->inmax);
 
3561
        if (isNumber == 1) {
 
3562
                self->inmax = PyNumber_Float(tmp);
 
3563
        self->modebuffer[3] = 0;
 
3564
        }
 
3565
        else {
 
3566
                self->inmax = tmp;
 
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;
 
3572
        }
 
3573
    
 
3574
    (*self->mode_func_ptr)(self);
 
3575
    
 
3576
        Py_INCREF(Py_None);
 
3577
        return Py_None;
 
3578
}       
 
3579
 
 
3580
static PyObject *
 
3581
Scale_setOutMin(Scale *self, PyObject *arg)
 
3582
{
 
3583
        PyObject *tmp, *streamtmp;
 
3584
        
 
3585
        if (arg == NULL) {
 
3586
                Py_INCREF(Py_None);
 
3587
                return Py_None;
 
3588
        }
 
3589
    
 
3590
        int isNumber = PyNumber_Check(arg);
 
3591
        
 
3592
        tmp = arg;
 
3593
        Py_INCREF(tmp);
 
3594
        Py_DECREF(self->outmin);
 
3595
        if (isNumber == 1) {
 
3596
                self->outmin = PyNumber_Float(tmp);
 
3597
        self->modebuffer[4] = 0;
 
3598
        }
 
3599
        else {
 
3600
                self->outmin = tmp;
 
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;
 
3606
        }
 
3607
    
 
3608
    (*self->mode_func_ptr)(self);
 
3609
    
 
3610
        Py_INCREF(Py_None);
 
3611
        return Py_None;
 
3612
}       
 
3613
 
 
3614
static PyObject *
 
3615
Scale_setOutMax(Scale *self, PyObject *arg)
 
3616
{
 
3617
        PyObject *tmp, *streamtmp;
 
3618
        
 
3619
        if (arg == NULL) {
 
3620
                Py_INCREF(Py_None);
 
3621
                return Py_None;
 
3622
        }
 
3623
    
 
3624
        int isNumber = PyNumber_Check(arg);
 
3625
        
 
3626
        tmp = arg;
 
3627
        Py_INCREF(tmp);
 
3628
        Py_DECREF(self->outmax);
 
3629
        if (isNumber == 1) {
 
3630
                self->outmax = PyNumber_Float(tmp);
 
3631
        self->modebuffer[5] = 0;
 
3632
        }
 
3633
        else {
 
3634
                self->outmax = tmp;
 
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;
 
3640
        }
 
3641
    
 
3642
    (*self->mode_func_ptr)(self);
 
3643
    
 
3644
        Py_INCREF(Py_None);
 
3645
        return Py_None;
 
3646
}       
 
3647
 
 
3648
static PyObject *
 
3649
Scale_setExp(Scale *self, PyObject *arg)
 
3650
{
 
3651
        PyObject *tmp, *streamtmp;
 
3652
        
 
3653
        if (arg == NULL) {
 
3654
                Py_INCREF(Py_None);
 
3655
                return Py_None;
 
3656
        }
 
3657
    
 
3658
        int isNumber = PyNumber_Check(arg);
 
3659
        
 
3660
        tmp = arg;
 
3661
        Py_INCREF(tmp);
 
3662
        Py_DECREF(self->exp);
 
3663
        if (isNumber == 1) {
 
3664
                self->exp = PyNumber_Float(tmp);
 
3665
        self->modebuffer[6] = 0;
 
3666
        }
 
3667
        else {
 
3668
                self->exp = tmp;
 
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;
 
3674
        }
 
3675
    
 
3676
    (*self->mode_func_ptr)(self);
 
3677
    
 
3678
        Py_INCREF(Py_None);
 
3679
        return Py_None;
 
3680
}       
 
3681
 
 
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 */
 
3689
};
 
3690
 
 
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 */
 
3708
};
 
3709
 
 
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*/
 
3715
    0,                                              /*nb_remainder*/
 
3716
    0,                                              /*nb_divmod*/
 
3717
    0,                                              /*nb_power*/
 
3718
    0,                                              /*nb_neg*/
 
3719
    0,                                              /*nb_pos*/
 
3720
    0,                                              /*(unaryfunc)array_abs,*/
 
3721
    0,                                              /*nb_nonzero*/
 
3722
    0,                                              /*nb_invert*/
 
3723
    0,                                              /*nb_lshift*/
 
3724
    0,                                              /*nb_rshift*/
 
3725
    0,                                              /*nb_and*/
 
3726
    0,                                              /*nb_xor*/
 
3727
    0,                                              /*nb_or*/
 
3728
    0,                                              /*nb_coerce*/
 
3729
    0,                                              /*nb_int*/
 
3730
    0,                                              /*nb_long*/
 
3731
    0,                                              /*nb_float*/
 
3732
    0,                                              /*nb_oct*/
 
3733
    0,                                              /*nb_hex*/
 
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*/
 
3742
    0,                                              /*inplace_and*/
 
3743
    0,                                              /*inplace_xor*/
 
3744
    0,                                              /*inplace_or*/
 
3745
    0,                                              /*nb_floor_divide*/
 
3746
    0,                                              /*nb_true_divide*/
 
3747
    0,                                              /*nb_inplace_floor_divide*/
 
3748
    0,                                              /*nb_inplace_true_divide*/
 
3749
    0,                                              /* nb_index */
 
3750
};
 
3751
 
 
3752
PyTypeObject ScaleType = {
 
3753
    PyObject_HEAD_INIT(NULL)
 
3754
    0,                                              /*ob_size*/
 
3755
    "_pyo.Scale_base",                                   /*tp_name*/
 
3756
    sizeof(Scale),                                 /*tp_basicsize*/
 
3757
    0,                                              /*tp_itemsize*/
 
3758
    (destructor)Scale_dealloc,                     /*tp_dealloc*/
 
3759
    0,                                              /*tp_print*/
 
3760
    0,                                              /*tp_getattr*/
 
3761
    0,                                              /*tp_setattr*/
 
3762
    0,                                              /*tp_compare*/
 
3763
    0,                                              /*tp_repr*/
 
3764
    &Scale_as_number,                              /*tp_as_number*/
 
3765
    0,                                              /*tp_as_sequence*/
 
3766
    0,                                              /*tp_as_mapping*/
 
3767
    0,                                              /*tp_hash */
 
3768
    0,                                              /*tp_call*/
 
3769
    0,                                              /*tp_str*/
 
3770
    0,                                              /*tp_getattro*/
 
3771
    0,                                              /*tp_setattro*/
 
3772
    0,                                              /*tp_as_buffer*/
 
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 */
 
3779
    0,                                              /* tp_iter */
 
3780
    0,                                              /* tp_iternext */
 
3781
    Scale_methods,                                 /* tp_methods */
 
3782
    Scale_members,                                 /* tp_members */
 
3783
    0,                                              /* tp_getset */
 
3784
    0,                                              /* tp_base */
 
3785
    0,                                              /* tp_dict */
 
3786
    0,                                              /* tp_descr_get */
 
3787
    0,                                              /* tp_descr_set */
 
3788
    0,                                              /* tp_dictoffset */
 
3789
    (initproc)Scale_init,                          /* tp_init */
 
3790
    0,                                              /* tp_alloc */
 
3791
    Scale_new,                                     /* tp_new */
 
3792
};
 
3793
 
 
3794
/************/
 
3795
/* CentsToTranspo */
 
3796
/************/
 
3797
typedef struct {
 
3798
    pyo_audio_HEAD
 
3799
    PyObject *input;
 
3800
    Stream *input_stream;
 
3801
    MYFLT lastcents;
 
3802
    MYFLT curtranspo;
 
3803
    int modebuffer[2]; // need at least 2 slots for mul & add
 
3804
} CentsToTranspo;
 
3805
 
 
3806
static void
 
3807
CentsToTranspo_process(CentsToTranspo *self) {
 
3808
    int i;
 
3809
    MYFLT cents;
 
3810
    MYFLT *in = Stream_getData((Stream *)self->input_stream);
 
3811
    
 
3812
    for (i=0; i<self->bufsize; i++) {
 
3813
        cents = in[i];
 
3814
        if (cents != self->lastcents) {
 
3815
            self->data[i] = self->curtranspo = MYPOW(2.0, cents / 1200.);
 
3816
            self->lastcents = cents;
 
3817
        }
 
3818
        else
 
3819
            self->data[i] = self->curtranspo;
 
3820
    }
 
3821
}
 
3822
 
 
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 };
 
3832
 
 
3833
static void
 
3834
CentsToTranspo_setProcMode(CentsToTranspo *self)
 
3835
{
 
3836
    int muladdmode;
 
3837
    muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
 
3838
    
 
3839
    self->proc_func_ptr = CentsToTranspo_process;
 
3840
    
 
3841
        switch (muladdmode) {
 
3842
        case 0:        
 
3843
            self->muladd_func_ptr = CentsToTranspo_postprocessing_ii;
 
3844
            break;
 
3845
        case 1:    
 
3846
            self->muladd_func_ptr = CentsToTranspo_postprocessing_ai;
 
3847
            break;
 
3848
        case 2:    
 
3849
            self->muladd_func_ptr = CentsToTranspo_postprocessing_revai;
 
3850
            break;
 
3851
        case 10:        
 
3852
            self->muladd_func_ptr = CentsToTranspo_postprocessing_ia;
 
3853
            break;
 
3854
        case 11:    
 
3855
            self->muladd_func_ptr = CentsToTranspo_postprocessing_aa;
 
3856
            break;
 
3857
        case 12:    
 
3858
            self->muladd_func_ptr = CentsToTranspo_postprocessing_revaa;
 
3859
            break;
 
3860
        case 20:        
 
3861
            self->muladd_func_ptr = CentsToTranspo_postprocessing_ireva;
 
3862
            break;
 
3863
        case 21:    
 
3864
            self->muladd_func_ptr = CentsToTranspo_postprocessing_areva;
 
3865
            break;
 
3866
        case 22:    
 
3867
            self->muladd_func_ptr = CentsToTranspo_postprocessing_revareva;
 
3868
            break;
 
3869
    }   
 
3870
}
 
3871
 
 
3872
static void
 
3873
CentsToTranspo_compute_next_data_frame(CentsToTranspo *self)
 
3874
{
 
3875
    (*self->proc_func_ptr)(self); 
 
3876
    (*self->muladd_func_ptr)(self);
 
3877
}
 
3878
 
 
3879
static int
 
3880
CentsToTranspo_traverse(CentsToTranspo *self, visitproc visit, void *arg)
 
3881
{
 
3882
    pyo_VISIT
 
3883
    Py_VISIT(self->input);
 
3884
    Py_VISIT(self->input_stream);
 
3885
    return 0;
 
3886
}
 
3887
 
 
3888
static int 
 
3889
CentsToTranspo_clear(CentsToTranspo *self)
 
3890
{
 
3891
    pyo_CLEAR
 
3892
    Py_CLEAR(self->input);
 
3893
    Py_CLEAR(self->input_stream);
 
3894
    return 0;
 
3895
}
 
3896
 
 
3897
static void
 
3898
CentsToTranspo_dealloc(CentsToTranspo* self)
 
3899
{
 
3900
    free(self->data);
 
3901
    CentsToTranspo_clear(self);
 
3902
    self->ob_type->tp_free((PyObject*)self);
 
3903
}
 
3904
 
 
3905
static PyObject * CentsToTranspo_deleteStream(CentsToTranspo *self) { DELETE_STREAM };
 
3906
 
 
3907
static PyObject *
 
3908
CentsToTranspo_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
3909
{
 
3910
    int i;
 
3911
    CentsToTranspo *self;
 
3912
    self = (CentsToTranspo *)type->tp_alloc(type, 0);
 
3913
    
 
3914
    self->lastcents = 0.0;
 
3915
    self->curtranspo = 1.0;
 
3916
        self->modebuffer[0] = 0;
 
3917
        self->modebuffer[1] = 0;
 
3918
    
 
3919
    INIT_OBJECT_COMMON
 
3920
    Stream_setFunctionPtr(self->stream, CentsToTranspo_compute_next_data_frame);
 
3921
    self->mode_func_ptr = CentsToTranspo_setProcMode;
 
3922
    return (PyObject *)self;
 
3923
}
 
3924
 
 
3925
static int
 
3926
CentsToTranspo_init(CentsToTranspo *self, PyObject *args, PyObject *kwds)
 
3927
{
 
3928
    PyObject *inputtmp, *input_streamtmp, *multmp=NULL, *addtmp=NULL;
 
3929
    
 
3930
    static char *kwlist[] = {"input", "mul", "add", NULL};
 
3931
    
 
3932
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
 
3933
        return -1; 
 
3934
    
 
3935
    INIT_INPUT_STREAM
 
3936
    
 
3937
    if (multmp) {
 
3938
        PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
 
3939
    }
 
3940
    
 
3941
    if (addtmp) {
 
3942
        PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
 
3943
    }
 
3944
    
 
3945
    Py_INCREF(self->stream);
 
3946
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
 
3947
    
 
3948
    (*self->mode_func_ptr)(self);
 
3949
    
 
3950
    
 
3951
    Py_INCREF(self);
 
3952
    return 0;
 
3953
}
 
3954
 
 
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 };       
 
3961
 
 
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 };
 
3965
 
 
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 };
 
3974
 
 
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 */
 
3982
};
 
3983
 
 
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 */
 
3996
};
 
3997
 
 
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*/
 
4003
    0,                                              /*nb_remainder*/
 
4004
    0,                                              /*nb_divmod*/
 
4005
    0,                                              /*nb_power*/
 
4006
    0,                                              /*nb_neg*/
 
4007
    0,                                              /*nb_pos*/
 
4008
    0,                                              /*(unaryfunc)array_abs,*/
 
4009
    0,                                              /*nb_nonzero*/
 
4010
    0,                                              /*nb_invert*/
 
4011
    0,                                              /*nb_lshift*/
 
4012
    0,                                              /*nb_rshift*/
 
4013
    0,                                              /*nb_and*/
 
4014
    0,                                              /*nb_xor*/
 
4015
    0,                                              /*nb_or*/
 
4016
    0,                                              /*nb_coerce*/
 
4017
    0,                                              /*nb_int*/
 
4018
    0,                                              /*nb_long*/
 
4019
    0,                                              /*nb_float*/
 
4020
    0,                                              /*nb_oct*/
 
4021
    0,                                              /*nb_hex*/
 
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*/
 
4030
    0,                                              /*inplace_and*/
 
4031
    0,                                              /*inplace_xor*/
 
4032
    0,                                              /*inplace_or*/
 
4033
    0,                                              /*nb_floor_divide*/
 
4034
    0,                                              /*nb_true_divide*/
 
4035
    0,                                              /*nb_inplace_floor_divide*/
 
4036
    0,                                              /*nb_inplace_true_divide*/
 
4037
    0,                                              /* nb_index */
 
4038
};
 
4039
 
 
4040
PyTypeObject CentsToTranspoType = {
 
4041
    PyObject_HEAD_INIT(NULL)
 
4042
    0,                                              /*ob_size*/
 
4043
    "_pyo.CentsToTranspo_base",                                   /*tp_name*/
 
4044
    sizeof(CentsToTranspo),                                 /*tp_basicsize*/
 
4045
    0,                                              /*tp_itemsize*/
 
4046
    (destructor)CentsToTranspo_dealloc,                     /*tp_dealloc*/
 
4047
    0,                                              /*tp_print*/
 
4048
    0,                                              /*tp_getattr*/
 
4049
    0,                                              /*tp_setattr*/
 
4050
    0,                                              /*tp_compare*/
 
4051
    0,                                              /*tp_repr*/
 
4052
    &CentsToTranspo_as_number,                              /*tp_as_number*/
 
4053
    0,                                              /*tp_as_sequence*/
 
4054
    0,                                              /*tp_as_mapping*/
 
4055
    0,                                              /*tp_hash */
 
4056
    0,                                              /*tp_call*/
 
4057
    0,                                              /*tp_str*/
 
4058
    0,                                              /*tp_getattro*/
 
4059
    0,                                              /*tp_setattro*/
 
4060
    0,                                              /*tp_as_buffer*/
 
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 */
 
4067
    0,                                              /* tp_iter */
 
4068
    0,                                              /* tp_iternext */
 
4069
    CentsToTranspo_methods,                                 /* tp_methods */
 
4070
    CentsToTranspo_members,                                 /* tp_members */
 
4071
    0,                                              /* tp_getset */
 
4072
    0,                                              /* tp_base */
 
4073
    0,                                              /* tp_dict */
 
4074
    0,                                              /* tp_descr_get */
 
4075
    0,                                              /* tp_descr_set */
 
4076
    0,                                              /* tp_dictoffset */
 
4077
    (initproc)CentsToTranspo_init,                          /* tp_init */
 
4078
    0,                                              /* tp_alloc */
 
4079
    CentsToTranspo_new,                                     /* tp_new */
 
4080
};
 
4081
 
 
4082
/************/
 
4083
/* TranspoToCents */
 
4084
/************/
 
4085
typedef struct {
 
4086
    pyo_audio_HEAD
 
4087
    PyObject *input;
 
4088
    Stream *input_stream;
 
4089
    MYFLT lasttranspo;
 
4090
    MYFLT curcents;
 
4091
    int modebuffer[2]; // need at least 2 slots for mul & add
 
4092
} TranspoToCents;
 
4093
 
 
4094
static void
 
4095
TranspoToCents_process(TranspoToCents *self) {
 
4096
    int i;
 
4097
    MYFLT transpo;
 
4098
    MYFLT *in = Stream_getData((Stream *)self->input_stream);
 
4099
    
 
4100
    for (i=0; i<self->bufsize; i++) {
 
4101
        transpo = in[i];
 
4102
        if (transpo != self->lasttranspo) {
 
4103
            self->data[i] = self->curcents = 1200.0 * MYLOG2(transpo);
 
4104
            self->lasttranspo = transpo;
 
4105
        }
 
4106
        else
 
4107
            self->data[i] = self->curcents;
 
4108
    }
 
4109
}
 
4110
 
 
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 };
 
4120
 
 
4121
static void
 
4122
TranspoToCents_setProcMode(TranspoToCents *self)
 
4123
{
 
4124
    int muladdmode;
 
4125
    muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
 
4126
    
 
4127
    self->proc_func_ptr = TranspoToCents_process;
 
4128
    
 
4129
        switch (muladdmode) {
 
4130
        case 0:        
 
4131
            self->muladd_func_ptr = TranspoToCents_postprocessing_ii;
 
4132
            break;
 
4133
        case 1:    
 
4134
            self->muladd_func_ptr = TranspoToCents_postprocessing_ai;
 
4135
            break;
 
4136
        case 2:    
 
4137
            self->muladd_func_ptr = TranspoToCents_postprocessing_revai;
 
4138
            break;
 
4139
        case 10:        
 
4140
            self->muladd_func_ptr = TranspoToCents_postprocessing_ia;
 
4141
            break;
 
4142
        case 11:    
 
4143
            self->muladd_func_ptr = TranspoToCents_postprocessing_aa;
 
4144
            break;
 
4145
        case 12:    
 
4146
            self->muladd_func_ptr = TranspoToCents_postprocessing_revaa;
 
4147
            break;
 
4148
        case 20:        
 
4149
            self->muladd_func_ptr = TranspoToCents_postprocessing_ireva;
 
4150
            break;
 
4151
        case 21:    
 
4152
            self->muladd_func_ptr = TranspoToCents_postprocessing_areva;
 
4153
            break;
 
4154
        case 22:    
 
4155
            self->muladd_func_ptr = TranspoToCents_postprocessing_revareva;
 
4156
            break;
 
4157
    }   
 
4158
}
 
4159
 
 
4160
static void
 
4161
TranspoToCents_compute_next_data_frame(TranspoToCents *self)
 
4162
{
 
4163
    (*self->proc_func_ptr)(self); 
 
4164
    (*self->muladd_func_ptr)(self);
 
4165
}
 
4166
 
 
4167
static int
 
4168
TranspoToCents_traverse(TranspoToCents *self, visitproc visit, void *arg)
 
4169
{
 
4170
    pyo_VISIT
 
4171
    Py_VISIT(self->input);
 
4172
    Py_VISIT(self->input_stream);
 
4173
    return 0;
 
4174
}
 
4175
 
 
4176
static int 
 
4177
TranspoToCents_clear(TranspoToCents *self)
 
4178
{
 
4179
    pyo_CLEAR
 
4180
    Py_CLEAR(self->input);
 
4181
    Py_CLEAR(self->input_stream);
 
4182
    return 0;
 
4183
}
 
4184
 
 
4185
static void
 
4186
TranspoToCents_dealloc(TranspoToCents* self)
 
4187
{
 
4188
    free(self->data);
 
4189
    TranspoToCents_clear(self);
 
4190
    self->ob_type->tp_free((PyObject*)self);
 
4191
}
 
4192
 
 
4193
static PyObject * TranspoToCents_deleteStream(TranspoToCents *self) { DELETE_STREAM };
 
4194
 
 
4195
static PyObject *
 
4196
TranspoToCents_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
4197
{
 
4198
    int i;
 
4199
    TranspoToCents *self;
 
4200
    self = (TranspoToCents *)type->tp_alloc(type, 0);
 
4201
    
 
4202
    self->lasttranspo = 1.0;
 
4203
    self->curcents = 0.0;
 
4204
        self->modebuffer[0] = 0;
 
4205
        self->modebuffer[1] = 0;
 
4206
    
 
4207
    INIT_OBJECT_COMMON
 
4208
    Stream_setFunctionPtr(self->stream, TranspoToCents_compute_next_data_frame);
 
4209
    self->mode_func_ptr = TranspoToCents_setProcMode;
 
4210
    return (PyObject *)self;
 
4211
}
 
4212
 
 
4213
static int
 
4214
TranspoToCents_init(TranspoToCents *self, PyObject *args, PyObject *kwds)
 
4215
{
 
4216
    PyObject *inputtmp, *input_streamtmp, *multmp=NULL, *addtmp=NULL;
 
4217
    
 
4218
    static char *kwlist[] = {"input", "mul", "add", NULL};
 
4219
    
 
4220
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
 
4221
        return -1; 
 
4222
    
 
4223
    INIT_INPUT_STREAM
 
4224
    
 
4225
    if (multmp) {
 
4226
        PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
 
4227
    }
 
4228
    
 
4229
    if (addtmp) {
 
4230
        PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
 
4231
    }
 
4232
    
 
4233
    Py_INCREF(self->stream);
 
4234
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
 
4235
    
 
4236
    (*self->mode_func_ptr)(self);
 
4237
    
 
4238
    
 
4239
    Py_INCREF(self);
 
4240
    return 0;
 
4241
}
 
4242
 
 
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 };       
 
4249
 
 
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 };
 
4253
 
 
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 };
 
4262
 
 
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 */
 
4270
};
 
4271
 
 
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 */
 
4284
};
 
4285
 
 
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*/
 
4291
    0,                                              /*nb_remainder*/
 
4292
    0,                                              /*nb_divmod*/
 
4293
    0,                                              /*nb_power*/
 
4294
    0,                                              /*nb_neg*/
 
4295
    0,                                              /*nb_pos*/
 
4296
    0,                                              /*(unaryfunc)array_abs,*/
 
4297
    0,                                              /*nb_nonzero*/
 
4298
    0,                                              /*nb_invert*/
 
4299
    0,                                              /*nb_lshift*/
 
4300
    0,                                              /*nb_rshift*/
 
4301
    0,                                              /*nb_and*/
 
4302
    0,                                              /*nb_xor*/
 
4303
    0,                                              /*nb_or*/
 
4304
    0,                                              /*nb_coerce*/
 
4305
    0,                                              /*nb_int*/
 
4306
    0,                                              /*nb_long*/
 
4307
    0,                                              /*nb_float*/
 
4308
    0,                                              /*nb_oct*/
 
4309
    0,                                              /*nb_hex*/
 
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*/
 
4318
    0,                                              /*inplace_and*/
 
4319
    0,                                              /*inplace_xor*/
 
4320
    0,                                              /*inplace_or*/
 
4321
    0,                                              /*nb_floor_divide*/
 
4322
    0,                                              /*nb_true_divide*/
 
4323
    0,                                              /*nb_inplace_floor_divide*/
 
4324
    0,                                              /*nb_inplace_true_divide*/
 
4325
    0,                                              /* nb_index */
 
4326
};
 
4327
 
 
4328
PyTypeObject TranspoToCentsType = {
 
4329
    PyObject_HEAD_INIT(NULL)
 
4330
    0,                                              /*ob_size*/
 
4331
    "_pyo.TranspoToCents_base",                                   /*tp_name*/
 
4332
    sizeof(TranspoToCents),                                 /*tp_basicsize*/
 
4333
    0,                                              /*tp_itemsize*/
 
4334
    (destructor)TranspoToCents_dealloc,                     /*tp_dealloc*/
 
4335
    0,                                              /*tp_print*/
 
4336
    0,                                              /*tp_getattr*/
 
4337
    0,                                              /*tp_setattr*/
 
4338
    0,                                              /*tp_compare*/
 
4339
    0,                                              /*tp_repr*/
 
4340
    &TranspoToCents_as_number,                              /*tp_as_number*/
 
4341
    0,                                              /*tp_as_sequence*/
 
4342
    0,                                              /*tp_as_mapping*/
 
4343
    0,                                              /*tp_hash */
 
4344
    0,                                              /*tp_call*/
 
4345
    0,                                              /*tp_str*/
 
4346
    0,                                              /*tp_getattro*/
 
4347
    0,                                              /*tp_setattro*/
 
4348
    0,                                              /*tp_as_buffer*/
 
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 */
 
4355
    0,                                              /* tp_iter */
 
4356
    0,                                              /* tp_iternext */
 
4357
    TranspoToCents_methods,                                 /* tp_methods */
 
4358
    TranspoToCents_members,                                 /* tp_members */
 
4359
    0,                                              /* tp_getset */
 
4360
    0,                                              /* tp_base */
 
4361
    0,                                              /* tp_dict */
 
4362
    0,                                              /* tp_descr_get */
 
4363
    0,                                              /* tp_descr_set */
 
4364
    0,                                              /* tp_dictoffset */
 
4365
    (initproc)TranspoToCents_init,                          /* tp_init */
 
4366
    0,                                              /* tp_alloc */
 
4367
    TranspoToCents_new,                                     /* tp_new */
 
4368
};
 
4369
 
 
4370
/************/
 
4371
/* MToF */
 
4372
/************/
 
4373
typedef struct {
 
4374
    pyo_audio_HEAD
 
4375
    PyObject *input;
 
4376
    Stream *input_stream;
 
4377
    MYFLT lastmidi;
 
4378
    MYFLT curfreq;
 
4379
    int modebuffer[2]; // need at least 2 slots for mul & add
 
4380
} MToF;
 
4381
 
 
4382
static void
 
4383
MToF_process(MToF *self) {
 
4384
    int i;
 
4385
    MYFLT midi;
 
4386
    MYFLT *in = Stream_getData((Stream *)self->input_stream);
 
4387
    
 
4388
    for (i=0; i<self->bufsize; i++) {
 
4389
        midi = in[i];
 
4390
        if (midi != self->lastmidi) {
 
4391
            self->data[i] = self->curfreq = 8.1757989156437 * MYPOW(1.0594630943593, midi);
 
4392
            self->lastmidi = midi;
 
4393
        }
 
4394
        else
 
4395
            self->data[i] = self->curfreq;
 
4396
    }
 
4397
}
 
4398
 
 
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 };
 
4408
 
 
4409
static void
 
4410
MToF_setProcMode(MToF *self)
 
4411
{
 
4412
    int muladdmode;
 
4413
    muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
 
4414
    
 
4415
    self->proc_func_ptr = MToF_process;
 
4416
    
 
4417
        switch (muladdmode) {
 
4418
        case 0:        
 
4419
            self->muladd_func_ptr = MToF_postprocessing_ii;
 
4420
            break;
 
4421
        case 1:    
 
4422
            self->muladd_func_ptr = MToF_postprocessing_ai;
 
4423
            break;
 
4424
        case 2:    
 
4425
            self->muladd_func_ptr = MToF_postprocessing_revai;
 
4426
            break;
 
4427
        case 10:        
 
4428
            self->muladd_func_ptr = MToF_postprocessing_ia;
 
4429
            break;
 
4430
        case 11:    
 
4431
            self->muladd_func_ptr = MToF_postprocessing_aa;
 
4432
            break;
 
4433
        case 12:    
 
4434
            self->muladd_func_ptr = MToF_postprocessing_revaa;
 
4435
            break;
 
4436
        case 20:        
 
4437
            self->muladd_func_ptr = MToF_postprocessing_ireva;
 
4438
            break;
 
4439
        case 21:    
 
4440
            self->muladd_func_ptr = MToF_postprocessing_areva;
 
4441
            break;
 
4442
        case 22:    
 
4443
            self->muladd_func_ptr = MToF_postprocessing_revareva;
 
4444
            break;
 
4445
    }   
 
4446
}
 
4447
 
 
4448
static void
 
4449
MToF_compute_next_data_frame(MToF *self)
 
4450
{
 
4451
    (*self->proc_func_ptr)(self); 
 
4452
    (*self->muladd_func_ptr)(self);
 
4453
}
 
4454
 
 
4455
static int
 
4456
MToF_traverse(MToF *self, visitproc visit, void *arg)
 
4457
{
 
4458
    pyo_VISIT
 
4459
    Py_VISIT(self->input);
 
4460
    Py_VISIT(self->input_stream);
 
4461
    return 0;
 
4462
}
 
4463
 
 
4464
static int 
 
4465
MToF_clear(MToF *self)
 
4466
{
 
4467
    pyo_CLEAR
 
4468
    Py_CLEAR(self->input);
 
4469
    Py_CLEAR(self->input_stream);
 
4470
    return 0;
 
4471
}
 
4472
 
 
4473
static void
 
4474
MToF_dealloc(MToF* self)
 
4475
{
 
4476
    free(self->data);
 
4477
    MToF_clear(self);
 
4478
    self->ob_type->tp_free((PyObject*)self);
 
4479
}
 
4480
 
 
4481
static PyObject * MToF_deleteStream(MToF *self) { DELETE_STREAM };
 
4482
 
 
4483
static PyObject *
 
4484
MToF_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
4485
{
 
4486
    int i;
 
4487
    MToF *self;
 
4488
    self = (MToF *)type->tp_alloc(type, 0);
 
4489
    
 
4490
    self->lastmidi = 0;
 
4491
    self->curfreq = 8.1757989156437;
 
4492
        self->modebuffer[0] = 0;
 
4493
        self->modebuffer[1] = 0;
 
4494
    
 
4495
    INIT_OBJECT_COMMON
 
4496
    Stream_setFunctionPtr(self->stream, MToF_compute_next_data_frame);
 
4497
    self->mode_func_ptr = MToF_setProcMode;
 
4498
    return (PyObject *)self;
 
4499
}
 
4500
 
 
4501
static int
 
4502
MToF_init(MToF *self, PyObject *args, PyObject *kwds)
 
4503
{
 
4504
    PyObject *inputtmp, *input_streamtmp, *multmp=NULL, *addtmp=NULL;
 
4505
    
 
4506
    static char *kwlist[] = {"input", "mul", "add", NULL};
 
4507
    
 
4508
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp))
 
4509
        return -1; 
 
4510
    
 
4511
    INIT_INPUT_STREAM
 
4512
    
 
4513
    if (multmp) {
 
4514
        PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
 
4515
    }
 
4516
    
 
4517
    if (addtmp) {
 
4518
        PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
 
4519
    }
 
4520
    
 
4521
    Py_INCREF(self->stream);
 
4522
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
 
4523
    
 
4524
    (*self->mode_func_ptr)(self);
 
4525
    
 
4526
    
 
4527
    Py_INCREF(self);
 
4528
    return 0;
 
4529
}
 
4530
 
 
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 };   
 
4537
 
 
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 };
 
4541
 
 
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 };
 
4550
 
 
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 */
 
4558
};
 
4559
 
 
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 */
 
4572
};
 
4573
 
 
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*/
 
4579
    0,                                              /*nb_remainder*/
 
4580
    0,                                              /*nb_divmod*/
 
4581
    0,                                              /*nb_power*/
 
4582
    0,                                              /*nb_neg*/
 
4583
    0,                                              /*nb_pos*/
 
4584
    0,                                              /*(unaryfunc)array_abs,*/
 
4585
    0,                                              /*nb_nonzero*/
 
4586
    0,                                              /*nb_invert*/
 
4587
    0,                                              /*nb_lshift*/
 
4588
    0,                                              /*nb_rshift*/
 
4589
    0,                                              /*nb_and*/
 
4590
    0,                                              /*nb_xor*/
 
4591
    0,                                              /*nb_or*/
 
4592
    0,                                              /*nb_coerce*/
 
4593
    0,                                              /*nb_int*/
 
4594
    0,                                              /*nb_long*/
 
4595
    0,                                              /*nb_float*/
 
4596
    0,                                              /*nb_oct*/
 
4597
    0,                                              /*nb_hex*/
 
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*/
 
4606
    0,                                              /*inplace_and*/
 
4607
    0,                                              /*inplace_xor*/
 
4608
    0,                                              /*inplace_or*/
 
4609
    0,                                              /*nb_floor_divide*/
 
4610
    0,                                              /*nb_true_divide*/
 
4611
    0,                                              /*nb_inplace_floor_divide*/
 
4612
    0,                                              /*nb_inplace_true_divide*/
 
4613
    0,                                              /* nb_index */
 
4614
};
 
4615
 
 
4616
PyTypeObject MToFType = {
 
4617
    PyObject_HEAD_INIT(NULL)
 
4618
    0,                                              /*ob_size*/
 
4619
    "_pyo.MToF_base",                                   /*tp_name*/
 
4620
    sizeof(MToF),                                 /*tp_basicsize*/
 
4621
    0,                                              /*tp_itemsize*/
 
4622
    (destructor)MToF_dealloc,                     /*tp_dealloc*/
 
4623
    0,                                              /*tp_print*/
 
4624
    0,                                              /*tp_getattr*/
 
4625
    0,                                              /*tp_setattr*/
 
4626
    0,                                              /*tp_compare*/
 
4627
    0,                                              /*tp_repr*/
 
4628
    &MToF_as_number,                              /*tp_as_number*/
 
4629
    0,                                              /*tp_as_sequence*/
 
4630
    0,                                              /*tp_as_mapping*/
 
4631
    0,                                              /*tp_hash */
 
4632
    0,                                              /*tp_call*/
 
4633
    0,                                              /*tp_str*/
 
4634
    0,                                              /*tp_getattro*/
 
4635
    0,                                              /*tp_setattro*/
 
4636
    0,                                              /*tp_as_buffer*/
 
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 */
 
4643
    0,                                              /* tp_iter */
 
4644
    0,                                              /* tp_iternext */
 
4645
    MToF_methods,                                 /* tp_methods */
 
4646
    MToF_members,                                 /* tp_members */
 
4647
    0,                                              /* tp_getset */
 
4648
    0,                                              /* tp_base */
 
4649
    0,                                              /* tp_dict */
 
4650
    0,                                              /* tp_descr_get */
 
4651
    0,                                              /* tp_descr_set */
 
4652
    0,                                              /* tp_dictoffset */
 
4653
    (initproc)MToF_init,                          /* tp_init */
 
4654
    0,                                              /* tp_alloc */
 
4655
    MToF_new,                                     /* tp_new */
 
4656
};
 
4657
 
 
4658
/************/
 
4659
/* MToT */
 
4660
/************/
 
4661
typedef struct {
 
4662
    pyo_audio_HEAD
 
4663
    PyObject *input;
 
4664
    Stream *input_stream;
 
4665
    MYFLT centralkey;
 
4666
    MYFLT lastmidi;
 
4667
    MYFLT curfreq;
 
4668
    int modebuffer[2]; // need at least 2 slots for mul & add
 
4669
} MToT;
 
4670
 
 
4671
static void
 
4672
MToT_process(MToT *self) {
 
4673
    int i;
 
4674
    MYFLT midi;
 
4675
    MYFLT *in = Stream_getData((Stream *)self->input_stream);
 
4676
    
 
4677
    for (i=0; i<self->bufsize; i++) {
 
4678
        midi = in[i];
 
4679
        if (midi != self->lastmidi) {
 
4680
            self->data[i] = self->curfreq = MYPOW(1.0594630943593, midi - self->centralkey);
 
4681
            self->lastmidi = midi;
 
4682
        }
 
4683
        else
 
4684
            self->data[i] = self->curfreq;
 
4685
    }
 
4686
}
 
4687
 
 
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 };
 
4697
 
 
4698
static void
 
4699
MToT_setProcMode(MToT *self)
 
4700
{
 
4701
    int muladdmode;
 
4702
    muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
 
4703
    
 
4704
    self->proc_func_ptr = MToT_process;
 
4705
    
 
4706
        switch (muladdmode) {
 
4707
        case 0:        
 
4708
            self->muladd_func_ptr = MToT_postprocessing_ii;
 
4709
            break;
 
4710
        case 1:    
 
4711
            self->muladd_func_ptr = MToT_postprocessing_ai;
 
4712
            break;
 
4713
        case 2:    
 
4714
            self->muladd_func_ptr = MToT_postprocessing_revai;
 
4715
            break;
 
4716
        case 10:        
 
4717
            self->muladd_func_ptr = MToT_postprocessing_ia;
 
4718
            break;
 
4719
        case 11:    
 
4720
            self->muladd_func_ptr = MToT_postprocessing_aa;
 
4721
            break;
 
4722
        case 12:    
 
4723
            self->muladd_func_ptr = MToT_postprocessing_revaa;
 
4724
            break;
 
4725
        case 20:        
 
4726
            self->muladd_func_ptr = MToT_postprocessing_ireva;
 
4727
            break;
 
4728
        case 21:    
 
4729
            self->muladd_func_ptr = MToT_postprocessing_areva;
 
4730
            break;
 
4731
        case 22:    
 
4732
            self->muladd_func_ptr = MToT_postprocessing_revareva;
 
4733
            break;
 
4734
    }   
 
4735
}
 
4736
 
 
4737
static void
 
4738
MToT_compute_next_data_frame(MToT *self)
 
4739
{
 
4740
    (*self->proc_func_ptr)(self); 
 
4741
    (*self->muladd_func_ptr)(self);
 
4742
}
 
4743
 
 
4744
static int
 
4745
MToT_traverse(MToT *self, visitproc visit, void *arg)
 
4746
{
 
4747
    pyo_VISIT
 
4748
    Py_VISIT(self->input);
 
4749
    Py_VISIT(self->input_stream);
 
4750
    return 0;
 
4751
}
 
4752
 
 
4753
static int 
 
4754
MToT_clear(MToT *self)
 
4755
{
 
4756
    pyo_CLEAR
 
4757
    Py_CLEAR(self->input);
 
4758
    Py_CLEAR(self->input_stream);
 
4759
    return 0;
 
4760
}
 
4761
 
 
4762
static void
 
4763
MToT_dealloc(MToT* self)
 
4764
{
 
4765
    free(self->data);
 
4766
    MToT_clear(self);
 
4767
    self->ob_type->tp_free((PyObject*)self);
 
4768
}
 
4769
 
 
4770
static PyObject * MToT_deleteStream(MToT *self) { DELETE_STREAM };
 
4771
 
 
4772
static PyObject *
 
4773
MToT_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
4774
{
 
4775
    int i;
 
4776
    MToT *self;
 
4777
    self = (MToT *)type->tp_alloc(type, 0);
 
4778
    
 
4779
    self->centralkey = 60.0;
 
4780
    self->lastmidi = 0;
 
4781
    self->curfreq = 8.1757989156437;
 
4782
        self->modebuffer[0] = 0;
 
4783
        self->modebuffer[1] = 0;
 
4784
    
 
4785
    INIT_OBJECT_COMMON
 
4786
    Stream_setFunctionPtr(self->stream, MToT_compute_next_data_frame);
 
4787
    self->mode_func_ptr = MToT_setProcMode;
 
4788
    return (PyObject *)self;
 
4789
}
 
4790
 
 
4791
static int
 
4792
MToT_init(MToT *self, PyObject *args, PyObject *kwds)
 
4793
{
 
4794
    PyObject *inputtmp, *input_streamtmp, *multmp=NULL, *addtmp=NULL;
 
4795
    
 
4796
    static char *kwlist[] = {"input", "centralkey", "mul", "add", NULL};
 
4797
    
 
4798
    if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_O_FOO, kwlist, &inputtmp, &self->centralkey, &multmp, &addtmp))
 
4799
        return -1; 
 
4800
    
 
4801
    INIT_INPUT_STREAM
 
4802
    
 
4803
    if (multmp) {
 
4804
        PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
 
4805
    }
 
4806
    
 
4807
    if (addtmp) {
 
4808
        PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
 
4809
    }
 
4810
    
 
4811
    Py_INCREF(self->stream);
 
4812
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
 
4813
    
 
4814
    (*self->mode_func_ptr)(self);
 
4815
    
 
4816
    
 
4817
    Py_INCREF(self);
 
4818
    return 0;
 
4819
}
 
4820
 
 
4821
static PyObject *
 
4822
MToT_setCentralKey(MToT *self, PyObject *arg)
 
4823
{
 
4824
        if (arg == NULL) {
 
4825
                Py_INCREF(Py_None);
 
4826
                return Py_None;
 
4827
        }
 
4828
    
 
4829
        int isNumber = PyNumber_Check(arg);
 
4830
        
 
4831
        if (isNumber == 1) {
 
4832
                self->centralkey = PyFloat_AS_DOUBLE(PyNumber_Float(arg));
 
4833
        }
 
4834
    
 
4835
        Py_INCREF(Py_None);
 
4836
        return Py_None;
 
4837
}
 
4838
 
 
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 };   
 
4845
 
 
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 };
 
4849
 
 
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 };
 
4858
 
 
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 */
 
4866
};
 
4867
 
 
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 */
 
4881
};
 
4882
 
 
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*/
 
4888
    0,                                              /*nb_remainder*/
 
4889
    0,                                              /*nb_divmod*/
 
4890
    0,                                              /*nb_power*/
 
4891
    0,                                              /*nb_neg*/
 
4892
    0,                                              /*nb_pos*/
 
4893
    0,                                              /*(unaryfunc)array_abs,*/
 
4894
    0,                                              /*nb_nonzero*/
 
4895
    0,                                              /*nb_invert*/
 
4896
    0,                                              /*nb_lshift*/
 
4897
    0,                                              /*nb_rshift*/
 
4898
    0,                                              /*nb_and*/
 
4899
    0,                                              /*nb_xor*/
 
4900
    0,                                              /*nb_or*/
 
4901
    0,                                              /*nb_coerce*/
 
4902
    0,                                              /*nb_int*/
 
4903
    0,                                              /*nb_long*/
 
4904
    0,                                              /*nb_float*/
 
4905
    0,                                              /*nb_oct*/
 
4906
    0,                                              /*nb_hex*/
 
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*/
 
4915
    0,                                              /*inplace_and*/
 
4916
    0,                                              /*inplace_xor*/
 
4917
    0,                                              /*inplace_or*/
 
4918
    0,                                              /*nb_floor_divide*/
 
4919
    0,                                              /*nb_true_divide*/
 
4920
    0,                                              /*nb_inplace_floor_divide*/
 
4921
    0,                                              /*nb_inplace_true_divide*/
 
4922
    0,                                              /* nb_index */
 
4923
};
 
4924
 
 
4925
PyTypeObject MToTType = {
 
4926
    PyObject_HEAD_INIT(NULL)
 
4927
    0,                                              /*ob_size*/
 
4928
    "_pyo.MToT_base",                                   /*tp_name*/
 
4929
    sizeof(MToT),                                 /*tp_basicsize*/
 
4930
    0,                                              /*tp_itemsize*/
 
4931
    (destructor)MToT_dealloc,                     /*tp_dealloc*/
 
4932
    0,                                              /*tp_print*/
 
4933
    0,                                              /*tp_getattr*/
 
4934
    0,                                              /*tp_setattr*/
 
4935
    0,                                              /*tp_compare*/
 
4936
    0,                                              /*tp_repr*/
 
4937
    &MToT_as_number,                              /*tp_as_number*/
 
4938
    0,                                              /*tp_as_sequence*/
 
4939
    0,                                              /*tp_as_mapping*/
 
4940
    0,                                              /*tp_hash */
 
4941
    0,                                              /*tp_call*/
 
4942
    0,                                              /*tp_str*/
 
4943
    0,                                              /*tp_getattro*/
 
4944
    0,                                              /*tp_setattro*/
 
4945
    0,                                              /*tp_as_buffer*/
 
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 */
 
4952
    0,                                              /* tp_iter */
 
4953
    0,                                              /* tp_iternext */
 
4954
    MToT_methods,                                 /* tp_methods */
 
4955
    MToT_members,                                 /* tp_members */
 
4956
    0,                                              /* tp_getset */
 
4957
    0,                                              /* tp_base */
 
4958
    0,                                              /* tp_dict */
 
4959
    0,                                              /* tp_descr_get */
 
4960
    0,                                              /* tp_descr_set */
 
4961
    0,                                              /* tp_dictoffset */
 
4962
    (initproc)MToT_init,                          /* tp_init */
 
4963
    0,                                              /* tp_alloc */
 
4964
    MToT_new,                                     /* tp_new */
 
4965
};