History

ext/py-source.c: add channels

Paul Brossier committed 12 years ago

Commit 24931d51 parent a79ec761 file · +19 −5Browse files

Showing the changes to python/ext/py-source.c (1 of 1 file). Show all

Unified · Split

python/ext/py-source.c+19−5
@@ -76,10 +76,11 @@ Py_source_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds) · 75 unmodified lines
7676 char_t* uri = NULL;
7777 uint_t samplerate = 0;
7878 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 };
8081
81− if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sII", kwlist,
82− &uri, &samplerate, &hop_size)) {
82+ if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sIII", kwlist,
83+ &uri, &samplerate, &hop_size, &channels)) {
8384 return NULL;
8485 }
8586
@@ -112,6 +113,15 @@ Py_source_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds) · 26 unmodified lines
112113 return NULL;
113114 }
114115
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+
115125 return (PyObject *) self;
116126 }
117127
@@ -120,11 +130,15 @@ Py_source_init (Py_source * self, PyObject * args, PyObject * kwds) · 2 unmodified lines
120130 {
121131 self->o = new_aubio_source ( self->uri, self->samplerate, self->hop_size );
122132 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);
124136 return -1;
125137 }
126138 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+ }
128142
129143 return 0;
130144 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t