History

taskpitch: limit frequency range and delay, update gettruth taskpitch: limit frequency range and delay, update gettruth

Paul Brossier committed 20 years ago

Commit 1944aaf1 parent 7538ac51 file · +59 −35Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/aubio/tasks.py+59−35
@@ -88,9 +88,9 @@ class taskparams(object): · 87 unmodified lines
88 self.threshold = 0.188 self.threshold = 0.1
89 self.onsetmode = 'dual'89 self.onsetmode = 'dual'
90 self.pitchmode = 'yin'90 self.pitchmode = 'yin'
91 self.pitchsmooth = 2091 self.pitchsmooth = 7
92 self.pitchmin=100.92 self.pitchmin=100.
93 self.pitchmax=1500.93 self.pitchmax=1000.
94 self.dcthreshold = -1.94 self.dcthreshold = -1.
95 self.omode = aubio_pitchm_freq95 self.omode = aubio_pitchm_freq
96 self.verbose = False96 self.verbose = False
@@ -213,25 +213,58 @@ class taskpitch(task): · 116 unmodified lines
213 return mylist213 return mylist
214 214
215 def gettruth(self):215 def gettruth(self):
216 """ big hack to extract midi note from /path/to/file.<midinote>.wav """216 """ extract ground truth array in frequency """
217 import os.path
218 """ from wavfile.txt """
219 datafile = self.input.replace('.wav','.txt')
220 if datafile == self.input: datafile = ""
221 """ from file.<midinote>.wav """
222 # FIXME very weak check
217 floatpit = self.input.split('.')[-2]223 floatpit = self.input.split('.')[-2]
218 try:224
219 return aubio_miditofreq(float(floatpit))225 if not os.path.isfile(datafile) and not len(self.input.split('.')) < 3:
220 except ValueError:226 print "no ground truth "
221 print "ERR: no truth file found"227 return False,False
222 return 0228 elif floatpit:
229 try:
230 self.truth = aubio_miditofreq(float(floatpit))
231 print "ground truth found in filename:", self.truth
232 tasksil = tasksilence(self.input)
233 time,pitch =[],[]
234 while(tasksil.readsize==tasksil.params.hopsize):
235 tasksil()
236 time.append(tasksil.params.step*tasksil.frameread)
237 if not tasksil.issilence:
238 pitch.append(self.truth)
239 else:
240 pitch.append(-1.)
241 return time,pitch #0,aubio_miditofreq(float(floatpit))
242 except ValueError:
243 # FIXME very weak check
244 if not os.path.isfile(datafile):
245 print "no ground truth found"
246 return 0,0
247 else:
248 from aubio.txtfile import read_datafile
249 values = read_datafile(datafile)
250 time, pitch = [], []
251 for i in range(len(values)):
252 time.append(values[i][0])
253 pitch.append(values[i][1])
254 return time,pitch
223 255
224 def eval(self,results):256 def eval(self,results):
225 def mmean(l):257 def mmean(l):
226 return sum(l)/max(float(len(l)),1)258 return sum(l)/max(float(len(l)),1)
227 259
228 from median import percental 260 from median import percental
229 self.truth = self.gettruth()261 timet,pitcht = self.gettruth()
230 res = []262 res = []
231 for i in results:263 for i in results:
264 #print i,self.truth
232 if i <= 0: pass265 if i <= 0: pass
233 else: res.append(self.truth-i)266 else: res.append(self.truth-i)
234 if not res: 267 if not res or len(res) < 3:
235 avg = self.truth; med = self.truth 268 avg = self.truth; med = self.truth
236 else:269 else:
237 avg = mmean(res) 270 avg = mmean(res)
@@ -239,8 +272,6 @@ class taskpitch(task): · 1 unmodified line
239 return self.truth, self.truth-med, self.truth-avg272 return self.truth, self.truth-med, self.truth-avg
240 273
241 def plot(self,pitch,wplot,oplots,outplot=None):274 def plot(self,pitch,wplot,oplots,outplot=None):
242 from aubio.txtfile import read_datafile
243 import os.path
244 import numarray275 import numarray
245 import Gnuplot276 import Gnuplot
246 277
@@ -248,32 +279,25 @@ class taskpitch(task): · 1 unmodified line
248 oplots.append(Gnuplot.Data(downtime,pitch,with='lines',279 oplots.append(Gnuplot.Data(downtime,pitch,with='lines',
249 title=self.params.pitchmode))280 title=self.params.pitchmode))
250 281
251 # check if ground truth exists
252 datafile = self.input.replace('.wav','.txt')
253 if datafile == self.input: datafile = ""
254 if not os.path.isfile(datafile):
255 self.title = "" #"truth file not found"
256 t = Gnuplot.Data(0,0,with='impulses')
257 else:
258 self.title = "" #"truth file plotting not implemented yet"
259 values = read_datafile(datafile)
260 if (len(datafile[0])) > 1:
261 time, pitch = [], []
262 for i in range(len(values)):
263 time.append(values[i][0])
264 pitch.append(values[i][1])
265 oplots.append(Gnuplot.Data(time,pitch,with='lines',
266 title='ground truth'))
267 282
268 def plotplot(self,wplot,oplots,outplot=None):283 def plotplot(self,wplot,oplots,outplot=None,multiplot = 1):
269 from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot284 from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot
270 import re285 import re
286 import Gnuplot
271 # audio data287 # audio data
272 time,data = audio_to_array(self.input)288 time,data = audio_to_array(self.input)
273 f = make_audio_plot(time,data)289 f = make_audio_plot(time,data)
274 290
291 # check if ground truth exists
292 timet,pitcht = self.gettruth()
293 if timet and pitcht:
294 oplots = [Gnuplot.Data(timet,pitcht,with='lines',
295 title='ground truth')] + oplots
296
297 t = Gnuplot.Data(0,0,with='impulses')
298
275 g = gnuplot_init(outplot)299 g = gnuplot_init(outplot)
276 g('set title \'%s %s\'' % (re.sub('.*/','',self.input),self.title))300 g('set title \'%s\'' % (re.sub('.*/','',self.input)))
277 g('set multiplot')301 g('set multiplot')
278 # hack to align left axis302 # hack to align left axis
279 g('set lmargin 15')303 g('set lmargin 15')
@@ -291,13 +315,13 @@ class taskpitch(task): · 11 unmodified lines
291 g('set size 1,0.7')315 g('set size 1,0.7')
292 g('set origin 0,0')316 g('set origin 0,0')
293 g('set xrange [0:%f]' % max(time))317 g('set xrange [0:%f]' % max(time))
294 g('set yrange [40:%f]' % self.params.pitchmax) 318 g('set yrange [100:%f]' % self.params.pitchmax)
295 g('set key right top')319 g('set key right top')
296 g('set noclip one') 320 g('set noclip one')
297 g('set format x ""')321 g('set format x ""')
322 g('set log y')
298 #g.xlabel('time (s)')323 #g.xlabel('time (s)')
299 g.ylabel('frequency (Hz)')324 g.ylabel('f0 (Hz)')
300 multiplot = 1
301 if multiplot:325 if multiplot:
302 for i in range(len(oplots)):326 for i in range(len(oplots)):
303 # plot onset detection functions327 # plot onset detection functions
@@ -427,12 +451,11 @@ class taskonset(task): · 123 unmodified lines
427 451
428 oplots.append(oplot)452 oplots.append(oplot)
429 453
430 # check if datafile exists truth454 # check if ground truth datafile exists
431 datafile = self.input.replace('.wav','.txt')455 datafile = self.input.replace('.wav','.txt')
432 if datafile == self.input: datafile = ""456 if datafile == self.input: datafile = ""
433 if not os.path.isfile(datafile):457 if not os.path.isfile(datafile):
434 self.title = "" #"(no ground truth)"458 self.title = "" #"(no ground truth)"
435 t = Gnuplot.Data(0,0,with='impulses')
436 else:459 else:
437 t_onsets = aubio.txtfile.read_datafile(datafile)460 t_onsets = aubio.txtfile.read_datafile(datafile)
438 x2 = numarray.array(t_onsets).resize(len(t_onsets))461 x2 = numarray.array(t_onsets).resize(len(t_onsets))
@@ -454,6 +477,7 @@ class taskonset(task): · 15 unmodified lines
454 # audio data477 # audio data
455 time,data = audio_to_array(self.input)478 time,data = audio_to_array(self.input)
456 wplot = [make_audio_plot(time,data)] + wplot479 wplot = [make_audio_plot(time,data)] + wplot
480 self.title = self.input
457 # prepare the plot481 # prepare the plot
458 g = gnuplot_init(outplot)482 g = gnuplot_init(outplot)
459 483

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