shithub: aubio

Download patch

ref: 3f16b615652d950e2ed57240ee95c251d1b78085
parent: 228e8d80880f3258ed2ae5637afe3338eba76708
author: Paul Brossier <piem@piem.org>
date: Sat Jan 9 10:27:22 EST 2010

demo_beat.py: added simple example

--- /dev/null
+++ b/interfaces/python/demo_beat.py
@@ -1,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