Changeset 24931d5 for python/ext


Ignore:
Timestamp:
Sep 21, 2014, 2:02:26 AM (10 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
11b49d7
Parents:
a79ec76
Message:

ext/py-source.c: add channels

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/ext/py-source.c

    ra79ec76 r24931d5  
    7777  uint_t samplerate = 0;
    7878  uint_t hop_size = 0;
    79   static char *kwlist[] = { "uri", "samplerate", "hop_size", NULL };
    80 
    81   if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sII", kwlist,
    82           &uri, &samplerate, &hop_size)) {
     79  uint_t channels = 0;
     80  static char *kwlist[] = { "uri", "samplerate", "hop_size", "channels", NULL };
     81
     82  if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sIII", kwlist,
     83          &uri, &samplerate, &hop_size, &channels)) {
    8384    return NULL;
    8485  }
     
    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}
     
    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;
Note: See TracChangeset for help on using the changeset viewer.