Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -88,9 +88,9 @@ class taskparams(object): · 87 unmodified lines | ||
| 88 | 88 | self.threshold = 0.1 |
| 89 | 89 | self.onsetmode = 'dual' |
| 90 | 90 | self.pitchmode = 'yin' |
| 91 | − self.pitchsmooth = 20 | |
| 91 | + self.pitchsmooth = 7 | |
| 92 | 92 | self.pitchmin=100. |
| 93 | − self.pitchmax=1500. | |
| 93 | + self.pitchmax=1000. | |
| 94 | 94 | self.dcthreshold = -1. |
| 95 | 95 | self.omode = aubio_pitchm_freq |
| 96 | 96 | self.verbose = False |
| @@ -213,25 +213,58 @@ class taskpitch(task): · 116 unmodified lines | ||
| 213 | 213 | return mylist |
| 214 | 214 | |
| 215 | 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 | 223 | 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 | |
| 223 | 255 | |
| 224 | 256 | def eval(self,results): |
| 225 | 257 | def mmean(l): |
| 226 | 258 | return sum(l)/max(float(len(l)),1) |
| 227 | 259 | |
| 228 | 260 | from median import percental |
| 229 | − self.truth = self.gettruth() | |
| 261 | + timet,pitcht = self.gettruth() | |
| 230 | 262 | res = [] |
| 231 | 263 | for i in results: |
| 264 | + #print i,self.truth | |
| 232 | 265 | if i <= 0: pass |
| 233 | 266 | else: res.append(self.truth-i) |
| 234 | − if not res: | |
| 267 | + if not res or len(res) < 3: | |
| 235 | 268 | avg = self.truth; med = self.truth |
| 236 | 269 | else: |
| 237 | 270 | avg = mmean(res) |
| @@ -239,8 +272,6 @@ class taskpitch(task): · 1 unmodified line | ||
| 239 | 272 | return self.truth, self.truth-med, self.truth-avg |
| 240 | 273 | |
| 241 | 274 | def plot(self,pitch,wplot,oplots,outplot=None): |
| 242 | − from aubio.txtfile import read_datafile | |
| 243 | − import os.path | |
| 244 | 275 | import numarray |
| 245 | 276 | import Gnuplot |
| 246 | 277 | |
| @@ -248,32 +279,25 @@ class taskpitch(task): · 1 unmodified line | ||
| 248 | 279 | oplots.append(Gnuplot.Data(downtime,pitch,with='lines', |
| 249 | 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 | 284 | from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot |
| 270 | 285 | import re |
| 286 | + import Gnuplot | |
| 271 | 287 | # audio data |
| 272 | 288 | time,data = audio_to_array(self.input) |
| 273 | 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 | 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 | 301 | g('set multiplot') |
| 278 | 302 | # hack to align left axis |
| 279 | 303 | g('set lmargin 15') |
| @@ -291,13 +315,13 @@ class taskpitch(task): · 11 unmodified lines | ||
| 291 | 315 | g('set size 1,0.7') |
| 292 | 316 | g('set origin 0,0') |
| 293 | 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 | 319 | g('set key right top') |
| 296 | 320 | g('set noclip one') |
| 297 | 321 | g('set format x ""') |
| 322 | + g('set log y') | |
| 298 | 323 | #g.xlabel('time (s)') |
| 299 | − g.ylabel('frequency (Hz)') | |
| 300 | − multiplot = 1 | |
| 324 | + g.ylabel('f0 (Hz)') | |
| 301 | 325 | if multiplot: |
| 302 | 326 | for i in range(len(oplots)): |
| 303 | 327 | # plot onset detection functions |
| @@ -427,12 +451,11 @@ class taskonset(task): · 123 unmodified lines | ||
| 427 | 451 | |
| 428 | 452 | oplots.append(oplot) |
| 429 | 453 | |
| 430 | − # check if datafile exists truth | |
| 454 | + # check if ground truth datafile exists | |
| 431 | 455 | datafile = self.input.replace('.wav','.txt') |
| 432 | 456 | if datafile == self.input: datafile = "" |
| 433 | 457 | if not os.path.isfile(datafile): |
| 434 | 458 | self.title = "" #"(no ground truth)" |
| 435 | − t = Gnuplot.Data(0,0,with='impulses') | |
| 436 | 459 | else: |
| 437 | 460 | t_onsets = aubio.txtfile.read_datafile(datafile) |
| 438 | 461 | x2 = numarray.array(t_onsets).resize(len(t_onsets)) |
| @@ -454,6 +477,7 @@ class taskonset(task): · 15 unmodified lines | ||
| 454 | 477 | # audio data |
| 455 | 478 | time,data = audio_to_array(self.input) |
| 456 | 479 | wplot = [make_audio_plot(time,data)] + wplot |
| 480 | + self.title = self.input | |
| 457 | 481 | # prepare the plot |
| 458 | 482 | g = gnuplot_init(outplot) |
| 459 | 483 | |