Showing the changes to python (5 of 5 files). Show all
Unified · Split
| @@ -70,3 +70,4 @@ extern PyTypeObject Py_pvocType; · 69 unmodified lines | |||
| 70 | 70 | ||
| 71 | extern PyTypeObject Py_sourceType; | 71 | extern PyTypeObject Py_sourceType; |
| 72 | 72 | ||
| 73 | extern PyTypeObject Py_sinkType; | ||
| @@ -199,6 +199,7 @@ init_aubio (void) · 198 unmodified lines | |||
| 199 | || (PyType_Ready (&Py_fftType) < 0) | 199 | || (PyType_Ready (&Py_fftType) < 0) |
| 200 | || (PyType_Ready (&Py_pvocType) < 0) | 200 | || (PyType_Ready (&Py_pvocType) < 0) |
| 201 | || (PyType_Ready (&Py_sourceType) < 0) | 201 | || (PyType_Ready (&Py_sourceType) < 0) |
| 202 | || (PyType_Ready (&Py_sinkType) < 0) | ||
| 202 | // generated objects | 203 | // generated objects |
| 203 | || (generated_types_ready() < 0 ) | 204 | || (generated_types_ready() < 0 ) |
| 204 | ) { | 205 | ) { |
| @@ -229,6 +230,8 @@ init_aubio (void) · 24 unmodified lines | |||
| 229 | PyModule_AddObject (m, "pvoc", (PyObject *) & Py_pvocType); | 230 | PyModule_AddObject (m, "pvoc", (PyObject *) & Py_pvocType); |
| 230 | Py_INCREF (&Py_sourceType); | 231 | Py_INCREF (&Py_sourceType); |
| 231 | PyModule_AddObject (m, "source", (PyObject *) & Py_sourceType); | 232 | PyModule_AddObject (m, "source", (PyObject *) & Py_sourceType); |
| 233 | Py_INCREF (&Py_sinkType); | ||
| 234 | PyModule_AddObject (m, "sink", (PyObject *) & Py_sinkType); | ||
| 232 | 235 | ||
| 233 | // add generated objects | 236 | // add generated objects |
| 234 | add_generated_objects(m); | 237 | add_generated_objects(m); |
| @@ -0,0 +1,97 @@ | |||
| 1 | #include "aubiowraphell.h" | ||
| 2 | |||
| 3 | typedef struct | ||
| 4 | { | ||
| 5 | PyObject_HEAD | ||
| 6 | aubio_sink_t * o; | ||
| 7 | char_t* uri; | ||
| 8 | uint_t samplerate; | ||
| 9 | } Py_sink; | ||
| 10 | |||
| 11 | static char Py_sink_doc[] = "sink object"; | ||
| 12 | |||
| 13 | static PyObject * | ||
| 14 | Py_sink_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds) | ||
| 15 | { | ||
| 16 | Py_sink *self; | ||
| 17 | char_t* uri = NULL; | ||
| 18 | uint_t samplerate = 0; | ||
| 19 | static char *kwlist[] = { "uri", "samplerate", NULL }; | ||
| 20 | |||
| 21 | if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sI", kwlist, | ||
| 22 | &uri, &samplerate)) { | ||
| 23 | return NULL; | ||
| 24 | } | ||
| 25 | |||
| 26 | self = (Py_sink *) pytype->tp_alloc (pytype, 0); | ||
| 27 | |||
| 28 | if (self == NULL) { | ||
| 29 | return NULL; | ||
| 30 | } | ||
| 31 | |||
| 32 | self->uri = "none"; | ||
| 33 | if (uri != NULL) { | ||
| 34 | self->uri = uri; | ||
| 35 | } | ||
| 36 | |||
| 37 | self->samplerate = Py_aubio_default_samplerate; | ||
| 38 | if ((sint_t)samplerate > 0) { | ||
| 39 | self->samplerate = samplerate; | ||
| 40 | } else if ((sint_t)samplerate < 0) { | ||
| 41 | PyErr_SetString (PyExc_ValueError, | ||
| 42 | "can not use negative value for samplerate"); | ||
| 43 | return NULL; | ||
| 44 | } | ||
| 45 | |||
| 46 | return (PyObject *) self; | ||
| 47 | } | ||
| 48 | |||
| 49 | AUBIO_INIT(sink , self->uri, self->samplerate) | ||
| 50 | |||
| 51 | AUBIO_DEL(sink) | ||
| 52 | |||
| 53 | /* function Py_sink_do */ | ||
| 54 | static PyObject * | ||
| 55 | Py_sink_do(Py_sink * self, PyObject * args) | ||
| 56 | { | ||
| 57 | /* input vectors python prototypes */ | ||
| 58 | PyObject * write_data_obj; | ||
| 59 | |||
| 60 | /* input vectors prototypes */ | ||
| 61 | fvec_t* write_data; | ||
| 62 | uint_t write; | ||
| 63 | |||
| 64 | |||
| 65 | if (!PyArg_ParseTuple (args, "OI", &write_data_obj, &write)) { | ||
| 66 | return NULL; | ||
| 67 | } | ||
| 68 | |||
| 69 | |||
| 70 | /* input vectors parsing */ | ||
| 71 | write_data = PyAubio_ArrayToCFvec (write_data_obj); | ||
| 72 | |||
| 73 | if (write_data == NULL) { | ||
| 74 | return NULL; | ||
| 75 | } | ||
| 76 | |||
| 77 | |||
| 78 | |||
| 79 | |||
| 80 | |||
| 81 | /* compute _do function */ | ||
| 82 | aubio_sink_do (self->o, write_data, write); | ||
| 83 | |||
| 84 | Py_RETURN_NONE; | ||
| 85 | } | ||
| 86 | |||
| 87 | AUBIO_MEMBERS_START(sink) | ||
| 88 | {"uri", T_STRING, offsetof (Py_sink, uri), READONLY, ""}, | ||
| 89 | {"samplerate", T_INT, offsetof (Py_sink, samplerate), READONLY, ""}, | ||
| 90 | AUBIO_MEMBERS_STOP(sink) | ||
| 91 | |||
| 92 | |||
| 93 | static PyMethodDef Py_sink_methods[] = { | ||
| 94 | {NULL} /* sentinel */ | ||
| 95 | }; | ||
| 96 | |||
| 97 | AUBIO_TYPEOBJECT(sink, "aubio.sink") | ||
| @@ -54,6 +54,7 @@ def generate_object_files(output_path): · 53 unmodified lines | |||
| 54 | 'pitchspecacf', | 54 | 'pitchspecacf', |
| 55 | 'pitchyin', | 55 | 'pitchyin', |
| 56 | 'pitchyinfft', | 56 | 'pitchyinfft', |
| 57 | 'sink', | ||
| 57 | 'sink_apple_audio', | 58 | 'sink_apple_audio', |
| 58 | 'sink_sndfile', | 59 | 'sink_sndfile', |
| 59 | 'source', | 60 | 'source', |
| @@ -54,6 +54,7 @@ aubio_extension = Extension("aubio._aubio", [ · 53 unmodified lines | |||
| 54 | "ext/py-fft.c", | 54 | "ext/py-fft.c", |
| 55 | "ext/py-phasevoc.c", | 55 | "ext/py-phasevoc.c", |
| 56 | "ext/py-source.c", | 56 | "ext/py-source.c", |
| 57 | "ext/py-sink.c", | ||
| 57 | # generated files | 58 | # generated files |
| 58 | ] + generated_object_files, | 59 | ] + generated_object_files, |
| 59 | include_dirs = include_dirs, | 60 | include_dirs = include_dirs, |