Ignore:
Timestamp:
Aug 12, 2015, 7:21:38 PM (9 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:
60fc05b
Parents:
3a1a5d6 (diff), 7b2d740 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'develop' into notes

File:
1 edited

Legend:

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

    r3a1a5d6 rb257b60  
    1111} Py_source;
    1212
    13 static char Py_source_doc[] = "source object";
     13static char Py_source_doc[] = ""
     14"   __new__(path, samplerate = 0, hop_size = 512, channels = 1)\n"
     15"\n"
     16"       Create a new source, opening the given path for reading.\n"
     17"\n"
     18"       Examples\n"
     19"       --------\n"
     20"\n"
     21"       Create a new source, using the original samplerate, with hop_size = 512:\n"
     22"\n"
     23"       >>> source('/tmp/t.wav')\n"
     24"\n"
     25"       Create a new source, resampling the original to 8000Hz:\n"
     26"\n"
     27"       >>> source('/tmp/t.wav', samplerate = 8000)\n"
     28"\n"
     29"       Create a new source, resampling it at 32000Hz, hop_size = 32:\n"
     30"\n"
     31"       >>> source('/tmp/t.wav', samplerate = 32000, hop_size = 32)\n"
     32"\n"
     33"       Create a new source, using its original samplerate:\n"
     34"\n"
     35"       >>> source('/tmp/t.wav', samplerate = 0)\n"
     36"\n"
     37"   __call__()\n"
     38"       vec, read = x() <==> vec, read = x.do()\n"
     39"\n"
     40"       Read vector from source.\n"
     41"\n"
     42"       See also\n"
     43"       --------\n"
     44"       aubio.source.do\n"
     45"\n";
     46
     47static char Py_source_get_samplerate_doc[] = ""
     48"x.get_samplerate() -> source samplerate\n"
     49"\n"
     50"Get samplerate of source.";
     51
     52static char Py_source_get_channels_doc[] = ""
     53"x.get_channels() -> number of channels\n"
     54"\n"
     55"Get number of channels in source.";
     56
     57static char Py_source_do_doc[] = ""
     58"vec, read = x.do() <==> vec, read = x()\n"
     59"\n"
     60"Read monophonic vector from source.";
     61
     62static char Py_source_do_multi_doc[] = ""
     63"mat, read = x.do_multi()\n"
     64"\n"
     65"Read polyphonic vector from source.";
     66
     67static char Py_source_close_doc[] = ""
     68"x.close()\n"
     69"\n"
     70"Close this source now.";
     71
     72static char Py_source_seek_doc[] = ""
     73"x.seek(position)\n"
     74"\n"
     75"Seek to resampled frame position.";
    1476
    1577static PyObject *
     
    2082  uint_t samplerate = 0;
    2183  uint_t hop_size = 0;
    22   static char *kwlist[] = { "uri", "samplerate", "hop_size", NULL };
    23 
    24   if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sII", kwlist,
    25           &uri, &samplerate, &hop_size)) {
     84  uint_t channels = 0;
     85  static char *kwlist[] = { "uri", "samplerate", "hop_size", "channels", NULL };
     86
     87  if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sIII", kwlist,
     88          &uri, &samplerate, &hop_size, &channels)) {
    2689    return NULL;
    2790  }
     
    56119  }
    57120
     121  self->channels = 1;
     122  if ((sint_t)channels >= 0) {
     123    self->channels = channels;
     124  } else if ((sint_t)channels < 0) {
     125    PyErr_SetString (PyExc_ValueError,
     126        "can not use negative value for channels");
     127    return NULL;
     128  }
     129
    58130  return (PyObject *) self;
    59131}
     
    64136  self->o = new_aubio_source ( self->uri, self->samplerate, self->hop_size );
    65137  if (self->o == NULL) {
    66     PyErr_SetString (PyExc_StandardError, "error creating object");
     138    char_t errstr[30 + strlen(self->uri)];
     139    sprintf(errstr, "error creating source with %s", self->uri);
     140    PyErr_SetString (PyExc_StandardError, errstr);
    67141    return -1;
    68142  }
    69143  self->samplerate = aubio_source_get_samplerate ( self->o );
    70   self->channels = aubio_source_get_channels ( self->o );
     144  if (self->channels == 0) {
     145    self->channels = aubio_source_get_channels ( self->o );
     146  }
    71147
    72148  return 0;
     
    136212
    137213AUBIO_MEMBERS_START(source)
    138   {"uri", T_STRING, offsetof (Py_source, uri), READONLY, ""},
    139   {"samplerate", T_INT, offsetof (Py_source, samplerate), READONLY, ""},
    140   {"channels", T_INT, offsetof (Py_source, channels), READONLY, ""},
    141   {"hop_size", T_INT, offsetof (Py_source, hop_size), READONLY, ""},
     214  {"uri", T_STRING, offsetof (Py_source, uri), READONLY,
     215    "path at which the source was created"},
     216  {"samplerate", T_INT, offsetof (Py_source, samplerate), READONLY,
     217    "samplerate at which the source is viewed"},
     218  {"channels", T_INT, offsetof (Py_source, channels), READONLY,
     219    "number of channels found in the source"},
     220  {"hop_size", T_INT, offsetof (Py_source, hop_size), READONLY,
     221    "number of consecutive frames that will be read at each do or do_multi call"},
    142222AUBIO_MEMBERS_STOP(source)
    143223
     
    164244}
    165245
     246static PyObject *
     247Pyaubio_source_seek (Py_source *self, PyObject *args)
     248{
     249  uint_t err = 0;
     250
     251  uint_t position;
     252  if (!PyArg_ParseTuple (args, "I", &position)) {
     253    return NULL;
     254  }
     255
     256  err = aubio_source_seek(self->o, position);
     257  if (err != 0) {
     258    PyErr_SetString (PyExc_ValueError,
     259        "error when seeking in source");
     260    return NULL;
     261  }
     262  Py_RETURN_NONE;
     263}
     264
    166265static PyMethodDef Py_source_methods[] = {
    167266  {"get_samplerate", (PyCFunction) Pyaubio_source_get_samplerate,
    168     METH_NOARGS, ""},
     267    METH_NOARGS, Py_source_get_samplerate_doc},
    169268  {"get_channels", (PyCFunction) Pyaubio_source_get_channels,
    170     METH_NOARGS, ""},
     269    METH_NOARGS, Py_source_get_channels_doc},
     270  {"do", (PyCFunction) Py_source_do,
     271    METH_NOARGS, Py_source_do_doc},
    171272  {"do_multi", (PyCFunction) Py_source_do_multi,
    172     METH_NOARGS, ""},
     273    METH_NOARGS, Py_source_do_multi_doc},
    173274  {"close", (PyCFunction) Pyaubio_source_close,
    174     METH_NOARGS, ""},
     275    METH_NOARGS, Py_source_close_doc},
     276  {"seek", (PyCFunction) Pyaubio_source_seek,
     277    METH_VARARGS, Py_source_seek_doc},
    175278  {NULL} /* sentinel */
    176279};
Note: See TracChangeset for help on using the changeset viewer.