Showing the changes to python (3 of 3 files). Show all
Unified · Split
| @@ -72,7 +72,7 @@ def plot_audio(filenames, fileout=None, start=0, end=None, noaxis=None,xsize=1., · 71 unmodified lines | |||
| 72 | xorig += xsize*xratio | 72 | xorig += xsize*xratio |
| 73 | g.gnuplot('unset multiplot;') | 73 | g.gnuplot('unset multiplot;') |
| 74 | 74 | ||
| 75 | def audio_to_spec(filename,minf = 0, maxf = 0, lowthres = 0.): | 75 | def audio_to_spec(filename,minf = 0, maxf = 0, lowthres = -20.): |
| 76 | from aubioclass import fvec,cvec,pvoc,sndfile | 76 | from aubioclass import fvec,cvec,pvoc,sndfile |
| 77 | from math import log10 | 77 | from math import log10 |
| 78 | bufsize = 8192 | 78 | bufsize = 8192 |
| @@ -134,7 +134,7 @@ def plot_spec(filename, outplot='',extension='', fileout=None, start=0, end=None · 55 unmodified lines | |||
| 134 | if log: | 134 | if log: |
| 135 | g('set yrange [%f:%f]' % (max(10,minf),maxf)) | 135 | g('set yrange [%f:%f]' % (max(10,minf),maxf)) |
| 136 | g('set log y') | 136 | 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)) |
| 138 | #xorig += 1./todraw | 138 | #xorig += 1./todraw |
| 139 | 139 | ||
| 140 | def downsample_audio(time,data,maxpoints=10000): | 140 | def downsample_audio(time,data,maxpoints=10000): |
| @@ -139,15 +139,16 @@ class taskonset(task): · 138 unmodified lines | |||
| 139 | (100*float(bad+doubled)/(orig))) | 139 | (100*float(bad+doubled)/(orig))) |
| 140 | 140 | ||
| 141 | 141 | ||
| 142 | def plotplot(self,wplot,oplots,outplot=None): | 142 | def plotplot(self,wplot,oplots,outplot=None,extension=None,xsize=1.,ysize=1.,spectro=False): |
| 143 | from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot | 143 | from aubio.gnuplot import gnuplot_create, audio_to_array, make_audio_plot, audio_to_spec |
| 144 | import re | 144 | import re |
| 145 | # audio data | ||
| 146 | time,data = audio_to_array(self.input) | ||
| 147 | wplot = [make_audio_plot(time,data)] + wplot | ||
| 148 | # prepare the plot | 145 | # prepare the plot |
| 149 | g = gnuplot_init(outplot) | 146 | g = gnuplot_create(outplot=outplot, extension=extension) |
| 150 | 147 | ||
| 148 | if spectro: | ||
| 149 | g('set size %f,%f' % (xsize,1.3*ysize) ) | ||
| 150 | else: | ||
| 151 | g('set size %f,%f' % (xsize,ysize) ) | ||
| 151 | g('set multiplot') | 152 | g('set multiplot') |
| 152 | 153 | ||
| 153 | # hack to align left axis | 154 | # hack to align left axis |
| @@ -160,8 +161,8 @@ class taskonset(task): · 6 unmodified lines | |||
| 160 | 161 | ||
| 161 | for i in range(len(oplots)): | 162 | for i in range(len(oplots)): |
| 162 | # plot onset detection functions | 163 | # plot onset detection functions |
| 163 | g('set size 1,%f' % (0.7/(len(oplots)))) | 164 | g('set size %f,%f' % (xsize,0.7*ysize/(len(oplots)))) |
| 164 | g('set origin 0,%f' % ((len(oplots)-float(i)-1)*0.7/(len(oplots)))) | 165 | g('set origin 0,%f' % ((len(oplots)-float(i)-1)*0.7*ysize/(len(oplots)))) |
| 165 | g('set xrange [0:%f]' % (self.lenofunc*self.params.step)) | 166 | g('set xrange [0:%f]' % (self.lenofunc*self.params.step)) |
| 166 | g('set nokey') | 167 | g('set nokey') |
| 167 | g('set yrange [0:%f]' % (1.1*oplots[i][2])) | 168 | g('set yrange [0:%f]' % (1.1*oplots[i][2])) |
| @@ -171,18 +172,46 @@ class taskonset(task): · 3 unmodified lines | |||
| 171 | g.xlabel('time (s)',offset=(0,0.7)) | 172 | g.xlabel('time (s)',offset=(0,0.7)) |
| 172 | g.plot(*oplots[i][0]) | 173 | g.plot(*oplots[i][0]) |
| 173 | 174 | ||
| 174 | g('set tmargin 2') | 175 | if spectro: |
| 175 | g.xlabel('time (s)',offset=(0,0.7)) | 176 | import Gnuplot |
| 176 | g('set format x "%1.1f"') | 177 | minf = 50 |
| 177 | g('set format y "%1f"') | 178 | maxf = 500 |
| 178 | g('set y2tics -1,1') | 179 | data,time,freq = audio_to_spec(self.input,minf=minf,maxf=maxf) |
| 179 | 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"') | ||
| 180 | 206 | ||
| 207 | g('set size %f,%f' % (1.*xsize, 0.3*ysize)) | ||
| 181 | g('set title \'%s %s\'' % (re.sub('.*/','',self.input),self.title)) | 208 | 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') | ||
| 182 | 214 | ||
| 183 | # plot waveform and onsets | ||
| 184 | g('set size 1,0.3') | ||
| 185 | g('set origin 0,0.7') | ||
| 186 | g('set xrange [0:%f]' % max(time)) | 215 | g('set xrange [0:%f]' % max(time)) |
| 187 | g('set yrange [-1:1]') | 216 | g('set yrange [-1:1]') |
| 188 | g.ylabel('amplitude') | 217 | g.ylabel('amplitude') |
| @@ -61,15 +61,24 @@ def parse_args(): · 60 unmodified lines | |||
| 61 | parser.add_option("-p","--plot", | 61 | parser.add_option("-p","--plot", |
| 62 | action="store_true", dest="plot", default=False, | 62 | action="store_true", dest="plot", default=False, |
| 63 | help="draw plot") | 63 | help="draw plot") |
| 64 | parser.add_option("-f","--function", | 64 | parser.add_option("-x","--xsize", |
| 65 | action="store_true", dest="func", default=False, | 65 | action="store", dest="xsize", default=1., |
| 66 | help="print detection function") | 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") | ||
| 67 | parser.add_option("-n","--no-onsets", | 73 | parser.add_option("-n","--no-onsets", |
| 68 | action="store_true", dest="nplot", default=False, | 74 | action="store_true", dest="nplot", default=False, |
| 69 | help="plot only detection functions") | 75 | help="do not plot detected onsets") |
| 70 | parser.add_option("-O","--outplot", | 76 | parser.add_option("-O","--outplot", |
| 71 | action="store", dest="outplot", default=None, | 77 | action="store", dest="outplot", default=None, |
| 72 | help="save plot to output.{ps,png}") | 78 | 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") | ||
| 73 | parser.add_option("-v","--verbose", | 82 | parser.add_option("-v","--verbose", |
| 74 | action="store_true", dest="verbose", default=False, | 83 | action="store_true", dest="verbose", default=False, |
| 75 | help="make lots of noise [default]") | 84 | help="make lots of noise [default]") |
| @@ -130,7 +139,13 @@ for i in range(len(modes)): · 54 unmodified lines | |||
| 130 | for i in ofunc: | 139 | for i in ofunc: |
| 131 | print i | 140 | print i |
| 132 | 141 | ||
| 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) | ||
| 134 | 149 | ||
| 135 | if options.cut: | 150 | if options.cut: |
| 136 | a = taskcut(filename,onsets,params=params) | 151 | a = taskcut(filename,onsets,params=params) |