Changeset 80c0417
- Timestamp:
- May 30, 2005, 6:44:52 AM (20 years ago)
- 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:
- d09cad2
- Parents:
- 588a09f
- Location:
- python
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
python/README
r588a09f r80c0417 2 2 routines. The python interface for libaubio is generated using Swig. 3 3 4 To have it working before installation, set LD_LIBRARY_PATH as: 5 LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib:../src/.libs 4 To have it working before installation, you will need to set LD_LIBRARY_PATH 5 # export LD_LIBRARY_PATH=../src/.libs:../ext/.libs 6 for instance, to run the python script from within aubio/python/. -
python/aubio/aubioclass.py
r588a09f r80c0417 74 74 class onsetpick: 75 75 """ superclass for aubio_pvoc + aubio_onsetdetection + aubio_peakpicker """ 76 def __init__(self,bufsize,hopsize,channels,myvec,threshold,mode='dual' ):76 def __init__(self,bufsize,hopsize,channels,myvec,threshold,mode='dual',derivate=False): 77 77 self.myfft = cvec(bufsize,channels) 78 78 self.pv = pvoc(bufsize,hopsize,channels) … … 87 87 self.mode = mode 88 88 self.pp = peakpick(float(threshold)) 89 self.derivate = derivate 90 self.oldval = 0. 89 91 90 92 def do(self,myvec): … … 94 96 self.myod2.do(self.myfft,self.myonset2) 95 97 self.myonset.set(self.myonset.get(0,0)*self.myonset2.get(0,0),0,0) 98 if self.derivate: 99 val = self.myonset.get(0,0) 100 dval = val - self.oldval 101 self.oldval = val 102 if dval > 0: self.myonset.set(dval,0,0) 103 else: self.myonset.set(0.,0,0) 96 104 return self.pp.do(self.myonset),self.myonset.get(0,0) 97 105 98 def getonsets(filein,threshold=0.2,silence=-70.,bufsize=1024,hopsize=512,mode='dual',localmin=False,storefunc=False): 106 def getonsets(filein,threshold=0.2,silence=-70.,bufsize=1024,hopsize=512, 107 mode='dual',localmin=False,storefunc=False,derivate=False): 99 108 frameread = 0 100 109 filei = sndfile(filein) … … 102 111 myvec = fvec(hopsize,channels) 103 112 readsize = filei.read(hopsize,myvec) 104 opick = onsetpick(bufsize,hopsize,channels,myvec,threshold,mode=mode) 113 opick = onsetpick(bufsize,hopsize,channels,myvec,threshold, 114 mode=mode,derivate=derivate) 105 115 mylist = list() 106 116 if localmin: … … 114 124 isonset=0 115 125 if localmin: 116 ovalist.append(val) 126 if val > 0: ovalist.append(val) 127 else: ovalist.append(0) 117 128 ovalist.pop(0) 118 129 if storefunc: … … 136 147 else: return mylist 137 148 138 def cutfile(filein,slicetimes,zerothres=0.00 2,bufsize=1024,hopsize=512):149 def cutfile(filein,slicetimes,zerothres=0.008,bufsize=1024,hopsize=512): 139 150 frameread = 0 140 151 readsize = hopsize … … 154 165 zerocross = 0 155 166 while ( abs( myvec.get(zerocross,0) ) > zerothres ): 156 167 zerocross += 1 157 168 writesize = fileo.write(zerocross,myvec) 158 169 fromcross = 0 159 170 while (zerocross < readsize): 160 161 162 163 171 for i in range(channels): 172 mycopy.set(myvec.get(zerocross,i),fromcross,i) 173 fromcross += 1 174 zerocross += 1 164 175 del fileo 165 176 fileo = sndfile("%s%s%f%s%s" % 166 167 177 (filein.split(".")[0].split("/")[-1],".", 178 frameread*framestep,".",filein.split(".")[-1]),model=filei) 168 179 writesize = fileo.write(fromcross,mycopy) 169 180 else: -
python/aubio/gnuplot.py
r588a09f r80c0417 137 137 def make_audio_plot(time,data,maxpoints=10000): 138 138 """ create gnuplot plot from an audio file """ 139 import numarray140 139 length = len(time) 141 140 downsample = length/maxpoints 142 141 if downsample == 0: downsample = 1 143 x = numarray.array(time).resize(length)[0:-1:downsample]144 y = numarray.array(data).resize(length)[0:-1:downsample]142 x = array(time).resize(length)[0:-1:downsample] 143 y = array(data).resize(length)[0:-1:downsample] 145 144 return Gnuplot.Data(x,y,with='lines') 145 146 147 def plot_onsets(filename, onsets, ofunc, samplerate=44100., hopsize=512, outplot=None): 148 import aubio.txtfile 149 import os.path 150 import numarray 151 from aubio.onsetcompare import onset_roc 152 153 # onset detection function 154 downtime = (hopsize/samplerate)*numarray.arange(len(ofunc)) 155 d = Gnuplot.Data(downtime,ofunc,with='lines') 156 157 # detected onsets 158 x1 = (hopsize/samplerate)*numarray.array(onsets) 159 y1 = max(ofunc)*numarray.ones(len(onsets)) 160 e = Gnuplot.Data(x1,-y1,with='impulses') 161 e2= Gnuplot.Data(x1,y1,with='impulses') 162 163 # check if datafile exists truth 164 datafile = filename.replace('.wav','.txt') 165 if not os.path.isfile(datafile): 166 title = "truth file not found" 167 t = Gnuplot.Data(0,0,with='impulses') 168 else: 169 t_onsets = aubio.txtfile.read_datafile(datafile) 170 y2 = max(ofunc)*numarray.ones(len(t_onsets)) 171 x2 = numarray.array(t_onsets).resize(len(t_onsets)) 172 t = Gnuplot.Data(x2,y2,with='impulses') 173 174 tol = 0.050 175 176 orig, missed, merged, expc, bad, doubled = \ 177 onset_roc(x2,x1,tol) 178 title = "GD %2.3f%% FP %2.3f%%" % \ 179 ((100*float(orig-missed-merged)/(orig)), 180 (100*float(bad+doubled)/(orig))) 181 #print orig, missed, merged, expc, bad, doubled 182 #print "GD %2.8f\t" % (100*float(orig-missed-merged)/(orig)), 183 #print "FP %2.8f\t" % (100*float(bad+doubled)/(orig)) , 184 #print "GD-merged %2.8f\t" % (100*float(orig-missed)/(orig)) , 185 #print "FP-pruned %2.8f\t" % (100*float(bad)/(orig)) 186 187 # audio data 188 time,data = audio_to_array(filename) 189 f = make_audio_plot(time,data) 190 191 # prepare the plot 192 g = Gnuplot.Gnuplot(debug=1, persist=1) 193 if outplot: 194 extension = outplot.split('.')[-1] 195 if extension == 'ps': extension = 'postscript' 196 g('set terminal %s' % extension) 197 g('set output \'%s\'' % outplot) 198 199 g('set title \'%s %s\'' % (filename,title)) 200 201 g('set multiplot') 202 203 # hack to align left axis 204 g('set lmargin 15') 205 206 # plot waveform and onsets 207 g('set size 1,0.3') 208 g('set origin 0,0.7') 209 g('set xrange [0:%f]' % max(time)) 210 g('set yrange [-1:1]') 211 g.ylabel('amplitude') 212 g.plot(f,e,t) 213 214 g('unset title') 215 216 # plot onset detection function 217 g('set size 1,0.7') 218 g('set origin 0,0') 219 g('set xrange [0:%f]' % (hopsize/samplerate*len(ofunc))) 220 g('set yrange [0:%f]' % (max(ofunc)*1.01)) 221 g.xlabel('time') 222 g.ylabel('onset detection value') 223 g.plot(d,e2) 224 225 g('unset multiplot') -
python/aubiocut
r588a09f r80c0417 34 34 parser.add_option("-m","--mode", action="callback", 35 35 callback=check_mode, dest="mode", default='dual', 36 help="onset detection mode [default=dual] \36 help="onset detection mode [default=dual] \ 37 37 complexdomain|hfc|phase|specdiff|energy|dual") 38 38 parser.add_option("-B","--bufsize", … … 52 52 help="minimum inter onset interval [default=0.048]") 53 53 parser.add_option("-D","--delay", 54 action="store", dest="delay", default=0.022, 55 help="number of seconds to take back [default=0.022]") 54 action="store", dest="delay", 55 help="number of seconds to take back [default=system]\ 56 default system delay is 2*hopsize/samplerate") 56 57 parser.add_option("-L","--localmin", 57 58 action="store_true", dest="localmin", default=False, … … 61 62 help="cut input sound file at detected labels \ 62 63 best used with option -L") 64 parser.add_option("-d","--derivate", 65 action="store_true", dest="derivate", default=False, 66 help="derivate onset detection function") 63 67 # to be implemented 64 # plotting functions65 parser.add_option("-d","--derivative",66 action="store_true", dest="derivative", default=False,67 help="NOT IMPLEMENTED derivate onset detection function")68 parser.add_option("-p","--plot",69 action="store_true", dest="doplot", default=False,70 help="NOT IMPLEMENTED draw plot")71 parser.add_option("-O","--outplot",72 action="store", dest="output-plot", default=None,73 help="NOT IMPLEMENTED save plot to output.{ps,png}")74 68 parser.add_option("-z","--zerocross", 75 69 action="store_true", dest="zerocross", default=False, … … 78 72 action="store_true", dest="beat", default=False, 79 73 help="NOT IMPLEMENTED output beat locations") 74 # plotting functions 75 parser.add_option("-p","--plot", 76 action="store_true", dest="plot", default=False, 77 help="draw plot") 78 parser.add_option("-O","--outplot", 79 action="store", dest="outplot", default=None, 80 help="save plot to output.{ps,png}") 80 81 parser.add_option("-v","--verbose", 81 82 action="store_true", dest="verbose", default=False, … … 100 101 silence = float(options.silence) 101 102 mintol = float(options.mintol)*step 102 delay = float(options.delay) 103 # default take back system delay 104 if options.delay: delay = float(options.delay) 105 else: delay = 2./step 103 106 104 107 if options.beat: 105 108 #onsets = getbeats(filename,threshold,silence,mode=options.mode) 106 109 exit("not implemented yet") 110 elif options.plot: 111 onsets, ofunc = getonsets(filename,threshold,silence, 112 mode=options.mode,localmin=options.localmin, 113 derivate=options.derivate, 114 bufsize=bufsize,hopsize=hopsize,storefunc=True) 107 115 else: 108 116 onsets = getonsets(filename,threshold,silence, 109 117 mode=options.mode,localmin=options.localmin, 118 derivate=options.derivate, 110 119 bufsize=bufsize,hopsize=hopsize) 111 120 … … 129 138 for i in onsets: print "%f" % (i/step) 130 139 140 if options.plot: 141 from aubio.gnuplot import plot_onsets 142 plot_onsets(filename, onsets, ofunc, 143 samplerate=samplerate, hopsize=hopsize, outplot=options.outplot) 144 131 145 if options.cut: 132 146 cutfile(filename,onsets,bufsize=bufsize,hopsize=hopsize)
Note: See TracChangeset
for help on using the changeset viewer.