new bench-pitch
authorPaul Brossier <piem@altern.org>
Thu, 23 Feb 2006 02:28:35 +0000 (02:28 +0000)
committerPaul Brossier <piem@altern.org>
Thu, 23 Feb 2006 02:28:35 +0000 (02:28 +0000)
new bench-pitch

python/test/bench/pitch/bench-pitch

index b38b068..dc84160 100755 (executable)
@@ -5,25 +5,83 @@ from aubio.tasks import *
 
 class benchpitch(bench):
        
+       """ list of values to store per file """
+       valuenames = ['mode']
+       """ list of lists to store per file """
+       valuelists = ['orig', 'mean', 'med']
+       """ list of values to print per dir """
+       printnames = [ 'mode']
+
+       """ per dir """
+       formats = {'mode': "%12s" , 'thres': "%5.4s", 
+               'dist':  "%5.4s", 'prec': "%5.4s", 'recl':  "%5.4s",
+               'Ttrue': "%5.4s", 'Tfp':   "%5.4s", 'Tfn':   "%5.4s", 
+               'Tm':    "%5.4s", 'Td':    "%5.4s",
+               'aTtrue':"%5.4s", 'aTfp':  "%5.4s", 'aTfn':  "%5.4s", 
+               'aTm':   "%5.4s", 'aTd':   "%5.4s",
+               'mean':  "%5.40s", 'smean': "%5.40s", 
+               'amean':  "%5.40s", 'samean': "%5.40s"}
+
+       def dir_eval(self):
+               """ evaluate statistical data over the directory """
+               v = self.v
+
+               v['mode']      = self.params.pitchmode
+
        def file_exec(self,input,output):
                filetask = self.task(input,params=self.params)
                computed_data = filetask.compute_all()
-               results = filetask.eval(computed_data)
-               self.results.append(results)
-               truth = filetask.gettruth()
+               orig,mean,med = filetask.eval(computed_data)
+               
+               self.v['orig'].append(orig)
+               self.v['mean'].append(mean)
+               self.v['med'].append(med)
+               #print results#, computed_data
                #print input, results, results - float(input.split('.')[-2])
-               self.pretty_print((self.params.pitchmode, truth, 
-                       truth - results[0], results[0],
-                       truth - results[1], results[1]))
                        
        def run_bench(self,modes=['schmitt']):
+               from os.path import basename
+               d = []
                self.modes = modes
-               self.pretty_print(self.titles)
+               self.pretty_titles()
                for mode in self.modes:
                        self.params.pitchmode = mode
-                       self.dir_exec()
-                       self.dir_eval()
-                       self.dir_plot()
+                       self.dir_eval_print()
+                       self.plotpitchtessiture(d,
+                               self.v['orig'], 
+                               self.v['med'],
+                               plottitle=self.v['mode'],
+                               plotmode='points')
+               #d.append('beta = .25,orig(x) title \"-2 octave\"')
+               d.append('beta = .50,orig(x) title \"-1 octave\"')
+               d.append('beta = 1.0,orig(x) title \"original\"')
+               d.append('beta = 2.0,orig(x) title \"+1 octave\"')
+               title = basename(self.datadir)
+               outplot = "_-_".join(('pitchtessiture',title))
+               for ext in ('ps','png','svg',''):
+                       self.plotplotpitchtessiture(d,
+                               plottitle=title,
+                               outplot=outplot,
+                               extension=ext)
+
+       """
+       Plot functions 
+       """
+
+       def plotpitchtessiture(self,d,lx,ly,plottitle="",plotmode='linespoints'):
+               import Gnuplot, Gnuplot.funcutils
+               d.append(Gnuplot.Data(lx, ly, with=plotmode, title="%s" % (plottitle) ))
+
+       def plotplotpitchtessiture(self,d,plottitle='',outplot=0,extension=''):
+               from aubio.gnuplot import gnuplot_create
+               g = gnuplot_create(outplot=outplot,extension=extension) 
+               g.title(plottitle)
+               g('orig(x) = beta*x')
+               g.xlabel('original pitch (Hz)')
+               g.ylabel('detected pitch (Hz)')
+               g('set log xy')
+               g.plot(*d)
+
 
 if __name__ == "__main__":
        import sys
@@ -31,15 +89,17 @@ if __name__ == "__main__":
        else: print "error: a path is required"; sys.exit(1)
        if len(sys.argv) > 2:
                for each in sys.argv[3:-1]: print each
-       modes = ['yin', 'schmitt', 'mcomb', 'fcomb']
+       modes = ['schmitt', 'yin', 'mcomb', 'fcomb']
+       #modes = ['fcomb']
 
-       benchpitch = benchpitch(datapath)
-       benchpitch.params = taskparams()
+       params = taskparams()
+       params.bufsize = 2048
+       params.hopsize = params.bufsize/2
+       benchpitch = benchpitch(datapath,params=params)
        benchpitch.task = taskpitch
 
-
-       benchpitch.titles  = [ 'mode', 'thres', 'avg', 'avgdist' ]
-       benchpitch.formats = ["%12s" , "| %6s", "| %6s", "| %6s", "| %6s", "| %6s" ]
+       #benchpitch.titles  = [ 'mode', 'thres', 'avg', 'avgdist' ]
+       #benchpitch.formats = ["%12s" , "| %6s", "| %6s", "| %6s", "| %6s", "| %6s" ]
        try:
                benchpitch.run_bench(modes=modes)
        except KeyboardInterrupt: