Changes in / [22df684:e6cde32]
- Location:
- python/demos
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/demos/demo_specdesc.py
r22df684 re6cde32 22 22 pv = pvoc(win_s, hop_s) 23 23 24 methods = ['default', 'energy', 'hfc', 'complex', 'phase', 'specdiff', 'kl', 'mkl',25 'specflux', 'centroid', 'spread', 'skewness', 'kurtosis', 'slope', 'decrease',26 'rolloff',]24 methods = ['default', 'energy', 'hfc', 'complex', 'phase', 'specdiff', 'kl', 25 'mkl', 'specflux', 'centroid', 'slope', 'rolloff', 'spread', 'skewness', 26 'kurtosis', 'decrease',] 27 27 28 28 all_descs = {} … … 40 40 samples, read = s() 41 41 fftgrain = pv(samples) 42 print "%f" % ( total_frames / float(samplerate) ),42 #print "%f" % ( total_frames / float(samplerate) ), 43 43 for method in methods: 44 44 specdesc_val = o[method](fftgrain)[0] 45 45 all_descs[method] = hstack ( [all_descs[method], specdesc_val] ) 46 print "%f" % specdesc_val,47 print46 #print "%f" % specdesc_val, 47 #print 48 48 total_frames += read 49 49 if read < hop_s: break … … 53 53 import matplotlib.pyplot as plt 54 54 from demo_waveform_plot import get_waveform_plot 55 from demo_waveform_plot import set_xlabels_sample2time 55 56 fig = plt.figure() 56 57 plt.rc('lines',linewidth='.8') 57 58 wave = plt.axes([0.1, 0.75, 0.8, 0.19]) 58 get_waveform_plot(filename, samplerate, ax = wave )59 get_waveform_plot(filename, samplerate, block_size = hop_s, ax = wave ) 59 60 wave.yaxis.set_visible(False) 60 61 wave.xaxis.set_visible(False) … … 74 75 horizontalalignment='right', verticalalignment='bottom', 75 76 ) 76 if all_desc_times[-1] / float(samplerate) > 60: 77 plt.xlabel('time (mm:ss)') 78 ax.set_xticklabels([ "%02d:%02d" % (t/float(samplerate)/60, (t/float(samplerate))%60) for t in ax.get_xticks()[:-1]], rotation = 50) 79 else: 80 plt.xlabel('time (ss.mm)') 81 ax.set_xticklabels([ "%02d.%02d" % (t/float(samplerate), 100*((t/float(samplerate))%1) ) for t in ax.get_xticks()[:-1]], rotation = 50) 77 set_xlabels_sample2time(ax, all_desc_times[-1], samplerate) 82 78 #plt.ylabel('spectral descriptor value') 83 79 ax.xaxis.set_visible(True) -
python/demos/demo_waveform_plot.py
r22df684 re6cde32 5 5 from numpy import zeros, hstack 6 6 7 def get_waveform_plot(filename, samplerate = 0, ax = None):7 def get_waveform_plot(filename, samplerate = 0, block_size = 4096, ax = None): 8 8 import matplotlib.pyplot as plt 9 9 if not ax: 10 10 fig = plt.figure() 11 11 ax = fig.add_subplot(111) 12 hop_s = 4096 # blocksize12 hop_s = block_size 13 13 14 14 allsamples_max = zeros(0,) 15 downsample = 2** 3# to plot n samples / hop_s15 downsample = 2**4 # to plot n samples / hop_s 16 16 17 17 a = source(filename, samplerate, hop_s) # source file … … 26 26 total_frames += read 27 27 if read < hop_s: break 28 print samples.reshape(hop_s/downsample, downsample).shape29 30 28 allsamples_max = (allsamples_max > 0) * allsamples_max 31 29 allsamples_max_times = [ ( float (t) / downsample ) * hop_s for t in range(len(allsamples_max)) ] … … 35 33 ax.axis(xmin = allsamples_max_times[0], xmax = allsamples_max_times[-1]) 36 34 37 if allsamples_max_times[-1] / float(samplerate) > 60: 35 set_xlabels_sample2time(ax, allsamples_max_times[-1], samplerate) 36 return ax 37 38 def set_xlabels_sample2time(ax, latest_sample, samplerate): 39 ax.axis(xmin = 0, xmax = latest_sample) 40 if latest_sample / float(samplerate) > 60: 38 41 ax.set_xlabel('time (mm:ss)') 39 42 ax.set_xticklabels([ "%02d:%02d" % (t/float(samplerate)/60, (t/float(samplerate))%60) for t in ax.get_xticks()[:-1]], rotation = 50) … … 41 44 ax.set_xlabel('time (ss.mm)') 42 45 ax.set_xticklabels([ "%02d.%02d" % (t/float(samplerate), 100*((t/float(samplerate))%1) ) for t in ax.get_xticks()[:-1]], rotation = 50) 46 47 43 48 if __name__ == '__main__': 44 49 import matplotlib.pyplot as plt
Note: See TracChangeset
for help on using the changeset viewer.