feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change
on this file since 9582713 was
459e46f,
checked in by Paul Brossier <piem@piem.org>, 12 years ago
|
python/demos/: update and add some demos
|
-
Property mode set to
100755
|
File size:
990 bytes
|
Line | |
---|
1 | #! /usr/bin/env python |
---|
2 | |
---|
3 | import sys |
---|
4 | from aubio import onset, source |
---|
5 | from numpy import array, hstack, zeros |
---|
6 | |
---|
7 | win_s = 512 # fft size |
---|
8 | hop_s = win_s / 2 # hop size |
---|
9 | |
---|
10 | if len(sys.argv) < 2: |
---|
11 | print "Usage: %s <filename> [samplerate]" % sys.argv[0] |
---|
12 | sys.exit(1) |
---|
13 | |
---|
14 | filename = sys.argv[1] |
---|
15 | |
---|
16 | samplerate = 0 |
---|
17 | if len( sys.argv ) > 2: samplerate = int(sys.argv[2]) |
---|
18 | |
---|
19 | s = source(filename, samplerate, hop_s) |
---|
20 | samplerate = s.samplerate |
---|
21 | o = onset("default", win_s, hop_s, samplerate) |
---|
22 | |
---|
23 | # onset detection delay, in samples |
---|
24 | # default to 4 blocks delay to catch up with |
---|
25 | delay = 4. * hop_s |
---|
26 | |
---|
27 | # list of onsets, in samples |
---|
28 | onsets = [] |
---|
29 | |
---|
30 | # total number of frames read |
---|
31 | total_frames = 0 |
---|
32 | while True: |
---|
33 | samples, read = s() |
---|
34 | is_onset = o(samples) |
---|
35 | if is_onset: |
---|
36 | this_onset = int(total_frames - delay + is_onset[0] * hop_s) |
---|
37 | print "%f" % (this_onset / float(samplerate)) |
---|
38 | onsets.append(this_onset) |
---|
39 | total_frames += read |
---|
40 | if read < hop_s: break |
---|
41 | #print len(onsets) |
---|
Note: See
TracBrowser
for help on using the repository browser.