Changeset 5e491b3b


Ignore:
Timestamp:
Aug 28, 2005, 7:58:31 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:
3c86eb1
Parents:
4cc9fe5
Message:

massive changes from cam

Location:
python
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • python/aubio/aubioclass.py

    r4cc9fe5 r5e491b3b  
    106106        return self.pp.do(self.myonset),self.myonset.get(0,0)
    107107
    108 def check_onset_mode(option, opt, value, parser):
    109         nvalue = parser.rargs[0]
    110         if   nvalue == 'complexdomain' or nvalue == 'complex' :
    111                  setattr(parser.values, option.dest, aubio_onset_complex)
    112         elif nvalue == 'hfc'           :
    113                  setattr(parser.values, option.dest, aubio_onset_hfc)
    114         elif nvalue == 'phase'         :
    115                  setattr(parser.values, option.dest, aubio_onset_phase)
    116         elif nvalue == 'specdiff'      :
    117                  setattr(parser.values, option.dest, aubio_onset_specdiff)
    118         elif nvalue == 'energy'        :
    119                  setattr(parser.values, option.dest, aubio_onset_energy)
    120         elif nvalue == 'kl'            :
    121                  setattr(parser.values, option.dest, aubio_onset_kl)
    122         elif nvalue == 'mkl'           :
    123                  setattr(parser.values, option.dest, aubio_onset_mkl)
    124         elif nvalue == 'dual'          :
    125                  setattr(parser.values, option.dest, 'dual')
    126         else:
    127                  print "unknown onset detection function selected"
    128                  sys.exit(1)
    129 
    130 def check_pitch_mode(option, opt, value, parser):
    131         nvalue = parser.rargs[0]
    132         if   nvalue == 'mcomb'  :
    133                  setattr(parser.values, option.dest, aubio_pitch_mcomb)
    134         elif nvalue == 'yin'    :
    135                  setattr(parser.values, option.dest, aubio_pitch_yin)
    136         elif nvalue == 'fcomb'  :
    137                  setattr(parser.values, option.dest, aubio_pitch_fcomb)
    138         elif nvalue == 'schmitt':
    139                  setattr(parser.values, option.dest, aubio_pitch_schmitt)
    140         else:
    141                  print "error: unknown pitch detection function selected"
    142                  sys.exit(1)
    143 
    144 def check_pitchm_mode(option, opt, value, parser):
    145         nvalue = parser.rargs[0]
    146         if   nvalue == 'freq'  :
    147                  setattr(parser.values, option.dest, aubio_pitchm_freq)
    148         elif nvalue == 'midi'  :
    149                  setattr(parser.values, option.dest, aubio_pitchm_midi)
    150         elif nvalue == 'cent'  :
    151                  setattr(parser.values, option.dest, aubio_pitchm_cent)
    152         elif nvalue == 'bin'   :
    153                  setattr(parser.values, option.dest, aubio_pitchm_bin)
    154         else:
    155                  print "error: unknown pitch detection output selected"
    156                  sys.exit(1)
    157 
    158 
    159 def getonsets(filein,threshold=0.2,silence=-70.,bufsize=1024,hopsize=512,
    160                 mode='dual',localmin=False,storefunc=False,derivate=False):
    161         frameread = 0
    162         filei     = sndfile(filein)
    163         channels  = filei.channels()
    164         myvec     = fvec(hopsize,channels)
    165         readsize  = filei.read(hopsize,myvec)
    166         opick     = onsetpick(bufsize,hopsize,channels,myvec,threshold,
    167                          mode=mode,derivate=derivate)
    168         mylist    = list()
    169         if localmin:
    170                 ovalist   = [0., 0., 0., 0., 0.]
    171         if storefunc:
    172                 ofunclist = []
    173         while(readsize):
    174                 readsize = filei.read(hopsize,myvec)
    175                 isonset,val = opick.do(myvec)
    176                 if (aubio_silence_detection(myvec(),silence)):
    177                         isonset=0
    178                 if localmin:
    179                         if val > 0: ovalist.append(val)
    180                         else: ovalist.append(0)
    181                         ovalist.pop(0)
    182                 if storefunc:
    183                         ofunclist.append(val)
    184                 if (isonset == 1):
    185                         if localmin:
    186                                 i=len(ovalist)-1
    187                                 # find local minima before peak
    188                                 while ovalist[i-1] < ovalist[i] and i > 0:
    189                                         i -= 1
    190                                 now = (frameread+1-i)
    191                         else:
    192                                 now = frameread
    193                         if now > 0 :
    194                                 mylist.append(now)
    195                         else:
    196                                 now = 0
    197                                 mylist.append(now)
    198                 frameread += 1
    199         if storefunc: return mylist, ofunclist
    200         else: return mylist
    201 
    202 def cutfile(filein,slicetimes,zerothres=0.008,bufsize=1024,hopsize=512):
    203     frameread = 0
    204     readsize  = hopsize
    205     filei     = sndfile(filein)
    206     framestep = hopsize/(filei.samplerate()+0.)
    207     channels  = filei.channels()
    208     newname   = "%s%s%09.5f%s%s" % (filein.split(".")[0].split("/")[-1],".",
    209                 frameread*framestep,".",filein.split(".")[-1])
    210     fileo     = sndfile(newname,model=filei)
    211     myvec     = fvec(hopsize,channels)
    212     mycopy    = fvec(hopsize,channels)
    213     while(readsize==hopsize):
    214         readsize = filei.read(hopsize,myvec)
    215         # write to current file
    216         if len(slicetimes) and frameread >= slicetimes[0]:
    217             slicetimes.pop(0)
    218             # write up to 1st zero crossing
    219             zerocross = 0
    220             while ( abs( myvec.get(zerocross,0) ) > zerothres ):
    221                 zerocross += 1
    222             writesize = fileo.write(zerocross,myvec)
    223             fromcross = 0
    224             while (zerocross < readsize):
    225                 for i in range(channels):
    226                     mycopy.set(myvec.get(zerocross,i),fromcross,i)
    227                     fromcross += 1
    228                     zerocross += 1
    229             del fileo
    230             fileo = sndfile("%s%s%09.5f%s%s" %
    231                 (filein.split(".")[0].split("/")[-1],".",
    232                 frameread*framestep,".",filein.split(".")[-1]),model=filei)
    233             writesize = fileo.write(fromcross,mycopy)
    234         else:
    235             writesize = fileo.write(readsize,myvec)
    236         frameread += 1
    237     del fileo
    238 
    239 
    240 def getsilences(filein,hopsize=512,silence=-70):
    241     frameread = 0
    242     filei     = sndfile(filein)
    243     srate     = filei.samplerate()
    244     channels  = filei.channels()
    245     myvec     = fvec(hopsize,channels)
    246     readsize  = filei.read(hopsize,myvec)
    247     mylist    = []
    248     wassilence = 0
    249     while(readsize==hopsize):
    250         readsize = filei.read(hopsize,myvec)
    251         if (aubio_silence_detection(myvec(),silence)==1):
    252             if wassilence == 0:
    253                 mylist.append(frameread)
    254                 wassilence == 1
    255         else: wassilence = 0
    256         frameread += 1
    257     return mylist
    258 
    259 def getpitch(filein,mode=aubio_pitch_mcomb,bufsize=1024,hopsize=512,omode=aubio_pitchm_freq,
    260         samplerate=44100.,silence=-70):
    261     frameread = 0
    262     filei     = sndfile(filein)
    263     srate     = filei.samplerate()
    264     channels  = filei.channels()
    265     myvec     = fvec(hopsize,channels)
    266     readsize  = filei.read(hopsize,myvec)
    267     pitchdet  = pitchdetection(mode=mode,bufsize=bufsize,hopsize=hopsize,
    268                          channels=channels,samplerate=srate,omode=omode)
    269     mylist    = []
    270     while(readsize==hopsize):
    271         readsize = filei.read(hopsize,myvec)
    272         freq = pitchdet(myvec)
    273         #print "%.3f     %.2f" % (now,freq)
    274         if (aubio_silence_detection(myvec(),silence)!=1):
    275                 mylist.append(freq)
    276         else:
    277                 mylist.append(-1.)
    278         frameread += 1
    279     return mylist
    280 
    281108class pitchdetection:
    282109    def __init__(self,mode=aubio_pitch_mcomb,bufsize=2048,hopsize=1024,
  • python/aubio/gnuplot.py

    r4cc9fe5 r5e491b3b  
    151151        from aubio.onsetcompare import onset_roc
    152152
    153         if len(onsets) == 0: onsets = [0.];
    154 
    155         # onset detection function
    156         downtime = (hopsize/samplerate)*numarray.arange(len(ofunc))
    157         d = Gnuplot.Data(downtime,ofunc,with='lines')
    158 
    159         # detected onsets
    160         x1 = (hopsize/samplerate)*numarray.array(onsets)
    161         y1 = max(ofunc)*numarray.ones(len(onsets))
    162         e = Gnuplot.Data(x1,-y1,with='impulses')
    163         e2= Gnuplot.Data(x1,y1,with='impulses')
     153        d,d2 = [],[]
     154        maxofunc = 0
     155        for i in range(len(onsets)):
     156                if len(onsets[i]) == 0: onsets[i] = [0.];
     157
     158                # onset detection function
     159                downtime = (hopsize/samplerate)*numarray.arange(len(ofunc[i]))
     160                d.append(Gnuplot.Data(downtime,ofunc[i],with='lines'))
     161                maxofunc = max(max(ofunc[i]), maxofunc)
     162
     163        for i in range(len(onsets)):
     164                # detected onsets
     165                x1 = (hopsize/samplerate)*numarray.array(onsets[i])
     166                y1 = maxofunc*numarray.ones(len(onsets[i]))
     167                d.append(Gnuplot.Data(x1,y1,with='impulses'))
     168                d2.append(Gnuplot.Data(x1,-y1,with='impulses'))
    164169
    165170        # check if datafile exists truth
     
    170175        else:
    171176                t_onsets = aubio.txtfile.read_datafile(datafile)
    172                 y2 = max(ofunc)*numarray.ones(len(t_onsets))
     177                y2 = maxofunc*numarray.ones(len(t_onsets))
    173178                x2 = numarray.array(t_onsets).resize(len(t_onsets))
    174                 t = Gnuplot.Data(x2,y2,with='impulses')
     179                d2.append(Gnuplot.Data(x2,y2,with='impulses'))
    175180               
    176181                tol = 0.050
     
    189194        # audio data
    190195        time,data = audio_to_array(filename)
    191         f = make_audio_plot(time,data)
     196        d2.append(make_audio_plot(time,data))
    192197
    193198        # prepare the plot
     
    212217        g('set yrange [-1:1]')
    213218        g.ylabel('amplitude')
    214         g.plot(f,e,t)
     219        g.plot(*d2)
    215220       
    216221        g('unset title')
     
    219224        g('set size 1,0.7')
    220225        g('set origin 0,0')
    221         g('set xrange [0:%f]' % (hopsize/samplerate*len(ofunc)))
    222         g('set yrange [0:%f]' % (max(ofunc)*1.01))
     226        g('set xrange [0:%f]' % (hopsize/samplerate*len(ofunc[0])))
     227        g('set yrange [0:%f]' % (maxofunc*1.01))
    223228        g.xlabel('time')
    224229        g.ylabel('onset detection value')
    225         g.plot(d,e2)
     230        g.plot(*d)
    226231
    227232        g('unset multiplot')
     
    233238        import numarray
    234239
    235         # onset detection function
    236         downtime = (hopsize/samplerate)*numarray.arange(len(pitch))
    237         d = Gnuplot.Data(downtime,pitch,with='lines')
     240        d = []
     241        maxpitch = 100
     242        for i in range(len(pitch)):
     243                downtime = (hopsize/samplerate)*numarray.arange(len(pitch[i]))
     244                d.append(Gnuplot.Data(downtime,pitch[i],with='lines'))
     245                maxpitch = max(maxpitch,max(pitch[i][:])*1.1)
    238246
    239247        # check if datafile exists truth
     
    291299        g('set size 1,0.7')
    292300        g('set origin 0,0')
    293         g('set xrange [0:%f]' % (hopsize/samplerate*len(pitch)))
    294         g('set yrange [0:%f]' % (max(pitch)*1.01))
     301        g('set xrange [0:%f]' % max(time))
     302        g('set yrange [40:%f]' % maxpitch)
    295303        g.xlabel('time')
    296304        g.ylabel('frequency (Hz)')
    297         g.plot(d,t)
     305        g.plot(*d)
    298306
    299307        g('unset multiplot')
  • python/aubiocut

    r4cc9fe5 r5e491b3b  
    66
    77import sys
    8 from aubio.aubioclass import *
     8from aubio.tasks import *
    99
    1010usage = "usage: %s [options] -i soundfile" % sys.argv[0]
     
    8989silence    = float(options.silence)
    9090mintol     = float(options.mintol)*step
     91mode       = options.mode
    9192# default take back system delay
    9293if options.delay: delay = float(options.delay)
     
    9899elif options.silencecut:
    99100        onsets = getsilences(filename,hopsize=hopsize,silence=silence)
    100 elif options.plot:
     101elif options.plot: storefunc=True
     102else:              storefunc=False
     103
     104lonsets, lofunc = [], []
     105for i in range(len(mode)):
    101106        onsets, ofunc = getonsets(filename,threshold,silence,
    102                 mode=options.mode,localmin=options.localmin,
     107                mode=mode[i],localmin=options.localmin,
    103108                derivate=options.derivate,
    104109                bufsize=bufsize,hopsize=hopsize,storefunc=True)
    105 else:
    106         onsets = getonsets(filename,threshold,silence,
    107                 mode=options.mode,localmin=options.localmin,
    108                 derivate=options.derivate,
    109                 bufsize=bufsize,hopsize=hopsize)
    110110
    111 # take back system delay
    112 if delay != 0:
    113         for i in range(len(onsets)):
    114                 onsets[i] -= delay*step
     111        # take back system delay
     112        if delay != 0:
     113                for i in range(len(onsets)):
     114                        onsets[i] -= delay*step
    115115
    116 # prune doubled
    117 if mintol > 0:
    118         last = -2*mintol
    119         newonsets = []
    120         for new in onsets:
    121                 if (new - last > mintol):
    122                         newonsets.append(new)
    123                 last = new
    124         onsets = newonsets
     116        # prune doubled
     117        if mintol > 0:
     118                last = -2*mintol
     119                newonsets = []
     120                for new in onsets:
     121                        if (new - last > mintol):
     122                                newonsets.append(new)
     123                        last = new
     124                onsets = newonsets
     125
     126        lonsets.append(onsets)
     127        lofunc.append(ofunc)
    125128
    126129# print times in second
    127130if options.verbose:
    128         for i in onsets: print "%f" % (i/step)
     131        maxonset = 0
     132        for j in range(len(mode)):
     133                for i in range(len(lonsets[j])):
     134                        print lonsets[j][i]/step
    129135
    130136if options.plot:
    131137        from aubio.gnuplot import plot_onsets
    132         plot_onsets(filename, onsets, ofunc,
     138        plot_onsets(filename, lonsets, lofunc,
    133139                samplerate=samplerate, hopsize=hopsize, outplot=options.outplot)
    134140
  • python/aubiopitch

    r4cc9fe5 r5e491b3b  
    55"""
    66
    7 
    87import sys
    9 from aubio.aubioclass import *
     8from aubio.tasks import *
    109
    1110usage = "usage: %s [options] -i soundfile" % sys.argv[0]
     
    7473                if options.mode == aubio_pitch_mcomb:   options.bufsize = 4096
    7574                if options.mode == aubio_pitch_fcomb:   options.bufsize = 4096
     75                else: options.bufsize = 2048
    7676        if not options.hopsize:
    7777                options.hopsize = float(options.bufsize) / 2
     
    9292threshold  = float(options.threshold)
    9393silence    = float(options.silence)
     94mode       = options.mode
    9495#mintol     = float(options.mintol)*step
    9596# default take back system delay
     
    100101        exit("not implemented yet")
    101102else:
    102         pitch = getpitch(filename, #threshold,
    103                 mode=options.mode,
    104                 omode=options.omode,
    105                 bufsize=bufsize,hopsize=hopsize,
    106                 silence=silence)
     103        pitch = []
     104        for i in range(len(mode)):
     105                pitch.append(getpitch(filename, #threshold,
     106                        mode=mode[i],
     107                        omode=options.omode,
     108                        bufsize=bufsize,hopsize=hopsize,
     109                        silence=silence))
    107110
    108111## take back system delay
     
    123126# print times in second
    124127if options.verbose:
    125         for i in range(len(pitch)):
    126                 print "%f\t%f" % (i/step,pitch[i])
     128        for j in range(len(pitch[0])):
     129                print "%f\t" % (j/step),
     130                for i in range(len(pitch)):
     131                        print "%f\t" % pitch[i][j],
     132                print
    127133
    128134if options.plot:
     
    130136        plot_pitch(filename, pitch,
    131137                samplerate=samplerate, hopsize=hopsize, outplot=options.outplot)
    132 
Note: See TracChangeset for help on using the changeset viewer.