ref: d27634db13fcc48b84ec2dd08018af7c105e9cba
parent: d7019c4b9e1f91be81d7fb740b5ba989a570e972
author: Paul Brossier <[email protected]>
date: Tue Dec 10 11:13:49 EST 2013
python/ext/py-source.c: not generated, modified init to get samplerate from aubio_source_t Signed-off-by: Paul Brossier <[email protected]>
--- a/python/ext/aubio-types.h
+++ b/python/ext/aubio-types.h
@@ -30,7 +30,7 @@
#define Py_default_vector_length 1024
-#define Py_aubio_default_samplerate 44100
+#define Py_aubio_default_samplerate 0
#if HAVE_AUBIO_DOUBLE
#error "Ouch! Python interface for aubio has not been much tested yet."
@@ -67,4 +67,6 @@
extern PyTypeObject Py_fftType;
extern PyTypeObject Py_pvocType;
+
+extern PyTypeObject Py_sourceType;
--- a/python/ext/aubiomodule.c
+++ b/python/ext/aubiomodule.c
@@ -198,6 +198,7 @@
|| (PyType_Ready (&Py_filterbankType) < 0)
|| (PyType_Ready (&Py_fftType) < 0)
|| (PyType_Ready (&Py_pvocType) < 0)
+ || (PyType_Ready (&Py_sourceType) < 0)
// generated objects
|| (generated_types_ready() < 0 )
) {
@@ -226,6 +227,8 @@
PyModule_AddObject (m, "fft", (PyObject *) & Py_fftType);
Py_INCREF (&Py_pvocType);
PyModule_AddObject (m, "pvoc", (PyObject *) & Py_pvocType);
+ Py_INCREF (&Py_sourceType);
+ PyModule_AddObject (m, "source", (PyObject *) & Py_sourceType);
// add generated objects
add_generated_objects(m);
--- /dev/null
+++ b/python/ext/py-source.c
@@ -1,0 +1,137 @@
+// WARNING: this file is generated, DO NOT EDIT
+
+// WARNING: if you haven't read the first line yet, please do so
+#include "aubiowraphell.h"
+
+typedef struct
+{
+ PyObject_HEAD
+ aubio_source_t * o;
+ char_t* uri;
+ uint_t samplerate;
+ uint_t hop_size;
+} Py_source;
+
+static char Py_source_doc[] = "source object";
+
+static PyObject *
+Py_source_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds)
+{
+ Py_source *self;
+ char_t* uri = NULL;
+ uint_t samplerate = 0;
+ uint_t hop_size = 0;
+ static char *kwlist[] = { "uri", "samplerate", "hop_size", NULL };
+
+ if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sII", kwlist,
+ &uri, &samplerate, &hop_size)) {
+ return NULL;
+ }
+
+ self = (Py_source *) 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 (samplerate > 0) {
+ self->samplerate = samplerate;
+ //} else if (samplerate < 0) {
+ // PyErr_SetString (PyExc_ValueError,
+ // "can not use negative value for samplerate");
+ // return NULL;
+ }
+
+ self->hop_size = Py_default_vector_length / 2;
+ if (hop_size > 0) {
+ self->hop_size = hop_size;
+ //} else if (hop_size < 0) {
+ // PyErr_SetString (PyExc_ValueError,
+ // "can not use negative value for hop_size");
+ // return NULL;
+ }
+
+ return (PyObject *) self;
+}
+
+static int
+Py_source_init (Py_source * self, PyObject * args, PyObject * kwds)
+{
+ self->o = new_aubio_source ( self->uri, self->samplerate, self->hop_size );
+ if (self->o == NULL) {
+ PyErr_SetString (PyExc_StandardError, "error creating object");
+ return -1;
+ }
+ self->samplerate = aubio_source_get_samplerate ( self->o );
+
+ return 0;
+}
+
+AUBIO_DEL(source)
+
+/* function Py_source_do */
+static PyObject *
+Py_source_do(Py_source * self, PyObject * args)
+{
+
+
+ /* output vectors prototypes */
+ fvec_t* read_to;
+ uint_t read;
+
+
+
+
+
+
+ /* creating output read_to as a new_fvec of length self->hop_size */
+ read_to = new_fvec (self->hop_size);
+ read = 0;
+
+
+ /* compute _do function */
+ aubio_source_do (self->o, read_to, &read);
+
+ PyObject *outputs = PyList_New(0);
+ PyList_Append( outputs, (PyObject *)PyAubio_CFvecToArray (read_to));
+ //del_fvec (read_to);
+ PyList_Append( outputs, (PyObject *)PyInt_FromLong (read));
+ return outputs;
+}
+
+AUBIO_MEMBERS_START(source)
+ {"uri", T_STRING, offsetof (Py_source, uri), READONLY, ""},
+ {"samplerate", T_INT, offsetof (Py_source, samplerate), READONLY, ""},
+ {"hop_size", T_INT, offsetof (Py_source, hop_size), READONLY, ""},
+AUBIO_MEMBERS_STOP(source)
+
+
+static PyObject *
+Pyaubio_source_get_samplerate (Py_source *self, PyObject *unused)
+{
+ uint_t tmp = aubio_source_get_samplerate (self->o);
+ return (PyObject *)PyInt_FromLong (tmp);
+}
+
+static PyObject *
+Pyaubio_source_get_channels (Py_source *self, PyObject *unused)
+{
+ uint_t tmp = aubio_source_get_channels (self->o);
+ return (PyObject *)PyInt_FromLong (tmp);
+}
+
+static PyMethodDef Py_source_methods[] = {
+ {"get_samplerate", (PyCFunction) Pyaubio_source_get_samplerate,
+ METH_NOARGS, ""},
+ {"get_channels", (PyCFunction) Pyaubio_source_get_channels,
+ METH_NOARGS, ""},
+ {NULL} /* sentinel */
+};
+
+AUBIO_TYPEOBJECT(source, "aubio.source")
--- a/python/lib/generator.py
+++ b/python/lib/generator.py
@@ -56,6 +56,7 @@
'pitchyinfft',
'sink_apple_audio',
'sink_sndfile',
+ 'source',
'source_apple_audio',
'source_sndfile',
'source_avcodec',
--- a/python/setup.py
+++ b/python/setup.py
@@ -53,6 +53,7 @@
"ext/py-filterbank.c",
"ext/py-fft.c",
"ext/py-phasevoc.c",
+ "ext/py-source.c",
# generated files
] + generated_object_files,
include_dirs = include_dirs,