Changeset 155cc10 for python/demos/demo_pitch_sinusoid.py
- Timestamp:
- Mar 10, 2017, 2:26:32 PM (7 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, sampler
- Children:
- ee8a57c
- Parents:
- 00d0275 (diff), 67b6618 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/demos/demo_pitch_sinusoid.py
r00d0275 r155cc10 1 1 #! /usr/bin/env python 2 2 3 from numpy import random, sin, arange, ones, zeros 4 from math import pi 5 from aubio import fvec, pitch 3 import numpy as np 4 import aubio 6 5 7 6 def build_sinusoid(length, freqs, samplerate): 8 return sin( 2. * pi * arange(length) * freqs / samplerate)7 return np.sin( 2. * np.pi * np.arange(length) * freqs / samplerate).astype(aubio.float_type) 9 8 10 9 def run_pitch(p, input_vec): 11 f = fvec (p.hop_size) 12 cands = [] 13 count = 0 14 for vec_slice in input_vec.reshape((-1, p.hop_size)): 15 f[:] = vec_slice 16 cands.append(p(f)) 17 return cands 10 cands = [] 11 for vec_slice in input_vec.reshape((-1, p.hop_size)): 12 a = p(vec_slice)[0] 13 cands.append(a) 14 return cands 18 15 19 16 methods = ['default', 'schmitt', 'fcomb', 'mcomb', 'yin', 'yinfft'] … … 24 21 samplerate = 44100 25 22 sin_length = (samplerate * 10) % 512 * 512 26 freqs = zeros(sin_length)23 freqs = np.zeros(sin_length) 27 24 28 partition = sin_length / 825 partition = sin_length // 8 29 26 pointer = 0 30 27 … … 41 38 pointer += partition 42 39 pointer += partition 43 freqs[ pointer : pointer + partition ] = 400 + 5 * random.random(sin_length/8)40 freqs[ pointer : pointer + partition ] = 400 + 5 * np.random.random(sin_length/8) 44 41 45 42 a = build_sinusoid(sin_length, freqs, samplerate) 46 43 47 44 for method in methods: 48 p = pitch(method, buf_size, hop_size, samplerate) 49 cands[method] = run_pitch(p, a) 45 p = aubio.pitch(method, buf_size, hop_size, samplerate) 46 cands[method] = run_pitch(p, a) 47 print(method) 48 print(cands[method]) 50 49 51 print "done computing"50 print("done computing") 52 51 53 52 if 1: 54 from pylab import plot, show, xlabel, ylabel, legend, ylim 55 ramp = arange(0, sin_length / hop_size).astype('float') * hop_size / samplerate 56 for method in methods: 57 plot(ramp, cands[method],'.-') 53 import matplotlib.pyplot as plt 58 54 59 # plot ground truth 60 ramp = arange(0, sin_length).astype('float') / samplerate 61 plot(ramp, freqs, ':') 55 # times 56 ramp = np.arange(0, sin_length / hop_size).astype('float') * hop_size / samplerate 62 57 63 legend(methods+['ground truth'], 'upper right') 64 xlabel('time (s)') 65 ylabel('frequency (Hz)') 66 ylim([0,2000]) 67 show() 58 # plot each result 59 for method in methods: 60 plt.plot(ramp, cands[method], '.-', label=method) 68 61 62 # plot ground truth 63 ramp = np.arange(0, sin_length).astype('float') / samplerate 64 plt.plot(ramp, freqs, ':', label = 'ground truth') 65 66 plt.legend(loc='upper left') 67 68 plt.xlabel('time (s)') 69 plt.ylabel('frequency (Hz)') 70 plt.ylim([0,2000]) 71 plt.show()
Note: See TracChangeset
for help on using the changeset viewer.