| 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 <object.h> |
| 25 |
#include "structmember.h" |
| 26 |
#include "pyomodule.h" |
| 27 |
#include "streammodule.h" |
| 28 |
#include "servermodule.h" |
| 29 |
#include "dummymodule.h" |
| 30 |
#include "sndfile.h" |
| 31 |
#include "wind.h" |
| 32 |
#include "fft.h" |
| 33 |
#include <math.h> |
| 34 |
#include <time.h> |
| 35 |
|
| 36 |
#if !defined(_WIN32) && !defined(_WIN64) |
| 37 |
#include <fcntl.h> |
| 38 |
#include <sys/mman.h> |
| 39 |
#endif |
| 40 |
|
| 41 |
#include "tablemodule.h" |
| 42 |
|
| 43 |
/*************************/ |
| 44 |
/* TableStream structure */ |
| 45 |
/*************************/ |
| 46 |
static void |
| 47 |
TableStream_dealloc(TableStream* self) |
| 48 |
{ |
| 49 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 50 |
} |
| 51 |
|
| 52 |
static PyObject * |
| 53 |
TableStream_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 54 |
{ |
| 55 |
TableStream *self; |
| 56 |
MAKE_NEW_TABLESTREAM(self, type, NULL); |
| 57 |
return (PyObject *)self; |
| 58 |
} |
| 59 |
|
| 60 |
MYFLT * |
| 61 |
TableStream_getData(TableStream *self) |
| 62 |
{ |
| 63 |
return (MYFLT *)self->data; |
| 64 |
} |
| 65 |
|
| 66 |
void |
| 67 |
TableStream_setData(TableStream *self, MYFLT *data) |
| 68 |
{ |
| 69 |
self->data = data; |
| 70 |
} |
| 71 |
|
| 72 |
T_SIZE_T |
| 73 |
TableStream_getSize(TableStream *self) |
| 74 |
{ |
| 75 |
return self->size; |
| 76 |
} |
| 77 |
|
| 78 |
void |
| 79 |
TableStream_setSize(TableStream *self, T_SIZE_T size) |
| 80 |
{ |
| 81 |
self->size = size; |
| 82 |
} |
| 83 |
|
| 84 |
double |
| 85 |
TableStream_getSamplingRate(TableStream *self) |
| 86 |
{ |
| 87 |
return self->samplingRate; |
| 88 |
} |
| 89 |
|
| 90 |
void |
| 91 |
TableStream_setSamplingRate(TableStream *self, double sr) |
| 92 |
{ |
| 93 |
self->samplingRate = sr; |
| 94 |
} |
| 95 |
|
| 96 |
static int TableStream_getBuffer(PyObject *obj, Py_buffer *view, int flags) |
| 97 |
{ |
| 98 |
TableStream *self = (TableStream *)obj; |
| 99 |
TABLESTREAM_GET_BUFFER |
| 100 |
}; |
| 101 |
|
| 102 |
void TableStream_recordChunk(TableStream *self, MYFLT *data, T_SIZE_T datasize) |
| 103 |
{ |
| 104 |
int i; |
| 105 |
for (i = 0; i < datasize; i++) |
| 106 |
{ |
| 107 |
self->data[self->pointer] = data[i] + self->data[self->pointer] * self->feedback; |
| 108 |
self->pointer++; |
| 109 |
|
| 110 |
if (self->pointer == self->size) |
| 111 |
{ |
| 112 |
self->pointer = 0; |
| 113 |
self->data[self->size] = self->data[0]; |
| 114 |
} |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
void TableStream_resetRecordingPointer(TableStream *self) |
| 119 |
{ |
| 120 |
self->pointer = 0; |
| 121 |
} |
| 122 |
|
| 123 |
void TableStream_setFeedback(TableStream *self, MYFLT feedback) |
| 124 |
{ |
| 125 |
self->feedback = feedback; |
| 126 |
} |
| 127 |
|
| 128 |
MYFLT TableStream_getFeedback(TableStream *self) |
| 129 |
{ |
| 130 |
return self->feedback; |
| 131 |
} |
| 132 |
|
| 133 |
void TableStream_record(TableStream *self, int pos, MYFLT value) |
| 134 |
{ |
| 135 |
self->data[pos] = value; |
| 136 |
} |
| 137 |
|
| 138 |
static PyBufferProcs TableStream_as_buffer = |
| 139 |
{ |
| 140 |
(getbufferproc)TableStream_getBuffer, |
| 141 |
(releasebufferproc)NULL, |
| 142 |
}; |
| 143 |
|
| 144 |
PyTypeObject TableStreamType = |
| 145 |
{ |
| 146 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 147 |
"_pyo.TableStream", /*tp_name*/ |
| 148 |
sizeof(TableStream), /*tp_basicsize*/ |
| 149 |
0, /*tp_itemsize*/ |
| 150 |
(destructor)TableStream_dealloc, /*tp_dealloc*/ |
| 151 |
0, /*tp_print*/ |
| 152 |
0, /*tp_getattr*/ |
| 153 |
0, /*tp_setattr*/ |
| 154 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 155 |
0, /*tp_repr*/ |
| 156 |
0, /*tp_as_number*/ |
| 157 |
0, /*tp_as_sequence*/ |
| 158 |
0, /*tp_as_mapping*/ |
| 159 |
0, /*tp_hash */ |
| 160 |
0, /*tp_call*/ |
| 161 |
0, /*tp_str*/ |
| 162 |
0, /*tp_getattro*/ |
| 163 |
0, /*tp_setattro*/ |
| 164 |
&TableStream_as_buffer, /*tp_as_buffer*/ |
| 165 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ |
| 166 |
"TableStream objects. For internal use only. Must never be instantiated by the user.", /* tp_doc */ |
| 167 |
0, /* tp_traverse */ |
| 168 |
0, /* tp_clear */ |
| 169 |
0, /* tp_richcompare */ |
| 170 |
0, /* tp_weaklistoffset */ |
| 171 |
0, /* tp_iter */ |
| 172 |
0, /* tp_iternext */ |
| 173 |
0, /* tp_methods */ |
| 174 |
0, /* tp_members */ |
| 175 |
0, /* tp_getset */ |
| 176 |
0, /* tp_base */ |
| 177 |
0, /* tp_dict */ |
| 178 |
0, /* tp_descr_get */ |
| 179 |
0, /* tp_descr_set */ |
| 180 |
0, /* tp_dictoffset */ |
| 181 |
0, /* tp_init */ |
| 182 |
0, /* tp_alloc */ |
| 183 |
TableStream_new, /* tp_new */ |
| 184 |
}; |
| 185 |
|
| 186 |
/***********************/ |
| 187 |
/* HarmTable structure */ |
| 188 |
/***********************/ |
| 189 |
typedef struct |
| 190 |
{ |
| 191 |
pyo_table_HEAD |
| 192 |
PyObject *amplist; |
| 193 |
} HarmTable; |
| 194 |
|
| 195 |
static void |
| 196 |
HarmTable_generate(HarmTable *self) |
| 197 |
{ |
| 198 |
int j, ampsize; |
| 199 |
T_SIZE_T i; |
| 200 |
MYFLT factor, amplitude, val; |
| 201 |
|
| 202 |
ampsize = PyList_Size(self->amplist); |
| 203 |
MYFLT array[ampsize]; |
| 204 |
|
| 205 |
for (j = 0; j < ampsize; j++) |
| 206 |
{ |
| 207 |
array[j] = PyFloat_AsDouble(PyList_GET_ITEM(self->amplist, j)); |
| 208 |
} |
| 209 |
|
| 210 |
factor = 1. / (self->size * 0.5) * PI; |
| 211 |
|
| 212 |
for (i = 0; i < self->size; i++) |
| 213 |
{ |
| 214 |
val = 0; |
| 215 |
|
| 216 |
for (j = 0; j < ampsize; j++) |
| 217 |
{ |
| 218 |
amplitude = array[j]; |
| 219 |
|
| 220 |
if (amplitude != 0.0) |
| 221 |
{ |
| 222 |
val += MYSIN((j + 1) * i * factor) * amplitude; |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
self->data[i] = val; |
| 227 |
} |
| 228 |
|
| 229 |
val = self->data[0]; |
| 230 |
self->data[self->size] = val; |
| 231 |
} |
| 232 |
|
| 233 |
static int |
| 234 |
HarmTable_traverse(HarmTable *self, visitproc visit, void *arg) |
| 235 |
{ |
| 236 |
pyo_table_VISIT |
| 237 |
Py_VISIT(self->amplist); |
| 238 |
return 0; |
| 239 |
} |
| 240 |
|
| 241 |
static int |
| 242 |
HarmTable_clear(HarmTable *self) |
| 243 |
{ |
| 244 |
pyo_table_CLEAR |
| 245 |
Py_CLEAR(self->amplist); |
| 246 |
return 0; |
| 247 |
} |
| 248 |
|
| 249 |
static void |
| 250 |
HarmTable_dealloc(HarmTable* self) |
| 251 |
{ |
| 252 |
PyMem_RawFree(self->data); |
| 253 |
HarmTable_clear(self); |
| 254 |
Py_TYPE(self->tablestream)->tp_free((PyObject*)self->tablestream); |
| 255 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 256 |
} |
| 257 |
|
| 258 |
static PyObject * |
| 259 |
HarmTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 260 |
{ |
| 261 |
PyObject *amplist = NULL; |
| 262 |
HarmTable *self; |
| 263 |
self = (HarmTable *)type->tp_alloc(type, 0); |
| 264 |
|
| 265 |
self->server = PyServer_get_server(); |
| 266 |
Py_INCREF(self->server); |
| 267 |
|
| 268 |
self->amplist = PyList_New(0); |
| 269 |
PyObject *init = PyFloat_FromDouble(1.); |
| 270 |
PyList_Append(self->amplist, init); |
| 271 |
Py_DECREF(init); |
| 272 |
self->size = 8192; |
| 273 |
|
| 274 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 275 |
|
| 276 |
static char *kwlist[] = {"list", "size", NULL}; |
| 277 |
|
| 278 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|On", kwlist, &list, &self->size)) |
| 279 |
Py_RETURN_NONE; |
| 280 |
|
| 281 |
if (amplist) |
| 282 |
{ |
| 283 |
Py_INCREF(amplist); |
| 284 |
Py_DECREF(self->amplist); |
| 285 |
self->amplist = amplist; |
| 286 |
} |
| 287 |
|
| 288 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 289 |
TableStream_setSize(self->tablestream, self->size); |
| 290 |
TableStream_setData(self->tablestream, self->data); |
| 291 |
HarmTable_generate(self); |
| 292 |
|
| 293 |
PyObject *srobj = PyObject_CallMethod(self->server, "getSamplingRate", NULL); |
| 294 |
double sr = PyFloat_AsDouble(srobj); |
| 295 |
Py_DECREF(srobj); |
| 296 |
|
| 297 |
TableStream_setSamplingRate(self->tablestream, sr); |
| 298 |
|
| 299 |
return (PyObject *)self; |
| 300 |
} |
| 301 |
|
| 302 |
static PyObject * HarmTable_getServer(HarmTable* self) { GET_SERVER }; |
| 303 |
static PyObject * HarmTable_getTableStream(HarmTable* self) { GET_TABLE_STREAM }; |
| 304 |
static PyObject * HarmTable_setData(HarmTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 305 |
static PyObject * HarmTable_reset(HarmTable *self) { TABLE_RESET }; |
| 306 |
static PyObject * HarmTable_normalize(HarmTable *self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 307 |
static PyObject * HarmTable_removeDC(HarmTable *self) { REMOVE_DC }; |
| 308 |
static PyObject * HarmTable_reverse(HarmTable *self) { REVERSE }; |
| 309 |
static PyObject * HarmTable_invert(HarmTable *self) { INVERT }; |
| 310 |
static PyObject * HarmTable_rectify(HarmTable *self) { RECTIFY }; |
| 311 |
static PyObject * HarmTable_bipolarGain(HarmTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 312 |
static PyObject * HarmTable_lowpass(HarmTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 313 |
static PyObject * HarmTable_fadein(HarmTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 314 |
static PyObject * HarmTable_fadeout(HarmTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 315 |
static PyObject * HarmTable_pow(HarmTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 316 |
static PyObject * HarmTable_copy(HarmTable *self, PyObject *arg) { COPY }; |
| 317 |
static PyObject * HarmTable_copyData(HarmTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 318 |
static PyObject * HarmTable_rotate(HarmTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 319 |
static PyObject * HarmTable_setTable(HarmTable *self, PyObject *arg) { SET_TABLE }; |
| 320 |
static PyObject * HarmTable_getTable(HarmTable *self) { GET_TABLE }; |
| 321 |
static PyObject * HarmTable_getRate(HarmTable *self) { TABLE_GET_RATE }; |
| 322 |
static PyObject * HarmTable_getViewTable(HarmTable *self, PyObject *args, PyObject *kwds) { GET_VIEW_TABLE }; |
| 323 |
static PyObject * HarmTable_put(HarmTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 324 |
static PyObject * HarmTable_get(HarmTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 325 |
static PyObject * HarmTable_add(HarmTable *self, PyObject *arg) { TABLE_ADD }; |
| 326 |
static PyObject * HarmTable_sub(HarmTable *self, PyObject *arg) { TABLE_SUB }; |
| 327 |
static PyObject * HarmTable_mul(HarmTable *self, PyObject *arg) { TABLE_MUL }; |
| 328 |
static PyObject * HarmTable_div(HarmTable *self, PyObject *arg) { TABLE_DIV }; |
| 329 |
|
| 330 |
static PyObject * |
| 331 |
HarmTable_setSize(HarmTable *self, PyObject *value) |
| 332 |
{ |
| 333 |
TABLE_SET_SIZE |
| 334 |
|
| 335 |
HarmTable_generate(self); |
| 336 |
|
| 337 |
Py_RETURN_NONE; |
| 338 |
} |
| 339 |
|
| 340 |
static PyObject * |
| 341 |
HarmTable_getSize(HarmTable *self) |
| 342 |
{ |
| 343 |
return PyLong_FromLong(self->size); |
| 344 |
}; |
| 345 |
|
| 346 |
static PyObject * |
| 347 |
HarmTable_replace(HarmTable *self, PyObject *value) |
| 348 |
{ |
| 349 |
if (value == NULL) |
| 350 |
{ |
| 351 |
PyErr_SetString(PyExc_TypeError, "Cannot delete the list attribute."); |
| 352 |
return PyLong_FromLong(-1); |
| 353 |
} |
| 354 |
|
| 355 |
if (! PyList_Check(value)) |
| 356 |
{ |
| 357 |
PyErr_SetString(PyExc_TypeError, "The amplitude list attribute value must be a list."); |
| 358 |
return PyLong_FromLong(-1); |
| 359 |
} |
| 360 |
|
| 361 |
Py_INCREF(value); |
| 362 |
Py_DECREF(self->amplist); |
| 363 |
self->amplist = value; |
| 364 |
|
| 365 |
HarmTable_generate(self); |
| 366 |
|
| 367 |
Py_RETURN_NONE; |
| 368 |
} |
| 369 |
|
| 370 |
static PyMemberDef HarmTable_members[] = |
| 371 |
{ |
| 372 |
{"server", T_OBJECT_EX, offsetof(HarmTable, server), 0, "Pyo server."}, |
| 373 |
{"tablestream", T_OBJECT_EX, offsetof(HarmTable, tablestream), 0, "Table stream object."}, |
| 374 |
{"amplist", T_OBJECT_EX, offsetof(HarmTable, amplist), 0, "Harmonics amplitude values."}, |
| 375 |
{NULL} /* Sentinel */ |
| 376 |
}; |
| 377 |
|
| 378 |
static PyMethodDef HarmTable_methods[] = |
| 379 |
{ |
| 380 |
{"getServer", (PyCFunction)HarmTable_getServer, METH_NOARGS, "Returns server object."}, |
| 381 |
{"setTable", (PyCFunction)HarmTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 382 |
{"getTable", (PyCFunction)HarmTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 383 |
{"getViewTable", (PyCFunction)HarmTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 384 |
{"getTableStream", (PyCFunction)HarmTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 385 |
{"normalize", (PyCFunction)HarmTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table samples"}, |
| 386 |
{"reset", (PyCFunction)HarmTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 387 |
{"removeDC", (PyCFunction)HarmTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 388 |
{"reverse", (PyCFunction)HarmTable_reverse, METH_NOARGS, "Reverse the table's data in time."}, |
| 389 |
{"invert", (PyCFunction)HarmTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 390 |
{"rectify", (PyCFunction)HarmTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 391 |
{"bipolarGain", (PyCFunction)HarmTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 392 |
{"lowpass", (PyCFunction)HarmTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 393 |
{"fadein", (PyCFunction)HarmTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 394 |
{"fadeout", (PyCFunction)HarmTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 395 |
{"pow", (PyCFunction)HarmTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 396 |
{"copy", (PyCFunction)HarmTable_copy, METH_O, "Copy data from table given in argument."}, |
| 397 |
{"copyData", (PyCFunction)HarmTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 398 |
{"rotate", (PyCFunction)HarmTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 399 |
{"setData", (PyCFunction)HarmTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 400 |
{"setSize", (PyCFunction)HarmTable_setSize, METH_O, "Sets the size of the table in samples"}, |
| 401 |
{"getSize", (PyCFunction)HarmTable_getSize, METH_NOARGS, "Return the size of the table in samples"}, |
| 402 |
{"getRate", (PyCFunction)HarmTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the table without pitch transposition."}, |
| 403 |
{"put", (PyCFunction)HarmTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 404 |
{"get", (PyCFunction)HarmTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 405 |
{"replace", (PyCFunction)HarmTable_replace, METH_O, "Sets the harmonics amplitude list and generates a new waveform table."}, |
| 406 |
{"add", (PyCFunction)HarmTable_add, METH_O, "Performs table addition."}, |
| 407 |
{"sub", (PyCFunction)HarmTable_sub, METH_O, "Performs table substraction."}, |
| 408 |
{"mul", (PyCFunction)HarmTable_mul, METH_O, "Performs table multiplication."}, |
| 409 |
{"div", (PyCFunction)HarmTable_div, METH_O, "Performs table division."}, |
| 410 |
{NULL} /* Sentinel */ |
| 411 |
}; |
| 412 |
|
| 413 |
PyTypeObject HarmTableType = |
| 414 |
{ |
| 415 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 416 |
"_pyo.HarmTable_base", /*tp_name*/ |
| 417 |
sizeof(HarmTable), /*tp_basicsize*/ |
| 418 |
0, /*tp_itemsize*/ |
| 419 |
(destructor)HarmTable_dealloc, /*tp_dealloc*/ |
| 420 |
0, /*tp_print*/ |
| 421 |
0, /*tp_getattr*/ |
| 422 |
0, /*tp_setattr*/ |
| 423 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 424 |
0, /*tp_repr*/ |
| 425 |
0, /*tp_as_number*/ |
| 426 |
0, /*tp_as_sequence*/ |
| 427 |
0, /*tp_as_mapping*/ |
| 428 |
0, /*tp_hash */ |
| 429 |
0, /*tp_call*/ |
| 430 |
0, /*tp_str*/ |
| 431 |
0, /*tp_getattro*/ |
| 432 |
0, /*tp_setattro*/ |
| 433 |
0, /*tp_as_buffer*/ |
| 434 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 435 |
"HarmTable objects. Generates a table filled with a waveform whose harmonic content correspond to a given amplitude list values.", /* tp_doc */ |
| 436 |
(traverseproc)HarmTable_traverse, /* tp_traverse */ |
| 437 |
(inquiry)HarmTable_clear, /* tp_clear */ |
| 438 |
0, /* tp_richcompare */ |
| 439 |
0, /* tp_weaklistoffset */ |
| 440 |
0, /* tp_iter */ |
| 441 |
0, /* tp_iternext */ |
| 442 |
HarmTable_methods, /* tp_methods */ |
| 443 |
HarmTable_members, /* tp_members */ |
| 444 |
0, /* tp_getset */ |
| 445 |
0, /* tp_base */ |
| 446 |
0, /* tp_dict */ |
| 447 |
0, /* tp_descr_get */ |
| 448 |
0, /* tp_descr_set */ |
| 449 |
0, /* tp_dictoffset */ |
| 450 |
0, /* tp_init */ |
| 451 |
0, /* tp_alloc */ |
| 452 |
HarmTable_new, /* tp_new */ |
| 453 |
}; |
| 454 |
|
| 455 |
/***********************/ |
| 456 |
/* ChebyTable structure */ |
| 457 |
/***********************/ |
| 458 |
typedef struct |
| 459 |
{ |
| 460 |
pyo_table_HEAD |
| 461 |
PyObject *amplist; |
| 462 |
} ChebyTable; |
| 463 |
|
| 464 |
static void |
| 465 |
ChebyTable_generate(ChebyTable *self) |
| 466 |
{ |
| 467 |
int j, ampsize, halfsize; |
| 468 |
T_SIZE_T i; |
| 469 |
MYFLT amplitude, val, ihalfsize, index, x; |
| 470 |
|
| 471 |
ampsize = PyList_Size(self->amplist); |
| 472 |
|
| 473 |
if (ampsize > 12) |
| 474 |
ampsize = 12; |
| 475 |
|
| 476 |
MYFLT array[ampsize]; |
| 477 |
|
| 478 |
for (j = 0; j < ampsize; j++) |
| 479 |
{ |
| 480 |
array[j] = PyFloat_AsDouble(PyList_GET_ITEM(self->amplist, j)); |
| 481 |
} |
| 482 |
|
| 483 |
halfsize = self->size / 2; |
| 484 |
ihalfsize = 1.0 / halfsize; |
| 485 |
|
| 486 |
x = 0.0; |
| 487 |
|
| 488 |
for (i = 0; i < self->size; i++) |
| 489 |
{ |
| 490 |
val = 0; |
| 491 |
index = (i - halfsize) * ihalfsize; |
| 492 |
|
| 493 |
for (j = 0; j < ampsize; j++) |
| 494 |
{ |
| 495 |
amplitude = array[j]; |
| 496 |
|
| 497 |
switch (j) |
| 498 |
{ |
| 499 |
case 0: |
| 500 |
x = index; |
| 501 |
break; |
| 502 |
|
| 503 |
case 1: |
| 504 |
x = 2 * MYPOW(index, 2) - 1; |
| 505 |
break; |
| 506 |
|
| 507 |
case 2: |
| 508 |
x = 4 * MYPOW(index, 3) - 3 * index; |
| 509 |
break; |
| 510 |
|
| 511 |
case 3: |
| 512 |
x = 8 * MYPOW(index, 4) - 8 * MYPOW(index, 2) + 1; |
| 513 |
break; |
| 514 |
|
| 515 |
case 4: |
| 516 |
x = 16 * MYPOW(index, 5) - 20 * MYPOW(index, 3) + 5 * index; |
| 517 |
break; |
| 518 |
|
| 519 |
case 5: |
| 520 |
x = 32 * MYPOW(index, 6) - 48 * MYPOW(index, 4) + 18 * MYPOW(index, 2) - 1; |
| 521 |
break; |
| 522 |
|
| 523 |
case 6: |
| 524 |
x = 64 * MYPOW(index, 7) - 112 * MYPOW(index, 5) + 56 * MYPOW(index, 3) - 7 * index; |
| 525 |
break; |
| 526 |
|
| 527 |
case 7: |
| 528 |
x = 128 * MYPOW(index, 8) - 256 * MYPOW(index, 6) + 160 * MYPOW(index, 4) - 32 * MYPOW(index, 2) + 1; |
| 529 |
break; |
| 530 |
|
| 531 |
case 8: |
| 532 |
x = 256 * MYPOW(index, 9) - 576 * MYPOW(index, 7) + 432 * MYPOW(index, 5) - 120 * MYPOW(index, 3) + 9 * index; |
| 533 |
break; |
| 534 |
|
| 535 |
case 9: |
| 536 |
x = 512 * MYPOW(index, 10) - 1280 * MYPOW(index, 8) + 1120 * MYPOW(index, 6) - 400 * MYPOW(index, 4) + 50 * MYPOW(index, 2) - 1; |
| 537 |
break; |
| 538 |
|
| 539 |
case 10: |
| 540 |
x = 1024 * MYPOW(index, 11) - 2816 * MYPOW(index, 9) + 2816 * MYPOW(index, 7) - 1232 * MYPOW(index, 5) + 220 * MYPOW(index, 3) - 11 * index; |
| 541 |
break; |
| 542 |
|
| 543 |
case 11: |
| 544 |
x = 2048 * MYPOW(index, 12) - 6144 * MYPOW(index, 10) + 6912 * MYPOW(index, 8) - 3584 * MYPOW(index, 6) + 840 * MYPOW(index, 4) - 72 * MYPOW(index, 2) + 1; |
| 545 |
break; |
| 546 |
} |
| 547 |
|
| 548 |
val += x * amplitude; |
| 549 |
} |
| 550 |
|
| 551 |
self->data[i] = val; |
| 552 |
} |
| 553 |
|
| 554 |
val = self->data[self->size - 1]; |
| 555 |
self->data[self->size] = val; |
| 556 |
} |
| 557 |
|
| 558 |
static int |
| 559 |
ChebyTable_traverse(ChebyTable *self, visitproc visit, void *arg) |
| 560 |
{ |
| 561 |
pyo_table_VISIT |
| 562 |
Py_VISIT(self->amplist); |
| 563 |
return 0; |
| 564 |
} |
| 565 |
|
| 566 |
static int |
| 567 |
ChebyTable_clear(ChebyTable *self) |
| 568 |
{ |
| 569 |
pyo_table_CLEAR |
| 570 |
Py_CLEAR(self->amplist); |
| 571 |
return 0; |
| 572 |
} |
| 573 |
|
| 574 |
static void |
| 575 |
ChebyTable_dealloc(ChebyTable* self) |
| 576 |
{ |
| 577 |
PyMem_RawFree(self->data); |
| 578 |
ChebyTable_clear(self); |
| 579 |
Py_TYPE(self->tablestream)->tp_free((PyObject*)self->tablestream); |
| 580 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 581 |
} |
| 582 |
|
| 583 |
static PyObject * |
| 584 |
ChebyTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 585 |
{ |
| 586 |
PyObject *amplist = NULL; |
| 587 |
ChebyTable *self; |
| 588 |
self = (ChebyTable *)type->tp_alloc(type, 0); |
| 589 |
|
| 590 |
self->server = PyServer_get_server(); |
| 591 |
Py_INCREF(self->server); |
| 592 |
|
| 593 |
self->amplist = PyList_New(0); |
| 594 |
PyObject *init = PyFloat_FromDouble(1.); |
| 595 |
PyList_Append(self->amplist, init); |
| 596 |
Py_DECREF(init); |
| 597 |
self->size = 8192; |
| 598 |
|
| 599 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 600 |
|
| 601 |
static char *kwlist[] = {"list", "size", NULL}; |
| 602 |
|
| 603 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|On", kwlist, &list, &self->size)) |
| 604 |
Py_RETURN_NONE; |
| 605 |
|
| 606 |
if (amplist) |
| 607 |
{ |
| 608 |
Py_INCREF(amplist); |
| 609 |
Py_DECREF(self->amplist); |
| 610 |
self->amplist = amplist; |
| 611 |
} |
| 612 |
|
| 613 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 614 |
TableStream_setSize(self->tablestream, self->size); |
| 615 |
TableStream_setData(self->tablestream, self->data); |
| 616 |
ChebyTable_generate(self); |
| 617 |
|
| 618 |
PyObject *srobj = PyObject_CallMethod(self->server, "getSamplingRate", NULL); |
| 619 |
double sr = PyFloat_AsDouble(srobj); |
| 620 |
Py_DECREF(srobj); |
| 621 |
|
| 622 |
TableStream_setSamplingRate(self->tablestream, sr); |
| 623 |
|
| 624 |
return (PyObject *)self; |
| 625 |
} |
| 626 |
|
| 627 |
static PyObject * ChebyTable_getServer(ChebyTable* self) { GET_SERVER }; |
| 628 |
static PyObject * ChebyTable_getTableStream(ChebyTable* self) { GET_TABLE_STREAM }; |
| 629 |
static PyObject * ChebyTable_setData(ChebyTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 630 |
static PyObject * ChebyTable_normalize(ChebyTable *self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 631 |
static PyObject * ChebyTable_reset(ChebyTable *self) { TABLE_RESET }; |
| 632 |
static PyObject * ChebyTable_removeDC(ChebyTable *self) { REMOVE_DC }; |
| 633 |
static PyObject * ChebyTable_reverse(ChebyTable *self) { REVERSE }; |
| 634 |
static PyObject * ChebyTable_invert(ChebyTable *self) { INVERT }; |
| 635 |
static PyObject * ChebyTable_rectify(ChebyTable *self) { RECTIFY }; |
| 636 |
static PyObject * ChebyTable_bipolarGain(ChebyTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 637 |
static PyObject * ChebyTable_lowpass(ChebyTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 638 |
static PyObject * ChebyTable_fadein(ChebyTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 639 |
static PyObject * ChebyTable_fadeout(ChebyTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 640 |
static PyObject * ChebyTable_pow(ChebyTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 641 |
static PyObject * ChebyTable_copy(ChebyTable *self, PyObject *arg) { COPY }; |
| 642 |
static PyObject * ChebyTable_copyData(ChebyTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 643 |
static PyObject * ChebyTable_rotate(ChebyTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 644 |
static PyObject * ChebyTable_setTable(ChebyTable *self, PyObject *arg) { SET_TABLE }; |
| 645 |
static PyObject * ChebyTable_getTable(ChebyTable *self) { GET_TABLE }; |
| 646 |
static PyObject * ChebyTable_getRate(ChebyTable *self) { TABLE_GET_RATE }; |
| 647 |
static PyObject * ChebyTable_getViewTable(ChebyTable *self, PyObject *args, PyObject *kwds) { GET_VIEW_TABLE }; |
| 648 |
static PyObject * ChebyTable_put(ChebyTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 649 |
static PyObject * ChebyTable_get(ChebyTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 650 |
static PyObject * ChebyTable_add(ChebyTable *self, PyObject *arg) { TABLE_ADD }; |
| 651 |
static PyObject * ChebyTable_sub(ChebyTable *self, PyObject *arg) { TABLE_SUB }; |
| 652 |
static PyObject * ChebyTable_mul(ChebyTable *self, PyObject *arg) { TABLE_MUL }; |
| 653 |
static PyObject * ChebyTable_div(ChebyTable *self, PyObject *arg) { TABLE_DIV }; |
| 654 |
|
| 655 |
static PyObject * |
| 656 |
ChebyTable_setSize(ChebyTable *self, PyObject *value) |
| 657 |
{ |
| 658 |
TABLE_SET_SIZE |
| 659 |
|
| 660 |
ChebyTable_generate(self); |
| 661 |
|
| 662 |
Py_RETURN_NONE; |
| 663 |
} |
| 664 |
|
| 665 |
static PyObject * |
| 666 |
ChebyTable_getSize(ChebyTable *self) |
| 667 |
{ |
| 668 |
return PyLong_FromLong(self->size); |
| 669 |
}; |
| 670 |
|
| 671 |
static PyObject * |
| 672 |
ChebyTable_replace(ChebyTable *self, PyObject *value) |
| 673 |
{ |
| 674 |
if (value == NULL) |
| 675 |
{ |
| 676 |
PyErr_SetString(PyExc_TypeError, "Cannot delete the list attribute."); |
| 677 |
return PyLong_FromLong(-1); |
| 678 |
} |
| 679 |
|
| 680 |
if (! PyList_Check(value)) |
| 681 |
{ |
| 682 |
PyErr_SetString(PyExc_TypeError, "The amplitude list attribute value must be a list."); |
| 683 |
return PyLong_FromLong(-1); |
| 684 |
} |
| 685 |
|
| 686 |
Py_INCREF(value); |
| 687 |
Py_DECREF(self->amplist); |
| 688 |
self->amplist = value; |
| 689 |
|
| 690 |
ChebyTable_generate(self); |
| 691 |
|
| 692 |
Py_RETURN_NONE; |
| 693 |
} |
| 694 |
|
| 695 |
static PyObject * |
| 696 |
ChebyTable_getNormTable(ChebyTable *self, PyObject *value) |
| 697 |
{ |
| 698 |
T_SIZE_T i, halfsize = self->size / 2; |
| 699 |
MYFLT maxval = 0.0; |
| 700 |
MYFLT val = 0.0, val2 = 0.0; |
| 701 |
MYFLT last = 0.0; |
| 702 |
long sym = PyLong_AsLong(value); |
| 703 |
MYFLT samps[halfsize]; // FIXME: Very large table would cause stack overflow. |
| 704 |
PyObject *samples = PyList_New(halfsize); |
| 705 |
|
| 706 |
if (sym == 0) |
| 707 |
{ |
| 708 |
for (i = 0; i < self->size; i++) |
| 709 |
{ |
| 710 |
if (self->data[i] > maxval) |
| 711 |
maxval = self->data[i]; |
| 712 |
} |
| 713 |
|
| 714 |
if (maxval > 1.0) |
| 715 |
{ |
| 716 |
for (i = 0; i < self->size; i++) |
| 717 |
{ |
| 718 |
self->data[i] /= maxval; |
| 719 |
} |
| 720 |
} |
| 721 |
|
| 722 |
maxval = -1; |
| 723 |
|
| 724 |
for (i = 0; i < halfsize; i++) |
| 725 |
{ |
| 726 |
val = MYFABS(self->data[halfsize + i]); |
| 727 |
|
| 728 |
if (val > maxval) |
| 729 |
maxval = val; |
| 730 |
|
| 731 |
if (maxval > 0.0) |
| 732 |
samps[i] = 1. - maxval; |
| 733 |
else |
| 734 |
samps[i] = -1.; |
| 735 |
} |
| 736 |
} |
| 737 |
else |
| 738 |
{ |
| 739 |
maxval = -1; |
| 740 |
|
| 741 |
for (i = 0; i < halfsize; i++) |
| 742 |
{ |
| 743 |
val = MYFABS(self->data[halfsize - i]); |
| 744 |
val2 = MYFABS(self->data[halfsize + i]); |
| 745 |
|
| 746 |
if (val2 > val) |
| 747 |
val = val2; |
| 748 |
|
| 749 |
if (val > maxval) |
| 750 |
maxval = val; |
| 751 |
|
| 752 |
if (maxval > 0.0) |
| 753 |
samps[i] = 1. / maxval; |
| 754 |
else |
| 755 |
samps[i] = -1.; |
| 756 |
} |
| 757 |
} |
| 758 |
|
| 759 |
maxval = 0.0; |
| 760 |
|
| 761 |
for (i = 0; i < halfsize; i++) |
| 762 |
{ |
| 763 |
val = samps[i]; |
| 764 |
|
| 765 |
if (val > maxval) |
| 766 |
maxval = val; |
| 767 |
} |
| 768 |
|
| 769 |
for (i = 0; i < halfsize; i++) |
| 770 |
{ |
| 771 |
val = samps[i]; |
| 772 |
|
| 773 |
if (val == -1.0) |
| 774 |
samps[i] = maxval; |
| 775 |
} |
| 776 |
|
| 777 |
last = samps[0]; |
| 778 |
|
| 779 |
for (i = 1; i < halfsize; i++) |
| 780 |
{ |
| 781 |
last = samps[i] = samps[i] + (last - samps[i]) * 0.95; |
| 782 |
} |
| 783 |
|
| 784 |
for (i = 0; i < halfsize; i++) |
| 785 |
{ |
| 786 |
PyList_SET_ITEM(samples, i, PyFloat_FromDouble(samps[i])); |
| 787 |
} |
| 788 |
|
| 789 |
return samples; |
| 790 |
} |
| 791 |
|
| 792 |
static PyMemberDef ChebyTable_members[] = |
| 793 |
{ |
| 794 |
{"server", T_OBJECT_EX, offsetof(ChebyTable, server), 0, "Pyo server."}, |
| 795 |
{"tablestream", T_OBJECT_EX, offsetof(ChebyTable, tablestream), 0, "Table stream object."}, |
| 796 |
{"amplist", T_OBJECT_EX, offsetof(ChebyTable, amplist), 0, "Harmonics amplitude values."}, |
| 797 |
{NULL} /* Sentinel */ |
| 798 |
}; |
| 799 |
|
| 800 |
static PyMethodDef ChebyTable_methods[] = |
| 801 |
{ |
| 802 |
{"getServer", (PyCFunction)ChebyTable_getServer, METH_NOARGS, "Returns server object."}, |
| 803 |
{"copy", (PyCFunction)ChebyTable_copy, METH_O, "Copy data from table given in argument."}, |
| 804 |
{"copyData", (PyCFunction)ChebyTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 805 |
{"rotate", (PyCFunction)ChebyTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 806 |
{"setTable", (PyCFunction)ChebyTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 807 |
{"getTable", (PyCFunction)ChebyTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 808 |
{"getViewTable", (PyCFunction)ChebyTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 809 |
{"getTableStream", (PyCFunction)ChebyTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 810 |
{"setData", (PyCFunction)ChebyTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 811 |
{"normalize", (PyCFunction)ChebyTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table samples"}, |
| 812 |
{"reset", (PyCFunction)ChebyTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 813 |
{"removeDC", (PyCFunction)ChebyTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 814 |
{"reverse", (PyCFunction)ChebyTable_reverse, METH_NOARGS, "Reverse the table's data."}, |
| 815 |
{"invert", (PyCFunction)ChebyTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 816 |
{"rectify", (PyCFunction)ChebyTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 817 |
{"bipolarGain", (PyCFunction)ChebyTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 818 |
{"lowpass", (PyCFunction)ChebyTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 819 |
{"fadein", (PyCFunction)ChebyTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 820 |
{"fadeout", (PyCFunction)ChebyTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 821 |
{"pow", (PyCFunction)ChebyTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 822 |
{"setSize", (PyCFunction)ChebyTable_setSize, METH_O, "Sets the size of the table in samples"}, |
| 823 |
{"getSize", (PyCFunction)ChebyTable_getSize, METH_NOARGS, "Return the size of the table in samples"}, |
| 824 |
{"getRate", (PyCFunction)ChebyTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the table without pitch transposition."}, |
| 825 |
{"put", (PyCFunction)ChebyTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 826 |
{"get", (PyCFunction)ChebyTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 827 |
{"replace", (PyCFunction)ChebyTable_replace, METH_O, "Sets the harmonics amplitude list and generates a new waveform table."}, |
| 828 |
{"getNormTable", (PyCFunction)ChebyTable_getNormTable, METH_O, "Computes and returns the normalization function for the current polynomial"}, |
| 829 |
{"add", (PyCFunction)ChebyTable_add, METH_O, "Performs table addition."}, |
| 830 |
{"sub", (PyCFunction)ChebyTable_sub, METH_O, "Performs table substraction."}, |
| 831 |
{"mul", (PyCFunction)ChebyTable_mul, METH_O, "Performs table multiplication."}, |
| 832 |
{"div", (PyCFunction)ChebyTable_div, METH_O, "Performs table division."}, |
| 833 |
{NULL} /* Sentinel */ |
| 834 |
}; |
| 835 |
|
| 836 |
PyTypeObject ChebyTableType = |
| 837 |
{ |
| 838 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 839 |
"_pyo.ChebyTable_base", /*tp_name*/ |
| 840 |
sizeof(ChebyTable), /*tp_basicsize*/ |
| 841 |
0, /*tp_itemsize*/ |
| 842 |
(destructor)ChebyTable_dealloc, /*tp_dealloc*/ |
| 843 |
0, /*tp_print*/ |
| 844 |
0, /*tp_getattr*/ |
| 845 |
0, /*tp_setattr*/ |
| 846 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 847 |
0, /*tp_repr*/ |
| 848 |
0, /*tp_as_number*/ |
| 849 |
0, /*tp_as_sequence*/ |
| 850 |
0, /*tp_as_mapping*/ |
| 851 |
0, /*tp_hash */ |
| 852 |
0, /*tp_call*/ |
| 853 |
0, /*tp_str*/ |
| 854 |
0, /*tp_getattro*/ |
| 855 |
0, /*tp_setattro*/ |
| 856 |
0, /*tp_as_buffer*/ |
| 857 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 858 |
"ChebyTable objects. Generates a table filled with a waveform whose harmonic content correspond to a given amplitude list values.", /* tp_doc */ |
| 859 |
(traverseproc)ChebyTable_traverse, /* tp_traverse */ |
| 860 |
(inquiry)ChebyTable_clear, /* tp_clear */ |
| 861 |
0, /* tp_richcompare */ |
| 862 |
0, /* tp_weaklistoffset */ |
| 863 |
0, /* tp_iter */ |
| 864 |
0, /* tp_iternext */ |
| 865 |
ChebyTable_methods, /* tp_methods */ |
| 866 |
ChebyTable_members, /* tp_members */ |
| 867 |
0, /* tp_getset */ |
| 868 |
0, /* tp_base */ |
| 869 |
0, /* tp_dict */ |
| 870 |
0, /* tp_descr_get */ |
| 871 |
0, /* tp_descr_set */ |
| 872 |
0, /* tp_dictoffset */ |
| 873 |
0, /* tp_init */ |
| 874 |
0, /* tp_alloc */ |
| 875 |
ChebyTable_new, /* tp_new */ |
| 876 |
}; |
| 877 |
|
| 878 |
/***********************/ |
| 879 |
/* HannTable structure */ |
| 880 |
/***********************/ |
| 881 |
typedef struct |
| 882 |
{ |
| 883 |
pyo_table_HEAD |
| 884 |
} HannTable; |
| 885 |
|
| 886 |
static void |
| 887 |
HannTable_generate(HannTable *self) |
| 888 |
{ |
| 889 |
T_SIZE_T i, halfSize; |
| 890 |
MYFLT val; |
| 891 |
|
| 892 |
halfSize = self->size / 2 - 1; |
| 893 |
|
| 894 |
for (i = 0; i < self->size; i++) |
| 895 |
{ |
| 896 |
val = 0.5 + (MYCOS(TWOPI * (i - halfSize) / self->size) * 0.5); |
| 897 |
self->data[i] = val; |
| 898 |
} |
| 899 |
|
| 900 |
val = self->data[0]; |
| 901 |
self->data[self->size] = val; |
| 902 |
} |
| 903 |
|
| 904 |
static int |
| 905 |
HannTable_traverse(HannTable *self, visitproc visit, void *arg) |
| 906 |
{ |
| 907 |
pyo_table_VISIT |
| 908 |
return 0; |
| 909 |
} |
| 910 |
|
| 911 |
static int |
| 912 |
HannTable_clear(HannTable *self) |
| 913 |
{ |
| 914 |
pyo_table_CLEAR |
| 915 |
return 0; |
| 916 |
} |
| 917 |
|
| 918 |
static void |
| 919 |
HannTable_dealloc(HannTable* self) |
| 920 |
{ |
| 921 |
PyMem_RawFree(self->data); |
| 922 |
HannTable_clear(self); |
| 923 |
Py_TYPE(self->tablestream)->tp_free((PyObject*)self->tablestream); |
| 924 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 925 |
} |
| 926 |
|
| 927 |
static PyObject * |
| 928 |
HannTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 929 |
{ |
| 930 |
HannTable *self; |
| 931 |
self = (HannTable *)type->tp_alloc(type, 0); |
| 932 |
|
| 933 |
self->server = PyServer_get_server(); |
| 934 |
Py_INCREF(self->server); |
| 935 |
|
| 936 |
self->size = 8192; |
| 937 |
|
| 938 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 939 |
|
| 940 |
static char *kwlist[] = {"size", NULL}; |
| 941 |
|
| 942 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|n", kwlist, &self->size)) |
| 943 |
Py_RETURN_NONE; |
| 944 |
|
| 945 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 946 |
TableStream_setSize(self->tablestream, self->size); |
| 947 |
TableStream_setData(self->tablestream, self->data); |
| 948 |
HannTable_generate(self); |
| 949 |
|
| 950 |
PyObject *srobj = PyObject_CallMethod(self->server, "getSamplingRate", NULL); |
| 951 |
double sr = PyFloat_AsDouble(srobj); |
| 952 |
Py_DECREF(srobj); |
| 953 |
|
| 954 |
TableStream_setSamplingRate(self->tablestream, sr); |
| 955 |
|
| 956 |
return (PyObject *)self; |
| 957 |
} |
| 958 |
|
| 959 |
static PyObject * HannTable_getServer(HannTable* self) { GET_SERVER }; |
| 960 |
static PyObject * HannTable_getTableStream(HannTable* self) { GET_TABLE_STREAM }; |
| 961 |
static PyObject * HannTable_setData(HannTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 962 |
static PyObject * HannTable_normalize(HannTable *self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 963 |
static PyObject * HannTable_reset(HannTable *self) { TABLE_RESET }; |
| 964 |
static PyObject * HannTable_removeDC(HannTable *self) { REMOVE_DC }; |
| 965 |
static PyObject * HannTable_reverse(HannTable *self) { REVERSE }; |
| 966 |
static PyObject * HannTable_invert(HannTable *self) { INVERT }; |
| 967 |
static PyObject * HannTable_rectify(HannTable *self) { RECTIFY }; |
| 968 |
static PyObject * HannTable_bipolarGain(HannTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 969 |
static PyObject * HannTable_lowpass(HannTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 970 |
static PyObject * HannTable_fadein(HannTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 971 |
static PyObject * HannTable_fadeout(HannTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 972 |
static PyObject * HannTable_pow(HannTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 973 |
static PyObject * HannTable_copy(HannTable *self, PyObject *arg) { COPY }; |
| 974 |
static PyObject * HannTable_copyData(HannTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 975 |
static PyObject * HannTable_rotate(HannTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 976 |
static PyObject * HannTable_setTable(HannTable *self, PyObject *arg) { SET_TABLE }; |
| 977 |
static PyObject * HannTable_getTable(HannTable *self) { GET_TABLE }; |
| 978 |
static PyObject * HannTable_getRate(HannTable *self) { TABLE_GET_RATE }; |
| 979 |
static PyObject * HannTable_getViewTable(HannTable *self, PyObject *args, PyObject *kwds) { GET_VIEW_TABLE }; |
| 980 |
static PyObject * HannTable_put(HannTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 981 |
static PyObject * HannTable_get(HannTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 982 |
static PyObject * HannTable_add(HannTable *self, PyObject *arg) { TABLE_ADD }; |
| 983 |
static PyObject * HannTable_sub(HannTable *self, PyObject *arg) { TABLE_SUB }; |
| 984 |
static PyObject * HannTable_mul(HannTable *self, PyObject *arg) { TABLE_MUL }; |
| 985 |
static PyObject * HannTable_div(HannTable *self, PyObject *arg) { TABLE_DIV }; |
| 986 |
|
| 987 |
static PyObject * |
| 988 |
HannTable_setSize(HannTable *self, PyObject *value) |
| 989 |
{ |
| 990 |
TABLE_SET_SIZE |
| 991 |
|
| 992 |
HannTable_generate(self); |
| 993 |
|
| 994 |
Py_RETURN_NONE; |
| 995 |
} |
| 996 |
|
| 997 |
static PyObject * |
| 998 |
HannTable_getSize(HannTable *self) |
| 999 |
{ |
| 1000 |
return PyLong_FromLong(self->size); |
| 1001 |
}; |
| 1002 |
|
| 1003 |
static PyMemberDef HannTable_members[] = |
| 1004 |
{ |
| 1005 |
{"server", T_OBJECT_EX, offsetof(HannTable, server), 0, "Pyo server."}, |
| 1006 |
{"tablestream", T_OBJECT_EX, offsetof(HannTable, tablestream), 0, "Table stream object."}, |
| 1007 |
{NULL} /* Sentinel */ |
| 1008 |
}; |
| 1009 |
|
| 1010 |
static PyMethodDef HannTable_methods[] = |
| 1011 |
{ |
| 1012 |
{"getServer", (PyCFunction)HannTable_getServer, METH_NOARGS, "Returns server object."}, |
| 1013 |
{"copy", (PyCFunction)HannTable_copy, METH_O, "Copy data from table given in argument."}, |
| 1014 |
{"copyData", (PyCFunction)HannTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 1015 |
{"rotate", (PyCFunction)HannTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 1016 |
{"setTable", (PyCFunction)HannTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 1017 |
{"getTable", (PyCFunction)HannTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 1018 |
{"getViewTable", (PyCFunction)HannTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 1019 |
{"getTableStream", (PyCFunction)HannTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 1020 |
{"setData", (PyCFunction)HannTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 1021 |
{"normalize", (PyCFunction)HannTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table samples"}, |
| 1022 |
{"reset", (PyCFunction)HannTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 1023 |
{"removeDC", (PyCFunction)HannTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 1024 |
{"reverse", (PyCFunction)HannTable_reverse, METH_NOARGS, "Reverse the table's data."}, |
| 1025 |
{"invert", (PyCFunction)HannTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 1026 |
{"rectify", (PyCFunction)HannTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 1027 |
{"bipolarGain", (PyCFunction)HannTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 1028 |
{"lowpass", (PyCFunction)HannTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 1029 |
{"fadein", (PyCFunction)HannTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 1030 |
{"fadeout", (PyCFunction)HannTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 1031 |
{"pow", (PyCFunction)HannTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 1032 |
{"setSize", (PyCFunction)HannTable_setSize, METH_O, "Sets the size of the table in samples"}, |
| 1033 |
{"getSize", (PyCFunction)HannTable_getSize, METH_NOARGS, "Return the size of the table in samples"}, |
| 1034 |
{"getRate", (PyCFunction)HannTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the table without pitch transposition."}, |
| 1035 |
{"put", (PyCFunction)HannTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 1036 |
{"get", (PyCFunction)HannTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 1037 |
{"add", (PyCFunction)HannTable_add, METH_O, "Performs table addition."}, |
| 1038 |
{"sub", (PyCFunction)HannTable_sub, METH_O, "Performs table substraction."}, |
| 1039 |
{"mul", (PyCFunction)HannTable_mul, METH_O, "Performs table multiplication."}, |
| 1040 |
{"div", (PyCFunction)HannTable_div, METH_O, "Performs table division."}, |
| 1041 |
{NULL} /* Sentinel */ |
| 1042 |
}; |
| 1043 |
|
| 1044 |
PyTypeObject HannTableType = |
| 1045 |
{ |
| 1046 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 1047 |
"_pyo.HannTable_base", /*tp_name*/ |
| 1048 |
sizeof(HannTable), /*tp_basicsize*/ |
| 1049 |
0, /*tp_itemsize*/ |
| 1050 |
(destructor)HannTable_dealloc, /*tp_dealloc*/ |
| 1051 |
0, /*tp_print*/ |
| 1052 |
0, /*tp_getattr*/ |
| 1053 |
0, /*tp_setattr*/ |
| 1054 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 1055 |
0, /*tp_repr*/ |
| 1056 |
0, /*tp_as_number*/ |
| 1057 |
0, /*tp_as_sequence*/ |
| 1058 |
0, /*tp_as_mapping*/ |
| 1059 |
0, /*tp_hash */ |
| 1060 |
0, /*tp_call*/ |
| 1061 |
0, /*tp_str*/ |
| 1062 |
0, /*tp_getattro*/ |
| 1063 |
0, /*tp_setattro*/ |
| 1064 |
0, /*tp_as_buffer*/ |
| 1065 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 1066 |
"HannTable objects. Generates a table filled with a hanning function.", /* tp_doc */ |
| 1067 |
(traverseproc)HannTable_traverse, /* tp_traverse */ |
| 1068 |
(inquiry)HannTable_clear, /* tp_clear */ |
| 1069 |
0, /* tp_richcompare */ |
| 1070 |
0, /* tp_weaklistoffset */ |
| 1071 |
0, /* tp_iter */ |
| 1072 |
0, /* tp_iternext */ |
| 1073 |
HannTable_methods, /* tp_methods */ |
| 1074 |
HannTable_members, /* tp_members */ |
| 1075 |
0, /* tp_getset */ |
| 1076 |
0, /* tp_base */ |
| 1077 |
0, /* tp_dict */ |
| 1078 |
0, /* tp_descr_get */ |
| 1079 |
0, /* tp_descr_set */ |
| 1080 |
0, /* tp_dictoffset */ |
| 1081 |
0, /* tp_init */ |
| 1082 |
0, /* tp_alloc */ |
| 1083 |
HannTable_new, /* tp_new */ |
| 1084 |
}; |
| 1085 |
|
| 1086 |
/***********************/ |
| 1087 |
/* SincTable structure */ |
| 1088 |
/***********************/ |
| 1089 |
typedef struct |
| 1090 |
{ |
| 1091 |
pyo_table_HEAD |
| 1092 |
MYFLT freq; |
| 1093 |
int windowed; |
| 1094 |
} SincTable; |
| 1095 |
|
| 1096 |
static void |
| 1097 |
SincTable_generate(SincTable *self) |
| 1098 |
{ |
| 1099 |
T_SIZE_T i, half, halfMinusOne; |
| 1100 |
MYFLT scl, val; |
| 1101 |
|
| 1102 |
half = self->size / 2; |
| 1103 |
|
| 1104 |
if (self->windowed) |
| 1105 |
{ |
| 1106 |
halfMinusOne = half - 1; |
| 1107 |
|
| 1108 |
for (i = 0; i < self->size; i++) |
| 1109 |
{ |
| 1110 |
scl = (MYFLT)(i - half) / half * self->freq; |
| 1111 |
|
| 1112 |
if (scl == 0.0) |
| 1113 |
val = 1.0; |
| 1114 |
else |
| 1115 |
val = (MYSIN(scl) / scl); |
| 1116 |
|
| 1117 |
val *= 0.5 + (MYCOS(TWOPI * (i - halfMinusOne) / self->size) * 0.5); |
| 1118 |
self->data[i] = val; |
| 1119 |
} |
| 1120 |
} |
| 1121 |
else |
| 1122 |
{ |
| 1123 |
for (i = 0; i < self->size; i++) |
| 1124 |
{ |
| 1125 |
scl = (MYFLT)(i - half) / half * self->freq; |
| 1126 |
|
| 1127 |
if (scl == 0.0) |
| 1128 |
val = 1.0; |
| 1129 |
else |
| 1130 |
val = (MYSIN(scl) / scl); |
| 1131 |
|
| 1132 |
self->data[i] = val; |
| 1133 |
} |
| 1134 |
} |
| 1135 |
|
| 1136 |
self->data[self->size] = self->data[0]; |
| 1137 |
} |
| 1138 |
|
| 1139 |
static int |
| 1140 |
SincTable_traverse(SincTable *self, visitproc visit, void *arg) |
| 1141 |
{ |
| 1142 |
pyo_table_VISIT |
| 1143 |
return 0; |
| 1144 |
} |
| 1145 |
|
| 1146 |
static int |
| 1147 |
SincTable_clear(SincTable *self) |
| 1148 |
{ |
| 1149 |
pyo_table_CLEAR |
| 1150 |
return 0; |
| 1151 |
} |
| 1152 |
|
| 1153 |
static void |
| 1154 |
SincTable_dealloc(SincTable* self) |
| 1155 |
{ |
| 1156 |
PyMem_RawFree(self->data); |
| 1157 |
SincTable_clear(self); |
| 1158 |
Py_TYPE(self->tablestream)->tp_free((PyObject*)self->tablestream); |
| 1159 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 1160 |
} |
| 1161 |
|
| 1162 |
static PyObject * |
| 1163 |
SincTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 1164 |
{ |
| 1165 |
SincTable *self; |
| 1166 |
self = (SincTable *)type->tp_alloc(type, 0); |
| 1167 |
|
| 1168 |
self->server = PyServer_get_server(); |
| 1169 |
Py_INCREF(self->server); |
| 1170 |
|
| 1171 |
self->size = 8192; |
| 1172 |
self->freq = TWOPI; |
| 1173 |
self->windowed = 0; |
| 1174 |
|
| 1175 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 1176 |
|
| 1177 |
static char *kwlist[] = {"freq", "windowed", "size", NULL}; |
| 1178 |
|
| 1179 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE__FIN, kwlist, &self->freq, &self->windowed, &self->size)) |
| 1180 |
Py_RETURN_NONE; |
| 1181 |
|
| 1182 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 1183 |
TableStream_setSize(self->tablestream, self->size); |
| 1184 |
TableStream_setData(self->tablestream, self->data); |
| 1185 |
SincTable_generate(self); |
| 1186 |
|
| 1187 |
PyObject *srobj = PyObject_CallMethod(self->server, "getSamplingRate", NULL); |
| 1188 |
double sr = PyFloat_AsDouble(srobj); |
| 1189 |
Py_DECREF(srobj); |
| 1190 |
|
| 1191 |
TableStream_setSamplingRate(self->tablestream, sr); |
| 1192 |
|
| 1193 |
return (PyObject *)self; |
| 1194 |
} |
| 1195 |
|
| 1196 |
static PyObject * SincTable_getServer(SincTable* self) { GET_SERVER }; |
| 1197 |
static PyObject * SincTable_getTableStream(SincTable* self) { GET_TABLE_STREAM }; |
| 1198 |
static PyObject * SincTable_setData(SincTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 1199 |
static PyObject * SincTable_normalize(SincTable *self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 1200 |
static PyObject * SincTable_reset(SincTable *self) { TABLE_RESET }; |
| 1201 |
static PyObject * SincTable_removeDC(SincTable *self) { REMOVE_DC }; |
| 1202 |
static PyObject * SincTable_reverse(SincTable *self) { REVERSE }; |
| 1203 |
static PyObject * SincTable_invert(SincTable *self) { INVERT }; |
| 1204 |
static PyObject * SincTable_rectify(SincTable *self) { RECTIFY }; |
| 1205 |
static PyObject * SincTable_bipolarGain(SincTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 1206 |
static PyObject * SincTable_lowpass(SincTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 1207 |
static PyObject * SincTable_fadein(SincTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 1208 |
static PyObject * SincTable_fadeout(SincTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 1209 |
static PyObject * SincTable_pow(SincTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 1210 |
static PyObject * SincTable_copy(SincTable *self, PyObject *arg) { COPY }; |
| 1211 |
static PyObject * SincTable_copyData(SincTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 1212 |
static PyObject * SincTable_rotate(SincTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 1213 |
static PyObject * SincTable_setTable(SincTable *self, PyObject *arg) { SET_TABLE }; |
| 1214 |
static PyObject * SincTable_getTable(SincTable *self) { GET_TABLE }; |
| 1215 |
static PyObject * SincTable_getRate(SincTable *self) { TABLE_GET_RATE }; |
| 1216 |
static PyObject * SincTable_getViewTable(SincTable *self, PyObject *args, PyObject *kwds) { GET_VIEW_TABLE }; |
| 1217 |
static PyObject * SincTable_put(SincTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 1218 |
static PyObject * SincTable_get(SincTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 1219 |
static PyObject * SincTable_add(SincTable *self, PyObject *arg) { TABLE_ADD }; |
| 1220 |
static PyObject * SincTable_sub(SincTable *self, PyObject *arg) { TABLE_SUB }; |
| 1221 |
static PyObject * SincTable_mul(SincTable *self, PyObject *arg) { TABLE_MUL }; |
| 1222 |
static PyObject * SincTable_div(SincTable *self, PyObject *arg) { TABLE_DIV }; |
| 1223 |
|
| 1224 |
static PyObject * |
| 1225 |
SincTable_setFreq(SincTable *self, PyObject *value) |
| 1226 |
{ |
| 1227 |
|
| 1228 |
if (! PyNumber_Check(value)) |
| 1229 |
{ |
| 1230 |
PyErr_SetString(PyExc_TypeError, "The freq attribute value must be a number."); |
| 1231 |
return PyLong_FromLong(-1); |
| 1232 |
} |
| 1233 |
|
| 1234 |
self->freq = PyFloat_AsDouble(value); |
| 1235 |
|
| 1236 |
SincTable_generate(self); |
| 1237 |
|
| 1238 |
Py_RETURN_NONE; |
| 1239 |
} |
| 1240 |
|
| 1241 |
static PyObject * |
| 1242 |
SincTable_setWindowed(SincTable *self, PyObject *value) |
| 1243 |
{ |
| 1244 |
|
| 1245 |
if (! PyLong_Check(value)) |
| 1246 |
{ |
| 1247 |
PyErr_SetString(PyExc_TypeError, "The windowed attribute value must be a boolean."); |
| 1248 |
return PyLong_FromLong(-1); |
| 1249 |
} |
| 1250 |
|
| 1251 |
self->windowed = PyLong_AsLong(value); |
| 1252 |
|
| 1253 |
SincTable_generate(self); |
| 1254 |
|
| 1255 |
Py_RETURN_NONE; |
| 1256 |
} |
| 1257 |
|
| 1258 |
static PyObject * |
| 1259 |
SincTable_setSize(SincTable *self, PyObject *value) |
| 1260 |
{ |
| 1261 |
TABLE_SET_SIZE |
| 1262 |
|
| 1263 |
SincTable_generate(self); |
| 1264 |
|
| 1265 |
Py_RETURN_NONE; |
| 1266 |
} |
| 1267 |
|
| 1268 |
static PyObject * |
| 1269 |
SincTable_getSize(SincTable *self) |
| 1270 |
{ |
| 1271 |
return PyLong_FromLong(self->size); |
| 1272 |
}; |
| 1273 |
|
| 1274 |
static PyMemberDef SincTable_members[] = |
| 1275 |
{ |
| 1276 |
{"server", T_OBJECT_EX, offsetof(SincTable, server), 0, "Pyo server."}, |
| 1277 |
{"tablestream", T_OBJECT_EX, offsetof(SincTable, tablestream), 0, "Table stream object."}, |
| 1278 |
{NULL} /* Sentinel */ |
| 1279 |
}; |
| 1280 |
|
| 1281 |
static PyMethodDef SincTable_methods[] = |
| 1282 |
{ |
| 1283 |
{"getServer", (PyCFunction)SincTable_getServer, METH_NOARGS, "Returns server object."}, |
| 1284 |
{"copy", (PyCFunction)SincTable_copy, METH_O, "Copy data from table given in argument."}, |
| 1285 |
{"copyData", (PyCFunction)SincTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 1286 |
{"rotate", (PyCFunction)SincTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 1287 |
{"setTable", (PyCFunction)SincTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 1288 |
{"getTable", (PyCFunction)SincTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 1289 |
{"getViewTable", (PyCFunction)SincTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 1290 |
{"getTableStream", (PyCFunction)SincTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 1291 |
{"setData", (PyCFunction)SincTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 1292 |
{"normalize", (PyCFunction)SincTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table samples"}, |
| 1293 |
{"reset", (PyCFunction)SincTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 1294 |
{"removeDC", (PyCFunction)SincTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 1295 |
{"reverse", (PyCFunction)SincTable_reverse, METH_NOARGS, "Reverse the table's data."}, |
| 1296 |
{"invert", (PyCFunction)SincTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 1297 |
{"rectify", (PyCFunction)SincTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 1298 |
{"bipolarGain", (PyCFunction)SincTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 1299 |
{"lowpass", (PyCFunction)SincTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 1300 |
{"fadein", (PyCFunction)SincTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 1301 |
{"fadeout", (PyCFunction)SincTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 1302 |
{"pow", (PyCFunction)SincTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 1303 |
{"setSize", (PyCFunction)SincTable_setSize, METH_O, "Sets the size of the table in samples"}, |
| 1304 |
{"getSize", (PyCFunction)SincTable_getSize, METH_NOARGS, "Return the size of the table in samples"}, |
| 1305 |
{"getRate", (PyCFunction)SincTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the table without pitch transposition."}, |
| 1306 |
{"setFreq", (PyCFunction)SincTable_setFreq, METH_O, "Sets the frequency, in radians, of the sinc function."}, |
| 1307 |
{"setWindowed", (PyCFunction)SincTable_setWindowed, METH_O, "If True, an hanning window is applied on the function."}, |
| 1308 |
{"put", (PyCFunction)SincTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 1309 |
{"get", (PyCFunction)SincTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 1310 |
{"add", (PyCFunction)SincTable_add, METH_O, "Performs table addition."}, |
| 1311 |
{"sub", (PyCFunction)SincTable_sub, METH_O, "Performs table substraction."}, |
| 1312 |
{"mul", (PyCFunction)SincTable_mul, METH_O, "Performs table multiplication."}, |
| 1313 |
{"div", (PyCFunction)SincTable_div, METH_O, "Performs table division."}, |
| 1314 |
{NULL} /* Sentinel */ |
| 1315 |
}; |
| 1316 |
|
| 1317 |
PyTypeObject SincTableType = |
| 1318 |
{ |
| 1319 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 1320 |
"_pyo.SincTable_base", /*tp_name*/ |
| 1321 |
sizeof(SincTable), /*tp_basicsize*/ |
| 1322 |
0, /*tp_itemsize*/ |
| 1323 |
(destructor)SincTable_dealloc, /*tp_dealloc*/ |
| 1324 |
0, /*tp_print*/ |
| 1325 |
0, /*tp_getattr*/ |
| 1326 |
0, /*tp_setattr*/ |
| 1327 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 1328 |
0, /*tp_repr*/ |
| 1329 |
0, /*tp_as_number*/ |
| 1330 |
0, /*tp_as_sequence*/ |
| 1331 |
0, /*tp_as_mapping*/ |
| 1332 |
0, /*tp_hash */ |
| 1333 |
0, /*tp_call*/ |
| 1334 |
0, /*tp_str*/ |
| 1335 |
0, /*tp_getattro*/ |
| 1336 |
0, /*tp_setattro*/ |
| 1337 |
0, /*tp_as_buffer*/ |
| 1338 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 1339 |
"SincTable objects. Generates a table filled with a sinc function.", /* tp_doc */ |
| 1340 |
(traverseproc)SincTable_traverse, /* tp_traverse */ |
| 1341 |
(inquiry)SincTable_clear, /* tp_clear */ |
| 1342 |
0, /* tp_richcompare */ |
| 1343 |
0, /* tp_weaklistoffset */ |
| 1344 |
0, /* tp_iter */ |
| 1345 |
0, /* tp_iternext */ |
| 1346 |
SincTable_methods, /* tp_methods */ |
| 1347 |
SincTable_members, /* tp_members */ |
| 1348 |
0, /* tp_getset */ |
| 1349 |
0, /* tp_base */ |
| 1350 |
0, /* tp_dict */ |
| 1351 |
0, /* tp_descr_get */ |
| 1352 |
0, /* tp_descr_set */ |
| 1353 |
0, /* tp_dictoffset */ |
| 1354 |
0, /* tp_init */ |
| 1355 |
0, /* tp_alloc */ |
| 1356 |
SincTable_new, /* tp_new */ |
| 1357 |
}; |
| 1358 |
|
| 1359 |
/***********************/ |
| 1360 |
/* WinTable structure */ |
| 1361 |
/***********************/ |
| 1362 |
typedef struct |
| 1363 |
{ |
| 1364 |
pyo_table_HEAD |
| 1365 |
int type; |
| 1366 |
} WinTable; |
| 1367 |
|
| 1368 |
static void |
| 1369 |
WinTable_generate(WinTable *self) |
| 1370 |
{ |
| 1371 |
gen_window(self->data, self->size, self->type); |
| 1372 |
self->data[self->size] = self->data[0]; |
| 1373 |
} |
| 1374 |
|
| 1375 |
static int |
| 1376 |
WinTable_traverse(WinTable *self, visitproc visit, void *arg) |
| 1377 |
{ |
| 1378 |
pyo_table_VISIT |
| 1379 |
return 0; |
| 1380 |
} |
| 1381 |
|
| 1382 |
static int |
| 1383 |
WinTable_clear(WinTable *self) |
| 1384 |
{ |
| 1385 |
pyo_table_CLEAR |
| 1386 |
return 0; |
| 1387 |
} |
| 1388 |
|
| 1389 |
static void |
| 1390 |
WinTable_dealloc(WinTable* self) |
| 1391 |
{ |
| 1392 |
PyMem_RawFree(self->data); |
| 1393 |
WinTable_clear(self); |
| 1394 |
Py_TYPE(self->tablestream)->tp_free((PyObject*)self->tablestream); |
| 1395 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 1396 |
} |
| 1397 |
|
| 1398 |
static PyObject * |
| 1399 |
WinTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 1400 |
{ |
| 1401 |
WinTable *self; |
| 1402 |
self = (WinTable *)type->tp_alloc(type, 0); |
| 1403 |
|
| 1404 |
self->server = PyServer_get_server(); |
| 1405 |
Py_INCREF(self->server); |
| 1406 |
|
| 1407 |
self->size = 8192; |
| 1408 |
self->type = 2; |
| 1409 |
|
| 1410 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 1411 |
|
| 1412 |
static char *kwlist[] = {"type", "size", NULL}; |
| 1413 |
|
| 1414 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|in", kwlist, &self->type, &self->size)) |
| 1415 |
Py_RETURN_NONE; |
| 1416 |
|
| 1417 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 1418 |
TableStream_setSize(self->tablestream, self->size); |
| 1419 |
TableStream_setData(self->tablestream, self->data); |
| 1420 |
WinTable_generate(self); |
| 1421 |
|
| 1422 |
PyObject *srobj = PyObject_CallMethod(self->server, "getSamplingRate", NULL); |
| 1423 |
double sr = PyFloat_AsDouble(srobj); |
| 1424 |
Py_DECREF(srobj); |
| 1425 |
|
| 1426 |
TableStream_setSamplingRate(self->tablestream, sr); |
| 1427 |
|
| 1428 |
return (PyObject *)self; |
| 1429 |
} |
| 1430 |
|
| 1431 |
static PyObject * WinTable_getServer(WinTable* self) { GET_SERVER }; |
| 1432 |
static PyObject * WinTable_getTableStream(WinTable* self) { GET_TABLE_STREAM }; |
| 1433 |
static PyObject * WinTable_setData(WinTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 1434 |
static PyObject * WinTable_normalize(WinTable *self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 1435 |
static PyObject * WinTable_reset(WinTable *self) { TABLE_RESET }; |
| 1436 |
static PyObject * WinTable_removeDC(WinTable *self) { REMOVE_DC }; |
| 1437 |
static PyObject * WinTable_reverse(WinTable *self) { REVERSE }; |
| 1438 |
static PyObject * WinTable_invert(WinTable *self) { INVERT }; |
| 1439 |
static PyObject * WinTable_rectify(WinTable *self) { RECTIFY }; |
| 1440 |
static PyObject * WinTable_bipolarGain(WinTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 1441 |
static PyObject * WinTable_lowpass(WinTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 1442 |
static PyObject * WinTable_fadein(WinTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 1443 |
static PyObject * WinTable_fadeout(WinTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 1444 |
static PyObject * WinTable_pow(WinTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 1445 |
static PyObject * WinTable_copy(WinTable *self, PyObject *arg) { COPY }; |
| 1446 |
static PyObject * WinTable_copyData(WinTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 1447 |
static PyObject * WinTable_rotate(WinTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 1448 |
static PyObject * WinTable_setTable(WinTable *self, PyObject *arg) { SET_TABLE }; |
| 1449 |
static PyObject * WinTable_getTable(WinTable *self) { GET_TABLE }; |
| 1450 |
static PyObject * WinTable_getRate(WinTable *self) { TABLE_GET_RATE }; |
| 1451 |
static PyObject * WinTable_getViewTable(WinTable *self, PyObject *args, PyObject *kwds) { GET_VIEW_TABLE }; |
| 1452 |
static PyObject * WinTable_put(WinTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 1453 |
static PyObject * WinTable_get(WinTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 1454 |
static PyObject * WinTable_add(WinTable *self, PyObject *arg) { TABLE_ADD }; |
| 1455 |
static PyObject * WinTable_sub(WinTable *self, PyObject *arg) { TABLE_SUB }; |
| 1456 |
static PyObject * WinTable_mul(WinTable *self, PyObject *arg) { TABLE_MUL }; |
| 1457 |
static PyObject * WinTable_div(WinTable *self, PyObject *arg) { TABLE_DIV }; |
| 1458 |
|
| 1459 |
static PyObject * |
| 1460 |
WinTable_setSize(WinTable *self, PyObject *value) |
| 1461 |
{ |
| 1462 |
TABLE_SET_SIZE |
| 1463 |
|
| 1464 |
WinTable_generate(self); |
| 1465 |
|
| 1466 |
Py_RETURN_NONE; |
| 1467 |
} |
| 1468 |
|
| 1469 |
static PyObject * |
| 1470 |
WinTable_getSize(WinTable *self) |
| 1471 |
{ |
| 1472 |
return PyLong_FromLong(self->size); |
| 1473 |
}; |
| 1474 |
|
| 1475 |
static PyObject * |
| 1476 |
WinTable_setType(WinTable *self, PyObject *value) |
| 1477 |
{ |
| 1478 |
if (value == NULL) |
| 1479 |
{ |
| 1480 |
PyErr_SetString(PyExc_TypeError, "Cannot delete the type attribute."); |
| 1481 |
return PyLong_FromLong(-1); |
| 1482 |
} |
| 1483 |
|
| 1484 |
if (! PyLong_Check(value)) |
| 1485 |
{ |
| 1486 |
PyErr_SetString(PyExc_TypeError, "The type attribute value must be an integer."); |
| 1487 |
return PyLong_FromLong(-1); |
| 1488 |
} |
| 1489 |
|
| 1490 |
self->type = PyLong_AsLong(value); |
| 1491 |
|
| 1492 |
WinTable_generate(self); |
| 1493 |
|
| 1494 |
Py_RETURN_NONE; |
| 1495 |
} |
| 1496 |
|
| 1497 |
static PyMemberDef WinTable_members[] = |
| 1498 |
{ |
| 1499 |
{"server", T_OBJECT_EX, offsetof(WinTable, server), 0, "Pyo server."}, |
| 1500 |
{"tablestream", T_OBJECT_EX, offsetof(WinTable, tablestream), 0, "Table stream object."}, |
| 1501 |
{NULL} /* Sentinel */ |
| 1502 |
}; |
| 1503 |
|
| 1504 |
static PyMethodDef WinTable_methods[] = |
| 1505 |
{ |
| 1506 |
{"getServer", (PyCFunction)WinTable_getServer, METH_NOARGS, "Returns server object."}, |
| 1507 |
{"copy", (PyCFunction)WinTable_copy, METH_O, "Copy data from table given in argument."}, |
| 1508 |
{"copyData", (PyCFunction)WinTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 1509 |
{"rotate", (PyCFunction)WinTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 1510 |
{"setTable", (PyCFunction)WinTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 1511 |
{"getTable", (PyCFunction)WinTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 1512 |
{"getViewTable", (PyCFunction)WinTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 1513 |
{"getTableStream", (PyCFunction)WinTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 1514 |
{"setData", (PyCFunction)WinTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 1515 |
{"normalize", (PyCFunction)WinTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table samples"}, |
| 1516 |
{"reset", (PyCFunction)WinTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 1517 |
{"removeDC", (PyCFunction)WinTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 1518 |
{"reverse", (PyCFunction)WinTable_reverse, METH_NOARGS, "Reverse the table's data."}, |
| 1519 |
{"invert", (PyCFunction)WinTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 1520 |
{"rectify", (PyCFunction)WinTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 1521 |
{"bipolarGain", (PyCFunction)WinTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 1522 |
{"lowpass", (PyCFunction)WinTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 1523 |
{"fadein", (PyCFunction)WinTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 1524 |
{"fadeout", (PyCFunction)WinTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 1525 |
{"pow", (PyCFunction)WinTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 1526 |
{"setSize", (PyCFunction)WinTable_setSize, METH_O, "Sets the size of the table in samples"}, |
| 1527 |
{"getSize", (PyCFunction)WinTable_getSize, METH_NOARGS, "Return the size of the table in samples"}, |
| 1528 |
{"getRate", (PyCFunction)WinTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the table without pitch transposition."}, |
| 1529 |
{"setType", (PyCFunction)WinTable_setType, METH_O, "Sets the type of the table."}, |
| 1530 |
{"put", (PyCFunction)WinTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 1531 |
{"get", (PyCFunction)WinTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 1532 |
{"add", (PyCFunction)WinTable_add, METH_O, "Performs table addition."}, |
| 1533 |
{"sub", (PyCFunction)WinTable_sub, METH_O, "Performs table substraction."}, |
| 1534 |
{"mul", (PyCFunction)WinTable_mul, METH_O, "Performs table multiplication."}, |
| 1535 |
{"div", (PyCFunction)WinTable_div, METH_O, "Performs table division."}, |
| 1536 |
{NULL} /* Sentinel */ |
| 1537 |
}; |
| 1538 |
|
| 1539 |
PyTypeObject WinTableType = |
| 1540 |
{ |
| 1541 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 1542 |
"_pyo.WinTable_base", /*tp_name*/ |
| 1543 |
sizeof(WinTable), /*tp_basicsize*/ |
| 1544 |
0, /*tp_itemsize*/ |
| 1545 |
(destructor)WinTable_dealloc, /*tp_dealloc*/ |
| 1546 |
0, /*tp_print*/ |
| 1547 |
0, /*tp_getattr*/ |
| 1548 |
0, /*tp_setattr*/ |
| 1549 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 1550 |
0, /*tp_repr*/ |
| 1551 |
0, /*tp_as_number*/ |
| 1552 |
0, /*tp_as_sequence*/ |
| 1553 |
0, /*tp_as_mapping*/ |
| 1554 |
0, /*tp_hash */ |
| 1555 |
0, /*tp_call*/ |
| 1556 |
0, /*tp_str*/ |
| 1557 |
0, /*tp_getattro*/ |
| 1558 |
0, /*tp_setattro*/ |
| 1559 |
0, /*tp_as_buffer*/ |
| 1560 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 1561 |
"WinTable objects. Generates a table filled with a hanning function.", /* tp_doc */ |
| 1562 |
(traverseproc)WinTable_traverse, /* tp_traverse */ |
| 1563 |
(inquiry)WinTable_clear, /* tp_clear */ |
| 1564 |
0, /* tp_richcompare */ |
| 1565 |
0, /* tp_weaklistoffset */ |
| 1566 |
0, /* tp_iter */ |
| 1567 |
0, /* tp_iternext */ |
| 1568 |
WinTable_methods, /* tp_methods */ |
| 1569 |
WinTable_members, /* tp_members */ |
| 1570 |
0, /* tp_getset */ |
| 1571 |
0, /* tp_base */ |
| 1572 |
0, /* tp_dict */ |
| 1573 |
0, /* tp_descr_get */ |
| 1574 |
0, /* tp_descr_set */ |
| 1575 |
0, /* tp_dictoffset */ |
| 1576 |
0, /* tp_init */ |
| 1577 |
0, /* tp_alloc */ |
| 1578 |
WinTable_new, /* tp_new */ |
| 1579 |
}; |
| 1580 |
|
| 1581 |
/***********************/ |
| 1582 |
/* ParaTable structure */ |
| 1583 |
/***********************/ |
| 1584 |
typedef struct |
| 1585 |
{ |
| 1586 |
pyo_table_HEAD |
| 1587 |
} ParaTable; |
| 1588 |
|
| 1589 |
static void |
| 1590 |
ParaTable_generate(ParaTable *self) |
| 1591 |
{ |
| 1592 |
T_SIZE_T i, sizeMinusOne; |
| 1593 |
MYFLT rdur, rdur2, level, slope, curve; |
| 1594 |
|
| 1595 |
sizeMinusOne = self->size - 1; |
| 1596 |
rdur = 1.0 / sizeMinusOne; |
| 1597 |
rdur2 = rdur * rdur; |
| 1598 |
level = 0.0; |
| 1599 |
slope = 4.0 * (rdur - rdur2); |
| 1600 |
curve = -8.0 * rdur2; |
| 1601 |
|
| 1602 |
for (i = 0; i < sizeMinusOne; i++) |
| 1603 |
{ |
| 1604 |
self->data[i] = level; |
| 1605 |
level += slope; |
| 1606 |
slope += curve; |
| 1607 |
} |
| 1608 |
|
| 1609 |
self->data[sizeMinusOne] = self->data[0]; |
| 1610 |
self->data[self->size] = self->data[0]; |
| 1611 |
} |
| 1612 |
|
| 1613 |
static int |
| 1614 |
ParaTable_traverse(ParaTable *self, visitproc visit, void *arg) |
| 1615 |
{ |
| 1616 |
pyo_table_VISIT |
| 1617 |
return 0; |
| 1618 |
} |
| 1619 |
|
| 1620 |
static int |
| 1621 |
ParaTable_clear(ParaTable *self) |
| 1622 |
{ |
| 1623 |
pyo_table_CLEAR |
| 1624 |
return 0; |
| 1625 |
} |
| 1626 |
|
| 1627 |
static void |
| 1628 |
ParaTable_dealloc(ParaTable* self) |
| 1629 |
{ |
| 1630 |
PyMem_RawFree(self->data); |
| 1631 |
ParaTable_clear(self); |
| 1632 |
Py_TYPE(self->tablestream)->tp_free((PyObject*)self->tablestream); |
| 1633 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 1634 |
} |
| 1635 |
|
| 1636 |
static PyObject * |
| 1637 |
ParaTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 1638 |
{ |
| 1639 |
ParaTable *self; |
| 1640 |
self = (ParaTable *)type->tp_alloc(type, 0); |
| 1641 |
|
| 1642 |
self->server = PyServer_get_server(); |
| 1643 |
Py_INCREF(self->server); |
| 1644 |
|
| 1645 |
self->size = 8192; |
| 1646 |
|
| 1647 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 1648 |
|
| 1649 |
static char *kwlist[] = {"size", NULL}; |
| 1650 |
|
| 1651 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|n", kwlist, &self->size)) |
| 1652 |
Py_RETURN_NONE; |
| 1653 |
|
| 1654 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 1655 |
TableStream_setSize(self->tablestream, self->size); |
| 1656 |
TableStream_setData(self->tablestream, self->data); |
| 1657 |
ParaTable_generate(self); |
| 1658 |
|
| 1659 |
PyObject *srobj = PyObject_CallMethod(self->server, "getSamplingRate", NULL); |
| 1660 |
double sr = PyFloat_AsDouble(srobj); |
| 1661 |
Py_DECREF(srobj); |
| 1662 |
|
| 1663 |
TableStream_setSamplingRate(self->tablestream, sr); |
| 1664 |
|
| 1665 |
return (PyObject *)self; |
| 1666 |
} |
| 1667 |
|
| 1668 |
static PyObject * ParaTable_getServer(ParaTable* self) { GET_SERVER }; |
| 1669 |
static PyObject * ParaTable_getTableStream(ParaTable* self) { GET_TABLE_STREAM }; |
| 1670 |
static PyObject * ParaTable_setData(ParaTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 1671 |
static PyObject * ParaTable_normalize(ParaTable *self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 1672 |
static PyObject * ParaTable_reset(ParaTable *self) { TABLE_RESET }; |
| 1673 |
static PyObject * ParaTable_removeDC(ParaTable *self) { REMOVE_DC }; |
| 1674 |
static PyObject * ParaTable_reverse(ParaTable *self) { REVERSE }; |
| 1675 |
static PyObject * ParaTable_invert(ParaTable *self) { INVERT }; |
| 1676 |
static PyObject * ParaTable_rectify(ParaTable *self) { RECTIFY }; |
| 1677 |
static PyObject * ParaTable_bipolarGain(ParaTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 1678 |
static PyObject * ParaTable_lowpass(ParaTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 1679 |
static PyObject * ParaTable_fadein(ParaTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 1680 |
static PyObject * ParaTable_fadeout(ParaTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 1681 |
static PyObject * ParaTable_pow(ParaTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 1682 |
static PyObject * ParaTable_copy(ParaTable *self, PyObject *arg) { COPY }; |
| 1683 |
static PyObject * ParaTable_copyData(ParaTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 1684 |
static PyObject * ParaTable_rotate(ParaTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 1685 |
static PyObject * ParaTable_setTable(ParaTable *self, PyObject *arg) { SET_TABLE }; |
| 1686 |
static PyObject * ParaTable_getTable(ParaTable *self) { GET_TABLE }; |
| 1687 |
static PyObject * ParaTable_getRate(ParaTable *self) { TABLE_GET_RATE }; |
| 1688 |
static PyObject * ParaTable_getViewTable(ParaTable *self, PyObject *args, PyObject *kwds) { GET_VIEW_TABLE }; |
| 1689 |
static PyObject * ParaTable_put(ParaTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 1690 |
static PyObject * ParaTable_get(ParaTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 1691 |
static PyObject * ParaTable_add(ParaTable *self, PyObject *arg) { TABLE_ADD }; |
| 1692 |
static PyObject * ParaTable_sub(ParaTable *self, PyObject *arg) { TABLE_SUB }; |
| 1693 |
static PyObject * ParaTable_mul(ParaTable *self, PyObject *arg) { TABLE_MUL }; |
| 1694 |
static PyObject * ParaTable_div(ParaTable *self, PyObject *arg) { TABLE_DIV }; |
| 1695 |
|
| 1696 |
static PyObject * |
| 1697 |
ParaTable_setSize(ParaTable *self, PyObject *value) |
| 1698 |
{ |
| 1699 |
TABLE_SET_SIZE |
| 1700 |
|
| 1701 |
ParaTable_generate(self); |
| 1702 |
|
| 1703 |
Py_RETURN_NONE; |
| 1704 |
} |
| 1705 |
|
| 1706 |
static PyObject * |
| 1707 |
ParaTable_getSize(ParaTable *self) |
| 1708 |
{ |
| 1709 |
return PyLong_FromLong(self->size); |
| 1710 |
}; |
| 1711 |
|
| 1712 |
static PyMemberDef ParaTable_members[] = |
| 1713 |
{ |
| 1714 |
{"server", T_OBJECT_EX, offsetof(ParaTable, server), 0, "Pyo server."}, |
| 1715 |
{"tablestream", T_OBJECT_EX, offsetof(ParaTable, tablestream), 0, "Table stream object."}, |
| 1716 |
{NULL} /* Sentinel */ |
| 1717 |
}; |
| 1718 |
|
| 1719 |
static PyMethodDef ParaTable_methods[] = |
| 1720 |
{ |
| 1721 |
{"getServer", (PyCFunction)ParaTable_getServer, METH_NOARGS, "Returns server object."}, |
| 1722 |
{"copy", (PyCFunction)ParaTable_copy, METH_O, "Copy data from table given in argument."}, |
| 1723 |
{"copyData", (PyCFunction)ParaTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 1724 |
{"rotate", (PyCFunction)ParaTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 1725 |
{"setTable", (PyCFunction)ParaTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 1726 |
{"getTable", (PyCFunction)ParaTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 1727 |
{"getViewTable", (PyCFunction)ParaTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 1728 |
{"getTableStream", (PyCFunction)ParaTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 1729 |
{"setData", (PyCFunction)ParaTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 1730 |
{"normalize", (PyCFunction)ParaTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table samples"}, |
| 1731 |
{"reset", (PyCFunction)ParaTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 1732 |
{"removeDC", (PyCFunction)ParaTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 1733 |
{"reverse", (PyCFunction)ParaTable_reverse, METH_NOARGS, "Reverse the table's data."}, |
| 1734 |
{"invert", (PyCFunction)ParaTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 1735 |
{"rectify", (PyCFunction)ParaTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 1736 |
{"bipolarGain", (PyCFunction)ParaTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 1737 |
{"lowpass", (PyCFunction)ParaTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 1738 |
{"fadein", (PyCFunction)ParaTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 1739 |
{"fadeout", (PyCFunction)ParaTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 1740 |
{"pow", (PyCFunction)ParaTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 1741 |
{"setSize", (PyCFunction)ParaTable_setSize, METH_O, "Sets the size of the table in samples"}, |
| 1742 |
{"getSize", (PyCFunction)ParaTable_getSize, METH_NOARGS, "Return the size of the table in samples"}, |
| 1743 |
{"getRate", (PyCFunction)ParaTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the table without pitch transposition."}, |
| 1744 |
{"put", (PyCFunction)ParaTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 1745 |
{"get", (PyCFunction)ParaTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 1746 |
{"add", (PyCFunction)ParaTable_add, METH_O, "Performs table addition."}, |
| 1747 |
{"sub", (PyCFunction)ParaTable_sub, METH_O, "Performs table substraction."}, |
| 1748 |
{"mul", (PyCFunction)ParaTable_mul, METH_O, "Performs table multiplication."}, |
| 1749 |
{"div", (PyCFunction)ParaTable_div, METH_O, "Performs table division."}, |
| 1750 |
{NULL} /* Sentinel */ |
| 1751 |
}; |
| 1752 |
|
| 1753 |
PyTypeObject ParaTableType = |
| 1754 |
{ |
| 1755 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 1756 |
"_pyo.ParaTable_base", /*tp_name*/ |
| 1757 |
sizeof(ParaTable), /*tp_basicsize*/ |
| 1758 |
0, /*tp_itemsize*/ |
| 1759 |
(destructor)ParaTable_dealloc, /*tp_dealloc*/ |
| 1760 |
0, /*tp_print*/ |
| 1761 |
0, /*tp_getattr*/ |
| 1762 |
0, /*tp_setattr*/ |
| 1763 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 1764 |
0, /*tp_repr*/ |
| 1765 |
0, /*tp_as_number*/ |
| 1766 |
0, /*tp_as_sequence*/ |
| 1767 |
0, /*tp_as_mapping*/ |
| 1768 |
0, /*tp_hash */ |
| 1769 |
0, /*tp_call*/ |
| 1770 |
0, /*tp_str*/ |
| 1771 |
0, /*tp_getattro*/ |
| 1772 |
0, /*tp_setattro*/ |
| 1773 |
0, /*tp_as_buffer*/ |
| 1774 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 1775 |
"ParaTable objects. Generates a parabola table.", /* tp_doc */ |
| 1776 |
(traverseproc)ParaTable_traverse, /* tp_traverse */ |
| 1777 |
(inquiry)ParaTable_clear, /* tp_clear */ |
| 1778 |
0, /* tp_richcompare */ |
| 1779 |
0, /* tp_weaklistoffset */ |
| 1780 |
0, /* tp_iter */ |
| 1781 |
0, /* tp_iternext */ |
| 1782 |
ParaTable_methods, /* tp_methods */ |
| 1783 |
ParaTable_members, /* tp_members */ |
| 1784 |
0, /* tp_getset */ |
| 1785 |
0, /* tp_base */ |
| 1786 |
0, /* tp_dict */ |
| 1787 |
0, /* tp_descr_get */ |
| 1788 |
0, /* tp_descr_set */ |
| 1789 |
0, /* tp_dictoffset */ |
| 1790 |
0, /* tp_init */ |
| 1791 |
0, /* tp_alloc */ |
| 1792 |
ParaTable_new, /* tp_new */ |
| 1793 |
}; |
| 1794 |
|
| 1795 |
/***********************/ |
| 1796 |
/* LinTable structure */ |
| 1797 |
/***********************/ |
| 1798 |
typedef struct |
| 1799 |
{ |
| 1800 |
pyo_table_HEAD |
| 1801 |
PyObject *pointslist; |
| 1802 |
} LinTable; |
| 1803 |
|
| 1804 |
static void |
| 1805 |
LinTable_generate(LinTable *self) |
| 1806 |
{ |
| 1807 |
T_SIZE_T i, j, steps; |
| 1808 |
T_SIZE_T listsize; |
| 1809 |
PyObject *tup, *tup2; |
| 1810 |
T_SIZE_T x1, y1; |
| 1811 |
MYFLT x2, y2, diff; |
| 1812 |
|
| 1813 |
y1 = 0; |
| 1814 |
y2 = 0.0; |
| 1815 |
|
| 1816 |
listsize = PyList_Size(self->pointslist); |
| 1817 |
|
| 1818 |
if (listsize < 2) |
| 1819 |
{ |
| 1820 |
PySys_WriteStderr("LinTable error: There should be at least two points in a LinTable.\n"); |
| 1821 |
return; |
| 1822 |
} |
| 1823 |
|
| 1824 |
for (i = 0; i < (listsize - 1); i++) |
| 1825 |
{ |
| 1826 |
tup = PyList_GET_ITEM(self->pointslist, i); |
| 1827 |
PyObject *p1 = PyTuple_GET_ITEM(tup, 0); |
| 1828 |
x1 = PyLong_AsLong(PyNumber_Long(p1)); |
| 1829 |
x2 = PyFloat_AsDouble(PyTuple_GET_ITEM(tup, 1)); |
| 1830 |
tup2 = PyList_GET_ITEM(self->pointslist, i + 1); |
| 1831 |
PyObject *p2 = PyTuple_GET_ITEM(tup2, 0); |
| 1832 |
y1 = PyLong_AsLong(PyNumber_Long(p2)); |
| 1833 |
y2 = PyFloat_AsDouble(PyTuple_GET_ITEM(tup2, 1)); |
| 1834 |
|
| 1835 |
Py_DECREF(p1); |
| 1836 |
Py_DECREF(p2); |
| 1837 |
|
| 1838 |
steps = y1 - x1; |
| 1839 |
|
| 1840 |
if (steps <= 0) |
| 1841 |
{ |
| 1842 |
PySys_WriteStderr("LinTable error: point position smaller than previous one.\n"); |
| 1843 |
return; |
| 1844 |
} |
| 1845 |
|
| 1846 |
diff = (y2 - x2) / steps; |
| 1847 |
|
| 1848 |
for (j = 0; j < steps; j++) |
| 1849 |
{ |
| 1850 |
self->data[x1 + j] = x2 + diff * j; |
| 1851 |
} |
| 1852 |
} |
| 1853 |
|
| 1854 |
if (y1 < (self->size - 1)) |
| 1855 |
{ |
| 1856 |
self->data[y1] = y2; |
| 1857 |
|
| 1858 |
for (i = y1; i < self->size; i++) |
| 1859 |
{ |
| 1860 |
self->data[i + 1] = 0.0; |
| 1861 |
} |
| 1862 |
|
| 1863 |
self->data[self->size] = 0.0; |
| 1864 |
} |
| 1865 |
else |
| 1866 |
{ |
| 1867 |
self->data[self->size - 1] = y2; |
| 1868 |
self->data[self->size] = y2; |
| 1869 |
} |
| 1870 |
} |
| 1871 |
|
| 1872 |
static int |
| 1873 |
LinTable_traverse(LinTable *self, visitproc visit, void *arg) |
| 1874 |
{ |
| 1875 |
pyo_table_VISIT |
| 1876 |
Py_VISIT(self->pointslist); |
| 1877 |
return 0; |
| 1878 |
} |
| 1879 |
|
| 1880 |
static int |
| 1881 |
LinTable_clear(LinTable *self) |
| 1882 |
{ |
| 1883 |
pyo_table_CLEAR |
| 1884 |
Py_CLEAR(self->pointslist); |
| 1885 |
return 0; |
| 1886 |
} |
| 1887 |
|
| 1888 |
static void |
| 1889 |
LinTable_dealloc(LinTable* self) |
| 1890 |
{ |
| 1891 |
PyMem_RawFree(self->data); |
| 1892 |
LinTable_clear(self); |
| 1893 |
Py_TYPE(self->tablestream)->tp_free((PyObject*)self->tablestream); |
| 1894 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 1895 |
} |
| 1896 |
|
| 1897 |
static PyObject * |
| 1898 |
LinTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 1899 |
{ |
| 1900 |
PyObject *pointslist = NULL; |
| 1901 |
LinTable *self; |
| 1902 |
self = (LinTable *)type->tp_alloc(type, 0); |
| 1903 |
|
| 1904 |
self->server = PyServer_get_server(); |
| 1905 |
Py_INCREF(self->server); |
| 1906 |
|
| 1907 |
self->pointslist = PyList_New(0); |
| 1908 |
self->size = 8192; |
| 1909 |
|
| 1910 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 1911 |
|
| 1912 |
static char *kwlist[] = {"list", "size", NULL}; |
| 1913 |
|
| 1914 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|On", kwlist, &pointslist, &self->size)) |
| 1915 |
Py_RETURN_NONE; |
| 1916 |
|
| 1917 |
if (pointslist) |
| 1918 |
{ |
| 1919 |
Py_INCREF(pointslist); |
| 1920 |
Py_DECREF(self->pointslist); |
| 1921 |
self->pointslist = pointslist; |
| 1922 |
} |
| 1923 |
else |
| 1924 |
{ |
| 1925 |
PyList_Append(self->pointslist, PyTuple_Pack(2, PyLong_FromLong(0), PyFloat_FromDouble(0.))); |
| 1926 |
PyList_Append(self->pointslist, PyTuple_Pack(2, PyLong_FromLong(self->size), PyFloat_FromDouble(1.))); |
| 1927 |
} |
| 1928 |
|
| 1929 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 1930 |
TableStream_setSize(self->tablestream, self->size); |
| 1931 |
TableStream_setData(self->tablestream, self->data); |
| 1932 |
LinTable_generate(self); |
| 1933 |
|
| 1934 |
PyObject *srobj = PyObject_CallMethod(self->server, "getSamplingRate", NULL); |
| 1935 |
double sr = PyFloat_AsDouble(srobj); |
| 1936 |
Py_DECREF(srobj); |
| 1937 |
|
| 1938 |
TableStream_setSamplingRate(self->tablestream, sr); |
| 1939 |
|
| 1940 |
return (PyObject *)self; |
| 1941 |
} |
| 1942 |
|
| 1943 |
static PyObject * LinTable_getServer(LinTable* self) { GET_SERVER }; |
| 1944 |
static PyObject * LinTable_getTableStream(LinTable* self) { GET_TABLE_STREAM }; |
| 1945 |
static PyObject * LinTable_setData(LinTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 1946 |
static PyObject * LinTable_normalize(LinTable *self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 1947 |
static PyObject * LinTable_reset(LinTable *self) { TABLE_RESET }; |
| 1948 |
static PyObject * LinTable_removeDC(LinTable *self) { REMOVE_DC }; |
| 1949 |
static PyObject * LinTable_reverse(LinTable *self) { REVERSE }; |
| 1950 |
static PyObject * LinTable_invert(LinTable *self) { INVERT }; |
| 1951 |
static PyObject * LinTable_rectify(LinTable *self) { RECTIFY }; |
| 1952 |
static PyObject * LinTable_bipolarGain(LinTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 1953 |
static PyObject * LinTable_lowpass(LinTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 1954 |
static PyObject * LinTable_fadein(LinTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 1955 |
static PyObject * LinTable_fadeout(LinTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 1956 |
static PyObject * LinTable_pow(LinTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 1957 |
static PyObject * LinTable_copy(LinTable *self, PyObject *arg) { COPY }; |
| 1958 |
static PyObject * LinTable_copyData(LinTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 1959 |
static PyObject * LinTable_rotate(LinTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 1960 |
static PyObject * LinTable_setTable(LinTable *self, PyObject *arg) { SET_TABLE }; |
| 1961 |
static PyObject * LinTable_getTable(LinTable *self) { GET_TABLE }; |
| 1962 |
static PyObject * LinTable_getRate(LinTable *self) { TABLE_GET_RATE }; |
| 1963 |
static PyObject * LinTable_getViewTable(LinTable *self, PyObject *args, PyObject *kwds) { GET_VIEW_TABLE }; |
| 1964 |
static PyObject * LinTable_put(LinTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 1965 |
static PyObject * LinTable_get(LinTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 1966 |
static PyObject * LinTable_add(LinTable *self, PyObject *arg) { TABLE_ADD }; |
| 1967 |
static PyObject * LinTable_sub(LinTable *self, PyObject *arg) { TABLE_SUB }; |
| 1968 |
static PyObject * LinTable_mul(LinTable *self, PyObject *arg) { TABLE_MUL }; |
| 1969 |
static PyObject * LinTable_div(LinTable *self, PyObject *arg) { TABLE_DIV }; |
| 1970 |
|
| 1971 |
static PyObject * |
| 1972 |
LinTable_setSize(LinTable *self, PyObject *value) |
| 1973 |
{ |
| 1974 |
TABLE_SET_SIZE_WITH_POINT_LIST |
| 1975 |
|
| 1976 |
LinTable_generate(self); |
| 1977 |
|
| 1978 |
Py_RETURN_NONE; |
| 1979 |
} |
| 1980 |
|
| 1981 |
static PyObject * |
| 1982 |
LinTable_getSize(LinTable *self) |
| 1983 |
{ |
| 1984 |
return PyLong_FromLong(self->size); |
| 1985 |
}; |
| 1986 |
|
| 1987 |
static PyObject * |
| 1988 |
LinTable_getPoints(LinTable *self) |
| 1989 |
{ |
| 1990 |
Py_INCREF(self->pointslist); |
| 1991 |
return self->pointslist; |
| 1992 |
}; |
| 1993 |
|
| 1994 |
static PyObject * |
| 1995 |
LinTable_replace(LinTable *self, PyObject *value) |
| 1996 |
{ |
| 1997 |
if (value == NULL) |
| 1998 |
{ |
| 1999 |
PyErr_SetString(PyExc_TypeError, "Cannot delete the list attribute."); |
| 2000 |
return PyLong_FromLong(-1); |
| 2001 |
} |
| 2002 |
|
| 2003 |
if (! PyList_Check(value)) |
| 2004 |
{ |
| 2005 |
PyErr_SetString(PyExc_TypeError, "The amplitude list attribute value must be a list of tuples."); |
| 2006 |
return PyLong_FromLong(-1); |
| 2007 |
} |
| 2008 |
|
| 2009 |
Py_INCREF(value); |
| 2010 |
Py_DECREF(self->pointslist); |
| 2011 |
self->pointslist = value; |
| 2012 |
|
| 2013 |
LinTable_generate(self); |
| 2014 |
|
| 2015 |
Py_RETURN_NONE; |
| 2016 |
} |
| 2017 |
|
| 2018 |
static PyMemberDef LinTable_members[] = |
| 2019 |
{ |
| 2020 |
{"server", T_OBJECT_EX, offsetof(LinTable, server), 0, "Pyo server."}, |
| 2021 |
{"tablestream", T_OBJECT_EX, offsetof(LinTable, tablestream), 0, "Table stream object."}, |
| 2022 |
{"pointslist", T_OBJECT_EX, offsetof(LinTable, pointslist), 0, "Harmonics amplitude values."}, |
| 2023 |
{NULL} /* Sentinel */ |
| 2024 |
}; |
| 2025 |
|
| 2026 |
static PyMethodDef LinTable_methods[] = |
| 2027 |
{ |
| 2028 |
{"getServer", (PyCFunction)LinTable_getServer, METH_NOARGS, "Returns server object."}, |
| 2029 |
{"copy", (PyCFunction)LinTable_copy, METH_O, "Copy data from table given in argument."}, |
| 2030 |
{"copyData", (PyCFunction)LinTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 2031 |
{"rotate", (PyCFunction)LinTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 2032 |
{"setTable", (PyCFunction)LinTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 2033 |
{"getTable", (PyCFunction)LinTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 2034 |
{"getViewTable", (PyCFunction)LinTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 2035 |
{"getTableStream", (PyCFunction)LinTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 2036 |
{"setData", (PyCFunction)LinTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 2037 |
{"normalize", (PyCFunction)LinTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table samples"}, |
| 2038 |
{"reset", (PyCFunction)LinTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 2039 |
{"removeDC", (PyCFunction)LinTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 2040 |
{"reverse", (PyCFunction)LinTable_reverse, METH_NOARGS, "Reverse the table's data."}, |
| 2041 |
{"invert", (PyCFunction)LinTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 2042 |
{"rectify", (PyCFunction)LinTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 2043 |
{"bipolarGain", (PyCFunction)LinTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 2044 |
{"lowpass", (PyCFunction)LinTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 2045 |
{"fadein", (PyCFunction)LinTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 2046 |
{"fadeout", (PyCFunction)LinTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 2047 |
{"pow", (PyCFunction)LinTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 2048 |
{"setSize", (PyCFunction)LinTable_setSize, METH_O, "Sets the size of the table in samples"}, |
| 2049 |
{"getSize", (PyCFunction)LinTable_getSize, METH_NOARGS, "Return the size of the table in samples"}, |
| 2050 |
{"getRate", (PyCFunction)LinTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the table without pitch transposition."}, |
| 2051 |
{"put", (PyCFunction)LinTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 2052 |
{"get", (PyCFunction)LinTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 2053 |
{"getPoints", (PyCFunction)LinTable_getPoints, METH_NOARGS, "Return the list of points."}, |
| 2054 |
{"replace", (PyCFunction)LinTable_replace, METH_O, "Sets the harmonics amplitude list and generates a new waveform table."}, |
| 2055 |
{"add", (PyCFunction)LinTable_add, METH_O, "Performs table addition."}, |
| 2056 |
{"sub", (PyCFunction)LinTable_sub, METH_O, "Performs table substraction."}, |
| 2057 |
{"mul", (PyCFunction)LinTable_mul, METH_O, "Performs table multiplication."}, |
| 2058 |
{"div", (PyCFunction)LinTable_div, METH_O, "Performs table division."}, |
| 2059 |
{NULL} /* Sentinel */ |
| 2060 |
}; |
| 2061 |
|
| 2062 |
PyTypeObject LinTableType = |
| 2063 |
{ |
| 2064 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 2065 |
"_pyo.LinTable_base", /*tp_name*/ |
| 2066 |
sizeof(LinTable), /*tp_basicsize*/ |
| 2067 |
0, /*tp_itemsize*/ |
| 2068 |
(destructor)LinTable_dealloc, /*tp_dealloc*/ |
| 2069 |
0, /*tp_print*/ |
| 2070 |
0, /*tp_getattr*/ |
| 2071 |
0, /*tp_setattr*/ |
| 2072 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 2073 |
0, /*tp_repr*/ |
| 2074 |
0, /*tp_as_number*/ |
| 2075 |
0, /*tp_as_sequence*/ |
| 2076 |
0, /*tp_as_mapping*/ |
| 2077 |
0, /*tp_hash */ |
| 2078 |
0, /*tp_call*/ |
| 2079 |
0, /*tp_str*/ |
| 2080 |
0, /*tp_getattro*/ |
| 2081 |
0, /*tp_setattro*/ |
| 2082 |
0, /*tp_as_buffer*/ |
| 2083 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 2084 |
"LinTable objects. Generates a table filled with one or more straight lines.", /* tp_doc */ |
| 2085 |
(traverseproc)LinTable_traverse, /* tp_traverse */ |
| 2086 |
(inquiry)LinTable_clear, /* tp_clear */ |
| 2087 |
0, /* tp_richcompare */ |
| 2088 |
0, /* tp_weaklistoffset */ |
| 2089 |
0, /* tp_iter */ |
| 2090 |
0, /* tp_iternext */ |
| 2091 |
LinTable_methods, /* tp_methods */ |
| 2092 |
LinTable_members, /* tp_members */ |
| 2093 |
0, /* tp_getset */ |
| 2094 |
0, /* tp_base */ |
| 2095 |
0, /* tp_dict */ |
| 2096 |
0, /* tp_descr_get */ |
| 2097 |
0, /* tp_descr_set */ |
| 2098 |
0, /* tp_dictoffset */ |
| 2099 |
0, /* tp_init */ |
| 2100 |
0, /* tp_alloc */ |
| 2101 |
LinTable_new, /* tp_new */ |
| 2102 |
}; |
| 2103 |
|
| 2104 |
/***********************/ |
| 2105 |
/* LogTable structure */ |
| 2106 |
/***********************/ |
| 2107 |
typedef struct |
| 2108 |
{ |
| 2109 |
pyo_table_HEAD |
| 2110 |
PyObject *pointslist; |
| 2111 |
} LogTable; |
| 2112 |
|
| 2113 |
static void |
| 2114 |
LogTable_generate(LogTable *self) |
| 2115 |
{ |
| 2116 |
T_SIZE_T i, j, steps; |
| 2117 |
T_SIZE_T listsize; |
| 2118 |
PyObject *tup, *tup2; |
| 2119 |
T_SIZE_T x1, y1; |
| 2120 |
MYFLT x2, y2, diff, range, logrange, logmin, ratio, low, high; |
| 2121 |
|
| 2122 |
y1 = 0; |
| 2123 |
y2 = 0.0; |
| 2124 |
|
| 2125 |
listsize = PyList_Size(self->pointslist); |
| 2126 |
|
| 2127 |
if (listsize < 2) |
| 2128 |
{ |
| 2129 |
PySys_WriteStderr("LogTable error: There should be at least two points in a LogTable.\n"); |
| 2130 |
return; |
| 2131 |
} |
| 2132 |
|
| 2133 |
for (i = 0; i < (listsize - 1); i++) |
| 2134 |
{ |
| 2135 |
tup = PyList_GET_ITEM(self->pointslist, i); |
| 2136 |
PyObject *p1 = PyTuple_GET_ITEM(tup, 0); |
| 2137 |
x1 = PyLong_AsLong(PyNumber_Long(p1)); |
| 2138 |
x2 = PyFloat_AsDouble(PyTuple_GET_ITEM(tup, 1)); |
| 2139 |
tup2 = PyList_GET_ITEM(self->pointslist, i + 1); |
| 2140 |
PyObject *p2 = PyTuple_GET_ITEM(tup2, 0); |
| 2141 |
y1 = PyLong_AsLong(PyNumber_Long(p2)); |
| 2142 |
y2 = PyFloat_AsDouble(PyTuple_GET_ITEM(tup2, 1)); |
| 2143 |
|
| 2144 |
Py_DECREF(p1); |
| 2145 |
Py_DECREF(p2); |
| 2146 |
|
| 2147 |
if (x2 <= 0) |
| 2148 |
x2 = 0.000001; |
| 2149 |
|
| 2150 |
if (y2 <= 0) |
| 2151 |
y2 = 0.000001; |
| 2152 |
|
| 2153 |
if (x2 > y2) |
| 2154 |
{ |
| 2155 |
low = y2; |
| 2156 |
high = x2; |
| 2157 |
} |
| 2158 |
else |
| 2159 |
{ |
| 2160 |
low = x2; |
| 2161 |
high = y2; |
| 2162 |
} |
| 2163 |
|
| 2164 |
steps = y1 - x1; |
| 2165 |
|
| 2166 |
if (steps <= 0) |
| 2167 |
{ |
| 2168 |
PySys_WriteStderr("LogTable error: point position smaller than previous one.\n"); |
| 2169 |
return; |
| 2170 |
} |
| 2171 |
|
| 2172 |
range = high - low; |
| 2173 |
logrange = MYLOG10(high) - MYLOG10(low); |
| 2174 |
logmin = MYLOG10(low); |
| 2175 |
|
| 2176 |
if (range == 0) |
| 2177 |
{ |
| 2178 |
for (j = 0; j < steps; j++) |
| 2179 |
{ |
| 2180 |
self->data[x1 + j] = x2; |
| 2181 |
} |
| 2182 |
} |
| 2183 |
else |
| 2184 |
{ |
| 2185 |
diff = (y2 - x2) / steps; |
| 2186 |
|
| 2187 |
for (j = 0; j < steps; j++) |
| 2188 |
{ |
| 2189 |
ratio = ((x2 + diff * j) - low) / range; |
| 2190 |
self->data[x1 + j] = MYPOW(10, ratio * logrange + logmin); |
| 2191 |
} |
| 2192 |
} |
| 2193 |
} |
| 2194 |
|
| 2195 |
if (y1 < (self->size - 1)) |
| 2196 |
{ |
| 2197 |
self->data[y1] = y2; |
| 2198 |
|
| 2199 |
for (i = y1; i < self->size; i++) |
| 2200 |
{ |
| 2201 |
self->data[i + 1] = 0.0; |
| 2202 |
} |
| 2203 |
|
| 2204 |
self->data[self->size] = 0.0; |
| 2205 |
} |
| 2206 |
else |
| 2207 |
{ |
| 2208 |
self->data[self->size - 1] = y2; |
| 2209 |
self->data[self->size] = y2; |
| 2210 |
} |
| 2211 |
} |
| 2212 |
|
| 2213 |
static int |
| 2214 |
LogTable_traverse(LogTable *self, visitproc visit, void *arg) |
| 2215 |
{ |
| 2216 |
pyo_table_VISIT |
| 2217 |
Py_VISIT(self->pointslist); |
| 2218 |
return 0; |
| 2219 |
} |
| 2220 |
|
| 2221 |
static int |
| 2222 |
LogTable_clear(LogTable *self) |
| 2223 |
{ |
| 2224 |
pyo_table_CLEAR |
| 2225 |
Py_CLEAR(self->pointslist); |
| 2226 |
return 0; |
| 2227 |
} |
| 2228 |
|
| 2229 |
static void |
| 2230 |
LogTable_dealloc(LogTable* self) |
| 2231 |
{ |
| 2232 |
PyMem_RawFree(self->data); |
| 2233 |
LogTable_clear(self); |
| 2234 |
Py_TYPE(self->tablestream)->tp_free((PyObject*)self->tablestream); |
| 2235 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 2236 |
} |
| 2237 |
|
| 2238 |
static PyObject * |
| 2239 |
LogTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 2240 |
{ |
| 2241 |
PyObject *pointslist = NULL; |
| 2242 |
LogTable *self; |
| 2243 |
self = (LogTable *)type->tp_alloc(type, 0); |
| 2244 |
|
| 2245 |
self->server = PyServer_get_server(); |
| 2246 |
Py_INCREF(self->server); |
| 2247 |
|
| 2248 |
self->pointslist = PyList_New(0); |
| 2249 |
self->size = 8192; |
| 2250 |
|
| 2251 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 2252 |
|
| 2253 |
static char *kwlist[] = {"list", "size", NULL}; |
| 2254 |
|
| 2255 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|On", kwlist, &pointslist, &self->size)) |
| 2256 |
Py_RETURN_NONE; |
| 2257 |
|
| 2258 |
if (pointslist) |
| 2259 |
{ |
| 2260 |
Py_INCREF(pointslist); |
| 2261 |
Py_DECREF(self->pointslist); |
| 2262 |
self->pointslist = pointslist; |
| 2263 |
} |
| 2264 |
else |
| 2265 |
{ |
| 2266 |
PyList_Append(self->pointslist, PyTuple_Pack(2, PyLong_FromLong(0), PyFloat_FromDouble(0.))); |
| 2267 |
PyList_Append(self->pointslist, PyTuple_Pack(2, PyLong_FromLong(self->size), PyFloat_FromDouble(1.))); |
| 2268 |
} |
| 2269 |
|
| 2270 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 2271 |
TableStream_setSize(self->tablestream, self->size); |
| 2272 |
TableStream_setData(self->tablestream, self->data); |
| 2273 |
LogTable_generate(self); |
| 2274 |
|
| 2275 |
PyObject *srobj = PyObject_CallMethod(self->server, "getSamplingRate", NULL); |
| 2276 |
double sr = PyFloat_AsDouble(srobj); |
| 2277 |
Py_DECREF(srobj); |
| 2278 |
|
| 2279 |
TableStream_setSamplingRate(self->tablestream, sr); |
| 2280 |
|
| 2281 |
return (PyObject *)self; |
| 2282 |
} |
| 2283 |
|
| 2284 |
static PyObject * LogTable_getServer(LogTable* self) { GET_SERVER }; |
| 2285 |
static PyObject * LogTable_getTableStream(LogTable* self) { GET_TABLE_STREAM }; |
| 2286 |
static PyObject * LogTable_setData(LogTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 2287 |
static PyObject * LogTable_normalize(LogTable *self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 2288 |
static PyObject * LogTable_reset(LogTable *self) { TABLE_RESET }; |
| 2289 |
static PyObject * LogTable_removeDC(LogTable *self) { REMOVE_DC }; |
| 2290 |
static PyObject * LogTable_reverse(LogTable *self) { REVERSE }; |
| 2291 |
static PyObject * LogTable_invert(LogTable *self) { INVERT }; |
| 2292 |
static PyObject * LogTable_rectify(LogTable *self) { RECTIFY }; |
| 2293 |
static PyObject * LogTable_bipolarGain(LogTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 2294 |
static PyObject * LogTable_lowpass(LogTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 2295 |
static PyObject * LogTable_fadein(LogTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 2296 |
static PyObject * LogTable_fadeout(LogTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 2297 |
static PyObject * LogTable_pow(LogTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 2298 |
static PyObject * LogTable_copy(LogTable *self, PyObject *arg) { COPY }; |
| 2299 |
static PyObject * LogTable_copyData(LogTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 2300 |
static PyObject * LogTable_rotate(LogTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 2301 |
static PyObject * LogTable_setTable(LogTable *self, PyObject *arg) { SET_TABLE }; |
| 2302 |
static PyObject * LogTable_getTable(LogTable *self) { GET_TABLE }; |
| 2303 |
static PyObject * LogTable_getRate(LogTable *self) { TABLE_GET_RATE }; |
| 2304 |
static PyObject * LogTable_getViewTable(LogTable *self, PyObject *args, PyObject *kwds) { GET_VIEW_TABLE }; |
| 2305 |
static PyObject * LogTable_put(LogTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 2306 |
static PyObject * LogTable_get(LogTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 2307 |
static PyObject * LogTable_add(LogTable *self, PyObject *arg) { TABLE_ADD }; |
| 2308 |
static PyObject * LogTable_sub(LogTable *self, PyObject *arg) { TABLE_SUB }; |
| 2309 |
static PyObject * LogTable_mul(LogTable *self, PyObject *arg) { TABLE_MUL }; |
| 2310 |
static PyObject * LogTable_div(LogTable *self, PyObject *arg) { TABLE_DIV }; |
| 2311 |
|
| 2312 |
static PyObject * |
| 2313 |
LogTable_setSize(LogTable *self, PyObject *value) |
| 2314 |
{ |
| 2315 |
TABLE_SET_SIZE_WITH_POINT_LIST |
| 2316 |
|
| 2317 |
LogTable_generate(self); |
| 2318 |
|
| 2319 |
Py_RETURN_NONE; |
| 2320 |
} |
| 2321 |
|
| 2322 |
static PyObject * |
| 2323 |
LogTable_getSize(LogTable *self) |
| 2324 |
{ |
| 2325 |
return PyLong_FromLong(self->size); |
| 2326 |
}; |
| 2327 |
|
| 2328 |
static PyObject * |
| 2329 |
LogTable_getPoints(LogTable *self) |
| 2330 |
{ |
| 2331 |
Py_INCREF(self->pointslist); |
| 2332 |
return self->pointslist; |
| 2333 |
}; |
| 2334 |
|
| 2335 |
static PyObject * |
| 2336 |
LogTable_replace(LogTable *self, PyObject *value) |
| 2337 |
{ |
| 2338 |
if (value == NULL) |
| 2339 |
{ |
| 2340 |
PyErr_SetString(PyExc_TypeError, "Cannot delete the list attribute."); |
| 2341 |
return PyLong_FromLong(-1); |
| 2342 |
} |
| 2343 |
|
| 2344 |
if (! PyList_Check(value)) |
| 2345 |
{ |
| 2346 |
PyErr_SetString(PyExc_TypeError, "The amplitude list attribute value must be a list of tuples."); |
| 2347 |
return PyLong_FromLong(-1); |
| 2348 |
} |
| 2349 |
|
| 2350 |
Py_INCREF(value); |
| 2351 |
Py_DECREF(self->pointslist); |
| 2352 |
self->pointslist = value; |
| 2353 |
|
| 2354 |
LogTable_generate(self); |
| 2355 |
|
| 2356 |
Py_RETURN_NONE; |
| 2357 |
} |
| 2358 |
|
| 2359 |
static PyMemberDef LogTable_members[] = |
| 2360 |
{ |
| 2361 |
{"server", T_OBJECT_EX, offsetof(LogTable, server), 0, "Pyo server."}, |
| 2362 |
{"tablestream", T_OBJECT_EX, offsetof(LogTable, tablestream), 0, "Table stream object."}, |
| 2363 |
{"pointslist", T_OBJECT_EX, offsetof(LogTable, pointslist), 0, "Harmonics amplitude values."}, |
| 2364 |
{NULL} /* Sentinel */ |
| 2365 |
}; |
| 2366 |
|
| 2367 |
static PyMethodDef LogTable_methods[] = |
| 2368 |
{ |
| 2369 |
{"getServer", (PyCFunction)LogTable_getServer, METH_NOARGS, "Returns server object."}, |
| 2370 |
{"copy", (PyCFunction)LogTable_copy, METH_O, "Copy data from table given in argument."}, |
| 2371 |
{"copyData", (PyCFunction)LogTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 2372 |
{"rotate", (PyCFunction)LogTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 2373 |
{"setTable", (PyCFunction)LogTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 2374 |
{"getTable", (PyCFunction)LogTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 2375 |
{"getViewTable", (PyCFunction)LogTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 2376 |
{"getTableStream", (PyCFunction)LogTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 2377 |
{"setData", (PyCFunction)LogTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 2378 |
{"normalize", (PyCFunction)LogTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table samples"}, |
| 2379 |
{"reset", (PyCFunction)LogTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 2380 |
{"removeDC", (PyCFunction)LogTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 2381 |
{"reverse", (PyCFunction)LogTable_reverse, METH_NOARGS, "Reverse the table's data."}, |
| 2382 |
{"invert", (PyCFunction)LogTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 2383 |
{"rectify", (PyCFunction)LogTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 2384 |
{"bipolarGain", (PyCFunction)LogTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 2385 |
{"lowpass", (PyCFunction)LogTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 2386 |
{"fadein", (PyCFunction)LogTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 2387 |
{"fadeout", (PyCFunction)LogTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 2388 |
{"pow", (PyCFunction)LogTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 2389 |
{"setSize", (PyCFunction)LogTable_setSize, METH_O, "Sets the size of the table in samples"}, |
| 2390 |
{"getSize", (PyCFunction)LogTable_getSize, METH_NOARGS, "Return the size of the table in samples"}, |
| 2391 |
{"getRate", (PyCFunction)LogTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the table without pitch transposition."}, |
| 2392 |
{"put", (PyCFunction)LogTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 2393 |
{"get", (PyCFunction)LogTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 2394 |
{"getPoints", (PyCFunction)LogTable_getPoints, METH_NOARGS, "Return the list of points."}, |
| 2395 |
{"replace", (PyCFunction)LogTable_replace, METH_O, "Sets the harmonics amplitude list and generates a new waveform table."}, |
| 2396 |
{"add", (PyCFunction)LogTable_add, METH_O, "Performs table addition."}, |
| 2397 |
{"sub", (PyCFunction)LogTable_sub, METH_O, "Performs table substraction."}, |
| 2398 |
{"mul", (PyCFunction)LogTable_mul, METH_O, "Performs table multiplication."}, |
| 2399 |
{"div", (PyCFunction)LogTable_div, METH_O, "Performs table division."}, |
| 2400 |
{NULL} /* Sentinel */ |
| 2401 |
}; |
| 2402 |
|
| 2403 |
PyTypeObject LogTableType = |
| 2404 |
{ |
| 2405 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 2406 |
"_pyo.LogTable_base", /*tp_name*/ |
| 2407 |
sizeof(LogTable), /*tp_basicsize*/ |
| 2408 |
0, /*tp_itemsize*/ |
| 2409 |
(destructor)LogTable_dealloc, /*tp_dealloc*/ |
| 2410 |
0, /*tp_print*/ |
| 2411 |
0, /*tp_getattr*/ |
| 2412 |
0, /*tp_setattr*/ |
| 2413 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 2414 |
0, /*tp_repr*/ |
| 2415 |
0, /*tp_as_number*/ |
| 2416 |
0, /*tp_as_sequence*/ |
| 2417 |
0, /*tp_as_mapping*/ |
| 2418 |
0, /*tp_hash */ |
| 2419 |
0, /*tp_call*/ |
| 2420 |
0, /*tp_str*/ |
| 2421 |
0, /*tp_getattro*/ |
| 2422 |
0, /*tp_setattro*/ |
| 2423 |
0, /*tp_as_buffer*/ |
| 2424 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 2425 |
"LogTable objects. Generates a table filled with one or more logarothmic lines.", /* tp_doc */ |
| 2426 |
(traverseproc)LogTable_traverse, /* tp_traverse */ |
| 2427 |
(inquiry)LogTable_clear, /* tp_clear */ |
| 2428 |
0, /* tp_richcompare */ |
| 2429 |
0, /* tp_weaklistoffset */ |
| 2430 |
0, /* tp_iter */ |
| 2431 |
0, /* tp_iternext */ |
| 2432 |
LogTable_methods, /* tp_methods */ |
| 2433 |
LogTable_members, /* tp_members */ |
| 2434 |
0, /* tp_getset */ |
| 2435 |
0, /* tp_base */ |
| 2436 |
0, /* tp_dict */ |
| 2437 |
0, /* tp_descr_get */ |
| 2438 |
0, /* tp_descr_set */ |
| 2439 |
0, /* tp_dictoffset */ |
| 2440 |
0, /* tp_init */ |
| 2441 |
0, /* tp_alloc */ |
| 2442 |
LogTable_new, /* tp_new */ |
| 2443 |
}; |
| 2444 |
|
| 2445 |
/***********************/ |
| 2446 |
/* CosTable structure */ |
| 2447 |
/***********************/ |
| 2448 |
typedef struct |
| 2449 |
{ |
| 2450 |
pyo_table_HEAD |
| 2451 |
PyObject *pointslist; |
| 2452 |
} CosTable; |
| 2453 |
|
| 2454 |
static void |
| 2455 |
CosTable_generate(CosTable *self) |
| 2456 |
{ |
| 2457 |
T_SIZE_T i, j, steps; |
| 2458 |
T_SIZE_T listsize; |
| 2459 |
PyObject *tup, *tup2; |
| 2460 |
T_SIZE_T x1, y1; |
| 2461 |
MYFLT x2, y2, mu, mu2; |
| 2462 |
|
| 2463 |
y1 = 0; |
| 2464 |
y2 = 0.0; |
| 2465 |
|
| 2466 |
listsize = PyList_Size(self->pointslist); |
| 2467 |
|
| 2468 |
if (listsize < 2) |
| 2469 |
{ |
| 2470 |
PySys_WriteStderr("CosTable error: There should be at least two points in a CosTable.\n"); |
| 2471 |
return; |
| 2472 |
} |
| 2473 |
|
| 2474 |
for (i = 0; i < (listsize - 1); i++) |
| 2475 |
{ |
| 2476 |
tup = PyList_GET_ITEM(self->pointslist, i); |
| 2477 |
PyObject *p1 = PyTuple_GET_ITEM(tup, 0); |
| 2478 |
x1 = PyLong_AsLong(PyNumber_Long(p1)); |
| 2479 |
x2 = PyFloat_AsDouble(PyTuple_GET_ITEM(tup, 1)); |
| 2480 |
tup2 = PyList_GET_ITEM(self->pointslist, i + 1); |
| 2481 |
PyObject *p2 = PyTuple_GET_ITEM(tup2, 0); |
| 2482 |
y1 = PyLong_AsLong(PyNumber_Long(p2)); |
| 2483 |
y2 = PyFloat_AsDouble(PyTuple_GET_ITEM(tup2, 1)); |
| 2484 |
|
| 2485 |
Py_DECREF(p1); |
| 2486 |
Py_DECREF(p2); |
| 2487 |
|
| 2488 |
steps = y1 - x1; |
| 2489 |
|
| 2490 |
if (steps <= 0) |
| 2491 |
{ |
| 2492 |
PySys_WriteStderr("CosTable error: point position smaller than previous one.\n"); |
| 2493 |
return; |
| 2494 |
} |
| 2495 |
|
| 2496 |
for (j = 0; j < steps; j++) |
| 2497 |
{ |
| 2498 |
mu = (MYFLT)j / steps; |
| 2499 |
mu2 = (1.0 - MYCOS(mu * PI)) / 2.0; |
| 2500 |
self->data[x1 + j] = x2 * (1.0 - mu2) + y2 * mu2; |
| 2501 |
} |
| 2502 |
} |
| 2503 |
|
| 2504 |
if (y1 < (self->size - 1)) |
| 2505 |
{ |
| 2506 |
self->data[y1] = y2; |
| 2507 |
|
| 2508 |
for (i = y1; i < self->size; i++) |
| 2509 |
{ |
| 2510 |
self->data[i + 1] = 0.0; |
| 2511 |
} |
| 2512 |
|
| 2513 |
self->data[self->size] = 0.0; |
| 2514 |
} |
| 2515 |
else |
| 2516 |
{ |
| 2517 |
self->data[self->size - 1] = y2; |
| 2518 |
self->data[self->size] = y2; |
| 2519 |
} |
| 2520 |
} |
| 2521 |
|
| 2522 |
static int |
| 2523 |
CosTable_traverse(CosTable *self, visitproc visit, void *arg) |
| 2524 |
{ |
| 2525 |
pyo_table_VISIT |
| 2526 |
Py_VISIT(self->pointslist); |
| 2527 |
return 0; |
| 2528 |
} |
| 2529 |
|
| 2530 |
static int |
| 2531 |
CosTable_clear(CosTable *self) |
| 2532 |
{ |
| 2533 |
pyo_table_CLEAR |
| 2534 |
Py_CLEAR(self->pointslist); |
| 2535 |
return 0; |
| 2536 |
} |
| 2537 |
|
| 2538 |
static void |
| 2539 |
CosTable_dealloc(CosTable* self) |
| 2540 |
{ |
| 2541 |
PyMem_RawFree(self->data); |
| 2542 |
CosTable_clear(self); |
| 2543 |
Py_TYPE(self->tablestream)->tp_free((PyObject*)self->tablestream); |
| 2544 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 2545 |
} |
| 2546 |
|
| 2547 |
static PyObject * |
| 2548 |
CosTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 2549 |
{ |
| 2550 |
PyObject *pointslist = NULL; |
| 2551 |
CosTable *self; |
| 2552 |
self = (CosTable *)type->tp_alloc(type, 0); |
| 2553 |
|
| 2554 |
self->server = PyServer_get_server(); |
| 2555 |
Py_INCREF(self->server); |
| 2556 |
|
| 2557 |
self->pointslist = PyList_New(0); |
| 2558 |
self->size = 8192; |
| 2559 |
|
| 2560 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 2561 |
|
| 2562 |
static char *kwlist[] = {"list", "size", NULL}; |
| 2563 |
|
| 2564 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|On", kwlist, &pointslist, &self->size)) |
| 2565 |
Py_RETURN_NONE; |
| 2566 |
|
| 2567 |
if (pointslist) |
| 2568 |
{ |
| 2569 |
Py_INCREF(pointslist); |
| 2570 |
Py_DECREF(self->pointslist); |
| 2571 |
self->pointslist = pointslist; |
| 2572 |
} |
| 2573 |
else |
| 2574 |
{ |
| 2575 |
PyList_Append(self->pointslist, PyTuple_Pack(2, PyLong_FromLong(0), PyFloat_FromDouble(0.))); |
| 2576 |
PyList_Append(self->pointslist, PyTuple_Pack(2, PyLong_FromLong(self->size), PyFloat_FromDouble(1.))); |
| 2577 |
} |
| 2578 |
|
| 2579 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 2580 |
TableStream_setSize(self->tablestream, self->size); |
| 2581 |
TableStream_setData(self->tablestream, self->data); |
| 2582 |
CosTable_generate(self); |
| 2583 |
|
| 2584 |
PyObject *srobj = PyObject_CallMethod(self->server, "getSamplingRate", NULL); |
| 2585 |
double sr = PyFloat_AsDouble(srobj); |
| 2586 |
Py_DECREF(srobj); |
| 2587 |
|
| 2588 |
TableStream_setSamplingRate(self->tablestream, sr); |
| 2589 |
|
| 2590 |
return (PyObject *)self; |
| 2591 |
} |
| 2592 |
|
| 2593 |
static PyObject * CosTable_getServer(CosTable* self) { GET_SERVER }; |
| 2594 |
static PyObject * CosTable_getTableStream(CosTable* self) { GET_TABLE_STREAM }; |
| 2595 |
static PyObject * CosTable_setData(CosTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 2596 |
static PyObject * CosTable_normalize(CosTable *self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 2597 |
static PyObject * CosTable_reset(CosTable *self) { TABLE_RESET }; |
| 2598 |
static PyObject * CosTable_removeDC(CosTable *self) { REMOVE_DC }; |
| 2599 |
static PyObject * CosTable_reverse(CosTable *self) { REVERSE }; |
| 2600 |
static PyObject * CosTable_invert(CosTable *self) { INVERT }; |
| 2601 |
static PyObject * CosTable_rectify(CosTable *self) { RECTIFY }; |
| 2602 |
static PyObject * CosTable_bipolarGain(CosTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 2603 |
static PyObject * CosTable_lowpass(CosTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 2604 |
static PyObject * CosTable_fadein(CosTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 2605 |
static PyObject * CosTable_fadeout(CosTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 2606 |
static PyObject * CosTable_pow(CosTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 2607 |
static PyObject * CosTable_copy(CosTable *self, PyObject *arg) { COPY }; |
| 2608 |
static PyObject * CosTable_copyData(CosTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 2609 |
static PyObject * CosTable_rotate(CosTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 2610 |
static PyObject * CosTable_setTable(CosTable *self, PyObject *arg) { SET_TABLE }; |
| 2611 |
static PyObject * CosTable_getTable(CosTable *self) { GET_TABLE }; |
| 2612 |
static PyObject * CosTable_getRate(CosTable *self) { TABLE_GET_RATE }; |
| 2613 |
static PyObject * CosTable_getViewTable(CosTable *self, PyObject *args, PyObject *kwds) { GET_VIEW_TABLE }; |
| 2614 |
static PyObject * CosTable_put(CosTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 2615 |
static PyObject * CosTable_get(CosTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 2616 |
static PyObject * CosTable_add(CosTable *self, PyObject *arg) { TABLE_ADD }; |
| 2617 |
static PyObject * CosTable_sub(CosTable *self, PyObject *arg) { TABLE_SUB }; |
| 2618 |
static PyObject * CosTable_mul(CosTable *self, PyObject *arg) { TABLE_MUL }; |
| 2619 |
static PyObject * CosTable_div(CosTable *self, PyObject *arg) { TABLE_DIV }; |
| 2620 |
|
| 2621 |
static PyObject * |
| 2622 |
CosTable_setSize(CosTable *self, PyObject *value) |
| 2623 |
{ |
| 2624 |
TABLE_SET_SIZE_WITH_POINT_LIST |
| 2625 |
|
| 2626 |
CosTable_generate(self); |
| 2627 |
|
| 2628 |
Py_RETURN_NONE; |
| 2629 |
} |
| 2630 |
|
| 2631 |
static PyObject * |
| 2632 |
CosTable_getSize(CosTable *self) |
| 2633 |
{ |
| 2634 |
return PyLong_FromLong(self->size); |
| 2635 |
}; |
| 2636 |
|
| 2637 |
static PyObject * |
| 2638 |
CosTable_getPoints(CosTable *self) |
| 2639 |
{ |
| 2640 |
Py_INCREF(self->pointslist); |
| 2641 |
return self->pointslist; |
| 2642 |
}; |
| 2643 |
|
| 2644 |
static PyObject * |
| 2645 |
CosTable_replace(CosTable *self, PyObject *value) |
| 2646 |
{ |
| 2647 |
if (value == NULL) |
| 2648 |
{ |
| 2649 |
PyErr_SetString(PyExc_TypeError, "Cannot delete the list attribute."); |
| 2650 |
return PyLong_FromLong(-1); |
| 2651 |
} |
| 2652 |
|
| 2653 |
if (! PyList_Check(value)) |
| 2654 |
{ |
| 2655 |
PyErr_SetString(PyExc_TypeError, "The amplitude list attribute value must be a list of tuples."); |
| 2656 |
return PyLong_FromLong(-1); |
| 2657 |
} |
| 2658 |
|
| 2659 |
Py_INCREF(value); |
| 2660 |
Py_DECREF(self->pointslist); |
| 2661 |
self->pointslist = value; |
| 2662 |
|
| 2663 |
CosTable_generate(self); |
| 2664 |
|
| 2665 |
Py_RETURN_NONE; |
| 2666 |
} |
| 2667 |
|
| 2668 |
static PyMemberDef CosTable_members[] = |
| 2669 |
{ |
| 2670 |
{"server", T_OBJECT_EX, offsetof(CosTable, server), 0, "Pyo server."}, |
| 2671 |
{"tablestream", T_OBJECT_EX, offsetof(CosTable, tablestream), 0, "Table stream object."}, |
| 2672 |
{"pointslist", T_OBJECT_EX, offsetof(CosTable, pointslist), 0, "Harmonics amplitude values."}, |
| 2673 |
{NULL} /* Sentinel */ |
| 2674 |
}; |
| 2675 |
|
| 2676 |
static PyMethodDef CosTable_methods[] = |
| 2677 |
{ |
| 2678 |
{"getServer", (PyCFunction)CosTable_getServer, METH_NOARGS, "Returns server object."}, |
| 2679 |
{"copy", (PyCFunction)CosTable_copy, METH_O, "Copy data from table given in argument."}, |
| 2680 |
{"copyData", (PyCFunction)CosTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 2681 |
{"rotate", (PyCFunction)CosTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 2682 |
{"setTable", (PyCFunction)CosTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 2683 |
{"getTable", (PyCFunction)CosTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 2684 |
{"getViewTable", (PyCFunction)CosTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 2685 |
{"getTableStream", (PyCFunction)CosTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 2686 |
{"setData", (PyCFunction)CosTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 2687 |
{"normalize", (PyCFunction)CosTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table samples"}, |
| 2688 |
{"reset", (PyCFunction)CosTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 2689 |
{"removeDC", (PyCFunction)CosTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 2690 |
{"reverse", (PyCFunction)CosTable_reverse, METH_NOARGS, "Reverse the table's data."}, |
| 2691 |
{"invert", (PyCFunction)CosTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 2692 |
{"rectify", (PyCFunction)CosTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 2693 |
{"bipolarGain", (PyCFunction)CosTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 2694 |
{"lowpass", (PyCFunction)CosTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 2695 |
{"fadein", (PyCFunction)CosTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 2696 |
{"fadeout", (PyCFunction)CosTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 2697 |
{"pow", (PyCFunction)CosTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 2698 |
{"setSize", (PyCFunction)CosTable_setSize, METH_O, "Sets the size of the table in samples"}, |
| 2699 |
{"getSize", (PyCFunction)CosTable_getSize, METH_NOARGS, "Return the size of the table in samples"}, |
| 2700 |
{"getRate", (PyCFunction)CosTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the table without pitch transposition."}, |
| 2701 |
{"put", (PyCFunction)CosTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 2702 |
{"get", (PyCFunction)CosTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 2703 |
{"getPoints", (PyCFunction)CosTable_getPoints, METH_NOARGS, "Return the list of points."}, |
| 2704 |
{"replace", (PyCFunction)CosTable_replace, METH_O, "Sets the harmonics amplitude list and generates a new waveform table."}, |
| 2705 |
{"add", (PyCFunction)CosTable_add, METH_O, "Performs table addition."}, |
| 2706 |
{"sub", (PyCFunction)CosTable_sub, METH_O, "Performs table substraction."}, |
| 2707 |
{"mul", (PyCFunction)CosTable_mul, METH_O, "Performs table multiplication."}, |
| 2708 |
{"div", (PyCFunction)CosTable_div, METH_O, "Performs table division."}, |
| 2709 |
{NULL} /* Sentinel */ |
| 2710 |
}; |
| 2711 |
|
| 2712 |
PyTypeObject CosTableType = |
| 2713 |
{ |
| 2714 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 2715 |
"_pyo.CosTable_base", /*tp_name*/ |
| 2716 |
sizeof(CosTable), /*tp_basicsize*/ |
| 2717 |
0, /*tp_itemsize*/ |
| 2718 |
(destructor)CosTable_dealloc, /*tp_dealloc*/ |
| 2719 |
0, /*tp_print*/ |
| 2720 |
0, /*tp_getattr*/ |
| 2721 |
0, /*tp_setattr*/ |
| 2722 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 2723 |
0, /*tp_repr*/ |
| 2724 |
0, /*tp_as_number*/ |
| 2725 |
0, /*tp_as_sequence*/ |
| 2726 |
0, /*tp_as_mapping*/ |
| 2727 |
0, /*tp_hash */ |
| 2728 |
0, /*tp_call*/ |
| 2729 |
0, /*tp_str*/ |
| 2730 |
0, /*tp_getattro*/ |
| 2731 |
0, /*tp_setattro*/ |
| 2732 |
0, /*tp_as_buffer*/ |
| 2733 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 2734 |
"CosTable objects. Generates a table filled with one or more straight lines.", /* tp_doc */ |
| 2735 |
(traverseproc)CosTable_traverse, /* tp_traverse */ |
| 2736 |
(inquiry)CosTable_clear, /* tp_clear */ |
| 2737 |
0, /* tp_richcompare */ |
| 2738 |
0, /* tp_weaklistoffset */ |
| 2739 |
0, /* tp_iter */ |
| 2740 |
0, /* tp_iternext */ |
| 2741 |
CosTable_methods, /* tp_methods */ |
| 2742 |
CosTable_members, /* tp_members */ |
| 2743 |
0, /* tp_getset */ |
| 2744 |
0, /* tp_base */ |
| 2745 |
0, /* tp_dict */ |
| 2746 |
0, /* tp_descr_get */ |
| 2747 |
0, /* tp_descr_set */ |
| 2748 |
0, /* tp_dictoffset */ |
| 2749 |
0, /* tp_init */ |
| 2750 |
0, /* tp_alloc */ |
| 2751 |
CosTable_new, /* tp_new */ |
| 2752 |
}; |
| 2753 |
|
| 2754 |
/***********************/ |
| 2755 |
/* CosLogTable structure */ |
| 2756 |
/***********************/ |
| 2757 |
typedef struct |
| 2758 |
{ |
| 2759 |
pyo_table_HEAD |
| 2760 |
PyObject *pointslist; |
| 2761 |
} CosLogTable; |
| 2762 |
|
| 2763 |
static void |
| 2764 |
CosLogTable_generate(CosLogTable *self) |
| 2765 |
{ |
| 2766 |
T_SIZE_T i, j, steps; |
| 2767 |
T_SIZE_T listsize; |
| 2768 |
PyObject *tup, *tup2; |
| 2769 |
T_SIZE_T x1, y1; |
| 2770 |
MYFLT x2, y2, range, logrange, logmin, ratio, low, high, mu; |
| 2771 |
|
| 2772 |
y1 = 0; |
| 2773 |
y2 = 0.0; |
| 2774 |
|
| 2775 |
listsize = PyList_Size(self->pointslist); |
| 2776 |
|
| 2777 |
if (listsize < 2) |
| 2778 |
{ |
| 2779 |
PySys_WriteStderr("CosLogTable error: There should be at least two points in a CosLogTable.\n"); |
| 2780 |
return; |
| 2781 |
} |
| 2782 |
|
| 2783 |
for (i = 0; i < (listsize - 1); i++) |
| 2784 |
{ |
| 2785 |
tup = PyList_GET_ITEM(self->pointslist, i); |
| 2786 |
PyObject *p1 = PyTuple_GET_ITEM(tup, 0); |
| 2787 |
x1 = PyLong_AsLong(PyNumber_Long(p1)); |
| 2788 |
x2 = PyFloat_AsDouble(PyTuple_GET_ITEM(tup, 1)); |
| 2789 |
tup2 = PyList_GET_ITEM(self->pointslist, i + 1); |
| 2790 |
PyObject *p2 = PyTuple_GET_ITEM(tup2, 0); |
| 2791 |
y1 = PyLong_AsLong(PyNumber_Long(p2)); |
| 2792 |
y2 = PyFloat_AsDouble(PyTuple_GET_ITEM(tup2, 1)); |
| 2793 |
|
| 2794 |
Py_DECREF(p1); |
| 2795 |
Py_DECREF(p2); |
| 2796 |
|
| 2797 |
if (x2 <= 0) |
| 2798 |
x2 = 0.000001; |
| 2799 |
|
| 2800 |
if (y2 <= 0) |
| 2801 |
y2 = 0.000001; |
| 2802 |
|
| 2803 |
if (x2 > y2) |
| 2804 |
{ |
| 2805 |
low = y2; |
| 2806 |
high = x2; |
| 2807 |
} |
| 2808 |
else |
| 2809 |
{ |
| 2810 |
low = x2; |
| 2811 |
high = y2; |
| 2812 |
} |
| 2813 |
|
| 2814 |
steps = y1 - x1; |
| 2815 |
|
| 2816 |
if (steps <= 0) |
| 2817 |
{ |
| 2818 |
PySys_WriteStderr("CosLogTable error: point position smaller than previous one.\n"); |
| 2819 |
return; |
| 2820 |
} |
| 2821 |
|
| 2822 |
range = high - low; |
| 2823 |
logrange = MYLOG10(high) - MYLOG10(low); |
| 2824 |
logmin = MYLOG10(low); |
| 2825 |
|
| 2826 |
if (range == 0) |
| 2827 |
{ |
| 2828 |
for (j = 0; j < steps; j++) |
| 2829 |
{ |
| 2830 |
self->data[x1 + j] = x2; |
| 2831 |
} |
| 2832 |
} |
| 2833 |
else |
| 2834 |
{ |
| 2835 |
for (j = 0; j < steps; j++) |
| 2836 |
{ |
| 2837 |
mu = (MYFLT)j / steps; |
| 2838 |
mu = (1.0 - MYCOS(mu * PI)) * 0.5; |
| 2839 |
mu = x2 * (1.0 - mu) + y2 * mu; |
| 2840 |
ratio = (mu - low) / range; |
| 2841 |
self->data[x1 + j] = MYPOW(10, ratio * logrange + logmin); |
| 2842 |
} |
| 2843 |
} |
| 2844 |
} |
| 2845 |
|
| 2846 |
if (y1 < (self->size - 1)) |
| 2847 |
{ |
| 2848 |
self->data[y1] = y2; |
| 2849 |
|
| 2850 |
for (i = y1; i < self->size; i++) |
| 2851 |
{ |
| 2852 |
self->data[i + 1] = 0.0; |
| 2853 |
} |
| 2854 |
|
| 2855 |
self->data[self->size] = 0.0; |
| 2856 |
} |
| 2857 |
else |
| 2858 |
{ |
| 2859 |
self->data[self->size - 1] = y2; |
| 2860 |
self->data[self->size] = y2; |
| 2861 |
} |
| 2862 |
} |
| 2863 |
|
| 2864 |
static int |
| 2865 |
CosLogTable_traverse(CosLogTable *self, visitproc visit, void *arg) |
| 2866 |
{ |
| 2867 |
pyo_table_VISIT |
| 2868 |
Py_VISIT(self->pointslist); |
| 2869 |
return 0; |
| 2870 |
} |
| 2871 |
|
| 2872 |
static int |
| 2873 |
CosLogTable_clear(CosLogTable *self) |
| 2874 |
{ |
| 2875 |
pyo_table_CLEAR |
| 2876 |
Py_CLEAR(self->pointslist); |
| 2877 |
return 0; |
| 2878 |
} |
| 2879 |
|
| 2880 |
static void |
| 2881 |
CosLogTable_dealloc(CosLogTable* self) |
| 2882 |
{ |
| 2883 |
PyMem_RawFree(self->data); |
| 2884 |
CosLogTable_clear(self); |
| 2885 |
Py_TYPE(self->tablestream)->tp_free((PyObject*)self->tablestream); |
| 2886 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 2887 |
} |
| 2888 |
|
| 2889 |
static PyObject * |
| 2890 |
CosLogTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 2891 |
{ |
| 2892 |
PyObject *pointslist = NULL; |
| 2893 |
CosLogTable *self; |
| 2894 |
self = (CosLogTable *)type->tp_alloc(type, 0); |
| 2895 |
|
| 2896 |
self->server = PyServer_get_server(); |
| 2897 |
Py_INCREF(self->server); |
| 2898 |
|
| 2899 |
self->pointslist = PyList_New(0); |
| 2900 |
self->size = 8192; |
| 2901 |
|
| 2902 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 2903 |
|
| 2904 |
static char *kwlist[] = {"list", "size", NULL}; |
| 2905 |
|
| 2906 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|On", kwlist, &pointslist, &self->size)) |
| 2907 |
Py_RETURN_NONE; |
| 2908 |
|
| 2909 |
if (pointslist) |
| 2910 |
{ |
| 2911 |
Py_INCREF(pointslist); |
| 2912 |
Py_DECREF(self->pointslist); |
| 2913 |
self->pointslist = pointslist; |
| 2914 |
} |
| 2915 |
else |
| 2916 |
{ |
| 2917 |
PyList_Append(self->pointslist, PyTuple_Pack(2, PyLong_FromLong(0), PyFloat_FromDouble(0.))); |
| 2918 |
PyList_Append(self->pointslist, PyTuple_Pack(2, PyLong_FromLong(self->size), PyFloat_FromDouble(1.))); |
| 2919 |
} |
| 2920 |
|
| 2921 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 2922 |
TableStream_setSize(self->tablestream, self->size); |
| 2923 |
TableStream_setData(self->tablestream, self->data); |
| 2924 |
CosLogTable_generate(self); |
| 2925 |
|
| 2926 |
PyObject *srobj = PyObject_CallMethod(self->server, "getSamplingRate", NULL); |
| 2927 |
double sr = PyFloat_AsDouble(srobj); |
| 2928 |
Py_DECREF(srobj); |
| 2929 |
|
| 2930 |
TableStream_setSamplingRate(self->tablestream, sr); |
| 2931 |
|
| 2932 |
return (PyObject *)self; |
| 2933 |
} |
| 2934 |
|
| 2935 |
static PyObject * CosLogTable_getServer(CosLogTable* self) { GET_SERVER }; |
| 2936 |
static PyObject * CosLogTable_getTableStream(CosLogTable* self) { GET_TABLE_STREAM }; |
| 2937 |
static PyObject * CosLogTable_setData(CosLogTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 2938 |
static PyObject * CosLogTable_normalize(CosLogTable *self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 2939 |
static PyObject * CosLogTable_reset(CosLogTable *self) { TABLE_RESET }; |
| 2940 |
static PyObject * CosLogTable_removeDC(CosLogTable *self) { REMOVE_DC }; |
| 2941 |
static PyObject * CosLogTable_reverse(CosLogTable *self) { REVERSE }; |
| 2942 |
static PyObject * CosLogTable_invert(CosLogTable *self) { INVERT }; |
| 2943 |
static PyObject * CosLogTable_rectify(CosLogTable *self) { RECTIFY }; |
| 2944 |
static PyObject * CosLogTable_bipolarGain(CosLogTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 2945 |
static PyObject * CosLogTable_lowpass(CosLogTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 2946 |
static PyObject * CosLogTable_fadein(CosLogTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 2947 |
static PyObject * CosLogTable_fadeout(CosLogTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 2948 |
static PyObject * CosLogTable_pow(CosLogTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 2949 |
static PyObject * CosLogTable_copy(CosLogTable *self, PyObject *arg) { COPY }; |
| 2950 |
static PyObject * CosLogTable_copyData(CosLogTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 2951 |
static PyObject * CosLogTable_rotate(CosLogTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 2952 |
static PyObject * CosLogTable_setTable(CosLogTable *self, PyObject *arg) { SET_TABLE }; |
| 2953 |
static PyObject * CosLogTable_getTable(CosLogTable *self) { GET_TABLE }; |
| 2954 |
static PyObject * CosLogTable_getRate(CosLogTable *self) { TABLE_GET_RATE }; |
| 2955 |
static PyObject * CosLogTable_getViewTable(CosLogTable *self, PyObject *args, PyObject *kwds) { GET_VIEW_TABLE }; |
| 2956 |
static PyObject * CosLogTable_put(CosLogTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 2957 |
static PyObject * CosLogTable_get(CosLogTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 2958 |
static PyObject * CosLogTable_add(CosLogTable *self, PyObject *arg) { TABLE_ADD }; |
| 2959 |
static PyObject * CosLogTable_sub(CosLogTable *self, PyObject *arg) { TABLE_SUB }; |
| 2960 |
static PyObject * CosLogTable_mul(CosLogTable *self, PyObject *arg) { TABLE_MUL }; |
| 2961 |
static PyObject * CosLogTable_div(CosLogTable *self, PyObject *arg) { TABLE_DIV }; |
| 2962 |
|
| 2963 |
static PyObject * |
| 2964 |
CosLogTable_setSize(CosLogTable *self, PyObject *value) |
| 2965 |
{ |
| 2966 |
TABLE_SET_SIZE_WITH_POINT_LIST |
| 2967 |
|
| 2968 |
CosLogTable_generate(self); |
| 2969 |
|
| 2970 |
Py_RETURN_NONE; |
| 2971 |
} |
| 2972 |
|
| 2973 |
static PyObject * |
| 2974 |
CosLogTable_getSize(CosLogTable *self) |
| 2975 |
{ |
| 2976 |
return PyLong_FromLong(self->size); |
| 2977 |
}; |
| 2978 |
|
| 2979 |
static PyObject * |
| 2980 |
CosLogTable_getPoints(CosLogTable *self) |
| 2981 |
{ |
| 2982 |
Py_INCREF(self->pointslist); |
| 2983 |
return self->pointslist; |
| 2984 |
}; |
| 2985 |
|
| 2986 |
static PyObject * |
| 2987 |
CosLogTable_replace(CosLogTable *self, PyObject *value) |
| 2988 |
{ |
| 2989 |
if (value == NULL) |
| 2990 |
{ |
| 2991 |
PyErr_SetString(PyExc_TypeError, "Cannot delete the list attribute."); |
| 2992 |
return PyLong_FromLong(-1); |
| 2993 |
} |
| 2994 |
|
| 2995 |
if (! PyList_Check(value)) |
| 2996 |
{ |
| 2997 |
PyErr_SetString(PyExc_TypeError, "The amplitude list attribute value must be a list of tuples."); |
| 2998 |
return PyLong_FromLong(-1); |
| 2999 |
} |
| 3000 |
|
| 3001 |
Py_INCREF(value); |
| 3002 |
Py_DECREF(self->pointslist); |
| 3003 |
self->pointslist = value; |
| 3004 |
|
| 3005 |
CosLogTable_generate(self); |
| 3006 |
|
| 3007 |
Py_RETURN_NONE; |
| 3008 |
} |
| 3009 |
|
| 3010 |
static PyMemberDef CosLogTable_members[] = |
| 3011 |
{ |
| 3012 |
{"server", T_OBJECT_EX, offsetof(CosLogTable, server), 0, "Pyo server."}, |
| 3013 |
{"tablestream", T_OBJECT_EX, offsetof(CosLogTable, tablestream), 0, "Table stream object."}, |
| 3014 |
{"pointslist", T_OBJECT_EX, offsetof(CosLogTable, pointslist), 0, "Harmonics amplitude values."}, |
| 3015 |
{NULL} /* Sentinel */ |
| 3016 |
}; |
| 3017 |
|
| 3018 |
static PyMethodDef CosLogTable_methods[] = |
| 3019 |
{ |
| 3020 |
{"getServer", (PyCFunction)CosLogTable_getServer, METH_NOARGS, "Returns server object."}, |
| 3021 |
{"copy", (PyCFunction)CosLogTable_copy, METH_O, "Copy data from table given in argument."}, |
| 3022 |
{"copyData", (PyCFunction)CosLogTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 3023 |
{"rotate", (PyCFunction)CosLogTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 3024 |
{"setTable", (PyCFunction)CosLogTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 3025 |
{"getTable", (PyCFunction)CosLogTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 3026 |
{"getViewTable", (PyCFunction)CosLogTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 3027 |
{"getTableStream", (PyCFunction)CosLogTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 3028 |
{"setData", (PyCFunction)CosLogTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 3029 |
{"normalize", (PyCFunction)CosLogTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table samples"}, |
| 3030 |
{"reset", (PyCFunction)CosLogTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 3031 |
{"removeDC", (PyCFunction)CosLogTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 3032 |
{"reverse", (PyCFunction)CosLogTable_reverse, METH_NOARGS, "Reverse the table's data."}, |
| 3033 |
{"invert", (PyCFunction)CosLogTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 3034 |
{"rectify", (PyCFunction)CosLogTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 3035 |
{"bipolarGain", (PyCFunction)CosLogTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 3036 |
{"lowpass", (PyCFunction)CosLogTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 3037 |
{"fadein", (PyCFunction)CosLogTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 3038 |
{"fadeout", (PyCFunction)CosLogTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 3039 |
{"pow", (PyCFunction)CosLogTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 3040 |
{"setSize", (PyCFunction)CosLogTable_setSize, METH_O, "Sets the size of the table in samples"}, |
| 3041 |
{"getSize", (PyCFunction)CosLogTable_getSize, METH_NOARGS, "Return the size of the table in samples"}, |
| 3042 |
{"getRate", (PyCFunction)CosLogTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the table without pitch transposition."}, |
| 3043 |
{"put", (PyCFunction)CosLogTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 3044 |
{"get", (PyCFunction)CosLogTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 3045 |
{"getPoints", (PyCFunction)CosLogTable_getPoints, METH_NOARGS, "Return the list of points."}, |
| 3046 |
{"replace", (PyCFunction)CosLogTable_replace, METH_O, "Sets the harmonics amplitude list and generates a new waveform table."}, |
| 3047 |
{"add", (PyCFunction)CosLogTable_add, METH_O, "Performs table addition."}, |
| 3048 |
{"sub", (PyCFunction)CosLogTable_sub, METH_O, "Performs table substraction."}, |
| 3049 |
{"mul", (PyCFunction)CosLogTable_mul, METH_O, "Performs table multiplication."}, |
| 3050 |
{"div", (PyCFunction)CosLogTable_div, METH_O, "Performs table division."}, |
| 3051 |
{NULL} /* Sentinel */ |
| 3052 |
}; |
| 3053 |
|
| 3054 |
PyTypeObject CosLogTableType = |
| 3055 |
{ |
| 3056 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 3057 |
"_pyo.CosLogTable_base", /*tp_name*/ |
| 3058 |
sizeof(CosLogTable), /*tp_basicsize*/ |
| 3059 |
0, /*tp_itemsize*/ |
| 3060 |
(destructor)CosLogTable_dealloc, /*tp_dealloc*/ |
| 3061 |
0, /*tp_print*/ |
| 3062 |
0, /*tp_getattr*/ |
| 3063 |
0, /*tp_setattr*/ |
| 3064 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 3065 |
0, /*tp_repr*/ |
| 3066 |
0, /*tp_as_number*/ |
| 3067 |
0, /*tp_as_sequence*/ |
| 3068 |
0, /*tp_as_mapping*/ |
| 3069 |
0, /*tp_hash */ |
| 3070 |
0, /*tp_call*/ |
| 3071 |
0, /*tp_str*/ |
| 3072 |
0, /*tp_getattro*/ |
| 3073 |
0, /*tp_setattro*/ |
| 3074 |
0, /*tp_as_buffer*/ |
| 3075 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 3076 |
"CosLogTable objects. Generates a table filled with one or more Cosine-logarithmic lines.", /* tp_doc */ |
| 3077 |
(traverseproc)CosLogTable_traverse, /* tp_traverse */ |
| 3078 |
(inquiry)CosLogTable_clear, /* tp_clear */ |
| 3079 |
0, /* tp_richcompare */ |
| 3080 |
0, /* tp_weaklistoffset */ |
| 3081 |
0, /* tp_iter */ |
| 3082 |
0, /* tp_iternext */ |
| 3083 |
CosLogTable_methods, /* tp_methods */ |
| 3084 |
CosLogTable_members, /* tp_members */ |
| 3085 |
0, /* tp_getset */ |
| 3086 |
0, /* tp_base */ |
| 3087 |
0, /* tp_dict */ |
| 3088 |
0, /* tp_descr_get */ |
| 3089 |
0, /* tp_descr_set */ |
| 3090 |
0, /* tp_dictoffset */ |
| 3091 |
0, /* tp_init */ |
| 3092 |
0, /* tp_alloc */ |
| 3093 |
CosLogTable_new, /* tp_new */ |
| 3094 |
}; |
| 3095 |
|
| 3096 |
/***********************/ |
| 3097 |
/* CurveTable structure */ |
| 3098 |
/***********************/ |
| 3099 |
typedef struct |
| 3100 |
{ |
| 3101 |
pyo_table_HEAD |
| 3102 |
PyObject *pointslist; |
| 3103 |
MYFLT tension; |
| 3104 |
MYFLT bias; |
| 3105 |
} CurveTable; |
| 3106 |
|
| 3107 |
static void |
| 3108 |
CurveTable_generate(CurveTable *self) |
| 3109 |
{ |
| 3110 |
T_SIZE_T i, j, steps; |
| 3111 |
T_SIZE_T listsize; |
| 3112 |
PyObject *tup; |
| 3113 |
T_SIZE_T x1, x2; |
| 3114 |
MYFLT y0, y1, y2, y3; |
| 3115 |
MYFLT m0, m1, mu, mu2, mu3; |
| 3116 |
MYFLT a0, a1, a2, a3; |
| 3117 |
|
| 3118 |
for (i = 0; i < self->size; i++) |
| 3119 |
{ |
| 3120 |
self->data[i] = 0.0; |
| 3121 |
} |
| 3122 |
|
| 3123 |
listsize = PyList_Size(self->pointslist); |
| 3124 |
|
| 3125 |
if (listsize < 2) |
| 3126 |
{ |
| 3127 |
PySys_WriteStderr("CurveTable error: There should be at least two points in a CurveTable.\n"); |
| 3128 |
return; |
| 3129 |
} |
| 3130 |
|
| 3131 |
T_SIZE_T times[listsize + 2]; |
| 3132 |
MYFLT values[listsize + 2]; |
| 3133 |
|
| 3134 |
for (i = 0; i < listsize; i++) |
| 3135 |
{ |
| 3136 |
tup = PyList_GET_ITEM(self->pointslist, i); |
| 3137 |
PyObject *p1 = PyTuple_GET_ITEM(tup, 0); |
| 3138 |
times[i + 1] = PyLong_AsLong(PyNumber_Long(p1)); |
| 3139 |
values[i + 1] = PyFloat_AsDouble(PyTuple_GET_ITEM(tup, 1)); |
| 3140 |
Py_DECREF(p1); |
| 3141 |
} |
| 3142 |
|
| 3143 |
// sets imaginary points |
| 3144 |
times[0] = times[1] - times[2]; |
| 3145 |
|
| 3146 |
if (values[1] < values[2]) |
| 3147 |
values[0] = values[1] - values[2]; |
| 3148 |
else |
| 3149 |
values[0] = values[1] + values[2]; |
| 3150 |
|
| 3151 |
T_SIZE_T endP = listsize + 1; |
| 3152 |
times[endP] = times[endP - 2] - times[endP - 1]; |
| 3153 |
|
| 3154 |
if (values[endP - 2] < values[endP - 1]) |
| 3155 |
values[endP] = values[endP - 1] + values[endP - 2]; |
| 3156 |
else |
| 3157 |
values[endP] = values[endP - 1] - values[endP - 2]; |
| 3158 |
|
| 3159 |
for (i = 1; i < listsize; i++) |
| 3160 |
{ |
| 3161 |
x1 = times[i]; |
| 3162 |
x2 = times[i + 1]; |
| 3163 |
y0 = values[i - 1]; |
| 3164 |
y1 = values[i]; |
| 3165 |
y2 = values[i + 1]; |
| 3166 |
y3 = values[i + 2]; |
| 3167 |
|
| 3168 |
steps = x2 - x1; |
| 3169 |
|
| 3170 |
if (steps <= 0) |
| 3171 |
{ |
| 3172 |
PySys_WriteStderr("CurveTable error: point position smaller than previous one.\n"); |
| 3173 |
return; |
| 3174 |
} |
| 3175 |
|
| 3176 |
for (j = 0; j < steps; j++) |
| 3177 |
{ |
| 3178 |
mu = (MYFLT)j / steps; |
| 3179 |
mu2 = mu * mu; |
| 3180 |
mu3 = mu2 * mu; |
| 3181 |
m0 = (y1 - y0) * (1.0 + self->bias) * (1.0 - self->tension) / 2.0; |
| 3182 |
m0 += (y2 - y1) * (1.0 - self->bias) * (1.0 - self->tension) / 2.0; |
| 3183 |
m1 = (y2 - y1) * (1.0 + self->bias) * (1.0 - self->tension) / 2.0; |
| 3184 |
m1 += (y3 - y2) * (1.0 - self->bias) * (1.0 - self->tension) / 2.0; |
| 3185 |
a0 = 2.0 * mu3 - 3.0 * mu2 + 1.0; |
| 3186 |
a1 = mu3 - 2.0 * mu2 + mu; |
| 3187 |
a2 = mu3 - mu2; |
| 3188 |
a3 = -2.0 * mu3 + 3.0 * mu2; |
| 3189 |
|
| 3190 |
self->data[x1 + j] = (a0 * y1 + a1 * m0 + a2 * m1 + a3 * y2); |
| 3191 |
} |
| 3192 |
} |
| 3193 |
|
| 3194 |
self->data[self->size] = self->data[self->size - 1]; |
| 3195 |
} |
| 3196 |
|
| 3197 |
static int |
| 3198 |
CurveTable_traverse(CurveTable *self, visitproc visit, void *arg) |
| 3199 |
{ |
| 3200 |
pyo_table_VISIT |
| 3201 |
Py_VISIT(self->pointslist); |
| 3202 |
return 0; |
| 3203 |
} |
| 3204 |
|
| 3205 |
static int |
| 3206 |
CurveTable_clear(CurveTable *self) |
| 3207 |
{ |
| 3208 |
pyo_table_CLEAR |
| 3209 |
Py_CLEAR(self->pointslist); |
| 3210 |
return 0; |
| 3211 |
} |
| 3212 |
|
| 3213 |
static void |
| 3214 |
CurveTable_dealloc(CurveTable* self) |
| 3215 |
{ |
| 3216 |
PyMem_RawFree(self->data); |
| 3217 |
CurveTable_clear(self); |
| 3218 |
Py_TYPE(self->tablestream)->tp_free((PyObject*)self->tablestream); |
| 3219 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 3220 |
} |
| 3221 |
|
| 3222 |
static PyObject * |
| 3223 |
CurveTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 3224 |
{ |
| 3225 |
PyObject *pointslist = NULL; |
| 3226 |
CurveTable *self; |
| 3227 |
self = (CurveTable *)type->tp_alloc(type, 0); |
| 3228 |
|
| 3229 |
self->server = PyServer_get_server(); |
| 3230 |
Py_INCREF(self->server); |
| 3231 |
|
| 3232 |
self->pointslist = PyList_New(0); |
| 3233 |
self->size = 8192; |
| 3234 |
self->tension = 0.0; |
| 3235 |
self->bias = 0.0; |
| 3236 |
|
| 3237 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 3238 |
|
| 3239 |
static char *kwlist[] = {"list", "tension", "bias", "size", NULL}; |
| 3240 |
|
| 3241 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE__OFFN, kwlist, &pointslist, &self->tension, &self->bias, &self->size)) |
| 3242 |
Py_RETURN_NONE; |
| 3243 |
|
| 3244 |
if (pointslist) |
| 3245 |
{ |
| 3246 |
Py_INCREF(pointslist); |
| 3247 |
Py_DECREF(self->pointslist); |
| 3248 |
self->pointslist = pointslist; |
| 3249 |
} |
| 3250 |
else |
| 3251 |
{ |
| 3252 |
PyList_Append(self->pointslist, PyTuple_Pack(2, PyLong_FromLong(0), PyFloat_FromDouble(0.))); |
| 3253 |
PyList_Append(self->pointslist, PyTuple_Pack(2, PyLong_FromLong(self->size), PyFloat_FromDouble(1.))); |
| 3254 |
} |
| 3255 |
|
| 3256 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 3257 |
TableStream_setSize(self->tablestream, self->size); |
| 3258 |
TableStream_setData(self->tablestream, self->data); |
| 3259 |
CurveTable_generate(self); |
| 3260 |
|
| 3261 |
PyObject *srobj = PyObject_CallMethod(self->server, "getSamplingRate", NULL); |
| 3262 |
double sr = PyFloat_AsDouble(srobj); |
| 3263 |
Py_DECREF(srobj); |
| 3264 |
|
| 3265 |
TableStream_setSamplingRate(self->tablestream, sr); |
| 3266 |
|
| 3267 |
return (PyObject *)self; |
| 3268 |
} |
| 3269 |
|
| 3270 |
static PyObject * CurveTable_getServer(CurveTable* self) { GET_SERVER }; |
| 3271 |
static PyObject * CurveTable_getTableStream(CurveTable* self) { GET_TABLE_STREAM }; |
| 3272 |
static PyObject * CurveTable_setData(CurveTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 3273 |
static PyObject * CurveTable_normalize(CurveTable * self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 3274 |
static PyObject * CurveTable_reset(CurveTable * self) { TABLE_RESET }; |
| 3275 |
static PyObject * CurveTable_removeDC(CurveTable *self) { REMOVE_DC }; |
| 3276 |
static PyObject * CurveTable_reverse(CurveTable *self) { REVERSE }; |
| 3277 |
static PyObject * CurveTable_invert(CurveTable *self) { INVERT }; |
| 3278 |
static PyObject * CurveTable_rectify(CurveTable *self) { RECTIFY }; |
| 3279 |
static PyObject * CurveTable_bipolarGain(CurveTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 3280 |
static PyObject * CurveTable_lowpass(CurveTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 3281 |
static PyObject * CurveTable_fadein(CurveTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 3282 |
static PyObject * CurveTable_fadeout(CurveTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 3283 |
static PyObject * CurveTable_pow(CurveTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 3284 |
static PyObject * CurveTable_copy(CurveTable *self, PyObject *arg) { COPY }; |
| 3285 |
static PyObject * CurveTable_copyData(CurveTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 3286 |
static PyObject * CurveTable_rotate(CurveTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 3287 |
static PyObject * CurveTable_setTable(CurveTable *self, PyObject *arg) { SET_TABLE }; |
| 3288 |
static PyObject * CurveTable_getTable(CurveTable *self) { GET_TABLE }; |
| 3289 |
static PyObject * CurveTable_getRate(CurveTable *self) { TABLE_GET_RATE }; |
| 3290 |
static PyObject * CurveTable_getViewTable(CurveTable *self, PyObject *args, PyObject *kwds) { GET_VIEW_TABLE }; |
| 3291 |
static PyObject * CurveTable_put(CurveTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 3292 |
static PyObject * CurveTable_get(CurveTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 3293 |
static PyObject * CurveTable_add(CurveTable *self, PyObject *arg) { TABLE_ADD }; |
| 3294 |
static PyObject * CurveTable_sub(CurveTable *self, PyObject *arg) { TABLE_SUB }; |
| 3295 |
static PyObject * CurveTable_mul(CurveTable *self, PyObject *arg) { TABLE_MUL }; |
| 3296 |
static PyObject * CurveTable_div(CurveTable *self, PyObject *arg) { TABLE_DIV }; |
| 3297 |
|
| 3298 |
static PyObject * |
| 3299 |
CurveTable_setTension(CurveTable *self, PyObject *value) |
| 3300 |
{ |
| 3301 |
if (value == NULL) |
| 3302 |
{ |
| 3303 |
PyErr_SetString(PyExc_TypeError, "Cannot delete the tension attribute."); |
| 3304 |
return PyLong_FromLong(-1); |
| 3305 |
} |
| 3306 |
|
| 3307 |
if (! PyNumber_Check(value)) |
| 3308 |
{ |
| 3309 |
PyErr_SetString(PyExc_TypeError, "The tension attribute value must be a float."); |
| 3310 |
return PyLong_FromLong(-1); |
| 3311 |
} |
| 3312 |
|
| 3313 |
self->tension = PyFloat_AsDouble(value); |
| 3314 |
|
| 3315 |
CurveTable_generate(self); |
| 3316 |
|
| 3317 |
Py_RETURN_NONE; |
| 3318 |
} |
| 3319 |
|
| 3320 |
static PyObject * |
| 3321 |
CurveTable_setBias(CurveTable *self, PyObject *value) |
| 3322 |
{ |
| 3323 |
if (value == NULL) |
| 3324 |
{ |
| 3325 |
PyErr_SetString(PyExc_TypeError, "Cannot delete the bias attribute."); |
| 3326 |
return PyLong_FromLong(-1); |
| 3327 |
} |
| 3328 |
|
| 3329 |
if (! PyNumber_Check(value)) |
| 3330 |
{ |
| 3331 |
PyErr_SetString(PyExc_TypeError, "The bias attribute value must be a float."); |
| 3332 |
return PyLong_FromLong(-1); |
| 3333 |
} |
| 3334 |
|
| 3335 |
self->bias = PyFloat_AsDouble(value); |
| 3336 |
|
| 3337 |
CurveTable_generate(self); |
| 3338 |
|
| 3339 |
Py_RETURN_NONE; |
| 3340 |
} |
| 3341 |
|
| 3342 |
static PyObject * |
| 3343 |
CurveTable_setSize(CurveTable *self, PyObject *value) |
| 3344 |
{ |
| 3345 |
TABLE_SET_SIZE_WITH_POINT_LIST |
| 3346 |
|
| 3347 |
CurveTable_generate(self); |
| 3348 |
|
| 3349 |
Py_RETURN_NONE; |
| 3350 |
} |
| 3351 |
|
| 3352 |
static PyObject * |
| 3353 |
CurveTable_getSize(CurveTable *self) |
| 3354 |
{ |
| 3355 |
return PyLong_FromLong(self->size); |
| 3356 |
}; |
| 3357 |
|
| 3358 |
static PyObject * |
| 3359 |
CurveTable_getPoints(CurveTable *self) |
| 3360 |
{ |
| 3361 |
Py_INCREF(self->pointslist); |
| 3362 |
return self->pointslist; |
| 3363 |
}; |
| 3364 |
|
| 3365 |
static PyObject * |
| 3366 |
CurveTable_replace(CurveTable *self, PyObject *value) |
| 3367 |
{ |
| 3368 |
if (value == NULL) |
| 3369 |
{ |
| 3370 |
PyErr_SetString(PyExc_TypeError, "Cannot delete the list attribute."); |
| 3371 |
return PyLong_FromLong(-1); |
| 3372 |
} |
| 3373 |
|
| 3374 |
if (! PyList_Check(value)) |
| 3375 |
{ |
| 3376 |
PyErr_SetString(PyExc_TypeError, "The amplitude list attribute value must be a list of tuples."); |
| 3377 |
return PyLong_FromLong(-1); |
| 3378 |
} |
| 3379 |
|
| 3380 |
Py_INCREF(value); |
| 3381 |
Py_DECREF(self->pointslist); |
| 3382 |
self->pointslist = value; |
| 3383 |
|
| 3384 |
CurveTable_generate(self); |
| 3385 |
|
| 3386 |
Py_RETURN_NONE; |
| 3387 |
} |
| 3388 |
|
| 3389 |
static PyMemberDef CurveTable_members[] = |
| 3390 |
{ |
| 3391 |
{"server", T_OBJECT_EX, offsetof(CurveTable, server), 0, "Pyo server."}, |
| 3392 |
{"tablestream", T_OBJECT_EX, offsetof(CurveTable, tablestream), 0, "Table stream object."}, |
| 3393 |
{"pointslist", T_OBJECT_EX, offsetof(CurveTable, pointslist), 0, "Harmonics amplitude values."}, |
| 3394 |
{NULL} /* Sentinel */ |
| 3395 |
}; |
| 3396 |
|
| 3397 |
static PyMethodDef CurveTable_methods[] = |
| 3398 |
{ |
| 3399 |
{"getServer", (PyCFunction)CurveTable_getServer, METH_NOARGS, "Returns server object."}, |
| 3400 |
{"copy", (PyCFunction)CurveTable_copy, METH_O, "Copy data from table given in argument."}, |
| 3401 |
{"copyData", (PyCFunction)CurveTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 3402 |
{"rotate", (PyCFunction)CurveTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 3403 |
{"setTable", (PyCFunction)CurveTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 3404 |
{"getTable", (PyCFunction)CurveTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 3405 |
{"getViewTable", (PyCFunction)CurveTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 3406 |
{"getTableStream", (PyCFunction)CurveTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 3407 |
{"setData", (PyCFunction)CurveTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 3408 |
{"setSize", (PyCFunction)CurveTable_setSize, METH_O, "Sets the size of the table in samples"}, |
| 3409 |
{"getSize", (PyCFunction)CurveTable_getSize, METH_NOARGS, "Return the size of the table in samples"}, |
| 3410 |
{"getRate", (PyCFunction)CurveTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the table without pitch transposition."}, |
| 3411 |
{"put", (PyCFunction)CurveTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 3412 |
{"get", (PyCFunction)CurveTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 3413 |
{"getPoints", (PyCFunction)CurveTable_getPoints, METH_NOARGS, "Return the list of points."}, |
| 3414 |
{"setTension", (PyCFunction)CurveTable_setTension, METH_O, "Sets the curvature tension."}, |
| 3415 |
{"setBias", (PyCFunction)CurveTable_setBias, METH_O, "Sets the curve bias."}, |
| 3416 |
{"replace", (PyCFunction)CurveTable_replace, METH_O, "Sets the harmonics amplitude list and generates a new waveform table."}, |
| 3417 |
{"normalize", (PyCFunction)CurveTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table between -1 and 1."}, |
| 3418 |
{"reset", (PyCFunction)CurveTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 3419 |
{"removeDC", (PyCFunction)CurveTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 3420 |
{"reverse", (PyCFunction)CurveTable_reverse, METH_NOARGS, "Reverse the table's data."}, |
| 3421 |
{"invert", (PyCFunction)CurveTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 3422 |
{"rectify", (PyCFunction)CurveTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 3423 |
{"bipolarGain", (PyCFunction)CurveTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 3424 |
{"lowpass", (PyCFunction)CurveTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 3425 |
{"fadein", (PyCFunction)CurveTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 3426 |
{"fadeout", (PyCFunction)CurveTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 3427 |
{"pow", (PyCFunction)CurveTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 3428 |
{"add", (PyCFunction)CurveTable_add, METH_O, "Performs table addition."}, |
| 3429 |
{"sub", (PyCFunction)CurveTable_sub, METH_O, "Performs table substraction."}, |
| 3430 |
{"mul", (PyCFunction)CurveTable_mul, METH_O, "Performs table multiplication."}, |
| 3431 |
{"div", (PyCFunction)CurveTable_div, METH_O, "Performs table division."}, |
| 3432 |
{NULL} /* Sentinel */ |
| 3433 |
}; |
| 3434 |
|
| 3435 |
PyTypeObject CurveTableType = |
| 3436 |
{ |
| 3437 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 3438 |
"_pyo.CurveTable_base", /*tp_name*/ |
| 3439 |
sizeof(CurveTable), /*tp_basicsize*/ |
| 3440 |
0, /*tp_itemsize*/ |
| 3441 |
(destructor)CurveTable_dealloc, /*tp_dealloc*/ |
| 3442 |
0, /*tp_print*/ |
| 3443 |
0, /*tp_getattr*/ |
| 3444 |
0, /*tp_setattr*/ |
| 3445 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 3446 |
0, /*tp_repr*/ |
| 3447 |
0, /*tp_as_number*/ |
| 3448 |
0, /*tp_as_sequence*/ |
| 3449 |
0, /*tp_as_mapping*/ |
| 3450 |
0, /*tp_hash */ |
| 3451 |
0, /*tp_call*/ |
| 3452 |
0, /*tp_str*/ |
| 3453 |
0, /*tp_getattro*/ |
| 3454 |
0, /*tp_setattro*/ |
| 3455 |
0, /*tp_as_buffer*/ |
| 3456 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 3457 |
"CurveTable objects. Generates a table filled with one or more straight lines.", /* tp_doc */ |
| 3458 |
(traverseproc)CurveTable_traverse, /* tp_traverse */ |
| 3459 |
(inquiry)CurveTable_clear, /* tp_clear */ |
| 3460 |
0, /* tp_richcompare */ |
| 3461 |
0, /* tp_weaklistoffset */ |
| 3462 |
0, /* tp_iter */ |
| 3463 |
0, /* tp_iternext */ |
| 3464 |
CurveTable_methods, /* tp_methods */ |
| 3465 |
CurveTable_members, /* tp_members */ |
| 3466 |
0, /* tp_getset */ |
| 3467 |
0, /* tp_base */ |
| 3468 |
0, /* tp_dict */ |
| 3469 |
0, /* tp_descr_get */ |
| 3470 |
0, /* tp_descr_set */ |
| 3471 |
0, /* tp_dictoffset */ |
| 3472 |
0, /* tp_init */ |
| 3473 |
0, /* tp_alloc */ |
| 3474 |
CurveTable_new, /* tp_new */ |
| 3475 |
}; |
| 3476 |
|
| 3477 |
/***********************/ |
| 3478 |
/* ExpTable structure */ |
| 3479 |
/***********************/ |
| 3480 |
typedef struct |
| 3481 |
{ |
| 3482 |
pyo_table_HEAD |
| 3483 |
PyObject *pointslist; |
| 3484 |
MYFLT exp; |
| 3485 |
int inverse; |
| 3486 |
} ExpTable; |
| 3487 |
|
| 3488 |
static void |
| 3489 |
ExpTable_generate(ExpTable *self) |
| 3490 |
{ |
| 3491 |
T_SIZE_T i, j, steps; |
| 3492 |
T_SIZE_T listsize; |
| 3493 |
PyObject *tup; |
| 3494 |
T_SIZE_T x1, x2; |
| 3495 |
MYFLT y1, y2, range, inc, pointer, scl; |
| 3496 |
|
| 3497 |
for (i = 0; i < self->size; i++) |
| 3498 |
{ |
| 3499 |
self->data[i] = 0.0; |
| 3500 |
} |
| 3501 |
|
| 3502 |
listsize = PyList_Size(self->pointslist); |
| 3503 |
|
| 3504 |
if (listsize < 2) |
| 3505 |
{ |
| 3506 |
PySys_WriteStderr("ExpTable error: There should be at least two points in a ExpTable.\n"); |
| 3507 |
return; |
| 3508 |
} |
| 3509 |
|
| 3510 |
T_SIZE_T times[listsize]; |
| 3511 |
MYFLT values[listsize]; |
| 3512 |
|
| 3513 |
for (i = 0; i < listsize; i++) |
| 3514 |
{ |
| 3515 |
tup = PyList_GET_ITEM(self->pointslist, i); |
| 3516 |
PyObject *p1 = PyTuple_GET_ITEM(tup, 0); |
| 3517 |
times[i] = PyLong_AsLong(PyNumber_Long(p1)); |
| 3518 |
values[i] = PyFloat_AsDouble(PyTuple_GET_ITEM(tup, 1)); |
| 3519 |
Py_DECREF(p1); |
| 3520 |
} |
| 3521 |
|
| 3522 |
y1 = y2 = 0.0; |
| 3523 |
|
| 3524 |
for (i = 0; i < (listsize - 1); i++) |
| 3525 |
{ |
| 3526 |
x1 = times[i]; |
| 3527 |
x2 = times[i + 1]; |
| 3528 |
y1 = values[i]; |
| 3529 |
y2 = values[i + 1]; |
| 3530 |
|
| 3531 |
range = y2 - y1; |
| 3532 |
steps = x2 - x1; |
| 3533 |
|
| 3534 |
if (steps <= 0) |
| 3535 |
{ |
| 3536 |
PySys_WriteStderr("ExpTable error: point position smaller than previous one.\n"); |
| 3537 |
return; |
| 3538 |
} |
| 3539 |
|
| 3540 |
inc = 1.0 / steps; |
| 3541 |
pointer = 0.0; |
| 3542 |
|
| 3543 |
if (self->inverse == 1) |
| 3544 |
{ |
| 3545 |
if (range >= 0) |
| 3546 |
{ |
| 3547 |
for (j = 0; j < steps; j++) |
| 3548 |
{ |
| 3549 |
scl = MYPOW(pointer, self->exp); |
| 3550 |
self->data[x1 + j] = scl * range + y1; |
| 3551 |
pointer += inc; |
| 3552 |
} |
| 3553 |
} |
| 3554 |
else |
| 3555 |
{ |
| 3556 |
for (j = 0; j < steps; j++) |
| 3557 |
{ |
| 3558 |
scl = 1.0 - MYPOW(1.0 - pointer, self->exp); |
| 3559 |
self->data[x1 + j] = scl * range + y1; |
| 3560 |
pointer += inc; |
| 3561 |
} |
| 3562 |
} |
| 3563 |
} |
| 3564 |
else |
| 3565 |
{ |
| 3566 |
for (j = 0; j < steps; j++) |
| 3567 |
{ |
| 3568 |
scl = MYPOW(pointer, self->exp); |
| 3569 |
self->data[x1 + j] = scl * range + y1; |
| 3570 |
pointer += inc; |
| 3571 |
} |
| 3572 |
} |
| 3573 |
} |
| 3574 |
|
| 3575 |
self->data[self->size] = y2; |
| 3576 |
} |
| 3577 |
|
| 3578 |
static int |
| 3579 |
ExpTable_traverse(ExpTable *self, visitproc visit, void *arg) |
| 3580 |
{ |
| 3581 |
pyo_table_VISIT |
| 3582 |
Py_VISIT(self->pointslist); |
| 3583 |
return 0; |
| 3584 |
} |
| 3585 |
|
| 3586 |
static int |
| 3587 |
ExpTable_clear(ExpTable *self) |
| 3588 |
{ |
| 3589 |
pyo_table_CLEAR |
| 3590 |
Py_CLEAR(self->pointslist); |
| 3591 |
return 0; |
| 3592 |
} |
| 3593 |
|
| 3594 |
static void |
| 3595 |
ExpTable_dealloc(ExpTable* self) |
| 3596 |
{ |
| 3597 |
PyMem_RawFree(self->data); |
| 3598 |
ExpTable_clear(self); |
| 3599 |
Py_TYPE(self->tablestream)->tp_free((PyObject*)self->tablestream); |
| 3600 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 3601 |
} |
| 3602 |
|
| 3603 |
static PyObject * |
| 3604 |
ExpTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 3605 |
{ |
| 3606 |
PyObject *pointslist = NULL; |
| 3607 |
ExpTable *self; |
| 3608 |
self = (ExpTable *)type->tp_alloc(type, 0); |
| 3609 |
|
| 3610 |
self->server = PyServer_get_server(); |
| 3611 |
Py_INCREF(self->server); |
| 3612 |
|
| 3613 |
self->pointslist = PyList_New(0); |
| 3614 |
self->size = 8192; |
| 3615 |
self->exp = 10.0; |
| 3616 |
self->inverse = 1; |
| 3617 |
|
| 3618 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 3619 |
|
| 3620 |
static char *kwlist[] = {"list", "exp", "inverse", "size", NULL}; |
| 3621 |
|
| 3622 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE__OFIN, kwlist, &pointslist, &self->exp, &self->inverse, &self->size)) |
| 3623 |
Py_RETURN_NONE; |
| 3624 |
|
| 3625 |
if (pointslist) |
| 3626 |
{ |
| 3627 |
Py_INCREF(pointslist); |
| 3628 |
Py_DECREF(self->pointslist); |
| 3629 |
self->pointslist = pointslist; |
| 3630 |
} |
| 3631 |
else |
| 3632 |
{ |
| 3633 |
PyList_Append(self->pointslist, PyTuple_Pack(2, PyLong_FromLong(0), PyFloat_FromDouble(0.))); |
| 3634 |
PyList_Append(self->pointslist, PyTuple_Pack(2, PyLong_FromLong(self->size), PyFloat_FromDouble(1.))); |
| 3635 |
} |
| 3636 |
|
| 3637 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 3638 |
TableStream_setSize(self->tablestream, self->size); |
| 3639 |
TableStream_setData(self->tablestream, self->data); |
| 3640 |
ExpTable_generate(self); |
| 3641 |
|
| 3642 |
PyObject *srobj = PyObject_CallMethod(self->server, "getSamplingRate", NULL); |
| 3643 |
double sr = PyFloat_AsDouble(srobj); |
| 3644 |
Py_DECREF(srobj); |
| 3645 |
|
| 3646 |
TableStream_setSamplingRate(self->tablestream, sr); |
| 3647 |
|
| 3648 |
return (PyObject *)self; |
| 3649 |
} |
| 3650 |
|
| 3651 |
static PyObject * ExpTable_getServer(ExpTable* self) { GET_SERVER }; |
| 3652 |
static PyObject * ExpTable_getTableStream(ExpTable* self) { GET_TABLE_STREAM }; |
| 3653 |
static PyObject * ExpTable_setData(ExpTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 3654 |
static PyObject * ExpTable_normalize(ExpTable * self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 3655 |
static PyObject * ExpTable_reset(ExpTable * self) { TABLE_RESET }; |
| 3656 |
static PyObject * ExpTable_removeDC(ExpTable *self) { REMOVE_DC }; |
| 3657 |
static PyObject * ExpTable_reverse(ExpTable *self) { REVERSE }; |
| 3658 |
static PyObject * ExpTable_invert(ExpTable *self) { INVERT }; |
| 3659 |
static PyObject * ExpTable_rectify(ExpTable *self) { RECTIFY }; |
| 3660 |
static PyObject * ExpTable_bipolarGain(ExpTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 3661 |
static PyObject * ExpTable_lowpass(ExpTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 3662 |
static PyObject * ExpTable_fadein(ExpTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 3663 |
static PyObject * ExpTable_fadeout(ExpTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 3664 |
static PyObject * ExpTable_pow(ExpTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 3665 |
static PyObject * ExpTable_copy(ExpTable *self, PyObject *arg) { COPY }; |
| 3666 |
static PyObject * ExpTable_copyData(ExpTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 3667 |
static PyObject * ExpTable_rotate(ExpTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 3668 |
static PyObject * ExpTable_setTable(ExpTable *self, PyObject *arg) { SET_TABLE }; |
| 3669 |
static PyObject * ExpTable_getTable(ExpTable *self) { GET_TABLE }; |
| 3670 |
static PyObject * ExpTable_getRate(ExpTable *self) { TABLE_GET_RATE }; |
| 3671 |
static PyObject * ExpTable_getViewTable(ExpTable *self, PyObject *args, PyObject *kwds) { GET_VIEW_TABLE }; |
| 3672 |
static PyObject * ExpTable_put(ExpTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 3673 |
static PyObject * ExpTable_get(ExpTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 3674 |
static PyObject * ExpTable_add(ExpTable *self, PyObject *arg) { TABLE_ADD }; |
| 3675 |
static PyObject * ExpTable_sub(ExpTable *self, PyObject *arg) { TABLE_SUB }; |
| 3676 |
static PyObject * ExpTable_mul(ExpTable *self, PyObject *arg) { TABLE_MUL }; |
| 3677 |
static PyObject * ExpTable_div(ExpTable *self, PyObject *arg) { TABLE_DIV }; |
| 3678 |
|
| 3679 |
static PyObject * |
| 3680 |
ExpTable_setExp(ExpTable *self, PyObject *value) |
| 3681 |
{ |
| 3682 |
if (value == NULL) |
| 3683 |
{ |
| 3684 |
PyErr_SetString(PyExc_TypeError, "Cannot delete the exp attribute."); |
| 3685 |
return PyLong_FromLong(-1); |
| 3686 |
} |
| 3687 |
|
| 3688 |
if (! PyNumber_Check(value)) |
| 3689 |
{ |
| 3690 |
PyErr_SetString(PyExc_TypeError, "The exp attribute value must be a float."); |
| 3691 |
return PyLong_FromLong(-1); |
| 3692 |
} |
| 3693 |
|
| 3694 |
self->exp = PyFloat_AsDouble(value); |
| 3695 |
|
| 3696 |
ExpTable_generate(self); |
| 3697 |
|
| 3698 |
Py_RETURN_NONE; |
| 3699 |
} |
| 3700 |
|
| 3701 |
static PyObject * |
| 3702 |
ExpTable_setInverse(ExpTable *self, PyObject *value) |
| 3703 |
{ |
| 3704 |
if (value == NULL) |
| 3705 |
{ |
| 3706 |
PyErr_SetString(PyExc_TypeError, "Cannot delete the inverse attribute."); |
| 3707 |
return PyLong_FromLong(-1); |
| 3708 |
} |
| 3709 |
|
| 3710 |
if (! PyLong_Check(value)) |
| 3711 |
{ |
| 3712 |
PyErr_SetString(PyExc_TypeError, "The inverse attribute value must be a boolean (True or False or 0 or 1)."); |
| 3713 |
return PyLong_FromLong(-1); |
| 3714 |
} |
| 3715 |
|
| 3716 |
self->inverse = PyLong_AsLong(value); |
| 3717 |
|
| 3718 |
ExpTable_generate(self); |
| 3719 |
|
| 3720 |
Py_RETURN_NONE; |
| 3721 |
} |
| 3722 |
|
| 3723 |
static PyObject * |
| 3724 |
ExpTable_setSize(ExpTable *self, PyObject *value) |
| 3725 |
{ |
| 3726 |
TABLE_SET_SIZE_WITH_POINT_LIST |
| 3727 |
|
| 3728 |
ExpTable_generate(self); |
| 3729 |
|
| 3730 |
Py_RETURN_NONE; |
| 3731 |
} |
| 3732 |
|
| 3733 |
static PyObject * |
| 3734 |
ExpTable_getSize(ExpTable *self) |
| 3735 |
{ |
| 3736 |
return PyLong_FromLong(self->size); |
| 3737 |
}; |
| 3738 |
|
| 3739 |
static PyObject * |
| 3740 |
ExpTable_getPoints(ExpTable *self) |
| 3741 |
{ |
| 3742 |
Py_INCREF(self->pointslist); |
| 3743 |
return self->pointslist; |
| 3744 |
}; |
| 3745 |
|
| 3746 |
static PyObject * |
| 3747 |
ExpTable_replace(ExpTable *self, PyObject *value) |
| 3748 |
{ |
| 3749 |
if (value == NULL) |
| 3750 |
{ |
| 3751 |
PyErr_SetString(PyExc_TypeError, "Cannot delete the list attribute."); |
| 3752 |
return PyLong_FromLong(-1); |
| 3753 |
} |
| 3754 |
|
| 3755 |
if (! PyList_Check(value)) |
| 3756 |
{ |
| 3757 |
PyErr_SetString(PyExc_TypeError, "The amplitude list attribute value must be a list of tuples."); |
| 3758 |
return PyLong_FromLong(-1); |
| 3759 |
} |
| 3760 |
|
| 3761 |
Py_INCREF(value); |
| 3762 |
Py_DECREF(self->pointslist); |
| 3763 |
self->pointslist = value; |
| 3764 |
|
| 3765 |
ExpTable_generate(self); |
| 3766 |
|
| 3767 |
Py_RETURN_NONE; |
| 3768 |
} |
| 3769 |
|
| 3770 |
static PyMemberDef ExpTable_members[] = |
| 3771 |
{ |
| 3772 |
{"server", T_OBJECT_EX, offsetof(ExpTable, server), 0, "Pyo server."}, |
| 3773 |
{"tablestream", T_OBJECT_EX, offsetof(ExpTable, tablestream), 0, "Table stream object."}, |
| 3774 |
{"pointslist", T_OBJECT_EX, offsetof(ExpTable, pointslist), 0, "Harmonics amplitude values."}, |
| 3775 |
{NULL} /* Sentinel */ |
| 3776 |
}; |
| 3777 |
static PyMethodDef ExpTable_methods[] = |
| 3778 |
{ |
| 3779 |
{"getServer", (PyCFunction)ExpTable_getServer, METH_NOARGS, "Returns server object."}, |
| 3780 |
{"copy", (PyCFunction)ExpTable_copy, METH_O, "Copy data from table given in argument."}, |
| 3781 |
{"copyData", (PyCFunction)ExpTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 3782 |
{"rotate", (PyCFunction)ExpTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 3783 |
{"setTable", (PyCFunction)ExpTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 3784 |
{"getTable", (PyCFunction)ExpTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 3785 |
{"getViewTable", (PyCFunction)ExpTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 3786 |
{"getTableStream", (PyCFunction)ExpTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 3787 |
{"setData", (PyCFunction)ExpTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 3788 |
{"setSize", (PyCFunction)ExpTable_setSize, METH_O, "Sets the size of the table in samples"}, |
| 3789 |
{"getSize", (PyCFunction)ExpTable_getSize, METH_NOARGS, "Return the size of the table in samples"}, |
| 3790 |
{"getRate", (PyCFunction)ExpTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the table without pitch transposition."}, |
| 3791 |
{"put", (PyCFunction)ExpTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 3792 |
{"get", (PyCFunction)ExpTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 3793 |
{"getPoints", (PyCFunction)ExpTable_getPoints, METH_NOARGS, "Return the list of points."}, |
| 3794 |
{"setExp", (PyCFunction)ExpTable_setExp, METH_O, "Sets the exponent factor."}, |
| 3795 |
{"setInverse", (PyCFunction)ExpTable_setInverse, METH_O, "Sets the inverse factor."}, |
| 3796 |
{"replace", (PyCFunction)ExpTable_replace, METH_O, "Sets the harmonics amplitude list and generates a new waveform table."}, |
| 3797 |
{"normalize", (PyCFunction)ExpTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table between -1 and 1."}, |
| 3798 |
{"reset", (PyCFunction)ExpTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 3799 |
{"removeDC", (PyCFunction)ExpTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 3800 |
{"reverse", (PyCFunction)ExpTable_reverse, METH_NOARGS, "Reverse the table's data."}, |
| 3801 |
{"invert", (PyCFunction)ExpTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 3802 |
{"rectify", (PyCFunction)ExpTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 3803 |
{"bipolarGain", (PyCFunction)ExpTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 3804 |
{"lowpass", (PyCFunction)ExpTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 3805 |
{"fadein", (PyCFunction)ExpTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 3806 |
{"fadeout", (PyCFunction)ExpTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 3807 |
{"pow", (PyCFunction)ExpTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 3808 |
{"add", (PyCFunction)ExpTable_add, METH_O, "Performs table addition."}, |
| 3809 |
{"sub", (PyCFunction)ExpTable_sub, METH_O, "Performs table substraction."}, |
| 3810 |
{"mul", (PyCFunction)ExpTable_mul, METH_O, "Performs table multiplication."}, |
| 3811 |
{"div", (PyCFunction)ExpTable_div, METH_O, "Performs table division."}, |
| 3812 |
{NULL} /* Sentinel */ |
| 3813 |
}; |
| 3814 |
|
| 3815 |
PyTypeObject ExpTableType = |
| 3816 |
{ |
| 3817 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 3818 |
"_pyo.ExpTable_base", /*tp_name*/ |
| 3819 |
sizeof(ExpTable), /*tp_basicsize*/ |
| 3820 |
0, /*tp_itemsize*/ |
| 3821 |
(destructor)ExpTable_dealloc, /*tp_dealloc*/ |
| 3822 |
0, /*tp_print*/ |
| 3823 |
0, /*tp_getattr*/ |
| 3824 |
0, /*tp_setattr*/ |
| 3825 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 3826 |
0, /*tp_repr*/ |
| 3827 |
0, /*tp_as_number*/ |
| 3828 |
0, /*tp_as_sequence*/ |
| 3829 |
0, /*tp_as_mapping*/ |
| 3830 |
0, /*tp_hash */ |
| 3831 |
0, /*tp_call*/ |
| 3832 |
0, /*tp_str*/ |
| 3833 |
0, /*tp_getattro*/ |
| 3834 |
0, /*tp_setattro*/ |
| 3835 |
0, /*tp_as_buffer*/ |
| 3836 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 3837 |
"ExpTable objects. Generates a table filled with one or more straight lines.", /* tp_doc */ |
| 3838 |
(traverseproc)ExpTable_traverse, /* tp_traverse */ |
| 3839 |
(inquiry)ExpTable_clear, /* tp_clear */ |
| 3840 |
0, /* tp_richcompare */ |
| 3841 |
0, /* tp_weaklistoffset */ |
| 3842 |
0, /* tp_iter */ |
| 3843 |
0, /* tp_iternext */ |
| 3844 |
ExpTable_methods, /* tp_methods */ |
| 3845 |
ExpTable_members, /* tp_members */ |
| 3846 |
0, /* tp_getset */ |
| 3847 |
0, /* tp_base */ |
| 3848 |
0, /* tp_dict */ |
| 3849 |
0, /* tp_descr_get */ |
| 3850 |
0, /* tp_descr_set */ |
| 3851 |
0, /* tp_dictoffset */ |
| 3852 |
0, /* tp_init */ |
| 3853 |
0, /* tp_alloc */ |
| 3854 |
ExpTable_new, /* tp_new */ |
| 3855 |
}; |
| 3856 |
|
| 3857 |
/***********************/ |
| 3858 |
/* SndTable structure */ |
| 3859 |
/***********************/ |
| 3860 |
typedef struct |
| 3861 |
{ |
| 3862 |
pyo_table_HEAD |
| 3863 |
char *path; |
| 3864 |
int sndSr; |
| 3865 |
int chnl; |
| 3866 |
MYFLT sr; |
| 3867 |
MYFLT start; |
| 3868 |
MYFLT stop; |
| 3869 |
MYFLT crossfade; |
| 3870 |
MYFLT insertPos; |
| 3871 |
} SndTable; |
| 3872 |
|
| 3873 |
static void |
| 3874 |
SndTable_full_reset(SndTable *self) |
| 3875 |
{ |
| 3876 |
T_SIZE_T i; |
| 3877 |
|
| 3878 |
for (i = 0; i < self->size; i++) |
| 3879 |
{ |
| 3880 |
self->data[i] = 0.0; |
| 3881 |
} |
| 3882 |
|
| 3883 |
self->data[self->size] = 0.0; |
| 3884 |
self->start = 0.0; |
| 3885 |
self->stop = -1.0; |
| 3886 |
} |
| 3887 |
|
| 3888 |
static void |
| 3889 |
SndTable_loadSound(SndTable *self) |
| 3890 |
{ |
| 3891 |
SNDFILE *sf; |
| 3892 |
SF_INFO info; |
| 3893 |
T_SIZE_T i, num, num_items, num_chnls, snd_size, start, stop, num_count = 0; |
| 3894 |
MYFLT *tmp; |
| 3895 |
|
| 3896 |
info.format = 0; |
| 3897 |
sf = sf_open(self->path, SFM_READ, &info); |
| 3898 |
|
| 3899 |
if (sf == NULL) |
| 3900 |
{ |
| 3901 |
PySys_WriteStdout("SndTable failed to open the file.\n"); |
| 3902 |
return; |
| 3903 |
} |
| 3904 |
|
| 3905 |
snd_size = info.frames; |
| 3906 |
self->sndSr = info.samplerate; |
| 3907 |
num_chnls = info.channels; |
| 3908 |
|
| 3909 |
if (self->stop <= 0 || self->stop <= self->start || (self->stop * self->sndSr) > snd_size) |
| 3910 |
stop = snd_size; |
| 3911 |
else |
| 3912 |
stop = (T_SIZE_T)(self->stop * self->sndSr); |
| 3913 |
|
| 3914 |
if (self->start < 0 || (self->start * self->sndSr) > snd_size) |
| 3915 |
start = 0; |
| 3916 |
else |
| 3917 |
start = (T_SIZE_T)(self->start * self->sndSr); |
| 3918 |
|
| 3919 |
self->size = stop - start; |
| 3920 |
num_items = self->size * num_chnls; |
| 3921 |
|
| 3922 |
/* Allocate space for the data to be read, then read it. */ |
| 3923 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 3924 |
|
| 3925 |
/* For sound longer than 1 minute, load 30 sec chunks. */ |
| 3926 |
if (self->size > (T_SIZE_T)(self->sndSr * 60 * num_chnls)) |
| 3927 |
{ |
| 3928 |
tmp = (MYFLT *)PyMem_RawMalloc(self->sndSr * 30 * num_chnls * sizeof(MYFLT)); |
| 3929 |
sf_seek(sf, start, SEEK_SET); |
| 3930 |
num_items = self->sndSr * 30 * num_chnls; |
| 3931 |
|
| 3932 |
do |
| 3933 |
{ |
| 3934 |
num = SF_READ(sf, tmp, num_items); |
| 3935 |
|
| 3936 |
for (i = 0; i < num; i++) |
| 3937 |
{ |
| 3938 |
if ((int)(i % num_chnls) == self->chnl) |
| 3939 |
{ |
| 3940 |
self->data[num_count++] = tmp[i]; |
| 3941 |
} |
| 3942 |
} |
| 3943 |
} |
| 3944 |
while (num == num_items); |
| 3945 |
|
| 3946 |
sf_close(sf); |
| 3947 |
} |
| 3948 |
/* For sound shorter than 1 minute, load sound in one pass. */ |
| 3949 |
else |
| 3950 |
{ |
| 3951 |
tmp = (MYFLT *)PyMem_RawMalloc(num_items * sizeof(MYFLT)); |
| 3952 |
sf_seek(sf, start, SEEK_SET); |
| 3953 |
num = SF_READ(sf, tmp, num_items); |
| 3954 |
sf_close(sf); |
| 3955 |
|
| 3956 |
for (i = 0; i < num_items; i++) |
| 3957 |
{ |
| 3958 |
if ((int)(i % num_chnls) == self->chnl) |
| 3959 |
{ |
| 3960 |
self->data[(T_SIZE_T)(i / num_chnls)] = tmp[i]; |
| 3961 |
} |
| 3962 |
} |
| 3963 |
} |
| 3964 |
|
| 3965 |
self->data[self->size] = self->data[0]; |
| 3966 |
|
| 3967 |
self->start = 0.0; |
| 3968 |
self->stop = -1.0; |
| 3969 |
PyMem_RawFree(tmp); |
| 3970 |
TableStream_setSize(self->tablestream, self->size); |
| 3971 |
TableStream_setSamplingRate(self->tablestream, self->sndSr); |
| 3972 |
TableStream_setData(self->tablestream, self->data); |
| 3973 |
} |
| 3974 |
|
| 3975 |
static void |
| 3976 |
SndTable_appendSound(SndTable *self) |
| 3977 |
{ |
| 3978 |
SNDFILE *sf; |
| 3979 |
SF_INFO info; |
| 3980 |
T_SIZE_T i, num_items, num_chnls, snd_size, start, stop, to_load_size, cross_in_samps, cross_point, index, real_index; |
| 3981 |
MYFLT *tmp, *tmp_data; |
| 3982 |
MYFLT cross_amp; |
| 3983 |
|
| 3984 |
info.format = 0; |
| 3985 |
sf = sf_open(self->path, SFM_READ, &info); |
| 3986 |
|
| 3987 |
if (sf == NULL) |
| 3988 |
{ |
| 3989 |
PySys_WriteStdout("SndTable failed to open the file.\n"); |
| 3990 |
return; |
| 3991 |
} |
| 3992 |
|
| 3993 |
snd_size = info.frames; |
| 3994 |
self->sndSr = info.samplerate; |
| 3995 |
num_chnls = info.channels; |
| 3996 |
|
| 3997 |
if (self->stop <= 0 || self->stop <= self->start || (self->stop * self->sndSr) > snd_size) |
| 3998 |
stop = snd_size; |
| 3999 |
else |
| 4000 |
stop = (T_SIZE_T)(self->stop * self->sndSr); |
| 4001 |
|
| 4002 |
if (self->start < 0 || (self->start * self->sndSr) > snd_size) |
| 4003 |
start = 0; |
| 4004 |
else |
| 4005 |
start = (T_SIZE_T)(self->start * self->sndSr); |
| 4006 |
|
| 4007 |
to_load_size = stop - start; |
| 4008 |
num_items = to_load_size * num_chnls; |
| 4009 |
cross_in_samps = (T_SIZE_T)(self->crossfade * self->sr); |
| 4010 |
|
| 4011 |
if (cross_in_samps >= to_load_size) |
| 4012 |
cross_in_samps = to_load_size - 1; |
| 4013 |
|
| 4014 |
if (cross_in_samps >= self->size) |
| 4015 |
cross_in_samps = self->size - 1; |
| 4016 |
|
| 4017 |
/* Allocate space for the data to be read, then read it. */ |
| 4018 |
tmp = (MYFLT *)PyMem_RawMalloc(num_items * sizeof(MYFLT)); |
| 4019 |
tmp_data = (MYFLT *)PyMem_RawMalloc(self->size * sizeof(MYFLT)); |
| 4020 |
|
| 4021 |
sf_seek(sf, start, SEEK_SET); |
| 4022 |
SF_READ(sf, tmp, num_items); |
| 4023 |
sf_close(sf); |
| 4024 |
|
| 4025 |
if (cross_in_samps != 0) |
| 4026 |
{ |
| 4027 |
for (i = 0; i < self->size; i++) |
| 4028 |
{ |
| 4029 |
tmp_data[i] = self->data[i]; |
| 4030 |
} |
| 4031 |
} |
| 4032 |
|
| 4033 |
cross_point = self->size - cross_in_samps; |
| 4034 |
self->size = self->size + to_load_size - cross_in_samps; |
| 4035 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 4036 |
|
| 4037 |
if (cross_in_samps != 0) |
| 4038 |
{ |
| 4039 |
for (i = 0; i < cross_point; i++) |
| 4040 |
{ |
| 4041 |
self->data[i] = tmp_data[i]; |
| 4042 |
} |
| 4043 |
} |
| 4044 |
|
| 4045 |
if (self->crossfade == 0.0) |
| 4046 |
{ |
| 4047 |
for (i = 0; i < num_items; i++) |
| 4048 |
{ |
| 4049 |
if ((int)(i % num_chnls) == self->chnl) |
| 4050 |
{ |
| 4051 |
index = (T_SIZE_T)(i / num_chnls); |
| 4052 |
real_index = cross_point + index; |
| 4053 |
self->data[real_index] = tmp[i]; |
| 4054 |
} |
| 4055 |
} |
| 4056 |
} |
| 4057 |
else |
| 4058 |
{ |
| 4059 |
for (i = 0; i < num_items; i++) |
| 4060 |
{ |
| 4061 |
if ((int)(i % num_chnls) == self->chnl) |
| 4062 |
{ |
| 4063 |
index = (T_SIZE_T)(i / num_chnls); |
| 4064 |
real_index = cross_point + index; |
| 4065 |
|
| 4066 |
if (index < cross_in_samps) |
| 4067 |
{ |
| 4068 |
cross_amp = MYSQRT(index / (MYFLT)cross_in_samps); |
| 4069 |
self->data[real_index] = tmp[i] * cross_amp + tmp_data[real_index] * (1. - cross_amp); |
| 4070 |
} |
| 4071 |
else |
| 4072 |
self->data[real_index] = tmp[i]; |
| 4073 |
} |
| 4074 |
} |
| 4075 |
} |
| 4076 |
|
| 4077 |
self->data[self->size] = self->data[0]; |
| 4078 |
|
| 4079 |
self->start = 0.0; |
| 4080 |
self->stop = -1.0; |
| 4081 |
PyMem_RawFree(tmp); |
| 4082 |
PyMem_RawFree(tmp_data); |
| 4083 |
TableStream_setSize(self->tablestream, self->size); |
| 4084 |
TableStream_setSamplingRate(self->tablestream, self->sndSr); |
| 4085 |
TableStream_setData(self->tablestream, self->data); |
| 4086 |
} |
| 4087 |
|
| 4088 |
static void |
| 4089 |
SndTable_prependSound(SndTable *self) |
| 4090 |
{ |
| 4091 |
SNDFILE *sf; |
| 4092 |
SF_INFO info; |
| 4093 |
T_SIZE_T i, num_items, num_chnls, snd_size, start, stop, to_load_size, cross_in_samps, cross_point, index = 0; |
| 4094 |
MYFLT *tmp, *tmp_data; |
| 4095 |
MYFLT cross_amp; |
| 4096 |
|
| 4097 |
info.format = 0; |
| 4098 |
sf = sf_open(self->path, SFM_READ, &info); |
| 4099 |
|
| 4100 |
if (sf == NULL) |
| 4101 |
{ |
| 4102 |
PySys_WriteStdout("SndTable failed to open the file.\n"); |
| 4103 |
return; |
| 4104 |
} |
| 4105 |
|
| 4106 |
snd_size = info.frames; |
| 4107 |
self->sndSr = info.samplerate; |
| 4108 |
num_chnls = info.channels; |
| 4109 |
|
| 4110 |
if (self->stop <= 0 || self->stop <= self->start || (self->stop * self->sndSr) > snd_size) |
| 4111 |
stop = snd_size; |
| 4112 |
else |
| 4113 |
stop = (T_SIZE_T)(self->stop * self->sndSr); |
| 4114 |
|
| 4115 |
if (self->start < 0 || (self->start * self->sndSr) > snd_size) |
| 4116 |
start = 0; |
| 4117 |
else |
| 4118 |
start = (T_SIZE_T)(self->start * self->sndSr); |
| 4119 |
|
| 4120 |
to_load_size = stop - start; |
| 4121 |
num_items = to_load_size * num_chnls; |
| 4122 |
cross_in_samps = (T_SIZE_T)(self->crossfade * self->sr); |
| 4123 |
|
| 4124 |
if (cross_in_samps >= to_load_size) |
| 4125 |
cross_in_samps = to_load_size - 1; |
| 4126 |
|
| 4127 |
if ((int)cross_in_samps >= self->size) |
| 4128 |
cross_in_samps = self->size - 1; |
| 4129 |
|
| 4130 |
/* Allocate space for the data to be read, then read it. */ |
| 4131 |
tmp = (MYFLT *)PyMem_RawMalloc(num_items * sizeof(MYFLT)); |
| 4132 |
tmp_data = (MYFLT *)PyMem_RawMalloc(self->size * sizeof(MYFLT)); |
| 4133 |
|
| 4134 |
sf_seek(sf, start, SEEK_SET); |
| 4135 |
SF_READ(sf, tmp, num_items); |
| 4136 |
sf_close(sf); |
| 4137 |
|
| 4138 |
for (i = 0; i < self->size; i++) |
| 4139 |
{ |
| 4140 |
tmp_data[i] = self->data[i]; |
| 4141 |
} |
| 4142 |
|
| 4143 |
cross_point = to_load_size - cross_in_samps; |
| 4144 |
self->size = self->size + to_load_size - cross_in_samps; |
| 4145 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 4146 |
|
| 4147 |
if (self->crossfade == 0.0) |
| 4148 |
{ |
| 4149 |
for (i = 0; i < num_items; i++) |
| 4150 |
{ |
| 4151 |
if ((int)(i % num_chnls) == self->chnl) |
| 4152 |
{ |
| 4153 |
index = (T_SIZE_T)(i / num_chnls); |
| 4154 |
self->data[index] = tmp[i]; |
| 4155 |
} |
| 4156 |
} |
| 4157 |
|
| 4158 |
} |
| 4159 |
else |
| 4160 |
{ |
| 4161 |
for (i = 0; i < num_items; i++) |
| 4162 |
{ |
| 4163 |
if ((int)(i % num_chnls) == self->chnl) |
| 4164 |
{ |
| 4165 |
index = (T_SIZE_T)(i / num_chnls); |
| 4166 |
|
| 4167 |
if (index >= cross_point) |
| 4168 |
{ |
| 4169 |
cross_amp = MYSQRT((index - cross_point) / (MYFLT)cross_in_samps); |
| 4170 |
self->data[index] = tmp[i] * (1. - cross_amp) + tmp_data[index - cross_point] * cross_amp; |
| 4171 |
} |
| 4172 |
else |
| 4173 |
self->data[index] = tmp[i]; |
| 4174 |
} |
| 4175 |
} |
| 4176 |
} |
| 4177 |
|
| 4178 |
for (i = (index + 1); i < self->size; i++) |
| 4179 |
{ |
| 4180 |
self->data[i] = tmp_data[i - cross_point]; |
| 4181 |
} |
| 4182 |
|
| 4183 |
self->data[self->size] = self->data[0]; |
| 4184 |
|
| 4185 |
self->start = 0.0; |
| 4186 |
self->stop = -1.0; |
| 4187 |
PyMem_RawFree(tmp); |
| 4188 |
PyMem_RawFree(tmp_data); |
| 4189 |
TableStream_setSize(self->tablestream, self->size); |
| 4190 |
TableStream_setSamplingRate(self->tablestream, self->sndSr); |
| 4191 |
TableStream_setData(self->tablestream, self->data); |
| 4192 |
} |
| 4193 |
|
| 4194 |
static void |
| 4195 |
SndTable_insertSound(SndTable *self) |
| 4196 |
{ |
| 4197 |
SNDFILE *sf; |
| 4198 |
SF_INFO info; |
| 4199 |
T_SIZE_T i, num_items, num_chnls, snd_size, start, stop, to_load_size; |
| 4200 |
T_SIZE_T cross_in_samps, cross_point, insert_point, index; |
| 4201 |
T_SIZE_T read_point = 0, real_index = 0; |
| 4202 |
MYFLT *tmp, *tmp_data; |
| 4203 |
MYFLT cross_amp; |
| 4204 |
|
| 4205 |
info.format = 0; |
| 4206 |
sf = sf_open(self->path, SFM_READ, &info); |
| 4207 |
|
| 4208 |
if (sf == NULL) |
| 4209 |
{ |
| 4210 |
PySys_WriteStdout("SndTable failed to open the file.\n"); |
| 4211 |
return; |
| 4212 |
} |
| 4213 |
|
| 4214 |
snd_size = info.frames; |
| 4215 |
self->sndSr = info.samplerate; |
| 4216 |
num_chnls = info.channels; |
| 4217 |
|
| 4218 |
if (self->stop <= 0 || self->stop <= self->start || (self->stop * self->sndSr) > snd_size) |
| 4219 |
stop = snd_size; |
| 4220 |
else |
| 4221 |
stop = (T_SIZE_T)(self->stop * self->sndSr); |
| 4222 |
|
| 4223 |
if (self->start < 0 || (self->start * self->sndSr) > snd_size) |
| 4224 |
start = 0; |
| 4225 |
else |
| 4226 |
start = (T_SIZE_T)(self->start * self->sndSr); |
| 4227 |
|
| 4228 |
to_load_size = stop - start; |
| 4229 |
num_items = to_load_size * num_chnls; |
| 4230 |
|
| 4231 |
insert_point = (T_SIZE_T)(self->insertPos * self->sr); |
| 4232 |
|
| 4233 |
if (insert_point >= self->size) |
| 4234 |
insert_point = self->size - 1; |
| 4235 |
|
| 4236 |
cross_in_samps = (T_SIZE_T)(self->crossfade * self->sr); |
| 4237 |
|
| 4238 |
if (cross_in_samps >= (to_load_size / 2)) |
| 4239 |
cross_in_samps = (to_load_size / 2) - 5; |
| 4240 |
|
| 4241 |
if (cross_in_samps >= insert_point) |
| 4242 |
cross_in_samps = insert_point - 5; |
| 4243 |
|
| 4244 |
if (cross_in_samps >= (self->size - insert_point)) |
| 4245 |
cross_in_samps = (self->size - insert_point) - 5; |
| 4246 |
|
| 4247 |
/* Allocate space for the data to be read, then read it. */ |
| 4248 |
tmp = (MYFLT *)PyMem_RawMalloc(num_items * sizeof(MYFLT)); |
| 4249 |
tmp_data = (MYFLT *)PyMem_RawMalloc(self->size * sizeof(MYFLT)); |
| 4250 |
|
| 4251 |
sf_seek(sf, start, SEEK_SET); |
| 4252 |
SF_READ(sf, tmp, num_items); |
| 4253 |
sf_close(sf); |
| 4254 |
|
| 4255 |
for (i = 0; i < self->size; i++) |
| 4256 |
{ |
| 4257 |
tmp_data[i] = self->data[i]; |
| 4258 |
} |
| 4259 |
|
| 4260 |
self->size = self->size + to_load_size - (cross_in_samps * 2); |
| 4261 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 4262 |
|
| 4263 |
cross_point = insert_point - cross_in_samps; |
| 4264 |
|
| 4265 |
for (i = 0; i < cross_point; i++) |
| 4266 |
{ |
| 4267 |
self->data[i] = tmp_data[i]; |
| 4268 |
} |
| 4269 |
|
| 4270 |
if (self->crossfade == 0.0) |
| 4271 |
{ |
| 4272 |
for (i = 0; i < num_items; i++) |
| 4273 |
{ |
| 4274 |
if ((int)(i % num_chnls) == self->chnl) |
| 4275 |
{ |
| 4276 |
index = (T_SIZE_T)(i / num_chnls); |
| 4277 |
self->data[index + cross_point] = tmp[i]; |
| 4278 |
} |
| 4279 |
} |
| 4280 |
|
| 4281 |
} |
| 4282 |
else |
| 4283 |
{ |
| 4284 |
for (i = 0; i < num_items; i++) |
| 4285 |
{ |
| 4286 |
if ((int)(i % num_chnls) == self->chnl) |
| 4287 |
{ |
| 4288 |
index = (T_SIZE_T)(i / num_chnls); |
| 4289 |
real_index = index + cross_point; |
| 4290 |
|
| 4291 |
if (index <= cross_in_samps) |
| 4292 |
{ |
| 4293 |
cross_amp = MYSQRT(index / (MYFLT)cross_in_samps); |
| 4294 |
self->data[real_index] = tmp[i] * cross_amp + tmp_data[cross_point + index] * (1.0 - cross_amp); |
| 4295 |
} |
| 4296 |
else if (index >= (to_load_size - cross_in_samps)) |
| 4297 |
{ |
| 4298 |
cross_amp = MYSQRT((to_load_size - index) / (MYFLT)cross_in_samps); |
| 4299 |
read_point = cross_in_samps - (to_load_size - index) + insert_point; |
| 4300 |
self->data[real_index] = tmp[i] * cross_amp + tmp_data[read_point] * (1.0 - cross_amp); |
| 4301 |
} |
| 4302 |
else |
| 4303 |
self->data[real_index] = tmp[i]; |
| 4304 |
} |
| 4305 |
} |
| 4306 |
} |
| 4307 |
|
| 4308 |
read_point++; |
| 4309 |
|
| 4310 |
for (i = (real_index + 1); i < self->size; i++) |
| 4311 |
{ |
| 4312 |
self->data[i] = tmp_data[read_point]; |
| 4313 |
read_point++; |
| 4314 |
} |
| 4315 |
|
| 4316 |
self->data[self->size] = self->data[0]; |
| 4317 |
|
| 4318 |
self->start = 0.0; |
| 4319 |
self->stop = -1.0; |
| 4320 |
PyMem_RawFree(tmp); |
| 4321 |
PyMem_RawFree(tmp_data); |
| 4322 |
TableStream_setSize(self->tablestream, self->size); |
| 4323 |
TableStream_setSamplingRate(self->tablestream, self->sndSr); |
| 4324 |
TableStream_setData(self->tablestream, self->data); |
| 4325 |
} |
| 4326 |
|
| 4327 |
static int |
| 4328 |
SndTable_traverse(SndTable *self, visitproc visit, void *arg) |
| 4329 |
{ |
| 4330 |
pyo_table_VISIT |
| 4331 |
return 0; |
| 4332 |
} |
| 4333 |
|
| 4334 |
static int |
| 4335 |
SndTable_clear(SndTable *self) |
| 4336 |
{ |
| 4337 |
pyo_table_CLEAR |
| 4338 |
return 0; |
| 4339 |
} |
| 4340 |
|
| 4341 |
static void |
| 4342 |
SndTable_dealloc(SndTable* self) |
| 4343 |
{ |
| 4344 |
PyMem_RawFree(self->data); |
| 4345 |
SndTable_clear(self); |
| 4346 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 4347 |
} |
| 4348 |
|
| 4349 |
static PyObject * |
| 4350 |
SndTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 4351 |
{ |
| 4352 |
T_SIZE_T psize; |
| 4353 |
SndTable *self; |
| 4354 |
|
| 4355 |
self = (SndTable *)type->tp_alloc(type, 0); |
| 4356 |
|
| 4357 |
self->server = PyServer_get_server(); |
| 4358 |
Py_INCREF(self->server); |
| 4359 |
|
| 4360 |
self->sr = (MYFLT)PyFloat_AsDouble(PyObject_CallMethod(self->server, "getSamplingRate", NULL)); |
| 4361 |
|
| 4362 |
self->chnl = 0; |
| 4363 |
self->stop = -1.0; |
| 4364 |
self->crossfade = 0.0; |
| 4365 |
self->insertPos = 0.0; |
| 4366 |
|
| 4367 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 4368 |
|
| 4369 |
static char *kwlist[] = {"path", "chnl", "start", "stop", NULL}; |
| 4370 |
|
| 4371 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_P_IFF, kwlist, &self->path, &psize, &self->chnl, &self->start, &self->stop)) |
| 4372 |
return PyLong_FromLong(-1); |
| 4373 |
|
| 4374 |
if (strcmp(self->path, "") == 0) |
| 4375 |
{ |
| 4376 |
self->size = (T_SIZE_T)self->sr; |
| 4377 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 4378 |
|
| 4379 |
SndTable_full_reset(self); |
| 4380 |
|
| 4381 |
self->sndSr = (int)self->sr; |
| 4382 |
TableStream_setSize(self->tablestream, self->size); |
| 4383 |
TableStream_setSamplingRate(self->tablestream, (int)self->sr); |
| 4384 |
TableStream_setData(self->tablestream, self->data); |
| 4385 |
} |
| 4386 |
else |
| 4387 |
{ |
| 4388 |
SndTable_loadSound(self); |
| 4389 |
} |
| 4390 |
|
| 4391 |
return (PyObject *)self; |
| 4392 |
} |
| 4393 |
|
| 4394 |
static PyObject * SndTable_getServer(SndTable* self) { GET_SERVER }; |
| 4395 |
static PyObject * SndTable_getTableStream(SndTable* self) { GET_TABLE_STREAM }; |
| 4396 |
static PyObject * SndTable_setData(SndTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 4397 |
static PyObject * SndTable_normalize(SndTable *self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 4398 |
static PyObject * SndTable_reset(SndTable *self) { TABLE_RESET }; |
| 4399 |
static PyObject * SndTable_removeDC(SndTable *self) { REMOVE_DC }; |
| 4400 |
static PyObject * SndTable_reverse(SndTable *self) { REVERSE }; |
| 4401 |
static PyObject * SndTable_invert(SndTable *self) { INVERT }; |
| 4402 |
static PyObject * SndTable_rectify(SndTable *self) { RECTIFY }; |
| 4403 |
static PyObject * SndTable_bipolarGain(SndTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 4404 |
static PyObject * SndTable_lowpass(SndTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 4405 |
static PyObject * SndTable_fadein(SndTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 4406 |
static PyObject * SndTable_fadeout(SndTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 4407 |
static PyObject * SndTable_pow(SndTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 4408 |
static PyObject * SndTable_copy(SndTable *self, PyObject *arg) { COPY }; |
| 4409 |
static PyObject * SndTable_copyData(SndTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 4410 |
static PyObject * SndTable_rotate(SndTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 4411 |
static PyObject * SndTable_setTable(SndTable *self, PyObject *arg) { SET_TABLE }; |
| 4412 |
static PyObject * SndTable_getTable(SndTable *self) { GET_TABLE }; |
| 4413 |
static PyObject * SndTable_put(SndTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 4414 |
static PyObject * SndTable_get(SndTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 4415 |
static PyObject * SndTable_add(SndTable *self, PyObject *arg) { TABLE_ADD }; |
| 4416 |
static PyObject * SndTable_sub(SndTable *self, PyObject *arg) { TABLE_SUB }; |
| 4417 |
static PyObject * SndTable_mul(SndTable *self, PyObject *arg) { TABLE_MUL }; |
| 4418 |
static PyObject * SndTable_div(SndTable *self, PyObject *arg) { TABLE_DIV }; |
| 4419 |
|
| 4420 |
static PyObject * |
| 4421 |
SndTable_getViewTable(SndTable *self, PyObject *args, PyObject *kwds) |
| 4422 |
{ |
| 4423 |
T_SIZE_T i, j, y, w, h, h2, step, size; |
| 4424 |
T_SIZE_T count = 0; |
| 4425 |
T_SIZE_T yOffset = 0; |
| 4426 |
MYFLT absin, fstep; |
| 4427 |
MYFLT begin = 0.0; |
| 4428 |
MYFLT end = -1.0; |
| 4429 |
PyObject *samples, *tuple; |
| 4430 |
PyObject *sizetmp = NULL; |
| 4431 |
|
| 4432 |
static char *kwlist[] = {"size", "begin", "end", "yOffset", NULL}; |
| 4433 |
|
| 4434 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE__OFFI, kwlist, &sizetmp, &begin, &end, &yOffset)) |
| 4435 |
return PyLong_FromLong(-1); |
| 4436 |
|
| 4437 |
if (end <= 0.0) |
| 4438 |
end = self->size; |
| 4439 |
else |
| 4440 |
{ |
| 4441 |
end = end * self->sr; |
| 4442 |
|
| 4443 |
if (end > self->size) |
| 4444 |
end = self->size; |
| 4445 |
} |
| 4446 |
|
| 4447 |
if (begin < 0.0) |
| 4448 |
begin = 0; |
| 4449 |
else |
| 4450 |
{ |
| 4451 |
begin = begin * self->sr; |
| 4452 |
|
| 4453 |
if (begin >= end) |
| 4454 |
begin = 0; |
| 4455 |
} |
| 4456 |
|
| 4457 |
size = (T_SIZE_T)(end - begin); |
| 4458 |
|
| 4459 |
if (sizetmp) |
| 4460 |
{ |
| 4461 |
if (PyTuple_Check(sizetmp)) |
| 4462 |
{ |
| 4463 |
w = PyLong_AsLong(PyTuple_GET_ITEM(sizetmp, 0)); |
| 4464 |
h = PyLong_AsLong(PyTuple_GET_ITEM(sizetmp, 1)); |
| 4465 |
} |
| 4466 |
else if (PyList_Check(sizetmp)) |
| 4467 |
{ |
| 4468 |
w = PyLong_AsLong(PyList_GET_ITEM(sizetmp, 0)); |
| 4469 |
h = PyLong_AsLong(PyList_GET_ITEM(sizetmp, 1)); |
| 4470 |
} |
| 4471 |
else |
| 4472 |
{ |
| 4473 |
w = 500; |
| 4474 |
h = 200; |
| 4475 |
} |
| 4476 |
} |
| 4477 |
else |
| 4478 |
{ |
| 4479 |
w = 500; |
| 4480 |
h = 200; |
| 4481 |
} |
| 4482 |
|
| 4483 |
h2 = h / 2; |
| 4484 |
step = (T_SIZE_T)(size / (MYFLT)(w)); |
| 4485 |
fstep = (MYFLT)(w) / (size - 1); |
| 4486 |
|
| 4487 |
if (step == 0) |
| 4488 |
{ |
| 4489 |
samples = PyList_New(size); |
| 4490 |
|
| 4491 |
for (i = 0; i < size; i++) |
| 4492 |
{ |
| 4493 |
tuple = PyTuple_New(2); |
| 4494 |
PyTuple_SetItem(tuple, 0, PyLong_FromLong((int)(i * fstep))); |
| 4495 |
PyTuple_SetItem(tuple, 1, PyLong_FromLong(-self->data[i + (int)(begin)]*h2 + h2 + yOffset)); |
| 4496 |
PyList_SetItem(samples, i, tuple); |
| 4497 |
} |
| 4498 |
} |
| 4499 |
else if (step < 32) |
| 4500 |
{ |
| 4501 |
samples = PyList_New(w); |
| 4502 |
|
| 4503 |
for (i = 0; i < w; i++) |
| 4504 |
{ |
| 4505 |
absin = 0.0; |
| 4506 |
|
| 4507 |
for (j = 0; j < step; j++) |
| 4508 |
{ |
| 4509 |
absin += -self->data[(T_SIZE_T)(begin) + count]; |
| 4510 |
count++; |
| 4511 |
} |
| 4512 |
|
| 4513 |
y = (T_SIZE_T)(absin / step * h2); |
| 4514 |
tuple = PyTuple_New(2); |
| 4515 |
PyTuple_SetItem(tuple, 0, PyLong_FromLong(i)); |
| 4516 |
PyTuple_SetItem(tuple, 1, PyLong_FromLong(h2 + y + yOffset)); |
| 4517 |
PyList_SetItem(samples, i, tuple); |
| 4518 |
} |
| 4519 |
} |
| 4520 |
else |
| 4521 |
{ |
| 4522 |
samples = PyList_New(w * 2); |
| 4523 |
|
| 4524 |
for (i = 0; i < w; i++) |
| 4525 |
{ |
| 4526 |
absin = 0.0; |
| 4527 |
|
| 4528 |
for (j = 0; j < step; j++) |
| 4529 |
{ |
| 4530 |
if (MYFABS(self->data[(T_SIZE_T)(begin) + count]) > absin) |
| 4531 |
absin = -self->data[(T_SIZE_T)(begin) + count]; |
| 4532 |
|
| 4533 |
count++; |
| 4534 |
} |
| 4535 |
|
| 4536 |
y = (T_SIZE_T)(absin * h2); |
| 4537 |
tuple = PyTuple_New(2); |
| 4538 |
PyTuple_SetItem(tuple, 0, PyLong_FromLong(i)); |
| 4539 |
PyTuple_SetItem(tuple, 1, PyLong_FromLong(h2 - y + yOffset)); |
| 4540 |
PyList_SetItem(samples, i * 2, tuple); |
| 4541 |
tuple = PyTuple_New(2); |
| 4542 |
PyTuple_SetItem(tuple, 0, PyLong_FromLong(i)); |
| 4543 |
PyTuple_SetItem(tuple, 1, PyLong_FromLong(h2 + y + yOffset)); |
| 4544 |
PyList_SetItem(samples, i * 2 + 1, tuple); |
| 4545 |
} |
| 4546 |
} |
| 4547 |
|
| 4548 |
return samples; |
| 4549 |
}; |
| 4550 |
|
| 4551 |
static PyObject * |
| 4552 |
SndTable_getEnvelope(SndTable *self, PyObject *arg) |
| 4553 |
{ |
| 4554 |
T_SIZE_T i, j, step, points; |
| 4555 |
long count; |
| 4556 |
MYFLT absin, last; |
| 4557 |
PyObject *samples; |
| 4558 |
|
| 4559 |
ASSERT_ARG_NOT_NULL |
| 4560 |
|
| 4561 |
if (PyLong_Check(arg)) |
| 4562 |
{ |
| 4563 |
count = 0; |
| 4564 |
points = PyLong_AsLong(arg); |
| 4565 |
step = self->size / points; |
| 4566 |
samples = PyList_New(points); |
| 4567 |
|
| 4568 |
for (i = 0; i < points; i++) |
| 4569 |
{ |
| 4570 |
last = 0.0; |
| 4571 |
absin = 0.0; |
| 4572 |
|
| 4573 |
for (j = 0; j < step; j++) |
| 4574 |
{ |
| 4575 |
if (MYFABS(self->data[count++]) > absin) |
| 4576 |
absin = self->data[count]; |
| 4577 |
} |
| 4578 |
|
| 4579 |
last = (absin + last) * 0.5; |
| 4580 |
PyList_SetItem(samples, i, PyFloat_FromDouble(last)); |
| 4581 |
} |
| 4582 |
|
| 4583 |
return samples; |
| 4584 |
} |
| 4585 |
else |
| 4586 |
{ |
| 4587 |
Py_RETURN_NONE; |
| 4588 |
} |
| 4589 |
}; |
| 4590 |
|
| 4591 |
static PyObject * |
| 4592 |
SndTable_setSound(SndTable *self, PyObject *args, PyObject *kwds) |
| 4593 |
{ |
| 4594 |
Py_ssize_t psize; |
| 4595 |
static char *kwlist[] = {"path", "chnl", "start", "stop", NULL}; |
| 4596 |
|
| 4597 |
MYFLT stoptmp = -1.0; |
| 4598 |
|
| 4599 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_P_IFF, kwlist, &self->path, &psize, &self->chnl, &self->start, &stoptmp)) |
| 4600 |
{ |
| 4601 |
Py_RETURN_NONE; |
| 4602 |
} |
| 4603 |
|
| 4604 |
self->stop = stoptmp; |
| 4605 |
SndTable_loadSound(self); |
| 4606 |
|
| 4607 |
Py_RETURN_NONE; |
| 4608 |
} |
| 4609 |
|
| 4610 |
static PyObject * |
| 4611 |
SndTable_append(SndTable *self, PyObject *args, PyObject *kwds) |
| 4612 |
{ |
| 4613 |
Py_ssize_t psize; |
| 4614 |
static char *kwlist[] = {"path", "crossfade", "chnl", "start", "stop", NULL}; |
| 4615 |
|
| 4616 |
MYFLT stoptmp = -1.0; |
| 4617 |
MYFLT crosstmp = 0.0; |
| 4618 |
|
| 4619 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_P_FIFF, kwlist, &self->path, &psize, &crosstmp, &self->chnl, &self->start, &stoptmp)) |
| 4620 |
{ |
| 4621 |
Py_RETURN_NONE; |
| 4622 |
} |
| 4623 |
|
| 4624 |
self->stop = stoptmp; |
| 4625 |
|
| 4626 |
if (crosstmp < 0.0) |
| 4627 |
self->crossfade = 0.0; |
| 4628 |
else |
| 4629 |
self->crossfade = crosstmp; |
| 4630 |
|
| 4631 |
SndTable_appendSound(self); |
| 4632 |
|
| 4633 |
Py_RETURN_NONE; |
| 4634 |
} |
| 4635 |
|
| 4636 |
static PyObject * |
| 4637 |
SndTable_insert(SndTable *self, PyObject *args, PyObject *kwds) |
| 4638 |
{ |
| 4639 |
Py_ssize_t psize; |
| 4640 |
static char *kwlist[] = {"path", "pos", "crossfade", "chnl", "start", "stop", NULL}; |
| 4641 |
|
| 4642 |
MYFLT stoptmp = -1.0; |
| 4643 |
MYFLT crosstmp = 0.0; |
| 4644 |
MYFLT postmp = 0.0; |
| 4645 |
|
| 4646 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_P_FFIFF, kwlist, &self->path, &psize, &postmp, &crosstmp, &self->chnl, &self->start, &stoptmp)) |
| 4647 |
{ |
| 4648 |
Py_RETURN_NONE; |
| 4649 |
} |
| 4650 |
|
| 4651 |
self->stop = stoptmp; |
| 4652 |
|
| 4653 |
if (crosstmp < 0.0) |
| 4654 |
self->crossfade = 0.0; |
| 4655 |
else |
| 4656 |
self->crossfade = crosstmp; |
| 4657 |
|
| 4658 |
if (postmp <= 0.0) |
| 4659 |
SndTable_prependSound(self); |
| 4660 |
else if (postmp >= ((self->size - 1) / self->sndSr)) |
| 4661 |
SndTable_appendSound(self); |
| 4662 |
else |
| 4663 |
{ |
| 4664 |
self->insertPos = postmp; |
| 4665 |
SndTable_insertSound(self); |
| 4666 |
} |
| 4667 |
|
| 4668 |
Py_RETURN_NONE; |
| 4669 |
} |
| 4670 |
|
| 4671 |
static PyObject * |
| 4672 |
SndTable_setSize(SndTable *self, PyObject *value) |
| 4673 |
{ |
| 4674 |
|
| 4675 |
TABLE_SET_SIZE |
| 4676 |
|
| 4677 |
Py_RETURN_NONE; |
| 4678 |
} |
| 4679 |
|
| 4680 |
static PyObject * |
| 4681 |
SndTable_getSize(SndTable *self) |
| 4682 |
{ |
| 4683 |
return PyLong_FromLong(self->size); |
| 4684 |
}; |
| 4685 |
|
| 4686 |
static PyObject * |
| 4687 |
SndTable_getRate(SndTable *self) |
| 4688 |
{ |
| 4689 |
MYFLT sr = PyFloat_AsDouble(PyObject_CallMethod(self->server, "getSamplingRate", NULL)); |
| 4690 |
\ |
| 4691 |
return PyFloat_FromDouble(sr * (self->sndSr / sr) / self->size); |
| 4692 |
}; |
| 4693 |
|
| 4694 |
static PyMemberDef SndTable_members[] = |
| 4695 |
{ |
| 4696 |
{"server", T_OBJECT_EX, offsetof(SndTable, server), 0, "Pyo server."}, |
| 4697 |
{"tablestream", T_OBJECT_EX, offsetof(SndTable, tablestream), 0, "Table stream object."}, |
| 4698 |
{NULL} /* Sentinel */ |
| 4699 |
}; |
| 4700 |
|
| 4701 |
static PyMethodDef SndTable_methods[] = |
| 4702 |
{ |
| 4703 |
{"getServer", (PyCFunction)SndTable_getServer, METH_NOARGS, "Returns server object."}, |
| 4704 |
{"copy", (PyCFunction)SndTable_copy, METH_O, "Copy data from table given in argument."}, |
| 4705 |
{"copyData", (PyCFunction)SndTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 4706 |
{"rotate", (PyCFunction)SndTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 4707 |
{"setTable", (PyCFunction)SndTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 4708 |
{"getTable", (PyCFunction)SndTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 4709 |
{"getViewTable", (PyCFunction)SndTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 4710 |
{"getTableStream", (PyCFunction)SndTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 4711 |
{"getEnvelope", (PyCFunction)SndTable_getEnvelope, METH_O, "Returns X points envelope follower of the table."}, |
| 4712 |
{"setData", (PyCFunction)SndTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 4713 |
{"normalize", (PyCFunction)SndTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table samples"}, |
| 4714 |
{"reset", (PyCFunction)SndTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 4715 |
{"removeDC", (PyCFunction)SndTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 4716 |
{"reverse", (PyCFunction)SndTable_reverse, METH_NOARGS, "Reverse the table's data."}, |
| 4717 |
{"invert", (PyCFunction)SndTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 4718 |
{"rectify", (PyCFunction)SndTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 4719 |
{"bipolarGain", (PyCFunction)SndTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 4720 |
{"lowpass", (PyCFunction)SndTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 4721 |
{"fadein", (PyCFunction)SndTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 4722 |
{"fadeout", (PyCFunction)SndTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 4723 |
{"pow", (PyCFunction)SndTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 4724 |
{"put", (PyCFunction)SndTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 4725 |
{"get", (PyCFunction)SndTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 4726 |
{"setSound", (PyCFunction)SndTable_setSound, METH_VARARGS | METH_KEYWORDS, "Load a new sound in the table."}, |
| 4727 |
{"append", (PyCFunction)SndTable_append, METH_VARARGS | METH_KEYWORDS, "Append a sound in the table."}, |
| 4728 |
{"insert", (PyCFunction)SndTable_insert, METH_VARARGS | METH_KEYWORDS, "Insert a sound in the table."}, |
| 4729 |
{"setSize", (PyCFunction)SndTable_setSize, METH_O, "Sets the size of the table in samples"}, |
| 4730 |
{"getSize", (PyCFunction)SndTable_getSize, METH_NOARGS, "Return the size of the table in samples."}, |
| 4731 |
{"getRate", (PyCFunction)SndTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the sound without pitch transposition."}, |
| 4732 |
{"add", (PyCFunction)SndTable_add, METH_O, "Performs table addition."}, |
| 4733 |
{"sub", (PyCFunction)SndTable_sub, METH_O, "Performs table substraction."}, |
| 4734 |
{"mul", (PyCFunction)SndTable_mul, METH_O, "Performs table multiplication."}, |
| 4735 |
{"div", (PyCFunction)SndTable_div, METH_O, "Performs table division."}, |
| 4736 |
{NULL} /* Sentinel */ |
| 4737 |
}; |
| 4738 |
|
| 4739 |
PyTypeObject SndTableType = |
| 4740 |
{ |
| 4741 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 4742 |
"_pyo.SndTable_base", /*tp_name*/ |
| 4743 |
sizeof(SndTable), /*tp_basicsize*/ |
| 4744 |
0, /*tp_itemsize*/ |
| 4745 |
(destructor)SndTable_dealloc, /*tp_dealloc*/ |
| 4746 |
0, /*tp_print*/ |
| 4747 |
0, /*tp_getattr*/ |
| 4748 |
0, /*tp_setattr*/ |
| 4749 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 4750 |
0, /*tp_repr*/ |
| 4751 |
0, /*tp_as_number*/ |
| 4752 |
0, /*tp_as_sequence*/ |
| 4753 |
0, /*tp_as_mapping*/ |
| 4754 |
0, /*tp_hash */ |
| 4755 |
0, /*tp_call*/ |
| 4756 |
0, /*tp_str*/ |
| 4757 |
0, /*tp_getattro*/ |
| 4758 |
0, /*tp_setattro*/ |
| 4759 |
0, /*tp_as_buffer*/ |
| 4760 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 4761 |
"SndTable objects. Generates a table filled with a soundfile.", /* tp_doc */ |
| 4762 |
(traverseproc)SndTable_traverse, /* tp_traverse */ |
| 4763 |
(inquiry)SndTable_clear, /* tp_clear */ |
| 4764 |
0, /* tp_richcompare */ |
| 4765 |
0, /* tp_weaklistoffset */ |
| 4766 |
0, /* tp_iter */ |
| 4767 |
0, /* tp_iternext */ |
| 4768 |
SndTable_methods, /* tp_methods */ |
| 4769 |
SndTable_members, /* tp_members */ |
| 4770 |
0, /* tp_getset */ |
| 4771 |
0, /* tp_base */ |
| 4772 |
0, /* tp_dict */ |
| 4773 |
0, /* tp_descr_get */ |
| 4774 |
0, /* tp_descr_set */ |
| 4775 |
0, /* tp_dictoffset */ |
| 4776 |
0, /* tp_init */ |
| 4777 |
0, /* tp_alloc */ |
| 4778 |
SndTable_new, /* tp_new */ |
| 4779 |
0, /* tp_free */ |
| 4780 |
0, /* tp_is_gc */ |
| 4781 |
0, /* tp_bases */ |
| 4782 |
0, /* tp_mro */ |
| 4783 |
0, /* tp_cache */ |
| 4784 |
0, /* tp_subclasses */ |
| 4785 |
0, /* tp_weaklist */ |
| 4786 |
0, /* tp_del */ |
| 4787 |
}; |
| 4788 |
|
| 4789 |
/***********************/ |
| 4790 |
/* NewTable structure */ |
| 4791 |
/***********************/ |
| 4792 |
typedef struct |
| 4793 |
{ |
| 4794 |
pyo_table_HEAD |
| 4795 |
MYFLT length; |
| 4796 |
MYFLT feedback; |
| 4797 |
MYFLT sr; |
| 4798 |
} NewTable; |
| 4799 |
|
| 4800 |
static int |
| 4801 |
NewTable_traverse(NewTable *self, visitproc visit, void *arg) |
| 4802 |
{ |
| 4803 |
pyo_table_VISIT |
| 4804 |
return 0; |
| 4805 |
} |
| 4806 |
|
| 4807 |
static int |
| 4808 |
NewTable_clear(NewTable *self) |
| 4809 |
{ |
| 4810 |
pyo_table_CLEAR |
| 4811 |
return 0; |
| 4812 |
} |
| 4813 |
|
| 4814 |
static void |
| 4815 |
NewTable_dealloc(NewTable* self) |
| 4816 |
{ |
| 4817 |
PyMem_RawFree(self->data); |
| 4818 |
NewTable_clear(self); |
| 4819 |
Py_TYPE(self->tablestream)->tp_free((PyObject*)self->tablestream); |
| 4820 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 4821 |
} |
| 4822 |
|
| 4823 |
static PyObject * |
| 4824 |
NewTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 4825 |
{ |
| 4826 |
T_SIZE_T i; |
| 4827 |
PyObject *inittmp = NULL; |
| 4828 |
NewTable *self; |
| 4829 |
self = (NewTable *)type->tp_alloc(type, 0); |
| 4830 |
|
| 4831 |
self->server = PyServer_get_server(); |
| 4832 |
Py_INCREF(self->server); |
| 4833 |
|
| 4834 |
self->feedback = 0.0; |
| 4835 |
|
| 4836 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 4837 |
|
| 4838 |
static char *kwlist[] = {"length", "init", "feedback", NULL}; |
| 4839 |
|
| 4840 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_F_OF, kwlist, &self->length, &inittmp, &self->feedback)) |
| 4841 |
Py_RETURN_NONE; |
| 4842 |
|
| 4843 |
PyObject *srobj = PyObject_CallMethod(self->server, "getSamplingRate", NULL); |
| 4844 |
self->sr = (MYFLT)PyFloat_AsDouble(srobj); |
| 4845 |
Py_DECREF(srobj); |
| 4846 |
|
| 4847 |
self->size = (T_SIZE_T)(self->length * self->sr + 0.5); |
| 4848 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 4849 |
|
| 4850 |
for (i = 0; i < (self->size + 1); i++) |
| 4851 |
{ |
| 4852 |
self->data[i] = 0.; |
| 4853 |
} |
| 4854 |
|
| 4855 |
TableStream_setFeedback(self->tablestream, self->feedback); |
| 4856 |
|
| 4857 |
TableStream_setSize(self->tablestream, self->size); |
| 4858 |
|
| 4859 |
if (inittmp && PyList_Check(inittmp)) |
| 4860 |
{ |
| 4861 |
if (PyList_Size(inittmp) < self->size) |
| 4862 |
{ |
| 4863 |
for (i = 0; i < (self->size - PyList_Size(inittmp)); i++) |
| 4864 |
{ |
| 4865 |
PyList_Append(inittmp, PyFloat_FromDouble(0.0)); |
| 4866 |
} |
| 4867 |
PySys_WriteStdout("Warning: NewTable data length < size... padded with 0s.\n"); |
| 4868 |
} |
| 4869 |
else if (PyList_Size(inittmp) > self->size) |
| 4870 |
{ |
| 4871 |
inittmp = PyList_GetSlice(inittmp, 0, self->size); |
| 4872 |
PySys_WriteStdout("Warning: NewTable data length > size... truncated to size.\n"); |
| 4873 |
} |
| 4874 |
PyObject_CallMethod((PyObject *)self, "setTable", "O", inittmp); |
| 4875 |
} |
| 4876 |
|
| 4877 |
TableStream_setData(self->tablestream, self->data); |
| 4878 |
TableStream_setSamplingRate(self->tablestream, self->sr); |
| 4879 |
|
| 4880 |
return (PyObject *)self; |
| 4881 |
} |
| 4882 |
|
| 4883 |
static PyObject * NewTable_getServer(NewTable* self) { GET_SERVER }; |
| 4884 |
static PyObject * NewTable_getTableStream(NewTable* self) { GET_TABLE_STREAM }; |
| 4885 |
static PyObject * NewTable_setData(NewTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 4886 |
static PyObject * NewTable_normalize(NewTable *self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 4887 |
static PyObject * NewTable_reset(NewTable *self) { TABLE_RESET }; |
| 4888 |
static PyObject * NewTable_removeDC(NewTable *self) { REMOVE_DC }; |
| 4889 |
static PyObject * NewTable_reverse(NewTable *self) { REVERSE }; |
| 4890 |
static PyObject * NewTable_invert(NewTable *self) { INVERT }; |
| 4891 |
static PyObject * NewTable_rectify(NewTable *self) { RECTIFY }; |
| 4892 |
static PyObject * NewTable_bipolarGain(NewTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 4893 |
static PyObject * NewTable_lowpass(NewTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 4894 |
static PyObject * NewTable_fadein(NewTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 4895 |
static PyObject * NewTable_fadeout(NewTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 4896 |
static PyObject * NewTable_pow(NewTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 4897 |
static PyObject * NewTable_copy(NewTable *self, PyObject *arg) { COPY }; |
| 4898 |
static PyObject * NewTable_copyData(NewTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 4899 |
static PyObject * NewTable_rotate(NewTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 4900 |
static PyObject * NewTable_setTable(NewTable *self, PyObject *arg) { SET_TABLE }; |
| 4901 |
static PyObject * NewTable_getTable(NewTable *self) { GET_TABLE }; |
| 4902 |
static PyObject * NewTable_getRate(NewTable *self) { TABLE_GET_RATE }; |
| 4903 |
static PyObject * NewTable_put(NewTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 4904 |
static PyObject * NewTable_get(NewTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 4905 |
static PyObject * NewTable_add(NewTable *self, PyObject *arg) { TABLE_ADD }; |
| 4906 |
static PyObject * NewTable_sub(NewTable *self, PyObject *arg) { TABLE_SUB }; |
| 4907 |
static PyObject * NewTable_mul(NewTable *self, PyObject *arg) { TABLE_MUL }; |
| 4908 |
static PyObject * NewTable_div(NewTable *self, PyObject *arg) { TABLE_DIV }; |
| 4909 |
|
| 4910 |
static PyObject * |
| 4911 |
NewTable_getViewTable(NewTable *self, PyObject *args, PyObject *kwds) |
| 4912 |
{ |
| 4913 |
T_SIZE_T i, j, y, w, h, h2, step, size; |
| 4914 |
T_SIZE_T count = 0; |
| 4915 |
T_SIZE_T yOffset = 0; |
| 4916 |
MYFLT absin, fstep; |
| 4917 |
MYFLT begin = 0.0; |
| 4918 |
MYFLT end = -1.0; |
| 4919 |
PyObject *samples, *tuple; |
| 4920 |
PyObject *sizetmp = NULL; |
| 4921 |
|
| 4922 |
static char *kwlist[] = {"size", "begin", "end", "yOffset", NULL}; |
| 4923 |
|
| 4924 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE__OFFI, kwlist, &sizetmp, &begin, &end, &yOffset)) |
| 4925 |
return PyLong_FromLong(-1); |
| 4926 |
|
| 4927 |
if (end <= 0.0) |
| 4928 |
end = self->size; |
| 4929 |
else |
| 4930 |
{ |
| 4931 |
end = end * self->sr; |
| 4932 |
|
| 4933 |
if (end > self->size) |
| 4934 |
end = self->size; |
| 4935 |
} |
| 4936 |
|
| 4937 |
if (begin < 0.0) |
| 4938 |
begin = 0; |
| 4939 |
else |
| 4940 |
{ |
| 4941 |
begin = begin * self->sr; |
| 4942 |
|
| 4943 |
if (begin >= end) |
| 4944 |
begin = 0; |
| 4945 |
} |
| 4946 |
|
| 4947 |
size = (T_SIZE_T)(end - begin); |
| 4948 |
|
| 4949 |
if (sizetmp) |
| 4950 |
{ |
| 4951 |
if (PyTuple_Check(sizetmp)) |
| 4952 |
{ |
| 4953 |
w = PyLong_AsLong(PyTuple_GET_ITEM(sizetmp, 0)); |
| 4954 |
h = PyLong_AsLong(PyTuple_GET_ITEM(sizetmp, 1)); |
| 4955 |
} |
| 4956 |
else if (PyList_Check(sizetmp)) |
| 4957 |
{ |
| 4958 |
w = PyLong_AsLong(PyList_GET_ITEM(sizetmp, 0)); |
| 4959 |
h = PyLong_AsLong(PyList_GET_ITEM(sizetmp, 1)); |
| 4960 |
} |
| 4961 |
else |
| 4962 |
{ |
| 4963 |
w = 500; |
| 4964 |
h = 200; |
| 4965 |
} |
| 4966 |
} |
| 4967 |
else |
| 4968 |
{ |
| 4969 |
w = 500; |
| 4970 |
h = 200; |
| 4971 |
} |
| 4972 |
|
| 4973 |
h2 = h / 2; |
| 4974 |
step = (T_SIZE_T)(size / (MYFLT)(w)); |
| 4975 |
fstep = (MYFLT)(w) / (size - 1); |
| 4976 |
|
| 4977 |
if (step == 0) |
| 4978 |
{ |
| 4979 |
samples = PyList_New(size); |
| 4980 |
|
| 4981 |
for (i = 0; i < size; i++) |
| 4982 |
{ |
| 4983 |
tuple = PyTuple_New(2); |
| 4984 |
PyTuple_SetItem(tuple, 0, PyLong_FromLong((T_SIZE_T)(i * fstep))); |
| 4985 |
PyTuple_SetItem(tuple, 1, PyLong_FromLong(-self->data[i + (T_SIZE_T)(begin)]*h2 + h2 + yOffset)); |
| 4986 |
PyList_SetItem(samples, i, tuple); |
| 4987 |
} |
| 4988 |
} |
| 4989 |
else if (step < 32) |
| 4990 |
{ |
| 4991 |
samples = PyList_New(w); |
| 4992 |
|
| 4993 |
for (i = 0; i < w; i++) |
| 4994 |
{ |
| 4995 |
absin = 0.0; |
| 4996 |
|
| 4997 |
for (j = 0; j < step; j++) |
| 4998 |
{ |
| 4999 |
absin += -self->data[(T_SIZE_T)(begin) + count]; |
| 5000 |
count++; |
| 5001 |
} |
| 5002 |
|
| 5003 |
y = (int)(absin / step * h2); |
| 5004 |
tuple = PyTuple_New(2); |
| 5005 |
PyTuple_SetItem(tuple, 0, PyLong_FromLong(i)); |
| 5006 |
PyTuple_SetItem(tuple, 1, PyLong_FromLong(h2 + y + yOffset)); |
| 5007 |
PyList_SetItem(samples, i, tuple); |
| 5008 |
} |
| 5009 |
} |
| 5010 |
else |
| 5011 |
{ |
| 5012 |
samples = PyList_New(w * 2); |
| 5013 |
|
| 5014 |
for (i = 0; i < w; i++) |
| 5015 |
{ |
| 5016 |
absin = 0.0; |
| 5017 |
|
| 5018 |
for (j = 0; j < step; j++) |
| 5019 |
{ |
| 5020 |
if (MYFABS(self->data[(T_SIZE_T)(begin) + count]) > absin) |
| 5021 |
absin = -self->data[(T_SIZE_T)(begin) + count]; |
| 5022 |
|
| 5023 |
count++; |
| 5024 |
} |
| 5025 |
|
| 5026 |
y = (T_SIZE_T)(absin * h2); |
| 5027 |
tuple = PyTuple_New(2); |
| 5028 |
PyTuple_SetItem(tuple, 0, PyLong_FromLong(i)); |
| 5029 |
PyTuple_SetItem(tuple, 1, PyLong_FromLong(h2 - y + yOffset)); |
| 5030 |
PyList_SetItem(samples, i * 2, tuple); |
| 5031 |
tuple = PyTuple_New(2); |
| 5032 |
PyTuple_SetItem(tuple, 0, PyLong_FromLong(i)); |
| 5033 |
PyTuple_SetItem(tuple, 1, PyLong_FromLong(h2 + y + yOffset)); |
| 5034 |
PyList_SetItem(samples, i * 2 + 1, tuple); |
| 5035 |
} |
| 5036 |
} |
| 5037 |
|
| 5038 |
return samples; |
| 5039 |
}; |
| 5040 |
|
| 5041 |
static PyObject * |
| 5042 |
NewTable_setLength(NewTable *self, PyObject *value) |
| 5043 |
{ |
| 5044 |
if (value == NULL) |
| 5045 |
{ |
| 5046 |
PyErr_SetString(PyExc_TypeError, "Cannot delete the length attribute."); |
| 5047 |
return PyLong_FromLong(-1); |
| 5048 |
} |
| 5049 |
|
| 5050 |
if (! PyNumber_Check(value)) |
| 5051 |
{ |
| 5052 |
PyErr_SetString(PyExc_TypeError, "The length attribute value must be a number."); |
| 5053 |
return PyLong_FromLong(-1); |
| 5054 |
} |
| 5055 |
|
| 5056 |
MYFLT tmp = (MYFLT)PyFloat_AsDouble(value); |
| 5057 |
MYFLT diff = tmp - self->length; |
| 5058 |
|
| 5059 |
T_SIZE_T size = (T_SIZE_T)(tmp * self->sr + 0.5); |
| 5060 |
|
| 5061 |
MYFLT *data = (MYFLT *)PyMem_RawRealloc(self->data, (size + 1) * sizeof(MYFLT)); |
| 5062 |
if (data == NULL) |
| 5063 |
{ |
| 5064 |
Py_RETURN_NONE; |
| 5065 |
} |
| 5066 |
|
| 5067 |
self->data = data; |
| 5068 |
self->size = size; |
| 5069 |
self->length = tmp; |
| 5070 |
TableStream_setData(self->tablestream, self->data); |
| 5071 |
TableStream_setSize(self->tablestream, self->size); |
| 5072 |
|
| 5073 |
if (diff > 0) |
| 5074 |
{ |
| 5075 |
MYFLT startf = self->length - diff; |
| 5076 |
T_SIZE_T starti = (T_SIZE_T)(startf * self->sr + 0.5); |
| 5077 |
|
| 5078 |
for ( ; starti < (self->size + 1); starti++) |
| 5079 |
{ |
| 5080 |
self->data[starti] = 0.0; |
| 5081 |
} |
| 5082 |
} |
| 5083 |
|
| 5084 |
Py_RETURN_NONE; |
| 5085 |
} |
| 5086 |
|
| 5087 |
static PyObject * |
| 5088 |
NewTable_setSize(NewTable *self, PyObject *value) |
| 5089 |
{ |
| 5090 |
TABLE_SET_SIZE |
| 5091 |
|
| 5092 |
MYFLT oldLength = self->length; |
| 5093 |
self->length = self->size / self->sr; |
| 5094 |
MYFLT diff = self->length - oldLength; |
| 5095 |
|
| 5096 |
if (diff > 0) |
| 5097 |
{ |
| 5098 |
MYFLT startf = self->length - diff; |
| 5099 |
T_SIZE_T starti = (T_SIZE_T)(startf * self->sr); |
| 5100 |
|
| 5101 |
for ( ; starti < (self->size + 1); starti++) |
| 5102 |
{ |
| 5103 |
self->data[starti] = 0.0; |
| 5104 |
} |
| 5105 |
} |
| 5106 |
|
| 5107 |
Py_RETURN_NONE; |
| 5108 |
} |
| 5109 |
|
| 5110 |
static PyObject * |
| 5111 |
NewTable_getSize(NewTable *self) |
| 5112 |
{ |
| 5113 |
return PyLong_FromLong(self->size); |
| 5114 |
}; |
| 5115 |
|
| 5116 |
static PyObject * |
| 5117 |
NewTable_getLength(NewTable *self) |
| 5118 |
{ |
| 5119 |
return PyFloat_FromDouble(self->length); |
| 5120 |
}; |
| 5121 |
|
| 5122 |
static PyObject * |
| 5123 |
NewTable_setFeedback(NewTable *self, PyObject *value) |
| 5124 |
{ |
| 5125 |
MYFLT feed; |
| 5126 |
|
| 5127 |
if (PyNumber_Check(value)) |
| 5128 |
{ |
| 5129 |
feed = PyFloat_AsDouble(value); |
| 5130 |
|
| 5131 |
if (feed < -1.0) |
| 5132 |
feed = -1.0; |
| 5133 |
else if (feed > 1.0) |
| 5134 |
feed = 1.0; |
| 5135 |
|
| 5136 |
self->feedback = feed; |
| 5137 |
TableStream_setFeedback(self->tablestream, feed); |
| 5138 |
} |
| 5139 |
|
| 5140 |
Py_RETURN_NONE; |
| 5141 |
} |
| 5142 |
|
| 5143 |
static PyMemberDef NewTable_members[] = |
| 5144 |
{ |
| 5145 |
{"server", T_OBJECT_EX, offsetof(NewTable, server), 0, "Pyo server."}, |
| 5146 |
{"tablestream", T_OBJECT_EX, offsetof(NewTable, tablestream), 0, "Table stream object."}, |
| 5147 |
{NULL} /* Sentinel */ |
| 5148 |
}; |
| 5149 |
|
| 5150 |
static PyMethodDef NewTable_methods[] = |
| 5151 |
{ |
| 5152 |
{"getServer", (PyCFunction)NewTable_getServer, METH_NOARGS, "Returns server object."}, |
| 5153 |
{"setTable", (PyCFunction)NewTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 5154 |
{"getTable", (PyCFunction)NewTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 5155 |
{"getViewTable", (PyCFunction)NewTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 5156 |
{"getTableStream", (PyCFunction)NewTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 5157 |
{"setFeedback", (PyCFunction)NewTable_setFeedback, METH_O, "Feedback sets the amount of old data to mix with a new recording."}, |
| 5158 |
{"setData", (PyCFunction)NewTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 5159 |
{"setLength", (PyCFunction)NewTable_setLength, METH_O, "Change the size, given in seconds, of the table."}, |
| 5160 |
{"setSize", (PyCFunction)NewTable_setSize, METH_O, "Change the size, given in samples, of the table."}, |
| 5161 |
{"copy", (PyCFunction)NewTable_copy, METH_O, "Copy data from table given in argument."}, |
| 5162 |
{"copyData", (PyCFunction)NewTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 5163 |
{"rotate", (PyCFunction)NewTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 5164 |
{"normalize", (PyCFunction)NewTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table samples"}, |
| 5165 |
{"reset", (PyCFunction)NewTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 5166 |
{"removeDC", (PyCFunction)NewTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 5167 |
{"reverse", (PyCFunction)NewTable_reverse, METH_NOARGS, "Reverse the table's data."}, |
| 5168 |
{"invert", (PyCFunction)NewTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 5169 |
{"rectify", (PyCFunction)NewTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 5170 |
{"bipolarGain", (PyCFunction)NewTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 5171 |
{"lowpass", (PyCFunction)NewTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 5172 |
{"fadein", (PyCFunction)NewTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 5173 |
{"fadeout", (PyCFunction)NewTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 5174 |
{"pow", (PyCFunction)NewTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 5175 |
{"put", (PyCFunction)NewTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 5176 |
{"get", (PyCFunction)NewTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 5177 |
{"getSize", (PyCFunction)NewTable_getSize, METH_NOARGS, "Return the size of the table in samples."}, |
| 5178 |
{"getLength", (PyCFunction)NewTable_getLength, METH_NOARGS, "Return the length of the table in seconds."}, |
| 5179 |
{"getRate", (PyCFunction)NewTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the sound without pitch transposition."}, |
| 5180 |
{"add", (PyCFunction)NewTable_add, METH_O, "Performs table addition."}, |
| 5181 |
{"sub", (PyCFunction)NewTable_sub, METH_O, "Performs table substraction."}, |
| 5182 |
{"mul", (PyCFunction)NewTable_mul, METH_O, "Performs table multiplication."}, |
| 5183 |
{"div", (PyCFunction)NewTable_div, METH_O, "Performs table division."}, |
| 5184 |
{NULL} /* Sentinel */ |
| 5185 |
}; |
| 5186 |
|
| 5187 |
PyTypeObject NewTableType = |
| 5188 |
{ |
| 5189 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 5190 |
"_pyo.NewTable_base", /*tp_name*/ |
| 5191 |
sizeof(NewTable), /*tp_basicsize*/ |
| 5192 |
0, /*tp_itemsize*/ |
| 5193 |
(destructor)NewTable_dealloc, /*tp_dealloc*/ |
| 5194 |
0, /*tp_print*/ |
| 5195 |
0, /*tp_getattr*/ |
| 5196 |
0, /*tp_setattr*/ |
| 5197 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 5198 |
0, /*tp_repr*/ |
| 5199 |
0, /*tp_as_number*/ |
| 5200 |
0, /*tp_as_sequence*/ |
| 5201 |
0, /*tp_as_mapping*/ |
| 5202 |
0, /*tp_hash */ |
| 5203 |
0, /*tp_call*/ |
| 5204 |
0, /*tp_str*/ |
| 5205 |
0, /*tp_getattro*/ |
| 5206 |
0, /*tp_setattro*/ |
| 5207 |
0, /*tp_as_buffer*/ |
| 5208 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 5209 |
"NewTable objects. Generates an empty table.", /* tp_doc */ |
| 5210 |
(traverseproc)NewTable_traverse, /* tp_traverse */ |
| 5211 |
(inquiry)NewTable_clear, /* tp_clear */ |
| 5212 |
0, /* tp_richcompare */ |
| 5213 |
0, /* tp_weaklistoffset */ |
| 5214 |
0, /* tp_iter */ |
| 5215 |
0, /* tp_iternext */ |
| 5216 |
NewTable_methods, /* tp_methods */ |
| 5217 |
NewTable_members, /* tp_members */ |
| 5218 |
0, /* tp_getset */ |
| 5219 |
0, /* tp_base */ |
| 5220 |
0, /* tp_dict */ |
| 5221 |
0, /* tp_descr_get */ |
| 5222 |
0, /* tp_descr_set */ |
| 5223 |
0, /* tp_dictoffset */ |
| 5224 |
0, /* tp_init */ |
| 5225 |
0, /* tp_alloc */ |
| 5226 |
NewTable_new, /* tp_new */ |
| 5227 |
}; |
| 5228 |
|
| 5229 |
/***********************/ |
| 5230 |
/* DataTable structure */ |
| 5231 |
/***********************/ |
| 5232 |
typedef struct |
| 5233 |
{ |
| 5234 |
pyo_table_HEAD |
| 5235 |
MYFLT sr; |
| 5236 |
} DataTable; |
| 5237 |
|
| 5238 |
static int |
| 5239 |
DataTable_traverse(DataTable *self, visitproc visit, void *arg) |
| 5240 |
{ |
| 5241 |
pyo_table_VISIT |
| 5242 |
return 0; |
| 5243 |
} |
| 5244 |
|
| 5245 |
static int |
| 5246 |
DataTable_clear(DataTable *self) |
| 5247 |
{ |
| 5248 |
pyo_table_CLEAR |
| 5249 |
return 0; |
| 5250 |
} |
| 5251 |
|
| 5252 |
static void |
| 5253 |
DataTable_dealloc(DataTable* self) |
| 5254 |
{ |
| 5255 |
PyMem_RawFree(self->data); |
| 5256 |
DataTable_clear(self); |
| 5257 |
Py_TYPE(self->tablestream)->tp_free((PyObject*)self->tablestream); |
| 5258 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 5259 |
} |
| 5260 |
|
| 5261 |
static PyObject * |
| 5262 |
DataTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 5263 |
{ |
| 5264 |
T_SIZE_T i; |
| 5265 |
PyObject *inittmp = NULL; |
| 5266 |
DataTable *self; |
| 5267 |
self = (DataTable *)type->tp_alloc(type, 0); |
| 5268 |
|
| 5269 |
self->server = PyServer_get_server(); |
| 5270 |
Py_INCREF(self->server); |
| 5271 |
|
| 5272 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 5273 |
|
| 5274 |
static char *kwlist[] = {"size", "init", NULL}; |
| 5275 |
|
| 5276 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "n|O", kwlist, &self->size, &inittmp)) |
| 5277 |
Py_RETURN_NONE; |
| 5278 |
|
| 5279 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 5280 |
|
| 5281 |
for (i = 0; i < (self->size + 1); i++) |
| 5282 |
{ |
| 5283 |
self->data[i] = 0.; |
| 5284 |
} |
| 5285 |
|
| 5286 |
TableStream_setSize(self->tablestream, self->size); |
| 5287 |
|
| 5288 |
if (inittmp) |
| 5289 |
{ |
| 5290 |
PyObject_CallMethod((PyObject *)self, "setTable", "O", inittmp); |
| 5291 |
} |
| 5292 |
|
| 5293 |
TableStream_setData(self->tablestream, self->data); |
| 5294 |
|
| 5295 |
PyObject *srobj = PyObject_CallMethod(self->server, "getSamplingRate", NULL); |
| 5296 |
self->sr = (MYFLT)PyFloat_AsDouble(srobj); |
| 5297 |
Py_DECREF(srobj); |
| 5298 |
|
| 5299 |
TableStream_setSamplingRate(self->tablestream, self->sr); |
| 5300 |
|
| 5301 |
return (PyObject *)self; |
| 5302 |
} |
| 5303 |
|
| 5304 |
static PyObject * DataTable_getServer(DataTable* self) { GET_SERVER }; |
| 5305 |
static PyObject * DataTable_getTableStream(DataTable* self) { GET_TABLE_STREAM }; |
| 5306 |
static PyObject * DataTable_setData(DataTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 5307 |
static PyObject * DataTable_normalize(DataTable *self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 5308 |
static PyObject * DataTable_reset(DataTable *self) { TABLE_RESET }; |
| 5309 |
static PyObject * DataTable_removeDC(DataTable *self) { REMOVE_DC }; |
| 5310 |
static PyObject * DataTable_reverse(DataTable *self) { REVERSE }; |
| 5311 |
static PyObject * DataTable_invert(DataTable *self) { INVERT }; |
| 5312 |
static PyObject * DataTable_rectify(DataTable *self) { RECTIFY }; |
| 5313 |
static PyObject * DataTable_bipolarGain(DataTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 5314 |
static PyObject * DataTable_lowpass(DataTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 5315 |
static PyObject * DataTable_fadein(DataTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 5316 |
static PyObject * DataTable_fadeout(DataTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 5317 |
static PyObject * DataTable_pow(DataTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 5318 |
static PyObject * DataTable_copy(DataTable *self, PyObject *arg) { COPY }; |
| 5319 |
static PyObject * DataTable_copyData(DataTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 5320 |
static PyObject * DataTable_rotate(DataTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 5321 |
static PyObject * DataTable_setTable(DataTable *self, PyObject *arg) { SET_TABLE }; |
| 5322 |
static PyObject * DataTable_getTable(DataTable *self) { GET_TABLE }; |
| 5323 |
static PyObject * DataTable_getRate(DataTable *self) { TABLE_GET_RATE }; |
| 5324 |
static PyObject * DataTable_getViewTable(DataTable *self, PyObject *args, PyObject *kwds) { GET_VIEW_TABLE }; |
| 5325 |
static PyObject * DataTable_put(DataTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 5326 |
static PyObject * DataTable_get(DataTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 5327 |
static PyObject * DataTable_add(DataTable *self, PyObject *arg) { TABLE_ADD }; |
| 5328 |
static PyObject * DataTable_sub(DataTable *self, PyObject *arg) { TABLE_SUB }; |
| 5329 |
static PyObject * DataTable_mul(DataTable *self, PyObject *arg) { TABLE_MUL }; |
| 5330 |
static PyObject * DataTable_div(DataTable *self, PyObject *arg) { TABLE_DIV }; |
| 5331 |
|
| 5332 |
static PyObject * |
| 5333 |
DataTable_getSize(DataTable *self) |
| 5334 |
{ |
| 5335 |
return PyLong_FromLong(self->size); |
| 5336 |
}; |
| 5337 |
|
| 5338 |
static PyMemberDef DataTable_members[] = |
| 5339 |
{ |
| 5340 |
{"server", T_OBJECT_EX, offsetof(DataTable, server), 0, "Pyo server."}, |
| 5341 |
{"tablestream", T_OBJECT_EX, offsetof(DataTable, tablestream), 0, "Table stream object."}, |
| 5342 |
{NULL} /* Sentinel */ |
| 5343 |
}; |
| 5344 |
|
| 5345 |
static PyMethodDef DataTable_methods[] = |
| 5346 |
{ |
| 5347 |
{"getServer", (PyCFunction)DataTable_getServer, METH_NOARGS, "Returns server object."}, |
| 5348 |
{"copy", (PyCFunction)DataTable_copy, METH_O, "Copy data from table given in argument."}, |
| 5349 |
{"copyData", (PyCFunction)DataTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 5350 |
{"rotate", (PyCFunction)DataTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 5351 |
{"setTable", (PyCFunction)DataTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 5352 |
{"getTable", (PyCFunction)DataTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 5353 |
{"getViewTable", (PyCFunction)DataTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 5354 |
{"getTableStream", (PyCFunction)DataTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 5355 |
{"setData", (PyCFunction)DataTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 5356 |
{"normalize", (PyCFunction)DataTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table samples"}, |
| 5357 |
{"reset", (PyCFunction)DataTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 5358 |
{"removeDC", (PyCFunction)DataTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 5359 |
{"reverse", (PyCFunction)DataTable_reverse, METH_NOARGS, "Reverse the table's data."}, |
| 5360 |
{"invert", (PyCFunction)DataTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 5361 |
{"rectify", (PyCFunction)DataTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 5362 |
{"bipolarGain", (PyCFunction)DataTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 5363 |
{"lowpass", (PyCFunction)DataTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 5364 |
{"fadein", (PyCFunction)DataTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 5365 |
{"fadeout", (PyCFunction)DataTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 5366 |
{"pow", (PyCFunction)DataTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 5367 |
{"put", (PyCFunction)DataTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 5368 |
{"get", (PyCFunction)DataTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 5369 |
{"getSize", (PyCFunction)DataTable_getSize, METH_NOARGS, "Return the size of the table in samples."}, |
| 5370 |
{"getRate", (PyCFunction)DataTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the sound without pitch transposition."}, |
| 5371 |
{"add", (PyCFunction)DataTable_add, METH_O, "Performs table addition."}, |
| 5372 |
{"sub", (PyCFunction)DataTable_sub, METH_O, "Performs table substraction."}, |
| 5373 |
{"mul", (PyCFunction)DataTable_mul, METH_O, "Performs table multiplication."}, |
| 5374 |
{"div", (PyCFunction)DataTable_div, METH_O, "Performs table division."}, |
| 5375 |
{NULL} /* Sentinel */ |
| 5376 |
}; |
| 5377 |
|
| 5378 |
PyTypeObject DataTableType = |
| 5379 |
{ |
| 5380 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 5381 |
"_pyo.DataTable_base", /*tp_name*/ |
| 5382 |
sizeof(DataTable), /*tp_basicsize*/ |
| 5383 |
0, /*tp_itemsize*/ |
| 5384 |
(destructor)DataTable_dealloc, /*tp_dealloc*/ |
| 5385 |
0, /*tp_print*/ |
| 5386 |
0, /*tp_getattr*/ |
| 5387 |
0, /*tp_setattr*/ |
| 5388 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 5389 |
0, /*tp_repr*/ |
| 5390 |
0, /*tp_as_number*/ |
| 5391 |
0, /*tp_as_sequence*/ |
| 5392 |
0, /*tp_as_mapping*/ |
| 5393 |
0, /*tp_hash */ |
| 5394 |
0, /*tp_call*/ |
| 5395 |
0, /*tp_str*/ |
| 5396 |
0, /*tp_getattro*/ |
| 5397 |
0, /*tp_setattro*/ |
| 5398 |
0, /*tp_as_buffer*/ |
| 5399 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 5400 |
"DataTable objects. Generates an empty table.", /* tp_doc */ |
| 5401 |
(traverseproc)DataTable_traverse, /* tp_traverse */ |
| 5402 |
(inquiry)DataTable_clear, /* tp_clear */ |
| 5403 |
0, /* tp_richcompare */ |
| 5404 |
0, /* tp_weaklistoffset */ |
| 5405 |
0, /* tp_iter */ |
| 5406 |
0, /* tp_iternext */ |
| 5407 |
DataTable_methods, /* tp_methods */ |
| 5408 |
DataTable_members, /* tp_members */ |
| 5409 |
0, /* tp_getset */ |
| 5410 |
0, /* tp_base */ |
| 5411 |
0, /* tp_dict */ |
| 5412 |
0, /* tp_descr_get */ |
| 5413 |
0, /* tp_descr_set */ |
| 5414 |
0, /* tp_dictoffset */ |
| 5415 |
0, /* tp_init */ |
| 5416 |
0, /* tp_alloc */ |
| 5417 |
DataTable_new, /* tp_new */ |
| 5418 |
}; |
| 5419 |
|
| 5420 |
/***********************/ |
| 5421 |
/* AtanTable structure */ |
| 5422 |
/***********************/ |
| 5423 |
typedef struct |
| 5424 |
{ |
| 5425 |
pyo_table_HEAD |
| 5426 |
MYFLT slope; |
| 5427 |
} AtanTable; |
| 5428 |
|
| 5429 |
static void |
| 5430 |
AtanTable_generate(AtanTable *self) |
| 5431 |
{ |
| 5432 |
T_SIZE_T i, hsize; |
| 5433 |
MYFLT drv, invhsize, val, t, fac = 0; |
| 5434 |
|
| 5435 |
hsize = self->size / 2; |
| 5436 |
invhsize = 1.0 / hsize; |
| 5437 |
|
| 5438 |
drv = 1 - self->slope; |
| 5439 |
drv = drv * drv * drv * PI; |
| 5440 |
|
| 5441 |
for (i = 0; i <= hsize; i++) |
| 5442 |
{ |
| 5443 |
t = i * invhsize - 1; |
| 5444 |
val = MYATAN2(t, drv); |
| 5445 |
|
| 5446 |
if (i == 0) |
| 5447 |
fac = 1.0 / -val; |
| 5448 |
|
| 5449 |
val = val * fac; |
| 5450 |
self->data[i] = val; |
| 5451 |
self->data[self->size - i] = -val; |
| 5452 |
} |
| 5453 |
} |
| 5454 |
|
| 5455 |
static int |
| 5456 |
AtanTable_traverse(AtanTable *self, visitproc visit, void *arg) |
| 5457 |
{ |
| 5458 |
pyo_table_VISIT |
| 5459 |
return 0; |
| 5460 |
} |
| 5461 |
|
| 5462 |
static int |
| 5463 |
AtanTable_clear(AtanTable *self) |
| 5464 |
{ |
| 5465 |
pyo_table_CLEAR |
| 5466 |
return 0; |
| 5467 |
} |
| 5468 |
|
| 5469 |
static void |
| 5470 |
AtanTable_dealloc(AtanTable* self) |
| 5471 |
{ |
| 5472 |
PyMem_RawFree(self->data); |
| 5473 |
AtanTable_clear(self); |
| 5474 |
Py_TYPE(self->tablestream)->tp_free((PyObject*)self->tablestream); |
| 5475 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 5476 |
} |
| 5477 |
|
| 5478 |
static PyObject * |
| 5479 |
AtanTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 5480 |
{ |
| 5481 |
AtanTable *self; |
| 5482 |
self = (AtanTable *)type->tp_alloc(type, 0); |
| 5483 |
|
| 5484 |
self->server = PyServer_get_server(); |
| 5485 |
Py_INCREF(self->server); |
| 5486 |
|
| 5487 |
self->size = 8192; |
| 5488 |
self->slope = 0.5; |
| 5489 |
|
| 5490 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 5491 |
|
| 5492 |
static char *kwlist[] = {"slope", "size", NULL}; |
| 5493 |
|
| 5494 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_F_N, kwlist, &self->slope, &self->size)) |
| 5495 |
Py_RETURN_NONE; |
| 5496 |
|
| 5497 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 5498 |
TableStream_setSize(self->tablestream, self->size); |
| 5499 |
TableStream_setData(self->tablestream, self->data); |
| 5500 |
AtanTable_generate(self); |
| 5501 |
|
| 5502 |
PyObject *srobj = PyObject_CallMethod(self->server, "getSamplingRate", NULL); |
| 5503 |
double sr = PyFloat_AsDouble(srobj); |
| 5504 |
Py_DECREF(srobj); |
| 5505 |
|
| 5506 |
TableStream_setSamplingRate(self->tablestream, sr); |
| 5507 |
|
| 5508 |
return (PyObject *)self; |
| 5509 |
} |
| 5510 |
|
| 5511 |
static PyObject * AtanTable_getServer(AtanTable* self) { GET_SERVER }; |
| 5512 |
static PyObject * AtanTable_getTableStream(AtanTable* self) { GET_TABLE_STREAM }; |
| 5513 |
static PyObject * AtanTable_setData(AtanTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 5514 |
static PyObject * AtanTable_normalize(AtanTable *self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 5515 |
static PyObject * AtanTable_reset(AtanTable *self) { TABLE_RESET }; |
| 5516 |
static PyObject * AtanTable_removeDC(AtanTable *self) { REMOVE_DC }; |
| 5517 |
static PyObject * AtanTable_reverse(AtanTable *self) { REVERSE }; |
| 5518 |
static PyObject * AtanTable_invert(AtanTable *self) { INVERT }; |
| 5519 |
static PyObject * AtanTable_rectify(AtanTable *self) { RECTIFY }; |
| 5520 |
static PyObject * AtanTable_bipolarGain(AtanTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 5521 |
static PyObject * AtanTable_lowpass(AtanTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 5522 |
static PyObject * AtanTable_fadein(AtanTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 5523 |
static PyObject * AtanTable_fadeout(AtanTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 5524 |
static PyObject * AtanTable_pow(AtanTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 5525 |
static PyObject * AtanTable_copy(AtanTable *self, PyObject *arg) { COPY }; |
| 5526 |
static PyObject * AtanTable_copyData(AtanTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 5527 |
static PyObject * AtanTable_rotate(AtanTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 5528 |
static PyObject * AtanTable_setTable(AtanTable *self, PyObject *arg) { SET_TABLE }; |
| 5529 |
static PyObject * AtanTable_getTable(AtanTable *self) { GET_TABLE }; |
| 5530 |
static PyObject * AtanTable_getRate(AtanTable *self) { TABLE_GET_RATE }; |
| 5531 |
static PyObject * AtanTable_getViewTable(AtanTable *self, PyObject *args, PyObject *kwds) { GET_VIEW_TABLE }; |
| 5532 |
static PyObject * AtanTable_put(AtanTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 5533 |
static PyObject * AtanTable_get(AtanTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 5534 |
static PyObject * AtanTable_add(AtanTable *self, PyObject *arg) { TABLE_ADD }; |
| 5535 |
static PyObject * AtanTable_sub(AtanTable *self, PyObject *arg) { TABLE_SUB }; |
| 5536 |
static PyObject * AtanTable_mul(AtanTable *self, PyObject *arg) { TABLE_MUL }; |
| 5537 |
static PyObject * AtanTable_div(AtanTable *self, PyObject *arg) { TABLE_DIV }; |
| 5538 |
|
| 5539 |
static PyObject * |
| 5540 |
AtanTable_setSlope(AtanTable *self, PyObject *value) |
| 5541 |
{ |
| 5542 |
|
| 5543 |
if (! PyNumber_Check(value)) |
| 5544 |
{ |
| 5545 |
PyErr_SetString(PyExc_TypeError, "The slope attribute value must be a number."); |
| 5546 |
return PyLong_FromLong(-1); |
| 5547 |
} |
| 5548 |
|
| 5549 |
self->slope = PyFloat_AsDouble(value); |
| 5550 |
|
| 5551 |
if (self->slope < 0.0) |
| 5552 |
self->slope = 0.0; |
| 5553 |
else if (self->slope > 1.0) |
| 5554 |
self->slope = 1.0; |
| 5555 |
|
| 5556 |
AtanTable_generate(self); |
| 5557 |
|
| 5558 |
Py_RETURN_NONE; |
| 5559 |
} |
| 5560 |
|
| 5561 |
static PyObject * |
| 5562 |
AtanTable_setSize(AtanTable *self, PyObject *value) |
| 5563 |
{ |
| 5564 |
TABLE_SET_SIZE |
| 5565 |
|
| 5566 |
AtanTable_generate(self); |
| 5567 |
|
| 5568 |
Py_RETURN_NONE; |
| 5569 |
} |
| 5570 |
|
| 5571 |
static PyObject * |
| 5572 |
AtanTable_getSize(AtanTable *self) |
| 5573 |
{ |
| 5574 |
return PyLong_FromLong(self->size); |
| 5575 |
}; |
| 5576 |
|
| 5577 |
static PyMemberDef AtanTable_members[] = |
| 5578 |
{ |
| 5579 |
{"server", T_OBJECT_EX, offsetof(AtanTable, server), 0, "Pyo server."}, |
| 5580 |
{"tablestream", T_OBJECT_EX, offsetof(AtanTable, tablestream), 0, "Table stream object."}, |
| 5581 |
{NULL} /* Sentinel */ |
| 5582 |
}; |
| 5583 |
|
| 5584 |
static PyMethodDef AtanTable_methods[] = |
| 5585 |
{ |
| 5586 |
{"getServer", (PyCFunction)AtanTable_getServer, METH_NOARGS, "Returns server object."}, |
| 5587 |
{"copy", (PyCFunction)AtanTable_copy, METH_O, "Copy data from table given in argument."}, |
| 5588 |
{"copyData", (PyCFunction)AtanTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 5589 |
{"rotate", (PyCFunction)AtanTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 5590 |
{"setTable", (PyCFunction)AtanTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 5591 |
{"getTable", (PyCFunction)AtanTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 5592 |
{"getViewTable", (PyCFunction)AtanTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 5593 |
{"getTableStream", (PyCFunction)AtanTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 5594 |
{"setData", (PyCFunction)AtanTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 5595 |
{"normalize", (PyCFunction)AtanTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table samples"}, |
| 5596 |
{"reset", (PyCFunction)AtanTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 5597 |
{"removeDC", (PyCFunction)AtanTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 5598 |
{"reverse", (PyCFunction)AtanTable_reverse, METH_NOARGS, "Reverse the table's data."}, |
| 5599 |
{"invert", (PyCFunction)AtanTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 5600 |
{"rectify", (PyCFunction)AtanTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 5601 |
{"bipolarGain", (PyCFunction)AtanTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 5602 |
{"lowpass", (PyCFunction)AtanTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 5603 |
{"fadein", (PyCFunction)AtanTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 5604 |
{"fadeout", (PyCFunction)AtanTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 5605 |
{"pow", (PyCFunction)AtanTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 5606 |
{"setSize", (PyCFunction)AtanTable_setSize, METH_O, "Sets the size of the table in samples"}, |
| 5607 |
{"getSize", (PyCFunction)AtanTable_getSize, METH_NOARGS, "Return the size of the table in samples"}, |
| 5608 |
{"getRate", (PyCFunction)AtanTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the table without pitch transposition."}, |
| 5609 |
{"setSlope", (PyCFunction)AtanTable_setSlope, METH_O, "Sets the slope of the atan function."}, |
| 5610 |
{"put", (PyCFunction)AtanTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 5611 |
{"get", (PyCFunction)AtanTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 5612 |
{"add", (PyCFunction)AtanTable_add, METH_O, "Performs table addition."}, |
| 5613 |
{"sub", (PyCFunction)AtanTable_sub, METH_O, "Performs table substraction."}, |
| 5614 |
{"mul", (PyCFunction)AtanTable_mul, METH_O, "Performs table multiplication."}, |
| 5615 |
{"div", (PyCFunction)AtanTable_div, METH_O, "Performs table division."}, |
| 5616 |
{NULL} /* Sentinel */ |
| 5617 |
}; |
| 5618 |
|
| 5619 |
PyTypeObject AtanTableType = |
| 5620 |
{ |
| 5621 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 5622 |
"_pyo.AtanTable_base", /*tp_name*/ |
| 5623 |
sizeof(AtanTable), /*tp_basicsize*/ |
| 5624 |
0, /*tp_itemsize*/ |
| 5625 |
(destructor)AtanTable_dealloc, /*tp_dealloc*/ |
| 5626 |
0, /*tp_print*/ |
| 5627 |
0, /*tp_getattr*/ |
| 5628 |
0, /*tp_setattr*/ |
| 5629 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 5630 |
0, /*tp_repr*/ |
| 5631 |
0, /*tp_as_number*/ |
| 5632 |
0, /*tp_as_sequence*/ |
| 5633 |
0, /*tp_as_mapping*/ |
| 5634 |
0, /*tp_hash */ |
| 5635 |
0, /*tp_call*/ |
| 5636 |
0, /*tp_str*/ |
| 5637 |
0, /*tp_getattro*/ |
| 5638 |
0, /*tp_setattro*/ |
| 5639 |
0, /*tp_as_buffer*/ |
| 5640 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 5641 |
"AtanTable objects. Generates a table filled with a sinc function.", /* tp_doc */ |
| 5642 |
(traverseproc)AtanTable_traverse, /* tp_traverse */ |
| 5643 |
(inquiry)AtanTable_clear, /* tp_clear */ |
| 5644 |
0, /* tp_richcompare */ |
| 5645 |
0, /* tp_weaklistoffset */ |
| 5646 |
0, /* tp_iter */ |
| 5647 |
0, /* tp_iternext */ |
| 5648 |
AtanTable_methods, /* tp_methods */ |
| 5649 |
AtanTable_members, /* tp_members */ |
| 5650 |
0, /* tp_getset */ |
| 5651 |
0, /* tp_base */ |
| 5652 |
0, /* tp_dict */ |
| 5653 |
0, /* tp_descr_get */ |
| 5654 |
0, /* tp_descr_set */ |
| 5655 |
0, /* tp_dictoffset */ |
| 5656 |
0, /* tp_init */ |
| 5657 |
0, /* tp_alloc */ |
| 5658 |
AtanTable_new, /* tp_new */ |
| 5659 |
}; |
| 5660 |
|
| 5661 |
static int |
| 5662 |
isPowerOfTwo(int x) |
| 5663 |
{ |
| 5664 |
return (x != 0) && ((x & (x - 1)) == 0); |
| 5665 |
} |
| 5666 |
|
| 5667 |
/***********************/ |
| 5668 |
/* PadSynthTable structure */ |
| 5669 |
/***********************/ |
| 5670 |
typedef struct |
| 5671 |
{ |
| 5672 |
pyo_table_HEAD |
| 5673 |
MYFLT **twiddle; |
| 5674 |
MYFLT basefreq; |
| 5675 |
MYFLT spread; |
| 5676 |
MYFLT bw; |
| 5677 |
MYFLT bwscl; |
| 5678 |
int nharms; |
| 5679 |
MYFLT damp; |
| 5680 |
double sr; |
| 5681 |
MYFLT *amp; |
| 5682 |
MYFLT *inframe; |
| 5683 |
int allocated; |
| 5684 |
} PadSynthTable; |
| 5685 |
|
| 5686 |
static void |
| 5687 |
PadSynthTable_gen_twiddle(PadSynthTable *self) |
| 5688 |
{ |
| 5689 |
int i, n8; |
| 5690 |
n8 = self->size >> 3; |
| 5691 |
|
| 5692 |
if (self->allocated) |
| 5693 |
{ |
| 5694 |
for (i = 0; i < 4; i++) |
| 5695 |
PyMem_RawFree(self->twiddle[i]); |
| 5696 |
} |
| 5697 |
|
| 5698 |
self->twiddle = (MYFLT **)PyMem_RawRealloc(self->twiddle, 4 * sizeof(MYFLT *)); |
| 5699 |
|
| 5700 |
for (i = 0; i < 4; i++) |
| 5701 |
self->twiddle[i] = (MYFLT *)PyMem_RawMalloc(n8 * sizeof(MYFLT)); |
| 5702 |
|
| 5703 |
fft_compute_split_twiddle(self->twiddle, self->size); |
| 5704 |
|
| 5705 |
self->allocated = 1; |
| 5706 |
} |
| 5707 |
|
| 5708 |
static void |
| 5709 |
PadSynthTable_generate(PadSynthTable *self) |
| 5710 |
{ |
| 5711 |
T_SIZE_T i, hsize = self->size / 2; |
| 5712 |
int nh; |
| 5713 |
MYFLT bfac, i2sr, bfonsr, nhspd, bwhz, bwi, fi, gain, absv, max, x, phase; |
| 5714 |
MYFLT ifsize = 1.0 / (MYFLT)self->size; |
| 5715 |
MYFLT twopirndmax = TWOPI / (MYFLT)RAND_MAX; |
| 5716 |
|
| 5717 |
for (i = 0; i < hsize; i++) |
| 5718 |
{ |
| 5719 |
self->amp[i] = 0.0; |
| 5720 |
} |
| 5721 |
|
| 5722 |
bfac = (MYPOW(2.0, self->bw / 1200.0) - 1.0) * self->basefreq; |
| 5723 |
i2sr = 1.0 / (2.0 * self->sr); |
| 5724 |
bfonsr = self->basefreq / self->sr; |
| 5725 |
gain = self->damp; |
| 5726 |
|
| 5727 |
for (nh = 1; nh < self->nharms; nh++) |
| 5728 |
{ |
| 5729 |
nhspd = MYPOW(nh, self->spread); |
| 5730 |
bwhz = bfac * MYPOW(nhspd, self->bwscl); |
| 5731 |
bwi = 1.0 / (bwhz * i2sr); |
| 5732 |
fi = bfonsr * nhspd; |
| 5733 |
|
| 5734 |
for (i = 0; i < hsize; i++) |
| 5735 |
{ |
| 5736 |
// harmonic profile. |
| 5737 |
x = (i * ifsize - fi) * bwi; |
| 5738 |
x *= x; |
| 5739 |
|
| 5740 |
if (x < 14.71280603) |
| 5741 |
self->amp[i] += MYEXP(-x) * bwi * gain; |
| 5742 |
} |
| 5743 |
|
| 5744 |
gain *= self->damp; |
| 5745 |
} |
| 5746 |
|
| 5747 |
phase = rand() * twopirndmax; |
| 5748 |
self->inframe[0] = self->amp[0] * MYCOS(phase); |
| 5749 |
self->inframe[hsize] = 0.0; |
| 5750 |
|
| 5751 |
for (i = 1; i < hsize; i++) |
| 5752 |
{ |
| 5753 |
phase = rand() * twopirndmax; |
| 5754 |
self->inframe[i] = self->amp[i] * MYCOS(phase); |
| 5755 |
self->inframe[self->size - i] = self->amp[i] * MYSIN(phase); |
| 5756 |
} |
| 5757 |
|
| 5758 |
irealfft_split(self->inframe, self->data, self->size, self->twiddle); |
| 5759 |
|
| 5760 |
max = 0.0; |
| 5761 |
|
| 5762 |
for (i = 0; i < self->size; i++) |
| 5763 |
{ |
| 5764 |
absv = MYFABS(self->data[i]); |
| 5765 |
|
| 5766 |
if (absv > max) |
| 5767 |
max = absv; |
| 5768 |
} |
| 5769 |
|
| 5770 |
if (max < 1e-5) |
| 5771 |
max = 1e-5; |
| 5772 |
|
| 5773 |
max = 1.0 / (max * 1.4142); |
| 5774 |
|
| 5775 |
for (i = 0; i < self->size; i++) |
| 5776 |
{ |
| 5777 |
self->data[i] *= max; |
| 5778 |
} |
| 5779 |
|
| 5780 |
self->data[self->size] = self->data[0]; |
| 5781 |
} |
| 5782 |
|
| 5783 |
static int |
| 5784 |
PadSynthTable_traverse(PadSynthTable *self, visitproc visit, void *arg) |
| 5785 |
{ |
| 5786 |
pyo_table_VISIT |
| 5787 |
return 0; |
| 5788 |
} |
| 5789 |
|
| 5790 |
static int |
| 5791 |
PadSynthTable_clear(PadSynthTable *self) |
| 5792 |
{ |
| 5793 |
pyo_table_CLEAR |
| 5794 |
return 0; |
| 5795 |
} |
| 5796 |
|
| 5797 |
static void |
| 5798 |
PadSynthTable_dealloc(PadSynthTable* self) |
| 5799 |
{ |
| 5800 |
int i; |
| 5801 |
|
| 5802 |
for (i = 0; i < 4; i++) |
| 5803 |
{ |
| 5804 |
PyMem_RawFree(self->twiddle[i]); |
| 5805 |
} |
| 5806 |
|
| 5807 |
PyMem_RawFree(self->twiddle); |
| 5808 |
PyMem_RawFree(self->data); |
| 5809 |
PyMem_RawFree(self->amp); |
| 5810 |
PyMem_RawFree(self->inframe); |
| 5811 |
PadSynthTable_clear(self); |
| 5812 |
Py_TYPE(self->tablestream)->tp_free((PyObject*)self->tablestream); |
| 5813 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 5814 |
} |
| 5815 |
|
| 5816 |
static PyObject * |
| 5817 |
PadSynthTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 5818 |
{ |
| 5819 |
PadSynthTable *self; |
| 5820 |
self = (PadSynthTable *)type->tp_alloc(type, 0); |
| 5821 |
|
| 5822 |
self->server = PyServer_get_server(); |
| 5823 |
Py_INCREF(self->server); |
| 5824 |
|
| 5825 |
self->size = 262144; |
| 5826 |
self->basefreq = 440; |
| 5827 |
self->spread = 1.0; |
| 5828 |
self->bw = 50.0; |
| 5829 |
self->bwscl = 1.0; |
| 5830 |
self->nharms = 64; |
| 5831 |
self->damp = 0.7; |
| 5832 |
self->allocated = 0; |
| 5833 |
|
| 5834 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 5835 |
|
| 5836 |
static char *kwlist[] = {"basefreq", "spread", "bw", "bwscl", "nharms", "damp", "size", NULL}; |
| 5837 |
|
| 5838 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE__FFFFIFN, kwlist, &self->basefreq, &self->spread, &self->bw, |
| 5839 |
&self->bwscl, &self->nharms, &self->damp, &self->size)) |
| 5840 |
Py_RETURN_NONE; |
| 5841 |
|
| 5842 |
if (!isPowerOfTwo(self->size)) |
| 5843 |
{ |
| 5844 |
int k = 1; |
| 5845 |
|
| 5846 |
while (k < self->size) |
| 5847 |
k *= 2; |
| 5848 |
|
| 5849 |
self->size = k; |
| 5850 |
PySys_WriteStdout("PadSynthTable size must be a power-of-2, using the next power-of-2 greater than size : %ld\n", (long)self->size); |
| 5851 |
} |
| 5852 |
|
| 5853 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 5854 |
self->amp = (MYFLT *)PyMem_RawRealloc(self->amp, (self->size / 2) * sizeof(MYFLT)); |
| 5855 |
self->inframe = (MYFLT *)PyMem_RawRealloc(self->inframe, self->size * sizeof(MYFLT)); |
| 5856 |
TableStream_setSize(self->tablestream, self->size); |
| 5857 |
TableStream_setData(self->tablestream, self->data); |
| 5858 |
|
| 5859 |
PyObject *srobj = PyObject_CallMethod(self->server, "getSamplingRate", NULL); |
| 5860 |
self->sr = PyFloat_AsDouble(srobj); |
| 5861 |
Py_DECREF(srobj); |
| 5862 |
|
| 5863 |
TableStream_setSamplingRate(self->tablestream, self->sr); |
| 5864 |
|
| 5865 |
PadSynthTable_gen_twiddle(self); |
| 5866 |
|
| 5867 |
srand(time(NULL)); |
| 5868 |
PadSynthTable_generate(self); |
| 5869 |
|
| 5870 |
return (PyObject *)self; |
| 5871 |
} |
| 5872 |
|
| 5873 |
static PyObject * PadSynthTable_getServer(PadSynthTable* self) { GET_SERVER }; |
| 5874 |
static PyObject * PadSynthTable_getTableStream(PadSynthTable* self) { GET_TABLE_STREAM }; |
| 5875 |
static PyObject * PadSynthTable_setData(PadSynthTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 5876 |
static PyObject * PadSynthTable_normalize(PadSynthTable *self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 5877 |
static PyObject * PadSynthTable_reset(PadSynthTable *self) { TABLE_RESET }; |
| 5878 |
static PyObject * PadSynthTable_removeDC(PadSynthTable *self) { REMOVE_DC }; |
| 5879 |
static PyObject * PadSynthTable_reverse(PadSynthTable *self) { REVERSE }; |
| 5880 |
static PyObject * PadSynthTable_invert(PadSynthTable *self) { INVERT }; |
| 5881 |
static PyObject * PadSynthTable_rectify(PadSynthTable *self) { RECTIFY }; |
| 5882 |
static PyObject * PadSynthTable_bipolarGain(PadSynthTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 5883 |
static PyObject * PadSynthTable_lowpass(PadSynthTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 5884 |
static PyObject * PadSynthTable_fadein(PadSynthTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 5885 |
static PyObject * PadSynthTable_fadeout(PadSynthTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 5886 |
static PyObject * PadSynthTable_pow(PadSynthTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 5887 |
static PyObject * PadSynthTable_copy(PadSynthTable *self, PyObject *arg) { COPY }; |
| 5888 |
static PyObject * PadSynthTable_copyData(PadSynthTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 5889 |
static PyObject * PadSynthTable_rotate(PadSynthTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 5890 |
static PyObject * PadSynthTable_setTable(PadSynthTable *self, PyObject *arg) { SET_TABLE }; |
| 5891 |
static PyObject * PadSynthTable_getTable(PadSynthTable *self) { GET_TABLE }; |
| 5892 |
static PyObject * PadSynthTable_getRate(PadSynthTable *self) { TABLE_GET_RATE }; |
| 5893 |
static PyObject * PadSynthTable_getViewTable(PadSynthTable *self, PyObject *args, PyObject *kwds) { GET_VIEW_TABLE }; |
| 5894 |
static PyObject * PadSynthTable_put(PadSynthTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 5895 |
static PyObject * PadSynthTable_get(PadSynthTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 5896 |
static PyObject * PadSynthTable_add(PadSynthTable *self, PyObject *arg) { TABLE_ADD }; |
| 5897 |
static PyObject * PadSynthTable_sub(PadSynthTable *self, PyObject *arg) { TABLE_SUB }; |
| 5898 |
static PyObject * PadSynthTable_mul(PadSynthTable *self, PyObject *arg) { TABLE_MUL }; |
| 5899 |
static PyObject * PadSynthTable_div(PadSynthTable *self, PyObject *arg) { TABLE_DIV }; |
| 5900 |
|
| 5901 |
static PyObject * |
| 5902 |
PadSynthTable_setBaseFreq(PadSynthTable *self, PyObject *args, PyObject *kwds) |
| 5903 |
{ |
| 5904 |
int generate = 1; |
| 5905 |
|
| 5906 |
static char *kwlist[] = {"basefreq", "generate", NULL}; |
| 5907 |
|
| 5908 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_F_I, kwlist, &self->basefreq, &generate)) |
| 5909 |
Py_RETURN_NONE; |
| 5910 |
|
| 5911 |
if (generate) |
| 5912 |
PadSynthTable_generate(self); |
| 5913 |
|
| 5914 |
Py_RETURN_NONE; |
| 5915 |
} |
| 5916 |
|
| 5917 |
static PyObject * |
| 5918 |
PadSynthTable_setSpread(PadSynthTable *self, PyObject *args, PyObject *kwds) |
| 5919 |
{ |
| 5920 |
int generate = 1; |
| 5921 |
|
| 5922 |
static char *kwlist[] = {"spread", "generate", NULL}; |
| 5923 |
|
| 5924 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_F_I, kwlist, &self->spread, &generate)) |
| 5925 |
Py_RETURN_NONE; |
| 5926 |
|
| 5927 |
if (generate) |
| 5928 |
PadSynthTable_generate(self); |
| 5929 |
|
| 5930 |
Py_RETURN_NONE; |
| 5931 |
} |
| 5932 |
|
| 5933 |
static PyObject * |
| 5934 |
PadSynthTable_setBw(PadSynthTable *self, PyObject *args, PyObject *kwds) |
| 5935 |
{ |
| 5936 |
int generate = 1; |
| 5937 |
|
| 5938 |
static char *kwlist[] = {"bw", "generate", NULL}; |
| 5939 |
|
| 5940 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_F_I, kwlist, &self->bw, &generate)) |
| 5941 |
Py_RETURN_NONE; |
| 5942 |
|
| 5943 |
if (generate) |
| 5944 |
PadSynthTable_generate(self); |
| 5945 |
|
| 5946 |
Py_RETURN_NONE; |
| 5947 |
} |
| 5948 |
|
| 5949 |
static PyObject * |
| 5950 |
PadSynthTable_setBwScl(PadSynthTable *self, PyObject *args, PyObject *kwds) |
| 5951 |
{ |
| 5952 |
int generate = 1; |
| 5953 |
|
| 5954 |
static char *kwlist[] = {"bwscl", "generate", NULL}; |
| 5955 |
|
| 5956 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_F_I, kwlist, &self->bwscl, &generate)) |
| 5957 |
Py_RETURN_NONE; |
| 5958 |
|
| 5959 |
if (generate) |
| 5960 |
PadSynthTable_generate(self); |
| 5961 |
|
| 5962 |
Py_RETURN_NONE; |
| 5963 |
} |
| 5964 |
|
| 5965 |
static PyObject * |
| 5966 |
PadSynthTable_setNharms(PadSynthTable *self, PyObject *args, PyObject *kwds) |
| 5967 |
{ |
| 5968 |
int generate = 1; |
| 5969 |
|
| 5970 |
static char *kwlist[] = {"nharms", "generate", NULL}; |
| 5971 |
|
| 5972 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwlist, &self->nharms, &generate)) |
| 5973 |
Py_RETURN_NONE; |
| 5974 |
|
| 5975 |
if (generate) |
| 5976 |
PadSynthTable_generate(self); |
| 5977 |
|
| 5978 |
Py_RETURN_NONE; |
| 5979 |
} |
| 5980 |
|
| 5981 |
static PyObject * |
| 5982 |
PadSynthTable_setDamp(PadSynthTable *self, PyObject *args, PyObject *kwds) |
| 5983 |
{ |
| 5984 |
int generate = 1; |
| 5985 |
|
| 5986 |
static char *kwlist[] = {"damp", "generate", NULL}; |
| 5987 |
|
| 5988 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_F_I, kwlist, &self->damp, &generate)) |
| 5989 |
Py_RETURN_NONE; |
| 5990 |
|
| 5991 |
if (generate) |
| 5992 |
PadSynthTable_generate(self); |
| 5993 |
|
| 5994 |
Py_RETURN_NONE; |
| 5995 |
} |
| 5996 |
|
| 5997 |
static PyObject * |
| 5998 |
PadSynthTable_setSize(PadSynthTable *self, PyObject *args, PyObject *kwds) |
| 5999 |
{ |
| 6000 |
int generate = 1; |
| 6001 |
|
| 6002 |
static char *kwlist[] = {"size", "generate", NULL}; |
| 6003 |
|
| 6004 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "n|i", kwlist, &self->size, &generate)) |
| 6005 |
Py_RETURN_NONE; |
| 6006 |
|
| 6007 |
if (!isPowerOfTwo(self->size)) |
| 6008 |
{ |
| 6009 |
int k = 1; |
| 6010 |
|
| 6011 |
while (k < self->size) |
| 6012 |
k *= 2; |
| 6013 |
|
| 6014 |
self->size = k; |
| 6015 |
PySys_WriteStdout("PadSynthTable size must be a power-of-2, using the next power-of-2 greater than size : %ld\n", (long)self->size); |
| 6016 |
} |
| 6017 |
|
| 6018 |
self->data = (MYFLT *)PyMem_RawRealloc(self->data, (self->size + 1) * sizeof(MYFLT)); |
| 6019 |
self->amp = (MYFLT *)PyMem_RawRealloc(self->amp, (self->size / 2) * sizeof(MYFLT)); |
| 6020 |
self->inframe = (MYFLT *)PyMem_RawRealloc(self->inframe, self->size * sizeof(MYFLT)); |
| 6021 |
TableStream_setSize(self->tablestream, self->size); |
| 6022 |
|
| 6023 |
PadSynthTable_gen_twiddle(self); |
| 6024 |
|
| 6025 |
if (generate) |
| 6026 |
PadSynthTable_generate(self); |
| 6027 |
|
| 6028 |
Py_RETURN_NONE; |
| 6029 |
} |
| 6030 |
|
| 6031 |
static PyObject * |
| 6032 |
PadSynthTable_getSize(PadSynthTable *self) |
| 6033 |
{ |
| 6034 |
return PyLong_FromLong(self->size); |
| 6035 |
}; |
| 6036 |
|
| 6037 |
static PyMemberDef PadSynthTable_members[] = |
| 6038 |
{ |
| 6039 |
{"server", T_OBJECT_EX, offsetof(PadSynthTable, server), 0, "Pyo server."}, |
| 6040 |
{"tablestream", T_OBJECT_EX, offsetof(PadSynthTable, tablestream), 0, "Table stream object."}, |
| 6041 |
{NULL} /* Sentinel */ |
| 6042 |
}; |
| 6043 |
|
| 6044 |
static PyMethodDef PadSynthTable_methods[] = |
| 6045 |
{ |
| 6046 |
{"getServer", (PyCFunction)PadSynthTable_getServer, METH_NOARGS, "Returns server object."}, |
| 6047 |
{"copy", (PyCFunction)PadSynthTable_copy, METH_O, "Copy data from table given in argument."}, |
| 6048 |
{"copyData", (PyCFunction)PadSynthTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 6049 |
{"rotate", (PyCFunction)PadSynthTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 6050 |
{"setTable", (PyCFunction)PadSynthTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 6051 |
{"getTable", (PyCFunction)PadSynthTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 6052 |
{"getViewTable", (PyCFunction)PadSynthTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 6053 |
{"getTableStream", (PyCFunction)PadSynthTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 6054 |
{"setData", (PyCFunction)PadSynthTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 6055 |
{"normalize", (PyCFunction)PadSynthTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table samples"}, |
| 6056 |
{"reset", (PyCFunction)PadSynthTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 6057 |
{"removeDC", (PyCFunction)PadSynthTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 6058 |
{"reverse", (PyCFunction)PadSynthTable_reverse, METH_NOARGS, "Reverse the table's data."}, |
| 6059 |
{"invert", (PyCFunction)PadSynthTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 6060 |
{"rectify", (PyCFunction)PadSynthTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 6061 |
{"bipolarGain", (PyCFunction)PadSynthTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 6062 |
{"lowpass", (PyCFunction)PadSynthTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 6063 |
{"fadein", (PyCFunction)PadSynthTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 6064 |
{"fadeout", (PyCFunction)PadSynthTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 6065 |
{"pow", (PyCFunction)PadSynthTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 6066 |
{"getSize", (PyCFunction)PadSynthTable_getSize, METH_NOARGS, "Return the size of the table in samples"}, |
| 6067 |
{"getRate", (PyCFunction)PadSynthTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the table without pitch transposition."}, |
| 6068 |
{"setBaseFreq", (PyCFunction)PadSynthTable_setBaseFreq, METH_VARARGS | METH_KEYWORDS, "Sets the base frequency in hertz."}, |
| 6069 |
{"setSpread", (PyCFunction)PadSynthTable_setSpread, METH_VARARGS | METH_KEYWORDS, "Sets the frequency spreading factor."}, |
| 6070 |
{"setBw", (PyCFunction)PadSynthTable_setBw, METH_VARARGS | METH_KEYWORDS, "Sets the bandwitdh of the first harmonic in cents."}, |
| 6071 |
{"setBwScl", (PyCFunction)PadSynthTable_setBwScl, METH_VARARGS | METH_KEYWORDS, "Sets the bandwitdh scaling factor."}, |
| 6072 |
{"setNharms", (PyCFunction)PadSynthTable_setNharms, METH_VARARGS | METH_KEYWORDS, "Sets the number of harmonics."}, |
| 6073 |
{"setDamp", (PyCFunction)PadSynthTable_setDamp, METH_VARARGS | METH_KEYWORDS, "Sets the damping factor."}, |
| 6074 |
{"setSize", (PyCFunction)PadSynthTable_setSize, METH_VARARGS | METH_KEYWORDS, "Sets the size of the table in samples"}, |
| 6075 |
{"put", (PyCFunction)PadSynthTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 6076 |
{"get", (PyCFunction)PadSynthTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 6077 |
{"add", (PyCFunction)PadSynthTable_add, METH_O, "Performs table addition."}, |
| 6078 |
{"sub", (PyCFunction)PadSynthTable_sub, METH_O, "Performs table substraction."}, |
| 6079 |
{"mul", (PyCFunction)PadSynthTable_mul, METH_O, "Performs table multiplication."}, |
| 6080 |
{"div", (PyCFunction)PadSynthTable_div, METH_O, "Performs table division."}, |
| 6081 |
{NULL} /* Sentinel */ |
| 6082 |
}; |
| 6083 |
|
| 6084 |
PyTypeObject PadSynthTableType = |
| 6085 |
{ |
| 6086 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 6087 |
"_pyo.PadSynthTable_base", /*tp_name*/ |
| 6088 |
sizeof(PadSynthTable), /*tp_basicsize*/ |
| 6089 |
0, /*tp_itemsize*/ |
| 6090 |
(destructor)PadSynthTable_dealloc, /*tp_dealloc*/ |
| 6091 |
0, /*tp_print*/ |
| 6092 |
0, /*tp_getattr*/ |
| 6093 |
0, /*tp_setattr*/ |
| 6094 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 6095 |
0, /*tp_repr*/ |
| 6096 |
0, /*tp_as_number*/ |
| 6097 |
0, /*tp_as_sequence*/ |
| 6098 |
0, /*tp_as_mapping*/ |
| 6099 |
0, /*tp_hash */ |
| 6100 |
0, /*tp_call*/ |
| 6101 |
0, /*tp_str*/ |
| 6102 |
0, /*tp_getattro*/ |
| 6103 |
0, /*tp_setattro*/ |
| 6104 |
0, /*tp_as_buffer*/ |
| 6105 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 6106 |
"PadSynthTable objects. Generates a table filled with a sinc function.", /* tp_doc */ |
| 6107 |
(traverseproc)PadSynthTable_traverse, /* tp_traverse */ |
| 6108 |
(inquiry)PadSynthTable_clear, /* tp_clear */ |
| 6109 |
0, /* tp_richcompare */ |
| 6110 |
0, /* tp_weaklistoffset */ |
| 6111 |
0, /* tp_iter */ |
| 6112 |
0, /* tp_iternext */ |
| 6113 |
PadSynthTable_methods, /* tp_methods */ |
| 6114 |
PadSynthTable_members, /* tp_members */ |
| 6115 |
0, /* tp_getset */ |
| 6116 |
0, /* tp_base */ |
| 6117 |
0, /* tp_dict */ |
| 6118 |
0, /* tp_descr_get */ |
| 6119 |
0, /* tp_descr_set */ |
| 6120 |
0, /* tp_dictoffset */ |
| 6121 |
0, /* tp_init */ |
| 6122 |
0, /* tp_alloc */ |
| 6123 |
PadSynthTable_new, /* tp_new */ |
| 6124 |
}; |
| 6125 |
|
| 6126 |
/******************************/ |
| 6127 |
/* TableRec object definition */ |
| 6128 |
/******************************/ |
| 6129 |
typedef struct |
| 6130 |
{ |
| 6131 |
pyo_audio_HEAD |
| 6132 |
PyObject *input; |
| 6133 |
Stream *input_stream; |
| 6134 |
PyObject *table; |
| 6135 |
T_SIZE_T pointer; |
| 6136 |
int active; |
| 6137 |
MYFLT fadetime; |
| 6138 |
MYFLT fadeInSample; |
| 6139 |
MYFLT *trigsBuffer; |
| 6140 |
TriggerStream *trig_stream; |
| 6141 |
MYFLT *time_buffer_streams; |
| 6142 |
MYFLT *buffer; |
| 6143 |
} TableRec; |
| 6144 |
|
| 6145 |
static void |
| 6146 |
TableRec_compute_next_data_frame(TableRec *self) |
| 6147 |
{ |
| 6148 |
int i; |
| 6149 |
MYFLT val; |
| 6150 |
T_SIZE_T num, upBound; |
| 6151 |
T_SIZE_T size = TableStream_getSize((TableStream *)self->table); |
| 6152 |
|
| 6153 |
for (i = 0; i < self->bufsize; i++) |
| 6154 |
{ |
| 6155 |
self->trigsBuffer[i] = 0.0; |
| 6156 |
} |
| 6157 |
|
| 6158 |
if (!self->active) |
| 6159 |
{ |
| 6160 |
for (i = 0; i < self->bufsize; i++) |
| 6161 |
{ |
| 6162 |
self->time_buffer_streams[i] = self->pointer; |
| 6163 |
} |
| 6164 |
} |
| 6165 |
|
| 6166 |
if ((size - self->pointer) >= self->bufsize) |
| 6167 |
num = self->bufsize; |
| 6168 |
else |
| 6169 |
{ |
| 6170 |
num = size - self->pointer; |
| 6171 |
|
| 6172 |
if (self->active == 1) |
| 6173 |
{ |
| 6174 |
if (num <= 0) |
| 6175 |
self->trigsBuffer[0] = 1.0; |
| 6176 |
else |
| 6177 |
self->trigsBuffer[num - 1] = 1.0; |
| 6178 |
|
| 6179 |
self->active = 0; |
| 6180 |
} |
| 6181 |
} |
| 6182 |
|
| 6183 |
if (self->pointer < size) |
| 6184 |
{ |
| 6185 |
upBound = (T_SIZE_T)(size - self->fadeInSample); |
| 6186 |
|
| 6187 |
for (i = 0; i < self->bufsize; i++) |
| 6188 |
{ |
| 6189 |
self->buffer[i] = 0.0; |
| 6190 |
} |
| 6191 |
|
| 6192 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 6193 |
|
| 6194 |
for (i = 0; i < num; i++) |
| 6195 |
{ |
| 6196 |
if (self->pointer < self->fadeInSample) |
| 6197 |
val = self->pointer / self->fadeInSample; |
| 6198 |
else if (self->pointer >= upBound) |
| 6199 |
val = (size - (self->pointer + 1)) / self->fadeInSample; |
| 6200 |
else |
| 6201 |
val = 1.; |
| 6202 |
|
| 6203 |
self->buffer[i] = in[i] * val; |
| 6204 |
self->time_buffer_streams[i] = self->pointer++; |
| 6205 |
} |
| 6206 |
|
| 6207 |
TableStream_recordChunk((TableStream *)self->table, self->buffer, num); |
| 6208 |
|
| 6209 |
if (num < self->bufsize) |
| 6210 |
{ |
| 6211 |
for (i = num; i < self->bufsize; i++) |
| 6212 |
{ |
| 6213 |
self->time_buffer_streams[i] = self->pointer; |
| 6214 |
} |
| 6215 |
} |
| 6216 |
} |
| 6217 |
} |
| 6218 |
|
| 6219 |
static MYFLT * |
| 6220 |
TableRec_getTimeBuffer(TableRec *self) |
| 6221 |
{ |
| 6222 |
return self->time_buffer_streams; |
| 6223 |
} |
| 6224 |
|
| 6225 |
static int |
| 6226 |
TableRec_traverse(TableRec *self, visitproc visit, void *arg) |
| 6227 |
{ |
| 6228 |
pyo_VISIT |
| 6229 |
Py_VISIT(self->input); |
| 6230 |
return 0; |
| 6231 |
} |
| 6232 |
|
| 6233 |
static int |
| 6234 |
TableRec_clear(TableRec *self) |
| 6235 |
{ |
| 6236 |
pyo_CLEAR |
| 6237 |
Py_CLEAR(self->input); |
| 6238 |
return 0; |
| 6239 |
} |
| 6240 |
|
| 6241 |
static void |
| 6242 |
TableRec_dealloc(TableRec* self) |
| 6243 |
{ |
| 6244 |
pyo_DEALLOC |
| 6245 |
PyMem_RawFree(self->buffer); |
| 6246 |
PyMem_RawFree(self->trigsBuffer); |
| 6247 |
PyMem_RawFree(self->time_buffer_streams); |
| 6248 |
TableRec_clear(self); |
| 6249 |
Py_TYPE(self->trig_stream)->tp_free((PyObject*)self->trig_stream); |
| 6250 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 6251 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 6252 |
} |
| 6253 |
|
| 6254 |
static PyObject * |
| 6255 |
TableRec_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 6256 |
{ |
| 6257 |
int i; |
| 6258 |
PyObject *inputtmp, *input_streamtmp, *tabletmp; |
| 6259 |
TableRec *self; |
| 6260 |
self = (TableRec *)type->tp_alloc(type, 0); |
| 6261 |
|
| 6262 |
self->pointer = 0; |
| 6263 |
self->active = 1; |
| 6264 |
self->fadetime = 0.; |
| 6265 |
|
| 6266 |
INIT_OBJECT_COMMON |
| 6267 |
|
| 6268 |
Stream_setFunctionPtr(self->stream, TableRec_compute_next_data_frame); |
| 6269 |
|
| 6270 |
static char *kwlist[] = {"input", "table", "fadetime", NULL}; |
| 6271 |
|
| 6272 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_OO_F, kwlist, &inputtmp, &tabletmp, &self->fadetime)) |
| 6273 |
Py_RETURN_NONE; |
| 6274 |
|
| 6275 |
INIT_INPUT_STREAM |
| 6276 |
|
| 6277 |
if ( PyObject_HasAttrString((PyObject *)tabletmp, "getTableStream") == 0 ) |
| 6278 |
{ |
| 6279 |
PyErr_SetString(PyExc_TypeError, "\"table\" argument of TableRec must be a PyoTableObject.\n"); |
| 6280 |
Py_RETURN_NONE; |
| 6281 |
} |
| 6282 |
|
| 6283 |
self->table = PyObject_CallMethod((PyObject *)tabletmp, "getTableStream", ""); |
| 6284 |
|
| 6285 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 6286 |
|
| 6287 |
self->buffer = (MYFLT *)PyMem_RawRealloc(self->buffer, self->bufsize * sizeof(MYFLT)); |
| 6288 |
self->trigsBuffer = (MYFLT *)PyMem_RawRealloc(self->trigsBuffer, self->bufsize * sizeof(MYFLT)); |
| 6289 |
self->time_buffer_streams = (MYFLT *)PyMem_RawRealloc(self->time_buffer_streams, self->bufsize * sizeof(MYFLT)); |
| 6290 |
|
| 6291 |
for (i = 0; i < self->bufsize; i++) |
| 6292 |
{ |
| 6293 |
self->buffer[i] = self->trigsBuffer[i] = self->time_buffer_streams[i] = 0.0; |
| 6294 |
} |
| 6295 |
|
| 6296 |
MAKE_NEW_TRIGGER_STREAM(self->trig_stream, &TriggerStreamType, NULL); |
| 6297 |
TriggerStream_setData(self->trig_stream, self->trigsBuffer); |
| 6298 |
|
| 6299 |
T_SIZE_T size = TableStream_getSize((TableStream *)self->table); |
| 6300 |
|
| 6301 |
if ((self->fadetime * self->sr) >= (size * 0.5)) |
| 6302 |
self->fadetime = size * 0.499 / self->sr; |
| 6303 |
|
| 6304 |
if (self->fadetime == 0.0) |
| 6305 |
self->fadeInSample = 0.0; |
| 6306 |
else |
| 6307 |
self->fadeInSample = MYFLOOR(self->fadetime * self->sr); |
| 6308 |
|
| 6309 |
return (PyObject *)self; |
| 6310 |
} |
| 6311 |
|
| 6312 |
static PyObject * TableRec_getServer(TableRec* self) { GET_SERVER }; |
| 6313 |
static PyObject * TableRec_getStream(TableRec* self) { GET_STREAM }; |
| 6314 |
static PyObject * TableRec_getTriggerStream(TableRec* self) { GET_TRIGGER_STREAM }; |
| 6315 |
|
| 6316 |
static PyObject * TableRec_play(TableRec *self, PyObject *args, PyObject *kwds) |
| 6317 |
{ |
| 6318 |
int j; |
| 6319 |
|
| 6320 |
for (j = 0; j < self->bufsize; j++) |
| 6321 |
{ |
| 6322 |
self->time_buffer_streams[j] = 0; |
| 6323 |
} |
| 6324 |
|
| 6325 |
self->pointer = 0; |
| 6326 |
self->active = 1; |
| 6327 |
TableStream_resetRecordingPointer((TableStream *)self->table); |
| 6328 |
PLAY |
| 6329 |
}; |
| 6330 |
|
| 6331 |
static PyObject * TableRec_stop(TableRec *self, PyObject *args, PyObject *kwds) |
| 6332 |
{ |
| 6333 |
int i, nearestBuf = 0; |
| 6334 |
float wait = 0.0; |
| 6335 |
|
| 6336 |
static char *kwlist[] = {"wait", NULL}; |
| 6337 |
|
| 6338 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|f", kwlist, &wait)) |
| 6339 |
return PyLong_FromLong(-1); |
| 6340 |
|
| 6341 |
if (wait == 0) |
| 6342 |
{ |
| 6343 |
Stream_setStreamActive(self->stream, 0); |
| 6344 |
Stream_setStreamChnl(self->stream, 0); |
| 6345 |
Stream_setStreamToDac(self->stream, 0); |
| 6346 |
|
| 6347 |
for (i = 0; i < self->bufsize; i++) |
| 6348 |
{ |
| 6349 |
self->time_buffer_streams[i] = self->pointer; |
| 6350 |
self->data[i] = 0; |
| 6351 |
} |
| 6352 |
} |
| 6353 |
else |
| 6354 |
{ |
| 6355 |
Stream_resetBufferCount(self->stream); |
| 6356 |
nearestBuf = (int)roundf((wait * self->sr) / self->bufsize + 0.5); |
| 6357 |
Stream_setDuration(self->stream, nearestBuf); |
| 6358 |
} |
| 6359 |
|
| 6360 |
Py_RETURN_NONE; |
| 6361 |
}; |
| 6362 |
|
| 6363 |
static PyObject * |
| 6364 |
TableRec_setTable(TableRec *self, PyObject *arg) |
| 6365 |
{ |
| 6366 |
ASSERT_ARG_NOT_NULL |
| 6367 |
|
| 6368 |
Py_DECREF(self->table); |
| 6369 |
self->table = PyObject_CallMethod((PyObject *)arg, "getTableStream", ""); |
| 6370 |
|
| 6371 |
Py_RETURN_NONE; |
| 6372 |
} |
| 6373 |
|
| 6374 |
static PyMemberDef TableRec_members[] = |
| 6375 |
{ |
| 6376 |
{"server", T_OBJECT_EX, offsetof(TableRec, server), 0, "Pyo server."}, |
| 6377 |
{"stream", T_OBJECT_EX, offsetof(TableRec, stream), 0, "Stream object."}, |
| 6378 |
{"trig_stream", T_OBJECT_EX, offsetof(TableRec, trig_stream), 0, "Trigger Stream object."}, |
| 6379 |
{"input", T_OBJECT_EX, offsetof(TableRec, input), 0, "Input sound object."}, |
| 6380 |
{"table", T_OBJECT_EX, offsetof(TableRec, table), 0, "Table to record in."}, |
| 6381 |
{NULL} /* Sentinel */ |
| 6382 |
}; |
| 6383 |
|
| 6384 |
static PyMethodDef TableRec_methods[] = |
| 6385 |
{ |
| 6386 |
{"getServer", (PyCFunction)TableRec_getServer, METH_NOARGS, "Returns server object."}, |
| 6387 |
{"_getStream", (PyCFunction)TableRec_getStream, METH_NOARGS, "Returns stream object."}, |
| 6388 |
{"_getTriggerStream", (PyCFunction)TableRec_getTriggerStream, METH_NOARGS, "Returns trigger stream object."}, |
| 6389 |
{"setTable", (PyCFunction)TableRec_setTable, METH_O, "Sets a new table."}, |
| 6390 |
{"play", (PyCFunction)TableRec_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 6391 |
{"stop", (PyCFunction)TableRec_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 6392 |
{NULL} /* Sentinel */ |
| 6393 |
}; |
| 6394 |
|
| 6395 |
PyTypeObject TableRecType = |
| 6396 |
{ |
| 6397 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 6398 |
"_pyo.TableRec_base", /*tp_name*/ |
| 6399 |
sizeof(TableRec), /*tp_basicsize*/ |
| 6400 |
0, /*tp_itemsize*/ |
| 6401 |
(destructor)TableRec_dealloc, /*tp_dealloc*/ |
| 6402 |
0, /*tp_print*/ |
| 6403 |
0, /*tp_getattr*/ |
| 6404 |
0, /*tp_setattr*/ |
| 6405 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 6406 |
0, /*tp_repr*/ |
| 6407 |
0, /*tp_as_number*/ |
| 6408 |
0, /*tp_as_sequence*/ |
| 6409 |
0, /*tp_as_mapping*/ |
| 6410 |
0, /*tp_hash */ |
| 6411 |
0, /*tp_call*/ |
| 6412 |
0, /*tp_str*/ |
| 6413 |
0, /*tp_getattro*/ |
| 6414 |
0, /*tp_setattro*/ |
| 6415 |
0, /*tp_as_buffer*/ |
| 6416 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 6417 |
"TableRec objects. Record audio input in a table object.", /* tp_doc */ |
| 6418 |
(traverseproc)TableRec_traverse, /* tp_traverse */ |
| 6419 |
(inquiry)TableRec_clear, /* tp_clear */ |
| 6420 |
0, /* tp_richcompare */ |
| 6421 |
0, /* tp_weaklistoffset */ |
| 6422 |
0, /* tp_iter */ |
| 6423 |
0, /* tp_iternext */ |
| 6424 |
TableRec_methods, /* tp_methods */ |
| 6425 |
TableRec_members, /* tp_members */ |
| 6426 |
0, /* tp_getset */ |
| 6427 |
0, /* tp_base */ |
| 6428 |
0, /* tp_dict */ |
| 6429 |
0, /* tp_descr_get */ |
| 6430 |
0, /* tp_descr_set */ |
| 6431 |
0, /* tp_dictoffset */ |
| 6432 |
0, /* tp_init */ |
| 6433 |
0, /* tp_alloc */ |
| 6434 |
TableRec_new, /* tp_new */ |
| 6435 |
}; |
| 6436 |
|
| 6437 |
typedef struct |
| 6438 |
{ |
| 6439 |
pyo_audio_HEAD |
| 6440 |
TableRec *mainPlayer; |
| 6441 |
int modebuffer[2]; |
| 6442 |
} TableRecTimeStream; |
| 6443 |
|
| 6444 |
static void TableRecTimeStream_postprocessing_ii(TableRecTimeStream *self) { POST_PROCESSING_II }; |
| 6445 |
static void TableRecTimeStream_postprocessing_ai(TableRecTimeStream *self) { POST_PROCESSING_AI }; |
| 6446 |
static void TableRecTimeStream_postprocessing_ia(TableRecTimeStream *self) { POST_PROCESSING_IA }; |
| 6447 |
static void TableRecTimeStream_postprocessing_aa(TableRecTimeStream *self) { POST_PROCESSING_AA }; |
| 6448 |
static void TableRecTimeStream_postprocessing_ireva(TableRecTimeStream *self) { POST_PROCESSING_IREVA }; |
| 6449 |
static void TableRecTimeStream_postprocessing_areva(TableRecTimeStream *self) { POST_PROCESSING_AREVA }; |
| 6450 |
static void TableRecTimeStream_postprocessing_revai(TableRecTimeStream *self) { POST_PROCESSING_REVAI }; |
| 6451 |
static void TableRecTimeStream_postprocessing_revaa(TableRecTimeStream *self) { POST_PROCESSING_REVAA }; |
| 6452 |
static void TableRecTimeStream_postprocessing_revareva(TableRecTimeStream *self) { POST_PROCESSING_REVAREVA }; |
| 6453 |
|
| 6454 |
static void |
| 6455 |
TableRecTimeStream_setProcMode(TableRecTimeStream *self) |
| 6456 |
{ |
| 6457 |
int muladdmode; |
| 6458 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 6459 |
|
| 6460 |
switch (muladdmode) |
| 6461 |
{ |
| 6462 |
case 0: |
| 6463 |
self->muladd_func_ptr = TableRecTimeStream_postprocessing_ii; |
| 6464 |
break; |
| 6465 |
|
| 6466 |
case 1: |
| 6467 |
self->muladd_func_ptr = TableRecTimeStream_postprocessing_ai; |
| 6468 |
break; |
| 6469 |
|
| 6470 |
case 2: |
| 6471 |
self->muladd_func_ptr = TableRecTimeStream_postprocessing_revai; |
| 6472 |
break; |
| 6473 |
|
| 6474 |
case 10: |
| 6475 |
self->muladd_func_ptr = TableRecTimeStream_postprocessing_ia; |
| 6476 |
break; |
| 6477 |
|
| 6478 |
case 11: |
| 6479 |
self->muladd_func_ptr = TableRecTimeStream_postprocessing_aa; |
| 6480 |
break; |
| 6481 |
|
| 6482 |
case 12: |
| 6483 |
self->muladd_func_ptr = TableRecTimeStream_postprocessing_revaa; |
| 6484 |
break; |
| 6485 |
|
| 6486 |
case 20: |
| 6487 |
self->muladd_func_ptr = TableRecTimeStream_postprocessing_ireva; |
| 6488 |
break; |
| 6489 |
|
| 6490 |
case 21: |
| 6491 |
self->muladd_func_ptr = TableRecTimeStream_postprocessing_areva; |
| 6492 |
break; |
| 6493 |
|
| 6494 |
case 22: |
| 6495 |
self->muladd_func_ptr = TableRecTimeStream_postprocessing_revareva; |
| 6496 |
break; |
| 6497 |
} |
| 6498 |
} |
| 6499 |
|
| 6500 |
static void |
| 6501 |
TableRecTimeStream_compute_next_data_frame(TableRecTimeStream *self) |
| 6502 |
{ |
| 6503 |
int i; |
| 6504 |
MYFLT *tmp; |
| 6505 |
tmp = TableRec_getTimeBuffer((TableRec *)self->mainPlayer); |
| 6506 |
|
| 6507 |
for (i = 0; i < self->bufsize; i++) |
| 6508 |
{ |
| 6509 |
self->data[i] = tmp[i]; |
| 6510 |
} |
| 6511 |
|
| 6512 |
(*self->muladd_func_ptr)(self); |
| 6513 |
} |
| 6514 |
|
| 6515 |
static int |
| 6516 |
TableRecTimeStream_traverse(TableRecTimeStream *self, visitproc visit, void *arg) |
| 6517 |
{ |
| 6518 |
pyo_VISIT |
| 6519 |
Py_VISIT(self->mainPlayer); |
| 6520 |
return 0; |
| 6521 |
} |
| 6522 |
|
| 6523 |
static int |
| 6524 |
TableRecTimeStream_clear(TableRecTimeStream *self) |
| 6525 |
{ |
| 6526 |
pyo_CLEAR |
| 6527 |
Py_CLEAR(self->mainPlayer); |
| 6528 |
return 0; |
| 6529 |
} |
| 6530 |
|
| 6531 |
static void |
| 6532 |
TableRecTimeStream_dealloc(TableRecTimeStream* self) |
| 6533 |
{ |
| 6534 |
pyo_DEALLOC |
| 6535 |
TableRecTimeStream_clear(self); |
| 6536 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 6537 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 6538 |
} |
| 6539 |
|
| 6540 |
static PyObject * |
| 6541 |
TableRecTimeStream_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 6542 |
{ |
| 6543 |
int i; |
| 6544 |
PyObject *maintmp = NULL; |
| 6545 |
TableRecTimeStream *self; |
| 6546 |
self = (TableRecTimeStream *)type->tp_alloc(type, 0); |
| 6547 |
|
| 6548 |
self->modebuffer[0] = 0; |
| 6549 |
self->modebuffer[1] = 0; |
| 6550 |
|
| 6551 |
INIT_OBJECT_COMMON |
| 6552 |
Stream_setFunctionPtr(self->stream, TableRecTimeStream_compute_next_data_frame); |
| 6553 |
self->mode_func_ptr = TableRecTimeStream_setProcMode; |
| 6554 |
|
| 6555 |
static char *kwlist[] = {"mainPlayer", NULL}; |
| 6556 |
|
| 6557 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, &maintmp)) |
| 6558 |
Py_RETURN_NONE; |
| 6559 |
|
| 6560 |
self->mainPlayer = (TableRec *)maintmp; |
| 6561 |
Py_INCREF(self->mainPlayer); |
| 6562 |
|
| 6563 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 6564 |
|
| 6565 |
(*self->mode_func_ptr)(self); |
| 6566 |
|
| 6567 |
return (PyObject *)self; |
| 6568 |
} |
| 6569 |
|
| 6570 |
static PyObject * TableRecTimeStream_getServer(TableRecTimeStream* self) { GET_SERVER }; |
| 6571 |
static PyObject * TableRecTimeStream_getStream(TableRecTimeStream* self) { GET_STREAM }; |
| 6572 |
static PyObject * TableRecTimeStream_setMul(TableRecTimeStream *self, PyObject *arg) { SET_MUL }; |
| 6573 |
static PyObject * TableRecTimeStream_setAdd(TableRecTimeStream *self, PyObject *arg) { SET_ADD }; |
| 6574 |
static PyObject * TableRecTimeStream_setSub(TableRecTimeStream *self, PyObject *arg) { SET_SUB }; |
| 6575 |
static PyObject * TableRecTimeStream_setDiv(TableRecTimeStream *self, PyObject *arg) { SET_DIV }; |
| 6576 |
|
| 6577 |
static PyObject * TableRecTimeStream_play(TableRecTimeStream *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 6578 |
static PyObject * TableRecTimeStream_out(TableRecTimeStream *self, PyObject *args, PyObject *kwds) { OUT }; |
| 6579 |
static PyObject * TableRecTimeStream_stop(TableRecTimeStream *self, PyObject *args, PyObject *kwds) { STOP }; |
| 6580 |
|
| 6581 |
static PyObject * TableRecTimeStream_multiply(TableRecTimeStream *self, PyObject *arg) { MULTIPLY }; |
| 6582 |
static PyObject * TableRecTimeStream_inplace_multiply(TableRecTimeStream *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 6583 |
static PyObject * TableRecTimeStream_add(TableRecTimeStream *self, PyObject *arg) { ADD }; |
| 6584 |
static PyObject * TableRecTimeStream_inplace_add(TableRecTimeStream *self, PyObject *arg) { INPLACE_ADD }; |
| 6585 |
static PyObject * TableRecTimeStream_sub(TableRecTimeStream *self, PyObject *arg) { SUB }; |
| 6586 |
static PyObject * TableRecTimeStream_inplace_sub(TableRecTimeStream *self, PyObject *arg) { INPLACE_SUB }; |
| 6587 |
static PyObject * TableRecTimeStream_div(TableRecTimeStream *self, PyObject *arg) { DIV }; |
| 6588 |
static PyObject * TableRecTimeStream_inplace_div(TableRecTimeStream *self, PyObject *arg) { INPLACE_DIV }; |
| 6589 |
|
| 6590 |
static PyMemberDef TableRecTimeStream_members[] = |
| 6591 |
{ |
| 6592 |
{"server", T_OBJECT_EX, offsetof(TableRecTimeStream, server), 0, "Pyo server."}, |
| 6593 |
{"stream", T_OBJECT_EX, offsetof(TableRecTimeStream, stream), 0, "Stream object."}, |
| 6594 |
{"mul", T_OBJECT_EX, offsetof(TableRecTimeStream, mul), 0, "Mul factor."}, |
| 6595 |
{"add", T_OBJECT_EX, offsetof(TableRecTimeStream, add), 0, "Add factor."}, |
| 6596 |
{NULL} /* Sentinel */ |
| 6597 |
}; |
| 6598 |
|
| 6599 |
static PyMethodDef TableRecTimeStream_methods[] = |
| 6600 |
{ |
| 6601 |
{"getServer", (PyCFunction)TableRecTimeStream_getServer, METH_NOARGS, "Returns server object."}, |
| 6602 |
{"_getStream", (PyCFunction)TableRecTimeStream_getStream, METH_NOARGS, "Returns stream object."}, |
| 6603 |
{"play", (PyCFunction)TableRecTimeStream_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 6604 |
{"out", (PyCFunction)TableRecTimeStream_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."}, |
| 6605 |
{"stop", (PyCFunction)TableRecTimeStream_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 6606 |
{"setMul", (PyCFunction)TableRecTimeStream_setMul, METH_O, "Sets oscillator mul factor."}, |
| 6607 |
{"setAdd", (PyCFunction)TableRecTimeStream_setAdd, METH_O, "Sets oscillator add factor."}, |
| 6608 |
{"setSub", (PyCFunction)TableRecTimeStream_setSub, METH_O, "Sets inverse add factor."}, |
| 6609 |
{"setDiv", (PyCFunction)TableRecTimeStream_setDiv, METH_O, "Sets inverse mul factor."}, |
| 6610 |
{NULL} /* Sentinel */ |
| 6611 |
}; |
| 6612 |
|
| 6613 |
static PyNumberMethods TableRecTimeStream_as_number = |
| 6614 |
{ |
| 6615 |
(binaryfunc)TableRecTimeStream_add, /*nb_add*/ |
| 6616 |
(binaryfunc)TableRecTimeStream_sub, /*nb_subtract*/ |
| 6617 |
(binaryfunc)TableRecTimeStream_multiply, /*nb_multiply*/ |
| 6618 |
0, /*nb_remainder*/ |
| 6619 |
0, /*nb_divmod*/ |
| 6620 |
0, /*nb_power*/ |
| 6621 |
0, /*nb_neg*/ |
| 6622 |
0, /*nb_pos*/ |
| 6623 |
0, /*(unaryfunc)array_abs,*/ |
| 6624 |
0, /*nb_nonzero*/ |
| 6625 |
0, /*nb_invert*/ |
| 6626 |
0, /*nb_lshift*/ |
| 6627 |
0, /*nb_rshift*/ |
| 6628 |
0, /*nb_and*/ |
| 6629 |
0, /*nb_xor*/ |
| 6630 |
0, /*nb_or*/ |
| 6631 |
0, /*nb_int*/ |
| 6632 |
0, /*nb_long*/ |
| 6633 |
0, /*nb_float*/ |
| 6634 |
(binaryfunc)TableRecTimeStream_inplace_add, /*inplace_add*/ |
| 6635 |
(binaryfunc)TableRecTimeStream_inplace_sub, /*inplace_subtract*/ |
| 6636 |
(binaryfunc)TableRecTimeStream_inplace_multiply, /*inplace_multiply*/ |
| 6637 |
0, /*inplace_remainder*/ |
| 6638 |
0, /*inplace_power*/ |
| 6639 |
0, /*inplace_lshift*/ |
| 6640 |
0, /*inplace_rshift*/ |
| 6641 |
0, /*inplace_and*/ |
| 6642 |
0, /*inplace_xor*/ |
| 6643 |
0, /*inplace_or*/ |
| 6644 |
0, /*nb_floor_divide*/ |
| 6645 |
(binaryfunc)TableRecTimeStream_div, /*nb_true_divide*/ |
| 6646 |
0, /*nb_inplace_floor_divide*/ |
| 6647 |
(binaryfunc)TableRecTimeStream_inplace_div, /*nb_inplace_true_divide*/ |
| 6648 |
0, /* nb_index */ |
| 6649 |
}; |
| 6650 |
|
| 6651 |
PyTypeObject TableRecTimeStreamType = |
| 6652 |
{ |
| 6653 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 6654 |
"_pyo.TableRecTimeStream_base", /*tp_name*/ |
| 6655 |
sizeof(TableRecTimeStream), /*tp_basicsize*/ |
| 6656 |
0, /*tp_itemsize*/ |
| 6657 |
(destructor)TableRecTimeStream_dealloc, /*tp_dealloc*/ |
| 6658 |
0, /*tp_print*/ |
| 6659 |
0, /*tp_getattr*/ |
| 6660 |
0, /*tp_setattr*/ |
| 6661 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 6662 |
0, /*tp_repr*/ |
| 6663 |
&TableRecTimeStream_as_number, /*tp_as_number*/ |
| 6664 |
0, /*tp_as_sequence*/ |
| 6665 |
0, /*tp_as_mapping*/ |
| 6666 |
0, /*tp_hash */ |
| 6667 |
0, /*tp_call*/ |
| 6668 |
0, /*tp_str*/ |
| 6669 |
0, /*tp_getattro*/ |
| 6670 |
0, /*tp_setattro*/ |
| 6671 |
0, /*tp_as_buffer*/ |
| 6672 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 6673 |
"TableRecTimeStream objects. Returns the current recording time, in samples, of a TableRec object.", /* tp_doc */ |
| 6674 |
(traverseproc)TableRecTimeStream_traverse, /* tp_traverse */ |
| 6675 |
(inquiry)TableRecTimeStream_clear, /* tp_clear */ |
| 6676 |
0, /* tp_richcompare */ |
| 6677 |
0, /* tp_weaklistoffset */ |
| 6678 |
0, /* tp_iter */ |
| 6679 |
0, /* tp_iternext */ |
| 6680 |
TableRecTimeStream_methods, /* tp_methods */ |
| 6681 |
TableRecTimeStream_members, /* tp_members */ |
| 6682 |
0, /* tp_getset */ |
| 6683 |
0, /* tp_base */ |
| 6684 |
0, /* tp_dict */ |
| 6685 |
0, /* tp_descr_get */ |
| 6686 |
0, /* tp_descr_set */ |
| 6687 |
0, /* tp_dictoffset */ |
| 6688 |
0, /* tp_init */ |
| 6689 |
0, /* tp_alloc */ |
| 6690 |
TableRecTimeStream_new, /* tp_new */ |
| 6691 |
}; |
| 6692 |
|
| 6693 |
/******************************/ |
| 6694 |
/* TableMorph object definition */ |
| 6695 |
/******************************/ |
| 6696 |
typedef struct |
| 6697 |
{ |
| 6698 |
pyo_audio_HEAD |
| 6699 |
PyObject *input; |
| 6700 |
Stream *input_stream; |
| 6701 |
PyObject *table; |
| 6702 |
PyObject *sources; |
| 6703 |
MYFLT *buffer; |
| 6704 |
T_SIZE_T last_size; |
| 6705 |
} TableMorph; |
| 6706 |
|
| 6707 |
static MYFLT |
| 6708 |
TableMorph_clip(MYFLT x) |
| 6709 |
{ |
| 6710 |
if (x < 0.0) |
| 6711 |
return 0.0; |
| 6712 |
else if (x >= 0.999999) |
| 6713 |
return 0.999999; |
| 6714 |
else |
| 6715 |
return x; |
| 6716 |
} |
| 6717 |
|
| 6718 |
static void |
| 6719 |
TableMorph_alloc_memories(TableMorph *self) |
| 6720 |
{ |
| 6721 |
T_SIZE_T i; |
| 6722 |
T_SIZE_T size = TableStream_getSize((TableStream *)self->table); |
| 6723 |
self->last_size = size; |
| 6724 |
self->buffer = (MYFLT *)PyMem_RawRealloc(self->buffer, size * sizeof(MYFLT)); |
| 6725 |
|
| 6726 |
for (i = 0; i < size; i++) |
| 6727 |
{ |
| 6728 |
self->buffer[i] = 0.0; |
| 6729 |
} |
| 6730 |
} |
| 6731 |
|
| 6732 |
static void |
| 6733 |
TableMorph_compute_next_data_frame(TableMorph *self) |
| 6734 |
{ |
| 6735 |
T_SIZE_T i; |
| 6736 |
int x, y; |
| 6737 |
MYFLT input, interp, interp1, interp2; |
| 6738 |
|
| 6739 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 6740 |
T_SIZE_T size = TableStream_getSize((TableStream *)self->table); |
| 6741 |
int len = PyList_Size(self->sources); |
| 6742 |
|
| 6743 |
if (size != self->last_size) |
| 6744 |
TableMorph_alloc_memories(self); |
| 6745 |
|
| 6746 |
input = TableMorph_clip(in[0]); |
| 6747 |
|
| 6748 |
interp = input * (len - 1); |
| 6749 |
x = (int)(interp); |
| 6750 |
y = x + 1; |
| 6751 |
|
| 6752 |
MYFLT *tab1 = TableStream_getData((TableStream *)PyObject_CallMethod((PyObject *)PyList_GET_ITEM(self->sources, x), "getTableStream", "")); |
| 6753 |
MYFLT *tab2 = TableStream_getData((TableStream *)PyObject_CallMethod((PyObject *)PyList_GET_ITEM(self->sources, y), "getTableStream", "")); |
| 6754 |
T_SIZE_T size1 = TableStream_getSize((TableStream *)PyObject_CallMethod((PyObject *)PyList_GET_ITEM(self->sources, x), "getTableStream", "")); |
| 6755 |
T_SIZE_T size2 = TableStream_getSize((TableStream *)PyObject_CallMethod((PyObject *)PyList_GET_ITEM(self->sources, y), "getTableStream", "")); |
| 6756 |
|
| 6757 |
size = size < size1 ? size : size1; |
| 6758 |
size = size < size2 ? size : size2; |
| 6759 |
|
| 6760 |
interp = MYFMOD(interp, 1.0); |
| 6761 |
interp1 = 1. - interp; |
| 6762 |
interp2 = interp; |
| 6763 |
|
| 6764 |
for (i = 0; i < size; i++) |
| 6765 |
{ |
| 6766 |
self->buffer[i] = tab1[i] * interp1 + tab2[i] * interp2; |
| 6767 |
} |
| 6768 |
|
| 6769 |
TableStream_recordChunk((TableStream *)self->table, self->buffer, size); |
| 6770 |
} |
| 6771 |
|
| 6772 |
static int |
| 6773 |
TableMorph_traverse(TableMorph *self, visitproc visit, void *arg) |
| 6774 |
{ |
| 6775 |
pyo_VISIT |
| 6776 |
Py_VISIT(self->input); |
| 6777 |
Py_VISIT(self->sources); |
| 6778 |
return 0; |
| 6779 |
} |
| 6780 |
|
| 6781 |
static int |
| 6782 |
TableMorph_clear(TableMorph *self) |
| 6783 |
{ |
| 6784 |
pyo_CLEAR |
| 6785 |
Py_CLEAR(self->input); |
| 6786 |
Py_CLEAR(self->sources); |
| 6787 |
return 0; |
| 6788 |
} |
| 6789 |
|
| 6790 |
static void |
| 6791 |
TableMorph_dealloc(TableMorph* self) |
| 6792 |
{ |
| 6793 |
pyo_DEALLOC |
| 6794 |
PyMem_RawFree(self->buffer); |
| 6795 |
TableMorph_clear(self); |
| 6796 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 6797 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 6798 |
} |
| 6799 |
|
| 6800 |
static PyObject * |
| 6801 |
TableMorph_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 6802 |
{ |
| 6803 |
int i; |
| 6804 |
PyObject *inputtmp, *input_streamtmp, *tabletmp, *sourcestmp; |
| 6805 |
TableMorph *self; |
| 6806 |
self = (TableMorph *)type->tp_alloc(type, 0); |
| 6807 |
|
| 6808 |
INIT_OBJECT_COMMON |
| 6809 |
|
| 6810 |
Stream_setFunctionPtr(self->stream, TableMorph_compute_next_data_frame); |
| 6811 |
|
| 6812 |
static char *kwlist[] = {"input", "table", "sources", NULL}; |
| 6813 |
|
| 6814 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OOO", kwlist, &inputtmp, &tabletmp, &sourcestmp)) |
| 6815 |
Py_RETURN_NONE; |
| 6816 |
|
| 6817 |
INIT_INPUT_STREAM |
| 6818 |
|
| 6819 |
if ( PyObject_HasAttrString((PyObject *)tabletmp, "getTableStream") == 0 ) |
| 6820 |
{ |
| 6821 |
PyErr_SetString(PyExc_TypeError, "\"table\" argument of TableMorph must be a PyoTableObject.\n"); |
| 6822 |
Py_RETURN_NONE; |
| 6823 |
} |
| 6824 |
|
| 6825 |
self->table = PyObject_CallMethod((PyObject *)tabletmp, "getTableStream", ""); |
| 6826 |
|
| 6827 |
self->sources = (PyObject *)sourcestmp; |
| 6828 |
Py_INCREF(self->sources); |
| 6829 |
|
| 6830 |
TableMorph_alloc_memories(self); |
| 6831 |
|
| 6832 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 6833 |
|
| 6834 |
return (PyObject *)self; |
| 6835 |
} |
| 6836 |
|
| 6837 |
static PyObject * TableMorph_getServer(TableMorph* self) { GET_SERVER }; |
| 6838 |
static PyObject * TableMorph_getStream(TableMorph* self) { GET_STREAM }; |
| 6839 |
|
| 6840 |
static PyObject * TableMorph_play(TableMorph *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 6841 |
static PyObject * TableMorph_stop(TableMorph *self, PyObject *args, PyObject *kwds) { STOP }; |
| 6842 |
|
| 6843 |
static PyObject * |
| 6844 |
TableMorph_setTable(TableMorph *self, PyObject *arg) |
| 6845 |
{ |
| 6846 |
ASSERT_ARG_NOT_NULL |
| 6847 |
|
| 6848 |
Py_DECREF(self->table); |
| 6849 |
self->table = PyObject_CallMethod((PyObject *)arg, "getTableStream", ""); |
| 6850 |
|
| 6851 |
Py_RETURN_NONE; |
| 6852 |
} |
| 6853 |
|
| 6854 |
static PyObject * |
| 6855 |
TableMorph_setSources(TableMorph *self, PyObject *arg) |
| 6856 |
{ |
| 6857 |
ASSERT_ARG_NOT_NULL |
| 6858 |
|
| 6859 |
if (! PyList_Check(arg)) |
| 6860 |
{ |
| 6861 |
PyErr_SetString(PyExc_TypeError, "The amplitude list attribute value must be a list."); |
| 6862 |
return PyLong_FromLong(-1); |
| 6863 |
} |
| 6864 |
|
| 6865 |
Py_INCREF(arg); |
| 6866 |
Py_DECREF(self->sources); |
| 6867 |
self->sources = arg; |
| 6868 |
|
| 6869 |
Py_RETURN_NONE; |
| 6870 |
} |
| 6871 |
|
| 6872 |
static PyMemberDef TableMorph_members[] = |
| 6873 |
{ |
| 6874 |
{"server", T_OBJECT_EX, offsetof(TableMorph, server), 0, "Pyo server."}, |
| 6875 |
{"stream", T_OBJECT_EX, offsetof(TableMorph, stream), 0, "Stream object."}, |
| 6876 |
{"input", T_OBJECT_EX, offsetof(TableMorph, input), 0, "Input sound object."}, |
| 6877 |
{"table", T_OBJECT_EX, offsetof(TableMorph, table), 0, "Table to record in."}, |
| 6878 |
{"sources", T_OBJECT_EX, offsetof(TableMorph, sources), 0, "list of tables to interpolate from."}, |
| 6879 |
{NULL} /* Sentinel */ |
| 6880 |
}; |
| 6881 |
|
| 6882 |
static PyMethodDef TableMorph_methods[] = |
| 6883 |
{ |
| 6884 |
{"getServer", (PyCFunction)TableMorph_getServer, METH_NOARGS, "Returns server object."}, |
| 6885 |
{"_getStream", (PyCFunction)TableMorph_getStream, METH_NOARGS, "Returns stream object."}, |
| 6886 |
{"setTable", (PyCFunction)TableMorph_setTable, METH_O, "Sets a new table."}, |
| 6887 |
{"setSources", (PyCFunction)TableMorph_setSources, METH_O, "Changes the sources tables."}, |
| 6888 |
{"play", (PyCFunction)TableMorph_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 6889 |
{"stop", (PyCFunction)TableMorph_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 6890 |
{NULL} /* Sentinel */ |
| 6891 |
}; |
| 6892 |
|
| 6893 |
PyTypeObject TableMorphType = |
| 6894 |
{ |
| 6895 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 6896 |
"_pyo.TableMorph_base", /*tp_name*/ |
| 6897 |
sizeof(TableMorph), /*tp_basicsize*/ |
| 6898 |
0, /*tp_itemsize*/ |
| 6899 |
(destructor)TableMorph_dealloc, /*tp_dealloc*/ |
| 6900 |
0, /*tp_print*/ |
| 6901 |
0, /*tp_getattr*/ |
| 6902 |
0, /*tp_setattr*/ |
| 6903 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 6904 |
0, /*tp_repr*/ |
| 6905 |
0, /*tp_as_number*/ |
| 6906 |
0, /*tp_as_sequence*/ |
| 6907 |
0, /*tp_as_mapping*/ |
| 6908 |
0, /*tp_hash */ |
| 6909 |
0, /*tp_call*/ |
| 6910 |
0, /*tp_str*/ |
| 6911 |
0, /*tp_getattro*/ |
| 6912 |
0, /*tp_setattro*/ |
| 6913 |
0, /*tp_as_buffer*/ |
| 6914 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 6915 |
"TableMorph objects. Interpolation contents of different table objects.", /* tp_doc */ |
| 6916 |
(traverseproc)TableMorph_traverse, /* tp_traverse */ |
| 6917 |
(inquiry)TableMorph_clear, /* tp_clear */ |
| 6918 |
0, /* tp_richcompare */ |
| 6919 |
0, /* tp_weaklistoffset */ |
| 6920 |
0, /* tp_iter */ |
| 6921 |
0, /* tp_iternext */ |
| 6922 |
TableMorph_methods, /* tp_methods */ |
| 6923 |
TableMorph_members, /* tp_members */ |
| 6924 |
0, /* tp_getset */ |
| 6925 |
0, /* tp_base */ |
| 6926 |
0, /* tp_dict */ |
| 6927 |
0, /* tp_descr_get */ |
| 6928 |
0, /* tp_descr_set */ |
| 6929 |
0, /* tp_dictoffset */ |
| 6930 |
0, /* tp_init */ |
| 6931 |
0, /* tp_alloc */ |
| 6932 |
TableMorph_new, /* tp_new */ |
| 6933 |
}; |
| 6934 |
|
| 6935 |
/******************************/ |
| 6936 |
/* TrigTableRec object definition */ |
| 6937 |
/******************************/ |
| 6938 |
typedef struct |
| 6939 |
{ |
| 6940 |
pyo_audio_HEAD |
| 6941 |
PyObject *input; |
| 6942 |
Stream *input_stream; |
| 6943 |
PyObject *trigger; |
| 6944 |
Stream *trigger_stream; |
| 6945 |
PyObject *table; |
| 6946 |
T_SIZE_T pointer; |
| 6947 |
int active; |
| 6948 |
MYFLT fadetime; |
| 6949 |
MYFLT fadeInSample; |
| 6950 |
MYFLT *trigsBuffer; |
| 6951 |
TriggerStream *trig_stream; |
| 6952 |
MYFLT *time_buffer_streams; |
| 6953 |
} TrigTableRec; |
| 6954 |
|
| 6955 |
static void |
| 6956 |
TrigTableRec_compute_next_data_frame(TrigTableRec *self) |
| 6957 |
{ |
| 6958 |
int i, j, num; |
| 6959 |
MYFLT val; |
| 6960 |
T_SIZE_T upBound; |
| 6961 |
T_SIZE_T size = TableStream_getSize((TableStream *)self->table); |
| 6962 |
|
| 6963 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 6964 |
MYFLT *trig = Stream_getData((Stream *)self->trigger_stream); |
| 6965 |
|
| 6966 |
for (i = 0; i < self->bufsize; i++) |
| 6967 |
{ |
| 6968 |
self->trigsBuffer[i] = 0.0; |
| 6969 |
} |
| 6970 |
|
| 6971 |
if (self->active == 1) |
| 6972 |
{ |
| 6973 |
if ((size - self->pointer) >= self->bufsize) |
| 6974 |
num = self->bufsize; |
| 6975 |
else |
| 6976 |
{ |
| 6977 |
num = size - self->pointer; |
| 6978 |
|
| 6979 |
if (self->active == 1) |
| 6980 |
{ |
| 6981 |
if (num <= 0) |
| 6982 |
self->trigsBuffer[0] = 1.0; |
| 6983 |
else |
| 6984 |
self->trigsBuffer[num - 1] = 1.0; |
| 6985 |
|
| 6986 |
self->active = 0; |
| 6987 |
} |
| 6988 |
} |
| 6989 |
|
| 6990 |
if (self->pointer < size) |
| 6991 |
{ |
| 6992 |
upBound = size - self->fadeInSample; |
| 6993 |
|
| 6994 |
MYFLT buffer[num]; |
| 6995 |
memset(&buffer, 0, sizeof(buffer)); |
| 6996 |
|
| 6997 |
for (i = 0; i < num; i++) |
| 6998 |
{ |
| 6999 |
if (self->pointer < self->fadeInSample) |
| 7000 |
val = self->pointer / self->fadeInSample; |
| 7001 |
else if (self->pointer > upBound) |
| 7002 |
val = (size - self->pointer) / self->fadeInSample; |
| 7003 |
else |
| 7004 |
val = 1.; |
| 7005 |
|
| 7006 |
buffer[i] = in[i] * val; |
| 7007 |
self->time_buffer_streams[i] = self->pointer++; |
| 7008 |
} |
| 7009 |
|
| 7010 |
TableStream_recordChunk((TableStream *)self->table, buffer, num); |
| 7011 |
|
| 7012 |
if (num < self->bufsize) |
| 7013 |
{ |
| 7014 |
for (i = num; i < self->bufsize; i++) |
| 7015 |
{ |
| 7016 |
self->time_buffer_streams[i] = self->pointer; |
| 7017 |
} |
| 7018 |
} |
| 7019 |
} |
| 7020 |
} |
| 7021 |
else |
| 7022 |
{ |
| 7023 |
for (j = 0; j < self->bufsize; j++) |
| 7024 |
{ |
| 7025 |
self->time_buffer_streams[j] = self->pointer; |
| 7026 |
|
| 7027 |
if (trig[j] == 1.0) |
| 7028 |
{ |
| 7029 |
self->active = 1; |
| 7030 |
self->pointer = 0; |
| 7031 |
TableStream_resetRecordingPointer((TableStream *)self->table); |
| 7032 |
|
| 7033 |
if (size >= self->bufsize) |
| 7034 |
num = self->bufsize - j; |
| 7035 |
else |
| 7036 |
{ |
| 7037 |
num = size < (self->bufsize - j) ? size : (self->bufsize - j); |
| 7038 |
|
| 7039 |
if (self->active == 1) |
| 7040 |
{ |
| 7041 |
if (num <= 0) |
| 7042 |
self->trigsBuffer[0] = 1.0; |
| 7043 |
else |
| 7044 |
self->trigsBuffer[num - 1] = 1.0; |
| 7045 |
|
| 7046 |
self->active = 0; |
| 7047 |
} |
| 7048 |
} |
| 7049 |
|
| 7050 |
upBound = size - self->fadeInSample; |
| 7051 |
|
| 7052 |
MYFLT buffer[num]; |
| 7053 |
memset(&buffer, 0, sizeof(buffer)); |
| 7054 |
|
| 7055 |
for (i = 0; i < num; i++) |
| 7056 |
{ |
| 7057 |
if (self->pointer < self->fadeInSample) |
| 7058 |
{ |
| 7059 |
val = self->pointer / self->fadeInSample; |
| 7060 |
} |
| 7061 |
else if (self->pointer > upBound) |
| 7062 |
val = (size - self->pointer) / self->fadeInSample; |
| 7063 |
else |
| 7064 |
val = 1.; |
| 7065 |
|
| 7066 |
buffer[i] = in[i + j] * val; |
| 7067 |
self->time_buffer_streams[i + j] = self->pointer++; |
| 7068 |
} |
| 7069 |
|
| 7070 |
TableStream_recordChunk((TableStream *)self->table, buffer, num); |
| 7071 |
|
| 7072 |
if (num < (self->bufsize - j)) |
| 7073 |
{ |
| 7074 |
for (i = num; i < (self->bufsize - j); i++) |
| 7075 |
{ |
| 7076 |
self->time_buffer_streams[i + j] = self->pointer; |
| 7077 |
} |
| 7078 |
} |
| 7079 |
|
| 7080 |
break; |
| 7081 |
} |
| 7082 |
} |
| 7083 |
} |
| 7084 |
} |
| 7085 |
|
| 7086 |
static MYFLT * |
| 7087 |
TrigTableRec_getTimeBuffer(TrigTableRec *self) |
| 7088 |
{ |
| 7089 |
return self->time_buffer_streams; |
| 7090 |
} |
| 7091 |
|
| 7092 |
static int |
| 7093 |
TrigTableRec_traverse(TrigTableRec *self, visitproc visit, void *arg) |
| 7094 |
{ |
| 7095 |
pyo_VISIT |
| 7096 |
Py_VISIT(self->input); |
| 7097 |
Py_VISIT(self->trigger); |
| 7098 |
return 0; |
| 7099 |
} |
| 7100 |
|
| 7101 |
static int |
| 7102 |
TrigTableRec_clear(TrigTableRec *self) |
| 7103 |
{ |
| 7104 |
pyo_CLEAR |
| 7105 |
Py_CLEAR(self->input); |
| 7106 |
Py_CLEAR(self->trigger); |
| 7107 |
return 0; |
| 7108 |
} |
| 7109 |
|
| 7110 |
static void |
| 7111 |
TrigTableRec_dealloc(TrigTableRec* self) |
| 7112 |
{ |
| 7113 |
pyo_DEALLOC |
| 7114 |
PyMem_RawFree(self->trigsBuffer); |
| 7115 |
PyMem_RawFree(self->time_buffer_streams); |
| 7116 |
TrigTableRec_clear(self); |
| 7117 |
Py_TYPE(self->trig_stream)->tp_free((PyObject*)self->trig_stream); |
| 7118 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 7119 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 7120 |
} |
| 7121 |
|
| 7122 |
static PyObject * |
| 7123 |
TrigTableRec_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 7124 |
{ |
| 7125 |
int i; |
| 7126 |
PyObject *inputtmp, *input_streamtmp, *trigtmp, *trig_streamtmp, *tabletmp; |
| 7127 |
TrigTableRec *self; |
| 7128 |
self = (TrigTableRec *)type->tp_alloc(type, 0); |
| 7129 |
|
| 7130 |
self->pointer = 0; |
| 7131 |
self->active = 0; |
| 7132 |
self->fadetime = 0.; |
| 7133 |
|
| 7134 |
INIT_OBJECT_COMMON |
| 7135 |
|
| 7136 |
Stream_setFunctionPtr(self->stream, TrigTableRec_compute_next_data_frame); |
| 7137 |
|
| 7138 |
static char *kwlist[] = {"input", "trig", "table", "fadetime", NULL}; |
| 7139 |
|
| 7140 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_OOO_F, kwlist, &inputtmp, &trigtmp, &tabletmp, &self->fadetime)) |
| 7141 |
Py_RETURN_NONE; |
| 7142 |
|
| 7143 |
INIT_INPUT_STREAM |
| 7144 |
|
| 7145 |
self->trigger = trigtmp; |
| 7146 |
Py_INCREF(self->trigger); |
| 7147 |
trig_streamtmp = PyObject_CallMethod((PyObject *)self->trigger, "_getStream", NULL); |
| 7148 |
self->trigger_stream = (Stream *)trig_streamtmp; |
| 7149 |
Py_INCREF(self->trigger_stream); |
| 7150 |
|
| 7151 |
if ( PyObject_HasAttrString((PyObject *)tabletmp, "getTableStream") == 0 ) |
| 7152 |
{ |
| 7153 |
PyErr_SetString(PyExc_TypeError, "\"table\" argument of TrigTableRec must be a PyoTableObject.\n"); |
| 7154 |
Py_RETURN_NONE; |
| 7155 |
} |
| 7156 |
|
| 7157 |
self->table = PyObject_CallMethod((PyObject *)tabletmp, "getTableStream", ""); |
| 7158 |
|
| 7159 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 7160 |
|
| 7161 |
self->trigsBuffer = (MYFLT *)PyMem_RawRealloc(self->trigsBuffer, self->bufsize * sizeof(MYFLT)); |
| 7162 |
self->time_buffer_streams = (MYFLT *)PyMem_RawRealloc(self->time_buffer_streams, self->bufsize * sizeof(MYFLT)); |
| 7163 |
|
| 7164 |
for (i = 0; i < self->bufsize; i++) |
| 7165 |
{ |
| 7166 |
self->trigsBuffer[i] = self->time_buffer_streams[i] = 0.0; |
| 7167 |
} |
| 7168 |
|
| 7169 |
MAKE_NEW_TRIGGER_STREAM(self->trig_stream, &TriggerStreamType, NULL); |
| 7170 |
TriggerStream_setData(self->trig_stream, self->trigsBuffer); |
| 7171 |
|
| 7172 |
T_SIZE_T size = TableStream_getSize((TableStream *)self->table); |
| 7173 |
if ((self->fadetime * self->sr) >= (size * 0.5)) |
| 7174 |
self->fadetime = size * 0.499 / self->sr; |
| 7175 |
|
| 7176 |
if (self->fadetime == 0.0) |
| 7177 |
self->fadeInSample = 0.0; |
| 7178 |
else |
| 7179 |
self->fadeInSample = MYROUND(self->fadetime * self->sr + 0.5); |
| 7180 |
|
| 7181 |
return (PyObject *)self; |
| 7182 |
} |
| 7183 |
|
| 7184 |
static PyObject * TrigTableRec_getServer(TrigTableRec* self) { GET_SERVER }; |
| 7185 |
static PyObject * TrigTableRec_getStream(TrigTableRec* self) { GET_STREAM }; |
| 7186 |
static PyObject * TrigTableRec_getTriggerStream(TrigTableRec* self) { GET_TRIGGER_STREAM }; |
| 7187 |
|
| 7188 |
static PyObject * TrigTableRec_play(TrigTableRec *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 7189 |
static PyObject * TrigTableRec_stop(TrigTableRec *self, PyObject *args, PyObject *kwds) { STOP }; |
| 7190 |
|
| 7191 |
static PyObject * |
| 7192 |
TrigTableRec_setTable(TrigTableRec *self, PyObject *arg) |
| 7193 |
{ |
| 7194 |
ASSERT_ARG_NOT_NULL |
| 7195 |
|
| 7196 |
Py_DECREF(self->table); |
| 7197 |
self->table = PyObject_CallMethod((PyObject *)arg, "getTableStream", ""); |
| 7198 |
|
| 7199 |
Py_RETURN_NONE; |
| 7200 |
} |
| 7201 |
|
| 7202 |
static PyMemberDef TrigTableRec_members[] = |
| 7203 |
{ |
| 7204 |
{"server", T_OBJECT_EX, offsetof(TrigTableRec, server), 0, "Pyo server."}, |
| 7205 |
{"stream", T_OBJECT_EX, offsetof(TrigTableRec, stream), 0, "Stream object."}, |
| 7206 |
{"trig_stream", T_OBJECT_EX, offsetof(TrigTableRec, trig_stream), 0, "Trigger Stream object."}, |
| 7207 |
{"input", T_OBJECT_EX, offsetof(TrigTableRec, input), 0, "Input sound object."}, |
| 7208 |
{"trigger", T_OBJECT_EX, offsetof(TrigTableRec, trigger), 0, "Trigger object."}, |
| 7209 |
{"table", T_OBJECT_EX, offsetof(TrigTableRec, table), 0, "Table to record in."}, |
| 7210 |
{NULL} /* Sentinel */ |
| 7211 |
}; |
| 7212 |
|
| 7213 |
static PyMethodDef TrigTableRec_methods[] = |
| 7214 |
{ |
| 7215 |
{"getServer", (PyCFunction)TrigTableRec_getServer, METH_NOARGS, "Returns server object."}, |
| 7216 |
{"_getStream", (PyCFunction)TrigTableRec_getStream, METH_NOARGS, "Returns stream object."}, |
| 7217 |
{"_getTriggerStream", (PyCFunction)TrigTableRec_getTriggerStream, METH_NOARGS, "Returns trigger stream object."}, |
| 7218 |
{"setTable", (PyCFunction)TrigTableRec_setTable, METH_O, "Sets a new table."}, |
| 7219 |
{"play", (PyCFunction)TrigTableRec_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 7220 |
{"stop", (PyCFunction)TrigTableRec_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 7221 |
{NULL} /* Sentinel */ |
| 7222 |
}; |
| 7223 |
|
| 7224 |
PyTypeObject TrigTableRecType = |
| 7225 |
{ |
| 7226 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 7227 |
"_pyo.TrigTableRec_base", /*tp_name*/ |
| 7228 |
sizeof(TrigTableRec), /*tp_basicsize*/ |
| 7229 |
0, /*tp_itemsize*/ |
| 7230 |
(destructor)TrigTableRec_dealloc, /*tp_dealloc*/ |
| 7231 |
0, /*tp_print*/ |
| 7232 |
0, /*tp_getattr*/ |
| 7233 |
0, /*tp_setattr*/ |
| 7234 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 7235 |
0, /*tp_repr*/ |
| 7236 |
0, /*tp_as_number*/ |
| 7237 |
0, /*tp_as_sequence*/ |
| 7238 |
0, /*tp_as_mapping*/ |
| 7239 |
0, /*tp_hash */ |
| 7240 |
0, /*tp_call*/ |
| 7241 |
0, /*tp_str*/ |
| 7242 |
0, /*tp_getattro*/ |
| 7243 |
0, /*tp_setattro*/ |
| 7244 |
0, /*tp_as_buffer*/ |
| 7245 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 7246 |
"TrigTableRec objects. Record audio input in a table object.", /* tp_doc */ |
| 7247 |
(traverseproc)TrigTableRec_traverse, /* tp_traverse */ |
| 7248 |
(inquiry)TrigTableRec_clear, /* tp_clear */ |
| 7249 |
0, /* tp_richcompare */ |
| 7250 |
0, /* tp_weaklistoffset */ |
| 7251 |
0, /* tp_iter */ |
| 7252 |
0, /* tp_iternext */ |
| 7253 |
TrigTableRec_methods, /* tp_methods */ |
| 7254 |
TrigTableRec_members, /* tp_members */ |
| 7255 |
0, /* tp_getset */ |
| 7256 |
0, /* tp_base */ |
| 7257 |
0, /* tp_dict */ |
| 7258 |
0, /* tp_descr_get */ |
| 7259 |
0, /* tp_descr_set */ |
| 7260 |
0, /* tp_dictoffset */ |
| 7261 |
0, /* tp_init */ |
| 7262 |
0, /* tp_alloc */ |
| 7263 |
TrigTableRec_new, /* tp_new */ |
| 7264 |
}; |
| 7265 |
|
| 7266 |
typedef struct |
| 7267 |
{ |
| 7268 |
pyo_audio_HEAD |
| 7269 |
TrigTableRec *mainPlayer; |
| 7270 |
int modebuffer[2]; |
| 7271 |
} TrigTableRecTimeStream; |
| 7272 |
|
| 7273 |
static void TrigTableRecTimeStream_postprocessing_ii(TrigTableRecTimeStream *self) { POST_PROCESSING_II }; |
| 7274 |
static void TrigTableRecTimeStream_postprocessing_ai(TrigTableRecTimeStream *self) { POST_PROCESSING_AI }; |
| 7275 |
static void TrigTableRecTimeStream_postprocessing_ia(TrigTableRecTimeStream *self) { POST_PROCESSING_IA }; |
| 7276 |
static void TrigTableRecTimeStream_postprocessing_aa(TrigTableRecTimeStream *self) { POST_PROCESSING_AA }; |
| 7277 |
static void TrigTableRecTimeStream_postprocessing_ireva(TrigTableRecTimeStream *self) { POST_PROCESSING_IREVA }; |
| 7278 |
static void TrigTableRecTimeStream_postprocessing_areva(TrigTableRecTimeStream *self) { POST_PROCESSING_AREVA }; |
| 7279 |
static void TrigTableRecTimeStream_postprocessing_revai(TrigTableRecTimeStream *self) { POST_PROCESSING_REVAI }; |
| 7280 |
static void TrigTableRecTimeStream_postprocessing_revaa(TrigTableRecTimeStream *self) { POST_PROCESSING_REVAA }; |
| 7281 |
static void TrigTableRecTimeStream_postprocessing_revareva(TrigTableRecTimeStream *self) { POST_PROCESSING_REVAREVA }; |
| 7282 |
|
| 7283 |
static void |
| 7284 |
TrigTableRecTimeStream_setProcMode(TrigTableRecTimeStream *self) |
| 7285 |
{ |
| 7286 |
int muladdmode; |
| 7287 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 7288 |
|
| 7289 |
switch (muladdmode) |
| 7290 |
{ |
| 7291 |
case 0: |
| 7292 |
self->muladd_func_ptr = TrigTableRecTimeStream_postprocessing_ii; |
| 7293 |
break; |
| 7294 |
|
| 7295 |
case 1: |
| 7296 |
self->muladd_func_ptr = TrigTableRecTimeStream_postprocessing_ai; |
| 7297 |
break; |
| 7298 |
|
| 7299 |
case 2: |
| 7300 |
self->muladd_func_ptr = TrigTableRecTimeStream_postprocessing_revai; |
| 7301 |
break; |
| 7302 |
|
| 7303 |
case 10: |
| 7304 |
self->muladd_func_ptr = TrigTableRecTimeStream_postprocessing_ia; |
| 7305 |
break; |
| 7306 |
|
| 7307 |
case 11: |
| 7308 |
self->muladd_func_ptr = TrigTableRecTimeStream_postprocessing_aa; |
| 7309 |
break; |
| 7310 |
|
| 7311 |
case 12: |
| 7312 |
self->muladd_func_ptr = TrigTableRecTimeStream_postprocessing_revaa; |
| 7313 |
break; |
| 7314 |
|
| 7315 |
case 20: |
| 7316 |
self->muladd_func_ptr = TrigTableRecTimeStream_postprocessing_ireva; |
| 7317 |
break; |
| 7318 |
|
| 7319 |
case 21: |
| 7320 |
self->muladd_func_ptr = TrigTableRecTimeStream_postprocessing_areva; |
| 7321 |
break; |
| 7322 |
|
| 7323 |
case 22: |
| 7324 |
self->muladd_func_ptr = TrigTableRecTimeStream_postprocessing_revareva; |
| 7325 |
break; |
| 7326 |
} |
| 7327 |
} |
| 7328 |
|
| 7329 |
static void |
| 7330 |
TrigTableRecTimeStream_compute_next_data_frame(TrigTableRecTimeStream *self) |
| 7331 |
{ |
| 7332 |
int i; |
| 7333 |
MYFLT *tmp; |
| 7334 |
tmp = TrigTableRec_getTimeBuffer((TrigTableRec *)self->mainPlayer); |
| 7335 |
|
| 7336 |
for (i = 0; i < self->bufsize; i++) |
| 7337 |
{ |
| 7338 |
self->data[i] = tmp[i]; |
| 7339 |
} |
| 7340 |
|
| 7341 |
(*self->muladd_func_ptr)(self); |
| 7342 |
} |
| 7343 |
|
| 7344 |
static int |
| 7345 |
TrigTableRecTimeStream_traverse(TrigTableRecTimeStream *self, visitproc visit, void *arg) |
| 7346 |
{ |
| 7347 |
pyo_VISIT |
| 7348 |
Py_VISIT(self->mainPlayer); |
| 7349 |
return 0; |
| 7350 |
} |
| 7351 |
|
| 7352 |
static int |
| 7353 |
TrigTableRecTimeStream_clear(TrigTableRecTimeStream *self) |
| 7354 |
{ |
| 7355 |
pyo_CLEAR |
| 7356 |
Py_CLEAR(self->mainPlayer); |
| 7357 |
return 0; |
| 7358 |
} |
| 7359 |
|
| 7360 |
static void |
| 7361 |
TrigTableRecTimeStream_dealloc(TrigTableRecTimeStream* self) |
| 7362 |
{ |
| 7363 |
pyo_DEALLOC |
| 7364 |
TrigTableRecTimeStream_clear(self); |
| 7365 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 7366 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 7367 |
} |
| 7368 |
|
| 7369 |
static PyObject * |
| 7370 |
TrigTableRecTimeStream_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 7371 |
{ |
| 7372 |
int i; |
| 7373 |
PyObject *maintmp = NULL; |
| 7374 |
TrigTableRecTimeStream *self; |
| 7375 |
self = (TrigTableRecTimeStream *)type->tp_alloc(type, 0); |
| 7376 |
|
| 7377 |
self->modebuffer[0] = 0; |
| 7378 |
self->modebuffer[1] = 0; |
| 7379 |
|
| 7380 |
INIT_OBJECT_COMMON |
| 7381 |
Stream_setFunctionPtr(self->stream, TrigTableRecTimeStream_compute_next_data_frame); |
| 7382 |
self->mode_func_ptr = TrigTableRecTimeStream_setProcMode; |
| 7383 |
|
| 7384 |
static char *kwlist[] = {"mainPlayer", NULL}; |
| 7385 |
|
| 7386 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, &maintmp)) |
| 7387 |
Py_RETURN_NONE; |
| 7388 |
|
| 7389 |
self->mainPlayer = (TrigTableRec *)maintmp; |
| 7390 |
Py_INCREF(self->mainPlayer); |
| 7391 |
|
| 7392 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 7393 |
|
| 7394 |
(*self->mode_func_ptr)(self); |
| 7395 |
|
| 7396 |
return (PyObject *)self; |
| 7397 |
} |
| 7398 |
|
| 7399 |
static PyObject * TrigTableRecTimeStream_getServer(TrigTableRecTimeStream* self) { GET_SERVER }; |
| 7400 |
static PyObject * TrigTableRecTimeStream_getStream(TrigTableRecTimeStream* self) { GET_STREAM }; |
| 7401 |
static PyObject * TrigTableRecTimeStream_setMul(TrigTableRecTimeStream *self, PyObject *arg) { SET_MUL }; |
| 7402 |
static PyObject * TrigTableRecTimeStream_setAdd(TrigTableRecTimeStream *self, PyObject *arg) { SET_ADD }; |
| 7403 |
static PyObject * TrigTableRecTimeStream_setSub(TrigTableRecTimeStream *self, PyObject *arg) { SET_SUB }; |
| 7404 |
static PyObject * TrigTableRecTimeStream_setDiv(TrigTableRecTimeStream *self, PyObject *arg) { SET_DIV }; |
| 7405 |
|
| 7406 |
static PyObject * TrigTableRecTimeStream_play(TrigTableRecTimeStream *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 7407 |
static PyObject * TrigTableRecTimeStream_out(TrigTableRecTimeStream *self, PyObject *args, PyObject *kwds) { OUT }; |
| 7408 |
static PyObject * TrigTableRecTimeStream_stop(TrigTableRecTimeStream *self, PyObject *args, PyObject *kwds) { STOP }; |
| 7409 |
|
| 7410 |
static PyObject * TrigTableRecTimeStream_multiply(TrigTableRecTimeStream *self, PyObject *arg) { MULTIPLY }; |
| 7411 |
static PyObject * TrigTableRecTimeStream_inplace_multiply(TrigTableRecTimeStream *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 7412 |
static PyObject * TrigTableRecTimeStream_add(TrigTableRecTimeStream *self, PyObject *arg) { ADD }; |
| 7413 |
static PyObject * TrigTableRecTimeStream_inplace_add(TrigTableRecTimeStream *self, PyObject *arg) { INPLACE_ADD }; |
| 7414 |
static PyObject * TrigTableRecTimeStream_sub(TrigTableRecTimeStream *self, PyObject *arg) { SUB }; |
| 7415 |
static PyObject * TrigTableRecTimeStream_inplace_sub(TrigTableRecTimeStream *self, PyObject *arg) { INPLACE_SUB }; |
| 7416 |
static PyObject * TrigTableRecTimeStream_div(TrigTableRecTimeStream *self, PyObject *arg) { DIV }; |
| 7417 |
static PyObject * TrigTableRecTimeStream_inplace_div(TrigTableRecTimeStream *self, PyObject *arg) { INPLACE_DIV }; |
| 7418 |
|
| 7419 |
static PyMemberDef TrigTableRecTimeStream_members[] = |
| 7420 |
{ |
| 7421 |
{"server", T_OBJECT_EX, offsetof(TrigTableRecTimeStream, server), 0, "Pyo server."}, |
| 7422 |
{"stream", T_OBJECT_EX, offsetof(TrigTableRecTimeStream, stream), 0, "Stream object."}, |
| 7423 |
{"mul", T_OBJECT_EX, offsetof(TrigTableRecTimeStream, mul), 0, "Mul factor."}, |
| 7424 |
{"add", T_OBJECT_EX, offsetof(TrigTableRecTimeStream, add), 0, "Add factor."}, |
| 7425 |
{NULL} /* Sentinel */ |
| 7426 |
}; |
| 7427 |
|
| 7428 |
static PyMethodDef TrigTableRecTimeStream_methods[] = |
| 7429 |
{ |
| 7430 |
{"getServer", (PyCFunction)TrigTableRecTimeStream_getServer, METH_NOARGS, "Returns server object."}, |
| 7431 |
{"_getStream", (PyCFunction)TrigTableRecTimeStream_getStream, METH_NOARGS, "Returns stream object."}, |
| 7432 |
{"play", (PyCFunction)TrigTableRecTimeStream_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 7433 |
{"out", (PyCFunction)TrigTableRecTimeStream_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."}, |
| 7434 |
{"stop", (PyCFunction)TrigTableRecTimeStream_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 7435 |
{"setMul", (PyCFunction)TrigTableRecTimeStream_setMul, METH_O, "Sets oscillator mul factor."}, |
| 7436 |
{"setAdd", (PyCFunction)TrigTableRecTimeStream_setAdd, METH_O, "Sets oscillator add factor."}, |
| 7437 |
{"setSub", (PyCFunction)TrigTableRecTimeStream_setSub, METH_O, "Sets inverse add factor."}, |
| 7438 |
{"setDiv", (PyCFunction)TrigTableRecTimeStream_setDiv, METH_O, "Sets inverse mul factor."}, |
| 7439 |
{NULL} /* Sentinel */ |
| 7440 |
}; |
| 7441 |
|
| 7442 |
static PyNumberMethods TrigTableRecTimeStream_as_number = |
| 7443 |
{ |
| 7444 |
(binaryfunc)TrigTableRecTimeStream_add, /*nb_add*/ |
| 7445 |
(binaryfunc)TrigTableRecTimeStream_sub, /*nb_subtract*/ |
| 7446 |
(binaryfunc)TrigTableRecTimeStream_multiply, /*nb_multiply*/ |
| 7447 |
0, /*nb_remainder*/ |
| 7448 |
0, /*nb_divmod*/ |
| 7449 |
0, /*nb_power*/ |
| 7450 |
0, /*nb_neg*/ |
| 7451 |
0, /*nb_pos*/ |
| 7452 |
0, /*(unaryfunc)array_abs,*/ |
| 7453 |
0, /*nb_nonzero*/ |
| 7454 |
0, /*nb_invert*/ |
| 7455 |
0, /*nb_lshift*/ |
| 7456 |
0, /*nb_rshift*/ |
| 7457 |
0, /*nb_and*/ |
| 7458 |
0, /*nb_xor*/ |
| 7459 |
0, /*nb_or*/ |
| 7460 |
0, /*nb_int*/ |
| 7461 |
0, /*nb_long*/ |
| 7462 |
0, /*nb_float*/ |
| 7463 |
(binaryfunc)TrigTableRecTimeStream_inplace_add, /*inplace_add*/ |
| 7464 |
(binaryfunc)TrigTableRecTimeStream_inplace_sub, /*inplace_subtract*/ |
| 7465 |
(binaryfunc)TrigTableRecTimeStream_inplace_multiply, /*inplace_multiply*/ |
| 7466 |
0, /*inplace_remainder*/ |
| 7467 |
0, /*inplace_power*/ |
| 7468 |
0, /*inplace_lshift*/ |
| 7469 |
0, /*inplace_rshift*/ |
| 7470 |
0, /*inplace_and*/ |
| 7471 |
0, /*inplace_xor*/ |
| 7472 |
0, /*inplace_or*/ |
| 7473 |
0, /*nb_floor_divide*/ |
| 7474 |
(binaryfunc)TrigTableRecTimeStream_div, /*nb_true_divide*/ |
| 7475 |
0, /*nb_inplace_floor_divide*/ |
| 7476 |
(binaryfunc)TrigTableRecTimeStream_inplace_div, /*nb_inplace_true_divide*/ |
| 7477 |
0, /* nb_index */ |
| 7478 |
}; |
| 7479 |
|
| 7480 |
PyTypeObject TrigTableRecTimeStreamType = |
| 7481 |
{ |
| 7482 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 7483 |
"_pyo.TrigTableRecTimeStream_base", /*tp_name*/ |
| 7484 |
sizeof(TrigTableRecTimeStream), /*tp_basicsize*/ |
| 7485 |
0, /*tp_itemsize*/ |
| 7486 |
(destructor)TrigTableRecTimeStream_dealloc, /*tp_dealloc*/ |
| 7487 |
0, /*tp_print*/ |
| 7488 |
0, /*tp_getattr*/ |
| 7489 |
0, /*tp_setattr*/ |
| 7490 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 7491 |
0, /*tp_repr*/ |
| 7492 |
&TrigTableRecTimeStream_as_number, /*tp_as_number*/ |
| 7493 |
0, /*tp_as_sequence*/ |
| 7494 |
0, /*tp_as_mapping*/ |
| 7495 |
0, /*tp_hash */ |
| 7496 |
0, /*tp_call*/ |
| 7497 |
0, /*tp_str*/ |
| 7498 |
0, /*tp_getattro*/ |
| 7499 |
0, /*tp_setattro*/ |
| 7500 |
0, /*tp_as_buffer*/ |
| 7501 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 7502 |
"TrigTableRecTimeStream objects. Returns the current recording time, in samples, of a TableRec object.", /* tp_doc */ |
| 7503 |
(traverseproc)TrigTableRecTimeStream_traverse, /* tp_traverse */ |
| 7504 |
(inquiry)TrigTableRecTimeStream_clear, /* tp_clear */ |
| 7505 |
0, /* tp_richcompare */ |
| 7506 |
0, /* tp_weaklistoffset */ |
| 7507 |
0, /* tp_iter */ |
| 7508 |
0, /* tp_iternext */ |
| 7509 |
TrigTableRecTimeStream_methods, /* tp_methods */ |
| 7510 |
TrigTableRecTimeStream_members, /* tp_members */ |
| 7511 |
0, /* tp_getset */ |
| 7512 |
0, /* tp_base */ |
| 7513 |
0, /* tp_dict */ |
| 7514 |
0, /* tp_descr_get */ |
| 7515 |
0, /* tp_descr_set */ |
| 7516 |
0, /* tp_dictoffset */ |
| 7517 |
0, /* tp_init */ |
| 7518 |
0, /* tp_alloc */ |
| 7519 |
TrigTableRecTimeStream_new, /* tp_new */ |
| 7520 |
}; |
| 7521 |
|
| 7522 |
/******************************/ |
| 7523 |
/* TablePut object definition */ |
| 7524 |
/******************************/ |
| 7525 |
typedef struct |
| 7526 |
{ |
| 7527 |
pyo_audio_HEAD |
| 7528 |
PyObject *input; |
| 7529 |
Stream *input_stream; |
| 7530 |
PyObject *table; |
| 7531 |
T_SIZE_T pointer; |
| 7532 |
int active; |
| 7533 |
MYFLT last_value; |
| 7534 |
MYFLT *trigsBuffer; |
| 7535 |
TriggerStream *trig_stream; |
| 7536 |
} TablePut; |
| 7537 |
|
| 7538 |
static void |
| 7539 |
TablePut_compute_next_data_frame(TablePut *self) |
| 7540 |
{ |
| 7541 |
int i; |
| 7542 |
T_SIZE_T size = TableStream_getSize((TableStream *)self->table); |
| 7543 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 7544 |
|
| 7545 |
for (i = 0; i < self->bufsize; i++) |
| 7546 |
{ |
| 7547 |
self->trigsBuffer[i] = 0.0; |
| 7548 |
} |
| 7549 |
|
| 7550 |
if (self->active == 1) |
| 7551 |
{ |
| 7552 |
for (i = 0; i < self->bufsize; i++) |
| 7553 |
{ |
| 7554 |
if (in[i] != self->last_value) |
| 7555 |
{ |
| 7556 |
self->last_value = in[i]; |
| 7557 |
TableStream_record((TableStream *)self->table, self->pointer++, self->last_value); |
| 7558 |
|
| 7559 |
if (self->pointer >= size) |
| 7560 |
{ |
| 7561 |
self->active = 0; |
| 7562 |
self->trigsBuffer[i] = 1.0; |
| 7563 |
break; |
| 7564 |
} |
| 7565 |
} |
| 7566 |
} |
| 7567 |
} |
| 7568 |
} |
| 7569 |
|
| 7570 |
static int |
| 7571 |
TablePut_traverse(TablePut *self, visitproc visit, void *arg) |
| 7572 |
{ |
| 7573 |
pyo_VISIT |
| 7574 |
Py_VISIT(self->input); |
| 7575 |
return 0; |
| 7576 |
} |
| 7577 |
|
| 7578 |
static int |
| 7579 |
TablePut_clear(TablePut *self) |
| 7580 |
{ |
| 7581 |
pyo_CLEAR |
| 7582 |
Py_CLEAR(self->input); |
| 7583 |
return 0; |
| 7584 |
} |
| 7585 |
|
| 7586 |
static void |
| 7587 |
TablePut_dealloc(TablePut* self) |
| 7588 |
{ |
| 7589 |
pyo_DEALLOC |
| 7590 |
PyMem_RawFree(self->trigsBuffer); |
| 7591 |
TablePut_clear(self); |
| 7592 |
Py_TYPE(self->trig_stream)->tp_free((PyObject*)self->trig_stream); |
| 7593 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 7594 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 7595 |
} |
| 7596 |
|
| 7597 |
static PyObject * |
| 7598 |
TablePut_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 7599 |
{ |
| 7600 |
int i; |
| 7601 |
PyObject *inputtmp, *input_streamtmp, *tabletmp; |
| 7602 |
TablePut *self; |
| 7603 |
self = (TablePut *)type->tp_alloc(type, 0); |
| 7604 |
|
| 7605 |
self->pointer = 0; |
| 7606 |
self->active = 1; |
| 7607 |
self->last_value = 0.0; |
| 7608 |
|
| 7609 |
INIT_OBJECT_COMMON |
| 7610 |
|
| 7611 |
Stream_setFunctionPtr(self->stream, TablePut_compute_next_data_frame); |
| 7612 |
|
| 7613 |
static char *kwlist[] = {"input", "table", NULL}; |
| 7614 |
|
| 7615 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &inputtmp, &tabletmp)) |
| 7616 |
Py_RETURN_NONE; |
| 7617 |
|
| 7618 |
INIT_INPUT_STREAM |
| 7619 |
|
| 7620 |
if ( PyObject_HasAttrString((PyObject *)tabletmp, "getTableStream") == 0 ) |
| 7621 |
{ |
| 7622 |
PyErr_SetString(PyExc_TypeError, "\"table\" argument of TablePut must be a PyoTableObject.\n"); |
| 7623 |
Py_RETURN_NONE; |
| 7624 |
} |
| 7625 |
|
| 7626 |
self->table = PyObject_CallMethod((PyObject *)tabletmp, "getTableStream", ""); |
| 7627 |
|
| 7628 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 7629 |
|
| 7630 |
self->trigsBuffer = (MYFLT *)PyMem_RawRealloc(self->trigsBuffer, self->bufsize * sizeof(MYFLT)); |
| 7631 |
|
| 7632 |
for (i = 0; i < self->bufsize; i++) |
| 7633 |
{ |
| 7634 |
self->trigsBuffer[i] = 0.0; |
| 7635 |
} |
| 7636 |
|
| 7637 |
MAKE_NEW_TRIGGER_STREAM(self->trig_stream, &TriggerStreamType, NULL); |
| 7638 |
TriggerStream_setData(self->trig_stream, self->trigsBuffer); |
| 7639 |
|
| 7640 |
return (PyObject *)self; |
| 7641 |
} |
| 7642 |
|
| 7643 |
static PyObject * TablePut_getServer(TablePut* self) { GET_SERVER }; |
| 7644 |
static PyObject * TablePut_getStream(TablePut* self) { GET_STREAM }; |
| 7645 |
static PyObject * TablePut_getTriggerStream(TablePut* self) { GET_TRIGGER_STREAM }; |
| 7646 |
|
| 7647 |
static PyObject * TablePut_play(TablePut *self, PyObject *args, PyObject *kwds) |
| 7648 |
{ |
| 7649 |
self->pointer = 0; |
| 7650 |
self->active = 1; |
| 7651 |
PLAY |
| 7652 |
}; |
| 7653 |
|
| 7654 |
static PyObject * TablePut_stop(TablePut *self, PyObject *args, PyObject *kwds) { STOP }; |
| 7655 |
|
| 7656 |
static PyObject * |
| 7657 |
TablePut_setTable(TablePut *self, PyObject *arg) |
| 7658 |
{ |
| 7659 |
ASSERT_ARG_NOT_NULL |
| 7660 |
|
| 7661 |
Py_DECREF(self->table); |
| 7662 |
self->table = PyObject_CallMethod((PyObject *)arg, "getTableStream", ""); |
| 7663 |
|
| 7664 |
Py_RETURN_NONE; |
| 7665 |
} |
| 7666 |
|
| 7667 |
static PyMemberDef TablePut_members[] = |
| 7668 |
{ |
| 7669 |
{"server", T_OBJECT_EX, offsetof(TablePut, server), 0, "Pyo server."}, |
| 7670 |
{"stream", T_OBJECT_EX, offsetof(TablePut, stream), 0, "Stream object."}, |
| 7671 |
{"trig_stream", T_OBJECT_EX, offsetof(TablePut, trig_stream), 0, "Trigger Stream object."}, |
| 7672 |
{"input", T_OBJECT_EX, offsetof(TablePut, input), 0, "Input sound object."}, |
| 7673 |
{"table", T_OBJECT_EX, offsetof(TablePut, table), 0, "Table to record in."}, |
| 7674 |
{NULL} /* Sentinel */ |
| 7675 |
}; |
| 7676 |
|
| 7677 |
static PyMethodDef TablePut_methods[] = |
| 7678 |
{ |
| 7679 |
{"getServer", (PyCFunction)TablePut_getServer, METH_NOARGS, "Returns server object."}, |
| 7680 |
{"_getStream", (PyCFunction)TablePut_getStream, METH_NOARGS, "Returns stream object."}, |
| 7681 |
{"_getTriggerStream", (PyCFunction)TablePut_getTriggerStream, METH_NOARGS, "Returns trigger stream object."}, |
| 7682 |
{"setTable", (PyCFunction)TablePut_setTable, METH_O, "Sets a new data table."}, |
| 7683 |
{"play", (PyCFunction)TablePut_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 7684 |
{"stop", (PyCFunction)TablePut_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 7685 |
{NULL} /* Sentinel */ |
| 7686 |
}; |
| 7687 |
|
| 7688 |
PyTypeObject TablePutType = |
| 7689 |
{ |
| 7690 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 7691 |
"_pyo.TablePut_base", /*tp_name*/ |
| 7692 |
sizeof(TablePut), /*tp_basicsize*/ |
| 7693 |
0, /*tp_itemsize*/ |
| 7694 |
(destructor)TablePut_dealloc, /*tp_dealloc*/ |
| 7695 |
0, /*tp_print*/ |
| 7696 |
0, /*tp_getattr*/ |
| 7697 |
0, /*tp_setattr*/ |
| 7698 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 7699 |
0, /*tp_repr*/ |
| 7700 |
0, /*tp_as_number*/ |
| 7701 |
0, /*tp_as_sequence*/ |
| 7702 |
0, /*tp_as_mapping*/ |
| 7703 |
0, /*tp_hash */ |
| 7704 |
0, /*tp_call*/ |
| 7705 |
0, /*tp_str*/ |
| 7706 |
0, /*tp_getattro*/ |
| 7707 |
0, /*tp_setattro*/ |
| 7708 |
0, /*tp_as_buffer*/ |
| 7709 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 7710 |
"TablePut objects. Record new value in input in a data table object.", /* tp_doc */ |
| 7711 |
(traverseproc)TablePut_traverse, /* tp_traverse */ |
| 7712 |
(inquiry)TablePut_clear, /* tp_clear */ |
| 7713 |
0, /* tp_richcompare */ |
| 7714 |
0, /* tp_weaklistoffset */ |
| 7715 |
0, /* tp_iter */ |
| 7716 |
0, /* tp_iternext */ |
| 7717 |
TablePut_methods, /* tp_methods */ |
| 7718 |
TablePut_members, /* tp_members */ |
| 7719 |
0, /* tp_getset */ |
| 7720 |
0, /* tp_base */ |
| 7721 |
0, /* tp_dict */ |
| 7722 |
0, /* tp_descr_get */ |
| 7723 |
0, /* tp_descr_set */ |
| 7724 |
0, /* tp_dictoffset */ |
| 7725 |
0, /* tp_init */ |
| 7726 |
0, /* tp_alloc */ |
| 7727 |
TablePut_new, /* tp_new */ |
| 7728 |
}; |
| 7729 |
|
| 7730 |
/******************************/ |
| 7731 |
/* TableWrite object definition */ |
| 7732 |
/******************************/ |
| 7733 |
typedef struct |
| 7734 |
{ |
| 7735 |
pyo_audio_HEAD |
| 7736 |
PyObject *input; |
| 7737 |
Stream *input_stream; |
| 7738 |
PyObject *pos; |
| 7739 |
Stream *pos_stream; |
| 7740 |
PyObject *table; |
| 7741 |
int mode; |
| 7742 |
int maxwindow; |
| 7743 |
T_SIZE_T lastPos; |
| 7744 |
MYFLT lastValue; |
| 7745 |
T_SIZE_T count; |
| 7746 |
MYFLT accum; |
| 7747 |
MYFLT valInTable; |
| 7748 |
} TableWrite; |
| 7749 |
|
| 7750 |
static void |
| 7751 |
TableWrite_compute_next_data_frame(TableWrite *self) |
| 7752 |
{ |
| 7753 |
T_SIZE_T i, j, ipos; |
| 7754 |
|
| 7755 |
MYFLT feed = TableStream_getFeedback((TableStream *)self->table); |
| 7756 |
MYFLT *tablelist = TableStream_getData((TableStream *)self->table); |
| 7757 |
T_SIZE_T size = TableStream_getSize((TableStream *)self->table); |
| 7758 |
|
| 7759 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 7760 |
MYFLT *pos = Stream_getData((Stream *)self->pos_stream); |
| 7761 |
|
| 7762 |
for (i = 0; i < self->bufsize; i++) |
| 7763 |
{ |
| 7764 |
if (self->mode == 0) |
| 7765 |
ipos = (T_SIZE_T)(pos[i] * size + 0.5); |
| 7766 |
else |
| 7767 |
ipos = (T_SIZE_T)(pos[i] + 0.5); |
| 7768 |
|
| 7769 |
if (ipos >= 0 && ipos < size) |
| 7770 |
{ |
| 7771 |
if (self->lastPos < 0) /* Init case. */ |
| 7772 |
{ |
| 7773 |
self->valInTable = tablelist[ipos]; |
| 7774 |
self->count = 1; |
| 7775 |
self->accum = in[i]; |
| 7776 |
tablelist[ipos] = in[i] + tablelist[ipos] * feed; |
| 7777 |
} |
| 7778 |
else if (ipos == self->lastPos) /* Same position, average inputs. */ |
| 7779 |
{ |
| 7780 |
self->count += 1; |
| 7781 |
self->accum += in[i]; |
| 7782 |
tablelist[ipos] = self->accum / self->count + self->valInTable * feed; |
| 7783 |
} |
| 7784 |
else /* Position changed. */ |
| 7785 |
{ |
| 7786 |
T_SIZE_T steps, dir; |
| 7787 |
|
| 7788 |
if (ipos > self->lastPos) /* Move forward. */ |
| 7789 |
{ |
| 7790 |
steps = ipos - self->lastPos; |
| 7791 |
|
| 7792 |
if (steps > self->maxwindow) |
| 7793 |
steps = 1; |
| 7794 |
|
| 7795 |
dir = 1; |
| 7796 |
} |
| 7797 |
else /* Move backward. */ |
| 7798 |
{ |
| 7799 |
steps = self->lastPos - ipos; |
| 7800 |
|
| 7801 |
if (steps > self->maxwindow) |
| 7802 |
steps = 1; |
| 7803 |
|
| 7804 |
dir = -1; |
| 7805 |
} |
| 7806 |
|
| 7807 |
self->valInTable = tablelist[ipos]; |
| 7808 |
self->count = 1; |
| 7809 |
self->accum = in[i]; |
| 7810 |
|
| 7811 |
if (steps < 2) /* Moved one sample, no need to interpolate. */ |
| 7812 |
{ |
| 7813 |
tablelist[ipos] = in[i] + tablelist[ipos] * feed; |
| 7814 |
} |
| 7815 |
else /* Interpolate between last pos and current pos. */ |
| 7816 |
{ |
| 7817 |
MYFLT inc = (in[i] - self->lastValue) / steps; |
| 7818 |
|
| 7819 |
for (j = 1; j <= steps; j++) |
| 7820 |
{ |
| 7821 |
MYFLT val = self->lastValue + inc * j; |
| 7822 |
tablelist[self->lastPos + j * dir] = val + tablelist[self->lastPos + j * dir] * feed; |
| 7823 |
} |
| 7824 |
} |
| 7825 |
} |
| 7826 |
|
| 7827 |
self->lastPos = ipos; |
| 7828 |
self->lastValue = in[i]; |
| 7829 |
} |
| 7830 |
} |
| 7831 |
} |
| 7832 |
|
| 7833 |
static int |
| 7834 |
TableWrite_traverse(TableWrite *self, visitproc visit, void *arg) |
| 7835 |
{ |
| 7836 |
pyo_VISIT |
| 7837 |
Py_VISIT(self->input); |
| 7838 |
Py_VISIT(self->pos); |
| 7839 |
return 0; |
| 7840 |
} |
| 7841 |
|
| 7842 |
static int |
| 7843 |
TableWrite_clear(TableWrite *self) |
| 7844 |
{ |
| 7845 |
pyo_CLEAR |
| 7846 |
Py_CLEAR(self->input); |
| 7847 |
Py_CLEAR(self->pos); |
| 7848 |
return 0; |
| 7849 |
} |
| 7850 |
|
| 7851 |
static void |
| 7852 |
TableWrite_dealloc(TableWrite* self) |
| 7853 |
{ |
| 7854 |
pyo_DEALLOC |
| 7855 |
TableWrite_clear(self); |
| 7856 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 7857 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 7858 |
} |
| 7859 |
|
| 7860 |
static PyObject * |
| 7861 |
TableWrite_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 7862 |
{ |
| 7863 |
int i; |
| 7864 |
PyObject *inputtmp, *input_streamtmp, *postmp, *tabletmp; |
| 7865 |
TableWrite *self; |
| 7866 |
self = (TableWrite *)type->tp_alloc(type, 0); |
| 7867 |
|
| 7868 |
self->pos = PyFloat_FromDouble(0.0); |
| 7869 |
|
| 7870 |
self->mode = 0; |
| 7871 |
self->maxwindow = 1024; |
| 7872 |
self->lastPos = -1; |
| 7873 |
self->lastValue = 0.0; |
| 7874 |
self->count = 0; |
| 7875 |
self->accum = 0.0; |
| 7876 |
self->valInTable = 0.0; |
| 7877 |
|
| 7878 |
INIT_OBJECT_COMMON |
| 7879 |
|
| 7880 |
Stream_setFunctionPtr(self->stream, TableWrite_compute_next_data_frame); |
| 7881 |
|
| 7882 |
static char *kwlist[] = {"input", "pos", "table", "mode", "maxwindow", NULL}; |
| 7883 |
|
| 7884 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OOOii", kwlist, &inputtmp, &postmp, &tabletmp, &self->mode, &self->maxwindow)) |
| 7885 |
Py_RETURN_NONE; |
| 7886 |
|
| 7887 |
INIT_INPUT_STREAM |
| 7888 |
|
| 7889 |
if (postmp) |
| 7890 |
{ |
| 7891 |
PyObject_CallMethod((PyObject *)self, "setPos", "O", postmp); |
| 7892 |
} |
| 7893 |
|
| 7894 |
if ( PyObject_HasAttrString((PyObject *)tabletmp, "getTableStream") == 0 ) |
| 7895 |
{ |
| 7896 |
PyErr_SetString(PyExc_TypeError, "\"table\" argument of TableWrite must be a PyoTableObject.\n"); |
| 7897 |
Py_RETURN_NONE; |
| 7898 |
} |
| 7899 |
|
| 7900 |
self->table = PyObject_CallMethod((PyObject *)tabletmp, "getTableStream", ""); |
| 7901 |
|
| 7902 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 7903 |
|
| 7904 |
return (PyObject *)self; |
| 7905 |
} |
| 7906 |
|
| 7907 |
static PyObject * TableWrite_getServer(TableWrite* self) { GET_SERVER }; |
| 7908 |
static PyObject * TableWrite_getStream(TableWrite* self) { GET_STREAM }; |
| 7909 |
|
| 7910 |
static PyObject * TableWrite_play(TableWrite *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 7911 |
static PyObject * TableWrite_stop(TableWrite *self, PyObject *args, PyObject *kwds) { STOP }; |
| 7912 |
|
| 7913 |
static PyObject * |
| 7914 |
TableWrite_setPos(TableWrite *self, PyObject *arg) |
| 7915 |
{ |
| 7916 |
ASSERT_ARG_NOT_NULL |
| 7917 |
|
| 7918 |
if (PyObject_HasAttrString((PyObject *)arg, "server") == 0) |
| 7919 |
{ |
| 7920 |
PyErr_SetString(PyExc_TypeError, "\"pos\" argument of TableWrite must be a PyoObject.\n"); |
| 7921 |
Py_RETURN_NONE; |
| 7922 |
} |
| 7923 |
|
| 7924 |
Py_DECREF(self->pos); |
| 7925 |
|
| 7926 |
self->pos = arg; |
| 7927 |
Py_INCREF(self->pos); |
| 7928 |
PyObject *streamtmp = PyObject_CallMethod((PyObject *)self->pos, "_getStream", NULL); |
| 7929 |
self->pos_stream = (Stream *)streamtmp; |
| 7930 |
Py_INCREF(self->pos_stream); |
| 7931 |
|
| 7932 |
Py_RETURN_NONE; |
| 7933 |
} |
| 7934 |
|
| 7935 |
static PyObject * |
| 7936 |
TableWrite_setTable(TableWrite *self, PyObject *arg) |
| 7937 |
{ |
| 7938 |
ASSERT_ARG_NOT_NULL |
| 7939 |
|
| 7940 |
Py_DECREF(self->table); |
| 7941 |
self->table = PyObject_CallMethod((PyObject *)arg, "getTableStream", ""); |
| 7942 |
|
| 7943 |
Py_RETURN_NONE; |
| 7944 |
} |
| 7945 |
|
| 7946 |
static PyMemberDef TableWrite_members[] = |
| 7947 |
{ |
| 7948 |
{"server", T_OBJECT_EX, offsetof(TableWrite, server), 0, "Pyo server."}, |
| 7949 |
{"stream", T_OBJECT_EX, offsetof(TableWrite, stream), 0, "Stream object."}, |
| 7950 |
{"input", T_OBJECT_EX, offsetof(TableWrite, input), 0, "Input sound object."}, |
| 7951 |
{"table", T_OBJECT_EX, offsetof(TableWrite, table), 0, "Table to record in."}, |
| 7952 |
{"pos", T_OBJECT_EX, offsetof(TableWrite, pos), 0, "Position in the Table to record in."}, |
| 7953 |
{NULL} /* Sentinel */ |
| 7954 |
}; |
| 7955 |
|
| 7956 |
static PyMethodDef TableWrite_methods[] = |
| 7957 |
{ |
| 7958 |
{"getServer", (PyCFunction)TableWrite_getServer, METH_NOARGS, "Returns server object."}, |
| 7959 |
{"_getStream", (PyCFunction)TableWrite_getStream, METH_NOARGS, "Returns stream object."}, |
| 7960 |
{"setTable", (PyCFunction)TableWrite_setTable, METH_O, "Sets a new table."}, |
| 7961 |
{"setPos", (PyCFunction)TableWrite_setPos, METH_O, "Sets position in the sound table."}, |
| 7962 |
{"play", (PyCFunction)TableWrite_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 7963 |
{"stop", (PyCFunction)TableWrite_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 7964 |
{NULL} /* Sentinel */ |
| 7965 |
}; |
| 7966 |
|
| 7967 |
PyTypeObject TableWriteType = |
| 7968 |
{ |
| 7969 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 7970 |
"_pyo.TableWrite_base", /*tp_name*/ |
| 7971 |
sizeof(TableWrite), /*tp_basicsize*/ |
| 7972 |
0, /*tp_itemsize*/ |
| 7973 |
(destructor)TableWrite_dealloc, /*tp_dealloc*/ |
| 7974 |
0, /*tp_print*/ |
| 7975 |
0, /*tp_getattr*/ |
| 7976 |
0, /*tp_setattr*/ |
| 7977 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 7978 |
0, /*tp_repr*/ |
| 7979 |
0, /*tp_as_number*/ |
| 7980 |
0, /*tp_as_sequence*/ |
| 7981 |
0, /*tp_as_mapping*/ |
| 7982 |
0, /*tp_hash */ |
| 7983 |
0, /*tp_call*/ |
| 7984 |
0, /*tp_str*/ |
| 7985 |
0, /*tp_getattro*/ |
| 7986 |
0, /*tp_setattro*/ |
| 7987 |
0, /*tp_as_buffer*/ |
| 7988 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 7989 |
"TableWrite objects. Record audio input in a table object.", /* tp_doc */ |
| 7990 |
(traverseproc)TableWrite_traverse, /* tp_traverse */ |
| 7991 |
(inquiry)TableWrite_clear, /* tp_clear */ |
| 7992 |
0, /* tp_richcompare */ |
| 7993 |
0, /* tp_weaklistoffset */ |
| 7994 |
0, /* tp_iter */ |
| 7995 |
0, /* tp_iternext */ |
| 7996 |
TableWrite_methods, /* tp_methods */ |
| 7997 |
TableWrite_members, /* tp_members */ |
| 7998 |
0, /* tp_getset */ |
| 7999 |
0, /* tp_base */ |
| 8000 |
0, /* tp_dict */ |
| 8001 |
0, /* tp_descr_get */ |
| 8002 |
0, /* tp_descr_set */ |
| 8003 |
0, /* tp_dictoffset */ |
| 8004 |
0, /* tp_init */ |
| 8005 |
0, /* tp_alloc */ |
| 8006 |
TableWrite_new, /* tp_new */ |
| 8007 |
}; |
| 8008 |
|
| 8009 |
/*************************/ |
| 8010 |
/* SharedTable structure */ |
| 8011 |
/*************************/ |
| 8012 |
typedef struct |
| 8013 |
{ |
| 8014 |
pyo_table_HEAD |
| 8015 |
char *name; |
| 8016 |
int create; |
| 8017 |
int fd; |
| 8018 |
double sr; |
| 8019 |
} SharedTable; |
| 8020 |
|
| 8021 |
static int |
| 8022 |
SharedTable_traverse(SharedTable *self, visitproc visit, void *arg) |
| 8023 |
{ |
| 8024 |
pyo_table_VISIT |
| 8025 |
return 0; |
| 8026 |
} |
| 8027 |
|
| 8028 |
static int |
| 8029 |
SharedTable_clear(SharedTable *self) |
| 8030 |
{ |
| 8031 |
pyo_table_CLEAR |
| 8032 |
return 0; |
| 8033 |
} |
| 8034 |
|
| 8035 |
static void |
| 8036 |
SharedTable_dealloc(SharedTable* self) |
| 8037 |
{ |
| 8038 |
#if !defined(_WIN32) && !defined(_WIN64) |
| 8039 |
close(self->fd); |
| 8040 |
|
| 8041 |
if (self->create) |
| 8042 |
shm_unlink(self->name); |
| 8043 |
|
| 8044 |
#endif |
| 8045 |
SharedTable_clear(self); |
| 8046 |
Py_TYPE(self->tablestream)->tp_free((PyObject*)self->tablestream); |
| 8047 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 8048 |
} |
| 8049 |
|
| 8050 |
static PyObject * |
| 8051 |
SharedTable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 8052 |
{ |
| 8053 |
SharedTable *self; |
| 8054 |
self = (SharedTable *)type->tp_alloc(type, 0); |
| 8055 |
|
| 8056 |
self->server = PyServer_get_server(); |
| 8057 |
Py_INCREF(self->server); |
| 8058 |
|
| 8059 |
MAKE_NEW_TABLESTREAM(self->tablestream, &TableStreamType, NULL); |
| 8060 |
|
| 8061 |
static char *kwlist[] = {"name", "create", "size", NULL}; |
| 8062 |
|
| 8063 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "sin", kwlist, &self->name, &self->create, &self->size)) |
| 8064 |
Py_RETURN_NONE; |
| 8065 |
|
| 8066 |
#if !defined(_WIN32) && !defined(_WIN64) |
| 8067 |
T_SIZE_T i; |
| 8068 |
|
| 8069 |
/* Open shared memory object. */ |
| 8070 |
if (self->create) |
| 8071 |
{ |
| 8072 |
self->fd = shm_open(self->name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); |
| 8073 |
|
| 8074 |
if (self->fd == -1) |
| 8075 |
{ |
| 8076 |
PySys_WriteStdout("SharedTable: failed to create shared memory.\n"); |
| 8077 |
Py_RETURN_NONE; |
| 8078 |
} |
| 8079 |
|
| 8080 |
if (ftruncate(self->fd, sizeof(MYFLT) * (self->size + 1)) == -1) |
| 8081 |
{ |
| 8082 |
PySys_WriteStdout("SharedTable: failed to truncate shared memory.\n"); |
| 8083 |
close(self->fd); |
| 8084 |
shm_unlink(self->name); |
| 8085 |
Py_RETURN_NONE; |
| 8086 |
} |
| 8087 |
} |
| 8088 |
else |
| 8089 |
{ |
| 8090 |
self->fd = shm_open(self->name, O_RDWR, 0); |
| 8091 |
|
| 8092 |
if (self->fd == -1) |
| 8093 |
{ |
| 8094 |
PySys_WriteStdout("SharedTable: failed to create shared memory.\n"); |
| 8095 |
Py_RETURN_NONE; |
| 8096 |
} |
| 8097 |
} |
| 8098 |
|
| 8099 |
/* Map shared memory object. */ |
| 8100 |
self->data = mmap(NULL, sizeof(MYFLT) * (self->size + 1), |
| 8101 |
PROT_READ | PROT_WRITE, MAP_SHARED, self->fd, 0); |
| 8102 |
|
| 8103 |
if (self->data == MAP_FAILED) |
| 8104 |
{ |
| 8105 |
PySys_WriteStdout("SharedTable: failed to mmap shared memory.\n"); |
| 8106 |
close(self->fd); |
| 8107 |
|
| 8108 |
if (self->create) |
| 8109 |
shm_unlink(self->name); |
| 8110 |
|
| 8111 |
Py_RETURN_NONE; |
| 8112 |
} |
| 8113 |
|
| 8114 |
/* Initialize the memory. */ |
| 8115 |
if (self->create) |
| 8116 |
{ |
| 8117 |
for (i = 0; i <= self->size; i++) |
| 8118 |
{ |
| 8119 |
self->data[i] = 0.0; |
| 8120 |
} |
| 8121 |
} |
| 8122 |
|
| 8123 |
#endif |
| 8124 |
|
| 8125 |
TableStream_setSize(self->tablestream, self->size); |
| 8126 |
TableStream_setData(self->tablestream, self->data); |
| 8127 |
|
| 8128 |
PyObject *srobj = PyObject_CallMethod(self->server, "getSamplingRate", NULL); |
| 8129 |
self->sr = PyFloat_AsDouble(srobj); |
| 8130 |
Py_DECREF(srobj); |
| 8131 |
|
| 8132 |
TableStream_setSamplingRate(self->tablestream, self->sr); |
| 8133 |
|
| 8134 |
return (PyObject *)self; |
| 8135 |
} |
| 8136 |
|
| 8137 |
static PyObject * SharedTable_getServer(SharedTable* self) { GET_SERVER }; |
| 8138 |
static PyObject * SharedTable_getTableStream(SharedTable* self) { GET_TABLE_STREAM }; |
| 8139 |
static PyObject * SharedTable_setData(SharedTable *self, PyObject *arg) { SET_TABLE_DATA }; |
| 8140 |
static PyObject * SharedTable_normalize(SharedTable *self, PyObject *args, PyObject *kwds) { NORMALIZE }; |
| 8141 |
static PyObject * SharedTable_reset(SharedTable *self) { TABLE_RESET }; |
| 8142 |
static PyObject * SharedTable_removeDC(SharedTable *self) { REMOVE_DC }; |
| 8143 |
static PyObject * SharedTable_reverse(SharedTable *self) { REVERSE }; |
| 8144 |
static PyObject * SharedTable_invert(SharedTable *self) { INVERT }; |
| 8145 |
static PyObject * SharedTable_rectify(SharedTable *self) { RECTIFY }; |
| 8146 |
static PyObject * SharedTable_bipolarGain(SharedTable *self, PyObject *args, PyObject *kwds) { TABLE_BIPOLAR_GAIN }; |
| 8147 |
static PyObject * SharedTable_lowpass(SharedTable *self, PyObject *args, PyObject *kwds) { TABLE_LOWPASS }; |
| 8148 |
static PyObject * SharedTable_fadein(SharedTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEIN }; |
| 8149 |
static PyObject * SharedTable_fadeout(SharedTable *self, PyObject *args, PyObject *kwds) { TABLE_FADEOUT }; |
| 8150 |
static PyObject * SharedTable_pow(SharedTable *self, PyObject *args, PyObject *kwds) { TABLE_POWER }; |
| 8151 |
static PyObject * SharedTable_copy(SharedTable *self, PyObject *arg) { COPY }; |
| 8152 |
static PyObject * SharedTable_copyData(SharedTable *self, PyObject *args, PyObject *kwds) { TABLE_COPYDATA }; |
| 8153 |
static PyObject * SharedTable_rotate(SharedTable *self, PyObject *args, PyObject *kwds) { TABLE_ROTATE }; |
| 8154 |
static PyObject * SharedTable_setTable(SharedTable *self, PyObject *arg) { SET_TABLE }; |
| 8155 |
static PyObject * SharedTable_getTable(SharedTable *self) { GET_TABLE }; |
| 8156 |
static PyObject * SharedTable_getRate(SharedTable *self) { TABLE_GET_RATE }; |
| 8157 |
static PyObject * SharedTable_getViewTable(SharedTable *self, PyObject *args, PyObject *kwds) { GET_VIEW_TABLE }; |
| 8158 |
static PyObject * SharedTable_put(SharedTable *self, PyObject *args, PyObject *kwds) { TABLE_PUT }; |
| 8159 |
static PyObject * SharedTable_get(SharedTable *self, PyObject *args, PyObject *kwds) { TABLE_GET }; |
| 8160 |
static PyObject * SharedTable_add(SharedTable *self, PyObject *arg) { TABLE_ADD }; |
| 8161 |
static PyObject * SharedTable_sub(SharedTable *self, PyObject *arg) { TABLE_SUB }; |
| 8162 |
static PyObject * SharedTable_mul(SharedTable *self, PyObject *arg) { TABLE_MUL }; |
| 8163 |
static PyObject * SharedTable_div(SharedTable *self, PyObject *arg) { TABLE_DIV }; |
| 8164 |
|
| 8165 |
static PyObject * |
| 8166 |
SharedTable_getSize(SharedTable *self) |
| 8167 |
{ |
| 8168 |
return PyLong_FromLong(self->size); |
| 8169 |
}; |
| 8170 |
|
| 8171 |
static PyMemberDef SharedTable_members[] = |
| 8172 |
{ |
| 8173 |
{"server", T_OBJECT_EX, offsetof(SharedTable, server), 0, "Pyo server."}, |
| 8174 |
{"tablestream", T_OBJECT_EX, offsetof(SharedTable, tablestream), 0, "Table stream object."}, |
| 8175 |
{NULL} /* Sentinel */ |
| 8176 |
}; |
| 8177 |
|
| 8178 |
static PyMethodDef SharedTable_methods[] = |
| 8179 |
{ |
| 8180 |
{"getServer", (PyCFunction)SharedTable_getServer, METH_NOARGS, "Returns server object."}, |
| 8181 |
{"copy", (PyCFunction)SharedTable_copy, METH_O, "Copy data from table given in argument."}, |
| 8182 |
{"copyData", (PyCFunction)SharedTable_copyData, METH_VARARGS | METH_KEYWORDS, "Copy data from table given in argument."}, |
| 8183 |
{"rotate", (PyCFunction)SharedTable_rotate, METH_VARARGS | METH_KEYWORDS, "Rotate table around position as argument."}, |
| 8184 |
{"setTable", (PyCFunction)SharedTable_setTable, METH_O, "Sets the table content from a list of floats (must be the same size as the object size)."}, |
| 8185 |
{"getTable", (PyCFunction)SharedTable_getTable, METH_NOARGS, "Returns a list of table samples."}, |
| 8186 |
{"getViewTable", (PyCFunction)SharedTable_getViewTable, METH_VARARGS | METH_KEYWORDS, "Returns a list of pixel coordinates for drawing the table."}, |
| 8187 |
{"getTableStream", (PyCFunction)SharedTable_getTableStream, METH_NOARGS, "Returns table stream object created by this table."}, |
| 8188 |
{"setData", (PyCFunction)SharedTable_setData, METH_O, "Sets the table from samples in a text file."}, |
| 8189 |
{"normalize", (PyCFunction)SharedTable_normalize, METH_VARARGS | METH_KEYWORDS, "Normalize table samples"}, |
| 8190 |
{"reset", (PyCFunction)SharedTable_reset, METH_NOARGS, "Resets table samples to 0.0"}, |
| 8191 |
{"removeDC", (PyCFunction)SharedTable_removeDC, METH_NOARGS, "Filter out DC offset from the table's data."}, |
| 8192 |
{"reverse", (PyCFunction)SharedTable_reverse, METH_NOARGS, "Reverse the table's data."}, |
| 8193 |
{"invert", (PyCFunction)SharedTable_invert, METH_NOARGS, "Reverse the table's data in amplitude."}, |
| 8194 |
{"rectify", (PyCFunction)SharedTable_rectify, METH_NOARGS, "Positive rectification of the table's data."}, |
| 8195 |
{"bipolarGain", (PyCFunction)SharedTable_bipolarGain, METH_VARARGS | METH_KEYWORDS, "Apply different amp values to positive and negative samples."}, |
| 8196 |
{"lowpass", (PyCFunction)SharedTable_lowpass, METH_VARARGS | METH_KEYWORDS, "Apply a one-pole lowpass filter on table's samples."}, |
| 8197 |
{"fadein", (PyCFunction)SharedTable_fadein, METH_VARARGS | METH_KEYWORDS, "Apply a gradual increase in the level of the table's samples."}, |
| 8198 |
{"fadeout", (PyCFunction)SharedTable_fadeout, METH_VARARGS | METH_KEYWORDS, "Apply a gradual decrease in the level of the table's samples."}, |
| 8199 |
{"pow", (PyCFunction)SharedTable_pow, METH_VARARGS | METH_KEYWORDS, "Apply a power function on each sample in the table."}, |
| 8200 |
{"put", (PyCFunction)SharedTable_put, METH_VARARGS | METH_KEYWORDS, "Puts a value at specified position in the table."}, |
| 8201 |
{"get", (PyCFunction)SharedTable_get, METH_VARARGS | METH_KEYWORDS, "Gets the value at specified position in the table."}, |
| 8202 |
{"getSize", (PyCFunction)SharedTable_getSize, METH_NOARGS, "Return the size of the table in samples."}, |
| 8203 |
{"getRate", (PyCFunction)SharedTable_getRate, METH_NOARGS, "Return the frequency (in cps) that reads the sound without pitch transposition."}, |
| 8204 |
{"add", (PyCFunction)SharedTable_add, METH_O, "Performs table addition."}, |
| 8205 |
{"sub", (PyCFunction)SharedTable_sub, METH_O, "Performs table substraction."}, |
| 8206 |
{"mul", (PyCFunction)SharedTable_mul, METH_O, "Performs table multiplication."}, |
| 8207 |
{"div", (PyCFunction)SharedTable_div, METH_O, "Performs table division."}, |
| 8208 |
{NULL} /* Sentinel */ |
| 8209 |
}; |
| 8210 |
|
| 8211 |
PyTypeObject SharedTableType = |
| 8212 |
{ |
| 8213 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 8214 |
"_pyo.SharedTable_base", /*tp_name*/ |
| 8215 |
sizeof(SharedTable), /*tp_basicsize*/ |
| 8216 |
0, /*tp_itemsize*/ |
| 8217 |
(destructor)SharedTable_dealloc, /*tp_dealloc*/ |
| 8218 |
0, /*tp_print*/ |
| 8219 |
0, /*tp_getattr*/ |
| 8220 |
0, /*tp_setattr*/ |
| 8221 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 8222 |
0, /*tp_repr*/ |
| 8223 |
0, /*tp_as_number*/ |
| 8224 |
0, /*tp_as_sequence*/ |
| 8225 |
0, /*tp_as_mapping*/ |
| 8226 |
0, /*tp_hash */ |
| 8227 |
0, /*tp_call*/ |
| 8228 |
0, /*tp_str*/ |
| 8229 |
0, /*tp_getattro*/ |
| 8230 |
0, /*tp_setattro*/ |
| 8231 |
0, /*tp_as_buffer*/ |
| 8232 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 8233 |
"SharedTable objects. Generates an empty table.", /* tp_doc */ |
| 8234 |
(traverseproc)SharedTable_traverse, /* tp_traverse */ |
| 8235 |
(inquiry)SharedTable_clear, /* tp_clear */ |
| 8236 |
0, /* tp_richcompare */ |
| 8237 |
0, /* tp_weaklistoffset */ |
| 8238 |
0, /* tp_iter */ |
| 8239 |
0, /* tp_iternext */ |
| 8240 |
SharedTable_methods, /* tp_methods */ |
| 8241 |
SharedTable_members, /* tp_members */ |
| 8242 |
0, /* tp_getset */ |
| 8243 |
0, /* tp_base */ |
| 8244 |
0, /* tp_dict */ |
| 8245 |
0, /* tp_descr_get */ |
| 8246 |
0, /* tp_descr_set */ |
| 8247 |
0, /* tp_dictoffset */ |
| 8248 |
0, /* tp_init */ |
| 8249 |
0, /* tp_alloc */ |
| 8250 |
SharedTable_new, /* tp_new */ |
| 8251 |
}; |