From: Paul Brossier Date: Mon, 25 Apr 2016 16:05:02 +0000 (+0200) Subject: python/ext/py-source.c: added duration X-Git-Tag: 0.4.4~300^2~207 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=cfa46b931b1c7ab59224f167f01652cef55180ae;p=aubio.git python/ext/py-source.c: added duration --- diff --git a/python/ext/py-source.c b/python/ext/py-source.c index a3096a10..6553b402 100644 --- a/python/ext/py-source.c +++ b/python/ext/py-source.c @@ -8,6 +8,7 @@ typedef struct uint_t samplerate; uint_t channels; uint_t hop_size; + uint_t duration; fvec_t *read_to; fmat_t *mread_to; } Py_source; @@ -146,6 +147,7 @@ Py_source_init (Py_source * self, PyObject * args, PyObject * kwds) if (self->channels == 0) { self->channels = aubio_source_get_channels ( self->o ); } + self->duration = aubio_source_get_duration ( self->o ); self->read_to = new_fvec(self->hop_size); self->mread_to = new_fmat (self->channels, self->hop_size); @@ -226,6 +228,8 @@ static PyMemberDef Py_source_members[] = { "number of channels found in the source"}, {"hop_size", T_INT, offsetof (Py_source, hop_size), READONLY, "number of consecutive frames that will be read at each do or do_multi call"}, + {"duration", T_INT, offsetof (Py_source, duration), READONLY, + "total number of frames in the source (estimated)"}, { NULL } // sentinel }; diff --git a/python/tests/test_source.py b/python/tests/test_source.py index 62b1820e..48bdc674 100755 --- a/python/tests/test_source.py +++ b/python/tests/test_source.py @@ -99,6 +99,17 @@ class aubio_source_read_test_case(aubio_source_test_case_base): b = self.read_from_source(f) assert a == b + c + def test_duration(self): + for p in list_of_sounds: + total_frames = 0 + f = source(p) + duration = f.duration + while True: + vec, read = f() + total_frames += read + if read < f.hop_size: break + self.assertEqual(duration, total_frames) + class aubio_source_readmulti_test_case(aubio_source_read_test_case): def read_from_source(self, f):