Showing the changes to python (2 of 2 files). Show all
Unified · Split
| @@ -72,11 +72,10 @@ def plot_audio(filenames, fileout=None, start=0, end=None, noaxis=None,xsize=1., · 71 unmodified lines | ||
| 72 | 72 | xorig += xsize*xratio |
| 73 | 73 | g.gnuplot('unset multiplot;') |
| 74 | 74 | |
| 75 | −def audio_to_spec(filename,minf = 0, maxf = 0, lowthres = -20.): | |
| 75 | +def audio_to_spec(filename,minf = 0, maxf = 0, lowthres = -20., | |
| 76 | + bufsize= 8192, hopsize = 1024): | |
| 76 | 77 | from aubioclass import fvec,cvec,pvoc,sndfile |
| 77 | 78 | from math import log10 |
| 78 | − bufsize = 8192 | |
| 79 | − hopsize = bufsize/8 # could depend on filelength | |
| 80 | 79 | filei = sndfile(filename) |
| 81 | 80 | srate = float(filei.samplerate()) |
| 82 | 81 | framestep = hopsize/srate |
| @@ -117,10 +116,10 @@ def audio_to_spec(filename,minf = 0, maxf = 0, lowthres = -20.): · 34 unmodified lines | ||
| 117 | 116 | assert len(data[0]) == len(freq) |
| 118 | 117 | return data,time,freq |
| 119 | 118 | |
| 120 | −def plot_spec(filename, outplot='',extension='', fileout=None, start=0, end=None, noaxis=None,log=1, minf=0, maxf= 0, xsize = 1., ysize = 1.): | |
| 119 | +def 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): | |
| 121 | 120 | import Gnuplot |
| 122 | 121 | g = gnuplot_create(outplot,extension) |
| 123 | − data,time,freq = audio_to_spec(filename,minf=minf,maxf=maxf) | |
| 122 | + data,time,freq = audio_to_spec(filename,minf=minf,maxf=maxf,bufsize=bufsize,hopsize=hopsize) | |
| 124 | 123 | xorig = 0. |
| 125 | 124 | if not noaxis: |
| 126 | 125 | g.xlabel('Time (s)') |
| @@ -16,7 +16,7 @@ def parse_args(): · 15 unmodified lines | ||
| 16 | 16 | action="store", dest="filename", |
| 17 | 17 | help="input sound file") |
| 18 | 18 | parser.add_option("-M","--maxf", |
| 19 | − action="store", dest="maxf", default=0., | |
| 19 | + action="store", dest="maxf", default=10000., | |
| 20 | 20 | type='float',help="higher frequency limit") |
| 21 | 21 | parser.add_option("-L","--minf", |
| 22 | 22 | action="store", dest="minf", default=0., |
| @@ -33,6 +33,12 @@ def parse_args(): · 10 unmodified lines | ||
| 33 | 33 | parser.add_option("-O","--outplot", |
| 34 | 34 | action="store", dest="outplot", default=None, |
| 35 | 35 | help="save plot to output.{ps,png}") |
| 36 | + parser.add_option("-B","--bufsize", type='int', | |
| 37 | + action="store", dest="bufsize", default=8192, | |
| 38 | + help="buffer size [default=8192]") | |
| 39 | + parser.add_option("-H","--hopsize", type='int', | |
| 40 | + action="store", dest="hopsize", default=1024, | |
| 41 | + help="overlap size [default=1024]") | |
| 36 | 42 | (options, args) = parser.parse_args() |
| 37 | 43 | if not options.filename: |
| 38 | 44 | print "no file name given\n", usage |
| @@ -51,4 +57,5 @@ else: · 12 unmodified lines | ||
| 51 | 57 | |
| 52 | 58 | plot_spec(filename, outplot=outplot, extension=extension, log=options.log, |
| 53 | 59 | maxf = options.maxf, minf = options.minf, |
| 54 | − xsize = options.xsize, ysize = options.ysize) | |
| 60 | + xsize = options.xsize, ysize = options.ysize, | |
| 61 | + bufsize = options.bufsize, hopsize = options.hopsize) | |