Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -43,7 +43,6 @@ def audio_to_array(filename): · 42 unmodified lines | ||
| 43 | 43 | return time,data |
| 44 | 44 | |
| 45 | 45 | def plot_audio(filenames, g, options): |
| 46 | − d = [] | |
| 47 | 46 | todraw = len(filenames) |
| 48 | 47 | xorig = 0. |
| 49 | 48 | xratio = 1./todraw |
| @@ -57,13 +56,13 @@ def plot_audio(filenames, g, options): · 7 unmodified lines | ||
| 57 | 56 | else: |
| 58 | 57 | g.xlabel('Time (s)') |
| 59 | 58 | g.ylabel('Amplitude') |
| 60 | − d.append(make_audio_plot(time,data)) | |
| 59 | + curplot = make_audio_plot(time,data) | |
| 61 | 60 | g('set size %f,%f;' % (options.xsize*xratio,options.ysize) ) |
| 62 | 61 | g('set origin %f,0.;' % (xorig) ) |
| 63 | 62 | g('set style data lines; \ |
| 64 | 63 | set yrange [-1.:1.]; \ |
| 65 | 64 | set xrange [0:%f]' % time[-1]) |
| 66 | − g.plot(d.pop(0)) | |
| 65 | + g.plot(curplot) | |
| 67 | 66 | xorig += options.xsize*xratio |
| 68 | 67 | g('unset multiplot;') |
| 69 | 68 | |
| @@ -158,6 +157,16 @@ def make_audio_plot(time,data,maxpoints=10000): · 88 unmodified lines | ||
| 158 | 157 | x,y = downsample_audio(time,data,maxpoints=maxpoints) |
| 159 | 158 | return Gnuplot.Data(x,y,with='lines') |
| 160 | 159 | |
| 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 | + | |
| 161 | 170 | def gnuplot_addargs(parser): |
| 162 | 171 | """ add common gnuplot argument to OptParser object """ |
| 163 | 172 | parser.add_option("-x","--xsize", |
| @@ -190,7 +199,10 @@ def gnuplot_addargs(parser): · 26 unmodified lines | ||
| 190 | 199 | |
| 191 | 200 | def gnuplot_create(outplot='',extension='', options=None): |
| 192 | 201 | 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 | 206 | if not extension or not outplot: return g |
| 195 | 207 | if extension == 'ps': ext, extension = '.ps' , 'postscript' |
| 196 | 208 | elif extension == 'eps': ext, extension = '.eps' , 'postscript enhanced' |
| @@ -199,11 +211,11 @@ def gnuplot_create(outplot='',extension='', options=None): · 2 unmodified lines | ||
| 199 | 211 | elif extension == 'svg': ext, extension = '.svg', 'svg' |
| 200 | 212 | else: exit("ERR: unknown plot extension") |
| 201 | 213 | 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) | |
| 206 | 218 | if outplot != "stdout": |
| 207 | 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 | 221 | return g |