Changeset d4a0cc4 for python/aubio
- Timestamp:
- Jun 3, 2005, 2:53:41 AM (20 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:
- 21cc311
- Parents:
- d53e4df
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/aubio/gnuplot.py
rd53e4df rd4a0cc4 224 224 225 225 g('unset multiplot') 226 227 228 def plot_pitch(filename, pitch, samplerate=44100., hopsize=512, outplot=None): 229 import aubio.txtfile 230 import os.path 231 import numarray 232 233 # onset detection function 234 downtime = (hopsize/samplerate)*numarray.arange(len(pitch)) 235 d = Gnuplot.Data(downtime,pitch,with='lines') 236 237 # check if datafile exists truth 238 datafile = filename.replace('.wav','.txt') 239 if not os.path.isfile(datafile): 240 title = "truth file not found" 241 t = Gnuplot.Data(0,0,with='impulses') 242 else: 243 title = "truth file plotting not implemented yet" 244 t = Gnuplot.Data(0,0,with='impulses') 245 #times,pitch = aubio.txtfile.read_datafile(datafile) 246 #t = Gnuplot.Data(times,pitch,with='lines') 247 248 #orig, missed, merged, expc, bad, doubled = \ 249 # onset_roc(x2,x1,tol) 250 #title = "GD %2.3f%% FP %2.3f%%" % \ 251 # ((100*float(orig-missed-merged)/(orig)), 252 # (100*float(bad+doubled)/(orig))) 253 #print orig, missed, merged, expc, bad, doubled 254 #print "GD %2.8f\t" % (100*float(orig-missed-merged)/(orig)), 255 #print "FP %2.8f\t" % (100*float(bad+doubled)/(orig)) , 256 #print "GD-merged %2.8f\t" % (100*float(orig-missed)/(orig)) , 257 #print "FP-pruned %2.8f\t" % (100*float(bad)/(orig)) 258 259 # audio data 260 time,data = audio_to_array(filename) 261 f = make_audio_plot(time,data) 262 263 # prepare the plot 264 g = Gnuplot.Gnuplot(debug=1, persist=1) 265 if outplot: 266 extension = outplot.split('.')[-1] 267 if extension == 'ps': extension = 'postscript' 268 g('set terminal %s' % extension) 269 g('set output \'%s\'' % outplot) 270 271 g('set title \'%s %s\'' % (filename,title)) 272 273 g('set multiplot') 274 275 # hack to align left axis 276 g('set lmargin 15') 277 278 # plot waveform and onsets 279 g('set size 1,0.3') 280 g('set origin 0,0.7') 281 g('set xrange [0:%f]' % max(time)) 282 g('set yrange [-1:1]') 283 g.ylabel('amplitude') 284 g.plot(f) 285 286 g('unset title') 287 288 # plot onset detection function 289 g('set size 1,0.7') 290 g('set origin 0,0') 291 g('set xrange [0:%f]' % (hopsize/samplerate*len(pitch))) 292 g('set yrange [0:%f]' % (max(pitch)*1.01)) 293 g.xlabel('time') 294 g.ylabel('frequency (Hz)') 295 g.plot(d,t) 296 297 g('unset multiplot')
Note: See TracChangeset
for help on using the changeset viewer.