History

add taskbeat, make taskparams an object subclass, fix bug on localmin add taskbeat, make taskparams an object subclass, fix bug on localmin

Paul Brossier committed 20 years ago

Commit c32976a1 parent 1dae4eb1 file · +59 −8Browse files

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

Unified · Split

python/aubio/tasks.py+59−8
@@ -195,7 +195,7 @@ def getpitch(filein,mode=aubio_pitch_mcomb,bufsize=1024,hopsize=512,omode=aubio_ · 194 unmodified lines
195 return mylist195 return mylist
196 196
197 197
198class taskparams:198class taskparams(object):
199 """ default parameters for task classes """199 """ default parameters for task classes """
200 def __init__(self,input=None,output=None):200 def __init__(self,input=None,output=None):
201 self.silence = -70201 self.silence = -70
@@ -288,8 +288,12 @@ class taskpitch(task): · 86 unmodified lines
288 288
289 def gettruth(self):289 def gettruth(self):
290 """ big hack to extract midi note from /path/to/file.<midinote>.wav """290 """ big hack to extract midi note from /path/to/file.<midinote>.wav """
291 return float(self.input.split('.')[-2])291 floatpit = self.input.split('.')[-2]
292 292 try:
293 return float(floatpit)
294 except ValueError:
295 print "ERR: no truth file found"
296 return 0
293 297
294 def eval(self,results):298 def eval(self,results):
295 from median import short_find 299 from median import short_find
@@ -339,7 +343,7 @@ class taskonset(task): · 43 unmodified lines
339 self.d,self.d2 = [],[]343 self.d,self.d2 = [],[]
340 self.maxofunc = 0344 self.maxofunc = 0
341 if self.params.localmin:345 if self.params.localmin:
342 ovalist = [0., 0., 0., 0., 0.]346 self.ovalist = [0., 0., 0., 0., 0.]
343 347
344 def __call__(self):348 def __call__(self):
345 task.__call__(self)349 task.__call__(self)
@@ -349,9 +353,9 @@ class taskonset(task): · 3 unmodified lines
349 if self.params.storefunc:353 if self.params.storefunc:
350 self.ofunc.append(val)354 self.ofunc.append(val)
351 if self.params.localmin:355 if self.params.localmin:
352 if val > 0: ovalist.append(val)356 if val > 0: self.ovalist.append(val)
353 else: ovalist.append(0)357 else: self.ovalist.append(0)
354 ovalist.pop(0)358 self.ovalist.pop(0)
355 if (isonset == 1):359 if (isonset == 1):
356 if self.params.localmin:360 if self.params.localmin:
357 i=len(self.ovalist)-1361 i=len(self.ovalist)-1
@@ -365,14 +369,25 @@ class taskonset(task): · 7 unmodified lines
365 now = 0369 now = 0
366 return now, val 370 return now, val
367 371
372 def gettruth(self):
373 from os.path import isfile
374 ftru = '.'.join(self.input.split('.')[:-1])
375 ftru = '.'.join((ftru,'txt'))
376 if isfile(ftru): return ftru
377 else: return
378
368 def eval(self,lres):379 def eval(self,lres):
369 from txtfile import read_datafile 380 from txtfile import read_datafile
370 from onsetcompare import onset_roc381 from onsetcompare import onset_roc
371 amode = 'roc'382 amode = 'roc'
372 vmode = 'verbose'383 vmode = 'verbose'
373 vmode = ''384 vmode = ''
385 ftru = self.gettruth()
386 if not ftru:
387 print "ERR: no truth file found"
388 return
389 ltru = read_datafile(ftru,depth=0)
374 for i in range(len(lres)): lres[i] = lres[i][0]*self.params.step390 for i in range(len(lres)): lres[i] = lres[i][0]*self.params.step
375 ltru = read_datafile(self.input.replace('.wav','.txt'),depth=0)
376 if vmode=='verbose':391 if vmode=='verbose':
377 print "Running with mode %s" % self.params.mode, 392 print "Running with mode %s" % self.params.mode,
378 print " and threshold %f" % self.params.threshold, 393 print " and threshold %f" % self.params.threshold,
@@ -502,3 +517,39 @@ class taskcut(task): · 123 unmodified lines
502 writesize = self.fileo.write(fromcross,self.mycopy)517 writesize = self.fileo.write(fromcross,self.mycopy)
503 else:518 else:
504 writesize = self.fileo.write(self.readsize,self.myvec)519 writesize = self.fileo.write(self.readsize,self.myvec)
520
521class taskbeat(taskonset):
522 def __init__(self,input,params=None,output=None):
523 """ open the input file and initialize arguments
524 parameters should be set *before* calling this method.
525 """
526 taskonset.__init__(self,input,output=None,params=params)
527 self.btwinlen = 512**2/self.params.hopsize
528 self.btstep = self.btwinlen/4
529 self.btoutput = fvec(self.btstep,self.channels)
530 self.dfframe = fvec(self.btwinlen,self.channels)
531 self.bt = beattracking(self.btwinlen,self.channels)
532 self.pos2 = 0
533
534 def __call__(self):
535 taskonset.__call__(self)
536 # write to current file
537 if self.pos2 == self.btstep - 1 :
538 self.bt.do(self.dfframe,self.btoutput)
539 for i in range (self.btwinlen - self.btstep):
540 self.dfframe.set(self.dfframe.get(i+self.btstep,0),i,0)
541 for i in range(self.btwinlen - self.btstep, self.btwinlen):
542 self.dfframe.set(0,i,0)
543 self.pos2 = -1;
544 self.pos2 += 1
545 val = self.opick.pp.getval()
546 self.dfframe.set(val,self.btwinlen - self.btstep + self.pos2,0)
547 i=0
548 for i in range(1,int( self.btoutput.get(0,0) ) ):
549 if self.pos2 == self.btoutput.get(i,0) and \
550 aubio_silence_detection(self.myvec(),
551 self.params.silence)!=1:
552 return self.frameread, 0
553
554 def eval(self,results):
555 pass

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