From: Paul Brossier Date: Wed, 17 May 2006 09:18:56 +0000 (+0000) Subject: add spectrogram and x/y sizes to aubiocut X-Git-Tag: bzr2git~696 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9b138a860a8a2939b8bd6aed7d5c460be0a4c8bd;p=aubio.git add spectrogram and x/y sizes to aubiocut add spectrogram and x/y sizes to aubiocut --- diff --git a/python/aubio/gnuplot.py b/python/aubio/gnuplot.py index cc18f045..a48f75bf 100644 --- a/python/aubio/gnuplot.py +++ b/python/aubio/gnuplot.py @@ -72,7 +72,7 @@ def plot_audio(filenames, fileout=None, start=0, end=None, noaxis=None,xsize=1., xorig += xsize*xratio g.gnuplot('unset multiplot;') -def audio_to_spec(filename,minf = 0, maxf = 0, lowthres = 0.): +def audio_to_spec(filename,minf = 0, maxf = 0, lowthres = -20.): from aubioclass import fvec,cvec,pvoc,sndfile from math import log10 bufsize = 8192 @@ -134,7 +134,7 @@ def plot_spec(filename, outplot='',extension='', fileout=None, start=0, end=None if log: g('set yrange [%f:%f]' % (max(10,minf),maxf)) g('set log y') - g.splot(Gnuplot.GridData(data,time,freq, binary=1, title='mag. (dB)')) + g.splot(Gnuplot.GridData(data,time,freq, binary=1)) #xorig += 1./todraw def downsample_audio(time,data,maxpoints=10000): diff --git a/python/aubio/task/onset.py b/python/aubio/task/onset.py index c2d5c065..41032462 100644 --- a/python/aubio/task/onset.py +++ b/python/aubio/task/onset.py @@ -139,15 +139,16 @@ class taskonset(task): (100*float(bad+doubled)/(orig))) - def plotplot(self,wplot,oplots,outplot=None): - from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot + def plotplot(self,wplot,oplots,outplot=None,extension=None,xsize=1.,ysize=1.,spectro=False): + from aubio.gnuplot import gnuplot_create, audio_to_array, make_audio_plot, audio_to_spec import re - # audio data - time,data = audio_to_array(self.input) - wplot = [make_audio_plot(time,data)] + wplot # prepare the plot - g = gnuplot_init(outplot) - + g = gnuplot_create(outplot=outplot, extension=extension) + + if spectro: + g('set size %f,%f' % (xsize,1.3*ysize) ) + else: + g('set size %f,%f' % (xsize,ysize) ) g('set multiplot') # hack to align left axis @@ -160,8 +161,8 @@ class taskonset(task): for i in range(len(oplots)): # plot onset detection functions - g('set size 1,%f' % (0.7/(len(oplots)))) - g('set origin 0,%f' % ((len(oplots)-float(i)-1)*0.7/(len(oplots)))) + g('set size %f,%f' % (xsize,0.7*ysize/(len(oplots)))) + g('set origin 0,%f' % ((len(oplots)-float(i)-1)*0.7*ysize/(len(oplots)))) g('set xrange [0:%f]' % (self.lenofunc*self.params.step)) g('set nokey') g('set yrange [0:%f]' % (1.1*oplots[i][2])) @@ -171,18 +172,46 @@ class taskonset(task): g.xlabel('time (s)',offset=(0,0.7)) g.plot(*oplots[i][0]) - g('set tmargin 2') - g.xlabel('time (s)',offset=(0,0.7)) - g('set format x "%1.1f"') - g('set format y "%1f"') - g('set y2tics -1,1') - + if spectro: + import Gnuplot + minf = 50 + maxf = 500 + data,time,freq = audio_to_spec(self.input,minf=minf,maxf=maxf) + g('set size %f,%f' % (1.24*xsize , 0.34*ysize) ) + g('set origin %f,%f' % (-0.12,0.65*ysize)) + g('set xrange [0.:%f]' % time[-1]) + g('set yrange [%f:%f]' % (minf,maxf)) + g('set pm3d map') + g('unset colorbox') + g('set lmargin 0') + g('set rmargin 0') + g('set tmargin 0') + g('set palette rgbformulae -25,-24,-32') + g.xlabel('') + g.ylabel('freq (Hz)') + #if log: + # g('set yrange [%f:%f]' % (max(10,minf),maxf)) + # g('set log y') + g.splot(Gnuplot.GridData(data,time,freq, binary=1, title='')) + g('set lmargin 3') + g('set rmargin 6') + g('set origin 0,%f' % (1.0*ysize) ) + g('set format x "%1.1f"') + g.xlabel('time (s)',offset=(0,1.)) + else: + # plot waveform and onsets + g('set origin 0,%f' % (0.7*ysize) ) + g.xlabel('time (s)',offset=(0,0.7)) + g('set format y "%1f"') + g('set size %f,%f' % (1.*xsize, 0.3*ysize)) g('set title \'%s %s\'' % (re.sub('.*/','',self.input),self.title)) + g('set tmargin 2') + # audio data + time,data = audio_to_array(self.input) + wplot = [make_audio_plot(time,data)] + wplot + g('set y2tics -1,1') - # 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') diff --git a/python/aubiocut b/python/aubiocut index b42b9567..4ed26aed 100755 --- a/python/aubiocut +++ b/python/aubiocut @@ -61,15 +61,24 @@ def parse_args(): parser.add_option("-p","--plot", action="store_true", dest="plot", default=False, help="draw plot") - parser.add_option("-f","--function", - action="store_true", dest="func", default=False, - help="print detection function") + parser.add_option("-x","--xsize", + action="store", dest="xsize", default=1., + type='float', help="define xsize for plot") + parser.add_option("-y","--ysize", + action="store", dest="ysize", default=1., + type='float', help="define ysize for plot") + parser.add_option("-f","--function", + action="store_true", dest="func", default=False, + help="print detection function") parser.add_option("-n","--no-onsets", action="store_true", dest="nplot", default=False, - help="plot only detection functions") + help="do not plot detected onsets") parser.add_option("-O","--outplot", action="store", dest="outplot", default=None, help="save plot to output.{ps,png}") + parser.add_option("-F","--spectrogram", + action="store_true", dest="spectro", default=False, + help="add spectrogram to the plot") parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=False, help="make lots of noise [default]") @@ -130,7 +139,13 @@ for i in range(len(modes)): for i in ofunc: print i -if options.plot: filetask.plotplot(wplot, oplots, outplot=options.outplot) +if options.outplot: + extension = options.outplot.split('.')[-1] + outplot = '.'.join(options.outplot.split('.')[:-1]) +else: + extension,outplot = None,None +if options.plot: filetask.plotplot(wplot, oplots, outplot=outplot, extension=extension, + xsize=options.xsize,ysize=options.ysize,spectro=options.spectro) if options.cut: a = taskcut(filename,onsets,params=params)