source: python/aubioplot-yinfft @ 4123f16

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 4123f16 was 4b4e6ae, checked in by Paul Brossier <piem@altern.org>, 18 years ago

add aubioplot-yinfft
add aubioplot-yinfft

  • Property mode set to 100755
File size: 4.7 KB
Line 
1#! /usr/bin/python
2
3""" this file was written by Paul Brossier
4  it is released under the GNU/GPL license.
5"""
6
7import sys,time
8from aubio.task import task,taskparams
9from aubio.aubioclass import fvec
10from aubio.gnuplot import gnuplot_create
11from aubio.aubiowrapper import *
12
13usage = "usage: %s [options] -i soundfile" % sys.argv[0]
14
15def parse_args():
16        from optparse import OptionParser
17        parser = OptionParser(usage=usage)
18        parser.add_option("-i","--input",
19                          action="store", dest="filename",
20                          help="input sound file")
21        parser.add_option("-n","--printframe",
22                          action="store", dest="printframe", default=-1,
23                          help="make a plot of the n_th frame")
24        parser.add_option("-x","--xsize",
25                          action="store", dest="xsize", default=1.,
26                          help="define xsize for plot")
27        parser.add_option("-y","--ysize",
28                          action="store", dest="ysize", default=1.,
29                          help="define ysize for plot")
30        parser.add_option("-O","--outplot",
31                          action="store", dest="outplot", default=None,
32                          help="save plot to output.{ps,png}")
33        (options, args) = parser.parse_args()
34        if not options.filename:
35                 print "no file name given\n", usage
36                 sys.exit(1)
37        return options, args
38
39def plotdata(x,y,plottitle="",**keyw):
40        import Gnuplot
41        return Gnuplot.Data(x, y, title="%s" % plottitle,**keyw)
42
43options, args = parse_args()
44filename = options.filename
45xsize = float(options.xsize)
46ysize = float(options.ysize)*2
47
48printframe = int(options.printframe)
49if printframe == -1:
50  print "Will wait for ^D to skip to next plot"
51  print "Press enter before to print to file"
52
53
54g = gnuplot_create()
55params = taskparams()
56params.hopsize = 2048 # 512
57params.bufsize = params.hopsize #2048
58taskfile = task(filename,params=params)
59
60yin = fvec(params.bufsize/2,1)
61
62t = [i for i in range(params.bufsize)]
63a = [0 for i in range(params.bufsize)]
64
65while (taskfile.readsize == params.hopsize):
66  taskfile()
67
68  n = [i for i in range(params.bufsize/2)]
69  a = [taskfile.myvec.get(i,0) for i in range(params.hopsize/2)]
70  aubio_pitchyin_diff(taskfile.myvec(),yin()) # compute d[t]
71  c = [yin.get(i,0) for i in range(params.bufsize/2)]
72  aubio_pitchyin_getcum(yin()) # compute d'[t]
73  y = [yin.get(i,0) for i in range(params.bufsize/2)]
74  thresh = [0.1 for i in range(params.bufsize/2)]
75  #t.append((i/float(params.hopsize)+taskfile.frameread)*params.step),t.pop(0)
76  d = [plotdata(n,a,plottitle="signal", with='lines'),
77    plotdata(n,c,plottitle="d[t]",axes='x1y2', with='lines lt 1'),
78    plotdata(n,y,plottitle="d'[t]",axes='x1y1', with='lines lt 2'),
79    plotdata(n,thresh,plottitle="threshold",axes='x1y1', with='lines lt 3')]
80  #g('set xrange [%f:%f]' % (t[0],t[-1]))
81  #time.sleep(.2)
82  g.reset()
83  g('set yrange [-1:3]')
84  g('set xrange [0:%d]' % (params.bufsize/2))
85  g('set title \"%s\"' %  "Example of period detection using YIN")
86  if printframe == -1:
87    g.replot(*d)
88    a = sys.stdin.read()
89  if a == "\n" or printframe == taskfile.frameread:
90      from os.path import basename
91      outplot = "_".join([basename(sys.argv[0]),'_'.join(basename(filename).split('.')),"%d" % taskfile.frameread])
92      print outplot
93      f = gnuplot_create(outplot=outplot,extension='ps')
94      f('set size %f,%f;' % (xsize,ysize) )
95      f('set lmargin %f' % (15*xsize))
96      f('set rmargin %f' % (10*xsize))
97      #f('set title \"%s\"' %  "Example of period detection using YIN")
98      f('set multiplot')
99      f.ylabel('amplitude',offset=(+.5,0))
100      f.xlabel('time (samples)')
101      f('set size %f,%f;' % (xsize,ysize*0.4) )
102      f('set orig %f,%f;' % (0,ysize*0.6) )
103      sigmax = max(abs(min(a)),abs(max(a)))
104      f('set yrange [%f:%f]' % (-1.3*sigmax,1.3*sigmax))
105      f('set xrange [0:%d]' % (params.bufsize/2))
106      f.plot(d[0])
107
108      f.ylabel('')
109      f.xlabel('lag (samples)')
110      f('set bmargin %f' % (4*ysize))
111      f('set size %f,%f;' % (xsize,ysize*0.6) )
112      f('set orig %f,%f;' % (0,0) )
113      f('set autoscale')
114      f('set xrange [0:%d]' % (params.bufsize/2))
115      f('set notitle')
116      f('set y2tics')
117      f('set ytics nomirror')
118      f('set noytics')
119      f('set key right')
120      f.plot(d[1])
121
122      f.ylabel('amplitude')
123      f.xlabel('')
124      f('set y2tics nomirror')
125      f('set ytics nomirror')
126      f('set noy2tics')
127      f('set noxtics')
128      f('set ytics')
129      f('set key left')
130      f.plot(d[2],d[3])
131      #f('set yrange [-1:3]')
132      #f.plot(*d)
133      print "saved plot", outplot, 'ps'
134  elif printframe < taskfile.frameread:
135      break
Note: See TracBrowser for help on using the repository browser.