Changeset 84e80a1


Ignore:
Timestamp:
Feb 26, 2006, 6:34:08 PM (18 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:
83ff0ab
Parents:
ea98179
Message:

added support for dcthres and verbose, moved task.step to tasks.params.step, updated plot functions
added support for dcthres and verbose, moved task.step to tasks.params.step, updated plot functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/aubio/tasks.py

    rea98179 r84e80a1  
    201201                self.derivate = False
    202202                self.localmin = False
    203                 self.delay = 0.
     203                self.delay = 4.
    204204                self.storefunc = False
    205205                self.bufsize = 512
     
    212212                self.onsetmode = 'dual'
    213213                self.pitchmode = 'yin'
     214                self.dcthreshold = -1.
    214215                self.omode = aubio_pitchm_freq
     216                self.verbose   = False
    215217
    216218class task(taskparams):
     
    230232                self.srate     = self.filei.samplerate()
    231233                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)
    233235                self.myvec     = fvec(self.params.hopsize,self.channels)
    234236                self.output    = output
     
    243245                while(self.readsize==self.params.hopsize):
    244246                        tmp = self()
    245                         if tmp: mylist.append(tmp)
     247                        if tmp:
     248                                mylist.append(tmp)
     249                                if self.params.verbose:
     250                                        self.fprint(tmp)
    246251                return mylist
     252       
     253        def fprint(self,foo):
     254                print foo
    247255
    248256        def eval(self,results):
     
    273281                        self.wassilence = 0
    274282                if self.issilence == -1:
    275                         return self.frameread, -1
     283                        return max(self.frameread-self.params.delay,0.), -1
    276284                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"
    278291
    279292class taskpitch(task):
     
    344357                        self.params.threshold,
    345358                        mode=get_onset_mode(self.params.onsetmode),
     359                        dcthreshold=self.params.dcthreshold,
    346360                        derivate=self.params.derivate)
    347361                self.olist = []
    348362                self.ofunc = []
    349                 self.d,self.d2 = [],[]
    350363                self.maxofunc = 0
    351364                self.last = 0
     
    366379                if (isonset == 1):
    367380                        if self.params.localmin:
     381                                # find local minima before peak
    368382                                i=len(self.ovalist)-1
    369                                 # find local minima before peak
    370383                                while self.ovalist[i-1] < self.ovalist[i] and i > 0:
    371384                                        i -= 1
     
    373386                        else:
    374387                                now = self.frameread
     388                        # take back delay
    375389                        if self.params.delay != 0.: now -= self.params.delay
    376390                        if now < 0 :
    377391                                now = 0
    378392                        if self.params.mintol:
    379                                 #print now - self.last, self.params.mintol
     393                                # prune doubled
    380394                                if (now - self.last) > self.params.mintol:
    381395                                        self.last = now
     
    384398                                return now, val
    385399
     400
     401        def fprint(self,foo):
     402                print self.params.step*foo[0]
    386403
    387404        def eval(self,inputdata,ftru,mode='roc',vmode=''):
     
    414431                                onset_rocloc(ltru,lres,self.params.tol)
    415432
    416         def plot(self,onsets,ofunc):
     433        def plot(self,onsets,ofunc,wplot,oplots,nplot=False):
    417434                import Gnuplot, Gnuplot.funcutils
    418435                import aubio.txtfile
     
    421438                from aubio.onsetcompare import onset_roc
    422439
     440                x1,y1,y1p = [],[],[]
     441                oplot = []
     442
    423443                self.lenofunc = len(ofunc)
    424                 self.maxofunc = max(max(ofunc), self.maxofunc)
     444                self.maxofunc = max(ofunc)
    425445                # onset detection function
    426                 downtime = numarray.arange(len(ofunc))/self.step
    427                 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))
    428448
    429449                # 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)
    434462
    435463                # check if datafile exists truth
     
    437465                if datafile == self.input: datafile = ""
    438466                if not os.path.isfile(datafile):
    439                         self.title = "truth file not found"
     467                        self.title = "" #"(no ground truth)"
    440468                        t = Gnuplot.Data(0,0,with='impulses')
    441469                else:
    442470                        t_onsets = aubio.txtfile.read_datafile(datafile)
     471                        x2 = numarray.array(t_onsets).resize(len(t_onsets))
    443472                        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'))
    446474                       
    447475                        tol = 0.050
     
    454482
    455483
    456         def plotplot(self,outplot=None):
     484        def plotplot(self,wplot,oplot,outplot=None):
    457485                from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot
    458486                import re
    459487                # audio data
    460488                time,data = audio_to_array(self.input)
    461                 self.d2.append(make_audio_plot(time,data))
     489                wplot = [make_audio_plot(time,data)] + wplot
    462490                # prepare the plot
    463491                g = gnuplot_init(outplot)
    464492
     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
    465512                g('set title \'%s %s\'' % (re.sub('.*/','',self.input),self.title))
    466 
    467                 g('set multiplot')
    468 
    469                 # hack to align left axis
    470                 g('set lmargin 15')
    471513
    472514                # plot waveform and onsets
     
    476518                g('set yrange [-1:1]')
    477519                g.ylabel('amplitude')
    478                 g.plot(*self.d2)
     520                g.plot(*wplot)
    479521               
    480                 g('unset title')
    481 
    482                 # plot onset detection function
    483                 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 
    491522                g('unset multiplot')
    492523
     
    498529                task.__init__(self,input,output=None,params=params)
    499530                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       = sndfile(self.newname,model=self.filei)
    502                 self.myvec       = fvec(self.params.hopsize,self.channels)
     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)
    503534                self.mycopy     = fvec(self.params.hopsize,self.channels)
    504535                self.slicetimes = slicetimes
     
    507538                task.__call__(self)
    508539                # 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]:
    510541                        self.slicetimes.pop(0)
    511542                        # write up to 1st zero crossing
     
    523554                        self.fileo = sndfile("%s%s%09.5f%s%s" %
    524555                                (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)
    526557                        writesize = self.fileo.write(fromcross,self.mycopy)
    527558                else:
Note: See TracChangeset for help on using the changeset viewer.