History

add spectrogram and x/y sizes to aubiocut add spectrogram and x/y sizes to aubiocut

Paul Brossier committed 20 years ago

Commit 9b138a81 parent 7cded323 files · +69 −25Browse files

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

Unified · Split

3 files
  1. python/aubio/gnuplot.py +2 −2
  2. python/aubio/task/onset.py +47 −18
  3. python/aubiocut +20 −5
python/aubio/gnuplot.py+2−2
@@ -72,7 +72,7 @@ def plot_audio(filenames, fileout=None, start=0, end=None, noaxis=None,xsize=1., · 71 unmodified lines
7272 xorig += xsize*xratio
7373 g.gnuplot('unset multiplot;')
7474
75−def audio_to_spec(filename,minf = 0, maxf = 0, lowthres = 0.):
75+def audio_to_spec(filename,minf = 0, maxf = 0, lowthres = -20.):
7676 from aubioclass import fvec,cvec,pvoc,sndfile
7777 from math import log10
7878 bufsize = 8192
@@ -134,7 +134,7 @@ def plot_spec(filename, outplot='',extension='', fileout=None, start=0, end=None · 55 unmodified lines
134134 if log:
135135 g('set yrange [%f:%f]' % (max(10,minf),maxf))
136136 g('set log y')
137− g.splot(Gnuplot.GridData(data,time,freq, binary=1, title='mag. (dB)'))
137+ g.splot(Gnuplot.GridData(data,time,freq, binary=1))
138138 #xorig += 1./todraw
139139
140140 def downsample_audio(time,data,maxpoints=10000):
python/aubio/task/onset.py+47−18
@@ -139,15 +139,16 @@ class taskonset(task): · 138 unmodified lines
139139 (100*float(bad+doubled)/(orig)))
140140
141141
142− def plotplot(self,wplot,oplots,outplot=None):
143− from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot
142+ def plotplot(self,wplot,oplots,outplot=None,extension=None,xsize=1.,ysize=1.,spectro=False):
143+ from aubio.gnuplot import gnuplot_create, audio_to_array, make_audio_plot, audio_to_spec
144144 import re
145− # audio data
146− time,data = audio_to_array(self.input)
147− wplot = [make_audio_plot(time,data)] + wplot
148145 # prepare the plot
149− g = gnuplot_init(outplot)
150−
146+ g = gnuplot_create(outplot=outplot, extension=extension)
147+
148+ if spectro:
149+ g('set size %f,%f' % (xsize,1.3*ysize) )
150+ else:
151+ g('set size %f,%f' % (xsize,ysize) )
151152 g('set multiplot')
152153
153154 # hack to align left axis
@@ -160,8 +161,8 @@ class taskonset(task): · 6 unmodified lines
160161
161162 for i in range(len(oplots)):
162163 # plot onset detection functions
163− g('set size 1,%f' % (0.7/(len(oplots))))
164− g('set origin 0,%f' % ((len(oplots)-float(i)-1)*0.7/(len(oplots))))
164+ g('set size %f,%f' % (xsize,0.7*ysize/(len(oplots))))
165+ g('set origin 0,%f' % ((len(oplots)-float(i)-1)*0.7*ysize/(len(oplots))))
165166 g('set xrange [0:%f]' % (self.lenofunc*self.params.step))
166167 g('set nokey')
167168 g('set yrange [0:%f]' % (1.1*oplots[i][2]))
@@ -171,18 +172,46 @@ class taskonset(task): · 3 unmodified lines
171172 g.xlabel('time (s)',offset=(0,0.7))
172173 g.plot(*oplots[i][0])
173174
174− g('set tmargin 2')
175− g.xlabel('time (s)',offset=(0,0.7))
176− g('set format x "%1.1f"')
177− g('set format y "%1f"')
178− g('set y2tics -1,1')
179−
175+ if spectro:
176+ import Gnuplot
177+ minf = 50
178+ maxf = 500
179+ data,time,freq = audio_to_spec(self.input,minf=minf,maxf=maxf)
180+ g('set size %f,%f' % (1.24*xsize , 0.34*ysize) )
181+ g('set origin %f,%f' % (-0.12,0.65*ysize))
182+ g('set xrange [0.:%f]' % time[-1])
183+ g('set yrange [%f:%f]' % (minf,maxf))
184+ g('set pm3d map')
185+ g('unset colorbox')
186+ g('set lmargin 0')
187+ g('set rmargin 0')
188+ g('set tmargin 0')
189+ g('set palette rgbformulae -25,-24,-32')
190+ g.xlabel('')
191+ g.ylabel('freq (Hz)')
192+ #if log:
193+ # g('set yrange [%f:%f]' % (max(10,minf),maxf))
194+ # g('set log y')
195+ g.splot(Gnuplot.GridData(data,time,freq, binary=1, title=''))
196+ g('set lmargin 3')
197+ g('set rmargin 6')
198+ g('set origin 0,%f' % (1.0*ysize) )
199+ g('set format x "%1.1f"')
200+ g.xlabel('time (s)',offset=(0,1.))
201+ else:
202+ # plot waveform and onsets
203+ g('set origin 0,%f' % (0.7*ysize) )
204+ g.xlabel('time (s)',offset=(0,0.7))
205+ g('set format y "%1f"')
180206
207+ g('set size %f,%f' % (1.*xsize, 0.3*ysize))
181208 g('set title \'%s %s\'' % (re.sub('.*/','',self.input),self.title))
209+ g('set tmargin 2')
210+ # audio data
211+ time,data = audio_to_array(self.input)
212+ wplot = [make_audio_plot(time,data)] + wplot
213+ g('set y2tics -1,1')
182214
183− # plot waveform and onsets
184− g('set size 1,0.3')
185− g('set origin 0,0.7')
186215 g('set xrange [0:%f]' % max(time))
187216 g('set yrange [-1:1]')
188217 g.ylabel('amplitude')
python/aubiocut+20−5
@@ -61,15 +61,24 @@ def parse_args(): · 60 unmodified lines
6161 parser.add_option("-p","--plot",
6262 action="store_true", dest="plot", default=False,
6363 help="draw plot")
64− parser.add_option("-f","--function",
65− action="store_true", dest="func", default=False,
66− help="print detection function")
64+ parser.add_option("-x","--xsize",
65+ action="store", dest="xsize", default=1.,
66+ type='float', help="define xsize for plot")
67+ parser.add_option("-y","--ysize",
68+ action="store", dest="ysize", default=1.,
69+ type='float', help="define ysize for plot")
70+ parser.add_option("-f","--function",
71+ action="store_true", dest="func", default=False,
72+ help="print detection function")
6773 parser.add_option("-n","--no-onsets",
6874 action="store_true", dest="nplot", default=False,
69− help="plot only detection functions")
75+ help="do not plot detected onsets")
7076 parser.add_option("-O","--outplot",
7177 action="store", dest="outplot", default=None,
7278 help="save plot to output.{ps,png}")
79+ parser.add_option("-F","--spectrogram",
80+ action="store_true", dest="spectro", default=False,
81+ help="add spectrogram to the plot")
7382 parser.add_option("-v","--verbose",
7483 action="store_true", dest="verbose", default=False,
7584 help="make lots of noise [default]")
@@ -130,7 +139,13 @@ for i in range(len(modes)): · 54 unmodified lines
130139 for i in ofunc:
131140 print i
132141
133−if options.plot: filetask.plotplot(wplot, oplots, outplot=options.outplot)
142+if options.outplot:
143+ extension = options.outplot.split('.')[-1]
144+ outplot = '.'.join(options.outplot.split('.')[:-1])
145+else:
146+ extension,outplot = None,None
147+if options.plot: filetask.plotplot(wplot, oplots, outplot=outplot, extension=extension,
148+ xsize=options.xsize,ysize=options.ysize,spectro=options.spectro)
134149
135150 if options.cut:
136151 a = taskcut(filename,onsets,params=params)

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