3 from numpy import random, sin, arange, ones, zeros
5 from aubio import fvec, onset
7 def build_sinusoid(length, freqs, samplerate):
8 return sin( 2. * pi * arange(length) * freqs / samplerate)
10 def run_onset(p, input_vec):
14 for vec_slice in input_vec.reshape((-1, p.hop_size)):
40 sin_length = (samplerate * 10) % 512 * 512
41 freqs = zeros(sin_length)
43 partition = sin_length / 8
47 freqs[pointer: pointer + partition] = 440
51 freqs[ pointer : pointer + partition ] = 740
54 freqs[ pointer : pointer + partition ] = 1480
58 freqs[ pointer : pointer + partition ] = 400 + 5 * random.random(sin_length/8)
60 a = build_sinusoid(sin_length, freqs, samplerate)
62 for method in methods:
63 o = onset(method, buf_size, hop_size, samplerate)
64 cands[method] = run_onset(o, a)
66 print "done computing"
69 from pylab import plot, show, xlabel, ylabel, legend, ylim, subplot
71 legend(methods+['ground truth'], 'upper right')
74 ramp = arange(0, sin_length).astype('float') / samplerate
77 ramp = arange(0, sin_length / hop_size).astype('float') * hop_size / samplerate
78 for method in methods:
79 plot(ramp, cands[method],'.-')
80 legend(methods, 'upper right')
82 ylabel('spectral descriptor value')