Changeset 1944aaf for python/aubio/tasks.py
- Timestamp:
- Mar 2, 2006, 7:42:37 PM (19 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- d45d118
- Parents:
- 7538ac5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/aubio/tasks.py
r7538ac5 r1944aaf 89 89 self.onsetmode = 'dual' 90 90 self.pitchmode = 'yin' 91 self.pitchsmooth = 2091 self.pitchsmooth = 7 92 92 self.pitchmin=100. 93 self.pitchmax=1 500.93 self.pitchmax=1000. 94 94 self.dcthreshold = -1. 95 95 self.omode = aubio_pitchm_freq … … 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): … … 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: … … 240 273 241 274 def plot(self,pitch,wplot,oplots,outplot=None): 242 from aubio.txtfile import read_datafile243 import os.path244 275 import numarray 245 276 import Gnuplot … … 249 280 title=self.params.pitchmode)) 250 281 251 # check if ground truth exists252 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 … … 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)): … … 428 452 oplots.append(oplot) 429 453 430 # check if datafile exists truth454 # 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) … … 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)
Note: See TracChangeset
for help on using the changeset viewer.