source: python/test/bench/pitch/bench-pitch @ 13c3fba

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 13c3fba was cafb00a, checked in by Paul Brossier <piem@altern.org>, 19 years ago

update to last bench-onset, bench-pitch
update to last bench-onset, bench-pitch

  • Property mode set to 100755
File size: 3.2 KB
Line 
1#! /usr/bin/python
2
3from aubio.bench.node import *
4from aubio.tasks import *
5
6class benchpitch(bench):
7       
8        """ list of values to store per file """
9        valuenames = ['mode']
10        """ list of lists to store per file """
11        valuelists = ['orig', 'mean', 'med']
12        """ list of values to print per dir """
13        printnames = [ 'mode']
14
15        """ per dir """
16        formats = {'mode': "%12s" , 'thres': "%5.4s",
17                'dist':  "%5.4s", 'prec': "%5.4s", 'recl':  "%5.4s",
18                'Ttrue': "%5.4s", 'Tfp':   "%5.4s", 'Tfn':   "%5.4s",
19                'Tm':    "%5.4s", 'Td':    "%5.4s",
20                'aTtrue':"%5.4s", 'aTfp':  "%5.4s", 'aTfn':  "%5.4s",
21                'aTm':   "%5.4s", 'aTd':   "%5.4s",
22                'mean':  "%5.40s", 'smean': "%5.40s",
23                'amean':  "%5.40s", 'samean': "%5.40s"}
24
25        def dir_eval(self):
26                """ evaluate statistical data over the directory """
27                v = self.v
28
29                v['mode']      = self.params.pitchmode
30
31        def file_exec(self,input,output):
32                filetask = self.task(input,params=self.params)
33                computed_data = filetask.compute_all()
34                orig,mean,med = filetask.eval(computed_data)
35               
36                self.v['orig'].append(orig)
37                self.v['mean'].append(mean)
38                self.v['med'].append(med)
39                #print results#, computed_data
40                #print input, results, results - float(input.split('.')[-2])
41                       
42        def run_bench(self,modes=['schmitt']):
43                from os.path import basename
44                d = []
45                self.modes = modes
46                self.pretty_titles()
47                for mode in self.modes:
48                        self.params.pitchmode = mode
49                        self.dir_eval_print()
50                        self.plotpitchtessiture(d,
51                                self.v['orig'],
52                                self.v['med'],
53                                plottitle=self.v['mode'],
54                                plotmode='points')
55                #d.append('beta = .25,orig(x) title \"-2 octave\"')
56                d.append('beta = .50,orig(x) title \"-1 octave\"')
57                d.append('beta = 1.0,orig(x) title \"original\"')
58                d.append('beta = 2.0,orig(x) title \"+1 octave\"')
59                title = basename(self.datadir)
60                outplot = "_-_".join(('pitchtessiture',title))
61                for ext in ('ps','png','svg',''):
62                        self.plotplotpitchtessiture(d,
63                                plottitle=title,
64                                outplot=outplot,
65                                extension=ext)
66
67        """
68        Plot functions
69        """
70
71        def plotpitchtessiture(self,d,lx,ly,plottitle="",plotmode='linespoints'):
72                import Gnuplot, Gnuplot.funcutils
73                d.append(Gnuplot.Data(lx, ly, with=plotmode, title="%s" % (plottitle) ))
74
75        def plotplotpitchtessiture(self,d,plottitle='',outplot=0,extension=''):
76                from aubio.gnuplot import gnuplot_create
77                g = gnuplot_create(outplot=outplot,extension=extension)
78                g.title(plottitle)
79                g('orig(x) = beta*x')
80                g.xlabel('original pitch (Hz)')
81                g.ylabel('detected pitch (Hz)')
82                g('set key left top')
83                g('set log xy')
84                g('set xrange [50:2000]')
85                g('set yrange [50:2000]')
86                g.plot(*d)
87
88
89if __name__ == "__main__":
90        import sys
91        if len(sys.argv) > 1: datapath = sys.argv[1]
92        else: print "error: a path is required"; sys.exit(1)
93        if len(sys.argv) > 2:
94                for each in sys.argv[3:-1]: print each
95        modes = ['schmitt', 'yin', 'mcomb', 'fcomb']
96        #modes = ['fcomb']
97
98        params = taskparams()
99        params.bufsize = 4096
100        params.hopsize = params.bufsize/4
101        params.silence = -1000.
102        params.pitchsmooth = 50
103        benchpitch = benchpitch(datapath,params=params)
104        benchpitch.task = taskpitch
105
106        #benchpitch.titles  = [ 'mode', 'thres', 'avg', 'avgdist' ]
107        #benchpitch.formats = ["%12s" , "| %6s", "| %6s", "| %6s", "| %6s", "| %6s" ]
108        try:
109                benchpitch.run_bench(modes=modes)
110        except KeyboardInterrupt:
111                print "Interrupted by user"
112                sys.exit(1)
113
114        sys.exit(0)
Note: See TracBrowser for help on using the repository browser.