Showing the changes to python (3 of 3 files). Show all
Unified · Split
| @@ -162,18 +162,36 @@ def make_audio_plot(time,data,maxpoints=10000): · 161 unmodified lines | ||
| 162 | 162 | x,y = downsample_audio(time,data,maxpoints=maxpoints) |
| 163 | 163 | return Gnuplot.Data(x,y,with='lines') |
| 164 | 164 | |
| 165 | −def gnuplot_create(outplot='',extension='',debug=0,persist=1, xsize=1., ysize=1.): | |
| 166 | − import Gnuplot | |
| 167 | − g = Gnuplot.Gnuplot(debug=debug, persist=persist) | |
| 168 | − if not extension or not outplot: return g | |
| 169 | − if extension == 'ps': ext, extension = '.ps' , 'postscript' | |
| 170 | − elif extension == 'eps': ext, extension = '.eps' , 'postscript enhanced' | |
| 171 | − elif extension == 'epsc': ext, extension = '.eps' , 'postscript enhanced color' | |
| 172 | − elif extension == 'png': ext, extension = '.png', 'png' | |
| 173 | − elif extension == 'svg': ext, extension = '.svg', 'svg' | |
| 174 | − else: exit("ERR: unknown plot extension") | |
| 175 | − g('set terminal %s' % extension) | |
| 176 | − if outplot != "stdout": | |
| 177 | − g('set output \'%s%s\'' % (outplot,ext)) | |
| 178 | − g('set size %f,%f' % (xsize, ysize)) | |
| 179 | − return g | |
| 165 | +def gnuplot_addargs(parser): | |
| 166 | + """ add common gnuplot argument to OptParser object """ | |
| 167 | + parser.add_option("-x","--xsize", | |
| 168 | + action="store", dest="xsize", default=1., | |
| 169 | + type='float',help="define xsize for plot") | |
| 170 | + parser.add_option("-y","--ysize", | |
| 171 | + action="store", dest="ysize", default=1., | |
| 172 | + type='float',help="define ysize for plot") | |
| 173 | + parser.add_option("-d","--debug", | |
| 174 | + action="store_true", dest="debug", default=False, | |
| 175 | + help="use gnuplot debug mode") | |
| 176 | + parser.add_option("-p","--persist", | |
| 177 | + action="store_false", dest="persist", default=True, | |
| 178 | + help="do not use gnuplot persistant mode") | |
| 179 | + parser.add_option("-O","--outplot", | |
| 180 | + action="store", dest="outplot", default=None, | |
| 181 | + help="save plot to output.{ps,png}") | |
| 182 | + | |
| 183 | +def gnuplot_create(outplot='',extension='', options=None): | |
| 184 | + import Gnuplot | |
| 185 | + g = Gnuplot.Gnuplot(debug=options.debug, persist=options.persist) | |
| 186 | + if not extension or not outplot: return g | |
| 187 | + if extension == 'ps': ext, extension = '.ps' , 'postscript' | |
| 188 | + elif extension == 'eps': ext, extension = '.eps' , 'postscript enhanced' | |
| 189 | + elif extension == 'epsc': ext, extension = '.eps' , 'postscript enhanced color' | |
| 190 | + elif extension == 'png': ext, extension = '.png', 'png' | |
| 191 | + elif extension == 'svg': ext, extension = '.svg', 'svg' | |
| 192 | + else: exit("ERR: unknown plot extension") | |
| 193 | + g('set terminal %s' % extension) | |
| 194 | + if outplot != "stdout": | |
| 195 | + g('set output \'%s%s\'' % (outplot,ext)) | |
| 196 | + g('set size %f,%f' % (options.xsize, options.ysize)) | |
| 197 | + return g | |
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | #!/usr/bin/python |
| 2 | 2 | |
| 3 | −import aubio.gnuplot, sys | |
| 3 | +import sys | |
| 4 | +from aubio.gnuplot import gnuplot_create,gnuplot_addargs,plot_audio | |
| 4 | 5 | |
| 5 | 6 | usage = "usage: %s [options] -i soundfile" % sys.argv[0] |
| 6 | 7 | |
| @@ -10,15 +11,7 @@ def parse_args(): · 3 unmodified lines | ||
| 10 | 11 | parser.add_option("-i","--input", |
| 11 | 12 | action="store", dest="filename", |
| 12 | 13 | help="input sound file") |
| 13 | − parser.add_option("-x","--xsize", | |
| 14 | − action="store", dest="xsize", default=1., | |
| 15 | − type='float',help="define xsize for plot") | |
| 16 | − parser.add_option("-y","--ysize", | |
| 17 | − action="store", dest="ysize", default=1., | |
| 18 | − type='float',help="define ysize for plot") | |
| 19 | − parser.add_option("-O","--outplot", | |
| 20 | − action="store", dest="outplot", default=None, | |
| 21 | − help="save plot to output.{ps,png}") | |
| 14 | + gnuplot_addargs(parser) | |
| 22 | 15 | (options, args) = parser.parse_args() |
| 23 | 16 | if not options.filename: |
| 24 | 17 | print "no file name given\n", usage |
| @@ -34,7 +27,7 @@ else: · 9 unmodified lines | ||
| 34 | 27 | extension = '' |
| 35 | 28 | outplot = None |
| 36 | 29 | |
| 37 | −g = aubio.gnuplot.gnuplot_create(outplot,extension,xsize=options.xsize, ysize=options.xsize) | |
| 38 | −aubio.gnuplot.plot_audio(options.filename.split(','), g, | |
| 30 | +g = gnuplot_create(outplot,extension,options) | |
| 31 | +plot_audio(options.filename.split(','), g, | |
| 39 | 32 | xsize=options.xsize, |
| 40 | 33 | ysize=options.ysize) |
| @@ -5,7 +5,7 @@ · 4 unmodified lines | ||
| 5 | 5 | """ |
| 6 | 6 | |
| 7 | 7 | import sys |
| 8 | −from aubio.gnuplot import * | |
| 8 | +from aubio.gnuplot import gnuplot_create,gnuplot_addargs,plot_spec | |
| 9 | 9 | |
| 10 | 10 | usage = "usage: %s [options] -i soundfile" % sys.argv[0] |
| 11 | 11 | |
| @@ -21,24 +21,16 @@ def parse_args(): · 9 unmodified lines | ||
| 21 | 21 | parser.add_option("-L","--minf", |
| 22 | 22 | action="store", dest="minf", default=0., |
| 23 | 23 | type='float',help="lower frequency limit") |
| 24 | − parser.add_option("-x","--xsize", | |
| 25 | − action="store", dest="xsize", default=1., | |
| 26 | − type='float',help="define xsize for plot") | |
| 27 | − parser.add_option("-y","--ysize", | |
| 28 | − action="store", dest="ysize", default=1., | |
| 29 | − type='float',help="define ysize for plot") | |
| 30 | 24 | parser.add_option("-l","--log", |
| 31 | 25 | action="store_true", dest="log", default=False, |
| 32 | 26 | help="plot on a logarithmic scale") |
| 33 | − parser.add_option("-O","--outplot", | |
| 34 | − action="store", dest="outplot", default=None, | |
| 35 | − help="save plot to output.{ps,png}") | |
| 36 | 27 | parser.add_option("-B","--bufsize", type='int', |
| 37 | 28 | action="store", dest="bufsize", default=8192, |
| 38 | 29 | help="buffer size [default=8192]") |
| 39 | 30 | parser.add_option("-H","--hopsize", type='int', |
| 40 | 31 | action="store", dest="hopsize", default=1024, |
| 41 | 32 | help="overlap size [default=1024]") |
| 33 | + gnuplot_addargs(parser) | |
| 42 | 34 | (options, args) = parser.parse_args() |
| 43 | 35 | if not options.filename: |
| 44 | 36 | print "no file name given\n", usage |
| @@ -55,7 +47,7 @@ else: · 10 unmodified lines | ||
| 55 | 47 | extension = '' |
| 56 | 48 | outplot = None |
| 57 | 49 | |
| 58 | −g = gnuplot_create(outplot,extension,xsize=options.xsize, ysize=options.ysize) | |
| 50 | +g = gnuplot_create(outplot,extension,options) | |
| 59 | 51 | plot_spec(filename, g, log=options.log, |
| 60 | 52 | maxf = options.maxf, minf = options.minf, |
| 61 | 53 | xsize = options.xsize, ysize = options.ysize, |