ref: 9b138a860a8a2939b8bd6aed7d5c460be0a4c8bd
parent: 7cded32206cb485ddfde9a26bb0dbe9506ea9b1b
author: Paul Brossier <piem@altern.org>
date: Wed May 17 05:18:56 EDT 2006
add spectrogram and x/y sizes to aubiocut add spectrogram and x/y sizes to aubiocut
--- a/python/aubio/gnuplot.py
+++ b/python/aubio/gnuplot.py
@@ -72,7 +72,7 @@
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 @@
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):
--- a/python/aubio/task/onset.py
+++ b/python/aubio/task/onset.py
@@ -139,15 +139,16 @@
(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 @@
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 @@
g.xlabel('time (s)',offset=(0,0.7))
g.plot(*oplots[i][0])
+ 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')
- g.xlabel('time (s)',offset=(0,0.7))
- g('set format x "%1.1f"')
- g('set format y "%1f"')
+ # audio data
+ time,data = audio_to_array(self.input)
+ wplot = [make_audio_plot(time,data)] + wplot
g('set y2tics -1,1')
-
- g('set title \'%s %s\'' % (re.sub('.*/','',self.input),self.title))
-
- # 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')
--- a/python/aubiocut
+++ b/python/aubiocut
@@ -61,15 +61,24 @@
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 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)