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
4343 return time,data
4444
4545 def plot_audio(filenames, g, options):
46− d = []
4746 todraw = len(filenames)
4847 xorig = 0.
4948 xratio = 1./todraw
@@ -57,13 +56,13 @@ def plot_audio(filenames, g, options): · 7 unmodified lines
5756 else:
5857 g.xlabel('Time (s)')
5958 g.ylabel('Amplitude')
60− d.append(make_audio_plot(time,data))
59+ curplot = make_audio_plot(time,data)
6160 g('set size %f,%f;' % (options.xsize*xratio,options.ysize) )
6261 g('set origin %f,0.;' % (xorig) )
6362 g('set style data lines; \
6463 set yrange [-1.:1.]; \
6564 set xrange [0:%f]' % time[-1])
66− g.plot(d.pop(0))
65+ g.plot(curplot)
6766 xorig += options.xsize*xratio
6867 g('unset multiplot;')
6968
@@ -158,6 +157,16 @@ def make_audio_plot(time,data,maxpoints=10000): · 88 unmodified lines
158157 x,y = downsample_audio(time,data,maxpoints=maxpoints)
159158 return Gnuplot.Data(x,y,with='lines')
160159
160+def 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+
161170 def gnuplot_addargs(parser):
162171 """ add common gnuplot argument to OptParser object """
163172 parser.add_option("-x","--xsize",
@@ -190,7 +199,10 @@ def gnuplot_addargs(parser): · 26 unmodified lines
190199
191200 def gnuplot_create(outplot='',extension='', options=None):
192201 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)
194206 if not extension or not outplot: return g
195207 if extension == 'ps': ext, extension = '.ps' , 'postscript'
196208 elif extension == 'eps': ext, extension = '.eps' , 'postscript enhanced'
@@ -199,11 +211,11 @@ def gnuplot_create(outplot='',extension='', options=None): · 2 unmodified lines
199211 elif extension == 'svg': ext, extension = '.svg', 'svg'
200212 else: exit("ERR: unknown plot extension")
201213 g('set terminal %s' % extension)
202− if options.lmargin: g('set lmargin %i' % options.lmargin)
203− if options.rmargin: g('set rmargin %i' % options.rmargin)
204− if options.bmargin: g('set bmargin %i' % options.bmargin)
205− if options.tmargin: g('set tmargin %i' % options.tmargin)
214+ if options and options.lmargin: g('set lmargin %i' % options.lmargin)
215+ if options and options.rmargin: g('set rmargin %i' % options.rmargin)
216+ if options and options.bmargin: g('set bmargin %i' % options.bmargin)
217+ if options and options.tmargin: g('set tmargin %i' % options.tmargin)
206218 if outplot != "stdout":
207219 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))
209221 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