Changeset 1eee405 for python/demos


Ignore:
Timestamp:
Mar 22, 2013, 5:42:17 PM (11 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
1e90588
Parents:
b429b68
Message:

python/demos/demo_waveform_plot.py: plot more samples, add hop_size parameter, add set_xlabels_sample2time

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/demos/demo_waveform_plot.py

    rb429b68 r1eee405  
    55from numpy import zeros, hstack
    66
    7 def get_waveform_plot(filename, samplerate = 0, ax = None):
     7def get_waveform_plot(filename, samplerate = 0, block_size = 4096, ax = None):
    88    import matplotlib.pyplot as plt
    99    if not ax:
    1010        fig = plt.figure()
    1111        ax = fig.add_subplot(111)
    12     hop_s = 4096 # block size
     12    hop_s = block_size
    1313
    1414    allsamples_max = zeros(0,)
    15     downsample = 2**3  # to plot n samples / hop_s
     15    downsample = 2**4  # to plot n samples / hop_s
    1616
    1717    a = source(filename, samplerate, hop_s)            # source file
     
    2626        total_frames += read
    2727        if read < hop_s: break
    28     print samples.reshape(hop_s/downsample, downsample).shape
    29 
    3028    allsamples_max = (allsamples_max > 0) * allsamples_max
    3129    allsamples_max_times = [ ( float (t) / downsample ) * hop_s for t in range(len(allsamples_max)) ]
     
    3533    ax.axis(xmin = allsamples_max_times[0], xmax = allsamples_max_times[-1])
    3634
    37     if allsamples_max_times[-1] / float(samplerate) > 60:
     35    set_xlabels_sample2time(ax, allsamples_max_times[-1], samplerate)
     36    return ax
     37
     38def set_xlabels_sample2time(ax, latest_sample, samplerate):
     39    if latest_sample / float(samplerate) > 60:
    3840        ax.set_xlabel('time (mm:ss)')
    3941        ax.set_xticklabels([ "%02d:%02d" % (t/float(samplerate)/60, (t/float(samplerate))%60) for t in ax.get_xticks()[:-1]], rotation = 50)
     
    4143        ax.set_xlabel('time (ss.mm)')
    4244        ax.set_xticklabels([ "%02d.%02d" % (t/float(samplerate), 100*((t/float(samplerate))%1) ) for t in ax.get_xticks()[:-1]], rotation = 50)
     45
     46
    4347if __name__ == '__main__':
    4448    import matplotlib.pyplot as plt
Note: See TracChangeset for help on using the changeset viewer.