History

demos/demo_waveform_plot.py: improve

Paul Brossier committed 13 years ago

Commit daa0d5d1 parent 5d5d6b91 file · +12 −3Browse files

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

Unified · Split

python/demos/demo_waveform_plot.py+12−3
@@ -9,10 +9,10 @@ def get_waveform_plot(filename, samplerate = 0, ax = None): · 8 unmodified lines
9 if not ax:9 if not ax:
10 fig = plt.figure()10 fig = plt.figure()
11 ax = fig.add_subplot(111)11 ax = fig.add_subplot(111)
12 hop_s = 512 # fft window size12 hop_s = 4096 # block size
13 13
14 allsamples_max = zeros(0,)14 allsamples_max = zeros(0,)
15 downsample = 2 # to plot n samples / hop_s15 downsample = 2**3 # to plot n samples / hop_s
16 16
17 a = source(filename, samplerate, hop_s) # source file17 a = source(filename, samplerate, hop_s) # source file
18 if samplerate == 0: samplerate = a.samplerate18 if samplerate == 0: samplerate = a.samplerate
@@ -25,18 +25,27 @@ def get_waveform_plot(filename, samplerate = 0, ax = None): · 6 unmodified lines
25 allsamples_max = hstack([allsamples_max, new_maxes])25 allsamples_max = hstack([allsamples_max, new_maxes])
26 total_frames += read26 total_frames += read
27 if read < hop_s: break27 if read < hop_s: break
28 print samples.reshape(hop_s/downsample, downsample).shape
28 29
29 allsamples_max = (allsamples_max > 0) * allsamples_max30 allsamples_max = (allsamples_max > 0) * allsamples_max
30 allsamples_max_times = [ ( float (t) / downsample ) * hop_s for t in range(len(allsamples_max)) ]31 allsamples_max_times = [ ( float (t) / downsample ) * hop_s for t in range(len(allsamples_max)) ]
31 32
32 ax.plot(allsamples_max_times, allsamples_max, '-b')33 ax.plot(allsamples_max_times, allsamples_max, '-b')
33 ax.plot(allsamples_max_times, -allsamples_max, '-b')34 ax.plot(allsamples_max_times, -allsamples_max, '-b')
35 ax.axis(xmin = allsamples_max_times[0], xmax = allsamples_max_times[-1])
34 36
37 if allsamples_max_times[-1] / float(samplerate) > 60:
38 ax.set_xlabel('time (mm:ss)')
39 ax.set_xticklabels([ "%02d:%02d" % (t/float(samplerate)/60, (t/float(samplerate))%60) for t in ax.get_xticks()[:-1]], rotation = 50)
40 else:
41 ax.set_xlabel('time (ss.mm)')
42 ax.set_xticklabels([ "%02d.%02d" % (t/float(samplerate), 100*((t/float(samplerate))%1) ) for t in ax.get_xticks()[:-1]], rotation = 50)
35if __name__ == '__main__':43if __name__ == '__main__':
44 import matplotlib.pyplot as plt
36 if len(sys.argv) < 2:45 if len(sys.argv) < 2:
37 print "Usage: %s <filename>" % sys.argv[0]46 print "Usage: %s <filename>" % sys.argv[0]
38 else:47 else:
39 for soundfile in sys.argv[1:]:48 for soundfile in sys.argv[1:]:
40 get_waveform_plot(soundfile)49 get_waveform_plot(soundfile)
41 # display graph50 # display graph
42 show()51 plt.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