History

python/demos/demo_onset_file.py: also plot descriptor and thresholded descriptor

Paul Brossier committed 13 years ago

Commit f36277c1 parent ae817261 file · +24 −9Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/demos/demo_onset_file.py+24−9
@@ -19,6 +19,9 @@ onsets = [] · 18 unmodified lines
19s = source(filename, samplerate, hop_s)19s = source(filename, samplerate, hop_s)
20o = onset("default", win_s, hop_s)20o = onset("default", win_s, hop_s)
21 21
22desc = []
23tdesc = []
24
22block_read = 025block_read = 0
23allsamples_max = zeros(0,)26allsamples_max = zeros(0,)
24while True:27while True:
@@ -26,6 +29,8 @@ while True: · 1 unmodified line
26 new_maxes = (abs(samples.reshape(hop_s/downsample, downsample))).max(axis=0)29 new_maxes = (abs(samples.reshape(hop_s/downsample, downsample))).max(axis=0)
27 allsamples_max = hstack([allsamples_max, new_maxes])30 allsamples_max = hstack([allsamples_max, new_maxes])
28 isbeat = o(samples)31 isbeat = o(samples)
32 desc.append(o.get_descriptor())
33 tdesc.append(o.get_thresholded_descriptor())
29 if isbeat:34 if isbeat:
30 thisbeat = (block_read - 4. + isbeat[0]) * hop_s / samplerate35 thisbeat = (block_read - 4. + isbeat[0]) * hop_s / samplerate
31 print "%.4f" % thisbeat36 print "%.4f" % thisbeat
@@ -35,14 +40,24 @@ while True: · 3 unmodified lines
35 40
36# do plotting41# do plotting
37from numpy import arange42from numpy import arange
38from pylab import plot, show, xlabel, ylabel, legend, ylim, subplot, axis43import matplotlib.pyplot as plt
39allsamples_max = (allsamples_max > 0) * allsamples_max44allsamples_max = (allsamples_max > 0) * allsamples_max
40allsamples_max_times = [ float(t) * hop_s / downsample / samplerate for t in range(len(allsamples_max)) ]45allsamples_max_times = [ float(t) * hop_s / downsample / samplerate for t in range(len(allsamples_max)) ]
41plot(allsamples_max_times, allsamples_max, '-b')46plt1 = plt.axes([0.1, 0.75, 0.8, 0.19])
42plot(allsamples_max_times, -allsamples_max, '-b')47plt2 = plt.axes([0.1, 0.1, 0.8, 0.65], sharex = plt1)
43axis(xmin = 0., xmax = max(allsamples_max_times) )48plt.rc('lines',linewidth='.8')
44for stamp in onsets: plot([stamp, stamp], [-1., 1.], '.-r')49plt1.plot(allsamples_max_times, allsamples_max, '-b')
45xlabel('time (s)')50plt1.plot(allsamples_max_times, -allsamples_max, '-b')
46ylabel('amplitude')51for stamp in onsets: plt1.plot([stamp, stamp], [-1., 1.], '-r')
47show()52plt1.axis(xmin = 0., xmax = max(allsamples_max_times) )
48 53plt1.xaxis.set_visible(False)
54desc_times = [ float(t) * hop_s / samplerate for t in range(len(desc)) ]
55desc_plot = [d / max(desc) for d in desc]
56plt2.plot(desc_times, desc_plot, '-g')
57tdesc_plot = [d / max(desc) for d in tdesc]
58for stamp in onsets: plt2.plot([stamp, stamp], [min(tdesc_plot), max(desc_plot)], '-r')
59plt2.plot(desc_times, tdesc_plot, '-y')
60plt2.axis(ymin = min(tdesc_plot), ymax = max(desc_plot))
61plt.xlabel('time (s)')
62#plt.savefig('/tmp/t.png', dpi=200)
63plt.show()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t