From 1eee4053a684d440a181d20022ab1c69e0ada024 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Fri, 22 Mar 2013 11:42:17 -0500 Subject: [PATCH] python/demos/demo_waveform_plot.py: plot more samples, add hop_size parameter, add set_xlabels_sample2time --- python/demos/demo_waveform_plot.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/python/demos/demo_waveform_plot.py b/python/demos/demo_waveform_plot.py index 7ab457a3..41314670 100755 --- a/python/demos/demo_waveform_plot.py +++ b/python/demos/demo_waveform_plot.py @@ -4,15 +4,15 @@ import sys from aubio import pvoc, source from numpy import zeros, hstack -def get_waveform_plot(filename, samplerate = 0, ax = None): +def get_waveform_plot(filename, samplerate = 0, block_size = 4096, ax = None): import matplotlib.pyplot as plt if not ax: fig = plt.figure() ax = fig.add_subplot(111) - hop_s = 4096 # block size + hop_s = block_size allsamples_max = zeros(0,) - downsample = 2**3 # to plot n samples / hop_s + downsample = 2**4 # to plot n samples / hop_s a = source(filename, samplerate, hop_s) # source file if samplerate == 0: samplerate = a.samplerate @@ -25,8 +25,6 @@ def get_waveform_plot(filename, samplerate = 0, ax = None): 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)) ] @@ -34,12 +32,18 @@ def get_waveform_plot(filename, samplerate = 0, ax = None): 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: + set_xlabels_sample2time(ax, allsamples_max_times[-1], samplerate) + return ax + +def set_xlabels_sample2time(ax, latest_sample, samplerate): + if latest_sample / 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: -- 2.26.2