add list_snd_files and downsample audio, temporary fix for filename check in plot...
authorPaul Brossier <piem@altern.org>
Tue, 13 Dec 2005 05:51:59 +0000 (05:51 +0000)
committerPaul Brossier <piem@altern.org>
Tue, 13 Dec 2005 05:51:59 +0000 (05:51 +0000)
add list_snd_files and downsample audio, temporary fix for filename check in plot functions

python/aubio/bench/node.py
python/aubio/gnuplot.py

index ca337b0..91318ee 100644 (file)
@@ -24,6 +24,9 @@ def list_files(datapath,filter='f'):
 def list_wav_files(datapath,maxdepth=1):
        return list_files(datapath, filter="f -name '*.wav' -maxdepth %d"%maxdepth)
 
+def list_snd_files(datapath,maxdepth=1):
+       return list_files(datapath, filter="f -name '*.wav' -o -name '*.aif' -maxdepth %d"%maxdepth)
+
 def list_dirs(datapath):
        return list_files(datapath, filter="d")
 
index dc100db..9c0ec42 100644 (file)
@@ -67,6 +67,16 @@ def plot_audio(filenames, fileout=None, start=0, end=None, noaxis=None):
                xorig += 1./todraw
        g.gnuplot('unset multiplot;')
 
+def downsample_audio(time,data,maxpoints=10000):
+       """ create gnuplot plot from an audio file """
+       import numarray
+        length = len(time)
+       downsample = length/maxpoints
+        if downsample == 0: downsample = 1
+        x = numarray.array(time).resize(length)[0:-1:downsample]
+        y = numarray.array(data).resize(length)[0:-1:downsample]
+       return x,y
+
 def make_audio_plot(time,data,maxpoints=10000):
        """ create gnuplot plot from an audio file """
        import numarray
@@ -106,6 +116,7 @@ def plot_onsets(filename, onsets, ofunc, samplerate=44100., hopsize=512, outplot
 
         # check if datafile exists truth
         datafile = filename.replace('.wav','.txt')
+       if datafile == filename: datafile = ""
         if not os.path.isfile(datafile):
                 title = "truth file not found"
                 t = Gnuplot.Data(0,0,with='impulses') 
@@ -176,6 +187,7 @@ def plot_pitch(filename, pitch, samplerate=44100., hopsize=512, outplot=None):
 
         # check if ground truth exists
         datafile = filename.replace('.wav','.txt')
+       if datafile == filename: datafile = ""
         if not os.path.isfile(datafile):
                 title = "truth file not found"
                 t = Gnuplot.Data(0,0,with='impulses')