1 #include "aubiowraphell.h"
12 static char Py_sink_doc[] = "sink object";
15 Py_sink_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds)
19 uint_t samplerate = 0;
21 static char *kwlist[] = { "uri", "samplerate", "channels", NULL };
23 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sII", kwlist,
24 &uri, &samplerate, &channels)) {
28 self = (Py_sink *) pytype->tp_alloc (pytype, 0);
39 self->samplerate = Py_aubio_default_samplerate;
40 if ((sint_t)samplerate > 0) {
41 self->samplerate = samplerate;
42 } else if ((sint_t)samplerate < 0) {
43 PyErr_SetString (PyExc_ValueError,
44 "can not use negative value for samplerate");
49 if ((sint_t)channels > 0) {
50 self->channels = channels;
51 } else if ((sint_t)channels < 0) {
52 PyErr_SetString (PyExc_ValueError,
53 "can not use negative or null value for channels");
57 return (PyObject *) self;
61 Py_sink_init (Py_sink * self, PyObject * args, PyObject * kwds)
63 if (self->channels == 1) {
64 self->o = new_aubio_sink ( self->uri, self->samplerate );
66 self->o = new_aubio_sink ( self->uri, 0 );
67 aubio_sink_preset_channels ( self->o, self->channels );
68 aubio_sink_preset_samplerate ( self->o, self->samplerate );
70 if (self->o == NULL) {
71 PyErr_SetString (PyExc_StandardError, "error creating sink with this uri");
74 self->samplerate = aubio_sink_get_samplerate ( self->o );
75 self->channels = aubio_sink_get_channels ( self->o );
82 /* function Py_sink_do */
84 Py_sink_do(Py_sink * self, PyObject * args)
86 /* input vectors python prototypes */
87 PyObject * write_data_obj;
89 /* input vectors prototypes */
94 if (!PyArg_ParseTuple (args, "OI", &write_data_obj, &write)) {
99 /* input vectors parsing */
100 write_data = PyAubio_ArrayToCFvec (write_data_obj);
102 if (write_data == NULL) {
110 /* compute _do function */
111 aubio_sink_do (self->o, write_data, write);
116 /* function Py_sink_do */
118 Py_sink_do_multi(Py_sink * self, PyObject * args)
120 /* input vectors python prototypes */
121 PyObject * write_data_obj;
123 /* input vectors prototypes */
128 if (!PyArg_ParseTuple (args, "OI", &write_data_obj, &write)) {
133 /* input vectors parsing */
134 write_data = PyAubio_ArrayToCFmat (write_data_obj);
136 if (write_data == NULL) {
144 /* compute _do function */
145 aubio_sink_do_multi (self->o, write_data, write);
149 AUBIO_MEMBERS_START(sink)
150 {"uri", T_STRING, offsetof (Py_sink, uri), READONLY, ""},
151 {"samplerate", T_INT, offsetof (Py_sink, samplerate), READONLY, ""},
152 {"channels", T_INT, offsetof (Py_sink, channels), READONLY, ""},
153 AUBIO_MEMBERS_STOP(sink)
156 Pyaubio_sink_close (Py_sink *self, PyObject *unused)
158 aubio_sink_close (self->o);
162 static PyMethodDef Py_sink_methods[] = {
163 {"__call__", (PyCFunction) Py_sink_do, METH_VARARGS,
164 "x.__call__(vec, write)\n"
165 "write monophonic vector to sink"
167 {"do", (PyCFunction) Py_sink_do, METH_VARARGS,
169 "write monophonic vector to sink"
171 {"do_multi", (PyCFunction) Py_sink_do_multi, METH_VARARGS,
172 "x.do_multi(mat, write)\n"
173 "write polyphonic vector to sink"},
174 {"close", (PyCFunction) Pyaubio_sink_close, METH_NOARGS,
176 "close this sink now"},
177 {NULL} /* sentinel */
180 AUBIO_TYPEOBJECT(sink, "aubio.sink")