Ignore:
Timestamp:
Jun 22, 2016, 1:00:10 PM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
4b9443c4
Parents:
60fc05b (diff), 6769586 (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.
Message:

Merge branch 'master' into notes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/demos/demo_pitch_sinusoid.py

    r60fc05b rf264b17  
    11#! /usr/bin/env python
    22
    3 from numpy import random, sin, arange, ones, zeros
    4 from math import pi
    5 from aubio import fvec, pitch
     3import numpy as np
     4import aubio
    65
    76def 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)
    98
    109def 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
    1815
    1916methods = ['default', 'schmitt', 'fcomb', 'mcomb', 'yin', 'yinfft']
     
    2421samplerate = 44100
    2522sin_length = (samplerate * 10) % 512 * 512
    26 freqs = zeros(sin_length)
     23freqs = np.zeros(sin_length)
    2724
    28 partition = sin_length / 8
     25partition = sin_length // 8
    2926pointer = 0
    3027
     
    4138pointer += partition
    4239pointer += partition
    43 freqs[ pointer : pointer + partition ] = 400 + 5 * random.random(sin_length/8)
     40freqs[ pointer : pointer + partition ] = 400 + 5 * np.random.random(sin_length/8)
    4441
    4542a = build_sinusoid(sin_length, freqs, samplerate)
    4643
    4744for 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])
    5049
    51 print "done computing"
     50print("done computing")
    5251
    5352if 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
    5854
    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
    6257
    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)
    6861
     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.