- Timestamp:
- Aug 28, 2005, 7:58:31 PM (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:
- 3c86eb1
- Parents:
- 4cc9fe5
- Location:
- python
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
python/aubio/aubioclass.py
r4cc9fe5 r5e491b3b 106 106 return self.pp.do(self.myonset),self.myonset.get(0,0) 107 107 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 = 0162 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=0178 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)-1187 # find local minima before peak188 while ovalist[i-1] < ovalist[i] and i > 0:189 i -= 1190 now = (frameread+1-i)191 else:192 now = frameread193 if now > 0 :194 mylist.append(now)195 else:196 now = 0197 mylist.append(now)198 frameread += 1199 if storefunc: return mylist, ofunclist200 else: return mylist201 202 def cutfile(filein,slicetimes,zerothres=0.008,bufsize=1024,hopsize=512):203 frameread = 0204 readsize = hopsize205 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 file216 if len(slicetimes) and frameread >= slicetimes[0]:217 slicetimes.pop(0)218 # write up to 1st zero crossing219 zerocross = 0220 while ( abs( myvec.get(zerocross,0) ) > zerothres ):221 zerocross += 1222 writesize = fileo.write(zerocross,myvec)223 fromcross = 0224 while (zerocross < readsize):225 for i in range(channels):226 mycopy.set(myvec.get(zerocross,i),fromcross,i)227 fromcross += 1228 zerocross += 1229 del fileo230 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 += 1237 del fileo238 239 240 def getsilences(filein,hopsize=512,silence=-70):241 frameread = 0242 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 = 0249 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 == 1255 else: wassilence = 0256 frameread += 1257 return mylist258 259 def getpitch(filein,mode=aubio_pitch_mcomb,bufsize=1024,hopsize=512,omode=aubio_pitchm_freq,260 samplerate=44100.,silence=-70):261 frameread = 0262 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 += 1279 return mylist280 281 108 class pitchdetection: 282 109 def __init__(self,mode=aubio_pitch_mcomb,bufsize=2048,hopsize=1024, -
python/aubio/gnuplot.py
r4cc9fe5 r5e491b3b 151 151 from aubio.onsetcompare import onset_roc 152 152 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')) 164 169 165 170 # check if datafile exists truth … … 170 175 else: 171 176 t_onsets = aubio.txtfile.read_datafile(datafile) 172 y2 = max (ofunc)*numarray.ones(len(t_onsets))177 y2 = maxofunc*numarray.ones(len(t_onsets)) 173 178 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')) 175 180 176 181 tol = 0.050 … … 189 194 # audio data 190 195 time,data = audio_to_array(filename) 191 f = make_audio_plot(time,data)196 d2.append(make_audio_plot(time,data)) 192 197 193 198 # prepare the plot … … 212 217 g('set yrange [-1:1]') 213 218 g.ylabel('amplitude') 214 g.plot( f,e,t)219 g.plot(*d2) 215 220 216 221 g('unset title') … … 219 224 g('set size 1,0.7') 220 225 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)) 223 228 g.xlabel('time') 224 229 g.ylabel('onset detection value') 225 g.plot( d,e2)230 g.plot(*d) 226 231 227 232 g('unset multiplot') … … 233 238 import numarray 234 239 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) 238 246 239 247 # check if datafile exists truth … … 291 299 g('set size 1,0.7') 292 300 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) 295 303 g.xlabel('time') 296 304 g.ylabel('frequency (Hz)') 297 g.plot( d,t)305 g.plot(*d) 298 306 299 307 g('unset multiplot') -
python/aubiocut
r4cc9fe5 r5e491b3b 6 6 7 7 import sys 8 from aubio. aubioclass import *8 from aubio.tasks import * 9 9 10 10 usage = "usage: %s [options] -i soundfile" % sys.argv[0] … … 89 89 silence = float(options.silence) 90 90 mintol = float(options.mintol)*step 91 mode = options.mode 91 92 # default take back system delay 92 93 if options.delay: delay = float(options.delay) … … 98 99 elif options.silencecut: 99 100 onsets = getsilences(filename,hopsize=hopsize,silence=silence) 100 elif options.plot: 101 elif options.plot: storefunc=True 102 else: storefunc=False 103 104 lonsets, lofunc = [], [] 105 for i in range(len(mode)): 101 106 onsets, ofunc = getonsets(filename,threshold,silence, 102 mode= options.mode,localmin=options.localmin,107 mode=mode[i],localmin=options.localmin, 103 108 derivate=options.derivate, 104 109 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)110 110 111 # take back system delay112 if delay != 0:113 for i in range(len(onsets)):114 onsets[i] -= delay*step111 # take back system delay 112 if delay != 0: 113 for i in range(len(onsets)): 114 onsets[i] -= delay*step 115 115 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) 125 128 126 129 # print times in second 127 130 if 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 129 135 130 136 if options.plot: 131 137 from aubio.gnuplot import plot_onsets 132 plot_onsets(filename, onsets,ofunc,138 plot_onsets(filename, lonsets, lofunc, 133 139 samplerate=samplerate, hopsize=hopsize, outplot=options.outplot) 134 140 -
python/aubiopitch
r4cc9fe5 r5e491b3b 5 5 """ 6 6 7 8 7 import sys 9 from aubio. aubioclass import *8 from aubio.tasks import * 10 9 11 10 usage = "usage: %s [options] -i soundfile" % sys.argv[0] … … 74 73 if options.mode == aubio_pitch_mcomb: options.bufsize = 4096 75 74 if options.mode == aubio_pitch_fcomb: options.bufsize = 4096 75 else: options.bufsize = 2048 76 76 if not options.hopsize: 77 77 options.hopsize = float(options.bufsize) / 2 … … 92 92 threshold = float(options.threshold) 93 93 silence = float(options.silence) 94 mode = options.mode 94 95 #mintol = float(options.mintol)*step 95 96 # default take back system delay … … 100 101 exit("not implemented yet") 101 102 else: 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)) 107 110 108 111 ## take back system delay … … 123 126 # print times in second 124 127 if 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 127 133 128 134 if options.plot: … … 130 136 plot_pitch(filename, pitch, 131 137 samplerate=samplerate, hopsize=hopsize, outplot=options.outplot) 132
Note: See TracChangeset
for help on using the changeset viewer.