Changes in python/ext/py-sink.c [0e70ef9:fcb6e8c]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/ext/py-sink.c
r0e70ef9 rfcb6e8c 81 81 } 82 82 83 self->uri = "none";83 self->uri = NULL; 84 84 if (uri != NULL) { 85 self->uri = uri; 85 self->uri = (char_t *)malloc(sizeof(char_t) * (strnlen(uri, PATH_MAX) + 1)); 86 strncpy(self->uri, uri, strnlen(uri, PATH_MAX) + 1); 86 87 } 87 88 88 89 self->samplerate = Py_aubio_default_samplerate; 89 if ( (sint_t)samplerate >0) {90 if (samplerate != 0) { 90 91 self->samplerate = samplerate; 91 } else if ((sint_t)samplerate < 0) {92 PyErr_SetString (PyExc_ValueError,93 "can not use negative value for samplerate");94 return NULL;95 92 } 96 93 97 94 self->channels = 1; 98 if ( (sint_t)channels >0) {95 if (channels != 0) { 99 96 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");103 return NULL;104 97 } 105 98 … … 110 103 Py_sink_init (Py_sink * self, PyObject * args, PyObject * kwds) 111 104 { 112 if (self->channels == 1) { 113 self->o = new_aubio_sink ( self->uri, self->samplerate ); 114 } else { 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 ); 118 } 105 self->o = new_aubio_sink ( self->uri, 0 ); 119 106 if (self->o == NULL) { 120 PyErr_SetString (PyExc_RuntimeError, "error creating sink with this uri");107 // error string was set in new_aubio_sink 121 108 return -1; 122 109 } 110 if (aubio_sink_preset_channels(self->o, self->channels) != 0) { 111 // error string was set in aubio_sink_preset_channels 112 return -1; 113 } 114 if (aubio_sink_preset_samplerate(self->o, self->samplerate) != 0) { 115 // error string was set in aubio_sink_preset_samplerate 116 return -1; 117 } 118 123 119 self->samplerate = aubio_sink_get_samplerate ( self->o ); 124 120 self->channels = aubio_sink_get_channels ( self->o ); … … 132 128 del_aubio_sink(self->o); 133 129 free(self->mwrite_data.data); 130 if (self->uri) { 131 free(self->uri); 132 } 134 133 Py_TYPE(self)->tp_free((PyObject *) self); 135 134 } … … 205 204 } 206 205 206 static char Pyaubio_sink_enter_doc[] = ""; 207 static PyObject* Pyaubio_sink_enter(Py_sink *self, PyObject *unused) { 208 Py_INCREF(self); 209 return (PyObject*)self; 210 } 211 212 static char Pyaubio_sink_exit_doc[] = ""; 213 static PyObject* Pyaubio_sink_exit(Py_sink *self, PyObject *unused) { 214 return Pyaubio_sink_close(self, unused); 215 } 216 207 217 static PyMethodDef Py_sink_methods[] = { 208 218 {"do", (PyCFunction) Py_sink_do, METH_VARARGS, Py_sink_do_doc}, 209 219 {"do_multi", (PyCFunction) Py_sink_do_multi, METH_VARARGS, Py_sink_do_multi_doc}, 210 220 {"close", (PyCFunction) Pyaubio_sink_close, METH_NOARGS, Py_sink_close_doc}, 221 {"__enter__", (PyCFunction)Pyaubio_sink_enter, METH_NOARGS, 222 Pyaubio_sink_enter_doc}, 223 {"__exit__", (PyCFunction)Pyaubio_sink_exit, METH_VARARGS, 224 Pyaubio_sink_exit_doc}, 211 225 {NULL} /* sentinel */ 212 226 };
Note: See TracChangeset
for help on using the changeset viewer.