source: python/demos/demo_notes.py @ 7a02ce9

feature/cnnfeature/crepefeature/timestretchfix/ffmpeg5
Last change on this file since 7a02ce9 was c470ad0, checked in by Paul Brossier <piem@piem.org>, 8 years ago

python/demos/demo_notes.py: add simple notes demos

  • Property mode set to 100755
File size: 877 bytes
Line 
1#! /usr/bin/env python
2
3import sys
4from aubio import source, notes
5
6if len(sys.argv) < 2:
7    print("Usage: %s <filename> [samplerate]" % sys.argv[0])
8    sys.exit(1)
9
10filename = sys.argv[1]
11
12downsample = 1
13samplerate = 44100 // downsample
14if len( sys.argv ) > 2: samplerate = int(sys.argv[2])
15
16win_s = 512 // downsample # fft size
17hop_s = 256 // downsample # hop size
18
19s = source(filename, samplerate, hop_s)
20samplerate = s.samplerate
21
22tolerance = 0.8
23
24notes_o = notes("default", win_s, hop_s, samplerate)
25
26print("%8s" % "time","[ start","vel","last ]")
27
28# total number of frames read
29total_frames = 0
30while True:
31    samples, read = s()
32    new_note = notes_o(samples)
33    if (new_note[0] != 0):
34        note_str = ' '.join(["%.2f" % i for i in new_note])
35        print("%.6f" % (total_frames/float(samplerate)), new_note)
36    total_frames += read
37    if read < hop_s: break
Note: See TracBrowser for help on using the repository browser.