[4cc9fe5] | 1 | #! /usr/bin/python |
---|
| 2 | |
---|
| 3 | from aubio.bench.node import * |
---|
[0029638] | 4 | from aubio.tasks import * |
---|
| 5 | |
---|
| 6 | class benchpitch(bench): |
---|
| 7 | |
---|
| 8 | def compute_file(self,input,output): |
---|
| 9 | filetask = self.task(input,params=self.params) |
---|
| 10 | computed_data = filetask.compute_all() |
---|
| 11 | results = filetask.eval(computed_data) |
---|
| 12 | self.results.append(results) |
---|
| 13 | truth = filetask.gettruth() |
---|
| 14 | #print input, results, results - float(input.split('.')[-2]) |
---|
| 15 | self.pretty_print((self.params.mode, truth, |
---|
| 16 | truth - results[0], results[0], |
---|
| 17 | truth - results[1], results[1])) |
---|
| 18 | |
---|
| 19 | def compute_data(self): |
---|
| 20 | self.orig, self.missed, self.merged, self.expc, \ |
---|
| 21 | self.bad, self.doubled = 0, 0, 0, 0, 0, 0 |
---|
| 22 | act_on_data(self.compute_file,self.datadir, \ |
---|
| 23 | suffix='',filter='f -name \'*.wav\'') |
---|
| 24 | |
---|
| 25 | def compute_results(self,truth): |
---|
| 26 | for i in self.results: print i |
---|
| 27 | |
---|
| 28 | def run_bench(self,modes=['dual']): |
---|
| 29 | self.modes = modes |
---|
| 30 | self.pretty_print(self.titles) |
---|
| 31 | for mode in self.modes: |
---|
| 32 | self.params.mode = mode |
---|
| 33 | self.compute_data() |
---|
| 34 | #self.compute_results() |
---|
| 35 | #self.pretty_print(self.results) |
---|
| 36 | |
---|
| 37 | if __name__ == "__main__": |
---|
| 38 | import sys |
---|
| 39 | if len(sys.argv) > 1: datapath = sys.argv[1] |
---|
| 40 | else: print "error: a path is required"; sys.exit(1) |
---|
| 41 | |
---|
| 42 | modes = ['schmitt', 'yin', 'mcomb', 'fcomb'] |
---|
| 43 | |
---|
| 44 | benchpitch = benchpitch(datapath) |
---|
| 45 | benchpitch.params = taskparams() |
---|
| 46 | benchpitch.task = taskpitch |
---|
| 47 | |
---|
| 48 | benchpitch.titles = [ 'mode', 'thres', 'avg', 'avgdist' ] |
---|
| 49 | benchpitch.formats = ["%12s" , "| %6s", "| %6s", "| %6s", "| %6s", "| %6s" ] |
---|
| 50 | try: |
---|
| 51 | benchpitch.run_bench(modes=modes) |
---|
| 52 | except KeyboardInterrupt: |
---|
| 53 | print "Interrupted by user" |
---|
| 54 | sys.exit(1) |
---|
| 55 | |
---|
| 56 | sys.exit(0) |
---|