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
8888 self.threshold = 0.1
8989 self.onsetmode = 'dual'
9090 self.pitchmode = 'yin'
91− self.pitchsmooth = 20
91+ self.pitchsmooth = 7
9292 self.pitchmin=100.
93− self.pitchmax=1500.
93+ self.pitchmax=1000.
9494 self.dcthreshold = -1.
9595 self.omode = aubio_pitchm_freq
9696 self.verbose = False
@@ -213,25 +213,58 @@ class taskpitch(task): · 116 unmodified lines
213213 return mylist
214214
215215 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
217223 floatpit = self.input.split('.')[-2]
218− try:
219− return aubio_miditofreq(float(floatpit))
220− except ValueError:
221− print "ERR: no truth file found"
222− return 0
224+
225+ if not os.path.isfile(datafile) and not len(self.input.split('.')) < 3:
226+ print "no ground truth "
227+ return False,False
228+ 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
223255
224256 def eval(self,results):
225257 def mmean(l):
226258 return sum(l)/max(float(len(l)),1)
227259
228260 from median import percental
229− self.truth = self.gettruth()
261+ timet,pitcht = self.gettruth()
230262 res = []
231263 for i in results:
264+ #print i,self.truth
232265 if i <= 0: pass
233266 else: res.append(self.truth-i)
234− if not res:
267+ if not res or len(res) < 3:
235268 avg = self.truth; med = self.truth
236269 else:
237270 avg = mmean(res)
@@ -239,8 +272,6 @@ class taskpitch(task): · 1 unmodified line
239272 return self.truth, self.truth-med, self.truth-avg
240273
241274 def plot(self,pitch,wplot,oplots,outplot=None):
242− from aubio.txtfile import read_datafile
243− import os.path
244275 import numarray
245276 import Gnuplot
246277
@@ -248,32 +279,25 @@ class taskpitch(task): · 1 unmodified line
248279 oplots.append(Gnuplot.Data(downtime,pitch,with='lines',
249280 title=self.params.pitchmode))
250281
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'))
267282
268− def plotplot(self,wplot,oplots,outplot=None):
283+ def plotplot(self,wplot,oplots,outplot=None,multiplot = 1):
269284 from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot
270285 import re
286+ import Gnuplot
271287 # audio data
272288 time,data = audio_to_array(self.input)
273289 f = make_audio_plot(time,data)
274290
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+
275299 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)))
277301 g('set multiplot')
278302 # hack to align left axis
279303 g('set lmargin 15')
@@ -291,13 +315,13 @@ class taskpitch(task): · 11 unmodified lines
291315 g('set size 1,0.7')
292316 g('set origin 0,0')
293317 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)
295319 g('set key right top')
296320 g('set noclip one')
297321 g('set format x ""')
322+ g('set log y')
298323 #g.xlabel('time (s)')
299− g.ylabel('frequency (Hz)')
300− multiplot = 1
324+ g.ylabel('f0 (Hz)')
301325 if multiplot:
302326 for i in range(len(oplots)):
303327 # plot onset detection functions
@@ -427,12 +451,11 @@ class taskonset(task): · 123 unmodified lines
427451
428452 oplots.append(oplot)
429453
430− # check if datafile exists truth
454+ # check if ground truth datafile exists
431455 datafile = self.input.replace('.wav','.txt')
432456 if datafile == self.input: datafile = ""
433457 if not os.path.isfile(datafile):
434458 self.title = "" #"(no ground truth)"
435− t = Gnuplot.Data(0,0,with='impulses')
436459 else:
437460 t_onsets = aubio.txtfile.read_datafile(datafile)
438461 x2 = numarray.array(t_onsets).resize(len(t_onsets))
@@ -454,6 +477,7 @@ class taskonset(task): · 15 unmodified lines
454477 # audio data
455478 time,data = audio_to_array(self.input)
456479 wplot = [make_audio_plot(time,data)] + wplot
480+ self.title = self.input
457481 # prepare the plot
458482 g = gnuplot_init(outplot)
459483

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