Changeset 1944aaf


Ignore:
Timestamp:
Mar 2, 2006, 7:42:37 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:
d45d118
Parents:
7538ac5
Message:

taskpitch: limit frequency range and delay, update gettruth
taskpitch: limit frequency range and delay, update gettruth

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/aubio/tasks.py

    r7538ac5 r1944aaf  
    8989                self.onsetmode = 'dual'
    9090                self.pitchmode = 'yin'
    91                 self.pitchsmooth = 20
     91                self.pitchsmooth = 7
    9292                self.pitchmin=100.
    93                 self.pitchmax=1500.
     93                self.pitchmax=1000.
    9494                self.dcthreshold = -1.
    9595                self.omode = aubio_pitchm_freq
     
    214214
    215215        def gettruth(self):
    216                 """ big hack to extract midi note from /path/to/file.<midinote>.wav """
     216                """ extract ground truth array in frequency """
     217                import os.path
     218                """ from wavfile.txt """
     219                datafile = self.input.replace('.wav','.txt')
     220                if datafile == self.input: datafile = ""
     221                """ from file.<midinote>.wav """
     222                # FIXME very weak check
    217223                floatpit = self.input.split('.')[-2]
    218                 try:
    219                         return aubio_miditofreq(float(floatpit))
    220                 except ValueError:
    221                         print "ERR: no truth file found"
    222                         return 0
     224
     225                if not os.path.isfile(datafile) and not len(self.input.split('.')) < 3:
     226                        print "no ground truth "
     227                        return False,False
     228                elif floatpit:
     229                        try:
     230                                self.truth = aubio_miditofreq(float(floatpit))
     231                                print "ground truth found in filename:", self.truth
     232                                tasksil = tasksilence(self.input)
     233                                time,pitch =[],[]
     234                                while(tasksil.readsize==tasksil.params.hopsize):
     235                                        tasksil()
     236                                        time.append(tasksil.params.step*tasksil.frameread)
     237                                        if not tasksil.issilence:
     238                                                pitch.append(self.truth)
     239                                        else:
     240                                                pitch.append(-1.)
     241                                return time,pitch #0,aubio_miditofreq(float(floatpit))
     242                        except ValueError:
     243                                # FIXME very weak check
     244                                if not os.path.isfile(datafile):
     245                                        print "no ground truth found"
     246                                        return 0,0
     247                                else:
     248                                        from aubio.txtfile import read_datafile
     249                                        values = read_datafile(datafile)
     250                                        time, pitch = [], []
     251                                        for i in range(len(values)):
     252                                                time.append(values[i][0])
     253                                                pitch.append(values[i][1])
     254                                        return time,pitch
    223255
    224256        def eval(self,results):
     
    227259
    228260                from median import percental
    229                 self.truth = self.gettruth()
     261                timet,pitcht = self.gettruth()
    230262                res = []
    231263                for i in results:
     264                        #print i,self.truth
    232265                        if i <= 0: pass
    233266                        else: res.append(self.truth-i)
    234                 if not res:
     267                if not res or len(res) < 3:
    235268                        avg = self.truth; med = self.truth
    236269                else:
     
    240273
    241274        def plot(self,pitch,wplot,oplots,outplot=None):
    242                 from aubio.txtfile import read_datafile
    243                 import os.path
    244275                import numarray
    245276                import Gnuplot
     
    249280                        title=self.params.pitchmode))
    250281
    251                 # check if ground truth exists
    252                 datafile = self.input.replace('.wav','.txt')
    253                 if datafile == self.input: datafile = ""
    254                 if not os.path.isfile(datafile):
    255                         self.title = "" #"truth file not found"
    256                         t = Gnuplot.Data(0,0,with='impulses')
    257                 else:
    258                         self.title = "" #"truth file plotting not implemented yet"
    259                         values = read_datafile(datafile)
    260                         if (len(datafile[0])) > 1:
    261                                 time, pitch = [], []
    262                                 for i in range(len(values)):
    263                                         time.append(values[i][0])
    264                                         pitch.append(values[i][1])
    265                                 oplots.append(Gnuplot.Data(time,pitch,with='lines',
    266                                         title='ground truth'))
    267282                       
    268         def plotplot(self,wplot,oplots,outplot=None):
     283        def plotplot(self,wplot,oplots,outplot=None,multiplot = 1):
    269284                from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot
    270285                import re
     286                import Gnuplot
    271287                # audio data
    272288                time,data = audio_to_array(self.input)
    273289                f = make_audio_plot(time,data)
    274290
     291                # check if ground truth exists
     292                timet,pitcht = self.gettruth()
     293                if timet and pitcht:
     294                        oplots = [Gnuplot.Data(timet,pitcht,with='lines',
     295                                title='ground truth')] + oplots
     296
     297                t = Gnuplot.Data(0,0,with='impulses')
     298
    275299                g = gnuplot_init(outplot)
    276                 g('set title \'%s %s\'' % (re.sub('.*/','',self.input),self.title))
     300                g('set title \'%s\'' % (re.sub('.*/','',self.input)))
    277301                g('set multiplot')
    278302                # hack to align left axis
     
    292316                g('set origin 0,0')
    293317                g('set xrange [0:%f]' % max(time))
    294                 g('set yrange [40:%f]' % self.params.pitchmax)
     318                g('set yrange [100:%f]' % self.params.pitchmax)
    295319                g('set key right top')
    296320                g('set noclip one')
    297321                g('set format x ""')
     322                g('set log y')
    298323                #g.xlabel('time (s)')
    299                 g.ylabel('frequency (Hz)')
    300                 multiplot = 1
     324                g.ylabel('f0 (Hz)')
    301325                if multiplot:
    302326                        for i in range(len(oplots)):
     
    428452                oplots.append(oplot)
    429453
    430                 # check if datafile exists truth
     454                # check if ground truth datafile exists
    431455                datafile = self.input.replace('.wav','.txt')
    432456                if datafile == self.input: datafile = ""
    433457                if not os.path.isfile(datafile):
    434458                        self.title = "" #"(no ground truth)"
    435                         t = Gnuplot.Data(0,0,with='impulses')
    436459                else:
    437460                        t_onsets = aubio.txtfile.read_datafile(datafile)
     
    455478                time,data = audio_to_array(self.input)
    456479                wplot = [make_audio_plot(time,data)] + wplot
     480                self.title = self.input
    457481                # prepare the plot
    458482                g = gnuplot_init(outplot)
Note: See TracChangeset for help on using the changeset viewer.