From f1100a49500036d9d901ce7869ce92f5c806dde3 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Thu, 23 Jan 2014 22:17:18 -0300 Subject: [PATCH] ext/py-sink.c: do not generate --- python/ext/aubio-types.h | 1 + python/ext/aubiomodule.c | 3 ++ python/ext/py-sink.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++ python/lib/generator.py | 1 + python/setup.py | 1 + 5 files changed, 103 insertions(+) create mode 100644 python/ext/py-sink.c diff --git a/python/ext/aubio-types.h b/python/ext/aubio-types.h index 57a18412..64af89b7 100644 --- a/python/ext/aubio-types.h +++ b/python/ext/aubio-types.h @@ -70,3 +70,4 @@ extern PyTypeObject Py_pvocType; extern PyTypeObject Py_sourceType; +extern PyTypeObject Py_sinkType; diff --git a/python/ext/aubiomodule.c b/python/ext/aubiomodule.c index 29610697..ca8f88f5 100644 --- a/python/ext/aubiomodule.c +++ b/python/ext/aubiomodule.c @@ -199,6 +199,7 @@ init_aubio (void) || (PyType_Ready (&Py_fftType) < 0) || (PyType_Ready (&Py_pvocType) < 0) || (PyType_Ready (&Py_sourceType) < 0) + || (PyType_Ready (&Py_sinkType) < 0) // generated objects || (generated_types_ready() < 0 ) ) { @@ -229,6 +230,8 @@ init_aubio (void) PyModule_AddObject (m, "pvoc", (PyObject *) & Py_pvocType); Py_INCREF (&Py_sourceType); PyModule_AddObject (m, "source", (PyObject *) & Py_sourceType); + Py_INCREF (&Py_sinkType); + PyModule_AddObject (m, "sink", (PyObject *) & Py_sinkType); // add generated objects add_generated_objects(m); diff --git a/python/ext/py-sink.c b/python/ext/py-sink.c new file mode 100644 index 00000000..59a2cc18 --- /dev/null +++ b/python/ext/py-sink.c @@ -0,0 +1,97 @@ +#include "aubiowraphell.h" + +typedef struct +{ + PyObject_HEAD + aubio_sink_t * o; + char_t* uri; + uint_t samplerate; +} Py_sink; + +static char Py_sink_doc[] = "sink object"; + +static PyObject * +Py_sink_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds) +{ + Py_sink *self; + char_t* uri = NULL; + uint_t samplerate = 0; + static char *kwlist[] = { "uri", "samplerate", NULL }; + + if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sI", kwlist, + &uri, &samplerate)) { + return NULL; + } + + self = (Py_sink *) pytype->tp_alloc (pytype, 0); + + if (self == NULL) { + return NULL; + } + + self->uri = "none"; + if (uri != NULL) { + self->uri = uri; + } + + self->samplerate = Py_aubio_default_samplerate; + if ((sint_t)samplerate > 0) { + self->samplerate = samplerate; + } else if ((sint_t)samplerate < 0) { + PyErr_SetString (PyExc_ValueError, + "can not use negative value for samplerate"); + return NULL; + } + + return (PyObject *) self; +} + +AUBIO_INIT(sink , self->uri, self->samplerate) + +AUBIO_DEL(sink) + +/* function Py_sink_do */ +static PyObject * +Py_sink_do(Py_sink * self, PyObject * args) +{ + /* input vectors python prototypes */ + PyObject * write_data_obj; + + /* input vectors prototypes */ + fvec_t* write_data; + uint_t write; + + + if (!PyArg_ParseTuple (args, "OI", &write_data_obj, &write)) { + return NULL; + } + + + /* input vectors parsing */ + write_data = PyAubio_ArrayToCFvec (write_data_obj); + + if (write_data == NULL) { + return NULL; + } + + + + + + /* compute _do function */ + aubio_sink_do (self->o, write_data, write); + + Py_RETURN_NONE; +} + +AUBIO_MEMBERS_START(sink) + {"uri", T_STRING, offsetof (Py_sink, uri), READONLY, ""}, + {"samplerate", T_INT, offsetof (Py_sink, samplerate), READONLY, ""}, +AUBIO_MEMBERS_STOP(sink) + + +static PyMethodDef Py_sink_methods[] = { + {NULL} /* sentinel */ +}; + +AUBIO_TYPEOBJECT(sink, "aubio.sink") diff --git a/python/lib/generator.py b/python/lib/generator.py index b13abd6b..867aeae1 100755 --- a/python/lib/generator.py +++ b/python/lib/generator.py @@ -54,6 +54,7 @@ def generate_object_files(output_path): 'pitchspecacf', 'pitchyin', 'pitchyinfft', + 'sink', 'sink_apple_audio', 'sink_sndfile', 'source', diff --git a/python/setup.py b/python/setup.py index 44380afb..fe4927a0 100755 --- a/python/setup.py +++ b/python/setup.py @@ -54,6 +54,7 @@ aubio_extension = Extension("aubio._aubio", [ "ext/py-fft.c", "ext/py-phasevoc.c", "ext/py-source.c", + "ext/py-sink.c", # generated files ] + generated_object_files, include_dirs = include_dirs, -- 2.11.0