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
195195 return mylist
196196
197197
198−class taskparams:
198+class taskparams(object):
199199 """ default parameters for task classes """
200200 def __init__(self,input=None,output=None):
201201 self.silence = -70
@@ -288,8 +288,12 @@ class taskpitch(task): · 86 unmodified lines
288288
289289 def gettruth(self):
290290 """ big hack to extract midi note from /path/to/file.<midinote>.wav """
291− return float(self.input.split('.')[-2])
292−
291+ floatpit = self.input.split('.')[-2]
292+ try:
293+ return float(floatpit)
294+ except ValueError:
295+ print "ERR: no truth file found"
296+ return 0
293297
294298 def eval(self,results):
295299 from median import short_find
@@ -339,7 +343,7 @@ class taskonset(task): · 43 unmodified lines
339343 self.d,self.d2 = [],[]
340344 self.maxofunc = 0
341345 if self.params.localmin:
342− ovalist = [0., 0., 0., 0., 0.]
346+ self.ovalist = [0., 0., 0., 0., 0.]
343347
344348 def __call__(self):
345349 task.__call__(self)
@@ -349,9 +353,9 @@ class taskonset(task): · 3 unmodified lines
349353 if self.params.storefunc:
350354 self.ofunc.append(val)
351355 if self.params.localmin:
352− if val > 0: ovalist.append(val)
353− else: ovalist.append(0)
354− ovalist.pop(0)
356+ if val > 0: self.ovalist.append(val)
357+ else: self.ovalist.append(0)
358+ self.ovalist.pop(0)
355359 if (isonset == 1):
356360 if self.params.localmin:
357361 i=len(self.ovalist)-1
@@ -365,14 +369,25 @@ class taskonset(task): · 7 unmodified lines
365369 now = 0
366370 return now, val
367371
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+
368379 def eval(self,lres):
369380 from txtfile import read_datafile
370381 from onsetcompare import onset_roc
371382 amode = 'roc'
372383 vmode = 'verbose'
373384 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)
374390 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)
376391 if vmode=='verbose':
377392 print "Running with mode %s" % self.params.mode,
378393 print " and threshold %f" % self.params.threshold,
@@ -502,3 +517,39 @@ class taskcut(task): · 123 unmodified lines
502517 writesize = self.fileo.write(fromcross,self.mycopy)
503518 else:
504519 writesize = self.fileo.write(self.readsize,self.myvec)
520+
521+class 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