feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change
on this file since 2fcb973 was
26adcfb,
checked in by Paul Brossier <piem@piem.org>, 12 years ago
|
moved tests to subdirectory
|
-
Property mode set to
100755
|
File size:
875 bytes
|
Rev | Line | |
---|
[7175ed4] | 1 | #! /usr/bin/env python |
---|
[3bba0e0] | 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 | samplerate = 44100 |
---|
| 9 | |
---|
| 10 | if len(sys.argv) < 2: |
---|
| 11 | print "Usage: %s <filename>" % sys.argv[0] |
---|
| 12 | sys.exit(1) |
---|
| 13 | |
---|
| 14 | filename = sys.argv[1] |
---|
| 15 | beats = [] |
---|
| 16 | |
---|
| 17 | s = source(filename, samplerate, hop_s) |
---|
| 18 | t = tempo("default", win_s, hop_s) |
---|
| 19 | |
---|
| 20 | block_read = 0 |
---|
| 21 | while True: |
---|
| 22 | samples, read = s() |
---|
| 23 | isbeat = t(samples) |
---|
| 24 | if isbeat: |
---|
| 25 | thisbeat = (block_read * hop_s + isbeat[0]) / samplerate |
---|
| 26 | print "%.4f" % thisbeat |
---|
| 27 | beats.append (thisbeat) |
---|
| 28 | block_read += 1 |
---|
| 29 | if read < hop_s: break |
---|
| 30 | |
---|
| 31 | periods = [60./(b - a) for a,b in zip(beats[:-1],beats[1:])] |
---|
| 32 | |
---|
| 33 | from numpy import mean, median |
---|
| 34 | print 'mean period:', mean(periods), 'bpm' |
---|
| 35 | print 'median period:', median(periods), 'bpm' |
---|
| 36 | |
---|
| 37 | from pylab import plot, show |
---|
| 38 | plot(beats[1:], periods) |
---|
| 39 | show() |
---|
Note: See
TracBrowser
for help on using the repository browser.