demo_beat.py: added simple example
authorPaul Brossier <piem@piem.org>
Sat, 9 Jan 2010 14:27:22 +0000 (15:27 +0100)
committerPaul Brossier <piem@piem.org>
Sat, 9 Jan 2010 14:27:22 +0000 (15:27 +0100)
interfaces/python/demo_beat.py [new file with mode: 0644]

diff --git a/interfaces/python/demo_beat.py b/interfaces/python/demo_beat.py
new file mode 100644 (file)
index 0000000..f3c669c
--- /dev/null
@@ -0,0 +1,28 @@
+#! /usr/bin/python
+
+import sys
+from os.path import splitext, basename
+from aubio import tempo 
+from aubioinput import aubioinput
+
+win_s = 512                 # fft size
+hop_s = win_s / 2           # hop size
+beat = tempo("default", win_s, hop_s)
+
+beats = []
+
+def process(samples, pos):
+    isbeat = beat(samples)
+    if isbeat:
+        thisbeat = (float(isbeat[0]) + pos * hop_s) / 44100.
+        print thisbeat
+        beats.append (thisbeat)
+
+if len(sys.argv) < 2:
+    print "Usage: %s <filename>" % sys.argv[0]
+else:
+    filename = sys.argv[1]
+    a = aubioinput(filename, process = process, hopsize = hop_s,
+            caps = 'audio/x-raw-float, rate=44100, channels=1')
+    a.run()
+    print beats