1 #include "aubiowraphell.h"
13 static char Py_source_doc[] = "source object";
16 Py_source_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds)
20 uint_t samplerate = 0;
22 static char *kwlist[] = { "uri", "samplerate", "hop_size", NULL };
24 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sII", kwlist,
25 &uri, &samplerate, &hop_size)) {
29 self = (Py_source *) pytype->tp_alloc (pytype, 0);
41 if ((sint_t)samplerate > 0) {
42 self->samplerate = samplerate;
43 } else if ((sint_t)samplerate < 0) {
44 PyErr_SetString (PyExc_ValueError,
45 "can not use negative value for samplerate");
49 self->hop_size = Py_default_vector_length / 2;
50 if ((sint_t)hop_size > 0) {
51 self->hop_size = hop_size;
52 } else if ((sint_t)hop_size < 0) {
53 PyErr_SetString (PyExc_ValueError,
54 "can not use negative value for hop_size");
58 return (PyObject *) self;
62 Py_source_init (Py_source * self, PyObject * args, PyObject * kwds)
64 self->o = new_aubio_source ( self->uri, self->samplerate, self->hop_size );
65 if (self->o == NULL) {
66 PyErr_SetString (PyExc_StandardError, "error creating object");
69 self->samplerate = aubio_source_get_samplerate ( self->o );
70 self->channels = aubio_source_get_channels ( self->o );
77 /* function Py_source_do */
79 Py_source_do(Py_source * self, PyObject * args)
83 /* output vectors prototypes */
92 /* creating output read_to as a new_fvec of length self->hop_size */
93 read_to = new_fvec (self->hop_size);
97 /* compute _do function */
98 aubio_source_do (self->o, read_to, &read);
100 PyObject *outputs = PyList_New(0);
101 PyList_Append( outputs, (PyObject *)PyAubio_CFvecToArray (read_to));
102 //del_fvec (read_to);
103 PyList_Append( outputs, (PyObject *)PyInt_FromLong (read));
107 /* function Py_source_do_multi */
109 Py_source_do_multi(Py_source * self, PyObject * args)
113 /* output vectors prototypes */
122 /* creating output read_to as a new_fvec of length self->hop_size */
123 read_to = new_fmat (self->channels, self->hop_size);
127 /* compute _do function */
128 aubio_source_do_multi (self->o, read_to, &read);
130 PyObject *outputs = PyList_New(0);
131 PyList_Append( outputs, (PyObject *)PyAubio_CFmatToArray (read_to));
132 //del_fvec (read_to);
133 PyList_Append( outputs, (PyObject *)PyInt_FromLong (read));
137 AUBIO_MEMBERS_START(source)
138 {"uri", T_STRING, offsetof (Py_source, uri), READONLY, ""},
139 {"samplerate", T_INT, offsetof (Py_source, samplerate), READONLY, ""},
140 {"channels", T_INT, offsetof (Py_source, channels), READONLY, ""},
141 {"hop_size", T_INT, offsetof (Py_source, hop_size), READONLY, ""},
142 AUBIO_MEMBERS_STOP(source)
146 Pyaubio_source_get_samplerate (Py_source *self, PyObject *unused)
148 uint_t tmp = aubio_source_get_samplerate (self->o);
149 return (PyObject *)PyInt_FromLong (tmp);
153 Pyaubio_source_get_channels (Py_source *self, PyObject *unused)
155 uint_t tmp = aubio_source_get_channels (self->o);
156 return (PyObject *)PyInt_FromLong (tmp);
160 Pyaubio_source_close (Py_source *self, PyObject *unused)
162 aubio_source_close (self->o);
166 static PyMethodDef Py_source_methods[] = {
167 {"get_samplerate", (PyCFunction) Pyaubio_source_get_samplerate,
169 {"get_channels", (PyCFunction) Pyaubio_source_get_channels,
171 {"do_multi", (PyCFunction) Py_source_do_multi,
173 {"close", (PyCFunction) Pyaubio_source_close,
175 {NULL} /* sentinel */
178 AUBIO_TYPEOBJECT(source, "aubio.source")