x,y = downsample_audio(time,data,maxpoints=maxpoints)
return Gnuplot.Data(x,y,with='lines')
-def gnuplot_create(outplot='',extension='',debug=0,persist=1, xsize=1., ysize=1.):
- import Gnuplot
- g = Gnuplot.Gnuplot(debug=debug, persist=persist)
- if not extension or not outplot: return g
- if extension == 'ps': ext, extension = '.ps' , 'postscript'
- elif extension == 'eps': ext, extension = '.eps' , 'postscript enhanced'
- elif extension == 'epsc': ext, extension = '.eps' , 'postscript enhanced color'
- elif extension == 'png': ext, extension = '.png', 'png'
- elif extension == 'svg': ext, extension = '.svg', 'svg'
- else: exit("ERR: unknown plot extension")
- g('set terminal %s' % extension)
- if outplot != "stdout":
- g('set output \'%s%s\'' % (outplot,ext))
- g('set size %f,%f' % (xsize, ysize))
- return g
+def gnuplot_addargs(parser):
+ """ add common gnuplot argument to OptParser object """
+ 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("-d","--debug",
+ action="store_true", dest="debug", default=False,
+ help="use gnuplot debug mode")
+ parser.add_option("-p","--persist",
+ action="store_false", dest="persist", default=True,
+ help="do not use gnuplot persistant mode")
+ parser.add_option("-O","--outplot",
+ action="store", dest="outplot", default=None,
+ help="save plot to output.{ps,png}")
+
+def gnuplot_create(outplot='',extension='', options=None):
+ import Gnuplot
+ g = Gnuplot.Gnuplot(debug=options.debug, persist=options.persist)
+ if not extension or not outplot: return g
+ if extension == 'ps': ext, extension = '.ps' , 'postscript'
+ elif extension == 'eps': ext, extension = '.eps' , 'postscript enhanced'
+ elif extension == 'epsc': ext, extension = '.eps' , 'postscript enhanced color'
+ elif extension == 'png': ext, extension = '.png', 'png'
+ elif extension == 'svg': ext, extension = '.svg', 'svg'
+ else: exit("ERR: unknown plot extension")
+ g('set terminal %s' % extension)
+ if outplot != "stdout":
+ g('set output \'%s%s\'' % (outplot,ext))
+ g('set size %f,%f' % (options.xsize, options.ysize))
+ return g
#!/usr/bin/python
-import aubio.gnuplot, sys
+import sys
+from aubio.gnuplot import gnuplot_create,gnuplot_addargs,plot_audio
usage = "usage: %s [options] -i soundfile" % sys.argv[0]
parser.add_option("-i","--input",
action="store", dest="filename",
help="input sound file")
- 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("-O","--outplot",
- action="store", dest="outplot", default=None,
- help="save plot to output.{ps,png}")
+ gnuplot_addargs(parser)
(options, args) = parser.parse_args()
if not options.filename:
print "no file name given\n", usage
extension = ''
outplot = None
-g = aubio.gnuplot.gnuplot_create(outplot,extension,xsize=options.xsize, ysize=options.xsize)
-aubio.gnuplot.plot_audio(options.filename.split(','), g,
+g = gnuplot_create(outplot,extension,options)
+plot_audio(options.filename.split(','), g,
xsize=options.xsize,
ysize=options.ysize)
"""
import sys
-from aubio.gnuplot import *
+from aubio.gnuplot import gnuplot_create,gnuplot_addargs,plot_spec
usage = "usage: %s [options] -i soundfile" % sys.argv[0]
parser.add_option("-L","--minf",
action="store", dest="minf", default=0.,
type='float',help="lower frequency limit")
- 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("-l","--log",
action="store_true", dest="log", default=False,
help="plot on a logarithmic scale")
- parser.add_option("-O","--outplot",
- action="store", dest="outplot", default=None,
- help="save plot to output.{ps,png}")
parser.add_option("-B","--bufsize", type='int',
action="store", dest="bufsize", default=8192,
help="buffer size [default=8192]")
parser.add_option("-H","--hopsize", type='int',
action="store", dest="hopsize", default=1024,
help="overlap size [default=1024]")
+ gnuplot_addargs(parser)
(options, args) = parser.parse_args()
if not options.filename:
print "no file name given\n", usage
extension = ''
outplot = None
-g = gnuplot_create(outplot,extension,xsize=options.xsize, ysize=options.ysize)
+g = gnuplot_create(outplot,extension,options)
plot_spec(filename, g, log=options.log,
maxf = options.maxf, minf = options.minf,
xsize = options.xsize, ysize = options.ysize,