Showing the changes to python/ext/py-source.c (1 of 1 file). Show all
Unified · Split
| @@ -76,10 +76,11 @@ Py_source_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds) · 75 unmodified lines | |||
| 76 | char_t* uri = NULL; | 76 | char_t* uri = NULL; |
| 77 | uint_t samplerate = 0; | 77 | uint_t samplerate = 0; |
| 78 | uint_t hop_size = 0; | 78 | uint_t hop_size = 0; |
| 79 | static char *kwlist[] = { "uri", "samplerate", "hop_size", NULL }; | 79 | uint_t channels = 0; |
| 80 | static char *kwlist[] = { "uri", "samplerate", "hop_size", "channels", NULL }; | ||
| 80 | 81 | ||
| 81 | if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sII", kwlist, | 82 | if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sIII", kwlist, |
| 82 | &uri, &samplerate, &hop_size)) { | 83 | &uri, &samplerate, &hop_size, &channels)) { |
| 83 | return NULL; | 84 | return NULL; |
| 84 | } | 85 | } |
| 85 | 86 | ||
| @@ -112,6 +113,15 @@ Py_source_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds) · 26 unmodified lines | |||
| 112 | return NULL; | 113 | return NULL; |
| 113 | } | 114 | } |
| 114 | 115 | ||
| 116 | self->channels = 1; | ||
| 117 | if ((sint_t)channels >= 0) { | ||
| 118 | self->channels = channels; | ||
| 119 | } else if ((sint_t)channels < 0) { | ||
| 120 | PyErr_SetString (PyExc_ValueError, | ||
| 121 | "can not use negative value for channels"); | ||
| 122 | return NULL; | ||
| 123 | } | ||
| 124 | |||
| 115 | return (PyObject *) self; | 125 | return (PyObject *) self; |
| 116 | } | 126 | } |
| 117 | 127 | ||
| @@ -120,11 +130,15 @@ Py_source_init (Py_source * self, PyObject * args, PyObject * kwds) · 2 unmodified lines | |||
| 120 | { | 130 | { |
| 121 | self->o = new_aubio_source ( self->uri, self->samplerate, self->hop_size ); | 131 | self->o = new_aubio_source ( self->uri, self->samplerate, self->hop_size ); |
| 122 | if (self->o == NULL) { | 132 | if (self->o == NULL) { |
| 123 | PyErr_SetString (PyExc_StandardError, "error creating object"); | 133 | char_t errstr[30 + strlen(self->uri)]; |
| 134 | sprintf(errstr, "error creating source with %s", self->uri); | ||
| 135 | PyErr_SetString (PyExc_StandardError, errstr); | ||
| 124 | return -1; | 136 | return -1; |
| 125 | } | 137 | } |
| 126 | self->samplerate = aubio_source_get_samplerate ( self->o ); | 138 | self->samplerate = aubio_source_get_samplerate ( self->o ); |
| 127 | self->channels = aubio_source_get_channels ( self->o ); | 139 | if (self->channels == 0) { |
| 140 | self->channels = aubio_source_get_channels ( self->o ); | ||
| 141 | } | ||
| 128 | 142 | ||
| 129 | return 0; | 143 | return 0; |
| 130 | } | 144 | } |