| 1 |
/************************************************************************** |
| 2 |
* Copyright 2009-2015 Olivier Belanger * |
| 3 |
* * |
| 4 |
* This file is part of pyo, a python module to help digital signal * |
| 5 |
* processing script creation. * |
| 6 |
* * |
| 7 |
* pyo is free software: you can redistribute it and/or modify * |
| 8 |
* it under the terms of the GNU Lesser General Public License as * |
| 9 |
* published by the Free Software Foundation, either version 3 of the * |
| 10 |
* License, or (at your option) any later version. * |
| 11 |
* * |
| 12 |
* pyo is distributed in the hope that it will be useful, * |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 15 |
* GNU Lesser General Public License for more details. * |
| 16 |
* * |
| 17 |
* You should have received a copy of the GNU Lesser General Public * |
| 18 |
* License along with pyo. If not, see <http://www.gnu.org/licenses/>. * |
| 19 |
*************************************************************************/ |
| 20 |
|
| 21 |
#define PY_SSIZE_T_CLEAN |
| 22 |
|
| 23 |
#include <Python.h> |
| 24 |
#include "structmember.h" |
| 25 |
#include "pyomodule.h" |
| 26 |
#include "streammodule.h" |
| 27 |
#include "servermodule.h" |
| 28 |
#include "dummymodule.h" |
| 29 |
#include "sndfile.h" |
| 30 |
#include "interpolation.h" |
| 31 |
|
| 32 |
/************/ |
| 33 |
/* Record */ |
| 34 |
/************/ |
| 35 |
typedef struct |
| 36 |
{ |
| 37 |
pyo_audio_HEAD |
| 38 |
PyObject *input_list; |
| 39 |
int chnls; |
| 40 |
int buffering; |
| 41 |
int count; |
| 42 |
int listlen; |
| 43 |
char *recpath; |
| 44 |
SNDFILE *recfile; |
| 45 |
SF_INFO recinfo; |
| 46 |
MYFLT *buffer; |
| 47 |
} Record; |
| 48 |
|
| 49 |
static void |
| 50 |
Record_process(Record *self) |
| 51 |
{ |
| 52 |
int i, j, chnl, offset, totlen; |
| 53 |
MYFLT *in; |
| 54 |
|
| 55 |
totlen = self->chnls * self->bufsize * self->buffering; |
| 56 |
|
| 57 |
if (self->count == self->buffering) |
| 58 |
{ |
| 59 |
self->count = 0; |
| 60 |
|
| 61 |
for (i = 0; i < totlen; i++) |
| 62 |
{ |
| 63 |
self->buffer[i] = 0.0; |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
offset = self->bufsize * self->chnls * self->count; |
| 68 |
|
| 69 |
for (j = 0; j < self->listlen; j++) |
| 70 |
{ |
| 71 |
chnl = j % self->chnls; |
| 72 |
in = Stream_getData((Stream *)PyObject_CallMethod(PyList_GET_ITEM(self->input_list, j), "_getStream", NULL)); |
| 73 |
|
| 74 |
for (i = 0; i < self->bufsize; i++) |
| 75 |
{ |
| 76 |
self->buffer[i * self->chnls + chnl + offset] += in[i]; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
self->count++; |
| 81 |
|
| 82 |
if (self->count == self->buffering) |
| 83 |
SF_WRITE(self->recfile, self->buffer, totlen); |
| 84 |
} |
| 85 |
|
| 86 |
static void |
| 87 |
Record_setProcMode(Record *self) |
| 88 |
{ |
| 89 |
self->proc_func_ptr = Record_process; |
| 90 |
} |
| 91 |
|
| 92 |
static void |
| 93 |
Record_compute_next_data_frame(Record *self) |
| 94 |
{ |
| 95 |
(*self->proc_func_ptr)(self); |
| 96 |
} |
| 97 |
|
| 98 |
static int |
| 99 |
Record_traverse(Record *self, visitproc visit, void *arg) |
| 100 |
{ |
| 101 |
pyo_VISIT |
| 102 |
Py_VISIT(self->input_list); |
| 103 |
return 0; |
| 104 |
} |
| 105 |
|
| 106 |
static int |
| 107 |
Record_clear(Record *self) |
| 108 |
{ |
| 109 |
pyo_CLEAR |
| 110 |
Py_CLEAR(self->input_list); |
| 111 |
return 0; |
| 112 |
} |
| 113 |
|
| 114 |
static void |
| 115 |
Record_dealloc(Record* self) |
| 116 |
{ |
| 117 |
if (Stream_getStreamActive(self->stream)) |
| 118 |
PyObject_CallMethod((PyObject *)self, "stop", NULL); |
| 119 |
|
| 120 |
pyo_DEALLOC |
| 121 |
PyMem_RawFree(self->buffer); |
| 122 |
Record_clear(self); |
| 123 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 124 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 125 |
} |
| 126 |
|
| 127 |
static PyObject * |
| 128 |
Record_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 129 |
{ |
| 130 |
int i, buflen; |
| 131 |
int fileformat = 0; |
| 132 |
int sampletype = 0; |
| 133 |
double quality = 0.4; |
| 134 |
Py_ssize_t psize; |
| 135 |
PyObject *input_listtmp; |
| 136 |
Record *self; |
| 137 |
self = (Record *)type->tp_alloc(type, 0); |
| 138 |
|
| 139 |
self->chnls = 2; |
| 140 |
self->buffering = 4; |
| 141 |
self->count = 0; |
| 142 |
|
| 143 |
INIT_OBJECT_COMMON |
| 144 |
Stream_setFunctionPtr(self->stream, Record_compute_next_data_frame); |
| 145 |
self->mode_func_ptr = Record_setProcMode; |
| 146 |
|
| 147 |
static char *kwlist[] = {"input", "filename", "chnls", "fileformat", "sampletype", "buffering", "quality", NULL}; |
| 148 |
|
| 149 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "Os#|iiiid", kwlist, &input_listtmp, &self->recpath, &psize, &self->chnls, &fileformat, &sampletype, &self->buffering, &quality)) |
| 150 |
Py_RETURN_NONE; |
| 151 |
|
| 152 |
self->input_list = input_listtmp; |
| 153 |
Py_INCREF(self->input_list); |
| 154 |
self->listlen = PyList_Size(self->input_list); |
| 155 |
|
| 156 |
/* Prepare sfinfo */ |
| 157 |
self->recinfo.samplerate = (int)self->sr; |
| 158 |
self->recinfo.channels = self->chnls; |
| 159 |
|
| 160 |
switch (fileformat) |
| 161 |
{ |
| 162 |
case 0: |
| 163 |
self->recinfo.format = SF_FORMAT_WAV; |
| 164 |
break; |
| 165 |
|
| 166 |
case 1: |
| 167 |
self->recinfo.format = SF_FORMAT_AIFF; |
| 168 |
break; |
| 169 |
|
| 170 |
case 2: |
| 171 |
self->recinfo.format = SF_FORMAT_AU; |
| 172 |
break; |
| 173 |
|
| 174 |
case 3: |
| 175 |
self->recinfo.format = SF_FORMAT_RAW; |
| 176 |
break; |
| 177 |
|
| 178 |
case 4: |
| 179 |
self->recinfo.format = SF_FORMAT_SD2; |
| 180 |
break; |
| 181 |
|
| 182 |
case 5: |
| 183 |
self->recinfo.format = SF_FORMAT_FLAC; |
| 184 |
break; |
| 185 |
|
| 186 |
case 6: |
| 187 |
self->recinfo.format = SF_FORMAT_CAF; |
| 188 |
break; |
| 189 |
|
| 190 |
case 7: |
| 191 |
self->recinfo.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS; |
| 192 |
break; |
| 193 |
} |
| 194 |
|
| 195 |
if (fileformat != 7) |
| 196 |
{ |
| 197 |
switch (sampletype) |
| 198 |
{ |
| 199 |
case 0: |
| 200 |
self->recinfo.format = self->recinfo.format | SF_FORMAT_PCM_16; |
| 201 |
break; |
| 202 |
|
| 203 |
case 1: |
| 204 |
self->recinfo.format = self->recinfo.format | SF_FORMAT_PCM_24; |
| 205 |
break; |
| 206 |
|
| 207 |
case 2: |
| 208 |
self->recinfo.format = self->recinfo.format | SF_FORMAT_PCM_32; |
| 209 |
break; |
| 210 |
|
| 211 |
case 3: |
| 212 |
self->recinfo.format = self->recinfo.format | SF_FORMAT_FLOAT; |
| 213 |
break; |
| 214 |
|
| 215 |
case 4: |
| 216 |
self->recinfo.format = self->recinfo.format | SF_FORMAT_DOUBLE; |
| 217 |
break; |
| 218 |
|
| 219 |
case 5: |
| 220 |
self->recinfo.format = self->recinfo.format | SF_FORMAT_ULAW; |
| 221 |
break; |
| 222 |
|
| 223 |
case 6: |
| 224 |
self->recinfo.format = self->recinfo.format | SF_FORMAT_ALAW; |
| 225 |
break; |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
/* Open the output file. */ |
| 230 |
if (! (self->recfile = sf_open(self->recpath, SFM_WRITE, &self->recinfo))) |
| 231 |
{ |
| 232 |
PySys_WriteStdout("Record: not able to open output file %s.\n", self->recpath); |
| 233 |
Py_RETURN_NONE; |
| 234 |
} |
| 235 |
|
| 236 |
// Sets the encoding quality for FLAC and OGG compressed formats |
| 237 |
if (fileformat == 5 || fileformat == 7) |
| 238 |
{ |
| 239 |
sf_command(self->recfile, SFC_SET_VBR_ENCODING_QUALITY, &quality, sizeof(double)); |
| 240 |
} |
| 241 |
|
| 242 |
buflen = self->bufsize * self->chnls * self->buffering; |
| 243 |
self->buffer = (MYFLT *)PyMem_RawRealloc(self->buffer, buflen * sizeof(MYFLT)); |
| 244 |
|
| 245 |
for (i = 0; i < buflen; i++) |
| 246 |
{ |
| 247 |
self->buffer[i] = 0.; |
| 248 |
} |
| 249 |
|
| 250 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 251 |
|
| 252 |
(*self->mode_func_ptr)(self); |
| 253 |
|
| 254 |
return (PyObject *)self; |
| 255 |
} |
| 256 |
|
| 257 |
static PyObject * Record_getServer(Record* self) { GET_SERVER }; |
| 258 |
static PyObject * Record_getStream(Record* self) { GET_STREAM }; |
| 259 |
|
| 260 |
static PyObject * Record_play(Record *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 261 |
static PyObject * Record_stop(Record *self, PyObject *args, PyObject *kwds) |
| 262 |
{ |
| 263 |
int i, nearestBuf = 0; |
| 264 |
float wait = 0.0; |
| 265 |
|
| 266 |
static char *kwlist[] = {"wait", NULL}; |
| 267 |
|
| 268 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|f", kwlist, &wait)) |
| 269 |
return PyLong_FromLong(-1); |
| 270 |
|
| 271 |
if (wait == 0) |
| 272 |
{ |
| 273 |
sf_close(self->recfile); |
| 274 |
Stream_setStreamActive(self->stream, 0); |
| 275 |
Stream_setStreamChnl(self->stream, 0); |
| 276 |
Stream_setStreamToDac(self->stream, 0); |
| 277 |
|
| 278 |
for (i = 0; i < self->bufsize; i++) |
| 279 |
{ |
| 280 |
self->data[i] = 0; |
| 281 |
} |
| 282 |
} |
| 283 |
else |
| 284 |
{ |
| 285 |
Stream_resetBufferCount(self->stream); |
| 286 |
nearestBuf = (int)roundf((wait * self->sr) / self->bufsize + 0.5); |
| 287 |
Stream_setDuration(self->stream, nearestBuf); |
| 288 |
} |
| 289 |
|
| 290 |
Py_RETURN_NONE; |
| 291 |
}; |
| 292 |
|
| 293 |
static PyMemberDef Record_members[] = |
| 294 |
{ |
| 295 |
{"server", T_OBJECT_EX, offsetof(Record, server), 0, "Pyo server."}, |
| 296 |
{"stream", T_OBJECT_EX, offsetof(Record, stream), 0, "Stream object."}, |
| 297 |
{"input", T_OBJECT_EX, offsetof(Record, input_list), 0, "Input sound base object list."}, |
| 298 |
{NULL} /* Sentinel */ |
| 299 |
}; |
| 300 |
|
| 301 |
static PyMethodDef Record_methods[] = |
| 302 |
{ |
| 303 |
{"getServer", (PyCFunction)Record_getServer, METH_NOARGS, "Returns server object."}, |
| 304 |
{"_getStream", (PyCFunction)Record_getStream, METH_NOARGS, "Returns stream object."}, |
| 305 |
{"play", (PyCFunction)Record_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 306 |
{"stop", (PyCFunction)Record_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 307 |
{NULL} /* Sentinel */ |
| 308 |
}; |
| 309 |
|
| 310 |
PyTypeObject RecordType = |
| 311 |
{ |
| 312 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 313 |
"_pyo.Record_base", /*tp_name*/ |
| 314 |
sizeof(Record), /*tp_basicsize*/ |
| 315 |
0, /*tp_itemsize*/ |
| 316 |
(destructor)Record_dealloc, /*tp_dealloc*/ |
| 317 |
0, /*tp_print*/ |
| 318 |
0, /*tp_getattr*/ |
| 319 |
0, /*tp_setattr*/ |
| 320 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 321 |
0, /*tp_repr*/ |
| 322 |
0, /*tp_as_number*/ |
| 323 |
0, /*tp_as_sequence*/ |
| 324 |
0, /*tp_as_mapping*/ |
| 325 |
0, /*tp_hash */ |
| 326 |
0, /*tp_call*/ |
| 327 |
0, /*tp_str*/ |
| 328 |
0, /*tp_getattro*/ |
| 329 |
0, /*tp_setattro*/ |
| 330 |
0, /*tp_as_buffer*/ |
| 331 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 332 |
"Record objects. Records its audio input in a file.", /* tp_doc */ |
| 333 |
(traverseproc)Record_traverse, /* tp_traverse */ |
| 334 |
(inquiry)Record_clear, /* tp_clear */ |
| 335 |
0, /* tp_richcompare */ |
| 336 |
0, /* tp_weaklistoffset */ |
| 337 |
0, /* tp_iter */ |
| 338 |
0, /* tp_iternext */ |
| 339 |
Record_methods, /* tp_methods */ |
| 340 |
Record_members, /* tp_members */ |
| 341 |
0, /* tp_getset */ |
| 342 |
0, /* tp_base */ |
| 343 |
0, /* tp_dict */ |
| 344 |
0, /* tp_descr_get */ |
| 345 |
0, /* tp_descr_set */ |
| 346 |
0, /* tp_dictoffset */ |
| 347 |
0, /* tp_init */ |
| 348 |
0, /* tp_alloc */ |
| 349 |
Record_new, /* tp_new */ |
| 350 |
}; |
| 351 |
|
| 352 |
/************/ |
| 353 |
/* ControlRec */ |
| 354 |
/************/ |
| 355 |
typedef struct |
| 356 |
{ |
| 357 |
pyo_audio_HEAD |
| 358 |
PyObject *input; |
| 359 |
Stream *input_stream; |
| 360 |
PyObject *tmp_list; |
| 361 |
MYFLT dur; |
| 362 |
int rate; |
| 363 |
int modulo; |
| 364 |
long count; |
| 365 |
long time; |
| 366 |
long size; |
| 367 |
MYFLT *buffer; |
| 368 |
} ControlRec; |
| 369 |
|
| 370 |
static void |
| 371 |
ControlRec_process(ControlRec *self) |
| 372 |
{ |
| 373 |
int i; |
| 374 |
|
| 375 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 376 |
|
| 377 |
if (self->dur > 0.0) |
| 378 |
{ |
| 379 |
for (i = 0; i < self->bufsize; i++) |
| 380 |
{ |
| 381 |
if ((self->time % self->modulo) == 0 && self->count < self->size) |
| 382 |
{ |
| 383 |
self->buffer[self->count] = in[i]; |
| 384 |
self->count++; |
| 385 |
} |
| 386 |
|
| 387 |
self->time++; |
| 388 |
|
| 389 |
if (self->count >= self->size) |
| 390 |
PyObject_CallMethod((PyObject *)self, "stop", NULL); |
| 391 |
} |
| 392 |
} |
| 393 |
else |
| 394 |
{ |
| 395 |
for (i = 0; i < self->bufsize; i++) |
| 396 |
{ |
| 397 |
if ((self->time % self->modulo) == 0) |
| 398 |
{ |
| 399 |
PyList_Append(self->tmp_list, PyFloat_FromDouble(in[i])); |
| 400 |
} |
| 401 |
|
| 402 |
self->time++; |
| 403 |
} |
| 404 |
} |
| 405 |
} |
| 406 |
|
| 407 |
static void |
| 408 |
ControlRec_setProcMode(ControlRec *self) |
| 409 |
{ |
| 410 |
self->proc_func_ptr = ControlRec_process; |
| 411 |
} |
| 412 |
|
| 413 |
static void |
| 414 |
ControlRec_compute_next_data_frame(ControlRec *self) |
| 415 |
{ |
| 416 |
(*self->proc_func_ptr)(self); |
| 417 |
} |
| 418 |
|
| 419 |
static int |
| 420 |
ControlRec_traverse(ControlRec *self, visitproc visit, void *arg) |
| 421 |
{ |
| 422 |
pyo_VISIT |
| 423 |
Py_VISIT(self->input); |
| 424 |
Py_VISIT(self->tmp_list); |
| 425 |
return 0; |
| 426 |
} |
| 427 |
|
| 428 |
static int |
| 429 |
ControlRec_clear(ControlRec *self) |
| 430 |
{ |
| 431 |
pyo_CLEAR |
| 432 |
Py_CLEAR(self->input); |
| 433 |
Py_CLEAR(self->tmp_list); |
| 434 |
return 0; |
| 435 |
} |
| 436 |
|
| 437 |
static void |
| 438 |
ControlRec_dealloc(ControlRec* self) |
| 439 |
{ |
| 440 |
pyo_DEALLOC |
| 441 |
|
| 442 |
if (self->buffer != NULL) |
| 443 |
PyMem_RawFree(self->buffer); |
| 444 |
|
| 445 |
ControlRec_clear(self); |
| 446 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 447 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 448 |
} |
| 449 |
|
| 450 |
static PyObject * |
| 451 |
ControlRec_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 452 |
{ |
| 453 |
int i; |
| 454 |
long j; |
| 455 |
PyObject *inputtmp, *input_streamtmp; |
| 456 |
ControlRec *self; |
| 457 |
self = (ControlRec *)type->tp_alloc(type, 0); |
| 458 |
|
| 459 |
self->dur = 0.0; |
| 460 |
self->rate = 1000; |
| 461 |
self->tmp_list = PyList_New(0); |
| 462 |
|
| 463 |
INIT_OBJECT_COMMON |
| 464 |
Stream_setFunctionPtr(self->stream, ControlRec_compute_next_data_frame); |
| 465 |
self->mode_func_ptr = ControlRec_setProcMode; |
| 466 |
|
| 467 |
static char *kwlist[] = {"input", "rate", "dur", NULL}; |
| 468 |
|
| 469 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_O_IF, kwlist, &inputtmp, &self->rate, &self->dur)) |
| 470 |
Py_RETURN_NONE; |
| 471 |
|
| 472 |
INIT_INPUT_STREAM |
| 473 |
|
| 474 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 475 |
|
| 476 |
if (self->dur > 0.0) |
| 477 |
{ |
| 478 |
self->size = (long)(self->dur * self->rate + 1); |
| 479 |
self->buffer = (MYFLT *)PyMem_RawRealloc(self->buffer, self->size * sizeof(MYFLT)); |
| 480 |
|
| 481 |
for (j = 0; j < self->size; j++) |
| 482 |
{ |
| 483 |
self->buffer[j] = 0.0; |
| 484 |
} |
| 485 |
} |
| 486 |
|
| 487 |
self->modulo = (int)(self->sr / self->rate); |
| 488 |
|
| 489 |
(*self->mode_func_ptr)(self); |
| 490 |
|
| 491 |
return (PyObject *)self; |
| 492 |
} |
| 493 |
|
| 494 |
static PyObject * ControlRec_getServer(ControlRec* self) { GET_SERVER }; |
| 495 |
static PyObject * ControlRec_getStream(ControlRec* self) { GET_STREAM }; |
| 496 |
|
| 497 |
static PyObject * ControlRec_play(ControlRec *self, PyObject *args, PyObject *kwds) |
| 498 |
{ |
| 499 |
self->count = self->time = 0; |
| 500 |
PLAY |
| 501 |
}; |
| 502 |
|
| 503 |
static PyObject * ControlRec_stop(ControlRec *self, PyObject *args, PyObject *kwds) { STOP }; |
| 504 |
|
| 505 |
static PyObject * |
| 506 |
ControlRec_getData(ControlRec *self) |
| 507 |
{ |
| 508 |
int i; |
| 509 |
PyObject *data, *point; |
| 510 |
MYFLT time, timescl = 1.0 / self->rate; |
| 511 |
|
| 512 |
if (self->dur > 0.0) |
| 513 |
{ |
| 514 |
data = PyList_New(self->size); |
| 515 |
|
| 516 |
for (i = 0; i < self->size; i++) |
| 517 |
{ |
| 518 |
time = i * timescl; |
| 519 |
point = PyTuple_New(2); |
| 520 |
PyTuple_SET_ITEM(point, 0, PyFloat_FromDouble(time)); |
| 521 |
PyTuple_SET_ITEM(point, 1, PyFloat_FromDouble(self->buffer[i])); |
| 522 |
PyList_SetItem(data, i, point); |
| 523 |
} |
| 524 |
} |
| 525 |
else |
| 526 |
{ |
| 527 |
if (Stream_getStreamActive(self->stream)) |
| 528 |
{ |
| 529 |
PyObject_CallMethod((PyObject *)self, "stop", NULL); |
| 530 |
} |
| 531 |
Py_ssize_t size = PyList_Size(self->tmp_list); |
| 532 |
data = PyList_New(size); |
| 533 |
|
| 534 |
for (i = 0; i < size; i++) |
| 535 |
{ |
| 536 |
time = i * timescl; |
| 537 |
point = PyTuple_New(2); |
| 538 |
PyTuple_SET_ITEM(point, 0, PyFloat_FromDouble(time)); |
| 539 |
PyTuple_SET_ITEM(point, 1, PyList_GET_ITEM(self->tmp_list, i)); |
| 540 |
PyList_SetItem(data, i, point); |
| 541 |
} |
| 542 |
} |
| 543 |
|
| 544 |
return data; |
| 545 |
} |
| 546 |
|
| 547 |
static PyMemberDef ControlRec_members[] = |
| 548 |
{ |
| 549 |
{"server", T_OBJECT_EX, offsetof(ControlRec, server), 0, "Pyo server."}, |
| 550 |
{"stream", T_OBJECT_EX, offsetof(ControlRec, stream), 0, "Stream object."}, |
| 551 |
{"input", T_OBJECT_EX, offsetof(ControlRec, input), 0, "Input sound."}, |
| 552 |
{NULL} /* Sentinel */ |
| 553 |
}; |
| 554 |
|
| 555 |
static PyMethodDef ControlRec_methods[] = |
| 556 |
{ |
| 557 |
{"getServer", (PyCFunction)ControlRec_getServer, METH_NOARGS, "Returns server object."}, |
| 558 |
{"_getStream", (PyCFunction)ControlRec_getStream, METH_NOARGS, "Returns stream object."}, |
| 559 |
{"play", (PyCFunction)ControlRec_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 560 |
{"stop", (PyCFunction)ControlRec_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 561 |
{"getData", (PyCFunction)ControlRec_getData, METH_NOARGS, "Returns list of sampled points."}, |
| 562 |
{NULL} /* Sentinel */ |
| 563 |
}; |
| 564 |
|
| 565 |
PyTypeObject ControlRecType = |
| 566 |
{ |
| 567 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 568 |
"_pyo.ControlRec_base", /*tp_name*/ |
| 569 |
sizeof(ControlRec), /*tp_basicsize*/ |
| 570 |
0, /*tp_itemsize*/ |
| 571 |
(destructor)ControlRec_dealloc, /*tp_dealloc*/ |
| 572 |
0, /*tp_print*/ |
| 573 |
0, /*tp_getattr*/ |
| 574 |
0, /*tp_setattr*/ |
| 575 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 576 |
0, /*tp_repr*/ |
| 577 |
0, /*tp_as_number*/ |
| 578 |
0, /*tp_as_sequence*/ |
| 579 |
0, /*tp_as_mapping*/ |
| 580 |
0, /*tp_hash */ |
| 581 |
0, /*tp_call*/ |
| 582 |
0, /*tp_str*/ |
| 583 |
0, /*tp_getattro*/ |
| 584 |
0, /*tp_setattro*/ |
| 585 |
0, /*tp_as_buffer*/ |
| 586 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 587 |
"ControlRec objects. Records control signal with user-defined sampling rate.", /* tp_doc */ |
| 588 |
(traverseproc)ControlRec_traverse, /* tp_traverse */ |
| 589 |
(inquiry)ControlRec_clear, /* tp_clear */ |
| 590 |
0, /* tp_richcompare */ |
| 591 |
0, /* tp_weaklistoffset */ |
| 592 |
0, /* tp_iter */ |
| 593 |
0, /* tp_iternext */ |
| 594 |
ControlRec_methods, /* tp_methods */ |
| 595 |
ControlRec_members, /* tp_members */ |
| 596 |
0, /* tp_getset */ |
| 597 |
0, /* tp_base */ |
| 598 |
0, /* tp_dict */ |
| 599 |
0, /* tp_descr_get */ |
| 600 |
0, /* tp_descr_set */ |
| 601 |
0, /* tp_dictoffset */ |
| 602 |
0, /* tp_init */ |
| 603 |
0, /* tp_alloc */ |
| 604 |
ControlRec_new, /* tp_new */ |
| 605 |
}; |
| 606 |
|
| 607 |
/**************/ |
| 608 |
/* ControlRead object */ |
| 609 |
/**************/ |
| 610 |
typedef struct |
| 611 |
{ |
| 612 |
pyo_audio_HEAD |
| 613 |
MYFLT *values; |
| 614 |
int rate; |
| 615 |
int modulo; |
| 616 |
int loop; |
| 617 |
int go; |
| 618 |
int modebuffer[2]; |
| 619 |
T_SIZE_T count; |
| 620 |
long time; |
| 621 |
T_SIZE_T size; |
| 622 |
MYFLT *trigsBuffer; |
| 623 |
TriggerStream *trig_stream; |
| 624 |
int interp; /* 0 = default to 2, 1 = nointerp, 2 = linear, 3 = cos, 4 = cubic */ |
| 625 |
MYFLT (*interp_func_ptr)(MYFLT *, T_SIZE_T, MYFLT, T_SIZE_T); |
| 626 |
} ControlRead; |
| 627 |
|
| 628 |
static void |
| 629 |
ControlRead_readframes_i(ControlRead *self) |
| 630 |
{ |
| 631 |
MYFLT fpart; |
| 632 |
long i, mod; |
| 633 |
MYFLT invmodulo = 1.0 / self->modulo; |
| 634 |
|
| 635 |
if (self->go == 0) |
| 636 |
PyObject_CallMethod((PyObject *)self, "stop", NULL); |
| 637 |
|
| 638 |
for (i = 0; i < self->bufsize; i++) |
| 639 |
{ |
| 640 |
self->trigsBuffer[i] = 0.0; |
| 641 |
|
| 642 |
if (self->go == 1) |
| 643 |
{ |
| 644 |
mod = self->time % self->modulo; |
| 645 |
fpart = mod * invmodulo; |
| 646 |
self->data[i] = (*self->interp_func_ptr)(self->values, self->count, fpart, self->size); |
| 647 |
} |
| 648 |
else |
| 649 |
{ |
| 650 |
mod = -1; |
| 651 |
self->data[i] = 0.0; |
| 652 |
} |
| 653 |
|
| 654 |
if (mod == 0) |
| 655 |
{ |
| 656 |
self->count++; |
| 657 |
|
| 658 |
if (self->count >= (self->size - 1)) |
| 659 |
{ |
| 660 |
self->trigsBuffer[i] = 1.0; |
| 661 |
|
| 662 |
if (self->loop == 1) |
| 663 |
self->count = 0; |
| 664 |
else |
| 665 |
self->go = 0; |
| 666 |
} |
| 667 |
} |
| 668 |
|
| 669 |
self->time++; |
| 670 |
} |
| 671 |
} |
| 672 |
|
| 673 |
static void ControlRead_postprocessing_ii(ControlRead *self) { POST_PROCESSING_II }; |
| 674 |
static void ControlRead_postprocessing_ai(ControlRead *self) { POST_PROCESSING_AI }; |
| 675 |
static void ControlRead_postprocessing_ia(ControlRead *self) { POST_PROCESSING_IA }; |
| 676 |
static void ControlRead_postprocessing_aa(ControlRead *self) { POST_PROCESSING_AA }; |
| 677 |
static void ControlRead_postprocessing_ireva(ControlRead *self) { POST_PROCESSING_IREVA }; |
| 678 |
static void ControlRead_postprocessing_areva(ControlRead *self) { POST_PROCESSING_AREVA }; |
| 679 |
static void ControlRead_postprocessing_revai(ControlRead *self) { POST_PROCESSING_REVAI }; |
| 680 |
static void ControlRead_postprocessing_revaa(ControlRead *self) { POST_PROCESSING_REVAA }; |
| 681 |
static void ControlRead_postprocessing_revareva(ControlRead *self) { POST_PROCESSING_REVAREVA }; |
| 682 |
|
| 683 |
static void |
| 684 |
ControlRead_setProcMode(ControlRead *self) |
| 685 |
{ |
| 686 |
int muladdmode; |
| 687 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 688 |
|
| 689 |
self->proc_func_ptr = ControlRead_readframes_i; |
| 690 |
|
| 691 |
switch (muladdmode) |
| 692 |
{ |
| 693 |
case 0: |
| 694 |
self->muladd_func_ptr = ControlRead_postprocessing_ii; |
| 695 |
break; |
| 696 |
|
| 697 |
case 1: |
| 698 |
self->muladd_func_ptr = ControlRead_postprocessing_ai; |
| 699 |
break; |
| 700 |
|
| 701 |
case 2: |
| 702 |
self->muladd_func_ptr = ControlRead_postprocessing_revai; |
| 703 |
break; |
| 704 |
|
| 705 |
case 10: |
| 706 |
self->muladd_func_ptr = ControlRead_postprocessing_ia; |
| 707 |
break; |
| 708 |
|
| 709 |
case 11: |
| 710 |
self->muladd_func_ptr = ControlRead_postprocessing_aa; |
| 711 |
break; |
| 712 |
|
| 713 |
case 12: |
| 714 |
self->muladd_func_ptr = ControlRead_postprocessing_revaa; |
| 715 |
break; |
| 716 |
|
| 717 |
case 20: |
| 718 |
self->muladd_func_ptr = ControlRead_postprocessing_ireva; |
| 719 |
break; |
| 720 |
|
| 721 |
case 21: |
| 722 |
self->muladd_func_ptr = ControlRead_postprocessing_areva; |
| 723 |
break; |
| 724 |
|
| 725 |
case 22: |
| 726 |
self->muladd_func_ptr = ControlRead_postprocessing_revareva; |
| 727 |
break; |
| 728 |
} |
| 729 |
} |
| 730 |
|
| 731 |
static void |
| 732 |
ControlRead_compute_next_data_frame(ControlRead *self) |
| 733 |
{ |
| 734 |
(*self->proc_func_ptr)(self); |
| 735 |
(*self->muladd_func_ptr)(self); |
| 736 |
} |
| 737 |
|
| 738 |
static int |
| 739 |
ControlRead_traverse(ControlRead *self, visitproc visit, void *arg) |
| 740 |
{ |
| 741 |
pyo_VISIT |
| 742 |
return 0; |
| 743 |
} |
| 744 |
|
| 745 |
static int |
| 746 |
ControlRead_clear(ControlRead *self) |
| 747 |
{ |
| 748 |
pyo_CLEAR |
| 749 |
return 0; |
| 750 |
} |
| 751 |
|
| 752 |
static void |
| 753 |
ControlRead_dealloc(ControlRead* self) |
| 754 |
{ |
| 755 |
pyo_DEALLOC |
| 756 |
PyMem_RawFree(self->values); |
| 757 |
PyMem_RawFree(self->trigsBuffer); |
| 758 |
ControlRead_clear(self); |
| 759 |
Py_TYPE(self->trig_stream)->tp_free((PyObject*)self->trig_stream); |
| 760 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 761 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 762 |
} |
| 763 |
|
| 764 |
static PyObject * |
| 765 |
ControlRead_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 766 |
{ |
| 767 |
int i; |
| 768 |
PyObject *valuestmp, *multmp = NULL, *addtmp = NULL; |
| 769 |
ControlRead *self; |
| 770 |
self = (ControlRead *)type->tp_alloc(type, 0); |
| 771 |
|
| 772 |
self->loop = 0; |
| 773 |
self->rate = 1000; |
| 774 |
self->interp = 2; |
| 775 |
self->go = 1; |
| 776 |
self->modebuffer[0] = 0; |
| 777 |
self->modebuffer[1] = 0; |
| 778 |
|
| 779 |
INIT_OBJECT_COMMON |
| 780 |
Stream_setFunctionPtr(self->stream, ControlRead_compute_next_data_frame); |
| 781 |
self->mode_func_ptr = ControlRead_setProcMode; |
| 782 |
|
| 783 |
static char *kwlist[] = {"values", "rate", "loop", "interp", "mul", "add", NULL}; |
| 784 |
|
| 785 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|iiiOO", kwlist, &valuestmp, &self->rate, &self->loop, &self->interp, &multmp, &addtmp)) |
| 786 |
Py_RETURN_NONE; |
| 787 |
|
| 788 |
if (valuestmp) |
| 789 |
{ |
| 790 |
PyObject_CallMethod((PyObject *)self, "setValues", "O", valuestmp); |
| 791 |
} |
| 792 |
|
| 793 |
if (multmp) |
| 794 |
{ |
| 795 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 796 |
} |
| 797 |
|
| 798 |
if (addtmp) |
| 799 |
{ |
| 800 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 801 |
} |
| 802 |
|
| 803 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 804 |
|
| 805 |
self->trigsBuffer = (MYFLT *)PyMem_RawRealloc(self->trigsBuffer, self->bufsize * sizeof(MYFLT)); |
| 806 |
|
| 807 |
for (i = 0; i < self->bufsize; i++) |
| 808 |
{ |
| 809 |
self->trigsBuffer[i] = 0.0; |
| 810 |
} |
| 811 |
|
| 812 |
MAKE_NEW_TRIGGER_STREAM(self->trig_stream, &TriggerStreamType, NULL); |
| 813 |
TriggerStream_setData(self->trig_stream, self->trigsBuffer); |
| 814 |
|
| 815 |
self->modulo = (int)(self->sr / self->rate); |
| 816 |
|
| 817 |
(*self->mode_func_ptr)(self); |
| 818 |
|
| 819 |
SET_INTERP_POINTER |
| 820 |
|
| 821 |
return (PyObject *)self; |
| 822 |
} |
| 823 |
|
| 824 |
static PyObject * ControlRead_getServer(ControlRead* self) { GET_SERVER }; |
| 825 |
static PyObject * ControlRead_getStream(ControlRead* self) { GET_STREAM }; |
| 826 |
static PyObject * ControlRead_getTriggerStream(ControlRead* self) { GET_TRIGGER_STREAM }; |
| 827 |
static PyObject * ControlRead_setMul(ControlRead *self, PyObject *arg) { SET_MUL }; |
| 828 |
static PyObject * ControlRead_setAdd(ControlRead *self, PyObject *arg) { SET_ADD }; |
| 829 |
static PyObject * ControlRead_setSub(ControlRead *self, PyObject *arg) { SET_SUB }; |
| 830 |
static PyObject * ControlRead_setDiv(ControlRead *self, PyObject *arg) { SET_DIV }; |
| 831 |
|
| 832 |
static PyObject * ControlRead_play(ControlRead *self, PyObject *args, PyObject *kwds) |
| 833 |
{ |
| 834 |
self->count = self->time = 0; |
| 835 |
self->go = 1; |
| 836 |
PLAY |
| 837 |
}; |
| 838 |
|
| 839 |
static PyObject * ControlRead_stop(ControlRead *self, PyObject *args, PyObject *kwds) |
| 840 |
{ |
| 841 |
self->go = 0; |
| 842 |
STOP |
| 843 |
}; |
| 844 |
|
| 845 |
static PyObject * ControlRead_multiply(ControlRead *self, PyObject *arg) { MULTIPLY }; |
| 846 |
static PyObject * ControlRead_inplace_multiply(ControlRead *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 847 |
static PyObject * ControlRead_add(ControlRead *self, PyObject *arg) { ADD }; |
| 848 |
static PyObject * ControlRead_inplace_add(ControlRead *self, PyObject *arg) { INPLACE_ADD }; |
| 849 |
static PyObject * ControlRead_sub(ControlRead *self, PyObject *arg) { SUB }; |
| 850 |
static PyObject * ControlRead_inplace_sub(ControlRead *self, PyObject *arg) { INPLACE_SUB }; |
| 851 |
static PyObject * ControlRead_div(ControlRead *self, PyObject *arg) { DIV }; |
| 852 |
static PyObject * ControlRead_inplace_div(ControlRead *self, PyObject *arg) { INPLACE_DIV }; |
| 853 |
|
| 854 |
static PyObject * |
| 855 |
ControlRead_setValues(ControlRead *self, PyObject *arg) |
| 856 |
{ |
| 857 |
Py_ssize_t i; |
| 858 |
|
| 859 |
ASSERT_ARG_NOT_NULL |
| 860 |
|
| 861 |
self->size = PyList_Size(arg); |
| 862 |
self->values = (MYFLT *)PyMem_RawRealloc(self->values, self->size * sizeof(MYFLT)); |
| 863 |
|
| 864 |
for (i = 0; i < self->size; i++) |
| 865 |
{ |
| 866 |
self->values[i] = PyFloat_AsDouble(PyList_GET_ITEM(arg, i)); |
| 867 |
} |
| 868 |
|
| 869 |
Py_RETURN_NONE; |
| 870 |
} |
| 871 |
|
| 872 |
static PyObject * |
| 873 |
ControlRead_setRate(ControlRead *self, PyObject *arg) |
| 874 |
{ |
| 875 |
ASSERT_ARG_NOT_NULL |
| 876 |
|
| 877 |
self->rate = PyLong_AsLong(arg); |
| 878 |
self->modulo = (int)(self->sr / self->rate); |
| 879 |
|
| 880 |
Py_RETURN_NONE; |
| 881 |
} |
| 882 |
|
| 883 |
static PyObject * |
| 884 |
ControlRead_setLoop(ControlRead *self, PyObject *arg) |
| 885 |
{ |
| 886 |
ASSERT_ARG_NOT_NULL |
| 887 |
|
| 888 |
self->loop = PyLong_AsLong(arg); |
| 889 |
|
| 890 |
Py_RETURN_NONE; |
| 891 |
} |
| 892 |
|
| 893 |
static PyObject * |
| 894 |
ControlRead_setInterp(ControlRead *self, PyObject *arg) |
| 895 |
{ |
| 896 |
ASSERT_ARG_NOT_NULL |
| 897 |
|
| 898 |
if (PyNumber_Check(arg)) |
| 899 |
{ |
| 900 |
self->interp = PyLong_AsLong(PyNumber_Long(arg)); |
| 901 |
} |
| 902 |
|
| 903 |
SET_INTERP_POINTER |
| 904 |
|
| 905 |
Py_RETURN_NONE; |
| 906 |
} |
| 907 |
|
| 908 |
static PyMemberDef ControlRead_members[] = |
| 909 |
{ |
| 910 |
{"server", T_OBJECT_EX, offsetof(ControlRead, server), 0, "Pyo server."}, |
| 911 |
{"stream", T_OBJECT_EX, offsetof(ControlRead, stream), 0, "Stream object."}, |
| 912 |
{"trig_stream", T_OBJECT_EX, offsetof(ControlRead, trig_stream), 0, "Trigger Stream object."}, |
| 913 |
{"mul", T_OBJECT_EX, offsetof(ControlRead, mul), 0, "Mul factor."}, |
| 914 |
{"add", T_OBJECT_EX, offsetof(ControlRead, add), 0, "Add factor."}, |
| 915 |
{NULL} /* Sentinel */ |
| 916 |
}; |
| 917 |
|
| 918 |
static PyMethodDef ControlRead_methods[] = |
| 919 |
{ |
| 920 |
{"getServer", (PyCFunction)ControlRead_getServer, METH_NOARGS, "Returns server object."}, |
| 921 |
{"_getStream", (PyCFunction)ControlRead_getStream, METH_NOARGS, "Returns stream object."}, |
| 922 |
{"_getTriggerStream", (PyCFunction)ControlRead_getTriggerStream, METH_NOARGS, "Returns trigger stream object."}, |
| 923 |
{"play", (PyCFunction)ControlRead_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 924 |
{"stop", (PyCFunction)ControlRead_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 925 |
{"setValues", (PyCFunction)ControlRead_setValues, METH_O, "Fill buffer with values in input."}, |
| 926 |
{"setRate", (PyCFunction)ControlRead_setRate, METH_O, "Sets reading rate."}, |
| 927 |
{"setLoop", (PyCFunction)ControlRead_setLoop, METH_O, "Sets the looping mode."}, |
| 928 |
{"setInterp", (PyCFunction)ControlRead_setInterp, METH_O, "Sets reader interpolation mode."}, |
| 929 |
{"setMul", (PyCFunction)ControlRead_setMul, METH_O, "Sets oscillator mul factor."}, |
| 930 |
{"setAdd", (PyCFunction)ControlRead_setAdd, METH_O, "Sets oscillator add factor."}, |
| 931 |
{"setSub", (PyCFunction)ControlRead_setSub, METH_O, "Sets oscillator inverse add factor."}, |
| 932 |
{"setDiv", (PyCFunction)ControlRead_setDiv, METH_O, "Sets inverse mul factor."}, |
| 933 |
{NULL} /* Sentinel */ |
| 934 |
}; |
| 935 |
|
| 936 |
static PyNumberMethods ControlRead_as_number = |
| 937 |
{ |
| 938 |
(binaryfunc)ControlRead_add, /*nb_add*/ |
| 939 |
(binaryfunc)ControlRead_sub, /*nb_subtract*/ |
| 940 |
(binaryfunc)ControlRead_multiply, /*nb_multiply*/ |
| 941 |
0, /*nb_remainder*/ |
| 942 |
0, /*nb_divmod*/ |
| 943 |
0, /*nb_power*/ |
| 944 |
0, /*nb_neg*/ |
| 945 |
0, /*nb_pos*/ |
| 946 |
0, /*(unaryfunc)array_abs,*/ |
| 947 |
0, /*nb_nonzero*/ |
| 948 |
0, /*nb_invert*/ |
| 949 |
0, /*nb_lshift*/ |
| 950 |
0, /*nb_rshift*/ |
| 951 |
0, /*nb_and*/ |
| 952 |
0, /*nb_xor*/ |
| 953 |
0, /*nb_or*/ |
| 954 |
0, /*nb_int*/ |
| 955 |
0, /*nb_long*/ |
| 956 |
0, /*nb_float*/ |
| 957 |
(binaryfunc)ControlRead_inplace_add, /*inplace_add*/ |
| 958 |
(binaryfunc)ControlRead_inplace_sub, /*inplace_subtract*/ |
| 959 |
(binaryfunc)ControlRead_inplace_multiply, /*inplace_multiply*/ |
| 960 |
0, /*inplace_remainder*/ |
| 961 |
0, /*inplace_power*/ |
| 962 |
0, /*inplace_lshift*/ |
| 963 |
0, /*inplace_rshift*/ |
| 964 |
0, /*inplace_and*/ |
| 965 |
0, /*inplace_xor*/ |
| 966 |
0, /*inplace_or*/ |
| 967 |
0, /*nb_floor_divide*/ |
| 968 |
(binaryfunc)ControlRead_div, /*nb_true_divide*/ |
| 969 |
0, /*nb_inplace_floor_divide*/ |
| 970 |
(binaryfunc)ControlRead_inplace_div, /*nb_inplace_true_divide*/ |
| 971 |
0, /* nb_index */ |
| 972 |
}; |
| 973 |
|
| 974 |
PyTypeObject ControlReadType = |
| 975 |
{ |
| 976 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 977 |
"_pyo.ControlRead_base", /*tp_name*/ |
| 978 |
sizeof(ControlRead), /*tp_basicsize*/ |
| 979 |
0, /*tp_itemsize*/ |
| 980 |
(destructor)ControlRead_dealloc, /*tp_dealloc*/ |
| 981 |
0, /*tp_print*/ |
| 982 |
0, /*tp_getattr*/ |
| 983 |
0, /*tp_setattr*/ |
| 984 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 985 |
0, /*tp_repr*/ |
| 986 |
&ControlRead_as_number, /*tp_as_number*/ |
| 987 |
0, /*tp_as_sequence*/ |
| 988 |
0, /*tp_as_mapping*/ |
| 989 |
0, /*tp_hash */ |
| 990 |
0, /*tp_call*/ |
| 991 |
0, /*tp_str*/ |
| 992 |
0, /*tp_getattro*/ |
| 993 |
0, /*tp_setattro*/ |
| 994 |
0, /*tp_as_buffer*/ |
| 995 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 996 |
"ControlRead objects. Generates an oscillatory waveform.", /* tp_doc */ |
| 997 |
(traverseproc)ControlRead_traverse, /* tp_traverse */ |
| 998 |
(inquiry)ControlRead_clear, /* tp_clear */ |
| 999 |
0, /* tp_richcompare */ |
| 1000 |
0, /* tp_weaklistoffset */ |
| 1001 |
0, /* tp_iter */ |
| 1002 |
0, /* tp_iternext */ |
| 1003 |
ControlRead_methods, /* tp_methods */ |
| 1004 |
ControlRead_members, /* tp_members */ |
| 1005 |
0, /* tp_getset */ |
| 1006 |
0, /* tp_base */ |
| 1007 |
0, /* tp_dict */ |
| 1008 |
0, /* tp_descr_get */ |
| 1009 |
0, /* tp_descr_set */ |
| 1010 |
0, /* tp_dictoffset */ |
| 1011 |
0, /* tp_init */ |
| 1012 |
0, /* tp_alloc */ |
| 1013 |
ControlRead_new, /* tp_new */ |
| 1014 |
}; |
| 1015 |
|
| 1016 |
/************/ |
| 1017 |
/* NoteinRec */ |
| 1018 |
/************/ |
| 1019 |
typedef struct |
| 1020 |
{ |
| 1021 |
pyo_audio_HEAD |
| 1022 |
PyObject *inputp; |
| 1023 |
Stream *inputp_stream; |
| 1024 |
PyObject *inputv; |
| 1025 |
Stream *inputv_stream; |
| 1026 |
PyObject *tmp_list_p; |
| 1027 |
PyObject *tmp_list_v; |
| 1028 |
PyObject *tmp_list_t; |
| 1029 |
MYFLT last_pitch; |
| 1030 |
MYFLT last_vel; |
| 1031 |
long time; |
| 1032 |
} NoteinRec; |
| 1033 |
|
| 1034 |
static void |
| 1035 |
NoteinRec_process(NoteinRec *self) |
| 1036 |
{ |
| 1037 |
int i; |
| 1038 |
MYFLT pit, vel; |
| 1039 |
|
| 1040 |
MYFLT *inp = Stream_getData((Stream *)self->inputp_stream); |
| 1041 |
MYFLT *inv = Stream_getData((Stream *)self->inputv_stream); |
| 1042 |
|
| 1043 |
for (i = 0; i < self->bufsize; i++) |
| 1044 |
{ |
| 1045 |
pit = inp[i]; |
| 1046 |
vel = inv[i]; |
| 1047 |
|
| 1048 |
if (pit != self->last_pitch || vel != self->last_vel) |
| 1049 |
{ |
| 1050 |
self->last_pitch = pit; |
| 1051 |
self->last_vel = vel; |
| 1052 |
PyList_Append(self->tmp_list_p, PyFloat_FromDouble(pit)); |
| 1053 |
PyList_Append(self->tmp_list_v, PyFloat_FromDouble(vel)); |
| 1054 |
PyList_Append(self->tmp_list_t, PyFloat_FromDouble( (float)self->time / self->sr) ); |
| 1055 |
} |
| 1056 |
|
| 1057 |
self->time++; |
| 1058 |
} |
| 1059 |
} |
| 1060 |
|
| 1061 |
static void |
| 1062 |
NoteinRec_setProcMode(NoteinRec *self) |
| 1063 |
{ |
| 1064 |
self->proc_func_ptr = NoteinRec_process; |
| 1065 |
} |
| 1066 |
|
| 1067 |
static void |
| 1068 |
NoteinRec_compute_next_data_frame(NoteinRec *self) |
| 1069 |
{ |
| 1070 |
(*self->proc_func_ptr)(self); |
| 1071 |
} |
| 1072 |
|
| 1073 |
static int |
| 1074 |
NoteinRec_traverse(NoteinRec *self, visitproc visit, void *arg) |
| 1075 |
{ |
| 1076 |
pyo_VISIT |
| 1077 |
Py_VISIT(self->inputp); |
| 1078 |
Py_VISIT(self->inputp_stream); |
| 1079 |
Py_VISIT(self->inputv); |
| 1080 |
Py_VISIT(self->inputv_stream); |
| 1081 |
Py_VISIT(self->tmp_list_p); |
| 1082 |
Py_VISIT(self->tmp_list_v); |
| 1083 |
Py_VISIT(self->tmp_list_t); |
| 1084 |
return 0; |
| 1085 |
} |
| 1086 |
|
| 1087 |
static int |
| 1088 |
NoteinRec_clear(NoteinRec *self) |
| 1089 |
{ |
| 1090 |
pyo_CLEAR |
| 1091 |
Py_CLEAR(self->inputp); |
| 1092 |
Py_CLEAR(self->inputp_stream); |
| 1093 |
Py_CLEAR(self->inputv); |
| 1094 |
Py_CLEAR(self->inputv_stream); |
| 1095 |
Py_CLEAR(self->tmp_list_p); |
| 1096 |
Py_CLEAR(self->tmp_list_v); |
| 1097 |
Py_CLEAR(self->tmp_list_t); |
| 1098 |
return 0; |
| 1099 |
} |
| 1100 |
|
| 1101 |
static void |
| 1102 |
NoteinRec_dealloc(NoteinRec* self) |
| 1103 |
{ |
| 1104 |
pyo_DEALLOC |
| 1105 |
NoteinRec_clear(self); |
| 1106 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 1107 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 1108 |
} |
| 1109 |
|
| 1110 |
static PyObject * |
| 1111 |
NoteinRec_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 1112 |
{ |
| 1113 |
int i; |
| 1114 |
PyObject *inputptmp, *inputp_streamtmp, *inputvtmp, *inputv_streamtmp; |
| 1115 |
NoteinRec *self; |
| 1116 |
self = (NoteinRec *)type->tp_alloc(type, 0); |
| 1117 |
|
| 1118 |
self->tmp_list_p = PyList_New(0); |
| 1119 |
self->tmp_list_v = PyList_New(0); |
| 1120 |
self->tmp_list_t = PyList_New(0); |
| 1121 |
self->last_pitch = self->last_vel = 0.0; |
| 1122 |
|
| 1123 |
INIT_OBJECT_COMMON |
| 1124 |
Stream_setFunctionPtr(self->stream, NoteinRec_compute_next_data_frame); |
| 1125 |
self->mode_func_ptr = NoteinRec_setProcMode; |
| 1126 |
|
| 1127 |
static char *kwlist[] = {"inputp", "inputv", NULL}; |
| 1128 |
|
| 1129 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &inputptmp, &inputvtmp)) |
| 1130 |
Py_RETURN_NONE; |
| 1131 |
|
| 1132 |
self->inputp = inputptmp; |
| 1133 |
Py_INCREF(self->inputp); |
| 1134 |
inputp_streamtmp = PyObject_CallMethod((PyObject *)self->inputp, "_getStream", NULL); |
| 1135 |
self->inputp_stream = (Stream *)inputp_streamtmp; |
| 1136 |
Py_INCREF(self->inputp_stream); |
| 1137 |
|
| 1138 |
self->inputv = inputvtmp; |
| 1139 |
Py_INCREF(self->inputv); |
| 1140 |
inputv_streamtmp = PyObject_CallMethod((PyObject *)self->inputv, "_getStream", NULL); |
| 1141 |
self->inputv_stream = (Stream *)inputv_streamtmp; |
| 1142 |
Py_INCREF(self->inputv_stream); |
| 1143 |
|
| 1144 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 1145 |
|
| 1146 |
(*self->mode_func_ptr)(self); |
| 1147 |
|
| 1148 |
return (PyObject *)self; |
| 1149 |
} |
| 1150 |
|
| 1151 |
static PyObject * NoteinRec_getServer(NoteinRec* self) { GET_SERVER }; |
| 1152 |
static PyObject * NoteinRec_getStream(NoteinRec* self) { GET_STREAM }; |
| 1153 |
|
| 1154 |
static PyObject * NoteinRec_play(NoteinRec *self, PyObject *args, PyObject *kwds) |
| 1155 |
{ |
| 1156 |
self->time = 0; |
| 1157 |
PLAY |
| 1158 |
}; |
| 1159 |
|
| 1160 |
static PyObject * NoteinRec_stop(NoteinRec *self, PyObject *args, PyObject *kwds) { STOP }; |
| 1161 |
|
| 1162 |
static PyObject * |
| 1163 |
NoteinRec_getData(NoteinRec *self) |
| 1164 |
{ |
| 1165 |
int i; |
| 1166 |
PyObject *data, *point; |
| 1167 |
|
| 1168 |
Py_ssize_t size = PyList_Size(self->tmp_list_p); |
| 1169 |
data = PyList_New(size); |
| 1170 |
|
| 1171 |
for (i = 0; i < size; i++) |
| 1172 |
{ |
| 1173 |
point = PyTuple_New(3); |
| 1174 |
PyTuple_SET_ITEM(point, 0, PyList_GET_ITEM(self->tmp_list_t, i)); |
| 1175 |
PyTuple_SET_ITEM(point, 1, PyList_GET_ITEM(self->tmp_list_p, i)); |
| 1176 |
PyTuple_SET_ITEM(point, 2, PyList_GET_ITEM(self->tmp_list_v, i)); |
| 1177 |
PyList_SetItem(data, i, point); |
| 1178 |
} |
| 1179 |
|
| 1180 |
return data; |
| 1181 |
} |
| 1182 |
|
| 1183 |
static PyMemberDef NoteinRec_members[] = |
| 1184 |
{ |
| 1185 |
{"server", T_OBJECT_EX, offsetof(NoteinRec, server), 0, "Pyo server."}, |
| 1186 |
{"stream", T_OBJECT_EX, offsetof(NoteinRec, stream), 0, "Stream object."}, |
| 1187 |
{"inputp", T_OBJECT_EX, offsetof(NoteinRec, inputp), 0, "Pitch input."}, |
| 1188 |
{"inputv", T_OBJECT_EX, offsetof(NoteinRec, inputv), 0, "Velocity input."}, |
| 1189 |
{NULL} /* Sentinel */ |
| 1190 |
}; |
| 1191 |
|
| 1192 |
static PyMethodDef NoteinRec_methods[] = |
| 1193 |
{ |
| 1194 |
{"getServer", (PyCFunction)NoteinRec_getServer, METH_NOARGS, "Returns server object."}, |
| 1195 |
{"_getStream", (PyCFunction)NoteinRec_getStream, METH_NOARGS, "Returns stream object."}, |
| 1196 |
{"play", (PyCFunction)NoteinRec_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 1197 |
{"stop", (PyCFunction)NoteinRec_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 1198 |
{"getData", (PyCFunction)NoteinRec_getData, METH_NOARGS, "Returns list of sampled points."}, |
| 1199 |
{NULL} /* Sentinel */ |
| 1200 |
}; |
| 1201 |
|
| 1202 |
PyTypeObject NoteinRecType = |
| 1203 |
{ |
| 1204 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 1205 |
"_pyo.NoteinRec_base", /*tp_name*/ |
| 1206 |
sizeof(NoteinRec), /*tp_basicsize*/ |
| 1207 |
0, /*tp_itemsize*/ |
| 1208 |
(destructor)NoteinRec_dealloc, /*tp_dealloc*/ |
| 1209 |
0, /*tp_print*/ |
| 1210 |
0, /*tp_getattr*/ |
| 1211 |
0, /*tp_setattr*/ |
| 1212 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 1213 |
0, /*tp_repr*/ |
| 1214 |
0, /*tp_as_number*/ |
| 1215 |
0, /*tp_as_sequence*/ |
| 1216 |
0, /*tp_as_mapping*/ |
| 1217 |
0, /*tp_hash */ |
| 1218 |
0, /*tp_call*/ |
| 1219 |
0, /*tp_str*/ |
| 1220 |
0, /*tp_getattro*/ |
| 1221 |
0, /*tp_setattro*/ |
| 1222 |
0, /*tp_as_buffer*/ |
| 1223 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 1224 |
"NoteinRec objects. Records Notein signal with user-defined sampling rate.", /* tp_doc */ |
| 1225 |
(traverseproc)NoteinRec_traverse, /* tp_traverse */ |
| 1226 |
(inquiry)NoteinRec_clear, /* tp_clear */ |
| 1227 |
0, /* tp_richcompare */ |
| 1228 |
0, /* tp_weaklistoffset */ |
| 1229 |
0, /* tp_iter */ |
| 1230 |
0, /* tp_iternext */ |
| 1231 |
NoteinRec_methods, /* tp_methods */ |
| 1232 |
NoteinRec_members, /* tp_members */ |
| 1233 |
0, /* tp_getset */ |
| 1234 |
0, /* tp_base */ |
| 1235 |
0, /* tp_dict */ |
| 1236 |
0, /* tp_descr_get */ |
| 1237 |
0, /* tp_descr_set */ |
| 1238 |
0, /* tp_dictoffset */ |
| 1239 |
0, /* tp_init */ |
| 1240 |
0, /* tp_alloc */ |
| 1241 |
NoteinRec_new, /* tp_new */ |
| 1242 |
}; |
| 1243 |
|
| 1244 |
/**************/ |
| 1245 |
/* NoteinRead object */ |
| 1246 |
/**************/ |
| 1247 |
typedef struct |
| 1248 |
{ |
| 1249 |
pyo_audio_HEAD |
| 1250 |
MYFLT *values; |
| 1251 |
long *timestamps; |
| 1252 |
MYFLT value; |
| 1253 |
int loop; |
| 1254 |
int go; |
| 1255 |
int modebuffer[2]; |
| 1256 |
long count; |
| 1257 |
long time; |
| 1258 |
long size; |
| 1259 |
MYFLT *trigsBuffer; |
| 1260 |
TriggerStream *trig_stream; |
| 1261 |
} NoteinRead; |
| 1262 |
|
| 1263 |
static void |
| 1264 |
NoteinRead_readframes_i(NoteinRead *self) |
| 1265 |
{ |
| 1266 |
long i; |
| 1267 |
|
| 1268 |
if (self->go == 0) |
| 1269 |
PyObject_CallMethod((PyObject *)self, "stop", NULL); |
| 1270 |
|
| 1271 |
for (i = 0; i < self->bufsize; i++) |
| 1272 |
{ |
| 1273 |
self->trigsBuffer[i] = 0.0; |
| 1274 |
|
| 1275 |
if (self->go == 1) |
| 1276 |
{ |
| 1277 |
if (self->time >= self->timestamps[self->count]) |
| 1278 |
{ |
| 1279 |
self->value = self->values[self->count]; |
| 1280 |
self->data[i] = self->value; |
| 1281 |
self->count++; |
| 1282 |
} |
| 1283 |
else |
| 1284 |
self->data[i] = self->value; |
| 1285 |
} |
| 1286 |
else |
| 1287 |
self->data[i] = 0.0; |
| 1288 |
|
| 1289 |
if (self->count >= self->size) |
| 1290 |
{ |
| 1291 |
self->trigsBuffer[i] = 1.0; |
| 1292 |
|
| 1293 |
if (self->loop == 1) |
| 1294 |
self->time = self->count = 0; |
| 1295 |
else |
| 1296 |
self->go = 0; |
| 1297 |
} |
| 1298 |
|
| 1299 |
self->time++; |
| 1300 |
} |
| 1301 |
} |
| 1302 |
|
| 1303 |
static void NoteinRead_postprocessing_ii(NoteinRead *self) { POST_PROCESSING_II }; |
| 1304 |
static void NoteinRead_postprocessing_ai(NoteinRead *self) { POST_PROCESSING_AI }; |
| 1305 |
static void NoteinRead_postprocessing_ia(NoteinRead *self) { POST_PROCESSING_IA }; |
| 1306 |
static void NoteinRead_postprocessing_aa(NoteinRead *self) { POST_PROCESSING_AA }; |
| 1307 |
static void NoteinRead_postprocessing_ireva(NoteinRead *self) { POST_PROCESSING_IREVA }; |
| 1308 |
static void NoteinRead_postprocessing_areva(NoteinRead *self) { POST_PROCESSING_AREVA }; |
| 1309 |
static void NoteinRead_postprocessing_revai(NoteinRead *self) { POST_PROCESSING_REVAI }; |
| 1310 |
static void NoteinRead_postprocessing_revaa(NoteinRead *self) { POST_PROCESSING_REVAA }; |
| 1311 |
static void NoteinRead_postprocessing_revareva(NoteinRead *self) { POST_PROCESSING_REVAREVA }; |
| 1312 |
|
| 1313 |
static void |
| 1314 |
NoteinRead_setProcMode(NoteinRead *self) |
| 1315 |
{ |
| 1316 |
int muladdmode; |
| 1317 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 1318 |
|
| 1319 |
self->proc_func_ptr = NoteinRead_readframes_i; |
| 1320 |
|
| 1321 |
switch (muladdmode) |
| 1322 |
{ |
| 1323 |
case 0: |
| 1324 |
self->muladd_func_ptr = NoteinRead_postprocessing_ii; |
| 1325 |
break; |
| 1326 |
|
| 1327 |
case 1: |
| 1328 |
self->muladd_func_ptr = NoteinRead_postprocessing_ai; |
| 1329 |
break; |
| 1330 |
|
| 1331 |
case 2: |
| 1332 |
self->muladd_func_ptr = NoteinRead_postprocessing_revai; |
| 1333 |
break; |
| 1334 |
|
| 1335 |
case 10: |
| 1336 |
self->muladd_func_ptr = NoteinRead_postprocessing_ia; |
| 1337 |
break; |
| 1338 |
|
| 1339 |
case 11: |
| 1340 |
self->muladd_func_ptr = NoteinRead_postprocessing_aa; |
| 1341 |
break; |
| 1342 |
|
| 1343 |
case 12: |
| 1344 |
self->muladd_func_ptr = NoteinRead_postprocessing_revaa; |
| 1345 |
break; |
| 1346 |
|
| 1347 |
case 20: |
| 1348 |
self->muladd_func_ptr = NoteinRead_postprocessing_ireva; |
| 1349 |
break; |
| 1350 |
|
| 1351 |
case 21: |
| 1352 |
self->muladd_func_ptr = NoteinRead_postprocessing_areva; |
| 1353 |
break; |
| 1354 |
|
| 1355 |
case 22: |
| 1356 |
self->muladd_func_ptr = NoteinRead_postprocessing_revareva; |
| 1357 |
break; |
| 1358 |
} |
| 1359 |
} |
| 1360 |
|
| 1361 |
static void |
| 1362 |
NoteinRead_compute_next_data_frame(NoteinRead *self) |
| 1363 |
{ |
| 1364 |
(*self->proc_func_ptr)(self); |
| 1365 |
(*self->muladd_func_ptr)(self); |
| 1366 |
} |
| 1367 |
|
| 1368 |
static int |
| 1369 |
NoteinRead_traverse(NoteinRead *self, visitproc visit, void *arg) |
| 1370 |
{ |
| 1371 |
pyo_VISIT |
| 1372 |
return 0; |
| 1373 |
} |
| 1374 |
|
| 1375 |
static int |
| 1376 |
NoteinRead_clear(NoteinRead *self) |
| 1377 |
{ |
| 1378 |
pyo_CLEAR |
| 1379 |
return 0; |
| 1380 |
} |
| 1381 |
|
| 1382 |
static void |
| 1383 |
NoteinRead_dealloc(NoteinRead* self) |
| 1384 |
{ |
| 1385 |
pyo_DEALLOC |
| 1386 |
PyMem_RawFree(self->values); |
| 1387 |
PyMem_RawFree(self->timestamps); |
| 1388 |
PyMem_RawFree(self->trigsBuffer); |
| 1389 |
NoteinRead_clear(self); |
| 1390 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 1391 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 1392 |
} |
| 1393 |
|
| 1394 |
static PyObject * |
| 1395 |
NoteinRead_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 1396 |
{ |
| 1397 |
int i; |
| 1398 |
PyObject *valuestmp, *timestampstmp, *multmp = NULL, *addtmp = NULL; |
| 1399 |
NoteinRead *self; |
| 1400 |
self = (NoteinRead *)type->tp_alloc(type, 0); |
| 1401 |
|
| 1402 |
self->value = 0.0; |
| 1403 |
self->loop = 0; |
| 1404 |
self->go = 1; |
| 1405 |
self->modebuffer[0] = 0; |
| 1406 |
self->modebuffer[1] = 0; |
| 1407 |
|
| 1408 |
INIT_OBJECT_COMMON |
| 1409 |
Stream_setFunctionPtr(self->stream, NoteinRead_compute_next_data_frame); |
| 1410 |
self->mode_func_ptr = NoteinRead_setProcMode; |
| 1411 |
|
| 1412 |
static char *kwlist[] = {"values", "timestamps", "loop", "mul", "add", NULL}; |
| 1413 |
|
| 1414 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|iOO", kwlist, &valuestmp, ×tampstmp, &self->loop, &multmp, &addtmp)) |
| 1415 |
Py_RETURN_NONE; |
| 1416 |
|
| 1417 |
if (valuestmp) |
| 1418 |
{ |
| 1419 |
PyObject_CallMethod((PyObject *)self, "setValues", "O", valuestmp); |
| 1420 |
} |
| 1421 |
|
| 1422 |
if (timestampstmp) |
| 1423 |
{ |
| 1424 |
PyObject_CallMethod((PyObject *)self, "setTimestamps", "O", timestampstmp); |
| 1425 |
} |
| 1426 |
|
| 1427 |
if (multmp) |
| 1428 |
{ |
| 1429 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 1430 |
} |
| 1431 |
|
| 1432 |
if (addtmp) |
| 1433 |
{ |
| 1434 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 1435 |
} |
| 1436 |
|
| 1437 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 1438 |
|
| 1439 |
self->trigsBuffer = (MYFLT *)PyMem_RawRealloc(self->trigsBuffer, self->bufsize * sizeof(MYFLT)); |
| 1440 |
|
| 1441 |
for (i = 0; i < self->bufsize; i++) |
| 1442 |
{ |
| 1443 |
self->trigsBuffer[i] = 0.0; |
| 1444 |
} |
| 1445 |
|
| 1446 |
MAKE_NEW_TRIGGER_STREAM(self->trig_stream, &TriggerStreamType, NULL); |
| 1447 |
TriggerStream_setData(self->trig_stream, self->trigsBuffer); |
| 1448 |
|
| 1449 |
(*self->mode_func_ptr)(self); |
| 1450 |
|
| 1451 |
return (PyObject *)self; |
| 1452 |
} |
| 1453 |
|
| 1454 |
static PyObject * NoteinRead_getServer(NoteinRead* self) { GET_SERVER }; |
| 1455 |
static PyObject * NoteinRead_getStream(NoteinRead* self) { GET_STREAM }; |
| 1456 |
static PyObject * NoteinRead_getTriggerStream(NoteinRead* self) { GET_TRIGGER_STREAM }; |
| 1457 |
static PyObject * NoteinRead_setMul(NoteinRead *self, PyObject *arg) { SET_MUL }; |
| 1458 |
static PyObject * NoteinRead_setAdd(NoteinRead *self, PyObject *arg) { SET_ADD }; |
| 1459 |
static PyObject * NoteinRead_setSub(NoteinRead *self, PyObject *arg) { SET_SUB }; |
| 1460 |
static PyObject * NoteinRead_setDiv(NoteinRead *self, PyObject *arg) { SET_DIV }; |
| 1461 |
|
| 1462 |
static PyObject * NoteinRead_play(NoteinRead *self, PyObject *args, PyObject *kwds) |
| 1463 |
{ |
| 1464 |
self->count = self->time = 0; |
| 1465 |
self->go = 1; |
| 1466 |
PLAY |
| 1467 |
}; |
| 1468 |
|
| 1469 |
static PyObject * NoteinRead_stop(NoteinRead *self, PyObject *args, PyObject *kwds) |
| 1470 |
{ |
| 1471 |
self->go = 0; |
| 1472 |
STOP |
| 1473 |
}; |
| 1474 |
|
| 1475 |
static PyObject * NoteinRead_multiply(NoteinRead *self, PyObject *arg) { MULTIPLY }; |
| 1476 |
static PyObject * NoteinRead_inplace_multiply(NoteinRead *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 1477 |
static PyObject * NoteinRead_add(NoteinRead *self, PyObject *arg) { ADD }; |
| 1478 |
static PyObject * NoteinRead_inplace_add(NoteinRead *self, PyObject *arg) { INPLACE_ADD }; |
| 1479 |
static PyObject * NoteinRead_sub(NoteinRead *self, PyObject *arg) { SUB }; |
| 1480 |
static PyObject * NoteinRead_inplace_sub(NoteinRead *self, PyObject *arg) { INPLACE_SUB }; |
| 1481 |
static PyObject * NoteinRead_div(NoteinRead *self, PyObject *arg) { DIV }; |
| 1482 |
static PyObject * NoteinRead_inplace_div(NoteinRead *self, PyObject *arg) { INPLACE_DIV }; |
| 1483 |
|
| 1484 |
static PyObject * |
| 1485 |
NoteinRead_setValues(NoteinRead *self, PyObject *arg) |
| 1486 |
{ |
| 1487 |
Py_ssize_t i; |
| 1488 |
|
| 1489 |
ASSERT_ARG_NOT_NULL |
| 1490 |
|
| 1491 |
self->size = PyList_Size(arg); |
| 1492 |
self->values = (MYFLT *)PyMem_RawRealloc(self->values, self->size * sizeof(MYFLT)); |
| 1493 |
|
| 1494 |
for (i = 0; i < self->size; i++) |
| 1495 |
{ |
| 1496 |
self->values[i] = PyFloat_AsDouble(PyList_GET_ITEM(arg, i)); |
| 1497 |
} |
| 1498 |
|
| 1499 |
Py_RETURN_NONE; |
| 1500 |
} |
| 1501 |
|
| 1502 |
static PyObject * |
| 1503 |
NoteinRead_setTimestamps(NoteinRead *self, PyObject *arg) |
| 1504 |
{ |
| 1505 |
Py_ssize_t i; |
| 1506 |
|
| 1507 |
ASSERT_ARG_NOT_NULL |
| 1508 |
|
| 1509 |
self->size = PyList_Size(arg); |
| 1510 |
self->timestamps = (long *)PyMem_RawRealloc(self->timestamps, self->size * sizeof(long)); |
| 1511 |
|
| 1512 |
for (i = 0; i < self->size; i++) |
| 1513 |
{ |
| 1514 |
self->timestamps[i] = (long)(PyFloat_AsDouble(PyList_GET_ITEM(arg, i)) * self->sr); |
| 1515 |
} |
| 1516 |
|
| 1517 |
Py_RETURN_NONE; |
| 1518 |
} |
| 1519 |
|
| 1520 |
static PyObject * |
| 1521 |
NoteinRead_setLoop(NoteinRead *self, PyObject *arg) |
| 1522 |
{ |
| 1523 |
ASSERT_ARG_NOT_NULL |
| 1524 |
|
| 1525 |
self->loop = PyLong_AsLong(arg); |
| 1526 |
|
| 1527 |
Py_RETURN_NONE; |
| 1528 |
} |
| 1529 |
|
| 1530 |
static PyMemberDef NoteinRead_members[] = |
| 1531 |
{ |
| 1532 |
{"server", T_OBJECT_EX, offsetof(NoteinRead, server), 0, "Pyo server."}, |
| 1533 |
{"stream", T_OBJECT_EX, offsetof(NoteinRead, stream), 0, "Stream object."}, |
| 1534 |
{"trig_stream", T_OBJECT_EX, offsetof(NoteinRead, trig_stream), 0, "Trigger Stream object."}, |
| 1535 |
{"mul", T_OBJECT_EX, offsetof(NoteinRead, mul), 0, "Mul factor."}, |
| 1536 |
{"add", T_OBJECT_EX, offsetof(NoteinRead, add), 0, "Add factor."}, |
| 1537 |
{NULL} /* Sentinel */ |
| 1538 |
}; |
| 1539 |
|
| 1540 |
static PyMethodDef NoteinRead_methods[] = |
| 1541 |
{ |
| 1542 |
{"getServer", (PyCFunction)NoteinRead_getServer, METH_NOARGS, "Returns server object."}, |
| 1543 |
{"_getStream", (PyCFunction)NoteinRead_getStream, METH_NOARGS, "Returns stream object."}, |
| 1544 |
{"_getTriggerStream", (PyCFunction)NoteinRead_getTriggerStream, METH_NOARGS, "Returns trigger stream object."}, |
| 1545 |
{"play", (PyCFunction)NoteinRead_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 1546 |
{"stop", (PyCFunction)NoteinRead_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 1547 |
{"setValues", (PyCFunction)NoteinRead_setValues, METH_O, "Fill buffer with values in input."}, |
| 1548 |
{"setTimestamps", (PyCFunction)NoteinRead_setTimestamps, METH_O, "Fill buffer with timestamps in input."}, |
| 1549 |
{"setLoop", (PyCFunction)NoteinRead_setLoop, METH_O, "Sets the looping mode."}, |
| 1550 |
{"setMul", (PyCFunction)NoteinRead_setMul, METH_O, "Sets oscillator mul factor."}, |
| 1551 |
{"setAdd", (PyCFunction)NoteinRead_setAdd, METH_O, "Sets oscillator add factor."}, |
| 1552 |
{"setSub", (PyCFunction)NoteinRead_setSub, METH_O, "Sets oscillator inverse add factor."}, |
| 1553 |
{"setDiv", (PyCFunction)NoteinRead_setDiv, METH_O, "Sets inverse mul factor."}, |
| 1554 |
{NULL} /* Sentinel */ |
| 1555 |
}; |
| 1556 |
|
| 1557 |
static PyNumberMethods NoteinRead_as_number = |
| 1558 |
{ |
| 1559 |
(binaryfunc)NoteinRead_add, /*nb_add*/ |
| 1560 |
(binaryfunc)NoteinRead_sub, /*nb_subtract*/ |
| 1561 |
(binaryfunc)NoteinRead_multiply, /*nb_multiply*/ |
| 1562 |
0, /*nb_remainder*/ |
| 1563 |
0, /*nb_divmod*/ |
| 1564 |
0, /*nb_power*/ |
| 1565 |
0, /*nb_neg*/ |
| 1566 |
0, /*nb_pos*/ |
| 1567 |
0, /*(unaryfunc)array_abs,*/ |
| 1568 |
0, /*nb_nonzero*/ |
| 1569 |
0, /*nb_invert*/ |
| 1570 |
0, /*nb_lshift*/ |
| 1571 |
0, /*nb_rshift*/ |
| 1572 |
0, /*nb_and*/ |
| 1573 |
0, /*nb_xor*/ |
| 1574 |
0, /*nb_or*/ |
| 1575 |
0, /*nb_int*/ |
| 1576 |
0, /*nb_long*/ |
| 1577 |
0, /*nb_float*/ |
| 1578 |
(binaryfunc)NoteinRead_inplace_add, /*inplace_add*/ |
| 1579 |
(binaryfunc)NoteinRead_inplace_sub, /*inplace_subtract*/ |
| 1580 |
(binaryfunc)NoteinRead_inplace_multiply, /*inplace_multiply*/ |
| 1581 |
0, /*inplace_remainder*/ |
| 1582 |
0, /*inplace_power*/ |
| 1583 |
0, /*inplace_lshift*/ |
| 1584 |
0, /*inplace_rshift*/ |
| 1585 |
0, /*inplace_and*/ |
| 1586 |
0, /*inplace_xor*/ |
| 1587 |
0, /*inplace_or*/ |
| 1588 |
0, /*nb_floor_divide*/ |
| 1589 |
(binaryfunc)NoteinRead_div, /*nb_true_divide*/ |
| 1590 |
0, /*nb_inplace_floor_divide*/ |
| 1591 |
(binaryfunc)NoteinRead_inplace_div, /*nb_inplace_true_divide*/ |
| 1592 |
0, /* nb_index */ |
| 1593 |
}; |
| 1594 |
|
| 1595 |
PyTypeObject NoteinReadType = |
| 1596 |
{ |
| 1597 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 1598 |
"_pyo.NoteinRead_base", /*tp_name*/ |
| 1599 |
sizeof(NoteinRead), /*tp_basicsize*/ |
| 1600 |
0, /*tp_itemsize*/ |
| 1601 |
(destructor)NoteinRead_dealloc, /*tp_dealloc*/ |
| 1602 |
0, /*tp_print*/ |
| 1603 |
0, /*tp_getattr*/ |
| 1604 |
0, /*tp_setattr*/ |
| 1605 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 1606 |
0, /*tp_repr*/ |
| 1607 |
&NoteinRead_as_number, /*tp_as_number*/ |
| 1608 |
0, /*tp_as_sequence*/ |
| 1609 |
0, /*tp_as_mapping*/ |
| 1610 |
0, /*tp_hash */ |
| 1611 |
0, /*tp_call*/ |
| 1612 |
0, /*tp_str*/ |
| 1613 |
0, /*tp_getattro*/ |
| 1614 |
0, /*tp_setattro*/ |
| 1615 |
0, /*tp_as_buffer*/ |
| 1616 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 1617 |
"NoteinRead objects. Reads a NoteinRec file.", /* tp_doc */ |
| 1618 |
(traverseproc)NoteinRead_traverse, /* tp_traverse */ |
| 1619 |
(inquiry)NoteinRead_clear, /* tp_clear */ |
| 1620 |
0, /* tp_richcompare */ |
| 1621 |
0, /* tp_weaklistoffset */ |
| 1622 |
0, /* tp_iter */ |
| 1623 |
0, /* tp_iternext */ |
| 1624 |
NoteinRead_methods, /* tp_methods */ |
| 1625 |
NoteinRead_members, /* tp_members */ |
| 1626 |
0, /* tp_getset */ |
| 1627 |
0, /* tp_base */ |
| 1628 |
0, /* tp_dict */ |
| 1629 |
0, /* tp_descr_get */ |
| 1630 |
0, /* tp_descr_set */ |
| 1631 |
0, /* tp_dictoffset */ |
| 1632 |
0, /* tp_init */ |
| 1633 |
0, /* tp_alloc */ |
| 1634 |
NoteinRead_new, /* tp_new */ |
| 1635 |
}; |