feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5
Last change
on this file since 09894ba3 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
|
Rev | Line | |
---|
[459e46f] | 1 | #! /usr/bin/env python |
---|
| 2 | |
---|
| 3 | import sys |
---|
| 4 | from aubio import tempo, source |
---|
| 5 | |
---|
| 6 | win_s = 512 # fft size |
---|
[4120fbc] | 7 | hop_s = win_s // 2 # hop size |
---|
[459e46f] | 8 | |
---|
| 9 | if len(sys.argv) < 2: |
---|
[4120fbc] | 10 | print("Usage: %s <filename> [samplerate]" % sys.argv[0]) |
---|
[459e46f] | 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) |
---|
[4120fbc] | 36 | print("%f" % (this_beat / float(samplerate))) |
---|
[459e46f] | 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.