[f1100a4] | 1 | #include "aubiowraphell.h" |
---|
| 2 | |
---|
| 3 | typedef struct |
---|
| 4 | { |
---|
| 5 | PyObject_HEAD |
---|
| 6 | aubio_sink_t * o; |
---|
| 7 | char_t* uri; |
---|
| 8 | uint_t samplerate; |
---|
| 9 | } Py_sink; |
---|
| 10 | |
---|
| 11 | static char Py_sink_doc[] = "sink object"; |
---|
| 12 | |
---|
| 13 | static PyObject * |
---|
| 14 | Py_sink_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds) |
---|
| 15 | { |
---|
| 16 | Py_sink *self; |
---|
| 17 | char_t* uri = NULL; |
---|
| 18 | uint_t samplerate = 0; |
---|
| 19 | static char *kwlist[] = { "uri", "samplerate", NULL }; |
---|
| 20 | |
---|
| 21 | if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sI", kwlist, |
---|
| 22 | &uri, &samplerate)) { |
---|
| 23 | return NULL; |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | self = (Py_sink *) pytype->tp_alloc (pytype, 0); |
---|
| 27 | |
---|
| 28 | if (self == NULL) { |
---|
| 29 | return NULL; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | self->uri = "none"; |
---|
| 33 | if (uri != NULL) { |
---|
| 34 | self->uri = uri; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | self->samplerate = Py_aubio_default_samplerate; |
---|
| 38 | if ((sint_t)samplerate > 0) { |
---|
| 39 | self->samplerate = samplerate; |
---|
| 40 | } else if ((sint_t)samplerate < 0) { |
---|
| 41 | PyErr_SetString (PyExc_ValueError, |
---|
| 42 | "can not use negative value for samplerate"); |
---|
| 43 | return NULL; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | return (PyObject *) self; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | AUBIO_INIT(sink , self->uri, self->samplerate) |
---|
| 50 | |
---|
| 51 | AUBIO_DEL(sink) |
---|
| 52 | |
---|
| 53 | /* function Py_sink_do */ |
---|
| 54 | static PyObject * |
---|
| 55 | Py_sink_do(Py_sink * self, PyObject * args) |
---|
| 56 | { |
---|
| 57 | /* input vectors python prototypes */ |
---|
| 58 | PyObject * write_data_obj; |
---|
| 59 | |
---|
| 60 | /* input vectors prototypes */ |
---|
| 61 | fvec_t* write_data; |
---|
| 62 | uint_t write; |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | if (!PyArg_ParseTuple (args, "OI", &write_data_obj, &write)) { |
---|
| 66 | return NULL; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | /* input vectors parsing */ |
---|
| 71 | write_data = PyAubio_ArrayToCFvec (write_data_obj); |
---|
| 72 | |
---|
| 73 | if (write_data == NULL) { |
---|
| 74 | return NULL; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | /* compute _do function */ |
---|
| 82 | aubio_sink_do (self->o, write_data, write); |
---|
| 83 | |
---|
| 84 | Py_RETURN_NONE; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | AUBIO_MEMBERS_START(sink) |
---|
| 88 | {"uri", T_STRING, offsetof (Py_sink, uri), READONLY, ""}, |
---|
| 89 | {"samplerate", T_INT, offsetof (Py_sink, samplerate), READONLY, ""}, |
---|
| 90 | AUBIO_MEMBERS_STOP(sink) |
---|
| 91 | |
---|
[7b56229] | 92 | static PyObject * |
---|
| 93 | Pyaubio_sink_close (Py_sink *self, PyObject *unused) |
---|
| 94 | { |
---|
| 95 | del_aubio_sink (self->o); |
---|
| 96 | self->o = NULL; |
---|
| 97 | Py_RETURN_NONE; |
---|
| 98 | } |
---|
[f1100a4] | 99 | |
---|
| 100 | static PyMethodDef Py_sink_methods[] = { |
---|
[7b56229] | 101 | {"close", (PyCFunction) Pyaubio_sink_close, |
---|
| 102 | METH_NOARGS, ""}, |
---|
[f1100a4] | 103 | {NULL} /* sentinel */ |
---|
| 104 | }; |
---|
| 105 | |
---|
| 106 | AUBIO_TYPEOBJECT(sink, "aubio.sink") |
---|