From: Paul Brossier Date: Wed, 1 Mar 2006 03:21:59 +0000 (+0000) Subject: remove old plot_pitch, plot_onset and getonsets, cutfile, getpitch X-Git-Tag: bzr2git~748 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1e3089c97d3e6f364e4bcea2f2c09c1963947e6a;p=aubio.git remove old plot_pitch, plot_onset and getonsets, cutfile, getpitch remove old plot_pitch, plot_onset and getonsets, cutfile, getpitch --- diff --git a/python/aubio/gnuplot.py b/python/aubio/gnuplot.py index e626ed52..10c52c16 100644 --- a/python/aubio/gnuplot.py +++ b/python/aubio/gnuplot.py @@ -149,151 +149,6 @@ def make_audio_plot(time,data,maxpoints=10000): y = numarray.array(data).resize(length)[0:-1:downsample] return Gnuplot.Data(x,y,with='lines') - -def plot_onsets(filename, onsets, ofunc, samplerate=44100., hopsize=512, outplot=None): - import Gnuplot, Gnuplot.funcutils - import aubio.txtfile - import os.path - import numarray - import re - from aubio.onsetcompare import onset_roc - - d,d2 = [],[] - maxofunc = 0 - for i in range(len(onsets)): - if len(onsets[i]) == 0: onsets[i] = [0.]; - - # onset detection function - downtime = (hopsize/samplerate)*numarray.arange(len(ofunc[i])) - d.append(Gnuplot.Data(downtime,ofunc[i],with='lines')) - maxofunc = max(max(ofunc[i]), maxofunc) - - for i in range(len(onsets)): - # detected onsets - x1 = (hopsize/samplerate)*numarray.array(onsets[i]) - y1 = maxofunc*numarray.ones(len(onsets[i])) - d.append(Gnuplot.Data(x1,y1,with='impulses')) - d2.append(Gnuplot.Data(x1,-y1,with='impulses')) - - # check if datafile exists truth - datafile = filename.replace('.wav','.txt') - if datafile == filename: datafile = "" - if not os.path.isfile(datafile): - title = "truth file not found" - t = Gnuplot.Data(0,0,with='impulses') - else: - t_onsets = aubio.txtfile.read_datafile(datafile) - y2 = maxofunc*numarray.ones(len(t_onsets)) - x2 = numarray.array(t_onsets).resize(len(t_onsets)) - d2.append(Gnuplot.Data(x2,y2,with='impulses')) - - tol = 0.050 - - orig, missed, merged, expc, bad, doubled = \ - onset_roc(x2,x1,tol) - title = "GD %2.3f%% FP %2.3f%%" % \ - ((100*float(orig-missed-merged)/(orig)), - (100*float(bad+doubled)/(orig))) - - # audio data - time,data = audio_to_array(filename) - d2.append(make_audio_plot(time,data)) - - # prepare the plot - g = gnuplot_init(outplot) - - g('set title \'%s %s\'' % (re.sub('.*/','',filename),title)) - - g('set multiplot') - - # hack to align left axis - g('set lmargin 15') - - # plot waveform and onsets - g('set size 1,0.3') - g('set origin 0,0.7') - g('set xrange [0:%f]' % max(time)) - g('set yrange [-1:1]') - g.ylabel('amplitude') - g.plot(*d2) - - g('unset title') - - # plot onset detection function - g('set size 1,0.7') - g('set origin 0,0') - g('set xrange [0:%f]' % (hopsize/samplerate*len(ofunc[0]))) - g('set yrange [0:%f]' % (maxofunc*1.01)) - g.xlabel('time') - g.ylabel('onset detection value') - g.plot(*d) - - g('unset multiplot') - - -def plot_pitch(filename, pitch, samplerate=44100., hopsize=512, outplot=None): - import aubio.txtfile - import os.path - import numarray - import Gnuplot - import re - - d = [] - maxpitch = 1000. - for i in range(len(pitch)): - #if len(pitch[i]) == 0: pitch[i] = [0.]; - - downtime = (hopsize/samplerate)*numarray.arange(len(pitch[i])) - d.append(Gnuplot.Data(downtime,pitch[i],with='lines', - title=('%d' % i))) - maxpitch = max(maxpitch,max(pitch[i][:])*1.1) - - # check if ground truth exists - datafile = filename.replace('.wav','.txt') - if datafile == filename: datafile = "" - if not os.path.isfile(datafile): - title = "truth file not found" - t = Gnuplot.Data(0,0,with='impulses') - else: - title = "truth file plotting not implemented yet" - values = aubio.txtfile.read_datafile(datafile) - if (len(datafile[0])) > 1: - time, pitch = [], [] - for i in range(len(values)): - time.append(values[i][0]) - pitch.append(values[i][1]) - d.append(Gnuplot.Data(time,pitch,with='lines', - title='ground truth')) - - # audio data - time,data = audio_to_array(filename) - f = make_audio_plot(time,data) - - g = gnuplot_init(outplot) - g('set title \'%s %s\'' % (re.sub('.*/','',filename),title)) - g('set multiplot') - # hack to align left axis - g('set lmargin 15') - # plot waveform and onsets - g('set size 1,0.3') - g('set origin 0,0.7') - g('set xrange [0:%f]' % max(time)) - g('set yrange [-1:1]') - g.ylabel('amplitude') - g.plot(f) - g('unset title') - # plot onset detection function - g('set size 1,0.7') - g('set origin 0,0') - g('set xrange [0:%f]' % max(time)) - g('set yrange [40:%f]' % maxpitch) - g('set key right top') - g('set noclip one') - g.xlabel('time') - g.ylabel('frequency (Hz)') - g.plot(*d) - g('unset multiplot') - def gnuplot_init(outplot,debug=0,persist=1): # prepare the plot import Gnuplot diff --git a/python/aubio/tasks.py b/python/aubio/tasks.py index cb3859ec..6dd9a7c3 100644 --- a/python/aubio/tasks.py +++ b/python/aubio/tasks.py @@ -71,129 +71,6 @@ def check_pitchm_mode(option, opt, value, parser): print "error: unknown pitch detection output selected" sys.exit(1) - -#def getonsets(filein,threshold=0.2,silence=-70.,bufsize=1024,hopsize=512, -# mode='dual',localmin=False,storefunc=False,derivate=False): -# frameread = 0 -# filei = sndfile(filein) -# channels = filei.channels() -# myvec = fvec(hopsize,channels) -# readsize = filei.read(hopsize,myvec) -# opick = onsetpick(bufsize,hopsize,channels,myvec,threshold, -# mode=mode,derivate=derivate) -# mylist = list() -# if localmin: -# ovalist = [0., 0., 0., 0., 0.] -# ofunclist = [] -# while(readsize): -# readsize = filei.read(hopsize,myvec) -# isonset,val = opick.do(myvec) -# if (aubio_silence_detection(myvec(),silence)): -# isonset=0 -# if localmin: -# if val > 0: ovalist.append(val) -# else: ovalist.append(0) -# ovalist.pop(0) -# if storefunc: -# ofunclist.append(val) -# if (isonset == 1): -# if localmin: -# i=len(ovalist)-1 -# # find local minima before peak -# while ovalist[i-1] < ovalist[i] and i > 0: -# i -= 1 -# now = (frameread+1-i) -# else: -# now = frameread -# if now > 0 : -# mylist.append(now) -# else: -# now = 0 -# mylist.append(now) -# frameread += 1 -# return mylist, ofunclist -# -#def cutfile(filein,slicetimes,zerothres=0.008,bufsize=1024,hopsize=512): -# frameread = 0 -# readsize = hopsize -# filei = sndfile(filein) -# framestep = hopsize/(filei.samplerate()+0.) -# channels = filei.channels() -# newname = "%s%s%09.5f%s%s" % (filein.split(".")[0].split("/")[-1],".", -# frameread*framestep,".",filein.split(".")[-1]) -# fileo = sndfile(newname,model=filei) -# myvec = fvec(hopsize,channels) -# mycopy = fvec(hopsize,channels) -# while(readsize==hopsize): -# readsize = filei.read(hopsize,myvec) -# # write to current file -# if len(slicetimes) and frameread >= slicetimes[0]: -# slicetimes.pop(0) -# # write up to 1st zero crossing -# zerocross = 0 -# while ( abs( myvec.get(zerocross,0) ) > zerothres ): -# zerocross += 1 -# writesize = fileo.write(zerocross,myvec) -# fromcross = 0 -# while (zerocross < readsize): -# for i in range(channels): -# mycopy.set(myvec.get(zerocross,i),fromcross,i) -# fromcross += 1 -# zerocross += 1 -# del fileo -# fileo = sndfile("%s%s%09.5f%s%s" % -# (filein.split(".")[0].split("/")[-1],".", -# frameread*framestep,".",filein.split(".")[-1]),model=filei) -# writesize = fileo.write(fromcross,mycopy) -# else: -# writesize = fileo.write(readsize,myvec) -# frameread += 1 -# del fileo -# -# -#def getsilences(filein,hopsize=512,silence=-70): -# frameread = 0 -# filei = sndfile(filein) -# srate = filei.samplerate() -# channels = filei.channels() -# myvec = fvec(hopsize,channels) -# readsize = filei.read(hopsize,myvec) -# mylist = [] -# wassilence = 0 -# while(readsize==hopsize): -# readsize = filei.read(hopsize,myvec) -# if (aubio_silence_detection(myvec(),silence)==1): -# if wassilence == 0: -# mylist.append(frameread) -# wassilence == 1 -# else: wassilence = 0 -# frameread += 1 -# return mylist -# -# -#def getpitch(filein,mode=aubio_pitch_mcomb,bufsize=1024,hopsize=512,omode=aubio_pitchm_freq, -# samplerate=44100.,silence=-70): -# frameread = 0 -# filei = sndfile(filein) -# srate = filei.samplerate() -# channels = filei.channels() -# myvec = fvec(hopsize,channels) -# readsize = filei.read(hopsize,myvec) -# pitchdet = pitchdetection(mode=mode,bufsize=bufsize,hopsize=hopsize, -# channels=channels,samplerate=srate,omode=omode) -# mylist = [] -# while(readsize==hopsize): -# readsize = filei.read(hopsize,myvec) -# freq = pitchdet(myvec) -# #print "%.3f %.2f" % (now,freq) -# if (aubio_silence_detection(myvec(),silence)!=1): -# mylist.append(freq) -# else: -# mylist.append(-1.) -# frameread += 1 -# return mylist - - class taskparams(object): """ default parameters for task classes """ def __init__(self,input=None,output=None):