source: python/demos/demo_onset.py @ 1c565c0

feature/autosinkfeature/cnnfeature/crepefix/ffmpeg5
Last change on this file since 1c565c0 was 4120fbc, checked in by Paul Brossier <piem@piem.org>, 9 years ago

python/demos: python3 and double precision compatibility

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