- Timestamp:
- Mar 1, 2006, 4:17:34 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:
- 0fe9aab
- Parents:
- 0484dc1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/aubio/tasks.py
r0484dc1 r300adc3 212 212 self.onsetmode = 'dual' 213 213 self.pitchmode = 'yin' 214 self.pitchsmooth = 20 215 self.pitchmin=100. 216 self.pitchmax=1500. 214 217 self.dcthreshold = -1. 215 218 self.omode = aubio_pitchm_freq … … 293 296 def __init__(self,input,params=None): 294 297 task.__init__(self,input,params=params) 298 self.shortlist = [0. for i in range(self.params.pitchsmooth)] 295 299 self.pitchdet = pitchdetection(mode=get_pitch_mode(self.params.pitchmode), 296 300 bufsize=self.params.bufsize, … … 301 305 302 306 def __call__(self): 303 #print "%.3f %.2f" % (now,freq)307 from median import short_find 304 308 task.__call__(self) 305 freq = self.pitchdet(self.myvec) 306 if (aubio_silence_detection(self.myvec(),self.params.silence)!=1): 309 if (aubio_silence_detection(self.myvec(),self.params.silence)==1): 310 freq = -1. 311 else: 312 freq = self.pitchdet(self.myvec) 313 minpitch = self.params.pitchmin 314 maxpitch = self.params.pitchmax 315 if maxpitch and freq > maxpitch : 316 freq = -1. 317 elif minpitch and freq < minpitch : 318 freq = -1. 319 if self.params.pitchsmooth: 320 self.shortlist.append(freq) 321 self.shortlist.pop(0) 322 smoothfreq = short_find(self.shortlist, 323 len(self.shortlist)/2) 324 return smoothfreq 325 else: 307 326 return freq 308 else: 309 return -1. 327 328 def compute_all(self): 329 """ Compute data """ 330 mylist = [] 331 while(self.readsize==self.params.hopsize): 332 freq = self() 333 mylist.append(freq) 334 if self.params.verbose: 335 self.fprint("%s\t%s" % (self.frameread*self.params.step,freq)) 336 return mylist 310 337 311 338 def gettruth(self): … … 322 349 return sum(l)/max(float(len(l)),1) 323 350 324 from median import short_find351 from median import percental 325 352 self.truth = self.gettruth() 326 353 res = [] 327 354 for i in results: 328 if i == -1: pass 329 else: 330 res.append(self.truth-i) 355 if i <= 0: pass 356 else: res.append(self.truth-i) 331 357 if not res: 332 358 avg = self.truth; med = self.truth 333 359 else: 334 360 avg = mmean(res) 335 med = short_find(res,len(res)/2)361 med = percental(res,len(res)/2) 336 362 return self.truth, self.truth-med, self.truth-avg 337 363 338 def plot(self,pitch,outplot=None): 339 from aubio.gnuplot import plot_pitch 340 plot_pitch(self.input, 341 pitch, 342 samplerate=float(self.srate), 343 hopsize=self.params.hopsize, 344 outplot=outplot) 364 def plot(self,pitch,wplot,oplots,outplot=None): 365 from aubio.txtfile import read_datafile 366 import os.path 367 import numarray 368 import Gnuplot 369 370 downtime = self.params.step*numarray.arange(len(pitch)) 371 oplots.append(Gnuplot.Data(downtime,pitch,with='lines', 372 title=self.params.pitchmode)) 373 374 # check if ground truth exists 375 datafile = self.input.replace('.wav','.txt') 376 if datafile == self.input: datafile = "" 377 if not os.path.isfile(datafile): 378 self.title = "" #"truth file not found" 379 t = Gnuplot.Data(0,0,with='impulses') 380 else: 381 self.title = "" #"truth file plotting not implemented yet" 382 values = read_datafile(datafile) 383 if (len(datafile[0])) > 1: 384 time, pitch = [], [] 385 for i in range(len(values)): 386 time.append(values[i][0]) 387 pitch.append(values[i][1]) 388 oplots.append(Gnuplot.Data(time,pitch,with='lines', 389 title='ground truth')) 390 391 def plotplot(self,wplot,oplots,outplot=None): 392 from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot 393 import re 394 # audio data 395 time,data = audio_to_array(self.input) 396 f = make_audio_plot(time,data) 397 398 g = gnuplot_init(outplot) 399 g('set title \'%s %s\'' % (re.sub('.*/','',self.input),self.title)) 400 g('set multiplot') 401 # hack to align left axis 402 g('set lmargin 15') 403 # plot waveform and onsets 404 g('set size 1,0.3') 405 g('set origin 0,0.7') 406 g('set xrange [0:%f]' % max(time)) 407 g('set yrange [-1:1]') 408 g.ylabel('amplitude') 409 g.plot(f) 410 g('unset title') 411 # plot onset detection function 412 413 414 g('set size 1,0.7') 415 g('set origin 0,0') 416 g('set xrange [0:%f]' % max(time)) 417 g('set yrange [40:%f]' % self.params.pitchmax) 418 g('set key right top') 419 g('set noclip one') 420 g('set format x ""') 421 #g.xlabel('time (s)') 422 g.ylabel('frequency (Hz)') 423 multiplot = 1 424 if multiplot: 425 for i in range(len(oplots)): 426 # plot onset detection functions 427 g('set size 1,%f' % (0.7/(len(oplots)))) 428 g('set origin 0,%f' % (float(i)*0.7/(len(oplots)))) 429 g('set xrange [0:%f]' % max(time)) 430 g.plot(oplots[i]) 431 else: 432 g.plot(*oplots) 433 g('unset multiplot') 345 434 346 435 … … 440 529 x1,y1,y1p = [],[],[] 441 530 oplot = [] 531 if self.params.onsetmode in ('mkl','kl'): ofunc[0:10] = [0] * 10 442 532 443 533 self.lenofunc = len(ofunc) … … 482 572 483 573 484 def plotplot(self,wplot,oplot ,outplot=None):574 def plotplot(self,wplot,oplots,outplot=None): 485 575 from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot 486 576 import re … … 500 590 g('set noytics') 501 591 502 for i in range(len(oplot )):592 for i in range(len(oplots)): 503 593 # plot onset detection functions 504 g('set size 1,%f' % (0.7/(len(oplot ))))505 g('set origin 0,%f' % (float(i)*0.7/(len(oplot ))))594 g('set size 1,%f' % (0.7/(len(oplots)))) 595 g('set origin 0,%f' % (float(i)*0.7/(len(oplots)))) 506 596 g('set xrange [0:%f]' % (self.lenofunc*self.params.step)) 507 g.plot(*oplot[i]) 508 509 g('set tmargin 3') 510 g('set format x "%10.1f"') 597 g.plot(*oplots[i]) 598 599 g('set tmargin 3.0') 600 g('set xlabel "time (s)" 1,0') 601 g('set format x "%1.1f"') 511 602 512 603 g('set title \'%s %s\'' % (re.sub('.*/','',self.input),self.title))
Note: See TracChangeset
for help on using the changeset viewer.