Changeset 11b49d7 for python


Ignore:
Timestamp:
Sep 21, 2014, 2:42:08 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:
74dcddb
Parents:
24931d5
Message:

python/ext/py-source.c: add seek, thanks @davebrent for the heads up

Location:
python
Files:
2 edited

Legend:

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

    r24931d5 r11b49d7  
    6969"\n"
    7070"Close this source now.";
     71
     72static char Py_source_seek_doc[] = ""
     73"x.seek(position)\n"
     74"\n"
     75"Seek to resampled frame position.";
    7176
    7277static PyObject *
     
    236241{
    237242  aubio_source_close (self->o);
     243  Py_RETURN_NONE;
     244}
     245
     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  }
    238262  Py_RETURN_NONE;
    239263}
     
    250274  {"close", (PyCFunction) Pyaubio_source_close,
    251275    METH_NOARGS, Py_source_close_doc},
     276  {"seek", (PyCFunction) Pyaubio_source_seek,
     277    METH_VARARGS, Py_source_seek_doc},
    252278  {NULL} /* sentinel */
    253279};
  • python/tests/test_source.py

    r24931d5 r11b49d7  
    3333class aubio_source_read_test_case(aubio_source_test_case_base):
    3434
    35     def read_from_sink(self, f):
     35    def read_from_source(self, f):
    3636        total_frames = 0
    3737        while True:
     
    4343        print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
    4444        print "from", f.uri
     45        return total_frames
    4546
    4647    def test_samplerate_hopsize(self):
     
    4950                f = source(p, samplerate, hop_size)
    5051                assert f.samplerate != 0
    51                 self.read_from_sink(f)
     52                self.read_from_source(f)
    5253
    5354    def test_samplerate_none(self):
     
    5556            f = source(p)
    5657            assert f.samplerate != 0
    57             self.read_from_sink(f)
     58            self.read_from_source(f)
    5859
    5960    def test_samplerate_0(self):
     
    6162            f = source(p, 0)
    6263            assert f.samplerate != 0
    63             self.read_from_sink(f)
     64            self.read_from_source(f)
    6465
    6566    def test_wrong_samplerate(self):
     
    8687            assert f.samplerate != 0
    8788            assert f.hop_size != 0
    88             self.read_from_sink(f)
     89            self.read_from_source(f)
     90
     91    def test_seek_to_half(self):
     92        from random import randint
     93        for p in list_of_sounds:
     94            f = source(p, 0, 0)
     95            assert f.samplerate != 0
     96            assert f.hop_size != 0
     97            a = self.read_from_source(f)
     98            c = randint(0, a)
     99            f.seek(c)
     100            b = self.read_from_source(f)
     101            assert a == b + c
    89102
    90103class aubio_source_readmulti_test_case(aubio_source_read_test_case):
    91104
    92     def read_from_sink(self, f):
     105    def read_from_source(self, f):
    93106        total_frames = 0
    94107        while True:
     
    101114        print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
    102115        print "from", f.uri
     116        return total_frames
    103117
    104118if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.