[7175ed4] | 1 | #! /usr/bin/env python |
---|
[6639eb1] | 2 | |
---|
[5d5d6b9] | 3 | import sys |
---|
| 4 | from aubio import fvec, source, pvoc, specdesc |
---|
| 5 | from numpy import hstack |
---|
[6639eb1] | 6 | |
---|
[5d5d6b9] | 7 | win_s = 512 # fft size |
---|
| 8 | hop_s = win_s / 4 # hop size |
---|
[6639eb1] | 9 | |
---|
[5d5d6b9] | 10 | if len(sys.argv) < 2: |
---|
| 11 | print "Usage: %s <filename> [samplerate]" % sys.argv[0] |
---|
| 12 | sys.exit(1) |
---|
[6639eb1] | 13 | |
---|
[5d5d6b9] | 14 | filename = sys.argv[1] |
---|
[6639eb1] | 15 | |
---|
[5d5d6b9] | 16 | samplerate = 0 |
---|
| 17 | if len( sys.argv ) > 2: samplerate = int(sys.argv[2]) |
---|
[6639eb1] | 18 | |
---|
[5d5d6b9] | 19 | s = source(filename, samplerate, hop_s) |
---|
| 20 | samplerate = s.samplerate |
---|
[6639eb1] | 21 | |
---|
[5d5d6b9] | 22 | pv = pvoc(win_s, hop_s) |
---|
[6639eb1] | 23 | |
---|
[6ff6d18] | 24 | methods = ['default', 'energy', 'hfc', 'complex', 'phase', 'specdiff', 'kl', |
---|
| 25 | 'mkl', 'specflux', 'centroid', 'slope', 'rolloff', 'spread', 'skewness', |
---|
| 26 | 'kurtosis', 'decrease',] |
---|
[6639eb1] | 27 | |
---|
[5d5d6b9] | 28 | all_descs = {} |
---|
| 29 | o = {} |
---|
[6639eb1] | 30 | |
---|
| 31 | for method in methods: |
---|
[5d5d6b9] | 32 | cands = [] |
---|
| 33 | all_descs[method] = fvec(0) |
---|
| 34 | o[method] = specdesc(method, win_s) |
---|
| 35 | |
---|
| 36 | total_frames = 0 |
---|
| 37 | downsample = 2 |
---|
[6639eb1] | 38 | |
---|
[5d5d6b9] | 39 | while True: |
---|
| 40 | samples, read = s() |
---|
| 41 | fftgrain = pv(samples) |
---|
[6ff6d18] | 42 | #print "%f" % ( total_frames / float(samplerate) ), |
---|
[5d5d6b9] | 43 | for method in methods: |
---|
| 44 | specdesc_val = o[method](fftgrain)[0] |
---|
| 45 | all_descs[method] = hstack ( [all_descs[method], specdesc_val] ) |
---|
[6ff6d18] | 46 | #print "%f" % specdesc_val, |
---|
| 47 | #print |
---|
[5d5d6b9] | 48 | total_frames += read |
---|
| 49 | if read < hop_s: break |
---|
[6639eb1] | 50 | |
---|
| 51 | if 1: |
---|
[5d5d6b9] | 52 | print "done computing, now plotting" |
---|
| 53 | import matplotlib.pyplot as plt |
---|
| 54 | from demo_waveform_plot import get_waveform_plot |
---|
[6ff6d18] | 55 | from demo_waveform_plot import set_xlabels_sample2time |
---|
[5d5d6b9] | 56 | fig = plt.figure() |
---|
| 57 | plt.rc('lines',linewidth='.8') |
---|
| 58 | wave = plt.axes([0.1, 0.75, 0.8, 0.19]) |
---|
[6ff6d18] | 59 | get_waveform_plot(filename, samplerate, block_size = hop_s, ax = wave ) |
---|
[5d5d6b9] | 60 | wave.yaxis.set_visible(False) |
---|
| 61 | wave.xaxis.set_visible(False) |
---|
[6639eb1] | 62 | |
---|
[5d5d6b9] | 63 | all_desc_times = [ x * hop_s for x in range(len(all_descs["default"])) ] |
---|
| 64 | n_methods = len(methods) |
---|
| 65 | for i, method in enumerate(methods): |
---|
| 66 | #ax = fig.add_subplot (n_methods, 1, i) |
---|
| 67 | #plt2 = plt.axes([0.1, 0.1, 0.8, 0.65], sharex = plt1) |
---|
| 68 | ax = plt.axes ( [0.1, 0.75 - ((i+1) * 0.65 / n_methods), 0.8, 0.65 / n_methods], sharex = wave ) |
---|
| 69 | ax.plot(all_desc_times, all_descs[method], '-', label = method) |
---|
| 70 | #ax.set_ylabel(method, rotation = 0) |
---|
| 71 | ax.xaxis.set_visible(False) |
---|
| 72 | ax.yaxis.set_visible(False) |
---|
| 73 | ax.axis(xmax = all_desc_times[-1], xmin = all_desc_times[0]) |
---|
[4f2c28c] | 74 | ax.annotate(method, xy=(-10, 0), xycoords='axes points', |
---|
[5d5d6b9] | 75 | horizontalalignment='right', verticalalignment='bottom', |
---|
| 76 | ) |
---|
[6ff6d18] | 77 | set_xlabels_sample2time(ax, all_desc_times[-1], samplerate) |
---|
[5d5d6b9] | 78 | #plt.ylabel('spectral descriptor value') |
---|
| 79 | ax.xaxis.set_visible(True) |
---|
| 80 | plt.show() |
---|