source:
python/demos/demo_onset.py
@
ce49bb5
Last change on this file since ce49bb5 was 4120fbc, checked in by , 9 years ago | |
---|---|
|
|
File size: 744 bytes |
Rev | Line | |
---|---|---|
[e6f7a4a] | 1 | #! /usr/bin/env python |
2 | ||
3 | import sys | |
[2cedc83] | 4 | from aubio import source, onset |
[e6f7a4a] | 5 | |
6 | win_s = 512 # fft size | |
[4120fbc] | 7 | hop_s = win_s // 2 # hop size |
[e6f7a4a] | 8 | |
9 | if len(sys.argv) < 2: | |
[4120fbc] | 10 | print("Usage: %s <filename> [samplerate]" % sys.argv[0]) |
[e6f7a4a] | 11 | sys.exit(1) |
12 | ||
13 | filename = sys.argv[1] | |
14 | ||
15 | samplerate = 0 | |
16 | if len( sys.argv ) > 2: samplerate = int(sys.argv[2]) | |
17 | ||
18 | s = source(filename, samplerate, hop_s) | |
19 | samplerate = s.samplerate | |
[5d5d6b9] | 20 | |
[459e46f] | 21 | o = onset("default", win_s, hop_s, samplerate) |
[e6f7a4a] | 22 | |
[459e46f] | 23 | # list of onsets, in samples |
[e6f7a4a] | 24 | onsets = [] |
[459e46f] | 25 | |
26 | # total number of frames read | |
[e6f7a4a] | 27 | total_frames = 0 |
28 | while True: | |
29 | samples, read = s() | |
[7e9e311] | 30 | if o(samples): |
[4120fbc] | 31 | print("%f" % o.get_last_s()) |
[8b884ef] | 32 | onsets.append(o.get_last()) |
[e6f7a4a] | 33 | total_frames += read |
34 | if read < hop_s: break | |
35 | #print len(onsets) |
Note: See TracBrowser
for help on using the repository browser.