History

fix gnuplot_create without options, add envelope draft, remove useless list fix gnuplot_create without options, add envelope draft, remove useless list

Paul Brossier committed 20 years ago

Commit e81c0451 parent dbd19ea1 file · +21 −9Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/aubio/gnuplot.py+21−9
@@ -43,7 +43,6 @@ def audio_to_array(filename): · 42 unmodified lines
43 return time,data43 return time,data
44 44
45def plot_audio(filenames, g, options):45def plot_audio(filenames, g, options):
46 d = []
47 todraw = len(filenames)46 todraw = len(filenames)
48 xorig = 0.47 xorig = 0.
49 xratio = 1./todraw48 xratio = 1./todraw
@@ -57,13 +56,13 @@ def plot_audio(filenames, g, options): · 7 unmodified lines
57 else:56 else:
58 g.xlabel('Time (s)')57 g.xlabel('Time (s)')
59 g.ylabel('Amplitude')58 g.ylabel('Amplitude')
60 d.append(make_audio_plot(time,data))59 curplot = make_audio_plot(time,data)
61 g('set size %f,%f;' % (options.xsize*xratio,options.ysize) )60 g('set size %f,%f;' % (options.xsize*xratio,options.ysize) )
62 g('set origin %f,0.;' % (xorig) )61 g('set origin %f,0.;' % (xorig) )
63 g('set style data lines; \62 g('set style data lines; \
64 set yrange [-1.:1.]; \63 set yrange [-1.:1.]; \
65 set xrange [0:%f]' % time[-1]) 64 set xrange [0:%f]' % time[-1])
66 g.plot(d.pop(0))65 g.plot(curplot)
67 xorig += options.xsize*xratio 66 xorig += options.xsize*xratio
68 g('unset multiplot;')67 g('unset multiplot;')
69 68
@@ -158,6 +157,16 @@ def make_audio_plot(time,data,maxpoints=10000): · 88 unmodified lines
158 x,y = downsample_audio(time,data,maxpoints=maxpoints)157 x,y = downsample_audio(time,data,maxpoints=maxpoints)
159 return Gnuplot.Data(x,y,with='lines')158 return Gnuplot.Data(x,y,with='lines')
160 159
160def make_audio_envelope(time,data,maxpoints=10000):
161 """ create gnuplot plot from an audio file """
162 import numarray
163 import Gnuplot, Gnuplot.funcutils
164 bufsize = 500
165 x = [i.mean() for i in numarray.array(time).resize(len(time)/bufsize,bufsize)]
166 y = [i.mean() for i in numarray.array(data).resize(len(time)/bufsize,bufsize)]
167 x,y = downsample_audio(x,y,maxpoints=maxpoints)
168 return Gnuplot.Data(x,y,with='lines')
169
161def gnuplot_addargs(parser):170def gnuplot_addargs(parser):
162 """ add common gnuplot argument to OptParser object """171 """ add common gnuplot argument to OptParser object """
163 parser.add_option("-x","--xsize",172 parser.add_option("-x","--xsize",
@@ -190,7 +199,10 @@ def gnuplot_addargs(parser): · 26 unmodified lines
190 199
191def gnuplot_create(outplot='',extension='', options=None):200def gnuplot_create(outplot='',extension='', options=None):
192 import Gnuplot201 import Gnuplot
193 g = Gnuplot.Gnuplot(debug=options.debug, persist=options.persist)202 if options:
203 g = Gnuplot.Gnuplot(debug=options.debug, persist=options.persist)
204 else:
205 g = Gnuplot.Gnuplot(persist=1)
194 if not extension or not outplot: return g206 if not extension or not outplot: return g
195 if extension == 'ps': ext, extension = '.ps' , 'postscript'207 if extension == 'ps': ext, extension = '.ps' , 'postscript'
196 elif extension == 'eps': ext, extension = '.eps' , 'postscript enhanced'208 elif extension == 'eps': ext, extension = '.eps' , 'postscript enhanced'
@@ -199,11 +211,11 @@ def gnuplot_create(outplot='',extension='', options=None): · 2 unmodified lines
199 elif extension == 'svg': ext, extension = '.svg', 'svg'211 elif extension == 'svg': ext, extension = '.svg', 'svg'
200 else: exit("ERR: unknown plot extension")212 else: exit("ERR: unknown plot extension")
201 g('set terminal %s' % extension)213 g('set terminal %s' % extension)
202 if options.lmargin: g('set lmargin %i' % options.lmargin)214 if options and options.lmargin: g('set lmargin %i' % options.lmargin)
203 if options.rmargin: g('set rmargin %i' % options.rmargin)215 if options and options.rmargin: g('set rmargin %i' % options.rmargin)
204 if options.bmargin: g('set bmargin %i' % options.bmargin)216 if options and options.bmargin: g('set bmargin %i' % options.bmargin)
205 if options.tmargin: g('set tmargin %i' % options.tmargin)217 if options and options.tmargin: g('set tmargin %i' % options.tmargin)
206 if outplot != "stdout":218 if outplot != "stdout":
207 g('set output \'%s%s\'' % (outplot,ext))219 g('set output \'%s%s\'' % (outplot,ext))
208 g('set size %f,%f' % (options.xsize, options.ysize))220 if options: g('set size %f,%f' % (options.xsize, options.ysize))
209 return g221 return g

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t