1 #include "aubio-types.h"
14 static char Py_sink_doc[] = ""
15 " __new__(path, samplerate = 44100, channels = 1)\n"
17 " Create a new sink, opening the given path for writing.\n"
22 " Create a new sink at 44100Hz, mono:\n"
24 " >>> sink('/tmp/t.wav')\n"
26 " Create a new sink at 8000Hz, mono:\n"
28 " >>> sink('/tmp/t.wav', samplerate = 8000)\n"
30 " Create a new sink at 32000Hz, stereo:\n"
32 " >>> sink('/tmp/t.wav', samplerate = 32000, channels = 2)\n"
34 " Create a new sink at 32000Hz, 5 channels:\n"
36 " >>> sink('/tmp/t.wav', channels = 5, samplerate = 32000)\n"
38 " __call__(vec, write)\n"
39 " x(vec,write) <==> x.do(vec, write)\n"
41 " Write vector to sink.\n"
48 static char Py_sink_do_doc[] = ""
49 "x.do(vec, write) <==> x(vec, write)\n"
51 "write monophonic vector to sink";
53 static char Py_sink_do_multi_doc[] = ""
54 "x.do_multi(mat, write)\n"
56 "write polyphonic vector to sink";
58 static char Py_sink_close_doc[] = ""
61 "close this sink now";
64 Py_sink_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds)
68 uint_t samplerate = 0;
70 static char *kwlist[] = { "uri", "samplerate", "channels", NULL };
72 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sII", kwlist,
73 &uri, &samplerate, &channels)) {
77 self = (Py_sink *) pytype->tp_alloc (pytype, 0);
88 self->samplerate = Py_aubio_default_samplerate;
89 if ((sint_t)samplerate > 0) {
90 self->samplerate = samplerate;
91 } else if ((sint_t)samplerate < 0) {
92 PyErr_SetString (PyExc_ValueError,
93 "can not use negative value for samplerate");
98 if ((sint_t)channels > 0) {
99 self->channels = channels;
100 } else if ((sint_t)channels < 0) {
101 PyErr_SetString (PyExc_ValueError,
102 "can not use negative or null value for channels");
106 return (PyObject *) self;
110 Py_sink_init (Py_sink * self, PyObject * args, PyObject * kwds)
112 if (self->channels == 1) {
113 self->o = new_aubio_sink ( self->uri, self->samplerate );
115 self->o = new_aubio_sink ( self->uri, 0 );
116 aubio_sink_preset_channels ( self->o, self->channels );
117 aubio_sink_preset_samplerate ( self->o, self->samplerate );
119 if (self->o == NULL) {
120 PyErr_SetString (PyExc_RuntimeError, "error creating sink with this uri");
123 self->samplerate = aubio_sink_get_samplerate ( self->o );
124 self->channels = aubio_sink_get_channels ( self->o );
130 Py_sink_del (Py_sink *self, PyObject *unused)
132 del_aubio_sink(self->o);
133 free(self->mwrite_data.data);
134 Py_TYPE(self)->tp_free((PyObject *) self);
137 /* function Py_sink_do */
139 Py_sink_do(Py_sink * self, PyObject * args)
141 /* input vectors python prototypes */
142 PyObject * write_data_obj;
144 /* input vectors prototypes */
148 if (!PyArg_ParseTuple (args, "OI", &write_data_obj, &write)) {
152 /* input vectors parsing */
153 if (!PyAubio_ArrayToCFvec(write_data_obj, &(self->write_data))) {
158 /* compute _do function */
159 aubio_sink_do (self->o, &(self->write_data), write);
164 /* function Py_sink_do_multi */
166 Py_sink_do_multi(Py_sink * self, PyObject * args)
168 /* input vectors python prototypes */
169 PyObject * write_data_obj;
171 /* input vectors prototypes */
175 if (!PyArg_ParseTuple (args, "OI", &write_data_obj, &write)) {
180 /* input vectors parsing */
181 if (!PyAubio_ArrayToCFmat(write_data_obj, &(self->mwrite_data))) {
185 /* compute _do function */
186 aubio_sink_do_multi (self->o, &(self->mwrite_data), write);
190 static PyMemberDef Py_sink_members[] = {
191 {"uri", T_STRING, offsetof (Py_sink, uri), READONLY,
192 "path at which the sink was created"},
193 {"samplerate", T_INT, offsetof (Py_sink, samplerate), READONLY,
194 "samplerate at which the sink was created"},
195 {"channels", T_INT, offsetof (Py_sink, channels), READONLY,
196 "number of channels with which the sink was created"},
201 Pyaubio_sink_close (Py_sink *self, PyObject *unused)
203 aubio_sink_close (self->o);
207 static PyMethodDef Py_sink_methods[] = {
208 {"do", (PyCFunction) Py_sink_do, METH_VARARGS, Py_sink_do_doc},
209 {"do_multi", (PyCFunction) Py_sink_do_multi, METH_VARARGS, Py_sink_do_multi_doc},
210 {"close", (PyCFunction) Pyaubio_sink_close, METH_NOARGS, Py_sink_close_doc},
211 {NULL} /* sentinel */
214 PyTypeObject Py_sinkType = {
215 PyVarObject_HEAD_INIT (NULL, 0)
219 (destructor) Py_sink_del,
229 (ternaryfunc)Py_sink_do,
250 (initproc) Py_sink_init,