History

move to new nodes and tasks move to new nodes and tasks

Paul Brossier committed 20 years ago

Commit 4f4a8a41 parent 7c9ad743 files · +103 −153Browse files

Showing the changes to python (3 of 3 files). Show all

Unified · Split

3 files
  1. python/aubiocut +40 −35
  2. python/bench-onset +52 −100
  3. python/bench-pitch +11 −18
python/aubiocut+40−35
@@ -15,8 +15,8 @@ def parse_args(): · 14 unmodified lines
15 parser.add_option("-i","--input",15 parser.add_option("-i","--input",
16 action="store", dest="filename", 16 action="store", dest="filename",
17 help="input sound file")17 help="input sound file")
18 parser.add_option("-m","--mode", action="callback", 18 parser.add_option("-m","--mode",
19 callback=check_onset_mode, dest="mode", default=['dual'], 19 action="store", dest="mode", default=['dual'],
20 help="onset detection mode [default=dual] \20 help="onset detection mode [default=dual] \
21 complexdomain|hfc|phase|specdiff|energy|kl|mkl|dual")21 complexdomain|hfc|phase|specdiff|energy|kl|mkl|dual")
22 parser.add_option("-B","--bufsize",22 parser.add_option("-B","--bufsize",
@@ -80,45 +80,50 @@ def parse_args(): · 57 unmodified lines
80options, args = parse_args()80options, args = parse_args()
81 81
82filename = options.filename82filename = options.filename
83samplerate = float(sndfile(filename).samplerate())83params = taskparams()
84hopsize = int(options.hopsize)84params.hopsize = int(options.hopsize)
85bufsize = int(options.bufsize)85params.bufsize = int(options.bufsize)
86step = float(samplerate)/float(hopsize)86params.threshold = float(options.threshold)
87threshold = float(options.threshold)87params.zerothres = float(options.zerothres)
88zerothres = float(options.zerothres)88params.silence = float(options.silence)
89silence = float(options.silence)89params.mintol = float(options.mintol)
90mintol = float(options.mintol)*step
91mode = options.mode
92# default take back system delay90# default take back system delay
93if options.delay: delay = float(options.delay)91if options.delay: delay = float(options.delay)
94else: delay = 3./step92else: delay = 3./params.step
95 93
96if options.beat:94if options.beat:
97 #onsets = getbeats(filename,threshold,silence,mode=options.mode)95 #onsets = getbeats(filename,threshold,silence,mode=options.mode)
98 exit("not implemented yet")96 exit("not implemented yet")
99elif options.silencecut:97elif options.silencecut:
100 onsets = getsilences(filename,hopsize=hopsize,silence=silence)98 onsets = getsilences(filename,hopsize=hopsize,silence=silence)
101elif options.plot: storefunc=True99elif options.plot: params.storefunc=True
102else: storefunc=False100else: params.storefunc=False
103 101
104lonsets, lofunc = [], []102lonsets, lofunc = [], []
105for i in range(len(mode)):103modes = options.mode.split(',')
106 onsets, ofunc = getonsets(filename,threshold,silence,104for i in range(len(modes)):
107 mode=mode[i],localmin=options.localmin,105
108 derivate=options.derivate,106 params.onsetmode = modes[i]
109 bufsize=bufsize,hopsize=hopsize,storefunc=True)107 filetask = taskonset(filename,params=params)
108 onsets = filetask.compute_all()
109 ofunc = filetask.ofunc
110 #onsets, ofunc = getonsets(filename,threshold,silence,
111 # mode=mode[i],localmin=options.localmin,
112 # derivate=options.derivate,
113 # bufsize=bufsize,hopsize=hopsize,storefunc=True)
110 114
111 # take back system delay115 # take back system delay
112 if delay != 0:116 if delay != 0:
113 for i in range(len(onsets)):117 for each in range(len(onsets)):
114 onsets[i] -= delay*step118 onsets[each] = onsets[each][0] - delay*params.step
115 119
116 # prune doubled 120 # prune doubled
117 if mintol > 0:121 params.mintol *= params.step
118 last = -2*mintol122 if params.mintol > 0:
123 last = -2*params.mintol
119 newonsets = []124 newonsets = []
120 for new in onsets:125 for new in onsets:
121 if (new - last > mintol): 126 if (new - last > params.mintol):
122 newonsets.append(new)127 newonsets.append(new)
123 last = new128 last = new
124 onsets = newonsets129 onsets = newonsets
@@ -126,17 +131,17 @@ for i in range(len(mode)): · 1 unmodified line
126 lonsets.append(onsets)131 lonsets.append(onsets)
127 lofunc.append(ofunc)132 lofunc.append(ofunc)
128 133
129# print times in second134 # print times in second
130if options.verbose:135 if options.verbose:
131 maxonset = 0136 print modes[i]
132 for j in range(len(mode)):137 maxonset = 0
133 for i in range(len(lonsets[j])):138 for i in range(len(onsets)):
134 print lonsets[j][i]/step139 print onsets[i]*params.step
135 140
136if options.plot:141 if options.plot:
137 from aubio.gnuplot import plot_onsets142 filetask.plot(onsets, ofunc)
138 plot_onsets(filename, lonsets, lofunc, 143 filetask.plotplot(outplot=options.outplot)
139 samplerate=samplerate, hopsize=hopsize, outplot=options.outplot)
140 144
141if options.cut:145if options.cut:
142 cutfile(filename,onsets,zerothres=zerothres,bufsize=bufsize,hopsize=hopsize)146 a = taskcut(filename,onsets,params=params)
147 a.compute_all()
python/bench-onset+52−100
@@ -1,31 +1,17 @@
1#! /usr/bin/python1#! /usr/bin/python
2 2
3from aubio.bench.config import *
4from aubio.bench.node import *3from aubio.bench.node import *
5 4from aubio.tasks import *
6class onset_parameters:
7 def __init__(self):
8 """ set default parameters """
9 self.silence = -70
10 self.derivate = False
11 self.localmin = False
12 self.bufsize = 512
13 self.hopsize = 256
14 self.samplerate = 44100
15 self.tol = 0.05
16 self.step = float(self.hopsize)/float(self.samplerate)
17 self.threshold = 0.1
18 self.mode = 'dual'
19 5
20class benchonset(bench):6class benchonset(bench):
21 7
22 def compute_results(self):8 def dir_eval(self):
23 self.P = 100*float(self.expc-self.missed-self.merged)/(self.expc-self.missed-self.merged + self.bad+self.doubled)9 self.P = 100*float(self.expc-self.missed-self.merged)/(self.expc-self.missed-self.merged + self.bad+self.doubled)
24 self.R = 100*float(self.expc-self.missed-self.merged)/(self.expc-self.missed-self.merged + self.missed+self.merged)10 self.R = 100*float(self.expc-self.missed-self.merged)/(self.expc-self.missed-self.merged + self.missed+self.merged)
25 if self.R < 0: self.R = 011 if self.R < 0: self.R = 0
26 self.F = 2* self.P*self.R / (self.P+self.R)12 self.F = 2* self.P*self.R / (self.P+self.R)
27 13
28 self.values = [self.params.mode, 14 self.values = [self.params.onsetmode,
29 "%2.3f" % self.params.threshold,15 "%2.3f" % self.params.threshold,
30 self.orig,16 self.orig,
31 self.expc,17 self.expc,
@@ -42,51 +28,17 @@ class benchonset(bench): · 10 unmodified lines
42 "%2.3f" % self.R,28 "%2.3f" % self.R,
43 "%2.3f" % self.F ]29 "%2.3f" % self.F ]
44 30
45 def compute_onset(self,input,output):31 def file_exec(self,input,output):
46 from aubio.tasks import getonsets, get_onset_mode32 filetask = self.task(input,params=self.params)
47 from aubio.onsetcompare import onset_roc, onset_diffs33 computed_data = filetask.compute_all()
48 from aubio.txtfile import read_datafile34 results = filetask.eval(computed_data)
49 amode = 'roc'35 self.orig += filetask.orig
50 vmode = 'verbose'36 self.missed += filetask.missed
51 vmode = ''37 self.merged += filetask.merged
52 lres, ofunc = getonsets(input,38 self.expc += filetask.expc
53 self.params.threshold,39 self.bad += filetask.bad
54 self.params.silence,40 self.doubled += filetask.doubled
55 mode=get_onset_mode(self.params.mode),41
56 localmin=self.params.localmin,
57 derivate=self.params.derivate,
58 bufsize=self.params.bufsize,
59 hopsize=self.params.hopsize,
60 storefunc=False)
61
62 for i in range(len(lres)): lres[i] = lres[i]*self.params.step
63 ltru = read_datafile(input.replace('.wav','.txt'),depth=0)
64 if vmode=='verbose':
65 print "Running with mode %s" % self.params.mode,
66 print " and threshold %f" % self.params.threshold,
67 print " on file", input
68 #print ltru; print lres
69 if amode == 'localisation':
70 l = onset_diffs(ltru,lres,self.params.tol)
71 mean = 0
72 for i in l: mean += i
73 if len(l): print "%.3f" % (mean/len(l))
74 else: print "?0"
75 elif amode == 'roc':
76 orig, missed, merged, expc, bad, doubled = onset_roc(ltru,lres,self.params.tol)
77 self.orig += orig
78 self.missed += missed
79 self.merged += merged
80 self.expc += expc
81 self.bad += bad
82 self.doubled += doubled
83 self.compute_results()
84
85 def compute_data(self):
86 self.orig, self.missed, self.merged, self.expc, \
87 self.bad, self.doubled = 0, 0, 0, 0, 0, 0
88 act_on_data(self.compute_onset,self.datadir,self.resdir, \
89 suffix='',filter='f -name \'*.wav\'')
90 42
91 def run_bench(self,modes=['dual'],thresholds=[0.5]):43 def run_bench(self,modes=['dual'],thresholds=[0.5]):
92 self.modes = modes44 self.modes = modes
@@ -94,11 +46,11 @@ class benchonset(bench): · 1 unmodified line
94 46
95 self.pretty_print(self.titles)47 self.pretty_print(self.titles)
96 for mode in self.modes:48 for mode in self.modes:
97 self.params.mode = mode49 self.params.onsetmode = mode
98 for threshold in self.thresholds:50 for threshold in self.thresholds:
99 self.params.threshold = threshold51 self.params.threshold = threshold
100 self.compute_data()52 self.dir_exec()
101 self.compute_results()53 self.dir_eval()
102 self.pretty_print(self.values)54 self.pretty_print(self.values)
103 55
104 def auto_learn(self,modes=['dual'],thresholds=[0.1,1.5]):56 def auto_learn(self,modes=['dual'],thresholds=[0.1,1.5]):
@@ -109,21 +61,24 @@ class benchonset(bench): · 4 unmodified lines
109 steps = 10 61 steps = 10
110 lesst = thresholds[0] 62 lesst = thresholds[0]
111 topt = thresholds[1]63 topt = thresholds[1]
112 self.params.mode = mode64 self.params.onsetmode = mode
113 65
114 self.params.threshold = topt 66 self.params.threshold = topt
115 self.compute_data()67 self.dir_exec()
68 self.dir_eval()
116 self.pretty_print(self.values)69 self.pretty_print(self.values)
117 topF = self.F 70 topF = self.F
118 71
119 self.params.threshold = lesst 72 self.params.threshold = lesst
120 self.compute_data()73 self.dir_exec()
74 self.dir_eval()
121 self.pretty_print(self.values)75 self.pretty_print(self.values)
122 lessF = self.F 76 lessF = self.F
123 77
124 for i in range(steps):78 for i in range(steps):
125 self.params.threshold = ( lesst + topt ) * .5 79 self.params.threshold = ( lesst + topt ) * .5
126 self.compute_data()80 self.dir_exec()
81 self.dir_eval()
127 self.pretty_print(self.values)82 self.pretty_print(self.values)
128 if self.F == 100.0 or self.F == topF: 83 if self.F == 100.0 or self.F == topF:
129 print "assuming we converged, stopping" 84 print "assuming we converged, stopping"
@@ -143,34 +98,31 @@ class benchonset(bench): · 13 unmodified lines
143 lesst /= 2.98 lesst /= 2.
144 99
145 100
146#modes = [ 'complex' ]101if __name__ == "__main__":
147modes = ['complex', 'energy', 'phase', 'specdiff', 'kl', 'mkl', 'dual']102 import sys
148#thresholds = [1.5]103 if len(sys.argv) > 1: datapath = sys.argv[1]
149thresholds = [ 0.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5]104 else: print "ERR: a path is required"; sys.exit(1)
150 105 modes = ['complex', 'energy', 'phase', 'specdiff', 'kl', 'mkl', 'dual']
151#datapath = "%s%s" % (DATADIR,'/onset/DB/*/')106 #modes = [ 'complex' ]
152datapath = "%s%s" % (DATADIR,'/onset/DB/PercussivePhrases/RobertRich')107 thresholds = [ 0.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5]
153respath = '/var/tmp/DB-testings'108 #thresholds = [1.5]
154 109
155benchonset = benchonset(datapath,respath,checkres=True,checkanno=True)110 #datapath = "%s%s" % (DATADIR,'/onset/DB/*/')
156 111 respath = '/var/tmp/DB-testings'
157benchonset.params = onset_parameters()112
158 113 benchonset = benchonset(datapath,respath,checkres=True,checkanno=True)
159benchonset.titles = [ 'mode', 'thres', 'orig', 'expc', 'missd', 'mergd',114 benchonset.params = taskparams()
160'bad', 'doubl', 'corrt', 'GD', 'FP', 'GD-merged', 'FP-pruned',115 benchonset.task = taskonset
161'prec', 'recl', 'dist' ]116
162benchonset.formats = ["%12s" , "| %6s", "| %6s", "| %6s", "| %6s", "| %6s", 117 benchonset.titles = [ 'mode', 'thres', 'orig', 'expc', 'missd', 'mergd',
163"| %6s", "| %6s", "| %6s", "| %8s", "| %8s", "| %8s", "| %8s",118 'bad', 'doubl', 'corrt', 'GD', 'FP', 'GD-merged', 'FP-pruned',
164"| %6s", "| %6s", "| %6s"] 119 'prec', 'recl', 'dist' ]
165 120 benchonset.formats = ["%12s" , "| %6s", "| %6s", "| %6s", "| %6s", "| %6s",
166#benchonset.run_bench(modes=modes,thresholds=thresholds)121 "| %6s", "| %6s", "| %6s", "| %8s", "| %8s", "| %8s", "| %8s",
167benchonset.auto_learn(modes=modes)122 "| %6s", "| %6s", "| %6s"]
168 123
169# gatherdata124 try:
170#act_on_data(my_print,datapath,respath,suffix='.txt',filter='f -name \'*.wav\'')125 benchonset.auto_learn(modes=modes)
171# gatherthreshold126 #benchonset.run_bench(modes=modes)
172# gathermodes127 except KeyboardInterrupt:
173# comparediffs128 sys.exit(1)
174# gatherdiffs
175
176
python/bench-pitch+11−18
@@ -5,46 +5,39 @@ from aubio.tasks import * · 4 unmodified lines
5 5
6class benchpitch(bench):6class benchpitch(bench):
7 7
8 def compute_file(self,input,output):8 def file_exec(self,input,output):
9 filetask = self.task(input,params=self.params)9 filetask = self.task(input,params=self.params)
10 computed_data = filetask.compute_all()10 computed_data = filetask.compute_all()
11 results = filetask.eval(computed_data)11 results = filetask.eval(computed_data)
12 self.results.append(results)12 self.results.append(results)
13 truth = filetask.gettruth()13 truth = filetask.gettruth()
14 #print input, results, results - float(input.split('.')[-2])14 #print input, results, results - float(input.split('.')[-2])
15 self.pretty_print((self.params.mode, truth, 15 self.pretty_print((self.params.pitchmode, truth,
16 truth - results[0], results[0],16 truth - results[0], results[0],
17 truth - results[1], results[1]))17 truth - results[1], results[1]))
18 18
19 def compute_data(self):19 def run_bench(self,modes=['schmitt']):
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 = modes20 self.modes = modes
30 self.pretty_print(self.titles)21 self.pretty_print(self.titles)
31 for mode in self.modes:22 for mode in self.modes:
32 self.params.mode = mode23 self.params.pitchmode = mode
33 self.compute_data()24 self.dir_exec()
34 #self.compute_results()25 self.dir_eval()
35 #self.pretty_print(self.results)26 self.dir_plot()
36 27
37if __name__ == "__main__":28if __name__ == "__main__":
38 import sys29 import sys
39 if len(sys.argv) > 1: datapath = sys.argv[1]30 if len(sys.argv) > 1: datapath = sys.argv[1]
40 else: print "error: a path is required"; sys.exit(1)31 else: print "error: a path is required"; sys.exit(1)
41 32 if len(sys.argv) > 2:
42 modes = ['schmitt', 'yin', 'mcomb', 'fcomb']33 for each in sys.argv[3:-1]: print each
34 modes = ['yin', 'schmitt', 'mcomb', 'fcomb']
43 35
44 benchpitch = benchpitch(datapath)36 benchpitch = benchpitch(datapath)
45 benchpitch.params = taskparams()37 benchpitch.params = taskparams()
46 benchpitch.task = taskpitch38 benchpitch.task = taskpitch
47 39
40
48 benchpitch.titles = [ 'mode', 'thres', 'avg', 'avgdist' ]41 benchpitch.titles = [ 'mode', 'thres', 'avg', 'avgdist' ]
49 benchpitch.formats = ["%12s" , "| %6s", "| %6s", "| %6s", "| %6s", "| %6s" ]42 benchpitch.formats = ["%12s" , "| %6s", "| %6s", "| %6s", "| %6s", "| %6s" ]
50 try:43 try:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t