shithub: aubio

Download patch

ref: 6ff6d18ce7790aa8adc8889923f13eafc8414ab6
parent: e5afd475bc606e5c78a5dda82863bc412b6580f0
author: Paul Brossier <piem@piem.org>
date: Fri Mar 22 07:56:15 EDT 2013

python/demos/demo_{mel-energy,mfcc,specdesc}.py: use set_xlabels_sample2time

--- a/python/demos/demo_mel-energy.py
+++ b/python/demos/demo_mel-energy.py
@@ -3,7 +3,6 @@
 import sys
 from aubio import fvec, source, pvoc, filterbank
 from numpy import vstack, zeros
-from demo_waveform_plot import set_xlabels_sample2time
 
 win_s = 512                 # fft size
 hop_s = win_s / 4           # hop size
@@ -45,6 +44,7 @@
     print "done computing, now plotting"
     import matplotlib.pyplot as plt
     from demo_waveform_plot import get_waveform_plot
+    from demo_waveform_plot import set_xlabels_sample2time
     fig = plt.figure()
     plt.rc('lines',linewidth='.8')
     wave = plt.axes([0.1, 0.75, 0.8, 0.19])
--- a/python/demos/demo_mfcc.py
+++ b/python/demos/demo_mfcc.py
@@ -3,7 +3,6 @@
 import sys
 from aubio import source, pvoc, mfcc
 from numpy import array, vstack, zeros
-from demo_waveform_plot import set_xlabels_sample2time
 
 win_s = 512                 # fft size
 hop_s = win_s / 4           # hop size
@@ -41,6 +40,7 @@
 # do plotting
 from numpy import arange
 from demo_waveform_plot import get_waveform_plot
+from demo_waveform_plot import set_xlabels_sample2time
 import matplotlib.pyplot as plt
 
 fig = plt.figure()
--- a/python/demos/demo_specdesc.py
+++ b/python/demos/demo_specdesc.py
@@ -21,9 +21,9 @@
 
 pv = pvoc(win_s, hop_s)
 
-methods = ['default', 'energy', 'hfc', 'complex', 'phase', 'specdiff', 'kl', 'mkl',
-    'specflux', 'centroid', 'spread', 'skewness', 'kurtosis', 'slope', 'decrease',
-    'rolloff', ]
+methods = ['default', 'energy', 'hfc', 'complex', 'phase', 'specdiff', 'kl',
+        'mkl', 'specflux', 'centroid', 'slope', 'rolloff', 'spread', 'skewness',
+        'kurtosis', 'decrease',]
 
 all_descs = {}
 o = {}
@@ -39,12 +39,12 @@
 while True:
     samples, read = s()
     fftgrain = pv(samples)
-    print "%f" % ( total_frames / float(samplerate) ),
+    #print "%f" % ( total_frames / float(samplerate) ),
     for method in methods:
         specdesc_val = o[method](fftgrain)[0]
         all_descs[method] = hstack ( [all_descs[method], specdesc_val] )
-        print "%f" % specdesc_val,
-    print
+        #print "%f" % specdesc_val,
+    #print
     total_frames += read
     if read < hop_s: break
 
@@ -52,10 +52,11 @@
     print "done computing, now plotting"
     import matplotlib.pyplot as plt
     from demo_waveform_plot import get_waveform_plot
+    from demo_waveform_plot import set_xlabels_sample2time
     fig = plt.figure()
     plt.rc('lines',linewidth='.8')
     wave = plt.axes([0.1, 0.75, 0.8, 0.19])
-    get_waveform_plot(filename, samplerate, ax = wave )
+    get_waveform_plot(filename, samplerate, block_size = hop_s, ax = wave )
     wave.yaxis.set_visible(False)
     wave.xaxis.set_visible(False)
 
@@ -73,12 +74,7 @@
         ax.annotate(method, xy=(-10, 10),  xycoords='axes points',
                 horizontalalignment='right', verticalalignment='bottom',
                 )
-    if all_desc_times[-1] / float(samplerate) > 60:
-        plt.xlabel('time (mm:ss)')
-        ax.set_xticklabels([ "%02d:%02d" % (t/float(samplerate)/60, (t/float(samplerate))%60) for t in ax.get_xticks()[:-1]], rotation = 50)
-    else:
-        plt.xlabel('time (ss.mm)')
-        ax.set_xticklabels([ "%02d.%02d" % (t/float(samplerate), 100*((t/float(samplerate))%1) ) for t in ax.get_xticks()[:-1]], rotation = 50)
+    set_xlabels_sample2time(ax, all_desc_times[-1], samplerate)
     #plt.ylabel('spectral descriptor value')
     ax.xaxis.set_visible(True)
     plt.show()