feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5sampleryinfft+
Last change
on this file since a203d0e 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 | |
---|
3 | import sys |
---|
4 | from aubio import tempo, source |
---|
5 | |
---|
6 | win_s = 512 # fft size |
---|
7 | hop_s = win_s // 2 # hop size |
---|
8 | |
---|
9 | if len(sys.argv) < 2: |
---|
10 | print("Usage: %s <filename> [samplerate]" % sys.argv[0]) |
---|
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 |
---|
20 | o = tempo("default", win_s, hop_s, samplerate) |
---|
21 | |
---|
22 | # tempo detection delay, in samples |
---|
23 | # default to 4 blocks delay to catch up with |
---|
24 | delay = 4. * hop_s |
---|
25 | |
---|
26 | # list of beats, in samples |
---|
27 | beats = [] |
---|
28 | |
---|
29 | # total number of frames read |
---|
30 | total_frames = 0 |
---|
31 | while 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.