ref: cfa46b931b1c7ab59224f167f01652cef55180ae
parent: 6e765ed8db687f82716d65bee04f7c44938f1499
author: Paul Brossier <piem@piem.org>
date: Mon Apr 25 14:05:02 EDT 2016
python/ext/py-source.c: added duration
--- a/python/ext/py-source.c
+++ b/python/ext/py-source.c
@@ -8,6 +8,7 @@
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 @@
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 @@
"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
};
--- a/python/tests/test_source.py
+++ b/python/tests/test_source.py
@@ -99,6 +99,17 @@
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):