Changeset daa0d5d for python/demos


Ignore:
Timestamp:
Mar 9, 2013, 1:20:39 AM (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:
1e7a8f9
Parents:
5d5d6b9
Message:

demos/demo_waveform_plot.py: improve

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/demos/demo_waveform_plot.py

    r5d5d6b9 rdaa0d5d  
    1010        fig = plt.figure()
    1111        ax = fig.add_subplot(111)
    12     hop_s = 512                                        # fft window size
     12    hop_s = 4096 # block size
    1313
    1414    allsamples_max = zeros(0,)
    15     downsample = 2  # to plot n samples / hop_s
     15    downsample = 2**3  # 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
    2829
    2930    allsamples_max = (allsamples_max > 0) * allsamples_max
     
    3233    ax.plot(allsamples_max_times,  allsamples_max, '-b')
    3334    ax.plot(allsamples_max_times, -allsamples_max, '-b')
     35    ax.axis(xmin = allsamples_max_times[0], xmax = allsamples_max_times[-1])
    3436
     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)
    3543if __name__ == '__main__':
     44    import matplotlib.pyplot as plt
    3645    if len(sys.argv) < 2:
    3746        print "Usage: %s <filename>" % sys.argv[0]
     
    4049            get_waveform_plot(soundfile)
    4150            # display graph
    42             show()
     51            plt.show()
Note: See TracChangeset for help on using the changeset viewer.