Changeset b1c2acc
- Timestamp:
- Jul 27, 2012, 6:36:29 PM (12 years ago)
- 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:
- 0c83de6
- Parents:
- 89fd1e5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
interfaces/python/demo_spectrogram.py
r89fd1e5 rb1c2acc 4 4 from aubio import pvoc, source 5 5 from numpy import array, arange, zeros, shape, log10, vstack 6 from pylab import imshow, show, gray, autumn, axis, ylabel, xlabel, xticks, yticks6 from pylab import imshow, show, cm, axis, ylabel, xlabel, xticks, yticks 7 7 8 8 def get_spectrogram(filename): 9 win_s = 512 # fft size10 hop_s = win_s / 2 # hopsize11 fft_s = win_s / 2 + 1 # number of spectrum bins12 samplerate = 1600013 specgram = zeros([0, fft_s], dtype='float32') 14 a = source(filename, samplerate, hop_s) # mono 8kHz only please9 samplerate = 44100 10 win_s = 512 # fft window size 11 hop_s = win_s / 2 # hop size 12 fft_s = win_s / 2 + 1 # spectrum bins 13 14 a = source(filename, samplerate, hop_s) # source file 15 15 pv = pvoc(win_s, hop_s) # phase vocoder 16 specgram = zeros([0, fft_s], dtype='float32') # numpy array to store spectrogram 17 18 # analysis 16 19 while True: 17 20 samples, read = a() # read file 18 #specgram = vstack((specgram,1.-log10(1.+pv(samples).norm))) # store new norm vector19 21 specgram = vstack((specgram,pv(samples).norm)) # store new norm vector 20 22 if read < a.hop_size: break 21 23 22 autumn() 23 from pylab import gray 24 gray() 25 imshow(specgram.T, origin = 'bottom', aspect = 'auto') 24 # plotting 25 imshow(log10(specgram.T), origin = 'bottom', aspect = 'auto', cmap=cm.gray_r) 26 26 axis([0, len(specgram), 0, len(specgram[0])]) 27 27 ylabel('Frequency (Hz)') 28 28 xlabel('Time (s)') 29 # show axes in Hz and seconds 29 30 time_step = hop_s / float(samplerate) 30 31 total_time = len(specgram) * time_step … … 34 35 yticks( arange(ticks) / float(ticks) * len(specgram[0]), 35 36 [x * samplerate / 2. / float(ticks) for x in range(ticks) ] ) 36 show()37 37 38 if len(sys.argv) < 2: 39 print "Usage: %s <filename>" % sys.argv[0] 40 else: 41 [get_spectrogram(soundfile) for soundfile in sys.argv[1:]] 38 if __name__ == '__main__': 39 if len(sys.argv) < 2: 40 print "Usage: %s <filename>" % sys.argv[0] 41 else: 42 for soundfile in sys.argv[1:]: 43 get_spectrogram(soundfile) 44 # display graph 45 show()
Note: See TracChangeset
for help on using the changeset viewer.