Changeset 80c0417 for python/aubio
- Timestamp:
- May 30, 2005, 6:44:52 AM (19 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/aubio
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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')
Note: See TracChangeset
for help on using the changeset viewer.