summaryrefslogtreecommitdiff
path: root/python/demos/demo_onset.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/demos/demo_onset.py')
-rwxr-xr-xpython/demos/demo_onset.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/python/demos/demo_onset.py b/python/demos/demo_onset.py
new file mode 100755
index 0000000..43e4aed
--- /dev/null
+++ b/python/demos/demo_onset.py
@@ -0,0 +1,35 @@
+#! /usr/bin/env python
+
+import sys
+from aubio import source, onset
+
+win_s = 512 # fft size
+hop_s = win_s // 2 # hop size
+
+if len(sys.argv) < 2:
+ print("Usage: %s <filename> [samplerate]" % sys.argv[0])
+ sys.exit(1)
+
+filename = sys.argv[1]
+
+samplerate = 0
+if len( sys.argv ) > 2: samplerate = int(sys.argv[2])
+
+s = source(filename, samplerate, hop_s)
+samplerate = s.samplerate
+
+o = onset("default", win_s, hop_s, samplerate)
+
+# list of onsets, in samples
+onsets = []
+
+# total number of frames read
+total_frames = 0
+while True:
+ samples, read = s()
+ if o(samples):
+ print("%f" % o.get_last_s())
+ onsets.append(o.get_last())
+ total_frames += read
+ if read < hop_s: break
+#print len(onsets)