History

pass created plot to plot_audio/spec instead of outplot/extension, minor fixes pass created plot to plot_audio/spec instead of outplot/extension, minor fixes

Paul Brossier committed 20 years ago

Commit e5cc1ea1 parent 90bcdaa3 files · +26 −20Browse files

Showing the changes to python (3 of 3 files). Show all

Unified · Split

3 files
  1. python/aubio/gnuplot.py +22 −15
  2. python/aubioplot-audio +2 −4
  3. python/aubioplot-spec +2 −1
python/aubio/gnuplot.py+22−15
@@ -45,14 +45,13 @@ def audio_to_array(filename): · 44 unmodified lines
45 time = numarray.arange(len(data))*framestep45 time = numarray.arange(len(data))*framestep
46 return time,data46 return time,data
47 47
48def plot_audio(filenames, outplot='', extension='', start=0, end=None, noaxis=None,xsize=1.,ysize=1.):48def plot_audio(filenames, g, start=0, end=None, noaxis=None,xsize=1.,ysize=1.):
49 g = gnuplot_create(outplot, extension)
50 d = []49 d = []
51 todraw = len(filenames)50 todraw = len(filenames)
52 xorig = 0.51 xorig = 0.
53 xratio = 1./todraw52 xratio = 1./todraw
54 g.gnuplot('set size %f,%f;' % (xsize,ysize) )53 #g('set rmargin 7')
55 g.gnuplot('set multiplot;')54 g('set multiplot;')
56 while (len(filenames)):55 while (len(filenames)):
57 time,data = audio_to_array(filenames.pop(0))56 time,data = audio_to_array(filenames.pop(0))
58 if not noaxis and todraw==1:57 if not noaxis and todraw==1:
@@ -63,14 +62,14 @@ def plot_audio(filenames, outplot='', extension='', start=0, end=None, noaxis=No · 4 unmodified lines
63 g.xlabel('Time (s)')62 g.xlabel('Time (s)')
64 g.ylabel('Amplitude')63 g.ylabel('Amplitude')
65 d.append(make_audio_plot(time,data))64 d.append(make_audio_plot(time,data))
66 g.gnuplot('set size %f,%f;' % (xsize*xratio,ysize) )65 g('set size %f,%f;' % (xsize*xratio,ysize) )
67 g.gnuplot('set origin %f,0.;' % (xorig) )66 g('set origin %f,0.;' % (xorig) )
68 g.gnuplot('set style data lines; \67 g('set style data lines; \
69 set yrange [-1.:1.]; \68 set yrange [-1.:1.]; \
70 set xrange [0:%f]' % time[-1]) 69 set xrange [0:%f]' % time[-1])
71 g.plot(d.pop(0))70 g.plot(d.pop(0))
72 xorig += xsize*xratio 71 xorig += xsize*xratio
73 g.gnuplot('unset multiplot;')72 g('unset multiplot;')
74 73
75def audio_to_spec(filename,minf = 0, maxf = 0, lowthres = -20., 74def audio_to_spec(filename,minf = 0, maxf = 0, lowthres = -20.,
76 bufsize= 8192, hopsize = 1024):75 bufsize= 8192, hopsize = 1024):
@@ -116,9 +115,8 @@ def audio_to_spec(filename,minf = 0, maxf = 0, lowthres = -20., · 39 unmodified lines
116 assert len(data[0]) == len(freq)115 assert len(data[0]) == len(freq)
117 return data,time,freq116 return data,time,freq
118 117
119def plot_spec(filename, outplot='',extension='', fileout=None, start=0, end=None, noaxis=None,log=1, minf=0, maxf= 0, xsize = 1., ysize = 1.,bufsize=8192, hopsize=1024):118def plot_spec(filename, g, start=0, end=None, noaxis=None,log=1, minf=0, maxf= 0, xsize = 1., ysize = 1.,bufsize=8192, hopsize=1024):
120 import Gnuplot119 import Gnuplot
121 g = gnuplot_create(outplot,extension)
122 data,time,freq = audio_to_spec(filename,minf=minf,maxf=maxf,bufsize=bufsize,hopsize=hopsize)120 data,time,freq = audio_to_spec(filename,minf=minf,maxf=maxf,bufsize=bufsize,hopsize=hopsize)
123 xorig = 0.121 xorig = 0.
124 if not noaxis:122 if not noaxis:
@@ -127,16 +125,24 @@ def plot_spec(filename, outplot='',extension='', fileout=None, start=0, end=None · 2 unmodified lines
127 g.xlabel('Time (ms)')125 g.xlabel('Time (ms)')
128 else:126 else:
129 g.xlabel('Time (s)')127 g.xlabel('Time (s)')
130 g.ylabel('Frequency (Hz)')128 if xsize < 0.5 and not log and max(time) > 1.:
131 g('set size %f,%f' % (xsize, ysize))129 freq = [f/1000. for f in freq]
130 minf /= 1000.
131 maxf /= 1000.
132 g.ylabel('Frequency (kHz)')
133 else:
134 g.ylabel('Frequency (Hz)')
132 g('set pm3d map')135 g('set pm3d map')
133 g('set palette rgbformulae -25,-24,-32')136 g('set palette rgbformulae -25,-24,-32')
137 #g('set lmargin 4')
138 g('set cbtics 20')
134 #g('set colorbox horizontal')139 #g('set colorbox horizontal')
135 g('set xrange [0.:%f]' % time[-1]) 140 g('set xrange [0.:%f]' % time[-1])
136 g('set yrange [%f:%f]' % (minf,maxf))
137 if log:141 if log:
138 g('set yrange [%f:%f]' % (max(10,minf),maxf))
139 g('set log y')142 g('set log y')
143 g('set yrange [%f:%f]' % (max(10,minf),maxf))
144 else:
145 g('set yrange [%f:%f]' % (minf,maxf))
140 g.splot(Gnuplot.GridData(data,time,freq, binary=1))146 g.splot(Gnuplot.GridData(data,time,freq, binary=1))
141 #xorig += 1./todraw147 #xorig += 1./todraw
142 148
@@ -175,7 +181,7 @@ def gnuplot_init(outplot,debug=0,persist=1): · 32 unmodified lines
175 g('set output \'%s\'' % outplot)181 g('set output \'%s\'' % outplot)
176 return g182 return g
177 183
178def gnuplot_create(outplot='',extension='',debug=0,persist=1):184def gnuplot_create(outplot='',extension='',debug=0,persist=1, xsize=1., ysize=1.):
179 import Gnuplot185 import Gnuplot
180 g = Gnuplot.Gnuplot(debug=debug, persist=persist)186 g = Gnuplot.Gnuplot(debug=debug, persist=persist)
181 if not extension or not outplot: return g187 if not extension or not outplot: return g
@@ -188,4 +194,5 @@ def gnuplot_create(outplot='',extension='',debug=0,persist=1): · 6 unmodified lines
188 g('set terminal %s' % extension)194 g('set terminal %s' % extension)
189 if outplot != "stdout":195 if outplot != "stdout":
190 g('set output \'%s%s\'' % (outplot,ext))196 g('set output \'%s%s\'' % (outplot,ext))
197 g('set size %f,%f' % (xsize, ysize))
191 return g198 return g
python/aubioplot-audio+2−4
@@ -34,9 +34,7 @@ else: · 33 unmodified lines
34 extension = ''34 extension = ''
35 outplot = None35 outplot = None
36 36
37aubio.gnuplot.plot_audio(options.filename.split(','), 37g = aubio.gnuplot.gnuplot_create(outplot,extension,xsize=options.xsize, ysize=options.xsize)
38 extension = extension,38aubio.gnuplot.plot_audio(options.filename.split(','), g,
39 outplot = outplot,
40g,
41 xsize=options.xsize,39 xsize=options.xsize,
42 ysize=options.ysize)40 ysize=options.ysize)
python/aubioplot-spec+2−1
@@ -55,7 +55,8 @@ else: · 54 unmodified lines
55 extension = ''55 extension = ''
56 outplot = None56 outplot = None
57 57
58plot_spec(filename, outplot=outplot, extension=extension, log=options.log,58g = gnuplot_create(outplot,extension,xsize=options.xsize, ysize=options.ysize)
59plot_spec(filename, g, log=options.log,
59 maxf = options.maxf, minf = options.minf, 60 maxf = options.maxf, minf = options.minf,
60 xsize = options.xsize, ysize = options.ysize,61 xsize = options.xsize, ysize = options.ysize,
61 bufsize = options.bufsize, hopsize = options.hopsize)62 bufsize = options.bufsize, hopsize = options.hopsize)

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