| @@ -21,9 +21,6 @@ __LICENSE__ = """\ · 20 unmodified lines |
| 21 | 21 | """ |
| 22 | 22 | |
| 23 | 23 | |
| 24 | | −__notesheight = 0.25 |
| 25 | | − |
| 26 | | − |
| 27 | 24 | def audio_to_array(filename): |
| 28 | 25 | import aubio.aubioclass |
| 29 | 26 | import numarray |
| @@ -45,16 +42,15 @@ def audio_to_array(filename): · 15 unmodified lines |
| 45 | 42 | time = numarray.arange(len(data))*framestep |
| 46 | 43 | return time,data |
| 47 | 44 | |
| 48 | | −def plot_audio(filenames, g, start=0, end=None, noaxis=None,xsize=1.,ysize=1.): |
| 45 | +def plot_audio(filenames, g, options): |
| 49 | 46 | d = [] |
| 50 | 47 | todraw = len(filenames) |
| 51 | 48 | xorig = 0. |
| 52 | 49 | xratio = 1./todraw |
| 53 | | − #g('set rmargin 7') |
| 54 | 50 | g('set multiplot;') |
| 55 | 51 | while (len(filenames)): |
| 56 | 52 | time,data = audio_to_array(filenames.pop(0)) |
| 57 | | − if not noaxis and todraw==1: |
| 53 | + if todraw==1: |
| 58 | 54 | if max(time) < 1.: |
| 59 | 55 | time = [t*1000. for t in time] |
| 60 | 56 | g.xlabel('Time (ms)') |
| @@ -62,13 +58,13 @@ def plot_audio(filenames, g, start=0, end=None, noaxis=None,xsize=1.,ysize=1.): · 1 unmodified line |
| 62 | 58 | g.xlabel('Time (s)') |
| 63 | 59 | g.ylabel('Amplitude') |
| 64 | 60 | d.append(make_audio_plot(time,data)) |
| 65 | | − g('set size %f,%f;' % (xsize*xratio,ysize) ) |
| 61 | + g('set size %f,%f;' % (options.xsize*xratio,options.ysize) ) |
| 66 | 62 | g('set origin %f,0.;' % (xorig) ) |
| 67 | 63 | g('set style data lines; \ |
| 68 | 64 | set yrange [-1.:1.]; \ |
| 69 | 65 | set xrange [0:%f]' % time[-1]) |
| 70 | 66 | g.plot(d.pop(0)) |
| 71 | | − xorig += xsize*xratio |
| 67 | + xorig += options.xsize*xratio |
| 72 | 68 | g('unset multiplot;') |
| 73 | 69 | |
| 74 | 70 | def audio_to_spec(filename,minf = 0, maxf = 0, lowthres = -20., |
| @@ -115,34 +111,34 @@ def audio_to_spec(filename,minf = 0, maxf = 0, lowthres = -20., · 40 unmodified lines |
| 115 | 111 | assert len(data[0]) == len(freq) |
| 116 | 112 | return data,time,freq |
| 117 | 113 | |
| 118 | | −def plot_spec(filename, g, start=0, end=None, noaxis=None,log=1, minf=0, maxf= 0, xsize = 1., ysize = 1.,bufsize=8192, hopsize=1024): |
| 114 | +def plot_spec(filename, g, options): |
| 119 | 115 | import Gnuplot |
| 120 | | − data,time,freq = audio_to_spec(filename,minf=minf,maxf=maxf,bufsize=bufsize,hopsize=hopsize) |
| 116 | + data,time,freq = audio_to_spec(filename, |
| 117 | + minf=options.minf,maxf=options.maxf, |
| 118 | + bufsize=options.bufsize,hopsize=options.hopsize) |
| 121 | 119 | xorig = 0. |
| 122 | | − if not noaxis: |
| 123 | | − if max(time) < 1.: |
| 124 | | − time = [t*1000. for t in time] |
| 125 | | − g.xlabel('Time (ms)') |
| 126 | | − else: |
| 127 | | − g.xlabel('Time (s)') |
| 128 | | − if xsize < 0.5 and not log and max(time) > 1.: |
| 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)') |
| 120 | + if max(time) < 1.: |
| 121 | + time = [t*1000. for t in time] |
| 122 | + g.xlabel('Time (ms)') |
| 123 | + else: |
| 124 | + g.xlabel('Time (s)') |
| 125 | + if options.xsize < 0.5 and not options.log and max(time) > 1.: |
| 126 | + freq = [f/1000. for f in freq] |
| 127 | + options.minf /= 1000. |
| 128 | + options.maxf /= 1000. |
| 129 | + g.ylabel('Frequency (kHz)') |
| 130 | + else: |
| 131 | + g.ylabel('Frequency (Hz)') |
| 135 | 132 | g('set pm3d map') |
| 136 | 133 | g('set palette rgbformulae -25,-24,-32') |
| 137 | | − #g('set lmargin 4') |
| 138 | 134 | g('set cbtics 20') |
| 139 | 135 | #g('set colorbox horizontal') |
| 140 | 136 | g('set xrange [0.:%f]' % time[-1]) |
| 141 | | − if log: |
| 137 | + if options.log: |
| 142 | 138 | g('set log y') |
| 143 | | − g('set yrange [%f:%f]' % (max(10,minf),maxf)) |
| 139 | + g('set yrange [%f:%f]' % (max(10,options.minf),options.maxf)) |
| 144 | 140 | else: |
| 145 | | − g('set yrange [%f:%f]' % (minf,maxf)) |
| 141 | + g('set yrange [%f:%f]' % (options.minf,options.maxf)) |
| 146 | 142 | g.splot(Gnuplot.GridData(data,time,freq, binary=1)) |
| 147 | 143 | #xorig += 1./todraw |
| 148 | 144 | |
| @@ -170,12 +166,24 @@ def gnuplot_addargs(parser): · 21 unmodified lines |
| 170 | 166 | parser.add_option("-y","--ysize", |
| 171 | 167 | action="store", dest="ysize", default=1., |
| 172 | 168 | type='float',help="define ysize for plot") |
| 173 | | − parser.add_option("-d","--debug", |
| 169 | + parser.add_option("--debug", |
| 174 | 170 | action="store_true", dest="debug", default=False, |
| 175 | 171 | help="use gnuplot debug mode") |
| 176 | | − parser.add_option("-p","--persist", |
| 172 | + parser.add_option("--persist", |
| 177 | 173 | action="store_false", dest="persist", default=True, |
| 178 | 174 | help="do not use gnuplot persistant mode") |
| 175 | + parser.add_option("--lmargin", |
| 176 | + action="store", dest="lmargin", default=None, |
| 177 | + type='int',help="define left margin for plot") |
| 178 | + parser.add_option("--rmargin", |
| 179 | + action="store", dest="rmargin", default=None, |
| 180 | + type='int',help="define right margin for plot") |
| 181 | + parser.add_option("--bmargin", |
| 182 | + action="store", dest="bmargin", default=None, |
| 183 | + type='int',help="define bottom margin for plot") |
| 184 | + parser.add_option("--tmargin", |
| 185 | + action="store", dest="tmargin", default=None, |
| 186 | + type='int',help="define top margin for plot") |
| 179 | 187 | parser.add_option("-O","--outplot", |
| 180 | 188 | action="store", dest="outplot", default=None, |
| 181 | 189 | help="save plot to output.{ps,png}") |
| @@ -191,6 +199,10 @@ def gnuplot_create(outplot='',extension='', options=None): · 9 unmodified lines |
| 191 | 199 | elif extension == 'svg': ext, extension = '.svg', 'svg' |
| 192 | 200 | else: exit("ERR: unknown plot extension") |
| 193 | 201 | 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) |
| 194 | 206 | if outplot != "stdout": |
| 195 | 207 | g('set output \'%s%s\'' % (outplot,ext)) |
| 196 | 208 | g('set size %f,%f' % (options.xsize, options.ysize)) |