Changeset da6d9af for python/aubio
- Timestamp:
- May 7, 2006, 5:42:43 PM (19 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 5cc94db
- Parents:
- cadf07b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/aubio/gnuplot.py
rcadf07b rda6d9af 46 46 return time,data 47 47 48 def plot_audio(filenames, fileout=None, start=0, end=None, noaxis=None ):48 def plot_audio(filenames, fileout=None, start=0, end=None, noaxis=None,xsize=1.,ysize=1.): 49 49 g = gnuplot_init(fileout) 50 50 d = [] 51 51 todraw = len(filenames) 52 52 xorig = 0. 53 xsize = 1./todraw 53 xratio = 1./todraw 54 g.gnuplot('set size %f,%f;' % (xsize,ysize) ) 54 55 g.gnuplot('set multiplot;') 55 56 while (len(filenames)): 56 57 time,data = audio_to_array(filenames.pop(0)) 58 if not noaxis and todraw==1: 59 if max(time) < 1.: 60 time = [t*1000. for t in time] 61 g.xlabel('Time (ms)') 62 else: 63 g.xlabel('Time (s)') 64 g.ylabel('Amplitude') 57 65 d.append(make_audio_plot(time,data)) 58 if not noaxis and todraw==1: 59 g.xlabel('Time (s)') 60 g.ylabel('Amplitude') 61 g.gnuplot('set size %f,1.;' % (xsize) ) 66 g.gnuplot('set size %f,%f;' % (xsize*xratio,ysize) ) 62 67 g.gnuplot('set origin %f,0.;' % (xorig) ) 63 68 g.gnuplot('set style data lines; \ … … 65 70 set xrange [0:%f]' % time[-1]) 66 71 g.plot(d.pop(0)) 67 xorig += 1./todraw72 xorig += xsize*xratio 68 73 g.gnuplot('unset multiplot;') 69 74 70 def audio_to_spec(filename ):75 def audio_to_spec(filename,minf = 0, maxf = 0, lowthres = 0.): 71 76 from aubioclass import fvec,cvec,pvoc,sndfile 72 from math import log 73 bufsize = 256*1674 hopsize = bufsize/ 4# could depend on filelength77 from math import log10 78 bufsize = 8192 79 hopsize = bufsize/8 # could depend on filelength 75 80 filei = sndfile(filename) 76 81 srate = float(filei.samplerate()) … … 79 84 channels = filei.channels() 80 85 myvec = fvec(hopsize,channels) 81 82 86 myfft = cvec(bufsize,channels) 87 pv = pvoc(bufsize,hopsize,channels) 83 88 data,time,freq = [],[],[] 84 for f in range(bufsize/2): 89 90 if maxf == 0.: maxf = bufsize/2 91 else: maxf = int(maxf/freqstep) 92 if minf: minf = int(minf/freqstep) 93 else: minf = 0 94 95 for f in range(minf,maxf): 85 96 freq.append(f*freqstep) 86 97 readsize = hopsize … … 91 102 frame = [] 92 103 i = 0 #for i in range(channels): 93 curpos = 094 while (curpos < bufsize/2):95 frame.append( log(myfft.get(curpos,i)**2+0.000001))104 curpos = minf 105 while (curpos < maxf): 106 frame.append(max(lowthres,20.*log10(myfft.get(curpos,i)**2+0.00001))) 96 107 curpos+=1 97 108 time.append(frameread*framestep) … … 107 118 return data,time,freq 108 119 109 def plot_spec(filename, outplot='',extension='', fileout=None, start=0, end=None, noaxis=None,log=1 ):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.): 110 121 import Gnuplot 111 122 g = gnuplot_create(outplot,extension) 112 data,time,freq = audio_to_spec(filename )123 data,time,freq = audio_to_spec(filename,minf=minf,maxf=maxf) 113 124 xorig = 0. 114 xsize = 1.#/todraw115 125 if not noaxis: 116 126 g.xlabel('Time (s)') 117 127 g.ylabel('Frequency (Hz)') 118 g.gnuplot('set pm3d map') 119 #g.gnuplot('set palette rgbformulae 30,31,32') 120 #g.gnuplot('set palette') 121 g.gnuplot('set xrange [0.:%f]' % time[-1]) 122 g.gnuplot('set yrange [1.:%f]' % (freq[-1]/1.)) 128 g('set size %f,%f' % (xsize, ysize)) 129 g('set pm3d map') 130 g('set palette rgbformulae -25,-24,-32') 131 #g('set colorbox horizontal') 132 g('set xrange [0.:%f]' % time[-1]) 133 g('set yrange [%f:%f]' % (minf,maxf)) 123 134 if log: 124 g .gnuplot('set yrange [10.1:%f]' % (freq[-1]/1.))125 g .gnuplot('set log y')126 g.splot(Gnuplot.GridData(data,time,freq, binary=1 ))135 g('set yrange [%f:%f]' % (max(10,minf),maxf)) 136 g('set log y') 137 g.splot(Gnuplot.GridData(data,time,freq, binary=1, title='mag. (dB)')) 127 138 #xorig += 1./todraw 128 139 … … 167 178 if not extension or not outplot: return g 168 179 if extension == 'ps': ext, extension = '.ps' , 'postscript' 180 elif extension == 'eps': ext, extension = '.eps' , 'postscript enhanced' 181 elif extension == 'epsc': ext, extension = '.eps' , 'postscript enhanced color' 169 182 elif extension == 'png': ext, extension = '.png', 'png' 170 183 elif extension == 'svg': ext, extension = '.svg', 'svg'
Note: See TracChangeset
for help on using the changeset viewer.