Ignore:
Timestamp:
May 16, 2016, 3:16:00 AM (9 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:
dc654f8
Parents:
416ddd1
Message:

python/demos: python3 and double precision compatibility

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/demos/demo_spectrogram.py

    r416ddd1 r4120fbc  
    22
    33import sys, os.path
    4 from aubio import pvoc, source
     4from aubio import pvoc, source, float_type
    55from numpy import zeros, log10, vstack
    66import matplotlib.pyplot as plt
     
    88def get_spectrogram(filename, samplerate = 0):
    99    win_s = 512                                        # fft window size
    10     hop_s = win_s / 2                                  # hop size
    11     fft_s = win_s / 2 + 1                              # spectrum bins
     10    hop_s = win_s // 2                                 # hop size
     11    fft_s = win_s // 2 + 1                             # spectrum bins
    1212
    1313    a = source(filename, samplerate, hop_s)            # source file
    1414    if samplerate == 0: samplerate = a.samplerate
    1515    pv = pvoc(win_s, hop_s)                            # phase vocoder
    16     specgram = zeros([0, fft_s], dtype='float32')      # numpy array to store spectrogram
     16    specgram = zeros([0, fft_s], dtype=float_type)     # numpy array to store spectrogram
    1717
    1818    # analysis
     
    2929    time_step = hop_s / float(samplerate)
    3030    total_time = len(specgram) * time_step
    31     print "total time: %0.2fs" % total_time,
    32     print ", samplerate: %.2fkHz" % (samplerate / 1000.)
     31    outstr = "total time: %0.2fs" % total_time
     32    print(outstr + ", samplerate: %.2fkHz" % (samplerate / 1000.))
    3333    n_xticks = 10
    3434    n_yticks = 10
     
    6666if __name__ == '__main__':
    6767    if len(sys.argv) < 2:
    68         print "Usage: %s <filename>" % sys.argv[0]
     68        print("Usage: %s <filename>" % sys.argv[0])
    6969    else:
    7070        for soundfile in sys.argv[1:]:
    7171            fig = get_spectrogram(soundfile)
    7272            # display graph
    73             fig.show()
     73            plt.show()
    7474            #outimage = os.path.basename(soundfile) + '.png'
    7575            #print ("writing: " + outimage)
Note: See TracChangeset for help on using the changeset viewer.