demos/demo_spectrogram.py: add samplerate option to spectrogram
authorPaul Brossier <piem@piem.org>
Wed, 6 Mar 2013 21:56:53 +0000 (16:56 -0500)
committerPaul Brossier <piem@piem.org>
Wed, 6 Mar 2013 21:56:53 +0000 (16:56 -0500)
python/demos/demo_spectrogram.py

index 16bd69efae67ac49264b43d10cbcb543b73c9f28..cf5f80d5a697122475468d1984fb0041cbdfc98b 100755 (executable)
@@ -5,13 +5,13 @@ from aubio import pvoc, source
 from numpy import array, arange, zeros, shape, log10, vstack
 from pylab import imshow, show, cm, axis, ylabel, xlabel, xticks, yticks
 
-def get_spectrogram(filename):
-  samplerate = 44100
+def get_spectrogram(filename, samplerate = 0):
   win_s = 512                                        # fft window size
   hop_s = win_s / 2                                  # hop size
   fft_s = win_s / 2 + 1                              # spectrum bins
 
   a = source(filename, samplerate, hop_s)            # source file
+  if samplerate == 0: samplerate = a.samplerate
   pv = pvoc(win_s, hop_s)                            # phase vocoder
   specgram = zeros([0, fft_s], dtype='float32')      # numpy array to store spectrogram