Changeset 80c0417 for python/aubio/gnuplot.py
- Timestamp:
- May 30, 2005, 6:44:52 AM (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:
- d09cad2
- Parents:
- 588a09f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/aubio/gnuplot.py
r588a09f r80c0417 137 137 def make_audio_plot(time,data,maxpoints=10000): 138 138 """ create gnuplot plot from an audio file """ 139 import numarray140 139 length = len(time) 141 140 downsample = length/maxpoints 142 141 if downsample == 0: downsample = 1 143 x = numarray.array(time).resize(length)[0:-1:downsample]144 y = numarray.array(data).resize(length)[0:-1:downsample]142 x = array(time).resize(length)[0:-1:downsample] 143 y = array(data).resize(length)[0:-1:downsample] 145 144 return Gnuplot.Data(x,y,with='lines') 145 146 147 def plot_onsets(filename, onsets, ofunc, samplerate=44100., hopsize=512, outplot=None): 148 import aubio.txtfile 149 import os.path 150 import numarray 151 from aubio.onsetcompare import onset_roc 152 153 # onset detection function 154 downtime = (hopsize/samplerate)*numarray.arange(len(ofunc)) 155 d = Gnuplot.Data(downtime,ofunc,with='lines') 156 157 # detected onsets 158 x1 = (hopsize/samplerate)*numarray.array(onsets) 159 y1 = max(ofunc)*numarray.ones(len(onsets)) 160 e = Gnuplot.Data(x1,-y1,with='impulses') 161 e2= Gnuplot.Data(x1,y1,with='impulses') 162 163 # check if datafile exists truth 164 datafile = filename.replace('.wav','.txt') 165 if not os.path.isfile(datafile): 166 title = "truth file not found" 167 t = Gnuplot.Data(0,0,with='impulses') 168 else: 169 t_onsets = aubio.txtfile.read_datafile(datafile) 170 y2 = max(ofunc)*numarray.ones(len(t_onsets)) 171 x2 = numarray.array(t_onsets).resize(len(t_onsets)) 172 t = Gnuplot.Data(x2,y2,with='impulses') 173 174 tol = 0.050 175 176 orig, missed, merged, expc, bad, doubled = \ 177 onset_roc(x2,x1,tol) 178 title = "GD %2.3f%% FP %2.3f%%" % \ 179 ((100*float(orig-missed-merged)/(orig)), 180 (100*float(bad+doubled)/(orig))) 181 #print orig, missed, merged, expc, bad, doubled 182 #print "GD %2.8f\t" % (100*float(orig-missed-merged)/(orig)), 183 #print "FP %2.8f\t" % (100*float(bad+doubled)/(orig)) , 184 #print "GD-merged %2.8f\t" % (100*float(orig-missed)/(orig)) , 185 #print "FP-pruned %2.8f\t" % (100*float(bad)/(orig)) 186 187 # audio data 188 time,data = audio_to_array(filename) 189 f = make_audio_plot(time,data) 190 191 # prepare the plot 192 g = Gnuplot.Gnuplot(debug=1, persist=1) 193 if outplot: 194 extension = outplot.split('.')[-1] 195 if extension == 'ps': extension = 'postscript' 196 g('set terminal %s' % extension) 197 g('set output \'%s\'' % outplot) 198 199 g('set title \'%s %s\'' % (filename,title)) 200 201 g('set multiplot') 202 203 # hack to align left axis 204 g('set lmargin 15') 205 206 # plot waveform and onsets 207 g('set size 1,0.3') 208 g('set origin 0,0.7') 209 g('set xrange [0:%f]' % max(time)) 210 g('set yrange [-1:1]') 211 g.ylabel('amplitude') 212 g.plot(f,e,t) 213 214 g('unset title') 215 216 # plot onset detection function 217 g('set size 1,0.7') 218 g('set origin 0,0') 219 g('set xrange [0:%f]' % (hopsize/samplerate*len(ofunc))) 220 g('set yrange [0:%f]' % (max(ofunc)*1.01)) 221 g.xlabel('time') 222 g.ylabel('onset detection value') 223 g.plot(d,e2) 224 225 g('unset multiplot')
Note: See TracChangeset
for help on using the changeset viewer.