From c470ad04d596eff648aa8e055d385cda0dcbcad7 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sat, 17 Dec 2016 12:41:41 +0100 Subject: [PATCH] python/demos/demo_notes.py: add simple notes demos --- python/demos/demo_notes.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 python/demos/demo_notes.py diff --git a/python/demos/demo_notes.py b/python/demos/demo_notes.py new file mode 100755 index 00000000..301013a6 --- /dev/null +++ b/python/demos/demo_notes.py @@ -0,0 +1,37 @@ +#! /usr/bin/env python + +import sys +from aubio import source, notes + +if len(sys.argv) < 2: + print("Usage: %s [samplerate]" % sys.argv[0]) + sys.exit(1) + +filename = sys.argv[1] + +downsample = 1 +samplerate = 44100 // downsample +if len( sys.argv ) > 2: samplerate = int(sys.argv[2]) + +win_s = 512 // downsample # fft size +hop_s = 256 // downsample # hop size + +s = source(filename, samplerate, hop_s) +samplerate = s.samplerate + +tolerance = 0.8 + +notes_o = notes("default", win_s, hop_s, samplerate) + +print("%8s" % "time","[ start","vel","last ]") + +# total number of frames read +total_frames = 0 +while True: + samples, read = s() + new_note = notes_o(samples) + if (new_note[0] != 0): + note_str = ' '.join(["%.2f" % i for i in new_note]) + print("%.6f" % (total_frames/float(samplerate)), new_note) + total_frames += read + if read < hop_s: break -- 2.11.0