source: python/aubiopitch @ 42f1cf14

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

makes aubiocut and aubiopitch verbose by default, not quiet
makes aubiocut and aubiopitch verbose by default, not quiet

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