Showing the changes to python/ext (1 of 1 file). Show all
Unified · Split
| @@ -6,6 +6,7 @@ typedef struct · 5 unmodified lines | ||
| 6 | 6 | aubio_sink_t * o; |
| 7 | 7 | char_t* uri; |
| 8 | 8 | uint_t samplerate; |
| 9 | + uint_t channels; | |
| 9 | 10 | } Py_sink; |
| 10 | 11 | |
| 11 | 12 | static char Py_sink_doc[] = "sink object"; |
| @@ -16,10 +17,11 @@ Py_sink_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds) · 4 unmodified lines | ||
| 16 | 17 | Py_sink *self; |
| 17 | 18 | char_t* uri = NULL; |
| 18 | 19 | uint_t samplerate = 0; |
| 19 | − static char *kwlist[] = { "uri", "samplerate", NULL }; | |
| 20 | + uint_t channels = 0; | |
| 21 | + static char *kwlist[] = { "uri", "samplerate", "channels", NULL }; | |
| 20 | 22 | |
| 21 | − if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sI", kwlist, | |
| 22 | − &uri, &samplerate)) { | |
| 23 | + if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sII", kwlist, | |
| 24 | + &uri, &samplerate, &channels)) { | |
| 23 | 25 | return NULL; |
| 24 | 26 | } |
| 25 | 27 | |
| @@ -43,15 +45,42 @@ Py_sink_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds) · 17 unmodified lines | ||
| 43 | 45 | return NULL; |
| 44 | 46 | } |
| 45 | 47 | |
| 48 | + self->channels = 1; | |
| 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"); | |
| 54 | + return NULL; | |
| 55 | + } | |
| 56 | + | |
| 46 | 57 | return (PyObject *) self; |
| 47 | 58 | } |
| 48 | 59 | |
| 49 | −AUBIO_INIT(sink , self->uri, self->samplerate) | |
| 60 | +static int | |
| 61 | +Py_sink_init (Py_sink * self, PyObject * args, PyObject * kwds) | |
| 62 | +{ | |
| 63 | + if (self->channels == 1) { | |
| 64 | + self->o = new_aubio_sink ( self->uri, self->samplerate ); | |
| 65 | + } else { | |
| 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 ); | |
| 69 | + } | |
| 70 | + if (self->o == NULL) { | |
| 71 | + PyErr_SetString (PyExc_StandardError, "error creating sink with this uri"); | |
| 72 | + return -1; | |
| 73 | + } | |
| 74 | + self->samplerate = aubio_sink_get_samplerate ( self->o ); | |
| 75 | + self->channels = aubio_sink_get_channels ( self->o ); | |
| 76 | + | |
| 77 | + return 0; | |
| 78 | +} | |
| 50 | 79 | |
| 51 | 80 | AUBIO_DEL(sink) |
| 52 | 81 | |
| 53 | 82 | /* function Py_sink_do */ |
| 54 | −static PyObject * | |
| 83 | +static PyObject * | |
| 55 | 84 | Py_sink_do(Py_sink * self, PyObject * args) |
| 56 | 85 | { |
| 57 | 86 | /* input vectors python prototypes */ |
| @@ -74,8 +103,8 @@ Py_sink_do(Py_sink * self, PyObject * args) · 16 unmodified lines | ||
| 74 | 103 | return NULL; |
| 75 | 104 | } |
| 76 | 105 | |
| 77 | − | |
| 78 | − | |
| 106 | + | |
| 107 | + | |
| 79 | 108 | |
| 80 | 109 | |
| 81 | 110 | /* compute _do function */ |
| @@ -84,9 +113,43 @@ Py_sink_do(Py_sink * self, PyObject * args) · 2 unmodified lines | ||
| 84 | 113 | Py_RETURN_NONE; |
| 85 | 114 | } |
| 86 | 115 | |
| 116 | +/* function Py_sink_do */ | |
| 117 | +static PyObject * | |
| 118 | +Py_sink_do_multi(Py_sink * self, PyObject * args) | |
| 119 | +{ | |
| 120 | + /* input vectors python prototypes */ | |
| 121 | + PyObject * write_data_obj; | |
| 122 | + | |
| 123 | + /* input vectors prototypes */ | |
| 124 | + fmat_t * write_data; | |
| 125 | + uint_t write; | |
| 126 | + | |
| 127 | + | |
| 128 | + if (!PyArg_ParseTuple (args, "OI", &write_data_obj, &write)) { | |
| 129 | + return NULL; | |
| 130 | + } | |
| 131 | + | |
| 132 | + | |
| 133 | + /* input vectors parsing */ | |
| 134 | + write_data = PyAubio_ArrayToCFmat (write_data_obj); | |
| 135 | + | |
| 136 | + if (write_data == NULL) { | |
| 137 | + return NULL; | |
| 138 | + } | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + /* compute _do function */ | |
| 145 | + aubio_sink_do_multi (self->o, write_data, write); | |
| 146 | + Py_RETURN_NONE; | |
| 147 | +} | |
| 148 | + | |
| 87 | 149 | AUBIO_MEMBERS_START(sink) |
| 88 | 150 | {"uri", T_STRING, offsetof (Py_sink, uri), READONLY, ""}, |
| 89 | 151 | {"samplerate", T_INT, offsetof (Py_sink, samplerate), READONLY, ""}, |
| 152 | + {"channels", T_INT, offsetof (Py_sink, channels), READONLY, ""}, | |
| 90 | 153 | AUBIO_MEMBERS_STOP(sink) |
| 91 | 154 | |
| 92 | 155 | static PyObject * |
| @@ -97,8 +160,20 @@ Pyaubio_sink_close (Py_sink *self, PyObject *unused) · 4 unmodified lines | ||
| 97 | 160 | } |
| 98 | 161 | |
| 99 | 162 | static PyMethodDef Py_sink_methods[] = { |
| 100 | − {"close", (PyCFunction) Pyaubio_sink_close, | |
| 101 | − METH_NOARGS, ""}, | |
| 163 | + {"__call__", (PyCFunction) Py_sink_do, METH_VARARGS, | |
| 164 | + "x.__call__(vec, write)\n" | |
| 165 | + "write monophonic vector to sink" | |
| 166 | + ""}, | |
| 167 | + {"do", (PyCFunction) Py_sink_do, METH_VARARGS, | |
| 168 | + "x.do(vec, write)\n" | |
| 169 | + "write monophonic vector to sink" | |
| 170 | + ""}, | |
| 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, | |
| 175 | + "x.close()\n" | |
| 176 | + "close this sink now"}, | |
| 102 | 177 | {NULL} /* sentinel */ |
| 103 | 178 | }; |
| 104 | 179 | |