ref: daa0d5ddb8081b3cc2219fe641e622995b934966
parent: 5d5d6b9511f97e818372e70242e7293f6d79be83
author: Paul Brossier <piem@piem.org>
date: Fri Mar 8 14:20:39 EST 2013
demos/demo_waveform_plot.py: improve
--- a/python/demos/demo_waveform_plot.py
+++ b/python/demos/demo_waveform_plot.py
@@ -9,10 +9,10 @@
if not ax:
fig = plt.figure()
ax = fig.add_subplot(111)
- hop_s = 512 # fft window size
+ hop_s = 4096 # block size
allsamples_max = zeros(0,)
- downsample = 2 # to plot n samples / hop_s
+ downsample = 2**3 # to plot n samples / hop_s
a = source(filename, samplerate, hop_s) # source file
if samplerate == 0: samplerate = a.samplerate
@@ -25,6 +25,7 @@
allsamples_max = hstack([allsamples_max, new_maxes])
total_frames += read
if read < hop_s: break
+ print samples.reshape(hop_s/downsample, downsample).shape
allsamples_max = (allsamples_max > 0) * allsamples_max
allsamples_max_times = [ ( float (t) / downsample ) * hop_s for t in range(len(allsamples_max)) ]
@@ -31,8 +32,16 @@
ax.plot(allsamples_max_times, allsamples_max, '-b')
ax.plot(allsamples_max_times, -allsamples_max, '-b')
+ ax.axis(xmin = allsamples_max_times[0], xmax = allsamples_max_times[-1])
+ if allsamples_max_times[-1] / float(samplerate) > 60:
+ ax.set_xlabel('time (mm:ss)')
+ ax.set_xticklabels([ "%02d:%02d" % (t/float(samplerate)/60, (t/float(samplerate))%60) for t in ax.get_xticks()[:-1]], rotation = 50)
+ else:
+ ax.set_xlabel('time (ss.mm)')
+ ax.set_xticklabels([ "%02d.%02d" % (t/float(samplerate), 100*((t/float(samplerate))%1) ) for t in ax.get_xticks()[:-1]], rotation = 50)
if __name__ == '__main__':
+ import matplotlib.pyplot as plt
if len(sys.argv) < 2:
print "Usage: %s <filename>" % sys.argv[0]
else:
@@ -39,4 +48,4 @@
for soundfile in sys.argv[1:]:
get_waveform_plot(soundfile)
# display graph
- show()
+ plt.show()