source: python/demos/demo_pitch_sinusoid.py @ 8fb567c

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

python/demos: remove unused import and variables

  • Property mode set to 100755
File size: 1.6 KB
RevLine 
[7175ed4]1#! /usr/bin/env python
[e4c2169]2
[8fb567c]3from numpy import random, sin, arange, zeros
[e4c2169]4from math import pi
5from aubio import fvec, pitch
6
7def build_sinusoid(length, freqs, samplerate):
8  return sin( 2. * pi * arange(length) * freqs / samplerate)
9
10def run_pitch(p, input_vec):
11  f = fvec (p.hop_size)
12  cands = []
13  for vec_slice in input_vec.reshape((-1, p.hop_size)):
14    f[:] = vec_slice
15    cands.append(p(f))
16  return cands
17
18methods = ['default', 'schmitt', 'fcomb', 'mcomb', 'yin', 'yinfft']
19
20cands = {}
21buf_size = 2048
22hop_size = 512
23samplerate = 44100
24sin_length = (samplerate * 10) % 512 * 512
25freqs = zeros(sin_length)
26
27partition = sin_length / 8
28pointer = 0
29
30pointer += partition
31freqs[pointer: pointer + partition] = 440
32
33pointer += partition
34pointer += partition
35freqs[ pointer : pointer + partition ] = 740
36
37pointer += partition
38freqs[ pointer : pointer + partition ] = 1480
39
40pointer += partition
41pointer += partition
42freqs[ pointer : pointer + partition ] = 400 + 5 * random.random(sin_length/8)
43
44a = build_sinusoid(sin_length, freqs, samplerate)
45
46for method in methods:
47  p = pitch(method, buf_size, hop_size, samplerate)
48  cands[method] = run_pitch(p, a)
49
50print "done computing"
51
52if 1:
53  from pylab import plot, show, xlabel, ylabel, legend, ylim
54  ramp = arange(0, sin_length / hop_size).astype('float') * hop_size / samplerate
55  for method in methods:
56    plot(ramp, cands[method],'.-')
57
58  # plot ground truth
59  ramp = arange(0, sin_length).astype('float') / samplerate
60  plot(ramp, freqs, ':')
61
62  legend(methods+['ground truth'], 'upper right')
63  xlabel('time (s)')
64  ylabel('frequency (Hz)')
65  ylim([0,2000])
66  show()
67
Note: See TracBrowser for help on using the repository browser.