source: python/aubiopitch @ 29808b1

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

src/pitch: use a string to set pitch method, add a new function to set pitch unit, keep pitch enums private, update pitch methods where they are used

  • Property mode set to 100755
File size: 4.9 KB
RevLine 
[96fb8ad]1#!/usr/bin/python
2
[d4a0cc4]3""" this file was written by Paul Brossier
4  it is released under the GNU/GPL license.
5"""
6
7import sys
[13c3fba]8from aubio.task import *
[d4a0cc4]9
10usage = "usage: %s [options] -i soundfile" % sys.argv[0]
11
12
13def parse_args():
[3e29681]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", 
[fe163ad]20      action="store", dest="mode", default='yinfft',
[3e29681]21      help="pitch detection mode [default=mcomb] \
22      mcomb|yin|fcomb|schmitt")
[fe163ad]23  parser.add_option("-u","--units",
24      action="store", dest="omode", default="freq",
[3e29681]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, 
[1ab7d54]29      help="buffer size [default=2048]")
[3e29681]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")
[bf8e134]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")
[3e29681]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",
[1566886]72      action="store_true", dest="verbose", default=True,
[3e29681]73      help="make lots of noise")
74  parser.add_option("-q","--quiet",
[1566886]75      action="store_false", dest="verbose", default=True, 
[3e29681]76      help="be quiet")
77  (options, args) = parser.parse_args()
78  if not options.bufsize:
[fe163ad]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 
[3e29681]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
[d4a0cc4]90
91options, args = parse_args()
92
[aa17581]93#print options.bufsize, options.hopsize
94
[d4a0cc4]95filename   = options.filename
[d9101a5]96params = taskparams()
[0fe9aab]97params.samplerate = float(sndfile(filename).samplerate())
[d9101a5]98params.hopsize    = int(options.hopsize)
99params.bufsize    = int(options.bufsize)
[0fe9aab]100params.step       = params.samplerate/float(params.hopsize)
[650e39b]101params.yinthresh  = float(options.threshold)
[d9101a5]102params.silence    = float(options.silence)
[0fe9aab]103params.verbose    = options.verbose
[4798fdf]104if options.smoothing: params.pitchsmooth = int(options.smoothing)
105if options.pitchmax:  params.pitchmax    = int(options.pitchmax)
106if options.pitchmin:  params.pitchmin    = int(options.pitchmin)
[d4a0cc4]107#mintol     = float(options.mintol)*step
108# default take back system delay
[4798fdf]109if options.delay: params.pitchdelay = float(options.delay)
[d4a0cc4]110
111if options.note:
112        exit("not implemented yet")
113
[3e29681]114wplot,oplots,titles = [],[],[]
[d9101a5]115modes = options.mode.split(',')
116for i in range(len(modes)):
[0fe9aab]117        pitch = []
[d9101a5]118        params.pitchmode  = modes[i]
[0fe9aab]119        filetask = taskpitch(filename,params=params)
120        pitch = filetask.compute_all()
121        #print filetask.eval(pitch[i])
[3e29681]122        if options.plot: filetask.plot(pitch,wplot,oplots,titles)
[d4a0cc4]123
[bf8e134]124if options.outplot:
125  extension = options.outplot.split('.')[-1] 
126  outplot = '.'.join(options.outplot.split('.')[:-1])
127else:
128  extension,outplot = None,None
[9610f0a]129if options.plot: 
[bf8e134]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.