source: python/demos/demo_onset.py @ 33102ab

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 33102ab was 5d5d6b9, checked in by Paul Brossier <piem@piem.org>, 12 years ago

python/demos: add demo_pitch.py and demo_waveform_plot.py

  • Property mode set to 100755
File size: 952 bytes
RevLine 
[e6f7a4a]1#! /usr/bin/env python
2
3import sys
[2cedc83]4from aubio import source, onset
[e6f7a4a]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
[5d5d6b9]20
[459e46f]21o = onset("default", win_s, hop_s, samplerate)
[e6f7a4a]22
[459e46f]23# onset detection delay, in samples
24# default to 4 blocks delay to catch up with
[e6f7a4a]25delay = 4. * hop_s
26
[459e46f]27# list of onsets, in samples
[e6f7a4a]28onsets = []
[459e46f]29
30# total number of frames read
[e6f7a4a]31total_frames = 0
32while 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.