source: python.old/aubiopitch @ 870ad70

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 870ad70 was b554e41, checked in by Paul Brossier <piem@piem.org>, 12 years ago

moved out old python interface

  • Property mode set to 100755
File size: 4.9 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
8from aubio.task import *
9
10usage = "usage: %s [options] -i soundfile" % sys.argv[0]
11
12
13def parse_args():
14  from optparse import OptionParser
15  parser = OptionParser(usage=usage)
16  parser.add_option("-i","--input",
17      action="store", dest="filename", 
18      help="input sound file")
19  parser.add_option("-m","--mode", 
20      action="store", dest="mode", default='yinfft',
21      help="pitch detection mode [default=mcomb] \
22      mcomb|yin|fcomb|schmitt")
23  parser.add_option("-u","--units",
24      action="store", dest="omode", default="freq",
25      help="output pitch in units [default=Hz] \
26      freq|midi|cent|bin")
27  parser.add_option("-B","--bufsize",
28      action="store", dest="bufsize", default=None, 
29      help="buffer size [default=2048]")
30  parser.add_option("-H","--hopsize",
31      action="store", dest="hopsize", default=None, 
32      help="overlap size [default=512]")
33  parser.add_option("-t","--threshold",
34      action="store", dest="threshold", default=0.1, 
35      help="pitch threshold (for yin) [default=0.1]")
36  parser.add_option("-s","--silence",
37      action="store", dest="silence", default=-70, 
38      help="silence threshold [default=-70]")
39  parser.add_option("-D","--delay",
40      action="store", dest="delay", 
41      help="number of seconds frames to take back [default=0]")
42  parser.add_option("-S","--smoothing",
43      action="store", dest="smoothing", default=False, 
44      help="use a median filter of N frames [default=0]")
45  parser.add_option("-M","--maximum",
46      action="store", dest="pitchmax", default=False, 
47      help="maximum pitch value to look for (Hz) [default=20000]")
48  parser.add_option("-l","--minimum",
49      action="store", dest="pitchmin", default=False, 
50      help="minimum pitch value to look for (Hz) [default=20]")
51  # to be implemented
52  parser.add_option("-n","--note",
53      action="store_true", dest="note", default=False,
54      help="NOT IMPLEMENTED output notes")
55  # plotting functions
56  parser.add_option("-T","--plottruth",
57      action="store_true", dest="plottruth", default=False, 
58      help="draw plot of the ground truth pitch track")
59  parser.add_option("-p","--plot",
60      action="store_true", dest="plot", default=False, 
61      help="draw plot of the pitch track")
62  parser.add_option("-x","--xsize",
63      action="store", dest="xsize", default=1., 
64      type='float', help="define xsize for plot")
65  parser.add_option("-y","--ysize",
66      action="store", dest="ysize", default=1., 
67      type='float', help="define ysize for plot")
68  parser.add_option("-O","--outplot",
69      action="store", dest="outplot", default=None, 
70      help="save the plot to output.{ps,png,svg} instead of displaying it")
71  parser.add_option("-v","--verbose",
72      action="store_true", dest="verbose", default=True,
73      help="make lots of noise")
74  parser.add_option("-q","--quiet",
75      action="store_false", dest="verbose", default=True, 
76      help="be quiet")
77  (options, args) = parser.parse_args()
78  if not options.bufsize:
79    if options.mode == "yin":     options.bufsize = 1024
80    if options.mode == "schmitt": options.bufsize = 2048
81    if options.mode == "mcomb":   options.bufsize = 4096
82    if options.mode == "fcomb":   options.bufsize = 4096 
83    else: options.bufsize = 2048
84  if not options.hopsize:
85    options.hopsize = float(options.bufsize) / 2
86  if not options.filename: 
87    print "no file name given\n", usage
88    sys.exit(1)
89  return options, args
90
91options, args = parse_args()
92
93#print options.bufsize, options.hopsize
94
95filename   = options.filename
96params = taskparams()
97params.samplerate = float(sndfile(filename).samplerate())
98params.hopsize    = int(options.hopsize)
99params.bufsize    = int(options.bufsize)
100params.step       = params.samplerate/float(params.hopsize)
101params.yinthresh  = float(options.threshold)
102params.silence    = float(options.silence)
103params.verbose    = options.verbose
104if options.smoothing: params.pitchsmooth = int(options.smoothing)
105if options.pitchmax:  params.pitchmax    = int(options.pitchmax)
106if options.pitchmin:  params.pitchmin    = int(options.pitchmin)
107#mintol     = float(options.mintol)*step
108# default take back system delay
109if options.delay: params.pitchdelay = float(options.delay)
110
111if options.note:
112        exit("not implemented yet")
113
114wplot,oplots,titles = [],[],[]
115modes = options.mode.split(',')
116for i in range(len(modes)):
117        pitch = []
118        params.pitchmode  = modes[i]
119        filetask = taskpitch(filename,params=params)
120        pitch = filetask.compute_all()
121        #print filetask.eval(pitch[i])
122        if options.plot: filetask.plot(pitch,wplot,oplots,titles)
123
124if options.outplot:
125  extension = options.outplot.split('.')[-1] 
126  outplot = '.'.join(options.outplot.split('.')[:-1])
127else:
128  extension,outplot = None,None
129if options.plot: 
130        filetask.plotplot(wplot,oplots,titles,outplot=outplot,extension=extension,
131  xsize=options.xsize,ysize=options.ysize,truth=options.plottruth)
Note: See TracBrowser for help on using the repository browser.