Changeset c32976a5


Ignore:
Timestamp:
Dec 22, 2005, 5:54:29 PM (19 years ago)
Author:
Paul Brossier <piem@altern.org>
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:
ada5baf
Parents:
1dae4eb
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/aubio/tasks.py

    r1dae4eb rc32976a5  
    196196
    197197
    198 class taskparams:
     198class taskparams(object):
    199199        """ default parameters for task classes """
    200200        def __init__(self,input=None,output=None):
     
    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):
     
    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):
     
    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:
     
    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
     
    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,
     
    503518                else:
    504519                        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
Note: See TracChangeset for help on using the changeset viewer.