Changeset 84e80a1 for python/aubio/tasks.py
- Timestamp:
- Feb 26, 2006, 6:34:08 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:
- 83ff0ab
- Parents:
- ea98179
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/aubio/tasks.py
rea98179 r84e80a1 201 201 self.derivate = False 202 202 self.localmin = False 203 self.delay = 0.203 self.delay = 4. 204 204 self.storefunc = False 205 205 self.bufsize = 512 … … 212 212 self.onsetmode = 'dual' 213 213 self.pitchmode = 'yin' 214 self.dcthreshold = -1. 214 215 self.omode = aubio_pitchm_freq 216 self.verbose = False 215 217 216 218 class task(taskparams): … … 230 232 self.srate = self.filei.samplerate() 231 233 self.channels = self.filei.channels() 232 self. step = float(self.srate)/float(self.params.hopsize)234 self.params.step = float(self.params.hopsize)/float(self.srate) 233 235 self.myvec = fvec(self.params.hopsize,self.channels) 234 236 self.output = output … … 243 245 while(self.readsize==self.params.hopsize): 244 246 tmp = self() 245 if tmp: mylist.append(tmp) 247 if tmp: 248 mylist.append(tmp) 249 if self.params.verbose: 250 self.fprint(tmp) 246 251 return mylist 252 253 def fprint(self,foo): 254 print foo 247 255 248 256 def eval(self,results): … … 273 281 self.wassilence = 0 274 282 if self.issilence == -1: 275 return self.frameread, -1283 return max(self.frameread-self.params.delay,0.), -1 276 284 elif self.issilence == 2: 277 return self.frameread, 2 285 return max(self.frameread+self.params.delay,0.), 2 286 287 def fprint(self,foo): 288 print self.params.step*foo[0], 289 if foo[1] == 2: print "OFF" 290 else: print "ON" 278 291 279 292 class taskpitch(task): … … 344 357 self.params.threshold, 345 358 mode=get_onset_mode(self.params.onsetmode), 359 dcthreshold=self.params.dcthreshold, 346 360 derivate=self.params.derivate) 347 361 self.olist = [] 348 362 self.ofunc = [] 349 self.d,self.d2 = [],[]350 363 self.maxofunc = 0 351 364 self.last = 0 … … 366 379 if (isonset == 1): 367 380 if self.params.localmin: 381 # find local minima before peak 368 382 i=len(self.ovalist)-1 369 # find local minima before peak370 383 while self.ovalist[i-1] < self.ovalist[i] and i > 0: 371 384 i -= 1 … … 373 386 else: 374 387 now = self.frameread 388 # take back delay 375 389 if self.params.delay != 0.: now -= self.params.delay 376 390 if now < 0 : 377 391 now = 0 378 392 if self.params.mintol: 379 # print now - self.last, self.params.mintol393 # prune doubled 380 394 if (now - self.last) > self.params.mintol: 381 395 self.last = now … … 384 398 return now, val 385 399 400 401 def fprint(self,foo): 402 print self.params.step*foo[0] 386 403 387 404 def eval(self,inputdata,ftru,mode='roc',vmode=''): … … 414 431 onset_rocloc(ltru,lres,self.params.tol) 415 432 416 def plot(self,onsets,ofunc ):433 def plot(self,onsets,ofunc,wplot,oplots,nplot=False): 417 434 import Gnuplot, Gnuplot.funcutils 418 435 import aubio.txtfile … … 421 438 from aubio.onsetcompare import onset_roc 422 439 440 x1,y1,y1p = [],[],[] 441 oplot = [] 442 423 443 self.lenofunc = len(ofunc) 424 self.maxofunc = max( max(ofunc), self.maxofunc)444 self.maxofunc = max(ofunc) 425 445 # onset detection function 426 downtime = numarray.arange(len(ofunc)) /self.step427 self.d.append(Gnuplot.Data(downtime,ofunc,with='lines'))446 downtime = numarray.arange(len(ofunc))*self.params.step 447 oplot.append(Gnuplot.Data(downtime,ofunc,with='lines',title=self.params.onsetmode)) 428 448 429 449 # detected onsets 430 x1 = numarray.array(onsets)/self.step 431 y1 = self.maxofunc*numarray.ones(len(onsets)) 432 self.d.append(Gnuplot.Data(x1,y1,with='impulses')) 433 self.d2.append(Gnuplot.Data(x1,-y1,with='impulses')) 450 if not nplot: 451 for i in onsets: 452 x1.append(i[0]*self.params.step) 453 y1.append(self.maxofunc) 454 y1p.append(-self.maxofunc) 455 #x1 = numarray.array(onsets)*self.params.step 456 #y1 = self.maxofunc*numarray.ones(len(onsets)) 457 if x1: 458 oplot.append(Gnuplot.Data(x1,y1,with='impulses')) 459 wplot.append(Gnuplot.Data(x1,y1p,with='impulses')) 460 461 oplots.append(oplot) 434 462 435 463 # check if datafile exists truth … … 437 465 if datafile == self.input: datafile = "" 438 466 if not os.path.isfile(datafile): 439 self.title = " truth file not found"467 self.title = "" #"(no ground truth)" 440 468 t = Gnuplot.Data(0,0,with='impulses') 441 469 else: 442 470 t_onsets = aubio.txtfile.read_datafile(datafile) 471 x2 = numarray.array(t_onsets).resize(len(t_onsets)) 443 472 y2 = self.maxofunc*numarray.ones(len(t_onsets)) 444 x2 = numarray.array(t_onsets).resize(len(t_onsets)) 445 self.d2.append(Gnuplot.Data(x2,y2,with='impulses')) 473 wplot.append(Gnuplot.Data(x2,y2,with='impulses')) 446 474 447 475 tol = 0.050 … … 454 482 455 483 456 def plotplot(self, outplot=None):484 def plotplot(self,wplot,oplot,outplot=None): 457 485 from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot 458 486 import re 459 487 # audio data 460 488 time,data = audio_to_array(self.input) 461 self.d2.append(make_audio_plot(time,data))489 wplot = [make_audio_plot(time,data)] + wplot 462 490 # prepare the plot 463 491 g = gnuplot_init(outplot) 464 492 493 g('set multiplot') 494 495 # hack to align left axis 496 g('set lmargin 6') 497 g('set tmargin 0') 498 g('set format x ""') 499 g('set format y ""') 500 g('set noytics') 501 502 for i in range(len(oplot)): 503 # plot onset detection functions 504 g('set size 1,%f' % (0.7/(len(oplot)))) 505 g('set origin 0,%f' % (float(i)*0.7/(len(oplot)))) 506 g('set xrange [0:%f]' % (self.lenofunc*self.params.step)) 507 g.plot(*oplot[i]) 508 509 g('set tmargin 3') 510 g('set format x "%10.1f"') 511 465 512 g('set title \'%s %s\'' % (re.sub('.*/','',self.input),self.title)) 466 467 g('set multiplot')468 469 # hack to align left axis470 g('set lmargin 15')471 513 472 514 # plot waveform and onsets … … 476 518 g('set yrange [-1:1]') 477 519 g.ylabel('amplitude') 478 g.plot(* self.d2)520 g.plot(*wplot) 479 521 480 g('unset title')481 482 # plot onset detection function483 g('set size 1,0.7')484 g('set origin 0,0')485 g('set xrange [0:%f]' % (self.lenofunc/self.step))486 g('set yrange [0:%f]' % (self.maxofunc*1.01))487 g.xlabel('time')488 g.ylabel('onset detection value')489 g.plot(*self.d)490 491 522 g('unset multiplot') 492 523 … … 498 529 task.__init__(self,input,output=None,params=params) 499 530 self.newname = "%s%s%09.5f%s%s" % (self.input.split(".")[0].split("/")[-1],".", 500 self.frameread /self.step,".",self.input.split(".")[-1])501 self.fileo 502 self.myvec 531 self.frameread*self.params.step,".",self.input.split(".")[-1]) 532 self.fileo = sndfile(self.newname,model=self.filei) 533 self.myvec = fvec(self.params.hopsize,self.channels) 503 534 self.mycopy = fvec(self.params.hopsize,self.channels) 504 535 self.slicetimes = slicetimes … … 507 538 task.__call__(self) 508 539 # write to current file 509 if len(self.slicetimes) and self.frameread >= self.slicetimes[0] :540 if len(self.slicetimes) and self.frameread >= self.slicetimes[0][0]: 510 541 self.slicetimes.pop(0) 511 542 # write up to 1st zero crossing … … 523 554 self.fileo = sndfile("%s%s%09.5f%s%s" % 524 555 (self.input.split(".")[0].split("/")[-1],".", 525 self.frameread /self.step,".",self.input.split(".")[-1]),model=self.filei)556 self.frameread*self.params.step,".",self.input.split(".")[-1]),model=self.filei) 526 557 writesize = self.fileo.write(fromcross,self.mycopy) 527 558 else:
Note: See TracChangeset
for help on using the changeset viewer.