From e253a8616c70ef92de12c84faa0af3cffe0eb54a Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Wed, 6 Mar 2013 15:49:32 -0500 Subject: [PATCH] demos/demo_source.py: indent, add samplerate and hop_size options --- python/demos/demo_source.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/python/demos/demo_source.py b/python/demos/demo_source.py index 3b9c9636..30318b1d 100755 --- a/python/demos/demo_source.py +++ b/python/demos/demo_source.py @@ -4,13 +4,23 @@ import sys from aubio import source if __name__ == '__main__': - if len(sys.argv) < 2: - print 'usage: %s ' % sys.argv[0] - sys.exit(1) - f = source(sys.argv[1], 1, 256) - samplerate = f.get_samplerate() - total_frames, read = 0, 256 - while read: - vec, read = f() - total_frames += read - print "read", total_frames / float(samplerate), "seconds from", f.uri + if len(sys.argv) < 2: + print 'usage: %s [samplerate] [hop_size]' % sys.argv[0] + sys.exit(1) + samplerate = 0 + hop_size = 256 + if len(sys.argv) > 2: samplerate = int(sys.argv[2]) + if len(sys.argv) > 3: hop_size = int(sys.argv[3]) + + f = source(sys.argv[1], samplerate, hop_size) + samplerate = f.samplerate + + total_frames, read = 0, f.hop_size + while read: + vec, read = f() + total_frames += read + if read < f.hop_size: break + print "read", "%.2fs" % (total_frames / float(samplerate) ), + print "(", total_frames, "frames", "in", + print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")", + print "from", f.uri -- 2.26.2