| 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 |
#include <Python.h> |
| 22 |
#include "structmember.h" |
| 23 |
#include <math.h> |
| 24 |
#include "pyomodule.h" |
| 25 |
#include "streammodule.h" |
| 26 |
#include "servermodule.h" |
| 27 |
#include "dummymodule.h" |
| 28 |
|
| 29 |
typedef struct |
| 30 |
{ |
| 31 |
pyo_audio_HEAD |
| 32 |
PyObject *input; |
| 33 |
Stream *input_stream; |
| 34 |
PyObject *delay; |
| 35 |
Stream *delay_stream; |
| 36 |
PyObject *feedback; |
| 37 |
Stream *feedback_stream; |
| 38 |
MYFLT maxdelay; |
| 39 |
MYFLT oneOverSr; |
| 40 |
long size; |
| 41 |
long in_count; |
| 42 |
int modebuffer[4]; |
| 43 |
MYFLT *buffer; // samples memory |
| 44 |
} Delay; |
| 45 |
|
| 46 |
static void |
| 47 |
Delay_process_ii(Delay *self) |
| 48 |
{ |
| 49 |
MYFLT val, xind, frac; |
| 50 |
int i; |
| 51 |
long ind; |
| 52 |
|
| 53 |
MYFLT del = PyFloat_AS_DOUBLE(self->delay); |
| 54 |
MYFLT feed = PyFloat_AS_DOUBLE(self->feedback); |
| 55 |
|
| 56 |
if (del < self->oneOverSr) |
| 57 |
del = self->oneOverSr; |
| 58 |
else if (del > self->maxdelay) |
| 59 |
del = self->maxdelay; |
| 60 |
|
| 61 |
MYFLT sampdel = del * self->sr; |
| 62 |
|
| 63 |
if (feed < 0) |
| 64 |
feed = 0; |
| 65 |
else if (feed > 1) |
| 66 |
feed = 1; |
| 67 |
|
| 68 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 69 |
|
| 70 |
for (i = 0; i < self->bufsize; i++) |
| 71 |
{ |
| 72 |
xind = self->in_count - sampdel; |
| 73 |
|
| 74 |
if (xind < 0) |
| 75 |
xind += self->size; |
| 76 |
|
| 77 |
ind = (long)xind; |
| 78 |
frac = xind - ind; |
| 79 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 80 |
self->data[i] = val; |
| 81 |
|
| 82 |
self->buffer[self->in_count] = in[i] + (val * feed); |
| 83 |
|
| 84 |
if (self->in_count == 0) |
| 85 |
self->buffer[self->size] = self->buffer[self->in_count]; |
| 86 |
|
| 87 |
self->in_count++; |
| 88 |
|
| 89 |
if (self->in_count >= self->size) |
| 90 |
self->in_count = 0; |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
static void |
| 95 |
Delay_process_ai(Delay *self) |
| 96 |
{ |
| 97 |
MYFLT val, xind, frac, sampdel, del; |
| 98 |
int i; |
| 99 |
long ind; |
| 100 |
|
| 101 |
MYFLT *delobj = Stream_getData((Stream *)self->delay_stream); |
| 102 |
MYFLT feed = PyFloat_AS_DOUBLE(self->feedback); |
| 103 |
|
| 104 |
if (feed < 0) |
| 105 |
feed = 0; |
| 106 |
else if (feed > 1) |
| 107 |
feed = 1; |
| 108 |
|
| 109 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 110 |
|
| 111 |
for (i = 0; i < self->bufsize; i++) |
| 112 |
{ |
| 113 |
del = delobj[i]; |
| 114 |
|
| 115 |
if (del < self->oneOverSr) |
| 116 |
del = self->oneOverSr; |
| 117 |
else if (del > self->maxdelay) |
| 118 |
del = self->maxdelay; |
| 119 |
|
| 120 |
sampdel = del * self->sr; |
| 121 |
xind = self->in_count - sampdel; |
| 122 |
|
| 123 |
if (xind < 0) |
| 124 |
xind += self->size; |
| 125 |
|
| 126 |
ind = (long)xind; |
| 127 |
frac = xind - ind; |
| 128 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 129 |
self->data[i] = val; |
| 130 |
|
| 131 |
self->buffer[self->in_count] = in[i] + (val * feed); |
| 132 |
|
| 133 |
if (self->in_count == 0) |
| 134 |
self->buffer[self->size] = self->buffer[self->in_count]; |
| 135 |
|
| 136 |
self->in_count++; |
| 137 |
|
| 138 |
if (self->in_count >= self->size) |
| 139 |
self->in_count = 0; |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
static void |
| 144 |
Delay_process_ia(Delay *self) |
| 145 |
{ |
| 146 |
MYFLT val, xind, frac, feed; |
| 147 |
int i; |
| 148 |
long ind; |
| 149 |
|
| 150 |
MYFLT del = PyFloat_AS_DOUBLE(self->delay); |
| 151 |
MYFLT *fdb = Stream_getData((Stream *)self->feedback_stream); |
| 152 |
|
| 153 |
if (del < self->oneOverSr) |
| 154 |
del = self->oneOverSr; |
| 155 |
else if (del > self->maxdelay) |
| 156 |
del = self->maxdelay; |
| 157 |
|
| 158 |
MYFLT sampdel = del * self->sr; |
| 159 |
|
| 160 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 161 |
|
| 162 |
for (i = 0; i < self->bufsize; i++) |
| 163 |
{ |
| 164 |
xind = self->in_count - sampdel; |
| 165 |
|
| 166 |
if (xind < 0) |
| 167 |
xind += self->size; |
| 168 |
|
| 169 |
ind = (long)xind; |
| 170 |
frac = xind - ind; |
| 171 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 172 |
self->data[i] = val; |
| 173 |
|
| 174 |
feed = fdb[i]; |
| 175 |
|
| 176 |
if (feed < 0) |
| 177 |
feed = 0; |
| 178 |
else if (feed > 1) |
| 179 |
feed = 1; |
| 180 |
|
| 181 |
self->buffer[self->in_count] = in[i] + (val * feed); |
| 182 |
|
| 183 |
if (self->in_count == 0) |
| 184 |
self->buffer[self->size] = self->buffer[self->in_count]; |
| 185 |
|
| 186 |
self->in_count++; |
| 187 |
|
| 188 |
if (self->in_count == self->size) |
| 189 |
self->in_count = 0; |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
static void |
| 194 |
Delay_process_aa(Delay *self) |
| 195 |
{ |
| 196 |
MYFLT val, xind, frac, sampdel, feed, del; |
| 197 |
int i; |
| 198 |
long ind; |
| 199 |
|
| 200 |
MYFLT *delobj = Stream_getData((Stream *)self->delay_stream); |
| 201 |
MYFLT *fdb = Stream_getData((Stream *)self->feedback_stream); |
| 202 |
|
| 203 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 204 |
|
| 205 |
for (i = 0; i < self->bufsize; i++) |
| 206 |
{ |
| 207 |
del = delobj[i]; |
| 208 |
|
| 209 |
if (del < self->oneOverSr) |
| 210 |
del = self->oneOverSr; |
| 211 |
else if (del > self->maxdelay) |
| 212 |
del = self->maxdelay; |
| 213 |
|
| 214 |
sampdel = del * self->sr; |
| 215 |
xind = self->in_count - sampdel; |
| 216 |
|
| 217 |
if (xind < 0) |
| 218 |
xind += self->size; |
| 219 |
|
| 220 |
ind = (long)xind; |
| 221 |
frac = xind - ind; |
| 222 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 223 |
self->data[i] = val; |
| 224 |
|
| 225 |
feed = fdb[i]; |
| 226 |
|
| 227 |
if (feed < 0) |
| 228 |
feed = 0; |
| 229 |
else if (feed > 1) |
| 230 |
feed = 1; |
| 231 |
|
| 232 |
self->buffer[self->in_count] = in[i] + (val * feed); |
| 233 |
|
| 234 |
if (self->in_count == 0) |
| 235 |
self->buffer[self->size] = self->buffer[self->in_count]; |
| 236 |
|
| 237 |
self->in_count++; |
| 238 |
|
| 239 |
if (self->in_count == self->size) |
| 240 |
self->in_count = 0; |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
static void Delay_postprocessing_ii(Delay *self) { POST_PROCESSING_II }; |
| 245 |
static void Delay_postprocessing_ai(Delay *self) { POST_PROCESSING_AI }; |
| 246 |
static void Delay_postprocessing_ia(Delay *self) { POST_PROCESSING_IA }; |
| 247 |
static void Delay_postprocessing_aa(Delay *self) { POST_PROCESSING_AA }; |
| 248 |
static void Delay_postprocessing_ireva(Delay *self) { POST_PROCESSING_IREVA }; |
| 249 |
static void Delay_postprocessing_areva(Delay *self) { POST_PROCESSING_AREVA }; |
| 250 |
static void Delay_postprocessing_revai(Delay *self) { POST_PROCESSING_REVAI }; |
| 251 |
static void Delay_postprocessing_revaa(Delay *self) { POST_PROCESSING_REVAA }; |
| 252 |
static void Delay_postprocessing_revareva(Delay *self) { POST_PROCESSING_REVAREVA }; |
| 253 |
|
| 254 |
static void |
| 255 |
Delay_setProcMode(Delay *self) |
| 256 |
{ |
| 257 |
int procmode, muladdmode; |
| 258 |
procmode = self->modebuffer[2] + self->modebuffer[3] * 10; |
| 259 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 260 |
|
| 261 |
switch (procmode) |
| 262 |
{ |
| 263 |
case 0: |
| 264 |
self->proc_func_ptr = Delay_process_ii; |
| 265 |
break; |
| 266 |
|
| 267 |
case 1: |
| 268 |
self->proc_func_ptr = Delay_process_ai; |
| 269 |
break; |
| 270 |
|
| 271 |
case 10: |
| 272 |
self->proc_func_ptr = Delay_process_ia; |
| 273 |
break; |
| 274 |
|
| 275 |
case 11: |
| 276 |
self->proc_func_ptr = Delay_process_aa; |
| 277 |
break; |
| 278 |
} |
| 279 |
|
| 280 |
switch (muladdmode) |
| 281 |
{ |
| 282 |
case 0: |
| 283 |
self->muladd_func_ptr = Delay_postprocessing_ii; |
| 284 |
break; |
| 285 |
|
| 286 |
case 1: |
| 287 |
self->muladd_func_ptr = Delay_postprocessing_ai; |
| 288 |
break; |
| 289 |
|
| 290 |
case 2: |
| 291 |
self->muladd_func_ptr = Delay_postprocessing_revai; |
| 292 |
break; |
| 293 |
|
| 294 |
case 10: |
| 295 |
self->muladd_func_ptr = Delay_postprocessing_ia; |
| 296 |
break; |
| 297 |
|
| 298 |
case 11: |
| 299 |
self->muladd_func_ptr = Delay_postprocessing_aa; |
| 300 |
break; |
| 301 |
|
| 302 |
case 12: |
| 303 |
self->muladd_func_ptr = Delay_postprocessing_revaa; |
| 304 |
break; |
| 305 |
|
| 306 |
case 20: |
| 307 |
self->muladd_func_ptr = Delay_postprocessing_ireva; |
| 308 |
break; |
| 309 |
|
| 310 |
case 21: |
| 311 |
self->muladd_func_ptr = Delay_postprocessing_areva; |
| 312 |
break; |
| 313 |
|
| 314 |
case 22: |
| 315 |
self->muladd_func_ptr = Delay_postprocessing_revareva; |
| 316 |
break; |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
static void |
| 321 |
Delay_compute_next_data_frame(Delay *self) |
| 322 |
{ |
| 323 |
(*self->proc_func_ptr)(self); |
| 324 |
(*self->muladd_func_ptr)(self); |
| 325 |
} |
| 326 |
|
| 327 |
static int |
| 328 |
Delay_traverse(Delay *self, visitproc visit, void *arg) |
| 329 |
{ |
| 330 |
pyo_VISIT |
| 331 |
Py_VISIT(self->input); |
| 332 |
Py_VISIT(self->delay); |
| 333 |
Py_VISIT(self->feedback); |
| 334 |
return 0; |
| 335 |
} |
| 336 |
|
| 337 |
static int |
| 338 |
Delay_clear(Delay *self) |
| 339 |
{ |
| 340 |
pyo_CLEAR |
| 341 |
Py_CLEAR(self->input); |
| 342 |
Py_CLEAR(self->delay); |
| 343 |
Py_CLEAR(self->feedback); |
| 344 |
return 0; |
| 345 |
} |
| 346 |
|
| 347 |
static void |
| 348 |
Delay_dealloc(Delay* self) |
| 349 |
{ |
| 350 |
pyo_DEALLOC |
| 351 |
PyMem_RawFree(self->buffer); |
| 352 |
Delay_clear(self); |
| 353 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 354 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 355 |
} |
| 356 |
|
| 357 |
static PyObject * |
| 358 |
Delay_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 359 |
{ |
| 360 |
int i; |
| 361 |
PyObject *inputtmp, *input_streamtmp, *delaytmp = NULL, *feedbacktmp = NULL, *multmp = NULL, *addtmp = NULL; |
| 362 |
Delay *self; |
| 363 |
self = (Delay *)type->tp_alloc(type, 0); |
| 364 |
|
| 365 |
self->delay = PyFloat_FromDouble(0.25); |
| 366 |
self->feedback = PyFloat_FromDouble(0); |
| 367 |
self->maxdelay = 1; |
| 368 |
self->in_count = 0; |
| 369 |
self->modebuffer[0] = 0; |
| 370 |
self->modebuffer[1] = 0; |
| 371 |
self->modebuffer[2] = 0; |
| 372 |
self->modebuffer[3] = 0; |
| 373 |
|
| 374 |
INIT_OBJECT_COMMON |
| 375 |
|
| 376 |
self->oneOverSr = 1.0 / self->sr; |
| 377 |
|
| 378 |
Stream_setFunctionPtr(self->stream, Delay_compute_next_data_frame); |
| 379 |
self->mode_func_ptr = Delay_setProcMode; |
| 380 |
|
| 381 |
static char *kwlist[] = {"input", "delay", "feedback", "maxdelay", "mul", "add", NULL}; |
| 382 |
|
| 383 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_O_OOFOO, kwlist, &inputtmp, &delaytmp, &feedbacktmp, &self->maxdelay, &multmp, &addtmp)) |
| 384 |
Py_RETURN_NONE; |
| 385 |
|
| 386 |
INIT_INPUT_STREAM |
| 387 |
|
| 388 |
if (delaytmp) |
| 389 |
{ |
| 390 |
PyObject_CallMethod((PyObject *)self, "setDelay", "O", delaytmp); |
| 391 |
} |
| 392 |
|
| 393 |
if (feedbacktmp) |
| 394 |
{ |
| 395 |
PyObject_CallMethod((PyObject *)self, "setFeedback", "O", feedbacktmp); |
| 396 |
} |
| 397 |
|
| 398 |
if (multmp) |
| 399 |
{ |
| 400 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 401 |
} |
| 402 |
|
| 403 |
if (addtmp) |
| 404 |
{ |
| 405 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 406 |
} |
| 407 |
|
| 408 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 409 |
|
| 410 |
self->size = (long)(self->maxdelay * self->sr + 0.5); |
| 411 |
|
| 412 |
self->buffer = (MYFLT *)PyMem_RawRealloc(self->buffer, (self->size + 1) * sizeof(MYFLT)); |
| 413 |
|
| 414 |
for (i = 0; i < (self->size + 1); i++) |
| 415 |
{ |
| 416 |
self->buffer[i] = 0.; |
| 417 |
} |
| 418 |
|
| 419 |
(*self->mode_func_ptr)(self); |
| 420 |
|
| 421 |
return (PyObject *)self; |
| 422 |
} |
| 423 |
|
| 424 |
static PyObject * Delay_getServer(Delay* self) { GET_SERVER }; |
| 425 |
static PyObject * Delay_getStream(Delay* self) { GET_STREAM }; |
| 426 |
static PyObject * Delay_setMul(Delay *self, PyObject *arg) { SET_MUL }; |
| 427 |
static PyObject * Delay_setAdd(Delay *self, PyObject *arg) { SET_ADD }; |
| 428 |
static PyObject * Delay_setSub(Delay *self, PyObject *arg) { SET_SUB }; |
| 429 |
static PyObject * Delay_setDiv(Delay *self, PyObject *arg) { SET_DIV }; |
| 430 |
|
| 431 |
static PyObject * Delay_play(Delay *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 432 |
static PyObject * Delay_out(Delay *self, PyObject *args, PyObject *kwds) { OUT }; |
| 433 |
static PyObject * Delay_stop(Delay *self, PyObject *args, PyObject *kwds) { STOP }; |
| 434 |
|
| 435 |
static PyObject * Delay_multiply(Delay *self, PyObject *arg) { MULTIPLY }; |
| 436 |
static PyObject * Delay_inplace_multiply(Delay *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 437 |
static PyObject * Delay_add(Delay *self, PyObject *arg) { ADD }; |
| 438 |
static PyObject * Delay_inplace_add(Delay *self, PyObject *arg) { INPLACE_ADD }; |
| 439 |
static PyObject * Delay_sub(Delay *self, PyObject *arg) { SUB }; |
| 440 |
static PyObject * Delay_inplace_sub(Delay *self, PyObject *arg) { INPLACE_SUB }; |
| 441 |
static PyObject * Delay_div(Delay *self, PyObject *arg) { DIV }; |
| 442 |
static PyObject * Delay_inplace_div(Delay *self, PyObject *arg) { INPLACE_DIV }; |
| 443 |
|
| 444 |
static PyObject * Delay_setDelay(Delay *self, PyObject *arg) { SET_PARAM(self->delay, self->delay_stream, 2); } |
| 445 |
static PyObject * Delay_setFeedback(Delay *self, PyObject *arg) { SET_PARAM(self->feedback, self->feedback_stream, 3); } |
| 446 |
|
| 447 |
static PyObject * |
| 448 |
Delay_reset(Delay *self) |
| 449 |
{ |
| 450 |
int i; |
| 451 |
|
| 452 |
for (i = 0; i < (self->size + 1); i++) |
| 453 |
{ |
| 454 |
self->buffer[i] = 0.; |
| 455 |
} |
| 456 |
|
| 457 |
Py_RETURN_NONE; |
| 458 |
} |
| 459 |
|
| 460 |
static PyMemberDef Delay_members[] = |
| 461 |
{ |
| 462 |
{"server", T_OBJECT_EX, offsetof(Delay, server), 0, "Pyo server."}, |
| 463 |
{"stream", T_OBJECT_EX, offsetof(Delay, stream), 0, "Stream object."}, |
| 464 |
{"input", T_OBJECT_EX, offsetof(Delay, input), 0, "Input sound object."}, |
| 465 |
{"delay", T_OBJECT_EX, offsetof(Delay, delay), 0, "Delay time in seconds."}, |
| 466 |
{"feedback", T_OBJECT_EX, offsetof(Delay, feedback), 0, "Feedback value."}, |
| 467 |
{"mul", T_OBJECT_EX, offsetof(Delay, mul), 0, "Mul factor."}, |
| 468 |
{"add", T_OBJECT_EX, offsetof(Delay, add), 0, "Add factor."}, |
| 469 |
{NULL} /* Sentinel */ |
| 470 |
}; |
| 471 |
|
| 472 |
static PyMethodDef Delay_methods[] = |
| 473 |
{ |
| 474 |
{"getServer", (PyCFunction)Delay_getServer, METH_NOARGS, "Returns server object."}, |
| 475 |
{"_getStream", (PyCFunction)Delay_getStream, METH_NOARGS, "Returns stream object."}, |
| 476 |
{"play", (PyCFunction)Delay_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 477 |
{"out", (PyCFunction)Delay_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."}, |
| 478 |
{"stop", (PyCFunction)Delay_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 479 |
{"setDelay", (PyCFunction)Delay_setDelay, METH_O, "Sets delay time in seconds."}, |
| 480 |
{"setFeedback", (PyCFunction)Delay_setFeedback, METH_O, "Sets feedback value between 0 -> 1."}, |
| 481 |
{"reset", (PyCFunction)Delay_reset, METH_NOARGS, "Resets the memory buffer to zeros."}, |
| 482 |
{"setMul", (PyCFunction)Delay_setMul, METH_O, "Sets oscillator mul factor."}, |
| 483 |
{"setAdd", (PyCFunction)Delay_setAdd, METH_O, "Sets oscillator add factor."}, |
| 484 |
{"setSub", (PyCFunction)Delay_setSub, METH_O, "Sets inverse add factor."}, |
| 485 |
{"setDiv", (PyCFunction)Delay_setDiv, METH_O, "Sets inverse mul factor."}, |
| 486 |
{NULL} /* Sentinel */ |
| 487 |
}; |
| 488 |
|
| 489 |
static PyNumberMethods Delay_as_number = |
| 490 |
{ |
| 491 |
(binaryfunc)Delay_add, /*nb_add*/ |
| 492 |
(binaryfunc)Delay_sub, /*nb_subtract*/ |
| 493 |
(binaryfunc)Delay_multiply, /*nb_multiply*/ |
| 494 |
0, /*nb_remainder*/ |
| 495 |
0, /*nb_divmod*/ |
| 496 |
0, /*nb_power*/ |
| 497 |
0, /*nb_neg*/ |
| 498 |
0, /*nb_pos*/ |
| 499 |
0, /*(unaryfunc)array_abs,*/ |
| 500 |
0, /*nb_nonzero*/ |
| 501 |
0, /*nb_invert*/ |
| 502 |
0, /*nb_lshift*/ |
| 503 |
0, /*nb_rshift*/ |
| 504 |
0, /*nb_and*/ |
| 505 |
0, /*nb_xor*/ |
| 506 |
0, /*nb_or*/ |
| 507 |
0, /*nb_int*/ |
| 508 |
0, /*nb_long*/ |
| 509 |
0, /*nb_float*/ |
| 510 |
(binaryfunc)Delay_inplace_add, /*inplace_add*/ |
| 511 |
(binaryfunc)Delay_inplace_sub, /*inplace_subtract*/ |
| 512 |
(binaryfunc)Delay_inplace_multiply, /*inplace_multiply*/ |
| 513 |
0, /*inplace_remainder*/ |
| 514 |
0, /*inplace_power*/ |
| 515 |
0, /*inplace_lshift*/ |
| 516 |
0, /*inplace_rshift*/ |
| 517 |
0, /*inplace_and*/ |
| 518 |
0, /*inplace_xor*/ |
| 519 |
0, /*inplace_or*/ |
| 520 |
0, /*nb_floor_divide*/ |
| 521 |
(binaryfunc)Delay_div, /*nb_true_divide*/ |
| 522 |
0, /*nb_inplace_floor_divide*/ |
| 523 |
(binaryfunc)Delay_inplace_div, /*nb_inplace_true_divide*/ |
| 524 |
0, /* nb_index */ |
| 525 |
}; |
| 526 |
|
| 527 |
PyTypeObject DelayType = |
| 528 |
{ |
| 529 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 530 |
"_pyo.Delay_base", /*tp_name*/ |
| 531 |
sizeof(Delay), /*tp_basicsize*/ |
| 532 |
0, /*tp_itemsize*/ |
| 533 |
(destructor)Delay_dealloc, /*tp_dealloc*/ |
| 534 |
0, /*tp_print*/ |
| 535 |
0, /*tp_getattr*/ |
| 536 |
0, /*tp_setattr*/ |
| 537 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 538 |
0, /*tp_repr*/ |
| 539 |
&Delay_as_number, /*tp_as_number*/ |
| 540 |
0, /*tp_as_sequence*/ |
| 541 |
0, /*tp_as_mapping*/ |
| 542 |
0, /*tp_hash */ |
| 543 |
0, /*tp_call*/ |
| 544 |
0, /*tp_str*/ |
| 545 |
0, /*tp_getattro*/ |
| 546 |
0, /*tp_setattro*/ |
| 547 |
0, /*tp_as_buffer*/ |
| 548 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 549 |
"Delay objects. Delay signal by x samples.", /* tp_doc */ |
| 550 |
(traverseproc)Delay_traverse, /* tp_traverse */ |
| 551 |
(inquiry)Delay_clear, /* tp_clear */ |
| 552 |
0, /* tp_richcompare */ |
| 553 |
0, /* tp_weaklistoffset */ |
| 554 |
0, /* tp_iter */ |
| 555 |
0, /* tp_iternext */ |
| 556 |
Delay_methods, /* tp_methods */ |
| 557 |
Delay_members, /* tp_members */ |
| 558 |
0, /* tp_getset */ |
| 559 |
0, /* tp_base */ |
| 560 |
0, /* tp_dict */ |
| 561 |
0, /* tp_descr_get */ |
| 562 |
0, /* tp_descr_set */ |
| 563 |
0, /* tp_dictoffset */ |
| 564 |
0, /* tp_init */ |
| 565 |
0, /* tp_alloc */ |
| 566 |
Delay_new, /* tp_new */ |
| 567 |
}; |
| 568 |
|
| 569 |
typedef struct |
| 570 |
{ |
| 571 |
pyo_audio_HEAD |
| 572 |
PyObject *input; |
| 573 |
Stream *input_stream; |
| 574 |
PyObject *delay; |
| 575 |
Stream *delay_stream; |
| 576 |
MYFLT maxdelay; |
| 577 |
long size; |
| 578 |
long in_count; |
| 579 |
int modebuffer[3]; |
| 580 |
MYFLT *buffer; // samples memory |
| 581 |
} SDelay; |
| 582 |
|
| 583 |
static void |
| 584 |
SDelay_process_i(SDelay *self) |
| 585 |
{ |
| 586 |
int i; |
| 587 |
long ind; |
| 588 |
|
| 589 |
MYFLT del = PyFloat_AS_DOUBLE(self->delay); |
| 590 |
|
| 591 |
if (del < 0.) |
| 592 |
del = 0.; |
| 593 |
else if (del > self->maxdelay) |
| 594 |
del = self->maxdelay; |
| 595 |
|
| 596 |
long sampdel = (long)(del * self->sr); |
| 597 |
|
| 598 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 599 |
|
| 600 |
if (sampdel == 0) |
| 601 |
{ |
| 602 |
for (i = 0; i < self->bufsize; i++) |
| 603 |
{ |
| 604 |
self->data[i] = self->buffer[self->in_count] = in[i]; |
| 605 |
self->in_count++; |
| 606 |
|
| 607 |
if (self->in_count >= self->size) |
| 608 |
self->in_count = 0; |
| 609 |
} |
| 610 |
} |
| 611 |
else |
| 612 |
{ |
| 613 |
for (i = 0; i < self->bufsize; i++) |
| 614 |
{ |
| 615 |
ind = self->in_count - sampdel; |
| 616 |
|
| 617 |
if (ind < 0) |
| 618 |
ind += self->size; |
| 619 |
|
| 620 |
self->data[i] = self->buffer[ind]; |
| 621 |
|
| 622 |
self->buffer[self->in_count] = in[i]; |
| 623 |
self->in_count++; |
| 624 |
|
| 625 |
if (self->in_count >= self->size) |
| 626 |
self->in_count = 0; |
| 627 |
} |
| 628 |
} |
| 629 |
} |
| 630 |
|
| 631 |
static void |
| 632 |
SDelay_process_a(SDelay *self) |
| 633 |
{ |
| 634 |
MYFLT del; |
| 635 |
int i; |
| 636 |
long ind, sampdel; |
| 637 |
|
| 638 |
MYFLT *delobj = Stream_getData((Stream *)self->delay_stream); |
| 639 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 640 |
|
| 641 |
for (i = 0; i < self->bufsize; i++) |
| 642 |
{ |
| 643 |
del = delobj[i]; |
| 644 |
|
| 645 |
if (del < 0.) |
| 646 |
del = 0.; |
| 647 |
else if (del > self->maxdelay) |
| 648 |
del = self->maxdelay; |
| 649 |
|
| 650 |
sampdel = (long)(del * self->sr); |
| 651 |
|
| 652 |
if (sampdel == 0) |
| 653 |
{ |
| 654 |
self->data[i] = self->buffer[self->in_count] = in[i]; |
| 655 |
} |
| 656 |
else |
| 657 |
{ |
| 658 |
ind = self->in_count - sampdel; |
| 659 |
|
| 660 |
if (ind < 0) |
| 661 |
ind += self->size; |
| 662 |
|
| 663 |
self->data[i] = self->buffer[ind]; |
| 664 |
} |
| 665 |
|
| 666 |
self->buffer[self->in_count++] = in[i]; |
| 667 |
|
| 668 |
if (self->in_count >= self->size) |
| 669 |
self->in_count = 0; |
| 670 |
} |
| 671 |
} |
| 672 |
|
| 673 |
static void SDelay_postprocessing_ii(SDelay *self) { POST_PROCESSING_II }; |
| 674 |
static void SDelay_postprocessing_ai(SDelay *self) { POST_PROCESSING_AI }; |
| 675 |
static void SDelay_postprocessing_ia(SDelay *self) { POST_PROCESSING_IA }; |
| 676 |
static void SDelay_postprocessing_aa(SDelay *self) { POST_PROCESSING_AA }; |
| 677 |
static void SDelay_postprocessing_ireva(SDelay *self) { POST_PROCESSING_IREVA }; |
| 678 |
static void SDelay_postprocessing_areva(SDelay *self) { POST_PROCESSING_AREVA }; |
| 679 |
static void SDelay_postprocessing_revai(SDelay *self) { POST_PROCESSING_REVAI }; |
| 680 |
static void SDelay_postprocessing_revaa(SDelay *self) { POST_PROCESSING_REVAA }; |
| 681 |
static void SDelay_postprocessing_revareva(SDelay *self) { POST_PROCESSING_REVAREVA }; |
| 682 |
|
| 683 |
static void |
| 684 |
SDelay_setProcMode(SDelay *self) |
| 685 |
{ |
| 686 |
int procmode, muladdmode; |
| 687 |
procmode = self->modebuffer[2]; |
| 688 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 689 |
|
| 690 |
switch (procmode) |
| 691 |
{ |
| 692 |
case 0: |
| 693 |
self->proc_func_ptr = SDelay_process_i; |
| 694 |
break; |
| 695 |
|
| 696 |
case 1: |
| 697 |
self->proc_func_ptr = SDelay_process_a; |
| 698 |
break; |
| 699 |
} |
| 700 |
|
| 701 |
switch (muladdmode) |
| 702 |
{ |
| 703 |
case 0: |
| 704 |
self->muladd_func_ptr = SDelay_postprocessing_ii; |
| 705 |
break; |
| 706 |
|
| 707 |
case 1: |
| 708 |
self->muladd_func_ptr = SDelay_postprocessing_ai; |
| 709 |
break; |
| 710 |
|
| 711 |
case 2: |
| 712 |
self->muladd_func_ptr = SDelay_postprocessing_revai; |
| 713 |
break; |
| 714 |
|
| 715 |
case 10: |
| 716 |
self->muladd_func_ptr = SDelay_postprocessing_ia; |
| 717 |
break; |
| 718 |
|
| 719 |
case 11: |
| 720 |
self->muladd_func_ptr = SDelay_postprocessing_aa; |
| 721 |
break; |
| 722 |
|
| 723 |
case 12: |
| 724 |
self->muladd_func_ptr = SDelay_postprocessing_revaa; |
| 725 |
break; |
| 726 |
|
| 727 |
case 20: |
| 728 |
self->muladd_func_ptr = SDelay_postprocessing_ireva; |
| 729 |
break; |
| 730 |
|
| 731 |
case 21: |
| 732 |
self->muladd_func_ptr = SDelay_postprocessing_areva; |
| 733 |
break; |
| 734 |
|
| 735 |
case 22: |
| 736 |
self->muladd_func_ptr = SDelay_postprocessing_revareva; |
| 737 |
break; |
| 738 |
} |
| 739 |
} |
| 740 |
|
| 741 |
static void |
| 742 |
SDelay_compute_next_data_frame(SDelay *self) |
| 743 |
{ |
| 744 |
(*self->proc_func_ptr)(self); |
| 745 |
(*self->muladd_func_ptr)(self); |
| 746 |
} |
| 747 |
|
| 748 |
static int |
| 749 |
SDelay_traverse(SDelay *self, visitproc visit, void *arg) |
| 750 |
{ |
| 751 |
pyo_VISIT |
| 752 |
Py_VISIT(self->input); |
| 753 |
Py_VISIT(self->delay); |
| 754 |
return 0; |
| 755 |
} |
| 756 |
|
| 757 |
static int |
| 758 |
SDelay_clear(SDelay *self) |
| 759 |
{ |
| 760 |
pyo_CLEAR |
| 761 |
Py_CLEAR(self->input); |
| 762 |
Py_CLEAR(self->delay); |
| 763 |
return 0; |
| 764 |
} |
| 765 |
|
| 766 |
static void |
| 767 |
SDelay_dealloc(SDelay* self) |
| 768 |
{ |
| 769 |
pyo_DEALLOC |
| 770 |
PyMem_RawFree(self->buffer); |
| 771 |
SDelay_clear(self); |
| 772 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 773 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 774 |
} |
| 775 |
|
| 776 |
static PyObject * |
| 777 |
SDelay_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 778 |
{ |
| 779 |
int i; |
| 780 |
PyObject *inputtmp, *input_streamtmp, *delaytmp = NULL, *multmp = NULL, *addtmp = NULL; |
| 781 |
SDelay *self; |
| 782 |
self = (SDelay *)type->tp_alloc(type, 0); |
| 783 |
|
| 784 |
self->delay = PyFloat_FromDouble(0.25); |
| 785 |
self->maxdelay = 1; |
| 786 |
self->in_count = 0; |
| 787 |
self->modebuffer[0] = 0; |
| 788 |
self->modebuffer[1] = 0; |
| 789 |
self->modebuffer[2] = 0; |
| 790 |
|
| 791 |
INIT_OBJECT_COMMON |
| 792 |
Stream_setFunctionPtr(self->stream, SDelay_compute_next_data_frame); |
| 793 |
self->mode_func_ptr = SDelay_setProcMode; |
| 794 |
|
| 795 |
static char *kwlist[] = {"input", "delay", "maxdelay", "mul", "add", NULL}; |
| 796 |
|
| 797 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_O_OFOO, kwlist, &inputtmp, &delaytmp, &self->maxdelay, &multmp, &addtmp)) |
| 798 |
Py_RETURN_NONE; |
| 799 |
|
| 800 |
INIT_INPUT_STREAM |
| 801 |
|
| 802 |
if (delaytmp) |
| 803 |
{ |
| 804 |
PyObject_CallMethod((PyObject *)self, "setDelay", "O", delaytmp); |
| 805 |
} |
| 806 |
|
| 807 |
if (multmp) |
| 808 |
{ |
| 809 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 810 |
} |
| 811 |
|
| 812 |
if (addtmp) |
| 813 |
{ |
| 814 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 815 |
} |
| 816 |
|
| 817 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 818 |
|
| 819 |
self->size = (long)(self->maxdelay * self->sr + 0.5); |
| 820 |
|
| 821 |
self->buffer = (MYFLT *)PyMem_RawRealloc(self->buffer, (self->size + 1) * sizeof(MYFLT)); |
| 822 |
|
| 823 |
for (i = 0; i < (self->size + 1); i++) |
| 824 |
{ |
| 825 |
self->buffer[i] = 0.; |
| 826 |
} |
| 827 |
|
| 828 |
(*self->mode_func_ptr)(self); |
| 829 |
|
| 830 |
return (PyObject *)self; |
| 831 |
} |
| 832 |
|
| 833 |
static PyObject * SDelay_getServer(SDelay* self) { GET_SERVER }; |
| 834 |
static PyObject * SDelay_getStream(SDelay* self) { GET_STREAM }; |
| 835 |
static PyObject * SDelay_setMul(SDelay *self, PyObject *arg) { SET_MUL }; |
| 836 |
static PyObject * SDelay_setAdd(SDelay *self, PyObject *arg) { SET_ADD }; |
| 837 |
static PyObject * SDelay_setSub(SDelay *self, PyObject *arg) { SET_SUB }; |
| 838 |
static PyObject * SDelay_setDiv(SDelay *self, PyObject *arg) { SET_DIV }; |
| 839 |
|
| 840 |
static PyObject * SDelay_play(SDelay *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 841 |
static PyObject * SDelay_out(SDelay *self, PyObject *args, PyObject *kwds) { OUT }; |
| 842 |
static PyObject * SDelay_stop(SDelay *self, PyObject *args, PyObject *kwds) { STOP }; |
| 843 |
|
| 844 |
static PyObject * SDelay_multiply(SDelay *self, PyObject *arg) { MULTIPLY }; |
| 845 |
static PyObject * SDelay_inplace_multiply(SDelay *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 846 |
static PyObject * SDelay_add(SDelay *self, PyObject *arg) { ADD }; |
| 847 |
static PyObject * SDelay_inplace_add(SDelay *self, PyObject *arg) { INPLACE_ADD }; |
| 848 |
static PyObject * SDelay_sub(SDelay *self, PyObject *arg) { SUB }; |
| 849 |
static PyObject * SDelay_inplace_sub(SDelay *self, PyObject *arg) { INPLACE_SUB }; |
| 850 |
static PyObject * SDelay_div(SDelay *self, PyObject *arg) { DIV }; |
| 851 |
static PyObject * SDelay_inplace_div(SDelay *self, PyObject *arg) { INPLACE_DIV }; |
| 852 |
|
| 853 |
static PyObject * SDelay_setDelay(SDelay *self, PyObject *arg) { SET_PARAM(self->delay, self->delay_stream, 2); } |
| 854 |
|
| 855 |
static PyObject * |
| 856 |
SDelay_reset(SDelay *self) |
| 857 |
{ |
| 858 |
int i; |
| 859 |
|
| 860 |
for (i = 0; i < (self->size + 1); i++) |
| 861 |
{ |
| 862 |
self->buffer[i] = 0.; |
| 863 |
} |
| 864 |
|
| 865 |
Py_RETURN_NONE; |
| 866 |
} |
| 867 |
|
| 868 |
static PyMemberDef SDelay_members[] = |
| 869 |
{ |
| 870 |
{"server", T_OBJECT_EX, offsetof(SDelay, server), 0, "Pyo server."}, |
| 871 |
{"stream", T_OBJECT_EX, offsetof(SDelay, stream), 0, "Stream object."}, |
| 872 |
{"input", T_OBJECT_EX, offsetof(SDelay, input), 0, "Input sound object."}, |
| 873 |
{"delay", T_OBJECT_EX, offsetof(SDelay, delay), 0, "Delay time in seconds."}, |
| 874 |
{"mul", T_OBJECT_EX, offsetof(SDelay, mul), 0, "Mul factor."}, |
| 875 |
{"add", T_OBJECT_EX, offsetof(SDelay, add), 0, "Add factor."}, |
| 876 |
{NULL} /* Sentinel */ |
| 877 |
}; |
| 878 |
|
| 879 |
static PyMethodDef SDelay_methods[] = |
| 880 |
{ |
| 881 |
{"getServer", (PyCFunction)SDelay_getServer, METH_NOARGS, "Returns server object."}, |
| 882 |
{"_getStream", (PyCFunction)SDelay_getStream, METH_NOARGS, "Returns stream object."}, |
| 883 |
{"play", (PyCFunction)SDelay_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 884 |
{"out", (PyCFunction)SDelay_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."}, |
| 885 |
{"stop", (PyCFunction)SDelay_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 886 |
{"setDelay", (PyCFunction)SDelay_setDelay, METH_O, "Sets delay time in seconds."}, |
| 887 |
{"reset", (PyCFunction)SDelay_reset, METH_NOARGS, "Resets the memory buffer to zeros."}, |
| 888 |
{"setMul", (PyCFunction)SDelay_setMul, METH_O, "Sets oscillator mul factor."}, |
| 889 |
{"setAdd", (PyCFunction)SDelay_setAdd, METH_O, "Sets oscillator add factor."}, |
| 890 |
{"setSub", (PyCFunction)SDelay_setSub, METH_O, "Sets inverse add factor."}, |
| 891 |
{"setDiv", (PyCFunction)SDelay_setDiv, METH_O, "Sets inverse mul factor."}, |
| 892 |
{NULL} /* Sentinel */ |
| 893 |
}; |
| 894 |
|
| 895 |
static PyNumberMethods SDelay_as_number = |
| 896 |
{ |
| 897 |
(binaryfunc)SDelay_add, /*nb_add*/ |
| 898 |
(binaryfunc)SDelay_sub, /*nb_subtract*/ |
| 899 |
(binaryfunc)SDelay_multiply, /*nb_multiply*/ |
| 900 |
0, /*nb_remainder*/ |
| 901 |
0, /*nb_divmod*/ |
| 902 |
0, /*nb_power*/ |
| 903 |
0, /*nb_neg*/ |
| 904 |
0, /*nb_pos*/ |
| 905 |
0, /*(unaryfunc)array_abs,*/ |
| 906 |
0, /*nb_nonzero*/ |
| 907 |
0, /*nb_invert*/ |
| 908 |
0, /*nb_lshift*/ |
| 909 |
0, /*nb_rshift*/ |
| 910 |
0, /*nb_and*/ |
| 911 |
0, /*nb_xor*/ |
| 912 |
0, /*nb_or*/ |
| 913 |
0, /*nb_int*/ |
| 914 |
0, /*nb_long*/ |
| 915 |
0, /*nb_float*/ |
| 916 |
(binaryfunc)SDelay_inplace_add, /*inplace_add*/ |
| 917 |
(binaryfunc)SDelay_inplace_sub, /*inplace_subtract*/ |
| 918 |
(binaryfunc)SDelay_inplace_multiply, /*inplace_multiply*/ |
| 919 |
0, /*inplace_remainder*/ |
| 920 |
0, /*inplace_power*/ |
| 921 |
0, /*inplace_lshift*/ |
| 922 |
0, /*inplace_rshift*/ |
| 923 |
0, /*inplace_and*/ |
| 924 |
0, /*inplace_xor*/ |
| 925 |
0, /*inplace_or*/ |
| 926 |
0, /*nb_floor_divide*/ |
| 927 |
(binaryfunc)SDelay_div, /*nb_true_divide*/ |
| 928 |
0, /*nb_inplace_floor_divide*/ |
| 929 |
(binaryfunc)SDelay_inplace_div, /*nb_inplace_true_divide*/ |
| 930 |
0, /* nb_index */ |
| 931 |
}; |
| 932 |
|
| 933 |
PyTypeObject SDelayType = |
| 934 |
{ |
| 935 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 936 |
"_pyo.SDelay_base", /*tp_name*/ |
| 937 |
sizeof(SDelay), /*tp_basicsize*/ |
| 938 |
0, /*tp_itemsize*/ |
| 939 |
(destructor)SDelay_dealloc, /*tp_dealloc*/ |
| 940 |
0, /*tp_print*/ |
| 941 |
0, /*tp_getattr*/ |
| 942 |
0, /*tp_setattr*/ |
| 943 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 944 |
0, /*tp_repr*/ |
| 945 |
&SDelay_as_number, /*tp_as_number*/ |
| 946 |
0, /*tp_as_sequence*/ |
| 947 |
0, /*tp_as_mapping*/ |
| 948 |
0, /*tp_hash */ |
| 949 |
0, /*tp_call*/ |
| 950 |
0, /*tp_str*/ |
| 951 |
0, /*tp_getattro*/ |
| 952 |
0, /*tp_setattro*/ |
| 953 |
0, /*tp_as_buffer*/ |
| 954 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 955 |
"SDelay objects. Simple Delay with no interpolation and no feedback.", /* tp_doc */ |
| 956 |
(traverseproc)SDelay_traverse, /* tp_traverse */ |
| 957 |
(inquiry)SDelay_clear, /* tp_clear */ |
| 958 |
0, /* tp_richcompare */ |
| 959 |
0, /* tp_weaklistoffset */ |
| 960 |
0, /* tp_iter */ |
| 961 |
0, /* tp_iternext */ |
| 962 |
SDelay_methods, /* tp_methods */ |
| 963 |
SDelay_members, /* tp_members */ |
| 964 |
0, /* tp_getset */ |
| 965 |
0, /* tp_base */ |
| 966 |
0, /* tp_dict */ |
| 967 |
0, /* tp_descr_get */ |
| 968 |
0, /* tp_descr_set */ |
| 969 |
0, /* tp_dictoffset */ |
| 970 |
0, /* tp_init */ |
| 971 |
0, /* tp_alloc */ |
| 972 |
SDelay_new, /* tp_new */ |
| 973 |
}; |
| 974 |
|
| 975 |
/*********************/ |
| 976 |
/***** Waveguide *****/ |
| 977 |
/*********************/ |
| 978 |
typedef struct |
| 979 |
{ |
| 980 |
pyo_audio_HEAD |
| 981 |
PyObject *input; |
| 982 |
Stream *input_stream; |
| 983 |
PyObject *freq; |
| 984 |
Stream *freq_stream; |
| 985 |
PyObject *dur; |
| 986 |
Stream *dur_stream; |
| 987 |
MYFLT minfreq; |
| 988 |
MYFLT lastFreq; |
| 989 |
MYFLT lastSampDel; |
| 990 |
MYFLT lastDur; |
| 991 |
MYFLT lastFeed; |
| 992 |
long size; |
| 993 |
int in_count; |
| 994 |
MYFLT nyquist; |
| 995 |
int modebuffer[4]; |
| 996 |
MYFLT lpsamp; // lowpass sample memory |
| 997 |
MYFLT coeffs[5]; // lagrange coefficients |
| 998 |
MYFLT lagrange[4]; // lagrange samples memories |
| 999 |
MYFLT xn1; // dc block input delay |
| 1000 |
MYFLT yn1; // dc block output delay |
| 1001 |
MYFLT *buffer; // samples memory |
| 1002 |
} Waveguide; |
| 1003 |
|
| 1004 |
static void |
| 1005 |
Waveguide_process_ii(Waveguide *self) |
| 1006 |
{ |
| 1007 |
MYFLT val, x, y, sampdel, frac, feed, tmp; |
| 1008 |
int i, ind, isamp; |
| 1009 |
|
| 1010 |
MYFLT fr = PyFloat_AS_DOUBLE(self->freq); |
| 1011 |
MYFLT dur = PyFloat_AS_DOUBLE(self->dur); |
| 1012 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 1013 |
|
| 1014 |
/* Check boundaries */ |
| 1015 |
if (fr < self->minfreq) |
| 1016 |
fr = self->minfreq; |
| 1017 |
else if (fr >= self->nyquist) |
| 1018 |
fr = self->nyquist; |
| 1019 |
|
| 1020 |
if (dur <= 0) |
| 1021 |
dur = 0.1; |
| 1022 |
|
| 1023 |
|
| 1024 |
sampdel = self->lastSampDel; |
| 1025 |
feed = self->lastFeed; |
| 1026 |
|
| 1027 |
/* lagrange coeffs and feedback coeff */ |
| 1028 |
if (fr != self->lastFreq) |
| 1029 |
{ |
| 1030 |
self->lastFreq = fr; |
| 1031 |
sampdel = self->sr / fr - 0.5; |
| 1032 |
self->lastSampDel = sampdel; |
| 1033 |
isamp = (int)sampdel; |
| 1034 |
frac = sampdel - isamp; |
| 1035 |
self->coeffs[0] = (frac - 1) * (frac - 2) * (frac - 3) * (frac - 4) / 24.0; |
| 1036 |
self->coeffs[1] = -frac * (frac - 2) * (frac - 3) * (frac - 4) / 6.0; |
| 1037 |
self->coeffs[2] = frac * (frac - 1) * (frac - 3) * (frac - 4) / 4.0; |
| 1038 |
self->coeffs[3] = -frac * (frac - 1) * (frac - 2) * (frac - 4) / 6.0; |
| 1039 |
self->coeffs[4] = frac * (frac - 1) * (frac - 2) * (frac - 3) / 24.0; |
| 1040 |
|
| 1041 |
self->lastDur = dur; |
| 1042 |
feed = MYPOW(100, -1.0 / (fr * dur)); |
| 1043 |
self->lastFeed = feed; |
| 1044 |
} |
| 1045 |
else if (dur != self->lastDur) |
| 1046 |
{ |
| 1047 |
self->lastDur = dur; |
| 1048 |
feed = MYPOW(100, -1.0 / (fr * dur)); |
| 1049 |
self->lastFeed = feed; |
| 1050 |
} |
| 1051 |
|
| 1052 |
/* pick a new value in th delay line */ |
| 1053 |
isamp = (int)sampdel; |
| 1054 |
|
| 1055 |
for (i = 0; i < self->bufsize; i++) |
| 1056 |
{ |
| 1057 |
ind = self->in_count - isamp; |
| 1058 |
|
| 1059 |
if (ind < 0) |
| 1060 |
ind += self->size; |
| 1061 |
|
| 1062 |
val = self->buffer[ind]; |
| 1063 |
|
| 1064 |
/* simple lowpass filtering */ |
| 1065 |
tmp = val; |
| 1066 |
val = (val + self->lpsamp) * 0.5; |
| 1067 |
self->lpsamp = tmp; |
| 1068 |
|
| 1069 |
/* lagrange filtering */ |
| 1070 |
x = (val * self->coeffs[0]) + (self->lagrange[0] * self->coeffs[1]) + (self->lagrange[1] * self->coeffs[2]) + |
| 1071 |
(self->lagrange[2] * self->coeffs[3]) + (self->lagrange[3] * self->coeffs[4]); |
| 1072 |
self->lagrange[3] = self->lagrange[2]; |
| 1073 |
self->lagrange[2] = self->lagrange[1]; |
| 1074 |
self->lagrange[1] = self->lagrange[0]; |
| 1075 |
self->lagrange[0] = val; |
| 1076 |
|
| 1077 |
/* DC filtering */ |
| 1078 |
y = x - self->xn1 + 0.995 * self->yn1; |
| 1079 |
self->xn1 = x; |
| 1080 |
self->yn1 = y; |
| 1081 |
|
| 1082 |
self->data[i] = y; |
| 1083 |
|
| 1084 |
/* write current value in the delay line */ |
| 1085 |
self->buffer[self->in_count] = in[i] + (x * feed); |
| 1086 |
|
| 1087 |
if (self->in_count == 0) |
| 1088 |
self->buffer[self->size] = self->buffer[0]; |
| 1089 |
|
| 1090 |
self->in_count++; |
| 1091 |
|
| 1092 |
if (self->in_count == self->size) |
| 1093 |
self->in_count = 0; |
| 1094 |
} |
| 1095 |
} |
| 1096 |
|
| 1097 |
static void |
| 1098 |
Waveguide_process_ai(Waveguide *self) |
| 1099 |
{ |
| 1100 |
MYFLT val, x, y, sampdel, frac, feed, freq, tmp; |
| 1101 |
int i, ind, isamp; |
| 1102 |
|
| 1103 |
MYFLT *fr = Stream_getData((Stream *)self->freq_stream); |
| 1104 |
MYFLT dur = PyFloat_AS_DOUBLE(self->dur); |
| 1105 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 1106 |
|
| 1107 |
/* Check dur boundary */ |
| 1108 |
if (dur <= 0) |
| 1109 |
dur = 0.1; |
| 1110 |
|
| 1111 |
for (i = 0; i < self->bufsize; i++) |
| 1112 |
{ |
| 1113 |
freq = fr[i]; |
| 1114 |
|
| 1115 |
/* Check frequency boundary */ |
| 1116 |
if (freq < self->minfreq) |
| 1117 |
freq = self->minfreq; |
| 1118 |
else if (freq >= self->nyquist) |
| 1119 |
freq = self->nyquist; |
| 1120 |
|
| 1121 |
sampdel = self->lastSampDel; |
| 1122 |
feed = self->lastFeed; |
| 1123 |
|
| 1124 |
/* lagrange coeffs and feedback coeff */ |
| 1125 |
if (freq != self->lastFreq) |
| 1126 |
{ |
| 1127 |
self->lastFreq = freq; |
| 1128 |
sampdel = self->sr / freq - 0.5; |
| 1129 |
self->lastSampDel = sampdel; |
| 1130 |
isamp = (int)sampdel; |
| 1131 |
frac = sampdel - isamp; |
| 1132 |
self->coeffs[0] = (frac - 1) * (frac - 2) * (frac - 3) * (frac - 4) / 24.0; |
| 1133 |
self->coeffs[1] = -frac * (frac - 2) * (frac - 3) * (frac - 4) / 6.0; |
| 1134 |
self->coeffs[2] = frac * (frac - 1) * (frac - 3) * (frac - 4) / 4.0; |
| 1135 |
self->coeffs[3] = -frac * (frac - 1) * (frac - 2) * (frac - 4) / 6.0; |
| 1136 |
self->coeffs[4] = frac * (frac - 1) * (frac - 2) * (frac - 3) / 24.0; |
| 1137 |
|
| 1138 |
self->lastDur = dur; |
| 1139 |
feed = MYPOW(100, -1.0 / (freq * dur)); |
| 1140 |
self->lastFeed = feed; |
| 1141 |
} |
| 1142 |
else if (dur != self->lastDur) |
| 1143 |
{ |
| 1144 |
self->lastDur = dur; |
| 1145 |
feed = MYPOW(100, -1.0 / (freq * dur)); |
| 1146 |
self->lastFeed = feed; |
| 1147 |
} |
| 1148 |
|
| 1149 |
/* pick a new value in th delay line */ |
| 1150 |
isamp = (int)sampdel; |
| 1151 |
|
| 1152 |
ind = self->in_count - isamp; |
| 1153 |
|
| 1154 |
if (ind < 0) |
| 1155 |
ind += self->size; |
| 1156 |
|
| 1157 |
val = self->buffer[ind]; |
| 1158 |
|
| 1159 |
/* simple lowpass filtering */ |
| 1160 |
tmp = val; |
| 1161 |
val = (val + self->lpsamp) * 0.5; |
| 1162 |
self->lpsamp = tmp; |
| 1163 |
|
| 1164 |
/* lagrange filtering */ |
| 1165 |
x = (val * self->coeffs[0]) + (self->lagrange[0] * self->coeffs[1]) + (self->lagrange[1] * self->coeffs[2]) + |
| 1166 |
(self->lagrange[2] * self->coeffs[3]) + (self->lagrange[3] * self->coeffs[4]); |
| 1167 |
self->lagrange[3] = self->lagrange[2]; |
| 1168 |
self->lagrange[2] = self->lagrange[1]; |
| 1169 |
self->lagrange[1] = self->lagrange[0]; |
| 1170 |
self->lagrange[0] = val; |
| 1171 |
|
| 1172 |
/* DC filtering */ |
| 1173 |
y = x - self->xn1 + 0.995 * self->yn1; |
| 1174 |
self->xn1 = x; |
| 1175 |
self->yn1 = y; |
| 1176 |
|
| 1177 |
self->data[i] = y; |
| 1178 |
|
| 1179 |
/* write current value in the delay line */ |
| 1180 |
self->buffer[self->in_count] = in[i] + (x * feed); |
| 1181 |
|
| 1182 |
if (self->in_count == 0) |
| 1183 |
self->buffer[self->size] = self->buffer[0]; |
| 1184 |
|
| 1185 |
self->in_count++; |
| 1186 |
|
| 1187 |
if (self->in_count == self->size) |
| 1188 |
self->in_count = 0; |
| 1189 |
} |
| 1190 |
} |
| 1191 |
|
| 1192 |
|
| 1193 |
static void |
| 1194 |
Waveguide_process_ia(Waveguide *self) |
| 1195 |
{ |
| 1196 |
MYFLT val, x, y, sampdel, frac, feed, dur, tmp; |
| 1197 |
int i, ind, isamp; |
| 1198 |
|
| 1199 |
MYFLT fr = PyFloat_AS_DOUBLE(self->freq); |
| 1200 |
MYFLT *du = Stream_getData((Stream *)self->dur_stream); |
| 1201 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 1202 |
|
| 1203 |
/* Check boundaries */ |
| 1204 |
if (fr < self->minfreq) |
| 1205 |
fr = self->minfreq; |
| 1206 |
else if (fr >= self->nyquist) |
| 1207 |
fr = self->nyquist; |
| 1208 |
|
| 1209 |
sampdel = self->lastSampDel; |
| 1210 |
|
| 1211 |
/* lagrange coeffs and feedback coeff */ |
| 1212 |
if (fr != self->lastFreq) |
| 1213 |
{ |
| 1214 |
self->lastFreq = fr; |
| 1215 |
sampdel = self->sr / fr - 0.5; |
| 1216 |
self->lastSampDel = sampdel; |
| 1217 |
isamp = (int)sampdel; |
| 1218 |
frac = sampdel - isamp; |
| 1219 |
self->coeffs[0] = (frac - 1) * (frac - 2) * (frac - 3) * (frac - 4) / 24.0; |
| 1220 |
self->coeffs[1] = -frac * (frac - 2) * (frac - 3) * (frac - 4) / 6.0; |
| 1221 |
self->coeffs[2] = frac * (frac - 1) * (frac - 3) * (frac - 4) / 4.0; |
| 1222 |
self->coeffs[3] = -frac * (frac - 1) * (frac - 2) * (frac - 4) / 6.0; |
| 1223 |
self->coeffs[4] = frac * (frac - 1) * (frac - 2) * (frac - 3) / 24.0; |
| 1224 |
} |
| 1225 |
|
| 1226 |
/* pick a new value in th delay line */ |
| 1227 |
isamp = (int)sampdel; |
| 1228 |
|
| 1229 |
for (i = 0; i < self->bufsize; i++) |
| 1230 |
{ |
| 1231 |
feed = self->lastFeed; |
| 1232 |
dur = du[i]; |
| 1233 |
|
| 1234 |
if (dur <= 0) |
| 1235 |
dur = 0.1; |
| 1236 |
|
| 1237 |
if (dur != self->lastDur) |
| 1238 |
{ |
| 1239 |
self->lastDur = dur; |
| 1240 |
feed = MYPOW(100, -1.0 / (fr * dur)); |
| 1241 |
self->lastFeed = feed; |
| 1242 |
} |
| 1243 |
|
| 1244 |
ind = self->in_count - isamp; |
| 1245 |
|
| 1246 |
if (ind < 0) |
| 1247 |
ind += self->size; |
| 1248 |
|
| 1249 |
val = self->buffer[ind]; |
| 1250 |
|
| 1251 |
/* simple lowpass filtering */ |
| 1252 |
tmp = val; |
| 1253 |
val = (val + self->lpsamp) * 0.5; |
| 1254 |
self->lpsamp = tmp; |
| 1255 |
|
| 1256 |
/* lagrange filtering */ |
| 1257 |
x = (val * self->coeffs[0]) + (self->lagrange[0] * self->coeffs[1]) + (self->lagrange[1] * self->coeffs[2]) + |
| 1258 |
(self->lagrange[2] * self->coeffs[3]) + (self->lagrange[3] * self->coeffs[4]); |
| 1259 |
self->lagrange[3] = self->lagrange[2]; |
| 1260 |
self->lagrange[2] = self->lagrange[1]; |
| 1261 |
self->lagrange[1] = self->lagrange[0]; |
| 1262 |
self->lagrange[0] = val; |
| 1263 |
|
| 1264 |
/* DC filtering */ |
| 1265 |
y = x - self->xn1 + 0.995 * self->yn1; |
| 1266 |
self->xn1 = x; |
| 1267 |
self->yn1 = y; |
| 1268 |
|
| 1269 |
self->data[i] = y; |
| 1270 |
|
| 1271 |
/* write current value in the delay line */ |
| 1272 |
self->buffer[self->in_count] = in[i] + (x * feed); |
| 1273 |
|
| 1274 |
if (self->in_count == 0) |
| 1275 |
self->buffer[self->size] = self->buffer[0]; |
| 1276 |
|
| 1277 |
self->in_count++; |
| 1278 |
|
| 1279 |
if (self->in_count == self->size) |
| 1280 |
self->in_count = 0; |
| 1281 |
} |
| 1282 |
} |
| 1283 |
|
| 1284 |
|
| 1285 |
static void |
| 1286 |
Waveguide_process_aa(Waveguide *self) |
| 1287 |
{ |
| 1288 |
MYFLT val, x, y, sampdel, frac, feed, freq, dur, tmp; |
| 1289 |
int i, ind, isamp; |
| 1290 |
|
| 1291 |
MYFLT *fr = Stream_getData((Stream *)self->freq_stream); |
| 1292 |
MYFLT *du = Stream_getData((Stream *)self->dur_stream); |
| 1293 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 1294 |
|
| 1295 |
for (i = 0; i < self->bufsize; i++) |
| 1296 |
{ |
| 1297 |
freq = fr[i]; |
| 1298 |
dur = du[i]; |
| 1299 |
|
| 1300 |
/* Check boundaries */ |
| 1301 |
if (freq < self->minfreq) |
| 1302 |
freq = self->minfreq; |
| 1303 |
else if (freq >= self->nyquist) |
| 1304 |
freq = self->nyquist; |
| 1305 |
|
| 1306 |
if (dur <= 0) |
| 1307 |
dur = 0.1; |
| 1308 |
|
| 1309 |
sampdel = self->lastSampDel; |
| 1310 |
feed = self->lastFeed; |
| 1311 |
|
| 1312 |
/* lagrange coeffs and feedback coeff */ |
| 1313 |
if (freq != self->lastFreq) |
| 1314 |
{ |
| 1315 |
self->lastFreq = freq; |
| 1316 |
sampdel = self->sr / freq - 0.5; |
| 1317 |
self->lastSampDel = sampdel; |
| 1318 |
isamp = (int)sampdel; |
| 1319 |
frac = sampdel - isamp; |
| 1320 |
self->coeffs[0] = (frac - 1) * (frac - 2) * (frac - 3) * (frac - 4) / 24.0; |
| 1321 |
self->coeffs[1] = -frac * (frac - 2) * (frac - 3) * (frac - 4) / 6.0; |
| 1322 |
self->coeffs[2] = frac * (frac - 1) * (frac - 3) * (frac - 4) / 4.0; |
| 1323 |
self->coeffs[3] = -frac * (frac - 1) * (frac - 2) * (frac - 4) / 6.0; |
| 1324 |
self->coeffs[4] = frac * (frac - 1) * (frac - 2) * (frac - 3) / 24.0; |
| 1325 |
|
| 1326 |
self->lastDur = dur; |
| 1327 |
feed = MYPOW(100, -1.0 / (freq * dur)); |
| 1328 |
self->lastFeed = feed; |
| 1329 |
} |
| 1330 |
else if (dur != self->lastDur) |
| 1331 |
{ |
| 1332 |
self->lastDur = dur; |
| 1333 |
feed = MYPOW(100, -1.0 / (freq * dur)); |
| 1334 |
self->lastFeed = feed; |
| 1335 |
} |
| 1336 |
|
| 1337 |
/* pick a new value in th delay line */ |
| 1338 |
isamp = (int)sampdel; |
| 1339 |
|
| 1340 |
ind = self->in_count - isamp; |
| 1341 |
|
| 1342 |
if (ind < 0) |
| 1343 |
ind += self->size; |
| 1344 |
|
| 1345 |
val = self->buffer[ind]; |
| 1346 |
|
| 1347 |
/* simple lowpass filtering */ |
| 1348 |
tmp = val; |
| 1349 |
val = (val + self->lpsamp) * 0.5; |
| 1350 |
self->lpsamp = tmp; |
| 1351 |
|
| 1352 |
/* lagrange filtering */ |
| 1353 |
x = (val * self->coeffs[0]) + (self->lagrange[0] * self->coeffs[1]) + (self->lagrange[1] * self->coeffs[2]) + |
| 1354 |
(self->lagrange[2] * self->coeffs[3]) + (self->lagrange[3] * self->coeffs[4]); |
| 1355 |
self->lagrange[3] = self->lagrange[2]; |
| 1356 |
self->lagrange[2] = self->lagrange[1]; |
| 1357 |
self->lagrange[1] = self->lagrange[0]; |
| 1358 |
self->lagrange[0] = val; |
| 1359 |
|
| 1360 |
/* DC filtering */ |
| 1361 |
y = x - self->xn1 + 0.995 * self->yn1; |
| 1362 |
self->xn1 = x; |
| 1363 |
self->yn1 = y; |
| 1364 |
|
| 1365 |
self->data[i] = y; |
| 1366 |
|
| 1367 |
/* write current value in the delay line */ |
| 1368 |
self->buffer[self->in_count] = in[i] + (x * feed); |
| 1369 |
|
| 1370 |
if (self->in_count == 0) |
| 1371 |
self->buffer[self->size] = self->buffer[0]; |
| 1372 |
|
| 1373 |
self->in_count++; |
| 1374 |
|
| 1375 |
if (self->in_count == self->size) |
| 1376 |
self->in_count = 0; |
| 1377 |
} |
| 1378 |
} |
| 1379 |
|
| 1380 |
static void Waveguide_postprocessing_ii(Waveguide *self) { POST_PROCESSING_II }; |
| 1381 |
static void Waveguide_postprocessing_ai(Waveguide *self) { POST_PROCESSING_AI }; |
| 1382 |
static void Waveguide_postprocessing_ia(Waveguide *self) { POST_PROCESSING_IA }; |
| 1383 |
static void Waveguide_postprocessing_aa(Waveguide *self) { POST_PROCESSING_AA }; |
| 1384 |
static void Waveguide_postprocessing_ireva(Waveguide *self) { POST_PROCESSING_IREVA }; |
| 1385 |
static void Waveguide_postprocessing_areva(Waveguide *self) { POST_PROCESSING_AREVA }; |
| 1386 |
static void Waveguide_postprocessing_revai(Waveguide *self) { POST_PROCESSING_REVAI }; |
| 1387 |
static void Waveguide_postprocessing_revaa(Waveguide *self) { POST_PROCESSING_REVAA }; |
| 1388 |
static void Waveguide_postprocessing_revareva(Waveguide *self) { POST_PROCESSING_REVAREVA }; |
| 1389 |
|
| 1390 |
static void |
| 1391 |
Waveguide_setProcMode(Waveguide *self) |
| 1392 |
{ |
| 1393 |
int procmode, muladdmode; |
| 1394 |
procmode = self->modebuffer[2] + self->modebuffer[3] * 10; |
| 1395 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 1396 |
|
| 1397 |
switch (procmode) |
| 1398 |
{ |
| 1399 |
case 0: |
| 1400 |
self->proc_func_ptr = Waveguide_process_ii; |
| 1401 |
break; |
| 1402 |
|
| 1403 |
case 1: |
| 1404 |
self->proc_func_ptr = Waveguide_process_ai; |
| 1405 |
break; |
| 1406 |
|
| 1407 |
case 10: |
| 1408 |
self->proc_func_ptr = Waveguide_process_ia; |
| 1409 |
break; |
| 1410 |
|
| 1411 |
case 11: |
| 1412 |
self->proc_func_ptr = Waveguide_process_aa; |
| 1413 |
break; |
| 1414 |
} |
| 1415 |
|
| 1416 |
switch (muladdmode) |
| 1417 |
{ |
| 1418 |
case 0: |
| 1419 |
self->muladd_func_ptr = Waveguide_postprocessing_ii; |
| 1420 |
break; |
| 1421 |
|
| 1422 |
case 1: |
| 1423 |
self->muladd_func_ptr = Waveguide_postprocessing_ai; |
| 1424 |
break; |
| 1425 |
|
| 1426 |
case 2: |
| 1427 |
self->muladd_func_ptr = Waveguide_postprocessing_revai; |
| 1428 |
break; |
| 1429 |
|
| 1430 |
case 10: |
| 1431 |
self->muladd_func_ptr = Waveguide_postprocessing_ia; |
| 1432 |
break; |
| 1433 |
|
| 1434 |
case 11: |
| 1435 |
self->muladd_func_ptr = Waveguide_postprocessing_aa; |
| 1436 |
break; |
| 1437 |
|
| 1438 |
case 12: |
| 1439 |
self->muladd_func_ptr = Waveguide_postprocessing_revaa; |
| 1440 |
break; |
| 1441 |
|
| 1442 |
case 20: |
| 1443 |
self->muladd_func_ptr = Waveguide_postprocessing_ireva; |
| 1444 |
break; |
| 1445 |
|
| 1446 |
case 21: |
| 1447 |
self->muladd_func_ptr = Waveguide_postprocessing_areva; |
| 1448 |
break; |
| 1449 |
|
| 1450 |
case 22: |
| 1451 |
self->muladd_func_ptr = Waveguide_postprocessing_revareva; |
| 1452 |
break; |
| 1453 |
} |
| 1454 |
} |
| 1455 |
|
| 1456 |
static void |
| 1457 |
Waveguide_compute_next_data_frame(Waveguide *self) |
| 1458 |
{ |
| 1459 |
(*self->proc_func_ptr)(self); |
| 1460 |
(*self->muladd_func_ptr)(self); |
| 1461 |
} |
| 1462 |
|
| 1463 |
static int |
| 1464 |
Waveguide_traverse(Waveguide *self, visitproc visit, void *arg) |
| 1465 |
{ |
| 1466 |
pyo_VISIT |
| 1467 |
Py_VISIT(self->input); |
| 1468 |
Py_VISIT(self->freq); |
| 1469 |
Py_VISIT(self->dur); |
| 1470 |
return 0; |
| 1471 |
} |
| 1472 |
|
| 1473 |
static int |
| 1474 |
Waveguide_clear(Waveguide *self) |
| 1475 |
{ |
| 1476 |
pyo_CLEAR |
| 1477 |
Py_CLEAR(self->input); |
| 1478 |
Py_CLEAR(self->freq); |
| 1479 |
Py_CLEAR(self->dur); |
| 1480 |
return 0; |
| 1481 |
} |
| 1482 |
|
| 1483 |
static void |
| 1484 |
Waveguide_dealloc(Waveguide* self) |
| 1485 |
{ |
| 1486 |
pyo_DEALLOC |
| 1487 |
PyMem_RawFree(self->buffer); |
| 1488 |
Waveguide_clear(self); |
| 1489 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 1490 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 1491 |
} |
| 1492 |
|
| 1493 |
static PyObject * |
| 1494 |
Waveguide_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 1495 |
{ |
| 1496 |
int i; |
| 1497 |
PyObject *inputtmp, *input_streamtmp, *freqtmp = NULL, *durtmp = NULL, *multmp = NULL, *addtmp = NULL; |
| 1498 |
Waveguide *self; |
| 1499 |
self = (Waveguide *)type->tp_alloc(type, 0); |
| 1500 |
|
| 1501 |
self->freq = PyFloat_FromDouble(100); |
| 1502 |
self->dur = PyFloat_FromDouble(0.99); |
| 1503 |
self->minfreq = 20; |
| 1504 |
self->lastFreq = -1.0; |
| 1505 |
self->lastSampDel = -1.0; |
| 1506 |
self->lastDur = -1.0; |
| 1507 |
self->lastFeed = 0.0; |
| 1508 |
self->in_count = 0; |
| 1509 |
self->lpsamp = 0.0; |
| 1510 |
|
| 1511 |
for (i = 0; i < 4; i++) |
| 1512 |
{ |
| 1513 |
self->lagrange[i] = 0.0; |
| 1514 |
} |
| 1515 |
|
| 1516 |
self->xn1 = 0.0; |
| 1517 |
self->yn1 = 0.0; |
| 1518 |
self->modebuffer[0] = 0; |
| 1519 |
self->modebuffer[1] = 0; |
| 1520 |
self->modebuffer[2] = 0; |
| 1521 |
self->modebuffer[3] = 0; |
| 1522 |
|
| 1523 |
INIT_OBJECT_COMMON |
| 1524 |
|
| 1525 |
self->nyquist = (MYFLT)self->sr * 0.45; |
| 1526 |
|
| 1527 |
Stream_setFunctionPtr(self->stream, Waveguide_compute_next_data_frame); |
| 1528 |
self->mode_func_ptr = Waveguide_setProcMode; |
| 1529 |
|
| 1530 |
static char *kwlist[] = {"input", "freq", "dur", "minfreq", "mul", "add", NULL}; |
| 1531 |
|
| 1532 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_O_OOFOO, kwlist, &inputtmp, &freqtmp, &durtmp, &self->minfreq, &multmp, &addtmp)) |
| 1533 |
Py_RETURN_NONE; |
| 1534 |
|
| 1535 |
INIT_INPUT_STREAM |
| 1536 |
|
| 1537 |
if (freqtmp) |
| 1538 |
{ |
| 1539 |
PyObject_CallMethod((PyObject *)self, "setFreq", "O", freqtmp); |
| 1540 |
} |
| 1541 |
|
| 1542 |
if (durtmp) |
| 1543 |
{ |
| 1544 |
PyObject_CallMethod((PyObject *)self, "setDur", "O", durtmp); |
| 1545 |
} |
| 1546 |
|
| 1547 |
if (multmp) |
| 1548 |
{ |
| 1549 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 1550 |
} |
| 1551 |
|
| 1552 |
if (addtmp) |
| 1553 |
{ |
| 1554 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 1555 |
} |
| 1556 |
|
| 1557 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 1558 |
|
| 1559 |
self->size = (long)(1.0 / self->minfreq * self->sr + 0.5); |
| 1560 |
|
| 1561 |
self->buffer = (MYFLT *)PyMem_RawRealloc(self->buffer, (self->size + 1) * sizeof(MYFLT)); |
| 1562 |
|
| 1563 |
for (i = 0; i < (self->size + 1); i++) |
| 1564 |
{ |
| 1565 |
self->buffer[i] = 0.; |
| 1566 |
} |
| 1567 |
|
| 1568 |
(*self->mode_func_ptr)(self); |
| 1569 |
|
| 1570 |
return (PyObject *)self; |
| 1571 |
} |
| 1572 |
|
| 1573 |
static PyObject * Waveguide_getServer(Waveguide* self) { GET_SERVER }; |
| 1574 |
static PyObject * Waveguide_getStream(Waveguide* self) { GET_STREAM }; |
| 1575 |
static PyObject * Waveguide_setMul(Waveguide *self, PyObject *arg) { SET_MUL }; |
| 1576 |
static PyObject * Waveguide_setAdd(Waveguide *self, PyObject *arg) { SET_ADD }; |
| 1577 |
static PyObject * Waveguide_setSub(Waveguide *self, PyObject *arg) { SET_SUB }; |
| 1578 |
static PyObject * Waveguide_setDiv(Waveguide *self, PyObject *arg) { SET_DIV }; |
| 1579 |
|
| 1580 |
static PyObject * Waveguide_play(Waveguide *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 1581 |
static PyObject * Waveguide_out(Waveguide *self, PyObject *args, PyObject *kwds) { OUT }; |
| 1582 |
static PyObject * Waveguide_stop(Waveguide *self, PyObject *args, PyObject *kwds) { STOP }; |
| 1583 |
|
| 1584 |
static PyObject * Waveguide_multiply(Waveguide *self, PyObject *arg) { MULTIPLY }; |
| 1585 |
static PyObject * Waveguide_inplace_multiply(Waveguide *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 1586 |
static PyObject * Waveguide_add(Waveguide *self, PyObject *arg) { ADD }; |
| 1587 |
static PyObject * Waveguide_inplace_add(Waveguide *self, PyObject *arg) { INPLACE_ADD }; |
| 1588 |
static PyObject * Waveguide_sub(Waveguide *self, PyObject *arg) { SUB }; |
| 1589 |
static PyObject * Waveguide_inplace_sub(Waveguide *self, PyObject *arg) { INPLACE_SUB }; |
| 1590 |
static PyObject * Waveguide_div(Waveguide *self, PyObject *arg) { DIV }; |
| 1591 |
static PyObject * Waveguide_inplace_div(Waveguide *self, PyObject *arg) { INPLACE_DIV }; |
| 1592 |
|
| 1593 |
static PyObject * |
| 1594 |
Waveguide_reset(Waveguide *self) |
| 1595 |
{ |
| 1596 |
int i; |
| 1597 |
|
| 1598 |
for (i = 0; i < (self->size + 1); i++) |
| 1599 |
{ |
| 1600 |
self->buffer[i] = 0.; |
| 1601 |
} |
| 1602 |
|
| 1603 |
for (i = 0; i < 4; i++) |
| 1604 |
{ |
| 1605 |
self->lagrange[i] = 0.0; |
| 1606 |
} |
| 1607 |
|
| 1608 |
self->lpsamp = 0.0; |
| 1609 |
self->xn1 = 0.0; |
| 1610 |
self->yn1 = 0.0; |
| 1611 |
|
| 1612 |
Py_RETURN_NONE; |
| 1613 |
} |
| 1614 |
|
| 1615 |
static PyObject * Waveguide_setFreq(Waveguide *self, PyObject *arg) { SET_PARAM(self->freq, self->freq_stream, 2); } |
| 1616 |
static PyObject * Waveguide_setDur(Waveguide *self, PyObject *arg) { SET_PARAM(self->dur, self->dur_stream, 3); } |
| 1617 |
|
| 1618 |
static PyMemberDef Waveguide_members[] = |
| 1619 |
{ |
| 1620 |
{"server", T_OBJECT_EX, offsetof(Waveguide, server), 0, "Pyo server."}, |
| 1621 |
{"stream", T_OBJECT_EX, offsetof(Waveguide, stream), 0, "Stream object."}, |
| 1622 |
{"input", T_OBJECT_EX, offsetof(Waveguide, input), 0, "Input sound object."}, |
| 1623 |
{"freq", T_OBJECT_EX, offsetof(Waveguide, freq), 0, "Waveguide time in seconds."}, |
| 1624 |
{"dur", T_OBJECT_EX, offsetof(Waveguide, dur), 0, "Feedback value."}, |
| 1625 |
{"mul", T_OBJECT_EX, offsetof(Waveguide, mul), 0, "Mul factor."}, |
| 1626 |
{"add", T_OBJECT_EX, offsetof(Waveguide, add), 0, "Add factor."}, |
| 1627 |
{NULL} /* Sentinel */ |
| 1628 |
}; |
| 1629 |
|
| 1630 |
static PyMethodDef Waveguide_methods[] = |
| 1631 |
{ |
| 1632 |
{"getServer", (PyCFunction)Waveguide_getServer, METH_NOARGS, "Returns server object."}, |
| 1633 |
{"_getStream", (PyCFunction)Waveguide_getStream, METH_NOARGS, "Returns stream object."}, |
| 1634 |
{"play", (PyCFunction)Waveguide_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 1635 |
{"out", (PyCFunction)Waveguide_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."}, |
| 1636 |
{"stop", (PyCFunction)Waveguide_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 1637 |
{"reset", (PyCFunction)Waveguide_reset, METH_NOARGS, "Reset the delay line."}, |
| 1638 |
{"setFreq", (PyCFunction)Waveguide_setFreq, METH_O, "Sets freq time in seconds."}, |
| 1639 |
{"setDur", (PyCFunction)Waveguide_setDur, METH_O, "Sets dur value between 0 -> 1."}, |
| 1640 |
{"setMul", (PyCFunction)Waveguide_setMul, METH_O, "Sets oscillator mul factor."}, |
| 1641 |
{"setAdd", (PyCFunction)Waveguide_setAdd, METH_O, "Sets oscillator add factor."}, |
| 1642 |
{"setSub", (PyCFunction)Waveguide_setSub, METH_O, "Sets inverse add factor."}, |
| 1643 |
{"setDiv", (PyCFunction)Waveguide_setDiv, METH_O, "Sets inverse mul factor."}, |
| 1644 |
{NULL} /* Sentinel */ |
| 1645 |
}; |
| 1646 |
|
| 1647 |
static PyNumberMethods Waveguide_as_number = |
| 1648 |
{ |
| 1649 |
(binaryfunc)Waveguide_add, /*nb_add*/ |
| 1650 |
(binaryfunc)Waveguide_sub, /*nb_subtract*/ |
| 1651 |
(binaryfunc)Waveguide_multiply, /*nb_multiply*/ |
| 1652 |
0, /*nb_remainder*/ |
| 1653 |
0, /*nb_divmod*/ |
| 1654 |
0, /*nb_power*/ |
| 1655 |
0, /*nb_neg*/ |
| 1656 |
0, /*nb_pos*/ |
| 1657 |
0, /*(unaryfunc)array_abs,*/ |
| 1658 |
0, /*nb_nonzero*/ |
| 1659 |
0, /*nb_invert*/ |
| 1660 |
0, /*nb_lshift*/ |
| 1661 |
0, /*nb_rshift*/ |
| 1662 |
0, /*nb_and*/ |
| 1663 |
0, /*nb_xor*/ |
| 1664 |
0, /*nb_or*/ |
| 1665 |
0, /*nb_int*/ |
| 1666 |
0, /*nb_long*/ |
| 1667 |
0, /*nb_float*/ |
| 1668 |
(binaryfunc)Waveguide_inplace_add, /*inplace_add*/ |
| 1669 |
(binaryfunc)Waveguide_inplace_sub, /*inplace_subtract*/ |
| 1670 |
(binaryfunc)Waveguide_inplace_multiply, /*inplace_multiply*/ |
| 1671 |
0, /*inplace_remainder*/ |
| 1672 |
0, /*inplace_power*/ |
| 1673 |
0, /*inplace_lshift*/ |
| 1674 |
0, /*inplace_rshift*/ |
| 1675 |
0, /*inplace_and*/ |
| 1676 |
0, /*inplace_xor*/ |
| 1677 |
0, /*inplace_or*/ |
| 1678 |
0, /*nb_floor_divide*/ |
| 1679 |
(binaryfunc)Waveguide_div, /*nb_true_divide*/ |
| 1680 |
0, /*nb_inplace_floor_divide*/ |
| 1681 |
(binaryfunc)Waveguide_inplace_div, /*nb_inplace_true_divide*/ |
| 1682 |
0, /* nb_index */ |
| 1683 |
}; |
| 1684 |
|
| 1685 |
PyTypeObject WaveguideType = |
| 1686 |
{ |
| 1687 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 1688 |
"_pyo.Waveguide_base", /*tp_name*/ |
| 1689 |
sizeof(Waveguide), /*tp_basicsize*/ |
| 1690 |
0, /*tp_itemsize*/ |
| 1691 |
(destructor)Waveguide_dealloc, /*tp_dealloc*/ |
| 1692 |
0, /*tp_print*/ |
| 1693 |
0, /*tp_getattr*/ |
| 1694 |
0, /*tp_setattr*/ |
| 1695 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 1696 |
0, /*tp_repr*/ |
| 1697 |
&Waveguide_as_number, /*tp_as_number*/ |
| 1698 |
0, /*tp_as_sequence*/ |
| 1699 |
0, /*tp_as_mapping*/ |
| 1700 |
0, /*tp_hash */ |
| 1701 |
0, /*tp_call*/ |
| 1702 |
0, /*tp_str*/ |
| 1703 |
0, /*tp_getattro*/ |
| 1704 |
0, /*tp_setattro*/ |
| 1705 |
0, /*tp_as_buffer*/ |
| 1706 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 1707 |
"Waveguide objects. Waveguide signal by x samples.", /* tp_doc */ |
| 1708 |
(traverseproc)Waveguide_traverse, /* tp_traverse */ |
| 1709 |
(inquiry)Waveguide_clear, /* tp_clear */ |
| 1710 |
0, /* tp_richcompare */ |
| 1711 |
0, /* tp_weaklistoffset */ |
| 1712 |
0, /* tp_iter */ |
| 1713 |
0, /* tp_iternext */ |
| 1714 |
Waveguide_methods, /* tp_methods */ |
| 1715 |
Waveguide_members, /* tp_members */ |
| 1716 |
0, /* tp_getset */ |
| 1717 |
0, /* tp_base */ |
| 1718 |
0, /* tp_dict */ |
| 1719 |
0, /* tp_descr_get */ |
| 1720 |
0, /* tp_descr_set */ |
| 1721 |
0, /* tp_dictoffset */ |
| 1722 |
0, /* tp_init */ |
| 1723 |
0, /* tp_alloc */ |
| 1724 |
Waveguide_new, /* tp_new */ |
| 1725 |
}; |
| 1726 |
|
| 1727 |
/*********************/ |
| 1728 |
/***** AllpassWG *****/ |
| 1729 |
/*********************/ |
| 1730 |
static const MYFLT alp_chorus_factor[3] = {1.0, 0.9981, 0.9957}; |
| 1731 |
static const MYFLT alp_feedback = 0.3; |
| 1732 |
|
| 1733 |
typedef struct |
| 1734 |
{ |
| 1735 |
pyo_audio_HEAD |
| 1736 |
PyObject *input; |
| 1737 |
Stream *input_stream; |
| 1738 |
PyObject *freq; |
| 1739 |
Stream *freq_stream; |
| 1740 |
PyObject *feed; |
| 1741 |
Stream *feed_stream; |
| 1742 |
PyObject *detune; |
| 1743 |
Stream *detune_stream; |
| 1744 |
MYFLT minfreq; |
| 1745 |
MYFLT nyquist; |
| 1746 |
long size; |
| 1747 |
int alpsize; |
| 1748 |
int in_count; |
| 1749 |
int alp_in_count[3]; |
| 1750 |
int modebuffer[5]; |
| 1751 |
MYFLT *alpbuffer[3]; // allpass samples memories |
| 1752 |
MYFLT xn1; // dc block input delay |
| 1753 |
MYFLT yn1; // dc block output delay |
| 1754 |
MYFLT *buffer; // samples memory |
| 1755 |
} AllpassWG; |
| 1756 |
|
| 1757 |
static void |
| 1758 |
AllpassWG_process_iii(AllpassWG *self) |
| 1759 |
{ |
| 1760 |
int i, j; |
| 1761 |
long ind; |
| 1762 |
MYFLT val, y, xind, sampdel, frac, freqshift, alpsampdel, alpsampdelin, alpdetune; |
| 1763 |
|
| 1764 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 1765 |
MYFLT fr = PyFloat_AS_DOUBLE(self->freq); |
| 1766 |
MYFLT feed = PyFloat_AS_DOUBLE(self->feed); |
| 1767 |
MYFLT detune = PyFloat_AS_DOUBLE(self->detune); |
| 1768 |
|
| 1769 |
/* Check boundaries */ |
| 1770 |
if (fr < self->minfreq) |
| 1771 |
fr = self->minfreq; |
| 1772 |
else if (fr >= self->nyquist) |
| 1773 |
fr = self->nyquist; |
| 1774 |
|
| 1775 |
feed *= 0.4525; |
| 1776 |
|
| 1777 |
if (feed > 0.4525) |
| 1778 |
feed = 0.4525; |
| 1779 |
else if (feed < 0) |
| 1780 |
feed = 0; |
| 1781 |
|
| 1782 |
freqshift = detune * 0.5 + 1.; |
| 1783 |
detune = detune * 0.95 + 0.05; |
| 1784 |
|
| 1785 |
if (detune < 0.05) |
| 1786 |
detune = 0.05; |
| 1787 |
else if (detune > 1.0) |
| 1788 |
detune = 1.0; |
| 1789 |
|
| 1790 |
sampdel = self->sr / (fr * freqshift); |
| 1791 |
alpdetune = detune * self->alpsize; |
| 1792 |
|
| 1793 |
for (i = 0; i < self->bufsize; i++) |
| 1794 |
{ |
| 1795 |
/* pick a new value in the delay line */ |
| 1796 |
xind = self->in_count - sampdel; |
| 1797 |
|
| 1798 |
if (xind < 0) |
| 1799 |
xind += self->size; |
| 1800 |
|
| 1801 |
ind = (long)xind; |
| 1802 |
frac = xind - ind; |
| 1803 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 1804 |
|
| 1805 |
/* all-pass filter */ |
| 1806 |
for (j = 0; j < 3; j++) |
| 1807 |
{ |
| 1808 |
xind = self->alp_in_count[j] - (alpdetune * alp_chorus_factor[j]); |
| 1809 |
|
| 1810 |
if (xind < 0) |
| 1811 |
xind += self->alpsize; |
| 1812 |
|
| 1813 |
ind = (long)xind; |
| 1814 |
frac = xind - ind; |
| 1815 |
alpsampdel = self->alpbuffer[j][ind] + (self->alpbuffer[j][ind + 1] - self->alpbuffer[j][ind]) * frac; |
| 1816 |
alpsampdelin = val + ((val - alpsampdel) * alp_feedback); |
| 1817 |
val = alpsampdelin * alp_feedback + alpsampdel; |
| 1818 |
/* write current allpass value in the allpass delay line */ |
| 1819 |
self->alpbuffer[j][self->alp_in_count[j]] = alpsampdelin; |
| 1820 |
|
| 1821 |
if (self->alp_in_count[j] == 0) |
| 1822 |
self->alpbuffer[j][self->alpsize] = alpsampdelin; |
| 1823 |
|
| 1824 |
self->alp_in_count[j]++; |
| 1825 |
|
| 1826 |
if (self->alp_in_count[j] == self->alpsize) |
| 1827 |
self->alp_in_count[j] = 0; |
| 1828 |
} |
| 1829 |
|
| 1830 |
/* DC filtering and output */ |
| 1831 |
y = val - self->xn1 + 0.995 * self->yn1; |
| 1832 |
self->xn1 = val; |
| 1833 |
self->data[i] = self->yn1 = y; |
| 1834 |
|
| 1835 |
/* write current value in the delay line */ |
| 1836 |
self->buffer[self->in_count] = in[i] + val * feed; |
| 1837 |
|
| 1838 |
if (self->in_count == 0) |
| 1839 |
self->buffer[self->size] = self->buffer[0]; |
| 1840 |
|
| 1841 |
self->in_count++; |
| 1842 |
|
| 1843 |
if (self->in_count == self->size) |
| 1844 |
self->in_count = 0; |
| 1845 |
} |
| 1846 |
} |
| 1847 |
|
| 1848 |
static void |
| 1849 |
AllpassWG_process_aii(AllpassWG *self) |
| 1850 |
{ |
| 1851 |
int i, j; |
| 1852 |
long ind; |
| 1853 |
MYFLT val, y, xind, sampdel, frac, fr, freqshift, alpsampdel, alpsampdelin, alpdetune; |
| 1854 |
|
| 1855 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 1856 |
MYFLT *freq = Stream_getData((Stream *)self->freq_stream); |
| 1857 |
MYFLT feed = PyFloat_AS_DOUBLE(self->feed); |
| 1858 |
MYFLT detune = PyFloat_AS_DOUBLE(self->detune); |
| 1859 |
|
| 1860 |
feed *= 0.4525; |
| 1861 |
|
| 1862 |
if (feed > 0.4525) |
| 1863 |
feed = 0.4525; |
| 1864 |
else if (feed < 0) |
| 1865 |
feed = 0; |
| 1866 |
|
| 1867 |
freqshift = detune * 0.5 + 1.; |
| 1868 |
detune = detune * 0.95 + 0.05; |
| 1869 |
|
| 1870 |
if (detune < 0.05) |
| 1871 |
detune = 0.05; |
| 1872 |
else if (detune > 1.0) |
| 1873 |
detune = 1.0; |
| 1874 |
|
| 1875 |
alpdetune = detune * self->alpsize; |
| 1876 |
|
| 1877 |
for (i = 0; i < self->bufsize; i++) |
| 1878 |
{ |
| 1879 |
fr = freq[i]; |
| 1880 |
|
| 1881 |
if (fr < self->minfreq) |
| 1882 |
fr = self->minfreq; |
| 1883 |
else if (fr >= self->nyquist) |
| 1884 |
fr = self->nyquist; |
| 1885 |
|
| 1886 |
/* pick a new value in the delay line */ |
| 1887 |
sampdel = self->sr / (fr * freqshift); |
| 1888 |
xind = self->in_count - sampdel; |
| 1889 |
|
| 1890 |
if (xind < 0) |
| 1891 |
xind += self->size; |
| 1892 |
|
| 1893 |
ind = (long)xind; |
| 1894 |
frac = xind - ind; |
| 1895 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 1896 |
|
| 1897 |
/* all-pass filter */ |
| 1898 |
for (j = 0; j < 3; j++) |
| 1899 |
{ |
| 1900 |
xind = self->alp_in_count[j] - (alpdetune * alp_chorus_factor[j]); |
| 1901 |
|
| 1902 |
if (xind < 0) |
| 1903 |
xind += self->alpsize; |
| 1904 |
|
| 1905 |
ind = (long)xind; |
| 1906 |
frac = xind - ind; |
| 1907 |
alpsampdel = self->alpbuffer[j][ind] + (self->alpbuffer[j][ind + 1] - self->alpbuffer[j][ind]) * frac; |
| 1908 |
alpsampdelin = val + ((val - alpsampdel) * alp_feedback); |
| 1909 |
val = alpsampdelin * alp_feedback + alpsampdel; |
| 1910 |
/* write current allpass value in the allpass delay line */ |
| 1911 |
self->alpbuffer[j][self->alp_in_count[j]] = alpsampdelin; |
| 1912 |
|
| 1913 |
if (self->alp_in_count[j] == 0) |
| 1914 |
self->alpbuffer[j][self->alpsize] = alpsampdelin; |
| 1915 |
|
| 1916 |
self->alp_in_count[j]++; |
| 1917 |
|
| 1918 |
if (self->alp_in_count[j] == self->alpsize) |
| 1919 |
self->alp_in_count[j] = 0; |
| 1920 |
} |
| 1921 |
|
| 1922 |
/* DC filtering and output */ |
| 1923 |
y = val - self->xn1 + 0.995 * self->yn1; |
| 1924 |
self->xn1 = val; |
| 1925 |
self->data[i] = self->yn1 = y; |
| 1926 |
|
| 1927 |
/* write current value in the delay line */ |
| 1928 |
self->buffer[self->in_count] = in[i] + val * feed; |
| 1929 |
|
| 1930 |
if (self->in_count == 0) |
| 1931 |
self->buffer[self->size] = self->buffer[0]; |
| 1932 |
|
| 1933 |
self->in_count++; |
| 1934 |
|
| 1935 |
if (self->in_count == self->size) |
| 1936 |
self->in_count = 0; |
| 1937 |
} |
| 1938 |
} |
| 1939 |
|
| 1940 |
static void |
| 1941 |
AllpassWG_process_iai(AllpassWG *self) |
| 1942 |
{ |
| 1943 |
int i, j; |
| 1944 |
long ind; |
| 1945 |
MYFLT val, y, xind, sampdel, frac, feed, freqshift, alpsampdel, alpsampdelin, alpdetune; |
| 1946 |
|
| 1947 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 1948 |
MYFLT fr = PyFloat_AS_DOUBLE(self->freq); |
| 1949 |
MYFLT *fdb = Stream_getData((Stream *)self->feed_stream); |
| 1950 |
MYFLT detune = PyFloat_AS_DOUBLE(self->detune); |
| 1951 |
|
| 1952 |
/* Check boundaries */ |
| 1953 |
if (fr < self->minfreq) |
| 1954 |
fr = self->minfreq; |
| 1955 |
else if (fr >= self->nyquist) |
| 1956 |
fr = self->nyquist; |
| 1957 |
|
| 1958 |
freqshift = detune * 0.5 + 1.; |
| 1959 |
detune = detune * 0.95 + 0.05; |
| 1960 |
|
| 1961 |
if (detune < 0.05) |
| 1962 |
detune = 0.05; |
| 1963 |
else if (detune > 1.0) |
| 1964 |
detune = 1.0; |
| 1965 |
|
| 1966 |
sampdel = self->sr / (fr * freqshift); |
| 1967 |
alpdetune = detune * self->alpsize; |
| 1968 |
|
| 1969 |
for (i = 0; i < self->bufsize; i++) |
| 1970 |
{ |
| 1971 |
feed = fdb[i] * 0.4525; |
| 1972 |
|
| 1973 |
if (feed > 0.4525) |
| 1974 |
feed = 0.4525; |
| 1975 |
else if (feed < 0) |
| 1976 |
feed = 0; |
| 1977 |
|
| 1978 |
/* pick a new value in the delay line */ |
| 1979 |
xind = self->in_count - sampdel; |
| 1980 |
|
| 1981 |
if (xind < 0) |
| 1982 |
xind += self->size; |
| 1983 |
|
| 1984 |
ind = (long)xind; |
| 1985 |
frac = xind - ind; |
| 1986 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 1987 |
|
| 1988 |
/* all-pass filter */ |
| 1989 |
for (j = 0; j < 3; j++) |
| 1990 |
{ |
| 1991 |
xind = self->alp_in_count[j] - (alpdetune * alp_chorus_factor[j]); |
| 1992 |
|
| 1993 |
if (xind < 0) |
| 1994 |
xind += self->alpsize; |
| 1995 |
|
| 1996 |
ind = (long)xind; |
| 1997 |
frac = xind - ind; |
| 1998 |
alpsampdel = self->alpbuffer[j][ind] + (self->alpbuffer[j][ind + 1] - self->alpbuffer[j][ind]) * frac; |
| 1999 |
alpsampdelin = val + ((val - alpsampdel) * alp_feedback); |
| 2000 |
val = alpsampdelin * alp_feedback + alpsampdel; |
| 2001 |
/* write current allpass value in the allpass delay line */ |
| 2002 |
self->alpbuffer[j][self->alp_in_count[j]] = alpsampdelin; |
| 2003 |
|
| 2004 |
if (self->alp_in_count[j] == 0) |
| 2005 |
self->alpbuffer[j][self->alpsize] = alpsampdelin; |
| 2006 |
|
| 2007 |
self->alp_in_count[j]++; |
| 2008 |
|
| 2009 |
if (self->alp_in_count[j] == self->alpsize) |
| 2010 |
self->alp_in_count[j] = 0; |
| 2011 |
} |
| 2012 |
|
| 2013 |
/* DC filtering and output */ |
| 2014 |
y = val - self->xn1 + 0.995 * self->yn1; |
| 2015 |
self->xn1 = val; |
| 2016 |
self->data[i] = self->yn1 = y; |
| 2017 |
|
| 2018 |
/* write current value in the delay line */ |
| 2019 |
self->buffer[self->in_count] = in[i] + val * feed; |
| 2020 |
|
| 2021 |
if (self->in_count == 0) |
| 2022 |
self->buffer[self->size] = self->buffer[0]; |
| 2023 |
|
| 2024 |
self->in_count++; |
| 2025 |
|
| 2026 |
if (self->in_count == self->size) |
| 2027 |
self->in_count = 0; |
| 2028 |
} |
| 2029 |
} |
| 2030 |
|
| 2031 |
static void |
| 2032 |
AllpassWG_process_aai(AllpassWG *self) |
| 2033 |
{ |
| 2034 |
int i, j; |
| 2035 |
long ind; |
| 2036 |
MYFLT val, y, xind, sampdel, frac, fr, feed, freqshift, alpsampdel, alpsampdelin, alpdetune; |
| 2037 |
|
| 2038 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 2039 |
MYFLT *freq = Stream_getData((Stream *)self->freq_stream); |
| 2040 |
MYFLT *fdb = Stream_getData((Stream *)self->feed_stream); |
| 2041 |
MYFLT detune = PyFloat_AS_DOUBLE(self->detune); |
| 2042 |
|
| 2043 |
freqshift = detune * 0.5 + 1.; |
| 2044 |
detune = detune * 0.95 + 0.05; |
| 2045 |
|
| 2046 |
if (detune < 0.05) |
| 2047 |
detune = 0.05; |
| 2048 |
else if (detune > 1.0) |
| 2049 |
detune = 1.0; |
| 2050 |
|
| 2051 |
alpdetune = detune * self->alpsize; |
| 2052 |
|
| 2053 |
for (i = 0; i < self->bufsize; i++) |
| 2054 |
{ |
| 2055 |
fr = freq[i]; |
| 2056 |
|
| 2057 |
if (fr < self->minfreq) |
| 2058 |
fr = self->minfreq; |
| 2059 |
else if (fr >= self->nyquist) |
| 2060 |
fr = self->nyquist; |
| 2061 |
|
| 2062 |
feed = fdb[i] * 0.4525; |
| 2063 |
|
| 2064 |
if (feed > 0.4525) |
| 2065 |
feed = 0.4525; |
| 2066 |
else if (feed < 0) |
| 2067 |
feed = 0; |
| 2068 |
|
| 2069 |
/* pick a new value in the delay line */ |
| 2070 |
sampdel = self->sr / (fr * freqshift); |
| 2071 |
xind = self->in_count - sampdel; |
| 2072 |
|
| 2073 |
if (xind < 0) |
| 2074 |
xind += self->size; |
| 2075 |
|
| 2076 |
ind = (long)xind; |
| 2077 |
frac = xind - ind; |
| 2078 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 2079 |
|
| 2080 |
/* all-pass filter */ |
| 2081 |
for (j = 0; j < 3; j++) |
| 2082 |
{ |
| 2083 |
xind = self->alp_in_count[j] - (alpdetune * alp_chorus_factor[j]); |
| 2084 |
|
| 2085 |
if (xind < 0) |
| 2086 |
xind += self->alpsize; |
| 2087 |
|
| 2088 |
ind = (long)xind; |
| 2089 |
frac = xind - ind; |
| 2090 |
alpsampdel = self->alpbuffer[j][ind] + (self->alpbuffer[j][ind + 1] - self->alpbuffer[j][ind]) * frac; |
| 2091 |
alpsampdelin = val + ((val - alpsampdel) * alp_feedback); |
| 2092 |
val = alpsampdelin * alp_feedback + alpsampdel; |
| 2093 |
/* write current allpass value in the allpass delay line */ |
| 2094 |
self->alpbuffer[j][self->alp_in_count[j]] = alpsampdelin; |
| 2095 |
|
| 2096 |
if (self->alp_in_count[j] == 0) |
| 2097 |
self->alpbuffer[j][self->alpsize] = alpsampdelin; |
| 2098 |
|
| 2099 |
self->alp_in_count[j]++; |
| 2100 |
|
| 2101 |
if (self->alp_in_count[j] == self->alpsize) |
| 2102 |
self->alp_in_count[j] = 0; |
| 2103 |
} |
| 2104 |
|
| 2105 |
/* DC filtering and output */ |
| 2106 |
y = val - self->xn1 + 0.995 * self->yn1; |
| 2107 |
self->xn1 = val; |
| 2108 |
self->data[i] = self->yn1 = y; |
| 2109 |
|
| 2110 |
/* write current value in the delay line */ |
| 2111 |
self->buffer[self->in_count] = in[i] + val * feed; |
| 2112 |
|
| 2113 |
if (self->in_count == 0) |
| 2114 |
self->buffer[self->size] = self->buffer[0]; |
| 2115 |
|
| 2116 |
self->in_count++; |
| 2117 |
|
| 2118 |
if (self->in_count == self->size) |
| 2119 |
self->in_count = 0; |
| 2120 |
} |
| 2121 |
} |
| 2122 |
|
| 2123 |
static void |
| 2124 |
AllpassWG_process_iia(AllpassWG *self) |
| 2125 |
{ |
| 2126 |
int i, j; |
| 2127 |
long ind; |
| 2128 |
MYFLT val, y, xind, sampdel, frac, detune, freqshift, alpsampdel, alpsampdelin, alpdetune; |
| 2129 |
|
| 2130 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 2131 |
MYFLT fr = PyFloat_AS_DOUBLE(self->freq); |
| 2132 |
MYFLT feed = PyFloat_AS_DOUBLE(self->feed); |
| 2133 |
MYFLT *det = Stream_getData((Stream *)self->detune_stream); |
| 2134 |
|
| 2135 |
/* Check boundaries */ |
| 2136 |
if (fr < self->minfreq) |
| 2137 |
fr = self->minfreq; |
| 2138 |
else if (fr >= self->nyquist) |
| 2139 |
fr = self->nyquist; |
| 2140 |
|
| 2141 |
feed *= 0.4525; |
| 2142 |
|
| 2143 |
if (feed > 0.4525) |
| 2144 |
feed = 0.4525; |
| 2145 |
else if (feed < 0) |
| 2146 |
feed = 0; |
| 2147 |
|
| 2148 |
for (i = 0; i < self->bufsize; i++) |
| 2149 |
{ |
| 2150 |
detune = det[i]; |
| 2151 |
freqshift = detune * 0.5 + 1.; |
| 2152 |
detune = detune * 0.95 + 0.05; |
| 2153 |
|
| 2154 |
if (detune < 0.05) |
| 2155 |
detune = 0.05; |
| 2156 |
else if (detune > 1.0) |
| 2157 |
detune = 1.0; |
| 2158 |
|
| 2159 |
/* pick a new value in the delay line */ |
| 2160 |
sampdel = self->sr / (fr * freqshift); |
| 2161 |
xind = self->in_count - sampdel; |
| 2162 |
|
| 2163 |
if (xind < 0) |
| 2164 |
xind += self->size; |
| 2165 |
|
| 2166 |
ind = (long)xind; |
| 2167 |
frac = xind - ind; |
| 2168 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 2169 |
|
| 2170 |
/* all-pass filter */ |
| 2171 |
alpdetune = detune * self->alpsize; |
| 2172 |
|
| 2173 |
for (j = 0; j < 3; j++) |
| 2174 |
{ |
| 2175 |
xind = self->alp_in_count[j] - (alpdetune * alp_chorus_factor[j]); |
| 2176 |
|
| 2177 |
if (xind < 0) |
| 2178 |
xind += self->alpsize; |
| 2179 |
|
| 2180 |
ind = (long)xind; |
| 2181 |
frac = xind - ind; |
| 2182 |
alpsampdel = self->alpbuffer[j][ind] + (self->alpbuffer[j][ind + 1] - self->alpbuffer[j][ind]) * frac; |
| 2183 |
alpsampdelin = val + ((val - alpsampdel) * alp_feedback); |
| 2184 |
val = alpsampdelin * alp_feedback + alpsampdel; |
| 2185 |
/* write current allpass value in the allpass delay line */ |
| 2186 |
self->alpbuffer[j][self->alp_in_count[j]] = alpsampdelin; |
| 2187 |
|
| 2188 |
if (self->alp_in_count[j] == 0) |
| 2189 |
self->alpbuffer[j][self->alpsize] = alpsampdelin; |
| 2190 |
|
| 2191 |
self->alp_in_count[j]++; |
| 2192 |
|
| 2193 |
if (self->alp_in_count[j] == self->alpsize) |
| 2194 |
self->alp_in_count[j] = 0; |
| 2195 |
} |
| 2196 |
|
| 2197 |
/* DC filtering and output */ |
| 2198 |
y = val - self->xn1 + 0.995 * self->yn1; |
| 2199 |
self->xn1 = val; |
| 2200 |
self->data[i] = self->yn1 = y; |
| 2201 |
|
| 2202 |
/* write current value in the delay line */ |
| 2203 |
self->buffer[self->in_count] = in[i] + val * feed; |
| 2204 |
|
| 2205 |
if (self->in_count == 0) |
| 2206 |
self->buffer[self->size] = self->buffer[0]; |
| 2207 |
|
| 2208 |
self->in_count++; |
| 2209 |
|
| 2210 |
if (self->in_count == self->size) |
| 2211 |
self->in_count = 0; |
| 2212 |
} |
| 2213 |
} |
| 2214 |
|
| 2215 |
static void |
| 2216 |
AllpassWG_process_aia(AllpassWG *self) |
| 2217 |
{ |
| 2218 |
int i, j; |
| 2219 |
long ind; |
| 2220 |
MYFLT val, y, xind, sampdel, frac, fr, detune, freqshift, alpsampdel, alpsampdelin, alpdetune; |
| 2221 |
|
| 2222 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 2223 |
MYFLT *freq = Stream_getData((Stream *)self->freq_stream); |
| 2224 |
MYFLT feed = PyFloat_AS_DOUBLE(self->feed); |
| 2225 |
MYFLT *det = Stream_getData((Stream *)self->detune_stream); |
| 2226 |
|
| 2227 |
feed *= 0.4525; |
| 2228 |
|
| 2229 |
if (feed > 0.4525) |
| 2230 |
feed = 0.4525; |
| 2231 |
else if (feed < 0) |
| 2232 |
feed = 0; |
| 2233 |
|
| 2234 |
for (i = 0; i < self->bufsize; i++) |
| 2235 |
{ |
| 2236 |
fr = freq[i]; |
| 2237 |
|
| 2238 |
if (fr < self->minfreq) |
| 2239 |
fr = self->minfreq; |
| 2240 |
else if (fr >= self->nyquist) |
| 2241 |
fr = self->nyquist; |
| 2242 |
|
| 2243 |
detune = det[i]; |
| 2244 |
freqshift = detune * 0.5 + 1.; |
| 2245 |
detune = detune * 0.95 + 0.05; |
| 2246 |
|
| 2247 |
if (detune < 0.05) |
| 2248 |
detune = 0.05; |
| 2249 |
else if (detune > 1.0) |
| 2250 |
detune = 1.0; |
| 2251 |
|
| 2252 |
/* pick a new value in the delay line */ |
| 2253 |
sampdel = self->sr / (fr * freqshift); |
| 2254 |
xind = self->in_count - sampdel; |
| 2255 |
|
| 2256 |
if (xind < 0) |
| 2257 |
xind += self->size; |
| 2258 |
|
| 2259 |
ind = (long)xind; |
| 2260 |
frac = xind - ind; |
| 2261 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 2262 |
|
| 2263 |
/* all-pass filter */ |
| 2264 |
alpdetune = detune * self->alpsize; |
| 2265 |
|
| 2266 |
for (j = 0; j < 3; j++) |
| 2267 |
{ |
| 2268 |
xind = self->alp_in_count[j] - (alpdetune * alp_chorus_factor[j]); |
| 2269 |
|
| 2270 |
if (xind < 0) |
| 2271 |
xind += self->alpsize; |
| 2272 |
|
| 2273 |
ind = (long)xind; |
| 2274 |
frac = xind - ind; |
| 2275 |
alpsampdel = self->alpbuffer[j][ind] + (self->alpbuffer[j][ind + 1] - self->alpbuffer[j][ind]) * frac; |
| 2276 |
alpsampdelin = val + ((val - alpsampdel) * alp_feedback); |
| 2277 |
val = alpsampdelin * alp_feedback + alpsampdel; |
| 2278 |
/* write current allpass value in the allpass delay line */ |
| 2279 |
self->alpbuffer[j][self->alp_in_count[j]] = alpsampdelin; |
| 2280 |
|
| 2281 |
if (self->alp_in_count[j] == 0) |
| 2282 |
self->alpbuffer[j][self->alpsize] = alpsampdelin; |
| 2283 |
|
| 2284 |
self->alp_in_count[j]++; |
| 2285 |
|
| 2286 |
if (self->alp_in_count[j] == self->alpsize) |
| 2287 |
self->alp_in_count[j] = 0; |
| 2288 |
} |
| 2289 |
|
| 2290 |
/* DC filtering and output */ |
| 2291 |
y = val - self->xn1 + 0.995 * self->yn1; |
| 2292 |
self->xn1 = val; |
| 2293 |
self->data[i] = self->yn1 = y; |
| 2294 |
|
| 2295 |
/* write current value in the delay line */ |
| 2296 |
self->buffer[self->in_count] = in[i] + val * feed; |
| 2297 |
|
| 2298 |
if (self->in_count == 0) |
| 2299 |
self->buffer[self->size] = self->buffer[0]; |
| 2300 |
|
| 2301 |
self->in_count++; |
| 2302 |
|
| 2303 |
if (self->in_count == self->size) |
| 2304 |
self->in_count = 0; |
| 2305 |
} |
| 2306 |
} |
| 2307 |
|
| 2308 |
static void |
| 2309 |
AllpassWG_process_iaa(AllpassWG *self) |
| 2310 |
{ |
| 2311 |
int i, j; |
| 2312 |
long ind; |
| 2313 |
MYFLT val, y, xind, sampdel, frac, feed, detune, freqshift, alpsampdel, alpsampdelin, alpdetune; |
| 2314 |
|
| 2315 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 2316 |
MYFLT fr = PyFloat_AS_DOUBLE(self->freq); |
| 2317 |
MYFLT *fdb = Stream_getData((Stream *)self->feed_stream); |
| 2318 |
MYFLT *det = Stream_getData((Stream *)self->detune_stream); |
| 2319 |
|
| 2320 |
/* Check boundaries */ |
| 2321 |
if (fr < self->minfreq) |
| 2322 |
fr = self->minfreq; |
| 2323 |
else if (fr >= self->nyquist) |
| 2324 |
fr = self->nyquist; |
| 2325 |
|
| 2326 |
for (i = 0; i < self->bufsize; i++) |
| 2327 |
{ |
| 2328 |
feed = fdb[i] * 0.4525; |
| 2329 |
|
| 2330 |
if (feed > 0.4525) |
| 2331 |
feed = 0.4525; |
| 2332 |
else if (feed < 0) |
| 2333 |
feed = 0; |
| 2334 |
|
| 2335 |
detune = det[i]; |
| 2336 |
freqshift = detune * 0.5 + 1.; |
| 2337 |
detune = detune * 0.95 + 0.05; |
| 2338 |
|
| 2339 |
if (detune < 0.05) |
| 2340 |
detune = 0.05; |
| 2341 |
else if (detune > 1.0) |
| 2342 |
detune = 1.0; |
| 2343 |
|
| 2344 |
/* pick a new value in the delay line */ |
| 2345 |
sampdel = self->sr / (fr * freqshift); |
| 2346 |
xind = self->in_count - sampdel; |
| 2347 |
|
| 2348 |
if (xind < 0) |
| 2349 |
xind += self->size; |
| 2350 |
|
| 2351 |
ind = (long)xind; |
| 2352 |
frac = xind - ind; |
| 2353 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 2354 |
|
| 2355 |
/* all-pass filter */ |
| 2356 |
alpdetune = detune * self->alpsize; |
| 2357 |
|
| 2358 |
for (j = 0; j < 3; j++) |
| 2359 |
{ |
| 2360 |
xind = self->alp_in_count[j] - (alpdetune * alp_chorus_factor[j]); |
| 2361 |
|
| 2362 |
if (xind < 0) |
| 2363 |
xind += self->alpsize; |
| 2364 |
|
| 2365 |
ind = (long)xind; |
| 2366 |
frac = xind - ind; |
| 2367 |
alpsampdel = self->alpbuffer[j][ind] + (self->alpbuffer[j][ind + 1] - self->alpbuffer[j][ind]) * frac; |
| 2368 |
alpsampdelin = val + ((val - alpsampdel) * alp_feedback); |
| 2369 |
val = alpsampdelin * alp_feedback + alpsampdel; |
| 2370 |
/* write current allpass value in the allpass delay line */ |
| 2371 |
self->alpbuffer[j][self->alp_in_count[j]] = alpsampdelin; |
| 2372 |
|
| 2373 |
if (self->alp_in_count[j] == 0) |
| 2374 |
self->alpbuffer[j][self->alpsize] = alpsampdelin; |
| 2375 |
|
| 2376 |
self->alp_in_count[j]++; |
| 2377 |
|
| 2378 |
if (self->alp_in_count[j] == self->alpsize) |
| 2379 |
self->alp_in_count[j] = 0; |
| 2380 |
} |
| 2381 |
|
| 2382 |
/* DC filtering and output */ |
| 2383 |
y = val - self->xn1 + 0.995 * self->yn1; |
| 2384 |
self->xn1 = val; |
| 2385 |
self->data[i] = self->yn1 = y; |
| 2386 |
|
| 2387 |
/* write current value in the delay line */ |
| 2388 |
self->buffer[self->in_count] = in[i] + val * feed; |
| 2389 |
|
| 2390 |
if (self->in_count == 0) |
| 2391 |
self->buffer[self->size] = self->buffer[0]; |
| 2392 |
|
| 2393 |
self->in_count++; |
| 2394 |
|
| 2395 |
if (self->in_count == self->size) |
| 2396 |
self->in_count = 0; |
| 2397 |
} |
| 2398 |
} |
| 2399 |
|
| 2400 |
static void |
| 2401 |
AllpassWG_process_aaa(AllpassWG *self) |
| 2402 |
{ |
| 2403 |
int i, j; |
| 2404 |
long ind; |
| 2405 |
MYFLT val, y, xind, sampdel, frac, fr, feed, detune, freqshift, alpsampdel, alpsampdelin, alpdetune; |
| 2406 |
|
| 2407 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 2408 |
MYFLT *freq = Stream_getData((Stream *)self->freq_stream); |
| 2409 |
MYFLT *fdb = Stream_getData((Stream *)self->feed_stream); |
| 2410 |
MYFLT *det = Stream_getData((Stream *)self->detune_stream); |
| 2411 |
|
| 2412 |
for (i = 0; i < self->bufsize; i++) |
| 2413 |
{ |
| 2414 |
fr = freq[i]; |
| 2415 |
|
| 2416 |
if (fr < self->minfreq) |
| 2417 |
fr = self->minfreq; |
| 2418 |
else if (fr >= self->nyquist) |
| 2419 |
fr = self->nyquist; |
| 2420 |
|
| 2421 |
feed = fdb[i] * 0.4525; |
| 2422 |
|
| 2423 |
if (feed > 0.4525) |
| 2424 |
feed = 0.4525; |
| 2425 |
else if (feed < 0) |
| 2426 |
feed = 0; |
| 2427 |
|
| 2428 |
detune = det[i]; |
| 2429 |
freqshift = detune * 0.5 + 1.; |
| 2430 |
detune = detune * 0.95 + 0.05; |
| 2431 |
|
| 2432 |
if (detune < 0.05) |
| 2433 |
detune = 0.05; |
| 2434 |
else if (detune > 1.0) |
| 2435 |
detune = 1.0; |
| 2436 |
|
| 2437 |
/* pick a new value in the delay line */ |
| 2438 |
sampdel = self->sr / (fr * freqshift); |
| 2439 |
xind = self->in_count - sampdel; |
| 2440 |
|
| 2441 |
if (xind < 0) |
| 2442 |
xind += self->size; |
| 2443 |
|
| 2444 |
ind = (long)xind; |
| 2445 |
frac = xind - ind; |
| 2446 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 2447 |
|
| 2448 |
/* all-pass filter */ |
| 2449 |
alpdetune = detune * self->alpsize; |
| 2450 |
|
| 2451 |
for (j = 0; j < 3; j++) |
| 2452 |
{ |
| 2453 |
xind = self->alp_in_count[j] - (alpdetune * alp_chorus_factor[j]); |
| 2454 |
|
| 2455 |
if (xind < 0) |
| 2456 |
xind += self->alpsize; |
| 2457 |
|
| 2458 |
ind = (long)xind; |
| 2459 |
frac = xind - ind; |
| 2460 |
alpsampdel = self->alpbuffer[j][ind] + (self->alpbuffer[j][ind + 1] - self->alpbuffer[j][ind]) * frac; |
| 2461 |
alpsampdelin = val + ((val - alpsampdel) * alp_feedback); |
| 2462 |
val = alpsampdelin * alp_feedback + alpsampdel; |
| 2463 |
/* write current allpass value in the allpass delay line */ |
| 2464 |
self->alpbuffer[j][self->alp_in_count[j]] = alpsampdelin; |
| 2465 |
|
| 2466 |
if (self->alp_in_count[j] == 0) |
| 2467 |
self->alpbuffer[j][self->alpsize] = alpsampdelin; |
| 2468 |
|
| 2469 |
self->alp_in_count[j]++; |
| 2470 |
|
| 2471 |
if (self->alp_in_count[j] == self->alpsize) |
| 2472 |
self->alp_in_count[j] = 0; |
| 2473 |
} |
| 2474 |
|
| 2475 |
/* DC filtering and output */ |
| 2476 |
y = val - self->xn1 + 0.995 * self->yn1; |
| 2477 |
self->xn1 = val; |
| 2478 |
self->data[i] = self->yn1 = y; |
| 2479 |
|
| 2480 |
/* write current value in the delay line */ |
| 2481 |
self->buffer[self->in_count] = in[i] + val * feed; |
| 2482 |
|
| 2483 |
if (self->in_count == 0) |
| 2484 |
self->buffer[self->size] = self->buffer[0]; |
| 2485 |
|
| 2486 |
self->in_count++; |
| 2487 |
|
| 2488 |
if (self->in_count == self->size) |
| 2489 |
self->in_count = 0; |
| 2490 |
} |
| 2491 |
} |
| 2492 |
|
| 2493 |
static void AllpassWG_postprocessing_ii(AllpassWG *self) { POST_PROCESSING_II }; |
| 2494 |
static void AllpassWG_postprocessing_ai(AllpassWG *self) { POST_PROCESSING_AI }; |
| 2495 |
static void AllpassWG_postprocessing_ia(AllpassWG *self) { POST_PROCESSING_IA }; |
| 2496 |
static void AllpassWG_postprocessing_aa(AllpassWG *self) { POST_PROCESSING_AA }; |
| 2497 |
static void AllpassWG_postprocessing_ireva(AllpassWG *self) { POST_PROCESSING_IREVA }; |
| 2498 |
static void AllpassWG_postprocessing_areva(AllpassWG *self) { POST_PROCESSING_AREVA }; |
| 2499 |
static void AllpassWG_postprocessing_revai(AllpassWG *self) { POST_PROCESSING_REVAI }; |
| 2500 |
static void AllpassWG_postprocessing_revaa(AllpassWG *self) { POST_PROCESSING_REVAA }; |
| 2501 |
static void AllpassWG_postprocessing_revareva(AllpassWG *self) { POST_PROCESSING_REVAREVA }; |
| 2502 |
|
| 2503 |
static void |
| 2504 |
AllpassWG_setProcMode(AllpassWG *self) |
| 2505 |
{ |
| 2506 |
int procmode, muladdmode; |
| 2507 |
procmode = self->modebuffer[2] + self->modebuffer[3] * 10 + self->modebuffer[4] * 100; |
| 2508 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 2509 |
|
| 2510 |
switch (procmode) |
| 2511 |
{ |
| 2512 |
case 0: |
| 2513 |
self->proc_func_ptr = AllpassWG_process_iii; |
| 2514 |
break; |
| 2515 |
|
| 2516 |
case 1: |
| 2517 |
self->proc_func_ptr = AllpassWG_process_aii; |
| 2518 |
break; |
| 2519 |
|
| 2520 |
case 10: |
| 2521 |
self->proc_func_ptr = AllpassWG_process_iai; |
| 2522 |
break; |
| 2523 |
|
| 2524 |
case 11: |
| 2525 |
self->proc_func_ptr = AllpassWG_process_aai; |
| 2526 |
break; |
| 2527 |
|
| 2528 |
case 100: |
| 2529 |
self->proc_func_ptr = AllpassWG_process_iia; |
| 2530 |
break; |
| 2531 |
|
| 2532 |
case 101: |
| 2533 |
self->proc_func_ptr = AllpassWG_process_aia; |
| 2534 |
break; |
| 2535 |
|
| 2536 |
case 110: |
| 2537 |
self->proc_func_ptr = AllpassWG_process_iaa; |
| 2538 |
break; |
| 2539 |
|
| 2540 |
case 111: |
| 2541 |
self->proc_func_ptr = AllpassWG_process_aaa; |
| 2542 |
break; |
| 2543 |
} |
| 2544 |
|
| 2545 |
switch (muladdmode) |
| 2546 |
{ |
| 2547 |
case 0: |
| 2548 |
self->muladd_func_ptr = AllpassWG_postprocessing_ii; |
| 2549 |
break; |
| 2550 |
|
| 2551 |
case 1: |
| 2552 |
self->muladd_func_ptr = AllpassWG_postprocessing_ai; |
| 2553 |
break; |
| 2554 |
|
| 2555 |
case 2: |
| 2556 |
self->muladd_func_ptr = AllpassWG_postprocessing_revai; |
| 2557 |
break; |
| 2558 |
|
| 2559 |
case 10: |
| 2560 |
self->muladd_func_ptr = AllpassWG_postprocessing_ia; |
| 2561 |
break; |
| 2562 |
|
| 2563 |
case 11: |
| 2564 |
self->muladd_func_ptr = AllpassWG_postprocessing_aa; |
| 2565 |
break; |
| 2566 |
|
| 2567 |
case 12: |
| 2568 |
self->muladd_func_ptr = AllpassWG_postprocessing_revaa; |
| 2569 |
break; |
| 2570 |
|
| 2571 |
case 20: |
| 2572 |
self->muladd_func_ptr = AllpassWG_postprocessing_ireva; |
| 2573 |
break; |
| 2574 |
|
| 2575 |
case 21: |
| 2576 |
self->muladd_func_ptr = AllpassWG_postprocessing_areva; |
| 2577 |
break; |
| 2578 |
|
| 2579 |
case 22: |
| 2580 |
self->muladd_func_ptr = AllpassWG_postprocessing_revareva; |
| 2581 |
break; |
| 2582 |
} |
| 2583 |
} |
| 2584 |
|
| 2585 |
static void |
| 2586 |
AllpassWG_compute_next_data_frame(AllpassWG *self) |
| 2587 |
{ |
| 2588 |
(*self->proc_func_ptr)(self); |
| 2589 |
(*self->muladd_func_ptr)(self); |
| 2590 |
} |
| 2591 |
|
| 2592 |
static int |
| 2593 |
AllpassWG_traverse(AllpassWG *self, visitproc visit, void *arg) |
| 2594 |
{ |
| 2595 |
pyo_VISIT |
| 2596 |
Py_VISIT(self->input); |
| 2597 |
Py_VISIT(self->freq); |
| 2598 |
Py_VISIT(self->feed); |
| 2599 |
Py_VISIT(self->detune); |
| 2600 |
return 0; |
| 2601 |
} |
| 2602 |
|
| 2603 |
static int |
| 2604 |
AllpassWG_clear(AllpassWG *self) |
| 2605 |
{ |
| 2606 |
pyo_CLEAR |
| 2607 |
Py_CLEAR(self->input); |
| 2608 |
Py_CLEAR(self->freq); |
| 2609 |
Py_CLEAR(self->feed); |
| 2610 |
Py_CLEAR(self->detune); |
| 2611 |
return 0; |
| 2612 |
} |
| 2613 |
|
| 2614 |
static void |
| 2615 |
AllpassWG_dealloc(AllpassWG* self) |
| 2616 |
{ |
| 2617 |
int i; |
| 2618 |
pyo_DEALLOC |
| 2619 |
PyMem_RawFree(self->buffer); |
| 2620 |
|
| 2621 |
for (i = 0; i < 3; i++) |
| 2622 |
{ |
| 2623 |
PyMem_RawFree(self->alpbuffer[i]); |
| 2624 |
} |
| 2625 |
|
| 2626 |
AllpassWG_clear(self); |
| 2627 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 2628 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 2629 |
} |
| 2630 |
|
| 2631 |
static PyObject * |
| 2632 |
AllpassWG_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 2633 |
{ |
| 2634 |
int i, j; |
| 2635 |
PyObject *inputtmp, *input_streamtmp, *freqtmp = NULL, *feedtmp = NULL, *detunetmp = NULL, *multmp = NULL, *addtmp = NULL; |
| 2636 |
AllpassWG *self; |
| 2637 |
self = (AllpassWG *)type->tp_alloc(type, 0); |
| 2638 |
|
| 2639 |
self->freq = PyFloat_FromDouble(100); |
| 2640 |
self->feed = PyFloat_FromDouble(0.); |
| 2641 |
self->detune = PyFloat_FromDouble(0.5); |
| 2642 |
self->minfreq = 20; |
| 2643 |
self->in_count = self->alp_in_count[0] = self->alp_in_count[1] = self->alp_in_count[2] = 0; |
| 2644 |
self->xn1 = 0.0; |
| 2645 |
self->yn1 = 0.0; |
| 2646 |
self->modebuffer[0] = 0; |
| 2647 |
self->modebuffer[1] = 0; |
| 2648 |
self->modebuffer[2] = 0; |
| 2649 |
self->modebuffer[3] = 0; |
| 2650 |
self->modebuffer[4] = 0; |
| 2651 |
|
| 2652 |
INIT_OBJECT_COMMON |
| 2653 |
|
| 2654 |
self->nyquist = (MYFLT)self->sr * 0.45; |
| 2655 |
|
| 2656 |
Stream_setFunctionPtr(self->stream, AllpassWG_compute_next_data_frame); |
| 2657 |
self->mode_func_ptr = AllpassWG_setProcMode; |
| 2658 |
|
| 2659 |
static char *kwlist[] = {"input", "freq", "feed", "detune", "minfreq", "mul", "add", NULL}; |
| 2660 |
|
| 2661 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_O_OOOFOO, kwlist, &inputtmp, &freqtmp, &feedtmp, &detunetmp, &self->minfreq, &multmp, &addtmp)) |
| 2662 |
Py_RETURN_NONE; |
| 2663 |
|
| 2664 |
INIT_INPUT_STREAM |
| 2665 |
|
| 2666 |
if (freqtmp) |
| 2667 |
{ |
| 2668 |
PyObject_CallMethod((PyObject *)self, "setFreq", "O", freqtmp); |
| 2669 |
} |
| 2670 |
|
| 2671 |
if (feedtmp) |
| 2672 |
{ |
| 2673 |
PyObject_CallMethod((PyObject *)self, "setFeed", "O", feedtmp); |
| 2674 |
} |
| 2675 |
|
| 2676 |
if (detunetmp) |
| 2677 |
{ |
| 2678 |
PyObject_CallMethod((PyObject *)self, "setDetune", "O", detunetmp); |
| 2679 |
} |
| 2680 |
|
| 2681 |
if (multmp) |
| 2682 |
{ |
| 2683 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 2684 |
} |
| 2685 |
|
| 2686 |
if (addtmp) |
| 2687 |
{ |
| 2688 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 2689 |
} |
| 2690 |
|
| 2691 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 2692 |
|
| 2693 |
self->size = (long)(1.0 / self->minfreq * self->sr + 0.5); |
| 2694 |
self->buffer = (MYFLT *)PyMem_RawRealloc(self->buffer, (self->size + 1) * sizeof(MYFLT)); |
| 2695 |
|
| 2696 |
for (i = 0; i < (self->size + 1); i++) |
| 2697 |
{ |
| 2698 |
self->buffer[i] = 0.; |
| 2699 |
} |
| 2700 |
|
| 2701 |
self->alpsize = (int)(self->sr * 0.0025); |
| 2702 |
|
| 2703 |
for (i = 0; i < 3; i++) |
| 2704 |
{ |
| 2705 |
self->alpbuffer[i] = (MYFLT *)PyMem_RawRealloc(self->alpbuffer[i], (self->alpsize + 1) * sizeof(MYFLT)); |
| 2706 |
|
| 2707 |
for (j = 0; j < (self->alpsize + 1); j++) |
| 2708 |
{ |
| 2709 |
self->alpbuffer[i][j] = 0.; |
| 2710 |
} |
| 2711 |
} |
| 2712 |
|
| 2713 |
(*self->mode_func_ptr)(self); |
| 2714 |
|
| 2715 |
return (PyObject *)self; |
| 2716 |
} |
| 2717 |
|
| 2718 |
static PyObject * AllpassWG_getServer(AllpassWG* self) { GET_SERVER }; |
| 2719 |
static PyObject * AllpassWG_getStream(AllpassWG* self) { GET_STREAM }; |
| 2720 |
static PyObject * AllpassWG_setMul(AllpassWG *self, PyObject *arg) { SET_MUL }; |
| 2721 |
static PyObject * AllpassWG_setAdd(AllpassWG *self, PyObject *arg) { SET_ADD }; |
| 2722 |
static PyObject * AllpassWG_setSub(AllpassWG *self, PyObject *arg) { SET_SUB }; |
| 2723 |
static PyObject * AllpassWG_setDiv(AllpassWG *self, PyObject *arg) { SET_DIV }; |
| 2724 |
|
| 2725 |
static PyObject * AllpassWG_play(AllpassWG *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 2726 |
static PyObject * AllpassWG_out(AllpassWG *self, PyObject *args, PyObject *kwds) { OUT }; |
| 2727 |
static PyObject * AllpassWG_stop(AllpassWG *self, PyObject *args, PyObject *kwds) { STOP }; |
| 2728 |
|
| 2729 |
static PyObject * AllpassWG_multiply(AllpassWG *self, PyObject *arg) { MULTIPLY }; |
| 2730 |
static PyObject * AllpassWG_inplace_multiply(AllpassWG *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 2731 |
static PyObject * AllpassWG_add(AllpassWG *self, PyObject *arg) { ADD }; |
| 2732 |
static PyObject * AllpassWG_inplace_add(AllpassWG *self, PyObject *arg) { INPLACE_ADD }; |
| 2733 |
static PyObject * AllpassWG_sub(AllpassWG *self, PyObject *arg) { SUB }; |
| 2734 |
static PyObject * AllpassWG_inplace_sub(AllpassWG *self, PyObject *arg) { INPLACE_SUB }; |
| 2735 |
static PyObject * AllpassWG_div(AllpassWG *self, PyObject *arg) { DIV }; |
| 2736 |
static PyObject * AllpassWG_inplace_div(AllpassWG *self, PyObject *arg) { INPLACE_DIV }; |
| 2737 |
|
| 2738 |
static PyObject * |
| 2739 |
AllpassWG_reset(AllpassWG *self) |
| 2740 |
{ |
| 2741 |
int i, j; |
| 2742 |
|
| 2743 |
for (i = 0; i < (self->size + 1); i++) |
| 2744 |
{ |
| 2745 |
self->buffer[i] = 0.; |
| 2746 |
} |
| 2747 |
|
| 2748 |
for (i = 0; i < 3; i++) |
| 2749 |
{ |
| 2750 |
for (j = 0; j < (self->alpsize + 1); j++) |
| 2751 |
{ |
| 2752 |
self->alpbuffer[i][j] = 0.; |
| 2753 |
} |
| 2754 |
} |
| 2755 |
|
| 2756 |
self->in_count = self->alp_in_count[0] = self->alp_in_count[1] = self->alp_in_count[2] = 0; |
| 2757 |
self->xn1 = self->yn1 = 0.0; |
| 2758 |
|
| 2759 |
Py_RETURN_NONE; |
| 2760 |
} |
| 2761 |
|
| 2762 |
static PyObject * AllpassWG_setFreq(AllpassWG *self, PyObject *arg) { SET_PARAM(self->freq, self->freq_stream, 2); } |
| 2763 |
static PyObject * AllpassWG_setFeed(AllpassWG *self, PyObject *arg) { SET_PARAM(self->feed, self->feed_stream, 3); } |
| 2764 |
static PyObject * AllpassWG_setDetune(AllpassWG *self, PyObject *arg) { SET_PARAM(self->detune, self->detune_stream, 4); } |
| 2765 |
|
| 2766 |
static PyMemberDef AllpassWG_members[] = |
| 2767 |
{ |
| 2768 |
{"server", T_OBJECT_EX, offsetof(AllpassWG, server), 0, "Pyo server."}, |
| 2769 |
{"stream", T_OBJECT_EX, offsetof(AllpassWG, stream), 0, "Stream object."}, |
| 2770 |
{"input", T_OBJECT_EX, offsetof(AllpassWG, input), 0, "Input sound object."}, |
| 2771 |
{"freq", T_OBJECT_EX, offsetof(AllpassWG, freq), 0, "AllpassWG time in seconds."}, |
| 2772 |
{"feed", T_OBJECT_EX, offsetof(AllpassWG, feed), 0, "Feedback value."}, |
| 2773 |
{"detune", T_OBJECT_EX, offsetof(AllpassWG, detune), 0, "Detune value between 0 and 1."}, |
| 2774 |
{"mul", T_OBJECT_EX, offsetof(AllpassWG, mul), 0, "Mul factor."}, |
| 2775 |
{"add", T_OBJECT_EX, offsetof(AllpassWG, add), 0, "Add factor."}, |
| 2776 |
{NULL} /* Sentinel */ |
| 2777 |
}; |
| 2778 |
|
| 2779 |
static PyMethodDef AllpassWG_methods[] = |
| 2780 |
{ |
| 2781 |
{"getServer", (PyCFunction)AllpassWG_getServer, METH_NOARGS, "Returns server object."}, |
| 2782 |
{"_getStream", (PyCFunction)AllpassWG_getStream, METH_NOARGS, "Returns stream object."}, |
| 2783 |
{"play", (PyCFunction)AllpassWG_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 2784 |
{"out", (PyCFunction)AllpassWG_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."}, |
| 2785 |
{"stop", (PyCFunction)AllpassWG_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 2786 |
{"reset", (PyCFunction)AllpassWG_reset, METH_NOARGS, "Reset the delay line."}, |
| 2787 |
{"setFreq", (PyCFunction)AllpassWG_setFreq, METH_O, "Sets freq time in seconds."}, |
| 2788 |
{"setFeed", (PyCFunction)AllpassWG_setFeed, METH_O, "Sets feed value between 0 -> 1."}, |
| 2789 |
{"setDetune", (PyCFunction)AllpassWG_setDetune, METH_O, "Sets detune value between 0 -> 1."}, |
| 2790 |
{"setMul", (PyCFunction)AllpassWG_setMul, METH_O, "Sets oscillator mul factor."}, |
| 2791 |
{"setAdd", (PyCFunction)AllpassWG_setAdd, METH_O, "Sets oscillator add factor."}, |
| 2792 |
{"setSub", (PyCFunction)AllpassWG_setSub, METH_O, "Sets inverse add factor."}, |
| 2793 |
{"setDiv", (PyCFunction)AllpassWG_setDiv, METH_O, "Sets inverse mul factor."}, |
| 2794 |
{NULL} /* Sentinel */ |
| 2795 |
}; |
| 2796 |
|
| 2797 |
static PyNumberMethods AllpassWG_as_number = |
| 2798 |
{ |
| 2799 |
(binaryfunc)AllpassWG_add, /*nb_add*/ |
| 2800 |
(binaryfunc)AllpassWG_sub, /*nb_subtract*/ |
| 2801 |
(binaryfunc)AllpassWG_multiply, /*nb_multiply*/ |
| 2802 |
0, /*nb_remainder*/ |
| 2803 |
0, /*nb_divmod*/ |
| 2804 |
0, /*nb_power*/ |
| 2805 |
0, /*nb_neg*/ |
| 2806 |
0, /*nb_pos*/ |
| 2807 |
0, /*(unaryfunc)array_abs,*/ |
| 2808 |
0, /*nb_nonzero*/ |
| 2809 |
0, /*nb_invert*/ |
| 2810 |
0, /*nb_lshift*/ |
| 2811 |
0, /*nb_rshift*/ |
| 2812 |
0, /*nb_and*/ |
| 2813 |
0, /*nb_xor*/ |
| 2814 |
0, /*nb_or*/ |
| 2815 |
0, /*nb_int*/ |
| 2816 |
0, /*nb_long*/ |
| 2817 |
0, /*nb_float*/ |
| 2818 |
(binaryfunc)AllpassWG_inplace_add, /*inplace_add*/ |
| 2819 |
(binaryfunc)AllpassWG_inplace_sub, /*inplace_subtract*/ |
| 2820 |
(binaryfunc)AllpassWG_inplace_multiply, /*inplace_multiply*/ |
| 2821 |
0, /*inplace_remainder*/ |
| 2822 |
0, /*inplace_power*/ |
| 2823 |
0, /*inplace_lshift*/ |
| 2824 |
0, /*inplace_rshift*/ |
| 2825 |
0, /*inplace_and*/ |
| 2826 |
0, /*inplace_xor*/ |
| 2827 |
0, /*inplace_or*/ |
| 2828 |
0, /*nb_floor_divide*/ |
| 2829 |
(binaryfunc)AllpassWG_div, /*nb_true_divide*/ |
| 2830 |
0, /*nb_inplace_floor_divide*/ |
| 2831 |
(binaryfunc)AllpassWG_inplace_div, /*nb_inplace_true_divide*/ |
| 2832 |
0, /* nb_index */ |
| 2833 |
}; |
| 2834 |
|
| 2835 |
PyTypeObject AllpassWGType = |
| 2836 |
{ |
| 2837 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 2838 |
"_pyo.AllpassWG_base", /*tp_name*/ |
| 2839 |
sizeof(AllpassWG), /*tp_basicsize*/ |
| 2840 |
0, /*tp_itemsize*/ |
| 2841 |
(destructor)AllpassWG_dealloc, /*tp_dealloc*/ |
| 2842 |
0, /*tp_print*/ |
| 2843 |
0, /*tp_getattr*/ |
| 2844 |
0, /*tp_setattr*/ |
| 2845 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 2846 |
0, /*tp_repr*/ |
| 2847 |
&AllpassWG_as_number, /*tp_as_number*/ |
| 2848 |
0, /*tp_as_sequence*/ |
| 2849 |
0, /*tp_as_mapping*/ |
| 2850 |
0, /*tp_hash */ |
| 2851 |
0, /*tp_call*/ |
| 2852 |
0, /*tp_str*/ |
| 2853 |
0, /*tp_getattro*/ |
| 2854 |
0, /*tp_setattro*/ |
| 2855 |
0, /*tp_as_buffer*/ |
| 2856 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 2857 |
"AllpassWG objects. Waveguide model with builtin allpass circuit to detune resonance frequencies.", /* tp_doc */ |
| 2858 |
(traverseproc)AllpassWG_traverse, /* tp_traverse */ |
| 2859 |
(inquiry)AllpassWG_clear, /* tp_clear */ |
| 2860 |
0, /* tp_richcompare */ |
| 2861 |
0, /* tp_weaklistoffset */ |
| 2862 |
0, /* tp_iter */ |
| 2863 |
0, /* tp_iternext */ |
| 2864 |
AllpassWG_methods, /* tp_methods */ |
| 2865 |
AllpassWG_members, /* tp_members */ |
| 2866 |
0, /* tp_getset */ |
| 2867 |
0, /* tp_base */ |
| 2868 |
0, /* tp_dict */ |
| 2869 |
0, /* tp_descr_get */ |
| 2870 |
0, /* tp_descr_set */ |
| 2871 |
0, /* tp_dictoffset */ |
| 2872 |
0, /* tp_init */ |
| 2873 |
0, /* tp_alloc */ |
| 2874 |
AllpassWG_new, /* tp_new */ |
| 2875 |
}; |
| 2876 |
|
| 2877 |
/************/ |
| 2878 |
/* Delay1 */ |
| 2879 |
/************/ |
| 2880 |
typedef struct |
| 2881 |
{ |
| 2882 |
pyo_audio_HEAD |
| 2883 |
PyObject *input; |
| 2884 |
Stream *input_stream; |
| 2885 |
int modebuffer[2]; // need at least 2 slots for mul & add |
| 2886 |
MYFLT x1; |
| 2887 |
} Delay1; |
| 2888 |
|
| 2889 |
static void |
| 2890 |
Delay1_filters(Delay1 *self) |
| 2891 |
{ |
| 2892 |
int i; |
| 2893 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 2894 |
|
| 2895 |
for (i = 0; i < self->bufsize; i++) |
| 2896 |
{ |
| 2897 |
self->data[i] = self->x1; |
| 2898 |
self->x1 = in[i]; |
| 2899 |
} |
| 2900 |
} |
| 2901 |
|
| 2902 |
static void Delay1_postprocessing_ii(Delay1 *self) { POST_PROCESSING_II }; |
| 2903 |
static void Delay1_postprocessing_ai(Delay1 *self) { POST_PROCESSING_AI }; |
| 2904 |
static void Delay1_postprocessing_ia(Delay1 *self) { POST_PROCESSING_IA }; |
| 2905 |
static void Delay1_postprocessing_aa(Delay1 *self) { POST_PROCESSING_AA }; |
| 2906 |
static void Delay1_postprocessing_ireva(Delay1 *self) { POST_PROCESSING_IREVA }; |
| 2907 |
static void Delay1_postprocessing_areva(Delay1 *self) { POST_PROCESSING_AREVA }; |
| 2908 |
static void Delay1_postprocessing_revai(Delay1 *self) { POST_PROCESSING_REVAI }; |
| 2909 |
static void Delay1_postprocessing_revaa(Delay1 *self) { POST_PROCESSING_REVAA }; |
| 2910 |
static void Delay1_postprocessing_revareva(Delay1 *self) { POST_PROCESSING_REVAREVA }; |
| 2911 |
|
| 2912 |
static void |
| 2913 |
Delay1_setProcMode(Delay1 *self) |
| 2914 |
{ |
| 2915 |
int muladdmode; |
| 2916 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 2917 |
|
| 2918 |
self->proc_func_ptr = Delay1_filters; |
| 2919 |
|
| 2920 |
switch (muladdmode) |
| 2921 |
{ |
| 2922 |
case 0: |
| 2923 |
self->muladd_func_ptr = Delay1_postprocessing_ii; |
| 2924 |
break; |
| 2925 |
|
| 2926 |
case 1: |
| 2927 |
self->muladd_func_ptr = Delay1_postprocessing_ai; |
| 2928 |
break; |
| 2929 |
|
| 2930 |
case 2: |
| 2931 |
self->muladd_func_ptr = Delay1_postprocessing_revai; |
| 2932 |
break; |
| 2933 |
|
| 2934 |
case 10: |
| 2935 |
self->muladd_func_ptr = Delay1_postprocessing_ia; |
| 2936 |
break; |
| 2937 |
|
| 2938 |
case 11: |
| 2939 |
self->muladd_func_ptr = Delay1_postprocessing_aa; |
| 2940 |
break; |
| 2941 |
|
| 2942 |
case 12: |
| 2943 |
self->muladd_func_ptr = Delay1_postprocessing_revaa; |
| 2944 |
break; |
| 2945 |
|
| 2946 |
case 20: |
| 2947 |
self->muladd_func_ptr = Delay1_postprocessing_ireva; |
| 2948 |
break; |
| 2949 |
|
| 2950 |
case 21: |
| 2951 |
self->muladd_func_ptr = Delay1_postprocessing_areva; |
| 2952 |
break; |
| 2953 |
|
| 2954 |
case 22: |
| 2955 |
self->muladd_func_ptr = Delay1_postprocessing_revareva; |
| 2956 |
break; |
| 2957 |
} |
| 2958 |
} |
| 2959 |
|
| 2960 |
static void |
| 2961 |
Delay1_compute_next_data_frame(Delay1 *self) |
| 2962 |
{ |
| 2963 |
(*self->proc_func_ptr)(self); |
| 2964 |
(*self->muladd_func_ptr)(self); |
| 2965 |
} |
| 2966 |
|
| 2967 |
static int |
| 2968 |
Delay1_traverse(Delay1 *self, visitproc visit, void *arg) |
| 2969 |
{ |
| 2970 |
pyo_VISIT |
| 2971 |
Py_VISIT(self->input); |
| 2972 |
return 0; |
| 2973 |
} |
| 2974 |
|
| 2975 |
static int |
| 2976 |
Delay1_clear(Delay1 *self) |
| 2977 |
{ |
| 2978 |
pyo_CLEAR |
| 2979 |
Py_CLEAR(self->input); |
| 2980 |
return 0; |
| 2981 |
} |
| 2982 |
|
| 2983 |
static void |
| 2984 |
Delay1_dealloc(Delay1* self) |
| 2985 |
{ |
| 2986 |
pyo_DEALLOC |
| 2987 |
Delay1_clear(self); |
| 2988 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 2989 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 2990 |
} |
| 2991 |
|
| 2992 |
static PyObject * |
| 2993 |
Delay1_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 2994 |
{ |
| 2995 |
int i; |
| 2996 |
PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL; |
| 2997 |
Delay1 *self; |
| 2998 |
self = (Delay1 *)type->tp_alloc(type, 0); |
| 2999 |
|
| 3000 |
self->x1 = 0.0; |
| 3001 |
self->modebuffer[0] = 0; |
| 3002 |
self->modebuffer[1] = 0; |
| 3003 |
|
| 3004 |
INIT_OBJECT_COMMON |
| 3005 |
Stream_setFunctionPtr(self->stream, Delay1_compute_next_data_frame); |
| 3006 |
self->mode_func_ptr = Delay1_setProcMode; |
| 3007 |
|
| 3008 |
static char *kwlist[] = {"input", "mul", "add", NULL}; |
| 3009 |
|
| 3010 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &inputtmp, &multmp, &addtmp)) |
| 3011 |
Py_RETURN_NONE; |
| 3012 |
|
| 3013 |
INIT_INPUT_STREAM |
| 3014 |
|
| 3015 |
if (multmp) |
| 3016 |
{ |
| 3017 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 3018 |
} |
| 3019 |
|
| 3020 |
if (addtmp) |
| 3021 |
{ |
| 3022 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 3023 |
} |
| 3024 |
|
| 3025 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 3026 |
|
| 3027 |
(*self->mode_func_ptr)(self); |
| 3028 |
|
| 3029 |
return (PyObject *)self; |
| 3030 |
} |
| 3031 |
|
| 3032 |
static PyObject * Delay1_getServer(Delay1* self) { GET_SERVER }; |
| 3033 |
static PyObject * Delay1_getStream(Delay1* self) { GET_STREAM }; |
| 3034 |
static PyObject * Delay1_setMul(Delay1 *self, PyObject *arg) { SET_MUL }; |
| 3035 |
static PyObject * Delay1_setAdd(Delay1 *self, PyObject *arg) { SET_ADD }; |
| 3036 |
static PyObject * Delay1_setSub(Delay1 *self, PyObject *arg) { SET_SUB }; |
| 3037 |
static PyObject * Delay1_setDiv(Delay1 *self, PyObject *arg) { SET_DIV }; |
| 3038 |
|
| 3039 |
static PyObject * Delay1_play(Delay1 *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 3040 |
static PyObject * Delay1_out(Delay1 *self, PyObject *args, PyObject *kwds) { OUT }; |
| 3041 |
static PyObject * Delay1_stop(Delay1 *self, PyObject *args, PyObject *kwds) { STOP }; |
| 3042 |
|
| 3043 |
static PyObject * Delay1_multiply(Delay1 *self, PyObject *arg) { MULTIPLY }; |
| 3044 |
static PyObject * Delay1_inplace_multiply(Delay1 *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 3045 |
static PyObject * Delay1_add(Delay1 *self, PyObject *arg) { ADD }; |
| 3046 |
static PyObject * Delay1_inplace_add(Delay1 *self, PyObject *arg) { INPLACE_ADD }; |
| 3047 |
static PyObject * Delay1_sub(Delay1 *self, PyObject *arg) { SUB }; |
| 3048 |
static PyObject * Delay1_inplace_sub(Delay1 *self, PyObject *arg) { INPLACE_SUB }; |
| 3049 |
static PyObject * Delay1_div(Delay1 *self, PyObject *arg) { DIV }; |
| 3050 |
static PyObject * Delay1_inplace_div(Delay1 *self, PyObject *arg) { INPLACE_DIV }; |
| 3051 |
|
| 3052 |
static PyMemberDef Delay1_members[] = |
| 3053 |
{ |
| 3054 |
{"server", T_OBJECT_EX, offsetof(Delay1, server), 0, "Pyo server."}, |
| 3055 |
{"stream", T_OBJECT_EX, offsetof(Delay1, stream), 0, "Stream object."}, |
| 3056 |
{"input", T_OBJECT_EX, offsetof(Delay1, input), 0, "Input sound object."}, |
| 3057 |
{"mul", T_OBJECT_EX, offsetof(Delay1, mul), 0, "Mul factor."}, |
| 3058 |
{"add", T_OBJECT_EX, offsetof(Delay1, add), 0, "Add factor."}, |
| 3059 |
{NULL} /* Sentinel */ |
| 3060 |
}; |
| 3061 |
|
| 3062 |
static PyMethodDef Delay1_methods[] = |
| 3063 |
{ |
| 3064 |
{"getServer", (PyCFunction)Delay1_getServer, METH_NOARGS, "Returns server object."}, |
| 3065 |
{"_getStream", (PyCFunction)Delay1_getStream, METH_NOARGS, "Returns stream object."}, |
| 3066 |
{"play", (PyCFunction)Delay1_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 3067 |
{"out", (PyCFunction)Delay1_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."}, |
| 3068 |
{"stop", (PyCFunction)Delay1_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 3069 |
{"setMul", (PyCFunction)Delay1_setMul, METH_O, "Sets oscillator mul factor."}, |
| 3070 |
{"setAdd", (PyCFunction)Delay1_setAdd, METH_O, "Sets oscillator add factor."}, |
| 3071 |
{"setSub", (PyCFunction)Delay1_setSub, METH_O, "Sets inverse add factor."}, |
| 3072 |
{"setDiv", (PyCFunction)Delay1_setDiv, METH_O, "Sets inverse mul factor."}, |
| 3073 |
{NULL} /* Sentinel */ |
| 3074 |
}; |
| 3075 |
|
| 3076 |
static PyNumberMethods Delay1_as_number = |
| 3077 |
{ |
| 3078 |
(binaryfunc)Delay1_add, /*nb_add*/ |
| 3079 |
(binaryfunc)Delay1_sub, /*nb_subtract*/ |
| 3080 |
(binaryfunc)Delay1_multiply, /*nb_multiply*/ |
| 3081 |
0, /*nb_remainder*/ |
| 3082 |
0, /*nb_divmod*/ |
| 3083 |
0, /*nb_power*/ |
| 3084 |
0, /*nb_neg*/ |
| 3085 |
0, /*nb_pos*/ |
| 3086 |
0, /*(unaryfunc)array_abs,*/ |
| 3087 |
0, /*nb_nonzero*/ |
| 3088 |
0, /*nb_invert*/ |
| 3089 |
0, /*nb_lshift*/ |
| 3090 |
0, /*nb_rshift*/ |
| 3091 |
0, /*nb_and*/ |
| 3092 |
0, /*nb_xor*/ |
| 3093 |
0, /*nb_or*/ |
| 3094 |
0, /*nb_int*/ |
| 3095 |
0, /*nb_long*/ |
| 3096 |
0, /*nb_float*/ |
| 3097 |
(binaryfunc)Delay1_inplace_add, /*inplace_add*/ |
| 3098 |
(binaryfunc)Delay1_inplace_sub, /*inplace_subtract*/ |
| 3099 |
(binaryfunc)Delay1_inplace_multiply, /*inplace_multiply*/ |
| 3100 |
0, /*inplace_remainder*/ |
| 3101 |
0, /*inplace_power*/ |
| 3102 |
0, /*inplace_lshift*/ |
| 3103 |
0, /*inplace_rshift*/ |
| 3104 |
0, /*inplace_and*/ |
| 3105 |
0, /*inplace_xor*/ |
| 3106 |
0, /*inplace_or*/ |
| 3107 |
0, /*nb_floor_divide*/ |
| 3108 |
(binaryfunc)Delay1_div, /*nb_true_divide*/ |
| 3109 |
0, /*nb_inplace_floor_divide*/ |
| 3110 |
(binaryfunc)Delay1_inplace_div, /*nb_inplace_true_divide*/ |
| 3111 |
0, /* nb_index */ |
| 3112 |
}; |
| 3113 |
|
| 3114 |
PyTypeObject Delay1Type = |
| 3115 |
{ |
| 3116 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 3117 |
"_pyo.Delay1_base", /*tp_name*/ |
| 3118 |
sizeof(Delay1), /*tp_basicsize*/ |
| 3119 |
0, /*tp_itemsize*/ |
| 3120 |
(destructor)Delay1_dealloc, /*tp_dealloc*/ |
| 3121 |
0, /*tp_print*/ |
| 3122 |
0, /*tp_getattr*/ |
| 3123 |
0, /*tp_setattr*/ |
| 3124 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 3125 |
0, /*tp_repr*/ |
| 3126 |
&Delay1_as_number, /*tp_as_number*/ |
| 3127 |
0, /*tp_as_sequence*/ |
| 3128 |
0, /*tp_as_mapping*/ |
| 3129 |
0, /*tp_hash */ |
| 3130 |
0, /*tp_call*/ |
| 3131 |
0, /*tp_str*/ |
| 3132 |
0, /*tp_getattro*/ |
| 3133 |
0, /*tp_setattro*/ |
| 3134 |
0, /*tp_as_buffer*/ |
| 3135 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 3136 |
"Delay1 objects. Delays a signal by one sample.", /* tp_doc */ |
| 3137 |
(traverseproc)Delay1_traverse, /* tp_traverse */ |
| 3138 |
(inquiry)Delay1_clear, /* tp_clear */ |
| 3139 |
0, /* tp_richcompare */ |
| 3140 |
0, /* tp_weaklistoffset */ |
| 3141 |
0, /* tp_iter */ |
| 3142 |
0, /* tp_iternext */ |
| 3143 |
Delay1_methods, /* tp_methods */ |
| 3144 |
Delay1_members, /* tp_members */ |
| 3145 |
0, /* tp_getset */ |
| 3146 |
0, /* tp_base */ |
| 3147 |
0, /* tp_dict */ |
| 3148 |
0, /* tp_descr_get */ |
| 3149 |
0, /* tp_descr_set */ |
| 3150 |
0, /* tp_dictoffset */ |
| 3151 |
0, /* tp_init */ |
| 3152 |
0, /* tp_alloc */ |
| 3153 |
Delay1_new, /* tp_new */ |
| 3154 |
}; |
| 3155 |
|
| 3156 |
typedef struct |
| 3157 |
{ |
| 3158 |
pyo_audio_HEAD |
| 3159 |
PyObject *input; |
| 3160 |
Stream *input_stream; |
| 3161 |
PyObject *delay; |
| 3162 |
Stream *delay_stream; |
| 3163 |
PyObject *feedback; |
| 3164 |
Stream *feedback_stream; |
| 3165 |
MYFLT crossfade; |
| 3166 |
MYFLT maxdelay; |
| 3167 |
MYFLT oneOverSr; |
| 3168 |
MYFLT amp1; |
| 3169 |
MYFLT amp2; |
| 3170 |
MYFLT inc1; |
| 3171 |
MYFLT inc2; |
| 3172 |
int current; |
| 3173 |
long timer; |
| 3174 |
long size; |
| 3175 |
long in_count; |
| 3176 |
long sampdel; |
| 3177 |
MYFLT sampdel1; |
| 3178 |
MYFLT sampdel2; |
| 3179 |
int modebuffer[4]; |
| 3180 |
MYFLT *buffer; // samples memory |
| 3181 |
} SmoothDelay; |
| 3182 |
|
| 3183 |
static void |
| 3184 |
SmoothDelay_process_ii(SmoothDelay *self) |
| 3185 |
{ |
| 3186 |
MYFLT val, xind, frac, sum; |
| 3187 |
int i; |
| 3188 |
long ind, xsamps = 0; |
| 3189 |
|
| 3190 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 3191 |
MYFLT del = PyFloat_AS_DOUBLE(self->delay); |
| 3192 |
MYFLT feed = PyFloat_AS_DOUBLE(self->feedback); |
| 3193 |
|
| 3194 |
if (del < self->oneOverSr) del = self->oneOverSr; |
| 3195 |
else if (del > self->maxdelay) del = self->maxdelay; |
| 3196 |
|
| 3197 |
if (feed < 0) feed = 0.0; |
| 3198 |
else if (feed > 1) feed = 1.0; |
| 3199 |
|
| 3200 |
for (i = 0; i < self->bufsize; i++) |
| 3201 |
{ |
| 3202 |
if (self->timer == 0) |
| 3203 |
{ |
| 3204 |
self->current = (self->current + 1) % 2; |
| 3205 |
self->sampdel = (long)(del * self->sr + 0.5); |
| 3206 |
xsamps = (long)(self->crossfade * self->sr + 0.5); |
| 3207 |
|
| 3208 |
if (xsamps > self->sampdel) xsamps = self->sampdel; |
| 3209 |
|
| 3210 |
if (xsamps <= 0) xsamps = 1; |
| 3211 |
|
| 3212 |
if (self->current == 0) |
| 3213 |
{ |
| 3214 |
self->sampdel1 = del * self->sr; |
| 3215 |
self->inc1 = 1.0 / xsamps; |
| 3216 |
self->inc2 = -self->inc1; |
| 3217 |
} |
| 3218 |
else |
| 3219 |
{ |
| 3220 |
self->sampdel2 = del * self->sr; |
| 3221 |
self->inc2 = 1.0 / xsamps; |
| 3222 |
self->inc1 = -self->inc2; |
| 3223 |
} |
| 3224 |
} |
| 3225 |
|
| 3226 |
xind = self->in_count - self->sampdel1; |
| 3227 |
|
| 3228 |
while (xind < 0) |
| 3229 |
xind += self->size; |
| 3230 |
|
| 3231 |
if (xind == self->size) |
| 3232 |
xind = 0; |
| 3233 |
|
| 3234 |
ind = (long)xind; |
| 3235 |
frac = xind - ind; |
| 3236 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 3237 |
sum = val * self->amp1; |
| 3238 |
self->amp1 += self->inc1; |
| 3239 |
|
| 3240 |
if (self->amp1 < 0) self->amp1 = 0.0; |
| 3241 |
else if (self->amp1 > 1) self->amp1 = 1.0; |
| 3242 |
|
| 3243 |
xind = self->in_count - self->sampdel2; |
| 3244 |
|
| 3245 |
while (xind < 0) |
| 3246 |
xind += self->size; |
| 3247 |
|
| 3248 |
if (xind == self->size) |
| 3249 |
xind = 0; |
| 3250 |
|
| 3251 |
ind = (long)xind; |
| 3252 |
frac = xind - ind; |
| 3253 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 3254 |
sum += val * self->amp2; |
| 3255 |
self->amp2 += self->inc2; |
| 3256 |
|
| 3257 |
if (self->amp2 < 0) self->amp2 = 0.0; |
| 3258 |
else if (self->amp2 > 1) self->amp2 = 1.0; |
| 3259 |
|
| 3260 |
self->data[i] = sum; |
| 3261 |
|
| 3262 |
self->buffer[self->in_count] = in[i] + (sum * feed); |
| 3263 |
|
| 3264 |
if (self->in_count == 0) |
| 3265 |
self->buffer[self->size] = self->buffer[0]; |
| 3266 |
|
| 3267 |
self->in_count++; |
| 3268 |
|
| 3269 |
if (self->in_count >= self->size) |
| 3270 |
self->in_count = 0; |
| 3271 |
|
| 3272 |
self->timer++; |
| 3273 |
|
| 3274 |
if (self->timer == self->sampdel) |
| 3275 |
self->timer = 0; |
| 3276 |
} |
| 3277 |
} |
| 3278 |
|
| 3279 |
static void |
| 3280 |
SmoothDelay_process_ai(SmoothDelay *self) |
| 3281 |
{ |
| 3282 |
MYFLT val, xind, frac, sum, del; |
| 3283 |
int i; |
| 3284 |
long ind, xsamps = 0; |
| 3285 |
|
| 3286 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 3287 |
MYFLT *dl = Stream_getData((Stream *)self->delay_stream); |
| 3288 |
MYFLT feed = PyFloat_AS_DOUBLE(self->feedback); |
| 3289 |
|
| 3290 |
if (feed < 0) feed = 0.0; |
| 3291 |
else if (feed > 1) feed = 1.0; |
| 3292 |
|
| 3293 |
for (i = 0; i < self->bufsize; i++) |
| 3294 |
{ |
| 3295 |
if (self->timer == 0) |
| 3296 |
{ |
| 3297 |
del = dl[i]; |
| 3298 |
|
| 3299 |
if (del < self->oneOverSr) del = self->oneOverSr; |
| 3300 |
else if (del > self->maxdelay) del = self->maxdelay; |
| 3301 |
|
| 3302 |
self->current = (self->current + 1) % 2; |
| 3303 |
self->sampdel = (long)(del * self->sr + 0.5); |
| 3304 |
xsamps = (long)(self->crossfade * self->sr + 0.5); |
| 3305 |
|
| 3306 |
if (xsamps > self->sampdel) xsamps = self->sampdel; |
| 3307 |
|
| 3308 |
if (xsamps <= 0) xsamps = 1; |
| 3309 |
|
| 3310 |
if (self->current == 0) |
| 3311 |
{ |
| 3312 |
self->sampdel1 = del * self->sr; |
| 3313 |
self->inc1 = 1.0 / xsamps; |
| 3314 |
self->inc2 = -self->inc1; |
| 3315 |
} |
| 3316 |
else |
| 3317 |
{ |
| 3318 |
self->sampdel2 = del * self->sr; |
| 3319 |
self->inc2 = 1.0 / xsamps; |
| 3320 |
self->inc1 = -self->inc2; |
| 3321 |
} |
| 3322 |
} |
| 3323 |
|
| 3324 |
xind = self->in_count - self->sampdel1; |
| 3325 |
|
| 3326 |
while (xind < 0) |
| 3327 |
xind += self->size; |
| 3328 |
|
| 3329 |
if (xind == self->size) |
| 3330 |
xind = 0; |
| 3331 |
|
| 3332 |
ind = (long)xind; |
| 3333 |
frac = xind - ind; |
| 3334 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 3335 |
sum = val * self->amp1; |
| 3336 |
self->amp1 += self->inc1; |
| 3337 |
|
| 3338 |
if (self->amp1 < 0) self->amp1 = 0.0; |
| 3339 |
else if (self->amp1 > 1) self->amp1 = 1.0; |
| 3340 |
|
| 3341 |
xind = self->in_count - self->sampdel2; |
| 3342 |
|
| 3343 |
while (xind < 0) |
| 3344 |
xind += self->size; |
| 3345 |
|
| 3346 |
if (xind == self->size) |
| 3347 |
xind = 0; |
| 3348 |
|
| 3349 |
ind = (long)xind; |
| 3350 |
frac = xind - ind; |
| 3351 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 3352 |
sum += val * self->amp2; |
| 3353 |
self->amp2 += self->inc2; |
| 3354 |
|
| 3355 |
if (self->amp2 < 0) self->amp2 = 0.0; |
| 3356 |
else if (self->amp2 > 1) self->amp2 = 1.0; |
| 3357 |
|
| 3358 |
self->data[i] = sum; |
| 3359 |
|
| 3360 |
self->buffer[self->in_count] = in[i] + (sum * feed); |
| 3361 |
|
| 3362 |
if (self->in_count == 0) |
| 3363 |
self->buffer[self->size] = self->buffer[0]; |
| 3364 |
|
| 3365 |
self->in_count++; |
| 3366 |
|
| 3367 |
if (self->in_count >= self->size) |
| 3368 |
self->in_count = 0; |
| 3369 |
|
| 3370 |
self->timer++; |
| 3371 |
|
| 3372 |
if (self->timer == self->sampdel) |
| 3373 |
self->timer = 0; |
| 3374 |
} |
| 3375 |
} |
| 3376 |
|
| 3377 |
static void |
| 3378 |
SmoothDelay_process_ia(SmoothDelay *self) |
| 3379 |
{ |
| 3380 |
MYFLT val, xind, frac, sum, feed; |
| 3381 |
int i; |
| 3382 |
long ind, xsamps = 0; |
| 3383 |
|
| 3384 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 3385 |
MYFLT del = PyFloat_AS_DOUBLE(self->delay); |
| 3386 |
MYFLT *fd = Stream_getData((Stream *)self->feedback_stream); |
| 3387 |
|
| 3388 |
if (del < self->oneOverSr) del = self->oneOverSr; |
| 3389 |
else if (del > self->maxdelay) del = self->maxdelay; |
| 3390 |
|
| 3391 |
for (i = 0; i < self->bufsize; i++) |
| 3392 |
{ |
| 3393 |
feed = fd[i]; |
| 3394 |
|
| 3395 |
if (feed < 0) feed = 0.0; |
| 3396 |
else if (feed > 1) feed = 1.0; |
| 3397 |
|
| 3398 |
if (self->timer == 0) |
| 3399 |
{ |
| 3400 |
self->current = (self->current + 1) % 2; |
| 3401 |
self->sampdel = (long)(del * self->sr + 0.5); |
| 3402 |
xsamps = (long)(self->crossfade * self->sr + 0.5); |
| 3403 |
|
| 3404 |
if (xsamps > self->sampdel) xsamps = self->sampdel; |
| 3405 |
|
| 3406 |
if (xsamps <= 0) xsamps = 1; |
| 3407 |
|
| 3408 |
if (self->current == 0) |
| 3409 |
{ |
| 3410 |
self->sampdel1 = del * self->sr; |
| 3411 |
self->inc1 = 1.0 / xsamps; |
| 3412 |
self->inc2 = -self->inc1; |
| 3413 |
} |
| 3414 |
else |
| 3415 |
{ |
| 3416 |
self->sampdel2 = del * self->sr; |
| 3417 |
self->inc2 = 1.0 / xsamps; |
| 3418 |
self->inc1 = -self->inc2; |
| 3419 |
} |
| 3420 |
} |
| 3421 |
|
| 3422 |
xind = self->in_count - self->sampdel1; |
| 3423 |
|
| 3424 |
while (xind < 0) |
| 3425 |
xind += self->size; |
| 3426 |
|
| 3427 |
if (xind == self->size) |
| 3428 |
xind = 0; |
| 3429 |
|
| 3430 |
ind = (long)xind; |
| 3431 |
frac = xind - ind; |
| 3432 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 3433 |
sum = val * self->amp1; |
| 3434 |
self->amp1 += self->inc1; |
| 3435 |
|
| 3436 |
if (self->amp1 < 0) self->amp1 = 0.0; |
| 3437 |
else if (self->amp1 > 1) self->amp1 = 1.0; |
| 3438 |
|
| 3439 |
xind = self->in_count - self->sampdel2; |
| 3440 |
|
| 3441 |
while (xind < 0) |
| 3442 |
xind += self->size; |
| 3443 |
|
| 3444 |
if (xind == self->size) |
| 3445 |
xind = 0; |
| 3446 |
|
| 3447 |
ind = (long)xind; |
| 3448 |
frac = xind - ind; |
| 3449 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 3450 |
sum += val * self->amp2; |
| 3451 |
self->amp2 += self->inc2; |
| 3452 |
|
| 3453 |
if (self->amp2 < 0) self->amp2 = 0.0; |
| 3454 |
else if (self->amp2 > 1) self->amp2 = 1.0; |
| 3455 |
|
| 3456 |
self->data[i] = sum; |
| 3457 |
|
| 3458 |
self->buffer[self->in_count] = in[i] + (sum * feed); |
| 3459 |
|
| 3460 |
if (self->in_count == 0) |
| 3461 |
self->buffer[self->size] = self->buffer[0]; |
| 3462 |
|
| 3463 |
self->in_count++; |
| 3464 |
|
| 3465 |
if (self->in_count >= self->size) |
| 3466 |
self->in_count = 0; |
| 3467 |
|
| 3468 |
self->timer++; |
| 3469 |
|
| 3470 |
if (self->timer == self->sampdel) |
| 3471 |
self->timer = 0; |
| 3472 |
} |
| 3473 |
} |
| 3474 |
|
| 3475 |
static void |
| 3476 |
SmoothDelay_process_aa(SmoothDelay *self) |
| 3477 |
{ |
| 3478 |
MYFLT val, xind, frac, sum, del, feed; |
| 3479 |
int i; |
| 3480 |
long ind, xsamps = 0; |
| 3481 |
|
| 3482 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 3483 |
MYFLT *dl = Stream_getData((Stream *)self->delay_stream); |
| 3484 |
MYFLT *fd = Stream_getData((Stream *)self->feedback_stream); |
| 3485 |
|
| 3486 |
for (i = 0; i < self->bufsize; i++) |
| 3487 |
{ |
| 3488 |
feed = fd[i]; |
| 3489 |
|
| 3490 |
if (feed < 0) feed = 0.0; |
| 3491 |
else if (feed > 1) feed = 1.0; |
| 3492 |
|
| 3493 |
if (self->timer == 0) |
| 3494 |
{ |
| 3495 |
del = dl[i]; |
| 3496 |
|
| 3497 |
if (del < self->oneOverSr) del = self->oneOverSr; |
| 3498 |
else if (del > self->maxdelay) del = self->maxdelay; |
| 3499 |
|
| 3500 |
self->current = (self->current + 1) % 2; |
| 3501 |
self->sampdel = (long)(del * self->sr + 0.5); |
| 3502 |
xsamps = (long)(self->crossfade * self->sr + 0.5); |
| 3503 |
|
| 3504 |
if (xsamps > self->sampdel) xsamps = self->sampdel; |
| 3505 |
|
| 3506 |
if (xsamps <= 0) xsamps = 1; |
| 3507 |
|
| 3508 |
if (self->current == 0) |
| 3509 |
{ |
| 3510 |
self->sampdel1 = del * self->sr; |
| 3511 |
self->inc1 = 1.0 / xsamps; |
| 3512 |
self->inc2 = -self->inc1; |
| 3513 |
} |
| 3514 |
else |
| 3515 |
{ |
| 3516 |
self->sampdel2 = del * self->sr; |
| 3517 |
self->inc2 = 1.0 / xsamps; |
| 3518 |
self->inc1 = -self->inc2; |
| 3519 |
} |
| 3520 |
} |
| 3521 |
|
| 3522 |
xind = self->in_count - self->sampdel1; |
| 3523 |
|
| 3524 |
while (xind < 0) |
| 3525 |
xind += self->size; |
| 3526 |
|
| 3527 |
if (xind == self->size) |
| 3528 |
xind = 0; |
| 3529 |
|
| 3530 |
ind = (long)xind; |
| 3531 |
frac = xind - ind; |
| 3532 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 3533 |
sum = val * self->amp1; |
| 3534 |
self->amp1 += self->inc1; |
| 3535 |
|
| 3536 |
if (self->amp1 < 0) self->amp1 = 0.0; |
| 3537 |
else if (self->amp1 > 1) self->amp1 = 1.0; |
| 3538 |
|
| 3539 |
xind = self->in_count - self->sampdel2; |
| 3540 |
|
| 3541 |
while (xind < 0) |
| 3542 |
xind += self->size; |
| 3543 |
|
| 3544 |
if (xind == self->size) |
| 3545 |
xind = 0; |
| 3546 |
|
| 3547 |
ind = (long)xind; |
| 3548 |
frac = xind - ind; |
| 3549 |
val = self->buffer[ind] + (self->buffer[ind + 1] - self->buffer[ind]) * frac; |
| 3550 |
sum += val * self->amp2; |
| 3551 |
self->amp2 += self->inc2; |
| 3552 |
|
| 3553 |
if (self->amp2 < 0) self->amp2 = 0.0; |
| 3554 |
else if (self->amp2 > 1) self->amp2 = 1.0; |
| 3555 |
|
| 3556 |
self->data[i] = sum; |
| 3557 |
|
| 3558 |
self->buffer[self->in_count] = in[i] + (sum * feed); |
| 3559 |
|
| 3560 |
if (self->in_count == 0) |
| 3561 |
self->buffer[self->size] = self->buffer[0]; |
| 3562 |
|
| 3563 |
self->in_count++; |
| 3564 |
|
| 3565 |
if (self->in_count >= self->size) |
| 3566 |
self->in_count = 0; |
| 3567 |
|
| 3568 |
self->timer++; |
| 3569 |
|
| 3570 |
if (self->timer == self->sampdel) |
| 3571 |
self->timer = 0; |
| 3572 |
} |
| 3573 |
} |
| 3574 |
|
| 3575 |
static void SmoothDelay_postprocessing_ii(SmoothDelay *self) { POST_PROCESSING_II }; |
| 3576 |
static void SmoothDelay_postprocessing_ai(SmoothDelay *self) { POST_PROCESSING_AI }; |
| 3577 |
static void SmoothDelay_postprocessing_ia(SmoothDelay *self) { POST_PROCESSING_IA }; |
| 3578 |
static void SmoothDelay_postprocessing_aa(SmoothDelay *self) { POST_PROCESSING_AA }; |
| 3579 |
static void SmoothDelay_postprocessing_ireva(SmoothDelay *self) { POST_PROCESSING_IREVA }; |
| 3580 |
static void SmoothDelay_postprocessing_areva(SmoothDelay *self) { POST_PROCESSING_AREVA }; |
| 3581 |
static void SmoothDelay_postprocessing_revai(SmoothDelay *self) { POST_PROCESSING_REVAI }; |
| 3582 |
static void SmoothDelay_postprocessing_revaa(SmoothDelay *self) { POST_PROCESSING_REVAA }; |
| 3583 |
static void SmoothDelay_postprocessing_revareva(SmoothDelay *self) { POST_PROCESSING_REVAREVA }; |
| 3584 |
|
| 3585 |
static void |
| 3586 |
SmoothDelay_setProcMode(SmoothDelay *self) |
| 3587 |
{ |
| 3588 |
int procmode, muladdmode; |
| 3589 |
procmode = self->modebuffer[2] + self->modebuffer[3] * 10; |
| 3590 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 3591 |
|
| 3592 |
switch (procmode) |
| 3593 |
{ |
| 3594 |
case 0: |
| 3595 |
self->proc_func_ptr = SmoothDelay_process_ii; |
| 3596 |
break; |
| 3597 |
|
| 3598 |
case 1: |
| 3599 |
self->proc_func_ptr = SmoothDelay_process_ai; |
| 3600 |
break; |
| 3601 |
|
| 3602 |
case 10: |
| 3603 |
self->proc_func_ptr = SmoothDelay_process_ia; |
| 3604 |
break; |
| 3605 |
|
| 3606 |
case 11: |
| 3607 |
self->proc_func_ptr = SmoothDelay_process_aa; |
| 3608 |
break; |
| 3609 |
} |
| 3610 |
|
| 3611 |
switch (muladdmode) |
| 3612 |
{ |
| 3613 |
case 0: |
| 3614 |
self->muladd_func_ptr = SmoothDelay_postprocessing_ii; |
| 3615 |
break; |
| 3616 |
|
| 3617 |
case 1: |
| 3618 |
self->muladd_func_ptr = SmoothDelay_postprocessing_ai; |
| 3619 |
break; |
| 3620 |
|
| 3621 |
case 2: |
| 3622 |
self->muladd_func_ptr = SmoothDelay_postprocessing_revai; |
| 3623 |
break; |
| 3624 |
|
| 3625 |
case 10: |
| 3626 |
self->muladd_func_ptr = SmoothDelay_postprocessing_ia; |
| 3627 |
break; |
| 3628 |
|
| 3629 |
case 11: |
| 3630 |
self->muladd_func_ptr = SmoothDelay_postprocessing_aa; |
| 3631 |
break; |
| 3632 |
|
| 3633 |
case 12: |
| 3634 |
self->muladd_func_ptr = SmoothDelay_postprocessing_revaa; |
| 3635 |
break; |
| 3636 |
|
| 3637 |
case 20: |
| 3638 |
self->muladd_func_ptr = SmoothDelay_postprocessing_ireva; |
| 3639 |
break; |
| 3640 |
|
| 3641 |
case 21: |
| 3642 |
self->muladd_func_ptr = SmoothDelay_postprocessing_areva; |
| 3643 |
break; |
| 3644 |
|
| 3645 |
case 22: |
| 3646 |
self->muladd_func_ptr = SmoothDelay_postprocessing_revareva; |
| 3647 |
break; |
| 3648 |
} |
| 3649 |
} |
| 3650 |
|
| 3651 |
static void |
| 3652 |
SmoothDelay_compute_next_data_frame(SmoothDelay *self) |
| 3653 |
{ |
| 3654 |
(*self->proc_func_ptr)(self); |
| 3655 |
(*self->muladd_func_ptr)(self); |
| 3656 |
} |
| 3657 |
|
| 3658 |
static int |
| 3659 |
SmoothDelay_traverse(SmoothDelay *self, visitproc visit, void *arg) |
| 3660 |
{ |
| 3661 |
pyo_VISIT |
| 3662 |
Py_VISIT(self->input); |
| 3663 |
Py_VISIT(self->delay); |
| 3664 |
Py_VISIT(self->feedback); |
| 3665 |
return 0; |
| 3666 |
} |
| 3667 |
|
| 3668 |
static int |
| 3669 |
SmoothDelay_clear(SmoothDelay *self) |
| 3670 |
{ |
| 3671 |
pyo_CLEAR |
| 3672 |
Py_CLEAR(self->input); |
| 3673 |
Py_CLEAR(self->delay); |
| 3674 |
Py_CLEAR(self->feedback); |
| 3675 |
return 0; |
| 3676 |
} |
| 3677 |
|
| 3678 |
static void |
| 3679 |
SmoothDelay_dealloc(SmoothDelay* self) |
| 3680 |
{ |
| 3681 |
pyo_DEALLOC |
| 3682 |
PyMem_RawFree(self->buffer); |
| 3683 |
SmoothDelay_clear(self); |
| 3684 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 3685 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 3686 |
} |
| 3687 |
|
| 3688 |
static PyObject * |
| 3689 |
SmoothDelay_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 3690 |
{ |
| 3691 |
int i; |
| 3692 |
PyObject *inputtmp, *input_streamtmp, *delaytmp = NULL, *feedbacktmp = NULL, *multmp = NULL, *addtmp = NULL; |
| 3693 |
SmoothDelay *self; |
| 3694 |
self = (SmoothDelay *)type->tp_alloc(type, 0); |
| 3695 |
|
| 3696 |
self->delay = PyFloat_FromDouble(0.25); |
| 3697 |
self->feedback = PyFloat_FromDouble(0); |
| 3698 |
self->crossfade = 0.05; |
| 3699 |
self->maxdelay = 1; |
| 3700 |
self->in_count = 0; |
| 3701 |
self->current = 1; |
| 3702 |
self->timer = 0; |
| 3703 |
self->amp1 = 0.0; |
| 3704 |
self->amp2 = 1.0; |
| 3705 |
self->inc1 = self->inc2 = 0.0; |
| 3706 |
self->modebuffer[0] = 0; |
| 3707 |
self->modebuffer[1] = 0; |
| 3708 |
self->modebuffer[2] = 0; |
| 3709 |
self->modebuffer[3] = 0; |
| 3710 |
|
| 3711 |
INIT_OBJECT_COMMON |
| 3712 |
|
| 3713 |
self->oneOverSr = self->sampdel1 = self->sampdel2 = 1.0 / self->sr; |
| 3714 |
|
| 3715 |
Stream_setFunctionPtr(self->stream, SmoothDelay_compute_next_data_frame); |
| 3716 |
self->mode_func_ptr = SmoothDelay_setProcMode; |
| 3717 |
|
| 3718 |
static char *kwlist[] = {"input", "delay", "feedback", "crossfade", "maxdelay", "mul", "add", NULL}; |
| 3719 |
|
| 3720 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_O_OOFFOO, kwlist, &inputtmp, &delaytmp, &feedbacktmp, &self->crossfade, &self->maxdelay, &multmp, &addtmp)) |
| 3721 |
Py_RETURN_NONE; |
| 3722 |
|
| 3723 |
INIT_INPUT_STREAM |
| 3724 |
|
| 3725 |
if (delaytmp) |
| 3726 |
{ |
| 3727 |
PyObject_CallMethod((PyObject *)self, "setDelay", "O", delaytmp); |
| 3728 |
} |
| 3729 |
|
| 3730 |
if (feedbacktmp) |
| 3731 |
{ |
| 3732 |
PyObject_CallMethod((PyObject *)self, "setFeedback", "O", feedbacktmp); |
| 3733 |
} |
| 3734 |
|
| 3735 |
if (multmp) |
| 3736 |
{ |
| 3737 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 3738 |
} |
| 3739 |
|
| 3740 |
if (addtmp) |
| 3741 |
{ |
| 3742 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 3743 |
} |
| 3744 |
|
| 3745 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 3746 |
|
| 3747 |
self->size = (long)(self->maxdelay * self->sr + 0.5); |
| 3748 |
|
| 3749 |
self->buffer = (MYFLT *)PyMem_RawRealloc(self->buffer, (self->size + 1) * sizeof(MYFLT)); |
| 3750 |
|
| 3751 |
for (i = 0; i < (self->size + 1); i++) |
| 3752 |
{ |
| 3753 |
self->buffer[i] = 0.; |
| 3754 |
} |
| 3755 |
|
| 3756 |
(*self->mode_func_ptr)(self); |
| 3757 |
|
| 3758 |
return (PyObject *)self; |
| 3759 |
} |
| 3760 |
|
| 3761 |
static PyObject * SmoothDelay_getServer(SmoothDelay* self) { GET_SERVER }; |
| 3762 |
static PyObject * SmoothDelay_getStream(SmoothDelay* self) { GET_STREAM }; |
| 3763 |
static PyObject * SmoothDelay_setMul(SmoothDelay *self, PyObject *arg) { SET_MUL }; |
| 3764 |
static PyObject * SmoothDelay_setAdd(SmoothDelay *self, PyObject *arg) { SET_ADD }; |
| 3765 |
static PyObject * SmoothDelay_setSub(SmoothDelay *self, PyObject *arg) { SET_SUB }; |
| 3766 |
static PyObject * SmoothDelay_setDiv(SmoothDelay *self, PyObject *arg) { SET_DIV }; |
| 3767 |
|
| 3768 |
static PyObject * SmoothDelay_play(SmoothDelay *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 3769 |
static PyObject * SmoothDelay_out(SmoothDelay *self, PyObject *args, PyObject *kwds) { OUT }; |
| 3770 |
static PyObject * SmoothDelay_stop(SmoothDelay *self, PyObject *args, PyObject *kwds) { STOP }; |
| 3771 |
|
| 3772 |
static PyObject * SmoothDelay_multiply(SmoothDelay *self, PyObject *arg) { MULTIPLY }; |
| 3773 |
static PyObject * SmoothDelay_inplace_multiply(SmoothDelay *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 3774 |
static PyObject * SmoothDelay_add(SmoothDelay *self, PyObject *arg) { ADD }; |
| 3775 |
static PyObject * SmoothDelay_inplace_add(SmoothDelay *self, PyObject *arg) { INPLACE_ADD }; |
| 3776 |
static PyObject * SmoothDelay_sub(SmoothDelay *self, PyObject *arg) { SUB }; |
| 3777 |
static PyObject * SmoothDelay_inplace_sub(SmoothDelay *self, PyObject *arg) { INPLACE_SUB }; |
| 3778 |
static PyObject * SmoothDelay_div(SmoothDelay *self, PyObject *arg) { DIV }; |
| 3779 |
static PyObject * SmoothDelay_inplace_div(SmoothDelay *self, PyObject *arg) { INPLACE_DIV }; |
| 3780 |
|
| 3781 |
static PyObject * SmoothDelay_setDelay(SmoothDelay *self, PyObject *arg) { SET_PARAM(self->delay, self->delay_stream, 2); } |
| 3782 |
static PyObject * SmoothDelay_setFeedback(SmoothDelay *self, PyObject *arg) { SET_PARAM(self->feedback, self->feedback_stream, 3); } |
| 3783 |
|
| 3784 |
static PyObject * |
| 3785 |
SmoothDelay_setCrossfade(SmoothDelay *self, PyObject *arg) |
| 3786 |
{ |
| 3787 |
ASSERT_ARG_NOT_NULL |
| 3788 |
|
| 3789 |
if (PyNumber_Check(arg)) |
| 3790 |
{ |
| 3791 |
self->crossfade = PyFloat_AsDouble(arg); |
| 3792 |
} |
| 3793 |
|
| 3794 |
Py_RETURN_NONE; |
| 3795 |
} |
| 3796 |
|
| 3797 |
static PyObject * |
| 3798 |
SmoothDelay_reset(SmoothDelay *self) |
| 3799 |
{ |
| 3800 |
int i; |
| 3801 |
|
| 3802 |
for (i = 0; i < (self->size + 1); i++) |
| 3803 |
{ |
| 3804 |
self->buffer[i] = 0.; |
| 3805 |
} |
| 3806 |
|
| 3807 |
Py_RETURN_NONE; |
| 3808 |
} |
| 3809 |
|
| 3810 |
static PyMemberDef SmoothDelay_members[] = |
| 3811 |
{ |
| 3812 |
{"server", T_OBJECT_EX, offsetof(SmoothDelay, server), 0, "Pyo server."}, |
| 3813 |
{"stream", T_OBJECT_EX, offsetof(SmoothDelay, stream), 0, "Stream object."}, |
| 3814 |
{"input", T_OBJECT_EX, offsetof(SmoothDelay, input), 0, "Input sound object."}, |
| 3815 |
{"delay", T_OBJECT_EX, offsetof(SmoothDelay, delay), 0, "SmoothDelay time in seconds."}, |
| 3816 |
{"feedback", T_OBJECT_EX, offsetof(SmoothDelay, feedback), 0, "Feedback value."}, |
| 3817 |
{"mul", T_OBJECT_EX, offsetof(SmoothDelay, mul), 0, "Mul factor."}, |
| 3818 |
{"add", T_OBJECT_EX, offsetof(SmoothDelay, add), 0, "Add factor."}, |
| 3819 |
{NULL} /* Sentinel */ |
| 3820 |
}; |
| 3821 |
|
| 3822 |
static PyMethodDef SmoothDelay_methods[] = |
| 3823 |
{ |
| 3824 |
{"getServer", (PyCFunction)SmoothDelay_getServer, METH_NOARGS, "Returns server object."}, |
| 3825 |
{"_getStream", (PyCFunction)SmoothDelay_getStream, METH_NOARGS, "Returns stream object."}, |
| 3826 |
{"play", (PyCFunction)SmoothDelay_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 3827 |
{"out", (PyCFunction)SmoothDelay_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."}, |
| 3828 |
{"stop", (PyCFunction)SmoothDelay_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 3829 |
{"setDelay", (PyCFunction)SmoothDelay_setDelay, METH_O, "Sets delay time in seconds."}, |
| 3830 |
{"setFeedback", (PyCFunction)SmoothDelay_setFeedback, METH_O, "Sets feedback value between 0 -> 1."}, |
| 3831 |
{"setCrossfade", (PyCFunction)SmoothDelay_setCrossfade, METH_O, "Sets crossfade time."}, |
| 3832 |
{"reset", (PyCFunction)SmoothDelay_reset, METH_NOARGS, "Resets the memory buffer to zeros."}, |
| 3833 |
{"setMul", (PyCFunction)SmoothDelay_setMul, METH_O, "Sets oscillator mul factor."}, |
| 3834 |
{"setAdd", (PyCFunction)SmoothDelay_setAdd, METH_O, "Sets oscillator add factor."}, |
| 3835 |
{"setSub", (PyCFunction)SmoothDelay_setSub, METH_O, "Sets inverse add factor."}, |
| 3836 |
{"setDiv", (PyCFunction)SmoothDelay_setDiv, METH_O, "Sets inverse mul factor."}, |
| 3837 |
{NULL} /* Sentinel */ |
| 3838 |
}; |
| 3839 |
|
| 3840 |
static PyNumberMethods SmoothDelay_as_number = |
| 3841 |
{ |
| 3842 |
(binaryfunc)SmoothDelay_add, /*nb_add*/ |
| 3843 |
(binaryfunc)SmoothDelay_sub, /*nb_subtract*/ |
| 3844 |
(binaryfunc)SmoothDelay_multiply, /*nb_multiply*/ |
| 3845 |
0, /*nb_remainder*/ |
| 3846 |
0, /*nb_divmod*/ |
| 3847 |
0, /*nb_power*/ |
| 3848 |
0, /*nb_neg*/ |
| 3849 |
0, /*nb_pos*/ |
| 3850 |
0, /*(unaryfunc)array_abs,*/ |
| 3851 |
0, /*nb_nonzero*/ |
| 3852 |
0, /*nb_invert*/ |
| 3853 |
0, /*nb_lshift*/ |
| 3854 |
0, /*nb_rshift*/ |
| 3855 |
0, /*nb_and*/ |
| 3856 |
0, /*nb_xor*/ |
| 3857 |
0, /*nb_or*/ |
| 3858 |
0, /*nb_int*/ |
| 3859 |
0, /*nb_long*/ |
| 3860 |
0, /*nb_float*/ |
| 3861 |
(binaryfunc)SmoothDelay_inplace_add, /*inplace_add*/ |
| 3862 |
(binaryfunc)SmoothDelay_inplace_sub, /*inplace_subtract*/ |
| 3863 |
(binaryfunc)SmoothDelay_inplace_multiply, /*inplace_multiply*/ |
| 3864 |
0, /*inplace_remainder*/ |
| 3865 |
0, /*inplace_power*/ |
| 3866 |
0, /*inplace_lshift*/ |
| 3867 |
0, /*inplace_rshift*/ |
| 3868 |
0, /*inplace_and*/ |
| 3869 |
0, /*inplace_xor*/ |
| 3870 |
0, /*inplace_or*/ |
| 3871 |
0, /*nb_floor_divide*/ |
| 3872 |
(binaryfunc)SmoothDelay_div, /*nb_true_divide*/ |
| 3873 |
0, /*nb_inplace_floor_divide*/ |
| 3874 |
(binaryfunc)SmoothDelay_inplace_div, /*nb_inplace_true_divide*/ |
| 3875 |
0, /* nb_index */ |
| 3876 |
}; |
| 3877 |
|
| 3878 |
PyTypeObject SmoothDelayType = |
| 3879 |
{ |
| 3880 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 3881 |
"_pyo.SmoothDelay_base", /*tp_name*/ |
| 3882 |
sizeof(SmoothDelay), /*tp_basicsize*/ |
| 3883 |
0, /*tp_itemsize*/ |
| 3884 |
(destructor)SmoothDelay_dealloc, /*tp_dealloc*/ |
| 3885 |
0, /*tp_print*/ |
| 3886 |
0, /*tp_getattr*/ |
| 3887 |
0, /*tp_setattr*/ |
| 3888 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 3889 |
0, /*tp_repr*/ |
| 3890 |
&SmoothDelay_as_number, /*tp_as_number*/ |
| 3891 |
0, /*tp_as_sequence*/ |
| 3892 |
0, /*tp_as_mapping*/ |
| 3893 |
0, /*tp_hash */ |
| 3894 |
0, /*tp_call*/ |
| 3895 |
0, /*tp_str*/ |
| 3896 |
0, /*tp_getattro*/ |
| 3897 |
0, /*tp_setattro*/ |
| 3898 |
0, /*tp_as_buffer*/ |
| 3899 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 3900 |
"SmoothDelay objects. Delay signal by x samples.", /* tp_doc */ |
| 3901 |
(traverseproc)SmoothDelay_traverse, /* tp_traverse */ |
| 3902 |
(inquiry)SmoothDelay_clear, /* tp_clear */ |
| 3903 |
0, /* tp_richcompare */ |
| 3904 |
0, /* tp_weaklistoffset */ |
| 3905 |
0, /* tp_iter */ |
| 3906 |
0, /* tp_iternext */ |
| 3907 |
SmoothDelay_methods, /* tp_methods */ |
| 3908 |
SmoothDelay_members, /* tp_members */ |
| 3909 |
0, /* tp_getset */ |
| 3910 |
0, /* tp_base */ |
| 3911 |
0, /* tp_dict */ |
| 3912 |
0, /* tp_descr_get */ |
| 3913 |
0, /* tp_descr_set */ |
| 3914 |
0, /* tp_dictoffset */ |
| 3915 |
0, /* tp_init */ |
| 3916 |
0, /* tp_alloc */ |
| 3917 |
SmoothDelay_new, /* tp_new */ |
| 3918 |
}; |