source: python/demos/demo_onset.py @ e6f7a4a

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since e6f7a4a was e6f7a4a, checked in by Paul Brossier <piem@piem.org>, 12 years ago

demos/demo_onset.py: add simple onset example, update demo_onset_plot.py

  • Property mode set to 100755
File size: 872 bytes
Line 
1#! /usr/bin/env python
2
3import sys
4from aubio import onset, source
5from numpy import array, hstack, zeros
6
7win_s = 512                 # fft size
8hop_s = win_s / 2           # hop size
9
10if len(sys.argv) < 2:
11    print "Usage: %s <filename> [samplerate]" % sys.argv[0]
12    sys.exit(1)
13
14filename = sys.argv[1]
15
16samplerate = 0
17if len( sys.argv ) > 2: samplerate = int(sys.argv[2])
18
19s = source(filename, samplerate, hop_s)
20samplerate = s.samplerate
21o = onset("default", win_s, hop_s)
22
23# onset detection delay, in blocks
24delay = 4. * hop_s
25
26onsets = []
27total_frames = 0
28while True:
29    samples, read = s()
30    is_onset = o(samples)
31    if is_onset:
32        this_onset = int(total_frames - delay + is_onset[0] * hop_s)
33        print "%f" % (this_onset / float(samplerate))
34        onsets.append(this_onset)
35    total_frames += read
36    if read < hop_s: break
37#print len(onsets)
Note: See TracBrowser for help on using the repository browser.