- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/demos/demo_waveform_plot.py
rdaa0d5d r1e90588 5 5 from numpy import zeros, hstack 6 6 7 def get_waveform_plot(filename, samplerate = 0, ax = None):7 def get_waveform_plot(filename, samplerate = 0, block_size = 4096, ax = None): 8 8 import matplotlib.pyplot as plt 9 9 if not ax: 10 10 fig = plt.figure() 11 11 ax = fig.add_subplot(111) 12 hop_s = 4096 # blocksize12 hop_s = block_size 13 13 14 14 allsamples_max = zeros(0,) 15 downsample = 2** 3# to plot n samples / hop_s15 downsample = 2**4 # to plot n samples / hop_s 16 16 17 17 a = source(filename, samplerate, hop_s) # source file … … 26 26 total_frames += read 27 27 if read < hop_s: break 28 print samples.reshape(hop_s/downsample, downsample).shape29 30 28 allsamples_max = (allsamples_max > 0) * allsamples_max 31 29 allsamples_max_times = [ ( float (t) / downsample ) * hop_s for t in range(len(allsamples_max)) ] … … 35 33 ax.axis(xmin = allsamples_max_times[0], xmax = allsamples_max_times[-1]) 36 34 37 if allsamples_max_times[-1] / float(samplerate) > 60: 35 set_xlabels_sample2time(ax, allsamples_max_times[-1], samplerate) 36 return ax 37 38 def set_xlabels_sample2time(ax, latest_sample, samplerate): 39 ax.axis(xmin = 0, xmax = latest_sample) 40 if latest_sample / float(samplerate) > 60: 38 41 ax.set_xlabel('time (mm:ss)') 39 42 ax.set_xticklabels([ "%02d:%02d" % (t/float(samplerate)/60, (t/float(samplerate))%60) for t in ax.get_xticks()[:-1]], rotation = 50) … … 41 44 ax.set_xlabel('time (ss.mm)') 42 45 ax.set_xticklabels([ "%02d.%02d" % (t/float(samplerate), 100*((t/float(samplerate))%1) ) for t in ax.get_xticks()[:-1]], rotation = 50) 46 47 43 48 if __name__ == '__main__': 44 49 import matplotlib.pyplot as plt
Note: See TracChangeset
for help on using the changeset viewer.