source: python/demos/demo_tempo.py @ 0173e4a

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5
Last change on this file since 0173e4a 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: 943 bytes
Line 
1#! /usr/bin/env python
2
3import sys
4from aubio import tempo, source
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
20o = tempo("default", win_s, hop_s, samplerate)
21
22# tempo detection delay, in samples
23# default to 4 blocks delay to catch up with
24delay = 4. * hop_s
25
26# list of beats, in samples
27beats = []
28
29# total number of frames read
30total_frames = 0
31while True:
32    samples, read = s()
33    is_beat = o(samples)
34    if is_beat:
35        this_beat = int(total_frames - delay + is_beat[0] * hop_s)
36        print("%f" % (this_beat / float(samplerate)))
37        beats.append(this_beat)
38    total_frames += read
39    if read < hop_s: break
40#print len(beats)
Note: See TracBrowser for help on using the repository browser.