From e76eaf171d6d3e9245a6a2ccd8c5a62c38ba9729 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Tue, 5 Mar 2013 17:11:46 -0500 Subject: [PATCH] demos/demo_sink.py: add samplerate and hop_size options --- python/demos/demo_sink.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/python/demos/demo_sink.py b/python/demos/demo_sink.py index 702838c5..8a5b587c 100755 --- a/python/demos/demo_sink.py +++ b/python/demos/demo_sink.py @@ -5,13 +5,24 @@ from aubio import source, sink if __name__ == '__main__': if len(sys.argv) < 3: - print 'usage: %s ' % sys.argv[0] + print 'usage: %s [samplerate] [hop_size]' % sys.argv[0] sys.exit(1) - f = source(sys.argv[1], 8000, 256) - g = sink(sys.argv[2], 8000) - total_frames, read = 0, 256 + + if len(sys.argv) > 3: samplerate = int(sys.argv[3]) + else: samplerate = 0 + if len(sys.argv) > 4: hop_size = int(sys.argv[4]) + else: hop_size = 256 + + f = source(sys.argv[1], samplerate, hop_size) + if samplerate == 0: samplerate = f.samplerate + g = sink(sys.argv[2], samplerate) + + total_frames, read = 0, hop_size while read: vec, read = f() g(vec, read) total_frames += read - print "read", total_frames / float(f.samplerate), "seconds from", f.uri + print "wrote", "%.2fs" % (total_frames / float(samplerate) ), + print "(", total_frames, "frames", "in", total_frames % hop_size, "blocks", "at", "%dHz" % samplerate, ")", + print "from", f.uri, + print "to", g.uri -- 2.26.2